arm/arm64: add gic framework
Subsystems (3)
v4 cover arm/arm64: add gic framework
v4:
- Eric's r-b's
- Andre's suggestion to only take defines we need
- several other changes listed in individual patches
v3:
- Rebased on latest master
- Added Alex's r-b's
v2:
Rebased on latest master + my "populate argv[0]" series (will send a REPOST for that shortly. Additionally a few patches got fixes/features;
07/10 got same fix as kernel 7c9b973061 "irqchip/gic-v3: Configure
all interrupts as non-secure Group-1" in order to continue working over TCG, as the gicv3 code for TCG removed a hack it had there to make Linux happy.
08/10 added more output for when things fail (if they fail) 09/10 switched gicv3 broadcast implementation to using IRM. This
found a bug in a recent (but not tip) kernel, which I was about to fix, but then I saw MarcZ beat me to it.
10/10 actually check that the input irq is the received irq
Import defines, and steal enough helper functions, from Linux to enable programming of the gic (v2 and v3). Then use the framework to add an initial test (an ipi test; self, target-list, broadcast).
It's my hope that this framework will be a suitable base on which more tests may be easily added, particularly because we have vgic-new and tcg gicv3 emulation getting close to merge. (v3 UPDATE:
vgic-new and tcg gicv3 are merged now)
To run it, along with other tests, just do
./configure [ --arch=[arm|arm64] --cross-prefix=$PREFIX ] make
export QEMU=$PATH_TO_QEMU
./run_tests.sh
To run it separately do, e.g.
$QEMU -machine virt,accel=tcg -cpu cortex-a57 \
-device virtio-serial-device \
-device virtconsole,chardev=ctd -chardev testdev,id=ctd \
-display none -serial stdio \
-kernel arm/gic.flat \
-smp 123 -machine gic-version=3 -append ipi
^^ note, we can go nuts with nr-cpus on TCG :-)
Or, a KVM example using a different "sender" cpu and irq (other than zero)
$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 48 -machine gic-version=3 -append 'ipi sender=42 irq=1'
Patches:
01-05: fixes and functionality needed by the later gic patches 06-07: enable gicv2 and gicv2 IPI test
08-10: enable gicv3 and gicv3 IPI test
11: extend the IPI tests to take variable sender and irq
Available here: https://github.com/rhdrjones/kvm-unit-tests/commits/arm/gic-v4
Andrew Jones (10):
lib: xstr: allow multiple args
arm64: fix get_"sysreg32" and make MPIDR 64bit
arm/arm64: smp: support more than 8 cpus
arm/arm64: add some delay routines
arm/arm64: irq enable/disable
arm/arm64: add initial gicv2 support
arm/arm64: gicv2: add an IPI test
arm/arm64: add initial gicv3 support
arm/arm64: gicv3: add an IPI test
arm/arm64: gic: don't just use zero
Peter Xu (1):
libcflat: add IS_ALIGNED() macro, and page sizes
arm/Makefile.common | 7 +- arm/gic.c | 417 +++++++++++++++++++++++++++++++++++++++++++++ arm/run | 19 ++- arm/selftest.c | 5 +- arm/unittests.cfg | 13 ++ lib/arm/asm/arch_gicv3.h | 65 +++++++ lib/arm/asm/gic-v2.h | 28 +++ lib/arm/asm/gic-v3.h | 92 ++++++++++ lib/arm/asm/gic.h | 51 ++++++ lib/arm/asm/processor.h | 38 ++++- lib/arm/asm/setup.h | 4 +- lib/arm/gic.c | 131 ++++++++++++++ lib/arm/processor.c | 15 ++ lib/arm/setup.c | 12 +- lib/arm64/asm/arch_gicv3.h | 66 +++++++ lib/arm64/asm/gic-v2.h | 1 + lib/arm64/asm/gic-v3.h | 1 + lib/arm64/asm/gic.h | 1 + lib/arm64/asm/processor.h | 53 +++++- lib/arm64/asm/sysreg.h | 44 +++++ lib/arm64/processor.c | 15 ++ lib/libcflat.h | 10 +- 22 files changed, 1062 insertions(+), 26 deletions(-) create mode 100644 arm/gic.c create mode 100644 lib/arm/asm/arch_gicv3.h create mode 100644 lib/arm/asm/gic-v2.h create mode 100644 lib/arm/asm/gic-v3.h create mode 100644 lib/arm/asm/gic.h create mode 100644 lib/arm/gic.c create mode 100644 lib/arm64/asm/arch_gicv3.h create mode 100644 lib/arm64/asm/gic-v2.h create mode 100644 lib/arm64/asm/gic-v3.h create mode 100644 lib/arm64/asm/gic.h create mode 100644 lib/arm64/asm/sysreg.h
Signature · 1 line
2.7.4
PATCH v4 1/11 lib: xstr: allow multiple args
Make implementation equivalent to Linux's include/linux/stringify.h
--- lib/libcflat.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/libcflat.h +2 -2
@@ -27,8 +27,8 @@#define __unused __attribute__((__unused__)) -#define xstr (s) xxstr(s) -#define xxstr (s) #s +#define xstr(s...) xxstr(s) +#define xxstr(s...) #s#define __ALIGN_MASK (x, mask) (((x) + (mask)) & ~(mask))#define __ALIGN (x, a) __ALIGN_MASK(x, (typeof(x))(a) - 1)
Signature · 1 line
2.7.4
PATCH v4 2/11 arm64: fix get_"sysreg32" and make MPIDR 64bit
In reply to Andrew Jonesmrs is always 64bit, so we should always use a 64bit register. Sometimes we'll only want to return the lower 32, but not for MPIDR, as that does define fields in the upper 32.
--- lib/arm64/asm/processor.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
lib/arm64/asm/processor.h +9 -6
@@ -66,14 +66,17 @@ static inline unsigned long current_level(void)return el &0xc ; } -#define DEFINE_GET_SYSREG32 (reg) \ -static inline unsigned int get_##reg(void) \ +#define DEFINE_GET_SYSREG (reg, type) \ +static inline type get_##reg(void) \ { \ - unsigned int reg; \ - asm volatile("mrs %0, " #reg "_el1" : "=r" (reg)); \ - return reg; \ + unsigned long r; \ + asm volatile("mrs %0, " #reg "_el1" : "=r" (r)); \ + return (type)r; \ } -DEFINE_GET_SYSREG32 (mpidr) +#define DEFINE_GET_SYSREG32 (reg) DEFINE_GET_SYSREG(reg, unsigned int) +#define DEFINE_GET_SYSREG64 (reg) DEFINE_GET_SYSREG(reg, unsigned long) + +DEFINE_GET_SYSREG64 (mpidr) /* Only support Aff0 for now, gicv2 only */#define mpidr_to_cpu (mpidr) ((int)((mpidr) & 0xff))
Signature · 1 line
2.7.4
PATCH v4 3/11 arm/arm64: smp: support more than 8 cpus
In reply to Andrew JonesBy adding support for launching with gicv3 we can break the 8 vcpu limit. This patch adds support to smp code and also selects the vgic model corresponding to the host. The vgic model may also be manually selected by adding e.g. -machine gic-version=3 to extra_params.
---
v4: improved commit message
--- arm/run | 19 ++++++++++++------- arm/selftest.c | 5 ++++- lib/arm/asm/processor.h | 9 +++++++-- lib/arm/asm/setup.h | 4 ++-- lib/arm/setup.c | 12 +++++++++++- lib/arm64/asm/processor.h | 9 +++++++-- 6 files changed, 43 insertions(+), 15 deletions(-)
arm/run +12 -7
@@ -31,13 +31,6 @@ if [ -z "$ACCEL" ]; then fi fi -if [ "$HOST" = "aarch64" ] && [ "$ACCEL" = "kvm" ]; then - processor="host" - if [ "$ARCH" = "arm" ]; then - processor+=",aarch64=off" - fi -fi - qemu="${QEMU:-qemu-system-$ARCH_NAME}" qpath=$(which $qemu 2>/dev/null)
@@ -53,6 +46,18 @@ fi M='-machine virt' +if [ "$ACCEL" = "kvm" ]; then + if $qemu $M,\? 2>&1 | grep gic-version > /dev/null; then + M+=',gic-version=host' + fi + if [ "$HOST" = "aarch64" ]; then + processor="host" + if [ "$ARCH" = "arm" ]; then + processor+=",aarch64=off" + fi + fi +fi + if ! $qemu $M -device '?' 2>&1 | grep virtconsole > /dev/null; then echo "$qpath doesn't support virtio-console for chr-testdev. Exiting." exit 2
arm/selftest.c +4 -1
@@ -312,9 +312,10 @@ static bool psci_check(void)static cpumask_t smp_reported;static void cpu_report (void ) { +unsigned long mpidr =get_mpidr ();int cpu =smp_processor_id (); -report ("CPU%d online" , true, cpu); +report ("CPU(%3d) mpidr=%lx" ,mpidr_to_cpu (mpidr) == cpu, cpu, mpidr);cpumask_set_cpu (cpu, &smp_reported);halt (); }
@@ -343,6 +344,7 @@ int main(int argc, char **argv) }else if (strcmp (argv[1 ],"smp" ) ==0 ) { +unsigned long mpidr =get_mpidr ();int cpu;report ("PSCI version" ,psci_check ());
@@ -353,6 +355,7 @@ int main(int argc, char **argv)smp_boot_secondary (cpu, cpu_report); } +report ("CPU(%3d) mpidr=%lx" ,mpidr_to_cpu (mpidr) ==0 ,0 , mpidr);cpumask_set_cpu (0 , &smp_reported);while (!cpumask_full (&smp_reported))cpu_relax ();
lib/arm/asm/processor.h +7 -2
@@ -40,8 +40,13 @@ static inline unsigned int get_mpidr(void)return mpidr; } -/* Only support Aff0 for now, up to 4 cpus */ -#define mpidr_to_cpu (mpidr) ((int)((mpidr) & 0xff)) +#define MPIDR_HWID_BITMASK 0xffffff +extern int mpidr_to_cpu (unsigned long mpidr); + +#define MPIDR_LEVEL_SHIFT (level) \ + (((1 << level) >> 1) << 3) +#define MPIDR_AFFINITY_LEVEL (mpidr, level) \ + ((mpidr >> MPIDR_LEVEL_SHIFT(level)) & 0xff)extern void start_usr (void (*func)(void *arg),void *arg,unsigned long sp_usr);extern bool is_user (void );
lib/arm/asm/setup.h +2 -2
@@ -10,8 +10,8 @@#include <asm/page.h> #include <asm/pgtable-hwdef.h> -#define NR_CPUS 8 -extern u32 cpus[NR_CPUS ]; +#define NR_CPUS 255 +extern u64 cpus[NR_CPUS ];/* per-cpu IDs (MPIDRs) */ extern int nr_cpus;#define NR_MEM_REGIONS 8
lib/arm/setup.c +11 -1
@@ -24,12 +24,22 @@ extern unsigned long stacktop;extern void io_init (void );extern void setup_args_progname (const char *args); -u32 cpus[NR_CPUS ] = { [0 ...NR_CPUS -1 ] = (~0U ) }; +u64 cpus[NR_CPUS ] = { [0 ...NR_CPUS -1 ] = (~0U ) };int nr_cpus;struct mem_region mem_regions[NR_MEM_REGIONS ];phys_addr_t __phys_offset, __phys_end; +int mpidr_to_cpu (unsigned long mpidr) +{ +int i; + +for (i =0 ; i < nr_cpus; ++i) +if (cpus[i] == (mpidr &MPIDR_HWID_BITMASK )) +return i; +return -1 ; +} + static void cpu_set(int fdtnode __unused, u32 regval, void *info __unused) {int cpu = nr_cpus++;
lib/arm64/asm/processor.h +7 -2
@@ -78,8 +78,13 @@ static inline type get_##reg(void) \ DEFINE_GET_SYSREG64(mpidr) -/* Only support Aff0 for now, gicv2 only */ -#define mpidr_to_cpu (mpidr) ((int)((mpidr) & 0xff)) +#define MPIDR_HWID_BITMASK 0xff00ffffff +extern int mpidr_to_cpu (unsigned long mpidr); + +#define MPIDR_LEVEL_SHIFT (level) \ + (((1 << level) >> 1) << 3) +#define MPIDR_AFFINITY_LEVEL (mpidr, level) \ + ((mpidr >> MPIDR_LEVEL_SHIFT(level)) & 0xff)extern void start_usr (void (*func)(void *arg),void *arg,unsigned long sp_usr);extern bool is_user (void );
Signature · 1 line
2.7.4
PATCH v4 4/11 arm/arm64: add some delay routines
In reply to Andrew JonesAllow a thread to wait some specified amount of time. Can specify in cycles, usecs, and msecs.
--- lib/arm/asm/processor.h | 19 +++++++++++++++++++ lib/arm/processor.c | 15 +++++++++++++++ lib/arm64/asm/processor.h | 19 +++++++++++++++++++ lib/arm64/processor.c | 15 +++++++++++++++ 4 files changed, 68 insertions(+)
lib/arm/asm/processor.h +19 -0
@@ -5,7 +5,9 @@* * This work is licensed under the terms of the GNU LGPL, version 2. */ +#include <libcflat.h> #include <asm/ptrace.h> +#include <asm/barrier.h> enum vector {EXCPTN_RST ,
@@ -51,4 +53,21 @@ extern int mpidr_to_cpu(unsigned long mpidr);extern void start_usr (void (*func)(void *arg),void *arg,unsigned long sp_usr);extern bool is_user (void ); +static inline u64 get_cntvct (void ) +{ +u64 vct; +isb (); + asmvolatile ("mrrc p15, 1, %Q0, %R0, c14" :"=r" (vct)); +return vct; +} + +extern void delay (u64 cycles); +extern void udelay (unsigned long usecs); + +static inline void mdelay (unsigned long msecs) +{ +while (msecs--) +udelay (1000 ); +} +#endif /* _ASMARM_PROCESSOR_H_ */
lib/arm/processor.c +15 -0
@@ -9,6 +9,7 @@#include <asm/ptrace.h> #include <asm/processor.h> #include <asm/thread_info.h> +#include <asm/barrier.h> static const char *processor_modes[] = {"USER_26" ,"FIQ_26" ,"IRQ_26" ,"SVC_26" ,
@@ -141,3 +142,17 @@ bool is_user(void) {return current_thread_info ()->flags &TIF_USER_MODE ; } + +void delay (u64 cycles) +{ +u64 start =get_cntvct (); +while ((get_cntvct () - start) < cycles) +cpu_relax (); +} + +void udelay (unsigned long usec) +{ +unsigned int frq; + asmvolatile ("mrc p15, 0, %0, c14, c0, 0" :"=r" (frq)); +delay ((u64 )usec * frq /1000000 ); +}
lib/arm64/asm/processor.h +19 -0
@@ -17,8 +17,10 @@#define SCTLR_EL1_M (1 << 0)#ifndef __ASSEMBLY__ +#include <libcflat.h> #include <asm/ptrace.h> #include <asm/esr.h> +#include <asm/barrier.h> enum vector { EL1T_SYNC,
@@ -89,5 +91,22 @@ extern int mpidr_to_cpu(unsigned long mpidr);extern void start_usr (void (*func)(void *arg),void *arg,unsigned long sp_usr);extern bool is_user (void ); +static inline u64 get_cntvct (void ) +{ +u64 vct; +isb (); + asmvolatile ("mrs %0, cntvct_el0" :"=r" (vct)); +return vct; +} + +extern void delay (u64 cycles); +extern void udelay (unsigned long usecs); + +static inline void mdelay (unsigned long msecs) +{ +while (msecs--) +udelay (1000 ); +} +#endif /* !__ASSEMBLY__ */ #endif /* _ASMARM64_PROCESSOR_H_ */
lib/arm64/processor.c +15 -0
@@ -9,6 +9,7 @@#include <asm/ptrace.h> #include <asm/processor.h> #include <asm/thread_info.h> +#include <asm/barrier.h> static const char *vector_names[] = {"el1t_sync" ,
@@ -253,3 +254,17 @@ bool is_user(void) {return current_thread_info ()->flags &TIF_USER_MODE ; } + +void delay (u64 cycles) +{ +u64 start =get_cntvct (); +while ((get_cntvct () - start) < cycles) +cpu_relax (); +} + +void udelay (unsigned long usec) +{ +unsigned int frq; + asmvolatile ("mrs %0, cntfrq_el0" :"=r" (frq)); +delay ((u64 )usec * frq /1000000 ); +}
Signature · 1 line
2.7.4
PATCH v4 5/11 arm/arm64: irq enable/disable
In reply to Andrew Jones--- lib/arm/asm/processor.h | 10 ++++++++++ lib/arm64/asm/processor.h | 10 ++++++++++ 2 files changed, 20 insertions(+)
lib/arm/asm/processor.h +10 -0
@@ -35,6 +35,16 @@ static inline unsigned long current_cpsr(void)#define current_mode () (current_cpsr() & MODE_MASK) +static inline void local_irq_enable (void ) +{ + asmvolatile ("cpsie i" : : :"memory" ,"cc" ); +} + +static inline void local_irq_disable (void ) +{ + asmvolatile ("cpsid i" : : :"memory" ,"cc" ); +} +static inline unsigned int get_mpidr (void ) {unsigned int mpidr;
lib/arm64/asm/processor.h +10 -0
@@ -68,6 +68,16 @@ static inline unsigned long current_level(void)return el &0xc ; } +static inline void local_irq_enable (void ) +{ + asmvolatile ("msr daifclr, #2" : : :"memory" ); +} + +static inline void local_irq_disable (void ) +{ + asmvolatile ("msr daifset, #2" : : :"memory" ); +} +#define DEFINE_GET_SYSREG (reg, type) \ static inline type get_##reg(void) \ { \
Signature · 6 lines
2.7.4 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v4 6/11 arm/arm64: add initial gicv2 support
In reply to Andrew JonesAdd some gicv2 support. This just adds init and enable functions, allowing unit tests to start messing with it.
---
v4:
- only take defines from kernel we need now [Andre]
- moved defines to asm/gic.h so they'll be shared with v3 [drew]
- simplify enable by not caring if we reinit the distributor [drew]
- init all GICD_INT_DEF_PRI_X4 registers [Eric]
--- arm/Makefile.common | 1 + lib/arm/asm/gic-v2.h | 28 +++++++++++++++++++ lib/arm/asm/gic.h | 44 +++++++++++++++++++++++++++++ lib/arm/gic.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/arm64/asm/gic-v2.h | 1 + lib/arm64/asm/gic.h | 1 + 6 files changed, 150 insertions(+) create mode 100644 lib/arm/asm/gic-v2.h create mode 100644 lib/arm/asm/gic.h create mode 100644 lib/arm/gic.c create mode 100644 lib/arm64/asm/gic-v2.h create mode 100644 lib/arm64/asm/gic.h
arm/Makefile.common +1 -0
@@ -42,6 +42,7 @@ cflatobjs += lib/arm/mmu.o cflatobjs += lib/arm/bitops.o cflatobjs += lib/arm/psci.o cflatobjs += lib/arm/smp.o +cflatobjs += lib/arm/gic.o libeabi = lib/arm/libeabi.a eabiobjs = lib/arm/eabi_compat.o
lib/arm/asm/gic-v2.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* All GIC* defines are lifted from include/linux/irqchip/arm-gic.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_V2_H_ +#define _ASMARM_GIC_V2_H_ + +#ifndef _ASMARM_GIC_H_ +#error Do not directly include <asm/gic-v2.h>. Include <asm/gic.h> +#endif + +struct gicv2_data { +void *dist_base; +void *cpu_base; +unsigned int irq_nr; +}; +extern struct gicv2_data gicv2_data; + +#define gicv2_dist_base () (gicv2_data.dist_base) +#define gicv2_cpu_base () (gicv2_data.cpu_base) + +extern int gicv2_init (void ); +extern void gicv2_enable_defaults (void ); + +#endif /* _ASMARM_GIC_V2_H_ */
lib/arm/asm/gic.h new file +44 -0
44 lines not on this page · raw message
lib/arm/gic.c new file +75 -0
75 lines not on this page · raw message
lib/arm64/asm/gic-v2.h new file +1 -0
@@ -0,0 +1 @@ +#include "../../arm/asm/gic-v2.h"
lib/arm64/asm/gic.h new file +1 -0
@@ -0,0 +1 @@ +#include "../../arm/asm/gic.h"
Signature · 1 line
2.7.4
PATCH v4 7/11 arm/arm64: gicv2: add an IPI test
In reply to Andrew Jones---
v4: properly mask irqnr in ipi_handler
v2: add more details in the output if a test fails,
report spurious interrupts if we get them
--- arm/Makefile.common | 6 +- arm/gic.c | 195 ++++++++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 7 ++ lib/arm/asm/gic.h | 6 ++ 4 files changed, 211 insertions(+), 3 deletions(-) create mode 100644 arm/gic.c
arm/Makefile.common +3 -3
@@ -9,9 +9,9 @@ ifeq ($(LOADADDR),) LOADADDR = 0x40000000 endif -tests-common = \ - $(TEST_DIR)/selftest.flat \ - $(TEST_DIR)/spinlock-test.flat +tests-common = $(TEST_DIR)/selftest.flat +tests-common += $(TEST_DIR)/spinlock-test.flat +tests-common += $(TEST_DIR)/gic.flat all: test_cases
arm/gic.c new file +195 -0
195 lines not on this page · raw message
arm/unittests.cfg +7 -0
@@ -54,3 +54,10 @@ file = selftest.flat smp = $MAX_SMP extra_params = -append 'smp' groups = selftest + +# Test GIC emulation +[gicv2-ipi] +file = gic.flat +smp = $((($MAX_SMP < 8)?$MAX_SMP:8)) +extra_params = -machine gic-version=2 -append 'ipi' +groups = gic
lib/arm/asm/gic.h +6 -0
@@ -10,14 +10,20 @@#define GIC_CPU_CTRL 0x00#define GIC_CPU_PRIMASK 0x04 +#define GIC_CPU_INTACK 0x0c +#define GIC_CPU_EOI 0x10#define GICC_ENABLE 0x1#define GICC_INT_PRI_THRESHOLD 0xf0 +#define GICC_IAR_INT_ID_MASK 0x3ff +#define GICC_INT_SPURIOUS 1023 +#define GIC_DIST_CTRL 0x000#define GIC_DIST_CTR 0x004#define GIC_DIST_ENABLE_SET 0x100#define GIC_DIST_PRI 0x400 +#define GIC_DIST_SOFTINT 0xf00#define GICD_ENABLE 0x1#define GICD_INT_EN_SET_SGI 0x0000ffff
Signature · 1 line
2.7.4
PATCH v4 8/11 libcflat: add IS_ALIGNED() macro, and page sizes
In reply to Andrew JonesFrom: Peter Xu <[email protected]>
These macros will be useful to do page alignment checks.
--- lib/libcflat.h | 6 ++++++ 1 file changed, 6 insertions(+)
lib/libcflat.h +6 -0
@@ -33,6 +33,12 @@#define __ALIGN_MASK (x, mask) (((x) + (mask)) & ~(mask))#define __ALIGN (x, a) __ALIGN_MASK(x, (typeof(x))(a) - 1)#define ALIGN (x, a) __ALIGN((x), (a)) +#define IS_ALIGNED (x, a) (((x) & ((typeof(x))(a) - 1)) == 0) + +#define SZ_4K (0x1000) +#define SZ_64K (0x10000) +#define SZ_2M (0x200000) +#define SZ_1G (0x40000000)typedef uint8_t u8 ;typedef int8_t s8 ;
Signature · 1 line
2.7.4
PATCH v4 9/11 arm/arm64: add initial gicv3 support
In reply to Andrew Jones---
v4:
- only take defines from kernel we need now [Andre]
- simplify enable by not caring if we reinit the distributor [drew]
v2:
- configure irqs as NS GRP1
--- lib/arm/asm/arch_gicv3.h | 42 +++++++++++++++++++++ lib/arm/asm/gic-v3.h | 92 ++++++++++++++++++++++++++++++++++++++++++++++ lib/arm/asm/gic.h | 1 + lib/arm/gic.c | 56 ++++++++++++++++++++++++++++ lib/arm64/asm/arch_gicv3.h | 44 ++++++++++++++++++++++ lib/arm64/asm/gic-v3.h | 1 + lib/arm64/asm/sysreg.h | 44 ++++++++++++++++++++++ 7 files changed, 280 insertions(+) create mode 100644 lib/arm/asm/arch_gicv3.h create mode 100644 lib/arm/asm/gic-v3.h create mode 100644 lib/arm64/asm/arch_gicv3.h create mode 100644 lib/arm64/asm/gic-v3.h create mode 100644 lib/arm64/asm/sysreg.h
lib/arm/asm/arch_gicv3.h new file +42 -0
@@ -0,0 +1,42 @@ +/* +* All ripped off from arch/arm/include/asm/arch_gicv3.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_ARCH_GICV3_H_ +#define _ASMARM_ARCH_GICV3_H_ + +#ifndef __ASSEMBLY__ +#include <libcflat.h> +#include <asm/barrier.h> +#include <asm/io.h> + +#define __stringify xstr + +#define __ACCESS_CP15 (CRn, Op1, CRm, Op2) p15, Op1, %0, CRn, CRm, Op2 + +#define ICC_PMR __ACCESS_CP15(c4, 0, c6, 0) +#define ICC_IGRPEN1 __ACCESS_CP15(c12, 0, c12, 7) + +static inline void gicv3_write_pmr (u32 val) +{ + asm volatile("mcr " __stringify(ICC_PMR) : : "r" (val)); +} + +static inline void gicv3_write_grpen1 (u32 val) +{ + asm volatile("mcr " __stringify(ICC_IGRPEN1) : : "r" (val)); +isb (); +} + +static inline u64 gicv3_read_typer (const volatile void __iomem *addr) +{ +u64 val =readl (addr); + val |= (u64 )readl (addr +4 ) <<32 ; +return val; +} + +#endif /* !__ASSEMBLY__ */ +#endif /* _ASMARM_ARCH_GICV3_H_ */
lib/arm/asm/gic-v3.h new file +92 -0
92 lines not on this page · raw message
lib/arm/asm/gic.h +1 -0
@@ -7,6 +7,7 @@#define _ASMARM_GIC_H_#include <asm/gic-v2.h> +#include <asm/gic-v3.h> #define GIC_CPU_CTRL 0x00#define GIC_CPU_PRIMASK 0x04
lib/arm/gic.c +56 -0
78 lines not on this page · raw message
lib/arm64/asm/arch_gicv3.h new file +44 -0
44 lines not on this page · raw message
lib/arm64/asm/gic-v3.h new file +1 -0
@@ -0,0 +1 @@ +#include "../../arm/asm/gic-v3.h"
lib/arm64/asm/sysreg.h new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v4 10/11 arm/arm64: gicv3: add an IPI test
In reply to Andrew Jones---
v4:
- heavily comment gicv3_ipi_send_tlist() [Eric]
- changes needed for gicv2 iar/irqstat fix to other patch
v2:
- use IRM for gicv3 broadcast
--- arm/gic.c | 195 ++++++++++++++++++++++++++++++++++++++++++--- arm/unittests.cfg | 6 ++ lib/arm/asm/arch_gicv3.h | 23 ++++++ lib/arm64/asm/arch_gicv3.h | 22 +++++ 4 files changed, 236 insertions(+), 10 deletions(-)
arm/gic.c +185 -10
@@ -3,6 +3,8 @@* * GICv2 * + test sending/receiving IPIs +* GICv3 +* + test sending/receiving IPIs * * Copyright (C) 2016, Red Hat Inc, Andrew Jones <[email protected]> *
@@ -16,6 +18,19 @@#include <asm/barrier.h> #include <asm/io.h> +struct gic { +struct { +void (*enable)(void ); +void (*send_self)(void ); +void (*send_tlist)(cpumask_t *); +void (*send_broadcast)(void ); + } ipi; +u32 (*read_iar)(void ); +u32 (*irqnr)(u32 iar); +void (*write_eoi)(u32 ); +}; + +static struct gic *gic;static int gic_version;static int acked[NR_CPUS ], spurious[NR_CPUS ];static cpumask_t ready;
@@ -69,13 +84,33 @@ static void check_acked(cpumask_t *mask) false, missing, extra, unexpected); } +static u32 gicv2_read_iar (void ) +{ +return readl (gicv2_cpu_base () +GIC_CPU_INTACK ); +} + +static u32 gicv2_irqnr (u32 iar) +{ +return iar &GICC_IAR_INT_ID_MASK ; +} + +static void gicv2_write_eoi (u32 irqstat) +{ +writel (irqstat,gicv2_cpu_base () +GIC_CPU_EOI ); +} + +static u32 gicv3_irqnr (u32 iar) +{ +return iar; +} + static void ipi_handler(struct pt_regs *regs __unused) { -u32 irqstat =readl (gicv2_cpu_base () +GIC_CPU_INTACK ); -u32 irqnr = irqstat &GICC_IAR_INT_ID_MASK ; +u32 irqstat = gic->read_iar (); +u32 irqnr = gic->irqnr (irqstat);if (irqnr !=GICC_INT_SPURIOUS ) { -writel (irqstat,gicv2_cpu_base () +GIC_CPU_EOI ); + gic->write_eoi (irqstat);smp_rmb ();/* pairs with wmb in ipi_test functions */ ++acked[smp_processor_id ()];smp_wmb ();/* pairs with rmb in check_acked */
@@ -85,6 +120,112 @@ static void ipi_handler(struct pt_regs *regs __unused) } } +static void gicv2_ipi_send_self (void ) +{ +writel (2 <<24 ,gicv2_dist_base () +GIC_DIST_SOFTINT ); +} + +static void gicv2_ipi_send_tlist (cpumask_t *mask) +{ +u8 tlist = (u8 )cpumask_bits (mask)[0 ]; + +writel (tlist <<16 ,gicv2_dist_base () +GIC_DIST_SOFTINT ); +} + +static void gicv2_ipi_send_broadcast (void ) +{ +writel (1 <<24 ,gicv2_dist_base () +GIC_DIST_SOFTINT ); +} + +#define ICC_SGI1R_AFFINITY_1_SHIFT 16 +#define ICC_SGI1R_AFFINITY_2_SHIFT 32 +#define ICC_SGI1R_AFFINITY_3_SHIFT 48 +#define MPIDR_TO_SGI_AFFINITY (cluster_id, level) \ + (MPIDR_AFFINITY_LEVEL(cluster_id, level) << ICC_SGI1R_AFFINITY_## level ## _SHIFT) + +static void gicv3_ipi_send_tlist (cpumask_t *mask) +{ +u16 tlist; +int cpu; + +/* +* For each cpu in the mask collect its peers, which are also in +* the mask, in order to form target lists. +*/ +for_each_cpu (cpu, mask) { +u64 mpidr = cpus[cpu], sgi1r; +u64 cluster_id; + +/* +* GICv3 can send IPIs to up 16 peer cpus with a single +* write to ICC_SGI1R_EL1 (using the target list). Peers +* are cpus that have nearly identical MPIDRs, the only +* difference being Aff0. The matching upper affinity +* levels form the cluster ID. +*/ + cluster_id = mpidr & ~0xffUL ; + tlist =0 ; + +/* +* Sort of open code for_each_cpu in order to have a +* nested for_each_cpu loop. +*/ +while (cpu < nr_cpus) { +if ((mpidr &0xff ) >=16 ) { +printf ("cpu%d MPIDR:aff0 is %d (>= 16)!\n" , + cpu, (int )(mpidr &0xff )); +break ; + } + + tlist |=1 << (mpidr &0xf ); + + cpu =cpumask_next (cpu, mask); +if (cpu >= nr_cpus) +break ; + + mpidr = cpus[cpu]; + +if (cluster_id != (mpidr & ~0xffUL )) { +/* +* The next cpu isn't in our cluster. Roll +* back the cpu index allowing the outer +* for_each_cpu to find it again with +* cpumask_next +*/ + --cpu; +break ; + } + } + +/* Send the IPIs for the target list of this cluster */ + sgi1r = (MPIDR_TO_SGI_AFFINITY (cluster_id,3 ) | +MPIDR_TO_SGI_AFFINITY (cluster_id,2 ) | +/* irq << 24 | */ +MPIDR_TO_SGI_AFFINITY (cluster_id,1 ) | + tlist); + +gicv3_write_sgi1r (sgi1r); + } + +/* Force the above writes to ICC_SGI1R_EL1 to be executed */ +isb (); +} + +static void gicv3_ipi_send_self (void ) +{ +cpumask_t mask; + +cpumask_clear (&mask); +cpumask_set_cpu (smp_processor_id (), &mask); +gicv3_ipi_send_tlist (&mask); +} + +static void gicv3_ipi_send_broadcast (void ) +{ +gicv3_write_sgi1r (1ULL <<40 ); +isb (); +} +static void ipi_test_self (void ) {cpumask_t mask;
@@ -94,7 +235,7 @@ static void ipi_test_self(void)smp_wmb ();cpumask_clear (&mask);cpumask_set_cpu (0 , &mask); -writel (2 <<24 ,gicv2_dist_base () +GIC_DIST_SOFTINT ); + gic->ipi.send_self ();check_acked (&mask);report_prefix_pop (); }
@@ -102,14 +243,15 @@ static void ipi_test_self(void)static void ipi_test_smp (void ) {cpumask_t mask; -unsigned long tlist; +int i;report_prefix_push ("target-list" );memset (acked,0 ,sizeof (acked));smp_wmb (); - tlist =cpumask_bits (&cpu_present_mask)[0 ] &0xaa ; -cpumask_bits (&mask)[0 ] = tlist; -writel ((u8 )tlist <<16 ,gicv2_dist_base () +GIC_DIST_SOFTINT ); +cpumask_copy (&mask, &cpu_present_mask); +for (i =0 ; i < nr_cpus; i +=2 ) +cpumask_clear_cpu (i, &mask); + gic->ipi.send_tlist (&mask);check_acked (&mask);report_prefix_pop ();
@@ -118,14 +260,14 @@ static void ipi_test_smp(void)smp_wmb ();cpumask_copy (&mask, &cpu_present_mask);cpumask_clear_cpu (0 , &mask); -writel (1 <<24 ,gicv2_dist_base () +GIC_DIST_SOFTINT ); + gic->ipi.send_broadcast ();check_acked (&mask);report_prefix_pop (); }static void ipi_enable (void ) { -gicv2_enable_defaults (); + gic->ipi.enable ();#ifdef __arm__install_exception_handler (EXCPTN_IRQ , ipi_handler);#else
@@ -142,6 +284,30 @@ static void ipi_recv(void)wfi (); } +struct gic gicv2 = { + .ipi = { + .enable = gicv2_enable_defaults, + .send_self = gicv2_ipi_send_self, + .send_tlist = gicv2_ipi_send_tlist, + .send_broadcast = gicv2_ipi_send_broadcast, + }, + .read_iar = gicv2_read_iar, + .irqnr = gicv2_irqnr, + .write_eoi = gicv2_write_eoi, +}; + +struct gic gicv3 = { + .ipi = { + .enable = gicv3_enable_defaults, + .send_self = gicv3_ipi_send_self, + .send_tlist = gicv3_ipi_send_tlist, + .send_broadcast = gicv3_ipi_send_broadcast, + }, + .read_iar = gicv3_read_iar, + .irqnr = gicv3_irqnr, + .write_eoi = gicv3_write_eoir, +}; +int main (int argc,char **argv) {char pfx[8 ];
@@ -154,6 +320,15 @@ int main(int argc, char **argv)snprintf (pfx,8 ,"gicv%d" , gic_version);report_prefix_push (pfx); +switch (gic_version) { +case 2 : + gic = &gicv2; +break ; +case 3 : + gic = &gicv3; +break ; + } +if (argc <2 ) {report_prefix_push ("ipi" );
arm/unittests.cfg +6 -0
@@ -61,3 +61,9 @@ file = gic.flat smp = $((($MAX_SMP < 8)?$MAX_SMP:8)) extra_params = -machine gic-version=2 -append 'ipi' groups = gic + +[gicv3-ipi] +file = gic.flat +smp = $MAX_SMP +extra_params = -machine gic-version=3 -append 'ipi' +groups = gic
lib/arm/asm/arch_gicv3.h +23 -0
@@ -16,10 +16,28 @@#define __stringify xstr#define __ACCESS_CP15 (CRn, Op1, CRm, Op2) p15, Op1, %0, CRn, CRm, Op2 +#define __ACCESS_CP15_64 (Op1, CRm) p15, Op1, %Q0, %R0, CRm +#define ICC_EOIR1 __ACCESS_CP15(c12, 0, c12, 1) +#define ICC_IAR1 __ACCESS_CP15(c12, 0, c12, 0) +#define ICC_SGI1R __ACCESS_CP15_64(0, c12)#define ICC_PMR __ACCESS_CP15(c4, 0, c6, 0)#define ICC_IGRPEN1 __ACCESS_CP15(c12, 0, c12, 7) +static inline void gicv3_write_eoir (u32 irq) +{ + asm volatile("mcr " __stringify(ICC_EOIR1) : : "r" (val)); +isb (); +} + +static inline u32 gicv3_read_iar (void ) +{ +u32 irqstat; + asm volatile("mrc " __stringify(ICC_IAR1) : "=r" (irqstat)); +dsb (sy); +return irqstat; +} +static inline void gicv3_write_pmr (u32 val) { asm volatile("mcr " __stringify(ICC_PMR) : : "r" (val));
@@ -31,6 +49,11 @@ static inline void gicv3_write_grpen1(u32 val)isb (); } +static inline void gicv3_write_sgi1r (u64 val) +{ + asm volatile("mcrr " __stringify(ICC_SGI1R) : : "r" (val)); +} +static inline u64 gicv3_read_typer (const volatile void __iomem *addr) {u64 val =readl (addr);
lib/arm64/asm/arch_gicv3.h +22 -0
@@ -10,6 +10,9 @@#include <asm/sysreg.h> +#define ICC_EOIR1_EL1 sys_reg(3, 0, 12, 12, 1) +#define ICC_IAR1_EL1 sys_reg(3, 0, 12, 12, 0) +#define ICC_SGI1R_EL1 sys_reg(3, 0, 12, 11, 5)#define ICC_PMR_EL1 sys_reg(3, 0, 4, 6, 0)#define ICC_GRPEN1_EL1 sys_reg(3, 0, 12, 12, 7)
@@ -27,6 +30,20 @@* sets the GP register's most significant bits to 0 with an explicit cast. */ +static inline void gicv3_write_eoir (u32 irq) +{ + asm volatile("msr_s " __stringify(ICC_EOIR1_EL1) ", %0" : : "r" ((u64)irq)); +isb (); +} + +static inline u32 gicv3_read_iar (void ) +{ +u64 irqstat; + asm volatile("mrs_s %0, " __stringify(ICC_IAR1_EL1) : "=r" (irqstat)); +dsb (sy); +return (u64 )irqstat; +} +static inline void gicv3_write_pmr (u32 val) { asm volatile("msr_s " __stringify(ICC_PMR_EL1) ", %0" : : "r" ((u64)val));
@@ -38,6 +55,11 @@ static inline void gicv3_write_grpen1(u32 val)isb (); } +static inline void gicv3_write_sgi1r (u64 val) +{ + asm volatile("msr_s " __stringify(ICC_SGI1R_EL1) ", %0" : : "r" (val)); +} +#define gicv3_read_typer (c) readq(c)#endif /* __ASSEMBLY__ */
Signature · 1 line
2.7.4
PATCH v4 11/11 arm/arm64: gic: don't just use zero
In reply to Andrew JonesAllow user to select who sends ipis and with which irq, rather than just always sending irq=0 from cpu0.
---
v4: improve structure and make sure spurious checking is
done even when the sender isn't cpu0
v2: actually check that the irq received was the irq sent,
and (for gicv2) that the sender is the expected one.
--- arm/gic.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 73 insertions(+), 26 deletions(-)
arm/gic.c +73 -26
@@ -11,6 +11,7 @@* This work is licensed under the terms of the GNU LGPL, version 2. */ #include <libcflat.h> +#include <util.h> #include <asm/setup.h> #include <asm/processor.h> #include <asm/gic.h>
@@ -34,6 +35,8 @@ static struct gic *gic;static int gic_version;static int acked[NR_CPUS ], spurious[NR_CPUS ];static cpumask_t ready; +static int sender; +static u32 irq;static void nr_cpu_check (int nr) {
@@ -86,7 +89,16 @@ static void check_acked(cpumask_t *mask)static u32 gicv2_read_iar (void ) { -return readl (gicv2_cpu_base () +GIC_CPU_INTACK ); +u32 iar =readl (gicv2_cpu_base () +GIC_CPU_INTACK ); +int src = (iar >>10 ) &7 ; + +if (src != sender) { +report ("cpu%d received IPI from unexpected source cpu%d " +"(expected cpu%d)" , + false,smp_processor_id (), src, sender); + } + +return iar; }static u32 gicv2_irqnr (u32 iar)
@@ -111,9 +123,15 @@ static void ipi_handler(struct pt_regs *regs __unused)if (irqnr !=GICC_INT_SPURIOUS ) { gic->write_eoi (irqstat); -smp_rmb ();/* pairs with wmb in ipi_test functions */ - ++acked[smp_processor_id ()]; -smp_wmb ();/* pairs with rmb in check_acked */ +if (irqnr == irq) { +smp_rmb ();/* pairs with wmb in ipi_test functions */ + ++acked[smp_processor_id ()]; +smp_wmb ();/* pairs with rmb in check_acked */ + }else { +report ("cpu%d received unexpected irq %u " +"(expected %u)" , + false,smp_processor_id (), irqnr, irq); + } }else { ++spurious[smp_processor_id ()];smp_wmb ();
@@ -122,19 +140,19 @@ static void ipi_handler(struct pt_regs *regs __unused)static void gicv2_ipi_send_self (void ) { -writel (2 <<24 ,gicv2_dist_base () +GIC_DIST_SOFTINT ); +writel (2 <<24 | irq,gicv2_dist_base () +GIC_DIST_SOFTINT ); }static void gicv2_ipi_send_tlist (cpumask_t *mask) {u8 tlist = (u8 )cpumask_bits (mask)[0 ]; -writel (tlist <<16 ,gicv2_dist_base () +GIC_DIST_SOFTINT ); +writel (tlist <<16 | irq,gicv2_dist_base () +GIC_DIST_SOFTINT ); }static void gicv2_ipi_send_broadcast (void ) { -writel (1 <<24 ,gicv2_dist_base () +GIC_DIST_SOFTINT ); +writel (1 <<24 | irq,gicv2_dist_base () +GIC_DIST_SOFTINT ); }#define ICC_SGI1R_AFFINITY_1_SHIFT 16
@@ -200,7 +218,7 @@ static void gicv3_ipi_send_tlist(cpumask_t *mask)/* Send the IPIs for the target list of this cluster */ sgi1r = (MPIDR_TO_SGI_AFFINITY (cluster_id,3 ) |MPIDR_TO_SGI_AFFINITY (cluster_id,2 ) | -/* irq << 24 | */ + irq <<24 |MPIDR_TO_SGI_AFFINITY (cluster_id,1 ) | tlist);
@@ -222,7 +240,7 @@ static void gicv3_ipi_send_self(void)static void gicv3_ipi_send_broadcast (void ) { -gicv3_write_sgi1r (1ULL <<40 ); +gicv3_write_sgi1r (1ULL <<40 | irq <<24 );isb (); }
@@ -234,7 +252,7 @@ static void ipi_test_self(void)memset (acked,0 ,sizeof (acked));smp_wmb ();cpumask_clear (&mask); -cpumask_set_cpu (0 , &mask); +cpumask_set_cpu (smp_processor_id (), &mask); gic->ipi.send_self ();check_acked (&mask);report_prefix_pop ();
@@ -249,7 +267,7 @@ static void ipi_test_smp(void)memset (acked,0 ,sizeof (acked));smp_wmb ();cpumask_copy (&mask, &cpu_present_mask); -for (i =0 ; i < nr_cpus; i +=2 ) +for (i =smp_processor_id () &1 ; i < nr_cpus; i +=2 )cpumask_clear_cpu (i, &mask); gic->ipi.send_tlist (&mask);check_acked (&mask);
@@ -259,7 +277,7 @@ static void ipi_test_smp(void)memset (acked,0 ,sizeof (acked));smp_wmb ();cpumask_copy (&mask, &cpu_present_mask); -cpumask_clear_cpu (0 , &mask); +cpumask_clear_cpu (smp_processor_id (), &mask); gic->ipi.send_broadcast ();check_acked (&mask);report_prefix_pop ();
@@ -276,6 +294,27 @@ static void ipi_enable(void)local_irq_enable (); } +static void ipi_send (void ) +{ +int cpu; + +ipi_enable (); +wait_on_ready (); +ipi_test_self (); +ipi_test_smp (); + +smp_rmb (); +for_each_present_cpu (cpu) { +if (spurious[cpu]) { +printf ("ipi: WARN: cpu%d got %d spurious " +"interrupts\n" , + spurious[cpu],smp_processor_id ()); + } + } + +exit (report_summary ()); +} +static void ipi_recv (void ) {ipi_enable ();
@@ -284,6 +323,14 @@ static void ipi_recv(void)wfi (); } +static void ipi_test (void ) +{ +if (smp_processor_id () == sender) +ipi_send (); +else +ipi_recv (); +} +struct gic gicv2 = { .ipi = { .enable = gicv2_enable_defaults,
@@ -337,30 +384,30 @@ int main(int argc, char **argv)report_prefix_pop (); }else if (!strcmp (argv[1 ],"ipi" )) { +int off, i =1 ; +long val;report_prefix_push (argv[1 ]);nr_cpu_check (2 ); -for_each_present_cpu (cpu) { -if (cpu ==0 ) +while (--argc !=1 ) { + off =parse_keyval (argv[++i], &val); +if (off ==-1 )continue ; -smp_boot_secondary (cpu, ipi_recv); + argv[i][off] ='\0' ; +if (strcmp (argv[i],"sender" ) ==0 ) + sender = val; +else if (strcmp (argv[i],"irq" ) ==0 ) + irq = val; } -ipi_enable (); -wait_on_ready (); -ipi_test_self (); -ipi_test_smp (); -smp_rmb ();for_each_present_cpu (cpu) { -if (spurious[cpu]) { -printf ("ipi: WARN: cpu%d got %d spurious " -"interrupts\n" , - spurious[cpu],smp_processor_id ()); - } +if (cpu ==0 ) +continue ; +smp_boot_secondary (cpu, ipi_test); } -report_prefix_pop (); +ipi_test (); }else {report_abort ("Unknown subtest '%s'" , argv[1 ]);
Signature · 1 line
2.7.4
Re: [kvm-unit-tests PATCH v4 10/11] arm/arm64: gicv3: add an IPI test
In reply to Andrew JonesArgh. I forgot to compile/test arm32/gicv3... Just did now and found a copy+paste error.
On Tue, Nov 08, 2016 at 09:21:38PM +0100, Andrew Jones wrote:
[...]
Quoted 9 lines
lib/arm/asm/arch_gicv3.h +1
-0@@ -16,10 +16,28 @@#define __stringify xstr#define __ACCESS_CP15 (CRn, Op1, CRm, Op2) p15, Op1, %0, CRn, CRm, Op2 +#define __ACCESS_CP15_64 (Op1, CRm) p15, Op1, %Q0, %R0, CRm
lib/arm/asm/arch_gicv3.h line 29
Quoted 10 lines
lib/arm/asm/arch_gicv3.h +6
-0+#define ICC_EOIR1 __ACCESS_CP15(c12, 0, c12, 1) +#define ICC_IAR1 __ACCESS_CP15(c12, 0, c12, 0) +#define ICC_SGI1R __ACCESS_CP15_64(0, c12)#define ICC_PMR __ACCESS_CP15(c4, 0, c6, 0)#define ICC_IGRPEN1 __ACCESS_CP15(c12, 0, c12, 7) +static inline void gicv3_write_eoir (u32 irq) +{ + asm volatile("mcr " __stringify(ICC_EOIR1) : : "r" (val));
should be irq ^^
lib/arm/asm/arch_gicv3.h line 32
Quoted 3 lines
lib/arm/asm/arch_gicv3.h +3
-0+isb (); +} +
[...]
I've pushed an arm/gic-v5 branch[*] to github, and removed the broken arm/gic-v4 branch.
[*] https://github.com/rhdrjones/kvm-unit-tests/commits/arm/gic-v5
drew
Re: [kvm-unit-tests PATCH v4 03/11] arm/arm64: smp: support more than 8 cpus
In reply to Andrew JonesHi,
Quoted 129 lines · Andrew Jones
By adding support for launching with gicv3 we can break the 8 vcpu limit. This patch adds support to smp code and also selects the vgic model corresponding to the host. The vgic model may also be manually selected by adding e.g. -machine gic-version=3 to
extra_params.Reviewed-by Alex Bennée <[email protected]>Signed-off-by Andrew Jones <[email protected]>---
v4: improved commit message--- arm/run | 19 ++++++++++++------- arm/selftest.c | 5 ++++- lib/arm/asm/processor.h | 9 +++++++-- lib/arm/asm/setup.h | 4 ++-- lib/arm/setup.c | 12 +++++++++++- lib/arm64/asm/processor.h | 9 +++++++-- 6 files changed, 43 insertions(+), 15 deletions(-)arm/run +12
-7@@ -31,13 +31,6 @@ if [ -z "$ACCEL" ]; then fi fi -if [ "$HOST" = "aarch64" ] && [ "$ACCEL" = "kvm" ]; then - processor="host" - if [ "$ARCH" = "arm" ]; then - processor+=",aarch64=off" - fi -fi - qemu="${QEMU:-qemu-system-$ARCH_NAME}" qpath=$(which $qemu 2>/dev/null)@@ -53,6 +46,18 @@ fi M='-machine virt' +if [ "$ACCEL" = "kvm" ]; then + if $qemu $M,\? 2>&1 | grep gic-version > /dev/null; then + M+=',gic-version=host' + fi + if [ "$HOST" = "aarch64" ]; then + processor="host" + if [ "$ARCH" = "arm" ]; then + processor+=",aarch64=off" + fi + fi +fi + if ! $qemu $M -device '?' 2>&1 | grep virtconsole > /dev/null; then echo "$qpath doesn't support virtio-console for chr-testdev. Exiting." exit 2arm/selftest.c +4
-1@@ -312,9 +312,10 @@ static bool psci_check(void)static cpumask_t smp_reported;static void cpu_report (void ) { +unsigned long mpidr =get_mpidr ();int cpu =smp_processor_id (); -report ("CPU%d online" , true, cpu); +report ("CPU(%3d) mpidr=%lx" ,mpidr_to_cpu (mpidr) == cpu, cpu, mpidr);cpumask_set_cpu (cpu, &smp_reported);halt (); }@@ -343,6 +344,7 @@ int main(int argc, char **argv) }else if (strcmp (argv[1 ],"smp" ) ==0 ) { +unsigned long mpidr =get_mpidr ();int cpu;report ("PSCI version" ,psci_check ());@@ -353,6 +355,7 @@ int main(int argc, char **argv)smp_boot_secondary (cpu, cpu_report); } +report ("CPU(%3d) mpidr=%lx" ,mpidr_to_cpu (mpidr) ==0 ,0 , mpidr);cpumask_set_cpu (0 , &smp_reported);while (!cpumask_full (&smp_reported))cpu_relax ();lib/arm/asm/processor.h +7
-2@@ -40,8 +40,13 @@ static inline unsigned int get_mpidr(void)return mpidr; } -/* Only support Aff0 for now, up to 4 cpus */ -#define mpidr_to_cpu (mpidr) ((int)((mpidr) & 0xff)) +#define MPIDR_HWID_BITMASK 0xffffff +extern int mpidr_to_cpu (unsigned long mpidr); + +#define MPIDR_LEVEL_SHIFT (level) \ + (((1 << level) >> 1) << 3) +#define MPIDR_AFFINITY_LEVEL (mpidr, level) \ + ((mpidr >> MPIDR_LEVEL_SHIFT(level)) & 0xff)extern void start_usr (void (*func)(void *arg),void *arg,unsigned long sp_usr);extern bool is_user (void );lib/arm/asm/setup.h +2
-2@@ -10,8 +10,8 @@#include <asm/page.h> #include <asm/pgtable-hwdef.h> -#define NR_CPUS 8 -extern u32 cpus[NR_CPUS ]; +#define NR_CPUS 255 +extern u64 cpus[NR_CPUS ];/* per-cpu IDs (MPIDRs) */ extern int nr_cpus;#define NR_MEM_REGIONS 8lib/arm/setup.c +0
-0
lib/arm/setup.c extern unsigned long stacktop; · line 27
Quoted 5 lines
lib/arm/setup.c +1
-1@@ -24,12 +24,22 @@ extern unsigned long stacktop;extern void io_init (void );extern void setup_args_progname (const char *args); -u32 cpus[NR_CPUS ] = { [0 ...NR_CPUS -1 ] = (~0U ) }; +u64 cpus[NR_CPUS ] = { [0 ...NR_CPUS -1 ] = (~0U ) };
This should be ~0UL.
Also I think the type should be unsigned long to match the types used everywhere else.
Quoted 6 lines
lib/arm/setup.c +1
-0int nr_cpus;struct mem_region mem_regions[NR_MEM_REGIONS ];phys_addr_t __phys_offset, __phys_end; +int mpidr_to_cpu (unsigned long mpidr)
lib/arm/setup.c extern unsigned long stacktop; · line 43
Quoted 10 lines
lib/arm/setup.c +9
-0+{ +int i; + +for (i =0 ; i < nr_cpus; ++i) +if (cpus[i] == (mpidr &MPIDR_HWID_BITMASK )) +return i; +return -1 ; +} + static void cpu_set(int fdtnode __unused, u32 regval, void *info __unused)
I guess this needs to be extended as well, including dt_for_each_cpu_node() to cope with 64-bit reg properties in the CPU node (where the upper word is not 0).
But this is not really crucial atm, so can be fixed in a follow-up patch.
Cheers,
Andre.
Quoted 23 lines
lib/arm/setup.c +0
-0{int cpu = nr_cpus++;lib/arm64/asm/processor.h +7
-2@@ -78,8 +78,13 @@ static inline type get_##reg(void) \ DEFINE_GET_SYSREG64(mpidr) -/* Only support Aff0 for now, gicv2 only */ -#define mpidr_to_cpu (mpidr) ((int)((mpidr) & 0xff)) +#define MPIDR_HWID_BITMASK 0xff00ffffff +extern int mpidr_to_cpu (unsigned long mpidr); + +#define MPIDR_LEVEL_SHIFT (level) \ + (((1 << level) >> 1) << 3) +#define MPIDR_AFFINITY_LEVEL (mpidr, level) \ + ((mpidr >> MPIDR_LEVEL_SHIFT(level)) & 0xff)extern void start_usr (void (*func)(void *arg),void *arg,unsigned long sp_usr);extern bool is_user (void );
Re: [kvm-unit-tests PATCH v4 06/11] arm/arm64: add initial gicv2 support
In reply to Andrew JonesHi,
Quoted 85 lines · Andrew Jones
Add some gicv2 support. This just adds init and enable functions, allowing unit tests to start messing with it.
Signed-off-by Andrew Jones <[email protected]>---
v4:
- only take defines from kernel we need now [Andre]
- moved defines toasm/gic.hso they'll be shared with v3 [drew]
- simplify enable by not caring if we reinit the distributor [drew]
- init allGICD_INT_DEF_PRI_X4registers [Eric]--- arm/Makefile.common | 1 + lib/arm/asm/gic-v2.h | 28 +++++++++++++++++++ lib/arm/asm/gic.h | 44 +++++++++++++++++++++++++++++ lib/arm/gic.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/arm64/asm/gic-v2.h | 1 + lib/arm64/asm/gic.h | 1 + 6 files changed, 150 insertions(+) create mode 100644 lib/arm/asm/gic-v2.h create mode 100644 lib/arm/asm/gic.h create mode 100644 lib/arm/gic.c create mode 100644 lib/arm64/asm/gic-v2.h create mode 100644 lib/arm64/asm/gic.harm/Makefile.common +1
-0@@ -42,6 +42,7 @@ cflatobjs += lib/arm/mmu.o cflatobjs += lib/arm/bitops.o cflatobjs += lib/arm/psci.o cflatobjs += lib/arm/smp.o +cflatobjs += lib/arm/gic.o libeabi = lib/arm/libeabi.a eabiobjs = lib/arm/eabi_compat.olib/arm/asm/gic-v2.h new file +28
-0@@ -0,0 +1,28 @@ +/* +* All GIC* defines are lifted from include/linux/irqchip/arm-gic.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_V2_H_ +#define _ASMARM_GIC_V2_H_ + +#ifndef _ASMARM_GIC_H_ +#error Do not directly include <asm/gic-v2.h>. Include <asm/gic.h> +#endif + +struct gicv2_data { +void *dist_base; +void *cpu_base; +unsigned int irq_nr; +}; +extern struct gicv2_data gicv2_data; + +#define gicv2_dist_base () (gicv2_data.dist_base) +#define gicv2_cpu_base () (gicv2_data.cpu_base) + +extern int gicv2_init (void ); +extern void gicv2_enable_defaults (void ); + +#endif /* _ASMARM_GIC_V2_H_ */ lib/arm/asm/gic.h new file +8
-0@@ -0,0 +1,44 @@ +/* +* 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_H_ +#define _ASMARM_GIC_H_ +
lib/arm/asm/gic.h line 18
Quoted 10 lines
lib/arm/asm/gic.h new file +10
-0+#include <asm/gic-v2.h> + +#define GIC_CPU_CTRL 0x00 +#define GIC_CPU_PRIMASK 0x04 + +#define GICC_ENABLE 0x1 +#define GICC_INT_PRI_THRESHOLD 0xf0 + +#define GIC_DIST_CTRL 0x000 +#define GIC_DIST_CTR 0x004
I think we shouldn't copy this old name here, which stems from pre-GICv2 times (PL390?), IIUC. Both GIC specs talk of TYPER here.
Also if we now use the same defines for both the GICv2 and GICv3 distributor, we should really stick with the (modern) spec naming, which is GICD_CTRL, GICD_TYPER and so on. Same for the CPU interface (GICC_CTRL). In the kernel these names are used for GICv3, but we didn't bother to adjust the existing GICv2 names to avoid pointless churn.
Also that would line up with the bit field defines below.
Cheers,
Andre.
Quoted 122 lines
lib/arm/asm/gic.h new file +26
-0+#define GIC_DIST_ENABLE_SET 0x100 +#define GIC_DIST_PRI 0x400 + +#define GICD_ENABLE 0x1 +#define GICD_INT_EN_SET_SGI 0x0000ffff +#define GICD_INT_DEF_PRI 0xa0 +#define GICD_INT_DEF_PRI_X4 ((GICD_INT_DEF_PRI << 24) |\ + (GICD_INT_DEF_PRI << 16) |\ + (GICD_INT_DEF_PRI << 8) |\ + GICD_INT_DEF_PRI) + +#define GICD_TYPER_IRQS (typer) ((((typer) & 0x1f) + 1) * 32) + +#ifndef __ASSEMBLY__ + +/* +* gic_init will try to find all known gics, and then +* initialize the gic data for the one found. +* returns +* 0 : no gic was found +* > 0 : the gic version of the gic found +*/ +extern int gic_init (void ); + +#endif /* !__ASSEMBLY__ */ +#endif /* _ASMARM_GIC_H_ */ lib/arm/gic.c new file +75
-0@@ -0,0 +1,75 @@ +/* +* Copyright (C) 2016, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include <devicetree.h> +#include <asm/gic.h> +#include <asm/io.h> + +struct gicv2_data gicv2_data; + +/* +* Documentation/devicetree/bindings/interrupt-controller/arm,gic.txt +*/ +static bool +gic_get_dt_bases (const char *compatible,void **base1,void **base2) +{ +struct dt_pbus_reg reg; +struct dt_device gic; +struct dt_bus bus; +int node, ret; + +dt_bus_init_defaults (&bus); +dt_device_init (&gic, &bus,NULL ); + + node =dt_device_find_compatible (&gic, compatible); +assert (node >=0 || node == -FDT_ERR_NOTFOUND ); + +if (node == -FDT_ERR_NOTFOUND ) +return false; + +dt_device_bind_node (&gic, node); + + ret =dt_pbus_translate (&gic,0 , ®); +assert (ret ==0 ); + *base1 =ioremap (reg.addr, reg.size); + + ret =dt_pbus_translate (&gic,1 , ®); +assert (ret ==0 ); + *base2 =ioremap (reg.addr, reg.size); + +return true; +} + +int gicv2_init (void ) +{ +return gic_get_dt_bases ("arm,cortex-a15-gic" , + &gicv2_data.dist_base, &gicv2_data.cpu_base); +} + +int gic_init (void ) +{ +if (gicv2_init ()) +return 2 ; +return 0 ; +} + +void gicv2_enable_defaults (void ) +{ +void *dist =gicv2_dist_base (); +void *cpu_base =gicv2_cpu_base (); +unsigned int i; + + gicv2_data.irq_nr =GICD_TYPER_IRQS (readl (dist +GIC_DIST_CTR )); +if (gicv2_data.irq_nr >1020 ) + gicv2_data.irq_nr =1020 ; + +for (i =0 ; i < gicv2_data.irq_nr; i +=4 ) +writel (GICD_INT_DEF_PRI_X4 , dist + i +GIC_DIST_PRI ); + +writel (GICD_INT_EN_SET_SGI , dist +GIC_DIST_ENABLE_SET ); +writel (GICD_ENABLE , dist +GIC_DIST_CTRL ); +writel (GICC_INT_PRI_THRESHOLD , cpu_base +GIC_CPU_PRIMASK ); +writel (GICC_ENABLE , cpu_base +GIC_CPU_CTRL ); +}lib/arm64/asm/gic-v2.h new file +1
-0@@ -0,0 +1 @@ +#include "../../arm/asm/gic-v2.h" lib/arm64/asm/gic.h new file +1
-0@@ -0,0 +1 @@ +#include "../../arm/asm/gic.h"
Re: [kvm-unit-tests PATCH v4 03/11] arm/arm64: smp: support more than 8 cpus
In reply to Andre PrzywaraOn Wed, Nov 09, 2016 at 11:12:03AM +0000, Andre Przywara wrote:
[...]
Quoted 8 lines
Quoted 8 lines
lib/arm/setup.c +0
-0@@ -24,12 +24,22 @@ extern unsigned long stacktop;extern void io_init (void );extern void setup_args_progname (const char *args);
Quoted 4 lines
lib/arm/setup.c extern unsigned long stacktop; · line 27
Quoted 2 lines
lib/arm/setup.c +1
-1-u32 cpus[NR_CPUS ] = { [0 ...NR_CPUS -1 ] = (~0U ) }; +u64 cpus[NR_CPUS ] = { [0 ...NR_CPUS -1 ] = (~0U ) };This should be ~0UL.
Indeed. Thanks.
Quoted 2 lines
Also I think the type should be unsigned long to match the types used everywhere else.
I'll change mpidr_to_cpu to return u64 instead of unsigned long. Actually I think Alex suggested that. I'm not sure why I haven't done it...
Quoted 6 lines
Quoted 6 lines
lib/arm/setup.c +0
-0int nr_cpus;struct mem_region mem_regions[NR_MEM_REGIONS ];phys_addr_t __phys_offset, __phys_end;
Quoted 16 lines
lib/arm/setup.c extern unsigned long stacktop; · line 43
Quoted 11 lines
lib/arm/setup.c +10
-0+int mpidr_to_cpu (unsigned long mpidr) +{ +int i; + +for (i =0 ; i < nr_cpus; ++i) +if (cpus[i] == (mpidr &MPIDR_HWID_BITMASK )) +return i; +return -1 ; +} + static void cpu_set(int fdtnode __unused, u32 regval, void *info __unused)I guess this needs to be extended as well, including
dt_for_each_cpu_node()to cope with 64-bit reg properties in the CPU node (where the upper word is not 0).
But this is not really crucial atm, so can be fixed in a follow-up patch.
Yeah, I'll do it as a followup series, because it'll affect powerpc too.
drew
Re: [kvm-unit-tests PATCH v4 03/11] arm/arm64: smp: support more than 8 cpus
Hi,
Quoted 15 lines · Andrew Jones
On Wed, Nov 09, 2016 at 11:12:03AM +0000, Andre Przywara wrote:
[...]Quoted 8 lines
Quoted 8 lines
lib/arm/setup.c +0
-0@@ -24,12 +24,22 @@ extern unsigned long stacktop;extern void io_init (void );extern void setup_args_progname (const char *args);Quoted 4 lines
lib/arm/setup.c extern unsigned long stacktop; · line 27
Quoted 2 lines
lib/arm/setup.c +1
-1-u32 cpus[NR_CPUS ] = { [0 ...NR_CPUS -1 ] = (~0U ) }; +u64 cpus[NR_CPUS ] = { [0 ...NR_CPUS -1 ] = (~0U ) };This should be ~0UL.
Quoted 6 lines
Indeed. Thanks.
Quoted 2 lines
Also I think the type should be unsigned long to match the types used everywhere else.
I'll change
mpidr_to_cputo return u64 instead of unsigned long.
I am not sure this is the right direction. unsigned long is really the natural type for MPIDR, since this is a system register with exactly the native register size.
I think we use it this way in the kernel.
Cheers,
Andre
Quoted 30 lines
Actually I think Alex suggested that. I'm not sure why I haven't done it...
Quoted 6 lines
Quoted 6 lines
lib/arm/setup.c +0
-0int nr_cpus;struct mem_region mem_regions[NR_MEM_REGIONS ];phys_addr_t __phys_offset, __phys_end;Quoted 16 lines
lib/arm/setup.c extern unsigned long stacktop; · line 43
Quoted 11 lines
lib/arm/setup.c +10
-0+int mpidr_to_cpu (unsigned long mpidr) +{ +int i; + +for (i =0 ; i < nr_cpus; ++i) +if (cpus[i] == (mpidr &MPIDR_HWID_BITMASK )) +return i; +return -1 ; +} + static void cpu_set(int fdtnode __unused, u32 regval, void *info __unused)I guess this needs to be extended as well, including
dt_for_each_cpu_node()to cope with 64-bit reg properties in the CPU node (where the upper word is not 0).
But this is not really crucial atm, so can be fixed in a follow-up patch.Yeah, I'll do it as a followup series, because it'll affect powerpc too.
drew
Re: [Qemu-devel] [kvm-unit-tests PATCH v4 06/11] arm/arm64: add initial gicv2 support
In reply to Andre PrzywaraOn Wed, Nov 09, 2016 at 11:53:39AM +0000, Andre Przywara wrote:
[...]
Quoted 28 lines
Quoted 14 lines
lib/arm/asm/gic.h new file +8
-0@@ -0,0 +1,44 @@ +/* +* 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_H_ +#define _ASMARM_GIC_H_ +lib/arm/asm/gic.h line 18
Quoted 10 lines
lib/arm/asm/gic.h new file +10
-0+#include <asm/gic-v2.h> + +#define GIC_CPU_CTRL 0x00 +#define GIC_CPU_PRIMASK 0x04 + +#define GICC_ENABLE 0x1 +#define GICC_INT_PRI_THRESHOLD 0xf0 + +#define GIC_DIST_CTRL 0x000 +#define GIC_DIST_CTR 0x004I think we shouldn't copy this old name here, which stems from pre-GICv2 times (PL390?), IIUC. Both GIC specs talk of TYPER here.
Quoted 7 lines
Also if we now use the same defines for both the GICv2 and GICv3 distributor, we should really stick with the (modern) spec naming, which is
GICD_CTRL,GICD_TYPERand so on. Same for the CPU interface (GICC_CTRL). In the kernel these names are used for GICv3, but we didn't bother to adjust the existing GICv2 names to avoid pointless churn.
Also that would line up with the bit field defines below.
Yeah, I noticed the CTR vs. TYPER naming weirdness. I considered exclusively defining the gicv3/modern/better name, but wasn't sure I should deviate from the kernel names. Keeping the names consistent is nice for grepping kernel sources, which needs to be done when a test fails and we want to find the bug.
I'd personally prefer "pointless" churn in the kernel to get it straightened out there. If it ever is, then I'd obviously update this code too. Until then, I think maintaining easy greppability is the better choice.
Thanks,
drew
Re: [Qemu-devel] [kvm-unit-tests PATCH v4 03/11] arm/arm64: smp: support more than 8 cpus
In reply to Andre PrzywaraQuoted 23 lines · Andre Przywara
Hi,
Quoted 20 lines · Andrew Jones
On Wed, Nov 09, 2016 at 11:12:03AM +0000, Andre Przywara wrote:
[...]Quoted 8 lines
Quoted 8 lines
lib/arm/setup.c +0
-0@@ -24,12 +24,22 @@ extern unsigned long stacktop;extern void io_init (void );extern void setup_args_progname (const char *args);Quoted 4 lines
lib/arm/setup.c extern unsigned long stacktop; · line 27
Quoted 2 lines
lib/arm/setup.c +1
-1-u32 cpus[NR_CPUS ] = { [0 ...NR_CPUS -1 ] = (~0U ) }; +u64 cpus[NR_CPUS ] = { [0 ...NR_CPUS -1 ] = (~0U ) };This should be ~0UL.
Indeed. Thanks.
Quoted 2 lines
Also I think the type should be unsigned long to match the types used everywhere else.
Quoted 6 lines
Quoted 1 line
I'll change
mpidr_to_cputo return u64 instead of unsigned long.I am not sure this is the right direction. unsigned long is really the natural type for MPIDR, since this is a system register with exactly the native register size.
I think we use it this way in the kernel.
OK, actually, considering arm32 and arm64 should both implement mpidr_to_cpu, and the interface should be consistent, then unsigned long is the only way.
Thanks,
drew
Re: [kvm-unit-tests PATCH v4 09/11] arm/arm64: add initial gicv3 support
In reply to Andrew JonesHi,
Quoted 83 lines · Andrew Jones
Signed-off-by Andrew Jones <[email protected]>---
v4:
- only take defines from kernel we need now [Andre]
- simplify enable by not caring if we reinit the distributor [drew]
v2:
- configure irqs as NS GRP1--- lib/arm/asm/arch_gicv3.h | 42 +++++++++++++++++++++ lib/arm/asm/gic-v3.h | 92 ++++++++++++++++++++++++++++++++++++++++++++++ lib/arm/asm/gic.h | 1 + lib/arm/gic.c | 56 ++++++++++++++++++++++++++++ lib/arm64/asm/arch_gicv3.h | 44 ++++++++++++++++++++++ lib/arm64/asm/gic-v3.h | 1 + lib/arm64/asm/sysreg.h | 44 ++++++++++++++++++++++ 7 files changed, 280 insertions(+) create mode 100644 lib/arm/asm/arch_gicv3.h create mode 100644 lib/arm/asm/gic-v3.h create mode 100644 lib/arm64/asm/arch_gicv3.h create mode 100644 lib/arm64/asm/gic-v3.h create mode 100644 lib/arm64/asm/sysreg.hlib/arm/asm/arch_gicv3.h new file +42
-0@@ -0,0 +1,42 @@ +/* +* All ripped off from arch/arm/include/asm/arch_gicv3.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_ARCH_GICV3_H_ +#define _ASMARM_ARCH_GICV3_H_ + +#ifndef __ASSEMBLY__ +#include <libcflat.h> +#include <asm/barrier.h> +#include <asm/io.h> + +#define __stringify xstr + +#define __ACCESS_CP15 (CRn, Op1, CRm, Op2) p15, Op1, %0, CRn, CRm, Op2 + +#define ICC_PMR __ACCESS_CP15(c4, 0, c6, 0) +#define ICC_IGRPEN1 __ACCESS_CP15(c12, 0, c12, 7) + +static inline void gicv3_write_pmr (u32 val) +{ + asm volatile("mcr " __stringify(ICC_PMR) : : "r" (val)); +} + +static inline void gicv3_write_grpen1 (u32 val) +{ + asm volatile("mcr " __stringify(ICC_IGRPEN1) : : "r" (val)); +isb (); +} + +static inline u64 gicv3_read_typer (const volatile void __iomem *addr) +{ +u64 val =readl (addr); + val |= (u64 )readl (addr +4 ) <<32 ; +return val; +} + +#endif /* !__ASSEMBLY__ */ +#endif /* _ASMARM_ARCH_GICV3_H_ */ lib/arm/asm/gic-v3.h new file +6
-0@@ -0,0 +1,92 @@ +/* +* All GIC* 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.
lib/arm/asm/gic-v3.h line 16
Quoted 10 lines
lib/arm/asm/gic-v3.h new file +10
-0+*/ +#ifndef _ASMARM_GIC_V3_H_ +#define _ASMARM_GIC_V3_H_ + +#ifndef _ASMARM_GIC_H_ +#error Do not directly include <asm/gic-v3.h>. Include <asm/gic.h> +#endif + +#define GICD_CTLR 0x0000 +#define GICD_TYPER 0x0004
So if we share the distributor register definition with GICv2, these shouldn't be here, but in gic.h.
But this is the right naming scheme we should use (instead of GIC_DIST_xxx).
Now this gets interesting with your wish to both share the definitions for the GICv2 and GICv3 distributors, but also stick to the names the kernel uses (because they differ between the two) ;-)
So now you loose the greppability for either GIC_DIST_CTR or GICD_TYPER, for instance.
Quoted 154 lines
lib/arm/asm/gic-v3.h new file +76
-0+#define GICD_IGROUPR 0x0080 + +#define GICD_CTLR_RWP (1U << 31) +#define GICD_CTLR_ARE_NS (1U << 4) +#define GICD_CTLR_ENABLE_G1A (1U << 1) +#define GICD_CTLR_ENABLE_G1 (1U << 0) + +#define GICR_TYPER 0x0008 +#define GICR_IGROUPR0 GICD_IGROUPR +#define GICR_TYPER_LAST (1U << 4) + + +#include <asm/arch_gicv3.h> + +#ifndef __ASSEMBLY__ +#include <asm/setup.h> +#include <asm/smp.h> +#include <asm/processor.h> +#include <asm/io.h> + +struct gicv3_data { +void *dist_base; +void *redist_base[NR_CPUS ]; +unsigned int irq_nr; +}; +extern struct gicv3_data gicv3_data; + +#define gicv3_dist_base () (gicv3_data.dist_base) +#define gicv3_redist_base () (gicv3_data.redist_base[smp_processor_id()]) +#define gicv3_sgi_base () (gicv3_data.redist_base[smp_processor_id()] + SZ_64K) + +extern int gicv3_init (void ); +extern void gicv3_enable_defaults (void ); + +static inline void gicv3_do_wait_for_rwp (void *base) +{ +int count =100000 ;/* 1s */ + +while (readl (base +GICD_CTLR ) &GICD_CTLR_RWP ) { +if (!--count) { +printf ("GICv3: RWP timeout!\n" ); +abort (); + } +cpu_relax (); +udelay (10 ); + }; +} + +static inline void gicv3_dist_wait_for_rwp (void ) +{ +gicv3_do_wait_for_rwp (gicv3_dist_base ()); +} + +static inline void gicv3_redist_wait_for_rwp (void ) +{ +gicv3_do_wait_for_rwp (gicv3_redist_base ()); +} + +static inline u32 mpidr_compress (u64 mpidr) +{ +u64 compressed = mpidr &MPIDR_HWID_BITMASK ; + + compressed = (((compressed >>32 ) &0xff ) <<24 ) | compressed; +return compressed; +} + +static inline u64 mpidr_uncompress (u32 compressed) +{ +u64 mpidr = ((u64 )compressed >>24 ) <<32 ; + + mpidr |= compressed &MPIDR_HWID_BITMASK ; +return mpidr; +} + +#endif /* !__ASSEMBLY__ */ +#endif /* _ASMARM_GIC_V3_H_ */ lib/arm/asm/gic.h +1
-0@@ -7,6 +7,7 @@#define _ASMARM_GIC_H_#include <asm/gic-v2.h> +#include <asm/gic-v3.h> #define GIC_CPU_CTRL 0x00#define GIC_CPU_PRIMASK 0x04lib/arm/gic.c +37
-0@@ -8,9 +8,11 @@#include <asm/io.h> struct gicv2_data gicv2_data; +struct gicv3_data gicv3_data;/* * Documentation/devicetree/bindings/interrupt-controller/arm,gic.txt +* Documentation/devicetree/bindings/interrupt-controller/arm,gic-v3.txt */ static bool gic_get_dt_bases (const char *compatible,void **base1,void **base2)@@ -48,10 +50,18 @@ int gicv2_init(void) &gicv2_data.dist_base, &gicv2_data.cpu_base); } +int gicv3_init (void ) +{ +return gic_get_dt_bases ("arm,gic-v3" , &gicv3_data.dist_base, + &gicv3_data.redist_base[0 ]); +} +int gic_init (void ) {if (gicv2_init ())return 2 ; +else if (gicv3_init ()) +return 3 ;return 0 ; }@@ -73,3 +83,49 @@ void gicv2_enable_defaults(void)writel (GICC_INT_PRI_THRESHOLD , cpu_base +GIC_CPU_PRIMASK );writel (GICC_ENABLE , cpu_base +GIC_CPU_CTRL ); } + +void gicv3_set_redist_base (void ) +{ +u32 aff =mpidr_compress (get_mpidr ()); +void *ptr = gicv3_data.redist_base[0 ]; +u64 typer; + +do { + typer =gicv3_read_typer (ptr +GICR_TYPER ); +if ((typer >>32 ) == aff) { +gicv3_redist_base () = ptr; +return ; + } + ptr +=SZ_64K *2 ;/* skip RD_base and SGI_base */ + }while (!(typer &GICR_TYPER_LAST )); +assert (0 ); +} + +void gicv3_enable_defaults (void ) +{ +void *dist =gicv3_dist_base (); +void *sgi_base; +unsigned int i; + + gicv3_data.irq_nr =GICD_TYPER_IRQS (readl (dist +GICD_TYPER )); +if (gicv3_data.irq_nr >1020 ) + gicv3_data.irq_nr =1020 ;
lib/arm/gic.c void gicv2_enable_defaults(void) · line 122
Quoted 10 lines
lib/arm/gic.c +10
-0+ +writel (GICD_CTLR_ARE_NS |GICD_CTLR_ENABLE_G1A |GICD_CTLR_ENABLE_G1 , + dist +GICD_CTLR ); +gicv3_dist_wait_for_rwp (); + +if (!gicv3_redist_base ()) +gicv3_set_redist_base (); + sgi_base =gicv3_sgi_base (); + +writel (~0 , sgi_base +GICR_IGROUPR0 );
This is mixing redist setup with distributor setup. Is it that what you meant with:
" - simplify enable by not caring if we reinit the distributor [drew]"?
Also if you set the group for the SGIs, you should set it for SPIs as well (like the kernel does). This was done in v3 of the series.
What about you finish the per-CPU setup first, then bail out with:
if (smp_processor_id() != 0)
return;
and then do the distributor setup (only on the first core).
Cheers,
Andre.
Quoted 117 lines
lib/arm/gic.c +9
-0+writel (GICD_INT_EN_SET_SGI , sgi_base +GIC_DIST_ENABLE_SET ); + +for (i =0 ; i <32 ; i +=4 ) +writel (GICD_INT_DEF_PRI_X4 , sgi_base +GIC_DIST_PRI + i); +gicv3_redist_wait_for_rwp (); + +gicv3_write_pmr (0xf0 ); +gicv3_write_grpen1 (1 ); +}lib/arm64/asm/arch_gicv3.h new file +44
-0@@ -0,0 +1,44 @@ +/* +* All ripped off from arch/arm64/include/asm/arch_gicv3.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 _ASMARM64_ARCH_GICV3_H_ +#define _ASMARM64_ARCH_GICV3_H_ + +#include <asm/sysreg.h> + +#define ICC_PMR_EL1 sys_reg(3, 0, 4, 6, 0) +#define ICC_GRPEN1_EL1 sys_reg(3, 0, 12, 12, 7) + +#ifndef __ASSEMBLY__ + +#include <libcflat.h> +#include <asm/barrier.h> + +#define __stringify xstr + +/* +* Low-level accessors +* +* These system registers are 32 bits, but we make sure that the compiler +* sets the GP register's most significant bits to 0 with an explicit cast. +*/ + +static inline void gicv3_write_pmr (u32 val) +{ + asm volatile("msr_s " __stringify(ICC_PMR_EL1) ", %0" : : "r" ((u64)val)); +} + +static inline void gicv3_write_grpen1 (u32 val) +{ + asm volatile("msr_s " __stringify(ICC_GRPEN1_EL1) ", %0" : : "r" ((u64)val)); +isb (); +} + +#define gicv3_read_typer (c) readq(c) + +#endif /* __ASSEMBLY__ */ +#endif /* _ASMARM64_ARCH_GICV3_H_ */ lib/arm64/asm/gic-v3.h new file +1
-0@@ -0,0 +1 @@ +#include "../../arm/asm/gic-v3.h" lib/arm64/asm/sysreg.h new file +44
-0@@ -0,0 +1,44 @@ +/* +* Ripped off from arch/arm64/include/asm/sysreg.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 _ASMARM64_SYSREG_H_ +#define _ASMARM64_SYSREG_H_ + +#define sys_reg (op0, op1, crn, crm, op2) \ + ((((op0)&3)<<19)|((op1)<<16)|((crn)<<12)|((crm)<<8)|((op2)<<5)) + +#ifdef __ASSEMBLY__ + .irp num,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30 + .equ .L__reg_num_x\num, \num + .endr + .equ .L__reg_num_xzr, 31 + + .macro mrs_s, rt, sreg + .inst 0xd5200000|(\sreg)|(.L__reg_num_\rt) + .endm + + .macro msr_s, sreg, rt + .inst 0xd5000000|(\sreg)|(.L__reg_num_\rt) + .endm +#else +asm( +" .irp num,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30\n" +" .equ .L__reg_num_x\\num, \\num\n" +" .endr\n" +" .equ .L__reg_num_xzr, 31\n" +"\n" +" .macro mrs_s, rt, sreg\n" +" .inst 0xd5200000|(\\sreg)|(.L__reg_num_\\rt)\n" +" .endm\n" +"\n" +" .macro msr_s, sreg, rt\n" +" .inst 0xd5000000|(\\sreg)|(.L__reg_num_\\rt)\n" +" .endm\n" +); +#endif + +#endif /* _ASMARM64_SYSREG_H_ */
Re: [Qemu-devel] [kvm-unit-tests PATCH v4 09/11] arm/arm64: add initial gicv3 support
On Wed, Nov 09, 2016 at 12:35:48PM +0000, Andre Przywara wrote:
[...]
Quoted 27 lines
Quoted 12 lines
lib/arm/asm/gic-v3.h new file +6
-0@@ -0,0 +1,92 @@ +/* +* All GIC* 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. lib/arm/asm/gic-v3.h line 16
Quoted 10 lines
lib/arm/asm/gic-v3.h new file +10
-0+*/ +#ifndef _ASMARM_GIC_V3_H_ +#define _ASMARM_GIC_V3_H_ + +#ifndef _ASMARM_GIC_H_ +#error Do not directly include <asm/gic-v3.h>. Include <asm/gic.h> +#endif + +#define GICD_CTLR 0x0000 +#define GICD_TYPER 0x0004So if we share the distributor register definition with GICv2, these shouldn't be here, but in
gic.h.
But this is the right naming scheme we should use (instead ofGIC_DIST_xxx).
Quoted 5 lines
Now this gets interesting with your wish to both share the definitions for the GICv2 and GICv3 distributors, but also stick to the names the kernel uses (because they differ between the two) ;-)
So now you loose the greppability for eitherGIC_DIST_CTRorGICD_TYPER, for instance.
Well, we just have the same offset with two names (giving us two symbols to grep). I put them here, vs. asm/gic.h, because the kernel only uses theses symbols for gicv3. Now, nothing stops a unit test from using them with gicv2 tests, though, because unit tests include gic.h, which includes both gic-v2.h and gic-v3.h, and thus it gets both. I know, it's sounding messy... Shouldn't we post some churn to the kernel? :-)
Note, I tried to only add defines to asm/gic.h that are actually shared in the kernel between v2 and v3, e.g. GIC_DIST_ENABLE_SET. Actually, GIC_DIST_CTRL and GIC_DIST_CTR may be the only exceptions we have so far.
Quoted 161 lines
Quoted 161 lines
lib/arm/asm/gic-v3.h new file +76
-0+#define GICD_IGROUPR 0x0080 + +#define GICD_CTLR_RWP (1U << 31) +#define GICD_CTLR_ARE_NS (1U << 4) +#define GICD_CTLR_ENABLE_G1A (1U << 1) +#define GICD_CTLR_ENABLE_G1 (1U << 0) + +#define GICR_TYPER 0x0008 +#define GICR_IGROUPR0 GICD_IGROUPR +#define GICR_TYPER_LAST (1U << 4) + + +#include <asm/arch_gicv3.h> + +#ifndef __ASSEMBLY__ +#include <asm/setup.h> +#include <asm/smp.h> +#include <asm/processor.h> +#include <asm/io.h> + +struct gicv3_data { +void *dist_base; +void *redist_base[NR_CPUS ]; +unsigned int irq_nr; +}; +extern struct gicv3_data gicv3_data; + +#define gicv3_dist_base () (gicv3_data.dist_base) +#define gicv3_redist_base () (gicv3_data.redist_base[smp_processor_id()]) +#define gicv3_sgi_base () (gicv3_data.redist_base[smp_processor_id()] + SZ_64K) + +extern int gicv3_init (void ); +extern void gicv3_enable_defaults (void ); + +static inline void gicv3_do_wait_for_rwp (void *base) +{ +int count =100000 ;/* 1s */ + +while (readl (base +GICD_CTLR ) &GICD_CTLR_RWP ) { +if (!--count) { +printf ("GICv3: RWP timeout!\n" ); +abort (); + } +cpu_relax (); +udelay (10 ); + }; +} + +static inline void gicv3_dist_wait_for_rwp (void ) +{ +gicv3_do_wait_for_rwp (gicv3_dist_base ()); +} + +static inline void gicv3_redist_wait_for_rwp (void ) +{ +gicv3_do_wait_for_rwp (gicv3_redist_base ()); +} + +static inline u32 mpidr_compress (u64 mpidr) +{ +u64 compressed = mpidr &MPIDR_HWID_BITMASK ; + + compressed = (((compressed >>32 ) &0xff ) <<24 ) | compressed; +return compressed; +} + +static inline u64 mpidr_uncompress (u32 compressed) +{ +u64 mpidr = ((u64 )compressed >>24 ) <<32 ; + + mpidr |= compressed &MPIDR_HWID_BITMASK ; +return mpidr; +} + +#endif /* !__ASSEMBLY__ */ +#endif /* _ASMARM_GIC_V3_H_ */ lib/arm/asm/gic.h +1
-0@@ -7,6 +7,7 @@#define _ASMARM_GIC_H_#include <asm/gic-v2.h> +#include <asm/gic-v3.h> #define GIC_CPU_CTRL 0x00#define GIC_CPU_PRIMASK 0x04lib/arm/gic.c +43
-0@@ -8,9 +8,11 @@#include <asm/io.h> struct gicv2_data gicv2_data; +struct gicv3_data gicv3_data;/* * Documentation/devicetree/bindings/interrupt-controller/arm,gic.txt +* Documentation/devicetree/bindings/interrupt-controller/arm,gic-v3.txt */ static bool gic_get_dt_bases (const char *compatible,void **base1,void **base2)@@ -48,10 +50,18 @@ int gicv2_init(void) &gicv2_data.dist_base, &gicv2_data.cpu_base); } +int gicv3_init (void ) +{ +return gic_get_dt_bases ("arm,gic-v3" , &gicv3_data.dist_base, + &gicv3_data.redist_base[0 ]); +} +int gic_init (void ) {if (gicv2_init ())return 2 ; +else if (gicv3_init ()) +return 3 ;return 0 ; }@@ -73,3 +83,49 @@ void gicv2_enable_defaults(void)writel (GICC_INT_PRI_THRESHOLD , cpu_base +GIC_CPU_PRIMASK );writel (GICC_ENABLE , cpu_base +GIC_CPU_CTRL ); } + +void gicv3_set_redist_base (void ) +{ +u32 aff =mpidr_compress (get_mpidr ()); +void *ptr = gicv3_data.redist_base[0 ]; +u64 typer; + +do { + typer =gicv3_read_typer (ptr +GICR_TYPER ); +if ((typer >>32 ) == aff) { +gicv3_redist_base () = ptr; +return ; + } + ptr +=SZ_64K *2 ;/* skip RD_base and SGI_base */ + }while (!(typer &GICR_TYPER_LAST )); +assert (0 ); +} + +void gicv3_enable_defaults (void ) +{ +void *dist =gicv3_dist_base (); +void *sgi_base; +unsigned int i; + + gicv3_data.irq_nr =GICD_TYPER_IRQS (readl (dist +GICD_TYPER )); +if (gicv3_data.irq_nr >1020 ) + gicv3_data.irq_nr =1020 ; + +writel (GICD_CTLR_ARE_NS |GICD_CTLR_ENABLE_G1A |GICD_CTLR_ENABLE_G1 , + dist +GICD_CTLR ); +gicv3_dist_wait_for_rwp (); + +if (!gicv3_redist_base ())
Quoted 8 lines
lib/arm/gic.c void gicv2_enable_defaults(void) · line 122
Quoted 4 lines
lib/arm/gic.c +4
-0+gicv3_set_redist_base (); + sgi_base =gicv3_sgi_base (); + +writel (~0 , sgi_base +GICR_IGROUPR0 );This is mixing redist setup with distributor setup. Is it that what you meant with:
" - simplify enable by not caring if we reinit the distributor [drew]"?
Yes, but, TBH, I wasn't sure I could get away with it. I tested and it worked, and I figured you'd yell at me if I was wrong :-)
Quoted 3 lines
Also if you set the group for the SGIs, you should set it for SPIs as well (like the kernel does). This was done in v3 of the series.
OK, I was also simplifying by removing everything and then adding stuff back until it worked :-) I can certainly add this back for completeness though.
Quoted 7 lines
What about you finish the per-CPU setup first, then bail out with:
if (
smp_processor_id()!= 0)return;and then do the distributor setup (only on the first core).
Sure, if it's necessary. I actually like not having to worry about a particular core or a particular order/number of times this enable gets called. Does it hurt to just do it each time?
Thanks,
drew
Re: [Qemu-devel] [kvm-unit-tests PATCH v4 09/11] arm/arm64: add initial gicv3 support
Hi,
Quoted 35 lines · Andrew Jones
On Wed, Nov 09, 2016 at 12:35:48PM +0000, Andre Przywara wrote:
[...]Quoted 27 lines
Quoted 12 lines
lib/arm/asm/gic-v3.h new file +6
-0@@ -0,0 +1,92 @@ +/* +* All GIC* 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. lib/arm/asm/gic-v3.h line 16
Quoted 10 lines
lib/arm/asm/gic-v3.h new file +10
-0+*/ +#ifndef _ASMARM_GIC_V3_H_ +#define _ASMARM_GIC_V3_H_ + +#ifndef _ASMARM_GIC_H_ +#error Do not directly include <asm/gic-v3.h>. Include <asm/gic.h> +#endif + +#define GICD_CTLR 0x0000 +#define GICD_TYPER 0x0004So if we share the distributor register definition with GICv2, these shouldn't be here, but in
gic.h.
But this is the right naming scheme we should use (instead ofGIC_DIST_xxx).Quoted 5 lines
Now this gets interesting with your wish to both share the definitions for the GICv2 and GICv3 distributors, but also stick to the names the kernel uses (because they differ between the two) ;-)
So now you loose the greppability for eitherGIC_DIST_CTRorGICD_TYPER, for instance.
Quoted 7 lines
Well, we just have the same offset with two names (giving us two symbols to grep). I put them here, vs.
asm/gic.h, because the kernel only uses theses symbols for gicv3. Now, nothing stops a unit test from using them with gicv2 tests, though, because unit tests includegic.h, which includes bothgic-v2.handgic-v3.h, and thus it gets both. I know, it's sounding messy... Shouldn't we post some churn to the kernel? :-)
Well, on top of that the distributor registers are slightly different (check CTLR and TYPER, for instance). So it's churn plus a stretch, I guess Marc won't like that.
So if greppability is important, should we revert to separate definitions in separate header files then, like in v3?
I don't think we actually share _code_ between the two GIC revisions, do we?
Quoted 2 lines
Note, I tried to only add defines to
asm/gic.hthat are actually shared in the kernel between v2 and v3, e.g.GIC_DIST_ENABLE_SET.
Huh? GICv3 uses GICD_ISENABLER for that register.
Quoted 2 lines
Actually,
GIC_DIST_CTRLandGIC_DIST_CTRmay be the only exceptions we have so far.
Note that it's GIC_DIST_CTLR (L and R swapped), one reason more to dump _CTR ;-)
Quoted 174 lines
Quoted 161 lines
Quoted 161 lines
lib/arm/asm/gic-v3.h new file +76
-0+#define GICD_IGROUPR 0x0080 + +#define GICD_CTLR_RWP (1U << 31) +#define GICD_CTLR_ARE_NS (1U << 4) +#define GICD_CTLR_ENABLE_G1A (1U << 1) +#define GICD_CTLR_ENABLE_G1 (1U << 0) + +#define GICR_TYPER 0x0008 +#define GICR_IGROUPR0 GICD_IGROUPR +#define GICR_TYPER_LAST (1U << 4) + + +#include <asm/arch_gicv3.h> + +#ifndef __ASSEMBLY__ +#include <asm/setup.h> +#include <asm/smp.h> +#include <asm/processor.h> +#include <asm/io.h> + +struct gicv3_data { +void *dist_base; +void *redist_base[NR_CPUS ]; +unsigned int irq_nr; +}; +extern struct gicv3_data gicv3_data; + +#define gicv3_dist_base () (gicv3_data.dist_base) +#define gicv3_redist_base () (gicv3_data.redist_base[smp_processor_id()]) +#define gicv3_sgi_base () (gicv3_data.redist_base[smp_processor_id()] + SZ_64K) + +extern int gicv3_init (void ); +extern void gicv3_enable_defaults (void ); + +static inline void gicv3_do_wait_for_rwp (void *base) +{ +int count =100000 ;/* 1s */ + +while (readl (base +GICD_CTLR ) &GICD_CTLR_RWP ) { +if (!--count) { +printf ("GICv3: RWP timeout!\n" ); +abort (); + } +cpu_relax (); +udelay (10 ); + }; +} + +static inline void gicv3_dist_wait_for_rwp (void ) +{ +gicv3_do_wait_for_rwp (gicv3_dist_base ()); +} + +static inline void gicv3_redist_wait_for_rwp (void ) +{ +gicv3_do_wait_for_rwp (gicv3_redist_base ()); +} + +static inline u32 mpidr_compress (u64 mpidr) +{ +u64 compressed = mpidr &MPIDR_HWID_BITMASK ; + + compressed = (((compressed >>32 ) &0xff ) <<24 ) | compressed; +return compressed; +} + +static inline u64 mpidr_uncompress (u32 compressed) +{ +u64 mpidr = ((u64 )compressed >>24 ) <<32 ; + + mpidr |= compressed &MPIDR_HWID_BITMASK ; +return mpidr; +} + +#endif /* !__ASSEMBLY__ */ +#endif /* _ASMARM_GIC_V3_H_ */ lib/arm/asm/gic.h +1
-0@@ -7,6 +7,7 @@#define _ASMARM_GIC_H_#include <asm/gic-v2.h> +#include <asm/gic-v3.h> #define GIC_CPU_CTRL 0x00#define GIC_CPU_PRIMASK 0x04lib/arm/gic.c +43
-0@@ -8,9 +8,11 @@#include <asm/io.h> struct gicv2_data gicv2_data; +struct gicv3_data gicv3_data;/* * Documentation/devicetree/bindings/interrupt-controller/arm,gic.txt +* Documentation/devicetree/bindings/interrupt-controller/arm,gic-v3.txt */ static bool gic_get_dt_bases (const char *compatible,void **base1,void **base2)@@ -48,10 +50,18 @@ int gicv2_init(void) &gicv2_data.dist_base, &gicv2_data.cpu_base); } +int gicv3_init (void ) +{ +return gic_get_dt_bases ("arm,gic-v3" , &gicv3_data.dist_base, + &gicv3_data.redist_base[0 ]); +} +int gic_init (void ) {if (gicv2_init ())return 2 ; +else if (gicv3_init ()) +return 3 ;return 0 ; }@@ -73,3 +83,49 @@ void gicv2_enable_defaults(void)writel (GICC_INT_PRI_THRESHOLD , cpu_base +GIC_CPU_PRIMASK );writel (GICC_ENABLE , cpu_base +GIC_CPU_CTRL ); } + +void gicv3_set_redist_base (void ) +{ +u32 aff =mpidr_compress (get_mpidr ()); +void *ptr = gicv3_data.redist_base[0 ]; +u64 typer; + +do { + typer =gicv3_read_typer (ptr +GICR_TYPER ); +if ((typer >>32 ) == aff) { +gicv3_redist_base () = ptr; +return ; + } + ptr +=SZ_64K *2 ;/* skip RD_base and SGI_base */ + }while (!(typer &GICR_TYPER_LAST )); +assert (0 ); +} + +void gicv3_enable_defaults (void ) +{ +void *dist =gicv3_dist_base (); +void *sgi_base; +unsigned int i; + + gicv3_data.irq_nr =GICD_TYPER_IRQS (readl (dist +GICD_TYPER )); +if (gicv3_data.irq_nr >1020 ) + gicv3_data.irq_nr =1020 ; + +writel (GICD_CTLR_ARE_NS |GICD_CTLR_ENABLE_G1A |GICD_CTLR_ENABLE_G1 , + dist +GICD_CTLR ); +gicv3_dist_wait_for_rwp (); + +if (!gicv3_redist_base ())Quoted 8 lines
lib/arm/gic.c void gicv2_enable_defaults(void) · line 122
Quoted 4 lines
lib/arm/gic.c +4
-0+gicv3_set_redist_base (); + sgi_base =gicv3_sgi_base (); + +writel (~0 , sgi_base +GICR_IGROUPR0 );This is mixing redist setup with distributor setup. Is it that what you meant with:
" - simplify enable by not caring if we reinit the distributor [drew]"?Yes, but, TBH, I wasn't sure I could get away with it. I tested and it worked, and I figured you'd yell at me if I was wrong :-)
Quoted 1 line
Quoted 6 lines
Quoted 2 lines
Also if you set the group for the SGIs, you should set it for SPIs as well (like the kernel does). This was done in v3 of the series.
OK, I was also simplifying by removing everything and then adding stuff back until it worked :-) I can certainly add this back for completeness though.
So you did need IGROUP0?
Actually the VGIC implements a single security state, where those registers are supposed to be RAZ/WI, if I get the spec correctly. And KVM implements them as RAO/WI, both for GICR_IGROUPR0 and GICD_IGROUPRn. But the kernel sets both of them up (because it drives real hardware), so I'd trust Marc's wisdom more here ;-)
If we don't need this GROUPR setup for proper functionality, we could move it from the generic setup into an actual test.
Quoted 10 lines
Quoted 6 lines
What about you finish the per-CPU setup first, then bail out with:
if (
smp_processor_id()!= 0)return;and then do the distributor setup (only on the first core).
Sure, if it's necessary. I actually like not having to worry about a particular core or a particular order/number of times this enable gets called. Does it hurt to just do it each time?
Shouldn't really, so we could let it stay in there until someone complains ...
Cheers,
Andre.
Re: [kvm-unit-tests PATCH v4 08/11] libcflat: add IS_ALIGNED() macro, and page sizes
In reply to Andrew JonesHi,
Quoted 3 lines · Andrew Jones
From: Peter Xu <[email protected]>
These macros will be useful to do page alignment checks.
Cheers,
Andre.
Quoted 25 lines
Signed-off-by Peter Xu <[email protected]>[drew: also added SZ_64K]Signed-off-by Andrew Jones <[email protected]>--- lib/libcflat.h | 6 ++++++ 1 file changed, 6 insertions(+)lib/libcflat.h +6
-0@@ -33,6 +33,12 @@#define __ALIGN_MASK (x, mask) (((x) + (mask)) & ~(mask))#define __ALIGN (x, a) __ALIGN_MASK(x, (typeof(x))(a) - 1)#define ALIGN (x, a) __ALIGN((x), (a)) +#define IS_ALIGNED (x, a) (((x) & ((typeof(x))(a) - 1)) == 0) + +#define SZ_4K (0x1000) +#define SZ_64K (0x10000) +#define SZ_2M (0x200000) +#define SZ_1G (0x40000000)typedef uint8_t u8 ;typedef int8_t s8 ;
Re: [kvm-unit-tests PATCH v4 08/11] libcflat: add IS_ALIGNED() macro, and page sizes
In reply to Andrew JonesQuoted 7 lines · Andrew Jones
From: Peter Xu <[email protected]>
These macros will be useful to do page alignment checks.
Signed-off-by Peter Xu <[email protected]>[drew: also added SZ_64K]Signed-off-by Andrew Jones <[email protected]>
Re: [Qemu-devel] [kvm-unit-tests PATCH v4 09/11] arm/arm64: add initial gicv3 support
In reply to Andre PrzywaraQuoted 50 lines · Andre Przywara
Hi,
Quoted 35 lines · Andrew Jones
On Wed, Nov 09, 2016 at 12:35:48PM +0000, Andre Przywara wrote:
[...]Quoted 27 lines
Quoted 12 lines
lib/arm/asm/gic-v3.h new file +6
-0@@ -0,0 +1,92 @@ +/* +* All GIC* 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. lib/arm/asm/gic-v3.h line 16
Quoted 10 lines
lib/arm/asm/gic-v3.h new file +10
-0+*/ +#ifndef _ASMARM_GIC_V3_H_ +#define _ASMARM_GIC_V3_H_ + +#ifndef _ASMARM_GIC_H_ +#error Do not directly include <asm/gic-v3.h>. Include <asm/gic.h> +#endif + +#define GICD_CTLR 0x0000 +#define GICD_TYPER 0x0004So if we share the distributor register definition with GICv2, these shouldn't be here, but in
gic.h.
But this is the right naming scheme we should use (instead ofGIC_DIST_xxx).Quoted 5 lines
Now this gets interesting with your wish to both share the definitions for the GICv2 and GICv3 distributors, but also stick to the names the kernel uses (because they differ between the two) ;-)
So now you loose the greppability for eitherGIC_DIST_CTRorGICD_TYPER, for instance.Quoted 7 lines
Well, we just have the same offset with two names (giving us two symbols to grep). I put them here, vs.
asm/gic.h, because the kernel only uses theses symbols for gicv3. Now, nothing stops a unit test from using them with gicv2 tests, though, because unit tests includegic.h, which includes bothgic-v2.handgic-v3.h, and thus it gets both. I know, it's sounding messy... Shouldn't we post some churn to the kernel? :-)Well, on top of that the distributor registers are slightly different (check CTLR and TYPER, for instance). So it's churn plus a stretch, I guess Marc won't like that.
Quoted 8 lines
So if greppability is important, should we revert to separate definitions in separate header files then, like in v3?
I don't think we actually share _code_ between the two GIC revisions, do we?Quoted 2 lines
Note, I tried to only add defines to
asm/gic.hthat are actually shared in the kernel between v2 and v3, e.g.GIC_DIST_ENABLE_SET.Huh? GICv3 uses
GICD_ISENABLERfor that register.
drivers/irqchip/irq-gic-common.c:gic_cpu_config uses it, along with GICD_INT_DEF_PRI_X4 and GIC_DIST_PRI. But I guess those are the only shared ones duplicated here so far, so I was wrong to say the two below were the only two not shared.
Quoted 6 lines
Quoted 3 lines
Actually,
GIC_DIST_CTRLandGIC_DIST_CTRmay be the only exceptions we have so far.Note that it's
GIC_DIST_CTLR(L and R swapped), one reason more to dump_CTR;-)
Yeah, I noticed that too, craziness. OK, I won't fight for the greppability argument too hard. Actually, you'll likely be the one doing the grepping when you go fix the driver :-) If you'd prefer we only use one set of defines (the better, modern ones), then for v5 that's what I'll do.
Quoted 175 lines
Quoted 175 lines
Quoted 162 lines
Quoted 162 lines
lib/arm/asm/gic-v3.h new file +76
-0+#define GICD_IGROUPR 0x0080 + +#define GICD_CTLR_RWP (1U << 31) +#define GICD_CTLR_ARE_NS (1U << 4) +#define GICD_CTLR_ENABLE_G1A (1U << 1) +#define GICD_CTLR_ENABLE_G1 (1U << 0) + +#define GICR_TYPER 0x0008 +#define GICR_IGROUPR0 GICD_IGROUPR +#define GICR_TYPER_LAST (1U << 4) + + +#include <asm/arch_gicv3.h> + +#ifndef __ASSEMBLY__ +#include <asm/setup.h> +#include <asm/smp.h> +#include <asm/processor.h> +#include <asm/io.h> + +struct gicv3_data { +void *dist_base; +void *redist_base[NR_CPUS ]; +unsigned int irq_nr; +}; +extern struct gicv3_data gicv3_data; + +#define gicv3_dist_base () (gicv3_data.dist_base) +#define gicv3_redist_base () (gicv3_data.redist_base[smp_processor_id()]) +#define gicv3_sgi_base () (gicv3_data.redist_base[smp_processor_id()] + SZ_64K) + +extern int gicv3_init (void ); +extern void gicv3_enable_defaults (void ); + +static inline void gicv3_do_wait_for_rwp (void *base) +{ +int count =100000 ;/* 1s */ + +while (readl (base +GICD_CTLR ) &GICD_CTLR_RWP ) { +if (!--count) { +printf ("GICv3: RWP timeout!\n" ); +abort (); + } +cpu_relax (); +udelay (10 ); + }; +} + +static inline void gicv3_dist_wait_for_rwp (void ) +{ +gicv3_do_wait_for_rwp (gicv3_dist_base ()); +} + +static inline void gicv3_redist_wait_for_rwp (void ) +{ +gicv3_do_wait_for_rwp (gicv3_redist_base ()); +} + +static inline u32 mpidr_compress (u64 mpidr) +{ +u64 compressed = mpidr &MPIDR_HWID_BITMASK ; + + compressed = (((compressed >>32 ) &0xff ) <<24 ) | compressed; +return compressed; +} + +static inline u64 mpidr_uncompress (u32 compressed) +{ +u64 mpidr = ((u64 )compressed >>24 ) <<32 ; + + mpidr |= compressed &MPIDR_HWID_BITMASK ; +return mpidr; +} + +#endif /* !__ASSEMBLY__ */ +#endif /* _ASMARM_GIC_V3_H_ */ lib/arm/asm/gic.h +1
-0@@ -7,6 +7,7 @@#define _ASMARM_GIC_H_#include <asm/gic-v2.h> +#include <asm/gic-v3.h> #define GIC_CPU_CTRL 0x00#define GIC_CPU_PRIMASK 0x04lib/arm/gic.c +43
-0@@ -8,9 +8,11 @@#include <asm/io.h> struct gicv2_data gicv2_data; +struct gicv3_data gicv3_data;/* * Documentation/devicetree/bindings/interrupt-controller/arm,gic.txt +* Documentation/devicetree/bindings/interrupt-controller/arm,gic-v3.txt */ static bool gic_get_dt_bases (const char *compatible,void **base1,void **base2)@@ -48,10 +50,18 @@ int gicv2_init(void) &gicv2_data.dist_base, &gicv2_data.cpu_base); } +int gicv3_init (void ) +{ +return gic_get_dt_bases ("arm,gic-v3" , &gicv3_data.dist_base, + &gicv3_data.redist_base[0 ]); +} +int gic_init (void ) {if (gicv2_init ())return 2 ; +else if (gicv3_init ()) +return 3 ;return 0 ; }@@ -73,3 +83,49 @@ void gicv2_enable_defaults(void)writel (GICC_INT_PRI_THRESHOLD , cpu_base +GIC_CPU_PRIMASK );writel (GICC_ENABLE , cpu_base +GIC_CPU_CTRL ); } + +void gicv3_set_redist_base (void ) +{ +u32 aff =mpidr_compress (get_mpidr ()); +void *ptr = gicv3_data.redist_base[0 ]; +u64 typer; + +do { + typer =gicv3_read_typer (ptr +GICR_TYPER ); +if ((typer >>32 ) == aff) { +gicv3_redist_base () = ptr; +return ; + } + ptr +=SZ_64K *2 ;/* skip RD_base and SGI_base */ + }while (!(typer &GICR_TYPER_LAST )); +assert (0 ); +} + +void gicv3_enable_defaults (void ) +{ +void *dist =gicv3_dist_base (); +void *sgi_base; +unsigned int i; + + gicv3_data.irq_nr =GICD_TYPER_IRQS (readl (dist +GICD_TYPER )); +if (gicv3_data.irq_nr >1020 ) + gicv3_data.irq_nr =1020 ; + +writel (GICD_CTLR_ARE_NS |GICD_CTLR_ENABLE_G1A |GICD_CTLR_ENABLE_G1 , + dist +GICD_CTLR ); +gicv3_dist_wait_for_rwp (); + +if (!gicv3_redist_base ())Quoted 8 lines
lib/arm/gic.c void gicv2_enable_defaults(void) · line 122
Quoted 4 lines
lib/arm/gic.c +4
-0+gicv3_set_redist_base (); + sgi_base =gicv3_sgi_base (); + +writel (~0 , sgi_base +GICR_IGROUPR0 );This is mixing redist setup with distributor setup. Is it that what you meant with:
" - simplify enable by not caring if we reinit the distributor [drew]"?Yes, but, TBH, I wasn't sure I could get away with it. I tested and it worked, and I figured you'd yell at me if I was wrong :-)
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Also if you set the group for the SGIs, you should set it for SPIs as well (like the kernel does). This was done in v3 of the series.
OK, I was also simplifying by removing everything and then adding stuff back until it worked :-) I can certainly add this back for completeness though.
So you did need IGROUP0?
At least with TCG, yes. When I removed it and quick tested on my x86 notebook the gic test hung. I didn't try to debug, I just added stuff until it worked...
Quoted 8 lines
Actually the VGIC implements a single security state, where those registers are supposed to be RAZ/WI, if I get the spec correctly. And KVM implements them as RAO/WI, both for
GICR_IGROUPR0andGICD_IGROUPRn. But the kernel sets both of them up (because it drives real hardware), so I'd trust Marc's wisdom more here ;-)
If we don't need this GROUPR setup for proper functionality, we could move it from the generic setup into an actual test.
As I need GICR_IGROUP0, I'll bring GICD_IGROUPRn back too.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
What about you finish the per-CPU setup first, then bail out with:
if (
smp_processor_id()!= 0)return;
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
and then do the distributor setup (only on the first core).
Sure, if it's necessary. I actually like not having to worry about a particular core or a particular order/number of times this enable gets called. Does it hurt to just do it each time?
Shouldn't really, so we could let it stay in there until someone complains ...
Thanks,
drew
Re: [Qemu-devel] [kvm-unit-tests PATCH v4 09/11] arm/arm64: add initial gicv3 support
Quoted 69 lines · Andrew Jones
Quoted 50 lines · Andre Przywara
Hi,
Quoted 35 lines · Andrew Jones
On Wed, Nov 09, 2016 at 12:35:48PM +0000, Andre Przywara wrote:
[...]Quoted 27 lines
Quoted 12 lines
lib/arm/asm/gic-v3.h new file +6
-0@@ -0,0 +1,92 @@ +/* +* All GIC* 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. lib/arm/asm/gic-v3.h line 16
Quoted 10 lines
lib/arm/asm/gic-v3.h new file +10
-0+*/ +#ifndef _ASMARM_GIC_V3_H_ +#define _ASMARM_GIC_V3_H_ + +#ifndef _ASMARM_GIC_H_ +#error Do not directly include <asm/gic-v3.h>. Include <asm/gic.h> +#endif + +#define GICD_CTLR 0x0000 +#define GICD_TYPER 0x0004So if we share the distributor register definition with GICv2, these shouldn't be here, but in
gic.h.
But this is the right naming scheme we should use (instead ofGIC_DIST_xxx).Quoted 5 lines
Now this gets interesting with your wish to both share the definitions for the GICv2 and GICv3 distributors, but also stick to the names the kernel uses (because they differ between the two) ;-)
So now you loose the greppability for eitherGIC_DIST_CTRorGICD_TYPER, for instance.Quoted 7 lines
Well, we just have the same offset with two names (giving us two symbols to grep). I put them here, vs.
asm/gic.h, because the kernel only uses theses symbols for gicv3. Now, nothing stops a unit test from using them with gicv2 tests, though, because unit tests includegic.h, which includes bothgic-v2.handgic-v3.h, and thus it gets both. I know, it's sounding messy... Shouldn't we post some churn to the kernel? :-)Well, on top of that the distributor registers are slightly different (check CTLR and TYPER, for instance). So it's churn plus a stretch, I guess Marc won't like that.
Quoted 8 lines
So if greppability is important, should we revert to separate definitions in separate header files then, like in v3?
I don't think we actually share _code_ between the two GIC revisions, do we?Quoted 2 lines
Note, I tried to only add defines to
asm/gic.hthat are actually shared in the kernel between v2 and v3, e.g.GIC_DIST_ENABLE_SET.Huh? GICv3 uses
GICD_ISENABLERfor that register.drivers/irqchip/irq-gic-common.c:gic_cpu_config uses it, along with
GICD_INT_DEF_PRI_X4andGIC_DIST_PRI. But I guess those are the only shared ones duplicated here so far, so I was wrong to say the two below were the only two not shared.Quoted 4 lines
Quoted 3 lines
Actually,
GIC_DIST_CTRLandGIC_DIST_CTRmay be the only exceptions we have so far.
Quoted 8 lines
Quoted 2 lines
Note that it's
GIC_DIST_CTLR(L and R swapped), one reason more to dump_CTR;-)Yeah, I noticed that too, craziness. OK, I won't fight for the greppability argument too hard. Actually, you'll likely be the one doing the grepping when you go fix the driver :-) If you'd prefer we only use one set of defines (the better, modern ones), then for v5 that's what I'll do.
I am fine with either of them (grep vs. same names), just not both at the same time ;-)
So it's your call at the end, but I lean more toward modern names. And yes, I can deal with both naming schemes when debugging ;-)
Quoted 181 lines
Quoted 181 lines
Quoted 180 lines
Quoted 161 lines
Quoted 161 lines
lib/arm/asm/gic-v3.h new file +76
-0+#define GICD_IGROUPR 0x0080 + +#define GICD_CTLR_RWP (1U << 31) +#define GICD_CTLR_ARE_NS (1U << 4) +#define GICD_CTLR_ENABLE_G1A (1U << 1) +#define GICD_CTLR_ENABLE_G1 (1U << 0) + +#define GICR_TYPER 0x0008 +#define GICR_IGROUPR0 GICD_IGROUPR +#define GICR_TYPER_LAST (1U << 4) + + +#include <asm/arch_gicv3.h> + +#ifndef __ASSEMBLY__ +#include <asm/setup.h> +#include <asm/smp.h> +#include <asm/processor.h> +#include <asm/io.h> + +struct gicv3_data { +void *dist_base; +void *redist_base[NR_CPUS ]; +unsigned int irq_nr; +}; +extern struct gicv3_data gicv3_data; + +#define gicv3_dist_base () (gicv3_data.dist_base) +#define gicv3_redist_base () (gicv3_data.redist_base[smp_processor_id()]) +#define gicv3_sgi_base () (gicv3_data.redist_base[smp_processor_id()] + SZ_64K) + +extern int gicv3_init (void ); +extern void gicv3_enable_defaults (void ); + +static inline void gicv3_do_wait_for_rwp (void *base) +{ +int count =100000 ;/* 1s */ + +while (readl (base +GICD_CTLR ) &GICD_CTLR_RWP ) { +if (!--count) { +printf ("GICv3: RWP timeout!\n" ); +abort (); + } +cpu_relax (); +udelay (10 ); + }; +} + +static inline void gicv3_dist_wait_for_rwp (void ) +{ +gicv3_do_wait_for_rwp (gicv3_dist_base ()); +} + +static inline void gicv3_redist_wait_for_rwp (void ) +{ +gicv3_do_wait_for_rwp (gicv3_redist_base ()); +} + +static inline u32 mpidr_compress (u64 mpidr) +{ +u64 compressed = mpidr &MPIDR_HWID_BITMASK ; + + compressed = (((compressed >>32 ) &0xff ) <<24 ) | compressed; +return compressed; +} + +static inline u64 mpidr_uncompress (u32 compressed) +{ +u64 mpidr = ((u64 )compressed >>24 ) <<32 ; + + mpidr |= compressed &MPIDR_HWID_BITMASK ; +return mpidr; +} + +#endif /* !__ASSEMBLY__ */ +#endif /* _ASMARM_GIC_V3_H_ */ lib/arm/asm/gic.h +1
-0@@ -7,6 +7,7 @@#define _ASMARM_GIC_H_#include <asm/gic-v2.h> +#include <asm/gic-v3.h> #define GIC_CPU_CTRL 0x00#define GIC_CPU_PRIMASK 0x04lib/arm/gic.c +43
-0@@ -8,9 +8,11 @@#include <asm/io.h> struct gicv2_data gicv2_data; +struct gicv3_data gicv3_data;/* * Documentation/devicetree/bindings/interrupt-controller/arm,gic.txt +* Documentation/devicetree/bindings/interrupt-controller/arm,gic-v3.txt */ static bool gic_get_dt_bases (const char *compatible,void **base1,void **base2)@@ -48,10 +50,18 @@ int gicv2_init(void) &gicv2_data.dist_base, &gicv2_data.cpu_base); } +int gicv3_init (void ) +{ +return gic_get_dt_bases ("arm,gic-v3" , &gicv3_data.dist_base, + &gicv3_data.redist_base[0 ]); +} +int gic_init (void ) {if (gicv2_init ())return 2 ; +else if (gicv3_init ()) +return 3 ;return 0 ; }@@ -73,3 +83,49 @@ void gicv2_enable_defaults(void)writel (GICC_INT_PRI_THRESHOLD , cpu_base +GIC_CPU_PRIMASK );writel (GICC_ENABLE , cpu_base +GIC_CPU_CTRL ); } + +void gicv3_set_redist_base (void ) +{ +u32 aff =mpidr_compress (get_mpidr ()); +void *ptr = gicv3_data.redist_base[0 ]; +u64 typer; + +do { + typer =gicv3_read_typer (ptr +GICR_TYPER ); +if ((typer >>32 ) == aff) { +gicv3_redist_base () = ptr; +return ; + } + ptr +=SZ_64K *2 ;/* skip RD_base and SGI_base */ + }while (!(typer &GICR_TYPER_LAST )); +assert (0 ); +} + +void gicv3_enable_defaults (void ) +{ +void *dist =gicv3_dist_base (); +void *sgi_base; +unsigned int i; + + gicv3_data.irq_nr =GICD_TYPER_IRQS (readl (dist +GICD_TYPER )); +if (gicv3_data.irq_nr >1020 ) + gicv3_data.irq_nr =1020 ; + +writel (GICD_CTLR_ARE_NS |GICD_CTLR_ENABLE_G1A |GICD_CTLR_ENABLE_G1 , + dist +GICD_CTLR ); +gicv3_dist_wait_for_rwp (); + +if (!gicv3_redist_base ())Quoted 8 lines
lib/arm/gic.c void gicv2_enable_defaults(void) · line 122
Quoted 4 lines
lib/arm/gic.c +4
-0+gicv3_set_redist_base (); + sgi_base =gicv3_sgi_base (); + +writel (~0 , sgi_base +GICR_IGROUPR0 );This is mixing redist setup with distributor setup. Is it that what you meant with:
" - simplify enable by not caring if we reinit the distributor [drew]"?Yes, but, TBH, I wasn't sure I could get away with it. I tested and it worked, and I figured you'd yell at me if I was wrong :-)
Quoted 3 lines
Also if you set the group for the SGIs, you should set it for SPIs as well (like the kernel does). This was done in v3 of the series.
OK, I was also simplifying by removing everything and then adding stuff back until it worked :-) I can certainly add this back for completeness though.
Quoted 5 lines
Quoted 1 line
So you did need IGROUP0?
At least with TCG, yes. When I removed it and quick tested on my x86 notebook the gic test hung. I didn't try to debug, I just added stuff until it worked...
Ah, TCG might be different, because it also aims at emulating EL2 & 3, AFAIK. So the implementation in there is probably including the secure side as well (haven't checked, though).
Thanks!
Andre.
Quoted 28 lines
Quoted 7 lines
Actually the VGIC implements a single security state, where those registers are supposed to be RAZ/WI, if I get the spec correctly. And KVM implements them as RAO/WI, both for
GICR_IGROUPR0andGICD_IGROUPRn. But the kernel sets both of them up (because it drives real hardware), so I'd trust Marc's wisdom more here ;-)
If we don't need this GROUPR setup for proper functionality, we could move it from the generic setup into an actual test.As I need
GICR_IGROUP0, I'll bringGICD_IGROUPRnback too.Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
What about you finish the per-CPU setup first, then bail out with:
if (
smp_processor_id()!= 0)return;Quoted 8 lines
Quoted 5 lines
Quoted 1 line
and then do the distributor setup (only on the first core).
Sure, if it's necessary. I actually like not having to worry about a particular core or a particular order/number of times this enable gets called. Does it hurt to just do it each time?
Shouldn't really, so we could let it stay in there until someone complains ...
Thanks,
drew