Add Allwinner H3 SoC and Orange Pi PC Machine
v2 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
* 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) and mainline U-Boot are known to work. The SD/MMC code is tested using bonnie++ and various tools such as fsck, dd and fdisk. The EMAC is verified with iperf3 using -netdev socket.
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 -j5
To boot the newly build linux kernel in QEMU with the Orange Pi PC machine, use:
$ qemu-system-arm -M orangepi-pc -m 512 -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.dtbNote that this kernel does not have a root filesystem. You may provide it with an official Orange Pi PC image [1] either as an SD card or as USB mass storage. 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 -m 512 -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.imgAlternatively, you can also choose to build and boot a recent buildroot [2] using the orangepi_pc_defconfig or Armbian image [3] for Orange Pi PC. To attach 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
U-Boot mainline can be build and configured using the orangepi_pc_defconfig using similar commands as describe above for Linux. 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 -m 512 -nic user -nographic \
-kernel /path/to/uboot/u-boot -sd disk.imgUse 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
Looking forward to your review comments. I will do my best to update the patches where needed.
===== CHANGELOG =====
v2:
* hw/arm/allwinner-h3.c: use cpus array in AwH3State instead of object_new()
* hw/arm/allwinner-h3.c: use error_abort in aw_h3_realize()
* hw/arm/allwinner-h3.c: use qdev_init_nofail() in aw_h3_realize()
* hw/arm/allwinner-h3.c: use qdev_get_gpio_in() instead of irq array
* hw/arm/allwinner-h3.c: add all missing unimplemented devices (memory map is complete)
* hw/arm/allwinner-h3.c: add UART1, UART2, UART3 and remove 'if (serial_hd(...))'
* hw/arm/allwinner-h3.c: remove sysbusdev variable and use SYS_BUS_DEVICE() directly
* include/hw/arm/allwinner-h3.h: move PPI/SPI defines to allwinner-h3.c as enum
* include/hw/arm/allwinner-h3.h: replace mem base/size defines with enum and memmap (like aspeed_soc.h)
* hw/arm/orangepi.c: Only allow Cortex-A7 in machine->cpu_type
* hw/arm/orangepi.c: Set mc->default_cpu_type to ARM_CPU_TYPE_NAME("cortex-a7")
* hw/arm/orangepi.c: Use error_abort in orangepi_init()
* hw/arm/orangepi.c: only allow maximum 1GiB RAM
* hw/arm/orangepi.c: renamed machine name to 'orangepi-pc'
* hw/arm/orangepi.c: remove mc->ignore_memory_transaction_failures = true
* hw/arm/orangepi.c: remove unnecessary check for 'sd-bus'
* hw/net/allwinner-h3-emac.c: use AW_H3_EMAC() for opaque in read/write functions
* hw/sd/allwinner-h3-sdhost.c: replace register defines with enums
* hw/sd/allwinner-h3-sdhost.c: remove 'irq_en' and use if() to set 'irq' in update_irq function
* hw/sd/allwinner-h3-sdhost.c: simplified if (rlen==) conditions in send_command function
* hw/sd/allwinner-h3-sdhost.c: use KiB macro to set desc->size
* hw/sd/allwinner-h3-sdhost.c: use ARRAY_SIZE() macro in reset function
* hw/misc/allwinner-h3-sid.c: replace randomized identifier with QemuUUID property
* hw/misc/allwinner-h3-sid.c: add tracing for read/write functions
* hw/misc/allwinner-h3-sid.c: fix incorrect usage of REG_PRCTL_OP_LOCK/REG_PRCTL_WRITE
* hw/misc/trace-events: add allwinner_h3_cpucfg* entries in correct patch (#7)
* hw/*/trace-events: use PRIu32/PRIx32 macros for size and max fields
* hw/*/allwinner-h3-*.c: set .impl.min_access_size = 4 to restrict MMIO access to 32-bit aligned
* hw/*/allwinner-h3-*.c: replace register defines with enums
* hw/*/allwinner-h3-*.c: set VMStateDescription.name with inline string (dont use TYPE macro)
* include/hw/*/allwinner-h3-*.h: remove MEM_SIZE define and use size inline in the source file
* target/arm/arm-powerctl.c: invoke arm_rebuild_hflags() after setting CP15 bits
With kind regards,
Niek Linnenbank
[1] http://www.orangepi.org/downloadresources/
[2] https://buildroot.org/download.html
[3] https://www.armbian.com/orange-pi-pc/
Niek Linnenbank (10):
hw: arm: add Allwinner H3 System-on-Chip
hw: arm: add Xunlong Orange Pi PC machine
arm: allwinner-h3: add Clock Control Unit
arm: allwinner-h3: add USB host controller
arm: allwinner-h3: add System Control module arm/arm-powerctl: rebuild hflags after setting CP15 bits in
arm_set_cpu_on()
arm: allwinner-h3: add CPU Configuration module
arm: allwinner-h3: add Security Identifier device
arm: allwinner-h3: add SD/MMC host controller
arm: allwinner-h3: add EMAC ethernet device
default-configs/arm-softmmu.mak | 1 + hw/usb/hcd-ehci.h | 1 + include/hw/arm/allwinner-h3.h | 93 +++ include/hw/misc/allwinner-h3-clk.h | 40 ++ include/hw/misc/allwinner-h3-cpucfg.h | 42 ++ include/hw/misc/allwinner-h3-sid.h | 40 ++ include/hw/misc/allwinner-h3-syscon.h | 42 ++ include/hw/net/allwinner-h3-emac.h | 67 +++ include/hw/sd/allwinner-h3-sdhost.h | 71 +++ hw/arm/allwinner-h3.c | 442 ++++++++++++++ hw/arm/orangepi.c | 127 ++++ hw/misc/allwinner-h3-clk.c | 238 ++++++++ hw/misc/allwinner-h3-cpucfg.c | 288 +++++++++ hw/misc/allwinner-h3-sid.c | 179 ++++++ hw/misc/allwinner-h3-syscon.c | 146 +++++ hw/net/allwinner-h3-emac.c | 829 ++++++++++++++++++++++++++ hw/sd/allwinner-h3-sdhost.c | 813 +++++++++++++++++++++++++ hw/usb/hcd-ehci-sysbus.c | 17 + target/arm/arm-powerctl.c | 3 + MAINTAINERS | 8 + hw/arm/Kconfig | 9 + hw/arm/Makefile.objs | 1 + hw/misc/Makefile.objs | 4 + hw/misc/trace-events | 9 + hw/net/Kconfig | 3 + hw/net/Makefile.objs | 1 + hw/net/trace-events | 10 + hw/sd/Makefile.objs | 1 + hw/sd/trace-events | 7 + 29 files changed, 3532 insertions(+) create mode 100644 include/hw/arm/allwinner-h3.h create mode 100644 include/hw/misc/allwinner-h3-clk.h create mode 100644 include/hw/misc/allwinner-h3-cpucfg.h create mode 100644 include/hw/misc/allwinner-h3-sid.h create mode 100644 include/hw/misc/allwinner-h3-syscon.h create mode 100644 include/hw/net/allwinner-h3-emac.h create mode 100644 include/hw/sd/allwinner-h3-sdhost.h create mode 100644 hw/arm/allwinner-h3.c create mode 100644 hw/arm/orangepi.c create mode 100644 hw/misc/allwinner-h3-clk.c create mode 100644 hw/misc/allwinner-h3-cpucfg.c create mode 100644 hw/misc/allwinner-h3-sid.c create mode 100644 hw/misc/allwinner-h3-syscon.c create mode 100644 hw/net/allwinner-h3-emac.c create mode 100644 hw/sd/allwinner-h3-sdhost.c
Signature · 1 line
2.17.1
PATCH v2 1/10 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 | 80 +++++++ hw/arm/allwinner-h3.c | 360 ++++++++++++++++++++++++++++++++ MAINTAINERS | 7 + hw/arm/Kconfig | 8 + hw/arm/Makefile.objs | 1 + 6 files changed, 457 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
@@ -40,3 +40,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 +80 -0
80 lines not on this page · raw message
hw/arm/allwinner-h3.c new file +360 -0
360 lines not on this page · raw message
MAINTAINERS +7 -0
@@ -480,6 +480,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
@@ -291,6 +291,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
@@ -34,6 +34,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_XLNX_ZYNQMP_ARM) += xlnx-zynqmp.o xlnx-zcu102.o
Signature · 1 line
2.17.1
PATCH v2 2/10 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, 512MB 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 | 101 +++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + hw/arm/Makefile.objs | 2 +- 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 hw/arm/orangepi.c
hw/arm/orangepi.c new file +101 -0
@@ -0,0 +1,101 @@ +/* +* 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 "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" + +static struct arm_boot_info orangepi_binfo = { + .board_id =-1 , +}; + +typedef struct OrangePiState { +AwH3State *h3; +MemoryRegion sdram; +}OrangePiState ; + +static void orangepi_init (MachineState *machine) +{ +OrangePiState *s =g_new (OrangePiState,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->timer),32768 ,"clk0-freq" , + &error_abort); +if (error_abort !=NULL ) { +error_reportf_err (error_abort,"Couldn't set clk0 frequency: " ); +exit (1 ); + } + +object_property_set_int (OBJECT (&s->h3->timer),24000000 ,"clk1-freq" , + &error_abort); +if (error_abort !=NULL ) { +error_reportf_err (error_abort,"Couldn't set clk1 frequency: " ); +exit (1 ); + } + +/* Mark H3 object realized */ +object_property_set_bool (OBJECT (s->h3), true,"realized" , &error_abort); +if (error_abort !=NULL ) { +error_reportf_err (error_abort,"Couldn't realize Allwinner H3: " ); +exit (1 ); + } + +/* RAM */ +if (machine->ram_size >1 * GiB) { +error_report ("Requested ram size is too large for this machine: " +"maximum is 1GB" ); +exit (1 ); + } +memory_region_allocate_system_memory (&s->sdram,NULL ,"orangepi.ram" , + machine->ram_size); +memory_region_add_subregion (get_system_memory (), s->h3->memmap[AW_H3_SDRAM ], + &s->sdram); + +/* Load target kernel */ + orangepi_binfo.loader_start = s->h3->memmap[AW_H3_SDRAM ]; + orangepi_binfo.ram_size = machine->ram_size; + orangepi_binfo.nb_cpus =AW_H3_NUM_CPUS ; +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->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 ; + mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a7" ); +} + +DEFINE_MACHINE ("orangepi-pc" , orangepi_machine_init)
MAINTAINERS +1 -0
@@ -486,6 +486,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
@@ -34,7 +34,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_XLNX_ZYNQMP_ARM) += xlnx-zynqmp.o xlnx-zcu102.o
Signature · 1 line
2.17.1
Re: [PATCH v2 02/10] hw: arm: add Xunlong Orange Pi PC machine
Hi Niek,
Quoted 64 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, 512MB 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]>--- hw/arm/orangepi.c | 101 +++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + hw/arm/Makefile.objs | 2 +- 3 files changed, 103 insertions(+), 1 deletion(-)create mode 100644
hw/arm/orangepi.chw/arm/orangepi.c new file +42
-0@@ -0,0 +1,101 @@ +/* +* 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 "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" + +static struct arm_boot_info orangepi_binfo = { + .board_id =-1 , +}; + +typedef struct OrangePiState { +AwH3State *h3; +MemoryRegion sdram; +}OrangePiState ; + +static void orangepi_init (MachineState *machine) +{ +OrangePiState *s =g_new (OrangePiState,1 ); + +/* Only allow Cortex-A7 for this board */
hw/arm/orangepi.c line 52
Quoted 10 lines
hw/arm/orangepi.c new file +10
-0+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->timer),32768 ,"clk0-freq" , + &error_abort);
You access the timer object which is contained inside the soc object, but the soc isn't realized yet... I wonder if this is OK. Usually what we do is, either:
- add a 'xtal-freq-hz' property to the SoC, set it here in the board, then in soc::realize() set the property to the timer
- add an alias in the SoC to the timer 'freq-hz' property:
object_property_add_alias(soc, "xtal-freq-hz", OBJECT(&s->timer),
"freq-hz", &error_abort);Also, if you use &error_abort, a failure in object_property_set_int() triggers abort(). See "qapi/error.h":
* If @errp is &error_abort, print a suitable message and abort().
* If @errp is &error_fatal, print a suitable message and exit(1).
hw/arm/orangepi.c line 56
Quoted 4 lines
hw/arm/orangepi.c new file +4
-0+if (error_abort !=NULL ) { +error_reportf_err (error_abort,"Couldn't set clk0 frequency: " ); +exit (1 ); + }
So this if() block is useless.
hw/arm/orangepi.c line 63
Quoted 7 lines
hw/arm/orangepi.c new file +7
-0+ +object_property_set_int (OBJECT (&s->h3->timer),24000000 ,"clk1-freq" , + &error_abort); +if (error_abort !=NULL ) { +error_reportf_err (error_abort,"Couldn't set clk1 frequency: " ); +exit (1 ); + }
Similarly, remove if() block.
hw/arm/orangepi.c line 70
Quoted 7 lines
hw/arm/orangepi.c new file +7
-0+ +/* Mark H3 object realized */ +object_property_set_bool (OBJECT (s->h3), true,"realized" , &error_abort); +if (error_abort !=NULL ) { +error_reportf_err (error_abort,"Couldn't realize Allwinner H3: " ); +exit (1 ); + }
Similarly, remove if() block.
hw/arm/orangepi.c line 75
Quoted 5 lines
hw/arm/orangepi.c new file +5
-0+ +/* RAM */ +if (machine->ram_size >1 * GiB) { +error_report ("Requested ram size is too large for this machine: " +"maximum is 1GB" );
Per http://www.orangepi.org/orangepipc/ this board comes with a specific amount of RAM. I'd enforce the default (1GiB) and refuse other cases.
I noticed this by testing your series, without specifying the memory size you suggested in the cover (512) it defaults to 128 MiB, and the Raspian userland fails:
[ *** ] (2 of 4) A start job is running for…Persistent Storage (37s / 2min 1s) [ *** ] (2 of 4) A start job is running for…Persistent Storage (38s / 2min 1s) [ OK ] Started Flush Journal to Persistent Storage.
Starting Create Volatile Files and Directories...
Starting Armbian ZRAM config...
[ **] (3 of 6) A start job is running for…s and Directories (55s / no limit)
[ *] (3 of 6) A start job is running for…s and Directories (55s / no limit)
[ **] (3 of 6) A start job is running for…s and Directories (56s / no limit)
[ OK ] Started Create Volatile Files and Directories. [*** ] (5 of 6) A start job is running for… ZRAM config (1min 10s / 1min 19s) [** ] (5 of 6) A start job is running for… ZRAM config (1min 12s / 1min 19s) [* ] (5 of 6) A start job is running for… ZRAM config (1min 13s / 1min 19s)
[FAILED] Failed to start Armbian ZRAM config.
See 'systemctl status armbian-zram-config.service' for details.
hw/arm/orangepi.c line 78
Quoted 3 lines
hw/arm/orangepi.c new file +3
-0+exit (1 ); + } + memory_region_allocate_system_memory(&s->sdram, NULL, "orangepi.ram",
There is only one type of ram on this machine, I'd simply name this "sdram".
hw/arm/orangepi.c line 87
Quoted 9 lines
hw/arm/orangepi.c new file +9
-0+ machine->ram_size); +memory_region_add_subregion (get_system_memory (), s->h3->memmap[AW_H3_SDRAM ], + &s->sdram); + +/* Load target kernel */ + orangepi_binfo.loader_start = s->h3->memmap[AW_H3_SDRAM ]; + orangepi_binfo.ram_size = machine->ram_size; + orangepi_binfo.nb_cpus =AW_H3_NUM_CPUS ; +arm_load_kernel (ARM_CPU (first_cpu), machine, &orangepi_binfo);
I wonder if we should tell the user '-bios' is not supported on this machine.
hw/arm/orangepi.c line 94
Quoted 7 lines
hw/arm/orangepi.c new file +7
-0+} + +static void orangepi_machine_init (MachineClass *mc) +{ + mc->desc ="Orange Pi PC" ; + mc->init = orangepi_init; + mc->units_per_default_bus =1 ;
Maybe "units_per_default_bus = 1" belongs to patch 9 "add SD/MMC host controller".
hw/arm/orangepi.c line 98
Quoted 4 lines
hw/arm/orangepi.c new file +4
-0+ 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" );
Please add:
mc->default_ram_size = 1 * GiB;
Quoted 29 lines
hw/arm/orangepi.c new file +3
-0+} + +DEFINE_MACHINE ("orangepi-pc" , orangepi_machine_init)MAINTAINERS +1
-0@@ -486,6 +486,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@@ -34,7 +34,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_XLNX_ZYNQMP_ARM) += xlnx-zynqmp.o xlnx-zcu102.o
Re: [PATCH v2 02/10] hw: arm: add Xunlong Orange Pi PC machine
Hi Philippe,
Thanks again for your quick and helpful feedback! :-)
Quoted 86 lines · Philippe Mathieu-Daudé
Hi Niek,
Quoted 56 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, 512MB 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]>--- hw/arm/orangepi.c | 101 +++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + hw/arm/Makefile.objs | 2 +- 3 files changed, 103 insertions(+), 1 deletion(-)create mode 100644
hw/arm/orangepi.chw/arm/orangepi.c new file +17
-0@@ -0,0 +1,101 @@ +/* +* 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 +15
-0+ +#include "qemu/osdep.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" + +static struct arm_boot_info orangepi_binfo = { + .board_id =-1 , +}; + +typedef struct OrangePiState {hw/arm/orangepi.c
Quoted 10 lines
hw/arm/orangepi.c new file +10
-0+AwH3State *h3; +MemoryRegion sdram; +} OrangePiState; + +static void orangepi_init (MachineState *machine) +{ +OrangePiState *s =g_new (OrangePiState,1 ); + +/* Only allow Cortex-A7 for this board */ +if (strcmp (machine->cpu_type,ARM_CPU_TYPE_NAME ("cortex-a7" )) !=0 ){
hw/arm/orangepi.c line 52
Quoted 9 lines
hw/arm/orangepi.c new file +9
-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->timer),32768 ,"clk0-freq" , + &error_abort);You access the timer object which is contained inside the soc object, but the soc isn't realized yet... I wonder if this is OK. Usually what we do is, either:
- add a 'xtal-freq-hz' property to the SoC, set it here in the board, then insoc::realize()set the property to the timer
- add an alias in the SoC to the timer 'freq-hz' property:
Quoted 3 lines
object_property_add_alias(soc, "xtal-freq-hz", OBJECT(&s->timer),
"freq-hz", &error_abort);Good point. I shall rework that part using your suggestion. Actually, I copied the timer support code from the existing cubieboard.c that has
the Allwinner A10, so potentially the same problem is there.
While looking more closer at this part, I now also discovered that the timer module from the Allwinner H3 is
mostly a stripped down version of the timer module in the Allwinner A10:
Allwinner A10, 10.2 Timer Register List, page 85:
https://linux-sunxi.org/images/1/1e/Allwinner_A10_User_manual_V1.5.pdf
The A10 version has six timers, where the H3 has only two. That should be fine I would say, the guest would simply
use those available on H3 and ignore the rest. There is however one conflicting difference: the WDOG0 registers in the Allwinner H3 start at a different offset and are also different. The current A10 timer does not currently implement the watchdog part.
The watchdog part of this timer is relevant for the 'reset' command in
U-Boot: that does not work right now, because
U-Boot implements the reset for the Allwinner H3 boards by letting this watchdog expire (and we dont emulate it).
Also, this timer module is required for booting Linux, without it the kernel crashes using the sunxi_defconfig:
[ 0.000000] PC is at sun4i_timer_init+0x34/0x168 [ 0.000000] LR is at sun4i_timer_init+0x2c/0x168 [ 0.000000] pc : [<c07fa634>] lr : [<c07fa62c>] psr: 600000d3 [ 0.000000] sp : c0a03f70 ip : eec00188 fp : ef7ed040 ... [ 0.000000] [<c07fa634>] (sun4i_timer_init) from [<c07fa4e8>] (timer_probe+0x74/0xe4) [ 0.000000] [<c07fa4e8>] (timer_probe) from [<c07d9c10>] (start_kernel+0x2e0/0x440) [ 0.000000] [<c07d9c10>] (start_kernel) from [<00000000>] (0x0)
So in my opinion its a bit of a trade off here: we can keep it like this and re-use the A10 timer for now, and perhaps
attempt to generalize that module for proper use in both SoCs. Or we can introduce a new H3 specific timer module.
What do you think?
Quoted 44 lines
Also, if you use
&error_abort, a failure inobject_property_set_int()triggersabort(). See "qapi/error.h":* If @errp is
&error_abort, print a suitable message andabort().
* If @errp is&error_fatal, print a suitable message and exit(1).hw/arm/orangepi.c line 56
Quoted 4 lines
hw/arm/orangepi.c new file +4
-0+if (error_abort !=NULL ) { +error_reportf_err (error_abort,"Couldn't set clk0 frequency: " ); +exit (1 ); + }So this
if()block is useless.Ah ok, I'll remove them.
hw/arm/orangepi.c
Quoted 2 lines
hw/arm/orangepi.c new file +2
-0+ + object_property_set_int(OBJECT(&s->h3->timer), 24000000,"clk1-freq",
hw/arm/orangepi.c line 63
Quoted 5 lines
hw/arm/orangepi.c new file +5
-0+ &error_abort); +if (error_abort !=NULL ) { +error_reportf_err (error_abort,"Couldn't set clk1 frequency: " ); +exit (1 ); + }Similarly, remove
if()block.hw/arm/orangepi.c
Quoted 3 lines
hw/arm/orangepi.c new file +3
-0+ +/* Mark H3 object realized */ + object_property_set_bool(OBJECT(s->h3), true, "realized",
&error_abort);hw/arm/orangepi.c
Quoted 2 lines
hw/arm/orangepi.c new file +2
-0+if (error_abort !=NULL ) { + error_reportf_err(error_abort, "Couldn't realize Allwinner H3:");
hw/arm/orangepi.c
Quoted 2 lines
hw/arm/orangepi.c new file +2
-0+exit (1 ); + }Similarly, remove
if()block.hw/arm/orangepi.c
Quoted 4 lines
hw/arm/orangepi.c new file +4
-0+ +/* RAM */ +if (machine->ram_size >1 * GiB) { + error_report("Requested ram size is too large for this machine:
Quoted 6 lines
"
Quoted 1 line
+ "maximum is 1GB");
Per http://www.orangepi.org/orangepipc/ this board comes with a specific amount of RAM. I'd enforce the default (1GiB) and refuse other cases.
OK sure, I'll change it to a enforcing 1GiB. I do recall we briefly discussed this
in v1. Then we agreed to make it an upper limit for use cases where resources are
limited which is why I changed it like this.
Quoted 4 lines
I noticed this by testing your series, without specifying the memory size you suggested in the cover (512) it defaults to 128 MiB, and the Raspian userland fails:
Indeed! By the way, this is also the case for U-Boot: it freezes when using 128MiB.
Actually when working on the initial code I searched a bit for a way to set a default ram size, but could not find it at that time. But now I see in your comment below,
it can be done simply with mc->default_ram_size. Thanks a lot, I will surely add that!
Quoted 24 lines
[ *** ] (2 of 4) A start job is running for…Persistent Storage (37s / 2min 1s)
[ *** ] (2 of 4) A start job is running for…Persistent Storage (38s / 2min 1s)
[ OK ] Started Flush Journal to Persistent Storage. Starting Create Volatile Files and Directories...
Starting Armbian ZRAM config...
[ **] (3 of 6) A start job is running for…s and Directories (55s / no
limit)
[ *] (3 of 6) A start job is running for…s and Directories (55s / no
limit)
[ **] (3 of 6) A start job is running for…s and Directories (56s / no
limit)
[ OK ] Started Create Volatile Files and Directories.
[*** ] (5 of 6) A start job is running for… ZRAM config (1min 10s /
1min 19s)
[** ] (5 of 6) A start job is running for… ZRAM config (1min 12s /
1min 19s)
[* ] (5 of 6) A start job is running for… ZRAM config (1min 13s /
1min 19s)
[FAILED] Failed to start Armbian ZRAM config.
See 'systemctl status armbian-zram-config.service' for details.
Quoted 8 lines
hw/arm/orangepi.c
Quoted 3 lines
hw/arm/orangepi.c new file +3
-0+exit (1 ); + } + memory_region_allocate_system_memory(&s->sdram, NULL,"orangepi.ram",
There is only one type of ram on this machine, I'd simply name this "sdram".
OK!
Quoted 11 lines
hw/arm/orangepi.c
Quoted 2 lines
hw/arm/orangepi.c new file +2
-0+ machine->ram_size); + memory_region_add_subregion(get_system_memory(),s->h3->memmap[AW_H3_SDRAM],
hw/arm/orangepi.c line 87
Quoted 7 lines
hw/arm/orangepi.c new file +7
-0+ &s->sdram); + +/* Load target kernel */ + orangepi_binfo.loader_start = s->h3->memmap[AW_H3_SDRAM ]; + orangepi_binfo.ram_size = machine->ram_size; + orangepi_binfo.nb_cpus =AW_H3_NUM_CPUS ; +arm_load_kernel (ARM_CPU (first_cpu), machine, &orangepi_binfo);
Quoted 3 lines
I wonder if we should tell the user '-bios' is not supported on this machine.
Good suggestion, its not handled, at least not anywhere in the code I added for H3 support.
Shall I make it an error_report followed by exit(1), similar to the 1GiB check?
Quoted 12 lines
hw/arm/orangepi.c line 94
Quoted 8 lines
hw/arm/orangepi.c new file +7
-0+} + +static void orangepi_machine_init (MachineClass *mc) +{ + mc->desc ="Orange Pi PC" ; + mc->init = orangepi_init; + mc->units_per_default_bus =1 ;Maybe "
units_per_default_bus= 1" belongs to patch 9 "add SD/MMC host controller".
True, it should be in patch 9 indeed. I overlooked this when separating the work in individual patches.
Now I am also wondering if I actually need this setting. Without it, the SD device still works fine.
I did some greps in the code to discover what it is used for, but its not very clear to me yet. Is this ment to
restrict machines to only one harddisk (or SD card)? If I try to supply multiple SD cards with multiple -sd arguments,
this error is printed, regardless of having units_per_default_bus=1 or not:
qemu-system-arm: -sd test3.ext2: machine type does not support
if=sd,bus=1,unit=0
Quoted 10 lines
hw/arm/orangepi.c line 98
Quoted 5 lines
hw/arm/orangepi.c new file +4
-0+ 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" );Please add:
mc->default_ram_size = 1 * GiB;
Yes, thanks!
Quoted 14 lines
Quoted 14 lines
hw/arm/orangepi.c new file +3
-0+} + +DEFINE_MACHINE ("orangepi-pc" , orangepi_machine_init)MAINTAINERS +1
-0@@ -486,6 +486,7 @@ L: [email protected] S: Maintained F: hw/*/allwinner-h3* F: include/hw/*/allwinner-h3* +F: hw/arm/orangepi.c
Quoted 18 lines
Quoted 8 lines
MAINTAINERS +0
-0ARM PrimeCell and CMSDK devices M: Peter Maydell <[email protected]>hw/arm/Makefile.objs +0
-0hw/arm/Makefile.objs obj-$(CONFIG_DIGIC) += digic.o · line 40
Quoted 8 lines
hw/arm/Makefile.objs +1
-1@@ -34,7 +34,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_XLNX_ZYNQMP_ARM) += xlnx-zynqmp.o xlnx-zcu102.o
Regards,
Niek
Signature · 1 line
Niek Linnenbank
Re: [PATCH v2 02/10] hw: arm: add Xunlong Orange Pi PC machine
Quoted 131 lines · Niek Linnenbank
Hi Philippe,
Thanks again for your quick and helpful feedback! :-)
On Tue, Dec 17, 2019 at 8:31 AM Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:
Hi Niek, On 12/17/19 12:35 AM, Niek Linnenbank wrote: > 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, > 512MB 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] <mailto:[email protected]>> > Tested-by: KONRAD Frederic <[email protected] <mailto:[email protected]>> > --- > hw/arm/orangepi.c | 101 +++++++++++++++++++++++++++++++++++++++++++ > MAINTAINERS | 1 + > hw/arm/Makefile.objs | 2 +- > 3 files changed, 103 insertions(+), 1 deletion(-) > create mode 100644 hw/arm/orangepi.c > > diff --git a/hw/arm/orangepi.c b/hw/arm/orangepi.c > new file mode 100644 > index 0000000000..62cefc8c06 > --- /dev/null > +++ b/hw/arm/orangepi.c > @@ -0,0 +1,101 @@ > +/* > + * Orange Pi emulation > + * > + * Copyright (C) 2019 Niek Linnenbank <[email protected] <mailto:[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 "cpu.h" > +#include "hw/sysbus.h" > +#include "hw/boards.h" > +#include "hw/qdev-properties.h" > +#include "hw/arm/allwinner-h3.h" > + > +static struct arm_boot_info orangepi_binfo = { > + .board_id = -1, > +}; > + > +typedef struct OrangePiState { > + AwH3State *h3; > + MemoryRegion sdram; > +} OrangePiState; > + > +static void orangepi_init(MachineState *machine) > +{ > + OrangePiState *s = g_new(OrangePiState, 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->timer), 32768, "clk0-freq", > + &error_abort); You access the timer object which is contained inside the soc object, but the soc isn't realized yet... I wonder if this is OK. Usually what we do is, either: - add a 'xtal-freq-hz' property to the SoC, set it here in the board, then in soc::realize() set the property to the timer - add an alias in the SoC to the timer 'freq-hz' property: object_property_add_alias(soc, "xtal-freq-hz", OBJECT(&s->timer), "freq-hz", &error_abort);Good point. I shall rework that part using your suggestion. Actually, I copied the timer support code from the existing
cubieboard.cthat has the Allwinner A10, so potentially the same problem is there.While looking more closer at this part, I now also discovered that the timer module from the Allwinner H3 is mostly a stripped down version of the timer module in the Allwinner A10:
Allwinner A10, 10.2 Timer Register List, page 85:
https://linux-sunxi.org/images/1/1e/Allwinner_A10_User_manual_V1.5.pdfThe A10 version has six timers, where the H3 has only two. That should be fine I would say, the guest would simply use those available on H3 and ignore the rest. There is however one conflicting difference: the WDOG0 registers in the Allwinner H3 start at a different offset and are also different. The current A10 timer does not currently implement the watchdog part.
The watchdog part of this timer is relevant for the 'reset' command in U-Boot: that does not work right now, because U-Boot implements the reset for the Allwinner H3 boards by letting this watchdog expire (and we dont emulate it). Also, this timer module is required for booting Linux, without it the kernel crashes using the
sunxi_defconfig:[ 0.000000] PC is at sun4i_timer_init+0x34/0x168 [ 0.000000] LR is at sun4i_timer_init+0x2c/0x168 [ 0.000000] pc : [<c07fa634>] lr : [<c07fa62c>] psr: 600000d3 [ 0.000000] sp : c0a03f70 ip : eec00188 fp : ef7ed040 ... [ 0.000000] [<c07fa634>] (sun4i_timer_init) from [<c07fa4e8>] (timer_probe+0x74/0xe4) [ 0.000000] [<c07fa4e8>] (timer_probe) from [<c07d9c10>] (start_kernel+0x2e0/0x440) [ 0.000000] [<c07d9c10>] (start_kernel) from [<00000000>] (0x0)
Quoted 3 lines
So in my opinion its a bit of a trade off here: we can keep it like this and re-use the A10 timer for now, and perhaps attempt to generalize that module for proper use in both SoCs. Or we can introduce a new H3 specific timer module. What do you think?
See my answer about generalize/reuse here:
http://mid.mail-archive.com/[email protected]
PATCH v2 3/10 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 | 2 + include/hw/misc/allwinner-h3-clk.h | 40 +++++ hw/arm/allwinner-h3.c | 7 + hw/misc/allwinner-h3-clk.c | 238 +++++++++++++++++++++++++++++ hw/misc/Makefile.objs | 1 + 5 files changed, 288 insertions(+) create mode 100644 include/hw/misc/allwinner-h3-clk.h create mode 100644 hw/misc/allwinner-h3-clk.c
include/hw/arm/allwinner-h3.h +2 -0
@@ -26,6 +26,7 @@#include "hw/arm/boot.h" #include "hw/timer/allwinner-a10-pit.h" #include "hw/intc/arm_gic.h" +#include "hw/misc/allwinner-h3-clk.h" #include "target/arm/cpu.h" enum {
@@ -71,6 +72,7 @@ typedef struct AwH3State {ARMCPU cpus[AW_H3_NUM_CPUS ];const hwaddr *memmap;AwA10PITState timer; +AwH3ClockState ccu;GICState gic;MemoryRegion sram_a1;MemoryRegion sram_a2;
include/hw/misc/allwinner-h3-clk.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* 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_CLK_H +#define HW_MISC_ALLWINNER_H3_CLK_H + +#include "hw/sysbus.h" + +#define AW_H3_CLK_REGS_MAX_ADDR (0x304) +#define AW_H3_CLK_REGS_NUM (AW_H3_CLK_REGS_MAX_ADDR / sizeof(uint32_t)) + +#define TYPE_AW_H3_CLK "allwinner-h3-clk" +#define AW_H3_CLK (obj) OBJECT_CHECK(AwH3ClockState, (obj), TYPE_AW_H3_CLK) + +typedef struct AwH3ClockState { +/*< private >*/ +SysBusDevice parent_obj; +/*< public >*/ + +MemoryRegion iomem; +uint32_t regs[AW_H3_CLK_REGS_NUM ]; +}AwH3ClockState ; + +#endif
hw/arm/allwinner-h3.c +7 -0
@@ -186,6 +186,9 @@ static void aw_h3_init(Object *obj)sysbus_init_child_obj (obj,"timer" , &s->timer,sizeof (s->timer),TYPE_AW_A10_PIT ); + +sysbus_init_child_obj (obj,"ccu" , &s->ccu,sizeof (s->ccu), +TYPE_AW_H3_CLK ); }static void aw_h3_realize (DeviceState *dev,Error **errp)
@@ -310,6 +313,10 @@ static void aw_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 */ 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-clk.c new file +238 -0
238 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-clk.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
PATCH v2 4/10 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 + hw/arm/allwinner-h3.c | 28 ++++++++++++++++++++++++++++ hw/usb/hcd-ehci-sysbus.c | 17 +++++++++++++++++ 3 files changed, 46 insertions(+)
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"
hw/arm/allwinner-h3.c +28 -0
@@ -26,6 +26,7 @@#include "hw/sysbus.h" #include "hw/arm/allwinner-h3.h" #include "hw/misc/unimp.h" +#include "hw/usb/hcd-ehci.h" #include "sysemu/sysemu.h" /* Memory map */
@@ -317,6 +318,33 @@ static void aw_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 */ 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
2.17.1
PATCH v2 5/10 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 | 2 + include/hw/misc/allwinner-h3-syscon.h | 42 ++++++++ hw/arm/allwinner-h3.c | 7 ++ hw/misc/allwinner-h3-syscon.c | 146 ++++++++++++++++++++++++++ hw/misc/Makefile.objs | 1 + 5 files changed, 198 insertions(+) create mode 100644 include/hw/misc/allwinner-h3-syscon.h create mode 100644 hw/misc/allwinner-h3-syscon.c
include/hw/arm/allwinner-h3.h +2 -0
@@ -27,6 +27,7 @@#include "hw/timer/allwinner-a10-pit.h" #include "hw/intc/arm_gic.h" #include "hw/misc/allwinner-h3-clk.h" +#include "hw/misc/allwinner-h3-syscon.h" #include "target/arm/cpu.h" enum {
@@ -73,6 +74,7 @@ typedef struct AwH3State {const hwaddr *memmap;AwA10PITState timer;AwH3ClockState ccu; +AwH3SysconState syscon;GICState gic;MemoryRegion sram_a1;MemoryRegion sram_a2;
include/hw/misc/allwinner-h3-syscon.h new file +42 -0
42 lines not on this page · raw message
hw/arm/allwinner-h3.c +7 -0
@@ -190,6 +190,9 @@ static void aw_h3_init(Object *obj)sysbus_init_child_obj (obj,"ccu" , &s->ccu,sizeof (s->ccu),TYPE_AW_H3_CLK ); + +sysbus_init_child_obj (obj,"syscon" , &s->syscon,sizeof (s->syscon), +TYPE_AW_H3_SYSCON ); }static void aw_h3_realize (DeviceState *dev,Error **errp)
@@ -318,6 +321,10 @@ static void aw_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->syscon)); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->syscon),0 , s->memmap[AW_H3_SYSCON ]); +/* 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-syscon.c new file +146 -0
146 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-clk.o +common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-syscon.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
PATCH v2 6/10 arm/arm-powerctl: rebuild hflags after setting CP15 bits in arm_set_cpu_on()
In reply to Niek LinnenbankAfter setting CP15 bits in arm_set_cpu_on() the cached hflags must be rebuild to reflect the changed processor state. Without rebuilding, the cached hflags would be inconsistent until the next call to arm_rebuild_hflags(). When QEMU is compiled with debugging enabled (--enable-debug), this problem is captured shortly after the first call to arm_set_cpu_on() for CPUs running in ARM 32-bit non-secure mode:
qemu-system-arm: target/arm/helper.c:11359: cpu_get_tb_cpu_state:
Assertion `flags == rebuild_hflags_internal(env)' failed. Aborted (core dumped)
--- target/arm/arm-powerctl.c | 3 +++ 1 file changed, 3 insertions(+)
target/arm/arm-powerctl.c +3 -0
@@ -127,6 +127,9 @@ static void arm_set_cpu_on_async_work(CPUState *target_cpu_state, target_cpu->env.regs[0 ] = info->context_id; } +/* CP15 update requires rebuilding hflags */ +arm_rebuild_hflags (&target_cpu->env); +/* Start the new CPU at the requested address */ cpu_set_pc (target_cpu_state, info->entry);
Signature · 1 line
2.17.1
Re: [PATCH v2 06/10] arm/arm-powerctl: rebuild hflags after setting CP15 bits in arm_set_cpu_on()
Hello Peter,
In the previous version of this patch series I included the fix for setting CP10,CP11 bits
in arm_set_cpu_on(), which is now in master (0c7f8c43daf65560). While that worked, I did not
realize that setting those bits require rebuilding the flags. Philippe reported this [1] initially,
later on during review we discussed [2] and attempted to correct it [3].
Could you please have a short look at this? Right now I don't see anymore issues, but I'm just not very familiar with this area of the code.
Regards,
Niek
[1] https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg01920.html
[2] https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg02784.html
[3] https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg02785.html
Quoted 36 lines · Niek Linnenbank
After setting CP15 bits in
arm_set_cpu_on()the cached hflags must be rebuild to reflect the changed processor state. Without rebuilding, the cached hflags would be inconsistent until the next call toarm_rebuild_hflags(). When QEMU is compiled with debugging enabled (--enable-debug), this problem is captured shortly after the first call toarm_set_cpu_on()for CPUs running in ARM 32-bit non-secure mode:qemu-system-arm:
target/arm/helper.c:11359:cpu_get_tb_cpu_state:
Assertion `flags ==rebuild_hflags_internal(env)' failed. Aborted (core dumped)Fixes 0c7f8c43daf65Signed-off-by Niek Linnenbank <[email protected]>--- target/arm/arm-powerctl.c | 3 +++ 1 file changed, 3 insertions(+)target/arm/arm-powerctl.c +3
-1@@ -127,6 +127,9 @@ static void arm_set_cpu_on_async_work(CPUState *target_cpu_state, target_cpu->env.regs[0 ] = info->context_id; } +/* CP15 update requires rebuilding hflags */ +arm_rebuild_hflags (&target_cpu->env); +/* Start the new CPU at the requested address */ cpu_set_pc (target_cpu_state, info->entry); --2.17.1
Signature · 1 line
Niek Linnenbank
Re: [PATCH v2 06/10] arm/arm-powerctl: rebuild hflags after setting CP15 bits in arm_set_cpu_on()
Cc'ing Richard : this is one for you I think... (surely we need to rebuild the hflags from scratch when we power up a CPU anyway?)
thanks
-- PMM
Quoted 59 lines · Niek Linnenbank
Hello Peter,
In the previous version of this patch series I included the fix for setting CP10,CP11 bits in
arm_set_cpu_on(), which is now in master (0c7f8c43daf65560). While that worked, I did not realize that setting those bits require rebuilding the flags. Philippe reported this [1] initially, later on during review we discussed [2] and attempted to correct it [3].Could you please have a short look at this? Right now I don't see anymore issues, but I'm just not very familiar with this area of the code.
Regards,
Niek[1] https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg01920.html
[2] https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg02784.html
[3] https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg02785.htmlQuoted 33 lines · Niek Linnenbank
After setting CP15 bits in
arm_set_cpu_on()the cached hflags must be rebuild to reflect the changed processor state. Without rebuilding, the cached hflags would be inconsistent until the next call toarm_rebuild_hflags(). When QEMU is compiled with debugging enabled (--enable-debug), this problem is captured shortly after the first call toarm_set_cpu_on()for CPUs running in ARM 32-bit non-secure mode:qemu-system-arm:
target/arm/helper.c:11359:cpu_get_tb_cpu_state:
Assertion `flags ==rebuild_hflags_internal(env)' failed. Aborted (core dumped)Fixes 0c7f8c43daf65Signed-off-by Niek Linnenbank <[email protected]>--- target/arm/arm-powerctl.c | 3 +++ 1 file changed, 3 insertions(+)target/arm/arm-powerctl.c +3
-1@@ -127,6 +127,9 @@ static void arm_set_cpu_on_async_work(CPUState *target_cpu_state, target_cpu->env.regs[0 ] = info->context_id; } +/* CP15 update requires rebuilding hflags */ +arm_rebuild_hflags (&target_cpu->env); +/* Start the new CPU at the requested address */ cpu_set_pc (target_cpu_state, info->entry); --Quoted 2 lines
2.17.1
--
Niek Linnenbank
Richard Henderson
Reviewed-byRe: [PATCH v2 06/10] arm/arm-powerctl: rebuild hflags after setting CP15 bits in arm_set_cpu_on()
Quoted 3 lines · Peter Maydell
Cc'ing Richard : this is one for you I think... (surely we need to rebuild the hflags from scratch when we power up a CPU anyway?)
We do compute hflags from scratch in reset.
It has also turned out that there were a few board models that poked at the contents of the cpu and needed special help. Some of that I would imagine would be fixed properly with the multi-phase reset patches, where we could rebuild hflags when *leaving* reset.
In arm_set_cpu_on_async_work, we start by resetting the cpu and then start poking at the contents of some system registers. So, yes, we do need to rebuild after doing that. Also, I'm not sure how this function should fit into the multi-phase reset future.
So:
Quoted 27 lines
Quoted 27 lines · Niek Linnenbank
Quoted 26 lines
After setting CP15 bits in
arm_set_cpu_on()the cached hflags must be rebuild to reflect the changed processor state. Without rebuilding, the cached hflags would be inconsistent until the next call toarm_rebuild_hflags(). When QEMU is compiled with debugging enabled (--enable-debug), this problem is captured shortly after the first call toarm_set_cpu_on()for CPUs running in ARM 32-bit non-secure mode:qemu-system-arm:
target/arm/helper.c:11359:cpu_get_tb_cpu_state:
Assertion `flags ==rebuild_hflags_internal(env)' failed. Aborted (core dumped)Fixes 0c7f8c43daf65Signed-off-by Niek Linnenbank <[email protected]>--- target/arm/arm-powerctl.c | 3 +++ 1 file changed, 3 insertions(+)target/arm/arm-powerctl.c +0
-0@@ -127,6 +127,9 @@ static void arm_set_cpu_on_async_work(CPUState *target_cpu_state, target_cpu->env.regs[0 ] = info->context_id; }
Quoted 6 lines
Quoted 6 lines
target/arm/arm-powerctl.c static void arm_set_cpu_on_async_work(CPUState *target_cpu_state, · line 135
Quoted 6 lines
target/arm/arm-powerctl.c +3
-0+/* CP15 update requires rebuilding hflags */ +arm_rebuild_hflags (&target_cpu->env); +/* Start the new CPU at the requested address */ cpu_set_pc (target_cpu_state, info->entry);
r~
Re: [PATCH v2 06/10] arm/arm-powerctl: rebuild hflags after setting CP15 bits in arm_set_cpu_on()
Quoted 13 lines · Richard Henderson
Quoted 3 lines · Peter Maydell
Cc'ing Richard : this is one for you I think... (surely we need to rebuild the hflags from scratch when we power up a CPU anyway?)
We do compute hflags from scratch in reset.
It has also turned out that there were a few board models that poked at the contents of the cpu and needed special help. Some of that I would imagine would be fixed properly with the multi-phase reset patches, where we could rebuild hflags when *leaving* reset.
Quoted 8 lines
In
arm_set_cpu_on_async_work, we start by resetting the cpu and then start poking at the contents of some system registers. So, yes, we do need to rebuild after doing that. Also, I'm not sure how this function should fit into the multi-phase reset future.So:
Reviewed-by Richard Henderson <[email protected]>
Thanks; I've applied this patch to target-arm.next.
-- PMM
Re: [PATCH v2 06/10] arm/arm-powerctl: rebuild hflags after setting CP15 bits in arm_set_cpu_on()
In reply to Richard HendersonHello Richard,
Quoted 12 lines · Richard Henderson
Quoted 3 lines · Peter Maydell
Cc'ing Richard : this is one for you I think... (surely we need to rebuild the hflags from scratch when we power up a CPU anyway?)
We do compute hflags from scratch in reset.
It has also turned out that there were a few board models that poked at the contents of the cpu and needed special help. Some of that I would imagine would be fixed properly with the multi-phase reset patches, where we could rebuild hflags when *leaving* reset.
Quoted 6 lines
In
arm_set_cpu_on_async_work, we start by resetting the cpu and then start poking at the contents of some system registers. So, yes, we do need to rebuild after doing that. Also, I'm not sure how this function should fit into
the multi-phase reset future.
Great, thanks a lot for confirming and clarifying this!
You mention the multi-phase reset feature, is that going to replace the arm_set_cpu_on() functionality?
Currently I chose to use this function for implementing the CPU configuration module in the Allwinner H3 Soc.
U-Boot needs the CPU configuration module to provide PSCI which Linux uses to bring up the secondary cores.
And basically the CPU configuration module needs something to let the secondary CPUs power on, reset and start executing at some address.
Would you suggest to keep using arm_set_cpu_on() for this, or should I instead use a different function?
Regards,
Niek
Quoted 45 lines
So:
Quoted 1 line
Quoted 1 line
On Tue, Dec 17, 2019 at 12:36 AM Niek Linnenbank <
Quoted 7 lines · [email protected]> wrote:
Quoted 7 lines
Quoted 7 lines
After setting CP15 bits in
arm_set_cpu_on()the cached hflags must be rebuild to reflect the changed processor state. Without rebuilding, the cached hflags would be inconsistent until the next call toarm_rebuild_hflags(). When QEMU is compiled with debugging enabled (--enable-debug), this problem is captured shortly after the first call toarm_set_cpu_on()for CPUs running in ARM 32-bit non-securemode:
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
qemu-system-arm:
target/arm/helper.c:11359:cpu_get_tb_cpu_state:
Assertion `flags ==rebuild_hflags_internal(env)' failed. Aborted (core dumped)Fixes 0c7f8c43daf65Signed-off-by Niek Linnenbank <[email protected]>--- target/arm/arm-powerctl.c | 3 +++ 1 file changed, 3 insertions(+)Quoted 5 lines
Quoted 5 lines
target/arm/arm-powerctl.c static void arm_set_cpu_on_async_work(CPUState
Quoted 5 lines
target/arm/arm-powerctl.c +0
-0@@ -127,6 +127,9 @@ static void arm_set_cpu_on_async_work(CPUState
*target_cpu_state,Quoted 9 lines
Quoted 9 lines
target/arm/arm-powerctl.c static void arm_set_cpu_on_async_work(CPUState *target_cpu_state, · line 135
Quoted 9 lines
target/arm/arm-powerctl.c +3
-0target_cpu->env.regs[0 ] = info->context_id; } +/* CP15 update requires rebuilding hflags */ +arm_rebuild_hflags (&target_cpu->env); +/* Start the new CPU at the requested address */ cpu_set_pc (target_cpu_state, info->entry);Reviewed-by Richard Henderson <[email protected]>r~
Signature · 1 line
Niek Linnenbank
Re: [PATCH v2 06/10] arm/arm-powerctl: rebuild hflags after setting CP15 bits in arm_set_cpu_on()
Quoted 23 lines · Niek Linnenbank
Hello Richard,
On Tue, Dec 17, 2019 at 5:41 PM Richard Henderson <[email protected] <mailto:[email protected]>> wrote:
On 12/17/19 6:12 AM, Peter Maydell wrote:
> Cc'ing Richard : this is one for you I think... (surely we > need to rebuild the hflags from scratch when we power up > a CPU anyway?)We do compute hflags from scratch in reset.
It has also turned out that there were a few board models that poked at the contents of the cpu and needed special help. Some of that I would imagine would be fixed properly with the multi-phase reset patches, where we could rebuild hflags when *leaving* reset.
In
arm_set_cpu_on_async_work, we start by resetting the cpu and then start poking at the contents of some system registers. So, yes, we do need to rebuild after doing that. Also, I'm not sure how this function should fit into the multi-phase reset future.
Quoted 3 lines
Great, thanks a lot for confirming and clarifying this!
You mention the multi-phase reset feature, is that going to replace thearm_set_cpu_on()functionality?
I don't think so, but I'm not sure. As I said above, I don't immediately see how arm_set_cpu_on() will integrate.
In any case, multi-phase reset is still pending, though I believe it is high on Peter's priority queue for the 5.0 development cycle.
r~
PATCH v2 7/10 arm: allwinner-h3: add CPU Configuration module
In reply to Niek LinnenbankThe Allwinner H3 System on Chip design contains four ARM Cortex A7 processors that can be configured and reset using the CPU Configuration module interface. This commit adds support for the CPU configuration interface which emulates the following features:
* CPU reset
* Shared 64-bit timer
--- include/hw/arm/allwinner-h3.h | 2 + include/hw/misc/allwinner-h3-cpucfg.h | 42 ++++ hw/arm/allwinner-h3.c | 7 + hw/misc/allwinner-h3-cpucfg.c | 288 ++++++++++++++++++++++++++ hw/misc/Makefile.objs | 1 + hw/misc/trace-events | 5 + 6 files changed, 345 insertions(+) create mode 100644 include/hw/misc/allwinner-h3-cpucfg.h create mode 100644 hw/misc/allwinner-h3-cpucfg.c
include/hw/arm/allwinner-h3.h +2 -0
@@ -27,6 +27,7 @@#include "hw/timer/allwinner-a10-pit.h" #include "hw/intc/arm_gic.h" #include "hw/misc/allwinner-h3-clk.h" +#include "hw/misc/allwinner-h3-cpucfg.h" #include "hw/misc/allwinner-h3-syscon.h" #include "target/arm/cpu.h"
@@ -74,6 +75,7 @@ typedef struct AwH3State {const hwaddr *memmap;AwA10PITState timer;AwH3ClockState ccu; +AwH3CpuCfgState cpucfg;AwH3SysconState syscon;GICState gic;MemoryRegion sram_a1;
include/hw/misc/allwinner-h3-cpucfg.h new file +42 -0
42 lines not on this page · raw message
hw/arm/allwinner-h3.c +7 -0
@@ -193,6 +193,9 @@ static void aw_h3_init(Object *obj)sysbus_init_child_obj (obj,"syscon" , &s->syscon,sizeof (s->syscon),TYPE_AW_H3_SYSCON ); + +sysbus_init_child_obj (obj,"cpucfg" , &s->cpucfg,sizeof (s->cpucfg), +TYPE_AW_H3_CPUCFG ); }static void aw_h3_realize (DeviceState *dev,Error **errp)
@@ -325,6 +328,10 @@ static void aw_h3_realize(DeviceState *dev, Error **errp)qdev_init_nofail (DEVICE (&s->syscon));sysbus_mmio_map (SYS_BUS_DEVICE (&s->syscon),0 , s->memmap[AW_H3_SYSCON ]); +/* 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-h3-cpucfg.c new file +288 -0
288 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-clk.o +obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-cpucfg.o common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-syscon.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-h3-cpucfg.c +allwinner_h3_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "H3-CPUCFG: cpu_reset: id %u, reset_addr 0x%" PRIu32 +allwinner_h3_cpucfg_read(uint64_t offset, uint64_t data, unsigned size) "H3-CPUCFG: read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 +allwinner_h3_cpucfg_write(uint64_t offset, uint64_t data, unsigned size) "H3-CPUCFG: write: 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
PATCH v2 8/10 arm: allwinner-h3: add Security Identifier device
In reply to Niek LinnenbankThe Security Identifier device in Allwinner H3 System on Chip gives applications a per-board unique identifier. This commit adds support for the Allwinner H3 Security Identifier using a 128-bit UUID value as input.
--- include/hw/arm/allwinner-h3.h | 2 + include/hw/misc/allwinner-h3-sid.h | 40 +++++++ hw/arm/allwinner-h3.c | 7 ++ hw/arm/orangepi.c | 4 + hw/misc/allwinner-h3-sid.c | 179 +++++++++++++++++++++++++++++ hw/misc/Makefile.objs | 1 + hw/misc/trace-events | 4 + 7 files changed, 237 insertions(+) create mode 100644 include/hw/misc/allwinner-h3-sid.h create mode 100644 hw/misc/allwinner-h3-sid.c
include/hw/arm/allwinner-h3.h +2 -0
@@ -29,6 +29,7 @@#include "hw/misc/allwinner-h3-clk.h" #include "hw/misc/allwinner-h3-cpucfg.h" #include "hw/misc/allwinner-h3-syscon.h" +#include "hw/misc/allwinner-h3-sid.h" #include "target/arm/cpu.h" enum {
@@ -77,6 +78,7 @@ typedef struct AwH3State {AwH3ClockState ccu;AwH3CpuCfgState cpucfg;AwH3SysconState syscon; +AwH3SidState sid;GICState gic;MemoryRegion sram_a1;MemoryRegion sram_a2;
include/hw/misc/allwinner-h3-sid.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* Allwinner H3 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_H3_SID_H +#define HW_MISC_ALLWINNER_H3_SID_H + +#include "hw/sysbus.h" +#include "qemu/uuid.h" + +#define TYPE_AW_H3_SID "allwinner-h3-sid" +#define AW_H3_SID (obj) OBJECT_CHECK(AwH3SidState, (obj), TYPE_AW_H3_SID) + +typedef struct AwH3SidState { +/*< private >*/ +SysBusDevice parent_obj; +/*< public >*/ + +MemoryRegion iomem; +uint32_t control; +uint32_t rdkey; +QemuUUID identifier; +}AwH3SidState ; + +#endif
hw/arm/allwinner-h3.c +7 -0
@@ -196,6 +196,9 @@ static void aw_h3_init(Object *obj)sysbus_init_child_obj (obj,"cpucfg" , &s->cpucfg,sizeof (s->cpucfg),TYPE_AW_H3_CPUCFG ); + +sysbus_init_child_obj (obj,"sid" , &s->sid,sizeof (s->sid), +TYPE_AW_H3_SID ); }static void aw_h3_realize (DeviceState *dev,Error **errp)
@@ -332,6 +335,10 @@ static void aw_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
@@ -62,6 +62,10 @@ static void orangepi_init(MachineState *machine)exit (1 ); } +/* Setup SID properties */ +qdev_prop_set_string (DEVICE (&s->h3->sid),"identifier" , +"8100c002-0001-0002-0003-000044556677" ); +/* Mark H3 object realized */ object_property_set_bool (OBJECT (s->h3), true,"realized" , &error_abort);if (error_abort !=NULL ) {
hw/misc/allwinner-h3-sid.c new file +179 -0
179 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-clk.o obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-cpucfg.o common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-syscon.o +common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-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_h3_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "H3-CPUCFG: c allwinner_h3_cpucfg_read(uint64_t offset, uint64_t data, unsigned size) "H3-CPUCFG: read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 allwinner_h3_cpucfg_write(uint64_t offset, uint64_t data, unsigned size) "H3-CPUCFG: write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 +# allwinner-h3-sid.c +allwinner_h3_sid_read(uint64_t offset, uint64_t data, unsigned size) "H3-SID: read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 +allwinner_h3_sid_write(uint64_t offset, uint64_t data, unsigned size) "H3-SID: write: 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 v2 08/10] arm: allwinner-h3: add Security Identifier device
Hi Niek,
Quoted 89 lines · Niek Linnenbank
The Security Identifier device in Allwinner H3 System on Chip gives applications a per-board unique identifier. This commit adds support for the Allwinner H3 Security Identifier using a 128-bit UUID value as input.
Signed-off-by Niek Linnenbank <[email protected]>--- include/hw/arm/allwinner-h3.h | 2 + include/hw/misc/allwinner-h3-sid.h | 40 +++++++ hw/arm/allwinner-h3.c | 7 ++ hw/arm/orangepi.c | 4 + hw/misc/allwinner-h3-sid.c | 179 +++++++++++++++++++++++++++++ hw/misc/Makefile.objs | 1 + hw/misc/trace-events | 4 + 7 files changed, 237 insertions(+)create mode 100644
include/hw/misc/allwinner-h3-sid.hcreate mode 100644hw/misc/allwinner-h3-sid.cinclude/hw/arm/allwinner-h3.h +2
-0@@ -29,6 +29,7 @@#include "hw/misc/allwinner-h3-clk.h" #include "hw/misc/allwinner-h3-cpucfg.h" #include "hw/misc/allwinner-h3-syscon.h" +#include "hw/misc/allwinner-h3-sid.h" #include "target/arm/cpu.h" enum {@@ -77,6 +78,7 @@ typedef struct AwH3State {AwH3ClockState ccu;AwH3CpuCfgState cpucfg;AwH3SysconState syscon; +AwH3SidState sid;GICState gic;MemoryRegion sram_a1;MemoryRegion sram_a2;include/hw/misc/allwinner-h3-sid.h new file +40
-0@@ -0,0 +1,40 @@ +/* +* Allwinner H3 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_H3_SID_H +#define HW_MISC_ALLWINNER_H3_SID_H + +#include "hw/sysbus.h" +#include "qemu/uuid.h" + +#define TYPE_AW_H3_SID "allwinner-h3-sid" +#define AW_H3_SID (obj) OBJECT_CHECK(AwH3SidState, (obj), TYPE_AW_H3_SID) + +typedef struct AwH3SidState { +/*< private >*/ +SysBusDevice parent_obj; +/*< public >*/ + +MemoryRegion iomem; +uint32_t control; +uint32_t rdkey; +QemuUUID identifier; +}AwH3SidState ; + +#endif hw/arm/allwinner-h3.c +0
-0
hw/arm/allwinner-h3.c static void aw_h3_init(Object *obj) · line 201
Quoted 6 lines
hw/arm/allwinner-h3.c +3
-0@@ -196,6 +196,9 @@ static void aw_h3_init(Object *obj)sysbus_init_child_obj (obj,"cpucfg" , &s->cpucfg,sizeof (s->cpucfg),TYPE_AW_H3_CPUCFG ); + +sysbus_init_child_obj (obj,"sid" , &s->sid,sizeof (s->sid), +TYPE_AW_H3_SID );
Here add a property alias:
object_property_add_alias(obj, "identifier", OBJECT(&s->sid),
"identifier", &error_abort);Quoted 19 lines
hw/arm/allwinner-h3.c +4
-0}static void aw_h3_realize (DeviceState *dev,Error **errp)@@ -332,6 +335,10 @@ static void aw_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 67
Quoted 6 lines
hw/arm/orangepi.c +3
-0@@ -62,6 +62,10 @@ static void orangepi_init(MachineState *machine)exit (1 ); } +/* Setup SID properties */ +qdev_prop_set_string (DEVICE (&s->h3->sid),"identifier" , +"8100c002-0001-0002-0003-000044556677" );
And here use the alias:
qdev_prop_set_string(DEVICE(&s->h3), "identifier",
"8100c002-0001-0002-0003-000044556677");What means this value? Don't you want to be able to set it from command line?
Quoted 86 lines
hw/arm/orangepi.c +0
-0/* Mark H3 object realized */ object_property_set_bool (OBJECT (s->h3), true,"realized" , &error_abort);if (error_abort !=NULL ) {hw/misc/allwinner-h3-sid.c new file +77
-0@@ -0,0 +1,179 @@ +/* +* Allwinner H3 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-h3-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_h3_sid_read (void *opaque,hwaddr offset, +unsigned size) +{ +const AwH3SidState *s = (AwH3SidState *)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: bad read offset 0x%04x\n" , + __func__, (uint32_t )offset); +return 0 ; + } + +trace_allwinner_h3_sid_read (offset, val, size); + +return val; +} + +static void allwinner_h3_sid_write (void *opaque,hwaddr offset, +uint64_t val,unsigned size) +{ +AwH3SidState *s = (AwH3SidState *)opaque; + +trace_allwinner_h3_sid_write (offset, val, size); + +switch (offset) { +case REG_PRCTL :/* Control */ + s->control = val;
hw/misc/allwinner-h3-sid.c line 87
Quoted 10 lines
hw/misc/allwinner-h3-sid.c new file +10
-0+ +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 );
This is:
s->rdkey = ldl_le_p(&s->identifier.data[id]);
hw/misc/allwinner-h3-sid.c line 92
Quoted 5 lines
hw/misc/allwinner-h3-sid.c new file +5
-0+ } + } + s->control &= ~REG_PRCTL_WRITE ; +break ; +case REG_RDKEY :/* Read Key */
Read in a write()?
Maybe we can simply /* fall through */ LOG_GUEST_ERROR?
Quoted 6 lines
hw/misc/allwinner-h3-sid.c new file +6
-0+break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: bad write offset 0x%04x\n" , + __func__, (uint32_t )offset); +break ; + }
hw/misc/allwinner-h3-sid.c line 108
Quoted 10 lines
hw/misc/allwinner-h3-sid.c new file +10
-0+} + +static const MemoryRegionOps allwinner_h3_sid_ops = { + .read = allwinner_h3_sid_read, + .write = allwinner_h3_sid_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + .unaligned = false
'false' is the default value, maybe we can omit it?
Quoted 6 lines
hw/misc/allwinner-h3-sid.c new file +6
-0+ }, + .impl.min_access_size = 4, +}; + +static void allwinner_h3_sid_reset (DeviceState *dev) +{
hw/misc/allwinner-h3-sid.c line 124
Quoted 10 lines
hw/misc/allwinner-h3-sid.c new file +10
-0+AwH3SidState *s =AW_H3_SID (dev); + +/* Set default values for registers */ + s->control =0 ; + s->rdkey =0 ; +} + +static void allwinner_h3_sid_realize (DeviceState *dev,Error **errp) +{ +}
If you don't need realize(), just remove it. However maybe we want to check if the identifier is null, either warn/abort or generate a random one?
hw/misc/allwinner-h3-sid.c line 132
Quoted 8 lines
hw/misc/allwinner-h3-sid.c new file +8
-0+ +static void allwinner_h3_sid_init (Object *obj) +{ +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); +AwH3SidState *s =AW_H3_SID (obj); + +/* Fill UUID with zeroes by default */ +qemu_uuid_parse (UUID_NONE , &s->identifier);
AwH3SidState is zeroed just before this init() call. I think we don't need to zeroes the UUID again.
Quoted 75 lines
hw/misc/allwinner-h3-sid.c new file +47
-0+ +/* Memory mapping */ +memory_region_init_io (&s->iomem,OBJECT (s), &allwinner_h3_sid_ops, s, +TYPE_AW_H3_SID ,1 * KiB); +sysbus_init_mmio (sbd, &s->iomem); +} + +static Property allwinner_h3_sid_properties[] = { +DEFINE_PROP_UUID_NODEFAULT ("identifier" , AwH3SidState, identifier), +DEFINE_PROP_END_OF_LIST () +}; + +static const VMStateDescription allwinner_h3_sid_vmstate = { + .name ="allwinner-h3-sid" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (control, AwH3SidState), +VMSTATE_UINT32 (rdkey, AwH3SidState), +VMSTATE_END_OF_LIST () + } +}; + +static void allwinner_h3_sid_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->reset = allwinner_h3_sid_reset; + dc->realize = allwinner_h3_sid_realize; + dc->vmsd = &allwinner_h3_sid_vmstate; + dc->props = allwinner_h3_sid_properties; +} + +static const TypeInfo allwinner_h3_sid_info = { + .name =TYPE_AW_H3_SID , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_init = allwinner_h3_sid_init, + .instance_size =sizeof (AwH3SidState), + .class_init = allwinner_h3_sid_class_init, +}; + +static void allwinner_h3_sid_register (void ) +{ +type_register_static (&allwinner_h3_sid_info); +} + +type_init (allwinner_h3_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-clk.o obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-cpucfg.o common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-syscon.o +common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-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_h3_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "H3-CPUCFG: c allwinner_h3_cpucfg_read(uint64_t offset, uint64_t data, unsigned size) "H3-CPUCFG: read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 allwinner_h3_cpucfg_write(uint64_t offset, uint64_t data, unsigned size) "H3-CPUCFG: write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 +# allwinner-h3-sid.c +allwinner_h3_sid_read(uint64_t offset, uint64_t data, unsigned size) "H3-SID: read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 +allwinner_h3_sid_write(uint64_t offset, uint64_t data, unsigned size) "H3-SID: write: 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 v2 08/10] arm: allwinner-h3: add Security Identifier device
Hi Philippe,
Quoted 132 lines · Philippe Mathieu-Daudé
Hi Niek,
Quoted 15 lines · Niek Linnenbank
The Security Identifier device in Allwinner H3 System on Chip gives applications a per-board unique identifier. This commit adds support for the Allwinner H3 Security Identifier using a 128-bit UUID value as input.
Signed-off-by Niek Linnenbank <[email protected]>--- include/hw/arm/allwinner-h3.h | 2 + include/hw/misc/allwinner-h3-sid.h | 40 +++++++ hw/arm/allwinner-h3.c | 7 ++ hw/arm/orangepi.c | 4 + hw/misc/allwinner-h3-sid.c | 179 +++++++++++++++++++++++++++++ hw/misc/Makefile.objs | 1 + hw/misc/trace-events | 4 + 7 files changed, 237 insertions(+)Review
Quoted 4 lines
create mode 100644
include/hw/misc/allwinner-h3-sid.hcreate mode 100644hw/misc/allwinner-h3-sid.c(quoted diff) +0
-0
b/include/hw/arm/allwinner-h3.hReview
Quoted 20 lines
index
8128ae6131..c98c1972a6100644include/hw/arm/allwinner-h3.h +2
-0@@ -29,6 +29,7 @@#include "hw/misc/allwinner-h3-clk.h" #include "hw/misc/allwinner-h3-cpucfg.h" #include "hw/misc/allwinner-h3-syscon.h" +#include "hw/misc/allwinner-h3-sid.h" #include "target/arm/cpu.h" enum {@@ -77,6 +78,7 @@ typedef struct AwH3State {AwH3ClockState ccu;AwH3CpuCfgState cpucfg;AwH3SysconState syscon; +AwH3SidState sid;GICState gic;MemoryRegion sram_a1;MemoryRegion sram_a2;(quoted diff) +0
-0
b/include/hw/misc/allwinner-h3-sid.hQuoted 24 lines
new file mode 100644
index 0000000000..79c9a24459include/hw/misc/allwinner-h3-sid.h new file +17
-0@@ -0,0 +1,40 @@ +/* +* Allwinner H3 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-h3-sid.h
Quoted 9 lines
include/hw/misc/allwinner-h3-sid.h new file +9
-0+ +#ifndef HW_MISC_ALLWINNER_H3_SID_H +#define HW_MISC_ALLWINNER_H3_SID_H + +#include "hw/sysbus.h" +#include "qemu/uuid.h" + +#define TYPE_AW_H3_SID "allwinner-h3-sid" +#define AW_H3_SID (obj) OBJECT_CHECK(AwH3SidState, (obj),
TYPE_AW_H3_SID)Quoted 18 lines
include/hw/misc/allwinner-h3-sid.h new file +13
-0+ +typedef struct AwH3SidState { +/*< private >*/ +SysBusDevice parent_obj; +/*< public >*/ + +MemoryRegion iomem; +uint32_t control; +uint32_t rdkey; +QemuUUID identifier; +}AwH3SidState ; + +#endif hw/arm/allwinner-h3.c +0
-0hw/arm/allwinner-h3.c static void aw_h3_init(Object *obj) · line 201
Quoted 6 lines
hw/arm/allwinner-h3.c +3
-0@@ -196,6 +196,9 @@ static void aw_h3_init(Object *obj)sysbus_init_child_obj (obj,"cpucfg" , &s->cpucfg,sizeof (s->cpucfg),TYPE_AW_H3_CPUCFG ); + +sysbus_init_child_obj (obj,"sid" , &s->sid,sizeof (s->sid), +TYPE_AW_H3_SID );Here add a property alias:
object_property_add_alias(obj, "identifier", OBJECT(&s->sid), "identifier", &error_abort);hw/arm/allwinner-h3.c static void aw_h3_realize(DeviceState *dev, Error
Quoted 4 lines
hw/arm/allwinner-h3.c +0
-0}static void aw_h3_realize (DeviceState *dev,Error **errp)@@ -332,6 +335,10 @@ static void aw_h3_realize(DeviceState *dev, Error**errp)
hw/arm/allwinner-h3.c static void aw_h3_realize(DeviceState *dev, Error · line 336
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 16 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
-0@@ -62,6 +62,10 @@ static void orangepi_init(MachineState *machine)exit (1 ); }
Quoted 9 lines
hw/arm/orangepi.c static void orangepi_init(MachineState *machine) · line 67
Quoted 3 lines
hw/arm/orangepi.c +3
-0+/* Setup SID properties */ +qdev_prop_set_string (DEVICE (&s->h3->sid),"identifier" , +"8100c002-0001-0002-0003-000044556677" );And here use the alias:
qdev_prop_set_string(DEVICE(&s->h3), "identifier", "8100c002-0001-0002-0003-000044556677");
Ah OK, I see what you mean. The boards should be using the SoC object only and
not directly any of its sub devices, correct?
Quoted 4 lines
What means this value? Don't you want to be able to set it from command line?
The first word 0x02c00081 is the identifying word for the H3 SoC in the SID data.
After that come the per-device unique specific bytes. This is documented at the end of this page in 'Currently known SID's' on the linux-sunxi.org Wiki:
https://linux-sunxi.org/SID_Register_Guide
The remaining parts of this value I simply made up without any real meaning. And yes, it would in fact make sense to have the user be able to override it from the command line.
It is used by U-boot as an input for generating the MAC address. Linux also reads it, but I did not investigate
how it us used there. I think I did make a TODO of using a cmdline argument, but later forgot to actually implement it.
Do you have a suggestion how to best provide the command line argument? I do see '-device driver[,prop=value]'
is there in the --help for qemu-system-arm, but it looks like that should be used by the user for adding PCI / USB devices?
Quoted 109 lines
hw/arm/orangepi.c static void orangepi_init(MachineState *machine) · line 69
Quoted 2 lines
hw/arm/orangepi.c +0
-0/* Mark H3 object realized */ object_property_set_bool(OBJECT(s->h3), true, "realized",
&error_abort);Quoted 85 lines
hw/arm/orangepi.c +0
-0if (error_abort !=NULL ) {hw/misc/allwinner-h3-sid.c new file +17
-0@@ -0,0 +1,179 @@ +/* +* Allwinner H3 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-h3-sid.c new file +59
-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-h3-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_h3_sid_read (void *opaque,hwaddr offset, +unsigned size) +{ +const AwH3SidState *s = (AwH3SidState *)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: bad read offset 0x%04x\n" , + __func__, (uint32_t )offset); +return 0 ; + } + +trace_allwinner_h3_sid_read (offset, val, size); + +return val; +} + +static void allwinner_h3_sid_write (void *opaque,hwaddr offset, +uint64_t val,unsigned size) +{ +AwH3SidState *s = (AwH3SidState *)opaque; + +trace_allwinner_h3_sid_write (offset, val, size); + +switch (offset) { +case REG_PRCTL :/* Control */ + s->control = val;hw/misc/allwinner-h3-sid.c line 87
Quoted 10 lines
hw/misc/allwinner-h3-sid.c new file +10
-0+ +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 );This is:
s->rdkey = ldl_le_p(&s->identifier.data[id]);hw/misc/allwinner-h3-sid.c line 92
Quoted 5 lines
hw/misc/allwinner-h3-sid.c new file +5
-0+ } + } + s->control &= ~REG_PRCTL_WRITE ; +break ; +case REG_RDKEY :/* Read Key */
Quoted 4 lines
Read in a
write()?Maybe we can simply /* fall through */
LOG_GUEST_ERROR?
When writing this module, I looked at how U-Boot is using the SID registers and simply
named the registers after the names used by U-Boot. You can find this part in arch/arm/mach-sunxi/cpu_info.c:111,
functions sun8i_efuse_read() and sunxi_get_sid(). U-Boot defines SIDC_RDKEY, so I named the register also rdkey.
I used the U-Boot source because the Allwinner H3 datasheet does not document the registers. Later I
found the SID page on the linux-sunxi wiki that I mentioned earlier, and they also describe the same register names:
https://linux-sunxi.org/SID_Register_Guide
I suspect the information on this page is written based on the source code from the original SDK (which I did not study btw)
Quoted 11 lines
Quoted 11 lines
hw/misc/allwinner-h3-sid.c new file +10
-0+break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: bad write offset 0x%04x\n" , + __func__, (uint32_t )offset); +break ; + } +} + +static const MemoryRegionOps allwinner_h3_sid_ops = { + .read = allwinner_h3_sid_read,
Quoted 9 lines
hw/misc/allwinner-h3-sid.c line 108
Quoted 6 lines
hw/misc/allwinner-h3-sid.c new file +6
-0+ .write = allwinner_h3_sid_write, + .endianness = DEVICE_NATIVE_ENDIAN, + .valid = { + .min_access_size = 4, + .max_access_size =4 , + .unaligned = false'false' is the default value, maybe we can omit it?
Sure, I'll remove it.
Quoted 13 lines
Quoted 13 lines
hw/misc/allwinner-h3-sid.c new file +12
-0+ }, + .impl.min_access_size = 4, +}; + +static void allwinner_h3_sid_reset (DeviceState *dev) +{ +AwH3SidState *s =AW_H3_SID (dev); + +/* Set default values for registers */ + s->control =0 ; + s->rdkey =0 ; +}
Quoted 9 lines
hw/misc/allwinner-h3-sid.c line 124
Quoted 4 lines
hw/misc/allwinner-h3-sid.c new file +4
-0+ +static void allwinner_h3_sid_realize (DeviceState *dev,Error **errp) +{ +}If you don't need
realize(), just remove it. However maybe we want to check if the identifier is null, either warn/abort or generate a random one?
OK, removing it!
Quoted 13 lines
hw/misc/allwinner-h3-sid.c line 132
Quoted 9 lines
hw/misc/allwinner-h3-sid.c new file +8
-0+ +static void allwinner_h3_sid_init (Object *obj) +{ +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); +AwH3SidState *s =AW_H3_SID (obj); + +/* Fill UUID with zeroes by default */ +qemu_uuid_parse (UUID_NONE , &s->identifier);AwH3SidState is zeroed just before this
init()call. I think we don't need to zeroes the UUID again.
Ah OK, so you mean new objects are always zeroed. That makes it much easier indeed. Thanks, I'll remove those lines.
Quoted 71 lines
hw/misc/allwinner-h3-sid.c
Quoted 4 lines
hw/misc/allwinner-h3-sid.c new file +3
-0+ +/* Memory mapping */ + memory_region_init_io(&s->iomem, OBJECT(s), &allwinner_h3_sid_ops,s,
hw/misc/trace-events allwinner_h3_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t
Quoted 61 lines
hw/misc/allwinner-h3-sid.c new file +44
-0+ TYPE_AW_H3_SID, 1 * KiB); +sysbus_init_mmio (sbd, &s->iomem); +} + +static Property allwinner_h3_sid_properties[] = { +DEFINE_PROP_UUID_NODEFAULT ("identifier" , AwH3SidState, identifier), +DEFINE_PROP_END_OF_LIST () +}; + +static const VMStateDescription allwinner_h3_sid_vmstate = { + .name ="allwinner-h3-sid" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (control, AwH3SidState), +VMSTATE_UINT32 (rdkey, AwH3SidState), +VMSTATE_END_OF_LIST () + } +}; + +static void allwinner_h3_sid_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->reset = allwinner_h3_sid_reset; + dc->realize = allwinner_h3_sid_realize; + dc->vmsd = &allwinner_h3_sid_vmstate; + dc->props = allwinner_h3_sid_properties; +} + +static const TypeInfo allwinner_h3_sid_info = { + .name =TYPE_AW_H3_SID , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_init = allwinner_h3_sid_init, + .instance_size =sizeof (AwH3SidState), + .class_init = allwinner_h3_sid_class_init, +}; + +static void allwinner_h3_sid_register (void ) +{ +type_register_static (&allwinner_h3_sid_info); +} + +type_init (allwinner_h3_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-clk.o obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-cpucfg.o common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-syscon.o +common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-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_h3_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t
reset_addr) "H3-CPUCFG: chw/misc/trace-events allwinner_h3_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t · line 5
Quoted 1 line
hw/misc/trace-events +0
-0allwinner_h3_cpucfg_read(uint64_t offset, uint64_t data, unsignedsize) "H3-CPUCFG: read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
hw/misc/trace-events allwinner_h3_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t · line 6
Quoted 1 line
hw/misc/trace-events +0
-0allwinner_h3_cpucfg_write(uint64_t offset, uint64_t data, unsigned
Quoted 15 lines
size) "H3-CPUCFG: write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
hw/misc/trace-events allwinner_h3_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t · line 8
Quoted 3 lines
hw/misc/trace-events +2
-0+# allwinner-h3-sid.c +allwinner_h3_sid_read(uint64_t offset, uint64_t data, unsigned size)"H3-SID: read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
hw/misc/trace-events allwinner_h3_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t · line 9
Quoted 1 line
hw/misc/trace-events +1
-0+allwinner_h3_sid_write(uint64_t offset, uint64_t data, unsigned size)"H3-SID: write: 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"
Regards,
Niek
Signature · 1 line
Niek Linnenbank
Re: [PATCH v2 08/10] arm: allwinner-h3: add Security Identifier device
Quoted 164 lines · Niek Linnenbank
Hi Philippe,
On Tue, Dec 17, 2019 at 8:45 AM Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:
Hi Niek, On 12/17/19 12:35 AM, Niek Linnenbank wrote: > The Security Identifier device in Allwinner H3 System on Chip > gives applications a per-board unique identifier. This commit > adds support for the Allwinner H3 Security Identifier using > a 128-bit UUID value as input. > > Signed-off-by: Niek Linnenbank <[email protected] <mailto:[email protected]>> > --- > include/hw/arm/allwinner-h3.h | 2 + > include/hw/misc/allwinner-h3-sid.h | 40 +++++++ > hw/arm/allwinner-h3.c | 7 ++ > hw/arm/orangepi.c | 4 + > hw/misc/allwinner-h3-sid.c | 179 +++++++++++++++++++++++++++++ > hw/misc/Makefile.objs | 1 + > hw/misc/trace-events | 4 + > 7 files changed, 237 insertions(+) > create mode 100644 include/hw/misc/allwinner-h3-sid.h > create mode 100644 hw/misc/allwinner-h3-sid.c > > diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h > index 8128ae6131..c98c1972a6 100644 > --- a/include/hw/arm/allwinner-h3.h > +++ b/include/hw/arm/allwinner-h3.h > @@ -29,6 +29,7 @@ > #include "hw/misc/allwinner-h3-clk.h" > #include "hw/misc/allwinner-h3-cpucfg.h" > #include "hw/misc/allwinner-h3-syscon.h" > +#include "hw/misc/allwinner-h3-sid.h" > #include "target/arm/cpu.h" > > enum { > @@ -77,6 +78,7 @@ typedef struct AwH3State { > AwH3ClockState ccu; > AwH3CpuCfgState cpucfg; > AwH3SysconState syscon; > + AwH3SidState sid; > GICState gic; > MemoryRegion sram_a1; > MemoryRegion sram_a2; > diff --git a/include/hw/misc/allwinner-h3-sid.h b/include/hw/misc/allwinner-h3-sid.h > new file mode 100644 > index 0000000000..79c9a24459 > --- /dev/null > +++ b/include/hw/misc/allwinner-h3-sid.h > @@ -0,0 +1,40 @@ > +/* > + * Allwinner H3 Security ID emulation > + * > + * Copyright (C) 2019 Niek Linnenbank <[email protected] <mailto:[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_SID_H > +#define HW_MISC_ALLWINNER_H3_SID_H > + > +#include "hw/sysbus.h" > +#include "qemu/uuid.h" > + > +#define TYPE_AW_H3_SID "allwinner-h3-sid" > +#define AW_H3_SID(obj) OBJECT_CHECK(AwH3SidState, (obj), TYPE_AW_H3_SID) > + > +typedef struct AwH3SidState { > + /*< private >*/ > + SysBusDevice parent_obj; > + /*< public >*/ > + > + MemoryRegion iomem; > + uint32_t control; > + uint32_t rdkey; > + QemuUUID identifier; > +} AwH3SidState; > + > +#endif > diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c > index 1a9748ab2e..ba34f905cd 100644 > --- a/hw/arm/allwinner-h3.c > +++ b/hw/arm/allwinner-h3.c > @@ -196,6 +196,9 @@ static void aw_h3_init(Object *obj) > > sysbus_init_child_obj(obj, "cpucfg", &s->cpucfg, sizeof(s->cpucfg), > TYPE_AW_H3_CPUCFG); > + > + sysbus_init_child_obj(obj, "sid", &s->sid, sizeof(s->sid), > + TYPE_AW_H3_SID); Here add a property alias: object_property_add_alias(obj, "identifier", OBJECT(&s->sid), "identifier", &error_abort); > } > > static void aw_h3_realize(DeviceState *dev, Error **errp) > @@ -332,6 +335,10 @@ static void aw_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), > diff --git a/hw/arm/orangepi.c b/hw/arm/orangepi.c > index 62cefc8c06..b01c4b4f01 100644 > --- a/hw/arm/orangepi.c > +++ b/hw/arm/orangepi.c > @@ -62,6 +62,10 @@ static void orangepi_init(MachineState *machine) > exit(1); > } > > + /* Setup SID properties */ > + qdev_prop_set_string(DEVICE(&s->h3->sid), "identifier", > + "8100c002-0001-0002-0003-000044556677"); And here use the alias: qdev_prop_set_string(DEVICE(&s->h3), "identifier", "8100c002-0001-0002-0003-000044556677");Ah OK, I see what you mean. The boards should be using the SoC object only and not directly any of its sub devices, correct?
What means this value? Don't you want to be able to set it from command line?
The first word
0x02c00081is the identifying word for the H3 SoC in the SID data.
After that come the per-device unique specific bytes. This is documented at the end of this page in 'Currently known SID's' on the linux-sunxi.org <http://linux-sunxi.org> Wiki:
https://linux-sunxi.org/SID_Register_Guide
Quoted 7 lines
The remaining parts of this value I simply made up without any real meaning.
And yes, it would in fact make sense to have the user be able to override it from the command line. It is used by U-boot as an input for generating the MAC address. Linux also reads it, but I did not investigate how it us used there. I think I did make a TODO of using a cmdline argument, but later forgot to actually implement it.Do you have a suggestion how to best provide the command line argument? I do see '-device driver[,prop=value]' is there in the --help for qemu-system-arm, but it looks like that should be used by the user for adding PCI / USB devices?
Look for '-global' in the manpage:
-global driver.prop=value
-global driver=driver,property=property,value=value
Set default value of driver's property prop to value.
In particular, you can use this to set driver properties for devices which are created automatically by the machine model. To create a device which is not created automatically and set properties on it, use -device.
-global driver.prop=value is shorthand for -global driver=driver,property=prop,value=value.
So this should work for your device:
-global
allwinner-h3-sid.identifier=8100c002-0001-0002-0003-000044556677
Quoted 120 lines
> /* Mark H3 object realized */
> object_property_set_bool(OBJECT(s->h3), true, "realized",
&error_abort);
> if (error_abort != NULL) {
> diff --git a/hw/misc/allwinner-h3-sid.c b/hw/misc/allwinner-h3-sid.c
> new file mode 100644
> index 0000000000..c472f2bcc6
> --- /dev/null
> +++ b/hw/misc/allwinner-h3-sid.c
> @@ -0,0 +1,179 @@
> +/*
> + * Allwinner H3 Security ID emulation
> + *
> + * Copyright (C) 2019 Niek Linnenbank <[email protected]
<mailto:[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-h3-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_h3_sid_read(void *opaque, hwaddr offset,
> + unsigned size)
> +{
> + const AwH3SidState *s = (AwH3SidState *)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: bad read offset
0x%04x\n",
> + __func__, (uint32_t)offset);
> + return 0;
> + }
> +
> + trace_allwinner_h3_sid_read(offset, val, size);
> +
> + return val;
> +}
> +
> +static void allwinner_h3_sid_write(void *opaque, hwaddr offset,
> + uint64_t val, unsigned size)
> +{
> + AwH3SidState *s = (AwH3SidState *)opaque;
> +
> + trace_allwinner_h3_sid_write(offset, val, size);
> +
> + switch (offset) {
> + case REG_PRCTL: /* Control */
> + s->control = val;
> +
> + if ((s->control & REG_PRCTL_OP_LOCK) &&
> + (s->control & REG_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);
This is:
s->rdkey = ldl_le_p(&s->identifier.data[id]);
> + }
> + }
> + s->control &= ~REG_PRCTL_WRITE;
> + break;
> + case REG_RDKEY: /* Read Key */
Read in a write()?
Maybe we can simply /* fall through */ LOG_GUEST_ERROR?Quoted 7 lines
When writing this module, I looked at how U-Boot is using the SID registers and simply
named the registers after the names used by U-Boot. You can find this part inarch/arm/mach-sunxi/cpu_info.c:111, functionssun8i_efuse_read()andsunxi_get_sid(). U-Boot definesSIDC_RDKEY, so I named the register also rdkey. I used the U-Boot source because the Allwinner H3 datasheet does not document the registers. Later I found the SID page on the linux-sunxi wiki that I mentioned earlier, and they also describe the same register names:
Hmm this page describe this register as RW, odd. I think this is wrong because we deal with a fuse, and we program it via the REG_PRKEY register. Does Linux/U-Boot do write access to this register? We can start logging LOG_GUEST_ERROR, and correct it if we notice this register is really writable (which I doubt).
Quoted 2 lines
I suspect the information on this page is written based on the source code from the original SDK (which I did not study btw)
[...]
Re: [PATCH v2 08/10] arm: allwinner-h3: add Security Identifier device
Quoted 205 lines · Philippe Mathieu-Daudé
Quoted 59 lines · Niek Linnenbank
Hi Philippe,
On Tue, Dec 17, 2019 at 8:45 AM Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:
Hi Niek, On 12/17/19 12:35 AM, Niek Linnenbank wrote: > The Security Identifier device in Allwinner H3 System on Chip > gives applications a per-board unique identifier. This commit > adds support for the Allwinner H3 Security Identifier using > a 128-bit UUID value as input. > > Signed-off-by: Niek Linnenbank <[email protected] <mailto:[email protected]>> > --- > include/hw/arm/allwinner-h3.h | 2 + > include/hw/misc/allwinner-h3-sid.h | 40 +++++++ > hw/arm/allwinner-h3.c | 7 ++ > hw/arm/orangepi.c | 4 + > hw/misc/allwinner-h3-sid.c | 179 +++++++++++++++++++++++++++++ > hw/misc/Makefile.objs | 1 + > hw/misc/trace-events | 4 + > 7 files changed, 237 insertions(+) > create mode 100644 include/hw/misc/allwinner-h3-sid.h > create mode 100644 hw/misc/allwinner-h3-sid.c > > diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h > index 8128ae6131..c98c1972a6 100644 > --- a/include/hw/arm/allwinner-h3.h > +++ b/include/hw/arm/allwinner-h3.h > @@ -29,6 +29,7 @@ > #include "hw/misc/allwinner-h3-clk.h" > #include "hw/misc/allwinner-h3-cpucfg.h" > #include "hw/misc/allwinner-h3-syscon.h" > +#include "hw/misc/allwinner-h3-sid.h" > #include "target/arm/cpu.h" > > enum { > @@ -77,6 +78,7 @@ typedef struct AwH3State { > AwH3ClockState ccu; > AwH3CpuCfgState cpucfg; > AwH3SysconState syscon; > + AwH3SidState sid; > GICState gic; > MemoryRegion sram_a1; > MemoryRegion sram_a2; > diff --git a/include/hw/misc/allwinner-h3-sid.h b/include/hw/misc/allwinner-h3-sid.h > new file mode 100644 > index 0000000000..79c9a24459 > --- /dev/null > +++ b/include/hw/misc/allwinner-h3-sid.h > @@ -0,0 +1,40 @@ > +/* > + * Allwinner H3 Security ID emulation > + *Quoted 8 lines
> + * Copyright (C) 2019 Niek Linnenbank <[email protected] <mailto:[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 theLicense, or
Quoted 3 lines
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will beuseful,
Quoted 5 lines
> + * 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 PublicLicense
Quoted 34 lines
> + * along with this program. If not, see <http://www.gnu.org/licenses/>. > + */ > + > +#ifndef HW_MISC_ALLWINNER_H3_SID_H > +#define HW_MISC_ALLWINNER_H3_SID_H > + > +#include "hw/sysbus.h" > +#include "qemu/uuid.h" > + > +#define TYPE_AW_H3_SID "allwinner-h3-sid" > +#define AW_H3_SID(obj) OBJECT_CHECK(AwH3SidState, (obj), TYPE_AW_H3_SID) > + > +typedef struct AwH3SidState { > + /*< private >*/ > + SysBusDevice parent_obj; > + /*< public >*/ > + > + MemoryRegion iomem; > + uint32_t control; > + uint32_t rdkey; > + QemuUUID identifier; > +} AwH3SidState; > + > +#endif > diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c > index 1a9748ab2e..ba34f905cd 100644 > --- a/hw/arm/allwinner-h3.c > +++ b/hw/arm/allwinner-h3.c > @@ -196,6 +196,9 @@ static void aw_h3_init(Object *obj) > > sysbus_init_child_obj(obj, "cpucfg", &s->cpucfg, sizeof(s->cpucfg),Quoted 8 lines
> TYPE_AW_H3_CPUCFG); > + > + sysbus_init_child_obj(obj, "sid", &s->sid, sizeof(s->sid), > + TYPE_AW_H3_SID); Here add a property alias: object_property_add_alias(obj, "identifier",
OBJECT(&s->sid),Quoted 10 lines
"identifier", &error_abort); > } > > static void aw_h3_realize(DeviceState *dev, Error **errp) > @@ -332,6 +335,10 @@ static void aw_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]);Quoted 8 lines
> > + /* 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],
Quoted 6 lines
> qdev_get_gpio_in(DEVICE(&s->gic), > diff --git a/hw/arm/orangepi.c b/hw/arm/orangepi.c > index 62cefc8c06..b01c4b4f01 100644 > --- a/hw/arm/orangepi.c > +++ b/hw/arm/orangepi.c > @@ -62,6 +62,10 @@ static void orangepi_init(MachineState*machine)
Quoted 11 lines
> exit(1); > } > > + /* Setup SID properties */ > + qdev_prop_set_string(DEVICE(&s->h3->sid), "identifier", > + "8100c002-0001-0002-0003-000044556677"); And here use the alias: qdev_prop_set_string(DEVICE(&s->h3), "identifier","8100c002-0001-0002-0003-000044556677");
Quoted 8 lines
Ah OK, I see what you mean. The boards should be using the SoC object only and
not directly any of its sub devices, correct?What means this value? Don't you want to be able to set it from
command
Quoted 10 lines
line?
The first word
0x02c00081is the identifying word for the H3 SoC in the SID data.
After that come the per-device unique specific bytes. This is documented at the end of this page in 'Currently known SID's' on the linux-sunxi.org <http://linux-sunxi.org> Wiki:
https://linux-sunxi.org/SID_Register_GuideThe remaining parts of this value I simply made up without any real
meaning.
Quoted 11 lines
And yes, it would in fact make sense to have the user be able to override it from the command line.
It is used by U-boot as an input for generating the MAC address. Linux also reads it, but I did not investigate
how it us used there. I think I did make a TODO of using a cmdline argument, but later forgot to actually implement it.Do you have a suggestion how to best provide the command line argument? I do see '-device driver[,prop=value]'
is there in the --help for qemu-system-arm, but it looks like that should be used by the user for adding PCI / USB devices?Look for '-global' in the manpage:
-global driver.prop=value
-global driver=driver,property=property,value=valueSet default value of driver's property prop to value.
In particular, you can use this to set driver properties for devices which are created automatically by the machine model. To create a device which is not created automatically and set properties on it, use -device.
Quoted 8 lines
-global driver.prop=value is shorthand for -global driver=driver,property=prop,value=value.
So this should work for your device:
-global
allwinner-h3-sid.identifier=8100c002-0001-0002-0003-000044556677
Thanks, I tried this, however currently its not applied when used. I think its because the orangepi.c file sets the property as well.
Its not a blocking problem if the user can't override the SID value, but it would be a nice-to-have.
U-Boot uses its value for MAC generation and that can be overridden as well by U-Boot itself.
Quoted 136 lines
Quoted 7 lines
> /* Mark H3 object realized */ > object_property_set_bool(OBJECT(s->h3), true, "realized", &error_abort); > if (error_abort != NULL) { > diff --git a/hw/misc/allwinner-h3-sid.c
b/hw/misc/allwinner-h3-sid.cQuoted 8 lines
> new file mode 100644 > index 0000000000..c472f2bcc6 > --- /dev/null > +++ b/hw/misc/allwinner-h3-sid.c > @@ -0,0 +1,179 @@ > +/* > + * Allwinner H3 Security ID emulation > + *Quoted 8 lines
> + * Copyright (C) 2019 Niek Linnenbank <[email protected] <mailto:[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 theLicense, or
Quoted 3 lines
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will beuseful,
Quoted 5 lines
> + * 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 PublicLicense
Quoted 21 lines
> + * 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-h3-sid.h" > +#include "trace.h" > + > +/* SID register offsets */ > +enum { > + REG_PRCTL = 0x40, /* Control */ > + REG_RDKEY = 0x60, /* Read Key */ > +};Quoted 8 lines
> + > +/* SID register flags */ > +enum { > + REG_PRCTL_WRITE = 0x0002, /* Unknown write flag */ > + REG_PRCTL_OP_LOCK = 0xAC00, /* Lock operation */ > +}; > + > +static uint64_t allwinner_h3_sid_read(void *opaque, hwaddroffset,
Quoted 71 lines
> + unsigned size) > +{ > + const AwH3SidState *s = (AwH3SidState *)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: bad read offset 0x%04x\n", > + __func__, (uint32_t)offset); > + return 0; > + } > + > + trace_allwinner_h3_sid_read(offset, val, size); > + > + return val; > +} > + > +static void allwinner_h3_sid_write(void *opaque, hwaddr offset, > + uint64_t val, unsigned size) > +{ > + AwH3SidState *s = (AwH3SidState *)opaque; > + > + trace_allwinner_h3_sid_write(offset, val, size); > + > + switch (offset) { > + case REG_PRCTL: /* Control */ > + s->control = val; > + > + if ((s->control & REG_PRCTL_OP_LOCK) && > + (s->control & REG_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); This is: s->rdkey = ldl_le_p(&s->identifier.data[id]); > + } > + } > + s->control &= ~REG_PRCTL_WRITE; > + break; > + case REG_RDKEY: /* Read Key */ Read in a write()? Maybe we can simply /* fall through */ LOG_GUEST_ERROR?When writing this module, I looked at how U-Boot is using the SID registers and simply
named the registers after the names used by U-Boot. You can find this part inarch/arm/mach-sunxi/cpu_info.c:111,
functionssun8i_efuse_read()andsunxi_get_sid(). U-Boot definesSIDC_RDKEY, so I named the register also rdkey.
I used the U-Boot source because the Allwinner H3 datasheet does not document the registers. Later I
found the SID page on the linux-sunxi wiki that I mentioned earlier, and they also describe the same register names:
Quoted 9 lines
Quoted 1 line
Hmm this page describe this register as RW, odd. I think this is wrong because we deal with a fuse, and we program it via the
REG_PRKEYregister. Does Linux/U-Boot do write access to this register? We can start loggingLOG_GUEST_ERROR, and correct it if we notice this register is really writable (which I doubt).
Yes it seems so. The PRCTL is the "Control" register (R/W) and the RDKEY the "Data" register (RO).
You can see the Linux implementation in drivers/nvmem/sunxi_sid.c For U-Boot the file is in arch/arm/mach-sunxi/cpu_info.c, functions sunxi_get_sid and sun8i_efuse_read.
Regards,
Niek
Quoted 6 lines
Quoted 3 lines
I suspect the information on this page is written based on the source code from the original SDK (which I did not study btw)
[...]
Signature · 1 line
Niek Linnenbank
PATCH v2 9/10 arm: allwinner-h3: add SD/MMC host controller
In reply to Niek LinnenbankThe Allwinner H3 System on Chip contains an integrated storage controller for Secure Digital (SD) and Multi Media Card (MMC) interfaces. This commit adds support for the Allwinner H3 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
--- include/hw/arm/allwinner-h3.h | 2 + include/hw/sd/allwinner-h3-sdhost.h | 71 +++ hw/arm/allwinner-h3.c | 16 + hw/arm/orangepi.c | 15 + hw/sd/allwinner-h3-sdhost.c | 813 ++++++++++++++++++++++++++++ hw/sd/Makefile.objs | 1 + hw/sd/trace-events | 7 + 7 files changed, 925 insertions(+) create mode 100644 include/hw/sd/allwinner-h3-sdhost.h create mode 100644 hw/sd/allwinner-h3-sdhost.c
include/hw/arm/allwinner-h3.h +2 -0
@@ -30,6 +30,7 @@#include "hw/misc/allwinner-h3-cpucfg.h" #include "hw/misc/allwinner-h3-syscon.h" #include "hw/misc/allwinner-h3-sid.h" +#include "hw/sd/allwinner-h3-sdhost.h" #include "target/arm/cpu.h" enum {
@@ -79,6 +80,7 @@ typedef struct AwH3State {AwH3CpuCfgState cpucfg;AwH3SysconState syscon;AwH3SidState sid; +AwH3SDHostState mmc0;GICState gic;MemoryRegion sram_a1;MemoryRegion sram_a2;
include/hw/sd/allwinner-h3-sdhost.h new file +71 -0
71 lines not on this page · raw message
hw/arm/allwinner-h3.c +16 -0
@@ -199,6 +199,9 @@ static void aw_h3_init(Object *obj)sysbus_init_child_obj (obj,"sid" , &s->sid,sizeof (s->sid),TYPE_AW_H3_SID ); + +sysbus_init_child_obj (obj,"mmc0" , &s->mmc0,sizeof (s->mmc0), +TYPE_AW_H3_SDHOST ); }static void aw_h3_realize (DeviceState *dev,Error **errp)
@@ -339,6 +342,19 @@ static void aw_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); +if (error_abort) { +error_propagate (errp, error_abort); +return ; + } +/* 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 +15 -0
@@ -38,6 +38,10 @@ typedef struct OrangePiState {static void orangepi_init (MachineState *machine) {OrangePiState *s =g_new (OrangePiState,1 ); +DriveInfo *di; +BlockBackend *blk; +BusState *bus; +DeviceState *carddev;/* Only allow Cortex-A7 for this board */ if (strcmp (machine->cpu_type,ARM_CPU_TYPE_NAME ("cortex-a7" )) !=0 ) {
@@ -73,6 +77,16 @@ static void orangepi_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->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); +/* RAM */ if (machine->ram_size >1 * GiB) { error_report("Requested ram size is too large for this machine: "
@@ -95,6 +109,7 @@ 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 ;
hw/sd/allwinner-h3-sdhost.c new file +813 -0
813 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-h3-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-h3-sdhost.c +aw_h3_sdhost_set_inserted(bool inserted) "inserted %u" +aw_h3_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 +aw_h3_sdhost_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 +aw_h3_sdhost_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 +aw_h3_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
PATCH v2 10/10 arm: allwinner-h3: add EMAC ethernet device
In reply to Niek LinnenbankThe Allwinner H3 System on Chip includes an Ethernet MAC (EMAC) which provides 10M/100M/1000M Ethernet connectivity. This commit adds support for the Allwinner H3 EMAC, including emulation for the following functionality:
* DMA transfers
* MII interface
* Transmit CRC calculation
--- include/hw/arm/allwinner-h3.h | 2 + include/hw/net/allwinner-h3-emac.h | 67 +++ hw/arm/allwinner-h3.c | 13 + hw/arm/orangepi.c | 7 + hw/net/allwinner-h3-emac.c | 831 +++++++++++++++++++++++++++++ hw/arm/Kconfig | 1 + hw/net/Kconfig | 3 + hw/net/Makefile.objs | 1 + hw/net/trace-events | 10 + 9 files changed, 935 insertions(+) create mode 100644 include/hw/net/allwinner-h3-emac.h create mode 100644 hw/net/allwinner-h3-emac.c
include/hw/arm/allwinner-h3.h +2 -0
@@ -31,6 +31,7 @@#include "hw/misc/allwinner-h3-syscon.h" #include "hw/misc/allwinner-h3-sid.h" #include "hw/sd/allwinner-h3-sdhost.h" +#include "hw/net/allwinner-h3-emac.h" #include "target/arm/cpu.h" enum {
@@ -81,6 +82,7 @@ typedef struct AwH3State {AwH3SysconState syscon;AwH3SidState sid;AwH3SDHostState mmc0; +AwH3EmacState emac;GICState gic;MemoryRegion sram_a1;MemoryRegion sram_a2;
include/hw/net/allwinner-h3-emac.h new file +67 -0
67 lines not on this page · raw message
hw/arm/allwinner-h3.c +13 -0
@@ -202,6 +202,9 @@ static void aw_h3_init(Object *obj)sysbus_init_child_obj (obj,"mmc0" , &s->mmc0,sizeof (s->mmc0),TYPE_AW_H3_SDHOST ); + +sysbus_init_child_obj (obj,"emac" , &s->emac,sizeof (s->emac), +TYPE_AW_H3_EMAC ); }static void aw_h3_realize (DeviceState *dev,Error **errp)
@@ -355,6 +358,16 @@ static void aw_h3_realize(DeviceState *dev, Error **errp)return ; } +/* EMAC */ +if (nd_table[0 ].used) { +qemu_check_nic_model (&nd_table[0 ],TYPE_AW_H3_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 +7 -0
@@ -70,6 +70,13 @@ static void orangepi_init(MachineState *machine)qdev_prop_set_string (DEVICE (&s->h3->sid),"identifier" ,"8100c002-0001-0002-0003-000044556677" ); +/* Setup EMAC properties */ +object_property_set_int (OBJECT (&s->h3->emac),1 ,"phy-addr" , &error_abort); +if (error_abort !=NULL ) { +error_reportf_err (error_abort,"Couldn't set phy address: " ); +exit (1 ); + } +/* Mark H3 object realized */ object_property_set_bool (OBJECT (s->h3), true,"realized" , &error_abort);if (error_abort !=NULL ) {
hw/net/allwinner-h3-emac.c new file +831 -0
831 lines not on this page · raw message
hw/arm/Kconfig +1 -0
@@ -294,6 +294,7 @@ config ALLWINNER_A10 config ALLWINNER_H3 bool select ALLWINNER_A10_PIT + select ALLWINNER_H3_EMAC select SERIAL select ARM_TIMER select ARM_GIC
hw/net/Kconfig +3 -0
@@ -74,6 +74,9 @@ config MIPSNET config ALLWINNER_EMAC bool +config ALLWINNER_H3_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_H3_EMAC) += allwinner-h3-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-h3-emac.c +aw_h3_emac_mii_write_reg(uint32_t reg, uint32_t value) "MII write: reg=0x%" PRIx32 " value=0x%" PRIx32 +aw_h3_emac_mii_read_reg(uint32_t reg, uint32_t value) "MII read: reg=0x%" PRIx32 " value=0x%" PRIx32 +aw_h3_emac_receive(uint32_t desc, uint32_t paddr, uint32_t bytes) "RX packet: desc=0x%" PRIx32 " paddr=0x%" PRIx32 " bytes=%" PRIu32 +aw_h3_emac_transmit(uint32_t desc, uint32_t paddr, uint32_t bytes) "TX packet: desc=0x%" PRIx32 " paddr=0x%" PRIx32 " bytes=%" PRIu32 +aw_h3_emac_reset(void) "HW reset" +aw_h3_emac_set_link(bool active) "Set link: active=%u" +aw_h3_emac_read(uint64_t offset, uint64_t val) "MMIO read: offset=0x%" PRIx64 " value=0x%" PRIx64 +aw_h3_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
Hi,
Here a short status report of this patch series.
For V3 update I already prepared the following:
- reworked all review comments from Philippe, except:
- patch#8: question for the SID, whether command-line override is
required (and how is the best way for machine-specific cli arg?) [1]
- added BootROM support, allows booting with only specifying -sd <IMG>
- added SDRAM controller driver, for U-Boot SPL
- added Allwinner generic RTC driver (for both Cubieboard and OrangePi PC, supports sun4i, sun6i, sun7i)
- small fixes for EMAC
My current TODO:
- integrate Philips acceptance tests in the series
- integrate Philips work for generalizing the Allwinner timer, and finish
it
- test and fix BSD targets (NetBSD, FreeBSD) [2, 3]
- further generalize the series to cover very similar SoCs: H2+, H5
Does anyone have more comments/requests for the V3 update?
[1] https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg04049.html
[2] https://wiki.netbsd.org/ports/evbarm/allwinner/
[3]
https://wiki.freebsd.org/action/show/arm/Allwinner?action=show&redirect=FreeBSD%2Farm%2FAllwinner
Quoted 207 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
* 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) and mainline U-Boot are known to work. The SD/MMC code is tested using bonnie++ and various tools such as fsck, dd and fdisk. The EMAC is verified with iperf3 using -netdev socket.
To build a Linux mainline kernel that can be booted by the Orange Pi PC machine, simply configure the kernel using the
sunxi_defconfigconfiguration:$ ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make mrproper $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make sunxi_defconfigTo 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 menuconfigNavigate to the following item, enable it and save your configuration:
Device Drivers > USB support > USB Mass Storage supportBuild the Linux kernel with:
$ ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make -j5To boot the newly build linux kernel in QEMU with the Orange Pi PC machine, use:
$ qemu-system-arm -M orangepi-pc -m 512 -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.dtbNote that this kernel does not have a root filesystem. You may provide it with an official Orange Pi PC image [1] either as an SD card or as USB mass storage. 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 -m 512 -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.imgAlternatively, you can also choose to build and boot a recent buildroot [2] using the
orangepi_pc_defconfigor Armbian image [3] for Orange Pi PC. To attach 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=stickU-Boot mainline can be build and configured using the
orangepi_pc_defconfigusing similar commands as describe above for Linux. 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 -m 512 -nic user -nographic \ -kernel /path/to/uboot/u-boot -sd disk.imgUse the following U-boot commands to load and boot a Linux kernel from SD card:
-> setenv bootargs console=ttyS0,115200
-> ext2load mmc 00x42000000zImage
-> ext2load mmc 00x43000000sun8i-h3-orangepi-pc.dtb
-> bootz0x42000000-0x43000000Looking forward to your review comments. I will do my best to update the patches where needed.
===== CHANGELOG =====
v2:
*hw/arm/allwinner-h3.c: use cpus array in AwH3State instead ofobject_new()
*hw/arm/allwinner-h3.c: useerror_abortinaw_h3_realize()
*hw/arm/allwinner-h3.c: useqdev_init_nofail()inaw_h3_realize()
*hw/arm/allwinner-h3.c: useqdev_get_gpio_in()instead of irq array
*hw/arm/allwinner-h3.c: add all missing unimplemented devices (memory
map is complete)
*hw/arm/allwinner-h3.c: add UART1, UART2, UART3 and remove 'if
(serial_hd(...))'
*hw/arm/allwinner-h3.c: remove sysbusdev variable and useSYS_BUS_DEVICE()directly
*include/hw/arm/allwinner-h3.h: move PPI/SPI defines toallwinner-h3.c
as enum
*include/hw/arm/allwinner-h3.h: replace mem base/size defines with enum
and memmap (likeaspeed_soc.h)
*hw/arm/orangepi.c: Only allow Cortex-A7 inmachine->cpu_type
*hw/arm/orangepi.c: Setmc->default_cpu_typetoARM_CPU_TYPE_NAME("cortex-a7")
*hw/arm/orangepi.c: Useerror_abortinorangepi_init()
*hw/arm/orangepi.c: only allow maximum 1GiB RAM
*hw/arm/orangepi.c: renamed machine name to 'orangepi-pc'
*hw/arm/orangepi.c: removemc->ignore_memory_transaction_failures= true
*hw/arm/orangepi.c: remove unnecessary check for 'sd-bus'
*hw/net/allwinner-h3-emac.c: useAW_H3_EMAC()for opaque in read/write
functions
*hw/sd/allwinner-h3-sdhost.c: replace register defines with enums
*hw/sd/allwinner-h3-sdhost.c: remove 'irq_en' and useif()to set 'irq'
inupdate_irqfunction
*hw/sd/allwinner-h3-sdhost.c: simplified if (rlen==) conditions insend_commandfunction
*hw/sd/allwinner-h3-sdhost.c: use KiB macro to setdesc->size
*hw/sd/allwinner-h3-sdhost.c: useARRAY_SIZE()macro in reset function
*hw/misc/allwinner-h3-sid.c: replace randomized identifier with QemuUUID
property
*hw/misc/allwinner-h3-sid.c: add tracing for read/write functions
*hw/misc/allwinner-h3-sid.c: fix incorrect usage of
REG_PRCTL_OP_LOCK/REG_PRCTL_WRITE
* hw/misc/trace-events: add allwinner_h3_cpucfg* entries in correct patch
(#7)
* hw/*/trace-events: use PRIu32/PRIx32 macros for size and max fields
*hw/*/allwinner-h3-*.c: set .impl.min_access_size = 4 to restrict MMIO
access to 32-bit aligned
*hw/*/allwinner-h3-*.c: replace register defines with enums
*hw/*/allwinner-h3-*.c: set VMStateDescription.name with inline string
(dont use TYPE macro)
*include/hw/*/allwinner-h3-*.h: removeMEM_SIZEdefine and use size
inline in the source file
*target/arm/arm-powerctl.c: invokearm_rebuild_hflags()after setting
CP15 bitsWith kind regards,
Niek Linnenbank
[1] http://www.orangepi.org/downloadresources/
[2] https://buildroot.org/download.html
[3] https://www.armbian.com/orange-pi-pc/Niek Linnenbank (10):
hw: arm: add Allwinner H3 System-on-Chip
hw: arm: add Xunlong Orange Pi PC machine
arm: allwinner-h3: add Clock Control Unit
arm: allwinner-h3: add USB host controller
arm: allwinner-h3: add System Control module arm/arm-powerctl: rebuild hflags after setting CP15 bits inarm_set_cpu_on()arm: allwinner-h3: add CPU Configuration module
arm: allwinner-h3: add Security Identifier device
arm: allwinner-h3: add SD/MMC host controller
arm: allwinner-h3: add EMAC ethernet devicedefault-configs/arm-softmmu.mak | 1 + hw/usb/hcd-ehci.h | 1 + include/hw/arm/allwinner-h3.h | 93 +++ include/hw/misc/allwinner-h3-clk.h | 40 ++ include/hw/misc/allwinner-h3-cpucfg.h | 42 ++ include/hw/misc/allwinner-h3-sid.h | 40 ++ include/hw/misc/allwinner-h3-syscon.h | 42 ++ include/hw/net/allwinner-h3-emac.h | 67 +++ include/hw/sd/allwinner-h3-sdhost.h | 71 +++ hw/arm/allwinner-h3.c | 442 ++++++++++++++ hw/arm/orangepi.c | 127 ++++ hw/misc/allwinner-h3-clk.c | 238 ++++++++ hw/misc/allwinner-h3-cpucfg.c | 288 +++++++++ hw/misc/allwinner-h3-sid.c | 179 ++++++ hw/misc/allwinner-h3-syscon.c | 146 +++++ hw/net/allwinner-h3-emac.c | 829 ++++++++++++++++++++++++++ hw/sd/allwinner-h3-sdhost.c | 813 +++++++++++++++++++++++++ hw/usb/hcd-ehci-sysbus.c | 17 + target/arm/arm-powerctl.c | 3 + MAINTAINERS | 8 + hw/arm/Kconfig | 9 + hw/arm/Makefile.objs | 1 + hw/misc/Makefile.objs | 4 + hw/misc/trace-events | 9 + hw/net/Kconfig | 3 + hw/net/Makefile.objs | 1 + hw/net/trace-events | 10 + hw/sd/Makefile.objs | 1 + hw/sd/trace-events | 7 + 29 files changed, 3532 insertions(+) create mode 100644 include/hw/arm/allwinner-h3.h create mode 100644 include/hw/misc/allwinner-h3-clk.h create mode 100644 include/hw/misc/allwinner-h3-cpucfg.h create mode 100644 include/hw/misc/allwinner-h3-sid.h create mode 100644 include/hw/misc/allwinner-h3-syscon.h create mode 100644 include/hw/net/allwinner-h3-emac.h create mode 100644 include/hw/sd/allwinner-h3-sdhost.h create mode 100644 hw/arm/allwinner-h3.c create mode 100644 hw/arm/orangepi.c create mode 100644 hw/misc/allwinner-h3-clk.c create mode 100644 hw/misc/allwinner-h3-cpucfg.c create mode 100644 hw/misc/allwinner-h3-sid.c create mode 100644 hw/misc/allwinner-h3-syscon.c create mode 100644 hw/net/allwinner-h3-emac.c create mode 100644 hw/sd/allwinner-h3-sdhost.c--
2.17.1
Signature · 1 line
Niek Linnenbank
Quoted 3 lines · Niek Linnenbank
Hi,
Here a short status report of this patch series.
Good idea!
Quoted 5 lines
For V3 update I already prepared the following:
- reworked all review comments from Philippe, except:
- patch#8: question for the SID, whether command-line override is
required (and how is the best way for machine-specific cli arg?) [1]
Answered recently.
Quoted 8 lines
- added BootROM support, allows booting with only specifying -sd <IMG>
- added SDRAM controller driver, for U-Boot SPL
- added Allwinner generic RTC driver (for both Cubieboard and OrangePi PC, supports sun4i, sun6i, sun7i)
- small fixes for EMACMy current TODO:
- integrate Philips acceptance tests in the series
You can queue them in your series, adding your Signed-off-by tag after mine. See:
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin
The sign-off is a simple line at the end of the explanation for the
patch, which certifies that you wrote it or otherwise have the right to pass it on as an open-source patch.
See point (c).
Quoted 2 lines
- integrate Philips work for generalizing the Allwinner timer, and
finish it
We can also do that later, and get your work merged first.
Quoted 8 lines
- test and fix BSD targets (NetBSD, FreeBSD) [2, 3]
- further generalize the series to cover very similar SoCs: H2+, H5Does anyone have more comments/requests for the V3 update?
[1] https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg04049.html
[2] https://wiki.netbsd.org/ports/evbarm/allwinner/
[3] https://wiki.freebsd.org/action/show/arm/Allwinner?action=show&redirect=FreeBSD%2Farm%2FAllwinner
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 3 lines · Niek Linnenbank
Hi,
Here a short status report of this patch series.
Good idea!
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
For V3 update I already prepared the following:
- reworked all review comments from Philippe, except:
- patch#8: question for the SID, whether command-line override is
required (and how is the best way for machine-specific cli arg?) [1]Answered recently.
Thanks!
Quoted 21 lines
Quoted 9 lines
- added BootROM support, allows booting with only specifying -sd <IMG>
- added SDRAM controller driver, for U-Boot SPL
- added Allwinner generic RTC driver (for both Cubieboard and OrangePi PC, supports sun4i, sun6i, sun7i)
- small fixes for EMACMy current TODO:
- integrate Philips acceptance tests in the seriesYou can queue them in your series, adding your Signed-off-by tag after mine. See:
The sign-off is a simple line at the end of the explanation for the
patch, which certifies that you wrote it or otherwise have the right to pass it on as an open-source patch.See point (c).
Quoted 8 lines
Ah that certainly helps. I'll read that page.
Quoted 2 lines
- integrate Philips work for generalizing the Allwinner timer, and
finish itWe can also do that later, and get your work merged first.
Ok that sounds very good! Agreed, lets do the timer work later.
Quoted 13 lines
Quoted 10 lines
- test and fix BSD targets (NetBSD, FreeBSD) [2, 3]
- further generalize the series to cover very similar SoCs: H2+, H5Does anyone have more comments/requests for the V3 update?
[1] https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg04049.html
[2] https://wiki.netbsd.org/ports/evbarm/allwinner/
[3]https://wiki.freebsd.org/action/show/arm/Allwinner?action=show&redirect=FreeBSD%2Farm%2FAllwinner
Signature · 1 line
Niek Linnenbank
Hi Philippe,
I'm almost ready to send out v3 here.
Now for documentation I'm not sure yet what to do:
1) Where should I place board documentation?
For example, the information that I wrote on the cover letter with
instructions on how to get the board up and running,
some description of the design, where to find more inforformation,
datasheet sources, etc. I don't yet see any documentation
for the other boards in the source. In my opinion, it is important to
keep that information somewhere, such that also in the future
the boards can still be properly maintained. Can I / shall I place a new
file like ./docs/hw/arm/orangepi.txt for that?
2) Is is allowed / encouraged to provide Doxygen-style comments in the
header files in include/hw/*?
I see that some of the API's have that, but the boards and devices
mostly are free of Doxygen-style comments.
It takes some work, but I think it can really help to give more insight
/ background info on how things are working
for the devices and boards. But if it's not preferred for QEMU, I'm fine
with that as well.
Regards,
Niek
Quoted 73 lines · Niek Linnenbank
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 3 lines · Niek Linnenbank
Hi,
Here a short status report of this patch series.
Good idea!
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
For V3 update I already prepared the following:
- reworked all review comments from Philippe, except:
- patch#8: question for the SID, whether command-line override is
required (and how is the best way for machine-specific cli arg?) [1]Answered recently.
Thanks!
Quoted 21 lines
Quoted 9 lines
- added BootROM support, allows booting with only specifying -sd <IMG>
- added SDRAM controller driver, for U-Boot SPL
- added Allwinner generic RTC driver (for both Cubieboard and OrangePi PC, supports sun4i, sun6i, sun7i)
- small fixes for EMACMy current TODO:
- integrate Philips acceptance tests in the seriesYou can queue them in your series, adding your Signed-off-by tag after mine. See:
The sign-off is a simple line at the end of the explanation for the
patch, which certifies that you wrote it or otherwise have the right to pass it on as an open-source patch.See point (c).
Quoted 8 lines
Ah that certainly helps. I'll read that page.
Quoted 2 lines
- integrate Philips work for generalizing the Allwinner timer, and
finish itWe can also do that later, and get your work merged first.
Ok that sounds very good! Agreed, lets do the timer work later.
Quoted 4 lines
Quoted 4 lines
- test and fix BSD targets (NetBSD, FreeBSD) [2, 3]
- further generalize the series to cover very similar SoCs: H2+, H5Quoted 9 lines
Quoted 6 lines
Does anyone have more comments/requests for the V3 update?
[1] https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg04049.html
[2] https://wiki.netbsd.org/ports/evbarm/allwinner/
[3]https://wiki.freebsd.org/action/show/arm/Allwinner?action=show&redirect=FreeBSD%2Farm%2FAllwinner
--
Niek Linnenbank
Signature · 1 line
Niek Linnenbank
Hi Niek,
Quoted 11 lines · Niek Linnenbank
Hi Philippe,
I'm almost ready to send out v3 here.
Now for documentation I'm not sure yet what to do:
1) Where should I place board documentation?
For example, the information that I wrote on the cover letter with
instructions on how to get the board up and running,
some description of the design, where to find more inforformation,
datasheet sources, etc. I don't yet see any documentation
We usually refer the datasheet in the implementation header, see:
$ git grep -F .pdf hw/ | wc -l 62
You can cite the datasheet globally in hw/arm/allwinner-h3.c, and then the particular chapters or source files in the other hw/*/allwinner-* files.
Quoted 4 lines
for the other boards in the source. In my opinion, it is important
to keep that information somewhere, such that also in the future
the boards can still be properly maintained. Can I / shall I place a
new file like./docs/hw/arm/orangepi.txtfor that?
See docs/microvm.rst which is a recent example of machine documentation, the obvious name is docs/orangepi.rst.
Maybe refer to this file in hw/arm/orangepi.c header for completeness.
Quoted 8 lines
2) Is is allowed / encouraged to provide Doxygen-style comments in the
header files ininclude/hw/*?
I see that some of the API's have that, but the boards and devices
mostly are free of Doxygen-style comments.
It takes some work, but I think it can really help to give more
insight / background info on how things are working
for the devices and boards. But if it's not preferred for QEMU, I'm
fine with that as well.
Documentation is certainly welcome!
There are 2 different schools over the codebase, one that document the declarations, and another that documents the implementation/definition.
I personally prefer to document the headers, which is where I look when I want to consume an API. The implementation school says this can lead to documentation getting outdated.
So if you are willing to document, I'd suggest to document your include/hw/ files.
Happy new year!
Phil.
Quoted 86 lines · On Mon, Dec 30, 2019 at 9:10 PM Niek Linnenbank <[email protected]…
On Mon, Dec 30, 2019 at 3:56 PM Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:
On 12/30/19 12:28 PM, Niek Linnenbank wrote:
> Hi,
>
> Here a short status report of this patch series.Good idea!
>
> For V3 update I already prepared the following:
> - reworked all review comments from Philippe, except:
> - patch#8: question for the SID, whether command-line
override is
> required (and how is the best way for machine-specific cli
arg?) [1]Answered recently.
Thanks!
> - added BootROM support, allows booting with only specifying
-sd <IMG>
> - added SDRAM controller driver, for U-Boot SPL
> - added Allwinner generic RTC driver (for both Cubieboard and
OrangePi
> PC, supports sun4i, sun6i, sun7i)
> - small fixes for EMAC
>
> My current TODO:
> - integrate Philips acceptance tests in the seriesYou can queue them in your series, adding your Signed-off-by tag after
mine. See:
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-originThe sign-off is a simple line at the end of the explanation
for the
patch, which certifies that you wrote it or otherwise have the right to
pass it on as an open-source patch.See point (c).
Ah that certainly helps. I'll read that page.
> - integrate Philips work for generalizing the Allwinner
timer, and
> finish itWe can also do that later, and get your work merged first.
Ok that sounds very good! Agreed, lets do the timer work later.
> - test and fix BSD targets (NetBSD, FreeBSD) [2, 3] > - further generalize the series to cover very similar SoCs:
H2+, H5
>
> Does anyone have more comments/requests for the V3 update? >
> [1]
https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg04049.html
> [2] https://wiki.netbsd.org/ports/evbarm/allwinner/
> [3]
>
https://wiki.freebsd.org/action/show/arm/Allwinner?action=show&redirect=FreeBSD%2Farm%2FAllwinner--
Niek LinnenbankSignature · 1 line
Niek Linnenbank
Hey Philippe,
Quoted 29 lines · Philippe Mathieu-Daudé
Hi Niek,
Quoted 11 lines · Niek Linnenbank
Hi Philippe,
I'm almost ready to send out v3 here.
Now for documentation I'm not sure yet what to do:
1) Where should I place board documentation?
For example, the information that I wrote on the cover letter with
instructions on how to get the board up and running,
some description of the design, where to find more inforformation,
datasheet sources, etc. I don't yet see any documentationWe usually refer the datasheet in the implementation header, see:
$ git grep -F .pdf hw/ | wc -l 62You can cite the datasheet globally in
hw/arm/allwinner-h3.c, and then the particular chapters or source files in the other hw/*/allwinner-* files.Quoted 4 lines
for the other boards in the source. In my opinion, it is important
to keep that information somewhere, such that also in the future
the boards can still be properly maintained. Can I / shall I place a
new file like./docs/hw/arm/orangepi.txtfor that?
Quoted 4 lines
See
docs/microvm.rstwhich is a recent example of machine documentation, the obvious name isdocs/orangepi.rst.Ah great, that is very helpful! I will use the
microvm.rstas example and
add a new file docs/orangepi.rst to document the board.
Quoted 16 lines
Maybe refer to this file in
hw/arm/orangepi.cheader for completeness.Quoted 8 lines
2) Is is allowed / encouraged to provide Doxygen-style comments in the
header files ininclude/hw/*?
I see that some of the API's have that, but the boards and devices
mostly are free of Doxygen-style comments.
It takes some work, but I think it can really help to give more
insight / background info on how things are working
for the devices and boards. But if it's not preferred for QEMU, I'm
fine with that as well.Documentation is certainly welcome!
There are 2 different schools over the codebase, one that document the declarations, and another that documents the implementation/definition.
Quoted 8 lines
I personally prefer to document the headers, which is where I look when I want to consume an API.
The implementation school says this can lead to documentation getting outdated.So if you are willing to document, I'd suggest to document your
include/hw/files.
OK, thanks for clarifying! Yes, I also prefer to have it in the header files, it
makes the most sense indeed.
Quoted 3 lines
Happy new year!
And happy new year to you as well Philippe!
Regards,
Niek
Quoted 95 lines
Phil.
Quoted 39 lines
On Mon, Dec 30, 2019 at 9:10 PM Niek Linnenbank <[email protected] <mailto:[email protected]>> wrote:
On Mon, Dec 30, 2019 at 3:56 PM Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:
On 12/30/19 12:28 PM, Niek Linnenbank wrote:
> Hi,
>
> Here a short status report of this patch series.Good idea!
>
> For V3 update I already prepared the following:
> - reworked all review comments from Philippe, except:
> - patch#8: question for the SID, whether command-line
override is
> required (and how is the best way for machine-specific cli
arg?) [1]Answered recently.
Thanks!
> - added BootROM support, allows booting with only specifying
-sd <IMG>
> - added SDRAM controller driver, for U-Boot SPL
> - added Allwinner generic RTC driver (for both Cubieboard and
OrangePi
> PC, supports sun4i, sun6i, sun7i)
> - small fixes for EMAC
>
> My current TODO:
> - integrate Philips acceptance tests in the seriesQuoted 4 lines
You can queue them in your series, adding your Signed-off-by tag after
mine. See:Quoted 21 lines
The sign-off is a simple line at the end of the explanation
for the
patch, which certifies that you wrote it or otherwise have the right to
pass it on as an open-source patch.See point (c).
Ah that certainly helps. I'll read that page.
> - integrate Philips work for generalizing the Allwinner
timer, and
> finish itWe can also do that later, and get your work merged first.
Ok that sounds very good! Agreed, lets do the timer work later.
Quoted 8 lines
> - test and fix BSD targets (NetBSD, FreeBSD) [2, 3]
> - further generalize the series to cover very similar SoCs:
H2+, H5
>
> Does anyone have more comments/requests for the V3 update? >
> [1]https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg04049.html
Quoted 4 lines
> [2] https://wiki.netbsd.org/ports/evbarm/allwinner/ > [3] >https://wiki.freebsd.org/action/show/arm/Allwinner?action=show&redirect=FreeBSD%2Farm%2FAllwinner
Quoted 11 lines
-- Niek Linnenbank--
Niek Linnenbank
Signature · 1 line
Niek Linnenbank