]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h
MdeModulePkg/SdMmcPciHcDxe: Fix PIO transfer mode
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / SdMmcPciHcDxe / SdMmcPciHcDxe.h
CommitLineData
48555339
FT
1/** @file\r
2\r
3 Provides some data structure definitions used by the SD/MMC host controller driver.\r
4\r
690d60c0 5Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.\r
c67617f3 6Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.<BR>\r
9d510e61 7SPDX-License-Identifier: BSD-2-Clause-Patent\r
48555339
FT
8\r
9**/\r
10\r
11#ifndef _SD_MMC_PCI_HC_DXE_H_\r
12#define _SD_MMC_PCI_HC_DXE_H_\r
13\r
14#include <Uefi.h>\r
15\r
16#include <IndustryStandard/Pci.h>\r
17#include <IndustryStandard/Emmc.h>\r
18#include <IndustryStandard/Sd.h>\r
19\r
20#include <Library/UefiDriverEntryPoint.h>\r
21#include <Library/DebugLib.h>\r
22#include <Library/UefiBootServicesTableLib.h>\r
23#include <Library/BaseMemoryLib.h>\r
24#include <Library/MemoryAllocationLib.h>\r
25#include <Library/UefiLib.h>\r
26#include <Library/DevicePathLib.h>\r
27\r
28#include <Protocol/DevicePath.h>\r
29#include <Protocol/PciIo.h>\r
30#include <Protocol/DriverBinding.h>\r
31#include <Protocol/ComponentName.h>\r
32#include <Protocol/ComponentName2.h>\r
b23fc39c 33#include <Protocol/SdMmcOverride.h>\r
48555339
FT
34#include <Protocol/SdMmcPassThru.h>\r
35\r
36#include "SdMmcPciHci.h"\r
37\r
38extern EFI_COMPONENT_NAME_PROTOCOL gSdMmcPciHcComponentName;\r
39extern EFI_COMPONENT_NAME2_PROTOCOL gSdMmcPciHcComponentName2;\r
40extern EFI_DRIVER_BINDING_PROTOCOL gSdMmcPciHcDriverBinding;\r
41\r
b23fc39c
AB
42extern EDKII_SD_MMC_OVERRIDE *mOverride;\r
43\r
48555339
FT
44#define SD_MMC_HC_PRIVATE_SIGNATURE SIGNATURE_32 ('s', 'd', 't', 'f')\r
45\r
46#define SD_MMC_HC_PRIVATE_FROM_THIS(a) \\r
47 CR(a, SD_MMC_HC_PRIVATE_DATA, PassThru, SD_MMC_HC_PRIVATE_SIGNATURE)\r
48\r
49//\r
50// Generic time out value, 1 microsecond as unit.\r
51//\r
52#define SD_MMC_HC_GENERIC_TIMEOUT 1 * 1000 * 1000\r
53\r
54//\r
55// SD/MMC async transfer timer interval, set by experience.\r
56// The unit is 100us, takes 1ms as interval.\r
57//\r
58#define SD_MMC_HC_ASYNC_TIMER EFI_TIMER_PERIOD_MILLISECONDS(1)\r
59//\r
60// SD/MMC removable device enumeration timer interval, set by experience.\r
61// The unit is 100us, takes 100ms as interval.\r
62//\r
63#define SD_MMC_HC_ENUM_TIMER EFI_TIMER_PERIOD_MILLISECONDS(100)\r
64\r
65typedef enum {\r
66 UnknownCardType,\r
67 SdCardType,\r
68 SdioCardType,\r
69 MmcCardType,\r
70 EmmcCardType\r
71} SD_MMC_CARD_TYPE;\r
72\r
73typedef enum {\r
74 RemovableSlot,\r
75 EmbeddedSlot,\r
76 SharedBusSlot,\r
77 UnknownSlot\r
78} EFI_SD_MMC_SLOT_TYPE;\r
79\r
80typedef struct {\r
adec1f5d
AM
81 BOOLEAN Enable;\r
82 EFI_SD_MMC_SLOT_TYPE SlotType;\r
83 BOOLEAN MediaPresent;\r
84 BOOLEAN Initialized;\r
85 SD_MMC_CARD_TYPE CardType;\r
64362314 86 UINT64 CurrentFreq;\r
adec1f5d 87 EDKII_SD_MMC_OPERATING_PARAMETERS OperatingParameters;\r
48555339
FT
88} SD_MMC_HC_SLOT;\r
89\r
90typedef struct {\r
91 UINTN Signature;\r
92\r
93 EFI_HANDLE ControllerHandle;\r
94 EFI_PCI_IO_PROTOCOL *PciIo;\r
95\r
96 EFI_SD_MMC_PASS_THRU_PROTOCOL PassThru;\r
97\r
98 UINT64 PciAttributes;\r
99 //\r
100 // The field is used to record the previous slot in GetNextSlot().\r
101 //\r
102 UINT8 PreviousSlot;\r
103 //\r
104 // For Non-blocking operation.\r
105 //\r
106 EFI_EVENT TimerEvent;\r
107 //\r
108 // For Sd removable device enumeration.\r
109 //\r
110 EFI_EVENT ConnectEvent;\r
111 LIST_ENTRY Queue;\r
112\r
113 SD_MMC_HC_SLOT Slot[SD_MMC_HC_MAX_SLOT];\r
114 SD_MMC_HC_SLOT_CAP Capability[SD_MMC_HC_MAX_SLOT];\r
115 UINT64 MaxCurrent[SD_MMC_HC_MAX_SLOT];\r
b5547b9c 116 UINT16 ControllerVersion[SD_MMC_HC_MAX_SLOT];\r
7f3b0bad
MW
117\r
118 //\r
119 // Some controllers may require to override base clock frequency\r
120 // value stored in Capabilities Register 1.\r
121 //\r
122 UINT32 BaseClkFreq[SD_MMC_HC_MAX_SLOT];\r
48555339
FT
123} SD_MMC_HC_PRIVATE_DATA;\r
124\r
adec1f5d
AM
125typedef struct {\r
126 SD_MMC_BUS_MODE BusTiming;\r
127 UINT8 BusWidth;\r
128 UINT32 ClockFreq;\r
129 EDKII_SD_MMC_DRIVER_STRENGTH DriverStrength;\r
130} SD_MMC_BUS_SETTINGS;\r
131\r
48555339
FT
132#define SD_MMC_HC_TRB_SIG SIGNATURE_32 ('T', 'R', 'B', 'T')\r
133\r
c67617f3
AM
134#define SD_MMC_TRB_RETRIES 5\r
135\r
48555339
FT
136//\r
137// TRB (Transfer Request Block) contains information for the cmd request.\r
138//\r
139typedef struct {\r
140 UINT32 Signature;\r
141 LIST_ENTRY TrbList;\r
142\r
143 UINT8 Slot;\r
144 UINT16 BlockSize;\r
145\r
146 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET *Packet;\r
147 VOID *Data;\r
148 UINT32 DataLen;\r
149 BOOLEAN Read;\r
150 EFI_PHYSICAL_ADDRESS DataPhy;\r
151 VOID *DataMap;\r
152 SD_MMC_HC_TRANSFER_MODE Mode;\r
690d60c0 153 SD_MMC_HC_ADMA_LENGTH_MODE AdmaLengthMode;\r
48555339
FT
154\r
155 EFI_EVENT Event;\r
156 BOOLEAN Started;\r
6d387610 157 BOOLEAN CommandComplete;\r
48555339 158 UINT64 Timeout;\r
c67617f3 159 UINT32 Retries;\r
48555339 160\r
9bfaa3da
AM
161 BOOLEAN PioModeTransferCompleted;\r
162 UINT32 PioBlockIndex;\r
163\r
b5547b9c 164 SD_MMC_HC_ADMA_32_DESC_LINE *Adma32Desc;\r
690d60c0
AS
165 SD_MMC_HC_ADMA_64_V3_DESC_LINE *Adma64V3Desc;\r
166 SD_MMC_HC_ADMA_64_V4_DESC_LINE *Adma64V4Desc;\r
48555339
FT
167 EFI_PHYSICAL_ADDRESS AdmaDescPhy;\r
168 VOID *AdmaMap;\r
169 UINT32 AdmaPages;\r
170\r
171 SD_MMC_HC_PRIVATE_DATA *Private;\r
172} SD_MMC_HC_TRB;\r
173\r
174#define SD_MMC_HC_TRB_FROM_THIS(a) \\r
175 CR(a, SD_MMC_HC_TRB, TrbList, SD_MMC_HC_TRB_SIG)\r
176\r
177//\r
178// Task for Non-blocking mode.\r
179//\r
180typedef struct {\r
181 UINT32 Signature;\r
182 LIST_ENTRY Link;\r
183\r
184 UINT8 Slot;\r
185 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET *Packet;\r
186 BOOLEAN IsStart;\r
187 EFI_EVENT Event;\r
188 UINT64 RetryTimes;\r
189 BOOLEAN InfiniteWait;\r
190 VOID *Map;\r
191 VOID *MapAddress;\r
192} SD_MMC_HC_QUEUE;\r
193\r
194//\r
195// Prototypes\r
196//\r
197/**\r
198 Execute card identification procedure.\r
199\r
200 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.\r
201 @param[in] Slot The slot number of the SD card to send the command to.\r
202\r
203 @retval EFI_SUCCESS The card is identified correctly.\r
204 @retval Others The card can't be identified.\r
205\r
206**/\r
207typedef\r
208EFI_STATUS\r
209(*CARD_TYPE_DETECT_ROUTINE) (\r
210 IN SD_MMC_HC_PRIVATE_DATA *Private,\r
211 IN UINT8 Slot\r
212 );\r
213\r
214/**\r
215 Sends SD command to an SD card that is attached to the SD controller.\r
216\r
217 The PassThru() function sends the SD command specified by Packet to the SD card\r
218 specified by Slot.\r
219\r
220 If Packet is successfully sent to the SD card, then EFI_SUCCESS is returned.\r
221\r
222 If a device error occurs while sending the Packet, then EFI_DEVICE_ERROR is returned.\r
223\r
224 If Slot is not in a valid range for the SD controller, then EFI_INVALID_PARAMETER\r
225 is returned.\r
226\r
227 If Packet defines a data command but both InDataBuffer and OutDataBuffer are NULL,\r
228 EFI_INVALID_PARAMETER is returned.\r
229\r
230 @param[in] This A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.\r
231 @param[in] Slot The slot number of the SD card to send the command to.\r
232 @param[in,out] Packet A pointer to the SD command data structure.\r
233 @param[in] Event If Event is NULL, blocking I/O is performed. If Event is\r
234 not NULL, then nonblocking I/O is performed, and Event\r
235 will be signaled when the Packet completes.\r
236\r
237 @retval EFI_SUCCESS The SD Command Packet was sent by the host.\r
238 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SD\r
239 command Packet.\r
240 @retval EFI_INVALID_PARAMETER Packet, Slot, or the contents of the Packet is invalid.\r
241 @retval EFI_INVALID_PARAMETER Packet defines a data command but both InDataBuffer and\r
242 OutDataBuffer are NULL.\r
243 @retval EFI_NO_MEDIA SD Device not present in the Slot.\r
244 @retval EFI_UNSUPPORTED The command described by the SD Command Packet is not\r
245 supported by the host controller.\r
246 @retval EFI_BAD_BUFFER_SIZE The InTransferLength or OutTransferLength exceeds the\r
247 limit supported by SD card ( i.e. if the number of bytes\r
248 exceed the Last LBA).\r
249\r
250**/\r
251EFI_STATUS\r
252EFIAPI\r
253SdMmcPassThruPassThru (\r
254 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *This,\r
255 IN UINT8 Slot,\r
256 IN OUT EFI_SD_MMC_PASS_THRU_COMMAND_PACKET *Packet,\r
257 IN EFI_EVENT Event OPTIONAL\r
258 );\r
259\r
260/**\r
261 Used to retrieve next slot numbers supported by the SD controller. The function\r
262 returns information about all available slots (populated or not-populated).\r
263\r
264 The GetNextSlot() function retrieves the next slot number on an SD controller.\r
265 If on input Slot is 0xFF, then the slot number of the first slot on the SD controller\r
266 is returned.\r
267\r
268 If Slot is a slot number that was returned on a previous call to GetNextSlot(), then\r
269 the slot number of the next slot on the SD controller is returned.\r
270\r
271 If Slot is not 0xFF and Slot was not returned on a previous call to GetNextSlot(),\r
272 EFI_INVALID_PARAMETER is returned.\r
273\r
274 If Slot is the slot number of the last slot on the SD controller, then EFI_NOT_FOUND\r
275 is returned.\r
276\r
277 @param[in] This A pointer to the EFI_SD_MMMC_PASS_THRU_PROTOCOL instance.\r
278 @param[in,out] Slot On input, a pointer to a slot number on the SD controller.\r
279 On output, a pointer to the next slot number on the SD controller.\r
280 An input value of 0xFF retrieves the first slot number on the SD\r
281 controller.\r
282\r
283 @retval EFI_SUCCESS The next slot number on the SD controller was returned in Slot.\r
284 @retval EFI_NOT_FOUND There are no more slots on this SD controller.\r
285 @retval EFI_INVALID_PARAMETER Slot is not 0xFF and Slot was not returned on a previous call\r
286 to GetNextSlot().\r
287\r
288**/\r
289EFI_STATUS\r
290EFIAPI\r
291SdMmcPassThruGetNextSlot (\r
292 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *This,\r
293 IN OUT UINT8 *Slot\r
294 );\r
295\r
296/**\r
297 Used to allocate and build a device path node for an SD card on the SD controller.\r
298\r
299 The BuildDevicePath() function allocates and builds a single device node for the SD\r
300 card specified by Slot.\r
301\r
302 If the SD card specified by Slot is not present on the SD controller, then EFI_NOT_FOUND\r
303 is returned.\r
304\r
305 If DevicePath is NULL, then EFI_INVALID_PARAMETER is returned.\r
306\r
307 If there are not enough resources to allocate the device path node, then EFI_OUT_OF_RESOURCES\r
308 is returned.\r
309\r
310 Otherwise, DevicePath is allocated with the boot service AllocatePool(), the contents of\r
311 DevicePath are initialized to describe the SD card specified by Slot, and EFI_SUCCESS is\r
312 returned.\r
313\r
314 @param[in] This A pointer to the EFI_SD_MMMC_PASS_THRU_PROTOCOL instance.\r
315 @param[in] Slot Specifies the slot number of the SD card for which a device\r
316 path node is to be allocated and built.\r
317 @param[in,out] DevicePath A pointer to a single device path node that describes the SD\r
318 card specified by Slot. This function is responsible for\r
319 allocating the buffer DevicePath with the boot service\r
320 AllocatePool(). It is the caller's responsibility to free\r
321 DevicePath when the caller is finished with DevicePath.\r
322\r
323 @retval EFI_SUCCESS The device path node that describes the SD card specified by\r
324 Slot was allocated and returned in DevicePath.\r
325 @retval EFI_NOT_FOUND The SD card specified by Slot does not exist on the SD controller.\r
326 @retval EFI_INVALID_PARAMETER DevicePath is NULL.\r
327 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate DevicePath.\r
328\r
329**/\r
330EFI_STATUS\r
331EFIAPI\r
332SdMmcPassThruBuildDevicePath (\r
333 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *This,\r
334 IN UINT8 Slot,\r
335 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath\r
336 );\r
337\r
338/**\r
339 This function retrieves an SD card slot number based on the input device path.\r
340\r
341 The GetSlotNumber() function retrieves slot number for the SD card specified by\r
342 the DevicePath node. If DevicePath is NULL, EFI_INVALID_PARAMETER is returned.\r
343\r
344 If DevicePath is not a device path node type that the SD Pass Thru driver supports,\r
345 EFI_UNSUPPORTED is returned.\r
346\r
347 @param[in] This A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.\r
348 @param[in] DevicePath A pointer to the device path node that describes a SD\r
349 card on the SD controller.\r
350 @param[out] Slot On return, points to the slot number of an SD card on\r
351 the SD controller.\r
352\r
353 @retval EFI_SUCCESS SD card slot number is returned in Slot.\r
354 @retval EFI_INVALID_PARAMETER Slot or DevicePath is NULL.\r
355 @retval EFI_UNSUPPORTED DevicePath is not a device path node type that the SD\r
356 Pass Thru driver supports.\r
357\r
358**/\r
359EFI_STATUS\r
360EFIAPI\r
361SdMmcPassThruGetSlotNumber (\r
362 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *This,\r
363 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
364 OUT UINT8 *Slot\r
365 );\r
366\r
367/**\r
368 Resets an SD card that is connected to the SD controller.\r
369\r
370 The ResetDevice() function resets the SD card specified by Slot.\r
371\r
372 If this SD controller does not support a device reset operation, EFI_UNSUPPORTED is\r
373 returned.\r
374\r
375 If Slot is not in a valid slot number for this SD controller, EFI_INVALID_PARAMETER\r
376 is returned.\r
377\r
378 If the device reset operation is completed, EFI_SUCCESS is returned.\r
379\r
380 @param[in] This A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.\r
381 @param[in] Slot Specifies the slot number of the SD card to be reset.\r
382\r
383 @retval EFI_SUCCESS The SD card specified by Slot was reset.\r
384 @retval EFI_UNSUPPORTED The SD controller does not support a device reset operation.\r
385 @retval EFI_INVALID_PARAMETER Slot number is invalid.\r
386 @retval EFI_NO_MEDIA SD Device not present in the Slot.\r
387 @retval EFI_DEVICE_ERROR The reset command failed due to a device error\r
388\r
389**/\r
390EFI_STATUS\r
391EFIAPI\r
392SdMmcPassThruResetDevice (\r
393 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *This,\r
394 IN UINT8 Slot\r
395 );\r
396\r
397//\r
398// Driver model protocol interfaces\r
399//\r
400/**\r
401 Tests to see if this driver supports a given controller. If a child device is provided,\r
402 it further tests to see if this driver supports creating a handle for the specified child device.\r
403\r
404 This function checks to see if the driver specified by This supports the device specified by\r
405 ControllerHandle. Drivers will typically use the device path attached to\r
406 ControllerHandle and/or the services from the bus I/O abstraction attached to\r
407 ControllerHandle to determine if the driver supports ControllerHandle. This function\r
408 may be called many times during platform initialization. In order to reduce boot times, the tests\r
409 performed by this function must be very small, and take as little time as possible to execute. This\r
410 function must not change the state of any hardware devices, and this function must be aware that the\r
411 device specified by ControllerHandle may already be managed by the same driver or a\r
412 different driver. This function must match its calls to AllocatePages() with FreePages(),\r
413 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r
414 Since ControllerHandle may have been previously started by the same driver, if a protocol is\r
415 already in the opened state, then it must not be closed with CloseProtocol(). This is required\r
416 to guarantee the state of ControllerHandle is not modified by this function.\r
417\r
418 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
419 @param[in] ControllerHandle The handle of the controller to test. This handle\r
420 must support a protocol interface that supplies\r
421 an I/O abstraction to the driver.\r
422 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
423 parameter is ignored by device drivers, and is optional for bus\r
424 drivers. For bus drivers, if this parameter is not NULL, then\r
425 the bus driver must determine if the bus controller specified\r
426 by ControllerHandle and the child controller specified\r
427 by RemainingDevicePath are both supported by this\r
428 bus driver.\r
429\r
430 @retval EFI_SUCCESS The device specified by ControllerHandle and\r
431 RemainingDevicePath is supported by the driver specified by This.\r
432 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r
433 RemainingDevicePath is already being managed by the driver\r
434 specified by This.\r
435 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r
436 RemainingDevicePath is already being managed by a different\r
437 driver or an application that requires exclusive access.\r
438 Currently not implemented.\r
439 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r
440 RemainingDevicePath is not supported by the driver specified by This.\r
441**/\r
442EFI_STATUS\r
443EFIAPI\r
444SdMmcPciHcDriverBindingSupported (\r
445 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
446 IN EFI_HANDLE Controller,\r
447 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
448 );\r
449\r
450/**\r
451 Starts a device controller or a bus controller.\r
452\r
453 The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
454 As a result, much of the error checking on the parameters to Start() has been moved into this\r
455 common boot service. It is legal to call Start() from other locations,\r
456 but the following calling restrictions must be followed or the system behavior will not be deterministic.\r
457 1. ControllerHandle must be a valid EFI_HANDLE.\r
458 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
459 EFI_DEVICE_PATH_PROTOCOL.\r
460 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
461 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
462\r
463 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
464 @param[in] ControllerHandle The handle of the controller to start. This handle\r
465 must support a protocol interface that supplies\r
466 an I/O abstraction to the driver.\r
467 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
468 parameter is ignored by device drivers, and is optional for bus\r
469 drivers. For a bus driver, if this parameter is NULL, then handles\r
470 for all the children of Controller are created by this driver.\r
471 If this parameter is not NULL and the first Device Path Node is\r
472 not the End of Device Path Node, then only the handle for the\r
473 child device specified by the first Device Path Node of\r
474 RemainingDevicePath is created by this driver.\r
475 If the first Device Path Node of RemainingDevicePath is\r
476 the End of Device Path Node, no child handle is created by this\r
477 driver.\r
478\r
479 @retval EFI_SUCCESS The device was started.\r
480 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r
481 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
482 @retval Others The driver failded to start the device.\r
483\r
484**/\r
485EFI_STATUS\r
486EFIAPI\r
487SdMmcPciHcDriverBindingStart (\r
488 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
489 IN EFI_HANDLE Controller,\r
490 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
491 );\r
492\r
493/**\r
494 Stops a device controller or a bus controller.\r
495\r
496 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
497 As a result, much of the error checking on the parameters to Stop() has been moved\r
498 into this common boot service. It is legal to call Stop() from other locations,\r
499 but the following calling restrictions must be followed or the system behavior will not be deterministic.\r
500 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
501 same driver's Start() function.\r
502 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
503 EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
504 Start() function, and the Start() function must have called OpenProtocol() on\r
505 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
506\r
507 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
508 @param[in] ControllerHandle A handle to the device being stopped. The handle must\r
509 support a bus specific I/O protocol for the driver\r
510 to use to stop the device.\r
511 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
512 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r
513 if NumberOfChildren is 0.\r
514\r
515 @retval EFI_SUCCESS The device was stopped.\r
516 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
517\r
518**/\r
519EFI_STATUS\r
520EFIAPI\r
521SdMmcPciHcDriverBindingStop (\r
522 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
523 IN EFI_HANDLE Controller,\r
524 IN UINTN NumberOfChildren,\r
525 IN EFI_HANDLE *ChildHandleBuffer\r
526 );\r
527\r
528//\r
529// EFI Component Name Functions\r
530//\r
531/**\r
532 Retrieves a Unicode string that is the user readable name of the driver.\r
533\r
534 This function retrieves the user readable name of a driver in the form of a\r
535 Unicode string. If the driver specified by This has a user readable name in\r
536 the language specified by Language, then a pointer to the driver name is\r
537 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
538 by This does not support the language specified by Language,\r
539 then EFI_UNSUPPORTED is returned.\r
540\r
541 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
542 EFI_COMPONENT_NAME_PROTOCOL instance.\r
543\r
544 @param Language[in] A pointer to a Null-terminated ASCII string\r
545 array indicating the language. This is the\r
546 language of the driver name that the caller is\r
547 requesting, and it must match one of the\r
548 languages specified in SupportedLanguages. The\r
549 number of languages supported by a driver is up\r
550 to the driver writer. Language is specified\r
551 in RFC 4646 or ISO 639-2 language code format.\r
552\r
553 @param DriverName[out] A pointer to the Unicode string to return.\r
554 This Unicode string is the name of the\r
555 driver specified by This in the language\r
556 specified by Language.\r
557\r
558 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
559 This and the language specified by Language was\r
560 returned in DriverName.\r
561\r
562 @retval EFI_INVALID_PARAMETER Language is NULL.\r
563\r
564 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
565\r
566 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
567 the language specified by Language.\r
568\r
569**/\r
570EFI_STATUS\r
571EFIAPI\r
572SdMmcPciHcComponentNameGetDriverName (\r
573 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
574 IN CHAR8 *Language,\r
575 OUT CHAR16 **DriverName\r
576 );\r
577\r
578/**\r
579 Retrieves a Unicode string that is the user readable name of the controller\r
580 that is being managed by a driver.\r
581\r
582 This function retrieves the user readable name of the controller specified by\r
583 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
584 driver specified by This has a user readable name in the language specified by\r
585 Language, then a pointer to the controller name is returned in ControllerName,\r
586 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
587 managing the controller specified by ControllerHandle and ChildHandle,\r
588 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
589 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
590\r
591 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
592 EFI_COMPONENT_NAME_PROTOCOL instance.\r
593\r
594 @param ControllerHandle[in] The handle of a controller that the driver\r
595 specified by This is managing. This handle\r
596 specifies the controller whose name is to be\r
597 returned.\r
598\r
599 @param ChildHandle[in] The handle of the child controller to retrieve\r
600 the name of. This is an optional parameter that\r
601 may be NULL. It will be NULL for device\r
602 drivers. It will also be NULL for a bus drivers\r
603 that wish to retrieve the name of the bus\r
604 controller. It will not be NULL for a bus\r
605 driver that wishes to retrieve the name of a\r
606 child controller.\r
607\r
608 @param Language[in] A pointer to a Null-terminated ASCII string\r
609 array indicating the language. This is the\r
610 language of the driver name that the caller is\r
611 requesting, and it must match one of the\r
612 languages specified in SupportedLanguages. The\r
613 number of languages supported by a driver is up\r
614 to the driver writer. Language is specified in\r
615 RFC 4646 or ISO 639-2 language code format.\r
616\r
617 @param ControllerName[out] A pointer to the Unicode string to return.\r
618 This Unicode string is the name of the\r
619 controller specified by ControllerHandle and\r
620 ChildHandle in the language specified by\r
621 Language from the point of view of the driver\r
622 specified by This.\r
623\r
624 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
625 the language specified by Language for the\r
626 driver specified by This was returned in\r
627 DriverName.\r
628\r
629 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
630\r
631 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
632 EFI_HANDLE.\r
633\r
634 @retval EFI_INVALID_PARAMETER Language is NULL.\r
635\r
636 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
637\r
638 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
639 managing the controller specified by\r
640 ControllerHandle and ChildHandle.\r
641\r
642 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
643 the language specified by Language.\r
644\r
645**/\r
646EFI_STATUS\r
647EFIAPI\r
648SdMmcPciHcComponentNameGetControllerName (\r
649 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
650 IN EFI_HANDLE ControllerHandle,\r
651 IN EFI_HANDLE ChildHandle, OPTIONAL\r
652 IN CHAR8 *Language,\r
653 OUT CHAR16 **ControllerName\r
654 );\r
655\r
656/**\r
657 Create a new TRB for the SD/MMC cmd request.\r
658\r
659 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.\r
660 @param[in] Slot The slot number of the SD card to send the command to.\r
661 @param[in] Packet A pointer to the SD command data structure.\r
662 @param[in] Event If Event is NULL, blocking I/O is performed. If Event is\r
663 not NULL, then nonblocking I/O is performed, and Event\r
664 will be signaled when the Packet completes.\r
665\r
666 @return Created Trb or NULL.\r
667\r
668**/\r
669SD_MMC_HC_TRB *\r
670SdMmcCreateTrb (\r
671 IN SD_MMC_HC_PRIVATE_DATA *Private,\r
672 IN UINT8 Slot,\r
673 IN EFI_SD_MMC_PASS_THRU_COMMAND_PACKET *Packet,\r
674 IN EFI_EVENT Event\r
675 );\r
676\r
677/**\r
678 Free the resource used by the TRB.\r
679\r
680 @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.\r
681\r
682**/\r
683VOID\r
684SdMmcFreeTrb (\r
685 IN SD_MMC_HC_TRB *Trb\r
686 );\r
687\r
688/**\r
689 Check if the env is ready for execute specified TRB.\r
690\r
691 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.\r
692 @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.\r
693\r
694 @retval EFI_SUCCESS The env is ready for TRB execution.\r
695 @retval EFI_NOT_READY The env is not ready for TRB execution.\r
696 @retval Others Some erros happen.\r
697\r
698**/\r
699EFI_STATUS\r
700SdMmcCheckTrbEnv (\r
701 IN SD_MMC_HC_PRIVATE_DATA *Private,\r
702 IN SD_MMC_HC_TRB *Trb\r
703 );\r
704\r
705/**\r
706 Wait for the env to be ready for execute specified TRB.\r
707\r
708 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.\r
709 @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.\r
710\r
711 @retval EFI_SUCCESS The env is ready for TRB execution.\r
712 @retval EFI_TIMEOUT The env is not ready for TRB execution in time.\r
713 @retval Others Some erros happen.\r
714\r
715**/\r
716EFI_STATUS\r
717SdMmcWaitTrbEnv (\r
718 IN SD_MMC_HC_PRIVATE_DATA *Private,\r
719 IN SD_MMC_HC_TRB *Trb\r
720 );\r
721\r
722/**\r
723 Execute the specified TRB.\r
724\r
725 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.\r
726 @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.\r
727\r
728 @retval EFI_SUCCESS The TRB is sent to host controller successfully.\r
729 @retval Others Some erros happen when sending this request to the host controller.\r
730\r
731**/\r
732EFI_STATUS\r
733SdMmcExecTrb (\r
734 IN SD_MMC_HC_PRIVATE_DATA *Private,\r
735 IN SD_MMC_HC_TRB *Trb\r
736 );\r
737\r
738/**\r
739 Check the TRB execution result.\r
740\r
741 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.\r
742 @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.\r
743\r
744 @retval EFI_SUCCESS The TRB is executed successfully.\r
745 @retval EFI_NOT_READY The TRB is not completed for execution.\r
746 @retval Others Some erros happen when executing this request.\r
747\r
748**/\r
749EFI_STATUS\r
750SdMmcCheckTrbResult (\r
751 IN SD_MMC_HC_PRIVATE_DATA *Private,\r
752 IN SD_MMC_HC_TRB *Trb\r
753 );\r
754\r
755/**\r
756 Wait for the TRB execution result.\r
757\r
758 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.\r
759 @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.\r
760\r
761 @retval EFI_SUCCESS The TRB is executed successfully.\r
762 @retval Others Some erros happen when executing this request.\r
763\r
764**/\r
765EFI_STATUS\r
766SdMmcWaitTrbResult (\r
767 IN SD_MMC_HC_PRIVATE_DATA *Private,\r
768 IN SD_MMC_HC_TRB *Trb\r
769 );\r
770\r
771/**\r
772 Execute EMMC device identification procedure.\r
773\r
774 Refer to EMMC Electrical Standard Spec 5.1 Section 6.4 for details.\r
775\r
776 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.\r
777 @param[in] Slot The slot number of the SD card to send the command to.\r
778\r
779 @retval EFI_SUCCESS There is a EMMC card.\r
780 @retval Others There is not a EMMC card.\r
781\r
782**/\r
783EFI_STATUS\r
784EmmcIdentification (\r
785 IN SD_MMC_HC_PRIVATE_DATA *Private,\r
786 IN UINT8 Slot\r
787 );\r
788\r
789/**\r
790 Execute EMMC device identification procedure.\r
791\r
792 Refer to EMMC Electrical Standard Spec 5.1 Section 6.4 for details.\r
793\r
794 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.\r
795 @param[in] Slot The slot number of the SD card to send the command to.\r
796\r
797 @retval EFI_SUCCESS There is a EMMC card.\r
798 @retval Others There is not a EMMC card.\r
799\r
800**/\r
801EFI_STATUS\r
802SdCardIdentification (\r
803 IN SD_MMC_HC_PRIVATE_DATA *Private,\r
804 IN UINT8 Slot\r
805 );\r
806\r
49accded
AM
807/**\r
808 SD/MMC card clock supply.\r
809\r
810 Refer to SD Host Controller Simplified spec 3.0 Section 3.2.1 for details.\r
811\r
812 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.\r
813 @param[in] Slot The slot number of the SD card to send the command to.\r
814 @param[in] BusTiming BusTiming at which the frequency change is done.\r
815 @param[in] FirstTimeSetup Flag to indicate whether the clock is being setup for the first time.\r
816 @param[in] ClockFreq The max clock frequency to be set. The unit is KHz.\r
817\r
818 @retval EFI_SUCCESS The clock is supplied successfully.\r
819 @retval Others The clock isn't supplied successfully.\r
820\r
821**/\r
822EFI_STATUS\r
823SdMmcHcClockSupply (\r
824 IN SD_MMC_HC_PRIVATE_DATA *Private,\r
825 IN UINT8 Slot,\r
826 IN SD_MMC_BUS_MODE BusTiming,\r
827 IN BOOLEAN FirstTimeSetup,\r
828 IN UINT64 ClockFreq\r
829 );\r
830\r
b23fc39c
AB
831/**\r
832 Software reset the specified SD/MMC host controller.\r
833\r
834 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.\r
835 @param[in] Slot The slot number of the SD card to send the command to.\r
836\r
837 @retval EFI_SUCCESS The software reset executes successfully.\r
838 @retval Others The software reset fails.\r
839\r
840**/\r
841EFI_STATUS\r
842SdMmcHcReset (\r
843 IN SD_MMC_HC_PRIVATE_DATA *Private,\r
844 IN UINT8 Slot\r
845 );\r
846\r
847/**\r
848 Initial SD/MMC host controller with lowest clock frequency, max power and max timeout value\r
849 at initialization.\r
850\r
851 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.\r
852 @param[in] Slot The slot number of the SD card to send the command to.\r
853\r
854 @retval EFI_SUCCESS The host controller is initialized successfully.\r
855 @retval Others The host controller isn't initialized successfully.\r
856\r
857**/\r
858EFI_STATUS\r
859SdMmcHcInitHost (\r
860 IN SD_MMC_HC_PRIVATE_DATA *Private,\r
861 IN UINT8 Slot\r
862 );\r
863\r
48555339 864#endif\r