diff mbox

[edk2,4/4] OvmfPkg: add PciHotPlugInitDxe

Message ID 1467335453-25967-5-git-send-email-lersek@redhat.com
State Superseded
Headers show

Commit Message

Laszlo Ersek July 1, 2016, 1:10 a.m. UTC
After IncompatiblePciDeviceSupportDxe, this is another small driver /
protocol implementation that tweaks the behavior of the PCI bus driver in
edk2.

The protocol is specified in the Platform Init Spec v1.4a, Volume 5,
Chapter 12.6 "PCI Hot Plug PCI Initialization Protocol". This
implementation steers the PCI bus driver to reserve the following
resources ("padding") for each PCI bus, in addition to the BARs of the
devices on that PCI bus:
- 2MB of 64-bit non-prefetchable MMIO aperture,
- 512B of IO port space.

The goal is to reserve room for devices hot-plugged at runtime even if the
bridge receiving the device is empty at boot time.

The 2MB MMIO size is inspired by SeaBIOS. The 512B IO port size is
actually only 1/8th of the PCI spec mandated reservation, but the
specified size of 4096 has proved wasteful (given the limited size of our
IO port space -- see commit bba734ab4c7c). Especially on Q35, where every
PCIe root port and downstream port qualifies as a separate bridge (capable
of accepting a single device).

Test results for this patch:
- regardless of our request for 64-bit MMIO reservation, it is downgraded
  to 32-bit,
- although we request 512B alignment for the IO port space reservation,
  the next upstream bridge rounds it up to 4096B.

Cc: "Johnson, Brian J." <bjohnson@sgi.com>
Cc: Alex Williamson <alex.williamson@redhat.com>
Cc: Andrew Fish <afish@apple.com>
Cc: Feng Tian <feng.tian@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Marcel Apfelbaum <marcel@redhat.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Suggested-by: Andrew Fish <afish@apple.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>

---
 OvmfPkg/OvmfPkgIa32.dsc                      |   1 +
 OvmfPkg/OvmfPkgIa32X64.dsc                   |   1 +
 OvmfPkg/OvmfPkgX64.dsc                       |   1 +
 OvmfPkg/OvmfPkgIa32.fdf                      |   1 +
 OvmfPkg/OvmfPkgIa32X64.fdf                   |   1 +
 OvmfPkg/OvmfPkgX64.fdf                       |   1 +
 OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf |  46 +++
 OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.c   | 352 ++++++++++++++++++++
 8 files changed, 404 insertions(+)

-- 
1.8.3.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Comments

Laszlo Ersek July 1, 2016, 12:54 p.m. UTC | #1
On 07/01/16 03:10, Laszlo Ersek wrote:

> +STATIC CONST RESOURCE_PADDING mPadding = {

> +  //

> +  // MmioPadding

> +  //

> +  {

> +    ACPI_ADDRESS_SPACE_DESCRIPTOR,                 // Desc

> +    (UINT16)(                                      // Len

> +      sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) -

> +      OFFSET_OF (

> +        EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR,

> +        ResType

> +        )

> +      ),

> +    ACPI_ADDRESS_SPACE_TYPE_MEM, // ResType

> +    0,                           // GenFlag:

> +                                 //   ignored

> +    0,                           // SpecificFlag:

> +                                 //   non-prefetchable

> +    64,                          // AddrSpaceGranularity:

> +                                 //   reserve 64-bit aperture

> +    0,                           // AddrRangeMin:

> +                                 //   ignored

> +    SIZE_2MB,                    // AddrRangeMax:

> +                                 //   align at 2MB


This

> +    0,                           // AddrTranslationOffset:

> +                                 //   ignored

> +    SIZE_2MB                     // AddrLen:

> +                                 //   2MB padding

> +  },

> +

> +  //

> +  // IoPadding

> +  //

