Skip to contentSkip to conversation

Add ASPEED SCU device

PATCH Applied Andrew Jeffery 3 participants 9 messages Jun 24, 2016 – Jun 27, 2016 Arm/Aspeed machine support

lore
Share & tools
lore
#0 lore raw

v3 cover Add ASPEED SCU device

Hi all,

These are three patches implementing minimal functionality for the ASPEED System Control Unit device and integrating it into the AST2400 SoC model/palmetto-bmc machine. 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.

Since v2:

* Fix mixing of offsets and register indexes
* Sanity check device property values
* SoC actually initialises the silicon revision

Since v1:

* Select reset values based on silicon revision
* Expose hardware strapping values via properties

Andrew Jeffery (3):
hw/misc: Add a model for the ASPEED System Control Unit
ast2400: Integrate the SCU model and set silicon revision
palmetto-bmc: Configure the SCU's hardware strapping register

 hw/arm/ast2400.c             |  21 ++++
 hw/arm/palmetto-bmc.c        |   2 +
 hw/misc/Makefile.objs        |   1 +
 hw/misc/aspeed_scu.c         | 284 +++++++++++++++++++++++++++++++++++++++++++
 hw/misc/trace-events         |   3 +
 include/hw/arm/ast2400.h     |   2 +
 include/hw/misc/aspeed_scu.h |  34 ++++++
 7 files changed, 347 insertions(+)
 create mode 100644 hw/misc/aspeed_scu.c
 create mode 100644 include/hw/misc/aspeed_scu.h
Signature · 1 line
2.7.4
#1 lore raw

PATCH v3 1/3 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 ASPEED SoCs. 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 (eg AST2400 vs AST2500). A qdev property is exposed so that the integrating SoC model can configure the silicon revision, which in-turn selects the appropriate reset values. Further qdev properties are exposed so the board model can configure the board-dependent hardware strapping.

Almost all provided AST2400 reset values are specified by the datasheet. The notable exception is SOC_SCRATCH1, where we mark the DRAM as successfully initialised to avoid unnecessary dark corners in the SoC's u-boot support.

---
Since v2:

* Fix mixing of offsets and register indexes
* Sanity check device property values
* Move trace event definition to hw/misc/trace-events

Since v1:

* Move reset values into SCU implementation (also make register defines private)
* Expose silicon-rev property which is used to select appropriate reset values
* Expose hw-strap1/hw-strap2 properties for board-specific SoC configuration

 hw/misc/Makefile.objs        |   1 +
 hw/misc/aspeed_scu.c         | 284 +++++++++++++++++++++++++++++++++++++++++++
 hw/misc/trace-events         |   3 +
 include/hw/misc/aspeed_scu.h |  34 ++++++
 4 files changed, 322 insertions(+)
 create mode 100644 hw/misc/aspeed_scu.c
 create mode 100644 include/hw/misc/aspeed_scu.h
hw/misc/Makefile.objs +1 -0
index ffb49c11aca6..54020aa06c00 100644
@@ -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 +284 -0

284 lines not on this page · raw message

hw/misc/trace-events +3 -0
index 16b6701cbf9a..ea52a14d787f 100644
@@ -50,3 +50,6 @@ milkymist_pfpu_memory_read(uint32_t addr, uint32_t value) "addr %08x value %08x"
 milkymist_pfpu_memory_write(uint32_t addr, uint32_t value) "addr %08x value %08x"
 milkymist_pfpu_vectout(uint32_t a, uint32_t b, uint32_t dma_ptr) "a %08x b %08x dma_ptr %08x"
 milkymist_pfpu_pulse_irq(void) "Pulse IRQ"
+
+# hw/misc/aspeed_scu.c
+aspeed_scu_write(uint64_t offset, unsigned size, uint32_t data) "To 0x%" PRIx64 " of size %u: 0x%" PRIx32
include/hw/misc/aspeed_scu.h new file +34 -0
new file mode 100644
index 000000000000..6b8e46f85fad
@@ -0,0 +1,34 @@
+/*
+ * ASPEED System Control Unit
+ *
+ * Andrew Jeffery <[email protected]>
+ *
+ * Copyright 2016 IBM Corp.
+ *
+ * This code is licensed under the GPL version 2 or later.  See
+ * the COPYING file in the top-level directory.
+ */
+#ifndef ASPEED_SCU_H
+#define ASPEED_SCU_H
+
+#include "hw/sysbus.h"
+
+#define TYPE_ASPEED_SCU "aspeed.scu"
+#define ASPEED_SCU(obj) OBJECT_CHECK(AspeedSCUState, (obj), TYPE_ASPEED_SCU)
+
+#define ASPEED_SCU_NR_REGS (0x1A8 >> 2)
+
+typedef struct AspeedSCUState {
+    /*< private >*/
+    SysBusDevice parent_obj;
+
+    /*< public >*/
+    MemoryRegion iomem;
+
+    uint32_t regs[ASPEED_SCU_NR_REGS];
+    uint32_t silicon_rev;
+    uint32_t hw_strap1;
+    uint32_t hw_strap2;
+} AspeedSCUState;
+
+#endif /* ASPEED_SCU_H */
Signature · 1 line
2.7.4
Reviewed-by on v3 1/3
#2 lore raw

