Add ASPEED SCU device
cover Add ASPEED SCU device
Hi all,
These are two patches implementing minimal functionality for the ASPEED System Control Unit device and integrating it into the AST2400 SoC model. The device is critical for initialisation of u-boot and the kernel as it provides chip level control registers, influencing the configuration of the software and the software's configuration of the SoC.
Cheers,
Andrew
Andrew Jeffery (2):
hw/misc: Add a model for the ASPEED System Control Unit
ast2400: Integrate the SCU model and configure reset values
hw/arm/ast2400.c | 57 +++++++++++++++++ hw/misc/Makefile.objs | 1 + hw/misc/aspeed_scu.c | 147 +++++++++++++++++++++++++++++++++++++++++++ include/hw/arm/ast2400.h | 2 + include/hw/misc/aspeed_scu.h | 108 +++++++++++++++++++++++++++++++ trace-events | 3 + 6 files changed, 318 insertions(+) create mode 100644 hw/misc/aspeed_scu.c create mode 100644 include/hw/misc/aspeed_scu.h
Signature · 1 line
2.7.4
PATCH 1/2 hw/misc: Add a model for the ASPEED System Control Unit
The SCU is a collection of chip-level control registers that manage the various functions supported by the AST2400. Typically the bits control interactions with clocks, external hardware or reset behaviour, and we can largly take a hands-off approach to reads and writes.
Firmware makes heavy use of the state to determine how to boot, but the reset values vary from SoC to SoC. qdev properties are exposed so that the integrating SoC model can configure the appropriate reset values.
--- hw/misc/Makefile.objs | 1 + hw/misc/aspeed_scu.c | 147 +++++++++++++++++++++++++++++++++++++++++++ include/hw/misc/aspeed_scu.h | 108 +++++++++++++++++++++++++++++++ trace-events | 3 + 4 files changed, 259 insertions(+) create mode 100644 hw/misc/aspeed_scu.c create mode 100644 include/hw/misc/aspeed_scu.h
hw/misc/Makefile.objs +1 -0
@@ -52,3 +52,4 @@ obj-$(CONFIG_PVPANIC) += pvpanic.o obj-$(CONFIG_EDU) += edu.o obj-$(CONFIG_HYPERV_TESTDEV) += hyperv_testdev.o obj-$(CONFIG_AUX) += aux.o +obj-$(CONFIG_ASPEED_SOC) += aspeed_scu.o
hw/misc/aspeed_scu.c new file +147 -0
147 lines not on this page · raw message
include/hw/misc/aspeed_scu.h new file +108 -0
108 lines not on this page · raw message
trace-events +3 -0
@@ -2164,3 +2164,6 @@ e1000e_cfg_support_virtio(bool support) "Virtio header supported: %d" e1000e_vm_state_running(void) "VM state is running" e1000e_vm_state_stopped(void) "VM state is stopped" + +# hw/misc/aspeed_scu.c +aspeed_scu_write(uint64_t offset, unsigned size, uint32_t data) "To 0x%" PRIx64 " of size %u: 0x%" PRIx32
Signature · 1 line
2.7.4
Re: [Qemu-arm] [PATCH 1/2] hw/misc: Add a model for the ASPEED System Control Unit
Quoted 13 lines · Andrew Jeffery
The SCU is a collection of chip-level control registers that manage the various functions supported by the AST2400. Typically the bits control interactions with clocks, external hardware or reset behaviour, and we can largly take a hands-off approach to reads and writes.
Firmware makes heavy use of the state to determine how to boot, but the reset values vary from SoC to SoC. qdev properties are exposed so that the integrating SoC model can configure the appropriate reset values.
Signed-off-by Andrew Jeffery <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>Reviewed-by Joel Stanley <[email protected]>---
hw/misc/aspeed_scu.c
Quoted 7 lines
hw/misc/aspeed_scu.c new file +7
-0+static Property aspeed_scu_properties[] = { +DEFINE_PROP_ARRAY ("reset" , AspeedSCUState, num_resets, reset, + qdev_prop_uint32, uint32_t), +DEFINE_PROP_END_OF_LIST (), +}; + +#define ASPEED_SCU_NR_REGS (0x1A8 >> 2)
This seems like a very unwieldy way of specifying the reset values for this device. Are they really all fully configurable in the hardware? It seems unlikely. I'd much rather see something that looks more like what you might plausibly be configuring when wiring up the SoC, which might be some version/revision numbers and/or some particular tweakable parameters.
thanks
-- PMM
Re: [Qemu-arm] [PATCH 1/2] hw/misc: Add a model for the ASPEED System Control Unit
On Fri, 2016-06-17 at 15:22 +0100, Peter Maydell wrote:
On 16 June 2016 at 08:48, Andrew Jeffery <[email protected]> wrote:
The SCU is a collection of chip-level control registers that manage the various functions supported by the AST2400. Typically the bits control interactions with clocks, external hardware or reset behaviour, and we can largly take a hands-off approach to reads and writes.
Firmware makes heavy use of the state to determine how to boot, but the reset values vary from SoC to SoC. qdev properties are exposed so that the integrating SoC model can configure the appropriate reset values.
---
+static Property aspeed_scu_properties[] = {
+ DEFINE_PROP_ARRAY("reset", AspeedSCUState, num_resets, reset, + qdev_prop_uint32, uint32_t),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+#define ASPEED_SCU_NR_REGS (0x1A8 >> 2)
This seems like a very unwieldy way of specifying the reset values for this device. Are they really all fully configurable in the hardware? It seems unlikely. I'd much rather see something that looks more like what you might plausibly be configuring when wiring up the SoC, which might be some version/revision numbers and/or some particular tweakable parameters.
Right. I left out some context which may clear things up: We are working with two SoCs at the moment, the AST2400 and AST2500 (hopefully the AST2500 patches will be sent to the list soon). I wanted to abstract the configuration to cater for the differences in register values between the SoCs, less so for wiring the one SoC up in a different fashion. For what it's worth, out of 86 registers defined in the IO space between the two SoCs, 37 take the same value and 49 differ.
I can rework the commit message to say as much.
Separately, the qdev array approach was lifted from your commit 9c7d489379c2 hw/vexpress: Set reset values for daughterboard oscillators. Another approach would be to set the members of the SCU's reset array directly as we know the type. That seems less convoluted but my gut instinct was that wasn't how we should be configuring the devices. Is qdev the right way to go in the SCU's case?
Cheers,
Andrew
Re: [Qemu-arm] [PATCH 1/2] hw/misc: Add a model for the ASPEED System Control Unit
Quoted 15 lines · Andrew Jeffery
Quoted 7 lines · Peter Maydell
hw/misc/aspeed_scu.c new file +7
-0+static Property aspeed_scu_properties[] = { +DEFINE_PROP_ARRAY ("reset" , AspeedSCUState, num_resets, reset, + qdev_prop_uint32, uint32_t), +DEFINE_PROP_END_OF_LIST (), +}; + +#define ASPEED_SCU_NR_REGS (0x1A8 >> 2)Quoted 6 lines
This seems like a very unwieldy way of specifying the reset values for this device. Are they really all fully configurable in the hardware? It seems unlikely. I'd much rather see something that looks more like what you might plausibly be configuring when wiring up the SoC, which might be some version/revision numbers and/or some particular tweakable parameters.
Quoted 8 lines
Right. I left out some context which may clear things up: We are working with two SoCs at the moment, the AST2400 and AST2500 (hopefully the AST2500 patches will be sent to the list soon). I wanted to abstract the configuration to cater for the differences in register values between the SoCs, less so for wiring the one SoC up in a different fashion. For what it's worth, out of 86 registers defined in the IO space between the two SoCs, 37 take the same value and 49 differ.
I think there are a couple of plausible ways you might model this:
(a) just have a single property for "revision" which corresponds to the revision of this bit of silicon IP within the SoC; the model of the device itself then knows what the reset state is for this revision of the device.
(b) ditto, but also have some configurable flags where relevant (ie approximately where it's the same IP rev within the SoC but it's been configured by tying down different config lines; for instance hw/dma/pl330.c has a collection of properties which match the configurable knobs for the hardware.)
You might or might not have enough visibility into the thing to know which of these is closest to what the real hardware is doing; if not then it's a matter of taste, looking at what is varying between the two and what isn't, etc. But "board level specifies all the register reset values" is definitely far too broad and generalised an API, I think.
Quoted 3 lines
Separately, the qdev array approach was lifted from your commit
9c7d489379c2hw/vexpress: Set reset values for daughterboard oscillators.
You'll notice that we only configure the specific things that need configuring with interfaces specific to those things (eg "daughterboard clocks" and "daughterboard voltages" are separate), not a single "have a complete set of register values" API.
Quoted 4 lines
Another approach would be to set the members of the SCU's reset array directly as we know the type. That seems less convoluted but my gut instinct was that wasn't how we should be configuring the devices. Is qdev the right way to go in the SCU's case?
We should definitely use qdev rather than poking directly at the device's internal state struct.
thanks
-- PMM
Re: [Qemu-arm] [PATCH 1/2] hw/misc: Add a model for the ASPEED System Control Unit
Quoted 27 lines · Peter Maydell
Quoted 16 lines · Andrew Jeffery
Quoted 8 lines · Peter Maydell
hw/misc/aspeed_scu.c new file +7
-0+static Property aspeed_scu_properties[] = { + DEFINE_PROP_ARRAY("reset", AspeedSCUState, num_resets, reset, + qdev_prop_uint32, uint32_t), + DEFINE_PROP_END_OF_LIST(), +}; + +#define ASPEED_SCU_NR_REGS (0x1A8 >> 2)Quoted 6 lines
This seems like a very unwieldy way of specifying the reset values for this device. Are they really all fully configurable in the hardware? It seems unlikely. I'd much rather see something that looks more like what you might plausibly be configuring when wiring up the SoC, which might be some version/revision numbers and/or some particular tweakable parameters.
Quoted 8 lines
Right. I left out some context which may clear things up: We are working with two SoCs at the moment, the AST2400 and AST2500 (hopefully the AST2500 patches will be sent to the list soon). I wanted to abstract the configuration to cater for the differences in register values between the SoCs, less so for wiring the one SoC up in a different fashion. For what it's worth, out of 86 registers defined in the IO space between the two SoCs, 37 take the same value and 49 differ.
I think there are a couple of plausible ways you might model this:
Quoted 9 lines
(a) just have a single property for "revision" which corresponds to the revision of this bit of silicon IP within the SoC; the model of the device itself then knows what the reset state is for this revision of the device.
(b) ditto, but also have some configurable flags where relevant (ie approximately where it's the same IP rev within the SoC but it's been configured by tying down different config lines; for instancehw/dma/pl330.chas a collection of properties which match the configurable knobs for the hardware.)
Okay. I think (b) is the most appropriate. The board-controllable bits are primarily in the hardware strapping register. The register is composed of fields of mostly unrelated bits, so we could go two ways here:
(1) expose the register through a single 32bit property
(2) break out a property for each bitfield
Do you have a preference? grepping the tree suggests there isn't a precedent for "large" numbers of properties* so maybe (2) is overkill, but (1) feels like it might fit into the overly-general-interface problem that we're trying to eliminate.
* Seems the microblaze CPU defines the most with 9 properties? Approach
(2) will leave us with 21 properties for the SCU.
$ git grep -c DEFINE_PROP | sort -t: -k2 -r | head -n1
target-microblaze/cpu.c:9Quoted 9 lines
You might or might not have enough visibility into the thing to know which of these is closest to what the real hardware is doing; if not then it's a matter of taste, looking at what is varying between the two and what isn't, etc. But "board level specifies all the register reset values" is definitely far too broad and generalised an API, I think.
Quoted 1 line
Quoted 7 lines
Quoted 3 lines
Separately, the qdev array approach was lifted from your commit
9c7d489379c2hw/vexpress: Set reset values for daughterboard oscillators.You'll notice that we only configure the specific things that need configuring with interfaces specific to those things (eg "daughterboard clocks" and "daughterboard voltages" are separate), not a single "have a complete set of register values" API.
Yes, I appreciate that now. Thanks.
Andrew
Re: [Qemu-devel] [PATCH 1/2] hw/misc: Add a model for the ASPEED System Control Unit
Quoted 21 lines · Andrew Jeffery
Quoted 11 lines · Peter Maydell
I think there are a couple of plausible ways you might model this:
(a) just have a single property for "revision" which corresponds to the revision of this bit of silicon IP within the SoC; the model of the device itself then knows what the reset state is for this revision of the device.
(b) ditto, but also have some configurable flags where relevant (ie approximately where it's the same IP rev within the SoC but it's been configured by tying down different config lines; for instancehw/dma/pl330.chas a collection of properties which match the configurable knobs for the hardware.)Okay. I think (b) is the most appropriate. The board-controllable bits are primarily in the hardware strapping register. The register is composed of fields of mostly unrelated bits, so we could go two ways here:
(1) expose the register through a single 32bit property
(2) break out a property for each bitfield
Quoted 6 lines
Do you have a preference? grepping the tree suggests there isn't a precedent for "large" numbers of properties* so maybe (2) is overkill, but (1) feels like it might fit into the overly-general-interface problem that we're trying to eliminate.
* Seems the microblaze CPU defines the most with 9 properties?
(You forgot '-n' on your sort rune.)hw/dma/pl330.c has 15.
Quoted 1 line
Approach (2) will leave us with 21 properties for the SCU.
What would the 21 properties be in this case?
But yes, a single 32 bit property would probably be better.
thanks
-- PMM
Re: [Qemu-arm] [PATCH 1/2] hw/misc: Add a model for the ASPEED System Control Unit
Quoted 23 lines · Peter Maydell
Quoted 22 lines · Andrew Jeffery
Quoted 12 lines · Peter Maydell
I think there are a couple of plausible ways you might model this:
(a) just have a single property for "revision" which corresponds to the revision of this bit of silicon IP within the SoC; the model of the device itself then knows what the reset state is for this revision of the device.
(b) ditto, but also have some configurable flags where relevant (ie approximately where it's the same IP rev within the SoC but it's been configured by tying down different config lines; for instancehw/dma/pl330.chas a collection of properties which match the configurable knobs for the hardware.)Okay. I think (b) is the most appropriate. The board-controllable bits are primarily in the hardware strapping register. The register is composed of fields of mostly unrelated bits, so we could go two ways here:
(1) expose the register through a single 32bit property
(2) break out a property for each bitfield
Quoted 8 lines
Quoted 6 lines
Do you have a preference? grepping the tree suggests there isn't a precedent for "large" numbers of properties* so maybe (2) is overkill, but (1) feels like it might fit into the overly-general-interface problem that we're trying to eliminate.
* Seems the microblaze CPU defines the most with 9 properties?
(You forgot '-n' on your sort rune.)
hw/dma/pl330.chas 15.
Ugh.
Quoted 6 lines
Quoted 3 lines
Approach (2) will leave us with 21 properties for the SCU.
What would the 21 properties be in this case?
But yes, a single 32 bit property would probably be better.
Alright, I'll go ahead with that.
Thanks for the feedback.
Andrew
PATCH 2/2 ast2400: Integrate the SCU model and configure reset values
In reply to Andrew JefferyAlmost all configured reset values are specified by the datasheet. The notable exception is ASPEED_SCU_SOC_SCRATCH1, where we mark the DRAM as successfully initialised by the SoC to avoid unnecessary dark corners in the SoC's u-boot support.
--- hw/arm/ast2400.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/arm/ast2400.h | 2 ++ 2 files changed, 59 insertions(+)
hw/arm/ast2400.c +57 -0
@@ -24,12 +24,48 @@#define AST2400_IOMEM_SIZE 0x00200000#define AST2400_IOMEM_BASE 0x1E600000#define AST2400_VIC_BASE 0x1E6C0000 +#define AST2400_SCU_BASE 0x1E6E2000#define AST2400_TIMER_BASE 0x1E782000#define AST2400_I2C_BASE 0x1E78A000static const int uart_irqs[] = {9 ,32 ,33 ,34 ,10 };static const int timer_irqs[] = {16 ,17 ,18 ,35 ,36 ,37 ,38 ,39 , }; +static const AspeedSCUResetCfg scu_reset[] = { +/* Values are defaults from the datasheet except where noted */ + {ASPEED_SCU_SYS_RST_CTRL ,0xFFCFFEDCU }, + {ASPEED_SCU_CLK_SEL ,0xF3F40000U }, + {ASPEED_SCU_CLK_STOP_CTRL ,0x19FC3E8BU }, + {ASPEED_SCU_D2PLL_PARAM ,0x00026108U }, + {ASPEED_SCU_MPLL_PARAM ,0x00030291U }, + {ASPEED_SCU_HPLL_PARAM ,0x00000291U }, + {ASPEED_SCU_MISC_CTRL1 ,0x00000010U }, + {ASPEED_SCU_PCI_CTRL1 ,0x20001A03U }, + {ASPEED_SCU_PCI_CTRL2 ,0x20001A03U }, + {ASPEED_SCU_PCI_CTRL3 ,0x04000030U }, + {ASPEED_SCU_SYS_RST_STATUS ,0x00000001U }, + {ASPEED_SCU_SOC_SCRATCH1 ,0x000000C0U },/* SoC completed DRAM init */ + {ASPEED_SCU_MISC_CTRL2 ,0x00000023U }, + {ASPEED_SCU_HW_STRAP1 ,0x120CE416U },/* Extracted after boot */ + {ASPEED_SCU_RNG_CTRL ,0x0000000EU }, + {ASPEED_SCU_REV_ID ,0x02000303U }, + {ASPEED_SCU_PINMUX_CTRL2 ,0x0000F000U }, + {ASPEED_SCU_PINMUX_CTRL3 ,0x01000000U }, + {ASPEED_SCU_PINMUX_CTRL4 ,0x000000FFU }, + {ASPEED_SCU_PINMUX_CTRL5 ,0x0000A000U }, + {ASPEED_SCU_WDT_RST_CTRL ,0x003FFFF3U }, + {ASPEED_SCU_PINMUX_CTRL8 ,0xFFFF0000U }, + {ASPEED_SCU_PINMUX_CTRL9 ,0x000FFFFFU }, + {ASPEED_SCU_FREE_CNTR4 ,0x000000FFU }, + {ASPEED_SCU_FREE_CNTR4_EXT ,0x000000FFU }, + {ASPEED_SCU_CPU2_BASE_SEG1 ,0x80000000U }, + {ASPEED_SCU_CPU2_BASE_SEG4 ,0x1E600000U }, + {ASPEED_SCU_CPU2_BASE_SEG5 ,0xC0000000U }, + {ASPEED_SCU_UART_HPLL_CLK ,0x00001903U }, + {ASPEED_SCU_PCIE_CTRL ,0x0000007BU }, + {ASPEED_SCU_BMC_DEV_ID ,0x00002402U } +}; +/* * IO handlers: simply catch any reads/writes to IO addresses that aren't * handled by a device mapping.
@@ -57,6 +93,7 @@ static const MemoryRegionOps ast2400_io_ops = {static void ast2400_init (Object *obj) { +int i;AST2400State *s =AST2400 (obj); s->cpu =cpu_arm_init ("arm926" );
@@ -72,6 +109,18 @@ static void ast2400_init(Object *obj)object_initialize (&s->i2c,sizeof (s->i2c),TYPE_ASPEED_I2C );object_property_add_child (obj,"i2c" ,OBJECT (&s->i2c),NULL );qdev_set_parent_bus (DEVICE (&s->i2c),sysbus_get_default ()); + +object_initialize (&s->scu,sizeof (s->scu),TYPE_ASPEED_SCU ); +object_property_add_child (obj,"scu" ,OBJECT (&s->scu),NULL ); +qdev_set_parent_bus (DEVICE (&s->scu),sysbus_get_default ()); + +qdev_prop_set_uint32 (DEVICE (&s->scu),"len-reset" ,ASPEED_SCU_NR_REGS ); +for (i =0 ; i <ARRAY_SIZE (scu_reset); i++) { +int reg =ASPEED_SCU_TO_REG (scu_reset[i].offset); +char *propname =g_strdup_printf ("reset[%d]" , reg); +qdev_prop_set_uint32 (DEVICE (&s->scu), propname, scu_reset[i].val); +g_free (propname); + } }static void ast2400_realize (DeviceState *dev,Error **errp)
@@ -110,6 +159,14 @@ static void ast2400_realize(DeviceState *dev, Error **errp)sysbus_connect_irq (SYS_BUS_DEVICE (&s->timerctrl), i, irq); } +/* SCU */ +object_property_set_bool (OBJECT (&s->scu), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } +sysbus_mmio_map (SYS_BUS_DEVICE (&s->scu),0 ,AST2400_SCU_BASE ); +/* UART - attach an 8250 to the IO space as our UART5 */ if (serial_hds[0 ]) {qemu_irq uart5 =qdev_get_gpio_in (DEVICE (&s->vic), uart_irqs[4 ]);
include/hw/arm/ast2400.h +2 -0
@@ -14,6 +14,7 @@#include "hw/arm/arm.h" #include "hw/intc/aspeed_vic.h" +#include "hw/misc/aspeed_scu.h" #include "hw/timer/aspeed_timer.h" #include "hw/i2c/aspeed_i2c.h"
@@ -27,6 +28,7 @@ typedef struct AST2400State {AspeedVICState vic;AspeedTimerCtrlState timerctrl;AspeedI2CState i2c; +AspeedSCUState scu; } AST2400State;#define TYPE_AST2400 "ast2400"
Signature · 1 line
2.7.4