Add i.MX6 (Single/Dual/Quad) support
v3 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 (12):
i.MX: Allow GPT timer to rollover.
i.MX: Rename CCM NOCLK to CLK_NONE for naming consistency. i.MX: Remove CCM useless clock computation handling. i.MX: Add the CLK_IPG_HIGH clock
i.MX: Add i.MX6 CCM and ANALOG device.
ARM: Factor out ARM on/off PSCI control functions i.MX: Add i.MX6 System Reset Controller device. i.MX: Add missing descriptions in devices.
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-imx25.c | 1 + hw/arm/fsl-imx31.c | 1 + hw/arm/fsl-imx6.c | 449 +++++++++++++++++++++++ hw/arm/sabrelite.c | 117 ++++++ hw/i2c/imx_i2c.c | 1 + hw/misc/Makefile.objs | 2 + hw/misc/imx25_ccm.c | 29 +- hw/misc/imx31_ccm.c | 35 +- hw/misc/imx6_ccm.c | 774 ++++++++++++++++++++++++++++++++++++++++ hw/misc/imx6_src.c | 260 ++++++++++++++ hw/net/imx_fec.c | 1 + hw/ssi/Makefile.objs | 1 + hw/ssi/imx_spi.c | 459 ++++++++++++++++++++++++ hw/timer/imx_epit.c | 8 +- hw/timer/imx_gpt.c | 43 +-- include/hw/arm/fsl-imx6.h | 450 +++++++++++++++++++++++ include/hw/misc/imx6_ccm.h | 197 ++++++++++ include/hw/misc/imx6_src.h | 73 ++++ include/hw/misc/imx_ccm.h | 10 +- include/hw/ssi/imx_spi.h | 103 ++++++ include/qemu/fifo32.h | 186 ++++++++++ target-arm/Makefile.objs | 1 + target-arm/arm-powerctl.c | 156 ++++++++ target-arm/arm-powerctl.h | 22 ++ target-arm/psci.c | 72 +--- 27 files changed, 3294 insertions(+), 159 deletions(-) create mode 100644 hw/arm/fsl-imx6.c create mode 100644 hw/arm/sabrelite.c create mode 100644 hw/misc/imx6_ccm.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_ccm.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 v3 1/12 i.MX: Allow GPT timer to rollover.
GPT timer need to rollover when it reaches 0xffffffff.
It also need to reset to 0 when in "restart mode" and crossing the compare 1 register.
---
Changes since V1:
* None
Changes since V2:
* None
hw/timer/imx_gpt.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)
hw/timer/imx_gpt.c +15 -12
@@ -134,7 +134,7 @@ static inline uint32_t imx_gpt_find_limit(uint32_t count, uint32_t reg,static void imx_gpt_compute_next_timeout (IMXGPTState *s,bool event) {uint32_t timeout =GPT_TIMER_MAX ; -uint32_t count =0 ; +uint32_t count;long long limit;if (!(s->cr &GPT_CR_EN )) {
@@ -142,20 +142,23 @@ static void imx_gpt_compute_next_timeout(IMXGPTState *s, bool event)return ; } -if (event) { -/* This is a timer event */ +/* update the count */ + count =imx_gpt_update_count (s); -if ((s->cr &GPT_CR_FRR ) && (s->next_timeout !=GPT_TIMER_MAX )) { -/* -* if we are in free running mode and we have not reached -* the GPT_TIMER_MAX limit, then update the count +if (event) { +/* +* This is an event (the ptimer reached 0 and stopped), and the +* timer counter is now equal to s->next_timeout. +*/ +if (!(s->cr &GPT_CR_FRR ) && (count == s->ocr1)) { +/* We are in restart mode and we crossed the compare channel 1 +* value. We need to reset the counter to 0. */ - count =imx_gpt_update_count (s); + count = s->cnt = s->next_timeout =0 ; + }else if (count ==GPT_TIMER_MAX ) { +/* We reached GPT_TIMER_MAX so we need to rollover */ + count = s->cnt = s->next_timeout =0 ; } - }else { -/* not a timer event, then just update the count */ - - count =imx_gpt_update_count (s); }/* now, find the next timeout related to count */
Signature · 1 line
2.5.0
PATCH v3 3/12 i.MX: Remove CCM useless clock computation handling.
In reply to Jean-Christophe DuboisMost clocks supported by the CCM are useless to the qemu framework.
Only clocks related to timers (EPIT, GPT, PWM, WATCHDOG, ...) are usefull to QEMU code.
Therefore this patch removes clock computation handling for all clocks but:
* CLK_NONE,
* CLK_IPG,
* CLK_32k
---
Changes since V1:
* move NOCLK renaming in its own patch
* move CLK_IPG_HIGH addition in its own patch
Changes since V2:
* None
hw/misc/imx25_ccm.c | 26 -------------------------- hw/misc/imx31_ccm.c | 32 -------------------------------- include/hw/misc/imx_ccm.h | 7 ------- 3 files changed, 65 deletions(-)
hw/misc/imx25_ccm.c +0 -26
@@ -120,20 +120,6 @@ static uint32_t imx25_ccm_get_mpll_clk(IMXCCMState *dev)return freq; } -static uint32_t imx25_ccm_get_upll_clk (IMXCCMState *dev) -{ -uint32_t freq =0 ; -IMX25CCMState *s =IMX25_CCM (dev); - -if (!EXTRACT (s->reg[IMX25_CCM_CCTL_REG ],UPLL_DIS )) { - freq =imx_ccm_calc_pll (s->reg[IMX25_CCM_UPCTL_REG ],CKIH_FREQ ); - } - -DPRINTF ("freq = %d\n" , freq); - -return freq; -} -static uint32_t imx25_ccm_get_mcu_clk (IMXCCMState *dev) {uint32_t freq;
@@ -184,18 +170,6 @@ static uint32_t imx25_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock)switch (clock) {case CLK_NONE :break ; -case CLK_MPLL : - freq =imx25_ccm_get_mpll_clk (dev); -break ; -case CLK_UPLL : - freq =imx25_ccm_get_upll_clk (dev); -break ; -case CLK_MCU : - freq =imx25_ccm_get_mcu_clk (dev); -break ; -case CLK_AHB : - freq =imx25_ccm_get_ahb_clk (dev); -break ;case CLK_IPG : freq =imx25_ccm_get_ipg_clk (dev);break ;
hw/misc/imx31_ccm.c +0 -32
@@ -152,32 +152,6 @@ static uint32_t imx31_ccm_get_mcu_main_clk(IMXCCMState *dev)return freq; } -static uint32_t imx31_ccm_get_mcu_clk (IMXCCMState *dev) -{ -uint32_t freq; -IMX31CCMState *s =IMX31_CCM (dev); - - freq =imx31_ccm_get_mcu_main_clk (dev) - / (1 +EXTRACT (s->reg[IMX31_CCM_PDR0_REG ],MCU )); - -DPRINTF ("freq = %d\n" , freq); - -return freq; -} - -static uint32_t imx31_ccm_get_hsp_clk (IMXCCMState *dev) -{ -uint32_t freq; -IMX31CCMState *s =IMX31_CCM (dev); - - freq =imx31_ccm_get_mcu_main_clk (dev) - / (1 +EXTRACT (s->reg[IMX31_CCM_PDR0_REG ],HSP )); - -DPRINTF ("freq = %d\n" , freq); - -return freq; -} -static uint32_t imx31_ccm_get_hclk_clk (IMXCCMState *dev) {uint32_t freq;
@@ -211,12 +185,6 @@ static uint32_t imx31_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock)switch (clock) {case CLK_NONE :break ; -case CLK_MCU : - freq =imx31_ccm_get_mcu_clk (dev); -break ; -case CLK_HSP : - freq =imx31_ccm_get_hsp_clk (dev); -break ;case CLK_IPG : freq =imx31_ccm_get_ipg_clk (dev);break ;
include/hw/misc/imx_ccm.h +0 -7
@@ -44,14 +44,7 @@ typedef struct IMXCCMState {typedef enum {CLK_NONE , -CLK_MPLL , -CLK_UPLL , -CLK_MCU , -CLK_HSP , -CLK_MAX , -CLK_AHB ,CLK_IPG , -CLK_PER , CLK_32k }IMXClk ;
Signature · 1 line
2.5.0
PATCH v3 2/12 i.MX: Rename CCM NOCLK to CLK_NONE for naming consistency.
In reply to Jean-Christophe DuboisThis way all CCM clock defines/enums are named CLK_XXX
---
Changes since V1:
* Not present on V1
Changes since V2:
* None
hw/misc/imx25_ccm.c | 2 +- hw/misc/imx31_ccm.c | 2 +- hw/timer/imx_epit.c | 2 +- hw/timer/imx_gpt.c | 10 +++++----- include/hw/misc/imx_ccm.h | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-)
hw/misc/imx25_ccm.c +1 -1
@@ -182,7 +182,7 @@ static uint32_t imx25_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock)DPRINTF ("Clock = %d)\n" , clock);switch (clock) { -case NOCLK : +case CLK_NONE :break ;case CLK_MPLL : freq =imx25_ccm_get_mpll_clk (dev);
hw/misc/imx31_ccm.c +1 -1
@@ -209,7 +209,7 @@ static uint32_t imx31_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock)uint32_t freq =0 ;switch (clock) { -case NOCLK : +case CLK_NONE :break ;case CLK_MCU : freq =imx31_ccm_get_mcu_clk (dev);
hw/timer/imx_epit.c +1 -1
@@ -52,7 +52,7 @@ static char const *imx_epit_reg_name(uint32_t reg)* These are typical. */ static const IMXClk imx_epit_clocks[] = { -NOCLK ,/* 00 disabled */ +CLK_NONE ,/* 00 disabled */ CLK_IPG ,/* 01 ipg_clk, ~532MHz */ CLK_IPG ,/* 10 ipg_clk_highfreq */ CLK_32k,/* 11 ipg_clk_32k -- ~32kHz */
hw/timer/imx_gpt.c +5 -5
@@ -81,14 +81,14 @@ static const VMStateDescription vmstate_imx_timer_gpt = { };static const IMXClk imx_gpt_clocks[] = { -NOCLK ,/* 000 No clock source */ +CLK_NONE ,/* 000 No clock source */ CLK_IPG ,/* 001 ipg_clk, 532MHz*/ CLK_IPG ,/* 010 ipg_clk_highfreq */ -NOCLK ,/* 011 not defined */ +CLK_NONE ,/* 011 not defined */ CLK_32k,/* 100 ipg_clk_32k */ -NOCLK ,/* 101 not defined */ -NOCLK ,/* 110 not defined */ -NOCLK ,/* 111 not defined */ +CLK_NONE ,/* 101 not defined */ +CLK_NONE ,/* 110 not defined */ +CLK_NONE ,/* 111 not defined */ };static void imx_gpt_set_freq (IMXGPTState *s)
include/hw/misc/imx_ccm.h +1 -1
@@ -43,7 +43,7 @@ typedef struct IMXCCMState { } IMXCCMState; typedef enum { - NOCLK, + CLK_NONE, CLK_MPLL, CLK_UPLL, CLK_MCU,
Signature · 1 line
2.5.0
PATCH v3 4/12 i.MX: Add the CLK_IPG_HIGH clock
In reply to Jean-Christophe DuboisEPIT, GPT and other i.MX timers are using "abstract" clocks among which a CLK_IPG_HIGH clock.
On i.MX25 and i.MX31 CLK_IPG and CLK_IPG_HIGH are mapped to the same clock but on other SOC like i.MX6 they are mapped to distinct clocks.
This patch add the CLK_IPG_HIGH to prepare for SOC where these 2 clocks are different.
---
Changes since V1:
* Not present on V1
Changes since V2:
* None
hw/misc/imx25_ccm.c | 1 + hw/misc/imx31_ccm.c | 1 + hw/timer/imx_epit.c | 8 ++++---- hw/timer/imx_gpt.c | 16 ++++++++-------- include/hw/misc/imx_ccm.h | 1 + 5 files changed, 15 insertions(+), 12 deletions(-)
hw/misc/imx25_ccm.c +1 -0
@@ -171,6 +171,7 @@ static uint32_t imx25_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock)case CLK_NONE :break ;case CLK_IPG : +case CLK_IPG_HIGH : freq =imx25_ccm_get_ipg_clk (dev);break ;case CLK_32k:
hw/misc/imx31_ccm.c +1 -0
@@ -186,6 +186,7 @@ static uint32_t imx31_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock)case CLK_NONE :break ;case CLK_IPG : +case CLK_IPG_HIGH : freq =imx31_ccm_get_ipg_clk (dev);break ;case CLK_32k:
hw/timer/imx_epit.c +4 -4
@@ -52,10 +52,10 @@ static char const *imx_epit_reg_name(uint32_t reg)* These are typical. */ static const IMXClk imx_epit_clocks[] = { -CLK_NONE ,/* 00 disabled */ -CLK_IPG ,/* 01 ipg_clk, ~532MHz */ -CLK_IPG ,/* 10 ipg_clk_highfreq */ - CLK_32k,/* 11 ipg_clk_32k -- ~32kHz */ +CLK_NONE ,/* 00 disabled */ +CLK_IPG ,/* 01 ipg_clk, ~532MHz */ +CLK_IPG_HIGH ,/* 10 ipg_clk_highfreq */ + CLK_32k,/* 11 ipg_clk_32k -- ~32kHz */ };/*
hw/timer/imx_gpt.c +8 -8
@@ -81,14 +81,14 @@ static const VMStateDescription vmstate_imx_timer_gpt = { };static const IMXClk imx_gpt_clocks[] = { -CLK_NONE ,/* 000 No clock source */ -CLK_IPG ,/* 001 ipg_clk, 532MHz*/ -CLK_IPG ,/* 010 ipg_clk_highfreq */ -CLK_NONE ,/* 011 not defined */ - CLK_32k,/* 100 ipg_clk_32k */ -CLK_NONE ,/* 101 not defined */ -CLK_NONE ,/* 110 not defined */ -CLK_NONE ,/* 111 not defined */ +CLK_NONE ,/* 000 No clock source */ +CLK_IPG ,/* 001 ipg_clk, 532MHz*/ +CLK_IPG_HIGH ,/* 010 ipg_clk_highfreq */ +CLK_NONE ,/* 011 not defined */ + CLK_32k,/* 100 ipg_clk_32k */ +CLK_NONE ,/* 101 not defined */ +CLK_NONE ,/* 110 not defined */ +CLK_NONE ,/* 111 not defined */ };static void imx_gpt_set_freq (IMXGPTState *s)
include/hw/misc/imx_ccm.h +1 -0
@@ -45,6 +45,7 @@ typedef struct IMXCCMState {typedef enum {CLK_NONE ,CLK_IPG , +CLK_IPG_HIGH , CLK_32k }IMXClk ;
Signature · 1 line
2.5.0
PATCH v3 5/12 i.MX: Add i.MX6 CCM and ANALOG device.
In reply to Jean-Christophe Dubois---
Changes since V1:
* move clk computation to uint64_t to avoid overflow
* added explanation on _SET, _CLR and _TOG registers
* move CCM and ANALOG handling in sub memory regions.
Changes since V2:
* Added #include "qemu/osdep.h"
hw/misc/Makefile.objs | 1 + hw/misc/imx6_ccm.c | 774 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/misc/imx6_ccm.h | 197 ++++++++++++ 3 files changed, 972 insertions(+) create mode 100644 hw/misc/imx6_ccm.c create mode 100644 include/hw/misc/imx6_ccm.h
hw/misc/Makefile.objs +1 -0
@@ -28,6 +28,7 @@ obj-$(CONFIG_EXYNOS4) += exynos4210_pmu.o 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_MILKYMIST) += milkymist-hpdmc.o obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o obj-$(CONFIG_MAINSTONE) += mst_fpga.o
hw/misc/imx6_ccm.c new file +774 -0
774 lines not on this page · raw message
include/hw/misc/imx6_ccm.h new file +197 -0
197 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v3 6/12 ARM: Factor out ARM on/off PSCI control functions
In reply to Jean-Christophe DuboisSplit 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
target-arm/Makefile.objs | 1 + target-arm/arm-powerctl.c | 156 ++++++++++++++++++++++++++++++++++++++++++++++ target-arm/arm-powerctl.h | 22 +++++++ target-arm/psci.c | 72 ++------------------- 4 files changed, 184 insertions(+), 67 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 +156 -0
156 lines not on this page · raw message
target-arm/arm-powerctl.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* 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 + +CPUState *arm_get_cpu_by_id (uint64_t id); + +int arm_set_cpu_on (uint64_t cpuid,uint64_t entry,uint64_t context_id); + +void arm_set_cpu_off (uint64_t cpuid); + +int arm_reset_cpu (uint64_t cpuid); + +#endif
target-arm/psci.c +5 -67
113 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v3 7/12 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"
hw/misc/Makefile.objs | 1 + hw/misc/imx6_src.c | 260 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/misc/imx6_src.h | 73 +++++++++++++ 3 files changed, 334 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 +260 -0
260 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 v3 9/12 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()
include/qemu/fifo32.h | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 include/qemu/fifo32.h
include/qemu/fifo32.h new file +186 -0
@@ -0,0 +1,186 @@ +/* +* 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 bits 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 bits 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 bits 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 bits words to push +* +* Push a 32 bits 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; +} + +/** +* 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 v3 8/12 i.MX: Add missing descriptions in devices.
In reply to Jean-Christophe Dubois---
Changes since v1:
* Not present on V1
Changes since v2:
* None
hw/arm/fsl-imx25.c | 1 + hw/arm/fsl-imx31.c | 1 + hw/i2c/imx_i2c.c | 1 + hw/net/imx_fec.c | 1 + 4 files changed, 4 insertions(+)
hw/arm/fsl-imx25.c +1 -0
@@ -291,6 +291,7 @@ static void fsl_imx25_class_init(ObjectClass *oc, void *data)* arm_cpu_class_init() */ dc->cannot_destroy_with_object_finalize_yet = true; + dc->desc ="i.MX25 SOC" ; }static const TypeInfo fsl_imx25_type_info = {
hw/arm/fsl-imx31.c +1 -0
@@ -265,6 +265,7 @@ static void fsl_imx31_class_init(ObjectClass *oc, void *data)* arm_cpu_class_init() */ dc->cannot_destroy_with_object_finalize_yet = true; + dc->desc ="i.MX31 SOC" ; }static const TypeInfo fsl_imx31_type_info = {
hw/i2c/imx_i2c.c +1 -0
@@ -319,6 +319,7 @@ static void imx_i2c_class_init(ObjectClass *klass, void *data) dc->vmsd = &imx_i2c_vmstate; dc->reset = imx_i2c_reset; dc->realize = imx_i2c_realize; + dc->desc ="i.MX I2C Controller" ; }static const TypeInfo imx_i2c_type_info = {
hw/net/imx_fec.c +1 -0
@@ -693,6 +693,7 @@ static void imx_fec_class_init(ObjectClass *klass, void *data) dc->reset = imx_fec_reset; dc->props = imx_fec_properties; dc->realize = imx_fec_realize; + dc->desc ="i.MX FEC Ethernet Controller" ; }static const TypeInfo imx_fec_info = {
Signature · 1 line
2.5.0
PATCH v3 10/12 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
hw/ssi/Makefile.objs | 1 + hw/ssi/imx_spi.c | 459 +++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ssi/imx_spi.h | 103 +++++++++++ 3 files changed, 563 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 +459 -0
459 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 v3 12/12 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.
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,4 +16,4 @@ 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
hw/arm/sabrelite.c new file +117 -0
117 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v3 11/12 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.
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,3 +16,4 @@ 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
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
Re: [Qemu-devel] [PATCH v3 06/12] ARM: Factor out ARM on/off PSCI control functions
In reply to Jean-Christophe DuboisQuoted 69 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 V2target-arm/Makefile.objs | 1 + target-arm/arm-powerctl.c | 156 ++++++++++++++++++++++++++++++++++++++++++++++ target-arm/arm-powerctl.h | 22 +++++++ target-arm/psci.c | 72 ++------------------- 4 files changed, 184 insertions(+), 67 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 +33
-0@@ -0,0 +1,156 @@ +/* +* 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 "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) {
target-arm/arm-powerctl.c line 43
Quoted 10 lines
target-arm/arm-powerctl.c new file +10
-0+ARMCPU *armcpu =ARM_CPU (cpu); + +if (armcpu->mp_affinity == id) { +return cpu; + } + } + +qemu_log_mask (LOG_GUEST_ERROR , +"[ARM]%s: Resquesting unknown CPU %" PRId64"\n" , + __func__, id);
"Requesting"
Quoted 27 lines
target-arm/arm-powerctl.c new file +27
-0+ +return NULL ; +} + +int arm_set_cpu_on (uint64_t cpuid,uint64_t entry,uint64_t context_id) +{ +CPUState *target_cpu_state; +ARMCPU *target_cpu; +CPUClass *target_cpu_class; +CPUARMState *env = &ARM_CPU (current_cpu)->env; + +DPRINTF ("cpu %" PRId64" @ 0x%" PRIx64" with R0 = 0x%" PRIx64"\n" , + cpuid, entry, context_id); + +/* change to the cpu we are powering up */ + target_cpu_state =arm_get_cpu_by_id (cpuid); +if (!target_cpu_state) { +return -1 ; + } + 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 -1 ; + } + target_cpu_class =CPU_GET_CLASS (target_cpu);
target-arm/arm-powerctl.c line 80
Quoted 10 lines
target-arm/arm-powerctl.c new file +10
-0+ +/* 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.
This is a generic function so it's a bit out of place for it to talk about PSCI spec details. What are the semantics provided by this helper function?
target-arm/arm-powerctl.c line 84
Quoted 4 lines
target-arm/arm-powerctl.c new file +4
-0+* +* 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
It's no longer true that we only implement EL1, incidentally.
Quoted 56 lines
target-arm/arm-powerctl.c new file +54
-0+* (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 ) { +return -1 ; + } + target_cpu->env.xregs[0 ] = context_id; + }else { + target_cpu->env.regs[0 ] = context_id; + target_cpu->env.thumb = entry &1 ; + } + + target_cpu_class->set_pc (target_cpu_state, entry); + +return 0 ; +} + +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); +
target-arm/arm-powerctl.c line 148
Quoted 10 lines
target-arm/arm-powerctl.c new file +10
-0+/* change to the cpu we are resetting */ + target_cpu_state =arm_get_cpu_by_id (cpuid); +if (!target_cpu_state) { +return -1 ; + } + 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);
Whether requesting a power-off of a powered off CPU is a guest error depends on the API used to request it, so you can't log this as a guest error in the generic helper function.
Quoted 24 lines
target-arm/arm-powerctl.c new file +8
-0+return -1 ; + } + +/* Reset the cpu */ +cpu_reset (target_cpu_state); + +return 0 ; +}target-arm/arm-powerctl.h new file +10
-0@@ -0,0 +1,22 @@ +/* +* 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. +* +*/ +
target-arm/arm-powerctl.h line 20
Quoted 10 lines
target-arm/arm-powerctl.h new file +10
-0+#ifndef QEMU_ARM_POWERCTL_H +#define QEMU_ARM_POWERCTL_H + +CPUState *arm_get_cpu_by_id (uint64_t id); + +int arm_set_cpu_on (uint64_t cpuid,uint64_t entry,uint64_t context_id); + +void arm_set_cpu_off (uint64_t cpuid); + +int arm_reset_cpu (uint64_t cpuid);
Please provide doc comments for new globally-visible functions.
Quoted 66 lines
target-arm/arm-powerctl.h new file +2
-0+ +#endif target-arm/psci.c +2
-19@@ -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 ;@@ -168,51 +152,8 @@ void arm_handle_psci_call(ARMCPU *cpu) entry = param[2 ]; context_id = param[3 ]; -/* change to the cpu we are powering up */
target-arm/psci.c void arm_handle_psci_call(ARMCPU *cpu) · line 181
Quoted 10 lines
target-arm/psci.c +0
-10- 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 ; - }
You've lost the distinction between these two failure modes -- the PSCI error codes are returned to the guest and are mandated by the PSCI spec so you need to distinguish them.
Quoted 51 lines
target-arm/psci.c +3
-39- 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 ; - } - target_cpu_class->set_pc (target_cpu_state, entry); - - ret =0 ; + ret =arm_set_cpu_on (mpidr, entry, context_id) ? +QEMU_PSCI_RET_INVALID_PARAMS :0 ;break ;case QEMU_PSCI_0_1_FN_CPU_OFF :case QEMU_PSCI_0_2_FN_CPU_OFF :@@ -250,9 +191,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 2 lines
2.5.0
thanks
-- PMM
Re: [Qemu-devel] [PATCH v3 07/12] i.MX: Add i.MX6 System Reset Controller device.
In reply to Jean-Christophe Duboishw/misc/imx6_src.c line 88
Quoted 13 lines · Jean-Christophe Dubois
This controller is also present in i.MX5X devices but they are not yet emulated by QEMU.
Signed-off-by Jean-Christophe Dubois <[email protected]>---
hw/misc/imx6_src.c new file +7
-0+static void imx6_src_reset (DeviceState *dev) +{ +IMX6SRCState *s =IMX6_SRC (dev); + +DPRINTF ("\n" ); + +memset (s->regs,0 ,SRC_MAX *sizeof (uint32_t ));
memset(s->regs, 0, sizeof(s->regs));
is slightly better.
Quoted 14 lines
hw/misc/imx6_src.c new file +14
-0+ +/* Set reset values */ + s->regs[SRC_SCR ] =0x521 ; + s->regs[SRC_SRSR ] =0x1 ; + s->regs[SRC_SIMR ] =0x1F ; +} + +static uint64_t imx6_src_read (void *opaque,hwaddr offset,unsigned size) +{ +uint32_t value =0 ; +IMX6SRCState *s = (IMX6SRCState *)opaque; +uint32_t index = offset >>2 ; + +if (index <SRC_MAX ) {
hw/misc/imx6_src.c line 112
Quoted 10 lines
hw/misc/imx6_src.c new file +10
-0+ value = s->regs[index]; + }else { +qemu_log_mask (LOG_GUEST_ERROR ,"[%s]%s: Bad register at offset 0x%" + HWADDR_PRIx"\n" ,TYPE_IMX6_SRC , __func__, offset); + + } + +DPRINTF ("reg[%s] => 0x%" PRIx32"\n" ,imx6_src_reg_name (index), value); + +return (uint64_t )value;
This cast is unnecessary.
Quoted 9 lines
hw/misc/imx6_src.c new file +9
-0+} + +static void imx6_src_write (void *opaque,hwaddr offset,uint64_t value, +unsigned size) +{ +IMX6SRCState *s = (IMX6SRCState *)opaque; +uint32_t index = offset >>2 ; +uint64_t change_mask; +
hw/misc/imx6_src.c line 131
Quoted 10 lines
hw/misc/imx6_src.c new file +10
-0+if (index >=SRC_MAX ) { +qemu_log_mask (LOG_GUEST_ERROR ,"[%s]%s: Bad register at offset 0x%" + HWADDR_PRIx"\n" ,TYPE_IMX6_SRC , __func__, offset); +return ; + } + +DPRINTF ("reg[%s] <= 0x%" PRIx32"\n" ,imx6_src_reg_name (index), + (uint32_t )value); + + change_mask = s->regs[index] ^ (uint32_t )value;
s->regs[] is 32 bit, and you've explicitly cast value to 32-bits, so why is change_mask 64 bits?
hw/misc/imx6_src.c line 197
Quoted 6 lines
hw/misc/imx6_src.c new file +6
-0+if (EXTRACT (change_mask,CORE3_RST )) { +arm_reset_cpu (3 ); +clear_bit (CORE3_RST_SHIFT , &value); + } +if (EXTRACT (change_mask,SW_IPU2_RST )) { +/* We pretend the IPU2 is reseted */
"reset" (and below).
hw/misc/imx6_src.c line 205
Quoted 8 lines
hw/misc/imx6_src.c new file +8
-0+clear_bit (SW_IPU2_RST_SHIFT , &value); + } +if (EXTRACT (change_mask,SW_IPU1_RST )) { +/* We pretend the IPU1 is reseted */ +clear_bit (SW_IPU1_RST_SHIFT , &value); + } + s->regs[index] = value; +break ;
Otherwise
thanks
-- PMM
Re: [Qemu-devel] [PATCH v3 09/12] FIFO: Add a FIFO32 implementation
In reply to Jean-Christophe DuboisQuoted 41 lines · Jean-Christophe Dubois
This one is build on top of the existing FIFO8
Signed-off-by Jean-Christophe Dubois <[email protected]>---
Changes since v1:
* NoneChanges since v2:
* Added copyright
* define Fifo32 as a struct containing Fifo8
* removefifo32_pop_buf()include/qemu/fifo32.h | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 include/qemu/fifo32.hinclude/qemu/fifo32.h new file +18
-0@@ -0,0 +1,186 @@ +/* +* 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/fifo32.h line 28
Quoted 10 lines
include/qemu/fifo32.h new file +10
-0+#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 bits words
"32 bits word" should be "32 bit word" throughout.
There should be a comment somewhere noting that there is no fifo32_pop_buf() because the data is not stored in the buffer as a set of native-order words.
Otherwise
thanks
-- PMM
Re: [Qemu-devel] [PATCH v3 10/12] i.MX: Add the Freescale SPI Controller
In reply to Jean-Christophe DuboisQuoted 15 lines · Jean-Christophe Dubois
Signed-off-by Jean-Christophe Dubois <[email protected]>---
hw/ssi/imx_spi.c new file +12
-0+ +static void imx_spi_reset (DeviceState *dev) +{ +IMXSPIState *s =IMX_SPI (dev); +int i; + +DPRINTF ("\n" ); + +memset (s->regs,0 ,sizeof (s->regs)); + + s->regs[ECSPI_STATREG ] =0x00000003 ; +
hw/ssi/imx_spi.c line 249
Quoted 10 lines
hw/ssi/imx_spi.c new file +10
-0+imx_spi_rxfifo_reset (s); +imx_spi_txfifo_reset (s); + +imx_spi_update_irq (s); + + s->burst_length =0 ; + +for (i =0 ; i <4 ; i++) { +qemu_set_irq (s->cs_lines[i],0 ); + }
Calling qemu_set_irq() from a reset function is generally a bad idea.
Quoted 1 line
+}
Otherwise
thanks
-- PMM
Re: [Qemu-devel] [PATCH v3 11/12] i.MX: Add i.MX6 SOC implementation.
In reply to Jean-Christophe DuboisQuoted 14 lines · Jean-Christophe Dubois
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
* 3 I2C controllers
* 7 GPIO controllers
* 6 SDHC controllers
* 5 SPI controllers
* 1 CCM device
* 1 SRC device
* various ROM/RAM areas.
Quoted 1 line
Signed-off-by Jean-Christophe Dubois <[email protected]>
thanks
-- PMM
Re: [Qemu-devel] [PATCH v3 12/12] i.MX: Add sabrelite i.MX6 emulation.
In reply to Jean-Christophe DuboisQuoted 5 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 line 82
Quoted 10 lines
hw/arm/sabrelite.c new file +10
-0+ + { +/* Add the sst25vf016b NOR FLASH memory to first SPI */ +Object *spi_dev; + + spi_dev =object_resolve_path_component (OBJECT (&s->soc),"spi1" ); +if (spi_dev) { +SSIBus *spi_bus; + + spi_bus = (SSIBus *)qdev_get_child_bus (DEVICE (spi_dev),"spi" );
This looks odd. You should just be able to do
spi_bus = (SSIBus *)qdev_get_child_bus(DEVICE(&s->soc), "spi1");
without using object_resolve_path_component() to try to find an SPI device object, because your SoC device should have alias properties which provide access to its SPI subcomponents' SPI buses. See hw/arm/xlnx-ep108.c for an example of the board code for this and hw/arm/xlnx-zynqmp.c for the SoC code which calls object_property_add_alias() to set up the aliases.
hw/arm/sabrelite.c line 94
Quoted 12 lines
hw/arm/sabrelite.c new file +12
-0+if (spi_bus) { +DeviceState *flash_dev; + + flash_dev =ssi_create_slave (spi_bus,"sst25vf016b" ); +if (flash_dev) { +qemu_irq cs_line =qdev_get_gpio_in_named (flash_dev, +SSI_GPIO_CS ,0 ); +sysbus_connect_irq (SYS_BUS_DEVICE (spi_dev),1 , cs_line); + } + } + } + }
thanks
-- PMM
Re: [Qemu-devel] [PATCH v3 12/12] i.MX: Add sabrelite i.MX6 emulation.
Quoted 16 lines · Peter Maydell
Quoted 5 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 line 82
Quoted 10 lines
hw/arm/sabrelite.c new file +10
-0+ + { +/* Add the sst25vf016b NOR FLASH memory to first SPI */ +Object *spi_dev; + + spi_dev =object_resolve_path_component (OBJECT (&s->soc),"spi1" ); +if (spi_dev) { +SSIBus *spi_bus; + + spi_bus = (SSIBus *)qdev_get_child_bus (DEVICE (spi_dev),"spi" );
Quoted 8 lines
This looks odd. You should just be able to do
spi_bus= (SSIBus *)qdev_get_child_bus(DEVICE(&s->soc), "spi1");
without usingobject_resolve_path_component()to try to find an SPI device object, because your SoC device should have alias properties which provide access to its SPI subcomponents' SPI buses. Seehw/arm/xlnx-ep108.cfor an example of the board code for this andhw/arm/xlnx-zynqmp.cfor the SoC code which callsobject_property_add_alias()to set up the aliases.
I certainly could do as you proposed.
The problem is that I also need the spi_dev device for the sysbus_connect_irq() call below.
My spi_dev is referenced as "spi1" in the i.MX6 doc and I added a 'spi1" property for it in the i.MX6 soc.
Once I have the spi_dev device it is trivial to retrieve the spi_bus attached to it.
So, yes this is not in line with what is done in xlnx-zynqmp.c but the need is a bit different.
JC
Quoted 16 lines
hw/arm/sabrelite.c line 94
Quoted 13 lines
hw/arm/sabrelite.c new file +12
-0+if (spi_bus) { +DeviceState *flash_dev; + + flash_dev =ssi_create_slave (spi_bus,"sst25vf016b" ); +if (flash_dev) { +qemu_irq cs_line =qdev_get_gpio_in_named (flash_dev, +SSI_GPIO_CS ,0 ); +sysbus_connect_irq (SYS_BUS_DEVICE (spi_dev),1 , cs_line); + } + } + } + }thanks
-- PMM
Re: [Qemu-devel] [PATCH v3 10/12] i.MX: Add the Freescale SPI Controller
In reply to Peter MaydellQuoted 20 lines · Peter Maydell
Quoted 19 lines · Jean-Christophe Dubois
Signed-off-by Jean-Christophe Dubois <[email protected]>---
hw/ssi/imx_spi.c new file +16
-0+ +static void imx_spi_reset (DeviceState *dev) +{ +IMXSPIState *s =IMX_SPI (dev); +int i; + +DPRINTF ("\n" ); + +memset (s->regs,0 ,sizeof (s->regs)); + + s->regs[ECSPI_STATREG ] =0x00000003 ; + +imx_spi_rxfifo_reset (s); +imx_spi_txfifo_reset (s); + +imx_spi_update_irq (s);
Quoted 8 lines
hw/ssi/imx_spi.c line 249
Quoted 6 lines
hw/ssi/imx_spi.c new file +6
-0+ + s->burst_length =0 ; + +for (i =0 ; i <4 ; i++) { +qemu_set_irq (s->cs_lines[i],0 ); + }Calling
qemu_set_irq()from a reset function is generally a bad idea.
Could I assume that all irq lines are set automatically to 0 on reset?
Quoted 8 lines
Quoted 2 lines
+}
Otherwise
Reviewed-by Peter Maydell <[email protected]>thanks
-- PMM
Re: [Qemu-devel] [PATCH v3 09/12] FIFO: Add a FIFO32 implementation
In reply to Peter MaydellQuoted 54 lines · Peter Maydell
Quoted 41 lines · Jean-Christophe Dubois
This one is build on top of the existing FIFO8
Signed-off-by Jean-Christophe Dubois <[email protected]>---
Changes since v1:
* NoneChanges since v2:
* Added copyright
* define Fifo32 as a struct containing Fifo8
* removefifo32_pop_buf()include/qemu/fifo32.h | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+)create mode 100644
include/qemu/fifo32.hinclude/qemu/fifo32.h new file +18
-0@@ -0,0 +1,186 @@ +/* +* 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/fifo32.h line 28
Quoted 10 lines
include/qemu/fifo32.h new file +10
-0+#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 bits words "32 bits word" should be "32 bit word" throughout.
Quoted 3 lines
There should be a comment somewhere noting that there is no
fifo32_pop_buf()because the data is not stored in the buffer as a set of native-order words.
OK
Quoted 7 lines
Otherwise
Reviewed-by Peter Maydell <[email protected]>thanks
-- PMM
Re: [Qemu-devel] [PATCH v3 12/12] i.MX: Add sabrelite i.MX6 emulation.
In reply to Jean-Christophe DUBOISQuoted 38 lines · Jean-Christophe DUBOIS
Quoted 22 lines · Peter Maydell
Quoted 17 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 +6
-0+ + { +/* Add the sst25vf016b NOR FLASH memory to first SPI */ +Object *spi_dev; + + spi_dev = object_resolve_path_component(OBJECT(&s->soc),"spi1");
hw/arm/sabrelite.c new file +4
-0+if (spi_dev) { +SSIBus *spi_bus; + + spi_bus = (SSIBus *)qdev_get_child_bus(DEVICE(spi_dev),Quoted 1 line
"spi");
Quoted 8 lines
This looks odd. You should just be able to do
spi_bus= (SSIBus *)qdev_get_child_bus(DEVICE(&s->soc), "spi1");
without usingobject_resolve_path_component()to try to find an SPI device object, because your SoC device should have alias properties which provide access to its SPI subcomponents' SPI buses. Seehw/arm/xlnx-ep108.cfor an example of the board code for this andhw/arm/xlnx-zynqmp.cfor the SoC code which callsobject_property_add_alias()to set up the aliases.I certainly could do as you proposed.
The problem is that I also need the
spi_devdevice for thesysbus_connect_irq()call below.
Quoted 8 lines
My
spi_devis referenced as "spi1" in the i.MX6 doc and I added a 'spi1" property for it in the i.MX6 soc.Once I have the
spi_devdevice it is trivial to retrieve thespi_busattached to it.So, yes this is not in line with what is done in
xlnx-zynqmp.cbut the need is a bit different.
I think the SoC should probably have an externally-facing IRQ line which it wires up internally to the SPI's IRQ line. (This corresponds basically to what happens in h/w -- the SoC's interfaces are defined by it even though many of them may be directly wired up to some internal component it has, but from outside the SoC you don't get access to the whole of the internal component.)
thanks
-- PMM
Re: [Qemu-devel] [PATCH v3 10/12] i.MX: Add the Freescale SPI Controller
In reply to Jean-Christophe DUBOISQuoted 6 lines · Jean-Christophe DUBOIS
Quoted 2 lines · Peter Maydell
Calling
qemu_set_irq()from a reset function is generally a bad idea.Could I assume that all irq lines are set automatically to 0 on reset?
The way this works is that an irq line has two ends on it, and no internal state of its own. So on reset, the devices at each end reset themselves. For the device on the receiving end of the irq line, it will reset itself into the "assume this input of mine is at 0" state.
(The reason not to call qemu_set_irq() on reset from the sending end is that there's no guarantee about which order the two devices reset themselves -- if you reset before the receiving end then your call would do nothing anyway because the subsequent reset in the receiver resets its state and it forgets about the inbound signal being high.)
This is of course broken for the case where a device wants to assert a line to 1 when it resets, but we've basically been able to ignore this so far. Trying to clean up our reset handling would be a huge job and probably not back compatible either...
thanks
-- PMM
Re: [Qemu-devel] [PATCH v3 12/12] i.MX: Add sabrelite i.MX6 emulation.
In reply to Peter MaydellQuoted 43 lines · Peter Maydell
Quoted 34 lines · Jean-Christophe DUBOIS
Quoted 19 lines · Peter Maydell
Quoted 16 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 +6
-0+ + { +/* Add the sst25vf016b NOR FLASH memory to first SPI */ +Object *spi_dev; + + spi_dev = object_resolve_path_component(OBJECT(&s->soc),"spi1");
hw/arm/sabrelite.c new file +4
-0+if (spi_dev) { +SSIBus *spi_bus; + + spi_bus = (SSIBus *)qdev_get_child_bus(DEVICE(spi_dev),Quoted 1 line
"spi");
Quoted 8 lines
This looks odd. You should just be able to do
spi_bus= (SSIBus *)qdev_get_child_bus(DEVICE(&s->soc), "spi1");
without usingobject_resolve_path_component()to try to find an SPI device object, because your SoC device should have alias properties which provide access to its SPI subcomponents' SPI buses. Seehw/arm/xlnx-ep108.cfor an example of the board code for this andhw/arm/xlnx-zynqmp.cfor the SoC code which callsobject_property_add_alias()to set up the aliases.I certainly could do as you proposed.
The problem is that I also need the
spi_devdevice for thesysbus_connect_irq()call below.Quoted 8 lines
My
spi_devis referenced as "spi1" in the i.MX6 doc and I added a 'spi1" property for it in the i.MX6 soc.Once I have the
spi_devdevice it is trivial to retrieve thespi_busattached to it.So, yes this is not in line with what is done in
xlnx-zynqmp.cbut the need is a bit different.
Quoted 7 lines
I think the SoC should probably have an externally-facing IRQ line which it wires up internally to the SPI's IRQ line. (This corresponds basically to what happens in h/w -- the SoC's interfaces are defined by it even though many of them may be directly wired up to some internal component it has, but from outside the SoC you don't get access to the whole of the internal component.)
Well, each SPI controller has 4 possible CS lines to external devices and I have 5 SPI controllers.
This makes 20 externally facing IRQ lines (these are output lines) to add to the i.MX6 soc object as properties (with a meaningful naming convention).
And anyway, what I need to pass to sysbus_connect_irq() is a SYS_BUS_DEVICE and not an IRQ line ...
So do you mean I should define the 20 external lines (properties) and wire all of them up with sysbus_connect_irq() in the i.MX6 SOC implementation (fsl-imx6.c)?
Then How to you "connect" this externally facing line to the selected device CS line (here a FLASH memory) in sabrelite?
JC
Quoted 4 lines
thanks
-- PMM
Re: [Qemu-devel] [PATCH v3 12/12] i.MX: Add sabrelite i.MX6 emulation.
Quoted 8 lines · Jean-Christophe DUBOIS
Well, each SPI controller has 4 possible CS lines to external devices and I have 5 SPI controllers.
This makes 20 externally facing IRQ lines (these are output lines) to add to the i.MX6 soc object as properties (with a meaningful naming convention).
And anyway, what I need to pass to
sysbus_connect_irq()is aSYS_BUS_DEVICEand not an IRQ line ...
sysbus_connect_irq() is just syntactic sugar for a qdev_connect_gpio_out_named() call on the sysbus device; in this case you'd have a bunch of named gpio lines on the SoC device and use
qdev_connect_gpio_out_named(soc_device, SOC_CS_WHATEVER, 1, cs_line);
Quoted 3 lines
So do you mean I should define the 20 external lines (properties) and wire all of them up with
sysbus_connect_irq()in the i.MX6 SOC implementation (fsl-imx6.c)?
If you use qdev_init_gpio_out_named() in the SPI controller (which is probably a good idea anyway, chip selects aren't IRQs so using the gpio functions is clearer naming) then you ought to be able to create the appropriate aliases, since gpios are link properties. However I can't quite figure out how this is supposed to work -- Peter C ?
(There's a qdev_pass_gpios() which is almost right but that operates on all gpios rather than a specified subset.)
thanks
-- PMM
Quoted 15 lines · Jean-Christophe Dubois
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.
I've added patches 1-5 and 8 to target-arm.next, since they've been reviewed already; that will cut down the size of this series for subsequent versions.
thanks
-- PMM
Re: [Qemu-devel] [PATCH v3 12/12] i.MX: Add sabrelite i.MX6 emulation.
In reply to Peter MaydellQuoted 10 lines · Peter Maydell
Quoted 3 lines · Jean-Christophe DUBOIS
So do you mean I should define the 20 external lines (properties) and wire all of them up with
sysbus_connect_irq()in the i.MX6 SOC implementation (fsl-imx6.c)?If you use
qdev_init_gpio_out_named()in the SPI controller (which is probably a good idea anyway, chip selects aren't IRQs so using the gpio functions is clearer naming) then you ought to be able to create the appropriate aliases, since gpios are link properties. However I can't quite figure out how this is supposed to work -- Peter C ?
On the other hand if there isn't an obvious way to do this I'd be OK with taking this series with this part of the code the way you have it now, and we can clean it up later. We're already well into softfreeze so I'd rather we didn't delay too long...
thanks
-- PMM
Re: [Qemu-devel] [PATCH v3 06/12] ARM: Factor out ARM on/off PSCI control functions
In reply to Peter MaydellHi Peter,
I am wondering what is the "correct" (simple?) way in QEMU to put a CPU in a particular state (HYP, SVC, MON, ...) after I reset it (using cpu_reset()).
For example, if I reset a core that has "has_el3" property it will start in EL3 mode.
Now what is the simple way to transition this CPU to EL1 before starting running it with target_cpu_class->set_pc(target_cpu_state, entry);
Thanks
JC
Quoted 373 lines · Peter Maydell
Quoted 69 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 V2target-arm/Makefile.objs | 1 + target-arm/arm-powerctl.c | 156 ++++++++++++++++++++++++++++++++++++++++++++++ target-arm/arm-powerctl.h | 22 +++++++ target-arm/psci.c | 72 ++------------------- 4 files changed, 184 insertions(+), 67 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 +33
-0@@ -0,0 +1,156 @@ +/* +* 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 "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) {target-arm/arm-powerctl.c line 43
Quoted 10 lines
target-arm/arm-powerctl.c new file +10
-0+ARMCPU *armcpu =ARM_CPU (cpu); + +if (armcpu->mp_affinity == id) { +return cpu; + } + } + +qemu_log_mask (LOG_GUEST_ERROR , +"[ARM]%s: Resquesting unknown CPU %" PRId64"\n" , + __func__, id);"Requesting"
Quoted 27 lines
target-arm/arm-powerctl.c new file +27
-0+ +return NULL ; +} + +int arm_set_cpu_on (uint64_t cpuid,uint64_t entry,uint64_t context_id) +{ +CPUState *target_cpu_state; +ARMCPU *target_cpu; +CPUClass *target_cpu_class; +CPUARMState *env = &ARM_CPU (current_cpu)->env; + +DPRINTF ("cpu %" PRId64" @ 0x%" PRIx64" with R0 = 0x%" PRIx64"\n" , + cpuid, entry, context_id); + +/* change to the cpu we are powering up */ + target_cpu_state =arm_get_cpu_by_id (cpuid); +if (!target_cpu_state) { +return -1 ; + } + 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 -1 ; + } + target_cpu_class =CPU_GET_CLASS (target_cpu);target-arm/arm-powerctl.c line 80
Quoted 10 lines
target-arm/arm-powerctl.c new file +10
-0+ +/* 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. This is a generic function so it's a bit out of place for it to talk about PSCI spec details. What are the semantics provided by this helper function?
target-arm/arm-powerctl.c line 84
Quoted 4 lines
target-arm/arm-powerctl.c new file +4
-0+* +* 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 It's no longer true that we only implement EL1, incidentally.
Quoted 55 lines
target-arm/arm-powerctl.c new file +54
-0+* (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 ) { +return -1 ; + } + target_cpu->env.xregs[0 ] = context_id; + }else { + target_cpu->env.regs[0 ] = context_id; + target_cpu->env.thumb = entry &1 ; + } + + target_cpu_class->set_pc (target_cpu_state, entry); + +return 0 ; +} + +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); +target-arm/arm-powerctl.c line 148
Quoted 10 lines
target-arm/arm-powerctl.c new file +10
-0+/* change to the cpu we are resetting */ + target_cpu_state =arm_get_cpu_by_id (cpuid); +if (!target_cpu_state) { +return -1 ; + } + 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);Whether requesting a power-off of a powered off CPU is a guest error depends on the API used to request it, so you can't log this as a guest error in the generic helper function.
Quoted 24 lines
target-arm/arm-powerctl.c new file +8
-0+return -1 ; + } + +/* Reset the cpu */ +cpu_reset (target_cpu_state); + +return 0 ; +}target-arm/arm-powerctl.h new file +10
-0@@ -0,0 +1,22 @@ +/* +* 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. +* +*/ +target-arm/arm-powerctl.h line 20
Quoted 10 lines
target-arm/arm-powerctl.h new file +10
-0+#ifndef QEMU_ARM_POWERCTL_H +#define QEMU_ARM_POWERCTL_H + +CPUState *arm_get_cpu_by_id (uint64_t id); + +int arm_set_cpu_on (uint64_t cpuid,uint64_t entry,uint64_t context_id); + +void arm_set_cpu_off (uint64_t cpuid); + +int arm_reset_cpu (uint64_t cpuid);Please provide doc comments for new globally-visible functions.
Quoted 66 lines
target-arm/arm-powerctl.h new file +2
-0+ +#endif target-arm/psci.c +2
-19@@ -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 ;@@ -168,51 +152,8 @@ void arm_handle_psci_call(ARMCPU *cpu) entry = param[2 ]; context_id = param[3 ]; -/* change to the cpu we are powering up */ target-arm/psci.c void arm_handle_psci_call(ARMCPU *cpu) · line 181
Quoted 10 lines
target-arm/psci.c +0
-10- 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 ; - }You've lost the distinction between these two failure modes -- the PSCI error codes are returned to the guest and are mandated by the PSCI spec so you need to distinguish them.
Quoted 51 lines
target-arm/psci.c +3
-39- 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 ; - } - target_cpu_class->set_pc (target_cpu_state, entry); - - ret =0 ; + ret =arm_set_cpu_on (mpidr, entry, context_id) ? +QEMU_PSCI_RET_INVALID_PARAMS :0 ;break ;case QEMU_PSCI_0_1_FN_CPU_OFF :case QEMU_PSCI_0_2_FN_CPU_OFF :@@ -250,9 +191,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 2 lines
2.5.0
thanks
-- PMM
Re: [Qemu-devel] [PATCH v3 06/12] ARM: Factor out ARM on/off PSCI control functions
Quoted 7 lines · Jean-Christophe DUBOIS
Hi Peter,
I am wondering what is the "correct" (simple?) way in QEMU to put a CPU in a particular state (HYP, SVC, MON, ...) after I reset it (using
cpu_reset()).For example, if I reset a core that has "
has_el3" property it will start in EL3 mode.
If it's AArch64, yes. If it's AArch32 then it will start in Secure-SVC (which is EL3, but the distinction is that if you wanted NS-SVC then what you need to flip is the NS bit.)
Quoted 2 lines
Now what is the simple way to transition this CPU to EL1 before starting running it with
target_cpu_class->set_pc(target_cpu_state, entry);
There is no convenient API provided for this -- if you look at boot.c it just directly tweaks registers. We might want to abstract this out a bit better.
thanks
-- PMM