TianoCore EDK2 master
Loading...
Searching...
No Matches
SdMmcPciHcDxe.h
Go to the documentation of this file.
1
11#ifndef _SD_MMC_PCI_HC_DXE_H_
12#define _SD_MMC_PCI_HC_DXE_H_
13
14#include <Uefi.h>
15
18#include <IndustryStandard/Sd.h>
19
21#include <Library/DebugLib.h>
25#include <Library/UefiLib.h>
27#include <Library/PcdLib.h>
28
29#include <Protocol/DevicePath.h>
30#include <Protocol/PciIo.h>
36
37#include "SdMmcPciHci.h"
38
39extern EFI_COMPONENT_NAME_PROTOCOL gSdMmcPciHcComponentName;
40extern EFI_COMPONENT_NAME2_PROTOCOL gSdMmcPciHcComponentName2;
41extern EFI_DRIVER_BINDING_PROTOCOL gSdMmcPciHcDriverBinding;
42
43extern EDKII_SD_MMC_OVERRIDE *mOverride;
44
45#define SD_MMC_HC_PRIVATE_SIGNATURE SIGNATURE_32 ('s', 'd', 't', 'f')
46
47#define SD_MMC_HC_PRIVATE_FROM_THIS(a) \
48 CR(a, SD_MMC_HC_PRIVATE_DATA, PassThru, SD_MMC_HC_PRIVATE_SIGNATURE)
49
50//
51// Generic time out value, 1 microsecond as unit.
52//
53#define SD_MMC_HC_GENERIC_TIMEOUT (PcdGet32 (PcdSdMmcGenericTimeoutValue))
54
55//
56// SD/MMC async transfer timer interval, set by experience.
57// The unit is 100us, takes 1ms as interval.
58//
59#define SD_MMC_HC_ASYNC_TIMER EFI_TIMER_PERIOD_MILLISECONDS(1)
60//
61// SD/MMC removable device enumeration timer interval, set by experience.
62// The unit is 100us, takes 100ms as interval.
63//
64#define SD_MMC_HC_ENUM_TIMER EFI_TIMER_PERIOD_MILLISECONDS(100)
65
66typedef enum {
67 UnknownCardType,
68 SdCardType,
69 SdioCardType,
70 MmcCardType,
71 EmmcCardType
72} SD_MMC_CARD_TYPE;
73
74typedef enum {
75 RemovableSlot,
76 EmbeddedSlot,
77 SharedBusSlot,
78 UnknownSlot
79} EFI_SD_MMC_SLOT_TYPE;
80
81typedef struct {
82 BOOLEAN Enable;
83 EFI_SD_MMC_SLOT_TYPE SlotType;
84 BOOLEAN MediaPresent;
85 BOOLEAN Initialized;
86 SD_MMC_CARD_TYPE CardType;
87 UINT64 CurrentFreq;
88 EDKII_SD_MMC_OPERATING_PARAMETERS OperatingParameters;
90
91typedef struct {
92 UINTN Signature;
93
94 EFI_HANDLE ControllerHandle;
96
98
99 UINT64 PciAttributes;
100 //
101 // The field is used to record the previous slot in GetNextSlot().
102 //
103 UINT8 PreviousSlot;
104 //
105 // For Non-blocking operation.
106 //
107 EFI_EVENT TimerEvent;
108 //
109 // For Sd removable device enumeration.
110 //
111 EFI_EVENT ConnectEvent;
112 LIST_ENTRY Queue;
113
114 SD_MMC_HC_SLOT Slot[SD_MMC_HC_MAX_SLOT];
115 SD_MMC_HC_SLOT_CAP Capability[SD_MMC_HC_MAX_SLOT];
116 UINT64 MaxCurrent[SD_MMC_HC_MAX_SLOT];
117 UINT16 ControllerVersion[SD_MMC_HC_MAX_SLOT];
118
119 //
120 // Some controllers may require to override base clock frequency
121 // value stored in Capabilities Register 1.
122 //
123 UINT32 BaseClkFreq[SD_MMC_HC_MAX_SLOT];
125
126typedef struct {
127 SD_MMC_BUS_MODE BusTiming;
128 UINT8 BusWidth;
129 UINT32 ClockFreq;
130 EDKII_SD_MMC_DRIVER_STRENGTH DriverStrength;
132
133#define SD_MMC_HC_TRB_SIG SIGNATURE_32 ('T', 'R', 'B', 'T')
134
135#define SD_MMC_TRB_RETRIES 5
136
137//
138// TRB (Transfer Request Block) contains information for the cmd request.
139//
140typedef struct {
141 UINT32 Signature;
142 LIST_ENTRY TrbList;
143
144 UINT8 Slot;
145 UINT16 BlockSize;
146
148 VOID *Data;
149 UINT32 DataLen;
150 BOOLEAN Read;
151 EFI_PHYSICAL_ADDRESS DataPhy;
152 VOID *DataMap;
153 SD_MMC_HC_TRANSFER_MODE Mode;
154 SD_MMC_HC_ADMA_LENGTH_MODE AdmaLengthMode;
155
156 EFI_EVENT Event;
157 BOOLEAN Started;
158 BOOLEAN CommandComplete;
159 UINT64 Timeout;
160 UINT32 Retries;
161
162 BOOLEAN PioModeTransferCompleted;
163 UINT32 PioBlockIndex;
164
165 SD_MMC_HC_ADMA_32_DESC_LINE *Adma32Desc;
166 SD_MMC_HC_ADMA_64_V3_DESC_LINE *Adma64V3Desc;
167 SD_MMC_HC_ADMA_64_V4_DESC_LINE *Adma64V4Desc;
168 EFI_PHYSICAL_ADDRESS AdmaDescPhy;
169 VOID *AdmaMap;
170 UINT32 AdmaPages;
171
172 SD_MMC_HC_PRIVATE_DATA *Private;
174
175#define SD_MMC_HC_TRB_FROM_THIS(a) \
176 CR(a, SD_MMC_HC_TRB, TrbList, SD_MMC_HC_TRB_SIG)
177
178//
179// Task for Non-blocking mode.
180//
181typedef struct {
182 UINT32 Signature;
183 LIST_ENTRY Link;
184
185 UINT8 Slot;
187 BOOLEAN IsStart;
188 EFI_EVENT Event;
189 UINT64 RetryTimes;
190 BOOLEAN InfiniteWait;
191 VOID *Map;
192 VOID *MapAddress;
194
195//
196// Prototypes
197//
198
209typedef
212 IN SD_MMC_HC_PRIVATE_DATA *Private,
213 IN UINT8 Slot
214 );
215
254EFIAPI
257 IN UINT8 Slot,
259 IN EFI_EVENT Event OPTIONAL
260 );
261
292EFIAPI
295 IN OUT UINT8 *Slot
296 );
297
333EFIAPI
336 IN UINT8 Slot,
337 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
338 );
339
362EFIAPI
365 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
366 OUT UINT8 *Slot
367 );
368
393EFIAPI
396 IN UINT8 Slot
397 );
398
399//
400// Driver model protocol interfaces
401//
402
446EFIAPI
449 IN EFI_HANDLE Controller,
450 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
451 );
452
489EFIAPI
492 IN EFI_HANDLE Controller,
493 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
494 );
495
523EFIAPI
526 IN EFI_HANDLE Controller,
527 IN UINTN NumberOfChildren,
528 IN EFI_HANDLE *ChildHandleBuffer
529 );
530
531//
532// EFI Component Name Functions
533//
534
575EFIAPI
578 IN CHAR8 *Language,
579 OUT CHAR16 **DriverName
580 );
581
651EFIAPI
654 IN EFI_HANDLE ControllerHandle,
655 IN EFI_HANDLE ChildHandle OPTIONAL,
656 IN CHAR8 *Language,
657 OUT CHAR16 **ControllerName
658 );
659
675 IN SD_MMC_HC_PRIVATE_DATA *Private,
676 IN UINT8 Slot,
678 IN EFI_EVENT Event
679 );
680
687VOID
689 IN SD_MMC_HC_TRB *Trb
690 );
691
705 IN SD_MMC_HC_PRIVATE_DATA *Private,
706 IN SD_MMC_HC_TRB *Trb
707 );
708
722 IN SD_MMC_HC_PRIVATE_DATA *Private,
723 IN SD_MMC_HC_TRB *Trb
724 );
725
738 IN SD_MMC_HC_PRIVATE_DATA *Private,
739 IN SD_MMC_HC_TRB *Trb
740 );
741
755 IN SD_MMC_HC_PRIVATE_DATA *Private,
756 IN SD_MMC_HC_TRB *Trb
757 );
758
771 IN SD_MMC_HC_PRIVATE_DATA *Private,
772 IN SD_MMC_HC_TRB *Trb
773 );
774
789 IN SD_MMC_HC_PRIVATE_DATA *Private,
790 IN UINT8 Slot
791 );
792
807 IN SD_MMC_HC_PRIVATE_DATA *Private,
808 IN UINT8 Slot
809 );
810
828 IN SD_MMC_HC_PRIVATE_DATA *Private,
829 IN UINT8 Slot,
830 IN SD_MMC_BUS_MODE BusTiming,
831 IN BOOLEAN FirstTimeSetup,
832 IN UINT64 ClockFreq
833 );
834
847 IN SD_MMC_HC_PRIVATE_DATA *Private,
848 IN UINT8 Slot
849 );
850
864 IN SD_MMC_HC_PRIVATE_DATA *Private,
865 IN UINT8 Slot
866 );
867
868#endif
UINT64 UINTN
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
EFI_STATUS EFIAPI SdMmcPciHcComponentNameGetDriverName(IN EFI_COMPONENT_NAME_PROTOCOL *This, IN CHAR8 *Language, OUT CHAR16 **DriverName)
Definition: ComponentName.c:80
EFI_STATUS SdMmcHcReset(IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 Slot)
Definition: SdMmcPciHci.c:477
EFI_STATUS EFIAPI SdMmcPciHcDriverBindingStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
EFI_STATUS SdMmcWaitTrbEnv(IN SD_MMC_HC_PRIVATE_DATA *Private, IN SD_MMC_HC_TRB *Trb)
Definition: SdMmcPciHci.c:2075
EFI_STATUS SdMmcCheckTrbResult(IN SD_MMC_HC_PRIVATE_DATA *Private, IN SD_MMC_HC_TRB *Trb)
Definition: SdMmcPciHci.c:2798
SD_MMC_HC_TRB * SdMmcCreateTrb(IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 Slot, IN EFI_SD_MMC_PASS_THRU_COMMAND_PACKET *Packet, IN EFI_EVENT Event)
Definition: SdMmcPciHci.c:1848
EFI_STATUS(* CARD_TYPE_DETECT_ROUTINE)(IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 Slot)
EFI_STATUS SdMmcHcInitHost(IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 Slot)
Definition: SdMmcPciHci.c:1213
EFI_STATUS SdMmcCheckTrbEnv(IN SD_MMC_HC_PRIVATE_DATA *Private, IN SD_MMC_HC_TRB *Trb)
Definition: SdMmcPciHci.c:2021
EFI_STATUS EFIAPI SdMmcPassThruPassThru(IN EFI_SD_MMC_PASS_THRU_PROTOCOL *This, IN UINT8 Slot, IN OUT EFI_SD_MMC_PASS_THRU_COMMAND_PACKET *Packet, IN EFI_EVENT Event OPTIONAL)
EFI_STATUS SdMmcHcClockSupply(IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 Slot, IN SD_MMC_BUS_MODE BusTiming, IN BOOLEAN FirstTimeSetup, IN UINT64 ClockFreq)
Definition: SdMmcPciHci.c:815
EFI_STATUS EFIAPI SdMmcPassThruResetDevice(IN EFI_SD_MMC_PASS_THRU_PROTOCOL *This, IN UINT8 Slot)
EFI_STATUS EmmcIdentification(IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 Slot)
Definition: EmmcDevice.c:1318
EFI_STATUS EFIAPI SdMmcPassThruGetSlotNumber(IN EFI_SD_MMC_PASS_THRU_PROTOCOL *This, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, OUT UINT8 *Slot)
EFI_STATUS EFIAPI SdMmcPciHcComponentNameGetControllerName(IN EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ChildHandle OPTIONAL, IN CHAR8 *Language, OUT CHAR16 **ControllerName)
EFI_STATUS EFIAPI SdMmcPassThruGetNextSlot(IN EFI_SD_MMC_PASS_THRU_PROTOCOL *This, IN OUT UINT8 *Slot)
EFI_STATUS SdMmcWaitTrbResult(IN SD_MMC_HC_PRIVATE_DATA *Private, IN SD_MMC_HC_TRB *Trb)
Definition: SdMmcPciHci.c:2888
EFI_STATUS EFIAPI SdMmcPciHcDriverBindingSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
EFI_STATUS EFIAPI SdMmcPciHcDriverBindingStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer)
EFI_STATUS SdCardIdentification(IN SD_MMC_HC_PRIVATE_DATA *Private, IN UINT8 Slot)
Definition: SdDevice.c:1210
VOID SdMmcFreeTrb(IN SD_MMC_HC_TRB *Trb)
Definition: SdMmcPciHci.c:1959
EFI_STATUS SdMmcExecTrb(IN SD_MMC_HC_PRIVATE_DATA *Private, IN SD_MMC_HC_TRB *Trb)
Definition: SdMmcPciHci.c:2127
EFI_STATUS EFIAPI SdMmcPassThruBuildDevicePath(IN EFI_SD_MMC_PASS_THRU_PROTOCOL *This, IN UINT8 Slot, IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath)
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33