blockdev.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #ifndef DEV_BLOCKDEV_H_
  2. #define DEV_BLOCKDEV_H_
  3. /*
  4. * Copyright (C) 2005 by egnite Software GmbH. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. /*!
  35. * \file dev/blockdev.h
  36. * \brief Block device driver definitions.
  37. *
  38. * \verbatim
  39. *
  40. * $Log$
  41. * Revision 1.4 2009/01/09 17:59:05 haraldkipp
  42. * Added target independent AT45D block device drivers and non-volatile
  43. * memory support based on the new bus controllers.
  44. *
  45. * Revision 1.3 2008/08/11 06:59:59 haraldkipp
  46. * BSD types replaced by stdint types (feature request #1282721).
  47. *
  48. * Revision 1.2 2006/04/07 12:57:48 haraldkipp
  49. * Added ioctl(NUTBLKDEV_MEDIAAVAIL).
  50. *
  51. * Revision 1.1 2006/01/05 16:32:05 haraldkipp
  52. * First check-in.
  53. *
  54. *
  55. * \endverbatim
  56. */
  57. #include <sys/types.h>
  58. #include <stdint.h>
  59. #include <sys/device.h>
  60. #include <sys/file.h>
  61. /*!
  62. * \addtogroup xgBlockDev
  63. */
  64. /*@{*/
  65. /*!
  66. * \name Control Codes
  67. */
  68. /*@{*/
  69. /*! \brief Query for media change. */
  70. #define NUTBLKDEV_MEDIAAVAIL 0x1200
  71. /*! \brief Query for media change. */
  72. #define NUTBLKDEV_MEDIACHANGE 0x1201
  73. /*! \brief Retrieve device information. */
  74. #define NUTBLKDEV_INFO 0x1202
  75. /*! \brief Block seek request. */
  76. #define NUTBLKDEV_SEEK 0x1203
  77. /*@}*/
  78. /*!
  79. * \brief Block seek parameter structure.
  80. *
  81. * Used with \ref NUTBLKDEV_SEEK ioctl.
  82. */
  83. typedef struct _BLKPAR_SEEK {
  84. NUTFILE *par_nfp;
  85. uint32_t par_blknum;
  86. } BLKPAR_SEEK;
  87. /*!
  88. * \brief Device information parameter structure.
  89. *
  90. * Used with \ref NUTBLKDEV_INFO ioctl.
  91. */
  92. typedef struct _BLKPAR_INFO {
  93. NUTFILE *par_nfp;
  94. uint32_t par_nblks;
  95. uint32_t par_blksz;
  96. uint8_t *par_blkbp;
  97. } BLKPAR_INFO;
  98. /*! \brief Generic block I/O device interface structure type. */
  99. typedef struct _NUTBLOCKIO NUTBLOCKIO;
  100. /*!
  101. * \brief Generic block I/O device interface structure.
  102. *
  103. * This is a virtual structure, used by the generic block I/O device driver.
  104. *
  105. * \note Any real implementation must start with the same layout. If this
  106. * structure is changed, we must update all implementations.
  107. */
  108. struct _NUTBLOCKIO {
  109. /*!
  110. * \brief Device specific information.
  111. */
  112. void *blkio_info;
  113. /*!
  114. * \brief Total number of blocks on this device.
  115. */
  116. uint32_t blkio_blk_cnt;
  117. /*!
  118. * \brief Number of bytes per block.
  119. */
  120. uint32_t blkio_blk_siz;
  121. /*!
  122. * \brief First block for file system mount.
  123. */
  124. uint32_t blkio_vol_bot;
  125. /*!
  126. * \brief Number of blocks reserved on top of file system mount.
  127. */
  128. uint32_t blkio_vol_top;
  129. /*!
  130. * \brief Read from block I/O device, starting at the specified block.
  131. */
  132. int (*blkio_read) (NUTDEVICE *, uint32_t, void *, int);
  133. /*!
  134. * \brief Write to block I/O device, starting at the specified block.
  135. */
  136. int (*blkio_write) (NUTDEVICE *, uint32_t, const void *, int);
  137. #ifdef __HARVARD_ARCH__
  138. /*!
  139. * \brief Write program memory to block I/O device, starting at the specified block.
  140. */
  141. int (*blkio_write_P) (NUTDEVICE *, uint32_t, PGM_P, int);
  142. #endif
  143. /*!
  144. * \brief Control functions.
  145. */
  146. int (*blkio_ioctl)(NUTDEVICE *, int, void *);
  147. };
  148. /*@}*/
  149. extern int NutBlockDeviceInit(NUTDEVICE * dev);
  150. extern NUTFILE *NutBlockDeviceOpen(NUTDEVICE * dev, const char *name, int mode, int acc);
  151. extern int NutBlockDeviceClose(NUTFILE * nfp);
  152. extern int NutBlockDeviceIOCtl(NUTDEVICE * dev, int req, void *conf);
  153. extern int NutBlockDeviceRead(NUTFILE * nfp, void *buffer, int num);
  154. extern int NutBlockDeviceWrite(NUTFILE *nfp, const void *buffer, int num);
  155. extern long NutBlockDeviceSize(NUTFILE *nfp);
  156. #ifdef __HARVARD_ARCH__
  157. extern int NutBlockDeviceWrite_P(NUTFILE * nfp, PGM_P buffer, int num);
  158. #endif
  159. #endif