Skip to contentSkip to conversation

Add ASPEED AST2400 machine model

PATCH Superseded Andrew Jeffery 2 participants 9 messages Mar 5, 2016 – Mar 12, 2016 Arm/Aspeed machine support

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover Add ASPEED AST2400 machine model

This patch series models enough of the ASPEED AST2400 ARM9 SoC[0] to boot an aspeed_defconfig Linux kernel[1]. Specifically, the series implements the timer and VIC devices and integrates them into a new ast2400 machine through a AST2400SOC model. The device model patches only partially implement the hardware features of the timer and VIC, again mostly just enough to boot Linux.

Unfortunately the datasheet describing the devices is not generally available, but I'll try to add comments to any unclear areas.

The addition of the AST2400 to QEMU is motivated by use of the SoC as a BMC in OpenPOWER[2][3] machines and the ongoing development of OpenBMC[4]. The presence of a machine model for the AST2400 will help with development and testing of the OpenBMC stack.

Cheers,

Andrew

[0] http://www.aspeedtech.com/products.php?fPath=20&rId=376
[1] git fetch [email protected]:openbmc/linux.git dev-4.3
[2] http://openpowerfoundation.org/
[3] https://github.com/open-power/
[4] https://github.com/openbmc/openbmc

Changes since v2:

This re-roll is a reasonable rework of the patches in the series, which may make it difficult to compare v1 to v2.

Addressed reviews/comments from:
* Peter Maydell
* Alexey Kardashevskiy
* Joel Stanley

Changes since v1:

Addressed reviews/comments from:
* Cédric Le Goater

Andrew Jeffery (3):
hw/timer: Add ASPEED timer device model
hw/intc: Add (new) ASPEED VIC device model
hw/arm: Add ASPEED AST2400 machine model

 default-configs/arm-softmmu.mak |   1 +
 hw/arm/Makefile.objs            |   1 +
 hw/arm/ast2400.c                | 208 ++++++++++++++++++
 hw/intc/Makefile.objs           |   1 +
 hw/intc/aspeed_vic.c            | 335 +++++++++++++++++++++++++++++
 hw/timer/Makefile.objs          |   1 +
 hw/timer/aspeed_timer.c         | 452 ++++++++++++++++++++++++++++++++++++++++
 include/hw/intc/aspeed_vic.h    |  48 +++++
 include/hw/timer/aspeed_timer.h |  59 ++++++
 trace-events                    |  16 ++
 10 files changed, 1122 insertions(+)
 create mode 100644 hw/arm/ast2400.c
 create mode 100644 hw/intc/aspeed_vic.c
 create mode 100644 hw/timer/aspeed_timer.c
 create mode 100644 include/hw/intc/aspeed_vic.h
 create mode 100644 include/hw/timer/aspeed_timer.h
Signature · 1 line
2.5.0
#1 lore raw

PATCH v3 1/3 hw/timer: Add ASPEED timer device model

Implement basic AST2400 timer functionality: Up to 8 timers can independently be configured, enabled, reset and disabled. A couple of hardware features are not implemented, namely clock value matching and pulse generation, but the implementation is enough to boot the Linux kernel configured with aspeed_defconfig.

---
Since v2:
* Improve handling of timer configuration with respect to enabled state
* Remove redundant enabled member from AspeedTimer
* Implement VMStateDescriptions
* Fix interrupt behaviour (edge triggered, both edges)
* Fix various issues with trace-event declarations
* Include qemu/osdep.h

Since v1:
* Refactor initialisation of and respect requested clock rates (APB/External)
* Simplify some index calculations
* Use tracing infrastructure instead of internal DPRINTF
* Enforce access size constraints and alignment in MemoryRegionOps

 default-configs/arm-softmmu.mak |   1 +
 hw/timer/Makefile.objs          |   1 +
 hw/timer/aspeed_timer.c         | 452 ++++++++++++++++++++++++++++++++++++++++
 include/hw/timer/aspeed_timer.h |  59 ++++++
 trace-events                    |   9 +
 5 files changed, 522 insertions(+)
 create mode 100644 hw/timer/aspeed_timer.c
 create mode 100644 include/hw/timer/aspeed_timer.h
