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