]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.h
MdeModulePkg/SdMmcPciHcDxe: Check SD's supported bus mode before switch
[mirror_edk2.git] / MdeModulePkg / Bus / Sd / SdBlockIoPei / SdHci.h
CommitLineData
48555339
FT
1/** @file\r
2\r
3 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
4 This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php.\r
8\r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12**/\r
13\r
14#ifndef _SD_HCI_H_\r
15#define _SD_HCI_H_\r
16\r
17//\r
18// SD Host Controller MMIO Register Offset\r
19//\r
20#define SD_HC_SDMA_ADDR 0x00\r
21#define SD_HC_ARG2 0x00\r
22#define SD_HC_BLK_SIZE 0x04\r
23#define SD_HC_BLK_COUNT 0x06\r
24#define SD_HC_ARG1 0x08\r
25#define SD_HC_TRANS_MOD 0x0C\r
26#define SD_HC_COMMAND 0x0E\r
27#define SD_HC_RESPONSE 0x10\r
28#define SD_HC_BUF_DAT_PORT 0x20\r
29#define SD_HC_PRESENT_STATE 0x24\r
30#define SD_HC_HOST_CTRL1 0x28\r
31#define SD_HC_POWER_CTRL 0x29\r
32#define SD_HC_BLK_GAP_CTRL 0x2A\r
33#define SD_HC_WAKEUP_CTRL 0x2B\r
34#define SD_HC_CLOCK_CTRL 0x2C\r
35#define SD_HC_TIMEOUT_CTRL 0x2E\r
36#define SD_HC_SW_RST 0x2F\r
37#define SD_HC_NOR_INT_STS 0x30\r
38#define SD_HC_ERR_INT_STS 0x32\r
39#define SD_HC_NOR_INT_STS_EN 0x34\r
40#define SD_HC_ERR_INT_STS_EN 0x36\r
41#define SD_HC_NOR_INT_SIG_EN 0x38\r
42#define SD_HC_ERR_INT_SIG_EN 0x3A\r
43#define SD_HC_AUTO_CMD_ERR_STS 0x3C\r
44#define SD_HC_HOST_CTRL2 0x3E\r
45#define SD_HC_CAP 0x40\r
46#define SD_HC_MAX_CURRENT_CAP 0x48\r
47#define SD_HC_FORCE_EVT_AUTO_CMD 0x50\r
48#define SD_HC_FORCE_EVT_ERR_INT 0x52\r
49#define SD_HC_ADMA_ERR_STS 0x54\r
50#define SD_HC_ADMA_SYS_ADDR 0x58\r
51#define SD_HC_PRESET_VAL 0x60\r
52#define SD_HC_SHARED_BUS_CTRL 0xE0\r
53#define SD_HC_SLOT_INT_STS 0xFC\r
54#define SD_HC_CTRL_VER 0xFE\r
55\r
56//\r
57// The transfer modes supported by SD Host Controller\r
58// Simplified Spec 3.0 Table 1-2\r
59//\r
60typedef enum {\r
61 SdNoData,\r
62 SdPioMode,\r
63 SdSdmaMode,\r
64 SdAdmaMode\r
65} SD_HC_TRANSFER_MODE;\r
66\r
67//\r
68// The maximum data length of each descriptor line\r
69//\r
70#define ADMA_MAX_DATA_PER_LINE 0x10000\r
71#define SD_SDMA_BOUNDARY 512 * 1024\r
72#define SD_SDMA_ROUND_UP(x, n) (((x) + n) & ~(n - 1))\r
73\r
74typedef enum {\r
75 SdCommandTypeBc, // Broadcast commands, no response\r
76 SdCommandTypeBcr, // Broadcast commands with response\r
77 SdCommandTypeAc, // Addressed(point-to-point) commands\r
78 SdCommandTypeAdtc // Addressed(point-to-point) data transfer commands\r
79} SD_COMMAND_TYPE;\r
80\r
81typedef enum {\r
82 SdResponseTypeR1,\r
83 SdResponseTypeR1b,\r
84 SdResponseTypeR2,\r
85 SdResponseTypeR3,\r
86 SdResponseTypeR4,\r
87 SdResponseTypeR5,\r
88 SdResponseTypeR5b,\r
89 SdResponseTypeR6,\r
90 SdResponseTypeR7\r
91} SD_RESPONSE_TYPE;\r
92\r
93typedef struct _SD_COMMAND_BLOCK {\r
94 UINT16 CommandIndex;\r
95 UINT32 CommandArgument;\r
96 UINT32 CommandType; // One of the SD_COMMAND_TYPE values\r
97 UINT32 ResponseType; // One of the SD_RESPONSE_TYPE values\r
98} SD_COMMAND_BLOCK;\r
99\r
100typedef struct _SD_STATUS_BLOCK {\r
101 UINT32 Resp0;\r
102 UINT32 Resp1;\r
103 UINT32 Resp2;\r
104 UINT32 Resp3;\r
105} SD_STATUS_BLOCK;\r
106\r
107typedef struct _SD_COMMAND_PACKET {\r
108 UINT64 Timeout;\r
109 SD_COMMAND_BLOCK *SdCmdBlk;\r
110 SD_STATUS_BLOCK *SdStatusBlk;\r
111 VOID *InDataBuffer;\r
112 VOID *OutDataBuffer;\r
113 UINT32 InTransferLength;\r
114 UINT32 OutTransferLength;\r
115} SD_COMMAND_PACKET;\r
116\r
117#pragma pack(1)\r
118\r
119typedef struct {\r
120 UINT32 Valid:1;\r
121 UINT32 End:1;\r
122 UINT32 Int:1;\r
123 UINT32 Reserved:1;\r
124 UINT32 Act:2;\r
125 UINT32 Reserved1:10;\r
126 UINT32 Length:16;\r
127 UINT32 Address;\r
128} SD_HC_ADMA_DESC_LINE;\r
129\r
130typedef struct {\r
131 UINT32 TimeoutFreq:6; // bit 0:5\r
132 UINT32 Reserved:1; // bit 6\r
133 UINT32 TimeoutUnit:1; // bit 7\r
134 UINT32 BaseClkFreq:8; // bit 8:15\r
135 UINT32 MaxBlkLen:2; // bit 16:17\r
136 UINT32 BusWidth8:1; // bit 18\r
137 UINT32 Adma2:1; // bit 19\r
138 UINT32 Reserved2:1; // bit 20\r
139 UINT32 HighSpeed:1; // bit 21\r
140 UINT32 Sdma:1; // bit 22\r
141 UINT32 SuspRes:1; // bit 23\r
142 UINT32 Voltage33:1; // bit 24\r
143 UINT32 Voltage30:1; // bit 25\r
144 UINT32 Voltage18:1; // bit 26\r
145 UINT32 Reserved3:1; // bit 27\r
146 UINT32 SysBus64:1; // bit 28\r
147 UINT32 AsyncInt:1; // bit 29\r
148 UINT32 SlotType:2; // bit 30:31\r
149 UINT32 Sdr50:1; // bit 32\r
150 UINT32 Sdr104:1; // bit 33\r
151 UINT32 Ddr50:1; // bit 34\r
152 UINT32 Reserved4:1; // bit 35\r
153 UINT32 DriverTypeA:1; // bit 36\r
154 UINT32 DriverTypeC:1; // bit 37\r
155 UINT32 DriverTypeD:1; // bit 38\r
156 UINT32 DriverType4:1; // bit 39\r
157 UINT32 TimerCount:4; // bit 40:43\r
158 UINT32 Reserved5:1; // bit 44\r
159 UINT32 TuningSDR50:1; // bit 45\r
160 UINT32 RetuningMod:2; // bit 46:47\r
161 UINT32 ClkMultiplier:8; // bit 48:55\r
162 UINT32 Reserved6:7; // bit 56:62\r
163 UINT32 Hs400:1; // bit 63\r
164} SD_HC_SLOT_CAP;\r
165\r
166#pragma pack()\r
167\r
168/**\r
169 Software reset the specified SD host controller and enable all interrupts.\r
170\r
171 @param[in] Bar The mmio base address of the slot to be accessed.\r
172\r
173 @retval EFI_SUCCESS The software reset executes successfully.\r
174 @retval Others The software reset fails.\r
175\r
176**/\r
177EFI_STATUS\r
178SdPeimHcReset (\r
179 IN UINTN Bar\r
180 );\r
181\r
182/**\r
183 Set all interrupt status bits in Normal and Error Interrupt Status Enable\r
184 register.\r
185\r
186 @param[in] Bar The mmio base address of the slot to be accessed.\r
187\r
188 @retval EFI_SUCCESS The operation executes successfully.\r
189 @retval Others The operation fails.\r
190\r
191**/\r
192EFI_STATUS\r
193SdPeimHcEnableInterrupt (\r
194 IN UINTN Bar\r
195 );\r
196\r
197/**\r
198 Get the capability data from the specified slot.\r
199\r
200 @param[in] Bar The mmio base address of the slot to be accessed.\r
201 @param[out] Capability The buffer to store the capability data.\r
202\r
203 @retval EFI_SUCCESS The operation executes successfully.\r
204 @retval Others The operation fails.\r
205\r
206**/\r
207EFI_STATUS\r
208SdPeimHcGetCapability (\r
209 IN UINTN Bar,\r
210 OUT SD_HC_SLOT_CAP *Capability\r
211 );\r
212\r
213/**\r
214 Detect whether there is a SD card attached at the specified SD host controller\r
215 slot.\r
216\r
217 Refer to SD Host Controller Simplified spec 3.0 Section 3.1 for details.\r
218\r
219 @param[in] Bar The mmio base address of the slot to be accessed.\r
220\r
221 @retval EFI_SUCCESS There is a SD card attached.\r
222 @retval EFI_NO_MEDIA There is not a SD card attached.\r
223 @retval Others The detection fails.\r
224\r
225**/\r
226EFI_STATUS\r
227SdPeimHcCardDetect (\r
228 IN UINTN Bar\r
229 );\r
230\r
231/**\r
232 Initial SD host controller with lowest clock frequency, max power and max timeout value\r
233 at initialization.\r
234\r
235 @param[in] Bar The mmio base address of the slot to be accessed.\r
236\r
237 @retval EFI_SUCCESS The host controller is initialized successfully.\r
238 @retval Others The host controller isn't initialized successfully.\r
239\r
240**/\r
241EFI_STATUS\r
242SdPeimHcInitHost (\r
243 IN UINTN Bar\r
244 );\r
245\r
246/**\r
247 Send command SWITCH_FUNC to the SD device to check switchable function or switch card function.\r
248\r
249 Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.\r
250\r
251 @param[in] Slot The slot number of the SD card to send the command to.\r
252 @param[in] AccessMode The value for access mode group.\r
253 @param[in] CommandSystem The value for command set group.\r
254 @param[in] DriveStrength The value for drive length group.\r
255 @param[in] PowerLimit The value for power limit group.\r
256 @param[in] Mode Switch or check function.\r
6263ae93 257 @param[out] SwitchResp The return switch function status.\r
48555339
FT
258\r
259 @retval EFI_SUCCESS The operation is done correctly.\r
260 @retval Others The operation fails.\r
261\r
262**/\r
263EFI_STATUS\r
264SdPeimSwitch (\r
6263ae93
FT
265 IN SD_PEIM_HC_SLOT *Slot,\r
266 IN UINT8 AccessMode,\r
267 IN UINT8 CommandSystem,\r
268 IN UINT8 DriveStrength,\r
269 IN UINT8 PowerLimit,\r
270 IN BOOLEAN Mode,\r
271 OUT UINT8 *SwitchResp\r
48555339
FT
272 );\r
273\r
274/**\r
275 Send command READ_SINGLE_BLOCK/WRITE_SINGLE_BLOCK to the addressed SD device\r
276 to read/write the specified number of blocks.\r
277\r
278 Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.\r
279\r
280 @param[in] Slot The slot number of the SD card to send the command to.\r
281 @param[in] Lba The logical block address of starting access.\r
282 @param[in] BlockSize The block size of specified SD device partition.\r
283 @param[in] Buffer The pointer to the transfer buffer.\r
284 @param[in] BufferSize The size of transfer buffer.\r
285 @param[in] IsRead Boolean to show the operation direction.\r
286\r
287 @retval EFI_SUCCESS The operation is done correctly.\r
288 @retval Others The operation fails.\r
289\r
290**/\r
291EFI_STATUS\r
292SdPeimRwSingleBlock (\r
293 IN SD_PEIM_HC_SLOT *Slot,\r
294 IN EFI_LBA Lba,\r
295 IN UINT32 BlockSize,\r
296 IN VOID *Buffer,\r
297 IN UINTN BufferSize,\r
298 IN BOOLEAN IsRead\r
299 );\r
300\r
301/**\r
302 Send command READ_MULTIPLE_BLOCK/WRITE_MULTIPLE_BLOCK to the addressed SD device\r
303 to read/write the specified number of blocks.\r
304\r
305 Refer to SD Electrical Standard Spec 5.1 Section 6.10.4 for details.\r
306\r
307 @param[in] Slot The slot number of the Sd card to send the command to.\r
308 @param[in] Lba The logical block address of starting access.\r
309 @param[in] BlockSize The block size of specified SD device partition.\r
310 @param[in] Buffer The pointer to the transfer buffer.\r
311 @param[in] BufferSize The size of transfer buffer.\r
312 @param[in] IsRead Boolean to show the operation direction.\r
313\r
314 @retval EFI_SUCCESS The operation is done correctly.\r
315 @retval Others The operation fails.\r
316\r
317**/\r
318EFI_STATUS\r
319SdPeimRwMultiBlocks (\r
320 IN SD_PEIM_HC_SLOT *Slot,\r
321 IN EFI_LBA Lba,\r
322 IN UINT32 BlockSize,\r
323 IN VOID *Buffer,\r
324 IN UINTN BufferSize,\r
325 IN BOOLEAN IsRead\r
326 );\r
327\r
328/**\r
329 Execute SD device identification procedure.\r
330\r
331 Refer to SD Electrical Standard Spec 5.1 Section 6.4 for details.\r
332\r
333 @param[in] Slot The slot number of the Sd card to send the command to.\r
334\r
335 @retval EFI_SUCCESS There is a SD card.\r
336 @retval Others There is not a SD card.\r
337\r
338**/\r
339EFI_STATUS\r
340SdPeimIdentification (\r
341 IN SD_PEIM_HC_SLOT *Slot\r
342 );\r
343\r
344/**\r
345 Free the resource used by the TRB.\r
346\r
347 @param[in] Trb The pointer to the SD_TRB instance.\r
348\r
349**/\r
350VOID\r
351SdPeimFreeTrb (\r
352 IN SD_TRB *Trb\r
353 );\r
354\r
355#endif\r
356\r