source: rtems/cpukit/libblock/include/rtems/flashdisk.h @ 21242c2

4.115
Last change on this file since 21242c2 was 21242c2, checked in by Joel Sherrill <joel.sherrill@…>, on 06/24/11 at 17:52:58

2011-06-24 Joel Sherrill <joel.sherrill@…>

  • include/rtems/bspIo.h, include/rtems/concat.h, include/rtems/endian.h, include/rtems/fs.h, include/rtems/irq.h, include/rtems/pci.h, include/rtems/userenv.h, libblock/include/rtems/flashdisk.h, libblock/include/rtems/nvdisk-sram.h, libblock/include/rtems/nvdisk.h, libcsupport/include/clockdrv.h, libcsupport/include/console.h, libcsupport/include/iosupp.h, libcsupport/include/spurious.h, libcsupport/include/motorola/mc68230.h, libcsupport/include/rtems/assoc.h, libcsupport/include/rtems/error.h, libcsupport/include/rtems/framebuffer.h, libcsupport/include/rtems/gxx_wrappers.h, libcsupport/include/rtems/libcsupport.h, libcsupport/include/rtems/libio_.h, libcsupport/include/rtems/malloc.h, libcsupport/include/rtems/termiostypes.h, libcsupport/include/sys/statvfs.h, libcsupport/include/sys/termios.h, libcsupport/include/sys/utsname.h, libcsupport/include/zilog/z8036.h, libcsupport/include/zilog/z8530.h, libcsupport/include/zilog/z8536.h, libfs/src/imfs/imfs.h, libfs/src/pipe/pipe.h, libmisc/capture/capture-cli.h, libmisc/capture/capture.h, libmisc/cpuuse/cpuuse.h, libmisc/devnull/devnull.h, libmisc/devnull/devzero.h, libmisc/dumpbuf/dumpbuf.h, libmisc/fb/fb.h, libmisc/fb/mw_uid.h, libmisc/mouse/mouse_parser.h, libmisc/shell/shellconfig.h, libmisc/stringto/stringto.h, libmisc/untar/untar.h, libnetworking/memory.h, posix/include/aio.h, posix/include/mqueue.h, posix/include/semaphore.h, posix/include/rtems/posix/aio_misc.h, posix/include/rtems/posix/barrier.h, posix/include/rtems/posix/cond.h, posix/include/rtems/posix/config.h, posix/include/rtems/posix/key.h, posix/include/rtems/posix/mqueue.h, posix/include/rtems/posix/mutex.h, posix/include/rtems/posix/posixapi.h, posix/include/rtems/posix/priority.h, posix/include/rtems/posix/psignal.h, posix/include/rtems/posix/pthread.h, posix/include/rtems/posix/ptimer.h, posix/include/rtems/posix/rwlock.h, posix/include/rtems/posix/semaphore.h, posix/include/rtems/posix/sigset.h, posix/include/rtems/posix/spinlock.h, posix/include/rtems/posix/threadsup.h, posix/include/rtems/posix/time.h, posix/include/rtems/posix/timer.h, posix/inline/rtems/posix/barrier.inl, posix/inline/rtems/posix/cond.inl, posix/inline/rtems/posix/mqueue.inl, posix/inline/rtems/posix/mutex.inl, posix/inline/rtems/posix/priority.inl, posix/inline/rtems/posix/pthread.inl, posix/inline/rtems/posix/rwlock.inl, posix/inline/rtems/posix/semaphore.inl, posix/inline/rtems/posix/spinlock.inl, posix/inline/rtems/posix/timer.inl, rtems/mainpage.h, rtems/include/rtems/rtems/barrier.h, rtems/include/rtems/rtems/object.h, rtems/include/rtems/rtems/timer.h, rtems/inline/rtems/rtems/barrier.inl, rtems/inline/rtems/rtems/timer.inl, rtems/src/semtranslatereturncode.c, sapi/include/rtems/config.h, sapi/include/rtems/fatal.h, sapi/include/rtems/mptables.h, score/include/rtems/score/object.h, score/include/rtems/score/priority.h, score/inline/rtems/score/object.inl, score/inline/rtems/score/priority.inl: Add @file Doxygen directives and descriptions to files which originated with RTEMS. This improves the file list page generated by Doxygen.
  • Property mode set to 100644
