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