> +  {

> +    ACPI_ADDRESS_SPACE_DESCRIPTOR,                 // Desc

> +    (UINT16)(                                      // Len

> +      sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) -

> +      OFFSET_OF (

> +        EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR,

> +        ResType

> +        )

> +      ),

> +    ACPI_ADDRESS_SPACE_TYPE_IO,// ResType

> +    0,                          // GenFlag:

> +                                //   ignored

> +    0,                          // SpecificFlag:

> +                                //   ignored

> +    0,                          // AddrSpaceGranularity:

> +                                //   ignored

> +    0,                          // AddrRangeMin:

> +                                //   ignored

> +    512,                        // AddrRangeMax:

> +                                //   align at 512 IO ports


and this are incorrect. I missed in Table 8 that these values must be 2^n-1.

I'll update this for v2, but I'll wait for some comments first.

Thanks
Laszlo
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Laszlo Ersek July 7, 2016, 5:59 p.m. UTC | #2
On 07/07/16 19:36, Jordan Justen wrote:
> On 2016-06-30 18:10:53, Laszlo Ersek wrote:

>> +EFI_STATUS

>> +EFIAPI

>> +DriverInitialize (

>> +  IN EFI_HANDLE       ImageHandle,

>> +  IN EFI_SYSTEM_TABLE *SystemTable

>> +  )

>> +{

>> +  EFI_STATUS Status;

>> +

>> +  if (!FeaturePcdGet (PcdPciBusHotplugDeviceSupport)) {

>> +    DEBUG ((EFI_D_WARN,

>> +      "%a: this driver should not have been built into the firmware\n",

>> +      gEfiCallerBaseName));

>> +    return EFI_UNSUPPORTED;

>> +  }

> 

> It looks like we'll always have this PCD as true, and always include

> the driver. I don't have a concern about that. (Do you know of a

> reason that we might need to make it conditional?)


No, I don't expect any changes to PcdPciBusHotplugDeviceSupport. It's
just a warning for the case if we happen to change the PCD nonetheless.

In that case though, the warning is not high priority enough to prevent
the firmware from proceeding. Hence no ASSERT() / CpuDeadLoop(). It's
just a message for the maintainers to clean up their DSC.

> What if we instead add this to PlatformDxe, and either drop, or turn

> the PcdPciBusHotplugDeviceSupport check into an ASSERT?


I'm perfectly fine with dropping the PcdPciBusHotplugDeviceSupport check
-- I was a bit torn about adding it in the first place, but I wanted to
solicit your feedback about it, and including the check seemed the best
way to do that :)

About including the functionality in PlatformDxe: I disagree with that
idea. I realize this is a (standardized) PCI Bus platform tweak, but we
already have IncompatiblePciDeviceSupportDxe separately, which is the
exact same kind of (standardized) PCI Bus platform tweak. (And that
driver in turn exists separately because the example driver
"MdeModulePkg/Bus/Pci/IncompatiblePciDeviceSupportDxe" exists separately
as well.)

More importantly, to me PlatformDxe is primarily a HII-centered driver.
I would not like to dilute that "HII focus" in it. I have had to look at
PlatformDxe several times in the past few months -- you surely recall
those iPXE HII debugging sessions on the list -- for refreshing my
(sadly not extensive enough) HII knowlege. Turning PlatformDxe into a
grab-bag of platform tweaks would harm the driver, in my opinion.

(I think about PlatformPei a bit differently -- it *is* a grab-bag of
platform tweaks, but its scope is much more focused. It does low-level
chipset, CPU, and memory setup.)

If you would like to avoid yet another (standardized) PCI Bus driver
tweak, I guess I could fuse this driver with
IncompatiblePciDeviceSupportDxe. If you agree with that: do you have a
good name for the unified driver?

