]> git.proxmox.com Git - mirror_edk2.git/blobdiff - DuetPkg/PciBusNoEnumerationDxe/PciDeviceSupport.c
DuetPkg: Remove DuetPkg
[mirror_edk2.git] / DuetPkg / PciBusNoEnumerationDxe / PciDeviceSupport.c
diff --git a/DuetPkg/PciBusNoEnumerationDxe/PciDeviceSupport.c b/DuetPkg/PciBusNoEnumerationDxe/PciDeviceSupport.c
deleted file mode 100644 (file)
index bae266d..0000000
+++ /dev/null
@@ -1,973 +0,0 @@
-/*++\r
-\r
-Copyright (c) 2005 - 2006, 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
-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
-\r
-Module Name:\r
-\r
-  PciDeviceSupport.c\r
-  \r
-Abstract:\r
-\r
-  This file provides routine to support Pci device node manipulation\r
-\r
-Revision History\r
-\r
---*/\r
-\r
-#include "PciBus.h"\r
-\r
-//\r
-// This device structure is serviced as a header.\r
-// Its Next field points to the first root bridge device node\r
-//\r
-LIST_ENTRY  gPciDevicePool;\r
-\r
-EFI_STATUS\r
-InitializePciDevicePool (\r
-  VOID\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Initialize the gPciDevicePool\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
-{\r
-  InitializeListHead (&gPciDevicePool);\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-InsertRootBridge (\r
-  IN PCI_IO_DEVICE *RootBridge\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Insert a root bridge into PCI device pool\r
-\r
-Arguments:\r
-\r
-  RootBridge    - A pointer to the PCI_IO_DEVICE.\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
-{\r
-  InsertTailList (&gPciDevicePool, &(RootBridge->Link));\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-InsertPciDevice (\r
-  PCI_IO_DEVICE *Bridge,\r
-  PCI_IO_DEVICE *PciDeviceNode\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  This function is used to insert a PCI device node under\r
-  a bridge\r
-\r
-Arguments:\r
-  Bridge        - A pointer to the PCI_IO_DEVICE.\r
-  PciDeviceNode - A pointer to the PCI_IO_DEVICE.\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
-\r
-{\r
-\r
-  InsertTailList (&Bridge->ChildList, &(PciDeviceNode->Link));\r
-  PciDeviceNode->Parent = Bridge;\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-DestroyRootBridge (\r
-  IN PCI_IO_DEVICE *RootBridge\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  \r
-Arguments:\r
-\r
-  RootBridge   - A pointer to the PCI_IO_DEVICE.\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
-{\r
-  DestroyPciDeviceTree (RootBridge);\r
-\r
-  gBS->FreePool (RootBridge);\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-DestroyPciDeviceTree (\r
-  IN PCI_IO_DEVICE *Bridge\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Destroy all the pci device node under the bridge.\r
-  Bridge itself is not included.\r
-\r
-Arguments:\r
-\r
-  Bridge   - A pointer to the PCI_IO_DEVICE.\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
-{\r
-  LIST_ENTRY  *CurrentLink;\r
-  PCI_IO_DEVICE   *Temp;\r
-\r
-  while (!IsListEmpty (&Bridge->ChildList)) {\r
-\r
-    CurrentLink = Bridge->ChildList.ForwardLink;\r
-\r
-    //\r
-    // Remove this node from the linked list\r
-    //\r
-    RemoveEntryList (CurrentLink);\r
-\r
-    Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
-\r
-    if (IS_PCI_BRIDGE (&(Temp->Pci))) {\r
-      DestroyPciDeviceTree (Temp);\r
-    }\r
-    gBS->FreePool (Temp);\r
-  }\r
-  \r
-  return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-DestroyRootBridgeByHandle (\r
-  EFI_HANDLE Controller\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Destroy all device nodes under the root bridge\r
-  specified by Controller. \r
-  The root bridge itself is also included.\r
-\r
-Arguments:\r
-\r
-  Controller   - An efi handle.\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
-{\r
-\r
-  LIST_ENTRY  *CurrentLink;\r
-  PCI_IO_DEVICE   *Temp;\r
-\r
-  CurrentLink = gPciDevicePool.ForwardLink;\r
-\r
-  while (CurrentLink && CurrentLink != &gPciDevicePool) {\r
-    Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
-\r
-    if (Temp->Handle == Controller) {\r
-\r
-      RemoveEntryList (CurrentLink);\r
-\r
-      DestroyPciDeviceTree (Temp);\r
-\r
-      gBS->FreePool(Temp);\r
-\r
-      return EFI_SUCCESS;\r
-    }\r
-\r
-    CurrentLink = CurrentLink->ForwardLink;\r
-  }\r
-\r
-  return EFI_NOT_FOUND;\r
-}\r
-\r
-EFI_STATUS\r
-RegisterPciDevice (\r
-  IN  EFI_HANDLE                     Controller,\r
-  IN  PCI_IO_DEVICE                  *PciIoDevice,\r
-  OUT EFI_HANDLE                     *Handle OPTIONAL\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  This function registers the PCI IO device. It creates a handle for this PCI IO device \r
-  (if the handle does not exist), attaches appropriate protocols onto the handle, does\r
-  necessary initialization, and sets up parent/child relationship with its bus controller.\r
-\r
-Arguments:\r
-\r
-  Controller    - An EFI handle for the PCI bus controller.\r
-  PciIoDevice   - A PCI_IO_DEVICE pointer to the PCI IO device to be registered.\r
-  Handle        - A pointer to hold the EFI handle for the PCI IO device.\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS   - The PCI device is successfully registered.\r
-  Others        - An error occurred when registering the PCI device.\r
-\r
---*/\r
-{\r
-  EFI_STATUS          Status;\r
-  UINT8               PciExpressCapRegOffset;\r
-\r
-  //\r
-  // Install the pciio protocol, device path protocol and \r
-  // Bus Specific Driver Override Protocol\r
-  //\r
-\r
-  if (PciIoDevice->BusOverride) {\r
-    Status = gBS->InstallMultipleProtocolInterfaces (\r
-                  &PciIoDevice->Handle,             \r
-                  &gEfiDevicePathProtocolGuid,\r
-                  PciIoDevice->DevicePath,\r
-                  &gEfiPciIoProtocolGuid,\r
-                  &PciIoDevice->PciIo,\r
-                  &gEfiBusSpecificDriverOverrideProtocolGuid,\r
-                  &PciIoDevice->PciDriverOverride,\r
-                  NULL\r
-                  );\r
-  } else {\r
-    Status = gBS->InstallMultipleProtocolInterfaces (\r
-                  &PciIoDevice->Handle,             \r
-                  &gEfiDevicePathProtocolGuid,\r
-                  PciIoDevice->DevicePath,\r
-                  &gEfiPciIoProtocolGuid,\r
-                  &PciIoDevice->PciIo,\r
-                  NULL\r
-                  );\r
-  }\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  } else {\r
-    Status = gBS->OpenProtocol (\r
-                    Controller,           \r
-                    &gEfiPciRootBridgeIoProtocolGuid, \r
-                    (VOID **)&(PciIoDevice->PciRootBridgeIo),\r
-                    gPciBusDriverBinding.DriverBindingHandle,\r
-                    PciIoDevice->Handle,   \r
-                    EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
-                    );\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\r
-  }\r
-\r
-  if (Handle != NULL) {\r
-    *Handle = PciIoDevice->Handle;\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
-    DEBUG ((EFI_D_ERROR, "PciExp - %x (B-%x, D-%x, F-%x)\n", PciIoDevice->IsPciExp, PciIoDevice->BusNumber, PciIoDevice->DeviceNumber, PciIoDevice->FunctionNumber));\r
-  }\r
-  \r
-  //\r
-  // Indicate the pci device is registered\r
-  //\r
-  PciIoDevice->Registered = TRUE;\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
-EFI_STATUS\r
-DeRegisterPciDevice (\r
-  IN  EFI_HANDLE                     Controller,\r
-  IN  EFI_HANDLE                     Handle\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  This function is used to de-register the PCI device from the EFI,\r
-  That includes un-installing PciIo protocol from the specified PCI \r
-  device handle.\r
-\r
-Arguments:\r
-\r
-  Controller   - An efi handle.\r
-  Handle       - An efi handle.\r
-\r
-Returns:\r
-\r
-  None\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
-\r
-  Status = gBS->OpenProtocol (\r
-                  Handle,\r
-                  &gEfiPciIoProtocolGuid,\r
-                  (VOID **) &PciIo,\r
-                  gPciBusDriverBinding.DriverBindingHandle,\r
-                  Controller,\r
-                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                  );\r
-  if (!EFI_ERROR (Status)) {\r
-    PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (PciIo);\r
-\r
-    //\r
-    // If it is already de-registered\r
-    //\r
-    if (!PciIoDevice->Registered) {\r
-      return EFI_SUCCESS;\r
-    }\r
-\r
-    //\r
-    // If it is PPB, first de-register its children\r
-    //\r
-\r
-    if (IS_PCI_BRIDGE (&(PciIoDevice->Pci))) {\r
-\r
-      CurrentLink = PciIoDevice->ChildList.ForwardLink;\r
-\r
-      while (CurrentLink && CurrentLink != &PciIoDevice->ChildList) {\r
-        Node    = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
-        Status  = DeRegisterPciDevice (Controller, Node->Handle);\r
-\r
-        if (EFI_ERROR (Status)) {\r
-          return Status;\r
-        }\r
-\r
-        CurrentLink = CurrentLink->ForwardLink;\r
-      }\r
-    }\r
-\r
-    //\r
-    // First disconnect this device\r
-    //\r
-//    PciIoDevice->PciIo.Attributes(&(PciIoDevice->PciIo),\r
-//                                    EfiPciIoAttributeOperationDisable,\r
-//                                    EFI_PCI_DEVICE_ENABLE,\r
-//                                    NULL\r
-//                                    );\r
-       \r
-    //\r
-    // Close the child handle\r
-    //\r
-    Status = gBS->CloseProtocol (\r
-                    Controller,\r
-                    &gEfiPciRootBridgeIoProtocolGuid,\r
-                    gPciBusDriverBinding.DriverBindingHandle,\r
-                    Handle\r
-                    );\r
-\r
-    //\r
-    // Un-install the device path protocol and pci io protocol\r
-    //\r
-    if (PciIoDevice->BusOverride) {\r
-      Status = gBS->UninstallMultipleProtocolInterfaces (\r
-                      Handle,\r
-                      &gEfiDevicePathProtocolGuid,\r
-                      PciIoDevice->DevicePath,\r
-                      &gEfiPciIoProtocolGuid,\r
-                      &PciIoDevice->PciIo,\r
-                      &gEfiBusSpecificDriverOverrideProtocolGuid,\r
-                      &PciIoDevice->PciDriverOverride,\r
-                      NULL\r
-                      );\r
-    } else {\r
-      Status = gBS->UninstallMultipleProtocolInterfaces (\r
-                      Handle,\r
-                      &gEfiDevicePathProtocolGuid,\r
-                      PciIoDevice->DevicePath,\r
-                      &gEfiPciIoProtocolGuid,\r
-                      &PciIoDevice->PciIo,\r
-                      NULL\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
-      return Status;\r
-    }\r
-    \r
-    //\r
-    // The Device Driver should disable this device after disconnect\r
-    // so the Pci Bus driver will not touch this device any more.\r
-    // Restore the register field to the original value\r
-    //\r
-    PciIoDevice->Registered = FALSE;\r
-    PciIoDevice->Handle     = NULL;\r
-  } else {\r
-\r
-    //\r
-    // Handle may be closed before\r
-    //\r
-    return EFI_SUCCESS;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-EnableBridgeAttributes (\r
-  IN PCI_IO_DEVICE                       *PciIoDevice\r
-  )\r
-{\r
-  PCI_TYPE01                PciData;\r
-\r
-  //\r
-  // NOTE: We should not set EFI_PCI_DEVICE_ENABLE for a bridge\r
-  //       directly, because some legacy BIOS will NOT assign\r
-  //       IO or Memory resource for a bridge who has no child\r
-  //       device. So we add check IO or Memory here.\r
-  //\r
-\r
-  PciIoDevice->PciIo.Pci.Read (\r
-                           &PciIoDevice->PciIo,\r
-                           EfiPciIoWidthUint8,\r
-                           0,\r
-                           sizeof (PciData),\r
-                           &PciData\r
-                           );\r
-\r
-  if ((((PciData.Bridge.IoBase & 0xF) == 0) &&\r
-        (PciData.Bridge.IoBase != 0 || PciData.Bridge.IoLimit != 0)) ||\r
-      (((PciData.Bridge.IoBase & 0xF) == 1) &&\r
-        ((PciData.Bridge.IoBase & 0xF0) != 0 || (PciData.Bridge.IoLimit & 0xF0) != 0 || PciData.Bridge.IoBaseUpper16 != 0 || PciData.Bridge.IoLimitUpper16 != 0))) {\r
-    PciIoDevice->PciIo.Attributes(\r
-                         &(PciIoDevice->PciIo),\r
-                         EfiPciIoAttributeOperationEnable,\r
-                         (EFI_PCI_IO_ATTRIBUTE_IO | EFI_PCI_IO_ATTRIBUTE_BUS_MASTER),\r
-                         NULL\r
-                         );\r
-  }\r
-  if ((PciData.Bridge.MemoryBase & 0xFFF0) != 0 || (PciData.Bridge.MemoryLimit & 0xFFF0) != 0) {\r
-    PciIoDevice->PciIo.Attributes(\r
-                         &(PciIoDevice->PciIo),\r
-                         EfiPciIoAttributeOperationEnable,\r
-                         (EFI_PCI_IO_ATTRIBUTE_MEMORY | EFI_PCI_IO_ATTRIBUTE_BUS_MASTER),\r
-                         NULL\r
-                         );\r
-  }\r
-  if ((((PciData.Bridge.PrefetchableMemoryBase & 0xF) == 0) &&\r
-        (PciData.Bridge.PrefetchableMemoryBase != 0 || PciData.Bridge.PrefetchableMemoryLimit != 0)) ||\r
-      (((PciData.Bridge.PrefetchableMemoryBase & 0xF) == 1) &&\r
-        ((PciData.Bridge.PrefetchableMemoryBase & 0xFFF0) != 0 || (PciData.Bridge.PrefetchableMemoryLimit & 0xFFF0) != 0 || PciData.Bridge.PrefetchableBaseUpper32 != 0 || PciData.Bridge.PrefetchableLimitUpper32 != 0))) {\r
-    PciIoDevice->PciIo.Attributes(\r
-                         &(PciIoDevice->PciIo),\r
-                         EfiPciIoAttributeOperationEnable,\r
-                         (EFI_PCI_IO_ATTRIBUTE_MEMORY | EFI_PCI_IO_ATTRIBUTE_BUS_MASTER),\r
-                         NULL\r
-                         );\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS \r
-StartPciDevicesOnBridge (\r
-  IN EFI_HANDLE                          Controller,\r
-  IN PCI_IO_DEVICE                       *RootBridge,\r
-  IN EFI_DEVICE_PATH_PROTOCOL            *RemainingDevicePath \r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Start to manage the PCI device on specified the root bridge or PCI-PCI Bridge\r
-\r
-Arguments:\r
-\r
-  Controller          - An efi handle.\r
-  RootBridge          - A pointer to the PCI_IO_DEVICE.\r
-  RemainingDevicePath - A pointer to the EFI_DEVICE_PATH_PROTOCOL.\r
-  NumberOfChildren    - Children number.\r
-  ChildHandleBuffer   - A pointer to the child handle buffer.\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
-{\r
-  PCI_IO_DEVICE             *Temp;\r
-  PCI_IO_DEVICE             *PciIoDevice;\r
-  EFI_DEV_PATH_PTR          Node;\r
-  EFI_DEVICE_PATH_PROTOCOL  *CurrentDevicePath;\r
-  EFI_STATUS                Status;\r
-  LIST_ENTRY            *CurrentLink;\r
-\r
-  CurrentLink = RootBridge->ChildList.ForwardLink;\r
-\r
-  while (CurrentLink && CurrentLink != &RootBridge->ChildList) {\r
-\r
-    Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
-    if (RemainingDevicePath != NULL) {\r
-\r
-      Node.DevPath = RemainingDevicePath;\r
-\r
-      if (Node.Pci->Device != Temp->DeviceNumber || \r
-          Node.Pci->Function != Temp->FunctionNumber) {\r
-        CurrentLink = CurrentLink->ForwardLink;\r
-        continue;\r
-      }\r
-\r
-      //\r
-      // Check if the device has been assigned with required resource\r
-      //\r
-      if (!Temp->Allocated) {\r
-        return EFI_NOT_READY;\r
-      }\r
-      \r
-      //\r
-      // Check if the current node has been registered before\r
-      // If it is not, register it\r
-      //\r
-      if (!Temp->Registered) {\r
-        PciIoDevice = Temp;\r
-\r
-        Status = RegisterPciDevice (\r
-                  Controller,\r
-                  PciIoDevice,\r
-                  NULL\r
-                  );\r
-\r
-      }\r
-      \r
-      //\r
-      // Get the next device path\r
-      //\r
-      CurrentDevicePath = NextDevicePathNode (RemainingDevicePath);\r
-      if (IsDevicePathEnd (CurrentDevicePath)) {\r
-        return EFI_SUCCESS;\r
-      }\r
-  \r
-      //\r
-      // If it is a PPB\r
-      //\r
-      if (IS_PCI_BRIDGE (&(Temp->Pci))) {\r
-        Status = StartPciDevicesOnBridge (\r
-                  Controller,\r
-                  Temp,\r
-                  CurrentDevicePath\r
-                  );\r
-        EnableBridgeAttributes (Temp);\r
-\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
-      //\r
-\r
-      if (!Temp->Registered && Temp->Allocated) {\r
-\r
-        PciIoDevice = Temp;\r
-\r
-        Status = RegisterPciDevice (\r
-                  Controller,\r
-                  PciIoDevice,\r
-                  NULL\r
-                  );\r
-\r
-      }\r
-\r
-      if (IS_PCI_BRIDGE (&(Temp->Pci))) {\r
-        Status = StartPciDevicesOnBridge ( \r
-                   Controller,\r
-                   Temp,\r
-                   RemainingDevicePath\r
-                   );\r
-        EnableBridgeAttributes (Temp);\r
-      }\r
-\r
-      CurrentLink = CurrentLink->ForwardLink;\r
-      continue;\r
-    }\r
-  }\r
-\r
-  return EFI_NOT_FOUND;\r
-}\r
-\r
-EFI_STATUS\r
-StartPciDevices (\r
-  IN EFI_HANDLE                         Controller,\r
-  IN EFI_DEVICE_PATH_PROTOCOL           *RemainingDevicePath\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Start to manage the PCI device according to RemainingDevicePath\r
-  If RemainingDevicePath == NULL, the PCI bus driver will start \r
-  to manage all the PCI devices it found previously\r
-\r
-Arguments:\r
-  Controller          - An efi handle.\r
-  RemainingDevicePath - A pointer to the EFI_DEVICE_PATH_PROTOCOL.\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
-{\r
-  EFI_DEV_PATH_PTR  Node;\r
-  PCI_IO_DEVICE     *RootBridge;\r
-  LIST_ENTRY    *CurrentLink;\r
-\r
-  if (RemainingDevicePath != NULL) {\r
-\r
-    //\r
-    // Check if the RemainingDevicePath is valid\r
-    //\r
-    Node.DevPath = RemainingDevicePath;\r
-    if (Node.DevPath->Type != HARDWARE_DEVICE_PATH ||\r
-        Node.DevPath->SubType != HW_PCI_DP         ||\r
-        DevicePathNodeLength (Node.DevPath) != sizeof (PCI_DEVICE_PATH)\r
-        ) {\r
-      return EFI_UNSUPPORTED;\r
-    }\r
-  }\r
-\r
-  CurrentLink = gPciDevicePool.ForwardLink;\r
-\r
-  while (CurrentLink && CurrentLink != &gPciDevicePool) {\r
-\r
-    RootBridge = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
-    //\r
-    // Locate the right root bridge to start\r
-    //\r
-    if (RootBridge->Handle == Controller) {\r
-      StartPciDevicesOnBridge (\r
-        Controller,\r
-        RootBridge,\r
-        RemainingDevicePath\r
-        );\r
-    }\r
-\r
-    CurrentLink = CurrentLink->ForwardLink;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-PCI_IO_DEVICE *\r
-CreateRootBridge (\r
-  IN EFI_HANDLE RootBridgeHandle\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-\r
-Arguments:\r
-  RootBridgeHandle   - An efi handle.\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
-{\r
-\r
-  EFI_STATUS                      Status;\r
-  PCI_IO_DEVICE                   *Dev;\r
-\r
-  Dev = NULL;\r
-  Status = gBS->AllocatePool (\r
-                  EfiBootServicesData,\r
-                  sizeof (PCI_IO_DEVICE),\r
-                  (VOID **) &Dev\r
-                  );\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    return NULL;\r
-  }\r
-\r
-  ZeroMem (Dev, sizeof (PCI_IO_DEVICE));\r
-  Dev->Signature  = PCI_IO_DEVICE_SIGNATURE;\r
-  Dev->Handle     = RootBridgeHandle;\r
-  InitializeListHead (&Dev->ChildList);\r
-\r
-  return Dev;\r
-}\r
-\r
-PCI_IO_DEVICE *\r
-GetRootBridgeByHandle (\r
-  EFI_HANDLE RootBridgeHandle\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-\r
-Arguments:\r
-\r
-  RootBridgeHandle    - An efi handle.\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
-{\r
-  PCI_IO_DEVICE   *RootBridgeDev;\r
-  LIST_ENTRY  *CurrentLink;\r
-\r
-  CurrentLink = gPciDevicePool.ForwardLink;\r
-\r
-  while (CurrentLink && CurrentLink != &gPciDevicePool) {\r
-\r
-    RootBridgeDev = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
-    if (RootBridgeDev->Handle == RootBridgeHandle) {\r
-      return RootBridgeDev;\r
-    }\r
-\r
-    CurrentLink = CurrentLink->ForwardLink;\r
-  }\r
-\r
-  return NULL;\r
-}\r
-\r
-BOOLEAN\r
-RootBridgeExisted (\r
-  IN EFI_HANDLE RootBridgeHandle\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  This function searches if RootBridgeHandle has already existed\r
-  in current device pool.\r
-\r
-  If so, it means the given root bridge has been already enumerated.\r
-\r
-Arguments:\r
-\r
-  RootBridgeHandle   - An efi handle.\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
-{\r
-  PCI_IO_DEVICE *Bridge;\r
-\r
-  Bridge = GetRootBridgeByHandle (RootBridgeHandle);\r
-\r
-  if (Bridge != NULL) {\r
-    return TRUE;\r
-  }\r
-\r
-  return FALSE;\r
-}\r
-\r
-BOOLEAN\r
-PciDeviceExisted (\r
-  IN PCI_IO_DEVICE    *Bridge,\r
-  IN PCI_IO_DEVICE    *PciIoDevice\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-  \r
-Arguments:\r
-\r
-  Bridge       - A pointer to the PCI_IO_DEVICE.\r
-  PciIoDevice  - A pointer to the PCI_IO_DEVICE.\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
-{\r
-\r
-  PCI_IO_DEVICE   *Temp;\r
-  LIST_ENTRY  *CurrentLink;\r
-\r
-  CurrentLink = Bridge->ChildList.ForwardLink;\r
-\r
-  while (CurrentLink && CurrentLink != &Bridge->ChildList) {\r
-\r
-    Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
-\r
-    if (Temp == PciIoDevice) {\r
-      return TRUE;\r
-    }\r
-\r
-    if (!IsListEmpty (&Temp->ChildList)) {\r
-      if (PciDeviceExisted (Temp, PciIoDevice)) {\r
-        return TRUE;\r
-      }\r
-    }\r
-\r
-    CurrentLink = CurrentLink->ForwardLink;\r
-  }\r
-\r
-  return FALSE;\r
-}\r
-\r
-PCI_IO_DEVICE *\r
-ActiveVGADeviceOnTheSameSegment (\r
-  IN PCI_IO_DEVICE        *VgaDevice\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-  VgaDevice    - A pointer to the PCI_IO_DEVICE.\r
-  \r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
-{\r
-  LIST_ENTRY  *CurrentLink;\r
-  PCI_IO_DEVICE   *Temp;\r
-\r
-  CurrentLink = gPciDevicePool.ForwardLink;\r
-\r
-  while (CurrentLink && CurrentLink != &gPciDevicePool) {\r
-\r
-    Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink);\r
-\r
-    if (Temp->PciRootBridgeIo->SegmentNumber == VgaDevice->PciRootBridgeIo->SegmentNumber) {\r
-\r
-      Temp = ActiveVGADeviceOnTheRootBridge (Temp);\r
-\r
-      if (Temp != NULL) {\r
-        return Temp;\r
-      }\r
-    }\r
-\r
-    CurrentLink = CurrentLink->ForwardLink;\r
-  }\r
-\r
-  return NULL;\r
-}\r
-\r
-PCI_IO_DEVICE *\r
-ActiveVGADeviceOnTheRootBridge (\r
-  IN PCI_IO_DEVICE        *RootBridge\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-  RootBridge    - A pointer to the PCI_IO_DEVICE.\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
-{\r
-  LIST_ENTRY  *CurrentLink;\r
-  PCI_IO_DEVICE   *Temp;\r
-\r
-  CurrentLink = RootBridge->ChildList.ForwardLink;\r
-\r
-  while (CurrentLink && CurrentLink != &RootBridge->ChildList) {\r
-\r
-    Temp = 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))) {\r
-      return Temp;\r
-    }\r
-\r
-    if (IS_PCI_BRIDGE (&Temp->Pci)) {\r
-\r
-      Temp = ActiveVGADeviceOnTheRootBridge (Temp);\r
-\r
-      if (Temp != NULL) {\r
-        return Temp;\r
-      }\r
-    }\r
-\r
-    CurrentLink = CurrentLink->ForwardLink;\r
-  }\r
-\r
-  return NULL;\r
-}\r