Skip to contentSkip to conversation

Add SP810 to Versatile Express boards

PATCH In review Fabian Aggeler 4 participants 7 messages Aug 17, 2014 – Aug 22, 2014 Arm/versatile express platform

lore
Share & tools
lore
#0 lore raw

v3 cover Add SP810 to Versatile Express boards

Hi,

The Versatile Express emulation in QEMU currently does not have a model of the SP810 used in real hardware. The registers provided by this System Controller can be used to set the frequency of the SP804 timers. On newer releases of the board the SP804 is set to 32kHz by default and has to be increased by writing to the SCCTRL. See:
http://lists.infradead.org/pipermail/linux-arm-kernel/2011-January/038696.html

Since QEMU sets the SP804 timers to 1MHz by default this should be reflected in the SCCTRL register. These two patches add a model of the SP804 to the vexpress-boards and sets the SCCTRL register so that software that queries this register behaves as expected.

Feedback is greatly appreciated!

Best,
Fabian

v2 -> v3:
* removed duplicate comment
* split SCCTRL property into 4 individual properties
* moved initialisation back to vexpress.c

v2: https://lists.nongnu.org/archive/html/qemu-devel/2014-08/msg00629.html

v1 -> v2:
* TIMERENXSEL prefixed with register name
* removed casts
* created header file

v1: https://lists.nongnu.org/archive/html/qemu-devel/2014-07/msg02572.html

Fabian Aggeler (2):
hw/misc/arm_sp810: Create SP810 device
hw/arm/vexpress: add SP810 to the vexpress

 default-configs/arm-softmmu.mak |   1 +
 hw/arm/vexpress.c               |  13 ++++-
 hw/misc/Makefile.objs           |   1 +
 hw/misc/arm_sp810.c             | 109 ++++++++++++++++++++++++++++++++++++++++
 include/hw/misc/arm_sp810.h     |  80 +++++++++++++++++++++++++++++
 5 files changed, 202 insertions(+), 2 deletions(-)
 create mode 100644 hw/misc/arm_sp810.c
 create mode 100644 include/hw/misc/arm_sp810.h
Signature · 1 line
1.8.3.2
#1 lore raw

PATCH v3 1/2 hw/misc/arm_sp810: Create SP810 device

This adds a device model for the PrimeXsys System Controller (SP810) which is present in the Versatile Express motherboards. It is so far read-only but allows to read the SCCTRL register.

---
 default-configs/arm-softmmu.mak |   1 +
 hw/misc/Makefile.objs           |   1 +
 hw/misc/arm_sp810.c             | 109 ++++++++++++++++++++++++++++++++++++++++
 include/hw/misc/arm_sp810.h     |  80 +++++++++++++++++++++++++++++
 4 files changed, 191 insertions(+)
 create mode 100644 hw/misc/arm_sp810.c
 create mode 100644 include/hw/misc/arm_sp810.h
default-configs/arm-softmmu.mak +1 -0
index f3513fa..67ba99a 100644
@@ -55,6 +55,7 @@ CONFIG_PL181=y
 CONFIG_PL190=y
 CONFIG_PL310=y
 CONFIG_PL330=y
+CONFIG_SP810=y
 CONFIG_CADENCE=y
 CONFIG_XGMAC=y
 CONFIG_EXYNOS4=y
hw/misc/Makefile.objs +1 -0
index 979e532..49d023b 100644
@@ -13,6 +13,7 @@ common-obj-$(CONFIG_PL310) += arm_l2x0.o
 common-obj-$(CONFIG_INTEGRATOR_DEBUG) += arm_integrator_debug.o
 common-obj-$(CONFIG_A9SCU) += a9scu.o
 common-obj-$(CONFIG_ARM11SCU) += arm11scu.o
+common-obj-$(CONFIG_SP810) += arm_sp810.o
 
 # PKUnity SoC devices
 common-obj-$(CONFIG_PUV3) += puv3_pm.o
hw/misc/arm_sp810.c new file +109 -0

109 lines not on this page · raw message

include/hw/misc/arm_sp810.h new file +80 -0

80 lines not on this page · raw message

Signature · 1 line
1.8.3.2
#2 lore raw

Re: [Qemu-devel] [PATCH v3 1/2] hw/misc/arm_sp810: Create SP810 device

Quoted 31 lines · Fabian Aggeler

