]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
MdeModulePkg/SdMmcPciHcDxe: allow HC capabilities to be overridden
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / SdMmcPciHcDxe / SdMmcPciHcDxe.c
1 /** @file
2 This driver is used to manage SD/MMC PCI host controllers which are compliance
3 with SD Host Controller Simplified Specification version 3.00.
4
5 It would expose EFI_SD_MMC_PASS_THRU_PROTOCOL for upper layer use.
6
7 Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17
18 #include "SdMmcPciHcDxe.h"
19
20 EDKII_SD_MMC_OVERRIDE *mOverride;
21
22 //
23 // Driver Global Variables
24 //
25 EFI_DRIVER_BINDING_PROTOCOL gSdMmcPciHcDriverBinding = {
26 SdMmcPciHcDriverBindingSupported,
27 SdMmcPciHcDriverBindingStart,
28 SdMmcPciHcDriverBindingStop,
29 0x10,
30 NULL,
31 NULL
32 };
33
34 //
35 // Template for SD/MMC host controller private data.
36 //
37 SD_MMC_HC_PRIVATE_DATA gSdMmcPciHcTemplate = {
38 SD_MMC_HC_PRIVATE_SIGNATURE, // Signature
39 NULL, // ControllerHandle
40 NULL, // PciIo
41 { // PassThru
42 sizeof (UINT32),
43 SdMmcPassThruPassThru,
44 SdMmcPassThruGetNextSlot,
45 SdMmcPassThruBuildDevicePath,
46 SdMmcPassThruGetSlotNumber,
47 SdMmcPassThruResetDevice
48 },
49 0, // PciAttributes
50 0, // PreviousSlot
51 NULL, // TimerEvent
52 NULL, // ConnectEvent
53 // Queue
54 INITIALIZE_LIST_HEAD_VARIABLE (gSdMmcPciHcTemplate.Queue),
55 { // Slot
56 {0, UnknownSlot, 0, 0, 0}, {0, UnknownSlot, 0, 0, 0}, {0, UnknownSlot, 0, 0, 0},
57 {0, UnknownSlot, 0, 0, 0}, {0, UnknownSlot, 0, 0, 0}, {0, UnknownSlot, 0, 0, 0}
58 },
59 { // Capability
60 {0},
61 },
62 { // MaxCurrent
63 0,
64 },
65 0 // ControllerVersion
66 };
67
68 SD_DEVICE_PATH mSdDpTemplate = {
69 {
70 MESSAGING_DEVICE_PATH,
71 MSG_SD_DP,
72 {
73 (UINT8) (sizeof (SD_DEVICE_PATH)),
74 (UINT8) ((sizeof (SD_DEVICE_PATH)) >> 8)
75 }
76 },
77 0
78 };
79
80 EMMC_DEVICE_PATH mEmmcDpTemplate = {
81 {
82 MESSAGING_DEVICE_PATH,
83 MSG_EMMC_DP,
84 {
85 (UINT8) (sizeof (EMMC_DEVICE_PATH)),
86 (UINT8) ((sizeof (EMMC_DEVICE_PATH)) >> 8)
87 }
88 },
89 0
90 };
91
92 //
93 // Prioritized function list to detect card type.
94 // User could add other card detection logic here.
95 //
96 CARD_TYPE_DETECT_ROUTINE mCardTypeDetectRoutineTable[] = {
97 EmmcIdentification,
98 SdCardIdentification,
99 NULL
100 };
101
102 /**
103 The entry point for SD host controller driver, used to install this driver on the ImageHandle.
104
105 @param[in] ImageHandle The firmware allocated handle for this driver image.
106 @param[in] SystemTable Pointer to the EFI system table.
107
108 @retval EFI_SUCCESS Driver loaded.
109 @retval other Driver not loaded.
110
111 **/
112 EFI_STATUS
113 EFIAPI
114 InitializeSdMmcPciHcDxe (
115 IN EFI_HANDLE ImageHandle,
116 IN EFI_SYSTEM_TABLE *SystemTable
117 )
118 {
119 EFI_STATUS Status;
120
121 Status = EfiLibInstallDriverBindingComponentName2 (
122 ImageHandle,
123 SystemTable,
124 &gSdMmcPciHcDriverBinding,
125 ImageHandle,
126 &gSdMmcPciHcComponentName,
127 &gSdMmcPciHcComponentName2
128 );
129 ASSERT_EFI_ERROR (Status);
130
131 return Status;
132 }
133
134 /**
135 Call back function when the timer event is signaled.
136
137 @param[in] Event The Event this notify function registered to.
138 @param[in] Context Pointer to the context data registered to the
139 Event.
140
141 **/
142 VOID
143 EFIAPI
144 ProcessAsyncTaskList (
145 IN EFI_EVENT Event,
146 IN VOID* Context
147 )
148 {
149 SD_MMC_HC_PRIVATE_DATA *Private;
150 LIST_ENTRY *Link;
151 SD_MMC_HC_TRB *Trb;
152 EFI_STATUS Status;
153 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET *Packet;
154 BOOLEAN InfiniteWait;
155 EFI_EVENT TrbEvent;
156
157 Private = (SD_MMC_HC_PRIVATE_DATA*)Context;
158
159 //
160 // Check if the first entry in the async I/O queue is done or not.
161 //
162 Status = EFI_SUCCESS;
163 Trb = NULL;
164 Link = GetFirstNode (&Private->Queue);
165 if (!IsNull (&Private->Queue, Link)) {
166 Trb = SD_MMC_HC_TRB_FROM_THIS (Link);
167 if (!Private->Slot[Trb->Slot].MediaPresent) {
168 Status = EFI_NO_MEDIA;
169 goto Done;
170 }
171 if (!Trb->Started) {
172 //
173 // Check whether the cmd/data line is ready for transfer.
174 //
175 Status = SdMmcCheckTrbEnv (Private, Trb);
176 if (!EFI_ERROR (Status)) {
177 Trb->Started = TRUE;
178 Status = SdMmcExecTrb (Private, Trb);
179 if (EFI_ERROR (Status)) {
180 goto Done;
181 }
182 } else {
183 goto Done;
184 }
185 }
186 Status = SdMmcCheckTrbResult (Private, Trb);
187 }
188
189 Done:
190 if ((Trb != NULL) && (Status == EFI_NOT_READY)) {
191 Packet = Trb->Packet;
192 if (Packet->Timeout == 0) {
193 InfiniteWait = TRUE;
194 } else {
195 InfiniteWait = FALSE;
196 }
197 if ((!InfiniteWait) && (Trb->Timeout-- == 0)) {
198 RemoveEntryList (Link);
199 Trb->Packet->TransactionStatus = EFI_TIMEOUT;
200 TrbEvent = Trb->Event;
201 SdMmcFreeTrb (Trb);
202 DEBUG ((DEBUG_VERBOSE, "ProcessAsyncTaskList(): Signal Event %p EFI_TIMEOUT\n", TrbEvent));
203 gBS->SignalEvent (TrbEvent);
204 return;
205 }
206 }
207 if ((Trb != NULL) && (Status != EFI_NOT_READY)) {
208 RemoveEntryList (Link);
209 Trb->Packet->TransactionStatus = Status;
210 TrbEvent = Trb->Event;
211 SdMmcFreeTrb (Trb);
212 DEBUG ((DEBUG_VERBOSE, "ProcessAsyncTaskList(): Signal Event %p with %r\n", TrbEvent, Status));
213 gBS->SignalEvent (TrbEvent);
214 }
215 return;
216 }
217
218 /**
219 Sd removable device enumeration callback function when the timer event is signaled.
220
221 @param[in] Event The Event this notify function registered to.
222 @param[in] Context Pointer to the context data registered to the
223 Event.
224
225 **/
226 VOID
227 EFIAPI
228 SdMmcPciHcEnumerateDevice (
229 IN EFI_EVENT Event,
230 IN VOID* Context
231 )
232 {
233 SD_MMC_HC_PRIVATE_DATA *Private;
234 EFI_STATUS Status;
235 UINT8 Slot;
236 BOOLEAN MediaPresent;
237 UINT32 RoutineNum;
238 CARD_TYPE_DETECT_ROUTINE *Routine;
239 UINTN Index;
240 LIST_ENTRY *Link;
241 LIST_ENTRY *NextLink;
242 SD_MMC_HC_TRB *Trb;
243 EFI_TPL OldTpl;
244
245 Private = (SD_MMC_HC_PRIVATE_DATA*)Context;
246
247 for (Slot = 0; Slot < SD_MMC_HC_MAX_SLOT; Slot++) {
248 if ((Private->Slot[Slot].Enable) && (Private->Slot[Slot].SlotType == RemovableSlot)) {
249 Status = SdMmcHcCardDetect (Private->PciIo, Slot, &MediaPresent);
250 if ((Status == EFI_MEDIA_CHANGED) && !MediaPresent) {
251 DEBUG ((DEBUG_INFO, "SdMmcPciHcEnumerateDevice: device disconnected at slot %d of pci %p\n", Slot, Private->PciIo));
252 Private->Slot[Slot].MediaPresent = FALSE;
253 Private->Slot[Slot].Initialized = FALSE;
254 //
255 // Signal all async task events at the slot with EFI_NO_MEDIA status.
256 //
257 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
258 for (Link = GetFirstNode (&Private->Queue);
259 !IsNull (&Private->Queue, Link);
260 Link = NextLink) {
261 NextLink = GetNextNode (&Private->Queue, Link);
262 Trb = SD_MMC_HC_TRB_FROM_THIS (Link);
263 if (Trb->Slot == Slot) {
264 RemoveEntryList (Link);
265 Trb->Packet->TransactionStatus = EFI_NO_MEDIA;
266 gBS->SignalEvent (Trb->Event);
267 SdMmcFreeTrb (Trb);
268 }
269 }
270 gBS->RestoreTPL (OldTpl);
271 //
272 // Notify the upper layer the connect state change through ReinstallProtocolInterface.
273 //
274 gBS->ReinstallProtocolInterface (
275 Private->ControllerHandle,
276 &gEfiSdMmcPassThruProtocolGuid,
277 &Private->PassThru,
278 &Private->PassThru
279 );
280 }
281 if ((Status == EFI_MEDIA_CHANGED) && MediaPresent) {
282 DEBUG ((DEBUG_INFO, "SdMmcPciHcEnumerateDevice: device connected at slot %d of pci %p\n", Slot, Private->PciIo));
283 //
284 // Reset the specified slot of the SD/MMC Pci Host Controller
285 //
286 Status = SdMmcHcReset (Private, Slot);
287 if (EFI_ERROR (Status)) {
288 continue;
289 }
290 //
291 // Reinitialize slot and restart identification process for the new attached device
292 //
293 Status = SdMmcHcInitHost (Private, Slot);
294 if (EFI_ERROR (Status)) {
295 continue;
296 }
297
298 Private->Slot[Slot].MediaPresent = TRUE;
299 Private->Slot[Slot].Initialized = TRUE;
300 RoutineNum = sizeof (mCardTypeDetectRoutineTable) / sizeof (CARD_TYPE_DETECT_ROUTINE);
301 for (Index = 0; Index < RoutineNum; Index++) {
302 Routine = &mCardTypeDetectRoutineTable[Index];
303 if (*Routine != NULL) {
304 Status = (*Routine) (Private, Slot);
305 if (!EFI_ERROR (Status)) {
306 break;
307 }
308 }
309 }
310 //
311 // This card doesn't get initialized correctly.
312 //
313 if (Index == RoutineNum) {
314 Private->Slot[Slot].Initialized = FALSE;
315 }
316
317 //
318 // Notify the upper layer the connect state change through ReinstallProtocolInterface.
319 //
320 gBS->ReinstallProtocolInterface (
321 Private->ControllerHandle,
322 &gEfiSdMmcPassThruProtocolGuid,
323 &Private->PassThru,
324 &Private->PassThru
325 );
326 }
327 }
328 }
329
330 return;
331 }
332 /**
333 Tests to see if this driver supports a given controller. If a child device is provided,
334 it further tests to see if this driver supports creating a handle for the specified child device.
335
336 This function checks to see if the driver specified by This supports the device specified by
337 ControllerHandle. Drivers will typically use the device path attached to
338 ControllerHandle and/or the services from the bus I/O abstraction attached to
339 ControllerHandle to determine if the driver supports ControllerHandle. This function
340 may be called many times during platform initialization. In order to reduce boot times, the tests
341 performed by this function must be very small, and take as little time as possible to execute. This
342 function must not change the state of any hardware devices, and this function must be aware that the
343 device specified by ControllerHandle may already be managed by the same driver or a
344 different driver. This function must match its calls to AllocatePages() with FreePages(),
345 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
346 Since ControllerHandle may have been previously started by the same driver, if a protocol is
347 already in the opened state, then it must not be closed with CloseProtocol(). This is required
348 to guarantee the state of ControllerHandle is not modified by this function.
349
350 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
351 @param[in] ControllerHandle The handle of the controller to test. This handle
352 must support a protocol interface that supplies
353 an I/O abstraction to the driver.
354 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
355 parameter is ignored by device drivers, and is optional for bus
356 drivers. For bus drivers, if this parameter is not NULL, then
357 the bus driver must determine if the bus controller specified
358 by ControllerHandle and the child controller specified
359 by RemainingDevicePath are both supported by this
360 bus driver.
361
362 @retval EFI_SUCCESS The device specified by ControllerHandle and
363 RemainingDevicePath is supported by the driver specified by This.
364 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
365 RemainingDevicePath is already being managed by the driver
366 specified by This.
367 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
368 RemainingDevicePath is already being managed by a different
369 driver or an application that requires exclusive access.
370 Currently not implemented.
371 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
372 RemainingDevicePath is not supported by the driver specified by This.
373 **/
374 EFI_STATUS
375 EFIAPI
376 SdMmcPciHcDriverBindingSupported (
377 IN EFI_DRIVER_BINDING_PROTOCOL *This,
378 IN EFI_HANDLE Controller,
379 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
380 )
381 {
382 EFI_STATUS Status;
383 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
384 EFI_PCI_IO_PROTOCOL *PciIo;
385 PCI_TYPE00 PciData;
386
387 PciIo = NULL;
388 ParentDevicePath = NULL;
389
390 //
391 // SdPciHcDxe is a device driver, and should ingore the
392 // "RemainingDevicePath" according to EFI spec.
393 //
394 Status = gBS->OpenProtocol (
395 Controller,
396 &gEfiDevicePathProtocolGuid,
397 (VOID *) &ParentDevicePath,
398 This->DriverBindingHandle,
399 Controller,
400 EFI_OPEN_PROTOCOL_BY_DRIVER
401 );
402 if (EFI_ERROR (Status)) {
403 //
404 // EFI_ALREADY_STARTED is also an error.
405 //
406 return Status;
407 }
408 //
409 // Close the protocol because we don't use it here.
410 //
411 gBS->CloseProtocol (
412 Controller,
413 &gEfiDevicePathProtocolGuid,
414 This->DriverBindingHandle,
415 Controller
416 );
417
418 //
419 // Now test the EfiPciIoProtocol.
420 //
421 Status = gBS->OpenProtocol (
422 Controller,
423 &gEfiPciIoProtocolGuid,
424 (VOID **) &PciIo,
425 This->DriverBindingHandle,
426 Controller,
427 EFI_OPEN_PROTOCOL_BY_DRIVER
428 );
429 if (EFI_ERROR (Status)) {
430 return Status;
431 }
432
433 //
434 // Now further check the PCI header: Base class (offset 0x08) and
435 // Sub Class (offset 0x05). This controller should be an SD/MMC PCI
436 // Host Controller.
437 //
438 Status = PciIo->Pci.Read (
439 PciIo,
440 EfiPciIoWidthUint8,
441 0,
442 sizeof (PciData),
443 &PciData
444 );
445 if (EFI_ERROR (Status)) {
446 gBS->CloseProtocol (
447 Controller,
448 &gEfiPciIoProtocolGuid,
449 This->DriverBindingHandle,
450 Controller
451 );
452 return EFI_UNSUPPORTED;
453 }
454 //
455 // Since we already got the PciData, we can close protocol to avoid to carry it
456 // on for multiple exit points.
457 //
458 gBS->CloseProtocol (
459 Controller,
460 &gEfiPciIoProtocolGuid,
461 This->DriverBindingHandle,
462 Controller
463 );
464
465 //
466 // Examine SD PCI Host Controller PCI Configuration table fields.
467 //
468 if ((PciData.Hdr.ClassCode[2] == PCI_CLASS_SYSTEM_PERIPHERAL) &&
469 (PciData.Hdr.ClassCode[1] == PCI_SUBCLASS_SD_HOST_CONTROLLER) &&
470 ((PciData.Hdr.ClassCode[0] == 0x00) || (PciData.Hdr.ClassCode[0] == 0x01))) {
471 return EFI_SUCCESS;
472 }
473
474 return EFI_UNSUPPORTED;
475 }
476
477 /**
478 Starts a device controller or a bus controller.
479
480 The Start() function is designed to be invoked from the EFI boot service ConnectController().
481 As a result, much of the error checking on the parameters to Start() has been moved into this
482 common boot service. It is legal to call Start() from other locations,
483 but the following calling restrictions must be followed or the system behavior will not be deterministic.
484 1. ControllerHandle must be a valid EFI_HANDLE.
485 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
486 EFI_DEVICE_PATH_PROTOCOL.
487 3. Prior to calling Start(), the Supported() function for the driver specified by This must
488 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
489
490 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
491 @param[in] ControllerHandle The handle of the controller to start. This handle
492 must support a protocol interface that supplies
493 an I/O abstraction to the driver.
494 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
495 parameter is ignored by device drivers, and is optional for bus
496 drivers. For a bus driver, if this parameter is NULL, then handles
497 for all the children of Controller are created by this driver.
498 If this parameter is not NULL and the first Device Path Node is
499 not the End of Device Path Node, then only the handle for the
500 child device specified by the first Device Path Node of
501 RemainingDevicePath is created by this driver.
502 If the first Device Path Node of RemainingDevicePath is
503 the End of Device Path Node, no child handle is created by this
504 driver.
505
506 @retval EFI_SUCCESS The device was started.
507 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
508 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
509 @retval Others The driver failded to start the device.
510
511 **/
512 EFI_STATUS
513 EFIAPI
514 SdMmcPciHcDriverBindingStart (
515 IN EFI_DRIVER_BINDING_PROTOCOL *This,
516 IN EFI_HANDLE Controller,
517 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
518 )
519 {
520 EFI_STATUS Status;
521 SD_MMC_HC_PRIVATE_DATA *Private;
522 EFI_PCI_IO_PROTOCOL *PciIo;
523 UINT64 Supports;
524 UINT64 PciAttributes;
525 UINT8 SlotNum;
526 UINT8 FirstBar;
527 UINT8 Slot;
528 UINT8 Index;
529 CARD_TYPE_DETECT_ROUTINE *Routine;
530 UINT32 RoutineNum;
531 BOOLEAN MediaPresent;
532 BOOLEAN Support64BitDma;
533
534 DEBUG ((DEBUG_INFO, "SdMmcPciHcDriverBindingStart: Start\n"));
535
536 //
537 // Open PCI I/O Protocol and save pointer to open protocol
538 // in private data area.
539 //
540 PciIo = NULL;
541 Status = gBS->OpenProtocol (
542 Controller,
543 &gEfiPciIoProtocolGuid,
544 (VOID **) &PciIo,
545 This->DriverBindingHandle,
546 Controller,
547 EFI_OPEN_PROTOCOL_BY_DRIVER
548 );
549 if (EFI_ERROR (Status)) {
550 return Status;
551 }
552
553 //
554 // Enable the SD Host Controller MMIO space
555 //
556 Private = NULL;
557 Status = PciIo->Attributes (
558 PciIo,
559 EfiPciIoAttributeOperationGet,
560 0,
561 &PciAttributes
562 );
563
564 if (EFI_ERROR (Status)) {
565 goto Done;
566 }
567
568 Status = PciIo->Attributes (
569 PciIo,
570 EfiPciIoAttributeOperationSupported,
571 0,
572 &Supports
573 );
574
575 if (!EFI_ERROR (Status)) {
576 Supports &= (UINT64)EFI_PCI_DEVICE_ENABLE;
577 Status = PciIo->Attributes (
578 PciIo,
579 EfiPciIoAttributeOperationEnable,
580 Supports,
581 NULL
582 );
583 } else {
584 goto Done;
585 }
586
587 Private = AllocateCopyPool (sizeof (SD_MMC_HC_PRIVATE_DATA), &gSdMmcPciHcTemplate);
588 if (Private == NULL) {
589 Status = EFI_OUT_OF_RESOURCES;
590 goto Done;
591 }
592
593 Private->ControllerHandle = Controller;
594 Private->PciIo = PciIo;
595 Private->PciAttributes = PciAttributes;
596 InitializeListHead (&Private->Queue);
597
598 //
599 // Get SD/MMC Pci Host Controller Slot info
600 //
601 Status = SdMmcHcGetSlotInfo (PciIo, &FirstBar, &SlotNum);
602 if (EFI_ERROR (Status)) {
603 goto Done;
604 }
605
606 //
607 // Attempt to locate the singleton instance of the SD/MMC override protocol,
608 // which implements platform specific workarounds for non-standard SDHCI
609 // implementations.
610 //
611 if (mOverride == NULL) {
612 Status = gBS->LocateProtocol (&gEdkiiSdMmcOverrideProtocolGuid, NULL,
613 (VOID **)&mOverride);
614 if (!EFI_ERROR (Status)) {
615 DEBUG ((DEBUG_INFO, "%a: found SD/MMC override protocol\n",
616 __FUNCTION__));
617 }
618 }
619
620 Support64BitDma = TRUE;
621 for (Slot = FirstBar; Slot < (FirstBar + SlotNum); Slot++) {
622 Private->Slot[Slot].Enable = TRUE;
623
624 Status = SdMmcHcGetCapability (PciIo, Slot, &Private->Capability[Slot]);
625 if (EFI_ERROR (Status)) {
626 continue;
627 }
628 if (mOverride != NULL && mOverride->Capability != NULL) {
629 Status = mOverride->Capability (
630 Controller,
631 Slot,
632 &Private->Capability[Slot]);
633 if (EFI_ERROR (Status)) {
634 DEBUG ((DEBUG_WARN, "%a: Failed to override capability - %r\n",
635 __FUNCTION__, Status));
636 continue;
637 }
638 }
639 DumpCapabilityReg (Slot, &Private->Capability[Slot]);
640
641 Support64BitDma &= Private->Capability[Slot].SysBus64;
642
643 Status = SdMmcHcGetMaxCurrent (PciIo, Slot, &Private->MaxCurrent[Slot]);
644 if (EFI_ERROR (Status)) {
645 continue;
646 }
647
648 Private->Slot[Slot].SlotType = Private->Capability[Slot].SlotType;
649 if ((Private->Slot[Slot].SlotType != RemovableSlot) && (Private->Slot[Slot].SlotType != EmbeddedSlot)) {
650 DEBUG ((DEBUG_INFO, "SdMmcPciHcDxe doesn't support the slot type [%d]!!!\n", Private->Slot[Slot].SlotType));
651 continue;
652 }
653
654 //
655 // Reset the specified slot of the SD/MMC Pci Host Controller
656 //
657 Status = SdMmcHcReset (Private, Slot);
658 if (EFI_ERROR (Status)) {
659 continue;
660 }
661 //
662 // Check whether there is a SD/MMC card attached
663 //
664 Status = SdMmcHcCardDetect (PciIo, Slot, &MediaPresent);
665 if (EFI_ERROR (Status) && (Status != EFI_MEDIA_CHANGED)) {
666 continue;
667 } else if (!MediaPresent) {
668 DEBUG ((DEBUG_INFO, "SdMmcHcCardDetect: No device attached in Slot[%d]!!!\n", Slot));
669 continue;
670 }
671
672 Status = SdMmcHcInitHost (Private, Slot);
673 if (EFI_ERROR (Status)) {
674 continue;
675 }
676
677 Private->Slot[Slot].MediaPresent = TRUE;
678 Private->Slot[Slot].Initialized = TRUE;
679 RoutineNum = sizeof (mCardTypeDetectRoutineTable) / sizeof (CARD_TYPE_DETECT_ROUTINE);
680 for (Index = 0; Index < RoutineNum; Index++) {
681 Routine = &mCardTypeDetectRoutineTable[Index];
682 if (*Routine != NULL) {
683 Status = (*Routine) (Private, Slot);
684 if (!EFI_ERROR (Status)) {
685 break;
686 }
687 }
688 }
689 //
690 // This card doesn't get initialized correctly.
691 //
692 if (Index == RoutineNum) {
693 Private->Slot[Slot].Initialized = FALSE;
694 }
695 }
696
697 //
698 // Enable 64-bit DMA support in the PCI layer if this controller
699 // supports it.
700 //
701 if (Support64BitDma) {
702 Status = PciIo->Attributes (
703 PciIo,
704 EfiPciIoAttributeOperationEnable,
705 EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE,
706 NULL
707 );
708 if (EFI_ERROR (Status)) {
709 DEBUG ((DEBUG_WARN, "SdMmcPciHcDriverBindingStart: failed to enable 64-bit DMA (%r)\n", Status));
710 }
711 }
712
713 //
714 // Start the asynchronous I/O monitor
715 //
716 Status = gBS->CreateEvent (
717 EVT_TIMER | EVT_NOTIFY_SIGNAL,
718 TPL_NOTIFY,
719 ProcessAsyncTaskList,
720 Private,
721 &Private->TimerEvent
722 );
723 if (EFI_ERROR (Status)) {
724 goto Done;
725 }
726
727 Status = gBS->SetTimer (Private->TimerEvent, TimerPeriodic, SD_MMC_HC_ASYNC_TIMER);
728 if (EFI_ERROR (Status)) {
729 goto Done;
730 }
731
732 //
733 // Start the Sd removable device connection enumeration
734 //
735 Status = gBS->CreateEvent (
736 EVT_TIMER | EVT_NOTIFY_SIGNAL,
737 TPL_CALLBACK,
738 SdMmcPciHcEnumerateDevice,
739 Private,
740 &Private->ConnectEvent
741 );
742 if (EFI_ERROR (Status)) {
743 goto Done;
744 }
745
746 Status = gBS->SetTimer (Private->ConnectEvent, TimerPeriodic, SD_MMC_HC_ENUM_TIMER);
747 if (EFI_ERROR (Status)) {
748 goto Done;
749 }
750
751 Status = gBS->InstallMultipleProtocolInterfaces (
752 &Controller,
753 &gEfiSdMmcPassThruProtocolGuid,
754 &(Private->PassThru),
755 NULL
756 );
757
758 DEBUG ((DEBUG_INFO, "SdMmcPciHcDriverBindingStart: %r End on %x\n", Status, Controller));
759
760 Done:
761 if (EFI_ERROR (Status)) {
762 if ((Private != NULL) && (Private->PciAttributes != 0)) {
763 //
764 // Restore original PCI attributes
765 //
766 PciIo->Attributes (
767 PciIo,
768 EfiPciIoAttributeOperationSet,
769 Private->PciAttributes,
770 NULL
771 );
772 }
773 gBS->CloseProtocol (
774 Controller,
775 &gEfiPciIoProtocolGuid,
776 This->DriverBindingHandle,
777 Controller
778 );
779
780 if ((Private != NULL) && (Private->TimerEvent != NULL)) {
781 gBS->CloseEvent (Private->TimerEvent);
782 }
783
784 if ((Private != NULL) && (Private->ConnectEvent != NULL)) {
785 gBS->CloseEvent (Private->ConnectEvent);
786 }
787
788 if (Private != NULL) {
789 FreePool (Private);
790 }
791 }
792
793 return Status;
794 }
795
796 /**
797 Stops a device controller or a bus controller.
798
799 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
800 As a result, much of the error checking on the parameters to Stop() has been moved
801 into this common boot service. It is legal to call Stop() from other locations,
802 but the following calling restrictions must be followed or the system behavior will not be deterministic.
803 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
804 same driver's Start() function.
805 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
806 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
807 Start() function, and the Start() function must have called OpenProtocol() on
808 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
809
810 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
811 @param[in] ControllerHandle A handle to the device being stopped. The handle must
812 support a bus specific I/O protocol for the driver
813 to use to stop the device.
814 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
815 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
816 if NumberOfChildren is 0.
817
818 @retval EFI_SUCCESS The device was stopped.
819 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
820
821 **/
822 EFI_STATUS
823 EFIAPI
824 SdMmcPciHcDriverBindingStop (
825 IN EFI_DRIVER_BINDING_PROTOCOL *This,
826 IN EFI_HANDLE Controller,
827 IN UINTN NumberOfChildren,
828 IN EFI_HANDLE *ChildHandleBuffer
829 )
830 {
831 EFI_STATUS Status;
832 EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru;
833 SD_MMC_HC_PRIVATE_DATA *Private;
834 EFI_PCI_IO_PROTOCOL *PciIo;
835 LIST_ENTRY *Link;
836 LIST_ENTRY *NextLink;
837 SD_MMC_HC_TRB *Trb;
838
839 DEBUG ((DEBUG_INFO, "SdMmcPciHcDriverBindingStop: Start\n"));
840
841 Status = gBS->OpenProtocol (
842 Controller,
843 &gEfiSdMmcPassThruProtocolGuid,
844 (VOID**) &PassThru,
845 This->DriverBindingHandle,
846 Controller,
847 EFI_OPEN_PROTOCOL_GET_PROTOCOL
848 );
849 if (EFI_ERROR (Status)) {
850 return Status;
851 }
852
853 Private = SD_MMC_HC_PRIVATE_FROM_THIS (PassThru);
854 //
855 // Close Non-Blocking timer and free Task list.
856 //
857 if (Private->TimerEvent != NULL) {
858 gBS->CloseEvent (Private->TimerEvent);
859 Private->TimerEvent = NULL;
860 }
861 if (Private->ConnectEvent != NULL) {
862 gBS->CloseEvent (Private->ConnectEvent);
863 Private->ConnectEvent = NULL;
864 }
865 //
866 // As the timer is closed, there is no needs to use TPL lock to
867 // protect the critical region "queue".
868 //
869 for (Link = GetFirstNode (&Private->Queue);
870 !IsNull (&Private->Queue, Link);
871 Link = NextLink) {
872 NextLink = GetNextNode (&Private->Queue, Link);
873 RemoveEntryList (Link);
874 Trb = SD_MMC_HC_TRB_FROM_THIS (Link);
875 Trb->Packet->TransactionStatus = EFI_ABORTED;
876 gBS->SignalEvent (Trb->Event);
877 SdMmcFreeTrb (Trb);
878 }
879
880 //
881 // Uninstall Block I/O protocol from the device handle
882 //
883 Status = gBS->UninstallProtocolInterface (
884 Controller,
885 &gEfiSdMmcPassThruProtocolGuid,
886 &(Private->PassThru)
887 );
888
889 if (EFI_ERROR (Status)) {
890 return Status;
891 }
892
893 gBS->CloseProtocol (
894 Controller,
895 &gEfiPciIoProtocolGuid,
896 This->DriverBindingHandle,
897 Controller
898 );
899 //
900 // Restore original PCI attributes
901 //
902 PciIo = Private->PciIo;
903 Status = PciIo->Attributes (
904 PciIo,
905 EfiPciIoAttributeOperationSet,
906 Private->PciAttributes,
907 NULL
908 );
909 ASSERT_EFI_ERROR (Status);
910
911 FreePool (Private);
912
913 DEBUG ((DEBUG_INFO, "SdMmcPciHcDriverBindingStop: End with %r\n", Status));
914
915 return Status;
916 }
917
918 /**
919 Sends SD command to an SD card that is attached to the SD controller.
920
921 The PassThru() function sends the SD command specified by Packet to the SD card
922 specified by Slot.
923
924 If Packet is successfully sent to the SD card, then EFI_SUCCESS is returned.
925
926 If a device error occurs while sending the Packet, then EFI_DEVICE_ERROR is returned.
927
928 If Slot is not in a valid range for the SD controller, then EFI_INVALID_PARAMETER
929 is returned.
930
931 If Packet defines a data command but both InDataBuffer and OutDataBuffer are NULL,
932 EFI_INVALID_PARAMETER is returned.
933
934 @param[in] This A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
935 @param[in] Slot The slot number of the SD card to send the command to.
936 @param[in,out] Packet A pointer to the SD command data structure.
937 @param[in] Event If Event is NULL, blocking I/O is performed. If Event is
938 not NULL, then nonblocking I/O is performed, and Event
939 will be signaled when the Packet completes.
940
941 @retval EFI_SUCCESS The SD Command Packet was sent by the host.
942 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SD
943 command Packet.
944 @retval EFI_INVALID_PARAMETER Packet, Slot, or the contents of the Packet is invalid.
945 @retval EFI_INVALID_PARAMETER Packet defines a data command but both InDataBuffer and
946 OutDataBuffer are NULL.
947 @retval EFI_NO_MEDIA SD Device not present in the Slot.
948 @retval EFI_UNSUPPORTED The command described by the SD Command Packet is not
949 supported by the host controller.
950 @retval EFI_BAD_BUFFER_SIZE The InTransferLength or OutTransferLength exceeds the
951 limit supported by SD card ( i.e. if the number of bytes
952 exceed the Last LBA).
953
954 **/
955 EFI_STATUS
956 EFIAPI
957 SdMmcPassThruPassThru (
958 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *This,
959 IN UINT8 Slot,
960 IN OUT EFI_SD_MMC_PASS_THRU_COMMAND_PACKET *Packet,
961 IN EFI_EVENT Event OPTIONAL
962 )
963 {
964 EFI_STATUS Status;
965 SD_MMC_HC_PRIVATE_DATA *Private;
966 SD_MMC_HC_TRB *Trb;
967 EFI_TPL OldTpl;
968
969 if ((This == NULL) || (Packet == NULL)) {
970 return EFI_INVALID_PARAMETER;
971 }
972
973 if ((Packet->SdMmcCmdBlk == NULL) || (Packet->SdMmcStatusBlk == NULL)) {
974 return EFI_INVALID_PARAMETER;
975 }
976
977 if ((Packet->OutDataBuffer == NULL) && (Packet->OutTransferLength != 0)) {
978 return EFI_INVALID_PARAMETER;
979 }
980
981 if ((Packet->InDataBuffer == NULL) && (Packet->InTransferLength != 0)) {
982 return EFI_INVALID_PARAMETER;
983 }
984
985 Private = SD_MMC_HC_PRIVATE_FROM_THIS (This);
986
987 if (!Private->Slot[Slot].Enable) {
988 return EFI_INVALID_PARAMETER;
989 }
990
991 if (!Private->Slot[Slot].MediaPresent) {
992 return EFI_NO_MEDIA;
993 }
994
995 if (!Private->Slot[Slot].Initialized) {
996 return EFI_DEVICE_ERROR;
997 }
998
999 Trb = SdMmcCreateTrb (Private, Slot, Packet, Event);
1000 if (Trb == NULL) {
1001 return EFI_OUT_OF_RESOURCES;
1002 }
1003 //
1004 // Immediately return for async I/O.
1005 //
1006 if (Event != NULL) {
1007 return EFI_SUCCESS;
1008 }
1009
1010 //
1011 // Wait async I/O list is empty before execute sync I/O operation.
1012 //
1013 while (TRUE) {
1014 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
1015 if (IsListEmpty (&Private->Queue)) {
1016 gBS->RestoreTPL (OldTpl);
1017 break;
1018 }
1019 gBS->RestoreTPL (OldTpl);
1020 }
1021
1022 Status = SdMmcWaitTrbEnv (Private, Trb);
1023 if (EFI_ERROR (Status)) {
1024 goto Done;
1025 }
1026
1027 Status = SdMmcExecTrb (Private, Trb);
1028 if (EFI_ERROR (Status)) {
1029 goto Done;
1030 }
1031
1032 Status = SdMmcWaitTrbResult (Private, Trb);
1033 if (EFI_ERROR (Status)) {
1034 goto Done;
1035 }
1036
1037 Done:
1038 SdMmcFreeTrb (Trb);
1039
1040 return Status;
1041 }
1042
1043 /**
1044 Used to retrieve next slot numbers supported by the SD controller. The function
1045 returns information about all available slots (populated or not-populated).
1046
1047 The GetNextSlot() function retrieves the next slot number on an SD controller.
1048 If on input Slot is 0xFF, then the slot number of the first slot on the SD controller
1049 is returned.
1050
1051 If Slot is a slot number that was returned on a previous call to GetNextSlot(), then
1052 the slot number of the next slot on the SD controller is returned.
1053
1054 If Slot is not 0xFF and Slot was not returned on a previous call to GetNextSlot(),
1055 EFI_INVALID_PARAMETER is returned.
1056
1057 If Slot is the slot number of the last slot on the SD controller, then EFI_NOT_FOUND
1058 is returned.
1059
1060 @param[in] This A pointer to the EFI_SD_MMMC_PASS_THRU_PROTOCOL instance.
1061 @param[in,out] Slot On input, a pointer to a slot number on the SD controller.
1062 On output, a pointer to the next slot number on the SD controller.
1063 An input value of 0xFF retrieves the first slot number on the SD
1064 controller.
1065
1066 @retval EFI_SUCCESS The next slot number on the SD controller was returned in Slot.
1067 @retval EFI_NOT_FOUND There are no more slots on this SD controller.
1068 @retval EFI_INVALID_PARAMETER Slot is not 0xFF and Slot was not returned on a previous call
1069 to GetNextSlot().
1070
1071 **/
1072 EFI_STATUS
1073 EFIAPI
1074 SdMmcPassThruGetNextSlot (
1075 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *This,
1076 IN OUT UINT8 *Slot
1077 )
1078 {
1079 SD_MMC_HC_PRIVATE_DATA *Private;
1080 UINT8 Index;
1081
1082 if ((This == NULL) || (Slot == NULL)) {
1083 return EFI_INVALID_PARAMETER;
1084 }
1085
1086 Private = SD_MMC_HC_PRIVATE_FROM_THIS (This);
1087
1088 if (*Slot == 0xFF) {
1089 for (Index = 0; Index < SD_MMC_HC_MAX_SLOT; Index++) {
1090 if (Private->Slot[Index].Enable) {
1091 *Slot = Index;
1092 Private->PreviousSlot = Index;
1093 return EFI_SUCCESS;
1094 }
1095 }
1096 return EFI_NOT_FOUND;
1097 } else if (*Slot == Private->PreviousSlot) {
1098 for (Index = *Slot + 1; Index < SD_MMC_HC_MAX_SLOT; Index++) {
1099 if (Private->Slot[Index].Enable) {
1100 *Slot = Index;
1101 Private->PreviousSlot = Index;
1102 return EFI_SUCCESS;
1103 }
1104 }
1105 return EFI_NOT_FOUND;
1106 } else {
1107 return EFI_INVALID_PARAMETER;
1108 }
1109 }
1110
1111 /**
1112 Used to allocate and build a device path node for an SD card on the SD controller.
1113
1114 The BuildDevicePath() function allocates and builds a single device node for the SD
1115 card specified by Slot.
1116
1117 If the SD card specified by Slot is not present on the SD controller, then EFI_NOT_FOUND
1118 is returned.
1119
1120 If DevicePath is NULL, then EFI_INVALID_PARAMETER is returned.
1121
1122 If there are not enough resources to allocate the device path node, then EFI_OUT_OF_RESOURCES
1123 is returned.
1124
1125 Otherwise, DevicePath is allocated with the boot service AllocatePool(), the contents of
1126 DevicePath are initialized to describe the SD card specified by Slot, and EFI_SUCCESS is
1127 returned.
1128
1129 @param[in] This A pointer to the EFI_SD_MMMC_PASS_THRU_PROTOCOL instance.
1130 @param[in] Slot Specifies the slot number of the SD card for which a device
1131 path node is to be allocated and built.
1132 @param[in,out] DevicePath A pointer to a single device path node that describes the SD
1133 card specified by Slot. This function is responsible for
1134 allocating the buffer DevicePath with the boot service
1135 AllocatePool(). It is the caller's responsibility to free
1136 DevicePath when the caller is finished with DevicePath.
1137
1138 @retval EFI_SUCCESS The device path node that describes the SD card specified by
1139 Slot was allocated and returned in DevicePath.
1140 @retval EFI_NOT_FOUND The SD card specified by Slot does not exist on the SD controller.
1141 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
1142 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate DevicePath.
1143
1144 **/
1145 EFI_STATUS
1146 EFIAPI
1147 SdMmcPassThruBuildDevicePath (
1148 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *This,
1149 IN UINT8 Slot,
1150 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
1151 )
1152 {
1153 SD_MMC_HC_PRIVATE_DATA *Private;
1154 SD_DEVICE_PATH *SdNode;
1155 EMMC_DEVICE_PATH *EmmcNode;
1156
1157 if ((This == NULL) || (DevicePath == NULL) || (Slot >= SD_MMC_HC_MAX_SLOT)) {
1158 return EFI_INVALID_PARAMETER;
1159 }
1160
1161 Private = SD_MMC_HC_PRIVATE_FROM_THIS (This);
1162
1163 if ((!Private->Slot[Slot].Enable) || (!Private->Slot[Slot].MediaPresent)) {
1164 return EFI_NOT_FOUND;
1165 }
1166
1167 if (Private->Slot[Slot].CardType == SdCardType) {
1168 SdNode = AllocateCopyPool (sizeof (SD_DEVICE_PATH), &mSdDpTemplate);
1169 if (SdNode == NULL) {
1170 return EFI_OUT_OF_RESOURCES;
1171 }
1172 SdNode->SlotNumber = Slot;
1173
1174 *DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) SdNode;
1175 } else if (Private->Slot[Slot].CardType == EmmcCardType) {
1176 EmmcNode = AllocateCopyPool (sizeof (EMMC_DEVICE_PATH), &mEmmcDpTemplate);
1177 if (EmmcNode == NULL) {
1178 return EFI_OUT_OF_RESOURCES;
1179 }
1180 EmmcNode->SlotNumber = Slot;
1181
1182 *DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) EmmcNode;
1183 } else {
1184 //
1185 // Currently we only support SD and EMMC two device nodes.
1186 //
1187 return EFI_NOT_FOUND;
1188 }
1189
1190 return EFI_SUCCESS;
1191 }
1192
1193 /**
1194 This function retrieves an SD card slot number based on the input device path.
1195
1196 The GetSlotNumber() function retrieves slot number for the SD card specified by
1197 the DevicePath node. If DevicePath is NULL, EFI_INVALID_PARAMETER is returned.
1198
1199 If DevicePath is not a device path node type that the SD Pass Thru driver supports,
1200 EFI_UNSUPPORTED is returned.
1201
1202 @param[in] This A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
1203 @param[in] DevicePath A pointer to the device path node that describes a SD
1204 card on the SD controller.
1205 @param[out] Slot On return, points to the slot number of an SD card on
1206 the SD controller.
1207
1208 @retval EFI_SUCCESS SD card slot number is returned in Slot.
1209 @retval EFI_INVALID_PARAMETER Slot or DevicePath is NULL.
1210 @retval EFI_UNSUPPORTED DevicePath is not a device path node type that the SD
1211 Pass Thru driver supports.
1212
1213 **/
1214 EFI_STATUS
1215 EFIAPI
1216 SdMmcPassThruGetSlotNumber (
1217 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *This,
1218 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
1219 OUT UINT8 *Slot
1220 )
1221 {
1222 SD_MMC_HC_PRIVATE_DATA *Private;
1223 SD_DEVICE_PATH *SdNode;
1224 EMMC_DEVICE_PATH *EmmcNode;
1225 UINT8 SlotNumber;
1226
1227 if ((This == NULL) || (DevicePath == NULL) || (Slot == NULL)) {
1228 return EFI_INVALID_PARAMETER;
1229 }
1230
1231 Private = SD_MMC_HC_PRIVATE_FROM_THIS (This);
1232
1233 //
1234 // Check whether the DevicePath belongs to SD_DEVICE_PATH or EMMC_DEVICE_PATH
1235 //
1236 if ((DevicePath->Type != MESSAGING_DEVICE_PATH) ||
1237 ((DevicePath->SubType != MSG_SD_DP) &&
1238 (DevicePath->SubType != MSG_EMMC_DP)) ||
1239 (DevicePathNodeLength(DevicePath) != sizeof(SD_DEVICE_PATH)) ||
1240 (DevicePathNodeLength(DevicePath) != sizeof(EMMC_DEVICE_PATH))) {
1241 return EFI_UNSUPPORTED;
1242 }
1243
1244 if (DevicePath->SubType == MSG_SD_DP) {
1245 SdNode = (SD_DEVICE_PATH *) DevicePath;
1246 SlotNumber = SdNode->SlotNumber;
1247 } else {
1248 EmmcNode = (EMMC_DEVICE_PATH *) DevicePath;
1249 SlotNumber = EmmcNode->SlotNumber;
1250 }
1251
1252 if (SlotNumber >= SD_MMC_HC_MAX_SLOT) {
1253 return EFI_NOT_FOUND;
1254 }
1255
1256 if (Private->Slot[SlotNumber].Enable) {
1257 *Slot = SlotNumber;
1258 return EFI_SUCCESS;
1259 } else {
1260 return EFI_NOT_FOUND;
1261 }
1262 }
1263
1264 /**
1265 Resets an SD card that is connected to the SD controller.
1266
1267 The ResetDevice() function resets the SD card specified by Slot.
1268
1269 If this SD controller does not support a device reset operation, EFI_UNSUPPORTED is
1270 returned.
1271
1272 If Slot is not in a valid slot number for this SD controller, EFI_INVALID_PARAMETER
1273 is returned.
1274
1275 If the device reset operation is completed, EFI_SUCCESS is returned.
1276
1277 @param[in] This A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
1278 @param[in] Slot Specifies the slot number of the SD card to be reset.
1279
1280 @retval EFI_SUCCESS The SD card specified by Slot was reset.
1281 @retval EFI_UNSUPPORTED The SD controller does not support a device reset operation.
1282 @retval EFI_INVALID_PARAMETER Slot number is invalid.
1283 @retval EFI_NO_MEDIA SD Device not present in the Slot.
1284 @retval EFI_DEVICE_ERROR The reset command failed due to a device error
1285
1286 **/
1287 EFI_STATUS
1288 EFIAPI
1289 SdMmcPassThruResetDevice (
1290 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *This,
1291 IN UINT8 Slot
1292 )
1293 {
1294 SD_MMC_HC_PRIVATE_DATA *Private;
1295 LIST_ENTRY *Link;
1296 LIST_ENTRY *NextLink;
1297 SD_MMC_HC_TRB *Trb;
1298 EFI_TPL OldTpl;
1299
1300 if (This == NULL) {
1301 return EFI_INVALID_PARAMETER;
1302 }
1303
1304 Private = SD_MMC_HC_PRIVATE_FROM_THIS (This);
1305
1306 if (!Private->Slot[Slot].Enable) {
1307 return EFI_INVALID_PARAMETER;
1308 }
1309
1310 if (!Private->Slot[Slot].MediaPresent) {
1311 return EFI_NO_MEDIA;
1312 }
1313
1314 if (!Private->Slot[Slot].Initialized) {
1315 return EFI_DEVICE_ERROR;
1316 }
1317 //
1318 // Free all async I/O requests in the queue
1319 //
1320 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
1321
1322 for (Link = GetFirstNode (&Private->Queue);
1323 !IsNull (&Private->Queue, Link);
1324 Link = NextLink) {
1325 NextLink = GetNextNode (&Private->Queue, Link);
1326 RemoveEntryList (Link);
1327 Trb = SD_MMC_HC_TRB_FROM_THIS (Link);
1328 Trb->Packet->TransactionStatus = EFI_ABORTED;
1329 gBS->SignalEvent (Trb->Event);
1330 SdMmcFreeTrb (Trb);
1331 }
1332
1333 gBS->RestoreTPL (OldTpl);
1334
1335 return EFI_SUCCESS;
1336 }
1337