]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c
MdeModulePkg: Apply uncrustify changes
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciBusDxe / PciDeviceSupport.c
index 25387bd257c7707da4127a97906189d14a64c4f0..581e9075ad41ffa4aded31fdd490d5f5a9588663 100644 (file)
@@ -1,14 +1,9 @@
 /** @file\r
-  Supporting functions implementaion for PCI devices management.\r
+  Supporting functions implementation for PCI devices management.\r
 \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
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2018 Hewlett Packard Enterprise Development LP<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -40,7 +35,7 @@ InitializePciDevicePool (
 **/\r
 VOID\r
 InsertRootBridge (\r
-  IN PCI_IO_DEVICE      *RootBridge\r
+  IN PCI_IO_DEVICE  *RootBridge\r
   )\r
 {\r
   InsertTailList (&mPciDevicePool, &(RootBridge->Link));\r
@@ -56,8 +51,8 @@ InsertRootBridge (
 **/\r
 VOID\r
 InsertPciDevice (\r
-  IN PCI_IO_DEVICE      *Bridge,\r
-  IN PCI_IO_DEVICE      *PciDeviceNode\r
+  IN PCI_IO_DEVICE  *Bridge,\r
+  IN PCI_IO_DEVICE  *PciDeviceNode\r
   )\r
 {\r
   InsertTailList (&Bridge->ChildList, &(PciDeviceNode->Link));\r
@@ -65,14 +60,14 @@ InsertPciDevice (
 }\r
 \r
 /**\r
-  Destroy root bridge and remove it from deivce tree.\r
+  Destroy root bridge and remove it from device tree.\r
 \r
   @param RootBridge     The bridge want to be removed.\r
 \r
 **/\r
 VOID\r
 DestroyRootBridge (\r
-  IN PCI_IO_DEVICE      *RootBridge\r
+  IN PCI_IO_DEVICE  *RootBridge\r
   )\r
 {\r
   DestroyPciDeviceTree (RootBridge);\r
@@ -85,12 +80,12 @@ DestroyRootBridge (
 \r
   All direct or indirect allocated resource for this node will be freed.\r
 \r
-  @param PciIoDevice  A pointer to the PCI_IO_DEVICE to be destoried.\r
+  @param PciIoDevice  A pointer to the PCI_IO_DEVICE to be destroyed.\r
 \r
 **/\r
 VOID\r
 FreePciDevice (\r
-  IN PCI_IO_DEVICE    *PciIoDevice\r
+  IN PCI_IO_DEVICE  *PciIoDevice\r
   )\r
 {\r
   ASSERT (PciIoDevice != NULL);\r
@@ -105,6 +100,10 @@ FreePciDevice (
     FreePool (PciIoDevice->DevicePath);\r
   }\r
 \r
+  if (PciIoDevice->BusNumberRanges != NULL) {\r
+    FreePool (PciIoDevice->BusNumberRanges);\r
+  }\r
+\r
   FreePool (PciIoDevice);\r
 }\r
 \r
@@ -117,14 +116,13 @@ FreePciDevice (
 **/\r
 VOID\r
 DestroyPciDeviceTree (\r
-  IN PCI_IO_DEVICE      *Bridge\r
+  IN PCI_IO_DEVICE  *Bridge\r
   )\r
 {\r
-  LIST_ENTRY      *CurrentLink;\r
-  PCI_IO_DEVICE   *Temp;\r
+  LIST_ENTRY     *CurrentLink;\r
+  PCI_IO_DEVICE  *Temp;\r
 \r
   while (!IsListEmpty (&Bridge->ChildList)) {\r
-\r
     CurrentLink = Bridge->ChildList.ForwardLink;\r
 \r
     //\r
@@ -150,19 +148,18 @@ DestroyPciDeviceTree (
 \r
   @param  Controller    Root bridge handle.\r
 \r
-  @retval EFI_SUCCESS   Destory all devcie nodes successfully.\r
+  @retval EFI_SUCCESS   Destroy all device nodes successfully.\r
   @retval EFI_NOT_FOUND Cannot find any PCI device under specified\r
                         root bridge.\r
 \r
 **/\r
 EFI_STATUS\r
 DestroyRootBridgeByHandle (\r
-  IN EFI_HANDLE        Controller\r
+  IN EFI_HANDLE  Controller\r
   )\r
 {\r
-\r
-  LIST_ENTRY      *CurrentLink;\r
-  PCI_IO_DEVICE   *Temp;\r
+  LIST_ENTRY     *CurrentLink;\r
+  PCI_IO_DEVICE  *Temp;\r
 \r
   CurrentLink = mPciDevicePool.ForwardLink;\r
 \r
@@ -170,7 +167,6 @@ DestroyRootBridgeByHandle (
     Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
 \r
     if (Temp->Handle == Controller) {\r
-\r
       RemoveEntryList (CurrentLink);\r
 \r
       DestroyPciDeviceTree (Temp);\r
@@ -203,22 +199,17 @@ DestroyRootBridgeByHandle (
 **/\r
 EFI_STATUS\r
 RegisterPciDevice (\r
-  IN  EFI_HANDLE          Controller,\r
-  IN  PCI_IO_DEVICE       *PciIoDevice,\r
-  OUT EFI_HANDLE          *Handle      OPTIONAL\r
+  IN  EFI_HANDLE     Controller,\r
+  IN  PCI_IO_DEVICE  *PciIoDevice,\r
+  OUT EFI_HANDLE     *Handle      OPTIONAL\r
   )\r
 {\r
-  EFI_STATUS          Status;\r
-  VOID                *PlatformOpRomBuffer;\r
-  UINTN               PlatformOpRomSize;\r
-  UINT8               PciExpressCapRegOffset;\r
-  EFI_PCI_IO_PROTOCOL *PciIo;\r
-  UINT8               Data8;\r
-  BOOLEAN             HasEfiImage;\r
-  PCI_IO_DEVICE       *ParrentPciIoDevice;\r
-  EFI_PCI_IO_PROTOCOL *ParrentPciIo;\r
-  UINT16              Data16;\r
-  UINT32              Data32;\r
+  EFI_STATUS           Status;\r
+  VOID                 *PlatformOpRomBuffer;\r
+  UINTN                PlatformOpRomSize;\r
+  EFI_PCI_IO_PROTOCOL  *PciIo;\r
+  UINT8                Data8;\r
+  BOOLEAN              HasEfiImage;\r
 \r
   //\r
   // Install the pciio protocol, device path protocol\r
@@ -235,60 +226,17 @@ RegisterPciDevice (
     return Status;\r
   }\r
 \r
-  //\r
-  // Detect if PCI Express Device\r
-  //\r
-  PciExpressCapRegOffset = 0;\r
-  Status = LocateCapabilityRegBlock (\r
-             PciIoDevice,\r
-             EFI_PCI_CAPABILITY_ID_PCIEXP,\r
-             &PciExpressCapRegOffset,\r
-             NULL\r
-             );\r
-  if (!EFI_ERROR (Status)) {\r
-    PciIoDevice->IsPciExp = TRUE;\r
-  }\r
-\r
   //\r
   // Force Interrupt line to "Unknown" or "No Connection"\r
   //\r
   PciIo = &(PciIoDevice->PciIo);\r
   Data8 = PCI_INT_LINE_UNKNOWN;\r
   PciIo->Pci.Write (PciIo, EfiPciIoWidthUint8, 0x3C, 1, &Data8);\r
-  \r
-  //\r
-  // PCI-IOV programming\r
-  //\r
-  if (((FeaturePcdGet(PcdAriSupport) & EFI_PCI_IOV_POLICY_ARI) != 0) && (PciIoDevice->AriCapabilityOffset != 0) && ((FeaturePcdGet(PcdSrIovSupport) & EFI_PCI_IOV_POLICY_SRIOV) != 0) &&\r
-      (PciIoDevice->SrIovCapabilityOffset != 0)) {\r
-    //\r
-    // Check its parrent ARI forwarding capability\r
-    //\r
-    ParrentPciIoDevice = PciIoDevice->Parent;\r
-    ParrentPciIo = &(ParrentPciIoDevice->PciIo);\r
-    ParrentPciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, ParrentPciIoDevice->PciExpressCapabilityOffset + EFI_PCIE_CAPABILITY_DEVICE_CAPABILITIES_2_OFFSET, 1, &Data32);\r
-    if (Data32 & EFI_PCIE_CAPABILITY_DEVICE_CAPABILITIES_2_ARI_FORWARDING) {\r
-      //\r
-      // ARI forward support in bridge, so enable it.\r
-      //\r
-      ParrentPciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, ParrentPciIoDevice->PciExpressCapabilityOffset + EFI_PCIE_CAPABILITY_DEVICE_CONTROL_2_OFFSET, 1, &Data32);\r
-      Data32 |= EFI_PCIE_CAPABILITY_DEVICE_CONTROL_2_ARI_FORWARDING;\r
-      ParrentPciIo->Pci.Write (PciIo, EfiPciIoWidthUint32, ParrentPciIoDevice->PciExpressCapabilityOffset + EFI_PCIE_CAPABILITY_DEVICE_CONTROL_2_OFFSET, 1, &Data32);\r
 \r
-      //\r
-      // Set ARI Capable Hierarchy for device\r
-      //\r
-      PciIo->Pci.Read (PciIo, EfiPciIoWidthUint16, PciIoDevice->SrIovCapabilityOffset + EFI_PCIE_CAPABILITY_ID_SRIOV_CONTROL, 1, &Data16);\r
-      Data16 |= EFI_PCIE_CAPABILITY_ID_SRIOV_CONTROL_ARI_HIERARCHY;\r
-      PciIo->Pci.Write (PciIo, EfiPciIoWidthUint16, PciIoDevice->SrIovCapabilityOffset + EFI_PCIE_CAPABILITY_ID_SRIOV_CONTROL, 1, &Data16);\r
-    }\r
-  }\r
-  \r
   //\r
   // Process OpRom\r
   //\r
   if (!PciIoDevice->AllOpRomProcessed) {\r
-\r
     //\r
     // Get the OpRom provided by platform\r
     //\r
@@ -300,7 +248,8 @@ RegisterPciDevice (
                                        &PlatformOpRomSize\r
                                        );\r
       if (!EFI_ERROR (Status)) {\r
-        PciIoDevice->RomSize        = PlatformOpRomSize;\r
+        PciIoDevice->EmbeddedRom    = FALSE;\r
+        PciIoDevice->RomSize        = (UINT32)PlatformOpRomSize;\r
         PciIoDevice->PciIo.RomSize  = PlatformOpRomSize;\r
         PciIoDevice->PciIo.RomImage = PlatformOpRomBuffer;\r
         //\r
@@ -313,7 +262,7 @@ RegisterPciDevice (
           PciIoDevice->BusNumber,\r
           PciIoDevice->DeviceNumber,\r
           PciIoDevice->FunctionNumber,\r
-          (UINT64) (UINTN) PciIoDevice->PciIo.RomImage,\r
+          PciIoDevice->PciIo.RomImage,\r
           PciIoDevice->PciIo.RomSize\r
           );\r
       }\r
@@ -325,7 +274,8 @@ RegisterPciDevice (
                                        &PlatformOpRomSize\r
                                        );\r
       if (!EFI_ERROR (Status)) {\r
-        PciIoDevice->RomSize        = PlatformOpRomSize;\r
+        PciIoDevice->EmbeddedRom    = FALSE;\r
+        PciIoDevice->RomSize        = (UINT32)PlatformOpRomSize;\r
         PciIoDevice->PciIo.RomSize  = PlatformOpRomSize;\r
         PciIoDevice->PciIo.RomImage = PlatformOpRomBuffer;\r
         //\r
@@ -338,10 +288,10 @@ RegisterPciDevice (
           PciIoDevice->BusNumber,\r
           PciIoDevice->DeviceNumber,\r
           PciIoDevice->FunctionNumber,\r
-          (UINT64) (UINTN) PciIoDevice->PciIo.RomImage,\r
+          PciIoDevice->PciIo.RomImage,\r
           PciIoDevice->PciIo.RomSize\r
           );\r
-      }   \r
+      }\r
     }\r
   }\r
 \r
@@ -359,7 +309,7 @@ RegisterPciDevice (
                     );\r
     if (EFI_ERROR (Status)) {\r
       gBS->UninstallMultipleProtocolInterfaces (\r
-             &PciIoDevice->Handle,\r
+             PciIoDevice->Handle,\r
              &gEfiDevicePathProtocolGuid,\r
              PciIoDevice->DevicePath,\r
              &gEfiPciIoProtocolGuid,\r
@@ -370,9 +320,7 @@ RegisterPciDevice (
     }\r
   }\r
 \r
-\r
   if (!PciIoDevice->AllOpRomProcessed) {\r
-\r
     PciIoDevice->AllOpRomProcessed = TRUE;\r
 \r
     //\r
@@ -397,7 +345,7 @@ RegisterPciDevice (
                     );\r
     if (EFI_ERROR (Status)) {\r
       gBS->UninstallMultipleProtocolInterfaces (\r
-             &PciIoDevice->Handle,\r
+             PciIoDevice->Handle,\r
              &gEfiDevicePathProtocolGuid,\r
              PciIoDevice->DevicePath,\r
              &gEfiPciIoProtocolGuid,\r
@@ -406,7 +354,7 @@ RegisterPciDevice (
              );\r
       if (HasEfiImage) {\r
         gBS->UninstallMultipleProtocolInterfaces (\r
-               &PciIoDevice->Handle,\r
+               PciIoDevice->Handle,\r
                &gEfiLoadFile2ProtocolGuid,\r
                &PciIoDevice->LoadFile2,\r
                NULL\r
@@ -420,7 +368,7 @@ RegisterPciDevice (
   Status = gBS->OpenProtocol (\r
                   Controller,\r
                   &gEfiPciRootBridgeIoProtocolGuid,\r
-                  (VOID **) &(PciIoDevice->PciRootBridgeIo),\r
+                  (VOID **)&(PciIoDevice->PciRootBridgeIo),\r
                   gPciBusDriverBinding.DriverBindingHandle,\r
                   PciIoDevice->Handle,\r
                   EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
@@ -451,15 +399,14 @@ RegisterPciDevice (
 **/\r
 VOID\r
 RemoveAllPciDeviceOnBridge (\r
-  EFI_HANDLE               RootBridgeHandle,\r
-  PCI_IO_DEVICE            *Bridge\r
+  EFI_HANDLE     RootBridgeHandle,\r
+  PCI_IO_DEVICE  *Bridge\r
   )\r
 {\r
-  LIST_ENTRY      *CurrentLink;\r
-  PCI_IO_DEVICE   *Temp;\r
+  LIST_ENTRY     *CurrentLink;\r
+  PCI_IO_DEVICE  *Temp;\r
 \r
   while (!IsListEmpty (&Bridge->ChildList)) {\r
-\r
     CurrentLink = Bridge->ChildList.ForwardLink;\r
     Temp        = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
 \r
@@ -499,22 +446,22 @@ RemoveAllPciDeviceOnBridge (
 **/\r
 EFI_STATUS\r
 DeRegisterPciDevice (\r
-  IN  EFI_HANDLE                     Controller,\r
-  IN  EFI_HANDLE                     Handle\r
+  IN  EFI_HANDLE  Controller,\r
+  IN  EFI_HANDLE  Handle\r
   )\r
 \r
 {\r
-  EFI_PCI_IO_PROTOCOL             *PciIo;\r
-  EFI_STATUS                      Status;\r
-  PCI_IO_DEVICE                   *PciIoDevice;\r
-  PCI_IO_DEVICE                   *Node;\r
-  LIST_ENTRY                      *CurrentLink;\r
-  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;\r
+  EFI_PCI_IO_PROTOCOL              *PciIo;\r
+  EFI_STATUS                       Status;\r
+  PCI_IO_DEVICE                    *PciIoDevice;\r
+  PCI_IO_DEVICE                    *Node;\r
+  LIST_ENTRY                       *CurrentLink;\r
+  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL  *PciRootBridgeIo;\r
 \r
   Status = gBS->OpenProtocol (\r
                   Handle,\r
                   &gEfiPciIoProtocolGuid,\r
-                  (VOID **) &PciIo,\r
+                  (VOID **)&PciIo,\r
                   gPciBusDriverBinding.DriverBindingHandle,\r
                   Controller,\r
                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
@@ -534,12 +481,11 @@ DeRegisterPciDevice (
     //\r
 \r
     if (!IsListEmpty (&PciIoDevice->ChildList)) {\r
-\r
       CurrentLink = PciIoDevice->ChildList.ForwardLink;\r
 \r
       while (CurrentLink != NULL && CurrentLink != &PciIoDevice->ChildList) {\r
-        Node    = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
-        Status  = DeRegisterPciDevice (Controller, Node->Handle);\r
+        Node   = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
+        Status = DeRegisterPciDevice (Controller, Node->Handle);\r
 \r
         if (EFI_ERROR (Status)) {\r
           return Status;\r
@@ -605,22 +551,22 @@ DeRegisterPciDevice (
                         NULL\r
                         );\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
-            &gEfiPciRootBridgeIoProtocolGuid,\r
-            (VOID **) &PciRootBridgeIo,\r
-            gPciBusDriverBinding.DriverBindingHandle,\r
-            Handle,\r
-            EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
-            );\r
+             Controller,\r
+             &gEfiPciRootBridgeIoProtocolGuid,\r
+             (VOID **)&PciRootBridgeIo,\r
+             gPciBusDriverBinding.DriverBindingHandle,\r
+             Handle,\r
+             EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+             );\r
       return Status;\r
     }\r
 \r
@@ -632,7 +578,6 @@ DeRegisterPciDevice (
     PciIoDevice->Registered = FALSE;\r
     PciIoDevice->Handle     = NULL;\r
   } else {\r
-\r
     //\r
     // Handle may be closed before\r
     //\r
@@ -659,11 +604,11 @@ DeRegisterPciDevice (
 **/\r
 EFI_STATUS\r
 StartPciDevicesOnBridge (\r
-  IN EFI_HANDLE                          Controller,\r
-  IN PCI_IO_DEVICE                       *RootBridge,\r
-  IN EFI_DEVICE_PATH_PROTOCOL            *RemainingDevicePath,\r
-  IN OUT UINT8                           *NumberOfChildren,\r
-  IN OUT EFI_HANDLE                      *ChildHandleBuffer\r
+  IN EFI_HANDLE                Controller,\r
+  IN PCI_IO_DEVICE             *RootBridge,\r
+  IN EFI_DEVICE_PATH_PROTOCOL  *RemainingDevicePath,\r
+  IN OUT UINT8                 *NumberOfChildren,\r
+  IN OUT EFI_HANDLE            *ChildHandleBuffer\r
   )\r
 \r
 {\r
@@ -678,14 +623,13 @@ StartPciDevicesOnBridge (
   CurrentLink = RootBridge->ChildList.ForwardLink;\r
 \r
   while (CurrentLink != NULL && CurrentLink != &RootBridge->ChildList) {\r
-\r
     PciIoDevice = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
     if (RemainingDevicePath != NULL) {\r
-\r
       Node.DevPath = RemainingDevicePath;\r
 \r
-      if (Node.Pci->Device != PciIoDevice->DeviceNumber ||\r
-          Node.Pci->Function != PciIoDevice->FunctionNumber) {\r
+      if ((Node.Pci->Device != PciIoDevice->DeviceNumber) ||\r
+          (Node.Pci->Function != PciIoDevice->FunctionNumber))\r
+      {\r
         CurrentLink = CurrentLink->ForwardLink;\r
         continue;\r
       }\r
@@ -707,10 +651,9 @@ StartPciDevicesOnBridge (
                    PciIoDevice,\r
                    NULL\r
                    );\r
-\r
       }\r
 \r
-      if (NumberOfChildren != NULL && ChildHandleBuffer != NULL && PciIoDevice->Registered) {\r
+      if ((NumberOfChildren != NULL) && (ChildHandleBuffer != NULL) && PciIoDevice->Registered) {\r
         ChildHandleBuffer[*NumberOfChildren] = PciIoDevice->Handle;\r
         (*NumberOfChildren)++;\r
       }\r
@@ -726,7 +669,7 @@ StartPciDevicesOnBridge (
       //\r
       // If it is a PPB\r
       //\r
-      if (!IsListEmpty (&PciIoDevice->ChildList)) {\r
+      if (IS_PCI_BRIDGE (&PciIoDevice->Pci)) {\r
         Status = StartPciDevicesOnBridge (\r
                    Controller,\r
                    PciIoDevice,\r
@@ -741,7 +684,7 @@ StartPciDevicesOnBridge (
                              0,\r
                              &Supports\r
                              );\r
-        Supports &= EFI_PCI_DEVICE_ENABLE;\r
+        Supports &= (UINT64)EFI_PCI_DEVICE_ENABLE;\r
         PciIoDevice->PciIo.Attributes (\r
                              &(PciIoDevice->PciIo),\r
                              EfiPciIoAttributeOperationEnable,\r
@@ -751,15 +694,12 @@ StartPciDevicesOnBridge (
 \r
         return Status;\r
       } else {\r
-\r
         //\r
         // Currently, the PCI bus driver only support PCI-PCI bridge\r
         //\r
         return EFI_UNSUPPORTED;\r
       }\r
-\r
     } else {\r
-\r
       //\r
       // If remaining device path is NULL,\r
       // try to enable all the pci devices under this bridge\r
@@ -770,15 +710,14 @@ StartPciDevicesOnBridge (
                    PciIoDevice,\r
                    NULL\r
                    );\r
-\r
       }\r
 \r
-      if (NumberOfChildren != NULL && ChildHandleBuffer != NULL && PciIoDevice->Registered) {\r
+      if ((NumberOfChildren != NULL) && (ChildHandleBuffer != NULL) && PciIoDevice->Registered) {\r
         ChildHandleBuffer[*NumberOfChildren] = PciIoDevice->Handle;\r
         (*NumberOfChildren)++;\r
       }\r
 \r
-      if (!IsListEmpty (&PciIoDevice->ChildList)) {\r
+      if (IS_PCI_BRIDGE (&PciIoDevice->Pci)) {\r
         Status = StartPciDevicesOnBridge (\r
                    Controller,\r
                    PciIoDevice,\r
@@ -793,14 +732,13 @@ StartPciDevicesOnBridge (
                              0,\r
                              &Supports\r
                              );\r
-        Supports &= EFI_PCI_DEVICE_ENABLE;\r
+        Supports &= (UINT64)EFI_PCI_DEVICE_ENABLE;\r
         PciIoDevice->PciIo.Attributes (\r
                              &(PciIoDevice->PciIo),\r
                              EfiPciIoAttributeOperationEnable,\r
                              Supports,\r
                              NULL\r
                              );\r
-\r
       }\r
 \r
       CurrentLink = CurrentLink->ForwardLink;\r
@@ -826,12 +764,12 @@ StartPciDevicesOnBridge (
 **/\r
 EFI_STATUS\r
 StartPciDevices (\r
-  IN EFI_HANDLE                         Controller\r
+  IN EFI_HANDLE  Controller\r
   )\r
 {\r
-  PCI_IO_DEVICE     *RootBridge;\r
-  EFI_HANDLE        ThisHostBridge;\r
-  LIST_ENTRY        *CurrentLink;\r
+  PCI_IO_DEVICE  *RootBridge;\r
+  EFI_HANDLE     ThisHostBridge;\r
+  LIST_ENTRY     *CurrentLink;\r
 \r
   RootBridge = GetRootBridgeByHandle (Controller);\r
   ASSERT (RootBridge != NULL);\r
@@ -840,19 +778,18 @@ StartPciDevices (
   CurrentLink = mPciDevicePool.ForwardLink;\r
 \r
   while (CurrentLink != NULL && CurrentLink != &mPciDevicePool) {\r
-\r
     RootBridge = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
     //\r
     // Locate the right root bridge to start\r
     //\r
     if (RootBridge->PciRootBridgeIo->ParentHandle == ThisHostBridge) {\r
       StartPciDevicesOnBridge (\r
-         RootBridge->Handle,\r
-         RootBridge,\r
-         NULL,\r
-         NULL,\r
-         NULL\r
-         );\r
+        RootBridge->Handle,\r
+        RootBridge,\r
+        NULL,\r
+        NULL,\r
+        NULL\r
+        );\r
     }\r
 \r
     CurrentLink = CurrentLink->ForwardLink;\r
@@ -864,7 +801,7 @@ StartPciDevices (
 /**\r
   Create root bridge device.\r
 \r
-  @param RootBridgeHandle    Specified root bridge hanle.\r
+  @param RootBridgeHandle    Specified root bridge handle.\r
 \r
   @return The crated root bridge device instance, NULL means no\r
           root bridge device instance created.\r
@@ -872,27 +809,27 @@ StartPciDevices (
 **/\r
 PCI_IO_DEVICE *\r
 CreateRootBridge (\r
-  IN EFI_HANDLE                   RootBridgeHandle\r
+  IN EFI_HANDLE  RootBridgeHandle\r
   )\r
 {\r
-  EFI_STATUS                      Status;\r
-  PCI_IO_DEVICE                   *Dev;\r
-  EFI_DEVICE_PATH_PROTOCOL        *ParentDevicePath;\r
-  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;\r
+  EFI_STATUS                       Status;\r
+  PCI_IO_DEVICE                    *Dev;\r
+  EFI_DEVICE_PATH_PROTOCOL         *ParentDevicePath;\r
+  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL  *PciRootBridgeIo;\r
 \r
   Dev = AllocateZeroPool (sizeof (PCI_IO_DEVICE));\r
   if (Dev == NULL) {\r
     return NULL;\r
   }\r
 \r
-  Dev->Signature  = PCI_IO_DEVICE_SIGNATURE;\r
-  Dev->Handle     = RootBridgeHandle;\r
+  Dev->Signature = PCI_IO_DEVICE_SIGNATURE;\r
+  Dev->Handle    = RootBridgeHandle;\r
   InitializeListHead (&Dev->ChildList);\r
 \r
   Status = gBS->OpenProtocol (\r
                   RootBridgeHandle,\r
                   &gEfiDevicePathProtocolGuid,\r
-                  (VOID **) &ParentDevicePath,\r
+                  (VOID **)&ParentDevicePath,\r
                   gPciBusDriverBinding.DriverBindingHandle,\r
                   RootBridgeHandle,\r
                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
@@ -914,7 +851,7 @@ CreateRootBridge (
   Status = gBS->OpenProtocol (\r
                   RootBridgeHandle,\r
                   &gEfiPciRootBridgeIoProtocolGuid,\r
-                  (VOID **) &PciRootBridgeIo,\r
+                  (VOID **)&PciRootBridgeIo,\r
                   gPciBusDriverBinding.DriverBindingHandle,\r
                   RootBridgeHandle,\r
                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
@@ -955,16 +892,15 @@ CreateRootBridge (
 **/\r
 PCI_IO_DEVICE *\r
 GetRootBridgeByHandle (\r
-  EFI_HANDLE RootBridgeHandle\r
+  EFI_HANDLE  RootBridgeHandle\r
   )\r
 {\r
-  PCI_IO_DEVICE   *RootBridgeDev;\r
-  LIST_ENTRY      *CurrentLink;\r
+  PCI_IO_DEVICE  *RootBridgeDev;\r
+  LIST_ENTRY     *CurrentLink;\r
 \r
   CurrentLink = mPciDevicePool.ForwardLink;\r
 \r
   while (CurrentLink != NULL && CurrentLink != &mPciDevicePool) {\r
-\r
     RootBridgeDev = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
     if (RootBridgeDev->Handle == RootBridgeHandle) {\r
       return RootBridgeDev;\r
@@ -977,9 +913,9 @@ GetRootBridgeByHandle (
 }\r
 \r
 /**\r
-  Judege whether Pci device existed.\r
+  Judge whether Pci device existed.\r
 \r
-  @param Bridge       Parent bridege instance.\r
+  @param Bridge       Parent bridge instance.\r
   @param PciIoDevice  Device instance.\r
 \r
   @retval TRUE        Pci device existed.\r
@@ -988,18 +924,16 @@ GetRootBridgeByHandle (
 **/\r
 BOOLEAN\r
 PciDeviceExisted (\r
-  IN PCI_IO_DEVICE    *Bridge,\r
-  IN PCI_IO_DEVICE    *PciIoDevice\r
+  IN PCI_IO_DEVICE  *Bridge,\r
+  IN PCI_IO_DEVICE  *PciIoDevice\r
   )\r
 {\r
-\r
-  PCI_IO_DEVICE   *Temp;\r
-  LIST_ENTRY      *CurrentLink;\r
+  PCI_IO_DEVICE  *Temp;\r
+  LIST_ENTRY     *CurrentLink;\r
 \r
   CurrentLink = Bridge->ChildList.ForwardLink;\r
 \r
   while (CurrentLink != NULL && CurrentLink != &Bridge->ChildList) {\r
-\r
     Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
 \r
     if (Temp == PciIoDevice) {\r
@@ -1019,33 +953,31 @@ PciDeviceExisted (
 }\r
 \r
 /**\r
-  Get the active VGA device on the same segment.\r
+  Get the active VGA device on the specified Host Bridge.\r
 \r
-  @param VgaDevice    PCI IO instance for the VGA device.\r
+  @param HostBridgeHandle    Host Bridge handle.\r
 \r
-  @return The active VGA device on the same segment.\r
+  @return The active VGA device on the specified Host Bridge.\r
 \r
 **/\r
 PCI_IO_DEVICE *\r
-ActiveVGADeviceOnTheSameSegment (\r
-  IN PCI_IO_DEVICE        *VgaDevice\r
+LocateVgaDeviceOnHostBridge (\r
+  IN EFI_HANDLE  HostBridgeHandle\r
   )\r
 {\r
-  LIST_ENTRY      *CurrentLink;\r
-  PCI_IO_DEVICE   *Temp;\r
+  LIST_ENTRY     *CurrentLink;\r
+  PCI_IO_DEVICE  *PciIoDevice;\r
 \r
   CurrentLink = mPciDevicePool.ForwardLink;\r
 \r
   while (CurrentLink != NULL && CurrentLink != &mPciDevicePool) {\r
+    PciIoDevice = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
 \r
-    Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
-\r
-    if (Temp->PciRootBridgeIo->SegmentNumber == VgaDevice->PciRootBridgeIo->SegmentNumber) {\r
-\r
-      Temp = ActiveVGADeviceOnTheRootBridge (Temp);\r
+    if (PciIoDevice->PciRootBridgeIo->ParentHandle == HostBridgeHandle) {\r
+      PciIoDevice = LocateVgaDevice (PciIoDevice);\r
 \r
-      if (Temp != NULL) {\r
-        return Temp;\r
+      if (PciIoDevice != NULL) {\r
+        return PciIoDevice;\r
       }\r
     }\r
 \r
@@ -1056,41 +988,40 @@ ActiveVGADeviceOnTheSameSegment (
 }\r
 \r
 /**\r
-  Get the active VGA device on the root bridge.\r
+  Locate the active VGA device under the bridge.\r
 \r
-  @param RootBridge  PCI IO instance for the root bridge.\r
+  @param Bridge  PCI IO instance for the bridge.\r
 \r
   @return The active VGA device.\r
 \r
 **/\r
 PCI_IO_DEVICE *\r
-ActiveVGADeviceOnTheRootBridge (\r
-  IN PCI_IO_DEVICE        *RootBridge\r
+LocateVgaDevice (\r
+  IN PCI_IO_DEVICE  *Bridge\r
   )\r
 {\r
-  LIST_ENTRY      *CurrentLink;\r
-  PCI_IO_DEVICE   *Temp;\r
-\r
-  CurrentLink = RootBridge->ChildList.ForwardLink;\r
+  LIST_ENTRY     *CurrentLink;\r
+  PCI_IO_DEVICE  *PciIoDevice;\r
 \r
-  while (CurrentLink != NULL && CurrentLink != &RootBridge->ChildList) {\r
+  CurrentLink = Bridge->ChildList.ForwardLink;\r
 \r
-    Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
+  while (CurrentLink != NULL && CurrentLink != &Bridge->ChildList) {\r
+    PciIoDevice = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
 \r
-    if (IS_PCI_VGA(&Temp->Pci) &&\r
-        (Temp->Attributes &\r
-         (EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY |\r
-          EFI_PCI_IO_ATTRIBUTE_VGA_IO     |\r
-          EFI_PCI_IO_ATTRIBUTE_VGA_IO_16)) != 0) {\r
-      return Temp;\r
+    if (IS_PCI_VGA (&PciIoDevice->Pci) &&\r
+        ((PciIoDevice->Attributes &\r
+          (EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY |\r
+           EFI_PCI_IO_ATTRIBUTE_VGA_IO     |\r
+           EFI_PCI_IO_ATTRIBUTE_VGA_IO_16)) != 0))\r
+    {\r
+      return PciIoDevice;\r
     }\r
 \r
-    if (IS_PCI_BRIDGE (&Temp->Pci)) {\r
-\r
-      Temp = ActiveVGADeviceOnTheRootBridge (Temp);\r
+    if (IS_PCI_BRIDGE (&PciIoDevice->Pci)) {\r
+      PciIoDevice = LocateVgaDevice (PciIoDevice);\r
 \r
-      if (Temp != NULL) {\r
-        return Temp;\r
+      if (PciIoDevice != NULL) {\r
+        return PciIoDevice;\r
       }\r
     }\r
 \r
@@ -1099,87 +1030,3 @@ ActiveVGADeviceOnTheRootBridge (
 \r
   return NULL;\r
 }\r
-\r
-\r
-/**\r
-  Get HPC PCI address according to its device path.\r
-\r
-  @param RootBridge           Root bridege Io instance.\r
-  @param RemainingDevicePath  Given searching device path.\r
-  @param PciAddress           Buffer holding searched result.\r
-\r
-  @retval EFI_SUCCESS         PCI address was stored in PciAddress\r
-  @retval EFI_NOT_FOUND       Can not find the specific device path.\r
-\r
-**/\r
-EFI_STATUS\r
-GetHpcPciAddressFromRootBridge (\r
-  IN  PCI_IO_DEVICE                    *RootBridge,\r
-  IN  EFI_DEVICE_PATH_PROTOCOL         *RemainingDevicePath,\r
-  OUT UINT64                           *PciAddress\r
-  )\r
-{\r
-  EFI_DEV_PATH_PTR          Node;\r
-  PCI_IO_DEVICE             *Temp;\r
-  EFI_DEVICE_PATH_PROTOCOL  *CurrentDevicePath;\r
-  LIST_ENTRY                *CurrentLink;\r
-  BOOLEAN                   MisMatch;\r
-\r
-  MisMatch          = FALSE;\r
-\r
-  CurrentDevicePath = RemainingDevicePath;\r
-  Node.DevPath      = CurrentDevicePath;\r
-  Temp              = NULL;\r
-\r
-  while (!IsDevicePathEnd (CurrentDevicePath)) {\r
-\r
-    CurrentLink   = RootBridge->ChildList.ForwardLink;\r
-    Node.DevPath  = CurrentDevicePath;\r
-\r
-    while (CurrentLink != NULL && CurrentLink != &RootBridge->ChildList) {\r
-      Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
-\r
-      if (Node.Pci->Device   == Temp->DeviceNumber &&\r
-          Node.Pci->Function == Temp->FunctionNumber) {\r
-        RootBridge = Temp;\r
-        break;\r
-      }\r
-\r
-      CurrentLink = CurrentLink->ForwardLink;\r
-    }\r
-\r
-    //\r
-    // Check if we find the bridge\r
-    //\r
-    if (CurrentLink == &RootBridge->ChildList) {\r
-\r
-      MisMatch = TRUE;\r
-      break;\r
-\r
-    }\r
-\r
-    CurrentDevicePath = NextDevicePathNode (CurrentDevicePath);\r
-  }\r
-\r
-  if (MisMatch) {\r
-\r
-    CurrentDevicePath = NextDevicePathNode (CurrentDevicePath);\r
-\r
-    if (IsDevicePathEnd (CurrentDevicePath)) {\r
-      *PciAddress = EFI_PCI_ADDRESS (RootBridge->BusNumber, Node.Pci->Device, Node.Pci->Function, 0);\r
-      return EFI_SUCCESS;\r
-    }\r
-\r
-    return EFI_NOT_FOUND;\r
-  }\r
-\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
-}\r
-\r