ARM: Add support for a generic PCI Express host bridge
v4 cover ARM: Add support for a generic PCI Express host bridge
Linux implements a nice binding to describe a "generic" PCI Express host bridge using only device tree.
This patch set adds enough emulation logic to expose the parts that are "generic" as a simple sysbus device and maps it into ARM's virt machine.
With this patch set, we can finally spawn PCI devices on ARM VMs. I was able to have a fully DRM enabled virtual machine with VGA, e1000 and XHCI (for keyboard and mouse) up and working.
It's only a small step for QEMU, but a big step for ARM VM's usability.
v1 -> v2:
- Add documentation links
- Remove mmio_window_size
- Add define for pci range types
- Use 4 PCI INTX IRQ lines
v2 -> v3:
- Update patch description
- Increase ecam region to full size
- Expose number of irqs via define
- Update header description
- Update host bridge qom description string
- Use new Red Hat PCIe host bridge PCI ID
- Coding style fixes
- Map ECAM space via alias to limit its size
- Increase ECAM size to 16 buses
- Use GPEX IRQ number define
- Align ECAM region, Document region allocation better
- Move interrupt-map into irq map function
- s/FDT_PCI_RANGE_TYPE/FDT_PCI_RANGE_TYPE_MASK/
v3 -> v4:
- update memory map comment
Alexander Graf (4):
pci: Allocate PCIe host bridge PCI ID
pci: Add generic PCIe host bridge
arm: Add PCIe host bridge in virt machine
pci: Move PCI VGA to pci.mak
default-configs/alpha-softmmu.mak | 2 - default-configs/arm-softmmu.mak | 2 + default-configs/i386-softmmu.mak | 2 - default-configs/mips-softmmu.mak | 2 - default-configs/mips64-softmmu.mak | 2 - default-configs/mips64el-softmmu.mak | 2 - default-configs/mipsel-softmmu.mak | 2 - default-configs/pci.mak | 2 + default-configs/ppc-softmmu.mak | 2 - default-configs/ppc64-softmmu.mak | 2 - default-configs/ppcemb-softmmu.mak | 2 - default-configs/sparc64-softmmu.mak | 2 - default-configs/x86_64-softmmu.mak | 2 - hw/arm/virt.c | 135 ++++++++++++++++++++++++++++-- hw/pci-host/Makefile.objs | 1 + hw/pci-host/gpex.c | 154 +++++++++++++++++++++++++++++++++++ include/hw/pci-host/gpex.h | 56 +++++++++++++ include/hw/pci/pci.h | 1 + include/sysemu/device_tree.h | 9 ++ 19 files changed, 355 insertions(+), 27 deletions(-) create mode 100644 hw/pci-host/gpex.c create mode 100644 include/hw/pci-host/gpex.h
Signature · 1 line
1.7.12.4
PATCH v4 1/4 pci: Allocate PCIe host bridge PCI ID
We are going to introduce a PCIe host controller that doesn't exist that way in real hardware, but still needs to expose some PCIe root device which has PCI IDs.
Allocate a PCI ID in the Red Hat space that we use for other devices of this kind.
--- include/hw/pci/pci.h | 1 + 1 file changed, 1 insertion(+)
include/hw/pci/pci.h +1 -0
@@ -89,6 +89,7 @@#define PCI_DEVICE_ID_REDHAT_SERIAL4 0x0004#define PCI_DEVICE_ID_REDHAT_TEST 0x0005#define PCI_DEVICE_ID_REDHAT_SDHCI 0x0007 +#define PCI_DEVICE_ID_REDHAT_PCIE_HOST 0x0008#define PCI_DEVICE_ID_REDHAT_QXL 0x0100#define FMT_PCIBUS PRIx64
Signature · 1 line
1.7.12.4
Re: [Qemu-devel] [PATCH v4 1/4] pci: Allocate PCIe host bridge PCI ID
Quoted 17 lines · Alexander Graf
We are going to introduce a PCIe host controller that doesn't exist that way in real hardware, but still needs to expose some PCIe root device which has PCI IDs.
Allocate a PCI ID in the Red Hat space that we use for other devices of this kind.
Signed-off-by Alexander Graf <[email protected]>--- include/hw/pci/pci.h | 1 + 1 file changed, 1 insertion(+)include/hw/pci/pci.h +0
-0
include/hw/pci/pci.h line 95
Quoted 7 lines
include/hw/pci/pci.h +1
-0@@ -89,6 +89,7 @@#define PCI_DEVICE_ID_REDHAT_SERIAL4 0x0004#define PCI_DEVICE_ID_REDHAT_TEST 0x0005#define PCI_DEVICE_ID_REDHAT_SDHCI 0x0007 +#define PCI_DEVICE_ID_REDHAT_PCIE_HOST 0x0008#define PCI_DEVICE_ID_REDHAT_QXL 0x0100#define FMT_PCIBUS PRIx64
thanks
-- PMM
PATCH v4 2/4 pci: Add generic PCIe host bridge
In reply to Alexander GrafWith simple exposure of MMFG, ioport window, mmio window and an IRQ line we can successfully create a workable PCIe host bridge that can be mapped anywhere and only needs to get described to the OS using whatever means it likes.
This patch implements such a "generic" host bridge. It handles 4 legacy IRQ lines. MSIs need to be handled external to the host bridge.
This device is particularly useful for the "pci-host-ecam-generic" driver in Linux.
---
v1 -> v2:
- Add documentation links
- Remove mmio_window_size
- Expose 4 INTX IRQs
v2 -> v3:
- Update patch description
- Increase ecam region to full size
- Expose number of irqs via define
- Update header description
- Update host bridge qom description string
- Use new Red Hat PCIe host bridge PCI ID
--- hw/pci-host/Makefile.objs | 1 + hw/pci-host/gpex.c | 154 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/pci-host/gpex.h | 56 +++++++++++++++++ 3 files changed, 211 insertions(+) create mode 100644 hw/pci-host/gpex.c create mode 100644 include/hw/pci-host/gpex.h
hw/pci-host/Makefile.objs +1 -0
@@ -15,3 +15,4 @@ common-obj-$(CONFIG_PCI_APB) += apb.o common-obj-$(CONFIG_FULONG) += bonito.o common-obj-$(CONFIG_PCI_PIIX) += piix.o common-obj-$(CONFIG_PCI_Q35) += q35.o +common-obj-$(CONFIG_PCI_GENERIC) += gpex.o
hw/pci-host/gpex.c new file +154 -0
154 lines not on this page · raw message
include/hw/pci-host/gpex.h new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
1.7.12.4
Re: [Qemu-devel] [PATCH v4 2/4] pci: Add generic PCIe host bridge
Quoted 7 lines · Alexander Graf
With simple exposure of MMFG, ioport window, mmio window and an IRQ line we can successfully create a workable PCIe host bridge that can be mapped anywhere and only needs to get described to the OS using whatever means it likes.
This patch implements such a "generic" host bridge. It handles 4 legacy IRQ lines. MSIs need to be handled external to the host bridge.
Quoted 6 lines
This device is particularly useful for the "pci-host-ecam-generic" driver in Linux.
Signed-off-by Alexander Graf <[email protected]>Reviewed-by Claudio Fontana <[email protected]>Tested-by Claudio Fontana <[email protected]>
thanks
-- PMM
PATCH v4 3/4 arm: Add PCIe host bridge in virt machine
In reply to Alexander GrafNow that we have a working "generic" PCIe host bridge driver, we can plug it into ARM's virt machine to always have PCIe available to normal ARM VMs.
I've successfully managed to expose a Bochs VGA device, XHCI and an e1000 into an AArch64 VM with this and they all lived happily ever after.
---
Linux 3.19 only supports the generic PCIe host bridge driver for 32bit ARM systems. If you want to use it with AArch64 guests, please apply the following patch or wait until upstream cleaned up the code properly:
http://csgraf.de/agraf/pci/pci-3.19.patch
v1 -> v2:
- Add define for pci range types
- Remove mmio_window_size
- Use 4 PCI INTX IRQ lines
v2 -> v3:
- Coding style fixes
- Map ECAM space via alias to limit its size
- Increase ECAM size to 16 buses
- Use GPEX IRQ number define
- Align ECAM region, Document region allocation better
- Move interrupt-map into irq map function
- s/FDT_PCI_RANGE_TYPE/FDT_PCI_RANGE_TYPE_MASK/
v3 -> v4:
- update memory map comment
--- default-configs/arm-softmmu.mak | 2 + hw/arm/virt.c | 135 ++++++++++++++++++++++++++++++++++++++-- include/sysemu/device_tree.h | 9 +++ 3 files changed, 141 insertions(+), 5 deletions(-)
default-configs/arm-softmmu.mak +2 -0
@@ -82,6 +82,8 @@ CONFIG_ZYNQ=y CONFIG_VERSATILE_PCI=y CONFIG_VERSATILE_I2C=y +CONFIG_PCI_GENERIC=y + CONFIG_SDHCI=y CONFIG_INTEGRATOR_DEBUG=y
hw/arm/virt.c +130 -5
202 lines not on this page · raw message
include/sysemu/device_tree.h +9 -0
@@ -110,4 +110,13 @@ int qemu_fdt_setprop_sized_cells_from_array(void *fdt, qdt_tmp); \ }) +#define FDT_PCI_RANGE_RELOCATABLE 0x80000000 +#define FDT_PCI_RANGE_PREFETCHABLE 0x40000000 +#define FDT_PCI_RANGE_ALIASED 0x20000000 +#define FDT_PCI_RANGE_TYPE_MASK 0x03000000 +#define FDT_PCI_RANGE_MMIO_64BIT 0x03000000 +#define FDT_PCI_RANGE_MMIO 0x02000000 +#define FDT_PCI_RANGE_IOPORT 0x01000000 +#define FDT_PCI_RANGE_CONFIG 0x00000000 +#endif /* __DEVICE_TREE_H__ */
Signature · 1 line
1.7.12.4
Re: [Qemu-devel] [PATCH v4 3/4] arm: Add PCIe host bridge in virt machine
Quoted 22 lines · Alexander Graf
Now that we have a working "generic" PCIe host bridge driver, we can plug it into ARM's virt machine to always have PCIe available to normal ARM VMs.
I've successfully managed to expose a Bochs VGA device, XHCI and an e1000 into an AArch64 VM with this and they all lived happily ever after.
Signed-off-by Alexander Graf <[email protected]>Tested-by Claudio Fontana <[email protected]>hw/arm/virt.c +13
-0+static void create_pcie (const VirtBoardInfo *vbi,qemu_irq *pic, +uint32_t gic_phandle) +{ +hwaddr base = vbi->memmap[VIRT_PCIE ].base; +hwaddr size = vbi->memmap[VIRT_PCIE ].size; +hwaddr end = base + size; +hwaddr size_mmio; +hwaddr size_ioport =64 *1024 ; +hwaddr size_ecam =PCIE_MMCFG_SIZE_MIN *16 ;/* 16 PCIe buses */ +hwaddr base_mmio = base; +hwaddr base_ioport; +hwaddr base_ecam; +int irq = vbi->irqmap[VIRT_PCIE ];
hw/arm/virt.c static void create_fw_cfg(const VirtBoardInfo *vbi) · line 628
Quoted 10 lines
hw/arm/virt.c +10
-0+MemoryRegion *mmio_alias; +MemoryRegion *mmio_reg; +MemoryRegion *ecam_alias; +MemoryRegion *ecam_reg; +DeviceState *dev; +char *nodename; +int i; + + base_ecam =QEMU_ALIGN_DOWN (end - size_ecam, size_ecam); + size_ecam = end - base_ecam;
Why do we do this? If we've had to align down a 256MB ECAM that doesn't mean the space gets bigger -- it's still 256MB.
Quoted 1 line
+
base_ioport=QEMU_ALIGN_DOWN(end - size_ecam - size_ioport, size_ioport);
Shouldn't the first argument here be 'base_ecam - size_ioport' ? Otherwise if we did have to align down the ECAM window we won't have started the ioport far enough down...
Quoted 1 line
+
size_ioport=base_ecam-base_ioport;
Again, I don't think the ioport size should get bigger.
hw/arm/virt.c static void create_fw_cfg(const VirtBoardInfo *vbi) · line 643
Quoted 13 lines
hw/arm/virt.c +13
-0+ size_mmio = base_ioport - base; + + dev =qdev_create (NULL ,TYPE_GPEX_HOST ); +qdev_init_nofail (dev); + +/* Map only the first size_ecam bytes of ECAM space */ + ecam_alias =g_new0 (MemoryRegion,1 ); + ecam_reg =sysbus_mmio_get_region (SYS_BUS_DEVICE (dev),0 ); +memory_region_init_alias (ecam_alias,OBJECT (dev),"pcie-ecam" , + ecam_reg,0 , size_ecam); +memory_region_add_subregion (get_system_memory (), base_ecam, ecam_alias); + +/* Map the MMIO window at the same spot in bus and cpu layouts */
I still think this comment is a little cryptic. I suggest:
/* Map the MMIO window into system address space so as to expose
* the section of PCI MMIO space which starts at the same base address
* (ie 1:1 mapping for that part of PCI MMIO space visible through
* the window).
*/
Quoted 11 lines
hw/arm/virt.c +11
-0+ mmio_alias =g_new0 (MemoryRegion,1 ); + mmio_reg =sysbus_mmio_get_region (SYS_BUS_DEVICE (dev),1 ); +memory_region_init_alias (mmio_alias,OBJECT (dev),"pcie-mmio" , + mmio_reg, base_mmio, size_mmio); +memory_region_add_subregion (get_system_memory (), base_mmio, mmio_alias); + +/* Map IO port space */ +sysbus_mmio_map (SYS_BUS_DEVICE (dev),2 , base_ioport); + +for (i =0 ; i <GPEX_NUM_IRQS ; i++) { +sysbus_connect_irq (SYS_BUS_DEVICE (dev), i, pic[irq + i]);
hw/arm/virt.c static void create_fw_cfg(const VirtBoardInfo *vbi) · line 664
Quoted 10 lines
hw/arm/virt.c +10
-0+ } + + nodename =g_strdup_printf ("/pcie@%" PRIx64, base); +qemu_fdt_add_subnode (vbi->fdt, nodename); +qemu_fdt_setprop_string (vbi->fdt, nodename, +"compatible" ,"pci-host-ecam-generic" ); +qemu_fdt_setprop_string (vbi->fdt, nodename,"device_type" ,"pci" ); +qemu_fdt_setprop_cell (vbi->fdt, nodename,"#address-cells" ,3 ); +qemu_fdt_setprop_cell (vbi->fdt, nodename,"#size-cells" ,2 ); +qemu_fdt_setprop_cells (vbi->fdt, nodename,"bus-range" ,0 ,1 );
Is this right? It doesn't seem to match the expanded eCAM size we've used above. (Maybe we should calculate this based on the size_ecam or something?)
hw/arm/virt.c static void create_fw_cfg(const VirtBoardInfo *vbi) · line 671
Quoted 7 lines
hw/arm/virt.c +7
-0+ +qemu_fdt_setprop_sized_cells (vbi->fdt, nodename,"reg" , +2 , base_ecam,2 , size_ecam); + qemu_fdt_setprop_sized_cells(vbi->fdt, nodename, "ranges", + 1, FDT_PCI_RANGE_IOPORT, 2, 0, + 2, base_ioport, 2, size_ioport, +
I guess this blank line is deliberate to separate out the io from the mmio part of this definition...
hw/arm/virt.c static void create_fw_cfg(const VirtBoardInfo *vbi) · line 679
Quoted 8 lines
hw/arm/virt.c +8
-0+1 ,FDT_PCI_RANGE_MMIO ,2 , base_mmio, + 2, base_mmio, 2, size_mmio); + +qemu_fdt_setprop_cell (vbi->fdt, nodename,"#interrupt-cells" ,1 ); +create_pcie_irq_map (vbi, gic_phandle, irq, nodename); + +g_free (nodename); +}
Otherwise looks OK.
thanks
-- PMM
PATCH v4 4/4 pci: Move PCI VGA to pci.mak
In reply to Alexander GrafEvery platform that supports PCI can also spawn the Bochs VGA PCI adapter. Move it to pci.mak to enable it for everyone.
--- default-configs/alpha-softmmu.mak | 2 -- default-configs/i386-softmmu.mak | 2 -- default-configs/mips-softmmu.mak | 2 -- default-configs/mips64-softmmu.mak | 2 -- default-configs/mips64el-softmmu.mak | 2 -- default-configs/mipsel-softmmu.mak | 2 -- default-configs/pci.mak | 2 ++ default-configs/ppc-softmmu.mak | 2 -- default-configs/ppc64-softmmu.mak | 2 -- default-configs/ppcemb-softmmu.mak | 2 -- default-configs/sparc64-softmmu.mak | 2 -- default-configs/x86_64-softmmu.mak | 2 -- 12 files changed, 2 insertions(+), 22 deletions(-)
default-configs/alpha-softmmu.mak +0 -2
@@ -5,8 +5,6 @@ include usb.mak CONFIG_SERIAL=y CONFIG_I8254=y CONFIG_PCKBD=y -CONFIG_VGA=y -CONFIG_VGA_PCI=y CONFIG_VGA_CIRRUS=y CONFIG_IDE_CORE=y CONFIG_IDE_QDEV=y
default-configs/i386-softmmu.mak +0 -2
@@ -3,9 +3,7 @@ include pci.mak include sound.mak include usb.mak -CONFIG_VGA=y CONFIG_QXL=$(CONFIG_SPICE) -CONFIG_VGA_PCI=y CONFIG_VGA_ISA=y CONFIG_VGA_CIRRUS=y CONFIG_VMWARE_VGA=y
default-configs/mips-softmmu.mak +0 -2
@@ -4,8 +4,6 @@ include pci.mak include sound.mak include usb.mak CONFIG_ESP=y -CONFIG_VGA=y -CONFIG_VGA_PCI=y CONFIG_VGA_ISA=y CONFIG_VGA_ISA_MM=y CONFIG_VGA_CIRRUS=y
default-configs/mips64-softmmu.mak +0 -2
@@ -4,8 +4,6 @@ include pci.mak include sound.mak include usb.mak CONFIG_ESP=y -CONFIG_VGA=y -CONFIG_VGA_PCI=y CONFIG_VGA_ISA=y CONFIG_VGA_ISA_MM=y CONFIG_VGA_CIRRUS=y
default-configs/mips64el-softmmu.mak +0 -2
@@ -4,8 +4,6 @@ include pci.mak include sound.mak include usb.mak CONFIG_ESP=y -CONFIG_VGA=y -CONFIG_VGA_PCI=y CONFIG_VGA_ISA=y CONFIG_VGA_ISA_MM=y CONFIG_VGA_CIRRUS=y
default-configs/mipsel-softmmu.mak +0 -2
@@ -4,8 +4,6 @@ include pci.mak include sound.mak include usb.mak CONFIG_ESP=y -CONFIG_VGA=y -CONFIG_VGA_PCI=y CONFIG_VGA_ISA=y CONFIG_VGA_ISA_MM=y CONFIG_VGA_CIRRUS=y
default-configs/pci.mak +2 -0
@@ -33,3 +33,5 @@ CONFIG_NVME_PCI=y CONFIG_SD=y CONFIG_SDHCI=y CONFIG_EDU=y +CONFIG_VGA=y +CONFIG_VGA_PCI=y
default-configs/ppc-softmmu.mak +0 -2
@@ -6,8 +6,6 @@ include usb.mak CONFIG_ISA_MMIO=y CONFIG_ESCC=y CONFIG_M48T59=y -CONFIG_VGA=y -CONFIG_VGA_PCI=y CONFIG_SERIAL=y CONFIG_PARALLEL=y CONFIG_I8254=y
default-configs/ppc64-softmmu.mak +0 -2
@@ -6,8 +6,6 @@ include usb.mak CONFIG_ISA_MMIO=y CONFIG_ESCC=y CONFIG_M48T59=y -CONFIG_VGA=y -CONFIG_VGA_PCI=y CONFIG_SERIAL=y CONFIG_PARALLEL=y CONFIG_I8254=y
default-configs/ppcemb-softmmu.mak +0 -2
@@ -4,8 +4,6 @@ include pci.mak include sound.mak include usb.mak CONFIG_M48T59=y -CONFIG_VGA=y -CONFIG_VGA_PCI=y CONFIG_SERIAL=y CONFIG_I8257=y CONFIG_OPENPIC=y
default-configs/sparc64-softmmu.mak +0 -2
@@ -5,8 +5,6 @@ include usb.mak CONFIG_ISA_MMIO=y CONFIG_M48T59=y CONFIG_PTIMER=y -CONFIG_VGA=y -CONFIG_VGA_PCI=y CONFIG_SERIAL=y CONFIG_PARALLEL=y CONFIG_PCKBD=y
default-configs/x86_64-softmmu.mak +0 -2
@@ -3,9 +3,7 @@ include pci.mak include sound.mak include usb.mak -CONFIG_VGA=y CONFIG_QXL=$(CONFIG_SPICE) -CONFIG_VGA_PCI=y CONFIG_VGA_ISA=y CONFIG_VGA_CIRRUS=y CONFIG_VMWARE_VGA=y
Signature · 1 line
1.7.12.4
Re: [Qemu-devel] [PATCH v4 4/4] pci: Move PCI VGA to pci.mak
Quoted 4 lines · Alexander Graf
Every platform that supports PCI can also spawn the Bochs VGA PCI adapter. Move it to pci.mak to enable it for everyone.
Signed-off-by Alexander Graf <[email protected]>
thanks
-- PMM