1
The following changes since commit c95bd5ff1660883d15ad6e0005e4c8571604f51a:
1
The following changes since commit 57e28d34c0cb04abf7683ac6a12c87ede447c320:
2
2
3
Merge remote-tracking branch 'remotes/philmd/tags/mips-fixes-20210322' into staging (2021-03-22 14:26:13 +0000)
3
Merge remote-tracking branch 'remotes/cohuck-gitlab/tags/s390x-20210708' into staging (2021-07-12 19:15:11 +0100)
4
4
5
are available in the Git repository at:
5
are available in the Git repository at:
6
6
7
git@github.com:alistair23/qemu.git tags/pull-riscv-to-apply-20210322-2
7
git@github.com:alistair23/qemu.git tags/pull-riscv-to-apply-20210712
8
8
9
for you to fetch changes up to 9a27f69bd668d9d71674407badc412ce1231c7d5:
9
for you to fetch changes up to d6b87906f09f72a837dc68c33bfc3d913ef74b7d:
10
10
11
target/riscv: Prevent lost illegal instruction exceptions (2021-03-22 21:54:40 -0400)
11
hw/riscv: opentitan: Add the flash alias (2021-07-13 08:47:52 +1000)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
RISC-V PR for 6.0
14
Fourth RISC-V PR for 6.1 release
15
15
16
This PR includes:
16
- Code cleanups
17
- Fix for vector CSR access
17
- Documentation improvements
18
- Improvements to the Ibex UART device
18
- Hypervisor extension improvements with hideleg and hedeleg
19
- PMP improvements and bug fixes
19
- sifive_u fixes
20
- Hypervisor extension bug fixes
20
- OpenTitan register layout updates
21
- ramfb support for the virt machine
22
- Fast read support for SST flash
23
- Improvements to the microchip_pfsoc machine
24
21
25
----------------------------------------------------------------
22
----------------------------------------------------------------
26
Alexander Wagner (1):
23
Alistair Francis (3):
27
hw/char: disable ibex uart receive if the buffer is full
24
char: ibex_uart: Update the register layout
25
hw/riscv: opentitan: Add the unimplement rv_core_ibex_peri
26
hw/riscv: opentitan: Add the flash alias
28
27
29
Asherah Connor (2):
28
Bin Meng (7):
30
hw/riscv: Add fw_cfg support to virt
29
target/riscv: pmp: Fix some typos
31
hw/riscv: allow ramfb on virt
30
target/riscv: csr: Remove redundant check in fp csr read/write routines
31
docs/system: riscv: Fix CLINT name in the sifive_u doc
32
docs/system: riscv: Add documentation for virt machine
33
docs/system: riscv: Update Microchip Icicle Kit for direct kernel boot
34
hw/riscv: sifive_u: Correct the CLINT timebase frequency
35
hw/riscv: sifive_u: Make sure firmware info is 8-byte aligned
32
36
33
Bin Meng (3):
37
Jose Martins (1):
34
hw/block: m25p80: Support fast read for SST flashes
38
target/riscv: hardwire bits in hideleg and hedeleg
35
hw/riscv: microchip_pfsoc: Map EMMC/SD mux register
36
docs/system: riscv: Add documentation for 'microchip-icicle-kit' machine
37
39
38
Frank Chang (1):
40
docs/system/riscv/microchip-icicle-kit.rst | 54 +++++++++--
39
target/riscv: fix vs() to return proper error code
41
docs/system/riscv/sifive_u.rst | 2 +-
42
docs/system/riscv/virt.rst | 138 +++++++++++++++++++++++++++++
43
docs/system/target-riscv.rst | 1 +
44
include/hw/riscv/opentitan.h | 3 +
45
hw/char/ibex_uart.c | 19 ++--
46
hw/riscv/opentitan.c | 9 ++
47
hw/riscv/sifive_u.c | 12 ++-
48
target/riscv/csr.c | 37 +++-----
49
target/riscv/pmp.c | 10 +--
50
10 files changed, 233 insertions(+), 52 deletions(-)
51
create mode 100644 docs/system/riscv/virt.rst
40
52
41
Georg Kotheimer (6):
42
target/riscv: Adjust privilege level for HLV(X)/HSV instructions
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
49
Jim Shu (3):
50
target/riscv: propagate PMP permission to TLB page
51
target/riscv: add log of PMP permission checking
52
target/riscv: flush TLB pages if PMP permission has been changed
53
54
docs/system/riscv/microchip-icicle-kit.rst | 89 ++++++++++++++
55
docs/system/target-riscv.rst | 1 +
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
diff view generated by jsdifflib
Deleted patch
1
From: Frank Chang <frank.chang@sifive.com>
2
1
3
vs() should return -RISCV_EXCP_ILLEGAL_INST instead of -1 if rvv feature
4
is not enabled.
5
6
If -1 is returned, exception will be raised and cs->exception_index will
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>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
13
Message-id: 20210223065935.20208-1-frank.chang@sifive.com
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
---
16
target/riscv/csr.c | 2 +-
17
1 file changed, 1 insertion(+), 1 deletion(-)
18
19
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
20
index XXXXXXX..XXXXXXX 100644
21
--- a/target/riscv/csr.c
22
+++ b/target/riscv/csr.c
23
@@ -XXX,XX +XXX,XX @@ static int vs(CPURISCVState *env, int csrno)
24
if (env->misa & RVV) {
25
return 0;
26
}
27
- return -1;
28
+ return -RISCV_EXCP_ILLEGAL_INST;
29
}
30
31
static int ctr(CPURISCVState *env, int csrno)
32
--
33
2.30.1
34
35
diff view generated by jsdifflib
1
From: Jim Shu <cwshu@andestech.com>
1
From: Bin Meng <bmeng.cn@gmail.com>
2
2
3
Currently, PMP permission checking of TLB page is bypassed if TLB hits
3
%s/CSP/CSR
4
Fix it by propagating PMP permission to TLB page permission.
4
%s/thie/the
5
5
6
PMP permission checking also use MMU-style API to change TLB permission
6
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
7
and size.
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
9
Signed-off-by: Jim Shu <cwshu@andestech.com>
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Message-id: 1613916082-19528-2-git-send-email-cwshu@andestech.com
9
Message-id: 20210627115716.3552-1-bmeng.cn@gmail.com
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
11
---
14
target/riscv/pmp.h | 4 +-
12
target/riscv/pmp.c | 10 +++++-----
15
target/riscv/cpu_helper.c | 84 +++++++++++++++++++++++++++++----------
13
1 file changed, 5 insertions(+), 5 deletions(-)
16
target/riscv/pmp.c | 80 +++++++++++++++++++++++++++----------
17
3 files changed, 125 insertions(+), 43 deletions(-)
18
14
19
diff --git a/target/riscv/pmp.h b/target/riscv/pmp.h
20
index XXXXXXX..XXXXXXX 100644
21
--- a/target/riscv/pmp.h
22
+++ b/target/riscv/pmp.h
23
@@ -XXX,XX +XXX,XX @@ void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index,
24
target_ulong val);
25
target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index);
26
bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,
27
- target_ulong size, pmp_priv_t priv, target_ulong mode);
28
+ target_ulong size, pmp_priv_t privs, pmp_priv_t *allowed_privs,
29
+ target_ulong mode);
30
bool pmp_is_range_in_tlb(CPURISCVState *env, hwaddr tlb_sa,
31
target_ulong *tlb_size);
32
void pmp_update_rule_addr(CPURISCVState *env, uint32_t pmp_index);
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
40
--- a/target/riscv/cpu_helper.c
41
+++ b/target/riscv/cpu_helper.c
42
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv)
43
env->load_res = -1;
44
}
45
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
+
68
+ if (!riscv_feature(env, RISCV_FEATURE_PMP)) {
69
+ *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
70
+ return TRANSLATE_SUCCESS;
71
+ }
72
+
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
15
diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
174
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
175
--- a/target/riscv/pmp.c
17
--- a/target/riscv/pmp.c
176
+++ b/target/riscv/pmp.c
18
+++ b/target/riscv/pmp.c
177
@@ -XXX,XX +XXX,XX @@ static int pmp_is_in_range(CPURISCVState *env, int pmp_index, target_ulong addr)
19
@@ -XXX,XX +XXX,XX @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,
178
return result;
179
}
20
}
180
21
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
/*
22
/*
212
* Public Interface
23
- * Handle a write to a pmpcfg CSP
213
@@ -XXX,XX +XXX,XX @@ static int pmp_is_in_range(CPURISCVState *env, int pmp_index, target_ulong addr)
24
+ * Handle a write to a pmpcfg CSR
214
* Check if the address has required RWX privs to complete desired operation
215
*/
25
*/
216
bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,
26
void pmpcfg_csr_write(CPURISCVState *env, uint32_t reg_index,
217
- target_ulong size, pmp_priv_t privs, target_ulong mode)
27
target_ulong val)
218
+ target_ulong size, pmp_priv_t privs, pmp_priv_t *allowed_privs,
28
@@ -XXX,XX +XXX,XX @@ void pmpcfg_csr_write(CPURISCVState *env, uint32_t reg_index,
219
+ target_ulong mode)
29
30
31
/*
32
- * Handle a read from a pmpcfg CSP
33
+ * Handle a read from a pmpcfg CSR
34
*/
35
target_ulong pmpcfg_csr_read(CPURISCVState *env, uint32_t reg_index)
220
{
36
{
221
int i = 0;
37
@@ -XXX,XX +XXX,XX @@ target_ulong pmpcfg_csr_read(CPURISCVState *env, uint32_t reg_index)
222
int ret = -1;
38
223
int pmp_size = 0;
39
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
}
257
}
258
259
/* No rule matched */
260
if (ret == -1) {
261
- if (mode == PRV_M) {
262
- ret = 1; /* Privileged spec v1.10 states if no PMP entry matches an
263
- * M-Mode access, the access succeeds */
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
}
275
276
-
277
/*
40
/*
278
* Handle a write to a pmpcfg CSP
41
- * Handle a write to a pmpaddr CSP
42
+ * Handle a write to a pmpaddr CSR
279
*/
43
*/
280
@@ -XXX,XX +XXX,XX @@ bool pmp_is_range_in_tlb(CPURISCVState *env, hwaddr tlb_sa,
44
void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index,
281
45
target_ulong val)
282
return false;
46
@@ -XXX,XX +XXX,XX @@ void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index,
283
}
47
284
+
48
285
+/*
49
/*
286
+ * Convert PMP privilege to TLB page privilege.
50
- * Handle a read from a pmpaddr CSP
287
+ */
51
+ * Handle a read from a pmpaddr CSR
288
+int pmp_priv_to_page_prot(pmp_priv_t pmp_priv)
52
*/
289
+{
53
target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index)
290
+ int prot = 0;
54
{
291
+
55
@@ -XXX,XX +XXX,XX @@ target_ulong mseccfg_csr_read(CPURISCVState *env)
292
+ if (pmp_priv & PMP_READ) {
56
293
+ prot |= PAGE_READ;
57
/*
294
+ }
58
* Calculate the TLB size if the start address or the end address of
295
+ if (pmp_priv & PMP_WRITE) {
59
- * PMP entry is presented in thie TLB page.
296
+ prot |= PAGE_WRITE;
60
+ * PMP entry is presented in the TLB page.
297
+ }
61
*/
298
+ if (pmp_priv & PMP_EXEC) {
62
static target_ulong pmp_get_tlb_size(CPURISCVState *env, int pmp_index,
299
+ prot |= PAGE_EXEC;
63
target_ulong tlb_sa, target_ulong tlb_ea)
300
+ }
301
+
302
+ return prot;
303
+}
304
--
64
--
305
2.30.1
65
2.31.1
306
66
307
67
diff view generated by jsdifflib
1
From: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
1
From: Bin Meng <bmeng.cn@gmail.com>
2
2
3
Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
3
The following check:
4
5
if (!env->debugger && !riscv_cpu_fp_enabled(env)) {
6
return -RISCV_EXCP_ILLEGAL_INST;
7
}
8
9
is redundant in fflags/frm/fcsr read/write routines, as the check was
10
already done in fs().
11
12
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
4
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
13
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
5
Message-id: 20210311094902.1377593-1-georg.kotheimer@kernkonzept.com
14
Message-id: 20210627120604.11116-1-bmeng.cn@gmail.com
6
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
7
---
16
---
8
target/riscv/csr.c | 7 ++++---
17
target/riscv/csr.c | 24 ------------------------
9
1 file changed, 4 insertions(+), 3 deletions(-)
18
1 file changed, 24 deletions(-)
10
19
11
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
20
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
12
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
13
--- a/target/riscv/csr.c
22
--- a/target/riscv/csr.c
14
+++ b/target/riscv/csr.c
23
+++ b/target/riscv/csr.c
15
@@ -XXX,XX +XXX,XX @@ static const target_ulong sstatus_v1_10_mask = SSTATUS_SIE | SSTATUS_SPIE |
24
@@ -XXX,XX +XXX,XX @@ static RISCVException epmp(CPURISCVState *env, int csrno)
16
SSTATUS_UIE | SSTATUS_UPIE | SSTATUS_SPP | SSTATUS_FS | SSTATUS_XS |
25
static RISCVException read_fflags(CPURISCVState *env, int csrno,
17
SSTATUS_SUM | SSTATUS_MXR | SSTATUS_SD;
26
target_ulong *val)
18
static const target_ulong sip_writable_mask = SIP_SSIP | MIP_USIP | MIP_UEIP;
19
-static const target_ulong hip_writable_mask = MIP_VSSIP | MIP_VSTIP | MIP_VSEIP;
20
+static const target_ulong hip_writable_mask = MIP_VSSIP;
21
+static const target_ulong hvip_writable_mask = MIP_VSSIP | MIP_VSTIP | MIP_VSEIP;
22
static const target_ulong vsip_writable_mask = MIP_VSSIP;
23
24
static const char valid_vm_1_10_32[16] = {
25
@@ -XXX,XX +XXX,XX @@ static int rmw_hvip(CPURISCVState *env, int csrno, target_ulong *ret_value,
26
target_ulong new_value, target_ulong write_mask)
27
{
27
{
28
int ret = rmw_mip(env, 0, ret_value, new_value,
28
-#if !defined(CONFIG_USER_ONLY)
29
- write_mask & hip_writable_mask);
29
- if (!env->debugger && !riscv_cpu_fp_enabled(env)) {
30
+ write_mask & hvip_writable_mask);
30
- return RISCV_EXCP_ILLEGAL_INST;
31
31
- }
32
- *ret_value &= hip_writable_mask;
32
-#endif
33
+ *ret_value &= hvip_writable_mask;
33
*val = riscv_cpu_get_fflags(env);
34
34
return RISCV_EXCP_NONE;
35
return ret;
36
}
35
}
36
@@ -XXX,XX +XXX,XX @@ static RISCVException write_fflags(CPURISCVState *env, int csrno,
37
target_ulong val)
38
{
39
#if !defined(CONFIG_USER_ONLY)
40
- if (!env->debugger && !riscv_cpu_fp_enabled(env)) {
41
- return RISCV_EXCP_ILLEGAL_INST;
42
- }
43
env->mstatus |= MSTATUS_FS;
44
#endif
45
riscv_cpu_set_fflags(env, val & (FSR_AEXC >> FSR_AEXC_SHIFT));
46
@@ -XXX,XX +XXX,XX @@ static RISCVException write_fflags(CPURISCVState *env, int csrno,
47
static RISCVException read_frm(CPURISCVState *env, int csrno,
48
target_ulong *val)
49
{
50
-#if !defined(CONFIG_USER_ONLY)
51
- if (!env->debugger && !riscv_cpu_fp_enabled(env)) {
52
- return RISCV_EXCP_ILLEGAL_INST;
53
- }
54
-#endif
55
*val = env->frm;
56
return RISCV_EXCP_NONE;
57
}
58
@@ -XXX,XX +XXX,XX @@ static RISCVException write_frm(CPURISCVState *env, int csrno,
59
target_ulong val)
60
{
61
#if !defined(CONFIG_USER_ONLY)
62
- if (!env->debugger && !riscv_cpu_fp_enabled(env)) {
63
- return RISCV_EXCP_ILLEGAL_INST;
64
- }
65
env->mstatus |= MSTATUS_FS;
66
#endif
67
env->frm = val & (FSR_RD >> FSR_RD_SHIFT);
68
@@ -XXX,XX +XXX,XX @@ static RISCVException write_frm(CPURISCVState *env, int csrno,
69
static RISCVException read_fcsr(CPURISCVState *env, int csrno,
70
target_ulong *val)
71
{
72
-#if !defined(CONFIG_USER_ONLY)
73
- if (!env->debugger && !riscv_cpu_fp_enabled(env)) {
74
- return RISCV_EXCP_ILLEGAL_INST;
75
- }
76
-#endif
77
*val = (riscv_cpu_get_fflags(env) << FSR_AEXC_SHIFT)
78
| (env->frm << FSR_RD_SHIFT);
79
if (vs(env, csrno) >= 0) {
80
@@ -XXX,XX +XXX,XX @@ static RISCVException write_fcsr(CPURISCVState *env, int csrno,
81
target_ulong val)
82
{
83
#if !defined(CONFIG_USER_ONLY)
84
- if (!env->debugger && !riscv_cpu_fp_enabled(env)) {
85
- return RISCV_EXCP_ILLEGAL_INST;
86
- }
87
env->mstatus |= MSTATUS_FS;
88
#endif
89
env->frm = (val & FSR_RD) >> FSR_RD_SHIFT;
37
--
90
--
38
2.30.1
91
2.31.1
39
92
40
93
diff view generated by jsdifflib
1
From: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
1
From: Bin Meng <bmeng.cn@gmail.com>
2
2
3
The current condition for the use of background registers only
3
It's Core *Local* Interruptor, not 'Level'.
4
considers the hypervisor load and store instructions,
5
but not accesses from M mode via MSTATUS_MPRV+MPV.
6
4
7
Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
5
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
6
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Message-id: 20210311103036.1401073-1-georg.kotheimer@kernkonzept.com
7
Message-id: 20210627142816.19789-1-bmeng.cn@gmail.com
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
8
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
9
---
12
target/riscv/cpu_helper.c | 2 +-
10
docs/system/riscv/sifive_u.rst | 2 +-
13
1 file changed, 1 insertion(+), 1 deletion(-)
11
1 file changed, 1 insertion(+), 1 deletion(-)
14
12
15
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
13
diff --git a/docs/system/riscv/sifive_u.rst b/docs/system/riscv/sifive_u.rst
16
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/cpu_helper.c
15
--- a/docs/system/riscv/sifive_u.rst
18
+++ b/target/riscv/cpu_helper.c
16
+++ b/docs/system/riscv/sifive_u.rst
19
@@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,
17
@@ -XXX,XX +XXX,XX @@ The ``sifive_u`` machine supports the following devices:
20
* was called. Background registers will be used if the guest has
18
21
* forced a two stage translation to be on (in HS or M mode).
19
* 1 E51 / E31 core
22
*/
20
* Up to 4 U54 / U34 cores
23
- if (!riscv_cpu_virt_enabled(env) && riscv_cpu_two_stage_lookup(mmu_idx)) {
21
-* Core Level Interruptor (CLINT)
24
+ if (!riscv_cpu_virt_enabled(env) && two_stage) {
22
+* Core Local Interruptor (CLINT)
25
use_background = true;
23
* Platform-Level Interrupt Controller (PLIC)
26
}
24
* Power, Reset, Clock, Interrupt (PRCI)
27
25
* L2 Loosely Integrated Memory (L2-LIM)
28
--
26
--
29
2.30.1
27
2.31.1
30
28
31
29
diff view generated by jsdifflib
1
From: Bin Meng <bin.meng@windriver.com>
1
From: Bin Meng <bmeng.cn@gmail.com>
2
2
3
This adds the documentation to describe what is supported for the
3
This adds detailed documentation for RISC-V `virt` machine,
4
'microchip-icicle-kit' machine, and how to boot the machine in QEMU.
4
including the following information:
5
5
6
Signed-off-by: Bin Meng <bin.meng@windriver.com>
6
- Supported devices
7
- Hardware configuration information
8
- Boot options
9
- Running Linux kernel
10
- Running U-Boot
11
12
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
13
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Message-id: 20210322075248.136255-2-bmeng.cn@gmail.com
14
Message-id: 20210627142816.19789-2-bmeng.cn@gmail.com
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
---
16
---
11
docs/system/riscv/microchip-icicle-kit.rst | 89 ++++++++++++++++++++++
17
docs/system/riscv/virt.rst | 138 +++++++++++++++++++++++++++++++++++
12
docs/system/target-riscv.rst | 1 +
18
docs/system/target-riscv.rst | 1 +
13
2 files changed, 90 insertions(+)
19
2 files changed, 139 insertions(+)
14
create mode 100644 docs/system/riscv/microchip-icicle-kit.rst
20
create mode 100644 docs/system/riscv/virt.rst
15
21
16
diff --git a/docs/system/riscv/microchip-icicle-kit.rst b/docs/system/riscv/microchip-icicle-kit.rst
22
diff --git a/docs/system/riscv/virt.rst b/docs/system/riscv/virt.rst
17
new file mode 100644
23
new file mode 100644
18
index XXXXXXX..XXXXXXX
24
index XXXXXXX..XXXXXXX
19
--- /dev/null
25
--- /dev/null
20
+++ b/docs/system/riscv/microchip-icicle-kit.rst
26
+++ b/docs/system/riscv/virt.rst
21
@@ -XXX,XX +XXX,XX @@
27
@@ -XXX,XX +XXX,XX @@
22
+Microchip PolarFire SoC Icicle Kit (``microchip-icicle-kit``)
28
+'virt' Generic Virtual Platform (``virt``)
23
+=============================================================
29
+==========================================
24
+
30
+
25
+Microchip PolarFire SoC Icicle Kit integrates a PolarFire SoC, with one
31
+The `virt` board is a platform which does not correspond to any real hardware;
26
+SiFive's E51 plus four U54 cores and many on-chip peripherals and an FPGA.
32
+it is designed for use in virtual machines. It is the recommended board type
27
+
33
+if you simply want to run a guest such as Linux and do not care about
28
+For more details about Microchip PolarFire SoC, please see:
34
+reproducing the idiosyncrasies and limitations of a particular bit of
29
+https://www.microsemi.com/product-directory/soc-fpgas/5498-polarfire-soc-fpga
35
+real-world hardware.
30
+
31
+The Icicle Kit board information can be found here:
32
+https://www.microsemi.com/existing-parts/parts/152514
33
+
36
+
34
+Supported devices
37
+Supported devices
35
+-----------------
38
+-----------------
36
+
39
+
37
+The ``microchip-icicle-kit`` machine supports the following devices:
40
+The ``virt`` machine supports the following devices:
38
+
41
+
39
+ * 1 E51 core
42
+* Up to 8 generic RV32GC/RV64GC cores, with optional extensions
40
+ * 4 U54 cores
43
+* Core Local Interruptor (CLINT)
41
+ * Core Level Interruptor (CLINT)
44
+* Platform-Level Interrupt Controller (PLIC)
42
+ * Platform-Level Interrupt Controller (PLIC)
45
+* CFI parallel NOR flash memory
43
+ * L2 Loosely Integrated Memory (L2-LIM)
46
+* 1 NS16550 compatible UART
44
+ * DDR memory controller
47
+* 1 Google Goldfish RTC
45
+ * 5 MMUARTs
48
+* 1 SiFive Test device
46
+ * 1 DMA controller
49
+* 8 virtio-mmio transport devices
47
+ * 2 GEM Ethernet controllers
50
+* 1 generic PCIe host bridge
48
+ * 1 SDHC storage controller
51
+* The fw_cfg device that allows a guest to obtain data from QEMU
52
+
53
+Note that the default CPU is a generic RV32GC/RV64GC. Optional extensions
54
+can be enabled via command line parameters, e.g.: ``-cpu rv64,x-h=true``
55
+enables the hypervisor extension for RV64.
56
+
57
+Hardware configuration information
58
+----------------------------------
59
+
60
+The ``virt`` machine automatically generates a device tree blob ("dtb")
61
+which it passes to the guest, if there is no ``-dtb`` option. This provides
62
+information about the addresses, interrupt lines and other configuration of
63
+the various devices in the system. Guest software should discover the devices
64
+that are present in the generated DTB.
65
+
66
+If users want to provide their own DTB, they can use the ``-dtb`` option.
67
+These DTBs should have the following requirements:
68
+
69
+* The number of subnodes of the /cpus node should match QEMU's ``-smp`` option
70
+* The /memory reg size should match QEMU’s selected ram_size via ``-m``
71
+* Should contain a node for the CLINT device with a compatible string
72
+ "riscv,clint0" if using with OpenSBI BIOS images
49
+
73
+
50
+Boot options
74
+Boot options
51
+------------
75
+------------
52
+
76
+
53
+The ``microchip-icicle-kit`` machine can start using the standard -bios
77
+The ``virt`` machine can start using the standard -kernel functionality
54
+functionality for loading its BIOS image, aka Hart Software Services (HSS_).
78
+for loading a Linux kernel, a VxWorks kernel, an S-mode U-Boot bootloader
55
+HSS loads the second stage bootloader U-Boot from an SD card. It does not
79
+with the default OpenSBI firmware image as the -bios. It also supports
56
+support direct kernel loading via the -kernel option. One has to load kernel
80
+the recommended RISC-V bootflow: U-Boot SPL (M-mode) loads OpenSBI fw_dynamic
57
+from U-Boot.
81
+firmware and U-Boot proper (S-mode), using the standard -bios functionality.
58
+
82
+
59
+The memory is set to 1537 MiB by default which is the minimum required high
83
+Running Linux kernel
60
+memory size by HSS. A sanity check on ram size is performed in the machine
84
+--------------------
61
+init routine to prompt user to increase the RAM size to > 1537 MiB when less
62
+than 1537 MiB ram is detected.
63
+
85
+
64
+Boot the machine
86
+Linux mainline v5.12 release is tested at the time of writing. To build a
65
+----------------
87
+Linux mainline kernel that can be booted by the ``virt`` machine in
88
+64-bit mode, simply configure the kernel using the defconfig configuration:
66
+
89
+
67
+HSS 2020.12 release is tested at the time of writing. To build an HSS image
90
+.. code-block:: bash
68
+that can be booted by the ``microchip-icicle-kit`` machine, type the following
91
+
69
+in the HSS source tree:
92
+ $ export ARCH=riscv
93
+ $ export CROSS_COMPILE=riscv64-linux-
94
+ $ make defconfig
95
+ $ make
96
+
97
+To boot the newly built Linux kernel in QEMU with the ``virt`` machine:
98
+
99
+.. code-block:: bash
100
+
101
+ $ qemu-system-riscv64 -M virt -smp 4 -m 2G \
102
+ -display none -serial stdio \
103
+ -kernel arch/riscv/boot/Image \
104
+ -initrd /path/to/rootfs.cpio \
105
+ -append "root=/dev/ram"
106
+
107
+To build a Linux mainline kernel that can be booted by the ``virt`` machine
108
+in 32-bit mode, use the rv32_defconfig configuration. A patch is required to
109
+fix the 32-bit boot issue for Linux kernel v5.12.
110
+
111
+.. code-block:: bash
112
+
113
+ $ export ARCH=riscv
114
+ $ export CROSS_COMPILE=riscv64-linux-
115
+ $ curl https://patchwork.kernel.org/project/linux-riscv/patch/20210627135117.28641-1-bmeng.cn@gmail.com/mbox/ > riscv.patch
116
+ $ git am riscv.patch
117
+ $ make rv32_defconfig
118
+ $ make
119
+
120
+Replace ``qemu-system-riscv64`` with ``qemu-system-riscv32`` in the command
121
+line above to boot the 32-bit Linux kernel. A rootfs image containing 32-bit
122
+applications shall be used in order for kernel to boot to user space.
123
+
124
+Running U-Boot
125
+--------------
126
+
127
+U-Boot mainline v2021.04 release is tested at the time of writing. To build an
128
+S-mode U-Boot bootloader that can be booted by the ``virt`` machine, use
129
+the qemu-riscv64_smode_defconfig with similar commands as described above for Linux:
70
+
130
+
71
+.. code-block:: bash
131
+.. code-block:: bash
72
+
132
+
73
+ $ export CROSS_COMPILE=riscv64-linux-
133
+ $ export CROSS_COMPILE=riscv64-linux-
74
+ $ cp boards/mpfs-icicle-kit-es/def_config .config
134
+ $ make qemu-riscv64_smode_defconfig
75
+ $ make BOARD=mpfs-icicle-kit-es
76
+
135
+
77
+Download the official SD card image released by Microchip and prepare it for
136
+Boot the 64-bit U-Boot S-mode image directly:
78
+QEMU usage:
79
+
137
+
80
+.. code-block:: bash
138
+.. code-block:: bash
81
+
139
+
82
+ $ wget ftp://ftpsoc.microsemi.com/outgoing/core-image-minimal-dev-icicle-kit-es-sd-20201009141623.rootfs.wic.gz
140
+ $ qemu-system-riscv64 -M virt -smp 4 -m 2G \
83
+ $ gunzip core-image-minimal-dev-icicle-kit-es-sd-20201009141623.rootfs.wic.gz
141
+ -display none -serial stdio \
84
+ $ qemu-img resize core-image-minimal-dev-icicle-kit-es-sd-20201009141623.rootfs.wic 4G
142
+ -kernel /path/to/u-boot.bin
85
+
143
+
86
+Then we can boot the machine by:
144
+To test booting U-Boot SPL which in M-mode, which in turn loads a FIT image
145
+that bundles OpenSBI fw_dynamic firmware and U-Boot proper (S-mode) together,
146
+build the U-Boot images using riscv64_spl_defconfig:
87
+
147
+
88
+.. code-block:: bash
148
+.. code-block:: bash
89
+
149
+
90
+ $ qemu-system-riscv64 -M microchip-icicle-kit -smp 5 \
150
+ $ export CROSS_COMPILE=riscv64-linux-
91
+ -bios path/to/hss.bin -sd path/to/sdcard.img \
151
+ $ export OPENSBI=/path/to/opensbi-riscv64-generic-fw_dynamic.bin
92
+ -nic user,model=cadence_gem \
152
+ $ make qemu-riscv64_spl_defconfig
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
+
153
+
98
+With above command line, current terminal session will be used for the first
154
+The minimal QEMU commands to run U-Boot SPL are:
99
+serial port. Open another terminal window, and use `minicom` to connect the
100
+second serial port.
101
+
155
+
102
+.. code-block:: bash
156
+.. code-block:: bash
103
+
157
+
104
+ $ minicom -D unix\#serial1.sock
158
+ $ qemu-system-riscv64 -M virt -smp 4 -m 2G \
159
+ -display none -serial stdio \
160
+ -bios /path/to/u-boot-spl \
161
+ -device loader,file=/path/to/u-boot.itb,addr=0x80200000
105
+
162
+
106
+HSS output is on the first serial port (stdio) and U-Boot outputs on the
163
+To test 32-bit U-Boot images, switch to use qemu-riscv32_smode_defconfig and
107
+second serial port. U-Boot will automatically load the Linux kernel from
164
+riscv32_spl_defconfig builds, and replace ``qemu-system-riscv64`` with
108
+the SD card image.
165
+``qemu-system-riscv32`` in the command lines above to boot the 32-bit U-Boot.
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
166
diff --git a/docs/system/target-riscv.rst b/docs/system/target-riscv.rst
112
index XXXXXXX..XXXXXXX 100644
167
index XXXXXXX..XXXXXXX 100644
113
--- a/docs/system/target-riscv.rst
168
--- a/docs/system/target-riscv.rst
114
+++ b/docs/system/target-riscv.rst
169
+++ b/docs/system/target-riscv.rst
115
@@ -XXX,XX +XXX,XX @@ undocumented; you can get a complete list by running
170
@@ -XXX,XX +XXX,XX @@ undocumented; you can get a complete list by running
116
.. toctree::
171
riscv/microchip-icicle-kit
117
:maxdepth: 1
172
riscv/shakti-c
118
119
+ riscv/microchip-icicle-kit
120
riscv/sifive_u
173
riscv/sifive_u
121
174
+ riscv/virt
122
RISC-V CPU features
175
176
RISC-V CPU firmware
177
-------------------
123
--
178
--
124
2.30.1
179
2.31.1
125
180
126
181
diff view generated by jsdifflib
1
From: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
1
From: Jose Martins <josemartins90@gmail.com>
2
2
3
The previous implementation was broken in many ways:
3
The specification mandates for certain bits to be hardwired in the
4
- Used mideleg instead of hideleg to mask accesses
4
hypervisor delegation registers. This was not being enforced.
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
Signed-off-by: Jose Martins <josemartins90@gmail.com>
7
Reviewed-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Message-id: 20210311094738.1376795-1-georg.kotheimer@kernkonzept.com
9
Message-id: 20210522155902.374439-1-josemartins90@gmail.com
10
[ Changes by AF:
11
- Improve indentation
12
]
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 | 13 +++++++++++--
14
1 file changed, 34 insertions(+), 34 deletions(-)
16
1 file changed, 11 insertions(+), 2 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 RISCVException read_timeh(CPURISCVState *env, int csrno,
21
return write_mstatus(env, CSR_MSTATUS, newval);
23
24
static const target_ulong delegable_ints = S_MODE_INTERRUPTS |
25
VS_MODE_INTERRUPTS;
26
+static const target_ulong vs_delegable_ints = VS_MODE_INTERRUPTS;
27
static const target_ulong all_ints = M_MODE_INTERRUPTS | S_MODE_INTERRUPTS |
28
VS_MODE_INTERRUPTS;
29
static const target_ulong delegable_excps =
30
@@ -XXX,XX +XXX,XX @@ static const target_ulong delegable_excps =
31
(1ULL << (RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT)) |
32
(1ULL << (RISCV_EXCP_VIRT_INSTRUCTION_FAULT)) |
33
(1ULL << (RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT));
34
+static const target_ulong vs_delegable_excps = delegable_excps &
35
+ ~((1ULL << (RISCV_EXCP_S_ECALL)) |
36
+ (1ULL << (RISCV_EXCP_VS_ECALL)) |
37
+ (1ULL << (RISCV_EXCP_M_ECALL)) |
38
+ (1ULL << (RISCV_EXCP_INST_GUEST_PAGE_FAULT)) |
39
+ (1ULL << (RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT)) |
40
+ (1ULL << (RISCV_EXCP_VIRT_INSTRUCTION_FAULT)) |
41
+ (1ULL << (RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT)));
42
static const target_ulong sstatus_v1_10_mask = SSTATUS_SIE | SSTATUS_SPIE |
43
SSTATUS_UIE | SSTATUS_UPIE | SSTATUS_SPP | SSTATUS_FS | SSTATUS_XS |
44
SSTATUS_SUM | SSTATUS_MXR;
45
@@ -XXX,XX +XXX,XX @@ static RISCVException read_hedeleg(CPURISCVState *env, int csrno,
46
static RISCVException write_hedeleg(CPURISCVState *env, int csrno,
47
target_ulong val)
48
{
49
- env->hedeleg = val;
50
+ env->hedeleg = val & vs_delegable_excps;
51
return RISCV_EXCP_NONE;
22
}
52
}
23
53
24
+static int read_vsie(CPURISCVState *env, int csrno, target_ulong *val)
54
@@ -XXX,XX +XXX,XX @@ static RISCVException read_hideleg(CPURISCVState *env, int csrno,
25
+{
55
static RISCVException write_hideleg(CPURISCVState *env, int csrno,
26
+ /* Shift the VS bits to their S bit location in vsie */
56
target_ulong val)
27
+ *val = (env->mie & env->hideleg & VS_MODE_INTERRUPTS) >> 1;
28
+ return 0;
29
+}
30
+
31
static int read_sie(CPURISCVState *env, int csrno, target_ulong *val)
32
{
57
{
33
if (riscv_cpu_virt_enabled(env)) {
58
- env->hideleg = val;
34
- /* Tell the guest the VS bits, shifted to the S bit locations */
59
+ env->hideleg = val & vs_delegable_ints;
35
- *val = (env->mie & env->mideleg & VS_MODE_INTERRUPTS) >> 1;
60
return RISCV_EXCP_NONE;
36
+ read_vsie(env, CSR_VSIE, val);
37
} else {
38
*val = env->mie & env->mideleg;
39
}
40
return 0;
41
}
61
}
42
62
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
--
63
--
131
2.30.1
64
2.31.1
132
65
133
66
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
This adds a new section in the documentation to demonstrate how to
4
the address bytes. Note only SPI mode is supported by SST flashes.
4
use the new direct kernel boot feature for Microchip Icicle Kit,
5
other than the HSS bootflow, using an upstream U-Boot v2021.07 image
6
as an example.
5
7
6
[1] http://ww1.microchip.com/downloads/en/devicedoc/s71271_04.pdf
8
It also updates the truth table to have a new '-dtb' column which is
9
required by direct kernel boot.
7
10
8
Signed-off-by: Bin Meng <bin.meng@windriver.com>
11
Signed-off-by: Bin Meng <bin.meng@windriver.com>
9
Acked-by: Alistair Francis <alistair.francis@wdc.com>
12
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Message-id: 20210306060152.7250-1-bmeng.cn@gmail.com
13
Message-id: 20210706095045.1917913-1-bmeng.cn@gmail.com
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
15
---
13
hw/block/m25p80.c | 3 +++
16
docs/system/riscv/microchip-icicle-kit.rst | 54 +++++++++++++++++++---
14
1 file changed, 3 insertions(+)
17
1 file changed, 47 insertions(+), 7 deletions(-)
15
18
16
diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
19
diff --git a/docs/system/riscv/microchip-icicle-kit.rst b/docs/system/riscv/microchip-icicle-kit.rst
17
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/block/m25p80.c
21
--- a/docs/system/riscv/microchip-icicle-kit.rst
19
+++ b/hw/block/m25p80.c
22
+++ b/docs/system/riscv/microchip-icicle-kit.rst
20
@@ -XXX,XX +XXX,XX @@ static void decode_fast_read_cmd(Flash *s)
23
@@ -XXX,XX +XXX,XX @@ The user provided DTB should have the following requirements:
21
s->needed_bytes = get_addr_length(s);
24
22
switch (get_man(s)) {
25
QEMU follows below truth table to select which payload to execute:
23
/* Dummy cycles - modeled with bytes writes instead of bits */
26
24
+ case MAN_SST:
27
-===== ========== =======
25
+ s->needed_bytes += 1;
28
--bios -kernel payload
26
+ break;
29
-===== ========== =======
27
case MAN_WINBOND:
30
- N N HSS
28
s->needed_bytes += 8;
31
- Y don't care HSS
29
break;
32
- N Y kernel
33
-===== ========== =======
34
+===== ========== ========== =======
35
+-bios -kernel -dtb payload
36
+===== ========== ========== =======
37
+ N N don't care HSS
38
+ Y don't care don't care HSS
39
+ N Y Y kernel
40
+===== ========== ========== =======
41
42
The memory is set to 1537 MiB by default which is the minimum required high
43
memory size by HSS. A sanity check on ram size is performed in the machine
44
@@ -XXX,XX +XXX,XX @@ HSS output is on the first serial port (stdio) and U-Boot outputs on the
45
second serial port. U-Boot will automatically load the Linux kernel from
46
the SD card image.
47
48
+Direct Kernel Boot
49
+------------------
50
+
51
+Sometimes we just want to test booting a new kernel, and transforming the
52
+kernel image to the format required by the HSS bootflow is tedious. We can
53
+use '-kernel' for direct kernel booting just like other RISC-V machines do.
54
+
55
+In this mode, the OpenSBI fw_dynamic BIOS image for 'generic' platform is
56
+used to boot an S-mode payload like U-Boot or OS kernel directly.
57
+
58
+For example, the following commands show building a U-Boot image from U-Boot
59
+mainline v2021.07 for the Microchip Icicle Kit board:
60
+
61
+.. code-block:: bash
62
+
63
+ $ export CROSS_COMPILE=riscv64-linux-
64
+ $ make microchip_mpfs_icicle_defconfig
65
+
66
+Then we can boot the machine by:
67
+
68
+.. code-block:: bash
69
+
70
+ $ qemu-system-riscv64 -M microchip-icicle-kit -smp 5 -m 2G \
71
+ -sd path/to/sdcard.img \
72
+ -nic user,model=cadence_gem \
73
+ -nic tap,ifname=tap,model=cadence_gem,script=no \
74
+ -display none -serial stdio \
75
+ -kernel path/to/u-boot/build/dir/u-boot.bin \
76
+ -dtb path/to/u-boot/build/dir/u-boot.dtb
77
+
78
+CAVEATS:
79
+
80
+* Check the "stdout-path" property in the /chosen node in the DTB to determine
81
+ which serial port is used for the serial console, e.g.: if the console is set
82
+ to the second serial port, change to use "-serial null -serial stdio".
83
+* The default U-Boot configuration uses CONFIG_OF_SEPARATE hence the ELF image
84
+ ``u-boot`` cannot be passed to "-kernel" as it does not contain the DTB hence
85
+ ``u-boot.bin`` has to be used which does contain one. To use the ELF image,
86
+ we need to change to CONFIG_OF_EMBED or CONFIG_OF_PRIOR_STAGE.
87
+
88
.. _HSS: https://github.com/polarfire-soc/hart-software-services
30
--
89
--
31
2.30.1
90
2.31.1
32
91
33
92
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
At present the CLINT timebase frequency is set to 10MHz on sifive_u,
4
been updated to use a register mapped at 0x4f000000 instead of a
4
but on the real hardware the timebase frequency is 1Mhz.
5
GPIO to control whether eMMC or SD card is to be used. With this
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
5
13
Signed-off-by: Bin Meng <bin.meng@windriver.com>
6
Signed-off-by: Bin Meng <bin.meng@windriver.com>
14
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
15
Message-id: 20210322075248.136255-1-bmeng.cn@gmail.com
8
Message-id: 20210706102616.1922469-1-bmeng.cn@gmail.com
16
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
17
---
10
---
18
include/hw/riscv/microchip_pfsoc.h | 1 +
11
hw/riscv/sifive_u.c | 7 +++++--
19
hw/riscv/microchip_pfsoc.c | 6 ++++++
12
1 file changed, 5 insertions(+), 2 deletions(-)
20
2 files changed, 7 insertions(+)
21
13
22
diff --git a/include/hw/riscv/microchip_pfsoc.h b/include/hw/riscv/microchip_pfsoc.h
14
diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
23
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
24
--- a/include/hw/riscv/microchip_pfsoc.h
16
--- a/hw/riscv/sifive_u.c
25
+++ b/include/hw/riscv/microchip_pfsoc.h
17
+++ b/hw/riscv/sifive_u.c
26
@@ -XXX,XX +XXX,XX @@ enum {
18
@@ -XXX,XX +XXX,XX @@
27
MICROCHIP_PFSOC_ENVM_DATA,
19
28
MICROCHIP_PFSOC_QSPI_XIP,
20
#include <libfdt.h>
29
MICROCHIP_PFSOC_IOSCB,
21
30
+ MICROCHIP_PFSOC_EMMC_SD_MUX,
22
+/* CLINT timebase frequency */
31
MICROCHIP_PFSOC_DRAM_LO,
23
+#define CLINT_TIMEBASE_FREQ 1000000
32
MICROCHIP_PFSOC_DRAM_LO_ALIAS,
33
MICROCHIP_PFSOC_DRAM_HI,
34
diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c
35
index XXXXXXX..XXXXXXX 100644
36
--- a/hw/riscv/microchip_pfsoc.c
37
+++ b/hw/riscv/microchip_pfsoc.c
38
@@ -XXX,XX +XXX,XX @@ static const MemMapEntry microchip_pfsoc_memmap[] = {
39
[MICROCHIP_PFSOC_ENVM_DATA] = { 0x20220000, 0x20000 },
40
[MICROCHIP_PFSOC_QSPI_XIP] = { 0x21000000, 0x1000000 },
41
[MICROCHIP_PFSOC_IOSCB] = { 0x30000000, 0x10000000 },
42
+ [MICROCHIP_PFSOC_EMMC_SD_MUX] = { 0x4f000000, 0x4 },
43
[MICROCHIP_PFSOC_DRAM_LO] = { 0x80000000, 0x40000000 },
44
[MICROCHIP_PFSOC_DRAM_LO_ALIAS] = { 0xc0000000, 0x40000000 },
45
[MICROCHIP_PFSOC_DRAM_HI] = { 0x1000000000, 0x0 },
46
@@ -XXX,XX +XXX,XX @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
47
sysbus_mmio_map(SYS_BUS_DEVICE(&s->ioscb), 0,
48
memmap[MICROCHIP_PFSOC_IOSCB].base);
49
50
+ /* eMMC/SD mux */
51
+ create_unimplemented_device("microchip.pfsoc.emmc_sd_mux",
52
+ memmap[MICROCHIP_PFSOC_EMMC_SD_MUX].base,
53
+ memmap[MICROCHIP_PFSOC_EMMC_SD_MUX].size);
54
+
24
+
55
/* QSPI Flash */
25
static const MemMapEntry sifive_u_memmap[] = {
56
memory_region_init_rom(qspi_xip_mem, OBJECT(dev),
26
[SIFIVE_U_DEV_DEBUG] = { 0x0, 0x100 },
57
"microchip.pfsoc.qspi_xip",
27
[SIFIVE_U_DEV_MROM] = { 0x1000, 0xf000 },
28
@@ -XXX,XX +XXX,XX @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,
29
30
qemu_fdt_add_subnode(fdt, "/cpus");
31
qemu_fdt_setprop_cell(fdt, "/cpus", "timebase-frequency",
32
- SIFIVE_CLINT_TIMEBASE_FREQ);
33
+ CLINT_TIMEBASE_FREQ);
34
qemu_fdt_setprop_cell(fdt, "/cpus", "#size-cells", 0x0);
35
qemu_fdt_setprop_cell(fdt, "/cpus", "#address-cells", 0x1);
36
37
@@ -XXX,XX +XXX,XX @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp)
38
sifive_clint_create(memmap[SIFIVE_U_DEV_CLINT].base,
39
memmap[SIFIVE_U_DEV_CLINT].size, 0, ms->smp.cpus,
40
SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE,
41
- SIFIVE_CLINT_TIMEBASE_FREQ, false);
42
+ CLINT_TIMEBASE_FREQ, false);
43
44
if (!sysbus_realize(SYS_BUS_DEVICE(&s->prci), errp)) {
45
return;
58
--
46
--
59
2.30.1
47
2.31.1
60
48
61
49
diff view generated by jsdifflib
1
From: Asherah Connor <ashe@kivikakk.ee>
1
From: Bin Meng <bmeng.cn@gmail.com>
2
2
3
Provides fw_cfg for the virt machine on riscv. This enables
3
Currently the firmware dynamic info (fw_dyn) is put right after
4
using e.g. ramfb later.
4
the reset vector, which is not 8-byte aligned on RV64. OpenSBI
5
fw_dynamic uses ld to read contents from 'struct fw_dynamic_info',
6
which expects fw_dyn to be on the 8-byte boundary, otherwise the
7
misaligned load exception may happen. Fortunately this does not
8
cause any issue on QEMU, as QEMU does support misaligned load.
5
9
6
Signed-off-by: Asherah Connor <ashe@kivikakk.ee>
10
RV32 does not have any issue as it is 4-byte aligned already.
7
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
11
Change to make sure it is 8-byte aligned which works for both
12
RV32 and RV64.
13
14
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
15
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Message-id: 20210318235041.17175-2-ashe@kivikakk.ee
16
Message-id: 20210708143319.10441-1-bmeng.cn@gmail.com
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
17
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
18
---
12
include/hw/riscv/virt.h | 2 ++
19
hw/riscv/sifive_u.c | 5 +++--
13
hw/riscv/virt.c | 30 ++++++++++++++++++++++++++++++
20
1 file changed, 3 insertions(+), 2 deletions(-)
14
hw/riscv/Kconfig | 1 +
15
3 files changed, 33 insertions(+)
16
21
17
diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h
22
diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
18
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
19
--- a/include/hw/riscv/virt.h
24
--- a/hw/riscv/sifive_u.c
20
+++ b/include/hw/riscv/virt.h
25
+++ b/hw/riscv/sifive_u.c
21
@@ -XXX,XX +XXX,XX @@ struct RISCVVirtState {
26
@@ -XXX,XX +XXX,XX @@ static void sifive_u_machine_init(MachineState *machine)
22
RISCVHartArrayState soc[VIRT_SOCKETS_MAX];
23
DeviceState *plic[VIRT_SOCKETS_MAX];
24
PFlashCFI01 *flash[2];
25
+ FWCfgState *fw_cfg;
26
27
int fdt_size;
28
};
29
@@ -XXX,XX +XXX,XX @@ enum {
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
38
index XXXXXXX..XXXXXXX 100644
39
--- a/hw/riscv/virt.c
40
+++ 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)
79
start_addr = virt_memmap[VIRT_FLASH].base;
80
}
27
}
81
28
82
+ /*
29
/* reset vector */
83
+ * Init fw_cfg. Must be done before riscv_load_fdt, otherwise the device
30
- uint32_t reset_vec[11] = {
84
+ * tree cannot be altered and we get FDT_ERR_NOSPACE.
31
+ uint32_t reset_vec[12] = {
85
+ */
32
s->msel, /* MSEL pin state */
86
+ s->fw_cfg = create_fw_cfg(machine);
33
0x00000297, /* 1: auipc t0, %pcrel_hi(fw_dyn) */
87
+ rom_set_fw(s->fw_cfg);
34
- 0x02828613, /* addi a2, t0, %pcrel_lo(1b) */
88
+
35
+ 0x02c28613, /* addi a2, t0, %pcrel_lo(1b) */
89
/* Compute the fdt load address in dram */
36
0xf1402573, /* csrr a0, mhartid */
90
fdt_load_addr = riscv_load_fdt(memmap[VIRT_DRAM].base,
37
0,
91
machine->ram_size, machine->fdt);
38
0,
92
diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig
39
@@ -XXX,XX +XXX,XX @@ static void sifive_u_machine_init(MachineState *machine)
93
index XXXXXXX..XXXXXXX 100644
40
start_addr, /* start: .dword */
94
--- a/hw/riscv/Kconfig
41
start_addr_hi32,
95
+++ b/hw/riscv/Kconfig
42
fdt_load_addr, /* fdt_laddr: .dword */
96
@@ -XXX,XX +XXX,XX @@ config RISCV_VIRT
43
+ 0x00000000,
97
select SIFIVE_PLIC
44
0x00000000,
98
select SIFIVE_TEST
45
/* fw_dyn: */
99
select VIRTIO_MMIO
46
};
100
+ select FW_CFG_DMA
101
102
config SIFIVE_E
103
bool
104
--
47
--
105
2.30.1
48
2.31.1
106
49
107
50
diff view generated by jsdifflib
1
From: Alexander Wagner <alexander.wagner@ulal.de>
1
Update the register layout to match the latest OpenTitan bitstream.
2
2
3
Not disabling the UART leads to QEMU overwriting the UART receive buffer with
3
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
4
the newest received byte. The rx_level variable is added to allow the use of
4
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
5
the existing OpenTitan driver libraries.
5
Message-id: 25c8377d32f3e0f0a1a862c8a5092f8a9e3f9928.1625801868.git.alistair.francis@wdc.com
6
---
7
hw/char/ibex_uart.c | 19 ++++++++++---------
8
1 file changed, 10 insertions(+), 9 deletions(-)
6
9
7
Signed-off-by: Alexander Wagner <alexander.wagner@ulal.de>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Message-id: 20210309152130.13038-1-alexander.wagner@ulal.de
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
12
include/hw/char/ibex_uart.h | 4 ++++
13
hw/char/ibex_uart.c | 23 ++++++++++++++++++-----
14
2 files changed, 22 insertions(+), 5 deletions(-)
15
16
diff --git a/include/hw/char/ibex_uart.h b/include/hw/char/ibex_uart.h
17
index XXXXXXX..XXXXXXX 100644
18
--- a/include/hw/char/ibex_uart.h
19
+++ b/include/hw/char/ibex_uart.h
20
@@ -XXX,XX +XXX,XX @@ REG32(FIFO_CTRL, 0x1c)
21
FIELD(FIFO_CTRL, RXILVL, 2, 3)
22
FIELD(FIFO_CTRL, TXILVL, 5, 2)
23
REG32(FIFO_STATUS, 0x20)
24
+ FIELD(FIFO_STATUS, TXLVL, 0, 5)
25
+ FIELD(FIFO_STATUS, RXLVL, 16, 5)
26
REG32(OVRD, 0x24)
27
REG32(VAL, 0x28)
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
+
35
QEMUTimer *fifo_trigger_handle;
36
uint64_t char_tx_time;
37
38
diff --git a/hw/char/ibex_uart.c b/hw/char/ibex_uart.c
10
diff --git a/hw/char/ibex_uart.c b/hw/char/ibex_uart.c
39
index XXXXXXX..XXXXXXX 100644
11
index XXXXXXX..XXXXXXX 100644
40
--- a/hw/char/ibex_uart.c
12
--- a/hw/char/ibex_uart.c
41
+++ b/hw/char/ibex_uart.c
13
+++ b/hw/char/ibex_uart.c
42
@@ -XXX,XX +XXX,XX @@ static int ibex_uart_can_receive(void *opaque)
14
@@ -XXX,XX +XXX,XX @@ REG32(INTR_STATE, 0x00)
15
FIELD(INTR_STATE, RX_OVERFLOW, 3, 1)
16
REG32(INTR_ENABLE, 0x04)
17
REG32(INTR_TEST, 0x08)
18
-REG32(CTRL, 0x0C)
19
+REG32(ALERT_TEST, 0x0C)
20
+REG32(CTRL, 0x10)
21
FIELD(CTRL, TX_ENABLE, 0, 1)
22
FIELD(CTRL, RX_ENABLE, 1, 1)
23
FIELD(CTRL, NF, 2, 1)
24
@@ -XXX,XX +XXX,XX @@ REG32(CTRL, 0x0C)
25
FIELD(CTRL, PARITY_ODD, 7, 1)
26
FIELD(CTRL, RXBLVL, 8, 2)
27
FIELD(CTRL, NCO, 16, 16)
28
-REG32(STATUS, 0x10)
29
+REG32(STATUS, 0x14)
30
FIELD(STATUS, TXFULL, 0, 1)
31
FIELD(STATUS, RXFULL, 1, 1)
32
FIELD(STATUS, TXEMPTY, 2, 1)
33
FIELD(STATUS, RXIDLE, 4, 1)
34
FIELD(STATUS, RXEMPTY, 5, 1)
35
-REG32(RDATA, 0x14)
36
-REG32(WDATA, 0x18)
37
-REG32(FIFO_CTRL, 0x1c)
38
+REG32(RDATA, 0x18)
39
+REG32(WDATA, 0x1C)
40
+REG32(FIFO_CTRL, 0x20)
41
FIELD(FIFO_CTRL, RXRST, 0, 1)
42
FIELD(FIFO_CTRL, TXRST, 1, 1)
43
FIELD(FIFO_CTRL, RXILVL, 2, 3)
44
FIELD(FIFO_CTRL, TXILVL, 5, 2)
45
-REG32(FIFO_STATUS, 0x20)
46
+REG32(FIFO_STATUS, 0x24)
47
FIELD(FIFO_STATUS, TXLVL, 0, 5)
48
FIELD(FIFO_STATUS, RXLVL, 16, 5)
49
-REG32(OVRD, 0x24)
50
-REG32(VAL, 0x28)
51
-REG32(TIMEOUT_CTRL, 0x2c)
52
+REG32(OVRD, 0x28)
53
+REG32(VAL, 0x2C)
54
+REG32(TIMEOUT_CTRL, 0x30)
55
56
static void ibex_uart_update_irqs(IbexUartState *s)
43
{
57
{
44
IbexUartState *s = opaque;
45
46
- if (s->uart_ctrl & R_CTRL_RX_ENABLE_MASK) {
47
+ if ((s->uart_ctrl & R_CTRL_RX_ENABLE_MASK)
48
+ && !(s->uart_status & R_STATUS_RXFULL_MASK)) {
49
return 1;
50
}
51
52
@@ -XXX,XX +XXX,XX @@ static void ibex_uart_receive(void *opaque, const uint8_t *buf, int size)
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
+ }
88
}
89
break;
90
case R_WDATA:
91
@@ -XXX,XX +XXX,XX @@ static uint64_t ibex_uart_read(void *opaque, hwaddr addr,
92
case R_FIFO_STATUS:
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
}
109
--
58
--
110
2.30.1
59
2.31.1
111
60
112
61
diff view generated by jsdifflib
Deleted patch
1
From: Jim Shu <cwshu@andestech.com>
2
1
3
Like MMU translation, add qemu log of PMP permission checking for
4
debugging.
5
6
Signed-off-by: Jim Shu <cwshu@andestech.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Message-id: 1613916082-19528-3-git-send-email-cwshu@andestech.com
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
---
11
target/riscv/cpu_helper.c | 12 ++++++++++++
12
1 file changed, 12 insertions(+)
13
14
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/target/riscv/cpu_helper.c
17
+++ b/target/riscv/cpu_helper.c
18
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
19
if (ret == TRANSLATE_SUCCESS) {
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
}
30
31
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
32
if (ret == TRANSLATE_SUCCESS) {
33
ret = get_physical_address_pmp(env, &prot_pmp, &tlb_size, pa,
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
}
43
}
44
--
45
2.30.1
46
47
diff view generated by jsdifflib
Deleted patch
1
From: Jim Shu <cwshu@andestech.com>
2
1
3
If PMP permission of any address has been changed by updating PMP entry,
4
flush all TLB pages to prevent from getting old permission.
5
6
Signed-off-by: Jim Shu <cwshu@andestech.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Message-id: 1613916082-19528-4-git-send-email-cwshu@andestech.com
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
---
11
target/riscv/pmp.c | 4 ++++
12
1 file changed, 4 insertions(+)
13
14
diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/target/riscv/pmp.c
17
+++ b/target/riscv/pmp.c
18
@@ -XXX,XX +XXX,XX @@
19
#include "qapi/error.h"
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
}
34
35
36
--
37
2.30.1
38
39
diff view generated by jsdifflib
Deleted patch
1
From: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
2
1
3
According to the specification the "field SPVP of hstatus controls the
4
privilege level of the access" for the hypervisor virtual-machine load
5
and store instructions HLV, HLVX and HSV.
6
7
Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Message-id: 20210311103005.1400718-1-georg.kotheimer@kernkonzept.com
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
12
target/riscv/cpu_helper.c | 25 ++++++++++++++-----------
13
1 file changed, 14 insertions(+), 11 deletions(-)
14
15
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/cpu_helper.c
18
+++ b/target/riscv/cpu_helper.c
19
@@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,
20
use_background = true;
21
}
22
23
- if (mode == PRV_M && access_type != MMU_INST_FETCH) {
24
+ /* MPRV does not affect the virtual-machine load/store
25
+ instructions, HLV, HLVX, and HSV. */
26
+ if (riscv_cpu_two_stage_lookup(mmu_idx)) {
27
+ mode = get_field(env->hstatus, HSTATUS_SPVP);
28
+ } else if (mode == PRV_M && access_type != MMU_INST_FETCH) {
29
if (get_field(env->mstatus, MSTATUS_MPRV)) {
30
mode = get_field(env->mstatus, MSTATUS_MPP);
31
}
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
--
62
2.30.1
63
64
diff view generated by jsdifflib
Deleted patch
1
From: Asherah Connor <ashe@kivikakk.ee>
2
1
3
Allow ramfb on virt. This lets `-device ramfb' work.
4
5
Signed-off-by: Asherah Connor <ashe@kivikakk.ee>
6
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Message-id: 20210318235041.17175-3-ashe@kivikakk.ee
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
---
11
hw/riscv/virt.c | 3 +++
12
1 file changed, 3 insertions(+)
13
14
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/riscv/virt.c
17
+++ b/hw/riscv/virt.c
18
@@ -XXX,XX +XXX,XX @@
19
#include "sysemu/sysemu.h"
20
#include "hw/pci/pci.h"
21
#include "hw/pci-host/gpex.h"
22
+#include "hw/display/ramfb.h"
23
24
static const MemMapEntry virt_memmap[] = {
25
[VIRT_DEBUG] = { 0x0, 0x100 },
26
@@ -XXX,XX +XXX,XX @@ static void virt_machine_class_init(ObjectClass *oc, void *data)
27
mc->cpu_index_to_instance_props = riscv_numa_cpu_index_to_props;
28
mc->get_default_cpu_node_id = riscv_numa_get_default_cpu_node_id;
29
mc->numa_mem_supported = true;
30
+
31
+ machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE);
32
}
33
34
static const TypeInfo virt_machine_typeinfo = {
35
--
36
2.30.1
37
38
diff view generated by jsdifflib
1
From: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
1
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
3
Message-id: ed707782e84118e1b06a32fd79b70fecfb54ff82.1625801868.git.alistair.francis@wdc.com
4
---
5
include/hw/riscv/opentitan.h | 1 +
6
hw/riscv/opentitan.c | 3 +++
7
2 files changed, 4 insertions(+)
2
8
3
When decode_insn16() fails, we fall back to decode_RV32_64C() for
9
diff --git a/include/hw/riscv/opentitan.h b/include/hw/riscv/opentitan.h
4
further compressed instruction decoding. However, prior to this change,
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
10
Instead of patching decode_RV32_64C(), we can just remove it,
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>
15
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
16
Message-id: 20210322121609.3097928-1-georg.kotheimer@kernkonzept.com
17
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
18
---
19
target/riscv/translate.c | 179 +--------------------------------------
20
1 file changed, 1 insertion(+), 178 deletions(-)
21
22
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
23
index XXXXXXX..XXXXXXX 100644
10
index XXXXXXX..XXXXXXX 100644
24
--- a/target/riscv/translate.c
11
--- a/include/hw/riscv/opentitan.h
25
+++ b/target/riscv/translate.c
12
+++ b/include/hw/riscv/opentitan.h
26
@@ -XXX,XX +XXX,XX @@ typedef struct DisasContext {
13
@@ -XXX,XX +XXX,XX @@ enum {
27
CPUState *cs;
14
IBEX_DEV_ALERT_HANDLER,
28
} DisasContext;
15
IBEX_DEV_NMI_GEN,
29
16
IBEX_DEV_OTBN,
30
-#ifdef TARGET_RISCV64
17
+ IBEX_DEV_PERI,
31
-/* convert riscv funct3 to qemu memop for load/store */
18
};
32
-static const int tcg_memop_lookup[8] = {
19
33
- [0 ... 7] = -1,
20
enum {
34
- [0] = MO_SB,
21
diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c
35
- [1] = MO_TESW,
22
index XXXXXXX..XXXXXXX 100644
36
- [2] = MO_TESL,
23
--- a/hw/riscv/opentitan.c
37
- [3] = MO_TEQ,
24
+++ b/hw/riscv/opentitan.c
38
- [4] = MO_UB,
25
@@ -XXX,XX +XXX,XX @@ static const MemMapEntry ibex_memmap[] = {
39
- [5] = MO_TEUW,
26
[IBEX_DEV_ALERT_HANDLER] = { 0x411b0000, 0x1000 },
40
- [6] = MO_TEUL,
27
[IBEX_DEV_NMI_GEN] = { 0x411c0000, 0x1000 },
41
-};
28
[IBEX_DEV_OTBN] = { 0x411d0000, 0x10000 },
42
-#endif
29
+ [IBEX_DEV_PERI] = { 0x411f0000, 0x10000 },
43
-
30
};
44
#ifdef TARGET_RISCV64
31
45
#define CASE_OP_32_64(X) case X: case glue(X, W)
32
static void opentitan_board_init(MachineState *machine)
46
#else
33
@@ -XXX,XX +XXX,XX @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp)
47
@@ -XXX,XX +XXX,XX @@ static void gen_jal(DisasContext *ctx, int rd, target_ulong imm)
34
memmap[IBEX_DEV_NMI_GEN].base, memmap[IBEX_DEV_NMI_GEN].size);
48
ctx->base.is_jmp = DISAS_NORETURN;
35
create_unimplemented_device("riscv.lowrisc.ibex.otbn",
36
memmap[IBEX_DEV_OTBN].base, memmap[IBEX_DEV_OTBN].size);
37
+ create_unimplemented_device("riscv.lowrisc.ibex.peri",
38
+ memmap[IBEX_DEV_PERI].base, memmap[IBEX_DEV_PERI].size);
49
}
39
}
50
40
51
-#ifdef TARGET_RISCV64
41
static void lowrisc_ibex_soc_class_init(ObjectClass *oc, void *data)
52
-static void gen_load_c(DisasContext *ctx, uint32_t opc, int rd, int rs1,
53
- target_long imm)
54
-{
55
- TCGv t0 = tcg_temp_new();
56
- TCGv t1 = tcg_temp_new();
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
-}
71
-
72
-static void gen_store_c(DisasContext *ctx, uint32_t opc, int rs1, int rs2,
73
- target_long imm)
74
-{
75
- TCGv t0 = tcg_temp_new();
76
- TCGv dat = tcg_temp_new();
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
-}
139
-
140
-static void gen_fp_store(DisasContext *ctx, uint32_t opc, int rs1,
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
{
179
TCGv_i32 t0;
180
@@ -XXX,XX +XXX,XX @@ static void gen_set_rm(DisasContext *ctx, int rm)
181
tcg_temp_free_i32(t0);
182
}
183
184
-static void decode_RV32_64C0(DisasContext *ctx, uint16_t opcode)
185
-{
186
- uint8_t funct3 = extract16(opcode, 13, 3);
187
- uint8_t rd_rs2 = GET_C_RS2S(opcode);
188
- uint8_t rs1s = GET_C_RS1S(opcode);
189
-
190
- switch (funct3) {
191
- case 3:
192
-#if defined(TARGET_RISCV64)
193
- /* C.LD(RV64/128) -> ld rd', offset[7:3](rs1')*/
194
- gen_load_c(ctx, OPC_RISC_LD, rd_rs2, rs1s,
195
- GET_C_LD_IMM(opcode));
196
-#else
197
- /* C.FLW (RV32) -> flw rd', offset[6:2](rs1')*/
198
- gen_fp_load(ctx, OPC_RISC_FLW, rd_rs2, rs1s,
199
- GET_C_LW_IMM(opcode));
200
-#endif
201
- break;
202
- case 7:
203
-#if defined(TARGET_RISCV64)
204
- /* C.SD (RV64/128) -> sd rs2', offset[7:3](rs1')*/
205
- gen_store_c(ctx, OPC_RISC_SD, rs1s, rd_rs2,
206
- GET_C_LD_IMM(opcode));
207
-#else
208
- /* C.FSW (RV32) -> fsw rs2', offset[6:2](rs1')*/
209
- gen_fp_store(ctx, OPC_RISC_FSW, rs1s, rd_rs2,
210
- GET_C_LW_IMM(opcode));
211
-#endif
212
- break;
213
- }
214
-}
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
--
42
--
241
2.30.1
43
2.31.1
242
44
243
45
diff view generated by jsdifflib
1
From: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
1
OpenTitan has an alias of flash avaliable which is called virtual flash.
2
Add support for that in the QEMU model.
2
3
3
The current two-stage lookup detection in riscv_cpu_do_interrupt falls
4
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
4
short of its purpose, as all it checks is whether two-stage address
5
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
5
translation either via the hypervisor-load store instructions or the
6
Message-id: c9cfbd2dd840fd0076877b8ea4d6dcfce60db5e9.1625801868.git.alistair.francis@wdc.com
6
MPRV feature would be allowed.
7
---
8
include/hw/riscv/opentitan.h | 2 ++
9
hw/riscv/opentitan.c | 6 ++++++
10
2 files changed, 8 insertions(+)
7
11
8
What we really need instead is whether two-stage address translation was
12
diff --git a/include/hw/riscv/opentitan.h b/include/hw/riscv/opentitan.h
9
active when the exception was raised. However, in riscv_cpu_do_interrupt
10
we do not have the information to reliably detect this. Therefore, when
11
we raise a memory fault exception we have to record whether two-stage
12
address translation is active.
13
14
Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
15
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
16
Message-id: 20210319141459.1196741-1-georg.kotheimer@kernkonzept.com
17
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
18
---
19
target/riscv/cpu.h | 4 ++++
20
target/riscv/cpu.c | 1 +
21
target/riscv/cpu_helper.c | 21 ++++++++-------------
22
3 files changed, 13 insertions(+), 13 deletions(-)
23
24
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
25
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
26
--- a/target/riscv/cpu.h
14
--- a/include/hw/riscv/opentitan.h
27
+++ b/target/riscv/cpu.h
15
+++ b/include/hw/riscv/opentitan.h
28
@@ -XXX,XX +XXX,XX @@ struct CPURISCVState {
16
@@ -XXX,XX +XXX,XX @@ struct LowRISCIbexSoCState {
29
target_ulong satp_hs;
17
30
uint64_t mstatus_hs;
18
MemoryRegion flash_mem;
31
19
MemoryRegion rom;
32
+ /* Signals whether the current exception occurred with two-stage address
20
+ MemoryRegion flash_alias;
33
+ translation active. */
21
};
34
+ bool two_stage_lookup;
22
35
+
23
typedef struct OpenTitanState {
36
target_ulong scounteren;
24
@@ -XXX,XX +XXX,XX @@ enum {
37
target_ulong mcounteren;
25
IBEX_DEV_ROM,
38
26
IBEX_DEV_RAM,
39
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
27
IBEX_DEV_FLASH,
28
+ IBEX_DEV_FLASH_VIRTUAL,
29
IBEX_DEV_UART,
30
IBEX_DEV_GPIO,
31
IBEX_DEV_SPI,
32
diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c
40
index XXXXXXX..XXXXXXX 100644
33
index XXXXXXX..XXXXXXX 100644
41
--- a/target/riscv/cpu.c
34
--- a/hw/riscv/opentitan.c
42
+++ b/target/riscv/cpu.c
35
+++ b/hw/riscv/opentitan.c
43
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset(DeviceState *dev)
36
@@ -XXX,XX +XXX,XX @@ static const MemMapEntry ibex_memmap[] = {
44
env->mstatus &= ~(MSTATUS_MIE | MSTATUS_MPRV);
37
[IBEX_DEV_NMI_GEN] = { 0x411c0000, 0x1000 },
45
env->mcause = 0;
38
[IBEX_DEV_OTBN] = { 0x411d0000, 0x10000 },
46
env->pc = env->resetvec;
39
[IBEX_DEV_PERI] = { 0x411f0000, 0x10000 },
47
+ env->two_stage_lookup = false;
40
+ [IBEX_DEV_FLASH_VIRTUAL] = { 0x80000000, 0x80000 },
48
#endif
41
};
49
cs->exception_index = EXCP_NONE;
42
50
env->load_res = -1;
43
static void opentitan_board_init(MachineState *machine)
51
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
44
@@ -XXX,XX +XXX,XX @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp)
52
index XXXXXXX..XXXXXXX 100644
45
/* Flash memory */
53
--- a/target/riscv/cpu_helper.c
46
memory_region_init_rom(&s->flash_mem, OBJECT(dev_soc), "riscv.lowrisc.ibex.flash",
54
+++ b/target/riscv/cpu_helper.c
47
memmap[IBEX_DEV_FLASH].size, &error_fatal);
55
@@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address,
48
+ memory_region_init_alias(&s->flash_alias, OBJECT(dev_soc),
56
g_assert_not_reached();
49
+ "riscv.lowrisc.ibex.flash_virtual", &s->flash_mem, 0,
57
}
50
+ memmap[IBEX_DEV_FLASH_VIRTUAL].size);
58
env->badaddr = address;
51
memory_region_add_subregion(sys_mem, memmap[IBEX_DEV_FLASH].base,
59
+ env->two_stage_lookup = two_stage;
52
&s->flash_mem);
60
}
53
+ memory_region_add_subregion(sys_mem, memmap[IBEX_DEV_FLASH_VIRTUAL].base,
61
54
+ &s->flash_alias);
62
hwaddr riscv_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
55
63
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr,
56
/* PLIC */
64
}
57
if (!sysbus_realize(SYS_BUS_DEVICE(&s->plic), errp)) {
65
66
env->badaddr = addr;
67
+ env->two_stage_lookup = riscv_cpu_virt_enabled(env) ||
68
+ riscv_cpu_two_stage_lookup(mmu_idx);
69
riscv_raise_exception(&cpu->env, cs->exception_index, retaddr);
70
}
71
72
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr,
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
--
58
--
120
2.30.1
59
2.31.1
121
60
122
61
diff view generated by jsdifflib