add sunxi machine type
v5 cover add sunxi machine type
this patch-set implemented a device-reduced
machine type for Allwinner's sunxi series SoC,
like sunxi-4i/5i/7i ...
now, It can support sunxi-4i with a cortex-a8 processor. and will support more later, like sunxi-7i with cortex-a7, and will add more devices.
v2: split timer and interrupt controller emulation into
their corresponding files.
v3:
1. change loader_start address
2. add 64-bit counter
3. fixup fail to clear interrup status issue
v4:
1. add VMSD
2. use defines of magic number for readability
3. code cleanup
v5:
1. add VMSTATE_PTIMER_ARRAY
2. code cleanup
TODO:
1. add BROM support
2. add more devices
3. add sunxi-7i support
test:
can boot-up officially released linux kernel.
reference:
http://linux-sunxi.org/Main_Page
Li Guang (5)
hw/ptimer: add VMSTATE_PTIMER_ARRAY hw/timer: add sunxi timer device hw/intc: add sunxi interrupt controller device hw/arm: add sunxi machine type
MAINTAINERS: add myself to maintain sunxi machine
MAINTAINERS | 9 +++++++++ default-configs/arm-softmmu.mak | 3 + hw/arm/Makefile.objs | 1 + hw/arm/sunxi-soc.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/intc/Makefile.objs | 1 + hw/intc/sunxi-pic.c | 244 +++++++++++++++++++++++++++++++++++++++ hw/timer/Makefile.objs | 1 + hw/timer/sunxi-pit.c | 276 +++++++++++++++++++++++++++++++++++++++ include/hw/intc/sunxi-pic.h | 20 +++ include/hw/ptimer.h | 3 +++ include/hw/timer/sunxi-pit.h | 37 +++++ 11 files changed, 693 insertions(+), 0 deletions(-) create mode 100644 hw/timer/sunxi-pit.c create mode 100644 include/hw/timer/sunxi-pit.h create mode 100644 hw/intc/sunxi-pic.c create mode 100644 include/hw/intc/sunxi-pic.h create mode 100644 hw/arm/sunxi-soc.c
PATCH v5 1/5 hw/ptimer: add VMSTATE_PTIMER_ARRAY
--- include/hw/ptimer.h | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
include/hw/ptimer.h +3 -0
@@ -27,6 +27,9 @@ void ptimer_stop(ptimer_state *s);extern const VMStateDescription vmstate_ptimer; +#define VMSTATE_PTIMER_ARRAY (_f, _s, _n) \ + VMSTATE_STRUCT_ARRAY(_f, _s, _n, 0, vmstate_ptimer, ptimer_state*) +#define VMSTATE_PTIMER (_field, _state) { \ .name = (stringify(_field)), \ .version_id = (1), \
Signature · 1 line
1.7.2.5
PATCH v5 2/5 hw/timer: add sunxi timer device
In reply to liguang--- default-configs/arm-softmmu.mak | 2 + hw/timer/Makefile.objs | 1 + hw/timer/sunxi-pit.c | 276 +++++++++++++++++++++++++++++++++++++++ include/hw/timer/sunxi-pit.h | 37 +++++ 4 files changed, 316 insertions(+), 0 deletions(-) create mode 100644 hw/timer/sunxi-pit.c create mode 100644 include/hw/timer/sunxi-pit.h
default-configs/arm-softmmu.mak +2 -0
@@ -81,3 +81,5 @@ CONFIG_VERSATILE_I2C=y CONFIG_SDHCI=y CONFIG_INTEGRATOR_DEBUG=y + +CONFIG_SUNXI_PIT=y
hw/timer/Makefile.objs +1 -0
@@ -27,3 +27,4 @@ obj-$(CONFIG_SH4) += sh_timer.o obj-$(CONFIG_TUSB6010) += tusb6010.o obj-$(CONFIG_MC146818RTC) += mc146818rtc.o +obj-$(CONFIG_SUNXI_PIT) += sunxi-pit.o
hw/timer/sunxi-pit.c new file +276 -0
276 lines not on this page · raw message
include/hw/timer/sunxi-pit.h new file +37 -0
@@ -0,0 +1,37 @@ +#ifndef SUNXI_PIT_H +#define SUNXI_PIT_H + + +#define TYPE_SUNXI_PIT "sunxi-timer" +#define SUNXI_PIT (obj) OBJECT_CHECK(SunxiPITState, (obj), TYPE_SUNXI_PIT) + +#define SUNXI_TIMER_NR 6 +#define SUNXI_TIMER_IRQ 0x1 +#define SUNXI_WDOG_IRQ 0x100 + +#define SUNXI_TIMER_IRQ_EN 0 +#define SUNXI_TIMER_IRQ_ST 0x4 + +#define SUNXI_TIMER_CONTROL 0x0 +#define SUNXI_TIMER_EN 0x1 +#define SUNXI_TIMER_RELOAD 0x2 +#define SUNXI_TIMER_MODE 0x80 + +#define SUNXI_TIMER_INTERVAL 0x4 +#define SUNXI_TIMER_COUNT 0x8 +#define SUNXI_WDOG_CONTROL 0x90 +#define SUNXI_WDOG_MODE 0x94 + +#define SUNXI_COUNT_CTL 0xa0 +#define SUNXI_COUNT_RL_EN 0x2 +#define SUNXI_COUNT_CLR_EN 0x1 +#define SUNXI_COUNT_LO 0xa4 +#define SUNXI_COUNT_HI 0xa8 + +#define SUNXI_TIMER_BASE 0x10 + +#define SUNXI_DEFAULT_CLOCK 0x4 + + +#endif +
Signature · 1 line
1.7.2.5
Re: [Qemu-devel] [PATCH v5 2/5] hw/timer: add sunxi timer device
Quoted 67 lines · liguang
Signed-off-by liguang <[email protected]>--- default-configs/arm-softmmu.mak | 2 + hw/timer/Makefile.objs | 1 + hw/timer/sunxi-pit.c | 276 +++++++++++++++++++++++++++++++++++++++ include/hw/timer/sunxi-pit.h | 37 +++++ 4 files changed, 316 insertions(+), 0 deletions(-) create mode 100644 hw/timer/sunxi-pit.c create mode 100644 include/hw/timer/sunxi-pit.hdefault-configs/arm-softmmu.mak +2
-0@@ -81,3 +81,5 @@ CONFIG_VERSATILE_I2C=y CONFIG_SDHCI=y CONFIG_INTEGRATOR_DEBUG=y + +CONFIG_SUNXI_PIT=yhw/timer/Makefile.objs +1
-0@@ -27,3 +27,4 @@ obj-$(CONFIG_SH4) += sh_timer.o obj-$(CONFIG_TUSB6010) += tusb6010.o obj-$(CONFIG_MC146818RTC) += mc146818rtc.o +obj-$(CONFIG_SUNXI_PIT) += sunxi-pit.ohw/timer/sunxi-pit.c new file +32
-0@@ -0,0 +1,276 @@ +/* +* Allwinner sunxi timer device emulation +* +* Copyright (C) 2013 Li Guang +* Written by Li Guang <[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. +*/ + +#include "hw/sysbus.h" +#include "hw/ptimer.h" +#include "sysemu/sysemu.h" +#include "hw/timer/sunxi-pit.h" + + +typedef struct SunxiPITState { + /*< private >*/ + SysBusDevice parent_obj; + /*< public >*/ + qemu_irq irq[SUNXI_TIMER_NR]; + ptimer_state *timer[SUNXI_TIMER_NR]; + MemoryRegion iomem; + + uint32_t irq_enable;
hw/timer/sunxi-pit.c line 42
Quoted 10 lines
hw/timer/sunxi-pit.c new file +10
-0+uint32_t irq_status; +uint32_t control[SUNXI_TIMER_NR ]; +uint32_t interval[SUNXI_TIMER_NR ]; +uint32_t count[SUNXI_TIMER_NR ]; +uint32_t watch_dog_mode; +uint32_t watch_dog_control; +uint32_t count_lo; +uint32_t count_hi; +uint32_t count_ctl; +} SunxiPITState;
So i've done some more list reasearch. If you want this to work with the latest SoC style device model layout, you need to move this struct definition to the device header file, so container object can embed it with their container state structs. Check the arm mpcore and its subcomponents (e.g. mptimer) for a very modern example.
hw/timer/sunxi-pit.c line 52
Quoted 10 lines
hw/timer/sunxi-pit.c new file +10
-0+ +static uint64_t sunxi_pit_read (void *opaque,hwaddr offset,unsigned size) +{ +SunxiPITState *s =SUNXI_PIT (opaque); +uint8_t index; + +switch (offset) { +case SUNXI_TIMER_IRQ_EN : +return s->irq_enable; +break ;
break after return not needed. Does this throw a werror? Fix globally.
Quoted 9 lines
hw/timer/sunxi-pit.c new file +9
-0+case SUNXI_TIMER_IRQ_ST : +return s->irq_status; +break ; + case SUNXI_TIMER_BASE ... SUNXI_TIMER_BASE * 6 + SUNXI_TIMER_COUNT: + index = offset &0xf0 ; + index >>=4 ; + index -=1 ; +switch (offset &0x0f ) { +case SUNXI_TIMER_CONTROL :
hw/timer/sunxi-pit.c line 71
Quoted 10 lines
hw/timer/sunxi-pit.c new file +10
-0+return s->control[index]; +break ; +case SUNXI_TIMER_INTERVAL : +return s->interval[index]; +break ; +case SUNXI_TIMER_COUNT : + s->count[index] =ptimer_get_count (s->timer[index]); +return s->count[index]; +default : +break ;
This is also a guest error condition. Same in write().
Regards,
Peter
Re: [Qemu-devel] [PATCH v5 2/5] hw/timer: add sunxi timer device
Quoted 121 lines · Peter Crosthwaite
Quoted 68 lines · liguang
Signed-off-by liguang<[email protected]>--- default-configs/arm-softmmu.mak | 2 + hw/timer/Makefile.objs | 1 + hw/timer/sunxi-pit.c | 276 +++++++++++++++++++++++++++++++++++++++ include/hw/timer/sunxi-pit.h | 37 +++++ 4 files changed, 316 insertions(+), 0 deletions(-)create mode 100644
hw/timer/sunxi-pit.c
create mode 100644include/hw/timer/sunxi-pit.hdefault-configs/arm-softmmu.mak +2
-0@@ -81,3 +81,5 @@ CONFIG_VERSATILE_I2C=y CONFIG_SDHCI=y CONFIG_INTEGRATOR_DEBUG=y + +CONFIG_SUNXI_PIT=yhw/timer/Makefile.objs +1
-0@@ -27,3 +27,4 @@ obj-$(CONFIG_SH4) += sh_timer.o obj-$(CONFIG_TUSB6010) += tusb6010.o obj-$(CONFIG_MC146818RTC) += mc146818rtc.o +obj-$(CONFIG_SUNXI_PIT) += sunxi-pit.ohw/timer/sunxi-pit.c new file +32
-0@@ -0,0 +1,276 @@ +/* +* Allwinner sunxi timer device emulation +* +* Copyright (C) 2013 Li Guang +* Written by Li Guang<[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. +*/ + +#include "hw/sysbus.h" +#include "hw/ptimer.h" +#include "sysemu/sysemu.h" +#include "hw/timer/sunxi-pit.h" + + +typedef struct SunxiPITState { + /*< private>*/ + SysBusDevice parent_obj; + /*< public>*/ + qemu_irq irq[SUNXI_TIMER_NR]; + ptimer_state *timer[SUNXI_TIMER_NR]; + MemoryRegion iomem; + + uint32_t irq_enable;hw/timer/sunxi-pit.c line 42
Quoted 10 lines
hw/timer/sunxi-pit.c new file +10
-0+uint32_t irq_status; +uint32_t control[SUNXI_TIMER_NR ]; +uint32_t interval[SUNXI_TIMER_NR ]; +uint32_t count[SUNXI_TIMER_NR ]; +uint32_t watch_dog_mode; +uint32_t watch_dog_control; +uint32_t count_lo; +uint32_t count_hi; +uint32_t count_ctl; +} SunxiPITState;So i've done some more list reasearch. If you want this to work with the latest SoC style device model layout, you need to move this struct definition to the device header file, so container object can embed it with their container state structs. Check the arm mpcore and its subcomponents (e.g. mptimer) for a very modern example.
hw/timer/sunxi-pit.c line 52
Quoted 11 lines
hw/timer/sunxi-pit.c new file +10
-0+ +static uint64_t sunxi_pit_read (void *opaque,hwaddr offset,unsigned size) +{ +SunxiPITState *s =SUNXI_PIT (opaque); +uint8_t index; + +switch (offset) { +case SUNXI_TIMER_IRQ_EN : +return s->irq_enable; +break ;break after return not needed. Does this throw a werror? Fix globally.
Quoted 10 lines
hw/timer/sunxi-pit.c new file +9
-0+case SUNXI_TIMER_IRQ_ST : +return s->irq_status; +break ; + case SUNXI_TIMER_BASE ... SUNXI_TIMER_BASE * 6 + SUNXI_TIMER_COUNT: + index = offset&0xf0 ; + index>>=4 ; + index -=1 ; +switch (offset&0x0f ) { +case SUNXI_TIMER_CONTROL :hw/timer/sunxi-pit.c line 71
Quoted 10 lines
hw/timer/sunxi-pit.c new file +10
-0+return s->control[index]; +break ; +case SUNXI_TIMER_INTERVAL : +return s->interval[index]; +break ; +case SUNXI_TIMER_COUNT : + s->count[index] =ptimer_get_count (s->timer[index]); +return s->count[index]; +default : +break ;
Quoted 4 lines
This is also a guest error condition. Same in
write().
will fix all.
Thanks!
Li Guang
PATCH v5 3/5 hw/intc: add sunxi interrupt controller device
In reply to liguang--- default-configs/arm-softmmu.mak | 1 + hw/intc/Makefile.objs | 1 + hw/intc/sunxi-pic.c | 247 +++++++++++++++++++++++++++++++++++++++ include/hw/intc/sunxi-pic.h | 20 +++ 4 files changed, 269 insertions(+), 0 deletions(-) create mode 100644 hw/intc/sunxi-pic.c create mode 100644 include/hw/intc/sunxi-pic.h
default-configs/arm-softmmu.mak +1 -0
@@ -83,3 +83,4 @@ CONFIG_SDHCI=y CONFIG_INTEGRATOR_DEBUG=y CONFIG_SUNXI_PIT=y +CONFIG_SUNXI_PIC=y
hw/intc/Makefile.objs +1 -0
@@ -12,6 +12,7 @@ common-obj-$(CONFIG_IOAPIC) += ioapic_common.o common-obj-$(CONFIG_ARM_GIC) += arm_gic_common.o common-obj-$(CONFIG_ARM_GIC) += arm_gic.o common-obj-$(CONFIG_OPENPIC) += openpic.o +common-obj-$(CONFIG_SUNXI_PIC) += sunxi-pic.o obj-$(CONFIG_APIC) += apic.o apic_common.o obj-$(CONFIG_ARM_GIC_KVM) += arm_gic_kvm.o
hw/intc/sunxi-pic.c new file +247 -0
247 lines not on this page · raw message
include/hw/intc/sunxi-pic.h new file +20 -0
@@ -0,0 +1,20 @@ +#ifndef SUNXI_PIC_H +#define SUNXI_PIC_H + +#define TYPE_SUNXI_PIC "sunxi-pic" +#define SUNXI_PIC (obj) OBJECT_CHECK(SunxiPICState, (obj), TYPE_SUNXI_PIC) + +#define SUNXI_PIC_VECTOR 0 +#define SUNXI_PIC_BASE_ADDR 4 +#define SUNXI_PIC_PROTECT 8 +#define SUNXI_PIC_NMI 0xc +#define SUNXI_PIC_IRQ_PENDING 0x10 +#define SUNXI_PIC_FIQ_PENDING 0x20 +#define SUNXI_PIC_SELECT 0x30 +#define SUNXI_PIC_ENABLE 0x40 +#define SUNXI_PIC_MASK 0x50 + +#define SUNXI_PIC_INT_NR 95 +#define SUNXI_PIC_REG_IDX DIV_ROUND_UP(SUNXI_PIC_INT_NR, 32) + +#endif
Signature · 1 line
1.7.2.5
PATCH v5 4/5 hw/arm: add sunxi machine type
In reply to liguang--- hw/arm/Makefile.objs | 1 + hw/arm/sunxi-soc.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 0 deletions(-) create mode 100644 hw/arm/sunxi-soc.c
hw/arm/Makefile.objs +1 -0
@@ -5,3 +5,4 @@ obj-y += tosa.o versatilepb.o vexpress.o xilinx_zynq.o z2.o obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o obj-y += omap1.o omap2.o strongarm.o +obj-y += sunxi-soc.o
hw/arm/sunxi-soc.c new file +98 -0
98 lines not on this page · raw message
Signature · 1 line
1.7.2.5
PATCH v5 5/5 MAINTAINERS: add myself to maintain sunxi machine
In reply to liguang--- MAINTAINERS | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
MAINTAINERS +9 -0
@@ -284,6 +284,15 @@ M: Peter Maydell <[email protected]> S: Maintained F: hw/*/stellaris* +Sunxi +M: Li Guang <[email protected]> +S: Maintained +F: hw/arm/sunxi-soc.c +F: hw/intc/sunxi-pic.c +F: hw/timer/sunxi-pit.c +F: include/hw/intc/sunxi-pic.h +F: include/hw/timer/sunxi-pit.h + Versatile PB M: Peter Maydell <[email protected]> S: Maintained
Signature · 1 line
1.7.2.5