]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
UefiPayloadPkg: UefiPayload retrieve PCI root bridge from Guid Hob
[mirror_edk2.git] / UefiPayloadPkg / Library / PciHostBridgeLib / PciHostBridgeLib.c
index 512c3127cc5631d8761a4b5e9fec2e79515af24a..a0d7cdc306fc13f5510443668af7a0112166a3c9 100644 (file)
@@ -2,7 +2,7 @@
   Library instance of PciHostBridgeLib library class for coreboot.\r
 \r
   Copyright (C) 2016, Red Hat, Inc.\r
-  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2016 - 2021, Intel Corporation. All rights reserved.<BR>\r
 \r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
@@ -19,6 +19,7 @@
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/PciHostBridgeLib.h>\r
 #include <Library/PciLib.h>\r
+#include <Library/HobLib.h>\r
 \r
 #include "PciHostBridge.h"\r
 \r
@@ -48,7 +49,6 @@ CB_PCI_ROOT_BRIDGE_DEVICE_PATH mRootBridgeDevicePathTemplate = {
   }\r
 };\r
 \r
-\r
 /**\r
   Initialize a PCI_ROOT_BRIDGE structure.\r
 \r
@@ -145,6 +145,27 @@ InitRootBridge (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Initialize DevicePath for a PCI_ROOT_BRIDGE.\r
+  @param[in] HID               HID for device path\r
+  @param[in] UID               UID for device path\r
+\r
+  @retval A pointer to the new created device patch.\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+CreateRootBridgeDevicePath (\r
+  IN     UINT32                   HID,\r
+  IN     UINT32                   UID\r
+)\r
+{\r
+  CB_PCI_ROOT_BRIDGE_DEVICE_PATH *DevicePath;\r
+  DevicePath = AllocateCopyPool (sizeof (mRootBridgeDevicePathTemplate),\r
+                                 &mRootBridgeDevicePathTemplate);\r
+  ASSERT (DevicePath != NULL);\r
+  DevicePath->AcpiDevicePath.HID = HID;\r
+  DevicePath->AcpiDevicePath.UID = UID;\r
+  return (EFI_DEVICE_PATH_PROTOCOL *)DevicePath;\r
+}\r
 \r
 /**\r
   Return all the root bridge instances in an array.\r
@@ -161,10 +182,30 @@ PciHostBridgeGetRootBridges (
   UINTN *Count\r
 )\r
 {\r
+  UNIVERSAL_PAYLOAD_PCI_ROOT_BRIDGES  *PciRootBridgeInfo;\r
+  EFI_HOB_GUID_TYPE                   *GuidHob;\r
+  UNIVERSAL_PAYLOAD_GENERIC_HEADER    *GenericHeader;\r
+  //\r
+  // Find Universal Payload PCI Root Bridge Info hob\r
+  //\r
+  GuidHob = GetFirstGuidHob (&gUniversalPayloadPciRootBridgeInfoGuid);\r
+  if (GuidHob != NULL) {\r
+    GenericHeader = (UNIVERSAL_PAYLOAD_GENERIC_HEADER *) GET_GUID_HOB_DATA (GuidHob);\r
+    if ((sizeof(UNIVERSAL_PAYLOAD_GENERIC_HEADER) <= GET_GUID_HOB_DATA_SIZE (GuidHob)) && (GenericHeader->Length <= GET_GUID_HOB_DATA_SIZE (GuidHob))) {\r
+      if ((GenericHeader->Revision == UNIVERSAL_PAYLOAD_PCI_ROOT_BRIDGES_REVISION) && (GenericHeader->Length >= sizeof (UNIVERSAL_PAYLOAD_PCI_ROOT_BRIDGES))) {\r
+        //\r
+        // UNIVERSAL_PAYLOAD_PCI_ROOT_BRIDGES structure is used when Revision equals to UNIVERSAL_PAYLOAD_PCI_ROOT_BRIDGES_REVISION\r
+        //\r
+        PciRootBridgeInfo = (UNIVERSAL_PAYLOAD_PCI_ROOT_BRIDGES *) GET_GUID_HOB_DATA (GuidHob);\r
+        if (PciRootBridgeInfo->Count <= (GET_GUID_HOB_DATA_SIZE (GuidHob) - sizeof(UNIVERSAL_PAYLOAD_PCI_ROOT_BRIDGES)) / sizeof(UNIVERSAL_PAYLOAD_PCI_ROOT_BRIDGE)) {\r
+          return RetrieveRootBridgeInfoFromHob (PciRootBridgeInfo, Count);\r
+        }\r
+      }\r
+    }\r
+  }\r
   return ScanForRootBridges (Count);\r
 }\r
 \r
-\r
 /**\r
   Free the root bridge instances array returned from\r
   PciHostBridgeGetRootBridges().\r