TianoCore EDK2 master
Loading...
Searching...
No Matches
SdMmcPciHci.h
Go to the documentation of this file.
1
11#ifndef _SD_MMC_PCI_HCI_H_
12#define _SD_MMC_PCI_HCI_H_
13
14//
15// SD Host Controller SlotInfo Register Offset
16//
17#define SD_MMC_HC_SLOT_OFFSET 0x40
18
19#define SD_MMC_HC_MAX_SLOT 6
20
21//
22// SD Host Controller MMIO Register Offset
23//
24#define SD_MMC_HC_SDMA_ADDR 0x00
25#define SD_MMC_HC_ARG2 0x00
26#define SD_MMC_HC_BLK_SIZE 0x04
27#define SD_MMC_HC_BLK_COUNT 0x06
28#define SD_MMC_HC_ARG1 0x08
29#define SD_MMC_HC_TRANS_MOD 0x0C
30#define SD_MMC_HC_COMMAND 0x0E
31#define SD_MMC_HC_RESPONSE 0x10
32#define SD_MMC_HC_BUF_DAT_PORT 0x20
33#define SD_MMC_HC_PRESENT_STATE 0x24
34#define SD_MMC_HC_HOST_CTRL1 0x28
35#define SD_MMC_HC_POWER_CTRL 0x29
36#define SD_MMC_HC_BLK_GAP_CTRL 0x2A
37#define SD_MMC_HC_WAKEUP_CTRL 0x2B
38#define SD_MMC_HC_CLOCK_CTRL 0x2C
39#define SD_MMC_HC_TIMEOUT_CTRL 0x2E
40#define SD_MMC_HC_SW_RST 0x2F
41#define SD_MMC_HC_NOR_INT_STS 0x30
42#define SD_MMC_HC_ERR_INT_STS 0x32
43#define SD_MMC_HC_NOR_INT_STS_EN 0x34
44#define SD_MMC_HC_ERR_INT_STS_EN 0x36
45#define SD_MMC_HC_NOR_INT_SIG_EN 0x38
46#define SD_MMC_HC_ERR_INT_SIG_EN 0x3A
47#define SD_MMC_HC_AUTO_CMD_ERR_STS 0x3C
48#define SD_MMC_HC_HOST_CTRL2 0x3E
49#define SD_MMC_HC_CAP 0x40
50#define SD_MMC_HC_MAX_CURRENT_CAP 0x48
51#define SD_MMC_HC_FORCE_EVT_AUTO_CMD 0x50
52#define SD_MMC_HC_FORCE_EVT_ERR_INT 0x52
53#define SD_MMC_HC_ADMA_ERR_STS 0x54
54#define SD_MMC_HC_ADMA_SYS_ADDR 0x58
55#define SD_MMC_HC_PRESET_VAL 0x60
56#define SD_MMC_HC_SHARED_BUS_CTRL 0xE0
57#define SD_MMC_HC_SLOT_INT_STS 0xFC
58#define SD_MMC_HC_CTRL_VER 0xFE
59
60//
61// SD Host Controller bits to HOST_CTRL2 register
62//
63#define SD_MMC_HC_CTRL_UHS_MASK 0x0007
64#define SD_MMC_HC_CTRL_UHS_SDR12 0x0000
65#define SD_MMC_HC_CTRL_UHS_SDR25 0x0001
66#define SD_MMC_HC_CTRL_UHS_SDR50 0x0002
67#define SD_MMC_HC_CTRL_UHS_SDR104 0x0003
68#define SD_MMC_HC_CTRL_UHS_DDR50 0x0004
69#define SD_MMC_HC_CTRL_MMC_LEGACY 0x0000
70#define SD_MMC_HC_CTRL_MMC_HS_SDR 0x0001
71#define SD_MMC_HC_CTRL_MMC_HS_DDR 0x0004
72#define SD_MMC_HC_CTRL_MMC_HS200 0x0003
73#define SD_MMC_HC_CTRL_MMC_HS400 0x0005
74
75#define SD_MMC_HC_CTRL_DRIVER_STRENGTH_MASK 0x0030
76
77//
78// The transfer modes supported by SD Host Controller
79//
80typedef enum {
81 SdMmcNoData,
82 SdMmcPioMode,
83 SdMmcSdmaMode,
84 SdMmcAdma32bMode,
85 SdMmcAdma64bV3Mode,
86 SdMmcAdma64bV4Mode
87} SD_MMC_HC_TRANSFER_MODE;
88
89//
90// The ADMA transfer lengths supported by SD Host Controller
91//
92typedef enum {
93 SdMmcAdmaLen16b,
94 SdMmcAdmaLen26b
95} SD_MMC_HC_ADMA_LENGTH_MODE;
96
97//
98// The maximum data length of each descriptor line
99//
100#define ADMA_MAX_DATA_PER_LINE_16B SIZE_64KB
101#define ADMA_MAX_DATA_PER_LINE_26B SIZE_64MB
102
103//
104// ADMA descriptor for 32b addressing.
105//
106typedef struct {
107 UINT32 Valid : 1;
108 UINT32 End : 1;
109 UINT32 Int : 1;
110 UINT32 Reserved : 1;
111 UINT32 Act : 2;
112 UINT32 UpperLength : 10;
113 UINT32 LowerLength : 16;
114 UINT32 Address;
116
117//
118// ADMA descriptor for 64b addressing.
119//
120typedef struct {
121 UINT32 Valid : 1;
122 UINT32 End : 1;
123 UINT32 Int : 1;
124 UINT32 Reserved : 1;
125 UINT32 Act : 2;
126 UINT32 UpperLength : 10;
127 UINT32 LowerLength : 16;
128 UINT32 LowerAddress;
129 UINT32 UpperAddress;
131
132typedef struct {
133 UINT32 Valid : 1;
134 UINT32 End : 1;
135 UINT32 Int : 1;
136 UINT32 Reserved : 1;
137 UINT32 Act : 2;
138 UINT32 UpperLength : 10;
139 UINT32 LowerLength : 16;
140 UINT32 LowerAddress;
141 UINT32 UpperAddress;
142 UINT32 Reserved1;
144
145#define SD_MMC_SDMA_BOUNDARY 512 * 1024
146#define SD_MMC_SDMA_ROUND_UP(x, n) (((x) + n) & ~(n - 1))
147
148typedef struct {
149 UINT8 FirstBar : 3; // bit 0:2
150 UINT8 Reserved : 1; // bit 3
151 UINT8 SlotNum : 3; // bit 4:6
152 UINT8 Reserved1 : 1; // bit 7
154
155typedef struct {
156 UINT32 TimeoutFreq : 6; // bit 0:5
157 UINT32 Reserved : 1; // bit 6
158 UINT32 TimeoutUnit : 1; // bit 7
159 UINT32 BaseClkFreq : 8; // bit 8:15
160 UINT32 MaxBlkLen : 2; // bit 16:17
161 UINT32 BusWidth8 : 1; // bit 18
162 UINT32 Adma2 : 1; // bit 19
163 UINT32 Reserved2 : 1; // bit 20
164 UINT32 HighSpeed : 1; // bit 21
165 UINT32 Sdma : 1; // bit 22
166 UINT32 SuspRes : 1; // bit 23
167 UINT32 Voltage33 : 1; // bit 24
168 UINT32 Voltage30 : 1; // bit 25
169 UINT32 Voltage18 : 1; // bit 26
170 UINT32 SysBus64V4 : 1; // bit 27
171 UINT32 SysBus64V3 : 1; // bit 28
172 UINT32 AsyncInt : 1; // bit 29
173 UINT32 SlotType : 2; // bit 30:31
174 UINT32 Sdr50 : 1; // bit 32
175 UINT32 Sdr104 : 1; // bit 33
176 UINT32 Ddr50 : 1; // bit 34
177 UINT32 Reserved3 : 1; // bit 35
178 UINT32 DriverTypeA : 1; // bit 36
179 UINT32 DriverTypeC : 1; // bit 37
180 UINT32 DriverTypeD : 1; // bit 38
181 UINT32 DriverType4 : 1; // bit 39
182 UINT32 TimerCount : 4; // bit 40:43
183 UINT32 Reserved4 : 1; // bit 44
184 UINT32 TuningSDR50 : 1; // bit 45
185 UINT32 RetuningMod : 2; // bit 46:47
186 UINT32 ClkMultiplier : 8; // bit 48:55
187 UINT32 Reserved5 : 7; // bit 56:62
188 UINT32 Hs400 : 1; // bit 63
190
191//
192// SD Host controller version
193//
194#define SD_MMC_HC_CTRL_VER_100 0x00
195#define SD_MMC_HC_CTRL_VER_200 0x01
196#define SD_MMC_HC_CTRL_VER_300 0x02
197#define SD_MMC_HC_CTRL_VER_400 0x03
198#define SD_MMC_HC_CTRL_VER_410 0x04
199#define SD_MMC_HC_CTRL_VER_420 0x05
200
201//
202// SD Host controller V4 enhancements
203//
204#define SD_MMC_HC_V4_EN BIT12
205#define SD_MMC_HC_64_ADDR_EN BIT13
206#define SD_MMC_HC_26_DATA_LEN_ADMA_EN BIT10
207
215VOID
217 IN UINT8 Slot,
218 IN SD_MMC_HC_SLOT_CAP *Capability
219 );
220
233EFIAPI
235 IN EFI_PCI_IO_PROTOCOL *PciIo,
236 OUT UINT8 *FirstBar,
237 OUT UINT8 *SlotNum
238 );
239
264EFIAPI
266 IN EFI_PCI_IO_PROTOCOL *PciIo,
267 IN UINT8 BarIndex,
268 IN UINT32 Offset,
269 IN BOOLEAN Read,
270 IN UINT8 Count,
271 IN OUT VOID *Data
272 );
273
296EFIAPI
298 IN EFI_PCI_IO_PROTOCOL *PciIo,
299 IN UINT8 BarIndex,
300 IN UINT32 Offset,
301 IN UINT8 Count,
302 IN VOID *OrData
303 );
304
327EFIAPI
329 IN EFI_PCI_IO_PROTOCOL *PciIo,
330 IN UINT8 BarIndex,
331 IN UINT32 Offset,
332 IN UINT8 Count,
333 IN VOID *AndData
334 );
335
359EFIAPI
361 IN EFI_PCI_IO_PROTOCOL *PciIo,
362 IN UINT8 BarIndex,
363 IN UINT32 Offset,
364 IN UINT8 Count,
365 IN UINT64 MaskValue,
366 IN UINT64 TestValue,
367 IN UINT64 Timeout
368 );
369
383 IN EFI_PCI_IO_PROTOCOL *PciIo,
384 IN UINT8 Slot,
385 OUT UINT16 *Version
386 );
387
401 IN EFI_PCI_IO_PROTOCOL *PciIo,
402 IN UINT8 Slot
403 );
404
418 IN EFI_PCI_IO_PROTOCOL *PciIo,
419 IN UINT8 Slot,
420 OUT SD_MMC_HC_SLOT_CAP *Capability
421 );
422
436 IN EFI_PCI_IO_PROTOCOL *PciIo,
437 IN UINT8 Slot,
438 OUT UINT64 *MaxCurrent
439 );
440
458 IN EFI_PCI_IO_PROTOCOL *PciIo,
459 IN UINT8 Slot,
460 OUT BOOLEAN *MediaPresent
461 );
462
477 IN EFI_PCI_IO_PROTOCOL *PciIo,
478 IN UINT8 Slot
479 );
480
492 IN EFI_PCI_IO_PROTOCOL *PciIo,
493 IN UINT8 Slot
494 );
495
511 IN EFI_PCI_IO_PROTOCOL *PciIo,
512 IN UINT8 Slot,
513 IN UINT8 PowerCtrl
514 );
515
531 IN EFI_PCI_IO_PROTOCOL *PciIo,
532 IN UINT8 Slot,
533 IN UINT16 BusWidth
534 );
535
551 IN EFI_PCI_IO_PROTOCOL *PciIo,
552 IN UINT8 Slot,
553 IN SD_MMC_HC_SLOT_CAP Capability
554 );
555
570 IN EFI_PCI_IO_PROTOCOL *PciIo,
571 IN UINT8 Slot
572 );
573
587 IN EFI_HANDLE ControllerHandle,
588 IN EFI_PCI_IO_PROTOCOL *PciIo,
589 IN UINT8 Slot,
590 IN SD_MMC_BUS_MODE Timing
591 );
592
605 IN EFI_PCI_IO_PROTOCOL *PciIo,
606 IN UINT8 SlotIndex,
607 IN SD_DRIVER_STRENGTH_TYPE DriverStrength
608 );
609
610#endif
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
EFI_STATUS SdMmcHcInitPowerVoltage(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot, IN SD_MMC_HC_SLOT_CAP Capability)
Definition: SdMmcPciHci.c:1127
EFI_STATUS SdMmcHcCardDetect(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot, OUT BOOLEAN *MediaPresent)
Definition: SdMmcPciHci.c:678
EFI_STATUS EFIAPI SdMmcHcRwMmio(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 BarIndex, IN UINT32 Offset, IN BOOLEAN Read, IN UINT8 Count, IN OUT VOID *Data)
Definition: SdMmcPciHci.c:143
EFI_STATUS SdMmcHcStartSdClock(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot)
Definition: SdMmcPciHci.c:785
EFI_STATUS SdMmcHcGetMaxCurrent(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot, OUT UINT64 *MaxCurrent)
Definition: SdMmcPciHci.c:649
EFI_STATUS SdMmcSetDriverStrength(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 SlotIndex, IN SD_DRIVER_STRENGTH_TYPE DriverStrength)
Definition: SdMmcPciHci.c:1399
EFI_STATUS SdMmcHcUhsSignaling(IN EFI_HANDLE ControllerHandle, IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot, IN SD_MMC_BUS_MODE Timing)
Definition: SdMmcPciHci.c:1310
EFI_STATUS EFIAPI SdMmcHcGetSlotInfo(IN EFI_PCI_IO_PROTOCOL *PciIo, OUT UINT8 *FirstBar, OUT UINT8 *SlotNum)
Definition: SdMmcPciHci.c:92
EFI_STATUS EFIAPI SdMmcHcAndMmio(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 BarIndex, IN UINT32 Offset, IN UINT8 Count, IN VOID *AndData)
Definition: SdMmcPciHci.c:283
EFI_STATUS SdMmcHcGetCapability(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot, OUT SD_MMC_HC_SLOT_CAP *Capability)
Definition: SdMmcPciHci.c:618
EFI_STATUS SdMmcHcInitTimeoutCtrl(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot)
Definition: SdMmcPciHci.c:1187
EFI_STATUS SdMmcHcStopClock(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot)
Definition: SdMmcPciHci.c:739
EFI_STATUS SdMmcHcPowerControl(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot, IN UINT8 PowerCtrl)
Definition: SdMmcPciHci.c:971
EFI_STATUS SdMmcHcGetControllerVersion(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot, OUT UINT16 *Version)
Definition: SdMmcPciHci.c:448
EFI_STATUS EFIAPI SdMmcHcWaitMmioSet(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 BarIndex, IN UINT32 Offset, IN UINT8 Count, IN UINT64 MaskValue, IN UINT64 TestValue, IN UINT64 Timeout)
Definition: SdMmcPciHci.c:393
VOID DumpCapabilityReg(IN UINT8 Slot, IN SD_MMC_HC_SLOT_CAP *Capability)
Definition: SdMmcPciHci.c:25
EFI_STATUS SdMmcHcSetBusWidth(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot, IN UINT16 BusWidth)
Definition: SdMmcPciHci.c:1011
EFI_STATUS SdMmcHcEnableInterrupt(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot)
Definition: SdMmcPciHci.c:580
EFI_STATUS EFIAPI SdMmcHcOrMmio(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 BarIndex, IN UINT32 Offset, IN UINT8 Count, IN VOID *OrData)
Definition: SdMmcPciHci.c:225
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33