audk/OvmfPkg/Library
Borghorst, Hendrik via groups.io 6573ae8c85 OvmfPkg/PlatformBootManagerLib: fix PCI interrupt link (LNKx)
This patch fixes an issue with the current programming of the i440fx
PCI Interrupt routing assignment.

Explanation by Laszlo Ersek:

(1) The rotating pattern is a map:

  (slot, function) --> (interrupt link) [LNKA..LNKD]

(more precisely, it is a pattern from (slot, pin) to (interrupt link),
but function<->pin is an identity mapping in the QEMU hardware, so we
can just use (slot, function) rather than (slot, pin) on the left hand
side. But I digress.)

The ACPI _PRT object is generated by QEMU; it describes this map.

(2) Another map is

  (interrupt link) --> { set of possible interrupt numbers,
                         for this link }

This map is given by the LNK[A..D] ACPI objects, also given by QEMU.

(3) What the firmware is expected to do is:

(3a) for each interrupt link, select an *actual* interrupt from the set
that's possible for that link, yielding a deterministic map

  (interrupt link) --> (actual interrupt number)

and

(3b) for each PCI device/function with an interrupt pin, resolve the

  (slot, function) --> (interrupt link) --> (actual interrupt number)

functional composition, and program the result into the Interrupt Line
register of the device.

In OVMF, we do not parse the rotating map described under (1) from
QEMU's _PRT object. Instead, we duplicate the code. This is not a
problem.

In OVMF, we also do not parse the map described under (2) from QEMU's
ACPI content. Instead, we pick a specific selection (3a) that we
"apriori" know satisfies (2). This is also not a problem. OVMF's
particular selection is the PciHostIrqs table.

(

Table (2) from QEMU is

  LNKA -> { 5, 10, 11 }
  LNKB -> { 5, 10, 11 }
  LNKC -> { 5, 10, 11 }
  LNKD -> { 5, 10, 11 }

and our specific pick in OVMF, in the PciHostIrqs table, is

  LNKA -> 10
  LNKB -> 10
  LNKC -> 11
  LNKD -> 11

)

In OVMF, we also cover step (3b), in the SetPciIntLine() function.

What's missing in OVMF -- and what this patch corrects -- is that we
currently fail to program our selection for table (3) into the hardware.
We pick a specific LNKx->IRQ# mapping for each interrupt link, and we
correctly program the PCI Interrupt Line registers through those
link-to-IRQ mappings -- but we don't tell the hardware about the
link-to-IRQ mappings. More precisely, we program such a link-to-IRQ
mapping table into the hardware that is then not matched by the mapping
we use for programming the PCI device/function interrupt lines. As a
result, some PCI Interrupt Line registers will have impossible values --
a given (slot, function) may use a particular link, but also report an
interrupt number that was never picked for that link.

Output of Linux PCI Interrupt Links for i440fx before the patch:

[    0.327305] ACPI: PCI Interrupt Link [LNKA] (IRQs 5 10 *11)
[    0.327944] ACPI: PCI Interrupt Link [LNKB] (IRQs 5 10 *11)
[    0.328582] ACPI: PCI Interrupt Link [LNKC] (IRQs 5 *10 11)
[    0.329208] ACPI: PCI Interrupt Link [LNKD] (IRQs 5 *10 11)
[    0.329807] ACPI: PCI Interrupt Link [LNKS] (IRQs *9)

after the patch:

[    0.327292] ACPI: PCI Interrupt Link [LNKA] (IRQs 5 *10 11)
[    0.327934] ACPI: PCI Interrupt Link [LNKB] (IRQs 5 *10 11)
[    0.328564] ACPI: PCI Interrupt Link [LNKC] (IRQs 5 10 *11)
[    0.329195] ACPI: PCI Interrupt Link [LNKD] (IRQs 5 10 *11)
[    0.329785] ACPI: PCI Interrupt Link [LNKS] (IRQs *9)

