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