1/*  *********************************************************************
2    *  Broadcom Common Firmware Environment (CFE)
3    *
4    *  Filesystem dispatch defs	       		File: cfe_fileops.h
5    *
6    *  CFE supports multiple access methods to files on boot
7    *  media.  This module contains the dispatch table structures
8    *  for "file systems".
9    *
10    *  Author:  Mitch Lichtenberg
11    *
12    *********************************************************************
13    *
14    *  Copyright 2000,2001,2002,2003
15    *  Broadcom Corporation. All rights reserved.
16    *
17    *  This software is furnished under license and may be used and
18    *  copied only in accordance with the following terms and
19    *  conditions.  Subject to these conditions, you may download,
20    *  copy, install, use, modify and distribute modified or unmodified
21    *  copies of this software in source and/or binary form.  No title
22    *  or ownership is transferred hereby.
23    *
24    *  1) Any source code used, modified or distributed must reproduce
25    *     and retain this copyright notice and list of conditions
26    *     as they appear in the source file.
27    *
28    *  2) No right is granted to use any trade name, trademark, or
29    *     logo of Broadcom Corporation.  The "Broadcom Corporation"
30    *     name may not be used to endorse or promote products derived
31    *     from this software without the prior written permission of
32    *     Broadcom Corporation.
33    *
34    *  3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
35    *     IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
36    *     WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
37    *     PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
38    *     SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
39    *     PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
40    *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
41    *     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
42    *     GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43    *     BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
44    *     OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
45    *     TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
46    *     THE POSSIBILITY OF SUCH DAMAGE.
47    ********************************************************************* */
48
49
50/*  *********************************************************************
51    *  Constants
52    ********************************************************************* */
53
54#define FILE_SEEK_BEGINNING	0
55#define FILE_SEEK_CURRENT	1
56
57#define FILE_MODE_READ	1
58#define FILE_MODE_WRITE	2
59
60/* These flags should not conflict with the loader arg flags (see cfe_loadargs_t) */
61#define FSYS_TYPE_NETWORK	0x40000000
62
63/*  *********************************************************************
64    *  Macros
65    ********************************************************************* */
66
67#define BDINIT(ops,fsctx,name) (ops)->init((fsctx),(name))
68#define BDOPEN(ops,ref,fsctx,name) (ops)->open((ref),(fsctx),(name),FILE_MODE_READ)
69#define BDOPEN2(ops,ref,fsctx,name,mode) (ops)->open((ref),(fsctx),(name),(mode))
70#define BDOPEN_WR(ops,ref,fsctx,name) (ops)->open((ref),(fsctx),(name),FILE_MODE_WRITE)
71#define BDREAD(ops,ref,buf,len) (ops)->read((ref),(buf),(len))
72#define BDWRITE(ops,ref,buf,len) (ops)->write((ref),(buf),(len))
73#define BDCLOSE(ops,ref) (ops)->close((ref))
74#define BDUNINIT(ops,ref) (ops)->uninit((ref))
75#define BDSEEK(ops,ref,offset,how) (ops)->seek((ref),(offset),(how))
76
77/*  *********************************************************************
78    *  Structures
79    ********************************************************************* */
80
81typedef struct fileio_dispatch_s {
82    const char *method;
83    unsigned int loadflags;
84    int (*init)(void **fsctx,void *device);
85    int (*open)(void **ref,void *fsctx,char *filename,int mode);
86    int (*read)(void *ref,hsaddr_t buf,int len);
87    int (*write)(void *ref,hsaddr_t buf,int len);
88    int (*seek)(void *ref,int offset,int how);
89    void (*close)(void *ref);
90    void (*uninit)(void *devctx);
91} fileio_dispatch_t;
92
93typedef struct fileio_ctx_s {
94    const fileio_dispatch_t *ops;
95    void *fsctx;
96} fileio_ctx_t;
97
98const fileio_dispatch_t *cfe_findfilesys(const char *name);
99
100int fs_init(char *fsname,fileio_ctx_t **fsctx,void *device);
101int fs_uninit(fileio_ctx_t *);
102int fs_open(fileio_ctx_t *,void **ref,char *filename,int mode);
103int fs_close(fileio_ctx_t *,void *ref);
104int fs_read(fileio_ctx_t *,void *ref,hsaddr_t buffer,int len);
105int fs_write(fileio_ctx_t *,void *ref,hsaddr_t buffer,int len);
106int fs_seek(fileio_ctx_t *,void *ref,int offset,int how);
107int fs_hook(fileio_ctx_t *fsctx,char *fsname);
108
109
110