Output of Linux PCI Interrupt Links for q35 before the patch:

[    0.307474] ACPI: PCI Interrupt Link [LNKA] (IRQs 5 *10 11)
[    0.308027] ACPI: PCI Interrupt Link [LNKB] (IRQs 5 *10 11)
[    0.308764] ACPI: PCI Interrupt Link [LNKC] (IRQs 5 10 *11)
[    0.309310] ACPI: PCI Interrupt Link [LNKD] (IRQs 5 10 *11)
[    0.309853] ACPI: PCI Interrupt Link [LNKE] (IRQs 5 *10 11)
[    0.310508] ACPI: PCI Interrupt Link [LNKF] (IRQs 5 *10 11)
[    0.311051] ACPI: PCI Interrupt Link [LNKG] (IRQs 5 10 *11)
[    0.311589] ACPI: PCI Interrupt Link [LNKH] (IRQs 5 10 *11)

after the patch:

[    0.301991] ACPI: PCI Interrupt Link [LNKA] (IRQs 5 *10 11)
[    0.302833] ACPI: PCI Interrupt Link [LNKB] (IRQs 5 *10 11)
[    0.303354] ACPI: PCI Interrupt Link [LNKC] (IRQs 5 10 *11)
[    0.303873] ACPI: PCI Interrupt Link [LNKD] (IRQs 5 10 *11)
[    0.304399] ACPI: PCI Interrupt Link [LNKE] (IRQs 5 *10 11)
[    0.304918] ACPI: PCI Interrupt Link [LNKF] (IRQs 5 *10 11)
[    0.305436] ACPI: PCI Interrupt Link [LNKG] (IRQs 5 10 *11)
[    0.305954] ACPI: PCI Interrupt Link [LNKH] (IRQs 5 10 *11)