Re: [Qemu-arm] [PATCH v3 1/3] hw/misc: Add a model for the ASPEED System Control Unit

Quoted 57 lines · Andrew Jeffery

The SCU is a collection of chip-level control registers that manage the various functions supported by ASPEED SoCs. 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 (eg AST2400 vs AST2500). A qdev property is exposed so that the integrating SoC model can configure the silicon revision, which in-turn selects the appropriate reset values. Further qdev properties are exposed so the board model can configure the board-dependent hardware strapping.

Almost all provided AST2400 reset values are specified by the datasheet. The notable exception is SOC_SCRATCH1, where we mark the DRAM as successfully initialised to avoid unnecessary dark corners in the SoC's u-boot support.

---
Since v2:

* Fix mixing of offsets and register indexes
* Sanity check device property values
* Move trace event definition to hw/misc/trace-events

Since v1:

* Move reset values into SCU implementation (also make register defines private)
* Expose silicon-rev property which is used to select appropriate reset values
* Expose hw-strap1/hw-strap2 properties for board-specific SoC configuration

 hw/misc/Makefile.objs        |   1 +
 hw/misc/aspeed_scu.c         | 284 +++++++++++++++++++++++++++++++++++++++++++
 hw/misc/trace-events         |   3 +
 include/hw/misc/aspeed_scu.h |  34 ++++++
 4 files changed, 322 insertions(+)
 create mode 100644 hw/misc/aspeed_scu.c
 create mode 100644 include/hw/misc/aspeed_scu.h