default-configs/arm-softmmu.mak +1 -0
index a9f82a1..2bcd236 100644
@@ -110,3 +110,4 @@ CONFIG_IOH3420=y
 CONFIG_I82801B11=y
 CONFIG_ACPI=y
 CONFIG_SMBIOS=y
+CONFIG_ASPEED_SOC=y
hw/timer/Makefile.objs +1 -0
index 5cfea6e..003c14f 100644
@@ -32,3 +32,4 @@ obj-$(CONFIG_MC146818RTC) += mc146818rtc.o
 obj-$(CONFIG_ALLWINNER_A10_PIT) += allwinner-a10-pit.o
 
 common-obj-$(CONFIG_STM32F2XX_TIMER) += stm32f2xx_timer.o
+common-obj-$(CONFIG_ASPEED_SOC) += aspeed_timer.o
hw/timer/aspeed_timer.c new file +452 -0

452 lines not on this page · raw message

include/hw/timer/aspeed_timer.h new file +59 -0

59 lines not on this page · raw message

trace-events +9 -0
index 6fba6cc..856425d 100644
@@ -1886,3 +1886,12 @@ qio_channel_command_new_pid(void *ioc, int writefd, int readfd, int pid) "Comman
 qio_channel_command_new_spawn(void *ioc, const char *binary, int flags) "Command new spawn ioc=%p binary=%s flags=%d"
 qio_channel_command_abort(void *ioc, int pid) "Command abort ioc=%p pid=%d"
 qio_channel_command_wait(void *ioc, int pid, int ret, int status) "Command abort ioc=%p pid=%d ret=%d status=%d"
+
+# hw/timer/aspeed_timer.c
+aspeed_timer_ctrl_enable(uint8_t i, bool enable) "Timer %" PRIu8 ": %d"
+aspeed_timer_ctrl_external_clock(uint8_t i, bool enable) "Timer %" PRIu8 ": %d"
+aspeed_timer_ctrl_overflow_interrupt(uint8_t i, bool enable) "Timer %" PRIu8 ": %d"
+aspeed_timer_ctrl_pulse_enable(uint8_t i, bool enable) "Timer %" PRIu8 ": %d"
+aspeed_timer_set_ctrl2(uint32_t value) "Value: 0x%" PRIx32
+aspeed_timer_set_value(int timer, int reg, uint32_t value) "Timer %d register %d: 0x%" PRIx32
+aspeed_timer_read(uint64_t offset, unsigned size, uint64_t value) "From 0x%" PRIx64 ": of size %u: 0x%" PRIx64
Signature · 1 line
2.5.0
Reviewed-by on v3 1/3
#2 lore raw

Re: [Qemu-devel] [PATCH v3 1/3] hw/timer: Add ASPEED timer device model

Quoted 6 lines · Andrew Jeffery

Implement basic AST2400 timer functionality: Up to 8 timers can independently be configured, enabled, reset and disabled. A couple of hardware features are not implemented, namely clock value matching and pulse generation, but the implementation is enough to boot the Linux kernel configured with aspeed_defconfig.

Quoted 6 lines

---
+/**
+ * Avoid mutual references between AspeedTimerCtrlState and AspeedTimer
+ * structs, as it's a waste of memory and it makes implementing
+ * VMStateDescription a little clunky.

Not sure what you have in mind with the reference to VMStateDescription here. The vmstate struct only has to list the fields which contain actual volatile state -- things like backreference pointers to other structs aren't volatile state so don't appear.

Quoted 10 lines

The ptimer BH callback needs to know
+ * whether a specific AspeedTimer is enabled, but this information is held in
+ * AspeedTimerCtrlState. So, provide a helper to hoist ourselves from an
+ * arbitrary AspeedTimer to AspeedTimerCtrlState.
+ */

hw/timer/aspeed_timer.c new file +5 -0
+static inline struct AspeedTimerCtrlState *timer_to_ctrl(AspeedTimer *t)
+{
+    AspeedTimer (*timers)[] = (void *)t - (t->id * sizeof(*t));
+    return container_of(timers, AspeedTimerCtrlState, timers);
+}

hw/timer/aspeed_timer.c line 88

Quoted 10 lines
hw/timer/aspeed_timer.c new file +9 -0
 
