flashvar.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* $OpenBSD: flashvar.h,v 1.7 2013/11/11 03:03:34 dlg Exp $ */
  2. /*
  3. * Copyright (c) 2005 Uwe Stuehler <uwe@openbsd.org>
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #ifndef _FLASHVAR_H_
  18. #define _FLASHVAR_H_
  19. #ifdef _KERNEL
  20. /* Flash controller descriptor structure */
  21. struct flash_ctl_tag {
  22. u_int8_t (*reg8_read)(void *, int);
  23. int (*regx_read_page)(void *, caddr_t, caddr_t);
  24. void (*reg8_write)(void *, int, u_int8_t);
  25. int (*regx_write_page)(void *, caddr_t, caddr_t);
  26. void (*default_disklabel)(void *, dev_t, struct disklabel *);
  27. int (*safe_strategy)(void *, struct buf *);
  28. };
  29. /*
  30. * Pseudo-registers for a fictitious flash controller
  31. *
  32. * Note that logical levels are assumed for CE and WP bits.
  33. * Signals corresponding to these bits are usually negated.
  34. */
  35. #define FLASH_REG_DATA 0x00
  36. #define FLASH_REG_COL 0x01
  37. #define FLASH_REG_ROW 0x02
  38. #define FLASH_REG_CMD 0x03
  39. #define FLASH_REG_ALE 0x04
  40. #define FLASH_REG_CLE 0x05
  41. #define FLASH_REG_CE 0x06
  42. #define FLASH_REG_WP 0x07
  43. #define FLASH_REG_READY 0x0f
  44. /* Flash device descriptor structure */
  45. struct flashdev {
  46. u_int16_t id;
  47. const char *longname;
  48. u_long pagesize; /* bytes per page */
  49. u_long oobsize; /* OOB bytes per page */
  50. u_long blkpages; /* pages per erasable block */
  51. u_long capacity; /* pages per device */
  52. };
  53. #define FLASH_DEVICE(v,d) ((FLASH_VENDOR_##v << 8) | (d))
  54. /* Flash device vendors */
  55. #define FLASH_VENDOR_SAMSUNG 0xec
  56. /* Flash devices */
  57. #define FLASH_DEVICE_SAMSUNG_K9F2808U0C FLASH_DEVICE(SAMSUNG, 0x73)
  58. #define FLASH_DEVICE_SAMSUNG_K9F1G08U0A FLASH_DEVICE(SAMSUNG, 0xf1)
  59. /* Maximum sizes for all devices */
  60. #define FLASH_MAXPAGESIZE 2048
  61. #define FLASH_MAXOOBSIZE 64
  62. /*
  63. * Should-be private softc structure for the generic flash driver.
  64. */
  65. struct flash_softc {
  66. struct device sc_dev;
  67. /* Disk device information */
  68. struct disk sc_dk;
  69. struct bufq sc_bufq;
  70. struct buf *sc_bp;
  71. int sc_flags;
  72. /* Flash controller tag */
  73. struct flash_ctl_tag *sc_tag;
  74. void *sc_cookie;
  75. /* Flash device characteristics */
  76. const struct flashdev *sc_flashdev;
  77. int sc_maxwaitready;
  78. int sc_maxwaitcomplete;
  79. };
  80. /* Values for sc_flags */
  81. #define FDK_LOADED 0x00000001
  82. #define FDK_SAFE 0x00000002
  83. /*
  84. * Similar to vnd(4) devices there are two kinds of flash devices.
  85. * Both device kinds share the same disklabel.
  86. *
  87. * ``Safe'' devices have bit 11 set in the minor number and use the
  88. * out-of-band page data to implement wear-leveling and transparent
  89. * management of bad block information. Block erasing and rewriting
  90. * is also handled transparently; arbitrary pages can be modified.
  91. *
  92. * ``Unsafe'' devices provide raw access to the flash pages. Access
  93. * to OOB page data is possible via ioctl()s only with these devices.
  94. * Erasing the containing flash block may be necessary before a page
  95. * can be writting successfully, but the block erase command is only
  96. * provided as an ioctl().
  97. */
  98. #define flashsafe(x) (minor(x) & 0x800)
  99. #define flashunit(x) DISKUNIT(makedev(major(x), minor(x) & 0x7ff))
  100. #define flashpart(x) DISKPART(makedev(major(x), minor(x) & 0x7ff))
  101. #define flashlabeldev(x) (MAKEDISKDEV(major(x), flashunit(x), RAW_PART)\
  102. |flashsafe(x))
  103. void flashattach(struct flash_softc *, struct flash_ctl_tag *, void *);
  104. int flashdetach(struct device *, int);
  105. u_int8_t flash_reg8_read(struct flash_softc *, int);
  106. void flash_reg8_read_page(struct flash_softc *, caddr_t, caddr_t);
  107. void flash_reg8_write(struct flash_softc *, int, u_int8_t);
  108. void flash_reg8_write_page(struct flash_softc *, caddr_t, caddr_t);
  109. void flash_chip_enable(struct flash_softc *);
  110. void flash_chip_disable(struct flash_softc *);
  111. int flash_chip_reset(struct flash_softc *);
  112. int flash_chip_identify(struct flash_softc *, u_int8_t *, u_int8_t *);
  113. int flash_chip_erase_block(struct flash_softc *, long);
  114. int flash_chip_read_block(struct flash_softc *, long, caddr_t);
  115. int flash_chip_read_page(struct flash_softc *, long, caddr_t, caddr_t);
  116. int flash_chip_read_oob(struct flash_softc *, long, caddr_t);
  117. int flash_chip_write_block(struct flash_softc *, long, caddr_t, caddr_t);
  118. int flash_chip_write_page(struct flash_softc *, long, caddr_t, caddr_t);
  119. int flash_chip_verify_block(struct flash_softc *, long, caddr_t, caddr_t);
  120. int flash_chip_verify_page(struct flash_softc *, long, caddr_t, caddr_t);
  121. #endif /* _KERNEL */
  122. /* XXX: define ioctl commands for OOB page data access and block erase. */
  123. #endif /* _FLASHVAR_H_ */