]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/io/common/v2_0/include/devtab.h
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / io / common / v2_0 / include / devtab.h
1 #ifndef CYGONCE_IO_DEVTAB_H
2 #define CYGONCE_IO_DEVTAB_H
3 // ====================================================================
4 //
5 //      devtab.h
6 //
7 //      Device I/O Table
8 //
9 // ====================================================================
10 //####ECOSGPLCOPYRIGHTBEGIN####
11 // -------------------------------------------
12 // This file is part of eCos, the Embedded Configurable Operating System.
13 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
14 //
15 // eCos is free software; you can redistribute it and/or modify it under
16 // the terms of the GNU General Public License as published by the Free
17 // Software Foundation; either version 2 or (at your option) any later version.
18 //
19 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22 // for more details.
23 //
24 // You should have received a copy of the GNU General Public License along
25 // with eCos; if not, write to the Free Software Foundation, Inc.,
26 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27 //
28 // As a special exception, if other files instantiate templates or use macros
29 // or inline functions from this file, or you compile this file and link it
30 // with other works to produce a work based on this file, this file does not
31 // by itself cause the resulting work to be covered by the GNU General Public
32 // License. However the source code for this file must still be made available
33 // in accordance with section (3) of the GNU General Public License.
34 //
35 // This exception does not invalidate any other reasons why a work based on
36 // this file might be covered by the GNU General Public License.
37 //
38 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39 // at http://sources.redhat.com/ecos/ecos-license/
40 // -------------------------------------------
41 //####ECOSGPLCOPYRIGHTEND####
42 // ====================================================================
43 //#####DESCRIPTIONBEGIN####
44 //
45 // Author(s):   gthomas
46 // Contributors:        gthomas
47 // Date:        1999-02-04
48 // Purpose:     Describe low level I/O interfaces.
49 // Description:
50 //
51 //####DESCRIPTIONEND####
52 //
53 // ====================================================================
54
55 // Private include file.  This file should only be used by device 
56 // drivers, not application code.
57
58 #include <pkgconf/system.h>
59 #include <cyg/io/io.h>
60 #include <cyg/hal/drv_api.h>
61 #include <cyg/hal/hal_tables.h>
62
63 // Set of functions which handle top level I/O functions
64 typedef struct {
65     Cyg_ErrNo (*write)(cyg_io_handle_t handle, 
66                        const void *buf, 
67                        cyg_uint32 *len);
68     Cyg_ErrNo (*read)(cyg_io_handle_t handle, 
69                       void *buf, 
70                       cyg_uint32 *len);
71     Cyg_ErrNo (*bwrite)(cyg_io_handle_t handle, 
72                         const void *buf, 
73                         cyg_uint32 *len,   // in blocks
74                         cyg_uint32 pos);   // in blocks
75     Cyg_ErrNo (*bread)(cyg_io_handle_t handle, 
76                        void *buf, 
77                        cyg_uint32 *len,    // in blocks
78                        cyg_uint32 pos);    // in blocks
79     cyg_bool  (*select)(cyg_io_handle_t handle,
80                         cyg_uint32 which,
81                         CYG_ADDRWORD info);
82     Cyg_ErrNo (*get_config)(cyg_io_handle_t handle, 
83                             cyg_uint32 key, 
84                             void *buf, 
85                             cyg_uint32 *len);
86     Cyg_ErrNo (*set_config)(cyg_io_handle_t handle, 
87                             cyg_uint32 key, 
88                             const void *buf, 
89                             cyg_uint32 *len);
90 } cyg_devio_table_t;
91
92
93 // Default functions
94
95 __externC Cyg_ErrNo cyg_devio_cwrite(cyg_io_handle_t handle, 
96                                      const void *buf, cyg_uint32 *len);
97 __externC Cyg_ErrNo cyg_devio_cread(cyg_io_handle_t handle, 
98                                     void *buf, cyg_uint32 *len);
99 __externC Cyg_ErrNo cyg_devio_bwrite(cyg_io_handle_t handle, 
100                                      const void *buf, cyg_uint32 *len,
101                                      cyg_uint32 pos);
102 __externC Cyg_ErrNo cyg_devio_bread(cyg_io_handle_t handle, 
103                                     void *buf, cyg_uint32 *len,
104                                     cyg_uint32 pos);
105
106 __externC Cyg_ErrNo cyg_devio_select(cyg_io_handle_t handle,
107                                      cyg_uint32 which,
108                                      CYG_ADDRWORD info);
109
110 __externC Cyg_ErrNo cyg_devio_get_config(cyg_io_handle_t handle,
111                                          cyg_uint32 key,
112                                          void* buf,
113                                          cyg_uint32* len);
114
115 __externC Cyg_ErrNo cyg_devio_set_config(cyg_io_handle_t handle,
116                                          cyg_uint32 key,
117                                          void* buf,
118                                          cyg_uint32* len);
119
120 // Initialization macros
121
122 #define CHAR_DEVIO_TABLE(_l,_write,_read,_select,_get_config,_set_config)    \
123 cyg_devio_table_t _l = {                                        \
124     _write,                                                     \
125     _read,                                                      \
126     cyg_devio_bwrite,                                           \
127     cyg_devio_bread,                                            \
128     _select,                                                    \
129     _get_config,                                                \
130     _set_config,                                                \
131 };
132
133 // Note: _bwrite and _bread pass len and pos in terms of blocks, not
134 // bytes.
135 #define BLOCK_DEVIO_TABLE(_l,_bwrite,_bread,_select,_get_config,_set_config)    \
136 cyg_devio_table_t _l = {                                        \
137     cyg_devio_cwrite,                                           \
138     cyg_devio_cread,                                            \
139     _bwrite,                                                    \
140     _bread,                                                     \
141     _select,                                                    \
142     _get_config,                                                \
143     _set_config,                                                \
144 };
145
146 #define DEVIO_TABLE(_l,_write,_read,_select,_get_config,_set_config) \
147         CHAR_DEVIO_TABLE(_l,_write,_read,_select,_get_config,_set_config)
148
149 typedef struct cyg_devtab_entry {
150     const char        *name;
151     const char        *dep_name;
152     cyg_devio_table_t *handlers;
153     bool             (*init)(struct cyg_devtab_entry *tab);
154     Cyg_ErrNo        (*lookup)(struct cyg_devtab_entry **tab, 
155                                struct cyg_devtab_entry *sub_tab,
156                                const char *name);
157     void              *priv;
158     unsigned long     status;
159 } CYG_HAL_TABLE_TYPE cyg_devtab_entry_t;
160
161 #define CYG_DEVTAB_STATUS_AVAIL   0x0001
162 #define CYG_DEVTAB_STATUS_CHAR    0x1000
163 #define CYG_DEVTAB_STATUS_BLOCK   0x2000
164
165 extern cyg_devtab_entry_t __DEVTAB__[], __DEVTAB_END__;
166
167 #define CHAR_DEVTAB_ENTRY(_l,_name,_dep_name,_handlers,_init,_lookup,_priv)  \
168 cyg_devtab_entry_t _l CYG_HAL_TABLE_ENTRY(devtab) = {                   \
169    _name,                                                               \
170    _dep_name,                                                           \
171    _handlers,                                                           \
172    _init,                                                               \
173    _lookup,                                                             \
174    _priv,                                                               \
175    CYG_DEVTAB_STATUS_CHAR                                               \
176 };
177
178 #define BLOCK_DEVTAB_ENTRY(_l,_name,_dep_name,_handlers,_init,_lookup,_priv)  \
179 cyg_devtab_entry_t _l CYG_HAL_TABLE_ENTRY(devtab) = {                   \
180    _name,                                                               \
181    _dep_name,                                                           \
182    _handlers,                                                           \
183    _init,                                                               \
184    _lookup,                                                             \
185    _priv,                                                               \
186    CYG_DEVTAB_STATUS_BLOCK                                              \
187 };
188
189 #define DEVTAB_ENTRY(_l,_name,_dep_name,_handlers,_init,_lookup,_priv) \
190         CHAR_DEVTAB_ENTRY(_l,_name,_dep_name,_handlers,_init,_lookup,_priv)
191
192
193 #define DEVTAB_ENTRY_NO_INIT(_l,_name,_dep_name,_handlers,_init,_lookup,_priv)  \
194 cyg_devtab_entry_t _l = {                                                       \
195    _name,                                                                       \
196    _dep_name,                                                                   \
197    _handlers,                                                                   \
198    _init,                                                                       \
199    _lookup,                                                                     \
200    _priv,                                                                       \
201    CYG_DEVTAB_STATUS_CHAR                                                       \
202 };
203
204 #endif // CYGONCE_IO_DEVTAB_H