[b80dd59d] | 1 | /** |
---|
[57aa979] | 2 | * @file |
---|
| 3 | * |
---|
[4670d91] | 4 | * @ingroup rtems_blkdev |
---|
| 5 | * |
---|
[57aa979] | 6 | * Block device management. |
---|
[b80dd59d] | 7 | */ |
---|
| 8 | |
---|
[8b96149] | 9 | /* |
---|
[e51bd96] | 10 | * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia |
---|
| 11 | * Author: Victor V. Vengerov <vvv@oktet.ru> |
---|
| 12 | * |
---|
| 13 | * @(#) $Id$ |
---|
| 14 | */ |
---|
| 15 | |
---|
[a6f5d89] | 16 | #ifndef _RTEMS_BLKDEV_H |
---|
| 17 | #define _RTEMS_BLKDEV_H |
---|
[e51bd96] | 18 | |
---|
| 19 | #include <rtems.h> |
---|
| 20 | #include <sys/ioctl.h> |
---|
| 21 | |
---|
| 22 | #ifdef __cplusplus |
---|
| 23 | extern "C" { |
---|
| 24 | #endif |
---|
| 25 | |
---|
[57aa979] | 26 | /** |
---|
| 27 | * @defgroup rtems_blkdev Block Device Management |
---|
| 28 | * |
---|
| 29 | * @ingroup rtems_libblock |
---|
| 30 | * |
---|
[d8602eb] | 31 | * Interface between device drivers and the |
---|
| 32 | * @ref rtems_bdbuf "block device buffer module". |
---|
[57aa979] | 33 | * |
---|
| 34 | * The heart of the block device driver is the @ref RTEMS_BLKIO_REQUEST IO |
---|
| 35 | * control. This call puts IO @ref rtems_blkdev_request "requests" to the block |
---|
| 36 | * device for asynchronous processing. When a driver executes a request, it |
---|
| 37 | * invokes the request done callback function to finish the request. |
---|
| 38 | * |
---|
| 39 | * @{ |
---|
[e51bd96] | 40 | */ |
---|
| 41 | |
---|
[57aa979] | 42 | /** |
---|
| 43 | * Block device block index type. |
---|
[3899a537] | 44 | */ |
---|
| 45 | typedef uint32_t rtems_blkdev_bnum; |
---|
[e51bd96] | 46 | |
---|
[57aa979] | 47 | /** |
---|
| 48 | * Block device request type. |
---|
| 49 | */ |
---|
[3899a537] | 50 | typedef enum rtems_blkdev_request_op { |
---|
[57aa979] | 51 | RTEMS_BLKDEV_REQ_READ, |
---|
| 52 | RTEMS_BLKDEV_REQ_WRITE, |
---|
| 53 | RTEMS_BLKDEV_CAPABILITIES |
---|
[3899a537] | 54 | } rtems_blkdev_request_op; |
---|
| 55 | |
---|
| 56 | /** |
---|
[57aa979] | 57 | * Only consecutive multi-sector buffer requests are supported. |
---|
| 58 | * |
---|
| 59 | * This option means the cache will only supply multiple buffers that are |
---|
| 60 | * inorder so the ATA multi-sector command for example can be used. This is a |
---|
[3899a537] | 61 | * hack to work around the current ATA driver. |
---|
| 62 | */ |
---|
| 63 | #define RTEMS_BLKDEV_CAP_MULTISECTOR_CONT (1 << 0) |
---|
[e51bd96] | 64 | |
---|
[57aa979] | 65 | /** |
---|
[3899a537] | 66 | * Type for block device request done callback function. |
---|
| 67 | * |
---|
[57aa979] | 68 | * @param arg Argument supplied in @ref rtems_blkdev_request. |
---|
| 69 | * @param status Status code for this operation. |
---|
| 70 | * @param errno The @c errno value to be passed to the user when status is not |
---|
| 71 | * equal to @c RTEMS_SUCCESSFUL. |
---|
[e51bd96] | 72 | */ |
---|
[3899a537] | 73 | typedef void (* rtems_blkdev_request_cb)(void *arg, |
---|
| 74 | rtems_status_code status, |
---|
| 75 | int error); |
---|
[e51bd96] | 76 | |
---|
[3899a537] | 77 | /** |
---|
[57aa979] | 78 | * Block device scatter or gather buffer structure. |
---|
[e51bd96] | 79 | */ |
---|
[3899a537] | 80 | typedef struct rtems_blkdev_sg_buffer { |
---|
[57aa979] | 81 | /** |
---|
| 82 | * Block index. |
---|
| 83 | */ |
---|
| 84 | rtems_blkdev_bnum block; |
---|
| 85 | |
---|
| 86 | /** |
---|
| 87 | * Buffer length. |
---|
| 88 | */ |
---|
| 89 | uint32_t length; |
---|
| 90 | |
---|
| 91 | /** |
---|
| 92 | * Buffer pointer. |
---|
| 93 | */ |
---|
| 94 | void *buffer; |
---|
| 95 | |
---|
| 96 | /** |
---|
| 97 | * User pointer. |
---|
| 98 | */ |
---|
| 99 | void *user; |
---|
[3899a537] | 100 | } rtems_blkdev_sg_buffer; |
---|
[e51bd96] | 101 | |
---|
[57aa979] | 102 | /** |
---|
[d8602eb] | 103 | * The block device request structure is used to read or write a number of |
---|
[57aa979] | 104 | * blocks from or to the device. |
---|
[e51bd96] | 105 | */ |
---|
[3899a537] | 106 | typedef struct rtems_blkdev_request { |
---|
[57aa979] | 107 | /** |
---|
| 108 | * Block device operation (read or write). |
---|
| 109 | */ |
---|
| 110 | rtems_blkdev_request_op req; |
---|
| 111 | |
---|
| 112 | /** |
---|
| 113 | * Request done callback function. |
---|
| 114 | */ |
---|
| 115 | rtems_blkdev_request_cb req_done; |
---|
| 116 | |
---|
| 117 | /** |
---|
| 118 | * Argument to be passed to callback function. |
---|
| 119 | */ |
---|
| 120 | void *done_arg; |
---|
| 121 | |
---|
| 122 | /** |
---|
| 123 | * Last IO operation completion status. |
---|
| 124 | */ |
---|
| 125 | rtems_status_code status; |
---|
| 126 | |
---|
| 127 | /** |
---|
| 128 | * If @c status is not equal to @c RTEMS_SUCCESSFUL, this field contains the |
---|
| 129 | * error number. |
---|
| 130 | */ |
---|
| 131 | int error; |
---|
| 132 | |
---|
| 133 | /** |
---|
| 134 | * Number of blocks for this request. |
---|
| 135 | */ |
---|
| 136 | uint32_t bufnum; |
---|
| 137 | |
---|
| 138 | /** |
---|
| 139 | * The task requesting the IO operation. |
---|
| 140 | */ |
---|
| 141 | rtems_id io_task; |
---|
| 142 | |
---|
| 143 | /** |
---|
| 144 | * List of scatter or gather buffers. |
---|
| 145 | */ |
---|
| 146 | rtems_blkdev_sg_buffer bufs[0]; |
---|
[3899a537] | 147 | } rtems_blkdev_request; |
---|
[e51bd96] | 148 | |
---|
[57aa979] | 149 | /** |
---|
| 150 | * The start block in a request. |
---|
| 151 | * |
---|
| 152 | * Only valid if the driver has returned the @ref RTEMS_BLKDEV_CAPABILITIES of |
---|
| 153 | * @ref RTEMS_BLKDEV_CAP_MULTISECTOR_CONT. |
---|
| 154 | */ |
---|
| 155 | #define RTEMS_BLKDEV_START_BLOCK(req) (req->bufs[0].block) |
---|
[e51bd96] | 156 | |
---|
[57aa979] | 157 | /** |
---|
| 158 | * @name IO Control Request Codes |
---|
| 159 | * |
---|
| 160 | * @{ |
---|
[e51bd96] | 161 | */ |
---|
| 162 | |
---|
[57aa979] | 163 | #define RTEMS_BLKIO_REQUEST _IOWR('B', 1, rtems_blkdev_request) |
---|
| 164 | #define RTEMS_BLKIO_GETBLKSIZE _IO('B', 2) |
---|
| 165 | #define RTEMS_BLKIO_GETSIZE _IO('B', 3) |
---|
| 166 | #define RTEMS_BLKIO_SYNCDEV _IO('B', 4) |
---|
| 167 | |
---|
| 168 | /** @} */ |
---|
| 169 | |
---|
| 170 | /** |
---|
| 171 | * The device driver interface conventions suppose that a driver may contain an |
---|
| 172 | * initialize, open, close, read, write and IO control entry points. These |
---|
| 173 | * primitives (except initialize) can be implemented in a generic fashion based |
---|
| 174 | * upon the supplied block device driver IO control handler. Every block device |
---|
| 175 | * driver should provide an initialize entry point, which registers the |
---|
| 176 | * appropriate IO control handler. |
---|
| 177 | */ |
---|
[3899a537] | 178 | #define RTEMS_GENERIC_BLOCK_DEVICE_DRIVER_ENTRIES \ |
---|
[57aa979] | 179 | .open_entry = rtems_blkdev_generic_open, \ |
---|
| 180 | .close_entry = rtems_blkdev_generic_close, \ |
---|
| 181 | .read_entry = rtems_blkdev_generic_read, \ |
---|
| 182 | .write_entry = rtems_blkdev_generic_write, \ |
---|
| 183 | .control_entry = rtems_blkdev_generic_ioctl |
---|
[e51bd96] | 184 | |
---|
[57aa979] | 185 | /** |
---|
| 186 | * Generic block device read primitive. |
---|
| 187 | * |
---|
| 188 | * Implemented using block device buffer management primitives. |
---|
[e51bd96] | 189 | */ |
---|
| 190 | rtems_device_driver |
---|
| 191 | rtems_blkdev_generic_read( |
---|
| 192 | rtems_device_major_number major, |
---|
| 193 | rtems_device_minor_number minor, |
---|
| 194 | void * arg |
---|
| 195 | ); |
---|
| 196 | |
---|
[57aa979] | 197 | /** |
---|
| 198 | * Generic block device write primitive. |
---|
| 199 | * |
---|
| 200 | * Implemented using block device buffer management primitives. |
---|
[e51bd96] | 201 | */ |
---|
| 202 | rtems_device_driver |
---|
| 203 | rtems_blkdev_generic_write( |
---|
| 204 | rtems_device_major_number major, |
---|
| 205 | rtems_device_minor_number minor, |
---|
| 206 | void * arg |
---|
| 207 | ); |
---|
| 208 | |
---|
[57aa979] | 209 | /** |
---|
| 210 | * Generic block device open primitive. |
---|
| 211 | * |
---|
| 212 | * Implemented using block device buffer management primitives. |
---|
[e51bd96] | 213 | */ |
---|
| 214 | rtems_device_driver |
---|
| 215 | rtems_blkdev_generic_open( |
---|
| 216 | rtems_device_major_number major, |
---|
| 217 | rtems_device_minor_number minor, |
---|
| 218 | void * arg |
---|
| 219 | ); |
---|
| 220 | |
---|
[57aa979] | 221 | /** |
---|
| 222 | * Generic block device close primitive. |
---|
| 223 | * |
---|
| 224 | * Implemented using block device buffer management primitives. |
---|
[e51bd96] | 225 | */ |
---|
| 226 | rtems_device_driver |
---|
| 227 | rtems_blkdev_generic_close( |
---|
| 228 | rtems_device_major_number major, |
---|
| 229 | rtems_device_minor_number minor, |
---|
| 230 | void * arg |
---|
| 231 | ); |
---|
| 232 | |
---|
[57aa979] | 233 | /** |
---|
| 234 | * Generic block device IO control primitive. |
---|
| 235 | * |
---|
| 236 | * Implemented using block device buffer management primitives. |
---|
[e51bd96] | 237 | */ |
---|
| 238 | rtems_device_driver |
---|
| 239 | rtems_blkdev_generic_ioctl( |
---|
| 240 | rtems_device_major_number major, |
---|
| 241 | rtems_device_minor_number minor, |
---|
| 242 | void * arg |
---|
| 243 | ); |
---|
| 244 | |
---|
[57aa979] | 245 | /** @} */ |
---|
| 246 | |
---|
[e51bd96] | 247 | #ifdef __cplusplus |
---|
| 248 | } |
---|
| 249 | #endif |
---|
| 250 | |
---|
| 251 | #endif |
---|