1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Block Device Disk Management API |
---|
5 | * |
---|
6 | * @ingroup rtems_disk |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia |
---|
11 | * Author: Victor V. Vengerov <vvv@oktet.ru> |
---|
12 | */ |
---|
13 | |
---|
14 | #ifndef _RTEMS_DISKDEVS_H |
---|
15 | #define _RTEMS_DISKDEVS_H |
---|
16 | |
---|
17 | #include <rtems.h> |
---|
18 | #include <rtems/libio.h> |
---|
19 | #include <rtems/chain.h> |
---|
20 | |
---|
21 | #ifdef __cplusplus |
---|
22 | extern "C" { |
---|
23 | #endif |
---|
24 | |
---|
25 | typedef struct rtems_disk_device rtems_disk_device; |
---|
26 | |
---|
27 | /** |
---|
28 | * @defgroup rtems_disk Block Device Disk Management |
---|
29 | * |
---|
30 | * @ingroup rtems_libblock |
---|
31 | * |
---|
32 | * @brief This module provides functions to manage disk devices. |
---|
33 | * |
---|
34 | * A disk is a set of blocks which are identified by a consecutive set of |
---|
35 | * non-negative integers starting at zero. There are also logical disks which |
---|
36 | * contain a subset of consecutive disk blocks. The logical disks are used to |
---|
37 | * represent the partitions of a disk. The disk devices are accessed via the |
---|
38 | * @ref rtems_bdbuf "block device buffer module". |
---|
39 | */ |
---|
40 | /**@{**/ |
---|
41 | |
---|
42 | /** |
---|
43 | * @brief Block device block index type. |
---|
44 | */ |
---|
45 | typedef uint32_t rtems_blkdev_bnum; |
---|
46 | |
---|
47 | /** |
---|
48 | * @brief Block device IO control handler type. |
---|
49 | */ |
---|
50 | typedef int (*rtems_block_device_ioctl)( |
---|
51 | rtems_disk_device *dd, |
---|
52 | uint32_t req, |
---|
53 | void *argp |
---|
54 | ); |
---|
55 | |
---|
56 | /** |
---|
57 | * @brief Trigger value to disable further read-ahead requests. |
---|
58 | */ |
---|
59 | #define RTEMS_DISK_READ_AHEAD_NO_TRIGGER ((rtems_blkdev_bnum) -1) |
---|
60 | |
---|
61 | /** |
---|
62 | * @brief Size value to set number of blocks based on config and disk size. |
---|
63 | */ |
---|
64 | #define RTEMS_DISK_READ_AHEAD_SIZE_AUTO (0) |
---|
65 | |
---|
66 | /** |
---|
67 | * @brief Block device read-ahead control. |
---|
68 | */ |
---|
69 | typedef struct { |
---|
70 | /** |
---|
71 | * @brief Chain node for the read-ahead request queue of the read-ahead task. |
---|
72 | */ |
---|
73 | rtems_chain_node node; |
---|
74 | |
---|
75 | /** |
---|
76 | * @brief Block value to trigger the read-ahead request. |
---|
77 | * |
---|
78 | * A value of @ref RTEMS_DISK_READ_AHEAD_NO_TRIGGER will disable further |
---|
79 | * read-ahead requests (except the ones triggered by @a rtems_bdbuf_peek) |
---|
80 | * since no valid block can have this value. |
---|
81 | */ |
---|
82 | rtems_blkdev_bnum trigger; |
---|
83 | |
---|
84 | /** |
---|
85 | * @brief Start block for the next read-ahead request. |
---|
86 | * |
---|
87 | * In case the trigger value is out of range of valid blocks, this value my |
---|
88 | * be arbitrary. |
---|
89 | */ |
---|
90 | rtems_blkdev_bnum next; |
---|
91 | |
---|
92 | /** |
---|
93 | * @brief Size of the next read-ahead request in blocks. |
---|
94 | * |
---|
95 | * A value of @ref RTEMS_DISK_READ_AHEAD_SIZE_AUTO will try to read the rest |
---|
96 | * of the disk but at most the configured max_read_ahead_blocks. |
---|
97 | */ |
---|
98 | uint32_t nr_blocks; |
---|
99 | } rtems_blkdev_read_ahead; |
---|
100 | |
---|
101 | /** |
---|
102 | * @brief Block device statistics. |
---|
103 | * |
---|
104 | * Integer overflows in the statistic counters may happen. |
---|
105 | */ |
---|
106 | typedef struct { |
---|
107 | /** |
---|
108 | * @brief Read hit count. |
---|
109 | * |
---|
110 | * A read hit occurs in the rtems_bdbuf_read() function in case the block is |
---|
111 | * in the cached or modified state. |
---|
112 | */ |
---|
113 | uint32_t read_hits; |
---|
114 | |
---|
115 | /** |
---|
116 | * @brief Read miss count. |
---|
117 | * |
---|
118 | * A read miss occurs in the rtems_bdbuf_read() function in case the block is |
---|
119 | * in the empty state and a read transfer must be initiated to read the data |
---|
120 | * from the device. |
---|
121 | */ |
---|
122 | uint32_t read_misses; |
---|
123 | |
---|
124 | /** |
---|
125 | * @brief Read-ahead transfer count. |
---|
126 | * |
---|
127 | * Each read-ahead transfer may read multiple blocks. This counts all |
---|
128 | * transfers (including peeks). |
---|
129 | */ |
---|
130 | uint32_t read_ahead_transfers; |
---|
131 | |
---|
132 | /** |
---|
133 | * @brief Read-ahead transfers caused by a peek. |
---|
134 | */ |
---|
135 | uint32_t read_ahead_peeks; |
---|
136 | |
---|
137 | /** |
---|
138 | * @brief Count of blocks transfered from the device. |
---|
139 | */ |
---|
140 | uint32_t read_blocks; |
---|
141 | |
---|
142 | /** |
---|
143 | * @brief Read error count. |
---|
144 | * |
---|
145 | * Error count of transfers issued by the read or read-ahead requests. |
---|
146 | */ |
---|
147 | uint32_t read_errors; |
---|
148 | |
---|
149 | /** |
---|
150 | * @brief Write transfer count. |
---|
151 | * |
---|
152 | * Each write transfer may write multiple blocks. |
---|
153 | */ |
---|
154 | uint32_t write_transfers; |
---|
155 | |
---|
156 | /** |
---|
157 | * @brief Count of blocks transfered to the device. |
---|
158 | */ |
---|
159 | uint32_t write_blocks; |
---|
160 | |
---|
161 | /** |
---|
162 | * @brief Write error count. |
---|
163 | * |
---|
164 | * Error count of transfers issued by write requests. |
---|
165 | */ |
---|
166 | uint32_t write_errors; |
---|
167 | } rtems_blkdev_stats; |
---|
168 | |
---|
169 | /** |
---|
170 | * @brief Description of a disk device (logical and physical disks). |
---|
171 | * |
---|
172 | * An array of pointer tables to rtems_disk_device structures is maintained. |
---|
173 | * The first table will be indexed by the major number and the second table |
---|
174 | * will be indexed by the minor number. This allows quick lookup using a data |
---|
175 | * structure of moderated size. |
---|
176 | */ |
---|
177 | struct rtems_disk_device { |
---|
178 | /** |
---|
179 | * @brief Device identifier (concatenation of major and minor number). |
---|
180 | */ |
---|
181 | dev_t dev; |
---|
182 | |
---|
183 | /** |
---|
184 | * @brief Physical device identifier (equals the @c dev entry if it specifies a |
---|
185 | * physical device). |
---|
186 | */ |
---|
187 | rtems_disk_device *phys_dev; |
---|
188 | |
---|
189 | /** |
---|
190 | * @brief Driver capabilities. |
---|
191 | */ |
---|
192 | uint32_t capabilities; |
---|
193 | |
---|
194 | /** |
---|
195 | * @brief Disk device name. |
---|
196 | */ |
---|
197 | char *name; |
---|
198 | |
---|
199 | /** |
---|
200 | * @brief Usage counter. |
---|
201 | * |
---|
202 | * Devices cannot be deleted if they are in use. |
---|
203 | */ |
---|
204 | unsigned uses; |
---|
205 | |
---|
206 | /** |
---|
207 | * @brief Start media block number. |
---|
208 | * |
---|
209 | * Equals zero for physical devices. It is a media block offset to the |
---|
210 | * related physical device for logical device. |
---|
211 | */ |
---|
212 | rtems_blkdev_bnum start; |
---|
213 | |
---|
214 | /** |
---|
215 | * @brief Size of the physical or logical disk in media blocks. |
---|
216 | */ |
---|
217 | rtems_blkdev_bnum size; |
---|
218 | |
---|
219 | /** |
---|
220 | * @brief Media block size in bytes. |
---|
221 | * |
---|
222 | * This is the media transfer unit the hardware defaults to. |
---|
223 | */ |
---|
224 | uint32_t media_block_size; |
---|
225 | |
---|
226 | /** |
---|
227 | * @brief Block size in bytes. |
---|
228 | * |
---|
229 | * This is the minimum transfer unit. It may be a multiple of the media |
---|
230 | * block size. It must be positive. |
---|
231 | * |
---|
232 | * @see rtems_bdbuf_set_block_size(). |
---|
233 | */ |
---|
234 | uint32_t block_size; |
---|
235 | |
---|
236 | /** |
---|
237 | * @brief Block count. |
---|
238 | * |
---|
239 | * @see rtems_bdbuf_set_block_size(). |
---|
240 | */ |
---|
241 | rtems_blkdev_bnum block_count; |
---|
242 | |
---|
243 | /** |
---|
244 | * @brief Media blocks per device blocks. |
---|
245 | * |
---|
246 | * @see rtems_bdbuf_set_block_size(). |
---|
247 | */ |
---|
248 | uint32_t media_blocks_per_block; |
---|
249 | |
---|
250 | /** |
---|
251 | * @brief Block to media block shift. |
---|
252 | * |
---|
253 | * In case this value is non-negative the media block of a block can be |
---|
254 | * calculated as media block = block << block_to_media_block_shift, otherwise |
---|
255 | * a 64-bit operation will be used. |
---|
256 | * |
---|
257 | * @see rtems_bdbuf_set_block_size(). |
---|
258 | */ |
---|
259 | int block_to_media_block_shift; |
---|
260 | |
---|
261 | /** |
---|
262 | * @brief Buffer descriptors per group count. |
---|
263 | * |
---|
264 | * @see rtems_bdbuf_set_block_size(). |
---|
265 | */ |
---|
266 | size_t bds_per_group; |
---|
267 | |
---|
268 | /** |
---|
269 | * @brief IO control handler for this disk. |
---|
270 | */ |
---|
271 | rtems_block_device_ioctl ioctl; |
---|
272 | |
---|
273 | /** |
---|
274 | * @brief Private data for the disk driver. |
---|
275 | */ |
---|
276 | void *driver_data; |
---|
277 | |
---|
278 | /** |
---|
279 | * @brief Indicates that this disk should be deleted as soon as the last user |
---|
280 | * releases this disk. |
---|
281 | */ |
---|
282 | bool deleted; |
---|
283 | |
---|
284 | /** |
---|
285 | * @brief Device statistics for this disk. |
---|
286 | */ |
---|
287 | rtems_blkdev_stats stats; |
---|
288 | |
---|
289 | /** |
---|
290 | * @brief Read-ahead control for this disk. |
---|
291 | */ |
---|
292 | rtems_blkdev_read_ahead read_ahead; |
---|
293 | }; |
---|
294 | |
---|
295 | /** |
---|
296 | * @name Disk Device Data |
---|
297 | */ |
---|
298 | /**@{**/ |
---|
299 | |
---|
300 | /* Use fstat() instead */ |
---|
301 | RTEMS_DEPRECATED static inline dev_t rtems_disk_get_device_identifier( |
---|
302 | const rtems_disk_device *dd |
---|
303 | ) |
---|
304 | { |
---|
305 | return dd->dev; |
---|
306 | } |
---|
307 | |
---|
308 | /* Use fstat() instead */ |
---|
309 | RTEMS_DEPRECATED static inline rtems_device_major_number rtems_disk_get_major_number( |
---|
310 | const rtems_disk_device *dd |
---|
311 | ) |
---|
312 | { |
---|
313 | return rtems_filesystem_dev_major_t(dd->dev); |
---|
314 | } |
---|
315 | |
---|
316 | /* Use fstat() instead */ |
---|
317 | RTEMS_DEPRECATED static inline rtems_device_minor_number rtems_disk_get_minor_number( |
---|
318 | const rtems_disk_device *dd |
---|
319 | ) |
---|
320 | { |
---|
321 | return rtems_filesystem_dev_minor_t(dd->dev); |
---|
322 | } |
---|
323 | |
---|
324 | static inline void *rtems_disk_get_driver_data( |
---|
325 | const rtems_disk_device *dd |
---|
326 | ) |
---|
327 | { |
---|
328 | return dd->driver_data; |
---|
329 | } |
---|
330 | |
---|
331 | static inline uint32_t rtems_disk_get_media_block_size( |
---|
332 | const rtems_disk_device *dd |
---|
333 | ) |
---|
334 | { |
---|
335 | return dd->media_block_size; |
---|
336 | } |
---|
337 | |
---|
338 | static inline uint32_t rtems_disk_get_block_size( |
---|
339 | const rtems_disk_device *dd |
---|
340 | ) |
---|
341 | { |
---|
342 | return dd->block_size; |
---|
343 | } |
---|
344 | |
---|
345 | static inline rtems_blkdev_bnum rtems_disk_get_block_begin( |
---|
346 | const rtems_disk_device *dd |
---|
347 | ) |
---|
348 | { |
---|
349 | return dd->start; |
---|
350 | } |
---|
351 | |
---|
352 | static inline rtems_blkdev_bnum rtems_disk_get_block_count( |
---|
353 | const rtems_disk_device *dd |
---|
354 | ) |
---|
355 | { |
---|
356 | return dd->size; |
---|
357 | } |
---|
358 | |
---|
359 | /** @} */ |
---|
360 | |
---|
361 | /** |
---|
362 | * @name Disk Device Maintainance |
---|
363 | */ |
---|
364 | /**@{**/ |
---|
365 | |
---|
366 | /* Use rtems_blkdev_create() instead */ |
---|
367 | RTEMS_DEPRECATED rtems_status_code rtems_disk_create_phys( |
---|
368 | dev_t dev, |
---|
369 | uint32_t block_size, |
---|
370 | rtems_blkdev_bnum block_count, |
---|
371 | rtems_block_device_ioctl handler, |
---|
372 | void *driver_data, |
---|
373 | const char *name |
---|
374 | ); |
---|
375 | |
---|
376 | /* Use rtems_blkdev_create_partition() instead */ |
---|
377 | RTEMS_DEPRECATED rtems_status_code rtems_disk_create_log( |
---|
378 | dev_t dev, |
---|
379 | dev_t phys, |
---|
380 | rtems_blkdev_bnum block_begin, |
---|
381 | rtems_blkdev_bnum block_count, |
---|
382 | const char *name |
---|
383 | ); |
---|
384 | |
---|
385 | /* |
---|
386 | * Use rtems_blkdev_create() or rtems_blkdev_create_partition and unlink() |
---|
387 | * instead. |
---|
388 | */ |
---|
389 | RTEMS_DEPRECATED rtems_status_code rtems_disk_delete(dev_t dev); |
---|
390 | |
---|
391 | /* |
---|
392 | * Use rtems_blkdev_create() or rtems_blkdev_create_partition and open() |
---|
393 | * instead. |
---|
394 | */ |
---|
395 | RTEMS_DEPRECATED rtems_disk_device *rtems_disk_obtain(dev_t dev); |
---|
396 | |
---|
397 | /* |
---|
398 | * Use rtems_blkdev_create() or rtems_blkdev_create_partition and close() |
---|
399 | * instead. |
---|
400 | */ |
---|
401 | RTEMS_DEPRECATED rtems_status_code rtems_disk_release(rtems_disk_device *dd); |
---|
402 | |
---|
403 | /** @} */ |
---|
404 | |
---|
405 | /** |
---|
406 | * @name Disk Management |
---|
407 | */ |
---|
408 | /**@{**/ |
---|
409 | |
---|
410 | /* Just remove calls to this function */ |
---|
411 | RTEMS_DEPRECATED rtems_status_code rtems_disk_io_initialize(void); |
---|
412 | |
---|
413 | /* Just remove calls to this function */ |
---|
414 | RTEMS_DEPRECATED rtems_status_code rtems_disk_io_done(void); |
---|
415 | |
---|
416 | /** @} */ |
---|
417 | |
---|
418 | /** @} */ |
---|
419 | |
---|
420 | /* |
---|
421 | * This functionality no longer available. There is no global registration for |
---|
422 | * disk devices. |
---|
423 | */ |
---|
424 | RTEMS_DEPRECATED rtems_disk_device *rtems_disk_next(dev_t dev); |
---|
425 | |
---|
426 | /* Internal function, do not use */ |
---|
427 | rtems_status_code rtems_disk_init_phys( |
---|
428 | rtems_disk_device *dd, |
---|
429 | uint32_t block_size, |
---|
430 | rtems_blkdev_bnum block_count, |
---|
431 | rtems_block_device_ioctl handler, |
---|
432 | void *driver_data |
---|
433 | ); |
---|
434 | |
---|
435 | /* Internal function, do not use */ |
---|
436 | rtems_status_code rtems_disk_init_log( |
---|
437 | rtems_disk_device *dd, |
---|
438 | rtems_disk_device *phys_dd, |
---|
439 | rtems_blkdev_bnum block_begin, |
---|
440 | rtems_blkdev_bnum block_count |
---|
441 | ); |
---|
442 | |
---|
443 | #ifdef __cplusplus |
---|
444 | } |
---|
445 | #endif |
---|
446 | |
---|
447 | #endif |
---|