source: rtems/cpukit/libblock/include/rtems/blkdev.h @ 57aa979

4.104.11
Last change on this file since 57aa979 was 57aa979, checked in by Chris Johns <chrisj@…>, on Apr 29, 2009 at 8:51:07 AM

2009-04-29 Sebastian Huber <sebastian.huber@…>

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