hw/arm/aspeed_ast27x0: minor IRQ number cleanup
cover hw/arm/aspeed_ast27x0: minor IRQ number cleanup
In the course of a conversation on IRC with somebody who was using the ast27x0 code as a model for a new board, I noticed that the code currently defines a local ARCH_GIC_MAINT_IRQ with a different value from the constant of the same name that we define in the include/hw/arm/bsa.h header. This patchset cleans that up and also another minor awkwardness that I spotted in the process.
thanks
-- PMM
Peter Maydell (2):
hw/arm/aspeed_ast27x0: Use bsa.h for PPI definitions hw/arm/aspeed_ast27x0: Avoid hardcoded '256' in IRQ calculation
hw/arm/aspeed_ast27x0.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/2 hw/arm/aspeed_ast27x0: Use bsa.h for PPI definitions
Use the private peripheral interrupt definitions from bsa.h instead of defining them locally.
Note that bsa.h defines these values as INTID values, which are all 16 greater than the PPI values that we were previously using. So we refactor the code to use INTID-based values to match that.
This is the same thing we did in commit d40ab068c07d9 for sbsa-ref. It removes the "same constant, different values" confusion where this board code and bsa.h both define an ARCH_GIC_MAINT_IRQ, and allows us to use symbolic names for the timer interrupt IDs.
--- hw/arm/aspeed_ast27x0.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
hw/arm/aspeed_ast27x0.c +10 -9
@@ -13,6 +13,7 @@#include "qapi/error.h" #include "hw/misc/unimp.h" #include "hw/arm/aspeed_soc.h" +#include "hw/arm/bsa.h" #include "qemu/module.h" #include "qemu/error-report.h" #include "hw/i2c/aspeed_i2c.h"
@@ -416,28 +417,28 @@ static bool aspeed_soc_ast2700_gic_realize(DeviceState *dev, Error **errp)for (i =0 ; i < sc->num_cpus; i++) {DeviceState *cpudev =DEVICE (&a->cpu[i]); -int NUM_IRQS =256 ,ARCH_GIC_MAINT_IRQ =9 ,VIRTUAL_PMU_IRQ =7 ; -int ppibase =NUM_IRQS + i *GIC_INTERNAL +GIC_NR_SGIS ; +int NUM_IRQS =256 ; +int intidbase =NUM_IRQS + i *GIC_INTERNAL ;const int timer_irq[] = { - [GTIMER_PHYS ] =14 , - [GTIMER_VIRT ] =11 , - [GTIMER_HYP ] =10 , - [GTIMER_SEC ] =13 , + [GTIMER_PHYS ] =ARCH_TIMER_NS_EL1_IRQ , + [GTIMER_VIRT ] =ARCH_TIMER_VIRT_IRQ , + [GTIMER_HYP ] =ARCH_TIMER_NS_EL2_IRQ , + [GTIMER_SEC ] =ARCH_TIMER_S_EL1_IRQ , };int j;for (j =0 ; j <ARRAY_SIZE (timer_irq); j++) {qdev_connect_gpio_out (cpudev, j, -qdev_get_gpio_in (gicdev, ppibase + timer_irq[j])); +qdev_get_gpio_in (gicdev, intidbase + timer_irq[j])); }qemu_irq irq =qdev_get_gpio_in (gicdev, - ppibase +ARCH_GIC_MAINT_IRQ ); + intidbase +ARCH_GIC_MAINT_IRQ );qdev_connect_gpio_out_named (cpudev,"gicv3-maintenance-interrupt" ,0 , irq);qdev_connect_gpio_out_named (cpudev,"pmu-interrupt" ,0 , -qdev_get_gpio_in (gicdev, ppibase +VIRTUAL_PMU_IRQ )); +qdev_get_gpio_in (gicdev, intidbase +VIRTUAL_PMU_IRQ ));sysbus_connect_irq (gicbusdev, i,qdev_get_gpio_in (cpudev,ARM_CPU_IRQ )); sysbus_connect_irq(gicbusdev, i + sc->num_cpus,
Signature · 1 line
2.34.1
Re: [PATCH 1/2] hw/arm/aspeed_ast27x0: Use bsa.h for PPI definitions
Quoted 57 lines · Peter Maydell
Use the private peripheral interrupt definitions from
bsa.hinstead of defining them locally.Note that
bsa.hdefines these values as INTID values, which are all 16 greater than the PPI values that we were previously using. So we refactor the code to use INTID-based values to match that.This is the same thing we did in commit
d40ab068c07d9for sbsa-ref. It removes the "same constant, different values" confusion where this board code andbsa.hboth define anARCH_GIC_MAINT_IRQ, and allows us to use symbolic names for the timer interrupt IDs.Signed-off-by Peter Maydell <[email protected]>--- hw/arm/aspeed_ast27x0.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)hw/arm/aspeed_ast27x0.c +8
-7@@ -13,6 +13,7 @@#include "qapi/error.h" #include "hw/misc/unimp.h" #include "hw/arm/aspeed_soc.h" +#include "hw/arm/bsa.h" #include "qemu/module.h" #include "qemu/error-report.h" #include "hw/i2c/aspeed_i2c.h" @@ -416,28 +417,28 @@ static bool aspeed_soc_ast2700_gic_realize(DeviceState *dev, Error **errp)for (i =0 ; i < sc->num_cpus; i++) {DeviceState *cpudev =DEVICE (&a->cpu[i]); -int NUM_IRQS =256 ,ARCH_GIC_MAINT_IRQ =9 ,VIRTUAL_PMU_IRQ =7 ; -int ppibase =NUM_IRQS + i *GIC_INTERNAL +GIC_NR_SGIS ; +int NUM_IRQS =256 ; +int intidbase =NUM_IRQS + i *GIC_INTERNAL ;const int timer_irq[] = { - [GTIMER_PHYS ] =14 , - [GTIMER_VIRT ] =11 , - [GTIMER_HYP ] =10 , - [GTIMER_SEC ] =13 , + [GTIMER_PHYS ] =ARCH_TIMER_NS_EL1_IRQ , + [GTIMER_VIRT ] =ARCH_TIMER_VIRT_IRQ , + [GTIMER_HYP ] =ARCH_TIMER_NS_EL2_IRQ , + [GTIMER_SEC ] =ARCH_TIMER_S_EL1_IRQ , };int j;for (j =0 ; j <ARRAY_SIZE (timer_irq); j++) {qdev_connect_gpio_out (cpudev, j, -qdev_get_gpio_in (gicdev, ppibase + timer_irq[j])); +qdev_get_gpio_in (gicdev, intidbase + timer_irq[j])); } qemu_irq irq = qdev_get_gpio_in(gicdev,
hw/arm/aspeed_ast27x0.c static bool aspeed_soc_ast2700_gic_realize(DeviceState *dev, Error **errp) · line 444
Quoted 10 lines
hw/arm/aspeed_ast27x0.c +2
-2- ppibase + ARCH_GIC_MAINT_IRQ); + intidbase + ARCH_GIC_MAINT_IRQ);qdev_connect_gpio_out_named (cpudev,"gicv3-maintenance-interrupt" ,0 , irq);qdev_connect_gpio_out_named (cpudev,"pmu-interrupt" ,0 , -qdev_get_gpio_in (gicdev, ppibase +VIRTUAL_PMU_IRQ )); +qdev_get_gpio_in (gicdev, intidbase +VIRTUAL_PMU_IRQ ));sysbus_connect_irq (gicbusdev, i,qdev_get_gpio_in (cpudev,ARM_CPU_IRQ )); sysbus_connect_irq(gicbusdev, i + sc->num_cpus,
Re: [PATCH 1/2] hw/arm/aspeed_ast27x0: Use bsa.h for PPI definitions
In reply to Peter MaydellQuoted 12 lines · Peter Maydell
Use the private peripheral interrupt definitions from
bsa.hinstead of defining them locally.Note that
bsa.hdefines these values as INTID values, which are all 16 greater than the PPI values that we were previously using. So we refactor the code to use INTID-based values to match that.This is the same thing we did in commit
d40ab068c07d9for sbsa-ref. It removes the "same constant, different values" confusion where this board code andbsa.hboth define anARCH_GIC_MAINT_IRQ, and allows us to use symbolic names for the timer interrupt IDs.
Quoted 4 lines
Signed-off-by Peter Maydell <[email protected]>--- hw/arm/aspeed_ast27x0.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
PATCH 2/2 hw/arm/aspeed_ast27x0: Avoid hardcoded '256' in IRQ calculation
In reply to Peter MaydellWhen calculating the index into the GIC's GPIO array for per-CPU interrupts, we have to start with the number of SPIs. The code currently hard-codes this to 'NUM_IRQS = 256'. However the number of SPIs is set separately and implicitly by the value of AST2700_MAX_IRQ, which is the number of SPIs plus 32 (since it is what we set the GIC num-irq property to).
Define AST2700_MAX_IRQ as the total number of SPIs; this brings AST2700 into line with AST2600, which defines AST2600_MAX_IRQ as the number of SPIs not including the 32 internal interrupts. We can then use AST2700_MAX_IRQ instead of the hardcoded 256.
--- hw/arm/aspeed_ast27x0.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
hw/arm/aspeed_ast27x0.c +3 -4
@@ -66,7 +66,7 @@ static const hwaddr aspeed_soc_ast2700_memmap[] = { [ASPEED_DEV_GPIO] = 0x14C0B000, }; -#define AST2700_MAX_IRQ 288 +#define AST2700_MAX_IRQ 256/* Shared Peripheral Interrupt values below are offset by -32 from datasheet */ static const int aspeed_soc_ast2700_irqmap[] = {
@@ -403,7 +403,7 @@ static bool aspeed_soc_ast2700_gic_realize(DeviceState *dev, Error **errp) gicdev =DEVICE (&a->gic);qdev_prop_set_uint32 (gicdev,"revision" ,3 );qdev_prop_set_uint32 (gicdev,"num-cpu" , sc->num_cpus); -qdev_prop_set_uint32 (gicdev,"num-irq" ,AST2700_MAX_IRQ ); +qdev_prop_set_uint32 (gicdev,"num-irq" ,AST2700_MAX_IRQ +GIC_INTERNAL ); redist_region_count =qlist_new ();qlist_append_int (redist_region_count, sc->num_cpus);
@@ -417,8 +417,7 @@ static bool aspeed_soc_ast2700_gic_realize(DeviceState *dev, Error **errp)for (i =0 ; i < sc->num_cpus; i++) {DeviceState *cpudev =DEVICE (&a->cpu[i]); -int NUM_IRQS =256 ; -int intidbase =NUM_IRQS + i *GIC_INTERNAL ; +int intidbase =AST2700_MAX_IRQ + i *GIC_INTERNAL ;const int timer_irq[] = { [GTIMER_PHYS ] =ARCH_TIMER_NS_EL1_IRQ ,
Signature · 1 line
2.34.1
Re: [PATCH 2/2] hw/arm/aspeed_ast27x0: Avoid hardcoded '256' in IRQ calculation
Quoted 40 lines · Peter Maydell
When calculating the index into the GIC's GPIO array for per-CPU interrupts, we have to start with the number of SPIs. The code currently hard-codes this to '
NUM_IRQS= 256'. However the number of SPIs is set separately and implicitly by the value ofAST2700_MAX_IRQ, which is the number of SPIs plus 32 (since it is what we set the GIC num-irq property to).Define
AST2700_MAX_IRQas the total number of SPIs; this brings AST2700 into line with AST2600, which definesAST2600_MAX_IRQas the number of SPIs not including the 32 internal interrupts. We can then useAST2700_MAX_IRQinstead of the hardcoded 256.Signed-off-by Peter Maydell <[email protected]>--- hw/arm/aspeed_ast27x0.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)hw/arm/aspeed_ast27x0.c +2
-2@@ -66,7 +66,7 @@ static const hwaddr aspeed_soc_ast2700_memmap[] = { [ASPEED_DEV_GPIO] = 0x14C0B000, }; -#define AST2700_MAX_IRQ 288 +#define AST2700_MAX_IRQ 256/* Shared Peripheral Interrupt values below are offset by -32 from datasheet */ static const int aspeed_soc_ast2700_irqmap[] = {@@ -403,7 +403,7 @@ static bool aspeed_soc_ast2700_gic_realize(DeviceState *dev, Error **errp) gicdev =DEVICE (&a->gic);qdev_prop_set_uint32 (gicdev,"revision" ,3 );qdev_prop_set_uint32 (gicdev,"num-cpu" , sc->num_cpus); -qdev_prop_set_uint32 (gicdev,"num-irq" ,AST2700_MAX_IRQ ); +qdev_prop_set_uint32 (gicdev,"num-irq" ,AST2700_MAX_IRQ +GIC_INTERNAL ); redist_region_count =qlist_new ();qlist_append_int (redist_region_count, sc->num_cpus);
hw/arm/aspeed_ast27x0.c static bool aspeed_soc_ast2700_gic_realize(DeviceState *dev, Error **errp) · line 423
Quoted 9 lines
hw/arm/aspeed_ast27x0.c +1
-2@@ -417,8 +417,7 @@ static bool aspeed_soc_ast2700_gic_realize(DeviceState *dev, Error **errp)for (i =0 ; i < sc->num_cpus; i++) {DeviceState *cpudev =DEVICE (&a->cpu[i]); -int NUM_IRQS =256 ; -int intidbase =NUM_IRQS + i *GIC_INTERNAL ; +int intidbase =AST2700_MAX_IRQ + i *GIC_INTERNAL ;const int timer_irq[] = { [GTIMER_PHYS ] =ARCH_TIMER_NS_EL1_IRQ ,
Re: [PATCH 2/2] hw/arm/aspeed_ast27x0: Avoid hardcoded '256' in IRQ calculation
In reply to Peter MaydellQuoted 12 lines · Peter Maydell
When calculating the index into the GIC's GPIO array for per-CPU interrupts, we have to start with the number of SPIs. The code currently hard-codes this to '
NUM_IRQS= 256'. However the number of SPIs is set separately and implicitly by the value ofAST2700_MAX_IRQ, which is the number of SPIs plus 32 (since it is what we set the GIC num-irq property to).Define
AST2700_MAX_IRQas the total number of SPIs; this brings AST2700 into line with AST2600, which definesAST2600_MAX_IRQas the number of SPIs not including the 32 internal interrupts. We can then useAST2700_MAX_IRQinstead of the hardcoded 256.
Quoted 4 lines
Signed-off-by Peter Maydell <[email protected]>--- hw/arm/aspeed_ast27x0.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
Re: [PATCH 2/2] hw/arm/aspeed_ast27x0: Avoid hardcoded '256' in IRQ calculation
In reply to Peter MaydellQuoted 31 lines · Peter Maydell
When calculating the index into the GIC's GPIO array for per-CPU interrupts, we have to start with the number of SPIs. The code currently hard-codes this to '
NUM_IRQS= 256'. However the number of SPIs is set separately and implicitly by the value ofAST2700_MAX_IRQ, which is the number of SPIs plus 32 (since it is what we set the GIC num-irq property to).Define
AST2700_MAX_IRQas the total number of SPIs; this brings AST2700 into line with AST2600, which definesAST2600_MAX_IRQas the number of SPIs not including the 32 internal interrupts. We can then useAST2700_MAX_IRQinstead of the hardcoded 256.Signed-off-by Peter Maydell <[email protected]>--- hw/arm/aspeed_ast27x0.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)hw/arm/aspeed_ast27x0.c +1
-1@@ -66,7 +66,7 @@ static const hwaddr aspeed_soc_ast2700_memmap[] = { [ASPEED_DEV_GPIO] = 0x14C0B000, }; -#define AST2700_MAX_IRQ 288 +#define AST2700_MAX_IRQ 256/* Shared Peripheral Interrupt values below are offset by -32 from datasheet */ static const int aspeed_soc_ast2700_irqmap[] = {
hw/arm/aspeed_ast27x0.c static bool aspeed_soc_ast2700_gic_realize(DeviceState *dev, Error **errp) · line 406
Quoted 5 lines
hw/arm/aspeed_ast27x0.c +1
-1@@ -403,7 +403,7 @@ static bool aspeed_soc_ast2700_gic_realize(DeviceState *dev, Error **errp) gicdev =DEVICE (&a->gic);qdev_prop_set_uint32 (gicdev,"revision" ,3 );qdev_prop_set_uint32 (gicdev,"num-cpu" , sc->num_cpus); -qdev_prop_set_uint32 (gicdev,"num-irq" ,AST2700_MAX_IRQ ); +qdev_prop_set_uint32 (gicdev,"num-irq" ,AST2700_MAX_IRQ +GIC_INTERNAL );
Pre-existing, GIC has AST2700_MAX_IRQ + GIC_INTERNAL IRQs, ...
hw/arm/aspeed_ast27x0.c static bool aspeed_soc_ast2700_gic_realize(DeviceState *dev, Error **errp) · line 420
Quoted 10 lines
hw/arm/aspeed_ast27x0.c +1
-2redist_region_count =qlist_new ();qlist_append_int (redist_region_count, sc->num_cpus);@@ -417,8 +417,7 @@ static bool aspeed_soc_ast2700_gic_realize(DeviceState *dev, Error **errp)for (i =0 ; i < sc->num_cpus; i++) {DeviceState *cpudev =DEVICE (&a->cpu[i]); -int NUM_IRQS =256 ; -int intidbase =NUM_IRQS + i *GIC_INTERNAL ; +int intidbase =AST2700_MAX_IRQ + i *GIC_INTERNAL ;
... then our base IRQ starts at AST2700_MAX_IRQ + i * GIC_INTERNAL, having i = [0..3]. Jamin, is that correct?
Quoted 3 lines
hw/arm/aspeed_ast27x0.c +0
-0const int timer_irq[] = { [GTIMER_PHYS ] =ARCH_TIMER_NS_EL1_IRQ ,
RE: [PATCH 2/2] hw/arm/aspeed_ast27x0: Avoid hardcoded '256' in IRQ calculation
Hi Philippe
Quoted 59 lines
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Thursday, January 30, 2025 11:03 PM
To: [email protected]; [email protected]
Cc: Cédric Le Goater <[email protected]>; Peter Maydell <[email protected]>; Steven Lee <[email protected]>; Troy Lee <[email protected]>; Jamin Lin <[email protected]>; Andrew Jeffery <[email protected]>; Joel Stanley <[email protected]>
Subject: Re: [PATCH 2/2] hw/arm/aspeed_ast27x0: Avoid hardcoded '256' in IRQ calculationhw/arm/aspeed_ast27x0.c static const hwaddr aspeed_soc_ast2700_memmap[] =
Quoted 22 lines · Peter Maydell
When calculating the index into the GIC's GPIO array for per-CPU interrupts, we have to start with the number of SPIs. The code currently hard-codes this to '
NUM_IRQS= 256'. However the number of SPIs is set separately and implicitly by the value ofAST2700_MAX_IRQ, which is the number of SPIs plus 32 (since it is what we set the GIC num-irq property to).Define
AST2700_MAX_IRQas the total number of SPIs; this brings AST2700 into line with AST2600, which definesAST2600_MAX_IRQas the number of SPIs not including the 32 internal interrupts. We can then useAST2700_MAX_IRQinstead of the hardcoded 256.Signed-off-by Peter Maydell <[email protected]>--- hw/arm/aspeed_ast27x0.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)hw/arm/aspeed_ast27x0.c index renamed from hw/arm/aspeed_ast27x0.c +0
-0
5638a7a5781..7b246440952100644hw/arm/aspeed_ast27x0.c +0
-0@@ -66,7 +66,7 @@ static const hwaddr aspeed_soc_ast2700_memmap[] ={
hw/arm/aspeed_ast27x0.c static const hwaddr aspeed_soc_ast2700_memmap[] = {
Quoted 7 lines
hw/arm/aspeed_ast27x0.c +1
-1[ASPEED_DEV_GPIO] = 0x14C0B000, }; -#define AST2700_MAX_IRQ 288 +#define AST2700_MAX_IRQ 256/* Shared Peripheral Interrupt values below are offset by -32 from datasheet */
hw/arm/aspeed_ast27x0.c
Quoted 8 lines
hw/arm/aspeed_ast27x0.c +0
-0static const int aspeed_soc_ast2700_irqmap[] = { @@ -403,7 +403,7 @@static bool
aspeed_soc_ast2700_gic_realize(DeviceState *dev, Error **errp)gicdev = DEVICE(&a->gic); qdev_prop_set_uint32(gicdev, "revision", 3); qdev_prop_set_uint32(gicdev, "num-cpu", sc->num_cpus);hw/arm/aspeed_ast27x0.c +2
-1-qdev_prop_set_uint32 (gicdev,"num-irq" ,AST2700_MAX_IRQ ); +qdev_prop_set_uint32 (gicdev,"num-irq" ,AST2700_MAX_IRQ + +GIC_INTERNAL );Pre-existing, GIC has
AST2700_MAX_IRQ+GIC_INTERNALIRQs, ...Quoted 6 lines
redist_region_count = qlist_new(); qlist_append_int(redist_region_count, sc->num_cpus); @@ -417,8+417,7 @@ static bool
aspeed_soc_ast2700_gic_realize(DeviceState *dev, Error **errp)
Quoted 9 lines
hw/arm/aspeed_ast27x0.c static bool aspeed_soc_ast2700_gic_realize(DeviceState *dev, Error **errp) · line 420
Quoted 5 lines
for (i = 0; i < sc->num_cpus; i++) { DeviceState *cpudev = DEVICE(&a->cpu[i]);hw/arm/aspeed_ast27x0.c +1
-2-int NUM_IRQS =256 ; -int intidbase =NUM_IRQS + i *GIC_INTERNAL ; +int intidbase =AST2700_MAX_IRQ + i *GIC_INTERNAL ;... then our base IRQ starts at
AST2700_MAX_IRQ+ i *GIC_INTERNAL, having i = [0..3]. Jamin, is that correct?
Correct.
The value of "i" is 0 to 3 and the value of intidbase is 256, 288, 320 and 352.
Quoted 3 lines
Quoted 3 lines
const int timer_irq[] = { [GTIMER_PHYS] = ARCH_TIMER_NS_EL1_IRQ,
Cédric Le Goater
AppliedQuoted 10 lines · Peter Maydell
In the course of a conversation on IRC with somebody who was using the ast27x0 code as a model for a new board, I noticed that the code currently defines a local
ARCH_GIC_MAINT_IRQwith a different value from the constant of the same name that we define in theinclude/hw/arm/bsa.hheader. This patchset cleans that up and also another minor awkwardness that I spotted in the process.thanks
-- PMM
Quoted 7 lines
Peter Maydell (2):
hw/arm/aspeed_ast27x0: Usebsa.hfor PPI definitions hw/arm/aspeed_ast27x0: Avoid hardcoded '256' in IRQ calculationhw/arm/aspeed_ast27x0.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
Applied to aspeed-next.
Thanks,
C.