]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg: PciHostBridgeDxe: use private buffer in RootBridgeIoConfiguration()
authorLaszlo Ersek <lersek@redhat.com>
Tue, 14 Jul 2015 12:02:20 +0000 (12:02 +0000)
committerlersek <lersek@Edk2>
Tue, 14 Jul 2015 12:02:20 +0000 (12:02 +0000)
On output, the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.Configuration() function
produces a pointer to a buffer of ACPI 2.0 resource descriptors:

  Resources  A pointer to the ACPI 2.0 resource descriptors that describe
             the current configuration of this PCI root bridge. The
             storage for the ACPI 2.0 resource descriptors is allocated by
             this function. The caller must treat the return buffer as
             read-only data, and the buffer must not be freed by the
             caller.

PciHostBridgeDxe currently provides this buffer in a structure with static
storage duration. If multiple root bridges existed in parallel, the
pointers returned by their Configuration() methods would point to the same
static storage. A later Configuration() call would overwrite the storage
pointed out by an earlier Configuration() call (which was possibly made
for a different, but still alive, root bridge.)

Fix this problem by embedding the configuration buffer in
PCI_ROOT_BRIDGE_INSTANCE.

While we're at it, correct some typos (Desp -> Desc), spell out a missing
pack(1) pragma, and improve formatting.

Cc: Jordan Justen <jordan.l.justen@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Regression-tested-by: Gabriel Somlo <somlo@cmu.edu>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17960 6f19259b-4bc3-4df7-8a09-765794883524

OvmfPkg/PciHostBridgeDxe/PciHostBridge.h
OvmfPkg/PciHostBridgeDxe/PciRootBridgeIo.c

index 05b8cecf80d4b88b9ed0058903f92f1640e7af4a..d2c28bcd20b8f6f291bce769ceffc8a85eb71e4f 100644 (file)
@@ -581,6 +581,13 @@ typedef struct {
   RES_STATUS        Status;\r
 } PCI_RES_NODE;\r
 \r
+#pragma pack(1)\r
+typedef struct {\r
+  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR SpaceDesc[TypeMax];\r
+  EFI_ACPI_END_TAG_DESCRIPTOR       EndDesc;\r
+} RESOURCE_CONFIGURATION;\r
+#pragma pack()\r
+\r
 #define PCI_ROOT_BRIDGE_SIGNATURE  SIGNATURE_32('e', '2', 'p', 'b')\r
 \r
 typedef struct {\r
@@ -609,6 +616,7 @@ typedef struct {
   EFI_PCI_ROOT_BRIDGE_DEVICE_PATH         DevicePath;\r
   EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL         Io;\r
 \r
+  RESOURCE_CONFIGURATION                  ConfigBuffer;\r
 } PCI_ROOT_BRIDGE_INSTANCE;\r
 \r
 \r
index 5de28b18eb03914ba9d3b1e41709b32b97fe5cd7..c61fd1d7db6ba6290a4e47206a64560ca38385a0 100644 (file)
@@ -1,6 +1,7 @@
 /** @file\r
   PCI Root Bridge Io Protocol implementation\r
 \r
+  Copyright (C) 2015, Red Hat, Inc.\r
   Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials are licensed and made available\r
 #include "PciHostBridge.h"\r
 #include "IoFifo.h"\r
 \r
-typedef struct {\r
-  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR     SpaceDesp[TypeMax];\r
-  EFI_ACPI_END_TAG_DESCRIPTOR           EndDesp;\r
-} RESOURCE_CONFIGURATION;\r
-\r
-RESOURCE_CONFIGURATION Configuration = {\r
-  {{0x8A, 0x2B, 1, 0, 0, 0, 0, 0, 0, 0},\r
-  {0x8A, 0x2B, 0, 0, 0, 32, 0, 0, 0, 0},\r
-  {0x8A, 0x2B, 0, 0, 6, 32, 0, 0, 0, 0},\r
-  {0x8A, 0x2B, 0, 0, 0, 64, 0, 0, 0, 0},\r
-  {0x8A, 0x2B, 0, 0, 6, 64, 0, 0, 0, 0},\r
-  {0x8A, 0x2B, 2, 0, 0, 0, 0, 0, 0, 0}},\r
-  {0x79, 0}\r
+STATIC\r
+CONST\r
+RESOURCE_CONFIGURATION mConfigurationTemplate = {\r
+  {\r
+    { 0x8A, 0x2B, 1, 0, 0,  0, 0, 0, 0, 0 }, // SpaceDesc[TypeIo]\r
+    { 0x8A, 0x2B, 0, 0, 0, 32, 0, 0, 0, 0 }, // SpaceDesc[TypeMem32]\r
+    { 0x8A, 0x2B, 0, 0, 6, 32, 0, 0, 0, 0 }, // SpaceDesc[TypePMem32]\r
+    { 0x8A, 0x2B, 0, 0, 0, 64, 0, 0, 0, 0 }, // SpaceDesc[TypeMem64]\r
+    { 0x8A, 0x2B, 0, 0, 6, 64, 0, 0, 0, 0 }, // SpaceDesc[TypePMem64]\r
+    { 0x8A, 0x2B, 2, 0, 0,  0, 0, 0, 0, 0 }  // SpaceDesc[TypeBus]\r
+  },\r
+  { 0x79, 0 }                                // EndDesc\r
 };\r
 \r
 //\r
@@ -2607,12 +2607,14 @@ RootBridgeIoConfiguration (
   UINTN                                 Index;\r
 \r
   PrivateData = DRIVER_INSTANCE_FROM_PCI_ROOT_BRIDGE_IO_THIS (This);\r
+  CopyMem (&PrivateData->ConfigBuffer, &mConfigurationTemplate,\r
+    sizeof mConfigurationTemplate);\r
 \r
   for (Index = 0; Index < TypeMax; Index++) {\r
     if (PrivateData->ResAllocNode[Index].Status == ResAllocated) {\r
       EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc;\r
 \r
-      Desc = &Configuration.SpaceDesp[Index];\r
+      Desc = &PrivateData->ConfigBuffer.SpaceDesc[Index];\r
       Desc->AddrRangeMin = PrivateData->ResAllocNode[Index].Base;\r
       Desc->AddrRangeMax = PrivateData->ResAllocNode[Index].Base +\r
                            PrivateData->ResAllocNode[Index].Length - 1;\r
@@ -2620,7 +2622,7 @@ RootBridgeIoConfiguration (
     }\r
   }\r
 \r
-  *Resources = &Configuration;\r
+  *Resources = &PrivateData->ConfigBuffer;\r
   return EFI_SUCCESS;\r
 }\r
 \r