Revision: 17960
          http://sourceforge.net/p/edk2/code/17960
Author:   lersek
Date:     2015-07-14 12:02:20 +0000 (Tue, 14 Jul 2015)
Log Message:
-----------
OvmfPkg: PciHostBridgeDxe: use private buffer in RootBridgeIoConfiguration()

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 <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <[email protected]>
Regression-tested-by: Gabriel Somlo <[email protected]>
Reviewed-by: Jordan Justen <[email protected]>

Modified Paths:
--------------
    trunk/edk2/OvmfPkg/PciHostBridgeDxe/PciHostBridge.h
    trunk/edk2/OvmfPkg/PciHostBridgeDxe/PciRootBridgeIo.c

Modified: trunk/edk2/OvmfPkg/PciHostBridgeDxe/PciHostBridge.h
===================================================================
--- trunk/edk2/OvmfPkg/PciHostBridgeDxe/PciHostBridge.h 2015-07-14 12:02:15 UTC 
(rev 17959)
+++ trunk/edk2/OvmfPkg/PciHostBridgeDxe/PciHostBridge.h 2015-07-14 12:02:20 UTC 
(rev 17960)
@@ -581,6 +581,13 @@
   RES_STATUS        Status;
 } PCI_RES_NODE;
 
+#pragma pack(1)
+typedef struct {
+  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR SpaceDesc[TypeMax];
+  EFI_ACPI_END_TAG_DESCRIPTOR       EndDesc;
+} RESOURCE_CONFIGURATION;
+#pragma pack()
+
 #define PCI_ROOT_BRIDGE_SIGNATURE  SIGNATURE_32('e', '2', 'p', 'b')
 
 typedef struct {
@@ -609,6 +616,7 @@
   EFI_PCI_ROOT_BRIDGE_DEVICE_PATH         DevicePath;
   EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL         Io;
 
+  RESOURCE_CONFIGURATION                  ConfigBuffer;
 } PCI_ROOT_BRIDGE_INSTANCE;
 
 

Modified: trunk/edk2/OvmfPkg/PciHostBridgeDxe/PciRootBridgeIo.c
===================================================================
--- trunk/edk2/OvmfPkg/PciHostBridgeDxe/PciRootBridgeIo.c       2015-07-14 
12:02:15 UTC (rev 17959)
+++ trunk/edk2/OvmfPkg/PciHostBridgeDxe/PciRootBridgeIo.c       2015-07-14 
12:02:20 UTC (rev 17960)
@@ -1,6 +1,7 @@
 /** @file
   PCI Root Bridge Io Protocol implementation
 
+  Copyright (C) 2015, Red Hat, Inc.
   Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>
 
   This program and the accompanying materials are licensed and made available
@@ -15,19 +16,18 @@
 #include "PciHostBridge.h"
 #include "IoFifo.h"
 
-typedef struct {
-  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR     SpaceDesp[TypeMax];
-  EFI_ACPI_END_TAG_DESCRIPTOR           EndDesp;
-} RESOURCE_CONFIGURATION;
-
-RESOURCE_CONFIGURATION Configuration = {
-  {{0x8A, 0x2B, 1, 0, 0, 0, 0, 0, 0, 0},
-  {0x8A, 0x2B, 0, 0, 0, 32, 0, 0, 0, 0},
-  {0x8A, 0x2B, 0, 0, 6, 32, 0, 0, 0, 0},
-  {0x8A, 0x2B, 0, 0, 0, 64, 0, 0, 0, 0},
-  {0x8A, 0x2B, 0, 0, 6, 64, 0, 0, 0, 0},
-  {0x8A, 0x2B, 2, 0, 0, 0, 0, 0, 0, 0}},
-  {0x79, 0}
+STATIC
+CONST
+RESOURCE_CONFIGURATION mConfigurationTemplate = {
+  {
+    { 0x8A, 0x2B, 1, 0, 0,  0, 0, 0, 0, 0 }, // SpaceDesc[TypeIo]
+    { 0x8A, 0x2B, 0, 0, 0, 32, 0, 0, 0, 0 }, // SpaceDesc[TypeMem32]
+    { 0x8A, 0x2B, 0, 0, 6, 32, 0, 0, 0, 0 }, // SpaceDesc[TypePMem32]
+    { 0x8A, 0x2B, 0, 0, 0, 64, 0, 0, 0, 0 }, // SpaceDesc[TypeMem64]
+    { 0x8A, 0x2B, 0, 0, 6, 64, 0, 0, 0, 0 }, // SpaceDesc[TypePMem64]
+    { 0x8A, 0x2B, 2, 0, 0,  0, 0, 0, 0, 0 }  // SpaceDesc[TypeBus]
+  },
+  { 0x79, 0 }                                // EndDesc
 };
 
 //
@@ -2607,12 +2607,14 @@
   UINTN                                 Index;
 
   PrivateData = DRIVER_INSTANCE_FROM_PCI_ROOT_BRIDGE_IO_THIS (This);
+  CopyMem (&PrivateData->ConfigBuffer, &mConfigurationTemplate,
+    sizeof mConfigurationTemplate);
 
   for (Index = 0; Index < TypeMax; Index++) {
     if (PrivateData->ResAllocNode[Index].Status == ResAllocated) {
       EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc;
 
-      Desc = &Configuration.SpaceDesp[Index];
+      Desc = &PrivateData->ConfigBuffer.SpaceDesc[Index];
       Desc->AddrRangeMin = PrivateData->ResAllocNode[Index].Base;
       Desc->AddrRangeMax = PrivateData->ResAllocNode[Index].Base +
                            PrivateData->ResAllocNode[Index].Length - 1;
@@ -2620,7 +2622,7 @@
     }
   }
 
-  *Resources = &Configuration;
+  *Resources = &PrivateData->ConfigBuffer;
   return EFI_SUCCESS;
 }
 


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to