hw/i386: AMD-Vi IVRS DMA alias support
commit977aff1045b01579e73020a271336e559cdd6b58
authorAlex Williamson <alex.williamson@redhat.com>
Wed, 23 Oct 2019 22:47:28 +0000 (23 16:47 -0600)
committerMichael S. Tsirkin <mst@redhat.com>
Tue, 5 Nov 2019 09:04:21 +0000 (5 04:04 -0500)
treebca57802f8b72fb68c2e4b45220aac0687847b05
parent77ef8f8db2b2dd9d646a47a6a4154e27a96c929a
hw/i386: AMD-Vi IVRS DMA alias support

When we account for DMA aliases in the PCI address space, we can no
longer use a single IVHD entry in the IVRS covering all devices.  We
instead need to walk the PCI bus and create alias ranges when we find
a conventional bus.  These alias ranges cannot overlap with a "Select
All" range (as currently implemented), so we also need to enumerate
each device with IVHD entries.

Importantly, the IVHD entries used here include a Device ID, which is
simply the PCI BDF (Bus/Device/Function).  The guest firmware is
responsible for programming bus numbers, so the final revision of this
table depends on the update mechanism (acpi_build_update) to be called
after guest PCI enumeration.

For an example guest configuration of:

-+-[0000:40]---00.0-[41]----00.0  Intel Corporation 82574L Gigabit Network Connection
 \-[0000:00]-+-00.0  Intel Corporation 82G33/G31/P35/P31 Express DRAM Controller
             +-01.0  Device 1234:1111
             +-02.0-[01]----00.0  Intel Corporation 82574L Gigabit Network Connection
             +-02.1-[02]----00.0  Red Hat, Inc. QEMU XHCI Host Controller
             +-02.2-[03]--
             +-02.3-[04]--
             +-02.4-[05]--
             +-02.5-[06-09]----00.0-[07-09]--+-00.0-[08]--
             |                               \-01.0-[09]----00.0  Intel Corporation 82574L Gigabit Network Connection
             +-02.6-[0a-0c]----00.0-[0b-0c]--+-01.0-[0c]--
             |                               \-03.0  Intel Corporation 82540EM Gigabit Ethernet Controller
             +-02.7-[0d]----0e.0  Intel Corporation 82540EM Gigabit Ethernet Controller
             +-03.0  Red Hat, Inc. QEMU PCIe Expander bridge
             +-04.0  Advanced Micro Devices, Inc. [AMD] Device 0020
             +-1f.0  Intel Corporation 82801IB (ICH9) LPC Interface Controller
             +-1f.2  Intel Corporation 82801IR/IO/IH (ICH9R/DO/DH) 6 port SATA Controller [AHCI mode]
             \-1f.3  Intel Corporation 82801I (ICH9 Family) SMBus Controller

Where we have:

00:02.7 PCI bridge: Intel Corporation 82801 PCI Bridge
 (dmi-to-pci-bridge)
00:03.0 Host bridge: Red Hat, Inc. QEMU PCIe Expander bridge
 (pcie-expander-bus)
06:00.0 PCI bridge: Texas Instruments XIO3130 PCI Express Switch (Upstream)
 (pcie-switch-upstream-port)
07:00.0 PCI bridge: Texas Instruments XIO3130 PCI Express Switch (Downstream)
 (pcie-switch-downstream-port)
07:01.0 PCI bridge: Texas Instruments XIO3130 PCI Express Switch (Downstream)
 (pcie-switch-downstream-port)
0a:00.0 PCI bridge: Red Hat, Inc. Device 000e
 (pcie-to-pci-bridge)

The following IVRS table is produced:

AMD-Vi: Using IVHD type 0x10
AMD-Vi: device: 00:04.0 cap: 0040 seg: 0 flags: d1 info 0000
AMD-Vi:        mmio-addr: 00000000fed80000
AMD-Vi:   DEV_SELECT  devid: 40:00.0 flags: 00
AMD-Vi:   DEV_SELECT_RANGE_START  devid: 41:00.0 flags: 00
AMD-Vi:   DEV_RANGE_END  devid: 41:1f.7
AMD-Vi:   DEV_SELECT  devid: 00:00.0 flags: 00
AMD-Vi:   DEV_SELECT  devid: 00:01.0 flags: 00
AMD-Vi:   DEV_SELECT  devid: 00:02.0 flags: 00
AMD-Vi:   DEV_SELECT_RANGE_START  devid: 01:00.0 flags: 00
AMD-Vi:   DEV_RANGE_END  devid: 01:1f.7
AMD-Vi:   DEV_SELECT  devid: 00:02.1 flags: 00
AMD-Vi:   DEV_SELECT_RANGE_START  devid: 02:00.0 flags: 00
AMD-Vi:   DEV_RANGE_END  devid: 02:1f.7
AMD-Vi:   DEV_SELECT  devid: 00:02.2 flags: 00
AMD-Vi:   DEV_SELECT_RANGE_START  devid: 03:00.0 flags: 00
AMD-Vi:   DEV_RANGE_END  devid: 03:1f.7
AMD-Vi:   DEV_SELECT  devid: 00:02.3 flags: 00
AMD-Vi:   DEV_SELECT_RANGE_START  devid: 04:00.0 flags: 00
AMD-Vi:   DEV_RANGE_END  devid: 04:1f.7
AMD-Vi:   DEV_SELECT  devid: 00:02.4 flags: 00
AMD-Vi:   DEV_SELECT_RANGE_START  devid: 05:00.0 flags: 00
AMD-Vi:   DEV_RANGE_END  devid: 05:1f.7
AMD-Vi:   DEV_SELECT  devid: 00:02.5 flags: 00
AMD-Vi:   DEV_SELECT  devid: 06:00.0 flags: 00
AMD-Vi:   DEV_SELECT  devid: 07:00.0 flags: 00
AMD-Vi:   DEV_SELECT_RANGE_START  devid: 08:00.0 flags: 00
AMD-Vi:   DEV_RANGE_END  devid: 08:1f.7
AMD-Vi:   DEV_SELECT  devid: 07:01.0 flags: 00
AMD-Vi:   DEV_SELECT_RANGE_START  devid: 09:00.0 flags: 00
AMD-Vi:   DEV_RANGE_END  devid: 09:1f.7
AMD-Vi:   DEV_SELECT  devid: 00:02.6 flags: 00
AMD-Vi:   DEV_SELECT  devid: 0a:00.0 flags: 00
AMD-Vi:   DEV_ALIAS_RANGE  devid: 0b:00.0 flags: 00 devid_to: 0b:00.0
AMD-Vi:   DEV_RANGE_END  devid: 0c:1f.7
AMD-Vi:   DEV_SELECT  devid: 00:02.7 flags: 00
AMD-Vi:   DEV_ALIAS_RANGE  devid: 0d:00.0 flags: 00 devid_to: 00:02.7
AMD-Vi:   DEV_RANGE_END  devid: 0d:1f.7
AMD-Vi:   DEV_SELECT  devid: 00:03.0 flags: 00
AMD-Vi:   DEV_SELECT  devid: 00:04.0 flags: 00
AMD-Vi:   DEV_SELECT  devid: 00:1f.0 flags: 00
AMD-Vi:   DEV_SELECT  devid: 00:1f.2 flags: 00
AMD-Vi:   DEV_SELECT  devid: 00:1f.3 flags: 00

Reviewed-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Message-Id: <157187084880.5439.16700585779699233836.stgit@gimli.home>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
hw/i386/acpi-build.c