Signed-off-by: Hendrik Borghorst <hborghor@amazon.de>
Reviewed-by: David Woodhouse <dwmw@amazon.co.uk>
Message-Id: <8dbedc4c7a1c3fd390aca915270814e3b35e13a5.camel@amazon.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2020-12-18 12:51:37 +00:00
..
AcpiTimerLib OvmfPkg: Add bhyve support into AcpiTimerLib 2020-04-30 13:46:11 +00:00
BaseMemEncryptSevLib OvmfPkg/MemEncryptSevLib: Add an SEV-ES guest indicator function 2020-08-17 02:46:39 +00:00
BasePciCapLib OvmfPkg/BasePciCapLib: suppress invalid "nullptr deref" warning 2019-04-18 16:06:04 +02:00
BasePciCapPciSegmentLib OvmfPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:19 -07:00
BhyveFwCtlLib OvmfPkg: Fix style of BhyveFwCtlLib.inf 2020-11-30 17:49:39 +00:00
DxePciLibI440FxQ35 OvmfPkg/Qemu: Fix various typos 2020-02-10 22:30:07 +00:00
EmuVariableFvbLib OvmfPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:19 -07:00
GenericQemuLoadImageLib OvmfPkg/GenericQemuLoadImageLib: log "Not Found" at INFO level 2020-06-10 07:55:55 +00:00
LoadLinuxLib OvmfPkg: replace old EFI_D_ debug levels with new DEBUG_ ones 2020-04-30 13:01:16 +00:00
LockBoxLib OvmfPkg: strip trailing whitespace 2019-10-04 11:18:32 +01:00
NvVarsFileLib OvmfPkg: replace old EFI_D_ debug levels with new DEBUG_ ones 2020-04-30 13:01:16 +00:00
PciHostBridgeLib OvmfPkg: replace old EFI_D_ debug levels with new DEBUG_ ones 2020-04-30 13:01:16 +00:00
PlatformBmPrintScLib OvmfPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:19 -07:00
PlatformBootManagerLib OvmfPkg/PlatformBootManagerLib: fix PCI interrupt link (LNKx) 2020-12-18 12:51:37 +00:00
PlatformBootManagerLibBhyve OvmfPkg/Bhyve: Add support for the AMD host bridge 2020-11-27 16:48:47 +00:00
PlatformBootManagerLibGrub OvmfPkg/AmdSev: add Grub Firmware Volume Package 2020-12-14 19:56:18 +00:00
PlatformDebugLibIoPort OvmfPkg/PlatformDebugLibIoPort: Introduce a Nocheck variant 2020-04-28 21:12:01 +00:00
PlatformFvbLibNull OvmfPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:19 -07:00
PlatformHasIoMmuLib OvmfPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:19 -07:00
PlatformSecureLib OvmfPkg: strip trailing whitespace 2019-10-04 11:18:32 +01:00
PxeBcPcdProducerLib OvmfPkg: control PXEv4 / PXEv6 boot support from the QEMU command line 2020-04-28 22:37:35 +00:00
QemuBootOrderLib OvmfPkg: replace old EFI_D_ debug levels with new DEBUG_ ones 2020-04-30 13:01:16 +00:00
QemuFwCfgLib OvmfPkg: Add QemuFwCfgLibNull 2020-05-05 16:57:57 +00:00
QemuFwCfgS3Lib OvmfPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:19 -07:00
QemuFwCfgSimpleParserLib OvmfPkg: introduce QemuFwCfgSimpleParserLib 2020-04-28 22:37:35 +00:00
ResetSystemLib OvmfPkg: Add BaseResetSystemLibBhyve 2020-05-05 19:40:40 +00:00
SerializeVariablesLib OvmfPkg: replace old EFI_D_ debug levels with new DEBUG_ ones 2020-04-30 13:01:16 +00:00
SmbiosVersionLib OvmfPkg: replace old EFI_D_ debug levels with new DEBUG_ ones 2020-04-30 13:01:16 +00:00
SmmCpuFeaturesLib OvmfPkg/SEV: don't manage the lifecycle of the SMRAM at the default SMBASE 2020-02-05 12:59:32 +00:00
SmmCpuPlatformHookLibQemu OvmfPkg: enable SMM Monarch Election in PiSmmCpuDxeSmm 2020-03-04 12:22:07 +00:00
Tcg2PhysicalPresenceLibNull OvmfPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:19 -07:00
Tcg2PhysicalPresenceLibQemu OvmfPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:19 -07:00
TlsAuthConfigLib OvmfPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:19 -07:00
UefiPciCapPciIoLib OvmfPkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:19 -07:00
VirtioLib OvmfPkg/Virtio: Fix few typos 2020-02-10 22:30:07 +00:00
VirtioMmioDeviceLib OvmfPkg: drop redundant VendorID check in VirtioMmioDeviceLib 2020-09-17 12:01:11 +00:00
VmgExitLib UefiCpuPkg, OvmfPkg: Disable interrupts when using the GHCB 2020-11-10 19:07:55 +00:00
X86QemuLoadImageLib OvmfPkg/X86QemuLoadImageLib: handle EFI_ACCESS_DENIED from LoadImage() 2020-06-09 20:19:04 +00:00
XenConsoleSerialPortLib OvmfPkg/Xen: Fix various typos 2020-02-10 22:30:07 +00:00
XenHypercallLib OvmfPkg: replace old EFI_D_ debug levels with new DEBUG_ ones 2020-04-30 13:01:16 +00:00
XenIoMmioLib OvmfPkg: replace old EFI_D_ debug levels with new DEBUG_ ones 2020-04-30 13:01:16 +00:00
XenPlatformLib OvmfPkg/XenPlatformLib: Cache result for XenDetected 2019-08-21 18:03:49 +02:00
XenRealTimeClockLib OvmfPkg: Move XenRealTimeClockLib from ArmVirtPkg 2019-08-21 18:03:50 +02:00