File size: 13.8 KB
Line 
1/**
2 * @file rtems/flashdisk.h
3 *
4 * This file defines the interface to a flash disk block device.
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.com/license/LICENSE.
13 *
14 * $Id$
15 */
16
17#if !defined (_RTEMS_FLASHDISK_H_)
18#define _RTEMS_FLASHDISK_H_
19
20#include <stdint.h>
21#include <sys/ioctl.h>
22
23#include <rtems.h>
24
25/**
26 * The base name of the flash disks.
27 */
28#define RTEMS_FLASHDISK_DEVICE_BASE_NAME "/dev/fdd"
29
30/**
31 * Flash disk specific ioctl request types. To use open the
32 * device and issue the ioctl call.
33 *
34 * @code
35 *  int fd = open ("/dev/flashdisk0", O_WRONLY, 0);
36 *  if (fd < 0)
37 *  {
38 *    printf ("driver open failed: %s\n", strerror (errno));
39 *    exit (1);
40 *  }
41 *  if (ioctl (fd, RTEMS_FDISK_IOCTL_ERASE_DISK) < 0)
42 *  {
43 *    printf ("driver erase failed: %s\n", strerror (errno));
44 *    exit (1);
45 *  }
46 *  close (fd);
47 * @endcode
48 */
49#define RTEMS_FDISK_IOCTL_ERASE_DISK   _IO('B', 128)
50#define RTEMS_FDISK_IOCTL_COMPACT      _IO('B', 129)
51#define RTEMS_FDISK_IOCTL_ERASE_USED   _IO('B', 130)
52#define RTEMS_FDISK_IOCTL_MONITORING   _IO('B', 131)
53#define RTEMS_FDISK_IOCTL_INFO_LEVEL   _IO('B', 132)
54#define RTEMS_FDISK_IOCTL_PRINT_STATUS _IO('B', 133)
55
56/**
57 * Flash Disk Monitoring Data allows a user to obtain
58 * the current status of the disk.
59 */
60typedef struct rtems_fdisk_monitor_data
61{
62  uint32_t block_size;
63  uint32_t block_count;
64  uint32_t unavail_blocks;
65  uint32_t device_count;
66  uint32_t segment_count;
67  uint32_t page_count;
68  uint32_t blocks_used;
69  uint32_t segs_available;
70  uint32_t segs_used;
71  uint32_t segs_failed;
72  uint32_t seg_erases;
73  uint32_t pages_desc;
74  uint32_t pages_active;
75  uint32_t pages_used;
76  uint32_t pages_bad;
77  uint32_t info_level;
78} rtems_fdisk_monitor_data;
79
80/**
81 * Flash Segment Descriptor holds, number of continuous segments in the
82 * device of this type, the base segment number in the device, the
83 * address offset of the base segment in the device, and the size of
84 * segment.
85 *
86 * Typically this structure is part of a table of segments in the
87 * device which is referenced in the flash disk configuration table.
88 * The reference is kept in the driver and used all the time to
89 * manage the flash device, therefore it must always exist.
90 */
91typedef struct rtems_fdisk_segment_desc
92{
93  uint16_t count;    /**< Number of segments of this type in a row. */
94  uint16_t segment;  /**< The base segment number. */
95  uint32_t offset;   /**< Address offset of base segment in device. */
96  uint32_t size;     /**< Size of the segment in bytes. */
97} rtems_fdisk_segment_desc;
98
99/**
100 * Return the number of kilo-bytes.
101 */
102#define RTEMS_FDISK_KBYTES(_k) (UINT32_C(1024) * (_k))
103
104/**
105 * Forward declaration of the device descriptor.
106 */
107struct rtems_fdisk_device_desc;
108
109/**
110 * Flash Low Level driver handlers.
111
112 * Typically this structure is part of a table of handlers in the
113 * device which is referenced in the flash disk configuration table.
114 * The reference is kept in the driver and used all the time to
115 * manage the flash device, therefore it must always exist.
116 */
117typedef struct rtems_fdisk_driver_handlers
118{
119  /**
120   * Read data from the device into the buffer. Return an errno
121   * error number if the device cannot be read. A segment descriptor
122   * can describe more than one segment in a device if the device has
123   * repeating segments. The segment number is the device segment to
124   * access and the segment descriptor must reference the segment
125   * being requested. For example the segment number must resided in
126   * the range [base, base + count).
127   *
128   * @param sd The segment descriptor.
129   * @param device The device to read data from.
130   * @param segment The segment within the device to read.
131   * @param offset The offset in the segment to read.
132   * @param buffer The buffer to read the data into.
133   * @param size The amount of data to read.
134   * @retval 0 No error.
135   * @retval EIO The read did not complete.
136   */
137  int (*read) (const rtems_fdisk_segment_desc* sd,
138               uint32_t                        device,
139               uint32_t                        segment,
140               uint32_t                        offset,
141               void*                           buffer,
142               uint32_t                        size);
143
144  /**
145   * Write data from the buffer to the device. Return an errno
146   * error number if the device cannot be written to. A segment
147   * descriptor can describe more than segment in a device if the
148   * device has repeating segments. The segment number is the device
149   * segment to access and the segment descriptor must reference
150   * the segment being requested. For example the segment number must
151   * resided in the range [base, base + count).
152   *
153   * @param sd The segment descriptor.
154   * @param device The device to write data from.
155   * @param segment The segment within the device to write to.
156   * @param offset The offset in the segment to write.
157   * @param buffer The buffer to write the data from.
158   * @param size The amount of data to write.
159   * @retval 0 No error.
160   * @retval EIO The write did not complete or verify.
161   */
162  int (*write) (const rtems_fdisk_segment_desc* sd,
163                uint32_t                        device,
164                uint32_t                        segment,
165                uint32_t                        offset,
166                const void*                     buffer,
167                uint32_t                        size);
168
169  /**
170   * Blank a segment in the device. Return an errno error number
171   * if the device cannot be read or is not blank. A segment descriptor
172   * can describe more than segment in a device if the device has
173   * repeating segments. The segment number is the device segment to
174   * access and the segment descriptor must reference the segment
175   * being requested. For example the segment number must resided in
176   * the range [base, base + count).
177   *
178   * @param sd The segment descriptor.
179   * @param device The device to read data from.
180   * @param segment The segment within the device to read.
181   * @param offset The offset in the segment to checl.
182   * @param size The amount of data to check.
183   * @retval 0 No error.
184   * @retval EIO The segment is not blank.
185   */
186  int (*blank) (const rtems_fdisk_segment_desc* sd,
187                uint32_t                        device,
188                uint32_t                        segment,
189                uint32_t                        offset,
190                uint32_t                        size);
191
192  /**
193   * Verify data in the buffer to the data in the device. Return an
194   * errno error number if the device cannot be read. A segment
195   * descriptor can describe more than segment in a device if the
196   * device has repeating segments. The segment number is the
197   * segment to access and the segment descriptor must reference
198   * the device segment being requested. For example the segment number
199   * must resided in the range [base, base + count).
200   *
201   * @param sd The segment descriptor.
202   * @param device The device to verify data in.
203   * @param segment The segment within the device to verify.
204   * @param offset The offset in the segment to verify.
205   * @param buffer The buffer to verify the data in the device with.
206   * @param size The amount of data to verify.
207   * @retval 0 No error.
208   * @retval EIO The data did not verify.
209   */
210  int (*verify) (const rtems_fdisk_segment_desc* sd,
211                 uint32_t                        device,
212                 uint32_t                        segment,
213                 uint32_t                        offset,
214                 const void*                     buffer,
215                 uint32_t                        size);
216
217  /**
218   * Erase the segment. Return an errno error number if the
219   * segment cannot be erased. A segment descriptor can describe
220   * more than segment in a device if the device has repeating
221   * segments. The segment number is the device segment to access and
222   * the segment descriptor must reference the segment being requested.
223   *
224   * @param sd The segment descriptor.
225   * @param device The device to erase the segment of.
226   * @param segment The segment within the device to erase.
227   * @retval 0 No error.
228   * @retval EIO The segment was not erased.
229   */
230  int (*erase) (const rtems_fdisk_segment_desc* sd,
231                uint32_t                        device,
232                uint32_t                        segment);
233
234  /**
235   * Erase the device. Return an errno error number if the
236   * segment cannot be erased. A segment descriptor can describe
237   * more than segment in a device if the device has repeating
238   * segments. The segment number is the segment to access and
239   * the segment descriptor must reference the segment being requested.
240   *
241   * @param sd The segment descriptor.
242   * @param device The device to erase.
243   * @retval 0 No error.
244   * @retval EIO The device was not erased.
245   */
246  int (*erase_device) (const struct rtems_fdisk_device_desc* dd,
247                       uint32_t                              device);
248
249} rtems_fdisk_driver_handlers;
250
251/**
252 * Flash Device Descriptor holds the segments in a device. The
253 * placing of the segments in a device decriptor allows the
254 * low level driver to share the segment descriptors for a
255 * number of devices.
256 *
257 * Typically this structure is part of a table of segments in the
258 * device which is referenced in the flash disk configuration table.
259 * The reference is kept in the driver and used all the time to
260 * manage the flash device, therefore it must always exist.
261 */
262typedef struct rtems_fdisk_device_desc
263{
264  uint32_t                           segment_count; /**< Number of segments. */
265  const rtems_fdisk_segment_desc*    segments;      /**< Array of segments. */
266  const rtems_fdisk_driver_handlers* flash_ops;     /**< Device handlers. */
267} rtems_fdisk_device_desc;
268
269/**
270 * RTEMS Flash Disk configuration table used to initialise the
271 * driver.
272 *
273 * The unavailable blocks count is the number of blocks less than the
274 * available number of blocks the file system is given. This means there
275 * will always be that number of blocks available when the file system
276 * thinks the disk is full. The compaction code needs blocks to compact
277 * with so you will never be able to have all the blocks allocated to the
278 * file system and be able to full the disk.
279 *
280 * The compacting segment count is the number of segments that are
281 * moved into a new segment. A high number will mean more segments with
282 * low active page counts and high used page counts will be moved into
283 * avaliable pages how-ever this extends the compaction time due to
284 * time it takes the erase the pages. There is no pont making this number
285 * greater than the maximum number of pages in a segment.
286 *
287 * The available compacting segment count is the level when compaction occurs
288 * when writing. If you set this to 0 then compaction will fail because
289 * there will be no segments to compact into.
290 *
291 * The info level can be 0 for off with error, and abort messages allowed.
292 * Level 1 is warning messages, level 1 is informational messages, and level 3
293 * is debugging type prints. The info level can be turned off with a compile
294 * time directive on the command line to the compiler of:
295 *
296 *     -DRTEMS_FDISK_TRACE=0
297 */
298typedef struct rtems_flashdisk_config
299{
300  uint32_t                       block_size;     /**< The block size. */
301  uint32_t                       device_count;   /**< The number of devices. */
302  const rtems_fdisk_device_desc* devices;        /**< The device descriptions. */
303  uint32_t                       flags;          /**< Set of flags to control
304                                                      driver. */
305  uint32_t                       unavail_blocks; /**< Number of blocks not
306                                                      available to the file sys. */
307  uint32_t                       compact_segs;   /**< Max number of segs to
308                                                      compact in one pass. */
309  uint32_t                       avail_compact_segs; /**< The number of segments
310                                                          when compaction occurs
311                                                          when writing. */
312  uint32_t                       info_level;     /**< Default info level. */
313} rtems_flashdisk_config;
314
315/*
316 * Driver flags.
317 */
318
319/**
320 * Leave the erasing of used segment to the background handler.
321 */
322#define RTEMS_FDISK_BACKGROUND_ERASE (1 << 0)
323
324/**
325 * Leave the compacting of of used segment to the background handler.
326 */
327#define RTEMS_FDISK_BACKGROUND_COMPACT (1 << 1)
328
329/**
330 * Check the pages during initialisation to see which pages are
331 * valid and which are not. This could slow down initialising the
332 * disk driver.
333 */
334#define RTEMS_FDISK_CHECK_PAGES (1 << 2)
335
336/**
337 * Blank check the flash device before writing to them. This is needed if
338 * you think you have a driver or device problem.
339 */
340#define RTEMS_FDISK_BLANK_CHECK_BEFORE_WRITE (1 << 3)
341
342/**
343 * Flash disk device driver initialization. Place in a table as the
344 * initialisation entry and remainder of the entries are the
345 * RTEMS block device generic handlers.
346 *
347 * @param major Flash disk major device number.
348 * @param minor Minor device number, not applicable.
349 * @param arg Initialization argument, not applicable.
350 * @return The rtems_device_driver is actually just
351 *         rtems_status_code.
352 */
353rtems_device_driver
354rtems_fdisk_initialize (rtems_device_major_number major,
355                        rtems_device_minor_number minor,
356                        void*                     arg);
357
358/**
359 * External reference to the configuration. Please supply.
360 * Support is present in confdefs.h for providing this variable.
361 */
362extern const rtems_flashdisk_config rtems_flashdisk_configuration[];
363
364/**
365 * External reference to the number of configurations. Please supply.
366 * Support is present in confdefs.h for providing this variable.
367 */
368extern uint32_t rtems_flashdisk_configuration_size;
369
370#endif
Note: See TracBrowser for help on using the repository browser.