hw/misc/Makefile.objs +1 -0
index ffb49c11aca6..54020aa06c00 100644
@@ -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 +3 -0
new file mode 100644
index 000000000000..ff231dbb3c17
@@ -0,0 +1,284 @@
+/*
+ * ASPEED System Control Unit
+ *

hw/misc/aspeed_scu.c line 13

Quoted 10 lines
hw/misc/aspeed_scu.c new file +10 -0
+ * Andrew Jeffery <[email protected]>
+ *
+ * Copyright 2016 IBM Corp.
+ *
+ * This code is licensed under the GPL version 2 or later.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include <inttypes.h>

osdep.h provides this, you don't need to include it yourself.

Otherwise

so if this is the only problem with the series I'll fix it up when I put it in target-arm.next.

thanks
-- PMM

#3 lore raw

Re: [Qemu-arm] [PATCH v3 1/3] hw/misc: Add a model for the ASPEED System Control Unit

Quoted 71 lines · Peter Maydell
Quoted 58 lines · Andrew Jeffery

The SCU is a collection of chip-level control registers that manage the various functions supported by ASPEED SoCs. 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 (eg AST2400 vs AST2500). A qdev property is exposed so that the integrating SoC model can configure the silicon revision, which in-turn selects the appropriate reset values. Further qdev properties are exposed so the board model can configure the board-dependent hardware strapping.

Almost all provided AST2400 reset values are specified by the datasheet. The notable exception is SOC_SCRATCH1, where we mark the DRAM as successfully initialised to avoid unnecessary dark corners in the SoC's u-boot support.

---
Since v2:

* Fix mixing of offsets and register indexes
* Sanity check device property values
* Move trace event definition to hw/misc/trace-events

Since v1:

* Move reset values into SCU implementation (also make register defines private)
* Expose silicon-rev property which is used to select appropriate reset values
* Expose hw-strap1/hw-strap2 properties for board-specific SoC configuration

 hw/misc/Makefile.objs        |   1 +
 hw/misc/aspeed_scu.c         | 284 +++++++++++++++++++++++++++++++++++++++++++ hw/misc/trace-events         |   3 +
 include/hw/misc/aspeed_scu.h |  34 ++++++

 4 files changed, 322 insertions(+)

 create mode 100644 hw/misc/aspeed_scu.c
 create mode 100644 include/hw/misc/aspeed_scu.h

hw/misc/Makefile.objs +0 -0
index ffb49c11aca6..54020aa06c00 100644
@@ -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

hw/misc/Makefile.objs +1 -0
+obj-$(CONFIG_ASPEED_SOC) += aspeed_scu.o
hw/misc/aspeed_scu.c new file +3 -0
new file mode 100644
index 000000000000..ff231dbb3c17
@@ -0,0 +1,284 @@
+/*
+ * ASPEED System Control Unit
+ *

hw/misc/aspeed_scu.c line 13

Quoted 10 lines
hw/misc/aspeed_scu.c new file +10 -0
+ * Andrew Jeffery <[email protected]>
+ *
+ * Copyright 2016 IBM Corp.
+ *
+ * This code is licensed under the GPL version 2 or later.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include 

osdep.h provides this, you don't need to include it yourself.

Quoted 6 lines

Otherwise

so if this is the only problem with the series I'll fix it up when I put it in target-arm.next.

As far as I'm aware that's the only issue aside from the discussion on patch 3/3.

Cheers,

Andrew

#4 lore raw

PATCH v3 2/3 ast2400: Integrate the SCU model and set silicon revision

In reply to Andrew Jeffery

By specifying the silicon revision we select the appropriate reset values for the SoC.

Additionally, expose hardware strapping properties aliasing those provided by the SCU for board-specific configuration.

---
Since v2:

* Configure SoC silicon revision in the SCU via silicon-rev property

Since v1:

* Remove reset value configuration
* Alias the SCU's hardware strapping properties to expose them to boards

 hw/arm/ast2400.c         | 21 +++++++++++++++++++++
 include/hw/arm/ast2400.h |  2 ++
 2 files changed, 23 insertions(+)
hw/arm/ast2400.c +21 -0
index 4a9de0e10cbc..b14a82fcdef1 100644
@@ -24,9 +24,12 @@
 #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         0x1E78A000
 
+#define AST2400_A0_SILICON_REV   0x02000303
+
 static const int uart_irqs[] = { 9, 32, 33, 34, 10 };
 static const int timer_irqs[] = { 16, 17, 18, 35, 36, 37, 38, 39, };
 
@@ -72,6 +75,16 @@ 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), "silicon-rev",
+                         AST2400_A0_SILICON_REV);
+    object_property_add_alias(obj, "hw-strap1", OBJECT(&s->scu),
+                              "hw-strap1", &error_abort);
+    object_property_add_alias(obj, "hw-strap2", OBJECT(&s->scu),
+                              "hw-strap2", &error_abort);
 }
 
 static void ast2400_realize(DeviceState *dev, Error **errp)
@@ -110,6 +123,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
index c05ed5376736..f1a64fd3893d 100644
@@ -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
#5 lore raw

PATCH v3 3/3 palmetto-bmc: Configure the SCU's hardware strapping register

In reply to Andrew Jeffery

The magic constant configures the following options:

* 28:27: Configure DRAM size as 256MB
* 26:24: DDR3 SDRAM with CL = 6, CWL = 5
* 23: Configure 24/48MHz CLKIN
* 22: Disable GPIOE pass-through mode
* 21: Disable GPIOD pass-through mode
* 20: Enable LPC decode of SuperIO 0x2E/0x4E addresses
* 19: Disable ACPI
* 18: Configure 48MHz CLKIN
* 17: Disable BMC 2nd boot watchdog timer
* 16: Decode SuperIO address 0x2E
* 15: VGA Class Code
* 14: Enable LPC dedicated reset pin
* 13:12: Enable SPI Master and SPI Slave to AHB Bridge
* 11:10: Select CPU:AHB ratio = 2:1
* 9:8: Select 384MHz H-PLL
* 7: Configure MAC#2 for RMII/NCSI
* 6: Configure MAC#1 for RMII/NCSI
* 5: No VGA BIOS ROM
* 4: Boot using 32bit SPI address mode
* 3:2: Select 16MB VGA memory
* 1:0: Boot from SPI flash memory

---
 hw/arm/palmetto-bmc.c | 2 ++
 1 file changed, 2 insertions(+)
hw/arm/palmetto-bmc.c +2 -0
index a51d960510ee..b8eed21348d8 100644
@@ -44,6 +44,8 @@ static void palmetto_bmc_init(MachineState *machine)
                                 &bmc->ram);
     object_property_add_const_link(OBJECT(&bmc->soc), "ram", OBJECT(&bmc->ram),
                                    &error_abort);
+    object_property_set_int(OBJECT(&bmc->soc), 0x120CE416, "hw-strap1",
+                            &error_abort);
     object_property_set_bool(OBJECT(&bmc->soc), true, "realized",
                              &error_abort);
 
Signature · 1 line
2.7.4
Tested-by on v3 3/3
#6 lore raw

Re: [Qemu-arm] [PATCH v3 3/3] palmetto-bmc: Configure the SCU's hardware strapping register

Quoted 15 lines · Andrew Jeffery

The magic constant configures the following options:

* 28:27: Configure DRAM size as 256MB
* 26:24: DDR3 SDRAM with CL = 6, CWL = 5
* 23: Configure 24/48MHz CLKIN
* 22: Disable GPIOE pass-through mode
* 21: Disable GPIOD pass-through mode
* 20: Enable LPC decode of SuperIO 0x2E/0x4E addresses
* 19: Disable ACPI
* 18: Configure 48MHz CLKIN
* 17: Disable BMC 2nd boot watchdog timer
* 16: Decode SuperIO address 0x2E
* 15: VGA Class Code
* 14: Enable LPC dedicated reset pin
* 13:12: Enable SPI Master and SPI Slave to AHB Bridge

Quoted 8 lines

* 11:10: Select CPU:AHB ratio = 2:1
* 9:8: Select 384MHz H-PLL
* 7: Configure MAC#2 for RMII/NCSI
* 6: Configure MAC#1 for RMII/NCSI
* 5: No VGA BIOS ROM
* 4: Boot using 32bit SPI address mode
* 3:2: Select 16MB VGA memory
* 1:0: Boot from SPI flash memory

As the previous patchset was not setting the silicon version, we did not see that should be skipping the SPI Flash checks in U-Boot. So, with this little change :

- object_property_set_int(OBJECT(&bmc->soc), 0x120CE416, "hw-strap1",
+ object_property_set_int(OBJECT(&bmc->soc), 0x120CE414, "hw-strap1",

We reach a point where U-Boot is ready to load a kernel :

	U-Boot 2013.07 (Jun 07 2016 - 01:33:14)

	I2C:   ready
	DRAM:  256 MiB
	WARNING: Caches not enabled
	Flash: SPI Flash ID: 19ba20 
	32 MiB
	In:    serial
	Out:   serial
	Err:   serial
	H/W:   AST2400 series chip Rev. 00 
	Watchdog: 300s
	Net:   aspeednic#0
	Warning: aspeednic#0 (eth0) using random MAC address - aa:36:26:50:30:9c

	Hit any key to stop autoboot:  0 
	boot#    

I will see if it is worth adding what is required in the SMC controller to support this. Else, we have the quick solution above.

Thanks,

C.

Quoted 21 lines
---
 hw/arm/palmetto-bmc.c | 2 ++
 1 file changed, 2 insertions(+)
hw/arm/palmetto-bmc.c +2 -0
index a51d960510ee..b8eed21348d8 100644
@@ -44,6 +44,8 @@ static void palmetto_bmc_init(MachineState *machine)
                                 &bmc->ram);
     object_property_add_const_link(OBJECT(&bmc->soc), "ram", OBJECT(&bmc->ram),
                                    &error_abort);
+    object_property_set_int(OBJECT(&bmc->soc), 0x120CE416, "hw-strap1",
+                            &error_abort);
     object_property_set_bool(OBJECT(&bmc->soc), true, "realized",
                              &error_abort);
 
#7 lore raw
In reply to Andrew Jeffery
Quoted 16 lines · Andrew Jeffery

Hi all,

These are three patches implementing minimal functionality for the ASPEED System Control Unit device and integrating it into the AST2400 SoC model/palmetto-bmc machine. 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.

Since v2:

* Fix mixing of offsets and register indexes
* Sanity check device property values
* SoC actually initialises the silicon revision

Since v1:

Quoted 7 lines

* Select reset values based on silicon revision
* Expose hardware strapping values via properties

Andrew Jeffery (3):
hw/misc: Add a model for the ASPEED System Control Unit
ast2400: Integrate the SCU model and set silicon revision
palmetto-bmc: Configure the SCU's hardware strapping register

Applied to target-arm.next, thanks.

-- PMM

#8 lore raw
Quoted 21 lines · Peter Maydell
Quoted 20 lines · Andrew Jeffery

Hi all,

These are three patches implementing minimal functionality for the ASPEED System Control Unit device and integrating it into the AST2400 SoC model/palmetto-bmc machine. 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.

Since v2:

* Fix mixing of offsets and register indexes
* Sanity check device property values
* SoC actually initialises the silicon revision

Since v1:

* Select reset values based on silicon revision
* Expose hardware strapping values via properties

Quoted 7 lines
Quoted 4 lines

Andrew Jeffery (3):
  hw/misc: Add a model for the ASPEED System Control Unit
  ast2400: Integrate the SCU model and set silicon revision
  palmetto-bmc: Configure the SCU's hardware strapping register

Applied to target-arm.next, thanks.

Thanks; I intend to send a follow-up patch addressing the discussion on patch 3/3. I'm away for a week so it will miss soft-freeze, but given the nature of the patch that might not be the end of the world?

Cheers,

Andrew