]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/io/disk/v2_0/include/disk.h
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / io / disk / v2_0 / include / disk.h
1 #ifndef CYGONCE_DISK_H
2 #define CYGONCE_DISK_H
3 // ====================================================================
4 //
5 //      disk.h
6 //
7 //      Device I/O 
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 // Copyright (C) 2003, 2004, 2005 eCosCentric Limited
15 //
16 // eCos is free software; you can redistribute it and/or modify it under
17 // the terms of the GNU General Public License as published by the Free
18 // Software Foundation; either version 2 or (at your option) any later version.
19 //
20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23 // for more details.
24 //
25 // You should have received a copy of the GNU General Public License along
26 // with eCos; if not, write to the Free Software Foundation, Inc.,
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 //
29 // As a special exception, if other files instantiate templates or use macros
30 // or inline functions from this file, or you compile this file and link it
31 // with other works to produce a work based on this file, this file does not
32 // by itself cause the resulting work to be covered by the GNU General Public
33 // License. However the source code for this file must still be made available
34 // in accordance with section (3) of the GNU General Public License.
35 //
36 // This exception does not invalidate any other reasons why a work based on
37 // this file might be covered by the GNU General Public License.
38 //
39 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
40 // at http://sources.redhat.com/ecos/ecos-license/
41 // -------------------------------------------
42 //####ECOSGPLCOPYRIGHTEND####
43 // ====================================================================
44 //#####DESCRIPTIONBEGIN####
45 //
46 // Author(s):     savin 
47 // Original data: gthomas
48 // Date:          2003-06-09
49 // Purpose:       Internal interfaces for disk I/O drivers
50 // Description:
51 //
52 //####DESCRIPTIONEND####
53 //
54 // ====================================================================
55
56 // Disk I/O interfaces
57
58 #include <pkgconf/system.h>
59 #include <pkgconf/io_disk.h>
60
61 #include <cyg/infra/cyg_type.h>
62 #include <cyg/io/devtab.h>
63 #include <cyg/io/io.h>
64 #include <cyg/hal/drv_api.h>
65 #include <string.h> /* memset() */
66
67 // ---------------------------------------------------------------------------
68
69 typedef struct cyg_disk_partition_t cyg_disk_partition_t;
70 typedef struct cyg_disk_info_t cyg_disk_info_t;
71 typedef struct cyg_disk_identify_t cyg_disk_identify_t;
72
73 typedef struct disk_channel    disk_channel;
74 typedef struct disk_controller disk_controller;
75 typedef struct disk_funs       disk_funs;
76
77 // ---------------------------------------------------------------------------
78
79 // Pointers into upper-level driver
80 typedef struct {
81     
82     // Initialize the disk 
83     cyg_bool (*disk_init)(struct cyg_devtab_entry *tab);
84
85     // Disk device has been connected
86     Cyg_ErrNo (*disk_connected)(struct cyg_devtab_entry *tab,
87                                 cyg_disk_identify_t     *ident);
88
89     // Disk device has been disconnected
90     Cyg_ErrNo (*disk_disconnected)(struct disk_channel *chan);
91
92     // Lookup disk device
93     Cyg_ErrNo (*disk_lookup)(struct cyg_devtab_entry **tab,
94                              struct cyg_devtab_entry  *sub_tab,
95                              const char               *name);
96
97     // Asynchronous block transfer done
98     void (*disk_transfer_done)(struct disk_channel *chan, Cyg_ErrNo res);
99     
100 } disk_callbacks_t;
101
102 #define DISK_CALLBACKS(_l,                      \
103                        _init,                   \
104                        _connected,              \
105                        _disconnected,           \
106                        _lookup,                 \
107                        _transfer_done)          \
108 disk_callbacks_t _l = {                         \
109     _init,                                      \
110     _connected,                                 \
111     _disconnected,                              \
112     _lookup,                                    \
113     _transfer_done                              \
114 };
115
116 extern disk_callbacks_t cyg_io_disk_callbacks;
117
118 // ---------------------------------------------------------------------------
119 // Private data which describes a disk controller
120
121 struct disk_controller {
122     cyg_drv_mutex_t     lock;           // Per-controller lock
123     cyg_drv_cond_t      queue;          // Access wait list
124     cyg_drv_cond_t      async;          // Async transfer waits here
125     void                *priv;          // Private data
126     volatile Cyg_ErrNo  result;         // Last operation result
127     cyg_bool            init;           // Initialized?
128     volatile cyg_bool   busy;           // Busy?
129 };
130
131 #define DISK_CONTROLLER(_l, _priv)              \
132 static disk_controller _l = {                   \
133     priv:       &_priv,                         \
134     init:       false,                          \
135     busy:       false                           \
136 };
137
138 // ---------------------------------------------------------------------------
139 // Private data which describes this channel
140
141 struct disk_channel {
142     disk_funs               *funs;
143     disk_callbacks_t        *callbacks;
144     void                    *dev_priv;    // device private data
145     disk_controller         *controller;  // pointer to controller
146     cyg_disk_info_t         *info;        // disk info 
147     cyg_disk_partition_t    *partition;   // partition data 
148     struct cyg_devtab_entry *pdevs_dev;   // partition devs devtab ents 
149     disk_channel            *pdevs_chan;  // partition devs disk chans 
150     cyg_bool                 mbr_support; // true if disk has MBR
151     cyg_bool                 valid;       // true if device valid 
152     cyg_bool                 init;        // true if initialized
153     cyg_ucount16             mounts;      // count of number of mounts
154 };
155
156 // Initialization macro for disk channel
157 #define DISK_CHANNEL(_l,                                              \
158                      _funs,                                           \
159                      _dev_priv,                                       \
160                      _controller,                                     \
161                      _mbr_supp,                                       \
162                      _max_part_num)                                   \
163 static struct cyg_devtab_entry _l##_part_dev[_max_part_num];          \
164 static disk_channel            _l##_part_chan[_max_part_num];         \
165 static cyg_disk_partition_t    _l##_part_tab[_max_part_num];          \
166 static cyg_disk_info_t         _l##_disk_info = {                     \
167     _l##_part_tab,                                                    \
168     _max_part_num                                                     \
169 };                                                                    \
170 static disk_channel _l = {                                            \
171     &(_funs),                                                         \
172     &cyg_io_disk_callbacks,                                           \
173     &(_dev_priv),                                                     \
174     &(_controller),                                                   \
175     &(_l##_disk_info),                                                \
176     NULL,                                                             \
177     _l##_part_dev,                                                    \
178     _l##_part_chan,                                                   \
179     _mbr_supp,                                                        \
180     false,                                                            \
181     false,                                                            \
182     0                                                                 \
183 };
184
185 // Initialization macro for disk channel allocated elsewhere.
186 #define DISK_CHANNEL_INIT(_dc,                           \
187                           _funs,                         \
188                           _dev_priv,                     \
189                           _controller,                   \
190                           _disk_info,                    \
191                           _part_dev,                     \
192                           _part_chan,                    \
193                           _part_tab,                     \
194                           _mbr_supp,                     \
195                           _max_part_num)                 \
196     CYG_MACRO_START                                      \
197     memset((_disk_info), 0, sizeof(cyg_disk_info_t));    \
198     (_dc).funs = &(_funs);                               \
199     (_dc).callbacks = &cyg_io_disk_callbacks;            \
200     (_dc).dev_priv = (_dev_priv);                        \
201     (_dc).controller = &(_controller);                   \
202     (_dc).info = &(_disk_info);                          \
203     (_dc).info->partitions = (_part_tab);                \
204     (_dc).pdevs_dev = (_part_dev);                       \
205     (_dc).pdevs_chan = (_part_chan);                     \
206     (_dc).partition = NULL;                              \
207     (_dc).mbr_support = (_mbr_supp);                     \
208     (_dc).valid = false;                                 \
209     (_dc).init = false;                                  \
210     (_dc).mounts = 0;                                    \
211     (_dc).info->partitions_num = (_max_part_num);        \
212     CYG_MACRO_END
213
214 // ---------------------------------------------------------------------------
215 // Low level interface functions
216
217 struct disk_funs {
218
219     // Read block data into buf
220     Cyg_ErrNo (*read)(disk_channel *priv, 
221                       void         *buf, 
222                       cyg_uint32    len,
223                       cyg_uint32    block_num);
224     
225     // Write block data from buf
226     Cyg_ErrNo (*write)(disk_channel *priv, 
227                        const void   *buf, 
228                        cyg_uint32    len,
229                        cyg_uint32    block_num);
230     
231     // Get hardware configuration
232     Cyg_ErrNo (*get_config)(disk_channel *priv, 
233                             cyg_uint32    key, 
234                             const void   *xbuf, 
235                             cyg_uint32   *len);
236     
237     // Set hardware configuration
238     Cyg_ErrNo (*set_config)(disk_channel *priv, 
239                             cyg_uint32    key, 
240                             const void   *xbuf, 
241                             cyg_uint32   *len);
242 };
243
244 #define DISK_FUNS(_l,_read,_write,_get_config,_set_config)           \
245 static disk_funs _l = {                                              \
246   _read,                                                             \
247   _write,                                                            \
248   _get_config,                                                       \
249   _set_config                                                        \
250 };
251
252 extern cyg_devio_table_t cyg_io_disk_devio;
253
254 // ---------------------------------------------------------------------------
255
256 #include <cyg/io/diskio.h>
257
258 // ---------------------------------------------------------------------------
259 #endif // CYGONCE_DISK_H