GICv3 emulation
cover GICv3 emulation
This series implements emulation of the GICv3 interrupt controller. It is based to some extent on previous patches from Shlomo and Pavel, but the bulk of it has turned out to be new code. (The combination of changing the underlying data structures, adding support for TrustZone and implementing proper GICv3 behaviour rather than borrowing fragments of GICv2 emulation code meant there wasn't much left to reuse.) I've tried to reflect this in the various authorship credits on the patches, but please let me know if you feel I got anything miscredited one way or the other.
Key points about the GICv3 emulated here:
* "non-legacy" only, ie system registers and affinity routing
* TrustZone is implemented
* no virtualization support
* only the "core" GICv3, so no LPI support (via ITS or otherwise)
I have included the "support KVM save/restore" patches from Pavel, reworked to use the new data structures, but they are only RFC status because the kernel API is not yet final (there are a couple of loose threads there to be followed up). Those patches are at the end of the series; I think everything else is in a commitable state (give or take code review).
Testing: I have confirmed that we can boot a Linux guest kernel, but not tried any other GIC-using guest code. I've done some light stress-testing using 'stress', and checked an SMP (2-cpu) boot.
Design: all the code here is in hw/intc/, split into several files to avoid them being huge. The interface between the CPU proper and the CPU interface is a bit ad-hoc (you can see the awkward seams that result from the choice to think of the cpu i/f as part of the GIC device rather than part of the CPU itself), but I think that if you put the cpu i/f in the CPU you'd end up with an ad-hoc interface and awkward seams in the other direction. The GICv3 device currently assumes it is always connected to all CPUs; we can change that later to allow some kind of QOM link property to specify the CPUs explicitly, but I think this is OK for now (and it's already a pretty huge set of code changes to have to review).
I include a workaround for a Linux kernel bug which otherwise prevents booting on the virt board. I've reported the bug to Marc Zyngier and he should post a kernel patch to fix it shortly, but I think we'll need to retain the workaround for the benefit of older kernels (an ugly but pragmatic choice).
Code review, testing, attempts to run guests other than Linux welcome (UEFI, anybody?)
thanks
-- PMM
Pavel Fedin (5):
target-arm: Add mp-affinity property for ARM CPU class hw/intc/arm_gicv3: Add state information hw/intc/arm_gicv3: Add vmstate descriptors
NOT-FOR-UPSTREAM: kernel: Add definitions for GICv3 attributes
RFC: hw/intc/arm_gicv3_kvm: Implement get/put functions
Peter Maydell (15):
migration: Define VMSTATE_UINT64_2DARRAY
bitops.h: Implement half-shuffle and half-unshuffle ops
target-arm: Define new arm_is_el3_or_mon() function
target-arm: Provide hook to tell GICv3 about changes of security state hw/intc/arm_gicv3: Move irq lines into GICv3CPUState structure hw/intc/arm_gicv3: Implement functions to identify next pending irq hw/intc/arm_gicv3: Wire up distributor and redistributor MMIO regions hw/intc/arm_gicv3: Implement gicv3_set_irq() hw/intc/arm_gicv3: Implement GICv3 CPU interface registers hw/intc/arm_gicv3: Implement gicv3_cpuif_update() hw/intc/arm_gicv3: Implement CPU i/f SGI generation registers hw/intc/arm_gicv3: Add IRQ handling CPU interface registers target-arm/machine.c: Allow user to request GICv3 emulation target-arm/monitor.c: Advertise emulated GICv3 in capabilities hw/intc/arm_gicv3: Work around Linux assuming interrupts are group 1
Shlomo Pongratz (3):
hw/intc/arm_gicv3: ARM GICv3 device framework hw/intc/arm_gicv3: Implement GICv3 distributor registers hw/intc/arm_gicv3: Implement GICv3 redistributor registers
hw/intc/Makefile.objs | 4 + hw/intc/arm_gicv3.c | 397 +++++++++++ hw/intc/arm_gicv3_common.c | 213 +++++- hw/intc/arm_gicv3_cpuif.c | 1345 ++++++++++++++++++++++++++++++++++++ hw/intc/arm_gicv3_dist.c | 862 +++++++++++++++++++++++ hw/intc/arm_gicv3_kvm.c | 447 +++++++++++- hw/intc/arm_gicv3_redist.c | 556 +++++++++++++++ hw/intc/gicv3_internal.h | 331 +++++++++ include/hw/intc/arm_gicv3.h | 32 + include/hw/intc/arm_gicv3_common.h | 212 +++++- include/migration/vmstate.h | 6 + include/qemu/bitops.h | 108 +++ linux-headers/asm-arm64/kvm.h | 17 +- target-arm/cpu-qom.h | 40 +- target-arm/cpu.c | 10 + target-arm/cpu.h | 13 +- target-arm/helper.c | 2 + target-arm/internals.h | 8 + target-arm/machine.c | 3 +- target-arm/monitor.c | 3 +- target-arm/op_helper.c | 4 + tests/test-bitops.c | 68 ++ trace-events | 41 ++ 23 files changed, 4692 insertions(+), 30 deletions(-) create mode 100644 hw/intc/arm_gicv3.c create mode 100644 hw/intc/arm_gicv3_cpuif.c create mode 100644 hw/intc/arm_gicv3_dist.c create mode 100644 hw/intc/arm_gicv3_redist.c create mode 100644 hw/intc/gicv3_internal.h create mode 100644 include/hw/intc/arm_gicv3.h
Signature · 1 line
1.9.1
PATCH 1/23 migration: Define VMSTATE_UINT64_2DARRAY
Define a VMSTATE_UINT64_2DARRAY macro, to go with the ones we already have for other type sizes.
--- include/migration/vmstate.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/migration/vmstate.h +6 -0
@@ -846,6 +846,12 @@ extern const VMStateInfo vmstate_info_bitmap;#define VMSTATE_UINT64_ARRAY (_f, _s, _n) \ VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0) +#define VMSTATE_UINT64_2DARRAY (_f, _s, _n1, _n2) \ + VMSTATE_UINT64_2DARRAY_V(_f, _s, _n1, _n2, 0) + +#define VMSTATE_UINT64_2DARRAY_V (_f, _s, _n1, _n2, _v) \ + VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint64, uint64_t) +#define VMSTATE_INT16_ARRAY_V (_f, _s, _n, _v) \ VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int16, int16_t)
Signature · 1 line
1.9.1
PATCH 2/23 bitops.h: Implement half-shuffle and half-unshuffle ops
In reply to Peter MaydellA half-shuffle operation takes a word with zeros in the high half:
0000 0000 0000 0000 ABCD EFGH IJKL MNOP
and spreads the bits out so they are in every other bit of the word:
0A0B 0C0D 0E0F 0G0H 0I0J 0K0L 0M0N 0O0P
A half-unshuffle performs the reverse operation.
Provide functions in bitops.h which implement these operations for 32-bit and 64-bit inputs, and add tests for them.
--- include/qemu/bitops.h | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/test-bitops.c | 68 +++++++++++++++++++++++++++++++ 2 files changed, 176 insertions(+)
include/qemu/bitops.h +108 -0
@@ -428,4 +428,112 @@ static inline uint64_t deposit64(uint64_t value, int start, int length, return (value & ~mask) | ((fieldval << start) & mask); } +/** +* half_shuffle32: +* @value: 32-bit value (of which only the bottom 16 bits are of interest) +* +* Given an input value: +* xxxx xxxx xxxx xxxx ABCD EFGH IJKL MNOP +* return the value where the bottom 16 bits are spread out into +* the odd bits in the word, and the even bits are zeroed: +* 0A0B 0C0D 0E0F 0G0H 0I0J 0K0L 0M0N 0O0P +* +* Any bits set in the top half of the input are ignored. +* +* Returns: the shuffled bits. +*/ +static inline uint32_t half_shuffle32 (uint32_t x) +{ +/* This algorithm is from _Hacker's Delight_ section 7-2 "Shuffling Bits". +* It ignores any bits set in the top half of the input. +*/ + x = ((x &0xFF00 ) <<8 ) | (x &0x00FF ); + x = ((x <<4 ) | x) &0x0F0F0F0F ; + x = ((x <<2 ) | x) &0x33333333 ; + x = ((x <<1 ) | x) &0x55555555 ; +return x; +} + +/** +* half_shuffle64: +* @value: 64-bit value (of which only the bottom 32 bits are of interest) +* +* Given an input value: +* xxxx xxxx xxxx .... xxxx xxxx ABCD EFGH IJKL MNOP QRST UVWX YZab cdef +* return the value where the bottom 32 bits are spread out into +* the odd bits in the word, and the even bits are zeroed: +* 0A0B 0C0D 0E0F 0G0H 0I0J 0K0L 0M0N .... 0U0V 0W0X 0Y0Z 0a0b 0c0d 0e0f +* +* Any bits set in the top half of the input are ignored. +* +* Returns: the shuffled bits. +*/ +static inline uint64_t half_shuffle64 (uint64_t x) +{ +/* This algorithm is from _Hacker's Delight_ section 7-2 "Shuffling Bits". +* It ignores any bits set in the top half of the input. +*/ + x = ((x &0xFFFF0000ULL ) <<16 ) | (x &0xFFFF ); + x = ((x <<8 ) | x) &0x00FF00FF00FF00FFULL ; + x = ((x <<4 ) | x) &0x0F0F0F0F0F0F0F0FULL ; + x = ((x <<2 ) | x) &0x3333333333333333ULL ; + x = ((x <<1 ) | x) &0x5555555555555555ULL ; +return x; +} + +/** +* half_unshuffle32: +* @value: 32-bit value (of which only the odd bits are of interest) +* +* Given an input value: +* xAxB xCxD xExF xGxH xIxJ xKxL xMxN xOxP +* return the value where all the odd bits are compressed down +* into the low half of the word, and the high half is zeroed: +* 0000 0000 0000 0000 ABCD EFGH IJKL MNOP +* +* Any even bits set in the input are ignored. +* +* Returns: the unshuffled bits. +*/ +static inline uint32_t half_unshuffle32 (uint32_t x) +{ +/* This algorithm is from _Hacker's Delight_ section 7-2 "Shuffling Bits". +* where it is called an inverse half shuffle. +*/ + x &=0x55555555 ; + x = ((x >>1 ) | x) &0x33333333 ; + x = ((x >>2 ) | x) &0x0F0F0F0F ; + x = ((x >>4 ) | x) &0x00FF00FF ; + x = ((x >>8 ) | x) &0x0000FFFF ; +return x; +} + +/** +* half_unshuffle64: +* @value: 64-bit value (of which only the odd bits are of interest) +* +* Given an input value: +* xAxB xCxD xExF xGxH xIxJ xKxL xMxN .... xUxV xWxX xYxZ xaxb xcxd xexf +* return the value where all the odd bits are compressed down +* into the low half of the word, and the high half is zeroed: +* 0000 0000 0000 .... 0000 0000 ABCD EFGH IJKL MNOP QRST UVWX YZab cdef +* +* Any even bits set in the input are ignored. +* +* Returns: the unshuffled bits. +*/ +static inline uint64_t half_unshuffle64 (uint64_t x) +{ +/* This algorithm is from _Hacker's Delight_ section 7-2 "Shuffling Bits". +* where it is called an inverse half shuffle. +*/ + x &=0x5555555555555555ULL ; + x = ((x >>1 ) | x) &0x3333333333333333ULL ; + x = ((x >>2 ) | x) &0x0F0F0F0F0F0F0F0FULL ; + x = ((x >>4 ) | x) &0x00FF00FF00FF00FFULL ; + x = ((x >>8 ) | x) &0x0000FFFF0000FFFFULL ; + x = ((x >>16 ) | x) &0x00000000FFFFFFFFULL ; +return x; +} +#endif
tests/test-bitops.c +68 -0
78 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH 3/23 target-arm: Define new arm_is_el3_or_mon() function
In reply to Peter MaydellThe GICv3 system registers need to know if the CPU is AArch64 in EL3 or AArch32 in Monitor mode. This happens to be the first part of the check for arm_is_secure(), so factor it out into a new arm_is_el3_or_mon() function that the GIC can also use.
--- target-arm/cpu.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
target-arm/cpu.h +11 -2
@@ -960,8 +960,8 @@ static inline bool arm_is_secure_below_el3(CPUARMState *env) } } -/* Return true if the processor is in secure state */ -static inline bool arm_is_secure (CPUARMState *env) +/* Return true if the CPU is AArch64 EL3 or AArch32 Mon */ +static bool arm_is_el3_or_mon (CPUARMState *env) {if (arm_feature (env,ARM_FEATURE_EL3 )) {if (is_a64 (env) &&extract32 (env->pstate,2 ,2 ) ==3 ) {
@@ -973,6 +973,15 @@ static inline bool arm_is_secure(CPUARMState *env)return true; } } +return false; +} + +/* Return true if the processor is in secure state */ +static inline bool arm_is_secure (CPUARMState *env) +{ +if (arm_is_el3_or_mon (env)) { +return true; + }return arm_is_secure_below_el3 (env); }
Signature · 1 line
1.9.1
Re: [Qemu-arm] [PATCH 03/23] target-arm: Define new arm_is_el3_or_mon() function
Quoted 15 lines · Peter Maydell
The GICv3 system registers need to know if the CPU is AArch64 in EL3 or AArch32 in Monitor mode. This happens to be the first part of the check for
arm_is_secure(), so factor it out into a newarm_is_el3_or_mon()function that the GIC can also use.Signed-off-by Peter Maydell <[email protected]>--- target-arm/cpu.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)target-arm/cpu.h +0
-0
target-arm/cpu.h static inline bool arm_is_secure_below_el3(CPUARMState *env) · line 964
Quoted 7 lines
target-arm/cpu.h +2
-2@@ -960,8 +960,8 @@ static inline bool arm_is_secure_below_el3(CPUARMState *env) } } -/* Return true if the processor is in secure state */ -static inline bool arm_is_secure (CPUARMState *env) +/* Return true if the CPU is AArch64 EL3 or AArch32 Mon */ +static bool arm_is_el3_or_mon (CPUARMState *env)
inline?
Quoted 10 lines
target-arm/cpu.h +2
-0{if (arm_feature (env,ARM_FEATURE_EL3 )) {if (is_a64 (env) &&extract32 (env->pstate,2 ,2 ) ==3 ) {@@ -973,6 +973,15 @@ static inline bool arm_is_secure(CPUARMState *env)return true; } } +return false; +}
target-arm/cpu.h static inline bool arm_is_secure(CPUARMState *env) · line 987
Quoted 10 lines
target-arm/cpu.h +7
-0+ +/* Return true if the processor is in secure state */ +static inline bool arm_is_secure (CPUARMState *env) +{ +if (arm_is_el3_or_mon (env)) { +return true; + }return arm_is_secure_below_el3 (env); }
Thanks,
Signature · 1 line
Shannon
PATCH 4/23 target-arm: Provide hook to tell GICv3 about changes of security state
In reply to Peter MaydellThe GICv3 CPU interface needs to know when the CPU it is attached to makes an exception level or mode transition that changes the security state, because whether it is asserting IRQ or FIQ can change depending on these things. Provide a mechanism for letting the GICv3 device register a hook to be called on such changes.
--- target-arm/cpu-qom.h | 40 ++++++++++++++++++++++++++++++++++++++-- target-arm/cpu.c | 9 +++++++++ target-arm/helper.c | 2 ++ target-arm/internals.h | 8 ++++++++ target-arm/op_helper.c | 4 ++++ 5 files changed, 61 insertions(+), 2 deletions(-)
target-arm/cpu-qom.h +38 -2
@@ -47,13 +47,22 @@ typedef struct ARMCPUClass {void (*parent_reset)(CPUState *cpu); } ARMCPUClass; +typedef struct ARMCPU ARMCPU ; + +/** +* ARMELChangeHook: +* type of a function which can be registered via arm_register_el_change_hook() +* to get callbacks when the CPU changes its exception level or mode. +*/ +typedef void ARMELChangeHook (ARMCPU *cpu,void *opaque); +/** * ARMCPU: * @env: #CPUARMState * * An ARM CPU core. */ -typedef struct ARMCPU { +struct ARMCPU {/*< private >*/ CPUState parent_obj;/*< public >*/
@@ -185,7 +194,10 @@ typedef struct ARMCPU {/* DCZ blocksize, in log_2(words), ie low 4 bits of DCZID_EL0 */ uint32_t dcz_blocksize;uint64_t rvbar; -}ARMCPU ; + +ARMELChangeHook *el_change_hook; +void *el_change_hook_opaque; +};#define TYPE_AARCH64_CPU "aarch64-cpu"#define AARCH64_CPU_CLASS (klass) \
@@ -257,4 +269,28 @@ int aarch64_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg);int aarch64_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg);#endif +/** +* arm_register_el_change_hook: +* Register a hook function which will be called back whenever this +* CPU changes exception level or mode. The hook function will be +* passed a pointer to the ARMCPU and the opaque data pointer passed +* to this function when the hook was registered. +* +* Note that we currently only support registering a single hook function, +* and will assert if this function is called twice. +* This facility is intended for the use of the GICv3 emulation. +*/ +void arm_register_el_change_hook (ARMCPU *cpu,ARMELChangeHook *hook, +void *opaque); + +/** +* arm_get_el_change_hook_opaque: +* Return the opaque data that will be used by the el_change_hook +* for this CPU. +*/ +static inline void *arm_get_el_change_hook_opaque (ARMCPU *cpu) +{ +return cpu->el_change_hook_opaque; +} +#endif
target-arm/cpu.c +9 -0
@@ -50,6 +50,15 @@ static bool arm_cpu_has_work(CPUState *cs) | CPU_INTERRUPT_EXITTB); } +void arm_register_el_change_hook (ARMCPU *cpu,ARMELChangeHook *hook, +void *opaque) +{ +/* We currently only support registering a single hook function */ +assert (!cpu->el_change_hook); + cpu->el_change_hook = hook; + cpu->el_change_hook_opaque = opaque; +} +static void cp_reg_reset (gpointer key,gpointer value,gpointer opaque) {/* Reset a single ARMCPRegInfo register */
target-arm/helper.c +2 -0
@@ -6476,6 +6476,8 @@ void arm_cpu_do_interrupt(CPUState *cs)arm_cpu_do_interrupt_aarch32 (cs); } +arm_call_el_change_hook (cpu); +if (!kvm_enabled ()) { cs->interrupt_request |=CPU_INTERRUPT_EXITTB ; }
target-arm/internals.h +8 -0
@@ -476,4 +476,12 @@ bool arm_s1_regime_using_lpae_format(CPUARMState *env, ARMMMUIdx mmu_idx);void arm_cpu_do_unaligned_access (CPUState *cs,vaddr vaddr,int is_write,int is_user,uintptr_t retaddr); +/* Call the EL change hook if one has been registered */ +static inline void arm_call_el_change_hook (ARMCPU *cpu) +{ +if (cpu->el_change_hook) { + cpu->el_change_hook (cpu, cpu->el_change_hook_opaque); + } +} +#endif
target-arm/op_helper.c +4 -0
@@ -434,6 +434,8 @@ void HELPER(cpsr_write)(CPUARMState *env, uint32_t val, uint32_t mask)void HELPER (cpsr_write_eret )(CPUARMState *env,uint32_t val) {cpsr_write (env, val,CPSR_ERET_MASK , CPSRWriteExceptionReturn); + +arm_call_el_change_hook (arm_env_get_cpu (env)); }/* Access to user mode registers from privileged modes. */
@@ -929,6 +931,8 @@ void HELPER(exception_return)(CPUARMState *env) env->pc = env->elr_el[cur_el]; } +arm_call_el_change_hook (arm_env_get_cpu (env)); +return ; illegal_return:
Signature · 1 line
1.9.1
PATCH 5/23 target-arm: Add mp-affinity property for ARM CPU class
In reply to Peter MaydellFrom: Pavel Fedin <[email protected]>
This allows to override default affinity IDs on a per-machine basis, and possibility to retrieve IDs will be used by vGICv3 live migration code.
--- target-arm/cpu.c | 1 + 1 file changed, 1 insertion(+)
target-arm/cpu.c +1 -0
@@ -1414,6 +1414,7 @@ static Property arm_cpu_properties[] = {DEFINE_PROP_BOOL ("start-powered-off" ,ARMCPU , start_powered_off, false),DEFINE_PROP_UINT32 ("psci-conduit" ,ARMCPU , psci_conduit,0 ),DEFINE_PROP_UINT32 ("midr" ,ARMCPU , midr,0 ), +DEFINE_PROP_UINT64 ("mp-affinity" ,ARMCPU , mp_affinity,0 ), DEFINE_PROP_END_OF_LIST() };
Signature · 1 line
1.9.1
PATCH 6/23 hw/intc/arm_gicv3: Add state information
In reply to Peter MaydellFrom: Pavel Fedin <[email protected]>
Add state information to GICv3 object structure and implement arm_gicv3_common_reset().
This commit includes accessor functions for the fields which are stored as bitmaps in uint32_t arrays.
[PMM: significantly overhauled:
* Add missing qom/cpu.h include
* Remove legacy-only state fields (we can add them later if/when we add legacy emulation)
* Use arrays of uint32_t to store the various distributor bitmaps, and provide accessor functions for the various set/test/etc operations
* Add various missing register offset #defines
* Accessor macros which combine distributor and redistributor behaviour removed
* Fields in state structures renamed to match architectural register names
* Corrected the reset value for GICR_IENABLER0 since we don't support legacy mode
* Added ARM_LINUX_BOOT_IF interface for "we are directly booting a kernel in non-secure" so that we can fake up the firmware-mandated reconfiguration only when we need it
]
--- hw/intc/arm_gicv3_common.c | 140 ++++++++++++++++++++++++++- hw/intc/gicv3_internal.h | 172 +++++++++++++++++++++++++++++++++ include/hw/intc/arm_gicv3_common.h | 189 ++++++++++++++++++++++++++++++++++++- 3 files changed, 496 insertions(+), 5 deletions(-) create mode 100644 hw/intc/gicv3_internal.h
hw/intc/arm_gicv3_common.c +138 -2
@@ -3,8 +3,9 @@* * Copyright (c) 2012 Linaro Limited * Copyright (c) 2015 Huawei. +* Copyright (c) 2015 Samsung Electronics Co., Ltd. * Written by Peter Maydell -* Extended to 64 cores by Shlomo Pongratz +* Reworked for GICv3 by Shlomo Pongratz and Pavel Fedin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -22,7 +23,10 @@#include "qemu/osdep.h" #include "qapi/error.h" +#include "qom/cpu.h" #include "hw/intc/arm_gicv3_common.h" +#include "gicv3_internal.h" +#include "hw/arm/linux-boot-if.h" static void gicv3_pre_save (void *opaque) {
@@ -90,6 +94,7 @@ void gicv3_init_irqs_and_mmio(GICv3State *s, qemu_irq_handler handler,static void arm_gicv3_common_realize (DeviceState *dev,Error **errp) {GICv3State *s =ARM_GICV3_COMMON (dev); +int i;/* revision property is actually reserved and currently used only in order * to keep the interface compatible with GICv2 code, avoiding extra
@@ -100,11 +105,136 @@ static void arm_gicv3_common_realize(DeviceState *dev, Error **errp)error_setg (errp,"unsupported GIC revision %d" , s->revision);return ; } + +if (s->num_irq >GICV3_MAXIRQ ) { +error_setg (errp, +"requested %u interrupt lines exceeds GIC maximum %d" , + s->num_irq,GICV3_MAXIRQ ); +return ; + } + + s->cpu =g_new0 (GICv3CPUState, s->num_cpu); + +for (i =0 ; i < s->num_cpu; i++) { +CPUState *cpu =qemu_get_cpu (i); +uint64_t cpu_affid; +int last; + + s->cpu[i].cpu = cpu; + s->cpu[i].gic = s; + +/* Pre-construct the GICR_TYPER: +* For our implementation: +* Top 32 bits are the affinity value of the associated CPU +* CommonLPIAff == 01 (redistributors with same Aff3 share LPI table) +* Processor_Number == CPU index starting from 0 +* DPGS == 0 (GICR_CTLR.DPG* not supported) +* Last == 1 if this is the last redistributor in a series of +* contiguous redistributor pages +* DirectLPI == 0 (direct injection of LPIs not supported) +* VLPIS == 0 (virtual LPIs not supported) +* PLPIS == 0 (physical LPIs not supported) +*/ + cpu_affid =object_property_get_int (OBJECT (cpu),"mp-affinity" ,NULL ); + last = (i == s->num_cpu -1 ); + +/* The CPU mp-affinity property is in MPIDR register format; squash +* the affinity bytes into 32 bits as the GICR_TYPER has them. +*/ + cpu_affid = (cpu_affid &0xFF00000000ULL >>8 ) | (cpu_affid &0xFFFFFF ); + s->cpu[i].gicr_typer = (cpu_affid <<32 ) | + (1 <<24 ) | + (i <<8 ) | + (last <<4 ); + } }static void arm_gicv3_common_reset (DeviceState *dev) { -/* TODO */ +GICv3State *s =ARM_GICV3_COMMON (dev); +int i; + +for (i =0 ; i < s->num_cpu; i++) { +GICv3CPUState *cs = &s->cpu[i]; + + cs->level =0 ; + cs->gicr_ctlr =0 ; + cs->gicr_statusr[GICV3_S ] =0 ; + cs->gicr_statusr[GICV3_NS ] =0 ; + cs->gicr_waker = GICR_WAKER_ProcessorSleep | GICR_WAKER_ChildrenAsleep; + cs->gicr_propbaser =0 ; + cs->gicr_pendbaser =0 ; +/* If we're resetting a TZ-aware GIC as if secure firmware +* had set it up ready to start a kernel in non-secure, we +* need to set interrupts to group 1 so the kernel can use them. +* Otherwise they reset to group 0 like the hardware. +*/ +if (s->irq_reset_nonsecure) { + cs->gicr_igroupr0 =0xffffffff ; + }else { + cs->gicr_igroupr0 =0 ; + } + + cs->gicr_ienabler0 =0 ; + cs->gicr_ipendr0 =0 ; + cs->gicr_iactiver0 =0 ; + cs->edge_trigger =0xffff ; + cs->gicr_igrpmodr0 =0 ; + cs->gicr_nsacr =0 ; +memset (cs->gicr_ipriorityr,0 ,sizeof (cs->gicr_ipriorityr)); + +/* State in the CPU interface must *not* be reset here, because it +* is part of the CPU's reset domain, not the GIC device's. +*/ + } + +/* For our implementation affinity routing is always enabled */ +if (s->security_extn) { + s->gicd_ctlr =GICD_CTLR_ARE_S |GICD_CTLR_ARE_NS ; + }else { + s->gicd_ctlr =GICD_CTLR_DS |GICD_CTLR_ARE ; + } + + s->gicd_statusr[GICV3_S ] =0 ; + s->gicd_statusr[GICV3_NS ] =0 ; + +memset (s->group,0 ,sizeof (s->group)); +memset (s->grpmod,0 ,sizeof (s->grpmod)); +memset (s->enabled,0 ,sizeof (s->enabled)); +memset (s->pending,0 ,sizeof (s->pending)); +memset (s->active,0 ,sizeof (s->active)); +memset (s->level,0 ,sizeof (s->level)); +memset (s->edge_trigger,0 ,sizeof (s->edge_trigger)); +memset (s->gicd_ipriority,0 ,sizeof (s->gicd_ipriority)); +memset (s->gicd_irouter,0 ,sizeof (s->gicd_irouter)); + +if (s->irq_reset_nonsecure) { +/* If we're resetting a TZ-aware GIC as if secure firmware +* had set it up ready to start a kernel in non-secure, we +* need to set interrupts to group 1 so the kernel can use them. +* Otherwise they reset to group 0 like the hardware. +*/ +for (i =GIC_INTERNAL ; i < s->num_irq; i++) { +gicv3_gicd_group_set (s, i); + } + } +} + +static void arm_gic_common_linux_init (ARMLinuxBootIf *obj, +bool secure_boot) +{ +GICv3State *s =ARM_GICV3_COMMON (obj); + +if (s->security_extn && !secure_boot) { +/* We're directly booting a kernel into NonSecure. If this GIC +* implements the security extensions then we must configure it +* to have all the interrupts be NonSecure (this is a job that +* is done by the Secure boot firmware in real hardware, and in +* this mode QEMU is acting as a minimalist firmware-and-bootloader +* equivalent). +*/ + s->irq_reset_nonsecure = true; + } }static Property arm_gicv3_common_properties[] = {
@@ -118,11 +248,13 @@ static Property arm_gicv3_common_properties[] = {static void arm_gicv3_common_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); +ARMLinuxBootIfClass *albifc =ARM_LINUX_BOOT_IF_CLASS (klass); dc->reset = arm_gicv3_common_reset; dc->realize = arm_gicv3_common_realize; dc->props = arm_gicv3_common_properties; dc->vmsd = &vmstate_gicv3; + albifc->arm_linux_init = arm_gic_common_linux_init; }static const TypeInfo arm_gicv3_common_type = {
@@ -132,6 +264,10 @@ static const TypeInfo arm_gicv3_common_type = { .class_size = sizeof(ARMGICv3CommonClass), .class_init = arm_gicv3_common_class_init, .abstract = true, + .interfaces = (InterfaceInfo []) { + {TYPE_ARM_LINUX_BOOT_IF }, + { }, + }, };static void register_types (void )
hw/intc/gicv3_internal.h new file +172 -0
172 lines not on this page · raw message
include/hw/intc/arm_gicv3_common.h +186 -3
210 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 06/23] hw/intc/arm_gicv3: Add state information
Quoted 69 lines · Peter Maydell
From: Pavel Fedin <[email protected]>
Add state information to GICv3 object structure and implement
arm_gicv3_common_reset().This commit includes accessor functions for the fields which are stored as bitmaps in
uint32_tarrays.Signed-off-by Pavel Fedin <[email protected]>[PMM: significantly overhauled:
* Add missingqom/cpu.hinclude
* Remove legacy-only state fields (we can add them later if/when we add legacy emulation)
* Use arrays ofuint32_tto store the various distributor bitmaps, and provide accessor functions for the various set/test/etc operations
* Add various missing register offset #defines
* Accessor macros which combine distributor and redistributor behaviour removed
* Fields in state structures renamed to match architectural register names
* Corrected the reset value forGICR_IENABLER0since we don't support legacy mode
* AddedARM_LINUX_BOOT_IFinterface for "we are directly booting a kernel in non-secure" so that we can fake up the firmware-mandated reconfiguration only when we need it
]Signed-off-by Peter Maydell <[email protected]>--- hw/intc/arm_gicv3_common.c | 140 ++++++++++++++++++++++++++- hw/intc/gicv3_internal.h | 172 +++++++++++++++++++++++++++++++++ include/hw/intc/arm_gicv3_common.h | 189 ++++++++++++++++++++++++++++++++++++- 3 files changed, 496 insertions(+), 5 deletions(-) create mode 100644 hw/intc/gicv3_internal.hhw/intc/arm_gicv3_common.c +6
-1@@ -3,8 +3,9 @@* * Copyright (c) 2012 Linaro Limited * Copyright (c) 2015 Huawei. +* Copyright (c) 2015 Samsung Electronics Co., Ltd. * Written by Peter Maydell -* Extended to 64 cores by Shlomo Pongratz +* Reworked for GICv3 by Shlomo Pongratz and Pavel Fedin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,7 +23,10 @@#include "qemu/osdep.h" #include "qapi/error.h" +#include "qom/cpu.h" #include "hw/intc/arm_gicv3_common.h" +#include "gicv3_internal.h" +#include "hw/arm/linux-boot-if.h" static void gicv3_pre_save (void *opaque) {@@ -90,6 +94,7 @@ void gicv3_init_irqs_and_mmio(GICv3State *s, qemu_irq_handler handler,static void arm_gicv3_common_realize (DeviceState *dev,Error **errp) {GICv3State *s =ARM_GICV3_COMMON (dev); +int i;/* revision property is actually reserved and currently used only in order * to keep the interface compatible with GICv2 code, avoiding extra @@ -100,11 +105,136 @@ static void arm_gicv3_common_realize(DeviceState *dev, Error **errp)error_setg (errp,"unsupported GIC revision %d" , s->revision);
hw/intc/arm_gicv3_common.c static void arm_gicv3_common_realize(DeviceState *dev, Error **errp) · line 115
Quoted 10 lines
hw/intc/arm_gicv3_common.c +8
-0return ; } + +if (s->num_irq >GICV3_MAXIRQ ) { +error_setg (errp, +"requested %u interrupt lines exceeds GIC maximum %d" , + s->num_irq,GICV3_MAXIRQ ); +return ; + } +
Does it need to check if s->num_irq is less than 32?
hw/intc/arm_gicv3_common.c static void arm_gicv3_common_realize(DeviceState *dev, Error **errp) · line 117
Quoted 2 lines
hw/intc/arm_gicv3_common.c +2
-0+ s->cpu =g_new0 (GICv3CPUState, s->num_cpu); +
And check if s->num_cpu is greater than 0?
Quoted 71 lines
hw/intc/arm_gicv3_common.c +66
-1+for (i =0 ; i < s->num_cpu; i++) { +CPUState *cpu =qemu_get_cpu (i); +uint64_t cpu_affid; +int last; + + s->cpu[i].cpu = cpu; + s->cpu[i].gic = s; + +/* Pre-construct the GICR_TYPER: +* For our implementation: +* Top 32 bits are the affinity value of the associated CPU +* CommonLPIAff == 01 (redistributors with same Aff3 share LPI table) +* Processor_Number == CPU index starting from 0 +* DPGS == 0 (GICR_CTLR.DPG* not supported) +* Last == 1 if this is the last redistributor in a series of +* contiguous redistributor pages +* DirectLPI == 0 (direct injection of LPIs not supported) +* VLPIS == 0 (virtual LPIs not supported) +* PLPIS == 0 (physical LPIs not supported) +*/ + cpu_affid =object_property_get_int (OBJECT (cpu),"mp-affinity" ,NULL ); + last = (i == s->num_cpu -1 ); + +/* The CPU mp-affinity property is in MPIDR register format; squash +* the affinity bytes into 32 bits as the GICR_TYPER has them. +*/ + cpu_affid = (cpu_affid &0xFF00000000ULL >>8 ) | (cpu_affid &0xFFFFFF ); + s->cpu[i].gicr_typer = (cpu_affid <<32 ) | + (1 <<24 ) | + (i <<8 ) | + (last <<4 ); + } }static void arm_gicv3_common_reset (DeviceState *dev) { -/* TODO */ +GICv3State *s =ARM_GICV3_COMMON (dev); +int i; + +for (i =0 ; i < s->num_cpu; i++) { +GICv3CPUState *cs = &s->cpu[i]; + + cs->level =0 ; + cs->gicr_ctlr =0 ; + cs->gicr_statusr[GICV3_S ] =0 ; + cs->gicr_statusr[GICV3_NS ] =0 ; + cs->gicr_waker = GICR_WAKER_ProcessorSleep | GICR_WAKER_ChildrenAsleep; + cs->gicr_propbaser =0 ; + cs->gicr_pendbaser =0 ; +/* If we're resetting a TZ-aware GIC as if secure firmware +* had set it up ready to start a kernel in non-secure, we +* need to set interrupts to group 1 so the kernel can use them. +* Otherwise they reset to group 0 like the hardware. +*/ +if (s->irq_reset_nonsecure) { + cs->gicr_igroupr0 =0xffffffff ; + }else { + cs->gicr_igroupr0 =0 ; + } + + cs->gicr_ienabler0 =0 ; + cs->gicr_ipendr0 =0 ; + cs->gicr_iactiver0 =0 ; + cs->edge_trigger =0xffff ; + cs->gicr_igrpmodr0 =0 ; + cs->gicr_nsacr =0 ; +memset (cs->gicr_ipriorityr,0 ,sizeof (cs->gicr_ipriorityr)); + +/* State in the CPU interface must *not* be reset here, because it +* is part of the CPU's reset domain, not the GIC device's.
hw/intc/arm_gicv3_common.c static void arm_gicv3_common_realize(DeviceState *dev, Error **errp) · line 197
Quoted 10 lines
hw/intc/arm_gicv3_common.c +10
-0+*/ + } + +/* For our implementation affinity routing is always enabled */ +if (s->security_extn) { + s->gicd_ctlr =GICD_CTLR_ARE_S |GICD_CTLR_ARE_NS ; + }else { + s->gicd_ctlr =GICD_CTLR_DS |GICD_CTLR_ARE ; + } +
I'm a little confused with the no security support case, and in that case, this GICv3 implementation supports only a single Security state, right? If so, the SPEC says the DS bit is "Disable Security. This field is RAO/WI." So why do you set the DS bit here?
[...]
Quoted 50 lines
hw/intc/gicv3_internal.h new file +44
-0@@ -0,0 +1,172 @@ +/* +* ARM GICv3 support - internal interfaces +* +* Copyright (c) 2012 Linaro Limited +* Copyright (c) 2015 Huawei. +* Copyright (c) 2015 Samsung Electronics Co., Ltd. +* Written by Peter Maydell +* Reworked for GICv3 by Shlomo Pongratz and Pavel Fedin +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef QEMU_ARM_GICV3_INTERNAL_H +#define QEMU_ARM_GICV3_INTERNAL_H + +#include "hw/intc/arm_gicv3_common.h" + +/* Distributor registers, as offsets from the distributor base address */ +#define GICD_CTLR 0x0000 +#define GICD_TYPER 0x0004 +#define GICD_IIDR 0x0008 +#define GICD_STATUSR 0x0010 +#define GICD_SETSPI_NSR 0x0040 +#define GICD_CLRSPI_NSR 0x0048 +#define GICD_SETSPI_SR 0x0050 +#define GICD_CLRSPI_SR 0x0058 +#define GICD_SEIR 0x0068 +#define GICD_IGROUPR 0x0080 +#define GICD_ISENABLER 0x0100 +#define GICD_ICENABLER 0x0180 +#define GICD_ISPENDR 0x0200 +#define GICD_ICPENDR 0x0280 +#define GICD_ISACTIVER 0x0300
hw/intc/gicv3_internal.h line 54
Quoted 10 lines
hw/intc/gicv3_internal.h new file +10
-0+#define GICD_ICACTIVER 0x0380 +#define GICD_IPRIORITYR 0x0400 +#define GICD_ITARGETSR 0x0800 +#define GICD_ICFGR 0x0C00 +#define GICD_IGRPMODR 0x0D00 +#define GICD_NSACR 0x0E00 +#define GICD_SGIR 0x0F00 +#define GICD_CPENDSGIR 0x0F10 +#define GICD_SPENDSGIR 0x0F20 +#define GICD_IROUTER 0x6000
This should be 0x6100 or gicd_irouter[GICV3_MAXSPI] should use GIC_MAXIRQ in struct GICv3State. Otherwise gicd_read_irouter() will be wrong because s->gicd_irouter[irq] will be off normal upper if irq is e.g. GIC_MAXIRQ - 1.
[...]
hw/intc/gicv3_internal.h line 129
Quoted 5 lines
hw/intc/gicv3_internal.h new file +5
-0+#define GICR_PROPBASER_OUTER_CACHEABILITY_MASK (7ULL << 56) +#define GICR_PROPBASER_ADDR_MASK (0xfffffffffULL << 12) +#define GICR_PROPBASER_SHAREABILITY_MASK (3U << 10) +#define GICR_PROPBASER_CACHEABILITY_MASK (7U << 7) +#define GICR_PROPBASER_IDBITS_MASK (0x1f)
Use (0x1f << 0) to keep consistent?
Thanks,
Signature · 1 line
Shannon
Re: [Qemu-arm] [Qemu-devel] [PATCH 06/23] hw/intc/arm_gicv3: Add state information
Quoted 84 lines · Shannon Zhao
Quoted 69 lines · Peter Maydell
From: Pavel Fedin <[email protected]>
Add state information to GICv3 object structure and implement
arm_gicv3_common_reset().This commit includes accessor functions for the fields which are stored as bitmaps in
uint32_tarrays.Signed-off-by Pavel Fedin <[email protected]>[PMM: significantly overhauled:
* Add missingqom/cpu.hinclude
* Remove legacy-only state fields (we can add them later if/when we add legacy emulation)
* Use arrays ofuint32_tto store the various distributor bitmaps, and provide accessor functions for the various set/test/etc operations
* Add various missing register offset #defines
* Accessor macros which combine distributor and redistributor behaviour removed
* Fields in state structures renamed to match architectural register names
* Corrected the reset value forGICR_IENABLER0since we don't support legacy mode
* AddedARM_LINUX_BOOT_IFinterface for "we are directly booting a kernel in non-secure" so that we can fake up the firmware-mandated reconfiguration only when we need it
]Signed-off-by Peter Maydell <[email protected]>--- hw/intc/arm_gicv3_common.c | 140 ++++++++++++++++++++++++++- hw/intc/gicv3_internal.h | 172 +++++++++++++++++++++++++++++++++ include/hw/intc/arm_gicv3_common.h | 189 ++++++++++++++++++++++++++++++++++++- 3 files changed, 496 insertions(+), 5 deletions(-) create mode 100644 hw/intc/gicv3_internal.hhw/intc/arm_gicv3_common.c +6
-1@@ -3,8 +3,9 @@* * Copyright (c) 2012 Linaro Limited * Copyright (c) 2015 Huawei. +* Copyright (c) 2015 Samsung Electronics Co., Ltd. * Written by Peter Maydell -* Extended to 64 cores by Shlomo Pongratz +* Reworked for GICv3 by Shlomo Pongratz and Pavel Fedin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,7 +23,10 @@#include "qemu/osdep.h" #include "qapi/error.h" +#include "qom/cpu.h" #include "hw/intc/arm_gicv3_common.h" +#include "gicv3_internal.h" +#include "hw/arm/linux-boot-if.h" static void gicv3_pre_save (void *opaque) {@@ -90,6 +94,7 @@ void gicv3_init_irqs_and_mmio(GICv3State *s, qemu_irq_handler handler,static void arm_gicv3_common_realize (DeviceState *dev,Error **errp) {GICv3State *s =ARM_GICV3_COMMON (dev); +int i;/* revision property is actually reserved and currently used only in order * to keep the interface compatible with GICv2 code, avoiding extra @@ -100,11 +105,136 @@ static void arm_gicv3_common_realize(DeviceState *dev, Error **errp)error_setg (errp,"unsupported GIC revision %d" , s->revision);hw/intc/arm_gicv3_common.c static void arm_gicv3_common_realize(DeviceState *dev, Error **errp) · line 115
Quoted 10 lines
hw/intc/arm_gicv3_common.c +8
-0return ; } + +if (s->num_irq >GICV3_MAXIRQ ) { +error_setg (errp, +"requested %u interrupt lines exceeds GIC maximum %d" , + s->num_irq,GICV3_MAXIRQ ); +return ; + } +Does it need to check if
s->num_irqis less than 32?
Quoted 3 lines
hw/intc/arm_gicv3_common.c static void arm_gicv3_common_realize(DeviceState *dev, Error **errp) · line 117
Quoted 2 lines
hw/intc/arm_gicv3_common.c +2
-0+ s->cpu =g_new0 (GICv3CPUState, s->num_cpu); +And check if
s->num_cpuis greater than 0?
Yes, we should probably use the same set of checks as the gicv2 common realize code does.
Quoted 11 lines
hw/intc/arm_gicv3_common.c static void arm_gicv3_common_realize(DeviceState *dev, Error **errp) · line 197
Quoted 7 lines
hw/intc/arm_gicv3_common.c +7
-0+/* For our implementation affinity routing is always enabled */ +if (s->security_extn) { + s->gicd_ctlr =GICD_CTLR_ARE_S |GICD_CTLR_ARE_NS ; + }else { + s->gicd_ctlr =GICD_CTLR_DS |GICD_CTLR_ARE ; + } +I'm a little confused with the no security support case, and in that case, this GICv3 implementation supports only a single Security state, right? If so, the SPEC says the DS bit is "Disable Security. This field is RAO/WI." So why do you set the DS bit here?
We set the bit here exactly because it is RAO/WI: the bit is set to 1 here, and we forbid changing it via register writes, so it always reads as 1. Then all the rest of the GIC code[*] checks (s->gicd_ctlr & GICD_CTLR_DS), which works whether this is a no-security GIC or a with-security GIC that the guest has configured to disable security.
[*] there are one or two config register values that architecturally need to care about s->security_extn rather than the CTLR_DS bit.
Quoted 6 lines
hw/intc/arm_gicv3_common.c static void arm_gicv3_common_realize(DeviceState *dev, Error **errp) · line 125
Quoted 1 line
hw/intc/arm_gicv3_common.c +1
-0+#define GICD_IROUTER 0x6000This should be
0x6100or gicd_irouter[GICV3_MAXSPI] should useGIC_MAXIRQin struct GICv3State. Otherwisegicd_read_irouter()will be wrong because s->gicd_irouter[irq] will be off normal upper if irq is e.g.GIC_MAXIRQ- 1.
I think we should leave this offset as 0x6000, and have gicd_read_irouter() and other places that use the array subtract GIC_INTERNAL from the irq number. This would then be in line with how we handle gicd_ipriority[] (and with the bitmap regs).
Quoted 6 lines
hw/intc/arm_gicv3_common.c static void arm_gicv3_common_realize(DeviceState *dev, Error **errp) · line 130
Quoted 5 lines
hw/intc/arm_gicv3_common.c +5
-0+#define GICR_PROPBASER_OUTER_CACHEABILITY_MASK (7ULL << 56) +#define GICR_PROPBASER_ADDR_MASK (0xfffffffffULL << 12) +#define GICR_PROPBASER_SHAREABILITY_MASK (3U << 10) +#define GICR_PROPBASER_CACHEABILITY_MASK (7U << 7) +#define GICR_PROPBASER_IDBITS_MASK (0x1f)Use (
0x1f<< 0) to keep consistent?
Sure.
thanks
-- PMM
PATCH 7/23 hw/intc/arm_gicv3: Move irq lines into GICv3CPUState structure
In reply to Peter MaydellMove the GICv3 parent_irq and parent_fiq pointers into the GICv3CPUState structure rather than giving them their own array. This will make it easy to assert the IRQ and FIQ lines for a particular CPU interface without having to know or calculate the CPU index for the GICv3CPUState we are working on.
--- hw/intc/arm_gicv3_common.c | 7 ++----- include/hw/intc/arm_gicv3_common.h | 5 ++--- 2 files changed, 4 insertions(+), 8 deletions(-)
hw/intc/arm_gicv3_common.c +2 -5
@@ -72,14 +72,11 @@ void gicv3_init_irqs_and_mmio(GICv3State *s, qemu_irq_handler handler, i = s->num_irq -GIC_INTERNAL +GIC_INTERNAL * s->num_cpu;qdev_init_gpio_in (DEVICE (s), handler, i); - s->parent_irq =g_malloc (s->num_cpu *sizeof (qemu_irq)); - s->parent_fiq =g_malloc (s->num_cpu *sizeof (qemu_irq)); -for (i =0 ; i < s->num_cpu; i++) { -sysbus_init_irq (sbd, &s->parent_irq[i]); +sysbus_init_irq (sbd, &s->cpu[i].parent_irq); }for (i =0 ; i < s->num_cpu; i++) { -sysbus_init_irq (sbd, &s->parent_fiq[i]); +sysbus_init_irq (sbd, &s->cpu[i].parent_fiq); } memory_region_init_io(&s->iomem_dist, OBJECT(s), ops, s,
include/hw/intc/arm_gicv3_common.h +2 -3
@@ -131,6 +131,8 @@ typedef struct GICv3CPUState GICv3CPUState;struct GICv3CPUState {GICv3State *gic;CPUState *cpu; +qemu_irq parent_irq; +qemu_irq parent_fiq;/* Redistributor */ uint32_t level;/* Current IRQ level */
@@ -165,9 +167,6 @@ struct GICv3State {SysBusDevice parent_obj;/*< public >*/ -qemu_irq *parent_irq; -qemu_irq *parent_fiq; -MemoryRegion iomem_dist;/* Distributor */ MemoryRegion iomem_redist;/* Redistributors */
Signature · 1 line
1.9.1
PATCH 8/23 hw/intc/arm_gicv3: Add vmstate descriptors
In reply to Peter MaydellFrom: Pavel Fedin <[email protected]>
Add state structure descriptors for the GICv3 state. We mark the KVM GICv3 device as having a migration blocker until the code to save and restore the state in the kernel is implemented.
[PMM: Adjust to renamed struct fields; switched to using uint32_t
array backed bitmaps; add migration blocker setting]
--- hw/intc/arm_gicv3_common.c | 50 +++++++++++++++++++++++++++++++++++++++++++++- hw/intc/arm_gicv3_kvm.c | 7 +++++++ 2 files changed, 56 insertions(+), 1 deletion(-)
hw/intc/arm_gicv3_common.c +49 -1
@@ -49,11 +49,59 @@ static int gicv3_post_load(void *opaque, int version_id)return 0 ; } +static const VMStateDescription vmstate_gicv3_cpu = { + .name ="arm_gicv3_cpu" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (level, GICv3CPUState), +VMSTATE_UINT32 (gicr_ctlr, GICv3CPUState), +VMSTATE_UINT32_ARRAY (gicr_statusr, GICv3CPUState,2 ), +VMSTATE_UINT32 (gicr_waker, GICv3CPUState), +VMSTATE_UINT64 (gicr_propbaser, GICv3CPUState), +VMSTATE_UINT64 (gicr_pendbaser, GICv3CPUState), +VMSTATE_UINT32 (gicr_igroupr0, GICv3CPUState), +VMSTATE_UINT32 (gicr_ienabler0, GICv3CPUState), +VMSTATE_UINT32 (gicr_ipendr0, GICv3CPUState), +VMSTATE_UINT32 (gicr_iactiver0, GICv3CPUState), +VMSTATE_UINT32 (edge_trigger, GICv3CPUState), +VMSTATE_UINT32 (gicr_igrpmodr0, GICv3CPUState), +VMSTATE_UINT32 (gicr_nsacr, GICv3CPUState), +VMSTATE_UINT8_ARRAY (gicr_ipriorityr, GICv3CPUState,GIC_INTERNAL ), +VMSTATE_UINT64_ARRAY (icc_ctlr_el1, GICv3CPUState,2 ), +VMSTATE_UINT64 (icc_pmr_el1, GICv3CPUState), +VMSTATE_UINT64_ARRAY (icc_bpr, GICv3CPUState,3 ), +VMSTATE_UINT64_2DARRAY (icc_apr, GICv3CPUState,3 ,4 ), +VMSTATE_UINT64_ARRAY (icc_igrpen, GICv3CPUState,3 ), +VMSTATE_UINT64 (icc_ctlr_el3, GICv3CPUState), +VMSTATE_END_OF_LIST () + } +}; +static const VMStateDescription vmstate_gicv3 = { .name ="arm_gicv3" , - .unmigratable =1 , + .version_id =1 , + .minimum_version_id =1 , .pre_save = gicv3_pre_save, .post_load = gicv3_post_load, + .fields = (VMStateField []) { +VMSTATE_UINT32 (gicd_ctlr, GICv3State), +VMSTATE_UINT32_ARRAY (gicd_statusr, GICv3State,2 ), +VMSTATE_UINT32_ARRAY (group, GICv3State,GICV3_BMP_SIZE ), +VMSTATE_UINT32_ARRAY (grpmod, GICv3State,GICV3_BMP_SIZE ), +VMSTATE_UINT32_ARRAY (enabled, GICv3State,GICV3_BMP_SIZE ), +VMSTATE_UINT32_ARRAY (pending, GICv3State,GICV3_BMP_SIZE ), +VMSTATE_UINT32_ARRAY (active, GICv3State,GICV3_BMP_SIZE ), +VMSTATE_UINT32_ARRAY (level, GICv3State,GICV3_BMP_SIZE ), +VMSTATE_UINT32_ARRAY (edge_trigger, GICv3State,GICV3_BMP_SIZE ), +VMSTATE_UINT8_ARRAY (gicd_ipriority, GICv3State,GICV3_MAXSPI ), +VMSTATE_UINT64_ARRAY (gicd_irouter, GICv3State,GICV3_MAXSPI ), +VMSTATE_UINT32_ARRAY (gicd_nsacr, GICv3State, +DIV_ROUND_UP (GICV3_MAXSPI ,16 )), +VMSTATE_STRUCT_VARRAY_POINTER_UINT32 (cpu, GICv3State, num_cpu, + vmstate_gicv3_cpu, GICv3CPUState), +VMSTATE_END_OF_LIST () + } }; void gicv3_init_irqs_and_mmio(GICv3State *s, qemu_irq_handler handler,
hw/intc/arm_gicv3_kvm.c +7 -0
@@ -119,6 +119,13 @@ static void kvm_arm_gicv3_realize(DeviceState *dev, Error **errp) KVM_VGIC_V3_ADDR_TYPE_DIST, s->dev_fd);kvm_arm_register_device (&s->iomem_redist,-1 ,KVM_DEV_ARM_VGIC_GRP_ADDR ,KVM_VGIC_V3_ADDR_TYPE_REDIST , s->dev_fd); + +/* Block migration of a KVM GICv3 device: the API for saving and restoring +* the state in the kernel is not yet finalised in the kernel or +* implemented in QEMU. +*/ +error_setg (&s->migration_blocker,"vGICv3 migration is not implemented" ); +migrate_add_blocker (s->migration_blocker); }static void kvm_arm_gicv3_class_init (ObjectClass *klass,void *data)
Signature · 1 line
1.9.1
PATCH 9/23 hw/intc/arm_gicv3: ARM GICv3 device framework
In reply to Peter MaydellFrom: Shlomo Pongratz <[email protected]>
This patch includes the device class itself, some ID register value functions which will be needed by both distributor and redistributor, and some skeleton functions for handling interrupts coming in and going out, which will be filled in in a subsequent patch.
[PMM: pulled this patch earlier in the sequence, and left
some code out of it for a later patch]
--- hw/intc/Makefile.objs | 1 + hw/intc/arm_gicv3.c | 74 +++++++++++++++++++++++++++++++++++++++++++++ hw/intc/gicv3_internal.h | 24 +++++++++++++++ include/hw/intc/arm_gicv3.h | 32 ++++++++++++++++++++ 4 files changed, 131 insertions(+) create mode 100644 hw/intc/arm_gicv3.c create mode 100644 include/hw/intc/arm_gicv3.h
hw/intc/Makefile.objs +1 -0
@@ -13,6 +13,7 @@ common-obj-$(CONFIG_ARM_GIC) += arm_gic_common.o common-obj-$(CONFIG_ARM_GIC) += arm_gic.o common-obj-$(CONFIG_ARM_GIC) += arm_gicv2m.o common-obj-$(CONFIG_ARM_GIC) += arm_gicv3_common.o +common-obj-$(CONFIG_ARM_GIC) += arm_gicv3.o common-obj-$(CONFIG_OPENPIC) += openpic.o obj-$(CONFIG_APIC) += apic.o apic_common.o
hw/intc/arm_gicv3.c new file +74 -0
74 lines not on this page · raw message
hw/intc/gicv3_internal.h +24 -0
@@ -159,6 +159,30 @@#define ICC_CTLR_EL3_A3V (1U << 15)#define ICC_CTLR_EL3_NDS (1U << 17) +static inline uint32_t gicv3_iidr (void ) +{ +/* Return the Implementer Identification Register value +* for the emulated GICv3, as reported in GICD_IIDR and GICR_IIDR. +* +* We claim to be an ARM r0p0 with a zero ProductID. +* This is the same as an r0p0 GIC-500. +*/ +return 0x43b ; +} + +static inline uint32_t gicv3_idreg (int regoffset) +{ +/* Return the value of the CoreSight ID register at the specified +* offset from the first ID register (as found in the distributor +* and redistributor register banks). +* These values indicate an ARM implementation of a GICv3. +*/ +static const uint8_t gicd_ids[] = { +0x44 ,0x00 ,0x00 ,0x00 ,0x92 ,0xB4 ,0x3B ,0x00 ,0x0D ,0xF0 ,0x05 ,0xB1 + }; +return gicd_ids[regoffset /4 ]; +} +/** * gicv3_redist_affid: *
include/hw/intc/arm_gicv3.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* ARM Generic Interrupt Controller v3 +* +* Copyright (c) 2015 Huawei. +* Copyright (c) 2016 Linaro Limited +* Written by Shlomo Pongratz, Peter Maydell +* +* This code is licensed under the GPL, version 2 or (at your option) +* any later version. +*/ + +#ifndef HW_ARM_GICV3_H +#define HW_ARM_GICV3_H + +#include "arm_gicv3_common.h" + +#define TYPE_ARM_GICV3 "arm-gicv3" +#define ARM_GICV3 (obj) OBJECT_CHECK(GICv3State, (obj), TYPE_ARM_GICV3) +#define ARM_GICV3_CLASS (klass) \ + OBJECT_CLASS_CHECK(ARMGICv3Class, (klass), TYPE_ARM_GICV3) +#define ARM_GICV3_GET_CLASS (obj) \ + OBJECT_GET_CLASS(ARMGICv3Class, (obj), TYPE_ARM_GICV3) + +typedef struct ARMGICv3Class { +/*< private >*/ +ARMGICv3CommonClass parent_class; +/*< public >*/ + +DeviceRealize parent_realize; +}ARMGICv3Class ; + +#endif
Signature · 1 line
1.9.1
PATCH 10/23 hw/intc/arm_gicv3: Implement functions to identify next pending irq
In reply to Peter MaydellImplement the GICv3 logic to recalculate the highest priority pending interrupt for each CPU after some part of the GIC state has changed. We avoid unnecessary full recalculation where possible.
--- hw/intc/arm_gicv3.c | 290 +++++++++++++++++++++++++++++++++++++ hw/intc/arm_gicv3_common.c | 9 ++ hw/intc/gicv3_internal.h | 121 ++++++++++++++++ include/hw/intc/arm_gicv3_common.h | 18 +++ 4 files changed, 438 insertions(+)
hw/intc/arm_gicv3.c +290 -0
@@ -21,6 +21,284 @@#include "hw/intc/arm_gicv3.h" #include "gicv3_internal.h" +static bool irqbetter (GICv3CPUState *cs,int irq,uint8_t prio) +{ +/* Return true if this IRQ at this priority should take +* precedence over the current recorded highest priority +* pending interrupt for this CPU. We also return true if +* the current recorded highest priority pending interrupt +* is the same as this one (a property which the calling code +* relies on). +*/ +if (prio < cs->hppi.prio) { +return true; + } +/* If multiple pending interrupts have the same priority then it is an +* IMPDEF choice which of them to signal to the CPU. We choose to +* signal the one with the lowest interrupt number. +*/ +if (prio == cs->hppi.prio && irq <= cs->hppi.irq) { +return true; + } +return false; +} + +static uint32_t gicd_int_pending (GICv3State *s,int irq) +{ +/* Recalculate which redistributor interrupts are actually pending +* in the group of 32 interrupts starting at irq (which should be a multiple +* of 32), and return a 32-bit integer which has a bit set for each +* interrupt that is eligible to be signaled to the CPU interface. +* +* An interrupt is pending if: +* + the PENDING latch is set OR it is level triggered and the input is 1 +* + its ENABLE bit is set +* + the GICD enable bit for its group is set +* Conveniently we can bulk-calculate this with bitwise operations. +*/ +uint32_t pend, grpmask; +uint32_t pending = *gic_bmp_ptr32 (s->pending, irq -GIC_INTERNAL ); +uint32_t edge_trigger = *gic_bmp_ptr32 (s->edge_trigger, irq -GIC_INTERNAL ); +uint32_t level = *gic_bmp_ptr32 (s->level, irq -GIC_INTERNAL ); +uint32_t group = *gic_bmp_ptr32 (s->group, irq -GIC_INTERNAL ); +uint32_t grpmod = *gic_bmp_ptr32 (s->grpmod, irq -GIC_INTERNAL ); +uint32_t enable = *gic_bmp_ptr32 (s->enabled, irq -GIC_INTERNAL ); + + pend = pending | (~edge_trigger & level); + pend &= enable; + +if (s->gicd_ctlr &GICD_CTLR_DS ) { + grpmod =0 ; + } + + grpmask =0 ; +if (s->gicd_ctlr &GICD_CTLR_EN_GRP1NS ) { + grpmask |= group; + } +if (s->gicd_ctlr &GICD_CTLR_EN_GRP1S ) { + grpmask |= (~group & grpmod); + } +if (s->gicd_ctlr &GICD_CTLR_EN_GRP0 ) { + grpmask |= (~group & ~grpmod); + } + pend &= grpmask; + +return pend; +} + +static uint32_t gicr_int_pending (GICv3CPUState *cs) +{ +/* Recalculate which redistributor interrupts are actually pending, +* and return a 32-bit integer which has a bit set for each interrupt +* that is eligible to be signaled to the CPU interface. +* +* An interrupt is pending if: +* + the PENDING latch is set OR it is level triggered and the input is 1 +* + its ENABLE bit is set +* + the GICD enable bit for its group is set +* Conveniently we can bulk-calculate this with bitwise operations. +*/ +uint32_t pend, grpmask, grpmod; + + pend = cs->gicr_ipendr0 | (~cs->edge_trigger & cs->level); + pend &= cs->gicr_ienabler0; + +if (cs->gic->gicd_ctlr &GICD_CTLR_DS ) { + grpmod =0 ; + }else { + grpmod = cs->gicr_igrpmodr0; + } + + grpmask =0 ; +if (cs->gic->gicd_ctlr &GICD_CTLR_EN_GRP1NS ) { + grpmask |= cs->gicr_igroupr0; + } +if (cs->gic->gicd_ctlr &GICD_CTLR_EN_GRP1S ) { + grpmask |= (~cs->gicr_igroupr0 & grpmod); + } +if (cs->gic->gicd_ctlr &GICD_CTLR_EN_GRP0 ) { + grpmask |= (~cs->gicr_igroupr0 & ~grpmod); + } + pend &= grpmask; + +return pend; +} + +/* Update the interrupt status after state in a redistributor +* or CPU interface has changed, but don't tell the CPU i/f. +*/ +static void gicv3_redist_update_noirqset (GICv3CPUState *cs) +{ +/* Find the highest priority pending interrupt among the +* redistributor interrupts (SGIs and PPIs). +*/ +bool seenbetter = false; +uint8_t prio; +int i; +uint32_t pend; + +/* Find out which redistributor interrupts are eligible to be +* signaled to the CPU interface. +*/ + pend =gicr_int_pending (cs); + +if (pend) { +for (i =0 ; i <GIC_INTERNAL ; i++) { +if (!(pend & (1 << i))) { +continue ; + } + prio = cs->gicr_ipriorityr[i]; +if (irqbetter (cs, i, prio)) { + cs->hppi.irq = i; + cs->hppi.prio = prio; + seenbetter = true; + } + } + } + +if (seenbetter) { + cs->hppi.grp =gicv3_irq_group (cs->gic, cs, cs->hppi.irq); + } + +/* If the best interrupt we just found would preempt whatever +* was the previous best interrupt before this update, then +* we know it's definitely the best one now. +* If we didn't find an interrupt that would preempt the previous +* best, and the previous best is outside our range (or there was no +* previous pending interrupt at all), then that is still valid, and +* we leave it as the best. +* Otherwise, we need to do a full update (because the previous best +* interrupt has reduced in priority and any other interrupt could +* now be the new best one). +*/ +if (!seenbetter && cs->hppi.prio !=0xff && cs->hppi.irq <GIC_INTERNAL ) { +gicv3_full_update_noirqset (cs->gic); + } +} + +/* Update the GIC status after state in a redistributor or +* CPU interface has changed, and inform the CPU i/f of +* its new highest priority pending interrupt. +*/ +void gicv3_redist_update (GICv3CPUState *cs) +{ +gicv3_redist_update_noirqset (cs); +gicv3_cpuif_update (cs); +} + +/* Update the GIC status after state in the distributor has +* changed affecting @len interrupts starting at @start, +* but don't tell the CPU i/f. +*/ +static void gicv3_update_noirqset (GICv3State *s,int start,int len) +{ +int i; +uint8_t prio; +uint32_t pend =0 ; + +for (i =0 ; i < s->num_cpu; i++) { + s->cpu[i].seenbetter = false; + } + +/* Find the highest priority pending interrupt in this range. */ +for (i = start; i < start + len; i++) { +GICv3CPUState *cs; + +if (i == start || (i &0x1f ) ==0 ) { +/* Calculate the next 32 bits worth of pending status */ + pend =gicd_int_pending (s, i & ~0x1f ); + } + +if (!(pend & (1 << (i &0x1f )))) { +continue ; + } + cs = s->gicd_irouter_target[i]; +if (!cs) { +/* Interrupts targeting no implemented CPU should remain pending +* and not be forwarded to any CPU. +*/ +continue ; + } + prio = s->gicd_ipriority[i]; +if (irqbetter (cs, i, prio)) { + cs->hppi.irq = i; + cs->hppi.prio = prio; + cs->seenbetter = true; + } + } + +/* If the best interrupt we just found would preempt whatever +* was the previous best interrupt before this update, then +* we know it's definitely the best one now. +* If we didn't find an interrupt that would preempt the previous +* best, and the previous best is outside our range (or there was +* no previous pending interrupt at all), then that +* is still valid, and we leave it as the best. +* Otherwise, we need to do a full update (because the previous best +* interrupt has reduced in priority and any other interrupt could +* now be the new best one). +*/ +for (i =0 ; i < s->num_cpu; i++) { +GICv3CPUState *cs = &s->cpu[i]; + +if (cs->seenbetter) { + cs->hppi.grp =gicv3_irq_group (cs->gic, cs, cs->hppi.irq); + } + +if (!cs->seenbetter && cs->hppi.prio !=0xff && + cs->hppi.irq >= start && cs->hppi.irq < start + len) { +gicv3_full_update_noirqset (s); +break ; + } + } +} + +void gicv3_update (GICv3State *s,int start,int len) +{ +int i; + +gicv3_update_noirqset (s, start, len); +for (i =0 ; i < s->num_cpu; i++) { +gicv3_cpuif_update (&s->cpu[i]); + } +} + +void gicv3_full_update_noirqset (GICv3State *s) +{ +/* Completely recalculate the GIC status from scratch, but +* don't update any outbound IRQ lines. +*/ +int i; + +for (i =0 ; i < s->num_cpu; i++) { + s->cpu[i].hppi.prio =0xff ; + } + +/* Note that we can guarantee that these functions will not +* recursively call back into gicv3_full_update(), because +* at each point the "previous best" is always outside the +* range we ask them to update. +*/ +gicv3_update_noirqset (s,0 , s->num_irq); + +for (i =0 ; i < s->num_cpu; i++) { +gicv3_redist_update_noirqset (&s->cpu[i]); + } +} + +void gicv3_full_update (GICv3State *s) +{ +/* Completely recalculate the GIC status from scratch, including +* updating outbound IRQ lines. +*/ +int i; + +gicv3_full_update_noirqset (s); +for (i =0 ; i < s->num_cpu; i++) { +gicv3_cpuif_update (&s->cpu[i]); + } +} +/* Process a change in an external IRQ input. */ static void gicv3_set_irq (void *opaque,int irq,int level) {
@@ -33,6 +311,16 @@ static void gicv3_set_irq(void *opaque, int irq, int level)/* Do nothing for now */ } +static void arm_gicv3_post_load (GICv3State *s) +{ +/* Recalculate our cached idea of the current highest priority +* pending interrupt, but don't set IRQ or FIQ lines. +*/ +gicv3_full_update_noirqset (s); +/* Repopulate the cache of GICv3CPUState pointers for target CPUs */ +gicv3_cache_all_target_cpustates (s); +} +static void arm_gic_realize (DeviceState *dev,Error **errp) {/* Device instance realize function for the GIC sysbus device */
@@ -52,8 +340,10 @@ static void arm_gic_realize(DeviceState *dev, Error **errp)static void arm_gicv3_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); +ARMGICv3CommonClass *agcc =ARM_GICV3_COMMON_CLASS (klass);ARMGICv3Class *agc =ARM_GICV3_CLASS (klass); + agcc->post_load = arm_gicv3_post_load; agc->parent_realize = dc->realize; dc->realize = arm_gic_realize; }
hw/intc/arm_gicv3_common.c +9 -0
@@ -228,6 +228,8 @@ static void arm_gicv3_common_reset(DeviceState *dev) cs->gicr_nsacr =0 ;memset (cs->gicr_ipriorityr,0 ,sizeof (cs->gicr_ipriorityr)); + cs->hppi.prio =0xff ; +/* State in the CPU interface must *not* be reset here, because it * is part of the CPU's reset domain, not the GIC device's. */
@@ -252,6 +254,13 @@ static void arm_gicv3_common_reset(DeviceState *dev)memset (s->edge_trigger,0 ,sizeof (s->edge_trigger));memset (s->gicd_ipriority,0 ,sizeof (s->gicd_ipriority));memset (s->gicd_irouter,0 ,sizeof (s->gicd_irouter)); +/* GICD_IROUTER are UNKNOWN at reset so in theory the guest must +* write these to get sane behaviour and we need not populate the +* pointer cache here; however having the cache be different for +* "happened to be 0 from reset" and "guest wrote 0" would be +* too confusing. +*/ +gicv3_cache_all_target_cpustates (s);if (s->irq_reset_nonsecure) {/* If we're resetting a TZ-aware GIC as if secure firmware
hw/intc/gicv3_internal.h +121 -0
137 lines not on this page · raw message
include/hw/intc/arm_gicv3_common.h +18 -0
@@ -128,6 +128,12 @@ typedef struct GICv3CPUState GICv3CPUState;#define GICV3_S 0#define GICV3_NS 1 +typedef struct { +int irq; +uint8_t prio; +int grp; +}PendingIrq ; +struct GICv3CPUState {GICv3State *gic;CPUState *cpu;
@@ -160,6 +166,14 @@ struct GICv3CPUState {uint64_t icc_apr[3 ][4 ];uint64_t icc_igrpen[3 ];uint64_t icc_ctlr_el3; + +/* Current highest priority pending interrupt for this CPU. +* This is cached information that can be recalculated from the +* real state above; it doesn't need to be migrated. +*/ +PendingIrq hppi; +/* This is temporary working state, to avoid a malloc in gicv3_update() */ +bool seenbetter; };struct GICv3State {
@@ -195,6 +209,10 @@ struct GICv3State {GIC_DECLARE_BITMAP (edge_trigger);/* GICD_ICFGR even bits */ uint8_t gicd_ipriority[GICV3_MAXSPI ];uint64_t gicd_irouter[GICV3_MAXSPI ]; +/* Cached information: pointer to the cpu i/f for the CPUs specified +* in the IROUTER registers +*/ +GICv3CPUState *gicd_irouter_target[GICV3_MAXSPI ];uint32_t gicd_nsacr[DIV_ROUND_UP (GICV3_MAXSPI ,16 )];GICv3CPUState *cpu;
Signature · 1 line
1.9.1
Re: [Qemu-arm] [Qemu-devel] [PATCH 10/23] hw/intc/arm_gicv3: Implement functions to identify next pending irq
hw/intc/arm_gicv3.c line 66
Quoted 8 lines · Peter Maydell
hw/intc/arm_gicv3.c +8
-0+uint32_t pend, grpmask; +uint32_t pending = *gic_bmp_ptr32 (s->pending, irq -GIC_INTERNAL ); +uint32_t edge_trigger = *gic_bmp_ptr32 (s->edge_trigger, irq -GIC_INTERNAL ); +uint32_t level = *gic_bmp_ptr32 (s->level, irq -GIC_INTERNAL ); +uint32_t group = *gic_bmp_ptr32 (s->group, irq -GIC_INTERNAL ); +uint32_t grpmod = *gic_bmp_ptr32 (s->grpmod, irq -GIC_INTERNAL ); +uint32_t enable = *gic_bmp_ptr32 (s->enabled, irq -GIC_INTERNAL ); +
Since you use "irq - GIC_INTERNAL" many times, how about moving into the gic_bmp_ptr32()?
[...]
Quoted 8 lines
hw/intc/arm_gicv3.c +8
-0+/* Update the GIC status after state in the distributor has +* changed affecting @len interrupts starting at @start, +* but don't tell the CPU i/f. +*/ +static void gicv3_update_noirqset (GICv3State *s,int start,int len) +{ +int i; +uint8_t prio;
hw/intc/arm_gicv3.c line 206
Quoted 10 lines
hw/intc/arm_gicv3.c +10
-0+uint32_t pend =0 ; + +for (i =0 ; i < s->num_cpu; i++) { + s->cpu[i].seenbetter = false; + } + +/* Find the highest priority pending interrupt in this range. */ +for (i = start; i < start + len; i++) { +GICv3CPUState *cs; +
The i should start from GIC_INTERNAL or you should change the parameter of the callers.
Quoted 5 lines
hw/intc/arm_gicv3.c +5
-0+if (i == start || (i &0x1f ) ==0 ) { +/* Calculate the next 32 bits worth of pending status */ + pend =gicd_int_pending (s, i & ~0x1f ); + } +
[...]
hw/intc/arm_gicv3.c line 283
Quoted 8 lines
hw/intc/arm_gicv3.c +8
-0+ +/* Note that we can guarantee that these functions will not +* recursively call back into gicv3_full_update(), because +* at each point the "previous best" is always outside the +* range we ask them to update. +*/ +gicv3_update_noirqset (s,0 , s->num_irq); +
use GIC_INTERNAL instead of 0?
Quoted 7 lines
/**
+ *gicv3_irq_group:
+ *
+ * Return the group which this interrupt is configured as (GICV3_G0,
+ *GICV3_G1orGICV3_G1NS).
+ */
+static inline intgicv3_irq_group(GICv3State *s, GICv3CPUState *cs, int irq)
use uint32_t instead of int in this and other functions?
Thanks,
Signature · 1 line
Shannon
Re: [Qemu-arm] [Qemu-devel] [PATCH 10/23] hw/intc/arm_gicv3: Implement functions to identify next pending irq
Quoted 11 lines · Shannon Zhao
hw/intc/arm_gicv3.c line 66
Quoted 8 lines · Peter Maydell
hw/intc/arm_gicv3.c +8
-0+uint32_t pend, grpmask; +uint32_t pending = *gic_bmp_ptr32 (s->pending, irq -GIC_INTERNAL ); +uint32_t edge_trigger = *gic_bmp_ptr32 (s->edge_trigger, irq -GIC_INTERNAL ); +uint32_t level = *gic_bmp_ptr32 (s->level, irq -GIC_INTERNAL ); +uint32_t group = *gic_bmp_ptr32 (s->group, irq -GIC_INTERNAL ); +uint32_t grpmod = *gic_bmp_ptr32 (s->grpmod, irq -GIC_INTERNAL ); +uint32_t enable = *gic_bmp_ptr32 (s->enabled, irq -GIC_INTERNAL ); +
Quoted 2 lines
Since you use "irq -
GIC_INTERNAL" many times, how about moving into thegic_bmp_ptr32()?
The bmp* functions are supposed to be generic (with APIs matching the bitmap.h ones), so passing it X should give you bit X in the bitmap.
Maybe it would be less confusing to make the bitmaps all have 32 unused bits at the start, so the bit for interrupt X is bit X in the bitmap... That only costs us five words of memory per CPU, so it seems worth it for the code clarity and avoiding annoying bugs.
Quoted 8 lines
Quoted 7 lines
/**
+ *gicv3_irq_group:
+ *
+ * Return the group which this interrupt is configured as (GICV3_G0,
+ *GICV3_G1orGICV3_G1NS).
+ */
+static inline intgicv3_irq_group(GICv3State *s, GICv3CPUState *cs, int irq)use
uint32_tinstead of int in this and other functions?
Neither interrupt numbers nor group numbers are particularly large or specifically 32-bit, so 'int' seemed the most reasonable type to use.
thanks
-- PMM
PATCH 11/23 hw/intc/arm_gicv3: Implement GICv3 distributor registers
In reply to Peter MaydellFrom: Shlomo Pongratz <[email protected]>
Implement the distributor registers of a GICv3.
[PMM: significantly overhauled/rewritten:
* use the new bitmap data structures
* restructure register read/write to handle different width accesses natively, since almost all registers are 32-bit only, rather than implementing everything as byte accesses
* implemented security extension support
]
--- hw/intc/Makefile.objs | 1 + hw/intc/arm_gicv3_dist.c | 841 +++++++++++++++++++++++++++++++++++++++++++++++ hw/intc/gicv3_internal.h | 4 + trace-events | 6 + 4 files changed, 852 insertions(+) create mode 100644 hw/intc/arm_gicv3_dist.c
hw/intc/Makefile.objs +1 -0
@@ -14,6 +14,7 @@ common-obj-$(CONFIG_ARM_GIC) += arm_gic.o common-obj-$(CONFIG_ARM_GIC) += arm_gicv2m.o common-obj-$(CONFIG_ARM_GIC) += arm_gicv3_common.o common-obj-$(CONFIG_ARM_GIC) += arm_gicv3.o +common-obj-$(CONFIG_ARM_GIC) += arm_gicv3_dist.o common-obj-$(CONFIG_OPENPIC) += openpic.o obj-$(CONFIG_APIC) += apic.o apic_common.o
hw/intc/arm_gicv3_dist.c new file +841 -0
841 lines not on this page · raw message
hw/intc/gicv3_internal.h +4 -0
@@ -201,6 +201,10 @@ void gicv3_full_update_noirqset(GICv3State *s);* and inform the CPUs accordingly. */ void gicv3_full_update (GICv3State *s); +MemTxResult gicv3_dist_read (void *opaque,hwaddr offset,uint64_t *data, +unsigned size,MemTxAttrs attrs); +MemTxResult gicv3_dist_write (void *opaque,hwaddr addr,uint64_t data, +unsigned size,MemTxAttrs attrs);/** * gicv3_cpuif_update:
trace-events +6 -0
@@ -1909,3 +1909,9 @@ aspeed_vic_update_fiq(int flags) "Raising FIQ: %d" aspeed_vic_update_irq(int flags) "Raising IRQ: %d" aspeed_vic_read(uint64_t offset, unsigned size, uint32_t value) "From 0x%" PRIx64 " of size %u: 0x%" PRIx32 aspeed_vic_write(uint64_t offset, unsigned size, uint32_t data) "To 0x%" PRIx64 " of size %u: 0x%" PRIx32 + +# hw/intc/arm_gicv3_dist.c +gicv3_dist_read(uint64_t offset, uint64_t data, unsigned size, bool secure) "GICv3 distributor read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u secure %d" +gicv3_dist_badread(uint64_t offset, unsigned size, bool secure) "GICv3 distributor read: offset 0x%" PRIx64 " size %u secure %d: error" +gicv3_dist_write(uint64_t offset, uint64_t data, unsigned size, bool secure) "GICv3 distributor write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u secure %d" +gicv3_dist_badwrite(uint64_t offset, uint64_t data, unsigned size, bool secure) "GICv3 distributor write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u secure %d: error"
Signature · 1 line
1.9.1
Re: [Qemu-arm] [PATCH 11/23] hw/intc/arm_gicv3: Implement GICv3 distributor registers
Quoted 8 lines · Peter Maydell
hw/intc/arm_gicv3_dist.c new file +8
-0+static MemTxResult gicd_writeb (GICv3State *s,hwaddr offset, +uint64_t value,MemTxAttrs attrs) +{ +/* Most GICv3 distributor registers do not support byte accesses. */ +switch (offset) { + case GICD_CPENDSGIR ... GICD_CPENDSGIR + 0xf: + case GICD_SPENDSGIR ... GICD_SPENDSGIR + 0xf: + case GICD_ITARGETSR ... GICD_ITARGETSR + 0x3ff:
hw/intc/arm_gicv3_dist.c line 301
Quoted 10 lines
hw/intc/arm_gicv3_dist.c new file +10
-0+/* This GIC implementation always has affinity routing enabled, +* so these registers are all RAZ/WI. +*/ +return MEMTX_OK ; + case GICD_IPRIORITYR ... GICD_IPRIORITYR + 0x3ff: + { +int irq = offset -GICD_IPRIORITYR ; + +gicd_write_ipriorityr (s, attrs, irq, value); +gicv3_update (s, irq,1 );
The GICv3 SPEC says:
"
When affinity routing is enabled for the security state of an interrupt:
• GICR_IPRIORITYR<n> is used instead of GICD_IPRIORITYR<n> where n = 0 to 7 (that
is, for SGIs and PPIs).
• GICD_IPRIORITYR<n> is RAZ/WI where n = 0 to 7.
"
So I think it shouldn't call gicv3_update if attrs.secure is true and irq < 32. And it should check the parameter irq in gicv3_update().
Quoted 45 lines
hw/intc/arm_gicv3_dist.c new file +45
-0+return MEMTX_OK ; + } +default : +return MEMTX_ERROR ; + } +} + +static MemTxResult gicd_readw (GICv3State *s,hwaddr offset, +uint64_t *data,MemTxAttrs attrs) +{ +/* Only GICD_SETSPI_NSR, GICD_CLRSPI_NSR, GICD_SETSPI_SR and GICD_SETSPI_NSR +* support 16 bit accesses, and those registers are all part of the +* optional message-based SPI feature which this GIC does not currently +* implement (ie for us GICD_TYPER.MBIS == 0), so for us they are +* reserved. +*/ +return MEMTX_ERROR ; +} + +static MemTxResult gicd_writew (GICv3State *s,hwaddr offset, +uint64_t value,MemTxAttrs attrs) +{ +/* Only GICD_SETSPI_NSR, GICD_CLRSPI_NSR, GICD_SETSPI_SR and GICD_SETSPI_NSR +* support 16 bit accesses, and those registers are all part of the +* optional message-based SPI feature which this GIC does not currently +* implement (ie for us GICD_TYPER.MBIS == 0), so for us they are +* reserved. +*/ +return MEMTX_ERROR ; +} + +static MemTxResult gicd_readl (GICv3State *s,hwaddr offset, +uint64_t *data,MemTxAttrs attrs) +{ +/* Almost all GICv3 distributor registers are 32-bit. +* Note that WO registers must return an UNKNOWN value on reads, +* not an abort. +*/ + +switch (offset) { +case GICD_CTLR : +if (!attrs.secure && !(s->gicd_ctlr &GICD_CTLR_DS )) { +/* The NS view of the GICD_CTLR sees only certain bits: +* + bit [31] (RWP) is an alias of the Secure bit [31] +* + bit [4] (ARE_NS) is an alias of Secure bit [5]
hw/intc/arm_gicv3_dist.c line 356
Quoted 10 lines
hw/intc/arm_gicv3_dist.c new file +10
-0+* + bit [1] (EnableGrp1A) is an alias of Secure bit [1] if +* NS affinity routing is enabled, otherwise RES0 +* + bit [0] (EnableGrp1) is an alias of Secure bit [1] if +* NS affinity routing is not enabled, otherwise RES0 +* Since for QEMU affinity routing is always enabled +* for both S and NS this means that bits [4] and [5] are +* both always 1, and we can simply make the NS view +* be bits 31, 4 and 1 of the S view. +*/ + *data = s->gicd_ctlr & (GICD_CTLR_ARE_NS |
As you said, we make the NS view be bit 4 of the S view. So the GICD_CTLR_ARE_NS should be GICD_CTLR_ARE_S, right?
Quoted 6 lines
hw/intc/arm_gicv3_dist.c new file +6
-0+GICD_CTLR_EN_GRP1NS | + GICD_CTLR_RWP); + }else { + *data = s->gicd_ctlr; + } +return MEMTX_OK ;
Signature · 1 line
Shannon
Re: [Qemu-arm] [PATCH 11/23] hw/intc/arm_gicv3: Implement GICv3 distributor registers
Quoted 28 lines · Shannon Zhao
Quoted 8 lines · Peter Maydell
hw/intc/arm_gicv3_dist.c new file +8
-0+static MemTxResult gicd_writeb (GICv3State *s,hwaddr offset, +uint64_t value,MemTxAttrs attrs) +{ +/* Most GICv3 distributor registers do not support byte accesses. */ +switch (offset) { + case GICD_CPENDSGIR ... GICD_CPENDSGIR + 0xf: + case GICD_SPENDSGIR ... GICD_SPENDSGIR + 0xf: + case GICD_ITARGETSR ... GICD_ITARGETSR + 0x3ff:hw/intc/arm_gicv3_dist.c line 301
Quoted 10 lines
hw/intc/arm_gicv3_dist.c new file +10
-0+/* This GIC implementation always has affinity routing enabled, +* so these registers are all RAZ/WI. +*/ +return MEMTX_OK ; + case GICD_IPRIORITYR ... GICD_IPRIORITYR + 0x3ff: + { +int irq = offset -GICD_IPRIORITYR ; + +gicd_write_ipriorityr (s, attrs, irq, value); +gicv3_update (s, irq,1 );The GICv3 SPEC says:
"
When affinity routing is enabled for the security state of an interrupt:
• GICR_IPRIORITYR<n> is used instead of GICD_IPRIORITYR<n> where n = 0 to 7 (that
is, for SGIs and PPIs).
• GICD_IPRIORITYR<n> is RAZ/WI where n = 0 to 7.
"
Quoted 2 lines
So I think it shouldn't call
gicv3_updateif attrs.secure is true and irq < 32. And it should check the parameter irq ingicv3_update().
If irq < 32 then gicd_write_ipriority() will return without doing anything. We'll unnecessarily call gicv3_update(), but that does no harm, and I don't think being slightly inefficient for an access a correctly functioning guest will never make is a big problem.
Quoted 16 lines
Quoted 6 lines
hw/intc/arm_gicv3_dist.c new file +6
-0+switch (offset) { +case GICD_CTLR : +if (!attrs.secure && !(s->gicd_ctlr &GICD_CTLR_DS )) { +/* The NS view of the GICD_CTLR sees only certain bits: +* + bit [31] (RWP) is an alias of the Secure bit [31] +* + bit [4] (ARE_NS) is an alias of Secure bit [5] hw/intc/arm_gicv3_dist.c line 356
Quoted 10 lines
hw/intc/arm_gicv3_dist.c new file +10
-0+* + bit [1] (EnableGrp1A) is an alias of Secure bit [1] if +* NS affinity routing is enabled, otherwise RES0 +* + bit [0] (EnableGrp1) is an alias of Secure bit [1] if +* NS affinity routing is not enabled, otherwise RES0 +* Since for QEMU affinity routing is always enabled +* for both S and NS this means that bits [4] and [5] are +* both always 1, and we can simply make the NS view +* be bits 31, 4 and 1 of the S view. +*/ + *data = s->gicd_ctlr & (GICD_CTLR_ARE_NS |
Quoted 2 lines
As you said, we make the NS view be bit 4 of the S view. So the
GICD_CTLR_ARE_NSshould beGICD_CTLR_ARE_S, right?
Yes, you're right, this should be GICD_CTLR_ARE_S.
Quoted 6 lines
hw/intc/arm_gicv3_dist.c line 362
Quoted 6 lines
hw/intc/arm_gicv3_dist.c new file +6
-0+GICD_CTLR_EN_GRP1NS | + GICD_CTLR_RWP); + }else { + *data = s->gicd_ctlr; + } +return MEMTX_OK ;
thanks
-- PMM
Re: [Qemu-arm] [PATCH 11/23] hw/intc/arm_gicv3: Implement GICv3 distributor registers
Quoted 8 lines · Peter Maydell
Quoted 2 lines · Shannon Zhao
So I think it shouldn't call
gicv3_updateif attrs.secure is true and irq < 32. And it should check the parameter irq ingicv3_update().If irq < 32 then
gicd_write_ipriority()will return without doing anything. We'll unnecessarily callgicv3_update(), but that does no harm, and I don't think being slightly inefficient for an access a correctly functioning guest will never make is a big problem.
Thinking about this again over the weekend I realised you're right, because gicv3_update() doesn't handle out-of-range irq numbers. I need to either make gicv3_update() return doing nothing for out of range IRQs or ensure we don't call it in that case (and add an assert just in case).
thanks
-- PMM
PATCH 12/23 hw/intc/arm_gicv3: Implement GICv3 redistributor registers
In reply to Peter MaydellFrom: Shlomo Pongratz <[email protected]>
Implement the redistributor registers of a GICv3.
[PMM: significantly overhauled/rewritten:
* use the new data structures
* restructure register read/write to handle different width accesses natively, since almost all registers are 32-bit only, rather than implementing everything as byte accesses
* implemented security extension support
]
--- hw/intc/Makefile.objs | 1 + hw/intc/arm_gicv3_redist.c | 495 +++++++++++++++++++++++++++++++++++++++++++++ hw/intc/gicv3_internal.h | 4 + trace-events | 6 + 4 files changed, 506 insertions(+) create mode 100644 hw/intc/arm_gicv3_redist.c
hw/intc/Makefile.objs +1 -0
@@ -15,6 +15,7 @@ common-obj-$(CONFIG_ARM_GIC) += arm_gicv2m.o common-obj-$(CONFIG_ARM_GIC) += arm_gicv3_common.o common-obj-$(CONFIG_ARM_GIC) += arm_gicv3.o common-obj-$(CONFIG_ARM_GIC) += arm_gicv3_dist.o +common-obj-$(CONFIG_ARM_GIC) += arm_gicv3_redist.o common-obj-$(CONFIG_OPENPIC) += openpic.o obj-$(CONFIG_APIC) += apic.o apic_common.o
hw/intc/arm_gicv3_redist.c new file +495 -0
495 lines not on this page · raw message
hw/intc/gicv3_internal.h +4 -0
@@ -205,6 +205,10 @@ MemTxResult gicv3_dist_read(void *opaque, hwaddr offset, uint64_t *data, unsigned size, MemTxAttrs attrs);MemTxResult gicv3_dist_write (void *opaque,hwaddr addr,uint64_t data,unsigned size,MemTxAttrs attrs); +MemTxResult gicv3_redist_read (void *opaque,hwaddr offset,uint64_t *data, +unsigned size,MemTxAttrs attrs); +MemTxResult gicv3_redist_write (void *opaque,hwaddr offset,uint64_t data, +unsigned size,MemTxAttrs attrs);/** * gicv3_cpuif_update:
trace-events +6 -0
@@ -1915,3 +1915,9 @@ gicv3_dist_read(uint64_t offset, uint64_t data, unsigned size, bool secure) "GIC gicv3_dist_badread(uint64_t offset, unsigned size, bool secure) "GICv3 distributor read: offset 0x%" PRIx64 " size %u secure %d: error" gicv3_dist_write(uint64_t offset, uint64_t data, unsigned size, bool secure) "GICv3 distributor write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u secure %d" gicv3_dist_badwrite(uint64_t offset, uint64_t data, unsigned size, bool secure) "GICv3 distributor write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u secure %d: error" + +# hw/intc/arm_gicv3_redist.c +gicv3_redist_read(uint32_t cpu, uint64_t offset, uint64_t data, unsigned size, bool secure) "GICv3 redistributor %x read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u secure %d" +gicv3_redist_badread(uint32_t cpu, uint64_t offset, unsigned size, bool secure) "GICv3 redistributor %x read: offset 0x%" PRIx64 " size %u secure %d: error" +gicv3_redist_write(uint32_t cpu, uint64_t offset, uint64_t data, unsigned size, bool secure) "GICv3 redistributor %x write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u secure %d" +gicv3_redist_badwrite(uint32_t cpu, uint64_t offset, uint64_t data, unsigned size, bool secure) "GICv3 redistributor %x write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u secure %d: error"
Signature · 1 line
1.9.1
PATCH 13/23 hw/intc/arm_gicv3: Wire up distributor and redistributor MMIO regions
In reply to Peter MaydellWire up the MMIO functions exposed by the distributor and the redistributor into MMIO regions exposed by the GICv3 device.
--- hw/intc/arm_gicv3.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
hw/intc/arm_gicv3.c +14 -1
@@ -321,6 +321,19 @@ static void arm_gicv3_post_load(GICv3State *s)gicv3_cache_all_target_cpustates (s); } +static const MemoryRegionOps gic_ops[] = { + { + .read_with_attrs = gicv3_dist_read, + .write_with_attrs = gicv3_dist_write, + .endianness =DEVICE_NATIVE_ENDIAN , + }, + { + .read_with_attrs = gicv3_redist_read, + .write_with_attrs = gicv3_redist_write, + .endianness =DEVICE_NATIVE_ENDIAN , + } +}; +static void arm_gic_realize (DeviceState *dev,Error **errp) {/* Device instance realize function for the GIC sysbus device */
@@ -334,7 +347,7 @@ static void arm_gic_realize(DeviceState *dev, Error **errp)return ; } -gicv3_init_irqs_and_mmio (s, gicv3_set_irq,NULL ); +gicv3_init_irqs_and_mmio (s, gicv3_set_irq, gic_ops); }static void arm_gicv3_class_init (ObjectClass *klass,void *data)
Signature · 1 line
1.9.1
PATCH 14/23 hw/intc/arm_gicv3: Implement gicv3_set_irq()
In reply to Peter MaydellImplement the code which updates the GIC state when an interrupt input into the GIC is asserted.
--- hw/intc/arm_gicv3.c | 20 +++++++++++++++++++- hw/intc/arm_gicv3_dist.c | 21 +++++++++++++++++++++ hw/intc/arm_gicv3_redist.c | 21 +++++++++++++++++++++ hw/intc/gicv3_internal.h | 2 ++ trace-events | 2 ++ 5 files changed, 65 insertions(+), 1 deletion(-)
hw/intc/arm_gicv3.c +19 -1
@@ -308,7 +308,25 @@ static void gicv3_set_irq(void *opaque, int irq, int level)* [N+32..N+63] : PPI (internal interrupts for CPU 1 * ... */ -/* Do nothing for now */ +GICv3State *s = opaque; + +if (irq < (s->num_irq -GIC_INTERNAL )) { +/* external interrupt (SPI) */ +gicv3_dist_set_irq (s, irq +GIC_INTERNAL , level); + }else { +/* per-cpu interrupt (PPI) */ +int cpu; + + irq -= (s->num_irq -GIC_INTERNAL ); + cpu = irq /GIC_INTERNAL ; + irq %=GIC_INTERNAL ; +assert (cpu < s->num_cpu); +/* Raising SGIs via this function would be a bug in how the board +* model wires up interrupts. +*/ +assert (irq >=16 && irq <32 ); +gicv3_redist_set_irq (&s->cpu[cpu], irq, level); + } }static void arm_gicv3_post_load (GICv3State *s)
hw/intc/arm_gicv3_dist.c +21 -0
@@ -839,3 +839,24 @@ MemTxResult gicv3_dist_write(void *opaque, hwaddr offset, uint64_t data, }return r; } + +void gicv3_dist_set_irq (GICv3State *s,int irq,int level) +{ +/* Update distributor state for a change in an external SPI input line */ +if (level ==gicv3_gicd_level_test (s, irq)) { +return ; + } + +trace_gicv3_dist_set_irq (irq, level); + +gicv3_gicd_level_replace (s, irq, level); + +if (level) { +/* 0->1 edges latch the pending bit for edge-triggered interrupts */ +if (gicv3_gicd_edge_trigger_test (s, irq)) { +gicv3_gicd_pending_set (s, irq); + } + } + +gicv3_update (s, irq,1 ); +}
hw/intc/arm_gicv3_redist.c +21 -0
@@ -493,3 +493,24 @@ MemTxResult gicv3_redist_write(void *opaque, hwaddr offset, uint64_t data, }return r; } + +void gicv3_redist_set_irq (GICv3CPUState *cs,int irq,int level) +{ +/* Update redistributor state for a change in an external PPI input line */ +if (level ==extract32 (cs->level, irq,1 )) { +return ; + } + +trace_gicv3_redist_set_irq (gicv3_redist_affid (cs), irq, level); + + cs->level =deposit32 (cs->level, irq,1 , level); + +if (level) { +/* 0->1 edges latch the pending bit for edge-triggered interrupts */ +if (extract32 (cs->edge_trigger, irq,1 )) { + cs->gicr_ipendr0 =deposit32 (cs->gicr_ipendr0, irq,1 ,1 ); + } + } + +gicv3_redist_update (cs); +}
hw/intc/gicv3_internal.h +2 -0
@@ -209,6 +209,8 @@ MemTxResult gicv3_redist_read(void *opaque, hwaddr offset, uint64_t *data, unsigned size, MemTxAttrs attrs);MemTxResult gicv3_redist_write (void *opaque,hwaddr offset,uint64_t data,unsigned size,MemTxAttrs attrs); +void gicv3_dist_set_irq (GICv3State *s,int irq,int level); +void gicv3_redist_set_irq (GICv3CPUState *cs,int irq,int level);/** * gicv3_cpuif_update:
trace-events +2 -0
@@ -1915,9 +1915,11 @@ gicv3_dist_read(uint64_t offset, uint64_t data, unsigned size, bool secure) "GIC gicv3_dist_badread(uint64_t offset, unsigned size, bool secure) "GICv3 distributor read: offset 0x%" PRIx64 " size %u secure %d: error" gicv3_dist_write(uint64_t offset, uint64_t data, unsigned size, bool secure) "GICv3 distributor write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u secure %d" gicv3_dist_badwrite(uint64_t offset, uint64_t data, unsigned size, bool secure) "GICv3 distributor write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u secure %d: error" +gicv3_dist_set_irq(int irq, int level) "GICv3 distributor interrupt %d level changed to %d" # hw/intc/arm_gicv3_redist.c gicv3_redist_read(uint32_t cpu, uint64_t offset, uint64_t data, unsigned size, bool secure) "GICv3 redistributor %x read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u secure %d" gicv3_redist_badread(uint32_t cpu, uint64_t offset, unsigned size, bool secure) "GICv3 redistributor %x read: offset 0x%" PRIx64 " size %u secure %d: error" gicv3_redist_write(uint32_t cpu, uint64_t offset, uint64_t data, unsigned size, bool secure) "GICv3 redistributor %x write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u secure %d" gicv3_redist_badwrite(uint32_t cpu, uint64_t offset, uint64_t data, unsigned size, bool secure) "GICv3 redistributor %x write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u secure %d: error" +gicv3_redist_set_irq(uint32_t cpu, int irq, int level) "GICv3 redistributor %x interrupt %d level changed to %d"
Signature · 1 line
1.9.1
PATCH 15/23 hw/intc/arm_gicv3: Implement GICv3 CPU interface registers
In reply to Peter MaydellImplement the CPU interface registers for the GICv3; these are CPU system registers, not MMIO registers.
This commit implements all the registers which are simple accessors for GIC state, but not those which act as interfaces for acknowledging, dismissing or generating interrupts. (Those will be added in a later commit.)
--- hw/intc/Makefile.objs | 1 + hw/intc/arm_gicv3.c | 2 + hw/intc/arm_gicv3_cpuif.c | 646 ++++++++++++++++++++++++++++++++++++++++++++++ hw/intc/gicv3_internal.h | 1 + trace-events | 16 ++ 5 files changed, 666 insertions(+) create mode 100644 hw/intc/arm_gicv3_cpuif.c
hw/intc/Makefile.objs +1 -0
@@ -35,3 +35,4 @@ obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.o obj-$(CONFIG_S390_FLIC_KVM) += s390_flic_kvm.o obj-$(CONFIG_ASPEED_SOC) += aspeed_vic.o +obj-$(CONFIG_ARM_GIC) += arm_gicv3_cpuif.o
hw/intc/arm_gicv3.c +2 -0
@@ -366,6 +366,8 @@ static void arm_gic_realize(DeviceState *dev, Error **errp) }gicv3_init_irqs_and_mmio (s, gicv3_set_irq, gic_ops); + +gicv3_init_cpuif (s); }static void arm_gicv3_class_init (ObjectClass *klass,void *data)
hw/intc/arm_gicv3_cpuif.c new file +646 -0
646 lines not on this page · raw message
hw/intc/gicv3_internal.h +1 -0
@@ -211,6 +211,7 @@ MemTxResult gicv3_redist_write(void *opaque, hwaddr offset, uint64_t data, unsigned size, MemTxAttrs attrs);void gicv3_dist_set_irq (GICv3State *s,int irq,int level);void gicv3_redist_set_irq (GICv3CPUState *cs,int irq,int level); +void gicv3_init_cpuif (GICv3State *s);/** * gicv3_cpuif_update:
trace-events +16 -0
@@ -1910,6 +1910,22 @@ aspeed_vic_update_irq(int flags) "Raising IRQ: %d" aspeed_vic_read(uint64_t offset, unsigned size, uint32_t value) "From 0x%" PRIx64 " of size %u: 0x%" PRIx32 aspeed_vic_write(uint64_t offset, unsigned size, uint32_t data) "To 0x%" PRIx64 " of size %u: 0x%" PRIx32 +# hw/intc/arm_gicv3_cpuif.c +gicv3_icc_pmr_read(uint32_t cpu, uint64_t val) "GICv3 ICC_PMR read cpu %x value 0x%" PRIx64 +gicv3_icc_pmr_write(uint32_t cpu, uint64_t val) "GICv3 ICC_PMR write cpu %x value 0x%" PRIx64 +gicv3_icc_bpr_read(uint32_t cpu, uint64_t val) "GICv3 ICC_BPR read cpu %x value 0x%" PRIx64 +gicv3_icc_bpr_write(uint32_t cpu, uint64_t val) "GICv3 ICC_BPR write cpu %x value 0x%" PRIx64 +gicv3_icc_ap_read(int regno, uint32_t cpu, uint64_t val) "GICv3 ICC_AP%dR read cpu %x value 0x%" PRIx64 +gicv3_icc_ap_write(int regno, uint32_t cpu, uint64_t val) "GICv3 ICC_AP%dR write cpu %x value 0x%" PRIx64 +gicv3_icc_igrpen_read(uint32_t cpu, uint64_t val) "GICv3 ICC_IGRPEN read cpu %x value 0x%" PRIx64 +gicv3_icc_igrpen_write(uint32_t cpu, uint64_t val) "GICv3 ICC_IGRPEN write cpu %x value 0x%" PRIx64 +gicv3_icc_igrpen1_el3_read(uint32_t cpu, uint64_t val) "GICv3 ICC_IGRPEN1_EL3 read cpu %x value 0x%" PRIx64 +gicv3_icc_igrpen1_el3_write(uint32_t cpu, uint64_t val) "GICv3 ICC_IGRPEN1_EL3 write cpu %x value 0x%" PRIx64 +gicv3_icc_ctlr_read(uint32_t cpu, uint64_t val) "GICv3 ICC_CTLR read cpu %x value 0x%" PRIx64 +gicv3_icc_ctlr_write(uint32_t cpu, uint64_t val) "GICv3 ICC_CTLR write cpu %x value 0x%" PRIx64 +gicv3_icc_ctlr_el3_read(uint32_t cpu, uint64_t val) "GICv3 ICC_CTLR_EL3 read cpu %x value 0x%" PRIx64 +gicv3_icc_ctlr_el3_write(uint32_t cpu, uint64_t val) "GICv3 ICC_CTLR_EL3 write cpu %x value 0x%" PRIx64 + # hw/intc/arm_gicv3_dist.c gicv3_dist_read(uint64_t offset, uint64_t data, unsigned size, bool secure) "GICv3 distributor read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u secure %d" gicv3_dist_badread(uint64_t offset, unsigned size, bool secure) "GICv3 distributor read: offset 0x%" PRIx64 " size %u secure %d: error"
Signature · 1 line
1.9.1
PATCH 16/23 hw/intc/arm_gicv3: Implement gicv3_cpuif_update()
In reply to Peter MaydellImplement the gicv3_cpuif_update() function which deals with correctly asserting IRQ and FIQ based on the current running priority of the CPU, the priority of the highest priority pending interrupt and the CPU's current exception level and security state.
--- hw/intc/arm_gicv3_cpuif.c | 140 +++++++++++++++++++++++++++++++++++++++++++++- hw/intc/gicv3_internal.h | 5 +- trace-events | 2 + 3 files changed, 142 insertions(+), 5 deletions(-)
hw/intc/arm_gicv3_cpuif.c +139 -1
@@ -36,6 +36,142 @@ static bool gicv3_use_ns_bank(CPUARMState *env)return !arm_is_secure_below_el3 (env); } +static int icc_highest_active_prio (GICv3CPUState *cs) +{ +/* Calculate the current running priority based on the set bits +* in the Active Priority Registers. +*/ +int i; + +for (i =0 ; i <ARRAY_SIZE (cs->icc_apr[0 ]); i++) { +uint32_t apr = cs->icc_apr[GICV3_G0 ][i] | + cs->icc_apr[GICV3_G1 ][i] | cs->icc_apr[GICV3_G1NS ][i]; + +if (!apr) { +continue ; + } +return (i *32 +ctz32 (apr)) << (GIC_MIN_BPR +1 ); + } +/* No current active interrupts: return idle priority */ +return 0xff ; +} + +static uint32_t icc_gprio_mask (GICv3CPUState *cs,int group) +{ +/* Return a mask word which clears the subpriority bits from +* a priority value for an interrupt in the specified group. +* This depends on the BPR value: +* a BPR of 0 means the group priority bits are [7:1]; +* a BPR of 1 means they are [7:2], and so on down to +* a BPR of 7 meaning no group priority bits at all. +* Which BPR to use depends on the group of the interrupt and +* the current ICC_CTLR.CBPR settings. +*/ +if ((group ==GICV3_G1 && cs->icc_ctlr_el1[GICV3_S ] &ICC_CTLR_EL1_CBPR ) || + (group ==GICV3_G1NS && + cs->icc_ctlr_el1[GICV3_NS ] &ICC_CTLR_EL1_CBPR )) { + group =GICV3_G0 ; + } + +return ~0U << ((cs->icc_bpr[group] &7 ) +1 ); +} + +static bool icc_no_enabled_hppi (GICv3CPUState *cs) +{ +/* Return true if there is no pending interrupt, or the +* highest priority pending interrupt is in a group which has been +* disabled at the CPU interface by the ICC_IGRPEN* register enable bits. +*/ +return cs->hppi.prio ==0xff || (cs->icc_igrpen[cs->hppi.grp] ==0 ); +} + +static bool icc_hppi_can_preempt (GICv3CPUState *cs) +{ +/* Return true if we have a pending interrupt of sufficient +* priority to preempt. +*/ +int rprio; +uint32_t mask; + +if (icc_no_enabled_hppi (cs)) { +return false; + } + +if (cs->hppi.prio >= cs->icc_pmr_el1) { +/* Priority mask masks this interrupt */ +return false; + } + + rprio =icc_highest_active_prio (cs); +if (rprio ==0xff ) { +/* No currently running interrupt so we can preempt */ +return true; + } + + mask =icc_gprio_mask (cs, cs->hppi.grp); + +/* We only preempt a running interrupt if the pending interrupt's +* group priority is sufficient (the subpriorities are not considered). +*/ +if ((cs->hppi.prio & mask) < (rprio & mask)) { +return true; + } + +return false; +} + +void gicv3_cpuif_update (GICv3CPUState *cs) +{ +/* Tell the CPU about its highest priority pending interrupt */ +int irqlevel =0 ; +int fiqlevel =0 ; +ARMCPU *cpu =ARM_CPU (cs->cpu); +CPUARMState *env = &cpu->env; + +trace_gicv3_cpuif_update (gicv3_redist_affid (cs), cs->hppi.irq, + cs->hppi.grp, cs->hppi.prio); + +if (cs->hppi.grp ==GICV3_G1 && !arm_feature (env,ARM_FEATURE_EL3 )) { +/* If a Security-enabled GIC sends a G1S interrupt to a +* Security-disabled CPU, we must treat it as if it were G0. +*/ + cs->hppi.grp =GICV3_G0 ; + } + +if (icc_hppi_can_preempt (cs)) { +/* We have an interrupt: should we signal it as IRQ or FIQ? +* This is described in the GICv3 spec section 4.6.2. +*/ +bool isfiq; + +switch (cs->hppi.grp) { +case GICV3_G0 : + isfiq = true; +break ; +case GICV3_G1 : + isfiq = (!arm_is_secure (env) || + (arm_current_el (env) ==3 &&arm_el_is_aa64 (env,3 ))); +break ; +case GICV3_G1NS : + isfiq =arm_is_secure (env); +break ; +default : +g_assert_not_reached (); + } + +if (isfiq) { + fiqlevel =1 ; + }else { + irqlevel =1 ; + } + } + +trace_gicv3_cpuif_set_irqs (gicv3_redist_affid (cs), fiqlevel, irqlevel); + +qemu_set_irq (cs->parent_fiq, fiqlevel); +qemu_set_irq (cs->parent_irq, irqlevel); +} +static uint64_t icc_pmr_read (CPUARMState *env,const ARMCPRegInfo *ri) {GICv3CPUState *cs =icc_cs_from_env (env);
@@ -617,7 +753,9 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = {static void gicv3_cpuif_el_change_hook (ARMCPU *cpu,void *opaque) { -/* Do nothing for now. */ +GICv3CPUState *cs = opaque; + +gicv3_cpuif_update (cs); }void gicv3_init_cpuif (GICv3State *s)
hw/intc/gicv3_internal.h +1 -4
@@ -222,10 +222,7 @@ void gicv3_init_cpuif(GICv3State *s);* current running priority or the CPU's current exception level or * security state. */ -static inline void gicv3_cpuif_update (GICv3CPUState *cs) -{ -/* This will be implemented in a later commit. */ -} +void gicv3_cpuif_update (GICv3CPUState *cs);static inline uint32_t gicv3_iidr (void ) {
trace-events +2 -0
@@ -1925,6 +1925,8 @@ gicv3_icc_ctlr_read(uint32_t cpu, uint64_t val) "GICv3 ICC_CTLR read cpu %x valu gicv3_icc_ctlr_write(uint32_t cpu, uint64_t val) "GICv3 ICC_CTLR write cpu %x value 0x%" PRIx64 gicv3_icc_ctlr_el3_read(uint32_t cpu, uint64_t val) "GICv3 ICC_CTLR_EL3 read cpu %x value 0x%" PRIx64 gicv3_icc_ctlr_el3_write(uint32_t cpu, uint64_t val) "GICv3 ICC_CTLR_EL3 write cpu %x value 0x%" PRIx64 +gicv3_cpuif_update(uint32_t cpuid, int irq, int grp, int prio) "GICv3 CPU i/f %x HPPI update: irq %d group %d prio %d" +gicv3_cpuif_set_irqs(uint32_t cpuid, int fiqlevel, int irqlevel) "GICv3 CPU i/f %x HPPI update: setting FIQ %d IRQ %d" # hw/intc/arm_gicv3_dist.c gicv3_dist_read(uint64_t offset, uint64_t data, unsigned size, bool secure) "GICv3 distributor read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u secure %d"
Signature · 1 line
1.9.1
PATCH 17/23 hw/intc/arm_gicv3: Implement CPU i/f SGI generation registers
In reply to Peter MaydellImplement the registers in the GICv3 CPU interface which generate new SGI interrupts.
--- hw/intc/arm_gicv3_cpuif.c | 125 +++++++++++++++++++++++++++++++++++++++++++++ hw/intc/arm_gicv3_redist.c | 40 +++++++++++++++ hw/intc/gicv3_internal.h | 1 + trace-events | 2 + 4 files changed, 168 insertions(+)
hw/intc/arm_gicv3_cpuif.c +125 -0
@@ -331,6 +331,95 @@ static void icc_ap_write(CPUARMState *env, const ARMCPRegInfo *ri,gicv3_cpuif_update (cs); } +static void icc_generate_sgi (CPUARMState *env,GICv3CPUState *cs, +uint64_t value,int grp,bool ns) +{ +GICv3State *s = cs->gic; + +/* Extract Aff3/Aff2/Aff1 and shift into the bottom 24 bits */ +uint64_t aff =extract64 (value,48 ,8 ) <<16 | +extract64 (value,32 ,8 ) <<8 | +extract64 (value,16 ,8 ); +uint32_t targetlist =extract64 (value,0 ,16 ); +uint32_t irq =extract64 (value,24 ,4 ); +bool irm =extract64 (value,40 ,1 ); +int i; + +if (grp ==GICV3_G1 && s->gicd_ctlr &GICD_CTLR_DS ) { +/* If GICD_CTLR.DS == 1, the Distributor treats Secure Group 1 +* interrupts as Group 0 interrupts and must send Secure Group 0 +* interrupts to the target CPUs. +*/ + grp =GICV3_G0 ; + } + +trace_gicv3_icc_generate_sgi (gicv3_redist_affid (cs), irq, irm, + aff, targetlist); + +for (i =0 ; i < s->num_cpu; i++) { +GICv3CPUState *ocs = &s->cpu[i]; + +if (irm) { +/* IRM == 1 : route to all CPUs except self */ +if (cs == ocs) { +continue ; + } + }else { +/* IRM == 0 : route to Aff3.Aff2.Aff1.n for all n in [0..15] +* where the corresponding bit is set in targetlist +*/ +int aff0; + +if (ocs->gicr_typer >>40 != aff) { +continue ; + } + aff0 =extract64 (ocs->gicr_typer,32 ,8 ); +if (aff0 >15 ||extract32 (targetlist, aff0,1 ) ==0 ) { +continue ; + } + } + +/* The redistributor will check against its own GICR_NSACR as needed */ +gicv3_redist_send_sgi (ocs, grp, irq, ns); + } +} + +static void icc_sgi0r_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +/* Generate Secure Group 0 SGI. */ +GICv3CPUState *cs =icc_cs_from_env (env); +bool ns = !arm_is_secure (env); + +icc_generate_sgi (env, cs, value,GICV3_G0 , ns); +} + +static void icc_sgi1r_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +/* Generate Group 1 SGI for the current Security state */ +GICv3CPUState *cs =icc_cs_from_env (env); +int grp; +bool ns = !arm_is_secure (env); + + grp = ns ?GICV3_G1NS :GICV3_G1 ; +icc_generate_sgi (env, cs, value, grp, ns); +} + +static void icc_asgi1r_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +/* Generate Group 1 SGI for the Security state that is not +* the current state +*/ +GICv3CPUState *cs =icc_cs_from_env (env); +int grp; +bool ns = !arm_is_secure (env); + + grp = ns ?GICV3_G1 :GICV3_G1NS ; +icc_generate_sgi (env, cs, value, grp, ns); +} +static uint64_t icc_igrpen_read (CPUARMState *env,const ARMCPRegInfo *ri) {GICv3CPUState *cs =icc_cs_from_env (env);
@@ -673,6 +762,42 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = { .readfn = icc_ap_read, .writefn = icc_ap_write, }, + { .name = "ICC_SGI1R_EL1", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 11, .opc2 = 5, + .type = ARM_CP_IO | ARM_CP_NO_RAW, + .access = PL1_W, .accessfn = gicv3_irqfiq_access, + .writefn = icc_sgi1r_write, + }, + { .name = "ICC_SGI1R", + .cp = 15, .opc1 = 0, .crm = 12, + .type = ARM_CP_64BIT | ARM_CP_IO | ARM_CP_NO_RAW, + .access = PL1_W, .accessfn = gicv3_irqfiq_access, + .writefn = icc_sgi1r_write, + }, + { .name = "ICC_ASGI1R_EL1", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 11, .opc2 = 6, + .type = ARM_CP_IO | ARM_CP_NO_RAW, + .access = PL1_W, .accessfn = gicv3_irqfiq_access, + .writefn = icc_asgi1r_write, + }, + { .name = "ICC_ASGI1R", + .cp = 15, .opc1 = 1, .crm = 12, + .type = ARM_CP_64BIT | ARM_CP_IO | ARM_CP_NO_RAW, + .access = PL1_W, .accessfn = gicv3_irqfiq_access, + .writefn = icc_asgi1r_write, + }, + { .name = "ICC_SGI0R_EL1", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 11, .opc2 = 7, + .type = ARM_CP_IO | ARM_CP_NO_RAW, + .access = PL1_W, .accessfn = gicv3_irqfiq_access, + .writefn = icc_sgi0r_write, + }, + { .name = "ICC_SGI0R", + .cp = 15, .opc1 = 2, .crm = 12, + .type = ARM_CP_64BIT | ARM_CP_IO | ARM_CP_NO_RAW, + .access = PL1_W, .accessfn = gicv3_irqfiq_access, + .writefn = icc_sgi0r_write, + }, /* This register is banked */ { .name = "ICC_BPR1_EL1", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 12, .opc2 = 3,
hw/intc/arm_gicv3_redist.c +40 -0
@@ -27,6 +27,13 @@ static uint32_t mask_group(GICv3CPUState *cs, MemTxAttrs attrs)return 0xFFFFFFFFU ; } +static int gicr_ns_access (GICv3CPUState *cs,int irq) +{ +/* Return the 2 bit NSACR.NS_access field for this SGI */ +assert (irq <16 ); +return extract32 (cs->gicr_nsacr, irq *2 ,2 ); +} +static void gicr_write_set_bitmap_reg (GICv3CPUState *cs,MemTxAttrs attrs,uint32_t *reg,uint32_t val) {
@@ -514,3 +521,36 @@ void gicv3_redist_set_irq(GICv3CPUState *cs, int irq, int level)gicv3_redist_update (cs); } + +void gicv3_redist_send_sgi (GICv3CPUState *cs,int grp,int irq,bool ns) +{ +/* Update redistributor state for a generated SGI */ +int irqgrp =gicv3_irq_group (cs->gic, cs, irq); + +/* If we are asked for a Secure Group 1 SGI and it's actually +* configured as Secure Group 0 this is OK (subject to the usual +* NSACR checks). +*/ +if (grp ==GICV3_G1 && irqgrp ==GICV3_G0 ) { + grp =GICV3_G0 ; + } + +if (grp != irqgrp) { +return ; + } + +if (ns && !(cs->gic->gicd_ctlr &GICD_CTLR_DS )) { +/* If security is enabled we must test the NSACR bits */ +int nsaccess =gicr_ns_access (cs, irq); + +if ((irqgrp ==GICV3_G0 && nsaccess <1 ) || + (irqgrp ==GICV3_G1 && nsaccess <2 )) { +return ; + } + } + +/* OK, we can accept the SGI */ +trace_gicv3_redist_send_sgi (gicv3_redist_affid (cs), irq); + cs->gicr_ipendr0 =deposit32 (cs->gicr_ipendr0, irq,1 ,1 ); +gicv3_redist_update (cs); +}
hw/intc/gicv3_internal.h +1 -0
@@ -211,6 +211,7 @@ MemTxResult gicv3_redist_write(void *opaque, hwaddr offset, uint64_t data, unsigned size, MemTxAttrs attrs);void gicv3_dist_set_irq (GICv3State *s,int irq,int level);void gicv3_redist_set_irq (GICv3CPUState *cs,int irq,int level); +void gicv3_redist_send_sgi (GICv3CPUState *cs,int grp,int irq,bool ns);void gicv3_init_cpuif (GICv3State *s);/**
trace-events +2 -0
@@ -1927,6 +1927,7 @@ gicv3_icc_ctlr_el3_read(uint32_t cpu, uint64_t val) "GICv3 ICC_CTLR_EL3 read cpu gicv3_icc_ctlr_el3_write(uint32_t cpu, uint64_t val) "GICv3 ICC_CTLR_EL3 write cpu %x value 0x%" PRIx64 gicv3_cpuif_update(uint32_t cpuid, int irq, int grp, int prio) "GICv3 CPU i/f %x HPPI update: irq %d group %d prio %d" gicv3_cpuif_set_irqs(uint32_t cpuid, int fiqlevel, int irqlevel) "GICv3 CPU i/f %x HPPI update: setting FIQ %d IRQ %d" +gicv3_icc_generate_sgi(uint32_t cpuid, int irq, int irm, uint32_t aff, uint32_t targetlist) "GICv3 CPU i/f %x generating SGI %d IRM %d target affinity 0x%xxx targetlist 0x%x" # hw/intc/arm_gicv3_dist.c gicv3_dist_read(uint64_t offset, uint64_t data, unsigned size, bool secure) "GICv3 distributor read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u secure %d"
@@ -1941,3 +1942,4 @@ gicv3_redist_badread(uint32_t cpu, uint64_t offset, unsigned size, bool secure) gicv3_redist_write(uint32_t cpu, uint64_t offset, uint64_t data, unsigned size, bool secure) "GICv3 redistributor %x write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u secure %d" gicv3_redist_badwrite(uint32_t cpu, uint64_t offset, uint64_t data, unsigned size, bool secure) "GICv3 redistributor %x write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u secure %d: error" gicv3_redist_set_irq(uint32_t cpu, int irq, int level) "GICv3 redistributor %x interrupt %d level changed to %d" +gicv3_redist_send_sgi(uint32_t cpu, int irq) "GICv3 redistributor %x pending SGI %d"
Signature · 1 line
1.9.1
PATCH 18/23 hw/intc/arm_gicv3: Add IRQ handling CPU interface registers
In reply to Peter MaydellAdd the CPU interface registers which deal with acknowledging and dismissing interrupts.
--- hw/intc/arm_gicv3_cpuif.c | 436 ++++++++++++++++++++++++++++++++++++++++++++++ hw/intc/gicv3_internal.h | 5 + trace-events | 7 + 3 files changed, 448 insertions(+)
hw/intc/arm_gicv3_cpuif.c +436 -0
@@ -219,6 +219,296 @@ static void icc_pmr_write(CPUARMState *env, const ARMCPRegInfo *ri,gicv3_cpuif_update (cs); } +static void icc_activate_irq (GICv3CPUState *cs,int irq) +{ +/* Move the interrupt from the Pending state to Active, and update +* the Active Priority Registers +*/ +uint32_t mask =icc_gprio_mask (cs, cs->hppi.grp); +int prio = cs->hppi.prio & mask; +int aprbit = prio >>1 ; +int regno = aprbit /32 ; +int regbit = aprbit %32 ; + + cs->icc_apr[cs->hppi.grp][regno] |= (1 << regbit); + +if (irq <GIC_INTERNAL ) { + cs->gicr_iactiver0 =deposit32 (cs->gicr_iactiver0, irq,1 ,1 ); + cs->gicr_ipendr0 =deposit32 (cs->gicr_ipendr0, irq,1 ,0 ); + }else { +gicv3_gicd_active_set (cs->gic, irq); +gicv3_gicd_pending_clear (cs->gic, irq); + } +gicv3_update (cs->gic, irq,1 ); +} + +static uint64_t icc_hppir0_value (GICv3CPUState *cs,CPUARMState *env) +{ +/* Return the highest priority pending interrupt register value +* for group 0. +*/ +bool irq_is_secure; + +if (cs->hppi.prio ==0xff ) { +return INTID_SPURIOUS ; + } + +/* Check whether we can return the interrupt or if we should return +* a special identifier, as per the CheckGroup0ForSpecialIdentifiers +* pseudocode. (We can simplify a little because for us ICC_SRE_EL1.RM +* is always zero.) +*/ + irq_is_secure = (!(cs->gic->gicd_ctlr &GICD_CTLR_DS ) && + (cs->hppi.grp !=GICV3_G1NS )); + +if (cs->hppi.grp !=GICV3_G0 && !arm_is_el3_or_mon (env)) { +return INTID_SPURIOUS ; + } +if (irq_is_secure && !arm_is_secure (env)) { +/* Secure interrupts not visible to Nonsecure */ +return INTID_SPURIOUS ; + } + +if (cs->hppi.grp !=GICV3_G0 ) { +/* Indicate to EL3 that there's a Group 1 interrupt for the other +* state pending. +*/ +return irq_is_secure ?INTID_SECURE :INTID_NONSECURE ; + } + +return cs->hppi.irq; +} + +static uint64_t icc_hppir1_value (GICv3CPUState *cs,CPUARMState *env) +{ +/* Return the highest priority pending interrupt register value +* for group 1. +*/ +bool irq_is_secure; + +if (cs->hppi.prio ==0xff ) { +return INTID_SPURIOUS ; + } + +/* Check whether we can return the interrupt or if we should return +* a special identifier, as per the CheckGroup1ForSpecialIdentifiers +* pseudocode. (We can simplify a little because for us ICC_SRE_EL1.RM +* is always zero.) +*/ + irq_is_secure = (!(cs->gic->gicd_ctlr &GICD_CTLR_DS ) && + (cs->hppi.grp !=GICV3_G1NS )); + +if (cs->hppi.grp ==GICV3_G0 ) { +/* Group 0 interrupts not visible via HPPIR1 */ +return INTID_SPURIOUS ; + } +if (irq_is_secure) { +if (!arm_is_secure (env)) { +/* Secure interrupts not visible in Non-secure */ +return INTID_SPURIOUS ; + } + }else if (!arm_is_el3_or_mon (env) &&arm_is_secure (env)) { +/* Group 1 non-secure interrupts not visible in Secure EL1 */ +return INTID_SPURIOUS ; + } + +return cs->hppi.irq; +} + +static uint64_t icc_iar0_read (CPUARMState *env,const ARMCPRegInfo *ri) +{ +GICv3CPUState *cs =icc_cs_from_env (env); +uint64_t intid; + +if (!icc_hppi_can_preempt (cs)) { + intid =INTID_SPURIOUS ; + }else { + intid =icc_hppir0_value (cs, env); + } + +if (!(intid >=INTID_SECURE && intid <=INTID_SPURIOUS )) { +icc_activate_irq (cs, intid); + } + +trace_gicv3_icc_iar0_read (gicv3_redist_affid (cs), intid); +return intid; +} + +static uint64_t icc_iar1_read (CPUARMState *env,const ARMCPRegInfo *ri) +{ +GICv3CPUState *cs =icc_cs_from_env (env); +uint64_t intid; + +if (!icc_hppi_can_preempt (cs)) { + intid =INTID_SPURIOUS ; + }else { + intid =icc_hppir1_value (cs, env); + } + +if (!(intid >=INTID_SECURE && intid <=INTID_SPURIOUS )) { +icc_activate_irq (cs, intid); + } + +trace_gicv3_icc_iar1_read (gicv3_redist_affid (cs), intid); +return intid; +} + +static void icc_drop_prio (GICv3CPUState *cs,int grp) +{ +/* Drop the priority of the currently active interrupt in +* the specified group. +* +* Note that we can guarantee (because of the requirement to nest +* ICC_IAR reads [which activate an interrupt and raise priority] +* with ICC_EOIR writes [which drop the priority for the interrupt]) +* that the interrupt we're being called for is the highest priority +* active interrupt, meaning that it has the lowest set bit in the +* APR registers. +* +* If the guest does not honour the ordering constraints then the +* behaviour of the GIC is UNPREDICTABLE, which for us means that +* the values of the APR registers might become incorrect and the +* running priority will be wrong, so interrupts that should preempt +* might not do so, and interrupts that should not preempt might do so. +*/ +int i; + +for (i =0 ; i <ARRAY_SIZE (cs->icc_apr[grp]); i++) { +uint64_t *papr = &cs->icc_apr[grp][i]; + +if (!*papr) { +continue ; + } +/* Clear the lowest set bit */ + *papr &= *papr -1 ; +break ; + } + +/* running priority change means we need an update for this cpu i/f */ +gicv3_cpuif_update (cs); +} + +static bool icc_eoi_split (CPUARMState *env,GICv3CPUState *cs) +{ +/* Return true if we should split priority drop and interrupt +* deactivation, ie whether the relevant EOIMode bit is set. +*/ +if (arm_is_el3_or_mon (env)) { +return cs->icc_ctlr_el3 &ICC_CTLR_EL3_EOIMODE_EL3 ; + } +if (arm_is_secure_below_el3 (env)) { +return cs->icc_ctlr_el1[GICV3_S ] &ICC_CTLR_EL1_EOIMODE ; + }else { +return cs->icc_ctlr_el1[GICV3_NS ] &ICC_CTLR_EL1_EOIMODE ; + } +} + +static int icc_highest_active_group (GICv3CPUState *cs) +{ +/* Return the group with the highest priority active interrupt. +* We can do this by just comparing the APRs to see which one +* has the lowest set bit. +* (If more than one group is active at the same priority then +* we're in UNPREDICTABLE territory.) +*/ +int i; + +for (i =0 ; i <ARRAY_SIZE (cs->icc_apr[0 ]); i++) { +int g0ctz =ctz32 (cs->icc_apr[GICV3_G0 ][i]); +int g1ctz =ctz32 (cs->icc_apr[GICV3_G1 ][i]); +int g1nsctz =ctz32 (cs->icc_apr[GICV3_G1NS ][i]); + +if (g1nsctz < g0ctz && g1nsctz < g1ctz) { +return GICV3_G1NS ; + } +if (g1ctz < g0ctz) { +return GICV3_G1 ; + } +if (g0ctz <32 ) { +return GICV3_G0 ; + } + } +/* No set active bits? UNPREDICTABLE; return -1 so the caller +* ignores the spurious EOI attempt. +*/ +return -1 ; +} + +static void icc_deactivate_irq (GICv3CPUState *cs,int irq) +{ +if (irq <GIC_INTERNAL ) { + cs->gicr_iactiver0 =deposit32 (cs->gicr_iactiver0, irq,1 ,0 ); +gicv3_redist_update (cs); + }else { +gicv3_gicd_active_clear (cs->gic, irq); +gicv3_update (cs->gic, irq,1 ); + } +} + +static void icc_eoir_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +/* End of Interrupt */ +GICv3CPUState *cs =icc_cs_from_env (env); +int irq = value &0xffffff ; +int grp; + +trace_gicv3_icc_eoir_write (gicv3_redist_affid (cs), value); + +if (ri->crm ==8 ) { +/* EOIR0 */ + grp =GICV3_G0 ; + }else { +/* EOIR1 */ +if (arm_is_secure (env)) { + grp =GICV3_G1 ; + }else { + grp =GICV3_G1NS ; + } + } + +if (irq >= cs->gic->num_irq) { +/* This handles two cases: +* 1. If software writes the ID of a spurious interrupt [ie 1020-1023] +* to the GICC_EOIR, the GIC ignores that write. +* 2. If software writes the number of a non-existent interrupt +* this must be a subcase of "value written does not match the last +* valid interrupt value read from the Interrupt Acknowledge +* register" and so this is UNPREDICTABLE. We choose to ignore it. +*/ +return ; + } + +if (icc_highest_active_group (cs) != grp) { +return ; + } + +icc_drop_prio (cs, grp); + +if (!icc_eoi_split (env, cs)) { +/* Priority drop and deactivate not split: deactivate irq now */ +icc_deactivate_irq (cs, irq); + } +} + +static uint64_t icc_hppir0_read (CPUARMState *env,const ARMCPRegInfo *ri) +{ +GICv3CPUState *cs =icc_cs_from_env (env); +uint64_t value =icc_hppir0_value (cs, env); + +trace_gicv3_icc_hppir0_read (gicv3_redist_affid (cs), value); +return value; +} + +static uint64_t icc_hppir1_read (CPUARMState *env,const ARMCPRegInfo *ri) +{ +GICv3CPUState *cs =icc_cs_from_env (env); +uint64_t value =icc_hppir1_value (cs, env); + +trace_gicv3_icc_hppir1_read (gicv3_redist_affid (cs), value); +return value; +} +static uint64_t icc_bpr_read (CPUARMState *env,const ARMCPRegInfo *ri) {GICv3CPUState *cs =icc_cs_from_env (env);
@@ -331,6 +621,104 @@ static void icc_ap_write(CPUARMState *env, const ARMCPRegInfo *ri,gicv3_cpuif_update (cs); } +static void icc_dir_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +/* Deactivate interrupt */ +GICv3CPUState *cs =icc_cs_from_env (env); +int irq = value &0xffffff ; +bool irq_is_secure, single_sec_state, irq_is_grp0; +bool route_fiq_to_el3, route_irq_to_el3, route_fiq_to_el2, route_irq_to_el2; + +trace_gicv3_icc_dir_write (gicv3_redist_affid (cs), value); + +if (irq >= cs->gic->num_irq) { +/* Also catches special interrupt numbers and LPIs */ +return ; + } + +if (!icc_eoi_split (env, cs)) { +return ; + } + +int grp =gicv3_irq_group (cs->gic, cs, irq); + + single_sec_state = cs->gic->gicd_ctlr &GICD_CTLR_DS ; + irq_is_secure = !single_sec_state && (grp !=GICV3_G1NS ); + irq_is_grp0 = grp ==GICV3_G0 ; + +/* Check whether we're allowed to deactivate this interrupt based +* on its group and the current CPU state. +* These checks are laid out to correspond to the spec's pseudocode. +*/ + route_fiq_to_el3 = env->cp15.scr_el3 &SCR_FIQ ; + route_irq_to_el3 = env->cp15.scr_el3 &SCR_IRQ ; +/* No need to include !IsSecure in route_*_to_el2 as it's only +* tested in cases where we know !IsSecure is true. +*/ + route_fiq_to_el2 = env->cp15.hcr_el2 &HCR_FMO ; + route_irq_to_el2 = env->cp15.hcr_el2 &HCR_FMO ; + +switch (arm_current_el (env)) { +case 3 : +break ; +case 2 : +if (single_sec_state && irq_is_grp0 && !route_fiq_to_el3) { +break ; + } +if (!irq_is_secure && !irq_is_grp0 && !route_irq_to_el3) { +break ; + } +return ; +case 1 : +if (!arm_is_secure_below_el3 (env)) { +if (single_sec_state && irq_is_grp0 && + !route_fiq_to_el3 && !route_fiq_to_el2) { +break ; + } +if (!irq_is_secure && !irq_is_grp0 && + !route_irq_to_el3 && !route_irq_to_el2) { +break ; + } + }else { +if (irq_is_grp0 && !route_fiq_to_el3) { +break ; + } +if (!irq_is_grp0 && + (!irq_is_secure || !single_sec_state) && + !route_irq_to_el3) { +break ; + } + } +return ; +default : +g_assert_not_reached (); + } + +icc_deactivate_irq (cs, irq); +} + +static uint64_t icc_rpr_read (CPUARMState *env,const ARMCPRegInfo *ri) +{ +GICv3CPUState *cs =icc_cs_from_env (env); +int prio =icc_highest_active_prio (cs); + +if (arm_feature (env,ARM_FEATURE_EL3 ) && + !arm_is_secure (env) && (env->cp15.scr_el3 &SCR_FIQ )) { +/* NS GIC access and Group 0 is inaccessible to NS */ +if (prio &0x80 ) { +/* NS mustn't see priorities in the Secure half of the range */ + prio =0 ; + }else if (prio !=0xff ) { +/* Non-idle priority: show the Non-secure view of it */ + prio = (prio <<1 ) &0xff ; + } + } + +trace_gicv3_icc_rpr_read (gicv3_redist_affid (cs), prio); +return prio; +} +static void icc_generate_sgi (CPUARMState *env,GICv3CPUState *cs,uint64_t value,int grp,bool ns) {
@@ -698,6 +1086,24 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = {*/ .resetfn = icc_reset, }, + { .name = "ICC_IAR0_EL1", .state = ARM_CP_STATE_BOTH, + .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 8, .opc2 = 0, + .type = ARM_CP_IO | ARM_CP_NO_RAW, + .access = PL1_R, .accessfn = gicv3_fiq_access, + .readfn = icc_iar0_read, + }, + { .name = "ICC_EOIR0_EL1", .state = ARM_CP_STATE_BOTH, + .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 8, .opc2 = 1, + .type = ARM_CP_IO | ARM_CP_NO_RAW, + .access = PL1_W, .accessfn = gicv3_fiq_access, + .writefn = icc_eoir_write, + }, + { .name = "ICC_HPPIR0_EL1", .state = ARM_CP_STATE_BOTH, + .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 8, .opc2 = 2, + .type = ARM_CP_IO | ARM_CP_NO_RAW, + .access = PL1_R, .accessfn = gicv3_fiq_access, + .readfn = icc_hppir0_read, + }, { .name = "ICC_BPR0_EL1", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 8, .opc2 = 3, .type = ARM_CP_IO | ARM_CP_NO_RAW,
@@ -762,6 +1168,18 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = { .readfn = icc_ap_read, .writefn = icc_ap_write, }, + { .name = "ICC_DIR_EL1", .state = ARM_CP_STATE_BOTH, + .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 11, .opc2 = 1, + .type = ARM_CP_IO | ARM_CP_NO_RAW, + .access = PL1_W, .accessfn = gicv3_irqfiq_access, + .writefn = icc_dir_write, + }, + { .name = "ICC_RPR_EL1", .state = ARM_CP_STATE_BOTH, + .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 11, .opc2 = 3, + .type = ARM_CP_IO | ARM_CP_NO_RAW, + .access = PL1_R, .accessfn = gicv3_irqfiq_access, + .readfn = icc_rpr_read, + }, { .name = "ICC_SGI1R_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 11, .opc2 = 5, .type = ARM_CP_IO | ARM_CP_NO_RAW,
@@ -798,6 +1216,24 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = { .access = PL1_W, .accessfn = gicv3_irqfiq_access, .writefn = icc_sgi0r_write, }, + { .name = "ICC_IAR1_EL1", .state = ARM_CP_STATE_BOTH, + .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 12, .opc2 = 0, + .type = ARM_CP_IO | ARM_CP_NO_RAW, + .access = PL1_R, .accessfn = gicv3_irq_access, + .readfn = icc_iar1_read, + }, + { .name = "ICC_EOIR1_EL1", .state = ARM_CP_STATE_BOTH, + .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 12, .opc2 = 1, + .type = ARM_CP_IO | ARM_CP_NO_RAW, + .access = PL1_W, .accessfn = gicv3_irq_access, + .writefn = icc_eoir_write, + }, + { .name = "ICC_HPPIR1_EL1", .state = ARM_CP_STATE_BOTH, + .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 12, .opc2 = 2, + .type = ARM_CP_IO | ARM_CP_NO_RAW, + .access = PL1_R, .accessfn = gicv3_irq_access, + .readfn = icc_hppir1_read, + }, /* This register is banked */ { .name = "ICC_BPR1_EL1", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 12, .opc2 = 3,
hw/intc/gicv3_internal.h +5 -0
@@ -159,6 +159,11 @@#define ICC_CTLR_EL3_A3V (1U << 15)#define ICC_CTLR_EL3_NDS (1U << 17) +/* Special interrupt IDs */ +#define INTID_SECURE 1020 +#define INTID_NONSECURE 1021 +#define INTID_SPURIOUS 1023 +/* Functions internal to the emulated GICv3 */ /**
trace-events +7 -0
@@ -1928,6 +1928,13 @@ gicv3_icc_ctlr_el3_write(uint32_t cpu, uint64_t val) "GICv3 ICC_CTLR_EL3 write c gicv3_cpuif_update(uint32_t cpuid, int irq, int grp, int prio) "GICv3 CPU i/f %x HPPI update: irq %d group %d prio %d" gicv3_cpuif_set_irqs(uint32_t cpuid, int fiqlevel, int irqlevel) "GICv3 CPU i/f %x HPPI update: setting FIQ %d IRQ %d" gicv3_icc_generate_sgi(uint32_t cpuid, int irq, int irm, uint32_t aff, uint32_t targetlist) "GICv3 CPU i/f %x generating SGI %d IRM %d target affinity 0x%xxx targetlist 0x%x" +gicv3_icc_iar0_read(uint32_t cpu, uint64_t val) "GICv3 ICC_IAR0 read cpu %x value 0x%" PRIx64 +gicv3_icc_iar1_read(uint32_t cpu, uint64_t val) "GICv3 ICC_IAR1 read cpu %x value 0x%" PRIx64 +gicv3_icc_eoir_write(uint32_t cpu, uint64_t val) "GICv3 ICC_EOIR write cpu %x value 0x%" PRIx64 +gicv3_icc_hppir0_read(uint32_t cpu, uint64_t val) "GICv3 ICC_HPPIR0 read cpu %x value 0x%" PRIx64 +gicv3_icc_hppir1_read(uint32_t cpu, uint64_t val) "GICv3 ICC_HPPIR1 read cpu %x value 0x%" PRIx64 +gicv3_icc_dir_write(uint32_t cpu, uint64_t val) "GICv3 ICC_DIR write cpu %x value 0x%" PRIx64 +gicv3_icc_rpr_read(uint32_t cpu, uint64_t val) "GICv3 ICC_RPR read cpu %x value 0x%" PRIx64 # hw/intc/arm_gicv3_dist.c gicv3_dist_read(uint64_t offset, uint64_t data, unsigned size, bool secure) "GICv3 distributor read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u secure %d"
Signature · 1 line
1.9.1
PATCH 19/23 target-arm/machine.c: Allow user to request GICv3 emulation
In reply to Peter MaydellNow we have an emulated GICv3, remove the restriction in gicv3_class_name() so that the user can request a GICv3 with -machine gic-version=3 even when not using KVM.
--- target-arm/machine.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
target-arm/machine.c +1 -2
@@ -339,8 +339,7 @@ const char *gicv3_class_name(void) "platform");#endif }else { -/* TODO: Software emulation is not implemented yet */ -error_report ("KVM is currently required for GICv3 emulation" ); +return "arm-gicv3" ; }exit (1 );
Signature · 1 line
1.9.1
PATCH 20/23 target-arm/monitor.c: Advertise emulated GICv3 in capabilities
In reply to Peter MaydellNow we have an emulated GICv3 we should advertise it via the capabilities in the monitor protocol.
--- target-arm/monitor.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
target-arm/monitor.c +1 -2
@@ -72,8 +72,7 @@ GICCapabilityList *qmp_query_gic_capabilities(Error **errp)GICCapability *v2 =gic_cap_new (2 ), *v3 =gic_cap_new (3 ); v2->emulated = true; -/* TODO: we'd change to true after we get emulated GICv3. */ - v3->emulated = false; + v3->emulated = true;gic_cap_kvm_probe (v2, v3);
Signature · 1 line
1.9.1
PATCH 21/23 hw/intc/arm_gicv3: Work around Linux assuming interrupts are group 1
In reply to Peter MaydellThe Linux kernel's GICv3 driver assumes that all interrupts are in group 1. This is correct if the system supports the Security extensions, because in that case the kernel cannot configure the interrupts and it must have been done already by firmware. However if the system does not support the Security extensions then the kernel is perfectly capable of configuring them into group 1 itself if it wants them there; it just doesn't.
Work around this by having the GICv3 emulation put all the interrupts into group 1 if we're directly booting a Linux kernel, whether the Security extensions are supported or not.
--- hw/intc/arm_gicv3_common.c | 7 +++++++ 1 file changed, 7 insertions(+)
hw/intc/arm_gicv3_common.c +7 -0
@@ -288,6 +288,13 @@ static void arm_gic_common_linux_init(ARMLinuxBootIf *obj,* equivalent). */ s->irq_reset_nonsecure = true; + }else { +/* This is purely a workaround for broken Linux kernel behaviour +* on non-TrustZone systems. It assumes that interrupts have been +* set to group 1 even though it could do that itself for a non-secure +* GIC. +*/ + s->irq_reset_nonsecure = true; } }
Signature · 1 line
1.9.1
PATCH 22/23 NOT-FOR-UPSTREAM: kernel: Add definitions for GICv3 attributes
In reply to Peter MaydellFrom: Pavel Fedin <[email protected]>
This temporary patch adds kernel API definitions. Use proper header update procedure after these features are released.
FIXME: not-for-upstream
--- linux-headers/asm-arm64/kvm.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
linux-headers/asm-arm64/kvm.h +13 -4
@@ -180,14 +180,14 @@ struct kvm_arch_memory_slot { KVM_REG_ARM64_SYSREG_ ## n ## _MASK)#define __ARM64_SYS_REG (op0,op1,crn,crm,op2) \ - (KVM_REG_ARM64 | KVM_REG_ARM64_SYSREG | \ - ARM64_SYS_REG_SHIFT_MASK(op0, OP0) | \ + (ARM64_SYS_REG_SHIFT_MASK(op0, OP0) | \ ARM64_SYS_REG_SHIFT_MASK(op1, OP1) | \ ARM64_SYS_REG_SHIFT_MASK(crn, CRN) | \ ARM64_SYS_REG_SHIFT_MASK(crm, CRM) | \ ARM64_SYS_REG_SHIFT_MASK(op2, OP2)) -#define ARM64_SYS_REG (...) (__ARM64_SYS_REG(__VA_ARGS__) | KVM_REG_SIZE_U64) +#define ARM64_SYS_REG (...) (__ARM64_SYS_REG(__VA_ARGS__) | KVM_REG_ARM64 | \ + KVM_REG_SIZE_U64 | KVM_REG_ARM64_SYSREG)#define KVM_REG_ARM_TIMER_CTL ARM64_SYS_REG(3, 3, 14, 3, 1)#define KVM_REG_ARM_TIMER_CNT ARM64_SYS_REG(3, 3, 14, 3, 2)
@@ -198,12 +198,21 @@ struct kvm_arch_memory_slot {#define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1#define KVM_DEV_ARM_VGIC_GRP_CPU_REGS 2#define KVM_DEV_ARM_VGIC_CPUID_SHIFT 32 -#define KVM_DEV_ARM_VGIC_CPUID_MASK (0xffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT) +#define KVM_DEV_ARM_VGIC_CPUID_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT)#define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0#define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT)#define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3#define KVM_DEV_ARM_VGIC_GRP_CTRL 4#define KVM_DEV_ARM_VGIC_CTRL_INIT 0 +#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5 +#define KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 6 +#define KVM_DEV_ARM_VGIC_SYSREG_MASK (KVM_REG_ARM64_SYSREG_OP0_MASK | \ + KVM_REG_ARM64_SYSREG_OP1_MASK | \ + KVM_REG_ARM64_SYSREG_CRN_MASK | \ + KVM_REG_ARM64_SYSREG_CRM_MASK | \ + KVM_REG_ARM64_SYSREG_OP2_MASK) +#define KVM_DEV_ARM_VGIC_SYSREG (op0,op1,crn,crm,op2) \ + __ARM64_SYS_REG(op0,op1,crn,crm,op2)/* Device Control API on vcpu fd */ #define KVM_ARM_VCPU_PMU_V3_CTRL 0
Signature · 1 line
1.9.1
PATCH 23/23 RFC: hw/intc/arm_gicv3_kvm: Implement get/put functions
In reply to Peter MaydellFrom: Pavel Fedin <[email protected]>
This actually implements pre_save and post_load methods for in-kernel vGICv3.
[PMM:
* use decimal, not 0bnnn
* fixed typo in names of ICC_APR0R_EL1 and ICC_AP1R_EL1
* completely rearranged the get and put functions to read and write the state in a natural order, rather than mixing distributor and redistributor state together]
FIXME: the kernel API is not final yet, so this can't be committed yet.
--- hw/intc/arm_gicv3_kvm.c | 452 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 442 insertions(+), 10 deletions(-)
hw/intc/arm_gicv3_kvm.c +442 -10
@@ -23,8 +23,11 @@#include "qapi/error.h" #include "hw/intc/arm_gicv3_common.h" #include "hw/sysbus.h" +#include "migration/migration.h" +#include "qemu/error-report.h" #include "sysemu/kvm.h" #include "kvm_arm.h" +#include "gicv3_internal.h" #include "vgic_common.h" #ifdef DEBUG_GICV3_KVM
@@ -43,6 +46,23 @@#define KVM_ARM_GICV3_GET_CLASS (obj) \ OBJECT_GET_CLASS(KVMARMGICv3Class, (obj), TYPE_KVM_ARM_GICV3) +#define ICC_PMR_EL1 \ + KVM_DEV_ARM_VGIC_SYSREG(3, 0, 4, 6, 0) +#define ICC_BPR0_EL1 \ + KVM_DEV_ARM_VGIC_SYSREG(3, 0, 12, 8, 3) +#define ICC_AP0R_EL1 (n) \ + KVM_DEV_ARM_VGIC_SYSREG(3, 0, 12, 8, 4 | n) +#define ICC_AP1R_EL1 (n) \ + KVM_DEV_ARM_VGIC_SYSREG(3, 0, 12, 9, n) +#define ICC_BPR1_EL1 \ + KVM_DEV_ARM_VGIC_SYSREG(3, 0, 12, 12, 3) +#define ICC_CTLR_EL1 \ + KVM_DEV_ARM_VGIC_SYSREG(3, 0, 12, 12, 4) +#define ICC_IGRPEN0_EL1 \ + KVM_DEV_ARM_VGIC_SYSREG(3, 0, 12, 12, 6) +#define ICC_IGRPEN1_EL1 \ + KVM_DEV_ARM_VGIC_SYSREG(3, 0, 12, 12, 7) + typedef struct KVMARMGICv3Class { ARMGICv3CommonClass parent_class; DeviceRealize parent_realize;
@@ -56,16 +76,422 @@ static void kvm_arm_gicv3_set_irq(void *opaque, int irq, int level)kvm_arm_gic_set_irq (s->num_irq, irq, level); } +#define KVM_VGIC_ATTR (reg, typer) \ + ((typer & 0xFFFFFFFF00000000ULL) | (reg)) + +static inline void kvm_gicd_access (GICv3State *s,int offset, +uint64_t *val,bool write) +{ +kvm_device_access (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_DIST_REGS , +KVM_VGIC_ATTR (offset,0 ), + val, write); +} + +static inline void kvm_gicr_access (GICv3State *s,int offset,int cpu, +uint64_t *val,bool write) +{ +kvm_device_access (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_REDIST_REGS , +KVM_VGIC_ATTR (offset, s->cpu[cpu].gicr_typer), + val, write); +} + +static inline void kvm_gicc_access (GICv3State *s,uint64_t reg,int cpu, +uint64_t *val,bool write) +{ +kvm_device_access (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS , +KVM_VGIC_ATTR (reg, s->cpu[cpu].gicr_typer), + val, write); +} + +/* Translate from the in-kernel field for an IRQ value to/from the qemu +* representation. Note that these are only expected to be used for +* SPIs (that is, for interrupts whose state is in the distributor +* rather than the redistributor). +*/ +typedef void (*vgic_translate_fn )(GICv3State *s,int irq, +uint32_t *field,bool to_kernel); + +static void translate_edge_trigger (GICv3State *s,int irq, +uint32_t *field,bool to_kernel) +{ +if (to_kernel) { \ + *field =gicv3_gicd_edge_trigger_test (s, irq); \ + }else { \ +gicv3_gicd_edge_trigger_replace (s, irq, *field); \ + } \ +} + +static void translate_priority (GICv3State *s,int irq, +uint32_t *field,bool to_kernel) +{ +if (to_kernel) { + *field = s->gicd_ipriority[irq -GIC_INTERNAL ]; + }else { + s->gicd_ipriority[irq -GIC_INTERNAL ] = *field; + } +} + +/* Loop through each distributor IRQ related register; since bits +* corresponding to SPIs and PPIs are RAZ/WI when affinity routing +* is enabled, we skip those. +*/ +#define for_each_dist_irq_reg (_irq, _max, _field_width) \ + for (_irq = GIC_INTERNAL; _irq < _max; _irq += (32 / _field_width)) + +/* Read a register group from the kernel VGIC */ +static void kvm_dist_get (GICv3State *s,uint32_t offset,int width, +vgic_translate_fn translate_fn) +{ +uint64_t reg; +int j; +int irq; +uint32_t field; +int regsz =32 / width;/* irqs per kernel register */ + +for_each_dist_irq_reg (irq, s->num_irq, width) { +kvm_gicd_access (s, offset, ®, false); + +for (j =0 ; j < regsz; j++) { + field =extract32 (reg, j * width, width); +translate_fn (s, irq + j, &field, false); + } + offset +=4 ; + } +} + +/* Write a register group to the kernel VGIC */ +static void kvm_dist_put (GICv3State *s,uint32_t offset,int width, +vgic_translate_fn translate_fn) +{ +uint64_t reg; +int j; +int irq; +uint32_t field; +int regsz =32 / width;/* irqs per kernel register */ + +for_each_dist_irq_reg (irq, s->num_irq, width) { + reg =0 ; +for (j =0 ; j < regsz; j++) { +translate_fn (s, irq + j, &field, true); + reg =deposit32 (reg, j * width, width, field); + } +kvm_gicd_access (s, offset, ®, true); + offset +=4 ; + } +} + +/* Read a bitmap register group from the kernel VGIC. */ +static void kvm_dist_getbmp (GICv3State *s,uint32_t offset,uint32_t *bmp) +{ +uint64_t reg; +int irq; + +for_each_dist_irq_reg (irq, s->num_irq,1 ) { +kvm_gicd_access (s, offset, ®, false); + *gic_bmp_ptr32 (bmp, irq -GIC_INTERNAL ) = reg; + offset +=4 ; + } +} + +static void kvm_dist_putbmp (GICv3State *s,uint32_t offset, +uint32_t clroffset,uint32_t *bmp) +{ +uint64_t reg; +int irq; + +for_each_dist_irq_reg (irq, s->num_irq,1 ) { +/* If this bitmap is a set/clear register pair, first write to the +* clear-reg to clear all bits before using the set-reg to write +* the 1 bits. +*/ +if (clroffset !=0 ) { + reg =0 ; +kvm_gicd_access (s, clroffset, ®, true); + } + reg = *gic_bmp_ptr32 (bmp, irq -GIC_INTERNAL ); +kvm_gicd_access (s, offset, ®, true); + offset +=4 ; + } +} + +static void kvm_arm_gicv3_check (GICv3State *s) +{ +uint64_t reg; +uint32_t num_irq; + +/* Sanity checking s->num_irq */ +kvm_gicd_access (s,GICD_TYPER , ®, false); + num_irq = ((reg &0x1f ) +1 ) *32 ; + +if (num_irq < s->num_irq) { +error_report ("Model requests %u IRQs, but kernel supports max %u" , + s->num_irq, num_irq); +abort (); + } +} +static void kvm_arm_gicv3_put (GICv3State *s) { -/* TODO */ -DPRINTF ("Cannot put kernel gic state, no kernel interface\n" ); +uint64_t reg, redist_typer; +int ncpu, i; + +kvm_arm_gicv3_check (s); + +kvm_gicr_access (s,GICR_TYPER ,0 , &redist_typer, false); + + reg = s->gicd_ctlr; +kvm_gicd_access (s,GICD_CTLR , ®, true); + +if (redist_typer &GICR_TYPER_PLPIS ) { +/* Set base addresses before LPIs are enabled by GICR_CTLR write */ +for (ncpu =0 ; ncpu < s->num_cpu; ncpu++) { +GICv3CPUState *c = &s->cpu[ncpu]; + + reg = c->gicr_propbaser; +kvm_gicr_access (s,GICR_PROPBASER , ncpu, ®, true); + + reg = c->gicr_pendbaser; +if (!c->gicr_ctlr &GICR_CTLR_ENABLE_LPIS ) { +/* Setting PTZ is advised if LPIs are disabled, to reduce +* GIC initialization time. +*/ + reg |=GICR_PENDBASER_PTZ ; + } +kvm_gicr_access (s,GICR_PENDBASER , ncpu, ®, true); + } + } + +/* Redistributor state (one per CPU) */ + +for (ncpu =0 ; ncpu < s->num_cpu; ncpu++) { +GICv3CPUState *c = &s->cpu[ncpu]; + + reg = c->gicr_ctlr; +kvm_gicr_access (s,GICR_CTLR , ncpu, ®, true); + + reg = c->gicr_statusr[GICV3_NS ]; +kvm_gicr_access (s,GICR_STATUSR , ncpu, ®, true); + + reg = c->gicr_waker; +kvm_gicr_access (s,GICR_WAKER , ncpu, ®, true); + + reg = c->gicr_igroupr0; +kvm_gicr_access (s,GICR_IGROUPR0 , ncpu, ®, true); + + reg = ~0 ; +kvm_gicr_access (s,GICR_ICENABLER0 , ncpu, ®, true); + reg = c->gicr_ienabler0; +kvm_gicr_access (s,GICR_ISENABLER0 , ncpu, ®, true); + +/* Restore config before pending so we treat level/edge correctly */ + reg =half_shuffle32 (c->edge_trigger >>16 ) <<1 ; +kvm_gicr_access (s,GICR_ICFGR1 , ncpu, ®, true); + +// TODO: there is no kernel API for reading/writing c->level + + reg = ~0 ; +kvm_gicr_access (s,GICR_ICPENDR0 , ncpu, ®, true); + reg = c->gicr_ipendr0; +kvm_gicr_access (s,GICR_ISPENDR0 , ncpu, ®, true); + + reg = ~0 ; +kvm_gicr_access (s,GICR_ICACTIVER0 , ncpu, ®, true); + reg = c->gicr_iactiver0; +kvm_gicr_access (s,GICR_ISACTIVER0 , ncpu, ®, true); + +for (i =0 ; i <GIC_INTERNAL ; i +=4 ) { + reg = c->gicr_ipriorityr[i] | + (c->gicr_ipriorityr[i +1 ] <<8 ) | + (c->gicr_ipriorityr[i +2 ] <<16 ) | + (c->gicr_ipriorityr[i +3 ] <<24 ); +kvm_gicr_access (s,GICR_IPRIORITYR + i, ncpu, ®, true); + } + } + +/* Distributor state (shared between all CPUs */ + + reg = s->gicd_statusr[GICV3_NS ]; +kvm_gicd_access (s,GICD_STATUSR , ®, true); + +/* s->enable bitmap -> GICD_ISENABLERn */ +kvm_dist_putbmp (s,GICD_ISENABLER ,GICD_ICENABLER , s->enabled); + +/* s->group bitmap -> GICD_IGROUPRn */ +kvm_dist_putbmp (s,GICD_IGROUPR ,0 , s->group); + +/* Restore targets before pending to ensure the pending state is set on +* the appropriate CPU interfaces in the kernel +*/ + +/* s->gicd_irouter[irq] -> GICD_IROUTERn +* We can't use kvm_dist_put() here because the registers are 64-bit +*/ +for (i =GIC_INTERNAL ; i < s->num_irq; i++) { +uint32_t offset =GICD_IROUTER + (sizeof (uint64_t ) * i); + +kvm_gicd_access (s, offset, &s->gicd_irouter[i -GIC_INTERNAL ], true); + } + +/* s->trigger bitmap -> GICD_ICFGRn +* (restore configuration registers before pending IRQs so we treat +* level/edge correctly) +*/ +kvm_dist_put (s,GICD_ICFGR ,2 , translate_edge_trigger); + +// TODO: there is no kernel API for reading/writing s->level + +/* s->pending bitmap -> GICD_ISPENDRn */ +kvm_dist_putbmp (s,GICD_ISPENDR ,GICD_ICPENDR , s->pending); + +/* s->active bitmap -> GICD_ISACTIVERn */ +kvm_dist_putbmp (s,GICD_ISACTIVER ,GICD_ICACTIVER , s->active); + +/* s->gicd_ipriority[] -> GICD_IPRIORITYRn */ +kvm_dist_put (s,GICD_IPRIORITYR ,8 , translate_priority); + +/* CPU Interface state (one per CPU) */ + +for (ncpu =0 ; ncpu < s->num_cpu; ncpu++) { +GICv3CPUState *c = &s->cpu[ncpu]; + +kvm_gicc_access (s,ICC_CTLR_EL1 , ncpu, + &c->icc_ctlr_el1[GICV3_NS ], true); +kvm_gicc_access (s,ICC_IGRPEN0_EL1 , ncpu, + &c->icc_igrpen[GICV3_G0 ], true); +kvm_gicc_access (s,ICC_IGRPEN1_EL1 , ncpu, + &c->icc_igrpen[GICV3_G1NS ], true); +kvm_gicc_access (s,ICC_PMR_EL1 , ncpu, &c->icc_pmr_el1, true); +kvm_gicc_access (s,ICC_BPR0_EL1 , ncpu, &c->icc_bpr[GICV3_G0 ], true); +kvm_gicc_access (s,ICC_BPR1_EL1 , ncpu, &c->icc_bpr[GICV3_G1NS ], true); + +for (i =0 ; i <4 ; i++) { + reg = c->icc_apr[GICV3_G0 ][i]; +kvm_gicc_access (s,ICC_AP0R_EL1 (i), ncpu, ®, true); + } + +for (i =0 ; i <4 ; i++) { + reg = c->icc_apr[GICV3_G1NS ][i]; +kvm_gicc_access (s,ICC_AP1R_EL1 (i), ncpu, ®, true); + } + } }static void kvm_arm_gicv3_get (GICv3State *s) { -/* TODO */ -DPRINTF ("Cannot get kernel gic state, no kernel interface\n" ); +uint64_t reg, redist_typer; +int ncpu, i; + +kvm_arm_gicv3_check (s); + +kvm_gicr_access (s,GICR_TYPER ,0 , &redist_typer, false); + +kvm_gicd_access (s,GICD_CTLR , ®, false); + s->gicd_ctlr = reg; + +/* Redistributor state (one per CPU) */ + +for (ncpu =0 ; ncpu < s->num_cpu; ncpu++) { +GICv3CPUState *c = &s->cpu[ncpu]; + +kvm_gicr_access (s,GICR_CTLR , ncpu, ®, false); + c->gicr_ctlr = reg; + +kvm_gicr_access (s,GICR_STATUSR , ncpu, ®, false); + c->gicr_statusr[GICV3_NS ] = reg; + +kvm_gicr_access (s,GICR_WAKER , ncpu, ®, false); + c->gicr_waker = reg; + +kvm_gicr_access (s,GICR_IGROUPR0 , ncpu, ®, false); + c->gicr_igroupr0 = reg; +kvm_gicr_access (s,GICR_ISENABLER0 , ncpu, ®, false); + c->gicr_ienabler0 = reg; +kvm_gicr_access (s,GICR_ICFGR1 , ncpu, ®, false); + c->edge_trigger =half_unshuffle32 (reg >>1 ) <<16 ; +kvm_gicr_access (s,GICR_ISPENDR0 , ncpu, ®, false); + c->gicr_ipendr0 = reg; +kvm_gicr_access (s,GICR_ISACTIVER0 , ncpu, ®, false); + c->gicr_iactiver0 = reg; + +for (i =0 ; i <GIC_INTERNAL ; i +=4 ) { +kvm_gicr_access (s,GICR_IPRIORITYR + i, ncpu, ®, false); + c->gicr_ipriorityr[i] =extract32 (reg,0 ,8 ); + c->gicr_ipriorityr[i +1 ] =extract32 (reg,8 ,8 ); + c->gicr_ipriorityr[i +2 ] =extract32 (reg,16 ,8 ); + c->gicr_ipriorityr[i +3 ] =extract32 (reg,24 ,8 ); + } + } + +if (redist_typer &GICR_TYPER_PLPIS ) { +for (ncpu =0 ; ncpu < s->num_cpu; ncpu++) { +GICv3CPUState *c = &s->cpu[ncpu]; + +kvm_gicr_access (s,GICR_PROPBASER , ncpu, ®, false); + c->gicr_propbaser = reg; + +kvm_gicr_access (s,GICR_PENDBASER , ncpu, ®, false); + c->gicr_pendbaser = reg; + } + } + +/* Distributor state (shared between all CPUs */ + +kvm_gicd_access (s,GICD_STATUSR , ®, false); + s->gicd_statusr[GICV3_NS ] = reg; + +/* GICD_IGROUPRn -> s->group bitmap */ +kvm_dist_getbmp (s,GICD_IGROUPR , s->group); + +/* GICD_ISENABLERn -> s->enabled bitmap */ +kvm_dist_getbmp (s,GICD_ISENABLER , s->enabled); + +/* GICD_ISPENDRn -> s->pending bitmap */ +kvm_dist_getbmp (s,GICD_ISPENDR , s->pending); + +/* GICD_ISACTIVERn -> s->active bitmap */ +kvm_dist_getbmp (s,GICD_ISACTIVER , s->active); + +/* GICD_ICFGRn -> s->trigger bitmap */ +kvm_dist_get (s,GICD_ICFGR ,2 , translate_edge_trigger); + +/* GICD_IPRIORITYRn -> s->gicd_ipriority[] */ +kvm_dist_get (s,GICD_IPRIORITYR ,8 , translate_priority); + +/* GICD_IROUTERn -> s->gicd_irouter[irq] */ +for (i =GIC_INTERNAL ; i < s->num_irq; i++) { +uint32_t offset =GICD_IROUTER + (sizeof (reg) * i); + +kvm_gicd_access (s, offset, ®, false); + s->gicd_irouter[i -GIC_INTERNAL ] = reg; + } + +/***************************************************************** +* CPU Interface(s) State +*/ + +for (ncpu =0 ; ncpu < s->num_cpu; ncpu++) { +GICv3CPUState *c = &s->cpu[ncpu]; + +kvm_gicc_access (s,ICC_CTLR_EL1 , ncpu, + &c->icc_ctlr_el1[GICV3_NS ], false); +kvm_gicc_access (s,ICC_IGRPEN0_EL1 , ncpu, + &c->icc_igrpen[GICV3_G0 ], false); +kvm_gicc_access (s,ICC_IGRPEN1_EL1 , ncpu, + &c->icc_igrpen[GICV3_G1NS ], false); +kvm_gicc_access (s,ICC_PMR_EL1 , ncpu, &c->icc_pmr_el1, false); +kvm_gicc_access (s,ICC_BPR0_EL1 , ncpu, &c->icc_bpr[GICV3_G0 ], false); +kvm_gicc_access (s,ICC_BPR1_EL1 , ncpu, &c->icc_bpr[GICV3_G1NS ], false); + +for (i =0 ; i <4 ; i++) { +kvm_gicc_access (s,ICC_AP0R_EL1 (i), ncpu, ®, false); + c->icc_apr[0 ][i] = reg; + } + +for (i =0 ; i <4 ; i++) { +kvm_gicc_access (s,ICC_AP1R_EL1 (i), ncpu, ®, false); + c->icc_apr[1 ][i] = reg; + } + } }static void kvm_arm_gicv3_reset (DeviceState *dev)
@@ -76,6 +502,12 @@ static void kvm_arm_gicv3_reset(DeviceState *dev)DPRINTF ("Reset\n" ); kgc->parent_reset (dev); + +if (s->migration_blocker) { +DPRINTF ("Cannot put kernel gic state, no kernel interface\n" ); +return ; + } +kvm_arm_gicv3_put (s); }
@@ -120,12 +552,12 @@ static void kvm_arm_gicv3_realize(DeviceState *dev, Error **errp)kvm_arm_register_device (&s->iomem_redist,-1 ,KVM_DEV_ARM_VGIC_GRP_ADDR ,KVM_VGIC_V3_ADDR_TYPE_REDIST , s->dev_fd); -/* Block migration of a KVM GICv3 device: the API for saving and restoring -* the state in the kernel is not yet finalised in the kernel or -* implemented in QEMU. -*/ -error_setg (&s->migration_blocker,"vGICv3 migration is not implemented" ); -migrate_add_blocker (s->migration_blocker); +if (!kvm_device_check_attr (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_DIST_REGS , +GICD_CTLR )) { +error_setg (&s->migration_blocker,"This operating system kernel does " +"not support vGICv3 migration" ); +migrate_add_blocker (s->migration_blocker); + } }static void kvm_arm_gicv3_class_init (ObjectClass *klass,void *data)
Signature · 1 line
1.9.1
Hi Peter,
Quoted 2 lines · Peter Maydell
Code review, testing, attempts to run guests other than Linux welcome (UEFI, anybody?)
I run a guest with UEFI firmware. It gets stuck when kernel boots:
[ 0.186331] Brought up 1 CPUs [ 0.186613] SMP: Total of 1 processors activated. [ 0.187976] CPU: All CPU(s) started at EL1 [ 0.191060] alternatives: patching kernel code [ 0.234352] devtmpfs: initialized [ 0.273918] SMBIOS 3.0.0 present. [ 0.280438] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns [ 0.289983] pinctrl core: initialized pinctrl subsystem [ 0.347558] NET: Registered protocol family 16
Thanks,
Signature · 1 line
Shannon
Quoted 8 lines · Shannon Zhao
Hi Peter,
Quoted 2 lines · Peter Maydell
Code review, testing, attempts to run guests other than Linux welcome (UEFI, anybody?)
I run a guest with UEFI firmware. It gets stuck when kernel boots:
Quoted 10 lines
[ 0.186331] Brought up 1 CPUs [ 0.186613] SMP: Total of 1 processors activated. [ 0.187976] CPU: All CPU(s) started at EL1 [ 0.191060] alternatives: patching kernel code [ 0.234352] devtmpfs: initialized [ 0.273918] SMBIOS 3.0.0 present. [ 0.280438] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns [ 0.289983] pinctrl core: initialized pinctrl subsystem [ 0.347558] NET: Registered protocol family 16
Hmm, this works for me. I'm using the Linaro built UEFI from
https://releases.linaro.org/components/kernel/uefi-linaro/15.12/release/qemu64/QEMU_EFI.fd
and a 4.4 kernel and a command line ./build/a64-targets-nodbg/aarch64-softmmu/qemu-system-aarch64 -m 1024 -M virt,gic-version=3 -cpu cortex-a57 -nographic -kernel ~/test-images/virtv8/Image -bios /tmp/QEMU_EFI.fd -append 'console=ttyAMA0,38400 keep_bootcon root=/dev/vda2'
(which panics for not finding the root fs because I didn't bother to put that into the command line, but it doesn't hang at the early stage yours does).
Did you build the QEMU you're testing from the patchset I sent out, or did you try pulling my git tree? I've just realised I forgot to update the git tree branch (now done).
thanks
-- PMM
Quoted 20 lines · Peter Maydell
Quoted 8 lines · Shannon Zhao
Hi Peter,
Quoted 2 lines · Peter Maydell
Code review, testing, attempts to run guests other than Linux welcome (UEFI, anybody?)
I run a guest with UEFI firmware. It gets stuck when kernel boots:
Quoted 10 lines
[ 0.186331] Brought up 1 CPUs [ 0.186613] SMP: Total of 1 processors activated. [ 0.187976] CPU: All CPU(s) started at EL1 [ 0.191060] alternatives: patching kernel code [ 0.234352] devtmpfs: initialized [ 0.273918] SMBIOS 3.0.0 present. [ 0.280438] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns [ 0.289983] pinctrl core: initialized pinctrl subsystem [ 0.347558] NET: Registered protocol family 16
Quoted 8 lines
Hmm, this works for me. I'm using the Linaro built UEFI from
https://releases.linaro.org/components/kernel/uefi-linaro/15.12/release/qemu64/QEMU_EFI.fd
and a 4.4 kernel and a command line ./build/a64-targets-nodbg/aarch64-softmmu/qemu-system-aarch64 -m 1024 -M virt,gic-version=3 -cpu cortex-a57 -nographic -kernel ~/test-images/virtv8/Image -bios/tmp/QEMU_EFI.fd-append 'console=ttyAMA0,38400keep_bootconroot=/dev/vda2'
I wget the UEFI you use from above url and test with below script. It still hangs.
./qemu/aarch64-softmmu/qemu-system-aarch64 -smp 1 \
-m 1024 -M virt,gic-version=3 -cpu cortex-a57 -nographic -kernel Image \
-bios QEMU_EFI.fd -append 'console=ttyAMA0 root=/dev/ram earlycon=pl011,0x9000000 rw'
Booting log:
http://paste.ubuntu.com/16375541/
Quoted 8 lines
(which panics for not finding the root fs because I didn't bother to put that into the command line, but it doesn't hang at the early stage yours does).
Did you build the QEMU you're testing from the patchset I sent out, or did you try pulling my git tree? I've just realised I forgot to update the git tree branch (now done).
I just apply the patches you sent out(since you didn't mention there is a tree for them).
Thanks,
Signature · 1 line
Shannon
Quoted 34 lines · Shannon Zhao
Quoted 20 lines · Peter Maydell
Quoted 8 lines · Shannon Zhao
Hi Peter,
Quoted 2 lines · Peter Maydell
Code review, testing, attempts to run guests other than Linux welcome (UEFI, anybody?)
I run a guest with UEFI firmware. It gets stuck when kernel boots:
Quoted 10 lines
[ 0.186331] Brought up 1 CPUs [ 0.186613] SMP: Total of 1 processors activated. [ 0.187976] CPU: All CPU(s) started at EL1 [ 0.191060] alternatives: patching kernel code [ 0.234352] devtmpfs: initialized [ 0.273918] SMBIOS 3.0.0 present. [ 0.280438] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns [ 0.289983] pinctrl core: initialized pinctrl subsystem [ 0.347558] NET: Registered protocol family 16Quoted 8 lines
Hmm, this works for me. I'm using the Linaro built UEFI from
https://releases.linaro.org/components/kernel/uefi-linaro/15.12/release/qemu64/QEMU_EFI.fd
and a 4.4 kernel and a command line ./build/a64-targets-nodbg/aarch64-softmmu/qemu-system-aarch64 -m 1024 -M virt,gic-version=3 -cpu cortex-a57 -nographic -kernel ~/test-images/virtv8/Image -bios/tmp/QEMU_EFI.fd-append 'console=ttyAMA0,38400keep_bootconroot=/dev/vda2'I wget the UEFI you use from above url and test with below script. It still hangs.
./qemu/aarch64-softmmu/qemu-system-aarch64 -smp 1 \(quoted diff) +0
-2-m 1024 -M virt,gic-version=3 -cpu cortex-a57 -nographic -kernel Image \ -bios QEMU_EFI.fd -append 'console=ttyAMA0 root=/dev/ram
Quoted 1 line
earlycon=pl011,0x9000000 rw'
Can you put the Image file somewhere I can download it, please?
thanks
-- PMM
Quoted 30 lines · Peter Maydell
Quoted 29 lines · Shannon Zhao
Quoted 29 lines · Peter Maydell
Quoted 28 lines
Quoted 28 lines · Shannon Zhao
Quoted 8 lines
Quoted 8 lines
Hi Peter,
Quoted 2 lines · Peter Maydell
Quoted 2 lines
Code review, testing, attempts to run guests other than Linux welcome (UEFI, anybody?)
I run a guest with UEFI firmware. It gets stuck when kernel boots:
Quoted 10 lines
Quoted 10 lines
[ 0.186331] Brought up 1 CPUs [ 0.186613] SMP: Total of 1 processors activated. [ 0.187976] CPU: All CPU(s) started at EL1 [ 0.191060] alternatives: patching kernel code [ 0.234352] devtmpfs: initialized [ 0.273918] SMBIOS 3.0.0 present. [ 0.280438] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns [ 0.289983] pinctrl core: initialized pinctrl subsystem [ 0.347558] NET: Registered protocol family 16Hmm, this works for me. I'm using the Linaro built UEFI from
https://releases.linaro.org/components/kernel/uefi-linaro/15.12/release/qemu64/QEMU_EFI.fd
and a 4.4 kernel and a command line ./build/a64-targets-nodbg/aarch64-softmmu/qemu-system-aarch64 -m 1024 -M virt,gic-version=3 -cpu cortex-a57 -nographic -kernel ~/test-images/virtv8/Image -bios/tmp/QEMU_EFI.fd-append 'console=ttyAMA0,38400keep_bootconroot=/dev/vda2'
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
I wget the UEFI you use from above url and test with below script. It still hangs.
./qemu/aarch64-softmmu/qemu-system-aarch64 -smp 1 \(quoted diff) +0
-2-m 1024 -M virt,gic-version=3 -cpu cortex-a57 -nographic -kernel Image \ -bios QEMU_EFI.fd -append 'console=ttyAMA0 root=/dev/ramearlycon=pl011,0x9000000 rw'
Can you put the Image file somewhere I can download it, please?
I just upload it to
http://people.linaro.org/~shannon.zhao/ACPI_ARM/Image
Signature · 1 line
Shannon
Quoted 4 lines · Shannon Zhao
Quoted 1 line · Peter Maydell
Can you put the Image file somewhere I can download it, please?
I just upload it to
http://people.linaro.org/~shannon.zhao/ACPI_ARM/Image
OK, I can reproduce with that, and I think I know what this is. If we boot a "-bios" image then we don't apply the QEMU workaround for booting buggy Linux images which puts all the interrupts into Group 1, and it looks like a no-TZ-support UEFI doesn't configure the interrupt groups either. So Linux ends up hanging because the interrupt is group 0 but group 0 is disabled.
If you apply this patch to your guest kernel you should find it boots OK I think:
https://lkml.org/lkml/2016/5/10/297
(I'm not sure why the images I was running worked OK; I must have been testing with an image that had that bugfix in it, though I could have sworn I wasn't.)
I don't really want to apply the QEMU workaround when we're booting firmware images as well as raw kernels, but on the other hand via-UEFI is kind of supposed to be the normal way to boot in future. Perhaps we should drop the QEMU workaround altogether, putting everybody on the same playing field...
thanks
-- PMM
Quoted 13 lines · Peter Maydell
Quoted 4 lines · Shannon Zhao
Quoted 1 line · Peter Maydell
Can you put the Image file somewhere I can download it, please?
I just upload it to
http://people.linaro.org/~shannon.zhao/ACPI_ARM/ImageOK, I can reproduce with that, and I think I know what this is. If we boot a "-bios" image then we don't apply the QEMU workaround for booting buggy Linux images which puts all the interrupts into Group 1, and it looks like a no-TZ-support UEFI doesn't configure the interrupt groups either. So Linux ends up hanging because the interrupt is group 0 but group 0 is disabled.
Quoted 4 lines
If you apply this patch to your guest kernel you should find it boots OK I think:
https://lkml.org/lkml/2016/5/10/297
Yeah, it boots OK with this patch.
Quoted 10 lines
(I'm not sure why the images I was running worked OK; I must have been testing with an image that had that bugfix in it, though I could have sworn I wasn't.)
I don't really want to apply the QEMU workaround when we're booting firmware images as well as raw kernels, but on the other hand via-UEFI is kind of supposed to be the normal way to boot in future. Perhaps we should drop the QEMU workaround altogether, putting everybody on the same playing field...
Maybe and if people want to use old kernels, they could use the stable kernel after the kernel patch applied.
Thanks,
Signature · 1 line
Shannon
Quoted 77 lines · Peter Maydell
This series implements emulation of the GICv3 interrupt controller. It is based to some extent on previous patches from Shlomo and Pavel, but the bulk of it has turned out to be new code. (The combination of changing the underlying data structures, adding support for TrustZone and implementing proper GICv3 behaviour rather than borrowing fragments of GICv2 emulation code meant there wasn't much left to reuse.) I've tried to reflect this in the various authorship credits on the patches, but please let me know if you feel I got anything miscredited one way or the other.
Key points about the GICv3 emulated here:
* "non-legacy" only, ie system registers and affinity routing
* TrustZone is implemented
* no virtualization support
* only the "core" GICv3, so no LPI support (via ITS or otherwise)I have included the "support KVM save/restore" patches from Pavel, reworked to use the new data structures, but they are only RFC status because the kernel API is not yet final (there are a couple of loose threads there to be followed up). Those patches are at the end of the series; I think everything else is in a commitable state (give or take code review).
Testing: I have confirmed that we can boot a Linux guest kernel, but not tried any other GIC-using guest code. I've done some light stress-testing using 'stress', and checked an SMP (2-cpu) boot.
Design: all the code here is in hw/intc/, split into several files to avoid them being huge. The interface between the CPU proper and the CPU interface is a bit ad-hoc (you can see the awkward seams that result from the choice to think of the cpu i/f as part of the GIC device rather than part of the CPU itself), but I think that if you put the cpu i/f in the CPU you'd end up with an ad-hoc interface and awkward seams in the other direction. The GICv3 device currently assumes it is always connected to all CPUs; we can change that later to allow some kind of QOM link property to specify the CPUs explicitly, but I think this is OK for now (and it's already a pretty huge set of code changes to have to review).
I include a workaround for a Linux kernel bug which otherwise prevents booting on the virt board. I've reported the bug to Marc Zyngier and he should post a kernel patch to fix it shortly, but I think we'll need to retain the workaround for the benefit of older kernels (an ugly but pragmatic choice).
Code review, testing, attempts to run guests other than Linux welcome (UEFI, anybody?)
thanks
-- PMMPavel Fedin (5):
target-arm: Add mp-affinity property for ARM CPU class hw/intc/arm_gicv3: Add state information hw/intc/arm_gicv3: Add vmstate descriptors
NOT-FOR-UPSTREAM: kernel: Add definitions for GICv3 attributes
RFC: hw/intc/arm_gicv3_kvm: Implement get/put functionsPeter Maydell (15):
migration: DefineVMSTATE_UINT64_2DARRAY
bitops.h: Implement half-shuffle and half-unshuffle ops
target-arm: Define newarm_is_el3_or_mon()function
target-arm: Provide hook to tell GICv3 about changes of security state hw/intc/arm_gicv3: Move irq lines into GICv3CPUState structure hw/intc/arm_gicv3: Implement functions to identify next pending irq hw/intc/arm_gicv3: Wire up distributor and redistributor MMIO regions hw/intc/arm_gicv3: Implementgicv3_set_irq()hw/intc/arm_gicv3: Implement GICv3 CPU interface registers hw/intc/arm_gicv3: Implementgicv3_cpuif_update()hw/intc/arm_gicv3: Implement CPU i/f SGI generation registers hw/intc/arm_gicv3: Add IRQ handling CPU interface registerstarget-arm/machine.c: Allow user to request GICv3 emulationtarget-arm/monitor.c: Advertise emulated GICv3 in capabilities hw/intc/arm_gicv3: Work around Linux assuming interrupts are group 1
Quoted 5 lines
Shlomo Pongratz (3):
hw/intc/arm_gicv3: ARM GICv3 device framework hw/intc/arm_gicv3: Implement GICv3 distributor registers hw/intc/arm_gicv3: Implement GICv3 redistributor registers
Hi Peter, I have gone through these patches. I think I don't have further comments. Sorry that I just reviewed the patches while studying the SPEC, so there are only few problems I found(on the hand your patches are good:) ). I hope I'll give effective comments on the next version.
Thanks,
Signature · 1 line
Shannon