source: rtems/cpukit/libblock/include/rtems/blkdev.h @ e41369ef

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