Use a PCD set from PEI to determine the legacy interrupt device
number appropriate for the underlying platform type during protocol
initialization.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Gabriel Somlo <so...@cmu.edu>
Reviewed-by: Paolo Bonzini <pbonz...@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.jus...@intel.com>
---
 OvmfPkg/Csm/CsmSupportLib/CsmSupportLib.inf |  3 +++
 OvmfPkg/Csm/CsmSupportLib/LegacyInterrupt.c | 27 +++++++++++++++++++++++++--
 OvmfPkg/Csm/CsmSupportLib/LegacyInterrupt.h |  6 +++++-
 3 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/OvmfPkg/Csm/CsmSupportLib/CsmSupportLib.inf 
b/OvmfPkg/Csm/CsmSupportLib/CsmSupportLib.inf
index 34cadb2..1f16646 100644
--- a/OvmfPkg/Csm/CsmSupportLib/CsmSupportLib.inf
+++ b/OvmfPkg/Csm/CsmSupportLib/CsmSupportLib.inf
@@ -38,6 +38,9 @@
   MdePkg/MdePkg.dec
   IntelFrameworkPkg/IntelFrameworkPkg.dec
 
+[Pcd]
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
+
 [Protocols]
   gEfiDevicePathProtocolGuid                    # PROTOCOL ALWAYS_CONSUMED
   gEfiDiskInfoProtocolGuid                      # PROTOCOL ALWAYS_CONSUMED
diff --git a/OvmfPkg/Csm/CsmSupportLib/LegacyInterrupt.c 
b/OvmfPkg/Csm/CsmSupportLib/LegacyInterrupt.c
index cd98417..6ad6e31 100644
--- a/OvmfPkg/Csm/CsmSupportLib/LegacyInterrupt.c
+++ b/OvmfPkg/Csm/CsmSupportLib/LegacyInterrupt.c
@@ -21,6 +21,11 @@
 STATIC EFI_HANDLE mLegacyInterruptHandle = NULL;
 
 //
+// Legacy Interrupt Device number (0x01 on piix4, 0x1f on q35/mch)
+//
+STATIC UINT8      mLegacyInterruptDevice;
+
+//
 // The Legacy Interrupt Protocol instance produced by this driver
 //
 STATIC EFI_LEGACY_INTERRUPT_PROTOCOL mLegacyInterrupt = {
@@ -77,7 +82,7 @@ GetLocation (
   )
 {
   *Bus      = LEGACY_INT_BUS;
-  *Device   = LEGACY_INT_DEV;
+  *Device   = mLegacyInterruptDevice;
   *Function = LEGACY_INT_FUNC;
 
   return EFI_SUCCESS;
@@ -98,7 +103,7 @@ GetAddress (
 {
   return PCI_LIB_ADDRESS(
           LEGACY_INT_BUS,
-          LEGACY_INT_DEV,
+          mLegacyInterruptDevice,
           LEGACY_INT_FUNC,
           PirqReg[PirqNumber]
           );
@@ -173,6 +178,7 @@ LegacyInterruptInstall (
   VOID
   )
 {
+  UINT16      HostBridgeDevId;
   EFI_STATUS  Status;
 
   //
@@ -181,6 +187,23 @@ LegacyInterruptInstall (
   ASSERT_PROTOCOL_ALREADY_INSTALLED(NULL, &gEfiLegacyInterruptProtocolGuid);
 
   //
+  // Query Host Bridge DID to determine platform type, then set device number
+  //
+  HostBridgeDevId = PcdGet16 (PcdOvmfHostBridgePciDevId);
+  switch (HostBridgeDevId) {
+    case INTEL_82441_DEVICE_ID:
+      mLegacyInterruptDevice = LEGACY_INT_DEV_PIIX4;
+      break;
+    case INTEL_Q35_MCH_DEVICE_ID:
+      mLegacyInterruptDevice = LEGACY_INT_DEV_Q35;
+      break;
+    default:
+      DEBUG ((EFI_D_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",
+        __FUNCTION__, HostBridgeDevId));
+      ASSERT (FALSE);
+  }
+
+  //
   // Make a new handle and install the protocol
   //
   Status = gBS->InstallMultipleProtocolInterfaces (
diff --git a/OvmfPkg/Csm/CsmSupportLib/LegacyInterrupt.h 
b/OvmfPkg/Csm/CsmSupportLib/LegacyInterrupt.h
index 193e48b..eb1f583 100644
--- a/OvmfPkg/Csm/CsmSupportLib/LegacyInterrupt.h
+++ b/OvmfPkg/Csm/CsmSupportLib/LegacyInterrupt.h
@@ -20,12 +20,16 @@
 
 #include <Protocol/LegacyInterrupt.h>
 
+#include <Library/PcdLib.h>
 #include <Library/PciLib.h>
 #include <Library/DebugLib.h>
 #include <Library/UefiBootServicesTableLib.h>
+#include <OvmfPlatforms.h>
+
 
 #define LEGACY_INT_BUS  0
-#define LEGACY_INT_DEV  1
+#define LEGACY_INT_DEV_PIIX4  0x01
+#define LEGACY_INT_DEV_Q35    0x1f
 #define LEGACY_INT_FUNC 0
 
 #define PIRQN           0x00  // PIRQ Null
-- 
1.9.3


------------------------------------------------------------------------------
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to