PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/edk2/Clover/Trash/OsxMmcDxe/Mmc.h

https://gitlab.com/envieidoc/Clover
C Header | 302 lines | 175 code | 39 blank | 88 comment | 0 complexity | 96072ebde93db10e965f8343d047e149 MD5 | raw file
  1. /** @file
  2. Main Header file for the MMC DXE driver
  3. Copyright (c) 2011, ARM Limited. All rights reserved.
  4. This program and the accompanying materials
  5. are licensed and made available under the terms and conditions of the BSD License
  6. which accompanies this distribution. The full text of the license may be found at
  7. http://opensource.org/licenses/bsd-license.php
  8. THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  10. **/
  11. #ifndef __MMC_H
  12. #define __MMC_H
  13. #include <Uefi.h>
  14. #include <Protocol/DiskIo.h>
  15. #include <Protocol/BlockIo.h>
  16. #include <Protocol/DevicePath.h>
  17. #include <Protocol/MmcHost.h>
  18. #include <Library/UefiLib.h>
  19. #define MMC_TRACE(txt) DEBUG((EFI_D_BLKIO, "MMC: " txt "\n"))
  20. #define MMC_IOBLOCKS_READ 0
  21. #define MMC_IOBLOCKS_WRITE 1
  22. #define MMC_OCR_POWERUP 0x80000000
  23. #define MMC_CSD_GET_CCC(Response) (Response[2] >> 20)
  24. #define MMC_CSD_GET_TRANSPEED(Response) (Response[3] & 0xFF)
  25. #define MMC_CSD_GET_READBLLEN(Response) ((Response[2] >> 16) & 0xF)
  26. #define MMC_CSD_GET_WRITEBLLEN(Response) ((Response[0] >> 22) & 0xF)
  27. #define MMC_CSD_GET_FILEFORMAT(Response) ((Response[0] >> 10) & 0x3)
  28. #define MMC_CSD_GET_FILEFORMATGRP(Response) ((Response[0] >> 15) & 0x1)
  29. #define MMC_CSD_GET_DEVICESIZE(csd) (((Response[1] >> 30) & 0x3) | ((Response[2] & 0x3FF) << 2))
  30. #define HC_MMC_CSD_GET_DEVICESIZE(Response) ((Response[1] >> 16) | ((Response[2] & 0x40) << 16));
  31. #define MMC_CSD_GET_DEVICESIZEMULT(csd) ((Response[1] >> 15) & 0x7)
  32. #define MMC_R0_READY_FOR_DATA (1 << 8)
  33. #define MMC_R0_CURRENTSTATE(Response) ((Response[0] >> 9) & 0xF)
  34. #define MMC_R0_STATE_IDLE 0
  35. #define MMC_R0_STATE_READY 1
  36. #define MMC_R0_STATE_IDENT 2
  37. #define MMC_R0_STATE_STDBY 3
  38. #define MMC_R0_STATE_TRAN 4
  39. #define MMC_R0_STATE_DATA 5
  40. typedef enum {
  41. UNKNOWN_CARD,
  42. MMC_CARD, //MMC card
  43. MMC_CARD_HIGH, //MMC Card with High capacity
  44. SD_CARD, //SD 1.1 card
  45. SD_CARD_2, //SD 2.0 or above standard card
  46. SD_CARD_2_HIGH //SD 2.0 or above high capacity card
  47. } CARD_TYPE;
  48. typedef struct {
  49. UINT32 Reserved0: 7; // 0
  50. UINT32 V170_V195: 1; // 1.70V - 1.95V
  51. UINT32 V200_V260: 7; // 2.00V - 2.60V
  52. UINT32 V270_V360: 9; // 2.70V - 3.60V
  53. UINT32 RESERVED_1: 5; // Reserved
  54. UINT32 AccessMode: 2; // 00b (byte mode), 10b (sector mode)
  55. UINT32 Busy: 1; // This bit is set to LOW if the card has not finished the power up routine
  56. } OCR;
  57. typedef struct {
  58. UINT32 NOT_USED; // 1 [0:0]
  59. UINT32 CRC; // CRC7 checksum [7:1]
  60. UINT32 MDT; // Manufacturing date [19:8]
  61. UINT32 RESERVED_1; // Reserved [23:20]
  62. UINT32 PSN; // Product serial number [55:24]
  63. UINT8 PRV; // Product revision [63:56]
  64. UINT8 PNM[5]; // Product name [64:103]
  65. UINT16 OID; // OEM/Application ID [119:104]
  66. UINT8 MID; // Manufacturer ID [127:120]
  67. } CID;
  68. typedef struct {
  69. UINT8 NOT_USED: 1; // Not used, always 1 [0:0]
  70. UINT8 CRC: 7; // CRC [7:1]
  71. UINT8 RESERVED_1: 2; // Reserved [9:8]
  72. UINT8 FILE_FORMAT: 2; // File format [11:10]
  73. UINT8 TMP_WRITE_PROTECT: 1; // Temporary write protection [12:12]
  74. UINT8 PERM_WRITE_PROTECT: 1; // Permanent write protection [13:13]
  75. UINT8 COPY: 1; // Copy flag (OTP) [14:14]
  76. UINT8 FILE_FORMAT_GRP: 1; // File format group [15:15]
  77. UINT16 RESERVED_2: 5; // Reserved [20:16]
  78. UINT16 WRITE_BL_PARTIAL: 1; // Partial blocks for write allowed [21:21]
  79. UINT16 WRITE_BL_LEN: 4; // Max. write data block length [25:22]
  80. UINT16 R2W_FACTOR: 3; // Write speed factor [28:26]
  81. UINT16 RESERVED_3: 2; // Reserved [30:29]
  82. UINT16 WP_GRP_ENABLE: 1; // Write protect group enable [31:31]
  83. UINT32 WP_GRP_SIZE: 7; // Write protect group size [38:32]
  84. UINT32 SECTOR_SIZE: 7; // Erase sector size [45:39]
  85. UINT32 ERASE_BLK_EN: 1; // Erase single block enable [46:46]
  86. UINT32 C_SIZE_MULT: 3; // Device size multiplier [49:47]
  87. UINT32 VDD_W_CURR_MAX: 3; // Max. write current @ VDD max [52:50]
  88. UINT32 VDD_W_CURR_MIN: 3; // Max. write current @ VDD min [55:53]
  89. UINT32 VDD_R_CURR_MAX: 3; // Max. read current @ VDD max [58:56]
  90. UINT32 VDD_R_CURR_MIN: 3; // Max. read current @ VDD min [61:59]
  91. UINT32 C_SIZELow2: 2; // Device size [63:62]
  92. UINT32 C_SIZEHigh10: 10;// Device size [73:64]
  93. UINT32 RESERVED_4: 2; // Reserved [75:74]
  94. UINT32 DSR_IMP: 1; // DSR implemented [76:76]
  95. UINT32 READ_BLK_MISALIGN: 1; // Read block misalignment [77:77]
  96. UINT32 WRITE_BLK_MISALIGN: 1; // Write block misalignment [78:78]
  97. UINT32 READ_BL_PARTIAL: 1; // Partial blocks for read allowed [79:79]
  98. UINT32 READ_BL_LEN: 4; // Max. read data block length [83:80]
  99. UINT32 CCC: 12;// Card command classes [95:84]
  100. UINT8 TRAN_SPEED ; // Max. bus clock frequency [103:96]
  101. UINT8 NSAC ; // Data read access-time 2 in CLK cycles (NSAC*100) [111:104]
  102. UINT8 TAAC ; // Data read access-time 1 [119:112]
  103. UINT8 RESERVED_5: 6; // Reserved [125:120]
  104. UINT8 CSD_STRUCTURE: 2; // CSD structure [127:126]
  105. } CSD;
  106. typedef struct {
  107. UINT16 RCA;
  108. CARD_TYPE CardType;
  109. OCR OCRData;
  110. CID CIDData;
  111. CSD CSDData;
  112. } CARD_INFO;
  113. typedef struct _MMC_HOST_INSTANCE {
  114. UINTN Signature;
  115. LIST_ENTRY Link;
  116. EFI_HANDLE MmcHandle;
  117. EFI_DEVICE_PATH_PROTOCOL *DevicePath;
  118. MMC_STATE State;
  119. EFI_BLOCK_IO_PROTOCOL BlockIo;
  120. CARD_INFO CardInfo;
  121. EFI_MMC_HOST_PROTOCOL *MmcHost;
  122. BOOLEAN Initialized;
  123. } MMC_HOST_INSTANCE;
  124. #define MMC_HOST_INSTANCE_SIGNATURE SIGNATURE_32('m', 'm', 'c', 'h')
  125. #define MMC_HOST_INSTANCE_FROM_BLOCK_IO_THIS(a) CR (a, MMC_HOST_INSTANCE, BlockIo, MMC_HOST_INSTANCE_SIGNATURE)
  126. #define MMC_HOST_INSTANCE_FROM_LINK(a) CR (a, MMC_HOST_INSTANCE, Link, MMC_HOST_INSTANCE_SIGNATURE)
  127. EFI_STATUS
  128. EFIAPI
  129. MmcGetDriverName (
  130. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  131. IN CHAR8 *Language,
  132. OUT CHAR16 **DriverName
  133. );
  134. EFI_STATUS
  135. EFIAPI
  136. MmcGetControllerName (
  137. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  138. IN EFI_HANDLE ControllerHandle,
  139. IN EFI_HANDLE ChildHandle OPTIONAL,
  140. IN CHAR8 *Language,
  141. OUT CHAR16 **ControllerName
  142. );
  143. extern EFI_COMPONENT_NAME_PROTOCOL gMmcComponentName;
  144. extern EFI_COMPONENT_NAME2_PROTOCOL gMmcComponentName2;
  145. extern EFI_DRIVER_DIAGNOSTICS2_PROTOCOL gMmcDriverDiagnostics2;
  146. extern LIST_ENTRY mMmcHostPool;
  147. /**
  148. Reset the block device.
  149. This function implements EFI_BLOCK_IO_PROTOCOL.Reset().
  150. It resets the block device hardware.
  151. ExtendedVerification is ignored in this implementation.
  152. @param This Indicates a pointer to the calling context.
  153. @param ExtendedVerification Indicates that the driver may perform a more exhaustive
  154. verification operation of the device during reset.
  155. @retval EFI_SUCCESS The block device was reset.
  156. @retval EFI_DEVICE_ERROR The block device is not functioning correctly and could not be reset.
  157. **/
  158. EFI_STATUS
  159. EFIAPI
  160. MmcReset (
  161. IN EFI_BLOCK_IO_PROTOCOL *This,
  162. IN BOOLEAN ExtendedVerification
  163. );
  164. /**
  165. Reads the requested number of blocks from the device.
  166. This function implements EFI_BLOCK_IO_PROTOCOL.ReadBlocks().
  167. It reads the requested number of blocks from the device.
  168. All the blocks are read, or an error is returned.
  169. @param This Indicates a pointer to the calling context.
  170. @param MediaId The media ID that the read request is for.
  171. @param Lba The starting logical block address to read from on the device.
  172. @param BufferSize The size of the Buffer in bytes.
  173. This must be a multiple of the intrinsic block size of the device.
  174. @param Buffer A pointer to the destination buffer for the data. The caller is
  175. responsible for either having implicit or explicit ownership of the buffer.
  176. @retval EFI_SUCCESS The data was read correctly from the device.
  177. @retval EFI_DEVICE_ERROR The device reported an error while attempting to perform the read operation.
  178. @retval EFI_NO_MEDIA There is no media in the device.
  179. @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
  180. @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the intrinsic block size of the device.
  181. @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
  182. or the buffer is not on proper alignment.
  183. **/
  184. EFI_STATUS
  185. EFIAPI
  186. MmcReadBlocks (
  187. IN EFI_BLOCK_IO_PROTOCOL *This,
  188. IN UINT32 MediaId,
  189. IN EFI_LBA Lba,
  190. IN UINTN BufferSize,
  191. OUT VOID *Buffer
  192. );
  193. /**
  194. Writes a specified number of blocks to the device.
  195. This function implements EFI_BLOCK_IO_PROTOCOL.WriteBlocks().
  196. It writes a specified number of blocks to the device.
  197. All blocks are written, or an error is returned.
  198. @param This Indicates a pointer to the calling context.
  199. @param MediaId The media ID that the write request is for.
  200. @param Lba The starting logical block address to be written.
  201. @param BufferSize The size of the Buffer in bytes.
  202. This must be a multiple of the intrinsic block size of the device.
  203. @param Buffer Pointer to the source buffer for the data.
  204. @retval EFI_SUCCESS The data were written correctly to the device.
  205. @retval EFI_WRITE_PROTECTED The device cannot be written to.
  206. @retval EFI_NO_MEDIA There is no media in the device.
  207. @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
  208. @retval EFI_DEVICE_ERROR The device reported an error while attempting to perform the write operation.
  209. @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the intrinsic
  210. block size of the device.
  211. @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
  212. or the buffer is not on proper alignment.
  213. **/
  214. EFI_STATUS
  215. EFIAPI
  216. MmcWriteBlocks (
  217. IN EFI_BLOCK_IO_PROTOCOL *This,
  218. IN UINT32 MediaId,
  219. IN EFI_LBA Lba,
  220. IN UINTN BufferSize,
  221. IN VOID *Buffer
  222. );
  223. /**
  224. Flushes all modified data to a physical block device.
  225. @param This Indicates a pointer to the calling context.
  226. @retval EFI_SUCCESS All outstanding data were written correctly to the device.
  227. @retval EFI_DEVICE_ERROR The device reported an error while attempting to write data.
  228. @retval EFI_NO_MEDIA There is no media in the device.
  229. **/
  230. EFI_STATUS
  231. EFIAPI
  232. MmcFlushBlocks (
  233. IN EFI_BLOCK_IO_PROTOCOL *This
  234. );
  235. EFI_STATUS InitializeMmcDevice (
  236. IN MMC_HOST_INSTANCE *MmcHost
  237. );
  238. VOID
  239. EFIAPI
  240. CheckCardsCallback (
  241. IN EFI_EVENT Event,
  242. IN VOID *Context
  243. );
  244. #endif