]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
MdeModulePkg/SdMmcPciHcDxe: Execute card detect only for RemovableSlot
[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 if (Private->Slot[Slot].SlotType == RemovableSlot) {
665 Status = SdMmcHcCardDetect (PciIo, Slot, &MediaPresent);
666 if (EFI_ERROR (Status) && (Status != EFI_MEDIA_CHANGED)) {
667 continue;
668 } else if (!MediaPresent) {
669 DEBUG ((
670 DEBUG_INFO,
671 "SdMmcHcCardDetect: No device attached in Slot[%d]!!!\n",
672 Slot
673 ));
674 continue;
675 }
676 }
677
678 Status = SdMmcHcInitHost (Private, Slot);
679 if (EFI_ERROR (Status)) {
680 continue;
681 }
682
683 Private->Slot[Slot].MediaPresent = TRUE;
684 Private->Slot[Slot].Initialized = TRUE;
685 RoutineNum = sizeof (mCardTypeDetectRoutineTable) / sizeof (CARD_TYPE_DETECT_ROUTINE);
686 for (Index = 0; Index < RoutineNum; Index++) {
687 Routine = &mCardTypeDetectRoutineTable[Index];
688 if (*Routine != NULL) {
689 Status = (*Routine) (Private, Slot);
690 if (!EFI_ERROR (Status)) {
691 break;
692 }
693 }
694 }
695 //
696 // This card doesn't get initialized correctly.
697 //
698 if (Index == RoutineNum) {
699 Private->Slot[Slot].Initialized = FALSE;
700 }
701 }
702
703 //
704 // Enable 64-bit DMA support in the PCI layer if this controller
705 // supports it.
706 //
707 if (Support64BitDma) {
708 Status = PciIo->Attributes (
709 PciIo,
710 EfiPciIoAttributeOperationEnable,
711 EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE,
712 NULL
713 );
714 if (EFI_ERROR (Status)) {
715 DEBUG ((DEBUG_WARN, "SdMmcPciHcDriverBindingStart: failed to enable 64-bit DMA (%r)\n", Status));
716 }
717 }
718
719 //
720 // Start the asynchronous I/O monitor
721 //
722 Status = gBS->CreateEvent (
723 EVT_TIMER | EVT_NOTIFY_SIGNAL,
724 TPL_NOTIFY,
725 ProcessAsyncTaskList,
726 Private,
727 &Private->TimerEvent
728 );
729 if (EFI_ERROR (Status)) {
730 goto Done;
731 }
732
733 Status = gBS->SetTimer (Private->TimerEvent, TimerPeriodic, SD_MMC_HC_ASYNC_TIMER);
734 if (EFI_ERROR (Status)) {
735 goto Done;
736 }
737
738 //
739 // Start the Sd removable device connection enumeration
740 //
741 Status = gBS->CreateEvent (
742 EVT_TIMER | EVT_NOTIFY_SIGNAL,
743 TPL_CALLBACK,
744 SdMmcPciHcEnumerateDevice,
745 Private,
746 &Private->ConnectEvent
747 );
748 if (EFI_ERROR (Status)) {
749 goto Done;
750 }
751
752 Status = gBS->SetTimer (Private->ConnectEvent, TimerPeriodic, SD_MMC_HC_ENUM_TIMER);
753 if (EFI_ERROR (Status)) {
754 goto Done;
755 }
756
757 Status = gBS->InstallMultipleProtocolInterfaces (
758 &Controller,
759 &gEfiSdMmcPassThruProtocolGuid,
760 &(Private->PassThru),
761 NULL
762 );
763
764 DEBUG ((DEBUG_INFO, "SdMmcPciHcDriverBindingStart: %r End on %x\n", Status, Controller));
765
766 Done:
767 if (EFI_ERROR (Status)) {
768 if ((Private != NULL) && (Private->PciAttributes != 0)) {
769 //
770 // Restore original PCI attributes
771 //
772 PciIo->Attributes (
773 PciIo,
774 EfiPciIoAttributeOperationSet,
775 Private->PciAttributes,
776 NULL
777 );
778 }
779 gBS->CloseProtocol (
780 Controller,
781 &gEfiPciIoProtocolGuid,
782 This->DriverBindingHandle,
783 Controller
784 );
785
786 if ((Private != NULL) && (Private->TimerEvent != NULL)) {
787 gBS->CloseEvent (Private->TimerEvent);
788 }
789
790 if ((Private != NULL) && (Private->ConnectEvent != NULL)) {
791 gBS->CloseEvent (Private->ConnectEvent);
792 }
793
794 if (Private != NULL) {
795 FreePool (Private);
796 }
797 }
798
799 return Status;
800 }
801
802 /**
803 Stops a device controller or a bus controller.
804
805 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
806 As a result, much of the error checking on the parameters to Stop() has been moved
807 into this common boot service. It is legal to call Stop() from other locations,
808 but the following calling restrictions must be followed or the system behavior will not be deterministic.
809 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
810 same driver's Start() function.
811 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
812 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
813 Start() function, and the Start() function must have called OpenProtocol() on
814 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
815
816 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
817 @param[in] ControllerHandle A handle to the device being stopped. The handle must
818 support a bus specific I/O protocol for the driver
819 to use to stop the device.
820 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
821 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
822 if NumberOfChildren is 0.
823
824 @retval EFI_SUCCESS The device was stopped.
825 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
826
827 **/
828 EFI_STATUS
829 EFIAPI
830 SdMmcPciHcDriverBindingStop (
831 IN EFI_DRIVER_BINDING_PROTOCOL *This,
832 IN EFI_HANDLE Controller,
833 IN UINTN NumberOfChildren,
834 IN EFI_HANDLE *ChildHandleBuffer
835 )
836 {
837 EFI_STATUS Status;
838 EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru;
839 SD_MMC_HC_PRIVATE_DATA *Private;
840 EFI_PCI_IO_PROTOCOL *PciIo;
841 LIST_ENTRY *Link;
842 LIST_ENTRY *NextLink;
843 SD_MMC_HC_TRB *Trb;
844
845 DEBUG ((DEBUG_INFO, "SdMmcPciHcDriverBindingStop: Start\n"));
846
847 Status = gBS->OpenProtocol (
848 Controller,
849 &gEfiSdMmcPassThruProtocolGuid,
850 (VOID**) &PassThru,
851 This->DriverBindingHandle,
852 Controller,
853 EFI_OPEN_PROTOCOL_GET_PROTOCOL
854 );
855 if (EFI_ERROR (Status)) {
856 return Status;
857 }
858
859 Private = SD_MMC_HC_PRIVATE_FROM_THIS (PassThru);
860 //
861 // Close Non-Blocking timer and free Task list.
862 //
863 if (Private->TimerEvent != NULL) {
864 gBS->CloseEvent (Private->TimerEvent);
865 Private->TimerEvent = NULL;
866 }
867 if (Private->ConnectEvent != NULL) {
868 gBS->CloseEvent (Private->ConnectEvent);
869 Private->ConnectEvent = NULL;
870 }
871 //
872 // As the timer is closed, there is no needs to use TPL lock to
873 // protect the critical region "queue".
874 //
875 for (Link = GetFirstNode (&Private->Queue);
876 !IsNull (&Private->Queue, Link);
877 Link = NextLink) {
878 NextLink = GetNextNode (&Private->Queue, Link);
879 RemoveEntryList (Link);
880 Trb = SD_MMC_HC_TRB_FROM_THIS (Link);
881 Trb->Packet->TransactionStatus = EFI_ABORTED;
882 gBS->SignalEvent (Trb->Event);
883 SdMmcFreeTrb (Trb);
884 }
885
886 //
887 // Uninstall Block I/O protocol from the device handle
888 //
889 Status = gBS->UninstallProtocolInterface (
890 Controller,
891 &gEfiSdMmcPassThruProtocolGuid,
892 &(Private->PassThru)
893 );
894
895 if (EFI_ERROR (Status)) {
896 return Status;
897 }
898
899 gBS->CloseProtocol (
900 Controller,
901 &gEfiPciIoProtocolGuid,
902 This->DriverBindingHandle,
903 Controller
904 );
905 //
906 // Restore original PCI attributes
907 //
908 PciIo = Private->PciIo;
909 Status = PciIo->Attributes (
910 PciIo,
911 EfiPciIoAttributeOperationSet,
912 Private->PciAttributes,
913 NULL
914 );
915 ASSERT_EFI_ERROR (Status);
916
917 FreePool (Private);
918
919 DEBUG ((DEBUG_INFO, "SdMmcPciHcDriverBindingStop: End with %r\n", Status));
920
921 return Status;
922 }
923
924 /**
925 Sends SD command to an SD card that is attached to the SD controller.
926
927 The PassThru() function sends the SD command specified by Packet to the SD card
928 specified by Slot.
929
930 If Packet is successfully sent to the SD card, then EFI_SUCCESS is returned.
931
932 If a device error occurs while sending the Packet, then EFI_DEVICE_ERROR is returned.
933
934 If Slot is not in a valid range for the SD controller, then EFI_INVALID_PARAMETER
935 is returned.
936
937 If Packet defines a data command but both InDataBuffer and OutDataBuffer are NULL,
938 EFI_INVALID_PARAMETER is returned.
939
940 @param[in] This A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
941 @param[in] Slot The slot number of the SD card to send the command to.
942 @param[in,out] Packet A pointer to the SD command data structure.
943 @param[in] Event If Event is NULL, blocking I/O is performed. If Event is
944 not NULL, then nonblocking I/O is performed, and Event
945 will be signaled when the Packet completes.
946
947 @retval EFI_SUCCESS The SD Command Packet was sent by the host.
948 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SD
949 command Packet.
950 @retval EFI_INVALID_PARAMETER Packet, Slot, or the contents of the Packet is invalid.
951 @retval EFI_INVALID_PARAMETER Packet defines a data command but both InDataBuffer and
952 OutDataBuffer are NULL.
953 @retval EFI_NO_MEDIA SD Device not present in the Slot.
954 @retval EFI_UNSUPPORTED The command described by the SD Command Packet is not
955 supported by the host controller.
956 @retval EFI_BAD_BUFFER_SIZE The InTransferLength or OutTransferLength exceeds the
957 limit supported by SD card ( i.e. if the number of bytes
958 exceed the Last LBA).
959
960 **/
961 EFI_STATUS
962 EFIAPI
963 SdMmcPassThruPassThru (
964 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *This,
965 IN UINT8 Slot,
966 IN OUT EFI_SD_MMC_PASS_THRU_COMMAND_PACKET *Packet,
967 IN EFI_EVENT Event OPTIONAL
968 )
969 {
970 EFI_STATUS Status;
971 SD_MMC_HC_PRIVATE_DATA *Private;
972 SD_MMC_HC_TRB *Trb;
973 EFI_TPL OldTpl;
974
975 if ((This == NULL) || (Packet == NULL)) {
976 return EFI_INVALID_PARAMETER;
977 }
978
979 if ((Packet->SdMmcCmdBlk == NULL) || (Packet->SdMmcStatusBlk == NULL)) {
980 return EFI_INVALID_PARAMETER;
981 }
982
983 if ((Packet->OutDataBuffer == NULL) && (Packet->OutTransferLength != 0)) {
984 return EFI_INVALID_PARAMETER;
985 }
986
987 if ((Packet->InDataBuffer == NULL) && (Packet->InTransferLength != 0)) {
988 return EFI_INVALID_PARAMETER;
989 }
990
991 Private = SD_MMC_HC_PRIVATE_FROM_THIS (This);
992
993 if (!Private->Slot[Slot].Enable) {
994 return EFI_INVALID_PARAMETER;
995 }
996
997 if (!Private->Slot[Slot].MediaPresent) {
998 return EFI_NO_MEDIA;
999 }
1000
1001 if (!Private->Slot[Slot].Initialized) {
1002 return EFI_DEVICE_ERROR;
1003 }
1004
1005 Trb = SdMmcCreateTrb (Private, Slot, Packet, Event);
1006 if (Trb == NULL) {
1007 return EFI_OUT_OF_RESOURCES;
1008 }
1009 //
1010 // Immediately return for async I/O.
1011 //
1012 if (Event != NULL) {
1013 return EFI_SUCCESS;
1014 }
1015
1016 //
1017 // Wait async I/O list is empty before execute sync I/O operation.
1018 //
1019 while (TRUE) {
1020 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
1021 if (IsListEmpty (&Private->Queue)) {
1022 gBS->RestoreTPL (OldTpl);
1023 break;
1024 }
1025 gBS->RestoreTPL (OldTpl);
1026 }
1027
1028 Status = SdMmcWaitTrbEnv (Private, Trb);
1029 if (EFI_ERROR (Status)) {
1030 goto Done;
1031 }
1032
1033 Status = SdMmcExecTrb (Private, Trb);
1034 if (EFI_ERROR (Status)) {
1035 goto Done;
1036 }
1037
1038 Status = SdMmcWaitTrbResult (Private, Trb);
1039 if (EFI_ERROR (Status)) {
1040 goto Done;
1041 }
1042
1043 Done:
1044 SdMmcFreeTrb (Trb);
1045
1046 return Status;
1047 }
1048
1049 /**
1050 Used to retrieve next slot numbers supported by the SD controller. The function
1051 returns information about all available slots (populated or not-populated).
1052
1053 The GetNextSlot() function retrieves the next slot number on an SD controller.
1054 If on input Slot is 0xFF, then the slot number of the first slot on the SD controller
1055 is returned.
1056
1057 If Slot is a slot number that was returned on a previous call to GetNextSlot(), then
1058 the slot number of the next slot on the SD controller is returned.
1059
1060 If Slot is not 0xFF and Slot was not returned on a previous call to GetNextSlot(),
1061 EFI_INVALID_PARAMETER is returned.
1062
1063 If Slot is the slot number of the last slot on the SD controller, then EFI_NOT_FOUND
1064 is returned.
1065
1066 @param[in] This A pointer to the EFI_SD_MMMC_PASS_THRU_PROTOCOL instance.
1067 @param[in,out] Slot On input, a pointer to a slot number on the SD controller.
1068 On output, a pointer to the next slot number on the SD controller.
1069 An input value of 0xFF retrieves the first slot number on the SD
1070 controller.
1071
1072 @retval EFI_SUCCESS The next slot number on the SD controller was returned in Slot.
1073 @retval EFI_NOT_FOUND There are no more slots on this SD controller.
1074 @retval EFI_INVALID_PARAMETER Slot is not 0xFF and Slot was not returned on a previous call
1075 to GetNextSlot().
1076
1077 **/
1078 EFI_STATUS
1079 EFIAPI
1080 SdMmcPassThruGetNextSlot (
1081 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *This,
1082 IN OUT UINT8 *Slot
1083 )
1084 {
1085 SD_MMC_HC_PRIVATE_DATA *Private;
1086 UINT8 Index;
1087
1088 if ((This == NULL) || (Slot == NULL)) {
1089 return EFI_INVALID_PARAMETER;
1090 }
1091
1092 Private = SD_MMC_HC_PRIVATE_FROM_THIS (This);
1093
1094 if (*Slot == 0xFF) {
1095 for (Index = 0; Index < SD_MMC_HC_MAX_SLOT; Index++) {
1096 if (Private->Slot[Index].Enable) {
1097 *Slot = Index;
1098 Private->PreviousSlot = Index;
1099 return EFI_SUCCESS;
1100 }
1101 }
1102 return EFI_NOT_FOUND;
1103 } else if (*Slot == Private->PreviousSlot) {
1104 for (Index = *Slot + 1; Index < SD_MMC_HC_MAX_SLOT; Index++) {
1105 if (Private->Slot[Index].Enable) {
1106 *Slot = Index;
1107 Private->PreviousSlot = Index;
1108 return EFI_SUCCESS;
1109 }
1110 }
1111 return EFI_NOT_FOUND;
1112 } else {
1113 return EFI_INVALID_PARAMETER;
1114 }
1115 }
1116
1117 /**
1118 Used to allocate and build a device path node for an SD card on the SD controller.
1119
1120 The BuildDevicePath() function allocates and builds a single device node for the SD
1121 card specified by Slot.
1122
1123 If the SD card specified by Slot is not present on the SD controller, then EFI_NOT_FOUND
1124 is returned.
1125
1126 If DevicePath is NULL, then EFI_INVALID_PARAMETER is returned.
1127
1128 If there are not enough resources to allocate the device path node, then EFI_OUT_OF_RESOURCES
1129 is returned.
1130
1131 Otherwise, DevicePath is allocated with the boot service AllocatePool(), the contents of
1132 DevicePath are initialized to describe the SD card specified by Slot, and EFI_SUCCESS is
1133 returned.
1134
1135 @param[in] This A pointer to the EFI_SD_MMMC_PASS_THRU_PROTOCOL instance.
1136 @param[in] Slot Specifies the slot number of the SD card for which a device
1137 path node is to be allocated and built.
1138 @param[in,out] DevicePath A pointer to a single device path node that describes the SD
1139 card specified by Slot. This function is responsible for
1140 allocating the buffer DevicePath with the boot service
1141 AllocatePool(). It is the caller's responsibility to free
1142 DevicePath when the caller is finished with DevicePath.
1143
1144 @retval EFI_SUCCESS The device path node that describes the SD card specified by
1145 Slot was allocated and returned in DevicePath.
1146 @retval EFI_NOT_FOUND The SD card specified by Slot does not exist on the SD controller.
1147 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
1148 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate DevicePath.
1149
1150 **/
1151 EFI_STATUS
1152 EFIAPI
1153 SdMmcPassThruBuildDevicePath (
1154 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *This,
1155 IN UINT8 Slot,
1156 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
1157 )
1158 {
1159 SD_MMC_HC_PRIVATE_DATA *Private;
1160 SD_DEVICE_PATH *SdNode;
1161 EMMC_DEVICE_PATH *EmmcNode;
1162
1163 if ((This == NULL) || (DevicePath == NULL) || (Slot >= SD_MMC_HC_MAX_SLOT)) {
1164 return EFI_INVALID_PARAMETER;
1165 }
1166
1167 Private = SD_MMC_HC_PRIVATE_FROM_THIS (This);
1168
1169 if ((!Private->Slot[Slot].Enable) || (!Private->Slot[Slot].MediaPresent)) {
1170 return EFI_NOT_FOUND;
1171 }
1172
1173 if (Private->Slot[Slot].CardType == SdCardType) {
1174 SdNode = AllocateCopyPool (sizeof (SD_DEVICE_PATH), &mSdDpTemplate);
1175 if (SdNode == NULL) {
1176 return EFI_OUT_OF_RESOURCES;
1177 }
1178 SdNode->SlotNumber = Slot;
1179
1180 *DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) SdNode;
1181 } else if (Private->Slot[Slot].CardType == EmmcCardType) {
1182 EmmcNode = AllocateCopyPool (sizeof (EMMC_DEVICE_PATH), &mEmmcDpTemplate);
1183 if (EmmcNode == NULL) {
1184 return EFI_OUT_OF_RESOURCES;
1185 }
1186 EmmcNode->SlotNumber = Slot;
1187
1188 *DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) EmmcNode;
1189 } else {
1190 //
1191 // Currently we only support SD and EMMC two device nodes.
1192 //
1193 return EFI_NOT_FOUND;
1194 }
1195
1196 return EFI_SUCCESS;
1197 }
1198
1199 /**
1200 This function retrieves an SD card slot number based on the input device path.
1201
1202 The GetSlotNumber() function retrieves slot number for the SD card specified by
1203 the DevicePath node. If DevicePath is NULL, EFI_INVALID_PARAMETER is returned.
1204
1205 If DevicePath is not a device path node type that the SD Pass Thru driver supports,
1206 EFI_UNSUPPORTED is returned.
1207
1208 @param[in] This A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
1209 @param[in] DevicePath A pointer to the device path node that describes a SD
1210 card on the SD controller.
1211 @param[out] Slot On return, points to the slot number of an SD card on
1212 the SD controller.
1213
1214 @retval EFI_SUCCESS SD card slot number is returned in Slot.
1215 @retval EFI_INVALID_PARAMETER Slot or DevicePath is NULL.
1216 @retval EFI_UNSUPPORTED DevicePath is not a device path node type that the SD
1217 Pass Thru driver supports.
1218
1219 **/
1220 EFI_STATUS
1221 EFIAPI
1222 SdMmcPassThruGetSlotNumber (
1223 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *This,
1224 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
1225 OUT UINT8 *Slot
1226 )
1227 {
1228 SD_MMC_HC_PRIVATE_DATA *Private;
1229 SD_DEVICE_PATH *SdNode;
1230 EMMC_DEVICE_PATH *EmmcNode;
1231 UINT8 SlotNumber;
1232
1233 if ((This == NULL) || (DevicePath == NULL) || (Slot == NULL)) {
1234 return EFI_INVALID_PARAMETER;
1235 }
1236
1237 Private = SD_MMC_HC_PRIVATE_FROM_THIS (This);
1238
1239 //
1240 // Check whether the DevicePath belongs to SD_DEVICE_PATH or EMMC_DEVICE_PATH
1241 //
1242 if ((DevicePath->Type != MESSAGING_DEVICE_PATH) ||
1243 ((DevicePath->SubType != MSG_SD_DP) &&
1244 (DevicePath->SubType != MSG_EMMC_DP)) ||
1245 (DevicePathNodeLength(DevicePath) != sizeof(SD_DEVICE_PATH)) ||
1246 (DevicePathNodeLength(DevicePath) != sizeof(EMMC_DEVICE_PATH))) {
1247 return EFI_UNSUPPORTED;
1248 }
1249
1250 if (DevicePath->SubType == MSG_SD_DP) {
1251 SdNode = (SD_DEVICE_PATH *) DevicePath;
1252 SlotNumber = SdNode->SlotNumber;
1253 } else {
1254 EmmcNode = (EMMC_DEVICE_PATH *) DevicePath;
1255 SlotNumber = EmmcNode->SlotNumber;
1256 }
1257
1258 if (SlotNumber >= SD_MMC_HC_MAX_SLOT) {
1259 return EFI_NOT_FOUND;
1260 }
1261
1262 if (Private->Slot[SlotNumber].Enable) {
1263 *Slot = SlotNumber;
1264 return EFI_SUCCESS;
1265 } else {
1266 return EFI_NOT_FOUND;
1267 }
1268 }
1269
1270 /**
1271 Resets an SD card that is connected to the SD controller.
1272
1273 The ResetDevice() function resets the SD card specified by Slot.
1274
1275 If this SD controller does not support a device reset operation, EFI_UNSUPPORTED is
1276 returned.
1277
1278 If Slot is not in a valid slot number for this SD controller, EFI_INVALID_PARAMETER
1279 is returned.
1280
1281 If the device reset operation is completed, EFI_SUCCESS is returned.
1282
1283 @param[in] This A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
1284 @param[in] Slot Specifies the slot number of the SD card to be reset.
1285
1286 @retval EFI_SUCCESS The SD card specified by Slot was reset.
1287 @retval EFI_UNSUPPORTED The SD controller does not support a device reset operation.
1288 @retval EFI_INVALID_PARAMETER Slot number is invalid.
1289 @retval EFI_NO_MEDIA SD Device not present in the Slot.
1290 @retval EFI_DEVICE_ERROR The reset command failed due to a device error
1291
1292 **/
1293 EFI_STATUS
1294 EFIAPI
1295 SdMmcPassThruResetDevice (
1296 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *This,
1297 IN UINT8 Slot
1298 )
1299 {
1300 SD_MMC_HC_PRIVATE_DATA *Private;
1301 LIST_ENTRY *Link;
1302 LIST_ENTRY *NextLink;
1303 SD_MMC_HC_TRB *Trb;
1304 EFI_TPL OldTpl;
1305
1306 if (This == NULL) {
1307 return EFI_INVALID_PARAMETER;
1308 }
1309
1310 Private = SD_MMC_HC_PRIVATE_FROM_THIS (This);
1311
1312 if (!Private->Slot[Slot].Enable) {
1313 return EFI_INVALID_PARAMETER;
1314 }
1315
1316 if (!Private->Slot[Slot].MediaPresent) {
1317 return EFI_NO_MEDIA;
1318 }
1319
1320 if (!Private->Slot[Slot].Initialized) {
1321 return EFI_DEVICE_ERROR;
1322 }
1323 //
1324 // Free all async I/O requests in the queue
1325 //
1326 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
1327
1328 for (Link = GetFirstNode (&Private->Queue);
1329 !IsNull (&Private->Queue, Link);
1330 Link = NextLink) {
1331 NextLink = GetNextNode (&Private->Queue, Link);
1332 RemoveEntryList (Link);
1333 Trb = SD_MMC_HC_TRB_FROM_THIS (Link);
1334 Trb->Packet->TransactionStatus = EFI_ABORTED;
1335 gBS->SignalEvent (Trb->Event);
1336 SdMmcFreeTrb (Trb);
1337 }
1338
1339 gBS->RestoreTPL (OldTpl);
1340
1341 return EFI_SUCCESS;
1342 }
1343