]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/IncompatiblePciDeviceSupportDxe: Refine the configuration
authorMin Xu <min.m.xu@intel.com>
Thu, 24 Feb 2022 13:49:41 +0000 (21:49 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sat, 2 Apr 2022 10:09:47 +0000 (10:09 +0000)
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429

MMIO64_PREFERENCE is a fixed length data structure which contains one
AddressSpaceDesc and one EndDesc. This patch removes MMIO64_PREFERENCE
and create AddressSpaceDesc and EndDesc respectively. This change
gives the chance to add more AddressSpaceDesc when CheckDevice is
called.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.c

index 8730874613f807753217c6db4fa10687489f74a9..f5c03bdf6dd6c4c71a7ad587a6bcbf24cecc4c6a 100644 (file)
@@ -9,6 +9,8 @@
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 **/\r
 \r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
 #include <IndustryStandard/Acpi10.h>\r
 #include <IndustryStandard/Pci22.h>\r
 \r
@@ -40,49 +42,38 @@ STATIC EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL
 // This structure is interpreted by the UpdatePciInfo() function in the edk2\r
 // PCI Bus UEFI_DRIVER.\r
 //\r
-#pragma pack (1)\r
-typedef struct {\r
-  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR    AddressSpaceDesc;\r
-  EFI_ACPI_END_TAG_DESCRIPTOR          EndDesc;\r
-} MMIO64_PREFERENCE;\r
-#pragma pack ()\r
-\r
-STATIC CONST MMIO64_PREFERENCE  mConfiguration = {\r
-  //\r
-  // AddressSpaceDesc\r
-  //\r
-  {\r
-    ACPI_ADDRESS_SPACE_DESCRIPTOR,                 // Desc\r
-    (UINT16)(                                      // Len\r
+// This structure looks like:\r
+// AddressDesc-1 + AddressDesc-2 + ... + AddressDesc-n + EndDesc\r
+//\r
+STATIC CONST EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR  mMmio64Configuration = {\r
+  ACPI_ADDRESS_SPACE_DESCRIPTOR,                   // Desc\r
+  (UINT16)(                                        // Len\r
                                                    sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) -\r
                                                    OFFSET_OF (\r
                                                      EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR,\r
                                                      ResType\r
                                                      )\r
                                                    ),\r
-    ACPI_ADDRESS_SPACE_TYPE_MEM,                   // ResType\r
-    0,                                             // GenFlag\r
-    0,                                             // SpecificFlag\r
-    64,                                            // AddrSpaceGranularity:\r
+  ACPI_ADDRESS_SPACE_TYPE_MEM,                     // ResType\r
+  0,                                               // GenFlag\r
+  0,                                               // SpecificFlag\r
+  64,                                              // AddrSpaceGranularity:\r
                                                    //   aperture selection hint\r
                                                    //   for BAR allocation\r
-    0,                                             // AddrRangeMin\r
-    0,                                             // AddrRangeMax:\r
+  0,                                               // AddrRangeMin\r
+  0,                                               // AddrRangeMax:\r
                                                    //   no special alignment\r
                                                    //   for affected BARs\r
-    MAX_UINT64,                                    // AddrTranslationOffset:\r
+  MAX_UINT64,                                      // AddrTranslationOffset:\r
                                                    //   hint covers all\r
                                                    //   eligible BARs\r
-    0                                              // AddrLen:\r
+  0                                                // AddrLen:\r
                                                    //   use probed BAR size\r
-  },\r
-  //\r
-  // EndDesc\r
-  //\r
-  {\r
-    ACPI_END_TAG_DESCRIPTOR,                       // Desc\r
-    0                                              // Checksum: to be ignored\r
-  }\r
+};\r
+\r
+STATIC CONST EFI_ACPI_END_TAG_DESCRIPTOR  mEndDesc = {\r
+  ACPI_END_TAG_DESCRIPTOR,                         // Desc\r
+  0                                                // Checksum: to be ignored\r
 };\r
 \r
 //\r
@@ -203,6 +194,8 @@ CheckDevice (
   )\r
 {\r
   mCheckDeviceCalled = TRUE;\r
+  UINTN  Length;\r
+  UINT8  *Ptr;\r
 \r
   //\r
   // Unlike the general description of this protocol member suggests, there is\r
@@ -232,7 +225,10 @@ CheckDevice (
   // the edk2 PCI Bus UEFI_DRIVER actually handles error codes; see the\r
   // UpdatePciInfo() function.\r
   //\r
-  *Configuration = AllocateCopyPool (sizeof mConfiguration, &mConfiguration);\r
+  Length = sizeof mMmio64Configuration + sizeof mEndDesc;\r
+\r
+  *Configuration = AllocateZeroPool (Length);\r
+\r
   if (*Configuration == NULL) {\r
     DEBUG ((\r
       DEBUG_WARN,\r
@@ -245,6 +241,12 @@ CheckDevice (
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
+  Ptr = (UINT8 *)(UINTN)*Configuration;\r
+  CopyMem (Ptr, &mMmio64Configuration, sizeof mMmio64Configuration);\r
+  Length = sizeof mMmio64Configuration;\r
+\r
+  CopyMem (Ptr + Length, &mEndDesc, sizeof mEndDesc);\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r