[b80dd59d] | 1 | /** |
---|
| 2 | * @file rtems/blkdev.h |
---|
| 3 | * block device driver interface definitions |
---|
| 4 | */ |
---|
| 5 | |
---|
[8b96149] | 6 | /* |
---|
[e51bd96] | 7 | * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia |
---|
| 8 | * Author: Victor V. Vengerov <vvv@oktet.ru> |
---|
| 9 | * |
---|
| 10 | * @(#) $Id$ |
---|
| 11 | */ |
---|
| 12 | |
---|
[a6f5d89] | 13 | #ifndef _RTEMS_BLKDEV_H |
---|
| 14 | #define _RTEMS_BLKDEV_H |
---|
[e51bd96] | 15 | |
---|
| 16 | #include <rtems.h> |
---|
| 17 | #include <sys/ioctl.h> |
---|
| 18 | |
---|
| 19 | #ifdef __cplusplus |
---|
| 20 | extern "C" { |
---|
| 21 | #endif |
---|
| 22 | |
---|
[3899a537] | 23 | /* |
---|
| 24 | * Interface with device drivers Block device looks, initialized and behaves |
---|
| 25 | * like traditional RTEMS device driver. Heart of the block device driver is in |
---|
| 26 | * BIOREQUEST ioctl. This call puts I/O request to the block device queue, in |
---|
| 27 | * priority order, for asynchronous processing. When driver executes request, |
---|
| 28 | * req_done function invoked, so callee knows about it. Look for details below. |
---|
[e51bd96] | 29 | */ |
---|
| 30 | |
---|
[3899a537] | 31 | /* |
---|
| 32 | * Block device block number datatype |
---|
| 33 | */ |
---|
| 34 | typedef uint32_t rtems_blkdev_bnum; |
---|
[e51bd96] | 35 | |
---|
| 36 | /* Block device request type */ |
---|
[3899a537] | 37 | typedef enum rtems_blkdev_request_op { |
---|
| 38 | RTEMS_BLKDEV_REQ_READ, /* Read operation */ |
---|
| 39 | RTEMS_BLKDEV_REQ_WRITE, /* Write operation */ |
---|
| 40 | RTEMS_BLKDEV_CAPABILITIES /* Capabilities request */ |
---|
| 41 | } rtems_blkdev_request_op; |
---|
| 42 | |
---|
| 43 | /** |
---|
| 44 | * ATA multi-sector buffer requests only supported. This option |
---|
| 45 | * means the cache will only supply multiple buffers that are |
---|
| 46 | * inorder so the ATA multi-sector command can be used. This is a |
---|
| 47 | * hack to work around the current ATA driver. |
---|
| 48 | */ |
---|
| 49 | #define RTEMS_BLKDEV_CAP_MULTISECTOR_CONT (1 << 0) |
---|
[e51bd96] | 50 | |
---|
[3899a537] | 51 | /* |
---|
| 52 | * @typedef rtems_blkdev_request_cb |
---|
[e51bd96] | 53 | * |
---|
[3899a537] | 54 | * Type for block device request done callback function. |
---|
| 55 | * |
---|
| 56 | * @param arg Argument supplied in blkdev_request |
---|
| 57 | * @param status RTEMS status code for this operation |
---|
| 58 | * @param errno errno value to be passed to the user when |
---|
[e51bd96] | 59 | * status != RTEMS_SUCCESSFUL |
---|
| 60 | */ |
---|
[3899a537] | 61 | typedef void (* rtems_blkdev_request_cb)(void *arg, |
---|
| 62 | rtems_status_code status, |
---|
| 63 | int error); |
---|
[e51bd96] | 64 | |
---|
[3899a537] | 65 | /** |
---|
| 66 | * @struct rtems_blkdev_sg_buffer |
---|
[e51bd96] | 67 | * Block device scatter/gather buffer structure |
---|
| 68 | */ |
---|
[3899a537] | 69 | typedef struct rtems_blkdev_sg_buffer { |
---|
| 70 | uint32_t block; /* The block number */ |
---|
[c01d95b7] | 71 | uint32_t length; /* Buffer length */ |
---|
[3899a537] | 72 | void *buffer; /* Buffer pointer */ |
---|
| 73 | void *user; /* User pointer */ |
---|
| 74 | } rtems_blkdev_sg_buffer; |
---|
[e51bd96] | 75 | |
---|
| 76 | /* blkdev_request (Block Device Request) structure is |
---|
[8b96149] | 77 | * used to read/write a number of blocks from/to device. |
---|
[e51bd96] | 78 | */ |
---|
[3899a537] | 79 | typedef struct rtems_blkdev_request { |
---|
| 80 | /* Block device operation (read or write) */ |
---|
| 81 | rtems_blkdev_request_op req; |
---|
| 82 | /* Callback function */ |
---|
| 83 | rtems_blkdev_request_cb req_done; |
---|
| 84 | /* Argument to be passed to callback function*/ |
---|
| 85 | void *done_arg; |
---|
| 86 | /* Last I/O operation completion status */ |
---|
| 87 | rtems_status_code status; |
---|
| 88 | /* If status != RTEMS_SUCCESSFUL, this field contains error code */ |
---|
| 89 | int error; |
---|
[2eb89ad] | 90 | /* Number of blocks for this request. */ |
---|
[3899a537] | 91 | uint32_t bufnum; |
---|
| 92 | |
---|
| 93 | /* The task requesting the IO operation. */ |
---|
| 94 | rtems_id io_task; |
---|
| 95 | |
---|
| 96 | /* List of scatter/gather buffers */ |
---|
| 97 | rtems_blkdev_sg_buffer bufs[0]; |
---|
| 98 | } rtems_blkdev_request; |
---|
[e51bd96] | 99 | |
---|
[2eb89ad] | 100 | /* The start block in a request. Only valid if the driver has returned the |
---|
| 101 | * RTEMS_BLKDEV_CAPABILITIES of RTEMS_BLKDEV_CAP_MULTISECTOR_CONT */ |
---|
| 102 | #define RTEMS_BLKDEV_START_BLOCK(_r) (_r->bufs[0].block) |
---|
| 103 | |
---|
[e51bd96] | 104 | /* Block device IOCTL request codes */ |
---|
[3899a537] | 105 | #define RTEMS_BLKIO_REQUEST _IOWR('B', 1, rtems_blkdev_request) |
---|
| 106 | #define RTEMS_BLKIO_GETBLKSIZE _IO('B', 2) |
---|
| 107 | #define RTEMS_BLKIO_GETSIZE _IO('B', 3) |
---|
| 108 | #define RTEMS_BLKIO_SYNCDEV _IO('B', 4) |
---|
[e51bd96] | 109 | |
---|
| 110 | /* Device driver interface conventions suppose that driver may |
---|
[8b96149] | 111 | * contain initialize/open/close/read/write/ioctl entry points. These |
---|
| 112 | * primitives (except initialize) can be implemented in generic fashion, |
---|
[e51bd96] | 113 | * based upon supplied block device driver ioctl handler. Every block |
---|
| 114 | * device driver should provide initialize entry point, which is register |
---|
| 115 | * all block devices and appropriate ioctl handlers. |
---|
| 116 | */ |
---|
| 117 | |
---|
[3899a537] | 118 | #define RTEMS_GENERIC_BLOCK_DEVICE_DRIVER_ENTRIES \ |
---|
[e51bd96] | 119 | rtems_blkdev_generic_open, rtems_blkdev_generic_close, \ |
---|
| 120 | rtems_blkdev_generic_read, rtems_blkdev_generic_write, \ |
---|
| 121 | rtems_blkdev_generic_ioctl |
---|
| 122 | |
---|
| 123 | /* blkdev_generic_read -- |
---|
| 124 | * Generic block device read primitive. Implemented using block device |
---|
| 125 | * buffer management primitives. |
---|
| 126 | */ |
---|
| 127 | rtems_device_driver |
---|
| 128 | rtems_blkdev_generic_read( |
---|
| 129 | rtems_device_major_number major, |
---|
| 130 | rtems_device_minor_number minor, |
---|
| 131 | void * arg |
---|
| 132 | ); |
---|
| 133 | |
---|
| 134 | /* blkdev_generic_write -- |
---|
[8b96149] | 135 | * Generic block device driver write primitive. Implemented using block |
---|
| 136 | * device buffer management primitives. |
---|
[e51bd96] | 137 | */ |
---|
| 138 | rtems_device_driver |
---|
| 139 | rtems_blkdev_generic_write( |
---|
| 140 | rtems_device_major_number major, |
---|
| 141 | rtems_device_minor_number minor, |
---|
| 142 | void * arg |
---|
| 143 | ); |
---|
| 144 | |
---|
| 145 | /* blkdev_generic_open -- |
---|
| 146 | * Generic block device open primitive. |
---|
| 147 | */ |
---|
| 148 | rtems_device_driver |
---|
| 149 | rtems_blkdev_generic_open( |
---|
| 150 | rtems_device_major_number major, |
---|
| 151 | rtems_device_minor_number minor, |
---|
| 152 | void * arg |
---|
| 153 | ); |
---|
| 154 | |
---|
| 155 | /* blkdev_generic_close -- |
---|
| 156 | * Generic block device close primitive. |
---|
| 157 | */ |
---|
| 158 | rtems_device_driver |
---|
| 159 | rtems_blkdev_generic_close( |
---|
| 160 | rtems_device_major_number major, |
---|
| 161 | rtems_device_minor_number minor, |
---|
| 162 | void * arg |
---|
| 163 | ); |
---|
| 164 | |
---|
| 165 | /* blkdev_generic_ioctl -- |
---|
| 166 | * Generic block device ioctl primitive. |
---|
| 167 | */ |
---|
| 168 | rtems_device_driver |
---|
| 169 | rtems_blkdev_generic_ioctl( |
---|
| 170 | rtems_device_major_number major, |
---|
| 171 | rtems_device_minor_number minor, |
---|
| 172 | void * arg |
---|
| 173 | ); |
---|
| 174 | |
---|
| 175 | #ifdef __cplusplus |
---|
| 176 | } |
---|
| 177 | #endif |
---|
| 178 | |
---|
| 179 | #endif |
---|