RISC-V Patches for the 4.1 Soft Freeze, Part 2
Subsystems (3)
merged tag 'mips-queue-jun-21-2019'
The following changes since commit 474f3938d79ab36b9231c9ad3b5a9314c2aeacde:
Merge remote-tracking branch 'remotes/amarkovic/tags/mips-queue-jun-21-2019' into staging (2019-06-21 15:40:50 +0100)
are available in the Git repository at:
git://github.com/palmer-dabbelt/qemu.git tags/riscv-for-master-4.1-sf1
for you to fetch changes up to c08a8317e31033ec76b8460a0b75cbcdaeeef481:
hw/riscv: Load OpenSBI as the default firmware (2019-06-27 02:47:06 -0700)
----------------------------------------------------------------
RISC-V Patches for the 4.1 Soft Freeze, Part 2
This pull request contains a handful of patches that I'd like to target for the 4.1 soft freeze. There are a handful of new features:
* The -bios option now works sanely, including both a built-in copy of OpenSBI and the ability to load external versions. Users no longer need to figure out how to build their own firmware.
* Support for the 1.11.0, the latest privileged specification.
* Support for reading and writing the PRCI registers.
* Better control over the ISA of the target machine.
* Support for the cpu-topology device tree node.
Additionally, there are a handful of bug fixes including:
* Load reservations are now broken by both store conditional and by scheduling, which fixes issues with parallel applications.
* Various fixes to the PMP implementation.
* Fixes to the 32-bit linux-user syscall ABI.
* Various fixes for instruction decodeing.
* A fix to the PCI device tree "bus-range" property.
This boots 32-bit and 64-bit OpenEmbedded.
----------------------------------------------------------------
Alistair Francis (14):
target/riscv: Allow setting ISA extensions via CPU props target/riscv: Restructure deprecatd CPUs target/riscv: Add the privledge spec version 1.11.0 target/riscv: Add the mcountinhibit CSR
target/riscv: Set privledge spec 1.11.0 as default qemu-deprecated.texi: Deprecate the RISC-V privledge spec 1.09.1 target/riscv: Require either I or E base extension target/riscv: Remove user version information target/riscv: Add support for disabling/enabling Counters hw/riscv: Split out the boot functions
hw/riscv: Add support for loading a firmware hw/riscv: Extend the kernel loading support
roms: Add OpenSBI version 0.3
hw/riscv: Load OpenSBI as the default firmware
Atish Patra (1):
riscv: virt: Add cpu-topology DT node.
Bin Meng (3):
riscv: virt: Correct pci "bus-range" encoding
riscv: sifive_u: Do not create hard-coded phandles in DT
riscv: sifive_u: Update the plic hart config to support multicore
Dayeol Lee (1):
target/riscv: Fix PMP range boundary address bug
Hesham Almatary (6):
RISC-V: Only Check PMP if MMU translation succeeds
RISC-V: Raise access fault exceptions on PMP violations
RISC-V: Check for the effective memory privilege mode during PMP checks
RISC-V: Check PMP during Page Table Walks
RISC-V: Fix a PMP bug where it succeeds even if PMP entry is off
RISC-V: Fix a PMP check with the correct access size
Jim Wilson (1):
RISC-V: Update syscall list for 32-bit support.
Joel Sing (1):
RISC-V: Clear load reservations on context switch and SC
Michael Clark (2):
target/riscv: Implement riscv_cpu_unassigned_access disas/riscv: Disassemble reserved compressed encodings as illegal
Nathaniel Graff (1):
sifive_prci: Read and write PRCI registers
Palmer Dabbelt (3):
RISC-V: Fix a memory leak when realizing a sifive_e
RISC-V: Add support for the Zifencei extension
RISC-V: Add support for the Zicsr extension
Wladimir J. van der Laan (1):
disas/riscv: Fix rdinstreth constraint
.gitmodules | 3 + Makefile | 5 +- disas/riscv.c | 65 ++++++++--- hw/riscv/Makefile.objs | 1 + hw/riscv/boot.c | 154 +++++++++++++++++++++++++ hw/riscv/sifive_e.c | 30 ++--- hw/riscv/sifive_prci.c | 49 ++++++-- hw/riscv/sifive_u.c | 55 +++++---- hw/riscv/spike.c | 21 +--- hw/riscv/virt.c | 84 ++++++-------- include/hw/riscv/boot.h | 32 +++++ include/hw/riscv/sifive_e.h | 2 + include/hw/riscv/sifive_prci.h | 32 +++++ linux-user/riscv/syscall_nr.h | 15 ++- pc-bios/opensbi-riscv32-virt-fw_jump.bin | Bin 0 -> 28848 bytes pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin | Bin 0 -> 28904 bytes pc-bios/opensbi-riscv64-virt-fw_jump.bin | Bin 0 -> 28904 bytes qemu-deprecated.texi | 28 +++++ roms/Makefile | 48 ++++++-- roms/opensbi | 1 + target/riscv/cpu.c | 137 ++++++++++++++++------ target/riscv/cpu.h | 33 ++++-- target/riscv/cpu_bits.h | 1 + target/riscv/cpu_helper.c | 55 ++++++++- target/riscv/csr.c | 30 ++++- target/riscv/insn_trans/trans_privileged.inc.c | 2 +- target/riscv/insn_trans/trans_rva.inc.c | 8 +- target/riscv/insn_trans/trans_rvi.inc.c | 4 + target/riscv/pmp.c | 17 +-- target/riscv/pmp.h | 2 +- target/riscv/translate.c | 3 + 31 files changed, 705 insertions(+), 212 deletions(-) create mode 100644 hw/riscv/boot.c create mode 100644 include/hw/riscv/boot.h create mode 100644 pc-bios/opensbi-riscv32-virt-fw_jump.bin create mode 100644 pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin create mode 100644 pc-bios/opensbi-riscv64-virt-fw_jump.bin create mode 160000 roms/opensbi
[Qemu-devel] [PULL 01/34] target/riscv: Allow setting ISA extensions via CPU props
From: Alistair Francis <[email protected]>
This patch allows us to enable/disable the RISC-V ISA extensions from the QEMU command line. This works with the rv32 and rv64 machines. The idea is that in the future we can now add extensions and leave them disabled by default until enabled by the user.
--- target/riscv/cpu.c | 70 ++++++++++++++++++++++++++++++++++++++++++++-- target/riscv/cpu.h | 11 ++++++++ 2 files changed, 79 insertions(+), 2 deletions(-)
target/riscv/cpu.c +68 -2
@@ -24,6 +24,7 @@#include "cpu.h" #include "exec/exec-all.h" #include "qapi/error.h" +#include "qemu/error-report.h" #include "hw/qdev-properties.h" #include "migration/vmstate.h"
@@ -119,7 +120,8 @@ static void riscv_any_cpu_init(Object *obj)static void riscv_base32_cpu_init (Object *obj) {CPURISCVState *env = &RISCV_CPU (obj)->env; -set_misa (env,RV32 |RVI |RVM |RVA |RVF |RVD |RVC |RVS |RVU ); +/* We set this in the realise function */ +set_misa (env,0 ); }static void rv32gcsu_priv1_09_1_cpu_init (Object *obj)
@@ -156,7 +158,8 @@ static void rv32imacu_nommu_cpu_init(Object *obj)static void riscv_base64_cpu_init (Object *obj) {CPURISCVState *env = &RISCV_CPU (obj)->env; -set_misa (env,RV64 |RVI |RVM |RVA |RVF |RVD |RVC |RVS |RVU ); +/* We set this in the realise function */ +set_misa (env,0 ); }static void rv64gcsu_priv1_09_1_cpu_init (Object *obj)
@@ -315,6 +318,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)RISCVCPUClass *mcc =RISCV_CPU_GET_CLASS (dev);int priv_version =PRIV_VERSION_1_10_0 ;int user_version =USER_VERSION_2_02_0 ; +target_ulong target_misa =0 ;Error *local_err =NULL ;cpu_exec_realizefn (cs, &local_err);
@@ -358,6 +362,58 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)set_feature (env,RISCV_FEATURE_PMP ); } +/* If misa isn't set (rv32 and rv64 machines) set it here */ +if (!env->misa) { +/* Do some ISA extension error checking */ +if (cpu->cfg.ext_i && cpu->cfg.ext_e) { +error_setg (errp, +"I and E extensions are incompatible" ); +return ; + } + +if (cpu->cfg.ext_g && !(cpu->cfg.ext_i & cpu->cfg.ext_m & + cpu->cfg.ext_a & cpu->cfg.ext_f & + cpu->cfg.ext_d)) { +warn_report ("Setting G will also set IMAFD" ); + cpu->cfg.ext_i = true; + cpu->cfg.ext_m = true; + cpu->cfg.ext_a = true; + cpu->cfg.ext_f = true; + cpu->cfg.ext_d = true; + } + +/* Set the ISA extensions, checks should have happened above */ +if (cpu->cfg.ext_i) { + target_misa |=RVI ; + } +if (cpu->cfg.ext_e) { + target_misa |=RVE ; + } +if (cpu->cfg.ext_m) { + target_misa |=RVM ; + } +if (cpu->cfg.ext_a) { + target_misa |=RVA ; + } +if (cpu->cfg.ext_f) { + target_misa |=RVF ; + } +if (cpu->cfg.ext_d) { + target_misa |=RVD ; + } +if (cpu->cfg.ext_c) { + target_misa |=RVC ; + } +if (cpu->cfg.ext_s) { + target_misa |=RVS ; + } +if (cpu->cfg.ext_u) { + target_misa |=RVU ; + } + +set_misa (env,RVXLEN | target_misa); + } +riscv_cpu_register_gdb_regs_for_features (cs);qemu_init_vcpu (cs);
@@ -379,6 +435,16 @@ static const VMStateDescription vmstate_riscv_cpu = { };static Property riscv_cpu_properties[] = { +DEFINE_PROP_BOOL ("i" ,RISCVCPU , cfg.ext_i, true), +DEFINE_PROP_BOOL ("e" ,RISCVCPU , cfg.ext_e, false), +DEFINE_PROP_BOOL ("g" ,RISCVCPU , cfg.ext_g, true), +DEFINE_PROP_BOOL ("m" ,RISCVCPU , cfg.ext_m, true), +DEFINE_PROP_BOOL ("a" ,RISCVCPU , cfg.ext_a, true), +DEFINE_PROP_BOOL ("f" ,RISCVCPU , cfg.ext_f, true), +DEFINE_PROP_BOOL ("d" ,RISCVCPU , cfg.ext_d, true), +DEFINE_PROP_BOOL ("c" ,RISCVCPU , cfg.ext_c, true), +DEFINE_PROP_BOOL ("s" ,RISCVCPU , cfg.ext_s, true), +DEFINE_PROP_BOOL ("u" ,RISCVCPU , cfg.ext_u, true),DEFINE_PROP_STRING ("priv_spec" ,RISCVCPU , cfg.priv_spec),DEFINE_PROP_STRING ("user_spec" ,RISCVCPU , cfg.user_spec),DEFINE_PROP_BOOL ("mmu" ,RISCVCPU , cfg.mmu, true),
target/riscv/cpu.h +11 -0
@@ -211,6 +211,17 @@ typedef struct RISCVCPU {/* Configuration Settings */ struct { +bool ext_i; +bool ext_e; +bool ext_g; +bool ext_m; +bool ext_a; +bool ext_f; +bool ext_d; +bool ext_c; +bool ext_s; +bool ext_u; +char *priv_spec;char *user_spec;bool mmu;
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 02/34] sifive_prci: Read and write PRCI registers
In reply to Palmer DabbeltFrom: Nathaniel Graff <[email protected]>
Writes to the SiFive PRCI registers are preserved while leaving the ready bits set for the HFX/HFR oscillators and the lock bit set for the PLL.
--- hw/riscv/sifive_prci.c | 49 ++++++++++++++++++++++++++++------ include/hw/riscv/sifive_prci.h | 32 ++++++++++++++++++++++ 2 files changed, 73 insertions(+), 8 deletions(-)
hw/riscv/sifive_prci.c +41 -8
@@ -24,15 +24,18 @@#include "target/riscv/cpu.h" #include "hw/riscv/sifive_prci.h" -/* currently implements enough to mock freedom-e-sdk BSP clock programming */ -static uint64_t sifive_prci_read (void *opaque,hwaddr addr,unsigned int size) { -if (addr ==0 /* PRCI_HFROSCCFG */ ) { -return 1 <<31 ;/* ROSC_RDY */ - } -if (addr ==8 /* PRCI_PLLCFG */ ) { -return 1 <<31 ;/* PLL_LOCK */ +SiFivePRCIState *s = opaque; +switch (addr) { +case SIFIVE_PRCI_HFROSCCFG : +return s->hfrosccfg; +case SIFIVE_PRCI_HFXOSCCFG : +return s->hfxosccfg; +case SIFIVE_PRCI_PLLCFG : +return s->pllcfg; +case SIFIVE_PRCI_PLLOUTDIV : +return s->plloutdiv; }hw_error ("%s: read: addr=0x%x\n" , __func__, (int )addr);return 0 ;
@@ -41,7 +44,30 @@ static uint64_t sifive_prci_read(void *opaque, hwaddr addr, unsigned int size)static void sifive_prci_write (void *opaque,hwaddr addr,uint64_t val64,unsigned int size) { -/* discard writes */ +SiFivePRCIState *s = opaque; +switch (addr) { +case SIFIVE_PRCI_HFROSCCFG : + s->hfrosccfg = (uint32_t ) val64; +/* OSC stays ready */ + s->hfrosccfg |=SIFIVE_PRCI_HFROSCCFG_RDY ; +break ; +case SIFIVE_PRCI_HFXOSCCFG : + s->hfxosccfg = (uint32_t ) val64; +/* OSC stays ready */ + s->hfxosccfg |=SIFIVE_PRCI_HFXOSCCFG_RDY ; +break ; +case SIFIVE_PRCI_PLLCFG : + s->pllcfg = (uint32_t ) val64; +/* PLL stays locked */ + s->pllcfg |=SIFIVE_PRCI_PLLCFG_LOCK ; +break ; +case SIFIVE_PRCI_PLLOUTDIV : + s->plloutdiv = (uint32_t ) val64; +break ; +default : +hw_error ("%s: bad write: addr=0x%x v=0x%x\n" , + __func__, (int )addr, (int )val64); + } }static const MemoryRegionOps sifive_prci_ops = {
@@ -61,6 +87,13 @@ static void sifive_prci_init(Object *obj)memory_region_init_io (&s->mmio, obj, &sifive_prci_ops, s,TYPE_SIFIVE_PRCI ,0x8000 );sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->mmio); + + s->hfrosccfg = (SIFIVE_PRCI_HFROSCCFG_RDY |SIFIVE_PRCI_HFROSCCFG_EN ); + s->hfxosccfg = (SIFIVE_PRCI_HFROSCCFG_RDY |SIFIVE_PRCI_HFROSCCFG_EN ); + s->pllcfg = (SIFIVE_PRCI_PLLCFG_REFSEL |SIFIVE_PRCI_PLLCFG_BYPASS | +SIFIVE_PRCI_PLLCFG_LOCK ); + s->plloutdiv =SIFIVE_PRCI_PLLOUTDIV_DIV1 ; + }static const TypeInfo sifive_prci_info = {
include/hw/riscv/sifive_prci.h +32 -0
@@ -19,6 +19,34 @@#ifndef HW_SIFIVE_PRCI_H #define HW_SIFIVE_PRCI_H +enum { +SIFIVE_PRCI_HFROSCCFG =0x0 , +SIFIVE_PRCI_HFXOSCCFG =0x4 , +SIFIVE_PRCI_PLLCFG =0x8 , +SIFIVE_PRCI_PLLOUTDIV =0xC +}; + +enum { +SIFIVE_PRCI_HFROSCCFG_RDY = (1 <<31 ), +SIFIVE_PRCI_HFROSCCFG_EN = (1 <<30 ) +}; + +enum { +SIFIVE_PRCI_HFXOSCCFG_RDY = (1 <<31 ), +SIFIVE_PRCI_HFXOSCCFG_EN = (1 <<30 ) +}; + +enum { +SIFIVE_PRCI_PLLCFG_PLLSEL = (1 <<16 ), +SIFIVE_PRCI_PLLCFG_REFSEL = (1 <<17 ), +SIFIVE_PRCI_PLLCFG_BYPASS = (1 <<18 ), +SIFIVE_PRCI_PLLCFG_LOCK = (1 <<31 ) +}; + +enum { +SIFIVE_PRCI_PLLOUTDIV_DIV1 = (1 <<8 ) +}; +#define TYPE_SIFIVE_PRCI "riscv.sifive.prci"#define SIFIVE_PRCI (obj) \
@@ -30,6 +58,10 @@ typedef struct SiFivePRCIState {/*< public >*/ MemoryRegion mmio; +uint32_t hfrosccfg; +uint32_t hfxosccfg; +uint32_t pllcfg; +uint32_t plloutdiv; } SiFivePRCIState;DeviceState *sifive_prci_create (hwaddr addr);
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 05/34] RISC-V: Only Check PMP if MMU translation succeeds
In reply to Palmer DabbeltFrom: Hesham Almatary <[email protected]>
The current implementation unnecessarily checks for PMP even if MMU translation failed. This may trigger a wrong PMP access exception instead of
a page exception.
For example, the very first instruction fetched after the first satp write in S-Mode will trigger a PMP access fault instead of an instruction fetch page fault.
This patch prioritises MMU exceptions over PMP exceptions and only checks for PMP if MMU translation succeeds. This patch is required for future commits that properly report PMP exception violations if PTW succeeds.
--- target/riscv/cpu_helper.c | 1 + 1 file changed, 1 insertion(+)
target/riscv/cpu_helper.c +1 -0
@@ -436,6 +436,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, " prot %d\n", __func__, address, ret, pa, prot);if (riscv_feature (env,RISCV_FEATURE_PMP ) && + (ret ==TRANSLATE_SUCCESS ) && !pmp_hart_has_privs (env, pa,TARGET_PAGE_SIZE ,1 << access_type)) { ret =TRANSLATE_FAIL ; }
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 03/34] target/riscv: Fix PMP range boundary address bug
In reply to Palmer DabbeltFrom: Dayeol Lee <[email protected]>
A wrong address is passed to pmp_is_in_range while checking if a memory access is within a PMP range.
Since the ending address of the pmp range (i.e., pmp_state.addr[i].ea) is set to the last address in the range (i.e., pmp base + pmp size - 1), memory accesses containg the last address in the range will always fail.
For example, assume that a PMP range is 4KB from 0x87654000 such that the last address within the range is 0x87654fff.
1-byte access to 0x87654fff should be considered to be fully inside the PMP range.
However the access now fails and complains partial inclusion because pmp_is_in_range(env, i, addr + size) returns 0 whereas pmp_is_in_range(env, i, addr) returns 1.
--- target/riscv/pmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/pmp.c +1 -1
@@ -245,7 +245,7 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,from low to high */ for (i =0 ; i <MAX_RISCV_PMPS ; i++) { s =pmp_is_in_range (env, i, addr); - e =pmp_is_in_range (env, i, addr + size); + e =pmp_is_in_range (env, i, addr + size -1 );/* partially inside */ if ((s + e) ==1 ) {
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 04/34] target/riscv: Implement riscv_cpu_unassigned_access
In reply to Palmer DabbeltFrom: Michael Clark <[email protected]>
This patch adds support for the riscv_cpu_unassigned_access call and will raise a load or store access fault.
[Changes by AF:
- Squash two patches and rewrite commit message
- Set baddr to the access address
]
--- target/riscv/cpu.c | 1 + target/riscv/cpu.h | 2 ++ target/riscv/cpu_helper.c | 16 ++++++++++++++++ 3 files changed, 19 insertions(+)
target/riscv/cpu.c +1 -0
@@ -482,6 +482,7 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) cc->gdb_stop_before_watchpoint = true; cc->disas_set_info = riscv_cpu_disas_set_info;#ifndef CONFIG_USER_ONLY + cc->do_unassigned_access = riscv_cpu_unassigned_access; cc->do_unaligned_access = riscv_cpu_do_unaligned_access; cc->get_phys_page_debug = riscv_cpu_get_phys_page_debug;#endif
target/riscv/cpu.h +2 -0
@@ -259,6 +259,8 @@ void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr,bool riscv_cpu_tlb_fill (CPUState *cs,vaddr address,int size,MMUAccessType access_type,int mmu_idx,bool probe,uintptr_t retaddr); +void riscv_cpu_unassigned_access (CPUState *cpu,hwaddr addr,bool is_write, +bool is_exec,int unused,unsigned size);char *riscv_isa_string (RISCVCPU *cpu);void riscv_cpu_list (void );
target/riscv/cpu_helper.c +16 -0
@@ -375,6 +375,22 @@ hwaddr riscv_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)return phys_addr; } +void riscv_cpu_unassigned_access (CPUState *cs,hwaddr addr,bool is_write, +bool is_exec,int unused,unsigned size) +{ +RISCVCPU *cpu =RISCV_CPU (cs); +CPURISCVState *env = &cpu->env; + +if (is_write) { + cs->exception_index =RISCV_EXCP_STORE_AMO_ACCESS_FAULT ; + }else { + cs->exception_index =RISCV_EXCP_LOAD_ACCESS_FAULT ; + } + + env->badaddr = addr; +riscv_raise_exception (&cpu->env, cs->exception_index,GETPC ()); +} +void riscv_cpu_do_unaligned_access (CPUState *cs,vaddr addr,MMUAccessType access_type,int mmu_idx,uintptr_t retaddr)
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 19/34] target/riscv: Remove user version information
In reply to Palmer DabbeltFrom: Alistair Francis <[email protected]>
Remove the user version information. This was never used and never publically exposed in a release of QEMU, so let's just remove it. In future to manage versions we can extend the extension properties to specify version.
--- target/riscv/cpu.c | 32 +++++++++----------------------- target/riscv/cpu.h | 2 -- 2 files changed, 9 insertions(+), 25 deletions(-)
target/riscv/cpu.c +9 -23
@@ -89,9 +89,8 @@ static void set_misa(CPURISCVState *env, target_ulong misa) env->misa_mask = env->misa = misa; } -static void set_versions (CPURISCVState *env,int user_ver,int priv_ver) +static void set_priv_version (CPURISCVState *env,int priv_ver) { - env->user_ver = user_ver; env->priv_ver = priv_ver; }
@@ -111,7 +110,7 @@ static void riscv_any_cpu_init(Object *obj) {CPURISCVState *env = &RISCV_CPU (obj)->env;set_misa (env,RVXLEN |RVI |RVM |RVA |RVF |RVD |RVC |RVU ); -set_versions (env,USER_VERSION_2_02_0 ,PRIV_VERSION_1_11_0 ); +set_priv_version (env,PRIV_VERSION_1_11_0 );set_resetvec (env,DEFAULT_RSTVEC ); }
@@ -128,7 +127,7 @@ static void rv32gcsu_priv1_09_1_cpu_init(Object *obj) {CPURISCVState *env = &RISCV_CPU (obj)->env;set_misa (env,RV32 |RVI |RVM |RVA |RVF |RVD |RVC |RVS |RVU ); -set_versions (env,USER_VERSION_2_02_0 ,PRIV_VERSION_1_09_1 ); +set_priv_version (env,PRIV_VERSION_1_09_1 );set_resetvec (env,DEFAULT_RSTVEC );set_feature (env,RISCV_FEATURE_MMU );set_feature (env,RISCV_FEATURE_PMP );
@@ -138,7 +137,7 @@ static void rv32gcsu_priv1_10_0_cpu_init(Object *obj) {CPURISCVState *env = &RISCV_CPU (obj)->env;set_misa (env,RV32 |RVI |RVM |RVA |RVF |RVD |RVC |RVS |RVU ); -set_versions (env,USER_VERSION_2_02_0 ,PRIV_VERSION_1_10_0 ); +set_priv_version (env,PRIV_VERSION_1_10_0 );set_resetvec (env,DEFAULT_RSTVEC );set_feature (env,RISCV_FEATURE_MMU );set_feature (env,RISCV_FEATURE_PMP );
@@ -148,7 +147,7 @@ static void rv32imacu_nommu_cpu_init(Object *obj) {CPURISCVState *env = &RISCV_CPU (obj)->env;set_misa (env,RV32 |RVI |RVM |RVA |RVC |RVU ); -set_versions (env,USER_VERSION_2_02_0 ,PRIV_VERSION_1_10_0 ); +set_priv_version (env,PRIV_VERSION_1_10_0 );set_resetvec (env,DEFAULT_RSTVEC );set_feature (env,RISCV_FEATURE_PMP ); }
@@ -166,7 +165,7 @@ static void rv64gcsu_priv1_09_1_cpu_init(Object *obj) {CPURISCVState *env = &RISCV_CPU (obj)->env;set_misa (env,RV64 |RVI |RVM |RVA |RVF |RVD |RVC |RVS |RVU ); -set_versions (env,USER_VERSION_2_02_0 ,PRIV_VERSION_1_09_1 ); +set_priv_version (env,PRIV_VERSION_1_09_1 );set_resetvec (env,DEFAULT_RSTVEC );set_feature (env,RISCV_FEATURE_MMU );set_feature (env,RISCV_FEATURE_PMP );
@@ -176,7 +175,7 @@ static void rv64gcsu_priv1_10_0_cpu_init(Object *obj) {CPURISCVState *env = &RISCV_CPU (obj)->env;set_misa (env,RV64 |RVI |RVM |RVA |RVF |RVD |RVC |RVS |RVU ); -set_versions (env,USER_VERSION_2_02_0 ,PRIV_VERSION_1_10_0 ); +set_priv_version (env,PRIV_VERSION_1_10_0 );set_resetvec (env,DEFAULT_RSTVEC );set_feature (env,RISCV_FEATURE_MMU );set_feature (env,RISCV_FEATURE_PMP );
@@ -186,7 +185,7 @@ static void rv64imacu_nommu_cpu_init(Object *obj) {CPURISCVState *env = &RISCV_CPU (obj)->env;set_misa (env,RV64 |RVI |RVM |RVA |RVC |RVU ); -set_versions (env,USER_VERSION_2_02_0 ,PRIV_VERSION_1_10_0 ); +set_priv_version (env,PRIV_VERSION_1_10_0 );set_resetvec (env,DEFAULT_RSTVEC );set_feature (env,RISCV_FEATURE_PMP ); }
@@ -317,7 +316,6 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)CPURISCVState *env = &cpu->env;RISCVCPUClass *mcc =RISCV_CPU_GET_CLASS (dev);int priv_version =PRIV_VERSION_1_11_0 ; -int user_version =USER_VERSION_2_02_0 ;target_ulong target_misa =0 ;Error *local_err =NULL ;
@@ -342,18 +340,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) } } -if (cpu->cfg.user_spec) { -if (!g_strcmp0 (cpu->cfg.user_spec,"v2.02.0" )) { - user_version =USER_VERSION_2_02_0 ; - }else { -error_setg (errp, -"Unsupported user spec version '%s'" , - cpu->cfg.user_spec); -return ; - } - } - -set_versions (env, user_version, priv_version); +set_priv_version (env, priv_version);set_resetvec (env,DEFAULT_RSTVEC );if (cpu->cfg.mmu) {
@@ -454,7 +441,6 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("s" ,RISCVCPU , cfg.ext_s, true),DEFINE_PROP_BOOL ("u" ,RISCVCPU , cfg.ext_u, true),DEFINE_PROP_STRING ("priv_spec" ,RISCVCPU , cfg.priv_spec), -DEFINE_PROP_STRING ("user_spec" ,RISCVCPU , cfg.user_spec),DEFINE_PROP_BOOL ("mmu" ,RISCVCPU , cfg.mmu, true),DEFINE_PROP_BOOL ("pmp" ,RISCVCPU , cfg.pmp, true), DEFINE_PROP_END_OF_LIST(),
target/riscv/cpu.h +0 -2
@@ -78,7 +78,6 @@ enum { RISCV_FEATURE_MISA }; -#define USER_VERSION_2_02_0 0x00020200#define PRIV_VERSION_1_09_1 0x00010901#define PRIV_VERSION_1_10_0 0x00011000#define PRIV_VERSION_1_11_0 0x00011100
@@ -105,7 +104,6 @@ struct CPURISCVState {target_ulong badaddr; -target_ulong user_ver;target_ulong priv_ver;target_ulong misa;target_ulong misa_mask;
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 10/34] RISC-V: Fix a PMP check with the correct access size
In reply to Palmer DabbeltFrom: Hesham Almatary <[email protected]>
The PMP check should be of the memory access size rather than TARGET_PAGE_SIZE.
--- target/riscv/cpu_helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
target/riscv/cpu_helper.c +1 -2
@@ -452,8 +452,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,if (riscv_feature (env,RISCV_FEATURE_PMP ) && (ret ==TRANSLATE_SUCCESS ) && - !pmp_hart_has_privs (env, pa,TARGET_PAGE_SIZE ,1 << access_type, - mode)) { + !pmp_hart_has_privs (env, pa, size,1 << access_type, mode)) { ret =TRANSLATE_PMP_FAIL ; }if (ret ==TRANSLATE_PMP_FAIL ) {
Signature · 1 line
2.21.0
Re: [Qemu-devel] [Qemu-riscv] [PULL 10/34] RISC-V: Fix a PMP check with the correct access size
I think this patch is slightly incorrect. If the PMP region is valid for the size of the access, but not the rest of the page then a few lines down in this function the entire page should not be placed into the TLB. Instead only the portion of the page that passed the access check should be included. To give an example of where this goes wrong, in the code below access to address 0x90000008 should always fail due to PMP rules, but if the TLB has already been primed by loading the (allowed) address 0x90000000 then no fault will be triggered. Notably, this code also executes improperly without the patch because the first ld instruction traps when it shouldn't.
li t0, 0x0000000024000000 // region[0]: 0x90000000..0x90000007 csrw pmpaddr0, t0
li t0, 0x00000000240001FF // region[1]: 0x90000000..0x90000fff csrw pmpaddr1, t0
li t0, 0x1F0000000000989F // cfg[0] = LXRW, cfg[1] = L csrw pmpcfg0, t0
sfence.vma
li t0, 0x90000000
ld s0, 0(t0)
ld s1, 8(t0) // NO TRAP: address is incorrectly in TLB!
sfence.vma
ld s1, 8(t0) // TRAP: TLB has been flushed!
I think that the proper fix would be to first do a PMP check for the full PAGE_SIZE and execute normally if it passes. Then in the event the full page fails, there could be a more granular PMP check with only the accessed region inserted as an entry in the TLB.
Unrelated question: should I be sending "Reviewed By" lines if I read through patches that seem reasonable? Or there some formal process I'd have to go through first to be approved?
Jonathan
Quoted 32 lines · Palmer Dabbelt
From: Hesham Almatary <[email protected]>
The PMP check should be of the memory access size rather than
TARGET_PAGE_SIZE.Signed-off-by Hesham Almatary <[email protected]>Reviewed-by Alistair Francis <[email protected]>Signed-off-by Palmer Dabbelt <[email protected]>--- target/riscv/cpu_helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)target/riscv/cpu_helper.c +1
-2@@ -452,8 +452,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address,int size, if (riscv_feature(env, RISCV_FEATURE_PMP) && (ret == TRANSLATE_SUCCESS) && - !pmp_hart_has_privs(env, pa, TARGET_PAGE_SIZE, 1 << access_type, - mode)) { + !pmp_hart_has_privs(env, pa, size, 1 << access_type, mode)) { ret = TRANSLATE_PMP_FAIL; }if (ret == TRANSLATE_PMP_FAIL) {--
2.21.0
Re: [Qemu-devel] [Qemu-riscv] [PULL 10/34] RISC-V: Fix a PMP check with the correct access size
Quoted 17 lines · Jonathan Behrens
I think this patch is slightly incorrect. If the PMP region is valid for the size of the access, but not the rest of the page then a few lines down in this function the entire page should not be placed into the TLB. Instead only the portion of the page that passed the access check should be included. To give an example of where this goes wrong, in the code below access to address
0x90000008should always fail due to PMP rules, but if the TLB has already been primed by loading the (allowed) address0x90000000then no fault will be triggered. Notably, this code also executes improperly without the patch because the firstldinstruction traps when it shouldn't.li t0,
0x0000000024000000// region[0]: 0x90000000..0x90000007 csrw pmpaddr0, t0li t0,
0x00000000240001FF// region[1]: 0x90000000..0x90000fff csrw pmpaddr1, t0
Quoted 8 lines
li t0,
0x1F0000000000989F// cfg[0] = LXRW, cfg[1] = L csrw pmpcfg0, t0sfence.vma
li t0,
0x90000000
ld s0, 0(t0)
ld s1, 8(t0) // NO TRAP: address is incorrectly in TLB!
Nice test case.
Quoted 4 lines
I think that the proper fix would be to first do a PMP check for the full
PAGE_SIZEand execute normally if it passes. Then in the event the full page fails, there could be a more granular PMP check with only the accessed region inserted as an entry in the TLB.
This feature looks to be almost identical to the ARM m-profile MPU.
The fix is:
If the PMP check is valid for the entire page, then continue to call tlb_set_page with size=TARGET_PAGE_SIZE.
If the PMP check is valid for the current access, but not for the entire page, then call tlb_set_page with any size < TARGET_PAGE_SIZE. This change alone is sufficient, even though the full argument tuple (paddr, vaddr, size) no longer quite make perfect sense. (For the arm mpu, we compute some 1 << rsize, but the actual value is never used; setting size=1 would be sufficient.)
Any size < TARGET_PAGE_SIZE will cause TLB_RECHECK to be set for the page, which will force all accesses to the page to go back through riscv_cpu_tlb_fill for re-validation.
Quoted 3 lines
Unrelated question: should I be sending "Reviewed By" lines if I read through patches that seem reasonable? Or there some formal process I'd have to go through first to be approved?
No formal process. More eyes are always welcome.
r~
Re: [Qemu-devel] [Qemu-riscv] [PULL 10/34] RISC-V: Fix a PMP check with the correct access size
Quoted 47 lines · On Thu, 27 Jun 2019 11:23:20 PDT (-0700), [email protected] wrote:
Quoted 17 lines · Jonathan Behrens
I think this patch is slightly incorrect. If the PMP region is valid for the size of the access, but not the rest of the page then a few lines down in this function the entire page should not be placed into the TLB. Instead only the portion of the page that passed the access check should be included. To give an example of where this goes wrong, in the code below access to address
0x90000008should always fail due to PMP rules, but if the TLB has already been primed by loading the (allowed) address0x90000000then no fault will be triggered. Notably, this code also executes improperly without the patch because the firstldinstruction traps when it shouldn't.li t0,
0x0000000024000000// region[0]: 0x90000000..0x90000007 csrw pmpaddr0, t0li t0,
0x00000000240001FF// region[1]: 0x90000000..0x90000fff csrw pmpaddr1, t0Quoted 8 lines
li t0,
0x1F0000000000989F// cfg[0] = LXRW, cfg[1] = L csrw pmpcfg0, t0sfence.vma
li t0,
0x90000000
ld s0, 0(t0)
ld s1, 8(t0) // NO TRAP: address is incorrectly in TLB!Nice test case.
Quoted 4 lines
I think that the proper fix would be to first do a PMP check for the full
PAGE_SIZEand execute normally if it passes. Then in the event the full page fails, there could be a more granular PMP check with only the accessed region inserted as an entry in the TLB.This feature looks to be almost identical to the ARM m-profile MPU.
The fix is:
If the PMP check is valid for the entire page, then continue to call
tlb_set_pagewith size=TARGET_PAGE_SIZE.If the PMP check is valid for the current access, but not for the entire page, then call
tlb_set_pagewith any size <TARGET_PAGE_SIZE. This change alone is sufficient, even though the full argument tuple (paddr, vaddr, size) no longer quite make perfect sense. (For the arm mpu, we compute some 1 << rsize, but the actual value is never used; setting size=1 would be sufficient.)
Quoted 3 lines
Any size <
TARGET_PAGE_SIZEwill causeTLB_RECHECKto be set for the page, which will force all accesses to the page to go back throughriscv_cpu_tlb_fillfor re-validation.
RISC-V allows another option: support for fine-grained PMPs is optional, which allows implementations ignore this issue to save on hardware costs. It looks like Rocket leaves this as a parameter
https://github.com/chipsalliance/rocket-chip/blob/master/src/main/scala/rocket/TLB.scala#L159
but our implementations always have page-granularity PMPs if virtual memory is supported.
Unless anyone objects, I'll restrict the PMP granularity to 4K on all systems that support virtual memory as a bug fix. We can add the configuration option in as a feature.
Quoted 8 lines
Quoted 3 lines
Unrelated question: should I be sending "Reviewed By" lines if I read through patches that seem reasonable? Or there some formal process I'd have to go through first to be approved?
No formal process. More eyes are always welcome.
r~
[Qemu-devel] [PULL 27/34] disas/riscv: Fix `rdinstreth` constraint
In reply to Palmer DabbeltFrom: "Wladimir J. van der Laan" <[email protected]>
The constraint for rdinstreth was comparing the csr number to 0xc80, which is cycleh instead. Fix this.
--- disas/riscv.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
disas/riscv.c +3 -2
@@ -614,7 +614,8 @@ static const rvc_constraint rvcc_rdtime[] = { rvc_rs1_eq_x0, rvc_csr_eq_0xc01, rstatic const rvc_constraint rvcc_rdinstret[] = { rvc_rs1_eq_x0, rvc_csr_eq_0xc02, rvc_end };static const rvc_constraint rvcc_rdcycleh[] = { rvc_rs1_eq_x0, rvc_csr_eq_0xc80, rvc_end };static const rvc_constraint rvcc_rdtimeh[] = { rvc_rs1_eq_x0, rvc_csr_eq_0xc81, rvc_end }; -static const rvc_constraint rvcc_rdinstreth[] = { rvc_rs1_eq_x0, rvc_csr_eq_0xc80, rvc_end }; +static const rvc_constraint rvcc_rdinstreth[] = { rvc_rs1_eq_x0, + rvc_csr_eq_0xc82, rvc_end };static const rvc_constraint rvcc_frcsr[] = { rvc_rs1_eq_x0, rvc_csr_eq_0x003, rvc_end };static const rvc_constraint rvcc_frrm[] = { rvc_rs1_eq_x0, rvc_csr_eq_0x002, rvc_end };static const rvc_constraint rvcc_frflags[] = { rvc_rs1_eq_x0, rvc_csr_eq_0x001, rvc_end };
@@ -1038,7 +1039,7 @@ const rv_opcode_data opcode_data[] = { {"c.srai" , rv_codec_cb_sh6, rv_fmt_rd_rs1_imm,NULL , rv_op_srai, rv_op_srai, rv_op_srai, rvcd_imm_nz }, { "c.andi", rv_codec_cb_imm, rv_fmt_rd_rs1_imm, NULL, rv_op_andi, - rv_op_andi, rv_op_andi, rvcd_imm_nz }, + rv_op_andi, rv_op_andi }, { "c.sub", rv_codec_cs, rv_fmt_rd_rs1_rs2, NULL, rv_op_sub, rv_op_sub, rv_op_sub }, { "c.xor", rv_codec_cs, rv_fmt_rd_rs1_rs2, NULL, rv_op_xor, rv_op_xor, rv_op_xor }, { "c.or", rv_codec_cs, rv_fmt_rd_rs1_rs2, NULL, rv_op_or, rv_op_or, rv_op_or },
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 08/34] RISC-V: Check PMP during Page Table Walks
In reply to Palmer DabbeltFrom: Hesham Almatary <[email protected]>
The PMP should be checked when doing a page table walk, and report access fault exception if the to-be-read PTE failed the PMP check.
--- target/riscv/cpu.h | 1 + target/riscv/cpu_helper.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-)
target/riscv/cpu.h +1 -0
@@ -81,6 +81,7 @@ enum {#define PRIV_VERSION_1_09_1 0x00010901#define PRIV_VERSION_1_10_0 0x00011000 +#define TRANSLATE_PMP_FAIL 2#define TRANSLATE_FAIL 1#define TRANSLATE_SUCCESS 0#define MMU_USER_IDX 3
target/riscv/cpu_helper.c +9 -1
@@ -230,6 +230,12 @@ restart:/* check that physical address of PTE is legal */ target_ulong pte_addr = base + idx * ptesize; + +if (riscv_feature (env,RISCV_FEATURE_PMP ) && + !pmp_hart_has_privs (env, pte_addr,sizeof (target_ulong), +1 <<MMU_DATA_LOAD ,PRV_S )) { +return TRANSLATE_PMP_FAIL ; + }#if defined(TARGET_RISCV32 )target_ulong pte =ldl_phys (cs->as, pte_addr);#elif defined(TARGET_RISCV64 )
@@ -448,8 +454,10 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, (ret == TRANSLATE_SUCCESS) && !pmp_hart_has_privs(env, pa, TARGET_PAGE_SIZE, 1 << access_type, mode)) { + ret =TRANSLATE_PMP_FAIL ; + } +if (ret ==TRANSLATE_PMP_FAIL ) { pmp_violation = true; - ret =TRANSLATE_FAIL ; }if (ret ==TRANSLATE_SUCCESS ) { tlb_set_page(cs, address & TARGET_PAGE_MASK, pa & TARGET_PAGE_MASK,
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 21/34] RISC-V: Add support for the Zifencei extension
In reply to Palmer Dabbeltfence.i has been split out of the base ISA as part of the ratification process. This patch adds a Zifencei argument, which disables the fence.i instruction.
--- target/riscv/cpu.c | 1 + target/riscv/cpu.h | 1 + target/riscv/insn_trans/trans_rvi.inc.c | 4 ++++ target/riscv/translate.c | 3 +++ 4 files changed, 9 insertions(+)
target/riscv/cpu.c +1 -0
@@ -441,6 +441,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("s" ,RISCVCPU , cfg.ext_s, true),DEFINE_PROP_BOOL ("u" ,RISCVCPU , cfg.ext_u, true),DEFINE_PROP_BOOL ("Counters" ,RISCVCPU , cfg.ext_counters, true), +DEFINE_PROP_BOOL ("Zifencei" ,RISCVCPU , cfg.ext_ifencei, true),DEFINE_PROP_STRING ("priv_spec" ,RISCVCPU , cfg.priv_spec),DEFINE_PROP_BOOL ("mmu" ,RISCVCPU , cfg.mmu, true), DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true),
target/riscv/cpu.h +1 -0
@@ -223,6 +223,7 @@ typedef struct RISCVCPU {bool ext_s;bool ext_u;bool ext_counters; +bool ext_ifencei;char *priv_spec;char *user_spec;
target/riscv/insn_trans/trans_rvi.inc.c +4 -0
@@ -484,6 +484,10 @@ static bool trans_fence(DisasContext *ctx, arg_fence *a)static bool trans_fence_i (DisasContext *ctx,arg_fence_i *a) { +if (!ctx->ext_ifencei) { +return false; + } +/* * FENCE_I is a no-op in QEMU, * however we need to end the translation block
target/riscv/translate.c +3 -0
@@ -54,6 +54,7 @@ typedef struct DisasContext {to any system register, which includes CSR_FRM, so we do not have to reset this known value. */ int frm; +bool ext_ifencei; } DisasContext;#ifdef TARGET_RISCV64
@@ -752,6 +753,7 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) {DisasContext *ctx =container_of (dcbase, DisasContext, base);CPURISCVState *env = cs->env_ptr; +RISCVCPU *cpu =RISCV_CPU (cs); ctx->pc_succ_insn = ctx->base.pc_first; ctx->mem_idx = ctx->base.tb->flags &TB_FLAGS_MMU_MASK ;
@@ -759,6 +761,7 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->priv_ver = env->priv_ver; ctx->misa = env->misa; ctx->frm =-1 ;/* unknown rounding mode */ + ctx->ext_ifencei = cpu->cfg.ext_ifencei; }static void riscv_tr_tb_start (DisasContextBase *db,CPUState *cpu)
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 13/34] target/riscv: Restructure deprecatd CPUs
In reply to Palmer DabbeltFrom: Alistair Francis <[email protected]>
Restructure the deprecated CPUs to make it clear in the code that these are depreated. They are already marked as deprecated in qemu-deprecated.texi. There are no functional changes.
--- target/riscv/cpu.c | 18 ++++++++++-------- target/riscv/cpu.h | 13 +++++++------ 2 files changed, 17 insertions(+), 14 deletions(-)
target/riscv/cpu.c +10 -8
@@ -559,18 +559,20 @@ static const TypeInfo riscv_cpu_type_infos[] = { DEFINE_CPU(TYPE_RISCV_CPU_ANY, riscv_any_cpu_init),#if defined(TARGET_RISCV32 )DEFINE_CPU (TYPE_RISCV_CPU_BASE32 , riscv_base32_cpu_init), -DEFINE_CPU (TYPE_RISCV_CPU_RV32GCSU_V1_09_1 , rv32gcsu_priv1_09_1_cpu_init), -DEFINE_CPU (TYPE_RISCV_CPU_RV32GCSU_V1_10_0 , rv32gcsu_priv1_10_0_cpu_init), -DEFINE_CPU (TYPE_RISCV_CPU_RV32IMACU_NOMMU , rv32imacu_nommu_cpu_init),DEFINE_CPU (TYPE_RISCV_CPU_SIFIVE_E31 , rv32imacu_nommu_cpu_init), - DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U34, rv32gcsu_priv1_10_0_cpu_init) +DEFINE_CPU (TYPE_RISCV_CPU_SIFIVE_U34 , rv32gcsu_priv1_10_0_cpu_init), +/* Depreacted */ +DEFINE_CPU (TYPE_RISCV_CPU_RV32IMACU_NOMMU , rv32imacu_nommu_cpu_init), +DEFINE_CPU (TYPE_RISCV_CPU_RV32GCSU_V1_09_1 , rv32gcsu_priv1_09_1_cpu_init), + DEFINE_CPU(TYPE_RISCV_CPU_RV32GCSU_V1_10_0, rv32gcsu_priv1_10_0_cpu_init)#elif defined(TARGET_RISCV64 )DEFINE_CPU (TYPE_RISCV_CPU_BASE64 , riscv_base64_cpu_init), -DEFINE_CPU (TYPE_RISCV_CPU_RV64GCSU_V1_09_1 , rv64gcsu_priv1_09_1_cpu_init), -DEFINE_CPU (TYPE_RISCV_CPU_RV64GCSU_V1_10_0 , rv64gcsu_priv1_10_0_cpu_init), -DEFINE_CPU (TYPE_RISCV_CPU_RV64IMACU_NOMMU , rv64imacu_nommu_cpu_init),DEFINE_CPU (TYPE_RISCV_CPU_SIFIVE_E51 , rv64imacu_nommu_cpu_init), - DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U54, rv64gcsu_priv1_10_0_cpu_init) +DEFINE_CPU (TYPE_RISCV_CPU_SIFIVE_U54 , rv64gcsu_priv1_10_0_cpu_init), +/* Deprecated */ +DEFINE_CPU (TYPE_RISCV_CPU_RV64IMACU_NOMMU , rv64imacu_nommu_cpu_init), +DEFINE_CPU (TYPE_RISCV_CPU_RV64GCSU_V1_09_1 , rv64gcsu_priv1_09_1_cpu_init), + DEFINE_CPU(TYPE_RISCV_CPU_RV64GCSU_V1_10_0, rv64gcsu_priv1_10_0_cpu_init)#endif };
target/riscv/cpu.h +7 -6
@@ -35,16 +35,17 @@#define TYPE_RISCV_CPU_ANY RISCV_CPU_TYPE_NAME("any")#define TYPE_RISCV_CPU_BASE32 RISCV_CPU_TYPE_NAME("rv32")#define TYPE_RISCV_CPU_BASE64 RISCV_CPU_TYPE_NAME("rv64") -#define TYPE_RISCV_CPU_RV32GCSU_V1_09_1 RISCV_CPU_TYPE_NAME("rv32gcsu-v1.9.1") -#define TYPE_RISCV_CPU_RV32GCSU_V1_10_0 RISCV_CPU_TYPE_NAME("rv32gcsu-v1.10.0") -#define TYPE_RISCV_CPU_RV32IMACU_NOMMU RISCV_CPU_TYPE_NAME("rv32imacu-nommu") -#define TYPE_RISCV_CPU_RV64GCSU_V1_09_1 RISCV_CPU_TYPE_NAME("rv64gcsu-v1.9.1") -#define TYPE_RISCV_CPU_RV64GCSU_V1_10_0 RISCV_CPU_TYPE_NAME("rv64gcsu-v1.10.0") -#define TYPE_RISCV_CPU_RV64IMACU_NOMMU RISCV_CPU_TYPE_NAME("rv64imacu-nommu")#define TYPE_RISCV_CPU_SIFIVE_E31 RISCV_CPU_TYPE_NAME("sifive-e31")#define TYPE_RISCV_CPU_SIFIVE_E51 RISCV_CPU_TYPE_NAME("sifive-e51")#define TYPE_RISCV_CPU_SIFIVE_U34 RISCV_CPU_TYPE_NAME("sifive-u34")#define TYPE_RISCV_CPU_SIFIVE_U54 RISCV_CPU_TYPE_NAME("sifive-u54") +/* Deprecated */ +#define TYPE_RISCV_CPU_RV32IMACU_NOMMU RISCV_CPU_TYPE_NAME("rv32imacu-nommu") +#define TYPE_RISCV_CPU_RV32GCSU_V1_09_1 RISCV_CPU_TYPE_NAME("rv32gcsu-v1.9.1") +#define TYPE_RISCV_CPU_RV32GCSU_V1_10_0 RISCV_CPU_TYPE_NAME("rv32gcsu-v1.10.0") +#define TYPE_RISCV_CPU_RV64IMACU_NOMMU RISCV_CPU_TYPE_NAME("rv64imacu-nommu") +#define TYPE_RISCV_CPU_RV64GCSU_V1_09_1 RISCV_CPU_TYPE_NAME("rv64gcsu-v1.9.1") +#define TYPE_RISCV_CPU_RV64GCSU_V1_10_0 RISCV_CPU_TYPE_NAME("rv64gcsu-v1.10.0")#define RV32 ((target_ulong)1 << (TARGET_LONG_BITS - 2))#define RV64 ((target_ulong)2 << (TARGET_LONG_BITS - 2))
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 31/34] hw/riscv: Add support for loading a firmware
In reply to Palmer DabbeltFrom: Alistair Francis <[email protected]>
Add support for loading a firmware file for the virt machine and the SiFive U. This can be run with the following command:
qemu-system-riscv64 -machine virt -bios fw_jump.bin -kernel vmlinux
--- hw/riscv/boot.c | 26 ++++++++++++++++++++++++++ hw/riscv/sifive_u.c | 4 ++++ hw/riscv/virt.c | 4 ++++ include/hw/riscv/boot.h | 2 ++ 4 files changed, 36 insertions(+)
hw/riscv/boot.c +26 -0
@@ -23,8 +23,34 @@#include "exec/cpu-defs.h" #include "hw/loader.h" #include "hw/riscv/boot.h" +#include "hw/boards.h" #include "elf.h" +#if defined(TARGET_RISCV32 ) +# define KERNEL_BOOT_ADDRESS 0x80400000 +#else +# define KERNEL_BOOT_ADDRESS 0x80200000 +#endif + +target_ulong riscv_load_firmware (const char *firmware_filename, +hwaddr firmware_load_addr) +{ +uint64_t firmware_entry, firmware_start, firmware_end; + +if (load_elf (firmware_filename,NULL ,NULL ,NULL , &firmware_entry, + &firmware_start, &firmware_end,0 ,EM_RISCV ,1 ,0 ) >0 ) { +return firmware_entry; + } + +if (load_image_targphys_as (firmware_filename, firmware_load_addr, + ram_size,NULL ) >0 ) { +return firmware_load_addr; + } + +error_report ("could not load firmware '%s'" , firmware_filename); +exit (1 ); +} +target_ulong riscv_load_kernel (const char *kernel_filename) {uint64_t kernel_entry, kernel_high;
hw/riscv/sifive_u.c +4 -0
@@ -269,6 +269,10 @@ static void riscv_sifive_u_init(MachineState *machine)/* create device tree */ create_fdt (s, memmap, machine->ram_size, machine->kernel_cmdline); +if (machine->firmware) { +riscv_load_firmware (machine->firmware, memmap[SIFIVE_U_DRAM ].base); + } +if (machine->kernel_filename) {riscv_load_kernel (machine->kernel_filename); }
hw/riscv/virt.c +4 -0
@@ -398,6 +398,10 @@ static void riscv_virt_board_init(MachineState *machine)memory_region_add_subregion (system_memory, memmap[VIRT_MROM ].base, mask_rom); +if (machine->firmware) { +riscv_load_firmware (machine->firmware, memmap[VIRT_DRAM ].base); + } +if (machine->kernel_filename) {uint64_t kernel_entry =riscv_load_kernel (machine->kernel_filename);
include/hw/riscv/boot.h +2 -0
@@ -20,6 +20,8 @@#ifndef RISCV_BOOT_H #define RISCV_BOOT_H +target_ulong riscv_load_firmware (const char *firmware_filename, +hwaddr firmware_load_addr);target_ulong riscv_load_kernel (const char *kernel_filename);hwaddr riscv_load_initrd (const char *filename,uint64_t mem_size,uint64_t kernel_entry,hwaddr *start);
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 07/34] RISC-V: Check for the effective memory privilege mode during PMP checks
In reply to Palmer DabbeltFrom: Hesham Almatary <[email protected]>
The current PMP check function checks for env->priv which is not the effective memory privilege mode.
For example, mstatus.MPRV could be set while executing in M-Mode, and in that case the privilege mode for the PMP check should be S-Mode rather than M-Mode (in env->priv) if mstatus.MPP == PRV_S.
This patch passes the effective memory privilege mode to the PMP check. Functions that call the PMP check should pass the correct memory privilege mode after reading mstatus' MPRV/MPP or hstatus.SPRV (if Hypervisor mode exists).
--- target/riscv/cpu_helper.c | 10 +++++++++- target/riscv/pmp.c | 6 +++--- target/riscv/pmp.h | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-)
target/riscv/cpu_helper.c +9 -1
@@ -427,19 +427,27 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,int prot;bool pmp_violation = false;int ret =TRANSLATE_FAIL ; +int mode = mmu_idx;qemu_log_mask (CPU_LOG_MMU ,"%s ad %" VADDR_PRIx" rw %d mmu_idx %d\n" , __func__, address, access_type, mmu_idx); ret =get_physical_address (env, &pa, &prot, address, access_type, mmu_idx); +if (mode ==PRV_M && access_type !=MMU_INST_FETCH ) { +if (get_field (env->mstatus,MSTATUS_MPRV )) { + mode =get_field (env->mstatus,MSTATUS_MPP ); + } + } +qemu_log_mask (CPU_LOG_MMU ,"%s address=%" VADDR_PRIx" ret %d physical " TARGET_FMT_plx" prot %d\n" , __func__, address, ret, pa, prot);if (riscv_feature (env,RISCV_FEATURE_PMP ) && (ret ==TRANSLATE_SUCCESS ) && - !pmp_hart_has_privs (env, pa,TARGET_PAGE_SIZE ,1 << access_type)) { + !pmp_hart_has_privs (env, pa,TARGET_PAGE_SIZE ,1 << access_type, + mode)) { pmp_violation = true; ret =TRANSLATE_FAIL ; }
target/riscv/pmp.c +3 -3
@@ -228,7 +228,7 @@ static int pmp_is_in_range(CPURISCVState *env, int pmp_index, target_ulong addr)* Check if the address has required RWX privs to complete desired operation */ bool pmp_hart_has_privs (CPURISCVState *env,target_ulong addr, -target_ulong size,pmp_priv_t privs) +target_ulong size,pmp_priv_t privs,target_ulong mode) {int i =0 ;int ret =-1 ;
@@ -264,7 +264,7 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr, } allowed_privs =PMP_READ |PMP_WRITE |PMP_EXEC ; -if ((env->priv !=PRV_M ) ||pmp_is_locked (env, i)) { +if ((mode !=PRV_M ) ||pmp_is_locked (env, i)) { allowed_privs &= env->pmp_state.pmp[i].cfg_reg; }
@@ -280,7 +280,7 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,/* No rule matched */ if (ret ==-1 ) { -if (env->priv ==PRV_M ) { +if (mode ==PRV_M ) { ret =1 ;/* Privileged spec v1.10 states if no PMP entry matches an * M-Mode access, the access succeeds */ }else {
target/riscv/pmp.h +1 -1
@@ -59,6 +59,6 @@ void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index, target_ulong val);target_ulong pmpaddr_csr_read (CPURISCVState *env,uint32_t addr_index);bool pmp_hart_has_privs (CPURISCVState *env,target_ulong addr, -target_ulong size,pmp_priv_t priv); +target_ulong size,pmp_priv_t priv,target_ulong mode);#endif
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 20/34] target/riscv: Add support for disabling/enabling Counters
In reply to Palmer DabbeltFrom: Alistair Francis <[email protected]>
Add support for disabling/enabling the "Counters" extension.
--- target/riscv/cpu.c | 1 + target/riscv/cpu.h | 1 + target/riscv/csr.c | 17 ++++++++++++----- 3 files changed, 14 insertions(+), 5 deletions(-)
target/riscv/cpu.c +1 -0
@@ -440,6 +440,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("c" ,RISCVCPU , cfg.ext_c, true),DEFINE_PROP_BOOL ("s" ,RISCVCPU , cfg.ext_s, true),DEFINE_PROP_BOOL ("u" ,RISCVCPU , cfg.ext_u, true), +DEFINE_PROP_BOOL ("Counters" ,RISCVCPU , cfg.ext_counters, true),DEFINE_PROP_STRING ("priv_spec" ,RISCVCPU , cfg.priv_spec),DEFINE_PROP_BOOL ("mmu" ,RISCVCPU , cfg.mmu, true), DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true),
target/riscv/cpu.h +1 -0
@@ -222,6 +222,7 @@ typedef struct RISCVCPU {bool ext_c;bool ext_s;bool ext_u; +bool ext_counters;char *priv_spec;char *user_spec;
target/riscv/csr.c +12 -5
@@ -56,17 +56,24 @@ static int fs(CPURISCVState *env, int csrno)static int ctr (CPURISCVState *env,int csrno) {#if !defined(CONFIG_USER_ONLY ) +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); +uint32_t ctr_en = ~0u ; + +if (!cpu->cfg.ext_counters) { +/* The Counters extensions is not enabled */ +return -1 ; + } +/* -* The counters are always enabled on newer priv specs, as the CSR has -* changed from controlling that the counters can be read to controlling -* that the counters increment. +* The counters are always enabled at run time on newer priv specs, as the +* CSR has changed from controlling that the counters can be read to +* controlling that the counters increment. */ if (env->priv_ver >PRIV_VERSION_1_09_1 ) {return 0 ; } -uint32_t ctr_en = ~0u ; -if (env->priv <PRV_M ) { ctr_en &= env->mcounteren; }
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 22/34] RISC-V: Add support for the Zicsr extension
In reply to Palmer DabbeltThe various CSR instructions have been split out of the base ISA as part of the ratification process. This patch adds a Zicsr argument, which disables all the CSR instructions.
--- target/riscv/cpu.c | 1 + target/riscv/cpu.h | 1 + target/riscv/csr.c | 6 ++++++ 3 files changed, 8 insertions(+)
target/riscv/cpu.c +1 -0
@@ -442,6 +442,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("u" ,RISCVCPU , cfg.ext_u, true),DEFINE_PROP_BOOL ("Counters" ,RISCVCPU , cfg.ext_counters, true),DEFINE_PROP_BOOL ("Zifencei" ,RISCVCPU , cfg.ext_ifencei, true), +DEFINE_PROP_BOOL ("Zicsr" ,RISCVCPU , cfg.ext_icsr, true),DEFINE_PROP_STRING ("priv_spec" ,RISCVCPU , cfg.priv_spec),DEFINE_PROP_BOOL ("mmu" ,RISCVCPU , cfg.mmu, true), DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true),
target/riscv/cpu.h +1 -0
@@ -224,6 +224,7 @@ typedef struct RISCVCPU {bool ext_u;bool ext_counters;bool ext_ifencei; +bool ext_icsr;char *priv_spec;char *user_spec;
target/riscv/csr.c +6 -0
@@ -793,6 +793,7 @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, {int ret;target_ulong old_value; +RISCVCPU *cpu =env_archcpu (env);/* check privileges and return -1 if check fails */ #if !defined(CONFIG_USER_ONLY )
@@ -803,6 +804,11 @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, }#endif +/* ensure the CSR extension is enabled. */ +if (!cpu->cfg.ext_icsr) { +return -1 ; + } +/* check predicate */ if (!csr_ops[csrno].predicate || csr_ops[csrno].predicate (env, csrno) <0 ) {return -1 ;
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 15/34] target/riscv: Add the mcountinhibit CSR
In reply to Palmer DabbeltFrom: Alistair Francis <[email protected]>
1.11 defines mcountinhibit, which has the same numeric CSR value as mucounteren from 1.09.1 but has different semantics. This patch enables the CSR for 1.11-based targets, which is trivial to implement because the counters in QEMU never tick (legal according to the spec).
[Palmer: Fix counter access semantics, change commit message to indicate the behavior is fully emulated.]
--- target/riscv/cpu_bits.h | 1 + target/riscv/csr.c | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-)
target/riscv/cpu_bits.h +1 -0
@@ -136,6 +136,7 @@#define CSR_MCOUNTEREN 0x306/* Legacy Counter Setup (priv v1.9.1) */ +/* Update to #define CSR_MCOUNTINHIBIT 0x320 for 1.11.0 */ #define CSR_MUCOUNTEREN 0x320#define CSR_MSCOUNTEREN 0x321#define CSR_MHCOUNTEREN 0x322
target/riscv/csr.c +15 -2
@@ -56,6 +56,15 @@ static int fs(CPURISCVState *env, int csrno)static int ctr (CPURISCVState *env,int csrno) {#if !defined(CONFIG_USER_ONLY ) +/* +* The counters are always enabled on newer priv specs, as the CSR has +* changed from controlling that the counters can be read to controlling +* that the counters increment. +*/ +if (env->priv_ver >PRIV_VERSION_1_09_1 ) { +return 0 ; + } +uint32_t ctr_en = ~0u ;if (env->priv <PRV_M ) {
@@ -461,18 +470,22 @@ static int write_mcounteren(CPURISCVState *env, int csrno, target_ulong val)return 0 ; } +/* This regiser is replaced with CSR_MCOUNTINHIBIT in 1.11.0 */ static int read_mscounteren (CPURISCVState *env,int csrno,target_ulong *val) { -if (env->priv_ver >PRIV_VERSION_1_09_1 ) { +if (env->priv_ver >PRIV_VERSION_1_09_1 + && env->priv_ver <PRIV_VERSION_1_11_0 ) {return -1 ; } *val = env->mcounteren;return 0 ; } +/* This regiser is replaced with CSR_MCOUNTINHIBIT in 1.11.0 */ static int write_mscounteren (CPURISCVState *env,int csrno,target_ulong val) { -if (env->priv_ver >PRIV_VERSION_1_09_1 ) { +if (env->priv_ver >PRIV_VERSION_1_09_1 + && env->priv_ver <PRIV_VERSION_1_11_0 ) {return -1 ; } env->mcounteren = val;
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 12/34] RISC-V: Fix a memory leak when realizing a sifive_e
In reply to Palmer DabbeltCoverity pointed out a memory leak in riscv_sifive_e_soc_realize(), where a pair of recently added MemoryRegion instances would not be freed if there were errors elsewhere in the function. The fix here is to simply not use dynamic allocation for these instances: there's always one of each in SiFiveESoCState, so instead we just include them within the struct.
--- hw/riscv/sifive_e.c | 13 ++++++------- include/hw/riscv/sifive_e.h | 2 ++ 2 files changed, 8 insertions(+), 7 deletions(-)
hw/riscv/sifive_e.c +6 -7
@@ -158,17 +158,15 @@ static void riscv_sifive_e_soc_realize(DeviceState *dev, Error **errp)SiFiveESoCState *s =RISCV_E_SOC (dev);MemoryRegion *sys_mem =get_system_memory (); -MemoryRegion *xip_mem =g_new (MemoryRegion,1 ); -MemoryRegion *mask_rom =g_new (MemoryRegion,1 );object_property_set_bool (OBJECT (&s->cpus), true,"realized" , &error_abort);/* Mask ROM */ -memory_region_init_rom (mask_rom,NULL ,"riscv.sifive.e.mrom" , +memory_region_init_rom (&s->mask_rom,NULL ,"riscv.sifive.e.mrom" , memmap[SIFIVE_E_MROM ].size, &error_fatal);memory_region_add_subregion (sys_mem, - memmap[SIFIVE_E_MROM ].base, mask_rom); + memmap[SIFIVE_E_MROM ].base, &s->mask_rom);/* MMIO */ s->plic = sifive_plic_create(memmap[SIFIVE_E_PLIC].base,
@@ -228,10 +226,11 @@ static void riscv_sifive_e_soc_realize(DeviceState *dev, Error **errp) memmap[SIFIVE_E_PWM2].base, memmap[SIFIVE_E_PWM2].size);/* Flash memory */ -memory_region_init_ram (xip_mem,NULL ,"riscv.sifive.e.xip" , +memory_region_init_ram (&s->xip_mem,NULL ,"riscv.sifive.e.xip" , memmap[SIFIVE_E_XIP ].size, &error_fatal); -memory_region_set_readonly (xip_mem, true); -memory_region_add_subregion (sys_mem, memmap[SIFIVE_E_XIP ].base, xip_mem); +memory_region_set_readonly (&s->xip_mem, true); +memory_region_add_subregion (sys_mem, memmap[SIFIVE_E_XIP ].base, + &s->xip_mem); }static void riscv_sifive_e_machine_init (MachineClass *mc)
include/hw/riscv/sifive_e.h +2 -0
@@ -33,6 +33,8 @@ typedef struct SiFiveESoCState {RISCVHartArrayState cpus;DeviceState *plic;SIFIVEGPIOState gpio; +MemoryRegion xip_mem; +MemoryRegion mask_rom; } SiFiveESoCState; typedef struct SiFiveEState {
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 29/34] riscv: sifive_u: Update the plic hart config to support multicore
In reply to Palmer DabbeltFrom: Bin Meng <[email protected]>
At present the PLIC is instantiated to support only one hart, while the machine allows at most 4 harts to be created. When more than 1 hart is configured, PLIC needs to instantiated to support multicore, otherwise an SMP OS does not work.
--- hw/riscv/sifive_u.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
hw/riscv/sifive_u.c +15 -1
@@ -344,6 +344,8 @@ static void riscv_sifive_u_soc_realize(DeviceState *dev, Error **errp)MemoryRegion *system_memory =get_system_memory ();MemoryRegion *mask_rom =g_new (MemoryRegion,1 );qemu_irq plic_gpios[SIFIVE_U_PLIC_NUM_SOURCES ]; +char *plic_hart_config; +size_t plic_hart_config_len;int i;Error *err =NULL ;NICInfo *nd = &nd_table[0 ];
@@ -357,9 +359,21 @@ static void riscv_sifive_u_soc_realize(DeviceState *dev, Error **errp)memory_region_add_subregion (system_memory, memmap[SIFIVE_U_MROM ].base, mask_rom); +/* create PLIC hart topology configuration string */ + plic_hart_config_len = (strlen (SIFIVE_U_PLIC_HART_CONFIG ) +1 ) * smp_cpus; + plic_hart_config =g_malloc0 (plic_hart_config_len); +for (i =0 ; i < smp_cpus; i++) { +if (i !=0 ) { +strncat (plic_hart_config,"," , plic_hart_config_len); + } +strncat (plic_hart_config,SIFIVE_U_PLIC_HART_CONFIG , + plic_hart_config_len); + plic_hart_config_len -= (strlen (SIFIVE_U_PLIC_HART_CONFIG ) +1 ); + } +/* MMIO */ s->plic = sifive_plic_create(memmap[SIFIVE_U_PLIC].base, - (char *)SIFIVE_U_PLIC_HART_CONFIG, + plic_hart_config, SIFIVE_U_PLIC_NUM_SOURCES, SIFIVE_U_PLIC_NUM_PRIORITIES, SIFIVE_U_PLIC_PRIORITY_BASE,
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 18/34] target/riscv: Require either I or E base extension
In reply to Palmer DabbeltFrom: Alistair Francis <[email protected]>
--- target/riscv/cpu.c | 6 ++++++ 1 file changed, 6 insertions(+)
target/riscv/cpu.c +6 -0
@@ -373,6 +373,12 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)return ; } +if (!cpu->cfg.ext_i && !cpu->cfg.ext_e) { +error_setg (errp, +"Either I or E extension must be set" ); +return ; + } +if (cpu->cfg.ext_g && !(cpu->cfg.ext_i & cpu->cfg.ext_m & cpu->cfg.ext_a & cpu->cfg.ext_f & cpu->cfg.ext_d)) {
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 06/34] RISC-V: Raise access fault exceptions on PMP violations
In reply to Palmer DabbeltFrom: Hesham Almatary <[email protected]>
Section 3.6 in RISC-V v1.10 privilege specification states that PMP violations report "access exceptions." The current PMP implementation has
a bug which wrongly reports "page exceptions" on PMP violations.
This patch fixes this bug by reporting the correct PMP access exceptions trap values.
--- target/riscv/cpu_helper.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
target/riscv/cpu_helper.c +6 -3
@@ -337,12 +337,13 @@ restart: }static void raise_mmu_exception (CPURISCVState *env,target_ulong address, -MMUAccessType access_type) +MMUAccessType access_type,bool pmp_violation) {CPUState *cs =env_cpu (env);int page_fault_exceptions = (env->priv_ver >=PRIV_VERSION_1_10_0 ) && -get_field (env->satp,SATP_MODE ) !=VM_1_10_MBARE ; +get_field (env->satp,SATP_MODE ) !=VM_1_10_MBARE && + !pmp_violation;switch (access_type) {case MMU_INST_FETCH : cs->exception_index = page_fault_exceptions ?
@@ -424,6 +425,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,CPURISCVState *env = &cpu->env;hwaddr pa =0 ;int prot; +bool pmp_violation = false;int ret =TRANSLATE_FAIL ; qemu_log_mask(CPU_LOG_MMU, "%s ad %" VADDR_PRIx " rw %d mmu_idx %d\n",
@@ -438,6 +440,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,if (riscv_feature (env,RISCV_FEATURE_PMP ) && (ret ==TRANSLATE_SUCCESS ) && !pmp_hart_has_privs (env, pa,TARGET_PAGE_SIZE ,1 << access_type)) { + pmp_violation = true; ret =TRANSLATE_FAIL ; }if (ret ==TRANSLATE_SUCCESS ) {
@@ -447,7 +450,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, } else if (probe) {return false; }else { -raise_mmu_exception (env, address, access_type); +raise_mmu_exception (env, address, access_type, pmp_violation);riscv_raise_exception (env, cs->exception_index, retaddr); }#else
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 14/34] target/riscv: Add the privledge spec version 1.11.0
In reply to Palmer DabbeltFrom: Alistair Francis <[email protected]>
Add support for the ratified RISC-V privledge spec.
--- target/riscv/cpu.h | 1 + target/riscv/insn_trans/trans_privileged.inc.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
target/riscv/cpu.h +1 -0
@@ -81,6 +81,7 @@ enum {#define USER_VERSION_2_02_0 0x00020200#define PRIV_VERSION_1_09_1 0x00010901#define PRIV_VERSION_1_10_0 0x00011000 +#define PRIV_VERSION_1_11_0 0x00011100#define TRANSLATE_PMP_FAIL 2#define TRANSLATE_FAIL 1
target/riscv/insn_trans/trans_privileged.inc.c +1 -1
@@ -90,7 +90,7 @@ static bool trans_wfi(DisasContext *ctx, arg_wfi *a)static bool trans_sfence_vma (DisasContext *ctx,arg_sfence_vma *a) {#ifndef CONFIG_USER_ONLY -if (ctx->priv_ver ==PRIV_VERSION_1_10_0 ) { +if (ctx->priv_ver >=PRIV_VERSION_1_10_0 ) {gen_helper_tlb_flush (cpu_env);return true; }
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 17/34] qemu-deprecated.texi: Deprecate the RISC-V privledge spec 1.09.1
In reply to Palmer DabbeltFrom: Alistair Francis <[email protected]>
Deprecate the RISC-V privledge spec version 1.09.1 in favour of the new 1.10.0 and the ratified 1.11.0.
--- qemu-deprecated.texi | 8 ++++++++ 1 file changed, 8 insertions(+)
qemu-deprecated.texi +8 -0
@@ -144,6 +144,14 @@ The ``acl_show'', ``acl_reset'', ``acl_policy'', ``acl_add'', and ``acl_remove'' commands are deprecated with no replacement. Authorization for VNC should be performed using the pluggable QAuthZ objects. +@section Guest Emulator ISAs + +@subsection RISC-V ISA privledge specification version 1.09.1 (since 4.1) + +The RISC-V ISA privledge specification version 1.09.1 has been deprecated. +QEMU supports both the newer version 1.10.0 and the ratified version 1.11.0, these +should be used instead of the 1.09.1 version. + @section System emulator CPUS @subsection RISC-V ISA CPUs (since 4.1)
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 34/34] hw/riscv: Load OpenSBI as the default firmware
In reply to Palmer DabbeltFrom: Alistair Francis <[email protected]>
If the user hasn't specified a firmware to load (with -bios) or specified no bios (with -bios none) then load OpenSBI by default. This allows users to boot a RISC-V kernel with just -kernel.
--- hw/riscv/boot.c | 49 +++++++++++++++++++++++++++++++++++++++++ hw/riscv/sifive_u.c | 7 +++--- hw/riscv/virt.c | 11 ++++++--- include/hw/riscv/boot.h | 3 +++ qemu-deprecated.texi | 20 +++++++++++++++++ 5 files changed, 84 insertions(+), 6 deletions(-)
hw/riscv/boot.c +49 -0
@@ -18,6 +18,7 @@*/ #include "qemu/osdep.h" +#include "qemu-common.h" #include "qemu/units.h" #include "qemu/error-report.h" #include "exec/cpu-defs.h"
@@ -32,6 +33,54 @@# define KERNEL_BOOT_ADDRESS 0x80200000#endif +void riscv_find_and_load_firmware (MachineState *machine, +const char *default_machine_firmware, +hwaddr firmware_load_addr) +{ +char *firmware_filename; + +if (!machine->firmware) { +/* +* The user didn't specify -bios. +* At the moment we default to loading nothing when this hapens. +* In the future this defaul will change to loading the prebuilt +* OpenSBI firmware. Let's warn the user and then continue. +*/ +warn_report ("No -bios option specified. Not loading a firmware." ); +warn_report ("This default will change in QEMU 4.3. Please use the " \ +"-bios option to aviod breakages when this happens." ); +warn_report ("See QEMU's deprecation documentation for details" ); +return ; + } + +if (!strcmp (machine->firmware,"default" )) { +/* +* The user has specified "-bios default". That means we are going to +* load the OpenSBI binary included in the QEMU source. +* +* We can't load the binary by default as it will break existing users +* as users are already loading their own firmware. +* +* Let's try to get everyone to specify the -bios option at all times, +* so then in the future we can make "-bios default" the default option +* if no -bios option is set without breaking anything. +*/ + firmware_filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , + default_machine_firmware); + }else { + firmware_filename = machine->firmware; + } + +if (strcmp (firmware_filename,"none" )) { +/* If not "none" load the firmware */ +riscv_load_firmware (firmware_filename, firmware_load_addr); + } + +if (!strcmp (machine->firmware,"default" )) { +g_free (firmware_filename); + } +} +target_ulong riscv_load_firmware (const char *firmware_filename,hwaddr firmware_load_addr) {
hw/riscv/sifive_u.c +4 -3
@@ -49,6 +49,8 @@#include <libfdt.h> +#define BIOS_FILENAME "opensbi-riscv64-sifive_u-fw_jump.bin" + static const struct MemmapEntry { hwaddr base; hwaddr size;
@@ -269,9 +271,8 @@ static void riscv_sifive_u_init(MachineState *machine)/* create device tree */ create_fdt (s, memmap, machine->ram_size, machine->kernel_cmdline); -if (machine->firmware) { -riscv_load_firmware (machine->firmware, memmap[SIFIVE_U_DRAM ].base); - } +riscv_find_and_load_firmware (machine,BIOS_FILENAME , + memmap[SIFIVE_U_DRAM ].base);if (machine->kernel_filename) {riscv_load_kernel (machine->kernel_filename);
hw/riscv/virt.c +8 -3
@@ -44,6 +44,12 @@#include <libfdt.h> +#if defined(TARGET_RISCV32 ) +# define BIOS_FILENAME "opensbi-riscv32-virt-fw_jump.bin" +#else +# define BIOS_FILENAME "opensbi-riscv64-virt-fw_jump.bin" +#endif + static const struct MemmapEntry { hwaddr base; hwaddr size;
@@ -398,9 +404,8 @@ static void riscv_virt_board_init(MachineState *machine)memory_region_add_subregion (system_memory, memmap[VIRT_MROM ].base, mask_rom); -if (machine->firmware) { -riscv_load_firmware (machine->firmware, memmap[VIRT_DRAM ].base); - } +riscv_find_and_load_firmware (machine,BIOS_FILENAME , + memmap[VIRT_DRAM ].base);if (machine->kernel_filename) {uint64_t kernel_entry =riscv_load_kernel (machine->kernel_filename);
include/hw/riscv/boot.h +3 -0
@@ -20,6 +20,9 @@#ifndef RISCV_BOOT_H #define RISCV_BOOT_H +void riscv_find_and_load_firmware (MachineState *machine, +const char *default_machine_firmware, +hwaddr firmware_load_addr);target_ulong riscv_load_firmware (const char *firmware_filename,hwaddr firmware_load_addr);target_ulong riscv_load_kernel (const char *kernel_filename);
qemu-deprecated.texi +20 -0
@@ -88,6 +88,26 @@ The @code{-realtime mlock=on|off} argument has been replaced by the The ``-virtfs_synth'' argument is now deprecated. Please use ``-fsdev synth'' and ``-device virtio-9p-...'' instead. +@subsection RISC-V -bios (since 4.1) + +QEMU 4.1 introduced support for the -bios option in QEMU for RISC-V for the +RISC-V virt machine and sifive_u machine. + +QEMU 4.1 has no changes to the default behaviour to avoid breakages. This +default will change in a future QEMU release, so please prepare now. All users +of the virt or sifive_u machine must change their command line usage. + +QEMU 4.1 has three options, please migrate to one of these three: + 1. ``-bios none`` - This is the current default behavior if no -bios option + is included. QEMU will not automatically load any firmware. It is up + to the user to load all the images they need. + 2. ``-bios default`` - In a future QEMU release this will become the default + behaviour if no -bios option is specified. This option will load the + default OpenSBI firmware automatically. The firmware is included with + the QEMU release and no user interaction is required. All a user needs + to do is specify the kernel they want to boot with the -kernel option + 3. ``-bios <file>`` - Tells QEMU to load the specified file as the firmwrae. + @section QEMU Machine Protocol (QMP) commands @subsection block-dirty-bitmap-add "autoload" parameter (since 2.12.0)
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 11/34] riscv: virt: Correct pci "bus-range" encoding
In reply to Palmer DabbeltFrom: Bin Meng <[email protected]>
The largest pci bus number should be calculated from ECAM size, instead of its base address.
--- hw/riscv/virt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/riscv/virt.c +1 -1
@@ -298,7 +298,7 @@ static void *create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,qemu_fdt_setprop_string (fdt, nodename,"device_type" ,"pci" );qemu_fdt_setprop_cell (fdt, nodename,"linux,pci-domain" ,0 );qemu_fdt_setprop_cells (fdt, nodename,"bus-range" ,0 , - memmap[VIRT_PCIE_ECAM ].base / + memmap[VIRT_PCIE_ECAM ].size /PCIE_MMCFG_SIZE_MIN -1 );qemu_fdt_setprop (fdt, nodename,"dma-coherent" ,NULL ,0 ); qemu_fdt_setprop_cells(fdt, nodename, "reg", 0, memmap[VIRT_PCIE_ECAM].base,
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 23/34] RISC-V: Clear load reservations on context switch and SC
In reply to Palmer DabbeltFrom: Joel Sing <[email protected]>
This prevents a load reservation from being placed in one context/process, then being used in another, resulting in an SC succeeding incorrectly and breaking atomics.
--- target/riscv/cpu.c | 1 + target/riscv/cpu_helper.c | 10 ++++++++++ target/riscv/insn_trans/trans_rva.inc.c | 8 +++++++- 3 files changed, 18 insertions(+), 1 deletion(-)
target/riscv/cpu.c +1 -0
@@ -297,6 +297,7 @@ static void riscv_cpu_reset(CPUState *cs) env->pc = env->resetvec;#endif cs->exception_index =EXCP_NONE ; + env->load_res =-1 ;set_default_nan_mode (1 , &env->fp_status); }
target/riscv/cpu_helper.c +10 -0
@@ -132,6 +132,16 @@ void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv) }/* tlb_flush is unnecessary as mode is contained in mmu_idx */ env->priv = newpriv; + +/* +* Clear the load reservation - otherwise a reservation placed in one +* context/process can be used by another, resulting in an SC succeeding +* incorrectly. Version 2.2 of the ISA specification explicitly requires +* this behaviour, while later revisions say that the kernel "should" use +* an SC instruction to force the yielding of a load reservation on a +* preemptive context switch. As a result, do both. +*/ + env->load_res =-1 ; }/* get_physical_address - get the physical address for this virtual address
target/riscv/insn_trans/trans_rva.inc.c +7 -1
@@ -61,7 +61,7 @@ static inline bool gen_sc(DisasContext *ctx, arg_atomic *a, TCGMemOp mop)gen_set_label (l1);/* -* Address comparion failure. However, we still need to +* Address comparison failure. However, we still need to * provide the memory barrier implied by AQ/RL. */ tcg_gen_mb (TCG_MO_ALL + a->aq *TCG_BAR_LDAQ + a->rl *TCG_BAR_STRL );
@@ -69,6 +69,12 @@ static inline bool gen_sc(DisasContext *ctx, arg_atomic *a, TCGMemOp mop)gen_set_gpr (a->rd, dat);gen_set_label (l2); +/* +* Clear the load reservation, since an SC must fail if there is +* an SC to any address, in between an LR and SC pair. +*/ +tcg_gen_movi_tl (load_res,-1 ); +tcg_temp_free (dat);tcg_temp_free (src1);tcg_temp_free (src2);
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 26/34] disas/riscv: Disassemble reserved compressed encodings as illegal
In reply to Palmer DabbeltFrom: Michael Clark <[email protected]>
Due to the design of the disassembler, the immediate is not known during decoding of the opcode; so to handle compressed encodings with reserved immediate values (non-zero), we need to add an additional check during decompression to match reserved encodings with zero immediates and translate them into the illegal instruction.
The following compressed opcodes have reserved encodings with zero immediates: c.addi4spn, c.addi, c.lui, c.addi16sp, c.srli, c.srai, c.andi and c.slli
--- disas/riscv.c | 62 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 17 deletions(-)
disas/riscv.c +45 -17
@@ -504,14 +504,19 @@ typedef struct {const rvc_constraint *constraints; } rv_comp_data; +enum { + rvcd_imm_nz =0x1 +}; +typedef struct {const char *const name;const rv_codec codec;const char *const format;const rv_comp_data *pseudo; -const int decomp_rv32; -const int decomp_rv64; -const int decomp_rv128; +const short decomp_rv32; +const short decomp_rv64; +const short decomp_rv128; +const short decomp_data; }rv_opcode_data ;/* register names */
@@ -1011,7 +1016,8 @@ const rv_opcode_data opcode_data[] = { { "fcvt.q.lu", rv_codec_r_m, rv_fmt_rm_frd_rs1, NULL, 0, 0, 0 }, { "fmv.x.q", rv_codec_r, rv_fmt_rd_frs1, NULL, 0, 0, 0 }, { "fmv.q.x", rv_codec_r, rv_fmt_frd_rs1, NULL, 0, 0, 0 }, - { "c.addi4spn", rv_codec_ciw_4spn, rv_fmt_rd_rs1_imm, NULL, rv_op_addi, rv_op_addi, rv_op_addi }, + { "c.addi4spn", rv_codec_ciw_4spn, rv_fmt_rd_rs1_imm, NULL, rv_op_addi, + rv_op_addi, rv_op_addi, rvcd_imm_nz }, { "c.fld", rv_codec_cl_ld, rv_fmt_frd_offset_rs1, NULL, rv_op_fld, rv_op_fld, 0 }, { "c.lw", rv_codec_cl_lw, rv_fmt_rd_offset_rs1, NULL, rv_op_lw, rv_op_lw, rv_op_lw }, { "c.flw", rv_codec_cl_lw, rv_fmt_frd_offset_rs1, NULL, rv_op_flw, 0, 0 },
@@ -1019,14 +1025,20 @@ const rv_opcode_data opcode_data[] = { { "c.sw", rv_codec_cs_sw, rv_fmt_rs2_offset_rs1, NULL, rv_op_sw, rv_op_sw, rv_op_sw }, { "c.fsw", rv_codec_cs_sw, rv_fmt_frs2_offset_rs1, NULL, rv_op_fsw, 0, 0 }, { "c.nop", rv_codec_ci_none, rv_fmt_none, NULL, rv_op_addi, rv_op_addi, rv_op_addi }, - { "c.addi", rv_codec_ci, rv_fmt_rd_rs1_imm, NULL, rv_op_addi, rv_op_addi, rv_op_addi }, + { "c.addi", rv_codec_ci, rv_fmt_rd_rs1_imm, NULL, rv_op_addi, rv_op_addi, + rv_op_addi, rvcd_imm_nz }, { "c.jal", rv_codec_cj_jal, rv_fmt_rd_offset, NULL, rv_op_jal, 0, 0 }, { "c.li", rv_codec_ci_li, rv_fmt_rd_rs1_imm, NULL, rv_op_addi, rv_op_addi, rv_op_addi }, - { "c.addi16sp", rv_codec_ci_16sp, rv_fmt_rd_rs1_imm, NULL, rv_op_addi, rv_op_addi, rv_op_addi }, - { "c.lui", rv_codec_ci_lui, rv_fmt_rd_imm, NULL, rv_op_lui, rv_op_lui, rv_op_lui }, - { "c.srli", rv_codec_cb_sh6, rv_fmt_rd_rs1_imm, NULL, rv_op_srli, rv_op_srli, rv_op_srli }, - { "c.srai", rv_codec_cb_sh6, rv_fmt_rd_rs1_imm, NULL, rv_op_srai, rv_op_srai, rv_op_srai }, - { "c.andi", rv_codec_cb_imm, rv_fmt_rd_rs1_imm, NULL, rv_op_andi, rv_op_andi, rv_op_andi }, + { "c.addi16sp", rv_codec_ci_16sp, rv_fmt_rd_rs1_imm, NULL, rv_op_addi, + rv_op_addi, rv_op_addi, rvcd_imm_nz }, + { "c.lui", rv_codec_ci_lui, rv_fmt_rd_imm, NULL, rv_op_lui, rv_op_lui, + rv_op_lui, rvcd_imm_nz }, + { "c.srli", rv_codec_cb_sh6, rv_fmt_rd_rs1_imm, NULL, rv_op_srli, + rv_op_srli, rv_op_srli, rvcd_imm_nz }, + { "c.srai", rv_codec_cb_sh6, rv_fmt_rd_rs1_imm, NULL, rv_op_srai, + rv_op_srai, rv_op_srai, rvcd_imm_nz }, + { "c.andi", rv_codec_cb_imm, rv_fmt_rd_rs1_imm, NULL, rv_op_andi, + rv_op_andi, rv_op_andi, rvcd_imm_nz }, { "c.sub", rv_codec_cs, rv_fmt_rd_rs1_rs2, NULL, rv_op_sub, rv_op_sub, rv_op_sub }, { "c.xor", rv_codec_cs, rv_fmt_rd_rs1_rs2, NULL, rv_op_xor, rv_op_xor, rv_op_xor }, { "c.or", rv_codec_cs, rv_fmt_rd_rs1_rs2, NULL, rv_op_or, rv_op_or, rv_op_or },
@@ -1036,7 +1048,8 @@ const rv_opcode_data opcode_data[] = { { "c.j", rv_codec_cj, rv_fmt_rd_offset, NULL, rv_op_jal, rv_op_jal, rv_op_jal }, { "c.beqz", rv_codec_cb, rv_fmt_rs1_rs2_offset, NULL, rv_op_beq, rv_op_beq, rv_op_beq }, { "c.bnez", rv_codec_cb, rv_fmt_rs1_rs2_offset, NULL, rv_op_bne, rv_op_bne, rv_op_bne }, - { "c.slli", rv_codec_ci_sh6, rv_fmt_rd_rs1_imm, NULL, rv_op_slli, rv_op_slli, rv_op_slli }, + { "c.slli", rv_codec_ci_sh6, rv_fmt_rd_rs1_imm, NULL, rv_op_slli, + rv_op_slli, rv_op_slli, rvcd_imm_nz }, { "c.fldsp", rv_codec_ci_ldsp, rv_fmt_frd_offset_rs1, NULL, rv_op_fld, rv_op_fld, rv_op_fld }, { "c.lwsp", rv_codec_ci_lwsp, rv_fmt_rd_offset_rs1, NULL, rv_op_lw, rv_op_lw, rv_op_lw }, { "c.flwsp", rv_codec_ci_lwsp, rv_fmt_frd_offset_rs1, NULL, rv_op_flw, 0, 0 },
@@ -2795,8 +2808,13 @@ static void decode_inst_decompress_rv32(rv_decode *dec) {int decomp_op = opcode_data[dec->op].decomp_rv32;if (decomp_op != rv_op_illegal) { - dec->op = decomp_op; - dec->codec = opcode_data[decomp_op].codec; +if ((opcode_data[dec->op].decomp_data & rvcd_imm_nz) + && dec->imm ==0 ) { + dec->op = rv_op_illegal; + }else { + dec->op = decomp_op; + dec->codec = opcode_data[decomp_op].codec; + } } }
@@ -2804,8 +2822,13 @@ static void decode_inst_decompress_rv64(rv_decode *dec) {int decomp_op = opcode_data[dec->op].decomp_rv64;if (decomp_op != rv_op_illegal) { - dec->op = decomp_op; - dec->codec = opcode_data[decomp_op].codec; +if ((opcode_data[dec->op].decomp_data & rvcd_imm_nz) + && dec->imm ==0 ) { + dec->op = rv_op_illegal; + }else { + dec->op = decomp_op; + dec->codec = opcode_data[decomp_op].codec; + } } }
@@ -2813,8 +2836,13 @@ static void decode_inst_decompress_rv128(rv_decode *dec) {int decomp_op = opcode_data[dec->op].decomp_rv128;if (decomp_op != rv_op_illegal) { - dec->op = decomp_op; - dec->codec = opcode_data[decomp_op].codec; +if ((opcode_data[dec->op].decomp_data & rvcd_imm_nz) + && dec->imm ==0 ) { + dec->op = rv_op_illegal; + }else { + dec->op = decomp_op; + dec->codec = opcode_data[decomp_op].codec; + } } }
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 09/34] RISC-V: Fix a PMP bug where it succeeds even if PMP entry is off
In reply to Palmer DabbeltFrom: Hesham Almatary <[email protected]>
The current implementation returns 1 (PMP check success) if the address is in range even if the PMP entry is off. This is a bug.
For example, if there is a PMP check in S-Mode which is in range, but its PMP entry is off, this will succeed, which it should not.
The patch fixes this bug by only checking the PMP permissions if the address is in range and its corresponding PMP entry it not off. Otherwise, it will keep the ret = -1 which will be checked and handled correctly at the end of the function.
--- target/riscv/pmp.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
target/riscv/pmp.c +5 -4
@@ -258,11 +258,12 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,/* fully inside */ const uint8_t a_field =pmp_get_a_field (env->pmp_state.pmp[i].cfg_reg); -if ((s + e) ==2 ) { -if (PMP_AMATCH_OFF == a_field) { -return 1 ; - } +/* +* If the PMP entry is not off and the address is in range, do the priv +* check +*/ +if (((s + e) ==2 ) && (PMP_AMATCH_OFF != a_field)) { allowed_privs =PMP_READ |PMP_WRITE |PMP_EXEC ;if ((mode !=PRV_M ) ||pmp_is_locked (env, i)) { allowed_privs &= env->pmp_state.pmp[i].cfg_reg;
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 28/34] riscv: sifive_u: Do not create hard-coded phandles in DT
In reply to Palmer DabbeltFrom: Bin Meng <[email protected]>
At present the cpu, plic and ethclk nodes' phandles are hard-coded to 1/2/3 in DT. If we configure more than 1 cpu for the machine, all cpu nodes' phandles conflict with each other as they are all 1. Fix it by removing the hardcode.
--- hw/riscv/sifive_u.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
hw/riscv/sifive_u.c +10 -7
@@ -86,7 +86,7 @@ static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap,uint32_t *cells;char *nodename;char ethclk_names[] ="pclk\0hclk\0tx_clk" ; -uint32_t plic_phandle, ethclk_phandle; +uint32_t plic_phandle, ethclk_phandle, phandle =1 ; fdt = s->fdt =create_device_tree (&s->fdt_size);if (!fdt) {
@@ -121,6 +121,7 @@ static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap,qemu_fdt_setprop_cell (fdt,"/cpus" ,"#address-cells" ,0x1 );for (cpu = s->soc.cpus.num_harts -1 ; cpu >=0 ; cpu--) { +int cpu_phandle = phandle++; nodename =g_strdup_printf ("/cpus/cpu@%d" , cpu);char *intc =g_strdup_printf ("/cpus/cpu@%d/interrupt-controller" , cpu);char *isa =riscv_isa_string (&s->soc.cpus.harts[cpu]);
@@ -134,8 +135,8 @@ static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap,qemu_fdt_setprop_cell (fdt, nodename,"reg" , cpu);qemu_fdt_setprop_string (fdt, nodename,"device_type" ,"cpu" );qemu_fdt_add_subnode (fdt, intc); -qemu_fdt_setprop_cell (fdt, intc,"phandle" ,1 ); -qemu_fdt_setprop_cell (fdt, intc,"linux,phandle" ,1 ); +qemu_fdt_setprop_cell (fdt, intc,"phandle" , cpu_phandle); +qemu_fdt_setprop_cell (fdt, intc,"linux,phandle" , cpu_phandle);qemu_fdt_setprop_string (fdt, intc,"compatible" ,"riscv,cpu-intc" );qemu_fdt_setprop (fdt, intc,"interrupt-controller" ,NULL ,0 );qemu_fdt_setprop_cell (fdt, intc,"#interrupt-cells" ,1 );
@@ -167,6 +168,7 @@ static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap,g_free (cells);g_free (nodename); + plic_phandle = phandle++; cells =g_new0 (uint32_t, s->soc.cpus.num_harts *4 );for (cpu =0 ; cpu < s->soc.cpus.num_harts; cpu++) { nodename =
@@ -192,20 +194,21 @@ static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap,qemu_fdt_setprop_string (fdt, nodename,"reg-names" ,"control" );qemu_fdt_setprop_cell (fdt, nodename,"riscv,max-priority" ,7 );qemu_fdt_setprop_cell (fdt, nodename,"riscv,ndev" ,0x35 ); -qemu_fdt_setprop_cells (fdt, nodename,"phandle" ,2 ); -qemu_fdt_setprop_cells (fdt, nodename,"linux,phandle" ,2 ); +qemu_fdt_setprop_cells (fdt, nodename,"phandle" , plic_phandle); +qemu_fdt_setprop_cells (fdt, nodename,"linux,phandle" , plic_phandle); plic_phandle =qemu_fdt_get_phandle (fdt, nodename);g_free (cells);g_free (nodename); + ethclk_phandle = phandle++; nodename =g_strdup_printf ("/soc/ethclk" );qemu_fdt_add_subnode (fdt, nodename);qemu_fdt_setprop_string (fdt, nodename,"compatible" ,"fixed-clock" );qemu_fdt_setprop_cell (fdt, nodename,"#clock-cells" ,0x0 );qemu_fdt_setprop_cell (fdt, nodename,"clock-frequency" ,SIFIVE_U_GEM_CLOCK_FREQ ); -qemu_fdt_setprop_cell (fdt, nodename,"phandle" ,3 ); -qemu_fdt_setprop_cell (fdt, nodename,"linux,phandle" ,3 ); +qemu_fdt_setprop_cell (fdt, nodename,"phandle" , ethclk_phandle); +qemu_fdt_setprop_cell (fdt, nodename,"linux,phandle" , ethclk_phandle); ethclk_phandle =qemu_fdt_get_phandle (fdt, nodename);g_free (nodename);
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 32/34] hw/riscv: Extend the kernel loading support
In reply to Palmer DabbeltFrom: Alistair Francis <[email protected]>
Extend the RISC-V kernel loader to support Image and uImage files. A Linux kernel can now be booted with:
qemu-system-riscv64 -machine virt -bios fw_jump.bin -kernel Image
--- hw/riscv/boot.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
hw/riscv/boot.c +14 -4
@@ -56,12 +56,22 @@ target_ulong riscv_load_kernel(const char *kernel_filename)uint64_t kernel_entry, kernel_high;if (load_elf (kernel_filename,NULL ,NULL ,NULL , - &kernel_entry,NULL , &kernel_high,0 ,EM_RISCV ,1 ,0 ) <0 ) { -error_report ("could not load kernel '%s'" , kernel_filename); -exit (1 ); + &kernel_entry,NULL , &kernel_high,0 ,EM_RISCV ,1 ,0 ) >0 ) { +return kernel_entry; } -return kernel_entry; +if (load_uimage_as (kernel_filename, &kernel_entry,NULL ,NULL , +NULL ,NULL ,NULL ) >0 ) { +return kernel_entry; + } + +if (load_image_targphys_as (kernel_filename,KERNEL_BOOT_ADDRESS , + ram_size,NULL ) >0 ) { +return KERNEL_BOOT_ADDRESS ; + } + +error_report ("could not load kernel '%s'" , kernel_filename); +exit (1 ); } hwaddr riscv_load_initrd(const char *filename, uint64_t mem_size,
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 33/34] roms: Add OpenSBI version 0.3
In reply to Palmer DabbeltFrom: Alistair Francis <[email protected]>
Add OpenSBI version 0.3 as a git submodule and as a prebult binary.
--- .gitmodules | 3 ++ Makefile | 5 +- pc-bios/opensbi-riscv32-virt-fw_jump.bin | Bin 0 -> 28848 bytes pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin | Bin 0 -> 28904 bytes pc-bios/opensbi-riscv64-virt-fw_jump.bin | Bin 0 -> 28904 bytes roms/Makefile | 48 ++++++++++++++----- roms/opensbi | 1 + 7 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 pc-bios/opensbi-riscv32-virt-fw_jump.bin create mode 100644 pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin create mode 100644 pc-bios/opensbi-riscv64-virt-fw_jump.bin create mode 160000 roms/opensbi
.gitmodules +3 -0
@@ -55,3 +55,6 @@ [submodule "slirp"] path = slirp url = https://git.qemu.org/git/libslirp.git +[submodule "roms/opensbi"] + path = roms/opensbi + url = https://github.com/riscv/opensbi.git
Makefile +4 -1
@@ -761,7 +761,10 @@ palcode-clipper \ u-boot.e500 u-boot-sam460-20100605.bin \ qemu_vga.ndrv \ edk2-licenses.txt \ -hppa-firmware.img +hppa-firmware.img \ +opensbi-riscv32-virt-fw_jump.bin \ +opensbi-riscv64-sifive_u-fw_jump.bin opensbi-riscv64-virt-fw_jump.bin + DESCS=50-edk2-i386-secure.json 50-edk2-x86_64-secure.json \ 60-edk2-aarch64.json 60-edk2-arm.json 60-edk2-i386.json 60-edk2-x86_64.json
pc-bios/opensbi-riscv32-virt-fw_jump.bin new file binary +0 -0
pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin new file binary +0 -0
pc-bios/opensbi-riscv64-virt-fw_jump.bin new file binary +0 -0
roms/Makefile +36 -12
69 lines not on this page · raw message
roms/opensbi new file +1 -0
@@ -0,0 +1 @@ +Subproject commit ca20ac0cd4c099006d4eea4d9ac7bd7b58e2ae0f
Signature · 1 line
2.21.0
Re: [Qemu-devel] [PULL 33/34] roms: Add OpenSBI version 0.3
Quoted 8 lines · On Thu, 27 Jun 2019 08:20:10 -0700 Palmer Dabbelt <[email protected]> wrote:
From: Alistair Francis <[email protected]>
Add OpenSBI version 0.3 as a git submodule and as a prebult binary.
Signed-off-by Alistair Francis <[email protected]>Reviewed-by Bin Meng <[email protected]>Tested-by Bin Meng <[email protected]>Signed-off-by Palmer Dabbelt <[email protected]>
I sent a late bug report on this one.. Hence posting here as well to make sure it doesn't fall through the cracks!
Right now you can't actually build the opensbi64-virt firmware due to cut and paste error in the Makefile.
As a side note, I hit this because OpenSBI 0.3 is resulting in a login loop on a debian test image and the current upstream isn't. I haven't debugged yet, but someone else may hit that problem.
Thanks,
Jonathan
Quoted 54 lines
roms/Makefile +20
-12@@ -37,6 +37,8 @@ find-cross-prefix = $(subst gcc,,$(notdir $(call find-cross-gcc,$(1)))) powerpc64_cross_prefix := $(call find-cross-prefix,powerpc64) powerpc_cross_prefix := $(call find-cross-prefix,powerpc) x86_64_cross_prefix := $(call find-cross-prefix,x86_64) +riscv32_cross_prefix := $(call find-cross-prefix,riscv32) +riscv64_cross_prefix := $(call find-cross-prefix,riscv64) # tag our seabios builds SEABIOS_EXTRAVERSION="-prebuilt.qemu.org"@@ -52,18 +54,21 @@ EDK2_EFIROM = edk2/BaseTools/Source/C/bin/EfiRom default: @echo "nothing is build by default" @echo "available build targets:" - @echo " bios -- update bios.bin (seabios)" - @echo " vgabios -- update vgabios binaries (seabios)" - @echo " sgabios -- update sgabios binaries" - @echo " pxerom -- update nic roms (bios only)" - @echo " efirom -- update nic roms (bios+efi)" - @echo " slof -- update slof.bin" - @echo " skiboot -- update skiboot.lid" - @echo " u-boot.e500 -- update u-boot.e500" - @echo " u-boot.sam460 -- update u-boot.sam460" - @echo " efi -- update UEFI (edk2) platform firmware" - @echo " clean -- delete the files generated by the previous" \ - "build targets" + @echo " bios -- update bios.bin (seabios)" + @echo " vgabios -- update vgabios binaries (seabios)" + @echo " sgabios -- update sgabios binaries" + @echo " pxerom -- update nic roms (bios only)" + @echo " efirom -- update nic roms (bios+efi)" + @echo " slof -- update slof.bin" + @echo " skiboot -- update skiboot.lid" + @echo " u-boot.e500 -- update u-boot.e500" + @echo " u-boot.sam460 -- update u-boot.sam460" + @echo " efi -- update UEFI (edk2) platform firmware" + @echo " opensbi32-virt -- update OpenSBI for 32-bit virt machine" + @echo " opensbi64-virt -- update OpenSBI for 64-bit virt machine" + @echo " opensbi64-sifive_u -- update OpenSBI for 64-bit sifive_u machine" + @echo " clean -- delete the files generated by the previous" \ + "build targets" bios: build-seabios-config-seabios-128k build-seabios-config-seabios-256k cp seabios/builds/seabios-128k/bios.bin ../pc-bios/bios.bin@@ -162,6 +167,24 @@ skiboot: efi: edk2-basetools $(MAKE) -f Makefile.edk2 +opensbi32-virt: + $(MAKE) -C opensbi \ + CROSS_COMPILE=$(riscv32_cross_prefix) \
roms/Makefile skiboot: · line 182
Quoted 10 lines
roms/Makefile +10
-0+ PLATFORM="qemu/virt" + cp opensbi/build/platform/qemu/virt/firmware/fw_jump.bin ../pc-bios/opensbi-riscv32-virt-fw_jump.bin + +opensbi64-virt: + $(MAKE) -C opensbi \ + CROSS_COMPILE=$(riscv64_cross_prefix) \ + PLATFORM="qemu/virt" + cp opensbi/build/platform/qemu/virt/firmware/fw_jump.bin ../pc-bios/opensbi-riscv64-virt-fw_jump.bin + +opensbi64-virt:
Cut and paste buglet. opensbi64-sifive_u
Quoted 20 lines
roms/Makefile +6
-0+ $(MAKE) -C opensbi \ + CROSS_COMPILE=$(riscv64_cross_prefix) \ + PLATFORM="qemu/sifive_u" + cp opensbi/build/platform/qemu/virt/firmware/fw_jump.bin ../pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin + clean: rm -rf seabios/.config seabios/out seabios/builds $(MAKE) -C sgabios clean@@ -173,3 +196,4 @@ clean: $(MAKE) -C u-boot-sam460ex distclean $(MAKE) -C skiboot clean $(MAKE) -f Makefile.edk2 clean + $(MAKE) -C opensbi cleanroms/opensbi new file +1
-0@@ -0,0 +1 @@ +Subproject commit ca20ac0cd4c099006d4eea4d9ac7bd7b58e2ae0f
Re: [Qemu-devel] [PULL 33/34] roms: Add OpenSBI version 0.3
Quoted 13 lines · Jonathan Cameron
Quoted 8 lines · On Thu, 27 Jun 2019 08:20:10 -0700 Palmer Dabbelt <[email protected]> wrote:
From: Alistair Francis <[email protected]>
Add OpenSBI version 0.3 as a git submodule and as a prebult binary.
Signed-off-by Alistair Francis <[email protected]>Reviewed-by Bin Meng <[email protected]>Tested-by Bin Meng <[email protected]>Signed-off-by Palmer Dabbelt <[email protected]>
Quoted 5 lines
I sent a late bug report on this one.. Hence posting here as well to make sure it doesn't fall through the cracks!
Right now you can't actually build the opensbi64-virt firmware due to cut and paste error in the
Makefile.
Ah, thanks for the bug report.
@Palmer Dabbelt I'm just going to send you a fixup commit. Can you apply it to your tree and send a PRv2?
Quoted 4 lines
As a side note, I hit this because OpenSBI 0.3 is resulting in a login loop on a debian test image and the current upstream isn't. I haven't debugged yet, but someone else may hit that problem.
Unfortunately OpenSBI 0.3 is a little old now, in saying that I didn't know there are bugs in it? Which kernel are you using?
Alistair
Quoted 95 lines
Thanks,
Jonathan
Quoted 54 lines
roms/Makefile +20
-12@@ -37,6 +37,8 @@ find-cross-prefix = $(subst gcc,,$(notdir $(call find-cross-gcc,$(1)))) powerpc64_cross_prefix := $(call find-cross-prefix,powerpc64) powerpc_cross_prefix := $(call find-cross-prefix,powerpc) x86_64_cross_prefix := $(call find-cross-prefix,x86_64) +riscv32_cross_prefix := $(call find-cross-prefix,riscv32) +riscv64_cross_prefix := $(call find-cross-prefix,riscv64) # tag our seabios builds SEABIOS_EXTRAVERSION="-prebuilt.qemu.org"@@ -52,18 +54,21 @@ EDK2_EFIROM = edk2/BaseTools/Source/C/bin/EfiRom default: @echo "nothing is build by default" @echo "available build targets:" - @echo " bios -- update bios.bin (seabios)" - @echo " vgabios -- update vgabios binaries (seabios)" - @echo " sgabios -- update sgabios binaries" - @echo " pxerom -- update nic roms (bios only)" - @echo " efirom -- update nic roms (bios+efi)" - @echo " slof -- update slof.bin" - @echo " skiboot -- update skiboot.lid" - @echo " u-boot.e500 -- update u-boot.e500" - @echo " u-boot.sam460 -- update u-boot.sam460" - @echo " efi -- update UEFI (edk2) platform firmware" - @echo " clean -- delete the files generated by the previous" \ - "build targets" + @echo " bios -- update bios.bin (seabios)" + @echo " vgabios -- update vgabios binaries (seabios)" + @echo " sgabios -- update sgabios binaries" + @echo " pxerom -- update nic roms (bios only)" + @echo " efirom -- update nic roms (bios+efi)" + @echo " slof -- update slof.bin" + @echo " skiboot -- update skiboot.lid" + @echo " u-boot.e500 -- update u-boot.e500" + @echo " u-boot.sam460 -- update u-boot.sam460" + @echo " efi -- update UEFI (edk2) platform firmware" + @echo " opensbi32-virt -- update OpenSBI for 32-bit virt machine" + @echo " opensbi64-virt -- update OpenSBI for 64-bit virt machine" + @echo " opensbi64-sifive_u -- update OpenSBI for 64-bit sifive_u machine" + @echo " clean -- delete the files generated by the previous" \ + "build targets" bios: build-seabios-config-seabios-128k build-seabios-config-seabios-256k cp seabios/builds/seabios-128k/bios.bin ../pc-bios/bios.bin@@ -162,6 +167,24 @@ skiboot: efi: edk2-basetools $(MAKE) -f Makefile.edk2 +opensbi32-virt: + $(MAKE) -C opensbi \ + CROSS_COMPILE=$(riscv32_cross_prefix) \roms/Makefile skiboot: · line 182
Quoted 10 lines
roms/Makefile +10
-0+ PLATFORM="qemu/virt" + cp opensbi/build/platform/qemu/virt/firmware/fw_jump.bin ../pc-bios/opensbi-riscv32-virt-fw_jump.bin + +opensbi64-virt: + $(MAKE) -C opensbi \ + CROSS_COMPILE=$(riscv64_cross_prefix) \ + PLATFORM="qemu/virt" + cp opensbi/build/platform/qemu/virt/firmware/fw_jump.bin ../pc-bios/opensbi-riscv64-virt-fw_jump.bin + +opensbi64-virt:Cut and paste buglet. opensbi64-sifive_u
Quoted 20 lines
roms/Makefile +6
-0+ $(MAKE) -C opensbi \ + CROSS_COMPILE=$(riscv64_cross_prefix) \ + PLATFORM="qemu/sifive_u" + cp opensbi/build/platform/qemu/virt/firmware/fw_jump.bin ../pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin + clean: rm -rf seabios/.config seabios/out seabios/builds $(MAKE) -C sgabios clean@@ -173,3 +196,4 @@ clean: $(MAKE) -C u-boot-sam460ex distclean $(MAKE) -C skiboot clean $(MAKE) -f Makefile.edk2 clean + $(MAKE) -C opensbi cleanroms/opensbi new file +1
-0@@ -0,0 +1 @@ +Subproject commit ca20ac0cd4c099006d4eea4d9ac7bd7b58e2ae0f
Re: [Qemu-devel] [PULL 33/34] roms: Add OpenSBI version 0.3
Quoted 18 lines · On Fri, 28 Jun 2019 09:12:45 PDT (-0700), [email protected] wrote:
Quoted 16 lines · Jonathan Cameron
Quoted 8 lines · On Thu, 27 Jun 2019 08:20:10 -0700 Palmer Dabbelt <[email protected]> wrote:
From: Alistair Francis <[email protected]>
Add OpenSBI version 0.3 as a git submodule and as a prebult binary.
Signed-off-by Alistair Francis <[email protected]>Reviewed-by Bin Meng <[email protected]>Tested-by Bin Meng <[email protected]>Signed-off-by Palmer Dabbelt <[email protected]>I sent a late bug report on this one.. Hence posting here as well to make sure it doesn't fall through the cracks!
Quoted 7 lines
Quoted 2 lines
Right now you can't actually build the opensbi64-virt firmware due to cut and paste error in the
Makefile.Ah, thanks for the bug report.
@Palmer Dabbelt I'm just going to send you a fixup commit. Can you apply it to your tree and send a PRv2?
WFM.
Quoted 106 lines
Quoted 5 lines
As a side note, I hit this because OpenSBI 0.3 is resulting in a login loop on a debian test image and the current upstream isn't. I haven't debugged yet, but someone else may hit that problem.
Unfortunately OpenSBI 0.3 is a little old now, in saying that I didn't know there are bugs in it? Which kernel are you using?
Alistair
Quoted 95 lines
Thanks,
Jonathan
Quoted 54 lines
roms/Makefile +20
-12@@ -37,6 +37,8 @@ find-cross-prefix = $(subst gcc,,$(notdir $(call find-cross-gcc,$(1)))) powerpc64_cross_prefix := $(call find-cross-prefix,powerpc64) powerpc_cross_prefix := $(call find-cross-prefix,powerpc) x86_64_cross_prefix := $(call find-cross-prefix,x86_64) +riscv32_cross_prefix := $(call find-cross-prefix,riscv32) +riscv64_cross_prefix := $(call find-cross-prefix,riscv64) # tag our seabios builds SEABIOS_EXTRAVERSION="-prebuilt.qemu.org"@@ -52,18 +54,21 @@ EDK2_EFIROM = edk2/BaseTools/Source/C/bin/EfiRom default: @echo "nothing is build by default" @echo "available build targets:" - @echo " bios -- update bios.bin (seabios)" - @echo " vgabios -- update vgabios binaries (seabios)" - @echo " sgabios -- update sgabios binaries" - @echo " pxerom -- update nic roms (bios only)" - @echo " efirom -- update nic roms (bios+efi)" - @echo " slof -- update slof.bin" - @echo " skiboot -- update skiboot.lid" - @echo " u-boot.e500 -- update u-boot.e500" - @echo " u-boot.sam460 -- update u-boot.sam460" - @echo " efi -- update UEFI (edk2) platform firmware" - @echo " clean -- delete the files generated by the previous" \ - "build targets" + @echo " bios -- update bios.bin (seabios)" + @echo " vgabios -- update vgabios binaries (seabios)" + @echo " sgabios -- update sgabios binaries" + @echo " pxerom -- update nic roms (bios only)" + @echo " efirom -- update nic roms (bios+efi)" + @echo " slof -- update slof.bin" + @echo " skiboot -- update skiboot.lid" + @echo " u-boot.e500 -- update u-boot.e500" + @echo " u-boot.sam460 -- update u-boot.sam460" + @echo " efi -- update UEFI (edk2) platform firmware" + @echo " opensbi32-virt -- update OpenSBI for 32-bit virt machine" + @echo " opensbi64-virt -- update OpenSBI for 64-bit virt machine" + @echo " opensbi64-sifive_u -- update OpenSBI for 64-bit sifive_u machine" + @echo " clean -- delete the files generated by the previous" \ + "build targets" bios: build-seabios-config-seabios-128k build-seabios-config-seabios-256k cp seabios/builds/seabios-128k/bios.bin ../pc-bios/bios.bin@@ -162,6 +167,24 @@ skiboot: efi: edk2-basetools $(MAKE) -f Makefile.edk2 +opensbi32-virt: + $(MAKE) -C opensbi \ + CROSS_COMPILE=$(riscv32_cross_prefix) \roms/Makefile skiboot: · line 182
Quoted 10 lines
roms/Makefile +10
-0+ PLATFORM="qemu/virt" + cp opensbi/build/platform/qemu/virt/firmware/fw_jump.bin ../pc-bios/opensbi-riscv32-virt-fw_jump.bin + +opensbi64-virt: + $(MAKE) -C opensbi \ + CROSS_COMPILE=$(riscv64_cross_prefix) \ + PLATFORM="qemu/virt" + cp opensbi/build/platform/qemu/virt/firmware/fw_jump.bin ../pc-bios/opensbi-riscv64-virt-fw_jump.bin + +opensbi64-virt:Cut and paste buglet. opensbi64-sifive_u
Quoted 20 lines
roms/Makefile +6
-0+ $(MAKE) -C opensbi \ + CROSS_COMPILE=$(riscv64_cross_prefix) \ + PLATFORM="qemu/sifive_u" + cp opensbi/build/platform/qemu/virt/firmware/fw_jump.bin ../pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin + clean: rm -rf seabios/.config seabios/out seabios/builds $(MAKE) -C sgabios clean@@ -173,3 +196,4 @@ clean: $(MAKE) -C u-boot-sam460ex distclean $(MAKE) -C skiboot clean $(MAKE) -f Makefile.edk2 clean + $(MAKE) -C opensbi cleanroms/opensbi new file +1
-0@@ -0,0 +1 @@ +Subproject commit ca20ac0cd4c099006d4eea4d9ac7bd7b58e2ae0f
Re: [Qemu-devel] [PULL 33/34] roms: Add OpenSBI version 0.3
In reply to Alistair FrancisQuoted 27 lines · On Fri, 28 Jun 2019 09:12:45 -0700 Alistair Francis <[email protected]>…
Quoted 13 lines · Jonathan Cameron
Quoted 8 lines · On Thu, 27 Jun 2019 08:20:10 -0700 Palmer Dabbelt <[email protected]> wrote:
From: Alistair Francis <[email protected]>
Add OpenSBI version 0.3 as a git submodule and as a prebult binary.
Signed-off-by Alistair Francis <[email protected]>Reviewed-by Bin Meng <[email protected]>Tested-by Bin Meng <[email protected]>Signed-off-by Palmer Dabbelt <[email protected]>Quoted 5 lines
I sent a late bug report on this one.. Hence posting here as well to make sure it doesn't fall through the cracks!
Right now you can't actually build the opensbi64-virt firmware due to cut and paste error in the
Makefile.Ah, thanks for the bug report.
@Palmer Dabbelt I'm just going to send you a fixup commit. Can you apply it to your tree and send a PRv2?
Quoted 1 line
Quoted 6 lines
Quoted 3 lines
As a side note, I hit this because OpenSBI 0.3 is resulting in a login loop on a debian test image and the current upstream isn't. I haven't debugged yet, but someone else may hit that problem.
Unfortunately OpenSBI 0.3 is a little old now, in saying that I didn't know there are bugs in it? Which kernel are you using?
Mainline 5.2.0-rc5.
Just in case I also checked 5.2.0-rc7
I tried doing an odd git bisect with good and bad reversed to figure out what fixed the problem, but boot wedged at "Run /sbin/init as init process."
The wedge was bisected to:
4e2cd47820 ("lib: Flush everything when remote TLB flush range is too large")
Which the patch correctly identifies as a problem introduced this kernel cycle. 5.2-rc1.
So on that basis alone I'd suggest we want to move to a more recent openSBI asap, after all the 5.2 kernel will be out in a week or so.
I'm a bit short on time (flight to catch), so haven't pushed that fix that far back in the tree yet in order to figure what is causing the login loop. Won't have access to relevant build machines until Wednesday.
That patch cherry-picked on lib: Optimize TLB flush IPIs seems fine, so it is before that point...
Passing that point would require real effort though as the two patches are changing the same code.
So I had a go from the other end (0.3) to see if it was fixed quickly. Ran out of time, but at
"firmware: Reset all registers and flush the icache" it superficially all seems to be working with no TLB related hang, or login loop.
The login loop is present in firmware: Add a barrier instruction for wait for boot hart.
Will see if I can pin it down fully later in the week.
Thanks,
Jonathan
Quoted 98 lines
Alistair
Quoted 95 lines
Thanks,
Jonathan
Quoted 54 lines
roms/Makefile +20
-12@@ -37,6 +37,8 @@ find-cross-prefix = $(subst gcc,,$(notdir $(call find-cross-gcc,$(1)))) powerpc64_cross_prefix := $(call find-cross-prefix,powerpc64) powerpc_cross_prefix := $(call find-cross-prefix,powerpc) x86_64_cross_prefix := $(call find-cross-prefix,x86_64) +riscv32_cross_prefix := $(call find-cross-prefix,riscv32) +riscv64_cross_prefix := $(call find-cross-prefix,riscv64) # tag our seabios builds SEABIOS_EXTRAVERSION="-prebuilt.qemu.org"@@ -52,18 +54,21 @@ EDK2_EFIROM = edk2/BaseTools/Source/C/bin/EfiRom default: @echo "nothing is build by default" @echo "available build targets:" - @echo " bios -- update bios.bin (seabios)" - @echo " vgabios -- update vgabios binaries (seabios)" - @echo " sgabios -- update sgabios binaries" - @echo " pxerom -- update nic roms (bios only)" - @echo " efirom -- update nic roms (bios+efi)" - @echo " slof -- update slof.bin" - @echo " skiboot -- update skiboot.lid" - @echo " u-boot.e500 -- update u-boot.e500" - @echo " u-boot.sam460 -- update u-boot.sam460" - @echo " efi -- update UEFI (edk2) platform firmware" - @echo " clean -- delete the files generated by the previous" \ - "build targets" + @echo " bios -- update bios.bin (seabios)" + @echo " vgabios -- update vgabios binaries (seabios)" + @echo " sgabios -- update sgabios binaries" + @echo " pxerom -- update nic roms (bios only)" + @echo " efirom -- update nic roms (bios+efi)" + @echo " slof -- update slof.bin" + @echo " skiboot -- update skiboot.lid" + @echo " u-boot.e500 -- update u-boot.e500" + @echo " u-boot.sam460 -- update u-boot.sam460" + @echo " efi -- update UEFI (edk2) platform firmware" + @echo " opensbi32-virt -- update OpenSBI for 32-bit virt machine" + @echo " opensbi64-virt -- update OpenSBI for 64-bit virt machine" + @echo " opensbi64-sifive_u -- update OpenSBI for 64-bit sifive_u machine" + @echo " clean -- delete the files generated by the previous" \ + "build targets" bios: build-seabios-config-seabios-128k build-seabios-config-seabios-256k cp seabios/builds/seabios-128k/bios.bin ../pc-bios/bios.bin@@ -162,6 +167,24 @@ skiboot: efi: edk2-basetools $(MAKE) -f Makefile.edk2 +opensbi32-virt: + $(MAKE) -C opensbi \ + CROSS_COMPILE=$(riscv32_cross_prefix) \roms/Makefile skiboot: · line 182
Quoted 10 lines
roms/Makefile +10
-0+ PLATFORM="qemu/virt" + cp opensbi/build/platform/qemu/virt/firmware/fw_jump.bin ../pc-bios/opensbi-riscv32-virt-fw_jump.bin + +opensbi64-virt: + $(MAKE) -C opensbi \ + CROSS_COMPILE=$(riscv64_cross_prefix) \ + PLATFORM="qemu/virt" + cp opensbi/build/platform/qemu/virt/firmware/fw_jump.bin ../pc-bios/opensbi-riscv64-virt-fw_jump.bin + +opensbi64-virt:Cut and paste buglet. opensbi64-sifive_u
Quoted 20 lines
roms/Makefile +6
-0+ $(MAKE) -C opensbi \ + CROSS_COMPILE=$(riscv64_cross_prefix) \ + PLATFORM="qemu/sifive_u" + cp opensbi/build/platform/qemu/virt/firmware/fw_jump.bin ../pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin + clean: rm -rf seabios/.config seabios/out seabios/builds $(MAKE) -C sgabios clean@@ -173,3 +196,4 @@ clean: $(MAKE) -C u-boot-sam460ex distclean $(MAKE) -C skiboot clean $(MAKE) -f Makefile.edk2 clean + $(MAKE) -C opensbi cleanroms/opensbi new file +1
-0@@ -0,0 +1 @@ +Subproject commit ca20ac0cd4c099006d4eea4d9ac7bd7b58e2ae0f
Re: [Qemu-devel] [Qemu-riscv] [PULL 33/34] roms: Add OpenSBI version 0.3
Quoted 62 lines · Jonathan Cameron
Quoted 27 lines · On Fri, 28 Jun 2019 09:12:45 -0700 Alistair Francis <[email protected]>…
Quoted 13 lines · Jonathan Cameron
Quoted 8 lines · On Thu, 27 Jun 2019 08:20:10 -0700 Palmer Dabbelt <[email protected]> wrote:
From: Alistair Francis <[email protected]>
Add OpenSBI version 0.3 as a git submodule and as a prebult binary.
Signed-off-by Alistair Francis <[email protected]>Reviewed-by Bin Meng <[email protected]>Tested-by Bin Meng <[email protected]>Signed-off-by Palmer Dabbelt <[email protected]>Quoted 5 lines
I sent a late bug report on this one.. Hence posting here as well to make sure it doesn't fall through the cracks!
Right now you can't actually build the opensbi64-virt firmware due to cut and paste error in the
Makefile.Ah, thanks for the bug report.
@Palmer Dabbelt I'm just going to send you a fixup commit. Can you apply it to your tree and send a PRv2?
Quoted 1 line
Quoted 6 lines
Quoted 3 lines
As a side note, I hit this because OpenSBI 0.3 is resulting in a login loop on a debian test image and the current upstream isn't. I haven't debugged yet, but someone else may hit that problem.
Unfortunately OpenSBI 0.3 is a little old now, in saying that I didn't know there are bugs in it? Which kernel are you using?
Mainline 5.2.0-rc5.
Just in case I also checked 5.2.0-rc7
I tried doing an odd git bisect with good and bad reversed to figure out what fixed the problem, but boot wedged at "Run
/sbin/initas init process."The wedge was bisected to:
4e2cd47820("lib: Flush everything when remote TLB flush range is too large")Which the patch correctly identifies as a problem introduced this kernel cycle. 5.2-rc1.
So on that basis alone I'd suggest we want to move to a more recent openSBI asap, after all the 5.2 kernel will be out in a week or so.
I'm a bit short on time (flight to catch), so haven't pushed that fix that far back in the tree yet in order to figure what is causing the login loop. Won't have access to relevant build machines until Wednesday.
That patch cherry-picked on lib: Optimize TLB flush IPIs seems fine, so it is before that point...
Quoted 7 lines
Passing that point would require real effort though as the two patches are changing the same code.
So I had a go from the other end (0.3) to see if it was fixed quickly. Ran out of time, but at
"firmware: Reset all registers and flush the icache" it superficially all seems to be working with no TLB related hang, or login loop.
We plan to release OpenSBI 0.4 in couple of days. It would be best to pick-up OpenSBI 0.4 FW_JUMP binaries.
Regards,
Anup
Re: [Qemu-devel] [Qemu-riscv] [PULL 33/34] roms: Add OpenSBI version 0.3
Quoted 68 lines · Anup Patel
Quoted 65 lines · Jonathan Cameron
Quoted 27 lines · On Fri, 28 Jun 2019 09:12:45 -0700 Alistair Francis <[email protected]>…
Quoted 13 lines · Jonathan Cameron
Quoted 8 lines · On Thu, 27 Jun 2019 08:20:10 -0700 Palmer Dabbelt <[email protected]> wrote:
From: Alistair Francis <[email protected]>
Add OpenSBI version 0.3 as a git submodule and as a prebult binary.
Signed-off-by Alistair Francis <[email protected]>Reviewed-by Bin Meng <[email protected]>Tested-by Bin Meng <[email protected]>Signed-off-by Palmer Dabbelt <[email protected]>Quoted 5 lines
I sent a late bug report on this one.. Hence posting here as well to make sure it doesn't fall through the cracks!
Right now you can't actually build the opensbi64-virt firmware due to cut and paste error in the
Makefile.Ah, thanks for the bug report.
@Palmer Dabbelt I'm just going to send you a fixup commit. Can you apply it to your tree and send a PRv2?
Quoted 1 line
Quoted 6 lines
Quoted 3 lines
As a side note, I hit this because OpenSBI 0.3 is resulting in a login loop on a debian test image and the current upstream isn't. I haven't debugged yet, but someone else may hit that problem.
Unfortunately OpenSBI 0.3 is a little old now, in saying that I didn't know there are bugs in it? Which kernel are you using?
Mainline 5.2.0-rc5.
Just in case I also checked 5.2.0-rc7
I tried doing an odd git bisect with good and bad reversed to figure out what fixed the problem, but boot wedged at "Run
/sbin/initas init process."The wedge was bisected to:
4e2cd47820("lib: Flush everything when remote TLB flush range is too large")Which the patch correctly identifies as a problem introduced this kernel cycle. 5.2-rc1.
So on that basis alone I'd suggest we want to move to a more recent openSBI asap, after all the 5.2 kernel will be out in a week or so.
I'm a bit short on time (flight to catch), so haven't pushed that fix that far back in the tree yet in order to figure what is causing the login loop. Won't have access to relevant build machines until Wednesday.
That patch cherry-picked on lib: Optimize TLB flush IPIs seems fine, so it is before that point...
Passing that point would require real effort though as the two patches are changing the same code.
Quoted 7 lines
Quoted 4 lines
So I had a go from the other end (0.3) to see if it was fixed quickly. Ran out of time, but at
"firmware: Reset all registers and flush the icache" it superficially all seems to be working with no TLB related hang, or login loop.We plan to release OpenSBI 0.4 in couple of days. It would be best to pick-up OpenSBI 0.4
FW_JUMPbinaries.
Great! When the 0.4 release comes out I'll send a patch to update the QEMU binaries and submodules. If this PR is merged before then we can just update on top of this (as 5.1 and earlier kernels will work with 0.3) and it not it can be squashed into this PR.
Alistair
Quoted 3 lines
Regards,
Anup
Re: [Qemu-devel] [PULL 33/34] roms: Add OpenSBI version 0.3
In reply to Palmer DabbeltQuoted 28 lines · Palmer Dabbelt
From: Alistair Francis <[email protected]>
Add OpenSBI version 0.3 as a git submodule and as a prebult binary.
Signed-off-by Alistair Francis <[email protected]>Reviewed-by Bin Meng <[email protected]>Tested-by Bin Meng <[email protected]>Signed-off-by Palmer Dabbelt <[email protected]>--- .gitmodules | 3 ++ Makefile | 5 +- pc-bios/opensbi-riscv32-virt-fw_jump.bin | Bin 0 -> 28848 bytes pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin | Bin 0 -> 28904 bytes pc-bios/opensbi-riscv64-virt-fw_jump.bin | Bin 0 -> 28904 bytes roms/Makefile | 48 ++++++++++++++----- roms/opensbi | 1 + 7 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 pc-bios/opensbi-riscv32-virt-fw_jump.bin create mode 100644 pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin create mode 100644 pc-bios/opensbi-riscv64-virt-fw_jump.bin create mode 160000 roms/opensbi.gitmodules +0
-0
.gitmodules line 60
Quoted 6 lines
.gitmodules +3
-0@@ -55,3 +55,6 @@ [submodule "slirp"] path = slirp url = https://git.qemu.org/git/libslirp.git +[submodule "roms/opensbi"] + path = roms/opensbi + url = https://github.com/riscv/opensbi.git
It would be nice to state the license for new blobs we're adding to the source tree... In particular, I find the readme at https://github.com/riscv/opensbi a bit confusing because it says it's 2-BSD but also that some parts are Apache-2.0; the latter is *not* GPL-2.0 compatible. That makes it not completely obvious to me that we can ship this with QEMU.
Also, new git modules in .gitmodules should be qemu.org URLs, not random external ones. (ie, we should set up mirroring of any new external repo we start shipping code and binaries for). We can set this up and fix up the gitmodules file after the fact, but the ideal is to do it in advance rather than afterwards.
thanks
-- PMM
Re: [Qemu-devel] [PULL 33/34] roms: Add OpenSBI version 0.3
Quoted 38 lines · Peter Maydell
Quoted 36 lines · Palmer Dabbelt
From: Alistair Francis <[email protected]>
Add OpenSBI version 0.3 as a git submodule and as a prebult binary.
Signed-off-by Alistair Francis <[email protected]>Reviewed-by Bin Meng <[email protected]>Tested-by Bin Meng <[email protected]>Signed-off-by Palmer Dabbelt <[email protected]>--- .gitmodules | 3 ++ Makefile | 5 +- pc-bios/opensbi-riscv32-virt-fw_jump.bin | Bin 0 -> 28848 bytes pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin | Bin 0 -> 28904 bytes pc-bios/opensbi-riscv64-virt-fw_jump.bin | Bin 0 -> 28904 bytes roms/Makefile | 48 ++++++++++++++- ---- roms/opensbi | 1 + 7 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 pc-bios/opensbi-riscv32-virt-fw_jump.bin create mode 100644 pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin create mode 100644 pc-bios/opensbi-riscv64-virt-fw_jump.bin create mode 160000 roms/opensbi.gitmodules +2
-0@@ -55,3 +55,6 @@ [submodule "slirp"] path = slirp url = https://git.qemu.org/git/libslirp.git +[submodule "roms/opensbi"] + path = roms/opensbi
Quoted 8 lines
.gitmodules line 60
Quoted 1 line
.gitmodules +1
-0+ url = https://github.com/riscv/opensbi.gitIt would be nice to state the license for new blobs we're adding to the source tree... In particular, I find the readme at https://github.com/riscv/opensbi a bit confusing because it says it's 2-BSD but also that some parts are Apache-2.0; the latter is *not* GPL-2.0 compatible. That makes it not completely obvious to me that we can ship this with QEMU.
Ah, I didn't realise there is Apache-2.0 code in there.
In this case all of the code we are using (we aren't using the Kendryte code with QEMU) is BSD-2-Clause. Even then though does it matter if it is GPL compatible? This isn't being linked with QEMU it is just being included with QEMU.
I can add details of the license in the source tree, where should it be added?
Quoted 7 lines
Also, new git modules in .gitmodules should be qemu.org URLs, not random external ones. (ie, we should set up mirroring of any new external repo we start shipping code and binaries for). We can set this up and fix up the gitmodules file after the fact, but the ideal is to do it in advance rather than afterwards.
Ok, who can setup a git mirror for the QEMU repo?
PS: It seems like there are still some issues with this patch so maybe it's worth dropping this patch from the PR so that we can get everything else merged.
Alistair
Quoted 3 lines
thanks
-- PMM
Re: [Qemu-devel] [PULL 33/34] roms: Add OpenSBI version 0.3
Quoted 49 lines · Alistair Francis
Quoted 38 lines · Peter Maydell
Quoted 36 lines · Palmer Dabbelt
From: Alistair Francis <[email protected]>
Add OpenSBI version 0.3 as a git submodule and as a prebult binary.
Signed-off-by Alistair Francis <[email protected]>Reviewed-by Bin Meng <[email protected]>Tested-by Bin Meng <[email protected]>Signed-off-by Palmer Dabbelt <[email protected]>--- .gitmodules | 3 ++ Makefile | 5 +- pc-bios/opensbi-riscv32-virt-fw_jump.bin | Bin 0 -> 28848 bytes pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin | Bin 0 -> 28904 bytes pc-bios/opensbi-riscv64-virt-fw_jump.bin | Bin 0 -> 28904 bytes roms/Makefile | 48 ++++++++++++++- ---- roms/opensbi | 1 + 7 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 pc-bios/opensbi-riscv32-virt-fw_jump.bin create mode 100644 pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin create mode 100644 pc-bios/opensbi-riscv64-virt-fw_jump.bin create mode 160000 roms/opensbi.gitmodules +2
-0@@ -55,3 +55,6 @@ [submodule "slirp"] path = slirp url = https://git.qemu.org/git/libslirp.git +[submodule "roms/opensbi"] + path = roms/opensbiQuoted 8 lines
.gitmodules line 60
Quoted 1 line
.gitmodules +1
-0+ url = https://github.com/riscv/opensbi.gitIt would be nice to state the license for new blobs we're adding to the source tree... In particular, I find the readme at https://github.com/riscv/opensbi a bit confusing because it says it's 2-BSD but also that some parts are Apache-2.0; the latter is *not* GPL-2.0 compatible. That makes it not completely obvious to me that we can ship this with QEMU.
Quoted 6 lines
Ah, I didn't realise there is Apache-2.0 code in there.
In this case all of the code we are using (we aren't using the Kendryte code with QEMU) is BSD-2-Clause. Even then though does it matter if it is GPL compatible? This isn't being linked with QEMU it is just being included with QEMU.
Yeah, if we're not building the apache-2.0 parts then I think we're OK, and as you say there's the question of whether QEMU's GPL affects what we ship as mere bios blobs to run as guest code anyway. But it's sufficiently not a "really obviously ok" that I'd like a second opinion; cc'd some people who might have second opinions.
Quoted 2 lines
I can add details of the license in the source tree, where should it be added?
I was thinking in the commit message. We also seem to have human-readable information in pc-bios/README for the various blobs, which seems to be a good place for a brief one-para summary of what OpenSBI is, a URL for its upstream, and a brief note of the license.
Quoted 9 lines
Quoted 7 lines
Also, new git modules in .gitmodules should be qemu.org URLs, not random external ones. (ie, we should set up mirroring of any new external repo we start shipping code and binaries for). We can set this up and fix up the gitmodules file after the fact, but the ideal is to do it in advance rather than afterwards.
Ok, who can setup a git mirror for the QEMU repo?
That would be Jeff or Stefan (cc'd).
Quoted 3 lines
PS: It seems like there are still some issues with this patch so maybe it's worth dropping this patch from the PR so that we can get everything else merged.
Yeah, that would be my suggestion.
thanks
-- PMM
Re: [Qemu-devel] [PULL 33/34] roms: Add OpenSBI version 0.3
Quoted 76 lines · Peter Maydell
Quoted 55 lines · Alistair Francis
Quoted 43 lines · Peter Maydell
Quoted 34 lines · Palmer Dabbelt
From: Alistair Francis <[email protected]>
Add OpenSBI version 0.3 as a git submodule and as a prebult binary.
Signed-off-by Alistair Francis <[email protected]>Reviewed-by Bin Meng <[email protected]>Tested-by Bin Meng <[email protected]>Signed-off-by Palmer Dabbelt <[email protected]>--- .gitmodules | 3 ++ Makefile | 5 +- pc-bios/opensbi-riscv32-virt-fw_jump.bin | Bin 0 -> 28848 bytes pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin | Bin 0 -> 28904 bytes pc-bios/opensbi-riscv64-virt-fw_jump.bin | Bin 0 -> 28904 bytes roms/Makefile | 48 ++++++++++++++- ---- roms/opensbi | 1 + 7 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 pc-bios/opensbi-riscv32-virt-fw_jump.bin create mode 100644 pc-bios/opensbi-riscv64-sifive_u- fw_jump.bin create mode 100644 pc-bios/opensbi-riscv64-virt-fw_jump.bin create mode 160000 roms/opensbi.gitmodules +0
-0.gitmodules line 60
Quoted 6 lines
.gitmodules +3
-0@@ -55,3 +55,6 @@ [submodule "slirp"] path = slirp url = https://git.qemu.org/git/libslirp.git +[submodule "roms/opensbi"] + path = roms/opensbi + url = https://github.com/riscv/opensbi.gitQuoted 8 lines
It would be nice to state the license for new blobs we're adding to the source tree... In particular, I find the readme at https://github.com/riscv/opensbi a bit confusing because it says it's 2-BSD but also that some parts are Apache- 2.0;
the latter is *not* GPL-2.0 compatible. That makes it not completely
obvious to me that we can ship this with QEMU.Ah, I didn't realise there is Apache-2.0 code in there.
Quoted 7 lines
In this case all of the code we are using (we aren't using the Kendryte
code with QEMU) is BSD-2-Clause. Even then though does it matter if it
is GPL compatible? This isn't being linked with QEMU it is just being
included with QEMU.Yeah, if we're not building the apache-2.0 parts then I think we're OK, and as you say there's the question of whether QEMU's GPL affects what we ship as mere bios blobs to run as guest code anyway. But it's sufficiently not a "really obviously ok" that I'd like a second opinion; cc'd some people who might have second opinions.
Quoted 3 lines
I can add details of the license in the source tree, where should it be
added?
Quoted 5 lines
I was thinking in the commit message. We also seem to have human-readable information in pc-bios/README for the various blobs, which seems to be a good place for a brief one-para summary of what OpenSBI is, a URL for its upstream, and a brief note of the license.
Ok, I'll add that.
Quoted 10 lines
Quoted 9 lines
Quoted 7 lines
Also, new git modules in .gitmodules should be qemu.org URLs, not random external ones. (ie, we should set up mirroring of any new external repo we start shipping code and binaries for). We can set this up and fix up the gitmodules file after the fact, but the ideal is to do it in advance rather than afterwards.
Ok, who can setup a git mirror for the QEMU repo?
Quoted 8 lines
That would be Jeff or Stefan (cc'd).
Quoted 4 lines
PS: It seems like there are still some issues with this patch so maybe
it's worth dropping this patch from the PR so that we can get everything else merged.Yeah, that would be my suggestion.
Can you do that when you merge it or does Palmer have to send the PR again?
Alistair
Quoted 3 lines
thanks
-- PMM
Re: [Qemu-devel] [PULL 33/34] roms: Add OpenSBI version 0.3
Quoted 9 lines · Alistair Francis
Quoted 7 lines · Peter Maydell
Quoted 4 lines · Alistair Francis
PS: It seems like there are still some issues with this patch so maybe
it's worth dropping this patch from the PR so that we can get everything else merged.
Quoted 4 lines
Quoted 1 line
Yeah, that would be my suggestion.
Can you do that when you merge it or does Palmer have to send the PR again?
Palmer needs to respin it -- pulls are signed and I can't modify them, only either apply them or not. (Technically I could in theory cherry-pick all the other commits out of them but that would be a huge amount of manual labour.)
thanks
-- PMM
Re: [Qemu-devel] [PULL 33/34] roms: Add OpenSBI version 0.3
Quoted 13 lines · Peter Maydell
Quoted 11 lines · Alistair Francis
Quoted 9 lines · Peter Maydell
Quoted 5 lines · Alistair Francis
PS: It seems like there are still some issues with this patch so
maybe
it's worth dropping this patch from the PR so that we can get everything else merged.Yeah, that would be my suggestion.
Quoted 8 lines
Quoted 3 lines
Can you do that when you merge it or does Palmer have to send the PR
again?Palmer needs to respin it -- pulls are signed and I can't modify them, only either apply them or not. (Technically I could in theory cherry-pick all the other commits out of them but that would be a huge amount of manual labour.)
No worries.
@Palmer can you please drop these two patches from this PR?
hw/riscv: Load OpenSBI as the default firmware
roms: Add OpenSBI version 0.3
Sorry for the all the last minute changes. I'll wait until OpenSBI 0.4 to respin those two patches.
Alistair
Quoted 3 lines
thanks
-- PMM
Re: [Qemu-devel] [Qemu-riscv] [PULL 33/34] roms: Add OpenSBI version 0.3
Quoted 26 lines · Alistair Francis
Quoted 13 lines · Peter Maydell
Quoted 11 lines · Alistair Francis
Quoted 9 lines · Peter Maydell
Quoted 5 lines · Alistair Francis
PS: It seems like there are still some issues with this patch so
maybe
it's worth dropping this patch from the PR so that we can get everything else merged.Yeah, that would be my suggestion.
Quoted 8 lines
Quoted 3 lines
Can you do that when you merge it or does Palmer have to send the PR
again?Palmer needs to respin it -- pulls are signed and I can't modify them, only either apply them or not. (Technically I could in theory cherry-pick all the other commits out of them but that would be a huge amount of manual labour.)
No worries.
Quoted 7 lines
@Palmer can you please drop these two patches from this PR?
hw/riscv: Load OpenSBI as the default firmware
roms: Add OpenSBI version 0.3Sorry for the all the last minute changes. I'll wait until OpenSBI 0.4 to respin those two patches.
OpenSBI v0.4 is now available.
(Refer, https://github.com/riscv/opensbi/releases/tag/v0.4)
Regards,
Anup
Re: [Qemu-devel] [PULL 33/34] roms: Add OpenSBI version 0.3
In reply to Peter MaydellQuoted 57 lines · Peter Maydell
Quoted 49 lines · Alistair Francis
Quoted 38 lines · Peter Maydell
Quoted 36 lines · Palmer Dabbelt
From: Alistair Francis <[email protected]>
Add OpenSBI version 0.3 as a git submodule and as a prebult binary.
Signed-off-by Alistair Francis <[email protected]>Reviewed-by Bin Meng <[email protected]>Tested-by Bin Meng <[email protected]>Signed-off-by Palmer Dabbelt <[email protected]>--- .gitmodules | 3 ++ Makefile | 5 +- pc-bios/opensbi-riscv32-virt-fw_jump.bin | Bin 0 -> 28848 bytes pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin | Bin 0 -> 28904 bytes pc-bios/opensbi-riscv64-virt-fw_jump.bin | Bin 0 -> 28904 bytes roms/Makefile | 48 ++++++++++++++- ---- roms/opensbi | 1 + 7 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 pc-bios/opensbi-riscv32-virt-fw_jump.bin create mode 100644 pc-bios/opensbi-riscv64-sifive_u-fw_jump.bin create mode 100644 pc-bios/opensbi-riscv64-virt-fw_jump.bin create mode 160000 roms/opensbi.gitmodules +2
-0@@ -55,3 +55,6 @@ [submodule "slirp"] path = slirp url = https://git.qemu.org/git/libslirp.git +[submodule "roms/opensbi"] + path = roms/opensbiQuoted 8 lines
.gitmodules line 60
Quoted 1 line
.gitmodules +1
-0+ url = https://github.com/riscv/opensbi.gitIt would be nice to state the license for new blobs we're adding to the source tree... In particular, I find the readme at https://github.com/riscv/opensbi a bit confusing because it says it's 2-BSD but also that some parts are Apache-2.0; the latter is *not* GPL-2.0 compatible. That makes it not completely obvious to me that we can ship this with QEMU.
Quoted 6 lines
Ah, I didn't realise there is Apache-2.0 code in there.
In this case all of the code we are using (we aren't using the Kendryte code with QEMU) is BSD-2-Clause. Even then though does it matter if it is GPL compatible? This isn't being linked with QEMU it is just being included with QEMU.
Quoted 6 lines
Yeah, if we're not building the apache-2.0 parts then I think we're OK, and as you say there's the question of whether QEMU's GPL affects what we ship as mere bios blobs to run as guest code anyway. But it's sufficiently not a "really obviously ok" that I'd like a second opinion; cc'd some people who might have second opinions.
You need an expert opinion.
My non-expert opinion: we can't distribute anything that's not compatible with GPLv2, at least as long as LICENSE makes the following claims:
1) QEMU as a whole is released under the GNU General Public License, version 2.
2) Parts of QEMU have specific licenses which are compatible with the GNU General Public License, version 2. Hence each source file contains its own licensing information. Source files with no licensing information are released under the GNU General Public License, version 2 or (at your option) any later version.
As of July 2013, contributions under version 2 of the GNU General Public License (and no later version) are only accepted for the following files or directories: bsd-user/, linux-user/, hw/vfio/, hw/xen/xen_pt*.
3) The Tiny Code Generator (TCG) is released under the BSD license (see license headers in files).
Complicating things further just to distribute a firmware blob would be a mistake. Our licensing situation is already complex enough for me to call it a mistake.
[...]
Re: [Qemu-devel] [PULL 33/34] roms: Add OpenSBI version 0.3
Quoted 11 lines · Markus Armbruster
Quoted 6 lines
Yeah, if we're not building the apache-2.0 parts then I think we're OK, and as you say there's the question of whether QEMU's GPL affects what we ship as mere bios blobs to run as guest code anyway. But it's sufficiently not a "really obviously ok" that I'd like a second opinion; cc'd some people who might have second opinions.
You need an expert opinion.
My non-expert opinion: we can't distribute anything that's not compatible with GPLv2
Guest code is not part of QEMU. We don't say that SeaBIOS, SLOF, etc. are part of QEMU; it constitutes mere aggregation with the GPLv2 QEMU sources, so it _is_ possible to distribute APSL2 guest code with QEMU. IANAL, but I'm fairly sure about this.
However I agree that LICENSE needs to be updated, something like this:
LICENSE +13 -8
@@ -1,13 +1,18 @@ -The following points clarify the QEMU license: +The QEMU distribution includes both the QEMU emulator and +various firmware files. These are separate programs that are +distributed together for our users' convenience, and they have +separate license. -1) QEMU as a whole is released under the GNU General Public License, -version 2. +The following points clarify the license of the QEMU emulator: -2) Parts of QEMU have specific licenses which are compatible with the -GNU General Public License, version 2. Hence each source file contains -its own licensing information. Source files with no licensing information -are released under the GNU General Public License, version 2 or (at your -option) any later version. +1) The QEMU emulator as a whole is released under the GNU General +Public License, version 2. + +2) Parts of the QEMU emulator have specific licenses which are compatible +with the GNU General Public License, version 2. Hence each source file +contains its own licensing information. Source files with no licensing +information are released under the GNU General Public License, version +2 or (at your option) any later version. As of July 2013, contributions under version 2 of the GNU General Public License (and no later version) are only accepted for the following files
Paolo
Re: [Qemu-devel] [PULL 33/34] roms: Add OpenSBI version 0.3
Quoted 11 lines · Paolo Bonzini
Quoted 9 lines · Markus Armbruster
Quoted 6 lines
Yeah, if we're not building the apache-2.0 parts then I think we're OK, and as you say there's the question of whether QEMU's GPL affects what we ship as mere bios blobs to run as guest code anyway. But it's sufficiently not a "really obviously ok" that I'd like a second opinion; cc'd some people who might have second opinions.
You need an expert opinion.
Quoted 7 lines
Quoted 2 lines
My non-expert opinion: we can't distribute anything that's not compatible with GPLv2
Guest code is not part of QEMU. We don't say that SeaBIOS, SLOF, etc. are part of QEMU; it constitutes mere aggregation with the GPLv2 QEMU sources, so it _is_ possible to distribute APSL2 guest code with QEMU. IANAL, but I'm fairly sure about this.
This is my understanding as well. We aren't linking OpenSBI with QEMU so we should be fine to release it with any license.
Quoted 24 lines
However I agree that LICENSE needs to be updated, something like this:
LICENSE +6
-8@@ -1,13 +1,18 @@ -The following points clarify the QEMU license: +The QEMU distribution includes both the QEMU emulator and +various firmware files. These are separate programs that are +distributed together for our users' convenience, and they have +separate license. -1) QEMU as a whole is released under the GNU General Public License, -version 2. +The following points clarify the license of the QEMU emulator: -2) Parts of QEMU have specific licenses which are compatible with the -GNU General Public License, version 2. Hence each source file contains -its own licensing information. Source files with no licensing information -are released under the GNU General Public License, version 2 or (at your -option) any later version. +1) The QEMU emulator as a whole is released under the GNU General
LICENSE line 18
Quoted 10 lines
LICENSE +7
-0+Public License, version 2. + +2) Parts of the QEMU emulator have specific licenses which are compatible +with the GNU General Public License, version 2. Hence each source file +contains its own licensing information. Source files with no licensing +information are released under the GNU General Public License, version +2 or (at your option) any later version. As of July 2013, contributions under version 2 of the GNU General Public License (and no later version) are only accepted for the following files
Ok, I'll update the QEMU LICENSE file in the next patch version.
Alistair
Quoted 3 lines
Paolo
Re: [Qemu-devel] [PULL 33/34] roms: Add OpenSBI version 0.3
In reply to Peter MaydellQuoted 13 lines · Peter Maydell
Quoted 12 lines · Alistair Francis
Quoted 9 lines · Peter Maydell
Quoted 1 line · Palmer Dabbelt
From: Alistair Francis <[email protected]>
Also, new git modules in .gitmodules should be qemu.org URLs, not random external ones. (ie, we should set up mirroring of any new external repo we start shipping code and binaries for). We can set this up and fix up the gitmodules file after the fact, but the ideal is to do it in advance rather than afterwards.
Quoted 3 lines
Quoted 1 line
Ok, who can setup a git mirror for the QEMU repo?
That would be Jeff or Stefan (cc'd).
Please let me know when you're ready and I'll set up a git mirror.
Your commit can be merged as normal and then I'll send another one updating it to a git.qemu.org mirror.
Stefan
Re: [Qemu-devel] [PULL 33/34] roms: Add OpenSBI version 0.3
Quoted 15 lines · Stefan Hajnoczi
Quoted 13 lines · Peter Maydell
Quoted 12 lines · Alistair Francis
Quoted 9 lines · Peter Maydell
Quoted 1 line · Palmer Dabbelt
From: Alistair Francis <[email protected]>
Also, new git modules in .gitmodules should be qemu.org URLs, not random external ones. (ie, we should set up mirroring of any new external repo we start shipping code and binaries for). We can set this up and fix up the gitmodules file after the fact, but the ideal is to do it in advance rather than afterwards.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Ok, who can setup a git mirror for the QEMU repo?
That would be Jeff or Stefan (cc'd).
Please let me know when you're ready and I'll set up a git mirror.
I'm ready whenever. We have a long weekend here so I'll be back at work on Monday and send the new version of the patch with version 0.4 of OpenSBI.
Quoted 3 lines
Your commit can be merged as normal and then I'll send another one updating it to a git.qemu.org mirror.
Works for me. If the mirror is setup by Monday I will use it in the first commit as well.
Thanks for helping with this Stefan
Alistair
Quoted 2 lines
Stefan
[Qemu-devel] [PULL 16/34] target/riscv: Set privledge spec 1.11.0 as default
In reply to Palmer DabbeltFrom: Alistair Francis <[email protected]>
Set the priv spec version 1.11.0 as the default and allow selecting it via the command line.
--- target/riscv/cpu.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
target/riscv/cpu.c +5 -3
@@ -111,7 +111,7 @@ static void riscv_any_cpu_init(Object *obj) {CPURISCVState *env = &RISCV_CPU (obj)->env;set_misa (env,RVXLEN |RVI |RVM |RVA |RVF |RVD |RVC |RVU ); -set_versions (env,USER_VERSION_2_02_0 ,PRIV_VERSION_1_10_0 ); +set_versions (env,USER_VERSION_2_02_0 ,PRIV_VERSION_1_11_0 );set_resetvec (env,DEFAULT_RSTVEC ); }
@@ -316,7 +316,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)RISCVCPU *cpu =RISCV_CPU (dev);CPURISCVState *env = &cpu->env;RISCVCPUClass *mcc =RISCV_CPU_GET_CLASS (dev); -int priv_version =PRIV_VERSION_1_10_0 ; +int priv_version =PRIV_VERSION_1_11_0 ;int user_version =USER_VERSION_2_02_0 ;target_ulong target_misa =0 ;Error *local_err =NULL ;
@@ -328,7 +328,9 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) }if (cpu->cfg.priv_spec) { -if (!g_strcmp0 (cpu->cfg.priv_spec,"v1.10.0" )) { +if (!g_strcmp0 (cpu->cfg.priv_spec,"v1.11.0" )) { + priv_version =PRIV_VERSION_1_11_0 ; + }else if (!g_strcmp0 (cpu->cfg.priv_spec,"v1.10.0" )) { priv_version =PRIV_VERSION_1_10_0 ; }else if (!g_strcmp0 (cpu->cfg.priv_spec,"v1.9.1" )) { priv_version =PRIV_VERSION_1_09_1 ;
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 24/34] RISC-V: Update syscall list for 32-bit support.
In reply to Palmer DabbeltFrom: Jim Wilson <[email protected]>
32-bit RISC-V uses _llseek instead of lseek as syscall number 62. Update syscall list from open-embedded build, primarily because 32-bit RISC-V requires statx support.
Tested with cross gcc testsuite runs for rv32 and rv64, with the pending statx patch also applied.
--- linux-user/riscv/syscall_nr.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
linux-user/riscv/syscall_nr.h +14 -1
@@ -72,7 +72,11 @@#define TARGET_NR_pipe2 59#define TARGET_NR_quotactl 60#define TARGET_NR_getdents64 61 +#ifdef TARGET_RISCV32 +#define TARGET_NR__llseek 62 +#else #define TARGET_NR_lseek 62 +#endif #define TARGET_NR_read 63#define TARGET_NR_write 64#define TARGET_NR_readv 65
@@ -286,7 +290,16 @@#define TARGET_NR_membarrier 283#define TARGET_NR_mlock2 284#define TARGET_NR_copy_file_range 285 +#define TARGET_NR_preadv2 286 +#define TARGET_NR_pwritev2 287 +#define TARGET_NR_pkey_mprotect 288 +#define TARGET_NR_pkey_alloc 289 +#define TARGET_NR_pkey_free 290 +#define TARGET_NR_statx 291 +#define TARGET_NR_io_pgetevents 292 +#define TARGET_NR_rseq 293 +#define TARGET_NR_kexec_file_load 294 -#define TARGET_NR_syscalls (TARGET_NR_copy_file_range + 1) +#define TARGET_NR_syscalls (TARGET_NR_kexec_file_load + 1)#endif
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 25/34] riscv: virt: Add cpu-topology DT node.
In reply to Palmer DabbeltFrom: Atish Patra <[email protected]>
Currently, there is no cpu topology defined in RISC-V. Define a device tree node that clearly describes the entire topology. This saves the trouble of scanning individual cache to figure out the topology.
Here is the linux kernel patch series that enables topology for RISC-V.
http://lists.infradead.org/pipermail/linux-riscv/2019-June/005072.html
CPU topology after applying this patch in QEMU & above series in kernel
/ # cat /sys/devices/system/cpu/cpu2/topology/thread_siblings_list 2
/ # cat /sys/devices/system/cpu/cpu2/topology/physical_package_id 0
/ # cat /sys/devices/system/cpu/cpu2/topology/core_siblings_list 0-7
--- hw/riscv/virt.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
hw/riscv/virt.c +20 -2
@@ -191,6 +191,7 @@ static void *create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,for (cpu = s->soc.num_harts -1 ; cpu >=0 ; cpu--) {int cpu_phandle = phandle++; +int intc_phandle; nodename =g_strdup_printf ("/cpus/cpu@%d" , cpu);char *intc =g_strdup_printf ("/cpus/cpu@%d/interrupt-controller" , cpu);char *isa =riscv_isa_string (&s->soc.harts[cpu]);
@@ -203,9 +204,12 @@ static void *create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,qemu_fdt_setprop_string (fdt, nodename,"status" ,"okay" );qemu_fdt_setprop_cell (fdt, nodename,"reg" , cpu);qemu_fdt_setprop_string (fdt, nodename,"device_type" ,"cpu" ); +qemu_fdt_setprop_cell (fdt, nodename,"phandle" , cpu_phandle); +qemu_fdt_setprop_cell (fdt, nodename,"linux,phandle" , cpu_phandle); + intc_phandle = phandle++;qemu_fdt_add_subnode (fdt, intc); -qemu_fdt_setprop_cell (fdt, intc,"phandle" , cpu_phandle); -qemu_fdt_setprop_cell (fdt, intc,"linux,phandle" , cpu_phandle); +qemu_fdt_setprop_cell (fdt, intc,"phandle" , intc_phandle); +qemu_fdt_setprop_cell (fdt, intc,"linux,phandle" , intc_phandle);qemu_fdt_setprop_string (fdt, intc,"compatible" ,"riscv,cpu-intc" );qemu_fdt_setprop (fdt, intc,"interrupt-controller" ,NULL ,0 );qemu_fdt_setprop_cell (fdt, intc,"#interrupt-cells" ,1 );
@@ -214,6 +218,20 @@ static void *create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,g_free (nodename); } +/* Add cpu-topology node */ +qemu_fdt_add_subnode (fdt,"/cpus/cpu-map" ); +qemu_fdt_add_subnode (fdt,"/cpus/cpu-map/cluster0" ); +for (cpu = s->soc.num_harts -1 ; cpu >=0 ; cpu--) { +char *core_nodename =g_strdup_printf ("/cpus/cpu-map/cluster0/core%d" , + cpu); +char *cpu_nodename =g_strdup_printf ("/cpus/cpu@%d" , cpu); +uint32_t intc_phandle =qemu_fdt_get_phandle (fdt, cpu_nodename); +qemu_fdt_add_subnode (fdt, core_nodename); +qemu_fdt_setprop_cell (fdt, core_nodename,"cpu" , intc_phandle); +g_free (core_nodename); +g_free (cpu_nodename); + } + cells =g_new0 (uint32_t, s->soc.num_harts *4 );for (cpu =0 ; cpu < s->soc.num_harts; cpu++) { nodename =
Signature · 1 line
2.21.0
[Qemu-devel] [PULL 30/34] hw/riscv: Split out the boot functions
In reply to Palmer DabbeltFrom: Alistair Francis <[email protected]>
Split the common RISC-V boot functions into a seperate file. This allows us to share the common code.
--- hw/riscv/Makefile.objs | 1 + hw/riscv/boot.c | 69 +++++++++++++++++++++++++++++++++++++++++ hw/riscv/sifive_e.c | 17 ++-------- hw/riscv/sifive_u.c | 17 ++-------- hw/riscv/spike.c | 21 +++---------- hw/riscv/virt.c | 51 +++--------------------------- include/hw/riscv/boot.h | 27 ++++++++++++++++ 7 files changed, 110 insertions(+), 93 deletions(-) create mode 100644 hw/riscv/boot.c create mode 100644 include/hw/riscv/boot.h
hw/riscv/Makefile.objs +1 -0
@@ -1,3 +1,4 @@ +obj-y += boot.o obj-$(CONFIG_SPIKE) += riscv_htif.o obj-$(CONFIG_HART) += riscv_hart.o obj-$(CONFIG_SIFIVE_E) += sifive_e.o
hw/riscv/boot.c new file +69 -0
69 lines not on this page · raw message
hw/riscv/sifive_e.c +2 -15
@@ -44,10 +44,10 @@#include "hw/riscv/sifive_prci.h" #include "hw/riscv/sifive_uart.h" #include "hw/riscv/sifive_e.h" +#include "hw/riscv/boot.h" #include "chardev/char.h" #include "sysemu/arch_init.h" #include "exec/address-spaces.h" -#include "elf.h" static const struct MemmapEntry { hwaddr base;
@@ -74,19 +74,6 @@ static const struct MemmapEntry { [SIFIVE_E_DTIM] = { 0x80000000, 0x4000 } }; -static target_ulong load_kernel (const char *kernel_filename) -{ -uint64_t kernel_entry, kernel_high; - -if (load_elf (kernel_filename,NULL ,NULL ,NULL , - &kernel_entry,NULL , &kernel_high, -0 ,EM_RISCV ,1 ,0 ) <0 ) { -error_report ("could not load kernel '%s'" , kernel_filename); -exit (1 ); - } -return kernel_entry; -} -static void sifive_mmio_emulate (MemoryRegion *parent,const char *name,uintptr_t offset,uintptr_t length) {
@@ -131,7 +118,7 @@ static void riscv_sifive_e_init(MachineState *machine) memmap[SIFIVE_E_MROM].base, &address_space_memory);if (machine->kernel_filename) { -load_kernel (machine->kernel_filename); +riscv_load_kernel (machine->kernel_filename); } }
hw/riscv/sifive_u.c +2 -15
@@ -41,11 +41,11 @@#include "hw/riscv/sifive_uart.h" #include "hw/riscv/sifive_prci.h" #include "hw/riscv/sifive_u.h" +#include "hw/riscv/boot.h" #include "chardev/char.h" #include "sysemu/arch_init.h" #include "sysemu/device_tree.h" #include "exec/address-spaces.h" -#include "elf.h" #include <libfdt.h>
@@ -65,19 +65,6 @@ static const struct MemmapEntry {#define GEM_REVISION 0x10070109 -static target_ulong load_kernel (const char *kernel_filename) -{ -uint64_t kernel_entry, kernel_high; - -if (load_elf (kernel_filename,NULL ,NULL ,NULL , - &kernel_entry,NULL , &kernel_high, -0 ,EM_RISCV ,1 ,0 ) <0 ) { -error_report ("could not load kernel '%s'" , kernel_filename); -exit (1 ); - } -return kernel_entry; -} -static void create_fdt (SiFiveUState *s,const struct MemmapEntry *memmap,uint64_t mem_size,const char *cmdline) {
@@ -283,7 +270,7 @@ static void riscv_sifive_u_init(MachineState *machine)create_fdt (s, memmap, machine->ram_size, machine->kernel_cmdline);if (machine->kernel_filename) { -load_kernel (machine->kernel_filename); +riscv_load_kernel (machine->kernel_filename); }/* reset vector */
hw/riscv/spike.c +4 -17
@@ -36,12 +36,12 @@#include "hw/riscv/riscv_hart.h" #include "hw/riscv/sifive_clint.h" #include "hw/riscv/spike.h" +#include "hw/riscv/boot.h" #include "chardev/char.h" #include "sysemu/arch_init.h" #include "sysemu/device_tree.h" #include "sysemu/qtest.h" #include "exec/address-spaces.h" -#include "elf.h" #include <libfdt.h>
@@ -54,19 +54,6 @@ static const struct MemmapEntry { [SPIKE_DRAM] = { 0x80000000, 0x0 }, }; -static target_ulong load_kernel (const char *kernel_filename) -{ -uint64_t kernel_entry, kernel_high; - -if (load_elf_ram_sym (kernel_filename,NULL ,NULL ,NULL , - &kernel_entry,NULL , &kernel_high,0 ,EM_RISCV ,1 ,0 , -NULL , true, htif_symbol_callback) <0 ) { -error_report ("could not load kernel '%s'" , kernel_filename); -exit (1 ); - } -return kernel_entry; -} -static void create_fdt (SpikeState *s,const struct MemmapEntry *memmap,uint64_t mem_size,const char *cmdline) {
@@ -199,7 +186,7 @@ static void spike_board_init(MachineState *machine) mask_rom);if (machine->kernel_filename) { -load_kernel (machine->kernel_filename); +riscv_load_kernel (machine->kernel_filename); }/* reset vector */
@@ -287,7 +274,7 @@ static void spike_v1_10_0_board_init(MachineState *machine) mask_rom);if (machine->kernel_filename) { -load_kernel (machine->kernel_filename); +riscv_load_kernel (machine->kernel_filename); }/* reset vector */
@@ -372,7 +359,7 @@ static void spike_v1_09_1_board_init(MachineState *machine) mask_rom);if (machine->kernel_filename) { -load_kernel (machine->kernel_filename); +riscv_load_kernel (machine->kernel_filename); }/* reset vector */
hw/riscv/virt.c +5 -46
78 lines not on this page · raw message
include/hw/riscv/boot.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* QEMU RISC-V Boot Helper +* +* Copyright (c) 2017 SiFive, Inc. +* Copyright (c) 2019 Alistair Francis <[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 RISCV_BOOT_H +#define RISCV_BOOT_H + +target_ulong riscv_load_kernel (const char *kernel_filename); +hwaddr riscv_load_initrd (const char *filename,uint64_t mem_size, +uint64_t kernel_entry,hwaddr *start); + +#endif /* RISCV_BOOT_H */
Signature · 1 line
2.21.0