[d7001e47] | 1 | /** |
---|
[d0c3b38b] | 2 | * @file |
---|
| 3 | * |
---|
[4670d91] | 4 | * @ingroup rtems_ramdisk |
---|
| 5 | * |
---|
[1560d12] | 6 | * @brief RAM disk block device API. |
---|
[d7001e47] | 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_RAMDISK_H |
---|
| 17 | #define _RTEMS_RAMDISK_H |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | #include <rtems.h> |
---|
[90b2c072] | 21 | #include <rtems/blkdev.h> |
---|
[d7001e47] | 22 | |
---|
[90b2c072] | 23 | #ifdef __cplusplus |
---|
| 24 | extern "C" { |
---|
| 25 | #endif |
---|
[d7001e47] | 26 | |
---|
[d0c3b38b] | 27 | /** |
---|
| 28 | * @defgroup rtems_ramdisk RAM Disk Device |
---|
| 29 | * |
---|
| 30 | * @ingroup rtems_blkdev |
---|
| 31 | * |
---|
| 32 | * @{ |
---|
| 33 | */ |
---|
| 34 | |
---|
| 35 | /** |
---|
[1560d12] | 36 | * @name Static Configuration |
---|
| 37 | * |
---|
| 38 | * @{ |
---|
| 39 | */ |
---|
| 40 | |
---|
| 41 | /** |
---|
| 42 | * @brief RAM disk configuration table entry. |
---|
[d0c3b38b] | 43 | */ |
---|
[d7001e47] | 44 | typedef struct rtems_ramdisk_config { |
---|
[d0c3b38b] | 45 | /** |
---|
[1560d12] | 46 | * @brief RAM disk block size. |
---|
[d0c3b38b] | 47 | */ |
---|
| 48 | uint32_t block_size; |
---|
| 49 | |
---|
| 50 | /** |
---|
[1560d12] | 51 | * @brief Number of blocks on this RAM disk. |
---|
[d0c3b38b] | 52 | */ |
---|
| 53 | rtems_blkdev_bnum block_num; |
---|
| 54 | |
---|
| 55 | /** |
---|
[1560d12] | 56 | * @brief RAM disk location or @c NULL if RAM disk memory should be allocated |
---|
[d0c3b38b] | 57 | * dynamically. |
---|
| 58 | */ |
---|
| 59 | void *location; |
---|
[d7001e47] | 60 | } rtems_ramdisk_config; |
---|
| 61 | |
---|
[d0c3b38b] | 62 | /** |
---|
[1560d12] | 63 | * @brief External reference to the RAM disk configuration table describing |
---|
| 64 | * each RAM disk in the system. |
---|
[d0c3b38b] | 65 | * |
---|
| 66 | * The configuration table is provided by the application. |
---|
| 67 | */ |
---|
| 68 | extern rtems_ramdisk_config rtems_ramdisk_configuration []; |
---|
| 69 | |
---|
| 70 | /** |
---|
[1560d12] | 71 | * @brief External reference the size of the RAM disk configuration table @ref |
---|
| 72 | * rtems_ramdisk_configuration. |
---|
[d0c3b38b] | 73 | * |
---|
| 74 | * The configuration table size is provided by the application. |
---|
[d7001e47] | 75 | */ |
---|
| 76 | extern size_t rtems_ramdisk_configuration_size; |
---|
| 77 | |
---|
[d0c3b38b] | 78 | /** |
---|
[1560d12] | 79 | * @brief RAM disk driver initialization entry point. |
---|
[d7001e47] | 80 | */ |
---|
[d0c3b38b] | 81 | rtems_device_driver ramdisk_initialize( |
---|
| 82 | rtems_device_major_number major, |
---|
| 83 | rtems_device_minor_number minor, |
---|
| 84 | void *arg |
---|
| 85 | ); |
---|
[d7001e47] | 86 | |
---|
[d0c3b38b] | 87 | /** |
---|
| 88 | * RAM disk driver table entry. |
---|
| 89 | */ |
---|
[d7001e47] | 90 | #define RAMDISK_DRIVER_TABLE_ENTRY \ |
---|
[d0c3b38b] | 91 | { \ |
---|
| 92 | .initialization_entry = ramdisk_initialize, \ |
---|
| 93 | RTEMS_GENERIC_BLOCK_DEVICE_DRIVER_ENTRIES \ |
---|
| 94 | } |
---|
| 95 | |
---|
[1560d12] | 96 | #define RAMDISK_DEVICE_BASE_NAME "/dev/rd" |
---|
| 97 | |
---|
| 98 | /** @} */ |
---|
| 99 | |
---|
| 100 | /** |
---|
| 101 | * @name Runtime Configuration |
---|
| 102 | * |
---|
| 103 | * @{ |
---|
| 104 | */ |
---|
| 105 | |
---|
| 106 | /** |
---|
| 107 | * @brief RAM disk descriptor. |
---|
| 108 | */ |
---|
| 109 | typedef struct ramdisk { |
---|
| 110 | /** |
---|
| 111 | * @brief RAM disk block size, the media size. |
---|
| 112 | */ |
---|
| 113 | uint32_t block_size; |
---|
| 114 | |
---|
| 115 | /** |
---|
| 116 | * @brief Number of blocks on this RAM disk. |
---|
| 117 | */ |
---|
| 118 | rtems_blkdev_bnum block_num; |
---|
| 119 | |
---|
| 120 | /** |
---|
| 121 | * @brief RAM disk memory area. |
---|
| 122 | */ |
---|
| 123 | void *area; |
---|
| 124 | |
---|
| 125 | /** |
---|
| 126 | * @brief RAM disk is initialized. |
---|
| 127 | */ |
---|
| 128 | bool initialized; |
---|
| 129 | |
---|
| 130 | /** |
---|
| 131 | * @brief Indicates if memory is allocated by malloc() for this RAM disk. |
---|
| 132 | */ |
---|
| 133 | bool malloced; |
---|
| 134 | |
---|
| 135 | /** |
---|
| 136 | * @brief Trace enable. |
---|
| 137 | */ |
---|
| 138 | bool trace; |
---|
| 139 | } ramdisk; |
---|
| 140 | |
---|
| 141 | extern const rtems_driver_address_table ramdisk_ops; |
---|
| 142 | |
---|
[e41369ef] | 143 | int ramdisk_ioctl(rtems_disk_device *dd, uint32_t req, void *argp); |
---|
| 144 | |
---|
[1560d12] | 145 | /** |
---|
| 146 | * @brief Allocates and initializes a RAM disk descriptor. |
---|
| 147 | * |
---|
| 148 | * The block size will be @a block_size. The block count will be @a |
---|
| 149 | * block_count. The disk storage area begins at @a area_begin. If @a |
---|
| 150 | * area_begin is @c NULL, the memory will be allocated and zeroed. Sets the |
---|
| 151 | * trace enable to @a trace. |
---|
| 152 | * |
---|
| 153 | * @return Pointer to allocated and initialized ramdisk structure, or @c NULL |
---|
| 154 | * if no memory is available. |
---|
| 155 | * |
---|
[e41369ef] | 156 | * @note |
---|
| 157 | * Runtime configuration example: |
---|
[1560d12] | 158 | * @code |
---|
[e41369ef] | 159 | * #include <rtems.h> |
---|
| 160 | * #include <rtems/libio.h> |
---|
| 161 | * #include <rtems/ramdisk.h> |
---|
| 162 | * |
---|
[1560d12] | 163 | * rtems_status_code create_ramdisk( |
---|
| 164 | * const char *disk_name_path, |
---|
| 165 | * uint32_t block_size, |
---|
| 166 | * rtems_blkdev_bnum block_count |
---|
| 167 | * ) |
---|
| 168 | * { |
---|
| 169 | * rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
| 170 | * rtems_device_major_number major = 0; |
---|
| 171 | * ramdisk *rd = NULL; |
---|
| 172 | * dev_t dev = 0; |
---|
[33c3b54d] | 173 | * |
---|
[1560d12] | 174 | * sc = rtems_io_register_driver(0, &ramdisk_ops, &major); |
---|
| 175 | * if (sc != RTEMS_SUCCESSFUL) { |
---|
| 176 | * return RTEMS_UNSATISFIED; |
---|
| 177 | * } |
---|
[33c3b54d] | 178 | * |
---|
[1560d12] | 179 | * rd = ramdisk_allocate(NULL, block_size, block_count, false); |
---|
| 180 | * if (rd == NULL) { |
---|
| 181 | * rtems_io_unregister_driver(major); |
---|
[33c3b54d] | 182 | * |
---|
[1560d12] | 183 | * return RTEMS_UNSATISFIED; |
---|
| 184 | * } |
---|
[33c3b54d] | 185 | * |
---|
[1560d12] | 186 | * dev = rtems_filesystem_make_dev_t(major, 0); |
---|
[33c3b54d] | 187 | * |
---|
[1560d12] | 188 | * sc = rtems_disk_create_phys( |
---|
| 189 | * dev, |
---|
| 190 | * block_size, |
---|
| 191 | * block_count, |
---|
| 192 | * ramdisk_ioctl, |
---|
| 193 | * rd, |
---|
| 194 | * disk_name_path |
---|
| 195 | * ); |
---|
| 196 | * if (sc != RTEMS_SUCCESSFUL) { |
---|
| 197 | * ramdisk_free(rd); |
---|
| 198 | * rtems_io_unregister_driver(major); |
---|
[33c3b54d] | 199 | * |
---|
[1560d12] | 200 | * return RTEMS_UNSATISFIED; |
---|
| 201 | * } |
---|
[33c3b54d] | 202 | * |
---|
[1560d12] | 203 | * return RTEMS_SUCCESSFUL; |
---|
| 204 | * } |
---|
| 205 | * @endcode |
---|
| 206 | */ |
---|
| 207 | ramdisk *ramdisk_allocate( |
---|
| 208 | void *area_begin, |
---|
| 209 | uint32_t block_size, |
---|
| 210 | rtems_blkdev_bnum block_count, |
---|
| 211 | bool trace |
---|
| 212 | ); |
---|
| 213 | |
---|
| 214 | void ramdisk_free(ramdisk *rd); |
---|
| 215 | |
---|
[982ca110] | 216 | /** |
---|
| 217 | * @brief Allocates, initializes and registers a RAM disk. |
---|
| 218 | * |
---|
| 219 | * The block size will be @a block_size. The block count will be @a |
---|
| 220 | * block_count. The disk storage will be allocated. Sets the trace enable to |
---|
| 221 | * @a trace. Registers a device node with disk name path @a disk. The |
---|
| 222 | * registered device number will be returned in @a dev. |
---|
| 223 | * |
---|
| 224 | * @retval RTEMS_SUCCESSFUL Successful operation. |
---|
| 225 | * @retval RTEMS_UNSATISFIED Something is wrong. |
---|
| 226 | */ |
---|
| 227 | rtems_status_code ramdisk_register( |
---|
| 228 | uint32_t block_size, |
---|
| 229 | rtems_blkdev_bnum block_count, |
---|
| 230 | bool trace, |
---|
| 231 | const char *disk, |
---|
| 232 | dev_t *dev |
---|
| 233 | ); |
---|
| 234 | |
---|
[1560d12] | 235 | /** @} */ |
---|
| 236 | |
---|
[d0c3b38b] | 237 | /** @} */ |
---|
[d7001e47] | 238 | |
---|
| 239 | #ifdef __cplusplus |
---|
| 240 | } |
---|
| 241 | #endif |
---|
| 242 | |
---|
| 243 | #endif |
---|