Add i.MX6 (Single/Dual/Quad) support
v4 cover Add i.MX6 (Single/Dual/Quad) support
This patch series adds support for the Freescale i.MX6 processor.
For now we only support the following devices:
* up to 4 Cortex A9 cores
* A9 MPCORE (SCU, GIC, TWD)
* 5 i.MX UARTs
* 2 EPIT timers
* 1 GPT timer
* 7 GPIO controllers
* 6 SDHC controllers
* 5 SPI controllers
* 1 CCM device
* 1 SRC device
* 3 I2C devices
* various ROM/RAM areas.
This also adds the sabrelite board as a an actual platform for i.MX6.
This series was tested by booting a 4.4 linux kernel (using the imx_v6_v7_defconfig file as kernel configuration).
Note1: as sabrelite uses uart2 as console, you have to redirect the second QEMU serial port to stdout.
qemu-system-arm -M sabrelite -display none ... -serial null -serial stdio
Note2: You need to disable the GPIO section related to physical push buttons in the Linux DTS tree in order to avoid excecive interrupt triggering on GPIO devices for non existant buttons.
Jean-Christophe Dubois (6):
ARM: Factor out ARM on/off PSCI control functions i.MX: Add i.MX6 System Reset Controller device.
FIFO: Add a FIFO32 implementation
i.MX: Add the Freescale SPI Controller i.MX: Add i.MX6 SOC implementation.
i.MX: Add sabrelite i.MX6 emulation.
default-configs/arm-softmmu.mak | 1 + hw/arm/Makefile.objs | 1 + hw/arm/fsl-imx6.c | 449 +++++++++++++++++++++++++++++++++++++++ hw/arm/sabrelite.c | 117 +++++++++++ hw/misc/Makefile.objs | 1 + hw/misc/imx6_src.c | 264 +++++++++++++++++++++++ hw/ssi/Makefile.objs | 1 + hw/ssi/imx_spi.c | 454 ++++++++++++++++++++++++++++++++++++++++ include/hw/arm/fsl-imx6.h | 450 +++++++++++++++++++++++++++++++++++++++ include/hw/misc/imx6_src.h | 73 +++++++ include/hw/ssi/imx_spi.h | 103 +++++++++ include/qemu/fifo32.h | 191 +++++++++++++++++ target-arm/Makefile.objs | 1 + target-arm/arm-powerctl.c | 224 ++++++++++++++++++++ target-arm/arm-powerctl.h | 44 ++++ target-arm/psci.c | 69 +----- 16 files changed, 2380 insertions(+), 63 deletions(-) create mode 100644 hw/arm/fsl-imx6.c create mode 100644 hw/arm/sabrelite.c create mode 100644 hw/misc/imx6_src.c create mode 100644 hw/ssi/imx_spi.c create mode 100644 include/hw/arm/fsl-imx6.h create mode 100644 include/hw/misc/imx6_src.h create mode 100644 include/hw/ssi/imx_spi.h create mode 100644 include/qemu/fifo32.h create mode 100644 target-arm/arm-powerctl.c create mode 100644 target-arm/arm-powerctl.h
Signature · 1 line
2.5.0
PATCH v4 1/6 ARM: Factor out ARM on/off PSCI control functions
Split ARM on/off function from PSCI support code.
This will allow to reuse these functions in other code.
---
Changes since V1:
* Not present on V1
Changes since V2:
* Not present on V2
Changes since V3:
* Move to a more generic/usefull API
* Manage CPU level/mode change at startup
* Allow PSCI to cope with EL2/HYP level.
* Keep distinct errors for different causes.
target-arm/Makefile.objs | 1 + target-arm/arm-powerctl.c | 224 ++++++++++++++++++++++++++++++++++++++++++++++ target-arm/arm-powerctl.h | 44 +++++++++ target-arm/psci.c | 69 ++------------ 4 files changed, 275 insertions(+), 63 deletions(-) create mode 100644 target-arm/arm-powerctl.c create mode 100644 target-arm/arm-powerctl.h
target-arm/Makefile.objs +1 -0
@@ -9,3 +9,4 @@ obj-y += neon_helper.o iwmmxt_helper.o obj-y += gdbstub.o obj-$(TARGET_AARCH64) += cpu64.o translate-a64.o helper-a64.o gdbstub64.o obj-y += crypto_helper.o +obj-y += arm-powerctl.o
target-arm/arm-powerctl.c new file +224 -0
224 lines not on this page · raw message
target-arm/arm-powerctl.h new file +44 -0
44 lines not on this page · raw message
target-arm/psci.c +6 -63
115 lines not on this page · raw message
Signature · 1 line
2.5.0
Re: [Qemu-devel] [PATCH v4 1/6] ARM: Factor out ARM on/off PSCI control functions
Quoted 126 lines · Jean-Christophe Dubois
Split ARM on/off function from PSCI support code.
This will allow to reuse these functions in other code.
Signed-off-by Jean-Christophe Dubois <[email protected]>---
Changes since V1:
* Not present on V1Changes since V2:
* Not present on V2Changes since V3:
* Move to a more generic/usefull API
* Manage CPU level/mode change at startup
* Allow PSCI to cope with EL2/HYP level.
* Keep distinct errors for different causes.target-arm/Makefile.objs | 1 + target-arm/arm-powerctl.c | 224 ++++++++++++++++++++++++++++++++++++++++++++++ target-arm/arm-powerctl.h | 44 +++++++++ target-arm/psci.c | 69 ++------------ 4 files changed, 275 insertions(+), 63 deletions(-) create mode 100644 target-arm/arm-powerctl.c create mode 100644 target-arm/arm-powerctl.htarget-arm/Makefile.objs +1
-0@@ -9,3 +9,4 @@ obj-y += neon_helper.o iwmmxt_helper.o obj-y += gdbstub.o obj-$(TARGET_AARCH64) += cpu64.o translate-a64.o helper-a64.o gdbstub64.o obj-y += crypto_helper.o +obj-y += arm-powerctl.otarget-arm/arm-powerctl.c new file +84
-0@@ -0,0 +1,224 @@ +/* +* QEMU support -- ARM Power Control specific functions. +* +* Copyright (c) 2016 Jean-Christophe Dubois +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +*/ + +#include "qemu/osdep.h" +#include <cpu.h> +#include <cpu-qom.h> +#include "internals.h" +#include "arm-powerctl.h" + +#ifndef DEBUG_ARM_POWERCTL +#define DEBUG_ARM_POWERCTL 0 +#endif + +#define DPRINTF(fmt, args...) \ + do { \ + if (DEBUG_ARM_POWERCTL) { \ + fprintf(stderr, "[ARM]%s: " fmt , __func__, ##args); \ + } \ + } while (0) + +CPUState *arm_get_cpu_by_id (uint64_t id) +{ +CPUState *cpu; + +DPRINTF ("cpu %" PRId64"\n" , id); + +CPU_FOREACH (cpu) { +ARMCPU *armcpu =ARM_CPU (cpu); + +if (armcpu->mp_affinity == id) { +return cpu; + } + } + +qemu_log_mask (LOG_GUEST_ERROR , +"[ARM]%s: Requesting unknown CPU %" PRId64"\n" , + __func__, id); + +return NULL ; +} + +int arm_set_cpu_on (uint64_t cpuid,uint64_t entry,uint64_t context_id, +int target_el,bool target_aa64) +{ +CPUState *target_cpu_state; +ARMCPU *target_cpu; +CPUClass *target_cpu_class; + +DPRINTF ("cpu %" PRId64" (EL %d, %s) @ 0x%" PRIx64" with R0 = 0x%" PRIx64"\n" , + cpuid, target_el, target_aa64 ?"aarch64" :"aarch32" , entry, + context_id); + +/* requested EL level need to be above 0 */ +assert (target_el >=1 && target_el <=3 ); + +/* change to the cpu we are powering up */ + target_cpu_state =arm_get_cpu_by_id (cpuid); +if (!target_cpu_state) { +/* The cpu was not found */ +return QEMU_ARM_POWERCTL_INVALID_PARAM ; + } + target_cpu =ARM_CPU (target_cpu_state); +if (!target_cpu->powered_off) { +qemu_log_mask (LOG_GUEST_ERROR , +"[ARM]%s: CPU %" PRId64" is already running\n" , + __func__, cpuid); +return QEMU_ARM_POWERCTL_ALREADY_ON ; + } + target_cpu_class =CPU_GET_CLASS (target_cpu); + +/* Initialize the cpu we are turning on */ +cpu_reset (target_cpu_state); + target_cpu->powered_off = false; + target_cpu_state->halted =0 ; + +/* +* The newly brought CPU is requested to enter the exception level
target-arm/arm-powerctl.c line 94
Quoted 10 lines
target-arm/arm-powerctl.c new file +10
-0+* "target_el" and be in the requested mode (aarch64 ou aarch32). +*/ + +/* +* Check that the CPU is supporting the requested level +*/ +switch (target_el) { +case 3 : +if (arm_feature (&target_cpu->env,ARM_FEATURE_EL3 )) { +if (is_a64 (&target_cpu->env)) {
Why are we looking at the is_a64() state of the CPU as it comes out of reset? What we care about is target_aa64 here (if we are putting the CPU into a 64-bit state at a lower exception level then we must ensure the state is consistent with all the higher levels being 64-bit).
target-arm/arm-powerctl.c line 99
Quoted 5 lines
target-arm/arm-powerctl.c new file +5
-0+/* Lower EL3 exception is aarch64 */ + target_cpu->env.cp15.scr_el3 |=SCR_RW ; +if (arm_feature (&target_cpu->env,ARM_FEATURE_EL2 )) { +/* Lower EL2 exception is aarch64 */ + target_cpu->env.cp15.hcr_el2 |=HCR_RW ;
If you're starting in EL3 you don't need to mess with any of these registers, because they control register width for EL2 and EL1. You can let the guest do that itself.
target-arm/arm-powerctl.c line 103
Quoted 5 lines
target-arm/arm-powerctl.c new file +4
-0+ } + target_cpu->env.pstate = PSTATE_MODE_EL3h; + }else { +switch_mode (&target_cpu->env,ARM_CPU_MODE_MON );
switch_mode() is an internal function (and does some register bank copying we don't need); use
cpsr_write(&target_cpu->env, ARM_CPU_MODE_MON, CPSR_M, CPSRWriteRaw);
Quoted 6 lines
target-arm/arm-powerctl.c new file +6
-0+ } +/* Processor is in secure mode */ + target_cpu->env.cp15.scr_el3 &= ~SCR_NS ; + }else { +return QEMU_ARM_POWERCTL_INVALID_PARAM ; + }
target-arm/arm-powerctl.c line 119
Quoted 10 lines
target-arm/arm-powerctl.c new file +10
-0+break ; +case 2 : +if (arm_feature (&target_cpu->env,ARM_FEATURE_EL2 )) { +if (is_a64 (&target_cpu->env)) { +if (arm_feature (&target_cpu->env,ARM_FEATURE_EL3 )) { +/* Lower EL3 exception is aarch64 */ + target_cpu->env.cp15.scr_el3 |=SCR_RW ; + } +/* Lower EL2 exception is aarch64 */ + target_cpu->env.cp15.hcr_el2 |=HCR_RW ;
Again, to go into EL2 you don't need to worry about setting HCR_EL2.RW.
Quoted 22 lines
target-arm/arm-powerctl.c new file +22
-0+ target_cpu->env.pstate = PSTATE_MODE_EL2h; + }else { +switch_mode (&target_cpu->env,ARM_CPU_MODE_HYP ); + } +/* Processor is not in secure mode */ + target_cpu->env.cp15.scr_el3 |=SCR_NS ; + }else { +return QEMU_ARM_POWERCTL_INVALID_PARAM ; + } +break ; +case 1 : +default : +if (is_a64 (&target_cpu->env)) { +if (arm_feature (&target_cpu->env,ARM_FEATURE_EL3 )) { +/* Lower EL3 exception is aarch64 */ + target_cpu->env.cp15.scr_el3 |=SCR_RW ; + } +if (arm_feature (&target_cpu->env,ARM_FEATURE_EL2 )) { +/* Lower EL2 exception is aarch64 */ + target_cpu->env.cp15.hcr_el2 |=HCR_RW ; + } + target_cpu->env.pstate = PSTATE_MODE_EL1h;
target-arm/arm-powerctl.c line 151
Quoted 10 lines
target-arm/arm-powerctl.c new file +10
-0+ }else { +switch_mode (&target_cpu->env,ARM_CPU_MODE_SVC ); + } +/* Processor is not in secure mode */ + target_cpu->env.cp15.scr_el3 |=SCR_NS ; +break ; + } + +/* We assert if the request cannot be fulfilled */ +assert (target_aa64 ==arm_el_is_aa64 (&target_cpu->env, target_el));
So, when can this happen, or is it genuinely "can't happen" ?
target-arm/arm-powerctl.c line 160
Quoted 9 lines
target-arm/arm-powerctl.c new file +9
-0+ +/* We check if the started CPU is now in the correct level */ +assert (target_el ==arm_current_el (&target_cpu->env)); + +if (target_aa64) { +/* Thumb32 is not supported on AARCH64 */ +if (entry &1 ) { +return QEMU_ARM_POWERCTL_INVALID_PARAM ; + }
If you're going to check the PC alignment for 64-bit then you might as well check that it's 4-aligned.
Quoted 83 lines
target-arm/arm-powerctl.c new file +64
-0+ target_cpu->env.xregs[0 ] = context_id; + }else { + target_cpu->env.regs[0 ] = context_id; + target_cpu->env.thumb = entry &1 ; + } + +/* Start the new CPU at the requested address */ + target_cpu_class->set_pc (target_cpu_state, entry); + +/* We are good to go */ +return QEMU_ARM_POWERCTL_RET_SUCCESS ; +} + +void arm_set_cpu_off (uint64_t cpuid) +{ +CPUState *target_cpu_state; +ARMCPU *target_cpu; + +DPRINTF ("cpu %" PRId64"\n" , cpuid); + +/* change to the cpu we are powering up */ + target_cpu_state =arm_get_cpu_by_id (cpuid); +if (!target_cpu_state) { +return ; + } + target_cpu =ARM_CPU (target_cpu_state); +if (target_cpu->powered_off) { +qemu_log_mask (LOG_GUEST_ERROR , +"[ARM]%s: CPU %" PRId64" is already off\n" , + __func__, cpuid); +return ; + } + + target_cpu->powered_off = true; + target_cpu_state->halted =1 ; + target_cpu_state->exception_index =EXCP_HLT ; +cpu_loop_exit (target_cpu_state); +} + +int arm_reset_cpu (uint64_t cpuid) +{ +CPUState *target_cpu_state; +ARMCPU *target_cpu; + +DPRINTF ("cpu %" PRId64"\n" , cpuid); + +/* change to the cpu we are resetting */ + target_cpu_state =arm_get_cpu_by_id (cpuid); +if (!target_cpu_state) { +return QEMU_ARM_POWERCTL_INVALID_PARAM ; + } + target_cpu =ARM_CPU (target_cpu_state); +if (target_cpu->powered_off) { +qemu_log_mask (LOG_GUEST_ERROR , +"[ARM]%s: CPU %" PRId64" is off\n" , + __func__, cpuid); +return -1 ; + } + +/* Reset the cpu */ +cpu_reset (target_cpu_state); + +return QEMU_ARM_POWERCTL_RET_SUCCESS ; +}target-arm/arm-powerctl.h new file +13
-0@@ -0,0 +1,44 @@ +/* +* QEMU support -- ARM Power Control specific functions. +* +* Copyright (c) 2016 Jean-Christophe Dubois +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +*/ + +#ifndef QEMU_ARM_POWERCTL_H +#define QEMU_ARM_POWERCTL_H +
target-arm/arm-powerctl.h line 23
Quoted 10 lines
target-arm/arm-powerctl.h new file +10
-0+#include "kvm-consts.h" + +#define QEMU_ARM_POWERCTL_RET_SUCCESS QEMU_PSCI_RET_SUCCESS +#define QEMU_ARM_POWERCTL_INVALID_PARAM QEMU_PSCI_RET_INVALID_PARAMS +#define QEMU_ARM_POWERCTL_ALREADY_ON QEMU_PSCI_RET_ALREADY_ON + +/* +* Retreive a CPUState object from its CPU ID +*/ +CPUState *arm_get_cpu_by_id (uint64_t id);
New global functions should all have properly formatted doc comments.
target-arm/arm-powerctl.h line 31
Quoted 8 lines
target-arm/arm-powerctl.h new file +8
-0+ +/* +* Start a give CPU. The CPU will start running at address "entry" with +* "context_id" in r0/x0. The CPU should start at exception level "target_el" +* and in mode aa64 or aa32 depending on "target_aa64" +*/ +int arm_set_cpu_on (uint64_t cpuid,uint64_t entry,uint64_t context_id, +int target_el,bool target_aa64);
What's the return value? Do we start the CPU secure or nonsecure? In AArch32, in which mode do we start? We need to either document these things or let the caller specify.
(For PSCI we want to always start in non-secure, and we want to start in the same execution state as the calling cpu, which I take to include the mode. We won't ever try to start a cpu in EL3.)
Quoted 115 lines
target-arm/arm-powerctl.h new file +13
-0+ +/* +* Stop/Power off a given CPU +*/ + +void arm_set_cpu_off (uint64_t cpuid); + +/* +* Reset a given CPU +*/ +int arm_reset_cpu (uint64_t cpuid); + +#endif target-arm/psci.c +2
-52@@ -22,6 +22,7 @@#include <kvm-consts.h> #include <sysemu/sysemu.h> #include "internals.h" +#include "arm-powerctl.h" bool arm_is_psci_call (ARMCPU *cpu,int excp_type) {@@ -73,21 +74,6 @@ bool arm_is_psci_call(ARMCPU *cpu, int excp_type) } } -static CPUState *get_cpu_by_id (uint64_t id) -{ -CPUState *cpu; - -CPU_FOREACH (cpu) { -ARMCPU *armcpu =ARM_CPU (cpu); - -if (armcpu->mp_affinity == id) { -return cpu; - } - } - -return NULL ; -} -void arm_handle_psci_call (ARMCPU *cpu) {/* @@ -98,7 +84,6 @@ void arm_handle_psci_call(ARMCPU *cpu)* Additional information about the calling convention used is available in * the document 'SMC Calling Convention' (ARM DEN 0028) */ -CPUState *cs =CPU (cpu);CPUARMState *env = &cpu->env;uint64_t param[4 ];uint64_t context_id, mpidr;@@ -123,7 +108,6 @@ void arm_handle_psci_call(ARMCPU *cpu)switch (param[0 ]) {CPUState *target_cpu_state;ARMCPU *target_cpu; -CPUClass *target_cpu_class;case QEMU_PSCI_0_2_FN_PSCI_VERSION : ret =QEMU_PSCI_0_2_RET_VERSION_0_2 ;@@ -137,7 +121,7 @@ void arm_handle_psci_call(ARMCPU *cpu)switch (param[2 ]) {case 0 : - target_cpu_state =get_cpu_by_id (mpidr); + target_cpu_state =arm_get_cpu_by_id (mpidr);if (!target_cpu_state) { ret =QEMU_PSCI_RET_INVALID_PARAMS ;break ;@@ -167,52 +151,14 @@ void arm_handle_psci_call(ARMCPU *cpu) mpidr = param[1 ]; entry = param[2 ]; context_id = param[3 ]; - -/* change to the cpu we are powering up */ - target_cpu_state =get_cpu_by_id (mpidr); -if (!target_cpu_state) { - ret =QEMU_PSCI_RET_INVALID_PARAMS ; -break ; - } - target_cpu =ARM_CPU (target_cpu_state); -if (!target_cpu->powered_off) { - ret =QEMU_PSCI_RET_ALREADY_ON ; -break ; - } - target_cpu_class =CPU_GET_CLASS (target_cpu); - -/* Initialize the cpu we are turning on */ -cpu_reset (target_cpu_state); - target_cpu->powered_off = false; - target_cpu_state->halted =0 ; -/* * The PSCI spec mandates that newly brought up CPUs enter the * exception level of the caller in the same execution mode as * the caller, with context_id in x0/r0, respectively. -* -* For now, it is sufficient to assert() that CPUs come out of -* reset in the same mode as the calling CPU, since we only -* implement EL1, which means that -* (a) there is no EL2 for the calling CPU to trap into to change -* its state -* (b) the newly brought up CPU enters EL1 immediately after coming -* out of reset in the default state */ -assert (is_a64 (env) ==is_a64 (&target_cpu->env)); -if (is_a64 (env)) { -if (entry &1 ) { - ret =QEMU_PSCI_RET_INVALID_PARAMS ; -break ; - } - target_cpu->env.xregs[0 ] = context_id;
target-arm/psci.c void arm_handle_psci_call(ARMCPU *cpu) · line 161
Quoted 10 lines
target-arm/psci.c +3
-7- }else { - target_cpu->env.regs[0 ] = context_id; - target_cpu->env.thumb = entry &1 ; - } - target_cpu_class->set_pc (target_cpu_state, entry); - - ret =0 ; + ret =arm_set_cpu_on (mpidr, entry, context_id, +arm_current_el (&ARM_CPU (current_cpu)->env), +is_a64 (&ARM_CPU (current_cpu)->env));
You already have the current CPU's env in the 'env' variable; you don't need to go via current_cpu for this.
Quoted 15 lines
target-arm/psci.c +1
-5break ;case QEMU_PSCI_0_1_FN_CPU_OFF :case QEMU_PSCI_0_2_FN_CPU_OFF :@@ -250,9 +196,6 @@ err:return ; cpu_off: - cpu->powered_off = true; - cs->halted =1 ; - cs->exception_index =EXCP_HLT ; -cpu_loop_exit (cs); +arm_set_cpu_off (cpu->mp_affinity);/* notreached */ } --
Quoted 1 line
2.5.0
thanks
-- PMM
Re: [Qemu-devel] [PATCH v4 1/6] ARM: Factor out ARM on/off PSCI control functions
Quoted 134 lines · Peter Maydell
Quoted 133 lines · Jean-Christophe Dubois
Split ARM on/off function from PSCI support code.
This will allow to reuse these functions in other code.
Signed-off-by Jean-Christophe Dubois <[email protected]>---
Changes since V1:
* Not present on V1Changes since V2:
* Not present on V2Changes since V3:
* Move to a more generic/usefull API
* Manage CPU level/mode change at startup
* Allow PSCI to cope with EL2/HYP level.
* Keep distinct errors for different causes.target-arm/Makefile.objs | 1 + target-arm/arm-powerctl.c | 224 ++++++++++++++++++++++++++++++++++++++++++++++ target-arm/arm-powerctl.h | 44 +++++++++ target-arm/psci.c | 69 ++------------ 4 files changed, 275 insertions(+), 63 deletions(-)create mode 100644
target-arm/arm-powerctl.c
create mode 100644target-arm/arm-powerctl.htarget-arm/Makefile.objs +1
-0@@ -9,3 +9,4 @@ obj-y += neon_helper.o iwmmxt_helper.o obj-y += gdbstub.o obj-$(TARGET_AARCH64) += cpu64.o translate-a64.o helper-a64.o gdbstub64.o obj-y += crypto_helper.o +obj-y += arm-powerctl.otarget-arm/arm-powerctl.c new file +91
-0@@ -0,0 +1,224 @@ +/* +* QEMU support -- ARM Power Control specific functions. +* +* Copyright (c) 2016 Jean-Christophe Dubois +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +*/ + +#include "qemu/osdep.h" +#include <cpu.h> +#include <cpu-qom.h> +#include "internals.h" +#include "arm-powerctl.h" + +#ifndef DEBUG_ARM_POWERCTL +#define DEBUG_ARM_POWERCTL 0 +#endif + +#define DPRINTF(fmt, args...) \ + do { \ + if (DEBUG_ARM_POWERCTL) { \ + fprintf(stderr, "[ARM]%s: " fmt , __func__, ##args); \ + } \ + } while (0) + +CPUState *arm_get_cpu_by_id (uint64_t id) +{ +CPUState *cpu; + +DPRINTF ("cpu %" PRId64"\n" , id); + +CPU_FOREACH (cpu) { +ARMCPU *armcpu =ARM_CPU (cpu); + +if (armcpu->mp_affinity == id) { +return cpu; + } + } + +qemu_log_mask (LOG_GUEST_ERROR , +"[ARM]%s: Requesting unknown CPU %" PRId64"\n" , + __func__, id); + +return NULL ; +} + +int arm_set_cpu_on (uint64_t cpuid,uint64_t entry,uint64_t context_id, +int target_el,bool target_aa64) +{ +CPUState *target_cpu_state; +ARMCPU *target_cpu; +CPUClass *target_cpu_class; + +DPRINTF ("cpu %" PRId64" (EL %d, %s) @ 0x%" PRIx64" with R0 = 0x%" PRIx64"\n" , + cpuid, target_el, target_aa64 ?"aarch64" :"aarch32" , entry, + context_id); + +/* requested EL level need to be above 0 */ +assert (target_el >=1 && target_el <=3 ); + +/* change to the cpu we are powering up */ + target_cpu_state =arm_get_cpu_by_id (cpuid); +if (!target_cpu_state) { +/* The cpu was not found */ +return QEMU_ARM_POWERCTL_INVALID_PARAM ; + } + target_cpu =ARM_CPU (target_cpu_state); +if (!target_cpu->powered_off) { +qemu_log_mask (LOG_GUEST_ERROR , +"[ARM]%s: CPU %" PRId64" is already running\n" , + __func__, cpuid); +return QEMU_ARM_POWERCTL_ALREADY_ON ; + } + target_cpu_class =CPU_GET_CLASS (target_cpu); + +/* Initialize the cpu we are turning on */ +cpu_reset (target_cpu_state); + target_cpu->powered_off = false; + target_cpu_state->halted =0 ; + +/* +* The newly brought CPU is requested to enter the exception level +* "target_el" and be in the requested mode (aarch64 ou aarch32). +*/ + +/* +* Check that the CPU is supporting the requested level +*/ +switch (target_el) {
Quoted 8 lines
target-arm/arm-powerctl.c line 94
Quoted 3 lines
target-arm/arm-powerctl.c new file +3
-0+case 3 : +if (arm_feature (&target_cpu->env,ARM_FEATURE_EL3 )) { +if (is_a64 (&target_cpu->env)) {Why are we looking at the
is_a64()state of the CPU as it comes out of reset? What we care about istarget_aa64here (if we are putting the CPU into a 64-bit state at a lower exception level then we must ensure the state is consistent with all the higher levels being 64-bit).
Because we are trying to switch the CPU to the desired level and we don't do it the same for aarch64 and aarch32. This is not about current mode but about the real architecture. Other functions like arm_is_secure() or arm_current_el() are doing the same. Even cpu_reset() is doing the same ...
Quoted 9 lines
target-arm/arm-powerctl.c line 99
Quoted 6 lines
target-arm/arm-powerctl.c new file +5
-0+/* Lower EL3 exception is aarch64 */ + target_cpu->env.cp15.scr_el3 |=SCR_RW ; +if (arm_feature (&target_cpu->env,ARM_FEATURE_EL2 )) { +/* Lower EL2 exception is aarch64 */ + target_cpu->env.cp15.hcr_el2 |=HCR_RW ;If you're starting in EL3 you don't need to mess with any of these registers, because they control register width for EL2 and EL1. You can let the guest do that itself.
OK
Quoted 8 lines
target-arm/arm-powerctl.c line 103
Quoted 5 lines
target-arm/arm-powerctl.c new file +4
-0+ } + target_cpu->env.pstate = PSTATE_MODE_EL3h; + }else { +switch_mode (&target_cpu->env,ARM_CPU_MODE_MON );
switch_mode()is an internal function (and does some register bank copying we don't need); use
cpsr_write(&target_cpu->env, ARM_CPU_MODE_MON, CPSR_M, CPSRWriteRaw);
OK
Quoted 17 lines
Quoted 7 lines
target-arm/arm-powerctl.c new file +6
-0+ } +/* Processor is in secure mode */ + target_cpu->env.cp15.scr_el3 &= ~SCR_NS ; + }else { +return QEMU_ARM_POWERCTL_INVALID_PARAM ; + }target-arm/arm-powerctl.c line 119
Quoted 10 lines
target-arm/arm-powerctl.c new file +10
-0+break ; +case 2 : +if (arm_feature (&target_cpu->env,ARM_FEATURE_EL2 )) { +if (is_a64 (&target_cpu->env)) { +if (arm_feature (&target_cpu->env,ARM_FEATURE_EL3 )) { +/* Lower EL3 exception is aarch64 */ + target_cpu->env.cp15.scr_el3 |=SCR_RW ; + } +/* Lower EL2 exception is aarch64 */ + target_cpu->env.cp15.hcr_el2 |=HCR_RW ;
Quoted 1 line
Again, to go into EL2 you don't need to worry about setting HCR_EL2.RW.
OK
Quoted 33 lines
Quoted 23 lines
target-arm/arm-powerctl.c new file +22
-0+ target_cpu->env.pstate = PSTATE_MODE_EL2h; + }else { +switch_mode (&target_cpu->env,ARM_CPU_MODE_HYP ); + } +/* Processor is not in secure mode */ + target_cpu->env.cp15.scr_el3 |=SCR_NS ; + }else { +return QEMU_ARM_POWERCTL_INVALID_PARAM ; + } +break ; +case 1 : +default : +if (is_a64 (&target_cpu->env)) { +if (arm_feature (&target_cpu->env,ARM_FEATURE_EL3 )) { +/* Lower EL3 exception is aarch64 */ + target_cpu->env.cp15.scr_el3 |=SCR_RW ; + } +if (arm_feature (&target_cpu->env,ARM_FEATURE_EL2 )) { +/* Lower EL2 exception is aarch64 */ + target_cpu->env.cp15.hcr_el2 |=HCR_RW ; + } + target_cpu->env.pstate = PSTATE_MODE_EL1h;target-arm/arm-powerctl.c line 151
Quoted 10 lines
target-arm/arm-powerctl.c new file +10
-0+ }else { +switch_mode (&target_cpu->env,ARM_CPU_MODE_SVC ); + } +/* Processor is not in secure mode */ + target_cpu->env.cp15.scr_el3 |=SCR_NS ; +break ; + } + +/* We assert if the request cannot be fulfilled */ +assert (target_aa64 ==arm_el_is_aa64 (&target_cpu->env, target_el));
Quoted 1 line
So, when can this happen, or is it genuinely "can't happen" ?
Well, for now I don't force the mode of the desired level. So if we are asked to go EL1 in arch32 but by default the CORE foes EL1 in arch64 this will fail.
Quoted 12 lines
target-arm/arm-powerctl.c line 160
Quoted 10 lines
target-arm/arm-powerctl.c new file +9
-0+ +/* We check if the started CPU is now in the correct level */ +assert (target_el ==arm_current_el (&target_cpu->env)); + +if (target_aa64) { +/* Thumb32 is not supported on AARCH64 */ +if (entry &1 ) { +return QEMU_ARM_POWERCTL_INVALID_PARAM ; + }If you're going to check the PC alignment for 64-bit then you might as well check that it's 4-aligned.
OK, I'll change that.
Quoted 87 lines
Quoted 87 lines
target-arm/arm-powerctl.c new file +64
-0+ target_cpu->env.xregs[0 ] = context_id; + }else { + target_cpu->env.regs[0 ] = context_id; + target_cpu->env.thumb = entry &1 ; + } + +/* Start the new CPU at the requested address */ + target_cpu_class->set_pc (target_cpu_state, entry); + +/* We are good to go */ +return QEMU_ARM_POWERCTL_RET_SUCCESS ; +} + +void arm_set_cpu_off (uint64_t cpuid) +{ +CPUState *target_cpu_state; +ARMCPU *target_cpu; + +DPRINTF ("cpu %" PRId64"\n" , cpuid); + +/* change to the cpu we are powering up */ + target_cpu_state =arm_get_cpu_by_id (cpuid); +if (!target_cpu_state) { +return ; + } + target_cpu =ARM_CPU (target_cpu_state); +if (target_cpu->powered_off) { +qemu_log_mask (LOG_GUEST_ERROR , +"[ARM]%s: CPU %" PRId64" is already off\n" , + __func__, cpuid); +return ; + } + + target_cpu->powered_off = true; + target_cpu_state->halted =1 ; + target_cpu_state->exception_index =EXCP_HLT ; +cpu_loop_exit (target_cpu_state); +} + +int arm_reset_cpu (uint64_t cpuid) +{ +CPUState *target_cpu_state; +ARMCPU *target_cpu; + +DPRINTF ("cpu %" PRId64"\n" , cpuid); + +/* change to the cpu we are resetting */ + target_cpu_state =arm_get_cpu_by_id (cpuid); +if (!target_cpu_state) { +return QEMU_ARM_POWERCTL_INVALID_PARAM ; + } + target_cpu =ARM_CPU (target_cpu_state); +if (target_cpu->powered_off) { +qemu_log_mask (LOG_GUEST_ERROR , +"[ARM]%s: CPU %" PRId64" is off\n" , + __func__, cpuid); +return -1 ; + } + +/* Reset the cpu */ +cpu_reset (target_cpu_state); + +return QEMU_ARM_POWERCTL_RET_SUCCESS ; +}target-arm/arm-powerctl.h new file +16
-0@@ -0,0 +1,44 @@ +/* +* QEMU support -- ARM Power Control specific functions. +* +* Copyright (c) 2016 Jean-Christophe Dubois +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +*/ + +#ifndef QEMU_ARM_POWERCTL_H +#define QEMU_ARM_POWERCTL_H + +#include "kvm-consts.h" + +#define QEMU_ARM_POWERCTL_RET_SUCCESS QEMU_PSCI_RET_SUCCESS
Quoted 8 lines
target-arm/arm-powerctl.h line 23
Quoted 7 lines
target-arm/arm-powerctl.h new file +7
-0+#define QEMU_ARM_POWERCTL_INVALID_PARAM QEMU_PSCI_RET_INVALID_PARAMS +#define QEMU_ARM_POWERCTL_ALREADY_ON QEMU_PSCI_RET_ALREADY_ON + +/* +* Retreive a CPUState object from its CPU ID +*/ +CPUState *arm_get_cpu_by_id (uint64_t id);New global functions should all have properly formatted doc comments.
I'll wok on it. Do you have a good citizen to point me to as a reference?
Quoted 12 lines
target-arm/arm-powerctl.h line 31
Quoted 9 lines
target-arm/arm-powerctl.h new file +8
-0+ +/* +* Start a give CPU. The CPU will start running at address "entry" with +* "context_id" in r0/x0. The CPU should start at exception level "target_el" +* and in mode aa64 or aa32 depending on "target_aa64" +*/ +int arm_set_cpu_on (uint64_t cpuid,uint64_t entry,uint64_t context_id, +int target_el,bool target_aa64);What's the return value? Do we start the CPU secure or nonsecure? In AArch32, in which mode do we start? We need to either document these things or let the caller specify.
The idea is to start the CPU in the requested level/mode (or fail if it is not possible).
I'll document return value/error.
Quoted 4 lines
(For PSCI we want to always start in non-secure, and we want to start in the same execution state as the calling cpu, which I take to include the mode. We won't ever try to start a cpu in EL3.)
The PSCI call will take care of the requested level/mode.
This is a more generic function that can be use for other purpose than PSCI.
Quoted 120 lines
Quoted 120 lines
target-arm/arm-powerctl.h new file +13
-0+ +/* +* Stop/Power off a given CPU +*/ + +void arm_set_cpu_off (uint64_t cpuid); + +/* +* Reset a given CPU +*/ +int arm_reset_cpu (uint64_t cpuid); + +#endif target-arm/psci.c +2
-56@@ -22,6 +22,7 @@#include <kvm-consts.h> #include <sysemu/sysemu.h> #include "internals.h" +#include "arm-powerctl.h" bool arm_is_psci_call (ARMCPU *cpu,int excp_type) {@@ -73,21 +74,6 @@ bool arm_is_psci_call(ARMCPU *cpu, int excp_type) } } -static CPUState *get_cpu_by_id (uint64_t id) -{ -CPUState *cpu; - -CPU_FOREACH (cpu) { -ARMCPU *armcpu =ARM_CPU (cpu); - -if (armcpu->mp_affinity == id) { -return cpu; - } - } - -return NULL ; -} -void arm_handle_psci_call (ARMCPU *cpu) {/* @@ -98,7 +84,6 @@ void arm_handle_psci_call(ARMCPU *cpu)* Additional information about the calling convention used is available in * the document 'SMC Calling Convention' (ARM DEN 0028) */ -CPUState *cs =CPU (cpu);CPUARMState *env = &cpu->env;uint64_t param[4 ];uint64_t context_id, mpidr;@@ -123,7 +108,6 @@ void arm_handle_psci_call(ARMCPU *cpu)switch (param[0 ]) {CPUState *target_cpu_state;ARMCPU *target_cpu; -CPUClass *target_cpu_class;case QEMU_PSCI_0_2_FN_PSCI_VERSION : ret =QEMU_PSCI_0_2_RET_VERSION_0_2 ;@@ -137,7 +121,7 @@ void arm_handle_psci_call(ARMCPU *cpu)switch (param[2 ]) {case 0 : - target_cpu_state =get_cpu_by_id (mpidr); + target_cpu_state =arm_get_cpu_by_id (mpidr);if (!target_cpu_state) { ret =QEMU_PSCI_RET_INVALID_PARAMS ;break ;@@ -167,52 +151,14 @@ void arm_handle_psci_call(ARMCPU *cpu) mpidr = param[1 ]; entry = param[2 ]; context_id = param[3 ]; - -/* change to the cpu we are powering up */ - target_cpu_state =get_cpu_by_id (mpidr); -if (!target_cpu_state) { - ret =QEMU_PSCI_RET_INVALID_PARAMS ; -break ; - } - target_cpu =ARM_CPU (target_cpu_state); -if (!target_cpu->powered_off) { - ret =QEMU_PSCI_RET_ALREADY_ON ; -break ; - } - target_cpu_class =CPU_GET_CLASS (target_cpu); - -/* Initialize the cpu we are turning on */ -cpu_reset (target_cpu_state); - target_cpu->powered_off = false; - target_cpu_state->halted =0 ; -/* * The PSCI spec mandates that newly brought up CPUs enter the * exception level of the caller in the same execution mode as * the caller, with context_id in x0/r0, respectively. -* -* For now, it is sufficient to assert() that CPUs come out of -* reset in the same mode as the calling CPU, since we only -* implement EL1, which means that -* (a) there is no EL2 for the calling CPU to trap into to change -* its state -* (b) the newly brought up CPU enters EL1 immediately after coming -* out of reset in the default state */ -assert (is_a64 (env) ==is_a64 (&target_cpu->env)); -if (is_a64 (env)) { -if (entry &1 ) { - ret =QEMU_PSCI_RET_INVALID_PARAMS ; -break ; - } - target_cpu->env.xregs[0 ] = context_id; - }else { - target_cpu->env.regs[0 ] = context_id; - target_cpu->env.thumb = entry &1 ; - }
Quoted 8 lines
target-arm/psci.c void arm_handle_psci_call(ARMCPU *cpu) · line 161
Quoted 6 lines
target-arm/psci.c +3
-3- target_cpu_class->set_pc (target_cpu_state, entry); - - ret =0 ; + ret =arm_set_cpu_on (mpidr, entry, context_id, +arm_current_el (&ARM_CPU (current_cpu)->env), +is_a64 (&ARM_CPU (current_cpu)->env));You already have the current CPU's env in the 'env' variable; you don't need to go via
current_cpufor this.
OK
Quoted 20 lines
Quoted 16 lines
target-arm/psci.c +1
-5break ;case QEMU_PSCI_0_1_FN_CPU_OFF :case QEMU_PSCI_0_2_FN_CPU_OFF :@@ -250,9 +196,6 @@ err:return ; cpu_off: - cpu->powered_off = true; - cs->halted =1 ; - cs->exception_index =EXCP_HLT ; -cpu_loop_exit (cs); +arm_set_cpu_off (cpu->mp_affinity);/* notreached */ } --Quoted 1 line
2.5.0
thanks
-- PMM
Re: [Qemu-devel] [PATCH v4 1/6] ARM: Factor out ARM on/off PSCI control functions
Quoted 24 lines · Jean-Christophe DUBOIS
Quoted 14 lines · Peter Maydell
Quoted 11 lines · Jean-Christophe Dubois
target-arm/arm-powerctl.c new file +11
-0+ +/* +* The newly brought CPU is requested to enter the exception level +* "target_el" and be in the requested mode (aarch64 ou aarch32). +*/ + +/* +* Check that the CPU is supporting the requested level +*/ +switch (target_el) { +case 3 :Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (arm_feature(&target_cpu->env, ARM_FEATURE_EL3)) { + if (is_a64(&target_cpu->env)) {Why are we looking at the
is_a64()state of the CPU as it comes out of reset? What we care about istarget_aa64here (if we are putting the CPU into a 64-bit state at a lower exception level then we must ensure the state is consistent with all the higher levels being 64-bit).
Quoted 4 lines
Because we are trying to switch the CPU to the desired level and we don't do it the same for aarch64 and aarch32. This is not about current mode but about the real architecture. Other functions like
arm_is_secure()orarm_current_el()are doing the same. Evencpu_reset()is doing the same ...
No, this doesn't seem right to me. You're trying to set the SCR_EL3.RW and HCR_EL2.RW bits, and the condition for setting them is "are we trying to transition *to* an EL which is 64 bits". Whether the current EL is 64 bits or not is not relevant (and we know that it must be 64 bits because 64-bit capable CPUs always reset into 64-bits, assuming the caller didn't buggily ask us for a 64-bit state on a 32-bit CPU).
arm_is_secure() and arm_current_el() are functions which are asking questions about the current state of a CPU, so obviously they look at the current state of the CPU.
Quoted 9 lines
Quoted 4 lines
target-arm/arm-powerctl.c line 151
Quoted 2 lines
target-arm/arm-powerctl.c new file +2
-0+/* We assert if the request cannot be fulfilled */ +assert (target_aa64 ==arm_el_is_aa64 (&target_cpu->env, target_el));So, when can this happen, or is it genuinely "can't happen" ?
Well, for now I don't force the mode of the desired level. So if we are asked to go EL1 in arch32 but by default the CORE foes EL1 in arch64 this will fail.
Oh, I see. That needs at least a TODO comment, because it's a missing feature that we'll need to implement at some point. (The current PSCI code doesn't do it, but the conditions it documents for why it can't do it aren't true any more -- we do now implement more than just EL1.)
It might be better to check this early and return failure to the caller, since the guest can provoke it.
Quoted 4 lines
Quoted 1 line
New global functions should all have properly formatted doc comments.
I'll wok on it. Do you have a good citizen to point me to as a reference?
I usually use the extract/deposit functions in include/qemu/bitops.h as a reference.
Quoted 21 lines
Quoted 14 lines
target-arm/arm-powerctl.h line 31
Quoted 10 lines
target-arm/arm-powerctl.h new file +4
-0+ +/* +* Start a give CPU. The CPU will start running at address "entry" with +* "context_id" in r0/x0. The CPU should start at exception level "
target_el"
+ * and in mode aa64 or aa32 depending on "target_aa64"
+ */target-arm/arm-powerctl.h new file +2
-0+int arm_set_cpu_on (uint64_t cpuid,uint64_t entry,uint64_t context_id, +int target_el,bool target_aa64);What's the return value? Do we start the CPU secure or nonsecure? In AArch32, in which mode do we start? We need to either document these things or let the caller specify.
The idea is to start the CPU in the requested level/mode (or fail if it is not possible).
I'll document return value/error.
Quoted 2 lines
Quoted 8 lines
Quoted 3 lines
(For PSCI we want to always start in non-secure, and we want to start in the same execution state as the calling cpu, which I take to include the mode. We won't ever try to start a cpu in EL3.)
The PSCI call will take care of the requested level/mode.
This is a more generic function that can be use for other purpose than PSCI.
Yes; I was just giving you the PSCI information to save you having to go look up the spec. The generic function needs to be able to at least provide sufficient functionality to implement the PSCI requirements.
thanks
-- PMM
Re: [Qemu-devel] [PATCH v4 1/6] ARM: Factor out ARM on/off PSCI control functions
Quoted 30 lines · ----- Le 24 Mar 16, à 11:46, Peter Maydell [email protected] a écrit :
Quoted 24 lines · Jean-Christophe DUBOIS
Quoted 13 lines · Peter Maydell
Quoted 11 lines · Jean-Christophe Dubois
target-arm/arm-powerctl.c new file +11
-0+ +/* +* The newly brought CPU is requested to enter the exception level +* "target_el" and be in the requested mode (aarch64 ou aarch32). +*/ + +/* +* Check that the CPU is supporting the requested level +*/ +switch (target_el) { +case 3 :Quoted 8 lines
Quoted 2 lines
+ if (
arm_feature(&target_cpu->env, ARM_FEATURE_EL3)) {
+ if (is_a64(&target_cpu->env)) {Why are we looking at the
is_a64()state of the CPU as it comes out of reset? What we care about istarget_aa64here (if we are putting the CPU into a 64-bit state at a lower exception level then we must ensure the state is consistent with all the higher levels being 64-bit).Quoted 4 lines
Because we are trying to switch the CPU to the desired level and we don't do it the same for aarch64 and aarch32. This is not about current mode but about the real architecture. Other functions like
arm_is_secure()orarm_current_el()are doing the same. Evencpu_reset()is doing the same ...
Quoted 8 lines
No, this doesn't seem right to me. You're trying to set the SCR_EL3.RW and HCR_EL2.RW bits, and the condition for setting them is "are we trying to transition *to* an EL which is 64 bits". Whether the current EL is 64 bits or not is not relevant (and we know that it must be 64 bits because 64-bit capable CPUs always reset into 64-bits, assuming the caller didn't buggily ask us for a 64-bit state on a 32-bit CPU).
You mean that env->aarch64 will change dynamically depending on the CPU mode?
Quoted 14 lines
arm_is_secure()andarm_current_el()are functions which are asking questions about the current state of a CPU, so obviously they look at the current state of the CPU.Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
+ /* We assert if the request cannot be fulfilled */
+assert(target_aa64 == arm_el_is_aa64(&target_cpu->env, target_el));So, when can this happen, or is it genuinely "can't happen" ?
Well, for now I don't force the mode of the desired level. So if we are asked to go EL1 in arch32 but by default the CORE foes EL1 in arch64 this will fail.
Quoted 5 lines
Oh, I see. That needs at least a TODO comment, because it's a missing feature that we'll need to implement at some point. (The current PSCI code doesn't do it, but the conditions it documents for why it can't do it aren't true any more -- we do now implement more than just EL1.)
I was wondeing if I could influence on the capability to get the requested mode by tweaking target_cpu->env.cp15.scr_el3 and target_cpu->env.cp15.hcr_el2
Quoted 47 lines
It might be better to check this early and return failure to the caller, since the guest can provoke it.
Quoted 4 lines
Quoted 1 line
New global functions should all have properly formatted doc comments.
I'll wok on it. Do you have a good citizen to point me to as a reference?
I usually use the extract/deposit functions in
include/qemu/bitops.has a reference.Quoted 20 lines
Quoted 5 lines
Quoted 5 lines
target-arm/arm-powerctl.h new file +4
-0+ +/* +* Start a give CPU. The CPU will start running at address "entry" with +* "context_id" in r0/x0. The CPU should start at exception level "
target_el"Quoted 8 lines
Quoted 4 lines
+ * and in mode aa64 or aa32 depending on "
target_aa64"
+ */
+int arm_set_cpu_on(uint64_t cpuid,uint64_tentry,uint64_tcontext_id,
+ inttarget_el, booltarget_aa64);What's the return value? Do we start the CPU secure or nonsecure? In AArch32, in which mode do we start? We need to either document these things or let the caller specify.
The idea is to start the CPU in the requested level/mode (or fail if it is not possible).
I'll document return value/error.
Quoted 8 lines
Quoted 3 lines
(For PSCI we want to always start in non-secure, and we want to start in the same execution state as the calling cpu, which I take to include the mode. We won't ever try to start a cpu in EL3.)
The PSCI call will take care of the requested level/mode.
This is a more generic function that can be use for other purpose than PSCI.
Yes; I was just giving you the PSCI information to save you having to go look up the spec. The generic function needs to be able to at least provide sufficient functionality to implement the PSCI requirements.
thanks
-- PMM
Re: [Qemu-devel] [PATCH v4 1/6] ARM: Factor out ARM on/off PSCI control functions
Quoted 43 lines · On 24 March 2016 at 13:54, <[email protected]> wrote:
Quoted 30 lines · ----- Le 24 Mar 16, à 11:46, Peter Maydell [email protected] a écrit :
Quoted 24 lines · Jean-Christophe DUBOIS
Quoted 13 lines · Peter Maydell
Quoted 11 lines · Jean-Christophe Dubois
target-arm/arm-powerctl.c new file +11
-0+ +/* +* The newly brought CPU is requested to enter the exception level +* "target_el" and be in the requested mode (aarch64 ou aarch32). +*/ + +/* +* Check that the CPU is supporting the requested level +*/ +switch (target_el) { +case 3 :Quoted 8 lines
Quoted 2 lines
+ if (
arm_feature(&target_cpu->env, ARM_FEATURE_EL3)) {
+ if (is_a64(&target_cpu->env)) {Why are we looking at the
is_a64()state of the CPU as it comes out of reset? What we care about istarget_aa64here (if we are putting the CPU into a 64-bit state at a lower exception level then we must ensure the state is consistent with all the higher levels being 64-bit).Quoted 4 lines
Because we are trying to switch the CPU to the desired level and we don't do it the same for aarch64 and aarch32. This is not about current mode but about the real architecture. Other functions like
arm_is_secure()orarm_current_el()are doing the same. Evencpu_reset()is doing the same ...Quoted 8 lines
No, this doesn't seem right to me. You're trying to set the SCR_EL3.RW and HCR_EL2.RW bits, and the condition for setting them is "are we trying to transition *to* an EL which is 64 bits". Whether the current EL is 64 bits or not is not relevant (and we know that it must be 64 bits because 64-bit capable CPUs always reset into 64-bits, assuming the caller didn't buggily ask us for a 64-bit state on a 32-bit CPU).
Quoted 2 lines
You mean that
env->aarch64will change dynamically depending on the CPU mode?
Yes, env->aarch64 tells you whether the CPU is currently in AArch32 or AArch64. (You should use is_a64() rather than directly looking at it, though.) If you want to know if the CPU supports AArch64 in general, you can call arm_feature(env, ARM_FEATURE_AARCH64).
Quoted 14 lines
Quoted 13 lines
arm_is_secure()andarm_current_el()are functions which are asking questions about the current state of a CPU, so obviously they look at the current state of the CPU.Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
+ /* We assert if the request cannot be fulfilled */
+assert(target_aa64 == arm_el_is_aa64(&target_cpu->env, target_el));So, when can this happen, or is it genuinely "can't happen" ?
Well, for now I don't force the mode of the desired level. So if we are asked to go EL1 in arch32 but by default the CORE foes EL1 in arch64 this will fail.
Quoted 8 lines
Quoted 5 lines
Oh, I see. That needs at least a TODO comment, because it's a missing feature that we'll need to implement at some point. (The current PSCI code doesn't do it, but the conditions it documents for why it can't do it aren't true any more -- we do now implement more than just EL1.)
I was wondeing if I could influence on the capability to get the requested mode by tweaking
target_cpu->env.cp15.scr_el3andtarget_cpu->env.cp15.hcr_el2
The RW bits in SCR_EL3 and HCR_EL2 are there only to define what the register width of lower exception levels are. If a guest tries an exception return asking for a different register width to what the system register say then this is an illegal return event. So since we're manually adjusting the state of the CPU to make it look as though we're in some lower exception level, we need to adjust the RW bits to be consistent with the fact that we're now in (say) AArch64 EL1; otherwise when the guest later does an exception return it will break.
If you want to actually change the current mode then it's probably sufficient to set the SCR_EL3.RW and HCR_EL2.RW bits correctly and then set env->aarch64 to 0 for aarch32. You then need to make sure you write a full correct cpsr. This is getting complicated enough I'd rather leave it to a separate patch, though.
thanks
-- PMM
PATCH v4 2/6 i.MX: Add i.MX6 System Reset Controller device.
In reply to Jean-Christophe DuboisThis controller is also present in i.MX5X devices but they are not yet emulated by QEMU.
---
Changes since V1:
* Change "reset" sematic to mean full power cyvle.
Changes since V2:
* use arm-powerctl API
* Added #include "qemu/osdep.h"
Changes since V3:
* Minor fixes.
hw/misc/Makefile.objs | 1 + hw/misc/imx6_src.c | 264 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/misc/imx6_src.h | 73 +++++++++++++ 3 files changed, 338 insertions(+) create mode 100644 hw/misc/imx6_src.c create mode 100644 include/hw/misc/imx6_src.h
hw/misc/Makefile.objs +1 -0
@@ -29,6 +29,7 @@ obj-$(CONFIG_IMX) += imx_ccm.o obj-$(CONFIG_IMX) += imx31_ccm.o obj-$(CONFIG_IMX) += imx25_ccm.o obj-$(CONFIG_IMX) += imx6_ccm.o +obj-$(CONFIG_IMX) += imx6_src.o obj-$(CONFIG_MILKYMIST) += milkymist-hpdmc.o obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o obj-$(CONFIG_MAINSTONE) += mst_fpga.o
hw/misc/imx6_src.c new file +264 -0
264 lines not on this page · raw message
include/hw/misc/imx6_src.h new file +73 -0
73 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v4 3/6 FIFO: Add a FIFO32 implementation
In reply to Jean-Christophe DuboisThis one is build on top of the existing FIFO8
---
Changes since v1:
* None
Changes since v2:
* Added copyright
* define Fifo32 as a struct containing Fifo8
* remove fifo32_pop_buf()
Changes since v3:
* Added comment on unsupported fifo32_pop_buf()
include/qemu/fifo32.h | 191 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 include/qemu/fifo32.h
include/qemu/fifo32.h new file +191 -0
@@ -0,0 +1,191 @@ +/* +* Generic FIFO32 component, based on FIFO8. +* +* Copyright (c) 2016 Jean-Christophe Dubois +* +* 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. +* +* 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 FIFO32_H +#define FIFO32_H + +#include "qemu/osdep.h" +#include "qemu/fifo8.h" + +typedef struct { +Fifo8 fifo; +}Fifo32 ; + +/** +* fifo32_create: +* @fifo: struct Fifo32 to initialise with new FIFO +* @capacity: capacity of the newly created FIFO expressed in 32 bit words +* +* Create a FIFO of the specified size. Clients should call fifo32_destroy() +* when finished using the fifo. The FIFO is initially empty. +*/ + +static inline void fifo32_create (Fifo32 *fifo,uint32_t capacity) +{ +fifo8_create (&fifo->fifo, capacity *sizeof (uint32_t )); +} + +/** +* fifo32_destroy: +* @fifo: FIFO to cleanup +* +* Cleanup a FIFO created with fifo32_create(). Frees memory created for FIFO +* storage. The FIFO is no longer usable after this has been called. +*/ + +static inline void fifo32_destroy (Fifo32 *fifo) +{ +fifo8_destroy (&fifo->fifo); +} + +/** +* fifo32_num_free: +* @fifo: FIFO to check +* +* Return the number of free uint32_t slots in the FIFO. +* +* Returns: Number of free 32 bit words. +*/ + +static inline uint32_t fifo32_num_free (Fifo32 *fifo) +{ +return DIV_ROUND_UP (fifo8_num_free (&fifo->fifo),sizeof (uint32_t )); +} + +/** +* fifo32_num_used: +* @fifo: FIFO to check +* +* Return the number of used uint32_t slots in the FIFO. +* +* Returns: Number of used 32 bit words. +*/ + +static inline uint32_t fifo32_num_used (Fifo32 *fifo) +{ +return DIV_ROUND_UP (fifo8_num_used (&fifo->fifo),sizeof (uint32_t )); +} + +/** +* fifo32_push: +* @fifo: FIFO to push to +* @data: 32 bits data word to push +* +* Push a 32 bits data word to the FIFO. Behaviour is undefined if the FIFO +* is full. Clients are responsible for checking for fullness using +* fifo32_is_full(). +*/ + +static inline void fifo32_push (Fifo32 *fifo,uint32_t data) +{ +int i; + +for (i =0 ; i <sizeof (data); i++) { +fifo8_push (&fifo->fifo, data &0xff ); + data >>=8 ; + } +} + +/** +* fifo32_push_all: +* @fifo: FIFO to push to +* @data: data to push +* @size: number of 32 bit words to push +* +* Push a 32 bit word array to the FIFO. Behaviour is undefined if the FIFO +* is full. Clients are responsible for checking the space left in the FIFO +* using fifo32_num_free(). +*/ + +static inline void fifo32_push_all (Fifo32 *fifo,const uint32_t *data, +uint32_t num) +{ +int i; + +for (i =0 ; i < num; i++) { +fifo32_push (fifo, data[i]); + } +} + +/** +* fifo32_pop: +* @fifo: fifo to pop from +* +* Pop a 32 bits data word from the FIFO. Behaviour is undefined if the FIFO +* is empty. Clients are responsible for checking for emptiness using +* fifo32_is_empty(). +* +* Returns: The popped 32 bits data word. +*/ + +static inline uint32_t fifo32_pop (Fifo32 *fifo) +{ +uint32_t ret =0 ; +int i; + +for (i =0 ; i <sizeof (uint32_t ); i++) { + ret |= (fifo8_pop (&fifo->fifo) << (i *8 )); + } + +return ret; +} + +/** +* There is no fifo32_pop_buf() because the data is not stored in the buffer +* as a set of native-order words. +*/ + +/** +* fifo32_reset: +* @fifo: FIFO to reset +* +* Reset a FIFO. All data is discarded and the FIFO is emptied. +*/ + +static inline void fifo32_reset (Fifo32 *fifo) +{ +fifo8_reset (&fifo->fifo); +} + +/** +* fifo32_is_empty: +* @fifo: FIFO to check +* +* Check if a FIFO is empty. +* +* Returns: True if the fifo is empty, false otherwise. +*/ + +static inline bool fifo32_is_empty (Fifo32 *fifo) +{ +return fifo8_is_empty (&fifo->fifo); +} + +/** +* fifo32_is_full: +* @fifo: FIFO to check +* +* Check if a FIFO is full. +* +* Returns: True if the fifo is full, false otherwise. +*/ + +static inline bool fifo32_is_full (Fifo32 *fifo) +{ +return fifo8_num_free (&fifo->fifo) <sizeof (uint32_t ); +} + +#define VMSTATE_FIFO32 (_field, _state) VMSTATE_FIFO8(_field.fifo, _state) + +#endif /* FIFO32_H */
Signature · 1 line
2.5.0
PATCH v4 4/6 i.MX: Add the Freescale SPI Controller
In reply to Jean-Christophe Dubois---
Changes since v1:
* Access SPI slave only at a byte level.
* rework the CS activation to avoid to reset access to SPI slaves.
Changes since v2:
* Added #include "qemu/osdep.h"
* remove previous_level from state struct
* save burst_length in VMSTATE
Changes since v3:
* Don't call qemu_set_irq() in reset function
hw/ssi/Makefile.objs | 1 + hw/ssi/imx_spi.c | 454 +++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ssi/imx_spi.h | 103 +++++++++++ 3 files changed, 558 insertions(+) create mode 100644 hw/ssi/imx_spi.c create mode 100644 include/hw/ssi/imx_spi.h
hw/ssi/Makefile.objs +1 -0
@@ -4,3 +4,4 @@ common-obj-$(CONFIG_XILINX_SPI) += xilinx_spi.o common-obj-$(CONFIG_XILINX_SPIPS) += xilinx_spips.o obj-$(CONFIG_OMAP) += omap_spi.o +obj-$(CONFIG_IMX) += imx_spi.o
hw/ssi/imx_spi.c new file +454 -0
454 lines not on this page · raw message
include/hw/ssi/imx_spi.h new file +103 -0
103 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v4 5/6 i.MX: Add i.MX6 SOC implementation.
In reply to Jean-Christophe DuboisFor now we only support the following devices:
* up to 4 Cortex A9 cores
* A9 MPCORE (SCU, GIC, TWD)
* 5 i.MX UARTs
* 2 EPIT timers
* 1 GPT timer
* 3 I2C controllers
* 7 GPIO controllers
* 6 SDHC controllers
* 5 SPI controllers
* 1 CCM device
* 1 SRC device
* various ROM/RAM areas.
---
Changes since V1:
* use g_strdup_printf/g_free instead of local char array.
* output a message on exit for unsupported number of cores.
Changes since V2:
* Added Include "osdep/qemu.h"
* Added support for EL3
* Added SPI controllers
* Added a property for each controller.
Changes since V3:
* None.
default-configs/arm-softmmu.mak | 1 + hw/arm/Makefile.objs | 1 + hw/arm/fsl-imx6.c | 449 +++++++++++++++++++++++++++++++++++++++ include/hw/arm/fsl-imx6.h | 450 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 901 insertions(+) create mode 100644 hw/arm/fsl-imx6.c create mode 100644 include/hw/arm/fsl-imx6.h
default-configs/arm-softmmu.mak +1 -0
@@ -100,6 +100,7 @@ CONFIG_ALLWINNER_A10_PIT=y CONFIG_ALLWINNER_A10_PIC=y CONFIG_ALLWINNER_A10=y +CONFIG_FSL_IMX6=y CONFIG_FSL_IMX31=y CONFIG_FSL_IMX25=y
hw/arm/Makefile.objs +1 -0
@@ -16,4 +16,5 @@ obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-zynqmp.o xlnx-ep108.o obj-$(CONFIG_FSL_IMX25) += fsl-imx25.o imx25_pdk.o obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o +obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o obj-$(CONFIG_ASPEED_SOC) += ast2400.o palmetto-bmc.o
hw/arm/fsl-imx6.c new file +449 -0
449 lines not on this page · raw message
include/hw/arm/fsl-imx6.h new file +450 -0
450 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v4 6/6 i.MX: Add sabrelite i.MX6 emulation.
In reply to Jean-Christophe DuboisThe sabrelite supports one SPI FLASH memory on SPI1
---
Changes since v1:
* output a message and exit if RAM size is unsupported.
Changes since v2:
* Added include "qemu/osdep.h"
* Added access to controllers through properties.
Changes since v3:
* None
hw/arm/Makefile.objs | 2 +- hw/arm/sabrelite.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 hw/arm/sabrelite.c
hw/arm/Makefile.objs +1 -1
@@ -16,5 +16,5 @@ obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-zynqmp.o xlnx-ep108.o obj-$(CONFIG_FSL_IMX25) += fsl-imx25.o imx25_pdk.o obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o -obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o +obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o sabrelite.o obj-$(CONFIG_ASPEED_SOC) += ast2400.o palmetto-bmc.o
hw/arm/sabrelite.c new file +117 -0
117 lines not on this page · raw message
Signature · 1 line
2.5.0
Re: [Qemu-devel] [PATCH v4 6/6] i.MX: Add sabrelite i.MX6 emulation.
hw/arm/sabrelite.c line 78
Quoted 8 lines · Jean-Christophe Dubois
The sabrelite supports one SPI FLASH memory on SPI1
Signed-off-by Jean-Christophe Dubois <[email protected]>hw/arm/sabrelite.c new file +5
-0+ { +/* Add the sst25vf016b NOR FLASH memory to first SPI */ +Object *spi_dev; + + spi_dev =object_resolve_path_component (OBJECT (&s->soc),"spi1" );
Can you add a comment to remind us there's a todo here:
/* Ideally we would expose the chip select and spi bus on the SoC
* object using alias properties; then we would not need to directly
* access the underlying spi device object.
*/
Otherwise
thanks
-- PMM
Re: [Qemu-devel] [PATCH v4 6/6] i.MX: Add sabrelite i.MX6 emulation.
Quoted 9 lines · Peter Maydell
hw/arm/sabrelite.c line 78
Quoted 8 lines · Jean-Christophe Dubois
The sabrelite supports one SPI FLASH memory on SPI1
Signed-off-by Jean-Christophe Dubois <[email protected]>hw/arm/sabrelite.c new file +5
-0+ { +/* Add the sst25vf016b NOR FLASH memory to first SPI */ +Object *spi_dev; + + spi_dev =object_resolve_path_component (OBJECT (&s->soc),"spi1" );
Quoted 5 lines
Can you add a comment to remind us there's a todo here:
/* Ideally we would expose the chip select and spi bus on the SoC
* object using alias properties; then we would not need to directly
* access the underlying spi device object.
*/
OK
Quoted 7 lines
Otherwise
Reviewed-by Peter Maydell <[email protected]>thanks
-- PMM