This adds a device model for the PrimeXsys System Controller (SP810) which is present in the Versatile Express motherboards. It is so far read-only but allows to read the SCCTRL register.

---
 default-configs/arm-softmmu.mak |   1 +
 hw/misc/Makefile.objs           |   1 +
 hw/misc/arm_sp810.c             | 109 ++++++++++++++++++++++++++++++++++++++++
 include/hw/misc/arm_sp810.h     |  80 +++++++++++++++++++++++++++++
 4 files changed, 191 insertions(+)
 create mode 100644 hw/misc/arm_sp810.c
 create mode 100644 include/hw/misc/arm_sp810.h
default-configs/arm-softmmu.mak +1 -0
index f3513fa..67ba99a 100644
@@ -55,6 +55,7 @@ CONFIG_PL181=y
 CONFIG_PL190=y
 CONFIG_PL310=y
 CONFIG_PL330=y
+CONFIG_SP810=y
 CONFIG_CADENCE=y
 CONFIG_XGMAC=y
 CONFIG_EXYNOS4=y
hw/misc/Makefile.objs +0 -0
index 979e532..49d023b 100644

hw/misc/Makefile.objs common-obj-$(CONFIG_PL310) += arm_l2x0.o · line 16

Quoted 4 lines
hw/misc/Makefile.objs +1 -0
@@ -13,6 +13,7 @@ common-obj-$(CONFIG_PL310) += arm_l2x0.o
 common-obj-$(CONFIG_INTEGRATOR_DEBUG) += arm_integrator_debug.o
 common-obj-$(CONFIG_A9SCU) += a9scu.o
 common-obj-$(CONFIG_ARM11SCU) += arm11scu.o
+common-obj-$(CONFIG_SP810) += arm_sp810.o

We mostly don't use the 'arm' prefix (compare pl330, pl011, and other examples for other architectures), so you can remove it from filenames and variable names here.

Quoted 19 lines
hw/misc/Makefile.objs +0 -0
 # PKUnity SoC devices
 common-obj-$(CONFIG_PUV3) += puv3_pm.o