+static void aspeed_timer_expire(void *opaque)
+{
+    AspeedTimer *t = opaque;
+
+    /* Only support interrupts on match values of zero for the moment - this is
+     * sufficient to boot an aspeed_defconfig Linux kernel. Non-zero match
+     * values need some further consideration given the current ptimer API.
+     * Maybe run multiple ptimers?
+     */

See hw/timer/a9gtimer.c for an example of a timer with a comparator that can fire when the timer hits an arbitrary comparator value (it doesn't use ptimers but the principle is the same -- you set the timer to fire at the next interesting event, and then in the timer-fired handler you reset the timer to fire whenever the next event after that is, if any.) In any case this is probably ok for now.

hw/timer/aspeed_timer.c line 96

Quoted 8 lines
hw/timer/aspeed_timer.c new file +8 -0
+    bool match = !(t->match[0] && t->match[1]);
+    bool interrupt = timer_overflow_interrupt(t) || match;
+    if (timer_enabled(t) && interrupt) {
+        t->level = !t->level;
+        qemu_set_irq(t->irq, t->level);
+    }
+}
+

Otherwise

thanks
-- PMM

#3 lore raw

Re: [Qemu-arm] [PATCH v3 1/3] hw/timer: Add ASPEED timer device model

Quoted 14 lines · Peter Maydell
Quoted 6 lines · Andrew Jeffery

Implement basic AST2400 timer functionality: Up to 8 timers can independently be configured, enabled, reset and disabled. A couple of hardware features are not implemented, namely clock value matching and pulse generation, but the implementation is enough to boot the Linux kernel configured with aspeed_defconfig.

Quoted 6 lines

---
+/**
+ * Avoid mutual references between AspeedTimerCtrlState and AspeedTimer
+ * structs, as it's a waste of memory and it makes implementing
+ * VMStateDescription a little clunky.

Quoted 4 lines

Not sure what you have in mind with the reference to VMStateDescription here. The vmstate struct only has to list the fields which contain actual volatile state -- things like backreference pointers to other structs aren't volatile state so don't appear.

Good point, looks like I was over-thinking things. I'll remove the part referencing VMStateDescription.

Quoted 12 lines
Quoted 11 lines

The ptimer BH callback needs to know
+ * whether a specific AspeedTimer is enabled, but this information is held in
+ * AspeedTimerCtrlState. So, provide a helper to hoist ourselves from an
+ * arbitrary AspeedTimer to AspeedTimerCtrlState.
+ */

hw/timer/aspeed_timer.c new file +5 -0
+static inline struct AspeedTimerCtrlState *timer_to_ctrl(AspeedTimer *t)
+{
+    AspeedTimer (*timers)[] = (void *)t - (t->id * sizeof(*t));
+    return container_of(timers, AspeedTimerCtrlState, timers);
+}
Quoted 16 lines

hw/timer/aspeed_timer.c line 88

Quoted 9 lines
hw/timer/aspeed_timer.c new file +9 -0
+static void aspeed_timer_expire(void *opaque)
+{
+    AspeedTimer *t = opaque;
+
+    /* Only support interrupts on match values of zero for the moment - this is
+     * sufficient to boot an aspeed_defconfig Linux kernel. Non-zero match
+     * values need some further consideration given the current ptimer API.
+     * Maybe run multiple ptimers?
+     */

See hw/timer/a9gtimer.c for an example of a timer with a comparator that can fire when the timer hits an arbitrary comparator value (it doesn't use ptimers but the principle is the same -- you set the timer to fire at the next interesting event, and then in the timer-fired handler you reset the timer to fire whenever the next event after that is, if any.) In any case this is probably ok for now.

Thanks for the pointer. I'll leave that change to a future patch given it looks like this is converging on being acceptable, though I'll expand the comment to cover a9gtimer.

Quoted 11 lines

hw/timer/aspeed_timer.c line 96

Quoted 9 lines
hw/timer/aspeed_timer.c new file +8 -0
+    bool match = !(t->match[0] && t->match[1]);
+    bool interrupt = timer_overflow_interrupt(t) || match;
+    if (timer_enabled(t) && interrupt) {
+        t->level = !t->level;
+        qemu_set_irq(t->irq, t->level);
+    }
+}
+

Otherwise

Quoted 1 line

Thanks!

Andrew

Quoted 3 lines

thanks
-- PMM

#4 lore raw

PATCH v3 2/3 hw/intc: Add (new) ASPEED VIC device model

In reply to Andrew Jeffery

Implement a basic ASPEED VIC device model, enough to boot a Linux kernel configured with aspeed_defconfig. The model implements the 'new' (revised) register set and while the hardware exposes both the new and legacy register sets, accesses to the legacy register set will not be serviced (though the access will be logged).

---
Since v2:
* Implement all supported interrupt types and configurations
* Implement a VMStateDescription
* Log accesses to legacy IO space
* Add documentation on some implementation and hardware details
* Switch to extract64/deposit64 where possible
* Drop int_ prefix from some struct member names
* Fix various issues with trace-event declarations
* Include qemu/osdep.h

 hw/intc/Makefile.objs        |   1 +
 hw/intc/aspeed_vic.c         | 335 +++++++++++++++++++++++++++++++++++++++++++
 include/hw/intc/aspeed_vic.h |  48 +++++++
 trace-events                 |   7 +
 4 files changed, 391 insertions(+)
 create mode 100644 hw/intc/aspeed_vic.c
 create mode 100644 include/hw/intc/aspeed_vic.h
hw/intc/Makefile.objs +1 -0
index 6a13a39..0e47f0f 100644
@@ -31,3 +31,4 @@ obj-$(CONFIG_XICS_KVM) += xics_kvm.o
 obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o
 obj-$(CONFIG_S390_FLIC) += s390_flic.o
 obj-$(CONFIG_S390_FLIC_KVM) += s390_flic_kvm.o
+obj-$(CONFIG_ASPEED_SOC) += aspeed_vic.o
hw/intc/aspeed_vic.c new file +335 -0

335 lines not on this page · raw message

include/hw/intc/aspeed_vic.h new file +48 -0

48 lines not on this page · raw message

trace-events +7 -0
index 856425d..eecca15 100644
@@ -1895,3 +1895,10 @@ aspeed_timer_ctrl_pulse_enable(uint8_t i, bool enable) "Timer %" PRIu8 ": %d"
 aspeed_timer_set_ctrl2(uint32_t value) "Value: 0x%" PRIx32
 aspeed_timer_set_value(int timer, int reg, uint32_t value) "Timer %d register %d: 0x%" PRIx32
 aspeed_timer_read(uint64_t offset, unsigned size, uint64_t value) "From 0x%" PRIx64 ": of size %u: 0x%" PRIx64
+
+# hw/intc/aspeed_vic.c
+aspeed_vic_set_irq(int irq, int level) "Enabling IRQ %d: %d"
+aspeed_vic_update_fiq(int flags) "Raising FIQ %d"
+aspeed_vic_update_irq(int flags) "Raising IRQ %d"
+aspeed_vic_read(uint64_t offset, unsigned size, uint32_t value) "From 0x%" PRIx64 " of size %u: 0x%" PRIx32
+aspeed_vic_write(uint64_t offset, unsigned size, uint32_t data) "To 0x%" PRIx64 " of size %u: 0x%" PRIx32
Signature · 1 line
2.5.0
Reviewed-by on v3 2/3
#5 lore raw

Re: [Qemu-arm] [PATCH v3 2/3] hw/intc: Add (new) ASPEED VIC device model

Quoted 56 lines · Andrew Jeffery

Implement a basic ASPEED VIC device model, enough to boot a Linux kernel configured with aspeed_defconfig. The model implements the 'new' (revised) register set and while the hardware exposes both the new and legacy register sets, accesses to the legacy register set will not be serviced (though the access will be logged).

hw/intc/aspeed_vic.c new file +48 -0
+static void aspeed_vic_write(void *opaque, hwaddr offset, uint64_t data,
+                             unsigned size)
+{
+    const bool high = !!(offset & 0x4);
+    hwaddr n_offset = (offset & ~0x4);
+    AspeedVICState *s = (AspeedVICState *)opaque;
+
+    if (offset < AVIC_NEW_BASE_OFFSET) {
+        qemu_log_mask(LOG_UNIMP,
+                      "%s: Ignoring write to legacy registers at 0x%"
+                      HWADDR_PRIx "[%u] <- 0x%" PRIx64 "\n", __func__, offset,
+                      size, data);
+        return;
+    }
+
+    n_offset -= AVIC_NEW_BASE_OFFSET;
+    trace_aspeed_vic_write(offset, size, data);
+
+    /* Given we have members using separate enable/clear registers, deposit64()
+     * isn't quite the tool for the job. Instead, relocate the incoming bits to
+     * the required bit offset based on the provided access address
+     */
+    if (high) {
+        data &= AVIC_H_MASK;
+        data <<= 32;
+    } else {
+        data &= AVIC_L_MASK;
+    }
+
+    switch (n_offset) {
+    case 0x18: /* Interrupt Selection */
+        /* Register has deposit64() semantics - overwrite requested 32 bits */
+        if (high) {
+            s->select &= AVIC_L_MASK;
+        } else {
+            s->select &= ((uint64_t) AVIC_H_MASK) << 32;
+        }
+        s->select |= data;
+        break;
+    case 0x20: /* Interrupt Enable */
+        s->enable |= data;
+        break;
+    case 0x28: /* Interrupt Enable Clear */
+        s->enable &= ~data;
+        break;
+    case 0x30: /* Software Interrupt */
+        qemu_log_mask(LOG_UNIMP, "%s: Software interrupts unavailable. "
+                "IRQs requested: 0x%016" PRIx64 "\n", __func__, data);

hw/intc/aspeed_vic.c line 230

Quoted 10 lines
hw/intc/aspeed_vic.c new file +10 -0
+        break;
+    case 0x38: /* Software Interrupt Clear */
+        qemu_log_mask(LOG_UNIMP, "%s: Software interrupts unavailable. "
+                "IRQs to be cleared: 0x%016" PRIx64 "\n", __func__, data);
+        break;
+    case 0x50: /* Interrupt Event */
+        /* Register has deposit64() semantics - overwrite the top four valid
+         * IRQ bits, as only the top four IRQs (GPIOs) can change their event
+         * type */
+        g_assert(high);

Don't assert on conditions that can be triggered by a guest.

Quoted 15 lines
hw/intc/aspeed_vic.c new file +15 -0
+        s->event &= ~AVIC_EVENT_W_MASK;
+        s->event |= (data & AVIC_EVENT_W_MASK);
+        break;
+    case 0x58: /* Edge Triggered Interrupt Clear */
+        s->raw &= ~(data & ~s->sense);
+        break;
+    case 0x00: /* IRQ Status */
+    case 0x08: /* FIQ Status */
+    case 0x10: /* Raw Interrupt Status */
+    case 0x40: /* Interrupt Sensitivity */
+    case 0x48: /* Interrupt Both Edge Trigger Control */
+    case 0x60: /* Edge Triggered Interrupt Status */
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "%s: Write of read-only register with offset 0x%"
+                      HWADDR_PRIx "\n", __func__, offset);

hw/intc/aspeed_vic.c line 255

Quoted 10 lines
hw/intc/aspeed_vic.c new file +10 -0
+        break;
+
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "%s: Bad register at offset 0x%" HWADDR_PRIx "\n",
+                      __func__, offset);
+        break;
+    }
+    aspeed_vic_update(s);
+}

