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