OpenRISC Virtual Machine
v2 cover OpenRISC Virtual Machine
Hello,
This is the OpenRISC Virtual Machine plaform which we are now using for OpenRISC CI such as the wireguard testing that Jason has been working on.
The first few patches help get OpenRISC QEMU ready for the virtual machine. There is one bug fix for GDB debugging there too.
Next we have the Virt patch followed by a separate patch to add PCI support which is split out because it's a bit easier to review that way I thought. The next few patches are fixes to get the Multicore platform stable, such as adding MTTCG support and fixing some interrupt and timer related bugs.
The platform is relatively stable now, but every few boots we get ~10 second soft lockups. My hunch is that this is another interrupt race condition where IPI's end up getting lost. However, overall the is much more stable than the SMP support we had before. So I want to submit this for review and maybe upstream it before tracking down these last issues which might take significant more time.
This is being tested with my or1k-virt kernel branch here:
https://github.com/stffrdhrn/linux/commits/or1k-virt
This tree has support for: OpenRISC PCI and virt_defconfig and an irqchip bug fix.
Changes since v1:
- Dropped semihosting support
- Added PCI support
- Added OpenRISC documentation
- Added OpenRISC support for MTTCG
- Support Configurating Goldfish RTC endianness
- Added a few bug fix patches
-Stafford
Jason A. Donenfeld (1):
hw/openrisc: virt: pass random seed to fdt
Stafford Horne (10):
hw/openrisc: Split re-usable boot time apis out to boot.c target/openrisc: Fix memory reading in debugger
goldfish_rtc: Add endianness property hw/openrisc: Add the OpenRISC virtual machine hw/openrisc: Add PCI bus support to virt hw/openrisc: Initialize timer time at startup target/openrisc: Add interrupted CPU to log target/openrisc: Enable MTTCG
target/openrisc: Interrupt handling fixes docs/system: openrisc: Add OpenRISC documentation
configs/devices/or1k-softmmu/default.mak | 1 + configs/targets/or1k-softmmu.mak | 1 + docs/system/openrisc/cpu-features.rst | 15 + docs/system/openrisc/emulation.rst | 17 + docs/system/openrisc/or1k-sim.rst | 43 ++ docs/system/openrisc/virt.rst | 50 ++ docs/system/target-openrisc.rst | 72 +++ docs/system/targets.rst | 1 + hw/openrisc/Kconfig | 12 + hw/openrisc/boot.c | 117 +++++ hw/openrisc/cputimer.c | 18 + hw/openrisc/meson.build | 2 + hw/openrisc/openrisc_sim.c | 106 +---- hw/openrisc/virt.c | 578 +++++++++++++++++++++++ hw/rtc/goldfish_rtc.c | 46 +- include/hw/openrisc/boot.h | 34 ++ include/hw/rtc/goldfish_rtc.h | 2 + target/openrisc/cpu.c | 1 - target/openrisc/cpu.h | 3 + target/openrisc/interrupt.c | 4 +- target/openrisc/mmu.c | 8 +- target/openrisc/sys_helper.c | 18 +- 22 files changed, 1035 insertions(+), 114 deletions(-) create mode 100644 docs/system/openrisc/cpu-features.rst create mode 100644 docs/system/openrisc/emulation.rst create mode 100644 docs/system/openrisc/or1k-sim.rst create mode 100644 docs/system/openrisc/virt.rst create mode 100644 docs/system/target-openrisc.rst create mode 100644 hw/openrisc/boot.c create mode 100644 hw/openrisc/virt.c create mode 100644 include/hw/openrisc/boot.h
Signature · 1 line
2.36.1
PATCH v2 1/11 hw/openrisc: Split re-usable boot time apis out to boot.c
These will be shared with the virt platform.
--- hw/openrisc/boot.c | 117 +++++++++++++++++++++++++++++++++++++ hw/openrisc/meson.build | 1 + hw/openrisc/openrisc_sim.c | 106 ++------------------------------- include/hw/openrisc/boot.h | 34 +++++++++++ 4 files changed, 158 insertions(+), 100 deletions(-) create mode 100644 hw/openrisc/boot.c create mode 100644 include/hw/openrisc/boot.h
hw/openrisc/boot.c new file +117 -0
@@ -0,0 +1,117 @@ +/* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* QEMU OpenRISC boot helpers. +* +* (c) 2022 Stafford Horne <[email protected]> +*/ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "exec/cpu-defs.h" +#include "elf.h" +#include "hw/loader.h" +#include "hw/openrisc/boot.h" +#include "sysemu/device_tree.h" +#include "sysemu/qtest.h" + +#include <libfdt.h> + +#define KERNEL_LOAD_ADDR 0x100 + +hwaddr openrisc_load_kernel (ram_addr_t ram_size, +const char *kernel_filename, +uint32_t *bootstrap_pc) +{ +long kernel_size; +uint64_t elf_entry; +uint64_t high_addr; +hwaddr entry; + +if (kernel_filename && !qtest_enabled ()) { + kernel_size =load_elf (kernel_filename,NULL ,NULL ,NULL , + &elf_entry,NULL , &high_addr,NULL ,1 , +EM_OPENRISC ,1 ,0 ); + entry = elf_entry; +if (kernel_size <0 ) { + kernel_size =load_uimage (kernel_filename, + &entry,NULL ,NULL ,NULL ,NULL ); + high_addr = entry + kernel_size; + } +if (kernel_size <0 ) { + kernel_size =load_image_targphys (kernel_filename, +KERNEL_LOAD_ADDR , + ram_size -KERNEL_LOAD_ADDR ); + high_addr =KERNEL_LOAD_ADDR + kernel_size; + } + +if (entry <=0 ) { + entry =KERNEL_LOAD_ADDR ; + } + +if (kernel_size <0 ) { +error_report ("couldn't load the kernel '%s'" , kernel_filename); +exit (1 ); + } + *bootstrap_pc = entry; + +return high_addr; + } +return 0 ; +} + +hwaddr openrisc_load_initrd (void *fdt,const char *filename, +hwaddr load_start,uint64_t mem_size) +{ +int size; +hwaddr start; + +/* We put the initrd right after the kernel; page aligned. */ + start =TARGET_PAGE_ALIGN (load_start); + + size =load_ramdisk (filename, start, mem_size - start); +if (size <0 ) { + size =load_image_targphys (filename, start, mem_size - start); +if (size <0 ) { +error_report ("could not load ramdisk '%s'" , filename); +exit (1 ); + } + } + +if (fdt) { +qemu_fdt_setprop_cell (fdt,"/chosen" , +"linux,initrd-start" , start); +qemu_fdt_setprop_cell (fdt,"/chosen" , +"linux,initrd-end" , start + size); + } + +return start + size; +} + +uint32_t openrisc_load_fdt (void *fdt,hwaddr load_start, +uint64_t mem_size) +{ +uint32_t fdt_addr; +int ret; +int fdtsize =fdt_totalsize (fdt); + +if (fdtsize <=0 ) { +error_report ("invalid device-tree" ); +exit (1 ); + } + +/* We put fdt right after the kernel and/or initrd. */ + fdt_addr =TARGET_PAGE_ALIGN (load_start); + + ret =fdt_pack (fdt); +/* Should only fail if we've built a corrupted tree */ +g_assert (ret ==0 ); +/* copy in the device tree */ +qemu_fdt_dumpdtb (fdt, fdtsize); + +rom_add_blob_fixed_as ("fdt" , fdt, fdtsize, fdt_addr, + &address_space_memory); + +return fdt_addr; +} +
hw/openrisc/meson.build +1 -0
@@ -1,5 +1,6 @@ openrisc_ss = ss.source_set() openrisc_ss.add(files('cputimer.c')) +openrisc_ss.add(files('boot.c')) openrisc_ss.add(when: 'CONFIG_OR1K_SIM', if_true: [files('openrisc_sim.c'), fdt]) hw_arch += {'openrisc': openrisc_ss}
hw/openrisc/openrisc_sim.c +6 -100
130 lines not on this page · raw message
include/hw/openrisc/boot.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* QEMU OpenRISC boot helpers. +* +* Copyright (c) 2022 Stafford Horne <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2 or later, as published by the Free Software Foundation. +* +* This program is distributed in the hope 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 OPENRISC_BOOT_H +#define OPENRISC_BOOT_H + +#include "exec/cpu-defs.h" + +hwaddr openrisc_load_kernel (ram_addr_t ram_size, +const char *kernel_filename, +uint32_t *bootstrap_pc); + +hwaddr openrisc_load_initrd (void *fdt,const char *filename, +hwaddr load_start,uint64_t mem_size); + +uint32_t openrisc_load_fdt (void *fdt,hwaddr load_start, +uint64_t mem_size); + +#endif /* OPENRISC_BOOT_H */
Signature · 1 line
2.36.1
PATCH v2 2/11 target/openrisc: Fix memory reading in debugger
In reply to Stafford HorneIn commit f0655423ca ("target/openrisc: Reorg tlb lookup") data and instruction TLB reads were combined. This, broke debugger reads where we first tried to map using the data tlb then fall back to the instruction tlb.
This patch replicates this logic by first requesting a PAGE_READ protection mapping then falling back to PAGE_EXEC.
--- target/openrisc/mmu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
target/openrisc/mmu.c +7 -1
@@ -148,7 +148,13 @@ hwaddr openrisc_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)case SR_DME |SR_IME :/* The mmu is definitely enabled. */ excp =get_phys_mmu (cpu, &phys_addr, &prot, addr, -PAGE_EXEC |PAGE_READ |PAGE_WRITE , +PAGE_READ , + (sr &SR_SM ) !=0 ); +if (!excp) { +return phys_addr; + } + excp =get_phys_mmu (cpu, &phys_addr, &prot, addr, +PAGE_EXEC , (sr &SR_SM ) !=0 );return excp ?-1 : phys_addr;
Signature · 1 line
2.36.1
PATCH v2 3/11 goldfish_rtc: Add endianness property
In reply to Stafford HorneAdd an endianness property to allow configuring the RTC as either native, little or big endian.
--- hw/rtc/goldfish_rtc.c | 46 ++++++++++++++++++++++++++++------- include/hw/rtc/goldfish_rtc.h | 2 ++ 2 files changed, 39 insertions(+), 9 deletions(-)
hw/rtc/goldfish_rtc.c +37 -9
@@ -216,14 +216,34 @@ static int goldfish_rtc_post_load(void *opaque, int version_id)return 0 ; } -static const MemoryRegionOps goldfish_rtc_ops = { - .read = goldfish_rtc_read, - .write = goldfish_rtc_write, - .endianness =DEVICE_NATIVE_ENDIAN , - .valid = { - .min_access_size =4 , - .max_access_size =4 - } +static const MemoryRegionOps goldfish_rtc_ops[3 ] = { + [DEVICE_NATIVE_ENDIAN ] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 + } + }, + [DEVICE_LITTLE_ENDIAN ] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 + } + }, + [DEVICE_BIG_ENDIAN ] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness =DEVICE_BIG_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 + } + }, };static const VMStateDescription goldfish_rtc_vmstate = {
@@ -265,7 +285,8 @@ static void goldfish_rtc_realize(DeviceState *d, Error **errp)SysBusDevice *dev =SYS_BUS_DEVICE (d);GoldfishRTCState *s =GOLDFISH_RTC (d); -memory_region_init_io (&s->iomem,OBJECT (s), &goldfish_rtc_ops, s, +memory_region_init_io (&s->iomem,OBJECT (s), + &goldfish_rtc_ops[s->endianness], s,"goldfish_rtc" ,0x24 );sysbus_init_mmio (dev, &s->iomem);
@@ -274,10 +295,17 @@ static void goldfish_rtc_realize(DeviceState *d, Error **errp) s->timer =timer_new_ns (rtc_clock, goldfish_rtc_interrupt, s); } +static Property goldfish_rtc_properties[] = { +DEFINE_PROP_UINT8 ("endianness" , GoldfishRTCState, endianness, +DEVICE_NATIVE_ENDIAN ), +DEFINE_PROP_END_OF_LIST (), +}; +static void goldfish_rtc_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); +device_class_set_props (dc, goldfish_rtc_properties); dc->realize = goldfish_rtc_realize; dc->reset = goldfish_rtc_reset; dc->vmsd = &goldfish_rtc_vmstate;
include/hw/rtc/goldfish_rtc.h +2 -0
@@ -42,6 +42,8 @@ struct GoldfishRTCState {uint32_t irq_pending;uint32_t irq_enabled;uint32_t time_high; + + uint8_t endianness; };#endif
Signature · 1 line
2.36.1
PATCH v2 4/11 hw/openrisc: Add the OpenRISC virtual machine
In reply to Stafford HorneThis patch adds the OpenRISC virtual machine 'virt' for OpenRISC. This platform allows for a convenient CI platform for toolchain, software ports and the OpenRISC linux kernel port.
Much of this has been sourced from the m68k and riscv virt platforms.
The platform provides:
- OpenRISC SMP with up to 4 cpus
- A virtio bus with up to 8 devices
- Standard ns16550a serial
- Goldfish RTC
- SiFive TEST device for poweroff and reboot
- Generated Device Tree to automatically configure the guest kernel
--- configs/devices/or1k-softmmu/default.mak | 1 + hw/openrisc/Kconfig | 9 + hw/openrisc/meson.build | 1 + hw/openrisc/virt.c | 424 +++++++++++++++++++++++ 4 files changed, 435 insertions(+) create mode 100644 hw/openrisc/virt.c
configs/devices/or1k-softmmu/default.mak +1 -0
@@ -3,3 +3,4 @@ # Boards: # CONFIG_OR1K_SIM=y +CONFIG_OR1K_VIRT=y
hw/openrisc/Kconfig +9 -0
@@ -4,3 +4,12 @@ config OR1K_SIM select OPENCORES_ETH select OMPIC select SPLIT_IRQ + +config OR1K_VIRT + bool + imply VIRTIO_VGA + imply TEST_DEVICES + select GOLDFISH_RTC + select SERIAL + select SIFIVE_TEST + select VIRTIO_MMIO
hw/openrisc/meson.build +1 -0
@@ -2,5 +2,6 @@ openrisc_ss = ss.source_set() openrisc_ss.add(files('cputimer.c')) openrisc_ss.add(files('boot.c')) openrisc_ss.add(when: 'CONFIG_OR1K_SIM', if_true: [files('openrisc_sim.c'), fdt]) +openrisc_ss.add(when: 'CONFIG_OR1K_VIRT', if_true: [files('virt.c'), fdt]) hw_arch += {'openrisc': openrisc_ss}
hw/openrisc/virt.c new file +424 -0
424 lines not on this page · raw message
Signature · 1 line
2.36.1
PATCH v2 5/11 hw/openrisc: Add PCI bus support to virt
In reply to Stafford HorneThis is mostly borrowed from xtensa and riscv as examples. The create_pcie_irq_map swizzle function is almost and exact copy but here we use a single cell interrupt, possibly we can make this generic.
--- hw/openrisc/Kconfig | 3 + hw/openrisc/virt.c | 160 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 157 insertions(+), 6 deletions(-)
hw/openrisc/Kconfig +3 -0
@@ -7,8 +7,11 @@ config OR1K_SIM config OR1K_VIRT bool + imply PCI_DEVICES imply VIRTIO_VGA imply TEST_DEVICES + select PCI + select PCI_EXPRESS_GENERIC_BRIDGE select GOLDFISH_RTC select SERIAL select SIFIVE_TEST
hw/openrisc/virt.c +154 -6
235 lines not on this page · raw message
Signature · 1 line
2.36.1
PATCH v2 6/11 hw/openrisc: Initialize timer time at startup
In reply to Stafford HorneThe last_clk time was initialized at zero, this means when we calculate the first delta we will calculate 0 vs current time which could cause unnecessary hops.
Initialize last_clk to the qemu clock on initialization.
--- hw/openrisc/cputimer.c | 1 + 1 file changed, 1 insertion(+)
hw/openrisc/cputimer.c +1 -0
@@ -140,6 +140,7 @@ void cpu_openrisc_clock_init(OpenRISCCPU *cpu)if (or1k_timer ==NULL ) { or1k_timer =g_new0 (OR1KTimerState,1 ); + or1k_timer->last_clk =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );vmstate_register (NULL ,0 , &vmstate_or1k_timer, or1k_timer); } }
Signature · 1 line
2.36.1
PATCH v2 7/11 target/openrisc: Add interrupted CPU to log
In reply to Stafford HorneWhen we are tracing it's helpful to know which CPU's are getting interrupted, att that detail to the log line.
--- target/openrisc/interrupt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
target/openrisc/interrupt.c +3 -1
@@ -83,7 +83,9 @@ void openrisc_cpu_do_interrupt(CPUState *cs) [EXCP_TRAP ] ="TRAP" , }; -qemu_log_mask (CPU_LOG_INT ,"INT: %s\n" , int_name[exception]); +qemu_log_mask (CPU_LOG_INT ,"CPU: %d INT: %s\n" , + cs->cpu_index, + int_name[exception]);hwaddr vect_pc = exception <<8 ;if (env->cpucfgr &CPUCFGR_EVBARP ) {
Signature · 1 line
2.36.1
PATCH v2 8/11 target/openrisc: Enable MTTCG
In reply to Stafford HorneThis patch enables multithread TCG for OpenRISC. Since the or1k shared syncrhonized timer can be updated from each vCPU via helpers we use a mutex to synchronize updates.
--- configs/targets/or1k-softmmu.mak | 1 + hw/openrisc/cputimer.c | 17 +++++++++++++++++ target/openrisc/cpu.h | 3 +++ target/openrisc/sys_helper.c | 11 +++++++++-- 4 files changed, 30 insertions(+), 2 deletions(-)
configs/targets/or1k-softmmu.mak +1 -0
@@ -1,3 +1,4 @@ TARGET_ARCH=openrisc +TARGET_SUPPORTS_MTTCG=y TARGET_BIG_ENDIAN=y TARGET_NEED_FDT=y
hw/openrisc/cputimer.c +17 -0
@@ -43,6 +43,23 @@ uint32_t cpu_openrisc_count_get(OpenRISCCPU *cpu)return or1k_timer->ttcr; } +/* +* Check to see if calling cpu_openrisc_count_update will +* actually advance the time. +* +* Used in hot spots to avoid taking expensive locks. +*/ +bool cpu_openrisc_timer_has_advanced (OpenRISCCPU *cpu) +{ +uint64_t now; + +if (!cpu->env.is_counting) { +return false; + } + now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +return (now - or1k_timer->last_clk) >=TIMER_PERIOD ; +} +/* Add elapsed ticks to ttcr */ void cpu_openrisc_count_update (OpenRISCCPU *cpu) {
target/openrisc/cpu.h +3 -0
@@ -25,6 +25,8 @@#include "hw/core/cpu.h" #include "qom/object.h" +#define TCG_GUEST_DEFAULT_MO (0) +#define TYPE_OPENRISC_CPU "or1k-cpu"OBJECT_DECLARE_CPU_TYPE (OpenRISCCPU, OpenRISCCPUClass,OPENRISC_CPU )
@@ -333,6 +335,7 @@ void cpu_openrisc_pic_init(OpenRISCCPU *cpu);/* hw/openrisc_timer.c */ void cpu_openrisc_clock_init (OpenRISCCPU *cpu); +bool cpu_openrisc_timer_has_advanced (OpenRISCCPU *cpu);uint32_t cpu_openrisc_count_get (OpenRISCCPU *cpu);void cpu_openrisc_count_set (OpenRISCCPU *cpu,uint32_t val);void cpu_openrisc_count_update (OpenRISCCPU *cpu);
target/openrisc/sys_helper.c +9 -2
@@ -145,6 +145,7 @@ void HELPER(mtspr)(CPUOpenRISCState *env, target_ulong spr, target_ulong rb)break ;case TO_SPR (10 ,0 ):/* TTMR */ { +qemu_mutex_lock_iothread ();if ((env->ttmr &TTMR_M ) ^ (rb &TTMR_M )) {switch (rb &TTMR_M ) {case TIMER_NONE :
@@ -168,14 +169,16 @@ void HELPER(mtspr)(CPUOpenRISCState *env, target_ulong spr, target_ulong rb) env->ttmr = rb & ~TTMR_IP ; cs->interrupt_request &= ~CPU_INTERRUPT_TIMER; } -cpu_openrisc_timer_update (cpu); +qemu_mutex_unlock_iothread (); }break ;case TO_SPR (10 ,1 ):/* TTCR */ +qemu_mutex_lock_iothread ();cpu_openrisc_count_set (cpu, rb);cpu_openrisc_timer_update (cpu); +qemu_mutex_unlock_iothread ();break ;#endif
@@ -303,7 +306,11 @@ target_ulong HELPER(mfspr)(CPUOpenRISCState *env, target_ulong rd,return env->ttmr;case TO_SPR (10 ,1 ):/* TTCR */ -cpu_openrisc_count_update (cpu); +if (cpu_openrisc_timer_has_advanced (cpu)) { +qemu_mutex_lock_iothread (); +cpu_openrisc_count_update (cpu); +qemu_mutex_unlock_iothread (); + }return cpu_openrisc_count_get (cpu);#endif
Signature · 1 line
2.36.1
PATCH v2 9/11 target/openrisc: Interrupt handling fixes
In reply to Stafford HorneWhen running SMP systems we sometimes were seeing lockups where IPI interrupts were being raised by never handled.
This looks to be caused by 2 issues in the openrisc interrupt handling logic.
1. After clearing an interrupt the openrisc_cpu_set_irq handler will always clear PICSR. This is not correct as masked interrupts should still be visible in PICSR.
2. After setting PICMR (mask register) and exposed interrupts should cause an interrupt to be raised. This was not being done so add it.
This patch fixes both issues.
--- target/openrisc/cpu.c | 1 - target/openrisc/sys_helper.c | 7 +++++++ 2 files changed, 7 insertions(+), 1 deletion(-)
target/openrisc/cpu.c +0 -1
@@ -98,7 +98,6 @@ static void openrisc_cpu_set_irq(void *opaque, int irq, int level) cpu_interrupt(cs, CPU_INTERRUPT_HARD); }else {cpu_reset_interrupt (cs,CPU_INTERRUPT_HARD ); - cpu->env.picsr =0 ; } }#endif
target/openrisc/sys_helper.c +7 -0
@@ -139,6 +139,13 @@ void HELPER(mtspr)(CPUOpenRISCState *env, target_ulong spr, target_ulong rb)break ;case TO_SPR (9 ,0 ):/* PICMR */ env->picmr = rb; +qemu_mutex_lock_iothread (); +if (env->picsr & env->picmr) { +cpu_interrupt (cs,CPU_INTERRUPT_HARD ); + }else { +cpu_reset_interrupt (cs,CPU_INTERRUPT_HARD ); + } +qemu_mutex_unlock_iothread ();break ;case TO_SPR (9 ,2 ):/* PICSR */ env->picsr &= ~rb;
Signature · 1 line
2.36.1
PATCH v2 10/11 hw/openrisc: virt: pass random seed to fdt
In reply to Stafford HorneFrom: "Jason A. Donenfeld" <[email protected]>
If the FDT contains /chosen/rng-seed, then the Linux RNG will use it to initialize early. Set this using the usual guest random number generation function. This is confirmed to successfully initialize the RNG on Linux 5.19-rc2.
--- hw/openrisc/virt.c | 6 ++++++ 1 file changed, 6 insertions(+)
hw/openrisc/virt.c +6 -0
@@ -8,6 +8,7 @@#include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qemu/guest-random.h" #include "qapi/error.h" #include "cpu.h" #include "exec/address-spaces.h"
@@ -130,6 +131,7 @@ static void openrisc_create_fdt(OR1KVirtState *state,void *fdt;int cpu;char *nodename; +uint8_t rng_seed[32 ]; fdt = state->fdt =create_device_tree (&state->fdt_size);if (!fdt) {
@@ -186,6 +188,10 @@ static void openrisc_create_fdt(OR1KVirtState *state,qemu_fdt_setprop_string (fdt,"/chosen" ,"bootargs" , cmdline); } +/* Pass seed to RNG. */ +qemu_guest_getrandom_nofail (rng_seed,sizeof (rng_seed)); +qemu_fdt_setprop (fdt,"/chosen" ,"rng-seed" , rng_seed,sizeof (rng_seed)); +/* Create aliases node for use by devices. */ qemu_fdt_add_subnode (fdt,"/aliases" ); }
Signature · 1 line
2.36.1
PATCH v2 11/11 docs/system: openrisc: Add OpenRISC documentation
In reply to Stafford Horne--- docs/system/openrisc/cpu-features.rst | 15 ++++++ docs/system/openrisc/emulation.rst | 17 +++++++ docs/system/openrisc/or1k-sim.rst | 43 ++++++++++++++++ docs/system/openrisc/virt.rst | 50 +++++++++++++++++++ docs/system/target-openrisc.rst | 72 +++++++++++++++++++++++++++ docs/system/targets.rst | 1 + 6 files changed, 198 insertions(+) create mode 100644 docs/system/openrisc/cpu-features.rst create mode 100644 docs/system/openrisc/emulation.rst create mode 100644 docs/system/openrisc/or1k-sim.rst create mode 100644 docs/system/openrisc/virt.rst create mode 100644 docs/system/target-openrisc.rst
docs/system/openrisc/cpu-features.rst new file +15 -0
@@ -0,0 +1,15 @@ +CPU Features +============ + +The QEMU emulation of the OpenRISC architecture provides following built in +features. + +- Shadow GPRs +- MMU TLB with 128 entries, 1 way +- Power Management (PM) +- Programmable Interrupt Controller (PIC) +- Tick Timer + +These features are on by default and the presence can be confirmed by checking +the contents of the Unit Presence Register (``UPR``) and CPU Configuration +Register (``CPUCFGR``).
docs/system/openrisc/emulation.rst new file +17 -0
@@ -0,0 +1,17 @@ +OpenRISC 1000 CPU architecture support +====================================== + +QEMU's TCG emulation includes support for the OpenRISC or1200 implementation of +the OpenRISC 1000 cpu architecture. + +The or1200 cpu also has support for the following instruction subsets: + +- ORBIS32 (OpenRISC Basic Instruction Set) +- ORFPX32 (OpenRISC Floating-Point eXtension) + +In addition to the instruction subsets the QEMU TCG emulation also has support +for most Class II (optional) instructions. + +For information on all OpenRISC instructions please refer to the latest +architecture manual available on the OpenRISC website in the +`OpenRISC Architecture <https://openrisc.io/architecture>`_ section.
docs/system/openrisc/or1k-sim.rst new file +43 -0
43 lines not on this page · raw message
docs/system/openrisc/virt.rst new file +50 -0
50 lines not on this page · raw message
docs/system/target-openrisc.rst new file +72 -0
72 lines not on this page · raw message
docs/system/targets.rst +1 -0
@@ -21,6 +21,7 @@ Contents: target-m68k target-mips target-ppc + target-openrisc target-riscv target-rx target-s390x
Signature · 1 line
2.36.1
Re: [PATCH v2 03/11] goldfish_rtc: Add endianness property
In reply to Stafford HorneQuoted 6 lines · Stafford Horne
Add an endianness property to allow configuring the RTC as either native, little or big endian.
Cc Laurent Vivier <[email protected]>Signed-off-by Stafford Horne <[email protected]>
Looks good to me.
Regards,
Anup
Quoted 97 lines
--- hw/rtc/goldfish_rtc.c | 46 ++++++++++++++++++++++++++++------- include/hw/rtc/goldfish_rtc.h | 2 ++ 2 files changed, 39 insertions(+), 9 deletions(-)hw/rtc/goldfish_rtc.c +37
-9@@ -216,14 +216,34 @@ static int goldfish_rtc_post_load(void *opaque, int version_id)return 0 ; } -static const MemoryRegionOps goldfish_rtc_ops = { - .read = goldfish_rtc_read, - .write = goldfish_rtc_write, - .endianness =DEVICE_NATIVE_ENDIAN , - .valid = { - .min_access_size =4 , - .max_access_size =4 - } +static const MemoryRegionOps goldfish_rtc_ops[3 ] = { + [DEVICE_NATIVE_ENDIAN ] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 + } + }, + [DEVICE_LITTLE_ENDIAN ] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 + } + }, + [DEVICE_BIG_ENDIAN ] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness =DEVICE_BIG_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 + } + }, };static const VMStateDescription goldfish_rtc_vmstate = {@@ -265,7 +285,8 @@ static void goldfish_rtc_realize(DeviceState *d, Error **errp)SysBusDevice *dev =SYS_BUS_DEVICE (d);GoldfishRTCState *s =GOLDFISH_RTC (d); -memory_region_init_io (&s->iomem,OBJECT (s), &goldfish_rtc_ops, s, +memory_region_init_io (&s->iomem,OBJECT (s), + &goldfish_rtc_ops[s->endianness], s,"goldfish_rtc" ,0x24 );sysbus_init_mmio (dev, &s->iomem);@@ -274,10 +295,17 @@ static void goldfish_rtc_realize(DeviceState *d, Error **errp) s->timer =timer_new_ns (rtc_clock, goldfish_rtc_interrupt, s); } +static Property goldfish_rtc_properties[] = { +DEFINE_PROP_UINT8 ("endianness" , GoldfishRTCState, endianness, +DEVICE_NATIVE_ENDIAN ), +DEFINE_PROP_END_OF_LIST (), +}; +static void goldfish_rtc_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); +device_class_set_props (dc, goldfish_rtc_properties); dc->realize = goldfish_rtc_realize; dc->reset = goldfish_rtc_reset; dc->vmsd = &goldfish_rtc_vmstate;include/hw/rtc/goldfish_rtc.h +2
-1@@ -42,6 +42,8 @@ struct GoldfishRTCState {uint32_t irq_pending;uint32_t irq_enabled;uint32_t time_high; + + uint8_t endianness; };#endif --2.36.1
Re: [PATCH v2 03/11] goldfish_rtc: Add endianness property
In reply to Stafford HorneQuoted 27 lines · Stafford Horne
hw/rtc/goldfish_rtc.c +19
-8-static const MemoryRegionOps goldfish_rtc_ops = { - .read = goldfish_rtc_read, - .write = goldfish_rtc_write, - .endianness =DEVICE_NATIVE_ENDIAN , - .valid = { - .min_access_size =4 , - .max_access_size =4 - } +static const MemoryRegionOps goldfish_rtc_ops[3 ] = { + [DEVICE_NATIVE_ENDIAN ] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 + } + }, + [DEVICE_LITTLE_ENDIAN ] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 + } + },
hw/rtc/goldfish_rtc.c static int goldfish_rtc_post_load(void *opaque, int version_id) · line 247
Quoted 10 lines
hw/rtc/goldfish_rtc.c +9
-0+ [DEVICE_BIG_ENDIAN ] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness =DEVICE_BIG_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 + } + }, };
You don't need 3 copies, only big and little.
hw/rtc/goldfish_rtc.c static void goldfish_rtc_realize(DeviceState *d, Error **errp) · line 302
Quoted 5 lines
hw/rtc/goldfish_rtc.c +5
-0+static Property goldfish_rtc_properties[] = { +DEFINE_PROP_UINT8 ("endianness" , GoldfishRTCState, endianness, +DEVICE_NATIVE_ENDIAN ), +DEFINE_PROP_END_OF_LIST (), +};
... and I think the clear desire for default is little-endian. I would make the property be bool, and add a comment that this is only for m68k compatibility, so don't use it in new code.
r~
Re: [PATCH v2 02/11] target/openrisc: Fix memory reading in debugger
In reply to Stafford HorneQuoted 9 lines · Stafford Horne
In commit
f0655423ca("target/openrisc: Reorg tlb lookup") data and instruction TLB reads were combined. This, broke debugger reads where we first tried to map using the data tlb then fall back to the instruction tlb.This patch replicates this logic by first requesting a
PAGE_READprotection mapping then falling back toPAGE_EXEC.Signed-off-by Stafford Horne <[email protected]>
r~
Re: [PATCH v2 06/11] hw/openrisc: Initialize timer time at startup
In reply to Stafford HorneQuoted 16 lines · Stafford Horne
The
last_clktime was initialized at zero, this means when we calculate the first delta we will calculate 0 vs current time which could cause unnecessary hops.Initialize
last_clkto the qemu clock on initialization.Signed-off-by Stafford Horne <[email protected]>--- hw/openrisc/cputimer.c | 1 + 1 file changed, 1 insertion(+)hw/openrisc/cputimer.c +0
-0
hw/openrisc/cputimer.c void cpu_openrisc_clock_init(OpenRISCCPU *cpu) · line 146
Quoted 7 lines
hw/openrisc/cputimer.c +1
-0@@ -140,6 +140,7 @@ void cpu_openrisc_clock_init(OpenRISCCPU *cpu)if (or1k_timer ==NULL ) { or1k_timer =g_new0 (OR1KTimerState,1 ); + or1k_timer->last_clk =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );vmstate_register (NULL ,0 , &vmstate_or1k_timer, or1k_timer); } }
Init doesn't seem right. Should be in reset?
r~
Re: [PATCH v2 07/11] target/openrisc: Add interrupted CPU to log
In reply to Stafford HorneQuoted 2 lines · Stafford Horne
When we are tracing it's helpful to know which CPU's are getting interrupted, att that detail to the log line.
"at".
Quoted 21 lines
Signed-off-by Stafford Horne <[email protected]>--- target/openrisc/interrupt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)target/openrisc/interrupt.c +3
-1@@ -83,7 +83,9 @@ void openrisc_cpu_do_interrupt(CPUState *cs) [EXCP_TRAP ] ="TRAP" , }; -qemu_log_mask (CPU_LOG_INT ,"INT: %s\n" , int_name[exception]); +qemu_log_mask (CPU_LOG_INT ,"CPU: %d INT: %s\n" , + cs->cpu_index, + int_name[exception]);hwaddr vect_pc = exception <<8 ;if (env->cpucfgr &CPUCFGR_EVBARP ) {
Re: [PATCH v2 08/11] target/openrisc: Enable MTTCG
In reply to Stafford Hornetarget/openrisc/sys_helper.c target_ulong HELPER(mfspr)(CPUOpenRISCState *env, target_ulong rd, · line 313
Quoted 7 lines · Stafford Horne
case TO_SPR(10, 1): /* TTCR */target/openrisc/sys_helper.c +5
-1-cpu_openrisc_count_update (cpu); +if (cpu_openrisc_timer_has_advanced (cpu)) { +qemu_mutex_lock_iothread (); +cpu_openrisc_count_update (cpu); +qemu_mutex_unlock_iothread (); + }
Lock around the whole if, I think. Otherwise looks good.
r~
Re: [PATCH v2 03/11] goldfish_rtc: Add endianness property
In reply to Richard HendersonQuoted 41 lines · Richard Henderson
Quoted 36 lines · Stafford Horne
hw/rtc/goldfish_rtc.c +28
-8-static const MemoryRegionOps goldfish_rtc_ops = { - .read = goldfish_rtc_read, - .write = goldfish_rtc_write, - .endianness = DEVICE_NATIVE_ENDIAN, - .valid = { - .min_access_size = 4, - .max_access_size = 4 - } +static const MemoryRegionOps goldfish_rtc_ops[3 ] = { + [DEVICE_NATIVE_ENDIAN] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness = DEVICE_NATIVE_ENDIAN, + .valid = { + .min_access_size = 4, + .max_access_size = 4 + } + }, + [DEVICE_LITTLE_ENDIAN] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness = DEVICE_LITTLE_ENDIAN, + .valid = { + .min_access_size = 4, + .max_access_size = 4 + } + }, + [DEVICE_BIG_ENDIAN] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness = DEVICE_BIG_ENDIAN, + .valid = { + .min_access_size = 4, + .max_access_size = 4 + } + },Quoted 1 line
};
You don't need 3 copies, only big and little.
Quoted 7 lines
hw/rtc/goldfish_rtc.c static void goldfish_rtc_realize(DeviceState *d, Error **errp) · line 302
Quoted 5 lines
hw/rtc/goldfish_rtc.c +5
-0+static Property goldfish_rtc_properties[] = { + DEFINE_PROP_UINT8("endianness", GoldfishRTCState, endianness, + DEVICE_NATIVE_ENDIAN), + DEFINE_PROP_END_OF_LIST(), +};... and I think the clear desire for default is little-endian. I would make the property be bool, and add a comment that this is only for m68k compatibility, so don't use it in new code.
m68k doesn't really need this.
kernel with the m68k virt machine and goldfish device supports "native" mode so I think it's not needed to add another layer of complexity for it.
Thanks,
Laurent
Re: [PATCH v2 09/11] target/openrisc: Interrupt handling fixes
In reply to Stafford HorneQuoted 6 lines · Stafford Horne
When running SMP systems we sometimes were seeing lockups where IPI interrupts were being raised by never handled.
This looks to be caused by 2 issues in the openrisc interrupt handling logic.
Quoted 7 lines
1. After clearing an interrupt the
openrisc_cpu_set_irqhandler will always clear PICSR. This is not correct as masked interrupts should still be visible in PICSR.
2. After setting PICMR (mask register) and exposed interrupts should cause an interrupt to be raised. This was not being done so add it.This patch fixes both issues.
r~
Re: [PATCH v2 03/11] goldfish_rtc: Add endianness property
In reply to Laurent VivierQuoted 50 lines · Laurent Vivier
Quoted 41 lines · Richard Henderson
Quoted 36 lines · Stafford Horne
hw/rtc/goldfish_rtc.c +28
-8-static const MemoryRegionOps goldfish_rtc_ops = { - .read = goldfish_rtc_read, - .write = goldfish_rtc_write, - .endianness = DEVICE_NATIVE_ENDIAN, - .valid = { - .min_access_size = 4, - .max_access_size = 4 - } +static const MemoryRegionOps goldfish_rtc_ops[3 ] = { + [DEVICE_NATIVE_ENDIAN] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness = DEVICE_NATIVE_ENDIAN, + .valid = { + .min_access_size = 4, + .max_access_size = 4 + } + }, + [DEVICE_LITTLE_ENDIAN] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness = DEVICE_LITTLE_ENDIAN, + .valid = { + .min_access_size = 4, + .max_access_size = 4 + } + }, + [DEVICE_BIG_ENDIAN] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness = DEVICE_BIG_ENDIAN, + .valid = { + .min_access_size = 4, + .max_access_size = 4 + } + },Quoted 1 line
};
You don't need 3 copies, only big and little.
Quoted 7 lines
hw/rtc/goldfish_rtc.c static void goldfish_rtc_realize(DeviceState *d, Error **errp) · line 302
Quoted 5 lines
hw/rtc/goldfish_rtc.c +5
-0+static Property goldfish_rtc_properties[] = { + DEFINE_PROP_UINT8("endianness", GoldfishRTCState, endianness, + DEVICE_NATIVE_ENDIAN), + DEFINE_PROP_END_OF_LIST(), +};... and I think the clear desire for default is little-endian. I would make the property be bool, and add a comment that this is only for m68k compatibility, so don't use it in new code.
Quoted 3 lines
m68k doesn't really need this.
kernel with the m68k virt machine and goldfish device supports "native" mode so I think it's not needed to add another layer of complexity for it.
"Another level"? I'm talking about removing "native", and only having "big" and "little", which is less complexity.
r~
Re: [PATCH v2 10/11] hw/openrisc: virt: pass random seed to fdt
In reply to Stafford HorneQuoted 10 lines · Stafford Horne
From: "Jason A. Donenfeld" <[email protected]>
If the FDT contains /chosen/rng-seed, then the Linux RNG will use it to initialize early. Set this using the usual guest random number generation function. This is confirmed to successfully initialize the RNG on Linux 5.19-rc2.
Cc Stafford Horne <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>Signed-off-by Stafford Horne <[email protected]>
You could remove yourself from cc now that you've signed it. :-)
r~
Re: [PATCH v2 03/11] goldfish_rtc: Add endianness property
In reply to Richard HendersonQuoted 51 lines · Richard Henderson
Quoted 50 lines · Laurent Vivier
Quoted 48 lines · Richard Henderson
Quoted 36 lines · Stafford Horne
hw/rtc/goldfish_rtc.c +28
-8-static const MemoryRegionOps goldfish_rtc_ops = { - .read = goldfish_rtc_read, - .write = goldfish_rtc_write, - .endianness = DEVICE_NATIVE_ENDIAN, - .valid = { - .min_access_size = 4, - .max_access_size = 4 - } +static const MemoryRegionOps goldfish_rtc_ops[3 ] = { + [DEVICE_NATIVE_ENDIAN] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness = DEVICE_NATIVE_ENDIAN, + .valid = { + .min_access_size = 4, + .max_access_size = 4 + } + }, + [DEVICE_LITTLE_ENDIAN] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness = DEVICE_LITTLE_ENDIAN, + .valid = { + .min_access_size = 4, + .max_access_size = 4 + } + }, + [DEVICE_BIG_ENDIAN] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness = DEVICE_BIG_ENDIAN, + .valid = { + .min_access_size = 4, + .max_access_size = 4 + } + },Quoted 1 line
};
You don't need 3 copies, only big and little.
hw/rtc/goldfish_rtc.c static void goldfish_rtc_realize(DeviceState *d, Error **errp) · line 302
Quoted 5 lines
hw/rtc/goldfish_rtc.c +5
-0+static Property goldfish_rtc_properties[] = { + DEFINE_PROP_UINT8("endianness", GoldfishRTCState, endianness, + DEVICE_NATIVE_ENDIAN), + DEFINE_PROP_END_OF_LIST(), +};... and I think the clear desire for default is little-endian. I would make the property be bool, and add a comment that this is only for m68k compatibility, so don't use it in new code.
Quoted 5 lines
Quoted 3 lines
m68k doesn't really need this.
kernel with the m68k virt machine and goldfish device supports "native" mode so I think it's not needed to add another layer of complexity for it.
"Another level"? I'm talking about removing "native", and only having "big" and "little", which is less complexity.
"Less complexity" is to keep only native. I'm not against the change, I'm just saying it's not needed by m68k.
Thanks,
Laurent
Re: [PATCH v2 11/11] docs/system: openrisc: Add OpenRISC documentation
In reply to Stafford HorneQuoted 9 lines · Stafford Horne
Signed-off-by Stafford Horne<[email protected]>--- docs/system/openrisc/cpu-features.rst | 15 ++++++ docs/system/openrisc/emulation.rst | 17 +++++++ docs/system/openrisc/or1k-sim.rst | 43 ++++++++++++++++ docs/system/openrisc/virt.rst | 50 +++++++++++++++++++ docs/system/target-openrisc.rst | 72 +++++++++++++++++++++++++++ docs/system/targets.rst | 1 + 6 files changed, 198 insertions(+)
Quoted 5 lines
create mode 100644
docs/system/openrisc/cpu-features.rstcreate mode 100644docs/system/openrisc/emulation.rstcreate mode 100644docs/system/openrisc/or1k-sim.rstcreate mode 100644docs/system/openrisc/virt.rstcreate mode 100644docs/system/target-openrisc.rst
r~
Re: [PATCH v2 07/11] target/openrisc: Add interrupted CPU to log
In reply to Richard HendersonQuoted 7 lines · Richard Henderson
Quoted 2 lines · Stafford Horne
When we are tracing it's helpful to know which CPU's are getting interrupted, att that detail to the log line.
"at".
Reviewed-by Richard Henderson <[email protected]>
Actually it should be "add", thanks I fixed it.
-Stafford
Re: [PATCH v2 08/11] target/openrisc: Enable MTTCG
In reply to Richard HendersonQuoted 10 lines · Richard Henderson
target/openrisc/sys_helper.c target_ulong HELPER(mfspr)(CPUOpenRISCState *env, target_ulong rd, · line 313
Quoted 7 lines · Stafford Horne
case TO_SPR(10, 1): /* TTCR */target/openrisc/sys_helper.c +5
-1-cpu_openrisc_count_update (cpu); +if (cpu_openrisc_timer_has_advanced (cpu)) { +qemu_mutex_lock_iothread (); +cpu_openrisc_count_update (cpu); +qemu_mutex_unlock_iothread (); + }Lock around the whole if, I think. Otherwise looks good.
Well, actually the cpu_openrisc_timer_has_advanced read is done once outside the lock as an optimization to avoid taking the lock when it is not needed. i.e. if we have 4 cores that all try to update the clock at the same time in theory only one will have to take the lock and update the shared timer.
But I do see that could be flawed as after it takes the lock the timer could have been updated by then. Ill move it inside and see if there is any perfromance hit / increase in the sync-profile.
Quoted 4 lines
Reviewed-by Richard Henderson <[email protected]>r~
Re: [PATCH v2 06/11] hw/openrisc: Initialize timer time at startupi
In reply to Richard HendersonQuoted 12 lines · Richard Henderson
Quoted 11 lines · Stafford Horne
The
last_clktime was initialized at zero, this means when we calculate the first delta we will calculate 0 vs current time which could cause unnecessary hops.Initialize
last_clkto the qemu clock on initialization.Signed-off-by Stafford Horne <[email protected]>--- hw/openrisc/cputimer.c | 1 + 1 file changed, 1 insertion(+)
Quoted 13 lines
hw/openrisc/cputimer.c void cpu_openrisc_clock_init(OpenRISCCPU *cpu) · line 145
Quoted 11 lines
hw/openrisc/cputimer.c +1
-0@@ -140,6 +140,7 @@ void cpu_openrisc_clock_init(OpenRISCCPU *cpu)if (or1k_timer ==NULL ) { or1k_timer =g_new0 (OR1KTimerState,1 ); + or1k_timer->last_clk =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );vmstate_register (NULL ,0 , &vmstate_or1k_timer, or1k_timer); } }Init doesn't seem right. Should be in reset?
Good point, I think reset would be better.
Re: [PATCH v2 03/11] goldfish_rtc: Add endianness property
In reply to Richard HendersonQuoted 41 lines · Richard Henderson
Quoted 27 lines · Stafford Horne
hw/rtc/goldfish_rtc.c +19
-8-static const MemoryRegionOps goldfish_rtc_ops = { - .read = goldfish_rtc_read, - .write = goldfish_rtc_write, - .endianness =DEVICE_NATIVE_ENDIAN , - .valid = { - .min_access_size =4 , - .max_access_size =4 - } +static const MemoryRegionOps goldfish_rtc_ops[3 ] = { + [DEVICE_NATIVE_ENDIAN ] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 + } + }, + [DEVICE_LITTLE_ENDIAN ] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 + } + },hw/rtc/goldfish_rtc.c static int goldfish_rtc_post_load(void *opaque, int version_id) · line 247
Quoted 10 lines
hw/rtc/goldfish_rtc.c +9
-0+ [DEVICE_BIG_ENDIAN ] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness =DEVICE_BIG_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 + } + }, };You don't need 3 copies, only big and little.
Quoted 9 lines
hw/rtc/goldfish_rtc.c static void goldfish_rtc_realize(DeviceState *d, Error **errp) · line 302
Quoted 5 lines
hw/rtc/goldfish_rtc.c +5
-0+static Property goldfish_rtc_properties[] = { +DEFINE_PROP_UINT8 ("endianness" , GoldfishRTCState, endianness, +DEVICE_NATIVE_ENDIAN ), +DEFINE_PROP_END_OF_LIST (), +};... and I think the clear desire for default is little-endian. I would make the property be bool, and add a comment that this is only for m68k compatibility, so don't use it in new code.
Yeah, that makes sense.
-Stafford
Re: [PATCH v2 03/11] goldfish_rtc: Add endianness property
In reply to Laurent VivierQuoted 60 lines · Laurent Vivier
Quoted 59 lines · Richard Henderson
Quoted 57 lines · Laurent Vivier
Quoted 41 lines · Richard Henderson
Quoted 36 lines · Stafford Horne
hw/rtc/goldfish_rtc.c +28
-8-static const MemoryRegionOps goldfish_rtc_ops = { - .read = goldfish_rtc_read, - .write = goldfish_rtc_write, - .endianness = DEVICE_NATIVE_ENDIAN, - .valid = { - .min_access_size = 4, - .max_access_size = 4 - } +static const MemoryRegionOps goldfish_rtc_ops[3 ] = { + [DEVICE_NATIVE_ENDIAN] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness = DEVICE_NATIVE_ENDIAN, + .valid = { + .min_access_size = 4, + .max_access_size = 4 + } + }, + [DEVICE_LITTLE_ENDIAN] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness = DEVICE_LITTLE_ENDIAN, + .valid = { + .min_access_size = 4, + .max_access_size = 4 + } + }, + [DEVICE_BIG_ENDIAN] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness = DEVICE_BIG_ENDIAN, + .valid = { + .min_access_size = 4, + .max_access_size = 4 + } + },Quoted 1 line
};
You don't need 3 copies, only big and little.
Quoted 9 lines
hw/rtc/goldfish_rtc.c static void goldfish_rtc_realize(DeviceState *d, Error **errp) · line 302
Quoted 5 lines
hw/rtc/goldfish_rtc.c +5
-0+static Property goldfish_rtc_properties[] = { + DEFINE_PROP_UINT8("endianness", GoldfishRTCState, endianness, + DEVICE_NATIVE_ENDIAN), + DEFINE_PROP_END_OF_LIST(), +};... and I think the clear desire for default is little-endian. I would make the property be bool, and add a comment that this is only for m68k compatibility, so don't use it in new code.
m68k doesn't really need this.
kernel with the m68k virt machine and goldfish device supports "native" mode so I think it's not needed to add another layer of complexity for it.
Quoted 5 lines
Quoted 2 lines
"Another level"? I'm talking about removing "native", and only having "big" and "little", which is less complexity.
"Less complexity" is to keep only native. I'm not against the change, I'm just saying it's not needed by m68k.
Hi Laurent,
I would agree if we only had m68k. But I am making this change so that OpenRISC (another big-endian architecture) could use this. In the OpenRISC case we want to use this as little-endian so no kernel updates would be needed.
So in the end we will have the following qemu platforms:
riscv{LE}--------------->goldfish_rtc{LE} mips-longsoon3{LE}------>goldfish_rtc{LE} openrisc{BE}------------>goldfish_rtc{LE} (LE to BE conversion done in driver) m68k{BE}---------------->goldfish_rtc{BE} (only big-endian user)
-Stafford
Re: [PATCH v2 03/11] goldfish_rtc: Add endianness property
Quoted 4 lines · Stafford Horne
riscv{LE}--------------->goldfish_rtc{LE} mips-longsoon3{LE}------>goldfish_rtc{LE} openrisc{BE}------------>goldfish_rtc{LE} (LE to BE conversion done in driver) m68k{BE}---------------->goldfish_rtc{BE} (only big-endian user)
I wish the powers that be would lighten up a little bit and let us change m68k to be LE, and then we could avoid all this...
Just a last grumble, I guess.
Jason