Otherwise

thanks
-- PMM

#6 lore raw

Re: [Qemu-arm] [PATCH v3 2/3] hw/intc: Add (new) ASPEED VIC device model

Quoted 61 lines · Peter Maydell
Quoted 60 lines · Andrew Jeffery

Implement a basic ASPEED VIC device model, enough to boot a Linux kernel configured with aspeed_defconfig. The model implements the 'new' (revised) register set and while the hardware exposes both the new and legacy register sets, accesses to the legacy register set will not be serviced (though the access will be logged).

hw/intc/aspeed_vic.c new file +52 -0
+static void aspeed_vic_write(void *opaque, hwaddr offset, uint64_t data,
+                             unsigned size)
+{
+    const bool high = !!(offset & 0x4);
+    hwaddr n_offset = (offset & ~0x4);
+    AspeedVICState *s = (AspeedVICState *)opaque;
+
+    if (offset < AVIC_NEW_BASE_OFFSET) {
+        qemu_log_mask(LOG_UNIMP,
+                      "%s: Ignoring write to legacy registers at 0x%"
+                      HWADDR_PRIx "[%u] <- 0x%" PRIx64 "\n", __func__, offset,
+                      size, data);
+        return;
+    }
+
+    n_offset -= AVIC_NEW_BASE_OFFSET;
+    trace_aspeed_vic_write(offset, size, data);
+
+    /* Given we have members using separate enable/clear registers, deposit64()
+     * isn't quite the tool for the job. Instead, relocate the incoming bits to
+     * the required bit offset based on the provided access address
+     */
+    if (high) {
+        data &= AVIC_H_MASK;
+        data <<= 32;
+    } else {
+        data &= AVIC_L_MASK;
+    }
+
+    switch (n_offset) {
+    case 0x18: /* Interrupt Selection */
+        /* Register has deposit64() semantics - overwrite requested 32 bits */
+        if (high) {
+            s->select &= AVIC_L_MASK;
+        } else {
+            s->select &= ((uint64_t) AVIC_H_MASK) << 32;
+        }
+        s->select |= data;
+        break;
+    case 0x20: /* Interrupt Enable */
+        s->enable |= data;
+        break;
+    case 0x28: /* Interrupt Enable Clear */
+        s->enable &= ~data;
+        break;
+    case 0x30: /* Software Interrupt */
+        qemu_log_mask(LOG_UNIMP, "%s: Software interrupts unavailable. "
+                "IRQs requested: 0x%016" PRIx64 "\n", __func__, data);
+        break;
+    case 0x38: /* Software Interrupt Clear */
+        qemu_log_mask(LOG_UNIMP, "%s: Software interrupts unavailable. "
+                "IRQs to be cleared: 0x%016" PRIx64 "\n", __func__, data);
Quoted 8 lines

hw/intc/aspeed_vic.c line 230

Quoted 6 lines
hw/intc/aspeed_vic.c new file +6 -0
+        break;
+    case 0x50: /* Interrupt Event */
+        /* Register has deposit64() semantics - overwrite the top four valid
+         * IRQ bits, as only the top four IRQs (GPIOs) can change their event
+         * type */
+        g_assert(high);

Don't assert on conditions that can be triggered by a guest.

Good point, I'll change it to qemu_log_mask(LOG_GUEST_ERROR, ...)

Quoted 28 lines
Quoted 16 lines
hw/intc/aspeed_vic.c new file +15 -0
+        s->event &= ~AVIC_EVENT_W_MASK;
+        s->event |= (data & AVIC_EVENT_W_MASK);
+        break;
+    case 0x58: /* Edge Triggered Interrupt Clear */
+        s->raw &= ~(data & ~s->sense);
+        break;
+    case 0x00: /* IRQ Status */
+    case 0x08: /* FIQ Status */
+    case 0x10: /* Raw Interrupt Status */
+    case 0x40: /* Interrupt Sensitivity */
+    case 0x48: /* Interrupt Both Edge Trigger Control */
+    case 0x60: /* Edge Triggered Interrupt Status */
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "%s: Write of read-only register with offset 0x%"
+                      HWADDR_PRIx "\n", __func__, offset);

hw/intc/aspeed_vic.c line 255

Quoted 10 lines
hw/intc/aspeed_vic.c new file +10 -0
+        break;
+
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "%s: Bad register at offset 0x%" HWADDR_PRIx "\n",
+                      __func__, offset);
+        break;
+    }
+    aspeed_vic_update(s);
+}

