OpenRISC Virtual Machine
v3 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. I also have recently used it to test glibc 2.36 and it worked well. Previous glibc testsuite runs on my FPGA board took about 3 days, running on qemu virt now takes 6 hours.
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 about 10 second hangs. However, overall this 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 the or1k-5.20-updates kernel branch here:
https://github.com/stffrdhrn/linux/commits/or1k-5.20-updates
This tree has support for: OpenRISC PCI and virt_defconfig and an irqchip bug fix.
Changes since v2:
- Changed goldfish_rtc endian property to boolean
- Moved or1k timer init from init to reset
- Removed cpu_openrisc_timer_has_advanced lock optimization in MTTCG patch, measuring revealed it did not help much.
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
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 big-endian 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/m68k/virt.c | 1 + hw/openrisc/Kconfig | 12 + hw/openrisc/boot.c | 117 +++++ hw/openrisc/cputimer.c | 22 +- hw/openrisc/meson.build | 2 + hw/openrisc/openrisc_sim.c | 106 +---- hw/openrisc/virt.c | 571 +++++++++++++++++++++++ hw/rtc/goldfish_rtc.c | 37 +- include/hw/openrisc/boot.h | 34 ++ include/hw/rtc/goldfish_rtc.h | 2 + target/openrisc/cpu.c | 1 - target/openrisc/cpu.h | 2 + target/openrisc/interrupt.c | 4 +- target/openrisc/mmu.c | 8 +- target/openrisc/sys_helper.c | 14 +- 23 files changed, 1019 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.37.1
PATCH v3 1/11 hw/openrisc: Split re-usable boot time apis out to boot.c
These will be shared with the virt platform.
---
Since v2:
- No changes
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.37.1
PATCH v3 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.
---
Since v2:
- No changes, added Reviewed-by
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.37.1
PATCH v3 3/11 goldfish_rtc: Add big-endian property
In reply to Stafford HorneAdd a new property "big-endian" to allow configuring the RTC as either little or big endian, the default is little endian.
Currently overriding the default to big endian is only used by the m68k virt platform. New platforms should prefer to use little endian and not set this.
---
Since v2:
- Added Reviewed-by
- Changed from enum property to boolean as suggested by Richard
hw/m68k/virt.c | 1 + hw/rtc/goldfish_rtc.c | 37 ++++++++++++++++++++++++++--------- include/hw/rtc/goldfish_rtc.h | 2 ++ 3 files changed, 31 insertions(+), 9 deletions(-)
hw/m68k/virt.c +1 -0
@@ -173,6 +173,7 @@ static void virt_init(MachineState *machine) io_base =VIRT_GF_RTC_MMIO_BASE ;for (i =0 ; i <VIRT_GF_RTC_NB ; i++) { dev =qdev_new (TYPE_GOLDFISH_RTC ); +qdev_prop_set_bit (dev,"big-endian" , true); sysbus =SYS_BUS_DEVICE (dev);sysbus_realize_and_unref (sysbus, &error_fatal);sysbus_mmio_map (sysbus,0 , io_base);
hw/rtc/goldfish_rtc.c +28 -9
@@ -216,14 +216,25 @@ 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[2 ] = { + [false] = { + .read = goldfish_rtc_read, + .write = goldfish_rtc_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 + } + }, + [true] = { + .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 +276,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->big_endian], s,"goldfish_rtc" ,0x24 );sysbus_init_mmio (dev, &s->iomem);
@@ -274,10 +286,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_BOOL ("big-endian" , GoldfishRTCState, big_endian, + false), +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; + + bool big_endian; };#endif
Signature · 1 line
2.37.1
Re: [PATCH v3 03/11] goldfish_rtc: Add big-endian property
Quoted 7 lines · Stafford Horne
Add a new property "big-endian" to allow configuring the RTC as either little or big endian, the default is little endian.
Currently overriding the default to big endian is only used by the m68k virt platform. New platforms should prefer to use little endian and not set this.
Quoted 7 lines
Cc Laurent Vivier<[email protected]>Reviewed-by Anup Patel<[email protected]>Signed-off-by Stafford Horne<[email protected]>---
Since v2:
- Added Reviewed-by
- Changed from enum property to boolean as suggested by Richard
r~
PATCH v3 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
---
Since v2:
- No changes
configs/devices/or1k-softmmu/default.mak | 1 + hw/openrisc/Kconfig | 9 + hw/openrisc/meson.build | 1 + hw/openrisc/virt.c | 417 +++++++++++++++++++++++ 4 files changed, 428 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 +417 -0
417 lines not on this page · raw message
Signature · 1 line
2.37.1
PATCH v3 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.
---
Since v2:
- No changes
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.37.1
PATCH v3 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.
This patch moves timer initialization to the cpu reset. There are two resets registered here:
1. Per cpu timer mask (ttmr) reset.
2. Global cpu timer (last_clk and ttcr) reset, attached to the first cpu only.
---
Since v2:
- Moved timer init from init to reset suggested by Richard
hw/openrisc/cputimer.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
hw/openrisc/cputimer.c +21 -1
@@ -22,6 +22,7 @@#include "cpu.h" #include "migration/vmstate.h" #include "qemu/timer.h" +#include "sysemu/reset.h" #define TIMER_PERIOD 50/* 50 ns period for 20 MHz timer */
@@ -122,6 +123,24 @@ static void openrisc_timer_cb(void *opaque)qemu_cpu_kick (CPU (cpu)); } +/* Reset the per CPU counter state. */ +static void openrisc_count_reset (void *opaque) +{ +OpenRISCCPU *cpu = opaque; + +if (cpu->env.is_counting) { +cpu_openrisc_count_stop (cpu); + } + cpu->env.ttmr =0x00000000 ; +} + +/* Reset the global timer state. */ +static void openrisc_timer_reset (void *opaque) +{ + or1k_timer->ttcr =0x00000000 ; + or1k_timer->last_clk =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +} +static const VMStateDescription vmstate_or1k_timer = { .name ="or1k_timer" , .version_id =1 ,
@@ -136,10 +155,11 @@ static const VMStateDescription vmstate_or1k_timer = {void cpu_openrisc_clock_init (OpenRISCCPU *cpu) { cpu->env.timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , &openrisc_timer_cb, cpu); - cpu->env.ttmr =0x00000000 ; +qemu_register_reset (openrisc_count_reset, cpu);if (or1k_timer ==NULL ) { or1k_timer =g_new0 (OR1KTimerState,1 ); +qemu_register_reset (openrisc_timer_reset, cpu);vmstate_register (NULL ,0 , &vmstate_or1k_timer, or1k_timer); } }
Signature · 1 line
2.37.1
Re: [PATCH v3 06/11] hw/openrisc: Initialize timer time at startup
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.This patch moves timer initialization to the cpu reset. There are two resets registered here:
1. Per cpu timer mask (ttmr) reset.
2. Global cpu timer (last_clkand ttcr) reset, attached to the first cpu only.
Quoted 7 lines
Signed-off-by Stafford Horne<[email protected]>---
Since v2:
- Moved timer init from init to reset suggested by Richardhw/openrisc/cputimer.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
r~
PATCH v3 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, add that detail to the log line.
---
Since v2:
- Added Reviewed-by
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.37.1
PATCH v3 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.
---
Since v2:
- Removed cpu_openrisc_timer_has_advanced lock optimization, measuring revealed it did not help much.
configs/targets/or1k-softmmu.mak | 1 + target/openrisc/cpu.h | 2 ++ target/openrisc/sys_helper.c | 7 ++++++- 3 files changed, 9 insertions(+), 1 deletion(-)
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
target/openrisc/cpu.h +2 -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 )
target/openrisc/sys_helper.c +6 -1
@@ -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,9 @@ target_ulong HELPER(mfspr)(CPUOpenRISCState *env, target_ulong rd,return env->ttmr;case TO_SPR (10 ,1 ):/* TTCR */ +qemu_mutex_lock_iothread ();cpu_openrisc_count_update (cpu); +qemu_mutex_unlock_iothread ();return cpu_openrisc_count_get (cpu);#endif
Signature · 1 line
2.37.1
Re: [PATCH v3 08/11] target/openrisc: Enable MTTCG
Quoted 10 lines · Stafford Horne
This 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.
Signed-off-by Stafford Horne<[email protected]>---
Since v2:
- Removedcpu_openrisc_timer_has_advancedlock optimization, measuring revealed it did not help much.
Quoted 4 lines
configs/targets/or1k-softmmu.mak | 1 + target/openrisc/cpu.h | 2 ++ target/openrisc/sys_helper.c | 7 ++++++- 3 files changed, 9 insertions(+), 1 deletion(-)
r~
Re: [PATCH v3 08/11] target/openrisc: Enable MTTCG
Quoted 11 lines · Richard Henderson
Quoted 10 lines · Stafford Horne
This 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.
Signed-off-by Stafford Horne<[email protected]>---
Since v2:
- Removedcpu_openrisc_timer_has_advancedlock optimization, measuring revealed it did not help much.
Quoted 6 lines
Quoted 4 lines
configs/targets/or1k-softmmu.mak | 1 + target/openrisc/cpu.h | 2 ++ target/openrisc/sys_helper.c | 7 ++++++- 3 files changed, 9 insertions(+), 1 deletion(-)Reviewed-by Richard Henderson <[email protected]>
Thank you,
I guess this whole series is a bit late for 7.1.0 now.
I will post the PR after 7.1.0 is released and target it for 7.2.0.
-Stafford
PATCH v3 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.
---
Since v2:
- Added Reviewed-by
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.37.1
PATCH v3 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.
---
Since v2:
- No changes
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.37.1
PATCH v3 11/11 docs/system: openrisc: Add OpenRISC documentation
In reply to Stafford Horne---
Since v2;
- Added Reviewed-by
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.37.1