hw: arm: exynos: Improvements and cleanups
Krzysztof Kozlowski
maintainerv4 cover hw: arm: exynos: Improvements and cleanups
Hi,
I split non-intrusive changes from my previous attempts [1].
This patchset contains only cleanups, minor improvements and support for power off. Power off itself will not happen because kernel will hang before trying it, on syncing IRQ works (fix for this is [2], but this will be separate).
Changes since v3:
1. Rebase on current master (API for shutdown changed).
2. Apply Peter's reviewed-by tag.
Best regards,
Krzysztof
[1] https://lists.gnu.org/archive/html/qemu-devel/2017-05/msg04821.html
[2] https://lists.gnu.org/archive/html/qemu-devel/2017-05/msg04818.html
Krzysztof Kozlowski (9):
hw/intc/exynos4210_gic: Use more meaningful name for local variable hw/timer/exynos4210_mct: Fix checkpatch style errors hw/timer/exynos4210_mct: Cleanup indentation and empty new lines hw/timer/exynos4210_mct: Remove unused defines hw/arm/exynos: Move DRAM initialization next boards hw/arm/exynos: Declare local variables in some order hw/arm/exynos: Use type define instead of hard-coded a9mpcore_priv
string
hw/intc/exynos4210_gic: Constify array of combiner interrupts hw/misc/exynos4210_pmu: Add support for system poweroff
hw/arm/exynos4210.c | 27 +++++------------------- hw/arm/exynos4_boards.c | 50 ++++++++++++++++++++++++++++++++++++++------- hw/intc/exynos4210_gic.c | 14 ++++++------- hw/misc/exynos4210_pmu.c | 20 +++++++++++++++++- hw/timer/exynos4210_mct.c | 50 +++++++++++++++++++-------------------------- include/hw/arm/exynos4210.h | 5 +---- 6 files changed, 96 insertions(+), 70 deletions(-)
Signature · 1 line
2.9.3
Krzysztof Kozlowski
maintainerPATCH v4 1/9 hw/intc/exynos4210_gic: Use more meaningful name for local variable
There are to SysBusDevice variables in exynos4210_gic_realize()
function: one for the device itself and second for arm_gic device. Add a prefix "gic" to the second one so it will be easier to understand the code.
While at it, put local uninitialized 'i' variable at the end, next to other uninitialized ones.
--- hw/intc/exynos4210_gic.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
hw/intc/exynos4210_gic.c +6 -6
@@ -286,21 +286,21 @@ static void exynos4210_gic_init(Object *obj)DeviceState *dev =DEVICE (obj);Exynos4210GicState *s =EXYNOS4210_GIC (obj);SysBusDevice *sbd =SYS_BUS_DEVICE (obj); -uint32_t i;const char cpu_prefix[] ="exynos4210-gic-alias_cpu" ;const char dist_prefix[] ="exynos4210-gic-alias_dist" ;char cpu_alias_name[sizeof (cpu_prefix) +3 ];char dist_alias_name[sizeof (cpu_prefix) +3 ]; -SysBusDevice *busdev; +SysBusDevice *gicbusdev; +uint32_t i; s->gic =qdev_create (NULL ,"arm_gic" );qdev_prop_set_uint32 (s->gic,"num-cpu" , s->num_cpu);qdev_prop_set_uint32 (s->gic,"num-irq" ,EXYNOS4210_GIC_NIRQ );qdev_init_nofail (s->gic); - busdev =SYS_BUS_DEVICE (s->gic); + gicbusdev =SYS_BUS_DEVICE (s->gic);/* Pass through outbound IRQ lines from the GIC */ -sysbus_pass_irq (sbd, busdev); +sysbus_pass_irq (sbd, gicbusdev);/* Pass through inbound GPIO lines to the GIC */ qdev_init_gpio_in(dev, exynos4210_gic_set_irq,
@@ -316,7 +316,7 @@ static void exynos4210_gic_init(Object *obj)sprintf (cpu_alias_name,"%s%x" , cpu_prefix, i);memory_region_init_alias (&s->cpu_alias[i], obj, cpu_alias_name, -sysbus_mmio_get_region (busdev,1 ), +sysbus_mmio_get_region (gicbusdev,1 ),0 ,EXYNOS4210_GIC_CPU_REGION_SIZE ); memory_region_add_subregion(&s->cpu_container,
@@ -326,7 +326,7 @@ static void exynos4210_gic_init(Object *obj)sprintf (dist_alias_name,"%s%x" , dist_prefix, i);memory_region_init_alias (&s->dist_alias[i], obj, dist_alias_name, -sysbus_mmio_get_region (busdev,0 ), +sysbus_mmio_get_region (gicbusdev,0 ),0 ,EXYNOS4210_GIC_DIST_REGION_SIZE ); memory_region_add_subregion(&s->dist_container,
Signature · 1 line
2.9.3
Krzysztof Kozlowski
maintainerPATCH v4 2/9 hw/timer/exynos4210_mct: Fix checkpatch style errors
Fix checkpatch errors:
1. ERROR: spaces required around that '+' (ctx:VxV)
2. ERROR: spaces required around that '&' (ctx:VxV)
No functional changes.
--- hw/timer/exynos4210_mct.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/timer/exynos4210_mct.c +2 -2
@@ -937,7 +937,7 @@ static void exynos4210_mct_update_freq(Exynos4210MCTState *s) {uint32_t freq = s->freq; s->freq =24000000 / - ((MCT_CFG_GET_PRESCALER (s->reg_mct_cfg)+1 ) * + ((MCT_CFG_GET_PRESCALER (s->reg_mct_cfg) +1 ) *MCT_CFG_GET_DIVIDER (s->reg_mct_cfg));if (freq != s->freq) {
@@ -1162,7 +1162,7 @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,DPRINTF ("comparator %d write 0x%llx val << %d\n" , index, value, shift); -if (offset&0x4 ) { +if (offset &0x4 ) { s->g_timer.reg.wstat |=G_WSTAT_COMP_U (index); }else { s->g_timer.reg.wstat |=G_WSTAT_COMP_L (index);
Signature · 1 line
2.9.3
Re: [Qemu-arm] [PATCH v4 2/9] hw/timer/exynos4210_mct: Fix checkpatch style errors
Quoted 8 lines · Krzysztof Kozlowski
Fix checkpatch errors:
1. ERROR: spaces required around that '+' (ctx:VxV)
2. ERROR: spaces required around that '&' (ctx:VxV)No functional changes.
Signed-off-by Krzysztof Kozlowski <[email protected]>Reviewed-by Peter Maydell <[email protected]>
Quoted 27 lines
--- hw/timer/exynos4210_mct.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/timer/exynos4210_mct.c +2
-2@@ -937,7 +937,7 @@ static void exynos4210_mct_update_freq(Exynos4210MCTState *s) {uint32_t freq = s->freq; s->freq =24000000 / - ((MCT_CFG_GET_PRESCALER (s->reg_mct_cfg)+1 ) * + ((MCT_CFG_GET_PRESCALER (s->reg_mct_cfg) +1 ) *MCT_CFG_GET_DIVIDER (s->reg_mct_cfg));if (freq != s->freq) {@@ -1162,7 +1162,7 @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,DPRINTF ("comparator %d write 0x%llx val << %d\n" , index, value, shift); -if (offset&0x4 ) { +if (offset &0x4 ) { s->g_timer.reg.wstat |=G_WSTAT_COMP_U (index); }else { s->g_timer.reg.wstat |=G_WSTAT_COMP_L (index);
Krzysztof Kozlowski
maintainerPATCH v4 3/9 hw/timer/exynos4210_mct: Cleanup indentation and empty new lines
In reply to Krzysztof KozlowskiStatements under 'case' were in some places wrongly indented bringing confusion and making the code less readable. Remove also few unneeded blank lines. No functional changes.
--- hw/timer/exynos4210_mct.c | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-)
hw/timer/exynos4210_mct.c +20 -25
@@ -1016,9 +1016,9 @@ static uint64_t exynos4210_mct_read(void *opaque, hwaddr offset,case G_COMP_L (0 ):case G_COMP_L (1 ):case G_COMP_L (2 ):case G_COMP_L (3 ):case G_COMP_U (0 ):case G_COMP_U (1 ):case G_COMP_U (2 ):case G_COMP_U (3 ): - index =GET_G_COMP_IDX (offset); - shift =8 * (offset &0x4 ); - value =UINT32_MAX & (s->g_timer.reg.comp[index] >> shift); + index =GET_G_COMP_IDX (offset); + shift =8 * (offset &0x4 ); + value =UINT32_MAX & (s->g_timer.reg.comp[index] >> shift);break ;case G_TCON :
@@ -1067,7 +1067,6 @@ static uint64_t exynos4210_mct_read(void *opaque, hwaddr offset, lt_i =GET_L_TIMER_IDX (offset); value =exynos4210_lfrc_get_count (&s->l_timer[lt_i]); -break ;case L0_TCON :case L1_TCON :
@@ -1153,23 +1152,23 @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,case G_COMP_L (0 ):case G_COMP_L (1 ):case G_COMP_L (2 ):case G_COMP_L (3 ):case G_COMP_U (0 ):case G_COMP_U (1 ):case G_COMP_U (2 ):case G_COMP_U (3 ): - index =GET_G_COMP_IDX (offset); - shift =8 * (offset &0x4 ); - s->g_timer.reg.comp[index] = - (s->g_timer.reg.comp[index] & - (((uint64_t )UINT32_MAX <<32 ) >> shift)) + - (value << shift); + index =GET_G_COMP_IDX (offset); + shift =8 * (offset &0x4 ); + s->g_timer.reg.comp[index] = + (s->g_timer.reg.comp[index] & + (((uint64_t )UINT32_MAX <<32 ) >> shift)) + + (value << shift); -DPRINTF ("comparator %d write 0x%llx val << %d\n" , index, value, shift); +DPRINTF ("comparator %d write 0x%llx val << %d\n" , index, value, shift); -if (offset &0x4 ) { - s->g_timer.reg.wstat |=G_WSTAT_COMP_U (index); - }else { - s->g_timer.reg.wstat |=G_WSTAT_COMP_L (index); - } +if (offset &0x4 ) { + s->g_timer.reg.wstat |=G_WSTAT_COMP_U (index); + }else { + s->g_timer.reg.wstat |=G_WSTAT_COMP_L (index); + } -exynos4210_gfrc_restart (s); -break ; +exynos4210_gfrc_restart (s); +break ;case G_TCON : old_val = s->g_timer.reg.tcon;
@@ -1207,7 +1206,6 @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,break ;case G_INT_ENB : -/* Raise IRQ if transition from disabled to enabled and CSTAT pending */ for (i =0 ; i <MCT_GT_CMP_NUM ; i++) { if ((value & G_INT_ENABLE(i)) > (s->g_timer.reg.tcon &
@@ -1288,7 +1286,6 @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,break ;case L0_TCNTB :case L1_TCNTB : - lt_i =GET_L_TIMER_IDX (offset); index =GET_L_TIMER_CNT_REG_IDX (offset, lt_i);
@@ -1316,7 +1313,6 @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,break ;case L0_ICNTB :case L1_ICNTB : - lt_i =GET_L_TIMER_IDX (offset); index =GET_L_TIMER_CNT_REG_IDX (offset, lt_i);
@@ -1353,13 +1349,12 @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,if (icntb_max[lt_i] < value) { icntb_max[lt_i] = value; } -DPRINTF ("local timer[%d] ICNTB write %llx; max=%x, min=%x\n\n" , - lt_i, value, icntb_max[lt_i], icntb_min[lt_i]); +DPRINTF ("local timer[%d] ICNTB write %llx; max=%x, min=%x\n\n" , + lt_i, value, icntb_max[lt_i], icntb_min[lt_i]);#endif -break ; +break ;case L0_FRCNTB :case L1_FRCNTB : - lt_i =GET_L_TIMER_IDX (offset); index =GET_L_TIMER_CNT_REG_IDX (offset, lt_i);
Signature · 1 line
2.9.3
Re: [Qemu-devel] [PATCH v4 3/9] hw/timer/exynos4210_mct: Cleanup indentation and empty new lines
Quoted 6 lines · Krzysztof Kozlowski
Statements under 'case' were in some places wrongly indented bringing confusion and making the code less readable. Remove also few unneeded blank lines. No functional changes.
Signed-off-by Krzysztof Kozlowski <[email protected]>Reviewed-by Peter Maydell <[email protected]>
Quoted 109 lines
--- hw/timer/exynos4210_mct.c | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-)hw/timer/exynos4210_mct.c +20
-25@@ -1016,9 +1016,9 @@ static uint64_t exynos4210_mct_read(void *opaque, hwaddr offset,case G_COMP_L (0 ):case G_COMP_L (1 ):case G_COMP_L (2 ):case G_COMP_L (3 ):case G_COMP_U (0 ):case G_COMP_U (1 ):case G_COMP_U (2 ):case G_COMP_U (3 ): - index =GET_G_COMP_IDX (offset); - shift =8 * (offset &0x4 ); - value =UINT32_MAX & (s->g_timer.reg.comp[index] >> shift); + index =GET_G_COMP_IDX (offset); + shift =8 * (offset &0x4 ); + value =UINT32_MAX & (s->g_timer.reg.comp[index] >> shift);break ;case G_TCON :@@ -1067,7 +1067,6 @@ static uint64_t exynos4210_mct_read(void *opaque, hwaddr offset, lt_i =GET_L_TIMER_IDX (offset); value =exynos4210_lfrc_get_count (&s->l_timer[lt_i]); -break ;case L0_TCON :case L1_TCON :@@ -1153,23 +1152,23 @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,case G_COMP_L (0 ):case G_COMP_L (1 ):case G_COMP_L (2 ):case G_COMP_L (3 ):case G_COMP_U (0 ):case G_COMP_U (1 ):case G_COMP_U (2 ):case G_COMP_U (3 ): - index =GET_G_COMP_IDX (offset); - shift =8 * (offset &0x4 ); - s->g_timer.reg.comp[index] = - (s->g_timer.reg.comp[index] & - (((uint64_t )UINT32_MAX <<32 ) >> shift)) + - (value << shift); + index =GET_G_COMP_IDX (offset); + shift =8 * (offset &0x4 ); + s->g_timer.reg.comp[index] = + (s->g_timer.reg.comp[index] & + (((uint64_t )UINT32_MAX <<32 ) >> shift)) + + (value << shift); -DPRINTF ("comparator %d write 0x%llx val << %d\n" , index, value, shift); +DPRINTF ("comparator %d write 0x%llx val << %d\n" , index, value, shift); -if (offset &0x4 ) { - s->g_timer.reg.wstat |=G_WSTAT_COMP_U (index); - }else { - s->g_timer.reg.wstat |=G_WSTAT_COMP_L (index); - } +if (offset &0x4 ) { + s->g_timer.reg.wstat |=G_WSTAT_COMP_U (index); + }else { + s->g_timer.reg.wstat |=G_WSTAT_COMP_L (index); + } -exynos4210_gfrc_restart (s); -break ; +exynos4210_gfrc_restart (s); +break ;case G_TCON : old_val = s->g_timer.reg.tcon;@@ -1207,7 +1206,6 @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,break ;case G_INT_ENB : -/* Raise IRQ if transition from disabled to enabled and CSTAT pending */ for (i =0 ; i <MCT_GT_CMP_NUM ; i++) { if ((value & G_INT_ENABLE(i)) > (s->g_timer.reg.tcon &@@ -1288,7 +1286,6 @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,break ;case L0_TCNTB :case L1_TCNTB : - lt_i =GET_L_TIMER_IDX (offset); index =GET_L_TIMER_CNT_REG_IDX (offset, lt_i);@@ -1316,7 +1313,6 @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,break ;case L0_ICNTB :case L1_ICNTB : - lt_i =GET_L_TIMER_IDX (offset); index =GET_L_TIMER_CNT_REG_IDX (offset, lt_i);@@ -1353,13 +1349,12 @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,if (icntb_max[lt_i] < value) { icntb_max[lt_i] = value; } -DPRINTF ("local timer[%d] ICNTB write %llx; max=%x, min=%x\n\n" , - lt_i, value, icntb_max[lt_i], icntb_min[lt_i]); +DPRINTF ("local timer[%d] ICNTB write %llx; max=%x, min=%x\n\n" , + lt_i, value, icntb_max[lt_i], icntb_min[lt_i]);#endif -break ; +break ;case L0_FRCNTB :case L1_FRCNTB : - lt_i =GET_L_TIMER_IDX (offset); index =GET_L_TIMER_CNT_REG_IDX (offset, lt_i);
Krzysztof Kozlowski
maintainerPATCH v4 4/9 hw/timer/exynos4210_mct: Remove unused defines
In reply to Krzysztof KozlowskiRemove defines not used anywhere.
--- hw/timer/exynos4210_mct.c | 3 --- 1 file changed, 3 deletions(-)
hw/timer/exynos4210_mct.c +0 -3
@@ -173,13 +173,10 @@ enum LocalTimerRegCntIndexes { L_REG_CNT_AMOUNT }; -#define MCT_NIRQ 6#define MCT_SFR_SIZE 0x444#define MCT_GT_CMP_NUM 4 -#define MCT_GT_MAX_VAL UINT64_MAX -#define MCT_GT_COUNTER_STEP 0x100000000ULL#define MCT_LT_COUNTER_STEP 0x100000000ULL#define MCT_LT_CNT_LOW_LIMIT 0x100
Signature · 1 line
2.9.3
Krzysztof Kozlowski
maintainerPATCH v4 5/9 hw/arm/exynos: Move DRAM initialization next boards
In reply to Krzysztof KozlowskiBefore QOM-ifying the Exynos4 SoC model, move the DRAM initialization from exynos4210.c to exynos4_boards.c because DRAM is board specific, not SoC.
--- hw/arm/exynos4210.c | 20 +----------------- hw/arm/exynos4_boards.c | 50 ++++++++++++++++++++++++++++++++++++++------- include/hw/arm/exynos4210.h | 5 +---- 3 files changed, 45 insertions(+), 30 deletions(-)
hw/arm/exynos4210.c +1 -19
@@ -160,13 +160,11 @@ static uint64_t exynos4210_calc_affinity(int cpu)return mp_affinity; } -Exynos4210State *exynos4210_init (MemoryRegion *system_mem, -unsigned long ram_size) +Exynos4210State *exynos4210_init (MemoryRegion *system_mem) {int i, n;Exynos4210State *s =g_new (Exynos4210State,1 );qemu_irq gate_irq[EXYNOS4210_NCPUS ][EXYNOS4210_IRQ_GATE_NINPUTS ]; -unsigned long mem_size;DeviceState *dev;SysBusDevice *busdev;ObjectClass *cpu_oc;
@@ -299,22 +297,6 @@ Exynos4210State *exynos4210_init(MemoryRegion *system_mem,memory_region_add_subregion (system_mem,EXYNOS4210_IRAM_BASE_ADDR , &s->iram_mem); -/* DRAM */ - mem_size = ram_size; -if (mem_size >EXYNOS4210_DRAM_MAX_SIZE ) { -memory_region_init_ram (&s->dram1_mem,NULL ,"exynos4210.dram1" , - mem_size -EXYNOS4210_DRAM_MAX_SIZE , &error_fatal); -vmstate_register_ram_global (&s->dram1_mem); -memory_region_add_subregion (system_mem,EXYNOS4210_DRAM1_BASE_ADDR , - &s->dram1_mem); - mem_size =EXYNOS4210_DRAM_MAX_SIZE ; - } -memory_region_init_ram (&s->dram0_mem,NULL ,"exynos4210.dram0" , mem_size, - &error_fatal); -vmstate_register_ram_global (&s->dram0_mem); -memory_region_add_subregion (system_mem,EXYNOS4210_DRAM0_BASE_ADDR , - &s->dram0_mem); -/* PMU. * The only reason of existence at the moment is that secondary CPU boot * loader uses PMU INFORM5 register as a holding pen.
hw/arm/exynos4_boards.c +43 -7
83 lines not on this page · raw message
include/hw/arm/exynos4210.h +1 -4
@@ -93,8 +93,6 @@ typedef struct Exynos4210State {MemoryRegion iram_mem;MemoryRegion irom_mem;MemoryRegion irom_alias_mem; -MemoryRegion dram0_mem; -MemoryRegion dram1_mem;MemoryRegion boot_secondary;MemoryRegion bootreg_mem;I2CBus *i2c_if[EXYNOS4210_I2C_NUMBER ];
@@ -103,8 +101,7 @@ typedef struct Exynos4210State {void exynos4210_write_secondary (ARMCPU *cpu,const struct arm_boot_info *info); -Exynos4210State *exynos4210_init (MemoryRegion *system_mem, -unsigned long ram_size); +Exynos4210State *exynos4210_init (MemoryRegion *system_mem);/* Initialize exynos4210 IRQ subsystem stub */ qemu_irq *exynos4210_init_irq (Exynos4210Irq *env);
Signature · 1 line
2.9.3
Krzysztof Kozlowski
maintainerPATCH v4 6/9 hw/arm/exynos: Declare local variables in some order
In reply to Krzysztof KozlowskiBring some more readability by declaring local function variables: first initialized ones and then the rest (with reversed-christmas-tree order).
--- hw/arm/exynos4210.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/arm/exynos4210.c +2 -2
@@ -162,12 +162,12 @@ static uint64_t exynos4210_calc_affinity(int cpu)Exynos4210State *exynos4210_init (MemoryRegion *system_mem) { -int i, n;Exynos4210State *s =g_new (Exynos4210State,1 );qemu_irq gate_irq[EXYNOS4210_NCPUS ][EXYNOS4210_IRQ_GATE_NINPUTS ]; -DeviceState *dev;SysBusDevice *busdev;ObjectClass *cpu_oc; +DeviceState *dev; +int i, n; cpu_oc =cpu_class_by_name (TYPE_ARM_CPU ,"cortex-a9" );assert (cpu_oc);
Signature · 1 line
2.9.3
Krzysztof Kozlowski
maintainerPATCH v4 7/9 hw/arm/exynos: Use type define instead of hard-coded a9mpcore_priv string
In reply to Krzysztof KozlowskiUse a define for a9mpcore_priv device type name instead of hard-coded string.
--- hw/arm/exynos4210.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/arm/exynos4210.c +2 -1
@@ -26,6 +26,7 @@#include "qemu-common.h" #include "qemu/log.h" #include "cpu.h" +#include "hw/cpu/a9mpcore.h" #include "hw/boards.h" #include "sysemu/sysemu.h" #include "hw/sysbus.h"
@@ -211,7 +212,7 @@ Exynos4210State *exynos4210_init(MemoryRegion *system_mem) }/* Private memory region and Internal GIC */ - dev =qdev_create (NULL ,"a9mpcore_priv" ); + dev =qdev_create (NULL ,TYPE_A9MPCORE_PRIV );qdev_prop_set_uint32 (dev,"num-cpu" ,EXYNOS4210_NCPUS );qdev_init_nofail (dev); busdev =SYS_BUS_DEVICE (dev);
Signature · 1 line
2.9.3
Krzysztof Kozlowski
maintainerPATCH v4 8/9 hw/intc/exynos4210_gic: Constify array of combiner interrupts
In reply to Krzysztof KozlowskiThe static array of interrupt combiner mappings is not modified so it can be made const for code safeness.
--- hw/intc/exynos4210_gic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/intc/exynos4210_gic.c +1 -1
@@ -116,7 +116,7 @@ enum ExtInt {* which is INTG16 in Internal Interrupt Combiner. */ -static uint32_t +static const uint32_t combiner_grp_to_gic_id[64 -EXYNOS4210_MAX_EXT_COMBINER_OUT_IRQ ][8 ] = {/* int combiner groups 16-19 */ { }, { }, { }, { },
Signature · 1 line
2.9.3
Krzysztof Kozlowski
maintainerPATCH v4 9/9 hw/misc/exynos4210_pmu: Add support for system poweroff
In reply to Krzysztof KozlowskiOn all Exynos-based boards, the system powers down itself by driving PS_HOLD signal low - eight bit in PS_HOLD_CONTROL register of PMU. Handle writing to respective PMU register to fix power off failure:
reboot: Power down
Unable to poweroff system
shutdown: 31 output lines suppressed due to ratelimiting
Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000000
CPU: 0 PID: 1 Comm: shutdown Not tainted 4.11.0-rc8 #846
Hardware name: SAMSUNG EXYNOS (Flattened Device Tree)
[<c031050c>] (unwind_backtrace) from [<c030ba6c>] (show_stack+0x10/0x14)
[<c030ba6c>] (show_stack) from [<c05b2800>] (dump_stack+0x88/0x9c)
[<c05b2800>] (dump_stack) from [<c03d3140>] (panic+0xdc/0x268)
[<c03d3140>] (panic) from [<c0343614>] (do_exit+0xa90/0xab4)
[<c0343614>] (do_exit) from [<c035f2dc>] (SyS_reboot+0x164/0x1d0)
[<c035f2dc>] (SyS_reboot) from [<c0307c80>] (ret_fast_syscall+0x0/0x3c)Additionally the initial value of PS_HOLD has to be changed because recent Linux kernel (v4.12-rc1) uses regmap cache for this access. When the register is kept at reset value, the kernel will not issue a write to it. Usually the bootloader sets the eight bit of PS_HOLD high so mimic its existence here.
--- hw/misc/exynos4210_pmu.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
hw/misc/exynos4210_pmu.c +19 -1
@@ -26,6 +26,7 @@#include "qemu/osdep.h" #include "hw/sysbus.h" +#include "sysemu/sysemu.h" #ifndef DEBUG_PMU #define DEBUG_PMU 0
@@ -350,7 +351,11 @@ static const Exynos4210PmuReg exynos4210_pmu_regs[] = { {"PAD_RETENTION_MMCB_OPTION", PAD_RETENTION_MMCB_OPTION, 0x00000000}, {"PAD_RETENTION_EBIA_OPTION", PAD_RETENTION_EBIA_OPTION, 0x00000000}, {"PAD_RETENTION_EBIB_OPTION", PAD_RETENTION_EBIB_OPTION, 0x00000000}, - {"PS_HOLD_CONTROL", PS_HOLD_CONTROL, 0x00005200}, +/* +* PS_HOLD_CONTROL: reset value and manually toggle high the DATA bit. +* DATA bit high, set usually by bootloader, keeps system on. +*/ + {"PS_HOLD_CONTROL", PS_HOLD_CONTROL, 0x00005200 | BIT(8)}, {"XUSBXTI_CONFIGURATION", XUSBXTI_CONFIGURATION, 0x00000001}, {"XUSBXTI_STATUS", XUSBXTI_STATUS, 0x00000001}, {"XUSBXTI_DURATION", XUSBXTI_DURATION, 0xFFF00000},
@@ -397,6 +402,12 @@ typedef struct Exynos4210PmuState {uint32_t reg[PMU_NUM_OF_REGISTERS ]; } Exynos4210PmuState; +static void exynos4210_pmu_poweroff (void ) +{ +PRINT_DEBUG ("QEMU PMU: PS_HOLD bit down, powering off\n" ); +qemu_system_shutdown_request (SHUTDOWN_CAUSE_GUEST_SHUTDOWN ); +} +static uint64_t exynos4210_pmu_read (void *opaque,hwaddr offset,unsigned size) {
@@ -428,6 +439,13 @@ static void exynos4210_pmu_write(void *opaque, hwaddr offset,PRINT_DEBUG_EXTEND ("%s <0x%04x> <- 0x%04x\n" , reg_p->name, (uint32_t )offset, (uint32_t )val); s->reg[i] = val; +if ((offset ==PS_HOLD_CONTROL ) && ((val &BIT (8 )) ==0 )) { +/* +* We are interested only in setting data bit +* of PS_HOLD_CONTROL register to indicate power off request. +*/ +exynos4210_pmu_poweroff (); + }return ; } reg_p++;
Signature · 1 line
2.9.3
Re: [Qemu-arm] [PATCH v4 9/9] hw/misc/exynos4210_pmu: Add support for system poweroff
Quoted 18 lines · Krzysztof Kozlowski
On all Exynos-based boards, the system powers down itself by driving
PS_HOLDsignal low - eight bit inPS_HOLD_CONTROLregister of PMU. Handle writing to respective PMU register to fix power off failure:reboot: Power down Unable to poweroff system shutdown: 31 output lines suppressed due to ratelimiting Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000000 CPU: 0 PID: 1 Comm: shutdown Not tainted 4.11.0-rc8 #846 Hardware name: SAMSUNG EXYNOS (Flattened Device Tree) [<c031050c>] (unwind_backtrace) from [<c030ba6c>] (show_stack+0x10/0x14) [<c030ba6c>] (show_stack) from [<c05b2800>] (dump_stack+0x88/0x9c) [<c05b2800>] (dump_stack) from [<c03d3140>] (panic+0xdc/0x268) [<c03d3140>] (panic) from [<c0343614>] (do_exit+0xa90/0xab4) [<c0343614>] (do_exit) from [<c035f2dc>] (SyS_reboot+0x164/0x1d0) [<c035f2dc>] (SyS_reboot) from [<c0307c80>] (ret_fast_syscall+0x0/0x3c)
Quoted 8 lines
Additionally the initial value of
PS_HOLDhas to be changed because recent Linux kernel (v4.12-rc1) uses regmap cache for this access. When the register is kept at reset value, the kernel will not issue a write to it. Usually the bootloader sets the eight bit ofPS_HOLDhigh so mimic its existence here.Signed-off-by Krzysztof Kozlowski <[email protected]>Reviewed-by Peter Maydell <[email protected]>
Quoted 57 lines
--- hw/misc/exynos4210_pmu.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)hw/misc/exynos4210_pmu.c +19
-1@@ -26,6 +26,7 @@#include "qemu/osdep.h" #include "hw/sysbus.h" +#include "sysemu/sysemu.h" #ifndef DEBUG_PMU #define DEBUG_PMU 0@@ -350,7 +351,11 @@ static const Exynos4210PmuReg exynos4210_pmu_regs[] = { {"PAD_RETENTION_MMCB_OPTION", PAD_RETENTION_MMCB_OPTION, 0x00000000}, {"PAD_RETENTION_EBIA_OPTION", PAD_RETENTION_EBIA_OPTION, 0x00000000}, {"PAD_RETENTION_EBIB_OPTION", PAD_RETENTION_EBIB_OPTION, 0x00000000}, - {"PS_HOLD_CONTROL", PS_HOLD_CONTROL, 0x00005200}, +/* +* PS_HOLD_CONTROL: reset value and manually toggle high the DATA bit. +* DATA bit high, set usually by bootloader, keeps system on. +*/ + {"PS_HOLD_CONTROL", PS_HOLD_CONTROL, 0x00005200 | BIT(8)}, {"XUSBXTI_CONFIGURATION", XUSBXTI_CONFIGURATION, 0x00000001}, {"XUSBXTI_STATUS", XUSBXTI_STATUS, 0x00000001}, {"XUSBXTI_DURATION", XUSBXTI_DURATION, 0xFFF00000},@@ -397,6 +402,12 @@ typedef struct Exynos4210PmuState {uint32_t reg[PMU_NUM_OF_REGISTERS ]; } Exynos4210PmuState; +static void exynos4210_pmu_poweroff (void ) +{ +PRINT_DEBUG ("QEMU PMU: PS_HOLD bit down, powering off\n" ); +qemu_system_shutdown_request (SHUTDOWN_CAUSE_GUEST_SHUTDOWN ); +} +static uint64_t exynos4210_pmu_read (void *opaque,hwaddr offset,unsigned size) {@@ -428,6 +439,13 @@ static void exynos4210_pmu_write(void *opaque, hwaddr offset,PRINT_DEBUG_EXTEND ("%s <0x%04x> <- 0x%04x\n" , reg_p->name, (uint32_t )offset, (uint32_t )val); s->reg[i] = val; +if ((offset ==PS_HOLD_CONTROL ) && ((val &BIT (8 )) ==0 )) { +/* +* We are interested only in setting data bit +* of PS_HOLD_CONTROL register to indicate power off request. +*/ +exynos4210_pmu_poweroff (); + }return ; } reg_p++;
Re: [Qemu-devel] [PATCH v4 1/9] hw/intc/exynos4210_gic: Use more meaningful name for local variable
In reply to Krzysztof KozlowskiQuoted 10 lines · Krzysztof Kozlowski
There are to SysBusDevice variables in
exynos4210_gic_realize()
function: one for the device itself and second forarm_gicdevice. Add a prefix "gic" to the second one so it will be easier to understand the code.While at it, put local uninitialized 'i' variable at the end, next to other uninitialized ones.
Signed-off-by Krzysztof Kozlowski <[email protected]>Reviewed-by Peter Maydell <[email protected]>
Quoted 53 lines
--- hw/intc/exynos4210_gic.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)hw/intc/exynos4210_gic.c +6
-6@@ -286,21 +286,21 @@ static void exynos4210_gic_init(Object *obj)DeviceState *dev =DEVICE (obj);Exynos4210GicState *s =EXYNOS4210_GIC (obj);SysBusDevice *sbd =SYS_BUS_DEVICE (obj); -uint32_t i;const char cpu_prefix[] ="exynos4210-gic-alias_cpu" ;const char dist_prefix[] ="exynos4210-gic-alias_dist" ;char cpu_alias_name[sizeof (cpu_prefix) +3 ];char dist_alias_name[sizeof (cpu_prefix) +3 ]; -SysBusDevice *busdev; +SysBusDevice *gicbusdev; +uint32_t i; s->gic =qdev_create (NULL ,"arm_gic" );qdev_prop_set_uint32 (s->gic,"num-cpu" , s->num_cpu);qdev_prop_set_uint32 (s->gic,"num-irq" ,EXYNOS4210_GIC_NIRQ );qdev_init_nofail (s->gic); - busdev =SYS_BUS_DEVICE (s->gic); + gicbusdev =SYS_BUS_DEVICE (s->gic);/* Pass through outbound IRQ lines from the GIC */ -sysbus_pass_irq (sbd, busdev); +sysbus_pass_irq (sbd, gicbusdev);/* Pass through inbound GPIO lines to the GIC */ qdev_init_gpio_in(dev, exynos4210_gic_set_irq,@@ -316,7 +316,7 @@ static void exynos4210_gic_init(Object *obj)sprintf (cpu_alias_name,"%s%x" , cpu_prefix, i);memory_region_init_alias (&s->cpu_alias[i], obj, cpu_alias_name, -sysbus_mmio_get_region (busdev,1 ), +sysbus_mmio_get_region (gicbusdev,1 ),0 ,EXYNOS4210_GIC_CPU_REGION_SIZE ); memory_region_add_subregion(&s->cpu_container,@@ -326,7 +326,7 @@ static void exynos4210_gic_init(Object *obj)sprintf (dist_alias_name,"%s%x" , dist_prefix, i);memory_region_init_alias (&s->dist_alias[i], obj, dist_alias_name, -sysbus_mmio_get_region (busdev,0 ), +sysbus_mmio_get_region (gicbusdev,0 ),0 ,EXYNOS4210_GIC_DIST_REGION_SIZE ); memory_region_add_subregion(&s->dist_container,
Quoted 4 lines · Krzysztof Kozlowski
Hi,
I split non-intrusive changes from my previous attempts [1].
Quoted 8 lines
This patchset contains only cleanups, minor improvements and support for power off. Power off itself will not happen because kernel will hang before trying it, on syncing IRQ works (fix for this is [2], but this will be separate).
Changes since v3:
1. Rebase on current master (API for shutdown changed).
2. Apply Peter's reviewed-by tag.
Thanks for splitting these out.
Applied to target-arm.next, thanks.
-- PMM