Thanks
Laszlo
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Laszlo Ersek July 8, 2016, 12:18 a.m. UTC | #3
On 07/08/16 01:38, Jordan Justen wrote:
> On 2016-07-07 15:55:34, Ni, Ruiyu wrote:
>> I vote for separate driver:) it's more clean and easy to maintain.
>>
> 
> (sigh) I guess that is the nature of EDK II. Big, but modular! :) It's
> not like this decision is going to make OVMF compete with seabios on
> size or speed,

That's never been my goal, and the edk2 development model (even the PI /
UEFI standards development model) are pretty unsuitable for that.

PI and UEFI are about binary compatibility between proprietary, closed
source modules, from independent vendors. Therefore interfaces that
would normally be "internal" and always subject to change in a
self-contained (hopefully even open source) code base, are exposed and
standardized in PI and UEFI for interoperability -- hence they ossify.

Some of the best examples for this relate precisely to the PCI Bus
driver. While we discuss, and struggle with, the separation between the
PCI bus driver, the PCI host bridge driver (with the many phases and
back-and-forth reporting), the EFI_PCI_HOT_PLUG_INIT_PROTOCOL, the
EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL, the SeaBIOS developers dig
down and modify five lines of code in the SeaBIOS tree, in the guts of
their PCI enumeration algorithm. They can construct new communication
channels, modify function prototypes, reorganize the algorithms, and so
on. I can submit an ECR, at best. (I guess.)

I'm not complaining, but modularity on this level has a price. See
"Documentation/stable_api_nonsense.txt" in the kernel tree :)

> so:
> 
> Acked-by: Jordan Justen <jordan.l.justen@intel.com>

Thanks. I'll drop the PcdPciBusHotplugDeviceSupport check as discussed
before.

> Laszlo, I disagree with you about PlatformDxe. I don't think it is an
> HII driver, but rather a dumping ground for any DXE phase platform
> code that we choose.

Noted. For the next similar driver, if I can't find a separate example
driver in MdeModulePkg, I'll attempt to squeeze the new code into
PlatformDxe. (I'm already getting cold feet from the thought. :))

Thanks,
Laszlo

>>
>>> 在 2016年7月8日,上午1:59,Laszlo Ersek <lersek@redhat.com> 写道:
>>>
>>>> On 07/07/16 19:36, Jordan Justen wrote:
>>>>> On 2016-06-30 18:10:53, Laszlo Ersek wrote:
>>>>> +EFI_STATUS
>>>>> +EFIAPI
>>>>> +DriverInitialize (
>>>>> +  IN EFI_HANDLE       ImageHandle,
>>>>> +  IN EFI_SYSTEM_TABLE *SystemTable
>>>>> +  )
>>>>> +{
>>>>> +  EFI_STATUS Status;
>>>>> +
>>>>> +  if (!FeaturePcdGet (PcdPciBusHotplugDeviceSupport)) {
>>>>> +    DEBUG ((EFI_D_WARN,
>>>>> +      "%a: this driver should not have been built into the firmware\n",
>>>>> +      gEfiCallerBaseName));
>>>>> +    return EFI_UNSUPPORTED;
>>>>> +  }
>>>>
>>>> It looks like we'll always have this PCD as true, and always include
>>>> the driver. I don't have a concern about that. (Do you know of a
>>>> reason that we might need to make it conditional?)
>>>
>>> No, I don't expect any changes to PcdPciBusHotplugDeviceSupport. It's
>>> just a warning for the case if we happen to change the PCD nonetheless.
>>>
>>> In that case though, the warning is not high priority enough to prevent
>>> the firmware from proceeding. Hence no ASSERT() / CpuDeadLoop(). It's
>>> just a message for the maintainers to clean up their DSC.
>>>
>>>> What if we instead add this to PlatformDxe, and either drop, or turn
>>>> the PcdPciBusHotplugDeviceSupport check into an ASSERT?
>>>
>>> I'm perfectly fine with dropping the PcdPciBusHotplugDeviceSupport check
>>> -- I was a bit torn about adding it in the first place, but I wanted to
>>> solicit your feedback about it, and including the check seemed the best
>>> way to do that :)
>>>
>>> About including the functionality in PlatformDxe: I disagree with that
>>> idea. I realize this is a (standardized) PCI Bus platform tweak, but we
>>> already have IncompatiblePciDeviceSupportDxe separately, which is the
>>> exact same kind of (standardized) PCI Bus platform tweak. (And that
>>> driver in turn exists separately because the example driver
>>> "MdeModulePkg/Bus/Pci/IncompatiblePciDeviceSupportDxe" exists separately
>>> as well.)
>>>
>>> More importantly, to me PlatformDxe is primarily a HII-centered driver.
>>> I would not like to dilute that "HII focus" in it. I have had to look at
>>> PlatformDxe several times in the past few months -- you surely recall
>>> those iPXE HII debugging sessions on the list -- for refreshing my
>>> (sadly not extensive enough) HII knowlege. Turning PlatformDxe into a
>>> grab-bag of platform tweaks would harm the driver, in my opinion.
>>>
>>> (I think about PlatformPei a bit differently -- it *is* a grab-bag of
>>> platform tweaks, but its scope is much more focused. It does low-level
>>> chipset, CPU, and memory setup.)
>>>
>>> If you would like to avoid yet another (standardized) PCI Bus driver
>>> tweak, I guess I could fuse this driver with
>>> IncompatiblePciDeviceSupportDxe. If you agree with that: do you have a
>>> good name for the unified driver?
>>>
>>> Thanks
>>> Laszlo
>>> _______________________________________________
>>> edk2-devel mailing list
>>> edk2-devel@lists.01.org
>>> https://lists.01.org/mailman/listinfo/edk2-devel
diff mbox

