source: rtems/cpukit/include/rtems/nvdisk.h @ 0fb724a

5
Last change on this file since 0fb724a was 0fb724a, checked in by Sebastian Huber <sebastian.huber@…>, on 03/12/18 at 09:04:11

libblock: C++ compatibility

  • Property mode set to 100644
File size: 6.7 KB
Line 
1/**
2 * @file rtems/nvdisk.h
3 *
4 * @brief Non-volatile Disk Block Device Implementation
5 */
6
7/*
8 * Copyright (C) 2007 Chris Johns
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15/**
16 * The Non-volatile disk provides a simple directly mapped disk
17 * driver with checksums for each. It is designed to provied a
18 * disk that can survive a restart. Examples are EEPROM devices
19 * which have byte writeable locations, or a battery backed up
20 * RAM disk.
21 *
22 * The low level driver provides the physical access to the
23 * hardware.
24 */
25#if !defined (_RTEMS_NVDISK_H_)
26#define _RTEMS_NVDISK_H_
27
28#include <stdint.h>
29#include <sys/ioctl.h>
30
31#include <rtems.h>
32
33#ifdef __cplusplus
34extern "C" {
35#endif /* __cplusplus */
36
37/**
38 * The base name of the nv disks.
39 */
40#define RTEMS_NVDISK_DEVICE_BASE_NAME "/dev/nvd"
41
42/**
43 * NV disk specific ioctl request types. To use open the
44 * device and issue the ioctl call.
45 *
46 * @code
47 *  int fd = open ("/dev/nvdisk0", O_WRONLY, 0);
48 *  if (fd < 0)
49 *  {
50 *    printf ("driver open failed: %s\n", strerror (errno));
51 *    exit (1);
52 *  }
53 *  if (ioctl (fd, RTEMS_NVDISK_IOCTL_ERASE_DISK) < 0)
54 *  {
55 *    printf ("driver erase failed: %s\n", strerror (errno));
56 *    exit (1);
57 *  }
58 *  close (fd);
59 * @endcode
60 */
61#define RTEMS_NVDISK_IOCTL_ERASE_DISK   _IO('B', 128)
62#define RTEMS_NVDISK_IOCTL_MONITORING   _IO('B', 129)
63#define RTEMS_NVDISK_IOCTL_INFO_LEVEL   _IO('B', 130)
64#define RTEMS_NVDISK_IOCTL_PRINT_STATUS _IO('B', 131)
65
66/**
67 * NV Disk Monitoring Data allows a user to obtain
68 * the current status of the disk.
69 */
70typedef struct rtems_nvdisk_monitor_data
71{
72  uint32_t block_size;
73  uint32_t block_count;
74  uint32_t page_count;
75  uint32_t pages_available;
76  uint32_t pages_used;
77  uint32_t info_level;
78} rtems_nvdisk_monitor_data;
79
80/**
81 * Return the number of kilo-bytes.
82 */
83#define RTEMS_NVDISK_KBYTES(_k) ((_k) * 1024)
84
85/**
86 * NV Low Level driver handlers.
87
88 * Typically this structure is part of a table of handlers in the
89 * device which is referenced in the nvdisk configuration table.
90 * The reference is kept in the driver and used all the time to
91 * manage the nv device, therefore it must always exist.
92 */
93typedef struct rtems_nvdisk_driver_handlers
94{
95  /**
96   * Read data from the device into the buffer. Return an errno
97   * error number if the data cannot be read.
98   *
99   * @param device The device to read data from.
100   * @param flags Device specific flags for the driver.
101   * @param base The base address of the device.
102   * @param offset The offset in the segment to read.
103   * @param buffer The buffer to read the data into.
104   * @param size The amount of data to read.
105   * @retval 0 No error.
106   * @retval EIO The read did not complete.
107   */
108  int (*read) (uint32_t device, uint32_t flags, void* base,
109               uint32_t offset, void* buffer, size_t size);
110
111  /**
112   * Write data from the buffer to the device. Return an errno
113   * error number if the device cannot be written to.
114   *
115   * @param device The device to write data to.
116   * @param flags Device specific flags for the driver.
117   * @param base The base address of the device.
118   * @param offset The offset in the device to write to.
119   * @param buffer The buffer to write the data from.
120   * @param size The amount of data to write.
121   * @retval 0 No error.
122   * @retval EIO The write did not complete or verify.
123   */
124  int (*write) (uint32_t device, uint32_t flags, void* base,
125                uint32_t offset, const void* buffer, size_t size);
126
127  /**
128   * Verify data in the buffer to the data in the device. Return an
129   * errno error number if the device cannot be read or the data verified.
130   *
131   * @param device The device to verify the data with.
132   * @param flags Device specific flags for the driver.
133   * @param base The base address of the device.
134   * @param offset The offset in the device to verify.
135   * @param buffer The buffer to verify the data in the device with.
136   * @param size The amount of data to verify.
137   * @retval 0 No error.
138   * @retval EIO The data did not verify.
139   */
140  int (*verify) (uint32_t device, uint32_t flags, void* base,
141                 uint32_t offset, const void* buffer, size_t size);
142
143} rtems_nvdisk_driver_handlers;
144
145/**
146 * NV Device Descriptor holds the description of a device that is
147 * part of the NV disk.
148 *
149 * Typically this structure is part of a table of the device which
150 * is referenced in the nvdisk configuration table.
151 * The reference is kept in the driver and used all the time to
152 * manage the nv device, therefore it must always exist.
153 */
154typedef struct rtems_nvdisk_device_desc
155{
156  uint32_t                            flags;  /**< Private user flags. */
157  void*                               base;   /**< Base address of the device. */
158  uint32_t                            size;   /**< Size of the device. */
159  const rtems_nvdisk_driver_handlers* nv_ops; /**< Device handlers. */
160} rtems_nvdisk_device_desc;
161
162/**
163 * RTEMS Non-Volatile Disk configuration table used to initialise the
164 * driver.
165 */
166typedef struct rtems_nvdisk_config
167{
168  uint32_t                        block_size;   /**< The block size. */
169  uint32_t                        device_count; /**< The number of devices. */
170  const rtems_nvdisk_device_desc* devices;      /**< The device descriptions. */
171  uint32_t                        flags;        /**< Set of flags to control
172                                                     driver. */
173  uint32_t                        info_level;   /**< Default info level. */
174} rtems_nvdisk_config;
175
176/*
177 * Driver flags.
178 */
179
180/**
181 * Check the pages during initialisation to see which pages are
182 * valid and which are not. This could slow down initialising the
183 * disk driver.
184 */
185#define RTEMS_NVDISK_CHECK_PAGES (1 << 0)
186
187/**
188 * Non-volatile disk device driver initialization. Place in a table as the
189 * initialisation entry and remainder of the entries are the RTEMS block
190 * device generic handlers.
191 *
192 * @param major NV disk major device number.
193 * @param minor Minor device number, not applicable.
194 * @param arg Initialization argument, not applicable.
195 * @return The rtems_device_driver is actually just
196 *         rtems_status_code.
197 */
198rtems_device_driver
199rtems_nvdisk_initialize (rtems_device_major_number major,
200                         rtems_device_minor_number minor,
201                         void*                     arg);
202
203/**
204 * External reference to the configuration. Please supply.
205 * Support is present in confdefs.h for providing this variable.
206 */
207extern const rtems_nvdisk_config rtems_nvdisk_configuration[];
208
209/**
210 * External reference to the number of configurations. Please supply.
211 * Support is present in confdefs.h for providing this variable.
212 */
213extern uint32_t rtems_nvdisk_configuration_size;
214
215#ifdef __cplusplus
216}
217#endif /* __cplusplus */
218
219#endif
Note: See TracBrowser for help on using the repository browser.