hw/misc/arm_sp810.c new file +10 -0
new file mode 100644
index 0000000..7aff9bd
@@ -0,0 +1,109 @@
+/*
+ * ARM PrimeXsys System Controller (SP810)
+ *
+ * Copyright (C) 2014 Fabian Aggeler <[email protected]>
+ *
+ * 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.
+ *

hw/misc/arm_sp810.c line 20

Quoted 10 lines
hw/misc/arm_sp810.c new file +10 -0
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include "hw/misc/arm_sp810.h"
+
+static const VMStateDescription vmstate_arm_sysctl = {

^^^ should be vmstate_sp810.

hw/misc/arm_sp810.c line 28

Quoted 8 lines
hw/misc/arm_sp810.c new file +8 -0
+    .name = "arm_sp810",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT8(timeren0_sel, arm_sp810_state),
+        VMSTATE_UINT8(timeren1_sel, arm_sp810_state),
+        VMSTATE_UINT8(timeren2_sel, arm_sp810_state),
+        VMSTATE_UINT8(timeren3_sel, arm_sp810_state),

These are read only properties, so you don't need to save them.

Quoted 46 lines
hw/misc/arm_sp810.c new file +46 -0
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static uint64_t arm_sp810_read(void *opaque, hwaddr offset, unsigned size)
+{
+    arm_sp810_state *s = opaque;
+
+    switch (offset) {
+    case SCCTRL:
+        return (s->timeren3_sel << 21) | (s->timeren2_sel << 19)
+                | (s->timeren1_sel << 17) | (s->timeren0_sel << 15);
+    default:
+        qemu_log_mask(LOG_UNIMP,
+                "arm_sp810_read: Register not yet implemented: %s\n",
+                HWADDR_PRIx);
+        return 0;
+    }
+}
+
+static void arm_sp810_write(void *opaque, hwaddr offset,
+                            uint64_t val, unsigned size)
+{
+    switch (offset) {
+    default:
+        qemu_log_mask(LOG_UNIMP,
+                "arm_sp810_write: Register not yet implemented: %s\n",
+                HWADDR_PRIx);
+        return;
+    }
+}
+
+static const MemoryRegionOps arm_sp810_ops = {
+    .read = arm_sp810_read,
+    .write = arm_sp810_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+};
+
+static void arm_sp810_init(Object *obj)
+{
+    arm_sp810_state *s = ARM_SP810(obj);
+
+    memory_region_init_io(&s->iomem, obj, &arm_sp810_ops, s, "arm-sp810",
+                          0x1000);
+    sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
+}

hw/misc/arm_sp810.c line 84

Quoted 10 lines
hw/misc/arm_sp810.c new file +10 -0
+
+static Property arm_sp810_properties[] = {
+    DEFINE_PROP_UINT8("timeren0-sel", arm_sp810_state, timeren0_sel,
+                                                       SCCTRL_TIMER_REFCLK),
+    DEFINE_PROP_UINT8("timeren1-sel", arm_sp810_state, timeren1_sel,
+                                                       SCCTRL_TIMER_REFCLK),
+    DEFINE_PROP_UINT8("timeren2-sel", arm_sp810_state, timeren2_sel,
+                                                       SCCTRL_TIMER_REFCLK),
+    DEFINE_PROP_UINT8("timeren3-sel", arm_sp810_state, timeren3_sel,
+                                                       SCCTRL_TIMER_REFCLK),

Which input signals in the hardware do these properties correspond to? I can't figure out what the mapping is. As far as I can tell from the documentation the bits in SCCTRL are just always reset to 0 and are not controlled by external signals (which is what qdev properties should typically correspond to).

thanks
-- PMM

#3 lore raw

Re: [Qemu-devel] [PATCH v3 1/2] hw/misc/arm_sp810: Create SP810 device

Quoted 32 lines · Peter Maydell
Quoted 31 lines · Fabian Aggeler

This adds a device model for the PrimeXsys System Controller (SP810) which is present in the Versatile Express motherboards. It is so far read-only but allows to read the SCCTRL register.

---

default-configs/arm-softmmu.mak |   1 +
hw/misc/Makefile.objs           |   1 +
hw/misc/arm_sp810.c             | 109 ++++++++++++++++++++++++++++++++++++++++
include/hw/misc/arm_sp810.h     |  80 +++++++++++++++++++++++++++++
4 files changed, 191 insertions(+)

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

default-configs/arm-softmmu.mak +0 -0
index f3513fa..67ba99a 100644
@@ -55,6 +55,7 @@ CONFIG_PL181=y

CONFIG_PL190=y
CONFIG_PL310=y
CONFIG_PL330=y
+CONFIG_SP810=y
CONFIG_CADENCE=y
CONFIG_XGMAC=y
CONFIG_EXYNOS4=y

hw/misc/Makefile.objs +0 -0
index 979e532..49d023b 100644
@@ -13,6 +13,7 @@ common-obj-$(CONFIG_PL310) += arm_l2x0.o
Quoted 8 lines
Quoted 4 lines

common-obj-$(CONFIG_INTEGRATOR_DEBUG) += arm_integrator_debug.o common-obj-$(CONFIG_A9SCU) += a9scu.o common-obj-$(CONFIG_ARM11SCU) += arm11scu.o +common-obj-$(CONFIG_SP810) += arm_sp810.o

We mostly don't use the 'arm' prefix (compare pl330, pl011, and other examples for other architectures), so you can remove it from filenames and variable names here.

Ok, will remove it then.

Quoted 24 lines
Quoted 24 lines

# PKUnity SoC devices
common-obj-$(CONFIG_PUV3) += puv3_pm.o

hw/misc/arm_sp810.c new file +14 -0
new file mode 100644
index 0000000..7aff9bd
@@ -0,0 +1,109 @@
+/*
+ * ARM PrimeXsys System Controller (SP810)
+ *
+ * Copyright (C) 2014 Fabian Aggeler <[email protected]>
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
Quoted 8 lines

hw/misc/arm_sp810.c line 20

Quoted 6 lines
hw/misc/arm_sp810.c new file +6 -0
+ *
+ */
+
+#include "hw/misc/arm_sp810.h"
+
+static const VMStateDescription vmstate_arm_sysctl = {

^^^ should be vmstate_sp810.

Thanks for catching this. I will change it.

Quoted 11 lines

hw/misc/arm_sp810.c line 28

Quoted 9 lines
hw/misc/arm_sp810.c new file +8 -0
+    .name = "arm_sp810",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT8(timeren0_sel, arm_sp810_state),
+        VMSTATE_UINT8(timeren1_sel, arm_sp810_state),
+        VMSTATE_UINT8(timeren2_sel, arm_sp810_state),
+        VMSTATE_UINT8(timeren3_sel, arm_sp810_state),

These are read only properties, so you don't need to save them.

Okay.

Quoted 56 lines
Quoted 56 lines
hw/misc/arm_sp810.c new file +55 -0
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static uint64_t arm_sp810_read(void *opaque, hwaddr offset, unsigned size)
+{
+    arm_sp810_state *s = opaque;
+
+    switch (offset) {
+    case SCCTRL:
+        return (s->timeren3_sel << 21) | (s->timeren2_sel << 19)
+                | (s->timeren1_sel << 17) | (s->timeren0_sel << 15);
+    default:
+        qemu_log_mask(LOG_UNIMP,
+                "arm_sp810_read: Register not yet implemented: %s\n",
+                HWADDR_PRIx);
+        return 0;
+    }
+}
+
+static void arm_sp810_write(void *opaque, hwaddr offset,
+                            uint64_t val, unsigned size)
+{
+    switch (offset) {
+    default:
+        qemu_log_mask(LOG_UNIMP,
+                "arm_sp810_write: Register not yet implemented: %s\n",
+                HWADDR_PRIx);
+        return;
+    }
+}
+
+static const MemoryRegionOps arm_sp810_ops = {
+    .read = arm_sp810_read,
+    .write = arm_sp810_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+};
+
+static void arm_sp810_init(Object *obj)
+{
+    arm_sp810_state *s = ARM_SP810(obj);
+
+    memory_region_init_io(&s->iomem, obj, &arm_sp810_ops, s, "arm-sp810",
+                          0x1000);
+    sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
+}
+
+static Property arm_sp810_properties[] = {
+    DEFINE_PROP_UINT8("timeren0-sel", arm_sp810_state, timeren0_sel,
+                                                       SCCTRL_TIMER_REFCLK),
+    DEFINE_PROP_UINT8("timeren1-sel", arm_sp810_state, timeren1_sel,
+                                                       SCCTRL_TIMER_REFCLK),
+    DEFINE_PROP_UINT8("timeren2-sel", arm_sp810_state, timeren2_sel,
+                                                       SCCTRL_TIMER_REFCLK),
+    DEFINE_PROP_UINT8("timeren3-sel", arm_sp810_state, timeren3_sel,
Quoted 8 lines

hw/misc/arm_sp810.c line 84

Quoted 1 line
hw/misc/arm_sp810.c new file +1 -0
+                                                       SCCTRL_TIMER_REFCLK),

Which input signals in the hardware do these properties correspond to? I can't figure out what the mapping is. As far as I can tell from the documentation the bits in SCCTRL are just always reset to 0 and are not controlled by external signals (which is what qdev properties should typically correspond to).

Actually I don’t know how it is done in hardware. My goal was to reflect the default speed of the SP804 timer in QEMU’s vexpress emulation in the SCCTRL. What do you suggest in this case? I could remove the QOM properties and set the reset value of the TimerEnXSel bits in SCCTRL to 1 (TIMCLK) to match the SCCTRL with the speed of the SP804.

Thanks,
Fabian

Quoted 3 lines

thanks
-- PMM

#4 lore raw

Re: [Qemu-devel] [PATCH v3 1/2] hw/misc/arm_sp810: Create SP810 device

Quoted 9 lines · Aggeler Fabian
Quoted 6 lines · Peter Maydell

Which input signals in the hardware do these properties correspond to? I can't figure out what the mapping is. As far as I can tell from the documentation the bits in SCCTRL are just always reset to 0 and are not controlled by external signals (which is what qdev properties should typically correspond to).

Quoted 3 lines

Actually I don’t know how it is done in hardware. My goal was to reflect the default speed of the SP804 timer in QEMU’s vexpress emulation in the SCCTRL. What do you suggest in this case?

Well, fundamentally you have to find out what the hardware does, and do that. We can't model anything else.

Quoted 3 lines

I could remove the QOM properties and set the reset value of the TimerEnXSel bits in SCCTRL to 1 (TIMCLK) to match the SCCTRL with the speed of the SP804.

The h/w docs suggest the reset value is 0.
I have a feeling you may be attempting to make QEMU's hardware model include behaviour which is the result of firmware code setting register values before booting the kernel...

thanks
-- PMM

#5 lore raw

Re: [Qemu-devel] [PATCH v3 1/2] hw/misc/arm_sp810: Create SP810 device

Quoted 10 lines · Peter Maydell
Quoted 9 lines · Aggeler Fabian
Quoted 6 lines · Peter Maydell

Which input signals in the hardware do these properties correspond to? I can't figure out what the mapping is. As far as I can tell from the documentation the bits in SCCTRL are just always reset to 0 and are not controlled by external signals (which is what qdev properties should typically correspond to).

Quoted 7 lines
Quoted 3 lines

Actually I don’t know how it is done in hardware. My goal was to reflect the default speed of the SP804 timer in QEMU’s vexpress emulation in the SCCTRL. What do you suggest in this case?

Well, fundamentally you have to find out what the hardware does, and do that. We can't model anything else.

With no actual clock muxing support it makes sense to me to pin the register value to a hardwired setting. This as least allows a guest to self-identify the one and only supported clocking setup without the need for dummy firmware.

To do what the hardware does and have this value at it's docced reset you would really want to add the clock frequency selection support which means propagating the numbers through to timers etc making this series much more complicated.

Regards,
Peter

Quoted 13 lines
Quoted 3 lines

I could remove the QOM properties and set the reset value of the TimerEnXSel bits in SCCTRL to 1 (TIMCLK) to match the SCCTRL with the speed of the SP804.

The h/w docs suggest the reset value is 0.
I have a feeling you may be attempting to make QEMU's hardware model include behaviour which is the result of firmware code setting register values before booting the kernel...

thanks
-- PMM

#6 lore raw

PATCH v3 2/2 hw/arm/vexpress: add SP810 to the vexpress

In reply to Fabian Aggeler

The SP810, which is present in the Versatile Express motherboards, allows to set the timing reference to either REFCLK or TIMCLK. QEMU currently sets the SP804 timer to 1MHz by default. To reflect this, we set the TimerEn0Sel, TimerEn1Sel, TimerEn2Sel, and TimerEn3Sel of the system control register (SCCTRL) to TIMCLK (1).

---
 hw/arm/vexpress.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
hw/arm/vexpress.c +11 -2
index a88732c..086f68a 100644
@@ -34,6 +34,7 @@
 #include "hw/block/flash.h"
 #include "sysemu/device_tree.h"
 #include "qemu/error-report.h"
+#include "hw/misc/arm_sp810.h"
 #include <libfdt.h>
 
 #define VEXPRESS_BOARD_ID 0x8e0
@@ -512,7 +513,7 @@ static pflash_t *ve_pflash_cfi01_register(hwaddr base, const char *name,
 static void vexpress_common_init(VEDBoardInfo *daughterboard,
                                  MachineState *machine)
 {
-    DeviceState *dev, *sysctl, *pl041;
+    DeviceState *dev, *sysctl, *pl041, *sp810;
     qemu_irq pic[64];
     uint32_t sys_id;
     DriveInfo *dinfo;
@@ -575,7 +576,15 @@ static void vexpress_common_init(VEDBoardInfo *daughterboard,
     qdev_init_nofail(sysctl);
     sysbus_mmio_map(SYS_BUS_DEVICE(sysctl), 0, map[VE_SYSREGS]);
 
-    /* VE_SP810: not modelled */
+    /* VE_SP810 (SP804 running at 1MHz (TIMCLK) by default) */
+    sp810 = qdev_create(NULL, TYPE_ARM_SP810);
+    qdev_prop_set_uint8(sp810, "timeren0-sel", SCCTRL_TIMER_TIMCLK);
+    qdev_prop_set_uint8(sp810, "timeren1-sel", SCCTRL_TIMER_TIMCLK);
+    qdev_prop_set_uint8(sp810, "timeren2-sel", SCCTRL_TIMER_TIMCLK);
+    qdev_prop_set_uint8(sp810, "timeren3-sel", SCCTRL_TIMER_TIMCLK);
+    qdev_init_nofail(sp810);
+    sysbus_mmio_map(SYS_BUS_DEVICE(sp810), 0, map[VE_SP810]);
+
     /* VE_SERIALPCI: not modelled */
 
     pl041 = qdev_create(NULL, "pl041");
Signature · 1 line
1.8.3.2