]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/io/disk/v2_0/include/disk.h
9d21cb6d5164d332271f4841c57cd409616f19ed
[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 Savin Zlobec 
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/io.h>
63 #include <cyg/io/diskio.h>
64 #include <cyg/hal/drv_api.h>
65
66 typedef struct disk_channel disk_channel;
67 typedef struct disk_funs    disk_funs;
68
69 // Pointers into upper-level driver
70 typedef struct {
71     
72     // Initialize the disk 
73     cyg_bool (*disk_init)(struct cyg_devtab_entry *tab);
74
75     // Disk device has been connected
76     Cyg_ErrNo (*disk_connected)(struct cyg_devtab_entry *tab,
77                                 cyg_disk_identify_t     *ident);
78
79     // Disk device has been disconnected
80     Cyg_ErrNo (*disk_disconnected)(struct cyg_devtab_entry *tab);
81
82     // Lookup disk device
83     Cyg_ErrNo (*disk_lookup)(struct cyg_devtab_entry **tab,
84                              struct cyg_devtab_entry  *sub_tab,
85                              const char               *name);
86 } disk_callbacks_t;
87
88 #define DISK_CALLBACKS(_l,                              \
89                        _init,                           \
90                        _connected,                      \
91                        _disconnected,                   \
92                        _lookup)                         \
93 disk_callbacks_t _l = {                                 \
94     _init,                                              \
95     _connected,                                         \
96     _disconnected,                                      \
97     _lookup                                             \
98 };
99
100 extern disk_callbacks_t cyg_io_disk_callbacks;
101
102 // Private data which describes this channel
103 struct disk_channel {
104     disk_funs               *funs;
105     disk_callbacks_t        *callbacks;
106     void                    *dev_priv;    // device private data
107     cyg_disk_info_t         *info;        // disk info 
108     cyg_disk_partition_t    *partition;   // partition data 
109     struct cyg_devtab_entry *pdevs_dev;   // partition devs devtab ents 
110     disk_channel            *pdevs_chan;  // partition devs disk chans 
111     cyg_bool                 mbr_support; // true if disk has MBR
112     cyg_bool                 valid;       // true if device valid 
113     cyg_bool                 init;        // true if initialized
114 };
115
116 // Initialization macro for disk channel
117 #define DISK_CHANNEL(_l,                                              \
118                      _funs,                                           \
119                      _dev_priv,                                       \
120                      _mbr_supp,                                       \
121                      _max_part_num)                                   \
122 static struct cyg_devtab_entry _l##_part_dev[_max_part_num];          \
123 static disk_channel            _l##_part_chan[_max_part_num];         \
124 static cyg_disk_partition_t    _l##_part_tab[_max_part_num];          \
125 static cyg_disk_info_t         _l##_disk_info = {                     \
126     _l##_part_tab,                                                    \
127     _max_part_num                                                     \
128 };                                                                    \
129 static disk_channel _l = {                                            \
130     &(_funs),                                                         \
131     &cyg_io_disk_callbacks,                                           \
132     &(_dev_priv),                                                     \
133     &(_l##_disk_info),                                                \
134     NULL,                                                             \
135     _l##_part_dev,                                                    \
136     _l##_part_chan,                                                   \
137     _mbr_supp,                                                        \
138     false,                                                            \
139     false                                                             \
140 };
141
142 // Low level interface functions
143 struct disk_funs {
144
145     // Read block data into buf
146     Cyg_ErrNo (*read)(disk_channel *priv, 
147                       void         *buf, 
148                       cyg_uint32    len,
149                       cyg_uint32    block_num);
150     
151     // Write block data from buf
152     Cyg_ErrNo (*write)(disk_channel *priv, 
153                        const void   *buf, 
154                        cyg_uint32    len,
155                        cyg_uint32    block_num);
156     
157     // Get hardware configuration
158     Cyg_ErrNo (*get_config)(disk_channel *priv, 
159                             cyg_uint32    key, 
160                             const void   *xbuf, 
161                             cyg_uint32   *len);
162     
163     // Set hardware configuration
164     Cyg_ErrNo (*set_config)(disk_channel *priv, 
165                             cyg_uint32    key, 
166                             const void   *xbuf, 
167                             cyg_uint32   *len);
168 };
169
170 #define DISK_FUNS(_l,_read,_write,_get_config,_set_config)           \
171 disk_funs _l = {                                                     \
172   _read,                                                             \
173   _write,                                                            \
174   _get_config,                                                       \
175   _set_config                                                        \
176 };
177
178 extern cyg_devio_table_t cyg_io_disk_devio;
179
180 #endif // CYGONCE_DISK_H