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