1
The following changes since commit c95bd5ff1660883d15ad6e0005e4c8571604f51a:
1
From: Alistair Francis <alistair.francis@wdc.com>
2
2
3
Merge remote-tracking branch 'remotes/philmd/tags/mips-fixes-20210322' into staging (2021-03-22 14:26:13 +0000)
3
The following changes since commit 3757b0d08b399c609954cf57f273b1167e5d7a8d:
4
5
Merge tag 'pull-request-2022-05-18' of https://gitlab.com/thuth/qemu into staging (2022-05-20 08:04:30 -0700)
4
6
5
are available in the Git repository at:
7
are available in the Git repository at:
6
8
7
git@github.com:alistair23/qemu.git tags/pull-riscv-to-apply-20210322-2
9
git@github.com:alistair23/qemu.git tags/pull-riscv-to-apply-20220525
8
10
9
for you to fetch changes up to 9a27f69bd668d9d71674407badc412ce1231c7d5:
11
for you to fetch changes up to 8fe63fe8e512d77583d6798acd2164f1fa1e40ab:
10
12
11
target/riscv: Prevent lost illegal instruction exceptions (2021-03-22 21:54:40 -0400)
13
hw/core: loader: Set is_linux to true for VxWorks uImage (2022-05-24 10:38:50 +1000)
12
14
13
----------------------------------------------------------------
15
----------------------------------------------------------------
14
RISC-V PR for 6.0
16
Third RISC-V PR for QEMU 7.1
15
17
16
This PR includes:
18
* Fixes for accessing VS hypervisor CSRs
17
- Fix for vector CSR access
19
* Improvements for RISC-V Vector extension
18
- Improvements to the Ibex UART device
20
* Fixes for accessing mtimecmp
19
- PMP improvements and bug fixes
21
* Add new short-isa-string CPU option
20
- Hypervisor extension bug fixes
22
* Improvements to RISC-V machine error handling
21
- ramfb support for the virt machine
23
* Disable the "G" extension by default internally, no functional change
22
- Fast read support for SST flash
24
* Enforce floating point extension requirements
23
- Improvements to the microchip_pfsoc machine
25
* Cleanup ISA extension checks
26
* Resolve redundant property accessors
27
* Fix typo of mimpid cpu option
28
* Improvements for virtulisation
29
* Add zicsr/zifencei to isa_string
30
* Support for VxWorks uImage
24
31
25
----------------------------------------------------------------
32
----------------------------------------------------------------
26
Alexander Wagner (1):
33
Anup Patel (4):
27
hw/char: disable ibex uart receive if the buffer is full
34
target/riscv: Fix csr number based privilege checking
35
target/riscv: Fix hstatus.GVA bit setting for traps taken from HS-mode
36
target/riscv: Set [m|s]tval for both illegal and virtual instruction traps
37
hw/riscv: virt: Fix interrupt parent for dynamic platform devices
28
38
29
Asherah Connor (2):
39
Atish Patra (1):
30
hw/riscv: Add fw_cfg support to virt
40
hw/intc: Pass correct hartid while updating mtimecmp
31
hw/riscv: allow ramfb on virt
32
41
33
Bin Meng (3):
42
Bernhard Beschow (2):
34
hw/block: m25p80: Support fast read for SST flashes
43
hw/vfio/pci-quirks: Resolve redundant property getters
35
hw/riscv: microchip_pfsoc: Map EMMC/SD mux register
44
hw/riscv/sifive_u: Resolve redundant property accessors
36
docs/system: riscv: Add documentation for 'microchip-icicle-kit' machine
45
46
Bin Meng (2):
47
hw/core: Sync uboot_image.h from U-Boot v2022.01
48
hw/core: loader: Set is_linux to true for VxWorks uImage
49
50
Dylan Reid (1):
51
target/riscv: Fix VS mode hypervisor CSR access
37
52
38
Frank Chang (1):
53
Frank Chang (1):
39
target/riscv: fix vs() to return proper error code
54
target/riscv: Fix typo of mimpid cpu option
40
55
41
Georg Kotheimer (6):
56
Hongren (Zenithal) Zheng (1):
42
target/riscv: Adjust privilege level for HLV(X)/HSV instructions
57
target/riscv: add zicsr/zifencei to isa_string
43
target/riscv: Make VSTIP and VSEIP read-only in hip
44
target/riscv: Use background registers also for MSTATUS_MPV
45
target/riscv: Fix read and write accesses to vsip and vsie
46
target/riscv: Add proper two-stage lookup exception detection
47
target/riscv: Prevent lost illegal instruction exceptions
48
58
49
Jim Shu (3):
59
Tsukasa OI (9):
50
target/riscv: propagate PMP permission to TLB page
60
target/riscv: Move Zhinx* extensions on ISA string
51
target/riscv: add log of PMP permission checking
61
target/riscv: Add short-isa-string option
52
target/riscv: flush TLB pages if PMP permission has been changed
62
hw/riscv: Make CPU config error handling generous (virt/spike)
63
hw/riscv: Make CPU config error handling generous (sifive_e/u/opentitan)
64
target/riscv: Fix coding style on "G" expansion
65
target/riscv: Disable "G" by default
66
target/riscv: Change "G" expansion
67
target/riscv: FP extension requirements
68
target/riscv: Move/refactor ISA extension checks
53
69
54
docs/system/riscv/microchip-icicle-kit.rst | 89 ++++++++++++++
70
Weiwei Li (1):
55
docs/system/target-riscv.rst | 1 +
71
target/riscv: check 'I' and 'E' after checking 'G' in riscv_cpu_realize
56
include/hw/char/ibex_uart.h | 4 +
57
include/hw/riscv/microchip_pfsoc.h | 1 +
58
include/hw/riscv/virt.h | 2 +
59
target/riscv/cpu.h | 4 +
60
target/riscv/pmp.h | 4 +-
61
hw/block/m25p80.c | 3 +
62
hw/char/ibex_uart.c | 23 +++-
63
hw/riscv/microchip_pfsoc.c | 6 +
64
hw/riscv/virt.c | 33 ++++++
65
target/riscv/cpu.c | 1 +
66
target/riscv/cpu_helper.c | 144 +++++++++++++++--------
67
target/riscv/csr.c | 77 +++++++------
68
target/riscv/pmp.c | 84 ++++++++++----
69
target/riscv/translate.c | 179 +----------------------------
70
hw/riscv/Kconfig | 1 +
71
17 files changed, 367 insertions(+), 289 deletions(-)
72
create mode 100644 docs/system/riscv/microchip-icicle-kit.rst
73
72
73
eopXD (1):
74
target/riscv: rvv: Fix early exit condition for whole register load/store
75
76
hw/core/uboot_image.h | 213 +++++++++++++++++++++-----------
77
target/riscv/cpu.h | 12 +-
78
hw/core/loader.c | 15 +++
79
hw/intc/riscv_aclint.c | 3 +-
80
hw/riscv/opentitan.c | 2 +-
81
hw/riscv/sifive_e.c | 2 +-
82
hw/riscv/sifive_u.c | 28 +----
83
hw/riscv/spike.c | 2 +-
84
hw/riscv/virt.c | 27 ++--
85
hw/vfio/pci-quirks.c | 34 ++---
86
target/riscv/cpu.c | 91 ++++++++++----
87
target/riscv/cpu_helper.c | 4 +-
88
target/riscv/csr.c | 26 ++--
89
target/riscv/translate.c | 17 ++-
90
target/riscv/insn_trans/trans_rvv.c.inc | 58 +++++----
91
15 files changed, 325 insertions(+), 209 deletions(-)
diff view generated by jsdifflib
1
From: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
1
From: Dylan Reid <dylan@rivosinc.com>
2
2
3
The previous implementation was broken in many ways:
3
VS mode access to hypervisor CSRs should generate virtual, not illegal,
4
- Used mideleg instead of hideleg to mask accesses
4
instruction exceptions.
5
- Used MIP_VSSIP instead of VS_MODE_INTERRUPTS to mask writes to vsie
6
- Did not shift between S bits and VS bits (VSEIP <-> SEIP, ...)
7
5
8
Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
6
Don't return early and indicate an illegal instruction exception when
7
accessing a hypervisor CSR from VS mode. Instead, fall through to the
8
`hmode` predicate to return the correct virtual instruction exception.
9
10
Signed-off-by: Dylan Reid <dgreid@rivosinc.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Message-id: 20210311094738.1376795-1-georg.kotheimer@kernkonzept.com
12
Message-Id: <20220506165456.297058-1-dgreid@rivosinc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
14
---
13
target/riscv/csr.c | 68 +++++++++++++++++++++++-----------------------
15
target/riscv/csr.c | 10 +++++-----
14
1 file changed, 34 insertions(+), 34 deletions(-)
16
1 file changed, 5 insertions(+), 5 deletions(-)
15
17
16
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
18
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
17
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
18
--- a/target/riscv/csr.c
20
--- a/target/riscv/csr.c
19
+++ b/target/riscv/csr.c
21
+++ b/target/riscv/csr.c
20
@@ -XXX,XX +XXX,XX @@ static int write_sstatus(CPURISCVState *env, int csrno, target_ulong val)
22
@@ -XXX,XX +XXX,XX @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env,
21
return write_mstatus(env, CSR_MSTATUS, newval);
23
#if !defined(CONFIG_USER_ONLY)
22
}
24
int effective_priv = env->priv;
23
25
24
+static int read_vsie(CPURISCVState *env, int csrno, target_ulong *val)
26
- if (riscv_has_ext(env, RVH) &&
25
+{
27
- env->priv == PRV_S &&
26
+ /* Shift the VS bits to their S bit location in vsie */
28
- !riscv_cpu_virt_enabled(env)) {
27
+ *val = (env->mie & env->hideleg & VS_MODE_INTERRUPTS) >> 1;
29
+ if (riscv_has_ext(env, RVH) && env->priv == PRV_S) {
28
+ return 0;
30
/*
29
+}
31
- * We are in S mode without virtualisation, therefore we are in HS Mode.
30
+
32
+ * We are in either HS or VS mode.
31
static int read_sie(CPURISCVState *env, int csrno, target_ulong *val)
33
* Add 1 to the effective privledge level to allow us to access the
32
{
34
- * Hypervisor CSRs.
33
if (riscv_cpu_virt_enabled(env)) {
35
+ * Hypervisor CSRs. The `hmode` predicate will determine if access
34
- /* Tell the guest the VS bits, shifted to the S bit locations */
36
+ * should be allowed(HS) or if a virtual instruction exception should be
35
- *val = (env->mie & env->mideleg & VS_MODE_INTERRUPTS) >> 1;
37
+ * raised(VS).
36
+ read_vsie(env, CSR_VSIE, val);
38
*/
37
} else {
39
effective_priv++;
38
*val = env->mie & env->mideleg;
39
}
40
}
40
return 0;
41
}
42
43
-static int write_sie(CPURISCVState *env, int csrno, target_ulong val)
44
+static int write_vsie(CPURISCVState *env, int csrno, target_ulong val)
45
{
46
- target_ulong newval;
47
+ /* Shift the S bits to their VS bit location in mie */
48
+ target_ulong newval = (env->mie & ~VS_MODE_INTERRUPTS) |
49
+ ((val << 1) & env->hideleg & VS_MODE_INTERRUPTS);
50
+ return write_mie(env, CSR_MIE, newval);
51
+}
52
53
+static int write_sie(CPURISCVState *env, int csrno, target_ulong val)
54
+{
55
if (riscv_cpu_virt_enabled(env)) {
56
- /* Shift the guests S bits to VS */
57
- newval = (env->mie & ~VS_MODE_INTERRUPTS) |
58
- ((val << 1) & VS_MODE_INTERRUPTS);
59
+ write_vsie(env, CSR_VSIE, val);
60
} else {
61
- newval = (env->mie & ~S_MODE_INTERRUPTS) | (val & S_MODE_INTERRUPTS);
62
+ target_ulong newval = (env->mie & ~S_MODE_INTERRUPTS) |
63
+ (val & S_MODE_INTERRUPTS);
64
+ write_mie(env, CSR_MIE, newval);
65
}
66
67
- return write_mie(env, CSR_MIE, newval);
68
+ return 0;
69
}
70
71
static int read_stvec(CPURISCVState *env, int csrno, target_ulong *val)
72
@@ -XXX,XX +XXX,XX @@ static int write_sbadaddr(CPURISCVState *env, int csrno, target_ulong val)
73
return 0;
74
}
75
76
+static int rmw_vsip(CPURISCVState *env, int csrno, target_ulong *ret_value,
77
+ target_ulong new_value, target_ulong write_mask)
78
+{
79
+ /* Shift the S bits to their VS bit location in mip */
80
+ int ret = rmw_mip(env, 0, ret_value, new_value << 1,
81
+ (write_mask << 1) & vsip_writable_mask & env->hideleg);
82
+ *ret_value &= VS_MODE_INTERRUPTS;
83
+ /* Shift the VS bits to their S bit location in vsip */
84
+ *ret_value >>= 1;
85
+ return ret;
86
+}
87
+
88
static int rmw_sip(CPURISCVState *env, int csrno, target_ulong *ret_value,
89
target_ulong new_value, target_ulong write_mask)
90
{
91
int ret;
92
93
if (riscv_cpu_virt_enabled(env)) {
94
- /* Shift the new values to line up with the VS bits */
95
- ret = rmw_mip(env, CSR_MSTATUS, ret_value, new_value << 1,
96
- (write_mask & sip_writable_mask) << 1 & env->mideleg);
97
- ret &= vsip_writable_mask;
98
- ret >>= 1;
99
+ ret = rmw_vsip(env, CSR_VSIP, ret_value, new_value, write_mask);
100
} else {
101
ret = rmw_mip(env, CSR_MSTATUS, ret_value, new_value,
102
write_mask & env->mideleg & sip_writable_mask);
103
@@ -XXX,XX +XXX,XX @@ static int write_vsstatus(CPURISCVState *env, int csrno, target_ulong val)
104
return 0;
105
}
106
107
-static int rmw_vsip(CPURISCVState *env, int csrno, target_ulong *ret_value,
108
- target_ulong new_value, target_ulong write_mask)
109
-{
110
- int ret = rmw_mip(env, 0, ret_value, new_value,
111
- write_mask & env->mideleg & vsip_writable_mask);
112
- return ret;
113
-}
114
-
115
-static int read_vsie(CPURISCVState *env, int csrno, target_ulong *val)
116
-{
117
- *val = env->mie & env->mideleg & VS_MODE_INTERRUPTS;
118
- return 0;
119
-}
120
-
121
-static int write_vsie(CPURISCVState *env, int csrno, target_ulong val)
122
-{
123
- target_ulong newval = (env->mie & ~env->mideleg) | (val & env->mideleg & MIP_VSSIP);
124
- return write_mie(env, CSR_MIE, newval);
125
-}
126
-
127
static int read_vstvec(CPURISCVState *env, int csrno, target_ulong *val)
128
{
129
*val = env->vstvec;
130
--
41
--
131
2.30.1
42
2.35.3
132
133
diff view generated by jsdifflib
New patch
1
From: eopXD <eop.chen@sifive.com>
1
2
3
Vector whole register load instructions have EEW encoded in the opcode,
4
so we shouldn't take SEW here. Vector whole register store instructions
5
are always EEW=8.
6
7
Signed-off-by: eop Chen <eop.chen@sifive.com>
8
Reviewed-by: Frank Chang <frank.chang@sifive.com>
9
Acked-by: Alistair Francis <alistair.francis@wdc.com>
10
Message-Id: <165181414065.18540.14828125053334599921-0@git.sr.ht>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
13
target/riscv/insn_trans/trans_rvv.c.inc | 58 +++++++++++++------------
14
1 file changed, 31 insertions(+), 27 deletions(-)
15
16
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
17
index XXXXXXX..XXXXXXX 100644
18
--- a/target/riscv/insn_trans/trans_rvv.c.inc
19
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
20
@@ -XXX,XX +XXX,XX @@ GEN_VEXT_TRANS(vle64ff_v, MO_64, r2nfvm, ldff_op, ld_us_check)
21
typedef void gen_helper_ldst_whole(TCGv_ptr, TCGv, TCGv_env, TCGv_i32);
22
23
static bool ldst_whole_trans(uint32_t vd, uint32_t rs1, uint32_t nf,
24
- gen_helper_ldst_whole *fn, DisasContext *s,
25
- bool is_store)
26
+ uint32_t width, gen_helper_ldst_whole *fn,
27
+ DisasContext *s, bool is_store)
28
{
29
- uint32_t evl = (s->cfg_ptr->vlen / 8) * nf / (1 << s->sew);
30
+ uint32_t evl = (s->cfg_ptr->vlen / 8) * nf / width;
31
TCGLabel *over = gen_new_label();
32
tcg_gen_brcondi_tl(TCG_COND_GEU, cpu_vstart, evl, over);
33
34
@@ -XXX,XX +XXX,XX @@ static bool ldst_whole_trans(uint32_t vd, uint32_t rs1, uint32_t nf,
35
* load and store whole register instructions ignore vtype and vl setting.
36
* Thus, we don't need to check vill bit. (Section 7.9)
37
*/
38
-#define GEN_LDST_WHOLE_TRANS(NAME, ARG_NF, IS_STORE) \
39
+#define GEN_LDST_WHOLE_TRANS(NAME, ARG_NF, WIDTH, IS_STORE) \
40
static bool trans_##NAME(DisasContext *s, arg_##NAME * a) \
41
{ \
42
if (require_rvv(s) && \
43
QEMU_IS_ALIGNED(a->rd, ARG_NF)) { \
44
- return ldst_whole_trans(a->rd, a->rs1, ARG_NF, gen_helper_##NAME, \
45
- s, IS_STORE); \
46
+ return ldst_whole_trans(a->rd, a->rs1, ARG_NF, WIDTH, \
47
+ gen_helper_##NAME, s, IS_STORE); \
48
} \
49
return false; \
50
}
51
52
-GEN_LDST_WHOLE_TRANS(vl1re8_v, 1, false)
53
-GEN_LDST_WHOLE_TRANS(vl1re16_v, 1, false)
54
-GEN_LDST_WHOLE_TRANS(vl1re32_v, 1, false)
55
-GEN_LDST_WHOLE_TRANS(vl1re64_v, 1, false)
56
-GEN_LDST_WHOLE_TRANS(vl2re8_v, 2, false)
57
-GEN_LDST_WHOLE_TRANS(vl2re16_v, 2, false)
58
-GEN_LDST_WHOLE_TRANS(vl2re32_v, 2, false)
59
-GEN_LDST_WHOLE_TRANS(vl2re64_v, 2, false)
60
-GEN_LDST_WHOLE_TRANS(vl4re8_v, 4, false)
61
-GEN_LDST_WHOLE_TRANS(vl4re16_v, 4, false)
62
-GEN_LDST_WHOLE_TRANS(vl4re32_v, 4, false)
63
-GEN_LDST_WHOLE_TRANS(vl4re64_v, 4, false)
64
-GEN_LDST_WHOLE_TRANS(vl8re8_v, 8, false)
65
-GEN_LDST_WHOLE_TRANS(vl8re16_v, 8, false)
66
-GEN_LDST_WHOLE_TRANS(vl8re32_v, 8, false)
67
-GEN_LDST_WHOLE_TRANS(vl8re64_v, 8, false)
68
-
69
-GEN_LDST_WHOLE_TRANS(vs1r_v, 1, true)
70
-GEN_LDST_WHOLE_TRANS(vs2r_v, 2, true)
71
-GEN_LDST_WHOLE_TRANS(vs4r_v, 4, true)
72
-GEN_LDST_WHOLE_TRANS(vs8r_v, 8, true)
73
+GEN_LDST_WHOLE_TRANS(vl1re8_v, 1, 1, false)
74
+GEN_LDST_WHOLE_TRANS(vl1re16_v, 1, 2, false)
75
+GEN_LDST_WHOLE_TRANS(vl1re32_v, 1, 4, false)
76
+GEN_LDST_WHOLE_TRANS(vl1re64_v, 1, 8, false)
77
+GEN_LDST_WHOLE_TRANS(vl2re8_v, 2, 1, false)
78
+GEN_LDST_WHOLE_TRANS(vl2re16_v, 2, 2, false)
79
+GEN_LDST_WHOLE_TRANS(vl2re32_v, 2, 4, false)
80
+GEN_LDST_WHOLE_TRANS(vl2re64_v, 2, 8, false)
81
+GEN_LDST_WHOLE_TRANS(vl4re8_v, 4, 1, false)
82
+GEN_LDST_WHOLE_TRANS(vl4re16_v, 4, 2, false)
83
+GEN_LDST_WHOLE_TRANS(vl4re32_v, 4, 4, false)
84
+GEN_LDST_WHOLE_TRANS(vl4re64_v, 4, 8, false)
85
+GEN_LDST_WHOLE_TRANS(vl8re8_v, 8, 1, false)
86
+GEN_LDST_WHOLE_TRANS(vl8re16_v, 8, 2, false)
87
+GEN_LDST_WHOLE_TRANS(vl8re32_v, 8, 4, false)
88
+GEN_LDST_WHOLE_TRANS(vl8re64_v, 8, 8, false)
89
+
90
+/*
91
+ * The vector whole register store instructions are encoded similar to
92
+ * unmasked unit-stride store of elements with EEW=8.
93
+ */
94
+GEN_LDST_WHOLE_TRANS(vs1r_v, 1, 1, true)
95
+GEN_LDST_WHOLE_TRANS(vs2r_v, 2, 1, true)
96
+GEN_LDST_WHOLE_TRANS(vs4r_v, 4, 1, true)
97
+GEN_LDST_WHOLE_TRANS(vs8r_v, 8, 1, true)
98
99
/*
100
*** Vector Integer Arithmetic Instructions
101
--
102
2.35.3
diff view generated by jsdifflib
1
From: Jim Shu <cwshu@andestech.com>
1
From: Atish Patra <atishp@rivosinc.com>
2
2
3
Like MMU translation, add qemu log of PMP permission checking for
3
timecmp update function should be invoked with hartid for which
4
debugging.
4
timecmp is being updated. The following patch passes the incorrect
5
hartid to the update function.
5
6
6
Signed-off-by: Jim Shu <cwshu@andestech.com>
7
Fixes: e2f01f3c2e13 ("hw/intc: Make RISC-V ACLINT mtime MMIO register writable")
8
9
Signed-off-by: Atish Patra <atishp@rivosinc.com>
10
Reviewed-by: Frank Chang <frank.chang@sifive.com>
11
Reviewed-by: Anup Patel <anup@brainfault.org>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
12
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Message-id: 1613916082-19528-3-git-send-email-cwshu@andestech.com
13
Message-Id: <20220513221458.1192933-1-atishp@rivosinc.com>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
---
15
---
11
target/riscv/cpu_helper.c | 12 ++++++++++++
16
hw/intc/riscv_aclint.c | 3 ++-
12
1 file changed, 12 insertions(+)
17
1 file changed, 2 insertions(+), 1 deletion(-)
13
18
14
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
19
diff --git a/hw/intc/riscv_aclint.c b/hw/intc/riscv_aclint.c
15
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
16
--- a/target/riscv/cpu_helper.c
21
--- a/hw/intc/riscv_aclint.c
17
+++ b/target/riscv/cpu_helper.c
22
+++ b/hw/intc/riscv_aclint.c
18
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
23
@@ -XXX,XX +XXX,XX @@ static void riscv_aclint_mtimer_write(void *opaque, hwaddr addr,
19
if (ret == TRANSLATE_SUCCESS) {
24
continue;
20
ret = get_physical_address_pmp(env, &prot_pmp, &tlb_size, pa,
21
size, access_type, mode);
22
+
23
+ qemu_log_mask(CPU_LOG_MMU,
24
+ "%s PMP address=" TARGET_FMT_plx " ret %d prot"
25
+ " %d tlb_size " TARGET_FMT_lu "\n",
26
+ __func__, pa, ret, prot_pmp, tlb_size);
27
+
28
prot &= prot_pmp;
29
}
25
}
30
26
riscv_aclint_mtimer_write_timecmp(mtimer, RISCV_CPU(cpu),
31
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
27
- i, env->timecmp);
32
if (ret == TRANSLATE_SUCCESS) {
28
+ mtimer->hartid_base + i,
33
ret = get_physical_address_pmp(env, &prot_pmp, &tlb_size, pa,
29
+ env->timecmp);
34
size, access_type, mode);
35
+
36
+ qemu_log_mask(CPU_LOG_MMU,
37
+ "%s PMP address=" TARGET_FMT_plx " ret %d prot"
38
+ " %d tlb_size " TARGET_FMT_lu "\n",
39
+ __func__, pa, ret, prot_pmp, tlb_size);
40
+
41
prot &= prot_pmp;
42
}
30
}
31
return;
43
}
32
}
44
--
33
--
45
2.30.1
34
2.35.3
46
47
diff view generated by jsdifflib
New patch
1
From: Tsukasa OI <research_trasio@irq.a4lg.com>
1
2
3
This commit moves ISA string conversion for Zhinx and Zhinxmin extensions.
4
Because extension category ordering of "H" is going to be after "V",
5
their ordering is going to be valid (on canonical order).
6
7
Signed-off-by: Tsukasa OI <research_trasio@irq.a4lg.com>
8
Acked-by: Alistair Francis <alistair.francis@wdc.com>
9
Message-Id: <7a988aedb249b6709f9ce5464ff359b60958ca54.1652181972.git.research_trasio@irq.a4lg.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
12
target/riscv/cpu.c | 4 ++--
13
1 file changed, 2 insertions(+), 2 deletions(-)
14
15
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/cpu.c
18
+++ b/target/riscv/cpu.c
19
@@ -XXX,XX +XXX,XX @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)
20
ISA_EDATA_ENTRY(zfh, ext_zfh),
21
ISA_EDATA_ENTRY(zfhmin, ext_zfhmin),
22
ISA_EDATA_ENTRY(zfinx, ext_zfinx),
23
- ISA_EDATA_ENTRY(zhinx, ext_zhinx),
24
- ISA_EDATA_ENTRY(zhinxmin, ext_zhinxmin),
25
ISA_EDATA_ENTRY(zdinx, ext_zdinx),
26
ISA_EDATA_ENTRY(zba, ext_zba),
27
ISA_EDATA_ENTRY(zbb, ext_zbb),
28
@@ -XXX,XX +XXX,XX @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)
29
ISA_EDATA_ENTRY(zkt, ext_zkt),
30
ISA_EDATA_ENTRY(zve32f, ext_zve32f),
31
ISA_EDATA_ENTRY(zve64f, ext_zve64f),
32
+ ISA_EDATA_ENTRY(zhinx, ext_zhinx),
33
+ ISA_EDATA_ENTRY(zhinxmin, ext_zhinxmin),
34
ISA_EDATA_ENTRY(svinval, ext_svinval),
35
ISA_EDATA_ENTRY(svnapot, ext_svnapot),
36
ISA_EDATA_ENTRY(svpbmt, ext_svpbmt),
37
--
38
2.35.3
diff view generated by jsdifflib
1
From: Jim Shu <cwshu@andestech.com>
1
From: Tsukasa OI <research_trasio@irq.a4lg.com>
2
2
3
Currently, PMP permission checking of TLB page is bypassed if TLB hits
3
Because some operating systems don't correctly parse long ISA extension
4
Fix it by propagating PMP permission to TLB page permission.
4
string, this commit adds short-isa-string boolean option to disable
5
generating long ISA extension strings on Device Tree.
5
6
6
PMP permission checking also use MMU-style API to change TLB permission
7
For instance, enabling Zfinx and Zdinx extensions and booting Linux (5.17 or
7
and size.
8
earlier) with FPU support caused a kernel panic.
8
9
9
Signed-off-by: Jim Shu <cwshu@andestech.com>
10
Operating Systems which short-isa-string might be helpful:
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
11
Message-id: 1613916082-19528-2-git-send-email-cwshu@andestech.com
12
1. Linux (5.17 or earlier)
13
2. FreeBSD (at least 14.0-CURRENT)
14
3. OpenBSD (at least current development version)
15
16
Signed-off-by: Tsukasa OI <research_trasio@irq.a4lg.com>
17
Acked-by: Alistair Francis <alistair.francis@wdc.com>
18
Message-Id: <7c1fe5f06b0a7646a47e9bcdddb1042bb60c69c8.1652181972.git.research_trasio@irq.a4lg.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
19
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
20
---
14
target/riscv/pmp.h | 4 +-
21
target/riscv/cpu.h | 2 ++
15
target/riscv/cpu_helper.c | 84 +++++++++++++++++++++++++++++----------
22
target/riscv/cpu.c | 6 +++++-
16
target/riscv/pmp.c | 80 +++++++++++++++++++++++++++----------
23
2 files changed, 7 insertions(+), 1 deletion(-)
17
3 files changed, 125 insertions(+), 43 deletions(-)
18
24
19
diff --git a/target/riscv/pmp.h b/target/riscv/pmp.h
25
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
20
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
21
--- a/target/riscv/pmp.h
27
--- a/target/riscv/cpu.h
22
+++ b/target/riscv/pmp.h
28
+++ b/target/riscv/cpu.h
23
@@ -XXX,XX +XXX,XX @@ void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index,
29
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
24
target_ulong val);
30
bool aia;
25
target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index);
31
bool debug;
26
bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,
32
uint64_t resetvec;
27
- target_ulong size, pmp_priv_t priv, target_ulong mode);
33
+
28
+ target_ulong size, pmp_priv_t privs, pmp_priv_t *allowed_privs,
34
+ bool short_isa_string;
29
+ target_ulong mode);
35
};
30
bool pmp_is_range_in_tlb(CPURISCVState *env, hwaddr tlb_sa,
36
31
target_ulong *tlb_size);
37
typedef struct RISCVCPUConfig RISCVCPUConfig;
32
void pmp_update_rule_addr(CPURISCVState *env, uint32_t pmp_index);
38
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
33
void pmp_update_rule_nums(CPURISCVState *env);
34
uint32_t pmp_get_num_rules(CPURISCVState *env);
35
+int pmp_priv_to_page_prot(pmp_priv_t pmp_priv);
36
37
#endif
38
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
39
index XXXXXXX..XXXXXXX 100644
39
index XXXXXXX..XXXXXXX 100644
40
--- a/target/riscv/cpu_helper.c
40
--- a/target/riscv/cpu.c
41
+++ b/target/riscv/cpu_helper.c
41
+++ b/target/riscv/cpu.c
42
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv)
42
@@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = {
43
env->load_res = -1;
43
DEFINE_PROP_BOOL("x-aia", RISCVCPU, cfg.aia, false),
44
}
44
45
45
DEFINE_PROP_UINT64("resetvec", RISCVCPU, cfg.resetvec, DEFAULT_RSTVEC),
46
+/*
47
+ * get_physical_address_pmp - check PMP permission for this physical address
48
+ *
49
+ * Match the PMP region and check permission for this physical address and it's
50
+ * TLB page. Returns 0 if the permission checking was successful
51
+ *
52
+ * @env: CPURISCVState
53
+ * @prot: The returned protection attributes
54
+ * @tlb_size: TLB page size containing addr. It could be modified after PMP
55
+ * permission checking. NULL if not set TLB page for addr.
56
+ * @addr: The physical address to be checked permission
57
+ * @access_type: The type of MMU access
58
+ * @mode: Indicates current privilege level.
59
+ */
60
+static int get_physical_address_pmp(CPURISCVState *env, int *prot,
61
+ target_ulong *tlb_size, hwaddr addr,
62
+ int size, MMUAccessType access_type,
63
+ int mode)
64
+{
65
+ pmp_priv_t pmp_priv;
66
+ target_ulong tlb_size_pmp = 0;
67
+
46
+
68
+ if (!riscv_feature(env, RISCV_FEATURE_PMP)) {
47
+ DEFINE_PROP_BOOL("short-isa-string", RISCVCPU, cfg.short_isa_string, false),
69
+ *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
48
DEFINE_PROP_END_OF_LIST(),
70
+ return TRANSLATE_SUCCESS;
49
};
71
+ }
50
72
+
51
@@ -XXX,XX +XXX,XX @@ char *riscv_isa_string(RISCVCPU *cpu)
73
+ if (!pmp_hart_has_privs(env, addr, size, 1 << access_type, &pmp_priv,
74
+ mode)) {
75
+ *prot = 0;
76
+ return TRANSLATE_PMP_FAIL;
77
+ }
78
+
79
+ *prot = pmp_priv_to_page_prot(pmp_priv);
80
+ if (tlb_size != NULL) {
81
+ if (pmp_is_range_in_tlb(env, addr & ~(*tlb_size - 1), &tlb_size_pmp)) {
82
+ *tlb_size = tlb_size_pmp;
83
+ }
84
+ }
85
+
86
+ return TRANSLATE_SUCCESS;
87
+}
88
+
89
/* get_physical_address - get the physical address for this virtual address
90
*
91
* Do a page table walk to obtain the physical address corresponding to a
92
@@ -XXX,XX +XXX,XX @@ restart:
93
pte_addr = base + idx * ptesize;
94
}
95
96
- if (riscv_feature(env, RISCV_FEATURE_PMP) &&
97
- !pmp_hart_has_privs(env, pte_addr, sizeof(target_ulong),
98
- 1 << MMU_DATA_LOAD, PRV_S)) {
99
+ int pmp_prot;
100
+ int pmp_ret = get_physical_address_pmp(env, &pmp_prot, NULL, pte_addr,
101
+ sizeof(target_ulong),
102
+ MMU_DATA_LOAD, PRV_S);
103
+ if (pmp_ret != TRANSLATE_SUCCESS) {
104
return TRANSLATE_PMP_FAIL;
105
}
106
107
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
108
#ifndef CONFIG_USER_ONLY
109
vaddr im_address;
110
hwaddr pa = 0;
111
- int prot, prot2;
112
+ int prot, prot2, prot_pmp;
113
bool pmp_violation = false;
114
bool first_stage_error = true;
115
bool two_stage_lookup = false;
116
int ret = TRANSLATE_FAIL;
117
int mode = mmu_idx;
118
- target_ulong tlb_size = 0;
119
+ /* default TLB page size */
120
+ target_ulong tlb_size = TARGET_PAGE_SIZE;
121
122
env->guest_phys_fault_addr = 0;
123
124
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
125
126
prot &= prot2;
127
128
- if (riscv_feature(env, RISCV_FEATURE_PMP) &&
129
- (ret == TRANSLATE_SUCCESS) &&
130
- !pmp_hart_has_privs(env, pa, size, 1 << access_type, mode)) {
131
- ret = TRANSLATE_PMP_FAIL;
132
+ if (ret == TRANSLATE_SUCCESS) {
133
+ ret = get_physical_address_pmp(env, &prot_pmp, &tlb_size, pa,
134
+ size, access_type, mode);
135
+ prot &= prot_pmp;
136
}
137
138
if (ret != TRANSLATE_SUCCESS) {
139
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
140
"%s address=%" VADDR_PRIx " ret %d physical "
141
TARGET_FMT_plx " prot %d\n",
142
__func__, address, ret, pa, prot);
143
- }
144
145
- if (riscv_feature(env, RISCV_FEATURE_PMP) &&
146
- (ret == TRANSLATE_SUCCESS) &&
147
- !pmp_hart_has_privs(env, pa, size, 1 << access_type, mode)) {
148
- ret = TRANSLATE_PMP_FAIL;
149
+ if (ret == TRANSLATE_SUCCESS) {
150
+ ret = get_physical_address_pmp(env, &prot_pmp, &tlb_size, pa,
151
+ size, access_type, mode);
152
+ prot &= prot_pmp;
153
+ }
154
}
155
+
156
if (ret == TRANSLATE_PMP_FAIL) {
157
pmp_violation = true;
158
}
159
160
if (ret == TRANSLATE_SUCCESS) {
161
- if (pmp_is_range_in_tlb(env, pa & TARGET_PAGE_MASK, &tlb_size)) {
162
- tlb_set_page(cs, address & ~(tlb_size - 1), pa & ~(tlb_size - 1),
163
- prot, mmu_idx, tlb_size);
164
- } else {
165
- tlb_set_page(cs, address & TARGET_PAGE_MASK, pa & TARGET_PAGE_MASK,
166
- prot, mmu_idx, TARGET_PAGE_SIZE);
167
- }
168
+ tlb_set_page(cs, address & ~(tlb_size - 1), pa & ~(tlb_size - 1),
169
+ prot, mmu_idx, tlb_size);
170
return true;
171
} else if (probe) {
172
return false;
173
diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
174
index XXXXXXX..XXXXXXX 100644
175
--- a/target/riscv/pmp.c
176
+++ b/target/riscv/pmp.c
177
@@ -XXX,XX +XXX,XX @@ static int pmp_is_in_range(CPURISCVState *env, int pmp_index, target_ulong addr)
178
return result;
179
}
180
181
+/*
182
+ * Check if the address has required RWX privs when no PMP entry is matched.
183
+ */
184
+static bool pmp_hart_has_privs_default(CPURISCVState *env, target_ulong addr,
185
+ target_ulong size, pmp_priv_t privs, pmp_priv_t *allowed_privs,
186
+ target_ulong mode)
187
+{
188
+ bool ret;
189
+
190
+ if ((!riscv_feature(env, RISCV_FEATURE_PMP)) || (mode == PRV_M)) {
191
+ /*
192
+ * Privileged spec v1.10 states if HW doesn't implement any PMP entry
193
+ * or no PMP entry matches an M-Mode access, the access succeeds.
194
+ */
195
+ ret = true;
196
+ *allowed_privs = PMP_READ | PMP_WRITE | PMP_EXEC;
197
+ } else {
198
+ /*
199
+ * Other modes are not allowed to succeed if they don't * match a rule,
200
+ * but there are rules. We've checked for no rule earlier in this
201
+ * function.
202
+ */
203
+ ret = false;
204
+ *allowed_privs = 0;
205
+ }
206
+
207
+ return ret;
208
+}
209
+
210
211
/*
212
* Public Interface
213
@@ -XXX,XX +XXX,XX @@ static int pmp_is_in_range(CPURISCVState *env, int pmp_index, target_ulong addr)
214
* Check if the address has required RWX privs to complete desired operation
215
*/
216
bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,
217
- target_ulong size, pmp_priv_t privs, target_ulong mode)
218
+ target_ulong size, pmp_priv_t privs, pmp_priv_t *allowed_privs,
219
+ target_ulong mode)
220
{
221
int i = 0;
222
int ret = -1;
223
int pmp_size = 0;
224
target_ulong s = 0;
225
target_ulong e = 0;
226
- pmp_priv_t allowed_privs = 0;
227
228
/* Short cut if no rules */
229
if (0 == pmp_get_num_rules(env)) {
230
- return (env->priv == PRV_M) ? true : false;
231
+ return pmp_hart_has_privs_default(env, addr, size, privs,
232
+ allowed_privs, mode);
233
}
234
235
if (size == 0) {
236
@@ -XXX,XX +XXX,XX @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,
237
* check
238
*/
239
if (((s + e) == 2) && (PMP_AMATCH_OFF != a_field)) {
240
- allowed_privs = PMP_READ | PMP_WRITE | PMP_EXEC;
241
+ *allowed_privs = PMP_READ | PMP_WRITE | PMP_EXEC;
242
if ((mode != PRV_M) || pmp_is_locked(env, i)) {
243
- allowed_privs &= env->pmp_state.pmp[i].cfg_reg;
244
+ *allowed_privs &= env->pmp_state.pmp[i].cfg_reg;
245
}
246
247
- if ((privs & allowed_privs) == privs) {
248
- ret = 1;
249
- break;
250
- } else {
251
- ret = 0;
252
- break;
253
- }
254
+ ret = ((privs & *allowed_privs) == privs);
255
+ break;
256
}
52
}
257
}
53
}
258
54
*p = '\0';
259
/* No rule matched */
55
- riscv_isa_string_ext(cpu, &isa_str, maxlen);
260
if (ret == -1) {
56
+ if (!cpu->cfg.short_isa_string) {
261
- if (mode == PRV_M) {
57
+ riscv_isa_string_ext(cpu, &isa_str, maxlen);
262
- ret = 1; /* Privileged spec v1.10 states if no PMP entry matches an
58
+ }
263
- * M-Mode access, the access succeeds */
59
return isa_str;
264
- } else {
265
- ret = 0; /* Other modes are not allowed to succeed if they don't
266
- * match a rule, but there are rules. We've checked for
267
- * no rule earlier in this function. */
268
- }
269
+ return pmp_hart_has_privs_default(env, addr, size, privs,
270
+ allowed_privs, mode);
271
}
272
273
return ret == 1 ? true : false;
274
}
60
}
275
61
276
-
277
/*
278
* Handle a write to a pmpcfg CSP
279
*/
280
@@ -XXX,XX +XXX,XX @@ bool pmp_is_range_in_tlb(CPURISCVState *env, hwaddr tlb_sa,
281
282
return false;
283
}
284
+
285
+/*
286
+ * Convert PMP privilege to TLB page privilege.
287
+ */
288
+int pmp_priv_to_page_prot(pmp_priv_t pmp_priv)
289
+{
290
+ int prot = 0;
291
+
292
+ if (pmp_priv & PMP_READ) {
293
+ prot |= PAGE_READ;
294
+ }
295
+ if (pmp_priv & PMP_WRITE) {
296
+ prot |= PAGE_WRITE;
297
+ }
298
+ if (pmp_priv & PMP_EXEC) {
299
+ prot |= PAGE_EXEC;
300
+ }
301
+
302
+ return prot;
303
+}
304
--
62
--
305
2.30.1
63
2.35.3
306
307
diff view generated by jsdifflib
1
From: Asherah Connor <ashe@kivikakk.ee>
1
From: Tsukasa OI <research_trasio@irq.a4lg.com>
2
2
3
Provides fw_cfg for the virt machine on riscv. This enables
3
If specified CPU configuration is not valid, not just it prints error
4
using e.g. ramfb later.
4
message, it aborts and generates core dumps (depends on the operating
5
system). This kind of error handling should be used only when a serious
6
runtime error occurs.
5
7
6
Signed-off-by: Asherah Connor <ashe@kivikakk.ee>
8
This commit makes error handling on CPU configuration more generous on
7
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
9
virt/spike machines. It now just prints error message and quits (without
10
coredumps and aborts).
11
12
Signed-off-by: Tsukasa OI <research_trasio@irq.a4lg.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
13
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Message-id: 20210318235041.17175-2-ashe@kivikakk.ee
14
Message-Id: <d17381d3ea4992808cf1894f379ca67220f61b45.1652509778.git.research_trasio@irq.a4lg.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
16
---
12
include/hw/riscv/virt.h | 2 ++
17
hw/riscv/spike.c | 2 +-
13
hw/riscv/virt.c | 30 ++++++++++++++++++++++++++++++
18
hw/riscv/virt.c | 2 +-
14
hw/riscv/Kconfig | 1 +
19
2 files changed, 2 insertions(+), 2 deletions(-)
15
3 files changed, 33 insertions(+)
16
20
17
diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h
21
diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c
18
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
19
--- a/include/hw/riscv/virt.h
23
--- a/hw/riscv/spike.c
20
+++ b/include/hw/riscv/virt.h
24
+++ b/hw/riscv/spike.c
21
@@ -XXX,XX +XXX,XX @@ struct RISCVVirtState {
25
@@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine)
22
RISCVHartArrayState soc[VIRT_SOCKETS_MAX];
26
base_hartid, &error_abort);
23
DeviceState *plic[VIRT_SOCKETS_MAX];
27
object_property_set_int(OBJECT(&s->soc[i]), "num-harts",
24
PFlashCFI01 *flash[2];
28
hart_count, &error_abort);
25
+ FWCfgState *fw_cfg;
29
- sysbus_realize(SYS_BUS_DEVICE(&s->soc[i]), &error_abort);
26
30
+ sysbus_realize(SYS_BUS_DEVICE(&s->soc[i]), &error_fatal);
27
int fdt_size;
31
28
};
32
/* Core Local Interruptor (timer and IPI) for each socket */
29
@@ -XXX,XX +XXX,XX @@ enum {
33
riscv_aclint_swi_create(
30
VIRT_PLIC,
31
VIRT_UART0,
32
VIRT_VIRTIO,
33
+ VIRT_FW_CFG,
34
VIRT_FLASH,
35
VIRT_DRAM,
36
VIRT_PCIE_MMIO,
37
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
34
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
38
index XXXXXXX..XXXXXXX 100644
35
index XXXXXXX..XXXXXXX 100644
39
--- a/hw/riscv/virt.c
36
--- a/hw/riscv/virt.c
40
+++ b/hw/riscv/virt.c
37
+++ b/hw/riscv/virt.c
41
@@ -XXX,XX +XXX,XX @@ static const MemMapEntry virt_memmap[] = {
42
[VIRT_PLIC] = { 0xc000000, VIRT_PLIC_SIZE(VIRT_CPUS_MAX * 2) },
43
[VIRT_UART0] = { 0x10000000, 0x100 },
44
[VIRT_VIRTIO] = { 0x10001000, 0x1000 },
45
+ [VIRT_FW_CFG] = { 0x10100000, 0x18 },
46
[VIRT_FLASH] = { 0x20000000, 0x4000000 },
47
[VIRT_PCIE_ECAM] = { 0x30000000, 0x10000000 },
48
[VIRT_PCIE_MMIO] = { 0x40000000, 0x40000000 },
49
@@ -XXX,XX +XXX,XX @@ static inline DeviceState *gpex_pcie_init(MemoryRegion *sys_mem,
50
return dev;
51
}
52
53
+static FWCfgState *create_fw_cfg(const MachineState *mc)
54
+{
55
+ hwaddr base = virt_memmap[VIRT_FW_CFG].base;
56
+ hwaddr size = virt_memmap[VIRT_FW_CFG].size;
57
+ FWCfgState *fw_cfg;
58
+ char *nodename;
59
+
60
+ fw_cfg = fw_cfg_init_mem_wide(base + 8, base, 8, base + 16,
61
+ &address_space_memory);
62
+ fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, (uint16_t)mc->smp.cpus);
63
+
64
+ nodename = g_strdup_printf("/fw-cfg@%" PRIx64, base);
65
+ qemu_fdt_add_subnode(mc->fdt, nodename);
66
+ qemu_fdt_setprop_string(mc->fdt, nodename,
67
+ "compatible", "qemu,fw-cfg-mmio");
68
+ qemu_fdt_setprop_sized_cells(mc->fdt, nodename, "reg",
69
+ 2, base, 2, size);
70
+ qemu_fdt_setprop(mc->fdt, nodename, "dma-coherent", NULL, 0);
71
+ g_free(nodename);
72
+ return fw_cfg;
73
+}
74
+
75
static void virt_machine_init(MachineState *machine)
76
{
77
const MemMapEntry *memmap = virt_memmap;
78
@@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine)
38
@@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine)
79
start_addr = virt_memmap[VIRT_FLASH].base;
39
base_hartid, &error_abort);
80
}
40
object_property_set_int(OBJECT(&s->soc[i]), "num-harts",
81
41
hart_count, &error_abort);
82
+ /*
42
- sysbus_realize(SYS_BUS_DEVICE(&s->soc[i]), &error_abort);
83
+ * Init fw_cfg. Must be done before riscv_load_fdt, otherwise the device
43
+ sysbus_realize(SYS_BUS_DEVICE(&s->soc[i]), &error_fatal);
84
+ * tree cannot be altered and we get FDT_ERR_NOSPACE.
44
85
+ */
45
if (!kvm_enabled()) {
86
+ s->fw_cfg = create_fw_cfg(machine);
46
if (s->have_aclint) {
87
+ rom_set_fw(s->fw_cfg);
88
+
89
/* Compute the fdt load address in dram */
90
fdt_load_addr = riscv_load_fdt(memmap[VIRT_DRAM].base,
91
machine->ram_size, machine->fdt);
92
diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig
93
index XXXXXXX..XXXXXXX 100644
94
--- a/hw/riscv/Kconfig
95
+++ b/hw/riscv/Kconfig
96
@@ -XXX,XX +XXX,XX @@ config RISCV_VIRT
97
select SIFIVE_PLIC
98
select SIFIVE_TEST
99
select VIRTIO_MMIO
100
+ select FW_CFG_DMA
101
102
config SIFIVE_E
103
bool
104
--
47
--
105
2.30.1
48
2.35.3
106
107
diff view generated by jsdifflib
New patch
1
From: Tsukasa OI <research_trasio@irq.a4lg.com>
1
2
3
If specified CPU configuration is not valid, not just it prints error
4
message, it aborts and generates core dumps (depends on the operating
5
system). This kind of error handling should be used only when a serious
6
runtime error occurs.
7
8
This commit makes error handling on CPU configuration more generous on
9
sifive_e/u and opentitan machines. It now just prints error message and
10
quits (without coredumps and aborts).
11
12
This is separate from spike/virt because it involves different type
13
(TYPE_RISCV_HART_ARRAY) on sifive_e/u and opentitan machines.
14
15
Signed-off-by: Tsukasa OI <research_trasio@irq.a4lg.com>
16
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
17
Message-Id: <09e61e58a7543da44bdb0e0f5368afc8903b4aa6.1652509778.git.research_trasio@irq.a4lg.com>
18
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
19
---
20
hw/riscv/opentitan.c | 2 +-
21
hw/riscv/sifive_e.c | 2 +-
22
hw/riscv/sifive_u.c | 4 ++--
23
3 files changed, 4 insertions(+), 4 deletions(-)
24
25
diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c
26
index XXXXXXX..XXXXXXX 100644
27
--- a/hw/riscv/opentitan.c
28
+++ b/hw/riscv/opentitan.c
29
@@ -XXX,XX +XXX,XX @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp)
30
object_property_set_int(OBJECT(&s->cpus), "num-harts", ms->smp.cpus,
31
&error_abort);
32
object_property_set_int(OBJECT(&s->cpus), "resetvec", 0x8080, &error_abort);
33
- sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_abort);
34
+ sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_fatal);
35
36
/* Boot ROM */
37
memory_region_init_rom(&s->rom, OBJECT(dev_soc), "riscv.lowrisc.ibex.rom",
38
diff --git a/hw/riscv/sifive_e.c b/hw/riscv/sifive_e.c
39
index XXXXXXX..XXXXXXX 100644
40
--- a/hw/riscv/sifive_e.c
41
+++ b/hw/riscv/sifive_e.c
42
@@ -XXX,XX +XXX,XX @@ static void sifive_e_soc_realize(DeviceState *dev, Error **errp)
43
44
object_property_set_str(OBJECT(&s->cpus), "cpu-type", ms->cpu_type,
45
&error_abort);
46
- sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_abort);
47
+ sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_fatal);
48
49
/* Mask ROM */
50
memory_region_init_rom(&s->mask_rom, OBJECT(dev), "riscv.sifive.e.mrom",
51
diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
52
index XXXXXXX..XXXXXXX 100644
53
--- a/hw/riscv/sifive_u.c
54
+++ b/hw/riscv/sifive_u.c
55
@@ -XXX,XX +XXX,XX @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp)
56
qdev_prop_set_string(DEVICE(&s->u_cpus), "cpu-type", s->cpu_type);
57
qdev_prop_set_uint64(DEVICE(&s->u_cpus), "resetvec", 0x1004);
58
59
- sysbus_realize(SYS_BUS_DEVICE(&s->e_cpus), &error_abort);
60
- sysbus_realize(SYS_BUS_DEVICE(&s->u_cpus), &error_abort);
61
+ sysbus_realize(SYS_BUS_DEVICE(&s->e_cpus), &error_fatal);
62
+ sysbus_realize(SYS_BUS_DEVICE(&s->u_cpus), &error_fatal);
63
/*
64
* The cluster must be realized after the RISC-V hart array container,
65
* as the container's CPU object is only created on realize, and the
66
--
67
2.35.3
diff view generated by jsdifflib
New patch
1
From: Tsukasa OI <research_trasio@irq.a4lg.com>
1
2
3
Because ext_? members are boolean variables, operator `&&' should be
4
used instead of `&'.
5
6
Signed-off-by: Tsukasa OI <research_trasio@irq.a4lg.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Reviewed-by: Víctor Colombo <victor.colombo@eldorado.org.br>
9
Message-Id: <91633f8349253656dd08bc8dc36498a9c7538b10.1652583332.git.research_trasio@irq.a4lg.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
12
target/riscv/cpu.c | 4 ++--
13
1 file changed, 2 insertions(+), 2 deletions(-)
14
15
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/cpu.c
18
+++ b/target/riscv/cpu.c
19
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
20
return;
21
}
22
23
- if (cpu->cfg.ext_g && !(cpu->cfg.ext_i & cpu->cfg.ext_m &
24
- cpu->cfg.ext_a & cpu->cfg.ext_f &
25
+ if (cpu->cfg.ext_g && !(cpu->cfg.ext_i && cpu->cfg.ext_m &&
26
+ cpu->cfg.ext_a && cpu->cfg.ext_f &&
27
cpu->cfg.ext_d)) {
28
warn_report("Setting G will also set IMAFD");
29
cpu->cfg.ext_i = true;
30
--
31
2.35.3
diff view generated by jsdifflib
1
From: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
1
From: Tsukasa OI <research_trasio@irq.a4lg.com>
2
2
3
The current condition for the use of background registers only
3
Because "G" virtual extension expands to "IMAFD", we cannot separately
4
considers the hypervisor load and store instructions,
4
disable extensions like "F" or "D" without disabling "G". Because all
5
but not accesses from M mode via MSTATUS_MPRV+MPV.
5
"IMAFD" are enabled by default, it's harmless to disable "G" by default.
6
6
7
Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
7
Signed-off-by: Tsukasa OI <research_trasio@irq.a4lg.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Message-id: 20210311103036.1401073-1-georg.kotheimer@kernkonzept.com
9
Message-Id: <cab7205f1d7668f642fa242386543334af6bc1bd.1652583332.git.research_trasio@irq.a4lg.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
11
---
12
target/riscv/cpu_helper.c | 2 +-
12
target/riscv/cpu.c | 2 +-
13
1 file changed, 1 insertion(+), 1 deletion(-)
13
1 file changed, 1 insertion(+), 1 deletion(-)
14
14
15
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
15
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
16
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/cpu_helper.c
17
--- a/target/riscv/cpu.c
18
+++ b/target/riscv/cpu_helper.c
18
+++ b/target/riscv/cpu.c
19
@@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,
19
@@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = {
20
* was called. Background registers will be used if the guest has
20
/* Defaults for standard extensions */
21
* forced a two stage translation to be on (in HS or M mode).
21
DEFINE_PROP_BOOL("i", RISCVCPU, cfg.ext_i, true),
22
*/
22
DEFINE_PROP_BOOL("e", RISCVCPU, cfg.ext_e, false),
23
- if (!riscv_cpu_virt_enabled(env) && riscv_cpu_two_stage_lookup(mmu_idx)) {
23
- DEFINE_PROP_BOOL("g", RISCVCPU, cfg.ext_g, true),
24
+ if (!riscv_cpu_virt_enabled(env) && two_stage) {
24
+ DEFINE_PROP_BOOL("g", RISCVCPU, cfg.ext_g, false),
25
use_background = true;
25
DEFINE_PROP_BOOL("m", RISCVCPU, cfg.ext_m, true),
26
}
26
DEFINE_PROP_BOOL("a", RISCVCPU, cfg.ext_a, true),
27
27
DEFINE_PROP_BOOL("f", RISCVCPU, cfg.ext_f, true),
28
--
28
--
29
2.30.1
29
2.35.3
30
31
diff view generated by jsdifflib
New patch
1
From: Tsukasa OI <research_trasio@irq.a4lg.com>
1
2
3
On ISA version 20190608 or later, "G" expands to "IMAFD_Zicsr_Zifencei".
4
Both "Zicsr" and "Zifencei" are enabled by default and "G" is supposed to
5
be (virtually) enabled as well, it should be safe to change its expansion.
6
7
Signed-off-by: Tsukasa OI <research_trasio@irq.a4lg.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Message-Id: <d1b5be550a2893a0fd32c928f832d2ff7bfafe35.1652583332.git.research_trasio@irq.a4lg.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
12
target/riscv/cpu.c | 7 +++++--
13
1 file changed, 5 insertions(+), 2 deletions(-)
14
15
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/cpu.c
18
+++ b/target/riscv/cpu.c
19
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
20
21
if (cpu->cfg.ext_g && !(cpu->cfg.ext_i && cpu->cfg.ext_m &&
22
cpu->cfg.ext_a && cpu->cfg.ext_f &&
23
- cpu->cfg.ext_d)) {
24
- warn_report("Setting G will also set IMAFD");
25
+ cpu->cfg.ext_d &&
26
+ cpu->cfg.ext_icsr && cpu->cfg.ext_ifencei)) {
27
+ warn_report("Setting G will also set IMAFD_Zicsr_Zifencei");
28
cpu->cfg.ext_i = true;
29
cpu->cfg.ext_m = true;
30
cpu->cfg.ext_a = true;
31
cpu->cfg.ext_f = true;
32
cpu->cfg.ext_d = true;
33
+ cpu->cfg.ext_icsr = true;
34
+ cpu->cfg.ext_ifencei = true;
35
}
36
37
if (cpu->cfg.ext_zdinx || cpu->cfg.ext_zhinx ||
38
--
39
2.35.3
diff view generated by jsdifflib
New patch
1
From: Tsukasa OI <research_trasio@irq.a4lg.com>
1
2
3
QEMU allowed inconsistent configurations that made floating point
4
arithmetic effectively unusable.
5
6
This commit adds certain checks for consistent FP arithmetic:
7
8
- F requires Zicsr
9
- Zfinx requires Zicsr
10
- Zfh/Zfhmin require F
11
- D requires F
12
- V requires D
13
14
Because F/D/Zicsr are enabled by default (and an error will not occur unless
15
we manually disable one or more of prerequisites), this commit just enforces
16
the user to give consistent combinations.
17
18
Signed-off-by: Tsukasa OI <research_trasio@irq.a4lg.com>
19
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
20
Message-Id: <00e7b1c6060dab32ac7d49813b1ca84d3eb63298.1652583332.git.research_trasio@irq.a4lg.com>
21
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
22
---
23
target/riscv/cpu.c | 25 +++++++++++++++++++++++++
24
1 file changed, 25 insertions(+)
25
26
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
27
index XXXXXXX..XXXXXXX 100644
28
--- a/target/riscv/cpu.c
29
+++ b/target/riscv/cpu.c
30
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
31
cpu->cfg.ext_ifencei = true;
32
}
33
34
+ if (cpu->cfg.ext_f && !cpu->cfg.ext_icsr) {
35
+ error_setg(errp, "F extension requires Zicsr");
36
+ return;
37
+ }
38
+
39
+ if ((cpu->cfg.ext_zfh || cpu->cfg.ext_zfhmin) && !cpu->cfg.ext_f) {
40
+ error_setg(errp, "Zfh/Zfhmin extensions require F extension");
41
+ return;
42
+ }
43
+
44
+ if (cpu->cfg.ext_d && !cpu->cfg.ext_f) {
45
+ error_setg(errp, "D extension requires F extension");
46
+ return;
47
+ }
48
+
49
+ if (cpu->cfg.ext_v && !cpu->cfg.ext_d) {
50
+ error_setg(errp, "V extension requires D extension");
51
+ return;
52
+ }
53
+
54
if (cpu->cfg.ext_zdinx || cpu->cfg.ext_zhinx ||
55
cpu->cfg.ext_zhinxmin) {
56
cpu->cfg.ext_zfinx = true;
57
}
58
59
+ if (cpu->cfg.ext_zfinx && !cpu->cfg.ext_icsr) {
60
+ error_setg(errp, "Zfinx extension requires Zicsr");
61
+ return;
62
+ }
63
+
64
if (cpu->cfg.ext_zk) {
65
cpu->cfg.ext_zkn = true;
66
cpu->cfg.ext_zkr = true;
67
--
68
2.35.3
diff view generated by jsdifflib
1
From: Alexander Wagner <alexander.wagner@ulal.de>
1
From: Tsukasa OI <research_trasio@irq.a4lg.com>
2
2
3
Not disabling the UART leads to QEMU overwriting the UART receive buffer with
3
We should separate "check" and "configure" steps as possible.
4
the newest received byte. The rx_level variable is added to allow the use of
4
This commit separates both steps except vector/Zfinx-related checks.
5
the existing OpenTitan driver libraries.
6
5
7
Signed-off-by: Alexander Wagner <alexander.wagner@ulal.de>
6
Signed-off-by: Tsukasa OI <research_trasio@irq.a4lg.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Message-id: 20210309152130.13038-1-alexander.wagner@ulal.de
8
Message-Id: <c3145fa37a529484cf3047c8cb9841e9effad4b0.1652583332.git.research_trasio@irq.a4lg.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
10
---
12
include/hw/char/ibex_uart.h | 4 ++++
11
target/riscv/cpu.c | 31 ++++++++++++++++---------------
13
hw/char/ibex_uart.c | 23 ++++++++++++++++++-----
12
1 file changed, 16 insertions(+), 15 deletions(-)
14
2 files changed, 22 insertions(+), 5 deletions(-)
15
13
16
diff --git a/include/hw/char/ibex_uart.h b/include/hw/char/ibex_uart.h
14
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
17
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
18
--- a/include/hw/char/ibex_uart.h
16
--- a/target/riscv/cpu.c
19
+++ b/include/hw/char/ibex_uart.h
17
+++ b/target/riscv/cpu.c
20
@@ -XXX,XX +XXX,XX @@ REG32(FIFO_CTRL, 0x1c)
18
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
21
FIELD(FIFO_CTRL, RXILVL, 2, 3)
19
return;
22
FIELD(FIFO_CTRL, TXILVL, 5, 2)
20
}
23
REG32(FIFO_STATUS, 0x20)
21
24
+ FIELD(FIFO_STATUS, TXLVL, 0, 5)
22
+ if ((cpu->cfg.ext_zve32f || cpu->cfg.ext_zve64f) && !cpu->cfg.ext_f) {
25
+ FIELD(FIFO_STATUS, RXLVL, 16, 5)
23
+ error_setg(errp, "Zve32f/Zve64f extensions require F extension");
26
REG32(OVRD, 0x24)
24
+ return;
27
REG32(VAL, 0x28)
25
+ }
28
REG32(TIMEOUT_CTRL, 0x2c)
29
@@ -XXX,XX +XXX,XX @@ struct IbexUartState {
30
uint8_t tx_fifo[IBEX_UART_TX_FIFO_SIZE];
31
uint32_t tx_level;
32
33
+ uint32_t rx_level;
34
+
26
+
35
QEMUTimer *fifo_trigger_handle;
27
+ /* Set the ISA extensions, checks should have happened above */
36
uint64_t char_tx_time;
28
if (cpu->cfg.ext_zdinx || cpu->cfg.ext_zhinx ||
37
29
cpu->cfg.ext_zhinxmin) {
38
diff --git a/hw/char/ibex_uart.c b/hw/char/ibex_uart.c
30
cpu->cfg.ext_zfinx = true;
39
index XXXXXXX..XXXXXXX 100644
31
}
40
--- a/hw/char/ibex_uart.c
32
41
+++ b/hw/char/ibex_uart.c
33
- if (cpu->cfg.ext_zfinx && !cpu->cfg.ext_icsr) {
42
@@ -XXX,XX +XXX,XX @@ static int ibex_uart_can_receive(void *opaque)
34
- error_setg(errp, "Zfinx extension requires Zicsr");
43
{
35
- return;
44
IbexUartState *s = opaque;
36
+ if (cpu->cfg.ext_zfinx) {
45
37
+ if (!cpu->cfg.ext_icsr) {
46
- if (s->uart_ctrl & R_CTRL_RX_ENABLE_MASK) {
38
+ error_setg(errp, "Zfinx extension requires Zicsr");
47
+ if ((s->uart_ctrl & R_CTRL_RX_ENABLE_MASK)
39
+ return;
48
+ && !(s->uart_status & R_STATUS_RXFULL_MASK)) {
40
+ }
49
return 1;
41
+ if (cpu->cfg.ext_f) {
50
}
42
+ error_setg(errp,
51
43
+ "Zfinx cannot be supported together with F extension");
52
@@ -XXX,XX +XXX,XX @@ static void ibex_uart_receive(void *opaque, const uint8_t *buf, int size)
44
+ return;
53
54
s->uart_status &= ~R_STATUS_RXIDLE_MASK;
55
s->uart_status &= ~R_STATUS_RXEMPTY_MASK;
56
+ /* The RXFULL is set after receiving a single byte
57
+ * as the FIFO buffers are not yet implemented.
58
+ */
59
+ s->uart_status |= R_STATUS_RXFULL_MASK;
60
+ s->rx_level += 1;
61
62
if (size > rx_fifo_level) {
63
s->uart_intr_state |= R_INTR_STATE_RX_WATERMARK_MASK;
64
@@ -XXX,XX +XXX,XX @@ static void ibex_uart_reset(DeviceState *dev)
65
s->uart_timeout_ctrl = 0x00000000;
66
67
s->tx_level = 0;
68
+ s->rx_level = 0;
69
70
s->char_tx_time = (NANOSECONDS_PER_SECOND / 230400) * 10;
71
72
@@ -XXX,XX +XXX,XX @@ static uint64_t ibex_uart_read(void *opaque, hwaddr addr,
73
74
case R_RDATA:
75
retvalue = s->uart_rdata;
76
- if (s->uart_ctrl & R_CTRL_RX_ENABLE_MASK) {
77
+ if ((s->uart_ctrl & R_CTRL_RX_ENABLE_MASK) && (s->rx_level > 0)) {
78
qemu_chr_fe_accept_input(&s->chr);
79
80
- s->uart_status |= R_STATUS_RXIDLE_MASK;
81
- s->uart_status |= R_STATUS_RXEMPTY_MASK;
82
+ s->rx_level -= 1;
83
+ s->uart_status &= ~R_STATUS_RXFULL_MASK;
84
+ if (s->rx_level == 0) {
85
+ s->uart_status |= R_STATUS_RXIDLE_MASK;
86
+ s->uart_status |= R_STATUS_RXEMPTY_MASK;
87
+ }
45
+ }
88
}
46
}
89
break;
47
90
case R_WDATA:
48
if (cpu->cfg.ext_zk) {
91
@@ -XXX,XX +XXX,XX @@ static uint64_t ibex_uart_read(void *opaque, hwaddr addr,
49
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
92
case R_FIFO_STATUS:
50
cpu->cfg.ext_zksh = true;
93
retvalue = s->uart_fifo_status;
94
95
- retvalue |= s->tx_level & 0x1F;
96
+ retvalue |= (s->rx_level & 0x1F) << R_FIFO_STATUS_RXLVL_SHIFT;
97
+ retvalue |= (s->tx_level & 0x1F) << R_FIFO_STATUS_TXLVL_SHIFT;
98
99
qemu_log_mask(LOG_UNIMP,
100
"%s: RX fifos are not supported\n", __func__);
101
@@ -XXX,XX +XXX,XX @@ static void ibex_uart_write(void *opaque, hwaddr addr,
102
s->uart_fifo_ctrl = value;
103
104
if (value & R_FIFO_CTRL_RXRST_MASK) {
105
+ s->rx_level = 0;
106
qemu_log_mask(LOG_UNIMP,
107
"%s: RX fifos are not supported\n", __func__);
108
}
51
}
52
53
- /* Set the ISA extensions, checks should have happened above */
54
if (cpu->cfg.ext_i) {
55
ext |= RVI;
56
}
57
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
58
}
59
set_vext_version(env, vext_version);
60
}
61
- if ((cpu->cfg.ext_zve32f || cpu->cfg.ext_zve64f) && !cpu->cfg.ext_f) {
62
- error_setg(errp, "Zve32f/Zve64f extension depends upon RVF.");
63
- return;
64
- }
65
if (cpu->cfg.ext_j) {
66
ext |= RVJ;
67
}
68
- if (cpu->cfg.ext_zfinx && ((ext & (RVF | RVD)) || cpu->cfg.ext_zfh ||
69
- cpu->cfg.ext_zfhmin)) {
70
- error_setg(errp,
71
- "'Zfinx' cannot be supported together with 'F', 'D', 'Zfh',"
72
- " 'Zfhmin'");
73
- return;
74
- }
75
76
set_misa(env, env->misa_mxl, ext);
77
}
109
--
78
--
110
2.30.1
79
2.35.3
111
112
diff view generated by jsdifflib
1
From: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
1
From: Bernhard Beschow <shentey@gmail.com>
2
2
3
When decode_insn16() fails, we fall back to decode_RV32_64C() for
3
The QOM API already provides getters for uint64 and uint32 values, so reuse
4
further compressed instruction decoding. However, prior to this change,
4
them.
5
we did not raise an illegal instruction exception, if decode_RV32_64C()
6
fails to decode the instruction. This means that we skipped illegal
7
compressed instructions instead of raising an illegal instruction
8
exception.
9
5
10
Instead of patching decode_RV32_64C(), we can just remove it,
6
Signed-off-by: Bernhard Beschow <shentey@gmail.com>
11
as it is dead code since f330433b363 anyway.
12
13
Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
14
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
15
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
16
Message-id: 20210322121609.3097928-1-georg.kotheimer@kernkonzept.com
9
Message-Id: <20220301225220.239065-2-shentey@gmail.com>
17
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
18
---
11
---
19
target/riscv/translate.c | 179 +--------------------------------------
12
hw/vfio/pci-quirks.c | 34 +++++++++-------------------------
20
1 file changed, 1 insertion(+), 178 deletions(-)
13
1 file changed, 9 insertions(+), 25 deletions(-)
21
14
22
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
15
diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
23
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
24
--- a/target/riscv/translate.c
17
--- a/hw/vfio/pci-quirks.c
25
+++ b/target/riscv/translate.c
18
+++ b/hw/vfio/pci-quirks.c
26
@@ -XXX,XX +XXX,XX @@ typedef struct DisasContext {
19
@@ -XXX,XX +XXX,XX @@ static int vfio_add_nv_gpudirect_cap(VFIOPCIDevice *vdev, Error **errp)
27
CPUState *cs;
20
return 0;
28
} DisasContext;
29
30
-#ifdef TARGET_RISCV64
31
-/* convert riscv funct3 to qemu memop for load/store */
32
-static const int tcg_memop_lookup[8] = {
33
- [0 ... 7] = -1,
34
- [0] = MO_SB,
35
- [1] = MO_TESW,
36
- [2] = MO_TESL,
37
- [3] = MO_TEQ,
38
- [4] = MO_UB,
39
- [5] = MO_TEUW,
40
- [6] = MO_TEUL,
41
-};
42
-#endif
43
-
44
#ifdef TARGET_RISCV64
45
#define CASE_OP_32_64(X) case X: case glue(X, W)
46
#else
47
@@ -XXX,XX +XXX,XX @@ static void gen_jal(DisasContext *ctx, int rd, target_ulong imm)
48
ctx->base.is_jmp = DISAS_NORETURN;
49
}
21
}
50
22
51
-#ifdef TARGET_RISCV64
23
-static void vfio_pci_nvlink2_get_tgt(Object *obj, Visitor *v,
52
-static void gen_load_c(DisasContext *ctx, uint32_t opc, int rd, int rs1,
24
- const char *name,
53
- target_long imm)
25
- void *opaque, Error **errp)
54
-{
26
-{
55
- TCGv t0 = tcg_temp_new();
27
- uint64_t tgt = (uintptr_t) opaque;
56
- TCGv t1 = tcg_temp_new();
28
- visit_type_uint64(v, name, &tgt, errp);
57
- gen_get_gpr(t0, rs1);
58
- tcg_gen_addi_tl(t0, t0, imm);
59
- int memop = tcg_memop_lookup[(opc >> 12) & 0x7];
60
-
61
- if (memop < 0) {
62
- gen_exception_illegal(ctx);
63
- return;
64
- }
65
-
66
- tcg_gen_qemu_ld_tl(t1, t0, ctx->mem_idx, memop);
67
- gen_set_gpr(rd, t1);
68
- tcg_temp_free(t0);
69
- tcg_temp_free(t1);
70
-}
29
-}
71
-
30
-
72
-static void gen_store_c(DisasContext *ctx, uint32_t opc, int rs1, int rs2,
31
-static void vfio_pci_nvlink2_get_link_speed(Object *obj, Visitor *v,
73
- target_long imm)
32
- const char *name,
33
- void *opaque, Error **errp)
74
-{
34
-{
75
- TCGv t0 = tcg_temp_new();
35
- uint32_t link_speed = (uint32_t)(uintptr_t) opaque;
76
- TCGv dat = tcg_temp_new();
36
- visit_type_uint32(v, name, &link_speed, errp);
77
- gen_get_gpr(t0, rs1);
78
- tcg_gen_addi_tl(t0, t0, imm);
79
- gen_get_gpr(dat, rs2);
80
- int memop = tcg_memop_lookup[(opc >> 12) & 0x7];
81
-
82
- if (memop < 0) {
83
- gen_exception_illegal(ctx);
84
- return;
85
- }
86
-
87
- tcg_gen_qemu_st_tl(dat, t0, ctx->mem_idx, memop);
88
- tcg_temp_free(t0);
89
- tcg_temp_free(dat);
90
-}
91
-#endif
92
-
93
#ifndef CONFIG_USER_ONLY
94
/* The states of mstatus_fs are:
95
* 0 = disabled, 1 = initial, 2 = clean, 3 = dirty
96
@@ -XXX,XX +XXX,XX @@ static void mark_fs_dirty(DisasContext *ctx)
97
static inline void mark_fs_dirty(DisasContext *ctx) { }
98
#endif
99
100
-#if !defined(TARGET_RISCV64)
101
-static void gen_fp_load(DisasContext *ctx, uint32_t opc, int rd,
102
- int rs1, target_long imm)
103
-{
104
- TCGv t0;
105
-
106
- if (ctx->mstatus_fs == 0) {
107
- gen_exception_illegal(ctx);
108
- return;
109
- }
110
-
111
- t0 = tcg_temp_new();
112
- gen_get_gpr(t0, rs1);
113
- tcg_gen_addi_tl(t0, t0, imm);
114
-
115
- switch (opc) {
116
- case OPC_RISC_FLW:
117
- if (!has_ext(ctx, RVF)) {
118
- goto do_illegal;
119
- }
120
- tcg_gen_qemu_ld_i64(cpu_fpr[rd], t0, ctx->mem_idx, MO_TEUL);
121
- /* RISC-V requires NaN-boxing of narrower width floating point values */
122
- tcg_gen_ori_i64(cpu_fpr[rd], cpu_fpr[rd], 0xffffffff00000000ULL);
123
- break;
124
- case OPC_RISC_FLD:
125
- if (!has_ext(ctx, RVD)) {
126
- goto do_illegal;
127
- }
128
- tcg_gen_qemu_ld_i64(cpu_fpr[rd], t0, ctx->mem_idx, MO_TEQ);
129
- break;
130
- do_illegal:
131
- default:
132
- gen_exception_illegal(ctx);
133
- break;
134
- }
135
- tcg_temp_free(t0);
136
-
137
- mark_fs_dirty(ctx);
138
-}
37
-}
139
-
38
-
140
-static void gen_fp_store(DisasContext *ctx, uint32_t opc, int rs1,
39
int vfio_pci_nvidia_v100_ram_init(VFIOPCIDevice *vdev, Error **errp)
141
- int rs2, target_long imm)
142
-{
143
- TCGv t0;
144
-
145
- if (ctx->mstatus_fs == 0) {
146
- gen_exception_illegal(ctx);
147
- return;
148
- }
149
-
150
- t0 = tcg_temp_new();
151
- gen_get_gpr(t0, rs1);
152
- tcg_gen_addi_tl(t0, t0, imm);
153
-
154
- switch (opc) {
155
- case OPC_RISC_FSW:
156
- if (!has_ext(ctx, RVF)) {
157
- goto do_illegal;
158
- }
159
- tcg_gen_qemu_st_i64(cpu_fpr[rs2], t0, ctx->mem_idx, MO_TEUL);
160
- break;
161
- case OPC_RISC_FSD:
162
- if (!has_ext(ctx, RVD)) {
163
- goto do_illegal;
164
- }
165
- tcg_gen_qemu_st_i64(cpu_fpr[rs2], t0, ctx->mem_idx, MO_TEQ);
166
- break;
167
- do_illegal:
168
- default:
169
- gen_exception_illegal(ctx);
170
- break;
171
- }
172
-
173
- tcg_temp_free(t0);
174
-}
175
-#endif
176
-
177
static void gen_set_rm(DisasContext *ctx, int rm)
178
{
40
{
179
TCGv_i32 t0;
41
int ret;
180
@@ -XXX,XX +XXX,XX @@ static void gen_set_rm(DisasContext *ctx, int rm)
42
@@ -XXX,XX +XXX,XX @@ int vfio_pci_nvidia_v100_ram_init(VFIOPCIDevice *vdev, Error **errp)
181
tcg_temp_free_i32(t0);
43
nv2reg->size, p);
182
}
44
QLIST_INSERT_HEAD(&vdev->bars[0].quirks, quirk, next);
183
45
184
-static void decode_RV32_64C0(DisasContext *ctx, uint16_t opcode)
46
- object_property_add(OBJECT(vdev), "nvlink2-tgt", "uint64",
185
-{
47
- vfio_pci_nvlink2_get_tgt, NULL, NULL,
186
- uint8_t funct3 = extract16(opcode, 13, 3);
48
- (void *) (uintptr_t) cap->tgt);
187
- uint8_t rd_rs2 = GET_C_RS2S(opcode);
49
+ object_property_add_uint64_ptr(OBJECT(vdev), "nvlink2-tgt",
188
- uint8_t rs1s = GET_C_RS1S(opcode);
50
+ (uint64_t *) &cap->tgt,
189
-
51
+ OBJ_PROP_FLAG_READ);
190
- switch (funct3) {
52
trace_vfio_pci_nvidia_gpu_setup_quirk(vdev->vbasedev.name, cap->tgt,
191
- case 3:
53
nv2reg->size);
192
-#if defined(TARGET_RISCV64)
54
free_exit:
193
- /* C.LD(RV64/128) -> ld rd', offset[7:3](rs1')*/
55
@@ -XXX,XX +XXX,XX @@ int vfio_pci_nvlink2_init(VFIOPCIDevice *vdev, Error **errp)
194
- gen_load_c(ctx, OPC_RISC_LD, rd_rs2, rs1s,
56
QLIST_INSERT_HEAD(&vdev->bars[0].quirks, quirk, next);
195
- GET_C_LD_IMM(opcode));
57
}
196
-#else
58
197
- /* C.FLW (RV32) -> flw rd', offset[6:2](rs1')*/
59
- object_property_add(OBJECT(vdev), "nvlink2-tgt", "uint64",
198
- gen_fp_load(ctx, OPC_RISC_FLW, rd_rs2, rs1s,
60
- vfio_pci_nvlink2_get_tgt, NULL, NULL,
199
- GET_C_LW_IMM(opcode));
61
- (void *) (uintptr_t) captgt->tgt);
200
-#endif
62
+ object_property_add_uint64_ptr(OBJECT(vdev), "nvlink2-tgt",
201
- break;
63
+ (uint64_t *) &captgt->tgt,
202
- case 7:
64
+ OBJ_PROP_FLAG_READ);
203
-#if defined(TARGET_RISCV64)
65
trace_vfio_pci_nvlink2_setup_quirk_ssatgt(vdev->vbasedev.name, captgt->tgt,
204
- /* C.SD (RV64/128) -> sd rs2', offset[7:3](rs1')*/
66
atsdreg->size);
205
- gen_store_c(ctx, OPC_RISC_SD, rs1s, rd_rs2,
67
206
- GET_C_LD_IMM(opcode));
68
- object_property_add(OBJECT(vdev), "nvlink2-link-speed", "uint32",
207
-#else
69
- vfio_pci_nvlink2_get_link_speed, NULL, NULL,
208
- /* C.FSW (RV32) -> fsw rs2', offset[6:2](rs1')*/
70
- (void *) (uintptr_t) capspeed->link_speed);
209
- gen_fp_store(ctx, OPC_RISC_FSW, rs1s, rd_rs2,
71
+ object_property_add_uint32_ptr(OBJECT(vdev), "nvlink2-link-speed",
210
- GET_C_LW_IMM(opcode));
72
+ &capspeed->link_speed,
211
-#endif
73
+ OBJ_PROP_FLAG_READ);
212
- break;
74
trace_vfio_pci_nvlink2_setup_quirk_lnkspd(vdev->vbasedev.name,
213
- }
75
capspeed->link_speed);
214
-}
76
free_exit:
215
-
216
-static void decode_RV32_64C(DisasContext *ctx, uint16_t opcode)
217
-{
218
- uint8_t op = extract16(opcode, 0, 2);
219
-
220
- switch (op) {
221
- case 0:
222
- decode_RV32_64C0(ctx, opcode);
223
- break;
224
- }
225
-}
226
-
227
static int ex_plus_1(DisasContext *ctx, int nf)
228
{
229
return nf + 1;
230
@@ -XXX,XX +XXX,XX @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode)
231
} else {
232
ctx->pc_succ_insn = ctx->base.pc_next + 2;
233
if (!decode_insn16(ctx, opcode)) {
234
- /* fall back to old decoder */
235
- decode_RV32_64C(ctx, opcode);
236
+ gen_exception_illegal(ctx);
237
}
238
}
239
} else {
240
--
77
--
241
2.30.1
78
2.35.3
242
243
diff view generated by jsdifflib
1
From: Jim Shu <cwshu@andestech.com>
1
From: Bernhard Beschow <shentey@gmail.com>
2
2
3
If PMP permission of any address has been changed by updating PMP entry,
3
The QOM API already provides accessors for uint32 values, so reuse them.
4
flush all TLB pages to prevent from getting old permission.
5
4
6
Signed-off-by: Jim Shu <cwshu@andestech.com>
5
Signed-off-by: Bernhard Beschow <shentey@gmail.com>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Message-id: 1613916082-19528-4-git-send-email-cwshu@andestech.com
8
Message-Id: <20220301225220.239065-3-shentey@gmail.com>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
---
10
---
11
target/riscv/pmp.c | 4 ++++
11
hw/riscv/sifive_u.c | 24 ++++--------------------
12
1 file changed, 4 insertions(+)
12
1 file changed, 4 insertions(+), 20 deletions(-)
13
13
14
diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
14
diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
15
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
16
--- a/target/riscv/pmp.c
16
--- a/hw/riscv/sifive_u.c
17
+++ b/target/riscv/pmp.c
17
+++ b/hw/riscv/sifive_u.c
18
@@ -XXX,XX +XXX,XX @@
18
@@ -XXX,XX +XXX,XX @@ static void sifive_u_machine_set_start_in_flash(Object *obj, bool value, Error *
19
#include "qapi/error.h"
19
s->start_in_flash = value;
20
#include "cpu.h"
21
#include "trace.h"
22
+#include "exec/exec-all.h"
23
24
static void pmp_write_cfg(CPURISCVState *env, uint32_t addr_index,
25
uint8_t val);
26
@@ -XXX,XX +XXX,XX @@ void pmpcfg_csr_write(CPURISCVState *env, uint32_t reg_index,
27
cfg_val = (val >> 8 * i) & 0xff;
28
pmp_write_cfg(env, (reg_index * 4) + i, cfg_val);
29
}
30
+
31
+ /* If PMP permission of any addr has been changed, flush TLB pages. */
32
+ tlb_flush(env_cpu(env));
33
}
20
}
34
21
22
-static void sifive_u_machine_get_uint32_prop(Object *obj, Visitor *v,
23
- const char *name, void *opaque,
24
- Error **errp)
25
-{
26
- visit_type_uint32(v, name, (uint32_t *)opaque, errp);
27
-}
28
-
29
-static void sifive_u_machine_set_uint32_prop(Object *obj, Visitor *v,
30
- const char *name, void *opaque,
31
- Error **errp)
32
-{
33
- visit_type_uint32(v, name, (uint32_t *)opaque, errp);
34
-}
35
-
36
static void sifive_u_machine_instance_init(Object *obj)
37
{
38
SiFiveUState *s = RISCV_U_MACHINE(obj);
39
40
s->start_in_flash = false;
41
s->msel = 0;
42
- object_property_add(obj, "msel", "uint32",
43
- sifive_u_machine_get_uint32_prop,
44
- sifive_u_machine_set_uint32_prop, NULL, &s->msel);
45
+ object_property_add_uint32_ptr(obj, "msel", &s->msel,
46
+ OBJ_PROP_FLAG_READWRITE);
47
object_property_set_description(obj, "msel",
48
"Mode Select (MSEL[3:0]) pin state");
49
50
s->serial = OTP_SERIAL;
51
- object_property_add(obj, "serial", "uint32",
52
- sifive_u_machine_get_uint32_prop,
53
- sifive_u_machine_set_uint32_prop, NULL, &s->serial);
54
+ object_property_add_uint32_ptr(obj, "serial", &s->serial,
55
+ OBJ_PROP_FLAG_READWRITE);
56
object_property_set_description(obj, "serial", "Board serial number");
57
}
35
58
36
--
59
--
37
2.30.1
60
2.35.3
38
39
diff view generated by jsdifflib
New patch
1
From: Weiwei Li <liweiwei@iscas.ac.cn>
1
2
3
- setting ext_g will implicitly set ext_i
4
5
Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn>
6
Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Message-Id: <20220518012611.6772-1-liweiwei@iscas.ac.cn>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
---
11
target/riscv/cpu.c | 24 ++++++++++++------------
12
1 file changed, 12 insertions(+), 12 deletions(-)
13
14
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/target/riscv/cpu.c
17
+++ b/target/riscv/cpu.c
18
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
19
uint32_t ext = 0;
20
21
/* Do some ISA extension error checking */
22
- if (cpu->cfg.ext_i && cpu->cfg.ext_e) {
23
- error_setg(errp,
24
- "I and E extensions are incompatible");
25
- return;
26
- }
27
-
28
- if (!cpu->cfg.ext_i && !cpu->cfg.ext_e) {
29
- error_setg(errp,
30
- "Either I or E extension must be set");
31
- return;
32
- }
33
-
34
if (cpu->cfg.ext_g && !(cpu->cfg.ext_i && cpu->cfg.ext_m &&
35
cpu->cfg.ext_a && cpu->cfg.ext_f &&
36
cpu->cfg.ext_d &&
37
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
38
cpu->cfg.ext_ifencei = true;
39
}
40
41
+ if (cpu->cfg.ext_i && cpu->cfg.ext_e) {
42
+ error_setg(errp,
43
+ "I and E extensions are incompatible");
44
+ return;
45
+ }
46
+
47
+ if (!cpu->cfg.ext_i && !cpu->cfg.ext_e) {
48
+ error_setg(errp,
49
+ "Either I or E extension must be set");
50
+ return;
51
+ }
52
+
53
if (cpu->cfg.ext_f && !cpu->cfg.ext_icsr) {
54
error_setg(errp, "F extension requires Zicsr");
55
return;
56
--
57
2.35.3
diff view generated by jsdifflib
1
From: Frank Chang <frank.chang@sifive.com>
1
From: Frank Chang <frank.chang@sifive.com>
2
2
3
vs() should return -RISCV_EXCP_ILLEGAL_INST instead of -1 if rvv feature
3
"mimpid" cpu option was mistyped to "mipid".
4
is not enabled.
5
4
6
If -1 is returned, exception will be raised and cs->exception_index will
5
Fixes: 9951ba94 ("target/riscv: Support configuarable marchid, mvendorid, mipid CSR values")
7
be set to the negative return value. The exception will then be treated
8
as an instruction access fault instead of illegal instruction fault.
9
10
Signed-off-by: Frank Chang <frank.chang@sifive.com>
6
Signed-off-by: Frank Chang <frank.chang@sifive.com>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
13
Message-id: 20210223065935.20208-1-frank.chang@sifive.com
8
Message-Id: <20220523153147.15371-1-frank.chang@sifive.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
---
10
---
16
target/riscv/csr.c | 2 +-
11
target/riscv/cpu.h | 2 +-
17
1 file changed, 1 insertion(+), 1 deletion(-)
12
target/riscv/cpu.c | 4 ++--
13
target/riscv/csr.c | 8 ++++----
14
3 files changed, 7 insertions(+), 7 deletions(-)
18
15
16
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
17
index XXXXXXX..XXXXXXX 100644
18
--- a/target/riscv/cpu.h
19
+++ b/target/riscv/cpu.h
20
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
21
22
uint32_t mvendorid;
23
uint64_t marchid;
24
- uint64_t mipid;
25
+ uint64_t mimpid;
26
27
/* Vendor-specific custom extensions */
28
bool ext_XVentanaCondOps;
29
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
30
index XXXXXXX..XXXXXXX 100644
31
--- a/target/riscv/cpu.c
32
+++ b/target/riscv/cpu.c
33
@@ -XXX,XX +XXX,XX @@
34
#define RISCV_CPU_MARCHID ((QEMU_VERSION_MAJOR << 16) | \
35
(QEMU_VERSION_MINOR << 8) | \
36
(QEMU_VERSION_MICRO))
37
-#define RISCV_CPU_MIPID RISCV_CPU_MARCHID
38
+#define RISCV_CPU_MIMPID RISCV_CPU_MARCHID
39
40
static const char riscv_single_letter_exts[] = "IEMAFDQCPVH";
41
42
@@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = {
43
44
DEFINE_PROP_UINT32("mvendorid", RISCVCPU, cfg.mvendorid, 0),
45
DEFINE_PROP_UINT64("marchid", RISCVCPU, cfg.marchid, RISCV_CPU_MARCHID),
46
- DEFINE_PROP_UINT64("mipid", RISCVCPU, cfg.mipid, RISCV_CPU_MIPID),
47
+ DEFINE_PROP_UINT64("mimpid", RISCVCPU, cfg.mimpid, RISCV_CPU_MIMPID),
48
49
DEFINE_PROP_BOOL("svinval", RISCVCPU, cfg.ext_svinval, false),
50
DEFINE_PROP_BOOL("svnapot", RISCVCPU, cfg.ext_svnapot, false),
19
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
51
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
20
index XXXXXXX..XXXXXXX 100644
52
index XXXXXXX..XXXXXXX 100644
21
--- a/target/riscv/csr.c
53
--- a/target/riscv/csr.c
22
+++ b/target/riscv/csr.c
54
+++ b/target/riscv/csr.c
23
@@ -XXX,XX +XXX,XX @@ static int vs(CPURISCVState *env, int csrno)
55
@@ -XXX,XX +XXX,XX @@ static RISCVException read_marchid(CPURISCVState *env, int csrno,
24
if (env->misa & RVV) {
56
return RISCV_EXCP_NONE;
25
return 0;
26
}
27
- return -1;
28
+ return -RISCV_EXCP_ILLEGAL_INST;
29
}
57
}
30
58
31
static int ctr(CPURISCVState *env, int csrno)
59
-static RISCVException read_mipid(CPURISCVState *env, int csrno,
60
- target_ulong *val)
61
+static RISCVException read_mimpid(CPURISCVState *env, int csrno,
62
+ target_ulong *val)
63
{
64
CPUState *cs = env_cpu(env);
65
RISCVCPU *cpu = RISCV_CPU(cs);
66
67
- *val = cpu->cfg.mipid;
68
+ *val = cpu->cfg.mimpid;
69
return RISCV_EXCP_NONE;
70
}
71
72
@@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
73
/* Machine Information Registers */
74
[CSR_MVENDORID] = { "mvendorid", any, read_mvendorid },
75
[CSR_MARCHID] = { "marchid", any, read_marchid },
76
- [CSR_MIMPID] = { "mimpid", any, read_mipid },
77
+ [CSR_MIMPID] = { "mimpid", any, read_mimpid },
78
[CSR_MHARTID] = { "mhartid", any, read_mhartid },
79
80
[CSR_MCONFIGPTR] = { "mconfigptr", any, read_zero,
32
--
81
--
33
2.30.1
82
2.35.3
34
35
diff view generated by jsdifflib
1
From: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
1
From: Anup Patel <apatel@ventanamicro.com>
2
2
3
Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
3
When hypervisor and VS CSRs are accessed from VS-mode or VU-mode,
4
the riscv_csrrw_check() function should generate virtual instruction
5
trap instead illegal instruction trap.
6
7
Fixes: 0a42f4c44088 (" target/riscv: Fix CSR perm checking for HS mode")
8
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
4
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
5
Message-id: 20210311094902.1377593-1-georg.kotheimer@kernkonzept.com
10
Reviewed-by: Frank Chang <frank.chang@sifive.com>
11
Message-Id: <20220511144528.393530-2-apatel@ventanamicro.com>
6
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
7
---
13
---
8
target/riscv/csr.c | 7 ++++---
14
target/riscv/csr.c | 8 ++++++--
9
1 file changed, 4 insertions(+), 3 deletions(-)
15
1 file changed, 6 insertions(+), 2 deletions(-)
10
16
11
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
17
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
12
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
13
--- a/target/riscv/csr.c
19
--- a/target/riscv/csr.c
14
+++ b/target/riscv/csr.c
20
+++ b/target/riscv/csr.c
15
@@ -XXX,XX +XXX,XX @@ static const target_ulong sstatus_v1_10_mask = SSTATUS_SIE | SSTATUS_SPIE |
21
@@ -XXX,XX +XXX,XX @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env,
16
SSTATUS_UIE | SSTATUS_UPIE | SSTATUS_SPP | SSTATUS_FS | SSTATUS_XS |
22
int read_only = get_field(csrno, 0xC00) == 3;
17
SSTATUS_SUM | SSTATUS_MXR | SSTATUS_SD;
23
int csr_min_priv = csr_ops[csrno].min_priv_ver;
18
static const target_ulong sip_writable_mask = SIP_SSIP | MIP_USIP | MIP_UEIP;
24
#if !defined(CONFIG_USER_ONLY)
19
-static const target_ulong hip_writable_mask = MIP_VSSIP | MIP_VSTIP | MIP_VSEIP;
25
- int effective_priv = env->priv;
20
+static const target_ulong hip_writable_mask = MIP_VSSIP;
26
+ int csr_priv, effective_priv = env->priv;
21
+static const target_ulong hvip_writable_mask = MIP_VSSIP | MIP_VSTIP | MIP_VSEIP;
27
22
static const target_ulong vsip_writable_mask = MIP_VSSIP;
28
if (riscv_has_ext(env, RVH) && env->priv == PRV_S) {
23
29
/*
24
static const char valid_vm_1_10_32[16] = {
30
@@ -XXX,XX +XXX,XX @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env,
25
@@ -XXX,XX +XXX,XX @@ static int rmw_hvip(CPURISCVState *env, int csrno, target_ulong *ret_value,
31
effective_priv++;
26
target_ulong new_value, target_ulong write_mask)
32
}
27
{
33
28
int ret = rmw_mip(env, 0, ret_value, new_value,
34
- if (!env->debugger && (effective_priv < get_field(csrno, 0x300))) {
29
- write_mask & hip_writable_mask);
35
+ csr_priv = get_field(csrno, 0x300);
30
+ write_mask & hvip_writable_mask);
36
+ if (!env->debugger && (effective_priv < csr_priv)) {
31
37
+ if (csr_priv == (PRV_S + 1) && riscv_cpu_virt_enabled(env)) {
32
- *ret_value &= hip_writable_mask;
38
+ return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
33
+ *ret_value &= hvip_writable_mask;
39
+ }
34
40
return RISCV_EXCP_ILLEGAL_INST;
35
return ret;
41
}
36
}
42
#endif
37
--
43
--
38
2.30.1
44
2.35.3
39
40
diff view generated by jsdifflib
1
From: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
1
From: Anup Patel <apatel@ventanamicro.com>
2
2
3
According to the specification the "field SPVP of hstatus controls the
3
Currently, QEMU does not set hstatus.GVA bit for traps taken from
4
privilege level of the access" for the hypervisor virtual-machine load
4
HS-mode into HS-mode which breaks the Xvisor nested MMU test suite
5
and store instructions HLV, HLVX and HSV.
5
on QEMU. This was working previously.
6
6
7
Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
7
This patch updates riscv_cpu_do_interrupt() to fix the above issue.
8
9
Fixes: 86d0c457396b ("target/riscv: Fixup setting GVA")
10
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Message-id: 20210311103005.1400718-1-georg.kotheimer@kernkonzept.com
12
Message-Id: <20220511144528.393530-3-apatel@ventanamicro.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
14
---
12
target/riscv/cpu_helper.c | 25 ++++++++++++++-----------
15
target/riscv/cpu_helper.c | 3 +--
13
1 file changed, 14 insertions(+), 11 deletions(-)
16
1 file changed, 1 insertion(+), 2 deletions(-)
14
17
15
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
18
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
16
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/cpu_helper.c
20
--- a/target/riscv/cpu_helper.c
18
+++ b/target/riscv/cpu_helper.c
21
+++ b/target/riscv/cpu_helper.c
19
@@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,
22
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
20
use_background = true;
23
case RISCV_EXCP_INST_PAGE_FAULT:
21
}
24
case RISCV_EXCP_LOAD_PAGE_FAULT:
22
25
case RISCV_EXCP_STORE_PAGE_FAULT:
23
- if (mode == PRV_M && access_type != MMU_INST_FETCH) {
26
- write_gva = true;
24
+ /* MPRV does not affect the virtual-machine load/store
27
+ write_gva = env->two_stage_lookup;
25
+ instructions, HLV, HLVX, and HSV. */
28
tval = env->badaddr;
26
+ if (riscv_cpu_two_stage_lookup(mmu_idx)) {
29
break;
27
+ mode = get_field(env->hstatus, HSTATUS_SPVP);
30
case RISCV_EXCP_ILLEGAL_INST:
28
+ } else if (mode == PRV_M && access_type != MMU_INST_FETCH) {
31
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
29
if (get_field(env->mstatus, MSTATUS_MPRV)) {
32
/* Trap into HS mode */
30
mode = get_field(env->mstatus, MSTATUS_MPP);
33
env->hstatus = set_field(env->hstatus, HSTATUS_SPV, false);
34
htval = env->guest_phys_fault_addr;
35
- write_gva = false;
36
}
37
env->hstatus = set_field(env->hstatus, HSTATUS_GVA, write_gva);
31
}
38
}
32
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
33
qemu_log_mask(CPU_LOG_MMU, "%s ad %" VADDR_PRIx " rw %d mmu_idx %d\n",
34
__func__, address, access_type, mmu_idx);
35
36
- if (mode == PRV_M && access_type != MMU_INST_FETCH) {
37
- if (get_field(env->mstatus, MSTATUS_MPRV)) {
38
- mode = get_field(env->mstatus, MSTATUS_MPP);
39
+ /* MPRV does not affect the virtual-machine load/store
40
+ instructions, HLV, HLVX, and HSV. */
41
+ if (riscv_cpu_two_stage_lookup(mmu_idx)) {
42
+ mode = get_field(env->hstatus, HSTATUS_SPVP);
43
+ } else if (mode == PRV_M && access_type != MMU_INST_FETCH &&
44
+ get_field(env->mstatus, MSTATUS_MPRV)) {
45
+ mode = get_field(env->mstatus, MSTATUS_MPP);
46
+ if (riscv_has_ext(env, RVH) && get_field(env->mstatus, MSTATUS_MPV)) {
47
+ two_stage_lookup = true;
48
}
49
}
50
51
- if (riscv_has_ext(env, RVH) && env->priv == PRV_M &&
52
- access_type != MMU_INST_FETCH &&
53
- get_field(env->mstatus, MSTATUS_MPRV) &&
54
- get_field(env->mstatus, MSTATUS_MPV)) {
55
- two_stage_lookup = true;
56
- }
57
-
58
if (riscv_cpu_virt_enabled(env) ||
59
((riscv_cpu_two_stage_lookup(mmu_idx) || two_stage_lookup) &&
60
access_type != MMU_INST_FETCH)) {
61
--
39
--
62
2.30.1
40
2.35.3
63
64
diff view generated by jsdifflib
1
From: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
1
From: Anup Patel <apatel@ventanamicro.com>
2
2
3
The current two-stage lookup detection in riscv_cpu_do_interrupt falls
3
Currently, the [m|s]tval CSRs are set with trapping instruction encoding
4
short of its purpose, as all it checks is whether two-stage address
4
only for illegal instruction traps taken at the time of instruction
5
translation either via the hypervisor-load store instructions or the
5
decoding.
6
MPRV feature would be allowed.
7
6
8
What we really need instead is whether two-stage address translation was
7
In RISC-V world, a valid instructions might also trap as illegal or
9
active when the exception was raised. However, in riscv_cpu_do_interrupt
8
virtual instruction based to trapping bits in various CSRs (such as
10
we do not have the information to reliably detect this. Therefore, when
9
mstatus.TVM or hstatus.VTVM).
11
we raise a memory fault exception we have to record whether two-stage
12
address translation is active.
13
10
14
Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
11
We improve setting of [m|s]tval CSRs for all types of illegal and
12
virtual instruction traps.
13
14
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
15
Reviewed-by: Frank Chang <frank.chang@sifive.com>
15
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
16
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
16
Message-id: 20210319141459.1196741-1-georg.kotheimer@kernkonzept.com
17
Message-Id: <20220511144528.393530-4-apatel@ventanamicro.com>
17
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
18
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
18
---
19
---
19
target/riscv/cpu.h | 4 ++++
20
target/riscv/cpu.h | 8 +++++++-
20
target/riscv/cpu.c | 1 +
21
target/riscv/cpu.c | 2 ++
21
target/riscv/cpu_helper.c | 21 ++++++++-------------
22
target/riscv/cpu_helper.c | 1 +
22
3 files changed, 13 insertions(+), 13 deletions(-)
23
target/riscv/translate.c | 17 +++++++++++++----
24
4 files changed, 23 insertions(+), 5 deletions(-)
23
25
24
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
26
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
25
index XXXXXXX..XXXXXXX 100644
27
index XXXXXXX..XXXXXXX 100644
26
--- a/target/riscv/cpu.h
28
--- a/target/riscv/cpu.h
27
+++ b/target/riscv/cpu.h
29
+++ b/target/riscv/cpu.h
28
@@ -XXX,XX +XXX,XX @@ struct CPURISCVState {
30
@@ -XXX,XX +XXX,XX @@
29
target_ulong satp_hs;
31
30
uint64_t mstatus_hs;
32
#define TCG_GUEST_DEFAULT_MO 0
31
33
32
+ /* Signals whether the current exception occurred with two-stage address
34
+/*
33
+ translation active. */
35
+ * RISC-V-specific extra insn start words:
34
+ bool two_stage_lookup;
36
+ * 1: Original instruction opcode
37
+ */
38
+#define TARGET_INSN_START_EXTRA_WORDS 1
35
+
39
+
36
target_ulong scounteren;
40
#define TYPE_RISCV_CPU "riscv-cpu"
37
target_ulong mcounteren;
41
42
#define RISCV_CPU_TYPE_SUFFIX "-" TYPE_RISCV_CPU
43
@@ -XXX,XX +XXX,XX @@ struct CPUArchState {
44
target_ulong frm;
45
46
target_ulong badaddr;
47
- uint32_t bins;
48
+ target_ulong bins;
49
50
target_ulong guest_phys_fault_addr;
38
51
39
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
52
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
40
index XXXXXXX..XXXXXXX 100644
53
index XXXXXXX..XXXXXXX 100644
41
--- a/target/riscv/cpu.c
54
--- a/target/riscv/cpu.c
42
+++ b/target/riscv/cpu.c
55
+++ b/target/riscv/cpu.c
56
@@ -XXX,XX +XXX,XX @@ void restore_state_to_opc(CPURISCVState *env, TranslationBlock *tb,
57
} else {
58
env->pc = data[0];
59
}
60
+ env->bins = data[1];
61
}
62
63
static void riscv_cpu_reset(DeviceState *dev)
43
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset(DeviceState *dev)
64
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset(DeviceState *dev)
44
env->mstatus &= ~(MSTATUS_MIE | MSTATUS_MPRV);
45
env->mcause = 0;
65
env->mcause = 0;
66
env->miclaim = MIP_SGEIP;
46
env->pc = env->resetvec;
67
env->pc = env->resetvec;
47
+ env->two_stage_lookup = false;
68
+ env->bins = 0;
48
#endif
69
env->two_stage_lookup = false;
49
cs->exception_index = EXCP_NONE;
70
50
env->load_res = -1;
71
/* Initialized default priorities of local interrupts. */
51
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
72
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
52
index XXXXXXX..XXXXXXX 100644
73
index XXXXXXX..XXXXXXX 100644
53
--- a/target/riscv/cpu_helper.c
74
--- a/target/riscv/cpu_helper.c
54
+++ b/target/riscv/cpu_helper.c
75
+++ b/target/riscv/cpu_helper.c
55
@@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address,
76
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
56
g_assert_not_reached();
77
tval = env->badaddr;
57
}
78
break;
58
env->badaddr = address;
79
case RISCV_EXCP_ILLEGAL_INST:
59
+ env->two_stage_lookup = two_stage;
80
+ case RISCV_EXCP_VIRT_INSTRUCTION_FAULT:
81
tval = env->bins;
82
break;
83
default:
84
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
85
index XXXXXXX..XXXXXXX 100644
86
--- a/target/riscv/translate.c
87
+++ b/target/riscv/translate.c
88
@@ -XXX,XX +XXX,XX @@ typedef struct DisasContext {
89
/* PointerMasking extension */
90
bool pm_mask_enabled;
91
bool pm_base_enabled;
92
+ /* TCG of the current insn_start */
93
+ TCGOp *insn_start;
94
} DisasContext;
95
96
static inline bool has_ext(DisasContext *ctx, uint32_t ext)
97
@@ -XXX,XX +XXX,XX @@ static void generate_exception_mtval(DisasContext *ctx, int excp)
98
99
static void gen_exception_illegal(DisasContext *ctx)
100
{
101
- tcg_gen_st_i32(tcg_constant_i32(ctx->opcode), cpu_env,
102
- offsetof(CPURISCVState, bins));
103
-
104
generate_exception(ctx, RISCV_EXCP_ILLEGAL_INST);
60
}
105
}
61
106
62
hwaddr riscv_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
107
@@ -XXX,XX +XXX,XX @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)
63
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr,
108
/* Include decoders for factored-out extensions */
64
}
109
#include "decode-XVentanaCondOps.c.inc"
65
110
66
env->badaddr = addr;
111
+static inline void decode_save_opc(DisasContext *ctx, target_ulong opc)
67
+ env->two_stage_lookup = riscv_cpu_virt_enabled(env) ||
112
+{
68
+ riscv_cpu_two_stage_lookup(mmu_idx);
113
+ assert(ctx->insn_start != NULL);
69
riscv_raise_exception(&cpu->env, cs->exception_index, retaddr);
114
+ tcg_set_insn_start_param(ctx->insn_start, 1, opc);
115
+ ctx->insn_start = NULL;
116
+}
117
+
118
static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode)
119
{
120
/*
121
@@ -XXX,XX +XXX,XX @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode)
122
123
/* Check for compressed insn */
124
if (extract16(opcode, 0, 2) != 3) {
125
+ decode_save_opc(ctx, opcode);
126
if (!has_ext(ctx, RVC)) {
127
gen_exception_illegal(ctx);
128
} else {
129
@@ -XXX,XX +XXX,XX @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode)
130
opcode32 = deposit32(opcode32, 16, 16,
131
translator_lduw(env, &ctx->base,
132
ctx->base.pc_next + 2));
133
+ decode_save_opc(ctx, opcode32);
134
ctx->opcode = opcode32;
135
ctx->pc_succ_insn = ctx->base.pc_next + 4;
136
137
@@ -XXX,XX +XXX,XX @@ static void riscv_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu)
138
{
139
DisasContext *ctx = container_of(dcbase, DisasContext, base);
140
141
- tcg_gen_insn_start(ctx->base.pc_next);
142
+ tcg_gen_insn_start(ctx->base.pc_next, 0);
143
+ ctx->insn_start = tcg_last_op();
70
}
144
}
71
145
72
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr,
146
static void riscv_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
73
g_assert_not_reached();
74
}
75
env->badaddr = addr;
76
+ env->two_stage_lookup = riscv_cpu_virt_enabled(env) ||
77
+ riscv_cpu_two_stage_lookup(mmu_idx);
78
riscv_raise_exception(env, cs->exception_index, retaddr);
79
}
80
#endif /* !CONFIG_USER_ONLY */
81
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
82
/* handle the trap in S-mode */
83
if (riscv_has_ext(env, RVH)) {
84
target_ulong hdeleg = async ? env->hideleg : env->hedeleg;
85
- bool two_stage_lookup = false;
86
87
- if (env->priv == PRV_M ||
88
- (env->priv == PRV_S && !riscv_cpu_virt_enabled(env)) ||
89
- (env->priv == PRV_U && !riscv_cpu_virt_enabled(env) &&
90
- get_field(env->hstatus, HSTATUS_HU))) {
91
- two_stage_lookup = true;
92
- }
93
-
94
- if ((riscv_cpu_virt_enabled(env) || two_stage_lookup) && write_tval) {
95
+ if (env->two_stage_lookup && write_tval) {
96
/*
97
* If we are writing a guest virtual address to stval, set
98
* this to 1. If we are trapping to VS we will set this to 0
99
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
100
riscv_cpu_set_force_hs_excep(env, 0);
101
} else {
102
/* Trap into HS mode */
103
- if (!two_stage_lookup) {
104
- env->hstatus = set_field(env->hstatus, HSTATUS_SPV,
105
- riscv_cpu_virt_enabled(env));
106
- }
107
+ env->hstatus = set_field(env->hstatus, HSTATUS_SPV, false);
108
htval = env->guest_phys_fault_addr;
109
}
110
}
111
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
112
* RISC-V ISA Specification.
113
*/
114
115
+ env->two_stage_lookup = false;
116
#endif
117
cs->exception_index = EXCP_NONE; /* mark handled to qemu */
118
}
119
--
147
--
120
2.30.1
148
2.35.3
121
122
diff view generated by jsdifflib
1
From: Asherah Connor <ashe@kivikakk.ee>
1
From: Anup Patel <apatel@ventanamicro.com>
2
2
3
Allow ramfb on virt. This lets `-device ramfb' work.
3
When both APLIC and IMSIC are present in virt machine, the APLIC should
4
be used as parent interrupt controller for dynamic platform devices.
4
5
5
Signed-off-by: Asherah Connor <ashe@kivikakk.ee>
6
In case of multiple sockets, we should prefer interrupt controller of
6
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
7
socket0 for dynamic platform devices.
8
9
Fixes: 3029fab64309 ("hw/riscv: virt: Add support for generating
10
platform FDT entries")
11
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
12
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Message-id: 20210318235041.17175-3-ashe@kivikakk.ee
13
Message-Id: <20220511144528.393530-9-apatel@ventanamicro.com>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
---
15
---
11
hw/riscv/virt.c | 3 +++
16
hw/riscv/virt.c | 25 ++++++++++++-------------
12
1 file changed, 3 insertions(+)
17
1 file changed, 12 insertions(+), 13 deletions(-)
13
18
14
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
19
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
15
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/riscv/virt.c
21
--- a/hw/riscv/virt.c
17
+++ b/hw/riscv/virt.c
22
+++ b/hw/riscv/virt.c
18
@@ -XXX,XX +XXX,XX @@
23
@@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_plic(RISCVVirtState *s,
19
#include "sysemu/sysemu.h"
24
qemu_fdt_setprop_cell(mc->fdt, plic_name, "phandle",
20
#include "hw/pci/pci.h"
25
plic_phandles[socket]);
21
#include "hw/pci-host/gpex.h"
26
22
+#include "hw/display/ramfb.h"
27
- platform_bus_add_all_fdt_nodes(mc->fdt, plic_name,
23
28
- memmap[VIRT_PLATFORM_BUS].base,
24
static const MemMapEntry virt_memmap[] = {
29
- memmap[VIRT_PLATFORM_BUS].size,
25
[VIRT_DEBUG] = { 0x0, 0x100 },
30
- VIRT_PLATFORM_BUS_IRQ);
26
@@ -XXX,XX +XXX,XX @@ static void virt_machine_class_init(ObjectClass *oc, void *data)
31
+ if (!socket) {
27
mc->cpu_index_to_instance_props = riscv_numa_cpu_index_to_props;
32
+ platform_bus_add_all_fdt_nodes(mc->fdt, plic_name,
28
mc->get_default_cpu_node_id = riscv_numa_get_default_cpu_node_id;
33
+ memmap[VIRT_PLATFORM_BUS].base,
29
mc->numa_mem_supported = true;
34
+ memmap[VIRT_PLATFORM_BUS].size,
30
+
35
+ VIRT_PLATFORM_BUS_IRQ);
31
+ machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE);
36
+ }
32
}
37
33
38
g_free(plic_name);
34
static const TypeInfo virt_machine_typeinfo = {
39
40
@@ -XXX,XX +XXX,XX @@ static void create_fdt_imsic(RISCVVirtState *s, const MemMapEntry *memmap,
41
}
42
qemu_fdt_setprop_cell(mc->fdt, imsic_name, "phandle", *msi_m_phandle);
43
44
- platform_bus_add_all_fdt_nodes(mc->fdt, imsic_name,
45
- memmap[VIRT_PLATFORM_BUS].base,
46
- memmap[VIRT_PLATFORM_BUS].size,
47
- VIRT_PLATFORM_BUS_IRQ);
48
-
49
g_free(imsic_name);
50
51
/* S-level IMSIC node */
52
@@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_aplic(RISCVVirtState *s,
53
riscv_socket_fdt_write_id(mc, mc->fdt, aplic_name, socket);
54
qemu_fdt_setprop_cell(mc->fdt, aplic_name, "phandle", aplic_s_phandle);
55
56
- platform_bus_add_all_fdt_nodes(mc->fdt, aplic_name,
57
- memmap[VIRT_PLATFORM_BUS].base,
58
- memmap[VIRT_PLATFORM_BUS].size,
59
- VIRT_PLATFORM_BUS_IRQ);
60
+ if (!socket) {
61
+ platform_bus_add_all_fdt_nodes(mc->fdt, aplic_name,
62
+ memmap[VIRT_PLATFORM_BUS].base,
63
+ memmap[VIRT_PLATFORM_BUS].size,
64
+ VIRT_PLATFORM_BUS_IRQ);
65
+ }
66
67
g_free(aplic_name);
68
35
--
69
--
36
2.30.1
70
2.35.3
37
38
diff view generated by jsdifflib
1
From: Bin Meng <bin.meng@windriver.com>
1
From: "Hongren (Zenithal) Zheng" <i@zenithal.me>
2
2
3
This adds the documentation to describe what is supported for the
3
Zicsr/Zifencei is not in 'I' since ISA version 20190608,
4
'microchip-icicle-kit' machine, and how to boot the machine in QEMU.
4
thus to fully express the capability of the CPU,
5
they should be exposed in isa_string.
5
6
6
Signed-off-by: Bin Meng <bin.meng@windriver.com>
7
Signed-off-by: Hongren (Zenithal) Zheng <i@zenithal.me>
8
Tested-by: Jiatai He <jiatai2021@iscas.ac.cn>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Message-id: 20210322075248.136255-2-bmeng.cn@gmail.com
10
Message-Id: <YoTqwpfrodveJ7CR@Sun>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
---
12
---
11
docs/system/riscv/microchip-icicle-kit.rst | 89 ++++++++++++++++++++++
13
target/riscv/cpu.c | 2 ++
12
docs/system/target-riscv.rst | 1 +
14
1 file changed, 2 insertions(+)
13
2 files changed, 90 insertions(+)
14
create mode 100644 docs/system/riscv/microchip-icicle-kit.rst
15
15
16
diff --git a/docs/system/riscv/microchip-icicle-kit.rst b/docs/system/riscv/microchip-icicle-kit.rst
16
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
17
new file mode 100644
18
index XXXXXXX..XXXXXXX
19
--- /dev/null
20
+++ b/docs/system/riscv/microchip-icicle-kit.rst
21
@@ -XXX,XX +XXX,XX @@
22
+Microchip PolarFire SoC Icicle Kit (``microchip-icicle-kit``)
23
+=============================================================
24
+
25
+Microchip PolarFire SoC Icicle Kit integrates a PolarFire SoC, with one
26
+SiFive's E51 plus four U54 cores and many on-chip peripherals and an FPGA.
27
+
28
+For more details about Microchip PolarFire SoC, please see:
29
+https://www.microsemi.com/product-directory/soc-fpgas/5498-polarfire-soc-fpga
30
+
31
+The Icicle Kit board information can be found here:
32
+https://www.microsemi.com/existing-parts/parts/152514
33
+
34
+Supported devices
35
+-----------------
36
+
37
+The ``microchip-icicle-kit`` machine supports the following devices:
38
+
39
+ * 1 E51 core
40
+ * 4 U54 cores
41
+ * Core Level Interruptor (CLINT)
42
+ * Platform-Level Interrupt Controller (PLIC)
43
+ * L2 Loosely Integrated Memory (L2-LIM)
44
+ * DDR memory controller
45
+ * 5 MMUARTs
46
+ * 1 DMA controller
47
+ * 2 GEM Ethernet controllers
48
+ * 1 SDHC storage controller
49
+
50
+Boot options
51
+------------
52
+
53
+The ``microchip-icicle-kit`` machine can start using the standard -bios
54
+functionality for loading its BIOS image, aka Hart Software Services (HSS_).
55
+HSS loads the second stage bootloader U-Boot from an SD card. It does not
56
+support direct kernel loading via the -kernel option. One has to load kernel
57
+from U-Boot.
58
+
59
+The memory is set to 1537 MiB by default which is the minimum required high
60
+memory size by HSS. A sanity check on ram size is performed in the machine
61
+init routine to prompt user to increase the RAM size to > 1537 MiB when less
62
+than 1537 MiB ram is detected.
63
+
64
+Boot the machine
65
+----------------
66
+
67
+HSS 2020.12 release is tested at the time of writing. To build an HSS image
68
+that can be booted by the ``microchip-icicle-kit`` machine, type the following
69
+in the HSS source tree:
70
+
71
+.. code-block:: bash
72
+
73
+ $ export CROSS_COMPILE=riscv64-linux-
74
+ $ cp boards/mpfs-icicle-kit-es/def_config .config
75
+ $ make BOARD=mpfs-icicle-kit-es
76
+
77
+Download the official SD card image released by Microchip and prepare it for
78
+QEMU usage:
79
+
80
+.. code-block:: bash
81
+
82
+ $ wget ftp://ftpsoc.microsemi.com/outgoing/core-image-minimal-dev-icicle-kit-es-sd-20201009141623.rootfs.wic.gz
83
+ $ gunzip core-image-minimal-dev-icicle-kit-es-sd-20201009141623.rootfs.wic.gz
84
+ $ qemu-img resize core-image-minimal-dev-icicle-kit-es-sd-20201009141623.rootfs.wic 4G
85
+
86
+Then we can boot the machine by:
87
+
88
+.. code-block:: bash
89
+
90
+ $ qemu-system-riscv64 -M microchip-icicle-kit -smp 5 \
91
+ -bios path/to/hss.bin -sd path/to/sdcard.img \
92
+ -nic user,model=cadence_gem \
93
+ -nic tap,ifname=tap,model=cadence_gem,script=no \
94
+ -display none -serial stdio \
95
+ -chardev socket,id=serial1,path=serial1.sock,server=on,wait=on \
96
+ -serial chardev:serial1
97
+
98
+With above command line, current terminal session will be used for the first
99
+serial port. Open another terminal window, and use `minicom` to connect the
100
+second serial port.
101
+
102
+.. code-block:: bash
103
+
104
+ $ minicom -D unix\#serial1.sock
105
+
106
+HSS output is on the first serial port (stdio) and U-Boot outputs on the
107
+second serial port. U-Boot will automatically load the Linux kernel from
108
+the SD card image.
109
+
110
+.. _HSS: https://github.com/polarfire-soc/hart-software-services
111
diff --git a/docs/system/target-riscv.rst b/docs/system/target-riscv.rst
112
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
113
--- a/docs/system/target-riscv.rst
18
--- a/target/riscv/cpu.c
114
+++ b/docs/system/target-riscv.rst
19
+++ b/target/riscv/cpu.c
115
@@ -XXX,XX +XXX,XX @@ undocumented; you can get a complete list by running
20
@@ -XXX,XX +XXX,XX @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)
116
.. toctree::
21
* extensions by an underscore.
117
:maxdepth: 1
22
*/
118
23
struct isa_ext_data isa_edata_arr[] = {
119
+ riscv/microchip-icicle-kit
24
+ ISA_EDATA_ENTRY(zicsr, ext_icsr),
120
riscv/sifive_u
25
+ ISA_EDATA_ENTRY(zifencei, ext_ifencei),
121
26
ISA_EDATA_ENTRY(zfh, ext_zfh),
122
RISC-V CPU features
27
ISA_EDATA_ENTRY(zfhmin, ext_zfhmin),
28
ISA_EDATA_ENTRY(zfinx, ext_zfinx),
123
--
29
--
124
2.30.1
30
2.35.3
125
126
diff view generated by jsdifflib
1
From: Bin Meng <bin.meng@windriver.com>
1
From: Bin Meng <bin.meng@windriver.com>
2
2
3
Since HSS commit c20a89f8dcac, the Icicle Kit reference design has
3
Sync uboot_image.h from upstream U-Boot v2022.01 release [1].
4
been updated to use a register mapped at 0x4f000000 instead of a
4
5
GPIO to control whether eMMC or SD card is to be used. With this
5
[1] https://source.denx.de/u-boot/u-boot/-/blob/v2022.01/include/image.h
6
support the same HSS image can be used for both eMMC and SD card
7
boot flow, while previously two different board configurations were
8
used. This is undocumented but one can take a look at the HSS code
9
HSS_MMCInit() in services/mmc/mmc_api.c.
10
11
With this commit, HSS image built from 2020.12 release boots again.
12
6
13
Signed-off-by: Bin Meng <bin.meng@windriver.com>
7
Signed-off-by: Bin Meng <bin.meng@windriver.com>
14
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
15
Message-id: 20210322075248.136255-1-bmeng.cn@gmail.com
9
Message-Id: <20220324134812.541274-1-bmeng.cn@gmail.com>
16
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
17
---
11
---
18
include/hw/riscv/microchip_pfsoc.h | 1 +
12
hw/core/uboot_image.h | 213 ++++++++++++++++++++++++++++--------------
19
hw/riscv/microchip_pfsoc.c | 6 ++++++
13
1 file changed, 142 insertions(+), 71 deletions(-)
20
2 files changed, 7 insertions(+)
14
21
15
diff --git a/hw/core/uboot_image.h b/hw/core/uboot_image.h
22
diff --git a/include/hw/riscv/microchip_pfsoc.h b/include/hw/riscv/microchip_pfsoc.h
23
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
24
--- a/include/hw/riscv/microchip_pfsoc.h
17
--- a/hw/core/uboot_image.h
25
+++ b/include/hw/riscv/microchip_pfsoc.h
18
+++ b/hw/core/uboot_image.h
26
@@ -XXX,XX +XXX,XX @@ enum {
19
@@ -XXX,XX +XXX,XX @@
27
MICROCHIP_PFSOC_ENVM_DATA,
20
+/* SPDX-License-Identifier: GPL-2.0+ */
28
MICROCHIP_PFSOC_QSPI_XIP,
21
/*
29
MICROCHIP_PFSOC_IOSCB,
22
+ * (C) Copyright 2008 Semihalf
30
+ MICROCHIP_PFSOC_EMMC_SD_MUX,
23
+ *
31
MICROCHIP_PFSOC_DRAM_LO,
24
* (C) Copyright 2000-2005
32
MICROCHIP_PFSOC_DRAM_LO_ALIAS,
25
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
33
MICROCHIP_PFSOC_DRAM_HI,
26
- *
34
diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c
27
- * See file CREDITS for list of people who contributed to this
35
index XXXXXXX..XXXXXXX 100644
28
- * project.
36
--- a/hw/riscv/microchip_pfsoc.c
29
- *
37
+++ b/hw/riscv/microchip_pfsoc.c
30
- * This program is free software; you can redistribute it and/or
38
@@ -XXX,XX +XXX,XX @@ static const MemMapEntry microchip_pfsoc_memmap[] = {
31
- * modify it under the terms of the GNU General Public License as
39
[MICROCHIP_PFSOC_ENVM_DATA] = { 0x20220000, 0x20000 },
32
- * published by the Free Software Foundation; either version 2 of
40
[MICROCHIP_PFSOC_QSPI_XIP] = { 0x21000000, 0x1000000 },
33
- * the License, or (at your option) any later version.
41
[MICROCHIP_PFSOC_IOSCB] = { 0x30000000, 0x10000000 },
34
- *
42
+ [MICROCHIP_PFSOC_EMMC_SD_MUX] = { 0x4f000000, 0x4 },
35
- * This program is distributed in the hope that it will be useful,
43
[MICROCHIP_PFSOC_DRAM_LO] = { 0x80000000, 0x40000000 },
36
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
44
[MICROCHIP_PFSOC_DRAM_LO_ALIAS] = { 0xc0000000, 0x40000000 },
37
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
45
[MICROCHIP_PFSOC_DRAM_HI] = { 0x1000000000, 0x0 },
38
- * GNU General Public License for more details.
46
@@ -XXX,XX +XXX,XX @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
39
- *
47
sysbus_mmio_map(SYS_BUS_DEVICE(&s->ioscb), 0,
40
- * You should have received a copy of the GNU General Public License along
48
memmap[MICROCHIP_PFSOC_IOSCB].base);
41
- * with this program; if not, see <http://www.gnu.org/licenses/>.
49
42
- *
50
+ /* eMMC/SD mux */
43
********************************************************************
51
+ create_unimplemented_device("microchip.pfsoc.emmc_sd_mux",
44
* NOTE: This header file defines an interface to U-Boot. Including
52
+ memmap[MICROCHIP_PFSOC_EMMC_SD_MUX].base,
45
* this (unmodified) header file in another file is considered normal
53
+ memmap[MICROCHIP_PFSOC_EMMC_SD_MUX].size);
46
@@ -XXX,XX +XXX,XX @@
54
+
47
55
/* QSPI Flash */
48
/*
56
memory_region_init_rom(qspi_xip_mem, OBJECT(dev),
49
* Operating System Codes
57
"microchip.pfsoc.qspi_xip",
50
+ *
51
+ * The following are exposed to uImage header.
52
+ * New IDs *MUST* be appended at the end of the list and *NEVER*
53
+ * inserted for backward compatibility.
54
*/
55
-#define IH_OS_INVALID        0    /* Invalid OS    */
56
-#define IH_OS_OPENBSD        1    /* OpenBSD    */
57
-#define IH_OS_NETBSD        2    /* NetBSD    */
58
-#define IH_OS_FREEBSD        3    /* FreeBSD    */
59
-#define IH_OS_4_4BSD        4    /* 4.4BSD    */
60
-#define IH_OS_LINUX        5    /* Linux    */
61
-#define IH_OS_SVR4        6    /* SVR4        */
62
-#define IH_OS_ESIX        7    /* Esix        */
63
-#define IH_OS_SOLARIS        8    /* Solaris    */
64
-#define IH_OS_IRIX        9    /* Irix        */
65
-#define IH_OS_SCO        10    /* SCO        */
66
-#define IH_OS_DELL        11    /* Dell        */
67
-#define IH_OS_NCR        12    /* NCR        */
68
-#define IH_OS_LYNXOS        13    /* LynxOS    */
69
-#define IH_OS_VXWORKS        14    /* VxWorks    */
70
-#define IH_OS_PSOS        15    /* pSOS        */
71
-#define IH_OS_QNX        16    /* QNX        */
72
-#define IH_OS_U_BOOT        17    /* Firmware    */
73
-#define IH_OS_RTEMS        18    /* RTEMS    */
74
-#define IH_OS_ARTOS        19    /* ARTOS    */
75
-#define IH_OS_UNITY        20    /* Unity OS    */
76
+enum {
77
+    IH_OS_INVALID        = 0,    /* Invalid OS    */
78
+    IH_OS_OPENBSD,            /* OpenBSD    */
79
+    IH_OS_NETBSD,            /* NetBSD    */
80
+    IH_OS_FREEBSD,            /* FreeBSD    */
81
+    IH_OS_4_4BSD,            /* 4.4BSD    */
82
+    IH_OS_LINUX,            /* Linux    */
83
+    IH_OS_SVR4,            /* SVR4        */
84
+    IH_OS_ESIX,            /* Esix        */
85
+    IH_OS_SOLARIS,            /* Solaris    */
86
+    IH_OS_IRIX,            /* Irix        */
87
+    IH_OS_SCO,            /* SCO        */
88
+    IH_OS_DELL,            /* Dell        */
89
+    IH_OS_NCR,            /* NCR        */
90
+    IH_OS_LYNXOS,            /* LynxOS    */
91
+    IH_OS_VXWORKS,            /* VxWorks    */
92
+    IH_OS_PSOS,            /* pSOS        */
93
+    IH_OS_QNX,            /* QNX        */
94
+    IH_OS_U_BOOT,            /* Firmware    */
95
+    IH_OS_RTEMS,            /* RTEMS    */
96
+    IH_OS_ARTOS,            /* ARTOS    */
97
+    IH_OS_UNITY,            /* Unity OS    */
98
+    IH_OS_INTEGRITY,        /* INTEGRITY    */
99
+    IH_OS_OSE,            /* OSE        */
100
+    IH_OS_PLAN9,            /* Plan 9    */
101
+    IH_OS_OPENRTOS,        /* OpenRTOS    */
102
+    IH_OS_ARM_TRUSTED_FIRMWARE, /* ARM Trusted Firmware */
103
+    IH_OS_TEE,            /* Trusted Execution Environment */
104
+    IH_OS_OPENSBI,            /* RISC-V OpenSBI */
105
+    IH_OS_EFI,            /* EFI Firmware (e.g. GRUB2) */
106
+
107
+    IH_OS_COUNT,
108
+};
109
110
/*
111
* CPU Architecture Codes (supported by Linux)
112
+ *
113
+ * The following are exposed to uImage header.
114
+ * New IDs *MUST* be appended at the end of the list and *NEVER*
115
+ * inserted for backward compatibility.
116
*/
117
-#define IH_CPU_INVALID        0    /* Invalid CPU    */
118
-#define IH_CPU_ALPHA        1    /* Alpha    */
119
-#define IH_CPU_ARM        2    /* ARM        */
120
-#define IH_CPU_I386        3    /* Intel x86    */
121
-#define IH_CPU_IA64        4    /* IA64        */
122
-#define IH_CPU_MIPS        5    /* MIPS        */
123
-#define IH_CPU_MIPS64        6    /* MIPS     64 Bit */
124
-#define IH_CPU_PPC        7    /* PowerPC    */
125
-#define IH_CPU_S390        8    /* IBM S390    */
126
-#define IH_CPU_SH        9    /* SuperH    */
127
-#define IH_CPU_SPARC        10    /* Sparc    */
128
-#define IH_CPU_SPARC64        11    /* Sparc 64 Bit */
129
-#define IH_CPU_M68K        12    /* M68K        */
130
-#define IH_CPU_NIOS        13    /* Nios-32    */
131
-#define IH_CPU_MICROBLAZE    14    /* MicroBlaze */
132
-#define IH_CPU_NIOS2        15    /* Nios-II    */
133
-#define IH_CPU_BLACKFIN        16    /* Blackfin    */
134
-#define IH_CPU_AVR32        17    /* AVR32    */
135
+enum {
136
+    IH_ARCH_INVALID        = 0,    /* Invalid CPU    */
137
+    IH_ARCH_ALPHA,            /* Alpha    */
138
+    IH_ARCH_ARM,            /* ARM        */
139
+    IH_ARCH_I386,            /* Intel x86    */
140
+    IH_ARCH_IA64,            /* IA64        */
141
+    IH_ARCH_MIPS,            /* MIPS        */
142
+    IH_ARCH_MIPS64,            /* MIPS     64 Bit */
143
+    IH_ARCH_PPC,            /* PowerPC    */
144
+    IH_ARCH_S390,            /* IBM S390    */
145
+    IH_ARCH_SH,            /* SuperH    */
146
+    IH_ARCH_SPARC,            /* Sparc    */
147
+    IH_ARCH_SPARC64,        /* Sparc 64 Bit */
148
+    IH_ARCH_M68K,            /* M68K        */
149
+    IH_ARCH_NIOS,            /* Nios-32    */
150
+    IH_ARCH_MICROBLAZE,        /* MicroBlaze */
151
+    IH_ARCH_NIOS2,            /* Nios-II    */
152
+    IH_ARCH_BLACKFIN,        /* Blackfin    */
153
+    IH_ARCH_AVR32,            /* AVR32    */
154
+    IH_ARCH_ST200,            /* STMicroelectronics ST200 */
155
+    IH_ARCH_SANDBOX,        /* Sandbox architecture (test only) */
156
+    IH_ARCH_NDS32,            /* ANDES Technology - NDS32 */
157
+    IH_ARCH_OPENRISC,        /* OpenRISC 1000 */
158
+    IH_ARCH_ARM64,            /* ARM64    */
159
+    IH_ARCH_ARC,            /* Synopsys DesignWare ARC */
160
+    IH_ARCH_X86_64,            /* AMD x86_64, Intel and Via */
161
+    IH_ARCH_XTENSA,            /* Xtensa    */
162
+    IH_ARCH_RISCV,            /* RISC-V */
163
+
164
+    IH_ARCH_COUNT,
165
+};
166
167
/*
168
* Image Types
169
@@ -XXX,XX +XXX,XX @@
170
*    U-Boot's command interpreter; this feature is especially
171
*    useful when you configure U-Boot to use a real shell (hush)
172
*    as command interpreter (=> Shell Scripts).
173
+ *
174
+ * The following are exposed to uImage header.
175
+ * New IDs *MUST* be appended at the end of the list and *NEVER*
176
+ * inserted for backward compatibility.
177
*/
178
179
-#define IH_TYPE_INVALID        0    /* Invalid Image        */
180
-#define IH_TYPE_STANDALONE    1    /* Standalone Program        */
181
-#define IH_TYPE_KERNEL        2    /* OS Kernel Image        */
182
-#define IH_TYPE_RAMDISK        3    /* RAMDisk Image        */
183
-#define IH_TYPE_MULTI        4    /* Multi-File Image        */
184
-#define IH_TYPE_FIRMWARE    5    /* Firmware Image        */
185
-#define IH_TYPE_SCRIPT        6    /* Script file            */
186
-#define IH_TYPE_FILESYSTEM    7    /* Filesystem Image (any type)    */
187
-#define IH_TYPE_FLATDT        8    /* Binary Flat Device Tree Blob    */
188
-#define IH_TYPE_KERNEL_NOLOAD 14    /* OS Kernel Image (noload)    */
189
+enum {
190
+    IH_TYPE_INVALID        = 0,    /* Invalid Image        */
191
+    IH_TYPE_STANDALONE,        /* Standalone Program        */
192
+    IH_TYPE_KERNEL,            /* OS Kernel Image        */
193
+    IH_TYPE_RAMDISK,        /* RAMDisk Image        */
194
+    IH_TYPE_MULTI,            /* Multi-File Image        */
195
+    IH_TYPE_FIRMWARE,        /* Firmware Image        */
196
+    IH_TYPE_SCRIPT,            /* Script file            */
197
+    IH_TYPE_FILESYSTEM,        /* Filesystem Image (any type)    */
198
+    IH_TYPE_FLATDT,            /* Binary Flat Device Tree Blob    */
199
+    IH_TYPE_KWBIMAGE,        /* Kirkwood Boot Image        */
200
+    IH_TYPE_IMXIMAGE,        /* Freescale IMXBoot Image    */
201
+    IH_TYPE_UBLIMAGE,        /* Davinci UBL Image        */
202
+    IH_TYPE_OMAPIMAGE,        /* TI OMAP Config Header Image    */
203
+    IH_TYPE_AISIMAGE,        /* TI Davinci AIS Image        */
204
+    /* OS Kernel Image, can run from any load address */
205
+    IH_TYPE_KERNEL_NOLOAD,
206
+    IH_TYPE_PBLIMAGE,        /* Freescale PBL Boot Image    */
207
+    IH_TYPE_MXSIMAGE,        /* Freescale MXSBoot Image    */
208
+    IH_TYPE_GPIMAGE,        /* TI Keystone GPHeader Image    */
209
+    IH_TYPE_ATMELIMAGE,        /* ATMEL ROM bootable Image    */
210
+    IH_TYPE_SOCFPGAIMAGE,        /* Altera SOCFPGA CV/AV Preloader */
211
+    IH_TYPE_X86_SETUP,        /* x86 setup.bin Image        */
212
+    IH_TYPE_LPC32XXIMAGE,        /* x86 setup.bin Image        */
213
+    IH_TYPE_LOADABLE,        /* A list of typeless images    */
214
+    IH_TYPE_RKIMAGE,        /* Rockchip Boot Image        */
215
+    IH_TYPE_RKSD,            /* Rockchip SD card        */
216
+    IH_TYPE_RKSPI,            /* Rockchip SPI image        */
217
+    IH_TYPE_ZYNQIMAGE,        /* Xilinx Zynq Boot Image */
218
+    IH_TYPE_ZYNQMPIMAGE,        /* Xilinx ZynqMP Boot Image */
219
+    IH_TYPE_ZYNQMPBIF,        /* Xilinx ZynqMP Boot Image (bif) */
220
+    IH_TYPE_FPGA,            /* FPGA Image */
221
+    IH_TYPE_VYBRIDIMAGE,    /* VYBRID .vyb Image */
222
+    IH_TYPE_TEE, /* Trusted Execution Environment OS Image */
223
+    IH_TYPE_FIRMWARE_IVT,        /* Firmware Image with HABv4 IVT */
224
+    IH_TYPE_PMMC, /* TI Power Management Micro-Controller Firmware */
225
+    IH_TYPE_STM32IMAGE,        /* STMicroelectronics STM32 Image */
226
+    IH_TYPE_SOCFPGAIMAGE_V1,    /* Altera SOCFPGA A10 Preloader    */
227
+    IH_TYPE_MTKIMAGE,        /* MediaTek BootROM loadable Image */
228
+    IH_TYPE_IMX8MIMAGE,        /* Freescale IMX8MBoot Image    */
229
+    IH_TYPE_IMX8IMAGE,        /* Freescale IMX8Boot Image    */
230
+    IH_TYPE_COPRO,            /* Coprocessor Image for remoteproc*/
231
+    IH_TYPE_SUNXI_EGON,        /* Allwinner eGON Boot Image */
232
+
233
+    IH_TYPE_COUNT,            /* Number of image types */
234
+};
235
236
/*
237
* Compression Types
238
+ *
239
+ * The following are exposed to uImage header.
240
+ * New IDs *MUST* be appended at the end of the list and *NEVER*
241
+ * inserted for backward compatibility.
242
*/
243
-#define IH_COMP_NONE        0    /* No     Compression Used    */
244
-#define IH_COMP_GZIP        1    /* gzip     Compression Used    */
245
-#define IH_COMP_BZIP2        2    /* bzip2 Compression Used    */
246
+enum {
247
+    IH_COMP_NONE        = 0,    /* No     Compression Used    */
248
+    IH_COMP_GZIP,            /* gzip     Compression Used    */
249
+    IH_COMP_BZIP2,            /* bzip2 Compression Used    */
250
+    IH_COMP_LZMA,            /* lzma Compression Used    */
251
+    IH_COMP_LZO,            /* lzo Compression Used    */
252
+    IH_COMP_LZ4,            /* lz4 Compression Used    */
253
+    IH_COMP_ZSTD,            /* zstd Compression Used    */
254
+
255
+    IH_COMP_COUNT,
256
+};
257
258
#define IH_MAGIC    0x27051956    /* Image Magic Number        */
259
#define IH_NMLEN        32    /* Image Name Length        */
260
261
/*
262
- * all data in network byte order (aka natural aka bigendian)
263
+ * Legacy format image header,
264
+ * all data in network byte order (aka natural aka bigendian).
265
*/
266
-
267
typedef struct uboot_image_header {
268
    uint32_t    ih_magic;    /* Image Header Magic Number    */
269
    uint32_t    ih_hcrc;    /* Image Header CRC Checksum    */
58
--
270
--
59
2.30.1
271
2.35.3
60
61
diff view generated by jsdifflib
1
From: Bin Meng <bin.meng@windriver.com>
1
From: Bin Meng <bin.meng@windriver.com>
2
2
3
Per SST25VF016B datasheet [1], SST flash requires a dummy byte after
3
VxWorks 7 uses the same boot interface as the Linux kernel on Arm
4
the address bytes. Note only SPI mode is supported by SST flashes.
4
(64-bit only), PowerPC and RISC-V architectures. Add logic to set
5
5
is_linux to true for VxWorks uImage for these architectures in
6
[1] http://ww1.microchip.com/downloads/en/devicedoc/s71271_04.pdf
6
load_uboot_image().
7
7
8
Signed-off-by: Bin Meng <bin.meng@windriver.com>
8
Signed-off-by: Bin Meng <bin.meng@windriver.com>
9
Acked-by: Alistair Francis <alistair.francis@wdc.com>
9
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
10
Message-id: 20210306060152.7250-1-bmeng.cn@gmail.com
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Message-Id: <20220324134812.541274-2-bmeng.cn@gmail.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
13
---
13
hw/block/m25p80.c | 3 +++
14
hw/core/loader.c | 15 +++++++++++++++
14
1 file changed, 3 insertions(+)
15
1 file changed, 15 insertions(+)
15
16
16
diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
17
diff --git a/hw/core/loader.c b/hw/core/loader.c
17
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/block/m25p80.c
19
--- a/hw/core/loader.c
19
+++ b/hw/block/m25p80.c
20
+++ b/hw/core/loader.c
20
@@ -XXX,XX +XXX,XX @@ static void decode_fast_read_cmd(Flash *s)
21
@@ -XXX,XX +XXX,XX @@ static int load_uboot_image(const char *filename, hwaddr *ep, hwaddr *loadaddr,
21
s->needed_bytes = get_addr_length(s);
22
if (is_linux) {
22
switch (get_man(s)) {
23
if (hdr->ih_os == IH_OS_LINUX) {
23
/* Dummy cycles - modeled with bytes writes instead of bits */
24
*is_linux = 1;
24
+ case MAN_SST:
25
+ } else if (hdr->ih_os == IH_OS_VXWORKS) {
25
+ s->needed_bytes += 1;
26
+ /*
26
+ break;
27
+ * VxWorks 7 uses the same boot interface as the Linux kernel
27
case MAN_WINBOND:
28
+ * on Arm (64-bit only), PowerPC and RISC-V architectures.
28
s->needed_bytes += 8;
29
+ */
29
break;
30
+ switch (hdr->ih_arch) {
31
+ case IH_ARCH_ARM64:
32
+ case IH_ARCH_PPC:
33
+ case IH_ARCH_RISCV:
34
+ *is_linux = 1;
35
+ break;
36
+ default:
37
+ *is_linux = 0;
38
+ break;
39
+ }
40
} else {
41
*is_linux = 0;
42
}
30
--
43
--
31
2.30.1
44
2.35.3
32
33
diff view generated by jsdifflib