Add Allwinner H3 SoC and Orange Pi PC Machine
v4 cover Add Allwinner H3 SoC and Orange Pi PC Machine
Dear QEMU developers,
Hereby I would like to contribute the following set of patches to QEMU which add support for the Allwinner H3 System on Chip and the Orange Pi PC machine. The following features and devices are supported:
* SMP (Quad Core Cortex A7)
* Generic Interrupt Controller configuration
* SRAM mappings
* SDRAM controller
* Real Time Clock
* Timer device (re-used from Allwinner A10)
* UART
* SD/MMC storage controller
* EMAC ethernet connectivity
* USB 2.0 interfaces
* Clock Control Unit
* System Control module
* Security Identifier device
Functionality related to graphical output such as HDMI, GPU, Display Engine and audio are not included. Recently released mainline Linux kernels (4.19 up to latest master), mainline U-Boot and NetBSD 9.0-RC1 are known to work.
For full details on how to use the Orange Pi PC machine, see the file docs/orangepi.rst which is included as a patch in this series.
The contents of this patch series is available on Github at:
https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v3
The followings are currently known issues in this series:
- NetBSD 9.0-RC1 reads out year 2050 from RTC, while Linux works fine
-> This is due to difference in base year defined by the corresponding drivers
- RTC date & time is not persistent
- boot0 custom Allwinner bootloader not yet working
- Watchdog not yet implemented, affects U-Boot 'reset' and shutdown/reboot
-> This is part of the existing A10 timer that needs to be generalized firstLooking forward to your review comments. I will do my best to update the patches where needed.
===== CHANGELOG =====
v4:
* docs/orangepi.rst: correct SDRAM size in board description: 512MB -> 1GiB
* hw/arm/orangepi.c: correct SDRAM size in commit message: 512MB -> 1GiB
* hw/arm/orangepi.c: set .nb_cpus in the orangepi_binfo struct static initialisation
* hw/arm/orangepi.c: remove .board_id from orangepi_binfo struct
* hw/arm/orangepi.c: move BIOS check to top of orangepi_init()
* hw/arm/orangepi.c: change clk1-freq argument 24000000 to 24 * 1000 * 1000 for readability
* hw/arm/orangepi.c: rephrase 1GiB check error message
* include/hw/arm/allwinner-h3.h: improved comments
* hw/arm/allwinner-h3.c: remove duplicate initialization and declaration of i variable
* hw/arm/allwinner-h3.c: use DEVICE(&s->cpus[i]) instead of qemu_get_cpu()
* hw/arm/allwinner-h3.c: use qdev API instead of object API in CPU initialization part
* hw/arm/allwinner-h3.c: add note that UARTs are connected to APB2_CLK, for future clocktree API
* hw/arm/allwinner-h3.c: extend commit message for Boot ROM with description for the 32KiB size
* hw/rtc/allwinner-rtc.c: correct usage of AwRtcClass->regmap_size for checking r/w offset
* hw/misc/allwinner-cpucfg.c: remove 64-bit counter, as it is unused by Linux/U-Boot/NetBSD
* hw/misc/allwinner-cpucfg.c: add CPU_EXCEPTION_LEVEL_ON_RESET constant
* hw/misc/allwinner-cpucfg.c: break instead of return after logging guest error, for tracing
* hw/misc/allwinner-cpucfg.c: reduce duplication in switch/case for REG_CPUX_RST_CTRL in write function
* include/hw/rtc/allwinner-rtc.h: increase AW_RTC_REGS_MAXADDR to 0x200
* include/hw/rtc/allwinner-rtc.h: change type of AwRtcClass->year_offset to int, to match struct tm
* tests/acceptance/boot_linux_console.py: remove calls to vm.set_machine()
* tests/acceptance/boot_linux_console.py: added NetBSD test by Philippe
* docs/orangepi.rst: removed some unneeded words/typos
* docs/orangepi.rst: remove usage of -j5 for calling make (not all users have >= 4 SMP cores)
* include/hw/*/allwinner*.h: moved #include "qemu/osdep.h" and unneeded #includes to .c file
v3: https://lists.gnu.org/archive/html/qemu-devel/2020-01/msg01534.html
https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v3
v2: https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg03265.html
https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v2
v1: https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg00320.html
https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v1
With kind regards,
Niek Linnenbank
Niek Linnenbank (13):
hw/arm: add Allwinner H3 System-on-Chip hw/arm: add Xunlong Orange Pi PC machine hw/arm/allwinner-h3: add Clock Control Unit hw/arm/allwinner-h3: add USB host controller hw/arm/allwinner-h3: add System Control module hw/arm/allwinner: add CPU Configuration module hw/arm/allwinner: add Security Identifier device hw/arm/allwinner: add SD/MMC host controller hw/arm/allwinner-h3: add EMAC ethernet device hw/arm/allwinner-h3: add Boot ROM support hw/arm/allwinner-h3: add SDRAM controller device hw/arm/allwinner: add RTC device support
docs: add Orange Pi PC document
Philippe Mathieu-Daudé (7):
tests/boot_linux_console: Add a quick test for the OrangePi PC board tests/boot_linux_console: Add initrd test for the Orange Pi PC board tests/boot_linux_console: Add a SD card test for the OrangePi PC board tests/boot_linux_console: Add a SLOW test booting Ubuntu on OrangePi
PC
Acceptance tests: Extract _console_interaction() Acceptance tests: Add interrupt_interactive_console_until_pattern() tests/boot_linux_console: Test booting NetBSD via U-Boot on OrangePi
PC
docs/orangepi.rst | 199 +++++ default-configs/arm-softmmu.mak | 1 + hw/usb/hcd-ehci.h | 1 + include/hw/arm/allwinner-a10.h | 4 + include/hw/arm/allwinner-h3.h | 163 ++++ include/hw/misc/allwinner-cpucfg.h | 52 ++ include/hw/misc/allwinner-h3-ccu.h | 66 ++ include/hw/misc/allwinner-h3-dramc.h | 106 +++ include/hw/misc/allwinner-h3-sysctrl.h | 67 ++ include/hw/misc/allwinner-sid.h | 60 ++ include/hw/net/allwinner-sun8i-emac.h | 99 +++ include/hw/rtc/allwinner-rtc.h | 128 ++++ include/hw/sd/allwinner-sdhost.h | 135 ++++ hw/arm/allwinner-a10.c | 19 + hw/arm/allwinner-h3.c | 476 ++++++++++++ hw/arm/cubieboard.c | 15 + hw/arm/orangepi.c | 127 ++++ hw/misc/allwinner-cpucfg.c | 269 +++++++ hw/misc/allwinner-h3-ccu.c | 243 ++++++ hw/misc/allwinner-h3-dramc.c | 358 +++++++++ hw/misc/allwinner-h3-sysctrl.c | 140 ++++ hw/misc/allwinner-sid.c | 170 +++++ hw/net/allwinner-sun8i-emac.c | 871 ++++++++++++++++++++++ hw/rtc/allwinner-rtc.c | 386 ++++++++++ hw/sd/allwinner-sdhost.c | 848 +++++++++++++++++++++ hw/usb/hcd-ehci-sysbus.c | 17 + MAINTAINERS | 9 + hw/arm/Kconfig | 9 + hw/arm/Makefile.objs | 1 + hw/misc/Makefile.objs | 5 + hw/misc/trace-events | 19 + hw/net/Kconfig | 3 + hw/net/Makefile.objs | 1 + hw/net/trace-events | 10 + hw/rtc/Makefile.objs | 1 + hw/rtc/trace-events | 4 + hw/sd/Makefile.objs | 1 + hw/sd/trace-events | 7 + tests/acceptance/avocado_qemu/__init__.py | 59 +- tests/acceptance/boot_linux_console.py | 210 ++++++ 40 files changed, 5345 insertions(+), 14 deletions(-) create mode 100644 docs/orangepi.rst create mode 100644 include/hw/arm/allwinner-h3.h create mode 100644 include/hw/misc/allwinner-cpucfg.h create mode 100644 include/hw/misc/allwinner-h3-ccu.h create mode 100644 include/hw/misc/allwinner-h3-dramc.h create mode 100644 include/hw/misc/allwinner-h3-sysctrl.h create mode 100644 include/hw/misc/allwinner-sid.h create mode 100644 include/hw/net/allwinner-sun8i-emac.h create mode 100644 include/hw/rtc/allwinner-rtc.h create mode 100644 include/hw/sd/allwinner-sdhost.h create mode 100644 hw/arm/allwinner-h3.c create mode 100644 hw/arm/orangepi.c create mode 100644 hw/misc/allwinner-cpucfg.c create mode 100644 hw/misc/allwinner-h3-ccu.c create mode 100644 hw/misc/allwinner-h3-dramc.c create mode 100644 hw/misc/allwinner-h3-sysctrl.c create mode 100644 hw/misc/allwinner-sid.c create mode 100644 hw/net/allwinner-sun8i-emac.c create mode 100644 hw/rtc/allwinner-rtc.c create mode 100644 hw/sd/allwinner-sdhost.c
Signature · 1 line
2.17.1
PATCH v4 1/20 hw/arm: add Allwinner H3 System-on-Chip
The Allwinner H3 is a System on Chip containing four ARM Cortex A7 processor cores. Features and specifications include DDR2/DDR3 memory, SD/MMC storage cards, 10/100/1000Mbit Ethernet, USB 2.0, HDMI and various I/O modules. This commit adds support for the Allwinner H3 System on Chip.
--- default-configs/arm-softmmu.mak | 1 + include/hw/arm/allwinner-h3.h | 106 +++++++++++ hw/arm/allwinner-h3.c | 327 ++++++++++++++++++++++++++++++++ MAINTAINERS | 7 + hw/arm/Kconfig | 8 + hw/arm/Makefile.objs | 1 + 6 files changed, 450 insertions(+) create mode 100644 include/hw/arm/allwinner-h3.h create mode 100644 hw/arm/allwinner-h3.c
default-configs/arm-softmmu.mak +1 -0
@@ -41,3 +41,4 @@ CONFIG_FSL_IMX25=y CONFIG_FSL_IMX7=y CONFIG_FSL_IMX6UL=y CONFIG_SEMIHOSTING=y +CONFIG_ALLWINNER_H3=y
include/hw/arm/allwinner-h3.h new file +106 -0
106 lines not on this page · raw message
hw/arm/allwinner-h3.c new file +327 -0
327 lines not on this page · raw message
MAINTAINERS +7 -0
@@ -481,6 +481,13 @@ F: hw/*/allwinner* F: include/hw/*/allwinner* F: hw/arm/cubieboard.c +Allwinner-h3 +M: Niek Linnenbank <[email protected]> +L: [email protected] +S: Maintained +F: hw/*/allwinner-h3* +F: include/hw/*/allwinner-h3* + ARM PrimeCell and CMSDK devices M: Peter Maydell <[email protected]> L: [email protected]
hw/arm/Kconfig +8 -0
@@ -295,6 +295,14 @@ config ALLWINNER_A10 select SERIAL select UNIMP +config ALLWINNER_H3 + bool + select ALLWINNER_A10_PIT + select SERIAL + select ARM_TIMER + select ARM_GIC + select UNIMP + config RASPI bool select FRAMEBUFFER
hw/arm/Makefile.objs +1 -0
@@ -35,6 +35,7 @@ obj-$(CONFIG_DIGIC) += digic.o obj-$(CONFIG_OMAP) += omap1.o omap2.o obj-$(CONFIG_STRONGARM) += strongarm.o obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o +obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o obj-$(CONFIG_RASPI) += bcm2835_peripherals.o bcm2836.o raspi.o obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o obj-$(CONFIG_STM32F405_SOC) += stm32f405_soc.o
Signature · 1 line
2.17.1
Re: [PATCH v4 01/20] hw/arm: add Allwinner H3 System-on-Chip
Quoted 445 lines · Niek Linnenbank
The Allwinner H3 is a System on Chip containing four ARM Cortex A7 processor cores. Features and specifications include DDR2/DDR3 memory, SD/MMC storage cards, 10/100/1000Mbit Ethernet, USB 2.0, HDMI and various I/O modules. This commit adds support for the Allwinner H3 System on Chip.
Signed-off-by Niek Linnenbank <[email protected]>--- default-configs/arm-softmmu.mak | 1 + include/hw/arm/allwinner-h3.h | 106 +++++++++++ hw/arm/allwinner-h3.c | 327 ++++++++++++++++++++++++++++++++ MAINTAINERS | 7 + hw/arm/Kconfig | 8 + hw/arm/Makefile.objs | 1 + 6 files changed, 450 insertions(+)create mode 100644
include/hw/arm/allwinner-h3.hcreate mode 100644hw/arm/allwinner-h3.cdefault-configs/arm-softmmu.mak +1
-0@@ -41,3 +41,4 @@ CONFIG_FSL_IMX25=y CONFIG_FSL_IMX7=y CONFIG_FSL_IMX6UL=y CONFIG_SEMIHOSTING=y +CONFIG_ALLWINNER_H3=yinclude/hw/arm/allwinner-h3.h new file +106
-0@@ -0,0 +1,106 @@ +/* +* Allwinner H3 System on Chip emulation +* +* Copyright (C) 2019 Niek Linnenbank <[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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/* +* The Allwinner H3 is a System on Chip containing four ARM Cortex A7 +* processor cores. Features and specifications include DDR2/DDR3 memory, +* SD/MMC storage cards, 10/100/1000Mbit Ethernet, USB 2.0, HDMI and +* various I/O modules. +* +* This implementation is based on the following datasheet: +* +* https://linux-sunxi.org/File:Allwinner_H3_Datasheet_V1.2.pdf +* +* The latest datasheet and more info can be found on the Linux Sunxi wiki: +* +* https://linux-sunxi.org/H3 +*/ + +#ifndef HW_ARM_ALLWINNER_H3_H +#define HW_ARM_ALLWINNER_H3_H + +#include "qom/object.h" +#include "hw/arm/boot.h" +#include "hw/timer/allwinner-a10-pit.h" +#include "hw/intc/arm_gic.h" +#include "target/arm/cpu.h" + +/** +* Allwinner H3 device list +* +* This enumeration is can be used refer to a particular device in the +* Allwinner H3 SoC. For example, the physical memory base address for +* each device can be found in the AwH3State object in the memmap member +* using the device enum value as index. +* +* @see AwH3State +*/ +enum { +AW_H3_SRAM_A1 , +AW_H3_SRAM_A2 , +AW_H3_SRAM_C , +AW_H3_PIT , +AW_H3_UART0 , +AW_H3_UART1 , +AW_H3_UART2 , +AW_H3_UART3 , +AW_H3_GIC_DIST , +AW_H3_GIC_CPU , +AW_H3_GIC_HYP , +AW_H3_GIC_VCPU , +AW_H3_SDRAM +}; + +/** Total number of CPU cores in the H3 SoC */ +#define AW_H3_NUM_CPUS (4) + +/** +* Allwinner H3 object model +* @{ +*/ + +/** Object type for the Allwinner H3 SoC */ +#define TYPE_AW_H3 "allwinner-h3" + +/** Convert input object to Allwinner H3 state object */ +#define AW_H3 (obj) OBJECT_CHECK(AwH3State, (obj), TYPE_AW_H3) + +/** @} */ + +/** +* Allwinner H3 object +* +* This struct contains the state of all the devices +* which are currently emulated by the H3 SoC code. +*/ +typedef struct AwH3State { +/*< private >*/ +DeviceState parent_obj; +/*< public >*/ + +ARMCPU cpus[AW_H3_NUM_CPUS ]; +const hwaddr *memmap; +AwA10PITState timer; +GICState gic; +MemoryRegion sram_a1; +MemoryRegion sram_a2; +MemoryRegion sram_c; +}AwH3State ; + +#endif /* HW_ARM_ALLWINNER_H3_H */ hw/arm/allwinner-h3.c new file +300
-0@@ -0,0 +1,327 @@ +/* +* Allwinner H3 System on Chip emulation +* +* Copyright (C) 2019 Niek Linnenbank <[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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "exec/address-spaces.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "qemu/module.h" +#include "qemu/units.h" +#include "hw/qdev-core.h" +#include "cpu.h" +#include "hw/sysbus.h" +#include "hw/char/serial.h" +#include "hw/misc/unimp.h" +#include "sysemu/sysemu.h" +#include "hw/arm/allwinner-h3.h" + +/* Memory map */ +const hwaddr allwinner_h3_memmap[] = { + [AW_H3_SRAM_A1 ] =0x00000000 , + [AW_H3_SRAM_A2 ] =0x00044000 , + [AW_H3_SRAM_C ] =0x00010000 , + [AW_H3_PIT ] =0x01c20c00 , + [AW_H3_UART0 ] =0x01c28000 , + [AW_H3_UART1 ] =0x01c28400 , + [AW_H3_UART2 ] =0x01c28800 , + [AW_H3_UART3 ] =0x01c28c00 , + [AW_H3_GIC_DIST ] =0x01c81000 , + [AW_H3_GIC_CPU ] =0x01c82000 , + [AW_H3_GIC_HYP ] =0x01c84000 , + [AW_H3_GIC_VCPU ] =0x01c86000 , + [AW_H3_SDRAM ] =0x40000000 +}; + +/* List of unimplemented devices */ +struct AwH3Unimplemented { +const char *device_name; +hwaddr base; +hwaddr size; +} unimplemented[] = { + {"d-engine" ,0x01000000 ,4 * MiB }, + {"d-inter" ,0x01400000 ,128 * KiB }, + {"syscon" ,0x01c00000 ,4 * KiB }, + {"dma" ,0x01c02000 ,4 * KiB }, + {"nfdc" ,0x01c03000 ,4 * KiB }, + {"ts" ,0x01c06000 ,4 * KiB }, + {"keymem" ,0x01c0b000 ,4 * KiB }, + {"lcd0" ,0x01c0c000 ,4 * KiB }, + {"lcd1" ,0x01c0d000 ,4 * KiB }, + {"ve" ,0x01c0e000 ,4 * KiB }, + {"mmc0" ,0x01c0f000 ,4 * KiB }, + {"mmc1" ,0x01c10000 ,4 * KiB }, + {"mmc2" ,0x01c11000 ,4 * KiB }, + {"sid" ,0x01c14000 ,1 * KiB }, + {"crypto" ,0x01c15000 ,4 * KiB }, + {"msgbox" ,0x01c17000 ,4 * KiB }, + {"spinlock" ,0x01c18000 ,4 * KiB }, + {"usb0-otg" ,0x01c19000 ,4 * KiB }, + {"usb0" ,0x01c1a000 ,4 * KiB }, + {"usb1" ,0x01c1b000 ,4 * KiB }, + {"usb2" ,0x01c1c000 ,4 * KiB }, + {"usb3" ,0x01c1d000 ,4 * KiB }, + {"smc" ,0x01c1e000 ,4 * KiB }, + {"ccu" ,0x01c20000 ,1 * KiB }, + {"pio" ,0x01c20800 ,1 * KiB }, + {"owa" ,0x01c21000 ,1 * KiB }, + {"pwm" ,0x01c21400 ,1 * KiB }, + {"keyadc" ,0x01c21800 ,1 * KiB }, + {"pcm0" ,0x01c22000 ,1 * KiB }, + {"pcm1" ,0x01c22400 ,1 * KiB }, + {"pcm2" ,0x01c22800 ,1 * KiB }, + {"audio" ,0x01c22c00 ,2 * KiB }, + {"smta" ,0x01c23400 ,1 * KiB }, + {"ths" ,0x01c25000 ,1 * KiB }, + {"uart0" ,0x01c28000 ,1 * KiB }, + {"uart1" ,0x01c28400 ,1 * KiB }, + {"uart2" ,0x01c28800 ,1 * KiB }, + {"uart3" ,0x01c28c00 ,1 * KiB }, + {"twi0" ,0x01c2ac00 ,1 * KiB }, + {"twi1" ,0x01c2b000 ,1 * KiB }, + {"twi2" ,0x01c2b400 ,1 * KiB }, + {"scr" ,0x01c2c400 ,1 * KiB }, + {"emac" ,0x01c30000 ,64 * KiB }, + {"gpu" ,0x01c40000 ,64 * KiB }, + {"hstmr" ,0x01c60000 ,4 * KiB }, + {"dramcom" ,0x01c62000 ,4 * KiB }, + {"dramctl0" ,0x01c63000 ,4 * KiB }, + {"dramphy0" ,0x01c65000 ,4 * KiB }, + {"spi0" ,0x01c68000 ,4 * KiB }, + {"spi1" ,0x01c69000 ,4 * KiB }, + {"csi" ,0x01cb0000 ,320 * KiB }, + {"tve" ,0x01e00000 ,64 * KiB }, + {"hdmi" ,0x01ee0000 ,128 * KiB }, + {"rtc" ,0x01f00000 ,1 * KiB }, + {"r_timer" ,0x01f00800 ,1 * KiB }, + {"r_intc" ,0x01f00c00 ,1 * KiB }, + {"r_wdog" ,0x01f01000 ,1 * KiB }, + {"r_prcm" ,0x01f01400 ,1 * KiB }, + {"r_twd" ,0x01f01800 ,1 * KiB }, + {"r_cpucfg" ,0x01f01c00 ,1 * KiB }, + {"r_cir-rx" ,0x01f02000 ,1 * KiB }, + {"r_twi" ,0x01f02400 ,1 * KiB }, + {"r_uart" ,0x01f02800 ,1 * KiB }, + {"r_pio" ,0x01f02c00 ,1 * KiB }, + {"r_pwm" ,0x01f03800 ,1 * KiB }, + {"core-dbg" ,0x3f500000 ,128 * KiB }, + {"tsgen-ro" ,0x3f506000 ,4 * KiB }, + {"tsgen-ctl" ,0x3f507000 ,4 * KiB }, + {"ddr-mem" ,0x40000000 ,2 * GiB }, + {"n-brom" ,0xffff0000 ,32 * KiB }, + {"s-brom" ,0xffff0000 ,64 * KiB } +}; + +/* Per Processor Interrupts */ +enum { +AW_H3_GIC_PPI_MAINT =9 , +AW_H3_GIC_PPI_HYPTIMER =10 , +AW_H3_GIC_PPI_VIRTTIMER =11 , +AW_H3_GIC_PPI_SECTIMER =13 , +AW_H3_GIC_PPI_PHYSTIMER =14 +}; + +/* Shared Processor Interrupts */ +enum { +AW_H3_GIC_SPI_UART0 =0 , +AW_H3_GIC_SPI_UART1 =1 , +AW_H3_GIC_SPI_UART2 =2 , +AW_H3_GIC_SPI_UART3 =3 , +AW_H3_GIC_SPI_TIMER0 =18 , +AW_H3_GIC_SPI_TIMER1 =19 , +}; + +/* Allwinner H3 general constants */ +enum { +AW_H3_GIC_NUM_SPI =128 +}; + +static void allwinner_h3_init (Object *obj) +{ +AwH3State *s =AW_H3 (obj); + + s->memmap = allwinner_h3_memmap; + +for (int i =0 ; i <AW_H3_NUM_CPUS ; i++) { +object_initialize_child (obj,"cpu[*]" , &s->cpus[i],sizeof (s->cpus[i]), +ARM_CPU_TYPE_NAME ("cortex-a7" ), + &error_abort,NULL ); + } + +sysbus_init_child_obj (obj,"gic" , &s->gic,sizeof (s->gic), +TYPE_ARM_GIC ); + +sysbus_init_child_obj (obj,"timer" , &s->timer,sizeof (s->timer), +TYPE_AW_A10_PIT ); +object_property_add_alias (obj,"clk0-freq" ,OBJECT (&s->timer), +"clk0-freq" , &error_abort); +object_property_add_alias (obj,"clk1-freq" ,OBJECT (&s->timer), +"clk1-freq" , &error_abort); +} + +static void allwinner_h3_realize (DeviceState *dev,Error **errp) +{ +AwH3State *s =AW_H3 (dev); +unsigned i; + +/* CPUs */ +for (i =0 ; i <AW_H3_NUM_CPUS ; i++) { + +/* Provide Power State Coordination Interface */ +qdev_prop_set_int32 (DEVICE (&s->cpus[i]),"psci-conduit" , +QEMU_PSCI_CONDUIT_HVC ); + +/* Disable secondary CPUs */ +qdev_prop_set_bit (DEVICE (&s->cpus[i]),"start-powered-off" , + i >0 ); + +/* All exception levels required */ +qdev_prop_set_bit (DEVICE (&s->cpus[i]),"has_el3" , true); +qdev_prop_set_bit (DEVICE (&s->cpus[i]),"has_el2" , true); + +/* Mark realized */ +qdev_init_nofail (DEVICE (&s->cpus[i])); + } + +/* Generic Interrupt Controller */ +qdev_prop_set_uint32 (DEVICE (&s->gic),"num-irq" ,AW_H3_GIC_NUM_SPI + +GIC_INTERNAL ); +qdev_prop_set_uint32 (DEVICE (&s->gic),"revision" ,2 ); +qdev_prop_set_uint32 (DEVICE (&s->gic),"num-cpu" ,AW_H3_NUM_CPUS ); +qdev_prop_set_bit (DEVICE (&s->gic),"has-security-extensions" , false); +qdev_prop_set_bit (DEVICE (&s->gic),"has-virtualization-extensions" , true); +qdev_init_nofail (DEVICE (&s->gic)); + +sysbus_mmio_map (SYS_BUS_DEVICE (&s->gic),0 , s->memmap[AW_H3_GIC_DIST ]); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->gic),1 , s->memmap[AW_H3_GIC_CPU ]); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->gic),2 , s->memmap[AW_H3_GIC_HYP ]); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->gic),3 , s->memmap[AW_H3_GIC_VCPU ]); + +/* +* Wire the outputs from each CPU's generic timer and the GICv3 +* maintenance interrupt signal to the appropriate GIC PPI inputs, +* and the GIC's IRQ/FIQ/VIRQ/VFIQ interrupt outputs to the CPU's inputs. +*/ +for (i =0 ; i <AW_H3_NUM_CPUS ; i++) { +DeviceState *cpudev =DEVICE (&s->cpus[i]); +int ppibase =AW_H3_GIC_NUM_SPI + i *GIC_INTERNAL +GIC_NR_SGIS ; +int irq; +/* +* Mapping from the output timer irq lines from the CPU to the +* GIC PPI inputs used for this board. +*/ +const int timer_irq[] = { + [GTIMER_PHYS ] =AW_H3_GIC_PPI_PHYSTIMER , + [GTIMER_VIRT ] =AW_H3_GIC_PPI_VIRTTIMER , + [GTIMER_HYP ] =AW_H3_GIC_PPI_HYPTIMER , + [GTIMER_SEC ] =AW_H3_GIC_PPI_SECTIMER , + }; + +/* Connect CPU timer outputs to GIC PPI inputs */ +for (irq =0 ; irq <ARRAY_SIZE (timer_irq); irq++) { +qdev_connect_gpio_out (cpudev, irq, +qdev_get_gpio_in (DEVICE (&s->gic), + ppibase + timer_irq[irq])); + } + +/* Connect GIC outputs to CPU interrupt inputs */ +sysbus_connect_irq (SYS_BUS_DEVICE (&s->gic), i, +qdev_get_gpio_in (cpudev,ARM_CPU_IRQ )); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->gic), i +AW_H3_NUM_CPUS , +qdev_get_gpio_in (cpudev,ARM_CPU_FIQ )); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->gic), i + (2 *AW_H3_NUM_CPUS ), +qdev_get_gpio_in (cpudev,ARM_CPU_VIRQ )); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->gic), i + (3 *AW_H3_NUM_CPUS ), +qdev_get_gpio_in (cpudev,ARM_CPU_VFIQ )); + +/* GIC maintenance signal */ +sysbus_connect_irq (SYS_BUS_DEVICE (&s->gic), i + (4 *AW_H3_NUM_CPUS ), +qdev_get_gpio_in (DEVICE (&s->gic), + ppibase +AW_H3_GIC_PPI_MAINT )); + } + +/* Timer */ +qdev_init_nofail (DEVICE (&s->timer)); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->timer),0 , s->memmap[AW_H3_PIT ]); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->timer),0 , +qdev_get_gpio_in (DEVICE (&s->gic),AW_H3_GIC_SPI_TIMER0 )); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->timer),1 , +qdev_get_gpio_in (DEVICE (&s->gic),AW_H3_GIC_SPI_TIMER1 )); + +/* SRAM */ +memory_region_init_ram (&s->sram_a1,OBJECT (dev),"sram A1" , +64 * KiB, &error_abort); +memory_region_init_ram (&s->sram_a2,OBJECT (dev),"sram A2" , +32 * KiB, &error_abort); +memory_region_init_ram (&s->sram_c,OBJECT (dev),"sram C" , +44 * KiB, &error_abort); +memory_region_add_subregion (get_system_memory (), s->memmap[AW_H3_SRAM_A1 ], + &s->sram_a1); +memory_region_add_subregion (get_system_memory (), s->memmap[AW_H3_SRAM_A2 ], + &s->sram_a2); +memory_region_add_subregion (get_system_memory (), s->memmap[AW_H3_SRAM_C ], + &s->sram_c); + +/* UART0. For future clocktree API: All UARTS are connected to APB2_CLK. */ +serial_mm_init (get_system_memory (), s->memmap[AW_H3_UART0 ],2 , +qdev_get_gpio_in (DEVICE (&s->gic),AW_H3_GIC_SPI_UART0 ), +115200 ,serial_hd (0 ),DEVICE_NATIVE_ENDIAN ); +/* UART1 */ +serial_mm_init (get_system_memory (), s->memmap[AW_H3_UART1 ],2 , +qdev_get_gpio_in (DEVICE (&s->gic),AW_H3_GIC_SPI_UART1 ), +115200 ,serial_hd (1 ),DEVICE_NATIVE_ENDIAN ); +/* UART2 */ +serial_mm_init (get_system_memory (), s->memmap[AW_H3_UART2 ],2 , +qdev_get_gpio_in (DEVICE (&s->gic),AW_H3_GIC_SPI_UART2 ), +115200 ,serial_hd (2 ),DEVICE_NATIVE_ENDIAN ); +/* UART3 */ +serial_mm_init (get_system_memory (), s->memmap[AW_H3_UART3 ],2 , +qdev_get_gpio_in (DEVICE (&s->gic),AW_H3_GIC_SPI_UART3 ), +115200 ,serial_hd (3 ),DEVICE_NATIVE_ENDIAN ); + +/* Unimplemented devices */ +for (i =0 ; i <ARRAY_SIZE (unimplemented); i++) { + create_unimplemented_device(unimplemented[i].device_name, + unimplemented[i].base,
hw/arm/allwinner-h3.c line 310
Quoted 10 lines
hw/arm/allwinner-h3.c new file +10
-0+ unimplemented[i].size); + } +} + +static void allwinner_h3_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + + dc->realize = allwinner_h3_realize; +/* Reason: uses serial_hds and nd_table */
Maybe use "serial_hd()". Also nd_table is not used yet.
Quoted 40 lines
hw/arm/allwinner-h3.c new file +17
-0+ dc->user_creatable = false; +} + +static const TypeInfo allwinner_h3_type_info = { + .name =TYPE_AW_H3 , + .parent =TYPE_DEVICE , + .instance_size =sizeof (AwH3State), + .instance_init = allwinner_h3_init, + .class_init = allwinner_h3_class_init, +}; + +static void allwinner_h3_register_types (void ) +{ +type_register_static (&allwinner_h3_type_info); +} + +type_init (allwinner_h3_register_types)MAINTAINERS +7
-0@@ -481,6 +481,13 @@ F: hw/*/allwinner* F: include/hw/*/allwinner* F: hw/arm/cubieboard.c +Allwinner-h3 +M: Niek Linnenbank <[email protected]> +L: [email protected] +S: Maintained +F: hw/*/allwinner-h3* +F: include/hw/*/allwinner-h3* + ARM PrimeCell and CMSDK devices M: Peter Maydell <[email protected]> L: [email protected]hw/arm/Kconfig +0
-0
hw/arm/Kconfig config ALLWINNER_A10 · line 300
Quoted 6 lines
hw/arm/Kconfig +3
-0@@ -295,6 +295,14 @@ config ALLWINNER_A10 select SERIAL select UNIMP +config ALLWINNER_H3 + bool + select ALLWINNER_A10_PIT
We should now rename this as ALLWINNER_PIT.
Quoted 14 lines
hw/arm/Kconfig +5
-0+ select SERIAL + select ARM_TIMER + select ARM_GIC + select UNIMP + config RASPI bool select FRAMEBUFFERhw/arm/Makefile.objs +0
-0
hw/arm/Makefile.objs obj-$(CONFIG_DIGIC) += digic.o · line 41
Quoted 7 lines
hw/arm/Makefile.objs +1
-0@@ -35,6 +35,7 @@ obj-$(CONFIG_DIGIC) += digic.o obj-$(CONFIG_OMAP) += omap1.o omap2.o obj-$(CONFIG_STRONGARM) += strongarm.o obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o +obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o obj-$(CONFIG_RASPI) += bcm2835_peripherals.o bcm2836.o raspi.o obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o obj-$(CONFIG_STM32F405_SOC) += stm32f405_soc.o
Patch very clean!
Re: [PATCH v4 01/20] hw/arm: add Allwinner H3 System-on-Chip
Hi Philippe,
I just got back from traveling and will start processing these and the other comments soon.
Quoted 480 lines · Philippe Mathieu-Daudé
Quoted 15 lines · Niek Linnenbank
The Allwinner H3 is a System on Chip containing four ARM Cortex A7 processor cores. Features and specifications include DDR2/DDR3 memory, SD/MMC storage cards, 10/100/1000Mbit Ethernet, USB 2.0, HDMI and various I/O modules. This commit adds support for the Allwinner H3 System on Chip.
Signed-off-by Niek Linnenbank <[email protected]>--- default-configs/arm-softmmu.mak | 1 + include/hw/arm/allwinner-h3.h | 106 +++++++++++ hw/arm/allwinner-h3.c | 327 ++++++++++++++++++++++++++++++++ MAINTAINERS | 7 + hw/arm/Kconfig | 8 + hw/arm/Makefile.objs | 1 + 6 files changed, 450 insertions(+)Review
Quoted 4 lines
create mode 100644
include/hw/arm/allwinner-h3.hcreate mode 100644hw/arm/allwinner-h3.c(quoted diff) +0
-0b/default-configs/arm-softmmu.mak
Review
Quoted 9 lines
index
645e6201bb..36a0e89daa100644default-configs/arm-softmmu.mak +1
-0@@ -41,3 +41,4 @@ CONFIG_FSL_IMX25=y CONFIG_FSL_IMX7=y CONFIG_FSL_IMX6UL=y CONFIG_SEMIHOSTING=y +CONFIG_ALLWINNER_H3=y(quoted diff) +0
-0
b/include/hw/arm/allwinner-h3.hQuoted 24 lines
new file mode 100644
index 0000000000..2aac9b78ecinclude/hw/arm/allwinner-h3.h new file +17
-0@@ -0,0 +1,106 @@ +/* +* Allwinner H3 System on Chip emulation +* +* Copyright (C) 2019 Niek Linnenbank <[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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/ .
+ */include/hw/arm/allwinner-h3.h
Quoted 4 lines
include/hw/arm/allwinner-h3.h new file +4
-0+ +/* +* The Allwinner H3 is a System on Chip containing four ARM Cortex A7 +* processor cores. Features and specifications include DDR2/DDR3 memory,
Quoted 8 lines
+ * SD/MMC storage cards, 10/100/1000Mbit Ethernet, USB 2.0, HDMI and
+ * various I/O modules.
+ *
+ * This implementation is based on the following datasheet:
+ *
+ * https://linux-sunxi.org/File:Allwinner_H3_Datasheet_V1.2.pdf
+ *
+ * The latest datasheet and more info can be found on the Linux Sunxiwiki:
Quoted 234 lines
+ *
+ * https://linux-sunxi.org/H3
+ */include/hw/arm/allwinner-h3.h new file +73
-0+ +#ifndef HW_ARM_ALLWINNER_H3_H +#define HW_ARM_ALLWINNER_H3_H + +#include "qom/object.h" +#include "hw/arm/boot.h" +#include "hw/timer/allwinner-a10-pit.h" +#include "hw/intc/arm_gic.h" +#include "target/arm/cpu.h" + +/** +* Allwinner H3 device list +* +* This enumeration is can be used refer to a particular device in the +* Allwinner H3 SoC. For example, the physical memory base address for +* each device can be found in the AwH3State object in the memmap member +* using the device enum value as index. +* +* @see AwH3State +*/ +enum { +AW_H3_SRAM_A1 , +AW_H3_SRAM_A2 , +AW_H3_SRAM_C , +AW_H3_PIT , +AW_H3_UART0 , +AW_H3_UART1 , +AW_H3_UART2 , +AW_H3_UART3 , +AW_H3_GIC_DIST , +AW_H3_GIC_CPU , +AW_H3_GIC_HYP , +AW_H3_GIC_VCPU , +AW_H3_SDRAM +}; + +/** Total number of CPU cores in the H3 SoC */ +#define AW_H3_NUM_CPUS (4) + +/** +* Allwinner H3 object model +* @{ +*/ + +/** Object type for the Allwinner H3 SoC */ +#define TYPE_AW_H3 "allwinner-h3" + +/** Convert input object to Allwinner H3 state object */ +#define AW_H3 (obj) OBJECT_CHECK(AwH3State, (obj), TYPE_AW_H3) + +/** @} */ + +/** +* Allwinner H3 object +* +* This struct contains the state of all the devices +* which are currently emulated by the H3 SoC code. +*/ +typedef struct AwH3State { +/*< private >*/ +DeviceState parent_obj; +/*< public >*/ + +ARMCPU cpus[AW_H3_NUM_CPUS ]; +const hwaddr *memmap; +AwA10PITState timer; +GICState gic; +MemoryRegion sram_a1; +MemoryRegion sram_a2; +MemoryRegion sram_c; +}AwH3State ; + +#endif /* HW_ARM_ALLWINNER_H3_H */ hw/arm/allwinner-h3.c new file +17
-0@@ -0,0 +1,327 @@ +/* +* Allwinner H3 System on Chip emulation +* +* Copyright (C) 2019 Niek Linnenbank <[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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/ .
+ */hw/arm/allwinner-h3.c new file +133
-0+ +#include "qemu/osdep.h" +#include "exec/address-spaces.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "qemu/module.h" +#include "qemu/units.h" +#include "hw/qdev-core.h" +#include "cpu.h" +#include "hw/sysbus.h" +#include "hw/char/serial.h" +#include "hw/misc/unimp.h" +#include "sysemu/sysemu.h" +#include "hw/arm/allwinner-h3.h" + +/* Memory map */ +const hwaddr allwinner_h3_memmap[] = { + [AW_H3_SRAM_A1 ] =0x00000000 , + [AW_H3_SRAM_A2 ] =0x00044000 , + [AW_H3_SRAM_C ] =0x00010000 , + [AW_H3_PIT ] =0x01c20c00 , + [AW_H3_UART0 ] =0x01c28000 , + [AW_H3_UART1 ] =0x01c28400 , + [AW_H3_UART2 ] =0x01c28800 , + [AW_H3_UART3 ] =0x01c28c00 , + [AW_H3_GIC_DIST ] =0x01c81000 , + [AW_H3_GIC_CPU ] =0x01c82000 , + [AW_H3_GIC_HYP ] =0x01c84000 , + [AW_H3_GIC_VCPU ] =0x01c86000 , + [AW_H3_SDRAM ] =0x40000000 +}; + +/* List of unimplemented devices */ +struct AwH3Unimplemented { +const char *device_name; +hwaddr base; +hwaddr size; +} unimplemented[] = { + {"d-engine" ,0x01000000 ,4 * MiB }, + {"d-inter" ,0x01400000 ,128 * KiB }, + {"syscon" ,0x01c00000 ,4 * KiB }, + {"dma" ,0x01c02000 ,4 * KiB }, + {"nfdc" ,0x01c03000 ,4 * KiB }, + {"ts" ,0x01c06000 ,4 * KiB }, + {"keymem" ,0x01c0b000 ,4 * KiB }, + {"lcd0" ,0x01c0c000 ,4 * KiB }, + {"lcd1" ,0x01c0d000 ,4 * KiB }, + {"ve" ,0x01c0e000 ,4 * KiB }, + {"mmc0" ,0x01c0f000 ,4 * KiB }, + {"mmc1" ,0x01c10000 ,4 * KiB }, + {"mmc2" ,0x01c11000 ,4 * KiB }, + {"sid" ,0x01c14000 ,1 * KiB }, + {"crypto" ,0x01c15000 ,4 * KiB }, + {"msgbox" ,0x01c17000 ,4 * KiB }, + {"spinlock" ,0x01c18000 ,4 * KiB }, + {"usb0-otg" ,0x01c19000 ,4 * KiB }, + {"usb0" ,0x01c1a000 ,4 * KiB }, + {"usb1" ,0x01c1b000 ,4 * KiB }, + {"usb2" ,0x01c1c000 ,4 * KiB }, + {"usb3" ,0x01c1d000 ,4 * KiB }, + {"smc" ,0x01c1e000 ,4 * KiB }, + {"ccu" ,0x01c20000 ,1 * KiB }, + {"pio" ,0x01c20800 ,1 * KiB }, + {"owa" ,0x01c21000 ,1 * KiB }, + {"pwm" ,0x01c21400 ,1 * KiB }, + {"keyadc" ,0x01c21800 ,1 * KiB }, + {"pcm0" ,0x01c22000 ,1 * KiB }, + {"pcm1" ,0x01c22400 ,1 * KiB }, + {"pcm2" ,0x01c22800 ,1 * KiB }, + {"audio" ,0x01c22c00 ,2 * KiB }, + {"smta" ,0x01c23400 ,1 * KiB }, + {"ths" ,0x01c25000 ,1 * KiB }, + {"uart0" ,0x01c28000 ,1 * KiB }, + {"uart1" ,0x01c28400 ,1 * KiB }, + {"uart2" ,0x01c28800 ,1 * KiB }, + {"uart3" ,0x01c28c00 ,1 * KiB }, + {"twi0" ,0x01c2ac00 ,1 * KiB }, + {"twi1" ,0x01c2b000 ,1 * KiB }, + {"twi2" ,0x01c2b400 ,1 * KiB }, + {"scr" ,0x01c2c400 ,1 * KiB }, + {"emac" ,0x01c30000 ,64 * KiB }, + {"gpu" ,0x01c40000 ,64 * KiB }, + {"hstmr" ,0x01c60000 ,4 * KiB }, + {"dramcom" ,0x01c62000 ,4 * KiB }, + {"dramctl0" ,0x01c63000 ,4 * KiB }, + {"dramphy0" ,0x01c65000 ,4 * KiB }, + {"spi0" ,0x01c68000 ,4 * KiB }, + {"spi1" ,0x01c69000 ,4 * KiB }, + {"csi" ,0x01cb0000 ,320 * KiB }, + {"tve" ,0x01e00000 ,64 * KiB }, + {"hdmi" ,0x01ee0000 ,128 * KiB }, + {"rtc" ,0x01f00000 ,1 * KiB }, + {"r_timer" ,0x01f00800 ,1 * KiB }, + {"r_intc" ,0x01f00c00 ,1 * KiB }, + {"r_wdog" ,0x01f01000 ,1 * KiB }, + {"r_prcm" ,0x01f01400 ,1 * KiB }, + {"r_twd" ,0x01f01800 ,1 * KiB }, + {"r_cpucfg" ,0x01f01c00 ,1 * KiB }, + {"r_cir-rx" ,0x01f02000 ,1 * KiB }, + {"r_twi" ,0x01f02400 ,1 * KiB }, + {"r_uart" ,0x01f02800 ,1 * KiB }, + {"r_pio" ,0x01f02c00 ,1 * KiB }, + {"r_pwm" ,0x01f03800 ,1 * KiB }, + {"core-dbg" ,0x3f500000 ,128 * KiB }, + {"tsgen-ro" ,0x3f506000 ,4 * KiB }, + {"tsgen-ctl" ,0x3f507000 ,4 * KiB }, + {"ddr-mem" ,0x40000000 ,2 * GiB }, + {"n-brom" ,0xffff0000 ,32 * KiB }, + {"s-brom" ,0xffff0000 ,64 * KiB } +}; + +/* Per Processor Interrupts */ +enum { +AW_H3_GIC_PPI_MAINT =9 , +AW_H3_GIC_PPI_HYPTIMER =10 , +AW_H3_GIC_PPI_VIRTTIMER =11 , +AW_H3_GIC_PPI_SECTIMER =13 , +AW_H3_GIC_PPI_PHYSTIMER =14 +}; + +/* Shared Processor Interrupts */ +enum { +AW_H3_GIC_SPI_UART0 =0 , +AW_H3_GIC_SPI_UART1 =1 , +AW_H3_GIC_SPI_UART2 =2 , +AW_H3_GIC_SPI_UART3 =3 , +AW_H3_GIC_SPI_TIMER0 =18 , +AW_H3_GIC_SPI_TIMER1 =19 , +}; + +/* Allwinner H3 general constants */ +enum { +AW_H3_GIC_NUM_SPI =128 hw/arm/allwinner-h3.c
Quoted 10 lines
hw/arm/allwinner-h3.c new file +10
-0+}; + +static void allwinner_h3_init (Object *obj) +{ +AwH3State *s =AW_H3 (obj); + + s->memmap = allwinner_h3_memmap; + +for (int i =0 ; i <AW_H3_NUM_CPUS ; i++) { + object_initialize_child(obj, "cpu[*]", &s->cpus[i],
sizeof(s->cpus[i]),Quoted 35 lines
hw/arm/allwinner-h3.c new file +35
-0+ARM_CPU_TYPE_NAME ("cortex-a7" ), + &error_abort, NULL); + } + +sysbus_init_child_obj (obj,"gic" , &s->gic,sizeof (s->gic), +TYPE_ARM_GIC ); + +sysbus_init_child_obj (obj,"timer" , &s->timer,sizeof (s->timer), +TYPE_AW_A10_PIT ); +object_property_add_alias (obj,"clk0-freq" ,OBJECT (&s->timer), +"clk0-freq" , &error_abort); +object_property_add_alias (obj,"clk1-freq" ,OBJECT (&s->timer), +"clk1-freq" , &error_abort); +} + +static void allwinner_h3_realize (DeviceState *dev,Error **errp) +{ +AwH3State *s =AW_H3 (dev); +unsigned i; + +/* CPUs */ +for (i =0 ; i <AW_H3_NUM_CPUS ; i++) { + +/* Provide Power State Coordination Interface */ +qdev_prop_set_int32 (DEVICE (&s->cpus[i]),"psci-conduit" , +QEMU_PSCI_CONDUIT_HVC ); + +/* Disable secondary CPUs */ +qdev_prop_set_bit (DEVICE (&s->cpus[i]),"start-powered-off" , + i >0 ); + +/* All exception levels required */ +qdev_prop_set_bit (DEVICE (&s->cpus[i]),"has_el3" , true); +qdev_prop_set_bit (DEVICE (&s->cpus[i]),"has_el2" , true); +hw/arm/allwinner-h3.c
Quoted 10 lines
hw/arm/allwinner-h3.c new file +10
-0+/* Mark realized */ +qdev_init_nofail (DEVICE (&s->cpus[i])); + } + +/* Generic Interrupt Controller */ +qdev_prop_set_uint32 (DEVICE (&s->gic),"num-irq" ,AW_H3_GIC_NUM_SPI + +GIC_INTERNAL ); +qdev_prop_set_uint32 (DEVICE (&s->gic),"revision" ,2 ); +qdev_prop_set_uint32 (DEVICE (&s->gic),"num-cpu" ,AW_H3_NUM_CPUS ); + qdev_prop_set_bit(DEVICE(&s->gic), "has-security-extensions",false);
Quoted 1 line
+ qdev_prop_set_bit(DEVICE(&s->gic), "has-virtualization-extensions",
true);
hw/arm/allwinner-h3.c
Quoted 3 lines
hw/arm/allwinner-h3.c new file +3
-0+qdev_init_nofail (DEVICE (&s->gic)); + + sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 0,s->memmap[AW_H3_GIC_DIST]);
Quoted 1 line
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 1,
s->memmap[AW_H3_GIC_CPU]);
Quoted 1 line
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 2,
s->memmap[AW_H3_GIC_HYP]);
Quoted 1 line
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 3,
s->memmap[AW_H3_GIC_VCPU]);
hw/arm/allwinner-h3.c
Quoted 5 lines
hw/arm/allwinner-h3.c new file +5
-0+ +/* +* Wire the outputs from each CPU's generic timer and the GICv3 +* maintenance interrupt signal to the appropriate GIC PPI inputs, +* and the GIC's IRQ/FIQ/VIRQ/VFIQ interrupt outputs to the CPU's inputs.
hw/arm/allwinner-h3.c
Quoted 4 lines
hw/arm/allwinner-h3.c new file +4
-0+*/ +for (i =0 ; i <AW_H3_NUM_CPUS ; i++) { +DeviceState *cpudev =DEVICE (&s->cpus[i]); + int ppibase = AW_H3_GIC_NUM_SPI + i * GIC_INTERNAL +
GIC_NR_SGIS;Quoted 7 lines
hw/arm/allwinner-h3.c new file +7
-0+int irq; +/* +* Mapping from the output timer irq lines from the CPU to the +* GIC PPI inputs used for this board. +*/ +const int timer_irq[] = { + [GTIMER_PHYS ] =AW_H3_GIC_PPI_PHYSTIMER ,hw/arm/allwinner-h3.c
Quoted 10 lines
hw/arm/allwinner-h3.c new file +10
-0+ [GTIMER_VIRT] = AW_H3_GIC_PPI_VIRTTIMER, + [GTIMER_HYP] = AW_H3_GIC_PPI_HYPTIMER, + [GTIMER_SEC] = AW_H3_GIC_PPI_SECTIMER, + }; + +/* Connect CPU timer outputs to GIC PPI inputs */ +for (irq =0 ; irq <ARRAY_SIZE (timer_irq); irq++) { + qdev_connect_gpio_out(cpudev, irq, + qdev_get_gpio_in(DEVICE(&s->gic), + ppibase +timer_irq[irq]));
hw/arm/allwinner-h3.c
Quoted 8 lines
hw/arm/allwinner-h3.c new file +8
-0+ } + +/* Connect GIC outputs to CPU interrupt inputs */ +sysbus_connect_irq (SYS_BUS_DEVICE (&s->gic), i, +qdev_get_gpio_in (cpudev,ARM_CPU_IRQ )); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->gic), i +AW_H3_NUM_CPUS , +qdev_get_gpio_in (cpudev,ARM_CPU_FIQ )); + sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + (2 *
AW_H3_NUM_CPUS),hw/arm/allwinner-h3.c
Quoted 2 lines
hw/arm/allwinner-h3.c new file +2
-0+ qdev_get_gpio_in(cpudev, ARM_CPU_VIRQ)); + sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + (3 *
AW_H3_NUM_CPUS),hw/arm/allwinner-h3.c
Quoted 4 lines
hw/arm/allwinner-h3.c new file +4
-0+ qdev_get_gpio_in(cpudev, ARM_CPU_VFIQ)); + +/* GIC maintenance signal */ + sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + (4 *
AW_H3_NUM_CPUS),hw/arm/allwinner-h3.c
Quoted 2 lines
hw/arm/allwinner-h3.c new file +2
-0+ qdev_get_gpio_in(DEVICE(&s->gic), + ppibase +
AW_H3_GIC_PPI_MAINT));hw/arm/allwinner-h3.c
Quoted 7 lines
hw/arm/allwinner-h3.c new file +7
-0+ } + +/* Timer */ +qdev_init_nofail (DEVICE (&s->timer)); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->timer),0 , s->memmap[AW_H3_PIT ]); + sysbus_connect_irq(SYS_BUS_DEVICE(&s->timer), 0, + qdev_get_gpio_in(DEVICE(&s->gic),
AW_H3_GIC_SPI_TIMER0));hw/arm/allwinner-h3.c
Quoted 2 lines
hw/arm/allwinner-h3.c new file +2
-0+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->timer), 1, + qdev_get_gpio_in(DEVICE(&s->gic),
AW_H3_GIC_SPI_TIMER1));hw/arm/allwinner-h3.c
Quoted 9 lines
hw/arm/allwinner-h3.c new file +9
-0+ +/* SRAM */ +memory_region_init_ram (&s->sram_a1,OBJECT (dev),"sram A1" , +64 * KiB, &error_abort); +memory_region_init_ram (&s->sram_a2,OBJECT (dev),"sram A2" , +32 * KiB, &error_abort); +memory_region_init_ram (&s->sram_c,OBJECT (dev),"sram C" , +44 * KiB, &error_abort); + memory_region_add_subregion(get_system_memory(),s->memmap[AW_H3_SRAM_A1],
hw/arm/allwinner-h3.c
Quoted 2 lines
hw/arm/allwinner-h3.c new file +2
-0+ &s->sram_a1); + memory_region_add_subregion(get_system_memory(),s->memmap[AW_H3_SRAM_A2],
hw/arm/allwinner-h3.c
Quoted 2 lines
hw/arm/allwinner-h3.c new file +2
-0+ &s->sram_a2); + memory_region_add_subregion(get_system_memory(),s->memmap[AW_H3_SRAM_C],
hw/arm/allwinner-h3.c
Quoted 3 lines
hw/arm/allwinner-h3.c new file +3
-0+ &s->sram_c); + +/* UART0. For future clocktree API: All UARTS are connected to
APB2_CLK. */hw/arm/allwinner-h3.c
Quoted 2 lines
hw/arm/allwinner-h3.c new file +2
-0+ serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART0], 2, + qdev_get_gpio_in(DEVICE(&s->gic),
AW_H3_GIC_SPI_UART0),hw/arm/allwinner-h3.c
Quoted 4 lines
hw/arm/allwinner-h3.c new file +4
-0+ 115200, serial_hd(0), DEVICE_NATIVE_ENDIAN); +/* UART1 */ + serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART1], 2, + qdev_get_gpio_in(DEVICE(&s->gic),
AW_H3_GIC_SPI_UART1),hw/arm/allwinner-h3.c
Quoted 4 lines
hw/arm/allwinner-h3.c new file +4
-0+ 115200, serial_hd(1), DEVICE_NATIVE_ENDIAN); +/* UART2 */ + serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART2], 2, + qdev_get_gpio_in(DEVICE(&s->gic),
AW_H3_GIC_SPI_UART2),hw/arm/allwinner-h3.c
Quoted 4 lines
hw/arm/allwinner-h3.c new file +4
-0+ 115200, serial_hd(2), DEVICE_NATIVE_ENDIAN); +/* UART3 */ + serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART3], 2, + qdev_get_gpio_in(DEVICE(&s->gic),
AW_H3_GIC_SPI_UART3),Quoted 10 lines
hw/arm/allwinner-h3.c new file +10
-0+ 115200, serial_hd(3), DEVICE_NATIVE_ENDIAN); + +/* Unimplemented devices */ +for (i =0 ; i <ARRAY_SIZE (unimplemented); i++) { +create_unimplemented_device (unimplemented[i].device_name, + unimplemented[i].base, + unimplemented[i].size); + } +} +
Quoted 9 lines
hw/arm/allwinner-h3.c line 310
Quoted 6 lines
hw/arm/allwinner-h3.c new file +6
-0+static void allwinner_h3_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + + dc->realize = allwinner_h3_realize; +/* Reason: uses serial_hds and nd_table */ Maybe use "
serial_hd()". Alsond_tableis not used yet.
Thanks, this comment was outdated indeed, I'll correct it.
Quoted 44 lines
Quoted 44 lines
hw/arm/allwinner-h3.c new file +17
-0+ dc->user_creatable = false; +} + +static const TypeInfo allwinner_h3_type_info = { + .name =TYPE_AW_H3 , + .parent =TYPE_DEVICE , + .instance_size =sizeof (AwH3State), + .instance_init = allwinner_h3_init, + .class_init = allwinner_h3_class_init, +}; + +static void allwinner_h3_register_types (void ) +{ +type_register_static (&allwinner_h3_type_info); +} + +type_init (allwinner_h3_register_types)MAINTAINERS +7
-0@@ -481,6 +481,13 @@ F: hw/*/allwinner* F: include/hw/*/allwinner* F: hw/arm/cubieboard.c +Allwinner-h3 +M: Niek Linnenbank <[email protected]> +L: [email protected] +S: Maintained +F: hw/*/allwinner-h3* +F: include/hw/*/allwinner-h3* + ARM PrimeCell and CMSDK devices M: Peter Maydell <[email protected]> L: [email protected]hw/arm/Kconfig +0
-0@@ -295,6 +295,14 @@ config ALLWINNER_A10 select SERIAL select UNIMP
Quoted 6 lines
hw/arm/Kconfig config ALLWINNER_A10 · line 300
Quoted 3 lines
hw/arm/Kconfig +3
-0+config ALLWINNER_H3 + bool + select ALLWINNER_A10_PITWe should now rename this as
ALLWINNER_PIT.
I see your point, now both SoCs are using the A10 specific PIT timer. Previously we agreed to do the generalization of that timer in a separate patch series.
I think it makes sense to also do the rename of this item as part of that separate series.
Quoted 25 lines
Quoted 15 lines
hw/arm/Kconfig +5
-0+ select SERIAL + select ARM_TIMER + select ARM_GIC + select UNIMP + config RASPI bool select FRAMEBUFFERhw/arm/Makefile.objs +0
-0hw/arm/Makefile.objs obj-$(CONFIG_DIGIC) += digic.o · line 41
Quoted 7 lines
hw/arm/Makefile.objs +1
-0@@ -35,6 +35,7 @@ obj-$(CONFIG_DIGIC) += digic.o obj-$(CONFIG_OMAP) += omap1.o omap2.o obj-$(CONFIG_STRONGARM) += strongarm.o obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o +obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o obj-$(CONFIG_RASPI) += bcm2835_peripherals.o bcm2836.o raspi.o obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o obj-$(CONFIG_STM32F405_SOC) += stm32f405_soc.oPatch very clean!
Quoted 4 lines
Reviewed-by Philippe Mathieu-Daudé <[email protected]>Thanks for reviewing Philippe!
Regards,
Niek
Signature · 1 line
Niek Linnenbank
Re: [PATCH v4 01/20] hw/arm: add Allwinner H3 System-on-Chip
Quoted 18 lines · Niek Linnenbank
Hi Philippe,
I just got back from traveling and will start processing these and the other comments soon.
On Sun, Jan 19, 2020 at 7:01 PM Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:
On 1/19/20 1:50 AM, Niek Linnenbank wrote:
> The Allwinner H3 is a System on Chip containing four ARM Cortex A7 > processor cores. Features and specifications include DDR2/DDR3 memory, > SD/MMC storage cards, 10/100/1000Mbit Ethernet, USB 2.0, HDMI and > various I/O modules. This commit adds support for the Allwinner H3 > System on Chip.
>
> Signed-off-by: Niek Linnenbank <[email protected] <mailto:[email protected]>>
> ---
[...]
Quoted 15 lines
Quoted 11 lines
hw/arm/Kconfig +0
-0@@ -295,6 +295,14 @@ config ALLWINNER_A10select SERIAL
select UNIMP
+configALLWINNER_H3
+ bool
+ selectALLWINNER_A10_PITWe should now rename this as
ALLWINNER_PIT.
Quoted 5 lines
I see your point, now both SoCs are using the A10 specific PIT timer. Previously we agreed to do the generalization of that timer in a separate patch series.
I think it makes sense to also do the rename of this item as part of that separate series.
Fine by me.
PATCH v4 2/20 hw/arm: add Xunlong Orange Pi PC machine
In reply to Niek LinnenbankThe Xunlong Orange Pi PC is an Allwinner H3 System on Chip based embedded computer with mainline support in both U-Boot and Linux. The board comes with a Quad Core Cortex A7 @ 1.3GHz, 1GiB RAM, 100Mbit ethernet, USB, SD/MMC, USB, HDMI and various other I/O. This commit add support for the Xunlong Orange Pi PC machine.
--- hw/arm/orangepi.c | 93 ++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + hw/arm/Makefile.objs | 2 +- 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 hw/arm/orangepi.c
hw/arm/orangepi.c new file +93 -0
@@ -0,0 +1,93 @@ +/* +* Orange Pi emulation +* +* Copyright (C) 2019 Niek Linnenbank <[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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "exec/address-spaces.h" +#include "qapi/error.h" +#include "cpu.h" +#include "hw/sysbus.h" +#include "hw/boards.h" +#include "hw/qdev-properties.h" +#include "hw/arm/allwinner-h3.h" +#include "sysemu/sysemu.h" + +static struct arm_boot_info orangepi_binfo = { + .nb_cpus =AW_H3_NUM_CPUS , +}; + +typedef struct OrangePiState { +AwH3State *h3; +MemoryRegion sdram; +}OrangePiState ; + +static void orangepi_init (MachineState *machine) +{ +OrangePiState *s =g_new (OrangePiState,1 ); + +/* BIOS is not supported by this board */ +if (bios_name) { +error_report ("BIOS not supported for this machine" ); +exit (1 ); + } + +/* Only allow Cortex-A7 for this board */ +if (strcmp (machine->cpu_type,ARM_CPU_TYPE_NAME ("cortex-a7" )) !=0 ) { +error_report ("This board can only be used with cortex-a7 CPU" ); +exit (1 ); + } + + s->h3 =AW_H3 (object_new (TYPE_AW_H3 )); + +/* Setup timer properties */ +object_property_set_int (OBJECT (s->h3),32768 ,"clk0-freq" , + &error_abort); +object_property_set_int (OBJECT (s->h3),24 *1000 *1000 ,"clk1-freq" , + &error_abort); + +/* Mark H3 object realized */ +object_property_set_bool (OBJECT (s->h3), true,"realized" , &error_abort); + +/* SDRAM */ +if (machine->ram_size !=1 * GiB) { +error_report ("This machine can only be used with 1GiB of RAM" ); +exit (1 ); + } +memory_region_allocate_system_memory (&s->sdram,NULL ,"sdram" , + machine->ram_size); +memory_region_add_subregion (get_system_memory (), s->h3->memmap[AW_H3_SDRAM ], + &s->sdram); + + orangepi_binfo.loader_start = s->h3->memmap[AW_H3_SDRAM ]; + orangepi_binfo.ram_size = machine->ram_size; +arm_load_kernel (ARM_CPU (first_cpu), machine, &orangepi_binfo); +} + +static void orangepi_machine_init (MachineClass *mc) +{ + mc->desc ="Orange Pi PC" ; + mc->init = orangepi_init; + mc->min_cpus =AW_H3_NUM_CPUS ; + mc->max_cpus =AW_H3_NUM_CPUS ; + mc->default_cpus =AW_H3_NUM_CPUS ; + mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a7" ); + mc->default_ram_size =1 * GiB; +} + +DEFINE_MACHINE ("orangepi-pc" , orangepi_machine_init)
MAINTAINERS +1 -0
@@ -487,6 +487,7 @@ L: [email protected] S: Maintained F: hw/*/allwinner-h3* F: include/hw/*/allwinner-h3* +F: hw/arm/orangepi.c ARM PrimeCell and CMSDK devices M: Peter Maydell <[email protected]>
hw/arm/Makefile.objs +1 -1
@@ -35,7 +35,7 @@ obj-$(CONFIG_DIGIC) += digic.o obj-$(CONFIG_OMAP) += omap1.o omap2.o obj-$(CONFIG_STRONGARM) += strongarm.o obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o -obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o +obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o orangepi.o obj-$(CONFIG_RASPI) += bcm2835_peripherals.o bcm2836.o raspi.o obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o obj-$(CONFIG_STM32F405_SOC) += stm32f405_soc.o
Signature · 1 line
2.17.1
Re: [PATCH v4 02/20] hw/arm: add Xunlong Orange Pi PC machine
Quoted 84 lines · Niek Linnenbank
The Xunlong Orange Pi PC is an Allwinner H3 System on Chip based embedded computer with mainline support in both U-Boot and Linux. The board comes with a Quad Core Cortex A7 @ 1.3GHz, 1GiB RAM, 100Mbit ethernet, USB, SD/MMC, USB, HDMI and various other I/O. This commit add support for the Xunlong Orange Pi PC machine.
Signed-off-by Niek Linnenbank <[email protected]>Tested-by KONRAD Frederic <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>--- hw/arm/orangepi.c | 93 ++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + hw/arm/Makefile.objs | 2 +- 3 files changed, 95 insertions(+), 1 deletion(-)create mode 100644
hw/arm/orangepi.chw/arm/orangepi.c new file +61
-0@@ -0,0 +1,93 @@ +/* +* Orange Pi emulation +* +* Copyright (C) 2019 Niek Linnenbank <[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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "exec/address-spaces.h" +#include "qapi/error.h" +#include "cpu.h" +#include "hw/sysbus.h" +#include "hw/boards.h" +#include "hw/qdev-properties.h" +#include "hw/arm/allwinner-h3.h" +#include "sysemu/sysemu.h" + +static struct arm_boot_info orangepi_binfo = { + .nb_cpus =AW_H3_NUM_CPUS , +}; + +typedef struct OrangePiState { +AwH3State *h3; +MemoryRegion sdram; +}OrangePiState ; + +static void orangepi_init (MachineState *machine) +{ +OrangePiState *s =g_new (OrangePiState,1 ); + +/* BIOS is not supported by this board */ +if (bios_name) { +error_report ("BIOS not supported for this machine" ); +exit (1 ); + } + +/* Only allow Cortex-A7 for this board */ +if (strcmp (machine->cpu_type,ARM_CPU_TYPE_NAME ("cortex-a7" )) !=0 ) { +error_report ("This board can only be used with cortex-a7 CPU" ); +exit (1 ); + } + + s->h3 =AW_H3 (object_new (TYPE_AW_H3 )); + +/* Setup timer properties */ +object_property_set_int (OBJECT (s->h3),32768 ,"clk0-freq" , + &error_abort); + object_property_set_int(OBJECT(s->h3), 24 * 1000 * 1000, "clk1-freq",
hw/arm/orangepi.c line 71
Quoted 10 lines
hw/arm/orangepi.c new file +10
-0+ &error_abort); + +/* Mark H3 object realized */ +object_property_set_bool (OBJECT (s->h3), true,"realized" , &error_abort); + +/* SDRAM */ +if (machine->ram_size !=1 * GiB) { +error_report ("This machine can only be used with 1GiB of RAM" ); +exit (1 ); + }
I'd move this check earlier, eventually between the bios/cpu checks.
Quoted 40 lines
hw/arm/orangepi.c new file +22
-0+memory_region_allocate_system_memory (&s->sdram,NULL ,"sdram" , + machine->ram_size); +memory_region_add_subregion (get_system_memory (), s->h3->memmap[AW_H3_SDRAM ], + &s->sdram); + + orangepi_binfo.loader_start = s->h3->memmap[AW_H3_SDRAM ]; + orangepi_binfo.ram_size = machine->ram_size; +arm_load_kernel (ARM_CPU (first_cpu), machine, &orangepi_binfo); +} + +static void orangepi_machine_init (MachineClass *mc) +{ + mc->desc ="Orange Pi PC" ; + mc->init = orangepi_init; + mc->min_cpus =AW_H3_NUM_CPUS ; + mc->max_cpus =AW_H3_NUM_CPUS ; + mc->default_cpus =AW_H3_NUM_CPUS ; + mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a7" ); + mc->default_ram_size =1 * GiB; +} + +DEFINE_MACHINE ("orangepi-pc" , orangepi_machine_init)MAINTAINERS +1
-0@@ -487,6 +487,7 @@ L: [email protected] S: Maintained F: hw/*/allwinner-h3* F: include/hw/*/allwinner-h3* +F: hw/arm/orangepi.c ARM PrimeCell and CMSDK devices M: Peter Maydell <[email protected]>hw/arm/Makefile.objs +0
-0
hw/arm/Makefile.objs obj-$(CONFIG_DIGIC) += digic.o · line 41
Quoted 8 lines
hw/arm/Makefile.objs +1
-1@@ -35,7 +35,7 @@ obj-$(CONFIG_DIGIC) += digic.o obj-$(CONFIG_OMAP) += omap1.o omap2.o obj-$(CONFIG_STRONGARM) += strongarm.o obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o -obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o +obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o orangepi.o obj-$(CONFIG_RASPI) += bcm2835_peripherals.o bcm2836.o raspi.o obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o obj-$(CONFIG_STM32F405_SOC) += stm32f405_soc.o
Re: [PATCH v4 02/20] hw/arm: add Xunlong Orange Pi PC machine
Quoted 93 lines · Philippe Mathieu-Daudé
Quoted 65 lines · Niek Linnenbank
The Xunlong Orange Pi PC is an Allwinner H3 System on Chip based embedded computer with mainline support in both U-Boot and Linux. The board comes with a Quad Core Cortex A7 @ 1.3GHz, 1GiB RAM, 100Mbit ethernet, USB, SD/MMC, USB, HDMI and various other I/O. This commit add support for the Xunlong Orange Pi PC machine.
Signed-off-by Niek Linnenbank <[email protected]>Tested-by KONRAD Frederic <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>--- hw/arm/orangepi.c | 93 ++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + hw/arm/Makefile.objs | 2 +- 3 files changed, 95 insertions(+), 1 deletion(-)create mode 100644
hw/arm/orangepi.chw/arm/orangepi.c new file +17
-0@@ -0,0 +1,93 @@ +/* +* Orange Pi emulation +* +* Copyright (C) 2019 Niek Linnenbank <[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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/ .
+ */hw/arm/orangepi.c new file +23
-0+ +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "exec/address-spaces.h" +#include "qapi/error.h" +#include "cpu.h" +#include "hw/sysbus.h" +#include "hw/boards.h" +#include "hw/qdev-properties.h" +#include "hw/arm/allwinner-h3.h" +#include "sysemu/sysemu.h" + +static struct arm_boot_info orangepi_binfo = { + .nb_cpus =AW_H3_NUM_CPUS , +}; + +typedef struct OrangePiState { +AwH3State *h3; +MemoryRegion sdram; +}OrangePiState ; + +static void orangepi_init (MachineState *machine) +{hw/arm/orangepi.c
Quoted 10 lines
hw/arm/orangepi.c new file +10
-0+OrangePiState *s =g_new (OrangePiState,1 ); + +/* BIOS is not supported by this board */ +if (bios_name) { +error_report ("BIOS not supported for this machine" ); +exit (1 ); + } + +/* Only allow Cortex-A7 for this board */ +if (strcmp (machine->cpu_type,ARM_CPU_TYPE_NAME ("cortex-a7" )) !=0 ){
hw/arm/orangepi.c
Quoted 10 lines
hw/arm/orangepi.c new file +10
-0+error_report ("This board can only be used with cortex-a7 CPU" ); +exit (1 ); + } + + s->h3 =AW_H3 (object_new (TYPE_AW_H3 )); + +/* Setup timer properties */ +object_property_set_int (OBJECT (s->h3),32768 ,"clk0-freq" , + &error_abort); + object_property_set_int(OBJECT(s->h3), 24 * 1000 * 1000,"clk1-freq",
hw/arm/orangepi.c
Quoted 4 lines
hw/arm/orangepi.c new file +4
-0+ &error_abort); + +/* Mark H3 object realized */ + object_property_set_bool(OBJECT(s->h3), true, "realized",
&error_abort);
Quoted 9 lines
hw/arm/orangepi.c line 71
Quoted 6 lines
hw/arm/orangepi.c new file +6
-0+ +/* SDRAM */ +if (machine->ram_size !=1 * GiB) { +error_report ("This machine can only be used with 1GiB of RAM" ); +exit (1 ); + }I'd move this check earlier, eventually between the bios/cpu checks.
Sure, I'll move it between the bios/cpu checks.
Regards,
Niek
Quoted 54 lines
hw/arm/orangepi.c
Quoted 4 lines
hw/arm/orangepi.c new file +3
-0+memory_region_allocate_system_memory (&s->sdram,NULL ,"sdram" , + machine->ram_size); + memory_region_add_subregion(get_system_memory(),s->h3->memmap[AW_H3_SDRAM],
Quoted 37 lines
hw/arm/orangepi.c new file +19
-0+ &s->sdram); + + orangepi_binfo.loader_start = s->h3->memmap[AW_H3_SDRAM ]; + orangepi_binfo.ram_size = machine->ram_size; +arm_load_kernel (ARM_CPU (first_cpu), machine, &orangepi_binfo); +} + +static void orangepi_machine_init (MachineClass *mc) +{ + mc->desc ="Orange Pi PC" ; + mc->init = orangepi_init; + mc->min_cpus =AW_H3_NUM_CPUS ; + mc->max_cpus =AW_H3_NUM_CPUS ; + mc->default_cpus =AW_H3_NUM_CPUS ; + mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a7" ); + mc->default_ram_size =1 * GiB; +} + +DEFINE_MACHINE ("orangepi-pc" , orangepi_machine_init)MAINTAINERS +1
-0@@ -487,6 +487,7 @@ L: [email protected] S: Maintained F: hw/*/allwinner-h3* F: include/hw/*/allwinner-h3* +F: hw/arm/orangepi.c ARM PrimeCell and CMSDK devices M: Peter Maydell <[email protected]>hw/arm/Makefile.objs +0
-0hw/arm/Makefile.objs obj-$(CONFIG_DIGIC) += digic.o · line 41
Quoted 8 lines
hw/arm/Makefile.objs +1
-1@@ -35,7 +35,7 @@ obj-$(CONFIG_DIGIC) += digic.o obj-$(CONFIG_OMAP) += omap1.o omap2.o obj-$(CONFIG_STRONGARM) += strongarm.o obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o -obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o +obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o orangepi.o obj-$(CONFIG_RASPI) += bcm2835_peripherals.o bcm2836.o raspi.o obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o obj-$(CONFIG_STM32F405_SOC) += stm32f405_soc.o
Signature · 1 line
Niek Linnenbank
Re: [PATCH v4 02/20] hw/arm: add Xunlong Orange Pi PC machine
In reply to Niek LinnenbankQuoted 10 lines · On Sun, 19 Jan 2020 01:50:44 +0100 Niek Linnenbank <[email protected]>…
The Xunlong Orange Pi PC is an Allwinner H3 System on Chip based embedded computer with mainline support in both U-Boot and Linux. The board comes with a Quad Core Cortex A7 @ 1.3GHz, 1GiB RAM, 100Mbit ethernet, USB, SD/MMC, USB, HDMI and various other I/O. This commit add support for the Xunlong Orange Pi PC machine.
Signed-off-by Niek Linnenbank <[email protected]>Tested-by KONRAD Frederic <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Quoted 131 lines
--- hw/arm/orangepi.c | 93 ++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + hw/arm/Makefile.objs | 2 +- 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 hw/arm/orangepi.chw/arm/orangepi.c new file +93
-0@@ -0,0 +1,93 @@ +/* +* Orange Pi emulation +* +* Copyright (C) 2019 Niek Linnenbank <[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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "exec/address-spaces.h" +#include "qapi/error.h" +#include "cpu.h" +#include "hw/sysbus.h" +#include "hw/boards.h" +#include "hw/qdev-properties.h" +#include "hw/arm/allwinner-h3.h" +#include "sysemu/sysemu.h" + +static struct arm_boot_info orangepi_binfo = { + .nb_cpus =AW_H3_NUM_CPUS , +}; + +typedef struct OrangePiState { +AwH3State *h3; +MemoryRegion sdram; +}OrangePiState ; + +static void orangepi_init (MachineState *machine) +{ +OrangePiState *s =g_new (OrangePiState,1 ); + +/* BIOS is not supported by this board */ +if (bios_name) { +error_report ("BIOS not supported for this machine" ); +exit (1 ); + } + +/* Only allow Cortex-A7 for this board */ +if (strcmp (machine->cpu_type,ARM_CPU_TYPE_NAME ("cortex-a7" )) !=0 ) { +error_report ("This board can only be used with cortex-a7 CPU" ); +exit (1 ); + } + + s->h3 =AW_H3 (object_new (TYPE_AW_H3 )); + +/* Setup timer properties */ +object_property_set_int (OBJECT (s->h3),32768 ,"clk0-freq" , + &error_abort); +object_property_set_int (OBJECT (s->h3),24 *1000 *1000 ,"clk1-freq" , + &error_abort); + +/* Mark H3 object realized */ +object_property_set_bool (OBJECT (s->h3), true,"realized" , &error_abort); + +/* SDRAM */ +if (machine->ram_size !=1 * GiB) { +error_report ("This machine can only be used with 1GiB of RAM" ); +exit (1 ); + } +memory_region_allocate_system_memory (&s->sdram,NULL ,"sdram" , + machine->ram_size); +memory_region_add_subregion (get_system_memory (), s->h3->memmap[AW_H3_SDRAM ], + &s->sdram); + + orangepi_binfo.loader_start = s->h3->memmap[AW_H3_SDRAM ]; + orangepi_binfo.ram_size = machine->ram_size; +arm_load_kernel (ARM_CPU (first_cpu), machine, &orangepi_binfo); +} + +static void orangepi_machine_init (MachineClass *mc) +{ + mc->desc ="Orange Pi PC" ; + mc->init = orangepi_init; + mc->min_cpus =AW_H3_NUM_CPUS ; + mc->max_cpus =AW_H3_NUM_CPUS ; + mc->default_cpus =AW_H3_NUM_CPUS ; + mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a7" ); + mc->default_ram_size =1 * GiB; +} + +DEFINE_MACHINE ("orangepi-pc" , orangepi_machine_init)MAINTAINERS +1
-0@@ -487,6 +487,7 @@ L: [email protected] S: Maintained F: hw/*/allwinner-h3* F: include/hw/*/allwinner-h3* +F: hw/arm/orangepi.c ARM PrimeCell and CMSDK devices M: Peter Maydell <[email protected]>hw/arm/Makefile.objs +1
-1@@ -35,7 +35,7 @@ obj-$(CONFIG_DIGIC) += digic.o obj-$(CONFIG_OMAP) += omap1.o omap2.o obj-$(CONFIG_STRONGARM) += strongarm.o obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o -obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o +obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o orangepi.o obj-$(CONFIG_RASPI) += bcm2835_peripherals.o bcm2836.o raspi.o obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o obj-$(CONFIG_STM32F405_SOC) += stm32f405_soc.o
Re: [PATCH v4 02/20] hw/arm: add Xunlong Orange Pi PC machine
Quoted 10 lines · Igor Mammedov
Quoted 7 lines · On Sun, 19 Jan 2020 01:50:44 +0100 Niek Linnenbank <[email protected]>…
The Xunlong Orange Pi PC is an Allwinner H3 System on Chip based embedded computer with mainline support in both U-Boot and Linux. The board comes with a Quad Core Cortex A7 @ 1.3GHz, 1GiB RAM, 100Mbit ethernet, USB, SD/MMC, USB, HDMI and various other I/O. This commit add support for the Xunlong Orange Pi PC machine.
Quoted 6 lines
Quoted 3 lines
Signed-off-by Niek Linnenbank <[email protected]>Tested-by KONRAD Frederic <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Acked-by Igor Mammedov <[email protected]>
Thanks for the Acked-by Igor, I'm adding it to the commit message.
Regards,
Niek
Quoted 139 lines
Quoted 56 lines
--- hw/arm/orangepi.c | 93 ++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + hw/arm/Makefile.objs | 2 +- 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 hw/arm/orangepi.chw/arm/orangepi.c new file +17
-0@@ -0,0 +1,93 @@ +/* +* Orange Pi emulation +* +* Copyright (C) 2019 Niek Linnenbank <[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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/ .
+ */hw/arm/orangepi.c new file +23
-0+ +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "exec/address-spaces.h" +#include "qapi/error.h" +#include "cpu.h" +#include "hw/sysbus.h" +#include "hw/boards.h" +#include "hw/qdev-properties.h" +#include "hw/arm/allwinner-h3.h" +#include "sysemu/sysemu.h" + +static struct arm_boot_info orangepi_binfo = { + .nb_cpus =AW_H3_NUM_CPUS , +}; + +typedef struct OrangePiState { +AwH3State *h3; +MemoryRegion sdram; +}OrangePiState ; + +static void orangepi_init (MachineState *machine) +{hw/arm/orangepi.c
Quoted 10 lines
hw/arm/orangepi.c new file +10
-0+OrangePiState *s =g_new (OrangePiState,1 ); + +/* BIOS is not supported by this board */ +if (bios_name) { +error_report ("BIOS not supported for this machine" ); +exit (1 ); + } + +/* Only allow Cortex-A7 for this board */ +if (strcmp (machine->cpu_type,ARM_CPU_TYPE_NAME ("cortex-a7" )) !=0 ){
hw/arm/orangepi.c
Quoted 10 lines
hw/arm/orangepi.c new file +10
-0+error_report ("This board can only be used with cortex-a7 CPU" ); +exit (1 ); + } + + s->h3 =AW_H3 (object_new (TYPE_AW_H3 )); + +/* Setup timer properties */ +object_property_set_int (OBJECT (s->h3),32768 ,"clk0-freq" , + &error_abort); + object_property_set_int(OBJECT(s->h3), 24 * 1000 * 1000,"clk1-freq",
hw/arm/orangepi.c
Quoted 4 lines
hw/arm/orangepi.c new file +4
-0+ &error_abort); + +/* Mark H3 object realized */ + object_property_set_bool(OBJECT(s->h3), true, "realized",
&error_abort);hw/arm/orangepi.c
Quoted 9 lines
hw/arm/orangepi.c new file +9
-0+ +/* SDRAM */ +if (machine->ram_size !=1 * GiB) { +error_report ("This machine can only be used with 1GiB of RAM" ); +exit (1 ); + } +memory_region_allocate_system_memory (&s->sdram,NULL ,"sdram" , + machine->ram_size); + memory_region_add_subregion(get_system_memory(),s->h3->memmap[AW_H3_SDRAM],
Quoted 44 lines
hw/arm/orangepi.c new file +19
-0+ &s->sdram); + + orangepi_binfo.loader_start = s->h3->memmap[AW_H3_SDRAM ]; + orangepi_binfo.ram_size = machine->ram_size; +arm_load_kernel (ARM_CPU (first_cpu), machine, &orangepi_binfo); +} + +static void orangepi_machine_init (MachineClass *mc) +{ + mc->desc ="Orange Pi PC" ; + mc->init = orangepi_init; + mc->min_cpus =AW_H3_NUM_CPUS ; + mc->max_cpus =AW_H3_NUM_CPUS ; + mc->default_cpus =AW_H3_NUM_CPUS ; + mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a7" ); + mc->default_ram_size =1 * GiB; +} + +DEFINE_MACHINE ("orangepi-pc" , orangepi_machine_init)MAINTAINERS +1
-0@@ -487,6 +487,7 @@ L: [email protected] S: Maintained F: hw/*/allwinner-h3* F: include/hw/*/allwinner-h3* +F: hw/arm/orangepi.c ARM PrimeCell and CMSDK devices M: Peter Maydell <[email protected]>hw/arm/Makefile.objs +1
-1@@ -35,7 +35,7 @@ obj-$(CONFIG_DIGIC) += digic.o obj-$(CONFIG_OMAP) += omap1.o omap2.o obj-$(CONFIG_STRONGARM) += strongarm.o obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o -obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o +obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o orangepi.o obj-$(CONFIG_RASPI) += bcm2835_peripherals.o bcm2836.o raspi.o obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o obj-$(CONFIG_STM32F405_SOC) += stm32f405_soc.o
Signature · 1 line
Niek Linnenbank
PATCH v4 3/20 hw/arm/allwinner-h3: add Clock Control Unit
In reply to Niek LinnenbankThe Clock Control Unit is responsible for clock signal generation, configuration and distribution in the Allwinner H3 System on Chip. This commit adds support for the Clock Control Unit which emulates a simple read/write register interface.
--- include/hw/arm/allwinner-h3.h | 3 + include/hw/misc/allwinner-h3-ccu.h | 66 ++++++++ hw/arm/allwinner-h3.c | 9 +- hw/misc/allwinner-h3-ccu.c | 243 +++++++++++++++++++++++++++++ hw/misc/Makefile.objs | 1 + 5 files changed, 321 insertions(+), 1 deletion(-) create mode 100644 include/hw/misc/allwinner-h3-ccu.h create mode 100644 hw/misc/allwinner-h3-ccu.c
include/hw/arm/allwinner-h3.h +3 -0
@@ -39,6 +39,7 @@#include "hw/arm/boot.h" #include "hw/timer/allwinner-a10-pit.h" #include "hw/intc/arm_gic.h" +#include "hw/misc/allwinner-h3-ccu.h" #include "target/arm/cpu.h" /**
@@ -55,6 +56,7 @@ enum {AW_H3_SRAM_A1 ,AW_H3_SRAM_A2 ,AW_H3_SRAM_C , +AW_H3_CCU ,AW_H3_PIT ,AW_H3_UART0 , AW_H3_UART1,
@@ -97,6 +99,7 @@ typedef struct AwH3State {ARMCPU cpus[AW_H3_NUM_CPUS ];const hwaddr *memmap;AwA10PITState timer; +AwH3ClockCtlState ccu;GICState gic;MemoryRegion sram_a1;MemoryRegion sram_a2;
include/hw/misc/allwinner-h3-ccu.h new file +66 -0
66 lines not on this page · raw message
hw/arm/allwinner-h3.c +8 -1
@@ -36,6 +36,7 @@ const hwaddr allwinner_h3_memmap[] = { [AW_H3_SRAM_A1] = 0x00000000, [AW_H3_SRAM_A2] = 0x00044000, [AW_H3_SRAM_C] = 0x00010000, + [AW_H3_CCU] = 0x01c20000, [AW_H3_PIT] = 0x01c20c00, [AW_H3_UART0] = 0x01c28000, [AW_H3_UART1] = 0x01c28400,
@@ -77,7 +78,6 @@ struct AwH3Unimplemented { { "usb2", 0x01c1c000, 4 * KiB }, { "usb3", 0x01c1d000, 4 * KiB }, { "smc", 0x01c1e000, 4 * KiB }, - { "ccu", 0x01c20000, 1 * KiB }, { "pio", 0x01c20800, 1 * KiB }, { "owa", 0x01c21000, 1 * KiB }, { "pwm", 0x01c21400, 1 * KiB },
@@ -172,6 +172,9 @@ static void allwinner_h3_init(Object *obj) "clk0-freq", &error_abort);object_property_add_alias (obj,"clk1-freq" ,OBJECT (&s->timer),"clk1-freq" , &error_abort); + +sysbus_init_child_obj (obj,"ccu" , &s->ccu,sizeof (s->ccu), +TYPE_AW_H3_CCU ); }static void allwinner_h3_realize (DeviceState *dev,Error **errp)
@@ -277,6 +280,10 @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)memory_region_add_subregion (get_system_memory (), s->memmap[AW_H3_SRAM_C ], &s->sram_c); +/* Clock Control Unit */ +qdev_init_nofail (DEVICE (&s->ccu)); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->ccu),0 , s->memmap[AW_H3_CCU ]); +/* UART0. For future clocktree API: All UARTS are connected to APB2_CLK. */ serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART0], 2, qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_UART0),
hw/misc/allwinner-h3-ccu.c new file +243 -0
243 lines not on this page · raw message
hw/misc/Makefile.objs +1 -0
@@ -28,6 +28,7 @@ common-obj-$(CONFIG_MACIO) += macio/ common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o +common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o common-obj-$(CONFIG_NSERIES) += cbus.o common-obj-$(CONFIG_ECCMEMCTL) += eccmemctl.o
Signature · 1 line
2.17.1
Re: [PATCH v4 03/20] hw/arm/allwinner-h3: add Clock Control Unit
Quoted 72 lines · Niek Linnenbank
The Clock Control Unit is responsible for clock signal generation, configuration and distribution in the Allwinner H3 System on Chip. This commit adds support for the Clock Control Unit which emulates a simple read/write register interface.
Signed-off-by Niek Linnenbank <[email protected]>--- include/hw/arm/allwinner-h3.h | 3 + include/hw/misc/allwinner-h3-ccu.h | 66 ++++++++ hw/arm/allwinner-h3.c | 9 +- hw/misc/allwinner-h3-ccu.c | 243 +++++++++++++++++++++++++++++ hw/misc/Makefile.objs | 1 + 5 files changed, 321 insertions(+), 1 deletion(-)create mode 100644
include/hw/misc/allwinner-h3-ccu.hcreate mode 100644hw/misc/allwinner-h3-ccu.cinclude/hw/arm/allwinner-h3.h +3
-0@@ -39,6 +39,7 @@#include "hw/arm/boot.h" #include "hw/timer/allwinner-a10-pit.h" #include "hw/intc/arm_gic.h" +#include "hw/misc/allwinner-h3-ccu.h" #include "target/arm/cpu.h" /** @@ -55,6 +56,7 @@ enum {AW_H3_SRAM_A1 ,AW_H3_SRAM_A2 ,AW_H3_SRAM_C , +AW_H3_CCU ,AW_H3_PIT ,AW_H3_UART0 , AW_H3_UART1,@@ -97,6 +99,7 @@ typedef struct AwH3State {ARMCPU cpus[AW_H3_NUM_CPUS ];const hwaddr *memmap;AwA10PITState timer; +AwH3ClockCtlState ccu;GICState gic;MemoryRegion sram_a1;MemoryRegion sram_a2;include/hw/misc/allwinner-h3-ccu.h new file +22
-0@@ -0,0 +1,66 @@ +/* +* Allwinner H3 Clock Control Unit emulation +* +* Copyright (C) 2019 Niek Linnenbank <[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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HW_MISC_ALLWINNER_H3_CCU_H +#define HW_MISC_ALLWINNER_H3_CCU_H +
include/hw/misc/allwinner-h3-ccu.h line 32
Quoted 10 lines
include/hw/misc/allwinner-h3-ccu.h new file +10
-0+#include "qom/object.h" +#include "hw/sysbus.h" + +/** +* @name Constants +* @{ +*/ + +/** Highest register address used by CCU device */ +#define AW_H3_CCU_REGS_MAXADDR (0x304)
There might be a migration issue if one day we see some firmware accessing some undocumented register > 0x304 (you'd need to migrate more than 0x304/4 registers, so increase allwinner_h3_ccu_vmstate.version_id.
I'd simply replace this definition by
#define AW_H3_CCU_IOSIZE 0x400
And see comment in write().
Quoted 182 lines
include/hw/misc/allwinner-h3-ccu.h new file +34
-0+ +/** Total number of known registers */ +#define AW_H3_CCU_REGS_NUM (AW_H3_CCU_REGS_MAXADDR / sizeof(uint32_t)) + +/** @} */ + +/** +* @name Object model +* @{ +*/ + +#define TYPE_AW_H3_CCU "allwinner-h3-ccu" +#define AW_H3_CCU (obj) \ + OBJECT_CHECK(AwH3ClockCtlState, (obj), TYPE_AW_H3_CCU) + +/** @} */ + +/** +* Allwinner H3 CCU object instance state. +*/ +typedef struct AwH3ClockCtlState { +/*< private >*/ +SysBusDevice parent_obj; +/*< public >*/ + +/** Maps I/O registers in physical memory */ +MemoryRegion iomem; + +/** Array of hardware registers */ +uint32_t regs[AW_H3_CCU_REGS_NUM ]; + +}AwH3ClockCtlState ; + +#endif /* HW_MISC_ALLWINNER_H3_CCU_H */ hw/arm/allwinner-h3.c +8
-1@@ -36,6 +36,7 @@ const hwaddr allwinner_h3_memmap[] = { [AW_H3_SRAM_A1] = 0x00000000, [AW_H3_SRAM_A2] = 0x00044000, [AW_H3_SRAM_C] = 0x00010000, + [AW_H3_CCU] = 0x01c20000, [AW_H3_PIT] = 0x01c20c00, [AW_H3_UART0] = 0x01c28000, [AW_H3_UART1] = 0x01c28400,@@ -77,7 +78,6 @@ struct AwH3Unimplemented { { "usb2", 0x01c1c000, 4 * KiB }, { "usb3", 0x01c1d000, 4 * KiB }, { "smc", 0x01c1e000, 4 * KiB }, - { "ccu", 0x01c20000, 1 * KiB }, { "pio", 0x01c20800, 1 * KiB }, { "owa", 0x01c21000, 1 * KiB }, { "pwm", 0x01c21400, 1 * KiB },@@ -172,6 +172,9 @@ static void allwinner_h3_init(Object *obj) "clk0-freq", &error_abort);object_property_add_alias (obj,"clk1-freq" ,OBJECT (&s->timer),"clk1-freq" , &error_abort); + +sysbus_init_child_obj (obj,"ccu" , &s->ccu,sizeof (s->ccu), +TYPE_AW_H3_CCU ); }static void allwinner_h3_realize (DeviceState *dev,Error **errp)@@ -277,6 +280,10 @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)memory_region_add_subregion (get_system_memory (), s->memmap[AW_H3_SRAM_C ], &s->sram_c); +/* Clock Control Unit */ +qdev_init_nofail (DEVICE (&s->ccu)); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->ccu),0 , s->memmap[AW_H3_CCU ]); +/* UART0. For future clocktree API: All UARTS are connected to APB2_CLK. */ serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART0], 2, qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_UART0),hw/misc/allwinner-h3-ccu.c new file +101
-0@@ -0,0 +1,243 @@ +/* +* Allwinner H3 Clock Control Unit emulation +* +* Copyright (C) 2019 Niek Linnenbank <[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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "hw/sysbus.h" +#include "migration/vmstate.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "hw/misc/allwinner-h3-ccu.h" + +/* CCU register offsets */ +enum { +REG_PLL_CPUX =0x0000 ,/* PLL CPUX Control */ +REG_PLL_AUDIO =0x0008 ,/* PLL Audio Control */ +REG_PLL_VIDEO =0x0010 ,/* PLL Video Control */ +REG_PLL_VE =0x0018 ,/* PLL VE Control */ +REG_PLL_DDR =0x0020 ,/* PLL DDR Control */ +REG_PLL_PERIPH0 =0x0028 ,/* PLL Peripherals 0 Control */ +REG_PLL_GPU =0x0038 ,/* PLL GPU Control */ +REG_PLL_PERIPH1 =0x0044 ,/* PLL Peripherals 1 Control */ +REG_PLL_DE =0x0048 ,/* PLL Display Engine Control */ +REG_CPUX_AXI =0x0050 ,/* CPUX/AXI Configuration */ +REG_APB1 =0x0054 ,/* ARM Peripheral Bus 1 Config */ +REG_APB2 =0x0058 ,/* ARM Peripheral Bus 2 Config */ +REG_DRAM_CFG =0x00F4 ,/* DRAM Configuration */ +REG_MBUS =0x00FC ,/* MBUS Reset */ +REG_PLL_TIME0 =0x0200 ,/* PLL Stable Time 0 */ +REG_PLL_TIME1 =0x0204 ,/* PLL Stable Time 1 */ +REG_PLL_CPUX_BIAS =0x0220 ,/* PLL CPUX Bias */ +REG_PLL_AUDIO_BIAS =0x0224 ,/* PLL Audio Bias */ +REG_PLL_VIDEO_BIAS =0x0228 ,/* PLL Video Bias */ +REG_PLL_VE_BIAS =0x022C ,/* PLL VE Bias */ +REG_PLL_DDR_BIAS =0x0230 ,/* PLL DDR Bias */ +REG_PLL_PERIPH0_BIAS =0x0234 ,/* PLL Peripherals 0 Bias */ +REG_PLL_GPU_BIAS =0x023C ,/* PLL GPU Bias */ +REG_PLL_PERIPH1_BIAS =0x0244 ,/* PLL Peripherals 1 Bias */ +REG_PLL_DE_BIAS =0x0248 ,/* PLL Display Engine Bias */ +REG_PLL_CPUX_TUNING =0x0250 ,/* PLL CPUX Tuning */ +REG_PLL_DDR_TUNING =0x0260 ,/* PLL DDR Tuning */ +}; + +#define REG_INDEX (offset) (offset / sizeof(uint32_t)) + +/* CCU register flags */ +enum { +REG_DRAM_CFG_UPDATE = (1 <<16 ), +}; + +enum { +REG_PLL_ENABLE = (1 <<31 ), +REG_PLL_LOCK = (1 <<28 ), +}; + + +/* CCU register reset values */ +enum { +REG_PLL_CPUX_RST =0x00001000 , +REG_PLL_AUDIO_RST =0x00035514 , +REG_PLL_VIDEO_RST =0x03006207 , +REG_PLL_VE_RST =0x03006207 , +REG_PLL_DDR_RST =0x00001000 , +REG_PLL_PERIPH0_RST =0x00041811 , +REG_PLL_GPU_RST =0x03006207 , +REG_PLL_PERIPH1_RST =0x00041811 , +REG_PLL_DE_RST =0x03006207 , +REG_CPUX_AXI_RST =0x00010000 , +REG_APB1_RST =0x00001010 , +REG_APB2_RST =0x01000000 , +REG_DRAM_CFG_RST =0x00000000 , +REG_MBUS_RST =0x80000000 , +REG_PLL_TIME0_RST =0x000000FF , +REG_PLL_TIME1_RST =0x000000FF , +REG_PLL_CPUX_BIAS_RST =0x08100200 , +REG_PLL_AUDIO_BIAS_RST =0x10100000 , +REG_PLL_VIDEO_BIAS_RST =0x10100000 , +REG_PLL_VE_BIAS_RST =0x10100000 , +REG_PLL_DDR_BIAS_RST =0x81104000 , +REG_PLL_PERIPH0_BIAS_RST =0x10100010 , +REG_PLL_GPU_BIAS_RST =0x10100000 , +REG_PLL_PERIPH1_BIAS_RST =0x10100010 , +REG_PLL_DE_BIAS_RST =0x10100000 , +REG_PLL_CPUX_TUNING_RST =0x0A101000 , +REG_PLL_DDR_TUNING_RST =0x14880000 , +};
hw/misc/allwinner-h3-ccu.c line 111
Quoted 10 lines
hw/misc/allwinner-h3-ccu.c new file +10
-0+ +static uint64_t allwinner_h3_ccu_read (void *opaque,hwaddr offset, +unsigned size) +{ +const AwH3ClockCtlState *s =AW_H3_CCU (opaque); +const uint32_t idx =REG_INDEX (offset); + +if (idx >=AW_H3_CCU_REGS_NUM ) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: out-of-bounds offset 0x%04x\n" , + __func__, (uint32_t )offset);
See comment in write().
Quoted 5 lines
hw/misc/allwinner-h3-ccu.c new file +5
-0+return 0 ; + } + +return s->regs[idx]; +}
hw/misc/allwinner-h3-ccu.c line 126
Quoted 10 lines
hw/misc/allwinner-h3-ccu.c new file +10
-0+ +static void allwinner_h3_ccu_write (void *opaque,hwaddr offset, +uint64_t val,unsigned size) +{ +AwH3ClockCtlState *s =AW_H3_CCU (opaque); +const uint32_t idx =REG_INDEX (offset); + +if (idx >=AW_H3_CCU_REGS_NUM ) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: out-of-bounds offset 0x%04x\n" , + __func__, (uint32_t )offset);
I'd replace this check by ...
Quoted 10 lines
hw/misc/allwinner-h3-ccu.c new file +10
-0+return ; + } + +switch (offset) { +case REG_DRAM_CFG :/* DRAM Configuration */ + val &= ~REG_DRAM_CFG_UPDATE ; +break ; +case REG_PLL_CPUX :/* PLL CPUX Control */ +case REG_PLL_AUDIO :/* PLL Audio Control */ +case REG_PLL_VIDEO :/* PLL Video Control */
hw/misc/allwinner-h3-ccu.c line 146
Quoted 10 lines
hw/misc/allwinner-h3-ccu.c new file +10
-0+case REG_PLL_VE :/* PLL VE Control */ +case REG_PLL_DDR :/* PLL DDR Control */ +case REG_PLL_PERIPH0 :/* PLL Peripherals 0 Control */ +case REG_PLL_GPU :/* PLL GPU Control */ +case REG_PLL_PERIPH1 :/* PLL Peripherals 1 Control */ +case REG_PLL_DE :/* PLL Display Engine Control */ +if (val ®_PLL_ENABLE ) { + val |=REG_PLL_LOCK ; + } +break ;
case 0x304 ... AW_H3_CCU_IOSIZE:
qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset
0x%04x\n",
__func__, (uint32_t)offset);
break;hw/misc/allwinner-h3-ccu.c line 154
Quoted 8 lines
hw/misc/allwinner-h3-ccu.c new file +8
-0+default : +qemu_log_mask (LOG_UNIMP ,"%s: unimplemented write offset 0x%04x\n" , + __func__, (uint32_t )offset); +break ; + } + + s->regs[idx] = (uint32_t ) val; +}
That said,
Quoted 102 lines
hw/misc/allwinner-h3-ccu.c new file +89
-0+ +static const MemoryRegionOps allwinner_h3_ccu_ops = { + .read = allwinner_h3_ccu_read, + .write = allwinner_h3_ccu_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + }, + .impl.min_access_size =4 , +}; + +static void allwinner_h3_ccu_reset (DeviceState *dev) +{ +AwH3ClockCtlState *s =AW_H3_CCU (dev); + +/* Set default values for registers */ + s->regs[REG_INDEX (REG_PLL_CPUX )] =REG_PLL_CPUX_RST ; + s->regs[REG_INDEX (REG_PLL_AUDIO )] =REG_PLL_AUDIO_RST ; + s->regs[REG_INDEX (REG_PLL_VIDEO )] =REG_PLL_VIDEO_RST ; + s->regs[REG_INDEX (REG_PLL_VE )] =REG_PLL_VE_RST ; + s->regs[REG_INDEX (REG_PLL_DDR )] =REG_PLL_DDR_RST ; + s->regs[REG_INDEX (REG_PLL_PERIPH0 )] =REG_PLL_PERIPH0_RST ; + s->regs[REG_INDEX (REG_PLL_GPU )] =REG_PLL_GPU_RST ; + s->regs[REG_INDEX (REG_PLL_PERIPH1 )] =REG_PLL_PERIPH1_RST ; + s->regs[REG_INDEX (REG_PLL_DE )] =REG_PLL_DE_RST ; + s->regs[REG_INDEX (REG_CPUX_AXI )] =REG_CPUX_AXI_RST ; + s->regs[REG_INDEX (REG_APB1 )] =REG_APB1_RST ; + s->regs[REG_INDEX (REG_APB2 )] =REG_APB2_RST ; + s->regs[REG_INDEX (REG_DRAM_CFG )] =REG_DRAM_CFG_RST ; + s->regs[REG_INDEX (REG_MBUS )] =REG_MBUS_RST ; + s->regs[REG_INDEX (REG_PLL_TIME0 )] =REG_PLL_TIME0_RST ; + s->regs[REG_INDEX (REG_PLL_TIME1 )] =REG_PLL_TIME1_RST ; + s->regs[REG_INDEX (REG_PLL_CPUX_BIAS )] =REG_PLL_CPUX_BIAS_RST ; + s->regs[REG_INDEX (REG_PLL_AUDIO_BIAS )] =REG_PLL_AUDIO_BIAS_RST ; + s->regs[REG_INDEX (REG_PLL_VIDEO_BIAS )] =REG_PLL_VIDEO_BIAS_RST ; + s->regs[REG_INDEX (REG_PLL_VE_BIAS )] =REG_PLL_VE_BIAS_RST ; + s->regs[REG_INDEX (REG_PLL_DDR_BIAS )] =REG_PLL_DDR_BIAS_RST ; + s->regs[REG_INDEX (REG_PLL_PERIPH0_BIAS )] =REG_PLL_PERIPH0_BIAS_RST ; + s->regs[REG_INDEX (REG_PLL_GPU_BIAS )] =REG_PLL_GPU_BIAS_RST ; + s->regs[REG_INDEX (REG_PLL_PERIPH1_BIAS )] =REG_PLL_PERIPH1_BIAS_RST ; + s->regs[REG_INDEX (REG_PLL_DE_BIAS )] =REG_PLL_DE_BIAS_RST ; + s->regs[REG_INDEX (REG_PLL_CPUX_TUNING )] =REG_PLL_CPUX_TUNING_RST ; + s->regs[REG_INDEX (REG_PLL_DDR_TUNING )] =REG_PLL_DDR_TUNING_RST ; +} + +static void allwinner_h3_ccu_init (Object *obj) +{ +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); +AwH3ClockCtlState *s =AW_H3_CCU (obj); + +/* Memory mapping */ +memory_region_init_io (&s->iomem,OBJECT (s), &allwinner_h3_ccu_ops, s, +TYPE_AW_H3_CCU ,1 * KiB); +sysbus_init_mmio (sbd, &s->iomem); +} + +static const VMStateDescription allwinner_h3_ccu_vmstate = { + .name ="allwinner-h3-ccu" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32_ARRAY (regs, AwH3ClockCtlState,AW_H3_CCU_REGS_NUM ), +VMSTATE_END_OF_LIST () + } +}; + +static void allwinner_h3_ccu_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->reset = allwinner_h3_ccu_reset; + dc->vmsd = &allwinner_h3_ccu_vmstate; +} + +static const TypeInfo allwinner_h3_ccu_info = { + .name =TYPE_AW_H3_CCU , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_init = allwinner_h3_ccu_init, + .instance_size =sizeof (AwH3ClockCtlState), + .class_init = allwinner_h3_ccu_class_init, +}; + +static void allwinner_h3_ccu_register (void ) +{ +type_register_static (&allwinner_h3_ccu_info); +} + +type_init (allwinner_h3_ccu_register)hw/misc/Makefile.objs +1
-0@@ -28,6 +28,7 @@ common-obj-$(CONFIG_MACIO) += macio/ common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o +common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o common-obj-$(CONFIG_NSERIES) += cbus.o common-obj-$(CONFIG_ECCMEMCTL) += eccmemctl.o
Re: [PATCH v4 03/20] hw/arm/allwinner-h3: add Clock Control Unit
Hi Philippe,
Quoted 91 lines · Philippe Mathieu-Daudé
Quoted 13 lines · Niek Linnenbank
The Clock Control Unit is responsible for clock signal generation, configuration and distribution in the Allwinner H3 System on Chip. This commit adds support for the Clock Control Unit which emulates a simple read/write register interface.
Signed-off-by Niek Linnenbank <[email protected]>--- include/hw/arm/allwinner-h3.h | 3 + include/hw/misc/allwinner-h3-ccu.h | 66 ++++++++ hw/arm/allwinner-h3.c | 9 +- hw/misc/allwinner-h3-ccu.c | 243 +++++++++++++++++++++++++++++ hw/misc/Makefile.objs | 1 + 5 files changed, 321 insertions(+), 1 deletion(-)Review
Quoted 4 lines
create mode 100644
include/hw/misc/allwinner-h3-ccu.hcreate mode 100644hw/misc/allwinner-h3-ccu.c(quoted diff) +0
-0
b/include/hw/arm/allwinner-h3.hReview
Quoted 28 lines
index
2aac9b78ec..abdc20871a100644include/hw/arm/allwinner-h3.h +3
-0@@ -39,6 +39,7 @@#include "hw/arm/boot.h" #include "hw/timer/allwinner-a10-pit.h" #include "hw/intc/arm_gic.h" +#include "hw/misc/allwinner-h3-ccu.h" #include "target/arm/cpu.h" /** @@ -55,6 +56,7 @@ enum {AW_H3_SRAM_A1 ,AW_H3_SRAM_A2 ,AW_H3_SRAM_C , +AW_H3_CCU ,AW_H3_PIT ,AW_H3_UART0 , AW_H3_UART1,@@ -97,6 +99,7 @@ typedef struct AwH3State {ARMCPU cpus[AW_H3_NUM_CPUS ];const hwaddr *memmap;AwA10PITState timer; +AwH3ClockCtlState ccu;GICState gic;MemoryRegion sram_a1;MemoryRegion sram_a2;(quoted diff) +0
-0
b/include/hw/misc/allwinner-h3-ccu.hQuoted 28 lines
new file mode 100644
index 0000000000..9c8a887782include/hw/misc/allwinner-h3-ccu.h new file +17
-0@@ -0,0 +1,66 @@ +/* +* Allwinner H3 Clock Control Unit emulation +* +* Copyright (C) 2019 Niek Linnenbank <[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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/ .
+ */include/hw/misc/allwinner-h3-ccu.h new file +4
-0+ +#ifndef HW_MISC_ALLWINNER_H3_CCU_H +#define HW_MISC_ALLWINNER_H3_CCU_H +include/hw/misc/allwinner-h3-ccu.h line 32
Quoted 10 lines
include/hw/misc/allwinner-h3-ccu.h new file +10
-0+#include "qom/object.h" +#include "hw/sysbus.h" + +/** +* @name Constants +* @{ +*/ + +/** Highest register address used by CCU device */ +#define AW_H3_CCU_REGS_MAXADDR (0x304)There might be a migration issue if one day we see some firmware accessing some undocumented register >
0x304(you'd need to migrate more than 0x304/4 registers, so increase allwinner_h3_ccu_vmstate.version_id.
Quoted 6 lines
I'd simply replace this definition by
#define AW_H3_CCU_IOSIZE 0x400And see comment in
write().
Good point, thanks I'll change that to 0x400!
Quoted 243 lines
include/hw/misc/allwinner-h3-ccu.h
Quoted 4 lines
include/hw/misc/allwinner-h3-ccu.h new file +3
-0+ +/** Total number of known registers */ +#define AW_H3_CCU_REGS_NUM (AW_H3_CCU_REGS_MAXADDR /
sizeof(uint32_t))hw/arm/allwinner-h3.c static void allwinner_h3_realize(DeviceState *dev,
Quoted 62 lines
include/hw/misc/allwinner-h3-ccu.h new file +31
-0+ +/** @} */ + +/** +* @name Object model +* @{ +*/ + +#define TYPE_AW_H3_CCU "allwinner-h3-ccu" +#define AW_H3_CCU (obj) \ + OBJECT_CHECK(AwH3ClockCtlState, (obj), TYPE_AW_H3_CCU) + +/** @} */ + +/** +* Allwinner H3 CCU object instance state. +*/ +typedef struct AwH3ClockCtlState { +/*< private >*/ +SysBusDevice parent_obj; +/*< public >*/ + +/** Maps I/O registers in physical memory */ +MemoryRegion iomem; + +/** Array of hardware registers */ +uint32_t regs[AW_H3_CCU_REGS_NUM ]; + +}AwH3ClockCtlState ; + +#endif /* HW_MISC_ALLWINNER_H3_CCU_H */ hw/arm/allwinner-h3.c +4
-1@@ -36,6 +36,7 @@ const hwaddr allwinner_h3_memmap[] = { [AW_H3_SRAM_A1] = 0x00000000, [AW_H3_SRAM_A2] = 0x00044000, [AW_H3_SRAM_C] = 0x00010000, + [AW_H3_CCU] = 0x01c20000, [AW_H3_PIT] = 0x01c20c00, [AW_H3_UART0] = 0x01c28000, [AW_H3_UART1] = 0x01c28400,@@ -77,7 +78,6 @@ struct AwH3Unimplemented { { "usb2", 0x01c1c000, 4 * KiB }, { "usb3", 0x01c1d000, 4 * KiB }, { "smc", 0x01c1e000, 4 * KiB }, - { "ccu", 0x01c20000, 1 * KiB }, { "pio", 0x01c20800, 1 * KiB }, { "owa", 0x01c21000, 1 * KiB }, { "pwm", 0x01c21400, 1 * KiB },@@ -172,6 +172,9 @@ static void allwinner_h3_init(Object *obj) "clk0-freq", &error_abort);object_property_add_alias (obj,"clk1-freq" ,OBJECT (&s->timer),"clk1-freq" , &error_abort); + +sysbus_init_child_obj (obj,"ccu" , &s->ccu,sizeof (s->ccu), +TYPE_AW_H3_CCU ); }static void allwinner_h3_realize (DeviceState *dev,Error **errp)@@ -277,6 +280,10 @@ static void allwinner_h3_realize(DeviceState *dev,Error **errp)
hw/arm/allwinner-h3.c static void allwinner_h3_realize(DeviceState *dev, · line 280
Quoted 1 line
hw/arm/allwinner-h3.c +0
-0memory_region_add_subregion(get_system_memory(),s->memmap[AW_H3_SRAM_C],
hw/arm/allwinner-h3.c static void allwinner_h3_realize(DeviceState *dev, Error **errp)
Quoted 7 lines
hw/arm/allwinner-h3.c +4
-0&s->sram_c); +/* Clock Control Unit */ +qdev_init_nofail (DEVICE (&s->ccu)); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->ccu),0 , s->memmap[AW_H3_CCU ]); +/* UART0. For future clocktree API: All UARTS are connected to
APB2_CLK. */hw/arm/allwinner-h3.c static void allwinner_h3_realize(DeviceState *dev, · line 289
Quoted 2 lines
hw/arm/allwinner-h3.c +0
-0serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART0], 2, qdev_get_gpio_in(DEVICE(&s->gic),
AW_H3_GIC_SPI_UART0),Quoted 107 lines
hw/misc/allwinner-h3-ccu.c new file +17
-0@@ -0,0 +1,243 @@ +/* +* Allwinner H3 Clock Control Unit emulation +* +* Copyright (C) 2019 Niek Linnenbank <[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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/ .
+ */hw/misc/allwinner-h3-ccu.c new file +82
-0+ +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "hw/sysbus.h" +#include "migration/vmstate.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "hw/misc/allwinner-h3-ccu.h" + +/* CCU register offsets */ +enum { +REG_PLL_CPUX =0x0000 ,/* PLL CPUX Control */ +REG_PLL_AUDIO =0x0008 ,/* PLL Audio Control */ +REG_PLL_VIDEO =0x0010 ,/* PLL Video Control */ +REG_PLL_VE =0x0018 ,/* PLL VE Control */ +REG_PLL_DDR =0x0020 ,/* PLL DDR Control */ +REG_PLL_PERIPH0 =0x0028 ,/* PLL Peripherals 0 Control */ +REG_PLL_GPU =0x0038 ,/* PLL GPU Control */ +REG_PLL_PERIPH1 =0x0044 ,/* PLL Peripherals 1 Control */ +REG_PLL_DE =0x0048 ,/* PLL Display Engine Control */ +REG_CPUX_AXI =0x0050 ,/* CPUX/AXI Configuration */ +REG_APB1 =0x0054 ,/* ARM Peripheral Bus 1 Config */ +REG_APB2 =0x0058 ,/* ARM Peripheral Bus 2 Config */ +REG_DRAM_CFG =0x00F4 ,/* DRAM Configuration */ +REG_MBUS =0x00FC ,/* MBUS Reset */ +REG_PLL_TIME0 =0x0200 ,/* PLL Stable Time 0 */ +REG_PLL_TIME1 =0x0204 ,/* PLL Stable Time 1 */ +REG_PLL_CPUX_BIAS =0x0220 ,/* PLL CPUX Bias */ +REG_PLL_AUDIO_BIAS =0x0224 ,/* PLL Audio Bias */ +REG_PLL_VIDEO_BIAS =0x0228 ,/* PLL Video Bias */ +REG_PLL_VE_BIAS =0x022C ,/* PLL VE Bias */ +REG_PLL_DDR_BIAS =0x0230 ,/* PLL DDR Bias */ +REG_PLL_PERIPH0_BIAS =0x0234 ,/* PLL Peripherals 0 Bias */ +REG_PLL_GPU_BIAS =0x023C ,/* PLL GPU Bias */ +REG_PLL_PERIPH1_BIAS =0x0244 ,/* PLL Peripherals 1 Bias */ +REG_PLL_DE_BIAS =0x0248 ,/* PLL Display Engine Bias */ +REG_PLL_CPUX_TUNING =0x0250 ,/* PLL CPUX Tuning */ +REG_PLL_DDR_TUNING =0x0260 ,/* PLL DDR Tuning */ +}; + +#define REG_INDEX (offset) (offset / sizeof(uint32_t)) + +/* CCU register flags */ +enum { +REG_DRAM_CFG_UPDATE = (1 <<16 ), +}; + +enum { +REG_PLL_ENABLE = (1 <<31 ), +REG_PLL_LOCK = (1 <<28 ), +}; + + +/* CCU register reset values */ +enum { +REG_PLL_CPUX_RST =0x00001000 , +REG_PLL_AUDIO_RST =0x00035514 , +REG_PLL_VIDEO_RST =0x03006207 , +REG_PLL_VE_RST =0x03006207 , +REG_PLL_DDR_RST =0x00001000 , +REG_PLL_PERIPH0_RST =0x00041811 , +REG_PLL_GPU_RST =0x03006207 , +REG_PLL_PERIPH1_RST =0x00041811 , +REG_PLL_DE_RST =0x03006207 , +REG_CPUX_AXI_RST =0x00010000 , +REG_APB1_RST =0x00001010 , +REG_APB2_RST =0x01000000 , +REG_DRAM_CFG_RST =0x00000000 , +REG_MBUS_RST =0x80000000 , +REG_PLL_TIME0_RST =0x000000FF , +REG_PLL_TIME1_RST =0x000000FF , +REG_PLL_CPUX_BIAS_RST =0x08100200 , +REG_PLL_AUDIO_BIAS_RST =0x10100000 , +REG_PLL_VIDEO_BIAS_RST =0x10100000 , +REG_PLL_VE_BIAS_RST =0x10100000 , +REG_PLL_DDR_BIAS_RST =0x81104000 , +REG_PLL_PERIPH0_BIAS_RST =0x10100010 , +REG_PLL_GPU_BIAS_RST =0x10100000 , +REG_PLL_PERIPH1_BIAS_RST =0x10100010 , +REG_PLL_DE_BIAS_RST =0x10100000 , +REG_PLL_CPUX_TUNING_RST =0x0A101000 , +REG_PLL_DDR_TUNING_RST =0x14880000 ,hw/misc/allwinner-h3-ccu.c
Quoted 10 lines
hw/misc/allwinner-h3-ccu.c new file +10
-0+}; + +static uint64_t allwinner_h3_ccu_read (void *opaque,hwaddr offset, +unsigned size) +{ +const AwH3ClockCtlState *s =AW_H3_CCU (opaque); +const uint32_t idx =REG_INDEX (offset); + +if (idx >=AW_H3_CCU_REGS_NUM ) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset0x%04x\n",
Quoted 1 line
+
__func__, (uint32_t)offset);See comment in
write().Quoted 4 lines
hw/misc/allwinner-h3-ccu.c new file +4
-0+return 0 ; + } + +return s->regs[idx];hw/misc/allwinner-h3-ccu.c
Quoted 10 lines
hw/misc/allwinner-h3-ccu.c new file +10
-0+} + +static void allwinner_h3_ccu_write (void *opaque,hwaddr offset, +uint64_t val,unsigned size) +{ +AwH3ClockCtlState *s =AW_H3_CCU (opaque); +const uint32_t idx =REG_INDEX (offset); + +if (idx >=AW_H3_CCU_REGS_NUM ) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset0x%04x\n",
Quoted 1 line
+
__func__, (uint32_t)offset);I'd replace this check by ...
Quoted 10 lines
hw/misc/allwinner-h3-ccu.c new file +10
-0+return ; + } + +switch (offset) { +case REG_DRAM_CFG :/* DRAM Configuration */ + val &= ~REG_DRAM_CFG_UPDATE ; +break ; +case REG_PLL_CPUX :/* PLL CPUX Control */ +case REG_PLL_AUDIO :/* PLL Audio Control */ +case REG_PLL_VIDEO :/* PLL Video Control */ hw/misc/allwinner-h3-ccu.c line 146
Quoted 10 lines
hw/misc/allwinner-h3-ccu.c new file +10
-0+case REG_PLL_VE :/* PLL VE Control */ +case REG_PLL_DDR :/* PLL DDR Control */ +case REG_PLL_PERIPH0 :/* PLL Peripherals 0 Control */ +case REG_PLL_GPU :/* PLL GPU Control */ +case REG_PLL_PERIPH1 :/* PLL Peripherals 1 Control */ +case REG_PLL_DE :/* PLL Display Engine Control */ +if (val ®_PLL_ENABLE ) { + val |=REG_PLL_LOCK ; + } +break ;
Quoted 6 lines
case
0x304...AW_H3_CCU_IOSIZE:
qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset
0x%04x\n",__func__, (uint32_t)offset); break;
OK, looks more compact indeed.
Quoted 12 lines
hw/misc/allwinner-h3-ccu.c
Quoted 3 lines
hw/misc/allwinner-h3-ccu.c new file +2
-0+default : + qemu_log_mask(LOG_UNIMP, "%s: unimplemented write offset0x%04x\n",
hw/misc/allwinner-h3-ccu.c line 154
Quoted 6 lines
hw/misc/allwinner-h3-ccu.c new file +6
-0+ __func__, (uint32_t)offset); +break ; + } + + s->regs[idx] = (uint32_t ) val; +}That said,
Quoted 3 lines
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Thanks!
Niek
Quoted 107 lines
Quoted 44 lines
hw/misc/allwinner-h3-ccu.c new file +43
-0+ +static const MemoryRegionOps allwinner_h3_ccu_ops = { + .read = allwinner_h3_ccu_read, + .write = allwinner_h3_ccu_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + }, + .impl.min_access_size =4 , +}; + +static void allwinner_h3_ccu_reset (DeviceState *dev) +{ +AwH3ClockCtlState *s =AW_H3_CCU (dev); + +/* Set default values for registers */ + s->regs[REG_INDEX (REG_PLL_CPUX )] =REG_PLL_CPUX_RST ; + s->regs[REG_INDEX (REG_PLL_AUDIO )] =REG_PLL_AUDIO_RST ; + s->regs[REG_INDEX (REG_PLL_VIDEO )] =REG_PLL_VIDEO_RST ; + s->regs[REG_INDEX (REG_PLL_VE )] =REG_PLL_VE_RST ; + s->regs[REG_INDEX (REG_PLL_DDR )] =REG_PLL_DDR_RST ; + s->regs[REG_INDEX (REG_PLL_PERIPH0 )] =REG_PLL_PERIPH0_RST ; + s->regs[REG_INDEX (REG_PLL_GPU )] =REG_PLL_GPU_RST ; + s->regs[REG_INDEX (REG_PLL_PERIPH1 )] =REG_PLL_PERIPH1_RST ; + s->regs[REG_INDEX (REG_PLL_DE )] =REG_PLL_DE_RST ; + s->regs[REG_INDEX (REG_CPUX_AXI )] =REG_CPUX_AXI_RST ; + s->regs[REG_INDEX (REG_APB1 )] =REG_APB1_RST ; + s->regs[REG_INDEX (REG_APB2 )] =REG_APB2_RST ; + s->regs[REG_INDEX (REG_DRAM_CFG )] =REG_DRAM_CFG_RST ; + s->regs[REG_INDEX (REG_MBUS )] =REG_MBUS_RST ; + s->regs[REG_INDEX (REG_PLL_TIME0 )] =REG_PLL_TIME0_RST ; + s->regs[REG_INDEX (REG_PLL_TIME1 )] =REG_PLL_TIME1_RST ; + s->regs[REG_INDEX (REG_PLL_CPUX_BIAS )] =REG_PLL_CPUX_BIAS_RST ; + s->regs[REG_INDEX (REG_PLL_AUDIO_BIAS )] =REG_PLL_AUDIO_BIAS_RST ; + s->regs[REG_INDEX (REG_PLL_VIDEO_BIAS )] =REG_PLL_VIDEO_BIAS_RST ; + s->regs[REG_INDEX (REG_PLL_VE_BIAS )] =REG_PLL_VE_BIAS_RST ; + s->regs[REG_INDEX (REG_PLL_DDR_BIAS )] =REG_PLL_DDR_BIAS_RST ; + s->regs[REG_INDEX (REG_PLL_PERIPH0_BIAS )] =REG_PLL_PERIPH0_BIAS_RST ; + s->regs[REG_INDEX (REG_PLL_GPU_BIAS )] =REG_PLL_GPU_BIAS_RST ; + s->regs[REG_INDEX (REG_PLL_PERIPH1_BIAS )] =REG_PLL_PERIPH1_BIAS_RST ; + s->regs[REG_INDEX (REG_PLL_DE_BIAS )] =REG_PLL_DE_BIAS_RST ; + s->regs[REG_INDEX (REG_PLL_CPUX_TUNING )] =REG_PLL_CPUX_TUNING_RST ;hw/misc/allwinner-h3-ccu.c
Quoted 10 lines
hw/misc/allwinner-h3-ccu.c new file +10
-0+ s->regs[REG_INDEX (REG_PLL_DDR_TUNING )] =REG_PLL_DDR_TUNING_RST ; +} + +static void allwinner_h3_ccu_init (Object *obj) +{ +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); +AwH3ClockCtlState *s =AW_H3_CCU (obj); + +/* Memory mapping */ + memory_region_init_io(&s->iomem, OBJECT(s), &allwinner_h3_ccu_ops,s,
hw/misc/allwinner-h3-ccu.c
Quoted 10 lines
hw/misc/allwinner-h3-ccu.c new file +10
-0+ TYPE_AW_H3_CCU, 1 * KiB); +sysbus_init_mmio (sbd, &s->iomem); +} + +static const VMStateDescription allwinner_h3_ccu_vmstate = { + .name ="allwinner-h3-ccu" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { + VMSTATE_UINT32_ARRAY(regs, AwH3ClockCtlState,
AW_H3_CCU_REGS_NUM),Quoted 39 lines
hw/misc/allwinner-h3-ccu.c new file +26
-0+ VMSTATE_END_OF_LIST() + } +}; + +static void allwinner_h3_ccu_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->reset = allwinner_h3_ccu_reset; + dc->vmsd = &allwinner_h3_ccu_vmstate; +} + +static const TypeInfo allwinner_h3_ccu_info = { + .name =TYPE_AW_H3_CCU , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_init = allwinner_h3_ccu_init, + .instance_size =sizeof (AwH3ClockCtlState), + .class_init = allwinner_h3_ccu_class_init, +}; + +static void allwinner_h3_ccu_register (void ) +{ +type_register_static (&allwinner_h3_ccu_info); +} + +type_init (allwinner_h3_ccu_register)hw/misc/Makefile.objs +1
-0@@ -28,6 +28,7 @@ common-obj-$(CONFIG_MACIO) += macio/ common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o +common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o common-obj-$(CONFIG_NSERIES) += cbus.o common-obj-$(CONFIG_ECCMEMCTL) += eccmemctl.o
Signature · 1 line
Niek Linnenbank
PATCH v4 4/20 hw/arm/allwinner-h3: add USB host controller
In reply to Niek LinnenbankThe Allwinner H3 System on Chip contains multiple USB 2.0 bus connections which provide software access using the Enhanced Host Controller Interface (EHCI) and Open Host Controller Interface (OHCI) interfaces. This commit adds support for both interfaces in the Allwinner H3 System on Chip.
--- hw/usb/hcd-ehci.h | 1 + include/hw/arm/allwinner-h3.h | 8 ++++++ hw/arm/allwinner-h3.c | 52 ++++++++++++++++++++++++++++++++--- hw/usb/hcd-ehci-sysbus.c | 17 ++++++++++++ 4 files changed, 74 insertions(+), 4 deletions(-)
hw/usb/hcd-ehci.h +1 -0
@@ -342,6 +342,7 @@ typedef struct EHCIPCIState {#define TYPE_SYS_BUS_EHCI "sysbus-ehci-usb"#define TYPE_PLATFORM_EHCI "platform-ehci-usb"#define TYPE_EXYNOS4210_EHCI "exynos4210-ehci-usb" +#define TYPE_AW_H3_EHCI "aw-h3-ehci-usb"#define TYPE_TEGRA2_EHCI "tegra2-ehci-usb"#define TYPE_PPC4xx_EHCI "ppc4xx-ehci-usb"#define TYPE_FUSBH200_EHCI "fusbh200-ehci-usb"
include/hw/arm/allwinner-h3.h +8 -0
@@ -56,6 +56,14 @@ enum {AW_H3_SRAM_A1 ,AW_H3_SRAM_A2 ,AW_H3_SRAM_C , +AW_H3_EHCI0 , +AW_H3_OHCI0 , +AW_H3_EHCI1 , +AW_H3_OHCI1 , +AW_H3_EHCI2 , +AW_H3_OHCI2 , +AW_H3_EHCI3 , +AW_H3_OHCI3 ,AW_H3_CCU ,AW_H3_PIT , AW_H3_UART0,
hw/arm/allwinner-h3.c +48 -4
82 lines not on this page · raw message
hw/usb/hcd-ehci-sysbus.c +17 -0
@@ -145,6 +145,22 @@ static const TypeInfo ehci_exynos4210_type_info = { .class_init = ehci_exynos4210_class_init, }; +static void ehci_aw_h3_class_init (ObjectClass *oc,void *data) +{ +SysBusEHCIClass *sec =SYS_BUS_EHCI_CLASS (oc); +DeviceClass *dc =DEVICE_CLASS (oc); + + sec->capsbase =0x0 ; + sec->opregbase =0x10 ; +set_bit (DEVICE_CATEGORY_USB , dc->categories); +} + +static const TypeInfo ehci_aw_h3_type_info = { + .name =TYPE_AW_H3_EHCI , + .parent =TYPE_SYS_BUS_EHCI , + .class_init = ehci_aw_h3_class_init, +}; +static void ehci_tegra2_class_init (ObjectClass *oc,void *data) {SysBusEHCIClass *sec =SYS_BUS_EHCI_CLASS (oc);
@@ -267,6 +283,7 @@ static void ehci_sysbus_register_types(void)type_register_static (&ehci_platform_type_info);type_register_static (&ehci_xlnx_type_info);type_register_static (&ehci_exynos4210_type_info); +type_register_static (&ehci_aw_h3_type_info);type_register_static (&ehci_tegra2_type_info);type_register_static (&ehci_ppc4xx_type_info);type_register_static (&ehci_fusbh200_type_info);
Signature · 1 line
2.17.1
Re: [PATCH v4 04/20] hw/arm/allwinner-h3: add USB host controller
Quoted 75 lines · Niek Linnenbank
The Allwinner H3 System on Chip contains multiple USB 2.0 bus connections which provide software access using the Enhanced Host Controller Interface (EHCI) and Open Host Controller Interface (OHCI) interfaces. This commit adds support for both interfaces in the Allwinner H3 System on Chip.
Signed-off-by Niek Linnenbank <[email protected]>Reviewed-by Gerd Hoffmann <[email protected]>--- hw/usb/hcd-ehci.h | 1 + include/hw/arm/allwinner-h3.h | 8 ++++++ hw/arm/allwinner-h3.c | 52 ++++++++++++++++++++++++++++++++--- hw/usb/hcd-ehci-sysbus.c | 17 ++++++++++++ 4 files changed, 74 insertions(+), 4 deletions(-)hw/usb/hcd-ehci.h +1
-0@@ -342,6 +342,7 @@ typedef struct EHCIPCIState {#define TYPE_SYS_BUS_EHCI "sysbus-ehci-usb"#define TYPE_PLATFORM_EHCI "platform-ehci-usb"#define TYPE_EXYNOS4210_EHCI "exynos4210-ehci-usb" +#define TYPE_AW_H3_EHCI "aw-h3-ehci-usb"#define TYPE_TEGRA2_EHCI "tegra2-ehci-usb"#define TYPE_PPC4xx_EHCI "ppc4xx-ehci-usb"#define TYPE_FUSBH200_EHCI "fusbh200-ehci-usb"include/hw/arm/allwinner-h3.h +8
-0@@ -56,6 +56,14 @@ enum {AW_H3_SRAM_A1 ,AW_H3_SRAM_A2 ,AW_H3_SRAM_C , +AW_H3_EHCI0 , +AW_H3_OHCI0 , +AW_H3_EHCI1 , +AW_H3_OHCI1 , +AW_H3_EHCI2 , +AW_H3_OHCI2 , +AW_H3_EHCI3 , +AW_H3_OHCI3 ,AW_H3_CCU ,AW_H3_PIT , AW_H3_UART0,hw/arm/allwinner-h3.c +9
-0@@ -28,6 +28,7 @@#include "hw/sysbus.h" #include "hw/char/serial.h" #include "hw/misc/unimp.h" +#include "hw/usb/hcd-ehci.h" #include "sysemu/sysemu.h" #include "hw/arm/allwinner-h3.h" @@ -36,6 +37,14 @@ const hwaddr allwinner_h3_memmap[] = { [AW_H3_SRAM_A1] = 0x00000000, [AW_H3_SRAM_A2] = 0x00044000, [AW_H3_SRAM_C] = 0x00010000, + [AW_H3_EHCI0] = 0x01c1a000, + [AW_H3_OHCI0] = 0x01c1a400, + [AW_H3_EHCI1] = 0x01c1b000, + [AW_H3_OHCI1] = 0x01c1b400, + [AW_H3_EHCI2] = 0x01c1c000, + [AW_H3_OHCI2] = 0x01c1c400, + [AW_H3_EHCI3] = 0x01c1d000, + [AW_H3_OHCI3] = 0x01c1d400, [AW_H3_CCU] = 0x01c20000, [AW_H3_PIT] = 0x01c20c00, [AW_H3_UART0] = 0x01c28000,@@ -73,10 +82,10 @@ struct AwH3Unimplemented { { "msgbox", 0x01c17000, 4 * KiB },
hw/arm/allwinner-h3.c struct AwH3Unimplemented { · line 88
Quoted 10 lines
hw/arm/allwinner-h3.c +4
-4{ "spinlock", 0x01c18000, 4 * KiB }, { "usb0-otg", 0x01c19000, 4 * KiB }, - { "usb0", 0x01c1a000, 4 * KiB }, - { "usb1", 0x01c1b000, 4 * KiB }, - { "usb2", 0x01c1c000, 4 * KiB }, - { "usb3", 0x01c1d000, 4 * KiB }, + { "usb0-phy", 0x01c1a000, 4 * KiB }, + { "usb1-phy", 0x01c1b000, 4 * KiB }, + { "usb2-phy", 0x01c1c000, 4 * KiB }, + { "usb3-phy", 0x01c1d000, 4 * KiB },
As in v3 comment, this can be done in patch #1.
Quoted 88 lines
hw/arm/allwinner-h3.c +35
-0{ "smc", 0x01c1e000, 4 * KiB }, { "pio", 0x01c20800, 1 * KiB }, { "owa", 0x01c21000, 1 * KiB },@@ -144,6 +153,14 @@ enum {AW_H3_GIC_SPI_UART3 =3 ,AW_H3_GIC_SPI_TIMER0 =18 ,AW_H3_GIC_SPI_TIMER1 =19 , +AW_H3_GIC_SPI_EHCI0 =72 , +AW_H3_GIC_SPI_OHCI0 =73 , +AW_H3_GIC_SPI_EHCI1 =74 , +AW_H3_GIC_SPI_OHCI1 =75 , +AW_H3_GIC_SPI_EHCI2 =76 , +AW_H3_GIC_SPI_OHCI2 =77 , +AW_H3_GIC_SPI_EHCI3 =78 , + AW_H3_GIC_SPI_OHCI3 = 79, };/* Allwinner H3 general constants */ @@ -284,6 +301,33 @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)qdev_init_nofail (DEVICE (&s->ccu));sysbus_mmio_map (SYS_BUS_DEVICE (&s->ccu),0 , s->memmap[AW_H3_CCU ]); +/* Universal Serial Bus */ +sysbus_create_simple (TYPE_AW_H3_EHCI , s->memmap[AW_H3_EHCI0 ], +qdev_get_gpio_in (DEVICE (&s->gic), +AW_H3_GIC_SPI_EHCI0 )); +sysbus_create_simple (TYPE_AW_H3_EHCI , s->memmap[AW_H3_EHCI1 ], +qdev_get_gpio_in (DEVICE (&s->gic), +AW_H3_GIC_SPI_EHCI1 )); +sysbus_create_simple (TYPE_AW_H3_EHCI , s->memmap[AW_H3_EHCI2 ], +qdev_get_gpio_in (DEVICE (&s->gic), +AW_H3_GIC_SPI_EHCI2 )); +sysbus_create_simple (TYPE_AW_H3_EHCI , s->memmap[AW_H3_EHCI3 ], +qdev_get_gpio_in (DEVICE (&s->gic), +AW_H3_GIC_SPI_EHCI3 )); + +sysbus_create_simple ("sysbus-ohci" , s->memmap[AW_H3_OHCI0 ], +qdev_get_gpio_in (DEVICE (&s->gic), +AW_H3_GIC_SPI_OHCI0 )); +sysbus_create_simple ("sysbus-ohci" , s->memmap[AW_H3_OHCI1 ], +qdev_get_gpio_in (DEVICE (&s->gic), +AW_H3_GIC_SPI_OHCI1 )); +sysbus_create_simple ("sysbus-ohci" , s->memmap[AW_H3_OHCI2 ], +qdev_get_gpio_in (DEVICE (&s->gic), +AW_H3_GIC_SPI_OHCI2 )); +sysbus_create_simple ("sysbus-ohci" , s->memmap[AW_H3_OHCI3 ], +qdev_get_gpio_in (DEVICE (&s->gic), +AW_H3_GIC_SPI_OHCI3 )); +/* UART0. For future clocktree API: All UARTS are connected to APB2_CLK. */ serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART0], 2, qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_UART0),hw/usb/hcd-ehci-sysbus.c +17
-0@@ -145,6 +145,22 @@ static const TypeInfo ehci_exynos4210_type_info = { .class_init = ehci_exynos4210_class_init, }; +static void ehci_aw_h3_class_init (ObjectClass *oc,void *data) +{ +SysBusEHCIClass *sec =SYS_BUS_EHCI_CLASS (oc); +DeviceClass *dc =DEVICE_CLASS (oc); + + sec->capsbase =0x0 ; + sec->opregbase =0x10 ; +set_bit (DEVICE_CATEGORY_USB , dc->categories); +} + +static const TypeInfo ehci_aw_h3_type_info = { + .name =TYPE_AW_H3_EHCI , + .parent =TYPE_SYS_BUS_EHCI , + .class_init = ehci_aw_h3_class_init, +}; +static void ehci_tegra2_class_init (ObjectClass *oc,void *data) {SysBusEHCIClass *sec =SYS_BUS_EHCI_CLASS (oc);@@ -267,6 +283,7 @@ static void ehci_sysbus_register_types(void)type_register_static (&ehci_platform_type_info);type_register_static (&ehci_xlnx_type_info);type_register_static (&ehci_exynos4210_type_info); +type_register_static (&ehci_aw_h3_type_info);type_register_static (&ehci_tegra2_type_info);type_register_static (&ehci_ppc4xx_type_info);type_register_static (&ehci_fusbh200_type_info);
Re: [PATCH v4 04/20] hw/arm/allwinner-h3: add USB host controller
Quoted 88 lines · Philippe Mathieu-Daudé
Quoted 74 lines · Niek Linnenbank
The Allwinner H3 System on Chip contains multiple USB 2.0 bus connections which provide software access using the Enhanced Host Controller Interface (EHCI) and Open Host Controller Interface (OHCI) interfaces. This commit adds support for both interfaces in the Allwinner H3 System on Chip.
Signed-off-by Niek Linnenbank <[email protected]>Reviewed-by Gerd Hoffmann <[email protected]>---
hw/usb/hcd-ehci.h | 1 +include/hw/arm/allwinner-h3.h| 8 ++++++ hw/arm/allwinner-h3.c | 52 ++++++++++++++++++++++++++++++++--- hw/usb/hcd-ehci-sysbus.c | 17 ++++++++++++4 files changed, 74 insertions(+), 4 deletions(-)hw/usb/hcd-ehci.h +1
-0@@ -342,6 +342,7 @@ typedef struct EHCIPCIState { #define TYPE_SYS_BUS_EHCI "sysbus-ehci-usb" #define TYPE_PLATFORM_EHCI "platform-ehci-usb" #define TYPE_EXYNOS4210_EHCI "exynos4210-ehci-usb" +#define TYPE_AW_H3_EHCI "aw-h3-ehci-usb" #define TYPE_TEGRA2_EHCI "tegra2-ehci-usb" #define TYPE_PPC4xx_EHCI "ppc4xx-ehci-usb" #define TYPE_FUSBH200_EHCI "fusbh200-ehci-usb"include/hw/arm/allwinner-h3.h +8
-0@@ -56,6 +56,14 @@ enum { AW_H3_SRAM_A1, AW_H3_SRAM_A2, AW_H3_SRAM_C, + AW_H3_EHCI0, + AW_H3_OHCI0, + AW_H3_EHCI1, + AW_H3_OHCI1, + AW_H3_EHCI2, + AW_H3_OHCI2, + AW_H3_EHCI3, + AW_H3_OHCI3, AW_H3_CCU, AW_H3_PIT, AW_H3_UART0,hw/arm/allwinner-h3.c +9
-0@@ -28,6 +28,7 @@ #include "hw/sysbus.h" #include "hw/char/serial.h" #include "hw/misc/unimp.h" +#include "hw/usb/hcd-ehci.h" #include "sysemu/sysemu.h" #include "hw/arm/allwinner-h3.h"@@ -36,6 +37,14 @@ const hwaddr allwinner_h3_memmap[] = { [AW_H3_SRAM_A1] = 0x00000000, [AW_H3_SRAM_A2] = 0x00044000, [AW_H3_SRAM_C] = 0x00010000, + [AW_H3_EHCI0] = 0x01c1a000, + [AW_H3_OHCI0] = 0x01c1a400, + [AW_H3_EHCI1] = 0x01c1b000, + [AW_H3_OHCI1] = 0x01c1b400, + [AW_H3_EHCI2] = 0x01c1c000, + [AW_H3_OHCI2] = 0x01c1c400, + [AW_H3_EHCI3] = 0x01c1d000, + [AW_H3_OHCI3] = 0x01c1d400, [AW_H3_CCU] = 0x01c20000, [AW_H3_PIT] = 0x01c20c00, [AW_H3_UART0] = 0x01c28000,@@ -73,10 +82,10 @@ struct AwH3Unimplemented { { "msgbox", 0x01c17000, 4 * KiB },hw/arm/allwinner-h3.c struct AwH3Unimplemented { · line 88
Quoted 10 lines
hw/arm/allwinner-h3.c +4
-4{ "spinlock", 0x01c18000, 4 * KiB }, { "usb0-otg", 0x01c19000, 4 * KiB }, - { "usb0", 0x01c1a000, 4 * KiB }, - { "usb1", 0x01c1b000, 4 * KiB }, - { "usb2", 0x01c1c000, 4 * KiB }, - { "usb3", 0x01c1d000, 4 * KiB }, + { "usb0-phy", 0x01c1a000, 4 * KiB }, + { "usb1-phy", 0x01c1b000, 4 * KiB }, + { "usb2-phy", 0x01c1c000, 4 * KiB }, + { "usb3-phy", 0x01c1d000, 4 * KiB },As in v3 comment, this can be done in patch #1.
Quoted 2 lines
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Err, this patch is incomplete, when using ./configure --without-default-devices:
$ qemu-system-arm -M orangepi-pc qemu-system-arm: invalid accelerator kvm qemu-system-arm: falling back to tcg qemu-system-arm: Unknown device 'aw-h3-ehci-usb' for default sysbus qemu-system-arm: Unknown device 'sysbus-ohci' for default sysbus Aborted (core dumped)
You need to amend:
-- >8 --
hw/arm/Kconfig +2 -0
@@ -302,6 +302,8 @@ config ALLWINNER_H3 select ARM_TIMER select ARM_GIC select UNIMP + select USB_OHCI + select USB_EHCI_SYSBUS config RASPI bool
---
R/T-b tags can stay with this amended.
Quoted 86 lines
Quoted 86 lines
hw/arm/allwinner-h3.c +35
-0{ "smc", 0x01c1e000, 4 * KiB }, { "pio", 0x01c20800, 1 * KiB }, { "owa", 0x01c21000, 1 * KiB },@@ -144,6 +153,14 @@ enum { AW_H3_GIC_SPI_UART3 = 3, AW_H3_GIC_SPI_TIMER0 = 18, AW_H3_GIC_SPI_TIMER1 = 19, + AW_H3_GIC_SPI_EHCI0 = 72, + AW_H3_GIC_SPI_OHCI0 = 73, + AW_H3_GIC_SPI_EHCI1 = 74, + AW_H3_GIC_SPI_OHCI1 = 75, + AW_H3_GIC_SPI_EHCI2 = 76, + AW_H3_GIC_SPI_OHCI2 = 77, + AW_H3_GIC_SPI_EHCI3 = 78, + AW_H3_GIC_SPI_OHCI3 = 79, }; /* Allwinner H3 general constants */@@ -284,6 +301,33 @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp) qdev_init_nofail(DEVICE(&s->ccu)); sysbus_mmio_map(SYS_BUS_DEVICE(&s->ccu), 0, s->memmap[AW_H3_CCU]); + /* Universal Serial Bus */ + sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0], + qdev_get_gpio_in(DEVICE(&s->gic), + AW_H3_GIC_SPI_EHCI0)); + sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI1], + qdev_get_gpio_in(DEVICE(&s->gic), + AW_H3_GIC_SPI_EHCI1)); + sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI2], + qdev_get_gpio_in(DEVICE(&s->gic), + AW_H3_GIC_SPI_EHCI2)); + sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI3], + qdev_get_gpio_in(DEVICE(&s->gic), + AW_H3_GIC_SPI_EHCI3)); + + sysbus_create_simple("sysbus-ohci", s->memmap[AW_H3_OHCI0], + qdev_get_gpio_in(DEVICE(&s->gic), + AW_H3_GIC_SPI_OHCI0)); + sysbus_create_simple("sysbus-ohci", s->memmap[AW_H3_OHCI1], + qdev_get_gpio_in(DEVICE(&s->gic), + AW_H3_GIC_SPI_OHCI1)); + sysbus_create_simple("sysbus-ohci", s->memmap[AW_H3_OHCI2], + qdev_get_gpio_in(DEVICE(&s->gic), + AW_H3_GIC_SPI_OHCI2)); + sysbus_create_simple("sysbus-ohci", s->memmap[AW_H3_OHCI3], + qdev_get_gpio_in(DEVICE(&s->gic), + AW_H3_GIC_SPI_OHCI3)); + /* UART0. For future clocktree API: All UARTS are connected to APB2_CLK. */ serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART0], 2, qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_UART0),hw/usb/hcd-ehci-sysbus.c +17
-0@@ -145,6 +145,22 @@ static const TypeInfo ehci_exynos4210_type_info = { .class_init = ehci_exynos4210_class_init, }; +static void ehci_aw_h3_class_init (ObjectClass *oc,void *data) +{ + SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc); + DeviceClass *dc = DEVICE_CLASS(oc); + + sec->capsbase = 0x0; + sec->opregbase = 0x10; + set_bit(DEVICE_CATEGORY_USB, dc->categories); +} + +static const TypeInfo ehci_aw_h3_type_info = { + .name = TYPE_AW_H3_EHCI, + .parent = TYPE_SYS_BUS_EHCI, + .class_init = ehci_aw_h3_class_init, +}; + static void ehci_tegra2_class_init(ObjectClass *oc, void *data) { SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc);@@ -267,6 +283,7 @@ static void ehci_sysbus_register_types(void) type_register_static(&ehci_platform_type_info); type_register_static(&ehci_xlnx_type_info); type_register_static(&ehci_exynos4210_type_info); + type_register_static(&ehci_aw_h3_type_info); type_register_static(&ehci_tegra2_type_info); type_register_static(&ehci_ppc4xx_type_info); type_register_static(&ehci_fusbh200_type_info);
Re: [PATCH v4 04/20] hw/arm/allwinner-h3: add USB host controller
Quoted 96 lines · Philippe Mathieu-Daudé
Quoted 89 lines · Philippe Mathieu-Daudé
Quoted 75 lines · Niek Linnenbank
The Allwinner H3 System on Chip contains multiple USB 2.0 bus connections which provide software access using the Enhanced Host Controller Interface (EHCI) and Open Host Controller Interface (OHCI) interfaces. This commit adds support for both interfaces in the Allwinner H3 System on Chip.
Signed-off-by Niek Linnenbank <[email protected]>Reviewed-by Gerd Hoffmann <[email protected]>--- hw/usb/hcd-ehci.h | 1 + include/hw/arm/allwinner-h3.h | 8 ++++++ hw/arm/allwinner-h3.c | 52 ++++++++++++++++++++++++++++++++--- hw/usb/hcd-ehci-sysbus.c | 17 ++++++++++++ 4 files changed, 74 insertions(+), 4 deletions(-)hw/usb/hcd-ehci.h +1
-0@@ -342,6 +342,7 @@ typedef struct EHCIPCIState {#define TYPE_SYS_BUS_EHCI "sysbus-ehci-usb"#define TYPE_PLATFORM_EHCI "platform-ehci-usb"#define TYPE_EXYNOS4210_EHCI "exynos4210-ehci-usb" +#define TYPE_AW_H3_EHCI "aw-h3-ehci-usb"#define TYPE_TEGRA2_EHCI "tegra2-ehci-usb"#define TYPE_PPC4xx_EHCI "ppc4xx-ehci-usb"#define TYPE_FUSBH200_EHCI "fusbh200-ehci-usb"include/hw/arm/allwinner-h3.h +8
-0@@ -56,6 +56,14 @@ enum {AW_H3_SRAM_A1 ,AW_H3_SRAM_A2 ,AW_H3_SRAM_C , +AW_H3_EHCI0 , +AW_H3_OHCI0 , +AW_H3_EHCI1 , +AW_H3_OHCI1 , +AW_H3_EHCI2 , +AW_H3_OHCI2 , +AW_H3_EHCI3 , +AW_H3_OHCI3 ,AW_H3_CCU ,AW_H3_PIT , AW_H3_UART0,hw/arm/allwinner-h3.c +9
-0@@ -28,6 +28,7 @@#include "hw/sysbus.h" #include "hw/char/serial.h" #include "hw/misc/unimp.h" +#include "hw/usb/hcd-ehci.h" #include "sysemu/sysemu.h" #include "hw/arm/allwinner-h3.h" @@ -36,6 +37,14 @@ const hwaddr allwinner_h3_memmap[] = { [AW_H3_SRAM_A1] = 0x00000000, [AW_H3_SRAM_A2] = 0x00044000, [AW_H3_SRAM_C] = 0x00010000, + [AW_H3_EHCI0] = 0x01c1a000, + [AW_H3_OHCI0] = 0x01c1a400, + [AW_H3_EHCI1] = 0x01c1b000, + [AW_H3_OHCI1] = 0x01c1b400, + [AW_H3_EHCI2] = 0x01c1c000, + [AW_H3_OHCI2] = 0x01c1c400, + [AW_H3_EHCI3] = 0x01c1d000, + [AW_H3_OHCI3] = 0x01c1d400, [AW_H3_CCU] = 0x01c20000, [AW_H3_PIT] = 0x01c20c00, [AW_H3_UART0] = 0x01c28000,@@ -73,10 +82,10 @@ struct AwH3Unimplemented { { "msgbox", 0x01c17000, 4 * KiB },hw/arm/allwinner-h3.c struct AwH3Unimplemented { · line 88
Quoted 10 lines
hw/arm/allwinner-h3.c +4
-4{ "spinlock", 0x01c18000, 4 * KiB }, { "usb0-otg", 0x01c19000, 4 * KiB }, - { "usb0", 0x01c1a000, 4 * KiB }, - { "usb1", 0x01c1b000, 4 * KiB }, - { "usb2", 0x01c1c000, 4 * KiB }, - { "usb3", 0x01c1d000, 4 * KiB }, + { "usb0-phy", 0x01c1a000, 4 * KiB }, + { "usb1-phy", 0x01c1b000, 4 * KiB }, + { "usb2-phy", 0x01c1c000, 4 * KiB }, + { "usb3-phy", 0x01c1d000, 4 * KiB },As in v3 comment, this can be done in patch #1.
Quoted 2 lines
Reviewed-by Philippe Mathieu-Daudé <[email protected]>Err, this patch is incomplete, when using ./configure --without-default-devices:
Quoted 7 lines
$ qemu-system-arm -M orangepi-pc qemu-system-arm: invalid accelerator kvm qemu-system-arm: falling back to tcg qemu-system-arm: Unknown device 'aw-h3-ehci-usb' for default sysbus qemu-system-arm: Unknown device 'sysbus-ohci' for default sysbus Aborted (core dumped)
Thanks for pointing this out, I was not aware at all that the --without-default-devices option existed.
It's not in the configure --help message also.
I tried to re-produce the error by running:
$ ./configure --target-list=arm-softmmu --without-default-devices; make -j5 $ ./arm-softmmu/qemu-system-arm -M orangepi-pc
On my laptop it didn't give the error, I think because somehow the build system did select
the USB config items (even tho they were missing for the ALLWINNER_H3 item in hw/arm/Kconfig):
$ grep USB arm-softmmu/config-devices.mak CONFIG_TUSB6010=y CONFIG_USB=y CONFIG_USB_EHCI=y CONFIG_USB_EHCI_SYSBUS=y CONFIG_USB_MUSB=y CONFIG_USB_OHCI=y
Is there any other option you used in addition to --without-default-devices to trigger the error?
I also searched for something in configure to select/filter on machines to build, but I don't see that yet.
Nevertheless I will surely add the fix below to the patch.
Regards,
Niek
Quoted 110 lines
You need to amend:
-- >8 --
hw/arm/Kconfig +2
-1@@ -302,6 +302,8 @@ config ALLWINNER_H3 select ARM_TIMER select ARM_GIC select UNIMP + select USB_OHCI + select USB_EHCI_SYSBUS config RASPI bool ---R/T-b tags can stay with this amended.
Quoted 88 lines
Quoted 88 lines
hw/arm/allwinner-h3.c +35
-0{ "smc", 0x01c1e000, 4 * KiB }, { "pio", 0x01c20800, 1 * KiB }, { "owa", 0x01c21000, 1 * KiB },@@ -144,6 +153,14 @@ enum {AW_H3_GIC_SPI_UART3 =3 ,AW_H3_GIC_SPI_TIMER0 =18 ,AW_H3_GIC_SPI_TIMER1 =19 , +AW_H3_GIC_SPI_EHCI0 =72 , +AW_H3_GIC_SPI_OHCI0 =73 , +AW_H3_GIC_SPI_EHCI1 =74 , +AW_H3_GIC_SPI_OHCI1 =75 , +AW_H3_GIC_SPI_EHCI2 =76 , +AW_H3_GIC_SPI_OHCI2 =77 , +AW_H3_GIC_SPI_EHCI3 =78 , + AW_H3_GIC_SPI_OHCI3 = 79, };/* Allwinner H3 general constants */ @@ -284,6 +301,33 @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)qdev_init_nofail (DEVICE (&s->ccu));sysbus_mmio_map (SYS_BUS_DEVICE (&s->ccu),0 , s->memmap[AW_H3_CCU ]); +/* Universal Serial Bus */ +sysbus_create_simple (TYPE_AW_H3_EHCI , s->memmap[AW_H3_EHCI0 ], +qdev_get_gpio_in (DEVICE (&s->gic), +AW_H3_GIC_SPI_EHCI0 )); +sysbus_create_simple (TYPE_AW_H3_EHCI , s->memmap[AW_H3_EHCI1 ], +qdev_get_gpio_in (DEVICE (&s->gic), +AW_H3_GIC_SPI_EHCI1 )); +sysbus_create_simple (TYPE_AW_H3_EHCI , s->memmap[AW_H3_EHCI2 ], +qdev_get_gpio_in (DEVICE (&s->gic), +AW_H3_GIC_SPI_EHCI2 )); +sysbus_create_simple (TYPE_AW_H3_EHCI , s->memmap[AW_H3_EHCI3 ], +qdev_get_gpio_in (DEVICE (&s->gic), +AW_H3_GIC_SPI_EHCI3 )); + +sysbus_create_simple ("sysbus-ohci" , s->memmap[AW_H3_OHCI0 ], +qdev_get_gpio_in (DEVICE (&s->gic), +AW_H3_GIC_SPI_OHCI0 )); +sysbus_create_simple ("sysbus-ohci" , s->memmap[AW_H3_OHCI1 ], +qdev_get_gpio_in (DEVICE (&s->gic), +AW_H3_GIC_SPI_OHCI1 )); +sysbus_create_simple ("sysbus-ohci" , s->memmap[AW_H3_OHCI2 ], +qdev_get_gpio_in (DEVICE (&s->gic), +AW_H3_GIC_SPI_OHCI2 )); +sysbus_create_simple ("sysbus-ohci" , s->memmap[AW_H3_OHCI3 ], +qdev_get_gpio_in (DEVICE (&s->gic), +AW_H3_GIC_SPI_OHCI3 )); +/* UART0. For future clocktree API: All UARTS are connected to
APB2_CLK. */serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART0], 2, qdev_get_gpio_in(DEVICE(&s->gic),
AW_H3_GIC_SPI_UART0),hw/usb/hcd-ehci-sysbus.c +17
-0@@ -145,6 +145,22 @@ static const TypeInfo ehci_exynos4210_type_info = { .class_init = ehci_exynos4210_class_init, }; +static void ehci_aw_h3_class_init (ObjectClass *oc,void *data) +{ +SysBusEHCIClass *sec =SYS_BUS_EHCI_CLASS (oc); +DeviceClass *dc =DEVICE_CLASS (oc); + + sec->capsbase =0x0 ; + sec->opregbase =0x10 ; +set_bit (DEVICE_CATEGORY_USB , dc->categories); +} + +static const TypeInfo ehci_aw_h3_type_info = { + .name =TYPE_AW_H3_EHCI , + .parent =TYPE_SYS_BUS_EHCI , + .class_init = ehci_aw_h3_class_init, +}; +static void ehci_tegra2_class_init (ObjectClass *oc,void *data) {SysBusEHCIClass *sec =SYS_BUS_EHCI_CLASS (oc);@@ -267,6 +283,7 @@ static void ehci_sysbus_register_types(void)type_register_static (&ehci_platform_type_info);type_register_static (&ehci_xlnx_type_info);type_register_static (&ehci_exynos4210_type_info); +type_register_static (&ehci_aw_h3_type_info);type_register_static (&ehci_tegra2_type_info);type_register_static (&ehci_ppc4xx_type_info);type_register_static (&ehci_fusbh200_type_info);
Signature · 1 line
Niek Linnenbank
Re: [PATCH v4 04/20] hw/arm/allwinner-h3: add USB host controller
Quoted 111 lines · Niek Linnenbank
On Sun, Jan 19, 2020 at 7:44 PM Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:
On 1/19/20 7:37 PM, Philippe Mathieu-Daudé wrote: > On 1/19/20 1:50 AM, Niek Linnenbank wrote: >> The Allwinner H3 System on Chip contains multiple USB 2.0 bus >> connections which provide software access using the Enhanced >> Host Controller Interface (EHCI) and Open Host Controller >> Interface (OHCI) interfaces. This commit adds support for >> both interfaces in the Allwinner H3 System on Chip. >> >> Signed-off-by: Niek Linnenbank <[email protected] <mailto:[email protected]>> >> Reviewed-by: Gerd Hoffmann <[email protected] <mailto:[email protected]>> >> --- >> hw/usb/hcd-ehci.h | 1 + >> include/hw/arm/allwinner-h3.h | 8 ++++++ >> hw/arm/allwinner-h3.c | 52 ++++++++++++++++++++++++++++++++--- >> hw/usb/hcd-ehci-sysbus.c | 17 ++++++++++++ >> 4 files changed, 74 insertions(+), 4 deletions(-) >> >> diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h >> index 0298238f0b..edb59311c4 100644 >> --- a/hw/usb/hcd-ehci.h >> +++ b/hw/usb/hcd-ehci.h >> @@ -342,6 +342,7 @@ typedef struct EHCIPCIState { >> #define TYPE_SYS_BUS_EHCI "sysbus-ehci-usb" >> #define TYPE_PLATFORM_EHCI "platform-ehci-usb" >> #define TYPE_EXYNOS4210_EHCI "exynos4210-ehci-usb" >> +#define TYPE_AW_H3_EHCI "aw-h3-ehci-usb" >> #define TYPE_TEGRA2_EHCI "tegra2-ehci-usb" >> #define TYPE_PPC4xx_EHCI "ppc4xx-ehci-usb" >> #define TYPE_FUSBH200_EHCI "fusbh200-ehci-usb" >> diff --git a/include/hw/arm/allwinner-h3.h >> b/include/hw/arm/allwinner-h3.h >> index abdc20871a..4f4dcbcd17 100644 >> --- a/include/hw/arm/allwinner-h3.h >> +++ b/include/hw/arm/allwinner-h3.h >> @@ -56,6 +56,14 @@ enum { >> AW_H3_SRAM_A1, >> AW_H3_SRAM_A2, >> AW_H3_SRAM_C, >> + AW_H3_EHCI0, >> + AW_H3_OHCI0, >> + AW_H3_EHCI1, >> + AW_H3_OHCI1, >> + AW_H3_EHCI2, >> + AW_H3_OHCI2, >> + AW_H3_EHCI3, >> + AW_H3_OHCI3, >> AW_H3_CCU, >> AW_H3_PIT, >> AW_H3_UART0, >> diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c >> index 8df8e3e05e..f360625ee9 100644 >> --- a/hw/arm/allwinner-h3.c >> +++ b/hw/arm/allwinner-h3.c >> @@ -28,6 +28,7 @@ >> #include "hw/sysbus.h" >> #include "hw/char/serial.h" >> #include "hw/misc/unimp.h" >> +#include "hw/usb/hcd-ehci.h" >> #include "sysemu/sysemu.h" >> #include "hw/arm/allwinner-h3.h" >> @@ -36,6 +37,14 @@ const hwaddr allwinner_h3_memmap[] = { >> [AW_H3_SRAM_A1] = 0x00000000, >> [AW_H3_SRAM_A2] = 0x00044000, >> [AW_H3_SRAM_C] = 0x00010000, >> + [AW_H3_EHCI0] = 0x01c1a000, >> + [AW_H3_OHCI0] = 0x01c1a400, >> + [AW_H3_EHCI1] = 0x01c1b000, >> + [AW_H3_OHCI1] = 0x01c1b400, >> + [AW_H3_EHCI2] = 0x01c1c000, >> + [AW_H3_OHCI2] = 0x01c1c400, >> + [AW_H3_EHCI3] = 0x01c1d000, >> + [AW_H3_OHCI3] = 0x01c1d400, >> [AW_H3_CCU] = 0x01c20000, >> [AW_H3_PIT] = 0x01c20c00, >> [AW_H3_UART0] = 0x01c28000, >> @@ -73,10 +82,10 @@ struct AwH3Unimplemented { >> { "msgbox", 0x01c17000, 4 * KiB }, >> { "spinlock", 0x01c18000, 4 * KiB }, >> { "usb0-otg", 0x01c19000, 4 * KiB }, >> - { "usb0", 0x01c1a000, 4 * KiB }, >> - { "usb1", 0x01c1b000, 4 * KiB }, >> - { "usb2", 0x01c1c000, 4 * KiB }, >> - { "usb3", 0x01c1d000, 4 * KiB }, >> + { "usb0-phy", 0x01c1a000, 4 * KiB }, >> + { "usb1-phy", 0x01c1b000, 4 * KiB }, >> + { "usb2-phy", 0x01c1c000, 4 * KiB }, >> + { "usb3-phy", 0x01c1d000, 4 * KiB }, > > As in v3 comment, this can be done in patch #1. > > Reviewed-by: Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> > Tested-by: Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> Err, this patch is incomplete, when using ./configure --without-default-devices: $ qemu-system-arm -M orangepi-pc qemu-system-arm: invalid accelerator kvm qemu-system-arm: falling back to tcg qemu-system-arm: Unknown device 'aw-h3-ehci-usb' for default sysbus qemu-system-arm: Unknown device 'sysbus-ohci' for default sysbus Aborted (core dumped)
Quoted 3 lines
Thanks for pointing this out, I was not aware at all that the --without-default-devices option existed.
It's not in the configure --help message also.
Indeed. This is https://bugs.launchpad.net/qemu/+bug/1836537
Quoted 15 lines
I tried to re-produce the error by running:
$ ./configure --target-list=arm-softmmu --without-default-devices; make -j5 $ ./arm-softmmu/qemu-system-arm -M orangepi-pcOn my laptop it didn't give the error, I think because somehow the build system did select the USB config items (even tho they were missing for the
ALLWINNER_H3item in hw/arm/Kconfig):$ grep USB arm-softmmu/config-devices.mak CONFIG_TUSB6010=y CONFIG_USB=y CONFIG_USB_EHCI=y CONFIG_USB_EHCI_SYSBUS=y CONFIG_USB_MUSB=y CONFIG_USB_OHCI=y
Quoted 2 lines
Is there any other option you used in addition to
--without-default-devices to trigger the error?
Uff this was 1 month ago... I might have done:
$ echo CONFIG_ALLWINNER_H3=y > arm-softmmu/config-devices.mak $ make arm-softmmu/all
Quoted 28 lines
I also searched for something in configure to select/filter on machines to build, but I don't see that yet.
Nevertheless I will surely add the fix below to the patch.
Regards,
NiekYou need to amend: -- >8 -- diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index bb75c1de17..57b29cc522 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -302,6 +302,8 @@ config ALLWINNER_H3 select ARM_TIMER select ARM_GIC select UNIMP + select USB_OHCI + select USB_EHCI_SYSBUS config RASPI bool --- R/T-b tags can stay with this amended.
Re: [PATCH v4 04/20] hw/arm/allwinner-h3: add USB host controller
In reply to Philippe Mathieu-DaudéQuoted 81 lines · Philippe Mathieu-Daudé
Review
Quoted 28 lines · Niek Linnenbank
The Allwinner H3 System on Chip contains multiple USB 2.0 bus connections which provide software access using the Enhanced Host Controller Interface (EHCI) and Open Host Controller Interface (OHCI) interfaces. This commit adds support for both interfaces in the Allwinner H3 System on Chip.
Signed-off-by Niek Linnenbank <[email protected]>Reviewed-by Gerd Hoffmann <[email protected]>--- hw/usb/hcd-ehci.h | 1 + include/hw/arm/allwinner-h3.h | 8 ++++++ hw/arm/allwinner-h3.c | 52 ++++++++++++++++++++++++++++++++--- hw/usb/hcd-ehci-sysbus.c | 17 ++++++++++++ 4 files changed, 74 insertions(+), 4 deletions(-)hw/usb/hcd-ehci.h +1
-0@@ -342,6 +342,7 @@ typedef struct EHCIPCIState {#define TYPE_SYS_BUS_EHCI "sysbus-ehci-usb"#define TYPE_PLATFORM_EHCI "platform-ehci-usb"#define TYPE_EXYNOS4210_EHCI "exynos4210-ehci-usb" +#define TYPE_AW_H3_EHCI "aw-h3-ehci-usb"#define TYPE_TEGRA2_EHCI "tegra2-ehci-usb"#define TYPE_PPC4xx_EHCI "ppc4xx-ehci-usb"#define TYPE_FUSBH200_EHCI "fusbh200-ehci-usb"(quoted diff) +0
-0
b/include/hw/arm/allwinner-h3.hQuoted 51 lines
index
abdc20871a..4f4dcbcd17100644include/hw/arm/allwinner-h3.h +8
-0@@ -56,6 +56,14 @@ enum {AW_H3_SRAM_A1 ,AW_H3_SRAM_A2 ,AW_H3_SRAM_C , +AW_H3_EHCI0 , +AW_H3_OHCI0 , +AW_H3_EHCI1 , +AW_H3_OHCI1 , +AW_H3_EHCI2 , +AW_H3_OHCI2 , +AW_H3_EHCI3 , +AW_H3_OHCI3 ,AW_H3_CCU ,AW_H3_PIT , AW_H3_UART0,hw/arm/allwinner-h3.c +9
-2@@ -28,6 +28,7 @@#include "hw/sysbus.h" #include "hw/char/serial.h" #include "hw/misc/unimp.h" +#include "hw/usb/hcd-ehci.h" #include "sysemu/sysemu.h" #include "hw/arm/allwinner-h3.h" @@ -36,6 +37,14 @@ const hwaddr allwinner_h3_memmap[] = { [AW_H3_SRAM_A1] = 0x00000000, [AW_H3_SRAM_A2] = 0x00044000, [AW_H3_SRAM_C] = 0x00010000, + [AW_H3_EHCI0] = 0x01c1a000, + [AW_H3_OHCI0] = 0x01c1a400, + [AW_H3_EHCI1] = 0x01c1b000, + [AW_H3_OHCI1] = 0x01c1b400, + [AW_H3_EHCI2] = 0x01c1c000, + [AW_H3_OHCI2] = 0x01c1c400, + [AW_H3_EHCI3] = 0x01c1d000, + [AW_H3_OHCI3] = 0x01c1d400, [AW_H3_CCU] = 0x01c20000, [AW_H3_PIT] = 0x01c20c00, [AW_H3_UART0] = 0x01c28000,@@ -73,10 +82,10 @@ struct AwH3Unimplemented { { "msgbox", 0x01c17000, 4 * KiB }, { "spinlock", 0x01c18000, 4 * KiB }, { "usb0-otg", 0x01c19000, 4 * KiB }, - { "usb0", 0x01c1a000, 4 * KiB }, - { "usb1", 0x01c1b000, 4 * KiB },
Quoted 9 lines
hw/arm/allwinner-h3.c struct AwH3Unimplemented { · line 88
Quoted 6 lines
hw/arm/allwinner-h3.c +4
-2- { "usb2", 0x01c1c000, 4 * KiB }, - { "usb3", 0x01c1d000, 4 * KiB }, + { "usb0-phy", 0x01c1a000, 4 * KiB }, + { "usb1-phy", 0x01c1b000, 4 * KiB }, + { "usb2-phy", 0x01c1c000, 4 * KiB }, + { "usb3-phy", 0x01c1d000, 4 * KiB },As in v3 comment, this can be done in patch #1.
OK, I'll rename them in patch 1, so it won't show up here.
Quoted 4 lines
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Thanks for reviewing and testing Philippe!
Regards,
Niek
Quoted 94 lines
hw/arm/allwinner-h3.c static void allwinner_h3_realize(DeviceState *dev,
Quoted 20 lines
hw/arm/allwinner-h3.c +8
-0{ "smc", 0x01c1e000, 4 * KiB }, { "pio", 0x01c20800, 1 * KiB }, { "owa", 0x01c21000, 1 * KiB },@@ -144,6 +153,14 @@ enum {AW_H3_GIC_SPI_UART3 =3 ,AW_H3_GIC_SPI_TIMER0 =18 ,AW_H3_GIC_SPI_TIMER1 =19 , +AW_H3_GIC_SPI_EHCI0 =72 , +AW_H3_GIC_SPI_OHCI0 =73 , +AW_H3_GIC_SPI_EHCI1 =74 , +AW_H3_GIC_SPI_OHCI1 =75 , +AW_H3_GIC_SPI_EHCI2 =76 , +AW_H3_GIC_SPI_OHCI2 =77 , +AW_H3_GIC_SPI_EHCI3 =78 , + AW_H3_GIC_SPI_OHCI3 = 79, };/* Allwinner H3 general constants */ @@ -284,6 +301,33 @@ static void allwinner_h3_realize(DeviceState *dev,Error **errp)
Quoted 21 lines
hw/arm/allwinner-h3.c +18
-0qdev_init_nofail (DEVICE (&s->ccu));sysbus_mmio_map (SYS_BUS_DEVICE (&s->ccu),0 , s->memmap[AW_H3_CCU ]); +/* Universal Serial Bus */ +sysbus_create_simple (TYPE_AW_H3_EHCI , s->memmap[AW_H3_EHCI0 ], +qdev_get_gpio_in (DEVICE (&s->gic), +AW_H3_GIC_SPI_EHCI0 )); +sysbus_create_simple (TYPE_AW_H3_EHCI , s->memmap[AW_H3_EHCI1 ], +qdev_get_gpio_in (DEVICE (&s->gic), +AW_H3_GIC_SPI_EHCI1 )); +sysbus_create_simple (TYPE_AW_H3_EHCI , s->memmap[AW_H3_EHCI2 ], +qdev_get_gpio_in (DEVICE (&s->gic), +AW_H3_GIC_SPI_EHCI2 )); +sysbus_create_simple (TYPE_AW_H3_EHCI , s->memmap[AW_H3_EHCI3 ], +qdev_get_gpio_in (DEVICE (&s->gic), +AW_H3_GIC_SPI_EHCI3 )); + +sysbus_create_simple ("sysbus-ohci" , s->memmap[AW_H3_OHCI0 ], +qdev_get_gpio_in (DEVICE (&s->gic), +AW_H3_GIC_SPI_OHCI0 )); + sysbus_create_simple("sysbus-ohci", s->memmap[AW_H3_OHCI1],hw/arm/allwinner-h3.c static void allwinner_h3_realize(DeviceState *dev, Error **errp)
Quoted 10 lines
hw/arm/allwinner-h3.c +9
-0+qdev_get_gpio_in (DEVICE (&s->gic), + AW_H3_GIC_SPI_OHCI1)); +sysbus_create_simple ("sysbus-ohci" , s->memmap[AW_H3_OHCI2 ], +qdev_get_gpio_in (DEVICE (&s->gic), +AW_H3_GIC_SPI_OHCI2 )); +sysbus_create_simple ("sysbus-ohci" , s->memmap[AW_H3_OHCI3 ], +qdev_get_gpio_in (DEVICE (&s->gic), +AW_H3_GIC_SPI_OHCI3 )); +/* UART0. For future clocktree API: All UARTS are connected to
APB2_CLK. */hw/arm/allwinner-h3.c static void allwinner_h3_realize(DeviceState *dev, · line 333
Quoted 2 lines
hw/arm/allwinner-h3.c +0
-0serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART0], 2, qdev_get_gpio_in(DEVICE(&s->gic),
AW_H3_GIC_SPI_UART0),Quoted 36 lines
hw/usb/hcd-ehci-sysbus.c +17
-0@@ -145,6 +145,22 @@ static const TypeInfo ehci_exynos4210_type_info = { .class_init = ehci_exynos4210_class_init, }; +static void ehci_aw_h3_class_init (ObjectClass *oc,void *data) +{ +SysBusEHCIClass *sec =SYS_BUS_EHCI_CLASS (oc); +DeviceClass *dc =DEVICE_CLASS (oc); + + sec->capsbase =0x0 ; + sec->opregbase =0x10 ; +set_bit (DEVICE_CATEGORY_USB , dc->categories); +} + +static const TypeInfo ehci_aw_h3_type_info = { + .name =TYPE_AW_H3_EHCI , + .parent =TYPE_SYS_BUS_EHCI , + .class_init = ehci_aw_h3_class_init, +}; +static void ehci_tegra2_class_init (ObjectClass *oc,void *data) {SysBusEHCIClass *sec =SYS_BUS_EHCI_CLASS (oc);@@ -267,6 +283,7 @@ static void ehci_sysbus_register_types(void)type_register_static (&ehci_platform_type_info);type_register_static (&ehci_xlnx_type_info);type_register_static (&ehci_exynos4210_type_info); +type_register_static (&ehci_aw_h3_type_info);type_register_static (&ehci_tegra2_type_info);type_register_static (&ehci_ppc4xx_type_info);type_register_static (&ehci_fusbh200_type_info);
Signature · 1 line
Niek Linnenbank
PATCH v4 5/20 hw/arm/allwinner-h3: add System Control module
In reply to Niek LinnenbankThe Allwinner H3 System on Chip has an System Control module that provides system wide generic controls and device information. This commit adds support for the Allwinner H3 System Control module.
--- include/hw/arm/allwinner-h3.h | 3 + include/hw/misc/allwinner-h3-sysctrl.h | 67 ++++++++++++ hw/arm/allwinner-h3.c | 9 +- hw/misc/allwinner-h3-sysctrl.c | 140 +++++++++++++++++++++++++ hw/misc/Makefile.objs | 1 + 5 files changed, 219 insertions(+), 1 deletion(-) create mode 100644 include/hw/misc/allwinner-h3-sysctrl.h create mode 100644 hw/misc/allwinner-h3-sysctrl.c
include/hw/arm/allwinner-h3.h +3 -0
@@ -40,6 +40,7 @@#include "hw/timer/allwinner-a10-pit.h" #include "hw/intc/arm_gic.h" #include "hw/misc/allwinner-h3-ccu.h" +#include "hw/misc/allwinner-h3-sysctrl.h" #include "target/arm/cpu.h" /**
@@ -56,6 +57,7 @@ enum {AW_H3_SRAM_A1 ,AW_H3_SRAM_A2 ,AW_H3_SRAM_C , +AW_H3_SYSCTRL ,AW_H3_EHCI0 ,AW_H3_OHCI0 , AW_H3_EHCI1,
@@ -108,6 +110,7 @@ typedef struct AwH3State {const hwaddr *memmap;AwA10PITState timer;AwH3ClockCtlState ccu; +AwH3SysCtrlState sysctrl;GICState gic;MemoryRegion sram_a1;MemoryRegion sram_a2;
include/hw/misc/allwinner-h3-sysctrl.h new file +67 -0
67 lines not on this page · raw message
hw/arm/allwinner-h3.c +8 -1
@@ -37,6 +37,7 @@ const hwaddr allwinner_h3_memmap[] = { [AW_H3_SRAM_A1] = 0x00000000, [AW_H3_SRAM_A2] = 0x00044000, [AW_H3_SRAM_C] = 0x00010000, + [AW_H3_SYSCTRL] = 0x01c00000, [AW_H3_EHCI0] = 0x01c1a000, [AW_H3_OHCI0] = 0x01c1a400, [AW_H3_EHCI1] = 0x01c1b000,
@@ -66,7 +67,6 @@ struct AwH3Unimplemented { } unimplemented[] = { { "d-engine", 0x01000000, 4 * MiB }, { "d-inter", 0x01400000, 128 * KiB }, - { "syscon", 0x01c00000, 4 * KiB }, { "dma", 0x01c02000, 4 * KiB }, { "nfdc", 0x01c03000, 4 * KiB }, { "ts", 0x01c06000, 4 * KiB },
@@ -192,6 +192,9 @@ static void allwinner_h3_init(Object *obj)sysbus_init_child_obj (obj,"ccu" , &s->ccu,sizeof (s->ccu),TYPE_AW_H3_CCU ); + +sysbus_init_child_obj (obj,"sysctrl" , &s->sysctrl,sizeof (s->sysctrl), +TYPE_AW_H3_SYSCTRL ); }static void allwinner_h3_realize (DeviceState *dev,Error **errp)
@@ -301,6 +304,10 @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)qdev_init_nofail (DEVICE (&s->ccu));sysbus_mmio_map (SYS_BUS_DEVICE (&s->ccu),0 , s->memmap[AW_H3_CCU ]); +/* System Control */ +qdev_init_nofail (DEVICE (&s->sysctrl)); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->sysctrl),0 , s->memmap[AW_H3_SYSCTRL ]); +/* Universal Serial Bus */ sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0], qdev_get_gpio_in(DEVICE(&s->gic),
hw/misc/allwinner-h3-sysctrl.c new file +140 -0
140 lines not on this page · raw message
hw/misc/Makefile.objs +1 -0
@@ -29,6 +29,7 @@ common-obj-$(CONFIG_MACIO) += macio/ common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o +common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-sysctrl.o common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o common-obj-$(CONFIG_NSERIES) += cbus.o common-obj-$(CONFIG_ECCMEMCTL) += eccmemctl.o
Signature · 1 line
2.17.1
Re: [PATCH v4 05/20] hw/arm/allwinner-h3: add System Control module
Quoted 310 lines · Niek Linnenbank
The Allwinner H3 System on Chip has an System Control module that provides system wide generic controls and device information. This commit adds support for the Allwinner H3 System Control module.
Signed-off-by Niek Linnenbank <[email protected]>--- include/hw/arm/allwinner-h3.h | 3 + include/hw/misc/allwinner-h3-sysctrl.h | 67 ++++++++++++ hw/arm/allwinner-h3.c | 9 +- hw/misc/allwinner-h3-sysctrl.c | 140 +++++++++++++++++++++++++ hw/misc/Makefile.objs | 1 + 5 files changed, 219 insertions(+), 1 deletion(-)create mode 100644
include/hw/misc/allwinner-h3-sysctrl.hcreate mode 100644hw/misc/allwinner-h3-sysctrl.cinclude/hw/arm/allwinner-h3.h +3
-0@@ -40,6 +40,7 @@#include "hw/timer/allwinner-a10-pit.h" #include "hw/intc/arm_gic.h" #include "hw/misc/allwinner-h3-ccu.h" +#include "hw/misc/allwinner-h3-sysctrl.h" #include "target/arm/cpu.h" /** @@ -56,6 +57,7 @@ enum {AW_H3_SRAM_A1 ,AW_H3_SRAM_A2 ,AW_H3_SRAM_C , +AW_H3_SYSCTRL ,AW_H3_EHCI0 ,AW_H3_OHCI0 , AW_H3_EHCI1,@@ -108,6 +110,7 @@ typedef struct AwH3State {const hwaddr *memmap;AwA10PITState timer;AwH3ClockCtlState ccu; +AwH3SysCtrlState sysctrl;GICState gic;MemoryRegion sram_a1;MemoryRegion sram_a2;include/hw/misc/allwinner-h3-sysctrl.h new file +67
-0@@ -0,0 +1,67 @@ +/* +* Allwinner H3 System Control emulation +* +* Copyright (C) 2019 Niek Linnenbank <[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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HW_MISC_ALLWINNER_H3_SYSCTRL_H +#define HW_MISC_ALLWINNER_H3_SYSCTRL_H + +#include "qom/object.h" +#include "hw/sysbus.h" + +/** +* @name Constants +* @{ +*/ + +/** Highest register address used by System Control device */ +#define AW_H3_SYSCTRL_REGS_MAXADDR (0x30) + +/** Total number of known registers */ +#define AW_H3_SYSCTRL_REGS_NUM ((AW_H3_SYSCTRL_REGS_MAXADDR / \ + sizeof(uint32_t)) + 1) + +/** @} */ + +/** +* @name Object model +* @{ +*/ + +#define TYPE_AW_H3_SYSCTRL "allwinner-h3-sysctrl" +#define AW_H3_SYSCTRL (obj) \ + OBJECT_CHECK(AwH3SysCtrlState, (obj), TYPE_AW_H3_SYSCTRL) + +/** @} */ + +/** +* Allwinner H3 System Control object instance state +*/ +typedef struct AwH3SysCtrlState { +/*< private >*/ +SysBusDevice parent_obj; +/*< public >*/ + +/** Maps I/O registers in physical memory */ +MemoryRegion iomem; + +/** Array of hardware registers */ +uint32_t regs[AW_H3_SYSCTRL_REGS_NUM ]; + +}AwH3SysCtrlState ; + +#endif /* HW_MISC_ALLWINNER_H3_SYSCTRL_H */ hw/arm/allwinner-h3.c +8
-1@@ -37,6 +37,7 @@ const hwaddr allwinner_h3_memmap[] = { [AW_H3_SRAM_A1] = 0x00000000, [AW_H3_SRAM_A2] = 0x00044000, [AW_H3_SRAM_C] = 0x00010000, + [AW_H3_SYSCTRL] = 0x01c00000, [AW_H3_EHCI0] = 0x01c1a000, [AW_H3_OHCI0] = 0x01c1a400, [AW_H3_EHCI1] = 0x01c1b000,@@ -66,7 +67,6 @@ struct AwH3Unimplemented { } unimplemented[] = { { "d-engine", 0x01000000, 4 * MiB }, { "d-inter", 0x01400000, 128 * KiB }, - { "syscon", 0x01c00000, 4 * KiB }, { "dma", 0x01c02000, 4 * KiB }, { "nfdc", 0x01c03000, 4 * KiB }, { "ts", 0x01c06000, 4 * KiB },@@ -192,6 +192,9 @@ static void allwinner_h3_init(Object *obj)sysbus_init_child_obj (obj,"ccu" , &s->ccu,sizeof (s->ccu),TYPE_AW_H3_CCU ); + +sysbus_init_child_obj (obj,"sysctrl" , &s->sysctrl,sizeof (s->sysctrl), +TYPE_AW_H3_SYSCTRL ); }static void allwinner_h3_realize (DeviceState *dev,Error **errp)@@ -301,6 +304,10 @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)qdev_init_nofail (DEVICE (&s->ccu));sysbus_mmio_map (SYS_BUS_DEVICE (&s->ccu),0 , s->memmap[AW_H3_CCU ]); +/* System Control */ +qdev_init_nofail (DEVICE (&s->sysctrl)); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->sysctrl),0 , s->memmap[AW_H3_SYSCTRL ]); +/* Universal Serial Bus */ sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0], qdev_get_gpio_in(DEVICE(&s->gic),hw/misc/allwinner-h3-sysctrl.c new file +140
-0@@ -0,0 +1,140 @@ +/* +* Allwinner H3 System Control emulation +* +* Copyright (C) 2019 Niek Linnenbank <[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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "hw/sysbus.h" +#include "migration/vmstate.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "hw/misc/allwinner-h3-sysctrl.h" + +/* System Control register offsets */ +enum { +REG_VER =0x24 ,/* Version */ +REG_EMAC_PHY_CLK =0x30 ,/* EMAC PHY Clock */ +}; + +#define REG_INDEX (offset) (offset / sizeof(uint32_t)) + +/* System Control register reset values */ +enum { +REG_VER_RST =0x0 , +REG_EMAC_PHY_CLK_RST =0x58000 , +}; + +static uint64_t allwinner_h3_sysctrl_read (void *opaque,hwaddr offset, +unsigned size) +{ +const AwH3SysCtrlState *s =AW_H3_SYSCTRL (opaque); +const uint32_t idx =REG_INDEX (offset); + +if (idx >=AW_H3_SYSCTRL_REGS_NUM ) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: out-of-bounds offset 0x%04x\n" , + __func__, (uint32_t )offset); +return 0 ; + } + +return s->regs[idx]; +} + +static void allwinner_h3_sysctrl_write (void *opaque,hwaddr offset, +uint64_t val,unsigned size) +{ +AwH3SysCtrlState *s =AW_H3_SYSCTRL (opaque); +const uint32_t idx =REG_INDEX (offset); + +if (idx >=AW_H3_SYSCTRL_REGS_NUM ) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: out-of-bounds offset 0x%04x\n" , + __func__, (uint32_t )offset); +return ; + } + +switch (offset) { +case REG_VER :/* Version */ +break ; +default : + s->regs[idx] = (uint32_t ) val; +break ; + } +} + +static const MemoryRegionOps allwinner_h3_sysctrl_ops = { + .read = allwinner_h3_sysctrl_read, + .write = allwinner_h3_sysctrl_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + }, + .impl.min_access_size =4 , +}; + +static void allwinner_h3_sysctrl_reset (DeviceState *dev) +{ +AwH3SysCtrlState *s =AW_H3_SYSCTRL (dev); + +/* Set default values for registers */ + s->regs[REG_INDEX (REG_VER )] =REG_VER_RST ; + s->regs[REG_INDEX (REG_EMAC_PHY_CLK )] =REG_EMAC_PHY_CLK_RST ; +} + +static void allwinner_h3_sysctrl_init (Object *obj) +{ +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); +AwH3SysCtrlState *s =AW_H3_SYSCTRL (obj); + +/* Memory mapping */ +memory_region_init_io (&s->iomem,OBJECT (s), &allwinner_h3_sysctrl_ops, s, +TYPE_AW_H3_SYSCTRL ,4 * KiB); +sysbus_init_mmio (sbd, &s->iomem); +} + +static const VMStateDescription allwinner_h3_sysctrl_vmstate = { + .name ="allwinner-h3-sysctrl" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32_ARRAY (regs, AwH3SysCtrlState,AW_H3_SYSCTRL_REGS_NUM ), +VMSTATE_END_OF_LIST () + } +}; + +static void allwinner_h3_sysctrl_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->reset = allwinner_h3_sysctrl_reset; + dc->vmsd = &allwinner_h3_sysctrl_vmstate; +} + +static const TypeInfo allwinner_h3_sysctrl_info = { + .name =TYPE_AW_H3_SYSCTRL , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_init = allwinner_h3_sysctrl_init, + .instance_size =sizeof (AwH3SysCtrlState), + .class_init = allwinner_h3_sysctrl_class_init, +}; + +static void allwinner_h3_sysctrl_register (void ) +{ +type_register_static (&allwinner_h3_sysctrl_info); +} + +type_init (allwinner_h3_sysctrl_register)hw/misc/Makefile.objs +0
-0
hw/misc/Makefile.objs common-obj-$(CONFIG_MACIO) += macio/ · line 35
Quoted 7 lines
hw/misc/Makefile.objs +1
-0@@ -29,6 +29,7 @@ common-obj-$(CONFIG_MACIO) += macio/ common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o +common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-sysctrl.o common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o common-obj-$(CONFIG_NSERIES) += cbus.o common-obj-$(CONFIG_ECCMEMCTL) += eccmemctl.o
PATCH v4 6/20 hw/arm/allwinner: add CPU Configuration module
In reply to Niek LinnenbankVarious Allwinner System on Chip designs contain multiple processors that can be configured and reset using the generic CPU Configuration module interface. This commit adds support for the Allwinner CPU configuration interface which emulates the following features:
* CPU reset
* CPU status
--- include/hw/arm/allwinner-h3.h | 3 + include/hw/misc/allwinner-cpucfg.h | 52 ++++++ hw/arm/allwinner-h3.c | 9 +- hw/misc/allwinner-cpucfg.c | 269 +++++++++++++++++++++++++++++ hw/misc/Makefile.objs | 1 + hw/misc/trace-events | 5 + 6 files changed, 338 insertions(+), 1 deletion(-) create mode 100644 include/hw/misc/allwinner-cpucfg.h create mode 100644 hw/misc/allwinner-cpucfg.c
include/hw/arm/allwinner-h3.h +3 -0
@@ -40,6 +40,7 @@#include "hw/timer/allwinner-a10-pit.h" #include "hw/intc/arm_gic.h" #include "hw/misc/allwinner-h3-ccu.h" +#include "hw/misc/allwinner-cpucfg.h" #include "hw/misc/allwinner-h3-sysctrl.h" #include "target/arm/cpu.h"
@@ -76,6 +77,7 @@ enum {AW_H3_GIC_CPU ,AW_H3_GIC_HYP ,AW_H3_GIC_VCPU , +AW_H3_CPUCFG , AW_H3_SDRAM };
@@ -110,6 +112,7 @@ typedef struct AwH3State {const hwaddr *memmap;AwA10PITState timer;AwH3ClockCtlState ccu; +AwCpuCfgState cpucfg;AwH3SysCtrlState sysctrl;GICState gic;MemoryRegion sram_a1;
include/hw/misc/allwinner-cpucfg.h new file +52 -0
52 lines not on this page · raw message
hw/arm/allwinner-h3.c +8 -1
@@ -56,6 +56,7 @@ const hwaddr allwinner_h3_memmap[] = { [AW_H3_GIC_CPU] = 0x01c82000, [AW_H3_GIC_HYP] = 0x01c84000, [AW_H3_GIC_VCPU] = 0x01c86000, + [AW_H3_CPUCFG] = 0x01f01c00, [AW_H3_SDRAM] = 0x40000000 };
@@ -122,7 +123,6 @@ struct AwH3Unimplemented { { "r_wdog", 0x01f01000, 1 * KiB }, { "r_prcm", 0x01f01400, 1 * KiB }, { "r_twd", 0x01f01800, 1 * KiB }, - { "r_cpucfg", 0x01f01c00, 1 * KiB }, { "r_cir-rx", 0x01f02000, 1 * KiB }, { "r_twi", 0x01f02400, 1 * KiB }, { "r_uart", 0x01f02800, 1 * KiB },
@@ -195,6 +195,9 @@ static void allwinner_h3_init(Object *obj)sysbus_init_child_obj (obj,"sysctrl" , &s->sysctrl,sizeof (s->sysctrl),TYPE_AW_H3_SYSCTRL ); + +sysbus_init_child_obj (obj,"cpucfg" , &s->cpucfg,sizeof (s->cpucfg), +TYPE_AW_CPUCFG ); }static void allwinner_h3_realize (DeviceState *dev,Error **errp)
@@ -308,6 +311,10 @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)qdev_init_nofail (DEVICE (&s->sysctrl));sysbus_mmio_map (SYS_BUS_DEVICE (&s->sysctrl),0 , s->memmap[AW_H3_SYSCTRL ]); +/* CPU Configuration */ +qdev_init_nofail (DEVICE (&s->cpucfg)); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->cpucfg),0 , s->memmap[AW_H3_CPUCFG ]); +/* Universal Serial Bus */ sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0], qdev_get_gpio_in(DEVICE(&s->gic),
hw/misc/allwinner-cpucfg.c new file +269 -0
269 lines not on this page · raw message
hw/misc/Makefile.objs +1 -0
@@ -29,6 +29,7 @@ common-obj-$(CONFIG_MACIO) += macio/ common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o +obj-$(CONFIG_ALLWINNER_H3) += allwinner-cpucfg.o common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-sysctrl.o common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o common-obj-$(CONFIG_NSERIES) += cbus.o
hw/misc/trace-events +5 -0
@@ -1,5 +1,10 @@ # See docs/devel/tracing.txt for syntax documentation. +# allwinner-cpucfg.c +allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "id %u, reset_addr 0x%" PRIu32 +allwinner_cpucfg_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 +allwinner_cpucfg_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 + # eccmemctl.c ecc_mem_writel_mer(uint32_t val) "Write memory enable 0x%08x" ecc_mem_writel_mdr(uint32_t val) "Write memory delay 0x%08x"
Signature · 1 line
2.17.1
Re: [PATCH v4 06/20] hw/arm/allwinner: add CPU Configuration module
Quoted 386 lines · Niek Linnenbank
Various Allwinner System on Chip designs contain multiple processors that can be configured and reset using the generic CPU Configuration module interface. This commit adds support for the Allwinner CPU configuration interface which emulates the following features:
* CPU reset
* CPU statusSigned-off-by Niek Linnenbank <[email protected]>--- include/hw/arm/allwinner-h3.h | 3 + include/hw/misc/allwinner-cpucfg.h | 52 ++++++ hw/arm/allwinner-h3.c | 9 +- hw/misc/allwinner-cpucfg.c | 269 +++++++++++++++++++++++++++++ hw/misc/Makefile.objs | 1 + hw/misc/trace-events | 5 + 6 files changed, 338 insertions(+), 1 deletion(-)create mode 100644
include/hw/misc/allwinner-cpucfg.hcreate mode 100644hw/misc/allwinner-cpucfg.cinclude/hw/arm/allwinner-h3.h +3
-0@@ -40,6 +40,7 @@#include "hw/timer/allwinner-a10-pit.h" #include "hw/intc/arm_gic.h" #include "hw/misc/allwinner-h3-ccu.h" +#include "hw/misc/allwinner-cpucfg.h" #include "hw/misc/allwinner-h3-sysctrl.h" #include "target/arm/cpu.h" @@ -76,6 +77,7 @@ enum {AW_H3_GIC_CPU ,AW_H3_GIC_HYP ,AW_H3_GIC_VCPU , +AW_H3_CPUCFG , AW_H3_SDRAM };@@ -110,6 +112,7 @@ typedef struct AwH3State {const hwaddr *memmap;AwA10PITState timer;AwH3ClockCtlState ccu; +AwCpuCfgState cpucfg;AwH3SysCtrlState sysctrl;GICState gic;MemoryRegion sram_a1;include/hw/misc/allwinner-cpucfg.h new file +52
-0@@ -0,0 +1,52 @@ +/* +* Allwinner CPU Configuration Module emulation +* +* Copyright (C) 2019 Niek Linnenbank <[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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HW_MISC_ALLWINNER_CPUCFG_H +#define HW_MISC_ALLWINNER_CPUCFG_H + +#include "qom/object.h" +#include "hw/sysbus.h" + +/** +* Object model +* @{ +*/ + +#define TYPE_AW_CPUCFG "allwinner-cpucfg" +#define AW_CPUCFG (obj) \ + OBJECT_CHECK(AwCpuCfgState, (obj), TYPE_AW_CPUCFG) + +/** @} */ + +/** +* Allwinner CPU Configuration Module instance state +*/ +typedef struct AwCpuCfgState { +/*< private >*/ +SysBusDevice parent_obj; +/*< public >*/ + +MemoryRegion iomem; +uint32_t gen_ctrl; +uint32_t super_standby; +uint32_t entry_addr; + +}AwCpuCfgState ; + +#endif /* HW_MISC_ALLWINNER_CPUCFG_H */ hw/arm/allwinner-h3.c +8
-1@@ -56,6 +56,7 @@ const hwaddr allwinner_h3_memmap[] = { [AW_H3_GIC_CPU] = 0x01c82000, [AW_H3_GIC_HYP] = 0x01c84000, [AW_H3_GIC_VCPU] = 0x01c86000, + [AW_H3_CPUCFG] = 0x01f01c00, [AW_H3_SDRAM] = 0x40000000 };@@ -122,7 +123,6 @@ struct AwH3Unimplemented { { "r_wdog", 0x01f01000, 1 * KiB }, { "r_prcm", 0x01f01400, 1 * KiB }, { "r_twd", 0x01f01800, 1 * KiB }, - { "r_cpucfg", 0x01f01c00, 1 * KiB }, { "r_cir-rx", 0x01f02000, 1 * KiB }, { "r_twi", 0x01f02400, 1 * KiB }, { "r_uart", 0x01f02800, 1 * KiB },@@ -195,6 +195,9 @@ static void allwinner_h3_init(Object *obj)sysbus_init_child_obj (obj,"sysctrl" , &s->sysctrl,sizeof (s->sysctrl),TYPE_AW_H3_SYSCTRL ); + +sysbus_init_child_obj (obj,"cpucfg" , &s->cpucfg,sizeof (s->cpucfg), +TYPE_AW_CPUCFG ); }static void allwinner_h3_realize (DeviceState *dev,Error **errp)@@ -308,6 +311,10 @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)qdev_init_nofail (DEVICE (&s->sysctrl));sysbus_mmio_map (SYS_BUS_DEVICE (&s->sysctrl),0 , s->memmap[AW_H3_SYSCTRL ]); +/* CPU Configuration */ +qdev_init_nofail (DEVICE (&s->cpucfg)); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->cpucfg),0 , s->memmap[AW_H3_CPUCFG ]); +/* Universal Serial Bus */ sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0], qdev_get_gpio_in(DEVICE(&s->gic),hw/misc/allwinner-cpucfg.c new file +233
-0@@ -0,0 +1,269 @@ +/* +* Allwinner CPU Configuration Module emulation +* +* Copyright (C) 2019 Niek Linnenbank <[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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "hw/sysbus.h" +#include "migration/vmstate.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/error-report.h" +#include "qemu/timer.h" +#include "hw/core/cpu.h" +#include "arm-powerctl.h" +#include "hw/misc/allwinner-cpucfg.h" +#include "trace.h" + +/* CPUCFG register offsets */ +enum { +REG_CPUS_RST_CTRL =0x0000 ,/* CPUs Reset Control */ +REG_CPU0_RST_CTRL =0x0040 ,/* CPU#0 Reset Control */ +REG_CPU0_CTRL =0x0044 ,/* CPU#0 Control */ +REG_CPU0_STATUS =0x0048 ,/* CPU#0 Status */ +REG_CPU1_RST_CTRL =0x0080 ,/* CPU#1 Reset Control */ +REG_CPU1_CTRL =0x0084 ,/* CPU#1 Control */ +REG_CPU1_STATUS =0x0088 ,/* CPU#1 Status */ +REG_CPU2_RST_CTRL =0x00C0 ,/* CPU#2 Reset Control */ +REG_CPU2_CTRL =0x00C4 ,/* CPU#2 Control */ +REG_CPU2_STATUS =0x00C8 ,/* CPU#2 Status */ +REG_CPU3_RST_CTRL =0x0100 ,/* CPU#3 Reset Control */ +REG_CPU3_CTRL =0x0104 ,/* CPU#3 Control */ +REG_CPU3_STATUS =0x0108 ,/* CPU#3 Status */ +REG_CPU_SYS_RST =0x0140 ,/* CPU System Reset */ +REG_CLK_GATING =0x0144 ,/* CPU Clock Gating */ +REG_GEN_CTRL =0x0184 ,/* General Control */ +REG_SUPER_STANDBY =0x01A0 ,/* Super Standby Flag */ +REG_ENTRY_ADDR =0x01A4 ,/* Reset Entry Address */ +REG_DBG_EXTERN =0x01E4 ,/* Debug External */ +REG_CNT64_CTRL =0x0280 ,/* 64-bit Counter Control */ +REG_CNT64_LOW =0x0284 ,/* 64-bit Counter Low */ +REG_CNT64_HIGH =0x0288 ,/* 64-bit Counter High */ +}; + +/* CPUCFG register flags */ +enum { +CPUX_RESET_RELEASED = ((1 <<1 ) | (1 <<0 )), +CPUX_STATUS_SMP = (1 <<0 ), +CPU_SYS_RESET_RELEASED = (1 <<0 ), +CLK_GATING_ENABLE = ((1 <<8 ) |0xF ), +}; + +/* CPUCFG register reset values */ +enum { +REG_CLK_GATING_RST =0x0000010F , +REG_GEN_CTRL_RST =0x00000020 , +REG_SUPER_STANDBY_RST =0x0 , +REG_CNT64_CTRL_RST =0x0 , +}; + +/* CPUCFG constants */ +enum { +CPU_EXCEPTION_LEVEL_ON_RESET =3 ,/* EL3 */ +}; + +static void allwinner_cpucfg_cpu_reset (AwCpuCfgState *s,uint8_t cpu_id) +{ +int ret; + +trace_allwinner_cpucfg_cpu_reset (cpu_id, s->entry_addr); + + ret =arm_set_cpu_on (cpu_id, s->entry_addr,0 , +CPU_EXCEPTION_LEVEL_ON_RESET , false); +if (ret !=QEMU_ARM_POWERCTL_RET_SUCCESS ) { +error_report ("%s: failed to bring up CPU %d: err %d" , + __func__, cpu_id, ret); +return ; + } +} + +static uint64_t allwinner_cpucfg_read (void *opaque,hwaddr offset, +unsigned size) +{ +const AwCpuCfgState *s =AW_CPUCFG (opaque); +uint64_t val =0 ; + +switch (offset) { +case REG_CPUS_RST_CTRL :/* CPUs Reset Control */ +case REG_CPU_SYS_RST :/* CPU System Reset */ + val =CPU_SYS_RESET_RELEASED ; +break ; +case REG_CPU0_RST_CTRL :/* CPU#0 Reset Control */ +case REG_CPU1_RST_CTRL :/* CPU#1 Reset Control */ +case REG_CPU2_RST_CTRL :/* CPU#2 Reset Control */ +case REG_CPU3_RST_CTRL :/* CPU#3 Reset Control */ + val =CPUX_RESET_RELEASED ; +break ; +case REG_CPU0_CTRL :/* CPU#0 Control */ +case REG_CPU1_CTRL :/* CPU#1 Control */ +case REG_CPU2_CTRL :/* CPU#2 Control */ +case REG_CPU3_CTRL :/* CPU#3 Control */ + val =0 ; +break ; +case REG_CPU0_STATUS :/* CPU#0 Status */ +case REG_CPU1_STATUS :/* CPU#1 Status */ +case REG_CPU2_STATUS :/* CPU#2 Status */ +case REG_CPU3_STATUS :/* CPU#3 Status */ + val =CPUX_STATUS_SMP ; +break ; +case REG_CLK_GATING :/* CPU Clock Gating */ + val =CLK_GATING_ENABLE ; +break ; +case REG_GEN_CTRL :/* General Control */ + val = s->gen_ctrl; +break ; +case REG_SUPER_STANDBY :/* Super Standby Flag */ + val = s->super_standby; +break ; +case REG_ENTRY_ADDR :/* Reset Entry Address */ + val = s->entry_addr; +break ; +case REG_DBG_EXTERN :/* Debug External */ +case REG_CNT64_CTRL :/* 64-bit Counter Control */ +case REG_CNT64_LOW :/* 64-bit Counter Low */ +case REG_CNT64_HIGH :/* 64-bit Counter High */ +qemu_log_mask (LOG_UNIMP ,"%s: unimplemented register at 0x%04x\n" , + __func__, (uint32_t )offset); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: out-of-bounds offset 0x%04x\n" , + __func__, (uint32_t )offset); +break ; + } + +trace_allwinner_cpucfg_read (offset, val, size); + +return val; +} + +static void allwinner_cpucfg_write (void *opaque,hwaddr offset, +uint64_t val,unsigned size) +{ +AwCpuCfgState *s =AW_CPUCFG (opaque); + +trace_allwinner_cpucfg_write (offset, val, size); + +switch (offset) { +case REG_CPUS_RST_CTRL :/* CPUs Reset Control */ +case REG_CPU_SYS_RST :/* CPU System Reset */ +break ; +case REG_CPU0_RST_CTRL :/* CPU#0 Reset Control */ +case REG_CPU1_RST_CTRL :/* CPU#1 Reset Control */ +case REG_CPU2_RST_CTRL :/* CPU#2 Reset Control */ +case REG_CPU3_RST_CTRL :/* CPU#3 Reset Control */ +if (val) { +allwinner_cpucfg_cpu_reset (s, (offset -REG_CPU0_RST_CTRL ) >>6 ); + } +break ; +case REG_CPU0_CTRL :/* CPU#0 Control */ +case REG_CPU1_CTRL :/* CPU#1 Control */ +case REG_CPU2_CTRL :/* CPU#2 Control */ +case REG_CPU3_CTRL :/* CPU#3 Control */ +case REG_CPU0_STATUS :/* CPU#0 Status */ +case REG_CPU1_STATUS :/* CPU#1 Status */ +case REG_CPU2_STATUS :/* CPU#2 Status */ +case REG_CPU3_STATUS :/* CPU#3 Status */ +case REG_CLK_GATING :/* CPU Clock Gating */ +case REG_GEN_CTRL :/* General Control */ + s->gen_ctrl = val; +break ; +case REG_SUPER_STANDBY :/* Super Standby Flag */ + s->super_standby = val; +break ; +case REG_ENTRY_ADDR :/* Reset Entry Address */ + s->entry_addr = val; +break ; +case REG_DBG_EXTERN :/* Debug External */ +case REG_CNT64_CTRL :/* 64-bit Counter Control */ +case REG_CNT64_LOW :/* 64-bit Counter Low */ +case REG_CNT64_HIGH :/* 64-bit Counter High */ +qemu_log_mask (LOG_UNIMP ,"%s: unimplemented register at 0x%04x\n" , + __func__, (uint32_t )offset); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: out-of-bounds offset 0x%04x\n" , + __func__, (uint32_t )offset); +break ; + } +} + +static const MemoryRegionOps allwinner_cpucfg_ops = { + .read = allwinner_cpucfg_read, + .write = allwinner_cpucfg_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + }, + .impl.min_access_size =4 , +}; + +static void allwinner_cpucfg_reset (DeviceState *dev) +{ +AwCpuCfgState *s =AW_CPUCFG (dev); + +/* Set default values for registers */ + s->gen_ctrl =REG_GEN_CTRL_RST ; + s->super_standby =REG_SUPER_STANDBY_RST ; + s->entry_addr =0 ; +} + +static void allwinner_cpucfg_init (Object *obj) +{ +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); +AwCpuCfgState *s =AW_CPUCFG (obj); + +/* Memory mapping */ +memory_region_init_io (&s->iomem,OBJECT (s), &allwinner_cpucfg_ops, s, +TYPE_AW_CPUCFG ,1 * KiB);
hw/misc/allwinner-cpucfg.c line 243
Quoted 10 lines
hw/misc/allwinner-cpucfg.c new file +10
-0+sysbus_init_mmio (sbd, &s->iomem); +} + +static const VMStateDescription allwinner_cpucfg_vmstate = { + .name ="allwinner-cpucfg" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (gen_ctrl, AwCpuCfgState), +VMSTATE_UINT32 (super_standby, AwCpuCfgState),
Don't we need to migrate entry_addr?
Quoted 54 lines
hw/misc/allwinner-cpucfg.c new file +26
-0+ VMSTATE_END_OF_LIST() + } +}; + +static void allwinner_cpucfg_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->reset = allwinner_cpucfg_reset; + dc->vmsd = &allwinner_cpucfg_vmstate; +} + +static const TypeInfo allwinner_cpucfg_info = { + .name =TYPE_AW_CPUCFG , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_init = allwinner_cpucfg_init, + .instance_size =sizeof (AwCpuCfgState), + .class_init = allwinner_cpucfg_class_init, +}; + +static void allwinner_cpucfg_register (void ) +{ +type_register_static (&allwinner_cpucfg_info); +} + +type_init (allwinner_cpucfg_register)hw/misc/Makefile.objs +1
-0@@ -29,6 +29,7 @@ common-obj-$(CONFIG_MACIO) += macio/ common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o +obj-$(CONFIG_ALLWINNER_H3) += allwinner-cpucfg.o common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-sysctrl.o common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o common-obj-$(CONFIG_NSERIES) += cbus.ohw/misc/trace-events +5
-0@@ -1,5 +1,10 @@ # See docs/devel/tracing.txt for syntax documentation. +# allwinner-cpucfg.c +allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "id %u, reset_addr 0x%" PRIu32 +allwinner_cpucfg_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 +allwinner_cpucfg_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 + # eccmemctl.c ecc_mem_writel_mer(uint32_t val) "Write memory enable 0x%08x" ecc_mem_writel_mdr(uint32_t val) "Write memory delay 0x%08x"
Re: [PATCH v4 06/20] hw/arm/allwinner: add CPU Configuration module
Quoted 400 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Niek Linnenbank
Various Allwinner System on Chip designs contain multiple processors that can be configured and reset using the generic CPU Configuration module interface. This commit adds support for the Allwinner CPU configuration interface which emulates the following features:
* CPU reset
* CPU statusSigned-off-by Niek Linnenbank <[email protected]>--- include/hw/arm/allwinner-h3.h | 3 + include/hw/misc/allwinner-cpucfg.h | 52 ++++++ hw/arm/allwinner-h3.c | 9 +- hw/misc/allwinner-cpucfg.c | 269 +++++++++++++++++++++++++++++ hw/misc/Makefile.objs | 1 + hw/misc/trace-events | 5 + 6 files changed, 338 insertions(+), 1 deletion(-)Review
Quoted 4 lines
create mode 100644
include/hw/misc/allwinner-cpucfg.hcreate mode 100644hw/misc/allwinner-cpucfg.c(quoted diff) +0
-0
b/include/hw/arm/allwinner-h3.hReview
Quoted 28 lines
index
43500c4262..dc729176ab100644include/hw/arm/allwinner-h3.h +3
-0@@ -40,6 +40,7 @@#include "hw/timer/allwinner-a10-pit.h" #include "hw/intc/arm_gic.h" #include "hw/misc/allwinner-h3-ccu.h" +#include "hw/misc/allwinner-cpucfg.h" #include "hw/misc/allwinner-h3-sysctrl.h" #include "target/arm/cpu.h" @@ -76,6 +77,7 @@ enum {AW_H3_GIC_CPU ,AW_H3_GIC_HYP ,AW_H3_GIC_VCPU , +AW_H3_CPUCFG , AW_H3_SDRAM };@@ -110,6 +112,7 @@ typedef struct AwH3State {const hwaddr *memmap;AwA10PITState timer;AwH3ClockCtlState ccu; +AwCpuCfgState cpucfg;AwH3SysCtrlState sysctrl;GICState gic;MemoryRegion sram_a1;(quoted diff) +0
-0
b/include/hw/misc/allwinner-cpucfg.hQuoted 79 lines
new file mode 100644
index 0000000000..2c3693a8beinclude/hw/misc/allwinner-cpucfg.h new file +17
-0@@ -0,0 +1,52 @@ +/* +* Allwinner CPU Configuration Module emulation +* +* Copyright (C) 2019 Niek Linnenbank <[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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/ .
+ */include/hw/misc/allwinner-cpucfg.h new file +34
-0+ +#ifndef HW_MISC_ALLWINNER_CPUCFG_H +#define HW_MISC_ALLWINNER_CPUCFG_H + +#include "qom/object.h" +#include "hw/sysbus.h" + +/** +* Object model +* @{ +*/ + +#define TYPE_AW_CPUCFG "allwinner-cpucfg" +#define AW_CPUCFG (obj) \ + OBJECT_CHECK(AwCpuCfgState, (obj), TYPE_AW_CPUCFG) + +/** @} */ + +/** +* Allwinner CPU Configuration Module instance state +*/ +typedef struct AwCpuCfgState { +/*< private >*/ +SysBusDevice parent_obj; +/*< public >*/ + +MemoryRegion iomem; +uint32_t gen_ctrl; +uint32_t super_standby; +uint32_t entry_addr; + +}AwCpuCfgState ; + +#endif /* HW_MISC_ALLWINNER_CPUCFG_H */ hw/arm/allwinner-h3.c +1
-1@@ -56,6 +56,7 @@ const hwaddr allwinner_h3_memmap[] = { [AW_H3_GIC_CPU] = 0x01c82000, [AW_H3_GIC_HYP] = 0x01c84000, [AW_H3_GIC_VCPU] = 0x01c86000, + [AW_H3_CPUCFG] = 0x01f01c00, [AW_H3_SDRAM] = 0x40000000 };@@ -122,7 +123,6 @@ struct AwH3Unimplemented { { "r_wdog", 0x01f01000, 1 * KiB }, { "r_prcm", 0x01f01400, 1 * KiB }, { "r_twd", 0x01f01800, 1 * KiB }, - { "r_cpucfg", 0x01f01c00, 1 * KiB }, { "r_cir-rx", 0x01f02000, 1 * KiB }, { "r_twi", 0x01f02400, 1 * KiB }, { "r_uart", 0x01f02800, 1 * KiB },hw/arm/allwinner-h3.c static void allwinner_h3_init(Object *obj) · line 196
Quoted 2 lines
hw/arm/allwinner-h3.c +0
-0@@ -195,6 +195,9 @@ static void allwinner_h3_init(Object *obj) sysbus_init_child_obj(obj, "sysctrl", &s->sysctrl,
sizeof(s->sysctrl),hw/arm/allwinner-h3.c static void allwinner_h3_realize(DeviceState *dev,
Quoted 8 lines
hw/arm/allwinner-h3.c +3
-0TYPE_AW_H3_SYSCTRL); + +sysbus_init_child_obj (obj,"cpucfg" , &s->cpucfg,sizeof (s->cpucfg), +TYPE_AW_CPUCFG ); }static void allwinner_h3_realize (DeviceState *dev,Error **errp)@@ -308,6 +311,10 @@ static void allwinner_h3_realize(DeviceState *dev,Error **errp)
hw/arm/allwinner-h3.c static void allwinner_h3_realize(DeviceState *dev, · line 312
Quoted 2 lines
hw/arm/allwinner-h3.c +0
-0qdev_init_nofail (DEVICE (&s->sysctrl)); sysbus_mmio_map(SYS_BUS_DEVICE(&s->sysctrl), 0,s->memmap[AW_H3_SYSCTRL]);
hw/arm/allwinner-h3.c static void allwinner_h3_realize(DeviceState *dev, Error **errp)
Quoted 4 lines
hw/arm/allwinner-h3.c +3
-0+/* CPU Configuration */ +qdev_init_nofail (DEVICE (&s->cpucfg)); + sysbus_mmio_map(SYS_BUS_DEVICE(&s->cpucfg), 0,s->memmap[AW_H3_CPUCFG]);
Quoted 141 lines
hw/arm/allwinner-h3.c +1
-0+/* Universal Serial Bus */ sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0], qdev_get_gpio_in(DEVICE(&s->gic),hw/misc/allwinner-cpucfg.c new file +17
-0@@ -0,0 +1,269 @@ +/* +* Allwinner CPU Configuration Module emulation +* +* Copyright (C) 2019 Niek Linnenbank <[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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/ .
+ */hw/misc/allwinner-cpucfg.c new file +112
-0+ +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "hw/sysbus.h" +#include "migration/vmstate.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/error-report.h" +#include "qemu/timer.h" +#include "hw/core/cpu.h" +#include "arm-powerctl.h" +#include "hw/misc/allwinner-cpucfg.h" +#include "trace.h" + +/* CPUCFG register offsets */ +enum { +REG_CPUS_RST_CTRL =0x0000 ,/* CPUs Reset Control */ +REG_CPU0_RST_CTRL =0x0040 ,/* CPU#0 Reset Control */ +REG_CPU0_CTRL =0x0044 ,/* CPU#0 Control */ +REG_CPU0_STATUS =0x0048 ,/* CPU#0 Status */ +REG_CPU1_RST_CTRL =0x0080 ,/* CPU#1 Reset Control */ +REG_CPU1_CTRL =0x0084 ,/* CPU#1 Control */ +REG_CPU1_STATUS =0x0088 ,/* CPU#1 Status */ +REG_CPU2_RST_CTRL =0x00C0 ,/* CPU#2 Reset Control */ +REG_CPU2_CTRL =0x00C4 ,/* CPU#2 Control */ +REG_CPU2_STATUS =0x00C8 ,/* CPU#2 Status */ +REG_CPU3_RST_CTRL =0x0100 ,/* CPU#3 Reset Control */ +REG_CPU3_CTRL =0x0104 ,/* CPU#3 Control */ +REG_CPU3_STATUS =0x0108 ,/* CPU#3 Status */ +REG_CPU_SYS_RST =0x0140 ,/* CPU System Reset */ +REG_CLK_GATING =0x0144 ,/* CPU Clock Gating */ +REG_GEN_CTRL =0x0184 ,/* General Control */ +REG_SUPER_STANDBY =0x01A0 ,/* Super Standby Flag */ +REG_ENTRY_ADDR =0x01A4 ,/* Reset Entry Address */ +REG_DBG_EXTERN =0x01E4 ,/* Debug External */ +REG_CNT64_CTRL =0x0280 ,/* 64-bit Counter Control */ +REG_CNT64_LOW =0x0284 ,/* 64-bit Counter Low */ +REG_CNT64_HIGH =0x0288 ,/* 64-bit Counter High */ +}; + +/* CPUCFG register flags */ +enum { +CPUX_RESET_RELEASED = ((1 <<1 ) | (1 <<0 )), +CPUX_STATUS_SMP = (1 <<0 ), +CPU_SYS_RESET_RELEASED = (1 <<0 ), +CLK_GATING_ENABLE = ((1 <<8 ) |0xF ), +}; + +/* CPUCFG register reset values */ +enum { +REG_CLK_GATING_RST =0x0000010F , +REG_GEN_CTRL_RST =0x00000020 , +REG_SUPER_STANDBY_RST =0x0 , +REG_CNT64_CTRL_RST =0x0 , +}; + +/* CPUCFG constants */ +enum { +CPU_EXCEPTION_LEVEL_ON_RESET =3 ,/* EL3 */ +}; + +static void allwinner_cpucfg_cpu_reset (AwCpuCfgState *s,uint8_t cpu_id) +{ +int ret; + +trace_allwinner_cpucfg_cpu_reset (cpu_id, s->entry_addr); + + ret =arm_set_cpu_on (cpu_id, s->entry_addr,0 , +CPU_EXCEPTION_LEVEL_ON_RESET , false); +if (ret !=QEMU_ARM_POWERCTL_RET_SUCCESS ) { +error_report ("%s: failed to bring up CPU %d: err %d" , + __func__, cpu_id, ret); +return ; + } +} + +static uint64_t allwinner_cpucfg_read (void *opaque,hwaddr offset, +unsigned size) +{ +const AwCpuCfgState *s =AW_CPUCFG (opaque); +uint64_t val =0 ; + +switch (offset) { +case REG_CPUS_RST_CTRL :/* CPUs Reset Control */ +case REG_CPU_SYS_RST :/* CPU System Reset */ + val =CPU_SYS_RESET_RELEASED ; +break ; +case REG_CPU0_RST_CTRL :/* CPU#0 Reset Control */ +case REG_CPU1_RST_CTRL :/* CPU#1 Reset Control */ +case REG_CPU2_RST_CTRL :/* CPU#2 Reset Control */ +case REG_CPU3_RST_CTRL :/* CPU#3 Reset Control */ + val =CPUX_RESET_RELEASED ; +break ; +case REG_CPU0_CTRL :/* CPU#0 Control */ +case REG_CPU1_CTRL :/* CPU#1 Control */ +case REG_CPU2_CTRL :/* CPU#2 Control */ +case REG_CPU3_CTRL :/* CPU#3 Control */ + val =0 ; +break ; +case REG_CPU0_STATUS :/* CPU#0 Status */ +case REG_CPU1_STATUS :/* CPU#1 Status */ +case REG_CPU2_STATUS :/* CPU#2 Status */ +case REG_CPU3_STATUS :/* CPU#3 Status */ + val =CPUX_STATUS_SMP ; +break ; +case REG_CLK_GATING :/* CPU Clock Gating */ + val =CLK_GATING_ENABLE ; +break ; +case REG_GEN_CTRL :/* General Control */ + val = s->gen_ctrl; +break ; +case REG_SUPER_STANDBY :/* Super Standby Flag */ hw/misc/allwinner-cpucfg.c
Quoted 10 lines
hw/misc/allwinner-cpucfg.c new file +10
-0+ val = s->super_standby; +break ; +case REG_ENTRY_ADDR :/* Reset Entry Address */ + val = s->entry_addr; +break ; +case REG_DBG_EXTERN :/* Debug External */ +case REG_CNT64_CTRL :/* 64-bit Counter Control */ +case REG_CNT64_LOW :/* 64-bit Counter Low */ +case REG_CNT64_HIGH :/* 64-bit Counter High */ + qemu_log_mask(LOG_UNIMP, "%s: unimplemented register at0x%04x\n",
hw/misc/allwinner-cpucfg.c
Quoted 4 lines
hw/misc/allwinner-cpucfg.c new file +4
-0+ __func__, (uint32_t)offset); +break ; +default : + qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset0x%04x\n",
Quoted 42 lines
hw/misc/allwinner-cpucfg.c new file +26
-0+ __func__, (uint32_t)offset); +break ; + } + +trace_allwinner_cpucfg_read (offset, val, size); + +return val; +} + +static void allwinner_cpucfg_write (void *opaque,hwaddr offset, +uint64_t val,unsigned size) +{ +AwCpuCfgState *s =AW_CPUCFG (opaque); + +trace_allwinner_cpucfg_write (offset, val, size); + +switch (offset) { +case REG_CPUS_RST_CTRL :/* CPUs Reset Control */ +case REG_CPU_SYS_RST :/* CPU System Reset */ +break ; +case REG_CPU0_RST_CTRL :/* CPU#0 Reset Control */ +case REG_CPU1_RST_CTRL :/* CPU#1 Reset Control */ +case REG_CPU2_RST_CTRL :/* CPU#2 Reset Control */ +case REG_CPU3_RST_CTRL :/* CPU#3 Reset Control */ +if (val) { + allwinner_cpucfg_cpu_reset(s, (offset - REG_CPU0_RST_CTRL)Quoted 1 line
6);
hw/misc/allwinner-cpucfg.c new file +15
-0+ } +break ; +case REG_CPU0_CTRL :/* CPU#0 Control */ +case REG_CPU1_CTRL :/* CPU#1 Control */ +case REG_CPU2_CTRL :/* CPU#2 Control */ +case REG_CPU3_CTRL :/* CPU#3 Control */ +case REG_CPU0_STATUS :/* CPU#0 Status */ +case REG_CPU1_STATUS :/* CPU#1 Status */ +case REG_CPU2_STATUS :/* CPU#2 Status */ +case REG_CPU3_STATUS :/* CPU#3 Status */ +case REG_CLK_GATING :/* CPU Clock Gating */ +case REG_GEN_CTRL :/* General Control */ + s->gen_ctrl = val; +break ; +case REG_SUPER_STANDBY :/* Super Standby Flag */ hw/misc/allwinner-cpucfg.c
Quoted 10 lines
hw/misc/allwinner-cpucfg.c new file +10
-0+ s->super_standby = val; +break ; +case REG_ENTRY_ADDR :/* Reset Entry Address */ + s->entry_addr = val; +break ; +case REG_DBG_EXTERN :/* Debug External */ +case REG_CNT64_CTRL :/* 64-bit Counter Control */ +case REG_CNT64_LOW :/* 64-bit Counter Low */ +case REG_CNT64_HIGH :/* 64-bit Counter High */ + qemu_log_mask(LOG_UNIMP, "%s: unimplemented register at0x%04x\n",
hw/misc/allwinner-cpucfg.c
Quoted 4 lines
hw/misc/allwinner-cpucfg.c new file +4
-0+ __func__, (uint32_t)offset); +break ; +default : + qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset0x%04x\n",
Quoted 23 lines
hw/misc/allwinner-cpucfg.c new file +23
-0+ __func__, (uint32_t)offset); +break ; + } +} + +static const MemoryRegionOps allwinner_cpucfg_ops = { + .read = allwinner_cpucfg_read, + .write = allwinner_cpucfg_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + }, + .impl.min_access_size =4 , +}; + +static void allwinner_cpucfg_reset (DeviceState *dev) +{ +AwCpuCfgState *s =AW_CPUCFG (dev); + +/* Set default values for registers */ + s->gen_ctrl =REG_GEN_CTRL_RST ; + s->super_standby =REG_SUPER_STANDBY_RST ;hw/misc/allwinner-cpucfg.c
Quoted 10 lines
hw/misc/allwinner-cpucfg.c new file +10
-0+ s->entry_addr =0 ; +} + +static void allwinner_cpucfg_init (Object *obj) +{ +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); +AwCpuCfgState *s =AW_CPUCFG (obj); + +/* Memory mapping */ + memory_region_init_io(&s->iomem, OBJECT(s), &allwinner_cpucfg_ops,s,
Quoted 15 lines
hw/misc/allwinner-cpucfg.c line 243
Quoted 11 lines
hw/misc/allwinner-cpucfg.c new file +11
-0+ TYPE_AW_CPUCFG, 1 * KiB); +sysbus_init_mmio (sbd, &s->iomem); +} + +static const VMStateDescription allwinner_cpucfg_vmstate = { + .name ="allwinner-cpucfg" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (gen_ctrl, AwCpuCfgState), +VMSTATE_UINT32 (super_standby, AwCpuCfgState),Don't we need to migrate
entry_addr?
Thanks Philippe, indeed entry_addr should also be there. I'll add it.
Regards,
Niek
Quoted 59 lines
Quoted 43 lines
hw/misc/allwinner-cpucfg.c new file +26
-0+ VMSTATE_END_OF_LIST() + } +}; + +static void allwinner_cpucfg_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->reset = allwinner_cpucfg_reset; + dc->vmsd = &allwinner_cpucfg_vmstate; +} + +static const TypeInfo allwinner_cpucfg_info = { + .name =TYPE_AW_CPUCFG , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_init = allwinner_cpucfg_init, + .instance_size =sizeof (AwCpuCfgState), + .class_init = allwinner_cpucfg_class_init, +}; + +static void allwinner_cpucfg_register (void ) +{ +type_register_static (&allwinner_cpucfg_info); +} + +type_init (allwinner_cpucfg_register)hw/misc/Makefile.objs +1
-0@@ -29,6 +29,7 @@ common-obj-$(CONFIG_MACIO) += macio/ common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o +obj-$(CONFIG_ALLWINNER_H3) += allwinner-cpucfg.o common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-sysctrl.o common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o common-obj-$(CONFIG_NSERIES) += cbus.ohw/misc/trace-events +0
-0hw/misc/trace-events line 4
Quoted 4 lines
hw/misc/trace-events +2
-0@@ -1,5 +1,10 @@ # See docs/devel/tracing.txt for syntax documentation. +# allwinner-cpucfg.c +allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "id %u,
reset_addr0x%" PRIu32hw/misc/trace-events line 5
Quoted 1 line
hw/misc/trace-events +1
-0+allwinner_cpucfg_read(uint64_t offset, uint64_t data, unsigned size)"offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
hw/misc/trace-events line 6
Quoted 1 line
hw/misc/trace-events +1
-0+allwinner_cpucfg_write(uint64_t offset, uint64_t data, unsigned size)"offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
Quoted 5 lines
hw/misc/trace-events +1
-0+ # eccmemctl.c ecc_mem_writel_mer(uint32_t val) "Write memory enable 0x%08x" ecc_mem_writel_mdr(uint32_t val) "Write memory delay 0x%08x"
Signature · 1 line
Niek Linnenbank
PATCH v4 7/20 hw/arm/allwinner: add Security Identifier device
In reply to Niek LinnenbankThe Security Identifier device found in various Allwinner System on Chip designs gives applications a per-board unique identifier. This commit adds support for the Allwinner Security Identifier using a 128-bit UUID value as input.
--- include/hw/arm/allwinner-h3.h | 3 + include/hw/misc/allwinner-sid.h | 60 +++++++++++ hw/arm/allwinner-h3.c | 11 ++- hw/arm/orangepi.c | 4 + hw/misc/allwinner-sid.c | 170 ++++++++++++++++++++++++++++++++ hw/misc/Makefile.objs | 1 + hw/misc/trace-events | 4 + 7 files changed, 252 insertions(+), 1 deletion(-) create mode 100644 include/hw/misc/allwinner-sid.h create mode 100644 hw/misc/allwinner-sid.c
include/hw/arm/allwinner-h3.h +3 -0
@@ -42,6 +42,7 @@#include "hw/misc/allwinner-h3-ccu.h" #include "hw/misc/allwinner-cpucfg.h" #include "hw/misc/allwinner-h3-sysctrl.h" +#include "hw/misc/allwinner-sid.h" #include "target/arm/cpu.h" /**
@@ -59,6 +60,7 @@ enum {AW_H3_SRAM_A2 ,AW_H3_SRAM_C ,AW_H3_SYSCTRL , +AW_H3_SID ,AW_H3_EHCI0 ,AW_H3_OHCI0 , AW_H3_EHCI1,
@@ -114,6 +116,7 @@ typedef struct AwH3State {AwH3ClockCtlState ccu;AwCpuCfgState cpucfg;AwH3SysCtrlState sysctrl; +AwSidState sid;GICState gic;MemoryRegion sram_a1;MemoryRegion sram_a2;
include/hw/misc/allwinner-sid.h new file +60 -0
60 lines not on this page · raw message
hw/arm/allwinner-h3.c +10 -1
@@ -38,6 +38,7 @@ const hwaddr allwinner_h3_memmap[] = { [AW_H3_SRAM_A2] = 0x00044000, [AW_H3_SRAM_C] = 0x00010000, [AW_H3_SYSCTRL] = 0x01c00000, + [AW_H3_SID] = 0x01c14000, [AW_H3_EHCI0] = 0x01c1a000, [AW_H3_OHCI0] = 0x01c1a400, [AW_H3_EHCI1] = 0x01c1b000,
@@ -78,7 +79,6 @@ struct AwH3Unimplemented { { "mmc0", 0x01c0f000, 4 * KiB }, { "mmc1", 0x01c10000, 4 * KiB }, { "mmc2", 0x01c11000, 4 * KiB }, - { "sid", 0x01c14000, 1 * KiB }, { "crypto", 0x01c15000, 4 * KiB }, { "msgbox", 0x01c17000, 4 * KiB }, { "spinlock", 0x01c18000, 4 * KiB },
@@ -198,6 +198,11 @@ static void allwinner_h3_init(Object *obj)sysbus_init_child_obj (obj,"cpucfg" , &s->cpucfg,sizeof (s->cpucfg),TYPE_AW_CPUCFG ); + +sysbus_init_child_obj (obj,"sid" , &s->sid,sizeof (s->sid), +TYPE_AW_SID ); +object_property_add_alias (obj,"identifier" ,OBJECT (&s->sid), +"identifier" , &error_abort); }static void allwinner_h3_realize (DeviceState *dev,Error **errp)
@@ -315,6 +320,10 @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)qdev_init_nofail (DEVICE (&s->cpucfg));sysbus_mmio_map (SYS_BUS_DEVICE (&s->cpucfg),0 , s->memmap[AW_H3_CPUCFG ]); +/* Security Identifier */ +qdev_init_nofail (DEVICE (&s->sid)); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->sid),0 , s->memmap[AW_H3_SID ]); +/* Universal Serial Bus */ sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0], qdev_get_gpio_in(DEVICE(&s->gic),
hw/arm/orangepi.c +4 -0
@@ -61,6 +61,10 @@ static void orangepi_init(MachineState *machine)object_property_set_int (OBJECT (s->h3),24 *1000 *1000 ,"clk1-freq" , &error_abort); +/* Setup SID properties */ +qdev_prop_set_string (DEVICE (s->h3),"identifier" , +"8100c002-0001-0002-0003-000044556677" ); +/* Mark H3 object realized */ object_property_set_bool (OBJECT (s->h3), true,"realized" , &error_abort);
hw/misc/allwinner-sid.c new file +170 -0
170 lines not on this page · raw message
hw/misc/Makefile.objs +1 -0
@@ -31,6 +31,7 @@ common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o obj-$(CONFIG_ALLWINNER_H3) += allwinner-cpucfg.o common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-sysctrl.o +common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-sid.o common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o common-obj-$(CONFIG_NSERIES) += cbus.o common-obj-$(CONFIG_ECCMEMCTL) += eccmemctl.o
hw/misc/trace-events +4 -0
@@ -5,6 +5,10 @@ allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "id %u, reset_ad allwinner_cpucfg_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 allwinner_cpucfg_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 +# allwinner-sid.c +allwinner_sid_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 +allwinner_sid_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 + # eccmemctl.c ecc_mem_writel_mer(uint32_t val) "Write memory enable 0x%08x" ecc_mem_writel_mdr(uint32_t val) "Write memory delay 0x%08x"
Signature · 1 line
2.17.1
Re: [PATCH v4 07/20] hw/arm/allwinner: add Security Identifier device
Quoted 160 lines · Niek Linnenbank
The Security Identifier device found in various Allwinner System on Chip designs gives applications a per-board unique identifier. This commit adds support for the Allwinner Security Identifier using a 128-bit UUID value as input.
Signed-off-by Niek Linnenbank <[email protected]>--- include/hw/arm/allwinner-h3.h | 3 + include/hw/misc/allwinner-sid.h | 60 +++++++++++ hw/arm/allwinner-h3.c | 11 ++- hw/arm/orangepi.c | 4 + hw/misc/allwinner-sid.c | 170 ++++++++++++++++++++++++++++++++ hw/misc/Makefile.objs | 1 + hw/misc/trace-events | 4 + 7 files changed, 252 insertions(+), 1 deletion(-)create mode 100644
include/hw/misc/allwinner-sid.hcreate mode 100644hw/misc/allwinner-sid.cinclude/hw/arm/allwinner-h3.h +3
-0@@ -42,6 +42,7 @@#include "hw/misc/allwinner-h3-ccu.h" #include "hw/misc/allwinner-cpucfg.h" #include "hw/misc/allwinner-h3-sysctrl.h" +#include "hw/misc/allwinner-sid.h" #include "target/arm/cpu.h" /** @@ -59,6 +60,7 @@ enum {AW_H3_SRAM_A2 ,AW_H3_SRAM_C ,AW_H3_SYSCTRL , +AW_H3_SID ,AW_H3_EHCI0 ,AW_H3_OHCI0 , AW_H3_EHCI1,@@ -114,6 +116,7 @@ typedef struct AwH3State {AwH3ClockCtlState ccu;AwCpuCfgState cpucfg;AwH3SysCtrlState sysctrl; +AwSidState sid;GICState gic;MemoryRegion sram_a1;MemoryRegion sram_a2;include/hw/misc/allwinner-sid.h new file +60
-0@@ -0,0 +1,60 @@ +/* +* Allwinner Security ID emulation +* +* Copyright (C) 2019 Niek Linnenbank <[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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HW_MISC_ALLWINNER_SID_H +#define HW_MISC_ALLWINNER_SID_H + +#include "qom/object.h" +#include "hw/sysbus.h" +#include "qemu/uuid.h" + +/** +* Object model +* @{ +*/ + +#define TYPE_AW_SID "allwinner-sid" +#define AW_SID (obj) \ + OBJECT_CHECK(AwSidState, (obj), TYPE_AW_SID) + +/** @} */ + +/** +* Allwinner Security ID object instance state +*/ +typedef struct AwSidState { +/*< private >*/ +SysBusDevice parent_obj; +/*< public >*/ + +/** Maps I/O registers in physical memory */ +MemoryRegion iomem; + +/** Control register defines how and what to read */ +uint32_t control; + +/** RdKey register contains the data retrieved by the device */ +uint32_t rdkey; + +/** Stores the emulated device identifier */ +QemuUUID identifier; + +}AwSidState ; + +#endif /* HW_MISC_ALLWINNER_SID_H */ hw/arm/allwinner-h3.c +10
-1@@ -38,6 +38,7 @@ const hwaddr allwinner_h3_memmap[] = { [AW_H3_SRAM_A2] = 0x00044000, [AW_H3_SRAM_C] = 0x00010000, [AW_H3_SYSCTRL] = 0x01c00000, + [AW_H3_SID] = 0x01c14000, [AW_H3_EHCI0] = 0x01c1a000, [AW_H3_OHCI0] = 0x01c1a400, [AW_H3_EHCI1] = 0x01c1b000,@@ -78,7 +79,6 @@ struct AwH3Unimplemented { { "mmc0", 0x01c0f000, 4 * KiB }, { "mmc1", 0x01c10000, 4 * KiB }, { "mmc2", 0x01c11000, 4 * KiB }, - { "sid", 0x01c14000, 1 * KiB }, { "crypto", 0x01c15000, 4 * KiB }, { "msgbox", 0x01c17000, 4 * KiB }, { "spinlock", 0x01c18000, 4 * KiB },@@ -198,6 +198,11 @@ static void allwinner_h3_init(Object *obj)sysbus_init_child_obj (obj,"cpucfg" , &s->cpucfg,sizeof (s->cpucfg),TYPE_AW_CPUCFG ); + +sysbus_init_child_obj (obj,"sid" , &s->sid,sizeof (s->sid), +TYPE_AW_SID ); +object_property_add_alias (obj,"identifier" ,OBJECT (&s->sid), +"identifier" , &error_abort); }static void allwinner_h3_realize (DeviceState *dev,Error **errp)@@ -315,6 +320,10 @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)qdev_init_nofail (DEVICE (&s->cpucfg));sysbus_mmio_map (SYS_BUS_DEVICE (&s->cpucfg),0 , s->memmap[AW_H3_CPUCFG ]); +/* Security Identifier */ +qdev_init_nofail (DEVICE (&s->sid)); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->sid),0 , s->memmap[AW_H3_SID ]); +/* Universal Serial Bus */ sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0], qdev_get_gpio_in(DEVICE(&s->gic),hw/arm/orangepi.c +0
-0
hw/arm/orangepi.c static void orangepi_init(MachineState *machine) · line 66
Quoted 6 lines
hw/arm/orangepi.c +3
-0@@ -61,6 +61,10 @@ static void orangepi_init(MachineState *machine)object_property_set_int (OBJECT (s->h3),24 *1000 *1000 ,"clk1-freq" , &error_abort); +/* Setup SID properties */ +qdev_prop_set_string (DEVICE (s->h3),"identifier" , +"8100c002-0001-0002-0003-000044556677" );
This part misses a comment that we are enforcing the same UUID on all VMs (for now).
Quoted 143 lines
hw/arm/orangepi.c +1
-0+/* Mark H3 object realized */ object_property_set_bool (OBJECT (s->h3), true,"realized" , &error_abort);hw/misc/allwinner-sid.c new file +133
-0@@ -0,0 +1,170 @@ +/* +* Allwinner Security ID emulation +* +* Copyright (C) 2019 Niek Linnenbank <[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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "hw/sysbus.h" +#include "migration/vmstate.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/guest-random.h" +#include "qapi/error.h" +#include "hw/qdev-properties.h" +#include "hw/misc/allwinner-sid.h" +#include "trace.h" + +/* SID register offsets */ +enum { +REG_PRCTL =0x40 ,/* Control */ +REG_RDKEY =0x60 ,/* Read Key */ +}; + +/* SID register flags */ +enum { +REG_PRCTL_WRITE =0x0002 ,/* Unknown write flag */ +REG_PRCTL_OP_LOCK =0xAC00 ,/* Lock operation */ +}; + +static uint64_t allwinner_sid_read (void *opaque,hwaddr offset, +unsigned size) +{ +const AwSidState *s =AW_SID (opaque); +uint64_t val =0 ; + +switch (offset) { +case REG_PRCTL :/* Control */ + val = s->control; +break ; +case REG_RDKEY :/* Read Key */ + val = s->rdkey; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: out-of-bounds offset 0x%04x\n" , + __func__, (uint32_t )offset); +return 0 ; + } + +trace_allwinner_sid_read (offset, val, size); + +return val; +} + +static void allwinner_sid_write (void *opaque,hwaddr offset, +uint64_t val,unsigned size) +{ +AwSidState *s =AW_SID (opaque); + +trace_allwinner_sid_write (offset, val, size); + +switch (offset) { +case REG_PRCTL :/* Control */ + s->control = val; + +if ((s->control ®_PRCTL_OP_LOCK ) && + (s->control ®_PRCTL_WRITE )) { +uint32_t id = s->control >>16 ; + +if (id <sizeof (QemuUUID)) { + s->rdkey = (s->identifier.data[id]) | + (s->identifier.data[id +1 ] <<8 ) | + (s->identifier.data[id +2 ] <<16 ) | + (s->identifier.data[id +3 ] <<24 ); + } + } + s->control &= ~REG_PRCTL_WRITE ; +break ; +case REG_RDKEY :/* Read Key */ +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: out-of-bounds offset 0x%04x\n" , + __func__, (uint32_t )offset); +break ; + } +} + +static const MemoryRegionOps allwinner_sid_ops = { + .read = allwinner_sid_read, + .write = allwinner_sid_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + }, + .impl.min_access_size =4 , +}; + +static void allwinner_sid_reset (DeviceState *dev) +{ +AwSidState *s =AW_SID (dev); + +/* Set default values for registers */ + s->control =0 ; + s->rdkey =0 ; +} + +static void allwinner_sid_init (Object *obj) +{ +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); +AwSidState *s =AW_SID (obj); + +/* Memory mapping */ +memory_region_init_io (&s->iomem,OBJECT (s), &allwinner_sid_ops, s, +TYPE_AW_SID ,1 * KiB); +sysbus_init_mmio (sbd, &s->iomem); +} + +static Property allwinner_sid_properties[] = { +DEFINE_PROP_UUID_NODEFAULT ("identifier" , AwSidState, identifier),
hw/misc/allwinner-sid.c line 143
Quoted 10 lines
hw/misc/allwinner-sid.c new file +10
-0+DEFINE_PROP_END_OF_LIST () +}; + +static const VMStateDescription allwinner_sid_vmstate = { + .name ="allwinner-sid" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (control, AwSidState), +VMSTATE_UINT32 (rdkey, AwSidState),
We need to migrate the UUID too:
VMSTATE_UINT8_ARRAY_V(identifier.data, AwSidState,
sizeof(QemuUUID), 1),
Quoted 55 lines
hw/misc/allwinner-sid.c new file +27
-0+ VMSTATE_END_OF_LIST() + } +}; + +static void allwinner_sid_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->reset = allwinner_sid_reset; + dc->vmsd = &allwinner_sid_vmstate; + dc->props = allwinner_sid_properties; +} + +static const TypeInfo allwinner_sid_info = { + .name =TYPE_AW_SID , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_init = allwinner_sid_init, + .instance_size =sizeof (AwSidState), + .class_init = allwinner_sid_class_init, +}; + +static void allwinner_sid_register (void ) +{ +type_register_static (&allwinner_sid_info); +} + +type_init (allwinner_sid_register)hw/misc/Makefile.objs +1
-0@@ -31,6 +31,7 @@ common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o obj-$(CONFIG_ALLWINNER_H3) += allwinner-cpucfg.o common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-sysctrl.o +common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-sid.o common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o common-obj-$(CONFIG_NSERIES) += cbus.o common-obj-$(CONFIG_ECCMEMCTL) += eccmemctl.ohw/misc/trace-events +4
-0@@ -5,6 +5,10 @@ allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "id %u, reset_ad allwinner_cpucfg_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 allwinner_cpucfg_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 +# allwinner-sid.c +allwinner_sid_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 +allwinner_sid_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 + # eccmemctl.c ecc_mem_writel_mer(uint32_t val) "Write memory enable 0x%08x" ecc_mem_writel_mdr(uint32_t val) "Write memory delay 0x%08x"
Re: [PATCH v4 07/20] hw/arm/allwinner: add Security Identifier device
Quoted 168 lines · Philippe Mathieu-Daudé
Quoted 15 lines · Niek Linnenbank
The Security Identifier device found in various Allwinner System on Chip designs gives applications a per-board unique identifier. This commit adds support for the Allwinner Security Identifier using a 128-bit UUID value as input.
Signed-off-by Niek Linnenbank <[email protected]>--- include/hw/arm/allwinner-h3.h | 3 + include/hw/misc/allwinner-sid.h | 60 +++++++++++ hw/arm/allwinner-h3.c | 11 ++- hw/arm/orangepi.c | 4 + hw/misc/allwinner-sid.c | 170 ++++++++++++++++++++++++++++++++ hw/misc/Makefile.objs | 1 + hw/misc/trace-events | 4 + 7 files changed, 252 insertions(+), 1 deletion(-)Review
Quoted 4 lines
create mode 100644
include/hw/misc/allwinner-sid.hcreate mode 100644hw/misc/allwinner-sid.c(quoted diff) +0
-0
b/include/hw/arm/allwinner-h3.hReview
Quoted 28 lines
index
dc729176ab..85416d9d64100644include/hw/arm/allwinner-h3.h +3
-0@@ -42,6 +42,7 @@#include "hw/misc/allwinner-h3-ccu.h" #include "hw/misc/allwinner-cpucfg.h" #include "hw/misc/allwinner-h3-sysctrl.h" +#include "hw/misc/allwinner-sid.h" #include "target/arm/cpu.h" /** @@ -59,6 +60,7 @@ enum {AW_H3_SRAM_A2 ,AW_H3_SRAM_C ,AW_H3_SYSCTRL , +AW_H3_SID ,AW_H3_EHCI0 ,AW_H3_OHCI0 , AW_H3_EHCI1,@@ -114,6 +116,7 @@ typedef struct AwH3State {AwH3ClockCtlState ccu;AwCpuCfgState cpucfg;AwH3SysCtrlState sysctrl; +AwSidState sid;GICState gic;MemoryRegion sram_a1;MemoryRegion sram_a2;(quoted diff) +0
-0
b/include/hw/misc/allwinner-sid.hhw/arm/allwinner-h3.c static void allwinner_h3_realize(DeviceState *dev,
Quoted 99 lines
new file mode 100644
index 0000000000..4c1fa4762binclude/hw/misc/allwinner-sid.h new file +17
-0@@ -0,0 +1,60 @@ +/* +* Allwinner Security ID emulation +* +* Copyright (C) 2019 Niek Linnenbank <[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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/ .
+ */include/hw/misc/allwinner-sid.h new file +42
-0+ +#ifndef HW_MISC_ALLWINNER_SID_H +#define HW_MISC_ALLWINNER_SID_H + +#include "qom/object.h" +#include "hw/sysbus.h" +#include "qemu/uuid.h" + +/** +* Object model +* @{ +*/ + +#define TYPE_AW_SID "allwinner-sid" +#define AW_SID (obj) \ + OBJECT_CHECK(AwSidState, (obj), TYPE_AW_SID) + +/** @} */ + +/** +* Allwinner Security ID object instance state +*/ +typedef struct AwSidState { +/*< private >*/ +SysBusDevice parent_obj; +/*< public >*/ + +/** Maps I/O registers in physical memory */ +MemoryRegion iomem; + +/** Control register defines how and what to read */ +uint32_t control; + +/** RdKey register contains the data retrieved by the device */ +uint32_t rdkey; + +/** Stores the emulated device identifier */ +QemuUUID identifier; + +}AwSidState ; + +#endif /* HW_MISC_ALLWINNER_SID_H */ hw/arm/allwinner-h3.c +6
-1@@ -38,6 +38,7 @@ const hwaddr allwinner_h3_memmap[] = { [AW_H3_SRAM_A2] = 0x00044000, [AW_H3_SRAM_C] = 0x00010000, [AW_H3_SYSCTRL] = 0x01c00000, + [AW_H3_SID] = 0x01c14000, [AW_H3_EHCI0] = 0x01c1a000, [AW_H3_OHCI0] = 0x01c1a400, [AW_H3_EHCI1] = 0x01c1b000,@@ -78,7 +79,6 @@ struct AwH3Unimplemented { { "mmc0", 0x01c0f000, 4 * KiB }, { "mmc1", 0x01c10000, 4 * KiB }, { "mmc2", 0x01c11000, 4 * KiB }, - { "sid", 0x01c14000, 1 * KiB }, { "crypto", 0x01c15000, 4 * KiB }, { "msgbox", 0x01c17000, 4 * KiB }, { "spinlock", 0x01c18000, 4 * KiB },@@ -198,6 +198,11 @@ static void allwinner_h3_init(Object *obj)sysbus_init_child_obj (obj,"cpucfg" , &s->cpucfg,sizeof (s->cpucfg),TYPE_AW_CPUCFG ); + +sysbus_init_child_obj (obj,"sid" , &s->sid,sizeof (s->sid), +TYPE_AW_SID ); +object_property_add_alias (obj,"identifier" ,OBJECT (&s->sid), +"identifier" , &error_abort); }static void allwinner_h3_realize (DeviceState *dev,Error **errp)@@ -315,6 +320,10 @@ static void allwinner_h3_realize(DeviceState *dev,Error **errp)
hw/arm/allwinner-h3.c static void allwinner_h3_realize(DeviceState *dev, · line 321
Quoted 2 lines
hw/arm/allwinner-h3.c +0
-0qdev_init_nofail (DEVICE (&s->cpucfg)); sysbus_mmio_map(SYS_BUS_DEVICE(&s->cpucfg), 0,s->memmap[AW_H3_CPUCFG]);
Quoted 13 lines
hw/arm/allwinner-h3.c +4
-0+/* Security Identifier */ +qdev_init_nofail (DEVICE (&s->sid)); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->sid),0 , s->memmap[AW_H3_SID ]); +/* Universal Serial Bus */ sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0], qdev_get_gpio_in(DEVICE(&s->gic),hw/arm/orangepi.c +0
-0hw/arm/orangepi.c static void orangepi_init(MachineState *machine) · line 61
Quoted 1 line
hw/arm/orangepi.c +0
-0@@ -61,6 +61,10 @@ static void orangepi_init(MachineState *machine) object_property_set_int(OBJECT(s->h3), 24 * 1000 * 1000,"clk1-freq",
Quoted 9 lines
hw/arm/orangepi.c static void orangepi_init(MachineState *machine) · line 66
Quoted 5 lines
hw/arm/orangepi.c +3
-0&error_abort); +/* Setup SID properties */ +qdev_prop_set_string (DEVICE (s->h3),"identifier" , +"8100c002-0001-0002-0003-000044556677" );This part misses a comment that we are enforcing the same UUID on all VMs (for now).
Good idea, I'll add that in a comment.
Quoted 161 lines
hw/arm/orangepi.c static void orangepi_init(MachineState *machine)
Quoted 4 lines
hw/arm/orangepi.c +1
-0+/* Mark H3 object realized */ object_property_set_bool(OBJECT(s->h3), true, "realized",
&error_abort);Quoted 56 lines
hw/misc/allwinner-sid.c new file +17
-0@@ -0,0 +1,170 @@ +/* +* Allwinner Security ID emulation +* +* Copyright (C) 2019 Niek Linnenbank <[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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/ .
+ */hw/misc/allwinner-sid.c new file +30
-0+ +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "hw/sysbus.h" +#include "migration/vmstate.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/guest-random.h" +#include "qapi/error.h" +#include "hw/qdev-properties.h" +#include "hw/misc/allwinner-sid.h" +#include "trace.h" + +/* SID register offsets */ +enum { +REG_PRCTL =0x40 ,/* Control */ +REG_RDKEY =0x60 ,/* Read Key */ +}; + +/* SID register flags */ +enum { +REG_PRCTL_WRITE =0x0002 ,/* Unknown write flag */ +REG_PRCTL_OP_LOCK =0xAC00 ,/* Lock operation */ +}; + +static uint64_t allwinner_sid_read (void *opaque,hwaddr offset, +unsigned size) +{ +const AwSidState *s =AW_SID (opaque); +uint64_t val =0 ;hw/misc/allwinner-sid.c
Quoted 10 lines
hw/misc/allwinner-sid.c new file +10
-0+ +switch (offset) { +case REG_PRCTL :/* Control */ + val = s->control; +break ; +case REG_RDKEY :/* Read Key */ + val = s->rdkey; +break ; +default : + qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset0x%04x\n",
Quoted 27 lines
hw/misc/allwinner-sid.c new file +27
-0+ __func__, (uint32_t)offset); +return 0 ; + } + +trace_allwinner_sid_read (offset, val, size); + +return val; +} + +static void allwinner_sid_write (void *opaque,hwaddr offset, +uint64_t val,unsigned size) +{ +AwSidState *s =AW_SID (opaque); + +trace_allwinner_sid_write (offset, val, size); + +switch (offset) { +case REG_PRCTL :/* Control */ + s->control = val; + +if ((s->control ®_PRCTL_OP_LOCK ) && + (s->control ®_PRCTL_WRITE )) { +uint32_t id = s->control >>16 ; + +if (id <sizeof (QemuUUID)) { + s->rdkey = (s->identifier.data[id]) | + (s->identifier.data[id + 1] << 8) |hw/misc/allwinner-sid.c
Quoted 10 lines
hw/misc/allwinner-sid.c new file +10
-0+ (s->identifier.data[id +2 ] <<16 ) | + (s->identifier.data[id +3 ] <<24 ); + } + } + s->control &= ~REG_PRCTL_WRITE ; +break ; +case REG_RDKEY :/* Read Key */ +break ; +default : + qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset0x%04x\n",
Quoted 38 lines
hw/misc/allwinner-sid.c new file +38
-0+ __func__, (uint32_t)offset); +break ; + } +} + +static const MemoryRegionOps allwinner_sid_ops = { + .read = allwinner_sid_read, + .write = allwinner_sid_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + }, + .impl.min_access_size =4 , +}; + +static void allwinner_sid_reset (DeviceState *dev) +{ +AwSidState *s =AW_SID (dev); + +/* Set default values for registers */ + s->control =0 ; + s->rdkey =0 ; +} + +static void allwinner_sid_init (Object *obj) +{ +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); +AwSidState *s =AW_SID (obj); + +/* Memory mapping */ +memory_region_init_io (&s->iomem,OBJECT (s), &allwinner_sid_ops, s, +TYPE_AW_SID ,1 * KiB); +sysbus_init_mmio (sbd, &s->iomem); +} + +static Property allwinner_sid_properties[] = { +DEFINE_PROP_UUID_NODEFAULT ("identifier" , AwSidState, identifier),hw/misc/allwinner-sid.c line 143
Quoted 10 lines
hw/misc/allwinner-sid.c new file +10
-0+DEFINE_PROP_END_OF_LIST () +}; + +static const VMStateDescription allwinner_sid_vmstate = { + .name ="allwinner-sid" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (control, AwSidState), +VMSTATE_UINT32 (rdkey, AwSidState),We need to migrate the UUID too:
Quoted 3 lines
VMSTATE_UINT8_ARRAY_V(identifier.data, AwSidState,
sizeof(QemuUUID), 1),
Previously in v1 Peter explained that when using a fixed value for the identifier,
migration should not be needed [1]. On the other hand, having it anyway in the VMState
shouldn't break anything and also avoids that we forget about it later, so I'll add it, thanks!
Regards,
Niek
[1] https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg01203.html
Quoted 63 lines
hw/misc/trace-events allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t
Quoted 45 lines
hw/misc/allwinner-sid.c new file +27
-0+ VMSTATE_END_OF_LIST() + } +}; + +static void allwinner_sid_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->reset = allwinner_sid_reset; + dc->vmsd = &allwinner_sid_vmstate; + dc->props = allwinner_sid_properties; +} + +static const TypeInfo allwinner_sid_info = { + .name =TYPE_AW_SID , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_init = allwinner_sid_init, + .instance_size =sizeof (AwSidState), + .class_init = allwinner_sid_class_init, +}; + +static void allwinner_sid_register (void ) +{ +type_register_static (&allwinner_sid_info); +} + +type_init (allwinner_sid_register)hw/misc/Makefile.objs +1
-0@@ -31,6 +31,7 @@ common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o obj-$(CONFIG_ALLWINNER_H3) += allwinner-cpucfg.o common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-sysctrl.o +common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-sid.o common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o common-obj-$(CONFIG_NSERIES) += cbus.o common-obj-$(CONFIG_ECCMEMCTL) += eccmemctl.ohw/misc/trace-events +0
-0@@ -5,6 +5,10 @@ allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t
reset_addr) "id %u,reset_adhw/misc/trace-events allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t · line 5
Quoted 1 line
hw/misc/trace-events +0
-0allwinner_cpucfg_read(uint64_t offset, uint64_t data, unsigned size)"offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
hw/misc/trace-events allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t · line 6
Quoted 1 line
hw/misc/trace-events +0
-0allwinner_cpucfg_write(uint64_t offset, uint64_t data, unsigned size)"offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
hw/misc/trace-events allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t · line 8
Quoted 3 lines
hw/misc/trace-events +2
-0+# allwinner-sid.c +allwinner_sid_read(uint64_t offset, uint64_t data, unsigned size)"offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
hw/misc/trace-events allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t · line 9
Quoted 1 line
hw/misc/trace-events +1
-0+allwinner_sid_write(uint64_t offset, uint64_t data, unsigned size)"offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
Quoted 5 lines
hw/misc/trace-events +1
-0+ # eccmemctl.c ecc_mem_writel_mer(uint32_t val) "Write memory enable 0x%08x" ecc_mem_writel_mdr(uint32_t val) "Write memory delay 0x%08x"
Signature · 1 line
Niek Linnenbank
PATCH v4 8/20 hw/arm/allwinner: add SD/MMC host controller
In reply to Niek LinnenbankThe Allwinner System on Chip families sun4i and above contain an integrated storage controller for Secure Digital (SD) and Multi Media Card (MMC) interfaces. This commit adds support for the Allwinner SD/MMC storage controller with the following emulated features:
* DMA transfers
* Direct FIFO I/O
* Short/Long format command responses
* Auto-Stop command (CMD12)
* Insert & remove card detection
The following boards are extended with the SD host controller:
* Cubieboard (hw/arm/cubieboard.c)
* Orange Pi PC (hw/arm/orangepi.c)
--- include/hw/arm/allwinner-a10.h | 2 + include/hw/arm/allwinner-h3.h | 3 + include/hw/sd/allwinner-sdhost.h | 135 +++++ hw/arm/allwinner-a10.c | 11 + hw/arm/allwinner-h3.c | 15 +- hw/arm/cubieboard.c | 15 + hw/arm/orangepi.c | 16 + hw/sd/allwinner-sdhost.c | 848 +++++++++++++++++++++++++++++++ hw/sd/Makefile.objs | 1 + hw/sd/trace-events | 7 + 10 files changed, 1052 insertions(+), 1 deletion(-) create mode 100644 include/hw/sd/allwinner-sdhost.h create mode 100644 hw/sd/allwinner-sdhost.c
include/hw/arm/allwinner-a10.h +2 -0
@@ -7,6 +7,7 @@#include "hw/timer/allwinner-a10-pit.h" #include "hw/intc/allwinner-a10-pic.h" #include "hw/net/allwinner_emac.h" +#include "hw/sd/allwinner-sdhost.h" #include "hw/ide/ahci.h" #include "target/arm/cpu.h"
@@ -27,6 +28,7 @@ typedef struct AwA10State {AwA10PICState intc;AwEmacState emac;AllwinnerAHCIState sata; +AwSdHostState mmc0;MemoryRegion sram_a; } AwA10State;
include/hw/arm/allwinner-h3.h +3 -0
@@ -43,6 +43,7 @@#include "hw/misc/allwinner-cpucfg.h" #include "hw/misc/allwinner-h3-sysctrl.h" #include "hw/misc/allwinner-sid.h" +#include "hw/sd/allwinner-sdhost.h" #include "target/arm/cpu.h" /**
@@ -60,6 +61,7 @@ enum {AW_H3_SRAM_A2 ,AW_H3_SRAM_C ,AW_H3_SYSCTRL , +AW_H3_MMC0 ,AW_H3_SID ,AW_H3_EHCI0 , AW_H3_OHCI0,
@@ -117,6 +119,7 @@ typedef struct AwH3State {AwCpuCfgState cpucfg;AwH3SysCtrlState sysctrl;AwSidState sid; +AwSdHostState mmc0;GICState gic;MemoryRegion sram_a1;MemoryRegion sram_a2;
include/hw/sd/allwinner-sdhost.h new file +135 -0
135 lines not on this page · raw message
hw/arm/allwinner-a10.c +11 -0
@@ -25,6 +25,7 @@#include "hw/misc/unimp.h" #include "sysemu/sysemu.h" +#define AW_A10_MMC0_BASE 0x01c0f000#define AW_A10_PIC_REG_BASE 0x01c20400#define AW_A10_PIT_REG_BASE 0x01c20c00#define AW_A10_UART0_REG_BASE 0x01c28000
@@ -49,6 +50,9 @@ static void aw_a10_init(Object *obj)sysbus_init_child_obj (obj,"sata" , &s->sata,sizeof (s->sata),TYPE_ALLWINNER_AHCI ); + +sysbus_init_child_obj (obj,"mmc0" , &s->mmc0,sizeof (s->mmc0), +TYPE_AW_SDHOST_SUN4I ); }static void aw_a10_realize (DeviceState *dev,Error **errp)
@@ -121,6 +125,13 @@ static void aw_a10_realize(DeviceState *dev, Error **errp)serial_mm_init (get_system_memory (),AW_A10_UART0_REG_BASE ,2 ,qdev_get_gpio_in (dev,1 ),115200 ,serial_hd (0 ),DEVICE_NATIVE_ENDIAN ); + +/* SD/MMC */ +qdev_init_nofail (DEVICE (&s->mmc0)); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->mmc0),0 ,AW_A10_MMC0_BASE ); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->mmc0),0 ,qdev_get_gpio_in (dev,32 )); +object_property_add_alias (OBJECT (s),"sd-bus" ,OBJECT (&s->mmc0), +"sd-bus" , &error_abort); }static void aw_a10_class_init (ObjectClass *oc,void *data)
hw/arm/allwinner-h3.c +14 -1
@@ -38,6 +38,7 @@ const hwaddr allwinner_h3_memmap[] = { [AW_H3_SRAM_A2] = 0x00044000, [AW_H3_SRAM_C] = 0x00010000, [AW_H3_SYSCTRL] = 0x01c00000, + [AW_H3_MMC0] = 0x01c0f000, [AW_H3_SID] = 0x01c14000, [AW_H3_EHCI0] = 0x01c1a000, [AW_H3_OHCI0] = 0x01c1a400,
@@ -76,7 +77,6 @@ struct AwH3Unimplemented { { "lcd0", 0x01c0c000, 4 * KiB }, { "lcd1", 0x01c0d000, 4 * KiB }, { "ve", 0x01c0e000, 4 * KiB }, - { "mmc0", 0x01c0f000, 4 * KiB }, { "mmc1", 0x01c10000, 4 * KiB }, { "mmc2", 0x01c11000, 4 * KiB }, { "crypto", 0x01c15000, 4 * KiB },
@@ -153,6 +153,7 @@ enum {AW_H3_GIC_SPI_UART3 =3 ,AW_H3_GIC_SPI_TIMER0 =18 ,AW_H3_GIC_SPI_TIMER1 =19 , +AW_H3_GIC_SPI_MMC0 =60 ,AW_H3_GIC_SPI_EHCI0 =72 ,AW_H3_GIC_SPI_OHCI0 =73 , AW_H3_GIC_SPI_EHCI1 = 74,
@@ -203,6 +204,9 @@ static void allwinner_h3_init(Object *obj) TYPE_AW_SID);object_property_add_alias (obj,"identifier" ,OBJECT (&s->sid),"identifier" , &error_abort); + +sysbus_init_child_obj (obj,"mmc0" , &s->mmc0,sizeof (s->mmc0), +TYPE_AW_SDHOST_SUN5I ); }static void allwinner_h3_realize (DeviceState *dev,Error **errp)
@@ -324,6 +328,15 @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)qdev_init_nofail (DEVICE (&s->sid));sysbus_mmio_map (SYS_BUS_DEVICE (&s->sid),0 , s->memmap[AW_H3_SID ]); +/* SD/MMC */ +qdev_init_nofail (DEVICE (&s->mmc0)); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->mmc0),0 , s->memmap[AW_H3_MMC0 ]); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->mmc0),0 , +qdev_get_gpio_in (DEVICE (&s->gic),AW_H3_GIC_SPI_MMC0 )); + +object_property_add_alias (OBJECT (s),"sd-bus" ,OBJECT (&s->mmc0), +"sd-bus" , &error_abort); +/* Universal Serial Bus */ sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0], qdev_get_gpio_in(DEVICE(&s->gic),
hw/arm/cubieboard.c +15 -0
@@ -21,6 +21,7 @@#include "cpu.h" #include "hw/sysbus.h" #include "hw/boards.h" +#include "hw/qdev-properties.h" #include "hw/arm/allwinner-a10.h" static struct arm_boot_info cubieboard_binfo = {
@@ -37,6 +38,10 @@ static void cubieboard_init(MachineState *machine) {CubieBoardState *s =g_new (CubieBoardState,1 );Error *err =NULL ; +DriveInfo *di; +BlockBackend *blk; +BusState *bus; +DeviceState *carddev; s->a10 =AW_A10 (object_new (TYPE_AW_A10 ));
@@ -65,6 +70,16 @@ static void cubieboard_init(MachineState *machine)exit (1 ); } +/* Retrieve SD bus */ + di =drive_get_next (IF_SD ); + blk = di ?blk_by_legacy_dinfo (di) :NULL ; + bus =qdev_get_child_bus (DEVICE (s->a10),"sd-bus" ); + +/* Plug in SD card */ + carddev =qdev_create (bus,TYPE_SD_CARD ); +qdev_prop_set_drive (carddev,"drive" , blk, &error_fatal); +object_property_set_bool (OBJECT (carddev), true,"realized" , &error_fatal); +memory_region_allocate_system_memory (&s->sdram,NULL ,"cubieboard.ram" , machine->ram_size); memory_region_add_subregion(get_system_memory(), AW_A10_SDRAM_BASE,
hw/arm/orangepi.c +16 -0
@@ -40,6 +40,10 @@ typedef struct OrangePiState {static void orangepi_init (MachineState *machine) {OrangePiState *s =g_new (OrangePiState,1 ); +DriveInfo *di; +BlockBackend *blk; +BusState *bus; +DeviceState *carddev;/* BIOS is not supported by this board */ if (bios_name) {
@@ -68,6 +72,16 @@ static void orangepi_init(MachineState *machine)/* Mark H3 object realized */ object_property_set_bool (OBJECT (s->h3), true,"realized" , &error_abort); +/* Retrieve SD bus */ + di =drive_get_next (IF_SD ); + blk = di ?blk_by_legacy_dinfo (di) :NULL ; + bus =qdev_get_child_bus (DEVICE (s->h3),"sd-bus" ); + +/* Plug in SD card */ + carddev =qdev_create (bus,TYPE_SD_CARD ); +qdev_prop_set_drive (carddev,"drive" , blk, &error_fatal); +object_property_set_bool (OBJECT (carddev), true,"realized" , &error_fatal); +/* SDRAM */ if (machine->ram_size !=1 * GiB) {error_report ("This machine can only be used with 1GiB of RAM" );
@@ -87,6 +101,8 @@ static void orangepi_machine_init(MachineClass *mc) { mc->desc ="Orange Pi PC" ; mc->init = orangepi_init; + mc->block_default_type =IF_SD ; + mc->units_per_default_bus =1 ; mc->min_cpus =AW_H3_NUM_CPUS ; mc->max_cpus =AW_H3_NUM_CPUS ; mc->default_cpus =AW_H3_NUM_CPUS ;
hw/sd/allwinner-sdhost.c new file +848 -0
848 lines not on this page · raw message
hw/sd/Makefile.objs +1 -0
@@ -4,6 +4,7 @@ common-obj-$(CONFIG_SD) += sd.o core.o sdmmc-internal.o common-obj-$(CONFIG_SDHCI) += sdhci.o common-obj-$(CONFIG_SDHCI_PCI) += sdhci-pci.o +obj-$(CONFIG_ALLWINNER_H3) += allwinner-sdhost.o obj-$(CONFIG_MILKYMIST) += milkymist-memcard.o obj-$(CONFIG_OMAP) += omap_mmc.o obj-$(CONFIG_PXA2XX) += pxa2xx_mmci.o
hw/sd/trace-events +7 -0
@@ -1,5 +1,12 @@ # See docs/devel/tracing.txt for syntax documentation. +# allwinner-sdhost.c +allwinner_sdhost_set_inserted(bool inserted) "inserted %u" +allwinner_sdhost_process_desc(uint64_t desc_addr, uint32_t desc_size, bool is_write, uint32_t max_bytes) "desc_addr 0x%" PRIx64 " desc_size %" PRIu32 " is_write %u max_bytes %" PRIu32 +allwinner_sdhost_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 +allwinner_sdhost_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 +allwinner_sdhost_update_irq(uint32_t irq) "IRQ bits 0x%" PRIx32 + # bcm2835_sdhost.c bcm2835_sdhost_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" bcm2835_sdhost_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
Signature · 1 line
2.17.1
Re: [PATCH v4 08/20] hw/arm/allwinner: add SD/MMC host controller
Quoted 31 lines · Niek Linnenbank
The Allwinner System on Chip families sun4i and above contain an integrated storage controller for Secure Digital (SD) and Multi Media Card (MMC) interfaces. This commit adds support for the Allwinner SD/MMC storage controller with the following emulated features:
* DMA transfers
* Direct FIFO I/O
* Short/Long format command responses
* Auto-Stop command (CMD12)
* Insert & remove card detectionThe following boards are extended with the SD host controller:
* Cubieboard (
hw/arm/cubieboard.c)
* Orange Pi PC (hw/arm/orangepi.c)Signed-off-by Niek Linnenbank <[email protected]>--- include/hw/arm/allwinner-a10.h | 2 + include/hw/arm/allwinner-h3.h | 3 + include/hw/sd/allwinner-sdhost.h | 135 +++++ hw/arm/allwinner-a10.c | 11 + hw/arm/allwinner-h3.c | 15 +- hw/arm/cubieboard.c | 15 + hw/arm/orangepi.c | 16 + hw/sd/allwinner-sdhost.c | 848 +++++++++++++++++++++++++++++++ hw/sd/Makefile.objs | 1 + hw/sd/trace-events | 7 + 10 files changed, 1052 insertions(+), 1 deletion(-)
Quoted 2 lines
create mode 100644
include/hw/sd/allwinner-sdhost.hcreate mode 100644hw/sd/allwinner-sdhost.c
Failure at build if configured with --without-default-devices:
CC arm-softmmu/hw/sd/allwinner-sdhost.o CC arm-softmmu/hw/arm/orangepi.o CC arm-softmmu/hw/arm/allwinner-h3.o LINK arm-softmmu/qemu-system-arm
/usr/bin/ld: hw/sd/allwinner-sdhost.o: in function `allwinner_sdhost_send_command':hw/sd/allwinner-sdhost.c:239: undefined reference to sdbus_do_command' /usr/bin/ld: hw/sd/allwinner-sdhost.o: in function allwinner_sdhost_read':hw/sd/allwinner-sdhost.c:517: undefined reference to sdbus_data_ready' /usr/bin/ld: hw/sd/allwinner-sdhost.c:518: undefined reference to sdbus_read_data' /usr/bin/ld: hw/sd/allwinner-sdhost.c:519: undefined reference to sdbus_read_data' /usr/bin/ld: hw/sd/allwinner-sdhost.c:520: undefined reference to sdbus_read_data' /usr/bin/ld: hw/sd/allwinner-sdhost.c:521: undefined reference to sdbus_read_data' /usr/bin/ld: hw/sd/allwinner-sdhost.o: in function allwinner_sdhost_process_desc':hw/sd/allwinner-sdhost.c:340: undefined reference to sdbus_read_data' /usr/bin/ld: hw/sd/allwinner-sdhost.c:334: undefined reference to sdbus_write_data' /usr/bin/ld: hw/sd/allwinner-sdhost.o: in function `allwinner_sdhost_write':hw/sd/allwinner-sdhost.c:651: undefined reference to sdbus_write_data' /usr/bin/ld: hw/sd/allwinner-sdhost.c:652: undefined reference to sdbus_write_data' /usr/bin/ld: hw/sd/allwinner-sdhost.c:653: undefined reference to sdbus_write_data' /usr/bin/ld: hw/sd/allwinner-sdhost.c:654: undefined reference to sdbus_write_data' /usr/bin/ld: hw/sd/allwinner-sdhost.o: in function `allwinner_sdhost_dma':hw/sd/allwinner-sdhost.c:372: undefined reference to `sdbus_data_ready'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:206: qemu-system-arm] Error 1
Fixed by:
-- >8 --
hw/arm/Kconfig +1 -0
@@ -302,6 +302,9 @@ config ALLWINNER_H3 select ARM_TIMER select ARM_GIC select UNIMP select USB_OHCI select USB_EHCI_SYSBUS + select SD
config RASPI
bool
---
Re: [PATCH v4 08/20] hw/arm/allwinner: add SD/MMC host controller
Hi Philippe,
Quoted 64 lines · Philippe Mathieu-Daudé
Quoted 31 lines · Niek Linnenbank
The Allwinner System on Chip families sun4i and above contain an integrated storage controller for Secure Digital (SD) and Multi Media Card (MMC) interfaces. This commit adds support for the Allwinner SD/MMC storage controller with the following emulated features:
* DMA transfers
* Direct FIFO I/O
* Short/Long format command responses
* Auto-Stop command (CMD12)
* Insert & remove card detectionThe following boards are extended with the SD host controller:
* Cubieboard (
hw/arm/cubieboard.c)
* Orange Pi PC (hw/arm/orangepi.c)Signed-off-by Niek Linnenbank <[email protected]>--- include/hw/arm/allwinner-a10.h | 2 + include/hw/arm/allwinner-h3.h | 3 + include/hw/sd/allwinner-sdhost.h | 135 +++++ hw/arm/allwinner-a10.c | 11 + hw/arm/allwinner-h3.c | 15 +- hw/arm/cubieboard.c | 15 + hw/arm/orangepi.c | 16 + hw/sd/allwinner-sdhost.c | 848 +++++++++++++++++++++++++++++++ hw/sd/Makefile.objs | 1 + hw/sd/trace-events | 7 + 10 files changed, 1052 insertions(+), 1 deletion(-)Quoted 2 lines
create mode 100644
include/hw/sd/allwinner-sdhost.hcreate mode 100644hw/sd/allwinner-sdhost.cFailure at build if configured with --without-default-devices:
CC arm-softmmu/hw/sd/allwinner-sdhost.o CC arm-softmmu/hw/arm/orangepi.o CC arm-softmmu/hw/arm/allwinner-h3.o LINK arm-softmmu/qemu-system-arm
/usr/bin/ld:hw/sd/allwinner-sdhost.o: in function `allwinner_sdhost_send_command':hw/sd/allwinner-sdhost.c:239: undefined reference tosdbus_do_command' /usr/bin/ld: hw/sd/allwinner-sdhost.o: in functionallwinner_sdhost_read':hw/sd/allwinner-sdhost.c:517: undefined reference tosdbus_data_ready' /usr/bin/ld: hw/sd/allwinner-sdhost.c:518: undefined reference tosdbus_read_data'/usr/bin/ld:hw/sd/allwinner-sdhost.c:519: undefined reference to `sdbus_read_data'/usr/bin/ld:hw/sd/allwinner-sdhost.c:520: undefined reference to `sdbus_read_data'/usr/bin/ld:hw/sd/allwinner-sdhost.c:521: undefined reference to `sdbus_read_data'/usr/bin/ld:hw/sd/allwinner-sdhost.o: in function `allwinner_sdhost_process_desc':hw/sd/allwinner-sdhost.c:340: undefined reference tosdbus_read_data' /usr/bin/ld: hw/sd/allwinner-sdhost.c:334: undefined reference tosdbus_write_data'/usr/bin/ld:hw/sd/allwinner-sdhost.o: in function `allwinner_sdhost_write':hw/sd/allwinner-sdhost.c:651: undefined reference tosdbus_write_data' /usr/bin/ld: hw/sd/allwinner-sdhost.c:652: undefined reference tosdbus_write_data'
Quoted 10 lines
/usr/bin/ld:hw/sd/allwinner-sdhost.c:653: undefined reference to `sdbus_write_data'/usr/bin/ld:hw/sd/allwinner-sdhost.c:654: undefined reference to `sdbus_write_data'/usr/bin/ld:hw/sd/allwinner-sdhost.o: in function `allwinner_sdhost_dma':hw/sd/allwinner-sdhost.c:372: undefined reference to `sdbus_data_ready'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:206: qemu-system-arm] Error 1
Thanks for reporting this Philippe. As you pointed out, I also made the same mistake in patch #4 for USB support [1].
Here I also tried to re-produce the error here with:
$ ./configure --target-list=arm-softmmu --without-default-devices; make -j5
But again no error. I also see that CONFIG_SD=y is set in arm-softmmu/config-devices.mak.
Maybe on my laptop --without-default-devices has no effect or is overriden somehow, I'll try to debug it further.
[1] https://lists.gnu.org/archive/html/qemu-devel/2020-02/msg00125.html
Quoted 15 lines
Fixed by:
-- >8 --
hw/arm/Kconfig +1
-0@@ -302,6 +302,9 @@ config ALLWINNER_H3 select ARM_TIMER select ARM_GIC select UNIMP select USB_OHCI select USB_EHCI_SYSBUS + select SD
Quoted 1 line
Thanks, I'll add this fix.
Regards,
Niek
Quoted 5 lines
config RASPI
bool
---
Signature · 1 line
Niek Linnenbank
Re: [PATCH v4 08/20] hw/arm/allwinner: add SD/MMC host controller
Hi Philippe,
FYI, and in case someone also wants to do a similar configuration test on some other machine.
I managed to re-produce the same error by temporarily modifying default-configs/arm-softmmu.mak, such that it only enables the orangepi machine.
That way, if any configuration item is missing from the machine, the error will be visible.
Regards,
Niek
Quoted 125 lines · Niek Linnenbank
Hi Philippe,
Quoted 65 lines · Philippe Mathieu-Daudé
Quoted 31 lines · Niek Linnenbank
The Allwinner System on Chip families sun4i and above contain an integrated storage controller for Secure Digital (SD) and Multi Media Card (MMC) interfaces. This commit adds support for the Allwinner SD/MMC storage controller with the following emulated features:
* DMA transfers
* Direct FIFO I/O
* Short/Long format command responses
* Auto-Stop command (CMD12)
* Insert & remove card detectionThe following boards are extended with the SD host controller:
* Cubieboard (
hw/arm/cubieboard.c)
* Orange Pi PC (hw/arm/orangepi.c)Signed-off-by Niek Linnenbank <[email protected]>--- include/hw/arm/allwinner-a10.h | 2 + include/hw/arm/allwinner-h3.h | 3 + include/hw/sd/allwinner-sdhost.h | 135 +++++ hw/arm/allwinner-a10.c | 11 + hw/arm/allwinner-h3.c | 15 +- hw/arm/cubieboard.c | 15 + hw/arm/orangepi.c | 16 + hw/sd/allwinner-sdhost.c | 848 +++++++++++++++++++++++++++++++ hw/sd/Makefile.objs | 1 + hw/sd/trace-events | 7 + 10 files changed, 1052 insertions(+), 1 deletion(-)Quoted 2 lines
create mode 100644
include/hw/sd/allwinner-sdhost.hcreate mode 100644hw/sd/allwinner-sdhost.cFailure at build if configured with --without-default-devices:
CC arm-softmmu/hw/sd/allwinner-sdhost.o CC arm-softmmu/hw/arm/orangepi.o CC arm-softmmu/hw/arm/allwinner-h3.o LINK arm-softmmu/qemu-system-arm
/usr/bin/ld:hw/sd/allwinner-sdhost.o: in function `allwinner_sdhost_send_command':hw/sd/allwinner-sdhost.c:239: undefined reference tosdbus_do_command' /usr/bin/ld: hw/sd/allwinner-sdhost.o: in functionallwinner_sdhost_read':hw/sd/allwinner-sdhost.c:517: undefined reference tosdbus_data_ready' /usr/bin/ld: hw/sd/allwinner-sdhost.c:518: undefined reference tosdbus_read_data'/usr/bin/ld:hw/sd/allwinner-sdhost.c:519: undefined reference to `sdbus_read_data'/usr/bin/ld:hw/sd/allwinner-sdhost.c:520: undefined reference to `sdbus_read_data'/usr/bin/ld:hw/sd/allwinner-sdhost.c:521: undefined reference to `sdbus_read_data'/usr/bin/ld:hw/sd/allwinner-sdhost.o: in function `allwinner_sdhost_process_desc':hw/sd/allwinner-sdhost.c:340: undefined reference tosdbus_read_data' /usr/bin/ld: hw/sd/allwinner-sdhost.c:334: undefined reference tosdbus_write_data'/usr/bin/ld:hw/sd/allwinner-sdhost.o: in function `allwinner_sdhost_write':hw/sd/allwinner-sdhost.c:651: undefined reference tosdbus_write_data' /usr/bin/ld: hw/sd/allwinner-sdhost.c:652: undefined reference tosdbus_write_data'Quoted 10 lines
/usr/bin/ld:hw/sd/allwinner-sdhost.c:653: undefined reference to `sdbus_write_data'/usr/bin/ld:hw/sd/allwinner-sdhost.c:654: undefined reference to `sdbus_write_data'/usr/bin/ld:hw/sd/allwinner-sdhost.o: in function `allwinner_sdhost_dma':hw/sd/allwinner-sdhost.c:372: undefined reference to `sdbus_data_ready'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:206: qemu-system-arm] Error 1Thanks for reporting this Philippe. As you pointed out, I also made the same mistake in patch #4 for USB support [1].
Here I also tried to re-produce the error here with:$ ./configure --target-list=arm-softmmu --without-default-devices; make -j5But again no error. I also see that
CONFIG_SD=yis set in arm-softmmu/config-devices.mak.
Maybe on my laptop --without-default-devices has no effect or is overriden somehow, I'll try to debug it further.[1] https://lists.gnu.org/archive/html/qemu-devel/2020-02/msg00125.html
Quoted 15 lines
Fixed by:
-- >8 --
hw/arm/Kconfig +1
-0@@ -302,6 +302,9 @@ config ALLWINNER_H3 select ARM_TIMER select ARM_GIC select UNIMP select USB_OHCI select USB_EHCI_SYSBUS + select SDQuoted 1 line
Thanks, I'll add this fix.
Regards,
NiekQuoted 5 lines
config RASPI
bool
-----
Niek Linnenbank
Signature · 1 line
Niek Linnenbank
PATCH v4 9/20 hw/arm/allwinner-h3: add EMAC ethernet device
In reply to Niek LinnenbankThe Allwinner Sun8i System on Chip family includes an Ethernet MAC (EMAC) which provides 10M/100M/1000M Ethernet connectivity. This commit adds support for the Allwinner EMAC from the Sun8i family (H2+, H3, A33, etc), including emulation for the following functionality:
* DMA transfers
* MII interface
* Transmit CRC calculation
--- include/hw/arm/allwinner-h3.h | 3 + include/hw/net/allwinner-sun8i-emac.h | 99 +++ hw/arm/allwinner-h3.c | 16 +- hw/arm/orangepi.c | 3 + hw/net/allwinner-sun8i-emac.c | 871 ++++++++++++++++++++++++++ hw/arm/Kconfig | 1 + hw/net/Kconfig | 3 + hw/net/Makefile.objs | 1 + hw/net/trace-events | 10 + 9 files changed, 1006 insertions(+), 1 deletion(-) create mode 100644 include/hw/net/allwinner-sun8i-emac.h create mode 100644 hw/net/allwinner-sun8i-emac.c
include/hw/arm/allwinner-h3.h +3 -0
@@ -44,6 +44,7 @@#include "hw/misc/allwinner-h3-sysctrl.h" #include "hw/misc/allwinner-sid.h" #include "hw/sd/allwinner-sdhost.h" +#include "hw/net/allwinner-sun8i-emac.h" #include "target/arm/cpu.h" /**
@@ -77,6 +78,7 @@ enum {AW_H3_UART1 ,AW_H3_UART2 ,AW_H3_UART3 , +AW_H3_EMAC ,AW_H3_GIC_DIST ,AW_H3_GIC_CPU , AW_H3_GIC_HYP,
@@ -120,6 +122,7 @@ typedef struct AwH3State {AwH3SysCtrlState sysctrl;AwSidState sid;AwSdHostState mmc0; +AwSun8iEmacState emac;GICState gic;MemoryRegion sram_a1;MemoryRegion sram_a2;
include/hw/net/allwinner-sun8i-emac.h new file +99 -0
99 lines not on this page · raw message
hw/arm/allwinner-h3.c +15 -1
@@ -54,6 +54,7 @@ const hwaddr allwinner_h3_memmap[] = { [AW_H3_UART1] = 0x01c28400, [AW_H3_UART2] = 0x01c28800, [AW_H3_UART3] = 0x01c28c00, + [AW_H3_EMAC] = 0x01c30000, [AW_H3_GIC_DIST] = 0x01c81000, [AW_H3_GIC_CPU] = 0x01c82000, [AW_H3_GIC_HYP] = 0x01c84000,
@@ -106,7 +107,6 @@ struct AwH3Unimplemented { { "twi1", 0x01c2b000, 1 * KiB }, { "twi2", 0x01c2b400, 1 * KiB }, { "scr", 0x01c2c400, 1 * KiB }, - { "emac", 0x01c30000, 64 * KiB }, { "gpu", 0x01c40000, 64 * KiB }, { "hstmr", 0x01c60000, 4 * KiB }, { "dramcom", 0x01c62000, 4 * KiB },
@@ -162,6 +162,7 @@ enum {AW_H3_GIC_SPI_OHCI2 =77 ,AW_H3_GIC_SPI_EHCI3 =78 ,AW_H3_GIC_SPI_OHCI3 =79 , + AW_H3_GIC_SPI_EMAC = 82 };/* Allwinner H3 general constants */
@@ -207,6 +208,9 @@ static void allwinner_h3_init(Object *obj)sysbus_init_child_obj (obj,"mmc0" , &s->mmc0,sizeof (s->mmc0),TYPE_AW_SDHOST_SUN5I ); + +sysbus_init_child_obj (obj,"emac" , &s->emac,sizeof (s->emac), +TYPE_AW_SUN8I_EMAC ); }static void allwinner_h3_realize (DeviceState *dev,Error **errp)
@@ -337,6 +341,16 @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)object_property_add_alias (OBJECT (s),"sd-bus" ,OBJECT (&s->mmc0),"sd-bus" , &error_abort); +/* EMAC */ +if (nd_table[0 ].used) { +qemu_check_nic_model (&nd_table[0 ],TYPE_AW_SUN8I_EMAC ); +qdev_set_nic_properties (DEVICE (&s->emac), &nd_table[0 ]); + } +qdev_init_nofail (DEVICE (&s->emac)); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->emac),0 , s->memmap[AW_H3_EMAC ]); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->emac),0 , +qdev_get_gpio_in (DEVICE (&s->gic),AW_H3_GIC_SPI_EMAC )); +/* Universal Serial Bus */ sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0], qdev_get_gpio_in(DEVICE(&s->gic),
hw/arm/orangepi.c +3 -0
@@ -69,6 +69,9 @@ static void orangepi_init(MachineState *machine)qdev_prop_set_string (DEVICE (s->h3),"identifier" ,"8100c002-0001-0002-0003-000044556677" ); +/* Setup EMAC properties */ +object_property_set_int (OBJECT (&s->h3->emac),1 ,"phy-addr" , &error_abort); +/* Mark H3 object realized */ object_property_set_bool (OBJECT (s->h3), true,"realized" , &error_abort);
hw/net/allwinner-sun8i-emac.c new file +871 -0
871 lines not on this page · raw message
hw/arm/Kconfig +1 -0
@@ -298,6 +298,7 @@ config ALLWINNER_A10 config ALLWINNER_H3 bool select ALLWINNER_A10_PIT + select ALLWINNER_SUN8I_EMAC select SERIAL select ARM_TIMER select ARM_GIC
hw/net/Kconfig +3 -0
@@ -76,6 +76,9 @@ config MIPSNET config ALLWINNER_EMAC bool +config ALLWINNER_SUN8I_EMAC + bool + config IMX_FEC bool
hw/net/Makefile.objs +1 -0
@@ -23,6 +23,7 @@ common-obj-$(CONFIG_XGMAC) += xgmac.o common-obj-$(CONFIG_MIPSNET) += mipsnet.o common-obj-$(CONFIG_XILINX_AXI) += xilinx_axienet.o common-obj-$(CONFIG_ALLWINNER_EMAC) += allwinner_emac.o +common-obj-$(CONFIG_ALLWINNER_SUN8I_EMAC) += allwinner-sun8i-emac.o common-obj-$(CONFIG_IMX_FEC) += imx_fec.o common-obj-$(CONFIG_CADENCE) += cadence_gem.o
hw/net/trace-events +10 -0
@@ -1,5 +1,15 @@ # See docs/devel/tracing.txt for syntax documentation. +# allwinner-sun8i-emac.c +allwinner_sun8i_emac_mii_write_reg(uint32_t reg, uint32_t value) "MII write: reg=0x%" PRIx32 " value=0x%" PRIx32 +allwinner_sun8i_emac_mii_read_reg(uint32_t reg, uint32_t value) "MII read: reg=0x%" PRIx32 " value=0x%" PRIx32 +allwinner_sun8i_emac_receive(uint32_t desc, uint32_t paddr, uint32_t bytes) "RX packet: desc=0x%" PRIx32 " paddr=0x%" PRIx32 " bytes=%" PRIu32 +allwinner_sun8i_emac_transmit(uint32_t desc, uint32_t paddr, uint32_t bytes) "TX packet: desc=0x%" PRIx32 " paddr=0x%" PRIx32 " bytes=%" PRIu32 +allwinner_sun8i_emac_reset(void) "HW reset" +allwinner_sun8i_emac_set_link(bool active) "Set link: active=%u" +allwinner_sun8i_emac_read(uint64_t offset, uint64_t val) "MMIO read: offset=0x%" PRIx64 " value=0x%" PRIx64 +allwinner_sun8i_emac_write(uint64_t offset, uint64_t val) "MMIO write: offset=0x%" PRIx64 " value=0x%" PRIx64 + # etraxfs_eth.c mdio_phy_read(int regnum, uint16_t value) "read phy_reg:%d value:0x%04x" mdio_phy_write(int regnum, uint16_t value) "write phy_reg:%d value:0x%04x"
Signature · 1 line
2.17.1
PATCH v4 10/20 hw/arm/allwinner-h3: add Boot ROM support
In reply to Niek LinnenbankA real Allwinner H3 SoC contains a Boot ROM which is the first code that runs right after the SoC is powered on.
The Boot ROM is responsible for loading user code (e.g. a bootloader) from any of the supported external devices and writing the downloaded code to internal SRAM. After loading the SoC begins executing the code written to SRAM.
This commits adds emulation of the Boot ROM firmware setup functionality by loading user code from SD card in the A1 SRAM. While the A1 SRAM is 64KiB, we limit the size to 32KiB because the real H3 Boot ROM also rejects sizes larger than 32KiB. For reference, this behaviour is documented by the Linux Sunxi project wiki at:
https://linux-sunxi.org/BROM#U-Boot_SPL_limitations
--- include/hw/arm/allwinner-h3.h | 23 +++++++++++++++++++++++ hw/arm/allwinner-h3.c | 28 ++++++++++++++++++++++++++++ hw/arm/orangepi.c | 5 +++++ 3 files changed, 56 insertions(+)
include/hw/arm/allwinner-h3.h +23 -0
@@ -46,6 +46,7 @@#include "hw/sd/allwinner-sdhost.h" #include "hw/net/allwinner-sun8i-emac.h" #include "target/arm/cpu.h" +#include "sysemu/block-backend.h" /** * Allwinner H3 device list
@@ -129,4 +130,26 @@ typedef struct AwH3State { MemoryRegion sram_c; } AwH3State; +/** +* Emulate Boot ROM firmware setup functionality. +* +* A real Allwinner H3 SoC contains a Boot ROM +* which is the first code that runs right after +* the SoC is powered on. The Boot ROM is responsible +* for loading user code (e.g. a bootloader) from any +* of the supported external devices and writing the +* downloaded code to internal SRAM. After loading the SoC +* begins executing the code written to SRAM. +* +* This function emulates the Boot ROM by copying 32 KiB +* of data from the given block device and writes it to +* the start of the first internal SRAM memory. +* +* @s: Allwinner H3 state object pointer +* @blk: Block backend device object pointer +* @errp: Error object pointer for raising errors +*/ +void allwinner_h3_bootrom_setup (AwH3State *s,BlockBackend *blk, +Error **errp); +#endif /* HW_ARM_ALLWINNER_H3_H */
hw/arm/allwinner-h3.c +28 -0
@@ -29,6 +29,7 @@#include "hw/char/serial.h" #include "hw/misc/unimp.h" #include "hw/usb/hcd-ehci.h" +#include "hw/loader.h" #include "sysemu/sysemu.h" #include "hw/arm/allwinner-h3.h"
@@ -170,6 +171,33 @@ enum {AW_H3_GIC_NUM_SPI =128 }; +void allwinner_h3_bootrom_setup (AwH3State *s,BlockBackend *blk,Error **errp) +{ +uint8_t *buffer; +int64_t rom_size =32 * KiB; + +int64_t blk_size =blk_getlength (blk); +if (blk_size <=0 ) { +error_setg (errp,"%s: failed to get BlockBackend size" , __func__); +return ; + } + +if (rom_size > blk_size) { + rom_size = blk_size; + } + + buffer =g_new0 (uint8_t, rom_size); +if (blk_pread (blk,8 * KiB, buffer, rom_size) <0 ) { +error_setg (errp,"%s: failed to read BlockBackend data" , __func__); +return ; + } + +rom_add_blob ("allwinner-h3.bootrom" , buffer, rom_size, + rom_size, s->memmap[AW_H3_SRAM_A1 ], +NULL ,NULL ,NULL ,NULL , false); +g_free (buffer); +} +static void allwinner_h3_init (Object *obj) {AwH3State *s =AW_H3 (obj);
hw/arm/orangepi.c +5 -0
@@ -95,6 +95,11 @@ static void orangepi_init(MachineState *machine)memory_region_add_subregion (get_system_memory (), s->h3->memmap[AW_H3_SDRAM ], &s->sdram); +/* Load target kernel or start using BootROM */ +if (!machine->kernel_filename &&blk_is_available (blk)) { +/* Use Boot ROM to copy data from SD card to SRAM */ +allwinner_h3_bootrom_setup (s->h3, blk, &error_fatal); + } orangepi_binfo.loader_start = s->h3->memmap[AW_H3_SDRAM ]; orangepi_binfo.ram_size = machine->ram_size;arm_load_kernel (ARM_CPU (first_cpu), machine, &orangepi_binfo);
Signature · 1 line
2.17.1
Re: [PATCH v4 10/20] hw/arm/allwinner-h3: add Boot ROM support
Quoted 80 lines · Niek Linnenbank
A real Allwinner H3 SoC contains a Boot ROM which is the first code that runs right after the SoC is powered on.
The Boot ROM is responsible for loading user code (e.g. a bootloader) from any of the supported external devices and writing the downloaded code to internal SRAM. After loading the SoC begins executing the code written to SRAM.This commits adds emulation of the Boot ROM firmware setup functionality by loading user code from SD card in the A1 SRAM. While the A1 SRAM is 64KiB, we limit the size to 32KiB because the real H3 Boot ROM also rejects sizes larger than 32KiB. For reference, this behaviour is documented by the Linux Sunxi project wiki at:
https://linux-sunxi.org/BROM#U-Boot_SPL_limitations
Signed-off-by Niek Linnenbank <[email protected]>--- include/hw/arm/allwinner-h3.h | 23 +++++++++++++++++++++++ hw/arm/allwinner-h3.c | 28 ++++++++++++++++++++++++++++ hw/arm/orangepi.c | 5 +++++ 3 files changed, 56 insertions(+)include/hw/arm/allwinner-h3.h +23
-0@@ -46,6 +46,7 @@#include "hw/sd/allwinner-sdhost.h" #include "hw/net/allwinner-sun8i-emac.h" #include "target/arm/cpu.h" +#include "sysemu/block-backend.h" /** * Allwinner H3 device list @@ -129,4 +130,26 @@ typedef struct AwH3State { MemoryRegion sram_c; } AwH3State; +/** +* Emulate Boot ROM firmware setup functionality. +* +* A real Allwinner H3 SoC contains a Boot ROM +* which is the first code that runs right after +* the SoC is powered on. The Boot ROM is responsible +* for loading user code (e.g. a bootloader) from any +* of the supported external devices and writing the +* downloaded code to internal SRAM. After loading the SoC +* begins executing the code written to SRAM. +* +* This function emulates the Boot ROM by copying 32 KiB +* of data from the given block device and writes it to +* the start of the first internal SRAM memory. +* +* @s: Allwinner H3 state object pointer +* @blk: Block backend device object pointer +* @errp: Error object pointer for raising errors +*/ +void allwinner_h3_bootrom_setup (AwH3State *s,BlockBackend *blk, +Error **errp); +#endif /* HW_ARM_ALLWINNER_H3_H */ hw/arm/allwinner-h3.c +4
-0@@ -29,6 +29,7 @@#include "hw/char/serial.h" #include "hw/misc/unimp.h" #include "hw/usb/hcd-ehci.h" +#include "hw/loader.h" #include "sysemu/sysemu.h" #include "hw/arm/allwinner-h3.h" @@ -170,6 +171,33 @@ enum { AW_H3_GIC_NUM_SPI = 128 }; +void allwinner_h3_bootrom_setup (AwH3State *s,BlockBackend *blk,Error **errp) +{ +uint8_t *buffer;
hw/arm/allwinner-h3.c enum { · line 186
Quoted 10 lines
hw/arm/allwinner-h3.c +10
-0+int64_t rom_size =32 * KiB; + +int64_t blk_size =blk_getlength (blk); +if (blk_size <=0 ) { +error_setg (errp,"%s: failed to get BlockBackend size" , __func__); +return ; + } + +if (rom_size > blk_size) { + rom_size = blk_size;
This doesn't seem correct, have you tried to use a 1MB file?
This can't be bigger than the SRAM size, 64KB.
Quoted 22 lines
hw/arm/allwinner-h3.c +14
-0+ } + + buffer =g_new0 (uint8_t, rom_size); +if (blk_pread (blk,8 * KiB, buffer, rom_size) <0 ) { +error_setg (errp,"%s: failed to read BlockBackend data" , __func__); +return ; + } + +rom_add_blob ("allwinner-h3.bootrom" , buffer, rom_size, + rom_size, s->memmap[AW_H3_SRAM_A1 ], +NULL ,NULL ,NULL ,NULL , false); +g_free (buffer); +} +static void allwinner_h3_init (Object *obj) {AwH3State *s =AW_H3 (obj);hw/arm/orangepi.c +0
-0
hw/arm/orangepi.c static void orangepi_init(MachineState *machine) · line 101
Quoted 7 lines
hw/arm/orangepi.c +4
-0@@ -95,6 +95,11 @@ static void orangepi_init(MachineState *machine)memory_region_add_subregion (get_system_memory (), s->h3->memmap[AW_H3_SDRAM ], &s->sdram); +/* Load target kernel or start using BootROM */ +if (!machine->kernel_filename &&blk_is_available (blk)) { +/* Use Boot ROM to copy data from SD card to SRAM */ +allwinner_h3_bootrom_setup (s->h3, blk, &error_fatal);
allwinner_h3_bootrom_setup() doesn't need the errp argument, you can use error_fatal directly there.
Quoted 5 lines
hw/arm/orangepi.c +1
-0+ } orangepi_binfo.loader_start = s->h3->memmap[AW_H3_SDRAM ]; orangepi_binfo.ram_size = machine->ram_size;arm_load_kernel (ARM_CPU (first_cpu), machine, &orangepi_binfo);
Re: [PATCH v4 10/20] hw/arm/allwinner-h3: add Boot ROM support
Quoted 96 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Niek Linnenbank
A real Allwinner H3 SoC contains a Boot ROM which is the first code that runs right after the SoC is powered on.
The Boot ROM is responsible for loading user code (e.g. a bootloader) from any of the supported external devices and writing the downloaded code to internal SRAM. After loading the SoC begins executing the code written to SRAM.This commits adds emulation of the Boot ROM firmware setup functionality by loading user code from SD card in the A1 SRAM. While the A1 SRAM is 64KiB, we limit the size to 32KiB because the real H3 Boot ROM also
rejects
Quoted 5 lines
sizes larger than 32KiB. For reference, this behaviour is documented by the Linux Sunxi project wiki at:
Review
Quoted 8 lines
Signed-off-by Niek Linnenbank <[email protected]>--- include/hw/arm/allwinner-h3.h | 23 +++++++++++++++++++++++ hw/arm/allwinner-h3.c | 28 ++++++++++++++++++++++++++++ hw/arm/orangepi.c | 5 +++++ 3 files changed, 56 insertions(+)(quoted diff) +0
-0
b/include/hw/arm/allwinner-h3.hQuoted 51 lines
index
f9b9a02373..f5e16266cd100644include/hw/arm/allwinner-h3.h +23
-0@@ -46,6 +46,7 @@#include "hw/sd/allwinner-sdhost.h" #include "hw/net/allwinner-sun8i-emac.h" #include "target/arm/cpu.h" +#include "sysemu/block-backend.h" /** * Allwinner H3 device list @@ -129,4 +130,26 @@ typedef struct AwH3State { MemoryRegion sram_c; } AwH3State; +/** +* Emulate Boot ROM firmware setup functionality. +* +* A real Allwinner H3 SoC contains a Boot ROM +* which is the first code that runs right after +* the SoC is powered on. The Boot ROM is responsible +* for loading user code (e.g. a bootloader) from any +* of the supported external devices and writing the +* downloaded code to internal SRAM. After loading the SoC +* begins executing the code written to SRAM. +* +* This function emulates the Boot ROM by copying 32 KiB +* of data from the given block device and writes it to +* the start of the first internal SRAM memory. +* +* @s: Allwinner H3 state object pointer +* @blk: Block backend device object pointer +* @errp: Error object pointer for raising errors +*/ +void allwinner_h3_bootrom_setup (AwH3State *s,BlockBackend *blk, +Error **errp); +#endif /* HW_ARM_ALLWINNER_H3_H */ hw/arm/allwinner-h3.c +1
-0@@ -29,6 +29,7 @@#include "hw/char/serial.h" #include "hw/misc/unimp.h" #include "hw/usb/hcd-ehci.h" +#include "hw/loader.h" #include "sysemu/sysemu.h" #include "hw/arm/allwinner-h3.h" hw/arm/allwinner-h3.c enum { · line 174
Quoted 4 lines
hw/arm/allwinner-h3.c +1
-0@@ -170,6 +171,33 @@ enum {AW_H3_GIC_NUM_SPI =128 }; +void allwinner_h3_bootrom_setup(AwH3State *s, BlockBackend *blk, Error**errp)
hw/arm/allwinner-h3.c enum {
Quoted 7 lines
hw/arm/allwinner-h3.c +7
-0+{ +uint8_t *buffer; +int64_t rom_size =32 * KiB; + +int64_t blk_size =blk_getlength (blk); +if (blk_size <=0 ) { + error_setg(errp, "%s: failed to get BlockBackend size",
__func__);hw/arm/allwinner-h3.c enum { · line 186
Quoted 5 lines
hw/arm/allwinner-h3.c +5
-0+return ; + } + +if (rom_size > blk_size) { + rom_size = blk_size;
Quoted 4 lines
This doesn't seem correct, have you tried to use a 1MB file?
This can't be bigger than the SRAM size, 64KB.
This check was supposed to take into account the possibility that the BlockBackend is smaller than the rom_size. However, if the rom cannot be read from the BlockBackend it will return an error code anyway.
So the check can simply be removed. Thanks!
Quoted 26 lines
hw/arm/allwinner-h3.c enum {
Quoted 6 lines
hw/arm/allwinner-h3.c +5
-0+ } + + buffer =g_new0 (uint8_t, rom_size); +if (blk_pread (blk,8 * KiB, buffer, rom_size) <0 ) { + error_setg(errp, "%s: failed to read BlockBackend data",
__func__);Quoted 17 lines
hw/arm/allwinner-h3.c +9
-0+return ; + } + +rom_add_blob ("allwinner-h3.bootrom" , buffer, rom_size, + rom_size, s->memmap[AW_H3_SRAM_A1 ], +NULL ,NULL ,NULL ,NULL , false); +g_free (buffer); +} +static void allwinner_h3_init (Object *obj) {AwH3State *s =AW_H3 (obj);hw/arm/orangepi.c +0
-0hw/arm/orangepi.c static void orangepi_init(MachineState *machine) · line 95
Quoted 1 line
hw/arm/orangepi.c +0
-0@@ -95,6 +95,11 @@ static void orangepi_init(MachineState *machine) memory_region_add_subregion(get_system_memory(),s->h3->memmap[AW_H3_SDRAM],
Quoted 9 lines
hw/arm/orangepi.c static void orangepi_init(MachineState *machine) · line 101
Quoted 6 lines
hw/arm/orangepi.c +4
-0&s->sdram); +/* Load target kernel or start using BootROM */ +if (!machine->kernel_filename &&blk_is_available (blk)) { +/* Use Boot ROM to copy data from SD card to SRAM */ +allwinner_h3_bootrom_setup (s->h3, blk, &error_fatal);
allwinner_h3_bootrom_setup()doesn't need the errp argument, you can useerror_fataldirectly there.
OK, I'll use error_fatal and remove the errp argument.
Regards,
Niek
Quoted 8 lines
Quoted 6 lines
hw/arm/orangepi.c +1
-0+ } orangepi_binfo.loader_start = s->h3->memmap[AW_H3_SDRAM ]; orangepi_binfo.ram_size = machine->ram_size;arm_load_kernel (ARM_CPU (first_cpu), machine, &orangepi_binfo);
Signature · 1 line
Niek Linnenbank
PATCH v4 11/20 hw/arm/allwinner-h3: add SDRAM controller device
In reply to Niek LinnenbankIn the Allwinner H3 SoC the SDRAM controller is responsible for interfacing with the external Synchronous Dynamic Random Access Memory (SDRAM). Types of memory that the SDRAM controller supports are DDR2/DDR3 and capacities of up to 2GiB. This commit adds emulation support of the Allwinner H3 SDRAM controller.
--- include/hw/arm/allwinner-h3.h | 5 + include/hw/misc/allwinner-h3-dramc.h | 106 ++++++++ hw/arm/allwinner-h3.c | 19 +- hw/arm/orangepi.c | 6 + hw/misc/allwinner-h3-dramc.c | 358 +++++++++++++++++++++++++++ hw/misc/Makefile.objs | 1 + hw/misc/trace-events | 10 + 7 files changed, 502 insertions(+), 3 deletions(-) create mode 100644 include/hw/misc/allwinner-h3-dramc.h create mode 100644 hw/misc/allwinner-h3-dramc.c
include/hw/arm/allwinner-h3.h +5 -0
@@ -41,6 +41,7 @@#include "hw/intc/arm_gic.h" #include "hw/misc/allwinner-h3-ccu.h" #include "hw/misc/allwinner-cpucfg.h" +#include "hw/misc/allwinner-h3-dramc.h" #include "hw/misc/allwinner-h3-sysctrl.h" #include "hw/misc/allwinner-sid.h" #include "hw/sd/allwinner-sdhost.h"
@@ -80,6 +81,9 @@ enum {AW_H3_UART2 ,AW_H3_UART3 ,AW_H3_EMAC , +AW_H3_DRAMCOM , +AW_H3_DRAMCTL , +AW_H3_DRAMPHY ,AW_H3_GIC_DIST ,AW_H3_GIC_CPU , AW_H3_GIC_HYP,
@@ -120,6 +124,7 @@ typedef struct AwH3State {AwA10PITState timer;AwH3ClockCtlState ccu;AwCpuCfgState cpucfg; +AwH3DramCtlState dramc;AwH3SysCtrlState sysctrl;AwSidState sid;AwSdHostState mmc0;
include/hw/misc/allwinner-h3-dramc.h new file +106 -0
106 lines not on this page · raw message
hw/arm/allwinner-h3.c +16 -3
@@ -56,6 +56,9 @@ const hwaddr allwinner_h3_memmap[] = { [AW_H3_UART2] = 0x01c28800, [AW_H3_UART3] = 0x01c28c00, [AW_H3_EMAC] = 0x01c30000, + [AW_H3_DRAMCOM] = 0x01c62000, + [AW_H3_DRAMCTL] = 0x01c63000, + [AW_H3_DRAMPHY] = 0x01c65000, [AW_H3_GIC_DIST] = 0x01c81000, [AW_H3_GIC_CPU] = 0x01c82000, [AW_H3_GIC_HYP] = 0x01c84000,
@@ -110,9 +113,6 @@ struct AwH3Unimplemented { { "scr", 0x01c2c400, 1 * KiB }, { "gpu", 0x01c40000, 64 * KiB }, { "hstmr", 0x01c60000, 4 * KiB }, - { "dramcom", 0x01c62000, 4 * KiB }, - { "dramctl0", 0x01c63000, 4 * KiB }, - { "dramphy0", 0x01c65000, 4 * KiB }, { "spi0", 0x01c68000, 4 * KiB }, { "spi1", 0x01c69000, 4 * KiB }, { "csi", 0x01cb0000, 320 * KiB },
@@ -239,6 +239,13 @@ static void allwinner_h3_init(Object *obj)sysbus_init_child_obj (obj,"emac" , &s->emac,sizeof (s->emac),TYPE_AW_SUN8I_EMAC ); + +sysbus_init_child_obj (obj,"dramc" , &s->dramc,sizeof (s->dramc), +TYPE_AW_H3_DRAMC ); +object_property_add_alias (obj,"ram-addr" ,OBJECT (&s->dramc), +"ram-addr" , &error_abort); +object_property_add_alias (obj,"ram-size" ,OBJECT (&s->dramc), +"ram-size" , &error_abort); }static void allwinner_h3_realize (DeviceState *dev,Error **errp)
@@ -423,6 +430,12 @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)qdev_get_gpio_in (DEVICE (&s->gic),AW_H3_GIC_SPI_UART3 ), 115200, serial_hd(3), DEVICE_NATIVE_ENDIAN); +/* DRAMC */ +qdev_init_nofail (DEVICE (&s->dramc)); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->dramc),0 , s->memmap[AW_H3_DRAMCOM ]); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->dramc),1 , s->memmap[AW_H3_DRAMCTL ]); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->dramc),2 , s->memmap[AW_H3_DRAMPHY ]); +/* Unimplemented devices */ for (i =0 ; i <ARRAY_SIZE (unimplemented); i++) { create_unimplemented_device(unimplemented[i].device_name,
hw/arm/orangepi.c +6 -0
@@ -72,6 +72,12 @@ static void orangepi_init(MachineState *machine)/* Setup EMAC properties */ object_property_set_int (OBJECT (&s->h3->emac),1 ,"phy-addr" , &error_abort); +/* DRAMC */ +object_property_set_uint (OBJECT (s->h3), s->h3->memmap[AW_H3_SDRAM ], +"ram-addr" , &error_abort); +object_property_set_int (OBJECT (s->h3), machine->ram_size / MiB,"ram-size" , + &error_abort); +/* Mark H3 object realized */ object_property_set_bool (OBJECT (s->h3), true,"realized" , &error_abort);
hw/misc/allwinner-h3-dramc.c new file +358 -0
358 lines not on this page · raw message
hw/misc/Makefile.objs +1 -0
@@ -30,6 +30,7 @@ common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o obj-$(CONFIG_ALLWINNER_H3) += allwinner-cpucfg.o +common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-dramc.o common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-sysctrl.o common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-sid.o common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o
hw/misc/trace-events +10 -0
@@ -5,6 +5,16 @@ allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "id %u, reset_ad allwinner_cpucfg_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 allwinner_cpucfg_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 +# allwinner-h3-dramc.c +allwinner_h3_dramc_rowmirror_disable(void) "Disable row mirror" +allwinner_h3_dramc_rowmirror_enable(uint64_t addr) "Enable row mirror: addr 0x%" PRIx64 +allwinner_h3_dramcom_read(uint64_t offset, uint64_t data, unsigned size) "Read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 +allwinner_h3_dramcom_write(uint64_t offset, uint64_t data, unsigned size) "Write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 +allwinner_h3_dramctl_read(uint64_t offset, uint64_t data, unsigned size) "Read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 +allwinner_h3_dramctl_write(uint64_t offset, uint64_t data, unsigned size) "Write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 +allwinner_h3_dramphy_read(uint64_t offset, uint64_t data, unsigned size) "Read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 +allwinner_h3_dramphy_write(uint64_t offset, uint64_t data, unsigned size) "write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 + # allwinner-sid.c allwinner_sid_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 allwinner_sid_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
Signature · 1 line
2.17.1
PATCH v4 12/20 hw/arm/allwinner: add RTC device support
In reply to Niek LinnenbankAllwinner System-on-Chips usually contain a Real Time Clock (RTC) for non-volatile system date and time keeping. This commit adds a generic Allwinner RTC device that supports the RTC devices found in Allwinner SoC family sun4i (A10), sun7i (A20) and sun6i and newer (A31, H2+, H3, etc). The following RTC functionality and features are implemented:
* Year-Month-Day read/write
* Hour-Minute-Second read/write
* General Purpose storage
The following boards are extended with the RTC device:
* Cubieboard (hw/arm/cubieboard.c)
* Orange Pi PC (hw/arm/orangepi.c)
--- include/hw/arm/allwinner-a10.h | 2 + include/hw/arm/allwinner-h3.h | 3 + include/hw/rtc/allwinner-rtc.h | 128 +++++++++++ hw/arm/allwinner-a10.c | 8 + hw/arm/allwinner-h3.c | 9 +- hw/rtc/allwinner-rtc.c | 386 +++++++++++++++++++++++++++++++++ hw/rtc/Makefile.objs | 1 + hw/rtc/trace-events | 4 + 8 files changed, 540 insertions(+), 1 deletion(-) create mode 100644 include/hw/rtc/allwinner-rtc.h create mode 100644 hw/rtc/allwinner-rtc.c
include/hw/arm/allwinner-a10.h +2 -0
@@ -9,6 +9,7 @@#include "hw/net/allwinner_emac.h" #include "hw/sd/allwinner-sdhost.h" #include "hw/ide/ahci.h" +#include "hw/rtc/allwinner-rtc.h" #include "target/arm/cpu.h"
@@ -29,6 +30,7 @@ typedef struct AwA10State {AwEmacState emac;AllwinnerAHCIState sata;AwSdHostState mmc0; +AwRtcState rtc;MemoryRegion sram_a; } AwA10State;
include/hw/arm/allwinner-h3.h +3 -0
@@ -46,6 +46,7 @@#include "hw/misc/allwinner-sid.h" #include "hw/sd/allwinner-sdhost.h" #include "hw/net/allwinner-sun8i-emac.h" +#include "hw/rtc/allwinner-rtc.h" #include "target/arm/cpu.h" #include "sysemu/block-backend.h"
@@ -88,6 +89,7 @@ enum {AW_H3_GIC_CPU ,AW_H3_GIC_HYP ,AW_H3_GIC_VCPU , +AW_H3_RTC ,AW_H3_CPUCFG , AW_H3_SDRAM };
@@ -129,6 +131,7 @@ typedef struct AwH3State {AwSidState sid;AwSdHostState mmc0;AwSun8iEmacState emac; +AwRtcState rtc;GICState gic;MemoryRegion sram_a1;MemoryRegion sram_a2;
include/hw/rtc/allwinner-rtc.h new file +128 -0
128 lines not on this page · raw message
hw/arm/allwinner-a10.c +8 -0
@@ -31,6 +31,7 @@#define AW_A10_UART0_REG_BASE 0x01c28000#define AW_A10_EMAC_BASE 0x01c0b000#define AW_A10_SATA_BASE 0x01c18000 +#define AW_A10_RTC_BASE 0x01c20d00static void aw_a10_init (Object *obj) {
@@ -53,6 +54,9 @@ static void aw_a10_init(Object *obj)sysbus_init_child_obj (obj,"mmc0" , &s->mmc0,sizeof (s->mmc0),TYPE_AW_SDHOST_SUN4I ); + +sysbus_init_child_obj (obj,"rtc" , &s->rtc,sizeof (s->rtc), +TYPE_AW_RTC_SUN4I ); }static void aw_a10_realize (DeviceState *dev,Error **errp)
@@ -132,6 +136,10 @@ static void aw_a10_realize(DeviceState *dev, Error **errp)sysbus_connect_irq (SYS_BUS_DEVICE (&s->mmc0),0 ,qdev_get_gpio_in (dev,32 ));object_property_add_alias (OBJECT (s),"sd-bus" ,OBJECT (&s->mmc0),"sd-bus" , &error_abort); + +/* RTC */ +qdev_init_nofail (DEVICE (&s->rtc)); +sysbus_mmio_map_overlap (SYS_BUS_DEVICE (&s->rtc),0 ,AW_A10_RTC_BASE ,10 ); }static void aw_a10_class_init (ObjectClass *oc,void *data)
hw/arm/allwinner-h3.c +8 -1
@@ -63,6 +63,7 @@ const hwaddr allwinner_h3_memmap[] = { [AW_H3_GIC_CPU] = 0x01c82000, [AW_H3_GIC_HYP] = 0x01c84000, [AW_H3_GIC_VCPU] = 0x01c86000, + [AW_H3_RTC] = 0x01f00000, [AW_H3_CPUCFG] = 0x01f01c00, [AW_H3_SDRAM] = 0x40000000 };
@@ -118,7 +119,6 @@ struct AwH3Unimplemented { { "csi", 0x01cb0000, 320 * KiB }, { "tve", 0x01e00000, 64 * KiB }, { "hdmi", 0x01ee0000, 128 * KiB }, - { "rtc", 0x01f00000, 1 * KiB }, { "r_timer", 0x01f00800, 1 * KiB }, { "r_intc", 0x01f00c00, 1 * KiB }, { "r_wdog", 0x01f01000, 1 * KiB },
@@ -246,6 +246,9 @@ static void allwinner_h3_init(Object *obj) "ram-addr", &error_abort);object_property_add_alias (obj,"ram-size" ,OBJECT (&s->dramc),"ram-size" , &error_abort); + +sysbus_init_child_obj (obj,"rtc" , &s->rtc,sizeof (s->rtc), +TYPE_AW_RTC_SUN6I ); }static void allwinner_h3_realize (DeviceState *dev,Error **errp)
@@ -436,6 +439,10 @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)sysbus_mmio_map (SYS_BUS_DEVICE (&s->dramc),1 , s->memmap[AW_H3_DRAMCTL ]);sysbus_mmio_map (SYS_BUS_DEVICE (&s->dramc),2 , s->memmap[AW_H3_DRAMPHY ]); +/* RTC */ +qdev_init_nofail (DEVICE (&s->rtc)); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->rtc),0 , s->memmap[AW_H3_RTC ]); +/* Unimplemented devices */ for (i =0 ; i <ARRAY_SIZE (unimplemented); i++) { create_unimplemented_device(unimplemented[i].device_name,
hw/rtc/allwinner-rtc.c new file +386 -0
386 lines not on this page · raw message
hw/rtc/Makefile.objs +1 -0
@@ -11,3 +11,4 @@ common-obj-$(CONFIG_EXYNOS4) += exynos4210_rtc.o obj-$(CONFIG_MC146818RTC) += mc146818rtc.o common-obj-$(CONFIG_SUN4V_RTC) += sun4v-rtc.o common-obj-$(CONFIG_ASPEED_SOC) += aspeed_rtc.o +common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-rtc.o
hw/rtc/trace-events +4 -0
@@ -1,5 +1,9 @@ # See docs/devel/tracing.txt for syntax documentation. +# allwinner-rtc.c +allwinner_rtc_read(uint64_t addr, uint64_t value) "addr 0x%" PRIx64 " value 0x%" PRIx64 +allwinner_rtc_write(uint64_t addr, uint64_t value) "addr 0x%" PRIx64 " value 0x%" PRIx64 + # sun4v-rtc.c sun4v_rtc_read(uint64_t addr, uint64_t value) "read: addr 0x%" PRIx64 " value 0x%" PRIx64 sun4v_rtc_write(uint64_t addr, uint64_t value) "write: addr 0x%" PRIx64 " value 0x%" PRIx64
Signature · 1 line
2.17.1
PATCH v4 13/20 tests/boot_linux_console: Add a quick test for the OrangePi PC board
In reply to Niek LinnenbankFrom: Philippe Mathieu-Daudé <[email protected]>
This test boots a Linux kernel on a OrangePi PC board and verify the serial output is working.
The kernel image and DeviceTree blob are built by the Armbian project (based on Debian):
https://www.armbian.com/orange-pi-pc/
If ARM is a target being built, "make check-acceptance" will automatically include this test by the use of the "arch:arm" tags.
Alternatively, this test can be run using:
$ make check-venv $ ./tests/venv/bin/avocado --show=console,app run -t machine:orangepi-pc tests/acceptance/boot_linux_console.py JOB ID : 2e4d15eceb13c33672af406f08171e6e9de1414a JOB LOG : ~/job-results/job-2019-12-17T05.46-2e4d15e/job.log (1/1) tests/acceptance/boot_linux_console.py:BootLinuxConsole.test_arm_orangepi: console: Uncompressing Linux... done, booting the kernel. console: Booting Linux on physical CPU 0x0 console: Linux version 4.20.7-sunxi ([email protected]) (gcc version 7.2.1 20171011 (Linaro GCC 7.2-2017.11)) #5.75 SMP Fri Feb 8 09:02:10 CET 2019 console: CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=50c5387d console: CPU: div instructions available: patching division code console: CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache console: OF: fdt: Machine model: Xunlong Orange Pi PC console: Memory policy: Data cache writealloc console: OF: reserved mem: failed to allocate memory for node 'cma@4a000000' console: cma: Failed to reserve 128 MiB console: psci: probing for conduit method from DT. console: psci: PSCIv0.2 detected in firmware. console: psci: Using standard PSCI v0.2 function IDs console: psci: Trusted OS migration not required console: random: get_random_bytes called from start_kernel+0x8d/0x3c2 with crng_init=0 console: percpu: Embedded 18 pages/cpu @(ptrval) s41228 r8192 d24308 u73728 console: Built 1 zonelists, mobility grouping on. Total pages: 32480 console: Kernel command line: printk.time=0 console=ttyS0,115200 PASS (8.59 s) JOB TIME : 8.81 s
--- tests/acceptance/boot_linux_console.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
tests/acceptance/boot_linux_console.py +25 -0
@@ -485,6 +485,31 @@ class BootLinuxConsole(Test): exec_command_and_wait_for_pattern(self, 'reboot', 'reboot: Restarting system') + def test_arm_orangepi(self): + """ + :avocado: tags=arch:arm + :avocado: tags=machine:orangepi-pc + """ + deb_url = ('https://apt.armbian.com/pool/main/l/' + 'linux-4.20.7-sunxi/linux-image-dev-sunxi_5.75_armhf.deb') + deb_hash = '1334c29c44d984ffa05ed10de8c3361f33d78315' + deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) + kernel_path = self.extract_from_deb(deb_path, + '/boot/vmlinuz-4.20.7-sunxi') + dtb_path = '/usr/lib/linux-image-dev-sunxi/sun8i-h3-orangepi-pc.dtb' + dtb_path = self.extract_from_deb(deb_path, dtb_path) + + self.vm.set_console() + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'console=ttyS0,115200n8 ' + 'earlycon=uart,mmio32,0x1c28000') + self.vm.add_args('-kernel', kernel_path, + '-dtb', dtb_path, + '-append', kernel_command_line) + self.vm.launch() + console_pattern = 'Kernel command line: %s' % kernel_command_line + self.wait_for_console_pattern(console_pattern) + def test_s390x_s390_ccw_virtio(self): """ :avocado: tags=arch:s390x
Signature · 1 line
2.17.1
PATCH v4 14/20 tests/boot_linux_console: Add initrd test for the Orange Pi PC board
In reply to Niek LinnenbankFrom: Philippe Mathieu-Daudé <[email protected]>
This test boots a Linux kernel on a OrangePi PC board and verify the serial output is working.
The kernel image and DeviceTree blob are built by the Armbian project (based on Debian):
https://www.armbian.com/orange-pi-pc/
The cpio image used comes from the linux-build-test project:
https://github.com/groeck/linux-build-test
If ARM is a target being built, "make check-acceptance" will automatically include this test by the use of the "arch:arm" tags.
Alternatively, this test can be run using:
$ avocado --show=console run -t machine:orangepi-pc tests/acceptance/boot_linux_console.py console: Uncompressing Linux... done, booting the kernel. console: Booting Linux on physical CPU 0x0 console: Linux version 4.20.7-sunxi ([email protected]) (gcc version 7.2.1 20171011 (Linaro GCC 7.2-2017.11)) #5.75 SMP Fri Feb 8 09:02:10 CET 2019 console: CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=50c5387d console: CPU: div instructions available: patching division code console: CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache console: OF: fdt: Machine model: Xunlong Orange Pi PC [...] console: Trying to unpack rootfs image as initramfs... console: Freeing initrd memory: 3256K console: Freeing unused kernel memory: 1024K console: Run /init as init process console: mount: mounting devtmpfs on /dev failed: Device or resource busy console: Starting logging: OK console: Initializing random number generator... random: dd: uninitialized urandom read (512 bytes read) console: done. console: Starting network: OK console: Found console ttyS0 console: Linux version 4.20.7-sunxi ([email protected]) (gcc version 7.2.1 20171011 (Linaro GCC 7.2-2017.11)) #5.75 SMP Fri Feb 8 09:02:10 CET 2019 console: Boot successful. console: cat /proc/cpuinfo console: / # cat /proc/cpuinfo console: processor : 0 console: model name : ARMv7 Processor rev 5 (v7l) console: BogoMIPS : 125.00 console: Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm console: CPU implementer : 0x41 console: CPU architecture: 7 console: CPU variant : 0x0 console: CPU part : 0xc07 console: CPU revision : 5 [...] console: processor : 3 console: model name : ARMv7 Processor rev 5 (v7l) console: BogoMIPS : 125.00 console: Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm console: CPU implementer : 0x41 console: CPU architecture: 7 console: CPU variant : 0x0 console: CPU part : 0xc07 console: CPU revision : 5 console: Hardware : Allwinner sun8i Family console: Revision : 0000 console: Serial : 0000000000000000 console: cat /proc/iomem console: / # cat /proc/iomem console: 01000000-010fffff : clock@1000000 console: 01c00000-01c00fff : system-control@1c00000 console: 01c02000-01c02fff : dma-controller@1c02000 [...] console: reboot console: / # reboot console: / # Found console ttyS0 console: Stopping network: OK console: hrtimer: interrupt took 21852064 ns console: Saving random seed... random: dd: uninitialized urandom read (512 bytes read) console: done. console: Stopping logging: OK console: umount: devtmpfs busy - remounted read-only console: umount: can't unmount /: Invalid argument console: The system is going down NOW! console: Sent SIGTERM to all processes console: Sent SIGKILL to all processes console: Requesting system reboot console: reboot: Restarting system PASS (48.32 s) JOB TIME : 49.16 s
--- tests/acceptance/boot_linux_console.py | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
tests/acceptance/boot_linux_console.py +40 -0
@@ -510,6 +510,46 @@ class BootLinuxConsole(Test): console_pattern = 'Kernel command line: %s' % kernel_command_line self.wait_for_console_pattern(console_pattern) + def test_arm_orangepi_initrd(self): + """ + :avocado: tags=arch:arm + :avocado: tags=machine:orangepi-pc + """ + deb_url = ('https://apt.armbian.com/pool/main/l/' + 'linux-4.20.7-sunxi/linux-image-dev-sunxi_5.75_armhf.deb') + deb_hash = '1334c29c44d984ffa05ed10de8c3361f33d78315' + deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) + kernel_path = self.extract_from_deb(deb_path, + '/boot/vmlinuz-4.20.7-sunxi') + dtb_path = '/usr/lib/linux-image-dev-sunxi/sun8i-h3-orangepi-pc.dtb' + dtb_path = self.extract_from_deb(deb_path, dtb_path) + initrd_url = ('https://github.com/groeck/linux-build-test/raw/' + '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/' + 'arm/rootfs-armv7a.cpio.gz') + initrd_hash = '604b2e45cdf35045846b8bbfbf2129b1891bdc9c' + initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash) + initrd_path = os.path.join(self.workdir, 'rootfs.cpio') + archive.gzip_uncompress(initrd_path_gz, initrd_path) + + self.vm.set_console() + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'console=ttyS0,115200 ' + 'panic=-1 noreboot') + self.vm.add_args('-kernel', kernel_path, + '-dtb', dtb_path, + '-initrd', initrd_path, + '-append', kernel_command_line, + '-no-reboot') + self.vm.launch() + self.wait_for_console_pattern('Boot successful.') + + exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', + 'Allwinner sun8i Family') + exec_command_and_wait_for_pattern(self, 'cat /proc/iomem', + 'system-control@1c00000') + exec_command_and_wait_for_pattern(self, 'reboot', + 'reboot: Restarting system') + def test_s390x_s390_ccw_virtio(self): """ :avocado: tags=arch:s390x
Signature · 1 line
2.17.1
PATCH v4 15/20 tests/boot_linux_console: Add a SD card test for the OrangePi PC board
In reply to Niek LinnenbankFrom: Philippe Mathieu-Daudé <[email protected]>
The kernel image and DeviceTree blob are built by the Armbian project (based on Debian):
https://www.armbian.com/orange-pi-pc/
The SD image is from the kernelci.org project:
https://kernelci.org/faq/#the-code
If ARM is a target being built, "make check-acceptance" will automatically include this test by the use of the "arch:arm" tags.
Alternatively, this test can be run using:
$ avocado --show=console run -t machine:orangepi-pc tests/acceptance/boot_linux_console.py console: Uncompressing Linux... done, booting the kernel. console: Booting Linux on physical CPU 0x0 console: Linux version 4.20.7-sunxi ([email protected]) (gcc version 7.2.1 20171011 (Linaro GCC 7.2-2017.11)) #5.75 SMP Fri Feb 8 09:02:10 CET 2019 console: CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=50c5387d [...] console: sunxi-wdt 1c20ca0.watchdog: Watchdog enabled (timeout=16 sec, nowayout=0) console: sunxi-mmc 1c0f000.mmc: Linked as a consumer to regulator.2 console: sunxi-mmc 1c0f000.mmc: Got CD GPIO console: ledtrig-cpu: registered to indicate activity on CPUs console: hidraw: raw HID events driver (C) Jiri Kosina console: usbcore: registered new interface driver usbhid console: usbhid: USB HID core driver console: Initializing XFRM netlink socket console: sunxi-mmc 1c0f000.mmc: initialized, max. request size: 16384 KB console: NET: Registered protocol family 10 console: mmc0: host does not support reading read-only switch, assuming write-enable console: mmc0: Problem switching card into high-speed mode! console: mmc0: new SD card at address 4567 console: mmcblk0: mmc0:4567 QEMU! 60.0 MiB [...] console: EXT4-fs (mmcblk0): mounting ext2 file system using the ext4 subsystem console: EXT4-fs (mmcblk0): mounted filesystem without journal. Opts: (null) console: VFS: Mounted root (ext2 filesystem) on device 179:0. console: Run /sbin/init as init process console: EXT4-fs (mmcblk0): re-mounted. Opts: block_validity,barrier,user_xattr,acl console: Starting syslogd: OK console: Starting klogd: OK console: Populating /dev using udev: udevd[203]: starting version 3.2.7 console: /bin/sh: can't access tty; job control turned off console: cat /proc/partitions console: / # cat /proc/partitions console: major minor #blocks name console: 1 0 4096 ram0 console: 1 1 4096 ram1 console: 1 2 4096 ram2 console: 1 3 4096 ram3 console: 179 0 61440 mmcblk0 console: reboot console: / # reboot console: umount: devtmpfs busy - remounted read-only console: EXT4-fs (mmcblk0): re-mounted. Opts: (null) console: The system is going down NOW! console: Sent SIGTERM to all processes console: Sent SIGKILL to all processes console: Requesting system reboot console: reboot: Restarting system JOB TIME : 68.64 s
--- tests/acceptance/boot_linux_console.py | 41 ++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
tests/acceptance/boot_linux_console.py +41 -0
@@ -550,6 +550,47 @@ class BootLinuxConsole(Test): exec_command_and_wait_for_pattern(self, 'reboot', 'reboot: Restarting system') + def test_arm_orangepi_sd(self): + """ + :avocado: tags=arch:arm + :avocado: tags=machine:orangepi-pc + """ + deb_url = ('https://apt.armbian.com/pool/main/l/' + 'linux-4.20.7-sunxi/linux-image-dev-sunxi_5.75_armhf.deb') + deb_hash = '1334c29c44d984ffa05ed10de8c3361f33d78315' + deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) + kernel_path = self.extract_from_deb(deb_path, + '/boot/vmlinuz-4.20.7-sunxi') + dtb_path = '/usr/lib/linux-image-dev-sunxi/sun8i-h3-orangepi-pc.dtb' + dtb_path = self.extract_from_deb(deb_path, dtb_path) + rootfs_url = ('http://storage.kernelci.org/images/rootfs/buildroot/' + 'kci-2019.02/armel/base/rootfs.ext2.xz') + rootfs_hash = '692510cb625efda31640d1de0a8d60e26040f061' + rootfs_path_xz = self.fetch_asset(rootfs_url, asset_hash=rootfs_hash) + rootfs_path = os.path.join(self.workdir, 'rootfs.cpio') + archive.lzma_uncompress(rootfs_path_xz, rootfs_path) + + self.vm.set_console() + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'console=ttyS0,115200 ' + 'root=/dev/mmcblk0 rootwait rw ' + 'panic=-1 noreboot') + self.vm.add_args('-kernel', kernel_path, + '-dtb', dtb_path, + '-drive', 'file=' + rootfs_path + ',if=sd,format=raw', + '-append', kernel_command_line, + '-no-reboot') + self.vm.launch() + shell_ready = "/bin/sh: can't access tty; job control turned off" + self.wait_for_console_pattern(shell_ready) + + exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', + 'Allwinner sun8i Family') + exec_command_and_wait_for_pattern(self, 'cat /proc/partitions', + 'mmcblk0') + exec_command_and_wait_for_pattern(self, 'reboot', + 'reboot: Restarting system') + def test_s390x_s390_ccw_virtio(self): """ :avocado: tags=arch:s390x
Signature · 1 line
2.17.1
PATCH v4 16/20 tests/boot_linux_console: Add a SLOW test booting Ubuntu on OrangePi PC
In reply to Niek LinnenbankFrom: Philippe Mathieu-Daudé <[email protected]>
This test boots Ubuntu Bionic on a OrangePi PC board.
As it requires 1GB of storage, and is slow, this test is disabled on automatic CI testing.
It is useful for workstation testing. Currently Avocado timeouts too quickly, so we can't run userland commands.
The kernel image and DeviceTree blob are built by the Armbian project (based on Debian):
https://www.armbian.com/orange-pi-pc/
The Ubuntu image is downloaded from:
https://dl.armbian.com/orangepipc/Bionic_current
This test can be run using:
$ AVOCADO_ALLOW_LARGE_STORAGE=yes \
avocado --show=app,console run -t machine:orangepi-pc \
tests/acceptance/boot_linux_console.py
console: U-Boot SPL 2019.04-armbian (Nov 18 2019 - 23:08:35 +0100)
console: DRAM: 1024 MiB
console: Failed to set core voltage! Can't set CPU frequency
console: Trying to boot from MMC1
console: U-Boot 2019.04-armbian (Nov 18 2019 - 23:08:35 +0100) Allwinner Technology
console: CPU: Allwinner H3 (SUN8I 0000)
console: Model: Xunlong Orange Pi PC
console: DRAM: 1 GiB
console: MMC: mmc@1c0f000: 0
[...]
console: Uncompressing Linux... done, booting the kernel.
console: Booting Linux on physical CPU 0x0
console: Linux version 5.3.9-sunxi (root@builder) (gcc version 8.3.0 (GNU Toolchain for the A-profile Architecture 8.3-2019.03 (arm-rel-8.36))) #19.11.3 SMP Mon Nov 18 18:49:43 CET 2019
console: CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=50c5387d
console: CPU: div instructions available: patching division code
console: CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
console: OF: fdt: Machine model: Xunlong Orange Pi PC
[...]
console: EXT4-fs (mmcblk0p1): mounted filesystem with writeback data mode. Opts: (null)
console: done.
console: Begin: Running /scripts/local-bottom ... done.
console: Begin: Running /scripts/init-bottom ... done.
console: systemd[1]: systemd 237 running in system mode. (...)
console: systemd[1]: Detected architecture arm.
console: Welcome to Ubuntu 18.04.3 LTS!
console: systemd[1]: Set hostname to <orangepipc>.--- tests/acceptance/boot_linux_console.py | 41 ++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
tests/acceptance/boot_linux_console.py +41 -0
@@ -591,6 +591,47 @@ class BootLinuxConsole(Test): exec_command_and_wait_for_pattern(self, 'reboot', 'reboot: Restarting system') + @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited') + def test_arm_orangepi_bionic(self): + """ + :avocado: tags=arch:arm + :avocado: tags=machine:orangepi-pc + """ + + # This test download a 196MB compressed image and expand it to 932MB... + image_url = ('https://dl.armbian.com/orangepipc/archive/' + 'Armbian_19.11.3_Orangepipc_bionic_current_5.3.9.7z') + image_hash = '196a8ffb72b0123d92cea4a070894813d305c71e' + image_path_7z = self.fetch_asset(image_url, asset_hash=image_hash) + image_name = 'Armbian_19.11.3_Orangepipc_bionic_current_5.3.9.img' + image_path = os.path.join(self.workdir, image_name) + process.run("7z e -o%s %s" % (self.workdir, image_path_7z)) + + self.vm.set_console() + self.vm.add_args('-drive', 'file=' + image_path + ',if=sd,format=raw', + '-nic', 'user', + '-no-reboot') + self.vm.launch() + + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'console=ttyS0,115200 ' + 'loglevel=7 ' + 'nosmp ' + 'systemd.default_timeout_start_sec=9000 ' + 'systemd.mask=armbian-zram-config.service ' + 'systemd.mask=armbian-ramlog.service') + + self.wait_for_console_pattern('U-Boot SPL') + self.wait_for_console_pattern('Autoboot in ') + exec_command_and_wait_for_pattern(self, ' ', '=>') + exec_command_and_wait_for_pattern(self, "setenv extraargs '" + + kernel_command_line + "'", '=>') + exec_command_and_wait_for_pattern(self, 'boot', 'Starting kernel ...'); + + self.wait_for_console_pattern('systemd[1]: Set hostname ' + + 'to <orangepipc>') + self.wait_for_console_pattern('Starting Load Kernel Modules...') + def test_s390x_s390_ccw_virtio(self): """ :avocado: tags=arch:s390x
Signature · 1 line
2.17.1
Re: [PATCH v4 16/20] tests/boot_linux_console: Add a SLOW test booting Ubuntu on OrangePi PC
Quoted 10 lines · Niek Linnenbank
From: Philippe Mathieu-Daudé <[email protected]>
This test boots Ubuntu Bionic on a OrangePi PC board.
As it requires 1GB of storage, and is slow, this test is disabled on automatic CI testing.
It is useful for workstation testing. Currently Avocado timeouts too quickly, so we can't run userland commands.
Quoted 6 lines
The kernel image and DeviceTree blob are built by the Armbian project (based on Debian):
https://www.armbian.com/orange-pi-pc/The Ubuntu image is downloaded from:
https://dl.armbian.com/orangepipc/Bionic_current
I forgot the image is compressed is compressed with 7z, which is not provided by avocado.utils.archive. This patch requires more checks, see inlined...
tests/acceptance/boot_linux_console.py
Quoted 45 lines
This test can be run using:
$ AVOCADO_ALLOW_LARGE_STORAGE=yes \ avocado --show=app,console run -t machine:orangepi-pc \ tests/acceptance/boot_linux_console.py console: U-Boot SPL 2019.04-armbian (Nov 18 2019 - 23:08:35 +0100) console: DRAM: 1024 MiB console: Failed to set core voltage! Can't set CPU frequency console: Trying to boot from MMC1 console: U-Boot 2019.04-armbian (Nov 18 2019 - 23:08:35 +0100) Allwinner Technology console: CPU: Allwinner H3 (SUN8I 0000) console: Model: Xunlong Orange Pi PC console: DRAM: 1 GiB console: MMC: mmc@1c0f000: 0 [...] console: Uncompressing Linux... done, booting the kernel. console: Booting Linux on physical CPU 0x0 console: Linux version 5.3.9-sunxi (root@builder) (gcc version 8.3.0 (GNU Toolchain for the A-profile Architecture 8.3-2019.03 (arm-rel-8.36))) #19.11.3 SMP Mon Nov 18 18:49:43 CET 2019 console: CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=50c5387d console: CPU: div instructions available: patching division code console: CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache console: OF: fdt: Machine model: Xunlong Orange Pi PC [...] console: EXT4-fs (mmcblk0p1): mounted filesystem with writeback data mode. Opts: (null) console: done. console: Begin: Running /scripts/local-bottom ... done. console: Begin: Running /scripts/init-bottom ... done. console: systemd[1]: systemd 237 running in system mode. (...) console: systemd[1]: Detected architecture arm. console: Welcome to Ubuntu 18.04.3 LTS! console: systemd[1]: Set hostname to <orangepipc>.Signed-off-by Philippe Mathieu-Daudé <[email protected]>[NL: rename in commit message Raspbian to Armbian, remove vm.set_machine()][NL: changed test to boot from SD card via BootROM]Signed-off-by Niek Linnenbank <[email protected]>--- tests/acceptance/boot_linux_console.py | 41 ++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)tests/acceptance/boot_linux_console.py +0
-0
This patch needs:
from avocado.utils.path import find_command
P7ZIP_AVAILABLE = True
try:
find_command('7z') except CmdNotFoundError:
P7ZIP_AVAILABLE = False
tests/acceptance/boot_linux_console.py class BootLinuxConsole(Test): · line 594
Quoted 5 lines
tests/acceptance/boot_linux_console.py +1
-0@@ -591,6 +591,47 @@ class BootLinuxConsole(Test): exec_command_and_wait_for_pattern(self, 'reboot', 'reboot: Restarting system') + @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited')
@skipUnless(P7ZIP_AVAILABLE, '7z not installed')
Quoted 4 lines
tests/acceptance/boot_linux_console.py +4
-0+ def test_arm_orangepi_bionic(self): + """ + :avocado: tags=arch:arm + :avocado: tags=machine:orangepi-pc
tests/acceptance/boot_linux_console.py class BootLinuxConsole(Test): · line 608
Quoted 10 lines
tests/acceptance/boot_linux_console.py +10
-0+ """ + + # This test download a 196MB compressed image and expand it to 932MB... + image_url = ('https://dl.armbian.com/orangepipc/archive/' + 'Armbian_19.11.3_Orangepipc_bionic_current_5.3.9.7z') + image_hash = '196a8ffb72b0123d92cea4a070894813d305c71e' + image_path_7z = self.fetch_asset(image_url, asset_hash=image_hash) + image_name = 'Armbian_19.11.3_Orangepipc_bionic_current_5.3.9.img' + image_path = os.path.join(self.workdir, image_name) + process.run("7z e -o%s %s" % (self.workdir, image_path_7z))
Because here 7z is called ^
Quoted 30 lines
tests/acceptance/boot_linux_console.py +26
-0+ + self.vm.set_console() + self.vm.add_args('-drive', 'file=' + image_path + ',if=sd,format=raw', + '-nic', 'user', + '-no-reboot') + self.vm.launch() + + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'console=ttyS0,115200 ' + 'loglevel=7 ' + 'nosmp ' + 'systemd.default_timeout_start_sec=9000 ' + 'systemd.mask=armbian-zram-config.service ' + 'systemd.mask=armbian-ramlog.service') + + self.wait_for_console_pattern('U-Boot SPL') + self.wait_for_console_pattern('Autoboot in ') + exec_command_and_wait_for_pattern(self, ' ', '=>') + exec_command_and_wait_for_pattern(self, "setenv extraargs '" + + kernel_command_line + "'", '=>') + exec_command_and_wait_for_pattern(self, 'boot', 'Starting kernel ...'); + + self.wait_for_console_pattern('systemd[1]: Set hostname ' + + 'to <orangepipc>') + self.wait_for_console_pattern('Starting Load Kernel Modules...') + def test_s390x_s390_ccw_virtio(self): """ :avocado: tags=arch:s390x
Re: [PATCH v4 16/20] tests/boot_linux_console: Add a SLOW test booting Ubuntu on OrangePi PC
Hi Philippe,
Quoted 91 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Niek Linnenbank
From: Philippe Mathieu-Daudé <[email protected]>
This test boots Ubuntu Bionic on a OrangePi PC board.
As it requires 1GB of storage, and is slow, this test is disabled on automatic CI testing.
It is useful for workstation testing. Currently Avocado timeouts too quickly, so we can't run userland commands.
Quoted 6 lines
The kernel image and DeviceTree blob are built by the Armbian project (based on Debian):
https://www.armbian.com/orange-pi-pc/The Ubuntu image is downloaded from:
https://dl.armbian.com/orangepipc/Bionic_currentI forgot the image is compressed is compressed with 7z, which is not provided by avocado.utils.archive. This patch requires more checks, see inlined...
Quoted 11 lines
This test can be run using:
$ AVOCADO_ALLOW_LARGE_STORAGE=yes \ avocado --show=app,console run -t machine:orangepi-pc \ tests/acceptance/boot_linux_console.py console: U-Boot SPL 2019.04-armbian (Nov 18 2019 - 23:08:35 +0100) console: DRAM: 1024 MiB console: Failed to set core voltage! Can't set CPU frequency console: Trying to boot from MMC1 console: U-Boot 2019.04-armbian (Nov 18 2019 - 23:08:35 +0100)Allwinner Technology
Quoted 8 lines
console: CPU: Allwinner H3 (SUN8I 0000)
console: Model: Xunlong Orange Pi PC
console: DRAM: 1 GiB
console: MMC: mmc@1c0f000: 0
[...]
console: Uncompressing Linux... done, booting the kernel.
console: Booting Linux on physical CPU0x0
console: Linux version 5.3.9-sunxi (root@builder) (gcc version 8.3.0(GNU Toolchain for the A-profile Architecture 8.3-2019.03 (arm-rel-8.36))) #19.11.3 SMP Mon Nov 18 18:49:43 CET 2019
Quoted 1 line
console: CPU: ARMv7 Processor [
410fc075] revision 5 (ARMv7),cr=50c5387d
Quoted 2 lines
console: CPU: div instructions available: patching division code
console: CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasinginstruction cache
Quoted 3 lines
console: OF: fdt: Machine model: Xunlong Orange Pi PC [...]
console: EXT4-fs (mmcblk0p1): mounted filesystem with writeback datamode. Opts: (null)
Quoted 10 lines
console: done.
console: Begin: Running /scripts/local-bottom ... done.
console: Begin: Running /scripts/init-bottom ... done.
console: systemd[1]: systemd 237 running in system mode. (...)
console: systemd[1]: Detected architecture arm.
console: Welcome to Ubuntu 18.04.3 LTS!
console: systemd[1]: Set hostname to <orangepipc>.Signed-off-by Philippe Mathieu-Daudé <[email protected]>[NL: rename in commit message Raspbian to Armbian, remove
vm.set_machine()]Review
Quoted 7 lines
[NL: changed test to boot from SD card via BootROM]Signed-off-by Niek Linnenbank <[email protected]>--- tests/acceptance/boot_linux_console.py | 41 ++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)(quoted diff) +0
-0
b/tests/acceptance/boot_linux_console.pytests/acceptance/boot_linux_console.py
Quoted 3 lines
index
50294e1675..399d5062db100644tests/acceptance/boot_linux_console.py +0
-0This patch needs:
from avocado.utils.path import
find_command
P7ZIP_AVAILABLE= True
try:find_command('7z')except CmdNotFoundError:
P7ZIP_AVAILABLE= Falsetests/acceptance/boot_linux_console.py class BootLinuxConsole(Test): · line 592
Quoted 3 lines
tests/acceptance/boot_linux_console.py +0
-0@@ -591,6 +591,47 @@ class BootLinuxConsole(Test): exec_command_and_wait_for_pattern(self, 'reboot', 'reboot: Restartingsystem')
Quoted 1 line
Quoted 5 lines
Quoted 1 line
+ @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage
limited')
@skipUnless(P7ZIP_AVAILABLE, '7z not installed')
Ah indeed, that makes sense. I'll add this check for v5.
Now that we come accross this, I'm thinking that functionality like decompression
might not be specific to the linux tests and perhaps should eventually come in a utility/helper .py file.
Regards,
Niek
Quoted 57 lines
tests/acceptance/boot_linux_console.py class BootLinuxConsole(Test):
Quoted 8 lines
tests/acceptance/boot_linux_console.py +7
-0+ def test_arm_orangepi_bionic(self): + """ + :avocado: tags=arch:arm + :avocado: tags=machine:orangepi-pc + """ + + # This test download a 196MB compressed image and expand it to932MB...
tests/acceptance/boot_linux_console.py
Quoted 2 lines
tests/acceptance/boot_linux_console.py +2
-0+ image_url = ('https://dl.armbian.com/orangepipc/archive/' +'Armbian_19.11.3_Orangepipc_bionic_current_5.3.9.7z')
tests/acceptance/boot_linux_console.py
Quoted 2 lines
tests/acceptance/boot_linux_console.py +2
-0+ image_hash = '196a8ffb72b0123d92cea4a070894813d305c71e' + image_path_7z = self.fetch_asset(image_url,asset_hash=image_hash)
Quoted 1 line
+
image_name='Armbian_19.11.3_Orangepipc_bionic_current_5.3.9.img'
tests/acceptance/boot_linux_console.py class BootLinuxConsole(Test): · line 608
Quoted 2 lines
tests/acceptance/boot_linux_console.py +2
-0+ image_path = os.path.join(self.workdir, image_name) + process.run("7z e -o%s %s" % (self.workdir, image_path_7z))Because here 7z is called ^
tests/acceptance/boot_linux_console.py class BootLinuxConsole(Test):
Quoted 3 lines
tests/acceptance/boot_linux_console.py +3
-0+ + self.vm.set_console() + self.vm.add_args('-drive', 'file=' + image_path +',if=sd,format=raw',
tests/acceptance/boot_linux_console.py class BootLinuxConsole(Test): · line 623
Quoted 10 lines
tests/acceptance/boot_linux_console.py +10
-0+ '-nic', 'user', + '-no-reboot') + self.vm.launch() + + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'console=ttyS0,115200 ' + 'loglevel=7 ' + 'nosmp ' + 'systemd.default_timeout_start_sec=9000 ' +'systemd.mask=armbian-zram-config.service '
tests/acceptance/boot_linux_console.py class BootLinuxConsole(Test):
Quoted 7 lines
tests/acceptance/boot_linux_console.py +7
-0+ 'systemd.mask=armbian-ramlog.service') + + self.wait_for_console_pattern('U-Boot SPL') + self.wait_for_console_pattern('Autoboot in ') + exec_command_and_wait_for_pattern(self, ' ', '=>') + exec_command_and_wait_for_pattern(self, "setenv extraargs '" + + kernel_command_line +"'", '=>')
Quoted 1 line
+ exec_command_and_wait_for_pattern(self, 'boot', 'Starting
kernel ...');
Quoted 9 lines
tests/acceptance/boot_linux_console.py +5
-0+ + self.wait_for_console_pattern('systemd[1]: Set hostname ' + + 'to <orangepipc>') + self.wait_for_console_pattern('Starting Load Kernel Modules...') + def test_s390x_s390_ccw_virtio(self): """ :avocado: tags=arch:s390x
Signature · 1 line
Niek Linnenbank
Re: [PATCH v4 16/20] tests/boot_linux_console: Add a SLOW test booting Ubuntu on OrangePi PC
Quoted 102 lines · Niek Linnenbank
Hi Philippe,
On Sun, Jan 19, 2020 at 11:30 PM Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:
On 1/19/20 1:50 AM, Niek Linnenbank wrote:
> From: Philippe Mathieu-Daudé <[email protected]
<mailto:[email protected]>>
>
> This test boots Ubuntu Bionic on a OrangePi PC board.
>
> As it requires 1GB of storage, and is slow, this test is disabled > on automatic CI testing.
>
> It is useful for workstation testing. Currently Avocado timeouts too > quickly, so we can't run userland commands.
>
> The kernel image and DeviceTree blob are built by the Armbian > project (based on Debian):
> https://www.armbian.com/orange-pi-pc/
>
> The Ubuntu image is downloaded from:
> https://dl.armbian.com/orangepipc/Bionic_currentI forgot the image is compressed is compressed with 7z, which is not provided by avocado.utils.archive. This patch requires more checks, see inlined...
>
> This test can be run using:
>
> $ AVOCADO_ALLOW_LARGE_STORAGE=yes \
> avocado --show=app,console run -t machine:orangepi-pc \
> tests/acceptance/boot_linux_console.py
> console: U-Boot SPL 2019.04-armbian (Nov 18 2019 - 23:08:35 +0100) > console: DRAM: 1024 MiB
> console: Failed to set core voltage! Can't set CPU frequency > console: Trying to boot from MMC1
> console: U-Boot 2019.04-armbian (Nov 18 2019 - 23:08:35 +0100)
Allwinner Technology
> console: CPU: Allwinner H3 (SUN8I 0000)
> console: Model: Xunlong Orange Pi PC
> console: DRAM: 1 GiB
> console: MMC: mmc@1c0f000: 0
> [...]
> console: Uncompressing Linux... done, booting the kernel. > console: Booting Linux on physical CPU0x0
> console: Linux version 5.3.9-sunxi (root@builder) (gcc version
8.3.0 (GNU Toolchain for the A-profile Architecture 8.3-2019.03 (arm-rel-8.36))) #19.11.3 SMP Mon Nov 18 18:49:43 CET 2019
> console: CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7),
cr=50c5387d
> console: CPU: div instructions available: patching division code > console: CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing
instruction cache
> console: OF: fdt: Machine model: Xunlong Orange Pi PC > [...]
> console: EXT4-fs (mmcblk0p1): mounted filesystem with writeback
data mode. Opts: (null)
> console: done.
> console: Begin: Running /scripts/local-bottom ... done. > console: Begin: Running /scripts/init-bottom ... done. > console: systemd[1]: systemd 237 running in system mode. (...) > console: systemd[1]: Detected architecture arm.
> console: Welcome to Ubuntu 18.04.3 LTS!
> console: systemd[1]: Set hostname to <orangepipc>.
>
> Signed-off-by: Philippe Mathieu-Daudé <[email protected]
<mailto:[email protected]>>
> [NL: rename in commit message Raspbian to Armbian, remove
vm.set_machine()]
> [NL: changed test to boot from SD card via BootROM]
> Signed-off-by: Niek Linnenbank <[email protected]
<mailto:[email protected]>>
> ---
>tests/acceptance/boot_linux_console.py| 41
++++++++++++++++++++++++++
> 1 file changed, 41 insertions(+)
>
> diff --gita/tests/acceptance/boot_linux_console.py
b/tests/acceptance/boot_linux_console.py
> index50294e1675..399d5062db100644
> ---a/tests/acceptance/boot_linux_console.py
> +++b/tests/acceptance/boot_linux_console.pyThis patch needs:
from avocado.utils.path import
find_command
P7ZIP_AVAILABLE= True
try:
find_command('7z')
except CmdNotFoundError:
P7ZIP_AVAILABLE= False> @@ -591,6 +591,47 @@ class BootLinuxConsole(Test):
> exec_command_and_wait_for_pattern(self, 'reboot', > 'reboot:
Restarting system')
>
> + @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'),
'storage limited')
Quoted 6 lines
@skipUnless(P7ZIP_AVAILABLE, '7z not installed')
Ah indeed, that makes sense. I'll add this check for v5.
Now that we come accross this, I'm thinking that functionality like decompression
might not be specific to the linux tests and perhaps should eventually come in a utility/helper .py file.
Yes, but it is quicker if you start this way where you use it, then when another uses it he'll refactor the helper. Ideally this should go in the avocado.archive package.
Quoted 70 lines
Regards,
Niek> + def
test_arm_orangepi_bionic(self):
> + """
> + :avocado: tags=arch:arm
> + :avocado: tags=machine:orangepi-pc
> + """
> +
> + # This test download a 196MB compressed image and expand
it to 932MB...
> +image_url= ('https://dl.armbian.com/orangepipc/archive/' > +
'Armbian_19.11.3_Orangepipc_bionic_current_5.3.9.7z')
> +image_hash= '196a8ffb72b0123d92cea4a070894813d305c71e' > +image_path_7z= self.fetch_asset(image_url,
asset_hash=image_hash)
> +image_name=
'Armbian_19.11.3_Orangepipc_bionic_current_5.3.9.img'
> +image_path=os.path.join(self.workdir, image_name)> +process.run("7z e -o%s %s" % (self.workdir, image_path_7z))Because here 7z is called ^
> +
> +self.vm.set_console()
> + self.vm.add_args('-drive', 'file=' +image_path+
',if=sd,format=raw',
> + '-nic', 'user',
> + '-no-reboot')
> +self.vm.launch()
> +
> +kernel_command_line= (self.KERNEL_COMMON_COMMAND_LINE + > + 'console=ttyS0,115200 ' > + 'loglevel=7 '
> + 'nosmp '
> +
'systemd.default_timeout_start_sec=9000 '
> +
'systemd.mask=armbian-zram-config.service '
> +
'systemd.mask=armbian-ramlog.service')
> +
> +self.wait_for_console_pattern('U-Boot SPL')
> +self.wait_for_console_pattern('Autoboot in ')
> +exec_command_and_wait_for_pattern(self, ' ', '=>')> + exec_command_and_wait_for_pattern(self, "setenv
extraargs '" +
> +
kernel_command_line+ "'", '=>')
> + exec_command_and_wait_for_pattern(self, 'boot',
'Starting kernel ...');
> +
> + self.wait_for_console_pattern('systemd[1]: Set hostname ' + > + 'to <orangepipc>') > + self.wait_for_console_pattern('Starting Load Kernel
Modules...')
> +
> deftest_s390x_s390_ccw_virtio(self):
> """
> :avocado: tags=arch:s390x
>Signature · 1 line
Niek Linnenbank
PATCH v4 17/20 Acceptance tests: Extract _console_interaction()
In reply to Niek LinnenbankFrom: Philippe Mathieu-Daudé <[email protected]>
Since we are going to re-use the code shared between wait_for_console_pattern() and exec_command_and_wait_for_pattern(), extract the common part into a local function.
--- tests/acceptance/avocado_qemu/__init__.py | 31 +++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-)
tests/acceptance/avocado_qemu/__init__.py +17 -14
@@ -55,19 +55,14 @@ def pick_default_qemu_bin(arch=None): return qemu_bin_from_src_dir_path -def wait_for_console_pattern(test, success_message, failure_message=None): - """ - Waits for messages to appear on the console, while logging the content - - :param test: an Avocado test containing a VM that will have its console - read and probed for a success or failure message - :type test: :class:`avocado_qemu.Test` - :param success_message: if this message appears, test succeeds - :param failure_message: if this message appears, test fails - """ +def _console_interaction(test, success_message, failure_message, + send_string): console = test.vm.console_socket.makefile() console_logger = logging.getLogger('console') while True: + if send_string: + test.vm.console_socket.sendall(send_string.encode()) + send_string = None # send only once msg = console.readline().strip() if not msg: continue
@@ -79,6 +74,17 @@ def wait_for_console_pattern(test, success_message, failure_message=None): fail = 'Failure message found in console: %s' % failure_message test.fail(fail) +def wait_for_console_pattern(test, success_message, failure_message=None): + """ + Waits for messages to appear on the console, while logging the content + + :param test: an Avocado test containing a VM that will have its console + read and probed for a success or failure message + :type test: :class:`avocado_qemu.Test` + :param success_message: if this message appears, test succeeds + :param failure_message: if this message appears, test fails + """ + _console_interaction(test, success_message, failure_message, None) def exec_command_and_wait_for_pattern(test, command, success_message, failure_message=None):
@@ -94,10 +100,7 @@ def exec_command_and_wait_for_pattern(test, command, :param success_message: if this message appears, test succeeds :param failure_message: if this message appears, test fails """ - command += '\r' - test.vm.console_socket.sendall(command.encode()) - wait_for_console_pattern(test, success_message, failure_message) - + _console_interaction(test, success_message, failure_message, command + '\r') class Test(avocado.Test): def _get_unique_tag_val(self, tag_name):
Signature · 1 line
2.17.1
PATCH v4 18/20 Acceptance tests: Add interrupt_interactive_console_until_pattern()
In reply to Niek LinnenbankFrom: Philippe Mathieu-Daudé <[email protected]>
We need a function to interrupt interactive consoles.
Example: Interrupt U-Boot to set different environment values.
--- tests/acceptance/avocado_qemu/__init__.py | 32 +++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)
tests/acceptance/avocado_qemu/__init__.py +30 -2
@@ -56,13 +56,15 @@ def pick_default_qemu_bin(arch=None): def _console_interaction(test, success_message, failure_message, - send_string): + send_string, keep_sending=False): + assert not keep_sending or send_string console = test.vm.console_socket.makefile() console_logger = logging.getLogger('console') while True: if send_string: test.vm.console_socket.sendall(send_string.encode()) - send_string = None # send only once + if not keep_sending: + send_string = None # send only once msg = console.readline().strip() if not msg: continue
@@ -74,6 +76,32 @@ def _console_interaction(test, success_message, failure_message, fail = 'Failure message found in console: %s' % failure_message test.fail(fail) +def interrupt_interactive_console_until_pattern(test, success_message, + failure_message=None, + interrupt_string='\r'): + """ + Keep sending a string to interrupt a console prompt, while logging the + console output. Typical use case is to break a boot loader prompt, such: + + Press a key within 5 seconds to interrupt boot process. + 5 + 4 + 3 + 2 + 1 + Booting default image... + + :param test: an Avocado test containing a VM that will have its console + read and probed for a success or failure message + :type test: :class:`avocado_qemu.Test` + :param success_message: if this message appears, test succeeds + :param failure_message: if this message appears, test fails + :param interrupt_string: a string to send to the console before trying + to read a new line + """ + _console_interaction(test, success_message, failure_message, + interrupt_string, True) + def wait_for_console_pattern(test, success_message, failure_message=None): """ Waits for messages to appear on the console, while logging the content
Signature · 1 line
2.17.1
PATCH v4 19/20 tests/boot_linux_console: Test booting NetBSD via U-Boot on OrangePi PC
In reply to Niek LinnenbankFrom: Philippe Mathieu-Daudé <[email protected]>
This test boots U-Boot then NetBSD (stored on a SD card) on a OrangePi PC board.
As it requires ~1.3GB of storage, it is disabled by default.
U-Boot is built by the Debian project [1], and the SD card image is provided by the NetBSD organization [2].
Once the compressed SD card image is downloaded (304MB) and extracted, this test is fast:
$ AVOCADO_ALLOW_LARGE_STORAGE=yes \
avocado --show=app,console run -t machine:orangepi-pc \
tests/acceptance/boot_linux_console.py
console: U-Boot SPL 2020.01+dfsg-1 (Jan 08 2020 - 08:19:44 +0000)
console: DRAM: 1024 MiB
console: U-Boot 2020.01+dfsg-1 (Jan 08 2020 - 08:19:44 +0000) Allwinner Technology
console: CPU: Allwinner H3 (SUN8I 0000)
console: scanning bus usb@1c1b000 for devices... 1 USB Device(s) found
console: scanning bus usb@1c1d000 for devices... 1 USB Device(s) found
console: scanning usb for storage devices... 0 Storage Device(s) found
console: Hit any key to stop autoboot: 0
console: => setenv bootargs root=ld0a
console: => setenv kernel netbsd-GENERIC.ub
console: => setenv fdtfile dtb/sun8i-h3-orangepi-pc.dtb
console: => boot
console: ## Booting kernel from Legacy Image at 42000000 ...
console: Image Name: NetBSD/earmv7hf 9.0_RC1
console: Image Type: ARM Linux Kernel Image (no loading done) (uncompressed)
console: XIP Kernel Image (no loading done)
console: Loading Device Tree to 49ff6000, end 49fffe01 ... OK
console: Starting kernel ...
console: [ 1.0000000] NetBSD/evbarm (fdt) booting ...
console: [ 1.0000000] NetBSD 9.0_RC1 (GENERIC) #0: Wed Nov 27 16:14:52 UTC 2019
console: [ 1.0000000] simplebus0 at armfdt0: Xunlong Orange Pi PC
console: [ 1.0000000] cpu0 at cpus0: Cortex-A7 r0p5 (Cortex V7A core)
console: [ 1.0000000] cpu0: DC enabled IC enabled WB enabled LABT branch prediction enabled
console: [ 1.0000000] cpu0: 32KB/64B 2-way L1 VIPT Instruction cache
console: [ 1.0000000] cpu0: 32KB/64B 2-way write-back-locking-C L1 PIPT Data cache
console: [ 1.0000000] cpu0: 2304KB/64B 16-way write-through L2 PIPT Unified cache
console: [ 1.0000000] vfp0 at cpu0: NEON MPE (VFP 3.0+), rounding, NaN propagation, denormals
...
console: [ 2.8171937] sdmmc0: SD card status: 4-bit, C0
console: [ 2.8234040] ld0 at sdmmc0: <0xaa:0x5859:QEMU!:0x01:0xdeadbeef:0x062>
console: [ 2.8743967] ld0: 1290 MB, 655 cyl, 64 head, 63 sec, 512 bytes/sect x 2642944 sectors
console: [ 3.1588850] ld0: 4-bit width, High-Speed/SDR25, 50.000 MHz
console: [ 4.9942260] WARNING: 4 errors while detecting hardware; check system log.
console: [ 5.0142912] boot device: ld0
console: [ 5.0551260] root on ld0a dumps on ld0b
console: [ 5.2175484] root file system type: ffs
console: [ 5.2858559] kern.module.path=/stand/evbarm/9.0/modules
console: Tue Jan 18 18:15:15 UTC 2050
console: Starting root file system check:
PASS (35.96 s)
RESULTS : PASS 1 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB TIME : 36.09 sNote, this test only took ~65 seconds to run on Travis-CI, see: [3].
This test is based on a description from Niek Linnenbank from [4].
[1] https://wiki.debian.org/InstallingDebianOn/Allwinner#Creating_a_bootable_SD_Card_with_u-boot
[2] https://wiki.netbsd.org/ports/evbarm/allwinner/
[3] https://travis-ci.org/philmd/qemu/jobs/638823612#L3778
[4] https://www.mail-archive.com/[email protected]/msg669347.html
--- tests/acceptance/boot_linux_console.py | 63 ++++++++++++++++++++++++++ 1 file changed, 63 insertions(+)
tests/acceptance/boot_linux_console.py +63 -0
@@ -16,6 +16,7 @@ import shutil from avocado import skipUnless from avocado_qemu import Test from avocado_qemu import exec_command_and_wait_for_pattern +from avocado_qemu import interrupt_interactive_console_until_pattern from avocado_qemu import wait_for_console_pattern from avocado.utils import process from avocado.utils import archive
@@ -632,6 +633,68 @@ class BootLinuxConsole(Test): 'to <orangepipc>') self.wait_for_console_pattern('Starting Load Kernel Modules...') + @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited') + def test_arm_orangepi_uboot_netbsd9(self): + """ + :avocado: tags=arch:arm + :avocado: tags=machine:orangepi-pc + """ + # This test download a 304MB compressed image and expand it to 1.3GB... + deb_url = ('http://snapshot.debian.org/archive/debian/' + '20200108T145233Z/pool/main/u/u-boot/' + 'u-boot-sunxi_2020.01%2Bdfsg-1_armhf.deb') + deb_hash = 'f67f404a80753ca3d1258f13e38f2b060e13db99' + deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) + # We use the common OrangePi PC 'plus' build of U-Boot for our secondary + # program loader (SPL). We will then set the path to the more specific + # OrangePi "PC" device tree blob with 'setenv fdtfile' in U-Boot prompt, + # before to boot NetBSD. + uboot_path = '/usr/lib/u-boot/orangepi_plus/u-boot-sunxi-with-spl.bin' + uboot_path = self.extract_from_deb(deb_path, uboot_path) + image_url = ('https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.0_RC1/' + 'evbarm-earmv7hf/binary/gzimg/armv7.img.gz') + image_hash = '7f58d5c36600430a8bcebe7e999a8945a2be4d1f' + image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash) + image_path = os.path.join(self.workdir, 'armv7.img') + image_drive_args = 'if=sd,format=raw,snapshot=on,file=' + image_path + archive.gzip_uncompress(image_path_gz, image_path) + + # dd if=u-boot-sunxi-with-spl.bin of=armv7.img bs=1K seek=8 conv=notrunc + with open(uboot_path, 'rb') as f_in: + with open(image_path, 'r+b') as f_out: + f_out.seek(8 * 1024) + shutil.copyfileobj(f_in, f_out) + + self.vm.set_console() + self.vm.add_args('-nic', 'user', + '-drive', image_drive_args, + '-no-reboot') + self.vm.launch() + wait_for_console_pattern(self, 'U-Boot 2020.01+dfsg-1') + interrupt_interactive_console_until_pattern(self, + 'Hit any key to stop autoboot:', + 'switch to partitions #0, OK') + + exec_command_and_wait_for_pattern(self, '', '=>') + cmd = 'setenv bootargs root=ld0a' + exec_command_and_wait_for_pattern(self, cmd, '=>') + cmd = 'setenv kernel netbsd-GENERIC.ub' + exec_command_and_wait_for_pattern(self, cmd, '=>') + cmd = 'setenv fdtfile dtb/sun8i-h3-orangepi-pc.dtb' + exec_command_and_wait_for_pattern(self, cmd, '=>') + cmd = ("setenv bootcmd 'fatload mmc 0:1 ${kernel_addr_r} ${kernel}; " + "fatload mmc 0:1 ${fdt_addr_r} ${fdtfile}; " + "fdt addr ${fdt_addr_r}; " + "bootm ${kernel_addr_r} - ${fdt_addr_r}'") + exec_command_and_wait_for_pattern(self, cmd, '=>') + + exec_command_and_wait_for_pattern(self, 'boot', + 'Booting kernel from Legacy Image') + wait_for_console_pattern(self, 'Starting kernel ...') + wait_for_console_pattern(self, 'NetBSD 9.0_RC1 (GENERIC)') + # Wait for user-space + wait_for_console_pattern(self, 'Starting root file system check') + def test_s390x_s390_ccw_virtio(self): """ :avocado: tags=arch:s390x
Signature · 1 line
2.17.1
PATCH v4 20/20 docs: add Orange Pi PC document
In reply to Niek LinnenbankThe Xunlong Orange Pi PC machine is a functional ARM machine based on the Allwinner H3 System-on-Chip. It supports mainline Linux, U-Boot, NetBSD and is covered by acceptance tests.
This commit adds a documentation text file with a description of the machine and instructions for the user.
--- docs/orangepi.rst | 199 ++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 200 insertions(+) create mode 100644 docs/orangepi.rst
docs/orangepi.rst new file +199 -0
@@ -0,0 +1,199 @@ +========================= +Orange Pi PC Machine Type +========================= + +The Xunlong Orange Pi PC is an Allwinner H3 System on Chip +based embedded computer with mainline support in both U-Boot +and Linux. The board comes with a Quad Core Cortex A7 @ 1.3GHz, +1GiB RAM, 100Mbit ethernet, USB, SD/MMC, USB, HDMI and +various other I/O. + +Supported devices +----------------- + +The Orange Pi PC machine supports the following devices: + + * SMP (Quad Core Cortex A7) + * Generic Interrupt Controller configuration + * SRAM mappings + * SDRAM controller + * Real Time Clock + * Timer device (re-used from Allwinner A10) + * UART + * SD/MMC storage controller + * EMAC ethernet + * USB 2.0 interfaces + * Clock Control Unit + * System Control module + * Security Identifier device + +Limitations +----------- + +Currently, Orange Pi PC does *not* support the following features: + +- Graphical output via HDMI, GPU and/or the Display Engine +- Audio output +- Hardware Watchdog + +Also see the 'unimplemented' array in the Allwinner H3 SoC module +for a complete list of unimplemented I/O devices: + ./hw/arm/allwinner-h3.c + +Using the Orange Pi PC machine type +----------------------------------- + +Boot options +~~~~~~~~~~~~ + +The Orange Pi PC machine can start using the standard -kernel functionality +for loading a Linux kernel or ELF executable. Additionally, the Orange Pi PC +machine can also emulate the BootROM which is present on an actual Allwinner H3 +based SoC, which loads the bootloader from a SD card, specified via the -sd argument +to qemu-system-arm. + +Running mainline Linux +~~~~~~~~~~~~~~~~~~~~~~ + +Mainline Linux kernels from 4.19 up to latest master are known to work. +To build a Linux mainline kernel that can be booted by the Orange Pi PC machine, +simply configure the kernel using the sunxi_defconfig configuration: + + $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make mrproper + $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make sunxi_defconfig + +To be able to use USB storage, you need to manually enable the corresponding +configuration item. Start the kconfig configuration tool: + + $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make menuconfig + +Navigate to the following item, enable it and save your configuration: + + Device Drivers > USB support > USB Mass Storage support + +Build the Linux kernel with: + + $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make + +To boot the newly build linux kernel in QEMU with the Orange Pi PC machine, use: + + $ qemu-system-arm -M orangepi-pc -nic user -nographic \ + -kernel /path/to/linux/arch/arm/boot/zImage \ + -append 'console=ttyS0,115200' \ + -dtb /path/to/linux/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dtb + +Orange Pi PC images +~~~~~~~~~~~~~~~~~~~ + +Note that the mainline kernel does not have a root filesystem. You may provide it +with an official Orange Pi PC image from the official website: + + http://www.orangepi.org/downloadresources/ + +Another possibility is to run an Armbian image for Orange Pi PC which +can be downloaded from: + + https://www.armbian.com/orange-pi-pc/ + +Alternatively, you can also choose to build you own image with buildroot +using the orangepi_pc_defconfig. Also see https://buildroot.org for more information. + +You can choose to attach the selected image either as an SD card or as USB mass storage. +For example, to boot using the Orange Pi PC Debian image on SD card, simply add the -sd +argument and provide the proper root= kernel parameter: + + $ qemu-system-arm -M orangepi-pc -nic user -nographic \ + -kernel /path/to/linux/arch/arm/boot/zImage \ + -append 'console=ttyS0,115200 root=/dev/mmcblk0p2' \ + -dtb /path/to/linux/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dtb \ + -sd OrangePi_pc_debian_stretch_server_linux5.3.5_v1.0.img + +To attach the image as an USB mass storage device to the machine, +simply append to the command: + + -drive if=none,id=stick,file=myimage.img \ + -device usb-storage,bus=usb-bus.0,drive=stick + +Instead of providing a custom Linux kernel via the -kernel command you may also +choose to let the Orange Pi PC machine load the bootloader from SD card, just like +a real board would do using the BootROM. Simply pass the selected image via the -sd +argument and remove the -kernel, -append, -dbt and -initrd arguments: + + $ qemu-system-arm -M orangepi-pc -nic user -nographic \ + -sd Armbian_19.11.3_Orangepipc_buster_current_5.3.9.img + +Note that both the official Orange Pi PC images and Armbian images start +a lot of userland programs via systemd. Depending on the host hardware and OS, +they may be slow to emulate, especially due to emulating the 4 cores. +To help reduce the performance slow down due to emulating the 4 cores, you can +give the following kernel parameters (or via -append): + + => setenv extraargs 'systemd.default_timeout_start_sec=9000 loglevel=7 nosmp console=ttyS0,115200' + +Running U-Boot +~~~~~~~~~~~~~~ + +U-Boot mainline can be build and configured using the orangepi_pc_defconfig +using similar commands as describe above for Linux. Note that it is recommended +for development/testing to select the following configuration setting in U-Boot: + + Device Tree Control > Provider for DTB for DT Control > Embedded DTB + +To start U-Boot using the Orange Pi PC machine, provide the +u-boot binary to the -kernel argument: + + $ qemu-system-arm -M orangepi-pc -nic user -nographic \ + -kernel /path/to/uboot/u-boot -sd disk.img + +Use the following U-boot commands to load and boot a Linux kernel from SD card: + + -> setenv bootargs console=ttyS0,115200 + -> ext2load mmc 0 0x42000000 zImage + -> ext2load mmc 0 0x43000000 sun8i-h3-orangepi-pc.dtb + -> bootz 0x42000000 - 0x43000000 + +Running NetBSD +~~~~~~~~~~~~~~ + +The NetBSD operating system also includes support for Allwinner H3 based boards, +including the Orange Pi PC. NetBSD 9.0 is known to work best for the Orange Pi PC +board and provides a fully working system with serial console, networking and storage. + +Currently NetBSD 9.0 is in testing, but release candidate 1 can be started +successfully on the Orange Pi PC machine. Get the 'evbarm-earmv7hf' based image from: + + https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.0_RC1/evbarm-earmv7hf/binary/gzimg/armv7.img.gz + +The image requires manually installing U-Boot in the image. Build U-Boot with +the orangepi_pc_defconfig configuration as described in the previous section. +Next, unzip the NetBSD image and write the U-Boot binary including SPL using: + + $ gunzip armv7.img.gz + $ dd if=/path/to/u-boot-sunxi-with-spl.bin of=armv7.img bs=1024 seek=8 conv=notrunc + +Start the machine using the following command: + + $ qemu-system-arm -M orangepi-pc -nic user -nographic \ + -sd armv7.img + +At the U-Boot stage, interrupt the automatic boot process by pressing a key +and set the following environment variables before booting: + + => setenv bootargs root=ld0a + => setenv kernel netbsd-GENERIC.ub + => setenv fdtfile dtb/sun8i-h3-orangepi-pc.dtb + => setenv bootcmd 'fatload mmc 0:1 ${kernel_addr_r} ${kernel}; fatload mmc 0:1 ${fdt_addr_r} ${fdtfile}; fdt addr ${fdt_addr_r}; bootm ${kernel_addr_r} - ${fdt_addr_r}' + +Optionally you may save the environment variables to SD card with 'saveenv'. +To continue booting simply give the 'boot' command and NetBSD boots. + +Orange Pi PC acceptance tests +----------------------------- + +The Orange Pi PC machine has several acceptance tests included. +To run the whole set of tests, build QEMU from source and simply +provide the following command: + + $ AVOCADO_ALLOW_LARGE_STORAGE=yes avocado --show=app,console run \ + -t machine:orangepi-pc tests/acceptance/boot_linux_console.py +
MAINTAINERS +1 -0
@@ -488,6 +488,7 @@ S: Maintained F: hw/*/allwinner-h3* F: include/hw/*/allwinner-h3* F: hw/arm/orangepi.c +F: docs/orangepi.rst ARM PrimeCell and CMSDK devices M: Peter Maydell <[email protected]>
Signature · 1 line
2.17.1
Quoted 25 lines · On Sun, Jan 19, 2020, 01:51 Niek Linnenbank <[email protected]> wrote:
Dear QEMU developers,
Hereby I would like to contribute the following set of patches to QEMU which add support for the Allwinner H3 System on Chip and the Orange Pi PC machine. The following features and devices are supported:
* SMP (Quad Core Cortex A7)
* Generic Interrupt Controller configuration
* SRAM mappings
* SDRAM controller
* Real Time Clock
* Timer device (re-used from Allwinner A10)
* UART
* SD/MMC storage controller
* EMAC ethernet connectivity
* USB 2.0 interfaces
* Clock Control Unit
* System Control module
* Security Identifier deviceFunctionality related to graphical output such as HDMI, GPU, Display Engine and audio are not included. Recently released mainline Linux kernels (4.19 up to latest master), mainline U-Boot and NetBSD 9.0-RC1 are known to work.
Quoted 6 lines
For full details on how to use the Orange Pi PC machine, see the file
docs/orangepi.rstwhich is included as a patch in this series.The contents of this patch series is available on Github at:
I forgot to update this link in the cover letter to v4. The correct link is:
https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v4
Quoted 162 lines
The followings are currently known issues in this series:
- NetBSD 9.0-RC1 reads out year 2050 from RTC, while Linux works fine
-> This is due to difference in base year defined by thecorresponding drivers
- RTC date & time is not persistent
- boot0 custom Allwinner bootloader not yet working
- Watchdog not yet implemented, affects U-Boot 'reset' and
shutdown/reboot-> This is part of the existing A10 timer that needs to begeneralized first
Looking forward to your review comments. I will do my best to update the patches where needed.
===== CHANGELOG =====
v4:
*docs/orangepi.rst: correct SDRAM size in board description: 512MB ->
1GiB
*hw/arm/orangepi.c: correct SDRAM size in commit message: 512MB -> 1GiB
*hw/arm/orangepi.c: set .nb_cpus in theorangepi_binfostruct static
initialisation
*hw/arm/orangepi.c: remove .board_id fromorangepi_binfostruct
*hw/arm/orangepi.c: move BIOS check to top oforangepi_init()
*hw/arm/orangepi.c: change clk1-freq argument 24000000 to 24 * 1000 *
1000 for readability
*hw/arm/orangepi.c: rephrase 1GiB check error message
*include/hw/arm/allwinner-h3.h: improved comments
*hw/arm/allwinner-h3.c: remove duplicate initialization and declaration
of i variable
*hw/arm/allwinner-h3.c: useDEVICE(&s->cpus[i])instead ofqemu_get_cpu()
*hw/arm/allwinner-h3.c: use qdev API instead of object API in CPU
initialization part
*hw/arm/allwinner-h3.c: add note that UARTs are connected toAPB2_CLK,
for future clocktree API
*hw/arm/allwinner-h3.c: extend commit message for Boot ROM with
description for the 32KiB size
*hw/rtc/allwinner-rtc.c: correct usage ofAwRtcClass->regmap_sizefor
checking r/w offset
*hw/misc/allwinner-cpucfg.c: remove 64-bit counter, as it is unused by
Linux/U-Boot/NetBSD
*hw/misc/allwinner-cpucfg.c: addCPU_EXCEPTION_LEVEL_ON_RESETconstant
*hw/misc/allwinner-cpucfg.c: break instead of return after logging guest
error, for tracing
*hw/misc/allwinner-cpucfg.c: reduce duplication in switch/case forREG_CPUX_RST_CTRLin write function
*include/hw/rtc/allwinner-rtc.h: increaseAW_RTC_REGS_MAXADDRto0x200
*include/hw/rtc/allwinner-rtc.h: change type ofAwRtcClass->year_offset
to int, to match struct tm
*tests/acceptance/boot_linux_console.py: remove calls tovm.set_machine()
*tests/acceptance/boot_linux_console.py: added NetBSD test by Philippe
*docs/orangepi.rst: removed some unneeded words/typos
*docs/orangepi.rst: remove usage of -j5 for calling make (not all users
have >= 4 SMP cores)
*include/hw/*/allwinner*.h: moved #include "qemu/osdep.h" and unneeded
#includes to .c filev3: https://lists.gnu.org/archive/html/qemu-devel/2020-01/msg01534.html
https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v3v2: https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg03265.html
https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v2v1: https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg00320.html
https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v1With kind regards,
Niek Linnenbank
Niek Linnenbank (13):
hw/arm: add Allwinner H3 System-on-Chip hw/arm: add Xunlong Orange Pi PC machine hw/arm/allwinner-h3: add Clock Control Unit hw/arm/allwinner-h3: add USB host controller hw/arm/allwinner-h3: add System Control module hw/arm/allwinner: add CPU Configuration module hw/arm/allwinner: add Security Identifier device hw/arm/allwinner: add SD/MMC host controller hw/arm/allwinner-h3: add EMAC ethernet device hw/arm/allwinner-h3: add Boot ROM support hw/arm/allwinner-h3: add SDRAM controller device hw/arm/allwinner: add RTC device support
docs: add Orange Pi PC documentPhilippe Mathieu-Daudé (7):
tests/boot_linux_console: Add a quick test for the OrangePi PC board tests/boot_linux_console: Add initrd test for the Orange Pi PC board tests/boot_linux_console: Add a SD card test for the OrangePi PC board tests/boot_linux_console: Add a SLOW test booting Ubuntu on OrangePi
PC
Acceptance tests: Extract_console_interaction()Acceptance tests: Addinterrupt_interactive_console_until_pattern()tests/boot_linux_console: Test booting NetBSD via U-Boot on OrangePi
PCdocs/orangepi.rst | 199 +++++ default-configs/arm-softmmu.mak | 1 + hw/usb/hcd-ehci.h | 1 + include/hw/arm/allwinner-a10.h | 4 + include/hw/arm/allwinner-h3.h | 163 ++++ include/hw/misc/allwinner-cpucfg.h | 52 ++ include/hw/misc/allwinner-h3-ccu.h | 66 ++ include/hw/misc/allwinner-h3-dramc.h | 106 +++ include/hw/misc/allwinner-h3-sysctrl.h | 67 ++ include/hw/misc/allwinner-sid.h | 60 ++ include/hw/net/allwinner-sun8i-emac.h | 99 +++ include/hw/rtc/allwinner-rtc.h | 128 ++++ include/hw/sd/allwinner-sdhost.h | 135 ++++ hw/arm/allwinner-a10.c | 19 + hw/arm/allwinner-h3.c | 476 ++++++++++++ hw/arm/cubieboard.c | 15 + hw/arm/orangepi.c | 127 ++++ hw/misc/allwinner-cpucfg.c | 269 +++++++ hw/misc/allwinner-h3-ccu.c | 243 ++++++ hw/misc/allwinner-h3-dramc.c | 358 +++++++++ hw/misc/allwinner-h3-sysctrl.c | 140 ++++ hw/misc/allwinner-sid.c | 170 +++++ hw/net/allwinner-sun8i-emac.c | 871 ++++++++++++++++++++++ hw/rtc/allwinner-rtc.c | 386 ++++++++++ hw/sd/allwinner-sdhost.c | 848 +++++++++++++++++++++ hw/usb/hcd-ehci-sysbus.c | 17 + MAINTAINERS | 9 + hw/arm/Kconfig | 9 + hw/arm/Makefile.objs | 1 + hw/misc/Makefile.objs | 5 + hw/misc/trace-events | 19 + hw/net/Kconfig | 3 + hw/net/Makefile.objs | 1 + hw/net/trace-events | 10 + hw/rtc/Makefile.objs | 1 + hw/rtc/trace-events | 4 + hw/sd/Makefile.objs | 1 + hw/sd/trace-events | 7 + tests/acceptance/avocado_qemu/__init__.py | 59 +- tests/acceptance/boot_linux_console.py | 210 ++++++ 40 files changed, 5345 insertions(+), 14 deletions(-) create mode 100644 docs/orangepi.rst create mode 100644 include/hw/arm/allwinner-h3.h create mode 100644 include/hw/misc/allwinner-cpucfg.h create mode 100644 include/hw/misc/allwinner-h3-ccu.h create mode 100644 include/hw/misc/allwinner-h3-dramc.h create mode 100644 include/hw/misc/allwinner-h3-sysctrl.h create mode 100644 include/hw/misc/allwinner-sid.h create mode 100644 include/hw/net/allwinner-sun8i-emac.h create mode 100644 include/hw/rtc/allwinner-rtc.h create mode 100644 include/hw/sd/allwinner-sdhost.h create mode 100644 hw/arm/allwinner-h3.c create mode 100644 hw/arm/orangepi.c create mode 100644 hw/misc/allwinner-cpucfg.c create mode 100644 hw/misc/allwinner-h3-ccu.c create mode 100644 hw/misc/allwinner-h3-dramc.c create mode 100644 hw/misc/allwinner-h3-sysctrl.c create mode 100644 hw/misc/allwinner-sid.c create mode 100644 hw/net/allwinner-sun8i-emac.c create mode 100644 hw/rtc/allwinner-rtc.c create mode 100644 hw/sd/allwinner-sdhost.c--
2.17.1
Hi all,
Short status update regarding this series.
Currently I am debugging booting NetBSD 9.0-RC2, which is recently released
[1]
The problem is that, apparently, RC2 can't mount the rootfs properly:
[ 3.1871510] vfs_mountroot: can't open root device [ 3.2141370] cannot mount root, error = 6
This only happens using the RC2 filesystem image. However, the RC2 kernel can
properly load & boot the RC1 filesystem image, and the RC1 kernel gives the same error
on the RC2 filesystem. But I dont think its a NetBSD-RC2 issue, because on a real
Orange Pi PC hardware board, this problem does not show.
I'm comparing traces and adding more low-level debug output to NetBSD and QEMU to find the issue.
Also I processed the review remarks which were send so far.
Kind regards,
Niek
[1] https://www.netbsd.org/releases/formal-9/NetBSD-9.0.html
Quoted 193 lines · Niek Linnenbank
Dear QEMU developers,
Hereby I would like to contribute the following set of patches to QEMU which add support for the Allwinner H3 System on Chip and the Orange Pi PC machine. The following features and devices are supported:
* SMP (Quad Core Cortex A7)
* Generic Interrupt Controller configuration
* SRAM mappings
* SDRAM controller
* Real Time Clock
* Timer device (re-used from Allwinner A10)
* UART
* SD/MMC storage controller
* EMAC ethernet connectivity
* USB 2.0 interfaces
* Clock Control Unit
* System Control module
* Security Identifier deviceFunctionality related to graphical output such as HDMI, GPU, Display Engine and audio are not included. Recently released mainline Linux kernels (4.19 up to latest master), mainline U-Boot and NetBSD 9.0-RC1 are known to work.
For full details on how to use the Orange Pi PC machine, see the file
docs/orangepi.rstwhich is included as a patch in this series.The contents of this patch series is available on Github at:
https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v3
The followings are currently known issues in this series:
- NetBSD 9.0-RC1 reads out year 2050 from RTC, while Linux works fine
-> This is due to difference in base year defined by thecorresponding drivers
- RTC date & time is not persistent
- boot0 custom Allwinner bootloader not yet working
- Watchdog not yet implemented, affects U-Boot 'reset' and
shutdown/reboot-> This is part of the existing A10 timer that needs to begeneralized first
Looking forward to your review comments. I will do my best to update the patches where needed.
===== CHANGELOG =====
v4:
*docs/orangepi.rst: correct SDRAM size in board description: 512MB ->
1GiB
*hw/arm/orangepi.c: correct SDRAM size in commit message: 512MB -> 1GiB
*hw/arm/orangepi.c: set .nb_cpus in theorangepi_binfostruct static
initialisation
*hw/arm/orangepi.c: remove .board_id fromorangepi_binfostruct
*hw/arm/orangepi.c: move BIOS check to top oforangepi_init()
*hw/arm/orangepi.c: change clk1-freq argument 24000000 to 24 * 1000 *
1000 for readability
*hw/arm/orangepi.c: rephrase 1GiB check error message
*include/hw/arm/allwinner-h3.h: improved comments
*hw/arm/allwinner-h3.c: remove duplicate initialization and declaration
of i variable
*hw/arm/allwinner-h3.c: useDEVICE(&s->cpus[i])instead ofqemu_get_cpu()
*hw/arm/allwinner-h3.c: use qdev API instead of object API in CPU
initialization part
*hw/arm/allwinner-h3.c: add note that UARTs are connected toAPB2_CLK,
for future clocktree API
*hw/arm/allwinner-h3.c: extend commit message for Boot ROM with
description for the 32KiB size
*hw/rtc/allwinner-rtc.c: correct usage ofAwRtcClass->regmap_sizefor
checking r/w offset
*hw/misc/allwinner-cpucfg.c: remove 64-bit counter, as it is unused by
Linux/U-Boot/NetBSD
*hw/misc/allwinner-cpucfg.c: addCPU_EXCEPTION_LEVEL_ON_RESETconstant
*hw/misc/allwinner-cpucfg.c: break instead of return after logging guest
error, for tracing
*hw/misc/allwinner-cpucfg.c: reduce duplication in switch/case forREG_CPUX_RST_CTRLin write function
*include/hw/rtc/allwinner-rtc.h: increaseAW_RTC_REGS_MAXADDRto0x200
*include/hw/rtc/allwinner-rtc.h: change type ofAwRtcClass->year_offset
to int, to match struct tm
*tests/acceptance/boot_linux_console.py: remove calls tovm.set_machine()
*tests/acceptance/boot_linux_console.py: added NetBSD test by Philippe
*docs/orangepi.rst: removed some unneeded words/typos
*docs/orangepi.rst: remove usage of -j5 for calling make (not all users
have >= 4 SMP cores)
*include/hw/*/allwinner*.h: moved #include "qemu/osdep.h" and unneeded
#includes to .c filev3: https://lists.gnu.org/archive/html/qemu-devel/2020-01/msg01534.html
https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v3v2: https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg03265.html
https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v2v1: https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg00320.html
https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v1With kind regards,
Niek Linnenbank
Niek Linnenbank (13):
hw/arm: add Allwinner H3 System-on-Chip hw/arm: add Xunlong Orange Pi PC machine hw/arm/allwinner-h3: add Clock Control Unit hw/arm/allwinner-h3: add USB host controller hw/arm/allwinner-h3: add System Control module hw/arm/allwinner: add CPU Configuration module hw/arm/allwinner: add Security Identifier device hw/arm/allwinner: add SD/MMC host controller hw/arm/allwinner-h3: add EMAC ethernet device hw/arm/allwinner-h3: add Boot ROM support hw/arm/allwinner-h3: add SDRAM controller device hw/arm/allwinner: add RTC device support
docs: add Orange Pi PC documentPhilippe Mathieu-Daudé (7):
tests/boot_linux_console: Add a quick test for the OrangePi PC board tests/boot_linux_console: Add initrd test for the Orange Pi PC board tests/boot_linux_console: Add a SD card test for the OrangePi PC board tests/boot_linux_console: Add a SLOW test booting Ubuntu on OrangePi
PC
Acceptance tests: Extract_console_interaction()Acceptance tests: Addinterrupt_interactive_console_until_pattern()tests/boot_linux_console: Test booting NetBSD via U-Boot on OrangePi
PCdocs/orangepi.rst | 199 +++++ default-configs/arm-softmmu.mak | 1 + hw/usb/hcd-ehci.h | 1 + include/hw/arm/allwinner-a10.h | 4 + include/hw/arm/allwinner-h3.h | 163 ++++ include/hw/misc/allwinner-cpucfg.h | 52 ++ include/hw/misc/allwinner-h3-ccu.h | 66 ++ include/hw/misc/allwinner-h3-dramc.h | 106 +++ include/hw/misc/allwinner-h3-sysctrl.h | 67 ++ include/hw/misc/allwinner-sid.h | 60 ++ include/hw/net/allwinner-sun8i-emac.h | 99 +++ include/hw/rtc/allwinner-rtc.h | 128 ++++ include/hw/sd/allwinner-sdhost.h | 135 ++++ hw/arm/allwinner-a10.c | 19 + hw/arm/allwinner-h3.c | 476 ++++++++++++ hw/arm/cubieboard.c | 15 + hw/arm/orangepi.c | 127 ++++ hw/misc/allwinner-cpucfg.c | 269 +++++++ hw/misc/allwinner-h3-ccu.c | 243 ++++++ hw/misc/allwinner-h3-dramc.c | 358 +++++++++ hw/misc/allwinner-h3-sysctrl.c | 140 ++++ hw/misc/allwinner-sid.c | 170 +++++ hw/net/allwinner-sun8i-emac.c | 871 ++++++++++++++++++++++ hw/rtc/allwinner-rtc.c | 386 ++++++++++ hw/sd/allwinner-sdhost.c | 848 +++++++++++++++++++++ hw/usb/hcd-ehci-sysbus.c | 17 + MAINTAINERS | 9 + hw/arm/Kconfig | 9 + hw/arm/Makefile.objs | 1 + hw/misc/Makefile.objs | 5 + hw/misc/trace-events | 19 + hw/net/Kconfig | 3 + hw/net/Makefile.objs | 1 + hw/net/trace-events | 10 + hw/rtc/Makefile.objs | 1 + hw/rtc/trace-events | 4 + hw/sd/Makefile.objs | 1 + hw/sd/trace-events | 7 + tests/acceptance/avocado_qemu/__init__.py | 59 +- tests/acceptance/boot_linux_console.py | 210 ++++++ 40 files changed, 5345 insertions(+), 14 deletions(-) create mode 100644 docs/orangepi.rst create mode 100644 include/hw/arm/allwinner-h3.h create mode 100644 include/hw/misc/allwinner-cpucfg.h create mode 100644 include/hw/misc/allwinner-h3-ccu.h create mode 100644 include/hw/misc/allwinner-h3-dramc.h create mode 100644 include/hw/misc/allwinner-h3-sysctrl.h create mode 100644 include/hw/misc/allwinner-sid.h create mode 100644 include/hw/net/allwinner-sun8i-emac.h create mode 100644 include/hw/rtc/allwinner-rtc.h create mode 100644 include/hw/sd/allwinner-sdhost.h create mode 100644 hw/arm/allwinner-h3.c create mode 100644 hw/arm/orangepi.c create mode 100644 hw/misc/allwinner-cpucfg.c create mode 100644 hw/misc/allwinner-h3-ccu.c create mode 100644 hw/misc/allwinner-h3-dramc.c create mode 100644 hw/misc/allwinner-h3-sysctrl.c create mode 100644 hw/misc/allwinner-sid.c create mode 100644 hw/net/allwinner-sun8i-emac.c create mode 100644 hw/rtc/allwinner-rtc.c create mode 100644 hw/sd/allwinner-sdhost.c--
2.17.1
Signature · 1 line
Niek Linnenbank
Quoted 7 lines · Niek Linnenbank
Hi all,
Short status update regarding this series.
Currently I am debugging booting NetBSD 9.0-RC2, which is recently released [1] The problem is that, apparently, RC2 can't mount the rootfs properly:
Quoted 7 lines
[ 3.1871510]
vfs_mountroot: can't open root device [ 3.2141370] cannot mount root, error = 6This only happens using the RC2 filesystem image. However, the RC2 kernel can properly load & boot the RC1 filesystem image, and the RC1 kernel gives the same error on the RC2 filesystem. But I dont think its a NetBSD-RC2 issue, because on a real Orange Pi PC hardware board, this problem does not show.
Linux shows:
console: mmc0: Problem switching card into high-speed mode!
QEMU MMC support is not in good shape, and high-speed SD card support is limited. I keep procrastinating at reviewing your SDHCI patch hmmmmm.
So you added:
* DMA transfers
* Direct FIFO I/O
* Short/Long format command responses
I'd start diffing the trace output of the following events:
allwinner_sdhost*
sdcard*
with both kernels.
Quoted 9 lines
I'm comparing traces and adding more low-level debug output to NetBSD and QEMU to find the issue.
Also I processed the review remarks which were send so far.
Kind regards,
Niek[1] https://www.netbsd.org/releases/formal-9/NetBSD-9.0.html
Hi Philippe,
Quoted 32 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Niek Linnenbank
Hi all,
Short status update regarding this series.
Currently I am debugging booting NetBSD 9.0-RC2, which is recently released [1]
The problem is that, apparently, RC2 can't mount the rootfs properly:[ 3.1871510] vfs_mountroot: can't open root device [ 3.2141370] cannot mount root, error = 6Quoted 7 lines
This only happens using the RC2 filesystem image. However, the RC2 kernel can
properly load & boot the RC1 filesystem image, and the RC1 kernel gives the same error
on the RC2 filesystem. But I dont think its a NetBSD-RC2 issue, because on a real
Orange Pi PC hardware board, this problem does not show.Linux shows:
console: mmc0: Problem switching card into high-speed mode!QEMU MMC support is not in good shape, and high-speed SD card support is limited. I keep procrastinating at reviewing your SDHCI patch hmmmmm.
So you added:
* DMA transfers
* Direct FIFO I/O
* Short/Long format command responses
Quoted 8 lines
I'd start diffing the trace output of the following events:
allwinner_sdhost*
sdcard*with both kernels.
Thanks for the kind suggestions Philippe.
Indeed, comparing the trace files of both the RC1 and RC2 kernels is one of the things I did, and many more.
After extensive low-level debugging, I discovered that the issue is much more simple than I thought.
In particular, when using -sd <file>, the emulated device gets the same physical size as the file.
Normally this is not a problem, but for the NetBSD RC2 image, the kernel reads the MBR partition table,
compares it with the device size and concludes that the NetBSD partition in the image is larger than the actual device.
Unfortunately, this root cause is not printed on the NetBSD console, only the final 'can't open root device' message.
Also, when running on hardware, obviously the SD card will be larger, e.g. 4GB or more, so that is why this issue does not show.
So the fix is to extend the input image by a few megabytes before booting it.
And on the positive side, with this search we now have more confidence that the
emulated SD/MMC device in Qemu works as expected.
Kind regards,
Niek
Quoted 12 lines
Quoted 10 lines
I'm comparing traces and adding more low-level debug output to NetBSD and QEMU to find the issue.
Also I processed the review remarks which were send so far.
Kind regards,
Niek[1] https://www.netbsd.org/releases/formal-9/NetBSD-9.0.html
Signature · 1 line
Niek Linnenbank
Quoted 54 lines · Niek Linnenbank
Hi Philippe,
On Wed, Feb 12, 2020 at 11:12 PM Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:
On 2/12/20 10:47 PM, Niek Linnenbank wrote:
> Hi all,
>
> Short status update regarding this series.
>
> Currently I am debugging booting NetBSD 9.0-RC2, which is recently > released [1]
> The problem is that, apparently, RC2 can't mount the rootfs properly:
>
> [ 3.1871510]vfs_mountroot: can't open root device
> [ 3.2141370] cannot mount root, error = 6
>
> This only happens using the RC2 filesystem image. However, the RC2 > kernel can
> properly load & boot the RC1 filesystem image, and the RC1 kernel
gives
> the same error
> on the RC2 filesystem. But I dont think its a NetBSD-RC2 issue,
because
> on a real
> Orange Pi PC hardware board, this problem does not show.Linux shows:
console: mmc0: Problem switching card into high-speed mode!QEMU MMC support is not in good shape, and high-speed SD card support is
limited. I keep procrastinating at reviewing your SDHCI patch hmmmmm.So you added:
* DMA transfers
* Direct FIFO I/O
* Short/Long format command responsesI'd start diffing the trace output of the following events:
allwinner_sdhost*
sdcard*with both kernels.
Thanks for the kind suggestions Philippe.
Indeed, comparing the trace files of both the RC1 and RC2 kernels is one of the things I did, and many more.After extensive low-level debugging, I discovered that the issue is much more simple than I thought. In particular, when using -sd <file>, the emulated device gets the same physical size as the file. Normally this is not a problem, but for the NetBSD RC2 image, the kernel reads the MBR partition table, compares it with the device size and concludes that the NetBSD partition in the image is larger than the actual device.
Quoted 6 lines
Unfortunately, this root cause is not printed on the NetBSD console, only the final 'can't open root device' message. Also, when running on hardware, obviously the SD card will be larger, e.g. 4GB or more, so that is why this issue does not show.
So the fix is to extend the input image by a few megabytes before booting it. And on the positive side, with this search we now have more confidence that the emulated SD/MMC device in Qemu works as expected.
Good news!
IIRC from the specs, cards are block devices and the only alignment required is the size of a block (512KiB for your 4GiB card).
That said I never saw a card not pow2 aligned, but the card firmware should be able to discard blocks and announce fewer. Maybe FreeBSD is incorrect assuming a pow2 alignment?
Quoted 21 lines
Kind regards,
Niek> > I'm comparing traces and adding more low-level debug output to NetBSD > and QEMU to find the issue. > > Also I processed the review remarks which were send so far. > > Kind regards, > Niek > > [1] https://www.netbsd.org/releases/formal-9/NetBSD-9.0.htmlSignature · 1 line
Niek Linnenbank
Quoted 2 lines · Philippe Mathieu-Daudé
IIRC from the specs, cards are block devices and the only alignment required is the size of a block (512KiB for your 4GiB card).
Isn't there something related to erase blocks too, which impose a larger granularity than just a single block?
Anyway, in general the backing image for an SD card device needs to be exactly the size of the SD card you're emulating, because QEMU needs somewhere it can write back the data if the guest decides to write to the last block on the card. So short-length images generally don't work (true for all block devices, not just SD cards, I think). This often bites users if they're using some distro "here's a disk/sd card image file" where the expected use with real hardware is "dd the image file onto the SD card".
thanks
-- PMM
Hi Peter & Philippe,
Quoted 8 lines · Peter Maydell
Quoted 2 lines · Philippe Mathieu-Daudé
IIRC from the specs, cards are block devices and the only alignment required is the size of a block (512KiB for your 4GiB card).
Isn't there something related to erase blocks too, which impose a larger granularity than just a single block?
Quoted 10 lines
Anyway, in general the backing image for an SD card device needs to be exactly the size of the SD card you're emulating, because QEMU needs somewhere it can write back the data if the guest decides to write to the last block on the card. So short-length images generally don't work (true for all block devices, not just SD cards, I think). This often bites users if they're using some distro "here's a disk/sd card image file" where the expected use with real hardware is "dd the image file onto the SD card".
Yes, the description you gave here is indeed the issue.
And unfortunately in this particular case, the distro did not give a very understandable
diagnostic error message.
Kind regards,
Niek
Quoted 4 lines
thanks
-- PMM
Signature · 1 line
Niek Linnenbank