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