]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c
Retire PciHotplugDeviceGuid.
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Pci / PciBusDxe / PciDeviceSupport.c
index 3f72a71d731c6ffbbf96f091ea5b769715f351e0..e205fe9dc88cb696d32f9b4dcbb350f18aee7f73 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2006, Intel Corporation                                                         \r
+Copyright (c) 2006 - 2009, Intel Corporation                                                         \r
 All rights reserved. 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
@@ -220,6 +220,7 @@ RegisterPciDevice (
   UINT8               PciExpressCapRegOffset;\r
   EFI_PCI_IO_PROTOCOL *PciIo;\r
   UINT8               Data8;\r
+  BOOLEAN             HasEfiImage;\r
 \r
   //\r
   // Install the pciio protocol, device path protocol\r
@@ -261,7 +262,6 @@ RegisterPciDevice (
   // Process OpRom\r
   //\r
   if (!PciIoDevice->AllOpRomProcessed) {\r
-    PciIoDevice->AllOpRomProcessed = TRUE;\r
 \r
     //\r
     // Get the OpRom provided by platform\r
@@ -279,7 +279,7 @@ RegisterPciDevice (
         PciIoDevice->PciIo.RomImage = PlatformOpRomBuffer;\r
         //\r
         // For OpROM read from gPciPlatformProtocol:\r
-        //   Add the Rom Image to internal database for later PCI light enumeration\r
+        // Add the Rom Image to internal database for later PCI light enumeration\r
         //\r
         PciRomAddImageMapping (\r
           NULL,\r
@@ -290,16 +290,46 @@ RegisterPciDevice (
           (UINT64) (UINTN) PciIoDevice->PciIo.RomImage,\r
           PciIoDevice->PciIo.RomSize\r
           );\r
-        \r
       }\r
     }\r
+  }\r
+\r
+  //\r
+  // Determine if there are EFI images in the option rom\r
+  //\r
+  HasEfiImage = ContainEfiImage (PciIoDevice->PciIo.RomImage, PciIoDevice->PciIo.RomSize);\r
+\r
+  if (HasEfiImage) {\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                    &PciIoDevice->Handle,\r
+                    &gEfiLoadFile2ProtocolGuid,\r
+                    &PciIoDevice->LoadFile2,\r
+                    NULL\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      gBS->UninstallMultipleProtocolInterfaces (\r
+             &PciIoDevice->Handle,\r
+             &gEfiDevicePathProtocolGuid,\r
+             PciIoDevice->DevicePath,\r
+             &gEfiPciIoProtocolGuid,\r
+             &PciIoDevice->PciIo,\r
+             NULL\r
+             );\r
+      return Status;\r
+    }\r
+  }\r
+\r
+\r
+  if (!PciIoDevice->AllOpRomProcessed) {\r
+\r
+    PciIoDevice->AllOpRomProcessed = TRUE;\r
 \r
     //\r
     // Dispatch the EFI OpRom for the PCI device.\r
     // The OpRom is got from platform in the above code\r
-    //   or loaded from device in previous bus enumeration\r
+    // or loaded from device in the previous round of bus enumeration\r
     //\r
-    if (PciIoDevice->RomSize > 0) {\r
+    if (HasEfiImage) {\r
       ProcessOpRomImage (PciIoDevice);\r
     }\r
   }\r
@@ -323,6 +353,14 @@ RegisterPciDevice (
              &PciIoDevice->PciIo,\r
              NULL\r
              );\r
+      if (HasEfiImage) {\r
+        gBS->UninstallMultipleProtocolInterfaces (\r
+               &PciIoDevice->Handle,\r
+               &gEfiLoadFile2ProtocolGuid,\r
+               &PciIoDevice->LoadFile2,\r
+               NULL\r
+               );\r
+      }\r
 \r
       return Status;\r
     }\r
@@ -340,12 +378,6 @@ RegisterPciDevice (
     return Status;\r
   }\r
 \r
-  //\r
-  // Install Pccard Hotplug GUID for Pccard device so that\r
-  // to notify CardBus driver to stop the device when de-register happens\r
-  //\r
-  InstallPciHotplugGuid (PciIoDevice);\r
-\r
   if (Handle != NULL) {\r
     *Handle = PciIoDevice->Handle;\r
   }\r
@@ -467,10 +499,6 @@ DeRegisterPciDevice (
         CurrentLink = CurrentLink->ForwardLink;\r
       }\r
     }\r
-    //\r
-    // Uninstall Pccard Hotplug GUID for Pccard device\r
-    //\r
-    UninstallPciHotplugGuid (PciIoDevice);\r
 \r
     //\r
     // Close the child handle\r
@@ -507,6 +535,33 @@ DeRegisterPciDevice (
                       );\r
     }\r
 \r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Try to uninstall LoadFile2 protocol if exists\r
+      //\r
+      Status = gBS->OpenProtocol (\r
+                      Handle,\r
+                      &gEfiLoadFile2ProtocolGuid,\r
+                      NULL,\r
+                      gPciBusDriverBinding.DriverBindingHandle,\r
+                      Controller,\r
+                      EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
+                      );\r
+      if (!EFI_ERROR (Status)) {\r
+        Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                        Handle,\r
+                        &gEfiLoadFile2ProtocolGuid,\r
+                        &PciIoDevice->LoadFile2,\r
+                        NULL\r
+                        );\r
+      }\r
+      //\r
+      // Restore Status\r
+      //\r
+      Status = EFI_SUCCESS;\r
+    }\r
+\r
+\r
     if (EFI_ERROR (Status)) {\r
       gBS->OpenProtocol (\r
             Controller,\r
@@ -825,8 +880,9 @@ CreateRootBridge (
   //\r
   // Initialize the PCI I/O instance structure\r
   //\r
-  Status  = InitializePciIoInstance (Dev);\r
-  Status  = InitializePciDriverOverrideInstance (Dev);\r
+  InitializePciIoInstance (Dev);\r
+  InitializePciDriverOverrideInstance (Dev);\r
+  InitializePciLoadFile2 (Dev);\r
 \r
   //\r
   // Initialize reserved resource list and\r
@@ -1136,7 +1192,11 @@ GetHpcPciAddressFromRootBridge (
     return EFI_NOT_FOUND;\r
   }\r
 \r
-  *PciAddress = EFI_PCI_ADDRESS (Temp->BusNumber, Temp->DeviceNumber, Temp->FunctionNumber, 0);\r
+  if (Temp != NULL) {\r
+    *PciAddress = EFI_PCI_ADDRESS (Temp->BusNumber, Temp->DeviceNumber, Temp->FunctionNumber, 0);\r
+  } else {\r
+    return EFI_NOT_FOUND;\r
+  }\r
 \r
   return EFI_SUCCESS;\r
 \r