source: rtems/cpukit/libblock/include/rtems/nvdisk.h @ 72755421

4.104.115
Last change on this file since 72755421 was 72755421, checked in by Chris Johns <chrisj@…>, on 06/12/09 at 02:59:18

2009-06-12 Chris Johns <chrisj@…>

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