Otherwise

Quoted 1 line

Thanks,

Andrew

Quoted 3 lines

thanks
-- PMM

#7 lore raw

PATCH v3 3/3 hw/arm: Add ASPEED AST2400 machine model

In reply to Andrew Jeffery

Adds an AST2400 ARM machine[1], based around an AST2400 SOC containing an ARM926 processor, ASPEED VIC and timer devices, and a 8250 UART. The new machine type is functional enough to boot an aspeed_defconfig Linux kernel to userspace.

[1] http://www.aspeedtech.com/products.php?fPath=20&rId=376

---
Since v2:
* Implement a SOC model to move code out from the machine definition
* Rework the machine to better use QOM
* Include qemu/osdep.h
* Revert back to qemu_log_mask(LOG_UNIMP, ...) in IO handlers

Since v1:

 hw/arm/Makefile.objs |   1 +
 hw/arm/ast2400.c     | 208 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 209 insertions(+)
 create mode 100644 hw/arm/ast2400.c
hw/arm/Makefile.objs +1 -0
index a711e4d..f333b7f 100644
@@ -16,3 +16,4 @@ obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o
 obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-zynqmp.o xlnx-ep108.o
 obj-$(CONFIG_FSL_IMX25) += fsl-imx25.o imx25_pdk.o
 obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o
