1
The following changes since commit ad10b4badc1dd5b28305f9b9f1168cf0aa3ae946:
1
The following changes since commit 83851c7c60c90e9fb6a23ff48076387a77bc33cd:
2
2
3
Merge tag 'pull-error-2024-05-27' of https://repo.or.cz/qemu/armbru into staging (2024-05-27 06:40:42 -0700)
3
Merge remote-tracking branch 'remotes/mdroth/tags/qga-pull-2020-10-27-v3-tag' into staging (2020-11-03 12:47:58 +0000)
4
4
5
are available in the Git repository at:
5
are available in the Git repository at:
6
6
7
https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20240528
7
git@github.com:alistair23/qemu.git tags/pull-riscv-to-apply-20201103
8
8
9
for you to fetch changes up to 1806da76cb81088ea026ca3441551782b850e393:
9
for you to fetch changes up to 422819776101520cb56658ee5facf926526cf870:
10
10
11
target/riscv: raise an exception when CSRRS/CSRRC writes a read-only CSR (2024-05-28 12:20:27 +1000)
11
target/riscv/csr.c : add space before the open parenthesis '(' (2020-11-03 07:17:23 -0800)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
RISC-V PR for 9.1
14
This series adds support for migration to RISC-V QEMU and expands the
15
15
Microchip PFSoC to allow unmodified HSS and Linux boots.
16
* APLICs add child earlier than realize
17
* Fix exposure of Zkr
18
* Raise exceptions on wrs.nto
19
* Implement SBI debug console (DBCN) calls for KVM
20
* Support 64-bit addresses for initrd
21
* Change RISCV_EXCP_SEMIHOST exception number to 63
22
* Tolerate KVM disable ext errors
23
* Set tval in breakpoints
24
* Add support for Zve32x extension
25
* Add support for Zve64x extension
26
* Relax vector register check in RISCV gdbstub
27
* Fix the element agnostic Vector function problem
28
* Fix Zvkb extension config
29
* Implement dynamic establishment of custom decoder
30
* Add th.sxstatus CSR emulation
31
* Fix Zvfhmin checking for vfwcvt.f.f.v and vfncvt.f.f.w instructions
32
* Check single width operator for vector fp widen instructions
33
* Check single width operator for vfncvt.rod.f.f.w
34
* Remove redudant SEW checking for vector fp narrow/widen instructions
35
* Prioritize pmp errors in raise_mmu_exception()
36
* Do not set mtval2 for non guest-page faults
37
* Remove experimental prefix from "B" extension
38
* Fixup CBO extension register calculation
39
* Fix the hart bit setting of AIA
40
* Fix reg_width in ricsv_gen_dynamic_vector_feature()
41
* Decode all of the pmpcfg and pmpaddr CSRs
42
* Raise an exception when CSRRS/CSRRC writes a read-only CSR
43
16
44
----------------------------------------------------------------
17
----------------------------------------------------------------
45
Alexei Filippov (1):
18
Anup Patel (2):
46
target/riscv: do not set mtval2 for non guest-page faults
19
hw/riscv: sifive_u: Allow passing custom DTB
20
hw/riscv: virt: Allow passing custom DTB
47
21
48
Alistair Francis (2):
22
Bin Meng (10):
49
target/riscv: rvzicbo: Fixup CBO extension register calculation
23
hw/riscv: microchip_pfsoc: Document where to look at the SoC memory maps
50
disas/riscv: Decode all of the pmpcfg and pmpaddr CSRs
24
hw/misc: Add Microchip PolarFire SoC DDR Memory Controller support
25
hw/riscv: microchip_pfsoc: Connect DDR memory controller modules
26
hw/misc: Add Microchip PolarFire SoC IOSCB module support
27
hw/riscv: microchip_pfsoc: Connect the IOSCB module
28
hw/misc: Add Microchip PolarFire SoC SYSREG module support
29
hw/riscv: microchip_pfsoc: Connect the SYSREG module
30
hw/riscv: microchip_pfsoc: Map the reserved memory at address 0
31
hw/riscv: microchip_pfsoc: Correct DDR memory map
32
hw/riscv: microchip_pfsoc: Hook the I2C1 controller
51
33
52
Andrew Jones (2):
34
Xinhao Zhang (1):
53
target/riscv/kvm: Fix exposure of Zkr
35
target/riscv/csr.c : add space before the open parenthesis '('
54
target/riscv: Raise exceptions on wrs.nto
55
36
56
Cheng Yang (1):
37
Yifei Jiang (6):
57
hw/riscv/boot.c: Support 64-bit address for initrd
38
target/riscv: Merge m/vsstatus and m/vsstatush into one uint64_t unit
39
target/riscv: Add basic vmstate description of CPU
40
target/riscv: Add PMP state description
41
target/riscv: Add H extension state description
42
target/riscv: Add V extension state description
43
target/riscv: Add sifive_plic vmstate
58
44
59
Christoph Müllner (1):
45
include/hw/intc/sifive_plic.h | 1 +
60
riscv: thead: Add th.sxstatus CSR emulation
46
include/hw/misc/mchp_pfsoc_dmc.h | 56 +++++++++
47
include/hw/misc/mchp_pfsoc_ioscb.h | 50 ++++++++
48
include/hw/misc/mchp_pfsoc_sysreg.h | 39 ++++++
49
include/hw/riscv/microchip_pfsoc.h | 18 ++-
50
target/riscv/cpu.h | 24 ++--
51
target/riscv/cpu_bits.h | 19 +--
52
target/riscv/internals.h | 4 +
53
target/riscv/pmp.h | 2 +
54
hw/intc/sifive_plic.c | 26 +++-
55
hw/misc/mchp_pfsoc_dmc.c | 216 ++++++++++++++++++++++++++++++++
56
hw/misc/mchp_pfsoc_ioscb.c | 242 ++++++++++++++++++++++++++++++++++++
57
hw/misc/mchp_pfsoc_sysreg.c | 99 +++++++++++++++
58
hw/riscv/microchip_pfsoc.c | 125 ++++++++++++++++---
59
hw/riscv/sifive_u.c | 28 +++--
60
hw/riscv/virt.c | 27 ++--
61
target/riscv/cpu.c | 16 +--
62
target/riscv/cpu_helper.c | 35 ++----
63
target/riscv/csr.c | 20 +--
64
target/riscv/machine.c | 196 +++++++++++++++++++++++++++++
65
target/riscv/op_helper.c | 11 +-
66
target/riscv/pmp.c | 29 +++--
67
MAINTAINERS | 6 +
68
hw/misc/Kconfig | 9 ++
69
hw/misc/meson.build | 3 +
70
hw/riscv/Kconfig | 3 +
71
target/riscv/meson.build | 3 +-
72
27 files changed, 1180 insertions(+), 127 deletions(-)
73
create mode 100644 include/hw/misc/mchp_pfsoc_dmc.h
74
create mode 100644 include/hw/misc/mchp_pfsoc_ioscb.h
75
create mode 100644 include/hw/misc/mchp_pfsoc_sysreg.h
76
create mode 100644 hw/misc/mchp_pfsoc_dmc.c
77
create mode 100644 hw/misc/mchp_pfsoc_ioscb.c
78
create mode 100644 hw/misc/mchp_pfsoc_sysreg.c
79
create mode 100644 target/riscv/machine.c
61
80
62
Clément Léger (1):
63
target/riscv: change RISCV_EXCP_SEMIHOST exception number to 63
64
65
Daniel Henrique Barboza (6):
66
target/riscv/kvm: implement SBI debug console (DBCN) calls
67
target/riscv/kvm: tolerate KVM disable ext errors
68
target/riscv/debug: set tval=pc in breakpoint exceptions
69
trans_privileged.c.inc: set (m|s)tval on ebreak breakpoint
70
target/riscv: prioritize pmp errors in raise_mmu_exception()
71
riscv, gdbstub.c: fix reg_width in ricsv_gen_dynamic_vector_feature()
72
73
Huang Tao (2):
74
target/riscv: Fix the element agnostic function problem
75
target/riscv: Implement dynamic establishment of custom decoder
76
77
Jason Chien (3):
78
target/riscv: Add support for Zve32x extension
79
target/riscv: Add support for Zve64x extension
80
target/riscv: Relax vector register check in RISCV gdbstub
81
82
Max Chou (4):
83
target/riscv: rvv: Fix Zvfhmin checking for vfwcvt.f.f.v and vfncvt.f.f.w instructions
84
target/riscv: rvv: Check single width operator for vector fp widen instructions
85
target/riscv: rvv: Check single width operator for vfncvt.rod.f.f.w
86
target/riscv: rvv: Remove redudant SEW checking for vector fp narrow/widen instructions
87
88
Rob Bradford (1):
89
target/riscv: Remove experimental prefix from "B" extension
90
91
Yangyu Chen (1):
92
target/riscv/cpu.c: fix Zvkb extension config
93
94
Yong-Xuan Wang (1):
95
target/riscv/kvm.c: Fix the hart bit setting of AIA
96
97
Yu-Ming Chang (1):
98
target/riscv: raise an exception when CSRRS/CSRRC writes a read-only CSR
99
100
yang.zhang (1):
101
hw/intc/riscv_aplic: APLICs should add child earlier than realize
102
103
MAINTAINERS | 1 +
104
target/riscv/cpu.h | 11 ++
105
target/riscv/cpu_bits.h | 2 +-
106
target/riscv/cpu_cfg.h | 2 +
107
target/riscv/helper.h | 1 +
108
target/riscv/sbi_ecall_interface.h | 17 +++
109
target/riscv/tcg/tcg-cpu.h | 15 +++
110
disas/riscv.c | 65 +++++++++-
111
hw/intc/riscv_aplic.c | 8 +-
112
hw/riscv/boot.c | 4 +-
113
target/riscv/cpu.c | 10 +-
114
target/riscv/cpu_helper.c | 37 +++---
115
target/riscv/csr.c | 71 +++++++++--
116
target/riscv/debug.c | 3 +
117
target/riscv/gdbstub.c | 8 +-
118
target/riscv/kvm/kvm-cpu.c | 157 ++++++++++++++++++++++++-
119
target/riscv/op_helper.c | 17 ++-
120
target/riscv/tcg/tcg-cpu.c | 50 +++++---
121
target/riscv/th_csr.c | 79 +++++++++++++
122
target/riscv/translate.c | 31 +++--
123
target/riscv/vector_internals.c | 22 ++++
124
target/riscv/insn_trans/trans_privileged.c.inc | 2 +
125
target/riscv/insn_trans/trans_rvv.c.inc | 46 +++++---
126
target/riscv/insn_trans/trans_rvzawrs.c.inc | 29 +++--
127
target/riscv/insn_trans/trans_rvzicbo.c.inc | 16 ++-
128
target/riscv/meson.build | 1 +
129
26 files changed, 596 insertions(+), 109 deletions(-)
130
create mode 100644 target/riscv/th_csr.c
131
diff view generated by jsdifflib
1
From: "yang.zhang" <yang.zhang@hexintek.com>
1
From: Anup Patel <anup.patel@wdc.com>
2
2
3
Since only root APLICs can have hw IRQ lines, aplic->parent should
3
Extend sifive_u machine to allow passing custom DTB using "-dtb"
4
be initialized first.
4
command-line parameter. This will help users pass modified DTB
5
or Linux SiFive DTB to sifive_u machine.
5
6
6
Fixes: e8f79343cf ("hw/intc: Add RISC-V AIA APLIC device emulation")
7
Signed-off-by: Anup Patel <anup.patel@wdc.com>
7
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Signed-off-by: yang.zhang <yang.zhang@hexintek.com>
9
Message-id: 20201022053225.2596110-1-anup.patel@wdc.com
9
Cc: qemu-stable <qemu-stable@nongnu.org>
10
Message-ID: <20240409014445.278-1-gaoshanliukou@163.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
11
---
13
hw/intc/riscv_aplic.c | 8 ++++----
12
hw/riscv/sifive_u.c | 28 ++++++++++++++++++++--------
14
1 file changed, 4 insertions(+), 4 deletions(-)
13
1 file changed, 20 insertions(+), 8 deletions(-)
15
14
16
diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c
15
diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
17
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/intc/riscv_aplic.c
17
--- a/hw/riscv/sifive_u.c
19
+++ b/hw/intc/riscv_aplic.c
18
+++ b/hw/riscv/sifive_u.c
20
@@ -XXX,XX +XXX,XX @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size,
19
@@ -XXX,XX +XXX,XX @@ static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap,
21
qdev_prop_set_bit(dev, "msimode", msimode);
20
int cpu;
22
qdev_prop_set_bit(dev, "mmode", mmode);
21
uint32_t *cells;
23
22
char *nodename;
24
+ if (parent) {
23
+ const char *dtb_filename;
25
+ riscv_aplic_add_child(parent, dev);
24
char ethclk_names[] = "pclk\0hclk";
26
+ }
25
uint32_t plic_phandle, prci_phandle, gpio_phandle, phandle = 1;
27
+
26
uint32_t hfclk_phandle, rtcclk_phandle, phy_phandle;
28
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
27
29
28
- fdt = s->fdt = create_device_tree(&s->fdt_size);
30
if (!is_kvm_aia(msimode)) {
29
- if (!fdt) {
31
sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr);
30
- error_report("create_device_tree() failed");
31
- exit(1);
32
+ dtb_filename = qemu_opt_get(qemu_get_machine_opts(), "dtb");
33
+ if (dtb_filename) {
34
+ fdt = s->fdt = load_device_tree(dtb_filename, &s->fdt_size);
35
+ if (!fdt) {
36
+ error_report("load_device_tree() failed");
37
+ exit(1);
38
+ }
39
+ goto update_bootargs;
40
+ } else {
41
+ fdt = s->fdt = create_device_tree(&s->fdt_size);
42
+ if (!fdt) {
43
+ error_report("create_device_tree() failed");
44
+ exit(1);
45
+ }
32
}
46
}
33
47
34
- if (parent) {
48
qemu_fdt_setprop_string(fdt, "/", "model", "SiFive HiFive Unleashed A00");
35
- riscv_aplic_add_child(parent, dev);
49
@@ -XXX,XX +XXX,XX @@ static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap,
50
51
qemu_fdt_add_subnode(fdt, "/chosen");
52
qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", nodename);
53
- if (cmdline) {
54
- qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline);
36
- }
55
- }
37
-
56
-
38
if (!msimode) {
57
qemu_fdt_setprop_string(fdt, "/aliases", "serial0", nodename);
39
for (i = 0; i < num_harts; i++) {
58
40
CPUState *cpu = cpu_by_arch_id(hartid_base + i);
59
g_free(nodename);
60
+
61
+update_bootargs:
62
+ if (cmdline) {
63
+ qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline);
64
+ }
65
}
66
67
static void sifive_u_machine_reset(void *opaque, int n, int level)
41
--
68
--
42
2.45.1
69
2.28.0
70
71
diff view generated by jsdifflib
1
From: Yong-Xuan Wang <yongxuan.wang@sifive.com>
1
From: Anup Patel <anup.patel@wdc.com>
2
2
3
In AIA spec, each hart (or each hart within a group) has a unique hart
3
Extend virt machine to allow passing custom DTB using "-dtb"
4
number to locate the memory pages of interrupt files in the address
4
command-line parameter. This will help users pass modified DTB
5
space. The number of bits required to represent any hart number is equal
5
to virt machine.
6
to ceil(log2(hmax + 1)), where hmax is the largest hart number among
7
groups.
8
6
9
However, if the largest hart number among groups is a power of 2, QEMU
7
Signed-off-by: Anup Patel <anup.patel@wdc.com>
10
will pass an inaccurate hart-index-bit setting to Linux. For example, when
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
the guest OS has 4 harts, only ceil(log2(3 + 1)) = 2 bits are sufficient
9
Message-id: 20201022053225.2596110-2-anup.patel@wdc.com
12
to represent 4 harts, but we passes 3 to Linux. The code needs to be
13
updated to ensure accurate hart-index-bit settings.
14
15
Additionally, a Linux patch[1] is necessary to correctly recover the hart
16
index when the guest OS has only 1 hart, where the hart-index-bit is 0.
17
18
[1] https://lore.kernel.org/lkml/20240415064905.25184-1-yongxuan.wang@sifive.com/t/
19
20
Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
21
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
22
Cc: qemu-stable <qemu-stable@nongnu.org>
23
Message-ID: <20240515091129.28116-1-yongxuan.wang@sifive.com>
24
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
25
---
11
---
26
target/riscv/kvm/kvm-cpu.c | 9 ++++++++-
12
hw/riscv/virt.c | 27 ++++++++++++++++++++-------
27
1 file changed, 8 insertions(+), 1 deletion(-)
13
1 file changed, 20 insertions(+), 7 deletions(-)
28
14
29
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
15
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
30
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
31
--- a/target/riscv/kvm/kvm-cpu.c
17
--- a/hw/riscv/virt.c
32
+++ b/target/riscv/kvm/kvm-cpu.c
18
+++ b/hw/riscv/virt.c
33
@@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
19
@@ -XXX,XX +XXX,XX @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,
34
}
20
{
21
void *fdt;
22
int i, cpu, socket;
23
+ const char *dtb_filename;
24
MachineState *mc = MACHINE(s);
25
uint64_t addr, size;
26
uint32_t *clint_cells, *plic_cells;
27
@@ -XXX,XX +XXX,XX @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,
28
hwaddr flashsize = virt_memmap[VIRT_FLASH].size / 2;
29
hwaddr flashbase = virt_memmap[VIRT_FLASH].base;
30
31
- fdt = s->fdt = create_device_tree(&s->fdt_size);
32
- if (!fdt) {
33
- error_report("create_device_tree() failed");
34
- exit(1);
35
+ dtb_filename = qemu_opt_get(qemu_get_machine_opts(), "dtb");
36
+ if (dtb_filename) {
37
+ fdt = s->fdt = load_device_tree(dtb_filename, &s->fdt_size);
38
+ if (!fdt) {
39
+ error_report("load_device_tree() failed");
40
+ exit(1);
41
+ }
42
+ goto update_bootargs;
43
+ } else {
44
+ fdt = s->fdt = create_device_tree(&s->fdt_size);
45
+ if (!fdt) {
46
+ error_report("create_device_tree() failed");
47
+ exit(1);
48
+ }
35
}
49
}
36
50
37
- hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1;
51
qemu_fdt_setprop_string(fdt, "/", "model", "riscv-virtio,qemu");
52
@@ -XXX,XX +XXX,XX @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,
53
54
qemu_fdt_add_subnode(fdt, "/chosen");
55
qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", name);
56
- if (cmdline) {
57
- qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline);
58
- }
59
g_free(name);
60
61
name = g_strdup_printf("/soc/rtc@%lx", (long)memmap[VIRT_RTC].base);
62
@@ -XXX,XX +XXX,XX @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,
63
2, flashbase + flashsize, 2, flashsize);
64
qemu_fdt_setprop_cell(s->fdt, name, "bank-width", 4);
65
g_free(name);
38
+
66
+
39
+ if (max_hart_per_socket > 1) {
67
+update_bootargs:
40
+ max_hart_per_socket--;
68
+ if (cmdline) {
41
+ hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1;
69
+ qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline);
42
+ } else {
43
+ hart_bits = 0;
44
+ }
70
+ }
45
+
71
}
46
ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG,
72
47
KVM_DEV_RISCV_AIA_CONFIG_HART_BITS,
73
static inline DeviceState *gpex_pcie_init(MemoryRegion *sys_mem,
48
&hart_bits, true, NULL);
49
--
74
--
50
2.45.1
75
2.28.0
76
77
diff view generated by jsdifflib
1
From: Yu-Ming Chang <yumin686@andestech.com>
1
From: Yifei Jiang <jiangyifei@huawei.com>
2
2
3
Both CSRRS and CSRRC always read the addressed CSR and cause any read side
3
mstatus/mstatush and vsstatus/vsstatush are two halved for RISCV32.
4
effects regardless of rs1 and rd fields. Note that if rs1 specifies a register
4
This patch expands mstatus and vsstatus to uint64_t instead of
5
holding a zero value other than x0, the instruction will still attempt to write
5
target_ulong so that it can be saved as one unit and reduce some
6
the unmodified value back to the CSR and will cause any attendant side effects.
6
ifdefs in the code.
7
7
8
So if CSRRS or CSRRC tries to write a read-only CSR with rs1 which specifies
8
Signed-off-by: Yifei Jiang <jiangyifei@huawei.com>
9
a register holding a zero value, an illegal instruction exception should be
9
Signed-off-by: Yipeng Yin <yinyipeng1@huawei.com>
10
raised.
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
12
Signed-off-by: Yu-Ming Chang <yumin686@andestech.com>
13
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
14
Message-ID: <20240403070823.80897-1-yumin686@andestech.com>
12
Message-id: 20201026115530.304-2-jiangyifei@huawei.com
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
16
---
13
---
17
target/riscv/cpu.h | 4 ++++
14
target/riscv/cpu.h | 24 +++++++++++-------------
18
target/riscv/csr.c | 51 ++++++++++++++++++++++++++++++++++++----
15
target/riscv/cpu_bits.h | 19 ++++---------------
19
target/riscv/op_helper.c | 6 ++---
16
target/riscv/cpu.c | 8 +++++---
20
3 files changed, 53 insertions(+), 8 deletions(-)
17
target/riscv/cpu_helper.c | 35 +++++++----------------------------
18
target/riscv/csr.c | 18 ++++++++++--------
19
target/riscv/op_helper.c | 11 ++++-------
20
6 files changed, 41 insertions(+), 74 deletions(-)
21
21
22
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
22
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
23
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
24
--- a/target/riscv/cpu.h
24
--- a/target/riscv/cpu.h
25
+++ b/target/riscv/cpu.h
25
+++ b/target/riscv/cpu.h
26
@@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
26
@@ -XXX,XX +XXX,XX @@ struct CPURISCVState {
27
void riscv_cpu_update_mask(CPURISCVState *env);
27
target_ulong resetvec;
28
bool riscv_cpu_is_32bit(RISCVCPU *cpu);
28
29
29
target_ulong mhartid;
30
+RISCVException riscv_csrr(CPURISCVState *env, int csrno,
30
- target_ulong mstatus;
31
+ target_ulong *ret_value);
31
+ /*
32
RISCVException riscv_csrrw(CPURISCVState *env, int csrno,
32
+ * For RV32 this is 32-bit mstatus and 32-bit mstatush.
33
target_ulong *ret_value,
33
+ * For RV64 this is a 64-bit mstatus.
34
target_ulong new_value, target_ulong write_mask);
34
+ */
35
@@ -XXX,XX +XXX,XX @@ typedef RISCVException (*riscv_csr_op_fn)(CPURISCVState *env, int csrno,
35
+ uint64_t mstatus;
36
target_ulong new_value,
36
37
target_ulong write_mask);
37
target_ulong mip;
38
38
39
+RISCVException riscv_csrr_i128(CPURISCVState *env, int csrno,
39
-#ifdef TARGET_RISCV32
40
+ Int128 *ret_value);
40
- target_ulong mstatush;
41
RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno,
41
-#endif
42
Int128 *ret_value,
42
-
43
Int128 new_value, Int128 write_mask);
43
uint32_t miclaim;
44
45
target_ulong mie;
46
@@ -XXX,XX +XXX,XX @@ struct CPURISCVState {
47
uint64_t htimedelta;
48
49
/* Virtual CSRs */
50
- target_ulong vsstatus;
51
+ /*
52
+ * For RV32 this is 32-bit vsstatus and 32-bit vsstatush.
53
+ * For RV64 this is a 64-bit vsstatus.
54
+ */
55
+ uint64_t vsstatus;
56
target_ulong vstvec;
57
target_ulong vsscratch;
58
target_ulong vsepc;
59
target_ulong vscause;
60
target_ulong vstval;
61
target_ulong vsatp;
62
-#ifdef TARGET_RISCV32
63
- target_ulong vsstatush;
64
-#endif
65
66
target_ulong mtval2;
67
target_ulong mtinst;
68
@@ -XXX,XX +XXX,XX @@ struct CPURISCVState {
69
target_ulong scause_hs;
70
target_ulong stval_hs;
71
target_ulong satp_hs;
72
- target_ulong mstatus_hs;
73
-#ifdef TARGET_RISCV32
74
- target_ulong mstatush_hs;
75
-#endif
76
+ uint64_t mstatus_hs;
77
78
target_ulong scounteren;
79
target_ulong mcounteren;
80
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
81
index XXXXXXX..XXXXXXX 100644
82
--- a/target/riscv/cpu_bits.h
83
+++ b/target/riscv/cpu_bits.h
84
@@ -XXX,XX +XXX,XX @@
85
#define TARGET_RISCV_CPU_BITS_H
86
87
#define get_field(reg, mask) (((reg) & \
88
- (target_ulong)(mask)) / ((mask) & ~((mask) << 1)))
89
-#define set_field(reg, mask, val) (((reg) & ~(target_ulong)(mask)) | \
90
- (((target_ulong)(val) * ((mask) & ~((mask) << 1))) & \
91
- (target_ulong)(mask)))
92
+ (uint64_t)(mask)) / ((mask) & ~((mask) << 1)))
93
+#define set_field(reg, mask, val) (((reg) & ~(uint64_t)(mask)) | \
94
+ (((uint64_t)(val) * ((mask) & ~((mask) << 1))) & \
95
+ (uint64_t)(mask)))
96
97
/* Floating point round mode */
98
#define FSR_RD_SHIFT 5
99
@@ -XXX,XX +XXX,XX @@
100
#define MSTATUS_TVM 0x00100000 /* since: priv-1.10 */
101
#define MSTATUS_TW 0x20000000 /* since: priv-1.10 */
102
#define MSTATUS_TSR 0x40000000 /* since: priv-1.10 */
103
-#if defined(TARGET_RISCV64)
104
#define MSTATUS_GVA 0x4000000000ULL
105
#define MSTATUS_MPV 0x8000000000ULL
106
-#elif defined(TARGET_RISCV32)
107
-#define MSTATUS_GVA 0x00000040
108
-#define MSTATUS_MPV 0x00000080
109
-#endif
110
-
111
-#ifdef TARGET_RISCV32
112
-# define MSTATUS_MPV_ISSET(env) get_field(env->mstatush, MSTATUS_MPV)
113
-#else
114
-# define MSTATUS_MPV_ISSET(env) get_field(env->mstatus, MSTATUS_MPV)
115
-#endif
116
117
#define MSTATUS64_UXL 0x0000000300000000ULL
118
#define MSTATUS64_SXL 0x0000000C00000000ULL
119
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
120
index XXXXXXX..XXXXXXX 100644
121
--- a/target/riscv/cpu.c
122
+++ b/target/riscv/cpu.c
123
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags)
124
qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "pc ", env->pc);
125
#ifndef CONFIG_USER_ONLY
126
qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mhartid ", env->mhartid);
127
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mstatus ", env->mstatus);
128
+ qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mstatus ", (target_ulong)env->mstatus);
129
#ifdef TARGET_RISCV32
130
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mstatush ", env->mstatush);
131
+ qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mstatush ",
132
+ (target_ulong)(env->mstatus >> 32));
133
#endif
134
if (riscv_has_ext(env, RVH)) {
135
qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "hstatus ", env->hstatus);
136
- qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "vsstatus ", env->vsstatus);
137
+ qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "vsstatus ",
138
+ (target_ulong)env->vsstatus);
139
}
140
qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mip ", env->mip);
141
qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mie ", env->mie);
142
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
143
index XXXXXXX..XXXXXXX 100644
144
--- a/target/riscv/cpu_helper.c
145
+++ b/target/riscv/cpu_helper.c
146
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_fp_enabled(CPURISCVState *env)
147
148
void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env)
149
{
150
- target_ulong mstatus_mask = MSTATUS_MXR | MSTATUS_SUM | MSTATUS_FS |
151
- MSTATUS_SPP | MSTATUS_SPIE | MSTATUS_SIE;
152
+ uint64_t mstatus_mask = MSTATUS_MXR | MSTATUS_SUM | MSTATUS_FS |
153
+ MSTATUS_SPP | MSTATUS_SPIE | MSTATUS_SIE |
154
+ MSTATUS64_UXL;
155
bool current_virt = riscv_cpu_virt_enabled(env);
156
157
g_assert(riscv_has_ext(env, RVH));
158
159
-#if defined(TARGET_RISCV64)
160
- mstatus_mask |= MSTATUS64_UXL;
161
-#endif
162
-
163
if (current_virt) {
164
/* Current V=1 and we are about to change to V=0 */
165
env->vsstatus = env->mstatus & mstatus_mask;
166
env->mstatus &= ~mstatus_mask;
167
env->mstatus |= env->mstatus_hs;
168
169
-#if defined(TARGET_RISCV32)
170
- env->vsstatush = env->mstatush;
171
- env->mstatush |= env->mstatush_hs;
172
-#endif
173
-
174
env->vstvec = env->stvec;
175
env->stvec = env->stvec_hs;
176
177
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env)
178
env->mstatus &= ~mstatus_mask;
179
env->mstatus |= env->vsstatus;
180
181
-#if defined(TARGET_RISCV32)
182
- env->mstatush_hs = env->mstatush;
183
- env->mstatush |= env->vsstatush;
184
-#endif
185
-
186
env->stvec_hs = env->stvec;
187
env->stvec = env->vstvec;
188
189
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
190
if (riscv_has_ext(env, RVH) && env->priv == PRV_M &&
191
access_type != MMU_INST_FETCH &&
192
get_field(env->mstatus, MSTATUS_MPRV) &&
193
- MSTATUS_MPV_ISSET(env)) {
194
+ get_field(env->mstatus, MSTATUS_MPV)) {
195
riscv_cpu_set_two_stage_lookup(env, true);
196
}
197
198
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
199
if (riscv_has_ext(env, RVH) && env->priv == PRV_M &&
200
access_type != MMU_INST_FETCH &&
201
get_field(env->mstatus, MSTATUS_MPRV) &&
202
- MSTATUS_MPV_ISSET(env)) {
203
+ get_field(env->mstatus, MSTATUS_MPV)) {
204
riscv_cpu_set_two_stage_lookup(env, false);
205
}
206
207
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
208
RISCVCPU *cpu = RISCV_CPU(cs);
209
CPURISCVState *env = &cpu->env;
210
bool force_hs_execp = riscv_cpu_force_hs_excep_enabled(env);
211
- target_ulong s;
212
+ uint64_t s;
213
214
/* cs->exception is 32-bits wide unlike mcause which is XLEN-bits wide
215
* so we mask off the MSB and separate into trap type and cause.
216
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
217
if (riscv_cpu_virt_enabled(env)) {
218
riscv_cpu_swap_hypervisor_regs(env);
219
}
220
-#ifdef TARGET_RISCV32
221
- env->mstatush = set_field(env->mstatush, MSTATUS_MPV,
222
- riscv_cpu_virt_enabled(env));
223
- if (riscv_cpu_virt_enabled(env) && tval) {
224
- env->mstatush = set_field(env->mstatush, MSTATUS_GVA, 1);
225
- }
226
-#else
227
env->mstatus = set_field(env->mstatus, MSTATUS_MPV,
228
- riscv_cpu_virt_enabled(env));
229
+ riscv_cpu_virt_enabled(env));
230
if (riscv_cpu_virt_enabled(env) && tval) {
231
env->mstatus = set_field(env->mstatus, MSTATUS_GVA, 1);
232
}
233
-#endif
234
235
mtval2 = env->guest_phys_fault_addr;
236
44
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
237
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
45
index XXXXXXX..XXXXXXX 100644
238
index XXXXXXX..XXXXXXX 100644
46
--- a/target/riscv/csr.c
239
--- a/target/riscv/csr.c
47
+++ b/target/riscv/csr.c
240
+++ b/target/riscv/csr.c
48
@@ -XXX,XX +XXX,XX @@ static RISCVException rmw_seed(CPURISCVState *env, int csrno,
241
@@ -XXX,XX +XXX,XX @@ static int validate_vm(CPURISCVState *env, target_ulong vm)
49
242
50
static inline RISCVException riscv_csrrw_check(CPURISCVState *env,
243
static int write_mstatus(CPURISCVState *env, int csrno, target_ulong val)
51
int csrno,
244
{
52
- bool write_mask)
245
- target_ulong mstatus = env->mstatus;
53
+ bool write)
246
- target_ulong mask = 0;
54
{
247
+ uint64_t mstatus = env->mstatus;
55
/* check privileges and return RISCV_EXCP_ILLEGAL_INST if check fails */
248
+ uint64_t mask = 0;
56
bool read_only = get_field(csrno, 0xC00) == 3;
249
int dirty;
57
@@ -XXX,XX +XXX,XX @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env,
250
58
}
251
/* flush tlb on mstatus fields that affect VM */
59
252
@@ -XXX,XX +XXX,XX @@ static int write_mstatus(CPURISCVState *env, int csrno, target_ulong val)
60
/* read / write check */
253
#ifdef TARGET_RISCV32
61
- if (write_mask && read_only) {
254
static int read_mstatush(CPURISCVState *env, int csrno, target_ulong *val)
62
+ if (write && read_only) {
255
{
63
return RISCV_EXCP_ILLEGAL_INST;
256
- *val = env->mstatush;
64
}
257
+ *val = env->mstatus >> 32;
65
258
return 0;
66
@@ -XXX,XX +XXX,XX @@ static RISCVException riscv_csrrw_do64(CPURISCVState *env, int csrno,
67
return RISCV_EXCP_NONE;
68
}
259
}
69
260
70
+RISCVException riscv_csrr(CPURISCVState *env, int csrno,
261
static int write_mstatush(CPURISCVState *env, int csrno, target_ulong val)
71
+ target_ulong *ret_value)
262
{
72
+{
263
- if ((val ^ env->mstatush) & (MSTATUS_MPV)) {
73
+ RISCVException ret = riscv_csrrw_check(env, csrno, false);
264
+ uint64_t valh = (uint64_t)val << 32;
74
+ if (ret != RISCV_EXCP_NONE) {
265
+ uint64_t mask = MSTATUS_MPV | MSTATUS_GVA;
75
+ return ret;
76
+ }
77
+
266
+
78
+ return riscv_csrrw_do64(env, csrno, ret_value, 0, 0);
267
+ if ((valh ^ env->mstatus) & (MSTATUS_MPV)) {
79
+}
268
tlb_flush(env_cpu(env));
80
+
269
}
81
RISCVException riscv_csrrw(CPURISCVState *env, int csrno,
270
82
target_ulong *ret_value,
271
- val &= MSTATUS_MPV | MSTATUS_GVA;
83
target_ulong new_value, target_ulong write_mask)
272
-
84
{
273
- env->mstatush = val;
85
- RISCVException ret = riscv_csrrw_check(env, csrno, write_mask);
274
+ env->mstatus = (env->mstatus & ~mask) | (valh & mask);
86
+ RISCVException ret = riscv_csrrw_check(env, csrno, true);
275
87
if (ret != RISCV_EXCP_NONE) {
276
return 0;
88
return ret;
89
}
90
@@ -XXX,XX +XXX,XX @@ static RISCVException riscv_csrrw_do128(CPURISCVState *env, int csrno,
91
return RISCV_EXCP_NONE;
92
}
277
}
93
278
@@ -XXX,XX +XXX,XX @@ static int read_vsstatus(CPURISCVState *env, int csrno, target_ulong *val)
94
+RISCVException riscv_csrr_i128(CPURISCVState *env, int csrno,
279
95
+ Int128 *ret_value)
280
static int write_vsstatus(CPURISCVState *env, int csrno, target_ulong val)
96
+{
281
{
97
+ RISCVException ret;
282
- env->vsstatus = val;
98
+
283
+ uint64_t mask = (target_ulong)-1;
99
+ ret = riscv_csrrw_check(env, csrno, false);
284
+ env->vsstatus = (env->vsstatus & ~mask) | (uint64_t)val;
100
+ if (ret != RISCV_EXCP_NONE) {
285
return 0;
101
+ return ret;
286
}
102
+ }
287
103
+
104
+ if (csr_ops[csrno].read128) {
105
+ return riscv_csrrw_do128(env, csrno, ret_value,
106
+ int128_zero(), int128_zero());
107
+ }
108
+
109
+ /*
110
+ * Fall back to 64-bit version for now, if the 128-bit alternative isn't
111
+ * at all defined.
112
+ * Note, some CSRs don't need to extend to MXLEN (64 upper bits non
113
+ * significant), for those, this fallback is correctly handling the
114
+ * accesses
115
+ */
116
+ target_ulong old_value;
117
+ ret = riscv_csrrw_do64(env, csrno, &old_value,
118
+ (target_ulong)0,
119
+ (target_ulong)0);
120
+ if (ret == RISCV_EXCP_NONE && ret_value) {
121
+ *ret_value = int128_make64(old_value);
122
+ }
123
+ return ret;
124
+}
125
+
126
RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno,
127
Int128 *ret_value,
128
Int128 new_value, Int128 write_mask)
129
{
130
RISCVException ret;
131
132
- ret = riscv_csrrw_check(env, csrno, int128_nz(write_mask));
133
+ ret = riscv_csrrw_check(env, csrno, true);
134
if (ret != RISCV_EXCP_NONE) {
135
return ret;
136
}
137
diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
288
diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
138
index XXXXXXX..XXXXXXX 100644
289
index XXXXXXX..XXXXXXX 100644
139
--- a/target/riscv/op_helper.c
290
--- a/target/riscv/op_helper.c
140
+++ b/target/riscv/op_helper.c
291
+++ b/target/riscv/op_helper.c
141
@@ -XXX,XX +XXX,XX @@ target_ulong helper_csrr(CPURISCVState *env, int csr)
292
@@ -XXX,XX +XXX,XX @@ target_ulong helper_csrrc(CPURISCVState *env, target_ulong src,
142
}
293
143
294
target_ulong helper_sret(CPURISCVState *env, target_ulong cpu_pc_deb)
144
target_ulong val = 0;
295
{
145
- RISCVException ret = riscv_csrrw(env, csr, &val, 0, 0);
296
- target_ulong prev_priv, prev_virt, mstatus;
146
+ RISCVException ret = riscv_csrr(env, csr, &val);
297
+ uint64_t mstatus;
147
298
+ target_ulong prev_priv, prev_virt;
148
if (ret != RISCV_EXCP_NONE) {
299
149
riscv_raise_exception(env, ret, GETPC());
300
if (!(env->priv >= PRV_S)) {
150
@@ -XXX,XX +XXX,XX @@ target_ulong helper_csrrw(CPURISCVState *env, int csr,
301
riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC());
151
target_ulong helper_csrr_i128(CPURISCVState *env, int csr)
302
@@ -XXX,XX +XXX,XX @@ target_ulong helper_mret(CPURISCVState *env, target_ulong cpu_pc_deb)
152
{
303
riscv_raise_exception(env, RISCV_EXCP_INST_ADDR_MIS, GETPC());
153
Int128 rv = int128_zero();
304
}
154
- RISCVException ret = riscv_csrrw_i128(env, csr, &rv,
305
155
- int128_zero(),
306
- target_ulong mstatus = env->mstatus;
156
- int128_zero());
307
+ uint64_t mstatus = env->mstatus;
157
+ RISCVException ret = riscv_csrr_i128(env, csr, &rv);
308
target_ulong prev_priv = get_field(mstatus, MSTATUS_MPP);
158
309
- target_ulong prev_virt = MSTATUS_MPV_ISSET(env);
159
if (ret != RISCV_EXCP_NONE) {
310
+ target_ulong prev_virt = get_field(env->mstatus, MSTATUS_MPV);
160
riscv_raise_exception(env, ret, GETPC());
311
mstatus = set_field(mstatus, MSTATUS_MIE,
312
get_field(mstatus, MSTATUS_MPIE));
313
mstatus = set_field(mstatus, MSTATUS_MPIE, 1);
314
mstatus = set_field(mstatus, MSTATUS_MPP, PRV_U);
315
-#ifdef TARGET_RISCV32
316
- env->mstatush = set_field(env->mstatush, MSTATUS_MPV, 0);
317
-#else
318
mstatus = set_field(mstatus, MSTATUS_MPV, 0);
319
-#endif
320
env->mstatus = mstatus;
321
riscv_cpu_set_mode(env, prev_priv);
322
161
--
323
--
162
2.45.1
324
2.28.0
325
326
diff view generated by jsdifflib
1
From: Christoph Müllner <christoph.muellner@vrull.eu>
1
From: Yifei Jiang <jiangyifei@huawei.com>
2
2
3
The th.sxstatus CSR can be used to identify available custom extension
3
Add basic CPU state description to the newly created machine.c
4
on T-Head CPUs. The CSR is documented here:
5
https://github.com/T-head-Semi/thead-extension-spec/blob/master/xtheadsxstatus.adoc
6
4
7
An important property of this patch is, that the th.sxstatus MAEE field
5
Signed-off-by: Yifei Jiang <jiangyifei@huawei.com>
8
is not set (indicating that XTheadMae is not available).
6
Signed-off-by: Yipeng Yin <yinyipeng1@huawei.com>
9
XTheadMae is a memory attribute extension (similar to Svpbmt) which is
10
implemented in many T-Head CPUs (C906, C910, etc.) and utilizes bits
11
in PTEs that are marked as reserved. QEMU maintainers prefer to not
12
implement XTheadMae, so we need give kernels a mechanism to identify
13
if XTheadMae is available in a system or not. And this patch introduces
14
this mechanism in QEMU in a way that's compatible with real HW
15
(i.e., probing the th.sxstatus.MAEE bit).
16
17
Further context can be found on the list:
18
https://lists.gnu.org/archive/html/qemu-devel/2024-02/msg00775.html
19
20
Reviewed-by: LIU Zhiwei <zhiwe_liu@linux.alibaba.com>
21
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
22
Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
8
Message-id: 20201026115530.304-3-jiangyifei@huawei.com
23
Message-ID: <20240429073656.2486732-1-christoph.muellner@vrull.eu>
24
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
25
---
10
---
26
MAINTAINERS | 1 +
11
target/riscv/internals.h | 4 +++
27
target/riscv/cpu.h | 3 ++
12
target/riscv/cpu.c | 8 +----
28
target/riscv/cpu.c | 1 +
13
target/riscv/machine.c | 74 ++++++++++++++++++++++++++++++++++++++++
29
target/riscv/th_csr.c | 79 ++++++++++++++++++++++++++++++++++++++++
14
target/riscv/meson.build | 3 +-
30
target/riscv/meson.build | 1 +
15
4 files changed, 81 insertions(+), 8 deletions(-)
31
5 files changed, 85 insertions(+)
16
create mode 100644 target/riscv/machine.c
32
create mode 100644 target/riscv/th_csr.c
33
17
34
diff --git a/MAINTAINERS b/MAINTAINERS
18
diff --git a/target/riscv/internals.h b/target/riscv/internals.h
35
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
36
--- a/MAINTAINERS
20
--- a/target/riscv/internals.h
37
+++ b/MAINTAINERS
21
+++ b/target/riscv/internals.h
38
@@ -XXX,XX +XXX,XX @@ L: qemu-riscv@nongnu.org
22
@@ -XXX,XX +XXX,XX @@ target_ulong fclass_d(uint64_t frs1);
39
S: Supported
23
#define SEW32 2
40
F: target/riscv/insn_trans/trans_xthead.c.inc
24
#define SEW64 3
41
F: target/riscv/xthead*.decode
25
42
+F: target/riscv/th_*
26
+#ifndef CONFIG_USER_ONLY
43
F: disas/riscv-xthead*
27
+extern const VMStateDescription vmstate_riscv_cpu;
44
28
+#endif
45
RISC-V XVentanaCondOps extension
46
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
47
index XXXXXXX..XXXXXXX 100644
48
--- a/target/riscv/cpu.h
49
+++ b/target/riscv/cpu.h
50
@@ -XXX,XX +XXX,XX @@ target_ulong riscv_new_csr_seed(target_ulong new_value,
51
uint8_t satp_mode_max_from_map(uint32_t map);
52
const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit);
53
54
+/* Implemented in th_csr.c */
55
+void th_register_custom_csrs(RISCVCPU *cpu);
56
+
29
+
57
#endif /* RISCV_CPU_H */
30
static inline uint64_t nanbox_s(float32 f)
31
{
32
return f | MAKE_64BIT_MASK(32, 32);
58
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
33
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
59
index XXXXXXX..XXXXXXX 100644
34
index XXXXXXX..XXXXXXX 100644
60
--- a/target/riscv/cpu.c
35
--- a/target/riscv/cpu.c
61
+++ b/target/riscv/cpu.c
36
+++ b/target/riscv/cpu.c
62
@@ -XXX,XX +XXX,XX @@ static void rv64_thead_c906_cpu_init(Object *obj)
37
@@ -XXX,XX +XXX,XX @@
63
cpu->cfg.mvendorid = THEAD_VENDOR_ID;
38
#include "qemu/ctype.h"
64
#ifndef CONFIG_USER_ONLY
39
#include "qemu/log.h"
65
set_satp_mode_max_supported(cpu, VM_1_10_SV39);
40
#include "cpu.h"
66
+ th_register_custom_csrs(cpu);
41
+#include "internals.h"
67
#endif
42
#include "exec/exec-all.h"
68
43
#include "qapi/error.h"
69
/* inherited from parent obj via riscv_cpu_init() */
44
#include "qemu/error-report.h"
70
diff --git a/target/riscv/th_csr.c b/target/riscv/th_csr.c
45
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_init(Object *obj)
46
cpu_set_cpustate_pointers(cpu);
47
}
48
49
-#ifndef CONFIG_USER_ONLY
50
-static const VMStateDescription vmstate_riscv_cpu = {
51
- .name = "cpu",
52
- .unmigratable = 1,
53
-};
54
-#endif
55
-
56
static Property riscv_cpu_properties[] = {
57
DEFINE_PROP_BOOL("i", RISCVCPU, cfg.ext_i, true),
58
DEFINE_PROP_BOOL("e", RISCVCPU, cfg.ext_e, false),
59
diff --git a/target/riscv/machine.c b/target/riscv/machine.c
71
new file mode 100644
60
new file mode 100644
72
index XXXXXXX..XXXXXXX
61
index XXXXXXX..XXXXXXX
73
--- /dev/null
62
--- /dev/null
74
+++ b/target/riscv/th_csr.c
63
+++ b/target/riscv/machine.c
75
@@ -XXX,XX +XXX,XX @@
64
@@ -XXX,XX +XXX,XX @@
76
+/*
65
+/*
77
+ * T-Head-specific CSRs.
66
+ * RISC-V VMState Description
78
+ *
67
+ *
79
+ * Copyright (c) 2024 VRULL GmbH
68
+ * Copyright (c) 2020 Huawei Technologies Co., Ltd
80
+ *
69
+ *
81
+ * This program is free software; you can redistribute it and/or modify it
70
+ * This program is free software; you can redistribute it and/or modify it
82
+ * under the terms and conditions of the GNU General Public License,
71
+ * under the terms and conditions of the GNU General Public License,
83
+ * version 2 or later, as published by the Free Software Foundation.
72
+ * version 2 or later, as published by the Free Software Foundation.
84
+ *
73
+ *
...
...
91
+ * this program. If not, see <http://www.gnu.org/licenses/>.
80
+ * this program. If not, see <http://www.gnu.org/licenses/>.
92
+ */
81
+ */
93
+
82
+
94
+#include "qemu/osdep.h"
83
+#include "qemu/osdep.h"
95
+#include "cpu.h"
84
+#include "cpu.h"
96
+#include "cpu_vendorid.h"
85
+#include "qemu/error-report.h"
86
+#include "sysemu/kvm.h"
87
+#include "migration/cpu.h"
97
+
88
+
98
+#define CSR_TH_SXSTATUS 0x5c0
89
+const VMStateDescription vmstate_riscv_cpu = {
90
+ .name = "cpu",
91
+ .version_id = 1,
92
+ .minimum_version_id = 1,
93
+ .fields = (VMStateField[]) {
94
+ VMSTATE_UINTTL_ARRAY(env.gpr, RISCVCPU, 32),
95
+ VMSTATE_UINT64_ARRAY(env.fpr, RISCVCPU, 32),
96
+ VMSTATE_UINTTL(env.pc, RISCVCPU),
97
+ VMSTATE_UINTTL(env.load_res, RISCVCPU),
98
+ VMSTATE_UINTTL(env.load_val, RISCVCPU),
99
+ VMSTATE_UINTTL(env.frm, RISCVCPU),
100
+ VMSTATE_UINTTL(env.badaddr, RISCVCPU),
101
+ VMSTATE_UINTTL(env.guest_phys_fault_addr, RISCVCPU),
102
+ VMSTATE_UINTTL(env.priv_ver, RISCVCPU),
103
+ VMSTATE_UINTTL(env.vext_ver, RISCVCPU),
104
+ VMSTATE_UINTTL(env.misa, RISCVCPU),
105
+ VMSTATE_UINTTL(env.misa_mask, RISCVCPU),
106
+ VMSTATE_UINT32(env.features, RISCVCPU),
107
+ VMSTATE_UINTTL(env.priv, RISCVCPU),
108
+ VMSTATE_UINTTL(env.virt, RISCVCPU),
109
+ VMSTATE_UINTTL(env.resetvec, RISCVCPU),
110
+ VMSTATE_UINTTL(env.mhartid, RISCVCPU),
111
+ VMSTATE_UINT64(env.mstatus, RISCVCPU),
112
+ VMSTATE_UINTTL(env.mip, RISCVCPU),
113
+ VMSTATE_UINT32(env.miclaim, RISCVCPU),
114
+ VMSTATE_UINTTL(env.mie, RISCVCPU),
115
+ VMSTATE_UINTTL(env.mideleg, RISCVCPU),
116
+ VMSTATE_UINTTL(env.sptbr, RISCVCPU),
117
+ VMSTATE_UINTTL(env.satp, RISCVCPU),
118
+ VMSTATE_UINTTL(env.sbadaddr, RISCVCPU),
119
+ VMSTATE_UINTTL(env.mbadaddr, RISCVCPU),
120
+ VMSTATE_UINTTL(env.medeleg, RISCVCPU),
121
+ VMSTATE_UINTTL(env.stvec, RISCVCPU),
122
+ VMSTATE_UINTTL(env.sepc, RISCVCPU),
123
+ VMSTATE_UINTTL(env.scause, RISCVCPU),
124
+ VMSTATE_UINTTL(env.mtvec, RISCVCPU),
125
+ VMSTATE_UINTTL(env.mepc, RISCVCPU),
126
+ VMSTATE_UINTTL(env.mcause, RISCVCPU),
127
+ VMSTATE_UINTTL(env.mtval, RISCVCPU),
128
+ VMSTATE_UINTTL(env.scounteren, RISCVCPU),
129
+ VMSTATE_UINTTL(env.mcounteren, RISCVCPU),
130
+ VMSTATE_UINTTL(env.sscratch, RISCVCPU),
131
+ VMSTATE_UINTTL(env.mscratch, RISCVCPU),
132
+ VMSTATE_UINT64(env.mfromhost, RISCVCPU),
133
+ VMSTATE_UINT64(env.mtohost, RISCVCPU),
134
+ VMSTATE_UINT64(env.timecmp, RISCVCPU),
99
+
135
+
100
+/* TH_SXSTATUS bits */
136
+ VMSTATE_END_OF_LIST()
101
+#define TH_SXSTATUS_UCME BIT(16)
102
+#define TH_SXSTATUS_MAEE BIT(21)
103
+#define TH_SXSTATUS_THEADISAEE BIT(22)
104
+
105
+typedef struct {
106
+ int csrno;
107
+ int (*insertion_test)(RISCVCPU *cpu);
108
+ riscv_csr_operations csr_ops;
109
+} riscv_csr;
110
+
111
+static RISCVException smode(CPURISCVState *env, int csrno)
112
+{
113
+ if (riscv_has_ext(env, RVS)) {
114
+ return RISCV_EXCP_NONE;
115
+ }
116
+
117
+ return RISCV_EXCP_ILLEGAL_INST;
118
+}
119
+
120
+static int test_thead_mvendorid(RISCVCPU *cpu)
121
+{
122
+ if (cpu->cfg.mvendorid != THEAD_VENDOR_ID) {
123
+ return -1;
124
+ }
125
+
126
+ return 0;
127
+}
128
+
129
+static RISCVException read_th_sxstatus(CPURISCVState *env, int csrno,
130
+ target_ulong *val)
131
+{
132
+ /* We don't set MAEE here, because QEMU does not implement MAEE. */
133
+ *val = TH_SXSTATUS_UCME | TH_SXSTATUS_THEADISAEE;
134
+ return RISCV_EXCP_NONE;
135
+}
136
+
137
+static riscv_csr th_csr_list[] = {
138
+ {
139
+ .csrno = CSR_TH_SXSTATUS,
140
+ .insertion_test = test_thead_mvendorid,
141
+ .csr_ops = { "th.sxstatus", smode, read_th_sxstatus }
142
+ }
137
+ }
143
+};
138
+};
144
+
145
+void th_register_custom_csrs(RISCVCPU *cpu)
146
+{
147
+ for (size_t i = 0; i < ARRAY_SIZE(th_csr_list); i++) {
148
+ int csrno = th_csr_list[i].csrno;
149
+ riscv_csr_operations *csr_ops = &th_csr_list[i].csr_ops;
150
+ if (!th_csr_list[i].insertion_test(cpu)) {
151
+ riscv_set_csr_ops(csrno, csr_ops);
152
+ }
153
+ }
154
+}
155
diff --git a/target/riscv/meson.build b/target/riscv/meson.build
139
diff --git a/target/riscv/meson.build b/target/riscv/meson.build
156
index XXXXXXX..XXXXXXX 100644
140
index XXXXXXX..XXXXXXX 100644
157
--- a/target/riscv/meson.build
141
--- a/target/riscv/meson.build
158
+++ b/target/riscv/meson.build
142
+++ b/target/riscv/meson.build
159
@@ -XXX,XX +XXX,XX @@ riscv_system_ss.add(files(
143
@@ -XXX,XX +XXX,XX @@ riscv_ss.add(files(
160
'monitor.c',
144
riscv_softmmu_ss = ss.source_set()
161
'machine.c',
145
riscv_softmmu_ss.add(files(
162
'pmu.c',
146
'pmp.c',
163
+ 'th_csr.c',
147
- 'monitor.c'
164
'time_helper.c',
148
+ 'monitor.c',
165
'riscv-qmp-cmds.c',
149
+ 'machine.c'
166
))
150
))
151
152
target_arch += {'riscv': riscv_ss}
167
--
153
--
168
2.45.1
154
2.28.0
169
155
170
156
diff view generated by jsdifflib
1
From: Andrew Jones <ajones@ventanamicro.com>
1
From: Yifei Jiang <jiangyifei@huawei.com>
2
2
3
Implementing wrs.nto to always just return is consistent with the
3
In the case of supporting PMP feature, add PMP state description
4
specification, as the instruction is permitted to terminate the
4
to vmstate_riscv_cpu.
5
stall for any reason, but it's not useful for virtualization, where
6
we'd like the guest to trap to the hypervisor in order to allow
7
scheduling of the lock holding VCPU. Change to always immediately
8
raise exceptions when the appropriate conditions are present,
9
otherwise continue to just return. Note, immediately raising
10
exceptions is also consistent with the specification since the
11
time limit that should expire prior to the exception is
12
implementation-specific.
13
5
14
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
6
'vmstate_pmp_addr' and 'num_rules' could be regenerated by
15
Reviewed-by: Christoph Müllner <christoph.muellner@vrull.eu>
7
pmp_update_rule(). But there exists the problem of updating
16
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
8
num_rules repeatedly in pmp_update_rule(). So here extracts
9
pmp_update_rule_addr() and pmp_update_rule_nums() to update
10
'vmstate_pmp_addr' and 'num_rules' respectively.
11
12
Signed-off-by: Yifei Jiang <jiangyifei@huawei.com>
13
Signed-off-by: Yipeng Yin <yinyipeng1@huawei.com>
17
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
14
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
18
Message-ID: <20240424142808.62936-2-ajones@ventanamicro.com>
15
Message-id: 20201026115530.304-4-jiangyifei@huawei.com
19
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
16
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
20
---
17
---
21
target/riscv/helper.h | 1 +
18
target/riscv/pmp.h | 2 ++
22
target/riscv/op_helper.c | 11 ++++++++
19
target/riscv/machine.c | 50 ++++++++++++++++++++++++++++++++++++++++++
23
target/riscv/insn_trans/trans_rvzawrs.c.inc | 29 ++++++++++++++-------
20
target/riscv/pmp.c | 29 ++++++++++++++----------
24
3 files changed, 32 insertions(+), 9 deletions(-)
21
3 files changed, 70 insertions(+), 11 deletions(-)
25
22
26
diff --git a/target/riscv/helper.h b/target/riscv/helper.h
23
diff --git a/target/riscv/pmp.h b/target/riscv/pmp.h
27
index XXXXXXX..XXXXXXX 100644
24
index XXXXXXX..XXXXXXX 100644
28
--- a/target/riscv/helper.h
25
--- a/target/riscv/pmp.h
29
+++ b/target/riscv/helper.h
26
+++ b/target/riscv/pmp.h
30
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_6(csrrw_i128, tl, env, int, tl, tl, tl, tl)
27
@@ -XXX,XX +XXX,XX @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,
31
DEF_HELPER_1(sret, tl, env)
28
target_ulong size, pmp_priv_t priv, target_ulong mode);
32
DEF_HELPER_1(mret, tl, env)
29
bool pmp_is_range_in_tlb(CPURISCVState *env, hwaddr tlb_sa,
33
DEF_HELPER_1(wfi, void, env)
30
target_ulong *tlb_size);
34
+DEF_HELPER_1(wrs_nto, void, env)
31
+void pmp_update_rule_addr(CPURISCVState *env, uint32_t pmp_index);
35
DEF_HELPER_1(tlb_flush, void, env)
32
+void pmp_update_rule_nums(CPURISCVState *env);
36
DEF_HELPER_1(tlb_flush_all, void, env)
33
37
/* Native Debug */
34
#endif
38
diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
35
diff --git a/target/riscv/machine.c b/target/riscv/machine.c
39
index XXXXXXX..XXXXXXX 100644
36
index XXXXXXX..XXXXXXX 100644
40
--- a/target/riscv/op_helper.c
37
--- a/target/riscv/machine.c
41
+++ b/target/riscv/op_helper.c
38
+++ b/target/riscv/machine.c
42
@@ -XXX,XX +XXX,XX @@ void helper_wfi(CPURISCVState *env)
39
@@ -XXX,XX +XXX,XX @@
40
#include "sysemu/kvm.h"
41
#include "migration/cpu.h"
42
43
+static bool pmp_needed(void *opaque)
44
+{
45
+ RISCVCPU *cpu = opaque;
46
+ CPURISCVState *env = &cpu->env;
47
+
48
+ return riscv_feature(env, RISCV_FEATURE_PMP);
49
+}
50
+
51
+static int pmp_post_load(void *opaque, int version_id)
52
+{
53
+ RISCVCPU *cpu = opaque;
54
+ CPURISCVState *env = &cpu->env;
55
+ int i;
56
+
57
+ for (i = 0; i < MAX_RISCV_PMPS; i++) {
58
+ pmp_update_rule_addr(env, i);
59
+ }
60
+ pmp_update_rule_nums(env);
61
+
62
+ return 0;
63
+}
64
+
65
+static const VMStateDescription vmstate_pmp_entry = {
66
+ .name = "cpu/pmp/entry",
67
+ .version_id = 1,
68
+ .minimum_version_id = 1,
69
+ .fields = (VMStateField[]) {
70
+ VMSTATE_UINTTL(addr_reg, pmp_entry_t),
71
+ VMSTATE_UINT8(cfg_reg, pmp_entry_t),
72
+ VMSTATE_END_OF_LIST()
73
+ }
74
+};
75
+
76
+static const VMStateDescription vmstate_pmp = {
77
+ .name = "cpu/pmp",
78
+ .version_id = 1,
79
+ .minimum_version_id = 1,
80
+ .needed = pmp_needed,
81
+ .post_load = pmp_post_load,
82
+ .fields = (VMStateField[]) {
83
+ VMSTATE_STRUCT_ARRAY(env.pmp_state.pmp, RISCVCPU, MAX_RISCV_PMPS,
84
+ 0, vmstate_pmp_entry, pmp_entry_t),
85
+ VMSTATE_END_OF_LIST()
86
+ }
87
+};
88
+
89
const VMStateDescription vmstate_riscv_cpu = {
90
.name = "cpu",
91
.version_id = 1,
92
@@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_riscv_cpu = {
93
VMSTATE_UINT64(env.timecmp, RISCVCPU),
94
95
VMSTATE_END_OF_LIST()
96
+ },
97
+ .subsections = (const VMStateDescription * []) {
98
+ &vmstate_pmp,
99
+ NULL
100
}
101
};
102
diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
103
index XXXXXXX..XXXXXXX 100644
104
--- a/target/riscv/pmp.c
105
+++ b/target/riscv/pmp.c
106
@@ -XXX,XX +XXX,XX @@ static void pmp_decode_napot(target_ulong a, target_ulong *sa, target_ulong *ea)
43
}
107
}
44
}
108
}
45
109
46
+void helper_wrs_nto(CPURISCVState *env)
110
-
111
-/* Convert cfg/addr reg values here into simple 'sa' --> start address and 'ea'
112
- * end address values.
113
- * This function is called relatively infrequently whereas the check that
114
- * an address is within a pmp rule is called often, so optimise that one
115
- */
116
-static void pmp_update_rule(CPURISCVState *env, uint32_t pmp_index)
117
+void pmp_update_rule_addr(CPURISCVState *env, uint32_t pmp_index)
118
{
119
- int i;
120
-
121
- env->pmp_state.num_rules = 0;
122
-
123
uint8_t this_cfg = env->pmp_state.pmp[pmp_index].cfg_reg;
124
target_ulong this_addr = env->pmp_state.pmp[pmp_index].addr_reg;
125
target_ulong prev_addr = 0u;
126
@@ -XXX,XX +XXX,XX @@ static void pmp_update_rule(CPURISCVState *env, uint32_t pmp_index)
127
128
env->pmp_state.addr[pmp_index].sa = sa;
129
env->pmp_state.addr[pmp_index].ea = ea;
130
+}
131
132
+void pmp_update_rule_nums(CPURISCVState *env)
47
+{
133
+{
48
+ if (env->virt_enabled && (env->priv == PRV_S || env->priv == PRV_U) &&
134
+ int i;
49
+ get_field(env->hstatus, HSTATUS_VTW) &&
135
+
50
+ !get_field(env->mstatus, MSTATUS_TW)) {
136
+ env->pmp_state.num_rules = 0;
51
+ riscv_raise_exception(env, RISCV_EXCP_VIRT_INSTRUCTION_FAULT, GETPC());
137
for (i = 0; i < MAX_RISCV_PMPS; i++) {
52
+ } else if (env->priv != PRV_M && get_field(env->mstatus, MSTATUS_TW)) {
138
const uint8_t a_field =
53
+ riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC());
139
pmp_get_a_field(env->pmp_state.pmp[i].cfg_reg);
54
+ }
140
@@ -XXX,XX +XXX,XX @@ static void pmp_update_rule(CPURISCVState *env, uint32_t pmp_index)
141
}
142
}
143
144
+/* Convert cfg/addr reg values here into simple 'sa' --> start address and 'ea'
145
+ * end address values.
146
+ * This function is called relatively infrequently whereas the check that
147
+ * an address is within a pmp rule is called often, so optimise that one
148
+ */
149
+static void pmp_update_rule(CPURISCVState *env, uint32_t pmp_index)
150
+{
151
+ pmp_update_rule_addr(env, pmp_index);
152
+ pmp_update_rule_nums(env);
55
+}
153
+}
56
+
154
+
57
void helper_tlb_flush(CPURISCVState *env)
155
static int pmp_is_in_range(CPURISCVState *env, int pmp_index, target_ulong addr)
58
{
156
{
59
CPUState *cs = env_cpu(env);
157
int result = 0;
60
diff --git a/target/riscv/insn_trans/trans_rvzawrs.c.inc b/target/riscv/insn_trans/trans_rvzawrs.c.inc
61
index XXXXXXX..XXXXXXX 100644
62
--- a/target/riscv/insn_trans/trans_rvzawrs.c.inc
63
+++ b/target/riscv/insn_trans/trans_rvzawrs.c.inc
64
@@ -XXX,XX +XXX,XX @@
65
* this program. If not, see <http://www.gnu.org/licenses/>.
66
*/
67
68
-static bool trans_wrs(DisasContext *ctx)
69
+static bool trans_wrs_sto(DisasContext *ctx, arg_wrs_sto *a)
70
{
71
if (!ctx->cfg_ptr->ext_zawrs) {
72
return false;
73
@@ -XXX,XX +XXX,XX @@ static bool trans_wrs(DisasContext *ctx)
74
return true;
75
}
76
77
-#define GEN_TRANS_WRS(insn) \
78
-static bool trans_ ## insn(DisasContext *ctx, arg_ ## insn *a) \
79
-{ \
80
- (void)a; \
81
- return trans_wrs(ctx); \
82
-}
83
+static bool trans_wrs_nto(DisasContext *ctx, arg_wrs_nto *a)
84
+{
85
+ if (!ctx->cfg_ptr->ext_zawrs) {
86
+ return false;
87
+ }
88
89
-GEN_TRANS_WRS(wrs_nto)
90
-GEN_TRANS_WRS(wrs_sto)
91
+ /*
92
+ * Depending on the mode of execution, mstatus.TW and hstatus.VTW, wrs.nto
93
+ * should raise an exception when the implementation-specific bounded time
94
+ * limit has expired. Our time limit is zero, so we either return
95
+ * immediately, as does our implementation of wrs.sto, or raise an
96
+ * exception, as handled by the wrs.nto helper.
97
+ */
98
+#ifndef CONFIG_USER_ONLY
99
+ gen_helper_wrs_nto(tcg_env);
100
+#endif
101
+
102
+ /* We only get here when helper_wrs_nto() doesn't raise an exception. */
103
+ return trans_wrs_sto(ctx, NULL);
104
+}
105
--
158
--
106
2.45.1
159
2.28.0
107
160
108
161
diff view generated by jsdifflib
1
From: Rob Bradford <rbradford@rivosinc.com>
1
From: Yifei Jiang <jiangyifei@huawei.com>
2
2
3
This extension has now been ratified:
3
In the case of supporting H extension, add H extension description
4
https://jira.riscv.org/browse/RVS-2006 so the "x-" prefix can be
4
to vmstate_riscv_cpu.
5
removed.
6
5
7
Since this is now a ratified extension add it to the list of extensions
6
Signed-off-by: Yifei Jiang <jiangyifei@huawei.com>
8
included in the "max" CPU variant.
7
Signed-off-by: Yipeng Yin <yinyipeng1@huawei.com>
9
10
Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
11
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
12
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
13
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Message-id: 20201026115530.304-5-jiangyifei@huawei.com
14
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
15
Message-ID: <20240514110217.22516-1-rbradford@rivosinc.com>
16
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
17
---
11
---
18
target/riscv/cpu.c | 2 +-
12
target/riscv/machine.c | 47 ++++++++++++++++++++++++++++++++++++++++++
19
target/riscv/tcg/tcg-cpu.c | 2 +-
13
1 file changed, 47 insertions(+)
20
2 files changed, 2 insertions(+), 2 deletions(-)
21
14
22
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
15
diff --git a/target/riscv/machine.c b/target/riscv/machine.c
23
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
24
--- a/target/riscv/cpu.c
17
--- a/target/riscv/machine.c
25
+++ b/target/riscv/cpu.c
18
+++ b/target/riscv/machine.c
26
@@ -XXX,XX +XXX,XX @@ static const MISAExtInfo misa_ext_info_arr[] = {
19
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_pmp = {
27
MISA_EXT_INFO(RVJ, "x-j", "Dynamic translated languages"),
20
}
28
MISA_EXT_INFO(RVV, "v", "Vector operations"),
29
MISA_EXT_INFO(RVG, "g", "General purpose (IMAFD_Zicsr_Zifencei)"),
30
- MISA_EXT_INFO(RVB, "x-b", "Bit manipulation (Zba_Zbb_Zbs)")
31
+ MISA_EXT_INFO(RVB, "b", "Bit manipulation (Zba_Zbb_Zbs)")
32
};
21
};
33
22
34
static void riscv_cpu_validate_misa_mxl(RISCVCPUClass *mcc)
23
+static bool hyper_needed(void *opaque)
35
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
24
+{
36
index XXXXXXX..XXXXXXX 100644
25
+ RISCVCPU *cpu = opaque;
37
--- a/target/riscv/tcg/tcg-cpu.c
26
+ CPURISCVState *env = &cpu->env;
38
+++ b/target/riscv/tcg/tcg-cpu.c
27
+
39
@@ -XXX,XX +XXX,XX @@ static void riscv_init_max_cpu_extensions(Object *obj)
28
+ return riscv_has_ext(env, RVH);
40
const RISCVCPUMultiExtConfig *prop;
29
+}
41
30
+
42
/* Enable RVG, RVJ and RVV that are disabled by default */
31
+static const VMStateDescription vmstate_hyper = {
43
- riscv_cpu_set_misa_ext(env, env->misa_ext | RVG | RVJ | RVV);
32
+ .name = "cpu/hyper",
44
+ riscv_cpu_set_misa_ext(env, env->misa_ext | RVB | RVG | RVJ | RVV);
33
+ .version_id = 1,
45
34
+ .minimum_version_id = 1,
46
for (prop = riscv_cpu_extensions; prop && prop->name; prop++) {
35
+ .needed = hyper_needed,
47
isa_ext_update_enabled(cpu, prop->offset, true);
36
+ .fields = (VMStateField[]) {
37
+ VMSTATE_UINTTL(env.hstatus, RISCVCPU),
38
+ VMSTATE_UINTTL(env.hedeleg, RISCVCPU),
39
+ VMSTATE_UINTTL(env.hideleg, RISCVCPU),
40
+ VMSTATE_UINTTL(env.hcounteren, RISCVCPU),
41
+ VMSTATE_UINTTL(env.htval, RISCVCPU),
42
+ VMSTATE_UINTTL(env.htinst, RISCVCPU),
43
+ VMSTATE_UINTTL(env.hgatp, RISCVCPU),
44
+ VMSTATE_UINT64(env.htimedelta, RISCVCPU),
45
+
46
+ VMSTATE_UINT64(env.vsstatus, RISCVCPU),
47
+ VMSTATE_UINTTL(env.vstvec, RISCVCPU),
48
+ VMSTATE_UINTTL(env.vsscratch, RISCVCPU),
49
+ VMSTATE_UINTTL(env.vsepc, RISCVCPU),
50
+ VMSTATE_UINTTL(env.vscause, RISCVCPU),
51
+ VMSTATE_UINTTL(env.vstval, RISCVCPU),
52
+ VMSTATE_UINTTL(env.vsatp, RISCVCPU),
53
+
54
+ VMSTATE_UINTTL(env.mtval2, RISCVCPU),
55
+ VMSTATE_UINTTL(env.mtinst, RISCVCPU),
56
+
57
+ VMSTATE_UINTTL(env.stvec_hs, RISCVCPU),
58
+ VMSTATE_UINTTL(env.sscratch_hs, RISCVCPU),
59
+ VMSTATE_UINTTL(env.sepc_hs, RISCVCPU),
60
+ VMSTATE_UINTTL(env.scause_hs, RISCVCPU),
61
+ VMSTATE_UINTTL(env.stval_hs, RISCVCPU),
62
+ VMSTATE_UINTTL(env.satp_hs, RISCVCPU),
63
+ VMSTATE_UINT64(env.mstatus_hs, RISCVCPU),
64
+
65
+ VMSTATE_END_OF_LIST()
66
+ }
67
+};
68
+
69
const VMStateDescription vmstate_riscv_cpu = {
70
.name = "cpu",
71
.version_id = 1,
72
@@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_riscv_cpu = {
73
},
74
.subsections = (const VMStateDescription * []) {
75
&vmstate_pmp,
76
+ &vmstate_hyper,
77
NULL
78
}
79
};
48
--
80
--
49
2.45.1
81
2.28.0
82
83
diff view generated by jsdifflib
1
From: Max Chou <max.chou@sifive.com>
1
From: Yifei Jiang <jiangyifei@huawei.com>
2
2
3
According v spec 18.4, only the vfwcvt.f.f.v and vfncvt.f.f.w
3
In the case of supporting V extension, add V extension description
4
instructions will be affected by Zvfhmin extension.
4
to vmstate_riscv_cpu.
5
And the vfwcvt.f.f.v and vfncvt.f.f.w instructions only support the
6
conversions of
7
5
8
* From 1*SEW(16/32) to 2*SEW(32/64)
6
Signed-off-by: Yifei Jiang <jiangyifei@huawei.com>
9
* From 2*SEW(32/64) to 1*SEW(16/32)
7
Signed-off-by: Yipeng Yin <yinyipeng1@huawei.com>
10
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
11
Signed-off-by: Max Chou <max.chou@sifive.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
12
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
10
Message-id: 20201026115530.304-6-jiangyifei@huawei.com
13
Cc: qemu-stable <qemu-stable@nongnu.org>
14
Message-ID: <20240322092600.1198921-2-max.chou@sifive.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
16
---
12
---
17
target/riscv/insn_trans/trans_rvv.c.inc | 20 ++++++++++++++++++--
13
target/riscv/machine.c | 25 +++++++++++++++++++++++++
18
1 file changed, 18 insertions(+), 2 deletions(-)
14
1 file changed, 25 insertions(+)
19
15
20
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
16
diff --git a/target/riscv/machine.c b/target/riscv/machine.c
21
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
22
--- a/target/riscv/insn_trans/trans_rvv.c.inc
18
--- a/target/riscv/machine.c
23
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
19
+++ b/target/riscv/machine.c
24
@@ -XXX,XX +XXX,XX @@ static bool require_rvf(DisasContext *s)
20
@@ -XXX,XX +XXX,XX @@ static bool hyper_needed(void *opaque)
25
}
21
return riscv_has_ext(env, RVH);
26
}
22
}
27
23
28
+static bool require_rvfmin(DisasContext *s)
24
+static bool vector_needed(void *opaque)
29
+{
25
+{
30
+ if (s->mstatus_fs == EXT_STATUS_DISABLED) {
26
+ RISCVCPU *cpu = opaque;
31
+ return false;
27
+ CPURISCVState *env = &cpu->env;
32
+ }
33
+
28
+
34
+ switch (s->sew) {
29
+ return riscv_has_ext(env, RVV);
35
+ case MO_16:
36
+ return s->cfg_ptr->ext_zvfhmin;
37
+ case MO_32:
38
+ return s->cfg_ptr->ext_zve32f;
39
+ default:
40
+ return false;
41
+ }
42
+}
30
+}
43
+
31
+
44
static bool require_scale_rvf(DisasContext *s)
32
+static const VMStateDescription vmstate_vector = {
45
{
33
+ .name = "cpu/vector",
46
if (s->mstatus_fs == EXT_STATUS_DISABLED) {
34
+ .version_id = 1,
47
@@ -XXX,XX +XXX,XX @@ static bool require_scale_rvfmin(DisasContext *s)
35
+ .minimum_version_id = 1,
36
+ .needed = vector_needed,
37
+ .fields = (VMStateField[]) {
38
+ VMSTATE_UINT64_ARRAY(env.vreg, RISCVCPU, 32 * RV_VLEN_MAX / 64),
39
+ VMSTATE_UINTTL(env.vxrm, RISCVCPU),
40
+ VMSTATE_UINTTL(env.vxsat, RISCVCPU),
41
+ VMSTATE_UINTTL(env.vl, RISCVCPU),
42
+ VMSTATE_UINTTL(env.vstart, RISCVCPU),
43
+ VMSTATE_UINTTL(env.vtype, RISCVCPU),
44
+ VMSTATE_END_OF_LIST()
45
+ }
46
+};
47
+
48
static const VMStateDescription vmstate_hyper = {
49
.name = "cpu/hyper",
50
.version_id = 1,
51
@@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_riscv_cpu = {
52
.subsections = (const VMStateDescription * []) {
53
&vmstate_pmp,
54
&vmstate_hyper,
55
+ &vmstate_vector,
56
NULL
48
}
57
}
49
58
};
50
switch (s->sew) {
51
- case MO_8:
52
- return s->cfg_ptr->ext_zvfhmin;
53
case MO_16:
54
return s->cfg_ptr->ext_zve32f;
55
case MO_32:
56
@@ -XXX,XX +XXX,XX @@ static bool opxfv_widen_check(DisasContext *s, arg_rmr *a)
57
static bool opffv_widen_check(DisasContext *s, arg_rmr *a)
58
{
59
return opfv_widen_check(s, a) &&
60
+ require_rvfmin(s) &&
61
require_scale_rvfmin(s) &&
62
(s->sew != MO_8);
63
}
64
@@ -XXX,XX +XXX,XX @@ static bool opfxv_narrow_check(DisasContext *s, arg_rmr *a)
65
static bool opffv_narrow_check(DisasContext *s, arg_rmr *a)
66
{
67
return opfv_narrow_check(s, a) &&
68
+ require_rvfmin(s) &&
69
require_scale_rvfmin(s) &&
70
(s->sew != MO_8);
71
}
72
--
59
--
73
2.45.1
60
2.28.0
61
62
diff view generated by jsdifflib
1
From: Huang Tao <eric.huang@linux.alibaba.com>
1
From: Yifei Jiang <jiangyifei@huawei.com>
2
2
3
In this patch, we modify the decoder to be a freely composable data
3
Add sifive_plic vmstate for supporting sifive_plic migration.
4
structure instead of a hardcoded one. It can be dynamically builded up
4
Current vmstate framework only supports one structure parameter
5
according to the extensions.
5
as num field to describe variable length arrays, so introduce
6
This approach has several benefits:
6
num_enables.
7
1. Provides support for heterogeneous cpu architectures. As we add decoder in
8
RISCVCPU, each cpu can have their own decoder, and the decoders can be
9
different due to cpu's features.
10
2. Improve the decoding efficiency. We run the guard_func to see if the decoder
11
can be added to the dynamic_decoder when building up the decoder. Therefore,
12
there is no need to run the guard_func when decoding each instruction. It can
13
improve the decoding efficiency
14
3. For vendor or dynamic cpus, it allows them to customize their own decoder
15
functions to improve decoding efficiency, especially when vendor-defined
16
instruction sets increase. Because of dynamic building up, it can skip the other
17
decoder guard functions when decoding.
18
4. Pre patch for allowing adding a vendor decoder before decode_insn32() with minimal
19
overhead for users that don't need this particular vendor decoder.
20
7
21
Signed-off-by: Huang Tao <eric.huang@linux.alibaba.com>
8
Signed-off-by: Yifei Jiang <jiangyifei@huawei.com>
22
Suggested-by: Christoph Muellner <christoph.muellner@vrull.eu>
9
Signed-off-by: Yipeng Yin <yinyipeng1@huawei.com>
23
Co-authored-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
24
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
25
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
26
Message-ID: <20240506023607.29544-1-eric.huang@linux.alibaba.com>
11
Message-id: 20201026115530.304-7-jiangyifei@huawei.com
27
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
28
---
13
---
29
target/riscv/cpu.h | 1 +
14
include/hw/intc/sifive_plic.h | 1 +
30
target/riscv/tcg/tcg-cpu.h | 15 +++++++++++++++
15
hw/intc/sifive_plic.c | 26 +++++++++++++++++++++++++-
31
target/riscv/cpu.c | 1 +
16
2 files changed, 26 insertions(+), 1 deletion(-)
32
target/riscv/tcg/tcg-cpu.c | 15 +++++++++++++++
33
target/riscv/translate.c | 31 +++++++++++++++----------------
34
5 files changed, 47 insertions(+), 16 deletions(-)
35
17
36
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
18
diff --git a/include/hw/intc/sifive_plic.h b/include/hw/intc/sifive_plic.h
37
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
38
--- a/target/riscv/cpu.h
20
--- a/include/hw/intc/sifive_plic.h
39
+++ b/target/riscv/cpu.h
21
+++ b/include/hw/intc/sifive_plic.h
40
@@ -XXX,XX +XXX,XX @@ struct ArchCPU {
22
@@ -XXX,XX +XXX,XX @@ struct SiFivePLICState {
41
uint32_t pmu_avail_ctrs;
23
uint32_t num_addrs;
42
/* Mapping of events to counters */
24
uint32_t num_harts;
43
GHashTable *pmu_event_ctr_map;
25
uint32_t bitfield_words;
44
+ const GPtrArray *decoders;
26
+ uint32_t num_enables;
45
};
27
PLICAddr *addr_config;
46
28
uint32_t *source_priority;
47
/**
29
uint32_t *target_priority;
48
diff --git a/target/riscv/tcg/tcg-cpu.h b/target/riscv/tcg/tcg-cpu.h
30
diff --git a/hw/intc/sifive_plic.c b/hw/intc/sifive_plic.c
49
index XXXXXXX..XXXXXXX 100644
31
index XXXXXXX..XXXXXXX 100644
50
--- a/target/riscv/tcg/tcg-cpu.h
32
--- a/hw/intc/sifive_plic.c
51
+++ b/target/riscv/tcg/tcg-cpu.h
33
+++ b/hw/intc/sifive_plic.c
52
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp);
34
@@ -XXX,XX +XXX,XX @@
53
void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp);
35
#include "hw/intc/sifive_plic.h"
54
bool riscv_cpu_tcg_compatible(RISCVCPU *cpu);
36
#include "target/riscv/cpu.h"
55
37
#include "sysemu/sysemu.h"
56
+struct DisasContext;
38
+#include "migration/vmstate.h"
57
+struct RISCVCPUConfig;
39
58
+typedef struct RISCVDecoder {
40
#define RISCV_DEBUG_PLIC 0
59
+ bool (*guard_func)(const struct RISCVCPUConfig *);
41
60
+ bool (*riscv_cpu_decode_fn)(struct DisasContext *, uint32_t);
42
@@ -XXX,XX +XXX,XX @@ static void sifive_plic_realize(DeviceState *dev, Error **errp)
61
+} RISCVDecoder;
43
TYPE_SIFIVE_PLIC, plic->aperture_size);
62
+
44
parse_hart_config(plic);
63
+typedef bool (*riscv_cpu_decode_fn)(struct DisasContext *, uint32_t);
45
plic->bitfield_words = (plic->num_sources + 31) >> 5;
64
+
46
+ plic->num_enables = plic->bitfield_words * plic->num_addrs;
65
+extern const size_t decoder_table_size;
47
plic->source_priority = g_new0(uint32_t, plic->num_sources);
66
+
48
plic->target_priority = g_new(uint32_t, plic->num_addrs);
67
+extern const RISCVDecoder decoder_table[];
49
plic->pending = g_new0(uint32_t, plic->bitfield_words);
68
+
50
plic->claimed = g_new0(uint32_t, plic->bitfield_words);
69
+void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu);
51
- plic->enable = g_new0(uint32_t, plic->bitfield_words * plic->num_addrs);
70
+
52
+ plic->enable = g_new0(uint32_t, plic->num_enables);
71
#endif
53
sysbus_init_mmio(SYS_BUS_DEVICE(dev), &plic->mmio);
72
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
54
qdev_init_gpio_in(dev, sifive_plic_irq_request, plic->num_sources);
73
index XXXXXXX..XXXXXXX 100644
55
74
--- a/target/riscv/cpu.c
56
@@ -XXX,XX +XXX,XX @@ static void sifive_plic_realize(DeviceState *dev, Error **errp)
75
+++ b/target/riscv/cpu.c
57
msi_nonbroken = true;
76
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
77
error_propagate(errp, local_err);
78
return;
79
}
80
+ riscv_tcg_cpu_finalize_dynamic_decoder(cpu);
81
} else if (kvm_enabled()) {
82
riscv_kvm_cpu_finalize_features(cpu, &local_err);
83
if (local_err != NULL) {
84
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
85
index XXXXXXX..XXXXXXX 100644
86
--- a/target/riscv/tcg/tcg-cpu.c
87
+++ b/target/riscv/tcg/tcg-cpu.c
88
@@ -XXX,XX +XXX,XX @@ void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
89
}
90
}
58
}
91
59
92
+void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu)
60
+static const VMStateDescription vmstate_sifive_plic = {
93
+{
61
+ .name = "riscv_sifive_plic",
94
+ GPtrArray *dynamic_decoders;
62
+ .version_id = 1,
95
+ dynamic_decoders = g_ptr_array_sized_new(decoder_table_size);
63
+ .minimum_version_id = 1,
96
+ for (size_t i = 0; i < decoder_table_size; ++i) {
64
+ .fields = (VMStateField[]) {
97
+ if (decoder_table[i].guard_func &&
65
+ VMSTATE_VARRAY_UINT32(source_priority, SiFivePLICState,
98
+ decoder_table[i].guard_func(&cpu->cfg)) {
66
+ num_sources, 0,
99
+ g_ptr_array_add(dynamic_decoders,
67
+ vmstate_info_uint32, uint32_t),
100
+ (gpointer)decoder_table[i].riscv_cpu_decode_fn);
68
+ VMSTATE_VARRAY_UINT32(target_priority, SiFivePLICState,
69
+ num_addrs, 0,
70
+ vmstate_info_uint32, uint32_t),
71
+ VMSTATE_VARRAY_UINT32(pending, SiFivePLICState, bitfield_words, 0,
72
+ vmstate_info_uint32, uint32_t),
73
+ VMSTATE_VARRAY_UINT32(claimed, SiFivePLICState, bitfield_words, 0,
74
+ vmstate_info_uint32, uint32_t),
75
+ VMSTATE_VARRAY_UINT32(enable, SiFivePLICState, num_enables, 0,
76
+ vmstate_info_uint32, uint32_t),
77
+ VMSTATE_END_OF_LIST()
101
+ }
78
+ }
102
+ }
103
+
104
+ cpu->decoders = dynamic_decoders;
105
+}
106
+
107
bool riscv_cpu_tcg_compatible(RISCVCPU *cpu)
108
{
109
return object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_CPU_HOST) == NULL;
110
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
111
index XXXXXXX..XXXXXXX 100644
112
--- a/target/riscv/translate.c
113
+++ b/target/riscv/translate.c
114
@@ -XXX,XX +XXX,XX @@
115
#include "exec/helper-info.c.inc"
116
#undef HELPER_H
117
118
+#include "tcg/tcg-cpu.h"
119
+
120
/* global register indices */
121
static TCGv cpu_gpr[32], cpu_gprh[32], cpu_pc, cpu_vl, cpu_vstart;
122
static TCGv_i64 cpu_fpr[32]; /* assume F and D extensions */
123
@@ -XXX,XX +XXX,XX @@ typedef struct DisasContext {
124
/* FRM is known to contain a valid value. */
125
bool frm_valid;
126
bool insn_start_updated;
127
+ const GPtrArray *decoders;
128
} DisasContext;
129
130
static inline bool has_ext(DisasContext *ctx, uint32_t ext)
131
@@ -XXX,XX +XXX,XX @@ static inline int insn_len(uint16_t first_word)
132
return (first_word & 3) == 3 ? 4 : 2;
133
}
134
135
+const RISCVDecoder decoder_table[] = {
136
+ { always_true_p, decode_insn32 },
137
+ { has_xthead_p, decode_xthead},
138
+ { has_XVentanaCondOps_p, decode_XVentanaCodeOps},
139
+};
79
+};
140
+
80
+
141
+const size_t decoder_table_size = ARRAY_SIZE(decoder_table);
81
static void sifive_plic_class_init(ObjectClass *klass, void *data)
142
+
143
static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode)
144
{
82
{
145
- /*
83
DeviceClass *dc = DEVICE_CLASS(klass);
146
- * A table with predicate (i.e., guard) functions and decoder functions
84
147
- * that are tested in-order until a decoder matches onto the opcode.
85
device_class_set_props(dc, sifive_plic_properties);
148
- */
86
dc->realize = sifive_plic_realize;
149
- static const struct {
87
+ dc->vmsd = &vmstate_sifive_plic;
150
- bool (*guard_func)(const RISCVCPUConfig *);
151
- bool (*decode_func)(DisasContext *, uint32_t);
152
- } decoders[] = {
153
- { always_true_p, decode_insn32 },
154
- { has_xthead_p, decode_xthead },
155
- { has_XVentanaCondOps_p, decode_XVentanaCodeOps },
156
- };
157
-
158
ctx->virt_inst_excp = false;
159
ctx->cur_insn_len = insn_len(opcode);
160
/* Check for compressed insn */
161
@@ -XXX,XX +XXX,XX @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode)
162
ctx->base.pc_next + 2));
163
ctx->opcode = opcode32;
164
165
- for (size_t i = 0; i < ARRAY_SIZE(decoders); ++i) {
166
- if (decoders[i].guard_func(ctx->cfg_ptr) &&
167
- decoders[i].decode_func(ctx, opcode32)) {
168
+ for (guint i = 0; i < ctx->decoders->len; ++i) {
169
+ riscv_cpu_decode_fn func = g_ptr_array_index(ctx->decoders, i);
170
+ if (func(ctx, opcode32)) {
171
return;
172
}
173
}
174
@@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
175
ctx->itrigger = FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER);
176
ctx->zero = tcg_constant_tl(0);
177
ctx->virt_inst_excp = false;
178
+ ctx->decoders = cpu->decoders;
179
}
88
}
180
89
181
static void riscv_tr_tb_start(DisasContextBase *db, CPUState *cpu)
90
static const TypeInfo sifive_plic_info = {
182
--
91
--
183
2.45.1
92
2.28.0
93
94
diff view generated by jsdifflib
1
From: Alistair Francis <alistair23@gmail.com>
1
From: Bin Meng <bin.meng@windriver.com>
2
2
3
Previously we only listed a single pmpcfg CSR and the first 16 pmpaddr
3
It is not easy to find out the memory map for a specific component
4
CSRs. This patch fixes this to list all 16 pmpcfg and all 64 pmpaddr
4
in the PolarFire SoC as the information is scattered in different
5
CSRs are part of the disassembly.
5
documents. Add some comments so that people can know where to get
6
such information from the Microchip website.
6
7
7
Reported-by: Eric DeVolder <eric_devolder@yahoo.com>
8
Signed-off-by: Bin Meng <bin.meng@windriver.com>
8
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Fixes: ea10325917 ("RISC-V Disassembler")
10
Message-id: 1603863010-15807-2-git-send-email-bmeng.cn@gmail.com
10
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
11
Cc: qemu-stable <qemu-stable@nongnu.org>
12
Message-ID: <20240514051615.330979-1-alistair.francis@wdc.com>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
---
12
---
15
disas/riscv.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++-
13
hw/riscv/microchip_pfsoc.c | 18 ++++++++++++++++++
16
1 file changed, 64 insertions(+), 1 deletion(-)
14
1 file changed, 18 insertions(+)
17
15
18
diff --git a/disas/riscv.c b/disas/riscv.c
16
diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c
19
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
20
--- a/disas/riscv.c
18
--- a/hw/riscv/microchip_pfsoc.c
21
+++ b/disas/riscv.c
19
+++ b/hw/riscv/microchip_pfsoc.c
22
@@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno)
20
@@ -XXX,XX +XXX,XX @@
23
case 0x0383: return "mibound";
21
/* GEM version */
24
case 0x0384: return "mdbase";
22
#define GEM_REVISION 0x0107010c
25
case 0x0385: return "mdbound";
23
26
- case 0x03a0: return "pmpcfg3";
24
+/*
27
+ case 0x03a0: return "pmpcfg0";
25
+ * The complete description of the whole PolarFire SoC memory map is scattered
28
+ case 0x03a1: return "pmpcfg1";
26
+ * in different documents. There are several places to look at for memory maps:
29
+ case 0x03a2: return "pmpcfg2";
27
+ *
30
+ case 0x03a3: return "pmpcfg3";
28
+ * 1 Chapter 11 "MSS Memory Map", in the doc "UG0880: PolarFire SoC FPGA
31
+ case 0x03a4: return "pmpcfg4";
29
+ * Microprocessor Subsystem (MSS) User Guide", which can be downloaded from
32
+ case 0x03a5: return "pmpcfg5";
30
+ * https://www.microsemi.com/document-portal/doc_download/
33
+ case 0x03a6: return "pmpcfg6";
31
+ * 1244570-ug0880-polarfire-soc-fpga-microprocessor-subsystem-mss-user-guide,
34
+ case 0x03a7: return "pmpcfg7";
32
+ * describes the whole picture of the PolarFire SoC memory map.
35
+ case 0x03a8: return "pmpcfg8";
33
+ *
36
+ case 0x03a9: return "pmpcfg9";
34
+ * 2 A zip file for PolarFire soC memory map, which can be downloaded from
37
+ case 0x03aa: return "pmpcfg10";
35
+ * https://www.microsemi.com/document-portal/doc_download/
38
+ case 0x03ab: return "pmpcfg11";
36
+ * 1244581-polarfire-soc-register-map, contains the following 2 major parts:
39
+ case 0x03ac: return "pmpcfg12";
37
+ * - Register Map/PF_SoC_RegMap_V1_1/pfsoc_regmap.htm
40
+ case 0x03ad: return "pmpcfg13";
38
+ * describes the complete integrated peripherals memory map
41
+ case 0x03ae: return "pmpcfg14";
39
+ * - Register Map/PF_SoC_RegMap_V1_1/MPFS250T/mpfs250t_ioscb_memmap_dri.htm
42
+ case 0x03af: return "pmpcfg15";
40
+ * describes the complete IOSCB modules memory maps
43
case 0x03b0: return "pmpaddr0";
41
+ */
44
case 0x03b1: return "pmpaddr1";
42
static const struct MemmapEntry {
45
case 0x03b2: return "pmpaddr2";
43
hwaddr base;
46
@@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno)
44
hwaddr size;
47
case 0x03bd: return "pmpaddr13";
48
case 0x03be: return "pmpaddr14";
49
case 0x03bf: return "pmpaddr15";
50
+ case 0x03c0: return "pmpaddr16";
51
+ case 0x03c1: return "pmpaddr17";
52
+ case 0x03c2: return "pmpaddr18";
53
+ case 0x03c3: return "pmpaddr19";
54
+ case 0x03c4: return "pmpaddr20";
55
+ case 0x03c5: return "pmpaddr21";
56
+ case 0x03c6: return "pmpaddr22";
57
+ case 0x03c7: return "pmpaddr23";
58
+ case 0x03c8: return "pmpaddr24";
59
+ case 0x03c9: return "pmpaddr25";
60
+ case 0x03ca: return "pmpaddr26";
61
+ case 0x03cb: return "pmpaddr27";
62
+ case 0x03cc: return "pmpaddr28";
63
+ case 0x03cd: return "pmpaddr29";
64
+ case 0x03ce: return "pmpaddr30";
65
+ case 0x03cf: return "pmpaddr31";
66
+ case 0x03d0: return "pmpaddr32";
67
+ case 0x03d1: return "pmpaddr33";
68
+ case 0x03d2: return "pmpaddr34";
69
+ case 0x03d3: return "pmpaddr35";
70
+ case 0x03d4: return "pmpaddr36";
71
+ case 0x03d5: return "pmpaddr37";
72
+ case 0x03d6: return "pmpaddr38";
73
+ case 0x03d7: return "pmpaddr39";
74
+ case 0x03d8: return "pmpaddr40";
75
+ case 0x03d9: return "pmpaddr41";
76
+ case 0x03da: return "pmpaddr42";
77
+ case 0x03db: return "pmpaddr43";
78
+ case 0x03dc: return "pmpaddr44";
79
+ case 0x03dd: return "pmpaddr45";
80
+ case 0x03de: return "pmpaddr46";
81
+ case 0x03df: return "pmpaddr47";
82
+ case 0x03e0: return "pmpaddr48";
83
+ case 0x03e1: return "pmpaddr49";
84
+ case 0x03e2: return "pmpaddr50";
85
+ case 0x03e3: return "pmpaddr51";
86
+ case 0x03e4: return "pmpaddr52";
87
+ case 0x03e5: return "pmpaddr53";
88
+ case 0x03e6: return "pmpaddr54";
89
+ case 0x03e7: return "pmpaddr55";
90
+ case 0x03e8: return "pmpaddr56";
91
+ case 0x03e9: return "pmpaddr57";
92
+ case 0x03ea: return "pmpaddr58";
93
+ case 0x03eb: return "pmpaddr59";
94
+ case 0x03ec: return "pmpaddr60";
95
+ case 0x03ed: return "pmpaddr61";
96
+ case 0x03ee: return "pmpaddr62";
97
+ case 0x03ef: return "pmpaddr63";
98
case 0x0780: return "mtohost";
99
case 0x0781: return "mfromhost";
100
case 0x0782: return "mreset";
101
--
45
--
102
2.45.1
46
2.28.0
47
48
diff view generated by jsdifflib
1
From: Jason Chien <jason.chien@sifive.com>
1
From: Bin Meng <bin.meng@windriver.com>
2
2
3
Add support for Zve64x extension. Enabling Zve64f enables Zve64x and
3
The PolarFire SoC DDR Memory Controller mainly includes 2 modules,
4
enabling Zve64x enables Zve32x according to their dependency.
4
called SGMII PHY module and the CFG module, as documented in the
5
5
chipset datasheet.
6
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2107
6
7
Signed-off-by: Jason Chien <jason.chien@sifive.com>
7
This creates a single file that groups these 2 modules, providing
8
Reviewed-by: Frank Chang <frank.chang@sifive.com>
8
the minimum functionalities that make the HSS DDR initialization
9
Reviewed-by: Max Chou <max.chou@sifive.com>
9
codes happy.
10
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
10
11
Message-ID: <20240328022343.6871-3-jason.chien@sifive.com>
11
Signed-off-by: Bin Meng <bin.meng@windriver.com>
12
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
13
Message-id: 1603863010-15807-3-git-send-email-bmeng.cn@gmail.com
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
15
---
14
target/riscv/cpu_cfg.h | 1 +
16
include/hw/misc/mchp_pfsoc_dmc.h | 56 ++++++++
15
target/riscv/cpu.c | 2 ++
17
hw/misc/mchp_pfsoc_dmc.c | 216 +++++++++++++++++++++++++++++++
16
target/riscv/tcg/tcg-cpu.c | 17 +++++++++++------
18
MAINTAINERS | 2 +
17
3 files changed, 14 insertions(+), 6 deletions(-)
19
hw/misc/Kconfig | 3 +
18
20
hw/misc/meson.build | 1 +
19
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
21
5 files changed, 278 insertions(+)
22
create mode 100644 include/hw/misc/mchp_pfsoc_dmc.h
23
create mode 100644 hw/misc/mchp_pfsoc_dmc.c
24
25
diff --git a/include/hw/misc/mchp_pfsoc_dmc.h b/include/hw/misc/mchp_pfsoc_dmc.h
26
new file mode 100644
27
index XXXXXXX..XXXXXXX
28
--- /dev/null
29
+++ b/include/hw/misc/mchp_pfsoc_dmc.h
30
@@ -XXX,XX +XXX,XX @@
31
+/*
32
+ * Microchip PolarFire SoC DDR Memory Controller module emulation
33
+ *
34
+ * Copyright (c) 2020 Wind River Systems, Inc.
35
+ *
36
+ * Author:
37
+ * Bin Meng <bin.meng@windriver.com>
38
+ *
39
+ * This program is free software; you can redistribute it and/or
40
+ * modify it under the terms of the GNU General Public License as
41
+ * published by the Free Software Foundation; either version 2 or
42
+ * (at your option) version 3 of the License.
43
+ *
44
+ * This program is distributed in the hope that it will be useful,
45
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
46
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47
+ * GNU General Public License for more details.
48
+ *
49
+ * You should have received a copy of the GNU General Public License along
50
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
51
+ */
52
+
53
+#ifndef MCHP_PFSOC_DMC_H
54
+#define MCHP_PFSOC_DMC_H
55
+
56
+/* DDR SGMII PHY module */
57
+
58
+#define MCHP_PFSOC_DDR_SGMII_PHY_REG_SIZE 0x1000
59
+
60
+typedef struct MchpPfSoCDdrSgmiiPhyState {
61
+ SysBusDevice parent;
62
+ MemoryRegion sgmii_phy;
63
+} MchpPfSoCDdrSgmiiPhyState;
64
+
65
+#define TYPE_MCHP_PFSOC_DDR_SGMII_PHY "mchp.pfsoc.ddr_sgmii_phy"
66
+
67
+#define MCHP_PFSOC_DDR_SGMII_PHY(obj) \
68
+ OBJECT_CHECK(MchpPfSoCDdrSgmiiPhyState, (obj), \
69
+ TYPE_MCHP_PFSOC_DDR_SGMII_PHY)
70
+
71
+/* DDR CFG module */
72
+
73
+#define MCHP_PFSOC_DDR_CFG_REG_SIZE 0x40000
74
+
75
+typedef struct MchpPfSoCDdrCfgState {
76
+ SysBusDevice parent;
77
+ MemoryRegion cfg;
78
+} MchpPfSoCDdrCfgState;
79
+
80
+#define TYPE_MCHP_PFSOC_DDR_CFG "mchp.pfsoc.ddr_cfg"
81
+
82
+#define MCHP_PFSOC_DDR_CFG(obj) \
83
+ OBJECT_CHECK(MchpPfSoCDdrCfgState, (obj), \
84
+ TYPE_MCHP_PFSOC_DDR_CFG)
85
+
86
+#endif /* MCHP_PFSOC_DMC_H */
87
diff --git a/hw/misc/mchp_pfsoc_dmc.c b/hw/misc/mchp_pfsoc_dmc.c
88
new file mode 100644
89
index XXXXXXX..XXXXXXX
90
--- /dev/null
91
+++ b/hw/misc/mchp_pfsoc_dmc.c
92
@@ -XXX,XX +XXX,XX @@
93
+/*
94
+ * Microchip PolarFire SoC DDR Memory Controller module emulation
95
+ *
96
+ * Copyright (c) 2020 Wind River Systems, Inc.
97
+ *
98
+ * Author:
99
+ * Bin Meng <bin.meng@windriver.com>
100
+ *
101
+ * This program is free software; you can redistribute it and/or
102
+ * modify it under the terms of the GNU General Public License as
103
+ * published by the Free Software Foundation; either version 2 or
104
+ * (at your option) version 3 of the License.
105
+ *
106
+ * This program is distributed in the hope that it will be useful,
107
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
108
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
109
+ * GNU General Public License for more details.
110
+ *
111
+ * You should have received a copy of the GNU General Public License along
112
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
113
+ */
114
+
115
+#include "qemu/osdep.h"
116
+#include "qemu/bitops.h"
117
+#include "qemu/log.h"
118
+#include "qapi/error.h"
119
+#include "hw/hw.h"
120
+#include "hw/sysbus.h"
121
+#include "hw/misc/mchp_pfsoc_dmc.h"
122
+
123
+/* DDR SGMII PHY module */
124
+
125
+#define SGMII_PHY_IOC_REG1 0x208
126
+#define SGMII_PHY_TRAINING_STATUS 0x814
127
+#define SGMII_PHY_DQ_DQS_ERR_DONE 0x834
128
+#define SGMII_PHY_DQDQS_STATUS1 0x84c
129
+#define SGMII_PHY_PVT_STAT 0xc20
130
+
131
+static uint64_t mchp_pfsoc_ddr_sgmii_phy_read(void *opaque, hwaddr offset,
132
+ unsigned size)
133
+{
134
+ uint32_t val = 0;
135
+ static int training_status_bit;
136
+
137
+ switch (offset) {
138
+ case SGMII_PHY_IOC_REG1:
139
+ /* See ddr_pvt_calibration() in HSS */
140
+ val = BIT(4) | BIT(2);
141
+ break;
142
+ case SGMII_PHY_TRAINING_STATUS:
143
+ /*
144
+ * The codes logic emulates the training status change from
145
+ * DDR_TRAINING_IP_SM_BCLKSCLK to DDR_TRAINING_IP_SM_DQ_DQS.
146
+ *
147
+ * See ddr_setup() in mss_ddr.c in the HSS source codes.
148
+ */
149
+ val = 1 << training_status_bit;
150
+ training_status_bit = (training_status_bit + 1) % 5;
151
+ break;
152
+ case SGMII_PHY_DQ_DQS_ERR_DONE:
153
+ /*
154
+ * DDR_TRAINING_IP_SM_VERIFY state in ddr_setup(),
155
+ * check that DQ/DQS training passed without error.
156
+ */
157
+ val = 8;
158
+ break;
159
+ case SGMII_PHY_DQDQS_STATUS1:
160
+ /*
161
+ * DDR_TRAINING_IP_SM_VERIFY state in ddr_setup(),
162
+ * check that DQ/DQS calculated window is above 5 taps.
163
+ */
164
+ val = 0xff;
165
+ break;
166
+ case SGMII_PHY_PVT_STAT:
167
+ /* See sgmii_channel_setup() in HSS */
168
+ val = BIT(14) | BIT(6);
169
+ break;
170
+ default:
171
+ qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read "
172
+ "(size %d, offset 0x%" HWADDR_PRIx ")\n",
173
+ __func__, size, offset);
174
+ break;
175
+ }
176
+
177
+ return val;
178
+}
179
+
180
+static void mchp_pfsoc_ddr_sgmii_phy_write(void *opaque, hwaddr offset,
181
+ uint64_t value, unsigned size)
182
+{
183
+ qemu_log_mask(LOG_UNIMP, "%s: unimplemented device write "
184
+ "(size %d, value 0x%" PRIx64
185
+ ", offset 0x%" HWADDR_PRIx ")\n",
186
+ __func__, size, value, offset);
187
+}
188
+
189
+static const MemoryRegionOps mchp_pfsoc_ddr_sgmii_phy_ops = {
190
+ .read = mchp_pfsoc_ddr_sgmii_phy_read,
191
+ .write = mchp_pfsoc_ddr_sgmii_phy_write,
192
+ .endianness = DEVICE_LITTLE_ENDIAN,
193
+};
194
+
195
+static void mchp_pfsoc_ddr_sgmii_phy_realize(DeviceState *dev, Error **errp)
196
+{
197
+ MchpPfSoCDdrSgmiiPhyState *s = MCHP_PFSOC_DDR_SGMII_PHY(dev);
198
+
199
+ memory_region_init_io(&s->sgmii_phy, OBJECT(dev),
200
+ &mchp_pfsoc_ddr_sgmii_phy_ops, s,
201
+ "mchp.pfsoc.ddr_sgmii_phy",
202
+ MCHP_PFSOC_DDR_SGMII_PHY_REG_SIZE);
203
+ sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->sgmii_phy);
204
+}
205
+
206
+static void mchp_pfsoc_ddr_sgmii_phy_class_init(ObjectClass *klass, void *data)
207
+{
208
+ DeviceClass *dc = DEVICE_CLASS(klass);
209
+
210
+ dc->desc = "Microchip PolarFire SoC DDR SGMII PHY module";
211
+ dc->realize = mchp_pfsoc_ddr_sgmii_phy_realize;
212
+}
213
+
214
+static const TypeInfo mchp_pfsoc_ddr_sgmii_phy_info = {
215
+ .name = TYPE_MCHP_PFSOC_DDR_SGMII_PHY,
216
+ .parent = TYPE_SYS_BUS_DEVICE,
217
+ .instance_size = sizeof(MchpPfSoCDdrSgmiiPhyState),
218
+ .class_init = mchp_pfsoc_ddr_sgmii_phy_class_init,
219
+};
220
+
221
+static void mchp_pfsoc_ddr_sgmii_phy_register_types(void)
222
+{
223
+ type_register_static(&mchp_pfsoc_ddr_sgmii_phy_info);
224
+}
225
+
226
+type_init(mchp_pfsoc_ddr_sgmii_phy_register_types)
227
+
228
+/* DDR CFG module */
229
+
230
+#define CFG_MT_DONE_ACK 0x4428
231
+#define CFG_STAT_DFI_INIT_COMPLETE 0x10034
232
+#define CFG_STAT_DFI_TRAINING_COMPLETE 0x10038
233
+
234
+static uint64_t mchp_pfsoc_ddr_cfg_read(void *opaque, hwaddr offset,
235
+ unsigned size)
236
+{
237
+ uint32_t val = 0;
238
+
239
+ switch (offset) {
240
+ case CFG_MT_DONE_ACK:
241
+ /* memory test in MTC_test() */
242
+ val = BIT(0);
243
+ break;
244
+ case CFG_STAT_DFI_INIT_COMPLETE:
245
+ /* DDR_TRAINING_IP_SM_START_CHECK state in ddr_setup() */
246
+ val = BIT(0);
247
+ break;
248
+ case CFG_STAT_DFI_TRAINING_COMPLETE:
249
+ /* DDR_TRAINING_IP_SM_VERIFY state in ddr_setup() */
250
+ val = BIT(0);
251
+ break;
252
+ default:
253
+ qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read "
254
+ "(size %d, offset 0x%" HWADDR_PRIx ")\n",
255
+ __func__, size, offset);
256
+ break;
257
+ }
258
+
259
+ return val;
260
+}
261
+
262
+static void mchp_pfsoc_ddr_cfg_write(void *opaque, hwaddr offset,
263
+ uint64_t value, unsigned size)
264
+{
265
+ qemu_log_mask(LOG_UNIMP, "%s: unimplemented device write "
266
+ "(size %d, value 0x%" PRIx64
267
+ ", offset 0x%" HWADDR_PRIx ")\n",
268
+ __func__, size, value, offset);
269
+}
270
+
271
+static const MemoryRegionOps mchp_pfsoc_ddr_cfg_ops = {
272
+ .read = mchp_pfsoc_ddr_cfg_read,
273
+ .write = mchp_pfsoc_ddr_cfg_write,
274
+ .endianness = DEVICE_LITTLE_ENDIAN,
275
+};
276
+
277
+static void mchp_pfsoc_ddr_cfg_realize(DeviceState *dev, Error **errp)
278
+{
279
+ MchpPfSoCDdrCfgState *s = MCHP_PFSOC_DDR_CFG(dev);
280
+
281
+ memory_region_init_io(&s->cfg, OBJECT(dev),
282
+ &mchp_pfsoc_ddr_cfg_ops, s,
283
+ "mchp.pfsoc.ddr_cfg",
284
+ MCHP_PFSOC_DDR_CFG_REG_SIZE);
285
+ sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->cfg);
286
+}
287
+
288
+static void mchp_pfsoc_ddr_cfg_class_init(ObjectClass *klass, void *data)
289
+{
290
+ DeviceClass *dc = DEVICE_CLASS(klass);
291
+
292
+ dc->desc = "Microchip PolarFire SoC DDR CFG module";
293
+ dc->realize = mchp_pfsoc_ddr_cfg_realize;
294
+}
295
+
296
+static const TypeInfo mchp_pfsoc_ddr_cfg_info = {
297
+ .name = TYPE_MCHP_PFSOC_DDR_CFG,
298
+ .parent = TYPE_SYS_BUS_DEVICE,
299
+ .instance_size = sizeof(MchpPfSoCDdrCfgState),
300
+ .class_init = mchp_pfsoc_ddr_cfg_class_init,
301
+};
302
+
303
+static void mchp_pfsoc_ddr_cfg_register_types(void)
304
+{
305
+ type_register_static(&mchp_pfsoc_ddr_cfg_info);
306
+}
307
+
308
+type_init(mchp_pfsoc_ddr_cfg_register_types)
309
diff --git a/MAINTAINERS b/MAINTAINERS
20
index XXXXXXX..XXXXXXX 100644
310
index XXXXXXX..XXXXXXX 100644
21
--- a/target/riscv/cpu_cfg.h
311
--- a/MAINTAINERS
22
+++ b/target/riscv/cpu_cfg.h
312
+++ b/MAINTAINERS
23
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
313
@@ -XXX,XX +XXX,XX @@ L: qemu-riscv@nongnu.org
24
bool ext_zve32x;
314
S: Supported
25
bool ext_zve64f;
315
F: hw/riscv/microchip_pfsoc.c
26
bool ext_zve64d;
316
F: hw/char/mchp_pfsoc_mmuart.c
27
+ bool ext_zve64x;
317
+F: hw/misc/mchp_pfsoc_dmc.c
28
bool ext_zvbb;
318
F: include/hw/riscv/microchip_pfsoc.h
29
bool ext_zvbc;
319
F: include/hw/char/mchp_pfsoc_mmuart.h
30
bool ext_zvkb;
320
+F: include/hw/misc/mchp_pfsoc_dmc.h
31
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
321
322
RX Machines
323
-----------
324
diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig
32
index XXXXXXX..XXXXXXX 100644
325
index XXXXXXX..XXXXXXX 100644
33
--- a/target/riscv/cpu.c
326
--- a/hw/misc/Kconfig
34
+++ b/target/riscv/cpu.c
327
+++ b/hw/misc/Kconfig
35
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
328
@@ -XXX,XX +XXX,XX @@ config MAC_VIA
36
ISA_EXT_DATA_ENTRY(zve32x, PRIV_VERSION_1_10_0, ext_zve32x),
329
config AVR_POWER
37
ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f),
330
bool
38
ISA_EXT_DATA_ENTRY(zve64d, PRIV_VERSION_1_10_0, ext_zve64d),
331
39
+ ISA_EXT_DATA_ENTRY(zve64x, PRIV_VERSION_1_10_0, ext_zve64x),
332
+config MCHP_PFSOC_DMC
40
ISA_EXT_DATA_ENTRY(zvfbfmin, PRIV_VERSION_1_12_0, ext_zvfbfmin),
333
+ bool
41
ISA_EXT_DATA_ENTRY(zvfbfwma, PRIV_VERSION_1_12_0, ext_zvfbfwma),
334
+
42
ISA_EXT_DATA_ENTRY(zvfh, PRIV_VERSION_1_12_0, ext_zvfh),
335
config SIFIVE_TEST
43
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
336
bool
44
MULTI_EXT_CFG_BOOL("zve32x", ext_zve32x, false),
337
45
MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false),
338
diff --git a/hw/misc/meson.build b/hw/misc/meson.build
46
MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false),
47
+ MULTI_EXT_CFG_BOOL("zve64x", ext_zve64x, false),
48
MULTI_EXT_CFG_BOOL("zvfbfmin", ext_zvfbfmin, false),
49
MULTI_EXT_CFG_BOOL("zvfbfwma", ext_zvfbfwma, false),
50
MULTI_EXT_CFG_BOOL("zvfh", ext_zvfh, false),
51
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
52
index XXXXXXX..XXXXXXX 100644
339
index XXXXXXX..XXXXXXX 100644
53
--- a/target/riscv/tcg/tcg-cpu.c
340
--- a/hw/misc/meson.build
54
+++ b/target/riscv/tcg/tcg-cpu.c
341
+++ b/hw/misc/meson.build
55
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
342
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_ARM11SCU', if_true: files('arm11scu.c'))
56
343
softmmu_ss.add(when: 'CONFIG_MOS6522', if_true: files('mos6522.c'))
57
/* The Zve64d extension depends on the Zve64f extension */
344
58
if (cpu->cfg.ext_zve64d) {
345
# RISC-V devices
59
+ if (!riscv_has_ext(env, RVD)) {
346
+softmmu_ss.add(when: 'CONFIG_MCHP_PFSOC_DMC', if_true: files('mchp_pfsoc_dmc.c'))
60
+ error_setg(errp, "Zve64d/V extensions require D extension");
347
softmmu_ss.add(when: 'CONFIG_SIFIVE_TEST', if_true: files('sifive_test.c'))
61
+ return;
348
softmmu_ss.add(when: 'CONFIG_SIFIVE_E_PRCI', if_true: files('sifive_e_prci.c'))
62
+ }
349
softmmu_ss.add(when: 'CONFIG_SIFIVE_U_OTP', if_true: files('sifive_u_otp.c'))
63
cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64f), true);
64
}
65
66
- /* The Zve64f extension depends on the Zve32f extension */
67
+ /* The Zve64f extension depends on the Zve64x and Zve32f extensions */
68
if (cpu->cfg.ext_zve64f) {
69
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64x), true);
70
cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32f), true);
71
}
72
73
- if (cpu->cfg.ext_zve64d && !riscv_has_ext(env, RVD)) {
74
- error_setg(errp, "Zve64d/V extensions require D extension");
75
- return;
76
+ /* The Zve64x extension depends on the Zve32x extension */
77
+ if (cpu->cfg.ext_zve64x) {
78
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32x), true);
79
}
80
81
/* The Zve32f extension depends on the Zve32x extension */
82
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
83
return;
84
}
85
86
- if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64f) {
87
+ if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64x) {
88
error_setg(
89
errp,
90
- "Zvbc and Zvknhb extensions require V or Zve64{f,d} extensions");
91
+ "Zvbc and Zvknhb extensions require V or Zve64x extensions");
92
return;
93
}
94
95
--
350
--
96
2.45.1
351
2.28.0
352
353
diff view generated by jsdifflib
1
From: Max Chou <max.chou@sifive.com>
1
From: Bin Meng <bin.meng@windriver.com>
2
2
3
The require_scale_rvf function only checks the double width operator for
3
Connect DDR SGMII PHY module and CFG module to the PolarFire SoC.
4
the vector floating point widen instructions, so most of the widen
5
checking functions need to add require_rvf for single width operator.
6
4
7
The vfwcvt.f.x.v and vfwcvt.f.xu.v instructions convert single width
5
Signed-off-by: Bin Meng <bin.meng@windriver.com>
8
integer to double width float, so the opfxv_widen_check function doesn’t
6
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
need require_rvf for the single width operator(integer).
7
Message-id: 1603863010-15807-4-git-send-email-bmeng.cn@gmail.com
10
11
Signed-off-by: Max Chou <max.chou@sifive.com>
12
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
13
Cc: qemu-stable <qemu-stable@nongnu.org>
14
Message-ID: <20240322092600.1198921-3-max.chou@sifive.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
8
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
16
---
9
---
17
target/riscv/insn_trans/trans_rvv.c.inc | 5 +++++
10
include/hw/riscv/microchip_pfsoc.h | 5 +++++
18
1 file changed, 5 insertions(+)
11
hw/riscv/microchip_pfsoc.c | 18 ++++++++++++++++++
12
hw/riscv/Kconfig | 1 +
13
3 files changed, 24 insertions(+)
19
14
20
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
15
diff --git a/include/hw/riscv/microchip_pfsoc.h b/include/hw/riscv/microchip_pfsoc.h
21
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
22
--- a/target/riscv/insn_trans/trans_rvv.c.inc
17
--- a/include/hw/riscv/microchip_pfsoc.h
23
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
18
+++ b/include/hw/riscv/microchip_pfsoc.h
24
@@ -XXX,XX +XXX,XX @@ GEN_OPFVF_TRANS(vfrsub_vf, opfvf_check)
19
@@ -XXX,XX +XXX,XX @@
25
static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a)
20
26
{
21
#include "hw/char/mchp_pfsoc_mmuart.h"
27
return require_rvv(s) &&
22
#include "hw/dma/sifive_pdma.h"
28
+ require_rvf(s) &&
23
+#include "hw/misc/mchp_pfsoc_dmc.h"
29
require_scale_rvf(s) &&
24
#include "hw/net/cadence_gem.h"
30
(s->sew != MO_8) &&
25
#include "hw/sd/cadence_sdhci.h"
31
vext_check_isa_ill(s) &&
26
32
@@ -XXX,XX +XXX,XX @@ GEN_OPFVV_WIDEN_TRANS(vfwsub_vv, opfvv_widen_check)
27
@@ -XXX,XX +XXX,XX @@ typedef struct MicrochipPFSoCState {
33
static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a)
28
RISCVHartArrayState e_cpus;
34
{
29
RISCVHartArrayState u_cpus;
35
return require_rvv(s) &&
30
DeviceState *plic;
36
+ require_rvf(s) &&
31
+ MchpPfSoCDdrSgmiiPhyState ddr_sgmii_phy;
37
require_scale_rvf(s) &&
32
+ MchpPfSoCDdrCfgState ddr_cfg;
38
(s->sew != MO_8) &&
33
MchpPfSoCMMUartState *serial0;
39
vext_check_isa_ill(s) &&
34
MchpPfSoCMMUartState *serial1;
40
@@ -XXX,XX +XXX,XX @@ GEN_OPFVF_WIDEN_TRANS(vfwsub_vf)
35
MchpPfSoCMMUartState *serial2;
41
static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a)
36
@@ -XXX,XX +XXX,XX @@ enum {
42
{
37
MICROCHIP_PFSOC_MMUART0,
43
return require_rvv(s) &&
38
MICROCHIP_PFSOC_SYSREG,
44
+ require_rvf(s) &&
39
MICROCHIP_PFSOC_MPUCFG,
45
require_scale_rvf(s) &&
40
+ MICROCHIP_PFSOC_DDR_SGMII_PHY,
46
(s->sew != MO_8) &&
41
MICROCHIP_PFSOC_EMMC_SD,
47
vext_check_isa_ill(s) &&
42
+ MICROCHIP_PFSOC_DDR_CFG,
48
@@ -XXX,XX +XXX,XX @@ GEN_OPFWV_WIDEN_TRANS(vfwsub_wv)
43
MICROCHIP_PFSOC_MMUART1,
49
static bool opfwf_widen_check(DisasContext *s, arg_rmrr *a)
44
MICROCHIP_PFSOC_MMUART2,
50
{
45
MICROCHIP_PFSOC_MMUART3,
51
return require_rvv(s) &&
46
diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c
52
+ require_rvf(s) &&
47
index XXXXXXX..XXXXXXX 100644
53
require_scale_rvf(s) &&
48
--- a/hw/riscv/microchip_pfsoc.c
54
(s->sew != MO_8) &&
49
+++ b/hw/riscv/microchip_pfsoc.c
55
vext_check_isa_ill(s) &&
50
@@ -XXX,XX +XXX,XX @@
56
@@ -XXX,XX +XXX,XX @@ GEN_OPFVV_TRANS(vfredmin_vs, freduction_check)
51
* 4) Cadence eMMC/SDHC controller and an SD card connected to it
57
static bool freduction_widen_check(DisasContext *s, arg_rmrr *a)
52
* 5) SiFive Platform DMA (Direct Memory Access Controller)
58
{
53
* 6) GEM (Gigabit Ethernet MAC Controller)
59
return reduction_widen_check(s, a) &&
54
+ * 7) DMC (DDR Memory Controller)
60
+ require_rvf(s) &&
55
*
61
require_scale_rvf(s) &&
56
* This board currently generates devicetree dynamically that indicates at least
62
(s->sew != MO_8);
57
* two harts and up to five harts.
63
}
58
@@ -XXX,XX +XXX,XX @@ static const struct MemmapEntry {
59
[MICROCHIP_PFSOC_MMUART0] = { 0x20000000, 0x1000 },
60
[MICROCHIP_PFSOC_SYSREG] = { 0x20002000, 0x2000 },
61
[MICROCHIP_PFSOC_MPUCFG] = { 0x20005000, 0x1000 },
62
+ [MICROCHIP_PFSOC_DDR_SGMII_PHY] = { 0x20007000, 0x1000 },
63
[MICROCHIP_PFSOC_EMMC_SD] = { 0x20008000, 0x1000 },
64
+ [MICROCHIP_PFSOC_DDR_CFG] = { 0x20080000, 0x40000 },
65
[MICROCHIP_PFSOC_MMUART1] = { 0x20100000, 0x1000 },
66
[MICROCHIP_PFSOC_MMUART2] = { 0x20102000, 0x1000 },
67
[MICROCHIP_PFSOC_MMUART3] = { 0x20104000, 0x1000 },
68
@@ -XXX,XX +XXX,XX @@ static void microchip_pfsoc_soc_instance_init(Object *obj)
69
object_initialize_child(obj, "dma-controller", &s->dma,
70
TYPE_SIFIVE_PDMA);
71
72
+ object_initialize_child(obj, "ddr-sgmii-phy", &s->ddr_sgmii_phy,
73
+ TYPE_MCHP_PFSOC_DDR_SGMII_PHY);
74
+ object_initialize_child(obj, "ddr-cfg", &s->ddr_cfg,
75
+ TYPE_MCHP_PFSOC_DDR_CFG);
76
+
77
object_initialize_child(obj, "gem0", &s->gem0, TYPE_CADENCE_GEM);
78
object_initialize_child(obj, "gem1", &s->gem1, TYPE_CADENCE_GEM);
79
80
@@ -XXX,XX +XXX,XX @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
81
memmap[MICROCHIP_PFSOC_MPUCFG].base,
82
memmap[MICROCHIP_PFSOC_MPUCFG].size);
83
84
+ /* DDR SGMII PHY */
85
+ sysbus_realize(SYS_BUS_DEVICE(&s->ddr_sgmii_phy), errp);
86
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->ddr_sgmii_phy), 0,
87
+ memmap[MICROCHIP_PFSOC_DDR_SGMII_PHY].base);
88
+
89
+ /* DDR CFG */
90
+ sysbus_realize(SYS_BUS_DEVICE(&s->ddr_cfg), errp);
91
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->ddr_cfg), 0,
92
+ memmap[MICROCHIP_PFSOC_DDR_CFG].base);
93
+
94
/* SDHCI */
95
sysbus_realize(SYS_BUS_DEVICE(&s->sdhci), errp);
96
sysbus_mmio_map(SYS_BUS_DEVICE(&s->sdhci), 0,
97
diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig
98
index XXXXXXX..XXXXXXX 100644
99
--- a/hw/riscv/Kconfig
100
+++ b/hw/riscv/Kconfig
101
@@ -XXX,XX +XXX,XX @@ config IBEX
102
config MICROCHIP_PFSOC
103
bool
104
select CADENCE_SDHCI
105
+ select MCHP_PFSOC_DMC
106
select MCHP_PFSOC_MMUART
107
select MSI_NONBROKEN
108
select SIFIVE_CLINT
64
--
109
--
65
2.45.1
110
2.28.0
66
111
67
112
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Bin Meng <bin.meng@windriver.com>
2
2
3
SBI defines a Debug Console extension "DBCN" that will, in time, replace
3
This creates a model for PolarFire SoC IOSCB [1] module. It actually
4
the legacy console putchar and getchar SBI extensions.
4
contains lots of sub-modules like various PLLs to control different
5
5
peripherals. Only the mininum capabilities are emulated to make the
6
The appeal of the DBCN extension is that it allows multiple bytes to be
6
HSS DDR memory initialization codes happy. Lots of sub-modules are
7
read/written in the SBI console in a single SBI call.
7
created as an unimplemented devices.
8
8
9
As far as KVM goes, the DBCN calls are forwarded by an in-kernel KVM
9
[1] PF_SoC_RegMap_V1_1/MPFS250T/mpfs250t_ioscb_memmap_dri.htm in
10
module to userspace. But this will only happens if the KVM module
10
https://www.microsemi.com/document-portal/doc_download/1244581-polarfire-soc-register-map
11
actually supports this SBI extension and we activate it.
11
12
12
Signed-off-by: Bin Meng <bin.meng@windriver.com>
13
We'll check for DBCN support during init time, checking if get-reg-list
13
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
14
is advertising KVM_RISCV_SBI_EXT_DBCN. In that case, we'll enable it via
14
Message-id: 1603863010-15807-5-git-send-email-bmeng.cn@gmail.com
15
kvm_set_one_reg() during kvm_arch_init_vcpu().
16
17
Finally, change kvm_riscv_handle_sbi() to handle the incoming calls for
18
SBI_EXT_DBCN, reading and writing as required.
19
20
A simple KVM guest with 'earlycon=sbi', running in an emulated RISC-V
21
host, takes around 20 seconds to boot without using DBCN. With this
22
patch we're taking around 14 seconds to boot due to the speed-up in the
23
terminal output. There's no change in boot time if the guest isn't
24
using earlycon.
25
26
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
27
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
28
Message-ID: <20240425155012.581366-1-dbarboza@ventanamicro.com>
29
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
30
---
16
---
31
target/riscv/sbi_ecall_interface.h | 17 +++++
17
include/hw/misc/mchp_pfsoc_ioscb.h | 50 ++++++
32
target/riscv/kvm/kvm-cpu.c | 111 +++++++++++++++++++++++++++++
18
hw/misc/mchp_pfsoc_ioscb.c | 242 +++++++++++++++++++++++++++++
33
2 files changed, 128 insertions(+)
19
MAINTAINERS | 2 +
34
20
hw/misc/Kconfig | 3 +
35
diff --git a/target/riscv/sbi_ecall_interface.h b/target/riscv/sbi_ecall_interface.h
21
hw/misc/meson.build | 1 +
36
index XXXXXXX..XXXXXXX 100644
22
5 files changed, 298 insertions(+)
37
--- a/target/riscv/sbi_ecall_interface.h
23
create mode 100644 include/hw/misc/mchp_pfsoc_ioscb.h
38
+++ b/target/riscv/sbi_ecall_interface.h
24
create mode 100644 hw/misc/mchp_pfsoc_ioscb.c
25
26
diff --git a/include/hw/misc/mchp_pfsoc_ioscb.h b/include/hw/misc/mchp_pfsoc_ioscb.h
27
new file mode 100644
28
index XXXXXXX..XXXXXXX
29
--- /dev/null
30
+++ b/include/hw/misc/mchp_pfsoc_ioscb.h
39
@@ -XXX,XX +XXX,XX @@
31
@@ -XXX,XX +XXX,XX @@
40
32
+/*
41
/* clang-format off */
33
+ * Microchip PolarFire SoC IOSCB module emulation
42
34
+ *
43
+#define SBI_SUCCESS 0
35
+ * Copyright (c) 2020 Wind River Systems, Inc.
44
+#define SBI_ERR_FAILED -1
36
+ *
45
+#define SBI_ERR_NOT_SUPPORTED -2
37
+ * Author:
46
+#define SBI_ERR_INVALID_PARAM -3
38
+ * Bin Meng <bin.meng@windriver.com>
47
+#define SBI_ERR_DENIED -4
39
+ *
48
+#define SBI_ERR_INVALID_ADDRESS -5
40
+ * This program is free software; you can redistribute it and/or
49
+#define SBI_ERR_ALREADY_AVAILABLE -6
41
+ * modify it under the terms of the GNU General Public License as
50
+#define SBI_ERR_ALREADY_STARTED -7
42
+ * published by the Free Software Foundation; either version 2 or
51
+#define SBI_ERR_ALREADY_STOPPED -8
43
+ * (at your option) version 3 of the License.
52
+#define SBI_ERR_NO_SHMEM -9
44
+ *
53
+
45
+ * This program is distributed in the hope that it will be useful,
54
/* SBI Extension IDs */
46
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
55
#define SBI_EXT_0_1_SET_TIMER 0x0
47
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
56
#define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1
48
+ * GNU General Public License for more details.
49
+ *
50
+ * You should have received a copy of the GNU General Public License along
51
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
52
+ */
53
+
54
+#ifndef MCHP_PFSOC_IOSCB_H
55
+#define MCHP_PFSOC_IOSCB_H
56
+
57
+typedef struct MchpPfSoCIoscbState {
58
+ SysBusDevice parent;
59
+ MemoryRegion container;
60
+ MemoryRegion lane01;
61
+ MemoryRegion lane23;
62
+ MemoryRegion ctrl;
63
+ MemoryRegion cfg;
64
+ MemoryRegion pll_mss;
65
+ MemoryRegion cfm_mss;
66
+ MemoryRegion pll_ddr;
67
+ MemoryRegion bc_ddr;
68
+ MemoryRegion io_calib_ddr;
69
+ MemoryRegion pll_sgmii;
70
+ MemoryRegion dll_sgmii;
71
+ MemoryRegion cfm_sgmii;
72
+ MemoryRegion bc_sgmii;
73
+ MemoryRegion io_calib_sgmii;
74
+} MchpPfSoCIoscbState;
75
+
76
+#define TYPE_MCHP_PFSOC_IOSCB "mchp.pfsoc.ioscb"
77
+
78
+#define MCHP_PFSOC_IOSCB(obj) \
79
+ OBJECT_CHECK(MchpPfSoCIoscbState, (obj), TYPE_MCHP_PFSOC_IOSCB)
80
+
81
+#endif /* MCHP_PFSOC_IOSCB_H */
82
diff --git a/hw/misc/mchp_pfsoc_ioscb.c b/hw/misc/mchp_pfsoc_ioscb.c
83
new file mode 100644
84
index XXXXXXX..XXXXXXX
85
--- /dev/null
86
+++ b/hw/misc/mchp_pfsoc_ioscb.c
57
@@ -XXX,XX +XXX,XX @@
87
@@ -XXX,XX +XXX,XX @@
58
#define SBI_EXT_IPI 0x735049
88
+/*
59
#define SBI_EXT_RFENCE 0x52464E43
89
+ * Microchip PolarFire SoC IOSCB module emulation
60
#define SBI_EXT_HSM 0x48534D
90
+ *
61
+#define SBI_EXT_DBCN 0x4442434E
91
+ * Copyright (c) 2020 Wind River Systems, Inc.
62
92
+ *
63
/* SBI function IDs for BASE extension */
93
+ * Author:
64
#define SBI_EXT_BASE_GET_SPEC_VERSION 0x0
94
+ * Bin Meng <bin.meng@windriver.com>
65
@@ -XXX,XX +XXX,XX @@
95
+ *
66
#define SBI_EXT_HSM_HART_STOP 0x1
96
+ * This program is free software; you can redistribute it and/or
67
#define SBI_EXT_HSM_HART_GET_STATUS 0x2
97
+ * modify it under the terms of the GNU General Public License as
68
98
+ * published by the Free Software Foundation; either version 2 or
69
+/* SBI function IDs for DBCN extension */
99
+ * (at your option) version 3 of the License.
70
+#define SBI_EXT_DBCN_CONSOLE_WRITE 0x0
100
+ *
71
+#define SBI_EXT_DBCN_CONSOLE_READ 0x1
101
+ * This program is distributed in the hope that it will be useful,
72
+#define SBI_EXT_DBCN_CONSOLE_WRITE_BYTE 0x2
102
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
73
+
103
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
74
#define SBI_HSM_HART_STATUS_STARTED 0x0
104
+ * GNU General Public License for more details.
75
#define SBI_HSM_HART_STATUS_STOPPED 0x1
105
+ *
76
#define SBI_HSM_HART_STATUS_START_PENDING 0x2
106
+ * You should have received a copy of the GNU General Public License along
77
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
107
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
78
index XXXXXXX..XXXXXXX 100644
108
+ */
79
--- a/target/riscv/kvm/kvm-cpu.c
109
+
80
+++ b/target/riscv/kvm/kvm-cpu.c
110
+#include "qemu/osdep.h"
81
@@ -XXX,XX +XXX,XX @@ static KVMCPUConfig kvm_v_vlenb = {
111
+#include "qemu/bitops.h"
82
KVM_REG_RISCV_VECTOR_CSR_REG(vlenb)
112
+#include "qemu/log.h"
83
};
113
+#include "qapi/error.h"
84
114
+#include "hw/hw.h"
85
+static KVMCPUConfig kvm_sbi_dbcn = {
115
+#include "hw/sysbus.h"
86
+ .name = "sbi_dbcn",
116
+#include "hw/misc/mchp_pfsoc_ioscb.h"
87
+ .kvm_reg_id = KVM_REG_RISCV | KVM_REG_SIZE_U64 |
117
+
88
+ KVM_REG_RISCV_SBI_EXT | KVM_RISCV_SBI_EXT_DBCN
118
+/*
119
+ * The whole IOSCB module registers map into the system address at 0x3000_0000,
120
+ * named as "System Port 0 (AXI-D0)".
121
+ */
122
+#define IOSCB_WHOLE_REG_SIZE 0x10000000
123
+#define IOSCB_SUBMOD_REG_SIZE 0x1000
124
+
125
+/*
126
+ * There are many sub-modules in the IOSCB module.
127
+ * See Microchip PolarFire SoC documentation (Register_Map.zip),
128
+ * Register Map/PF_SoC_RegMap_V1_1/MPFS250T/mpfs250t_ioscb_memmap_dri.htm
129
+ *
130
+ * The following are sub-modules offsets that are of concern.
131
+ */
132
+#define IOSCB_LANE01_BASE 0x06500000
133
+#define IOSCB_LANE23_BASE 0x06510000
134
+#define IOSCB_CTRL_BASE 0x07020000
135
+#define IOSCB_CFG_BASE 0x07080000
136
+#define IOSCB_PLL_MSS_BASE 0x0E001000
137
+#define IOSCB_CFM_MSS_BASE 0x0E002000
138
+#define IOSCB_PLL_DDR_BASE 0x0E010000
139
+#define IOSCB_BC_DDR_BASE 0x0E020000
140
+#define IOSCB_IO_CALIB_DDR_BASE 0x0E040000
141
+#define IOSCB_PLL_SGMII_BASE 0x0E080000
142
+#define IOSCB_DLL_SGMII_BASE 0x0E100000
143
+#define IOSCB_CFM_SGMII_BASE 0x0E200000
144
+#define IOSCB_BC_SGMII_BASE 0x0E400000
145
+#define IOSCB_IO_CALIB_SGMII_BASE 0x0E800000
146
+
147
+static uint64_t mchp_pfsoc_dummy_read(void *opaque, hwaddr offset,
148
+ unsigned size)
149
+{
150
+ qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read "
151
+ "(size %d, offset 0x%" HWADDR_PRIx ")\n",
152
+ __func__, size, offset);
153
+
154
+ return 0;
155
+}
156
+
157
+static void mchp_pfsoc_dummy_write(void *opaque, hwaddr offset,
158
+ uint64_t value, unsigned size)
159
+{
160
+ qemu_log_mask(LOG_UNIMP, "%s: unimplemented device write "
161
+ "(size %d, value 0x%" PRIx64
162
+ ", offset 0x%" HWADDR_PRIx ")\n",
163
+ __func__, size, value, offset);
164
+}
165
+
166
+static const MemoryRegionOps mchp_pfsoc_dummy_ops = {
167
+ .read = mchp_pfsoc_dummy_read,
168
+ .write = mchp_pfsoc_dummy_write,
169
+ .endianness = DEVICE_LITTLE_ENDIAN,
89
+};
170
+};
90
+
171
+
91
static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs)
172
+/* All PLL modules in IOSCB have the same register layout */
92
{
173
+
93
CPURISCVState *env = &cpu->env;
174
+#define PLL_CTRL 0x04
94
@@ -XXX,XX +XXX,XX @@ static int uint64_cmp(const void *a, const void *b)
175
+
95
return 0;
176
+static uint64_t mchp_pfsoc_pll_read(void *opaque, hwaddr offset,
96
}
177
+ unsigned size)
97
178
+{
98
+static void kvm_riscv_check_sbi_dbcn_support(RISCVCPU *cpu,
179
+ uint32_t val = 0;
99
+ KVMScratchCPU *kvmcpu,
180
+
100
+ struct kvm_reg_list *reglist)
181
+ switch (offset) {
101
+{
182
+ case PLL_CTRL:
102
+ struct kvm_reg_list *reg_search;
183
+ /* PLL is locked */
103
+
184
+ val = BIT(25);
104
+ reg_search = bsearch(&kvm_sbi_dbcn.kvm_reg_id, reglist->reg, reglist->n,
105
+ sizeof(uint64_t), uint64_cmp);
106
+
107
+ if (reg_search) {
108
+ kvm_sbi_dbcn.supported = true;
109
+ }
110
+}
111
+
112
static void kvm_riscv_read_vlenb(RISCVCPU *cpu, KVMScratchCPU *kvmcpu,
113
struct kvm_reg_list *reglist)
114
{
115
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_init_multiext_cfg(RISCVCPU *cpu, KVMScratchCPU *kvmcpu)
116
if (riscv_has_ext(&cpu->env, RVV)) {
117
kvm_riscv_read_vlenb(cpu, kvmcpu, reglist);
118
}
119
+
120
+ kvm_riscv_check_sbi_dbcn_support(cpu, kvmcpu, reglist);
121
}
122
123
static void riscv_init_kvm_registers(Object *cpu_obj)
124
@@ -XXX,XX +XXX,XX @@ static int kvm_vcpu_set_machine_ids(RISCVCPU *cpu, CPUState *cs)
125
return ret;
126
}
127
128
+static int kvm_vcpu_enable_sbi_dbcn(RISCVCPU *cpu, CPUState *cs)
129
+{
130
+ target_ulong reg = 1;
131
+
132
+ if (!kvm_sbi_dbcn.supported) {
133
+ return 0;
134
+ }
135
+
136
+ return kvm_set_one_reg(cs, kvm_sbi_dbcn.kvm_reg_id, &reg);
137
+}
138
+
139
int kvm_arch_init_vcpu(CPUState *cs)
140
{
141
int ret = 0;
142
@@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs)
143
kvm_riscv_update_cpu_misa_ext(cpu, cs);
144
kvm_riscv_update_cpu_cfg_isa_ext(cpu, cs);
145
146
+ ret = kvm_vcpu_enable_sbi_dbcn(cpu, cs);
147
+
148
return ret;
149
}
150
151
@@ -XXX,XX +XXX,XX @@ bool kvm_arch_stop_on_emulation_error(CPUState *cs)
152
return true;
153
}
154
155
+static void kvm_riscv_handle_sbi_dbcn(CPUState *cs, struct kvm_run *run)
156
+{
157
+ g_autofree uint8_t *buf = NULL;
158
+ RISCVCPU *cpu = RISCV_CPU(cs);
159
+ target_ulong num_bytes;
160
+ uint64_t addr;
161
+ unsigned char ch;
162
+ int ret;
163
+
164
+ switch (run->riscv_sbi.function_id) {
165
+ case SBI_EXT_DBCN_CONSOLE_READ:
166
+ case SBI_EXT_DBCN_CONSOLE_WRITE:
167
+ num_bytes = run->riscv_sbi.args[0];
168
+
169
+ if (num_bytes == 0) {
170
+ run->riscv_sbi.ret[0] = SBI_SUCCESS;
171
+ run->riscv_sbi.ret[1] = 0;
172
+ break;
173
+ }
174
+
175
+ addr = run->riscv_sbi.args[1];
176
+
177
+ /*
178
+ * Handle the case where a 32 bit CPU is running in a
179
+ * 64 bit addressing env.
180
+ */
181
+ if (riscv_cpu_mxl(&cpu->env) == MXL_RV32) {
182
+ addr |= (uint64_t)run->riscv_sbi.args[2] << 32;
183
+ }
184
+
185
+ buf = g_malloc0(num_bytes);
186
+
187
+ if (run->riscv_sbi.function_id == SBI_EXT_DBCN_CONSOLE_READ) {
188
+ ret = qemu_chr_fe_read_all(serial_hd(0)->be, buf, num_bytes);
189
+ if (ret < 0) {
190
+ error_report("SBI_EXT_DBCN_CONSOLE_READ: error when "
191
+ "reading chardev");
192
+ exit(1);
193
+ }
194
+
195
+ cpu_physical_memory_write(addr, buf, ret);
196
+ } else {
197
+ cpu_physical_memory_read(addr, buf, num_bytes);
198
+
199
+ ret = qemu_chr_fe_write_all(serial_hd(0)->be, buf, num_bytes);
200
+ if (ret < 0) {
201
+ error_report("SBI_EXT_DBCN_CONSOLE_WRITE: error when "
202
+ "writing chardev");
203
+ exit(1);
204
+ }
205
+ }
206
+
207
+ run->riscv_sbi.ret[0] = SBI_SUCCESS;
208
+ run->riscv_sbi.ret[1] = ret;
209
+ break;
210
+ case SBI_EXT_DBCN_CONSOLE_WRITE_BYTE:
211
+ ch = run->riscv_sbi.args[0];
212
+ ret = qemu_chr_fe_write(serial_hd(0)->be, &ch, sizeof(ch));
213
+
214
+ if (ret < 0) {
215
+ error_report("SBI_EXT_DBCN_CONSOLE_WRITE_BYTE: error when "
216
+ "writing chardev");
217
+ exit(1);
218
+ }
219
+
220
+ run->riscv_sbi.ret[0] = SBI_SUCCESS;
221
+ run->riscv_sbi.ret[1] = 0;
222
+ break;
185
+ break;
223
+ default:
186
+ default:
224
+ run->riscv_sbi.ret[0] = SBI_ERR_NOT_SUPPORTED;
187
+ qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read "
188
+ "(size %d, offset 0x%" HWADDR_PRIx ")\n",
189
+ __func__, size, offset);
190
+ break;
225
+ }
191
+ }
226
+}
192
+
227
+
193
+ return val;
228
static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run)
194
+}
229
{
195
+
230
int ret = 0;
196
+static const MemoryRegionOps mchp_pfsoc_pll_ops = {
231
@@ -XXX,XX +XXX,XX @@ static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run)
197
+ .read = mchp_pfsoc_pll_read,
232
}
198
+ .write = mchp_pfsoc_dummy_write,
233
ret = 0;
199
+ .endianness = DEVICE_LITTLE_ENDIAN,
234
break;
200
+};
235
+ case SBI_EXT_DBCN:
201
+
236
+ kvm_riscv_handle_sbi_dbcn(cs, run);
202
+/* IO_CALIB_DDR submodule */
203
+
204
+#define IO_CALIB_DDR_IOC_REG1 0x08
205
+
206
+static uint64_t mchp_pfsoc_io_calib_ddr_read(void *opaque, hwaddr offset,
207
+ unsigned size)
208
+{
209
+ uint32_t val = 0;
210
+
211
+ switch (offset) {
212
+ case IO_CALIB_DDR_IOC_REG1:
213
+ /* calibration completed */
214
+ val = BIT(2);
237
+ break;
215
+ break;
238
default:
216
+ default:
239
qemu_log_mask(LOG_UNIMP,
217
+ qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read "
240
"%s: un-handled SBI EXIT, specific reasons is %lu\n",
218
+ "(size %d, offset 0x%" HWADDR_PRIx ")\n",
219
+ __func__, size, offset);
220
+ break;
221
+ }
222
+
223
+ return val;
224
+}
225
+
226
+static const MemoryRegionOps mchp_pfsoc_io_calib_ddr_ops = {
227
+ .read = mchp_pfsoc_io_calib_ddr_read,
228
+ .write = mchp_pfsoc_dummy_write,
229
+ .endianness = DEVICE_LITTLE_ENDIAN,
230
+};
231
+
232
+static void mchp_pfsoc_ioscb_realize(DeviceState *dev, Error **errp)
233
+{
234
+ MchpPfSoCIoscbState *s = MCHP_PFSOC_IOSCB(dev);
235
+ SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
236
+
237
+ memory_region_init(&s->container, OBJECT(s),
238
+ "mchp.pfsoc.ioscb", IOSCB_WHOLE_REG_SIZE);
239
+ sysbus_init_mmio(sbd, &s->container);
240
+
241
+ /* add subregions for all sub-modules in IOSCB */
242
+
243
+ memory_region_init_io(&s->lane01, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
244
+ "mchp.pfsoc.ioscb.lane01", IOSCB_SUBMOD_REG_SIZE);
245
+ memory_region_add_subregion(&s->container, IOSCB_LANE01_BASE, &s->lane01);
246
+
247
+ memory_region_init_io(&s->lane23, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
248
+ "mchp.pfsoc.ioscb.lane23", IOSCB_SUBMOD_REG_SIZE);
249
+ memory_region_add_subregion(&s->container, IOSCB_LANE23_BASE, &s->lane23);
250
+
251
+ memory_region_init_io(&s->ctrl, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
252
+ "mchp.pfsoc.ioscb.ctrl", IOSCB_SUBMOD_REG_SIZE);
253
+ memory_region_add_subregion(&s->container, IOSCB_CTRL_BASE, &s->ctrl);
254
+
255
+ memory_region_init_io(&s->cfg, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
256
+ "mchp.pfsoc.ioscb.cfg", IOSCB_SUBMOD_REG_SIZE);
257
+ memory_region_add_subregion(&s->container, IOSCB_CFG_BASE, &s->cfg);
258
+
259
+ memory_region_init_io(&s->pll_mss, OBJECT(s), &mchp_pfsoc_pll_ops, s,
260
+ "mchp.pfsoc.ioscb.pll_mss", IOSCB_SUBMOD_REG_SIZE);
261
+ memory_region_add_subregion(&s->container, IOSCB_PLL_MSS_BASE, &s->pll_mss);
262
+
263
+ memory_region_init_io(&s->cfm_mss, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
264
+ "mchp.pfsoc.ioscb.cfm_mss", IOSCB_SUBMOD_REG_SIZE);
265
+ memory_region_add_subregion(&s->container, IOSCB_CFM_MSS_BASE, &s->cfm_mss);
266
+
267
+ memory_region_init_io(&s->pll_ddr, OBJECT(s), &mchp_pfsoc_pll_ops, s,
268
+ "mchp.pfsoc.ioscb.pll_ddr", IOSCB_SUBMOD_REG_SIZE);
269
+ memory_region_add_subregion(&s->container, IOSCB_PLL_DDR_BASE, &s->pll_ddr);
270
+
271
+ memory_region_init_io(&s->bc_ddr, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
272
+ "mchp.pfsoc.ioscb.bc_ddr", IOSCB_SUBMOD_REG_SIZE);
273
+ memory_region_add_subregion(&s->container, IOSCB_BC_DDR_BASE, &s->bc_ddr);
274
+
275
+ memory_region_init_io(&s->io_calib_ddr, OBJECT(s),
276
+ &mchp_pfsoc_io_calib_ddr_ops, s,
277
+ "mchp.pfsoc.ioscb.io_calib_ddr",
278
+ IOSCB_SUBMOD_REG_SIZE);
279
+ memory_region_add_subregion(&s->container, IOSCB_IO_CALIB_DDR_BASE,
280
+ &s->io_calib_ddr);
281
+
282
+ memory_region_init_io(&s->pll_sgmii, OBJECT(s), &mchp_pfsoc_pll_ops, s,
283
+ "mchp.pfsoc.ioscb.pll_sgmii", IOSCB_SUBMOD_REG_SIZE);
284
+ memory_region_add_subregion(&s->container, IOSCB_PLL_SGMII_BASE,
285
+ &s->pll_sgmii);
286
+
287
+ memory_region_init_io(&s->dll_sgmii, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
288
+ "mchp.pfsoc.ioscb.dll_sgmii", IOSCB_SUBMOD_REG_SIZE);
289
+ memory_region_add_subregion(&s->container, IOSCB_DLL_SGMII_BASE,
290
+ &s->dll_sgmii);
291
+
292
+ memory_region_init_io(&s->cfm_sgmii, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
293
+ "mchp.pfsoc.ioscb.cfm_sgmii", IOSCB_SUBMOD_REG_SIZE);
294
+ memory_region_add_subregion(&s->container, IOSCB_CFM_SGMII_BASE,
295
+ &s->cfm_sgmii);
296
+
297
+ memory_region_init_io(&s->bc_sgmii, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
298
+ "mchp.pfsoc.ioscb.bc_sgmii", IOSCB_SUBMOD_REG_SIZE);
299
+ memory_region_add_subregion(&s->container, IOSCB_BC_SGMII_BASE,
300
+ &s->bc_sgmii);
301
+
302
+ memory_region_init_io(&s->io_calib_sgmii, OBJECT(s), &mchp_pfsoc_dummy_ops,
303
+ s, "mchp.pfsoc.ioscb.io_calib_sgmii",
304
+ IOSCB_SUBMOD_REG_SIZE);
305
+ memory_region_add_subregion(&s->container, IOSCB_IO_CALIB_SGMII_BASE,
306
+ &s->io_calib_sgmii);
307
+}
308
+
309
+static void mchp_pfsoc_ioscb_class_init(ObjectClass *klass, void *data)
310
+{
311
+ DeviceClass *dc = DEVICE_CLASS(klass);
312
+
313
+ dc->desc = "Microchip PolarFire SoC IOSCB modules";
314
+ dc->realize = mchp_pfsoc_ioscb_realize;
315
+}
316
+
317
+static const TypeInfo mchp_pfsoc_ioscb_info = {
318
+ .name = TYPE_MCHP_PFSOC_IOSCB,
319
+ .parent = TYPE_SYS_BUS_DEVICE,
320
+ .instance_size = sizeof(MchpPfSoCIoscbState),
321
+ .class_init = mchp_pfsoc_ioscb_class_init,
322
+};
323
+
324
+static void mchp_pfsoc_ioscb_register_types(void)
325
+{
326
+ type_register_static(&mchp_pfsoc_ioscb_info);
327
+}
328
+
329
+type_init(mchp_pfsoc_ioscb_register_types)
330
diff --git a/MAINTAINERS b/MAINTAINERS
331
index XXXXXXX..XXXXXXX 100644
332
--- a/MAINTAINERS
333
+++ b/MAINTAINERS
334
@@ -XXX,XX +XXX,XX @@ S: Supported
335
F: hw/riscv/microchip_pfsoc.c
336
F: hw/char/mchp_pfsoc_mmuart.c
337
F: hw/misc/mchp_pfsoc_dmc.c
338
+F: hw/misc/mchp_pfsoc_ioscb.c
339
F: include/hw/riscv/microchip_pfsoc.h
340
F: include/hw/char/mchp_pfsoc_mmuart.h
341
F: include/hw/misc/mchp_pfsoc_dmc.h
342
+F: include/hw/misc/mchp_pfsoc_ioscb.h
343
344
RX Machines
345
-----------
346
diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig
347
index XXXXXXX..XXXXXXX 100644
348
--- a/hw/misc/Kconfig
349
+++ b/hw/misc/Kconfig
350
@@ -XXX,XX +XXX,XX @@ config AVR_POWER
351
config MCHP_PFSOC_DMC
352
bool
353
354
+config MCHP_PFSOC_IOSCB
355
+ bool
356
+
357
config SIFIVE_TEST
358
bool
359
360
diff --git a/hw/misc/meson.build b/hw/misc/meson.build
361
index XXXXXXX..XXXXXXX 100644
362
--- a/hw/misc/meson.build
363
+++ b/hw/misc/meson.build
364
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_MOS6522', if_true: files('mos6522.c'))
365
366
# RISC-V devices
367
softmmu_ss.add(when: 'CONFIG_MCHP_PFSOC_DMC', if_true: files('mchp_pfsoc_dmc.c'))
368
+softmmu_ss.add(when: 'CONFIG_MCHP_PFSOC_IOSCB', if_true: files('mchp_pfsoc_ioscb.c'))
369
softmmu_ss.add(when: 'CONFIG_SIFIVE_TEST', if_true: files('sifive_test.c'))
370
softmmu_ss.add(when: 'CONFIG_SIFIVE_E_PRCI', if_true: files('sifive_e_prci.c'))
371
softmmu_ss.add(when: 'CONFIG_SIFIVE_U_OTP', if_true: files('sifive_u_otp.c'))
241
--
372
--
242
2.45.1
373
2.28.0
374
375
diff view generated by jsdifflib
1
From: Alistair Francis <alistair23@gmail.com>
1
From: Bin Meng <bin.meng@windriver.com>
2
2
3
When running the instruction
3
Previously IOSCB_CFG was created as an unimplemented device. With
4
the new IOSCB model, its memory range is already covered by the
5
IOSCB hence remove the previous unimplemented device creation in
6
the SoC codes.
4
7
5
```
8
Signed-off-by: Bin Meng <bin.meng@windriver.com>
6
cbo.flush 0(x0)
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
7
```
10
Message-id: 1603863010-15807-6-git-send-email-bmeng.cn@gmail.com
8
9
QEMU would segfault.
10
11
The issue was in cpu_gpr[a->rs1] as QEMU does not have cpu_gpr[0]
12
allocated.
13
14
In order to fix this let's use the existing get_address()
15
helper. This also has the benefit of performing pointer mask
16
calculations on the address specified in rs1.
17
18
The pointer masking specificiation specifically states:
19
20
"""
21
Cache Management Operations: All instructions in Zicbom, Zicbop and Zicboz
22
"""
23
24
So this is the correct behaviour and we previously have been incorrectly
25
not masking the address.
26
27
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
28
Reported-by: Fabian Thomas <fabian.thomas@cispa.de>
29
Fixes: e05da09b7cfd ("target/riscv: implement Zicbom extension")
30
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
31
Cc: qemu-stable <qemu-stable@nongnu.org>
32
Message-ID: <20240514023910.301766-1-alistair.francis@wdc.com>
33
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
34
---
12
---
35
target/riscv/insn_trans/trans_rvzicbo.c.inc | 16 ++++++++++++----
13
include/hw/riscv/microchip_pfsoc.h | 4 +++-
36
1 file changed, 12 insertions(+), 4 deletions(-)
14
hw/riscv/microchip_pfsoc.c | 13 ++++++++-----
15
hw/riscv/Kconfig | 1 +
16
3 files changed, 12 insertions(+), 6 deletions(-)
37
17
38
diff --git a/target/riscv/insn_trans/trans_rvzicbo.c.inc b/target/riscv/insn_trans/trans_rvzicbo.c.inc
18
diff --git a/include/hw/riscv/microchip_pfsoc.h b/include/hw/riscv/microchip_pfsoc.h
39
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
40
--- a/target/riscv/insn_trans/trans_rvzicbo.c.inc
20
--- a/include/hw/riscv/microchip_pfsoc.h
41
+++ b/target/riscv/insn_trans/trans_rvzicbo.c.inc
21
+++ b/include/hw/riscv/microchip_pfsoc.h
42
@@ -XXX,XX +XXX,XX @@
22
@@ -XXX,XX +XXX,XX @@
43
static bool trans_cbo_clean(DisasContext *ctx, arg_cbo_clean *a)
23
#include "hw/char/mchp_pfsoc_mmuart.h"
44
{
24
#include "hw/dma/sifive_pdma.h"
45
REQUIRE_ZICBOM(ctx);
25
#include "hw/misc/mchp_pfsoc_dmc.h"
46
- gen_helper_cbo_clean_flush(tcg_env, cpu_gpr[a->rs1]);
26
+#include "hw/misc/mchp_pfsoc_ioscb.h"
47
+ TCGv src = get_address(ctx, a->rs1, 0);
27
#include "hw/net/cadence_gem.h"
28
#include "hw/sd/cadence_sdhci.h"
29
30
@@ -XXX,XX +XXX,XX @@ typedef struct MicrochipPFSoCState {
31
DeviceState *plic;
32
MchpPfSoCDdrSgmiiPhyState ddr_sgmii_phy;
33
MchpPfSoCDdrCfgState ddr_cfg;
34
+ MchpPfSoCIoscbState ioscb;
35
MchpPfSoCMMUartState *serial0;
36
MchpPfSoCMMUartState *serial1;
37
MchpPfSoCMMUartState *serial2;
38
@@ -XXX,XX +XXX,XX @@ enum {
39
MICROCHIP_PFSOC_GPIO2,
40
MICROCHIP_PFSOC_ENVM_CFG,
41
MICROCHIP_PFSOC_ENVM_DATA,
42
- MICROCHIP_PFSOC_IOSCB_CFG,
43
+ MICROCHIP_PFSOC_IOSCB,
44
MICROCHIP_PFSOC_DRAM,
45
};
46
47
diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c
48
index XXXXXXX..XXXXXXX 100644
49
--- a/hw/riscv/microchip_pfsoc.c
50
+++ b/hw/riscv/microchip_pfsoc.c
51
@@ -XXX,XX +XXX,XX @@
52
* 5) SiFive Platform DMA (Direct Memory Access Controller)
53
* 6) GEM (Gigabit Ethernet MAC Controller)
54
* 7) DMC (DDR Memory Controller)
55
+ * 8) IOSCB modules
56
*
57
* This board currently generates devicetree dynamically that indicates at least
58
* two harts and up to five harts.
59
@@ -XXX,XX +XXX,XX @@ static const struct MemmapEntry {
60
[MICROCHIP_PFSOC_GPIO2] = { 0x20122000, 0x1000 },
61
[MICROCHIP_PFSOC_ENVM_CFG] = { 0x20200000, 0x1000 },
62
[MICROCHIP_PFSOC_ENVM_DATA] = { 0x20220000, 0x20000 },
63
- [MICROCHIP_PFSOC_IOSCB_CFG] = { 0x37080000, 0x1000 },
64
+ [MICROCHIP_PFSOC_IOSCB] = { 0x30000000, 0x10000000 },
65
[MICROCHIP_PFSOC_DRAM] = { 0x80000000, 0x0 },
66
};
67
68
@@ -XXX,XX +XXX,XX @@ static void microchip_pfsoc_soc_instance_init(Object *obj)
69
70
object_initialize_child(obj, "sd-controller", &s->sdhci,
71
TYPE_CADENCE_SDHCI);
48
+
72
+
49
+ gen_helper_cbo_clean_flush(tcg_env, src);
73
+ object_initialize_child(obj, "ioscb", &s->ioscb, TYPE_MCHP_PFSOC_IOSCB);
50
return true;
51
}
74
}
52
75
53
static bool trans_cbo_flush(DisasContext *ctx, arg_cbo_flush *a)
76
static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
54
{
77
@@ -XXX,XX +XXX,XX @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
55
REQUIRE_ZICBOM(ctx);
78
memmap[MICROCHIP_PFSOC_ENVM_DATA].base,
56
- gen_helper_cbo_clean_flush(tcg_env, cpu_gpr[a->rs1]);
79
envm_data);
57
+ TCGv src = get_address(ctx, a->rs1, 0);
80
58
+
81
- /* IOSCBCFG */
59
+ gen_helper_cbo_clean_flush(tcg_env, src);
82
- create_unimplemented_device("microchip.pfsoc.ioscb.cfg",
60
return true;
83
- memmap[MICROCHIP_PFSOC_IOSCB_CFG].base,
84
- memmap[MICROCHIP_PFSOC_IOSCB_CFG].size);
85
+ /* IOSCB */
86
+ sysbus_realize(SYS_BUS_DEVICE(&s->ioscb), errp);
87
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->ioscb), 0,
88
+ memmap[MICROCHIP_PFSOC_IOSCB].base);
61
}
89
}
62
90
63
static bool trans_cbo_inval(DisasContext *ctx, arg_cbo_inval *a)
91
static void microchip_pfsoc_soc_class_init(ObjectClass *oc, void *data)
64
{
92
diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig
65
REQUIRE_ZICBOM(ctx);
93
index XXXXXXX..XXXXXXX 100644
66
- gen_helper_cbo_inval(tcg_env, cpu_gpr[a->rs1]);
94
--- a/hw/riscv/Kconfig
67
+ TCGv src = get_address(ctx, a->rs1, 0);
95
+++ b/hw/riscv/Kconfig
68
+
96
@@ -XXX,XX +XXX,XX @@ config MICROCHIP_PFSOC
69
+ gen_helper_cbo_inval(tcg_env, src);
97
bool
70
return true;
98
select CADENCE_SDHCI
71
}
99
select MCHP_PFSOC_DMC
72
100
+ select MCHP_PFSOC_IOSCB
73
static bool trans_cbo_zero(DisasContext *ctx, arg_cbo_zero *a)
101
select MCHP_PFSOC_MMUART
74
{
102
select MSI_NONBROKEN
75
REQUIRE_ZICBOZ(ctx);
103
select SIFIVE_CLINT
76
- gen_helper_cbo_zero(tcg_env, cpu_gpr[a->rs1]);
77
+ TCGv src = get_address(ctx, a->rs1, 0);
78
+
79
+ gen_helper_cbo_zero(tcg_env, src);
80
return true;
81
}
82
--
104
--
83
2.45.1
105
2.28.0
106
107
diff view generated by jsdifflib
1
From: Andrew Jones <ajones@ventanamicro.com>
1
From: Bin Meng <bin.meng@windriver.com>
2
2
3
The Zkr extension may only be exposed to KVM guests if the VMM
3
This creates a minimum model for Microchip PolarFire SoC SYSREG
4
implements the SEED CSR. Use the same implementation as TCG.
4
module. It only implements the ENVM_CR register to tell guest
5
5
software that eNVM is running at the configured divider rate.
6
Without this patch, running with a KVM which does not forward the
6
7
SEED CSR access to QEMU will result in an ILL exception being
7
Signed-off-by: Bin Meng <bin.meng@windriver.com>
8
injected into the guest (this results in Linux guests crashing on
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
boot). And, when running with a KVM which does forward the access,
9
Message-id: 1603863010-15807-7-git-send-email-bmeng.cn@gmail.com
10
QEMU will crash, since QEMU doesn't know what to do with the exit.
11
12
Fixes: 3108e2f1c69d ("target/riscv/kvm: update KVM exts to Linux 6.8")
13
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
14
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
15
Cc: qemu-stable <qemu-stable@nongnu.org>
16
Message-ID: <20240422134605.534207-2-ajones@ventanamicro.com>
17
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
18
---
11
---
19
target/riscv/cpu.h | 3 +++
12
include/hw/misc/mchp_pfsoc_sysreg.h | 39 ++++++++++++
20
target/riscv/csr.c | 18 ++++++++++++++----
13
hw/misc/mchp_pfsoc_sysreg.c | 99 +++++++++++++++++++++++++++++
21
target/riscv/kvm/kvm-cpu.c | 25 +++++++++++++++++++++++++
14
MAINTAINERS | 2 +
22
3 files changed, 42 insertions(+), 4 deletions(-)
15
hw/misc/Kconfig | 3 +
23
16
hw/misc/meson.build | 1 +
24
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
17
5 files changed, 144 insertions(+)
25
index XXXXXXX..XXXXXXX 100644
18
create mode 100644 include/hw/misc/mchp_pfsoc_sysreg.h
26
--- a/target/riscv/cpu.h
19
create mode 100644 hw/misc/mchp_pfsoc_sysreg.c
27
+++ b/target/riscv/cpu.h
20
28
@@ -XXX,XX +XXX,XX @@ void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops);
21
diff --git a/include/hw/misc/mchp_pfsoc_sysreg.h b/include/hw/misc/mchp_pfsoc_sysreg.h
29
22
new file mode 100644
30
void riscv_cpu_register_gdb_regs_for_features(CPUState *cs);
23
index XXXXXXX..XXXXXXX
31
24
--- /dev/null
32
+target_ulong riscv_new_csr_seed(target_ulong new_value,
25
+++ b/include/hw/misc/mchp_pfsoc_sysreg.h
33
+ target_ulong write_mask);
26
@@ -XXX,XX +XXX,XX @@
34
+
27
+/*
35
uint8_t satp_mode_max_from_map(uint32_t map);
28
+ * Microchip PolarFire SoC SYSREG module emulation
36
const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit);
29
+ *
37
30
+ * Copyright (c) 2020 Wind River Systems, Inc.
38
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
31
+ *
39
index XXXXXXX..XXXXXXX 100644
32
+ * Author:
40
--- a/target/riscv/csr.c
33
+ * Bin Meng <bin.meng@windriver.com>
41
+++ b/target/riscv/csr.c
34
+ *
42
@@ -XXX,XX +XXX,XX @@ static RISCVException write_upmbase(CPURISCVState *env, int csrno,
35
+ * This program is free software; you can redistribute it and/or
43
#endif
36
+ * modify it under the terms of the GNU General Public License as
44
37
+ * published by the Free Software Foundation; either version 2 or
45
/* Crypto Extension */
38
+ * (at your option) version 3 of the License.
46
-static RISCVException rmw_seed(CPURISCVState *env, int csrno,
39
+ *
47
- target_ulong *ret_value,
40
+ * This program is distributed in the hope that it will be useful,
48
- target_ulong new_value,
41
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
49
- target_ulong write_mask)
42
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50
+target_ulong riscv_new_csr_seed(target_ulong new_value,
43
+ * GNU General Public License for more details.
51
+ target_ulong write_mask)
44
+ *
52
{
45
+ * You should have received a copy of the GNU General Public License along
53
uint16_t random_v;
46
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
54
Error *random_e = NULL;
47
+ */
55
@@ -XXX,XX +XXX,XX @@ static RISCVException rmw_seed(CPURISCVState *env, int csrno,
48
+
56
rval = random_v | SEED_OPST_ES16;
49
+#ifndef MCHP_PFSOC_SYSREG_H
57
}
50
+#define MCHP_PFSOC_SYSREG_H
58
51
+
59
+ return rval;
52
+#define MCHP_PFSOC_SYSREG_REG_SIZE 0x2000
60
+}
53
+
61
+
54
+typedef struct MchpPfSoCSysregState {
62
+static RISCVException rmw_seed(CPURISCVState *env, int csrno,
55
+ SysBusDevice parent;
63
+ target_ulong *ret_value,
56
+ MemoryRegion sysreg;
64
+ target_ulong new_value,
57
+} MchpPfSoCSysregState;
65
+ target_ulong write_mask)
58
+
66
+{
59
+#define TYPE_MCHP_PFSOC_SYSREG "mchp.pfsoc.sysreg"
67
+ target_ulong rval;
60
+
68
+
61
+#define MCHP_PFSOC_SYSREG(obj) \
69
+ rval = riscv_new_csr_seed(new_value, write_mask);
62
+ OBJECT_CHECK(MchpPfSoCSysregState, (obj), \
70
+
63
+ TYPE_MCHP_PFSOC_SYSREG)
71
if (ret_value) {
64
+
72
*ret_value = rval;
65
+#endif /* MCHP_PFSOC_SYSREG_H */
73
}
66
diff --git a/hw/misc/mchp_pfsoc_sysreg.c b/hw/misc/mchp_pfsoc_sysreg.c
74
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
67
new file mode 100644
75
index XXXXXXX..XXXXXXX 100644
68
index XXXXXXX..XXXXXXX
76
--- a/target/riscv/kvm/kvm-cpu.c
69
--- /dev/null
77
+++ b/target/riscv/kvm/kvm-cpu.c
70
+++ b/hw/misc/mchp_pfsoc_sysreg.c
78
@@ -XXX,XX +XXX,XX @@ static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run)
71
@@ -XXX,XX +XXX,XX @@
79
return ret;
72
+/*
80
}
73
+ * Microchip PolarFire SoC SYSREG module emulation
81
74
+ *
82
+static int kvm_riscv_handle_csr(CPUState *cs, struct kvm_run *run)
75
+ * Copyright (c) 2020 Wind River Systems, Inc.
83
+{
76
+ *
84
+ target_ulong csr_num = run->riscv_csr.csr_num;
77
+ * Author:
85
+ target_ulong new_value = run->riscv_csr.new_value;
78
+ * Bin Meng <bin.meng@windriver.com>
86
+ target_ulong write_mask = run->riscv_csr.write_mask;
79
+ *
87
+ int ret = 0;
80
+ * This program is free software; you can redistribute it and/or
88
+
81
+ * modify it under the terms of the GNU General Public License as
89
+ switch (csr_num) {
82
+ * published by the Free Software Foundation; either version 2 or
90
+ case CSR_SEED:
83
+ * (at your option) version 3 of the License.
91
+ run->riscv_csr.ret_value = riscv_new_csr_seed(new_value, write_mask);
84
+ *
85
+ * This program is distributed in the hope that it will be useful,
86
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
87
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
88
+ * GNU General Public License for more details.
89
+ *
90
+ * You should have received a copy of the GNU General Public License along
91
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
92
+ */
93
+
94
+#include "qemu/osdep.h"
95
+#include "qemu/bitops.h"
96
+#include "qemu/log.h"
97
+#include "qapi/error.h"
98
+#include "hw/hw.h"
99
+#include "hw/sysbus.h"
100
+#include "hw/misc/mchp_pfsoc_sysreg.h"
101
+
102
+#define ENVM_CR 0xb8
103
+
104
+static uint64_t mchp_pfsoc_sysreg_read(void *opaque, hwaddr offset,
105
+ unsigned size)
106
+{
107
+ uint32_t val = 0;
108
+
109
+ switch (offset) {
110
+ case ENVM_CR:
111
+ /* Indicate the eNVM is running at the configured divider rate */
112
+ val = BIT(6);
92
+ break;
113
+ break;
93
+ default:
114
+ default:
94
+ qemu_log_mask(LOG_UNIMP,
115
+ qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read "
95
+ "%s: un-handled CSR EXIT for CSR %lx\n",
116
+ "(size %d, offset 0x%" HWADDR_PRIx ")\n",
96
+ __func__, csr_num);
117
+ __func__, size, offset);
97
+ ret = -1;
98
+ break;
118
+ break;
99
+ }
119
+ }
100
+
120
+
101
+ return ret;
121
+ return val;
102
+}
122
+}
103
+
123
+
104
int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
124
+static void mchp_pfsoc_sysreg_write(void *opaque, hwaddr offset,
105
{
125
+ uint64_t value, unsigned size)
106
int ret = 0;
126
+{
107
@@ -XXX,XX +XXX,XX @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
127
+ qemu_log_mask(LOG_UNIMP, "%s: unimplemented device write "
108
case KVM_EXIT_RISCV_SBI:
128
+ "(size %d, value 0x%" PRIx64
109
ret = kvm_riscv_handle_sbi(cs, run);
129
+ ", offset 0x%" HWADDR_PRIx ")\n",
110
break;
130
+ __func__, size, value, offset);
111
+ case KVM_EXIT_RISCV_CSR:
131
+}
112
+ ret = kvm_riscv_handle_csr(cs, run);
132
+
113
+ break;
133
+static const MemoryRegionOps mchp_pfsoc_sysreg_ops = {
114
default:
134
+ .read = mchp_pfsoc_sysreg_read,
115
qemu_log_mask(LOG_UNIMP, "%s: un-handled exit reason %d\n",
135
+ .write = mchp_pfsoc_sysreg_write,
116
__func__, run->exit_reason);
136
+ .endianness = DEVICE_LITTLE_ENDIAN,
137
+};
138
+
139
+static void mchp_pfsoc_sysreg_realize(DeviceState *dev, Error **errp)
140
+{
141
+ MchpPfSoCSysregState *s = MCHP_PFSOC_SYSREG(dev);
142
+
143
+ memory_region_init_io(&s->sysreg, OBJECT(dev),
144
+ &mchp_pfsoc_sysreg_ops, s,
145
+ "mchp.pfsoc.sysreg",
146
+ MCHP_PFSOC_SYSREG_REG_SIZE);
147
+ sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->sysreg);
148
+}
149
+
150
+static void mchp_pfsoc_sysreg_class_init(ObjectClass *klass, void *data)
151
+{
152
+ DeviceClass *dc = DEVICE_CLASS(klass);
153
+
154
+ dc->desc = "Microchip PolarFire SoC SYSREG module";
155
+ dc->realize = mchp_pfsoc_sysreg_realize;
156
+}
157
+
158
+static const TypeInfo mchp_pfsoc_sysreg_info = {
159
+ .name = TYPE_MCHP_PFSOC_SYSREG,
160
+ .parent = TYPE_SYS_BUS_DEVICE,
161
+ .instance_size = sizeof(MchpPfSoCSysregState),
162
+ .class_init = mchp_pfsoc_sysreg_class_init,
163
+};
164
+
165
+static void mchp_pfsoc_sysreg_register_types(void)
166
+{
167
+ type_register_static(&mchp_pfsoc_sysreg_info);
168
+}
169
+
170
+type_init(mchp_pfsoc_sysreg_register_types)
171
diff --git a/MAINTAINERS b/MAINTAINERS
172
index XXXXXXX..XXXXXXX 100644
173
--- a/MAINTAINERS
174
+++ b/MAINTAINERS
175
@@ -XXX,XX +XXX,XX @@ F: hw/riscv/microchip_pfsoc.c
176
F: hw/char/mchp_pfsoc_mmuart.c
177
F: hw/misc/mchp_pfsoc_dmc.c
178
F: hw/misc/mchp_pfsoc_ioscb.c
179
+F: hw/misc/mchp_pfsoc_sysreg.c
180
F: include/hw/riscv/microchip_pfsoc.h
181
F: include/hw/char/mchp_pfsoc_mmuart.h
182
F: include/hw/misc/mchp_pfsoc_dmc.h
183
F: include/hw/misc/mchp_pfsoc_ioscb.h
184
+F: include/hw/misc/mchp_pfsoc_sysreg.h
185
186
RX Machines
187
-----------
188
diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig
189
index XXXXXXX..XXXXXXX 100644
190
--- a/hw/misc/Kconfig
191
+++ b/hw/misc/Kconfig
192
@@ -XXX,XX +XXX,XX @@ config MCHP_PFSOC_DMC
193
config MCHP_PFSOC_IOSCB
194
bool
195
196
+config MCHP_PFSOC_SYSREG
197
+ bool
198
+
199
config SIFIVE_TEST
200
bool
201
202
diff --git a/hw/misc/meson.build b/hw/misc/meson.build
203
index XXXXXXX..XXXXXXX 100644
204
--- a/hw/misc/meson.build
205
+++ b/hw/misc/meson.build
206
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_MOS6522', if_true: files('mos6522.c'))
207
# RISC-V devices
208
softmmu_ss.add(when: 'CONFIG_MCHP_PFSOC_DMC', if_true: files('mchp_pfsoc_dmc.c'))
209
softmmu_ss.add(when: 'CONFIG_MCHP_PFSOC_IOSCB', if_true: files('mchp_pfsoc_ioscb.c'))
210
+softmmu_ss.add(when: 'CONFIG_MCHP_PFSOC_SYSREG', if_true: files('mchp_pfsoc_sysreg.c'))
211
softmmu_ss.add(when: 'CONFIG_SIFIVE_TEST', if_true: files('sifive_test.c'))
212
softmmu_ss.add(when: 'CONFIG_SIFIVE_E_PRCI', if_true: files('sifive_e_prci.c'))
213
softmmu_ss.add(when: 'CONFIG_SIFIVE_U_OTP', if_true: files('sifive_u_otp.c'))
117
--
214
--
118
2.45.1
215
2.28.0
216
217
diff view generated by jsdifflib
Deleted patch
1
From: Cheng Yang <yangcheng.work@foxmail.com>
2
1
3
Use qemu_fdt_setprop_u64() instead of qemu_fdt_setprop_cell()
4
to set the address of initrd in FDT to support 64-bit address.
5
6
Signed-off-by: Cheng Yang <yangcheng.work@foxmail.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Message-ID: <tencent_A4482251DD0890F312758FA6B33F60815609@qq.com>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
---
11
hw/riscv/boot.c | 4 ++--
12
1 file changed, 2 insertions(+), 2 deletions(-)
13
14
diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/riscv/boot.c
17
+++ b/hw/riscv/boot.c
18
@@ -XXX,XX +XXX,XX @@ static void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry)
19
/* Some RISC-V machines (e.g. opentitan) don't have a fdt. */
20
if (fdt) {
21
end = start + size;
22
- qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-start", start);
23
- qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-end", end);
24
+ qemu_fdt_setprop_u64(fdt, "/chosen", "linux,initrd-start", start);
25
+ qemu_fdt_setprop_u64(fdt, "/chosen", "linux,initrd-end", end);
26
}
27
}
28
29
--
30
2.45.1
diff view generated by jsdifflib
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
From: Bin Meng <bin.meng@windriver.com>
2
2
3
Commit 33a24910ae changed 'reg_width' to use 'vlenb', i.e. vector length
3
Previously SYSREG was created as an unimplemented device. Now that
4
in bytes, when in this context we want 'reg_width' as the length in
4
we have a simple SYSREG module, connect it.
5
bits.
6
5
7
Fix 'reg_width' back to the value in bits like 7cb59921c05a
6
Signed-off-by: Bin Meng <bin.meng@windriver.com>
8
("target/riscv/gdbstub.c: use 'vlenb' instead of shifting 'vlen'") set
9
beforehand.
10
11
While we're at it, rename 'reg_width' to 'bitsize' to provide a bit more
12
clarity about what the variable represents. 'bitsize' is also used in
13
riscv_gen_dynamic_csr_feature() with the same purpose, i.e. as an input to
14
gdb_feature_builder_append_reg().
15
16
Cc: Akihiko Odaki <akihiko.odaki@daynix.com>
17
Cc: Alex Bennée <alex.bennee@linaro.org>
18
Reported-by: Robin Dapp <rdapp.gcc@gmail.com>
19
Fixes: 33a24910ae ("target/riscv: Use GDBFeature for dynamic XML")
20
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
21
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
22
Acked-by: Alex Bennée <alex.bennee@linaro.org>
23
Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
24
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
25
Cc: qemu-stable <qemu-stable@nongnu.org>
8
Message-id: 1603863010-15807-8-git-send-email-bmeng.cn@gmail.com
26
Message-ID: <20240517203054.880861-2-dbarboza@ventanamicro.com>
27
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
9
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
28
---
10
---
29
target/riscv/gdbstub.c | 6 +++---
11
include/hw/riscv/microchip_pfsoc.h | 2 ++
30
1 file changed, 3 insertions(+), 3 deletions(-)
12
hw/riscv/microchip_pfsoc.c | 9 ++++++---
13
hw/riscv/Kconfig | 1 +
14
3 files changed, 9 insertions(+), 3 deletions(-)
31
15
32
diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c
16
diff --git a/include/hw/riscv/microchip_pfsoc.h b/include/hw/riscv/microchip_pfsoc.h
33
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
34
--- a/target/riscv/gdbstub.c
18
--- a/include/hw/riscv/microchip_pfsoc.h
35
+++ b/target/riscv/gdbstub.c
19
+++ b/include/hw/riscv/microchip_pfsoc.h
36
@@ -XXX,XX +XXX,XX @@ static GDBFeature *riscv_gen_dynamic_csr_feature(CPUState *cs, int base_reg)
20
@@ -XXX,XX +XXX,XX @@
37
static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg)
21
#include "hw/dma/sifive_pdma.h"
38
{
22
#include "hw/misc/mchp_pfsoc_dmc.h"
39
RISCVCPU *cpu = RISCV_CPU(cs);
23
#include "hw/misc/mchp_pfsoc_ioscb.h"
40
- int reg_width = cpu->cfg.vlenb;
24
+#include "hw/misc/mchp_pfsoc_sysreg.h"
41
+ int bitsize = cpu->cfg.vlenb << 3;
25
#include "hw/net/cadence_gem.h"
42
GDBFeatureBuilder builder;
26
#include "hw/sd/cadence_sdhci.h"
43
int i;
27
44
28
@@ -XXX,XX +XXX,XX @@ typedef struct MicrochipPFSoCState {
45
@@ -XXX,XX +XXX,XX @@ static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg)
29
MchpPfSoCMMUartState *serial2;
46
30
MchpPfSoCMMUartState *serial3;
47
/* First define types and totals in a whole VL */
31
MchpPfSoCMMUartState *serial4;
48
for (i = 0; i < ARRAY_SIZE(vec_lanes); i++) {
32
+ MchpPfSoCSysregState sysreg;
49
- int count = reg_width / vec_lanes[i].size;
33
SiFivePDMAState dma;
50
+ int count = bitsize / vec_lanes[i].size;
34
CadenceGEMState gem0;
51
gdb_feature_builder_append_tag(
35
CadenceGEMState gem1;
52
&builder, "<vector id=\"%s\" type=\"%s\" count=\"%d\"/>",
36
diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c
53
vec_lanes[i].id, vec_lanes[i].gdb_type, count);
37
index XXXXXXX..XXXXXXX 100644
54
@@ -XXX,XX +XXX,XX @@ static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg)
38
--- a/hw/riscv/microchip_pfsoc.c
55
/* Define vector registers */
39
+++ b/hw/riscv/microchip_pfsoc.c
56
for (i = 0; i < 32; i++) {
40
@@ -XXX,XX +XXX,XX @@ static void microchip_pfsoc_soc_instance_init(Object *obj)
57
gdb_feature_builder_append_reg(&builder, g_strdup_printf("v%d", i),
41
object_initialize_child(obj, "dma-controller", &s->dma,
58
- reg_width, i, "riscv_vector", "vector");
42
TYPE_SIFIVE_PDMA);
59
+ bitsize, i, "riscv_vector", "vector");
43
44
+ object_initialize_child(obj, "sysreg", &s->sysreg,
45
+ TYPE_MCHP_PFSOC_SYSREG);
46
+
47
object_initialize_child(obj, "ddr-sgmii-phy", &s->ddr_sgmii_phy,
48
TYPE_MCHP_PFSOC_DDR_SGMII_PHY);
49
object_initialize_child(obj, "ddr-cfg", &s->ddr_cfg,
50
@@ -XXX,XX +XXX,XX @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
60
}
51
}
61
52
62
gdb_feature_builder_end(&builder);
53
/* SYSREG */
54
- create_unimplemented_device("microchip.pfsoc.sysreg",
55
- memmap[MICROCHIP_PFSOC_SYSREG].base,
56
- memmap[MICROCHIP_PFSOC_SYSREG].size);
57
+ sysbus_realize(SYS_BUS_DEVICE(&s->sysreg), errp);
58
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->sysreg), 0,
59
+ memmap[MICROCHIP_PFSOC_SYSREG].base);
60
61
/* MPUCFG */
62
create_unimplemented_device("microchip.pfsoc.mpucfg",
63
diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig
64
index XXXXXXX..XXXXXXX 100644
65
--- a/hw/riscv/Kconfig
66
+++ b/hw/riscv/Kconfig
67
@@ -XXX,XX +XXX,XX @@ config MICROCHIP_PFSOC
68
select MCHP_PFSOC_DMC
69
select MCHP_PFSOC_IOSCB
70
select MCHP_PFSOC_MMUART
71
+ select MCHP_PFSOC_SYSREG
72
select MSI_NONBROKEN
73
select SIFIVE_CLINT
74
select SIFIVE_PDMA
63
--
75
--
64
2.45.1
76
2.28.0
65
77
66
78
diff view generated by jsdifflib
1
From: Yangyu Chen <cyy@cyyself.name>
1
From: Bin Meng <bin.meng@windriver.com>
2
2
3
This code has a typo that writes zvkb to zvkg, causing users can't
3
Somehow HSS needs to access address 0 [1] for the DDR calibration data
4
enable zvkb through the config. This patch gets this fixed.
4
which is in the chipset's reserved memory. Let's map it.
5
5
6
Signed-off-by: Yangyu Chen <cyy@cyyself.name>
6
[1] See the config_copy() calls in various places in ddr_setup() in
7
Fixes: ea61ef7097d0 ("target/riscv: Move vector crypto extensions to riscv_cpu_extensions")
7
the HSS source codes.
8
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
8
9
Signed-off-by: Bin Meng <bin.meng@windriver.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Reviewed-by: Max Chou <max.chou@sifive.com>
11
Message-id: 1603863010-15807-9-git-send-email-bmeng.cn@gmail.com
11
Reviewed-by:  Weiwei Li <liwei1518@gmail.com>
12
Message-ID: <tencent_7E34EEF0F90B9A68BF38BEE09EC6D4877C0A@qq.com>
13
Cc: qemu-stable <qemu-stable@nongnu.org>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
---
13
---
16
target/riscv/cpu.c | 2 +-
14
include/hw/riscv/microchip_pfsoc.h | 1 +
17
1 file changed, 1 insertion(+), 1 deletion(-)
15
hw/riscv/microchip_pfsoc.c | 11 ++++++++++-
16
2 files changed, 11 insertions(+), 1 deletion(-)
18
17
19
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
18
diff --git a/include/hw/riscv/microchip_pfsoc.h b/include/hw/riscv/microchip_pfsoc.h
20
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
21
--- a/target/riscv/cpu.c
20
--- a/include/hw/riscv/microchip_pfsoc.h
22
+++ b/target/riscv/cpu.c
21
+++ b/include/hw/riscv/microchip_pfsoc.h
23
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
22
@@ -XXX,XX +XXX,XX @@ typedef struct MicrochipIcicleKitState {
24
/* Vector cryptography extensions */
23
TYPE_MICROCHIP_ICICLE_KIT_MACHINE)
25
MULTI_EXT_CFG_BOOL("zvbb", ext_zvbb, false),
24
26
MULTI_EXT_CFG_BOOL("zvbc", ext_zvbc, false),
25
enum {
27
- MULTI_EXT_CFG_BOOL("zvkb", ext_zvkg, false),
26
+ MICROCHIP_PFSOC_RSVD0,
28
+ MULTI_EXT_CFG_BOOL("zvkb", ext_zvkb, false),
27
MICROCHIP_PFSOC_DEBUG,
29
MULTI_EXT_CFG_BOOL("zvkg", ext_zvkg, false),
28
MICROCHIP_PFSOC_E51_DTIM,
30
MULTI_EXT_CFG_BOOL("zvkned", ext_zvkned, false),
29
MICROCHIP_PFSOC_BUSERR_UNIT0,
31
MULTI_EXT_CFG_BOOL("zvknha", ext_zvknha, false),
30
diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c
31
index XXXXXXX..XXXXXXX 100644
32
--- a/hw/riscv/microchip_pfsoc.c
33
+++ b/hw/riscv/microchip_pfsoc.c
34
@@ -XXX,XX +XXX,XX @@ static const struct MemmapEntry {
35
hwaddr base;
36
hwaddr size;
37
} microchip_pfsoc_memmap[] = {
38
- [MICROCHIP_PFSOC_DEBUG] = { 0x0, 0x1000 },
39
+ [MICROCHIP_PFSOC_RSVD0] = { 0x0, 0x100 },
40
+ [MICROCHIP_PFSOC_DEBUG] = { 0x100, 0xf00 },
41
[MICROCHIP_PFSOC_E51_DTIM] = { 0x1000000, 0x2000 },
42
[MICROCHIP_PFSOC_BUSERR_UNIT0] = { 0x1700000, 0x1000 },
43
[MICROCHIP_PFSOC_BUSERR_UNIT1] = { 0x1701000, 0x1000 },
44
@@ -XXX,XX +XXX,XX @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
45
MicrochipPFSoCState *s = MICROCHIP_PFSOC(dev);
46
const struct MemmapEntry *memmap = microchip_pfsoc_memmap;
47
MemoryRegion *system_memory = get_system_memory();
48
+ MemoryRegion *rsvd0_mem = g_new(MemoryRegion, 1);
49
MemoryRegion *e51_dtim_mem = g_new(MemoryRegion, 1);
50
MemoryRegion *l2lim_mem = g_new(MemoryRegion, 1);
51
MemoryRegion *envm_data = g_new(MemoryRegion, 1);
52
@@ -XXX,XX +XXX,XX @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
53
qdev_realize(DEVICE(&s->e_cluster), NULL, &error_abort);
54
qdev_realize(DEVICE(&s->u_cluster), NULL, &error_abort);
55
56
+ /* Reserved Memory at address 0 */
57
+ memory_region_init_ram(rsvd0_mem, NULL, "microchip.pfsoc.rsvd0_mem",
58
+ memmap[MICROCHIP_PFSOC_RSVD0].size, &error_fatal);
59
+ memory_region_add_subregion(system_memory,
60
+ memmap[MICROCHIP_PFSOC_RSVD0].base,
61
+ rsvd0_mem);
62
+
63
/* E51 DTIM */
64
memory_region_init_ram(e51_dtim_mem, NULL, "microchip.pfsoc.e51_dtim_mem",
65
memmap[MICROCHIP_PFSOC_E51_DTIM].size, &error_fatal);
32
--
66
--
33
2.45.1
67
2.28.0
34
68
35
69
diff view generated by jsdifflib
1
From: Huang Tao <eric.huang@linux.alibaba.com>
1
From: Bin Meng <bin.meng@windriver.com>
2
2
3
In RVV and vcrypto instructions, the masked and tail elements are set to 1s
3
When system memory is larger than 1 GiB (high memory), PolarFire SoC
4
using vext_set_elems_1s function if the vma/vta bit is set. It is the element
4
maps it at address 0x10_0000_0000. Address 0xC000_0000 and above is
5
agnostic policy.
5
aliased to the same 1 GiB low memory with different cache attributes.
6
6
7
However, this function can't deal the big endian situation. This patch fixes
7
At present QEMU maps the system memory contiguously from 0x8000_0000.
8
the problem by adding handling of such case.
8
This corrects the wrong QEMU logic. Note address 0x14_0000_0000 is
9
the alias to the high memory, and even physical memory is only 1 GiB,
10
the HSS codes still tries to probe the high memory alias address.
11
It seems there is no issue on the real hardware, so we will have to
12
take that into the consideration in our emulation. Due to this, we
13
we increase the default system memory size to 1537 MiB (the minimum
14
required high memory size by HSS) so that user gets notified an error
15
when less than 1537 MiB is specified.
9
16
10
Signed-off-by: Huang Tao <eric.huang@linux.alibaba.com>
17
Signed-off-by: Bin Meng <bin.meng@windriver.com>
11
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
18
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
12
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
19
Message-id: 20201101170538.3732-1-bmeng.cn@gmail.com
13
Cc: qemu-stable <qemu-stable@nongnu.org>
14
Message-ID: <20240325021654.6594-1-eric.huang@linux.alibaba.com>
15
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
20
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
16
---
21
---
17
target/riscv/vector_internals.c | 22 ++++++++++++++++++++++
22
include/hw/riscv/microchip_pfsoc.h | 5 ++-
18
1 file changed, 22 insertions(+)
23
hw/riscv/microchip_pfsoc.c | 50 ++++++++++++++++++++++++++----
24
2 files changed, 48 insertions(+), 7 deletions(-)
19
25
20
diff --git a/target/riscv/vector_internals.c b/target/riscv/vector_internals.c
26
diff --git a/include/hw/riscv/microchip_pfsoc.h b/include/hw/riscv/microchip_pfsoc.h
21
index XXXXXXX..XXXXXXX 100644
27
index XXXXXXX..XXXXXXX 100644
22
--- a/target/riscv/vector_internals.c
28
--- a/include/hw/riscv/microchip_pfsoc.h
23
+++ b/target/riscv/vector_internals.c
29
+++ b/include/hw/riscv/microchip_pfsoc.h
24
@@ -XXX,XX +XXX,XX @@ void vext_set_elems_1s(void *base, uint32_t is_agnostic, uint32_t cnt,
30
@@ -XXX,XX +XXX,XX @@ enum {
25
if (tot - cnt == 0) {
31
MICROCHIP_PFSOC_ENVM_CFG,
26
return ;
32
MICROCHIP_PFSOC_ENVM_DATA,
27
}
33
MICROCHIP_PFSOC_IOSCB,
34
- MICROCHIP_PFSOC_DRAM,
35
+ MICROCHIP_PFSOC_DRAM_LO,
36
+ MICROCHIP_PFSOC_DRAM_LO_ALIAS,
37
+ MICROCHIP_PFSOC_DRAM_HI,
38
+ MICROCHIP_PFSOC_DRAM_HI_ALIAS
39
};
40
41
enum {
42
diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c
43
index XXXXXXX..XXXXXXX 100644
44
--- a/hw/riscv/microchip_pfsoc.c
45
+++ b/hw/riscv/microchip_pfsoc.c
46
@@ -XXX,XX +XXX,XX @@ static const struct MemmapEntry {
47
[MICROCHIP_PFSOC_ENVM_CFG] = { 0x20200000, 0x1000 },
48
[MICROCHIP_PFSOC_ENVM_DATA] = { 0x20220000, 0x20000 },
49
[MICROCHIP_PFSOC_IOSCB] = { 0x30000000, 0x10000000 },
50
- [MICROCHIP_PFSOC_DRAM] = { 0x80000000, 0x0 },
51
+ [MICROCHIP_PFSOC_DRAM_LO] = { 0x80000000, 0x40000000 },
52
+ [MICROCHIP_PFSOC_DRAM_LO_ALIAS] = { 0xc0000000, 0x40000000 },
53
+ [MICROCHIP_PFSOC_DRAM_HI] = { 0x1000000000, 0x0 },
54
+ [MICROCHIP_PFSOC_DRAM_HI_ALIAS] = { 0x1400000000, 0x0 },
55
};
56
57
static void microchip_pfsoc_soc_instance_init(Object *obj)
58
@@ -XXX,XX +XXX,XX @@ static void microchip_icicle_kit_machine_init(MachineState *machine)
59
const struct MemmapEntry *memmap = microchip_pfsoc_memmap;
60
MicrochipIcicleKitState *s = MICROCHIP_ICICLE_KIT_MACHINE(machine);
61
MemoryRegion *system_memory = get_system_memory();
62
- MemoryRegion *main_mem = g_new(MemoryRegion, 1);
63
+ MemoryRegion *mem_low = g_new(MemoryRegion, 1);
64
+ MemoryRegion *mem_low_alias = g_new(MemoryRegion, 1);
65
+ MemoryRegion *mem_high = g_new(MemoryRegion, 1);
66
+ MemoryRegion *mem_high_alias = g_new(MemoryRegion, 1);
67
+ uint64_t mem_high_size;
68
DriveInfo *dinfo = drive_get_next(IF_SD);
69
70
/* Sanity check on RAM size */
71
@@ -XXX,XX +XXX,XX @@ static void microchip_icicle_kit_machine_init(MachineState *machine)
72
qdev_realize(DEVICE(&s->soc), NULL, &error_abort);
73
74
/* Register RAM */
75
- memory_region_init_ram(main_mem, NULL, "microchip.icicle.kit.ram",
76
- machine->ram_size, &error_fatal);
77
+ memory_region_init_ram(mem_low, NULL, "microchip.icicle.kit.ram_low",
78
+ memmap[MICROCHIP_PFSOC_DRAM_LO].size,
79
+ &error_fatal);
80
+ memory_region_init_alias(mem_low_alias, NULL,
81
+ "microchip.icicle.kit.ram_low.alias",
82
+ mem_low, 0,
83
+ memmap[MICROCHIP_PFSOC_DRAM_LO_ALIAS].size);
84
+ memory_region_add_subregion(system_memory,
85
+ memmap[MICROCHIP_PFSOC_DRAM_LO].base,
86
+ mem_low);
87
memory_region_add_subregion(system_memory,
88
- memmap[MICROCHIP_PFSOC_DRAM].base, main_mem);
89
+ memmap[MICROCHIP_PFSOC_DRAM_LO_ALIAS].base,
90
+ mem_low_alias);
28
+
91
+
29
+ if (HOST_BIG_ENDIAN) {
92
+ mem_high_size = machine->ram_size - 1 * GiB;
30
+ /*
93
+
31
+ * Deal the situation when the elements are insdie
94
+ memory_region_init_ram(mem_high, NULL, "microchip.icicle.kit.ram_high",
32
+ * only one uint64 block including setting the
95
+ mem_high_size, &error_fatal);
33
+ * masked-off element.
96
+ memory_region_init_alias(mem_high_alias, NULL,
34
+ */
97
+ "microchip.icicle.kit.ram_high.alias",
35
+ if (((tot - 1) ^ cnt) < 8) {
98
+ mem_high, 0, mem_high_size);
36
+ memset(base + H1(tot - 1), -1, tot - cnt);
99
+ memory_region_add_subregion(system_memory,
37
+ return;
100
+ memmap[MICROCHIP_PFSOC_DRAM_HI].base,
38
+ }
101
+ mem_high);
39
+ /*
102
+ memory_region_add_subregion(system_memory,
40
+ * Otherwise, at least cross two uint64_t blocks.
103
+ memmap[MICROCHIP_PFSOC_DRAM_HI_ALIAS].base,
41
+ * Set first unaligned block.
104
+ mem_high_alias);
42
+ */
105
43
+ if (cnt % 8 != 0) {
106
/* Load the firmware */
44
+ uint32_t j = ROUND_UP(cnt, 8);
107
riscv_find_and_load_firmware(machine, BIOS_FILENAME, RESET_VECTOR, NULL);
45
+ memset(base + H1(j - 1), -1, j - cnt);
108
@@ -XXX,XX +XXX,XX @@ static void microchip_icicle_kit_machine_class_init(ObjectClass *oc, void *data)
46
+ cnt = j;
109
MICROCHIP_PFSOC_COMPUTE_CPU_COUNT;
47
+ }
110
mc->min_cpus = MICROCHIP_PFSOC_MANAGEMENT_CPU_COUNT + 1;
48
+ /* Set other 64bit aligend blocks */
111
mc->default_cpus = mc->min_cpus;
49
+ }
112
- mc->default_ram_size = 1 * GiB;
50
memset(base + cnt, -1, tot - cnt);
113
+
114
+ /*
115
+ * Map 513 MiB high memory, the mimimum required high memory size, because
116
+ * HSS will do memory test against the high memory address range regardless
117
+ * of physical memory installed.
118
+ *
119
+ * See memory_tests() in mss_ddr.c in the HSS source code.
120
+ */
121
+ mc->default_ram_size = 1537 * MiB;
51
}
122
}
52
123
124
static const TypeInfo microchip_icicle_kit_machine_typeinfo = {
53
--
125
--
54
2.45.1
126
2.28.0
127
128
diff view generated by jsdifflib
1
From: Clément Léger <cleger@rivosinc.com>
1
From: Bin Meng <bin.meng@windriver.com>
2
2
3
The current semihost exception number (16) is a reserved number (range
3
The latest SD card image [1] released by Microchip ships a Linux
4
[16-17]). The upcoming double trap specification uses that number for
4
kernel with built-in PolarFire SoC I2C driver support. The device
5
the double trap exception. Since the privileged spec (Table 22) defines
5
tree file includes the description for the I2C1 node hence kernel
6
ranges for custom uses change the semihosting exception number to 63
6
tries to probe the I2C1 device during boot.
7
which belongs to the range [48-63] in order to avoid any future
8
collisions with reserved exception.
9
7
10
Signed-off-by: Clément Léger <cleger@rivosinc.com>
8
It is enough to create an unimplemented device for I2C1 to allow
9
the kernel to continue booting to the shell.
11
10
11
[1] ftp://ftpsoc.microsemi.com/outgoing/core-image-minimal-dev-icicle-kit-es-sd-20201009141623.rootfs.wic.gz
12
13
Signed-off-by: Bin Meng <bin.meng@windriver.com>
12
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
14
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
13
Message-ID: <20240422135840.1959967-1-cleger@rivosinc.com>
15
Message-id: 1603863010-15807-11-git-send-email-bmeng.cn@gmail.com
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
16
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
---
17
---
16
target/riscv/cpu_bits.h | 2 +-
18
include/hw/riscv/microchip_pfsoc.h | 1 +
17
1 file changed, 1 insertion(+), 1 deletion(-)
19
hw/riscv/microchip_pfsoc.c | 6 ++++++
20
2 files changed, 7 insertions(+)
18
21
19
diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
22
diff --git a/include/hw/riscv/microchip_pfsoc.h b/include/hw/riscv/microchip_pfsoc.h
20
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
21
--- a/target/riscv/cpu_bits.h
24
--- a/include/hw/riscv/microchip_pfsoc.h
22
+++ b/target/riscv/cpu_bits.h
25
+++ b/include/hw/riscv/microchip_pfsoc.h
23
@@ -XXX,XX +XXX,XX @@ typedef enum RISCVException {
26
@@ -XXX,XX +XXX,XX @@ enum {
24
RISCV_EXCP_INST_PAGE_FAULT = 0xc, /* since: priv-1.10.0 */
27
MICROCHIP_PFSOC_MMUART2,
25
RISCV_EXCP_LOAD_PAGE_FAULT = 0xd, /* since: priv-1.10.0 */
28
MICROCHIP_PFSOC_MMUART3,
26
RISCV_EXCP_STORE_PAGE_FAULT = 0xf, /* since: priv-1.10.0 */
29
MICROCHIP_PFSOC_MMUART4,
27
- RISCV_EXCP_SEMIHOST = 0x10,
30
+ MICROCHIP_PFSOC_I2C1,
28
RISCV_EXCP_INST_GUEST_PAGE_FAULT = 0x14,
31
MICROCHIP_PFSOC_GEM0,
29
RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT = 0x15,
32
MICROCHIP_PFSOC_GEM1,
30
RISCV_EXCP_VIRT_INSTRUCTION_FAULT = 0x16,
33
MICROCHIP_PFSOC_GPIO0,
31
RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT = 0x17,
34
diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c
32
+ RISCV_EXCP_SEMIHOST = 0x3f,
35
index XXXXXXX..XXXXXXX 100644
33
} RISCVException;
36
--- a/hw/riscv/microchip_pfsoc.c
34
37
+++ b/hw/riscv/microchip_pfsoc.c
35
#define RISCV_EXCP_INT_FLAG 0x80000000
38
@@ -XXX,XX +XXX,XX @@ static const struct MemmapEntry {
39
[MICROCHIP_PFSOC_MMUART2] = { 0x20102000, 0x1000 },
40
[MICROCHIP_PFSOC_MMUART3] = { 0x20104000, 0x1000 },
41
[MICROCHIP_PFSOC_MMUART4] = { 0x20106000, 0x1000 },
42
+ [MICROCHIP_PFSOC_I2C1] = { 0x2010b000, 0x1000 },
43
[MICROCHIP_PFSOC_GEM0] = { 0x20110000, 0x2000 },
44
[MICROCHIP_PFSOC_GEM1] = { 0x20112000, 0x2000 },
45
[MICROCHIP_PFSOC_GPIO0] = { 0x20120000, 0x1000 },
46
@@ -XXX,XX +XXX,XX @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
47
qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_MMUART4_IRQ),
48
serial_hd(4));
49
50
+ /* I2C1 */
51
+ create_unimplemented_device("microchip.pfsoc.i2c1",
52
+ memmap[MICROCHIP_PFSOC_I2C1].base,
53
+ memmap[MICROCHIP_PFSOC_I2C1].size);
54
+
55
/* GEMs */
56
57
nd = &nd_table[0];
36
--
58
--
37
2.45.1
59
2.28.0
38
60
39
61
diff view generated by jsdifflib
Deleted patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
1
3
Running a KVM guest using a 6.9-rc3 kernel, in a 6.8 host that has zkr
4
enabled, will fail with a kernel oops SIGILL right at the start. The
5
reason is that we can't expose zkr without implementing the SEED CSR.
6
Disabling zkr in the guest would be a workaround, but if the KVM doesn't
7
allow it we'll error out and never boot.
8
9
In hindsight this is too strict. If we keep proceeding, despite not
10
disabling the extension in the KVM vcpu, we'll not add the extension in
11
the riscv,isa. The guest kernel will be unaware of the extension, i.e.
12
it doesn't matter if the KVM vcpu has it enabled underneath or not. So
13
it's ok to keep booting in this case.
14
15
Change our current logic to not error out if we fail to disable an
16
extension in kvm_set_one_reg(), but show a warning and keep booting. It
17
is important to throw a warning because we must make the user aware that
18
the extension is still available in the vcpu, meaning that an
19
ill-behaved guest can ignore the riscv,isa settings and use the
20
extension.
21
22
The case we're handling happens with an EINVAL error code. If we fail to
23
disable the extension in KVM for any other reason, error out.
24
25
We'll also keep erroring out when we fail to enable an extension in KVM,
26
since adding the extension in riscv,isa at this point will cause a guest
27
malfunction because the extension isn't enabled in the vcpu.
28
29
Suggested-by: Andrew Jones <ajones@ventanamicro.com>
30
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
31
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
32
Cc: qemu-stable <qemu-stable@nongnu.org>
33
Message-ID: <20240422171425.333037-2-dbarboza@ventanamicro.com>
34
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
35
---
36
target/riscv/kvm/kvm-cpu.c | 12 ++++++++----
37
1 file changed, 8 insertions(+), 4 deletions(-)
38
39
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
40
index XXXXXXX..XXXXXXX 100644
41
--- a/target/riscv/kvm/kvm-cpu.c
42
+++ b/target/riscv/kvm/kvm-cpu.c
43
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs)
44
reg = kvm_cpu_cfg_get(cpu, multi_ext_cfg);
45
ret = kvm_set_one_reg(cs, id, &reg);
46
if (ret != 0) {
47
- error_report("Unable to %s extension %s in KVM, error %d",
48
- reg ? "enable" : "disable",
49
- multi_ext_cfg->name, ret);
50
- exit(EXIT_FAILURE);
51
+ if (!reg && ret == -EINVAL) {
52
+ warn_report("KVM cannot disable extension %s",
53
+ multi_ext_cfg->name);
54
+ } else {
55
+ error_report("Unable to enable extension %s in KVM, error %d",
56
+ multi_ext_cfg->name, ret);
57
+ exit(EXIT_FAILURE);
58
+ }
59
}
60
}
61
}
62
--
63
2.45.1
diff view generated by jsdifflib
Deleted patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
1
3
We're not setting (s/m)tval when triggering breakpoints of type 2
4
(mcontrol) and 6 (mcontrol6). According to the debug spec section
5
5.7.12, "Match Control Type 6":
6
7
"The Privileged Spec says that breakpoint exceptions that occur on
8
instruction fetches, loads, or stores update the tval CSR with either
9
zero or the faulting virtual address. The faulting virtual address for
10
an mcontrol6 trigger with action = 0 is the address being accessed and
11
which caused that trigger to fire."
12
13
A similar text is also found in the Debug spec section 5.7.11 w.r.t.
14
mcontrol.
15
16
Note that what we're doing ATM is not violating the spec, but it's
17
simple enough to set mtval/stval and it makes life easier for any
18
software that relies on this info.
19
20
Given that we always use action = 0, save the faulting address for the
21
mcontrol and mcontrol6 trigger breakpoints into env->badaddr, which is
22
used as as scratch area for traps with address information. 'tval' is
23
then set during riscv_cpu_do_interrupt().
24
25
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
26
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
27
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
28
Message-ID: <20240416230437.1869024-2-dbarboza@ventanamicro.com>
29
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
30
---
31
target/riscv/cpu_helper.c | 1 +
32
target/riscv/debug.c | 3 +++
33
2 files changed, 4 insertions(+)
34
35
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
36
index XXXXXXX..XXXXXXX 100644
37
--- a/target/riscv/cpu_helper.c
38
+++ b/target/riscv/cpu_helper.c
39
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs)
40
tval = env->bins;
41
break;
42
case RISCV_EXCP_BREAKPOINT:
43
+ tval = env->badaddr;
44
if (cs->watchpoint_hit) {
45
tval = cs->watchpoint_hit->hitaddr;
46
cs->watchpoint_hit = NULL;
47
diff --git a/target/riscv/debug.c b/target/riscv/debug.c
48
index XXXXXXX..XXXXXXX 100644
49
--- a/target/riscv/debug.c
50
+++ b/target/riscv/debug.c
51
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs)
52
if ((ctrl & TYPE2_EXEC) && (bp->pc == pc)) {
53
/* check U/S/M bit against current privilege level */
54
if ((ctrl >> 3) & BIT(env->priv)) {
55
+ env->badaddr = pc;
56
return true;
57
}
58
}
59
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs)
60
if (env->virt_enabled) {
61
/* check VU/VS bit against current privilege level */
62
if ((ctrl >> 23) & BIT(env->priv)) {
63
+ env->badaddr = pc;
64
return true;
65
}
66
} else {
67
/* check U/S/M bit against current privilege level */
68
if ((ctrl >> 3) & BIT(env->priv)) {
69
+ env->badaddr = pc;
70
return true;
71
}
72
}
73
--
74
2.45.1
diff view generated by jsdifflib
Deleted patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
1
3
Privileged spec section 4.1.9 mentions:
4
5
"When a trap is taken into S-mode, stval is written with
6
exception-specific information to assist software in handling the trap.
7
(...)
8
9
If stval is written with a nonzero value when a breakpoint,
10
address-misaligned, access-fault, or page-fault exception occurs on an
11
instruction fetch, load, or store, then stval will contain the faulting
12
virtual address."
13
14
A similar text is found for mtval in section 3.1.16.
15
16
Setting mtval/stval in this scenario is optional, but some softwares read
17
these regs when handling ebreaks.
18
19
Write 'badaddr' in all ebreak breakpoints to write the appropriate
20
'tval' during riscv_do_cpu_interrrupt().
21
22
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
23
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
24
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
25
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
26
Message-ID: <20240416230437.1869024-3-dbarboza@ventanamicro.com>
27
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
28
---
29
target/riscv/insn_trans/trans_privileged.c.inc | 2 ++
30
1 file changed, 2 insertions(+)
31
32
diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc
33
index XXXXXXX..XXXXXXX 100644
34
--- a/target/riscv/insn_trans/trans_privileged.c.inc
35
+++ b/target/riscv/insn_trans/trans_privileged.c.inc
36
@@ -XXX,XX +XXX,XX @@ static bool trans_ebreak(DisasContext *ctx, arg_ebreak *a)
37
if (pre == 0x01f01013 && ebreak == 0x00100073 && post == 0x40705013) {
38
generate_exception(ctx, RISCV_EXCP_SEMIHOST);
39
} else {
40
+ tcg_gen_st_tl(tcg_constant_tl(ebreak_addr), tcg_env,
41
+ offsetof(CPURISCVState, badaddr));
42
generate_exception(ctx, RISCV_EXCP_BREAKPOINT);
43
}
44
return true;
45
--
46
2.45.1
diff view generated by jsdifflib
1
From: Jason Chien <jason.chien@sifive.com>
1
From: Xinhao Zhang <zhangxinhao1@huawei.com>
2
2
3
Add support for Zve32x extension and replace some checks for Zve32f with
3
Fix code style. Space required before the open parenthesis '('.
4
Zve32x, since Zve32f depends on Zve32x.
5
4
6
Signed-off-by: Jason Chien <jason.chien@sifive.com>
5
Signed-off-by: Xinhao Zhang <zhangxinhao1@huawei.com>
7
Reviewed-by: Frank Chang <frank.chang@sifive.com>
6
Signed-off-by: Kai Deng <dengkai1@huawei.com>
8
Reviewed-by: Max Chou <max.chou@sifive.com>
7
Reported-by: Euler Robot <euler.robot@huawei.com>
9
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
8
Reviewed-by: Bin Meng <bin.meng@windriver.com>
10
Message-ID: <20240328022343.6871-2-jason.chien@sifive.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Message-id: 20201030004815.4172849-1-zhangxinhao1@huawei.com
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
12
---
13
target/riscv/cpu_cfg.h | 1 +
13
target/riscv/csr.c | 2 +-
14
target/riscv/cpu.c | 2 ++
14
1 file changed, 1 insertion(+), 1 deletion(-)
15
target/riscv/cpu_helper.c | 2 +-
16
target/riscv/csr.c | 2 +-
17
target/riscv/tcg/tcg-cpu.c | 16 ++++++++--------
18
target/riscv/insn_trans/trans_rvv.c.inc | 4 ++--
19
6 files changed, 15 insertions(+), 12 deletions(-)
20
15
21
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
22
index XXXXXXX..XXXXXXX 100644
23
--- a/target/riscv/cpu_cfg.h
24
+++ b/target/riscv/cpu_cfg.h
25
@@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig {
26
bool ext_zhinx;
27
bool ext_zhinxmin;
28
bool ext_zve32f;
29
+ bool ext_zve32x;
30
bool ext_zve64f;
31
bool ext_zve64d;
32
bool ext_zvbb;
33
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
34
index XXXXXXX..XXXXXXX 100644
35
--- a/target/riscv/cpu.c
36
+++ b/target/riscv/cpu.c
37
@@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = {
38
ISA_EXT_DATA_ENTRY(zvbb, PRIV_VERSION_1_12_0, ext_zvbb),
39
ISA_EXT_DATA_ENTRY(zvbc, PRIV_VERSION_1_12_0, ext_zvbc),
40
ISA_EXT_DATA_ENTRY(zve32f, PRIV_VERSION_1_10_0, ext_zve32f),
41
+ ISA_EXT_DATA_ENTRY(zve32x, PRIV_VERSION_1_10_0, ext_zve32x),
42
ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f),
43
ISA_EXT_DATA_ENTRY(zve64d, PRIV_VERSION_1_10_0, ext_zve64d),
44
ISA_EXT_DATA_ENTRY(zvfbfmin, PRIV_VERSION_1_12_0, ext_zvfbfmin),
45
@@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
46
MULTI_EXT_CFG_BOOL("zfh", ext_zfh, false),
47
MULTI_EXT_CFG_BOOL("zfhmin", ext_zfhmin, false),
48
MULTI_EXT_CFG_BOOL("zve32f", ext_zve32f, false),
49
+ MULTI_EXT_CFG_BOOL("zve32x", ext_zve32x, false),
50
MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false),
51
MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false),
52
MULTI_EXT_CFG_BOOL("zvfbfmin", ext_zvfbfmin, false),
53
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
54
index XXXXXXX..XXXXXXX 100644
55
--- a/target/riscv/cpu_helper.c
56
+++ b/target/riscv/cpu_helper.c
57
@@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
58
*pc = env->xl == MXL_RV32 ? env->pc & UINT32_MAX : env->pc;
59
*cs_base = 0;
60
61
- if (cpu->cfg.ext_zve32f) {
62
+ if (cpu->cfg.ext_zve32x) {
63
/*
64
* If env->vl equals to VLMAX, we can use generic vector operation
65
* expanders (GVEC) to accerlate the vector operations.
66
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
16
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
67
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
68
--- a/target/riscv/csr.c
18
--- a/target/riscv/csr.c
69
+++ b/target/riscv/csr.c
19
+++ b/target/riscv/csr.c
70
@@ -XXX,XX +XXX,XX @@ static RISCVException fs(CPURISCVState *env, int csrno)
20
@@ -XXX,XX +XXX,XX @@ static int write_satp(CPURISCVState *env, int csrno, target_ulong val)
71
21
if (env->priv == PRV_S && get_field(env->mstatus, MSTATUS_TVM)) {
72
static RISCVException vs(CPURISCVState *env, int csrno)
22
return -RISCV_EXCP_ILLEGAL_INST;
73
{
23
} else {
74
- if (riscv_cpu_cfg(env)->ext_zve32f) {
24
- if((val ^ env->satp) & SATP_ASID) {
75
+ if (riscv_cpu_cfg(env)->ext_zve32x) {
25
+ if ((val ^ env->satp) & SATP_ASID) {
76
#if !defined(CONFIG_USER_ONLY)
26
tlb_flush(env_cpu(env));
77
if (!env->debugger && !riscv_cpu_vector_enabled(env)) {
27
}
78
return RISCV_EXCP_ILLEGAL_INST;
28
env->satp = val;
79
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
80
index XXXXXXX..XXXXXXX 100644
81
--- a/target/riscv/tcg/tcg-cpu.c
82
+++ b/target/riscv/tcg/tcg-cpu.c
83
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
84
return;
85
}
86
87
- if (cpu->cfg.ext_zve32f && !riscv_has_ext(env, RVF)) {
88
- error_setg(errp, "Zve32f/Zve64f extensions require F extension");
89
- return;
90
+ /* The Zve32f extension depends on the Zve32x extension */
91
+ if (cpu->cfg.ext_zve32f) {
92
+ if (!riscv_has_ext(env, RVF)) {
93
+ error_setg(errp, "Zve32f/Zve64f extensions require F extension");
94
+ return;
95
+ }
96
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32x), true);
97
}
98
99
if (cpu->cfg.ext_zvfh) {
100
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
101
cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zvbc), true);
102
}
103
104
- /*
105
- * In principle Zve*x would also suffice here, were they supported
106
- * in qemu
107
- */
108
if ((cpu->cfg.ext_zvbb || cpu->cfg.ext_zvkb || cpu->cfg.ext_zvkg ||
109
cpu->cfg.ext_zvkned || cpu->cfg.ext_zvknha || cpu->cfg.ext_zvksed ||
110
- cpu->cfg.ext_zvksh) && !cpu->cfg.ext_zve32f) {
111
+ cpu->cfg.ext_zvksh) && !cpu->cfg.ext_zve32x) {
112
error_setg(errp,
113
"Vector crypto extensions require V or Zve* extensions");
114
return;
115
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
116
index XXXXXXX..XXXXXXX 100644
117
--- a/target/riscv/insn_trans/trans_rvv.c.inc
118
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
119
@@ -XXX,XX +XXX,XX @@ static bool do_vsetvl(DisasContext *s, int rd, int rs1, TCGv s2)
120
{
121
TCGv s1, dst;
122
123
- if (!require_rvv(s) || !s->cfg_ptr->ext_zve32f) {
124
+ if (!require_rvv(s) || !s->cfg_ptr->ext_zve32x) {
125
return false;
126
}
127
128
@@ -XXX,XX +XXX,XX @@ static bool do_vsetivli(DisasContext *s, int rd, TCGv s1, TCGv s2)
129
{
130
TCGv dst;
131
132
- if (!require_rvv(s) || !s->cfg_ptr->ext_zve32f) {
133
+ if (!require_rvv(s) || !s->cfg_ptr->ext_zve32x) {
134
return false;
135
}
136
137
--
29
--
138
2.45.1
30
2.28.0
31
32
diff view generated by jsdifflib
Deleted patch
1
From: Jason Chien <jason.chien@sifive.com>
2
1
3
In current implementation, the gdbstub allows reading vector registers
4
only if V extension is supported. However, all vector extensions and
5
vector crypto extensions have the vector registers and they all depend
6
on Zve32x. The gdbstub should check for Zve32x instead.
7
8
Signed-off-by: Jason Chien <jason.chien@sifive.com>
9
Reviewed-by: Frank Chang <frank.chang@sifive.com>
10
Reviewed-by: Max Chou <max.chou@sifive.com>
11
Message-ID: <20240328022343.6871-4-jason.chien@sifive.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
14
target/riscv/gdbstub.c | 2 +-
15
1 file changed, 1 insertion(+), 1 deletion(-)
16
17
diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/target/riscv/gdbstub.c
20
+++ b/target/riscv/gdbstub.c
21
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs)
22
gdb_find_static_feature("riscv-32bit-fpu.xml"),
23
0);
24
}
25
- if (env->misa_ext & RVV) {
26
+ if (cpu->cfg.ext_zve32x) {
27
gdb_register_coprocessor(cs, riscv_gdb_get_vector,
28
riscv_gdb_set_vector,
29
ricsv_gen_dynamic_vector_feature(cs, cs->gdb_num_regs),
30
--
31
2.45.1
diff view generated by jsdifflib
Deleted patch
1
From: Max Chou <max.chou@sifive.com>
2
1
3
The opfv_narrow_check needs to check the single width float operator by
4
require_rvf.
5
6
Signed-off-by: Max Chou <max.chou@sifive.com>
7
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
8
Cc: qemu-stable <qemu-stable@nongnu.org>
9
Message-ID: <20240322092600.1198921-4-max.chou@sifive.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
12
target/riscv/insn_trans/trans_rvv.c.inc | 1 +
13
1 file changed, 1 insertion(+)
14
15
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
16
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/insn_trans/trans_rvv.c.inc
18
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
19
@@ -XXX,XX +XXX,XX @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a)
20
static bool opffv_rod_narrow_check(DisasContext *s, arg_rmr *a)
21
{
22
return opfv_narrow_check(s, a) &&
23
+ require_rvf(s) &&
24
require_scale_rvf(s) &&
25
(s->sew != MO_8);
26
}
27
--
28
2.45.1
diff view generated by jsdifflib
Deleted patch
1
From: Max Chou <max.chou@sifive.com>
2
1
3
If the checking functions check both the single and double width
4
operators at the same time, then the single width operator checking
5
functions (require_rvf[min]) will check whether the SEW is 8.
6
7
Signed-off-by: Max Chou <max.chou@sifive.com>
8
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Cc: qemu-stable <qemu-stable@nongnu.org>
10
Message-ID: <20240322092600.1198921-5-max.chou@sifive.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
13
target/riscv/insn_trans/trans_rvv.c.inc | 16 ++++------------
14
1 file changed, 4 insertions(+), 12 deletions(-)
15
16
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
17
index XXXXXXX..XXXXXXX 100644
18
--- a/target/riscv/insn_trans/trans_rvv.c.inc
19
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
20
@@ -XXX,XX +XXX,XX @@ static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a)
21
return require_rvv(s) &&
22
require_rvf(s) &&
23
require_scale_rvf(s) &&
24
- (s->sew != MO_8) &&
25
vext_check_isa_ill(s) &&
26
vext_check_dss(s, a->rd, a->rs1, a->rs2, a->vm);
27
}
28
@@ -XXX,XX +XXX,XX @@ static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a)
29
return require_rvv(s) &&
30
require_rvf(s) &&
31
require_scale_rvf(s) &&
32
- (s->sew != MO_8) &&
33
vext_check_isa_ill(s) &&
34
vext_check_ds(s, a->rd, a->rs2, a->vm);
35
}
36
@@ -XXX,XX +XXX,XX @@ static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a)
37
return require_rvv(s) &&
38
require_rvf(s) &&
39
require_scale_rvf(s) &&
40
- (s->sew != MO_8) &&
41
vext_check_isa_ill(s) &&
42
vext_check_dds(s, a->rd, a->rs1, a->rs2, a->vm);
43
}
44
@@ -XXX,XX +XXX,XX @@ static bool opfwf_widen_check(DisasContext *s, arg_rmrr *a)
45
return require_rvv(s) &&
46
require_rvf(s) &&
47
require_scale_rvf(s) &&
48
- (s->sew != MO_8) &&
49
vext_check_isa_ill(s) &&
50
vext_check_dd(s, a->rd, a->rs2, a->vm);
51
}
52
@@ -XXX,XX +XXX,XX @@ static bool opffv_widen_check(DisasContext *s, arg_rmr *a)
53
{
54
return opfv_widen_check(s, a) &&
55
require_rvfmin(s) &&
56
- require_scale_rvfmin(s) &&
57
- (s->sew != MO_8);
58
+ require_scale_rvfmin(s);
59
}
60
61
#define GEN_OPFV_WIDEN_TRANS(NAME, CHECK, HELPER, FRM) \
62
@@ -XXX,XX +XXX,XX @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a)
63
{
64
return opfv_narrow_check(s, a) &&
65
require_rvfmin(s) &&
66
- require_scale_rvfmin(s) &&
67
- (s->sew != MO_8);
68
+ require_scale_rvfmin(s);
69
}
70
71
static bool opffv_rod_narrow_check(DisasContext *s, arg_rmr *a)
72
{
73
return opfv_narrow_check(s, a) &&
74
require_rvf(s) &&
75
- require_scale_rvf(s) &&
76
- (s->sew != MO_8);
77
+ require_scale_rvf(s);
78
}
79
80
#define GEN_OPFV_NARROW_TRANS(NAME, CHECK, HELPER, FRM) \
81
@@ -XXX,XX +XXX,XX @@ static bool freduction_widen_check(DisasContext *s, arg_rmrr *a)
82
{
83
return reduction_widen_check(s, a) &&
84
require_rvf(s) &&
85
- require_scale_rvf(s) &&
86
- (s->sew != MO_8);
87
+ require_scale_rvf(s);
88
}
89
90
GEN_OPFVV_WIDEN_TRANS(vfwredusum_vs, freduction_widen_check)
91
--
92
2.45.1
diff view generated by jsdifflib
Deleted patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
1
3
raise_mmu_exception(), as is today, is prioritizing guest page faults by
4
checking first if virt_enabled && !first_stage, and then considering the
5
regular inst/load/store faults.
6
7
There's no mention in the spec about guest page fault being a higher
8
priority that PMP faults. In fact, privileged spec section 3.7.1 says:
9
10
"Attempting to fetch an instruction from a PMP region that does not have
11
execute permissions raises an instruction access-fault exception.
12
Attempting to execute a load or load-reserved instruction which accesses
13
a physical address within a PMP region without read permissions raises a
14
load access-fault exception. Attempting to execute a store,
15
store-conditional, or AMO instruction which accesses a physical address
16
within a PMP region without write permissions raises a store
17
access-fault exception."
18
19
So, in fact, we're doing it wrong - PMP faults should always be thrown,
20
regardless of also being a first or second stage fault.
21
22
The way riscv_cpu_tlb_fill() and get_physical_address() work is
23
adequate: a TRANSLATE_PMP_FAIL error is immediately reported and
24
reflected in the 'pmp_violation' flag. What we need is to change
25
raise_mmu_exception() to prioritize it.
26
27
Reported-by: Joseph Chan <jchan@ventanamicro.com>
28
Fixes: 82d53adfbb ("target/riscv/cpu_helper.c: Invalid exception on MMU translation stage")
29
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
30
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
31
Message-ID: <20240413105929.7030-1-alexei.filippov@syntacore.com>
32
Cc: qemu-stable <qemu-stable@nongnu.org>
33
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
34
---
35
target/riscv/cpu_helper.c | 22 ++++++++++++----------
36
1 file changed, 12 insertions(+), 10 deletions(-)
37
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 @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address,
43
44
switch (access_type) {
45
case MMU_INST_FETCH:
46
- if (env->virt_enabled && !first_stage) {
47
+ if (pmp_violation) {
48
+ cs->exception_index = RISCV_EXCP_INST_ACCESS_FAULT;
49
+ } else if (env->virt_enabled && !first_stage) {
50
cs->exception_index = RISCV_EXCP_INST_GUEST_PAGE_FAULT;
51
} else {
52
- cs->exception_index = pmp_violation ?
53
- RISCV_EXCP_INST_ACCESS_FAULT : RISCV_EXCP_INST_PAGE_FAULT;
54
+ cs->exception_index = RISCV_EXCP_INST_PAGE_FAULT;
55
}
56
break;
57
case MMU_DATA_LOAD:
58
- if (two_stage && !first_stage) {
59
+ if (pmp_violation) {
60
+ cs->exception_index = RISCV_EXCP_LOAD_ACCESS_FAULT;
61
+ } else if (two_stage && !first_stage) {
62
cs->exception_index = RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT;
63
} else {
64
- cs->exception_index = pmp_violation ?
65
- RISCV_EXCP_LOAD_ACCESS_FAULT : RISCV_EXCP_LOAD_PAGE_FAULT;
66
+ cs->exception_index = RISCV_EXCP_LOAD_PAGE_FAULT;
67
}
68
break;
69
case MMU_DATA_STORE:
70
- if (two_stage && !first_stage) {
71
+ if (pmp_violation) {
72
+ cs->exception_index = RISCV_EXCP_STORE_AMO_ACCESS_FAULT;
73
+ } else if (two_stage && !first_stage) {
74
cs->exception_index = RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT;
75
} else {
76
- cs->exception_index = pmp_violation ?
77
- RISCV_EXCP_STORE_AMO_ACCESS_FAULT :
78
- RISCV_EXCP_STORE_PAGE_FAULT;
79
+ cs->exception_index = RISCV_EXCP_STORE_PAGE_FAULT;
80
}
81
break;
82
default:
83
--
84
2.45.1
diff view generated by jsdifflib
Deleted patch
1
From: Alexei Filippov <alexei.filippov@syntacore.com>
2
1
3
Previous patch fixed the PMP priority in raise_mmu_exception() but we're still
4
setting mtval2 incorrectly. In riscv_cpu_tlb_fill(), after pmp check in 2 stage
5
translation part, mtval2 will be set in case of successes 2 stage translation but
6
failed pmp check.
7
8
In this case we gonna set mtval2 via env->guest_phys_fault_addr in context of
9
riscv_cpu_tlb_fill(), as this was a guest-page-fault, but it didn't and mtval2
10
should be zero, according to RISCV privileged spec sect. 9.4.4: When a guest
11
page-fault is taken into M-mode, mtval2 is written with either zero or guest
12
physical address that faulted, shifted by 2 bits. *For other traps, mtval2
13
is set to zero...*
14
15
Signed-off-by: Alexei Filippov <alexei.filippov@syntacore.com>
16
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
17
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
18
Message-ID: <20240503103052.6819-1-alexei.filippov@syntacore.com>
19
Cc: qemu-stable <qemu-stable@nongnu.org>
20
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
21
---
22
target/riscv/cpu_helper.c | 12 ++++++------
23
1 file changed, 6 insertions(+), 6 deletions(-)
24
25
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
26
index XXXXXXX..XXXXXXX 100644
27
--- a/target/riscv/cpu_helper.c
28
+++ b/target/riscv/cpu_helper.c
29
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
30
__func__, pa, ret, prot_pmp, tlb_size);
31
32
prot &= prot_pmp;
33
- }
34
-
35
- if (ret != TRANSLATE_SUCCESS) {
36
+ } else {
37
/*
38
* Guest physical address translation failed, this is a HS
39
* level exception
40
*/
41
first_stage_error = false;
42
- env->guest_phys_fault_addr = (im_address |
43
- (address &
44
- (TARGET_PAGE_SIZE - 1))) >> 2;
45
+ if (ret != TRANSLATE_PMP_FAIL) {
46
+ env->guest_phys_fault_addr = (im_address |
47
+ (address &
48
+ (TARGET_PAGE_SIZE - 1))) >> 2;
49
+ }
50
}
51
}
52
} else {
53
--
54
2.45.1
diff view generated by jsdifflib