target-arm queue
target-arm queue: Eric's SMMUv3 patchset, and an array of minor bugfixes and improvements from various others.
thanks
-- PMM
The following changes since commit c8b7e627b4269a3bc3ae41d9f420547a47e6d9b9:
Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2018-05-04' into staging (2018-05-04 14:42:46 +0100)
are available in the Git repository at:
git://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20180504
for you to fetch changes up to 5680740c92993e9b3f3e011f2a2c394070e33f56:
hw/arm/virt: Introduce the iommu option (2018-05-04 18:05:52 +0100)
----------------------------------------------------------------
target-arm queue:
* Emulate the SMMUv3 (IOMMU); one will be created in the 'virt' board if the commandline includes "-machine iommu=smmuv3"
* target/arm: Implement v8M VLLDM and VLSTM
* hw/arm: Don't fail qtest due to missing SD card in -nodefaults mode
* Some fixes to silence Coverity false-positives
* arm: boot: set boot_info starting from first_cpu
(fixes a technical bug not visible in practice)
* hw/net/smc91c111: Convert away from old_mmio
* hw/usb/tusb6010: Convert away from old_mmio
* hw/char/cmsdk-apb-uart.c: Accept more input after character read
* target/arm: Make MPUIR write-ignored on OMAP, StrongARM
* hw/arm/virt: Add linux,pci-domain property
----------------------------------------------------------------
Eric Auger (11):
hw/arm/smmu-common: smmu base device and datatypes hw/arm/smmu-common: IOMMU memory region and address space setup hw/arm/smmu-common: VMSAv8-64 page table walk hw/arm/smmuv3: Wired IRQ and GERROR helpers
hw/arm/smmuv3: Queue helpers
hw/arm/smmuv3: Implement MMIO write operations hw/arm/smmuv3: Event queue recording helper
hw/arm/smmuv3: Implement translate callback
hw/arm/smmuv3: Abort on vfio or vhost case
target/arm/kvm: Translate the MSI doorbell in kvm_arch_fixup_msi_route hw/arm/virt: Introduce the iommu option
Igor Mammedov (1):
arm: boot: set boot_info starting from first_cpu
Jan Kiszka (1):
hw/arm/virt: Add linux,pci-domain property
Mathew Maidment (1):
target/arm: Correct MPUIR privilege level in register_cp_regs_for_features() conditional case
Patrick Oppenlander (1):
hw/char/cmsdk-apb-uart.c: Accept more input after character read
Peter Maydell (3):
hw/usb/tusb6010: Convert away from old_mmio hw/net/smc91c111: Convert away from old_mmio target/arm: Implement v8M VLLDM and VLSTM
Prem Mallappa (3):
hw/arm/smmuv3: Skeleton
hw/arm/virt: Add SMMUv3 to the virt board hw/arm/virt-acpi-build: Add smmuv3 node in IORT table
Richard Henderson (2):
target/arm: Tidy conditions in handle_vec_simd_shri target/arm: Tidy condition in disas_simd_two_reg_misc
Thomas Huth (1):
hw/arm: Don't fail qtest due to missing SD card in -nodefaults mode
hw/arm/Makefile.objs | 1 + hw/arm/smmu-internal.h | 99 +++ hw/arm/smmuv3-internal.h | 621 ++++++++++++++++++ include/hw/acpi/acpi-defs.h | 15 + include/hw/arm/smmu-common.h | 145 +++++ include/hw/arm/smmuv3.h | 87 +++ include/hw/arm/virt.h | 10 + hw/arm/boot.c | 2 +- hw/arm/omap1.c | 8 +- hw/arm/omap2.c | 8 +- hw/arm/pxa2xx.c | 15 +- hw/arm/smmu-common.c | 372 +++++++++++ hw/arm/smmuv3.c | 1191 +++++++++++++++++++++++++++++++++++ hw/arm/virt-acpi-build.c | 55 +- hw/arm/virt.c | 101 ++- hw/char/cmsdk-apb-uart.c | 1 + hw/net/smc91c111.c | 54 +- hw/usb/tusb6010.c | 40 +- target/arm/helper.c | 2 +- target/arm/kvm.c | 38 +- target/arm/translate-a64.c | 12 +- target/arm/translate.c | 17 +- default-configs/aarch64-softmmu.mak | 1 + hw/arm/trace-events | 37 ++ target/arm/trace-events | 3 + 25 files changed, 2868 insertions(+), 67 deletions(-) create mode 100644 hw/arm/smmu-internal.h create mode 100644 hw/arm/smmuv3-internal.h create mode 100644 include/hw/arm/smmu-common.h create mode 100644 include/hw/arm/smmuv3.h create mode 100644 hw/arm/smmu-common.c create mode 100644 hw/arm/smmuv3.c
[Qemu-devel] [PULL 03/24] hw/char/cmsdk-apb-uart.c: Accept more input after character read
From: Patrick Oppenlander <[email protected]>
The character frontend needs to be notified that the uart receive buffer is empty and ready to handle another character.
Previously, the uart only worked correctly when receiving one character at a time.
Message-id: CAEg67GkRTw=cXei3o9hvpxG_L4zSrNzR0bFyAgny+sSEUb_kPw@mail.gmail.com
--- hw/char/cmsdk-apb-uart.c | 1 + 1 file changed, 1 insertion(+)
hw/char/cmsdk-apb-uart.c +1 -0
@@ -157,6 +157,7 @@ static uint64_t uart_read(void *opaque, hwaddr offset, unsigned size) r = s->rxbuf; s->state &= ~R_STATE_RXFULL_MASK ;cmsdk_apb_uart_update (s); +qemu_chr_fe_accept_input (&s->chr);break ;case A_STATE : r = s->state;
Signature · 1 line
2.17.0
[Qemu-devel] [PULL 02/24] target/arm: Correct MPUIR privilege level in register_cp_regs_for_features() conditional case
In reply to Peter MaydellFrom: Mathew Maidment <[email protected]>
The duplication of id_tlbtr_reginfo was unintentionally added within 3281af8114c6b8ead02f08b58e3c36895c1ea047 which should have been id_mpuir_reginfo.
The effect was that for OMAP and StrongARM CPUs we would incorrectly UNDEF writes to MPUIR rather than NOPing them.
Message-id: [email protected]
--- target/arm/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/helper.c +1 -1
@@ -5347,7 +5347,7 @@ void register_cp_regs_for_features(ARMCPU *cpu)for (r = id_cp_reginfo; r->type !=ARM_CP_SENTINEL ; r++) { r->access =PL1_RW ; } - id_tlbtr_reginfo.access =PL1_RW ; + id_mpuir_reginfo.access =PL1_RW ; id_tlbtr_reginfo.access =PL1_RW ; }if (arm_feature (env,ARM_FEATURE_V8 )) {
Signature · 1 line
2.17.0
[Qemu-devel] [PULL 04/24] hw/usb/tusb6010: Convert away from old_mmio
In reply to Peter MaydellConvert the tusb6010 device away from using the old_mmio field of MemoryRegionOps. This device is used only in the n800 and n810 boards.
Message-id: [email protected]
--- hw/usb/tusb6010.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-)
hw/usb/tusb6010.c +36 -4
@@ -641,11 +641,43 @@ static void tusb_async_writew(void *opaque, hwaddr addr, } } +static uint64_t tusb_async_readfn (void *opaque,hwaddr addr,unsigned size) +{ +switch (size) { +case 1 : +return tusb_async_readb (opaque, addr); +case 2 : +return tusb_async_readh (opaque, addr); +case 4 : +return tusb_async_readw (opaque, addr); +default : +g_assert_not_reached (); + } +} + +static void tusb_async_writefn (void *opaque,hwaddr addr, +uint64_t value,unsigned size) +{ +switch (size) { +case 1 : +tusb_async_writeb (opaque, addr, value); +break ; +case 2 : +tusb_async_writeh (opaque, addr, value); +break ; +case 4 : +tusb_async_writew (opaque, addr, value); +break ; +default : +g_assert_not_reached (); + } +} +static const MemoryRegionOps tusb_async_ops = { - .old_mmio = { - .read = { tusb_async_readb, tusb_async_readh, tusb_async_readw, }, - .write = { tusb_async_writeb, tusb_async_writeh, tusb_async_writew, }, - }, + .read = tusb_async_readfn, + .write = tusb_async_writefn, + .valid.min_access_size =1 , + .valid.max_access_size =4 , .endianness =DEVICE_NATIVE_ENDIAN , };
Signature · 1 line
2.17.0
[Qemu-devel] [PULL 01/24] hw/arm/virt: Add linux, pci-domain property
In reply to Peter MaydellFrom: Jan Kiszka <[email protected]>
This allows to pin the host controller in the Linux PCI domain space. Linux requires that property to be available consistently or not at all, in which case the domain number becomes unstable on additions/removals. Adding it here won't make a difference in practice for most setups as we only expose one controller.
However, enabling Jailhouse on top may introduce another controller, and that one would like to have stable address as well. So the property is needed for the first controller as well.
Message-id: [email protected]
--- hw/arm/virt.c | 1 + 1 file changed, 1 insertion(+)
hw/arm/virt.c +1 -0
@@ -1023,6 +1023,7 @@ static void create_pcie(const VirtMachineState *vms, qemu_irq *pic)qemu_fdt_setprop_string (vms->fdt, nodename,"device_type" ,"pci" );qemu_fdt_setprop_cell (vms->fdt, nodename,"#address-cells" ,3 );qemu_fdt_setprop_cell (vms->fdt, nodename,"#size-cells" ,2 ); +qemu_fdt_setprop_cell (vms->fdt, nodename,"linux,pci-domain" ,0 );qemu_fdt_setprop_cells (vms->fdt, nodename,"bus-range" ,0 , nr_pcie_buses -1 );qemu_fdt_setprop (vms->fdt, nodename,"dma-coherent" ,NULL ,0 );
Signature · 1 line
2.17.0
[Qemu-devel] [PULL 05/24] hw/net/smc91c111: Convert away from old_mmio
In reply to Peter MaydellConvert the smc91c111 device away from using the old_mmio field of MemoryRegionOps. This device is used by several Arm board models.
Message-id: [email protected]
--- hw/net/smc91c111.c | 54 +++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 29 deletions(-)
hw/net/smc91c111.c +25 -29
@@ -625,37 +625,33 @@ static uint32_t smc91c111_readb(void *opaque, hwaddr offset)return 0 ; } -static void smc91c111_writew (void *opaque,hwaddr offset, -uint32_t value) +static uint64_t smc91c111_readfn (void *opaque,hwaddr addr,unsigned size) { -smc91c111_writeb (opaque, offset, value &0xff ); -smc91c111_writeb (opaque, offset +1 , value >>8 ); +int i; +uint32_t val =0 ; + +for (i =0 ; i < size; i++) { + val |=smc91c111_readb (opaque, addr + i) << (i *8 ); + } +return val; } -static void smc91c111_writel (void *opaque,hwaddr offset, -uint32_t value) +static void smc91c111_writefn (void *opaque,hwaddr addr, +uint64_t value,unsigned size) { +int i =0 ; +/* 32-bit writes to offset 0xc only actually write to the bank select -register (offset 0xe) */ -if (offset !=0xc ) -smc91c111_writew (opaque, offset, value &0xffff ); -smc91c111_writew (opaque, offset +2 , value >>16 ); -} +* register (offset 0xe), so skip the first two bytes we would write. +*/ +if (addr ==0xc && size ==4 ) { + i +=2 ; + } -static uint32_t smc91c111_readw (void *opaque,hwaddr offset) -{ -uint32_t val; - val =smc91c111_readb (opaque, offset); - val |=smc91c111_readb (opaque, offset +1 ) <<8 ; -return val; -} - -static uint32_t smc91c111_readl (void *opaque,hwaddr offset) -{ -uint32_t val; - val =smc91c111_readw (opaque, offset); - val |=smc91c111_readw (opaque, offset +2 ) <<16 ; -return val; +for (; i < size; i++) { +smc91c111_writeb (opaque, addr + i, +extract32 (value, i *8 ,8 )); + } }static int smc91c111_can_receive_nc (NetClientState *nc)
@@ -747,10 +743,10 @@ static const MemoryRegionOps smc91c111_mem_ops = {/* The special case for 32 bit writes to 0xc means we can't just * set .impl.min/max_access_size to 1, unfortunately */ - .old_mmio = { - .read = { smc91c111_readb, smc91c111_readw, smc91c111_readl, }, - .write = { smc91c111_writeb, smc91c111_writew, smc91c111_writel, }, - }, + .read = smc91c111_readfn, + .write = smc91c111_writefn, + .valid.min_access_size = 1, + .valid.max_access_size = 4, .endianness = DEVICE_NATIVE_ENDIAN, };
Signature · 1 line
2.17.0
[Qemu-devel] [PULL 06/24] arm: boot: set boot_info starting from first_cpu
In reply to Peter MaydellFrom: Igor Mammedov <[email protected]>
Even though nothing is currently broken (since all boards use first_cpu as boot cpu), make sure that boot_info is set on all CPUs.
If some board would like support heterogenuos setup (i.e. init boot_info on subset of CPUs) in future, it should add a reasonable API to do it, instead of starting assigning boot_info from some CPU and till the end of present CPUs list.
Ref:
"Message-ID: <CAFEAcA_NMWuA8WSs3cNeY6xX1kerO_uAcN_3=fK02BEhHJW86g@mail.gmail.com>"
Message-id: [email protected]
--- hw/arm/boot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/arm/boot.c +1 -1
@@ -1170,7 +1170,7 @@ static void arm_load_kernel_notify(Notifier *notifier, void *data) } info->is_linux = is_linux; -for (cs =CPU (cpu); cs; cs =CPU_NEXT (cs)) { +for (cs = first_cpu; cs; cs =CPU_NEXT (cs)) {ARM_CPU (cs)->env.boot_info = info; } }
Signature · 1 line
2.17.0
[Qemu-devel] [PULL 07/24] target/arm: Tidy conditions in handle_vec_simd_shri
In reply to Peter MaydellFrom: Richard Henderson <[email protected]>
The (size > 3 && !is_q) condition is identical to the preceeding test of bit 3 in immh; eliminate it. For the benefit of Coverity, assert that size is within the bounds we expect.
Message-id: [email protected]
--- target/arm/translate-a64.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
target/arm/translate-a64.c +1 -5
@@ -9019,11 +9019,7 @@ static void handle_vec_simd_shri(DisasContext *s, bool is_q, bool is_u,unallocated_encoding (s);return ; } - -if (size >3 && !is_q) { -unallocated_encoding (s); -return ; - } +tcg_debug_assert (size <=3 );if (!fp_access_check (s)) {return ;
Signature · 1 line
2.17.0
[Qemu-devel] [PULL 08/24] target/arm: Tidy condition in disas_simd_two_reg_misc
In reply to Peter MaydellFrom: Richard Henderson <[email protected]>
Path analysis shows that size == 3 && !is_q has been eliminated.
Message-id: [email protected]
--- target/arm/translate-a64.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
target/arm/translate-a64.c +5 -1
@@ -11473,7 +11473,11 @@ static void disas_simd_two_reg_misc(DisasContext *s, uint32_t insn)/* All 64-bit element operations can be shared with scalar 2misc */ int pass; -for (pass =0 ; pass < (is_q ?2 :1 ); pass++) { +/* Coverity claims (size == 3 && !is_q) has been eliminated +* from all paths leading to here. +*/ +tcg_debug_assert (is_q); +for (pass =0 ; pass <2 ; pass++) {TCGv_i64 tcg_op =tcg_temp_new_i64 ();TCGv_i64 tcg_res =tcg_temp_new_i64 ();
Signature · 1 line
2.17.0
[Qemu-devel] [PULL 09/24] hw/arm: Don't fail qtest due to missing SD card in -nodefaults mode
In reply to Peter MaydellFrom: Thomas Huth <[email protected]>
When running omap1/2 or pxa2xx based ARM machines with -nodefaults, they bail out immediately complaining about a "missing SecureDigital device". That's not how the "default" devices in vl.c are meant to work - it should be possible for a board to also start up without default devices. So let's turn the error message and exit() into a warning instead.
Message-id: [email protected]
--- hw/arm/omap1.c | 8 ++++---- hw/arm/omap2.c | 8 ++++---- hw/arm/pxa2xx.c | 15 +++++++-------- 3 files changed, 15 insertions(+), 16 deletions(-)
hw/arm/omap1.c +4 -4
@@ -30,6 +30,7 @@#include "hw/arm/soc_dma.h" #include "sysemu/block-backend.h" #include "sysemu/blockdev.h" +#include "sysemu/qtest.h" #include "qemu/range.h" #include "hw/sysbus.h" #include "qemu/cutils.h"
@@ -3987,12 +3988,11 @@ struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *system_memory, omap_findclk(s, "dpll3")); dinfo =drive_get (IF_SD ,0 ,0 ); -if (!dinfo) { -error_report ("missing SecureDigital device" ); -exit (1 ); +if (!dinfo && !qtest_enabled ()) { +warn_report ("missing SecureDigital device" ); } s->mmc =omap_mmc_init (0xfffb7800 , system_memory, -blk_by_legacy_dinfo (dinfo), + dinfo ?blk_by_legacy_dinfo (dinfo) :NULL ,qdev_get_gpio_in (s->ih[1 ],OMAP_INT_OQN ), &s->drq[OMAP_DMA_MMC_TX ],omap_findclk (s,"mmc_ck" ));
hw/arm/omap2.c +4 -4
@@ -25,6 +25,7 @@#include "cpu.h" #include "sysemu/block-backend.h" #include "sysemu/blockdev.h" +#include "sysemu/qtest.h" #include "hw/boards.h" #include "hw/hw.h" #include "hw/arm/arm.h"
@@ -2486,12 +2487,11 @@ struct omap_mpu_state_s *omap2420_mpu_init(MemoryRegion *sysmem, s->drq[OMAP24XX_DMA_GPMC]); dinfo =drive_get (IF_SD ,0 ,0 ); -if (!dinfo) { -error_report ("missing SecureDigital device" ); -exit (1 ); +if (!dinfo && !qtest_enabled ()) { +warn_report ("missing SecureDigital device" ); } s->mmc =omap2_mmc_init (omap_l4tao (s->l4,9 ), -blk_by_legacy_dinfo (dinfo), + dinfo ?blk_by_legacy_dinfo (dinfo) :NULL ,qdev_get_gpio_in (s->ih[0 ],OMAP_INT_24XX_MMC_IRQ ), &s->drq[OMAP24XX_DMA_MMC1_TX ],omap_findclk (s,"mmc_fclk" ),omap_findclk (s,"mmc_iclk" ));
hw/arm/pxa2xx.c +7 -8
@@ -21,6 +21,7 @@#include "chardev/char-fe.h" #include "sysemu/block-backend.h" #include "sysemu/blockdev.h" +#include "sysemu/qtest.h" #include "qemu/cutils.h" static struct {
@@ -2095,12 +2096,11 @@ PXA2xxState *pxa270_init(MemoryRegion *address_space, s->gpio =pxa2xx_gpio_init (0x40e00000 , s->cpu, s->pic,121 ); dinfo =drive_get (IF_SD ,0 ,0 ); -if (!dinfo) { -error_report ("missing SecureDigital device" ); -exit (1 ); +if (!dinfo && !qtest_enabled ()) { +warn_report ("missing SecureDigital device" ); } s->mmc =pxa2xx_mmci_init (address_space,0x41100000 , -blk_by_legacy_dinfo (dinfo), + dinfo ?blk_by_legacy_dinfo (dinfo) :NULL ,qdev_get_gpio_in (s->pic,PXA2XX_PIC_MMC ),qdev_get_gpio_in (s->dma,PXA2XX_RX_RQ_MMCI ),qdev_get_gpio_in (s->dma,PXA2XX_TX_RQ_MMCI ));
@@ -2220,12 +2220,11 @@ PXA2xxState *pxa255_init(MemoryRegion *address_space, unsigned int sdram_size) s->gpio =pxa2xx_gpio_init (0x40e00000 , s->cpu, s->pic,85 ); dinfo =drive_get (IF_SD ,0 ,0 ); -if (!dinfo) { -error_report ("missing SecureDigital device" ); -exit (1 ); +if (!dinfo && !qtest_enabled ()) { +warn_report ("missing SecureDigital device" ); } s->mmc =pxa2xx_mmci_init (address_space,0x41100000 , -blk_by_legacy_dinfo (dinfo), + dinfo ?blk_by_legacy_dinfo (dinfo) :NULL ,qdev_get_gpio_in (s->pic,PXA2XX_PIC_MMC ),qdev_get_gpio_in (s->dma,PXA2XX_RX_RQ_MMCI ),qdev_get_gpio_in (s->dma,PXA2XX_TX_RQ_MMCI ));
Signature · 1 line
2.17.0
[Qemu-devel] [PULL 10/24] target/arm: Implement v8M VLLDM and VLSTM
In reply to Peter MaydellFor v8M the instructions VLLDM and VLSTM support lazy saving and restoring of the secure floating-point registers. Even if the floating point extension is not implemented, these instructions must act as NOPs in Secure state, so they can be used as part of the secure-to-nonsecure call sequence.
Message-id: [email protected]
--- target/arm/translate.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
target/arm/translate.c +16 -1
@@ -10795,8 +10795,23 @@ static void disas_thumb2_insn(DisasContext *s, uint32_t insn)/* Coprocessor. */ if (arm_dc_feature (s,ARM_FEATURE_M )) {/* We don't currently implement M profile FP support, -* so this entire space should give a NOCP fault. +* so this entire space should give a NOCP fault, with +* the exception of the v8M VLLDM and VLSTM insns, which +* must be NOPs in Secure state and UNDEF in Nonsecure state. */ +if (arm_dc_feature (s,ARM_FEATURE_V8 ) && + (insn &0xffa00f00 ) ==0xec200a00 ) { +/* 0b1110_1100_0x1x_xxxx_xxxx_1010_xxxx_xxxx +* - VLLDM, VLSTM +* We choose to UNDEF if the RAZ bits are non-zero. +*/ +if (!s->v8m_secure || (insn &0x0040f0ff )) { + goto illegal_op; + } +/* Just NOP since FP support is not implemented */ +break ; + } +/* All other insns: NOCP */ gen_exception_insn (s,4 ,EXCP_NOCP ,syn_uncategorized (),default_exception_el (s));break ;
Signature · 1 line
2.17.0
[Qemu-devel] [PULL 11/24] hw/arm/smmu-common: smmu base device and datatypes
In reply to Peter MaydellFrom: Eric Auger <[email protected]>
The patch introduces the smmu base device and class for the ARM smmu. Devices for specific versions will be derived from this base device.
We also introduce some important datatypes.
Message-id: [email protected]
--- hw/arm/Makefile.objs | 1 + include/hw/arm/smmu-common.h | 123 ++++++++++++++++++++++++++++ hw/arm/smmu-common.c | 81 ++++++++++++++++++ default-configs/aarch64-softmmu.mak | 1 + 4 files changed, 206 insertions(+) create mode 100644 include/hw/arm/smmu-common.h create mode 100644 hw/arm/smmu-common.c
hw/arm/Makefile.objs +1 -0
@@ -35,3 +35,4 @@ obj-$(CONFIG_MPS2) += mps2-tz.o obj-$(CONFIG_MSF2) += msf2-soc.o msf2-som.o obj-$(CONFIG_IOTKIT) += iotkit.o obj-$(CONFIG_FSL_IMX7) += fsl-imx7.o mcimx7d-sabre.o +obj-$(CONFIG_ARM_SMMUV3) += smmu-common.o
include/hw/arm/smmu-common.h new file +123 -0
123 lines not on this page · raw message
hw/arm/smmu-common.c new file +81 -0
81 lines not on this page · raw message
default-configs/aarch64-softmmu.mak +1 -0
@@ -8,3 +8,4 @@ CONFIG_DDC=y CONFIG_DPCD=y CONFIG_XLNX_ZYNQMP=y CONFIG_XLNX_ZYNQMP_ARM=y +CONFIG_ARM_SMMUV3=y
Signature · 1 line
2.17.0
[Qemu-devel] [PULL 12/24] hw/arm/smmu-common: IOMMU memory region and address space setup
In reply to Peter MaydellFrom: Eric Auger <[email protected]>
We set up the infrastructure to enumerate all the PCI devices attached to the SMMU and create an associated IOMMU memory region and address space.
Those info are stored in SMMUDevice objects. The devices are grouped according to the PCIBus they belong to. A hash table indexed by the PCIBus pointer is used. Also an array indexed by the bus number allows to find the list of SMMUDevices.
Message-id: [email protected]
--- include/hw/arm/smmu-common.h | 8 +++++ hw/arm/smmu-common.c | 69 ++++++++++++++++++++++++++++++++++++ hw/arm/trace-events | 3 ++ 3 files changed, 80 insertions(+)
include/hw/arm/smmu-common.h +8 -0
@@ -120,4 +120,12 @@ typedef struct {#define ARM_SMMU_GET_CLASS (obj) \ OBJECT_GET_CLASS(SMMUBaseClass, (obj), TYPE_ARM_SMMU) +/* Return the SMMUPciBus handle associated to a PCI bus number */ +SMMUPciBus *smmu_find_smmu_pcibus (SMMUState *s,uint8_t bus_num); + +/* Return the stream ID of an SMMU device */ +static inline uint16_t smmu_get_sid (SMMUDevice *sdev) +{ +return PCI_BUILD_BDF (pci_bus_num (sdev->bus), sdev->devfn); +}#endif /* HW_ARM_SMMU_COMMON */
hw/arm/smmu-common.c +69 -0
83 lines not on this page · raw message
hw/arm/trace-events +3 -0
@@ -2,3 +2,6 @@ # hw/arm/virt-acpi-build.c virt_acpi_setup(void) "No fw cfg or ACPI disabled. Bailing out." + +# hw/arm/smmu-common.c +smmu_add_mr(const char *name) "%s"
Signature · 1 line
2.17.0
[Qemu-devel] [PULL 15/24] hw/arm/smmuv3: Wired IRQ and GERROR helpers
In reply to Peter MaydellFrom: Eric Auger <[email protected]>
We introduce some helpers to handle wired IRQs and especially GERROR interrupt. SMMU writes GERROR register on GERROR event and SW acks GERROR interrupts by setting GERRORn.
The Wired interrupts are edge sensitive hence the pulse usage.
Message-id: [email protected]
--- hw/arm/smmuv3-internal.h | 14 +++++++++ hw/arm/smmuv3.c | 64 ++++++++++++++++++++++++++++++++++++++++ hw/arm/trace-events | 3 ++ 3 files changed, 81 insertions(+)
hw/arm/smmuv3-internal.h +14 -0
@@ -139,4 +139,18 @@ static inline uint32_t smmuv3_idreg(int regoffset) return smmuv3_ids[regoffset / 4]; } +static inline bool smmuv3_eventq_irq_enabled (SMMUv3State *s) +{ +return FIELD_EX32 (s->irq_ctrl,IRQ_CTRL ,EVENTQ_IRQEN ); +} + +static inline bool smmuv3_gerror_irq_enabled (SMMUv3State *s) +{ +return FIELD_EX32 (s->irq_ctrl,IRQ_CTRL ,GERROR_IRQEN ); +} + +/* public until callers get introduced */ +void smmuv3_trigger_irq (SMMUv3State *s,SMMUIrq irq,uint32_t gerror_mask); +void smmuv3_write_gerrorn (SMMUv3State *s,uint32_t gerrorn); +#endif
hw/arm/smmuv3.c +64 -0
70 lines not on this page · raw message
hw/arm/trace-events +3 -0
@@ -15,3 +15,6 @@ smmu_get_pte(uint64_t baseaddr, int index, uint64_t pteaddr, uint64_t pte) "base #hw/arm/smmuv3.c smmuv3_read_mmio(uint64_t addr, uint64_t val, unsigned size, uint32_t r) "addr: 0x%"PRIx64" val:0x%"PRIx64" size: 0x%x(%d)" +smmuv3_trigger_irq(int irq) "irq=%d" +smmuv3_write_gerror(uint32_t toggled, uint32_t gerror) "toggled=0x%x, new GERROR=0x%x" +smmuv3_write_gerrorn(uint32_t acked, uint32_t gerrorn) "acked=0x%x, new GERRORN=0x%x"
Signature · 1 line
2.17.0
[Qemu-devel] [PULL 13/24] hw/arm/smmu-common: VMSAv8-64 page table walk
In reply to Peter MaydellFrom: Eric Auger <[email protected]>
This patch implements the page table walk for VMSAv8-64.
Message-id: [email protected]
--- hw/arm/smmu-internal.h | 99 ++++++++++++++++ include/hw/arm/smmu-common.h | 14 +++ hw/arm/smmu-common.c | 222 +++++++++++++++++++++++++++++++++++ hw/arm/trace-events | 9 +- 4 files changed, 343 insertions(+), 1 deletion(-) create mode 100644 hw/arm/smmu-internal.h
hw/arm/smmu-internal.h new file +99 -0
@@ -0,0 +1,99 @@ +/* +* ARM SMMU support - Internal API +* +* Copyright (c) 2017 Red Hat, Inc. +* Copyright (C) 2014-2016 Broadcom Corporation +* Written by Prem Mallappa, Eric Auger +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HW_ARM_SMMU_INTERNAL_H +#define HW_ARM_SMMU_INTERNAL_H + +#define TBI0 (tbi) ((tbi) & 0x1) +#define TBI1 (tbi) ((tbi) & 0x2 >> 1) + +/* PTE Manipulation */ + +#define ARM_LPAE_PTE_TYPE_SHIFT 0 +#define ARM_LPAE_PTE_TYPE_MASK 0x3 + +#define ARM_LPAE_PTE_TYPE_BLOCK 1 +#define ARM_LPAE_PTE_TYPE_TABLE 3 + +#define ARM_LPAE_L3_PTE_TYPE_RESERVED 1 +#define ARM_LPAE_L3_PTE_TYPE_PAGE 3 + +#define ARM_LPAE_PTE_VALID (1 << 0) + +#define PTE_ADDRESS (pte, shift) \ + (extract64(pte, shift, 47 - shift + 1) << shift) + +#define is_invalid_pte (pte) (!(pte & ARM_LPAE_PTE_VALID)) + +#define is_reserved_pte (pte, level) \ + ((level == 3) && \ + ((pte & ARM_LPAE_PTE_TYPE_MASK) == ARM_LPAE_L3_PTE_TYPE_RESERVED)) + +#define is_block_pte (pte, level) \ + ((level < 3) && \ + ((pte & ARM_LPAE_PTE_TYPE_MASK) == ARM_LPAE_PTE_TYPE_BLOCK)) + +#define is_table_pte (pte, level) \ + ((level < 3) && \ + ((pte & ARM_LPAE_PTE_TYPE_MASK) == ARM_LPAE_PTE_TYPE_TABLE)) + +#define is_page_pte (pte, level) \ + ((level == 3) && \ + ((pte & ARM_LPAE_PTE_TYPE_MASK) == ARM_LPAE_L3_PTE_TYPE_PAGE)) + +/* access permissions */ + +#define PTE_AP (pte) \ + (extract64(pte, 6, 2)) + +#define PTE_APTABLE (pte) \ + (extract64(pte, 61, 2)) + +/* +* TODO: At the moment all transactions are considered as privileged (EL1) +* as IOMMU translation callback does not pass user/priv attributes. +*/ +#define is_permission_fault (ap, perm) \ + (((perm) & IOMMU_WO) && ((ap) & 0x2)) + +#define PTE_AP_TO_PERM (ap) \ + (IOMMU_ACCESS_FLAG(true, !((ap) & 0x2))) + +/* Level Indexing */ + +static inline int level_shift (int level,int granule_sz) +{ +return granule_sz + (3 - level) * (granule_sz -3 ); +} + +static inline uint64_t level_page_mask (int level,int granule_sz) +{ +return ~(MAKE_64BIT_MASK (0 ,level_shift (level, granule_sz))); +} + +static inline +uint64_t iova_level_offset (uint64_t iova,int inputsize, +int level,int gsz) +{ +return ((iova &MAKE_64BIT_MASK (0 , inputsize)) >>level_shift (level, gsz)) & +MAKE_64BIT_MASK (0 , gsz -3 ); +} + +#endif
include/hw/arm/smmu-common.h +14 -0
@@ -128,4 +128,18 @@ static inline uint16_t smmu_get_sid(SMMUDevice *sdev) {return PCI_BUILD_BDF (pci_bus_num (sdev->bus), sdev->devfn); } + +/** +* smmu_ptw - Perform the page table walk for a given iova / access flags +* pair, according to @cfg translation config +*/ +int smmu_ptw (SMMUTransCfg *cfg,dma_addr_t iova,IOMMUAccessFlags perm, +IOMMUTLBEntry *tlbe,SMMUPTWEventInfo *info); + +/** +* select_tt - compute which translation table shall be used according to +* the input iova and translation config and return the TT specific info +*/ +SMMUTransTableInfo *select_tt (SMMUTransCfg *cfg,dma_addr_t iova); +#endif /* HW_ARM_SMMU_COMMON */
hw/arm/smmu-common.c +222 -0
228 lines not on this page · raw message
hw/arm/trace-events +8 -1
@@ -4,4 +4,11 @@ virt_acpi_setup(void) "No fw cfg or ACPI disabled. Bailing out." # hw/arm/smmu-common.c -smmu_add_mr(const char *name) "%s" +smmu_add_mr(const char *name) "%s" +smmu_page_walk(int stage, uint64_t baseaddr, int first_level, uint64_t start, uint64_t end) "stage=%d, baseaddr=0x%"PRIx64", first level=%d, start=0x%"PRIx64", end=0x%"PRIx64 +smmu_lookup_table(int level, uint64_t baseaddr, int granule_sz, uint64_t start, uint64_t end, int flags, uint64_t subpage_size) "level=%d baseaddr=0x%"PRIx64" granule=%d, start=0x%"PRIx64" end=0x%"PRIx64" flags=%d subpage_size=0x%"PRIx64 +smmu_ptw_level(int level, uint64_t iova, size_t subpage_size, uint64_t baseaddr, uint32_t offset, uint64_t pte) "level=%d iova=0x%"PRIx64" subpage_sz=0x%lx baseaddr=0x%"PRIx64" offset=%d => pte=0x%"PRIx64 +smmu_ptw_invalid_pte(int stage, int level, uint64_t baseaddr, uint64_t pteaddr, uint32_t offset, uint64_t pte) "stage=%d level=%d base@=0x%"PRIx64" pte@=0x%"PRIx64" offset=%d pte=0x%"PRIx64 +smmu_ptw_page_pte(int stage, int level, uint64_t iova, uint64_t baseaddr, uint64_t pteaddr, uint64_t pte, uint64_t address) "stage=%d level=%d iova=0x%"PRIx64" base@=0x%"PRIx64" pte@=0x%"PRIx64" pte=0x%"PRIx64" page address = 0x%"PRIx64 +smmu_ptw_block_pte(int stage, int level, uint64_t baseaddr, uint64_t pteaddr, uint64_t pte, uint64_t iova, uint64_t gpa, int bsize_mb) "stage=%d level=%d base@=0x%"PRIx64" pte@=0x%"PRIx64" pte=0x%"PRIx64" iova=0x%"PRIx64" block address = 0x%"PRIx64" block size = %d MiB" +smmu_get_pte(uint64_t baseaddr, int index, uint64_t pteaddr, uint64_t pte) "baseaddr=0x%"PRIx64" index=0x%x, pteaddr=0x%"PRIx64", pte=0x%"PRIx64
Signature · 1 line
2.17.0
Re: [Qemu-devel] [PULL 13/24] hw/arm/smmu-common: VMSAv8-64 page table walk
Quoted 3 lines · Peter Maydell
From: Eric Auger <[email protected]>
This patch implements the page table walk for VMSAv8-64.
Hi Eric;
hw/arm/smmu-common.c line 88
Quoted 9 lines
+ *
get_block_pte_address- return block descriptor output address and block size
+ * ARM ARM Figure D4-16 VMSAv8-64 level0, level1, and level 2 descriptor formats
+ */hw/arm/smmu-common.c +6
-0+static inline hwaddr get_block_pte_address (uint64_t pte,int level, +int granule_sz,uint64_t *bsz) +{ +int n = (granule_sz -3 ) * (4 - level) +3 ; + + *bsz =1 << n;
Coverity (CID 1391010) points out that this can overflow if n > 31, because it's only doing 32-bit arithmetic.
I think this is possible for some page table formats, so using "1ULL" rather than "1" should make coverity happy.
Incidentally, isn't
int n = (granule_sz - 3) * (4 - level) + 3;
equivalent to
int n = level_shift(level, granule_sz);
?
Review
Quoted 2 lines
(quoted diff) +2
-0+ return PTE_ADDRESS(pte, n); +}
thanks
-- PMM
[Qemu-devel] [PULL 14/24] hw/arm/smmuv3: Skeleton
In reply to Peter MaydellFrom: Prem Mallappa <[email protected]>
This patch implements a skeleton for the smmuv3 device. Datatypes and register definitions are introduced. The MMIO region, the interrupts and the queue are initialized.
Only the MMIO read operation is implemented here.
Message-id: [email protected]
--- hw/arm/Makefile.objs | 2 +- hw/arm/smmuv3-internal.h | 142 +++++++++++++++ include/hw/arm/smmuv3.h | 87 ++++++++++ hw/arm/smmuv3.c | 366 +++++++++++++++++++++++++++++++++++++++ hw/arm/trace-events | 3 + 5 files changed, 599 insertions(+), 1 deletion(-) create mode 100644 hw/arm/smmuv3-internal.h create mode 100644 include/hw/arm/smmuv3.h create mode 100644 hw/arm/smmuv3.c
hw/arm/Makefile.objs +1 -1
@@ -35,4 +35,4 @@ obj-$(CONFIG_MPS2) += mps2-tz.o obj-$(CONFIG_MSF2) += msf2-soc.o msf2-som.o obj-$(CONFIG_IOTKIT) += iotkit.o obj-$(CONFIG_FSL_IMX7) += fsl-imx7.o mcimx7d-sabre.o -obj-$(CONFIG_ARM_SMMUV3) += smmu-common.o +obj-$(CONFIG_ARM_SMMUV3) += smmu-common.o smmuv3.o
hw/arm/smmuv3-internal.h new file +142 -0
142 lines not on this page · raw message
include/hw/arm/smmuv3.h new file +87 -0
87 lines not on this page · raw message
hw/arm/smmuv3.c new file +366 -0
366 lines not on this page · raw message
hw/arm/trace-events +3 -0
@@ -12,3 +12,6 @@ smmu_ptw_invalid_pte(int stage, int level, uint64_t baseaddr, uint64_t pteaddr, smmu_ptw_page_pte(int stage, int level, uint64_t iova, uint64_t baseaddr, uint64_t pteaddr, uint64_t pte, uint64_t address) "stage=%d level=%d iova=0x%"PRIx64" base@=0x%"PRIx64" pte@=0x%"PRIx64" pte=0x%"PRIx64" page address = 0x%"PRIx64 smmu_ptw_block_pte(int stage, int level, uint64_t baseaddr, uint64_t pteaddr, uint64_t pte, uint64_t iova, uint64_t gpa, int bsize_mb) "stage=%d level=%d base@=0x%"PRIx64" pte@=0x%"PRIx64" pte=0x%"PRIx64" iova=0x%"PRIx64" block address = 0x%"PRIx64" block size = %d MiB" smmu_get_pte(uint64_t baseaddr, int index, uint64_t pteaddr, uint64_t pte) "baseaddr=0x%"PRIx64" index=0x%x, pteaddr=0x%"PRIx64", pte=0x%"PRIx64 + +#hw/arm/smmuv3.c +smmuv3_read_mmio(uint64_t addr, uint64_t val, unsigned size, uint32_t r) "addr: 0x%"PRIx64" val:0x%"PRIx64" size: 0x%x(%d)"
Signature · 1 line
2.17.0
[Qemu-devel] [PULL 16/24] hw/arm/smmuv3: Queue helpers
In reply to Peter MaydellFrom: Eric Auger <[email protected]>
We introduce helpers to read/write into the command and event circular queues.
smmuv3_write_eventq and smmuv3_cmq_consume will become static in subsequent patches.
Invalidation commands are not yet dealt with. We do not cache data that need to be invalidated. This will change with vhost integration.
Message-id: [email protected]
--- hw/arm/smmuv3-internal.h | 163 +++++++++++++++++++++++++++++++++++++++ hw/arm/smmuv3.c | 136 ++++++++++++++++++++++++++++++++ hw/arm/trace-events | 5 ++ 3 files changed, 304 insertions(+)
hw/arm/smmuv3-internal.h +163 -0
@@ -153,4 +153,167 @@ static inline bool smmuv3_gerror_irq_enabled(SMMUv3State *s)void smmuv3_trigger_irq (SMMUv3State *s,SMMUIrq irq,uint32_t gerror_mask);void smmuv3_write_gerrorn (SMMUv3State *s,uint32_t gerrorn); +/* Queue Handling */ + +#define Q_BASE (q) ((q)->base & SMMU_BASE_ADDR_MASK) +#define WRAP_MASK (q) (1 << (q)->log2size) +#define INDEX_MASK (q) (((1 << (q)->log2size)) - 1) +#define WRAP_INDEX_MASK (q) ((1 << ((q)->log2size + 1)) - 1) + +#define Q_CONS (q) ((q)->cons & INDEX_MASK(q)) +#define Q_PROD (q) ((q)->prod & INDEX_MASK(q)) + +#define Q_CONS_ENTRY (q) (Q_BASE(q) + (q)->entry_size * Q_CONS(q)) +#define Q_PROD_ENTRY (q) (Q_BASE(q) + (q)->entry_size * Q_PROD(q)) + +#define Q_CONS_WRAP (q) (((q)->cons & WRAP_MASK(q)) >> (q)->log2size) +#define Q_PROD_WRAP (q) (((q)->prod & WRAP_MASK(q)) >> (q)->log2size) + +static inline bool smmuv3_q_full (SMMUQueue *q) +{ +return ((q->cons ^ q->prod) &WRAP_INDEX_MASK (q)) ==WRAP_MASK (q); +} + +static inline bool smmuv3_q_empty (SMMUQueue *q) +{ +return (q->cons &WRAP_INDEX_MASK (q)) == (q->prod &WRAP_INDEX_MASK (q)); +} + +static inline void queue_prod_incr (SMMUQueue *q) +{ + q->prod = (q->prod +1 ) &WRAP_INDEX_MASK (q); +} + +static inline void queue_cons_incr (SMMUQueue *q) +{ +/* +* We have to use deposit for the CONS registers to preserve +* the ERR field in the high bits. +*/ + q->cons =deposit32 (q->cons,0 , q->log2size +1 , q->cons +1 ); +} + +static inline bool smmuv3_cmdq_enabled (SMMUv3State *s) +{ +return FIELD_EX32 (s->cr[0 ],CR0 ,CMDQEN ); +} + +static inline bool smmuv3_eventq_enabled (SMMUv3State *s) +{ +return FIELD_EX32 (s->cr[0 ],CR0 ,EVENTQEN ); +} + +static inline void smmu_write_cmdq_err (SMMUv3State *s,uint32_t err_type) +{ + s->cmdq.cons =FIELD_DP32 (s->cmdq.cons,CMDQ_CONS ,ERR , err_type); +} + +void smmuv3_write_eventq (SMMUv3State *s,Evt *evt); + +/* Commands */ + +typedef enum SMMUCommandType { +SMMU_CMD_NONE =0x00 , +SMMU_CMD_PREFETCH_CONFIG , +SMMU_CMD_PREFETCH_ADDR , +SMMU_CMD_CFGI_STE , +SMMU_CMD_CFGI_STE_RANGE , +SMMU_CMD_CFGI_CD , +SMMU_CMD_CFGI_CD_ALL , +SMMU_CMD_CFGI_ALL , +SMMU_CMD_TLBI_NH_ALL =0x10 , +SMMU_CMD_TLBI_NH_ASID , +SMMU_CMD_TLBI_NH_VA , +SMMU_CMD_TLBI_NH_VAA , +SMMU_CMD_TLBI_EL3_ALL =0x18 , +SMMU_CMD_TLBI_EL3_VA =0x1a , +SMMU_CMD_TLBI_EL2_ALL =0x20 , +SMMU_CMD_TLBI_EL2_ASID , +SMMU_CMD_TLBI_EL2_VA , +SMMU_CMD_TLBI_EL2_VAA , +SMMU_CMD_TLBI_S12_VMALL =0x28 , +SMMU_CMD_TLBI_S2_IPA =0x2a , +SMMU_CMD_TLBI_NSNH_ALL =0x30 , +SMMU_CMD_ATC_INV =0x40 , +SMMU_CMD_PRI_RESP , +SMMU_CMD_RESUME =0x44 , +SMMU_CMD_STALL_TERM , +SMMU_CMD_SYNC , +}SMMUCommandType ; + +static const char *cmd_stringify[] = { + [SMMU_CMD_PREFETCH_CONFIG ] ="SMMU_CMD_PREFETCH_CONFIG" , + [SMMU_CMD_PREFETCH_ADDR ] ="SMMU_CMD_PREFETCH_ADDR" , + [SMMU_CMD_CFGI_STE ] ="SMMU_CMD_CFGI_STE" , + [SMMU_CMD_CFGI_STE_RANGE ] ="SMMU_CMD_CFGI_STE_RANGE" , + [SMMU_CMD_CFGI_CD ] ="SMMU_CMD_CFGI_CD" , + [SMMU_CMD_CFGI_CD_ALL ] ="SMMU_CMD_CFGI_CD_ALL" , + [SMMU_CMD_CFGI_ALL ] ="SMMU_CMD_CFGI_ALL" , + [SMMU_CMD_TLBI_NH_ALL ] ="SMMU_CMD_TLBI_NH_ALL" , + [SMMU_CMD_TLBI_NH_ASID ] ="SMMU_CMD_TLBI_NH_ASID" , + [SMMU_CMD_TLBI_NH_VA ] ="SMMU_CMD_TLBI_NH_VA" , + [SMMU_CMD_TLBI_NH_VAA ] ="SMMU_CMD_TLBI_NH_VAA" , + [SMMU_CMD_TLBI_EL3_ALL ] ="SMMU_CMD_TLBI_EL3_ALL" , + [SMMU_CMD_TLBI_EL3_VA ] ="SMMU_CMD_TLBI_EL3_VA" , + [SMMU_CMD_TLBI_EL2_ALL ] ="SMMU_CMD_TLBI_EL2_ALL" , + [SMMU_CMD_TLBI_EL2_ASID ] ="SMMU_CMD_TLBI_EL2_ASID" , + [SMMU_CMD_TLBI_EL2_VA ] ="SMMU_CMD_TLBI_EL2_VA" , + [SMMU_CMD_TLBI_EL2_VAA ] ="SMMU_CMD_TLBI_EL2_VAA" , + [SMMU_CMD_TLBI_S12_VMALL ] ="SMMU_CMD_TLBI_S12_VMALL" , + [SMMU_CMD_TLBI_S2_IPA ] ="SMMU_CMD_TLBI_S2_IPA" , + [SMMU_CMD_TLBI_NSNH_ALL ] ="SMMU_CMD_TLBI_NSNH_ALL" , + [SMMU_CMD_ATC_INV ] ="SMMU_CMD_ATC_INV" , + [SMMU_CMD_PRI_RESP ] ="SMMU_CMD_PRI_RESP" , + [SMMU_CMD_RESUME ] ="SMMU_CMD_RESUME" , + [SMMU_CMD_STALL_TERM ] ="SMMU_CMD_STALL_TERM" , + [SMMU_CMD_SYNC ] ="SMMU_CMD_SYNC" , +}; + +static inline const char *smmu_cmd_string (SMMUCommandType type) +{ +if (type >SMMU_CMD_NONE && type <ARRAY_SIZE (cmd_stringify)) { +return cmd_stringify[type] ? cmd_stringify[type] :"UNKNOWN" ; + }else { +return "INVALID" ; + } +} + +/* CMDQ fields */ + +typedef enum { +SMMU_CERROR_NONE =0 , +SMMU_CERROR_ILL , +SMMU_CERROR_ABT , +SMMU_CERROR_ATC_INV_SYNC , +}SMMUCmdError ; + +enum {/* Command completion notification */ +CMD_SYNC_SIG_NONE , +CMD_SYNC_SIG_IRQ , +CMD_SYNC_SIG_SEV , +}; + +#define CMD_TYPE (x) extract32((x)->word[0], 0 , 8) +#define CMD_SSEC (x) extract32((x)->word[0], 10, 1) +#define CMD_SSV (x) extract32((x)->word[0], 11, 1) +#define CMD_RESUME_AC (x) extract32((x)->word[0], 12, 1) +#define CMD_RESUME_AB (x) extract32((x)->word[0], 13, 1) +#define CMD_SYNC_CS (x) extract32((x)->word[0], 12, 2) +#define CMD_SSID (x) extract32((x)->word[0], 12, 20) +#define CMD_SID (x) ((x)->word[1]) +#define CMD_VMID (x) extract32((x)->word[1], 0 , 16) +#define CMD_ASID (x) extract32((x)->word[1], 16, 16) +#define CMD_RESUME_STAG (x) extract32((x)->word[2], 0 , 16) +#define CMD_RESP (x) extract32((x)->word[2], 11, 2) +#define CMD_LEAF (x) extract32((x)->word[2], 0 , 1) +#define CMD_STE_RANGE (x) extract32((x)->word[2], 0 , 5) +#define CMD_ADDR (x) ({ \ + uint64_t high = (uint64_t)(x)->word[3]; \ + uint64_t low = extract32((x)->word[2], 12, 20); \ + uint64_t addr = high << 32 | (low << 12); \ + addr; \ + }) + +int smmuv3_cmdq_consume (SMMUv3State *s); +#endif
hw/arm/smmuv3.c +136 -0
148 lines not on this page · raw message
hw/arm/trace-events +5 -0
@@ -18,3 +18,8 @@ smmuv3_read_mmio(uint64_t addr, uint64_t val, unsigned size, uint32_t r) "addr: smmuv3_trigger_irq(int irq) "irq=%d" smmuv3_write_gerror(uint32_t toggled, uint32_t gerror) "toggled=0x%x, new GERROR=0x%x" smmuv3_write_gerrorn(uint32_t acked, uint32_t gerrorn) "acked=0x%x, new GERRORN=0x%x" +smmuv3_unhandled_cmd(uint32_t type) "Unhandled command type=%d" +smmuv3_cmdq_consume(uint32_t prod, uint32_t cons, uint8_t prod_wrap, uint8_t cons_wrap) "prod=%d cons=%d prod.wrap=%d cons.wrap=%d" +smmuv3_cmdq_opcode(const char *opcode) "<--- %s" +smmuv3_cmdq_consume_out(uint32_t prod, uint32_t cons, uint8_t prod_wrap, uint8_t cons_wrap) "prod:%d, cons:%d, prod_wrap:%d, cons_wrap:%d " +smmuv3_cmdq_consume_error(const char *cmd_name, uint8_t cmd_error) "Error on %s command execution: %d"
Signature · 1 line
2.17.0
[Qemu-devel] [PULL 17/24] hw/arm/smmuv3: Implement MMIO write operations
In reply to Peter MaydellFrom: Eric Auger <[email protected]>
Now we have relevant helpers for queue and irq management, let's implement MMIO write operations.
Message-id: [email protected]
--- hw/arm/smmuv3-internal.h | 8 +- hw/arm/smmuv3.c | 170 +++++++++++++++++++++++++++++++++++++-- hw/arm/trace-events | 6 ++ 3 files changed, 174 insertions(+), 10 deletions(-)
hw/arm/smmuv3-internal.h +3 -5
@@ -61,6 +61,8 @@ REG32(CR0, 0x20) FIELD(CR0, EVENTQEN, 2, 1) FIELD(CR0, CMDQEN, 3, 1) +#define SMMU_CR0_RESERVED 0xFFFFFC20 + REG32(CR0ACK, 0x24) REG32(CR1, 0x28)REG32 (CR2 ,0x2c )
@@ -149,10 +151,6 @@ static inline bool smmuv3_gerror_irq_enabled(SMMUv3State *s)return FIELD_EX32 (s->irq_ctrl,IRQ_CTRL ,GERROR_IRQEN ); } -/* public until callers get introduced */ -void smmuv3_trigger_irq (SMMUv3State *s,SMMUIrq irq,uint32_t gerror_mask); -void smmuv3_write_gerrorn (SMMUv3State *s,uint32_t gerrorn); -/* Queue Handling */ #define Q_BASE (q) ((q)->base & SMMU_BASE_ADDR_MASK)
@@ -314,6 +312,6 @@ enum { /* Command completion notification */ addr; \ }) -int smmuv3_cmdq_consume (SMMUv3State *s); +#define SMMU_FEATURE_2LVL_STE (1 << 0)#endif
hw/arm/smmuv3.c +165 -5
197 lines not on this page · raw message
hw/arm/trace-events +6 -0
@@ -23,3 +23,9 @@ smmuv3_cmdq_consume(uint32_t prod, uint32_t cons, uint8_t prod_wrap, uint8_t con smmuv3_cmdq_opcode(const char *opcode) "<--- %s" smmuv3_cmdq_consume_out(uint32_t prod, uint32_t cons, uint8_t prod_wrap, uint8_t cons_wrap) "prod:%d, cons:%d, prod_wrap:%d, cons_wrap:%d " smmuv3_cmdq_consume_error(const char *cmd_name, uint8_t cmd_error) "Error on %s command execution: %d" +smmuv3_update(bool is_empty, uint32_t prod, uint32_t cons, uint8_t prod_wrap, uint8_t cons_wrap) "q empty:%d prod:%d cons:%d p.wrap:%d p.cons:%d" +smmuv3_update_check_cmd(int error) "cmdq not enabled or error :0x%x" +smmuv3_write_mmio(uint64_t addr, uint64_t val, unsigned size, uint32_t r) "addr: 0x%"PRIx64" val:0x%"PRIx64" size: 0x%x(%d)" +smmuv3_write_mmio_idr(uint64_t addr, uint64_t val) "write to RO/Unimpl reg 0x%lx val64:0x%lx" +smmuv3_write_mmio_evtq_cons_bef_clear(uint32_t prod, uint32_t cons, uint8_t prod_wrap, uint8_t cons_wrap) "Before clearing interrupt prod:0x%x cons:0x%x prod.w:%d cons.w:%d" +smmuv3_write_mmio_evtq_cons_after_clear(uint32_t prod, uint32_t cons, uint8_t prod_wrap, uint8_t cons_wrap) "after clearing interrupt prod:0x%x cons:0x%x prod.w:%d cons.w:%d"
Signature · 1 line
2.17.0
[Qemu-devel] [PULL 18/24] hw/arm/smmuv3: Event queue recording helper
In reply to Peter MaydellFrom: Eric Auger <[email protected]>
Let's introduce a helper function aiming at recording an event in the event queue.
Message-id: [email protected]
--- hw/arm/smmuv3-internal.h | 148 ++++++++++++++++++++++++++++++++++++++- hw/arm/smmuv3.c | 108 ++++++++++++++++++++++++++-- hw/arm/trace-events | 1 + 3 files changed, 249 insertions(+), 8 deletions(-)
hw/arm/smmuv3-internal.h +146 -2
@@ -206,8 +206,6 @@ static inline void smmu_write_cmdq_err(SMMUv3State *s, uint32_t err_type) s->cmdq.cons =FIELD_DP32 (s->cmdq.cons,CMDQ_CONS ,ERR , err_type); } -void smmuv3_write_eventq (SMMUv3State *s,Evt *evt); -/* Commands */ typedef enum SMMUCommandType {
@@ -314,4 +312,150 @@ enum { /* Command completion notification */#define SMMU_FEATURE_2LVL_STE (1 << 0) +/* Events */ + +typedef enum SMMUEventType { +SMMU_EVT_OK =0x00 , +SMMU_EVT_F_UUT , +SMMU_EVT_C_BAD_STREAMID , +SMMU_EVT_F_STE_FETCH , +SMMU_EVT_C_BAD_STE , +SMMU_EVT_F_BAD_ATS_TREQ , +SMMU_EVT_F_STREAM_DISABLED , +SMMU_EVT_F_TRANS_FORBIDDEN , +SMMU_EVT_C_BAD_SUBSTREAMID , +SMMU_EVT_F_CD_FETCH , +SMMU_EVT_C_BAD_CD , +SMMU_EVT_F_WALK_EABT , +SMMU_EVT_F_TRANSLATION =0x10 , +SMMU_EVT_F_ADDR_SIZE , +SMMU_EVT_F_ACCESS , +SMMU_EVT_F_PERMISSION , +SMMU_EVT_F_TLB_CONFLICT =0x20 , +SMMU_EVT_F_CFG_CONFLICT , +SMMU_EVT_E_PAGE_REQ =0x24 , +}SMMUEventType ; + +static const char *event_stringify[] = { + [SMMU_EVT_OK ] ="SMMU_EVT_OK" , + [SMMU_EVT_F_UUT ] ="SMMU_EVT_F_UUT" , + [SMMU_EVT_C_BAD_STREAMID ] ="SMMU_EVT_C_BAD_STREAMID" , + [SMMU_EVT_F_STE_FETCH ] ="SMMU_EVT_F_STE_FETCH" , + [SMMU_EVT_C_BAD_STE ] ="SMMU_EVT_C_BAD_STE" , + [SMMU_EVT_F_BAD_ATS_TREQ ] ="SMMU_EVT_F_BAD_ATS_TREQ" , + [SMMU_EVT_F_STREAM_DISABLED ] ="SMMU_EVT_F_STREAM_DISABLED" , + [SMMU_EVT_F_TRANS_FORBIDDEN ] ="SMMU_EVT_F_TRANS_FORBIDDEN" , + [SMMU_EVT_C_BAD_SUBSTREAMID ] ="SMMU_EVT_C_BAD_SUBSTREAMID" , + [SMMU_EVT_F_CD_FETCH ] ="SMMU_EVT_F_CD_FETCH" , + [SMMU_EVT_C_BAD_CD ] ="SMMU_EVT_C_BAD_CD" , + [SMMU_EVT_F_WALK_EABT ] ="SMMU_EVT_F_WALK_EABT" , + [SMMU_EVT_F_TRANSLATION ] ="SMMU_EVT_F_TRANSLATION" , + [SMMU_EVT_F_ADDR_SIZE ] ="SMMU_EVT_F_ADDR_SIZE" , + [SMMU_EVT_F_ACCESS ] ="SMMU_EVT_F_ACCESS" , + [SMMU_EVT_F_PERMISSION ] ="SMMU_EVT_F_PERMISSION" , + [SMMU_EVT_F_TLB_CONFLICT ] ="SMMU_EVT_F_TLB_CONFLICT" , + [SMMU_EVT_F_CFG_CONFLICT ] ="SMMU_EVT_F_CFG_CONFLICT" , + [SMMU_EVT_E_PAGE_REQ ] ="SMMU_EVT_E_PAGE_REQ" , +}; + +static inline const char *smmu_event_string (SMMUEventType type) +{ +if (type <ARRAY_SIZE (event_stringify)) { +return event_stringify[type] ? event_stringify[type] :"UNKNOWN" ; + }else { +return "INVALID" ; + } +} + +/* Encode an event record */ +typedef struct SMMUEventInfo { +SMMUEventType type; +uint32_t sid; +bool recorded; +bool record_trans_faults; +union { +struct { +uint32_t ssid; +bool ssv; +dma_addr_t addr; +bool rnw; +bool pnu; +bool ind; + } f_uut; +struct SSIDInfo { +uint32_t ssid; +bool ssv; + } c_bad_streamid; +struct SSIDAddrInfo { +uint32_t ssid; +bool ssv; +dma_addr_t addr; + } f_ste_fetch; +struct SSIDInfo c_bad_ste; +struct { +dma_addr_t addr; +bool rnw; + } f_transl_forbidden; +struct { +uint32_t ssid; + } c_bad_substream; +struct SSIDAddrInfo f_cd_fetch; +struct SSIDInfo c_bad_cd; +struct FullInfo { +bool stall; +uint16_t stag; +uint32_t ssid; +bool ssv; +bool s2; +dma_addr_t addr; +bool rnw; +bool pnu; +bool ind; +uint8_t class; +dma_addr_t addr2; + } f_walk_eabt; +struct FullInfo f_translation; +struct FullInfo f_addr_size; +struct FullInfo f_access; +struct FullInfo f_permission; +struct SSIDInfo f_cfg_conflict; +/** +* not supported yet: +* F_BAD_ATS_TREQ +* F_BAD_ATS_TREQ +* F_TLB_CONFLICT +* E_PAGE_REQUEST +* IMPDEF_EVENTn +*/ + } u; +}SMMUEventInfo ; + +/* EVTQ fields */ + +#define EVT_Q_OVERFLOW (1 << 31) + +#define EVT_SET_TYPE (x, v) deposit32((x)->word[0], 0 , 8 , v) +#define EVT_SET_SSV (x, v) deposit32((x)->word[0], 11, 1 , v) +#define EVT_SET_SSID (x, v) deposit32((x)->word[0], 12, 20, v) +#define EVT_SET_SID (x, v) ((x)->word[1] = v) +#define EVT_SET_STAG (x, v) deposit32((x)->word[2], 0 , 16, v) +#define EVT_SET_STALL (x, v) deposit32((x)->word[2], 31, 1 , v) +#define EVT_SET_PNU (x, v) deposit32((x)->word[3], 1 , 1 , v) +#define EVT_SET_IND (x, v) deposit32((x)->word[3], 2 , 1 , v) +#define EVT_SET_RNW (x, v) deposit32((x)->word[3], 3 , 1 , v) +#define EVT_SET_S2 (x, v) deposit32((x)->word[3], 7 , 1 , v) +#define EVT_SET_CLASS (x, v) deposit32((x)->word[3], 8 , 2 , v) +#define EVT_SET_ADDR (x, addr) \ + do { \ + (x)->word[5] = (uint32_t)(addr >> 32); \ + (x)->word[4] = (uint32_t)(addr & 0xffffffff); \ + } while (0) +#define EVT_SET_ADDR2 (x, addr) \ + do { \ + deposit32((x)->word[7], 3, 29, addr >> 16); \ + deposit32((x)->word[7], 0, 16, addr & 0xffff);\ + } while (0) + +void smmuv3_record_event (SMMUv3State *s,SMMUEventInfo *event); +#endif
hw/arm/smmuv3.c +102 -6
125 lines not on this page · raw message
hw/arm/trace-events +1 -0
@@ -29,3 +29,4 @@ smmuv3_write_mmio(uint64_t addr, uint64_t val, unsigned size, uint32_t r) "addr: smmuv3_write_mmio_idr(uint64_t addr, uint64_t val) "write to RO/Unimpl reg 0x%lx val64:0x%lx" smmuv3_write_mmio_evtq_cons_bef_clear(uint32_t prod, uint32_t cons, uint8_t prod_wrap, uint8_t cons_wrap) "Before clearing interrupt prod:0x%x cons:0x%x prod.w:%d cons.w:%d" smmuv3_write_mmio_evtq_cons_after_clear(uint32_t prod, uint32_t cons, uint8_t prod_wrap, uint8_t cons_wrap) "after clearing interrupt prod:0x%x cons:0x%x prod.w:%d cons.w:%d" +smmuv3_record_event(const char *type, uint32_t sid) "%s sid=%d"
Signature · 1 line
2.17.0
Re: [Qemu-devel] [PULL 18/24] hw/arm/smmuv3: Event queue recording helper
Quoted 7 lines · Peter Maydell
From: Eric Auger <[email protected]>
Let's introduce a helper function aiming at recording an event in the event queue.
hw/arm/smmuv3.c +2
-0+void smmuv3_record_event (SMMUv3State *s,SMMUEventInfo *info) +{
hw/arm/smmuv3.c static MemTxResult queue_write(SMMUQueue *q, void *data) · line 154
Quoted 10 lines
hw/arm/smmuv3.c +4
-1+Evt evt; +MemTxResult r;if (!smmuv3_eventq_enabled (s)) {return ; } -if (smmuv3_q_full (q)) { +EVT_SET_TYPE (&evt, info->type); +EVT_SET_SID (&evt, info->sid);
Hi Eric -- Coverity complains about use of uninitialized data here (CID 1391004). Evt is a struct, and there's no initializer where we declare it, so its fields are uninitialized. The The EVT_SET_TYPE and similar setters use deposit32() on fields in the struct, so they read the uninitialized existing values. In cases where we don't set all the fields in the event struct we'll end up leaking random uninitialized data from QEMU's stack into the guest.
Initializing the struct with "Evt evt = {};" ought to satisfy Coverity and fix the data leak.
thanks
-- PMM
Re: [Qemu-devel] [PULL 18/24] hw/arm/smmuv3: Event queue recording helper
Hi Peter,
Quoted 28 lines · Peter Maydell
Quoted 7 lines · Peter Maydell
From: Eric Auger <[email protected]>
Let's introduce a helper function aiming at recording an event in the event queue.
hw/arm/smmuv3.c +2
-0+void smmuv3_record_event (SMMUv3State *s,SMMUEventInfo *info) +{hw/arm/smmuv3.c static MemTxResult queue_write(SMMUQueue *q, void *data) · line 154
Quoted 10 lines
hw/arm/smmuv3.c +4
-1+Evt evt; +MemTxResult r;if (!smmuv3_eventq_enabled (s)) {return ; } -if (smmuv3_q_full (q)) { +EVT_SET_TYPE (&evt, info->type); +EVT_SET_SID (&evt, info->sid);Hi Eric -- Coverity complains about use of uninitialized data here (CID 1391004). Evt is a struct, and there's no initializer where we declare it, so its fields are uninitialized. The The
EVT_SET_TYPEand similar setters usedeposit32()on fields in the struct, so they read the uninitialized existing values. In cases where we don't set all the fields in the event struct we'll end up leaking random uninitialized data from QEMU's stack into the guest.
Quoted 2 lines
Initializing the struct with "Evt evt = {};" ought to satisfy Coverity and fix the data leak.
Sure I will send a patch.
Thanks
Eric
Quoted 4 lines
thanks
-- PMM
[Qemu-devel] [PULL 20/24] hw/arm/smmuv3: Abort on vfio or vhost case
In reply to Peter MaydellFrom: Eric Auger <[email protected]>
At the moment, the SMMUv3 does not support notification on TLB invalidation. So let's log an error as soon as such notifier gets enabled.
Message-id: [email protected]
--- hw/arm/smmuv3.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
hw/arm/smmuv3.c +11 -0
@@ -1147,12 +1147,23 @@ static void smmuv3_class_init(ObjectClass *klass, void *data) dc->realize = smmu_realize; } +static void smmuv3_notify_flag_changed (IOMMUMemoryRegion *iommu, +IOMMUNotifierFlag old, +IOMMUNotifierFlag new) +{ +if (old ==IOMMU_NOTIFIER_NONE ) { +warn_report ("SMMUV3 does not support vhost/vfio integration yet: " +"devices of those types will not function properly" ); + } +} +static void smmuv3_iommu_memory_region_class_init (ObjectClass *klass,void *data) {IOMMUMemoryRegionClass *imrc =IOMMU_MEMORY_REGION_CLASS (klass); imrc->translate = smmuv3_translate; + imrc->notify_flag_changed = smmuv3_notify_flag_changed; }static const TypeInfo smmuv3_type_info = {
Signature · 1 line
2.17.0
[Qemu-devel] [PULL 21/24] target/arm/kvm: Translate the MSI doorbell in kvm_arch_fixup_msi_route
In reply to Peter MaydellFrom: Eric Auger <[email protected]>
In case the MSI is translated by an IOMMU we need to fixup the MSI route with the translated address.
Message-id: [email protected]
--- target/arm/kvm.c | 38 +++++++++++++++++++++++++++++++++++++- target/arm/trace-events | 3 +++ 2 files changed, 40 insertions(+), 1 deletion(-)
target/arm/kvm.c +37 -1
@@ -20,8 +20,10 @@#include "sysemu/kvm.h" #include "kvm_arm.h" #include "cpu.h" +#include "trace.h" #include "internals.h" #include "hw/arm/arm.h" +#include "hw/pci/pci.h" #include "exec/memattrs.h" #include "exec/address-spaces.h" #include "hw/boards.h"
@@ -649,7 +651,41 @@ int kvm_arm_vgic_probe(void)int kvm_arch_fixup_msi_route (struct kvm_irq_routing_entry *route,uint64_t address,uint32_t data,PCIDevice *dev) { -return 0 ; +AddressSpace *as =pci_device_iommu_address_space (dev); +hwaddr xlat, len, doorbell_gpa; +MemoryRegionSection mrs; +MemoryRegion *mr; +int ret =1 ; + +if (as == &address_space_memory) { +return 0 ; + } + +/* MSI doorbell address is translated by an IOMMU */ + +rcu_read_lock (); + mr =address_space_translate (as, address, &xlat, &len, true); +if (!mr) { + goto unlock; + } + mrs =memory_region_find (mr, xlat,1 ); +if (!mrs.mr) { + goto unlock; + } + + doorbell_gpa = mrs.offset_within_address_space; +memory_region_unref (mrs.mr); + + route->u.msi.address_lo = doorbell_gpa; + route->u.msi.address_hi = doorbell_gpa >>32 ; + +trace_kvm_arm_fixup_msi_route (address, doorbell_gpa); + + ret =0 ; + +unlock: +rcu_read_unlock (); +return ret; } int kvm_arch_add_msi_route_post(struct kvm_irq_routing_entry *route,
target/arm/trace-events +3 -0
@@ -8,3 +8,6 @@ arm_gt_tval_write(int timer, uint64_t value) "gt_tval_write: timer %d value 0x%" arm_gt_ctl_write(int timer, uint64_t value) "gt_ctl_write: timer %d value 0x%" PRIx64 arm_gt_imask_toggle(int timer, int irqstate) "gt_ctl_write: timer %d IMASK toggle, new irqstate %d" arm_gt_cntvoff_write(uint64_t value) "gt_cntvoff_write: value 0x%" PRIx64 + +# target/arm/kvm.c +kvm_arm_fixup_msi_route(uint64_t iova, uint64_t gpa) "MSI iova = 0x%"PRIx64" is translated into 0x%"PRIx64
Signature · 1 line
2.17.0
[Qemu-devel] [PULL 22/24] hw/arm/virt: Add SMMUv3 to the virt board
In reply to Peter MaydellFrom: Prem Mallappa <[email protected]>
Add code to instantiate an smmuv3 in virt machine. A new iommu integer member is introduced in VirtMachineState to store the type of the iommu in use.
Message-id: [email protected]
--- include/hw/arm/virt.h | 10 +++++++ hw/arm/virt.c | 64 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 1 deletion(-)
include/hw/arm/virt.h +10 -0
@@ -38,6 +38,7 @@#define NUM_GICV2M_SPIS 64#define NUM_VIRTIO_TRANSPORTS 32 +#define NUM_SMMU_IRQS 4#define ARCH_GICV3_MAINT_IRQ 9
@@ -59,6 +60,7 @@ enum {VIRT_GIC_V2M ,VIRT_GIC_ITS ,VIRT_GIC_REDIST , +VIRT_SMMU ,VIRT_UART ,VIRT_MMIO , VIRT_RTC,
@@ -74,6 +76,12 @@ enum { VIRT_SECURE_MEM, }; +typedef enum VirtIOMMUType { +VIRT_IOMMU_NONE , +VIRT_IOMMU_SMMUV3 , +VIRT_IOMMU_VIRTIO , +}VirtIOMMUType ; + typedef struct MemMapEntry { hwaddr base; hwaddr size;
@@ -97,6 +105,7 @@ typedef struct {bool its;bool virt;int32_t gic_version; +VirtIOMMUType iommu;struct arm_boot_info bootinfo;const MemMapEntry *memmap;const int *irqmap;
@@ -106,6 +115,7 @@ typedef struct {uint32_t clock_phandle;uint32_t gic_phandle;uint32_t msi_phandle; +uint32_t iommu_phandle;int psci_conduit; } VirtMachineState;
hw/arm/virt.c +63 -1
94 lines not on this page · raw message
Signature · 1 line
2.17.0
[Qemu-devel] [PULL 19/24] hw/arm/smmuv3: Implement translate callback
In reply to Peter MaydellFrom: Eric Auger <[email protected]>
This patch implements the IOMMU Memory Region translate() callback. Most of the code relates to the translation configuration decoding and check (STE, CD).
Message-id: [email protected]
--- hw/arm/smmuv3-internal.h | 160 +++++++++++++++++ hw/arm/smmuv3.c | 358 +++++++++++++++++++++++++++++++++++++++ hw/arm/trace-events | 9 + 3 files changed, 527 insertions(+)
hw/arm/smmuv3-internal.h +160 -0
@@ -458,4 +458,164 @@ typedef struct SMMUEventInfo {void smmuv3_record_event (SMMUv3State *s,SMMUEventInfo *event); +/* Configuration Data */ + +/* STE Level 1 Descriptor */ +typedef struct STEDesc { +uint32_t word[2 ]; +}STEDesc ; + +/* CD Level 1 Descriptor */ +typedef struct CDDesc { +uint32_t word[2 ]; +}CDDesc ; + +/* Stream Table Entry(STE) */ +typedef struct STE { +uint32_t word[16 ]; +}STE ; + +/* Context Descriptor(CD) */ +typedef struct CD { +uint32_t word[16 ]; +}CD ; + +/* STE fields */ + +#define STE_VALID (x) extract32((x)->word[0], 0, 1) + +#define STE_CONFIG (x) extract32((x)->word[0], 1, 3) +#define STE_CFG_S1_ENABLED (config) (config & 0x1) +#define STE_CFG_S2_ENABLED (config) (config & 0x2) +#define STE_CFG_ABORT (config) (!(config & 0x4)) +#define STE_CFG_BYPASS (config) (config == 0x4) + +#define STE_S1FMT (x) extract32((x)->word[0], 4 , 2) +#define STE_S1CDMAX (x) extract32((x)->word[1], 27, 5) +#define STE_S1STALLD (x) extract32((x)->word[2], 27, 1) +#define STE_EATS (x) extract32((x)->word[2], 28, 2) +#define STE_STRW (x) extract32((x)->word[2], 30, 2) +#define STE_S2VMID (x) extract32((x)->word[4], 0 , 16) +#define STE_S2T0SZ (x) extract32((x)->word[5], 0 , 6) +#define STE_S2SL0 (x) extract32((x)->word[5], 6 , 2) +#define STE_S2TG (x) extract32((x)->word[5], 14, 2) +#define STE_S2PS (x) extract32((x)->word[5], 16, 3) +#define STE_S2AA64 (x) extract32((x)->word[5], 19, 1) +#define STE_S2HD (x) extract32((x)->word[5], 24, 1) +#define STE_S2HA (x) extract32((x)->word[5], 25, 1) +#define STE_S2S (x) extract32((x)->word[5], 26, 1) +#define STE_CTXPTR (x) \ + ({ \ + unsigned long addr; \ + addr = (uint64_t)extract32((x)->word[1], 0, 16) << 32; \ + addr |= (uint64_t)((x)->word[0] & 0xffffffc0); \ + addr; \ + }) + +#define STE_S2TTB (x) \ + ({ \ + unsigned long addr; \ + addr = (uint64_t)extract32((x)->word[7], 0, 16) << 32; \ + addr |= (uint64_t)((x)->word[6] & 0xfffffff0); \ + addr; \ + }) + +static inline int oas2bits (int oas_field) +{ +switch (oas_field) { +case 0 : +return 32 ; +case 1 : +return 36 ; +case 2 : +return 40 ; +case 3 : +return 42 ; +case 4 : +return 44 ; +case 5 : +return 48 ; + } +return -1 ; +} + +static inline int pa_range (STE *ste) +{ +int oas_field =MIN (STE_S2PS (ste),SMMU_IDR5_OAS ); + +if (!STE_S2AA64 (ste)) { +return 40 ; + } + +return oas2bits (oas_field); +} + +#define MAX_PA (ste) ((1 << pa_range(ste)) - 1) + +/* CD fields */ + +#define CD_VALID (x) extract32((x)->word[0], 30, 1) +#define CD_ASID (x) extract32((x)->word[1], 16, 16) +#define CD_TTB (x, sel) \ + ({ \ + uint64_t hi, lo; \ + hi = extract32((x)->word[(sel) * 2 + 3], 0, 19); \ + hi <<= 32; \ + lo = (x)->word[(sel) * 2 + 2] & ~0xfULL; \ + hi | lo; \ + }) + +#define CD_TSZ (x, sel) extract32((x)->word[0], (16 * (sel)) + 0, 6) +#define CD_TG (x, sel) extract32((x)->word[0], (16 * (sel)) + 6, 2) +#define CD_EPD (x, sel) extract32((x)->word[0], (16 * (sel)) + 14, 1) +#define CD_ENDI (x) extract32((x)->word[0], 15, 1) +#define CD_IPS (x) extract32((x)->word[1], 0 , 3) +#define CD_TBI (x) extract32((x)->word[1], 6 , 2) +#define CD_HD (x) extract32((x)->word[1], 10 , 1) +#define CD_HA (x) extract32((x)->word[1], 11 , 1) +#define CD_S (x) extract32((x)->word[1], 12, 1) +#define CD_R (x) extract32((x)->word[1], 13, 1) +#define CD_A (x) extract32((x)->word[1], 14, 1) +#define CD_AARCH64 (x) extract32((x)->word[1], 9 , 1) + +#define CDM_VALID (x) ((x)->word[0] & 0x1) + +static inline int is_cd_valid (SMMUv3State *s,STE *ste,CD *cd) +{ +return CD_VALID (cd); +} + +/** +* tg2granule - Decodes the CD translation granule size field according +* to the ttbr in use +* @bits: TG0/1 fields +* @ttbr: ttbr index in use +*/ +static inline int tg2granule (int bits,int ttbr) +{ +switch (bits) { +case 0 : +return ttbr ?0 :12 ; +case 1 : +return ttbr ?14 :16 ; +case 2 : +return ttbr ?12 :14 ; +case 3 : +return ttbr ?16 :0 ; +default : +return 0 ; + } +} + +static inline uint64_t l1std_l2ptr (STEDesc *desc) +{ +uint64_t hi, lo; + + hi = desc->word[1 ]; + lo = desc->word[0 ] & ~0x1fULL ; +return hi <<32 | lo; +} + +#define L1STD_SPAN (stm) (extract32((stm)->word[0], 0, 4)) +#endif
hw/arm/smmuv3.c +358 -0
370 lines not on this page · raw message
hw/arm/trace-events +9 -0
@@ -30,3 +30,12 @@ smmuv3_write_mmio_idr(uint64_t addr, uint64_t val) "write to RO/Unimpl reg 0x%lx smmuv3_write_mmio_evtq_cons_bef_clear(uint32_t prod, uint32_t cons, uint8_t prod_wrap, uint8_t cons_wrap) "Before clearing interrupt prod:0x%x cons:0x%x prod.w:%d cons.w:%d" smmuv3_write_mmio_evtq_cons_after_clear(uint32_t prod, uint32_t cons, uint8_t prod_wrap, uint8_t cons_wrap) "after clearing interrupt prod:0x%x cons:0x%x prod.w:%d cons.w:%d" smmuv3_record_event(const char *type, uint32_t sid) "%s sid=%d" +smmuv3_find_ste(uint16_t sid, uint32_t features, uint16_t sid_split) "SID:0x%x features:0x%x, sid_split:0x%x" +smmuv3_find_ste_2lvl(uint64_t strtab_base, uint64_t l1ptr, int l1_ste_offset, uint64_t l2ptr, int l2_ste_offset, int max_l2_ste) "strtab_base:0x%lx l1ptr:0x%"PRIx64" l1_off:0x%x, l2ptr:0x%"PRIx64" l2_off:0x%x max_l2_ste:%d" +smmuv3_get_ste(uint64_t addr) "STE addr: 0x%"PRIx64 +smmuv3_translate_bypass(const char *n, uint16_t sid, uint64_t addr, bool is_write) "%s sid=%d bypass iova:0x%"PRIx64" is_write=%d" +smmuv3_translate_in(uint16_t sid, int pci_bus_num, uint64_t strtab_base) "SID:0x%x bus:%d strtab_base:0x%"PRIx64 +smmuv3_get_cd(uint64_t addr) "CD addr: 0x%"PRIx64 +smmuv3_translate(const char *n, uint16_t sid, uint64_t iova, uint64_t translated, int perm) "%s sid=%d iova=0x%"PRIx64" translated=0x%"PRIx64" perm=0x%x" +smmuv3_decode_cd(uint32_t oas) "oas=%d" +smmuv3_decode_cd_tt(int i, uint32_t tsz, uint64_t ttb, uint32_t granule_sz) "TT[%d]:tsz:%d ttb:0x%"PRIx64" granule_sz:%d"
Signature · 1 line
2.17.0
[Qemu-devel] [PULL 23/24] hw/arm/virt-acpi-build: Add smmuv3 node in IORT table
In reply to Peter MaydellFrom: Prem Mallappa <[email protected]>
This patch builds the smmuv3 node in the ACPI IORT table.
The RID space of the root complex, which spans 0x0-0x10000 maps to streamid space 0x0-0x10000 in smmuv3, which in turn maps to deviceid space 0x0-0x10000 in the ITS group.
The guest must feature the IOMMU probe deferral series
(https://lkml.org/lkml/2017/4/10/214) which fixes streamid multiple lookup. This bug is not related to the SMMU emulation.
Message-id: [email protected]
--- include/hw/acpi/acpi-defs.h | 15 ++++++++++ hw/arm/virt-acpi-build.c | 55 ++++++++++++++++++++++++++++++++----- 2 files changed, 63 insertions(+), 7 deletions(-)
include/hw/acpi/acpi-defs.h +15 -0
@@ -628,6 +628,21 @@ struct AcpiIortItsGroup { }QEMU_PACKED ;typedef struct AcpiIortItsGroup AcpiIortItsGroup ; +struct AcpiIortSmmu3 { +ACPI_IORT_NODE_HEADER_DEF + uint64_t base_address; +uint32_t flags; +uint32_t reserved2; +uint64_t vatos_address; +uint32_t model; +uint32_t event_gsiv; +uint32_t pri_gsiv; +uint32_t gerr_gsiv; +uint32_t sync_gsiv; +AcpiIortIdMapping id_mapping_array[0 ]; +}QEMU_PACKED ; +typedef struct AcpiIortSmmu3 AcpiIortSmmu3 ; +struct AcpiIortRC {ACPI_IORT_NODE_HEADER_DEF AcpiIortMemoryAccess memory_properties;
hw/arm/virt-acpi-build.c +48 -7
88 lines not on this page · raw message
Signature · 1 line
2.17.0
[Qemu-devel] [PULL 24/24] hw/arm/virt: Introduce the iommu option
In reply to Peter MaydellFrom: Eric Auger <[email protected]>
ARM virt machine now exposes a new "iommu" option.
The SMMUv3 IOMMU is instantiated using -machine virt,iommu=smmuv3.
Message-id: [email protected]
--- hw/arm/virt.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
hw/arm/virt.c +36 -0
@@ -1561,6 +1561,34 @@ static void virt_set_gic_version(Object *obj, const char *value, Error **errp) } } +static char *virt_get_iommu (Object *obj,Error **errp) +{ +VirtMachineState *vms =VIRT_MACHINE (obj); + +switch (vms->iommu) { +case VIRT_IOMMU_NONE : +return g_strdup ("none" ); +case VIRT_IOMMU_SMMUV3 : +return g_strdup ("smmuv3" ); +default : +g_assert_not_reached (); + } +} + +static void virt_set_iommu (Object *obj,const char *value,Error **errp) +{ +VirtMachineState *vms =VIRT_MACHINE (obj); + +if (!strcmp (value,"smmuv3" )) { + vms->iommu =VIRT_IOMMU_SMMUV3 ; + }else if (!strcmp (value,"none" )) { + vms->iommu =VIRT_IOMMU_NONE ; + }else { +error_setg (errp,"Invalid iommu value" ); +error_append_hint (errp,"Valid values are none, smmuv3.\n" ); + } +} +static CpuInstanceProperties virt_cpu_index_to_props (MachineState *ms,unsigned cpu_index) {
@@ -1693,6 +1721,14 @@ static void virt_2_12_instance_init(Object *obj) NULL); } +/* Default disallows iommu instantiation */ + vms->iommu =VIRT_IOMMU_NONE ; +object_property_add_str (obj,"iommu" , virt_get_iommu, virt_set_iommu,NULL ); +object_property_set_description (obj,"iommu" , +"Set the IOMMU type. " +"Valid values are none and smmuv3" , +NULL ); + vms->memmap = a15memmap; vms->irqmap = a15irqmap; }
Signature · 1 line
2.17.0
Quoted 18 lines · Peter Maydell
target-arm queue: Eric's SMMUv3 patchset, and an array of minor bugfixes and improvements from various others.
thanks
-- PMMThe following changes since commit
c8b7e627b4269a3bc3ae41d9f420547a47e6d9b9:Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2018-05-04' into staging (2018-05-04 14:42:46 +0100)
are available in the Git repository at:
git://git.linaro.org/people/pmaydell/qemu-arm.gittags/pull-target-arm-20180504for you to fetch changes up to
5680740c92993e9b3f3e011f2a2c394070e33f56:hw/arm/virt: Introduce the iommu option (2018-05-04 18:05:52 +0100)
Quoted 14 lines
----------------------------------------------------------------
target-arm queue:
* Emulate the SMMUv3 (IOMMU); one will be created in the 'virt' board if the commandline includes "-machine iommu=smmuv3"
* target/arm: Implement v8M VLLDM and VLSTM
* hw/arm: Don't fail qtest due to missing SD card in -nodefaults mode
* Some fixes to silence Coverity false-positives
* arm: boot: setboot_infostarting fromfirst_cpu
(fixes a technical bug not visible in practice)
* hw/net/smc91c111: Convert away fromold_mmio
* hw/usb/tusb6010: Convert away fromold_mmio
*hw/char/cmsdk-apb-uart.c: Accept more input after character read
* target/arm: Make MPUIR write-ignored on OMAP, StrongARM
* hw/arm/virt: Add linux,pci-domain property
Oops, 32-bit compile failures for format string issues;
hw/arm/trace.h: In function ‘_nocheck__trace_smmu_ptw_level’:hw/arm/trace.h:215:18: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 7 has type ‘size_t {aka unsigned int}’ [-Werror=format=]
qemu_log("%d@%zd.%06zd:smmu_ptw_level " "level=%d
iova=0x%"PRIx64" subpage_sz=0x%lx baseaddr=0x%"PRIx64" offset=%d =>
pte=0x%"PRIx64 "\n",
^hw/arm/trace.h: In function ‘_nocheck__trace_smmuv3_write_mmio_idr’:hw/arm/trace.h:606:18: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 5 has type ‘uint64_t {aka long long unsigned int}’ [-Werror=format=]
qemu_log("%d@%zd.%06zd:smmuv3_write_mmio_idr " "write to
RO/Unimpl reg 0x%lx val64:0x%lx" "\n",
^hw/arm/trace.h:606:18: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 6 has type ‘uint64_t {aka long long unsigned int}’ [-Werror=format=]hw/arm/trace.h: In function ‘_nocheck__trace_smmuv3_find_ste_2lvl’:hw/arm/trace.h:721:18: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 5 has type ‘uint64_t {aka long long unsigned int}’ [-Werror=format=]
qemu_log("%d@%zd.%06zd:smmuv3_find_ste_2lvl "
"strtab_base:0x%lx l1ptr:0x%"PRIx64" l1_off:0x%x, l2ptr:0x%"PRIx64"
l2_off:0x%x max_l2_ste:%d" "\n",
^size_t arguments need %zx, not %lx, and uint64_t arguments need %"PRIx64", not %lx. I'll squash in the changes to the relevant patches.
thanks
-- PMM
Hi Peter,
Quoted 58 lines · Peter Maydell
Quoted 18 lines · Peter Maydell
target-arm queue: Eric's SMMUv3 patchset, and an array of minor bugfixes and improvements from various others.
thanks
-- PMMThe following changes since commit
c8b7e627b4269a3bc3ae41d9f420547a47e6d9b9:Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2018-05-04' into staging (2018-05-04 14:42:46 +0100)
are available in the Git repository at:
git://git.linaro.org/people/pmaydell/qemu-arm.gittags/pull-target-arm-20180504for you to fetch changes up to
5680740c92993e9b3f3e011f2a2c394070e33f56:hw/arm/virt: Introduce the iommu option (2018-05-04 18:05:52 +0100)
Quoted 14 lines
----------------------------------------------------------------
target-arm queue:
* Emulate the SMMUv3 (IOMMU); one will be created in the 'virt' board if the commandline includes "-machine iommu=smmuv3"
* target/arm: Implement v8M VLLDM and VLSTM
* hw/arm: Don't fail qtest due to missing SD card in -nodefaults mode
* Some fixes to silence Coverity false-positives
* arm: boot: setboot_infostarting fromfirst_cpu
(fixes a technical bug not visible in practice)
* hw/net/smc91c111: Convert away fromold_mmio
* hw/usb/tusb6010: Convert away fromold_mmio
*hw/char/cmsdk-apb-uart.c: Accept more input after character read
* target/arm: Make MPUIR write-ignored on OMAP, StrongARM
* hw/arm/virt: Add linux,pci-domain propertyOops, 32-bit compile failures for format string issues;
hw/arm/trace.h: In function ‘_nocheck__trace_smmu_ptw_level’:hw/arm/trace.h:215:18: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 7 has type ‘size_t {aka unsigned int}’ [-Werror=format=]qemu_log("%d@%zd.%06zd:smmu_ptw_level " "level=%d iova=0x%"PRIx64" subpage_sz=0x%lx baseaddr=0x%"PRIx64" offset=%d => pte=0x%"PRIx64 "\n", ^
hw/arm/trace.h: In function ‘_nocheck__trace_smmuv3_write_mmio_idr’:hw/arm/trace.h:606:18: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 5 has type ‘uint64_t {aka long long unsigned int}’ [-Werror=format=]qemu_log("%d@%zd.%06zd:smmuv3_write_mmio_idr " "write to RO/Unimpl reg 0x%lx val64:0x%lx" "\n", ^
hw/arm/trace.h:606:18: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 6 has type ‘uint64_t {aka long long unsigned int}’ [-Werror=format=]hw/arm/trace.h: In function ‘_nocheck__trace_smmuv3_find_ste_2lvl’:hw/arm/trace.h:721:18: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 5 has type ‘uint64_t {aka long long unsigned int}’ [-Werror=format=]
Quoted 7 lines
qemu_log("%d@%zd.%06zd:smmuv3_find_ste_2lvl " "strtab_base:0x%lx l1ptr:0x%"PRIx64" l1_off:0x%x, l2ptr:0x%"PRIx64" l2_off:0x%x max_l2_ste:%d" "\n", ^
size_targuments need %zx, not %lx, anduint64_targuments need %"PRIx64", not %lx. I'll squash in the changes to the relevant patches.
OK. Thank you for taking this in charge!
Eric
Quoted 4 lines
thanks
-- PMM