+obj-$(CONFIG_ASPEED_SOC) += ast2400.o
hw/arm/ast2400.c new file +208 -0

208 lines not on this page · raw message

Signature · 1 line
2.5.0
#8 lore raw

Re: [Qemu-arm] [PATCH v3 3/3] hw/arm: Add ASPEED AST2400 machine model

Quoted 69 lines · Andrew Jeffery

Adds an AST2400 ARM machine[1], based around an AST2400 SOC containing an ARM926 processor, ASPEED VIC and timer devices, and a 8250 UART. The new machine type is functional enough to boot an aspeed_defconfig Linux kernel to userspace.

[1] http://www.aspeedtech.com/products.php?fPath=20&rId=376

---
Since v2:
* Implement a SOC model to move code out from the machine definition
* Rework the machine to better use QOM
* Include qemu/osdep.h
* Revert back to qemu_log_mask(LOG_UNIMP, ...) in IO handlers

Since v1:

 hw/arm/Makefile.objs |   1 +
 hw/arm/ast2400.c     | 208 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 209 insertions(+)
 create mode 100644 hw/arm/ast2400.c
hw/arm/Makefile.objs +1 -0
index a711e4d..f333b7f 100644
@@ -16,3 +16,4 @@ obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o
 obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-zynqmp.o xlnx-ep108.o
 obj-$(CONFIG_FSL_IMX25) += fsl-imx25.o imx25_pdk.o
 obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o
