arm/arm64: add ITS framework
Subsystems (3)
cover arm/arm64: add ITS framework
This series proposes a framework to test the virtual ITS. This is based on Drew's v7 series [1]. The last patch tests several ITS commands (collection/device mapping, interrupt translation service entry creation and LPI trigger through INT command). At this point we don't use any external PCIe device to write into the GITS_TRANSLATER register.
The bulk of the code derives from the ITS driver code so all the credit is due to Marc.
Many other ITS commands could be tested. Also existing MMIO accesses could be enhanced into standalone tests. Current focus was to make it functional.
The code deserves more cleanup with respect to cacheability attributes in general.
Tested on Cavium ThunderX [2].
Best Regards
Eric
[1] [kvm-unit-tests PATCH v7 00/11] arm/arm64: add gic framework
[2] sample command line:
$QEMU -machine virt,accel=kvm -cpu host \
-device virtio-serial-device \
-device virtconsole,chardev=ctd -chardev testdev,id=ctd \
-display none -serial stdio \
-kernel arm/gic.flat \
-smp 8 -machine gic-version=3 -append 'its'
Eric Auger (15):
libcflat: Add other size defines
arm/arm64: gicv3: Add some re-distributor defines arm/arm64: ITS skeleton
arm/arm64: ITS: BASER parsing and setup arm/arm64: GICv3: add cpu count
arm/arm64: ITS: Set the LPI config and pending tables arm/arm64: ITS: Init the command queue arm/arm64: ITS: enable LPIs at re-distributor level arm/arm64: ITS: Parse the typer register arm/arm64: ITS: its_enable_defaults arm/arm64: ITS: create device
arm/arm64: ITS: create collection
arm/arm64: ITS: commands
arm/arm64: gic: Generalize ipi_enable() arm/arm64: ITS test
arm/Makefile.common | 1 + arm/gic.c | 101 +++++++++++- lib/arm/asm/gic-v3-its.h | 238 +++++++++++++++++++++++++++ lib/arm/asm/gic-v3.h | 84 ++++++++++ lib/arm/asm/gic.h | 1 + lib/arm/gic-v3-its-cmd.c | 399 +++++++++++++++++++++++++++++++++++++++++++++ lib/arm/gic-v3-its.c | 305 ++++++++++++++++++++++++++++++++++ lib/arm/gic-v3.c | 2 + lib/arm/gic.c | 30 +++- lib/arm64/asm/gic-v3-its.h | 1 + lib/libcflat.h | 3 + 11 files changed, 1154 insertions(+), 11 deletions(-) create mode 100644 lib/arm/asm/gic-v3-its.h create mode 100644 lib/arm/gic-v3-its-cmd.c create mode 100644 lib/arm/gic-v3-its.c create mode 100644 lib/arm64/asm/gic-v3-its.h
Signature · 1 line
2.5.5
RFC 1/15 libcflat: Add other size defines
Introduce additional SZ_256, SZ_8K, SZ_16K macros that will be used by ITS tests.
--- lib/libcflat.h | 3 +++ 1 file changed, 3 insertions(+)
lib/libcflat.h +3 -0
@@ -35,7 +35,10 @@#define ALIGN (x, a) __ALIGN((x), (a))#define IS_ALIGNED (x, a) (((x) & ((typeof(x))(a) - 1)) == 0) +#define SZ_256 (1 << 8)#define SZ_4K (1 << 12) +#define SZ_8K (1 << 13) +#define SZ_16K (1 << 14)#define SZ_64K (1 << 16)#define SZ_2M (1 << 21)#define SZ_1G (1 << 30)
Signature · 1 line
2.5.5
RFC 2/15 arm/arm64: gicv3: Add some re-distributor defines
In reply to Eric AugerPROPBASER, PENDBASE and GICR_CTRL will be used for LPI management.
--- lib/arm/asm/gic-v3.h | 6 ++++++ 1 file changed, 6 insertions(+)
lib/arm/asm/gic-v3.h +6 -0
@@ -18,6 +18,7 @@* We expect to be run in Non-secure mode, thus we define the * group1 enable bits with respect to that view. */ +#define GICD_CTLR 0x0000#define GICD_CTLR_RWP (1U << 31)#define GICD_CTLR_ARE_NS (1U << 4)#define GICD_CTLR_ENABLE_G1A (1U << 1)
@@ -33,6 +34,11 @@#define GICR_ISENABLER0 GICD_ISENABLER#define GICR_IPRIORITYR0 GICD_IPRIORITYR +#define GICR_PROPBASER 0x0070 +#define GICR_PENDBASER 0x0078 +#define GICR_CTLR GICD_CTLR +#define GICR_CTLR_ENABLE_LPIS (1UL << 0) +#define ICC_SGI1R_AFFINITY_1_SHIFT 16#define ICC_SGI1R_AFFINITY_2_SHIFT 32#define ICC_SGI1R_AFFINITY_3_SHIFT 48
Signature · 1 line
2.5.5
RFC 3/15 arm/arm64: ITS skeleton
In reply to Eric AugerAt the moment we just detect the presence of ITS as part of the GICv3 init routine and initialize its base address.
--- arm/Makefile.common | 1 + lib/arm/asm/gic-v3-its.h | 22 ++++++++++++++++++++++ lib/arm/asm/gic.h | 1 + lib/arm/gic-v3-its.c | 9 +++++++++ lib/arm/gic.c | 30 +++++++++++++++++++++++++----- lib/arm64/asm/gic-v3-its.h | 1 + 6 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 lib/arm/asm/gic-v3-its.h create mode 100644 lib/arm/gic-v3-its.c create mode 100644 lib/arm64/asm/gic-v3-its.h
arm/Makefile.common +1 -0
@@ -47,6 +47,7 @@ cflatobjs += lib/arm/bitops.o cflatobjs += lib/arm/psci.o cflatobjs += lib/arm/smp.o cflatobjs += lib/arm/gic.o lib/arm/gic-v2.o lib/arm/gic-v3.o +cflatobjs += lib/arm/gic-v3-its.o libeabi = lib/arm/libeabi.a eabiobjs = lib/arm/eabi_compat.o
lib/arm/asm/gic-v3-its.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* All ITS* defines are lifted from include/linux/irqchip/arm-gic-v3.h +* +* Copyright (C) 2016, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#ifndef _ASMARM_GIC_V3_ITS_H_ +#define _ASMARM_GIC_V3_ITS_H_ + +#ifndef __ASSEMBLY__ + +struct its_data { +void *base; +}; + +extern struct its_data its_data; + +#define gicv3_its_base () (its_data.base) + +#endif /* !__ASSEMBLY__ */ +#endif /* _ASMARM_GIC_V3_ITS_H_ */
lib/arm/asm/gic.h +1 -0
@@ -30,6 +30,7 @@#include <asm/gic-v2.h> #include <asm/gic-v3.h> +#include <asm/gic-v3-its.h> #ifndef __ASSEMBLY__#include <asm/cpumask.h>
lib/arm/gic-v3-its.c new file +9 -0
@@ -0,0 +1,9 @@ +/* +* Copyright (C) 2016, Red Hat Inc, Eric Auger <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include <asm/gic.h> + +struct its_data its_data; +
lib/arm/gic.c +25 -5
@@ -6,6 +6,7 @@#include <devicetree.h> #include <asm/gic.h> #include <asm/io.h> +#include <asm/gic-v3-its.h> struct gic_common_ops *gic_common_ops;
@@ -17,12 +18,14 @@ struct gicv3_data gicv3_data;* Documentation/devicetree/bindings/interrupt-controller/arm,gic-v3.txt */ static bool -gic_get_dt_bases (const char *compatible,void **base1,void **base2) +gic_get_dt_bases (const char *compatible,void **base1,void **base2, +void **base3) {struct dt_pbus_reg reg; -struct dt_device gic; +struct dt_device gic, its;struct dt_bus bus; -int node, ret; +int node, subnode, ret, len; +const void *fdt =dt_fdt ();dt_bus_init_defaults (&bus);dt_device_init (&gic, &bus,NULL );
@@ -43,19 +46,36 @@ gic_get_dt_bases(const char *compatible, void **base1, void **base2)assert (ret ==0 ); *base2 =ioremap (reg.addr, reg.size); +if (base3 && !strcmp (compatible,"arm,gic-v3" )) { +dt_for_each_subnode (node, subnode) { +const struct fdt_property *prop; + + prop =fdt_get_property (fdt, subnode, +"compatible" , &len); +if (!strcmp ((char *)prop->data,"arm,gic-v3-its" )) { +dt_device_bind_node (&its, subnode); + ret =dt_pbus_translate (&its,0 , ®); +assert (ret ==0 ); + *base3 =ioremap (reg.addr, reg.size); +break ; + } + } + + } +return true; }int gicv2_init (void ) {return gic_get_dt_bases ("arm,cortex-a15-gic" , - &gicv2_data.dist_base, &gicv2_data.cpu_base); + &gicv2_data.dist_base, &gicv2_data.cpu_base,NULL ); }int gicv3_init (void ) {return gic_get_dt_bases ("arm,gic-v3" , &gicv3_data.dist_base, - &gicv3_data.redist_base[0 ]); + &gicv3_data.redist_base[0 ], &its_data.base); }int gic_init (void )
lib/arm64/asm/gic-v3-its.h new file +1 -0
@@ -0,0 +1 @@ +#include "../../arm/asm/gic-v3-its.h"
Signature · 1 line
2.5.5
Re: [Qemu-devel] [kvm-unit-tests RFC 03/15] arm/arm64: ITS skeleton
Quoted 34 lines · Eric Auger
At the moment we just detect the presence of ITS as part of the GICv3 init routine and initialize its base address.
Signed-off-by Eric Auger <[email protected]>--- arm/Makefile.common | 1 + lib/arm/asm/gic-v3-its.h | 22 ++++++++++++++++++++++ lib/arm/asm/gic.h | 1 + lib/arm/gic-v3-its.c | 9 +++++++++ lib/arm/gic.c | 30 +++++++++++++++++++++++++----- lib/arm64/asm/gic-v3-its.h | 1 + 6 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 lib/arm/asm/gic-v3-its.h create mode 100644 lib/arm/gic-v3-its.c create mode 100644 lib/arm64/asm/gic-v3-its.harm/Makefile.common +1
-0@@ -47,6 +47,7 @@ cflatobjs += lib/arm/bitops.o cflatobjs += lib/arm/psci.o cflatobjs += lib/arm/smp.o cflatobjs += lib/arm/gic.o lib/arm/gic-v2.o lib/arm/gic-v3.o +cflatobjs += lib/arm/gic-v3-its.o libeabi = lib/arm/libeabi.a eabiobjs = lib/arm/eabi_compat.olib/arm/asm/gic-v3-its.h new file +0
-0
lib/arm/asm/gic-v3-its.h line 4
Quoted 4 lines
lib/arm/asm/gic-v3-its.h new file +4
-0@@ -0,0 +1,22 @@ +/* +* All ITS* defines are lifted from include/linux/irqchip/arm-gic-v3.h +* +* Copyright (C) 2016, Red Hat Inc, Andrew Jones <[email protected]>
s/Andrew/Eric/
Quoted 5 lines
lib/arm/asm/gic-v3-its.h new file +5
-0+* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#ifndef _ASMARM_GIC_V3_ITS_H_ +#define _ASMARM_GIC_V3_ITS_H_
lib/arm/asm/gic-v3-its.h line 19
Quoted 10 lines
lib/arm/asm/gic-v3-its.h new file +10
-0+ +#ifndef __ASSEMBLY__ + +struct its_data { +void *base; +}; + +extern struct its_data its_data; + +#define gicv3_its_base () (its_data.base)
Can't we just add the ITS base address to the current gicv3_data struct?
Quoted 110 lines
lib/arm/asm/gic-v3-its.h new file +3
-0+ +#endif /* !__ASSEMBLY__ */ +#endif /* _ASMARM_GIC_V3_ITS_H_ */ lib/arm/asm/gic.h +1
-0@@ -30,6 +30,7 @@#include <asm/gic-v2.h> #include <asm/gic-v3.h> +#include <asm/gic-v3-its.h> #ifndef __ASSEMBLY__#include <asm/cpumask.h> lib/arm/gic-v3-its.c new file +9
-0@@ -0,0 +1,9 @@ +/* +* Copyright (C) 2016, Red Hat Inc, Eric Auger <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include <asm/gic.h> + +struct its_data its_data; +lib/arm/gic.c +25
-5@@ -6,6 +6,7 @@#include <devicetree.h> #include <asm/gic.h> #include <asm/io.h> +#include <asm/gic-v3-its.h> struct gic_common_ops *gic_common_ops;@@ -17,12 +18,14 @@ struct gicv3_data gicv3_data;* Documentation/devicetree/bindings/interrupt-controller/arm,gic-v3.txt */ static bool -gic_get_dt_bases (const char *compatible,void **base1,void **base2) +gic_get_dt_bases (const char *compatible,void **base1,void **base2, +void **base3) {struct dt_pbus_reg reg; -struct dt_device gic; +struct dt_device gic, its;struct dt_bus bus; -int node, ret; +int node, subnode, ret, len; +const void *fdt =dt_fdt ();dt_bus_init_defaults (&bus);dt_device_init (&gic, &bus,NULL );@@ -43,19 +46,36 @@ gic_get_dt_bases(const char *compatible, void **base1, void **base2)assert (ret ==0 ); *base2 =ioremap (reg.addr, reg.size); +if (base3 && !strcmp (compatible,"arm,gic-v3" )) { +dt_for_each_subnode (node, subnode) { +const struct fdt_property *prop; + + prop =fdt_get_property (fdt, subnode, +"compatible" , &len); +if (!strcmp ((char *)prop->data,"arm,gic-v3-its" )) { +dt_device_bind_node (&its, subnode); + ret =dt_pbus_translate (&its,0 , ®); +assert (ret ==0 ); + *base3 =ioremap (reg.addr, reg.size); +break ; + } + } + + } +return true; }int gicv2_init (void ) {return gic_get_dt_bases ("arm,cortex-a15-gic" , - &gicv2_data.dist_base, &gicv2_data.cpu_base); + &gicv2_data.dist_base, &gicv2_data.cpu_base,NULL ); }int gicv3_init (void ) {return gic_get_dt_bases ("arm,gic-v3" , &gicv3_data.dist_base, - &gicv3_data.redist_base[0 ]); + &gicv3_data.redist_base[0 ], &its_data.base); }int gic_init (void )lib/arm64/asm/gic-v3-its.h new file +1
-0@@ -0,0 +1 @@ +#include "../../arm/asm/gic-v3-its.h" Signature · 1 line
2.5.5
Thanks,
drew
RFC 4/15 arm/arm64: ITS: BASER parsing and setup
In reply to Eric AugerAdd helper routines to parse BASER registers and set them up
--- lib/arm/asm/gic-v3-its.h | 72 +++++++++++++++++++++++++++++++++++++++++++ lib/arm/gic-v3-its.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+)
lib/arm/asm/gic-v3-its.h +72 -0
@@ -10,13 +10,85 @@#ifndef __ASSEMBLY__ +#include <asm/setup.h> +#include <asm/io.h> + +#define GITS_BASER 0x0100 + +#define GITS_BASER_NR_REGS 8 + +#define GITS_BASER_VALID (1UL << 63) +#define GITS_BASER_INDIRECT (1ULL << 62) + +#define GITS_BASER_INNER_CACHEABILITY_SHIFT (59) +#define GITS_BASER_OUTER_CACHEABILITY_SHIFT (53) +#define GITS_BASER_INNER_CACHEABILITY_MASK \ + GIC_BASER_CACHEABILITY(GITS_BASER, INNER, MASK) +#define GITS_BASER_CACHEABILITY_MASK GITS_BASER_INNER_CACHEABILITY_MASK +#define GITS_BASER_OUTER_CACHEABILITY_MASK \ + GIC_BASER_CACHEABILITY(GITS_BASER, OUTER, MASK) +#define GITS_BASER_SHAREABILITY_MASK \ + GIC_BASER_SHAREABILITY(GITS_BASER, SHAREABILITY_MASK) + +#define GITS_BASER_nCnB GIC_BASER_CACHEABILITY(GITS_BASER, INNER, nCnB) +#define GITS_BASER_nC GIC_BASER_CACHEABILITY(GITS_BASER, INNER, nC) +#define GITS_BASER_RaWt GIC_BASER_CACHEABILITY(GITS_BASER, INNER, RaWt) +#define GITS_BASER_RaWb GIC_BASER_CACHEABILITY(GITS_BASER, INNER, RaWt) +#define GITS_BASER_WaWt GIC_BASER_CACHEABILITY(GITS_BASER, INNER, WaWt) +#define GITS_BASER_WaWb GIC_BASER_CACHEABILITY(GITS_BASER, INNER, WaWb) +#define GITS_BASER_RaWaWt GIC_BASER_CACHEABILITY(GITS_BASER, INNER, RaWaWt) +#define GITS_BASER_RaWaWb GIC_BASER_CACHEABILITY(GITS_BASER, INNER, RaWaWb) + +#define GITS_BASER_TYPE_SHIFT (56) +#define GITS_BASER_TYPE (r) (((r) >> GITS_BASER_TYPE_SHIFT) & 7) +#define GITS_BASER_ENTRY_SIZE_SHIFT (48) +#define GITS_BASER_ENTRY_SIZE (r) ((((r) >> GITS_BASER_ENTRY_SIZE_SHIFT) & 0x1f) + 1) +#define GITS_BASER_SHAREABILITY_SHIFT (10) +#define GITS_BASER_InnerShareable \ + GIC_BASER_SHAREABILITY(GITS_BASER, InnerShareable) +#define GITS_BASER_PAGE_SIZE_SHIFT (8) +#define GITS_BASER_PAGE_SIZE_4K (0UL << GITS_BASER_PAGE_SIZE_SHIFT) +#define GITS_BASER_PAGE_SIZE_16K (1UL << GITS_BASER_PAGE_SIZE_SHIFT) +#define GITS_BASER_PAGE_SIZE_64K (2UL << GITS_BASER_PAGE_SIZE_SHIFT) +#define GITS_BASER_PAGE_SIZE_MASK (3UL << GITS_BASER_PAGE_SIZE_SHIFT) +#define GITS_BASER_PAGES_MAX 256 +#define GITS_BASER_PAGES_SHIFT (0) +#define GITS_BASER_NR_PAGES (r) (((r) & 0xff) + 1) + +#define GITS_BASER_TYPE_NONE 0 +#define GITS_BASER_TYPE_DEVICE 1 +#define GITS_BASER_TYPE_VCPU 2 +#define GITS_BASER_TYPE_CPU 3 +#define GITS_BASER_TYPE_COLLECTION 4 +#define GITS_BASER_TYPE_RESERVED5 5 +#define GITS_BASER_TYPE_RESERVED6 6 +#define GITS_BASER_TYPE_RESERVED7 7 + +struct its_baser { +unsigned int index; +int type; +u64 cache; +int shr; +size_t psz; +int nr_pages; +bool indirect; +phys_addr_t table_addr; +bool valid; +int esz; +}; +struct its_data {void *base; +struct its_baser baser[GITS_BASER_NR_REGS ]; };extern struct its_data its_data;#define gicv3_its_base () (its_data.base) +extern int its_parse_baser (int i,struct its_baser *baser); +extern void its_setup_baser (int i,struct its_baser *baser); + +#endif /* !__ASSEMBLY__ */ #endif /* _ASMARM_GIC_V3_ITS_H_ */
lib/arm/gic-v3-its.c +79 -0
82 lines not on this page · raw message
Signature · 1 line
2.5.5
RFC 5/15 arm/arm64: GICv3: add cpu count
In reply to Eric AugerAdd a new cpu_count field in gicv3_data indicating the number of redistributors. This will be useful for enumeration of their resources such as LPI pending tables.
--- lib/arm/asm/gic-v3.h | 1 + lib/arm/gic-v3.c | 2 ++ 2 files changed, 3 insertions(+)
lib/arm/asm/gic-v3.h +1 -0
@@ -58,6 +58,7 @@ struct gicv3_data {void *dist_base;void *redist_base[NR_CPUS ];unsigned int irq_nr; +unsigned int cpu_count; };extern struct gicv3_data gicv3_data;
lib/arm/gic-v3.c +2 -0
@@ -12,12 +12,14 @@ void gicv3_set_redist_base(size_t stride)void *ptr = gicv3_data.redist_base[0 ];u64 typer; + gicv3_data.cpu_count =0 ;do { typer =gicv3_read_typer (ptr +GICR_TYPER );if ((typer >>32 ) == aff) {gicv3_redist_base () = ptr;return ; } + gicv3_data.cpu_count++; ptr += stride;/* skip RD_base, SGI_base, etc. */ }while (!(typer &GICR_TYPER_LAST ));
Signature · 1 line
2.5.5
Re: [Qemu-devel] [kvm-unit-tests RFC 05/15] arm/arm64: GICv3: add cpu count
Quoted 3 lines · Eric Auger
Add a new
cpu_countfield ingicv3_dataindicating the number of redistributors. This will be useful for enumeration of their resources such as LPI pending tables.
I'm fine with the additional state, but just curious, will it ever be possible for gicv3.cpu_count != nr_cpus?
Quoted 42 lines
Signed-off-by Eric Auger <[email protected]>--- lib/arm/asm/gic-v3.h | 1 + lib/arm/gic-v3.c | 2 ++ 2 files changed, 3 insertions(+)lib/arm/asm/gic-v3.h +1
-0@@ -58,6 +58,7 @@ struct gicv3_data {void *dist_base;void *redist_base[NR_CPUS ];unsigned int irq_nr; +unsigned int cpu_count; };extern struct gicv3_data gicv3_data;lib/arm/gic-v3.c +2
-0@@ -12,12 +12,14 @@ void gicv3_set_redist_base(size_t stride)void *ptr = gicv3_data.redist_base[0 ];u64 typer; + gicv3_data.cpu_count =0 ;do { typer =gicv3_read_typer (ptr +GICR_TYPER );if ((typer >>32 ) == aff) {gicv3_redist_base () = ptr;return ; } + gicv3_data.cpu_count++; ptr += stride;/* skip RD_base, SGI_base, etc. */ }while (!(typer &GICR_TYPER_LAST ));Signature · 1 line
2.5.5
Re: [Qemu-devel] [kvm-unit-tests RFC 05/15] arm/arm64: GICv3: add cpu count
Hi,
Quoted 7 lines · Andrew Jones
Quoted 3 lines · Eric Auger
Add a new
cpu_countfield ingicv3_dataindicating the number of redistributors. This will be useful for enumeration of their resources such as LPI pending tables.I'm fine with the additional state, but just curious, will it ever be possible for gicv3.cpu_count !=
nr_cpus?
If not you are in trouble, so that should in fact be one test.
Which brings me to my comment ...
Quoted 7 lines
Quoted 7 lines
Signed-off-by Eric Auger <[email protected]>--- lib/arm/asm/gic-v3.h | 1 + lib/arm/gic-v3.c | 2 ++ 2 files changed, 3 insertions(+)
Quoted 9 lines
lib/arm/asm/gic-v3.h struct gicv3_data { · line 61
Quoted 9 lines
lib/arm/asm/gic-v3.h +1
-0@@ -58,6 +58,7 @@ struct gicv3_data {void *dist_base;void *redist_base[NR_CPUS ];unsigned int irq_nr; +unsigned int cpu_count;
Should that be called "nr_redists" or the like?
Since this is what it counts in the code below.
Later we can then compare this with nr_cpus to check for a match.
Cheers,
Andre.
Quoted 26 lines
Quoted 26 lines
lib/arm/asm/gic-v3.h +0
-0};extern struct gicv3_data gicv3_data;lib/arm/gic-v3.c +2
-0@@ -12,12 +12,14 @@ void gicv3_set_redist_base(size_t stride)void *ptr = gicv3_data.redist_base[0 ];u64 typer; + gicv3_data.cpu_count =0 ;do { typer =gicv3_read_typer (ptr +GICR_TYPER );if ((typer >>32 ) == aff) {gicv3_redist_base () = ptr;return ; } + gicv3_data.cpu_count++; ptr += stride;/* skip RD_base, SGI_base, etc. */ }while (!(typer &GICR_TYPER_LAST ));Signature · 1 line
2.5.5
Re: [Qemu-devel] [kvm-unit-tests RFC 05/15] arm/arm64: GICv3: add cpu count
Hi Andre, Drew,
Quoted 22 lines · Andre Przywara
Hi,
Quoted 7 lines · Andrew Jones
Quoted 3 lines · Eric Auger
Add a new
cpu_countfield ingicv3_dataindicating the number of redistributors. This will be useful for enumeration of their resources such as LPI pending tables.I'm fine with the additional state, but just curious, will it ever be possible for gicv3.cpu_count !=
nr_cpus?If not you are in trouble, so that should in fact be one test.
Which brings me to my comment ...
Quoted 7 lines
Quoted 7 lines
Signed-off-by Eric Auger <[email protected]>--- lib/arm/asm/gic-v3.h | 1 + lib/arm/gic-v3.c | 2 ++ 2 files changed, 3 insertions(+)
Quoted 13 lines
Quoted 9 lines
lib/arm/asm/gic-v3.h struct gicv3_data { · line 61
Quoted 9 lines
lib/arm/asm/gic-v3.h +1
-0@@ -58,6 +58,7 @@ struct gicv3_data {void *dist_base;void *redist_base[NR_CPUS ];unsigned int irq_nr; +unsigned int cpu_count;Should that be called "
nr_redists" or the like?
Since this is what it counts in the code below.
Later we can then compare this withnr_cpusto check for a match.
I fully agree with you suggestion.
Thanks
Eric
Quoted 35 lines
Cheers,
Andre.Quoted 22 lines
Quoted 22 lines
lib/arm/asm/gic-v3.h +0
-0};extern struct gicv3_data gicv3_data;lib/arm/gic-v3.c +2
-0@@ -12,12 +12,14 @@ void gicv3_set_redist_base(size_t stride)void *ptr = gicv3_data.redist_base[0 ];u64 typer; + gicv3_data.cpu_count =0 ;do { typer =gicv3_read_typer (ptr +GICR_TYPER );if ((typer >>32 ) == aff) {gicv3_redist_base () = ptr;return ; } + gicv3_data.cpu_count++; ptr += stride;/* skip RD_base, SGI_base, etc. */ }while (!(typer &GICR_TYPER_LAST ));Quoted 4 lines
Quoted 4 lines
Signature · 1 line
2.5.5--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
RFC 6/15 arm/arm64: ITS: Set the LPI config and pending tables
In reply to Eric AugerAllocate the LPI configuration and per re-distributor pending table. Set redistributor's PROPBASER and PENDBASER. The LPIs are enabled by default in the config table.
--- lib/arm/asm/gic-v3-its.h | 20 +++++++++++++ lib/arm/asm/gic-v3.h | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/arm/gic-v3-its.c | 50 +++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+)
lib/arm/asm/gic-v3-its.h +20 -0
@@ -13,6 +13,26 @@#include <asm/setup.h> #include <asm/io.h> +#define GIC_BASER_CACHEABILITY (reg, inner_outer, type) \ + (GIC_BASER_CACHE_##type << reg##_##inner_outer##_CACHEABILITY_SHIFT) + +#define GIC_BASER_SHAREABILITY (reg, type) \ + (GIC_BASER_##type << reg##_SHAREABILITY_SHIFT) + +#define GICR_PROPBASER_SHAREABILITY_SHIFT (10) +#define GICR_PROPBASER_INNER_CACHEABILITY_SHIFT (7) +#define GICR_PROPBASER_OUTER_CACHEABILITY_SHIFT (56) +#define GICR_PROPBASER_SHAREABILITY_MASK \ + GIC_BASER_SHAREABILITY(GICR_PROPBASER, SHAREABILITY_MASK) +#define GICR_PROPBASER_INNER_CACHEABILITY_MASK \ + GIC_BASER_CACHEABILITY(GICR_PROPBASER, INNER, MASK) +#define GICR_PROPBASER_OUTER_CACHEABILITY_MASK \ + GIC_BASER_CACHEABILITY(GICR_PROPBASER, OUTER, MASK) +#define GICR_PROPBASER_CACHEABILITY_MASK GICR_PROPBASER_INNER_CACHEABILITY_MASK + +#define GICR_PROPBASER_InnerShareable \ + GIC_BASER_SHAREABILITY(GICR_PROPBASER, InnerShareable) +#define GITS_BASER 0x0100#define GITS_BASER_NR_REGS 8
lib/arm/asm/gic-v3.h +77 -0
89 lines not on this page · raw message
lib/arm/gic-v3-its.c +50 -0
53 lines not on this page · raw message
Signature · 1 line
2.5.5
RFC 7/15 arm/arm64: ITS: Init the command queue
In reply to Eric AugerAllocate the command queue and initialize related registers:
CBASER, CREADR, CWRITER.
The command queue is 64kB. This aims at not bothing with fullness.
--- lib/arm/asm/gic-v3-its.h | 37 +++++++++++++++++++++++++++++++++++++ lib/arm/gic-v3-its.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+)
lib/arm/asm/gic-v3-its.h +37 -0
@@ -33,8 +33,35 @@#define GICR_PROPBASER_InnerShareable \ GIC_BASER_SHAREABILITY(GICR_PROPBASER, InnerShareable) +#define GITS_CBASER 0x0080 +#define GITS_CWRITER 0x0088 +#define GITS_CREADR 0x0090#define GITS_BASER 0x0100 +#define GITS_CBASER_VALID (1UL << 63) +#define GITS_CBASER_SHAREABILITY_SHIFT (10) +#define GITS_CBASER_INNER_CACHEABILITY_SHIFT (59) +#define GITS_CBASER_OUTER_CACHEABILITY_SHIFT (53) +#define GITS_CBASER_SHAREABILITY_MASK \ + GIC_BASER_SHAREABILITY(GITS_CBASER, SHAREABILITY_MASK) +#define GITS_CBASER_INNER_CACHEABILITY_MASK \ + GIC_BASER_CACHEABILITY(GITS_CBASER, INNER, MASK) +#define GITS_CBASER_OUTER_CACHEABILITY_MASK \ + GIC_BASER_CACHEABILITY(GITS_CBASER, OUTER, MASK) +#define GITS_CBASER_CACHEABILITY_MASK GITS_CBASER_INNER_CACHEABILITY_MASK + +#define GITS_CBASER_InnerShareable \ + GIC_BASER_SHAREABILITY(GITS_CBASER, InnerShareable) + +#define GITS_CBASER_nCnB GIC_BASER_CACHEABILITY(GITS_CBASER, INNER, nCnB) +#define GITS_CBASER_nC GIC_BASER_CACHEABILITY(GITS_CBASER, INNER, nC) +#define GITS_CBASER_RaWt GIC_BASER_CACHEABILITY(GITS_CBASER, INNER, RaWt) +#define GITS_CBASER_RaWb GIC_BASER_CACHEABILITY(GITS_CBASER, INNER, RaWt) +#define GITS_CBASER_WaWt GIC_BASER_CACHEABILITY(GITS_CBASER, INNER, WaWt) +#define GITS_CBASER_WaWb GIC_BASER_CACHEABILITY(GITS_CBASER, INNER, WaWb) +#define GITS_CBASER_RaWaWt GIC_BASER_CACHEABILITY(GITS_CBASER, INNER, RaWaWt) +#define GITS_CBASER_RaWaWb GIC_BASER_CACHEABILITY(GITS_CBASER, INNER, RaWaWb) +#define GITS_BASER_NR_REGS 8#define GITS_BASER_VALID (1UL << 63)
@@ -84,6 +111,8 @@#define GITS_BASER_TYPE_RESERVED6 6#define GITS_BASER_TYPE_RESERVED7 7 +#define ITS_FLAGS_CMDQ_NEEDS_FLUSHING (1ULL << 0) +struct its_baser {unsigned int index;int type;
@@ -97,9 +126,17 @@ struct its_baser {int esz; }; +struct its_cmd_block { +u64 raw_cmd[4 ]; +}; +struct its_data {void *base; +struct its_cmd_block *cmd_base; +struct its_cmd_block *cmd_write; +struct its_cmd_block *cmd_readr;struct its_baser baser[GITS_BASER_NR_REGS ]; +u64 flags; };extern struct its_data its_data;
lib/arm/gic-v3-its.c +35 -0
@@ -136,3 +136,38 @@ void alloc_lpi_tables(void)writeq (pend_val, ptr +GICR_PENDBASER ); } } + +/** +* init_cmd_queue: Allocate the command queue and initialize +* CBASER, CREADR, CWRITER +*/ +void init_cmd_queue (void ) +{ +u64 cbaser, tmp; + + its_data.cmd_base = (void *)phys_zalloc_aligned (SZ_64K ,SZ_64K ); + + cbaser = ((u64 )its_data.cmd_base | + GITS_CBASER_WaWb | + GITS_CBASER_InnerShareable | + (SZ_64K /SZ_4K -1 ) | +GITS_CBASER_VALID ); + +writeq (cbaser, its_data.base +GITS_CBASER ); + tmp =readq (its_data.base +GITS_CBASER ); + +if ((tmp ^ cbaser) &GITS_CBASER_SHAREABILITY_MASK ) { +if (!(tmp &GITS_CBASER_SHAREABILITY_MASK )) { + cbaser &= ~(GITS_CBASER_SHAREABILITY_MASK | +GITS_CBASER_CACHEABILITY_MASK ); + cbaser |= GITS_CBASER_nC; +writeq (cbaser, its_data.base +GITS_CBASER ); + } + its_data.flags |=ITS_FLAGS_CMDQ_NEEDS_FLUSHING ; + } + + its_data.cmd_write = its_data.cmd_base; + its_data.cmd_readr = its_data.cmd_base; +writeq (0 , its_data.base +GITS_CWRITER ); +writeq (0 , its_data.base +GITS_CREADR ); +}
Signature · 1 line
2.5.5
RFC 8/15 arm/arm64: ITS: enable LPIs at re-distributor level
In reply to Eric AugerThis helper function enables the signaling of LPIs by the redistributor to the connected PE.
--- lib/arm/asm/gic-v3-its.h | 1 + lib/arm/gic-v3-its.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+)
lib/arm/asm/gic-v3-its.h +1 -0
@@ -145,6 +145,7 @@ extern struct its_data its_data;extern int its_parse_baser (int i,struct its_baser *baser);extern void its_setup_baser (int i,struct its_baser *baser); +extern void enable_lpi (u32 redist);#endif /* !__ASSEMBLY__ */
lib/arm/gic-v3-its.c +15 -0
@@ -171,3 +171,18 @@ void init_cmd_queue(void)writeq (0 , its_data.base +GITS_CWRITER );writeq (0 , its_data.base +GITS_CREADR ); } + +void enable_lpi (u32 redist) +{ +void *ptr; +u64 val; + +if (redist >= gicv3_data.cpu_count) +report_abort ("%s redist=%d >= cpu_count=%d\n" , + __func__, redist, gicv3_data.cpu_count); + + ptr = gicv3_data.redist_base[redist]; + val =readl (ptr +GICR_CTLR ); + val |=GICR_CTLR_ENABLE_LPIS ; +writel (val, ptr +GICR_CTLR ); +}
Signature · 1 line
2.5.5
RFC 9/15 arm/arm64: ITS: Parse the typer register
In reply to Eric AugerParse the ITS TYPER and populates the associate its_data field. Some of the info are needed for command handling, typically the PTA bit which reports the target address encoding type.
--- lib/arm/asm/gic-v3-its.h | 23 +++++++++++++++++++++++ lib/arm/gic-v3-its.c | 26 ++++++++++++++++++++++++++ 2 files changed, 49 insertions(+)
lib/arm/asm/gic-v3-its.h +23 -0
@@ -33,11 +33,19 @@#define GICR_PROPBASER_InnerShareable \ GIC_BASER_SHAREABILITY(GICR_PROPBASER, InnerShareable) +#define GITS_TYPER 0x0008#define GITS_CBASER 0x0080#define GITS_CWRITER 0x0088#define GITS_CREADR 0x0090#define GITS_BASER 0x0100 +#define GITS_TYPER_PLPIS (1UL << 0) +#define GITS_TYPER_IDBITS_SHIFT 8 +#define GITS_TYPER_DEVBITS_SHIFT 13 +#define GITS_TYPER_DEVBITS (r) ((((r) >> GITS_TYPER_DEVBITS_SHIFT) & 0x1f) + 1) +#define GITS_TYPER_PTA (1UL << 19) +#define GITS_TYPER_HWCOLLCNT_SHIFT 24 +#define GITS_CBASER_VALID (1UL << 63)#define GITS_CBASER_SHAREABILITY_SHIFT (10)#define GITS_CBASER_INNER_CACHEABILITY_SHIFT (59)
@@ -130,12 +138,26 @@ struct its_cmd_block {u64 raw_cmd[4 ]; }; +struct its_typer { +unsigned int ite_size; +unsigned int event_id_bits; +unsigned int device_id_bits; +unsigned int collection_id_bits; +unsigned int hardware_collectionc_count; +bool pta; +bool cil; +bool cct; +bool phys_lpi; +bool virt_lpi; +}; +struct its_data {void *base;struct its_cmd_block *cmd_base;struct its_cmd_block *cmd_write;struct its_cmd_block *cmd_readr;struct its_baser baser[GITS_BASER_NR_REGS ]; +struct its_typer typer;u64 flags; };
@@ -143,6 +165,7 @@ extern struct its_data its_data;#define gicv3_its_base () (its_data.base) +extern void its_parse_typer (void );extern int its_parse_baser (int i,struct its_baser *baser);extern void its_setup_baser (int i,struct its_baser *baser);extern void enable_lpi (u32 redist);
lib/arm/gic-v3-its.c +26 -0
@@ -17,6 +17,32 @@ static const char * const its_base_type_string[] = { [GITS_BASER_TYPE_RESERVED7] = "Reserved (7)", }; +void its_parse_typer (void ) +{ +u64 typer; + + typer =gicv3_read_typer (gicv3_its_base () +GITS_TYPER ); + + its_data.typer.ite_size = ((typer >>4 ) &0xf ) +1 ; + its_data.typer.pta = typer &GITS_TYPER_PTA ; + its_data.typer.event_id_bits = + ((typer >>GITS_TYPER_IDBITS_SHIFT ) &0x1f ) +1 ; + its_data.typer.device_id_bits =GITS_TYPER_DEVBITS (typer)+1 ; + + its_data.typer.cil = (typer >>36 ) &0x1 ; +if (its_data.typer.cil) + its_data.typer.collection_id_bits = ((typer >>32 ) &0xf ) +1 ; +else + its_data.typer.collection_id_bits =16 ; + + its_data.typer.hardware_collectionc_count = + (typer >>GITS_TYPER_HWCOLLCNT_SHIFT ) &0xff ; + + its_data.typer.cct = typer &0x4 ; + its_data.typer.virt_lpi = typer &0x2 ; + its_data.typer.phys_lpi = typer &GITS_TYPER_PLPIS ; +} +int its_parse_baser (int i,struct its_baser *baser) {void *reg_addr =gicv3_its_base () +GITS_BASER + i *8 ;
Signature · 1 line
2.5.5
RFC 10/15 arm/arm64: ITS: its_enable_defaults
In reply to Eric Augerits_enable_defaults() is the top init function that allocates all the requested tables (device, collection, lpi config and pending tables), enable LPIs at distributor level and ITS level.
gicv3_enable_defaults must be called before.
--- lib/arm/asm/gic-v3-its.h | 10 ++++++++++ lib/arm/gic-v3-its.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+)
lib/arm/asm/gic-v3-its.h +10 -0
@@ -33,6 +33,7 @@#define GICR_PROPBASER_InnerShareable \ GIC_BASER_SHAREABILITY(GICR_PROPBASER, InnerShareable) +#define GITS_CTLR 0x0000#define GITS_TYPER 0x0008#define GITS_CBASER 0x0080#define GITS_CWRITER 0x0088
@@ -46,6 +47,8 @@#define GITS_TYPER_PTA (1UL << 19)#define GITS_TYPER_HWCOLLCNT_SHIFT 24 +#define GITS_CTLR_ENABLE (1U << 0) +#define GITS_CBASER_VALID (1UL << 63)#define GITS_CBASER_SHAREABILITY_SHIFT (10)#define GITS_CBASER_INNER_CACHEABILITY_SHIFT (59)
@@ -151,6 +154,11 @@ struct its_typer {bool virt_lpi; }; +struct its_collection { +u64 target_address; +u16 col_id; +}; +struct its_data {void *base;struct its_cmd_block *cmd_base;
@@ -158,6 +166,7 @@ struct its_data {struct its_cmd_block *cmd_readr;struct its_baser baser[GITS_BASER_NR_REGS ];struct its_typer typer; +struct its_collection *collections;u64 flags; };
@@ -169,6 +178,7 @@ extern void its_parse_typer(void);extern int its_parse_baser (int i,struct its_baser *baser);extern void its_setup_baser (int i,struct its_baser *baser);extern void enable_lpi (u32 redist); +extern void its_enable_defaults (void );#endif /* !__ASSEMBLY__ */
lib/arm/gic-v3-its.c +46 -0
49 lines not on this page · raw message
Signature · 1 line
2.5.5
RFC 11/15 arm/arm64: ITS: create device
In reply to Eric AugerIntroduce an helper function that registers a new device candidate to send MSIs on the ITS. The device is characterized by its device id, the number of event ids. This dimensions the associated interrupt translation table (ITT), allocated by this function.
--- lib/arm/asm/gic-v3-its.h | 11 +++++++++++ lib/arm/gic-v3-its.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+)
lib/arm/asm/gic-v3-its.h +11 -0
@@ -124,6 +124,8 @@#define ITS_FLAGS_CMDQ_NEEDS_FLUSHING (1ULL << 0) +#define GITS_MAX_DEVICES 8 +struct its_baser {unsigned int index;int type;
@@ -154,6 +156,12 @@ struct its_typer {bool virt_lpi; }; +struct its_device { +u32 device_id; +u32 nr_ites; +void *itt; +}; +struct its_collection {u64 target_address;u16 col_id;
@@ -164,9 +172,11 @@ struct its_data {struct its_cmd_block *cmd_base;struct its_cmd_block *cmd_write;struct its_cmd_block *cmd_readr; +struct its_device devices[GITS_MAX_DEVICES ];struct its_baser baser[GITS_BASER_NR_REGS ];struct its_typer typer;struct its_collection *collections; +u32 nb_devices;u64 flags; };
@@ -179,6 +189,7 @@ extern int its_parse_baser(int i, struct its_baser *baser);extern void its_setup_baser (int i,struct its_baser *baser);extern void enable_lpi (u32 redist);extern void its_enable_defaults (void ); +extern struct its_device *its_create_device (u32 dev_id,int nvecs);#endif /* !__ASSEMBLY__ */
lib/arm/gic-v3-its.c +28 -0
@@ -80,6 +80,19 @@ int its_parse_baser(int i, struct its_baser *baser)return 0 ; } +static struct its_baser *its_lookup_baser (int type) +{ +int i; + +for (i =0 ; i <GITS_BASER_NR_REGS ; i++) { +struct its_baser *baser = &its_data.baser[i]; + +if (baser->type == type) +return baser; + } +return NULL ; +} +void its_setup_baser (int i,struct its_baser *baser) {void *reg_addr =gicv3_its_base () +GITS_BASER + i *8 ;
@@ -258,3 +271,18 @@ void its_enable_defaults(void)writel (GITS_CTLR_ENABLE , its_data.base +GITS_CTLR ); } + +struct its_device *its_create_device (u32 device_id,int nvecs) +{ +struct its_device *new = &its_data.devices[its_data.nb_devices]; +struct its_baser *baser =its_lookup_baser (GITS_BASER_TYPE_DEVICE ); + +if (!baser) +return NULL ; + + new->device_id = device_id; + new->nr_ites = nvecs; + new->itt = (void *)phys_zalloc (new->nr_ites * baser->esz); + its_data.nb_devices++; +return new; +}
Signature · 1 line
2.5.5
RFC 12/15 arm/arm64: ITS: create collection
In reply to Eric AugerHelper function to create a collection, characterized by its collection id and the target address. Currently the number of collections cannot exceed the number of redistributors.
---
--- lib/arm/asm/gic-v3-its.h | 1 + lib/arm/gic-v3-its.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)
lib/arm/asm/gic-v3-its.h +1 -0
@@ -190,6 +190,7 @@ extern void its_setup_baser(int i, struct its_baser *baser);extern void enable_lpi (u32 redist);extern void its_enable_defaults (void );extern struct its_device *its_create_device (u32 dev_id,int nvecs); +extern struct its_collection *its_create_collection (u32 col_id,u32 target);#endif /* !__ASSEMBLY__ */
lib/arm/gic-v3-its.c +17 -0
@@ -286,3 +286,20 @@ struct its_device *its_create_device(u32 device_id, int nvecs) its_data.nb_devices++;return new; } + +struct its_collection *its_create_collection (u32 col_id,u32 pe) +{ +if (col_id >= gicv3_data.cpu_count) +report_abort ("%s coll_id=%d >= cpu_count %d\n" , + __func__, col_id, gicv3_data.cpu_count); + +if (its_data.typer.pta) + its_data.collections[col_id].target_address = + (u64 )gicv3_data.redist_base[pe]; +else + its_data.collections[col_id].target_address = pe <<16 ; + + its_data.collections[col_id].col_id = col_id; + +return &its_data.collections[col_id]; +}
Signature · 1 line
2.5.5
RFC 13/15 arm/arm64: ITS: commands
In reply to Eric AugerImplement main ITS commands. The code is largely inherited from the ITS driver.
--- arm/Makefile.common | 2 +- lib/arm/asm/gic-v3-its.h | 31 ++++ lib/arm/gic-v3-its-cmd.c | 399 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 431 insertions(+), 1 deletion(-) create mode 100644 lib/arm/gic-v3-its-cmd.c
arm/Makefile.common +1 -1
@@ -47,7 +47,7 @@ cflatobjs += lib/arm/bitops.o cflatobjs += lib/arm/psci.o cflatobjs += lib/arm/smp.o cflatobjs += lib/arm/gic.o lib/arm/gic-v2.o lib/arm/gic-v3.o -cflatobjs += lib/arm/gic-v3-its.o +cflatobjs += lib/arm/gic-v3-its.o lib/arm/gic-v3-its-cmd.o libeabi = lib/arm/libeabi.a eabiobjs = lib/arm/eabi_compat.o
lib/arm/asm/gic-v3-its.h +31 -0
@@ -126,6 +126,24 @@#define GITS_MAX_DEVICES 8 +/* +* ITS commands +*/ +#define GITS_CMD_MAPD 0x08 +#define GITS_CMD_MAPC 0x09 +#define GITS_CMD_MAPTI 0x0a +/* older GIC documentation used MAPVI for this command */ +#define GITS_CMD_MAPVI GITS_CMD_MAPTI +#define GITS_CMD_MAPI 0x0b +#define GITS_CMD_MOVI 0x01 +#define GITS_CMD_DISCARD 0x0f +#define GITS_CMD_INV 0x0c +#define GITS_CMD_MOVALL 0x0e +#define GITS_CMD_INVALL 0x0d +#define GITS_CMD_INT 0x03 +#define GITS_CMD_CLEAR 0x04 +#define GITS_CMD_SYNC 0x05 +struct its_baser {unsigned int index;int type;
@@ -192,6 +210,19 @@ extern void its_enable_defaults(void);extern struct its_device *its_create_device (u32 dev_id,int nvecs);extern struct its_collection *its_create_collection (u32 col_id,u32 target); +extern void its_send_mapd (struct its_device *dev,int valid); +extern void its_send_mapc (struct its_collection *col,int valid); +extern void its_send_mapti (struct its_device *dev,u32 irq_id, +u32 event_id,struct its_collection *col); +extern void its_send_int (struct its_device *dev,u32 event_id); +extern void its_send_movi (struct its_device *dev, +struct its_collection *col,u32 id); +extern void its_send_sync (struct its_collection *col); +extern void its_print_cmd_state (void ); + +#define ITS_FLAGS_CMDQ_NEEDS_FLUSHING (1ULL << 0) +#define ITS_FLAGS_WORKAROUND_CAVIUM_22375 (1ULL << 1) +#define ITS_FLAGS_WORKAROUND_CAVIUM_23144 (1ULL << 2)#endif /* !__ASSEMBLY__ */ #endif /* _ASMARM_GIC_V3_ITS_H_ */
lib/arm/gic-v3-its-cmd.c new file +399 -0
399 lines not on this page · raw message
Signature · 1 line
2.5.5
RFC 14/15 arm/arm64: gic: Generalize ipi_enable()
In reply to Eric AugerFor ITS test we plan to reuse the ipi_enable() code to install the IRQ handler and enable the IRQ at CPU level. Let's rename the function into setup_irq().
--- arm/gic.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
arm/gic.c +8 -6
@@ -134,6 +134,8 @@ static void check_irqnr(u32 irqnr) bad_irq[smp_processor_id ()] = irqnr; } +typedef void (*handler_t)(struct pt_regs *regs __unused); + static void ipi_handler(struct pt_regs *regs __unused) {u32 irqstat =gic_read_iar ();
@@ -209,20 +211,20 @@ static void ipi_test_smp(void)report_prefix_pop (); } -static void ipi_enable (void ) +static void setup_irq (handler_t handler) {gic_enable_defaults ();#ifdef __arm__ -install_exception_handler (EXCPTN_IRQ , ipi_handler); +install_exception_handler (EXCPTN_IRQ , handler);#else -install_irq_handler (EL1H_IRQ , ipi_handler); +install_irq_handler (EL1H_IRQ , handler);#endif local_irq_enable (); }static void ipi_send (void ) { -ipi_enable (); +setup_irq (ipi_handler);wait_on_ready ();ipi_test_self ();ipi_test_smp ();
@@ -232,7 +234,7 @@ static void ipi_send(void)static void ipi_recv (void ) { -ipi_enable (); +setup_irq (ipi_handler);cpumask_set_cpu (smp_processor_id (), &ready);while (1 )wfi ();
@@ -323,7 +325,7 @@ int main(int argc, char **argv)if (argc <2 ) {report_prefix_push ("ipi" ); -ipi_enable (); +setup_irq (ipi_handler);ipi_test_self ();check_spurious ();report_prefix_pop ();
Signature · 1 line
2.5.5
RFC 15/15 arm/arm64: ITS test
In reply to Eric AugerThis patch implements an example ITS test which
- allocates a device
- allocates a collection
- maps the device to an ITT
- maps the collection to a redistributor
- creates an ITT entry for the device
- requests an LPI for this entry
the test checks the LPI hits the right CPU and triggers the right lpi id.
--- arm/gic.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/arm/asm/gic-v3-its.h | 10 ++++++ 2 files changed, 97 insertions(+)
arm/gic.c +87 -0
@@ -31,6 +31,7 @@ static int acked[NR_CPUS], spurious[NR_CPUS];static int bad_sender[NR_CPUS ], bad_irq[NR_CPUS ];static int cmdl_sender =1 , cmdl_irq =1 ;static cpumask_t ready; +static struct its_stats lpi_stats;static void nr_cpu_check (int nr) {
@@ -154,6 +155,42 @@ static void ipi_handler(struct pt_regs *regs __unused) } } +static void lpi_handler(struct pt_regs *regs __unused) +{ +u32 irqstat =gic_read_iar (); +int irqnr =gic_iar_irqnr (irqstat); + +gic_write_eoir (irqstat); +smp_rmb ();/* pairs with wmb in lpi_stats_reset */ + lpi_stats.observed.cpu_id =smp_processor_id (); + lpi_stats.observed.lpi_id = irqnr; +smp_wmb ();/* pairs with rmb in check_lpi_stats */ +} + +static void lpi_stats_reset (int exp_cpu_id,int exp_lpi_id) +{ + lpi_stats.expected.cpu_id = exp_cpu_id; + lpi_stats.expected.lpi_id = exp_lpi_id; + lpi_stats.observed.cpu_id =-1 ; + lpi_stats.observed.lpi_id =-1 ; +smp_wmb ();/* pairs with rmb in handler */ +} + +static void check_lpi_stats (void ) +{ +mdelay (100 ); +smp_rmb ();/* pairs with wmb in lpi_handler */ +if ((lpi_stats.observed.cpu_id != lpi_stats.expected.cpu_id) || + (lpi_stats.observed.lpi_id != lpi_stats.expected.lpi_id)) +report ("Unexpected LPI (cpuid=%d, lpidid=%d)\n" , false, + lpi_stats.observed.cpu_id, + lpi_stats.observed.lpi_id); +else +report ("LPI %d on CPU %d\n" , true, + lpi_stats.observed.lpi_id, + lpi_stats.observed.cpu_id); +} +static void gicv2_ipi_send_self (void ) {writel (2 <<24 | cmdl_irq,gicv2_dist_base () +GICD_SGIR );
@@ -288,6 +325,51 @@ static void cmdl_ipi_get_inputs(int argc, char **argv) } } +static void secondary_lpi_test (void ) +{ +setup_irq (lpi_handler); +cpumask_set_cpu (smp_processor_id (), &ready); +while (1 ) +wfi (); +} + +static int gic_test_its (void ) +{ +struct its_device *dev0; +struct its_collection *col0; +int cpu; + +stats_reset (); + +setup_irq (lpi_handler); +for_each_present_cpu (cpu) { +if (cpu ==0 ) +continue ; +smp_boot_secondary (cpu, secondary_lpi_test); + } +wait_on_ready (); + +its_enable_defaults (); + +report_prefix_push ("Test 1" ); + + dev0 =its_create_device (2 /* dev id */ ,8 /* nvecs */ ); + col0 =its_create_collection (3 /* col id */ ,3 /* target PE */ ); + +lpi_stats_reset (3 ,8195 ); + +its_send_mapd (dev0, true); +its_send_mapc (col0, true); +its_send_mapti (dev0,8195 /* lpi id */ , +8200 /* event id */ , col0); +its_send_int (dev0,8200 ); + +check_lpi_stats (); + +return 0 ; + +} +static struct gic gicv2 = { .ipi = { .send_self = gicv2_ipi_send_self,
@@ -342,7 +424,12 @@ int main(int argc, char **argv)smp_boot_secondary (cpu, ipi_test); }ipi_test (); + }else if (!strcmp (argv[1 ],"its" )) { +report_prefix_push (argv[1 ]); +gic_test_its (); + +report_prefix_pop (); }else {report_abort ("Unknown subtest '%s'" , argv[1 ]); }
lib/arm/asm/gic-v3-its.h +10 -0
@@ -198,6 +198,16 @@ struct its_data {u64 flags; }; +struct its_event { +int cpu_id; +int lpi_id; +}; + +struct its_stats { +struct its_event expected; +struct its_event observed; +}; +extern struct its_data its_data;#define gicv3_its_base () (its_data.base)
Signature · 1 line
2.5.5
Quoted 51 lines · Eric Auger
This series proposes a framework to test the virtual ITS. This is based on Drew's v7 series [1]. The last patch tests several ITS commands (collection/device mapping, interrupt translation service entry creation and LPI trigger through INT command). At this point we don't use any external PCIe device to write into the
GITS_TRANSLATERregister.The bulk of the code derives from the ITS driver code so all the credit is due to Marc.
Many other ITS commands could be tested. Also existing MMIO accesses could be enhanced into standalone tests. Current focus was to make it functional.
The code deserves more cleanup with respect to cacheability attributes in general.
Tested on Cavium ThunderX [2].
Best Regards
Eric
[1] [kvm-unit-tests PATCH v7 00/11] arm/arm64: add gic framework
[2] sample command line:
$QEMU -machine virt,accel=kvm -cpu host \
-device virtio-serial-device \
-device virtconsole,chardev=ctd -chardev testdev,id=ctd \
-display none -serial stdio \
-kernel arm/gic.flat \
-smp 8 -machine gic-version=3 -append 'its'Eric Auger (15):
libcflat: Add other size defines
arm/arm64: gicv3: Add some re-distributor defines arm/arm64: ITS skeleton
arm/arm64: ITS: BASER parsing and setup arm/arm64: GICv3: add cpu count
arm/arm64: ITS: Set the LPI config and pending tables arm/arm64: ITS: Init the command queue arm/arm64: ITS: enable LPIs at re-distributor level arm/arm64: ITS: Parse the typer register arm/arm64: ITS:its_enable_defaultsarm/arm64: ITS: create device
arm/arm64: ITS: create collection
arm/arm64: ITS: commands
arm/arm64: gic: Generalizeipi_enable()arm/arm64: ITS test
Quoted 21 lines
arm/Makefile.common | 1 + arm/gic.c | 101 +++++++++++- lib/arm/asm/gic-v3-its.h | 238 +++++++++++++++++++++++++++ lib/arm/asm/gic-v3.h | 84 ++++++++++ lib/arm/asm/gic.h | 1 + lib/arm/gic-v3-its-cmd.c | 399 +++++++++++++++++++++++++++++++++++++++++++++ lib/arm/gic-v3-its.c | 305 ++++++++++++++++++++++++++++++++++ lib/arm/gic-v3.c | 2 + lib/arm/gic.c | 30 +++- lib/arm64/asm/gic-v3-its.h | 1 + lib/libcflat.h | 3 + 11 files changed, 1154 insertions(+), 11 deletions(-) create mode 100644 lib/arm/asm/gic-v3-its.h create mode 100644 lib/arm/gic-v3-its-cmd.c create mode 100644 lib/arm/gic-v3-its.c create mode 100644 lib/arm64/asm/gic-v3-its.hSignature · 1 line
2.5.5
Thanks for this Eric! I'm glad to see we're getting more GIC test coverage written, even before v8 of the gic series is posted :-) v8 will be rebased on some sysreg stuff Wei is doing for the PMU series, that's why it's held up. I'll need to set plenty of time aside to learn enough in order to review all the 'ITS:' patches in this series. Apologies if I can't get to it right away.
Thanks again,
drew
Hi,
Quoted 74 lines · Andrew Jones
Quoted 51 lines · Eric Auger
This series proposes a framework to test the virtual ITS. This is based on Drew's v7 series [1]. The last patch tests several ITS commands (collection/device mapping, interrupt translation service entry creation and LPI trigger through INT command). At this point we don't use any external PCIe device to write into the
GITS_TRANSLATERregister.The bulk of the code derives from the ITS driver code so all the credit is due to Marc.
Many other ITS commands could be tested. Also existing MMIO accesses could be enhanced into standalone tests. Current focus was to make it functional.
The code deserves more cleanup with respect to cacheability attributes in general.
Tested on Cavium ThunderX [2].
Best Regards
Eric
[1] [kvm-unit-tests PATCH v7 00/11] arm/arm64: add gic framework
[2] sample command line:
$QEMU -machine virt,accel=kvm -cpu host \
-device virtio-serial-device \
-device virtconsole,chardev=ctd -chardev testdev,id=ctd \
-display none -serial stdio \
-kernel arm/gic.flat \
-smp 8 -machine gic-version=3 -append 'its'Eric Auger (15):
libcflat: Add other size defines
arm/arm64: gicv3: Add some re-distributor defines arm/arm64: ITS skeleton
arm/arm64: ITS: BASER parsing and setup arm/arm64: GICv3: add cpu count
arm/arm64: ITS: Set the LPI config and pending tables arm/arm64: ITS: Init the command queue arm/arm64: ITS: enable LPIs at re-distributor level arm/arm64: ITS: Parse the typer register arm/arm64: ITS:its_enable_defaultsarm/arm64: ITS: create device
arm/arm64: ITS: create collection
arm/arm64: ITS: commands
arm/arm64: gic: Generalizeipi_enable()arm/arm64: ITS testQuoted 21 lines
arm/Makefile.common | 1 + arm/gic.c | 101 +++++++++++- lib/arm/asm/gic-v3-its.h | 238 +++++++++++++++++++++++++++ lib/arm/asm/gic-v3.h | 84 ++++++++++ lib/arm/asm/gic.h | 1 + lib/arm/gic-v3-its-cmd.c | 399 +++++++++++++++++++++++++++++++++++++++++++++ lib/arm/gic-v3-its.c | 305 ++++++++++++++++++++++++++++++++++ lib/arm/gic-v3.c | 2 + lib/arm/gic.c | 30 +++- lib/arm64/asm/gic-v3-its.h | 1 + lib/libcflat.h | 3 + 11 files changed, 1154 insertions(+), 11 deletions(-) create mode 100644 lib/arm/asm/gic-v3-its.h create mode 100644 lib/arm/gic-v3-its-cmd.c create mode 100644 lib/arm/gic-v3-its.c create mode 100644 lib/arm64/asm/gic-v3-its.hSignature · 1 line
2.5.5
Quoted 4 lines
Thanks for this Eric! I'm glad to see we're getting more GIC test coverage written, even before v8 of the gic series is posted :-) v8 will be rebased on some sysreg stuff Wei is doing for the PMU series,
Are you planning on a v8 post any time soon?
Quoted 3 lines
that's why it's held up. I'll need to set plenty of time aside to learn enough in order to review all the 'ITS:' patches in this series.
Are you sure you want to really taint yourself with this stuff? You wouldn't be the first who risks his mental health by understanding the ITS ;-)
That being said, I will take a look, I am in ITS land anyway for Xen ...
Cheers,
Andre.
Quoted 5 lines
Apologies if I can't get to it right away.
Thanks again,
drew
Quoted 77 lines · Andre Przywara
Hi,
Quoted 74 lines · Andrew Jones
Quoted 72 lines · Eric Auger
This series proposes a framework to test the virtual ITS. This is based on Drew's v7 series [1]. The last patch tests several ITS commands (collection/device mapping, interrupt translation service entry creation and LPI trigger through INT command). At this point we don't use any external PCIe device to write into the
GITS_TRANSLATERregister.The bulk of the code derives from the ITS driver code so all the credit is due to Marc.
Many other ITS commands could be tested. Also existing MMIO accesses could be enhanced into standalone tests. Current focus was to make it functional.
The code deserves more cleanup with respect to cacheability attributes in general.
Tested on Cavium ThunderX [2].
Best Regards
Eric
[1] [kvm-unit-tests PATCH v7 00/11] arm/arm64: add gic framework
[2] sample command line:
$QEMU -machine virt,accel=kvm -cpu host \
-device virtio-serial-device \
-device virtconsole,chardev=ctd -chardev testdev,id=ctd \
-display none -serial stdio \
-kernel arm/gic.flat \
-smp 8 -machine gic-version=3 -append 'its'Eric Auger (15):
libcflat: Add other size defines
arm/arm64: gicv3: Add some re-distributor defines arm/arm64: ITS skeleton
arm/arm64: ITS: BASER parsing and setup arm/arm64: GICv3: add cpu count
arm/arm64: ITS: Set the LPI config and pending tables arm/arm64: ITS: Init the command queue arm/arm64: ITS: enable LPIs at re-distributor level arm/arm64: ITS: Parse the typer register arm/arm64: ITS:its_enable_defaultsarm/arm64: ITS: create device
arm/arm64: ITS: create collection
arm/arm64: ITS: commands
arm/arm64: gic: Generalizeipi_enable()arm/arm64: ITS testarm/Makefile.common | 1 + arm/gic.c | 101 +++++++++++- lib/arm/asm/gic-v3-its.h | 238 +++++++++++++++++++++++++++ lib/arm/asm/gic-v3.h | 84 ++++++++++ lib/arm/asm/gic.h | 1 + lib/arm/gic-v3-its-cmd.c | 399 +++++++++++++++++++++++++++++++++++++++++++++ lib/arm/gic-v3-its.c | 305 ++++++++++++++++++++++++++++++++++ lib/arm/gic-v3.c | 2 + lib/arm/gic.c | 30 +++- lib/arm64/asm/gic-v3-its.h | 1 + lib/libcflat.h | 3 + 11 files changed, 1154 insertions(+), 11 deletions(-) create mode 100644 lib/arm/asm/gic-v3-its.h create mode 100644 lib/arm/gic-v3-its-cmd.c create mode 100644 lib/arm/gic-v3-its.c create mode 100644 lib/arm64/asm/gic-v3-its.hSignature · 1 line
2.5.5
Quoted 6 lines
Quoted 4 lines
Thanks for this Eric! I'm glad to see we're getting more GIC test coverage written, even before v8 of the gic series is posted :-) v8 will be rebased on some sysreg stuff Wei is doing for the PMU series,
Are you planning on a v8 post any time soon?
I think Wei is going to post PMU today. Hopefully everyone will be happy with the sysreg bits. If so, then I'll post v8 no later than tomorrow sometime.
Quoted 10 lines
Quoted 4 lines
that's why it's held up. I'll need to set plenty of time aside to learn enough in order to review all the 'ITS:' patches in this series.
Are you sure you want to really taint yourself with this stuff? You wouldn't be the first who risks his mental health by understanding the ITS ;-)
That being said, I will take a look, I am in ITS land anyway for Xen ...
Excellent! Thanks!
drew
Quoted 10 lines
Cheers,
Andre.Quoted 5 lines
Apologies if I can't get to it right away.
Thanks again,
drew