]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.c
MdeModulePkg/PciBusDxe: Fix small memory leak in FreePciDevice
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciBusDxe / PciBus.c
index 950cacc1203c28e10e5867c28eefc0280f2f4082..9ae45cca9be926081a7de55f5b69748952c26410 100644 (file)
@@ -8,7 +8,7 @@
   PCI Root Bridges. So it means platform needs install PCI Root Bridge IO protocol for each\r
   PCI Root Bus and install PCI Host Bridge Resource Allocation Protocol.\r
 \r
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2018, 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
@@ -140,7 +140,7 @@ PciBusDriverBindingSupported (
   //\r
   if (RemainingDevicePath != NULL) {\r
     //\r
-    // Check if RemainingDevicePath is the End of Device Path Node, \r
+    // Check if RemainingDevicePath is the End of Device Path Node,\r
     // if yes, go on checking other conditions\r
     //\r
     if (!IsDevicePathEnd (RemainingDevicePath)) {\r
@@ -240,15 +240,21 @@ PciBusDriverBindingStart (
   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
   )\r
 {\r
-  EFI_STATUS                Status;\r
-  EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;\r
+  EFI_STATUS                      Status;\r
+  EFI_DEVICE_PATH_PROTOCOL        *ParentDevicePath;\r
+  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;\r
+\r
+  //\r
+  // Initialize PciRootBridgeIo to suppress incorrect compiler warning.\r
+  //\r
+  PciRootBridgeIo = NULL;\r
 \r
   //\r
   // Check RemainingDevicePath validation\r
   //\r
   if (RemainingDevicePath != NULL) {\r
     //\r
-    // Check if RemainingDevicePath is the End of Device Path Node, \r
+    // Check if RemainingDevicePath is the End of Device Path Node,\r
     // if yes, return EFI_SUCCESS\r
     //\r
     if (IsDevicePathEnd (RemainingDevicePath)) {\r
@@ -276,14 +282,14 @@ PciBusDriverBindingStart (
   //\r
   // If PCI Platform protocol doesn't exist, try to Pci Override Protocol.\r
   //\r
-  if (gPciPlatformProtocol == NULL) { \r
+  if (gPciPlatformProtocol == NULL) {\r
     gPciOverrideProtocol = NULL;\r
     gBS->LocateProtocol (\r
           &gEfiPciOverrideProtocolGuid,\r
           NULL,\r
           (VOID **) &gPciOverrideProtocol\r
           );\r
-  }  \r
+  }\r
 \r
   if (mIoMmuProtocol == NULL) {\r
     gBS->LocateProtocol (\r
@@ -309,7 +315,7 @@ PciBusDriverBindingStart (
                   This->DriverBindingHandle,\r
                   Controller,\r
                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                  );  \r
+                  );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
@@ -321,12 +327,34 @@ PciBusDriverBindingStart (
     ParentDevicePath\r
     );\r
 \r
+  Status = EFI_SUCCESS;\r
   //\r
   // Enumerate the entire host bridge\r
   // After enumeration, a database that records all the device information will be created\r
   //\r
   //\r
-  Status = PciEnumerator (Controller);\r
+  if (gFullEnumeration) {\r
+    //\r
+    // Get the rootbridge Io protocol to find the host bridge handle\r
+    //\r
+    Status = gBS->OpenProtocol (\r
+                    Controller,\r
+                    &gEfiPciRootBridgeIoProtocolGuid,\r
+                    (VOID **) &PciRootBridgeIo,\r
+                    gPciBusDriverBinding.DriverBindingHandle,\r
+                    Controller,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
+\r
+    if (!EFI_ERROR (Status)) {\r
+      Status = PciEnumerator (Controller, PciRootBridgeIo->ParentHandle);\r
+    }\r
+  } else {\r
+    //\r
+    // If PCI bus has already done the full enumeration, never do it again\r
+    //\r
+    Status = PciEnumeratorLight (Controller);\r
+  }\r
 \r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
@@ -337,7 +365,19 @@ PciBusDriverBindingStart (
   //\r
   StartPciDevices (Controller);\r
 \r
-  return EFI_SUCCESS;\r
+  if (gFullEnumeration) {\r
+    gFullEnumeration = FALSE;\r
+\r
+    Status = gBS->InstallProtocolInterface (\r
+                    &PciRootBridgeIo->ParentHandle,\r
+                    &gEfiPciEnumerationCompleteProtocolGuid,\r
+                    EFI_NATIVE_INTERFACE,\r
+                    NULL\r
+                    );\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+\r
+  return Status;\r
 }\r
 \r
 /**\r