ARM: add PSCI 0.2 support in TCG mode
v4 cover ARM: add PSCI 0.2 support in TCG mode
This series adds PSCI support to ARM and AArch64 system emulation when running in TCG mode. As PSCI calls can be made using either hypervisor call (HVC) or secure monitor call (SMC) instructions, support is added for handling those in patch #3 before patch #5 adds the actual PSCI dispatch logic. Patch #6 enables PSCI for the mach-virt platform.
Changes since v3:
- added some R-b's
- remove user mode interrupt handler for AArch32 as well
- update the SMC and HVC handling logic to
. take feature bits for EL2 and EL3 into account
. deal with conditional execution state in A32/T32
. add ARCH() and IS_USER()/current_pl tests where appropriate
- added some missing () in the PSCI constants
- update the PSCI dispatch logic to
. CPU_ON: take bit 0 of the entry point into account to either set the Thumb
state or return an error, and assert that the onlined CPU is in the same mode as the calling CPU
. CPU_OFF: call cpu_loop_exit() directly
. CPU_SUSPEND; use helper_wfi()
. follow the PSCI spec and adopt the name 'conduit' to refer to the type of
instruction used to invoke PSCI functions
. check the conduit in the translation stage to avoid advancing the single
step state machine inadvertently
- remove smp restriction from mach-virt running in TCG mode
Changes since v2:
- added path #4 to introduce QEMU counterparts of the kernel PSCI constants we refer to in the PSCI emulation, this is needed so QEMU can be built in environments that don't supply the PSCI header file.
Changes since v1:
- processed first round of review, that was already given when this series was sent out by Rob himself back in May
*** BLURB HERE ***
Ard Biesheuvel (1):
target-arm: add missing PSCI constants needed for PSCI emulation
Rob Herring (5):
target-arm: add powered off cpu state
target-arm: do not set do_interrupt handlers for ARM and AArch64 user
modes
target-arm: add hvc and smc exception emulation handling
infrastructure
target-arm: add emulation of PSCI calls for system emulation arm/virt: enable PSCI emulation support for system emulation
hw/arm/virt.c | 82 ++++++++++---------- target-arm/Makefile.objs | 1 + target-arm/cpu-qom.h | 11 +++ target-arm/cpu.c | 19 +++-- target-arm/cpu.h | 8 ++ target-arm/cpu64.c | 2 + target-arm/helper-a64.c | 19 +++++ target-arm/helper.c | 40 ++++++++-- target-arm/internals.h | 20 +++++ target-arm/kvm-consts.h | 40 ++++++++++ target-arm/machine.c | 5 +- target-arm/psci.c | 183 +++++++++++++++++++++++++++++++++++++++++++++ target-arm/translate-a64.c | 38 +++++++--- target-arm/translate.c | 59 ++++++++++++--- target-arm/translate.h | 4 + 15 files changed, 455 insertions(+), 76 deletions(-) create mode 100644 target-arm/psci.c
Signature · 1 line
1.8.3.2
PATCH v4 1/6 target-arm: add powered off cpu state
From: Rob Herring <[email protected]>
Add tracking of cpu power state in order to support powering off of cores in system emuluation. The initial state is determined by the start-powered-off QOM property.
--- target-arm/cpu-qom.h | 2 ++ target-arm/cpu.c | 7 ++++++- target-arm/machine.c | 5 +++-- 3 files changed, 11 insertions(+), 3 deletions(-)
target-arm/cpu-qom.h +2 -0
@@ -98,6 +98,8 @@ typedef struct ARMCPU {/* Should CPU start in PSCI powered-off state? */ bool start_powered_off; +/* CPU currently in PSCI powered-off state */ +bool powered_off;/* [QEMU_]KVM_ARM_TARGET_* constant for this CPU, or * QEMU_KVM_ARM_TARGET_NONE if the kernel doesn't support this CPU type.
target-arm/cpu.c +6 -1
@@ -40,7 +40,9 @@ static void arm_cpu_set_pc(CPUState *cs, vaddr value)static bool arm_cpu_has_work (CPUState *cs) { -return cs->interrupt_request & +ARMCPU *cpu =ARM_CPU (cs); + +return !cpu->powered_off && cs->interrupt_request & (CPU_INTERRUPT_FIQ |CPU_INTERRUPT_HARD |CPU_INTERRUPT_EXITTB ); }
@@ -91,6 +93,9 @@ static void arm_cpu_reset(CPUState *s) env->vfp.xregs[ARM_VFP_MVFR1 ] = cpu->mvfr1; env->vfp.xregs[ARM_VFP_MVFR2 ] = cpu->mvfr2; + cpu->powered_off = cpu->start_powered_off; + s->halted = cpu->start_powered_off; +if (arm_feature (env,ARM_FEATURE_IWMMXT )) { env->iwmmxt.cregs[ARM_IWMMXT_wCID] =0x69051000 |'Q' ; }
target-arm/machine.c +3 -2
@@ -218,8 +218,8 @@ static int cpu_post_load(void *opaque, int version_id)const VMStateDescription vmstate_arm_cpu = { .name ="cpu" , - .version_id =20 , - .minimum_version_id =20 , + .version_id =21 , + .minimum_version_id =21 , .pre_save = cpu_pre_save, .post_load = cpu_post_load, .fields = (VMStateField []) {
@@ -259,6 +259,7 @@ const VMStateDescription vmstate_arm_cpu = {VMSTATE_UINT64 (env.exception.vaddress,ARMCPU ),VMSTATE_TIMER (gt_timer[GTIMER_PHYS ],ARMCPU ),VMSTATE_TIMER (gt_timer[GTIMER_VIRT ],ARMCPU ), +VMSTATE_BOOL (powered_off,ARMCPU ),VMSTATE_END_OF_LIST () }, .subsections = (VMStateSubsection[]) {
Signature · 1 line
1.8.3.2
PATCH v4 2/6 target-arm: do not set do_interrupt handlers for ARM and AArch64 user modes
In reply to Ard BiesheuvelFrom: Rob Herring <[email protected]>
User mode emulation should never get interrupts and thus should not use the system emulation exception handler function. Remove the reference, and '#ifndef USER_MODE_ONLY' the function itself as well, so that we can add system mode only functionality to it.
--- target-arm/cpu.c | 2 +- target-arm/cpu64.c | 2 ++ target-arm/helper-a64.c | 3 +++ target-arm/helper.c | 5 ----- 4 files changed, 6 insertions(+), 6 deletions(-)
target-arm/cpu.c +1 -1
@@ -1043,7 +1043,6 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) cc->class_by_name = arm_cpu_class_by_name; cc->has_work = arm_cpu_has_work; - cc->do_interrupt = arm_cpu_do_interrupt; cc->dump_state = arm_cpu_dump_state; cc->set_pc = arm_cpu_set_pc; cc->gdb_read_register = arm_cpu_gdb_read_register;
@@ -1051,6 +1050,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)#ifdef CONFIG_USER_ONLY cc->handle_mmu_fault = arm_cpu_handle_mmu_fault;#else + cc->do_interrupt = arm_cpu_do_interrupt; cc->get_phys_page_debug = arm_cpu_get_phys_page_debug; cc->vmsd = &vmstate_arm_cpu;#endif
target-arm/cpu64.c +2 -0
@@ -196,7 +196,9 @@ static void aarch64_cpu_class_init(ObjectClass *oc, void *data) {CPUClass *cc =CPU_CLASS (oc); +#if !defined(CONFIG_USER_ONLY ) cc->do_interrupt = aarch64_cpu_do_interrupt; +#endif cc->set_pc = aarch64_cpu_set_pc; cc->gdb_read_register = aarch64_cpu_gdb_read_register; cc->gdb_write_register = aarch64_cpu_gdb_write_register;
target-arm/helper-a64.c +3 -0
@@ -438,6 +438,8 @@ uint64_t HELPER(crc32c_64)(uint64_t acc, uint64_t val, uint32_t bytes)return crc32c (acc, buf, bytes) ^0xffffffff ; } +#if !defined(CONFIG_USER_ONLY ) +/* Handle a CPU exception. */ void aarch64_cpu_do_interrupt (CPUState *cs) {
@@ -512,3 +514,4 @@ void aarch64_cpu_do_interrupt(CPUState *cs) env->pc = addr; cs->interrupt_request |= CPU_INTERRUPT_EXITTB; } +#endif
target-arm/helper.c +0 -5
@@ -3237,11 +3237,6 @@ uint32_t HELPER(rbit)(uint32_t x)#if defined(CONFIG_USER_ONLY ) -void arm_cpu_do_interrupt (CPUState *cs) -{ - cs->exception_index =-1 ; -} -int arm_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int rw,int mmu_idx) {
Signature · 1 line
1.8.3.2
PATCH v4 3/6 target-arm: add hvc and smc exception emulation handling infrastructure
In reply to Ard BiesheuvelFrom: Rob Herring <[email protected]>
Add the infrastructure to handle and emulate hvc and smc exceptions. This will enable emulation of things such as PSCI calls. This commit does not change the behavior and will exit with unknown exception.
--- target-arm/cpu-qom.h | 3 +++ target-arm/cpu.h | 2 ++ target-arm/helper-a64.c | 16 +++++++++++++ target-arm/helper.c | 23 ++++++++++++++++++ target-arm/internals.h | 20 ++++++++++++++++ target-arm/translate-a64.c | 35 ++++++++++++++++++++------- target-arm/translate.c | 59 +++++++++++++++++++++++++++++++++++++--------- target-arm/translate.h | 2 ++ 8 files changed, 140 insertions(+), 20 deletions(-)
target-arm/cpu-qom.h +3 -0
@@ -192,6 +192,9 @@ extern const struct VMStateDescription vmstate_arm_cpu;void register_cp_regs_for_features (ARMCPU *cpu);void init_cpreg_list (ARMCPU *cpu); +bool arm_cpu_do_hvc (CPUState *cs); +bool arm_cpu_do_smc (CPUState *cs); +void arm_cpu_do_interrupt (CPUState *cpu);void arm_v7m_cpu_do_interrupt (CPUState *cpu);
target-arm/cpu.h +2 -0
@@ -51,6 +51,8 @@#define EXCP_EXCEPTION_EXIT 8/* Return from v7M exception. */ #define EXCP_KERNEL_TRAP 9/* Jumped to kernel code page. */ #define EXCP_STREX 10 +#define EXCP_HVC 11 +#define EXCP_SMC 12#define ARMV7M_EXCP_RESET 1#define ARMV7M_EXCP_NMI 2
target-arm/helper-a64.c +16 -0
@@ -485,6 +485,22 @@ void aarch64_cpu_do_interrupt(CPUState *cs)case EXCP_FIQ : addr +=0x100 ;break ; +case EXCP_HVC : +if (arm_cpu_do_hvc (cs)) { +return ; + } +/* Treat as unallocated encoding */ +qemu_log_mask (LOG_GUEST_ERROR ,"HVC not implemented on this CPU\n" ); + env->exception.syndrome =syn_uncategorized (); +break ; +case EXCP_SMC : +if (arm_cpu_do_smc (cs)) { +return ; + } +/* Treat as unallocated encoding */ +qemu_log_mask (LOG_GUEST_ERROR ,"SMC not implemented on this CPU\n" ); + env->exception.syndrome =syn_uncategorized (); +break ;default :cpu_abort (cs,"Unhandled exception 0x%x\n" , cs->exception_index); }
target-arm/helper.c +23 -0
@@ -3492,6 +3492,16 @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) env->thumb = addr &1 ; } +bool arm_cpu_do_hvc (CPUState *cs) +{ +return false; +} + +bool arm_cpu_do_smc (CPUState *cs) +{ +return false; +} +/* Handle a CPU exception. */ void arm_cpu_do_interrupt (CPUState *cs) {
@@ -3508,6 +3518,19 @@ void arm_cpu_do_interrupt(CPUState *cs)/* TODO: Vectored interrupt controller. */ switch (cs->exception_index) { +case EXCP_HVC : +if (arm_cpu_do_hvc (cs)) { +return ; + } +qemu_log_mask (LOG_GUEST_ERROR ,"HVC not implemented on this CPU\n" ); + goto hvc_unallocated; +case EXCP_SMC : +if (arm_cpu_do_smc (cs)) { +return ; + } +qemu_log_mask (LOG_GUEST_ERROR ,"SMC not implemented on this CPU\n" ); + hvc_unallocated: +/* Fall through -- treat as unallocated encoding */ case EXCP_UDEF : new_mode =ARM_CPU_MODE_UND ; addr =0x04 ;
target-arm/internals.h +20 -0
@@ -210,6 +210,26 @@ static inline uint32_t syn_aa32_svc(uint32_t imm16, bool is_thumb) | (is_thumb ? 0 : ARM_EL_IL); } +static inline uint32_t syn_aa64_hvc (uint32_t imm16) +{ +return (EC_AA64_HVC <<ARM_EL_EC_SHIFT ) |ARM_EL_IL | (imm16 &0xffff ); +} + +static inline uint32_t syn_aa32_hvc (uint32_t imm16) +{ +return (EC_AA32_HVC <<ARM_EL_EC_SHIFT ) |ARM_EL_IL | (imm16 &0xffff ); +} + +static inline uint32_t syn_aa64_smc (uint32_t imm16) +{ +return (EC_AA64_SMC <<ARM_EL_EC_SHIFT ) |ARM_EL_IL | (imm16 &0xffff ); +} + +static inline uint32_t syn_aa32_smc (void ) +{ +return (EC_AA32_SMC <<ARM_EL_EC_SHIFT ) |ARM_EL_IL ; +} +static inline uint32_t syn_aa64_bkpt (uint32_t imm16) {return (EC_AA64_BKPT <<ARM_EL_EC_SHIFT ) |ARM_EL_IL | (imm16 &0xffff );
target-arm/translate-a64.c +26 -9
@@ -1473,20 +1473,37 @@ static void disas_exc(DisasContext *s, uint32_t insn)switch (opc) {case 0 : -/* SVC, HVC, SMC; since we don't support the Virtualization -* or TrustZone extensions these all UNDEF except SVC. -*/ -if (op2_ll !=1 ) { -unallocated_encoding (s); -break ; - }/* For SVC, HVC and SMC we advance the single-step state * machine before taking the exception. This is architecturally * mandated, to ensure that single-stepping a system call * instruction works properly. */ -gen_ss_advance (s); -gen_exception_insn (s,0 ,EXCP_SWI ,syn_aa64_svc (imm16)); +switch (op2_ll) { +case 1 : +gen_ss_advance (s); +gen_exception_insn (s,0 ,EXCP_SWI ,syn_aa64_svc (imm16)); +break ; +case 2 : +if (s->current_pl !=0 + &&arm_dc_feature (s,ARM_FEATURE_EL2 )) { +gen_ss_advance (s); +gen_exception_insn (s,0 ,EXCP_HVC ,syn_aa64_hvc (imm16)); +break ; + } +unallocated_encoding (s); +break ; +case 3 : +if (s->current_pl !=0 + &&arm_dc_feature (s,ARM_FEATURE_EL3 )) { +gen_ss_advance (s); +gen_exception_insn (s,0 ,EXCP_SMC ,syn_aa64_smc (imm16)); +break ; + } +/* fall through */ +default : +unallocated_encoding (s); +break ; + }break ;case 1 :if (op2_ll !=0 ) {
target-arm/translate.c +48 -11
79 lines not on this page · raw message
target-arm/translate.h +2 -0
@@ -82,6 +82,8 @@ static inline int get_mem_index(DisasContext *s)#define DISAS_EXC 6/* WFE */ #define DISAS_WFE 7 +#define DISAS_HVC 8 +#define DISAS_SMC 9#ifdef TARGET_AARCH64 void a64_translate_init (void );
Signature · 1 line
1.8.3.2
Re: [Qemu-devel] [PACTH v4 3/6] target-arm: add hvc and smc exception emulation handling infrastructure
Quoted 23 lines · Ard Biesheuvel
From: Rob Herring <[email protected]>
Add the infrastructure to handle and emulate hvc and smc exceptions. This will enable emulation of things such as PSCI calls. This commit does not change the behavior and will exit with unknown exception.
Signed-off-by Rob Herring <[email protected]>Signed-off-by Ard Biesheuvel <[email protected]>target-arm/helper-a64.c +6
-0@@ -485,6 +485,22 @@ void aarch64_cpu_do_interrupt(CPUState *cs)case EXCP_FIQ : addr +=0x100 ;break ; +case EXCP_HVC : +if (arm_cpu_do_hvc (cs)) { +return ; + } +/* Treat as unallocated encoding */ +qemu_log_mask (LOG_GUEST_ERROR ,"HVC not implemented on this CPU\n" );
target-arm/helper-a64.c void aarch64_cpu_do_interrupt(CPUState *cs) · line 503
Quoted 10 lines
target-arm/helper-a64.c +10
-0+ env->exception.syndrome =syn_uncategorized (); +break ; +case EXCP_SMC : +if (arm_cpu_do_smc (cs)) { +return ; + } +/* Treat as unallocated encoding */ +qemu_log_mask (LOG_GUEST_ERROR ,"SMC not implemented on this CPU\n" ); + env->exception.syndrome =syn_uncategorized (); +break ;
Looking again at this there are some issues with this, notably that we don't do anything to ensure that the PC is pointing at the instruction we're claiming to be UNDEF rather than just after it.
The best approach seems to me to be to figure out at translate time whether we're going to call this SMC UNDEF or not.
We also seem to only generate the SMC and HVC exception if the CPU has the FEATURE_EL2/3 bit set, which confuses me because our CPUs don't set that and so I'm not sure how this works at all...
I think the best way to fix this is going to be to rebase this on top of Edgar's EL2/EL3 support patches, which already deal with most of those problems (albeit only for AArch64 currently). I'll do that and send out a fixed version.
thanks
-- PMM
PATCH v4 4/6 target-arm: add missing PSCI constants needed for PSCI emulation
In reply to Ard BiesheuvelThis adds some PSCI function IDs and symbolic return codes that are needed to implement PSCI emulation in TCG mode.
--- target-arm/kvm-consts.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
target-arm/kvm-consts.h +40 -0
@@ -59,14 +59,21 @@ MISMATCH_CHECK(QEMU_PSCI_0_1_FN_MIGRATE, KVM_PSCI_FN_MIGRATE) (QEMU_PSCI_0_2_FN_BASE + QEMU_PSCI_0_2_64BIT)#define QEMU_PSCI_0_2_FN64 (n) (QEMU_PSCI_0_2_FN64_BASE + (n)) +#define QEMU_PSCI_0_2_FN_PSCI_VERSION QEMU_PSCI_0_2_FN(0)#define QEMU_PSCI_0_2_FN_CPU_SUSPEND QEMU_PSCI_0_2_FN(1)#define QEMU_PSCI_0_2_FN_CPU_OFF QEMU_PSCI_0_2_FN(2)#define QEMU_PSCI_0_2_FN_CPU_ON QEMU_PSCI_0_2_FN(3) +#define QEMU_PSCI_0_2_FN_AFFINITY_INFO QEMU_PSCI_0_2_FN(4)#define QEMU_PSCI_0_2_FN_MIGRATE QEMU_PSCI_0_2_FN(5) +#define QEMU_PSCI_0_2_FN_MIGRATE_INFO_TYPE QEMU_PSCI_0_2_FN(6) +#define QEMU_PSCI_0_2_FN_MIGRATE_INFO_UP_CPU QEMU_PSCI_0_2_FN(7) +#define QEMU_PSCI_0_2_FN_SYSTEM_OFF QEMU_PSCI_0_2_FN(8) +#define QEMU_PSCI_0_2_FN_SYSTEM_RESET QEMU_PSCI_0_2_FN(9)#define QEMU_PSCI_0_2_FN64_CPU_SUSPEND QEMU_PSCI_0_2_FN64(1)#define QEMU_PSCI_0_2_FN64_CPU_OFF QEMU_PSCI_0_2_FN64(2)#define QEMU_PSCI_0_2_FN64_CPU_ON QEMU_PSCI_0_2_FN64(3) +#define QEMU_PSCI_0_2_FN64_AFFINITY_INFO QEMU_PSCI_0_2_FN64(4)#define QEMU_PSCI_0_2_FN64_MIGRATE QEMU_PSCI_0_2_FN64(5)MISMATCH_CHECK (QEMU_PSCI_0_2_FN_CPU_SUSPEND ,PSCI_0_2_FN_CPU_SUSPEND )
@@ -77,6 +84,39 @@ MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_CPU_SUSPEND, PSCI_0_2_FN64_CPU_SUSPEND) MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_CPU_ON, PSCI_0_2_FN64_CPU_ON)MISMATCH_CHECK (QEMU_PSCI_0_2_FN64_MIGRATE ,PSCI_0_2_FN64_MIGRATE ) +/* PSCI v0.2 return values used by TCG emulation of PSCI */ + +/* No Trusted OS migration to worry about when offlining CPUs */ +#define QEMU_PSCI_0_2_RET_TOS_MIGRATION_NOT_REQUIRED 2 + +/* We implement version 0.2 only */ +#define QEMU_PSCI_0_2_RET_VERSION_0_2 2 + +MISMATCH_CHECK(QEMU_PSCI_0_2_RET_TOS_MIGRATION_NOT_REQUIRED, PSCI_0_2_TOS_MP) +MISMATCH_CHECK (QEMU_PSCI_0_2_RET_VERSION_0_2 , + (PSCI_VERSION_MAJOR (0 ) |PSCI_VERSION_MINOR (2 ))) + +/* PSCI return values (inclusive of all PSCI versions) */ +#define QEMU_PSCI_RET_SUCCESS 0 +#define QEMU_PSCI_RET_NOT_SUPPORTED -1 +#define QEMU_PSCI_RET_INVALID_PARAMS -2 +#define QEMU_PSCI_RET_DENIED -3 +#define QEMU_PSCI_RET_ALREADY_ON -4 +#define QEMU_PSCI_RET_ON_PENDING -5 +#define QEMU_PSCI_RET_INTERNAL_FAILURE -6 +#define QEMU_PSCI_RET_NOT_PRESENT -7 +#define QEMU_PSCI_RET_DISABLED -8 + +MISMATCH_CHECK(QEMU_PSCI_RET_SUCCESS, PSCI_RET_SUCCESS) +MISMATCH_CHECK(QEMU_PSCI_RET_NOT_SUPPORTED, PSCI_RET_NOT_SUPPORTED) +MISMATCH_CHECK(QEMU_PSCI_RET_INVALID_PARAMS, PSCI_RET_INVALID_PARAMS) +MISMATCH_CHECK(QEMU_PSCI_RET_DENIED, PSCI_RET_DENIED) +MISMATCH_CHECK(QEMU_PSCI_RET_ALREADY_ON, PSCI_RET_ALREADY_ON) +MISMATCH_CHECK(QEMU_PSCI_RET_ON_PENDING, PSCI_RET_ON_PENDING) +MISMATCH_CHECK(QEMU_PSCI_RET_INTERNAL_FAILURE, PSCI_RET_INTERNAL_FAILURE) +MISMATCH_CHECK(QEMU_PSCI_RET_NOT_PRESENT, PSCI_RET_NOT_PRESENT) +MISMATCH_CHECK (QEMU_PSCI_RET_DISABLED ,PSCI_RET_DISABLED ) +/* Note that KVM uses overlapping values for AArch32 and AArch64 * target CPU numbers. AArch32 targets: */
Signature · 1 line
1.8.3.2
PATCH v4 5/6 target-arm: add emulation of PSCI calls for system emulation
In reply to Ard BiesheuvelFrom: Rob Herring <[email protected]>
Add support for handling PSCI calls in system emulation. Both version 0.1 and 0.2 of the PSCI spec are supported. Platforms can enable support by setting the "psci-conduit" QOM property on the cpus to SMC or HVC emulation and having a PSCI binding in their dtb.
--- target-arm/Makefile.objs | 1 + target-arm/cpu-qom.h | 6 ++ target-arm/cpu.c | 10 ++- target-arm/cpu.h | 6 ++ target-arm/helper.c | 12 +++ target-arm/psci.c | 183 +++++++++++++++++++++++++++++++++++++++++++++ target-arm/translate-a64.c | 7 +- target-arm/translate.h | 2 + 8 files changed, 222 insertions(+), 5 deletions(-) create mode 100644 target-arm/psci.c
target-arm/Makefile.objs +1 -0
@@ -7,5 +7,6 @@ obj-$(call lnot,$(CONFIG_KVM)) += kvm-stub.o obj-y += translate.o op_helper.o helper.o cpu.o obj-y += neon_helper.o iwmmxt_helper.o obj-y += gdbstub.o +obj-$(CONFIG_SOFTMMU) += psci.o obj-$(TARGET_AARCH64) += cpu64.o translate-a64.o helper-a64.o gdbstub64.o obj-y += crypto_helper.o
target-arm/cpu-qom.h +6 -0
@@ -101,6 +101,11 @@ typedef struct ARMCPU {/* CPU currently in PSCI powered-off state */ bool powered_off; +/* PSCI conduit used to invoke PSCI methods +* 0 - disabled, 1 - smc, 2 - hvc +*/ +uint32_t psci_conduit; +/* [QEMU_]KVM_ARM_TARGET_* constant for this CPU, or * QEMU_KVM_ARM_TARGET_NONE if the kernel doesn't support this CPU type. */
@@ -192,6 +197,7 @@ extern const struct VMStateDescription vmstate_arm_cpu;void register_cp_regs_for_features (ARMCPU *cpu);void init_cpreg_list (ARMCPU *cpu); +bool arm_handle_psci (CPUState *cs);bool arm_cpu_do_hvc (CPUState *cs);bool arm_cpu_do_smc (CPUState *cs);
target-arm/cpu.c +7 -3
@@ -268,9 +268,12 @@ static void arm_cpu_initfn(Object *obj) cpu->psci_version =1 ;/* By default assume PSCI v0.1 */ cpu->kvm_target =QEMU_KVM_ARM_TARGET_NONE ; -if (tcg_enabled () && !inited) { - inited = true; -arm_translate_init (); +if (tcg_enabled ()) { + cpu->psci_version =2 ;/* TCG implements PSCI 0.2 */ +if (!inited) { + inited = true; +arm_translate_init (); + } } }
@@ -1024,6 +1027,7 @@ static const ARMCPUInfo arm_cpus[] = {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_END_OF_LIST () };
target-arm/cpu.h +6 -0
@@ -1350,4 +1350,10 @@ static inline void cpu_pc_from_tb(CPUARMState *env, TranslationBlock *tb) } } +enum { +QEMU_PSCI_CONDUIT_DISABLED =0 , +QEMU_PSCI_CONDUIT_SMC =1 , +QEMU_PSCI_CONDUIT_HVC =2 , +}; +#endif
target-arm/helper.c +12 -0
@@ -3494,11 +3494,23 @@ void arm_v7m_cpu_do_interrupt(CPUState *cs)bool arm_cpu_do_hvc (CPUState *cs) { +ARMCPU *cpu =ARM_CPU (cs); + +if (cpu->psci_conduit ==QEMU_PSCI_CONDUIT_HVC ) { +return arm_handle_psci (cs); + } +return false; }bool arm_cpu_do_smc (CPUState *cs) { +ARMCPU *cpu =ARM_CPU (cs); + +if (cpu->psci_conduit ==QEMU_PSCI_CONDUIT_SMC ) { +return arm_handle_psci (cs); + } +return false; }
target-arm/psci.c new file +183 -0
183 lines not on this page · raw message
target-arm/translate-a64.c +5 -2
@@ -1485,7 +1485,8 @@ static void disas_exc(DisasContext *s, uint32_t insn)break ;case 2 :if (s->current_pl !=0 - &&arm_dc_feature (s,ARM_FEATURE_EL2 )) { + && (arm_dc_feature (s,ARM_FEATURE_EL2 ) + || s->psci_conduit ==QEMU_PSCI_CONDUIT_HVC )) {gen_ss_advance (s);gen_exception_insn (s,0 ,EXCP_HVC ,syn_aa64_hvc (imm16));break ;
@@ -1494,7 +1495,8 @@ static void disas_exc(DisasContext *s, uint32_t insn)break ;case 3 :if (s->current_pl !=0 - &&arm_dc_feature (s,ARM_FEATURE_EL3 )) { + && (arm_dc_feature (s,ARM_FEATURE_EL3 ) + || s->psci_conduit ==QEMU_PSCI_CONDUIT_SMC )) {gen_ss_advance (s);gen_exception_insn (s,0 ,EXCP_SMC ,syn_aa64_smc (imm16));break ;
@@ -10943,6 +10945,7 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu, dc->pstate_ss =ARM_TBFLAG_AA64_PSTATE_SS (tb->flags); dc->is_ldex = false; dc->ss_same_el = (arm_debug_target_el (env) == dc->current_pl); + dc->psci_conduit = cpu->psci_conduit;init_tmp_a64_array (dc);
target-arm/translate.h +2 -0
@@ -52,6 +52,8 @@ typedef struct DisasContext {bool is_ldex;/* True if a single-step exception will be taken to the current EL */ bool ss_same_el; +/* Conduit used for PSCI method calls, either HVC or SMC (or disabled) */ +uint32_t psci_conduit;#define TMP_A64_MAX 16int tmp_a64_count;TCGv_i64 tmp_a64[TMP_A64_MAX ];
Signature · 1 line
1.8.3.2
Re: [Qemu-devel] [PACTH v4 5/6] target-arm: add emulation of PSCI calls for system emulation
Quoted 10 lines · Ard Biesheuvel
From: Rob Herring <[email protected]>
Add support for handling PSCI calls in system emulation. Both version 0.1 and 0.2 of the PSCI spec are supported. Platforms can enable support by setting the "psci-conduit" QOM property on the cpus to SMC or HVC emulation and having a PSCI binding in their dtb.
Signed-off-by Rob Herring <[email protected]>Signed-off-by Ard Biesheuvel <[email protected]>
Review
Quoted 6 lines
(quoted diff) +6
-0+ case QEMU_PSCI_0_2_FN_SYSTEM_RESET: + qemu_system_reset_request(); + break; + case QEMU_PSCI_0_2_FN_SYSTEM_OFF: + qemu_system_shutdown_request(); + break;
I just realised that this isn't quite right: PSCI mandates that the SYSTEM_RESET and SYSTEM_OFF functions never return to the caller, but the QEMU qemu_system_*_request() functions are just requests which the main loop will later handle asynchronously. So we should put the calling CPU into power off (and rely on CPU reset to power it up again if it's CPU 0; we don't care if we're shutting down, obviously).
I propose to apply the following fixup patch to deal with this (since this patchset is very nearly ready and I know Ard's not going to be back to deal with it for a few weeks):
target-arm/psci.c +15 -7
@@ -85,10 +85,15 @@ bool arm_handle_psci(CPUState *cs)break ;case QEMU_PSCI_0_2_FN_SYSTEM_RESET :qemu_system_reset_request (); -break ; +/* QEMU reset and shutdown are async requests, but PSCI +* mandates that we never return from the reset/shutdown +* call, so power the CPU off now so it doesn't execute +* anything further. +*/ + goto cpu_off;case QEMU_PSCI_0_2_FN_SYSTEM_OFF :qemu_system_shutdown_request (); -break ; + goto cpu_off;case QEMU_PSCI_0_1_FN_CPU_ON :case QEMU_PSCI_0_2_FN_CPU_ON :case QEMU_PSCI_0_2_FN64_CPU_ON :
@@ -144,11 +149,7 @@ bool arm_handle_psci(CPUState *cs)break ;case QEMU_PSCI_0_1_FN_CPU_OFF :case QEMU_PSCI_0_2_FN_CPU_OFF : - cpu->powered_off = true; - cs->halted =1 ; - cs->exception_index =EXCP_HLT ; -cpu_loop_exit (cs); -/* notreached */ + goto cpu_off;case QEMU_PSCI_0_1_FN_CPU_SUSPEND :case QEMU_PSCI_0_2_FN_CPU_SUSPEND :case QEMU_PSCI_0_2_FN64_CPU_SUSPEND :
@@ -180,4 +181,11 @@ err: env->regs[0 ] = ret; }return true; + +cpu_off: + cpu->powered_off = true; + cs->halted =1 ; + cs->exception_index =EXCP_HLT ; +cpu_loop_exit (cs); +/* notreached */ }
thanks
-- PMM
Re: [Qemu-devel] [PACTH v4 5/6] target-arm: add emulation of PSCI calls for system emulation
Il 26/09/2014 11:10, Peter Maydell ha scritto:
Quoted 27 lines · Ard Biesheuvel
Quoted 10 lines
From: Rob Herring <[email protected]>
Add support for handling PSCI calls in system emulation. Both version 0.1 and 0.2 of the PSCI spec are supported. Platforms can enable support by setting the "psci-conduit" QOM property on the cpus to SMC or HVC emulation and having a PSCI binding in their dtb.
Signed-off-by Rob Herring <[email protected]>Signed-off-by Ard Biesheuvel <[email protected]>Review
Quoted 6 lines
(quoted diff) +6
-0+ case QEMU_PSCI_0_2_FN_SYSTEM_RESET: + qemu_system_reset_request(); + break; + case QEMU_PSCI_0_2_FN_SYSTEM_OFF: + qemu_system_shutdown_request(); + break;I just realised that this isn't quite right: PSCI mandates that the
SYSTEM_RESETandSYSTEM_OFFfunctions never return to the caller, but the QEMU qemu_system_*_request() functions are just requests which the main loop will later handle asynchronously. So we should put the calling CPU into power off (and rely on CPU reset to power it up again if it's CPU 0; we don't care if we're shutting down, obviously).
Quoted 4 lines
I propose to apply the following fixup patch to deal with this (since this patchset is very nearly ready and I know Ard's not going to be back to deal with it for a few weeks):
FWIW, looks good.
Thanks,
Paolo
Quoted 52 lines
target-arm/psci.c +15
-7@@ -85,10 +85,15 @@ bool arm_handle_psci(CPUState *cs)break ;case QEMU_PSCI_0_2_FN_SYSTEM_RESET :qemu_system_reset_request (); -break ; +/* QEMU reset and shutdown are async requests, but PSCI +* mandates that we never return from the reset/shutdown +* call, so power the CPU off now so it doesn't execute +* anything further. +*/ + goto cpu_off;case QEMU_PSCI_0_2_FN_SYSTEM_OFF :qemu_system_shutdown_request (); -break ; + goto cpu_off;case QEMU_PSCI_0_1_FN_CPU_ON :case QEMU_PSCI_0_2_FN_CPU_ON :case QEMU_PSCI_0_2_FN64_CPU_ON :@@ -144,11 +149,7 @@ bool arm_handle_psci(CPUState *cs)break ;case QEMU_PSCI_0_1_FN_CPU_OFF :case QEMU_PSCI_0_2_FN_CPU_OFF : - cpu->powered_off = true; - cs->halted =1 ; - cs->exception_index =EXCP_HLT ; -cpu_loop_exit (cs); -/* notreached */ + goto cpu_off;case QEMU_PSCI_0_1_FN_CPU_SUSPEND :case QEMU_PSCI_0_2_FN_CPU_SUSPEND :case QEMU_PSCI_0_2_FN64_CPU_SUSPEND :@@ -180,4 +181,11 @@ err: env->regs[0 ] = ret; }return true; + +cpu_off: + cpu->powered_off = true; + cs->halted =1 ; + cs->exception_index =EXCP_HLT ; +cpu_loop_exit (cs); +/* notreached */ }thanks
-- PMM
PATCH v4 6/6 arm/virt: enable PSCI emulation support for system emulation
In reply to Ard BiesheuvelFrom: Rob Herring <[email protected]>
Now that we have PSCI emulation, enable it for the virt platform. This simplifies the virt machine a bit now that PSCI no longer needs to be a KVM only feature.
--- hw/arm/virt.c | 82 +++++++++++++++++++++++++++-------------------------------- 1 file changed, 38 insertions(+), 44 deletions(-)
hw/arm/virt.c +38 -44
@@ -189,47 +189,48 @@ static void create_fdt(VirtBoardInfo *vbi)static void fdt_add_psci_node (const VirtBoardInfo *vbi) { +uint32_t cpu_suspend_fn; +uint32_t cpu_off_fn; +uint32_t cpu_on_fn; +uint32_t migrate_fn;void *fdt = vbi->fdt;ARMCPU *armcpu =ARM_CPU (qemu_get_cpu (0 )); -/* No PSCI for TCG yet */ -if (kvm_enabled ()) { -uint32_t cpu_suspend_fn; -uint32_t cpu_off_fn; -uint32_t cpu_on_fn; -uint32_t migrate_fn; - -qemu_fdt_add_subnode (fdt,"/psci" ); -if (armcpu->psci_version ==2 ) { -const char comp[] ="arm,psci-0.2\0arm,psci" ; -qemu_fdt_setprop (fdt,"/psci" ,"compatible" , comp,sizeof (comp)); - - cpu_off_fn =QEMU_PSCI_0_2_FN_CPU_OFF ; -if (arm_feature (&armcpu->env,ARM_FEATURE_AARCH64 )) { - cpu_suspend_fn =QEMU_PSCI_0_2_FN64_CPU_SUSPEND ; - cpu_on_fn =QEMU_PSCI_0_2_FN64_CPU_ON ; - migrate_fn =QEMU_PSCI_0_2_FN64_MIGRATE ; - }else { - cpu_suspend_fn =QEMU_PSCI_0_2_FN_CPU_SUSPEND ; - cpu_on_fn =QEMU_PSCI_0_2_FN_CPU_ON ; - migrate_fn =QEMU_PSCI_0_2_FN_MIGRATE ; - } - }else { -qemu_fdt_setprop_string (fdt,"/psci" ,"compatible" ,"arm,psci" ); +qemu_fdt_add_subnode (fdt,"/psci" ); +if (armcpu->psci_version ==2 ) { +const char comp[] ="arm,psci-0.2\0arm,psci" ; +qemu_fdt_setprop (fdt,"/psci" ,"compatible" , comp,sizeof (comp)); - cpu_suspend_fn =QEMU_PSCI_0_1_FN_CPU_SUSPEND ; - cpu_off_fn =QEMU_PSCI_0_1_FN_CPU_OFF ; - cpu_on_fn =QEMU_PSCI_0_1_FN_CPU_ON ; - migrate_fn =QEMU_PSCI_0_1_FN_MIGRATE ; + cpu_off_fn =QEMU_PSCI_0_2_FN_CPU_OFF ; +if (arm_feature (&armcpu->env,ARM_FEATURE_AARCH64 )) { + cpu_suspend_fn =QEMU_PSCI_0_2_FN64_CPU_SUSPEND ; + cpu_on_fn =QEMU_PSCI_0_2_FN64_CPU_ON ; + migrate_fn =QEMU_PSCI_0_2_FN64_MIGRATE ; + }else { + cpu_suspend_fn =QEMU_PSCI_0_2_FN_CPU_SUSPEND ; + cpu_on_fn =QEMU_PSCI_0_2_FN_CPU_ON ; + migrate_fn =QEMU_PSCI_0_2_FN_MIGRATE ; } + }else { +qemu_fdt_setprop_string (fdt,"/psci" ,"compatible" ,"arm,psci" ); -qemu_fdt_setprop_string (fdt,"/psci" ,"method" ,"hvc" ); - -qemu_fdt_setprop_cell (fdt,"/psci" ,"cpu_suspend" , cpu_suspend_fn); -qemu_fdt_setprop_cell (fdt,"/psci" ,"cpu_off" , cpu_off_fn); -qemu_fdt_setprop_cell (fdt,"/psci" ,"cpu_on" , cpu_on_fn); -qemu_fdt_setprop_cell (fdt,"/psci" ,"migrate" , migrate_fn); + cpu_suspend_fn =QEMU_PSCI_0_1_FN_CPU_SUSPEND ; + cpu_off_fn =QEMU_PSCI_0_1_FN_CPU_OFF ; + cpu_on_fn =QEMU_PSCI_0_1_FN_CPU_ON ; + migrate_fn =QEMU_PSCI_0_1_FN_MIGRATE ; } + +/* We adopt the PSCI spec's nomenclature, and use 'conduit' to refer +* to the instruction that should be used to invoke PSCI functions. +* However, the device tree binding uses 'method' instead, so that is +* what we should use here. +*/ +qemu_fdt_setprop_string (fdt,"/psci" ,"method" ,"hvc" ); + +qemu_fdt_setprop_cell (fdt,"/psci" ,"cpu_suspend" , cpu_suspend_fn); +qemu_fdt_setprop_cell (fdt,"/psci" ,"cpu_off" , cpu_off_fn); +qemu_fdt_setprop_cell (fdt,"/psci" ,"cpu_on" , cpu_on_fn); +qemu_fdt_setprop_cell (fdt,"/psci" ,"migrate" , migrate_fn); }static void fdt_add_timer_nodes (const VirtBoardInfo *vbi)
@@ -467,16 +468,6 @@ static void machvirt_init(MachineState *machine) vbi->smp_cpus = smp_cpus; -/* -* Only supported method of starting secondary CPUs is PSCI and -* PSCI is not yet supported with TCG, so limit smp_cpus to 1 -* if we're not using KVM. -*/ -if (!kvm_enabled () && smp_cpus >1 ) { -error_report ("mach-virt: must enable KVM to use multiple CPUs" ); -exit (1 ); - } -if (machine->ram_size > vbi->memmap[VIRT_MEM ].size) {error_report ("mach-virt: cannot model more than 30GB RAM" );exit (1 );
@@ -495,6 +486,9 @@ static void machvirt_init(MachineState *machine) } cpuobj =object_new (object_class_get_name (oc)); +object_property_set_int (cpuobj,QEMU_PSCI_CONDUIT_HVC ,"psci-conduit" , +NULL ); +/* Secondary CPUs start in PSCI powered-down state */ if (n >0 ) {object_property_set_bool (cpuobj, true,"start-powered-off" ,NULL );
Signature · 1 line
1.8.3.2