1
The following changes since commit c95bd5ff1660883d15ad6e0005e4c8571604f51a:
1
The following changes since commit d0ac9a61474cf594d19082bc8976247e984ea9a3:
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/thuth-gitlab/tags/pull-request-2021-06-21' into staging (2021-06-24 09:31:26 +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-20210624-2
8
8
9
for you to fetch changes up to 9a27f69bd668d9d71674407badc412ce1231c7d5:
9
for you to fetch changes up to 3ef6434409c575e11faf537ce50ca05426c78940:
10
10
11
target/riscv: Prevent lost illegal instruction exceptions (2021-03-22 21:54:40 -0400)
11
hw/riscv: OpenTitan: Connect the mtime and mtimecmp timer (2021-06-24 05:00:13 -0700)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
RISC-V PR for 6.0
14
Third RISC-V PR for 6.1 release
15
15
16
This PR includes:
16
- Fix MISA in the DisasContext
17
- Fix for vector CSR access
17
- Fix GDB CSR XML generation
18
- Improvements to the Ibex UART device
18
- QOMify the SiFive UART
19
- PMP improvements and bug fixes
19
- Add support for the OpenTitan timer
20
- Hypervisor extension bug fixes
21
- ramfb support for the virt machine
22
- Fast read support for SST flash
23
- Improvements to the microchip_pfsoc machine
24
20
25
----------------------------------------------------------------
21
----------------------------------------------------------------
26
Alexander Wagner (1):
22
Alistair Francis (4):
27
hw/char: disable ibex uart receive if the buffer is full
23
target/riscv: Use target_ulong for the DisasContext misa
24
hw/char/ibex_uart: Make the register layout private
25
hw/timer: Initial commit of Ibex Timer
26
hw/riscv: OpenTitan: Connect the mtime and mtimecmp timer
28
27
29
Asherah Connor (2):
28
Bin Meng (1):
30
hw/riscv: Add fw_cfg support to virt
29
target/riscv: gdbstub: Fix dynamic CSR XML generation
31
hw/riscv: allow ramfb on virt
32
30
33
Bin Meng (3):
31
Lukas Jünger (2):
34
hw/block: m25p80: Support fast read for SST flashes
32
hw/char: Consistent function names for sifive_uart
35
hw/riscv: microchip_pfsoc: Map EMMC/SD mux register
33
hw/char: QOMify sifive_uart
36
docs/system: riscv: Add documentation for 'microchip-icicle-kit' machine
37
34
38
Frank Chang (1):
35
include/hw/char/ibex_uart.h | 37 -----
39
target/riscv: fix vs() to return proper error code
36
include/hw/char/sifive_uart.h | 11 +-
37
include/hw/riscv/opentitan.h | 5 +-
38
include/hw/timer/ibex_timer.h | 52 +++++++
39
hw/char/ibex_uart.c | 37 +++++
40
hw/char/sifive_uart.c | 152 +++++++++++++++++----
41
hw/riscv/opentitan.c | 14 +-
42
hw/timer/ibex_timer.c | 305 ++++++++++++++++++++++++++++++++++++++++++
43
target/riscv/gdbstub.c | 2 +-
44
target/riscv/translate.c | 2 +-
45
MAINTAINERS | 6 +-
46
hw/timer/meson.build | 1 +
47
12 files changed, 543 insertions(+), 81 deletions(-)
48
create mode 100644 include/hw/timer/ibex_timer.h
49
create mode 100644 hw/timer/ibex_timer.c
40
50
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: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
1
The is_32bit() check in translate.c expects a 64-bit guest to have a
2
64-bit misa value otherwise the macro check won't work. This patches
3
fixes that and fixes a Coverity issue at the same time.
2
4
3
When decode_insn16() fails, we fall back to decode_RV32_64C() for
5
Fixes: CID 1453107
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>
6
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
7
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
8
Message-id: c00176c7518c2a7b4de3eec320b6a683ab56f705.1622435221.git.alistair.francis@wdc.com
18
---
9
---
19
target/riscv/translate.c | 179 +--------------------------------------
10
target/riscv/translate.c | 2 +-
20
1 file changed, 1 insertion(+), 178 deletions(-)
11
1 file changed, 1 insertion(+), 1 deletion(-)
21
12
22
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
13
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
23
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
24
--- a/target/riscv/translate.c
15
--- a/target/riscv/translate.c
25
+++ b/target/riscv/translate.c
16
+++ b/target/riscv/translate.c
26
@@ -XXX,XX +XXX,XX @@ typedef struct DisasContext {
17
@@ -XXX,XX +XXX,XX @@ typedef struct DisasContext {
27
CPUState *cs;
18
bool virt_enabled;
28
} DisasContext;
19
uint32_t opcode;
29
20
uint32_t mstatus_fs;
30
-#ifdef TARGET_RISCV64
21
- uint32_t misa;
31
-/* convert riscv funct3 to qemu memop for load/store */
22
+ target_ulong misa;
32
-static const int tcg_memop_lookup[8] = {
23
uint32_t mem_idx;
33
- [0 ... 7] = -1,
24
/* Remember the rounding mode encoded in the previous fp instruction,
34
- [0] = MO_SB,
25
which we have already installed into env->fp_status. Or -1 for
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
}
50
51
-#ifdef TARGET_RISCV64
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
--
26
--
241
2.30.1
27
2.31.1
242
28
243
29
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
Since commit 605def6eeee5 ("target/riscv: Use the RISCVException enum for CSR operations")
4
been updated to use a register mapped at 0x4f000000 instead of a
4
the CSR predicate() function was changed to return RISCV_EXCP_NONE
5
GPIO to control whether eMMC or SD card is to be used. With this
5
instead of 0 for a valid CSR, but it forgot to update the dynamic
6
support the same HSS image can be used for both eMMC and SD card
6
CSR XML generation codes in gdbstub.
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
7
11
With this commit, HSS image built from 2020.12 release boots again.
8
Fixes: 605def6eeee5 ("target/riscv: Use the RISCVException enum for CSR operations")
12
9
Reported-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
13
Signed-off-by: Bin Meng <bin.meng@windriver.com>
10
Signed-off-by: Bin Meng <bin.meng@windriver.com>
11
Tested-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
14
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
12
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
15
Message-id: 20210322075248.136255-1-bmeng.cn@gmail.com
13
Message-id: 20210615085133.389887-1-bmeng.cn@gmail.com
16
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
17
---
15
---
18
include/hw/riscv/microchip_pfsoc.h | 1 +
16
target/riscv/gdbstub.c | 2 +-
19
hw/riscv/microchip_pfsoc.c | 6 ++++++
17
1 file changed, 1 insertion(+), 1 deletion(-)
20
2 files changed, 7 insertions(+)
21
18
22
diff --git a/include/hw/riscv/microchip_pfsoc.h b/include/hw/riscv/microchip_pfsoc.h
19
diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c
23
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
24
--- a/include/hw/riscv/microchip_pfsoc.h
21
--- a/target/riscv/gdbstub.c
25
+++ b/include/hw/riscv/microchip_pfsoc.h
22
+++ b/target/riscv/gdbstub.c
26
@@ -XXX,XX +XXX,XX @@ enum {
23
@@ -XXX,XX +XXX,XX @@ static int riscv_gen_dynamic_csr_xml(CPUState *cs, int base_reg)
27
MICROCHIP_PFSOC_ENVM_DATA,
24
28
MICROCHIP_PFSOC_QSPI_XIP,
25
for (i = 0; i < CSR_TABLE_SIZE; i++) {
29
MICROCHIP_PFSOC_IOSCB,
26
predicate = csr_ops[i].predicate;
30
+ MICROCHIP_PFSOC_EMMC_SD_MUX,
27
- if (predicate && !predicate(env, i)) {
31
MICROCHIP_PFSOC_DRAM_LO,
28
+ if (predicate && (predicate(env, i) == RISCV_EXCP_NONE)) {
32
MICROCHIP_PFSOC_DRAM_LO_ALIAS,
29
if (csr_ops[i].name) {
33
MICROCHIP_PFSOC_DRAM_HI,
30
g_string_append_printf(s, "<reg name=\"%s\"", csr_ops[i].name);
34
diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c
31
} else {
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
+
55
/* QSPI Flash */
56
memory_region_init_rom(qspi_xip_mem, OBJECT(dev),
57
"microchip.pfsoc.qspi_xip",
58
--
32
--
59
2.30.1
33
2.31.1
60
34
61
35
diff view generated by jsdifflib
1
From: Jim Shu <cwshu@andestech.com>
1
From: Lukas Jünger <lukas.juenger@greensocs.com>
2
2
3
Currently, PMP permission checking of TLB page is bypassed if TLB hits
3
This cleans up function names in the SiFive UART model.
4
Fix it by propagating PMP permission to TLB page permission.
5
4
6
PMP permission checking also use MMU-style API to change TLB permission
5
Signed-off-by: Lukas Jünger <lukas.juenger@greensocs.com>
7
and size.
8
9
Signed-off-by: Jim Shu <cwshu@andestech.com>
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
6
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Message-id: 1613916082-19528-2-git-send-email-cwshu@andestech.com
7
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
8
Message-id: 20210616092326.59639-2-lukas.juenger@greensocs.com
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
10
---
14
target/riscv/pmp.h | 4 +-
11
hw/char/sifive_uart.c | 46 ++++++++++++++++++++++---------------------
15
target/riscv/cpu_helper.c | 84 +++++++++++++++++++++++++++++----------
12
1 file changed, 24 insertions(+), 22 deletions(-)
16
target/riscv/pmp.c | 80 +++++++++++++++++++++++++++----------
17
3 files changed, 125 insertions(+), 43 deletions(-)
18
13
19
diff --git a/target/riscv/pmp.h b/target/riscv/pmp.h
14
diff --git a/hw/char/sifive_uart.c b/hw/char/sifive_uart.c
20
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
21
--- a/target/riscv/pmp.h
16
--- a/hw/char/sifive_uart.c
22
+++ b/target/riscv/pmp.h
17
+++ b/hw/char/sifive_uart.c
23
@@ -XXX,XX +XXX,XX @@ void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index,
18
@@ -XXX,XX +XXX,XX @@
24
target_ulong val);
19
*/
25
target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index);
20
26
bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,
21
/* Returns the state of the IP (interrupt pending) register */
27
- target_ulong size, pmp_priv_t priv, target_ulong mode);
22
-static uint64_t uart_ip(SiFiveUARTState *s)
28
+ target_ulong size, pmp_priv_t privs, pmp_priv_t *allowed_privs,
23
+static uint64_t sifive_uart_ip(SiFiveUARTState *s)
29
+ target_ulong mode);
24
{
30
bool pmp_is_range_in_tlb(CPURISCVState *env, hwaddr tlb_sa,
25
uint64_t ret = 0;
31
target_ulong *tlb_size);
26
32
void pmp_update_rule_addr(CPURISCVState *env, uint32_t pmp_index);
27
@@ -XXX,XX +XXX,XX @@ static uint64_t uart_ip(SiFiveUARTState *s)
33
void pmp_update_rule_nums(CPURISCVState *env);
28
return ret;
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
}
29
}
45
30
46
+/*
31
-static void update_irq(SiFiveUARTState *s)
47
+ * get_physical_address_pmp - check PMP permission for this physical address
32
+static void sifive_uart_update_irq(SiFiveUARTState *s)
48
+ *
33
{
49
+ * Match the PMP region and check permission for this physical address and it's
34
int cond = 0;
50
+ * TLB page. Returns 0 if the permission checking was successful
35
if ((s->ie & SIFIVE_UART_IE_TXWM) ||
51
+ *
36
@@ -XXX,XX +XXX,XX @@ static void update_irq(SiFiveUARTState *s)
52
+ * @env: CPURISCVState
37
}
53
+ * @prot: The returned protection attributes
38
54
+ * @tlb_size: TLB page size containing addr. It could be modified after PMP
39
static uint64_t
55
+ * permission checking. NULL if not set TLB page for addr.
40
-uart_read(void *opaque, hwaddr addr, unsigned int size)
56
+ * @addr: The physical address to be checked permission
41
+sifive_uart_read(void *opaque, hwaddr addr, unsigned int size)
57
+ * @access_type: The type of MMU access
42
{
58
+ * @mode: Indicates current privilege level.
43
SiFiveUARTState *s = opaque;
59
+ */
44
unsigned char r;
60
+static int get_physical_address_pmp(CPURISCVState *env, int *prot,
45
@@ -XXX,XX +XXX,XX @@ uart_read(void *opaque, hwaddr addr, unsigned int size)
61
+ target_ulong *tlb_size, hwaddr addr,
46
memmove(s->rx_fifo, s->rx_fifo + 1, s->rx_fifo_len - 1);
62
+ int size, MMUAccessType access_type,
47
s->rx_fifo_len--;
63
+ int mode)
48
qemu_chr_fe_accept_input(&s->chr);
64
+{
49
- update_irq(s);
65
+ pmp_priv_t pmp_priv;
50
+ sifive_uart_update_irq(s);
66
+ target_ulong tlb_size_pmp = 0;
51
return r;
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
}
52
}
95
53
return 0x80000000;
96
- if (riscv_feature(env, RISCV_FEATURE_PMP) &&
54
@@ -XXX,XX +XXX,XX @@ uart_read(void *opaque, hwaddr addr, unsigned int size)
97
- !pmp_hart_has_privs(env, pte_addr, sizeof(target_ulong),
55
case SIFIVE_UART_IE:
98
- 1 << MMU_DATA_LOAD, PRV_S)) {
56
return s->ie;
99
+ int pmp_prot;
57
case SIFIVE_UART_IP:
100
+ int pmp_ret = get_physical_address_pmp(env, &pmp_prot, NULL, pte_addr,
58
- return uart_ip(s);
101
+ sizeof(target_ulong),
59
+ return sifive_uart_ip(s);
102
+ MMU_DATA_LOAD, PRV_S);
60
case SIFIVE_UART_TXCTRL:
103
+ if (pmp_ret != TRANSLATE_SUCCESS) {
61
return s->txctrl;
104
return TRANSLATE_PMP_FAIL;
62
case SIFIVE_UART_RXCTRL:
105
}
63
@@ -XXX,XX +XXX,XX @@ uart_read(void *opaque, hwaddr addr, unsigned int size)
106
64
}
107
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
65
108
#ifndef CONFIG_USER_ONLY
66
static void
109
vaddr im_address;
67
-uart_write(void *opaque, hwaddr addr,
110
hwaddr pa = 0;
68
- uint64_t val64, unsigned int size)
111
- int prot, prot2;
69
+sifive_uart_write(void *opaque, hwaddr addr,
112
+ int prot, prot2, prot_pmp;
70
+ uint64_t val64, unsigned int size)
113
bool pmp_violation = false;
71
{
114
bool first_stage_error = true;
72
SiFiveUARTState *s = opaque;
115
bool two_stage_lookup = false;
73
uint32_t value = val64;
116
int ret = TRANSLATE_FAIL;
74
@@ -XXX,XX +XXX,XX @@ uart_write(void *opaque, hwaddr addr,
117
int mode = mmu_idx;
75
switch (addr) {
118
- target_ulong tlb_size = 0;
76
case SIFIVE_UART_TXFIFO:
119
+ /* default TLB page size */
77
qemu_chr_fe_write(&s->chr, &ch, 1);
120
+ target_ulong tlb_size = TARGET_PAGE_SIZE;
78
- update_irq(s);
121
79
+ sifive_uart_update_irq(s);
122
env->guest_phys_fault_addr = 0;
80
return;
123
81
case SIFIVE_UART_IE:
124
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
82
s->ie = val64;
125
83
- update_irq(s);
126
prot &= prot2;
84
+ sifive_uart_update_irq(s);
127
85
return;
128
- if (riscv_feature(env, RISCV_FEATURE_PMP) &&
86
case SIFIVE_UART_TXCTRL:
129
- (ret == TRANSLATE_SUCCESS) &&
87
s->txctrl = val64;
130
- !pmp_hart_has_privs(env, pa, size, 1 << access_type, mode)) {
88
@@ -XXX,XX +XXX,XX @@ uart_write(void *opaque, hwaddr addr,
131
- ret = TRANSLATE_PMP_FAIL;
89
__func__, (int)addr, (int)value);
132
+ if (ret == TRANSLATE_SUCCESS) {
90
}
133
+ ret = get_physical_address_pmp(env, &prot_pmp, &tlb_size, pa,
91
134
+ size, access_type, mode);
92
-static const MemoryRegionOps uart_ops = {
135
+ prot &= prot_pmp;
93
- .read = uart_read,
136
}
94
- .write = uart_write,
137
95
+static const MemoryRegionOps sifive_uart_ops = {
138
if (ret != TRANSLATE_SUCCESS) {
96
+ .read = sifive_uart_read,
139
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
97
+ .write = sifive_uart_write,
140
"%s address=%" VADDR_PRIx " ret %d physical "
98
.endianness = DEVICE_NATIVE_ENDIAN,
141
TARGET_FMT_plx " prot %d\n",
99
.valid = {
142
__func__, address, ret, pa, prot);
100
.min_access_size = 4,
143
- }
101
@@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps uart_ops = {
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
}
102
}
155
+
103
};
156
if (ret == TRANSLATE_PMP_FAIL) {
104
157
pmp_violation = true;
105
-static void uart_rx(void *opaque, const uint8_t *buf, int size)
106
+static void sifive_uart_rx(void *opaque, const uint8_t *buf, int size)
107
{
108
SiFiveUARTState *s = opaque;
109
110
@@ -XXX,XX +XXX,XX @@ static void uart_rx(void *opaque, const uint8_t *buf, int size)
158
}
111
}
159
112
s->rx_fifo[s->rx_fifo_len++] = *buf;
160
if (ret == TRANSLATE_SUCCESS) {
113
161
- if (pmp_is_range_in_tlb(env, pa & TARGET_PAGE_MASK, &tlb_size)) {
114
- update_irq(s);
162
- tlb_set_page(cs, address & ~(tlb_size - 1), pa & ~(tlb_size - 1),
115
+ sifive_uart_update_irq(s);
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
}
116
}
180
117
181
+/*
118
-static int uart_can_rx(void *opaque)
182
+ * Check if the address has required RWX privs when no PMP entry is matched.
119
+static int sifive_uart_can_rx(void *opaque)
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
{
120
{
221
int i = 0;
121
SiFiveUARTState *s = opaque;
222
int ret = -1;
122
223
int pmp_size = 0;
123
return s->rx_fifo_len < sizeof(s->rx_fifo);
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
}
124
}
275
125
276
-
126
-static void uart_event(void *opaque, QEMUChrEvent event)
277
/*
127
+static void sifive_uart_event(void *opaque, QEMUChrEvent event)
278
* Handle a write to a pmpcfg CSP
128
{
279
*/
280
@@ -XXX,XX +XXX,XX @@ bool pmp_is_range_in_tlb(CPURISCVState *env, hwaddr tlb_sa,
281
282
return false;
283
}
129
}
284
+
130
285
+/*
131
-static int uart_be_change(void *opaque)
286
+ * Convert PMP privilege to TLB page privilege.
132
+static int sifive_uart_be_change(void *opaque)
287
+ */
133
{
288
+int pmp_priv_to_page_prot(pmp_priv_t pmp_priv)
134
SiFiveUARTState *s = opaque;
289
+{
135
290
+ int prot = 0;
136
- qemu_chr_fe_set_handlers(&s->chr, uart_can_rx, uart_rx, uart_event,
291
+
137
- uart_be_change, s, NULL, true);
292
+ if (pmp_priv & PMP_READ) {
138
+ qemu_chr_fe_set_handlers(&s->chr, sifive_uart_can_rx, sifive_uart_rx,
293
+ prot |= PAGE_READ;
139
+ sifive_uart_event, sifive_uart_be_change, s,
294
+ }
140
+ NULL, true);
295
+ if (pmp_priv & PMP_WRITE) {
141
296
+ prot |= PAGE_WRITE;
142
return 0;
297
+ }
143
}
298
+ if (pmp_priv & PMP_EXEC) {
144
@@ -XXX,XX +XXX,XX @@ SiFiveUARTState *sifive_uart_create(MemoryRegion *address_space, hwaddr base,
299
+ prot |= PAGE_EXEC;
145
SiFiveUARTState *s = g_malloc0(sizeof(SiFiveUARTState));
300
+ }
146
s->irq = irq;
301
+
147
qemu_chr_fe_init(&s->chr, chr, &error_abort);
302
+ return prot;
148
- qemu_chr_fe_set_handlers(&s->chr, uart_can_rx, uart_rx, uart_event,
303
+}
149
- uart_be_change, s, NULL, true);
150
- memory_region_init_io(&s->mmio, NULL, &uart_ops, s,
151
+ qemu_chr_fe_set_handlers(&s->chr, sifive_uart_can_rx, sifive_uart_rx,
152
+ sifive_uart_event, sifive_uart_be_change, s,
153
+ NULL, true);
154
+ memory_region_init_io(&s->mmio, NULL, &sifive_uart_ops, s,
155
TYPE_SIFIVE_UART, SIFIVE_UART_MAX);
156
memory_region_add_subregion(address_space, base, &s->mmio);
157
return s;
304
--
158
--
305
2.30.1
159
2.31.1
306
160
307
161
diff view generated by jsdifflib
1
From: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
1
From: Lukas Jünger <lukas.juenger@greensocs.com>
2
2
3
The previous implementation was broken in many ways:
3
This QOMifies the SiFive UART model. Migration and reset have been
4
- Used mideleg instead of hideleg to mask accesses
4
implemented.
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: Lukas Jünger <lukas.juenger@greensocs.com>
7
Reviewed-by: Bin Meng <bmeng.cn@gmail.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: 20210616092326.59639-3-lukas.juenger@greensocs.com
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
11
---
13
target/riscv/csr.c | 68 +++++++++++++++++++++++-----------------------
12
include/hw/char/sifive_uart.h | 11 ++--
14
1 file changed, 34 insertions(+), 34 deletions(-)
13
hw/char/sifive_uart.c | 114 +++++++++++++++++++++++++++++++---
14
2 files changed, 109 insertions(+), 16 deletions(-)
15
15
16
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
16
diff --git a/include/hw/char/sifive_uart.h b/include/hw/char/sifive_uart.h
17
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
18
--- a/target/riscv/csr.c
18
--- a/include/hw/char/sifive_uart.h
19
+++ b/target/riscv/csr.c
19
+++ b/include/hw/char/sifive_uart.h
20
@@ -XXX,XX +XXX,XX @@ static int write_sstatus(CPURISCVState *env, int csrno, target_ulong val)
20
@@ -XXX,XX +XXX,XX @@
21
return write_mstatus(env, CSR_MSTATUS, newval);
21
#define HW_SIFIVE_UART_H
22
23
#include "chardev/char-fe.h"
24
+#include "hw/qdev-properties.h"
25
#include "hw/sysbus.h"
26
#include "qom/object.h"
27
28
@@ -XXX,XX +XXX,XX @@ enum {
29
30
#define SIFIVE_UART_GET_TXCNT(txctrl) ((txctrl >> 16) & 0x7)
31
#define SIFIVE_UART_GET_RXCNT(rxctrl) ((rxctrl >> 16) & 0x7)
32
+#define SIFIVE_UART_RX_FIFO_SIZE 8
33
34
#define TYPE_SIFIVE_UART "riscv.sifive.uart"
35
-
36
-typedef struct SiFiveUARTState SiFiveUARTState;
37
-DECLARE_INSTANCE_CHECKER(SiFiveUARTState, SIFIVE_UART,
38
- TYPE_SIFIVE_UART)
39
+OBJECT_DECLARE_SIMPLE_TYPE(SiFiveUARTState, SIFIVE_UART)
40
41
struct SiFiveUARTState {
42
/*< private >*/
43
@@ -XXX,XX +XXX,XX @@ struct SiFiveUARTState {
44
qemu_irq irq;
45
MemoryRegion mmio;
46
CharBackend chr;
47
- uint8_t rx_fifo[8];
48
- unsigned int rx_fifo_len;
49
+ uint8_t rx_fifo[SIFIVE_UART_RX_FIFO_SIZE];
50
+ uint8_t rx_fifo_len;
51
uint32_t ie;
52
uint32_t ip;
53
uint32_t txctrl;
54
diff --git a/hw/char/sifive_uart.c b/hw/char/sifive_uart.c
55
index XXXXXXX..XXXXXXX 100644
56
--- a/hw/char/sifive_uart.c
57
+++ b/hw/char/sifive_uart.c
58
@@ -XXX,XX +XXX,XX @@
59
#include "qemu/osdep.h"
60
#include "qapi/error.h"
61
#include "qemu/log.h"
62
+#include "migration/vmstate.h"
63
#include "chardev/char.h"
64
#include "chardev/char-fe.h"
65
#include "hw/irq.h"
66
#include "hw/char/sifive_uart.h"
67
+#include "hw/qdev-properties-system.h"
68
69
/*
70
* Not yet implemented:
71
@@ -XXX,XX +XXX,XX @@ static int sifive_uart_be_change(void *opaque)
72
return 0;
22
}
73
}
23
74
24
+static int read_vsie(CPURISCVState *env, int csrno, target_ulong *val)
75
+static Property sifive_uart_properties[] = {
76
+ DEFINE_PROP_CHR("chardev", SiFiveUARTState, chr),
77
+ DEFINE_PROP_END_OF_LIST(),
78
+};
79
+
80
+static void sifive_uart_init(Object *obj)
25
+{
81
+{
26
+ /* Shift the VS bits to their S bit location in vsie */
82
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
27
+ *val = (env->mie & env->hideleg & VS_MODE_INTERRUPTS) >> 1;
83
+ SiFiveUARTState *s = SIFIVE_UART(obj);
28
+ return 0;
84
+
85
+ memory_region_init_io(&s->mmio, OBJECT(s), &sifive_uart_ops, s,
86
+ TYPE_SIFIVE_UART, SIFIVE_UART_MAX);
87
+ sysbus_init_mmio(sbd, &s->mmio);
88
+ sysbus_init_irq(sbd, &s->irq);
29
+}
89
+}
30
+
90
+
31
static int read_sie(CPURISCVState *env, int csrno, target_ulong *val)
91
+static void sifive_uart_realize(DeviceState *dev, Error **errp)
32
{
33
if (riscv_cpu_virt_enabled(env)) {
34
- /* Tell the guest the VS bits, shifted to the S bit locations */
35
- *val = (env->mie & env->mideleg & VS_MODE_INTERRUPTS) >> 1;
36
+ read_vsie(env, CSR_VSIE, val);
37
} else {
38
*val = env->mie & env->mideleg;
39
}
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
+{
92
+{
55
if (riscv_cpu_virt_enabled(env)) {
93
+ SiFiveUARTState *s = SIFIVE_UART(dev);
56
- /* Shift the guests S bits to VS */
94
+
57
- newval = (env->mie & ~VS_MODE_INTERRUPTS) |
95
+ qemu_chr_fe_set_handlers(&s->chr, sifive_uart_can_rx, sifive_uart_rx,
58
- ((val << 1) & VS_MODE_INTERRUPTS);
96
+ sifive_uart_event, sifive_uart_be_change, s,
59
+ write_vsie(env, CSR_VSIE, val);
97
+ NULL, true);
60
} else {
98
+
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
+}
99
+}
87
+
100
+
88
static int rmw_sip(CPURISCVState *env, int csrno, target_ulong *ret_value,
101
+static void sifive_uart_reset_enter(Object *obj, ResetType type)
89
target_ulong new_value, target_ulong write_mask)
102
+{
103
+ SiFiveUARTState *s = SIFIVE_UART(obj);
104
+ s->ie = 0;
105
+ s->ip = 0;
106
+ s->txctrl = 0;
107
+ s->rxctrl = 0;
108
+ s->div = 0;
109
+ s->rx_fifo_len = 0;
110
+}
111
+
112
+static void sifive_uart_reset_hold(Object *obj)
113
+{
114
+ SiFiveUARTState *s = SIFIVE_UART(obj);
115
+ qemu_irq_lower(s->irq);
116
+}
117
+
118
+static const VMStateDescription vmstate_sifive_uart = {
119
+ .name = TYPE_SIFIVE_UART,
120
+ .version_id = 1,
121
+ .minimum_version_id = 1,
122
+ .fields = (VMStateField[]) {
123
+ VMSTATE_UINT8_ARRAY(rx_fifo, SiFiveUARTState,
124
+ SIFIVE_UART_RX_FIFO_SIZE),
125
+ VMSTATE_UINT8(rx_fifo_len, SiFiveUARTState),
126
+ VMSTATE_UINT32(ie, SiFiveUARTState),
127
+ VMSTATE_UINT32(ip, SiFiveUARTState),
128
+ VMSTATE_UINT32(txctrl, SiFiveUARTState),
129
+ VMSTATE_UINT32(rxctrl, SiFiveUARTState),
130
+ VMSTATE_UINT32(div, SiFiveUARTState),
131
+ VMSTATE_END_OF_LIST()
132
+ },
133
+};
134
+
135
+
136
+static void sifive_uart_class_init(ObjectClass *oc, void *data)
137
+{
138
+ DeviceClass *dc = DEVICE_CLASS(oc);
139
+ ResettableClass *rc = RESETTABLE_CLASS(oc);
140
+
141
+ dc->realize = sifive_uart_realize;
142
+ dc->vmsd = &vmstate_sifive_uart;
143
+ rc->phases.enter = sifive_uart_reset_enter;
144
+ rc->phases.hold = sifive_uart_reset_hold;
145
+ device_class_set_props(dc, sifive_uart_properties);
146
+}
147
+
148
+static const TypeInfo sifive_uart_info = {
149
+ .name = TYPE_SIFIVE_UART,
150
+ .parent = TYPE_SYS_BUS_DEVICE,
151
+ .instance_size = sizeof(SiFiveUARTState),
152
+ .instance_init = sifive_uart_init,
153
+ .class_init = sifive_uart_class_init,
154
+};
155
+
156
+static void sifive_uart_register_types(void)
157
+{
158
+ type_register_static(&sifive_uart_info);
159
+}
160
+
161
+type_init(sifive_uart_register_types)
162
+
163
/*
164
* Create UART device.
165
*/
166
SiFiveUARTState *sifive_uart_create(MemoryRegion *address_space, hwaddr base,
167
Chardev *chr, qemu_irq irq)
90
{
168
{
91
int ret;
169
- SiFiveUARTState *s = g_malloc0(sizeof(SiFiveUARTState));
92
170
- s->irq = irq;
93
if (riscv_cpu_virt_enabled(env)) {
171
- qemu_chr_fe_init(&s->chr, chr, &error_abort);
94
- /* Shift the new values to line up with the VS bits */
172
- qemu_chr_fe_set_handlers(&s->chr, sifive_uart_can_rx, sifive_uart_rx,
95
- ret = rmw_mip(env, CSR_MSTATUS, ret_value, new_value << 1,
173
- sifive_uart_event, sifive_uart_be_change, s,
96
- (write_mask & sip_writable_mask) << 1 & env->mideleg);
174
- NULL, true);
97
- ret &= vsip_writable_mask;
175
- memory_region_init_io(&s->mmio, NULL, &sifive_uart_ops, s,
98
- ret >>= 1;
176
- TYPE_SIFIVE_UART, SIFIVE_UART_MAX);
99
+ ret = rmw_vsip(env, CSR_VSIP, ret_value, new_value, write_mask);
177
- memory_region_add_subregion(address_space, base, &s->mmio);
100
} else {
178
- return s;
101
ret = rmw_mip(env, CSR_MSTATUS, ret_value, new_value,
179
+ DeviceState *dev;
102
write_mask & env->mideleg & sip_writable_mask);
180
+ SysBusDevice *s;
103
@@ -XXX,XX +XXX,XX @@ static int write_vsstatus(CPURISCVState *env, int csrno, target_ulong val)
181
+ SiFiveUARTState *r;
104
return 0;
182
+
183
+ dev = qdev_new("riscv.sifive.uart");
184
+ s = SYS_BUS_DEVICE(dev);
185
+ qdev_prop_set_chr(dev, "chardev", chr);
186
+ sysbus_realize_and_unref(s, &error_fatal);
187
+ memory_region_add_subregion(address_space, base,
188
+ sysbus_mmio_get_region(s, 0));
189
+ sysbus_connect_irq(s, 0, irq);
190
+
191
+ r = SIFIVE_UART(dev);
192
+ return r;
105
}
193
}
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
--
194
--
131
2.30.1
195
2.31.1
132
196
133
197
diff view generated by jsdifflib
1
From: Alexander Wagner <alexander.wagner@ulal.de>
1
We don't need to expose the register layout in the public header, so
2
don't.
2
3
3
Not disabling the UART leads to QEMU overwriting the UART receive buffer with
4
the newest received byte. The rx_level variable is added to allow the use of
5
the existing OpenTitan driver libraries.
6
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>
4
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
5
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
6
Message-id: c437f570b2b30ab4170387a3ba2fad7d116a4986.1624001156.git.alistair.francis@wdc.com
11
---
7
---
12
include/hw/char/ibex_uart.h | 4 ++++
8
include/hw/char/ibex_uart.h | 37 -------------------------------------
13
hw/char/ibex_uart.c | 23 ++++++++++++++++++-----
9
hw/char/ibex_uart.c | 37 +++++++++++++++++++++++++++++++++++++
14
2 files changed, 22 insertions(+), 5 deletions(-)
10
2 files changed, 37 insertions(+), 37 deletions(-)
15
11
16
diff --git a/include/hw/char/ibex_uart.h b/include/hw/char/ibex_uart.h
12
diff --git a/include/hw/char/ibex_uart.h b/include/hw/char/ibex_uart.h
17
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
18
--- a/include/hw/char/ibex_uart.h
14
--- a/include/hw/char/ibex_uart.h
19
+++ b/include/hw/char/ibex_uart.h
15
+++ b/include/hw/char/ibex_uart.h
20
@@ -XXX,XX +XXX,XX @@ REG32(FIFO_CTRL, 0x1c)
16
@@ -XXX,XX +XXX,XX @@
21
FIELD(FIFO_CTRL, RXILVL, 2, 3)
17
#include "qemu/timer.h"
22
FIELD(FIFO_CTRL, TXILVL, 5, 2)
18
#include "qom/object.h"
23
REG32(FIFO_STATUS, 0x20)
19
24
+ FIELD(FIFO_STATUS, TXLVL, 0, 5)
20
-REG32(INTR_STATE, 0x00)
25
+ FIELD(FIFO_STATUS, RXLVL, 16, 5)
21
- FIELD(INTR_STATE, TX_WATERMARK, 0, 1)
26
REG32(OVRD, 0x24)
22
- FIELD(INTR_STATE, RX_WATERMARK, 1, 1)
27
REG32(VAL, 0x28)
23
- FIELD(INTR_STATE, TX_EMPTY, 2, 1)
28
REG32(TIMEOUT_CTRL, 0x2c)
24
- FIELD(INTR_STATE, RX_OVERFLOW, 3, 1)
29
@@ -XXX,XX +XXX,XX @@ struct IbexUartState {
25
-REG32(INTR_ENABLE, 0x04)
30
uint8_t tx_fifo[IBEX_UART_TX_FIFO_SIZE];
26
-REG32(INTR_TEST, 0x08)
31
uint32_t tx_level;
27
-REG32(CTRL, 0x0C)
32
28
- FIELD(CTRL, TX_ENABLE, 0, 1)
33
+ uint32_t rx_level;
29
- FIELD(CTRL, RX_ENABLE, 1, 1)
34
+
30
- FIELD(CTRL, NF, 2, 1)
35
QEMUTimer *fifo_trigger_handle;
31
- FIELD(CTRL, SLPBK, 4, 1)
36
uint64_t char_tx_time;
32
- FIELD(CTRL, LLPBK, 5, 1)
33
- FIELD(CTRL, PARITY_EN, 6, 1)
34
- FIELD(CTRL, PARITY_ODD, 7, 1)
35
- FIELD(CTRL, RXBLVL, 8, 2)
36
- FIELD(CTRL, NCO, 16, 16)
37
-REG32(STATUS, 0x10)
38
- FIELD(STATUS, TXFULL, 0, 1)
39
- FIELD(STATUS, RXFULL, 1, 1)
40
- FIELD(STATUS, TXEMPTY, 2, 1)
41
- FIELD(STATUS, RXIDLE, 4, 1)
42
- FIELD(STATUS, RXEMPTY, 5, 1)
43
-REG32(RDATA, 0x14)
44
-REG32(WDATA, 0x18)
45
-REG32(FIFO_CTRL, 0x1c)
46
- FIELD(FIFO_CTRL, RXRST, 0, 1)
47
- FIELD(FIFO_CTRL, TXRST, 1, 1)
48
- FIELD(FIFO_CTRL, RXILVL, 2, 3)
49
- FIELD(FIFO_CTRL, TXILVL, 5, 2)
50
-REG32(FIFO_STATUS, 0x20)
51
- FIELD(FIFO_STATUS, TXLVL, 0, 5)
52
- FIELD(FIFO_STATUS, RXLVL, 16, 5)
53
-REG32(OVRD, 0x24)
54
-REG32(VAL, 0x28)
55
-REG32(TIMEOUT_CTRL, 0x2c)
56
-
57
#define IBEX_UART_TX_FIFO_SIZE 16
58
#define IBEX_UART_CLOCK 50000000 /* 50MHz clock */
37
59
38
diff --git a/hw/char/ibex_uart.c b/hw/char/ibex_uart.c
60
diff --git a/hw/char/ibex_uart.c b/hw/char/ibex_uart.c
39
index XXXXXXX..XXXXXXX 100644
61
index XXXXXXX..XXXXXXX 100644
40
--- a/hw/char/ibex_uart.c
62
--- a/hw/char/ibex_uart.c
41
+++ b/hw/char/ibex_uart.c
63
+++ b/hw/char/ibex_uart.c
42
@@ -XXX,XX +XXX,XX @@ static int ibex_uart_can_receive(void *opaque)
64
@@ -XXX,XX +XXX,XX @@
65
#include "qemu/log.h"
66
#include "qemu/module.h"
67
68
+REG32(INTR_STATE, 0x00)
69
+ FIELD(INTR_STATE, TX_WATERMARK, 0, 1)
70
+ FIELD(INTR_STATE, RX_WATERMARK, 1, 1)
71
+ FIELD(INTR_STATE, TX_EMPTY, 2, 1)
72
+ FIELD(INTR_STATE, RX_OVERFLOW, 3, 1)
73
+REG32(INTR_ENABLE, 0x04)
74
+REG32(INTR_TEST, 0x08)
75
+REG32(CTRL, 0x0C)
76
+ FIELD(CTRL, TX_ENABLE, 0, 1)
77
+ FIELD(CTRL, RX_ENABLE, 1, 1)
78
+ FIELD(CTRL, NF, 2, 1)
79
+ FIELD(CTRL, SLPBK, 4, 1)
80
+ FIELD(CTRL, LLPBK, 5, 1)
81
+ FIELD(CTRL, PARITY_EN, 6, 1)
82
+ FIELD(CTRL, PARITY_ODD, 7, 1)
83
+ FIELD(CTRL, RXBLVL, 8, 2)
84
+ FIELD(CTRL, NCO, 16, 16)
85
+REG32(STATUS, 0x10)
86
+ FIELD(STATUS, TXFULL, 0, 1)
87
+ FIELD(STATUS, RXFULL, 1, 1)
88
+ FIELD(STATUS, TXEMPTY, 2, 1)
89
+ FIELD(STATUS, RXIDLE, 4, 1)
90
+ FIELD(STATUS, RXEMPTY, 5, 1)
91
+REG32(RDATA, 0x14)
92
+REG32(WDATA, 0x18)
93
+REG32(FIFO_CTRL, 0x1c)
94
+ FIELD(FIFO_CTRL, RXRST, 0, 1)
95
+ FIELD(FIFO_CTRL, TXRST, 1, 1)
96
+ FIELD(FIFO_CTRL, RXILVL, 2, 3)
97
+ FIELD(FIFO_CTRL, TXILVL, 5, 2)
98
+REG32(FIFO_STATUS, 0x20)
99
+ FIELD(FIFO_STATUS, TXLVL, 0, 5)
100
+ FIELD(FIFO_STATUS, RXLVL, 16, 5)
101
+REG32(OVRD, 0x24)
102
+REG32(VAL, 0x28)
103
+REG32(TIMEOUT_CTRL, 0x2c)
104
+
105
static void ibex_uart_update_irqs(IbexUartState *s)
43
{
106
{
44
IbexUartState *s = opaque;
107
if (s->uart_intr_state & s->uart_intr_enable & R_INTR_STATE_TX_WATERMARK_MASK) {
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
--
108
--
110
2.30.1
109
2.31.1
111
110
112
111
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: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
2
1
3
Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
4
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
5
Message-id: 20210311094902.1377593-1-georg.kotheimer@kernkonzept.com
6
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
7
---
8
target/riscv/csr.c | 7 ++++---
9
1 file changed, 4 insertions(+), 3 deletions(-)
10
11
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
12
index XXXXXXX..XXXXXXX 100644
13
--- a/target/riscv/csr.c
14
+++ b/target/riscv/csr.c
15
@@ -XXX,XX +XXX,XX @@ static const target_ulong sstatus_v1_10_mask = SSTATUS_SIE | SSTATUS_SPIE |
16
SSTATUS_UIE | SSTATUS_UPIE | SSTATUS_SPP | SSTATUS_FS | SSTATUS_XS |
17
SSTATUS_SUM | SSTATUS_MXR | SSTATUS_SD;
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
{
28
int ret = rmw_mip(env, 0, ret_value, new_value,
29
- write_mask & hip_writable_mask);
30
+ write_mask & hvip_writable_mask);
31
32
- *ret_value &= hip_writable_mask;
33
+ *ret_value &= hvip_writable_mask;
34
35
return ret;
36
}
37
--
38
2.30.1
39
40
diff view generated by jsdifflib
Deleted patch
1
From: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
2
1
3
The current condition for the use of background registers only
4
considers the hypervisor load and store instructions,
5
but not accesses from M mode via MSTATUS_MPRV+MPV.
6
7
Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Message-id: 20210311103036.1401073-1-georg.kotheimer@kernkonzept.com
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
12
target/riscv/cpu_helper.c | 2 +-
13
1 file changed, 1 insertion(+), 1 deletion(-)
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
* was called. Background registers will be used if the guest has
21
* forced a two stage translation to be on (in HS or M mode).
22
*/
23
- if (!riscv_cpu_virt_enabled(env) && riscv_cpu_two_stage_lookup(mmu_idx)) {
24
+ if (!riscv_cpu_virt_enabled(env) && two_stage) {
25
use_background = true;
26
}
27
28
--
29
2.30.1
30
31
diff view generated by jsdifflib
Deleted patch
1
From: Asherah Connor <ashe@kivikakk.ee>
2
1
3
Provides fw_cfg for the virt machine on riscv. This enables
4
using e.g. ramfb later.
5
6
Signed-off-by: Asherah Connor <ashe@kivikakk.ee>
7
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Message-id: 20210318235041.17175-2-ashe@kivikakk.ee
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
12
include/hw/riscv/virt.h | 2 ++
13
hw/riscv/virt.c | 30 ++++++++++++++++++++++++++++++
14
hw/riscv/Kconfig | 1 +
15
3 files changed, 33 insertions(+)
16
17
diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h
18
index XXXXXXX..XXXXXXX 100644
19
--- a/include/hw/riscv/virt.h
20
+++ b/include/hw/riscv/virt.h
21
@@ -XXX,XX +XXX,XX @@ struct RISCVVirtState {
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
}
81
82
+ /*
83
+ * Init fw_cfg. Must be done before riscv_load_fdt, otherwise the device
84
+ * tree cannot be altered and we get FDT_ERR_NOSPACE.
85
+ */
86
+ s->fw_cfg = create_fw_cfg(machine);
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
--
105
2.30.1
106
107
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: Bin Meng <bin.meng@windriver.com>
1
Add support for the Ibex timer. This is used with the RISC-V
2
mtime/mtimecmp similar to the SiFive CLINT.
2
3
3
This adds the documentation to describe what is supported for the
4
We currently don't support changing the prescale or the timervalue.
4
'microchip-icicle-kit' machine, and how to boot the machine in QEMU.
5
5
6
Signed-off-by: Bin Meng <bin.meng@windriver.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Message-id: 20210322075248.136255-2-bmeng.cn@gmail.com
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
6
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
7
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
8
Message-id: 716fdea2244515ce86a2c46fe69467d013c03147.1624001156.git.alistair.francis@wdc.com
10
---
9
---
11
docs/system/riscv/microchip-icicle-kit.rst | 89 ++++++++++++++++++++++
10
include/hw/timer/ibex_timer.h | 52 ++++++
12
docs/system/target-riscv.rst | 1 +
11
hw/timer/ibex_timer.c | 305 ++++++++++++++++++++++++++++++++++
13
2 files changed, 90 insertions(+)
12
MAINTAINERS | 6 +-
14
create mode 100644 docs/system/riscv/microchip-icicle-kit.rst
13
hw/timer/meson.build | 1 +
14
4 files changed, 360 insertions(+), 4 deletions(-)
15
create mode 100644 include/hw/timer/ibex_timer.h
16
create mode 100644 hw/timer/ibex_timer.c
15
17
16
diff --git a/docs/system/riscv/microchip-icicle-kit.rst b/docs/system/riscv/microchip-icicle-kit.rst
18
diff --git a/include/hw/timer/ibex_timer.h b/include/hw/timer/ibex_timer.h
17
new file mode 100644
19
new file mode 100644
18
index XXXXXXX..XXXXXXX
20
index XXXXXXX..XXXXXXX
19
--- /dev/null
21
--- /dev/null
20
+++ b/docs/system/riscv/microchip-icicle-kit.rst
22
+++ b/include/hw/timer/ibex_timer.h
21
@@ -XXX,XX +XXX,XX @@
23
@@ -XXX,XX +XXX,XX @@
22
+Microchip PolarFire SoC Icicle Kit (``microchip-icicle-kit``)
24
+/*
23
+=============================================================
25
+ * QEMU lowRISC Ibex Timer device
24
+
26
+ *
25
+Microchip PolarFire SoC Icicle Kit integrates a PolarFire SoC, with one
27
+ * Copyright (c) 2021 Western Digital
26
+SiFive's E51 plus four U54 cores and many on-chip peripherals and an FPGA.
28
+ *
27
+
29
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
28
+For more details about Microchip PolarFire SoC, please see:
30
+ * of this software and associated documentation files (the "Software"), to deal
29
+https://www.microsemi.com/product-directory/soc-fpgas/5498-polarfire-soc-fpga
31
+ * in the Software without restriction, including without limitation the rights
30
+
32
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
31
+The Icicle Kit board information can be found here:
33
+ * copies of the Software, and to permit persons to whom the Software is
32
+https://www.microsemi.com/existing-parts/parts/152514
34
+ * furnished to do so, subject to the following conditions:
33
+
35
+ *
34
+Supported devices
36
+ * The above copyright notice and this permission notice shall be included in
35
+-----------------
37
+ * all copies or substantial portions of the Software.
36
+
38
+ *
37
+The ``microchip-icicle-kit`` machine supports the following devices:
39
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38
+
40
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39
+ * 1 E51 core
41
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
40
+ * 4 U54 cores
42
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41
+ * Core Level Interruptor (CLINT)
43
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
42
+ * Platform-Level Interrupt Controller (PLIC)
44
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
43
+ * L2 Loosely Integrated Memory (L2-LIM)
45
+ * THE SOFTWARE.
44
+ * DDR memory controller
46
+ */
45
+ * 5 MMUARTs
47
+
46
+ * 1 DMA controller
48
+#ifndef HW_IBEX_TIMER_H
47
+ * 2 GEM Ethernet controllers
49
+#define HW_IBEX_TIMER_H
48
+ * 1 SDHC storage controller
50
+
49
+
51
+#include "hw/sysbus.h"
50
+Boot options
52
+
51
+------------
53
+#define TYPE_IBEX_TIMER "ibex-timer"
52
+
54
+OBJECT_DECLARE_SIMPLE_TYPE(IbexTimerState, IBEX_TIMER)
53
+The ``microchip-icicle-kit`` machine can start using the standard -bios
55
+
54
+functionality for loading its BIOS image, aka Hart Software Services (HSS_).
56
+struct IbexTimerState {
55
+HSS loads the second stage bootloader U-Boot from an SD card. It does not
57
+ /* <private> */
56
+support direct kernel loading via the -kernel option. One has to load kernel
58
+ SysBusDevice parent_obj;
57
+from U-Boot.
59
+
58
+
60
+ /* <public> */
59
+The memory is set to 1537 MiB by default which is the minimum required high
61
+ MemoryRegion mmio;
60
+memory size by HSS. A sanity check on ram size is performed in the machine
62
+
61
+init routine to prompt user to increase the RAM size to > 1537 MiB when less
63
+ uint32_t timer_ctrl;
62
+than 1537 MiB ram is detected.
64
+ uint32_t timer_cfg0;
63
+
65
+ uint32_t timer_compare_lower0;
64
+Boot the machine
66
+ uint32_t timer_compare_upper0;
65
+----------------
67
+ uint32_t timer_intr_enable;
66
+
68
+ uint32_t timer_intr_state;
67
+HSS 2020.12 release is tested at the time of writing. To build an HSS image
69
+ uint32_t timer_intr_test;
68
+that can be booted by the ``microchip-icicle-kit`` machine, type the following
70
+
69
+in the HSS source tree:
71
+ uint32_t timebase_freq;
70
+
72
+
71
+.. code-block:: bash
73
+ qemu_irq irq;
72
+
74
+};
73
+ $ export CROSS_COMPILE=riscv64-linux-
75
+#endif /* HW_IBEX_TIMER_H */
74
+ $ cp boards/mpfs-icicle-kit-es/def_config .config
76
diff --git a/hw/timer/ibex_timer.c b/hw/timer/ibex_timer.c
75
+ $ make BOARD=mpfs-icicle-kit-es
77
new file mode 100644
76
+
78
index XXXXXXX..XXXXXXX
77
+Download the official SD card image released by Microchip and prepare it for
79
--- /dev/null
78
+QEMU usage:
80
+++ b/hw/timer/ibex_timer.c
79
+
81
@@ -XXX,XX +XXX,XX @@
80
+.. code-block:: bash
82
+/*
81
+
83
+ * QEMU lowRISC Ibex Timer device
82
+ $ wget ftp://ftpsoc.microsemi.com/outgoing/core-image-minimal-dev-icicle-kit-es-sd-20201009141623.rootfs.wic.gz
84
+ *
83
+ $ gunzip core-image-minimal-dev-icicle-kit-es-sd-20201009141623.rootfs.wic.gz
85
+ * Copyright (c) 2021 Western Digital
84
+ $ qemu-img resize core-image-minimal-dev-icicle-kit-es-sd-20201009141623.rootfs.wic 4G
86
+ *
85
+
87
+ * For details check the documentation here:
86
+Then we can boot the machine by:
88
+ * https://docs.opentitan.org/hw/ip/rv_timer/doc/
87
+
89
+ *
88
+.. code-block:: bash
90
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
89
+
91
+ * of this software and associated documentation files (the "Software"), to deal
90
+ $ qemu-system-riscv64 -M microchip-icicle-kit -smp 5 \
92
+ * in the Software without restriction, including without limitation the rights
91
+ -bios path/to/hss.bin -sd path/to/sdcard.img \
93
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
92
+ -nic user,model=cadence_gem \
94
+ * copies of the Software, and to permit persons to whom the Software is
93
+ -nic tap,ifname=tap,model=cadence_gem,script=no \
95
+ * furnished to do so, subject to the following conditions:
94
+ -display none -serial stdio \
96
+ *
95
+ -chardev socket,id=serial1,path=serial1.sock,server=on,wait=on \
97
+ * The above copyright notice and this permission notice shall be included in
96
+ -serial chardev:serial1
98
+ * all copies or substantial portions of the Software.
97
+
99
+ *
98
+With above command line, current terminal session will be used for the first
100
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
99
+serial port. Open another terminal window, and use `minicom` to connect the
101
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
100
+second serial port.
102
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
101
+
103
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
102
+.. code-block:: bash
104
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
103
+
105
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
104
+ $ minicom -D unix\#serial1.sock
106
+ * THE SOFTWARE.
105
+
107
+ */
106
+HSS output is on the first serial port (stdio) and U-Boot outputs on the
108
+
107
+second serial port. U-Boot will automatically load the Linux kernel from
109
+#include "qemu/osdep.h"
108
+the SD card image.
110
+#include "qemu/log.h"
109
+
111
+#include "qemu/timer.h"
110
+.. _HSS: https://github.com/polarfire-soc/hart-software-services
112
+#include "hw/timer/ibex_timer.h"
111
diff --git a/docs/system/target-riscv.rst b/docs/system/target-riscv.rst
113
+#include "hw/irq.h"
114
+#include "hw/qdev-properties.h"
115
+#include "target/riscv/cpu.h"
116
+#include "migration/vmstate.h"
117
+
118
+REG32(CTRL, 0x00)
119
+ FIELD(CTRL, ACTIVE, 0, 1)
120
+REG32(CFG0, 0x100)
121
+ FIELD(CFG0, PRESCALE, 0, 12)
122
+ FIELD(CFG0, STEP, 16, 8)
123
+REG32(LOWER0, 0x104)
124
+REG32(UPPER0, 0x108)
125
+REG32(COMPARE_LOWER0, 0x10C)
126
+REG32(COMPARE_UPPER0, 0x110)
127
+REG32(INTR_ENABLE, 0x114)
128
+ FIELD(INTR_ENABLE, IE_0, 0, 1)
129
+REG32(INTR_STATE, 0x118)
130
+ FIELD(INTR_STATE, IS_0, 0, 1)
131
+REG32(INTR_TEST, 0x11C)
132
+ FIELD(INTR_TEST, T_0, 0, 1)
133
+
134
+static uint64_t cpu_riscv_read_rtc(uint32_t timebase_freq)
135
+{
136
+ return muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
137
+ timebase_freq, NANOSECONDS_PER_SECOND);
138
+}
139
+
140
+static void ibex_timer_update_irqs(IbexTimerState *s)
141
+{
142
+ CPUState *cs = qemu_get_cpu(0);
143
+ RISCVCPU *cpu = RISCV_CPU(cs);
144
+ uint64_t value = s->timer_compare_lower0 |
145
+ ((uint64_t)s->timer_compare_upper0 << 32);
146
+ uint64_t next, diff;
147
+ uint64_t now = cpu_riscv_read_rtc(s->timebase_freq);
148
+
149
+ if (!(s->timer_ctrl & R_CTRL_ACTIVE_MASK)) {
150
+ /* Timer isn't active */
151
+ return;
152
+ }
153
+
154
+ /* Update the CPUs mtimecmp */
155
+ cpu->env.timecmp = value;
156
+
157
+ if (cpu->env.timecmp <= now) {
158
+ /*
159
+ * If the mtimecmp was in the past raise the interrupt now.
160
+ */
161
+ riscv_cpu_update_mip(cpu, MIP_MTIP, BOOL_TO_MASK(1));
162
+ if (s->timer_intr_enable & R_INTR_ENABLE_IE_0_MASK) {
163
+ s->timer_intr_state |= R_INTR_STATE_IS_0_MASK;
164
+ qemu_set_irq(s->irq, true);
165
+ }
166
+ return;
167
+ }
168
+
169
+ /* Setup a timer to trigger the interrupt in the future */
170
+ riscv_cpu_update_mip(cpu, MIP_MTIP, BOOL_TO_MASK(0));
171
+ qemu_set_irq(s->irq, false);
172
+
173
+ diff = cpu->env.timecmp - now;
174
+ next = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
175
+ muldiv64(diff,
176
+ NANOSECONDS_PER_SECOND,
177
+ s->timebase_freq);
178
+
179
+ if (next < qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)) {
180
+ /* We overflowed the timer, just set it as large as we can */
181
+ timer_mod(cpu->env.timer, 0x7FFFFFFFFFFFFFFF);
182
+ } else {
183
+ timer_mod(cpu->env.timer, next);
184
+ }
185
+}
186
+
187
+static void ibex_timer_cb(void *opaque)
188
+{
189
+ IbexTimerState *s = opaque;
190
+ CPUState *cs = qemu_get_cpu(0);
191
+ RISCVCPU *cpu = RISCV_CPU(cs);
192
+
193
+ riscv_cpu_update_mip(cpu, MIP_MTIP, BOOL_TO_MASK(1));
194
+ if (s->timer_intr_enable & R_INTR_ENABLE_IE_0_MASK) {
195
+ s->timer_intr_state |= R_INTR_STATE_IS_0_MASK;
196
+ qemu_set_irq(s->irq, true);
197
+ }
198
+}
199
+
200
+static void ibex_timer_reset(DeviceState *dev)
201
+{
202
+ IbexTimerState *s = IBEX_TIMER(dev);
203
+
204
+ CPUState *cpu = qemu_get_cpu(0);
205
+ CPURISCVState *env = cpu->env_ptr;
206
+ env->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
207
+ &ibex_timer_cb, s);
208
+ env->timecmp = 0;
209
+
210
+ s->timer_ctrl = 0x00000000;
211
+ s->timer_cfg0 = 0x00010000;
212
+ s->timer_compare_lower0 = 0xFFFFFFFF;
213
+ s->timer_compare_upper0 = 0xFFFFFFFF;
214
+ s->timer_intr_enable = 0x00000000;
215
+ s->timer_intr_state = 0x00000000;
216
+ s->timer_intr_test = 0x00000000;
217
+
218
+ ibex_timer_update_irqs(s);
219
+}
220
+
221
+static uint64_t ibex_timer_read(void *opaque, hwaddr addr,
222
+ unsigned int size)
223
+{
224
+ IbexTimerState *s = opaque;
225
+ uint64_t now = cpu_riscv_read_rtc(s->timebase_freq);
226
+ uint64_t retvalue = 0;
227
+
228
+ switch (addr >> 2) {
229
+ case R_CTRL:
230
+ retvalue = s->timer_ctrl;
231
+ break;
232
+ case R_CFG0:
233
+ retvalue = s->timer_cfg0;
234
+ break;
235
+ case R_LOWER0:
236
+ retvalue = now;
237
+ break;
238
+ case R_UPPER0:
239
+ retvalue = now >> 32;
240
+ break;
241
+ case R_COMPARE_LOWER0:
242
+ retvalue = s->timer_compare_lower0;
243
+ break;
244
+ case R_COMPARE_UPPER0:
245
+ retvalue = s->timer_compare_upper0;
246
+ break;
247
+ case R_INTR_ENABLE:
248
+ retvalue = s->timer_intr_enable;
249
+ break;
250
+ case R_INTR_STATE:
251
+ retvalue = s->timer_intr_state;
252
+ break;
253
+ case R_INTR_TEST:
254
+ retvalue = s->timer_intr_test;
255
+ break;
256
+ default:
257
+ qemu_log_mask(LOG_GUEST_ERROR,
258
+ "%s: Bad offset 0x%"HWADDR_PRIx"\n", __func__, addr);
259
+ return 0;
260
+ }
261
+
262
+ return retvalue;
263
+}
264
+
265
+static void ibex_timer_write(void *opaque, hwaddr addr,
266
+ uint64_t val64, unsigned int size)
267
+{
268
+ IbexTimerState *s = opaque;
269
+ uint32_t val = val64;
270
+
271
+ switch (addr >> 2) {
272
+ case R_CTRL:
273
+ s->timer_ctrl = val;
274
+ break;
275
+ case R_CFG0:
276
+ qemu_log_mask(LOG_UNIMP, "Changing prescale or step not supported");
277
+ s->timer_cfg0 = val;
278
+ break;
279
+ case R_LOWER0:
280
+ qemu_log_mask(LOG_UNIMP, "Changing timer value is not supported");
281
+ break;
282
+ case R_UPPER0:
283
+ qemu_log_mask(LOG_UNIMP, "Changing timer value is not supported");
284
+ break;
285
+ case R_COMPARE_LOWER0:
286
+ s->timer_compare_lower0 = val;
287
+ ibex_timer_update_irqs(s);
288
+ break;
289
+ case R_COMPARE_UPPER0:
290
+ s->timer_compare_upper0 = val;
291
+ ibex_timer_update_irqs(s);
292
+ break;
293
+ case R_INTR_ENABLE:
294
+ s->timer_intr_enable = val;
295
+ break;
296
+ case R_INTR_STATE:
297
+ /* Write 1 to clear */
298
+ s->timer_intr_state &= ~val;
299
+ break;
300
+ case R_INTR_TEST:
301
+ s->timer_intr_test = val;
302
+ if (s->timer_intr_enable &
303
+ s->timer_intr_test &
304
+ R_INTR_ENABLE_IE_0_MASK) {
305
+ s->timer_intr_state |= R_INTR_STATE_IS_0_MASK;
306
+ qemu_set_irq(s->irq, true);
307
+ }
308
+ break;
309
+ default:
310
+ qemu_log_mask(LOG_GUEST_ERROR,
311
+ "%s: Bad offset 0x%"HWADDR_PRIx"\n", __func__, addr);
312
+ }
313
+}
314
+
315
+static const MemoryRegionOps ibex_timer_ops = {
316
+ .read = ibex_timer_read,
317
+ .write = ibex_timer_write,
318
+ .endianness = DEVICE_NATIVE_ENDIAN,
319
+ .impl.min_access_size = 4,
320
+ .impl.max_access_size = 4,
321
+};
322
+
323
+static int ibex_timer_post_load(void *opaque, int version_id)
324
+{
325
+ IbexTimerState *s = opaque;
326
+
327
+ ibex_timer_update_irqs(s);
328
+ return 0;
329
+}
330
+
331
+static const VMStateDescription vmstate_ibex_timer = {
332
+ .name = TYPE_IBEX_TIMER,
333
+ .version_id = 1,
334
+ .minimum_version_id = 1,
335
+ .post_load = ibex_timer_post_load,
336
+ .fields = (VMStateField[]) {
337
+ VMSTATE_UINT32(timer_ctrl, IbexTimerState),
338
+ VMSTATE_UINT32(timer_cfg0, IbexTimerState),
339
+ VMSTATE_UINT32(timer_compare_lower0, IbexTimerState),
340
+ VMSTATE_UINT32(timer_compare_upper0, IbexTimerState),
341
+ VMSTATE_UINT32(timer_intr_enable, IbexTimerState),
342
+ VMSTATE_UINT32(timer_intr_state, IbexTimerState),
343
+ VMSTATE_UINT32(timer_intr_test, IbexTimerState),
344
+ VMSTATE_END_OF_LIST()
345
+ }
346
+};
347
+
348
+static Property ibex_timer_properties[] = {
349
+ DEFINE_PROP_UINT32("timebase-freq", IbexTimerState, timebase_freq, 10000),
350
+ DEFINE_PROP_END_OF_LIST(),
351
+};
352
+
353
+static void ibex_timer_init(Object *obj)
354
+{
355
+ IbexTimerState *s = IBEX_TIMER(obj);
356
+
357
+ sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->irq);
358
+
359
+ memory_region_init_io(&s->mmio, obj, &ibex_timer_ops, s,
360
+ TYPE_IBEX_TIMER, 0x400);
361
+ sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio);
362
+}
363
+
364
+static void ibex_timer_class_init(ObjectClass *klass, void *data)
365
+{
366
+ DeviceClass *dc = DEVICE_CLASS(klass);
367
+
368
+ dc->reset = ibex_timer_reset;
369
+ dc->vmsd = &vmstate_ibex_timer;
370
+ device_class_set_props(dc, ibex_timer_properties);
371
+}
372
+
373
+static const TypeInfo ibex_timer_info = {
374
+ .name = TYPE_IBEX_TIMER,
375
+ .parent = TYPE_SYS_BUS_DEVICE,
376
+ .instance_size = sizeof(IbexTimerState),
377
+ .instance_init = ibex_timer_init,
378
+ .class_init = ibex_timer_class_init,
379
+};
380
+
381
+static void ibex_timer_register_types(void)
382
+{
383
+ type_register_static(&ibex_timer_info);
384
+}
385
+
386
+type_init(ibex_timer_register_types)
387
diff --git a/MAINTAINERS b/MAINTAINERS
112
index XXXXXXX..XXXXXXX 100644
388
index XXXXXXX..XXXXXXX 100644
113
--- a/docs/system/target-riscv.rst
389
--- a/MAINTAINERS
114
+++ b/docs/system/target-riscv.rst
390
+++ b/MAINTAINERS
115
@@ -XXX,XX +XXX,XX @@ undocumented; you can get a complete list by running
391
@@ -XXX,XX +XXX,XX @@ M: Alistair Francis <Alistair.Francis@wdc.com>
116
.. toctree::
392
L: qemu-riscv@nongnu.org
117
:maxdepth: 1
393
S: Supported
118
394
F: hw/riscv/opentitan.c
119
+ riscv/microchip-icicle-kit
395
-F: hw/char/ibex_uart.c
120
riscv/sifive_u
396
-F: hw/intc/ibex_plic.c
121
397
+F: hw/*/ibex_*.c
122
RISC-V CPU features
398
F: include/hw/riscv/opentitan.h
399
-F: include/hw/char/ibex_uart.h
400
-F: include/hw/intc/ibex_plic.h
401
+F: include/hw/*/ibex_*.h
402
403
Microchip PolarFire SoC Icicle Kit
404
M: Bin Meng <bin.meng@windriver.com>
405
diff --git a/hw/timer/meson.build b/hw/timer/meson.build
406
index XXXXXXX..XXXXXXX 100644
407
--- a/hw/timer/meson.build
408
+++ b/hw/timer/meson.build
409
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_SSE_COUNTER', if_true: files('sse-counter.c'))
410
softmmu_ss.add(when: 'CONFIG_SSE_TIMER', if_true: files('sse-timer.c'))
411
softmmu_ss.add(when: 'CONFIG_STM32F2XX_TIMER', if_true: files('stm32f2xx_timer.c'))
412
softmmu_ss.add(when: 'CONFIG_XILINX', if_true: files('xilinx_timer.c'))
413
+specific_ss.add(when: 'CONFIG_IBEX', if_true: files('ibex_timer.c'))
414
415
specific_ss.add(when: 'CONFIG_AVR_TIMER16', if_true: files('avr_timer16.c'))
123
--
416
--
124
2.30.1
417
2.31.1
125
418
126
419
diff view generated by jsdifflib
1
From: Georg Kotheimer <georg.kotheimer@kernkonzept.com>
1
Connect the Ibex timer to the OpenTitan machine. The timer can trigger
2
the RISC-V MIE interrupt as well as a custom device interrupt.
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: 5e7f4e9b4537f863bcb8db1264b840b56ef2a929.1624001156.git.alistair.francis@wdc.com
6
MPRV feature would be allowed.
7
---
8
include/hw/riscv/opentitan.h | 5 ++++-
9
hw/riscv/opentitan.c | 14 +++++++++++---
10
2 files changed, 15 insertions(+), 4 deletions(-)
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 @@
29
target_ulong satp_hs;
17
#include "hw/riscv/riscv_hart.h"
30
uint64_t mstatus_hs;
18
#include "hw/intc/ibex_plic.h"
31
19
#include "hw/char/ibex_uart.h"
32
+ /* Signals whether the current exception occurred with two-stage address
20
+#include "hw/timer/ibex_timer.h"
33
+ translation active. */
21
#include "qom/object.h"
34
+ bool two_stage_lookup;
22
23
#define TYPE_RISCV_IBEX_SOC "riscv.lowrisc.ibex.soc"
24
@@ -XXX,XX +XXX,XX @@ struct LowRISCIbexSoCState {
25
RISCVHartArrayState cpus;
26
IbexPlicState plic;
27
IbexUartState uart;
28
+ IbexTimerState timer;
29
30
MemoryRegion flash_mem;
31
MemoryRegion rom;
32
@@ -XXX,XX +XXX,XX @@ enum {
33
IBEX_DEV_SPI,
34
IBEX_DEV_I2C,
35
IBEX_DEV_PATTGEN,
36
- IBEX_DEV_RV_TIMER,
37
+ IBEX_DEV_TIMER,
38
IBEX_DEV_SENSOR_CTRL,
39
IBEX_DEV_OTP_CTRL,
40
IBEX_DEV_PWRMGR,
41
@@ -XXX,XX +XXX,XX @@ enum {
42
};
43
44
enum {
45
+ IBEX_TIMER_TIMEREXPIRED0_0 = 125,
46
IBEX_UART0_RX_PARITY_ERR_IRQ = 8,
47
IBEX_UART0_RX_TIMEOUT_IRQ = 7,
48
IBEX_UART0_RX_BREAK_ERR_IRQ = 6,
49
diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c
50
index XXXXXXX..XXXXXXX 100644
51
--- a/hw/riscv/opentitan.c
52
+++ b/hw/riscv/opentitan.c
53
@@ -XXX,XX +XXX,XX @@ static const MemMapEntry ibex_memmap[] = {
54
[IBEX_DEV_SPI] = { 0x40050000, 0x1000 },
55
[IBEX_DEV_I2C] = { 0x40080000, 0x1000 },
56
[IBEX_DEV_PATTGEN] = { 0x400e0000, 0x1000 },
57
- [IBEX_DEV_RV_TIMER] = { 0x40100000, 0x1000 },
58
+ [IBEX_DEV_TIMER] = { 0x40100000, 0x1000 },
59
[IBEX_DEV_SENSOR_CTRL] = { 0x40110000, 0x1000 },
60
[IBEX_DEV_OTP_CTRL] = { 0x40130000, 0x4000 },
61
[IBEX_DEV_PWRMGR] = { 0x40400000, 0x1000 },
62
@@ -XXX,XX +XXX,XX @@ static void lowrisc_ibex_soc_init(Object *obj)
63
object_initialize_child(obj, "plic", &s->plic, TYPE_IBEX_PLIC);
64
65
object_initialize_child(obj, "uart", &s->uart, TYPE_IBEX_UART);
35
+
66
+
36
target_ulong scounteren;
67
+ object_initialize_child(obj, "timer", &s->timer, TYPE_IBEX_TIMER);
37
target_ulong mcounteren;
38
39
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
40
index XXXXXXX..XXXXXXX 100644
41
--- a/target/riscv/cpu.c
42
+++ b/target/riscv/cpu.c
43
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset(DeviceState *dev)
44
env->mstatus &= ~(MSTATUS_MIE | MSTATUS_MPRV);
45
env->mcause = 0;
46
env->pc = env->resetvec;
47
+ env->two_stage_lookup = false;
48
#endif
49
cs->exception_index = EXCP_NONE;
50
env->load_res = -1;
51
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
52
index XXXXXXX..XXXXXXX 100644
53
--- a/target/riscv/cpu_helper.c
54
+++ b/target/riscv/cpu_helper.c
55
@@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address,
56
g_assert_not_reached();
57
}
58
env->badaddr = address;
59
+ env->two_stage_lookup = two_stage;
60
}
68
}
61
69
62
hwaddr riscv_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
70
static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp)
63
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr,
71
@@ -XXX,XX +XXX,XX @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp)
64
}
72
3, qdev_get_gpio_in(DEVICE(&s->plic),
65
73
IBEX_UART0_RX_OVERFLOW_IRQ));
66
env->badaddr = addr;
74
67
+ env->two_stage_lookup = riscv_cpu_virt_enabled(env) ||
75
+ if (!sysbus_realize(SYS_BUS_DEVICE(&s->timer), errp)) {
68
+ riscv_cpu_two_stage_lookup(mmu_idx);
76
+ return;
69
riscv_raise_exception(&cpu->env, cs->exception_index, retaddr);
77
+ }
70
}
78
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->timer), 0, memmap[IBEX_DEV_TIMER].base);
71
79
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->timer),
72
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr,
80
+ 0, qdev_get_gpio_in(DEVICE(&s->plic),
73
g_assert_not_reached();
81
+ IBEX_TIMER_TIMEREXPIRED0_0));
74
}
82
+
75
env->badaddr = addr;
83
create_unimplemented_device("riscv.lowrisc.ibex.gpio",
76
+ env->two_stage_lookup = riscv_cpu_virt_enabled(env) ||
84
memmap[IBEX_DEV_GPIO].base, memmap[IBEX_DEV_GPIO].size);
77
+ riscv_cpu_two_stage_lookup(mmu_idx);
85
create_unimplemented_device("riscv.lowrisc.ibex.spi",
78
riscv_raise_exception(env, cs->exception_index, retaddr);
86
@@ -XXX,XX +XXX,XX @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp)
79
}
87
memmap[IBEX_DEV_I2C].base, memmap[IBEX_DEV_I2C].size);
80
#endif /* !CONFIG_USER_ONLY */
88
create_unimplemented_device("riscv.lowrisc.ibex.pattgen",
81
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
89
memmap[IBEX_DEV_PATTGEN].base, memmap[IBEX_DEV_PATTGEN].size);
82
/* handle the trap in S-mode */
90
- create_unimplemented_device("riscv.lowrisc.ibex.rv_timer",
83
if (riscv_has_ext(env, RVH)) {
91
- memmap[IBEX_DEV_RV_TIMER].base, memmap[IBEX_DEV_RV_TIMER].size);
84
target_ulong hdeleg = async ? env->hideleg : env->hedeleg;
92
create_unimplemented_device("riscv.lowrisc.ibex.sensor_ctrl",
85
- bool two_stage_lookup = false;
93
memmap[IBEX_DEV_SENSOR_CTRL].base, memmap[IBEX_DEV_SENSOR_CTRL].size);
86
94
create_unimplemented_device("riscv.lowrisc.ibex.otp_ctrl",
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
--
95
--
120
2.30.1
96
2.31.1
121
97
122
98
diff view generated by jsdifflib
Deleted patch
1
From: Bin Meng <bin.meng@windriver.com>
2
1
3
Per SST25VF016B datasheet [1], SST flash requires a dummy byte after
4
the address bytes. Note only SPI mode is supported by SST flashes.
5
6
[1] http://ww1.microchip.com/downloads/en/devicedoc/s71271_04.pdf
7
8
Signed-off-by: Bin Meng <bin.meng@windriver.com>
9
Acked-by: Alistair Francis <alistair.francis@wdc.com>
10
Message-id: 20210306060152.7250-1-bmeng.cn@gmail.com
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
13
hw/block/m25p80.c | 3 +++
14
1 file changed, 3 insertions(+)
15
16
diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/block/m25p80.c
19
+++ b/hw/block/m25p80.c
20
@@ -XXX,XX +XXX,XX @@ static void decode_fast_read_cmd(Flash *s)
21
s->needed_bytes = get_addr_length(s);
22
switch (get_man(s)) {
23
/* Dummy cycles - modeled with bytes writes instead of bits */
24
+ case MAN_SST:
25
+ s->needed_bytes += 1;
26
+ break;
27
case MAN_WINBOND:
28
s->needed_bytes += 8;
29
break;
30
--
31
2.30.1
32
33
diff view generated by jsdifflib