+obj-$(CONFIG_ASPEED_SOC) += ast2400.o
hw/arm/ast2400.c new file +31 -0
new file mode 100644
index 0000000..74aca49
@@ -0,0 +1,208 @@
+/*
+ * ASPEED AST2400
+ *
+ * Andrew Jeffery <[email protected]>
+ * Jeremy Kerr <[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 "exec/address-spaces.h"
+#include "hw/arm/arm.h"
+#include "hw/boards.h"
+#include "hw/char/serial.h"
+#include "hw/sysbus.h"
+#include "hw/intc/aspeed_vic.h"
+#include "hw/timer/aspeed_timer.h"
+#include "target-arm/cpu.h"
+#include "trace.h"
+
+#define AST2400_UART_5_BASE      0x00184000
+#define AST2400_IOMEM_SIZE       0x00200000
+#define AST2400_IOMEM_BASE       0x1E600000
+#define AST2400_VIC_BASE         0x1E6C0000
+#define AST2400_TIMER_BASE       0x1E782000
+#define AST2400_SDRAM_BASE       0x40000000
 
+
+static void ast2400_soc_realize(DeviceState *dev, Error **errp)

hw/arm/ast2400.c line 104

Quoted 10 lines
hw/arm/ast2400.c new file +10 -0
+{
+    int i;
+    AST2400SOCState *s = AST2400_SOC(dev);
+    Error *err = NULL;
+
+    /* IO space */
+    memory_region_init_io(&s->iomem, NULL, &ast2400_soc_io_ops, NULL,
+            "ast2400.io", AST2400_IOMEM_SIZE);
+    memory_region_add_subregion(get_system_memory(), AST2400_IOMEM_BASE,
+            &s->iomem);

You need to add this memory region with a priority set so it is lower priority than the VIC etc memory regions which it overlaps (use memory_region_add_subregion_overlap()).

hw/arm/ast2400.c line 164

Quoted 6 lines
hw/arm/ast2400.c new file +6 -0
+static void ast2400_soc_register_types(void)
+{
+    type_register_static(&ast2400_soc_type_info);
+}
+
+type_init(ast2400_soc_register_types)

Your SoC device should be in its own source file, not sharing one with the board file.

Otherwise I think this looks OK.

thanks
-- PMM