]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
MdeModulePkg/SdMmcPciHcDxe: Update comment for spec compliance status
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / SdMmcPciHcDxe / SdMmcPciHcDxe.c
index 4c1b5c8a5771b96ae04d8afbb2acfe5cff8f7712..b474f8decdb40aacc72a8dc737906337c2ec1cfa 100644 (file)
@@ -1,10 +1,13 @@
 /** @file\r
   This driver is used to manage SD/MMC PCI host controllers which are compliance\r
-  with SD Host Controller Simplified Specification version 3.00.\r
+  with SD Host Controller Simplified Specification version 3.00 plus the 64-bit\r
+  System Addressing support in SD Host Controller Simplified Specification version\r
+  4.20.\r
 \r
   It would expose EFI_SD_MMC_PASS_THRU_PROTOCOL for upper layer use.\r
 \r
-  Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.\r
+  Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -17,6 +20,8 @@
 \r
 #include "SdMmcPciHcDxe.h"\r
 \r
+EDKII_SD_MMC_OVERRIDE           *mOverride;\r
+\r
 //\r
 // Driver Global Variables\r
 //\r
@@ -60,7 +65,9 @@ SD_MMC_HC_PRIVATE_DATA gSdMmcPciHcTemplate = {
   {                                 // MaxCurrent\r
     0,\r
   },\r
-  0                                 // ControllerVersion\r
+  {\r
+    0                               // ControllerVersion\r
+  }\r
 };\r
 \r
 SD_DEVICE_PATH    mSdDpTemplate = {\r
@@ -281,14 +288,14 @@ SdMmcPciHcEnumerateDevice (
         //\r
         // Reset the specified slot of the SD/MMC Pci Host Controller\r
         //\r
-        Status = SdMmcHcReset (Private->PciIo, Slot);\r
+        Status = SdMmcHcReset (Private, Slot);\r
         if (EFI_ERROR (Status)) {\r
           continue;\r
         }\r
         //\r
         // Reinitialize slot and restart identification process for the new attached device\r
         //\r
-        Status = SdMmcHcInitHost (Private->PciIo, Slot, Private->Capability[Slot]);\r
+        Status = SdMmcHcInitHost (Private, Slot);\r
         if (EFI_ERROR (Status)) {\r
           continue;\r
         }\r
@@ -601,17 +608,68 @@ SdMmcPciHcDriverBindingStart (
     goto Done;\r
   }\r
 \r
+  //\r
+  // Attempt to locate the singleton instance of the SD/MMC override protocol,\r
+  // which implements platform specific workarounds for non-standard SDHCI\r
+  // implementations.\r
+  //\r
+  if (mOverride == NULL) {\r
+    Status = gBS->LocateProtocol (&gEdkiiSdMmcOverrideProtocolGuid, NULL,\r
+                    (VOID **)&mOverride);\r
+    if (!EFI_ERROR (Status)) {\r
+      DEBUG ((DEBUG_INFO, "%a: found SD/MMC override protocol\n",\r
+        __FUNCTION__));\r
+    }\r
+  }\r
+\r
   Support64BitDma = TRUE;\r
   for (Slot = FirstBar; Slot < (FirstBar + SlotNum); Slot++) {\r
     Private->Slot[Slot].Enable = TRUE;\r
 \r
+    //\r
+    // Get SD/MMC Pci Host Controller Version\r
+    //\r
+    Status = SdMmcHcGetControllerVersion (PciIo, Slot, &Private->ControllerVersion[Slot]);\r
+    if (EFI_ERROR (Status)) {\r
+      continue;\r
+    }\r
+\r
     Status = SdMmcHcGetCapability (PciIo, Slot, &Private->Capability[Slot]);\r
     if (EFI_ERROR (Status)) {\r
       continue;\r
     }\r
+\r
+    Private->BaseClkFreq[Slot] = Private->Capability[Slot].BaseClkFreq;\r
+\r
+    if (mOverride != NULL && mOverride->Capability != NULL) {\r
+      Status = mOverride->Capability (\r
+                            Controller,\r
+                            Slot,\r
+                            &Private->Capability[Slot],\r
+                            &Private->BaseClkFreq[Slot]\r
+                            );\r
+      if (EFI_ERROR (Status)) {\r
+        DEBUG ((DEBUG_WARN, "%a: Failed to override capability - %r\n",\r
+          __FUNCTION__, Status));\r
+        continue;\r
+      }\r
+    }\r
     DumpCapabilityReg (Slot, &Private->Capability[Slot]);\r
+    DEBUG ((\r
+      DEBUG_INFO,\r
+      "Slot[%d] Base Clock Frequency: %dMHz\n",\r
+      Slot,\r
+      Private->BaseClkFreq[Slot]\r
+      ));\r
 \r
-    Support64BitDma &= Private->Capability[Slot].SysBus64;\r
+    //\r
+    // If any of the slots does not support 64b system bus\r
+    // do not enable 64b DMA in the PCI layer.\r
+    //\r
+    if (Private->Capability[Slot].SysBus64V3 == 0 &&\r
+        Private->Capability[Slot].SysBus64V4 == 0) {\r
+      Support64BitDma = FALSE;\r
+    }\r
 \r
     Status = SdMmcHcGetMaxCurrent (PciIo, Slot, &Private->MaxCurrent[Slot]);\r
     if (EFI_ERROR (Status)) {\r
@@ -627,22 +685,28 @@ SdMmcPciHcDriverBindingStart (
     //\r
     // Reset the specified slot of the SD/MMC Pci Host Controller\r
     //\r
-    Status = SdMmcHcReset (PciIo, Slot);\r
+    Status = SdMmcHcReset (Private, Slot);\r
     if (EFI_ERROR (Status)) {\r
       continue;\r
     }\r
     //\r
     // Check whether there is a SD/MMC card attached\r
     //\r
-    Status = SdMmcHcCardDetect (PciIo, Slot, &MediaPresent);\r
-    if (EFI_ERROR (Status) && (Status != EFI_MEDIA_CHANGED)) {\r
-      continue;\r
-    } else if (!MediaPresent) {\r
-      DEBUG ((EFI_ERROR, "SdMmcHcCardDetect: No device attached in Slot[%d]!!!\n", Slot));\r
-      continue;\r
+    if (Private->Slot[Slot].SlotType == RemovableSlot) {\r
+      Status = SdMmcHcCardDetect (PciIo, Slot, &MediaPresent);\r
+      if (EFI_ERROR (Status) && (Status != EFI_MEDIA_CHANGED)) {\r
+        continue;\r
+      } else if (!MediaPresent) {\r
+        DEBUG ((\r
+          DEBUG_INFO,\r
+          "SdMmcHcCardDetect: No device attached in Slot[%d]!!!\n",\r
+          Slot\r
+          ));\r
+        continue;\r
+      }\r
     }\r
 \r
-    Status = SdMmcHcInitHost (PciIo, Slot, Private->Capability[Slot]);\r
+    Status = SdMmcHcInitHost (Private, Slot);\r
     if (EFI_ERROR (Status)) {\r
       continue;\r
     }\r
@@ -1008,13 +1072,7 @@ SdMmcPassThruPassThru (
   }\r
 \r
 Done:\r
-  if ((Trb != NULL) && (Trb->AdmaDesc != NULL)) {\r
-    FreePages (Trb->AdmaDesc, Trb->AdmaPages);\r
-  }\r
-\r
-  if (Trb != NULL) {\r
-    FreePool (Trb);\r
-  }\r
+  SdMmcFreeTrb (Trb);\r
 \r
   return Status;\r
 }\r