Patch

diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index 6d074641bede..805650059e96 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -552,6 +552,7 @@  [Components]
   UefiCpuPkg/CpuDxe/CpuDxe.inf
   PcAtChipsetPkg/8254TimerDxe/8254Timer.inf
   OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf
+  OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf
   MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf {
     <LibraryClasses>
       PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index 25fcb38aaf84..7615ee96dff2 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -561,6 +561,7 @@  [Components.X64]
   UefiCpuPkg/CpuDxe/CpuDxe.inf
   PcAtChipsetPkg/8254TimerDxe/8254Timer.inf
   OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf
+  OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf
   MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf {
     <LibraryClasses>
       PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index cb7ccf79618d..7f8a5c25a5c0 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -559,6 +559,7 @@  [Components]
   UefiCpuPkg/CpuDxe/CpuDxe.inf
   PcAtChipsetPkg/8254TimerDxe/8254Timer.inf
   OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf
+  OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf
   MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf {
     <LibraryClasses>
       PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
diff --git a/OvmfPkg/OvmfPkgIa32.fdf b/OvmfPkg/OvmfPkgIa32.fdf
index 59a4024ff026..386fd6bc1301 100644
--- a/OvmfPkg/OvmfPkgIa32.fdf
+++ b/OvmfPkg/OvmfPkgIa32.fdf
@@ -208,6 +208,7 @@  [FV.DXEFV]
 INF  UefiCpuPkg/CpuDxe/CpuDxe.inf
 INF  PcAtChipsetPkg/8254TimerDxe/8254Timer.inf
 INF  OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf
+INF  OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf
 INF  MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf
 INF  MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf
 INF  PcAtChipsetPkg/KbcResetDxe/Reset.inf
diff --git a/OvmfPkg/OvmfPkgIa32X64.fdf b/OvmfPkg/OvmfPkgIa32X64.fdf
index c6167a4176af..3a777a3dba88 100644
--- a/OvmfPkg/OvmfPkgIa32X64.fdf
+++ b/OvmfPkg/OvmfPkgIa32X64.fdf
@@ -208,6 +208,7 @@  [FV.DXEFV]
 INF  UefiCpuPkg/CpuDxe/CpuDxe.inf
 INF  PcAtChipsetPkg/8254TimerDxe/8254Timer.inf
 INF  OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf
+INF  OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf
 INF  MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf
 INF  MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf
 INF  PcAtChipsetPkg/KbcResetDxe/Reset.inf
diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf
index 30b0c2ba3fc8..de08cf966f50 100644
--- a/OvmfPkg/OvmfPkgX64.fdf
+++ b/OvmfPkg/OvmfPkgX64.fdf
@@ -208,6 +208,7 @@  [FV.DXEFV]
 INF  UefiCpuPkg/CpuDxe/CpuDxe.inf
 INF  PcAtChipsetPkg/8254TimerDxe/8254Timer.inf
 INF  OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf
+INF  OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf
 INF  MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf
 INF  MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf
 INF  PcAtChipsetPkg/KbcResetDxe/Reset.inf
diff --git a/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf b/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf
new file mode 100644
index 000000000000..0444e54c8610
--- /dev/null
+++ b/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf
@@ -0,0 +1,46 @@ 
+## @file
+# This driver implements EFI_PCI_HOT_PLUG_INIT_PROTOCOL, providing the PCI bus
+# driver with resource padding information, for PCIe hotplug purposes.
+#
+# Copyright (C) 2016, Red Hat, Inc.
+#
+# This program and the accompanying materials are licensed and made available
+# under the terms and conditions of the BSD License which accompanies this
+# distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+# WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = PciHotPlugInitDxe
+  FILE_GUID                      = 11A6EDF6-A9BE-426D-A6CC-B22FE51D9224
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  ENTRY_POINT                    = DriverInitialize
+
+[Sources]
+  PciHotPlugInit.c
+
+[Packages]
+  MdeModulePkg/MdeModulePkg.dec
+  MdePkg/MdePkg.dec
+
+[LibraryClasses]
+  DebugLib
+  DevicePathLib
+  MemoryAllocationLib
+  PcdLib
+  UefiBootServicesTableLib
+  UefiDriverEntryPoint
+
+[Protocols]
+  gEfiPciHotPlugInitProtocolGuid ## SOMETIMES_PRODUCES
+
+[FeaturePcd]
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPciBusHotplugDeviceSupport ## CONSUMES
+
+[Depex]
+  TRUE
diff --git a/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.c b/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.c
new file mode 100644
index 000000000000..cf025c29639f
--- /dev/null
+++ b/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.c
@@ -0,0 +1,352 @@ 
+/** @file
+  This driver implements EFI_PCI_HOT_PLUG_INIT_PROTOCOL, providing the PCI bus
+  driver with resource padding information, for PCIe hotplug purposes.
+
+  Copyright (C) 2016, Red Hat, Inc.
+
+  This program and the accompanying materials are licensed and made available
+  under the terms and conditions of the BSD License which accompanies this
+  distribution. The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+  WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+
+#include <IndustryStandard/Acpi10.h>
+
+#include <Library/DebugLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+#include <Protocol/PciHotPlugInit.h>
+#include <Protocol/PciRootBridgeIo.h>
+
+//
+// The protocol interface this driver produces.
+//
+// Refer to 12.6 "PCI Hot Plug PCI Initialization Protocol" in the Platform
+// Init 1.4a Spec, Volume 5.
+//
+STATIC EFI_PCI_HOT_PLUG_INIT_PROTOCOL mPciHotPlugInit;
+
+
+//
+// Resource padding template for the GetResourcePadding() protocol member
+// function.
+//
+// Refer to Table 8 "ACPI 2.0 & 3.0 QWORD Address Space Descriptor Usage" in
+// the Platform Init 1.4a Spec, Volume 5.
+//
+// This structure is interpreted by the ApplyResourcePadding() function in the
+// edk2 PCI Bus UEFI_DRIVER.
+//
+#pragma pack (1)
+typedef struct {
+  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR MmioPadding;
+  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR IoPadding;
+  EFI_ACPI_END_TAG_DESCRIPTOR       EndDesc;
+} RESOURCE_PADDING;
+#pragma pack ()
+
+STATIC CONST RESOURCE_PADDING mPadding = {
+  //
+  // MmioPadding
+  //
+  {
+    ACPI_ADDRESS_SPACE_DESCRIPTOR,                 // Desc
+    (UINT16)(                                      // Len
+      sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) -
+      OFFSET_OF (
+        EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR,
+        ResType
+        )
+      ),
+    ACPI_ADDRESS_SPACE_TYPE_MEM, // ResType
+    0,                           // GenFlag:
+                                 //   ignored
+    0,                           // SpecificFlag:
+                                 //   non-prefetchable
+    64,                          // AddrSpaceGranularity:
+                                 //   reserve 64-bit aperture
+    0,                           // AddrRangeMin:
+                                 //   ignored
+    SIZE_2MB,                    // AddrRangeMax:
+                                 //   align at 2MB
+    0,                           // AddrTranslationOffset:
+                                 //   ignored
+    SIZE_2MB                     // AddrLen:
+                                 //   2MB padding
+  },
+
+  //
+  // IoPadding
+  //
+  {
+    ACPI_ADDRESS_SPACE_DESCRIPTOR,                 // Desc
+    (UINT16)(                                      // Len
+      sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) -
+      OFFSET_OF (
+        EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR,
+        ResType
+        )
+      ),
+    ACPI_ADDRESS_SPACE_TYPE_IO,// ResType
+    0,                          // GenFlag:
+                                //   ignored
+    0,                          // SpecificFlag:
+                                //   ignored
+    0,                          // AddrSpaceGranularity:
+                                //   ignored
+    0,                          // AddrRangeMin:
+                                //   ignored
+    512,                        // AddrRangeMax:
+                                //   align at 512 IO ports
+    0,                          // AddrTranslationOffset:
+                                //   ignored
+    512                         // AddrLen:
+                                //   512 IO ports
+  },
+
+  //
+  // EndDesc
+  //
+  {
+    ACPI_END_TAG_DESCRIPTOR, // Desc
+    0                        // Checksum: to be ignored
+  }
+};
+
+
+/**
+  Returns a list of root Hot Plug Controllers (HPCs) that require
+  initialization during the boot process.
+
+  This procedure returns a list of root HPCs. The PCI bus driver must
+  initialize  these controllers during the boot process. The PCI bus driver may
+  or may not be  able to detect these HPCs. If the platform includes a
+  PCI-to-CardBus bridge, it  can be included in this list if it requires
+  initialization.  The HpcList must be  self consistent. An HPC cannot control
+  any of its parent buses. Only one HPC can  control a PCI bus. Because this
+  list includes only root HPCs, no HPC in the list  can be a child of another
+  HPC. This policy must be enforced by the  EFI_PCI_HOT_PLUG_INIT_PROTOCOL.
+  The PCI bus driver may not check for such  invalid conditions.  The callee
+  allocates the buffer HpcList
+
+  @param[in]  This       Pointer to the EFI_PCI_HOT_PLUG_INIT_PROTOCOL
+                         instance.
+  @param[out] HpcCount   The number of root HPCs that were returned.
+  @param[out] HpcList    The list of root HPCs. HpcCount defines the number of
+                         elements in this list.
+
+  @retval EFI_SUCCESS             HpcList was returned.
+  @retval EFI_OUT_OF_RESOURCES    HpcList was not returned due to insufficient
+                                  resources.
+  @retval EFI_INVALID_PARAMETER   HpcCount is NULL or HpcList is NULL.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+GetRootHpcList (
+  IN  EFI_PCI_HOT_PLUG_INIT_PROTOCOL *This,
+  OUT UINTN                          *HpcCount,
+  OUT EFI_HPC_LOCATION               **HpcList
+  )
+{
+  if (HpcCount == NULL || HpcList == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  //
+  // There are no top-level (i.e., un-enumerable) hot-plug controllers in QEMU
+  // that would require special initialization.
+  //
+  *HpcCount = 0;
+  *HpcList = NULL;
+  return EFI_SUCCESS;
+}
+
+
+/**
+  Initializes one root Hot Plug Controller (HPC). This process may causes
+  initialization of its subordinate buses.
+
+  This function initializes the specified HPC. At the end of initialization,
+  the hot-plug slots or sockets (controlled by this HPC) are powered and are
+  connected to the bus. All the necessary registers in the HPC are set up. For
+  a Standard (PCI) Hot Plug Controller (SHPC), the registers that must be set
+  up are defined in the PCI Standard Hot Plug Controller and Subsystem
+  Specification.
+
+  @param[in]  This            Pointer to the EFI_PCI_HOT_PLUG_INIT_PROTOCOL
+                              instance.
+  @param[in]  HpcDevicePath   The device path to the HPC that is being
+                              initialized.
+  @param[in]  HpcPciAddress   The address of the HPC function on the PCI bus.
+  @param[in]  Event           The event that should be signaled when the HPC
+                              initialization is complete.  Set to NULL if the
+                              caller wants to wait until the entire
+                              initialization  process is complete.
+  @param[out] HpcState        The state of the HPC hardware. The state is
+                              EFI_HPC_STATE_INITIALIZED or
+                              EFI_HPC_STATE_ENABLED.
+
+  @retval EFI_SUCCESS             If Event is NULL, the specific HPC was
+                                  successfully initialized. If Event is not
+                                  NULL, Event will be  signaled at a later time
+                                  when initialization is complete.
+  @retval EFI_UNSUPPORTED         This instance of
+                                  EFI_PCI_HOT_PLUG_INIT_PROTOCOL does not
+                                  support the specified HPC.
+  @retval EFI_OUT_OF_RESOURCES    Initialization failed due to insufficient
+                                  resources.
+  @retval EFI_INVALID_PARAMETER   HpcState is NULL.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+InitializeRootHpc (
+  IN  EFI_PCI_HOT_PLUG_INIT_PROTOCOL *This,
+  IN  EFI_DEVICE_PATH_PROTOCOL       *HpcDevicePath,
+  IN  UINT64                         HpcPciAddress,
+  IN  EFI_EVENT                      Event, OPTIONAL
+  OUT EFI_HPC_STATE                  *HpcState
+  )
+{
+  //
+  // This function should never be called, due to the information returned by
+  // GetRootHpcList().
+  //
+  ASSERT (FALSE);
+
+  if (HpcState == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+  return EFI_UNSUPPORTED;
+}
+
+
+/**
+  Returns the resource padding that is required by the PCI bus that is
+  controlled by the specified Hot Plug Controller (HPC).
+
+  This function returns the resource padding that is required by the PCI bus
+  that is controlled by the specified HPC. This member function is called for
+  all the  root HPCs and nonroot HPCs that are detected by the PCI bus
+  enumerator. This  function will be called before PCI resource allocation is
+  completed. This function  must be called after all the root HPCs, with the
+  possible exception of a  PCI-to-CardBus bridge, have completed
+  initialization.
+
+  @param[in]  This            Pointer to the EFI_PCI_HOT_PLUG_INIT_PROTOCOL
+                              instance.
+  @param[in]  HpcDevicePath   The device path to the HPC.
+  @param[in]  HpcPciAddress   The address of the HPC function on the PCI bus.
+  @param[in]  HpcState        The state of the HPC hardware.
+  @param[out] Padding         The amount of resource padding that is required
+                              by the PCI bus under the control of the specified
+                              HPC.
+  @param[out] Attributes      Describes how padding is accounted for. The
+                              padding is returned in the form of ACPI 2.0
+                              resource descriptors.
+
+  @retval EFI_SUCCESS             The resource padding was successfully
+                                  returned.
+  @retval EFI_UNSUPPORTED         This instance of the
+                                  EFI_PCI_HOT_PLUG_INIT_PROTOCOL does not
+                                  support the specified HPC.
+  @retval EFI_NOT_READY           This function was called before HPC
+                                  initialization is complete.
+  @retval EFI_INVALID_PARAMETER   HpcState or Padding or Attributes is NULL.
+  @retval EFI_OUT_OF_RESOURCES    ACPI 2.0 resource descriptors for Padding
+                                  cannot be allocated due to insufficient
+                                  resources.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+GetResourcePadding (
+  IN  EFI_PCI_HOT_PLUG_INIT_PROTOCOL *This,
+  IN  EFI_DEVICE_PATH_PROTOCOL       *HpcDevicePath,
+  IN  UINT64                         HpcPciAddress,
+  OUT EFI_HPC_STATE                  *HpcState,
+  OUT VOID                           **Padding,
+  OUT EFI_HPC_PADDING_ATTRIBUTES     *Attributes
+  )
+{
+  DEBUG_CODE (
+    EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS *Address;
+    CHAR16                                      *DevicePathString;
+
+    Address = (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS *)&HpcPciAddress;
+    DevicePathString = ConvertDevicePathToText (HpcDevicePath, FALSE, FALSE);
+
+    DEBUG ((EFI_D_VERBOSE, "%a: Address=%02x:%02x.%x DevicePath=%s\n",
+      __FUNCTION__, Address->Bus, Address->Device, Address->Function,
+      (DevicePathString == NULL) ? L"<unavailable>" : DevicePathString));
+
+    if (DevicePathString != NULL) {
+      FreePool (DevicePathString);
+    }
+    );
+
+  if (HpcState == NULL || Padding == NULL || Attributes == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  *Padding = AllocateCopyPool (sizeof mPadding, &mPadding);
+  if (*Padding == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  //
+  // Resource padding is required.
+  //
+  *HpcState = EFI_HPC_STATE_INITIALIZED | EFI_HPC_STATE_ENABLED;
+
+  //
+  // The padding should be applied at PCI bus level, and considered by upstream
+  // bridges, recursively.
+  //
+  *Attributes = EfiPaddingPciBus;
+  return EFI_SUCCESS;
+}
+
+
+/**
+  Entry point for this driver.
+
+  @param[in] ImageHandle  Image handle of this driver.
+  @param[in] SystemTable  Pointer to SystemTable.
+
+  @retval EFI_SUCESS       Driver has loaded successfully.
+  @retval EFI_UNSUPPORTED  The device hotplug feature of the PCI bus driver is
+                           disabled.
+  @return                  Error codes from lower level functions.
+
+**/
+EFI_STATUS
+EFIAPI
+DriverInitialize (
+  IN EFI_HANDLE       ImageHandle,
+  IN EFI_SYSTEM_TABLE *SystemTable
+  )
+{
+  EFI_STATUS Status;
+
+  if (!FeaturePcdGet (PcdPciBusHotplugDeviceSupport)) {
+    DEBUG ((EFI_D_WARN,
+      "%a: this driver should not have been built into the firmware\n",
+      gEfiCallerBaseName));
+    return EFI_UNSUPPORTED;
+  }
+
+  mPciHotPlugInit.GetRootHpcList = GetRootHpcList;
+  mPciHotPlugInit.InitializeRootHpc = InitializeRootHpc;
+  mPciHotPlugInit.GetResourcePadding = GetResourcePadding;
+  Status = gBS->InstallMultipleProtocolInterfaces (&ImageHandle,
+                  &gEfiPciHotPlugInitProtocolGuid, &mPciHotPlugInit, NULL);
+  return Status;
+}