3 // ====================================================================
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
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.
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
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.
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.
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.
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####
47 // Original data: gthomas
49 // Purpose: Internal interfaces for disk I/O drivers
52 //####DESCRIPTIONEND####
54 // ====================================================================
56 // Disk I/O interfaces
58 #include <pkgconf/system.h>
59 #include <pkgconf/io_disk.h>
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() */
67 // ---------------------------------------------------------------------------
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;
73 typedef struct disk_channel disk_channel;
74 typedef struct disk_controller disk_controller;
75 typedef struct disk_funs disk_funs;
77 // ---------------------------------------------------------------------------
79 // Pointers into upper-level driver
82 // Initialize the disk
83 cyg_bool (*disk_init)(struct cyg_devtab_entry *tab);
85 // Disk device has been connected
86 Cyg_ErrNo (*disk_connected)(struct cyg_devtab_entry *tab,
87 cyg_disk_identify_t *ident);
89 // Disk device has been disconnected
90 Cyg_ErrNo (*disk_disconnected)(struct disk_channel *chan);
93 Cyg_ErrNo (*disk_lookup)(struct cyg_devtab_entry **tab,
94 struct cyg_devtab_entry *sub_tab,
97 // Asynchronous block transfer done
98 void (*disk_transfer_done)(struct disk_channel *chan, Cyg_ErrNo res);
102 #define DISK_CALLBACKS(_l, \
108 disk_callbacks_t _l = { \
116 extern disk_callbacks_t cyg_io_disk_callbacks;
118 // ---------------------------------------------------------------------------
119 // Private data which describes a disk controller
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?
131 #define DISK_CONTROLLER(_l, _priv) \
132 static disk_controller _l = { \
138 // ---------------------------------------------------------------------------
139 // Private data which describes this channel
141 struct disk_channel {
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
156 // Initialization macro for disk channel
157 #define DISK_CHANNEL(_l, \
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 = { \
170 static disk_channel _l = { \
172 &cyg_io_disk_callbacks, \
185 // Initialization macro for disk channel allocated elsewhere.
186 #define DISK_CHANNEL_INIT(_dc, \
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; \
211 (_dc).info->partitions_num = (_max_part_num); \
214 // ---------------------------------------------------------------------------
215 // Low level interface functions
219 // Read block data into buf
220 Cyg_ErrNo (*read)(disk_channel *priv,
223 cyg_uint32 block_num);
225 // Write block data from buf
226 Cyg_ErrNo (*write)(disk_channel *priv,
229 cyg_uint32 block_num);
231 // Get hardware configuration
232 Cyg_ErrNo (*get_config)(disk_channel *priv,
237 // Set hardware configuration
238 Cyg_ErrNo (*set_config)(disk_channel *priv,
244 #define DISK_FUNS(_l,_read,_write,_get_config,_set_config) \
245 static disk_funs _l = { \
252 extern cyg_devio_table_t cyg_io_disk_devio;
254 // ---------------------------------------------------------------------------
256 #include <cyg/io/diskio.h>
258 // ---------------------------------------------------------------------------
259 #endif // CYGONCE_DISK_H