1 | The following changes since commit 661c2e1ab29cd9c4d268ae3f44712e8d421c0e56: | 1 | The following changes since commit e4f3ede95ce813d5705c65e1c0e1c80c70739ebb: |
---|---|---|---|
2 | 2 | ||
3 | scripts/checkpatch: Fix a typo (2025-03-04 09:30:26 +0800) | 3 | Merge remote-tracking branch 'remotes/kraxel/tags/usb-20210505-pull-request' into staging (2021-05-10 19:55:06 +0100) |
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-20250305-1 | 7 | git@github.com:alistair23/qemu.git tags/pull-riscv-to-apply-20210511 |
8 | 8 | ||
9 | for you to fetch changes up to 4db19d5b21e058e6eb3474b6be470d1184afaa9e: | 9 | for you to fetch changes up to c30a0757f094c107e491820e3d35224eb68859c7: |
10 | 10 | ||
11 | target/riscv/kvm: add missing KVM CSRs (2025-03-04 15:42:54 +1000) | 11 | target/riscv: Fix the RV64H decode comment (2021-05-11 20:02:07 +1000) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Third RISC-V PR for 10.0 | 14 | A large collection of RISC-V fixes, improvements and features |
15 | 15 | ||
16 | * CSR coverity fixes | 16 | - Clenaup some left over v1.9 code |
17 | * Fix unexpected behavior of vector reduction instructions when vl is 0 | 17 | - Documentation improvements |
18 | * Fix incorrect vlen comparison in prop_vlen_set | 18 | - Support for the shakti_c machine |
19 | * Throw debug exception before page fault | 19 | - Internal cleanup of the CSR accesses |
20 | * Remove redundant "hart_idx" masking from APLIC | 20 | - Updates to the OpenTitan platform |
21 | * Add support for Control Transfer Records Ext | 21 | - Support for the virtio-vga |
22 | * Remove redundant struct members from the IOMMU | 22 | - Fix for the saturate subtract in vector extensions |
23 | * Remove duplicate definitions from the IOMMU | 23 | - Experimental support for the ePMP spec |
24 | * Fix tick_offset migration for Goldfish RTC | 24 | - A range of other internal code cleanups and bug fixes |
25 | * Add serial alias in virt machine DTB | ||
26 | * Remove Bin Meng from RISC-V maintainers | ||
27 | * Add support for Control Transfer Records Ext | ||
28 | * Log guest errors when reserved bits are set in PTEs | ||
29 | * Add missing Sdtrig disas CSRs | ||
30 | * Correct the hpmevent sscofpmf mask | ||
31 | * Mask upper sscofpmf bits during validation | ||
32 | * Remove warnings about Smdbltrp/Smrnmi being disabled | ||
33 | * Respect mseccfg.RLB bit for TOR mode PMP entry | ||
34 | * Update KVM support to Linux 6.14-rc3 | ||
35 | * IOMMU HPM support | ||
36 | * Support Sscofpmf/Svade/Svadu/Smnpm/Ssnpm extensions in KVM | ||
37 | * Add --ignore-family option to binfmt | ||
38 | * Refinement for AIA with KVM acceleration | ||
39 | * Reset time changes for KVM | ||
40 | 25 | ||
41 | ---------------------------------------------------------------- | 26 | ---------------------------------------------------------------- |
42 | Alistair Francis (1): | 27 | Alexander Wagner (1): |
43 | MAINTAINERS: Remove Bin Meng from RISC-V maintainers | 28 | hw/riscv: Fix OT IBEX reset vector |
44 | 29 | ||
45 | Andrea Bolognani (3): | 30 | Alistair Francis (22): |
46 | binfmt: Shuffle things around | 31 | target/riscv: Convert the RISC-V exceptions to an enum |
47 | binfmt: Normalize host CPU architecture | 32 | target/riscv: Use the RISCVException enum for CSR predicates |
48 | binfmt: Add --ignore-family option | 33 | target/riscv: Fix 32-bit HS mode access permissions |
34 | target/riscv: Use the RISCVException enum for CSR operations | ||
35 | target/riscv: Use RISCVException enum for CSR access | ||
36 | MAINTAINERS: Update the RISC-V CPU Maintainers | ||
37 | hw/opentitan: Update the interrupt layout | ||
38 | hw/riscv: Enable VIRTIO_VGA for RISC-V virt machine | ||
39 | target/riscv: Fix the PMP is locked check when using TOR | ||
40 | target/riscv: Add the ePMP feature | ||
41 | target/riscv/pmp: Remove outdated comment | ||
42 | target/riscv: Add ePMP support for the Ibex CPU | ||
43 | target/riscv: Remove the hardcoded RVXLEN macro | ||
44 | target/riscv: Remove the hardcoded SSTATUS_SD macro | ||
45 | target/riscv: Remove the hardcoded HGATP_MODE macro | ||
46 | target/riscv: Remove the hardcoded MSTATUS_SD macro | ||
47 | target/riscv: Remove the hardcoded SATP_MODE macro | ||
48 | target/riscv: Remove the unused HSTATUS_WPRI macro | ||
49 | target/riscv: Remove an unused CASE_OP_32_64 macro | ||
50 | target/riscv: Consolidate RV32/64 32-bit instructions | ||
51 | target/riscv: Consolidate RV32/64 16-bit instructions | ||
52 | target/riscv: Fix the RV64H decode comment | ||
49 | 53 | ||
50 | Atish Patra (2): | 54 | Atish Patra (1): |
51 | target/riscv: Fix the hpmevent mask | 55 | target/riscv: Remove privilege v1.9 specific CSR related code |
52 | target/riscv: Mask out upper sscofpmf bits during validation | ||
53 | 56 | ||
54 | Clément Léger (1): | 57 | Axel Heider (1): |
55 | target/riscv: remove warnings about Smdbltrp/Smrnmi being disabled | 58 | docs/system/generic-loader.rst: Fix style |
56 | 59 | ||
57 | Daniel Henrique Barboza (22): | 60 | Bin Meng (1): |
58 | target/riscv/csr.c: fix deadcode in rmw_xireg() | 61 | hw/riscv: sifive_e: Add 'const' to sifive_e_memmap[] |
59 | target/riscv/csr.c: fix 'ret' deadcode in rmw_xireg() | ||
60 | target/riscv/csr.c: fix deadcode in rmw_xiregi() | ||
61 | target/riscv/csr.c: fix deadcode in aia_smode32() | ||
62 | target/riscv/cpu_helper.c: fix bad_shift in riscv_cpu_interrupt() | ||
63 | target/riscv/debug.c: use wp size = 4 for 32-bit CPUs | ||
64 | target/riscv: throw debug exception before page fault | ||
65 | target/riscv: add ssu64xl | ||
66 | target/riscv: use RVB in RVA22U64 | ||
67 | target/riscv: add profile u_parent and s_parent | ||
68 | target/riscv: change priv_ver check in validate_profile() | ||
69 | target/riscv: add RVA23U64 profile | ||
70 | target/riscv: add RVA23S64 profile | ||
71 | linux-headers: Update to Linux v6.14-rc3 | ||
72 | target/riscv/cpu.c: create flag for ziccrse | ||
73 | target/riscv/kvm: add extensions after 6.14-rc3 update | ||
74 | hw/riscv/riscv-iommu.h: add missing headers | ||
75 | hw/riscv: add IOMMU HPM trace events | ||
76 | docs/specs/riscv-iommu.rst: add HPM support info | ||
77 | target/riscv/cpu: remove unneeded !kvm_enabled() check | ||
78 | target/riscv/kvm: add kvm_riscv_reset_regs_csr() | ||
79 | target/riscv/kvm: add missing KVM CSRs | ||
80 | 62 | ||
81 | Huang Borong (1): | 63 | Dylan Jhong (1): |
82 | hw/intc/riscv_aplic: Remove redundant "hart_idx" masking | 64 | target/riscv: Align the data type of reset vector address |
83 | 65 | ||
84 | Jason Chien (2): | 66 | Emmanuel Blot (2): |
85 | hw/riscv/riscv-iommu: Remove redundant struct members | 67 | target/riscv: fix exception index on instruction access fault |
86 | hw/riscv/riscv-iommu-bits: Remove duplicate definitions | 68 | target/riscv: fix a typo with interrupt names |
87 | 69 | ||
88 | Max Chou (2): | 70 | Frank Chang (2): |
89 | target/riscv: rvv: Fix unexpected behavior of vector reduction instructions when vl is 0 | 71 | target/riscv: fix vrgather macro index variable type bug |
90 | target/riscv: rvv: Fix incorrect vlen comparison in prop_vlen_set | 72 | fpu/softfloat: set invalid excp flag for RISC-V muladd instructions |
91 | 73 | ||
92 | Quan Zhou (1): | 74 | Hou Weiying (4): |
93 | target/riscv/kvm: Add some exts support | 75 | target/riscv: Define ePMP mseccfg |
76 | target/riscv: Add ePMP CSR access functions | ||
77 | target/riscv: Implementation of enhanced PMP (ePMP) | ||
78 | target/riscv: Add a config option for ePMP | ||
94 | 79 | ||
95 | Rajnesh Kanwal (7): | 80 | Jade Fink (1): |
96 | target/riscv: Remove obsolete sfence.vm instruction | 81 | riscv: don't look at SUM when accessing memory from a debugger context |
97 | target/riscv: Add Control Transfer Records CSR definitions. | ||
98 | target/riscv: Add support for Control Transfer Records extension CSRs. | ||
99 | target/riscv: Add support to record CTR entries. | ||
100 | target/riscv: Add CTR sctrclr instruction. | ||
101 | target/riscv: machine: Add Control Transfer Record state description | ||
102 | target/riscv: Add support to access ctrsource, ctrtarget, ctrdata regs. | ||
103 | 82 | ||
104 | Rob Bradford (3): | 83 | LIU Zhiwei (1): |
105 | disas/riscv: Fix minor whitespace issues | 84 | target/riscv: Fixup saturate subtract function |
106 | disas/riscv: Add missing Sdtrig CSRs | ||
107 | target/riscv: Respect mseccfg.RLB bit for TOR mode PMP entry | ||
108 | 85 | ||
109 | Rodrigo Dias Correa (1): | 86 | Vijai Kumar K (5): |
110 | goldfish_rtc: Fix tick_offset migration | 87 | target/riscv: Add Shakti C class CPU |
88 | riscv: Add initial support for Shakti C machine | ||
89 | hw/char: Add Shakti UART emulation | ||
90 | hw/riscv: Connect Shakti UART to Shakti platform | ||
91 | docs: Add documentation for shakti_c machine | ||
111 | 92 | ||
112 | Tomasz Jeznach (8): | 93 | docs/system/generic-loader.rst | 9 +- |
113 | hw/riscv/riscv-iommu-bits.h: HPM bits | 94 | docs/system/riscv/shakti-c.rst | 82 +++ |
114 | hw/riscv/riscv-iommu: add riscv-iommu-hpm file | 95 | docs/system/target-riscv.rst | 1 + |
115 | hw/riscv/riscv-iommu: add riscv_iommu_hpm_incr_ctr() | 96 | default-configs/devices/riscv64-softmmu.mak | 1 + |
116 | hw/riscv/riscv-iommu: instantiate hpm_timer | 97 | include/hw/char/shakti_uart.h | 74 +++ |
117 | hw/riscv/riscv-iommu: add IOCOUNTINH mmio writes | 98 | include/hw/riscv/opentitan.h | 16 +- |
118 | hw/riscv/riscv-iommu: add IOHPMCYCLES mmio write | 99 | include/hw/riscv/shakti_c.h | 75 +++ |
119 | hw/riscv/riscv-iommu: add hpm events mmio write | 100 | target/riscv/cpu.h | 42 +- |
120 | hw/riscv/riscv-iommu.c: add RISCV_IOMMU_CAP_HPM cap | 101 | target/riscv/cpu_bits.h | 114 +--- |
102 | target/riscv/helper.h | 18 +- | ||
103 | target/riscv/pmp.h | 14 + | ||
104 | target/riscv/insn16-32.decode | 28 - | ||
105 | target/riscv/insn16-64.decode | 36 -- | ||
106 | target/riscv/insn16.decode | 30 + | ||
107 | target/riscv/insn32-64.decode | 88 --- | ||
108 | target/riscv/insn32.decode | 67 ++- | ||
109 | hw/char/shakti_uart.c | 185 +++++++ | ||
110 | hw/intc/ibex_plic.c | 20 +- | ||
111 | hw/riscv/opentitan.c | 10 +- | ||
112 | hw/riscv/shakti_c.c | 181 ++++++ | ||
113 | hw/riscv/sifive_e.c | 2 +- | ||
114 | target/riscv/cpu.c | 26 +- | ||
115 | target/riscv/cpu_helper.c | 88 ++- | ||
116 | target/riscv/csr.c | 824 +++++++++++++++++----------- | ||
117 | target/riscv/fpu_helper.c | 16 +- | ||
118 | target/riscv/gdbstub.c | 8 +- | ||
119 | target/riscv/machine.c | 8 +- | ||
120 | target/riscv/monitor.c | 22 +- | ||
121 | target/riscv/op_helper.c | 18 +- | ||
122 | target/riscv/pmp.c | 218 +++++++- | ||
123 | target/riscv/translate.c | 38 +- | ||
124 | target/riscv/vector_helper.c | 18 +- | ||
125 | fpu/softfloat-specialize.c.inc | 6 + | ||
126 | target/riscv/insn_trans/trans_rva.c.inc | 14 +- | ||
127 | target/riscv/insn_trans/trans_rvd.c.inc | 17 +- | ||
128 | target/riscv/insn_trans/trans_rvf.c.inc | 6 +- | ||
129 | target/riscv/insn_trans/trans_rvh.c.inc | 8 +- | ||
130 | target/riscv/insn_trans/trans_rvi.c.inc | 22 +- | ||
131 | target/riscv/insn_trans/trans_rvm.c.inc | 12 +- | ||
132 | target/riscv/insn_trans/trans_rvv.c.inc | 39 +- | ||
133 | MAINTAINERS | 14 +- | ||
134 | hw/char/meson.build | 1 + | ||
135 | hw/char/trace-events | 4 + | ||
136 | hw/riscv/Kconfig | 11 + | ||
137 | hw/riscv/meson.build | 1 + | ||
138 | target/riscv/meson.build | 13 +- | ||
139 | target/riscv/trace-events | 3 + | ||
140 | 47 files changed, 1759 insertions(+), 789 deletions(-) | ||
141 | create mode 100644 docs/system/riscv/shakti-c.rst | ||
142 | create mode 100644 include/hw/char/shakti_uart.h | ||
143 | create mode 100644 include/hw/riscv/shakti_c.h | ||
144 | delete mode 100644 target/riscv/insn16-32.decode | ||
145 | delete mode 100644 target/riscv/insn16-64.decode | ||
146 | delete mode 100644 target/riscv/insn32-64.decode | ||
147 | create mode 100644 hw/char/shakti_uart.c | ||
148 | create mode 100644 hw/riscv/shakti_c.c | ||
121 | 149 | ||
122 | Vasilis Liaskovitis (1): | ||
123 | hw/riscv/virt: Add serial alias in DTB | ||
124 | |||
125 | Yong-Xuan Wang (3): | ||
126 | hw/intc/imsic: refine the IMSIC realize | ||
127 | hw/intc/aplic: refine the APLIC realize | ||
128 | hw/intc/aplic: refine kvm_msicfgaddr | ||
129 | |||
130 | julia (1): | ||
131 | target/riscv: log guest errors when reserved bits are set in PTEs | ||
132 | |||
133 | MAINTAINERS | 5 +- | ||
134 | docs/specs/riscv-iommu.rst | 2 + | ||
135 | hw/riscv/riscv-iommu-bits.h | 69 +++- | ||
136 | hw/riscv/riscv-iommu-hpm.h | 33 ++ | ||
137 | hw/riscv/riscv-iommu.h | 32 +- | ||
138 | include/standard-headers/linux/ethtool.h | 4 + | ||
139 | include/standard-headers/linux/fuse.h | 76 +++- | ||
140 | include/standard-headers/linux/input-event-codes.h | 1 + | ||
141 | include/standard-headers/linux/pci_regs.h | 16 +- | ||
142 | include/standard-headers/linux/virtio_pci.h | 14 + | ||
143 | linux-headers/asm-arm64/kvm.h | 3 - | ||
144 | linux-headers/asm-loongarch/kvm_para.h | 1 + | ||
145 | linux-headers/asm-riscv/kvm.h | 7 +- | ||
146 | linux-headers/asm-x86/kvm.h | 1 + | ||
147 | linux-headers/linux/iommufd.h | 35 +- | ||
148 | linux-headers/linux/kvm.h | 8 +- | ||
149 | linux-headers/linux/stddef.h | 13 +- | ||
150 | linux-headers/linux/vduse.h | 2 +- | ||
151 | target/riscv/cpu-qom.h | 2 + | ||
152 | target/riscv/cpu.h | 16 +- | ||
153 | target/riscv/cpu_bits.h | 150 +++++++- | ||
154 | target/riscv/cpu_cfg.h | 5 + | ||
155 | target/riscv/helper.h | 2 + | ||
156 | target/riscv/insn32.decode | 2 +- | ||
157 | disas/riscv.c | 16 +- | ||
158 | hw/intc/riscv_aplic.c | 74 ++-- | ||
159 | hw/intc/riscv_imsic.c | 47 +-- | ||
160 | hw/riscv/riscv-iommu-hpm.c | 381 +++++++++++++++++++++ | ||
161 | hw/riscv/riscv-iommu.c | 131 ++++++- | ||
162 | hw/riscv/virt.c | 3 + | ||
163 | hw/rtc/goldfish_rtc.c | 43 +-- | ||
164 | target/riscv/cpu.c | 115 ++++++- | ||
165 | target/riscv/cpu_helper.c | 315 ++++++++++++++++- | ||
166 | target/riscv/csr.c | 318 +++++++++++++++-- | ||
167 | target/riscv/debug.c | 6 +- | ||
168 | target/riscv/kvm/kvm-cpu.c | 40 ++- | ||
169 | target/riscv/machine.c | 25 ++ | ||
170 | target/riscv/op_helper.c | 48 +++ | ||
171 | target/riscv/pmp.c | 2 +- | ||
172 | target/riscv/pmu.c | 2 +- | ||
173 | target/riscv/tcg/tcg-cpu.c | 58 +++- | ||
174 | target/riscv/translate.c | 46 +++ | ||
175 | target/riscv/vector_helper.c | 8 +- | ||
176 | target/riscv/insn_trans/trans_privileged.c.inc | 18 +- | ||
177 | target/riscv/insn_trans/trans_rvi.c.inc | 75 ++++ | ||
178 | target/riscv/insn_trans/trans_rvzce.c.inc | 21 ++ | ||
179 | hw/riscv/meson.build | 3 +- | ||
180 | hw/riscv/trace-events | 5 + | ||
181 | scripts/qemu-binfmt-conf.sh | 78 +++-- | ||
182 | tests/data/acpi/riscv64/virt/RHCT | Bin 390 -> 400 bytes | ||
183 | 50 files changed, 2106 insertions(+), 271 deletions(-) | ||
184 | create mode 100644 hw/riscv/riscv-iommu-hpm.h | ||
185 | create mode 100644 hw/riscv/riscv-iommu-hpm.c | ||
186 | diff view generated by jsdifflib |
1 | From: Rajnesh Kanwal <rkanwal@rivosinc.com> | 1 | From: Atish Patra <atish.patra@wdc.com> |
---|---|---|---|
2 | 2 | ||
3 | This commit adds logic to records CTR entries of different types | 3 | Qemu doesn't support RISC-V privilege specification v1.9. Remove the |
4 | and adds required hooks in TCG and interrupt/Exception logic to | 4 | remaining v1.9 specific references from the implementation. |
5 | record events. | 5 | |
6 | 6 | Signed-off-by: Atish Patra <atish.patra@wdc.com> | |
7 | This commit also adds support to invoke freeze CTR logic for breakpoint | 7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
8 | exceptions and counter overflow interrupts. | 8 | Message-Id: <20210319194534.2082397-2-atish.patra@wdc.com> |
9 | 9 | [Changes by AF: | |
10 | Signed-off-by: Rajnesh Kanwal <rkanwal@rivosinc.com> | 10 | - Rebase on latest patches |
11 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | 11 | - Bump the vmstate_riscv_cpu version_id and minimum_version_id |
12 | Message-ID: <20250205-b4-ctr_upstream_v6-v6-4-439d8e06c8ef@rivosinc.com> | 12 | ] |
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
14 | --- | 14 | --- |
15 | target/riscv/cpu.h | 7 + | 15 | target/riscv/cpu.h | 4 +--- |
16 | target/riscv/helper.h | 1 + | 16 | target/riscv/cpu_bits.h | 23 --------------------- |
17 | target/riscv/cpu_helper.c | 259 ++++++++++++++++++ | 17 | target/riscv/cpu.c | 2 +- |
18 | target/riscv/op_helper.c | 19 ++ | 18 | target/riscv/cpu_helper.c | 12 +++++------ |
19 | target/riscv/translate.c | 46 ++++ | 19 | target/riscv/csr.c | 42 ++++++++++----------------------------- |
20 | .../riscv/insn_trans/trans_privileged.c.inc | 2 + | 20 | target/riscv/machine.c | 8 +++----- |
21 | target/riscv/insn_trans/trans_rvi.c.inc | 75 +++++ | 21 | target/riscv/translate.c | 4 ++-- |
22 | target/riscv/insn_trans/trans_rvzce.c.inc | 21 ++ | 22 | 7 files changed, 23 insertions(+), 72 deletions(-) |
23 | 8 files changed, 430 insertions(+) | ||
24 | 23 | ||
25 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 24 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
26 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/target/riscv/cpu.h | 26 | --- a/target/riscv/cpu.h |
28 | +++ b/target/riscv/cpu.h | 27 | +++ b/target/riscv/cpu.h |
29 | @@ -XXX,XX +XXX,XX @@ struct CPUArchState { | 28 | @@ -XXX,XX +XXX,XX @@ struct CPURISCVState { |
30 | uint32_t sctrstatus; | 29 | target_ulong mie; |
31 | uint64_t vsctrctl; | 30 | target_ulong mideleg; |
32 | 31 | ||
33 | + uint64_t ctr_src[16 << SCTRDEPTH_MAX]; | 32 | - target_ulong sptbr; /* until: priv-1.9.1 */ |
34 | + uint64_t ctr_dst[16 << SCTRDEPTH_MAX]; | 33 | target_ulong satp; /* since: priv-1.10.0 */ |
35 | + uint64_t ctr_data[16 << SCTRDEPTH_MAX]; | 34 | - target_ulong sbadaddr; |
36 | + | 35 | - target_ulong mbadaddr; |
37 | /* Machine and Supervisor interrupt priorities */ | 36 | + target_ulong stval; |
38 | uint8_t miprio[64]; | 37 | target_ulong medeleg; |
39 | uint8_t siprio[64]; | 38 | |
40 | @@ -XXX,XX +XXX,XX @@ RISCVException smstateen_acc_ok(CPURISCVState *env, int index, uint64_t bit); | 39 | target_ulong stvec; |
41 | 40 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h | |
42 | void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv, bool virt_en); | 41 | index XXXXXXX..XXXXXXX 100644 |
43 | 42 | --- a/target/riscv/cpu_bits.h | |
44 | +void riscv_ctr_add_entry(CPURISCVState *env, target_long src, target_long dst, | 43 | +++ b/target/riscv/cpu_bits.h |
45 | + enum CTRType type, target_ulong prev_priv, bool prev_virt); | 44 | @@ -XXX,XX +XXX,XX @@ |
46 | + | 45 | /* 32-bit only */ |
47 | void riscv_translate_init(void); | 46 | #define CSR_MSTATUSH 0x310 |
48 | void riscv_translate_code(CPUState *cs, TranslationBlock *tb, | 47 | |
49 | int *max_insns, vaddr pc, void *host_pc); | 48 | -/* Legacy Counter Setup (priv v1.9.1) */ |
50 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h | 49 | -/* Update to #define CSR_MCOUNTINHIBIT 0x320 for 1.11.0 */ |
51 | index XXXXXXX..XXXXXXX 100644 | 50 | -#define CSR_MUCOUNTEREN 0x320 |
52 | --- a/target/riscv/helper.h | 51 | -#define CSR_MSCOUNTEREN 0x321 |
53 | +++ b/target/riscv/helper.h | 52 | -#define CSR_MHCOUNTEREN 0x322 |
54 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_1(wfi, void, env) | 53 | - |
55 | DEF_HELPER_1(wrs_nto, void, env) | 54 | /* Machine Trap Handling */ |
56 | DEF_HELPER_1(tlb_flush, void, env) | 55 | #define CSR_MSCRATCH 0x340 |
57 | DEF_HELPER_1(tlb_flush_all, void, env) | 56 | #define CSR_MEPC 0x341 |
58 | +DEF_HELPER_4(ctr_add_entry, void, env, tl, tl, tl) | 57 | @@ -XXX,XX +XXX,XX @@ |
59 | /* Native Debug */ | 58 | #define CSR_MTVAL 0x343 |
60 | DEF_HELPER_1(itrigger_match, void, env) | 59 | #define CSR_MIP 0x344 |
61 | #endif | 60 | |
61 | -/* Legacy Machine Trap Handling (priv v1.9.1) */ | ||
62 | -#define CSR_MBADADDR 0x343 | ||
63 | - | ||
64 | /* Supervisor Trap Setup */ | ||
65 | #define CSR_SSTATUS 0x100 | ||
66 | #define CSR_SEDELEG 0x102 | ||
67 | @@ -XXX,XX +XXX,XX @@ | ||
68 | #define CSR_STVAL 0x143 | ||
69 | #define CSR_SIP 0x144 | ||
70 | |||
71 | -/* Legacy Supervisor Trap Handling (priv v1.9.1) */ | ||
72 | -#define CSR_SBADADDR 0x143 | ||
73 | - | ||
74 | /* Supervisor Protection and Translation */ | ||
75 | #define CSR_SPTBR 0x180 | ||
76 | #define CSR_SATP 0x180 | ||
77 | @@ -XXX,XX +XXX,XX @@ | ||
78 | #define CSR_MHPMCOUNTER30H 0xb9e | ||
79 | #define CSR_MHPMCOUNTER31H 0xb9f | ||
80 | |||
81 | -/* Legacy Machine Protection and Translation (priv v1.9.1) */ | ||
82 | -#define CSR_MBASE 0x380 | ||
83 | -#define CSR_MBOUND 0x381 | ||
84 | -#define CSR_MIBASE 0x382 | ||
85 | -#define CSR_MIBOUND 0x383 | ||
86 | -#define CSR_MDBASE 0x384 | ||
87 | -#define CSR_MDBOUND 0x385 | ||
88 | - | ||
89 | /* mstatus CSR bits */ | ||
90 | #define MSTATUS_UIE 0x00000001 | ||
91 | #define MSTATUS_SIE 0x00000002 | ||
92 | @@ -XXX,XX +XXX,XX @@ | ||
93 | #define MSTATUS_FS 0x00006000 | ||
94 | #define MSTATUS_XS 0x00018000 | ||
95 | #define MSTATUS_MPRV 0x00020000 | ||
96 | -#define MSTATUS_PUM 0x00040000 /* until: priv-1.9.1 */ | ||
97 | #define MSTATUS_SUM 0x00040000 /* since: priv-1.10 */ | ||
98 | #define MSTATUS_MXR 0x00080000 | ||
99 | -#define MSTATUS_VM 0x1F000000 /* until: priv-1.9.1 */ | ||
100 | #define MSTATUS_TVM 0x00100000 /* since: priv-1.10 */ | ||
101 | #define MSTATUS_TW 0x00200000 /* since: priv-1.10 */ | ||
102 | #define MSTATUS_TSR 0x00400000 /* since: priv-1.10 */ | ||
103 | @@ -XXX,XX +XXX,XX @@ | ||
104 | #define SSTATUS_SPP 0x00000100 | ||
105 | #define SSTATUS_FS 0x00006000 | ||
106 | #define SSTATUS_XS 0x00018000 | ||
107 | -#define SSTATUS_PUM 0x00040000 /* until: priv-1.9.1 */ | ||
108 | #define SSTATUS_SUM 0x00040000 /* since: priv-1.10 */ | ||
109 | #define SSTATUS_MXR 0x00080000 | ||
110 | |||
111 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
112 | index XXXXXXX..XXXXXXX 100644 | ||
113 | --- a/target/riscv/cpu.c | ||
114 | +++ b/target/riscv/cpu.c | ||
115 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags) | ||
116 | qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "vscause ", env->vscause); | ||
117 | } | ||
118 | qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mtval ", env->mtval); | ||
119 | - qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "stval ", env->sbadaddr); | ||
120 | + qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "stval ", env->stval); | ||
121 | if (riscv_has_ext(env, RVH)) { | ||
122 | qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "htval ", env->htval); | ||
123 | qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mtval2 ", env->mtval2); | ||
62 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 124 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
63 | index XXXXXXX..XXXXXXX 100644 | 125 | index XXXXXXX..XXXXXXX 100644 |
64 | --- a/target/riscv/cpu_helper.c | 126 | --- a/target/riscv/cpu_helper.c |
65 | +++ b/target/riscv/cpu_helper.c | 127 | +++ b/target/riscv/cpu_helper.c |
66 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_set_aia_ireg_rmw_fn(CPURISCVState *env, uint32_t priv, | 128 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env) |
67 | } | 129 | env->vscause = env->scause; |
68 | } | 130 | env->scause = env->scause_hs; |
69 | 131 | ||
70 | +static void riscv_ctr_freeze(CPURISCVState *env, uint64_t freeze_mask, | 132 | - env->vstval = env->sbadaddr; |
71 | + bool virt) | 133 | - env->sbadaddr = env->stval_hs; |
72 | +{ | 134 | + env->vstval = env->stval; |
73 | + uint64_t ctl = virt ? env->vsctrctl : env->mctrctl; | 135 | + env->stval = env->stval_hs; |
74 | + | 136 | |
75 | + assert((freeze_mask & (~(XCTRCTL_BPFRZ | XCTRCTL_LCOFIFRZ))) == 0); | 137 | env->vsatp = env->satp; |
76 | + | 138 | env->satp = env->satp_hs; |
77 | + if (ctl & freeze_mask) { | 139 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env) |
78 | + env->sctrstatus |= SCTRSTATUS_FROZEN; | 140 | env->scause_hs = env->scause; |
79 | + } | 141 | env->scause = env->vscause; |
80 | +} | 142 | |
81 | + | 143 | - env->stval_hs = env->sbadaddr; |
82 | +static uint64_t riscv_ctr_priv_to_mask(target_ulong priv, bool virt) | 144 | - env->sbadaddr = env->vstval; |
83 | +{ | 145 | + env->stval_hs = env->stval; |
84 | + switch (priv) { | 146 | + env->stval = env->vstval; |
85 | + case PRV_M: | 147 | |
86 | + return MCTRCTL_M; | 148 | env->satp_hs = env->satp; |
87 | + case PRV_S: | 149 | env->satp = env->vsatp; |
88 | + if (virt) { | ||
89 | + return XCTRCTL_S; | ||
90 | + } | ||
91 | + return XCTRCTL_S; | ||
92 | + case PRV_U: | ||
93 | + if (virt) { | ||
94 | + return XCTRCTL_U; | ||
95 | + } | ||
96 | + return XCTRCTL_U; | ||
97 | + } | ||
98 | + | ||
99 | + g_assert_not_reached(); | ||
100 | +} | ||
101 | + | ||
102 | +static uint64_t riscv_ctr_get_control(CPURISCVState *env, target_long priv, | ||
103 | + bool virt) | ||
104 | +{ | ||
105 | + switch (priv) { | ||
106 | + case PRV_M: | ||
107 | + return env->mctrctl; | ||
108 | + case PRV_S: | ||
109 | + case PRV_U: | ||
110 | + if (virt) { | ||
111 | + return env->vsctrctl; | ||
112 | + } | ||
113 | + return env->mctrctl; | ||
114 | + } | ||
115 | + | ||
116 | + g_assert_not_reached(); | ||
117 | +} | ||
118 | + | ||
119 | +/* | ||
120 | + * This function assumes that src privilege and target privilege are not same | ||
121 | + * and src privilege is less than target privilege. This includes the virtual | ||
122 | + * state as well. | ||
123 | + */ | ||
124 | +static bool riscv_ctr_check_xte(CPURISCVState *env, target_long src_prv, | ||
125 | + bool src_virt) | ||
126 | +{ | ||
127 | + target_long tgt_prv = env->priv; | ||
128 | + bool res = true; | ||
129 | + | ||
130 | + /* | ||
131 | + * VS and U mode are same in terms of xTE bits required to record an | ||
132 | + * external trap. See 6.1.2. External Traps, table 8 External Trap Enable | ||
133 | + * Requirements. This changes VS to U to simplify the logic a bit. | ||
134 | + */ | ||
135 | + if (src_virt && src_prv == PRV_S) { | ||
136 | + src_prv = PRV_U; | ||
137 | + } else if (env->virt_enabled && tgt_prv == PRV_S) { | ||
138 | + tgt_prv = PRV_U; | ||
139 | + } | ||
140 | + | ||
141 | + /* VU mode is an outlier here. */ | ||
142 | + if (src_virt && src_prv == PRV_U) { | ||
143 | + res &= !!(env->vsctrctl & XCTRCTL_STE); | ||
144 | + } | ||
145 | + | ||
146 | + switch (src_prv) { | ||
147 | + case PRV_U: | ||
148 | + if (tgt_prv == PRV_U) { | ||
149 | + break; | ||
150 | + } | ||
151 | + res &= !!(env->mctrctl & XCTRCTL_STE); | ||
152 | + /* fall-through */ | ||
153 | + case PRV_S: | ||
154 | + if (tgt_prv == PRV_S) { | ||
155 | + break; | ||
156 | + } | ||
157 | + res &= !!(env->mctrctl & MCTRCTL_MTE); | ||
158 | + /* fall-through */ | ||
159 | + case PRV_M: | ||
160 | + break; | ||
161 | + } | ||
162 | + | ||
163 | + return res; | ||
164 | +} | ||
165 | + | ||
166 | +/* | ||
167 | + * Special cases for traps and trap returns: | ||
168 | + * | ||
169 | + * 1- Traps, and trap returns, between enabled modes are recorded as normal. | ||
170 | + * 2- Traps from an inhibited mode to an enabled mode, and trap returns from an | ||
171 | + * enabled mode back to an inhibited mode, are partially recorded. In such | ||
172 | + * cases, the PC from the inhibited mode (source PC for traps, and target PC | ||
173 | + * for trap returns) is 0. | ||
174 | + * | ||
175 | + * 3- Trap returns from an inhibited mode to an enabled mode are not recorded. | ||
176 | + * Traps from an enabled mode to an inhibited mode, known as external traps, | ||
177 | + * receive special handling. | ||
178 | + * By default external traps are not recorded, but a handshake mechanism exists | ||
179 | + * to allow partial recording. Software running in the target mode of the trap | ||
180 | + * can opt-in to allowing CTR to record traps into that mode even when the mode | ||
181 | + * is inhibited. The MTE, STE, and VSTE bits allow M-mode, S-mode, and VS-mode, | ||
182 | + * respectively, to opt-in. When an External Trap occurs, and xTE=1, such that | ||
183 | + * x is the target privilege mode of the trap, will CTR record the trap. In such | ||
184 | + * cases, the target PC is 0. | ||
185 | + */ | ||
186 | +/* | ||
187 | + * CTR arrays are implemented as circular buffers and new entry is stored at | ||
188 | + * sctrstatus.WRPTR, but they are presented to software as moving circular | ||
189 | + * buffers. Which means, software get's the illusion that whenever a new entry | ||
190 | + * is added the whole buffer is moved by one place and the new entry is added at | ||
191 | + * the start keeping new entry at idx 0 and older ones follow. | ||
192 | + * | ||
193 | + * Depth = 16. | ||
194 | + * | ||
195 | + * buffer [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [A] [B] [C] [D] [E] [F] | ||
196 | + * WRPTR W | ||
197 | + * entry 7 6 5 4 3 2 1 0 F E D C B A 9 8 | ||
198 | + * | ||
199 | + * When a new entry is added: | ||
200 | + * buffer [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [A] [B] [C] [D] [E] [F] | ||
201 | + * WRPTR W | ||
202 | + * entry 8 7 6 5 4 3 2 1 0 F E D C B A 9 | ||
203 | + * | ||
204 | + * entry here denotes the logical entry number that software can access | ||
205 | + * using ctrsource, ctrtarget and ctrdata registers. So xiselect 0x200 | ||
206 | + * will return entry 0 i-e buffer[8] and 0x201 will return entry 1 i-e | ||
207 | + * buffer[7]. Here is how we convert entry to buffer idx. | ||
208 | + * | ||
209 | + * entry = isel - CTR_ENTRIES_FIRST; | ||
210 | + * idx = (sctrstatus.WRPTR - entry - 1) & (depth - 1); | ||
211 | + */ | ||
212 | +void riscv_ctr_add_entry(CPURISCVState *env, target_long src, target_long dst, | ||
213 | + enum CTRType type, target_ulong src_priv, bool src_virt) | ||
214 | +{ | ||
215 | + bool tgt_virt = env->virt_enabled; | ||
216 | + uint64_t src_mask = riscv_ctr_priv_to_mask(src_priv, src_virt); | ||
217 | + uint64_t tgt_mask = riscv_ctr_priv_to_mask(env->priv, tgt_virt); | ||
218 | + uint64_t src_ctrl = riscv_ctr_get_control(env, src_priv, src_virt); | ||
219 | + uint64_t tgt_ctrl = riscv_ctr_get_control(env, env->priv, tgt_virt); | ||
220 | + uint64_t depth, head; | ||
221 | + bool ext_trap = false; | ||
222 | + | ||
223 | + /* | ||
224 | + * Return immediately if both target and src recording is disabled or if | ||
225 | + * CTR is in frozen state. | ||
226 | + */ | ||
227 | + if ((!(src_ctrl & src_mask) && !(tgt_ctrl & tgt_mask)) || | ||
228 | + env->sctrstatus & SCTRSTATUS_FROZEN) { | ||
229 | + return; | ||
230 | + } | ||
231 | + | ||
232 | + /* | ||
233 | + * With RAS Emul enabled, only allow Indirect, direct calls, Function | ||
234 | + * returns and Co-routine swap types. | ||
235 | + */ | ||
236 | + if (tgt_ctrl & XCTRCTL_RASEMU && | ||
237 | + type != CTRDATA_TYPE_INDIRECT_CALL && | ||
238 | + type != CTRDATA_TYPE_DIRECT_CALL && | ||
239 | + type != CTRDATA_TYPE_RETURN && | ||
240 | + type != CTRDATA_TYPE_CO_ROUTINE_SWAP) { | ||
241 | + return; | ||
242 | + } | ||
243 | + | ||
244 | + if (type == CTRDATA_TYPE_EXCEPTION || type == CTRDATA_TYPE_INTERRUPT) { | ||
245 | + /* Case 2 for traps. */ | ||
246 | + if (!(src_ctrl & src_mask)) { | ||
247 | + src = 0; | ||
248 | + } else if (!(tgt_ctrl & tgt_mask)) { | ||
249 | + /* Check if target priv-mode has allowed external trap recording. */ | ||
250 | + if (!riscv_ctr_check_xte(env, src_priv, src_virt)) { | ||
251 | + return; | ||
252 | + } | ||
253 | + | ||
254 | + ext_trap = true; | ||
255 | + dst = 0; | ||
256 | + } | ||
257 | + } else if (type == CTRDATA_TYPE_EXCEP_INT_RET) { | ||
258 | + /* | ||
259 | + * Case 3 for trap returns. Trap returns from inhibited mode are not | ||
260 | + * recorded. | ||
261 | + */ | ||
262 | + if (!(src_ctrl & src_mask)) { | ||
263 | + return; | ||
264 | + } | ||
265 | + | ||
266 | + /* Case 2 for trap returns. */ | ||
267 | + if (!(tgt_ctrl & tgt_mask)) { | ||
268 | + dst = 0; | ||
269 | + } | ||
270 | + } | ||
271 | + | ||
272 | + /* Ignore filters in case of RASEMU mode or External trap. */ | ||
273 | + if (!(tgt_ctrl & XCTRCTL_RASEMU) && !ext_trap) { | ||
274 | + /* | ||
275 | + * Check if the specific type is inhibited. Not taken branch filter is | ||
276 | + * an enable bit and needs to be checked separatly. | ||
277 | + */ | ||
278 | + bool check = tgt_ctrl & BIT_ULL(type + XCTRCTL_INH_START); | ||
279 | + if ((type == CTRDATA_TYPE_NONTAKEN_BRANCH && !check) || | ||
280 | + (type != CTRDATA_TYPE_NONTAKEN_BRANCH && check)) { | ||
281 | + return; | ||
282 | + } | ||
283 | + } | ||
284 | + | ||
285 | + head = get_field(env->sctrstatus, SCTRSTATUS_WRPTR_MASK); | ||
286 | + | ||
287 | + depth = 16 << get_field(env->sctrdepth, SCTRDEPTH_MASK); | ||
288 | + if (tgt_ctrl & XCTRCTL_RASEMU && type == CTRDATA_TYPE_RETURN) { | ||
289 | + head = (head - 1) & (depth - 1); | ||
290 | + | ||
291 | + env->ctr_src[head] &= ~CTRSOURCE_VALID; | ||
292 | + env->sctrstatus = | ||
293 | + set_field(env->sctrstatus, SCTRSTATUS_WRPTR_MASK, head); | ||
294 | + return; | ||
295 | + } | ||
296 | + | ||
297 | + /* In case of Co-routine SWAP we overwrite latest entry. */ | ||
298 | + if (tgt_ctrl & XCTRCTL_RASEMU && type == CTRDATA_TYPE_CO_ROUTINE_SWAP) { | ||
299 | + head = (head - 1) & (depth - 1); | ||
300 | + } | ||
301 | + | ||
302 | + env->ctr_src[head] = src | CTRSOURCE_VALID; | ||
303 | + env->ctr_dst[head] = dst & ~CTRTARGET_MISP; | ||
304 | + env->ctr_data[head] = set_field(0, CTRDATA_TYPE_MASK, type); | ||
305 | + | ||
306 | + head = (head + 1) & (depth - 1); | ||
307 | + | ||
308 | + env->sctrstatus = set_field(env->sctrstatus, SCTRSTATUS_WRPTR_MASK, head); | ||
309 | +} | ||
310 | + | ||
311 | void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv, bool virt_en) | ||
312 | { | ||
313 | g_assert(newpriv <= PRV_M && newpriv != PRV_RESERVED); | ||
314 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) | 150 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) |
315 | !(env->mip & (1ULL << cause)); | 151 | env->mstatus = s; |
316 | bool smode_double_trap = false; | 152 | env->scause = cause | ((target_ulong)async << (TARGET_LONG_BITS - 1)); |
317 | uint64_t hdeleg = async ? env->hideleg : env->hedeleg; | 153 | env->sepc = env->pc; |
318 | + const bool prev_virt = env->virt_enabled; | 154 | - env->sbadaddr = tval; |
319 | + const target_ulong prev_priv = env->priv; | 155 | + env->stval = tval; |
320 | target_ulong tval = 0; | 156 | env->htval = htval; |
321 | target_ulong tinst = 0; | 157 | env->pc = (env->stvec >> 2 << 2) + |
322 | target_ulong htval = 0; | 158 | ((async && (env->stvec & 3) == 1) ? cause * 4 : 0); |
323 | target_ulong mtval2 = 0; | ||
324 | + target_ulong src; | ||
325 | int sxlen = 0; | ||
326 | int mxlen = 16 << riscv_cpu_mxl(env); | ||
327 | bool nnmi_excep = false; | ||
328 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) | 159 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) |
329 | env->pc = (env->stvec >> 2 << 2) + | 160 | env->mstatus = s; |
330 | ((async && (env->stvec & 3) == 1) ? cause * 4 : 0); | 161 | env->mcause = cause | ~(((target_ulong)-1) >> async); |
331 | riscv_cpu_set_mode(env, PRV_S, virt); | 162 | env->mepc = env->pc; |
332 | + | 163 | - env->mbadaddr = tval; |
333 | + src = env->sepc; | 164 | + env->mtval = tval; |
334 | } else { | 165 | env->mtval2 = mtval2; |
335 | /* | 166 | env->pc = (env->mtvec >> 2 << 2) + |
336 | * If the hart encounters an exception while executing in M-mode | 167 | ((async && (env->mtvec & 3) == 1) ? cause * 4 : 0); |
337 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) | 168 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
338 | ((async && (env->mtvec & 3) == 1) ? cause * 4 : 0); | 169 | index XXXXXXX..XXXXXXX 100644 |
339 | } | 170 | --- a/target/riscv/csr.c |
340 | riscv_cpu_set_mode(env, PRV_M, virt); | 171 | +++ b/target/riscv/csr.c |
341 | + src = env->mepc; | 172 | @@ -XXX,XX +XXX,XX @@ static int write_mcounteren(CPURISCVState *env, int csrno, target_ulong val) |
342 | + } | 173 | return 0; |
343 | + | 174 | } |
344 | + if (riscv_cpu_cfg(env)->ext_smctr || riscv_cpu_cfg(env)->ext_ssctr) { | 175 | |
345 | + if (async && cause == IRQ_PMU_OVF) { | 176 | -/* This regiser is replaced with CSR_MCOUNTINHIBIT in 1.11.0 */ |
346 | + riscv_ctr_freeze(env, XCTRCTL_LCOFIFRZ, virt); | 177 | -static int read_mscounteren(CPURISCVState *env, int csrno, target_ulong *val) |
347 | + } else if (!async && cause == RISCV_EXCP_BREAKPOINT) { | 178 | -{ |
348 | + riscv_ctr_freeze(env, XCTRCTL_BPFRZ, virt); | 179 | - if (env->priv_ver < PRIV_VERSION_1_11_0) { |
349 | + } | 180 | - return -RISCV_EXCP_ILLEGAL_INST; |
350 | + | 181 | - } |
351 | + riscv_ctr_add_entry(env, src, env->pc, | 182 | - *val = env->mcounteren; |
352 | + async ? CTRDATA_TYPE_INTERRUPT : CTRDATA_TYPE_EXCEPTION, | 183 | - return 0; |
353 | + prev_priv, prev_virt); | 184 | -} |
354 | } | 185 | - |
355 | 186 | -/* This regiser is replaced with CSR_MCOUNTINHIBIT in 1.11.0 */ | |
356 | /* | 187 | -static int write_mscounteren(CPURISCVState *env, int csrno, target_ulong val) |
357 | diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c | 188 | -{ |
358 | index XXXXXXX..XXXXXXX 100644 | 189 | - if (env->priv_ver < PRIV_VERSION_1_11_0) { |
359 | --- a/target/riscv/op_helper.c | 190 | - return -RISCV_EXCP_ILLEGAL_INST; |
360 | +++ b/target/riscv/op_helper.c | 191 | - } |
361 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_sret(CPURISCVState *env) | 192 | - env->mcounteren = val; |
362 | { | 193 | - return 0; |
363 | uint64_t mstatus; | 194 | -} |
364 | target_ulong prev_priv, prev_virt = env->virt_enabled; | 195 | - |
365 | + const target_ulong src_priv = env->priv; | 196 | /* Machine Trap Handling */ |
366 | + const bool src_virt = env->virt_enabled; | 197 | static int read_mscratch(CPURISCVState *env, int csrno, target_ulong *val) |
367 | 198 | { | |
368 | if (!(env->priv >= PRV_S)) { | 199 | @@ -XXX,XX +XXX,XX @@ static int write_mcause(CPURISCVState *env, int csrno, target_ulong val) |
369 | riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); | 200 | return 0; |
370 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_sret(CPURISCVState *env) | 201 | } |
371 | } | 202 | |
372 | env->mstatus = set_field(env->mstatus, MSTATUS_SPELP, 0); | 203 | -static int read_mbadaddr(CPURISCVState *env, int csrno, target_ulong *val) |
373 | 204 | +static int read_mtval(CPURISCVState *env, int csrno, target_ulong *val) | |
374 | + if (riscv_cpu_cfg(env)->ext_smctr || riscv_cpu_cfg(env)->ext_ssctr) { | 205 | { |
375 | + riscv_ctr_add_entry(env, env->pc, retpc, CTRDATA_TYPE_EXCEP_INT_RET, | 206 | - *val = env->mbadaddr; |
376 | + src_priv, src_virt); | 207 | + *val = env->mtval; |
377 | + } | 208 | return 0; |
378 | + | 209 | } |
379 | return retpc; | 210 | |
380 | } | 211 | -static int write_mbadaddr(CPURISCVState *env, int csrno, target_ulong val) |
381 | 212 | +static int write_mtval(CPURISCVState *env, int csrno, target_ulong val) | |
382 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_mret(CPURISCVState *env) | 213 | { |
383 | } | 214 | - env->mbadaddr = val; |
384 | env->mstatus = set_field(env->mstatus, MSTATUS_MPELP, 0); | 215 | + env->mtval = val; |
385 | 216 | return 0; | |
386 | + if (riscv_cpu_cfg(env)->ext_smctr || riscv_cpu_cfg(env)->ext_ssctr) { | 217 | } |
387 | + riscv_ctr_add_entry(env, env->pc, retpc, CTRDATA_TYPE_EXCEP_INT_RET, | 218 | |
388 | + PRV_M, false); | 219 | @@ -XXX,XX +XXX,XX @@ static int write_scause(CPURISCVState *env, int csrno, target_ulong val) |
389 | + } | 220 | return 0; |
390 | + | 221 | } |
391 | return retpc; | 222 | |
392 | } | 223 | -static int read_sbadaddr(CPURISCVState *env, int csrno, target_ulong *val) |
393 | 224 | +static int read_stval(CPURISCVState *env, int csrno, target_ulong *val) | |
394 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_mnret(CPURISCVState *env) | 225 | { |
395 | return retpc; | 226 | - *val = env->sbadaddr; |
396 | } | 227 | + *val = env->stval; |
397 | 228 | return 0; | |
398 | +void helper_ctr_add_entry(CPURISCVState *env, target_ulong src, | 229 | } |
399 | + target_ulong dest, target_ulong type) | 230 | |
400 | +{ | 231 | -static int write_sbadaddr(CPURISCVState *env, int csrno, target_ulong val) |
401 | + riscv_ctr_add_entry(env, src, dest, (enum CTRType)type, | 232 | +static int write_stval(CPURISCVState *env, int csrno, target_ulong val) |
402 | + env->priv, env->virt_enabled); | 233 | { |
403 | +} | 234 | - env->sbadaddr = val; |
404 | + | 235 | + env->stval = val; |
405 | void helper_wfi(CPURISCVState *env) | 236 | return 0; |
406 | { | 237 | } |
407 | CPUState *cs = env_cpu(env); | 238 | |
239 | @@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { | ||
240 | |||
241 | [CSR_MSTATUSH] = { "mstatush", any32, read_mstatush, write_mstatush }, | ||
242 | |||
243 | - [CSR_MSCOUNTEREN] = { "msounteren", any, read_mscounteren, write_mscounteren }, | ||
244 | - | ||
245 | /* Machine Trap Handling */ | ||
246 | [CSR_MSCRATCH] = { "mscratch", any, read_mscratch, write_mscratch }, | ||
247 | [CSR_MEPC] = { "mepc", any, read_mepc, write_mepc }, | ||
248 | [CSR_MCAUSE] = { "mcause", any, read_mcause, write_mcause }, | ||
249 | - [CSR_MBADADDR] = { "mbadaddr", any, read_mbadaddr, write_mbadaddr }, | ||
250 | + [CSR_MTVAL] = { "mtval", any, read_mtval, write_mtval }, | ||
251 | [CSR_MIP] = { "mip", any, NULL, NULL, rmw_mip }, | ||
252 | |||
253 | /* Supervisor Trap Setup */ | ||
254 | @@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { | ||
255 | [CSR_SSCRATCH] = { "sscratch", smode, read_sscratch, write_sscratch }, | ||
256 | [CSR_SEPC] = { "sepc", smode, read_sepc, write_sepc }, | ||
257 | [CSR_SCAUSE] = { "scause", smode, read_scause, write_scause }, | ||
258 | - [CSR_SBADADDR] = { "sbadaddr", smode, read_sbadaddr, write_sbadaddr }, | ||
259 | + [CSR_STVAL] = { "stval", smode, read_stval, write_stval }, | ||
260 | [CSR_SIP] = { "sip", smode, NULL, NULL, rmw_sip }, | ||
261 | |||
262 | /* Supervisor Protection and Translation */ | ||
263 | diff --git a/target/riscv/machine.c b/target/riscv/machine.c | ||
264 | index XXXXXXX..XXXXXXX 100644 | ||
265 | --- a/target/riscv/machine.c | ||
266 | +++ b/target/riscv/machine.c | ||
267 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_hyper = { | ||
268 | |||
269 | const VMStateDescription vmstate_riscv_cpu = { | ||
270 | .name = "cpu", | ||
271 | - .version_id = 1, | ||
272 | - .minimum_version_id = 1, | ||
273 | + .version_id = 2, | ||
274 | + .minimum_version_id = 2, | ||
275 | .fields = (VMStateField[]) { | ||
276 | VMSTATE_UINTTL_ARRAY(env.gpr, RISCVCPU, 32), | ||
277 | VMSTATE_UINT64_ARRAY(env.fpr, RISCVCPU, 32), | ||
278 | @@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_riscv_cpu = { | ||
279 | VMSTATE_UINT32(env.miclaim, RISCVCPU), | ||
280 | VMSTATE_UINTTL(env.mie, RISCVCPU), | ||
281 | VMSTATE_UINTTL(env.mideleg, RISCVCPU), | ||
282 | - VMSTATE_UINTTL(env.sptbr, RISCVCPU), | ||
283 | VMSTATE_UINTTL(env.satp, RISCVCPU), | ||
284 | - VMSTATE_UINTTL(env.sbadaddr, RISCVCPU), | ||
285 | - VMSTATE_UINTTL(env.mbadaddr, RISCVCPU), | ||
286 | + VMSTATE_UINTTL(env.stval, RISCVCPU), | ||
287 | VMSTATE_UINTTL(env.medeleg, RISCVCPU), | ||
288 | VMSTATE_UINTTL(env.stvec, RISCVCPU), | ||
289 | VMSTATE_UINTTL(env.sepc, RISCVCPU), | ||
408 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | 290 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c |
409 | index XXXXXXX..XXXXXXX 100644 | 291 | index XXXXXXX..XXXXXXX 100644 |
410 | --- a/target/riscv/translate.c | 292 | --- a/target/riscv/translate.c |
411 | +++ b/target/riscv/translate.c | 293 | +++ b/target/riscv/translate.c |
412 | @@ -XXX,XX +XXX,XX @@ static void gen_set_fpr_d(DisasContext *ctx, int reg_num, TCGv_i64 t) | 294 | @@ -XXX,XX +XXX,XX @@ static void generate_exception(DisasContext *ctx, int excp) |
413 | } | ||
414 | } | ||
415 | |||
416 | +#ifndef CONFIG_USER_ONLY | ||
417 | +/* | ||
418 | + * Direct calls | ||
419 | + * - jal x1; | ||
420 | + * - jal x5; | ||
421 | + * - c.jal. | ||
422 | + * - cm.jalt. | ||
423 | + * | ||
424 | + * Direct jumps | ||
425 | + * - jal x0; | ||
426 | + * - c.j; | ||
427 | + * - cm.jt. | ||
428 | + * | ||
429 | + * Other direct jumps | ||
430 | + * - jal rd where rd != x1 and rd != x5 and rd != x0; | ||
431 | + */ | ||
432 | +static void gen_ctr_jal(DisasContext *ctx, int rd, target_ulong imm) | ||
433 | +{ | ||
434 | + TCGv dest = tcg_temp_new(); | ||
435 | + TCGv src = tcg_temp_new(); | ||
436 | + TCGv type; | ||
437 | + | ||
438 | + /* | ||
439 | + * If rd is x1 or x5 link registers, treat this as direct call otherwise | ||
440 | + * its a direct jump. | ||
441 | + */ | ||
442 | + if (rd == 1 || rd == 5) { | ||
443 | + type = tcg_constant_tl(CTRDATA_TYPE_DIRECT_CALL); | ||
444 | + } else if (rd == 0) { | ||
445 | + type = tcg_constant_tl(CTRDATA_TYPE_DIRECT_JUMP); | ||
446 | + } else { | ||
447 | + type = tcg_constant_tl(CTRDATA_TYPE_OTHER_DIRECT_JUMP); | ||
448 | + } | ||
449 | + | ||
450 | + gen_pc_plus_diff(dest, ctx, imm); | ||
451 | + gen_pc_plus_diff(src, ctx, 0); | ||
452 | + gen_helper_ctr_add_entry(tcg_env, src, dest, type); | ||
453 | +} | ||
454 | +#endif | ||
455 | + | ||
456 | static void gen_jal(DisasContext *ctx, int rd, target_ulong imm) | ||
457 | { | ||
458 | TCGv succ_pc = dest_gpr(ctx, rd); | ||
459 | @@ -XXX,XX +XXX,XX @@ static void gen_jal(DisasContext *ctx, int rd, target_ulong imm) | ||
460 | } | ||
461 | } | ||
462 | |||
463 | +#ifndef CONFIG_USER_ONLY | ||
464 | + if (ctx->cfg_ptr->ext_smctr || ctx->cfg_ptr->ext_ssctr) { | ||
465 | + gen_ctr_jal(ctx, rd, imm); | ||
466 | + } | ||
467 | +#endif | ||
468 | + | ||
469 | gen_pc_plus_diff(succ_pc, ctx, ctx->cur_insn_len); | ||
470 | gen_set_gpr(ctx, rd, succ_pc); | ||
471 | |||
472 | diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc | ||
473 | index XXXXXXX..XXXXXXX 100644 | ||
474 | --- a/target/riscv/insn_trans/trans_privileged.c.inc | ||
475 | +++ b/target/riscv/insn_trans/trans_privileged.c.inc | ||
476 | @@ -XXX,XX +XXX,XX @@ static bool trans_sret(DisasContext *ctx, arg_sret *a) | ||
477 | if (has_ext(ctx, RVS)) { | ||
478 | decode_save_opc(ctx, 0); | ||
479 | translator_io_start(&ctx->base); | ||
480 | + gen_update_pc(ctx, 0); | ||
481 | gen_helper_sret(cpu_pc, tcg_env); | ||
482 | exit_tb(ctx); /* no chaining */ | ||
483 | ctx->base.is_jmp = DISAS_NORETURN; | ||
484 | @@ -XXX,XX +XXX,XX @@ static bool trans_mret(DisasContext *ctx, arg_mret *a) | ||
485 | #ifndef CONFIG_USER_ONLY | ||
486 | decode_save_opc(ctx, 0); | ||
487 | translator_io_start(&ctx->base); | ||
488 | + gen_update_pc(ctx, 0); | ||
489 | gen_helper_mret(cpu_pc, tcg_env); | ||
490 | exit_tb(ctx); /* no chaining */ | ||
491 | ctx->base.is_jmp = DISAS_NORETURN; | 295 | ctx->base.is_jmp = DISAS_NORETURN; |
492 | diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_trans/trans_rvi.c.inc | 296 | } |
493 | index XXXXXXX..XXXXXXX 100644 | 297 | |
494 | --- a/target/riscv/insn_trans/trans_rvi.c.inc | 298 | -static void generate_exception_mbadaddr(DisasContext *ctx, int excp) |
495 | +++ b/target/riscv/insn_trans/trans_rvi.c.inc | 299 | +static void generate_exception_mtval(DisasContext *ctx, int excp) |
496 | @@ -XXX,XX +XXX,XX @@ static bool trans_jal(DisasContext *ctx, arg_jal *a) | 300 | { |
497 | return true; | 301 | tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next); |
498 | } | 302 | tcg_gen_st_tl(cpu_pc, cpu_env, offsetof(CPURISCVState, badaddr)); |
499 | 303 | @@ -XXX,XX +XXX,XX @@ static void gen_exception_illegal(DisasContext *ctx) | |
500 | +#ifndef CONFIG_USER_ONLY | 304 | |
501 | +/* | 305 | static void gen_exception_inst_addr_mis(DisasContext *ctx) |
502 | + * Indirect calls | 306 | { |
503 | + * - jalr x1, rs where rs != x5; | 307 | - generate_exception_mbadaddr(ctx, RISCV_EXCP_INST_ADDR_MIS); |
504 | + * - jalr x5, rs where rs != x1; | 308 | + generate_exception_mtval(ctx, RISCV_EXCP_INST_ADDR_MIS); |
505 | + * - c.jalr rs1 where rs1 != x5; | 309 | } |
506 | + * | 310 | |
507 | + * Indirect jumps | 311 | static inline bool use_goto_tb(DisasContext *ctx, target_ulong dest) |
508 | + * - jalr x0, rs where rs != x1 and rs != x5; | ||
509 | + * - c.jr rs1 where rs1 != x1 and rs1 != x5. | ||
510 | + * | ||
511 | + * Returns | ||
512 | + * - jalr rd, rs where (rs == x1 or rs == x5) and rd != x1 and rd != x5; | ||
513 | + * - c.jr rs1 where rs1 == x1 or rs1 == x5. | ||
514 | + * | ||
515 | + * Co-routine swap | ||
516 | + * - jalr x1, x5; | ||
517 | + * - jalr x5, x1; | ||
518 | + * - c.jalr x5. | ||
519 | + * | ||
520 | + * Other indirect jumps | ||
521 | + * - jalr rd, rs where rs != x1, rs != x5, rd != x0, rd != x1 and rd != x5. | ||
522 | + */ | ||
523 | +static void gen_ctr_jalr(DisasContext *ctx, arg_jalr *a, TCGv dest) | ||
524 | +{ | ||
525 | + TCGv src = tcg_temp_new(); | ||
526 | + TCGv type; | ||
527 | + | ||
528 | + if ((a->rd == 1 && a->rs1 != 5) || (a->rd == 5 && a->rs1 != 1)) { | ||
529 | + type = tcg_constant_tl(CTRDATA_TYPE_INDIRECT_CALL); | ||
530 | + } else if (a->rd == 0 && a->rs1 != 1 && a->rs1 != 5) { | ||
531 | + type = tcg_constant_tl(CTRDATA_TYPE_INDIRECT_JUMP); | ||
532 | + } else if ((a->rs1 == 1 || a->rs1 == 5) && (a->rd != 1 && a->rd != 5)) { | ||
533 | + type = tcg_constant_tl(CTRDATA_TYPE_RETURN); | ||
534 | + } else if ((a->rs1 == 1 && a->rd == 5) || (a->rs1 == 5 && a->rd == 1)) { | ||
535 | + type = tcg_constant_tl(CTRDATA_TYPE_CO_ROUTINE_SWAP); | ||
536 | + } else { | ||
537 | + type = tcg_constant_tl(CTRDATA_TYPE_OTHER_INDIRECT_JUMP); | ||
538 | + } | ||
539 | + | ||
540 | + gen_pc_plus_diff(src, ctx, 0); | ||
541 | + gen_helper_ctr_add_entry(tcg_env, src, dest, type); | ||
542 | +} | ||
543 | +#endif | ||
544 | + | ||
545 | static bool trans_jalr(DisasContext *ctx, arg_jalr *a) | ||
546 | { | ||
547 | TCGLabel *misaligned = NULL; | ||
548 | @@ -XXX,XX +XXX,XX @@ static bool trans_jalr(DisasContext *ctx, arg_jalr *a) | ||
549 | gen_pc_plus_diff(succ_pc, ctx, ctx->cur_insn_len); | ||
550 | gen_set_gpr(ctx, a->rd, succ_pc); | ||
551 | |||
552 | +#ifndef CONFIG_USER_ONLY | ||
553 | + if (ctx->cfg_ptr->ext_smctr || ctx->cfg_ptr->ext_ssctr) { | ||
554 | + gen_ctr_jalr(ctx, a, target_pc); | ||
555 | + } | ||
556 | +#endif | ||
557 | + | ||
558 | tcg_gen_mov_tl(cpu_pc, target_pc); | ||
559 | if (ctx->fcfi_enabled) { | ||
560 | /* | ||
561 | @@ -XXX,XX +XXX,XX @@ static bool gen_branch(DisasContext *ctx, arg_b *a, TCGCond cond) | ||
562 | } else { | ||
563 | tcg_gen_brcond_tl(cond, src1, src2, l); | ||
564 | } | ||
565 | + | ||
566 | +#ifndef CONFIG_USER_ONLY | ||
567 | + if (ctx->cfg_ptr->ext_smctr || ctx->cfg_ptr->ext_ssctr) { | ||
568 | + TCGv type = tcg_constant_tl(CTRDATA_TYPE_NONTAKEN_BRANCH); | ||
569 | + TCGv dest = tcg_temp_new(); | ||
570 | + TCGv src = tcg_temp_new(); | ||
571 | + | ||
572 | + gen_pc_plus_diff(src, ctx, 0); | ||
573 | + gen_pc_plus_diff(dest, ctx, ctx->cur_insn_len); | ||
574 | + gen_helper_ctr_add_entry(tcg_env, src, dest, type); | ||
575 | + } | ||
576 | +#endif | ||
577 | + | ||
578 | gen_goto_tb(ctx, 1, ctx->cur_insn_len); | ||
579 | ctx->pc_save = orig_pc_save; | ||
580 | |||
581 | @@ -XXX,XX +XXX,XX @@ static bool gen_branch(DisasContext *ctx, arg_b *a, TCGCond cond) | ||
582 | gen_pc_plus_diff(target_pc, ctx, a->imm); | ||
583 | gen_exception_inst_addr_mis(ctx, target_pc); | ||
584 | } else { | ||
585 | +#ifndef CONFIG_USER_ONLY | ||
586 | + if (ctx->cfg_ptr->ext_smctr || ctx->cfg_ptr->ext_ssctr) { | ||
587 | + TCGv type = tcg_constant_tl(CTRDATA_TYPE_TAKEN_BRANCH); | ||
588 | + TCGv dest = tcg_temp_new(); | ||
589 | + TCGv src = tcg_temp_new(); | ||
590 | + | ||
591 | + gen_pc_plus_diff(src, ctx, 0); | ||
592 | + gen_pc_plus_diff(dest, ctx, a->imm); | ||
593 | + gen_helper_ctr_add_entry(tcg_env, src, dest, type); | ||
594 | + } | ||
595 | +#endif | ||
596 | gen_goto_tb(ctx, 0, a->imm); | ||
597 | } | ||
598 | ctx->pc_save = -1; | ||
599 | diff --git a/target/riscv/insn_trans/trans_rvzce.c.inc b/target/riscv/insn_trans/trans_rvzce.c.inc | ||
600 | index XXXXXXX..XXXXXXX 100644 | ||
601 | --- a/target/riscv/insn_trans/trans_rvzce.c.inc | ||
602 | +++ b/target/riscv/insn_trans/trans_rvzce.c.inc | ||
603 | @@ -XXX,XX +XXX,XX @@ static bool gen_pop(DisasContext *ctx, arg_cmpp *a, bool ret, bool ret_val) | ||
604 | |||
605 | if (ret) { | ||
606 | TCGv ret_addr = get_gpr(ctx, xRA, EXT_SIGN); | ||
607 | +#ifndef CONFIG_USER_ONLY | ||
608 | + if (ctx->cfg_ptr->ext_smctr || ctx->cfg_ptr->ext_ssctr) { | ||
609 | + TCGv type = tcg_constant_tl(CTRDATA_TYPE_RETURN); | ||
610 | + TCGv src = tcg_temp_new(); | ||
611 | + gen_pc_plus_diff(src, ctx, 0); | ||
612 | + gen_helper_ctr_add_entry(tcg_env, src, ret_addr, type); | ||
613 | + } | ||
614 | +#endif | ||
615 | tcg_gen_mov_tl(cpu_pc, ret_addr); | ||
616 | tcg_gen_lookup_and_goto_ptr(); | ||
617 | ctx->base.is_jmp = DISAS_NORETURN; | ||
618 | @@ -XXX,XX +XXX,XX @@ static bool trans_cm_jalt(DisasContext *ctx, arg_cm_jalt *a) | ||
619 | gen_set_gpr(ctx, xRA, succ_pc); | ||
620 | } | ||
621 | |||
622 | +#ifndef CONFIG_USER_ONLY | ||
623 | + if (ctx->cfg_ptr->ext_smctr || ctx->cfg_ptr->ext_ssctr) { | ||
624 | + if (a->index >= 32) { | ||
625 | + TCGv type = tcg_constant_tl(CTRDATA_TYPE_DIRECT_CALL); | ||
626 | + gen_helper_ctr_add_entry(tcg_env, cpu_pc, addr, type); | ||
627 | + } else { | ||
628 | + TCGv type = tcg_constant_tl(CTRDATA_TYPE_DIRECT_JUMP); | ||
629 | + gen_helper_ctr_add_entry(tcg_env, cpu_pc, addr, type); | ||
630 | + } | ||
631 | + } | ||
632 | +#endif | ||
633 | + | ||
634 | + | ||
635 | tcg_gen_mov_tl(cpu_pc, addr); | ||
636 | |||
637 | tcg_gen_lookup_and_goto_ptr(); | ||
638 | -- | 312 | -- |
639 | 2.48.1 | 313 | 2.31.1 |
314 | |||
315 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Axel Heider <axelheider@gmx.de> |
---|---|---|---|
2 | 2 | ||
3 | We're setting reset vals for KVM csrs during kvm_riscv_reset_vcpu(), but | 3 | Fix style to have a proper description of the parameter 'force-raw'. |
4 | in no particular order and missing some of them (like env->mstatus). | ||
5 | 4 | ||
6 | Create a helper to do that, unclogging reset_vcpu(), and initialize | 5 | Signed-off-by: Axel Heider <axelheider@gmx.de> |
7 | env->mstatus as well. Keep the regs in the same order they appear in | ||
8 | struct kvm_riscv_csr from the KVM UAPI, similar to what | ||
9 | kvm_riscv_(get|put)_regs_csr are doing. This will make a bit easier to | ||
10 | add new KVM CSRs and to verify which values we're writing back to KVM | ||
11 | during vcpu reset. | ||
12 | |||
13 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
14 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
15 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
16 | Message-ID: <20250224123120.1644186-3-dbarboza@ventanamicro.com> | 7 | Message-id: a7e50a64-1c7c-2d41-96d3-d8a417a659ac@gmx.de |
17 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
18 | --- | 9 | --- |
19 | target/riscv/kvm/kvm-cpu.c | 23 +++++++++++++++-------- | 10 | docs/system/generic-loader.rst | 9 ++++++--- |
20 | 1 file changed, 15 insertions(+), 8 deletions(-) | 11 | 1 file changed, 6 insertions(+), 3 deletions(-) |
21 | 12 | ||
22 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c | 13 | diff --git a/docs/system/generic-loader.rst b/docs/system/generic-loader.rst |
23 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/target/riscv/kvm/kvm-cpu.c | 15 | --- a/docs/system/generic-loader.rst |
25 | +++ b/target/riscv/kvm/kvm-cpu.c | 16 | +++ b/docs/system/generic-loader.rst |
26 | @@ -XXX,XX +XXX,XX @@ static int kvm_riscv_put_regs_core(CPUState *cs) | 17 | @@ -XXX,XX +XXX,XX @@ shown below: |
27 | return ret; | 18 | specified in the executable format header. This option should only |
28 | } | 19 | be used for the boot image. This will also cause the image to be |
29 | 20 | written to the specified CPU's address space. If not specified, the | |
30 | +static void kvm_riscv_reset_regs_csr(CPURISCVState *env) | 21 | - default is CPU 0. <force-raw> - Setting force-raw=on forces the file |
31 | +{ | 22 | - to be treated as a raw image. This can be used to load supported |
32 | + env->mstatus = 0; | 23 | - executable formats as if they were raw. |
33 | + env->mie = 0; | 24 | + default is CPU 0. |
34 | + env->stvec = 0; | ||
35 | + env->sscratch = 0; | ||
36 | + env->sepc = 0; | ||
37 | + env->scause = 0; | ||
38 | + env->stval = 0; | ||
39 | + env->mip = 0; | ||
40 | + env->satp = 0; | ||
41 | +} | ||
42 | + | 25 | + |
43 | static int kvm_riscv_get_regs_csr(CPUState *cs) | 26 | +``<force-raw>`` |
44 | { | 27 | + Setting 'force-raw=on' forces the file to be treated as a raw image. |
45 | CPURISCVState *env = &RISCV_CPU(cs)->env; | 28 | + This can be used to load supported executable formats as if they |
46 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_reset_vcpu(RISCVCPU *cpu) | 29 | + were raw. |
47 | env->pc = cpu->env.kernel_addr; | 30 | |
48 | env->gpr[10] = kvm_arch_vcpu_id(CPU(cpu)); /* a0 */ | 31 | All values are parsed using the standard QemuOpts parsing. This allows the user |
49 | env->gpr[11] = cpu->env.fdt_addr; /* a1 */ | 32 | to specify any values in any format supported. By default the values |
50 | - env->satp = 0; | ||
51 | - env->mie = 0; | ||
52 | - env->stvec = 0; | ||
53 | - env->sscratch = 0; | ||
54 | - env->sepc = 0; | ||
55 | - env->scause = 0; | ||
56 | - env->stval = 0; | ||
57 | - env->mip = 0; | ||
58 | + | ||
59 | + kvm_riscv_reset_regs_csr(env); | ||
60 | } | ||
61 | |||
62 | void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level) | ||
63 | -- | 33 | -- |
64 | 2.48.1 | 34 | 2.31.1 |
35 | |||
36 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Dylan Jhong <dylan@andestech.com> |
---|---|---|---|
2 | 2 | ||
3 | At this moment ziccrse is a TCG always enabled named feature for | 3 | Use target_ulong to instead of uint64_t on reset vector address |
4 | priv_ver > 1.11 that has no exclusive flag. In the next patch we'll make | 4 | to adapt on both 32/64 machine. |
5 | the KVM driver turn ziccrse off if the extension isn't available in the | ||
6 | host, and we'll need an ext_ziccrse flag in the CPU state for that. | ||
7 | 5 | ||
8 | Create an exclusive flag for it like we do with other named features. | 6 | Signed-off-by: Dylan Jhong <dylan@andestech.com> |
9 | As with any named features we already have, it won't be exposed to | 7 | Signed-off-by: Ruinland ChuanTzu Tsai <ruinland@andestech.com> |
10 | users. | 8 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> |
11 | 9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | |
12 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 10 | Message-id: 20210329034801.22667-1-dylan@andestech.com |
13 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
14 | Message-ID: <20250221153758.652078-3-dbarboza@ventanamicro.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/cpu_cfg.h | 3 +++ | 13 | target/riscv/cpu.c | 2 +- |
18 | target/riscv/cpu.c | 3 ++- | 14 | 1 file changed, 1 insertion(+), 1 deletion(-) |
19 | target/riscv/tcg/tcg-cpu.c | 2 ++ | ||
20 | 3 files changed, 7 insertions(+), 1 deletion(-) | ||
21 | 15 | ||
22 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h | ||
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/target/riscv/cpu_cfg.h | ||
25 | +++ b/target/riscv/cpu_cfg.h | ||
26 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { | ||
27 | bool has_priv_1_12; | ||
28 | bool has_priv_1_11; | ||
29 | |||
30 | + /* Always enabled for TCG if has_priv_1_11 */ | ||
31 | + bool ext_ziccrse; | ||
32 | + | ||
33 | /* Vendor-specific custom extensions */ | ||
34 | bool ext_xtheadba; | ||
35 | bool ext_xtheadbb; | ||
36 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 16 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
37 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
38 | --- a/target/riscv/cpu.c | 18 | --- a/target/riscv/cpu.c |
39 | +++ b/target/riscv/cpu.c | 19 | +++ b/target/riscv/cpu.c |
40 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { | 20 | @@ -XXX,XX +XXX,XX @@ static void set_feature(CPURISCVState *env, int feature) |
41 | ISA_EXT_DATA_ENTRY(ziccamoa, PRIV_VERSION_1_11_0, has_priv_1_11), | 21 | env->features |= (1ULL << feature); |
42 | ISA_EXT_DATA_ENTRY(ziccif, PRIV_VERSION_1_11_0, has_priv_1_11), | ||
43 | ISA_EXT_DATA_ENTRY(zicclsm, PRIV_VERSION_1_11_0, has_priv_1_11), | ||
44 | - ISA_EXT_DATA_ENTRY(ziccrse, PRIV_VERSION_1_11_0, has_priv_1_11), | ||
45 | + ISA_EXT_DATA_ENTRY(ziccrse, PRIV_VERSION_1_11_0, ext_ziccrse), | ||
46 | ISA_EXT_DATA_ENTRY(zicfilp, PRIV_VERSION_1_12_0, ext_zicfilp), | ||
47 | ISA_EXT_DATA_ENTRY(zicfiss, PRIV_VERSION_1_13_0, ext_zicfiss), | ||
48 | ISA_EXT_DATA_ENTRY(zicond, PRIV_VERSION_1_12_0, ext_zicond), | ||
49 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_named_features[] = { | ||
50 | MULTI_EXT_CFG_BOOL("zic64b", ext_zic64b, true), | ||
51 | MULTI_EXT_CFG_BOOL("ssstateen", ext_ssstateen, true), | ||
52 | MULTI_EXT_CFG_BOOL("sha", ext_sha, true), | ||
53 | + MULTI_EXT_CFG_BOOL("ziccrse", ext_ziccrse, true), | ||
54 | |||
55 | { }, | ||
56 | }; | ||
57 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
58 | index XXXXXXX..XXXXXXX 100644 | ||
59 | --- a/target/riscv/tcg/tcg-cpu.c | ||
60 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
61 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_update_named_features(RISCVCPU *cpu) | ||
62 | |||
63 | cpu->cfg.ext_sha = riscv_has_ext(&cpu->env, RVH) && | ||
64 | cpu->cfg.ext_ssstateen; | ||
65 | + | ||
66 | + cpu->cfg.ext_ziccrse = cpu->cfg.has_priv_1_11; | ||
67 | } | 22 | } |
68 | 23 | ||
69 | static void riscv_cpu_validate_g(RISCVCPU *cpu) | 24 | -static void set_resetvec(CPURISCVState *env, int resetvec) |
25 | +static void set_resetvec(CPURISCVState *env, target_ulong resetvec) | ||
26 | { | ||
27 | #ifndef CONFIG_USER_ONLY | ||
28 | env->resetvec = resetvec; | ||
70 | -- | 29 | -- |
71 | 2.48.1 | 30 | 2.31.1 |
31 | |||
32 | diff view generated by jsdifflib |
1 | From: Atish Patra <atishp@rivosinc.com> | 1 | From: Bin Meng <bmeng.cn@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | As per the ISA definition, the upper 8 bits in hpmevent are defined | 3 | This was accidentally dropped before. Add it back. |
4 | by Sscofpmf for privilege mode filtering and overflow bits while the | ||
5 | lower 56 bits are desginated for platform specific hpmevent values. | ||
6 | For the reset case, mhpmevent value should have zero in lower 56 bits. | ||
7 | Software may set the OF bit to indicate disable interrupt. | ||
8 | 4 | ||
9 | Ensure that correct value is checked after masking while clearing the | 5 | Fixes: 732612856a8 ("hw/riscv: Drop 'struct MemmapEntry'") |
10 | event encodings. | 6 | Reported-by: Emmanuel Blot <eblot.ml@gmail.com> |
11 | 7 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> | |
12 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
13 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
14 | Signed-off-by: Atish Patra <atishp@rivosinc.com> | 10 | Message-id: 20210331103612.654261-1-bmeng.cn@gmail.com |
15 | Message-ID: <20250206-pmu_minor_fixes-v2-2-1bb0f4aeb8b4@rivosinc.com> | ||
16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
17 | --- | 12 | --- |
18 | target/riscv/pmu.c | 2 +- | 13 | hw/riscv/sifive_e.c | 2 +- |
19 | 1 file changed, 1 insertion(+), 1 deletion(-) | 14 | 1 file changed, 1 insertion(+), 1 deletion(-) |
20 | 15 | ||
21 | diff --git a/target/riscv/pmu.c b/target/riscv/pmu.c | 16 | diff --git a/hw/riscv/sifive_e.c b/hw/riscv/sifive_e.c |
22 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/target/riscv/pmu.c | 18 | --- a/hw/riscv/sifive_e.c |
24 | +++ b/target/riscv/pmu.c | 19 | +++ b/hw/riscv/sifive_e.c |
25 | @@ -XXX,XX +XXX,XX @@ int riscv_pmu_update_event_map(CPURISCVState *env, uint64_t value, | 20 | @@ -XXX,XX +XXX,XX @@ |
26 | * Expected mhpmevent value is zero for reset case. Remove the current | 21 | #include "sysemu/arch_init.h" |
27 | * mapping. | 22 | #include "sysemu/sysemu.h" |
28 | */ | 23 | |
29 | - if (!value) { | 24 | -static MemMapEntry sifive_e_memmap[] = { |
30 | + if (!(value & MHPMEVENT_IDX_MASK)) { | 25 | +static const MemMapEntry sifive_e_memmap[] = { |
31 | g_hash_table_foreach_remove(cpu->pmu_event_ctr_map, | 26 | [SIFIVE_E_DEV_DEBUG] = { 0x0, 0x1000 }, |
32 | pmu_remove_event_map, | 27 | [SIFIVE_E_DEV_MROM] = { 0x1000, 0x2000 }, |
33 | GUINT_TO_POINTER(ctr_idx)); | 28 | [SIFIVE_E_DEV_OTP] = { 0x20000, 0x2000 }, |
34 | -- | 29 | -- |
35 | 2.48.1 | 30 | 2.31.1 |
31 | |||
32 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Vijai Kumar K <vijai@behindbytes.com> |
---|---|---|---|
2 | 2 | ||
3 | Add RVA23S64 as described in [1]. This profile inherits all mandatory | 3 | C-Class is a member of the SHAKTI family of processors from IIT-M. |
4 | extensions of RVA23U64 and RVA22S64, making it a child of both profiles. | ||
5 | 4 | ||
6 | A new "rva23s64" profile CPU is also added. This is the generated | 5 | It is an extremely configurable and commercial-grade 5-stage in-order |
7 | riscv,isa for it (taken via -M dumpdtb): | 6 | core supporting the standard RV64GCSUN ISA extensions. |
8 | 7 | ||
9 | rv64imafdcbvh_zic64b_zicbom_zicbop_zicboz_ziccamoa_ziccif_zicclsm_ | 8 | Signed-off-by: Vijai Kumar K <vijai@behindbytes.com> |
10 | ziccrse_zicond_zicntr_zicsr_zifencei_zihintntl_zihintpause_zihpm_zimop_ | ||
11 | zmmul_za64rs_zaamo_zalrsc_zawrs_zfa_zfhmin_zca_zcb_zcd_zcmop_zba_zbb_zbs_ | ||
12 | zkt_zvbb_zve32f_zve32x_zve64f_zve64d_zve64x_zvfhmin_zvkb_zvkt_shcounterenw_ | ||
13 | sha_shgatpa_shtvala_shvsatpa_shvstvala_shvstvecd_smnpm_smstateen_ssccptr_ | ||
14 | sscofpmf_sscounterenw_ssnpm_ssstateen_sstc_sstvala_sstvecd_ssu64xl_ | ||
15 | supm_svade_svinval_svnapot_svpbmt | ||
16 | |||
17 | [1] https://github.com/riscv/riscv-profiles/blob/main/src/rva23-profile.adoc | ||
18 | |||
19 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
20 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
21 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
22 | Message-ID: <20250115184316.2344583-7-dbarboza@ventanamicro.com> | 10 | Message-id: 20210401181457.73039-2-vijai@behindbytes.com |
23 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
24 | --- | 12 | --- |
25 | target/riscv/cpu-qom.h | 1 + | 13 | target/riscv/cpu.h | 1 + |
26 | target/riscv/cpu.c | 39 +++++++++++++++++++++++++++++++++++++++ | 14 | target/riscv/cpu.c | 1 + |
27 | 2 files changed, 40 insertions(+) | 15 | 2 files changed, 2 insertions(+) |
28 | 16 | ||
29 | diff --git a/target/riscv/cpu-qom.h b/target/riscv/cpu-qom.h | 17 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
30 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
31 | --- a/target/riscv/cpu-qom.h | 19 | --- a/target/riscv/cpu.h |
32 | +++ b/target/riscv/cpu-qom.h | 20 | +++ b/target/riscv/cpu.h |
33 | @@ -XXX,XX +XXX,XX @@ | 21 | @@ -XXX,XX +XXX,XX @@ |
34 | #define TYPE_RISCV_CPU_RVA22U64 RISCV_CPU_TYPE_NAME("rva22u64") | 22 | #define TYPE_RISCV_CPU_BASE32 RISCV_CPU_TYPE_NAME("rv32") |
35 | #define TYPE_RISCV_CPU_RVA22S64 RISCV_CPU_TYPE_NAME("rva22s64") | 23 | #define TYPE_RISCV_CPU_BASE64 RISCV_CPU_TYPE_NAME("rv64") |
36 | #define TYPE_RISCV_CPU_RVA23U64 RISCV_CPU_TYPE_NAME("rva23u64") | ||
37 | +#define TYPE_RISCV_CPU_RVA23S64 RISCV_CPU_TYPE_NAME("rva23s64") | ||
38 | #define TYPE_RISCV_CPU_IBEX RISCV_CPU_TYPE_NAME("lowrisc-ibex") | 24 | #define TYPE_RISCV_CPU_IBEX RISCV_CPU_TYPE_NAME("lowrisc-ibex") |
39 | #define TYPE_RISCV_CPU_SHAKTI_C RISCV_CPU_TYPE_NAME("shakti-c") | 25 | +#define TYPE_RISCV_CPU_SHAKTI_C RISCV_CPU_TYPE_NAME("shakti-c") |
40 | #define TYPE_RISCV_CPU_SIFIVE_E31 RISCV_CPU_TYPE_NAME("sifive-e31") | 26 | #define TYPE_RISCV_CPU_SIFIVE_E31 RISCV_CPU_TYPE_NAME("sifive-e31") |
27 | #define TYPE_RISCV_CPU_SIFIVE_E34 RISCV_CPU_TYPE_NAME("sifive-e34") | ||
28 | #define TYPE_RISCV_CPU_SIFIVE_E51 RISCV_CPU_TYPE_NAME("sifive-e51") | ||
41 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 29 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
42 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
43 | --- a/target/riscv/cpu.c | 31 | --- a/target/riscv/cpu.c |
44 | +++ b/target/riscv/cpu.c | 32 | +++ b/target/riscv/cpu.c |
45 | @@ -XXX,XX +XXX,XX @@ static RISCVCPUProfile RVA23U64 = { | 33 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo riscv_cpu_type_infos[] = { |
46 | } | 34 | DEFINE_CPU(TYPE_RISCV_CPU_BASE64, rv64_base_cpu_init), |
35 | DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E51, rv64_sifive_e_cpu_init), | ||
36 | DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U54, rv64_sifive_u_cpu_init), | ||
37 | + DEFINE_CPU(TYPE_RISCV_CPU_SHAKTI_C, rv64_sifive_u_cpu_init), | ||
38 | #endif | ||
47 | }; | 39 | }; |
48 | 40 | ||
49 | +/* | ||
50 | + * As with RVA23U64, RVA23S64 also defines 'named features'. | ||
51 | + * | ||
52 | + * Cache related features that we consider enabled since we don't | ||
53 | + * implement cache: Ssccptr | ||
54 | + * | ||
55 | + * Other named features that we already implement: Sstvecd, Sstvala, | ||
56 | + * Sscounterenw, Ssu64xl | ||
57 | + * | ||
58 | + * The remaining features/extensions comes from RVA23S64. | ||
59 | + */ | ||
60 | +static RISCVCPUProfile RVA23S64 = { | ||
61 | + .u_parent = &RVA23U64, | ||
62 | + .s_parent = &RVA22S64, | ||
63 | + .name = "rva23s64", | ||
64 | + .misa_ext = RVS, | ||
65 | + .priv_spec = PRIV_VERSION_1_13_0, | ||
66 | + .satp_mode = VM_1_10_SV39, | ||
67 | + .ext_offsets = { | ||
68 | + /* New in RVA23S64 */ | ||
69 | + CPU_CFG_OFFSET(ext_svnapot), CPU_CFG_OFFSET(ext_sstc), | ||
70 | + CPU_CFG_OFFSET(ext_sscofpmf), CPU_CFG_OFFSET(ext_ssnpm), | ||
71 | + | ||
72 | + /* Named features: Sha */ | ||
73 | + CPU_CFG_OFFSET(ext_sha), | ||
74 | + | ||
75 | + RISCV_PROFILE_EXT_LIST_END | ||
76 | + } | ||
77 | +}; | ||
78 | + | ||
79 | RISCVCPUProfile *riscv_profiles[] = { | ||
80 | &RVA22U64, | ||
81 | &RVA22S64, | ||
82 | &RVA23U64, | ||
83 | + &RVA23S64, | ||
84 | NULL, | ||
85 | }; | ||
86 | |||
87 | @@ -XXX,XX +XXX,XX @@ static void rva23u64_profile_cpu_init(Object *obj) | ||
88 | |||
89 | RVA23U64.enabled = true; | ||
90 | } | ||
91 | + | ||
92 | +static void rva23s64_profile_cpu_init(Object *obj) | ||
93 | +{ | ||
94 | + rv64i_bare_cpu_init(obj); | ||
95 | + | ||
96 | + RVA23S64.enabled = true; | ||
97 | +} | ||
98 | #endif | ||
99 | |||
100 | static const gchar *riscv_gdb_arch_name(CPUState *cs) | ||
101 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo riscv_cpu_type_infos[] = { | ||
102 | DEFINE_PROFILE_CPU(TYPE_RISCV_CPU_RVA22U64, MXL_RV64, rva22u64_profile_cpu_init), | ||
103 | DEFINE_PROFILE_CPU(TYPE_RISCV_CPU_RVA22S64, MXL_RV64, rva22s64_profile_cpu_init), | ||
104 | DEFINE_PROFILE_CPU(TYPE_RISCV_CPU_RVA23U64, MXL_RV64, rva23u64_profile_cpu_init), | ||
105 | + DEFINE_PROFILE_CPU(TYPE_RISCV_CPU_RVA23S64, MXL_RV64, rva23s64_profile_cpu_init), | ||
106 | #endif /* TARGET_RISCV64 */ | ||
107 | }; | ||
108 | |||
109 | -- | 41 | -- |
110 | 2.48.1 | 42 | 2.31.1 |
43 | |||
44 | diff view generated by jsdifflib |
1 | From: Tomasz Jeznach <tjeznach@rivosinc.com> | 1 | From: Vijai Kumar K <vijai@behindbytes.com> |
---|---|---|---|
2 | 2 | ||
3 | The HPM (Hardware Performance Monitor) support consists of almost 7 | 3 | Add support for emulating Shakti reference platform based on C-class |
4 | hundred lines that would be put on top of the base riscv-iommu | 4 | running on arty-100T board. |
5 | emulation. | 5 | |
6 | 6 | https://gitlab.com/shaktiproject/cores/shakti-soc/-/blob/master/README.rst | |
7 | To avoid clogging riscv-iommu.c, add a separated riscv-iommu-hpm file | 7 | |
8 | that will contain HPM specific code. | 8 | Signed-off-by: Vijai Kumar K <vijai@behindbytes.com> |
9 | 9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | |
10 | We'll start by adding riscv_iommu_hpmcycle_read(), a helper that will be | 10 | Message-id: 20210401181457.73039-3-vijai@behindbytes.com |
11 | called during the riscv_iommu_mmio_read() callback. | 11 | [Changes by AF: |
12 | 12 | - Check for mstate->firmware before loading it | |
13 | This change will have no effect on the existing emulation since we're | 13 | ] |
14 | not declaring HPM feature support. | ||
15 | |||
16 | Signed-off-by: Tomasz Jeznach <tjeznach@rivosinc.com> | ||
17 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
18 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
19 | Message-ID: <20250224190826.1858473-4-dbarboza@ventanamicro.com> | ||
20 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
21 | --- | 15 | --- |
22 | hw/riscv/riscv-iommu-hpm.h | 27 +++++++++++++++++++ | 16 | default-configs/devices/riscv64-softmmu.mak | 1 + |
23 | hw/riscv/riscv-iommu.h | 4 +++ | 17 | include/hw/riscv/shakti_c.h | 73 +++++++++ |
24 | hw/riscv/riscv-iommu-hpm.c | 54 ++++++++++++++++++++++++++++++++++++++ | 18 | hw/riscv/shakti_c.c | 173 ++++++++++++++++++++ |
25 | hw/riscv/riscv-iommu.c | 24 ++++++++++++++++- | 19 | MAINTAINERS | 7 + |
26 | hw/riscv/meson.build | 3 ++- | 20 | hw/riscv/Kconfig | 10 ++ |
27 | 5 files changed, 110 insertions(+), 2 deletions(-) | 21 | hw/riscv/meson.build | 1 + |
28 | create mode 100644 hw/riscv/riscv-iommu-hpm.h | 22 | 6 files changed, 265 insertions(+) |
29 | create mode 100644 hw/riscv/riscv-iommu-hpm.c | 23 | create mode 100644 include/hw/riscv/shakti_c.h |
30 | 24 | create mode 100644 hw/riscv/shakti_c.c | |
31 | diff --git a/hw/riscv/riscv-iommu-hpm.h b/hw/riscv/riscv-iommu-hpm.h | 25 | |
26 | diff --git a/default-configs/devices/riscv64-softmmu.mak b/default-configs/devices/riscv64-softmmu.mak | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/default-configs/devices/riscv64-softmmu.mak | ||
29 | +++ b/default-configs/devices/riscv64-softmmu.mak | ||
30 | @@ -XXX,XX +XXX,XX @@ CONFIG_SIFIVE_E=y | ||
31 | CONFIG_SIFIVE_U=y | ||
32 | CONFIG_RISCV_VIRT=y | ||
33 | CONFIG_MICROCHIP_PFSOC=y | ||
34 | +CONFIG_SHAKTI_C=y | ||
35 | diff --git a/include/hw/riscv/shakti_c.h b/include/hw/riscv/shakti_c.h | ||
32 | new file mode 100644 | 36 | new file mode 100644 |
33 | index XXXXXXX..XXXXXXX | 37 | index XXXXXXX..XXXXXXX |
34 | --- /dev/null | 38 | --- /dev/null |
35 | +++ b/hw/riscv/riscv-iommu-hpm.h | 39 | +++ b/include/hw/riscv/shakti_c.h |
36 | @@ -XXX,XX +XXX,XX @@ | 40 | @@ -XXX,XX +XXX,XX @@ |
37 | +/* | 41 | +/* |
38 | + * RISC-V IOMMU - Hardware Performance Monitor (HPM) helpers | 42 | + * Shakti C-class SoC emulation |
39 | + * | 43 | + * |
40 | + * Copyright (C) 2022-2023 Rivos Inc. | 44 | + * Copyright (c) 2021 Vijai Kumar K <vijai@behindbytes.com> |
41 | + * | 45 | + * |
42 | + * This program is free software; you can redistribute it and/or modify it | 46 | + * This program is free software; you can redistribute it and/or modify it |
43 | + * under the terms and conditions of the GNU General Public License, | 47 | + * under the terms and conditions of the GNU General Public License, |
44 | + * version 2 or later, as published by the Free Software Foundation. | 48 | + * version 2 or later, as published by the Free Software Foundation. |
45 | + * | 49 | + * |
46 | + * This program is distributed in the hope that it will be useful, | 50 | + * This program is distributed in the hope it will be useful, but WITHOUT |
47 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | 51 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
48 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 52 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
49 | + * GNU General Public License for more details. | 53 | + * more details. |
50 | + * | 54 | + * |
51 | + * You should have received a copy of the GNU General Public License along | 55 | + * You should have received a copy of the GNU General Public License along with |
52 | + * with this program; if not, see <http://www.gnu.org/licenses/>. | 56 | + * this program. If not, see <http://www.gnu.org/licenses/>. |
53 | + */ | 57 | + */ |
54 | + | 58 | + |
55 | +#ifndef HW_RISCV_IOMMU_HPM_H | 59 | +#ifndef HW_SHAKTI_H |
56 | +#define HW_RISCV_IOMMU_HPM_H | 60 | +#define HW_SHAKTI_H |
57 | + | 61 | + |
58 | +#include "qom/object.h" | 62 | +#include "hw/riscv/riscv_hart.h" |
59 | +#include "hw/riscv/riscv-iommu.h" | 63 | +#include "hw/boards.h" |
60 | + | 64 | + |
61 | +uint64_t riscv_iommu_hpmcycle_read(RISCVIOMMUState *s); | 65 | +#define TYPE_RISCV_SHAKTI_SOC "riscv.shakti.cclass.soc" |
66 | +#define RISCV_SHAKTI_SOC(obj) \ | ||
67 | + OBJECT_CHECK(ShaktiCSoCState, (obj), TYPE_RISCV_SHAKTI_SOC) | ||
68 | + | ||
69 | +typedef struct ShaktiCSoCState { | ||
70 | + /*< private >*/ | ||
71 | + DeviceState parent_obj; | ||
72 | + | ||
73 | + /*< public >*/ | ||
74 | + RISCVHartArrayState cpus; | ||
75 | + DeviceState *plic; | ||
76 | + MemoryRegion rom; | ||
77 | + | ||
78 | +} ShaktiCSoCState; | ||
79 | + | ||
80 | +#define TYPE_RISCV_SHAKTI_MACHINE MACHINE_TYPE_NAME("shakti_c") | ||
81 | +#define RISCV_SHAKTI_MACHINE(obj) \ | ||
82 | + OBJECT_CHECK(ShaktiCMachineState, (obj), TYPE_RISCV_SHAKTI_MACHINE) | ||
83 | +typedef struct ShaktiCMachineState { | ||
84 | + /*< private >*/ | ||
85 | + MachineState parent_obj; | ||
86 | + | ||
87 | + /*< public >*/ | ||
88 | + ShaktiCSoCState soc; | ||
89 | +} ShaktiCMachineState; | ||
90 | + | ||
91 | +enum { | ||
92 | + SHAKTI_C_ROM, | ||
93 | + SHAKTI_C_RAM, | ||
94 | + SHAKTI_C_UART, | ||
95 | + SHAKTI_C_GPIO, | ||
96 | + SHAKTI_C_PLIC, | ||
97 | + SHAKTI_C_CLINT, | ||
98 | + SHAKTI_C_I2C, | ||
99 | +}; | ||
100 | + | ||
101 | +#define SHAKTI_C_PLIC_HART_CONFIG "MS" | ||
102 | +/* Including Interrupt ID 0 (no interrupt)*/ | ||
103 | +#define SHAKTI_C_PLIC_NUM_SOURCES 28 | ||
104 | +/* Excluding Priority 0 */ | ||
105 | +#define SHAKTI_C_PLIC_NUM_PRIORITIES 2 | ||
106 | +#define SHAKTI_C_PLIC_PRIORITY_BASE 0x04 | ||
107 | +#define SHAKTI_C_PLIC_PENDING_BASE 0x1000 | ||
108 | +#define SHAKTI_C_PLIC_ENABLE_BASE 0x2000 | ||
109 | +#define SHAKTI_C_PLIC_ENABLE_STRIDE 0x80 | ||
110 | +#define SHAKTI_C_PLIC_CONTEXT_BASE 0x200000 | ||
111 | +#define SHAKTI_C_PLIC_CONTEXT_STRIDE 0x1000 | ||
62 | + | 112 | + |
63 | +#endif | 113 | +#endif |
64 | diff --git a/hw/riscv/riscv-iommu.h b/hw/riscv/riscv-iommu.h | 114 | diff --git a/hw/riscv/shakti_c.c b/hw/riscv/shakti_c.c |
65 | index XXXXXXX..XXXXXXX 100644 | ||
66 | --- a/hw/riscv/riscv-iommu.h | ||
67 | +++ b/hw/riscv/riscv-iommu.h | ||
68 | @@ -XXX,XX +XXX,XX @@ struct RISCVIOMMUState { | ||
69 | |||
70 | QLIST_ENTRY(RISCVIOMMUState) iommus; | ||
71 | QLIST_HEAD(, RISCVIOMMUSpace) spaces; | ||
72 | + | ||
73 | + /* HPM cycle counter */ | ||
74 | + uint64_t hpmcycle_val; /* Current value of cycle register */ | ||
75 | + uint64_t hpmcycle_prev; /* Saved value of QEMU_CLOCK_VIRTUAL clock */ | ||
76 | }; | ||
77 | |||
78 | void riscv_iommu_pci_setup_iommu(RISCVIOMMUState *iommu, PCIBus *bus, | ||
79 | diff --git a/hw/riscv/riscv-iommu-hpm.c b/hw/riscv/riscv-iommu-hpm.c | ||
80 | new file mode 100644 | 115 | new file mode 100644 |
81 | index XXXXXXX..XXXXXXX | 116 | index XXXXXXX..XXXXXXX |
82 | --- /dev/null | 117 | --- /dev/null |
83 | +++ b/hw/riscv/riscv-iommu-hpm.c | 118 | +++ b/hw/riscv/shakti_c.c |
84 | @@ -XXX,XX +XXX,XX @@ | 119 | @@ -XXX,XX +XXX,XX @@ |
85 | +/* | 120 | +/* |
86 | + * RISC-V IOMMU - Hardware Performance Monitor (HPM) helpers | 121 | + * Shakti C-class SoC emulation |
87 | + * | 122 | + * |
88 | + * Copyright (C) 2022-2023 Rivos Inc. | 123 | + * Copyright (c) 2021 Vijai Kumar K <vijai@behindbytes.com> |
89 | + * | 124 | + * |
90 | + * This program is free software; you can redistribute it and/or modify it | 125 | + * This program is free software; you can redistribute it and/or modify it |
91 | + * under the terms and conditions of the GNU General Public License, | 126 | + * under the terms and conditions of the GNU General Public License, |
92 | + * version 2 or later, as published by the Free Software Foundation. | 127 | + * version 2 or later, as published by the Free Software Foundation. |
93 | + * | 128 | + * |
94 | + * This program is distributed in the hope that it will be useful, | 129 | + * This program is distributed in the hope it will be useful, but WITHOUT |
95 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | 130 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
96 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 131 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
97 | + * GNU General Public License for more details. | 132 | + * more details. |
98 | + * | 133 | + * |
99 | + * You should have received a copy of the GNU General Public License along | 134 | + * You should have received a copy of the GNU General Public License along with |
100 | + * with this program; if not, see <http://www.gnu.org/licenses/>. | 135 | + * this program. If not, see <http://www.gnu.org/licenses/>. |
101 | + */ | 136 | + */ |
102 | + | 137 | + |
103 | +#include "qemu/osdep.h" | 138 | +#include "qemu/osdep.h" |
104 | +#include "qemu/timer.h" | 139 | +#include "hw/boards.h" |
105 | +#include "cpu_bits.h" | 140 | +#include "hw/riscv/shakti_c.h" |
106 | +#include "riscv-iommu-hpm.h" | 141 | +#include "qapi/error.h" |
107 | +#include "riscv-iommu.h" | 142 | +#include "hw/intc/sifive_plic.h" |
108 | +#include "riscv-iommu-bits.h" | 143 | +#include "hw/intc/sifive_clint.h" |
109 | +#include "trace.h" | 144 | +#include "sysemu/sysemu.h" |
110 | + | 145 | +#include "hw/qdev-properties.h" |
111 | +/* For now we assume IOMMU HPM frequency to be 1GHz so 1-cycle is of 1-ns. */ | 146 | +#include "exec/address-spaces.h" |
112 | +static inline uint64_t get_cycles(void) | 147 | +#include "hw/riscv/boot.h" |
113 | +{ | 148 | + |
114 | + return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | 149 | + |
115 | +} | 150 | +static const struct MemmapEntry { |
116 | + | 151 | + hwaddr base; |
117 | +uint64_t riscv_iommu_hpmcycle_read(RISCVIOMMUState *s) | 152 | + hwaddr size; |
118 | +{ | 153 | +} shakti_c_memmap[] = { |
119 | + const uint64_t cycle = riscv_iommu_reg_get64( | 154 | + [SHAKTI_C_ROM] = { 0x00001000, 0x2000 }, |
120 | + s, RISCV_IOMMU_REG_IOHPMCYCLES); | 155 | + [SHAKTI_C_RAM] = { 0x80000000, 0x0 }, |
121 | + const uint32_t inhibit = riscv_iommu_reg_get32( | 156 | + [SHAKTI_C_UART] = { 0x00011300, 0x00040 }, |
122 | + s, RISCV_IOMMU_REG_IOCOUNTINH); | 157 | + [SHAKTI_C_GPIO] = { 0x020d0000, 0x00100 }, |
123 | + const uint64_t ctr_prev = s->hpmcycle_prev; | 158 | + [SHAKTI_C_PLIC] = { 0x0c000000, 0x20000 }, |
124 | + const uint64_t ctr_val = s->hpmcycle_val; | 159 | + [SHAKTI_C_CLINT] = { 0x02000000, 0xc0000 }, |
125 | + | 160 | + [SHAKTI_C_I2C] = { 0x20c00000, 0x00100 }, |
126 | + if (get_field(inhibit, RISCV_IOMMU_IOCOUNTINH_CY)) { | 161 | +}; |
127 | + /* | 162 | + |
128 | + * Counter should not increment if inhibit bit is set. We can't really | 163 | +static void shakti_c_machine_state_init(MachineState *mstate) |
129 | + * stop the QEMU_CLOCK_VIRTUAL, so we just return the last updated | 164 | +{ |
130 | + * counter value to indicate that counter was not incremented. | 165 | + ShaktiCMachineState *sms = RISCV_SHAKTI_MACHINE(mstate); |
131 | + */ | 166 | + MemoryRegion *system_memory = get_system_memory(); |
132 | + return (ctr_val & RISCV_IOMMU_IOHPMCYCLES_COUNTER) | | 167 | + MemoryRegion *main_mem = g_new(MemoryRegion, 1); |
133 | + (cycle & RISCV_IOMMU_IOHPMCYCLES_OVF); | 168 | + |
169 | + /* Allow only Shakti C CPU for this platform */ | ||
170 | + if (strcmp(mstate->cpu_type, TYPE_RISCV_CPU_SHAKTI_C) != 0) { | ||
171 | + error_report("This board can only be used with Shakti C CPU"); | ||
172 | + exit(1); | ||
134 | + } | 173 | + } |
135 | + | 174 | + |
136 | + return (ctr_val + get_cycles() - ctr_prev) | | 175 | + /* Initialize SoC */ |
137 | + (cycle & RISCV_IOMMU_IOHPMCYCLES_OVF); | 176 | + object_initialize_child(OBJECT(mstate), "soc", &sms->soc, |
138 | +} | 177 | + TYPE_RISCV_SHAKTI_SOC); |
139 | diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c | 178 | + qdev_realize(DEVICE(&sms->soc), NULL, &error_abort); |
179 | + | ||
180 | + /* register RAM */ | ||
181 | + memory_region_init_ram(main_mem, NULL, "riscv.shakti.c.ram", | ||
182 | + mstate->ram_size, &error_fatal); | ||
183 | + memory_region_add_subregion(system_memory, | ||
184 | + shakti_c_memmap[SHAKTI_C_RAM].base, | ||
185 | + main_mem); | ||
186 | + | ||
187 | + /* ROM reset vector */ | ||
188 | + riscv_setup_rom_reset_vec(mstate, &sms->soc.cpus, | ||
189 | + shakti_c_memmap[SHAKTI_C_RAM].base, | ||
190 | + shakti_c_memmap[SHAKTI_C_ROM].base, | ||
191 | + shakti_c_memmap[SHAKTI_C_ROM].size, 0, 0, | ||
192 | + NULL); | ||
193 | + if (mstate->firmware) { | ||
194 | + riscv_load_firmware(mstate->firmware, | ||
195 | + shakti_c_memmap[SHAKTI_C_RAM].base, | ||
196 | + NULL); | ||
197 | + } | ||
198 | +} | ||
199 | + | ||
200 | +static void shakti_c_machine_instance_init(Object *obj) | ||
201 | +{ | ||
202 | +} | ||
203 | + | ||
204 | +static void shakti_c_machine_class_init(ObjectClass *klass, void *data) | ||
205 | +{ | ||
206 | + MachineClass *mc = MACHINE_CLASS(klass); | ||
207 | + mc->desc = "RISC-V Board compatible with Shakti SDK"; | ||
208 | + mc->init = shakti_c_machine_state_init; | ||
209 | + mc->default_cpu_type = TYPE_RISCV_CPU_SHAKTI_C; | ||
210 | +} | ||
211 | + | ||
212 | +static const TypeInfo shakti_c_machine_type_info = { | ||
213 | + .name = TYPE_RISCV_SHAKTI_MACHINE, | ||
214 | + .parent = TYPE_MACHINE, | ||
215 | + .class_init = shakti_c_machine_class_init, | ||
216 | + .instance_init = shakti_c_machine_instance_init, | ||
217 | + .instance_size = sizeof(ShaktiCMachineState), | ||
218 | +}; | ||
219 | + | ||
220 | +static void shakti_c_machine_type_info_register(void) | ||
221 | +{ | ||
222 | + type_register_static(&shakti_c_machine_type_info); | ||
223 | +} | ||
224 | +type_init(shakti_c_machine_type_info_register) | ||
225 | + | ||
226 | +static void shakti_c_soc_state_realize(DeviceState *dev, Error **errp) | ||
227 | +{ | ||
228 | + ShaktiCSoCState *sss = RISCV_SHAKTI_SOC(dev); | ||
229 | + MemoryRegion *system_memory = get_system_memory(); | ||
230 | + | ||
231 | + sysbus_realize(SYS_BUS_DEVICE(&sss->cpus), &error_abort); | ||
232 | + | ||
233 | + sss->plic = sifive_plic_create(shakti_c_memmap[SHAKTI_C_PLIC].base, | ||
234 | + (char *)SHAKTI_C_PLIC_HART_CONFIG, 0, | ||
235 | + SHAKTI_C_PLIC_NUM_SOURCES, | ||
236 | + SHAKTI_C_PLIC_NUM_PRIORITIES, | ||
237 | + SHAKTI_C_PLIC_PRIORITY_BASE, | ||
238 | + SHAKTI_C_PLIC_PENDING_BASE, | ||
239 | + SHAKTI_C_PLIC_ENABLE_BASE, | ||
240 | + SHAKTI_C_PLIC_ENABLE_STRIDE, | ||
241 | + SHAKTI_C_PLIC_CONTEXT_BASE, | ||
242 | + SHAKTI_C_PLIC_CONTEXT_STRIDE, | ||
243 | + shakti_c_memmap[SHAKTI_C_PLIC].size); | ||
244 | + | ||
245 | + sifive_clint_create(shakti_c_memmap[SHAKTI_C_CLINT].base, | ||
246 | + shakti_c_memmap[SHAKTI_C_CLINT].size, 0, 1, | ||
247 | + SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, | ||
248 | + SIFIVE_CLINT_TIMEBASE_FREQ, false); | ||
249 | + | ||
250 | + /* ROM */ | ||
251 | + memory_region_init_rom(&sss->rom, OBJECT(dev), "riscv.shakti.c.rom", | ||
252 | + shakti_c_memmap[SHAKTI_C_ROM].size, &error_fatal); | ||
253 | + memory_region_add_subregion(system_memory, | ||
254 | + shakti_c_memmap[SHAKTI_C_ROM].base, &sss->rom); | ||
255 | +} | ||
256 | + | ||
257 | +static void shakti_c_soc_class_init(ObjectClass *klass, void *data) | ||
258 | +{ | ||
259 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
260 | + dc->realize = shakti_c_soc_state_realize; | ||
261 | +} | ||
262 | + | ||
263 | +static void shakti_c_soc_instance_init(Object *obj) | ||
264 | +{ | ||
265 | + ShaktiCSoCState *sss = RISCV_SHAKTI_SOC(obj); | ||
266 | + | ||
267 | + object_initialize_child(obj, "cpus", &sss->cpus, TYPE_RISCV_HART_ARRAY); | ||
268 | + | ||
269 | + /* | ||
270 | + * CPU type is fixed and we are not supporting passing from commandline yet. | ||
271 | + * So let it be in instance_init. When supported should use ms->cpu_type | ||
272 | + * instead of TYPE_RISCV_CPU_SHAKTI_C | ||
273 | + */ | ||
274 | + object_property_set_str(OBJECT(&sss->cpus), "cpu-type", | ||
275 | + TYPE_RISCV_CPU_SHAKTI_C, &error_abort); | ||
276 | + object_property_set_int(OBJECT(&sss->cpus), "num-harts", 1, | ||
277 | + &error_abort); | ||
278 | +} | ||
279 | + | ||
280 | +static const TypeInfo shakti_c_type_info = { | ||
281 | + .name = TYPE_RISCV_SHAKTI_SOC, | ||
282 | + .parent = TYPE_DEVICE, | ||
283 | + .class_init = shakti_c_soc_class_init, | ||
284 | + .instance_init = shakti_c_soc_instance_init, | ||
285 | + .instance_size = sizeof(ShaktiCSoCState), | ||
286 | +}; | ||
287 | + | ||
288 | +static void shakti_c_type_info_register(void) | ||
289 | +{ | ||
290 | + type_register_static(&shakti_c_type_info); | ||
291 | +} | ||
292 | +type_init(shakti_c_type_info_register) | ||
293 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
140 | index XXXXXXX..XXXXXXX 100644 | 294 | index XXXXXXX..XXXXXXX 100644 |
141 | --- a/hw/riscv/riscv-iommu.c | 295 | --- a/MAINTAINERS |
142 | +++ b/hw/riscv/riscv-iommu.c | 296 | +++ b/MAINTAINERS |
143 | @@ -XXX,XX +XXX,XX @@ | 297 | @@ -XXX,XX +XXX,XX @@ F: include/hw/misc/mchp_pfsoc_dmc.h |
144 | #include "cpu_bits.h" | 298 | F: include/hw/misc/mchp_pfsoc_ioscb.h |
145 | #include "riscv-iommu.h" | 299 | F: include/hw/misc/mchp_pfsoc_sysreg.h |
146 | #include "riscv-iommu-bits.h" | 300 | |
147 | +#include "riscv-iommu-hpm.h" | 301 | +Shakti C class SoC |
148 | #include "trace.h" | 302 | +M: Vijai Kumar K <vijai@behindbytes.com> |
149 | 303 | +L: qemu-riscv@nongnu.org | |
150 | #define LIMIT_CACHE_CTX (1U << 7) | 304 | +S: Supported |
151 | @@ -XXX,XX +XXX,XX @@ static MemTxResult riscv_iommu_mmio_read(void *opaque, hwaddr addr, | 305 | +F: hw/riscv/shakti_c.c |
152 | return MEMTX_ACCESS_ERROR; | 306 | +F: include/hw/riscv/shakti_c.h |
153 | } | 307 | + |
154 | 308 | SiFive Machines | |
155 | - ptr = &s->regs_rw[addr]; | 309 | M: Alistair Francis <Alistair.Francis@wdc.com> |
156 | + /* Compute cycle register value. */ | 310 | M: Bin Meng <bin.meng@windriver.com> |
157 | + if ((addr & ~7) == RISCV_IOMMU_REG_IOHPMCYCLES) { | 311 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig |
158 | + val = riscv_iommu_hpmcycle_read(s); | 312 | index XXXXXXX..XXXXXXX 100644 |
159 | + ptr = (uint8_t *)&val + (addr & 7); | 313 | --- a/hw/riscv/Kconfig |
160 | + } else if ((addr & ~3) == RISCV_IOMMU_REG_IOCOUNTOVF) { | 314 | +++ b/hw/riscv/Kconfig |
161 | + /* | 315 | @@ -XXX,XX +XXX,XX @@ config OPENTITAN |
162 | + * Software can read RISCV_IOMMU_REG_IOCOUNTOVF before timer | 316 | select IBEX |
163 | + * callback completes. In which case CY_OF bit in | 317 | select UNIMP |
164 | + * RISCV_IOMMU_IOHPMCYCLES_OVF would be 0. Here we take the | 318 | |
165 | + * CY_OF bit state from RISCV_IOMMU_REG_IOHPMCYCLES register as | 319 | +config SHAKTI |
166 | + * it's not dependent over the timer callback and is computed | 320 | + bool |
167 | + * from cycle overflow. | 321 | + |
168 | + */ | 322 | +config SHAKTI_C |
169 | + val = ldq_le_p(&s->regs_rw[addr]); | 323 | + bool |
170 | + val |= (riscv_iommu_hpmcycle_read(s) & RISCV_IOMMU_IOHPMCYCLES_OVF) | 324 | + select UNIMP |
171 | + ? RISCV_IOMMU_IOCOUNTOVF_CY | 325 | + select SHAKTI |
172 | + : 0; | 326 | + select SIFIVE_CLINT |
173 | + ptr = (uint8_t *)&val + (addr & 3); | 327 | + select SIFIVE_PLIC |
174 | + } else { | 328 | + |
175 | + ptr = &s->regs_rw[addr]; | 329 | config RISCV_VIRT |
176 | + } | 330 | bool |
177 | + | 331 | imply PCI_DEVICES |
178 | val = ldn_le_p(ptr, size); | ||
179 | |||
180 | *data = val; | ||
181 | diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build | 332 | diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build |
182 | index XXXXXXX..XXXXXXX 100644 | 333 | index XXXXXXX..XXXXXXX 100644 |
183 | --- a/hw/riscv/meson.build | 334 | --- a/hw/riscv/meson.build |
184 | +++ b/hw/riscv/meson.build | 335 | +++ b/hw/riscv/meson.build |
185 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sifive_u.c')) | 336 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(files('numa.c')) |
337 | riscv_ss.add(files('riscv_hart.c')) | ||
338 | riscv_ss.add(when: 'CONFIG_OPENTITAN', if_true: files('opentitan.c')) | ||
339 | riscv_ss.add(when: 'CONFIG_RISCV_VIRT', if_true: files('virt.c')) | ||
340 | +riscv_ss.add(when: 'CONFIG_SHAKTI_C', if_true: files('shakti_c.c')) | ||
341 | riscv_ss.add(when: 'CONFIG_SIFIVE_E', if_true: files('sifive_e.c')) | ||
342 | riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sifive_u.c')) | ||
186 | riscv_ss.add(when: 'CONFIG_SPIKE', if_true: files('spike.c')) | 343 | riscv_ss.add(when: 'CONFIG_SPIKE', if_true: files('spike.c')) |
187 | riscv_ss.add(when: 'CONFIG_MICROCHIP_PFSOC', if_true: files('microchip_pfsoc.c')) | ||
188 | riscv_ss.add(when: 'CONFIG_ACPI', if_true: files('virt-acpi-build.c')) | ||
189 | -riscv_ss.add(when: 'CONFIG_RISCV_IOMMU', if_true: files('riscv-iommu.c', 'riscv-iommu-pci.c', 'riscv-iommu-sys.c')) | ||
190 | +riscv_ss.add(when: 'CONFIG_RISCV_IOMMU', if_true: files( | ||
191 | + 'riscv-iommu.c', 'riscv-iommu-pci.c', 'riscv-iommu-sys.c', 'riscv-iommu-hpm.c')) | ||
192 | riscv_ss.add(when: 'CONFIG_MICROBLAZE_V', if_true: files('microblaze-v-generic.c')) | ||
193 | |||
194 | hw_arch += {'riscv': riscv_ss} | ||
195 | -- | 344 | -- |
196 | 2.48.1 | 345 | 2.31.1 |
346 | |||
347 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Vijai Kumar K <vijai@behindbytes.com> |
---|---|---|---|
2 | 2 | ||
3 | Remove the !kvm_enabled() check in kvm_riscv_reset_vcpu() since the | 3 | This is the initial implementation of Shakti UART. |
4 | function is already being gated by kvm_enabled() in | 4 | |
5 | riscv_cpu_reset_hold(). | 5 | Signed-off-by: Vijai Kumar K <vijai@behindbytes.com> |
6 | |||
7 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
8 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
10 | Message-ID: <20250224123120.1644186-2-dbarboza@ventanamicro.com> | 7 | Message-id: 20210401181457.73039-4-vijai@behindbytes.com |
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 9 | --- |
13 | target/riscv/kvm/kvm-cpu.c | 3 --- | 10 | include/hw/char/shakti_uart.h | 74 ++++++++++++++ |
14 | 1 file changed, 3 deletions(-) | 11 | hw/char/shakti_uart.c | 185 ++++++++++++++++++++++++++++++++++ |
15 | 12 | MAINTAINERS | 2 + | |
16 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c | 13 | hw/char/meson.build | 1 + |
14 | hw/char/trace-events | 4 + | ||
15 | 5 files changed, 266 insertions(+) | ||
16 | create mode 100644 include/hw/char/shakti_uart.h | ||
17 | create mode 100644 hw/char/shakti_uart.c | ||
18 | |||
19 | diff --git a/include/hw/char/shakti_uart.h b/include/hw/char/shakti_uart.h | ||
20 | new file mode 100644 | ||
21 | index XXXXXXX..XXXXXXX | ||
22 | --- /dev/null | ||
23 | +++ b/include/hw/char/shakti_uart.h | ||
24 | @@ -XXX,XX +XXX,XX @@ | ||
25 | +/* | ||
26 | + * SHAKTI UART | ||
27 | + * | ||
28 | + * Copyright (c) 2021 Vijai Kumar K <vijai@behindbytes.com> | ||
29 | + * | ||
30 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
31 | + * of this software and associated documentation files (the "Software"), to deal | ||
32 | + * in the Software without restriction, including without limitation the rights | ||
33 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
34 | + * copies of the Software, and to permit persons to whom the Software is | ||
35 | + * furnished to do so, subject to the following conditions: | ||
36 | + * | ||
37 | + * The above copyright notice and this permission notice shall be included in | ||
38 | + * all copies or substantial portions of the Software. | ||
39 | + * | ||
40 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
41 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
42 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
43 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
44 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
45 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
46 | + * THE SOFTWARE. | ||
47 | + */ | ||
48 | + | ||
49 | +#ifndef HW_SHAKTI_UART_H | ||
50 | +#define HW_SHAKTI_UART_H | ||
51 | + | ||
52 | +#include "hw/sysbus.h" | ||
53 | +#include "chardev/char-fe.h" | ||
54 | + | ||
55 | +#define SHAKTI_UART_BAUD 0x00 | ||
56 | +#define SHAKTI_UART_TX 0x04 | ||
57 | +#define SHAKTI_UART_RX 0x08 | ||
58 | +#define SHAKTI_UART_STATUS 0x0C | ||
59 | +#define SHAKTI_UART_DELAY 0x10 | ||
60 | +#define SHAKTI_UART_CONTROL 0x14 | ||
61 | +#define SHAKTI_UART_INT_EN 0x18 | ||
62 | +#define SHAKTI_UART_IQ_CYCLES 0x1C | ||
63 | +#define SHAKTI_UART_RX_THRES 0x20 | ||
64 | + | ||
65 | +#define SHAKTI_UART_STATUS_TX_EMPTY (1 << 0) | ||
66 | +#define SHAKTI_UART_STATUS_TX_FULL (1 << 1) | ||
67 | +#define SHAKTI_UART_STATUS_RX_NOT_EMPTY (1 << 2) | ||
68 | +#define SHAKTI_UART_STATUS_RX_FULL (1 << 3) | ||
69 | +/* 9600 8N1 is the default setting */ | ||
70 | +/* Reg value = (50000000 Hz)/(16 * 9600)*/ | ||
71 | +#define SHAKTI_UART_BAUD_DEFAULT 0x0145 | ||
72 | +#define SHAKTI_UART_CONTROL_DEFAULT 0x0100 | ||
73 | + | ||
74 | +#define TYPE_SHAKTI_UART "shakti-uart" | ||
75 | +#define SHAKTI_UART(obj) \ | ||
76 | + OBJECT_CHECK(ShaktiUartState, (obj), TYPE_SHAKTI_UART) | ||
77 | + | ||
78 | +typedef struct { | ||
79 | + /* <private> */ | ||
80 | + SysBusDevice parent_obj; | ||
81 | + | ||
82 | + /* <public> */ | ||
83 | + MemoryRegion mmio; | ||
84 | + | ||
85 | + uint32_t uart_baud; | ||
86 | + uint32_t uart_tx; | ||
87 | + uint32_t uart_rx; | ||
88 | + uint32_t uart_status; | ||
89 | + uint32_t uart_delay; | ||
90 | + uint32_t uart_control; | ||
91 | + uint32_t uart_interrupt; | ||
92 | + uint32_t uart_iq_cycles; | ||
93 | + uint32_t uart_rx_threshold; | ||
94 | + | ||
95 | + CharBackend chr; | ||
96 | +} ShaktiUartState; | ||
97 | + | ||
98 | +#endif /* HW_SHAKTI_UART_H */ | ||
99 | diff --git a/hw/char/shakti_uart.c b/hw/char/shakti_uart.c | ||
100 | new file mode 100644 | ||
101 | index XXXXXXX..XXXXXXX | ||
102 | --- /dev/null | ||
103 | +++ b/hw/char/shakti_uart.c | ||
104 | @@ -XXX,XX +XXX,XX @@ | ||
105 | +/* | ||
106 | + * SHAKTI UART | ||
107 | + * | ||
108 | + * Copyright (c) 2021 Vijai Kumar K <vijai@behindbytes.com> | ||
109 | + * | ||
110 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
111 | + * of this software and associated documentation files (the "Software"), to deal | ||
112 | + * in the Software without restriction, including without limitation the rights | ||
113 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
114 | + * copies of the Software, and to permit persons to whom the Software is | ||
115 | + * furnished to do so, subject to the following conditions: | ||
116 | + * | ||
117 | + * The above copyright notice and this permission notice shall be included in | ||
118 | + * all copies or substantial portions of the Software. | ||
119 | + * | ||
120 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
121 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
122 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
123 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
124 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
125 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
126 | + * THE SOFTWARE. | ||
127 | + */ | ||
128 | + | ||
129 | +#include "qemu/osdep.h" | ||
130 | +#include "hw/char/shakti_uart.h" | ||
131 | +#include "hw/qdev-properties.h" | ||
132 | +#include "hw/qdev-properties-system.h" | ||
133 | +#include "qemu/log.h" | ||
134 | + | ||
135 | +static uint64_t shakti_uart_read(void *opaque, hwaddr addr, unsigned size) | ||
136 | +{ | ||
137 | + ShaktiUartState *s = opaque; | ||
138 | + | ||
139 | + switch (addr) { | ||
140 | + case SHAKTI_UART_BAUD: | ||
141 | + return s->uart_baud; | ||
142 | + case SHAKTI_UART_RX: | ||
143 | + qemu_chr_fe_accept_input(&s->chr); | ||
144 | + s->uart_status &= ~SHAKTI_UART_STATUS_RX_NOT_EMPTY; | ||
145 | + return s->uart_rx; | ||
146 | + case SHAKTI_UART_STATUS: | ||
147 | + return s->uart_status; | ||
148 | + case SHAKTI_UART_DELAY: | ||
149 | + return s->uart_delay; | ||
150 | + case SHAKTI_UART_CONTROL: | ||
151 | + return s->uart_control; | ||
152 | + case SHAKTI_UART_INT_EN: | ||
153 | + return s->uart_interrupt; | ||
154 | + case SHAKTI_UART_IQ_CYCLES: | ||
155 | + return s->uart_iq_cycles; | ||
156 | + case SHAKTI_UART_RX_THRES: | ||
157 | + return s->uart_rx_threshold; | ||
158 | + default: | ||
159 | + /* Also handles TX REG which is write only */ | ||
160 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
161 | + "%s: Bad offset 0x%"HWADDR_PRIx"\n", __func__, addr); | ||
162 | + } | ||
163 | + | ||
164 | + return 0; | ||
165 | +} | ||
166 | + | ||
167 | +static void shakti_uart_write(void *opaque, hwaddr addr, | ||
168 | + uint64_t data, unsigned size) | ||
169 | +{ | ||
170 | + ShaktiUartState *s = opaque; | ||
171 | + uint32_t value = data; | ||
172 | + uint8_t ch; | ||
173 | + | ||
174 | + switch (addr) { | ||
175 | + case SHAKTI_UART_BAUD: | ||
176 | + s->uart_baud = value; | ||
177 | + break; | ||
178 | + case SHAKTI_UART_TX: | ||
179 | + ch = value; | ||
180 | + qemu_chr_fe_write_all(&s->chr, &ch, 1); | ||
181 | + s->uart_status &= ~SHAKTI_UART_STATUS_TX_FULL; | ||
182 | + break; | ||
183 | + case SHAKTI_UART_STATUS: | ||
184 | + s->uart_status = value; | ||
185 | + break; | ||
186 | + case SHAKTI_UART_DELAY: | ||
187 | + s->uart_delay = value; | ||
188 | + break; | ||
189 | + case SHAKTI_UART_CONTROL: | ||
190 | + s->uart_control = value; | ||
191 | + break; | ||
192 | + case SHAKTI_UART_INT_EN: | ||
193 | + s->uart_interrupt = value; | ||
194 | + break; | ||
195 | + case SHAKTI_UART_IQ_CYCLES: | ||
196 | + s->uart_iq_cycles = value; | ||
197 | + break; | ||
198 | + case SHAKTI_UART_RX_THRES: | ||
199 | + s->uart_rx_threshold = value; | ||
200 | + break; | ||
201 | + default: | ||
202 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
203 | + "%s: Bad offset 0x%"HWADDR_PRIx"\n", __func__, addr); | ||
204 | + } | ||
205 | +} | ||
206 | + | ||
207 | +static const MemoryRegionOps shakti_uart_ops = { | ||
208 | + .read = shakti_uart_read, | ||
209 | + .write = shakti_uart_write, | ||
210 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
211 | + .impl = {.min_access_size = 1, .max_access_size = 4}, | ||
212 | + .valid = {.min_access_size = 1, .max_access_size = 4}, | ||
213 | +}; | ||
214 | + | ||
215 | +static void shakti_uart_reset(DeviceState *dev) | ||
216 | +{ | ||
217 | + ShaktiUartState *s = SHAKTI_UART(dev); | ||
218 | + | ||
219 | + s->uart_baud = SHAKTI_UART_BAUD_DEFAULT; | ||
220 | + s->uart_tx = 0x0; | ||
221 | + s->uart_rx = 0x0; | ||
222 | + s->uart_status = 0x0000; | ||
223 | + s->uart_delay = 0x0000; | ||
224 | + s->uart_control = SHAKTI_UART_CONTROL_DEFAULT; | ||
225 | + s->uart_interrupt = 0x0000; | ||
226 | + s->uart_iq_cycles = 0x00; | ||
227 | + s->uart_rx_threshold = 0x00; | ||
228 | +} | ||
229 | + | ||
230 | +static int shakti_uart_can_receive(void *opaque) | ||
231 | +{ | ||
232 | + ShaktiUartState *s = opaque; | ||
233 | + | ||
234 | + return !(s->uart_status & SHAKTI_UART_STATUS_RX_NOT_EMPTY); | ||
235 | +} | ||
236 | + | ||
237 | +static void shakti_uart_receive(void *opaque, const uint8_t *buf, int size) | ||
238 | +{ | ||
239 | + ShaktiUartState *s = opaque; | ||
240 | + | ||
241 | + s->uart_rx = *buf; | ||
242 | + s->uart_status |= SHAKTI_UART_STATUS_RX_NOT_EMPTY; | ||
243 | +} | ||
244 | + | ||
245 | +static void shakti_uart_realize(DeviceState *dev, Error **errp) | ||
246 | +{ | ||
247 | + ShaktiUartState *sus = SHAKTI_UART(dev); | ||
248 | + qemu_chr_fe_set_handlers(&sus->chr, shakti_uart_can_receive, | ||
249 | + shakti_uart_receive, NULL, NULL, sus, NULL, true); | ||
250 | +} | ||
251 | + | ||
252 | +static void shakti_uart_instance_init(Object *obj) | ||
253 | +{ | ||
254 | + ShaktiUartState *sus = SHAKTI_UART(obj); | ||
255 | + memory_region_init_io(&sus->mmio, | ||
256 | + obj, | ||
257 | + &shakti_uart_ops, | ||
258 | + sus, | ||
259 | + TYPE_SHAKTI_UART, | ||
260 | + 0x1000); | ||
261 | + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &sus->mmio); | ||
262 | +} | ||
263 | + | ||
264 | +static Property shakti_uart_properties[] = { | ||
265 | + DEFINE_PROP_CHR("chardev", ShaktiUartState, chr), | ||
266 | + DEFINE_PROP_END_OF_LIST(), | ||
267 | +}; | ||
268 | + | ||
269 | +static void shakti_uart_class_init(ObjectClass *klass, void *data) | ||
270 | +{ | ||
271 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
272 | + dc->reset = shakti_uart_reset; | ||
273 | + dc->realize = shakti_uart_realize; | ||
274 | + device_class_set_props(dc, shakti_uart_properties); | ||
275 | +} | ||
276 | + | ||
277 | +static const TypeInfo shakti_uart_info = { | ||
278 | + .name = TYPE_SHAKTI_UART, | ||
279 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
280 | + .instance_size = sizeof(ShaktiUartState), | ||
281 | + .class_init = shakti_uart_class_init, | ||
282 | + .instance_init = shakti_uart_instance_init, | ||
283 | +}; | ||
284 | + | ||
285 | +static void shakti_uart_register_types(void) | ||
286 | +{ | ||
287 | + type_register_static(&shakti_uart_info); | ||
288 | +} | ||
289 | +type_init(shakti_uart_register_types) | ||
290 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
17 | index XXXXXXX..XXXXXXX 100644 | 291 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/riscv/kvm/kvm-cpu.c | 292 | --- a/MAINTAINERS |
19 | +++ b/target/riscv/kvm/kvm-cpu.c | 293 | +++ b/MAINTAINERS |
20 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_reset_vcpu(RISCVCPU *cpu) | 294 | @@ -XXX,XX +XXX,XX @@ M: Vijai Kumar K <vijai@behindbytes.com> |
21 | CPURISCVState *env = &cpu->env; | 295 | L: qemu-riscv@nongnu.org |
22 | int i; | 296 | S: Supported |
23 | 297 | F: hw/riscv/shakti_c.c | |
24 | - if (!kvm_enabled()) { | 298 | +F: hw/char/shakti_uart.c |
25 | - return; | 299 | F: include/hw/riscv/shakti_c.h |
26 | - } | 300 | +F: include/hw/char/shakti_uart.h |
27 | for (i = 0; i < 32; i++) { | 301 | |
28 | env->gpr[i] = 0; | 302 | SiFive Machines |
29 | } | 303 | M: Alistair Francis <Alistair.Francis@wdc.com> |
304 | diff --git a/hw/char/meson.build b/hw/char/meson.build | ||
305 | index XXXXXXX..XXXXXXX 100644 | ||
306 | --- a/hw/char/meson.build | ||
307 | +++ b/hw/char/meson.build | ||
308 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_SERIAL', if_true: files('serial.c')) | ||
309 | softmmu_ss.add(when: 'CONFIG_SERIAL_ISA', if_true: files('serial-isa.c')) | ||
310 | softmmu_ss.add(when: 'CONFIG_SERIAL_PCI', if_true: files('serial-pci.c')) | ||
311 | softmmu_ss.add(when: 'CONFIG_SERIAL_PCI_MULTI', if_true: files('serial-pci-multi.c')) | ||
312 | +softmmu_ss.add(when: 'CONFIG_SHAKTI', if_true: files('shakti_uart.c')) | ||
313 | softmmu_ss.add(when: 'CONFIG_VIRTIO_SERIAL', if_true: files('virtio-console.c')) | ||
314 | softmmu_ss.add(when: 'CONFIG_XEN', if_true: files('xen_console.c')) | ||
315 | softmmu_ss.add(when: 'CONFIG_XILINX', if_true: files('xilinx_uartlite.c')) | ||
316 | diff --git a/hw/char/trace-events b/hw/char/trace-events | ||
317 | index XXXXXXX..XXXXXXX 100644 | ||
318 | --- a/hw/char/trace-events | ||
319 | +++ b/hw/char/trace-events | ||
320 | @@ -XXX,XX +XXX,XX @@ cmsdk_apb_uart_set_params(int speed) "CMSDK APB UART: params set to %d 8N1" | ||
321 | nrf51_uart_read(uint64_t addr, uint64_t r, unsigned int size) "addr 0x%" PRIx64 " value 0x%" PRIx64 " size %u" | ||
322 | nrf51_uart_write(uint64_t addr, uint64_t value, unsigned int size) "addr 0x%" PRIx64 " value 0x%" PRIx64 " size %u" | ||
323 | |||
324 | +# shakti_uart.c | ||
325 | +shakti_uart_read(uint64_t addr, uint16_t r, unsigned int size) "addr 0x%" PRIx64 " value 0x%" PRIx16 " size %u" | ||
326 | +shakti_uart_write(uint64_t addr, uint64_t value, unsigned int size) "addr 0x%" PRIx64 " value 0x%" PRIx64 " size %u" | ||
327 | + | ||
328 | # exynos4210_uart.c | ||
329 | exynos_uart_dmabusy(uint32_t channel) "UART%d: DMA busy (Rx buffer empty)" | ||
330 | exynos_uart_dmaready(uint32_t channel) "UART%d: DMA ready" | ||
30 | -- | 331 | -- |
31 | 2.48.1 | 332 | 2.31.1 |
333 | |||
334 | diff view generated by jsdifflib |
1 | From: Yong-Xuan Wang <yongxuan.wang@sifive.com> | 1 | From: Vijai Kumar K <vijai@behindbytes.com> |
---|---|---|---|
2 | 2 | ||
3 | When the IMSIC is emulated in the kernel, the GPIO output lines to CPUs | 3 | Connect one shakti uart to the shakti_c machine. |
4 | and aia_ireg_rmw_fn setting can be remove. In this case the IMSIC | ||
5 | trigger CPU interrupts by KVM APIs, and the RMW of IREG is handled in | ||
6 | kernel. | ||
7 | 4 | ||
8 | This patch also move the code that claim the CPU interrupts to the | 5 | Signed-off-by: Vijai Kumar K <vijai@behindbytes.com> |
9 | beginning of IMSIC realization. This can avoid the unnecessary resource | 6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
10 | allocation before checking failed. | 7 | Message-id: 20210401181457.73039-5-vijai@behindbytes.com |
11 | |||
12 | Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com> | ||
13 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
14 | Message-ID: <20250224025722.3999-2-yongxuan.wang@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 | hw/intc/riscv_imsic.c | 47 ++++++++++++++++++++++++------------------- | 10 | include/hw/riscv/shakti_c.h | 2 ++ |
18 | 1 file changed, 26 insertions(+), 21 deletions(-) | 11 | hw/riscv/shakti_c.c | 8 ++++++++ |
12 | 2 files changed, 10 insertions(+) | ||
19 | 13 | ||
20 | diff --git a/hw/intc/riscv_imsic.c b/hw/intc/riscv_imsic.c | 14 | diff --git a/include/hw/riscv/shakti_c.h b/include/hw/riscv/shakti_c.h |
21 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/hw/intc/riscv_imsic.c | 16 | --- a/include/hw/riscv/shakti_c.h |
23 | +++ b/hw/intc/riscv_imsic.c | 17 | +++ b/include/hw/riscv/shakti_c.h |
24 | @@ -XXX,XX +XXX,XX @@ static void riscv_imsic_realize(DeviceState *dev, Error **errp) | 18 | @@ -XXX,XX +XXX,XX @@ |
25 | CPUState *cpu = cpu_by_arch_id(imsic->hartid); | 19 | |
26 | CPURISCVState *env = cpu ? cpu_env(cpu) : NULL; | 20 | #include "hw/riscv/riscv_hart.h" |
27 | 21 | #include "hw/boards.h" | |
28 | + /* Claim the CPU interrupt to be triggered by this IMSIC */ | 22 | +#include "hw/char/shakti_uart.h" |
29 | + if (riscv_cpu_claim_interrupts(rcpu, | 23 | |
30 | + (imsic->mmode) ? MIP_MEIP : MIP_SEIP) < 0) { | 24 | #define TYPE_RISCV_SHAKTI_SOC "riscv.shakti.cclass.soc" |
31 | + error_setg(errp, "%s already claimed", | 25 | #define RISCV_SHAKTI_SOC(obj) \ |
32 | + (imsic->mmode) ? "MEIP" : "SEIP"); | 26 | @@ -XXX,XX +XXX,XX @@ typedef struct ShaktiCSoCState { |
27 | /*< public >*/ | ||
28 | RISCVHartArrayState cpus; | ||
29 | DeviceState *plic; | ||
30 | + ShaktiUartState uart; | ||
31 | MemoryRegion rom; | ||
32 | |||
33 | } ShaktiCSoCState; | ||
34 | diff --git a/hw/riscv/shakti_c.c b/hw/riscv/shakti_c.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/hw/riscv/shakti_c.c | ||
37 | +++ b/hw/riscv/shakti_c.c | ||
38 | @@ -XXX,XX +XXX,XX @@ static void shakti_c_soc_state_realize(DeviceState *dev, Error **errp) | ||
39 | SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, | ||
40 | SIFIVE_CLINT_TIMEBASE_FREQ, false); | ||
41 | |||
42 | + qdev_prop_set_chr(DEVICE(&(sss->uart)), "chardev", serial_hd(0)); | ||
43 | + if (!sysbus_realize(SYS_BUS_DEVICE(&sss->uart), errp)) { | ||
33 | + return; | 44 | + return; |
34 | + } | 45 | + } |
46 | + sysbus_mmio_map(SYS_BUS_DEVICE(&sss->uart), 0, | ||
47 | + shakti_c_memmap[SHAKTI_C_UART].base); | ||
35 | + | 48 | + |
36 | if (!kvm_irqchip_in_kernel()) { | 49 | /* ROM */ |
37 | + /* Create output IRQ lines */ | 50 | memory_region_init_rom(&sss->rom, OBJECT(dev), "riscv.shakti.c.rom", |
38 | + imsic->external_irqs = g_malloc(sizeof(qemu_irq) * imsic->num_pages); | 51 | shakti_c_memmap[SHAKTI_C_ROM].size, &error_fatal); |
39 | + qdev_init_gpio_out(dev, imsic->external_irqs, imsic->num_pages); | 52 | @@ -XXX,XX +XXX,XX @@ static void shakti_c_soc_instance_init(Object *obj) |
40 | + | 53 | ShaktiCSoCState *sss = RISCV_SHAKTI_SOC(obj); |
41 | imsic->num_eistate = imsic->num_pages * imsic->num_irqs; | 54 | |
42 | imsic->eidelivery = g_new0(uint32_t, imsic->num_pages); | 55 | object_initialize_child(obj, "cpus", &sss->cpus, TYPE_RISCV_HART_ARRAY); |
43 | imsic->eithreshold = g_new0(uint32_t, imsic->num_pages); | 56 | + object_initialize_child(obj, "uart", &sss->uart, TYPE_SHAKTI_UART); |
44 | @@ -XXX,XX +XXX,XX @@ static void riscv_imsic_realize(DeviceState *dev, Error **errp) | 57 | |
45 | IMSIC_MMIO_SIZE(imsic->num_pages)); | 58 | /* |
46 | sysbus_init_mmio(SYS_BUS_DEVICE(dev), &imsic->mmio); | 59 | * CPU type is fixed and we are not supporting passing from commandline yet. |
47 | |||
48 | - /* Claim the CPU interrupt to be triggered by this IMSIC */ | ||
49 | - if (riscv_cpu_claim_interrupts(rcpu, | ||
50 | - (imsic->mmode) ? MIP_MEIP : MIP_SEIP) < 0) { | ||
51 | - error_setg(errp, "%s already claimed", | ||
52 | - (imsic->mmode) ? "MEIP" : "SEIP"); | ||
53 | - return; | ||
54 | - } | ||
55 | - | ||
56 | - /* Create output IRQ lines */ | ||
57 | - imsic->external_irqs = g_malloc(sizeof(qemu_irq) * imsic->num_pages); | ||
58 | - qdev_init_gpio_out(dev, imsic->external_irqs, imsic->num_pages); | ||
59 | - | ||
60 | /* Force select AIA feature and setup CSR read-modify-write callback */ | ||
61 | if (env) { | ||
62 | if (!imsic->mmode) { | ||
63 | @@ -XXX,XX +XXX,XX @@ static void riscv_imsic_realize(DeviceState *dev, Error **errp) | ||
64 | } else { | ||
65 | rcpu->cfg.ext_smaia = true; | ||
66 | } | ||
67 | - riscv_cpu_set_aia_ireg_rmw_fn(env, (imsic->mmode) ? PRV_M : PRV_S, | ||
68 | - riscv_imsic_rmw, imsic); | ||
69 | + | ||
70 | + if (!kvm_irqchip_in_kernel()) { | ||
71 | + riscv_cpu_set_aia_ireg_rmw_fn(env, (imsic->mmode) ? PRV_M : PRV_S, | ||
72 | + riscv_imsic_rmw, imsic); | ||
73 | + } | ||
74 | } | ||
75 | |||
76 | msi_nonbroken = true; | ||
77 | @@ -XXX,XX +XXX,XX @@ DeviceState *riscv_imsic_create(hwaddr addr, uint32_t hartid, bool mmode, | ||
78 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); | ||
79 | sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); | ||
80 | |||
81 | - for (i = 0; i < num_pages; i++) { | ||
82 | - if (!i) { | ||
83 | - qdev_connect_gpio_out_named(dev, NULL, i, | ||
84 | - qdev_get_gpio_in(DEVICE(cpu), | ||
85 | + if (!kvm_irqchip_in_kernel()) { | ||
86 | + for (i = 0; i < num_pages; i++) { | ||
87 | + if (!i) { | ||
88 | + qdev_connect_gpio_out_named(dev, NULL, i, | ||
89 | + qdev_get_gpio_in(DEVICE(cpu), | ||
90 | (mmode) ? IRQ_M_EXT : IRQ_S_EXT)); | ||
91 | - } else { | ||
92 | - qdev_connect_gpio_out_named(dev, NULL, i, | ||
93 | - qdev_get_gpio_in(DEVICE(cpu), | ||
94 | + } else { | ||
95 | + qdev_connect_gpio_out_named(dev, NULL, i, | ||
96 | + qdev_get_gpio_in(DEVICE(cpu), | ||
97 | IRQ_LOCAL_MAX + i - 1)); | ||
98 | + } | ||
99 | } | ||
100 | } | ||
101 | |||
102 | -- | 60 | -- |
103 | 2.48.1 | 61 | 2.31.1 |
62 | |||
63 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
---|---|---|---|
2 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
3 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
4 | Message-id: f191dcf08bf413a822e743a7c7f824d68879a527.1617290165.git.alistair.francis@wdc.com | ||
5 | --- | ||
6 | target/riscv/cpu_bits.h | 44 ++++++++++++++++++++------------------- | ||
7 | target/riscv/cpu.c | 2 +- | ||
8 | target/riscv/cpu_helper.c | 4 ++-- | ||
9 | 3 files changed, 26 insertions(+), 24 deletions(-) | ||
2 | 10 | ||
3 | Add RVA23U64 as described in [1]. Add it as a child of RVA22U64 since | 11 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h |
4 | all RVA22U64 mandatory extensions are also present in RVA23U64. What's | ||
5 | left then is to list the mandatory extensions that are RVA23 only. | ||
6 | |||
7 | A new "rva23u64" CPU is also added. | ||
8 | |||
9 | [1] https://github.com/riscv/riscv-profiles/blob/main/src/rva23-profile.adoc | ||
10 | |||
11 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
12 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
14 | Message-ID: <20250115184316.2344583-6-dbarboza@ventanamicro.com> | ||
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
16 | --- | ||
17 | target/riscv/cpu-qom.h | 1 + | ||
18 | target/riscv/cpu.c | 33 +++++++++++++++++++++++++++++++++ | ||
19 | 2 files changed, 34 insertions(+) | ||
20 | |||
21 | diff --git a/target/riscv/cpu-qom.h b/target/riscv/cpu-qom.h | ||
22 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/target/riscv/cpu-qom.h | 13 | --- a/target/riscv/cpu_bits.h |
24 | +++ b/target/riscv/cpu-qom.h | 14 | +++ b/target/riscv/cpu_bits.h |
25 | @@ -XXX,XX +XXX,XX @@ | 15 | @@ -XXX,XX +XXX,XX @@ |
26 | #define TYPE_RISCV_CPU_RV64E RISCV_CPU_TYPE_NAME("rv64e") | 16 | #define DEFAULT_RSTVEC 0x1000 |
27 | #define TYPE_RISCV_CPU_RVA22U64 RISCV_CPU_TYPE_NAME("rva22u64") | 17 | |
28 | #define TYPE_RISCV_CPU_RVA22S64 RISCV_CPU_TYPE_NAME("rva22s64") | 18 | /* Exception causes */ |
29 | +#define TYPE_RISCV_CPU_RVA23U64 RISCV_CPU_TYPE_NAME("rva23u64") | 19 | -#define EXCP_NONE -1 /* sentinel value */ |
30 | #define TYPE_RISCV_CPU_IBEX RISCV_CPU_TYPE_NAME("lowrisc-ibex") | 20 | -#define RISCV_EXCP_INST_ADDR_MIS 0x0 |
31 | #define TYPE_RISCV_CPU_SHAKTI_C RISCV_CPU_TYPE_NAME("shakti-c") | 21 | -#define RISCV_EXCP_INST_ACCESS_FAULT 0x1 |
32 | #define TYPE_RISCV_CPU_SIFIVE_E31 RISCV_CPU_TYPE_NAME("sifive-e31") | 22 | -#define RISCV_EXCP_ILLEGAL_INST 0x2 |
23 | -#define RISCV_EXCP_BREAKPOINT 0x3 | ||
24 | -#define RISCV_EXCP_LOAD_ADDR_MIS 0x4 | ||
25 | -#define RISCV_EXCP_LOAD_ACCESS_FAULT 0x5 | ||
26 | -#define RISCV_EXCP_STORE_AMO_ADDR_MIS 0x6 | ||
27 | -#define RISCV_EXCP_STORE_AMO_ACCESS_FAULT 0x7 | ||
28 | -#define RISCV_EXCP_U_ECALL 0x8 | ||
29 | -#define RISCV_EXCP_S_ECALL 0x9 | ||
30 | -#define RISCV_EXCP_VS_ECALL 0xa | ||
31 | -#define RISCV_EXCP_M_ECALL 0xb | ||
32 | -#define RISCV_EXCP_INST_PAGE_FAULT 0xc /* since: priv-1.10.0 */ | ||
33 | -#define RISCV_EXCP_LOAD_PAGE_FAULT 0xd /* since: priv-1.10.0 */ | ||
34 | -#define RISCV_EXCP_STORE_PAGE_FAULT 0xf /* since: priv-1.10.0 */ | ||
35 | -#define RISCV_EXCP_SEMIHOST 0x10 | ||
36 | -#define RISCV_EXCP_INST_GUEST_PAGE_FAULT 0x14 | ||
37 | -#define RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT 0x15 | ||
38 | -#define RISCV_EXCP_VIRT_INSTRUCTION_FAULT 0x16 | ||
39 | -#define RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT 0x17 | ||
40 | +typedef enum RISCVException { | ||
41 | + RISCV_EXCP_NONE = -1, /* sentinel value */ | ||
42 | + RISCV_EXCP_INST_ADDR_MIS = 0x0, | ||
43 | + RISCV_EXCP_INST_ACCESS_FAULT = 0x1, | ||
44 | + RISCV_EXCP_ILLEGAL_INST = 0x2, | ||
45 | + RISCV_EXCP_BREAKPOINT = 0x3, | ||
46 | + RISCV_EXCP_LOAD_ADDR_MIS = 0x4, | ||
47 | + RISCV_EXCP_LOAD_ACCESS_FAULT = 0x5, | ||
48 | + RISCV_EXCP_STORE_AMO_ADDR_MIS = 0x6, | ||
49 | + RISCV_EXCP_STORE_AMO_ACCESS_FAULT = 0x7, | ||
50 | + RISCV_EXCP_U_ECALL = 0x8, | ||
51 | + RISCV_EXCP_S_ECALL = 0x9, | ||
52 | + RISCV_EXCP_VS_ECALL = 0xa, | ||
53 | + RISCV_EXCP_M_ECALL = 0xb, | ||
54 | + RISCV_EXCP_INST_PAGE_FAULT = 0xc, /* since: priv-1.10.0 */ | ||
55 | + RISCV_EXCP_LOAD_PAGE_FAULT = 0xd, /* since: priv-1.10.0 */ | ||
56 | + RISCV_EXCP_STORE_PAGE_FAULT = 0xf, /* since: priv-1.10.0 */ | ||
57 | + RISCV_EXCP_SEMIHOST = 0x10, | ||
58 | + RISCV_EXCP_INST_GUEST_PAGE_FAULT = 0x14, | ||
59 | + RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT = 0x15, | ||
60 | + RISCV_EXCP_VIRT_INSTRUCTION_FAULT = 0x16, | ||
61 | + RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT = 0x17, | ||
62 | +} RISCVException; | ||
63 | |||
64 | #define RISCV_EXCP_INT_FLAG 0x80000000 | ||
65 | #define RISCV_EXCP_INT_MASK 0x7fffffff | ||
33 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 66 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
34 | index XXXXXXX..XXXXXXX 100644 | 67 | index XXXXXXX..XXXXXXX 100644 |
35 | --- a/target/riscv/cpu.c | 68 | --- a/target/riscv/cpu.c |
36 | +++ b/target/riscv/cpu.c | 69 | +++ b/target/riscv/cpu.c |
37 | @@ -XXX,XX +XXX,XX @@ static RISCVCPUProfile RVA22S64 = { | 70 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset(DeviceState *dev) |
71 | env->pc = env->resetvec; | ||
72 | env->two_stage_lookup = false; | ||
73 | #endif | ||
74 | - cs->exception_index = EXCP_NONE; | ||
75 | + cs->exception_index = RISCV_EXCP_NONE; | ||
76 | env->load_res = -1; | ||
77 | set_default_nan_mode(1, &env->fp_status); | ||
78 | } | ||
79 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | ||
80 | index XXXXXXX..XXXXXXX 100644 | ||
81 | --- a/target/riscv/cpu_helper.c | ||
82 | +++ b/target/riscv/cpu_helper.c | ||
83 | @@ -XXX,XX +XXX,XX @@ static int riscv_cpu_local_irq_pending(CPURISCVState *env) | ||
84 | if (irqs) { | ||
85 | return ctz64(irqs); /* since non-zero */ | ||
86 | } else { | ||
87 | - return EXCP_NONE; /* indicates no pending interrupt */ | ||
88 | + return RISCV_EXCP_NONE; /* indicates no pending interrupt */ | ||
38 | } | 89 | } |
39 | }; | ||
40 | |||
41 | +/* | ||
42 | + * All mandatory extensions from RVA22U64 are present | ||
43 | + * in RVA23U64 so set RVA22 as a parent. We need to | ||
44 | + * declare just the newly added mandatory extensions. | ||
45 | + */ | ||
46 | +static RISCVCPUProfile RVA23U64 = { | ||
47 | + .u_parent = &RVA22U64, | ||
48 | + .s_parent = NULL, | ||
49 | + .name = "rva23u64", | ||
50 | + .misa_ext = RVV, | ||
51 | + .priv_spec = RISCV_PROFILE_ATTR_UNUSED, | ||
52 | + .satp_mode = RISCV_PROFILE_ATTR_UNUSED, | ||
53 | + .ext_offsets = { | ||
54 | + CPU_CFG_OFFSET(ext_zvfhmin), CPU_CFG_OFFSET(ext_zvbb), | ||
55 | + CPU_CFG_OFFSET(ext_zvkt), CPU_CFG_OFFSET(ext_zihintntl), | ||
56 | + CPU_CFG_OFFSET(ext_zicond), CPU_CFG_OFFSET(ext_zimop), | ||
57 | + CPU_CFG_OFFSET(ext_zcmop), CPU_CFG_OFFSET(ext_zcb), | ||
58 | + CPU_CFG_OFFSET(ext_zfa), CPU_CFG_OFFSET(ext_zawrs), | ||
59 | + CPU_CFG_OFFSET(ext_supm), | ||
60 | + | ||
61 | + RISCV_PROFILE_EXT_LIST_END | ||
62 | + } | ||
63 | +}; | ||
64 | + | ||
65 | RISCVCPUProfile *riscv_profiles[] = { | ||
66 | &RVA22U64, | ||
67 | &RVA22S64, | ||
68 | + &RVA23U64, | ||
69 | NULL, | ||
70 | }; | ||
71 | |||
72 | @@ -XXX,XX +XXX,XX @@ static void rva22s64_profile_cpu_init(Object *obj) | ||
73 | |||
74 | RVA22S64.enabled = true; | ||
75 | } | 90 | } |
76 | + | ||
77 | +static void rva23u64_profile_cpu_init(Object *obj) | ||
78 | +{ | ||
79 | + rv64i_bare_cpu_init(obj); | ||
80 | + | ||
81 | + RVA23U64.enabled = true; | ||
82 | +} | ||
83 | #endif | 91 | #endif |
84 | 92 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) | |
85 | static const gchar *riscv_gdb_arch_name(CPUState *cs) | 93 | |
86 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo riscv_cpu_type_infos[] = { | 94 | env->two_stage_lookup = false; |
87 | DEFINE_BARE_CPU(TYPE_RISCV_CPU_RV64E, MXL_RV64, rv64e_bare_cpu_init), | 95 | #endif |
88 | DEFINE_PROFILE_CPU(TYPE_RISCV_CPU_RVA22U64, MXL_RV64, rva22u64_profile_cpu_init), | 96 | - cs->exception_index = EXCP_NONE; /* mark handled to qemu */ |
89 | DEFINE_PROFILE_CPU(TYPE_RISCV_CPU_RVA22S64, MXL_RV64, rva22s64_profile_cpu_init), | 97 | + cs->exception_index = RISCV_EXCP_NONE; /* mark handled to qemu */ |
90 | + DEFINE_PROFILE_CPU(TYPE_RISCV_CPU_RVA23U64, MXL_RV64, rva23u64_profile_cpu_init), | 98 | } |
91 | #endif /* TARGET_RISCV64 */ | ||
92 | }; | ||
93 | |||
94 | -- | 99 | -- |
95 | 2.48.1 | 100 | 2.31.1 |
101 | |||
102 | diff view generated by jsdifflib |
1 | From: Tomasz Jeznach <tjeznach@rivosinc.com> | 1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
---|---|---|---|
2 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
3 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
4 | Message-id: 187261fa671c3a77cf5aa482adb2a558c02a7cad.1617290165.git.alistair.francis@wdc.com | ||
5 | --- | ||
6 | target/riscv/cpu.h | 3 +- | ||
7 | target/riscv/csr.c | 80 +++++++++++++++++++++++++--------------------- | ||
8 | 2 files changed, 46 insertions(+), 37 deletions(-) | ||
2 | 9 | ||
3 | To support hpm events mmio writes, done via | 10 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
4 | riscv_iommu_process_hpmevt_write(), we're also adding the 'hpm-counters' | ||
5 | IOMMU property that are used to determine the amount of counters | ||
6 | available in the IOMMU. | ||
7 | |||
8 | Note that everything we did so far didn't change any IOMMU behavior | ||
9 | because we're still not advertising HPM capability to software. This | ||
10 | will be done in the next patch. | ||
11 | |||
12 | Signed-off-by: Tomasz Jeznach <tjeznach@rivosinc.com> | ||
13 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
14 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
15 | Message-ID: <20250224190826.1858473-9-dbarboza@ventanamicro.com> | ||
16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
17 | --- | ||
18 | hw/riscv/riscv-iommu-hpm.h | 1 + | ||
19 | hw/riscv/riscv-iommu.h | 1 + | ||
20 | hw/riscv/riscv-iommu-hpm.c | 88 ++++++++++++++++++++++++++++++++++++++ | ||
21 | hw/riscv/riscv-iommu.c | 4 +- | ||
22 | 4 files changed, 93 insertions(+), 1 deletion(-) | ||
23 | |||
24 | diff --git a/hw/riscv/riscv-iommu-hpm.h b/hw/riscv/riscv-iommu-hpm.h | ||
25 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/hw/riscv/riscv-iommu-hpm.h | 12 | --- a/target/riscv/cpu.h |
27 | +++ b/hw/riscv/riscv-iommu-hpm.h | 13 | +++ b/target/riscv/cpu.h |
28 | @@ -XXX,XX +XXX,XX @@ void riscv_iommu_hpm_incr_ctr(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, | 14 | @@ -XXX,XX +XXX,XX @@ static inline target_ulong riscv_csr_read(CPURISCVState *env, int csrno) |
29 | void riscv_iommu_hpm_timer_cb(void *priv); | 15 | return val; |
30 | void riscv_iommu_process_iocntinh_cy(RISCVIOMMUState *s, bool prev_cy_inh); | 16 | } |
31 | void riscv_iommu_process_hpmcycle_write(RISCVIOMMUState *s); | 17 | |
32 | +void riscv_iommu_process_hpmevt_write(RISCVIOMMUState *s, uint32_t evt_reg); | 18 | -typedef int (*riscv_csr_predicate_fn)(CPURISCVState *env, int csrno); |
33 | 19 | +typedef RISCVException (*riscv_csr_predicate_fn)(CPURISCVState *env, | |
20 | + int csrno); | ||
21 | typedef int (*riscv_csr_read_fn)(CPURISCVState *env, int csrno, | ||
22 | target_ulong *ret_value); | ||
23 | typedef int (*riscv_csr_write_fn)(CPURISCVState *env, int csrno, | ||
24 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/target/riscv/csr.c | ||
27 | +++ b/target/riscv/csr.c | ||
28 | @@ -XXX,XX +XXX,XX @@ void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops) | ||
29 | } | ||
30 | |||
31 | /* Predicates */ | ||
32 | -static int fs(CPURISCVState *env, int csrno) | ||
33 | +static RISCVException fs(CPURISCVState *env, int csrno) | ||
34 | { | ||
35 | #if !defined(CONFIG_USER_ONLY) | ||
36 | /* loose check condition for fcsr in vector extension */ | ||
37 | if ((csrno == CSR_FCSR) && (env->misa & RVV)) { | ||
38 | - return 0; | ||
39 | + return RISCV_EXCP_NONE; | ||
40 | } | ||
41 | if (!env->debugger && !riscv_cpu_fp_enabled(env)) { | ||
42 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
43 | + return RISCV_EXCP_ILLEGAL_INST; | ||
44 | } | ||
34 | #endif | 45 | #endif |
35 | diff --git a/hw/riscv/riscv-iommu.h b/hw/riscv/riscv-iommu.h | 46 | - return 0; |
36 | index XXXXXXX..XXXXXXX 100644 | 47 | + return RISCV_EXCP_NONE; |
37 | --- a/hw/riscv/riscv-iommu.h | 48 | } |
38 | +++ b/hw/riscv/riscv-iommu.h | 49 | |
39 | @@ -XXX,XX +XXX,XX @@ struct RISCVIOMMUState { | 50 | -static int vs(CPURISCVState *env, int csrno) |
40 | 51 | +static RISCVException vs(CPURISCVState *env, int csrno) | |
41 | /* HPM event counters */ | 52 | { |
42 | GHashTable *hpm_event_ctr_map; /* Mapping of events to counters */ | 53 | if (env->misa & RVV) { |
43 | + uint8_t hpm_cntrs; | 54 | - return 0; |
44 | }; | 55 | + return RISCV_EXCP_NONE; |
45 | 56 | } | |
46 | void riscv_iommu_pci_setup_iommu(RISCVIOMMUState *iommu, PCIBus *bus, | 57 | - return -RISCV_EXCP_ILLEGAL_INST; |
47 | diff --git a/hw/riscv/riscv-iommu-hpm.c b/hw/riscv/riscv-iommu-hpm.c | 58 | + return RISCV_EXCP_ILLEGAL_INST; |
48 | index XXXXXXX..XXXXXXX 100644 | 59 | } |
49 | --- a/hw/riscv/riscv-iommu-hpm.c | 60 | |
50 | +++ b/hw/riscv/riscv-iommu-hpm.c | 61 | -static int ctr(CPURISCVState *env, int csrno) |
51 | @@ -XXX,XX +XXX,XX @@ void riscv_iommu_process_hpmcycle_write(RISCVIOMMUState *s) | 62 | +static RISCVException ctr(CPURISCVState *env, int csrno) |
52 | s->hpmcycle_prev = get_cycles(); | 63 | { |
53 | hpm_setup_timer(s, s->hpmcycle_val); | 64 | #if !defined(CONFIG_USER_ONLY) |
54 | } | 65 | CPUState *cs = env_cpu(env); |
55 | + | 66 | @@ -XXX,XX +XXX,XX @@ static int ctr(CPURISCVState *env, int csrno) |
56 | +static inline bool check_valid_event_id(unsigned event_id) | 67 | |
57 | +{ | 68 | if (!cpu->cfg.ext_counters) { |
58 | + return event_id > RISCV_IOMMU_HPMEVENT_INVALID && | 69 | /* The Counters extensions is not enabled */ |
59 | + event_id < RISCV_IOMMU_HPMEVENT_MAX; | 70 | - return -RISCV_EXCP_ILLEGAL_INST; |
60 | +} | 71 | + return RISCV_EXCP_ILLEGAL_INST; |
61 | + | 72 | } |
62 | +static gboolean hpm_event_equal(gpointer key, gpointer value, gpointer udata) | 73 | |
63 | +{ | 74 | if (riscv_cpu_virt_enabled(env)) { |
64 | + uint32_t *pair = udata; | 75 | @@ -XXX,XX +XXX,XX @@ static int ctr(CPURISCVState *env, int csrno) |
65 | + | 76 | case CSR_CYCLE: |
66 | + if (GPOINTER_TO_UINT(value) & (1 << pair[0])) { | 77 | if (!get_field(env->hcounteren, HCOUNTEREN_CY) && |
67 | + pair[1] = GPOINTER_TO_UINT(key); | 78 | get_field(env->mcounteren, HCOUNTEREN_CY)) { |
68 | + return true; | 79 | - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; |
80 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
81 | } | ||
82 | break; | ||
83 | case CSR_TIME: | ||
84 | if (!get_field(env->hcounteren, HCOUNTEREN_TM) && | ||
85 | get_field(env->mcounteren, HCOUNTEREN_TM)) { | ||
86 | - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
87 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
88 | } | ||
89 | break; | ||
90 | case CSR_INSTRET: | ||
91 | if (!get_field(env->hcounteren, HCOUNTEREN_IR) && | ||
92 | get_field(env->mcounteren, HCOUNTEREN_IR)) { | ||
93 | - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
94 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
95 | } | ||
96 | break; | ||
97 | case CSR_HPMCOUNTER3...CSR_HPMCOUNTER31: | ||
98 | if (!get_field(env->hcounteren, 1 << (csrno - CSR_HPMCOUNTER3)) && | ||
99 | get_field(env->mcounteren, 1 << (csrno - CSR_HPMCOUNTER3))) { | ||
100 | - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
101 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
102 | } | ||
103 | break; | ||
104 | } | ||
105 | @@ -XXX,XX +XXX,XX @@ static int ctr(CPURISCVState *env, int csrno) | ||
106 | case CSR_CYCLEH: | ||
107 | if (!get_field(env->hcounteren, HCOUNTEREN_CY) && | ||
108 | get_field(env->mcounteren, HCOUNTEREN_CY)) { | ||
109 | - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
110 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
111 | } | ||
112 | break; | ||
113 | case CSR_TIMEH: | ||
114 | if (!get_field(env->hcounteren, HCOUNTEREN_TM) && | ||
115 | get_field(env->mcounteren, HCOUNTEREN_TM)) { | ||
116 | - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
117 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
118 | } | ||
119 | break; | ||
120 | case CSR_INSTRETH: | ||
121 | if (!get_field(env->hcounteren, HCOUNTEREN_IR) && | ||
122 | get_field(env->mcounteren, HCOUNTEREN_IR)) { | ||
123 | - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
124 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
125 | } | ||
126 | break; | ||
127 | case CSR_HPMCOUNTER3H...CSR_HPMCOUNTER31H: | ||
128 | if (!get_field(env->hcounteren, 1 << (csrno - CSR_HPMCOUNTER3H)) && | ||
129 | get_field(env->mcounteren, 1 << (csrno - CSR_HPMCOUNTER3H))) { | ||
130 | - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
131 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
132 | } | ||
133 | break; | ||
134 | } | ||
135 | } | ||
136 | } | ||
137 | #endif | ||
138 | - return 0; | ||
139 | + return RISCV_EXCP_NONE; | ||
140 | } | ||
141 | |||
142 | -static int ctr32(CPURISCVState *env, int csrno) | ||
143 | +static RISCVException ctr32(CPURISCVState *env, int csrno) | ||
144 | { | ||
145 | if (!riscv_cpu_is_32bit(env)) { | ||
146 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
147 | + return RISCV_EXCP_ILLEGAL_INST; | ||
148 | } | ||
149 | |||
150 | return ctr(env, csrno); | ||
151 | } | ||
152 | |||
153 | #if !defined(CONFIG_USER_ONLY) | ||
154 | -static int any(CPURISCVState *env, int csrno) | ||
155 | +static RISCVException any(CPURISCVState *env, int csrno) | ||
156 | { | ||
157 | - return 0; | ||
158 | + return RISCV_EXCP_NONE; | ||
159 | } | ||
160 | |||
161 | -static int any32(CPURISCVState *env, int csrno) | ||
162 | +static RISCVException any32(CPURISCVState *env, int csrno) | ||
163 | { | ||
164 | if (!riscv_cpu_is_32bit(env)) { | ||
165 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
166 | + return RISCV_EXCP_ILLEGAL_INST; | ||
167 | } | ||
168 | |||
169 | return any(env, csrno); | ||
170 | |||
171 | } | ||
172 | |||
173 | -static int smode(CPURISCVState *env, int csrno) | ||
174 | +static RISCVException smode(CPURISCVState *env, int csrno) | ||
175 | { | ||
176 | - return -!riscv_has_ext(env, RVS); | ||
177 | + if (riscv_has_ext(env, RVS)) { | ||
178 | + return RISCV_EXCP_NONE; | ||
69 | + } | 179 | + } |
70 | + | 180 | + |
71 | + return false; | 181 | + return RISCV_EXCP_ILLEGAL_INST; |
72 | +} | 182 | } |
73 | + | 183 | |
74 | +/* Caller must check ctr_idx against hpm_ctrs to see if its supported or not. */ | 184 | -static int hmode(CPURISCVState *env, int csrno) |
75 | +static void update_event_map(RISCVIOMMUState *s, uint64_t value, | 185 | +static RISCVException hmode(CPURISCVState *env, int csrno) |
76 | + uint32_t ctr_idx) | 186 | { |
77 | +{ | 187 | if (riscv_has_ext(env, RVS) && |
78 | + unsigned event_id = get_field(value, RISCV_IOMMU_IOHPMEVT_EVENT_ID); | 188 | riscv_has_ext(env, RVH)) { |
79 | + uint32_t pair[2] = { ctr_idx, RISCV_IOMMU_HPMEVENT_INVALID }; | 189 | /* Hypervisor extension is supported */ |
80 | + uint32_t new_value = 1 << ctr_idx; | 190 | if ((env->priv == PRV_S && !riscv_cpu_virt_enabled(env)) || |
81 | + gpointer data; | 191 | env->priv == PRV_M) { |
82 | + | 192 | - return 0; |
83 | + /* | 193 | + return RISCV_EXCP_NONE; |
84 | + * If EventID field is RISCV_IOMMU_HPMEVENT_INVALID | 194 | } else { |
85 | + * remove the current mapping. | 195 | - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; |
86 | + */ | 196 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; |
87 | + if (event_id == RISCV_IOMMU_HPMEVENT_INVALID) { | 197 | } |
88 | + data = g_hash_table_find(s->hpm_event_ctr_map, hpm_event_equal, pair); | 198 | } |
89 | + | 199 | |
90 | + new_value = GPOINTER_TO_UINT(data) & ~(new_value); | 200 | - return -RISCV_EXCP_ILLEGAL_INST; |
91 | + if (new_value != 0) { | 201 | + return RISCV_EXCP_ILLEGAL_INST; |
92 | + g_hash_table_replace(s->hpm_event_ctr_map, | 202 | } |
93 | + GUINT_TO_POINTER(pair[1]), | 203 | |
94 | + GUINT_TO_POINTER(new_value)); | 204 | -static int hmode32(CPURISCVState *env, int csrno) |
95 | + } else { | 205 | +static RISCVException hmode32(CPURISCVState *env, int csrno) |
96 | + g_hash_table_remove(s->hpm_event_ctr_map, | 206 | { |
97 | + GUINT_TO_POINTER(pair[1])); | 207 | if (!riscv_cpu_is_32bit(env)) { |
98 | + } | 208 | - return 0; |
99 | + | 209 | + return RISCV_EXCP_NONE; |
100 | + return; | 210 | } |
211 | |||
212 | return hmode(env, csrno); | ||
213 | |||
214 | } | ||
215 | |||
216 | -static int pmp(CPURISCVState *env, int csrno) | ||
217 | +static RISCVException pmp(CPURISCVState *env, int csrno) | ||
218 | { | ||
219 | - return -!riscv_feature(env, RISCV_FEATURE_PMP); | ||
220 | + if (riscv_feature(env, RISCV_FEATURE_PMP)) { | ||
221 | + return RISCV_EXCP_NONE; | ||
101 | + } | 222 | + } |
102 | + | 223 | + |
103 | + /* Update the counter mask if the event is already enabled. */ | 224 | + return RISCV_EXCP_ILLEGAL_INST; |
104 | + if (g_hash_table_lookup_extended(s->hpm_event_ctr_map, | 225 | } |
105 | + GUINT_TO_POINTER(event_id), | 226 | #endif |
106 | + NULL, | 227 | |
107 | + &data)) { | 228 | @@ -XXX,XX +XXX,XX @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, |
108 | + new_value |= GPOINTER_TO_UINT(data); | 229 | return -RISCV_EXCP_ILLEGAL_INST; |
109 | + } | 230 | } |
110 | + | 231 | ret = csr_ops[csrno].predicate(env, csrno); |
111 | + g_hash_table_insert(s->hpm_event_ctr_map, | 232 | - if (ret < 0) { |
112 | + GUINT_TO_POINTER(event_id), | 233 | - return ret; |
113 | + GUINT_TO_POINTER(new_value)); | 234 | + if (ret != RISCV_EXCP_NONE) { |
114 | +} | 235 | + return -ret; |
115 | + | 236 | } |
116 | +void riscv_iommu_process_hpmevt_write(RISCVIOMMUState *s, uint32_t evt_reg) | 237 | |
117 | +{ | 238 | /* execute combined read/write operation if it exists */ |
118 | + const uint32_t ctr_idx = (evt_reg - RISCV_IOMMU_REG_IOHPMEVT_BASE) >> 3; | ||
119 | + const uint32_t ovf = riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_IOCOUNTOVF); | ||
120 | + uint64_t val = riscv_iommu_reg_get64(s, evt_reg); | ||
121 | + | ||
122 | + if (ctr_idx >= s->hpm_cntrs) { | ||
123 | + return; | ||
124 | + } | ||
125 | + | ||
126 | + /* Clear OF bit in IOCNTOVF if it's being cleared in IOHPMEVT register. */ | ||
127 | + if (get_field(ovf, BIT(ctr_idx + 1)) && | ||
128 | + !get_field(val, RISCV_IOMMU_IOHPMEVT_OF)) { | ||
129 | + /* +1 to offset CYCLE register OF bit. */ | ||
130 | + riscv_iommu_reg_mod32( | ||
131 | + s, RISCV_IOMMU_REG_IOCOUNTOVF, 0, BIT(ctr_idx + 1)); | ||
132 | + } | ||
133 | + | ||
134 | + if (!check_valid_event_id(get_field(val, RISCV_IOMMU_IOHPMEVT_EVENT_ID))) { | ||
135 | + /* Reset EventID (WARL) field to invalid. */ | ||
136 | + val = set_field(val, RISCV_IOMMU_IOHPMEVT_EVENT_ID, | ||
137 | + RISCV_IOMMU_HPMEVENT_INVALID); | ||
138 | + riscv_iommu_reg_set64(s, evt_reg, val); | ||
139 | + } | ||
140 | + | ||
141 | + update_event_map(s, val, ctr_idx); | ||
142 | +} | ||
143 | diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c | ||
144 | index XXXXXXX..XXXXXXX 100644 | ||
145 | --- a/hw/riscv/riscv-iommu.c | ||
146 | +++ b/hw/riscv/riscv-iommu.c | ||
147 | @@ -XXX,XX +XXX,XX @@ static void riscv_iommu_process_hpm_writes(RISCVIOMMUState *s, | ||
148 | |||
149 | case RISCV_IOMMU_REG_IOHPMEVT_BASE ... | ||
150 | RISCV_IOMMU_REG_IOHPMEVT(RISCV_IOMMU_IOCOUNT_NUM) + 4: | ||
151 | - /* not yet implemented */ | ||
152 | + riscv_iommu_process_hpmevt_write(s, regb & ~7); | ||
153 | break; | ||
154 | } | ||
155 | } | ||
156 | @@ -XXX,XX +XXX,XX @@ static const Property riscv_iommu_properties[] = { | ||
157 | DEFINE_PROP_BOOL("g-stage", RISCVIOMMUState, enable_g_stage, TRUE), | ||
158 | DEFINE_PROP_LINK("downstream-mr", RISCVIOMMUState, target_mr, | ||
159 | TYPE_MEMORY_REGION, MemoryRegion *), | ||
160 | + DEFINE_PROP_UINT8("hpm-counters", RISCVIOMMUState, hpm_cntrs, | ||
161 | + RISCV_IOMMU_IOCOUNT_NUM), | ||
162 | }; | ||
163 | |||
164 | static void riscv_iommu_class_init(ObjectClass *klass, void* data) | ||
165 | -- | 239 | -- |
166 | 2.48.1 | 240 | 2.31.1 |
241 | |||
242 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
---|---|---|---|
2 | |||
3 | Coverity reported a DEADCODE ticket in this function, as follows: | ||
4 | |||
5 | >>>> CID 1590358: Control flow issues (DEADCODE) | ||
6 | >>>> Execution cannot reach this statement: "return ret;". | ||
7 | > 380 return ret; | ||
8 | > 381 } | ||
9 | |||
10 | The cause is that the 'if (ret != RISCV_EXCP_NONE)' conditional is | ||
11 | duplicated: | ||
12 | |||
13 | ret = smstateen_acc_ok(env, 0, SMSTATEEN0_AIA); | ||
14 | if (ret != RISCV_EXCP_NONE) { | ||
15 | return ret; | ||
16 | } | ||
17 | |||
18 | if (ret != RISCV_EXCP_NONE) { | ||
19 | return ret; | ||
20 | } | ||
21 | |||
22 | Remove the duplication to fix the deadcode. | ||
23 | |||
24 | Resolves: Coverity CID 1590358 | ||
25 | Fixes: dbcb6e1ccf ("target/riscv: Enable S*stateen bits for AIA") | ||
26 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
27 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
28 | Message-ID: <20250121184847.2109128-5-dbarboza@ventanamicro.com> | ||
29 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
2 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
3 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
4 | Message-id: cb1ef2061547dc9028ce3cf4f6622588f9c09149.1617290165.git.alistair.francis@wdc.com | ||
30 | --- | 5 | --- |
31 | target/riscv/csr.c | 4 ---- | 6 | target/riscv/csr.c | 6 +++++- |
32 | 1 file changed, 4 deletions(-) | 7 | 1 file changed, 5 insertions(+), 1 deletion(-) |
33 | 8 | ||
34 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 9 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
35 | index XXXXXXX..XXXXXXX 100644 | 10 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/target/riscv/csr.c | 11 | --- a/target/riscv/csr.c |
37 | +++ b/target/riscv/csr.c | 12 | +++ b/target/riscv/csr.c |
38 | @@ -XXX,XX +XXX,XX @@ static RISCVException aia_smode32(CPURISCVState *env, int csrno) | 13 | @@ -XXX,XX +XXX,XX @@ static RISCVException hmode(CPURISCVState *env, int csrno) |
39 | return ret; | 14 | static RISCVException hmode32(CPURISCVState *env, int csrno) |
15 | { | ||
16 | if (!riscv_cpu_is_32bit(env)) { | ||
17 | - return RISCV_EXCP_NONE; | ||
18 | + if (riscv_cpu_virt_enabled(env)) { | ||
19 | + return RISCV_EXCP_ILLEGAL_INST; | ||
20 | + } else { | ||
21 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
22 | + } | ||
40 | } | 23 | } |
41 | 24 | ||
42 | - if (ret != RISCV_EXCP_NONE) { | 25 | return hmode(env, csrno); |
43 | - return ret; | ||
44 | - } | ||
45 | - | ||
46 | return smode32(env, csrno); | ||
47 | } | ||
48 | |||
49 | -- | 26 | -- |
50 | 2.48.1 | 27 | 2.31.1 |
28 | |||
29 | diff view generated by jsdifflib |
1 | From: Tomasz Jeznach <tjeznach@rivosinc.com> | 1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
---|---|---|---|
2 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
3 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
4 | Message-id: 8566c4c271723f27f3ae8fc2429f906a459f17ce.1617290165.git.alistair.francis@wdc.com | ||
5 | --- | ||
6 | target/riscv/cpu.h | 14 +- | ||
7 | target/riscv/csr.c | 629 +++++++++++++++++++++++++++------------------ | ||
8 | 2 files changed, 382 insertions(+), 261 deletions(-) | ||
2 | 9 | ||
3 | This function will increment a specific counter, generating an interrupt | 10 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
4 | when an overflow occurs. | ||
5 | |||
6 | Some extra changes in riscv-iommu.c were required to add this new | ||
7 | helper in riscv-iommu-hpm.c: | ||
8 | |||
9 | - RISCVIOMMUContext was moved to riscv-iommu.h, making it visible in | ||
10 | riscv-iommu-hpm.c; | ||
11 | |||
12 | - riscv_iommu_notify() is now public. | ||
13 | |||
14 | No behavior change is made since HPM support is not being advertised | ||
15 | yet. | ||
16 | |||
17 | Signed-off-by: Tomasz Jeznach <tjeznach@rivosinc.com> | ||
18 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
19 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
20 | Message-ID: <20250224190826.1858473-5-dbarboza@ventanamicro.com> | ||
21 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
22 | --- | ||
23 | hw/riscv/riscv-iommu-hpm.h | 2 + | ||
24 | hw/riscv/riscv-iommu.h | 18 ++++++ | ||
25 | hw/riscv/riscv-iommu-hpm.c | 114 +++++++++++++++++++++++++++++++++++++ | ||
26 | hw/riscv/riscv-iommu.c | 43 +++++++++----- | ||
27 | 4 files changed, 162 insertions(+), 15 deletions(-) | ||
28 | |||
29 | diff --git a/hw/riscv/riscv-iommu-hpm.h b/hw/riscv/riscv-iommu-hpm.h | ||
30 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
31 | --- a/hw/riscv/riscv-iommu-hpm.h | 12 | --- a/target/riscv/cpu.h |
32 | +++ b/hw/riscv/riscv-iommu-hpm.h | 13 | +++ b/target/riscv/cpu.h |
33 | @@ -XXX,XX +XXX,XX @@ | 14 | @@ -XXX,XX +XXX,XX @@ static inline target_ulong riscv_csr_read(CPURISCVState *env, int csrno) |
34 | #include "hw/riscv/riscv-iommu.h" | 15 | |
35 | 16 | typedef RISCVException (*riscv_csr_predicate_fn)(CPURISCVState *env, | |
36 | uint64_t riscv_iommu_hpmcycle_read(RISCVIOMMUState *s); | 17 | int csrno); |
37 | +void riscv_iommu_hpm_incr_ctr(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, | 18 | -typedef int (*riscv_csr_read_fn)(CPURISCVState *env, int csrno, |
38 | + unsigned event_id); | 19 | - target_ulong *ret_value); |
39 | 20 | -typedef int (*riscv_csr_write_fn)(CPURISCVState *env, int csrno, | |
21 | - target_ulong new_value); | ||
22 | -typedef int (*riscv_csr_op_fn)(CPURISCVState *env, int csrno, | ||
23 | - target_ulong *ret_value, target_ulong new_value, target_ulong write_mask); | ||
24 | +typedef RISCVException (*riscv_csr_read_fn)(CPURISCVState *env, int csrno, | ||
25 | + target_ulong *ret_value); | ||
26 | +typedef RISCVException (*riscv_csr_write_fn)(CPURISCVState *env, int csrno, | ||
27 | + target_ulong new_value); | ||
28 | +typedef RISCVException (*riscv_csr_op_fn)(CPURISCVState *env, int csrno, | ||
29 | + target_ulong *ret_value, | ||
30 | + target_ulong new_value, | ||
31 | + target_ulong write_mask); | ||
32 | |||
33 | typedef struct { | ||
34 | const char *name; | ||
35 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | ||
36 | index XXXXXXX..XXXXXXX 100644 | ||
37 | --- a/target/riscv/csr.c | ||
38 | +++ b/target/riscv/csr.c | ||
39 | @@ -XXX,XX +XXX,XX @@ static RISCVException pmp(CPURISCVState *env, int csrno) | ||
40 | #endif | 40 | #endif |
41 | diff --git a/hw/riscv/riscv-iommu.h b/hw/riscv/riscv-iommu.h | 41 | |
42 | index XXXXXXX..XXXXXXX 100644 | 42 | /* User Floating-Point CSRs */ |
43 | --- a/hw/riscv/riscv-iommu.h | 43 | -static int read_fflags(CPURISCVState *env, int csrno, target_ulong *val) |
44 | +++ b/hw/riscv/riscv-iommu.h | 44 | +static RISCVException read_fflags(CPURISCVState *env, int csrno, |
45 | @@ -XXX,XX +XXX,XX @@ struct RISCVIOMMUState { | 45 | + target_ulong *val) |
46 | /* HPM cycle counter */ | 46 | { |
47 | uint64_t hpmcycle_val; /* Current value of cycle register */ | 47 | #if !defined(CONFIG_USER_ONLY) |
48 | uint64_t hpmcycle_prev; /* Saved value of QEMU_CLOCK_VIRTUAL clock */ | 48 | if (!env->debugger && !riscv_cpu_fp_enabled(env)) { |
49 | + | 49 | - return -RISCV_EXCP_ILLEGAL_INST; |
50 | + /* HPM event counters */ | 50 | + return RISCV_EXCP_ILLEGAL_INST; |
51 | + GHashTable *hpm_event_ctr_map; /* Mapping of events to counters */ | 51 | } |
52 | #endif | ||
53 | *val = riscv_cpu_get_fflags(env); | ||
54 | - return 0; | ||
55 | + return RISCV_EXCP_NONE; | ||
56 | } | ||
57 | |||
58 | -static int write_fflags(CPURISCVState *env, int csrno, target_ulong val) | ||
59 | +static RISCVException write_fflags(CPURISCVState *env, int csrno, | ||
60 | + target_ulong val) | ||
61 | { | ||
62 | #if !defined(CONFIG_USER_ONLY) | ||
63 | if (!env->debugger && !riscv_cpu_fp_enabled(env)) { | ||
64 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
65 | + return RISCV_EXCP_ILLEGAL_INST; | ||
66 | } | ||
67 | env->mstatus |= MSTATUS_FS; | ||
68 | #endif | ||
69 | riscv_cpu_set_fflags(env, val & (FSR_AEXC >> FSR_AEXC_SHIFT)); | ||
70 | - return 0; | ||
71 | + return RISCV_EXCP_NONE; | ||
72 | } | ||
73 | |||
74 | -static int read_frm(CPURISCVState *env, int csrno, target_ulong *val) | ||
75 | +static RISCVException read_frm(CPURISCVState *env, int csrno, | ||
76 | + target_ulong *val) | ||
77 | { | ||
78 | #if !defined(CONFIG_USER_ONLY) | ||
79 | if (!env->debugger && !riscv_cpu_fp_enabled(env)) { | ||
80 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
81 | + return RISCV_EXCP_ILLEGAL_INST; | ||
82 | } | ||
83 | #endif | ||
84 | *val = env->frm; | ||
85 | - return 0; | ||
86 | + return RISCV_EXCP_NONE; | ||
87 | } | ||
88 | |||
89 | -static int write_frm(CPURISCVState *env, int csrno, target_ulong val) | ||
90 | +static RISCVException write_frm(CPURISCVState *env, int csrno, | ||
91 | + target_ulong val) | ||
92 | { | ||
93 | #if !defined(CONFIG_USER_ONLY) | ||
94 | if (!env->debugger && !riscv_cpu_fp_enabled(env)) { | ||
95 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
96 | + return RISCV_EXCP_ILLEGAL_INST; | ||
97 | } | ||
98 | env->mstatus |= MSTATUS_FS; | ||
99 | #endif | ||
100 | env->frm = val & (FSR_RD >> FSR_RD_SHIFT); | ||
101 | - return 0; | ||
102 | + return RISCV_EXCP_NONE; | ||
103 | } | ||
104 | |||
105 | -static int read_fcsr(CPURISCVState *env, int csrno, target_ulong *val) | ||
106 | +static RISCVException read_fcsr(CPURISCVState *env, int csrno, | ||
107 | + target_ulong *val) | ||
108 | { | ||
109 | #if !defined(CONFIG_USER_ONLY) | ||
110 | if (!env->debugger && !riscv_cpu_fp_enabled(env)) { | ||
111 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
112 | + return RISCV_EXCP_ILLEGAL_INST; | ||
113 | } | ||
114 | #endif | ||
115 | *val = (riscv_cpu_get_fflags(env) << FSR_AEXC_SHIFT) | ||
116 | @@ -XXX,XX +XXX,XX @@ static int read_fcsr(CPURISCVState *env, int csrno, target_ulong *val) | ||
117 | *val |= (env->vxrm << FSR_VXRM_SHIFT) | ||
118 | | (env->vxsat << FSR_VXSAT_SHIFT); | ||
119 | } | ||
120 | - return 0; | ||
121 | + return RISCV_EXCP_NONE; | ||
122 | } | ||
123 | |||
124 | -static int write_fcsr(CPURISCVState *env, int csrno, target_ulong val) | ||
125 | +static RISCVException write_fcsr(CPURISCVState *env, int csrno, | ||
126 | + target_ulong val) | ||
127 | { | ||
128 | #if !defined(CONFIG_USER_ONLY) | ||
129 | if (!env->debugger && !riscv_cpu_fp_enabled(env)) { | ||
130 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
131 | + return RISCV_EXCP_ILLEGAL_INST; | ||
132 | } | ||
133 | env->mstatus |= MSTATUS_FS; | ||
134 | #endif | ||
135 | @@ -XXX,XX +XXX,XX @@ static int write_fcsr(CPURISCVState *env, int csrno, target_ulong val) | ||
136 | env->vxsat = (val & FSR_VXSAT) >> FSR_VXSAT_SHIFT; | ||
137 | } | ||
138 | riscv_cpu_set_fflags(env, (val & FSR_AEXC) >> FSR_AEXC_SHIFT); | ||
139 | - return 0; | ||
140 | + return RISCV_EXCP_NONE; | ||
141 | } | ||
142 | |||
143 | -static int read_vtype(CPURISCVState *env, int csrno, target_ulong *val) | ||
144 | +static RISCVException read_vtype(CPURISCVState *env, int csrno, | ||
145 | + target_ulong *val) | ||
146 | { | ||
147 | *val = env->vtype; | ||
148 | - return 0; | ||
149 | + return RISCV_EXCP_NONE; | ||
150 | } | ||
151 | |||
152 | -static int read_vl(CPURISCVState *env, int csrno, target_ulong *val) | ||
153 | +static RISCVException read_vl(CPURISCVState *env, int csrno, | ||
154 | + target_ulong *val) | ||
155 | { | ||
156 | *val = env->vl; | ||
157 | - return 0; | ||
158 | + return RISCV_EXCP_NONE; | ||
159 | } | ||
160 | |||
161 | -static int read_vxrm(CPURISCVState *env, int csrno, target_ulong *val) | ||
162 | +static RISCVException read_vxrm(CPURISCVState *env, int csrno, | ||
163 | + target_ulong *val) | ||
164 | { | ||
165 | *val = env->vxrm; | ||
166 | - return 0; | ||
167 | + return RISCV_EXCP_NONE; | ||
168 | } | ||
169 | |||
170 | -static int write_vxrm(CPURISCVState *env, int csrno, target_ulong val) | ||
171 | +static RISCVException write_vxrm(CPURISCVState *env, int csrno, | ||
172 | + target_ulong val) | ||
173 | { | ||
174 | env->vxrm = val; | ||
175 | - return 0; | ||
176 | + return RISCV_EXCP_NONE; | ||
177 | } | ||
178 | |||
179 | -static int read_vxsat(CPURISCVState *env, int csrno, target_ulong *val) | ||
180 | +static RISCVException read_vxsat(CPURISCVState *env, int csrno, | ||
181 | + target_ulong *val) | ||
182 | { | ||
183 | *val = env->vxsat; | ||
184 | - return 0; | ||
185 | + return RISCV_EXCP_NONE; | ||
186 | } | ||
187 | |||
188 | -static int write_vxsat(CPURISCVState *env, int csrno, target_ulong val) | ||
189 | +static RISCVException write_vxsat(CPURISCVState *env, int csrno, | ||
190 | + target_ulong val) | ||
191 | { | ||
192 | env->vxsat = val; | ||
193 | - return 0; | ||
194 | + return RISCV_EXCP_NONE; | ||
195 | } | ||
196 | |||
197 | -static int read_vstart(CPURISCVState *env, int csrno, target_ulong *val) | ||
198 | +static RISCVException read_vstart(CPURISCVState *env, int csrno, | ||
199 | + target_ulong *val) | ||
200 | { | ||
201 | *val = env->vstart; | ||
202 | - return 0; | ||
203 | + return RISCV_EXCP_NONE; | ||
204 | } | ||
205 | |||
206 | -static int write_vstart(CPURISCVState *env, int csrno, target_ulong val) | ||
207 | +static RISCVException write_vstart(CPURISCVState *env, int csrno, | ||
208 | + target_ulong val) | ||
209 | { | ||
210 | env->vstart = val; | ||
211 | - return 0; | ||
212 | + return RISCV_EXCP_NONE; | ||
213 | } | ||
214 | |||
215 | /* User Timers and Counters */ | ||
216 | -static int read_instret(CPURISCVState *env, int csrno, target_ulong *val) | ||
217 | +static RISCVException read_instret(CPURISCVState *env, int csrno, | ||
218 | + target_ulong *val) | ||
219 | { | ||
220 | #if !defined(CONFIG_USER_ONLY) | ||
221 | if (icount_enabled()) { | ||
222 | @@ -XXX,XX +XXX,XX @@ static int read_instret(CPURISCVState *env, int csrno, target_ulong *val) | ||
223 | #else | ||
224 | *val = cpu_get_host_ticks(); | ||
225 | #endif | ||
226 | - return 0; | ||
227 | + return RISCV_EXCP_NONE; | ||
228 | } | ||
229 | |||
230 | -static int read_instreth(CPURISCVState *env, int csrno, target_ulong *val) | ||
231 | +static RISCVException read_instreth(CPURISCVState *env, int csrno, | ||
232 | + target_ulong *val) | ||
233 | { | ||
234 | #if !defined(CONFIG_USER_ONLY) | ||
235 | if (icount_enabled()) { | ||
236 | @@ -XXX,XX +XXX,XX @@ static int read_instreth(CPURISCVState *env, int csrno, target_ulong *val) | ||
237 | #else | ||
238 | *val = cpu_get_host_ticks() >> 32; | ||
239 | #endif | ||
240 | - return 0; | ||
241 | + return RISCV_EXCP_NONE; | ||
242 | } | ||
243 | |||
244 | #if defined(CONFIG_USER_ONLY) | ||
245 | -static int read_time(CPURISCVState *env, int csrno, target_ulong *val) | ||
246 | +static RISCVException read_time(CPURISCVState *env, int csrno, | ||
247 | + target_ulong *val) | ||
248 | { | ||
249 | *val = cpu_get_host_ticks(); | ||
250 | - return 0; | ||
251 | + return RISCV_EXCP_NONE; | ||
252 | } | ||
253 | |||
254 | -static int read_timeh(CPURISCVState *env, int csrno, target_ulong *val) | ||
255 | +static RISCVException read_timeh(CPURISCVState *env, int csrno, | ||
256 | + target_ulong *val) | ||
257 | { | ||
258 | *val = cpu_get_host_ticks() >> 32; | ||
259 | - return 0; | ||
260 | + return RISCV_EXCP_NONE; | ||
261 | } | ||
262 | |||
263 | #else /* CONFIG_USER_ONLY */ | ||
264 | |||
265 | -static int read_time(CPURISCVState *env, int csrno, target_ulong *val) | ||
266 | +static RISCVException read_time(CPURISCVState *env, int csrno, | ||
267 | + target_ulong *val) | ||
268 | { | ||
269 | uint64_t delta = riscv_cpu_virt_enabled(env) ? env->htimedelta : 0; | ||
270 | |||
271 | if (!env->rdtime_fn) { | ||
272 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
273 | + return RISCV_EXCP_ILLEGAL_INST; | ||
274 | } | ||
275 | |||
276 | *val = env->rdtime_fn(env->rdtime_fn_arg) + delta; | ||
277 | - return 0; | ||
278 | + return RISCV_EXCP_NONE; | ||
279 | } | ||
280 | |||
281 | -static int read_timeh(CPURISCVState *env, int csrno, target_ulong *val) | ||
282 | +static RISCVException read_timeh(CPURISCVState *env, int csrno, | ||
283 | + target_ulong *val) | ||
284 | { | ||
285 | uint64_t delta = riscv_cpu_virt_enabled(env) ? env->htimedelta : 0; | ||
286 | |||
287 | if (!env->rdtime_fn) { | ||
288 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
289 | + return RISCV_EXCP_ILLEGAL_INST; | ||
290 | } | ||
291 | |||
292 | *val = (env->rdtime_fn(env->rdtime_fn_arg) + delta) >> 32; | ||
293 | - return 0; | ||
294 | + return RISCV_EXCP_NONE; | ||
295 | } | ||
296 | |||
297 | /* Machine constants */ | ||
298 | @@ -XXX,XX +XXX,XX @@ static const char valid_vm_1_10_64[16] = { | ||
52 | }; | 299 | }; |
53 | 300 | ||
54 | void riscv_iommu_pci_setup_iommu(RISCVIOMMUState *iommu, PCIBus *bus, | 301 | /* Machine Information Registers */ |
55 | Error **errp); | 302 | -static int read_zero(CPURISCVState *env, int csrno, target_ulong *val) |
56 | void riscv_iommu_set_cap_igs(RISCVIOMMUState *s, riscv_iommu_igs_mode mode); | 303 | +static RISCVException read_zero(CPURISCVState *env, int csrno, |
57 | void riscv_iommu_reset(RISCVIOMMUState *s); | 304 | + target_ulong *val) |
58 | +void riscv_iommu_notify(RISCVIOMMUState *s, int vec_type); | 305 | { |
59 | + | 306 | - return *val = 0; |
60 | +typedef struct RISCVIOMMUContext RISCVIOMMUContext; | 307 | + *val = 0; |
61 | +/* Device translation context state. */ | 308 | + return RISCV_EXCP_NONE; |
62 | +struct RISCVIOMMUContext { | 309 | } |
63 | + uint64_t devid:24; /* Requester Id, AKA device_id */ | 310 | |
64 | + uint64_t process_id:20; /* Process ID. PASID for PCIe */ | 311 | -static int read_mhartid(CPURISCVState *env, int csrno, target_ulong *val) |
65 | + uint64_t tc; /* Translation Control */ | 312 | +static RISCVException read_mhartid(CPURISCVState *env, int csrno, |
66 | + uint64_t ta; /* Translation Attributes */ | 313 | + target_ulong *val) |
67 | + uint64_t satp; /* S-Stage address translation and protection */ | 314 | { |
68 | + uint64_t gatp; /* G-Stage address translation and protection */ | 315 | *val = env->mhartid; |
69 | + uint64_t msi_addr_mask; /* MSI filtering - address mask */ | 316 | - return 0; |
70 | + uint64_t msi_addr_pattern; /* MSI filtering - address pattern */ | 317 | + return RISCV_EXCP_NONE; |
71 | + uint64_t msiptp; /* MSI redirection page table pointer */ | 318 | } |
72 | +}; | 319 | |
73 | 320 | /* Machine Trap Setup */ | |
74 | /* private helpers */ | 321 | -static int read_mstatus(CPURISCVState *env, int csrno, target_ulong *val) |
75 | 322 | +static RISCVException read_mstatus(CPURISCVState *env, int csrno, | |
76 | diff --git a/hw/riscv/riscv-iommu-hpm.c b/hw/riscv/riscv-iommu-hpm.c | 323 | + target_ulong *val) |
77 | index XXXXXXX..XXXXXXX 100644 | 324 | { |
78 | --- a/hw/riscv/riscv-iommu-hpm.c | 325 | *val = env->mstatus; |
79 | +++ b/hw/riscv/riscv-iommu-hpm.c | 326 | - return 0; |
80 | @@ -XXX,XX +XXX,XX @@ uint64_t riscv_iommu_hpmcycle_read(RISCVIOMMUState *s) | 327 | + return RISCV_EXCP_NONE; |
81 | return (ctr_val + get_cycles() - ctr_prev) | | 328 | } |
82 | (cycle & RISCV_IOMMU_IOHPMCYCLES_OVF); | 329 | |
83 | } | 330 | static int validate_vm(CPURISCVState *env, target_ulong vm) |
84 | + | 331 | @@ -XXX,XX +XXX,XX @@ static int validate_vm(CPURISCVState *env, target_ulong vm) |
85 | +static void hpm_incr_ctr(RISCVIOMMUState *s, uint32_t ctr_idx) | 332 | } |
86 | +{ | 333 | } |
87 | + const uint32_t off = ctr_idx << 3; | 334 | |
88 | + uint64_t cntr_val; | 335 | -static int write_mstatus(CPURISCVState *env, int csrno, target_ulong val) |
89 | + | 336 | +static RISCVException write_mstatus(CPURISCVState *env, int csrno, |
90 | + cntr_val = ldq_le_p(&s->regs_rw[RISCV_IOMMU_REG_IOHPMCTR_BASE + off]); | 337 | + target_ulong val) |
91 | + stq_le_p(&s->regs_rw[RISCV_IOMMU_REG_IOHPMCTR_BASE + off], cntr_val + 1); | 338 | { |
92 | + | 339 | uint64_t mstatus = env->mstatus; |
93 | + /* Handle the overflow scenario. */ | 340 | uint64_t mask = 0; |
94 | + if (cntr_val == UINT64_MAX) { | 341 | @@ -XXX,XX +XXX,XX @@ static int write_mstatus(CPURISCVState *env, int csrno, target_ulong val) |
95 | + /* | 342 | mstatus = set_field(mstatus, MSTATUS_SD, dirty); |
96 | + * Generate interrupt only if OF bit is clear. +1 to offset the cycle | 343 | env->mstatus = mstatus; |
97 | + * register OF bit. | 344 | |
98 | + */ | 345 | - return 0; |
99 | + const uint32_t ovf = | 346 | + return RISCV_EXCP_NONE; |
100 | + riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_IOCOUNTOVF, | 347 | } |
101 | + BIT(ctr_idx + 1), 0); | 348 | |
102 | + if (!get_field(ovf, BIT(ctr_idx + 1))) { | 349 | -static int read_mstatush(CPURISCVState *env, int csrno, target_ulong *val) |
103 | + riscv_iommu_reg_mod64(s, | 350 | +static RISCVException read_mstatush(CPURISCVState *env, int csrno, |
104 | + RISCV_IOMMU_REG_IOHPMEVT_BASE + off, | 351 | + target_ulong *val) |
105 | + RISCV_IOMMU_IOHPMEVT_OF, | 352 | { |
106 | + 0); | 353 | *val = env->mstatus >> 32; |
107 | + riscv_iommu_notify(s, RISCV_IOMMU_INTR_PM); | 354 | - return 0; |
355 | + return RISCV_EXCP_NONE; | ||
356 | } | ||
357 | |||
358 | -static int write_mstatush(CPURISCVState *env, int csrno, target_ulong val) | ||
359 | +static RISCVException write_mstatush(CPURISCVState *env, int csrno, | ||
360 | + target_ulong val) | ||
361 | { | ||
362 | uint64_t valh = (uint64_t)val << 32; | ||
363 | uint64_t mask = MSTATUS_MPV | MSTATUS_GVA; | ||
364 | @@ -XXX,XX +XXX,XX @@ static int write_mstatush(CPURISCVState *env, int csrno, target_ulong val) | ||
365 | |||
366 | env->mstatus = (env->mstatus & ~mask) | (valh & mask); | ||
367 | |||
368 | - return 0; | ||
369 | + return RISCV_EXCP_NONE; | ||
370 | } | ||
371 | |||
372 | -static int read_misa(CPURISCVState *env, int csrno, target_ulong *val) | ||
373 | +static RISCVException read_misa(CPURISCVState *env, int csrno, | ||
374 | + target_ulong *val) | ||
375 | { | ||
376 | *val = env->misa; | ||
377 | - return 0; | ||
378 | + return RISCV_EXCP_NONE; | ||
379 | } | ||
380 | |||
381 | -static int write_misa(CPURISCVState *env, int csrno, target_ulong val) | ||
382 | +static RISCVException write_misa(CPURISCVState *env, int csrno, | ||
383 | + target_ulong val) | ||
384 | { | ||
385 | if (!riscv_feature(env, RISCV_FEATURE_MISA)) { | ||
386 | /* drop write to misa */ | ||
387 | - return 0; | ||
388 | + return RISCV_EXCP_NONE; | ||
389 | } | ||
390 | |||
391 | /* 'I' or 'E' must be present */ | ||
392 | if (!(val & (RVI | RVE))) { | ||
393 | /* It is not, drop write to misa */ | ||
394 | - return 0; | ||
395 | + return RISCV_EXCP_NONE; | ||
396 | } | ||
397 | |||
398 | /* 'E' excludes all other extensions */ | ||
399 | @@ -XXX,XX +XXX,XX @@ static int write_misa(CPURISCVState *env, int csrno, target_ulong val) | ||
400 | /* when we support 'E' we can do "val = RVE;" however | ||
401 | * for now we just drop writes if 'E' is present. | ||
402 | */ | ||
403 | - return 0; | ||
404 | + return RISCV_EXCP_NONE; | ||
405 | } | ||
406 | |||
407 | /* Mask extensions that are not supported by this hart */ | ||
408 | @@ -XXX,XX +XXX,XX @@ static int write_misa(CPURISCVState *env, int csrno, target_ulong val) | ||
409 | |||
410 | env->misa = val; | ||
411 | |||
412 | - return 0; | ||
413 | + return RISCV_EXCP_NONE; | ||
414 | } | ||
415 | |||
416 | -static int read_medeleg(CPURISCVState *env, int csrno, target_ulong *val) | ||
417 | +static RISCVException read_medeleg(CPURISCVState *env, int csrno, | ||
418 | + target_ulong *val) | ||
419 | { | ||
420 | *val = env->medeleg; | ||
421 | - return 0; | ||
422 | + return RISCV_EXCP_NONE; | ||
423 | } | ||
424 | |||
425 | -static int write_medeleg(CPURISCVState *env, int csrno, target_ulong val) | ||
426 | +static RISCVException write_medeleg(CPURISCVState *env, int csrno, | ||
427 | + target_ulong val) | ||
428 | { | ||
429 | env->medeleg = (env->medeleg & ~delegable_excps) | (val & delegable_excps); | ||
430 | - return 0; | ||
431 | + return RISCV_EXCP_NONE; | ||
432 | } | ||
433 | |||
434 | -static int read_mideleg(CPURISCVState *env, int csrno, target_ulong *val) | ||
435 | +static RISCVException read_mideleg(CPURISCVState *env, int csrno, | ||
436 | + target_ulong *val) | ||
437 | { | ||
438 | *val = env->mideleg; | ||
439 | - return 0; | ||
440 | + return RISCV_EXCP_NONE; | ||
441 | } | ||
442 | |||
443 | -static int write_mideleg(CPURISCVState *env, int csrno, target_ulong val) | ||
444 | +static RISCVException write_mideleg(CPURISCVState *env, int csrno, | ||
445 | + target_ulong val) | ||
446 | { | ||
447 | env->mideleg = (env->mideleg & ~delegable_ints) | (val & delegable_ints); | ||
448 | if (riscv_has_ext(env, RVH)) { | ||
449 | env->mideleg |= VS_MODE_INTERRUPTS; | ||
450 | } | ||
451 | - return 0; | ||
452 | + return RISCV_EXCP_NONE; | ||
453 | } | ||
454 | |||
455 | -static int read_mie(CPURISCVState *env, int csrno, target_ulong *val) | ||
456 | +static RISCVException read_mie(CPURISCVState *env, int csrno, | ||
457 | + target_ulong *val) | ||
458 | { | ||
459 | *val = env->mie; | ||
460 | - return 0; | ||
461 | + return RISCV_EXCP_NONE; | ||
462 | } | ||
463 | |||
464 | -static int write_mie(CPURISCVState *env, int csrno, target_ulong val) | ||
465 | +static RISCVException write_mie(CPURISCVState *env, int csrno, | ||
466 | + target_ulong val) | ||
467 | { | ||
468 | env->mie = (env->mie & ~all_ints) | (val & all_ints); | ||
469 | - return 0; | ||
470 | + return RISCV_EXCP_NONE; | ||
471 | } | ||
472 | |||
473 | -static int read_mtvec(CPURISCVState *env, int csrno, target_ulong *val) | ||
474 | +static RISCVException read_mtvec(CPURISCVState *env, int csrno, | ||
475 | + target_ulong *val) | ||
476 | { | ||
477 | *val = env->mtvec; | ||
478 | - return 0; | ||
479 | + return RISCV_EXCP_NONE; | ||
480 | } | ||
481 | |||
482 | -static int write_mtvec(CPURISCVState *env, int csrno, target_ulong val) | ||
483 | +static RISCVException write_mtvec(CPURISCVState *env, int csrno, | ||
484 | + target_ulong val) | ||
485 | { | ||
486 | /* bits [1:0] encode mode; 0 = direct, 1 = vectored, 2 >= reserved */ | ||
487 | if ((val & 3) < 2) { | ||
488 | @@ -XXX,XX +XXX,XX @@ static int write_mtvec(CPURISCVState *env, int csrno, target_ulong val) | ||
489 | } else { | ||
490 | qemu_log_mask(LOG_UNIMP, "CSR_MTVEC: reserved mode not supported\n"); | ||
491 | } | ||
492 | - return 0; | ||
493 | + return RISCV_EXCP_NONE; | ||
494 | } | ||
495 | |||
496 | -static int read_mcounteren(CPURISCVState *env, int csrno, target_ulong *val) | ||
497 | +static RISCVException read_mcounteren(CPURISCVState *env, int csrno, | ||
498 | + target_ulong *val) | ||
499 | { | ||
500 | *val = env->mcounteren; | ||
501 | - return 0; | ||
502 | + return RISCV_EXCP_NONE; | ||
503 | } | ||
504 | |||
505 | -static int write_mcounteren(CPURISCVState *env, int csrno, target_ulong val) | ||
506 | +static RISCVException write_mcounteren(CPURISCVState *env, int csrno, | ||
507 | + target_ulong val) | ||
508 | { | ||
509 | env->mcounteren = val; | ||
510 | - return 0; | ||
511 | + return RISCV_EXCP_NONE; | ||
512 | } | ||
513 | |||
514 | /* Machine Trap Handling */ | ||
515 | -static int read_mscratch(CPURISCVState *env, int csrno, target_ulong *val) | ||
516 | +static RISCVException read_mscratch(CPURISCVState *env, int csrno, | ||
517 | + target_ulong *val) | ||
518 | { | ||
519 | *val = env->mscratch; | ||
520 | - return 0; | ||
521 | + return RISCV_EXCP_NONE; | ||
522 | } | ||
523 | |||
524 | -static int write_mscratch(CPURISCVState *env, int csrno, target_ulong val) | ||
525 | +static RISCVException write_mscratch(CPURISCVState *env, int csrno, | ||
526 | + target_ulong val) | ||
527 | { | ||
528 | env->mscratch = val; | ||
529 | - return 0; | ||
530 | + return RISCV_EXCP_NONE; | ||
531 | } | ||
532 | |||
533 | -static int read_mepc(CPURISCVState *env, int csrno, target_ulong *val) | ||
534 | +static RISCVException read_mepc(CPURISCVState *env, int csrno, | ||
535 | + target_ulong *val) | ||
536 | { | ||
537 | *val = env->mepc; | ||
538 | - return 0; | ||
539 | + return RISCV_EXCP_NONE; | ||
540 | } | ||
541 | |||
542 | -static int write_mepc(CPURISCVState *env, int csrno, target_ulong val) | ||
543 | +static RISCVException write_mepc(CPURISCVState *env, int csrno, | ||
544 | + target_ulong val) | ||
545 | { | ||
546 | env->mepc = val; | ||
547 | - return 0; | ||
548 | + return RISCV_EXCP_NONE; | ||
549 | } | ||
550 | |||
551 | -static int read_mcause(CPURISCVState *env, int csrno, target_ulong *val) | ||
552 | +static RISCVException read_mcause(CPURISCVState *env, int csrno, | ||
553 | + target_ulong *val) | ||
554 | { | ||
555 | *val = env->mcause; | ||
556 | - return 0; | ||
557 | + return RISCV_EXCP_NONE; | ||
558 | } | ||
559 | |||
560 | -static int write_mcause(CPURISCVState *env, int csrno, target_ulong val) | ||
561 | +static RISCVException write_mcause(CPURISCVState *env, int csrno, | ||
562 | + target_ulong val) | ||
563 | { | ||
564 | env->mcause = val; | ||
565 | - return 0; | ||
566 | + return RISCV_EXCP_NONE; | ||
567 | } | ||
568 | |||
569 | -static int read_mtval(CPURISCVState *env, int csrno, target_ulong *val) | ||
570 | +static RISCVException read_mtval(CPURISCVState *env, int csrno, | ||
571 | + target_ulong *val) | ||
572 | { | ||
573 | *val = env->mtval; | ||
574 | - return 0; | ||
575 | + return RISCV_EXCP_NONE; | ||
576 | } | ||
577 | |||
578 | -static int write_mtval(CPURISCVState *env, int csrno, target_ulong val) | ||
579 | +static RISCVException write_mtval(CPURISCVState *env, int csrno, | ||
580 | + target_ulong val) | ||
581 | { | ||
582 | env->mtval = val; | ||
583 | - return 0; | ||
584 | + return RISCV_EXCP_NONE; | ||
585 | } | ||
586 | |||
587 | -static int rmw_mip(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
588 | - target_ulong new_value, target_ulong write_mask) | ||
589 | +static RISCVException rmw_mip(CPURISCVState *env, int csrno, | ||
590 | + target_ulong *ret_value, | ||
591 | + target_ulong new_value, target_ulong write_mask) | ||
592 | { | ||
593 | RISCVCPU *cpu = env_archcpu(env); | ||
594 | /* Allow software control of delegable interrupts not claimed by hardware */ | ||
595 | @@ -XXX,XX +XXX,XX @@ static int rmw_mip(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
596 | *ret_value = old_mip; | ||
597 | } | ||
598 | |||
599 | - return 0; | ||
600 | + return RISCV_EXCP_NONE; | ||
601 | } | ||
602 | |||
603 | /* Supervisor Trap Setup */ | ||
604 | -static int read_sstatus(CPURISCVState *env, int csrno, target_ulong *val) | ||
605 | +static RISCVException read_sstatus(CPURISCVState *env, int csrno, | ||
606 | + target_ulong *val) | ||
607 | { | ||
608 | target_ulong mask = (sstatus_v1_10_mask); | ||
609 | *val = env->mstatus & mask; | ||
610 | - return 0; | ||
611 | + return RISCV_EXCP_NONE; | ||
612 | } | ||
613 | |||
614 | -static int write_sstatus(CPURISCVState *env, int csrno, target_ulong val) | ||
615 | +static RISCVException write_sstatus(CPURISCVState *env, int csrno, | ||
616 | + target_ulong val) | ||
617 | { | ||
618 | target_ulong mask = (sstatus_v1_10_mask); | ||
619 | target_ulong newval = (env->mstatus & ~mask) | (val & mask); | ||
620 | return write_mstatus(env, CSR_MSTATUS, newval); | ||
621 | } | ||
622 | |||
623 | -static int read_vsie(CPURISCVState *env, int csrno, target_ulong *val) | ||
624 | +static RISCVException read_vsie(CPURISCVState *env, int csrno, | ||
625 | + target_ulong *val) | ||
626 | { | ||
627 | /* Shift the VS bits to their S bit location in vsie */ | ||
628 | *val = (env->mie & env->hideleg & VS_MODE_INTERRUPTS) >> 1; | ||
629 | - return 0; | ||
630 | + return RISCV_EXCP_NONE; | ||
631 | } | ||
632 | |||
633 | -static int read_sie(CPURISCVState *env, int csrno, target_ulong *val) | ||
634 | +static RISCVException read_sie(CPURISCVState *env, int csrno, | ||
635 | + target_ulong *val) | ||
636 | { | ||
637 | if (riscv_cpu_virt_enabled(env)) { | ||
638 | read_vsie(env, CSR_VSIE, val); | ||
639 | } else { | ||
640 | *val = env->mie & env->mideleg; | ||
641 | } | ||
642 | - return 0; | ||
643 | + return RISCV_EXCP_NONE; | ||
644 | } | ||
645 | |||
646 | -static int write_vsie(CPURISCVState *env, int csrno, target_ulong val) | ||
647 | +static RISCVException write_vsie(CPURISCVState *env, int csrno, | ||
648 | + target_ulong val) | ||
649 | { | ||
650 | /* Shift the S bits to their VS bit location in mie */ | ||
651 | target_ulong newval = (env->mie & ~VS_MODE_INTERRUPTS) | | ||
652 | @@ -XXX,XX +XXX,XX @@ static int write_sie(CPURISCVState *env, int csrno, target_ulong val) | ||
653 | write_mie(env, CSR_MIE, newval); | ||
654 | } | ||
655 | |||
656 | - return 0; | ||
657 | + return RISCV_EXCP_NONE; | ||
658 | } | ||
659 | |||
660 | -static int read_stvec(CPURISCVState *env, int csrno, target_ulong *val) | ||
661 | +static RISCVException read_stvec(CPURISCVState *env, int csrno, | ||
662 | + target_ulong *val) | ||
663 | { | ||
664 | *val = env->stvec; | ||
665 | - return 0; | ||
666 | + return RISCV_EXCP_NONE; | ||
667 | } | ||
668 | |||
669 | -static int write_stvec(CPURISCVState *env, int csrno, target_ulong val) | ||
670 | +static RISCVException write_stvec(CPURISCVState *env, int csrno, | ||
671 | + target_ulong val) | ||
672 | { | ||
673 | /* bits [1:0] encode mode; 0 = direct, 1 = vectored, 2 >= reserved */ | ||
674 | if ((val & 3) < 2) { | ||
675 | @@ -XXX,XX +XXX,XX @@ static int write_stvec(CPURISCVState *env, int csrno, target_ulong val) | ||
676 | } else { | ||
677 | qemu_log_mask(LOG_UNIMP, "CSR_STVEC: reserved mode not supported\n"); | ||
678 | } | ||
679 | - return 0; | ||
680 | + return RISCV_EXCP_NONE; | ||
681 | } | ||
682 | |||
683 | -static int read_scounteren(CPURISCVState *env, int csrno, target_ulong *val) | ||
684 | +static RISCVException read_scounteren(CPURISCVState *env, int csrno, | ||
685 | + target_ulong *val) | ||
686 | { | ||
687 | *val = env->scounteren; | ||
688 | - return 0; | ||
689 | + return RISCV_EXCP_NONE; | ||
690 | } | ||
691 | |||
692 | -static int write_scounteren(CPURISCVState *env, int csrno, target_ulong val) | ||
693 | +static RISCVException write_scounteren(CPURISCVState *env, int csrno, | ||
694 | + target_ulong val) | ||
695 | { | ||
696 | env->scounteren = val; | ||
697 | - return 0; | ||
698 | + return RISCV_EXCP_NONE; | ||
699 | } | ||
700 | |||
701 | /* Supervisor Trap Handling */ | ||
702 | -static int read_sscratch(CPURISCVState *env, int csrno, target_ulong *val) | ||
703 | +static RISCVException read_sscratch(CPURISCVState *env, int csrno, | ||
704 | + target_ulong *val) | ||
705 | { | ||
706 | *val = env->sscratch; | ||
707 | - return 0; | ||
708 | + return RISCV_EXCP_NONE; | ||
709 | } | ||
710 | |||
711 | -static int write_sscratch(CPURISCVState *env, int csrno, target_ulong val) | ||
712 | +static RISCVException write_sscratch(CPURISCVState *env, int csrno, | ||
713 | + target_ulong val) | ||
714 | { | ||
715 | env->sscratch = val; | ||
716 | - return 0; | ||
717 | + return RISCV_EXCP_NONE; | ||
718 | } | ||
719 | |||
720 | -static int read_sepc(CPURISCVState *env, int csrno, target_ulong *val) | ||
721 | +static RISCVException read_sepc(CPURISCVState *env, int csrno, | ||
722 | + target_ulong *val) | ||
723 | { | ||
724 | *val = env->sepc; | ||
725 | - return 0; | ||
726 | + return RISCV_EXCP_NONE; | ||
727 | } | ||
728 | |||
729 | -static int write_sepc(CPURISCVState *env, int csrno, target_ulong val) | ||
730 | +static RISCVException write_sepc(CPURISCVState *env, int csrno, | ||
731 | + target_ulong val) | ||
732 | { | ||
733 | env->sepc = val; | ||
734 | - return 0; | ||
735 | + return RISCV_EXCP_NONE; | ||
736 | } | ||
737 | |||
738 | -static int read_scause(CPURISCVState *env, int csrno, target_ulong *val) | ||
739 | +static RISCVException read_scause(CPURISCVState *env, int csrno, | ||
740 | + target_ulong *val) | ||
741 | { | ||
742 | *val = env->scause; | ||
743 | - return 0; | ||
744 | + return RISCV_EXCP_NONE; | ||
745 | } | ||
746 | |||
747 | -static int write_scause(CPURISCVState *env, int csrno, target_ulong val) | ||
748 | +static RISCVException write_scause(CPURISCVState *env, int csrno, | ||
749 | + target_ulong val) | ||
750 | { | ||
751 | env->scause = val; | ||
752 | - return 0; | ||
753 | + return RISCV_EXCP_NONE; | ||
754 | } | ||
755 | |||
756 | -static int read_stval(CPURISCVState *env, int csrno, target_ulong *val) | ||
757 | +static RISCVException read_stval(CPURISCVState *env, int csrno, | ||
758 | + target_ulong *val) | ||
759 | { | ||
760 | *val = env->stval; | ||
761 | - return 0; | ||
762 | + return RISCV_EXCP_NONE; | ||
763 | } | ||
764 | |||
765 | -static int write_stval(CPURISCVState *env, int csrno, target_ulong val) | ||
766 | +static RISCVException write_stval(CPURISCVState *env, int csrno, | ||
767 | + target_ulong val) | ||
768 | { | ||
769 | env->stval = val; | ||
770 | - return 0; | ||
771 | + return RISCV_EXCP_NONE; | ||
772 | } | ||
773 | |||
774 | -static int rmw_vsip(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
775 | - target_ulong new_value, target_ulong write_mask) | ||
776 | +static RISCVException rmw_vsip(CPURISCVState *env, int csrno, | ||
777 | + target_ulong *ret_value, | ||
778 | + target_ulong new_value, target_ulong write_mask) | ||
779 | { | ||
780 | /* Shift the S bits to their VS bit location in mip */ | ||
781 | int ret = rmw_mip(env, 0, ret_value, new_value << 1, | ||
782 | @@ -XXX,XX +XXX,XX @@ static int rmw_vsip(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
783 | return ret; | ||
784 | } | ||
785 | |||
786 | -static int rmw_sip(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
787 | - target_ulong new_value, target_ulong write_mask) | ||
788 | +static RISCVException rmw_sip(CPURISCVState *env, int csrno, | ||
789 | + target_ulong *ret_value, | ||
790 | + target_ulong new_value, target_ulong write_mask) | ||
791 | { | ||
792 | int ret; | ||
793 | |||
794 | @@ -XXX,XX +XXX,XX @@ static int rmw_sip(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
795 | } | ||
796 | |||
797 | /* Supervisor Protection and Translation */ | ||
798 | -static int read_satp(CPURISCVState *env, int csrno, target_ulong *val) | ||
799 | +static RISCVException read_satp(CPURISCVState *env, int csrno, | ||
800 | + target_ulong *val) | ||
801 | { | ||
802 | if (!riscv_feature(env, RISCV_FEATURE_MMU)) { | ||
803 | *val = 0; | ||
804 | - return 0; | ||
805 | + return RISCV_EXCP_NONE; | ||
806 | } | ||
807 | |||
808 | if (env->priv == PRV_S && get_field(env->mstatus, MSTATUS_TVM)) { | ||
809 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
810 | + return RISCV_EXCP_ILLEGAL_INST; | ||
811 | } else { | ||
812 | *val = env->satp; | ||
813 | } | ||
814 | |||
815 | - return 0; | ||
816 | + return RISCV_EXCP_NONE; | ||
817 | } | ||
818 | |||
819 | -static int write_satp(CPURISCVState *env, int csrno, target_ulong val) | ||
820 | +static RISCVException write_satp(CPURISCVState *env, int csrno, | ||
821 | + target_ulong val) | ||
822 | { | ||
823 | if (!riscv_feature(env, RISCV_FEATURE_MMU)) { | ||
824 | - return 0; | ||
825 | + return RISCV_EXCP_NONE; | ||
826 | } | ||
827 | if (validate_vm(env, get_field(val, SATP_MODE)) && | ||
828 | ((val ^ env->satp) & (SATP_MODE | SATP_ASID | SATP_PPN))) | ||
829 | { | ||
830 | if (env->priv == PRV_S && get_field(env->mstatus, MSTATUS_TVM)) { | ||
831 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
832 | + return RISCV_EXCP_ILLEGAL_INST; | ||
833 | } else { | ||
834 | if ((val ^ env->satp) & SATP_ASID) { | ||
835 | tlb_flush(env_cpu(env)); | ||
836 | @@ -XXX,XX +XXX,XX @@ static int write_satp(CPURISCVState *env, int csrno, target_ulong val) | ||
837 | env->satp = val; | ||
838 | } | ||
839 | } | ||
840 | - return 0; | ||
841 | + return RISCV_EXCP_NONE; | ||
842 | } | ||
843 | |||
844 | /* Hypervisor Extensions */ | ||
845 | -static int read_hstatus(CPURISCVState *env, int csrno, target_ulong *val) | ||
846 | +static RISCVException read_hstatus(CPURISCVState *env, int csrno, | ||
847 | + target_ulong *val) | ||
848 | { | ||
849 | *val = env->hstatus; | ||
850 | if (!riscv_cpu_is_32bit(env)) { | ||
851 | @@ -XXX,XX +XXX,XX @@ static int read_hstatus(CPURISCVState *env, int csrno, target_ulong *val) | ||
852 | } | ||
853 | /* We only support little endian */ | ||
854 | *val = set_field(*val, HSTATUS_VSBE, 0); | ||
855 | - return 0; | ||
856 | + return RISCV_EXCP_NONE; | ||
857 | } | ||
858 | |||
859 | -static int write_hstatus(CPURISCVState *env, int csrno, target_ulong val) | ||
860 | +static RISCVException write_hstatus(CPURISCVState *env, int csrno, | ||
861 | + target_ulong val) | ||
862 | { | ||
863 | env->hstatus = val; | ||
864 | if (!riscv_cpu_is_32bit(env) && get_field(val, HSTATUS_VSXL) != 2) { | ||
865 | @@ -XXX,XX +XXX,XX @@ static int write_hstatus(CPURISCVState *env, int csrno, target_ulong val) | ||
866 | if (get_field(val, HSTATUS_VSBE) != 0) { | ||
867 | qemu_log_mask(LOG_UNIMP, "QEMU does not support big endian guests."); | ||
868 | } | ||
869 | - return 0; | ||
870 | + return RISCV_EXCP_NONE; | ||
871 | } | ||
872 | |||
873 | -static int read_hedeleg(CPURISCVState *env, int csrno, target_ulong *val) | ||
874 | +static RISCVException read_hedeleg(CPURISCVState *env, int csrno, | ||
875 | + target_ulong *val) | ||
876 | { | ||
877 | *val = env->hedeleg; | ||
878 | - return 0; | ||
879 | + return RISCV_EXCP_NONE; | ||
880 | } | ||
881 | |||
882 | -static int write_hedeleg(CPURISCVState *env, int csrno, target_ulong val) | ||
883 | +static RISCVException write_hedeleg(CPURISCVState *env, int csrno, | ||
884 | + target_ulong val) | ||
885 | { | ||
886 | env->hedeleg = val; | ||
887 | - return 0; | ||
888 | + return RISCV_EXCP_NONE; | ||
889 | } | ||
890 | |||
891 | -static int read_hideleg(CPURISCVState *env, int csrno, target_ulong *val) | ||
892 | +static RISCVException read_hideleg(CPURISCVState *env, int csrno, | ||
893 | + target_ulong *val) | ||
894 | { | ||
895 | *val = env->hideleg; | ||
896 | - return 0; | ||
897 | + return RISCV_EXCP_NONE; | ||
898 | } | ||
899 | |||
900 | -static int write_hideleg(CPURISCVState *env, int csrno, target_ulong val) | ||
901 | +static RISCVException write_hideleg(CPURISCVState *env, int csrno, | ||
902 | + target_ulong val) | ||
903 | { | ||
904 | env->hideleg = val; | ||
905 | - return 0; | ||
906 | + return RISCV_EXCP_NONE; | ||
907 | } | ||
908 | |||
909 | -static int rmw_hvip(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
910 | - target_ulong new_value, target_ulong write_mask) | ||
911 | +static RISCVException rmw_hvip(CPURISCVState *env, int csrno, | ||
912 | + target_ulong *ret_value, | ||
913 | + target_ulong new_value, target_ulong write_mask) | ||
914 | { | ||
915 | int ret = rmw_mip(env, 0, ret_value, new_value, | ||
916 | write_mask & hvip_writable_mask); | ||
917 | @@ -XXX,XX +XXX,XX @@ static int rmw_hvip(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
918 | return ret; | ||
919 | } | ||
920 | |||
921 | -static int rmw_hip(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
922 | - target_ulong new_value, target_ulong write_mask) | ||
923 | +static RISCVException rmw_hip(CPURISCVState *env, int csrno, | ||
924 | + target_ulong *ret_value, | ||
925 | + target_ulong new_value, target_ulong write_mask) | ||
926 | { | ||
927 | int ret = rmw_mip(env, 0, ret_value, new_value, | ||
928 | write_mask & hip_writable_mask); | ||
929 | @@ -XXX,XX +XXX,XX @@ static int rmw_hip(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
930 | return ret; | ||
931 | } | ||
932 | |||
933 | -static int read_hie(CPURISCVState *env, int csrno, target_ulong *val) | ||
934 | +static RISCVException read_hie(CPURISCVState *env, int csrno, | ||
935 | + target_ulong *val) | ||
936 | { | ||
937 | *val = env->mie & VS_MODE_INTERRUPTS; | ||
938 | - return 0; | ||
939 | + return RISCV_EXCP_NONE; | ||
940 | } | ||
941 | |||
942 | -static int write_hie(CPURISCVState *env, int csrno, target_ulong val) | ||
943 | +static RISCVException write_hie(CPURISCVState *env, int csrno, | ||
944 | + target_ulong val) | ||
945 | { | ||
946 | target_ulong newval = (env->mie & ~VS_MODE_INTERRUPTS) | (val & VS_MODE_INTERRUPTS); | ||
947 | return write_mie(env, CSR_MIE, newval); | ||
948 | } | ||
949 | |||
950 | -static int read_hcounteren(CPURISCVState *env, int csrno, target_ulong *val) | ||
951 | +static RISCVException read_hcounteren(CPURISCVState *env, int csrno, | ||
952 | + target_ulong *val) | ||
953 | { | ||
954 | *val = env->hcounteren; | ||
955 | - return 0; | ||
956 | + return RISCV_EXCP_NONE; | ||
957 | } | ||
958 | |||
959 | -static int write_hcounteren(CPURISCVState *env, int csrno, target_ulong val) | ||
960 | +static RISCVException write_hcounteren(CPURISCVState *env, int csrno, | ||
961 | + target_ulong val) | ||
962 | { | ||
963 | env->hcounteren = val; | ||
964 | - return 0; | ||
965 | + return RISCV_EXCP_NONE; | ||
966 | } | ||
967 | |||
968 | -static int read_hgeie(CPURISCVState *env, int csrno, target_ulong *val) | ||
969 | +static RISCVException read_hgeie(CPURISCVState *env, int csrno, | ||
970 | + target_ulong *val) | ||
971 | { | ||
972 | qemu_log_mask(LOG_UNIMP, "No support for a non-zero GEILEN."); | ||
973 | - return 0; | ||
974 | + return RISCV_EXCP_NONE; | ||
975 | } | ||
976 | |||
977 | -static int write_hgeie(CPURISCVState *env, int csrno, target_ulong val) | ||
978 | +static RISCVException write_hgeie(CPURISCVState *env, int csrno, | ||
979 | + target_ulong val) | ||
980 | { | ||
981 | qemu_log_mask(LOG_UNIMP, "No support for a non-zero GEILEN."); | ||
982 | - return 0; | ||
983 | + return RISCV_EXCP_NONE; | ||
984 | } | ||
985 | |||
986 | -static int read_htval(CPURISCVState *env, int csrno, target_ulong *val) | ||
987 | +static RISCVException read_htval(CPURISCVState *env, int csrno, | ||
988 | + target_ulong *val) | ||
989 | { | ||
990 | *val = env->htval; | ||
991 | - return 0; | ||
992 | + return RISCV_EXCP_NONE; | ||
993 | } | ||
994 | |||
995 | -static int write_htval(CPURISCVState *env, int csrno, target_ulong val) | ||
996 | +static RISCVException write_htval(CPURISCVState *env, int csrno, | ||
997 | + target_ulong val) | ||
998 | { | ||
999 | env->htval = val; | ||
1000 | - return 0; | ||
1001 | + return RISCV_EXCP_NONE; | ||
1002 | } | ||
1003 | |||
1004 | -static int read_htinst(CPURISCVState *env, int csrno, target_ulong *val) | ||
1005 | +static RISCVException read_htinst(CPURISCVState *env, int csrno, | ||
1006 | + target_ulong *val) | ||
1007 | { | ||
1008 | *val = env->htinst; | ||
1009 | - return 0; | ||
1010 | + return RISCV_EXCP_NONE; | ||
1011 | } | ||
1012 | |||
1013 | -static int write_htinst(CPURISCVState *env, int csrno, target_ulong val) | ||
1014 | +static RISCVException write_htinst(CPURISCVState *env, int csrno, | ||
1015 | + target_ulong val) | ||
1016 | { | ||
1017 | - return 0; | ||
1018 | + return RISCV_EXCP_NONE; | ||
1019 | } | ||
1020 | |||
1021 | -static int read_hgeip(CPURISCVState *env, int csrno, target_ulong *val) | ||
1022 | +static RISCVException read_hgeip(CPURISCVState *env, int csrno, | ||
1023 | + target_ulong *val) | ||
1024 | { | ||
1025 | qemu_log_mask(LOG_UNIMP, "No support for a non-zero GEILEN."); | ||
1026 | - return 0; | ||
1027 | + return RISCV_EXCP_NONE; | ||
1028 | } | ||
1029 | |||
1030 | -static int write_hgeip(CPURISCVState *env, int csrno, target_ulong val) | ||
1031 | +static RISCVException write_hgeip(CPURISCVState *env, int csrno, | ||
1032 | + target_ulong val) | ||
1033 | { | ||
1034 | qemu_log_mask(LOG_UNIMP, "No support for a non-zero GEILEN."); | ||
1035 | - return 0; | ||
1036 | + return RISCV_EXCP_NONE; | ||
1037 | } | ||
1038 | |||
1039 | -static int read_hgatp(CPURISCVState *env, int csrno, target_ulong *val) | ||
1040 | +static RISCVException read_hgatp(CPURISCVState *env, int csrno, | ||
1041 | + target_ulong *val) | ||
1042 | { | ||
1043 | *val = env->hgatp; | ||
1044 | - return 0; | ||
1045 | + return RISCV_EXCP_NONE; | ||
1046 | } | ||
1047 | |||
1048 | -static int write_hgatp(CPURISCVState *env, int csrno, target_ulong val) | ||
1049 | +static RISCVException write_hgatp(CPURISCVState *env, int csrno, | ||
1050 | + target_ulong val) | ||
1051 | { | ||
1052 | env->hgatp = val; | ||
1053 | - return 0; | ||
1054 | + return RISCV_EXCP_NONE; | ||
1055 | } | ||
1056 | |||
1057 | -static int read_htimedelta(CPURISCVState *env, int csrno, target_ulong *val) | ||
1058 | +static RISCVException read_htimedelta(CPURISCVState *env, int csrno, | ||
1059 | + target_ulong *val) | ||
1060 | { | ||
1061 | if (!env->rdtime_fn) { | ||
1062 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
1063 | + return RISCV_EXCP_ILLEGAL_INST; | ||
1064 | } | ||
1065 | |||
1066 | *val = env->htimedelta; | ||
1067 | - return 0; | ||
1068 | + return RISCV_EXCP_NONE; | ||
1069 | } | ||
1070 | |||
1071 | -static int write_htimedelta(CPURISCVState *env, int csrno, target_ulong val) | ||
1072 | +static RISCVException write_htimedelta(CPURISCVState *env, int csrno, | ||
1073 | + target_ulong val) | ||
1074 | { | ||
1075 | if (!env->rdtime_fn) { | ||
1076 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
1077 | + return RISCV_EXCP_ILLEGAL_INST; | ||
1078 | } | ||
1079 | |||
1080 | if (riscv_cpu_is_32bit(env)) { | ||
1081 | @@ -XXX,XX +XXX,XX @@ static int write_htimedelta(CPURISCVState *env, int csrno, target_ulong val) | ||
1082 | } else { | ||
1083 | env->htimedelta = val; | ||
1084 | } | ||
1085 | - return 0; | ||
1086 | + return RISCV_EXCP_NONE; | ||
1087 | } | ||
1088 | |||
1089 | -static int read_htimedeltah(CPURISCVState *env, int csrno, target_ulong *val) | ||
1090 | +static RISCVException read_htimedeltah(CPURISCVState *env, int csrno, | ||
1091 | + target_ulong *val) | ||
1092 | { | ||
1093 | if (!env->rdtime_fn) { | ||
1094 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
1095 | + return RISCV_EXCP_ILLEGAL_INST; | ||
1096 | } | ||
1097 | |||
1098 | *val = env->htimedelta >> 32; | ||
1099 | - return 0; | ||
1100 | + return RISCV_EXCP_NONE; | ||
1101 | } | ||
1102 | |||
1103 | -static int write_htimedeltah(CPURISCVState *env, int csrno, target_ulong val) | ||
1104 | +static RISCVException write_htimedeltah(CPURISCVState *env, int csrno, | ||
1105 | + target_ulong val) | ||
1106 | { | ||
1107 | if (!env->rdtime_fn) { | ||
1108 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
1109 | + return RISCV_EXCP_ILLEGAL_INST; | ||
1110 | } | ||
1111 | |||
1112 | env->htimedelta = deposit64(env->htimedelta, 32, 32, (uint64_t)val); | ||
1113 | - return 0; | ||
1114 | + return RISCV_EXCP_NONE; | ||
1115 | } | ||
1116 | |||
1117 | /* Virtual CSR Registers */ | ||
1118 | -static int read_vsstatus(CPURISCVState *env, int csrno, target_ulong *val) | ||
1119 | +static RISCVException read_vsstatus(CPURISCVState *env, int csrno, | ||
1120 | + target_ulong *val) | ||
1121 | { | ||
1122 | *val = env->vsstatus; | ||
1123 | - return 0; | ||
1124 | + return RISCV_EXCP_NONE; | ||
1125 | } | ||
1126 | |||
1127 | -static int write_vsstatus(CPURISCVState *env, int csrno, target_ulong val) | ||
1128 | +static RISCVException write_vsstatus(CPURISCVState *env, int csrno, | ||
1129 | + target_ulong val) | ||
1130 | { | ||
1131 | uint64_t mask = (target_ulong)-1; | ||
1132 | env->vsstatus = (env->vsstatus & ~mask) | (uint64_t)val; | ||
1133 | - return 0; | ||
1134 | + return RISCV_EXCP_NONE; | ||
1135 | } | ||
1136 | |||
1137 | static int read_vstvec(CPURISCVState *env, int csrno, target_ulong *val) | ||
1138 | { | ||
1139 | *val = env->vstvec; | ||
1140 | - return 0; | ||
1141 | + return RISCV_EXCP_NONE; | ||
1142 | } | ||
1143 | |||
1144 | -static int write_vstvec(CPURISCVState *env, int csrno, target_ulong val) | ||
1145 | +static RISCVException write_vstvec(CPURISCVState *env, int csrno, | ||
1146 | + target_ulong val) | ||
1147 | { | ||
1148 | env->vstvec = val; | ||
1149 | - return 0; | ||
1150 | + return RISCV_EXCP_NONE; | ||
1151 | } | ||
1152 | |||
1153 | -static int read_vsscratch(CPURISCVState *env, int csrno, target_ulong *val) | ||
1154 | +static RISCVException read_vsscratch(CPURISCVState *env, int csrno, | ||
1155 | + target_ulong *val) | ||
1156 | { | ||
1157 | *val = env->vsscratch; | ||
1158 | - return 0; | ||
1159 | + return RISCV_EXCP_NONE; | ||
1160 | } | ||
1161 | |||
1162 | -static int write_vsscratch(CPURISCVState *env, int csrno, target_ulong val) | ||
1163 | +static RISCVException write_vsscratch(CPURISCVState *env, int csrno, | ||
1164 | + target_ulong val) | ||
1165 | { | ||
1166 | env->vsscratch = val; | ||
1167 | - return 0; | ||
1168 | + return RISCV_EXCP_NONE; | ||
1169 | } | ||
1170 | |||
1171 | -static int read_vsepc(CPURISCVState *env, int csrno, target_ulong *val) | ||
1172 | +static RISCVException read_vsepc(CPURISCVState *env, int csrno, | ||
1173 | + target_ulong *val) | ||
1174 | { | ||
1175 | *val = env->vsepc; | ||
1176 | - return 0; | ||
1177 | + return RISCV_EXCP_NONE; | ||
1178 | } | ||
1179 | |||
1180 | -static int write_vsepc(CPURISCVState *env, int csrno, target_ulong val) | ||
1181 | +static RISCVException write_vsepc(CPURISCVState *env, int csrno, | ||
1182 | + target_ulong val) | ||
1183 | { | ||
1184 | env->vsepc = val; | ||
1185 | - return 0; | ||
1186 | + return RISCV_EXCP_NONE; | ||
1187 | } | ||
1188 | |||
1189 | -static int read_vscause(CPURISCVState *env, int csrno, target_ulong *val) | ||
1190 | +static RISCVException read_vscause(CPURISCVState *env, int csrno, | ||
1191 | + target_ulong *val) | ||
1192 | { | ||
1193 | *val = env->vscause; | ||
1194 | - return 0; | ||
1195 | + return RISCV_EXCP_NONE; | ||
1196 | } | ||
1197 | |||
1198 | -static int write_vscause(CPURISCVState *env, int csrno, target_ulong val) | ||
1199 | +static RISCVException write_vscause(CPURISCVState *env, int csrno, | ||
1200 | + target_ulong val) | ||
1201 | { | ||
1202 | env->vscause = val; | ||
1203 | - return 0; | ||
1204 | + return RISCV_EXCP_NONE; | ||
1205 | } | ||
1206 | |||
1207 | -static int read_vstval(CPURISCVState *env, int csrno, target_ulong *val) | ||
1208 | +static RISCVException read_vstval(CPURISCVState *env, int csrno, | ||
1209 | + target_ulong *val) | ||
1210 | { | ||
1211 | *val = env->vstval; | ||
1212 | - return 0; | ||
1213 | + return RISCV_EXCP_NONE; | ||
1214 | } | ||
1215 | |||
1216 | -static int write_vstval(CPURISCVState *env, int csrno, target_ulong val) | ||
1217 | +static RISCVException write_vstval(CPURISCVState *env, int csrno, | ||
1218 | + target_ulong val) | ||
1219 | { | ||
1220 | env->vstval = val; | ||
1221 | - return 0; | ||
1222 | + return RISCV_EXCP_NONE; | ||
1223 | } | ||
1224 | |||
1225 | -static int read_vsatp(CPURISCVState *env, int csrno, target_ulong *val) | ||
1226 | +static RISCVException read_vsatp(CPURISCVState *env, int csrno, | ||
1227 | + target_ulong *val) | ||
1228 | { | ||
1229 | *val = env->vsatp; | ||
1230 | - return 0; | ||
1231 | + return RISCV_EXCP_NONE; | ||
1232 | } | ||
1233 | |||
1234 | -static int write_vsatp(CPURISCVState *env, int csrno, target_ulong val) | ||
1235 | +static RISCVException write_vsatp(CPURISCVState *env, int csrno, | ||
1236 | + target_ulong val) | ||
1237 | { | ||
1238 | env->vsatp = val; | ||
1239 | - return 0; | ||
1240 | + return RISCV_EXCP_NONE; | ||
1241 | } | ||
1242 | |||
1243 | -static int read_mtval2(CPURISCVState *env, int csrno, target_ulong *val) | ||
1244 | +static RISCVException read_mtval2(CPURISCVState *env, int csrno, | ||
1245 | + target_ulong *val) | ||
1246 | { | ||
1247 | *val = env->mtval2; | ||
1248 | - return 0; | ||
1249 | + return RISCV_EXCP_NONE; | ||
1250 | } | ||
1251 | |||
1252 | -static int write_mtval2(CPURISCVState *env, int csrno, target_ulong val) | ||
1253 | +static RISCVException write_mtval2(CPURISCVState *env, int csrno, | ||
1254 | + target_ulong val) | ||
1255 | { | ||
1256 | env->mtval2 = val; | ||
1257 | - return 0; | ||
1258 | + return RISCV_EXCP_NONE; | ||
1259 | } | ||
1260 | |||
1261 | -static int read_mtinst(CPURISCVState *env, int csrno, target_ulong *val) | ||
1262 | +static RISCVException read_mtinst(CPURISCVState *env, int csrno, | ||
1263 | + target_ulong *val) | ||
1264 | { | ||
1265 | *val = env->mtinst; | ||
1266 | - return 0; | ||
1267 | + return RISCV_EXCP_NONE; | ||
1268 | } | ||
1269 | |||
1270 | -static int write_mtinst(CPURISCVState *env, int csrno, target_ulong val) | ||
1271 | +static RISCVException write_mtinst(CPURISCVState *env, int csrno, | ||
1272 | + target_ulong val) | ||
1273 | { | ||
1274 | env->mtinst = val; | ||
1275 | - return 0; | ||
1276 | + return RISCV_EXCP_NONE; | ||
1277 | } | ||
1278 | |||
1279 | /* Physical Memory Protection */ | ||
1280 | -static int read_pmpcfg(CPURISCVState *env, int csrno, target_ulong *val) | ||
1281 | +static RISCVException read_pmpcfg(CPURISCVState *env, int csrno, | ||
1282 | + target_ulong *val) | ||
1283 | { | ||
1284 | *val = pmpcfg_csr_read(env, csrno - CSR_PMPCFG0); | ||
1285 | - return 0; | ||
1286 | + return RISCV_EXCP_NONE; | ||
1287 | } | ||
1288 | |||
1289 | -static int write_pmpcfg(CPURISCVState *env, int csrno, target_ulong val) | ||
1290 | +static RISCVException write_pmpcfg(CPURISCVState *env, int csrno, | ||
1291 | + target_ulong val) | ||
1292 | { | ||
1293 | pmpcfg_csr_write(env, csrno - CSR_PMPCFG0, val); | ||
1294 | - return 0; | ||
1295 | + return RISCV_EXCP_NONE; | ||
1296 | } | ||
1297 | |||
1298 | -static int read_pmpaddr(CPURISCVState *env, int csrno, target_ulong *val) | ||
1299 | +static RISCVException read_pmpaddr(CPURISCVState *env, int csrno, | ||
1300 | + target_ulong *val) | ||
1301 | { | ||
1302 | *val = pmpaddr_csr_read(env, csrno - CSR_PMPADDR0); | ||
1303 | - return 0; | ||
1304 | + return RISCV_EXCP_NONE; | ||
1305 | } | ||
1306 | |||
1307 | -static int write_pmpaddr(CPURISCVState *env, int csrno, target_ulong val) | ||
1308 | +static RISCVException write_pmpaddr(CPURISCVState *env, int csrno, | ||
1309 | + target_ulong val) | ||
1310 | { | ||
1311 | pmpaddr_csr_write(env, csrno - CSR_PMPADDR0, val); | ||
1312 | - return 0; | ||
1313 | + return RISCV_EXCP_NONE; | ||
1314 | } | ||
1315 | |||
1316 | #endif | ||
1317 | @@ -XXX,XX +XXX,XX @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
1318 | |||
1319 | /* execute combined read/write operation if it exists */ | ||
1320 | if (csr_ops[csrno].op) { | ||
1321 | - return csr_ops[csrno].op(env, csrno, ret_value, new_value, write_mask); | ||
1322 | + ret = csr_ops[csrno].op(env, csrno, ret_value, new_value, write_mask); | ||
1323 | + if (ret != RISCV_EXCP_NONE) { | ||
1324 | + return -ret; | ||
108 | + } | 1325 | + } |
109 | + } | 1326 | + return 0; |
110 | +} | 1327 | } |
111 | + | 1328 | |
112 | +void riscv_iommu_hpm_incr_ctr(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, | 1329 | /* if no accessor exists then return failure */ |
113 | + unsigned event_id) | 1330 | if (!csr_ops[csrno].read) { |
114 | +{ | 1331 | return -RISCV_EXCP_ILLEGAL_INST; |
115 | + const uint32_t inhibit = riscv_iommu_reg_get32( | 1332 | } |
116 | + s, RISCV_IOMMU_REG_IOCOUNTINH); | ||
117 | + uint32_t did_gscid; | ||
118 | + uint32_t pid_pscid; | ||
119 | + uint32_t ctr_idx; | ||
120 | + gpointer value; | ||
121 | + uint32_t ctrs; | ||
122 | + uint64_t evt; | ||
123 | + | ||
124 | + if (!(s->cap & RISCV_IOMMU_CAP_HPM)) { | ||
125 | + return; | ||
126 | + } | ||
127 | + | ||
128 | + value = g_hash_table_lookup(s->hpm_event_ctr_map, | ||
129 | + GUINT_TO_POINTER(event_id)); | ||
130 | + if (value == NULL) { | ||
131 | + return; | ||
132 | + } | ||
133 | + | ||
134 | + for (ctrs = GPOINTER_TO_UINT(value); ctrs != 0; ctrs &= ctrs - 1) { | ||
135 | + ctr_idx = ctz32(ctrs); | ||
136 | + if (get_field(inhibit, BIT(ctr_idx + 1))) { | ||
137 | + continue; | ||
138 | + } | ||
139 | + | ||
140 | + evt = riscv_iommu_reg_get64(s, | ||
141 | + RISCV_IOMMU_REG_IOHPMEVT_BASE + (ctr_idx << 3)); | ||
142 | + | ||
143 | + /* | ||
144 | + * It's quite possible that event ID has been changed in counter | ||
145 | + * but hashtable hasn't been updated yet. We don't want to increment | ||
146 | + * counter for the old event ID. | ||
147 | + */ | ||
148 | + if (event_id != get_field(evt, RISCV_IOMMU_IOHPMEVT_EVENT_ID)) { | ||
149 | + continue; | ||
150 | + } | ||
151 | + | ||
152 | + if (get_field(evt, RISCV_IOMMU_IOHPMEVT_IDT)) { | ||
153 | + did_gscid = get_field(ctx->gatp, RISCV_IOMMU_DC_IOHGATP_GSCID); | ||
154 | + pid_pscid = get_field(ctx->ta, RISCV_IOMMU_DC_TA_PSCID); | ||
155 | + } else { | ||
156 | + did_gscid = ctx->devid; | ||
157 | + pid_pscid = ctx->process_id; | ||
158 | + } | ||
159 | + | ||
160 | + if (get_field(evt, RISCV_IOMMU_IOHPMEVT_PV_PSCV)) { | ||
161 | + /* | ||
162 | + * If the transaction does not have a valid process_id, counter | ||
163 | + * increments if device_id matches DID_GSCID. If the transaction | ||
164 | + * has a valid process_id, counter increments if device_id | ||
165 | + * matches DID_GSCID and process_id matches PID_PSCID. See | ||
166 | + * IOMMU Specification, Chapter 5.23. Performance-monitoring | ||
167 | + * event selector. | ||
168 | + */ | ||
169 | + if (ctx->process_id && | ||
170 | + get_field(evt, RISCV_IOMMU_IOHPMEVT_PID_PSCID) != pid_pscid) { | ||
171 | + continue; | ||
172 | + } | ||
173 | + } | ||
174 | + | ||
175 | + if (get_field(evt, RISCV_IOMMU_IOHPMEVT_DV_GSCV)) { | ||
176 | + uint32_t mask = ~0; | ||
177 | + | ||
178 | + if (get_field(evt, RISCV_IOMMU_IOHPMEVT_DMASK)) { | ||
179 | + /* | ||
180 | + * 1001 1011 mask = GSCID | ||
181 | + * 0000 0111 mask = mask ^ (mask + 1) | ||
182 | + * 1111 1000 mask = ~mask; | ||
183 | + */ | ||
184 | + mask = get_field(evt, RISCV_IOMMU_IOHPMEVT_DID_GSCID); | ||
185 | + mask = mask ^ (mask + 1); | ||
186 | + mask = ~mask; | ||
187 | + } | ||
188 | + | ||
189 | + if ((get_field(evt, RISCV_IOMMU_IOHPMEVT_DID_GSCID) & mask) != | ||
190 | + (did_gscid & mask)) { | ||
191 | + continue; | ||
192 | + } | ||
193 | + } | ||
194 | + | ||
195 | + hpm_incr_ctr(s, ctr_idx); | ||
196 | + } | ||
197 | +} | ||
198 | diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c | ||
199 | index XXXXXXX..XXXXXXX 100644 | ||
200 | --- a/hw/riscv/riscv-iommu.c | ||
201 | +++ b/hw/riscv/riscv-iommu.c | ||
202 | @@ -XXX,XX +XXX,XX @@ | ||
203 | #define PPN_PHYS(ppn) ((ppn) << TARGET_PAGE_BITS) | ||
204 | #define PPN_DOWN(phy) ((phy) >> TARGET_PAGE_BITS) | ||
205 | |||
206 | -typedef struct RISCVIOMMUContext RISCVIOMMUContext; | ||
207 | typedef struct RISCVIOMMUEntry RISCVIOMMUEntry; | ||
208 | |||
209 | /* Device assigned I/O address space */ | ||
210 | @@ -XXX,XX +XXX,XX @@ struct RISCVIOMMUSpace { | ||
211 | QLIST_ENTRY(RISCVIOMMUSpace) list; | ||
212 | }; | ||
213 | |||
214 | -/* Device translation context state. */ | ||
215 | -struct RISCVIOMMUContext { | ||
216 | - uint64_t devid:24; /* Requester Id, AKA device_id */ | ||
217 | - uint64_t process_id:20; /* Process ID. PASID for PCIe */ | ||
218 | - uint64_t tc; /* Translation Control */ | ||
219 | - uint64_t ta; /* Translation Attributes */ | ||
220 | - uint64_t satp; /* S-Stage address translation and protection */ | ||
221 | - uint64_t gatp; /* G-Stage address translation and protection */ | ||
222 | - uint64_t msi_addr_mask; /* MSI filtering - address mask */ | ||
223 | - uint64_t msi_addr_pattern; /* MSI filtering - address pattern */ | ||
224 | - uint64_t msiptp; /* MSI redirection page table pointer */ | ||
225 | -}; | ||
226 | - | 1333 | - |
227 | typedef enum RISCVIOMMUTransTag { | 1334 | /* read old value */ |
228 | RISCV_IOMMU_TRANS_TAG_BY, /* Bypass */ | 1335 | ret = csr_ops[csrno].read(env, csrno, &old_value); |
229 | RISCV_IOMMU_TRANS_TAG_SS, /* Single Stage */ | 1336 | - if (ret < 0) { |
230 | @@ -XXX,XX +XXX,XX @@ static uint8_t riscv_iommu_get_icvec_vector(uint32_t icvec, uint32_t vec_type) | 1337 | - return ret; |
231 | } | 1338 | + if (ret != RISCV_EXCP_NONE) { |
232 | } | 1339 | + return -ret; |
233 | 1340 | } | |
234 | -static void riscv_iommu_notify(RISCVIOMMUState *s, int vec_type) | 1341 | |
235 | +void riscv_iommu_notify(RISCVIOMMUState *s, int vec_type) | 1342 | /* write value if writable and write mask set, otherwise drop writes */ |
236 | { | 1343 | @@ -XXX,XX +XXX,XX @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, |
237 | uint32_t ipsr, icvec, vector; | 1344 | new_value = (old_value & ~write_mask) | (new_value & write_mask); |
238 | 1345 | if (csr_ops[csrno].write) { | |
239 | @@ -XXX,XX +XXX,XX @@ static int riscv_iommu_spa_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, | 1346 | ret = csr_ops[csrno].write(env, csrno, new_value); |
1347 | - if (ret < 0) { | ||
1348 | - return ret; | ||
1349 | + if (ret != RISCV_EXCP_NONE) { | ||
1350 | + return -ret; | ||
240 | } | 1351 | } |
241 | } | 1352 | } |
242 | 1353 | } | |
243 | + | ||
244 | + if (pass == S_STAGE) { | ||
245 | + riscv_iommu_hpm_incr_ctr(s, ctx, RISCV_IOMMU_HPMEVENT_S_VS_WALKS); | ||
246 | + } else { | ||
247 | + riscv_iommu_hpm_incr_ctr(s, ctx, RISCV_IOMMU_HPMEVENT_G_WALKS); | ||
248 | + } | ||
249 | + | ||
250 | /* Read page table entry */ | ||
251 | if (sc[pass].ptesize == 4) { | ||
252 | uint32_t pte32 = 0; | ||
253 | @@ -XXX,XX +XXX,XX @@ static int riscv_iommu_ctx_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx) | ||
254 | |||
255 | /* Device directory tree walk */ | ||
256 | for (; depth-- > 0; ) { | ||
257 | + riscv_iommu_hpm_incr_ctr(s, ctx, RISCV_IOMMU_HPMEVENT_DD_WALK); | ||
258 | /* | ||
259 | * Select device id index bits based on device directory tree level | ||
260 | * and device context format. | ||
261 | @@ -XXX,XX +XXX,XX @@ static int riscv_iommu_ctx_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx) | ||
262 | addr = PPN_PHYS(get_field(de, RISCV_IOMMU_DDTE_PPN)); | ||
263 | } | ||
264 | |||
265 | + riscv_iommu_hpm_incr_ctr(s, ctx, RISCV_IOMMU_HPMEVENT_DD_WALK); | ||
266 | + | ||
267 | /* index into device context entry page */ | ||
268 | addr |= (ctx->devid * dc_len) & ~TARGET_PAGE_MASK; | ||
269 | |||
270 | @@ -XXX,XX +XXX,XX @@ static int riscv_iommu_ctx_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx) | ||
271 | } | ||
272 | |||
273 | for (depth = mode - RISCV_IOMMU_DC_FSC_PDTP_MODE_PD8; depth-- > 0; ) { | ||
274 | + riscv_iommu_hpm_incr_ctr(s, ctx, RISCV_IOMMU_HPMEVENT_PD_WALK); | ||
275 | + | ||
276 | /* | ||
277 | * Select process id index bits based on process directory tree | ||
278 | * level. See IOMMU Specification, 2.2. Process-Directory-Table. | ||
279 | @@ -XXX,XX +XXX,XX @@ static int riscv_iommu_ctx_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx) | ||
280 | addr = PPN_PHYS(get_field(de, RISCV_IOMMU_PC_FSC_PPN)); | ||
281 | } | ||
282 | |||
283 | + riscv_iommu_hpm_incr_ctr(s, ctx, RISCV_IOMMU_HPMEVENT_PD_WALK); | ||
284 | + | ||
285 | /* Leaf entry in PDT */ | ||
286 | addr |= (ctx->process_id << 4) & ~TARGET_PAGE_MASK; | ||
287 | if (dma_memory_read(s->target_as, addr, &dc.ta, sizeof(uint64_t) * 2, | ||
288 | @@ -XXX,XX +XXX,XX @@ static int riscv_iommu_translate(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, | ||
289 | GHashTable *iot_cache; | ||
290 | int fault; | ||
291 | |||
292 | + riscv_iommu_hpm_incr_ctr(s, ctx, RISCV_IOMMU_HPMEVENT_URQ); | ||
293 | + | ||
294 | iot_cache = g_hash_table_ref(s->iot_cache); | ||
295 | /* | ||
296 | * TC[32] is reserved for custom extensions, used here to temporarily | ||
297 | @@ -XXX,XX +XXX,XX @@ static int riscv_iommu_translate(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, | ||
298 | |||
299 | /* Check for ATS request. */ | ||
300 | if (iotlb->perm == IOMMU_NONE) { | ||
301 | + riscv_iommu_hpm_incr_ctr(s, ctx, RISCV_IOMMU_HPMEVENT_ATS_RQ); | ||
302 | /* Check if ATS is disabled. */ | ||
303 | if (!(ctx->tc & RISCV_IOMMU_DC_TC_EN_ATS)) { | ||
304 | enable_pri = false; | ||
305 | @@ -XXX,XX +XXX,XX @@ static int riscv_iommu_translate(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, | ||
306 | goto done; | ||
307 | } | ||
308 | |||
309 | + riscv_iommu_hpm_incr_ctr(s, ctx, RISCV_IOMMU_HPMEVENT_TLB_MISS); | ||
310 | + | ||
311 | /* Translate using device directory / page table information. */ | ||
312 | fault = riscv_iommu_spa_fetch(s, ctx, iotlb); | ||
313 | |||
314 | @@ -XXX,XX +XXX,XX @@ static void riscv_iommu_realize(DeviceState *dev, Error **errp) | ||
315 | memory_region_init_io(&s->trap_mr, OBJECT(dev), &riscv_iommu_trap_ops, s, | ||
316 | "riscv-iommu-trap", ~0ULL); | ||
317 | address_space_init(&s->trap_as, &s->trap_mr, "riscv-iommu-trap-as"); | ||
318 | + | ||
319 | + if (s->cap & RISCV_IOMMU_CAP_HPM) { | ||
320 | + s->hpm_event_ctr_map = g_hash_table_new(g_direct_hash, g_direct_equal); | ||
321 | + } | ||
322 | } | ||
323 | |||
324 | static void riscv_iommu_unrealize(DeviceState *dev) | ||
325 | @@ -XXX,XX +XXX,XX @@ static void riscv_iommu_unrealize(DeviceState *dev) | ||
326 | |||
327 | g_hash_table_unref(s->iot_cache); | ||
328 | g_hash_table_unref(s->ctx_cache); | ||
329 | + | ||
330 | + if (s->cap & RISCV_IOMMU_CAP_HPM) { | ||
331 | + g_hash_table_unref(s->hpm_event_ctr_map); | ||
332 | + } | ||
333 | } | ||
334 | |||
335 | void riscv_iommu_reset(RISCVIOMMUState *s) | ||
336 | -- | 1354 | -- |
337 | 2.48.1 | 1355 | 2.31.1 |
1356 | |||
1357 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
---|---|---|---|
2 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
3 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
4 | Message-id: 302b208f40373557fa11b351b5c9f43039ca8ea3.1617290165.git.alistair.francis@wdc.com | ||
5 | --- | ||
6 | target/riscv/cpu.h | 11 +++++++---- | ||
7 | target/riscv/csr.c | 37 ++++++++++++++++++------------------- | ||
8 | target/riscv/gdbstub.c | 8 ++++---- | ||
9 | target/riscv/op_helper.c | 18 +++++++++--------- | ||
10 | 4 files changed, 38 insertions(+), 36 deletions(-) | ||
2 | 11 | ||
3 | Coverity found a DEADCODE issue in rmw_xiregi() claiming that we can't | 12 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
4 | reach 'RISCV_EXCP_VIRT_INSTRUCTION_FAULT' at the 'done' label: | 13 | index XXXXXXX..XXXXXXX 100644 |
5 | 14 | --- a/target/riscv/cpu.h | |
6 | > 2652 done: | 15 | +++ b/target/riscv/cpu.h |
7 | >>>> CID 1590357: Control flow issues (DEADCODE) | 16 | @@ -XXX,XX +XXX,XX @@ static inline void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, |
8 | >>>> Execution cannot reach the expression "RISCV_EXCP_VIRT_INSTRUCTION_FAULT" | 17 | *pflags = flags; |
9 | inside this statement: "return (env->virt_enabled &...". | 18 | } |
10 | > 2653 return (env->virt_enabled && virt) ? | 19 | |
11 | > 2654 RISCV_EXCP_VIRT_INSTRUCTION_FAULT : RISCV_EXCP_ILLEGAL_INST; | 20 | -int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, |
12 | 21 | - target_ulong new_value, target_ulong write_mask); | |
13 | This happens because 'virt' is being set to 'false' and it will remain | 22 | -int riscv_csrrw_debug(CPURISCVState *env, int csrno, target_ulong *ret_value, |
14 | as 'false' in any code path where 'done' will be called. The label can | 23 | - target_ulong new_value, target_ulong write_mask); |
15 | be safely reduced to: | 24 | +RISCVException riscv_csrrw(CPURISCVState *env, int csrno, |
16 | 25 | + target_ulong *ret_value, | |
17 | done: | 26 | + target_ulong new_value, target_ulong write_mask); |
18 | return RISCV_EXCP_ILLEGAL_INST; | 27 | +RISCVException riscv_csrrw_debug(CPURISCVState *env, int csrno, |
19 | 28 | + target_ulong *ret_value, | |
20 | And that will leave us with the following usage of a 'goto' skipping a | 29 | + target_ulong new_value, |
21 | single 'return' to do another single 'return': | 30 | + target_ulong write_mask); |
22 | 31 | ||
23 | } else { | 32 | static inline void riscv_csr_write(CPURISCVState *env, int csrno, |
24 | goto done; | 33 | target_ulong val) |
25 | } | ||
26 | |||
27 | return rmw_xireg_csrind(env, csrno, isel, val, new_val, wr_mask); | ||
28 | |||
29 | done: | ||
30 | return RISCV_EXCP_ILLEGAL_INST; | ||
31 | |||
32 | Which we will eliminate it and just do 'return RISCV_EXCP_ILLEGAL_INST' | ||
33 | instead. | ||
34 | |||
35 | Resolves: Coverity CID 1590357 | ||
36 | Fixes: 5e33a20827 ("target/riscv: Support generic CSR indirect access") | ||
37 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
38 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
39 | Message-ID: <20250121184847.2109128-4-dbarboza@ventanamicro.com> | ||
40 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
41 | --- | ||
42 | target/riscv/csr.c | 8 +------- | ||
43 | 1 file changed, 1 insertion(+), 7 deletions(-) | ||
44 | |||
45 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 34 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
46 | index XXXXXXX..XXXXXXX 100644 | 35 | index XXXXXXX..XXXXXXX 100644 |
47 | --- a/target/riscv/csr.c | 36 | --- a/target/riscv/csr.c |
48 | +++ b/target/riscv/csr.c | 37 | +++ b/target/riscv/csr.c |
49 | @@ -XXX,XX +XXX,XX @@ static int rmw_xireg_csrind(CPURISCVState *env, int csrno, | 38 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_pmpaddr(CPURISCVState *env, int csrno, |
50 | static int rmw_xiregi(CPURISCVState *env, int csrno, target_ulong *val, | 39 | * csrrc <-> riscv_csrrw(env, csrno, ret_value, 0, value); |
51 | target_ulong new_val, target_ulong wr_mask) | 40 | */ |
52 | { | 41 | |
53 | - bool virt = false; | 42 | -int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, |
54 | int ret = -EINVAL; | 43 | - target_ulong new_value, target_ulong write_mask) |
55 | target_ulong isel; | 44 | +RISCVException riscv_csrrw(CPURISCVState *env, int csrno, |
56 | 45 | + target_ulong *ret_value, | |
57 | @@ -XXX,XX +XXX,XX @@ static int rmw_xiregi(CPURISCVState *env, int csrno, target_ulong *val, | 46 | + target_ulong new_value, target_ulong write_mask) |
58 | } else if (CSR_VSIREG <= csrno && csrno <= CSR_VSIREG6 && | 47 | { |
59 | csrno != CSR_VSIREG4 - 1) { | 48 | - int ret; |
60 | isel = env->vsiselect; | 49 | + RISCVException ret; |
61 | - virt = true; | 50 | target_ulong old_value; |
62 | } else { | 51 | RISCVCPU *cpu = env_archcpu(env); |
63 | - goto done; | 52 | |
64 | + return RISCV_EXCP_ILLEGAL_INST; | 53 | @@ -XXX,XX +XXX,XX @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, |
65 | } | 54 | |
66 | 55 | if ((write_mask && read_only) || | |
67 | return rmw_xireg_csrind(env, csrno, isel, val, new_val, wr_mask); | 56 | (!env->debugger && (effective_priv < get_field(csrno, 0x300)))) { |
68 | - | 57 | - return -RISCV_EXCP_ILLEGAL_INST; |
69 | -done: | 58 | + return RISCV_EXCP_ILLEGAL_INST; |
70 | - return (env->virt_enabled && virt) ? | 59 | } |
71 | - RISCV_EXCP_VIRT_INSTRUCTION_FAULT : RISCV_EXCP_ILLEGAL_INST; | 60 | #endif |
72 | } | 61 | |
73 | 62 | /* ensure the CSR extension is enabled. */ | |
74 | static RISCVException rmw_xireg(CPURISCVState *env, int csrno, | 63 | if (!cpu->cfg.ext_icsr) { |
64 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
65 | + return RISCV_EXCP_ILLEGAL_INST; | ||
66 | } | ||
67 | |||
68 | /* check predicate */ | ||
69 | if (!csr_ops[csrno].predicate) { | ||
70 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
71 | + return RISCV_EXCP_ILLEGAL_INST; | ||
72 | } | ||
73 | ret = csr_ops[csrno].predicate(env, csrno); | ||
74 | if (ret != RISCV_EXCP_NONE) { | ||
75 | - return -ret; | ||
76 | + return ret; | ||
77 | } | ||
78 | |||
79 | /* execute combined read/write operation if it exists */ | ||
80 | if (csr_ops[csrno].op) { | ||
81 | - ret = csr_ops[csrno].op(env, csrno, ret_value, new_value, write_mask); | ||
82 | - if (ret != RISCV_EXCP_NONE) { | ||
83 | - return -ret; | ||
84 | - } | ||
85 | - return 0; | ||
86 | + return csr_ops[csrno].op(env, csrno, ret_value, new_value, write_mask); | ||
87 | } | ||
88 | |||
89 | /* if no accessor exists then return failure */ | ||
90 | if (!csr_ops[csrno].read) { | ||
91 | - return -RISCV_EXCP_ILLEGAL_INST; | ||
92 | + return RISCV_EXCP_ILLEGAL_INST; | ||
93 | } | ||
94 | /* read old value */ | ||
95 | ret = csr_ops[csrno].read(env, csrno, &old_value); | ||
96 | if (ret != RISCV_EXCP_NONE) { | ||
97 | - return -ret; | ||
98 | + return ret; | ||
99 | } | ||
100 | |||
101 | /* write value if writable and write mask set, otherwise drop writes */ | ||
102 | @@ -XXX,XX +XXX,XX @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
103 | if (csr_ops[csrno].write) { | ||
104 | ret = csr_ops[csrno].write(env, csrno, new_value); | ||
105 | if (ret != RISCV_EXCP_NONE) { | ||
106 | - return -ret; | ||
107 | + return ret; | ||
108 | } | ||
109 | } | ||
110 | } | ||
111 | @@ -XXX,XX +XXX,XX @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
112 | *ret_value = old_value; | ||
113 | } | ||
114 | |||
115 | - return 0; | ||
116 | + return RISCV_EXCP_NONE; | ||
117 | } | ||
118 | |||
119 | /* | ||
120 | * Debugger support. If not in user mode, set env->debugger before the | ||
121 | * riscv_csrrw call and clear it after the call. | ||
122 | */ | ||
123 | -int riscv_csrrw_debug(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
124 | - target_ulong new_value, target_ulong write_mask) | ||
125 | +RISCVException riscv_csrrw_debug(CPURISCVState *env, int csrno, | ||
126 | + target_ulong *ret_value, | ||
127 | + target_ulong new_value, | ||
128 | + target_ulong write_mask) | ||
129 | { | ||
130 | - int ret; | ||
131 | + RISCVException ret; | ||
132 | #if !defined(CONFIG_USER_ONLY) | ||
133 | env->debugger = true; | ||
134 | #endif | ||
135 | diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c | ||
136 | index XXXXXXX..XXXXXXX 100644 | ||
137 | --- a/target/riscv/gdbstub.c | ||
138 | +++ b/target/riscv/gdbstub.c | ||
139 | @@ -XXX,XX +XXX,XX @@ static int riscv_gdb_get_fpu(CPURISCVState *env, GByteArray *buf, int n) | ||
140 | */ | ||
141 | result = riscv_csrrw_debug(env, n - 32, &val, | ||
142 | 0, 0); | ||
143 | - if (result == 0) { | ||
144 | + if (result == RISCV_EXCP_NONE) { | ||
145 | return gdb_get_regl(buf, val); | ||
146 | } | ||
147 | } | ||
148 | @@ -XXX,XX +XXX,XX @@ static int riscv_gdb_set_fpu(CPURISCVState *env, uint8_t *mem_buf, int n) | ||
149 | */ | ||
150 | result = riscv_csrrw_debug(env, n - 32, NULL, | ||
151 | val, -1); | ||
152 | - if (result == 0) { | ||
153 | + if (result == RISCV_EXCP_NONE) { | ||
154 | return sizeof(target_ulong); | ||
155 | } | ||
156 | } | ||
157 | @@ -XXX,XX +XXX,XX @@ static int riscv_gdb_get_csr(CPURISCVState *env, GByteArray *buf, int n) | ||
158 | int result; | ||
159 | |||
160 | result = riscv_csrrw_debug(env, n, &val, 0, 0); | ||
161 | - if (result == 0) { | ||
162 | + if (result == RISCV_EXCP_NONE) { | ||
163 | return gdb_get_regl(buf, val); | ||
164 | } | ||
165 | } | ||
166 | @@ -XXX,XX +XXX,XX @@ static int riscv_gdb_set_csr(CPURISCVState *env, uint8_t *mem_buf, int n) | ||
167 | int result; | ||
168 | |||
169 | result = riscv_csrrw_debug(env, n, NULL, val, -1); | ||
170 | - if (result == 0) { | ||
171 | + if (result == RISCV_EXCP_NONE) { | ||
172 | return sizeof(target_ulong); | ||
173 | } | ||
174 | } | ||
175 | diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c | ||
176 | index XXXXXXX..XXXXXXX 100644 | ||
177 | --- a/target/riscv/op_helper.c | ||
178 | +++ b/target/riscv/op_helper.c | ||
179 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_csrrw(CPURISCVState *env, target_ulong src, | ||
180 | target_ulong csr) | ||
181 | { | ||
182 | target_ulong val = 0; | ||
183 | - int ret = riscv_csrrw(env, csr, &val, src, -1); | ||
184 | + RISCVException ret = riscv_csrrw(env, csr, &val, src, -1); | ||
185 | |||
186 | - if (ret < 0) { | ||
187 | - riscv_raise_exception(env, -ret, GETPC()); | ||
188 | + if (ret != RISCV_EXCP_NONE) { | ||
189 | + riscv_raise_exception(env, ret, GETPC()); | ||
190 | } | ||
191 | return val; | ||
192 | } | ||
193 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_csrrs(CPURISCVState *env, target_ulong src, | ||
194 | target_ulong csr, target_ulong rs1_pass) | ||
195 | { | ||
196 | target_ulong val = 0; | ||
197 | - int ret = riscv_csrrw(env, csr, &val, -1, rs1_pass ? src : 0); | ||
198 | + RISCVException ret = riscv_csrrw(env, csr, &val, -1, rs1_pass ? src : 0); | ||
199 | |||
200 | - if (ret < 0) { | ||
201 | - riscv_raise_exception(env, -ret, GETPC()); | ||
202 | + if (ret != RISCV_EXCP_NONE) { | ||
203 | + riscv_raise_exception(env, ret, GETPC()); | ||
204 | } | ||
205 | return val; | ||
206 | } | ||
207 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_csrrc(CPURISCVState *env, target_ulong src, | ||
208 | target_ulong csr, target_ulong rs1_pass) | ||
209 | { | ||
210 | target_ulong val = 0; | ||
211 | - int ret = riscv_csrrw(env, csr, &val, 0, rs1_pass ? src : 0); | ||
212 | + RISCVException ret = riscv_csrrw(env, csr, &val, 0, rs1_pass ? src : 0); | ||
213 | |||
214 | - if (ret < 0) { | ||
215 | - riscv_raise_exception(env, -ret, GETPC()); | ||
216 | + if (ret != RISCV_EXCP_NONE) { | ||
217 | + riscv_raise_exception(env, ret, GETPC()); | ||
218 | } | ||
219 | return val; | ||
220 | } | ||
75 | -- | 221 | -- |
76 | 2.48.1 | 222 | 2.31.1 |
223 | |||
224 | diff view generated by jsdifflib |
1 | From: Alistair Francis <alistair23@gmail.com> | 1 | Update the RISC-V maintainers by removing Sagar and Bastian who haven't |
---|---|---|---|
2 | been involved recently. | ||
2 | 3 | ||
3 | Bin Meng has been a long time contributor and maintainer for QEMU RISC-V | 4 | Also add Bin who has been helping with reviews. |
4 | and has been very beneficial to the RISC-V ecosystem. | ||
5 | |||
6 | Unfortunately his email has started to bounce so this patch is removing | ||
7 | them from MAINTAINERS. If in the future Bin Meng wants to return we will | ||
8 | happily re-add them. | ||
9 | |||
10 | Note that I'm not removing Bin Meng as a "SD (Secure Card)" maintainer. | ||
11 | 5 | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 6 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | Acked-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 7 | Acked-by: Bin Meng <bin.meng@windriver.com> |
14 | Message-ID: <20250128060546.1374394-1-alistair.francis@wdc.com> | 8 | Acked-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de> |
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
10 | Message-id: 6564ba829c40ad9aa7d28f43be69d8eb5cf4b56b.1617749142.git.alistair.francis@wdc.com | ||
16 | --- | 11 | --- |
17 | MAINTAINERS | 5 +---- | 12 | MAINTAINERS | 5 ++--- |
18 | 1 file changed, 1 insertion(+), 4 deletions(-) | 13 | 1 file changed, 2 insertions(+), 3 deletions(-) |
19 | 14 | ||
20 | diff --git a/MAINTAINERS b/MAINTAINERS | 15 | diff --git a/MAINTAINERS b/MAINTAINERS |
21 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/MAINTAINERS | 17 | --- a/MAINTAINERS |
23 | +++ b/MAINTAINERS | 18 | +++ b/MAINTAINERS |
24 | @@ -XXX,XX +XXX,XX @@ F: tests/functional/test_ppc_74xx.py | 19 | @@ -XXX,XX +XXX,XX @@ F: tests/acceptance/machine_ppc.py |
20 | |||
25 | RISC-V TCG CPUs | 21 | RISC-V TCG CPUs |
26 | M: Palmer Dabbelt <palmer@dabbelt.com> | 22 | M: Palmer Dabbelt <palmer@dabbelt.com> |
27 | M: Alistair Francis <alistair.francis@wdc.com> | 23 | -M: Alistair Francis <Alistair.Francis@wdc.com> |
28 | -M: Bin Meng <bmeng.cn@gmail.com> | 24 | -M: Sagar Karandikar <sagark@eecs.berkeley.edu> |
29 | R: Weiwei Li <liwei1518@gmail.com> | 25 | -M: Bastian Koppelmann <kbastian@mail.uni-paderborn.de> |
30 | R: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 26 | +M: Alistair Francis <alistair.francis@wdc.com> |
31 | R: Liu Zhiwei <zhiwei_liu@linux.alibaba.com> | 27 | +M: Bin Meng <bin.meng@windriver.com> |
32 | @@ -XXX,XX +XXX,XX @@ F: include/hw/riscv/opentitan.h | ||
33 | F: include/hw/*/ibex_*.h | ||
34 | |||
35 | Microchip PolarFire SoC Icicle Kit | ||
36 | -M: Bin Meng <bmeng.cn@gmail.com> | ||
37 | L: qemu-riscv@nongnu.org | 28 | L: qemu-riscv@nongnu.org |
38 | S: Supported | 29 | S: Supported |
39 | F: docs/system/riscv/microchip-icicle-kit.rst | 30 | F: target/riscv/ |
40 | @@ -XXX,XX +XXX,XX @@ F: include/hw/char/shakti_uart.h | ||
41 | |||
42 | SiFive Machines | ||
43 | M: Alistair Francis <Alistair.Francis@wdc.com> | ||
44 | -M: Bin Meng <bmeng.cn@gmail.com> | ||
45 | M: Palmer Dabbelt <palmer@dabbelt.com> | ||
46 | L: qemu-riscv@nongnu.org | ||
47 | S: Supported | ||
48 | @@ -XXX,XX +XXX,XX @@ S: Orphan | ||
49 | F: hw/i386/amd_iommu.? | ||
50 | |||
51 | OpenSBI Firmware | ||
52 | -M: Bin Meng <bmeng.cn@gmail.com> | ||
53 | +L: qemu-riscv@nongnu.org | ||
54 | S: Supported | ||
55 | F: pc-bios/opensbi-* | ||
56 | F: .gitlab-ci.d/opensbi.yml | ||
57 | -- | 31 | -- |
58 | 2.48.1 | 32 | 2.31.1 |
33 | |||
34 | diff view generated by jsdifflib |
1 | From: Yong-Xuan Wang <yongxuan.wang@sifive.com> | 1 | Update the OpenTitan interrupt layout to match the latest OpenTitan |
---|---|---|---|
2 | bitstreams. This involves changing the Ibex PLIC memory layout and the | ||
3 | UART interrupts. | ||
2 | 4 | ||
3 | Let kvm_msicfgaddr use the same format with mmsicfgaddr and smsicfgaddr. | 5 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
6 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
7 | Message-id: e92b696f1809c9fa4410da2e9f23c414db5a6960.1617202791.git.alistair.francis@wdc.com | ||
8 | --- | ||
9 | include/hw/riscv/opentitan.h | 16 ++++++++-------- | ||
10 | hw/intc/ibex_plic.c | 20 ++++++++++---------- | ||
11 | hw/riscv/opentitan.c | 8 ++++---- | ||
12 | 3 files changed, 22 insertions(+), 22 deletions(-) | ||
4 | 13 | ||
5 | Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com> | 14 | diff --git a/include/hw/riscv/opentitan.h b/include/hw/riscv/opentitan.h |
6 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 15 | index XXXXXXX..XXXXXXX 100644 |
7 | Message-ID: <20250224025722.3999-4-yongxuan.wang@sifive.com> | 16 | --- a/include/hw/riscv/opentitan.h |
8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 17 | +++ b/include/hw/riscv/opentitan.h |
9 | --- | 18 | @@ -XXX,XX +XXX,XX @@ enum { |
10 | hw/intc/riscv_aplic.c | 24 +++++++++++++----------- | 19 | }; |
11 | 1 file changed, 13 insertions(+), 11 deletions(-) | 20 | |
21 | enum { | ||
22 | - IBEX_UART_RX_PARITY_ERR_IRQ = 0x28, | ||
23 | - IBEX_UART_RX_TIMEOUT_IRQ = 0x27, | ||
24 | - IBEX_UART_RX_BREAK_ERR_IRQ = 0x26, | ||
25 | - IBEX_UART_RX_FRAME_ERR_IRQ = 0x25, | ||
26 | - IBEX_UART_RX_OVERFLOW_IRQ = 0x24, | ||
27 | - IBEX_UART_TX_EMPTY_IRQ = 0x23, | ||
28 | - IBEX_UART_RX_WATERMARK_IRQ = 0x22, | ||
29 | - IBEX_UART_TX_WATERMARK_IRQ = 0x21, | ||
30 | + IBEX_UART0_RX_PARITY_ERR_IRQ = 8, | ||
31 | + IBEX_UART0_RX_TIMEOUT_IRQ = 7, | ||
32 | + IBEX_UART0_RX_BREAK_ERR_IRQ = 6, | ||
33 | + IBEX_UART0_RX_FRAME_ERR_IRQ = 5, | ||
34 | + IBEX_UART0_RX_OVERFLOW_IRQ = 4, | ||
35 | + IBEX_UART0_TX_EMPTY_IRQ = 3, | ||
36 | + IBEX_UART0_RX_WATERMARK_IRQ = 2, | ||
37 | + IBEX_UART0_TX_WATERMARK_IRQ = 1, | ||
38 | }; | ||
39 | |||
40 | #endif | ||
41 | diff --git a/hw/intc/ibex_plic.c b/hw/intc/ibex_plic.c | ||
42 | index XXXXXXX..XXXXXXX 100644 | ||
43 | --- a/hw/intc/ibex_plic.c | ||
44 | +++ b/hw/intc/ibex_plic.c | ||
45 | @@ -XXX,XX +XXX,XX @@ static void ibex_plic_irq_request(void *opaque, int irq, int level) | ||
46 | |||
47 | static Property ibex_plic_properties[] = { | ||
48 | DEFINE_PROP_UINT32("num-cpus", IbexPlicState, num_cpus, 1), | ||
49 | - DEFINE_PROP_UINT32("num-sources", IbexPlicState, num_sources, 80), | ||
50 | + DEFINE_PROP_UINT32("num-sources", IbexPlicState, num_sources, 176), | ||
51 | |||
52 | DEFINE_PROP_UINT32("pending-base", IbexPlicState, pending_base, 0), | ||
53 | - DEFINE_PROP_UINT32("pending-num", IbexPlicState, pending_num, 3), | ||
54 | + DEFINE_PROP_UINT32("pending-num", IbexPlicState, pending_num, 6), | ||
55 | |||
56 | - DEFINE_PROP_UINT32("source-base", IbexPlicState, source_base, 0x0c), | ||
57 | - DEFINE_PROP_UINT32("source-num", IbexPlicState, source_num, 3), | ||
58 | + DEFINE_PROP_UINT32("source-base", IbexPlicState, source_base, 0x18), | ||
59 | + DEFINE_PROP_UINT32("source-num", IbexPlicState, source_num, 6), | ||
60 | |||
61 | - DEFINE_PROP_UINT32("priority-base", IbexPlicState, priority_base, 0x18), | ||
62 | - DEFINE_PROP_UINT32("priority-num", IbexPlicState, priority_num, 80), | ||
63 | + DEFINE_PROP_UINT32("priority-base", IbexPlicState, priority_base, 0x30), | ||
64 | + DEFINE_PROP_UINT32("priority-num", IbexPlicState, priority_num, 177), | ||
65 | |||
66 | - DEFINE_PROP_UINT32("enable-base", IbexPlicState, enable_base, 0x200), | ||
67 | - DEFINE_PROP_UINT32("enable-num", IbexPlicState, enable_num, 3), | ||
68 | + DEFINE_PROP_UINT32("enable-base", IbexPlicState, enable_base, 0x300), | ||
69 | + DEFINE_PROP_UINT32("enable-num", IbexPlicState, enable_num, 6), | ||
70 | |||
71 | - DEFINE_PROP_UINT32("threshold-base", IbexPlicState, threshold_base, 0x20c), | ||
72 | + DEFINE_PROP_UINT32("threshold-base", IbexPlicState, threshold_base, 0x318), | ||
73 | |||
74 | - DEFINE_PROP_UINT32("claim-base", IbexPlicState, claim_base, 0x210), | ||
75 | + DEFINE_PROP_UINT32("claim-base", IbexPlicState, claim_base, 0x31c), | ||
76 | DEFINE_PROP_END_OF_LIST(), | ||
77 | }; | ||
78 | |||
79 | diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c | ||
80 | index XXXXXXX..XXXXXXX 100644 | ||
81 | --- a/hw/riscv/opentitan.c | ||
82 | +++ b/hw/riscv/opentitan.c | ||
83 | @@ -XXX,XX +XXX,XX @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp) | ||
84 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->uart), 0, memmap[IBEX_DEV_UART].base); | ||
85 | sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart), | ||
86 | 0, qdev_get_gpio_in(DEVICE(&s->plic), | ||
87 | - IBEX_UART_TX_WATERMARK_IRQ)); | ||
88 | + IBEX_UART0_TX_WATERMARK_IRQ)); | ||
89 | sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart), | ||
90 | 1, qdev_get_gpio_in(DEVICE(&s->plic), | ||
91 | - IBEX_UART_RX_WATERMARK_IRQ)); | ||
92 | + IBEX_UART0_RX_WATERMARK_IRQ)); | ||
93 | sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart), | ||
94 | 2, qdev_get_gpio_in(DEVICE(&s->plic), | ||
95 | - IBEX_UART_TX_EMPTY_IRQ)); | ||
96 | + IBEX_UART0_TX_EMPTY_IRQ)); | ||
97 | sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart), | ||
98 | 3, qdev_get_gpio_in(DEVICE(&s->plic), | ||
99 | - IBEX_UART_RX_OVERFLOW_IRQ)); | ||
100 | + IBEX_UART0_RX_OVERFLOW_IRQ)); | ||
101 | |||
102 | create_unimplemented_device("riscv.lowrisc.ibex.gpio", | ||
103 | memmap[IBEX_DEV_GPIO].base, memmap[IBEX_DEV_GPIO].size); | ||
104 | -- | ||
105 | 2.31.1 | ||
12 | 106 | ||
13 | diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c | 107 | |
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/hw/intc/riscv_aplic.c | ||
16 | +++ b/hw/intc/riscv_aplic.c | ||
17 | @@ -XXX,XX +XXX,XX @@ void riscv_aplic_set_kvm_msicfgaddr(RISCVAPLICState *aplic, hwaddr addr) | ||
18 | { | ||
19 | #ifdef CONFIG_KVM | ||
20 | if (riscv_use_emulated_aplic(aplic->msimode)) { | ||
21 | + addr >>= APLIC_xMSICFGADDR_PPN_SHIFT; | ||
22 | aplic->kvm_msicfgaddr = extract64(addr, 0, 32); | ||
23 | - aplic->kvm_msicfgaddrH = extract64(addr, 32, 32); | ||
24 | + aplic->kvm_msicfgaddrH = extract64(addr, 32, 32) & | ||
25 | + APLIC_xMSICFGADDRH_VALID_MASK; | ||
26 | } | ||
27 | #endif | ||
28 | } | ||
29 | @@ -XXX,XX +XXX,XX @@ static void riscv_aplic_msi_send(RISCVAPLICState *aplic, | ||
30 | } | ||
31 | } | ||
32 | |||
33 | - if (aplic->mmode) { | ||
34 | - msicfgaddr = aplic_m->mmsicfgaddr; | ||
35 | - msicfgaddrH = aplic_m->mmsicfgaddrH; | ||
36 | + if (aplic->kvm_splitmode) { | ||
37 | + msicfgaddr = aplic->kvm_msicfgaddr; | ||
38 | + msicfgaddrH = ((uint64_t)aplic->kvm_msicfgaddrH << 32); | ||
39 | } else { | ||
40 | - msicfgaddr = aplic_m->smsicfgaddr; | ||
41 | - msicfgaddrH = aplic_m->smsicfgaddrH; | ||
42 | + if (aplic->mmode) { | ||
43 | + msicfgaddr = aplic_m->mmsicfgaddr; | ||
44 | + msicfgaddrH = aplic_m->mmsicfgaddrH; | ||
45 | + } else { | ||
46 | + msicfgaddr = aplic_m->smsicfgaddr; | ||
47 | + msicfgaddrH = aplic_m->smsicfgaddrH; | ||
48 | + } | ||
49 | } | ||
50 | |||
51 | lhxs = (msicfgaddrH >> APLIC_xMSICFGADDRH_LHXS_SHIFT) & | ||
52 | @@ -XXX,XX +XXX,XX @@ static void riscv_aplic_msi_send(RISCVAPLICState *aplic, | ||
53 | addr |= (uint64_t)(guest_idx & APLIC_xMSICFGADDR_PPN_HART(lhxs)); | ||
54 | addr <<= APLIC_xMSICFGADDR_PPN_SHIFT; | ||
55 | |||
56 | - if (aplic->kvm_splitmode) { | ||
57 | - addr |= aplic->kvm_msicfgaddr; | ||
58 | - addr |= ((uint64_t)aplic->kvm_msicfgaddrH << 32); | ||
59 | - } | ||
60 | - | ||
61 | address_space_stl_le(&address_space_memory, addr, | ||
62 | eiid, MEMTXATTRS_UNSPECIFIED, &result); | ||
63 | if (result != MEMTX_OK) { | ||
64 | -- | ||
65 | 2.48.1 | diff view generated by jsdifflib |
1 | From: Yong-Xuan Wang <yongxuan.wang@sifive.com> | 1 | imply VIRTIO_VGA for the virt machine, this fixes the following error |
---|---|---|---|
2 | when specifying `-vga virtio` as a command line argument: | ||
2 | 3 | ||
3 | When the APLIC is emulated in the kernel, the GPIO output lines to CPUs | 4 | qemu-system-riscv64: Virtio VGA not available |
4 | can be remove. In this case the APLIC trigger CPU interrupts by KVM APIs. | ||
5 | 5 | ||
6 | This patch also move the code that claim the CPU interrupts to the | 6 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
7 | beginning of APLIC realization. This can avoid the unnecessary resource | 7 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> |
8 | allocation before checking failed. | 8 | Message-id: 7ac26fafee8bd59d2a0640f3233f8ad1ab270e1e.1617367317.git.alistair.francis@wdc.com |
9 | --- | ||
10 | hw/riscv/Kconfig | 1 + | ||
11 | 1 file changed, 1 insertion(+) | ||
9 | 12 | ||
10 | Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com> | 13 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig |
11 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 14 | index XXXXXXX..XXXXXXX 100644 |
12 | Message-ID: <20250224025722.3999-3-yongxuan.wang@sifive.com> | 15 | --- a/hw/riscv/Kconfig |
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 16 | +++ b/hw/riscv/Kconfig |
14 | --- | 17 | @@ -XXX,XX +XXX,XX @@ config SHAKTI_C |
15 | hw/intc/riscv_aplic.c | 49 +++++++++++++++++++++++-------------------- | 18 | config RISCV_VIRT |
16 | 1 file changed, 26 insertions(+), 23 deletions(-) | 19 | bool |
20 | imply PCI_DEVICES | ||
21 | + imply VIRTIO_VGA | ||
22 | imply TEST_DEVICES | ||
23 | select GOLDFISH_RTC | ||
24 | select MSI_NONBROKEN | ||
25 | -- | ||
26 | 2.31.1 | ||
17 | 27 | ||
18 | diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c | 28 | |
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/hw/intc/riscv_aplic.c | ||
21 | +++ b/hw/intc/riscv_aplic.c | ||
22 | @@ -XXX,XX +XXX,XX @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp) | ||
23 | RISCVAPLICState *aplic = RISCV_APLIC(dev); | ||
24 | |||
25 | if (riscv_use_emulated_aplic(aplic->msimode)) { | ||
26 | + /* Create output IRQ lines for non-MSI mode */ | ||
27 | + if (!aplic->msimode) { | ||
28 | + /* Claim the CPU interrupt to be triggered by this APLIC */ | ||
29 | + for (i = 0; i < aplic->num_harts; i++) { | ||
30 | + RISCVCPU *cpu; | ||
31 | + | ||
32 | + cpu = RISCV_CPU(cpu_by_arch_id(aplic->hartid_base + i)); | ||
33 | + if (riscv_cpu_claim_interrupts(cpu, | ||
34 | + (aplic->mmode) ? MIP_MEIP : MIP_SEIP) < 0) { | ||
35 | + error_report("%s already claimed", | ||
36 | + (aplic->mmode) ? "MEIP" : "SEIP"); | ||
37 | + exit(1); | ||
38 | + } | ||
39 | + } | ||
40 | + | ||
41 | + aplic->external_irqs = g_malloc(sizeof(qemu_irq) * | ||
42 | + aplic->num_harts); | ||
43 | + qdev_init_gpio_out(dev, aplic->external_irqs, aplic->num_harts); | ||
44 | + } | ||
45 | + | ||
46 | aplic->bitfield_words = (aplic->num_irqs + 31) >> 5; | ||
47 | aplic->sourcecfg = g_new0(uint32_t, aplic->num_irqs); | ||
48 | aplic->state = g_new0(uint32_t, aplic->num_irqs); | ||
49 | @@ -XXX,XX +XXX,XX @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp) | ||
50 | } | ||
51 | } | ||
52 | |||
53 | - /* Create output IRQ lines for non-MSI mode */ | ||
54 | - if (!aplic->msimode) { | ||
55 | - aplic->external_irqs = g_malloc(sizeof(qemu_irq) * aplic->num_harts); | ||
56 | - qdev_init_gpio_out(dev, aplic->external_irqs, aplic->num_harts); | ||
57 | - | ||
58 | - /* Claim the CPU interrupt to be triggered by this APLIC */ | ||
59 | - for (i = 0; i < aplic->num_harts; i++) { | ||
60 | - RISCVCPU *cpu = RISCV_CPU(cpu_by_arch_id(aplic->hartid_base + i)); | ||
61 | - if (riscv_cpu_claim_interrupts(cpu, | ||
62 | - (aplic->mmode) ? MIP_MEIP : MIP_SEIP) < 0) { | ||
63 | - error_report("%s already claimed", | ||
64 | - (aplic->mmode) ? "MEIP" : "SEIP"); | ||
65 | - exit(1); | ||
66 | - } | ||
67 | - } | ||
68 | - } | ||
69 | - | ||
70 | msi_nonbroken = true; | ||
71 | } | ||
72 | |||
73 | @@ -XXX,XX +XXX,XX @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, | ||
74 | |||
75 | if (riscv_use_emulated_aplic(msimode)) { | ||
76 | sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); | ||
77 | - } | ||
78 | |||
79 | - if (!msimode) { | ||
80 | - for (i = 0; i < num_harts; i++) { | ||
81 | - CPUState *cpu = cpu_by_arch_id(hartid_base + i); | ||
82 | + if (!msimode) { | ||
83 | + for (i = 0; i < num_harts; i++) { | ||
84 | + CPUState *cpu = cpu_by_arch_id(hartid_base + i); | ||
85 | |||
86 | - qdev_connect_gpio_out_named(dev, NULL, i, | ||
87 | - qdev_get_gpio_in(DEVICE(cpu), | ||
88 | + qdev_connect_gpio_out_named(dev, NULL, i, | ||
89 | + qdev_get_gpio_in(DEVICE(cpu), | ||
90 | (mmode) ? IRQ_M_EXT : IRQ_S_EXT)); | ||
91 | + } | ||
92 | } | ||
93 | } | ||
94 | |||
95 | -- | ||
96 | 2.48.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Jade Fink <qemu@jade.fyi> |
---|---|---|---|
2 | 2 | ||
3 | In the RISC-V privileged ISA section 3.1.15 table 15, it is determined | 3 | Previously the qemu monitor and gdbstub looked at SUM and refused to |
4 | that a debug exception that is triggered from a load/store has a higher | 4 | perform accesses to user memory if it is off, which was an impediment to |
5 | priority than a possible fault that this access might trigger. | 5 | debugging. |
6 | 6 | ||
7 | This is not the case ATM as shown in [1]. Adding a breakpoint in an | 7 | Signed-off-by: Jade Fink <qemu@jade.fyi> |
8 | address that deliberately will fault is causing a load page fault | ||
9 | instead of a debug exception. The reason is that we're throwing in the | ||
10 | page fault as soon as the fault occurs (end of riscv_cpu_tlb_fill(), | ||
11 | raise_mmu_exception()), not allowing the installed watchpoints to | ||
12 | trigger. | ||
13 | |||
14 | Call cpu_check_watchpoint() in the page fault path to search and execute | ||
15 | any watchpoints that might exist for the address, never returning back | ||
16 | to the fault path. If no watchpoints are found cpu_check_watchpoint() | ||
17 | will return and we'll fall-through the regular path to | ||
18 | raise_mmu_exception(). | ||
19 | |||
20 | [1] https://gitlab.com/qemu-project/qemu/-/issues/2627 | ||
21 | |||
22 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2627 | ||
23 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
24 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
25 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 9 | Message-id: 20210406113109.1031033-1-qemu@jade.fyi |
26 | Message-ID: <20250121170626.1992570-3-dbarboza@ventanamicro.com> | ||
27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
28 | --- | 11 | --- |
29 | target/riscv/cpu_helper.c | 18 ++++++++++++++++++ | 12 | target/riscv/cpu_helper.c | 20 ++++++++++++-------- |
30 | 1 file changed, 18 insertions(+) | 13 | 1 file changed, 12 insertions(+), 8 deletions(-) |
31 | 14 | ||
32 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 15 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
33 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
34 | --- a/target/riscv/cpu_helper.c | 17 | --- a/target/riscv/cpu_helper.c |
35 | +++ b/target/riscv/cpu_helper.c | 18 | +++ b/target/riscv/cpu_helper.c |
36 | @@ -XXX,XX +XXX,XX @@ | 19 | @@ -XXX,XX +XXX,XX @@ static int get_physical_address_pmp(CPURISCVState *env, int *prot, |
37 | #include "exec/page-protection.h" | 20 | * @first_stage: Are we in first stage translation? |
38 | #include "instmap.h" | 21 | * Second stage is used for hypervisor guest translation |
39 | #include "tcg/tcg-op.h" | 22 | * @two_stage: Are we going to perform two stage translation |
40 | +#include "hw/core/tcg-cpu-ops.h" | 23 | + * @is_debug: Is this access from a debugger or the monitor? |
41 | #include "trace.h" | 24 | */ |
42 | #include "semihosting/common-semi.h" | 25 | static int get_physical_address(CPURISCVState *env, hwaddr *physical, |
43 | #include "system/cpu-timers.h" | 26 | int *prot, target_ulong addr, |
27 | target_ulong *fault_pte_addr, | ||
28 | int access_type, int mmu_idx, | ||
29 | - bool first_stage, bool two_stage) | ||
30 | + bool first_stage, bool two_stage, | ||
31 | + bool is_debug) | ||
32 | { | ||
33 | /* NOTE: the env->pc value visible here will not be | ||
34 | * correct, but the value visible to the exception handler | ||
35 | @@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, | ||
36 | widened = 2; | ||
37 | } | ||
38 | /* status.SUM will be ignored if execute on background */ | ||
39 | - sum = get_field(env->mstatus, MSTATUS_SUM) || use_background; | ||
40 | + sum = get_field(env->mstatus, MSTATUS_SUM) || use_background || is_debug; | ||
41 | switch (vm) { | ||
42 | case VM_1_10_SV32: | ||
43 | levels = 2; ptidxbits = 10; ptesize = 4; break; | ||
44 | @@ -XXX,XX +XXX,XX @@ restart: | ||
45 | /* Do the second stage translation on the base PTE address. */ | ||
46 | int vbase_ret = get_physical_address(env, &vbase, &vbase_prot, | ||
47 | base, NULL, MMU_DATA_LOAD, | ||
48 | - mmu_idx, false, true); | ||
49 | + mmu_idx, false, true, | ||
50 | + is_debug); | ||
51 | |||
52 | if (vbase_ret != TRANSLATE_SUCCESS) { | ||
53 | if (fault_pte_addr) { | ||
54 | @@ -XXX,XX +XXX,XX @@ hwaddr riscv_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) | ||
55 | int mmu_idx = cpu_mmu_index(&cpu->env, false); | ||
56 | |||
57 | if (get_physical_address(env, &phys_addr, &prot, addr, NULL, 0, mmu_idx, | ||
58 | - true, riscv_cpu_virt_enabled(env))) { | ||
59 | + true, riscv_cpu_virt_enabled(env), true)) { | ||
60 | return -1; | ||
61 | } | ||
62 | |||
63 | if (riscv_cpu_virt_enabled(env)) { | ||
64 | if (get_physical_address(env, &phys_addr, &prot, phys_addr, NULL, | ||
65 | - 0, mmu_idx, false, true)) { | ||
66 | + 0, mmu_idx, false, true, true)) { | ||
67 | return -1; | ||
68 | } | ||
69 | } | ||
44 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | 70 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, |
45 | } else if (probe) { | 71 | /* Two stage lookup */ |
46 | return false; | 72 | ret = get_physical_address(env, &pa, &prot, address, |
73 | &env->guest_phys_fault_addr, access_type, | ||
74 | - mmu_idx, true, true); | ||
75 | + mmu_idx, true, true, false); | ||
76 | |||
77 | /* | ||
78 | * A G-stage exception may be triggered during two state lookup. | ||
79 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | ||
80 | im_address = pa; | ||
81 | |||
82 | ret = get_physical_address(env, &pa, &prot2, im_address, NULL, | ||
83 | - access_type, mmu_idx, false, true); | ||
84 | + access_type, mmu_idx, false, true, | ||
85 | + false); | ||
86 | |||
87 | qemu_log_mask(CPU_LOG_MMU, | ||
88 | "%s 2nd-stage address=%" VADDR_PRIx " ret %d physical " | ||
89 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | ||
47 | } else { | 90 | } else { |
48 | + int wp_access = 0; | 91 | /* Single stage lookup */ |
49 | + | 92 | ret = get_physical_address(env, &pa, &prot, address, NULL, |
50 | + if (access_type == MMU_DATA_LOAD) { | 93 | - access_type, mmu_idx, true, false); |
51 | + wp_access |= BP_MEM_READ; | 94 | + access_type, mmu_idx, true, false, false); |
52 | + } else if (access_type == MMU_DATA_STORE) { | 95 | |
53 | + wp_access |= BP_MEM_WRITE; | 96 | qemu_log_mask(CPU_LOG_MMU, |
54 | + } | 97 | "%s address=%" VADDR_PRIx " ret %d physical " |
55 | + | ||
56 | + /* | ||
57 | + * If a watchpoint isn't found for 'addr' this will | ||
58 | + * be a no-op and we'll resume the mmu_exception path. | ||
59 | + * Otherwise we'll throw a debug exception and execution | ||
60 | + * will continue elsewhere. | ||
61 | + */ | ||
62 | + cpu_check_watchpoint(cs, address, size, MEMTXATTRS_UNSPECIFIED, | ||
63 | + wp_access, retaddr); | ||
64 | + | ||
65 | raise_mmu_exception(env, address, access_type, pmp_violation, | ||
66 | first_stage_error, two_stage_lookup, | ||
67 | two_stage_indirect_error); | ||
68 | -- | 98 | -- |
69 | 2.48.1 | 99 | 2.31.1 |
100 | |||
101 | diff view generated by jsdifflib |
1 | From: Max Chou <max.chou@sifive.com> | 1 | From: LIU Zhiwei <zhiwei_liu@c-sky.com> |
---|---|---|---|
2 | 2 | ||
3 | According to the Vector Reduction Operations section in the RISC-V "V" | 3 | The overflow predication ((a - b) ^ a) & (a ^ b) & INT64_MIN is right. |
4 | Vector Extension spec, | 4 | However, when the predication is ture and a is 0, it should return maximum. |
5 | "If vl=0, no operation is performed and the destination register is not | ||
6 | updated." | ||
7 | 5 | ||
8 | The vd should be updated when vl is larger than 0. | 6 | Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com> |
9 | 7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | |
10 | Fixes: fe5c9ab1fc ("target/riscv: vector single-width integer reduction instructions") | 8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
11 | Fixes: f714361ed7 ("target/riscv: rvv-1.0: implement vstart CSR") | 9 | Message-id: 20210212150256.885-4-zhiwei_liu@c-sky.com |
12 | Signed-off-by: Max Chou <max.chou@sifive.com> | ||
13 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
14 | Message-ID: <20250124101452.2519171-1-max.chou@sifive.com> | ||
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
16 | --- | 11 | --- |
17 | target/riscv/vector_helper.c | 8 ++++++-- | 12 | target/riscv/vector_helper.c | 8 ++++---- |
18 | 1 file changed, 6 insertions(+), 2 deletions(-) | 13 | 1 file changed, 4 insertions(+), 4 deletions(-) |
19 | 14 | ||
20 | diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c | 15 | diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c |
21 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/target/riscv/vector_helper.c | 17 | --- a/target/riscv/vector_helper.c |
23 | +++ b/target/riscv/vector_helper.c | 18 | +++ b/target/riscv/vector_helper.c |
24 | @@ -XXX,XX +XXX,XX @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, \ | 19 | @@ -XXX,XX +XXX,XX @@ static inline int8_t ssub8(CPURISCVState *env, int vxrm, int8_t a, int8_t b) |
25 | } \ | 20 | { |
26 | s1 = OP(s1, (TD)s2); \ | 21 | int8_t res = a - b; |
27 | } \ | 22 | if ((res ^ a) & (a ^ b) & INT8_MIN) { |
28 | - *((TD *)vd + HD(0)) = s1; \ | 23 | - res = a > 0 ? INT8_MAX : INT8_MIN; |
29 | + if (vl > 0) { \ | 24 | + res = a >= 0 ? INT8_MAX : INT8_MIN; |
30 | + *((TD *)vd + HD(0)) = s1; \ | 25 | env->vxsat = 0x1; |
31 | + } \ | 26 | } |
32 | env->vstart = 0; \ | 27 | return res; |
33 | /* set tail elements to 1s */ \ | 28 | @@ -XXX,XX +XXX,XX @@ static inline int16_t ssub16(CPURISCVState *env, int vxrm, int16_t a, int16_t b) |
34 | vext_set_elems_1s(vd, vta, esz, vlenb); \ | 29 | { |
35 | @@ -XXX,XX +XXX,XX @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, \ | 30 | int16_t res = a - b; |
36 | } \ | 31 | if ((res ^ a) & (a ^ b) & INT16_MIN) { |
37 | s1 = OP(s1, (TD)s2, &env->fp_status); \ | 32 | - res = a > 0 ? INT16_MAX : INT16_MIN; |
38 | } \ | 33 | + res = a >= 0 ? INT16_MAX : INT16_MIN; |
39 | - *((TD *)vd + HD(0)) = s1; \ | 34 | env->vxsat = 0x1; |
40 | + if (vl > 0) { \ | 35 | } |
41 | + *((TD *)vd + HD(0)) = s1; \ | 36 | return res; |
42 | + } \ | 37 | @@ -XXX,XX +XXX,XX @@ static inline int32_t ssub32(CPURISCVState *env, int vxrm, int32_t a, int32_t b) |
43 | env->vstart = 0; \ | 38 | { |
44 | /* set tail elements to 1s */ \ | 39 | int32_t res = a - b; |
45 | vext_set_elems_1s(vd, vta, esz, vlenb); \ | 40 | if ((res ^ a) & (a ^ b) & INT32_MIN) { |
41 | - res = a > 0 ? INT32_MAX : INT32_MIN; | ||
42 | + res = a >= 0 ? INT32_MAX : INT32_MIN; | ||
43 | env->vxsat = 0x1; | ||
44 | } | ||
45 | return res; | ||
46 | @@ -XXX,XX +XXX,XX @@ static inline int64_t ssub64(CPURISCVState *env, int vxrm, int64_t a, int64_t b) | ||
47 | { | ||
48 | int64_t res = a - b; | ||
49 | if ((res ^ a) & (a ^ b) & INT64_MIN) { | ||
50 | - res = a > 0 ? INT64_MAX : INT64_MIN; | ||
51 | + res = a >= 0 ? INT64_MAX : INT64_MIN; | ||
52 | env->vxsat = 0x1; | ||
53 | } | ||
54 | return res; | ||
46 | -- | 55 | -- |
47 | 2.48.1 | 56 | 2.31.1 |
57 | |||
58 | diff view generated by jsdifflib |
1 | From: Andrea Bolognani <abologna@redhat.com> | 1 | From: Vijai Kumar K <vijai@behindbytes.com> |
---|---|---|---|
2 | 2 | ||
3 | Until now, the script has worked under the assumption that a | 3 | Add documentation for Shakti C reference platform. |
4 | host CPU can run binaries targeting any CPU in the same family. | ||
5 | That's a fair enough assumption when it comes to running i386 | ||
6 | binaries on x86_64, but it doesn't quite apply in the general | ||
7 | case. | ||
8 | 4 | ||
9 | For example, while riscv64 CPUs could theoretically run riscv32 | 5 | Signed-off-by: Vijai Kumar K <vijai@behindbytes.com> |
10 | applications natively, in practice there exist few (if any?) | ||
11 | CPUs that implement the necessary silicon; moreover, even if you | ||
12 | had one such CPU, your host OS would most likely not have | ||
13 | enabled the necessary kernel bits. | ||
14 | |||
15 | This new option gives distro packagers the ability to opt out of | ||
16 | the assumption, likely on a per-architecture basis, and make | ||
17 | things work out of the box for a larger fraction of their user | ||
18 | base. | ||
19 | |||
20 | As an interesting side effect, this makes it possible to enable | ||
21 | execution of 64-bit binaries on 32-bit CPUs of the same family, | ||
22 | which is a perfectly valid use case that apparently hadn't been | ||
23 | considered until now. | ||
24 | |||
25 | Link: https://src.fedoraproject.org/rpms/qemu/pull-request/72 | ||
26 | Thanks: David Abdurachmanov <davidlt@rivosinc.com> | ||
27 | Thanks: Daniel P. Berrangé <berrange@redhat.com> | ||
28 | Signed-off-by: Andrea Bolognani <abologna@redhat.com> | ||
29 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
30 | Reviewed-by: Laurent Vivier <laurent@vivier.eu> | 7 | Message-id: 20210412174248.8668-1-vijai@behindbytes.com |
31 | Message-ID: <20250127182924.103510-4-abologna@redhat.com> | 8 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> |
9 | [ Changes from Bin Meng: | ||
10 | - Add missing TOC | ||
11 | Message-id: 20210430070534.1487242-1-bmeng.cn@gmail.com | ||
12 | ] | ||
32 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
33 | --- | 14 | --- |
34 | scripts/qemu-binfmt-conf.sh | 19 ++++++++++++++++--- | 15 | docs/system/riscv/shakti-c.rst | 82 ++++++++++++++++++++++++++++++++++ |
35 | 1 file changed, 16 insertions(+), 3 deletions(-) | 16 | docs/system/target-riscv.rst | 1 + |
17 | 2 files changed, 83 insertions(+) | ||
18 | create mode 100644 docs/system/riscv/shakti-c.rst | ||
36 | 19 | ||
37 | diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh | 20 | diff --git a/docs/system/riscv/shakti-c.rst b/docs/system/riscv/shakti-c.rst |
38 | index XXXXXXX..XXXXXXX 100755 | 21 | new file mode 100644 |
39 | --- a/scripts/qemu-binfmt-conf.sh | 22 | index XXXXXXX..XXXXXXX |
40 | +++ b/scripts/qemu-binfmt-conf.sh | 23 | --- /dev/null |
41 | @@ -XXX,XX +XXX,XX @@ Usage: qemu-binfmt-conf.sh [--qemu-path PATH][--debian][--systemd CPU] | 24 | +++ b/docs/system/riscv/shakti-c.rst |
42 | --persistent: if yes, the interpreter is loaded when binfmt is | 25 | @@ -XXX,XX +XXX,XX @@ |
43 | configured and remains in memory. All future uses | 26 | +Shakti C Reference Platform (``shakti_c``) |
44 | are cloned from the open file. | 27 | +========================================== |
45 | + --ignore-family: if yes, it is assumed that the host CPU (e.g. riscv64) | 28 | + |
46 | + can't natively run programs targeting a CPU that is | 29 | +Shakti C Reference Platform is a reference platform based on arty a7 100t |
47 | + part of the same family (e.g. riscv32). | 30 | +for the Shakti SoC. |
48 | --preserve-argv0 preserve argv[0] | 31 | + |
49 | 32 | +Shakti SoC is a SoC based on the Shakti C-class processor core. Shakti C | |
50 | To import templates with update-binfmts, use : | 33 | +is a 64bit RV64GCSUN processor core. |
51 | @@ -XXX,XX +XXX,XX @@ qemu_set_binfmts() { | 34 | + |
52 | fi | 35 | +For more details on Shakti SoC, please see: |
53 | 36 | +https://gitlab.com/shaktiproject/cores/shakti-soc/-/blob/master/fpga/boards/artya7-100t/c-class/README.rst | |
54 | if [ "$host_family" = "$family" ] ; then | 37 | + |
55 | - continue | 38 | +For more info on the Shakti C-class core, please see: |
56 | + # When --ignore-family is used, we have to generate rules even | 39 | +https://c-class.readthedocs.io/en/latest/ |
57 | + # for targets that are in the same family as the host CPU. The | 40 | + |
58 | + # only exception is of course when the CPU types exactly match | 41 | +Supported devices |
59 | + if [ "$target" = "$host_cpu" ] || [ "$IGNORE_FAMILY" = "no" ] ; then | 42 | +----------------- |
60 | + continue | 43 | + |
61 | + fi | 44 | +The ``shakti_c`` machine supports the following devices: |
62 | fi | 45 | + |
63 | 46 | + * 1 C-class core | |
64 | $BINFMT_SET | 47 | + * Core Level Interruptor (CLINT) |
65 | @@ -XXX,XX +XXX,XX @@ CREDENTIAL=no | 48 | + * Platform-Level Interrupt Controller (PLIC) |
66 | PERSISTENT=no | 49 | + * 1 UART |
67 | PRESERVE_ARG0=no | 50 | + |
68 | QEMU_SUFFIX="" | 51 | +Boot options |
69 | +IGNORE_FAMILY=no | 52 | +------------ |
70 | 53 | + | |
71 | _longopts="debian,systemd:,qemu-path:,qemu-suffix:,exportdir:,help,credential:,\ | 54 | +The ``shakti_c`` machine can start using the standard -bios |
72 | -persistent:,preserve-argv0:" | 55 | +functionality for loading the baremetal application or opensbi. |
73 | -options=$(getopt -o ds:Q:S:e:hc:p:g:F: -l ${_longopts} -- "$@") | 56 | + |
74 | +persistent:,preserve-argv0:,ignore-family:" | 57 | +Boot the machine |
75 | +options=$(getopt -o ds:Q:S:e:hc:p:g:F:i: -l ${_longopts} -- "$@") | 58 | +---------------- |
76 | eval set -- "$options" | 59 | + |
77 | 60 | +Shakti SDK | |
78 | while true ; do | 61 | +~~~~~~~~~~ |
79 | @@ -XXX,XX +XXX,XX @@ while true ; do | 62 | +Shakti SDK can be used to generate the baremetal example UART applications. |
80 | shift | 63 | + |
81 | PRESERVE_ARG0="$1" | 64 | +.. code-block:: bash |
82 | ;; | 65 | + |
83 | + -i|--ignore-family) | 66 | + $ git clone https://gitlab.com/behindbytes/shakti-sdk.git |
84 | + shift | 67 | + $ cd shakti-sdk |
85 | + IGNORE_FAMILY="$1" | 68 | + $ make software PROGRAM=loopback TARGET=artix7_100t |
86 | + ;; | 69 | + |
87 | *) | 70 | +Binary would be generated in: |
88 | break | 71 | + software/examples/uart_applns/loopback/output/loopback.shakti |
89 | ;; | 72 | + |
73 | +You could also download the precompiled example applicatons using below | ||
74 | +commands. | ||
75 | + | ||
76 | +.. code-block:: bash | ||
77 | + | ||
78 | + $ wget -c https://gitlab.com/behindbytes/shakti-binaries/-/raw/master/sdk/shakti_sdk_qemu.zip | ||
79 | + $ unzip shakti_sdk_qemu.zip | ||
80 | + | ||
81 | +Then we can run the UART example using: | ||
82 | + | ||
83 | +.. code-block:: bash | ||
84 | + | ||
85 | + $ qemu-system-riscv64 -M shakti_c -nographic \ | ||
86 | + -bios path/to/shakti_sdk_qemu/loopback.shakti | ||
87 | + | ||
88 | +OpenSBI | ||
89 | +~~~~~~~ | ||
90 | +We can also run OpenSBI with Test Payload. | ||
91 | + | ||
92 | +.. code-block:: bash | ||
93 | + | ||
94 | + $ git clone https://github.com/riscv/opensbi.git -b v0.9 | ||
95 | + $ cd opensbi | ||
96 | + $ wget -c https://gitlab.com/behindbytes/shakti-binaries/-/raw/master/dts/shakti.dtb | ||
97 | + $ export CROSS_COMPILE=riscv64-unknown-elf- | ||
98 | + $ export FW_FDT_PATH=./shakti.dtb | ||
99 | + $ make PLATFORM=generic | ||
100 | + | ||
101 | +fw_payload.elf would be generated in build/platform/generic/firmware/fw_payload.elf. | ||
102 | +Boot it using the below qemu command. | ||
103 | + | ||
104 | +.. code-block:: bash | ||
105 | + | ||
106 | + $ qemu-system-riscv64 -M shakti_c -nographic \ | ||
107 | + -bios path/to/fw_payload.elf | ||
108 | diff --git a/docs/system/target-riscv.rst b/docs/system/target-riscv.rst | ||
109 | index XXXXXXX..XXXXXXX 100644 | ||
110 | --- a/docs/system/target-riscv.rst | ||
111 | +++ b/docs/system/target-riscv.rst | ||
112 | @@ -XXX,XX +XXX,XX @@ undocumented; you can get a complete list by running | ||
113 | :maxdepth: 1 | ||
114 | |||
115 | riscv/microchip-icicle-kit | ||
116 | + riscv/shakti-c | ||
117 | riscv/sifive_u | ||
118 | |||
119 | RISC-V CPU features | ||
90 | -- | 120 | -- |
91 | 2.48.1 | 121 | 2.31.1 |
92 | 122 | ||
93 | 123 | diff view generated by jsdifflib |
1 | From: Clément Léger <cleger@rivosinc.com> | 1 | The RISC-V spec says: |
---|---|---|---|
2 | if PMP entry i is locked and pmpicfg.A is set to TOR, writes to | ||
3 | pmpaddri-1 are ignored. | ||
2 | 4 | ||
3 | As raised by Richard Henderson, these warnings are displayed in user | 5 | The current QEMU code ignores accesses to pmpaddri-1 and pmpcfgi-1 which |
4 | only as well. Since they aren't really useful for the end-user, remove | 6 | is incorrect. |
5 | them and add a "TODO" note in the leading comments. | ||
6 | 7 | ||
7 | Signed-off-by: Clément Léger <cleger@rivosinc.com> | 8 | Update the pmp_is_locked() function to not check the supporting fields |
8 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 9 | and instead enforce the lock functionality in the pmpaddr write operation. |
9 | Message-ID: <20250213145640.117275-1-cleger@rivosinc.com> | 10 | |
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
13 | Message-id: 2831241458163f445a89bd59c59990247265b0c6.1618812899.git.alistair.francis@wdc.com | ||
11 | --- | 14 | --- |
12 | target/riscv/tcg/tcg-cpu.c | 8 +++----- | 15 | target/riscv/pmp.c | 26 ++++++++++++++++---------- |
13 | 1 file changed, 3 insertions(+), 5 deletions(-) | 16 | 1 file changed, 16 insertions(+), 10 deletions(-) |
14 | 17 | ||
15 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | 18 | diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c |
16 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/riscv/tcg/tcg-cpu.c | 20 | --- a/target/riscv/pmp.c |
18 | +++ b/target/riscv/tcg/tcg-cpu.c | 21 | +++ b/target/riscv/pmp.c |
19 | @@ -XXX,XX +XXX,XX @@ static void riscv_init_max_cpu_extensions(Object *obj) | 22 | @@ -XXX,XX +XXX,XX @@ static inline int pmp_is_locked(CPURISCVState *env, uint32_t pmp_index) |
23 | return 0; | ||
20 | } | 24 | } |
21 | 25 | ||
22 | /* | 26 | - /* In TOR mode, need to check the lock bit of the next pmp |
23 | - * ext_smrnmi requires OpenSBI changes that our current | 27 | - * (if there is a next) |
24 | + * TODO: ext_smrnmi requires OpenSBI changes that our current | 28 | - */ |
25 | * image does not have. Disable it for now. | 29 | - const uint8_t a_field = |
26 | */ | 30 | - pmp_get_a_field(env->pmp_state.pmp[pmp_index + 1].cfg_reg); |
27 | if (cpu->cfg.ext_smrnmi) { | 31 | - if ((env->pmp_state.pmp[pmp_index + 1u].cfg_reg & PMP_LOCK) && |
28 | isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_smrnmi), false); | 32 | - (PMP_AMATCH_TOR == a_field)) { |
29 | - qemu_log("Smrnmi is disabled in the 'max' type CPU\n"); | 33 | - return 1; |
30 | } | 34 | - } |
31 | 35 | - | |
32 | /* | 36 | return 0; |
33 | - * ext_smdbltrp requires the firmware to clear MSTATUS.MDT on startup to | ||
34 | - * avoid generating a double trap. OpenSBI does not currently support it, | ||
35 | + * TODO: ext_smdbltrp requires the firmware to clear MSTATUS.MDT on startup | ||
36 | + * to avoid generating a double trap. OpenSBI does not currently support it, | ||
37 | * disable it for now. | ||
38 | */ | ||
39 | if (cpu->cfg.ext_smdbltrp) { | ||
40 | isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_smdbltrp), false); | ||
41 | - qemu_log("Smdbltrp is disabled in the 'max' type CPU\n"); | ||
42 | } | ||
43 | } | 37 | } |
44 | 38 | ||
39 | @@ -XXX,XX +XXX,XX @@ void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index, | ||
40 | target_ulong val) | ||
41 | { | ||
42 | trace_pmpaddr_csr_write(env->mhartid, addr_index, val); | ||
43 | + | ||
44 | if (addr_index < MAX_RISCV_PMPS) { | ||
45 | + /* | ||
46 | + * In TOR mode, need to check the lock bit of the next pmp | ||
47 | + * (if there is a next). | ||
48 | + */ | ||
49 | + if (addr_index + 1 < MAX_RISCV_PMPS) { | ||
50 | + uint8_t pmp_cfg = env->pmp_state.pmp[addr_index + 1].cfg_reg; | ||
51 | + | ||
52 | + if (pmp_cfg & PMP_LOCK && | ||
53 | + PMP_AMATCH_TOR == pmp_get_a_field(pmp_cfg)) { | ||
54 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
55 | + "ignoring pmpaddr write - pmpcfg + 1 locked\n"); | ||
56 | + return; | ||
57 | + } | ||
58 | + } | ||
59 | + | ||
60 | if (!pmp_is_locked(env, addr_index)) { | ||
61 | env->pmp_state.pmp[addr_index].addr_reg = val; | ||
62 | pmp_update_rule(env, addr_index); | ||
45 | -- | 63 | -- |
46 | 2.48.1 | 64 | 2.31.1 |
47 | 65 | ||
48 | 66 | diff view generated by jsdifflib |
1 | From: Atish Patra <atishp@rivosinc.com> | 1 | From: Hou Weiying <weiying_hou@outlook.com> |
---|---|---|---|
2 | 2 | ||
3 | As per the latest privilege specification v1.13[1], the sscofpmf | 3 | Use address 0x390 and 0x391 for the ePMP CSRs. |
4 | only reserves first 8 bits of hpmeventX. Update the corresponding | ||
5 | masks accordingly. | ||
6 | 4 | ||
7 | [1]https://github.com/riscv/riscv-isa-manual/issues/1578 | 5 | Signed-off-by: Hongzheng-Li <Ethan.Lee.QNL@gmail.com> |
8 | 6 | Signed-off-by: Hou Weiying <weiying_hou@outlook.com> | |
9 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 7 | Signed-off-by: Myriad-Dreamin <camiyoru@gmail.com> |
10 | Signed-off-by: Atish Patra <atishp@rivosinc.com> | 8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
11 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | Message-ID: <20250206-pmu_minor_fixes-v2-1-1bb0f4aeb8b4@rivosinc.com> | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
11 | Message-id: 63245b559f477a9ce6d4f930136d2d7fd7f99c78.1618812899.git.alistair.francis@wdc.com | ||
12 | [ Changes by AF: | ||
13 | - Tidy up commit message | ||
14 | ] | ||
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
16 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
14 | --- | 17 | --- |
15 | target/riscv/cpu_bits.h | 5 ++--- | 18 | target/riscv/cpu_bits.h | 3 +++ |
16 | 1 file changed, 2 insertions(+), 3 deletions(-) | 19 | 1 file changed, 3 insertions(+) |
17 | 20 | ||
18 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h | 21 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h |
19 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/riscv/cpu_bits.h | 23 | --- a/target/riscv/cpu_bits.h |
21 | +++ b/target/riscv/cpu_bits.h | 24 | +++ b/target/riscv/cpu_bits.h |
22 | @@ -XXX,XX +XXX,XX @@ typedef enum CTRType { | 25 | @@ -XXX,XX +XXX,XX @@ |
23 | MHPMEVENTH_BIT_VSINH | \ | 26 | #define CSR_MTINST 0x34a |
24 | MHPMEVENTH_BIT_VUINH) | 27 | #define CSR_MTVAL2 0x34b |
25 | 28 | ||
26 | -#define MHPMEVENT_SSCOF_MASK _ULL(0xFFFF000000000000) | 29 | +/* Enhanced Physical Memory Protection (ePMP) */ |
27 | -#define MHPMEVENT_IDX_MASK 0xFFFFF | 30 | +#define CSR_MSECCFG 0x390 |
28 | -#define MHPMEVENT_SSCOF_RESVD 16 | 31 | +#define CSR_MSECCFGH 0x391 |
29 | +#define MHPMEVENT_SSCOF_MASK MAKE_64BIT_MASK(63, 56) | 32 | /* Physical Memory Protection */ |
30 | +#define MHPMEVENT_IDX_MASK (~MHPMEVENT_SSCOF_MASK) | 33 | #define CSR_PMPCFG0 0x3a0 |
31 | 34 | #define CSR_PMPCFG1 0x3a1 | |
32 | /* RISC-V-specific interrupt pending bits. */ | ||
33 | #define CPU_INTERRUPT_RNMI CPU_INTERRUPT_TGT_EXT_0 | ||
34 | -- | 35 | -- |
35 | 2.48.1 | 36 | 2.31.1 |
37 | |||
38 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | The spec is avaliable at: |
---|---|---|---|
2 | https://docs.google.com/document/d/1Mh_aiHYxemL0umN3GTTw8vsbmzHZ_nxZXgjgOUzbvc8 | ||
2 | 3 | ||
3 | This header is incomplete, i.e. it is using definitions that are being | 4 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
4 | supplied by the .c files that are including it. | 5 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> |
6 | Message-id: 28c8855c80b0388a08c3ae009f5467e2b3960ce0.1618812899.git.alistair.francis@wdc.com | ||
7 | --- | ||
8 | target/riscv/cpu.h | 1 + | ||
9 | 1 file changed, 1 insertion(+) | ||
5 | 10 | ||
6 | Adding this header into a fresh .c file will result in errors: | 11 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
7 | |||
8 | /home/danielhb/work/qemu/hw/riscv/riscv-iommu.h:30:17: error: field ‘parent_obj’ has incomplete type | ||
9 | 30 | DeviceState parent_obj; | ||
10 | | ^~~~~~~~~~ | ||
11 | /home/danielhb/work/qemu/hw/riscv/riscv-iommu.h:50:5: error: unknown type name ‘dma_addr_t’; did you mean ‘in_addr_t’? | ||
12 | 50 | dma_addr_t cq_addr; /* Command queue base physical address */ | ||
13 | | ^~~~~~~~~~ | ||
14 | | in_addr_t | ||
15 | (...) | ||
16 | /home/danielhb/work/qemu/hw/riscv/riscv-iommu.h:62:5: error: unknown type name ‘QemuThread’; did you mean ‘GThread’? | ||
17 | 62 | QemuThread core_proc; /* Background processing thread */ | ||
18 | | ^~~~~~~~~~ | ||
19 | | GThread | ||
20 | /home/danielhb/work/qemu/hw/riscv/riscv-iommu.h:63:5: error: unknown type name ‘QemuCond’ | ||
21 | 63 | QemuCond core_cond; /* Background processing wake up signal */ | ||
22 | | ^~~~~~~~ | ||
23 | /home/danielhb/work/qemu/hw/riscv/riscv-iommu.h:71:18: error: field ‘trap_as’ has incomplete type | ||
24 | 71 | AddressSpace trap_as; | ||
25 | | ^~~~~~~ | ||
26 | /home/danielhb/work/qemu/hw/riscv/riscv-iommu.h:72:18: error: field ‘trap_mr’ has incomplete type | ||
27 | 72 | MemoryRegion trap_mr; | ||
28 | | ^~~~~~~ | ||
29 | /home/danielhb/work/qemu/hw/riscv/riscv-iommu.h:80:18: error: field ‘regs_mr’ has incomplete type | ||
30 | 80 | MemoryRegion regs_mr; | ||
31 | | ^~~~~~~ | ||
32 | |||
33 | Fix it by adding the missing headers for these definitions. | ||
34 | |||
35 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
36 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
37 | Message-ID: <20250224190826.1858473-2-dbarboza@ventanamicro.com> | ||
38 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
39 | --- | ||
40 | hw/riscv/riscv-iommu.h | 2 ++ | ||
41 | 1 file changed, 2 insertions(+) | ||
42 | |||
43 | diff --git a/hw/riscv/riscv-iommu.h b/hw/riscv/riscv-iommu.h | ||
44 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
45 | --- a/hw/riscv/riscv-iommu.h | 13 | --- a/target/riscv/cpu.h |
46 | +++ b/hw/riscv/riscv-iommu.h | 14 | +++ b/target/riscv/cpu.h |
47 | @@ -XXX,XX +XXX,XX @@ | 15 | @@ -XXX,XX +XXX,XX @@ |
48 | #define HW_RISCV_IOMMU_STATE_H | 16 | enum { |
49 | 17 | RISCV_FEATURE_MMU, | |
50 | #include "qom/object.h" | 18 | RISCV_FEATURE_PMP, |
51 | +#include "hw/qdev-properties.h" | 19 | + RISCV_FEATURE_EPMP, |
52 | +#include "system/dma.h" | 20 | RISCV_FEATURE_MISA |
53 | #include "hw/riscv/iommu.h" | 21 | }; |
54 | #include "hw/riscv/riscv-iommu-bits.h" | ||
55 | 22 | ||
56 | -- | 23 | -- |
57 | 2.48.1 | 24 | 2.31.1 |
58 | 25 | ||
59 | 26 | diff view generated by jsdifflib |
1 | From: Rajnesh Kanwal <rkanwal@rivosinc.com> | 1 | From: Hou Weiying <weiying_hou@outlook.com> |
---|---|---|---|
2 | 2 | ||
3 | This commit adds support for [m|s|vs]ctrcontrol, sctrstatus and | 3 | Signed-off-by: Hongzheng-Li <Ethan.Lee.QNL@gmail.com> |
4 | sctrdepth CSRs handling. | 4 | Signed-off-by: Hou Weiying <weiying_hou@outlook.com> |
5 | 5 | Signed-off-by: Myriad-Dreamin <camiyoru@gmail.com> | |
6 | Signed-off-by: Rajnesh Kanwal <rkanwal@rivosinc.com> | ||
7 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Message-ID: <20250205-b4-ctr_upstream_v6-v6-3-439d8e06c8ef@rivosinc.com> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 6 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
7 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
8 | Message-id: 270762cb2507fba6a9eeb99a774cf49f7da9cc32.1618812899.git.alistair.francis@wdc.com | ||
9 | [ Changes by AF: | ||
10 | - Rebase on master | ||
11 | - Fix build errors | ||
12 | - Fix some style issues | ||
13 | ] | ||
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
15 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
10 | --- | 16 | --- |
11 | target/riscv/cpu.h | 5 ++ | 17 | target/riscv/cpu.h | 1 + |
12 | target/riscv/cpu_cfg.h | 2 + | 18 | target/riscv/pmp.h | 14 ++++++++++++++ |
13 | target/riscv/csr.c | 144 +++++++++++++++++++++++++++++++++++++++++ | 19 | target/riscv/csr.c | 24 ++++++++++++++++++++++++ |
14 | 3 files changed, 151 insertions(+) | 20 | target/riscv/pmp.c | 34 ++++++++++++++++++++++++++++++++++ |
21 | target/riscv/trace-events | 3 +++ | ||
22 | 5 files changed, 76 insertions(+) | ||
15 | 23 | ||
16 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 24 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
17 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/riscv/cpu.h | 26 | --- a/target/riscv/cpu.h |
19 | +++ b/target/riscv/cpu.h | 27 | +++ b/target/riscv/cpu.h |
20 | @@ -XXX,XX +XXX,XX @@ struct CPUArchState { | 28 | @@ -XXX,XX +XXX,XX @@ struct CPURISCVState { |
21 | target_ulong mcause; | 29 | |
22 | target_ulong mtval; /* since: priv-1.10.0 */ | 30 | /* physical memory protection */ |
23 | 31 | pmp_table_t pmp_state; | |
24 | + uint64_t mctrctl; | 32 | + target_ulong mseccfg; |
25 | + uint32_t sctrdepth; | 33 | |
26 | + uint32_t sctrstatus; | 34 | /* machine specific rdtime callback */ |
27 | + uint64_t vsctrctl; | 35 | uint64_t (*rdtime_fn)(uint32_t); |
36 | diff --git a/target/riscv/pmp.h b/target/riscv/pmp.h | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/target/riscv/pmp.h | ||
39 | +++ b/target/riscv/pmp.h | ||
40 | @@ -XXX,XX +XXX,XX @@ typedef enum { | ||
41 | PMP_AMATCH_NAPOT /* Naturally aligned power-of-two region */ | ||
42 | } pmp_am_t; | ||
43 | |||
44 | +typedef enum { | ||
45 | + MSECCFG_MML = 1 << 0, | ||
46 | + MSECCFG_MMWP = 1 << 1, | ||
47 | + MSECCFG_RLB = 1 << 2 | ||
48 | +} mseccfg_field_t; | ||
28 | + | 49 | + |
29 | /* Machine and Supervisor interrupt priorities */ | 50 | typedef struct { |
30 | uint8_t miprio[64]; | 51 | target_ulong addr_reg; |
31 | uint8_t siprio[64]; | 52 | uint8_t cfg_reg; |
32 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h | 53 | @@ -XXX,XX +XXX,XX @@ typedef struct { |
33 | index XXXXXXX..XXXXXXX 100644 | 54 | void pmpcfg_csr_write(CPURISCVState *env, uint32_t reg_index, |
34 | --- a/target/riscv/cpu_cfg.h | 55 | target_ulong val); |
35 | +++ b/target/riscv/cpu_cfg.h | 56 | target_ulong pmpcfg_csr_read(CPURISCVState *env, uint32_t reg_index); |
36 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { | 57 | + |
37 | bool ext_zvfhmin; | 58 | +void mseccfg_csr_write(CPURISCVState *env, target_ulong val); |
38 | bool ext_smaia; | 59 | +target_ulong mseccfg_csr_read(CPURISCVState *env); |
39 | bool ext_ssaia; | 60 | + |
40 | + bool ext_smctr; | 61 | void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index, |
41 | + bool ext_ssctr; | 62 | target_ulong val); |
42 | bool ext_sscofpmf; | 63 | target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index); |
43 | bool ext_smepmp; | 64 | @@ -XXX,XX +XXX,XX @@ void pmp_update_rule_nums(CPURISCVState *env); |
44 | bool ext_smrnmi; | 65 | uint32_t pmp_get_num_rules(CPURISCVState *env); |
66 | int pmp_priv_to_page_prot(pmp_priv_t pmp_priv); | ||
67 | |||
68 | +#define MSECCFG_MML_ISSET(env) get_field(env->mseccfg, MSECCFG_MML) | ||
69 | +#define MSECCFG_MMWP_ISSET(env) get_field(env->mseccfg, MSECCFG_MMWP) | ||
70 | +#define MSECCFG_RLB_ISSET(env) get_field(env->mseccfg, MSECCFG_RLB) | ||
71 | + | ||
72 | #endif | ||
45 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 73 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
46 | index XXXXXXX..XXXXXXX 100644 | 74 | index XXXXXXX..XXXXXXX 100644 |
47 | --- a/target/riscv/csr.c | 75 | --- a/target/riscv/csr.c |
48 | +++ b/target/riscv/csr.c | 76 | +++ b/target/riscv/csr.c |
49 | @@ -XXX,XX +XXX,XX @@ static RISCVException hgatp(CPURISCVState *env, int csrno) | 77 | @@ -XXX,XX +XXX,XX @@ static RISCVException pmp(CPURISCVState *env, int csrno) |
50 | return hmode(env, csrno); | 78 | |
79 | return RISCV_EXCP_ILLEGAL_INST; | ||
51 | } | 80 | } |
52 | 81 | + | |
53 | +/* | 82 | +static RISCVException epmp(CPURISCVState *env, int csrno) |
54 | + * M-mode: | ||
55 | + * Without ext_smctr raise illegal inst excep. | ||
56 | + * Otherwise everything is accessible to m-mode. | ||
57 | + * | ||
58 | + * S-mode: | ||
59 | + * Without ext_ssctr or mstateen.ctr raise illegal inst excep. | ||
60 | + * Otherwise everything other than mctrctl is accessible. | ||
61 | + * | ||
62 | + * VS-mode: | ||
63 | + * Without ext_ssctr or mstateen.ctr raise illegal inst excep. | ||
64 | + * Without hstateen.ctr raise virtual illegal inst excep. | ||
65 | + * Otherwise allow sctrctl (vsctrctl), sctrstatus, 0x200-0x2ff entry range. | ||
66 | + * Always raise illegal instruction exception for sctrdepth. | ||
67 | + */ | ||
68 | +static RISCVException ctr_mmode(CPURISCVState *env, int csrno) | ||
69 | +{ | 83 | +{ |
70 | + /* Check if smctr-ext is present */ | 84 | + if (env->priv == PRV_M && riscv_feature(env, RISCV_FEATURE_EPMP)) { |
71 | + if (riscv_cpu_cfg(env)->ext_smctr) { | ||
72 | + return RISCV_EXCP_NONE; | 85 | + return RISCV_EXCP_NONE; |
73 | + } | 86 | + } |
74 | + | 87 | + |
75 | + return RISCV_EXCP_ILLEGAL_INST; | 88 | + return RISCV_EXCP_ILLEGAL_INST; |
76 | +} | 89 | +} |
77 | + | 90 | #endif |
78 | +static RISCVException ctr_smode(CPURISCVState *env, int csrno) | 91 | |
92 | /* User Floating-Point CSRs */ | ||
93 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_mtinst(CPURISCVState *env, int csrno, | ||
94 | } | ||
95 | |||
96 | /* Physical Memory Protection */ | ||
97 | +static RISCVException read_mseccfg(CPURISCVState *env, int csrno, | ||
98 | + target_ulong *val) | ||
79 | +{ | 99 | +{ |
80 | + const RISCVCPUConfig *cfg = riscv_cpu_cfg(env); | 100 | + *val = mseccfg_csr_read(env); |
81 | + | ||
82 | + if (!cfg->ext_smctr && !cfg->ext_ssctr) { | ||
83 | + return RISCV_EXCP_ILLEGAL_INST; | ||
84 | + } | ||
85 | + | ||
86 | + RISCVException ret = smstateen_acc_ok(env, 0, SMSTATEEN0_CTR); | ||
87 | + if (ret == RISCV_EXCP_NONE && csrno == CSR_SCTRDEPTH && | ||
88 | + env->virt_enabled) { | ||
89 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
90 | + } | ||
91 | + | ||
92 | + return ret; | ||
93 | +} | ||
94 | + | ||
95 | static RISCVException aia_hmode(CPURISCVState *env, int csrno) | ||
96 | { | ||
97 | int ret; | ||
98 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_mstateen0(CPURISCVState *env, int csrno, | ||
99 | wr_mask |= (SMSTATEEN0_AIA | SMSTATEEN0_IMSIC); | ||
100 | } | ||
101 | |||
102 | + if (riscv_cpu_cfg(env)->ext_ssctr) { | ||
103 | + wr_mask |= SMSTATEEN0_CTR; | ||
104 | + } | ||
105 | + | ||
106 | return write_mstateen(env, csrno, wr_mask, new_val); | ||
107 | } | ||
108 | |||
109 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_mstateen0h(CPURISCVState *env, int csrno, | ||
110 | wr_mask |= SMSTATEEN0_P1P13; | ||
111 | } | ||
112 | |||
113 | + if (riscv_cpu_cfg(env)->ext_ssctr) { | ||
114 | + wr_mask |= SMSTATEEN0_CTR; | ||
115 | + } | ||
116 | + | ||
117 | return write_mstateenh(env, csrno, wr_mask, new_val); | ||
118 | } | ||
119 | |||
120 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_hstateen0(CPURISCVState *env, int csrno, | ||
121 | wr_mask |= (SMSTATEEN0_AIA | SMSTATEEN0_IMSIC); | ||
122 | } | ||
123 | |||
124 | + if (riscv_cpu_cfg(env)->ext_ssctr) { | ||
125 | + wr_mask |= SMSTATEEN0_CTR; | ||
126 | + } | ||
127 | + | ||
128 | return write_hstateen(env, csrno, wr_mask, new_val); | ||
129 | } | ||
130 | |||
131 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_hstateen0h(CPURISCVState *env, int csrno, | ||
132 | { | ||
133 | uint64_t wr_mask = SMSTATEEN_STATEEN | SMSTATEEN0_HSENVCFG; | ||
134 | |||
135 | + if (riscv_cpu_cfg(env)->ext_ssctr) { | ||
136 | + wr_mask |= SMSTATEEN0_CTR; | ||
137 | + } | ||
138 | + | ||
139 | return write_hstateenh(env, csrno, wr_mask, new_val); | ||
140 | } | ||
141 | |||
142 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_satp(CPURISCVState *env, int csrno, | ||
143 | return RISCV_EXCP_NONE; | ||
144 | } | ||
145 | |||
146 | +static RISCVException rmw_sctrdepth(CPURISCVState *env, int csrno, | ||
147 | + target_ulong *ret_val, | ||
148 | + target_ulong new_val, target_ulong wr_mask) | ||
149 | +{ | ||
150 | + uint64_t mask = wr_mask & SCTRDEPTH_MASK; | ||
151 | + | ||
152 | + if (ret_val) { | ||
153 | + *ret_val = env->sctrdepth; | ||
154 | + } | ||
155 | + | ||
156 | + env->sctrdepth = (env->sctrdepth & ~mask) | (new_val & mask); | ||
157 | + | ||
158 | + /* Correct depth. */ | ||
159 | + if (mask) { | ||
160 | + uint64_t depth = get_field(env->sctrdepth, SCTRDEPTH_MASK); | ||
161 | + | ||
162 | + if (depth > SCTRDEPTH_MAX) { | ||
163 | + depth = SCTRDEPTH_MAX; | ||
164 | + env->sctrdepth = set_field(env->sctrdepth, SCTRDEPTH_MASK, depth); | ||
165 | + } | ||
166 | + | ||
167 | + /* Update sctrstatus.WRPTR with a legal value */ | ||
168 | + depth = 16 << depth; | ||
169 | + env->sctrstatus = | ||
170 | + env->sctrstatus & (~SCTRSTATUS_WRPTR_MASK | (depth - 1)); | ||
171 | + } | ||
172 | + | ||
173 | + return RISCV_EXCP_NONE; | 101 | + return RISCV_EXCP_NONE; |
174 | +} | 102 | +} |
175 | + | 103 | + |
176 | +static RISCVException rmw_sctrstatus(CPURISCVState *env, int csrno, | 104 | +static RISCVException write_mseccfg(CPURISCVState *env, int csrno, |
177 | + target_ulong *ret_val, | 105 | + target_ulong val) |
178 | + target_ulong new_val, target_ulong wr_mask) | ||
179 | +{ | 106 | +{ |
180 | + uint32_t depth = 16 << get_field(env->sctrdepth, SCTRDEPTH_MASK); | 107 | + mseccfg_csr_write(env, val); |
181 | + uint32_t mask = wr_mask & SCTRSTATUS_MASK; | ||
182 | + | ||
183 | + if (ret_val) { | ||
184 | + *ret_val = env->sctrstatus; | ||
185 | + } | ||
186 | + | ||
187 | + env->sctrstatus = (env->sctrstatus & ~mask) | (new_val & mask); | ||
188 | + | ||
189 | + /* Update sctrstatus.WRPTR with a legal value */ | ||
190 | + env->sctrstatus = env->sctrstatus & (~SCTRSTATUS_WRPTR_MASK | (depth - 1)); | ||
191 | + | ||
192 | + return RISCV_EXCP_NONE; | 108 | + return RISCV_EXCP_NONE; |
193 | +} | 109 | +} |
194 | + | 110 | + |
195 | +static RISCVException rmw_xctrctl(CPURISCVState *env, int csrno, | 111 | static RISCVException read_pmpcfg(CPURISCVState *env, int csrno, |
196 | + target_ulong *ret_val, | ||
197 | + target_ulong new_val, target_ulong wr_mask) | ||
198 | +{ | ||
199 | + uint64_t csr_mask, mask = wr_mask; | ||
200 | + uint64_t *ctl_ptr = &env->mctrctl; | ||
201 | + | ||
202 | + if (csrno == CSR_MCTRCTL) { | ||
203 | + csr_mask = MCTRCTL_MASK; | ||
204 | + } else if (csrno == CSR_SCTRCTL && !env->virt_enabled) { | ||
205 | + csr_mask = SCTRCTL_MASK; | ||
206 | + } else { | ||
207 | + /* | ||
208 | + * This is for csrno == CSR_SCTRCTL and env->virt_enabled == true | ||
209 | + * or csrno == CSR_VSCTRCTL. | ||
210 | + */ | ||
211 | + csr_mask = VSCTRCTL_MASK; | ||
212 | + ctl_ptr = &env->vsctrctl; | ||
213 | + } | ||
214 | + | ||
215 | + mask &= csr_mask; | ||
216 | + | ||
217 | + if (ret_val) { | ||
218 | + *ret_val = *ctl_ptr & csr_mask; | ||
219 | + } | ||
220 | + | ||
221 | + *ctl_ptr = (*ctl_ptr & ~mask) | (new_val & mask); | ||
222 | + | ||
223 | + return RISCV_EXCP_NONE; | ||
224 | +} | ||
225 | + | ||
226 | static RISCVException read_vstopi(CPURISCVState *env, int csrno, | ||
227 | target_ulong *val) | 112 | target_ulong *val) |
228 | { | 113 | { |
229 | @@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { | 114 | @@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { |
230 | [CSR_TINFO] = { "tinfo", debug, read_tinfo, write_ignore }, | 115 | [CSR_MTINST] = { "mtinst", hmode, read_mtinst, write_mtinst }, |
231 | [CSR_MCONTEXT] = { "mcontext", debug, read_mcontext, write_mcontext }, | 116 | |
232 | 117 | /* Physical Memory Protection */ | |
233 | + [CSR_MCTRCTL] = { "mctrctl", ctr_mmode, NULL, NULL, rmw_xctrctl }, | 118 | + [CSR_MSECCFG] = { "mseccfg", epmp, read_mseccfg, write_mseccfg }, |
234 | + [CSR_SCTRCTL] = { "sctrctl", ctr_smode, NULL, NULL, rmw_xctrctl }, | 119 | [CSR_PMPCFG0] = { "pmpcfg0", pmp, read_pmpcfg, write_pmpcfg }, |
235 | + [CSR_VSCTRCTL] = { "vsctrctl", ctr_smode, NULL, NULL, rmw_xctrctl }, | 120 | [CSR_PMPCFG1] = { "pmpcfg1", pmp, read_pmpcfg, write_pmpcfg }, |
236 | + [CSR_SCTRDEPTH] = { "sctrdepth", ctr_smode, NULL, NULL, rmw_sctrdepth }, | 121 | [CSR_PMPCFG2] = { "pmpcfg2", pmp, read_pmpcfg, write_pmpcfg }, |
237 | + [CSR_SCTRSTATUS] = { "sctrstatus", ctr_smode, NULL, NULL, rmw_sctrstatus }, | 122 | diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c |
123 | index XXXXXXX..XXXXXXX 100644 | ||
124 | --- a/target/riscv/pmp.c | ||
125 | +++ b/target/riscv/pmp.c | ||
126 | @@ -XXX,XX +XXX,XX @@ target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index) | ||
127 | return val; | ||
128 | } | ||
129 | |||
130 | +/* | ||
131 | + * Handle a write to a mseccfg CSR | ||
132 | + */ | ||
133 | +void mseccfg_csr_write(CPURISCVState *env, target_ulong val) | ||
134 | +{ | ||
135 | + int i; | ||
238 | + | 136 | + |
239 | /* Performance Counters */ | 137 | + trace_mseccfg_csr_write(env->mhartid, val); |
240 | [CSR_HPMCOUNTER3] = { "hpmcounter3", ctr, read_hpmcounter }, | 138 | + |
241 | [CSR_HPMCOUNTER4] = { "hpmcounter4", ctr, read_hpmcounter }, | 139 | + /* RLB cannot be enabled if it's already 0 and if any regions are locked */ |
140 | + if (!MSECCFG_RLB_ISSET(env)) { | ||
141 | + for (i = 0; i < MAX_RISCV_PMPS; i++) { | ||
142 | + if (pmp_is_locked(env, i)) { | ||
143 | + val &= ~MSECCFG_RLB; | ||
144 | + break; | ||
145 | + } | ||
146 | + } | ||
147 | + } | ||
148 | + | ||
149 | + /* Sticky bits */ | ||
150 | + val |= (env->mseccfg & (MSECCFG_MMWP | MSECCFG_MML)); | ||
151 | + | ||
152 | + env->mseccfg = val; | ||
153 | +} | ||
154 | + | ||
155 | +/* | ||
156 | + * Handle a read from a mseccfg CSR | ||
157 | + */ | ||
158 | +target_ulong mseccfg_csr_read(CPURISCVState *env) | ||
159 | +{ | ||
160 | + trace_mseccfg_csr_read(env->mhartid, env->mseccfg); | ||
161 | + return env->mseccfg; | ||
162 | +} | ||
163 | + | ||
164 | /* | ||
165 | * Calculate the TLB size if the start address or the end address of | ||
166 | * PMP entry is presented in thie TLB page. | ||
167 | diff --git a/target/riscv/trace-events b/target/riscv/trace-events | ||
168 | index XXXXXXX..XXXXXXX 100644 | ||
169 | --- a/target/riscv/trace-events | ||
170 | +++ b/target/riscv/trace-events | ||
171 | @@ -XXX,XX +XXX,XX @@ pmpcfg_csr_read(uint64_t mhartid, uint32_t reg_index, uint64_t val) "hart %" PRI | ||
172 | pmpcfg_csr_write(uint64_t mhartid, uint32_t reg_index, uint64_t val) "hart %" PRIu64 ": write reg%" PRIu32", val: 0x%" PRIx64 | ||
173 | pmpaddr_csr_read(uint64_t mhartid, uint32_t addr_index, uint64_t val) "hart %" PRIu64 ": read addr%" PRIu32", val: 0x%" PRIx64 | ||
174 | pmpaddr_csr_write(uint64_t mhartid, uint32_t addr_index, uint64_t val) "hart %" PRIu64 ": write addr%" PRIu32", val: 0x%" PRIx64 | ||
175 | + | ||
176 | +mseccfg_csr_read(uint64_t mhartid, uint64_t val) "hart %" PRIu64 ": read mseccfg, val: 0x%" PRIx64 | ||
177 | +mseccfg_csr_write(uint64_t mhartid, uint64_t val) "hart %" PRIu64 ": write mseccfg, val: 0x%" PRIx64 | ||
242 | -- | 178 | -- |
243 | 2.48.1 | 179 | 2.31.1 |
180 | |||
181 | diff view generated by jsdifflib |
1 | From: Tomasz Jeznach <tjeznach@rivosinc.com> | 1 | From: Hou Weiying <weiying_hou@outlook.com> |
---|---|---|---|
2 | 2 | ||
3 | Now that we have every piece in place we can advertise CAP_HTM to | 3 | This commit adds support for ePMP v0.9.1. |
4 | software, allowing any HPM aware driver to make use of the counters. | 4 | |
5 | 5 | The ePMP spec can be found in: | |
6 | HPM is enabled/disabled via the 'hpm-counters' attribute. Default value | 6 | https://docs.google.com/document/d/1Mh_aiHYxemL0umN3GTTw8vsbmzHZ_nxZXgjgOUzbvc8 |
7 | is 31, max value is also 31. Setting it to zero will disable HPM | 7 | |
8 | support. | 8 | Signed-off-by: Hongzheng-Li <Ethan.Lee.QNL@gmail.com> |
9 | 9 | Signed-off-by: Hou Weiying <weiying_hou@outlook.com> | |
10 | Signed-off-by: Tomasz Jeznach <tjeznach@rivosinc.com> | 10 | Signed-off-by: Myriad-Dreamin <camiyoru@gmail.com> |
11 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> |
13 | Message-ID: <20250224190826.1858473-10-dbarboza@ventanamicro.com> | 13 | Message-id: fef23b885f9649a4d54e7c98b168bdec5d297bb1.1618812899.git.alistair.francis@wdc.com |
14 | [ Changes by AF: | ||
15 | - Rebase on master | ||
16 | - Update to latest spec | ||
17 | - Use a switch case to handle ePMP MML permissions | ||
18 | - Fix a few bugs | ||
19 | ] | ||
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 20 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
15 | --- | 21 | --- |
16 | hw/riscv/riscv-iommu.c | 21 +++++++++++++++++++++ | 22 | target/riscv/pmp.c | 154 ++++++++++++++++++++++++++++++++++++++++++--- |
17 | 1 file changed, 21 insertions(+) | 23 | 1 file changed, 146 insertions(+), 8 deletions(-) |
18 | 24 | ||
19 | diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c | 25 | diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c |
20 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/hw/riscv/riscv-iommu.c | 27 | --- a/target/riscv/pmp.c |
22 | +++ b/hw/riscv/riscv-iommu.c | 28 | +++ b/target/riscv/pmp.c |
23 | @@ -XXX,XX +XXX,XX @@ static void riscv_iommu_realize(DeviceState *dev, Error **errp) | 29 | @@ -XXX,XX +XXX,XX @@ static inline uint8_t pmp_read_cfg(CPURISCVState *env, uint32_t pmp_index) |
24 | RISCV_IOMMU_CAP_SV48X4 | RISCV_IOMMU_CAP_SV57X4; | 30 | static void pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val) |
25 | } | 31 | { |
26 | 32 | if (pmp_index < MAX_RISCV_PMPS) { | |
27 | + if (s->hpm_cntrs > 0) { | 33 | - if (!pmp_is_locked(env, pmp_index)) { |
28 | + /* Clip number of HPM counters to maximum supported (31). */ | 34 | - env->pmp_state.pmp[pmp_index].cfg_reg = val; |
29 | + if (s->hpm_cntrs > RISCV_IOMMU_IOCOUNT_NUM) { | 35 | - pmp_update_rule(env, pmp_index); |
30 | + s->hpm_cntrs = RISCV_IOMMU_IOCOUNT_NUM; | 36 | + bool locked = true; |
37 | + | ||
38 | + if (riscv_feature(env, RISCV_FEATURE_EPMP)) { | ||
39 | + /* mseccfg.RLB is set */ | ||
40 | + if (MSECCFG_RLB_ISSET(env)) { | ||
41 | + locked = false; | ||
42 | + } | ||
43 | + | ||
44 | + /* mseccfg.MML is not set */ | ||
45 | + if (!MSECCFG_MML_ISSET(env) && !pmp_is_locked(env, pmp_index)) { | ||
46 | + locked = false; | ||
47 | + } | ||
48 | + | ||
49 | + /* mseccfg.MML is set */ | ||
50 | + if (MSECCFG_MML_ISSET(env)) { | ||
51 | + /* not adding execute bit */ | ||
52 | + if ((val & PMP_LOCK) != 0 && (val & PMP_EXEC) != PMP_EXEC) { | ||
53 | + locked = false; | ||
54 | + } | ||
55 | + /* shared region and not adding X bit */ | ||
56 | + if ((val & PMP_LOCK) != PMP_LOCK && | ||
57 | + (val & 0x7) != (PMP_WRITE | PMP_EXEC)) { | ||
58 | + locked = false; | ||
59 | + } | ||
60 | + } | ||
61 | } else { | ||
62 | + if (!pmp_is_locked(env, pmp_index)) { | ||
63 | + locked = false; | ||
64 | + } | ||
31 | + } | 65 | + } |
32 | + /* Enable hardware performance monitor interface */ | 66 | + |
33 | + s->cap |= RISCV_IOMMU_CAP_HPM; | 67 | + if (locked) { |
68 | qemu_log_mask(LOG_GUEST_ERROR, "ignoring pmpcfg write - locked\n"); | ||
69 | + } else { | ||
70 | + env->pmp_state.pmp[pmp_index].cfg_reg = val; | ||
71 | + pmp_update_rule(env, pmp_index); | ||
72 | } | ||
73 | } else { | ||
74 | qemu_log_mask(LOG_GUEST_ERROR, | ||
75 | @@ -XXX,XX +XXX,XX @@ static bool pmp_hart_has_privs_default(CPURISCVState *env, target_ulong addr, | ||
76 | { | ||
77 | bool ret; | ||
78 | |||
79 | + if (riscv_feature(env, RISCV_FEATURE_EPMP)) { | ||
80 | + if (MSECCFG_MMWP_ISSET(env)) { | ||
81 | + /* | ||
82 | + * The Machine Mode Whitelist Policy (mseccfg.MMWP) is set | ||
83 | + * so we default to deny all, even for M-mode. | ||
84 | + */ | ||
85 | + *allowed_privs = 0; | ||
86 | + return false; | ||
87 | + } else if (MSECCFG_MML_ISSET(env)) { | ||
88 | + /* | ||
89 | + * The Machine Mode Lockdown (mseccfg.MML) bit is set | ||
90 | + * so we can only execute code in M-mode with an applicable | ||
91 | + * rule. Other modes are disabled. | ||
92 | + */ | ||
93 | + if (mode == PRV_M && !(privs & PMP_EXEC)) { | ||
94 | + ret = true; | ||
95 | + *allowed_privs = PMP_READ | PMP_WRITE; | ||
96 | + } else { | ||
97 | + ret = false; | ||
98 | + *allowed_privs = 0; | ||
99 | + } | ||
100 | + | ||
101 | + return ret; | ||
102 | + } | ||
34 | + } | 103 | + } |
35 | + | 104 | + |
36 | /* Out-of-reset translation mode: OFF (DMA disabled) BARE (passthrough) */ | 105 | if ((!riscv_feature(env, RISCV_FEATURE_PMP)) || (mode == PRV_M)) { |
37 | s->ddtp = set_field(0, RISCV_IOMMU_DDTP_MODE, s->enable_off ? | 106 | /* |
38 | RISCV_IOMMU_DDTP_MODE_OFF : RISCV_IOMMU_DDTP_MODE_BARE); | 107 | * Privileged spec v1.10 states if HW doesn't implement any PMP entry |
39 | @@ -XXX,XX +XXX,XX @@ static void riscv_iommu_realize(DeviceState *dev, Error **errp) | 108 | @@ -XXX,XX +XXX,XX @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr, |
40 | RISCV_IOMMU_TR_REQ_CTL_GO_BUSY); | 109 | pmp_get_a_field(env->pmp_state.pmp[i].cfg_reg); |
41 | } | 110 | |
42 | 111 | /* | |
43 | + /* If HPM registers are enabled. */ | 112 | - * If the PMP entry is not off and the address is in range, do the priv |
44 | + if (s->cap & RISCV_IOMMU_CAP_HPM) { | 113 | - * check |
45 | + /* +1 for cycle counter bit. */ | 114 | + * Convert the PMP permissions to match the truth table in the |
46 | + stl_le_p(&s->regs_ro[RISCV_IOMMU_REG_IOCOUNTINH], | 115 | + * ePMP spec. |
47 | + ~((2 << s->hpm_cntrs) - 1)); | 116 | */ |
48 | + stq_le_p(&s->regs_ro[RISCV_IOMMU_REG_IOHPMCYCLES], 0); | 117 | + const uint8_t epmp_operation = |
49 | + memset(&s->regs_ro[RISCV_IOMMU_REG_IOHPMCTR_BASE], | 118 | + ((env->pmp_state.pmp[i].cfg_reg & PMP_LOCK) >> 4) | |
50 | + 0x00, s->hpm_cntrs * 8); | 119 | + ((env->pmp_state.pmp[i].cfg_reg & PMP_READ) << 2) | |
51 | + memset(&s->regs_ro[RISCV_IOMMU_REG_IOHPMEVT_BASE], | 120 | + (env->pmp_state.pmp[i].cfg_reg & PMP_WRITE) | |
52 | + 0x00, s->hpm_cntrs * 8); | 121 | + ((env->pmp_state.pmp[i].cfg_reg & PMP_EXEC) >> 2); |
53 | + } | 122 | + |
54 | + | 123 | if (((s + e) == 2) && (PMP_AMATCH_OFF != a_field)) { |
55 | /* Memory region for downstream access, if specified. */ | 124 | - *allowed_privs = PMP_READ | PMP_WRITE | PMP_EXEC; |
56 | if (s->target_mr) { | 125 | - if ((mode != PRV_M) || pmp_is_locked(env, i)) { |
57 | s->target_as = g_new0(AddressSpace, 1); | 126 | - *allowed_privs &= env->pmp_state.pmp[i].cfg_reg; |
127 | + /* | ||
128 | + * If the PMP entry is not off and the address is in range, | ||
129 | + * do the priv check | ||
130 | + */ | ||
131 | + if (!MSECCFG_MML_ISSET(env)) { | ||
132 | + /* | ||
133 | + * If mseccfg.MML Bit is not set, do pmp priv check | ||
134 | + * This will always apply to regular PMP. | ||
135 | + */ | ||
136 | + *allowed_privs = PMP_READ | PMP_WRITE | PMP_EXEC; | ||
137 | + if ((mode != PRV_M) || pmp_is_locked(env, i)) { | ||
138 | + *allowed_privs &= env->pmp_state.pmp[i].cfg_reg; | ||
139 | + } | ||
140 | + } else { | ||
141 | + /* | ||
142 | + * If mseccfg.MML Bit set, do the enhanced pmp priv check | ||
143 | + */ | ||
144 | + if (mode == PRV_M) { | ||
145 | + switch (epmp_operation) { | ||
146 | + case 0: | ||
147 | + case 1: | ||
148 | + case 4: | ||
149 | + case 5: | ||
150 | + case 6: | ||
151 | + case 7: | ||
152 | + case 8: | ||
153 | + *allowed_privs = 0; | ||
154 | + break; | ||
155 | + case 2: | ||
156 | + case 3: | ||
157 | + case 14: | ||
158 | + *allowed_privs = PMP_READ | PMP_WRITE; | ||
159 | + break; | ||
160 | + case 9: | ||
161 | + case 10: | ||
162 | + *allowed_privs = PMP_EXEC; | ||
163 | + break; | ||
164 | + case 11: | ||
165 | + case 13: | ||
166 | + *allowed_privs = PMP_READ | PMP_EXEC; | ||
167 | + break; | ||
168 | + case 12: | ||
169 | + case 15: | ||
170 | + *allowed_privs = PMP_READ; | ||
171 | + break; | ||
172 | + } | ||
173 | + } else { | ||
174 | + switch (epmp_operation) { | ||
175 | + case 0: | ||
176 | + case 8: | ||
177 | + case 9: | ||
178 | + case 12: | ||
179 | + case 13: | ||
180 | + case 14: | ||
181 | + *allowed_privs = 0; | ||
182 | + break; | ||
183 | + case 1: | ||
184 | + case 10: | ||
185 | + case 11: | ||
186 | + *allowed_privs = PMP_EXEC; | ||
187 | + break; | ||
188 | + case 2: | ||
189 | + case 4: | ||
190 | + case 15: | ||
191 | + *allowed_privs = PMP_READ; | ||
192 | + break; | ||
193 | + case 3: | ||
194 | + case 6: | ||
195 | + *allowed_privs = PMP_READ | PMP_WRITE; | ||
196 | + break; | ||
197 | + case 5: | ||
198 | + *allowed_privs = PMP_READ | PMP_EXEC; | ||
199 | + break; | ||
200 | + case 7: | ||
201 | + *allowed_privs = PMP_READ | PMP_WRITE | PMP_EXEC; | ||
202 | + break; | ||
203 | + } | ||
204 | + } | ||
205 | } | ||
206 | |||
207 | ret = ((privs & *allowed_privs) == privs); | ||
58 | -- | 208 | -- |
59 | 2.48.1 | 209 | 2.31.1 |
210 | |||
211 | diff view generated by jsdifflib |
1 | From: Max Chou <max.chou@sifive.com> | 1 | From: Hou Weiying <weiying_hou@outlook.com> |
---|---|---|---|
2 | 2 | ||
3 | In prop_vlen_set function, there is an incorrect comparison between | 3 | Add a config option to enable experimental support for ePMP. This |
4 | vlen(bit) and vlenb(byte). | 4 | is disabled by default and can be enabled with 'x-epmp=true'. |
5 | This will cause unexpected error when user applies the `vlen=1024` cpu | ||
6 | option with a vendor predefined cpu type that the default vlen is | ||
7 | 1024(vlenb=128). | ||
8 | 5 | ||
9 | Fixes: 4f6d036ccc ("target/riscv/cpu.c: remove cpu->cfg.vlen") | 6 | Signed-off-by: Hongzheng-Li <Ethan.Lee.QNL@gmail.com> |
10 | Signed-off-by: Max Chou <max.chou@sifive.com> | 7 | Signed-off-by: Hou Weiying <weiying_hou@outlook.com> |
11 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 8 | Signed-off-by: Myriad-Dreamin <camiyoru@gmail.com> |
12 | Message-ID: <20250124090539.2506448-1-max.chou@sifive.com> | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
11 | Message-id: a22ccdaf9314078bc735d3b323f966623f8af020.1618812899.git.alistair.francis@wdc.com | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
14 | --- | 14 | --- |
15 | target/riscv/cpu.c | 5 +++-- | 15 | target/riscv/cpu.h | 1 + |
16 | 1 file changed, 3 insertions(+), 2 deletions(-) | 16 | target/riscv/cpu.c | 10 ++++++++++ |
17 | 2 files changed, 11 insertions(+) | ||
17 | 18 | ||
19 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/target/riscv/cpu.h | ||
22 | +++ b/target/riscv/cpu.h | ||
23 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPU { | ||
24 | uint16_t elen; | ||
25 | bool mmu; | ||
26 | bool pmp; | ||
27 | + bool epmp; | ||
28 | uint64_t resetvec; | ||
29 | } cfg; | ||
30 | }; | ||
18 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 31 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
19 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/riscv/cpu.c | 33 | --- a/target/riscv/cpu.c |
21 | +++ b/target/riscv/cpu.c | 34 | +++ b/target/riscv/cpu.c |
22 | @@ -XXX,XX +XXX,XX @@ static void prop_vlen_set(Object *obj, Visitor *v, const char *name, | 35 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) |
23 | void *opaque, Error **errp) | 36 | |
24 | { | 37 | if (cpu->cfg.pmp) { |
25 | RISCVCPU *cpu = RISCV_CPU(obj); | 38 | set_feature(env, RISCV_FEATURE_PMP); |
26 | + uint16_t cpu_vlen = cpu->cfg.vlenb << 3; | 39 | + |
27 | uint16_t value; | 40 | + /* |
28 | 41 | + * Enhanced PMP should only be available | |
29 | if (!visit_type_uint16(v, name, &value, errp)) { | 42 | + * on harts with PMP support |
30 | @@ -XXX,XX +XXX,XX @@ static void prop_vlen_set(Object *obj, Visitor *v, const char *name, | 43 | + */ |
31 | return; | 44 | + if (cpu->cfg.epmp) { |
45 | + set_feature(env, RISCV_FEATURE_EPMP); | ||
46 | + } | ||
32 | } | 47 | } |
33 | 48 | ||
34 | - if (value != cpu->cfg.vlenb && riscv_cpu_is_vendor(obj)) { | 49 | set_resetvec(env, cpu->cfg.resetvec); |
35 | + if (value != cpu_vlen && riscv_cpu_is_vendor(obj)) { | 50 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = { |
36 | cpu_set_prop_err(cpu, name, errp); | 51 | DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64), |
37 | error_append_hint(errp, "Current '%s' val: %u\n", | 52 | DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true), |
38 | - name, cpu->cfg.vlenb << 3); | 53 | DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true), |
39 | + name, cpu_vlen); | 54 | + DEFINE_PROP_BOOL("x-epmp", RISCVCPU, cfg.epmp, false), |
40 | return; | 55 | + |
41 | } | 56 | DEFINE_PROP_UINT64("resetvec", RISCVCPU, cfg.resetvec, DEFAULT_RSTVEC), |
42 | 57 | DEFINE_PROP_END_OF_LIST(), | |
58 | }; | ||
43 | -- | 59 | -- |
44 | 2.48.1 | 60 | 2.31.1 |
61 | |||
62 | diff view generated by jsdifflib |
1 | From: Rob Bradford <rbradford@rivosinc.com> | ||
---|---|---|---|
2 | |||
3 | When running in TOR mode (Top of Range) the next PMP entry controls | ||
4 | whether the entry is locked. However simply checking if the PMP_LOCK bit | ||
5 | is set is not sufficient with the Smepmp extension which now provides a | ||
6 | bit (mseccfg.RLB (Rule Lock Bypass)) to disregard the lock bits. In | ||
7 | order to respect this bit use the convenience pmp_is_locked() function | ||
8 | rather than directly checking PMP_LOCK since this function checks | ||
9 | mseccfg.RLB. | ||
10 | |||
11 | Signed-off-by: Rob Bradford <rbradford@rivosinc.com> | ||
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
14 | Message-ID: <20250210153713.343626-1-rbradford@rivosinc.com> | ||
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
2 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
3 | Message-id: 10387eec21d2f17c499a78fdba85280cab4dd27f.1618812899.git.alistair.francis@wdc.com | ||
16 | --- | 4 | --- |
17 | target/riscv/pmp.c | 2 +- | 5 | target/riscv/pmp.c | 4 ---- |
18 | 1 file changed, 1 insertion(+), 1 deletion(-) | 6 | 1 file changed, 4 deletions(-) |
19 | 7 | ||
20 | diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c | 8 | diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c |
21 | index XXXXXXX..XXXXXXX 100644 | 9 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/target/riscv/pmp.c | 10 | --- a/target/riscv/pmp.c |
23 | +++ b/target/riscv/pmp.c | 11 | +++ b/target/riscv/pmp.c |
24 | @@ -XXX,XX +XXX,XX @@ void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index, | 12 | @@ -XXX,XX +XXX,XX @@ |
25 | uint8_t pmp_cfg = env->pmp_state.pmp[addr_index + 1].cfg_reg; | 13 | * this program. If not, see <http://www.gnu.org/licenses/>. |
26 | is_next_cfg_tor = PMP_AMATCH_TOR == pmp_get_a_field(pmp_cfg); | 14 | */ |
27 | 15 | ||
28 | - if (pmp_cfg & PMP_LOCK && is_next_cfg_tor) { | 16 | -/* |
29 | + if (pmp_is_locked(env, addr_index + 1) && is_next_cfg_tor) { | 17 | - * PMP (Physical Memory Protection) is as-of-yet unused and needs testing. |
30 | qemu_log_mask(LOG_GUEST_ERROR, | 18 | - */ |
31 | "ignoring pmpaddr write - pmpcfg + 1 locked\n"); | 19 | - |
32 | return; | 20 | #include "qemu/osdep.h" |
21 | #include "qemu/log.h" | ||
22 | #include "qapi/error.h" | ||
33 | -- | 23 | -- |
34 | 2.48.1 | 24 | 2.31.1 |
25 | |||
26 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | The physical Ibex CPU has ePMP support and it's enabled for the |
---|---|---|---|
2 | OpenTitan machine so let's enable ePMP support for the Ibex CPU in QEMU. | ||
2 | 3 | ||
3 | From the time we added RVA22U64 until now the spec didn't declare 'RVB' | ||
4 | as a dependency, using zba/zbb/zbs instead. Since then the RVA22 spec | ||
5 | [1] added the following in the 'RVA22U64 Mandatory Extensions' section: | ||
6 | |||
7 | "B Bit-manipulation instructions | ||
8 | |||
9 | Note: The B extension comprises the Zba, Zbb, and Zbs extensions. At the | ||
10 | time of RVA22U64's ratification, the B extension had not yet been | ||
11 | defined, and so RVA22U64 explicitly mandated Zba, Zbb, and Zbs instead. | ||
12 | Mandating B is equivalent." | ||
13 | |||
14 | It is also equivalent to QEMU (see riscv_cpu_validate_b() in | ||
15 | target/riscv/tcg/tcg-cpu.c). | ||
16 | |||
17 | Finally, RVA23U64 [2] directly mentions RVB as a mandatory extension, | ||
18 | not citing zba/zbb/zbs. | ||
19 | |||
20 | To make it clear that RVA23U64 will extend RVA22U64 (i.e. RVA22 is a | ||
21 | parent of RVA23), use RVB in RVA22U64 as well. | ||
22 | |||
23 | (bios-tables-test change: RVB added to riscv,isa) | ||
24 | |||
25 | [1] https://github.com/riscv/riscv-profiles/blob/main/src/profiles.adoc#61-rva22u64-profile | ||
26 | [2] https://github.com/riscv/riscv-profiles/blob/main/src/rva23-profile.adoc#rva23u64-profile | ||
27 | |||
28 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
29 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
30 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
31 | Message-ID: <20250115184316.2344583-3-dbarboza@ventanamicro.com> | ||
32 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 4 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
5 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
6 | Message-id: d426baabab0c9361ed2e989dbe416e417a551fd1.1618812899.git.alistair.francis@wdc.com | ||
33 | --- | 7 | --- |
34 | target/riscv/cpu.c | 2 +- | 8 | target/riscv/cpu.c | 1 + |
35 | tests/data/acpi/riscv64/virt/RHCT | Bin 398 -> 400 bytes | 9 | 1 file changed, 1 insertion(+) |
36 | 2 files changed, 1 insertion(+), 1 deletion(-) | ||
37 | 10 | ||
38 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 11 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
39 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
40 | --- a/target/riscv/cpu.c | 13 | --- a/target/riscv/cpu.c |
41 | +++ b/target/riscv/cpu.c | 14 | +++ b/target/riscv/cpu.c |
42 | @@ -XXX,XX +XXX,XX @@ static const PropertyInfo prop_marchid = { | 15 | @@ -XXX,XX +XXX,XX @@ static void rv32_ibex_cpu_init(Object *obj) |
43 | static RISCVCPUProfile RVA22U64 = { | 16 | set_misa(env, RV32 | RVI | RVM | RVC | RVU); |
44 | .parent = NULL, | 17 | set_priv_version(env, PRIV_VERSION_1_10_0); |
45 | .name = "rva22u64", | 18 | qdev_prop_set_bit(DEVICE(obj), "mmu", false); |
46 | - .misa_ext = RVI | RVM | RVA | RVF | RVD | RVC | RVU, | 19 | + qdev_prop_set_bit(DEVICE(obj), "x-epmp", true); |
47 | + .misa_ext = RVI | RVM | RVA | RVF | RVD | RVC | RVB | RVU, | 20 | } |
48 | .priv_spec = RISCV_PROFILE_ATTR_UNUSED, | 21 | |
49 | .satp_mode = RISCV_PROFILE_ATTR_UNUSED, | 22 | static void rv32_imafcu_nommu_cpu_init(Object *obj) |
50 | .ext_offsets = { | ||
51 | diff --git a/tests/data/acpi/riscv64/virt/RHCT b/tests/data/acpi/riscv64/virt/RHCT | ||
52 | index XXXXXXX..XXXXXXX 100644 | ||
53 | Binary files a/tests/data/acpi/riscv64/virt/RHCT and b/tests/data/acpi/riscv64/virt/RHCT differ | ||
54 | -- | 23 | -- |
55 | 2.48.1 | 24 | 2.31.1 |
25 | |||
26 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Frank Chang <frank.chang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | The mcontrol select bit (19) is always zero, meaning our triggers will | 3 | ETYPE may be type of uint64_t, thus index variable has to be declared as |
4 | always match virtual addresses. In this condition, if the user does not | 4 | type of uint64_t, too. Otherwise the value read from vs1 register may be |
5 | specify a size for the trigger, the access size defaults to XLEN. | 5 | truncated to type of uint32_t. |
6 | 6 | ||
7 | At this moment we're using def_size = 8 regardless of CPU XLEN. Use | 7 | Signed-off-by: Frank Chang <frank.chang@sifive.com> |
8 | def_size = 4 in case we're running 32 bits. | 8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
9 | 9 | Message-id: 20210419060302.14075-1-frank.chang@sifive.com | |
10 | Fixes: 95799e36c1 ("target/riscv: Add initial support for the Sdtrig extension") | ||
11 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
14 | Message-ID: <20250121170626.1992570-2-dbarboza@ventanamicro.com> | ||
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
16 | --- | 11 | --- |
17 | target/riscv/debug.c | 6 ++++-- | 12 | target/riscv/vector_helper.c | 6 ++++-- |
18 | 1 file changed, 4 insertions(+), 2 deletions(-) | 13 | 1 file changed, 4 insertions(+), 2 deletions(-) |
19 | 14 | ||
20 | diff --git a/target/riscv/debug.c b/target/riscv/debug.c | 15 | diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c |
21 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/target/riscv/debug.c | 17 | --- a/target/riscv/vector_helper.c |
23 | +++ b/target/riscv/debug.c | 18 | +++ b/target/riscv/vector_helper.c |
24 | @@ -XXX,XX +XXX,XX @@ static void type2_breakpoint_insert(CPURISCVState *env, target_ulong index) | 19 | @@ -XXX,XX +XXX,XX @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, void *vs2, \ |
25 | bool enabled = type2_breakpoint_enabled(ctrl); | 20 | uint32_t vlmax = env_archcpu(env)->cfg.vlen / mlen; \ |
26 | CPUState *cs = env_cpu(env); | 21 | uint32_t vm = vext_vm(desc); \ |
27 | int flags = BP_CPU | BP_STOP_BEFORE_ACCESS; | 22 | uint32_t vl = env->vl; \ |
28 | - uint32_t size; | 23 | - uint32_t index, i; \ |
29 | + uint32_t size, def_size; | 24 | + uint64_t index; \ |
30 | 25 | + uint32_t i; \ | |
31 | if (!enabled) { | 26 | \ |
32 | return; | 27 | for (i = 0; i < vl; i++) { \ |
33 | @@ -XXX,XX +XXX,XX @@ static void type2_breakpoint_insert(CPURISCVState *env, target_ulong index) | 28 | if (!vm && !vext_elem_mask(v0, mlen, i)) { \ |
34 | cpu_watchpoint_insert(cs, addr, size, flags, | 29 | @@ -XXX,XX +XXX,XX @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, void *vs2, \ |
35 | &env->cpu_watchpoint[index]); | 30 | uint32_t vlmax = env_archcpu(env)->cfg.vlen / mlen; \ |
36 | } else { | 31 | uint32_t vm = vext_vm(desc); \ |
37 | - cpu_watchpoint_insert(cs, addr, 8, flags, | 32 | uint32_t vl = env->vl; \ |
38 | + def_size = riscv_cpu_mxl(env) == MXL_RV64 ? 8 : 4; | 33 | - uint32_t index = s1, i; \ |
39 | + | 34 | + uint64_t index = s1; \ |
40 | + cpu_watchpoint_insert(cs, addr, def_size, flags, | 35 | + uint32_t i; \ |
41 | &env->cpu_watchpoint[index]); | 36 | \ |
42 | } | 37 | for (i = 0; i < vl; i++) { \ |
43 | } | 38 | if (!vm && !vext_elem_mask(v0, mlen, i)) { \ |
44 | -- | 39 | -- |
45 | 2.48.1 | 40 | 2.31.1 |
46 | 41 | ||
47 | 42 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Emmanuel Blot <emmanuel.blot@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Coverity reported a BAD_SHIFT issue in the following code: | 3 | When no MMU is used and the guest code attempts to fetch an instruction |
4 | from an invalid memory location, the exception index defaults to a data | ||
5 | load access fault, rather an instruction access fault. | ||
4 | 6 | ||
5 | > 2097 | 7 | Signed-off-by: Emmanuel Blot <emmanuel.blot@sifive.com> |
6 | >>>> CID 1590355: Integer handling issues (BAD_SHIFT) | ||
7 | >>>> In expression "hdeleg >> cause", right shifting by more than 63 | ||
8 | bits has undefined behavior. The shift amount, "cause", is at least 64. | ||
9 | > 2098 vsmode_exc = env->virt_enabled && (((hdeleg >> cause) & 1) || vs_injected); | ||
10 | > 2099 /* | ||
11 | |||
12 | It is not clear to me how the tool guarantees that '"cause" is at least | ||
13 | 64', but indeed there's no guarantees that it would be < 64 in the | ||
14 | 'async = true' code path. | ||
15 | |||
16 | A simple fix to avoid a potential UB is to add a 'cause < 64' guard like | ||
17 | 'mode' is already doing right before 'vsmode_exc'. | ||
18 | |||
19 | Resolves: Coverity CID 1590355 | ||
20 | Fixes: 967760f62c ("target/riscv: Implement Ssdbltrp exception handling") | ||
21 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
22 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
23 | Message-ID: <20250121184847.2109128-6-dbarboza@ventanamicro.com> | 9 | Message-id: FB9EA197-B018-4879-AB0F-922C2047A08B@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/cpu_helper.c | 4 +++- | 12 | target/riscv/cpu_helper.c | 4 +++- |
27 | 1 file changed, 3 insertions(+), 1 deletion(-) | 13 | 1 file changed, 3 insertions(+), 1 deletion(-) |
28 | 14 | ||
29 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 15 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
30 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
31 | --- a/target/riscv/cpu_helper.c | 17 | --- a/target/riscv/cpu_helper.c |
32 | +++ b/target/riscv/cpu_helper.c | 18 | +++ b/target/riscv/cpu_helper.c |
33 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) | 19 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, |
34 | mode = env->priv <= PRV_S && cause < 64 && | 20 | |
35 | (((deleg >> cause) & 1) || s_injected || vs_injected) ? PRV_S : PRV_M; | 21 | if (access_type == MMU_DATA_STORE) { |
36 | 22 | cs->exception_index = RISCV_EXCP_STORE_AMO_ACCESS_FAULT; | |
37 | - vsmode_exc = env->virt_enabled && (((hdeleg >> cause) & 1) || vs_injected); | 23 | - } else { |
38 | + vsmode_exc = env->virt_enabled && cause < 64 && | 24 | + } else if (access_type == MMU_DATA_LOAD) { |
39 | + (((hdeleg >> cause) & 1) || vs_injected); | 25 | cs->exception_index = RISCV_EXCP_LOAD_ACCESS_FAULT; |
40 | + | 26 | + } else { |
41 | /* | 27 | + cs->exception_index = RISCV_EXCP_INST_ACCESS_FAULT; |
42 | * Check double trap condition only if already in S-mode and targeting | 28 | } |
43 | * S-mode | 29 | |
30 | env->badaddr = addr; | ||
44 | -- | 31 | -- |
45 | 2.48.1 | 32 | 2.31.1 |
33 | |||
34 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Alexander Wagner <alexander.wagner@ulal.de> |
---|---|---|---|
2 | 2 | ||
3 | The S profiles do a priv_ver check during validation to see if the | 3 | The IBEX documentation [1] specifies the reset vector to be "the most |
4 | running priv_ver is compatible with it. This check is done by comparing | 4 | significant 3 bytes of the boot address and the reset value (0x80) as |
5 | if the running priv_ver is equal to the priv_ver the profile specifies. | 5 | the least significant byte". |
6 | 6 | ||
7 | There is an universe where we added RVA23S64 support based on both | 7 | [1] https://github.com/lowRISC/ibex/blob/master/doc/03_reference/exception_interrupts.rst |
8 | RVA23U64 and RVA22S64 and this error is being thrown: | ||
9 | 8 | ||
10 | qemu-system-riscv64: warning: Profile rva22s64 requires | 9 | Signed-off-by: Alexander Wagner <alexander.wagner@ulal.de> |
11 | priv spec v1.12.0, but priv ver v1.13.0 was set | ||
12 | |||
13 | We're enabling RVA22S64 (priv_ver 1.12) as a dependency of RVA23S64 | ||
14 | (priv_ver 1.13) and complaining to users about what we did ourselves. | ||
15 | |||
16 | There's no drawback in allowing a profile to run in an env that has a | ||
17 | priv_ver newer than it's required by it. So, like Hiro Nakamura saves | ||
18 | the future by changing the past, change the priv_ver check now to allow | ||
19 | profiles to run in a newer priv_ver. This universe will have one less | ||
20 | warning to deal with. | ||
21 | |||
22 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
23 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
24 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
25 | Message-ID: <20250115184316.2344583-5-dbarboza@ventanamicro.com> | 11 | Message-id: 20210420080008.119798-1-alexander.wagner@ulal.de |
26 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
27 | --- | 13 | --- |
28 | target/riscv/tcg/tcg-cpu.c | 2 +- | 14 | hw/riscv/opentitan.c | 2 +- |
29 | 1 file changed, 1 insertion(+), 1 deletion(-) | 15 | 1 file changed, 1 insertion(+), 1 deletion(-) |
30 | 16 | ||
31 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | 17 | diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c |
32 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/target/riscv/tcg/tcg-cpu.c | 19 | --- a/hw/riscv/opentitan.c |
34 | +++ b/target/riscv/tcg/tcg-cpu.c | 20 | +++ b/hw/riscv/opentitan.c |
35 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_validate_profile(RISCVCPU *cpu, | 21 | @@ -XXX,XX +XXX,XX @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp) |
36 | #endif | 22 | &error_abort); |
37 | 23 | object_property_set_int(OBJECT(&s->cpus), "num-harts", ms->smp.cpus, | |
38 | if (profile->priv_spec != RISCV_PROFILE_ATTR_UNUSED && | 24 | &error_abort); |
39 | - profile->priv_spec != env->priv_ver) { | 25 | - object_property_set_int(OBJECT(&s->cpus), "resetvec", 0x8090, &error_abort); |
40 | + profile->priv_spec > env->priv_ver) { | 26 | + object_property_set_int(OBJECT(&s->cpus), "resetvec", 0x8080, &error_abort); |
41 | profile_impl = false; | 27 | sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_abort); |
42 | 28 | ||
43 | if (send_warn) { | 29 | /* Boot ROM */ |
44 | -- | 30 | -- |
45 | 2.48.1 | 31 | 2.31.1 |
32 | |||
33 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Frank Chang <frank.chang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | We're missing scounteren and senvcfg CSRs, both already present in the | 3 | In IEEE 754-2008 spec: |
4 | KVM UAPI. | 4 | Invalid operation exception is signaled when doing: |
5 | fusedMultiplyAdd(0, Inf, c) or fusedMultiplyAdd(Inf, 0, c) | ||
6 | unless c is a quiet NaN; if c is a quiet NaN then it is | ||
7 | implementation defined whether the invalid operation exception | ||
8 | is signaled. | ||
5 | 9 | ||
6 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 10 | In RISC-V Unprivileged ISA spec: |
7 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | 11 | The fused multiply-add instructions must set the invalid |
8 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | 12 | operation exception flag when the multiplicands are Inf and |
9 | Message-ID: <20250224123120.1644186-4-dbarboza@ventanamicro.com> | 13 | zero, even when the addend is a quiet NaN. |
14 | |||
15 | This commit set invalid operation execption flag for RISC-V when | ||
16 | multiplicands of muladd instructions are Inf and zero. | ||
17 | |||
18 | Signed-off-by: Frank Chang <frank.chang@sifive.com> | ||
19 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
20 | Message-id: 20210420013150.21992-1-frank.chang@sifive.com | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 21 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 22 | --- |
12 | target/riscv/kvm/kvm-cpu.c | 6 ++++++ | 23 | fpu/softfloat-specialize.c.inc | 6 ++++++ |
13 | 1 file changed, 6 insertions(+) | 24 | 1 file changed, 6 insertions(+) |
14 | 25 | ||
15 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c | 26 | diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc |
16 | index XXXXXXX..XXXXXXX 100644 | 27 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/riscv/kvm/kvm-cpu.c | 28 | --- a/fpu/softfloat-specialize.c.inc |
18 | +++ b/target/riscv/kvm/kvm-cpu.c | 29 | +++ b/fpu/softfloat-specialize.c.inc |
19 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_reset_regs_csr(CPURISCVState *env) | 30 | @@ -XXX,XX +XXX,XX @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, |
20 | env->stval = 0; | 31 | } else { |
21 | env->mip = 0; | 32 | return 1; |
22 | env->satp = 0; | 33 | } |
23 | + env->scounteren = 0; | 34 | +#elif defined(TARGET_RISCV) |
24 | + env->senvcfg = 0; | 35 | + /* For RISC-V, InvalidOp is set when multiplicands are Inf and zero */ |
25 | } | 36 | + if (infzero) { |
26 | 37 | + float_raise(float_flag_invalid, status); | |
27 | static int kvm_riscv_get_regs_csr(CPUState *cs) | 38 | + } |
28 | @@ -XXX,XX +XXX,XX @@ static int kvm_riscv_get_regs_csr(CPUState *cs) | 39 | + return 3; /* default NaN */ |
29 | KVM_RISCV_GET_CSR(cs, env, stval, env->stval); | 40 | #elif defined(TARGET_XTENSA) |
30 | KVM_RISCV_GET_CSR(cs, env, sip, env->mip); | 41 | /* |
31 | KVM_RISCV_GET_CSR(cs, env, satp, env->satp); | 42 | * For Xtensa, the (inf,zero,nan) case sets InvalidOp and returns |
32 | + KVM_RISCV_GET_CSR(cs, env, scounteren, env->scounteren); | ||
33 | + KVM_RISCV_GET_CSR(cs, env, senvcfg, env->senvcfg); | ||
34 | |||
35 | return 0; | ||
36 | } | ||
37 | @@ -XXX,XX +XXX,XX @@ static int kvm_riscv_put_regs_csr(CPUState *cs) | ||
38 | KVM_RISCV_SET_CSR(cs, env, stval, env->stval); | ||
39 | KVM_RISCV_SET_CSR(cs, env, sip, env->mip); | ||
40 | KVM_RISCV_SET_CSR(cs, env, satp, env->satp); | ||
41 | + KVM_RISCV_SET_CSR(cs, env, scounteren, env->scounteren); | ||
42 | + KVM_RISCV_SET_CSR(cs, env, senvcfg, env->senvcfg); | ||
43 | |||
44 | return 0; | ||
45 | } | ||
46 | -- | 43 | -- |
47 | 2.48.1 | 44 | 2.31.1 |
45 | |||
46 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Emmanuel Blot <emmanuel.blot@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | ssu64xl is defined in RVA22 as: | 3 | Interrupt names have been swapped in 205377f8 and do not follow |
4 | IRQ_*_EXT definition order. | ||
4 | 5 | ||
5 | "sstatus.UXL must be capable of holding the value 2 (i.e., UXLEN=64 must | 6 | Signed-off-by: Emmanuel Blot <emmanuel.blot@sifive.com> |
6 | be supported)." | ||
7 | |||
8 | This is always true in TCG and it's mandatory for RVA23, so claim | ||
9 | support for it. | ||
10 | |||
11 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
12 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
14 | Message-ID: <20250115184316.2344583-2-dbarboza@ventanamicro.com> | 8 | Message-id: 20210421133236.11323-1-emmanuel.blot@sifive.com |
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
16 | --- | 10 | --- |
17 | target/riscv/cpu.c | 1 + | 11 | target/riscv/cpu.c | 2 +- |
18 | tests/data/acpi/riscv64/virt/RHCT | Bin 390 -> 398 bytes | 12 | 1 file changed, 1 insertion(+), 1 deletion(-) |
19 | 2 files changed, 1 insertion(+) | ||
20 | 13 | ||
21 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 14 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
22 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/target/riscv/cpu.c | 16 | --- a/target/riscv/cpu.c |
24 | +++ b/target/riscv/cpu.c | 17 | +++ b/target/riscv/cpu.c |
25 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { | 18 | @@ -XXX,XX +XXX,XX @@ const char * const riscv_intr_names[] = { |
26 | ISA_EXT_DATA_ENTRY(sstc, PRIV_VERSION_1_12_0, ext_sstc), | 19 | "vs_timer", |
27 | ISA_EXT_DATA_ENTRY(sstvala, PRIV_VERSION_1_12_0, has_priv_1_12), | 20 | "m_timer", |
28 | ISA_EXT_DATA_ENTRY(sstvecd, PRIV_VERSION_1_12_0, has_priv_1_12), | 21 | "u_external", |
29 | + ISA_EXT_DATA_ENTRY(ssu64xl, PRIV_VERSION_1_12_0, has_priv_1_12), | 22 | + "s_external", |
30 | ISA_EXT_DATA_ENTRY(supm, PRIV_VERSION_1_13_0, ext_supm), | 23 | "vs_external", |
31 | ISA_EXT_DATA_ENTRY(svade, PRIV_VERSION_1_11_0, ext_svade), | 24 | - "h_external", |
32 | ISA_EXT_DATA_ENTRY(svadu, PRIV_VERSION_1_12_0, ext_svadu), | 25 | "m_external", |
33 | diff --git a/tests/data/acpi/riscv64/virt/RHCT b/tests/data/acpi/riscv64/virt/RHCT | 26 | "reserved", |
34 | index XXXXXXX..XXXXXXX 100644 | 27 | "reserved", |
35 | Binary files a/tests/data/acpi/riscv64/virt/RHCT and b/tests/data/acpi/riscv64/virt/RHCT differ | ||
36 | -- | 28 | -- |
37 | 2.48.1 | 29 | 2.31.1 |
30 | |||
31 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
---|---|---|---|
2 | |||
3 | The current 'parent' mechanic for profiles allows for one profile to be | ||
4 | a child of a previous/older profile, enabling all its extensions (and | ||
5 | the parent profile itself) and sparing us from tediously listing all | ||
6 | extensions for every profile. | ||
7 | |||
8 | This works fine for u-mode profiles. For s-mode profiles this is not | ||
9 | enough: a s-mode profile extends not only his equivalent u-mode profile | ||
10 | but also the previous s-mode profile. This means, for example, that | ||
11 | RVA23S64 extends both RVA23U64 and RVA22S64. | ||
12 | |||
13 | To fit this usage, rename the existing 'parent' to 'u_parent' and add a | ||
14 | new 's_parent' attribute for profiles. Handle both like we were doing | ||
15 | with the previous 'parent' attribute, i.e. if set, enable it. This | ||
16 | change does nothing for the existing profiles but will make RVA23S64 | ||
17 | simpler. | ||
18 | |||
19 | Suggested-by: Andrew Jones <ajones@ventanamicro.com> | ||
20 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
21 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
22 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
23 | Message-ID: <20250115184316.2344583-4-dbarboza@ventanamicro.com> | ||
24 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
2 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
3 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
4 | Message-id: a07bc0c6dc4958681b4f93cbc5d0acc31ed3344a.1619234854.git.alistair.francis@wdc.com | ||
25 | --- | 5 | --- |
26 | target/riscv/cpu.h | 3 ++- | 6 | target/riscv/cpu.h | 6 ------ |
27 | target/riscv/cpu.c | 6 ++++-- | 7 | target/riscv/cpu.c | 6 +++++- |
28 | target/riscv/tcg/tcg-cpu.c | 35 ++++++++++++++++++++++++++--------- | 8 | 2 files changed, 5 insertions(+), 7 deletions(-) |
29 | 3 files changed, 32 insertions(+), 12 deletions(-) | ||
30 | 9 | ||
31 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 10 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
32 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/target/riscv/cpu.h | 12 | --- a/target/riscv/cpu.h |
34 | +++ b/target/riscv/cpu.h | 13 | +++ b/target/riscv/cpu.h |
35 | @@ -XXX,XX +XXX,XX @@ const char *riscv_get_misa_ext_description(uint32_t bit); | 14 | @@ -XXX,XX +XXX,XX @@ |
36 | #define CPU_CFG_OFFSET(_prop) offsetof(struct RISCVCPUConfig, _prop) | 15 | #define RV32 ((target_ulong)1 << (TARGET_LONG_BITS - 2)) |
37 | 16 | #define RV64 ((target_ulong)2 << (TARGET_LONG_BITS - 2)) | |
38 | typedef struct riscv_cpu_profile { | 17 | |
39 | - struct riscv_cpu_profile *parent; | 18 | -#if defined(TARGET_RISCV32) |
40 | + struct riscv_cpu_profile *u_parent; | 19 | -#define RVXLEN RV32 |
41 | + struct riscv_cpu_profile *s_parent; | 20 | -#elif defined(TARGET_RISCV64) |
42 | const char *name; | 21 | -#define RVXLEN RV64 |
43 | uint32_t misa_ext; | 22 | -#endif |
44 | bool enabled; | 23 | - |
24 | #define RV(x) ((target_ulong)1 << (x - 'A')) | ||
25 | |||
26 | #define RVI RV('I') | ||
45 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 27 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
46 | index XXXXXXX..XXXXXXX 100644 | 28 | index XXXXXXX..XXXXXXX 100644 |
47 | --- a/target/riscv/cpu.c | 29 | --- a/target/riscv/cpu.c |
48 | +++ b/target/riscv/cpu.c | 30 | +++ b/target/riscv/cpu.c |
49 | @@ -XXX,XX +XXX,XX @@ static const PropertyInfo prop_marchid = { | 31 | @@ -XXX,XX +XXX,XX @@ static void set_resetvec(CPURISCVState *env, target_ulong resetvec) |
50 | * doesn't need to be manually enabled by the profile. | 32 | static void riscv_any_cpu_init(Object *obj) |
51 | */ | 33 | { |
52 | static RISCVCPUProfile RVA22U64 = { | 34 | CPURISCVState *env = &RISCV_CPU(obj)->env; |
53 | - .parent = NULL, | 35 | - set_misa(env, RVXLEN | RVI | RVM | RVA | RVF | RVD | RVC | RVU); |
54 | + .u_parent = NULL, | 36 | +#if defined(TARGET_RISCV32) |
55 | + .s_parent = NULL, | 37 | + set_misa(env, RV32 | RVI | RVM | RVA | RVF | RVD | RVC | RVU); |
56 | .name = "rva22u64", | 38 | +#elif defined(TARGET_RISCV64) |
57 | .misa_ext = RVI | RVM | RVA | RVF | RVD | RVC | RVB | RVU, | 39 | + set_misa(env, RV64 | RVI | RVM | RVA | RVF | RVD | RVC | RVU); |
58 | .priv_spec = RISCV_PROFILE_ATTR_UNUSED, | 40 | +#endif |
59 | @@ -XXX,XX +XXX,XX @@ static RISCVCPUProfile RVA22U64 = { | 41 | set_priv_version(env, PRIV_VERSION_1_11_0); |
60 | * The remaining features/extensions comes from RVA22U64. | ||
61 | */ | ||
62 | static RISCVCPUProfile RVA22S64 = { | ||
63 | - .parent = &RVA22U64, | ||
64 | + .u_parent = &RVA22U64, | ||
65 | + .s_parent = NULL, | ||
66 | .name = "rva22s64", | ||
67 | .misa_ext = RVS, | ||
68 | .priv_spec = PRIV_VERSION_1_12_0, | ||
69 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
70 | index XXXXXXX..XXXXXXX 100644 | ||
71 | --- a/target/riscv/tcg/tcg-cpu.c | ||
72 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
73 | @@ -XXX,XX +XXX,XX @@ static bool riscv_cpu_validate_profile_satp(RISCVCPU *cpu, | ||
74 | } | 42 | } |
75 | #endif | ||
76 | |||
77 | +static void riscv_cpu_check_parent_profile(RISCVCPU *cpu, | ||
78 | + RISCVCPUProfile *profile, | ||
79 | + RISCVCPUProfile *parent) | ||
80 | +{ | ||
81 | + const char *parent_name; | ||
82 | + bool parent_enabled; | ||
83 | + | ||
84 | + if (!profile->enabled || !parent) { | ||
85 | + return; | ||
86 | + } | ||
87 | + | ||
88 | + parent_name = parent->name; | ||
89 | + parent_enabled = object_property_get_bool(OBJECT(cpu), parent_name, NULL); | ||
90 | + profile->enabled = parent_enabled; | ||
91 | +} | ||
92 | + | ||
93 | static void riscv_cpu_validate_profile(RISCVCPU *cpu, | ||
94 | RISCVCPUProfile *profile) | ||
95 | { | ||
96 | CPURISCVState *env = &cpu->env; | ||
97 | const char *warn_msg = "Profile %s mandates disabled extension %s"; | ||
98 | bool send_warn = profile->user_set && profile->enabled; | ||
99 | - bool parent_enabled, profile_impl = true; | ||
100 | + bool profile_impl = true; | ||
101 | int i; | ||
102 | |||
103 | #ifndef CONFIG_USER_ONLY | ||
104 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_validate_profile(RISCVCPU *cpu, | ||
105 | |||
106 | profile->enabled = profile_impl; | ||
107 | |||
108 | - if (profile->parent != NULL) { | ||
109 | - parent_enabled = object_property_get_bool(OBJECT(cpu), | ||
110 | - profile->parent->name, | ||
111 | - NULL); | ||
112 | - profile->enabled = profile->enabled && parent_enabled; | ||
113 | - } | ||
114 | + riscv_cpu_check_parent_profile(cpu, profile, profile->u_parent); | ||
115 | + riscv_cpu_check_parent_profile(cpu, profile, profile->s_parent); | ||
116 | } | ||
117 | |||
118 | static void riscv_cpu_validate_profiles(RISCVCPU *cpu) | ||
119 | @@ -XXX,XX +XXX,XX @@ static void cpu_set_profile(Object *obj, Visitor *v, const char *name, | ||
120 | profile->user_set = true; | ||
121 | profile->enabled = value; | ||
122 | |||
123 | - if (profile->parent != NULL) { | ||
124 | - object_property_set_bool(obj, profile->parent->name, | ||
125 | + if (profile->u_parent != NULL) { | ||
126 | + object_property_set_bool(obj, profile->u_parent->name, | ||
127 | + profile->enabled, NULL); | ||
128 | + } | ||
129 | + | ||
130 | + if (profile->s_parent != NULL) { | ||
131 | + object_property_set_bool(obj, profile->s_parent->name, | ||
132 | profile->enabled, NULL); | ||
133 | } | ||
134 | 43 | ||
135 | -- | 44 | -- |
136 | 2.48.1 | 45 | 2.31.1 |
46 | |||
47 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | This also ensures that the SD bit is not writable. |
---|---|---|---|
2 | 2 | ||
3 | Coverity found a DEADCODE issue in rmw_xireg() claiming that we can't | 3 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
4 | reach 'RISCV_EXCP_VIRT_INSTRUCTION_FAULT' at the 'done' label: | 4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
5 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
6 | Message-id: 9ea842309f0fd7adff172790f5b5fc058b40f2f1.1619234854.git.alistair.francis@wdc.com | ||
7 | --- | ||
8 | target/riscv/cpu_bits.h | 6 ------ | ||
9 | target/riscv/csr.c | 9 ++++++++- | ||
10 | 2 files changed, 8 insertions(+), 7 deletions(-) | ||
5 | 11 | ||
6 | done: | 12 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h |
7 | if (ret) { | 13 | index XXXXXXX..XXXXXXX 100644 |
8 | return (env->virt_enabled && virt) ? | 14 | --- a/target/riscv/cpu_bits.h |
9 | RISCV_EXCP_VIRT_INSTRUCTION_FAULT : RISCV_EXCP_ILLEGAL_INST; | 15 | +++ b/target/riscv/cpu_bits.h |
10 | } | 16 | @@ -XXX,XX +XXX,XX @@ |
11 | return RISCV_EXCP_NONE; | 17 | #define SSTATUS32_SD 0x80000000 |
12 | 18 | #define SSTATUS64_SD 0x8000000000000000ULL | |
13 | This happens because the 'virt' flag, which is only used by 'done', is | 19 | |
14 | set to 'false' and it will always remain 'false' in any condition where | 20 | -#if defined(TARGET_RISCV32) |
15 | we'll jump to 'done': | 21 | -#define SSTATUS_SD SSTATUS32_SD |
16 | 22 | -#elif defined(TARGET_RISCV64) | |
17 | switch (csrno) { | 23 | -#define SSTATUS_SD SSTATUS64_SD |
18 | (...) | 24 | -#endif |
19 | case CSR_VSIREG: | 25 | - |
20 | isel = env->vsiselect; | 26 | /* hstatus CSR bits */ |
21 | virt = true; | 27 | #define HSTATUS_VSBE 0x00000020 |
22 | break; | 28 | #define HSTATUS_GVA 0x00000040 |
23 | default: | ||
24 | goto done; | ||
25 | }; | ||
26 | |||
27 | 'virt = true' will never reach 'done' because we have a if/else-if/else | ||
28 | block right before the label that will always return: | ||
29 | |||
30 | if (xiselect_aia_range(isel)) { | ||
31 | return ... | ||
32 | } else if (...) { | ||
33 | return ... | ||
34 | } else { | ||
35 | return RISCV_EXCP_ILLEGAL_INST; | ||
36 | } | ||
37 | |||
38 | All this means that we can preserve the current logic by reducing the | ||
39 | 'done' label to: | ||
40 | |||
41 | done: | ||
42 | if (ret) { | ||
43 | return RISCV_EXCP_ILLEGAL_INST; | ||
44 | } | ||
45 | return RISCV_EXCP_NONE; | ||
46 | |||
47 | The flag 'virt' is now unused. Remove it. | ||
48 | |||
49 | Fix the 'goto done' identation while we're at it. | ||
50 | |||
51 | Resolves: Coverity CID 1590359 | ||
52 | Fixes: dc0280723d ("target/riscv: Decouple AIA processing from xiselect and xireg") | ||
53 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
54 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
55 | Message-ID: <20250121184847.2109128-2-dbarboza@ventanamicro.com> | ||
56 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
57 | --- | ||
58 | target/riscv/csr.c | 7 ++----- | ||
59 | 1 file changed, 2 insertions(+), 5 deletions(-) | ||
60 | |||
61 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 29 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
62 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
63 | --- a/target/riscv/csr.c | 31 | --- a/target/riscv/csr.c |
64 | +++ b/target/riscv/csr.c | 32 | +++ b/target/riscv/csr.c |
65 | @@ -XXX,XX +XXX,XX @@ static RISCVException rmw_xireg(CPURISCVState *env, int csrno, | 33 | @@ -XXX,XX +XXX,XX @@ static const target_ulong delegable_excps = |
66 | target_ulong *val, target_ulong new_val, | 34 | (1ULL << (RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT)); |
67 | target_ulong wr_mask) | 35 | static const target_ulong sstatus_v1_10_mask = SSTATUS_SIE | SSTATUS_SPIE | |
36 | SSTATUS_UIE | SSTATUS_UPIE | SSTATUS_SPP | SSTATUS_FS | SSTATUS_XS | | ||
37 | - SSTATUS_SUM | SSTATUS_MXR | SSTATUS_SD; | ||
38 | + SSTATUS_SUM | SSTATUS_MXR; | ||
39 | static const target_ulong sip_writable_mask = SIP_SSIP | MIP_USIP | MIP_UEIP; | ||
40 | static const target_ulong hip_writable_mask = MIP_VSSIP; | ||
41 | static const target_ulong hvip_writable_mask = MIP_VSSIP | MIP_VSTIP | MIP_VSEIP; | ||
42 | @@ -XXX,XX +XXX,XX @@ static RISCVException read_sstatus(CPURISCVState *env, int csrno, | ||
43 | target_ulong *val) | ||
68 | { | 44 | { |
69 | - bool virt = false; | 45 | target_ulong mask = (sstatus_v1_10_mask); |
70 | int ret = -EINVAL; | 46 | + |
71 | target_ulong isel; | 47 | + if (riscv_cpu_is_32bit(env)) { |
72 | 48 | + mask |= SSTATUS32_SD; | |
73 | @@ -XXX,XX +XXX,XX @@ static RISCVException rmw_xireg(CPURISCVState *env, int csrno, | 49 | + } else { |
74 | break; | 50 | + mask |= SSTATUS64_SD; |
75 | case CSR_VSIREG: | 51 | + } |
76 | isel = env->vsiselect; | 52 | + |
77 | - virt = true; | 53 | *val = env->mstatus & mask; |
78 | break; | ||
79 | default: | ||
80 | - goto done; | ||
81 | + goto done; | ||
82 | }; | ||
83 | |||
84 | /* | ||
85 | @@ -XXX,XX +XXX,XX @@ static RISCVException rmw_xireg(CPURISCVState *env, int csrno, | ||
86 | |||
87 | done: | ||
88 | if (ret) { | ||
89 | - return (env->virt_enabled && virt) ? | ||
90 | - RISCV_EXCP_VIRT_INSTRUCTION_FAULT : RISCV_EXCP_ILLEGAL_INST; | ||
91 | + return RISCV_EXCP_ILLEGAL_INST; | ||
92 | } | ||
93 | return RISCV_EXCP_NONE; | 54 | return RISCV_EXCP_NONE; |
94 | } | 55 | } |
95 | -- | 56 | -- |
96 | 2.48.1 | 57 | 2.31.1 |
58 | |||
59 | diff view generated by jsdifflib |
1 | From: julia <midnight@trainwit.ch> | 1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
---|---|---|---|
2 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
3 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
4 | Message-id: 665f624bfdc2e3ca64265004b07de7489c77a766.1619234854.git.alistair.francis@wdc.com | ||
5 | --- | ||
6 | target/riscv/cpu_bits.h | 11 ----------- | ||
7 | target/riscv/cpu_helper.c | 24 +++++++++++++++--------- | ||
8 | 2 files changed, 15 insertions(+), 20 deletions(-) | ||
2 | 9 | ||
3 | For instance, QEMUs newer than b6ecc63c569bb88c0fcadf79fb92bf4b88aefea8 | 10 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h |
4 | would silently treat this akin to an unmapped page (as required by the | 11 | index XXXXXXX..XXXXXXX 100644 |
5 | RISC-V spec, admittedly). However, not all hardware platforms do (e.g. | 12 | --- a/target/riscv/cpu_bits.h |
6 | CVA6) which leads to an apparent QEMU bug. | 13 | +++ b/target/riscv/cpu_bits.h |
7 | 14 | @@ -XXX,XX +XXX,XX @@ | |
8 | Instead, log a guest error so that in future, incorrectly set up page | 15 | #define CSR_HTIMEDELTA 0x605 |
9 | tables can be debugged without bisecting QEMU. | 16 | #define CSR_HTIMEDELTAH 0x615 |
10 | 17 | ||
11 | Signed-off-by: julia <midnight@trainwit.ch> | 18 | -#if defined(TARGET_RISCV32) |
12 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 19 | -#define HGATP_MODE SATP32_MODE |
13 | Message-ID: <20250203061852.2931556-1-midnight@trainwit.ch> | 20 | -#define HGATP_VMID SATP32_ASID |
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 21 | -#define HGATP_PPN SATP32_PPN |
15 | --- | 22 | -#endif |
16 | target/riscv/cpu_helper.c | 27 ++++++++++++++++++++++++++- | 23 | -#if defined(TARGET_RISCV64) |
17 | 1 file changed, 26 insertions(+), 1 deletion(-) | 24 | -#define HGATP_MODE SATP64_MODE |
18 | 25 | -#define HGATP_VMID SATP64_ASID | |
26 | -#define HGATP_PPN SATP64_PPN | ||
27 | -#endif | ||
28 | - | ||
29 | /* Virtual CSRs */ | ||
30 | #define CSR_VSSTATUS 0x200 | ||
31 | #define CSR_VSIE 0x204 | ||
19 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 32 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
20 | index XXXXXXX..XXXXXXX 100644 | 33 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/riscv/cpu_helper.c | 34 | --- a/target/riscv/cpu_helper.c |
22 | +++ b/target/riscv/cpu_helper.c | 35 | +++ b/target/riscv/cpu_helper.c |
23 | @@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, | 36 | @@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, |
24 | ppn = pte >> PTE_PPN_SHIFT; | ||
25 | } else { | ||
26 | if (pte & PTE_RESERVED) { | ||
27 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: reserved bits set in PTE: " | ||
28 | + "addr: 0x%" HWADDR_PRIx " pte: 0x" TARGET_FMT_lx "\n", | ||
29 | + __func__, pte_addr, pte); | ||
30 | return TRANSLATE_FAIL; | ||
31 | } | ||
32 | |||
33 | if (!pbmte && (pte & PTE_PBMT)) { | ||
34 | + /* Reserved without Svpbmt. */ | ||
35 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: PBMT bits set in PTE, " | ||
36 | + "and Svpbmt extension is disabled: " | ||
37 | + "addr: 0x%" HWADDR_PRIx " pte: 0x" TARGET_FMT_lx "\n", | ||
38 | + __func__, pte_addr, pte); | ||
39 | return TRANSLATE_FAIL; | ||
40 | } | ||
41 | |||
42 | if (!riscv_cpu_cfg(env)->ext_svnapot && (pte & PTE_N)) { | ||
43 | + /* Reserved without Svnapot extension */ | ||
44 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: N bit set in PTE, " | ||
45 | + "and Svnapot extension is disabled: " | ||
46 | + "addr: 0x%" HWADDR_PRIx " pte: 0x" TARGET_FMT_lx "\n", | ||
47 | + __func__, pte_addr, pte); | ||
48 | return TRANSLATE_FAIL; | ||
49 | } | ||
50 | |||
51 | @@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, | ||
52 | /* Invalid PTE */ | ||
53 | return TRANSLATE_FAIL; | ||
54 | } | 37 | } |
38 | widened = 0; | ||
39 | } else { | ||
40 | - base = (hwaddr)get_field(env->hgatp, HGATP_PPN) << PGSHIFT; | ||
41 | - vm = get_field(env->hgatp, HGATP_MODE); | ||
42 | + if (riscv_cpu_is_32bit(env)) { | ||
43 | + base = (hwaddr)get_field(env->hgatp, SATP32_PPN) << PGSHIFT; | ||
44 | + vm = get_field(env->hgatp, SATP32_MODE); | ||
45 | + } else { | ||
46 | + base = (hwaddr)get_field(env->hgatp, SATP64_PPN) << PGSHIFT; | ||
47 | + vm = get_field(env->hgatp, SATP64_MODE); | ||
48 | + } | ||
49 | widened = 2; | ||
50 | } | ||
51 | /* status.SUM will be ignored if execute on background */ | ||
52 | @@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address, | ||
53 | bool first_stage, bool two_stage) | ||
54 | { | ||
55 | CPUState *cs = env_cpu(env); | ||
56 | - int page_fault_exceptions; | ||
57 | + int page_fault_exceptions, vm; | ||
55 | + | 58 | + |
56 | if (pte & (PTE_R | PTE_W | PTE_X)) { | 59 | if (first_stage) { |
57 | goto leaf; | 60 | - page_fault_exceptions = |
58 | } | 61 | - get_field(env->satp, SATP_MODE) != VM_1_10_MBARE && |
59 | 62 | - !pmp_violation; | |
60 | - /* Inner PTE, continue walking */ | 63 | + vm = get_field(env->satp, SATP_MODE); |
61 | if (pte & (PTE_D | PTE_A | PTE_U | PTE_ATTR)) { | 64 | + } else if (riscv_cpu_is_32bit(env)) { |
62 | + /* D, A, and U bits are reserved in non-leaf/inner PTEs */ | 65 | + vm = get_field(env->hgatp, SATP32_MODE); |
63 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: D, A, or U bits set in non-leaf PTE: " | 66 | } else { |
64 | + "addr: 0x%" HWADDR_PRIx " pte: 0x" TARGET_FMT_lx "\n", | 67 | - page_fault_exceptions = |
65 | + __func__, pte_addr, pte); | 68 | - get_field(env->hgatp, HGATP_MODE) != VM_1_10_MBARE && |
66 | return TRANSLATE_FAIL; | 69 | - !pmp_violation; |
67 | } | 70 | + vm = get_field(env->hgatp, SATP64_MODE); |
68 | + /* Inner PTE, continue walking */ | ||
69 | base = ppn << PGSHIFT; | ||
70 | } | 71 | } |
71 | 72 | + page_fault_exceptions = vm != VM_1_10_MBARE && !pmp_violation; | |
72 | @@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, | 73 | + |
73 | leaf: | 74 | switch (access_type) { |
74 | if (ppn & ((1ULL << ptshift) - 1)) { | 75 | case MMU_INST_FETCH: |
75 | /* Misaligned PPN */ | 76 | if (riscv_cpu_virt_enabled(env) && !first_stage) { |
76 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: PPN bits in PTE is misaligned: " | ||
77 | + "addr: 0x%" HWADDR_PRIx " pte: 0x" TARGET_FMT_lx "\n", | ||
78 | + __func__, pte_addr, pte); | ||
79 | return TRANSLATE_FAIL; | ||
80 | } | ||
81 | if (!pbmte && (pte & PTE_PBMT)) { | ||
82 | /* Reserved without Svpbmt. */ | ||
83 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: PBMT bits set in PTE, " | ||
84 | + "and Svpbmt extension is disabled: " | ||
85 | + "addr: 0x%" HWADDR_PRIx " pte: 0x" TARGET_FMT_lx "\n", | ||
86 | + __func__, pte_addr, pte); | ||
87 | return TRANSLATE_FAIL; | ||
88 | } | ||
89 | |||
90 | -- | 77 | -- |
91 | 2.48.1 | 78 | 2.31.1 |
79 | |||
80 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
---|---|---|---|
2 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
3 | Message-id: fcc125d96da941b56c817c9dd6068dc36478fc53.1619234854.git.alistair.francis@wdc.com | ||
4 | --- | ||
5 | target/riscv/cpu_bits.h | 10 ---------- | ||
6 | target/riscv/csr.c | 12 ++++++++++-- | ||
7 | target/riscv/translate.c | 19 +++++++++++++++++-- | ||
8 | 3 files changed, 27 insertions(+), 14 deletions(-) | ||
2 | 9 | ||
3 | Coverity found a second DEADCODE issue in rmw_xireg() claiming that we can't | 10 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h |
4 | reach 'RISCV_EXCP_NONE' at the 'done' label: | 11 | index XXXXXXX..XXXXXXX 100644 |
5 | 12 | --- a/target/riscv/cpu_bits.h | |
6 | > 2706 done: | 13 | +++ b/target/riscv/cpu_bits.h |
7 | > 2707 if (ret) { | 14 | @@ -XXX,XX +XXX,XX @@ |
8 | > 2708 return (env->virt_enabled && virt) ? | 15 | #define MXL_RV64 2 |
9 | > 2709 RISCV_EXCP_VIRT_INSTRUCTION_FAULT : RISCV_EXCP_ILLEGAL_INST; | 16 | #define MXL_RV128 3 |
10 | > 2710 } | 17 | |
11 | >>>> CID 1590356: Control flow issues (DEADCODE) | 18 | -#if defined(TARGET_RISCV32) |
12 | >>>> Execution cannot reach this statement: "return RISCV_EXCP_NONE;". | 19 | -#define MSTATUS_SD MSTATUS32_SD |
13 | > 2711 return RISCV_EXCP_NONE; | 20 | -#define MISA_MXL MISA32_MXL |
14 | 21 | -#define MXL_VAL MXL_RV32 | |
15 | Our label is now reduced after fixing another deadcode in the previous | 22 | -#elif defined(TARGET_RISCV64) |
16 | patch but the problem reported here still remains: | 23 | -#define MSTATUS_SD MSTATUS64_SD |
17 | 24 | -#define MISA_MXL MISA64_MXL | |
18 | done: | 25 | -#define MXL_VAL MXL_RV64 |
19 | if (ret) { | 26 | -#endif |
20 | return RISCV_EXCP_ILLEGAL_INST; | 27 | - |
21 | } | 28 | /* sstatus CSR bits */ |
22 | return RISCV_EXCP_NONE; | 29 | #define SSTATUS_UIE 0x00000001 |
23 | 30 | #define SSTATUS_SIE 0x00000002 | |
24 | This happens because 'ret' changes only once at the start of the | ||
25 | function: | ||
26 | |||
27 | ret = smstateen_acc_ok(env, 0, SMSTATEEN0_SVSLCT); | ||
28 | if (ret != RISCV_EXCP_NONE) { | ||
29 | return ret; | ||
30 | } | ||
31 | |||
32 | So it's a guarantee that ret will be RISCV_EXCP_NONE (-1) if we ever | ||
33 | reach the label, i.e. "if (ret)" will always be true, and the label can | ||
34 | be even further reduced to: | ||
35 | |||
36 | done: | ||
37 | return RISCV_EXCP_ILLEGAL_INST; | ||
38 | |||
39 | To make a better use of the label, remove the 'else' from the | ||
40 | xiselect_aia_range() chain and let it fall-through to the 'done' label | ||
41 | since they are now both returning RISCV_EXCP_ILLEGAL_INST. | ||
42 | |||
43 | Resolves: Coverity CID 1590356 | ||
44 | Fixes: dc0280723d ("target/riscv: Decouple AIA processing from xiselect and xireg") | ||
45 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
46 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
47 | Message-ID: <20250121184847.2109128-3-dbarboza@ventanamicro.com> | ||
48 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
49 | --- | ||
50 | target/riscv/csr.c | 7 +------ | ||
51 | 1 file changed, 1 insertion(+), 6 deletions(-) | ||
52 | |||
53 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 31 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
54 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
55 | --- a/target/riscv/csr.c | 33 | --- a/target/riscv/csr.c |
56 | +++ b/target/riscv/csr.c | 34 | +++ b/target/riscv/csr.c |
57 | @@ -XXX,XX +XXX,XX @@ static RISCVException rmw_xireg(CPURISCVState *env, int csrno, | 35 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno, |
58 | } else if (riscv_cpu_cfg(env)->ext_smcsrind || | 36 | |
59 | riscv_cpu_cfg(env)->ext_sscsrind) { | 37 | dirty = ((mstatus & MSTATUS_FS) == MSTATUS_FS) | |
60 | return rmw_xireg_csrind(env, csrno, isel, val, new_val, wr_mask); | 38 | ((mstatus & MSTATUS_XS) == MSTATUS_XS); |
61 | - } else { | 39 | - mstatus = set_field(mstatus, MSTATUS_SD, dirty); |
62 | - return RISCV_EXCP_ILLEGAL_INST; | 40 | + if (riscv_cpu_is_32bit(env)) { |
41 | + mstatus = set_field(mstatus, MSTATUS32_SD, dirty); | ||
42 | + } else { | ||
43 | + mstatus = set_field(mstatus, MSTATUS64_SD, dirty); | ||
44 | + } | ||
45 | env->mstatus = mstatus; | ||
46 | |||
47 | return RISCV_EXCP_NONE; | ||
48 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_misa(CPURISCVState *env, int csrno, | ||
63 | } | 49 | } |
64 | 50 | ||
65 | done: | 51 | /* misa.MXL writes are not supported by QEMU */ |
66 | - if (ret) { | 52 | - val = (env->misa & MISA_MXL) | (val & ~MISA_MXL); |
67 | - return RISCV_EXCP_ILLEGAL_INST; | 53 | + if (riscv_cpu_is_32bit(env)) { |
68 | - } | 54 | + val = (env->misa & MISA32_MXL) | (val & ~MISA32_MXL); |
69 | - return RISCV_EXCP_NONE; | 55 | + } else { |
70 | + return RISCV_EXCP_ILLEGAL_INST; | 56 | + val = (env->misa & MISA64_MXL) | (val & ~MISA64_MXL); |
57 | + } | ||
58 | |||
59 | /* flush translation cache */ | ||
60 | if (val != env->misa) { | ||
61 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | ||
62 | index XXXXXXX..XXXXXXX 100644 | ||
63 | --- a/target/riscv/translate.c | ||
64 | +++ b/target/riscv/translate.c | ||
65 | @@ -XXX,XX +XXX,XX @@ static inline bool has_ext(DisasContext *ctx, uint32_t ext) | ||
66 | return ctx->misa & ext; | ||
71 | } | 67 | } |
72 | 68 | ||
73 | static RISCVException rmw_xtopei(CPURISCVState *env, int csrno, | 69 | +#ifdef TARGET_RISCV32 |
70 | +# define is_32bit(ctx) true | ||
71 | +#elif defined(CONFIG_USER_ONLY) | ||
72 | +# define is_32bit(ctx) false | ||
73 | +#else | ||
74 | +static inline bool is_32bit(DisasContext *ctx) | ||
75 | +{ | ||
76 | + return (ctx->misa & RV32) == RV32; | ||
77 | +} | ||
78 | +#endif | ||
79 | + | ||
80 | /* | ||
81 | * RISC-V requires NaN-boxing of narrower width floating point values. | ||
82 | * This applies when a 32-bit value is assigned to a 64-bit FP register. | ||
83 | @@ -XXX,XX +XXX,XX @@ static void gen_jal(DisasContext *ctx, int rd, target_ulong imm) | ||
84 | static void mark_fs_dirty(DisasContext *ctx) | ||
85 | { | ||
86 | TCGv tmp; | ||
87 | + target_ulong sd; | ||
88 | + | ||
89 | if (ctx->mstatus_fs == MSTATUS_FS) { | ||
90 | return; | ||
91 | } | ||
92 | @@ -XXX,XX +XXX,XX @@ static void mark_fs_dirty(DisasContext *ctx) | ||
93 | ctx->mstatus_fs = MSTATUS_FS; | ||
94 | |||
95 | tmp = tcg_temp_new(); | ||
96 | + sd = is_32bit(ctx) ? MSTATUS32_SD : MSTATUS64_SD; | ||
97 | + | ||
98 | tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); | ||
99 | - tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | MSTATUS_SD); | ||
100 | + tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | sd); | ||
101 | tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); | ||
102 | |||
103 | if (ctx->virt_enabled) { | ||
104 | tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs)); | ||
105 | - tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | MSTATUS_SD); | ||
106 | + tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | sd); | ||
107 | tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs)); | ||
108 | } | ||
109 | tcg_temp_free(tmp); | ||
74 | -- | 110 | -- |
75 | 2.48.1 | 111 | 2.31.1 |
112 | |||
113 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Huang Borong <huangborong@bosc.ac.cn> | ||
2 | 1 | ||
3 | Remove the redundant masking of "hart_idx", as the same operation is | ||
4 | performed later during address calculation. | ||
5 | |||
6 | This change impacts the "hart_idx" value in the final qemu_log_mask() | ||
7 | call. The original "hart_idx" parameter should be used for logging to | ||
8 | ensure accuracy, rather than the masked value. | ||
9 | |||
10 | Signed-off-by: Huang Borong <huangborong@bosc.ac.cn> | ||
11 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
12 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
13 | Message-ID: <20250115035105.19600-1-huangborong@bosc.ac.cn> | ||
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
15 | --- | ||
16 | hw/intc/riscv_aplic.c | 1 - | ||
17 | 1 file changed, 1 deletion(-) | ||
18 | |||
19 | diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/hw/intc/riscv_aplic.c | ||
22 | +++ b/hw/intc/riscv_aplic.c | ||
23 | @@ -XXX,XX +XXX,XX @@ static void riscv_aplic_msi_send(RISCVAPLICState *aplic, | ||
24 | APLIC_xMSICFGADDRH_HHXW_MASK; | ||
25 | |||
26 | group_idx = hart_idx >> lhxw; | ||
27 | - hart_idx &= APLIC_xMSICFGADDR_PPN_LHX_MASK(lhxw); | ||
28 | |||
29 | addr = msicfgaddr; | ||
30 | addr |= ((uint64_t)(msicfgaddrH & APLIC_xMSICFGADDRH_BAPPN_MASK)) << 32; | ||
31 | -- | ||
32 | 2.48.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Jason Chien <jason.chien@sifive.com> | ||
2 | 1 | ||
3 | Initially, the IOMMU would create a thread, but this thread was removed in | ||
4 | the merged version. The struct members for thread control should have been | ||
5 | removed as well, but they were not removed in commit 0c54acb8243 | ||
6 | ("hw/riscv: add RISC-V IOMMU base emulation"). | ||
7 | |||
8 | Signed-off-by: Jason Chien <jason.chien@sifive.com> | ||
9 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
10 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
11 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | Message-ID: <20250115141730.30858-1-jason.chien@sifive.com> | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
14 | --- | ||
15 | hw/riscv/riscv-iommu.h | 5 ----- | ||
16 | 1 file changed, 5 deletions(-) | ||
17 | |||
18 | diff --git a/hw/riscv/riscv-iommu.h b/hw/riscv/riscv-iommu.h | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/hw/riscv/riscv-iommu.h | ||
21 | +++ b/hw/riscv/riscv-iommu.h | ||
22 | @@ -XXX,XX +XXX,XX @@ struct RISCVIOMMUState { | ||
23 | /* interrupt notifier */ | ||
24 | void (*notify)(RISCVIOMMUState *iommu, unsigned vector); | ||
25 | |||
26 | - /* IOMMU State Machine */ | ||
27 | - QemuThread core_proc; /* Background processing thread */ | ||
28 | - QemuCond core_cond; /* Background processing wake up signal */ | ||
29 | - unsigned core_exec; /* Processing thread execution actions */ | ||
30 | - | ||
31 | /* IOMMU target address space */ | ||
32 | AddressSpace *target_as; | ||
33 | MemoryRegion *target_mr; | ||
34 | -- | ||
35 | 2.48.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Jason Chien <jason.chien@sifive.com> | ||
2 | 1 | ||
3 | The header contains duplicate macro definitions. | ||
4 | This commit eliminates the duplicate part. | ||
5 | |||
6 | Signed-off-by: Jason Chien <jason.chien@sifive.com> | ||
7 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
8 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | Message-ID: <20250115141730.30858-2-jason.chien@sifive.com> | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | --- | ||
13 | hw/riscv/riscv-iommu-bits.h | 22 ++++++---------------- | ||
14 | 1 file changed, 6 insertions(+), 16 deletions(-) | ||
15 | |||
16 | diff --git a/hw/riscv/riscv-iommu-bits.h b/hw/riscv/riscv-iommu-bits.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/hw/riscv/riscv-iommu-bits.h | ||
19 | +++ b/hw/riscv/riscv-iommu-bits.h | ||
20 | @@ -XXX,XX +XXX,XX @@ struct riscv_iommu_pq_record { | ||
21 | #define RISCV_IOMMU_PREQ_HDR_PRIV BIT_ULL(33) | ||
22 | #define RISCV_IOMMU_PREQ_HDR_EXEC BIT_ULL(34) | ||
23 | #define RISCV_IOMMU_PREQ_HDR_DID GENMASK_ULL(63, 40) | ||
24 | + | ||
25 | /* Payload fields */ | ||
26 | +#define RISCV_IOMMU_PREQ_PAYLOAD_R BIT_ULL(0) | ||
27 | +#define RISCV_IOMMU_PREQ_PAYLOAD_W BIT_ULL(1) | ||
28 | +#define RISCV_IOMMU_PREQ_PAYLOAD_L BIT_ULL(2) | ||
29 | #define RISCV_IOMMU_PREQ_PAYLOAD_M GENMASK_ULL(2, 0) | ||
30 | +#define RISCV_IOMMU_PREQ_PRG_INDEX GENMASK_ULL(11, 3) | ||
31 | +#define RISCV_IOMMU_PREQ_UADDR GENMASK_ULL(63, 12) | ||
32 | |||
33 | /* Common field positions */ | ||
34 | #define RISCV_IOMMU_PPN_FIELD GENMASK_ULL(53, 10) | ||
35 | @@ -XXX,XX +XXX,XX @@ enum riscv_iommu_fq_ttypes { | ||
36 | RISCV_IOMMU_FW_TTYPE_PCIE_MSG_REQ = 9, | ||
37 | }; | ||
38 | |||
39 | -/* Header fields */ | ||
40 | -#define RISCV_IOMMU_PREQ_HDR_PID GENMASK_ULL(31, 12) | ||
41 | -#define RISCV_IOMMU_PREQ_HDR_PV BIT_ULL(32) | ||
42 | -#define RISCV_IOMMU_PREQ_HDR_PRIV BIT_ULL(33) | ||
43 | -#define RISCV_IOMMU_PREQ_HDR_EXEC BIT_ULL(34) | ||
44 | -#define RISCV_IOMMU_PREQ_HDR_DID GENMASK_ULL(63, 40) | ||
45 | - | ||
46 | -/* Payload fields */ | ||
47 | -#define RISCV_IOMMU_PREQ_PAYLOAD_R BIT_ULL(0) | ||
48 | -#define RISCV_IOMMU_PREQ_PAYLOAD_W BIT_ULL(1) | ||
49 | -#define RISCV_IOMMU_PREQ_PAYLOAD_L BIT_ULL(2) | ||
50 | -#define RISCV_IOMMU_PREQ_PAYLOAD_M GENMASK_ULL(2, 0) | ||
51 | -#define RISCV_IOMMU_PREQ_PRG_INDEX GENMASK_ULL(11, 3) | ||
52 | -#define RISCV_IOMMU_PREQ_UADDR GENMASK_ULL(63, 12) | ||
53 | - | ||
54 | - | ||
55 | /* | ||
56 | * struct riscv_iommu_msi_pte - MSI Page Table Entry | ||
57 | */ | ||
58 | -- | ||
59 | 2.48.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Rodrigo Dias Correa <r@drigo.nl> | ||
2 | 1 | ||
3 | Instead of migrating the raw tick_offset, goldfish_rtc migrates a | ||
4 | recalculated value based on QEMU_CLOCK_VIRTUAL. As QEMU_CLOCK_VIRTUAL | ||
5 | stands still across a save-and-restore cycle, the guest RTC becomes out | ||
6 | of sync with the host RTC when the VM is restored. | ||
7 | |||
8 | As described in the bug description, it looks like this calculation was | ||
9 | copied from pl031 RTC, which had its tick_offset migration fixed by | ||
10 | Commit 032cfe6a79c8 ("pl031: Correctly migrate state when using -rtc | ||
11 | clock=host"). | ||
12 | |||
13 | Migrate the tick_offset directly, adding it as a version-dependent field | ||
14 | to VMState. Keep the old behavior when migrating from previous versions. | ||
15 | |||
16 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2033 | ||
17 | Signed-off-by: Rodrigo Dias Correa <r@drigo.nl> | ||
18 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
19 | Message-ID: <20250114212150.228241-1-r@drigo.nl> | ||
20 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
21 | --- | ||
22 | hw/rtc/goldfish_rtc.c | 43 +++++++++++++------------------------------ | ||
23 | 1 file changed, 13 insertions(+), 30 deletions(-) | ||
24 | |||
25 | diff --git a/hw/rtc/goldfish_rtc.c b/hw/rtc/goldfish_rtc.c | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/hw/rtc/goldfish_rtc.c | ||
28 | +++ b/hw/rtc/goldfish_rtc.c | ||
29 | @@ -XXX,XX +XXX,XX @@ static void goldfish_rtc_write(void *opaque, hwaddr offset, | ||
30 | trace_goldfish_rtc_write(offset, value); | ||
31 | } | ||
32 | |||
33 | -static int goldfish_rtc_pre_save(void *opaque) | ||
34 | -{ | ||
35 | - uint64_t delta; | ||
36 | - GoldfishRTCState *s = opaque; | ||
37 | - | ||
38 | - /* | ||
39 | - * We want to migrate this offset, which sounds straightforward. | ||
40 | - * Unfortunately, we cannot directly pass tick_offset because | ||
41 | - * rtc_clock on destination Host might not be same source Host. | ||
42 | - * | ||
43 | - * To tackle, this we pass tick_offset relative to vm_clock from | ||
44 | - * source Host and make it relative to rtc_clock at destination Host. | ||
45 | - */ | ||
46 | - delta = qemu_clock_get_ns(rtc_clock) - | ||
47 | - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
48 | - s->tick_offset_vmstate = s->tick_offset + delta; | ||
49 | - | ||
50 | - return 0; | ||
51 | -} | ||
52 | - | ||
53 | static int goldfish_rtc_post_load(void *opaque, int version_id) | ||
54 | { | ||
55 | - uint64_t delta; | ||
56 | GoldfishRTCState *s = opaque; | ||
57 | |||
58 | - /* | ||
59 | - * We extract tick_offset from tick_offset_vmstate by doing | ||
60 | - * reverse math compared to pre_save() function. | ||
61 | - */ | ||
62 | - delta = qemu_clock_get_ns(rtc_clock) - | ||
63 | - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
64 | - s->tick_offset = s->tick_offset_vmstate - delta; | ||
65 | + if (version_id < 3) { | ||
66 | + /* | ||
67 | + * Previous versions didn't migrate tick_offset directly. Instead, they | ||
68 | + * migrated tick_offset_vmstate, which is a recalculation based on | ||
69 | + * QEMU_CLOCK_VIRTUAL. We use tick_offset_vmstate when migrating from | ||
70 | + * older versions. | ||
71 | + */ | ||
72 | + uint64_t delta = qemu_clock_get_ns(rtc_clock) - | ||
73 | + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
74 | + s->tick_offset = s->tick_offset_vmstate - delta; | ||
75 | + } | ||
76 | |||
77 | goldfish_rtc_set_alarm(s); | ||
78 | |||
79 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps goldfish_rtc_ops[2] = { | ||
80 | |||
81 | static const VMStateDescription goldfish_rtc_vmstate = { | ||
82 | .name = TYPE_GOLDFISH_RTC, | ||
83 | - .version_id = 2, | ||
84 | - .pre_save = goldfish_rtc_pre_save, | ||
85 | + .version_id = 3, | ||
86 | .post_load = goldfish_rtc_post_load, | ||
87 | .fields = (const VMStateField[]) { | ||
88 | VMSTATE_UINT64(tick_offset_vmstate, GoldfishRTCState), | ||
89 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription goldfish_rtc_vmstate = { | ||
90 | VMSTATE_UINT32(irq_pending, GoldfishRTCState), | ||
91 | VMSTATE_UINT32(irq_enabled, GoldfishRTCState), | ||
92 | VMSTATE_UINT32(time_high, GoldfishRTCState), | ||
93 | + VMSTATE_UINT64_V(tick_offset, GoldfishRTCState, 3), | ||
94 | VMSTATE_END_OF_LIST() | ||
95 | } | ||
96 | }; | ||
97 | -- | ||
98 | 2.48.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Vasilis Liaskovitis <vliaskovitis@suse.com> | ||
2 | 1 | ||
3 | Add an "aliases" node with a "serial0" entry for the single UART | ||
4 | in the riscv virt machine. | ||
5 | |||
6 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2774 | ||
7 | Signed-off-by: Vasilis Liaskovitis <vliaskovitis@suse.com> | ||
8 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | Message-ID: <20250116161007.39710-1-vliaskovitis@suse.com> | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | --- | ||
13 | hw/riscv/virt.c | 3 +++ | ||
14 | 1 file changed, 3 insertions(+) | ||
15 | |||
16 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/hw/riscv/virt.c | ||
19 | +++ b/hw/riscv/virt.c | ||
20 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_uart(RISCVVirtState *s, const MemMapEntry *memmap, | ||
21 | } | ||
22 | |||
23 | qemu_fdt_setprop_string(ms->fdt, "/chosen", "stdout-path", name); | ||
24 | + qemu_fdt_setprop_string(ms->fdt, "/aliases", "serial0", name); | ||
25 | } | ||
26 | |||
27 | static void create_fdt_rtc(RISCVVirtState *s, const MemMapEntry *memmap, | ||
28 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(RISCVVirtState *s, const MemMapEntry *memmap) | ||
29 | qemu_fdt_setprop(ms->fdt, "/chosen", "rng-seed", | ||
30 | rng_seed, sizeof(rng_seed)); | ||
31 | |||
32 | + qemu_fdt_add_subnode(ms->fdt, "/aliases"); | ||
33 | + | ||
34 | create_fdt_flash(s, memmap); | ||
35 | create_fdt_fw_cfg(s, memmap); | ||
36 | create_fdt_pmu(s); | ||
37 | -- | ||
38 | 2.48.1 | diff view generated by jsdifflib |
1 | From: Rajnesh Kanwal <rkanwal@rivosinc.com> | 1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
---|---|---|---|
2 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
3 | Message-id: 6b701769d6621f45ba1739334198e36a64fe04df.1619234854.git.alistair.francis@wdc.com | ||
4 | --- | ||
5 | target/riscv/cpu_bits.h | 11 ----------- | ||
6 | target/riscv/cpu_helper.c | 32 ++++++++++++++++++++++++-------- | ||
7 | target/riscv/csr.c | 19 +++++++++++++++---- | ||
8 | target/riscv/monitor.c | 22 +++++++++++++++++----- | ||
9 | 4 files changed, 56 insertions(+), 28 deletions(-) | ||
2 | 10 | ||
3 | CTR entries are accessed using ctrsource, ctrtarget and ctrdata | 11 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h |
4 | registers using smcsrind/sscsrind extension. This commits extends | ||
5 | the csrind extension to support CTR registers. | ||
6 | |||
7 | ctrsource is accessible through xireg CSR, ctrtarget is accessible | ||
8 | through xireg1 and ctrdata is accessible through xireg2 CSR. | ||
9 | |||
10 | CTR supports maximum depth of 256 entries which are accessed using | ||
11 | xiselect range 0x200 to 0x2ff. | ||
12 | |||
13 | This commits also adds properties to enable CTR extension. CTR can be | ||
14 | enabled using smctr=true and ssctr=true now. | ||
15 | |||
16 | Signed-off-by: Rajnesh Kanwal <rkanwal@rivosinc.com> | ||
17 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
18 | Message-ID: <20250212-b4-ctr_upstream_v6-v7-1-4e8159ea33bf@rivosinc.com> | ||
19 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
20 | --- | ||
21 | target/riscv/cpu.c | 26 ++++++- | ||
22 | target/riscv/csr.c | 150 ++++++++++++++++++++++++++++++++++++- | ||
23 | target/riscv/tcg/tcg-cpu.c | 11 +++ | ||
24 | 3 files changed, 185 insertions(+), 2 deletions(-) | ||
25 | |||
26 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
27 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/target/riscv/cpu.c | 13 | --- a/target/riscv/cpu_bits.h |
29 | +++ b/target/riscv/cpu.c | 14 | +++ b/target/riscv/cpu_bits.h |
30 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { | 15 | @@ -XXX,XX +XXX,XX @@ |
31 | ISA_EXT_DATA_ENTRY(ssu64xl, PRIV_VERSION_1_12_0, has_priv_1_12), | 16 | #define SATP64_ASID 0x0FFFF00000000000ULL |
32 | ISA_EXT_DATA_ENTRY(supm, PRIV_VERSION_1_13_0, ext_supm), | 17 | #define SATP64_PPN 0x00000FFFFFFFFFFFULL |
33 | ISA_EXT_DATA_ENTRY(svade, PRIV_VERSION_1_11_0, ext_svade), | 18 | |
34 | + ISA_EXT_DATA_ENTRY(smctr, PRIV_VERSION_1_12_0, ext_smctr), | 19 | -#if defined(TARGET_RISCV32) |
35 | + ISA_EXT_DATA_ENTRY(ssctr, PRIV_VERSION_1_12_0, ext_ssctr), | 20 | -#define SATP_MODE SATP32_MODE |
36 | ISA_EXT_DATA_ENTRY(svadu, PRIV_VERSION_1_12_0, ext_svadu), | 21 | -#define SATP_ASID SATP32_ASID |
37 | ISA_EXT_DATA_ENTRY(svinval, PRIV_VERSION_1_12_0, ext_svinval), | 22 | -#define SATP_PPN SATP32_PPN |
38 | ISA_EXT_DATA_ENTRY(svnapot, PRIV_VERSION_1_12_0, ext_svnapot), | 23 | -#endif |
39 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { | 24 | -#if defined(TARGET_RISCV64) |
40 | MULTI_EXT_CFG_BOOL("smcdeleg", ext_smcdeleg, false), | 25 | -#define SATP_MODE SATP64_MODE |
41 | MULTI_EXT_CFG_BOOL("sscsrind", ext_sscsrind, false), | 26 | -#define SATP_ASID SATP64_ASID |
42 | MULTI_EXT_CFG_BOOL("ssccfg", ext_ssccfg, false), | 27 | -#define SATP_PPN SATP64_PPN |
43 | + MULTI_EXT_CFG_BOOL("smctr", ext_smctr, false), | 28 | -#endif |
44 | + MULTI_EXT_CFG_BOOL("ssctr", ext_ssctr, false), | 29 | - |
45 | MULTI_EXT_CFG_BOOL("zifencei", ext_zifencei, true), | 30 | /* VM modes (mstatus.vm) privileged ISA 1.9.1 */ |
46 | MULTI_EXT_CFG_BOOL("zicfilp", ext_zicfilp, false), | 31 | #define VM_1_09_MBARE 0 |
47 | MULTI_EXT_CFG_BOOL("zicfiss", ext_zicfiss, false), | 32 | #define VM_1_09_MBB 1 |
48 | @@ -XXX,XX +XXX,XX @@ static RISCVCPUImpliedExtsRule SSPM_IMPLIED = { | 33 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
49 | }, | 34 | index XXXXXXX..XXXXXXX 100644 |
50 | }; | 35 | --- a/target/riscv/cpu_helper.c |
51 | 36 | +++ b/target/riscv/cpu_helper.c | |
52 | +static RISCVCPUImpliedExtsRule SMCTR_IMPLIED = { | 37 | @@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, |
53 | + .ext = CPU_CFG_OFFSET(ext_smctr), | 38 | |
54 | + .implied_misa_exts = RVS, | 39 | if (first_stage == true) { |
55 | + .implied_multi_exts = { | 40 | if (use_background) { |
56 | + CPU_CFG_OFFSET(ext_sscsrind), | 41 | - base = (hwaddr)get_field(env->vsatp, SATP_PPN) << PGSHIFT; |
42 | - vm = get_field(env->vsatp, SATP_MODE); | ||
43 | + if (riscv_cpu_is_32bit(env)) { | ||
44 | + base = (hwaddr)get_field(env->vsatp, SATP32_PPN) << PGSHIFT; | ||
45 | + vm = get_field(env->vsatp, SATP32_MODE); | ||
46 | + } else { | ||
47 | + base = (hwaddr)get_field(env->vsatp, SATP64_PPN) << PGSHIFT; | ||
48 | + vm = get_field(env->vsatp, SATP64_MODE); | ||
49 | + } | ||
50 | } else { | ||
51 | - base = (hwaddr)get_field(env->satp, SATP_PPN) << PGSHIFT; | ||
52 | - vm = get_field(env->satp, SATP_MODE); | ||
53 | + if (riscv_cpu_is_32bit(env)) { | ||
54 | + base = (hwaddr)get_field(env->satp, SATP32_PPN) << PGSHIFT; | ||
55 | + vm = get_field(env->satp, SATP32_MODE); | ||
56 | + } else { | ||
57 | + base = (hwaddr)get_field(env->satp, SATP64_PPN) << PGSHIFT; | ||
58 | + vm = get_field(env->satp, SATP64_MODE); | ||
59 | + } | ||
60 | } | ||
61 | widened = 0; | ||
62 | } else { | ||
63 | @@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address, | ||
64 | { | ||
65 | CPUState *cs = env_cpu(env); | ||
66 | int page_fault_exceptions, vm; | ||
67 | + uint64_t stap_mode; | ||
57 | + | 68 | + |
58 | + RISCV_IMPLIED_EXTS_RULE_END | 69 | + if (riscv_cpu_is_32bit(env)) { |
59 | + }, | 70 | + stap_mode = SATP32_MODE; |
60 | +}; | 71 | + } else { |
72 | + stap_mode = SATP64_MODE; | ||
73 | + } | ||
74 | |||
75 | if (first_stage) { | ||
76 | - vm = get_field(env->satp, SATP_MODE); | ||
77 | - } else if (riscv_cpu_is_32bit(env)) { | ||
78 | - vm = get_field(env->hgatp, SATP32_MODE); | ||
79 | + vm = get_field(env->satp, stap_mode); | ||
80 | } else { | ||
81 | - vm = get_field(env->hgatp, SATP64_MODE); | ||
82 | + vm = get_field(env->hgatp, stap_mode); | ||
83 | } | ||
61 | + | 84 | + |
62 | +static RISCVCPUImpliedExtsRule SSCTR_IMPLIED = { | 85 | page_fault_exceptions = vm != VM_1_10_MBARE && !pmp_violation; |
63 | + .ext = CPU_CFG_OFFSET(ext_ssctr), | 86 | |
64 | + .implied_misa_exts = RVS, | 87 | switch (access_type) { |
65 | + .implied_multi_exts = { | ||
66 | + CPU_CFG_OFFSET(ext_sscsrind), | ||
67 | + | ||
68 | + RISCV_IMPLIED_EXTS_RULE_END | ||
69 | + }, | ||
70 | +}; | ||
71 | + | ||
72 | RISCVCPUImpliedExtsRule *riscv_misa_ext_implied_rules[] = { | ||
73 | &RVA_IMPLIED, &RVD_IMPLIED, &RVF_IMPLIED, | ||
74 | &RVM_IMPLIED, &RVV_IMPLIED, NULL | ||
75 | @@ -XXX,XX +XXX,XX @@ RISCVCPUImpliedExtsRule *riscv_multi_ext_implied_rules[] = { | ||
76 | &ZVFH_IMPLIED, &ZVFHMIN_IMPLIED, &ZVKN_IMPLIED, | ||
77 | &ZVKNC_IMPLIED, &ZVKNG_IMPLIED, &ZVKNHB_IMPLIED, | ||
78 | &ZVKS_IMPLIED, &ZVKSC_IMPLIED, &ZVKSG_IMPLIED, &SSCFG_IMPLIED, | ||
79 | - &SUPM_IMPLIED, &SSPM_IMPLIED, | ||
80 | + &SUPM_IMPLIED, &SSPM_IMPLIED, &SMCTR_IMPLIED, &SSCTR_IMPLIED, | ||
81 | NULL | ||
82 | }; | ||
83 | |||
84 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 88 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
85 | index XXXXXXX..XXXXXXX 100644 | 89 | index XXXXXXX..XXXXXXX 100644 |
86 | --- a/target/riscv/csr.c | 90 | --- a/target/riscv/csr.c |
87 | +++ b/target/riscv/csr.c | 91 | +++ b/target/riscv/csr.c |
88 | @@ -XXX,XX +XXX,XX @@ static bool xiselect_cd_range(target_ulong isel) | 92 | @@ -XXX,XX +XXX,XX @@ static RISCVException read_satp(CPURISCVState *env, int csrno, |
89 | return (ISELECT_CD_FIRST <= isel && isel <= ISELECT_CD_LAST); | 93 | static RISCVException write_satp(CPURISCVState *env, int csrno, |
90 | } | 94 | target_ulong val) |
91 | 95 | { | |
92 | +static bool xiselect_ctr_range(int csrno, target_ulong isel) | 96 | + int vm, mask, asid; |
93 | +{ | ||
94 | + /* MIREG-MIREG6 for the range 0x200-0x2ff are not used by CTR. */ | ||
95 | + return CTR_ENTRIES_FIRST <= isel && isel <= CTR_ENTRIES_LAST && | ||
96 | + csrno < CSR_MIREG; | ||
97 | +} | ||
98 | + | 97 | + |
99 | static int rmw_iprio(target_ulong xlen, | 98 | if (!riscv_feature(env, RISCV_FEATURE_MMU)) { |
100 | target_ulong iselect, uint8_t *iprio, | 99 | return RISCV_EXCP_NONE; |
101 | target_ulong *val, target_ulong new_val, | 100 | } |
102 | @@ -XXX,XX +XXX,XX @@ static int rmw_iprio(target_ulong xlen, | 101 | - if (validate_vm(env, get_field(val, SATP_MODE)) && |
103 | return 0; | 102 | - ((val ^ env->satp) & (SATP_MODE | SATP_ASID | SATP_PPN))) |
104 | } | 103 | - { |
105 | |||
106 | +static int rmw_ctrsource(CPURISCVState *env, int isel, target_ulong *val, | ||
107 | + target_ulong new_val, target_ulong wr_mask) | ||
108 | +{ | ||
109 | + /* | ||
110 | + * CTR arrays are treated as circular buffers and TOS always points to next | ||
111 | + * empty slot, keeping TOS - 1 always pointing to latest entry. Given entry | ||
112 | + * 0 is always the latest one, traversal is a bit different here. See the | ||
113 | + * below example. | ||
114 | + * | ||
115 | + * Depth = 16. | ||
116 | + * | ||
117 | + * idx [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [A] [B] [C] [D] [E] [F] | ||
118 | + * TOS H | ||
119 | + * entry 6 5 4 3 2 1 0 F E D C B A 9 8 7 | ||
120 | + */ | ||
121 | + const uint64_t entry = isel - CTR_ENTRIES_FIRST; | ||
122 | + const uint64_t depth = 16 << get_field(env->sctrdepth, SCTRDEPTH_MASK); | ||
123 | + uint64_t idx; | ||
124 | + | 104 | + |
125 | + /* Entry greater than depth-1 is read-only zero */ | 105 | + if (riscv_cpu_is_32bit(env)) { |
126 | + if (entry >= depth) { | 106 | + vm = validate_vm(env, get_field(val, SATP32_MODE)); |
127 | + if (val) { | 107 | + mask = (val ^ env->satp) & (SATP32_MODE | SATP32_ASID | SATP32_PPN); |
128 | + *val = 0; | 108 | + asid = (val ^ env->satp) & SATP32_ASID; |
129 | + } | 109 | + } else { |
130 | + return 0; | 110 | + vm = validate_vm(env, get_field(val, SATP64_MODE)); |
111 | + mask = (val ^ env->satp) & (SATP64_MODE | SATP64_ASID | SATP64_PPN); | ||
112 | + asid = (val ^ env->satp) & SATP64_ASID; | ||
131 | + } | 113 | + } |
132 | + | 114 | + |
133 | + idx = get_field(env->sctrstatus, SCTRSTATUS_WRPTR_MASK); | 115 | + if (vm && mask) { |
134 | + idx = (idx - entry - 1) & (depth - 1); | 116 | if (env->priv == PRV_S && get_field(env->mstatus, MSTATUS_TVM)) { |
135 | + | 117 | return RISCV_EXCP_ILLEGAL_INST; |
136 | + if (val) { | 118 | } else { |
137 | + *val = env->ctr_src[idx]; | 119 | - if ((val ^ env->satp) & SATP_ASID) { |
120 | + if (asid) { | ||
121 | tlb_flush(env_cpu(env)); | ||
122 | } | ||
123 | env->satp = val; | ||
124 | diff --git a/target/riscv/monitor.c b/target/riscv/monitor.c | ||
125 | index XXXXXXX..XXXXXXX 100644 | ||
126 | --- a/target/riscv/monitor.c | ||
127 | +++ b/target/riscv/monitor.c | ||
128 | @@ -XXX,XX +XXX,XX @@ static void mem_info_svxx(Monitor *mon, CPUArchState *env) | ||
129 | target_ulong last_size; | ||
130 | int last_attr; | ||
131 | |||
132 | - base = (hwaddr)get_field(env->satp, SATP_PPN) << PGSHIFT; | ||
133 | + if (riscv_cpu_is_32bit(env)) { | ||
134 | + base = (hwaddr)get_field(env->satp, SATP32_PPN) << PGSHIFT; | ||
135 | + vm = get_field(env->satp, SATP32_MODE); | ||
136 | + } else { | ||
137 | + base = (hwaddr)get_field(env->satp, SATP64_PPN) << PGSHIFT; | ||
138 | + vm = get_field(env->satp, SATP64_MODE); | ||
138 | + } | 139 | + } |
139 | + | 140 | |
140 | + env->ctr_src[idx] = (env->ctr_src[idx] & ~wr_mask) | (new_val & wr_mask); | 141 | - vm = get_field(env->satp, SATP_MODE); |
141 | + | 142 | switch (vm) { |
142 | + return 0; | 143 | case VM_1_10_SV32: |
143 | +} | 144 | levels = 2; |
144 | + | 145 | @@ -XXX,XX +XXX,XX @@ void hmp_info_mem(Monitor *mon, const QDict *qdict) |
145 | +static int rmw_ctrtarget(CPURISCVState *env, int isel, target_ulong *val, | ||
146 | + target_ulong new_val, target_ulong wr_mask) | ||
147 | +{ | ||
148 | + /* | ||
149 | + * CTR arrays are treated as circular buffers and TOS always points to next | ||
150 | + * empty slot, keeping TOS - 1 always pointing to latest entry. Given entry | ||
151 | + * 0 is always the latest one, traversal is a bit different here. See the | ||
152 | + * below example. | ||
153 | + * | ||
154 | + * Depth = 16. | ||
155 | + * | ||
156 | + * idx [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [A] [B] [C] [D] [E] [F] | ||
157 | + * head H | ||
158 | + * entry 6 5 4 3 2 1 0 F E D C B A 9 8 7 | ||
159 | + */ | ||
160 | + const uint64_t entry = isel - CTR_ENTRIES_FIRST; | ||
161 | + const uint64_t depth = 16 << get_field(env->sctrdepth, SCTRDEPTH_MASK); | ||
162 | + uint64_t idx; | ||
163 | + | ||
164 | + /* Entry greater than depth-1 is read-only zero */ | ||
165 | + if (entry >= depth) { | ||
166 | + if (val) { | ||
167 | + *val = 0; | ||
168 | + } | ||
169 | + return 0; | ||
170 | + } | ||
171 | + | ||
172 | + idx = get_field(env->sctrstatus, SCTRSTATUS_WRPTR_MASK); | ||
173 | + idx = (idx - entry - 1) & (depth - 1); | ||
174 | + | ||
175 | + if (val) { | ||
176 | + *val = env->ctr_dst[idx]; | ||
177 | + } | ||
178 | + | ||
179 | + env->ctr_dst[idx] = (env->ctr_dst[idx] & ~wr_mask) | (new_val & wr_mask); | ||
180 | + | ||
181 | + return 0; | ||
182 | +} | ||
183 | + | ||
184 | +static int rmw_ctrdata(CPURISCVState *env, int isel, target_ulong *val, | ||
185 | + target_ulong new_val, target_ulong wr_mask) | ||
186 | +{ | ||
187 | + /* | ||
188 | + * CTR arrays are treated as circular buffers and TOS always points to next | ||
189 | + * empty slot, keeping TOS - 1 always pointing to latest entry. Given entry | ||
190 | + * 0 is always the latest one, traversal is a bit different here. See the | ||
191 | + * below example. | ||
192 | + * | ||
193 | + * Depth = 16. | ||
194 | + * | ||
195 | + * idx [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [A] [B] [C] [D] [E] [F] | ||
196 | + * head H | ||
197 | + * entry 6 5 4 3 2 1 0 F E D C B A 9 8 7 | ||
198 | + */ | ||
199 | + const uint64_t entry = isel - CTR_ENTRIES_FIRST; | ||
200 | + const uint64_t mask = wr_mask & CTRDATA_MASK; | ||
201 | + const uint64_t depth = 16 << get_field(env->sctrdepth, SCTRDEPTH_MASK); | ||
202 | + uint64_t idx; | ||
203 | + | ||
204 | + /* Entry greater than depth-1 is read-only zero */ | ||
205 | + if (entry >= depth) { | ||
206 | + if (val) { | ||
207 | + *val = 0; | ||
208 | + } | ||
209 | + return 0; | ||
210 | + } | ||
211 | + | ||
212 | + idx = get_field(env->sctrstatus, SCTRSTATUS_WRPTR_MASK); | ||
213 | + idx = (idx - entry - 1) & (depth - 1); | ||
214 | + | ||
215 | + if (val) { | ||
216 | + *val = env->ctr_data[idx]; | ||
217 | + } | ||
218 | + | ||
219 | + env->ctr_data[idx] = (env->ctr_data[idx] & ~mask) | (new_val & mask); | ||
220 | + | ||
221 | + return 0; | ||
222 | +} | ||
223 | + | ||
224 | static RISCVException rmw_xireg_aia(CPURISCVState *env, int csrno, | ||
225 | target_ulong isel, target_ulong *val, | ||
226 | target_ulong new_val, target_ulong wr_mask) | ||
227 | @@ -XXX,XX +XXX,XX @@ done: | ||
228 | return ret; | ||
229 | } | ||
230 | |||
231 | +static int rmw_xireg_ctr(CPURISCVState *env, int csrno, | ||
232 | + target_ulong isel, target_ulong *val, | ||
233 | + target_ulong new_val, target_ulong wr_mask) | ||
234 | +{ | ||
235 | + if (!riscv_cpu_cfg(env)->ext_smctr && !riscv_cpu_cfg(env)->ext_ssctr) { | ||
236 | + return -EINVAL; | ||
237 | + } | ||
238 | + | ||
239 | + if (csrno == CSR_SIREG || csrno == CSR_VSIREG) { | ||
240 | + return rmw_ctrsource(env, isel, val, new_val, wr_mask); | ||
241 | + } else if (csrno == CSR_SIREG2 || csrno == CSR_VSIREG2) { | ||
242 | + return rmw_ctrtarget(env, isel, val, new_val, wr_mask); | ||
243 | + } else if (csrno == CSR_SIREG3 || csrno == CSR_VSIREG3) { | ||
244 | + return rmw_ctrdata(env, isel, val, new_val, wr_mask); | ||
245 | + } else if (val) { | ||
246 | + *val = 0; | ||
247 | + } | ||
248 | + | ||
249 | + return 0; | ||
250 | +} | ||
251 | + | ||
252 | /* | ||
253 | * rmw_xireg_csrind: Perform indirect access to xireg and xireg2-xireg6 | ||
254 | * | ||
255 | @@ -XXX,XX +XXX,XX @@ static int rmw_xireg_csrind(CPURISCVState *env, int csrno, | ||
256 | target_ulong isel, target_ulong *val, | ||
257 | target_ulong new_val, target_ulong wr_mask) | ||
258 | { | ||
259 | - int ret = -EINVAL; | ||
260 | bool virt = csrno == CSR_VSIREG ? true : false; | ||
261 | + int ret = -EINVAL; | ||
262 | |||
263 | if (xiselect_cd_range(isel)) { | ||
264 | ret = rmw_xireg_cd(env, csrno, isel, val, new_val, wr_mask); | ||
265 | + } else if (xiselect_ctr_range(csrno, isel)) { | ||
266 | + ret = rmw_xireg_ctr(env, csrno, isel, val, new_val, wr_mask); | ||
267 | } else { | ||
268 | /* | ||
269 | * As per the specification, access to unimplented region is undefined | ||
270 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
271 | index XXXXXXX..XXXXXXX 100644 | ||
272 | --- a/target/riscv/tcg/tcg-cpu.c | ||
273 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
274 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
275 | return; | 146 | return; |
276 | } | 147 | } |
277 | 148 | ||
278 | + if ((cpu->cfg.ext_smctr || cpu->cfg.ext_ssctr) && | 149 | - if (!(env->satp & SATP_MODE)) { |
279 | + (!riscv_has_ext(env, RVS) || !cpu->cfg.ext_sscsrind)) { | 150 | - monitor_printf(mon, "No translation or protection\n"); |
280 | + if (cpu_cfg_ext_is_user_set(CPU_CFG_OFFSET(ext_smctr)) || | 151 | - return; |
281 | + cpu_cfg_ext_is_user_set(CPU_CFG_OFFSET(ext_ssctr))) { | 152 | + if (riscv_cpu_is_32bit(env)) { |
282 | + error_setg(errp, "Smctr and Ssctr require S-mode and Sscsrind"); | 153 | + if (!(env->satp & SATP32_MODE)) { |
154 | + monitor_printf(mon, "No translation or protection\n"); | ||
283 | + return; | 155 | + return; |
284 | + } | 156 | + } |
285 | + cpu->cfg.ext_smctr = false; | 157 | + } else { |
286 | + cpu->cfg.ext_ssctr = false; | 158 | + if (!(env->satp & SATP64_MODE)) { |
287 | + } | 159 | + monitor_printf(mon, "No translation or protection\n"); |
288 | + | 160 | + return; |
289 | /* | 161 | + } |
290 | * Disable isa extensions based on priv spec after we | 162 | } |
291 | * validated and set everything we need. | 163 | |
164 | mem_info_svxx(mon, env); | ||
292 | -- | 165 | -- |
293 | 2.48.1 | 166 | 2.31.1 |
167 | |||
168 | diff view generated by jsdifflib |
1 | From: Rajnesh Kanwal <rkanwal@rivosinc.com> | ||
---|---|---|---|
2 | |||
3 | The Control Transfer Records (CTR) extension provides a method to | ||
4 | record a limited branch history in register-accessible internal chip | ||
5 | storage. | ||
6 | |||
7 | This extension is similar to Arch LBR in x86 and BRBE in ARM. | ||
8 | The Extension has been stable and the latest release can be found here | ||
9 | https://github.com/riscv/riscv-control-transfer-records/releases/tag/v1.0_rc5 | ||
10 | |||
11 | Signed-off-by: Rajnesh Kanwal <rkanwal@rivosinc.com> | ||
12 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | Message-ID: <20250205-b4-ctr_upstream_v6-v6-2-439d8e06c8ef@rivosinc.com> | ||
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
2 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
3 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
4 | Message-id: e095b57af0d419c8ed822958f04dfc732d7beb7e.1619234854.git.alistair.francis@wdc.com | ||
15 | --- | 5 | --- |
16 | target/riscv/cpu_bits.h | 145 ++++++++++++++++++++++++++++++++++++++++ | 6 | target/riscv/cpu_bits.h | 6 ------ |
17 | 1 file changed, 145 insertions(+) | 7 | 1 file changed, 6 deletions(-) |
18 | 8 | ||
19 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h | 9 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h |
20 | index XXXXXXX..XXXXXXX 100644 | 10 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/riscv/cpu_bits.h | 11 | --- a/target/riscv/cpu_bits.h |
22 | +++ b/target/riscv/cpu_bits.h | 12 | +++ b/target/riscv/cpu_bits.h |
23 | @@ -XXX,XX +XXX,XX @@ | 13 | @@ -XXX,XX +XXX,XX @@ |
24 | #define CSR_SIEH 0x114 | 14 | #define HSTATUS32_WPRI 0xFF8FF87E |
25 | #define CSR_SIPH 0x154 | 15 | #define HSTATUS64_WPRI 0xFFFFFFFFFF8FF87EULL |
26 | 16 | ||
27 | +/* Machine-Level Control transfer records CSRs */ | 17 | -#if defined(TARGET_RISCV32) |
28 | +#define CSR_MCTRCTL 0x34e | 18 | -#define HSTATUS_WPRI HSTATUS32_WPRI |
29 | + | 19 | -#elif defined(TARGET_RISCV64) |
30 | +/* Supervisor-Level Control transfer records CSRs */ | 20 | -#define HSTATUS_WPRI HSTATUS64_WPRI |
31 | +#define CSR_SCTRCTL 0x14e | 21 | -#endif |
32 | +#define CSR_SCTRSTATUS 0x14f | 22 | - |
33 | +#define CSR_SCTRDEPTH 0x15f | 23 | #define HCOUNTEREN_CY (1 << 0) |
34 | + | 24 | #define HCOUNTEREN_TM (1 << 1) |
35 | +/* VS-Level Control transfer records CSRs */ | 25 | #define HCOUNTEREN_IR (1 << 2) |
36 | +#define CSR_VSCTRCTL 0x24e | ||
37 | + | ||
38 | /* Hpervisor CSRs */ | ||
39 | #define CSR_HSTATUS 0x600 | ||
40 | #define CSR_HEDELEG 0x602 | ||
41 | @@ -XXX,XX +XXX,XX @@ | ||
42 | #define SMSTATEEN0_CS (1ULL << 0) | ||
43 | #define SMSTATEEN0_FCSR (1ULL << 1) | ||
44 | #define SMSTATEEN0_JVT (1ULL << 2) | ||
45 | +#define SMSTATEEN0_CTR (1ULL << 54) | ||
46 | #define SMSTATEEN0_P1P13 (1ULL << 56) | ||
47 | #define SMSTATEEN0_HSCONTXT (1ULL << 57) | ||
48 | #define SMSTATEEN0_IMSIC (1ULL << 58) | ||
49 | @@ -XXX,XX +XXX,XX @@ typedef enum RISCVException { | ||
50 | #define HENVCFGH_PBMTE MENVCFGH_PBMTE | ||
51 | #define HENVCFGH_STCE MENVCFGH_STCE | ||
52 | |||
53 | +/* Offsets for every pair of control bits per each priv level */ | ||
54 | +#define XS_OFFSET 0ULL | ||
55 | +#define U_OFFSET 2ULL | ||
56 | +#define S_OFFSET 5ULL | ||
57 | +#define M_OFFSET 8ULL | ||
58 | + | ||
59 | +#define PM_XS_BITS (EXT_STATUS_MASK << XS_OFFSET) | ||
60 | +#define U_PM_ENABLE (PM_ENABLE << U_OFFSET) | ||
61 | +#define U_PM_CURRENT (PM_CURRENT << U_OFFSET) | ||
62 | +#define U_PM_INSN (PM_INSN << U_OFFSET) | ||
63 | +#define S_PM_ENABLE (PM_ENABLE << S_OFFSET) | ||
64 | +#define S_PM_CURRENT (PM_CURRENT << S_OFFSET) | ||
65 | +#define S_PM_INSN (PM_INSN << S_OFFSET) | ||
66 | +#define M_PM_ENABLE (PM_ENABLE << M_OFFSET) | ||
67 | +#define M_PM_CURRENT (PM_CURRENT << M_OFFSET) | ||
68 | +#define M_PM_INSN (PM_INSN << M_OFFSET) | ||
69 | + | ||
70 | +/* mmte CSR bits */ | ||
71 | +#define MMTE_PM_XS_BITS PM_XS_BITS | ||
72 | +#define MMTE_U_PM_ENABLE U_PM_ENABLE | ||
73 | +#define MMTE_U_PM_CURRENT U_PM_CURRENT | ||
74 | +#define MMTE_U_PM_INSN U_PM_INSN | ||
75 | +#define MMTE_S_PM_ENABLE S_PM_ENABLE | ||
76 | +#define MMTE_S_PM_CURRENT S_PM_CURRENT | ||
77 | +#define MMTE_S_PM_INSN S_PM_INSN | ||
78 | +#define MMTE_M_PM_ENABLE M_PM_ENABLE | ||
79 | +#define MMTE_M_PM_CURRENT M_PM_CURRENT | ||
80 | +#define MMTE_M_PM_INSN M_PM_INSN | ||
81 | +#define MMTE_MASK (MMTE_U_PM_ENABLE | MMTE_U_PM_CURRENT | MMTE_U_PM_INSN | \ | ||
82 | + MMTE_S_PM_ENABLE | MMTE_S_PM_CURRENT | MMTE_S_PM_INSN | \ | ||
83 | + MMTE_M_PM_ENABLE | MMTE_M_PM_CURRENT | MMTE_M_PM_INSN | \ | ||
84 | + MMTE_PM_XS_BITS) | ||
85 | + | ||
86 | +/* (v)smte CSR bits */ | ||
87 | +#define SMTE_PM_XS_BITS PM_XS_BITS | ||
88 | +#define SMTE_U_PM_ENABLE U_PM_ENABLE | ||
89 | +#define SMTE_U_PM_CURRENT U_PM_CURRENT | ||
90 | +#define SMTE_U_PM_INSN U_PM_INSN | ||
91 | +#define SMTE_S_PM_ENABLE S_PM_ENABLE | ||
92 | +#define SMTE_S_PM_CURRENT S_PM_CURRENT | ||
93 | +#define SMTE_S_PM_INSN S_PM_INSN | ||
94 | +#define SMTE_MASK (SMTE_U_PM_ENABLE | SMTE_U_PM_CURRENT | SMTE_U_PM_INSN | \ | ||
95 | + SMTE_S_PM_ENABLE | SMTE_S_PM_CURRENT | SMTE_S_PM_INSN | \ | ||
96 | + SMTE_PM_XS_BITS) | ||
97 | + | ||
98 | +/* umte CSR bits */ | ||
99 | +#define UMTE_U_PM_ENABLE U_PM_ENABLE | ||
100 | +#define UMTE_U_PM_CURRENT U_PM_CURRENT | ||
101 | +#define UMTE_U_PM_INSN U_PM_INSN | ||
102 | +#define UMTE_MASK (UMTE_U_PM_ENABLE | MMTE_U_PM_CURRENT | UMTE_U_PM_INSN) | ||
103 | + | ||
104 | +/* CTR control register commom fields */ | ||
105 | +#define XCTRCTL_U BIT_ULL(0) | ||
106 | +#define XCTRCTL_S BIT_ULL(1) | ||
107 | +#define XCTRCTL_RASEMU BIT_ULL(7) | ||
108 | +#define XCTRCTL_STE BIT_ULL(8) | ||
109 | +#define XCTRCTL_BPFRZ BIT_ULL(11) | ||
110 | +#define XCTRCTL_LCOFIFRZ BIT_ULL(12) | ||
111 | +#define XCTRCTL_EXCINH BIT_ULL(33) | ||
112 | +#define XCTRCTL_INTRINH BIT_ULL(34) | ||
113 | +#define XCTRCTL_TRETINH BIT_ULL(35) | ||
114 | +#define XCTRCTL_NTBREN BIT_ULL(36) | ||
115 | +#define XCTRCTL_TKBRINH BIT_ULL(37) | ||
116 | +#define XCTRCTL_INDCALLINH BIT_ULL(40) | ||
117 | +#define XCTRCTL_DIRCALLINH BIT_ULL(41) | ||
118 | +#define XCTRCTL_INDJMPINH BIT_ULL(42) | ||
119 | +#define XCTRCTL_DIRJMPINH BIT_ULL(43) | ||
120 | +#define XCTRCTL_CORSWAPINH BIT_ULL(44) | ||
121 | +#define XCTRCTL_RETINH BIT_ULL(45) | ||
122 | +#define XCTRCTL_INDLJMPINH BIT_ULL(46) | ||
123 | +#define XCTRCTL_DIRLJMPINH BIT_ULL(47) | ||
124 | + | ||
125 | +#define XCTRCTL_MASK (XCTRCTL_U | XCTRCTL_S | XCTRCTL_RASEMU | \ | ||
126 | + XCTRCTL_STE | XCTRCTL_BPFRZ | XCTRCTL_LCOFIFRZ | \ | ||
127 | + XCTRCTL_EXCINH | XCTRCTL_INTRINH | XCTRCTL_TRETINH | \ | ||
128 | + XCTRCTL_NTBREN | XCTRCTL_TKBRINH | XCTRCTL_INDCALLINH | \ | ||
129 | + XCTRCTL_DIRCALLINH | XCTRCTL_INDJMPINH | \ | ||
130 | + XCTRCTL_DIRJMPINH | XCTRCTL_CORSWAPINH | \ | ||
131 | + XCTRCTL_RETINH | XCTRCTL_INDLJMPINH | XCTRCTL_DIRLJMPINH) | ||
132 | + | ||
133 | +#define XCTRCTL_INH_START 32U | ||
134 | + | ||
135 | +/* CTR mctrctl bits */ | ||
136 | +#define MCTRCTL_M BIT_ULL(2) | ||
137 | +#define MCTRCTL_MTE BIT_ULL(9) | ||
138 | + | ||
139 | +#define MCTRCTL_MASK (XCTRCTL_MASK | MCTRCTL_M | MCTRCTL_MTE) | ||
140 | +#define SCTRCTL_MASK XCTRCTL_MASK | ||
141 | +#define VSCTRCTL_MASK XCTRCTL_MASK | ||
142 | + | ||
143 | +/* sctrstatus CSR bits. */ | ||
144 | +#define SCTRSTATUS_WRPTR_MASK 0xFF | ||
145 | +#define SCTRSTATUS_FROZEN BIT(31) | ||
146 | +#define SCTRSTATUS_MASK (SCTRSTATUS_WRPTR_MASK | SCTRSTATUS_FROZEN) | ||
147 | + | ||
148 | +/* sctrdepth CSR bits. */ | ||
149 | +#define SCTRDEPTH_MASK 0x7 | ||
150 | +#define SCTRDEPTH_MIN 0U /* 16 Entries. */ | ||
151 | +#define SCTRDEPTH_MAX 4U /* 256 Entries. */ | ||
152 | + | ||
153 | +#define CTR_ENTRIES_FIRST 0x200 | ||
154 | +#define CTR_ENTRIES_LAST 0x2ff | ||
155 | + | ||
156 | +#define CTRSOURCE_VALID BIT(0) | ||
157 | +#define CTRTARGET_MISP BIT(0) | ||
158 | + | ||
159 | +#define CTRDATA_TYPE_MASK 0xF | ||
160 | +#define CTRDATA_CCV BIT(15) | ||
161 | +#define CTRDATA_CCM_MASK 0xFFF0000 | ||
162 | +#define CTRDATA_CCE_MASK 0xF0000000 | ||
163 | + | ||
164 | +#define CTRDATA_MASK (CTRDATA_TYPE_MASK | CTRDATA_CCV | \ | ||
165 | + CTRDATA_CCM_MASK | CTRDATA_CCE_MASK) | ||
166 | + | ||
167 | +typedef enum CTRType { | ||
168 | + CTRDATA_TYPE_NONE = 0, | ||
169 | + CTRDATA_TYPE_EXCEPTION = 1, | ||
170 | + CTRDATA_TYPE_INTERRUPT = 2, | ||
171 | + CTRDATA_TYPE_EXCEP_INT_RET = 3, | ||
172 | + CTRDATA_TYPE_NONTAKEN_BRANCH = 4, | ||
173 | + CTRDATA_TYPE_TAKEN_BRANCH = 5, | ||
174 | + CTRDATA_TYPE_RESERVED_0 = 6, | ||
175 | + CTRDATA_TYPE_RESERVED_1 = 7, | ||
176 | + CTRDATA_TYPE_INDIRECT_CALL = 8, | ||
177 | + CTRDATA_TYPE_DIRECT_CALL = 9, | ||
178 | + CTRDATA_TYPE_INDIRECT_JUMP = 10, | ||
179 | + CTRDATA_TYPE_DIRECT_JUMP = 11, | ||
180 | + CTRDATA_TYPE_CO_ROUTINE_SWAP = 12, | ||
181 | + CTRDATA_TYPE_RETURN = 13, | ||
182 | + CTRDATA_TYPE_OTHER_INDIRECT_JUMP = 14, | ||
183 | + CTRDATA_TYPE_OTHER_DIRECT_JUMP = 15, | ||
184 | +} CTRType; | ||
185 | + | ||
186 | /* MISELECT, SISELECT, and VSISELECT bits (AIA) */ | ||
187 | #define ISELECT_IPRIO0 0x30 | ||
188 | #define ISELECT_IPRIO15 0x3f | ||
189 | -- | 26 | -- |
190 | 2.48.1 | 27 | 2.31.1 |
28 | |||
29 | diff view generated by jsdifflib |
1 | From: Andrea Bolognani <abologna@redhat.com> | 1 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
---|---|---|---|
2 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
3 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
4 | Message-id: 4853459564af35a6690120c74ad892f60cec35ff.1619234854.git.alistair.francis@wdc.com | ||
5 | --- | ||
6 | target/riscv/translate.c | 6 ------ | ||
7 | 1 file changed, 6 deletions(-) | ||
2 | 8 | ||
3 | Right now information regarding the family each CPU type belongs | 9 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c |
4 | to is recorded in two places: the large data table at the top of | 10 | index XXXXXXX..XXXXXXX 100644 |
5 | the script, and the qemu_host_family() function. | 11 | --- a/target/riscv/translate.c |
12 | +++ b/target/riscv/translate.c | ||
13 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { | ||
14 | CPUState *cs; | ||
15 | } DisasContext; | ||
16 | |||
17 | -#ifdef TARGET_RISCV64 | ||
18 | -#define CASE_OP_32_64(X) case X: case glue(X, W) | ||
19 | -#else | ||
20 | -#define CASE_OP_32_64(X) case X | ||
21 | -#endif | ||
22 | - | ||
23 | static inline bool has_ext(DisasContext *ctx, uint32_t ext) | ||
24 | { | ||
25 | return ctx->misa & ext; | ||
26 | -- | ||
27 | 2.31.1 | ||
6 | 28 | ||
7 | We can make things better by mapping host CPU architecture to | ||
8 | QEMU target in the few cases where the two don't already match | ||
9 | and then using the data table to look up the family, same as | ||
10 | we're already doing for the guest CPU architecture. | ||
11 | 29 | ||
12 | Being able to reason in terms of QEMU target regardless of | ||
13 | whether we're looking at the host or guest CPU architecture will | ||
14 | come in handy to implement upcoming changes. | ||
15 | |||
16 | A couple of entries are dropped in the process: BePC and Power | ||
17 | Macintosh. I'm quite certain neither of those have ever been | ||
18 | reported as CPU architectures by Linux. I believe many more of | ||
19 | the entries that are carried forward could be dropped as well, | ||
20 | but I don't have the same level of confidence there so I | ||
21 | decided to play it safe just in case. | ||
22 | |||
23 | Signed-off-by: Andrea Bolognani <abologna@redhat.com> | ||
24 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
25 | Reviewed-by: Laurent Vivier <laurent@vivier.eu> | ||
26 | Message-ID: <20250127182924.103510-3-abologna@redhat.com> | ||
27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
28 | --- | ||
29 | scripts/qemu-binfmt-conf.sh | 44 +++++++++++++++++++++---------------- | ||
30 | 1 file changed, 25 insertions(+), 19 deletions(-) | ||
31 | |||
32 | diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh | ||
33 | index XXXXXXX..XXXXXXX 100755 | ||
34 | --- a/scripts/qemu-binfmt-conf.sh | ||
35 | +++ b/scripts/qemu-binfmt-conf.sh | ||
36 | @@ -XXX,XX +XXX,XX @@ loongarch64_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x | ||
37 | loongarch64_mask='\xff\xff\xff\xff\xff\xff\xff\xfc\x00\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' | ||
38 | loongarch64_family=loongarch | ||
39 | |||
40 | -qemu_get_family() { | ||
41 | - cpu=${HOST_ARCH:-$(uname -m)} | ||
42 | +# Converts the name of a host CPU architecture to the corresponding QEMU | ||
43 | +# target. | ||
44 | +# | ||
45 | +# FIXME: This can probably be simplified a lot by dropping most entries. | ||
46 | +# Remember that the script is only used on Linux, so we only need to | ||
47 | +# handle the strings Linux uses to report the host CPU architecture. | ||
48 | +qemu_normalize() { | ||
49 | + cpu="$1" | ||
50 | case "$cpu" in | ||
51 | - amd64|i386|i486|i586|i686|i86pc|BePC|x86_64) | ||
52 | + i[3-6]86) | ||
53 | echo "i386" | ||
54 | ;; | ||
55 | - mips*) | ||
56 | - echo "mips" | ||
57 | + amd64) | ||
58 | + echo "x86_64" | ||
59 | ;; | ||
60 | - "Power Macintosh"|ppc64|powerpc|ppc) | ||
61 | + powerpc) | ||
62 | echo "ppc" | ||
63 | ;; | ||
64 | - ppc64el|ppc64le) | ||
65 | - echo "ppcle" | ||
66 | + ppc64el) | ||
67 | + echo "ppc64le" | ||
68 | ;; | ||
69 | - arm|armel|armhf|arm64|armv[4-9]*l|aarch64) | ||
70 | + armel|armhf|armv[4-9]*l) | ||
71 | echo "arm" | ||
72 | ;; | ||
73 | - armeb|armv[4-9]*b|aarch64_be) | ||
74 | + armv[4-9]*b) | ||
75 | echo "armeb" | ||
76 | ;; | ||
77 | - sparc*) | ||
78 | - echo "sparc" | ||
79 | - ;; | ||
80 | - riscv*) | ||
81 | - echo "riscv" | ||
82 | - ;; | ||
83 | - loongarch*) | ||
84 | - echo "loongarch" | ||
85 | + arm64) | ||
86 | + echo "aarch64" | ||
87 | ;; | ||
88 | *) | ||
89 | echo "$cpu" | ||
90 | @@ -XXX,XX +XXX,XX @@ EOF | ||
91 | |||
92 | qemu_set_binfmts() { | ||
93 | # probe cpu type | ||
94 | - host_family=$(qemu_get_family) | ||
95 | + host_cpu=$(qemu_normalize ${HOST_ARCH:-$(uname -m)}) | ||
96 | + host_family=$(eval echo \$${host_cpu}_family) | ||
97 | + | ||
98 | + if [ "$host_family" = "" ] ; then | ||
99 | + echo "INTERNAL ERROR: unknown host cpu $host_cpu" 1>&2 | ||
100 | + exit 1 | ||
101 | + fi | ||
102 | |||
103 | # register the interpreter for each cpu except for the native one | ||
104 | |||
105 | -- | ||
106 | 2.48.1 | diff view generated by jsdifflib |
1 | From: Rajnesh Kanwal <rkanwal@rivosinc.com> | 1 | This patch removes the insn32-64.decode decode file and consolidates the |
---|---|---|---|
2 | instructions into the general RISC-V insn32.decode decode tree. | ||
2 | 3 | ||
3 | CTR extension adds a new instruction sctrclr to quickly | 4 | This means that all of the instructions are avaliable in both the 32-bit |
4 | clear the recorded entries buffer. | 5 | and 64-bit builds. This also means that we run a check to ensure we are |
6 | running a 64-bit softmmu before we execute the 64-bit only instructions. | ||
7 | This allows us to include the 32-bit instructions in the 64-bit build, | ||
8 | while also ensuring that 32-bit only software can not execute the | ||
9 | instructions. | ||
5 | 10 | ||
6 | Signed-off-by: Rajnesh Kanwal <rkanwal@rivosinc.com> | ||
7 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Message-ID: <20250205-b4-ctr_upstream_v6-v6-5-439d8e06c8ef@rivosinc.com> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
13 | Message-id: db709360e2be47d2f9c6483ab973fe4791aefa77.1619234854.git.alistair.francis@wdc.com | ||
10 | --- | 14 | --- |
11 | target/riscv/cpu.h | 1 + | 15 | target/riscv/helper.h | 18 +++-- |
12 | target/riscv/helper.h | 1 + | 16 | target/riscv/insn32-64.decode | 88 ------------------------- |
13 | target/riscv/insn32.decode | 1 + | 17 | target/riscv/insn32.decode | 67 ++++++++++++++++++- |
14 | target/riscv/cpu_helper.c | 7 +++++ | 18 | target/riscv/fpu_helper.c | 16 ++--- |
15 | target/riscv/op_helper.c | 29 +++++++++++++++++++ | 19 | target/riscv/translate.c | 9 ++- |
16 | .../riscv/insn_trans/trans_privileged.c.inc | 11 +++++++ | 20 | target/riscv/vector_helper.c | 4 -- |
17 | 6 files changed, 50 insertions(+) | 21 | target/riscv/insn_trans/trans_rva.c.inc | 14 +++- |
22 | target/riscv/insn_trans/trans_rvd.c.inc | 17 ++++- | ||
23 | target/riscv/insn_trans/trans_rvf.c.inc | 6 +- | ||
24 | target/riscv/insn_trans/trans_rvh.c.inc | 8 ++- | ||
25 | target/riscv/insn_trans/trans_rvi.c.inc | 16 +++-- | ||
26 | target/riscv/insn_trans/trans_rvm.c.inc | 12 +++- | ||
27 | target/riscv/insn_trans/trans_rvv.c.inc | 39 +++++------ | ||
28 | target/riscv/meson.build | 2 +- | ||
29 | 14 files changed, 166 insertions(+), 150 deletions(-) | ||
30 | delete mode 100644 target/riscv/insn32-64.decode | ||
18 | 31 | ||
19 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/target/riscv/cpu.h | ||
22 | +++ b/target/riscv/cpu.h | ||
23 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv, bool virt_en); | ||
24 | |||
25 | void riscv_ctr_add_entry(CPURISCVState *env, target_long src, target_long dst, | ||
26 | enum CTRType type, target_ulong prev_priv, bool prev_virt); | ||
27 | +void riscv_ctr_clear(CPURISCVState *env); | ||
28 | |||
29 | void riscv_translate_init(void); | ||
30 | void riscv_translate_code(CPUState *cs, TranslationBlock *tb, | ||
31 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h | 32 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h |
32 | index XXXXXXX..XXXXXXX 100644 | 33 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/target/riscv/helper.h | 34 | --- a/target/riscv/helper.h |
34 | +++ b/target/riscv/helper.h | 35 | +++ b/target/riscv/helper.h |
35 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_6(csrrw_i128, tl, env, int, tl, tl, tl, tl) | 36 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(flt_s, TCG_CALL_NO_RWG, tl, env, i64, i64) |
36 | DEF_HELPER_1(sret, tl, env) | 37 | DEF_HELPER_FLAGS_3(feq_s, TCG_CALL_NO_RWG, tl, env, i64, i64) |
37 | DEF_HELPER_1(mret, tl, env) | 38 | DEF_HELPER_FLAGS_2(fcvt_w_s, TCG_CALL_NO_RWG, tl, env, i64) |
38 | DEF_HELPER_1(mnret, tl, env) | 39 | DEF_HELPER_FLAGS_2(fcvt_wu_s, TCG_CALL_NO_RWG, tl, env, i64) |
39 | +DEF_HELPER_1(ctr_clear, void, env) | 40 | -DEF_HELPER_FLAGS_2(fcvt_l_s, TCG_CALL_NO_RWG, i64, env, i64) |
40 | DEF_HELPER_1(wfi, void, env) | 41 | -DEF_HELPER_FLAGS_2(fcvt_lu_s, TCG_CALL_NO_RWG, i64, env, i64) |
41 | DEF_HELPER_1(wrs_nto, void, env) | 42 | +DEF_HELPER_FLAGS_2(fcvt_l_s, TCG_CALL_NO_RWG, tl, env, i64) |
42 | DEF_HELPER_1(tlb_flush, void, env) | 43 | +DEF_HELPER_FLAGS_2(fcvt_lu_s, TCG_CALL_NO_RWG, tl, env, i64) |
44 | DEF_HELPER_FLAGS_2(fcvt_s_w, TCG_CALL_NO_RWG, i64, env, tl) | ||
45 | DEF_HELPER_FLAGS_2(fcvt_s_wu, TCG_CALL_NO_RWG, i64, env, tl) | ||
46 | -DEF_HELPER_FLAGS_2(fcvt_s_l, TCG_CALL_NO_RWG, i64, env, i64) | ||
47 | -DEF_HELPER_FLAGS_2(fcvt_s_lu, TCG_CALL_NO_RWG, i64, env, i64) | ||
48 | +DEF_HELPER_FLAGS_2(fcvt_s_l, TCG_CALL_NO_RWG, i64, env, tl) | ||
49 | +DEF_HELPER_FLAGS_2(fcvt_s_lu, TCG_CALL_NO_RWG, i64, env, tl) | ||
50 | DEF_HELPER_FLAGS_1(fclass_s, TCG_CALL_NO_RWG_SE, tl, i64) | ||
51 | |||
52 | /* Floating Point - Double Precision */ | ||
53 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(flt_d, TCG_CALL_NO_RWG, tl, env, i64, i64) | ||
54 | DEF_HELPER_FLAGS_3(feq_d, TCG_CALL_NO_RWG, tl, env, i64, i64) | ||
55 | DEF_HELPER_FLAGS_2(fcvt_w_d, TCG_CALL_NO_RWG, tl, env, i64) | ||
56 | DEF_HELPER_FLAGS_2(fcvt_wu_d, TCG_CALL_NO_RWG, tl, env, i64) | ||
57 | -DEF_HELPER_FLAGS_2(fcvt_l_d, TCG_CALL_NO_RWG, i64, env, i64) | ||
58 | -DEF_HELPER_FLAGS_2(fcvt_lu_d, TCG_CALL_NO_RWG, i64, env, i64) | ||
59 | +DEF_HELPER_FLAGS_2(fcvt_l_d, TCG_CALL_NO_RWG, tl, env, i64) | ||
60 | +DEF_HELPER_FLAGS_2(fcvt_lu_d, TCG_CALL_NO_RWG, tl, env, i64) | ||
61 | DEF_HELPER_FLAGS_2(fcvt_d_w, TCG_CALL_NO_RWG, i64, env, tl) | ||
62 | DEF_HELPER_FLAGS_2(fcvt_d_wu, TCG_CALL_NO_RWG, i64, env, tl) | ||
63 | -DEF_HELPER_FLAGS_2(fcvt_d_l, TCG_CALL_NO_RWG, i64, env, i64) | ||
64 | -DEF_HELPER_FLAGS_2(fcvt_d_lu, TCG_CALL_NO_RWG, i64, env, i64) | ||
65 | +DEF_HELPER_FLAGS_2(fcvt_d_l, TCG_CALL_NO_RWG, i64, env, tl) | ||
66 | +DEF_HELPER_FLAGS_2(fcvt_d_lu, TCG_CALL_NO_RWG, i64, env, tl) | ||
67 | DEF_HELPER_FLAGS_1(fclass_d, TCG_CALL_NO_RWG_SE, tl, i64) | ||
68 | |||
69 | /* Special functions */ | ||
70 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_5(vlhuff_v_w, void, ptr, ptr, tl, env, i32) | ||
71 | DEF_HELPER_5(vlhuff_v_d, void, ptr, ptr, tl, env, i32) | ||
72 | DEF_HELPER_5(vlwuff_v_w, void, ptr, ptr, tl, env, i32) | ||
73 | DEF_HELPER_5(vlwuff_v_d, void, ptr, ptr, tl, env, i32) | ||
74 | -#ifdef TARGET_RISCV64 | ||
75 | DEF_HELPER_6(vamoswapw_v_d, void, ptr, ptr, tl, ptr, env, i32) | ||
76 | DEF_HELPER_6(vamoswapd_v_d, void, ptr, ptr, tl, ptr, env, i32) | ||
77 | DEF_HELPER_6(vamoaddw_v_d, void, ptr, ptr, tl, ptr, env, i32) | ||
78 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_6(vamominuw_v_d, void, ptr, ptr, tl, ptr, env, i32) | ||
79 | DEF_HELPER_6(vamominud_v_d, void, ptr, ptr, tl, ptr, env, i32) | ||
80 | DEF_HELPER_6(vamomaxuw_v_d, void, ptr, ptr, tl, ptr, env, i32) | ||
81 | DEF_HELPER_6(vamomaxud_v_d, void, ptr, ptr, tl, ptr, env, i32) | ||
82 | -#endif | ||
83 | DEF_HELPER_6(vamoswapw_v_w, void, ptr, ptr, tl, ptr, env, i32) | ||
84 | DEF_HELPER_6(vamoaddw_v_w, void, ptr, ptr, tl, ptr, env, i32) | ||
85 | DEF_HELPER_6(vamoxorw_v_w, void, ptr, ptr, tl, ptr, env, i32) | ||
86 | diff --git a/target/riscv/insn32-64.decode b/target/riscv/insn32-64.decode | ||
87 | deleted file mode 100644 | ||
88 | index XXXXXXX..XXXXXXX | ||
89 | --- a/target/riscv/insn32-64.decode | ||
90 | +++ /dev/null | ||
91 | @@ -XXX,XX +XXX,XX @@ | ||
92 | -# | ||
93 | -# RISC-V translation routines for the RV Instruction Set. | ||
94 | -# | ||
95 | -# Copyright (c) 2018 Peer Adelt, peer.adelt@hni.uni-paderborn.de | ||
96 | -# Bastian Koppelmann, kbastian@mail.uni-paderborn.de | ||
97 | -# | ||
98 | -# This program is free software; you can redistribute it and/or modify it | ||
99 | -# under the terms and conditions of the GNU General Public License, | ||
100 | -# version 2 or later, as published by the Free Software Foundation. | ||
101 | -# | ||
102 | -# This program is distributed in the hope it will be useful, but WITHOUT | ||
103 | -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
104 | -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
105 | -# more details. | ||
106 | -# | ||
107 | -# You should have received a copy of the GNU General Public License along with | ||
108 | -# this program. If not, see <http://www.gnu.org/licenses/>. | ||
109 | - | ||
110 | -# This is concatenated with insn32.decode for risc64 targets. | ||
111 | -# Most of the fields and formats are there. | ||
112 | - | ||
113 | -%sh5 20:5 | ||
114 | - | ||
115 | -@sh5 ....... ..... ..... ... ..... ....... &shift shamt=%sh5 %rs1 %rd | ||
116 | - | ||
117 | -# *** RV64I Base Instruction Set (in addition to RV32I) *** | ||
118 | -lwu ............ ..... 110 ..... 0000011 @i | ||
119 | -ld ............ ..... 011 ..... 0000011 @i | ||
120 | -sd ....... ..... ..... 011 ..... 0100011 @s | ||
121 | -addiw ............ ..... 000 ..... 0011011 @i | ||
122 | -slliw 0000000 ..... ..... 001 ..... 0011011 @sh5 | ||
123 | -srliw 0000000 ..... ..... 101 ..... 0011011 @sh5 | ||
124 | -sraiw 0100000 ..... ..... 101 ..... 0011011 @sh5 | ||
125 | -addw 0000000 ..... ..... 000 ..... 0111011 @r | ||
126 | -subw 0100000 ..... ..... 000 ..... 0111011 @r | ||
127 | -sllw 0000000 ..... ..... 001 ..... 0111011 @r | ||
128 | -srlw 0000000 ..... ..... 101 ..... 0111011 @r | ||
129 | -sraw 0100000 ..... ..... 101 ..... 0111011 @r | ||
130 | - | ||
131 | -# *** RV64M Standard Extension (in addition to RV32M) *** | ||
132 | -mulw 0000001 ..... ..... 000 ..... 0111011 @r | ||
133 | -divw 0000001 ..... ..... 100 ..... 0111011 @r | ||
134 | -divuw 0000001 ..... ..... 101 ..... 0111011 @r | ||
135 | -remw 0000001 ..... ..... 110 ..... 0111011 @r | ||
136 | -remuw 0000001 ..... ..... 111 ..... 0111011 @r | ||
137 | - | ||
138 | -# *** RV64A Standard Extension (in addition to RV32A) *** | ||
139 | -lr_d 00010 . . 00000 ..... 011 ..... 0101111 @atom_ld | ||
140 | -sc_d 00011 . . ..... ..... 011 ..... 0101111 @atom_st | ||
141 | -amoswap_d 00001 . . ..... ..... 011 ..... 0101111 @atom_st | ||
142 | -amoadd_d 00000 . . ..... ..... 011 ..... 0101111 @atom_st | ||
143 | -amoxor_d 00100 . . ..... ..... 011 ..... 0101111 @atom_st | ||
144 | -amoand_d 01100 . . ..... ..... 011 ..... 0101111 @atom_st | ||
145 | -amoor_d 01000 . . ..... ..... 011 ..... 0101111 @atom_st | ||
146 | -amomin_d 10000 . . ..... ..... 011 ..... 0101111 @atom_st | ||
147 | -amomax_d 10100 . . ..... ..... 011 ..... 0101111 @atom_st | ||
148 | -amominu_d 11000 . . ..... ..... 011 ..... 0101111 @atom_st | ||
149 | -amomaxu_d 11100 . . ..... ..... 011 ..... 0101111 @atom_st | ||
150 | - | ||
151 | -#*** Vector AMO operations (in addition to Zvamo) *** | ||
152 | -vamoswapd_v 00001 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
153 | -vamoaddd_v 00000 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
154 | -vamoxord_v 00100 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
155 | -vamoandd_v 01100 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
156 | -vamoord_v 01000 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
157 | -vamomind_v 10000 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
158 | -vamomaxd_v 10100 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
159 | -vamominud_v 11000 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
160 | -vamomaxud_v 11100 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
161 | - | ||
162 | -# *** RV64F Standard Extension (in addition to RV32F) *** | ||
163 | -fcvt_l_s 1100000 00010 ..... ... ..... 1010011 @r2_rm | ||
164 | -fcvt_lu_s 1100000 00011 ..... ... ..... 1010011 @r2_rm | ||
165 | -fcvt_s_l 1101000 00010 ..... ... ..... 1010011 @r2_rm | ||
166 | -fcvt_s_lu 1101000 00011 ..... ... ..... 1010011 @r2_rm | ||
167 | - | ||
168 | -# *** RV64D Standard Extension (in addition to RV32D) *** | ||
169 | -fcvt_l_d 1100001 00010 ..... ... ..... 1010011 @r2_rm | ||
170 | -fcvt_lu_d 1100001 00011 ..... ... ..... 1010011 @r2_rm | ||
171 | -fmv_x_d 1110001 00000 ..... 000 ..... 1010011 @r2 | ||
172 | -fcvt_d_l 1101001 00010 ..... ... ..... 1010011 @r2_rm | ||
173 | -fcvt_d_lu 1101001 00011 ..... ... ..... 1010011 @r2_rm | ||
174 | -fmv_d_x 1111001 00000 ..... 000 ..... 1010011 @r2 | ||
175 | - | ||
176 | -# *** RV32H Base Instruction Set *** | ||
177 | -hlv_wu 0110100 00001 ..... 100 ..... 1110011 @r2 | ||
178 | -hlv_d 0110110 00000 ..... 100 ..... 1110011 @r2 | ||
179 | -hsv_d 0110111 ..... ..... 100 00000 1110011 @r2_s | ||
43 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | 180 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode |
44 | index XXXXXXX..XXXXXXX 100644 | 181 | index XXXXXXX..XXXXXXX 100644 |
45 | --- a/target/riscv/insn32.decode | 182 | --- a/target/riscv/insn32.decode |
46 | +++ b/target/riscv/insn32.decode | 183 | +++ b/target/riscv/insn32.decode |
47 | @@ -XXX,XX +XXX,XX @@ | 184 | @@ -XXX,XX +XXX,XX @@ |
185 | %rs2 20:5 | ||
186 | %rs1 15:5 | ||
187 | %rd 7:5 | ||
188 | +%sh5 20:5 | ||
189 | |||
190 | %sh10 20:10 | ||
191 | %csr 20:12 | ||
192 | @@ -XXX,XX +XXX,XX @@ | ||
193 | @sfence_vma ....... ..... ..... ... ..... ....... %rs2 %rs1 | ||
194 | @sfence_vm ....... ..... ..... ... ..... ....... %rs1 | ||
195 | |||
196 | +# Formats 64: | ||
197 | +@sh5 ....... ..... ..... ... ..... ....... &shift shamt=%sh5 %rs1 %rd | ||
198 | |||
48 | # *** Privileged Instructions *** | 199 | # *** Privileged Instructions *** |
49 | ecall 000000000000 00000 000 00000 1110011 | 200 | ecall 000000000000 00000 000 00000 1110011 |
50 | ebreak 000000000001 00000 000 00000 1110011 | 201 | @@ -XXX,XX +XXX,XX @@ csrrwi ............ ..... 101 ..... 1110011 @csr |
51 | +sctrclr 000100000100 00000 000 00000 1110011 | 202 | csrrsi ............ ..... 110 ..... 1110011 @csr |
52 | uret 0000000 00010 00000 000 00000 1110011 | 203 | csrrci ............ ..... 111 ..... 1110011 @csr |
53 | sret 0001000 00010 00000 000 00000 1110011 | 204 | |
54 | mret 0011000 00010 00000 000 00000 1110011 | 205 | +# *** RV64I Base Instruction Set (in addition to RV32I) *** |
55 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 206 | +lwu ............ ..... 110 ..... 0000011 @i |
56 | index XXXXXXX..XXXXXXX 100644 | 207 | +ld ............ ..... 011 ..... 0000011 @i |
57 | --- a/target/riscv/cpu_helper.c | 208 | +sd ....... ..... ..... 011 ..... 0100011 @s |
58 | +++ b/target/riscv/cpu_helper.c | 209 | +addiw ............ ..... 000 ..... 0011011 @i |
59 | @@ -XXX,XX +XXX,XX @@ static void riscv_ctr_freeze(CPURISCVState *env, uint64_t freeze_mask, | 210 | +slliw 0000000 ..... ..... 001 ..... 0011011 @sh5 |
60 | } | 211 | +srliw 0000000 ..... ..... 101 ..... 0011011 @sh5 |
61 | } | 212 | +sraiw 0100000 ..... ..... 101 ..... 0011011 @sh5 |
62 | 213 | +addw 0000000 ..... ..... 000 ..... 0111011 @r | |
63 | +void riscv_ctr_clear(CPURISCVState *env) | 214 | +subw 0100000 ..... ..... 000 ..... 0111011 @r |
215 | +sllw 0000000 ..... ..... 001 ..... 0111011 @r | ||
216 | +srlw 0000000 ..... ..... 101 ..... 0111011 @r | ||
217 | +sraw 0100000 ..... ..... 101 ..... 0111011 @r | ||
218 | + | ||
219 | # *** RV32M Standard Extension *** | ||
220 | mul 0000001 ..... ..... 000 ..... 0110011 @r | ||
221 | mulh 0000001 ..... ..... 001 ..... 0110011 @r | ||
222 | @@ -XXX,XX +XXX,XX @@ divu 0000001 ..... ..... 101 ..... 0110011 @r | ||
223 | rem 0000001 ..... ..... 110 ..... 0110011 @r | ||
224 | remu 0000001 ..... ..... 111 ..... 0110011 @r | ||
225 | |||
226 | +# *** RV64M Standard Extension (in addition to RV32M) *** | ||
227 | +mulw 0000001 ..... ..... 000 ..... 0111011 @r | ||
228 | +divw 0000001 ..... ..... 100 ..... 0111011 @r | ||
229 | +divuw 0000001 ..... ..... 101 ..... 0111011 @r | ||
230 | +remw 0000001 ..... ..... 110 ..... 0111011 @r | ||
231 | +remuw 0000001 ..... ..... 111 ..... 0111011 @r | ||
232 | + | ||
233 | # *** RV32A Standard Extension *** | ||
234 | lr_w 00010 . . 00000 ..... 010 ..... 0101111 @atom_ld | ||
235 | sc_w 00011 . . ..... ..... 010 ..... 0101111 @atom_st | ||
236 | @@ -XXX,XX +XXX,XX @@ amomax_w 10100 . . ..... ..... 010 ..... 0101111 @atom_st | ||
237 | amominu_w 11000 . . ..... ..... 010 ..... 0101111 @atom_st | ||
238 | amomaxu_w 11100 . . ..... ..... 010 ..... 0101111 @atom_st | ||
239 | |||
240 | +# *** RV64A Standard Extension (in addition to RV32A) *** | ||
241 | +lr_d 00010 . . 00000 ..... 011 ..... 0101111 @atom_ld | ||
242 | +sc_d 00011 . . ..... ..... 011 ..... 0101111 @atom_st | ||
243 | +amoswap_d 00001 . . ..... ..... 011 ..... 0101111 @atom_st | ||
244 | +amoadd_d 00000 . . ..... ..... 011 ..... 0101111 @atom_st | ||
245 | +amoxor_d 00100 . . ..... ..... 011 ..... 0101111 @atom_st | ||
246 | +amoand_d 01100 . . ..... ..... 011 ..... 0101111 @atom_st | ||
247 | +amoor_d 01000 . . ..... ..... 011 ..... 0101111 @atom_st | ||
248 | +amomin_d 10000 . . ..... ..... 011 ..... 0101111 @atom_st | ||
249 | +amomax_d 10100 . . ..... ..... 011 ..... 0101111 @atom_st | ||
250 | +amominu_d 11000 . . ..... ..... 011 ..... 0101111 @atom_st | ||
251 | +amomaxu_d 11100 . . ..... ..... 011 ..... 0101111 @atom_st | ||
252 | + | ||
253 | # *** RV32F Standard Extension *** | ||
254 | flw ............ ..... 010 ..... 0000111 @i | ||
255 | fsw ....... ..... ..... 010 ..... 0100111 @s | ||
256 | @@ -XXX,XX +XXX,XX @@ fcvt_s_w 1101000 00000 ..... ... ..... 1010011 @r2_rm | ||
257 | fcvt_s_wu 1101000 00001 ..... ... ..... 1010011 @r2_rm | ||
258 | fmv_w_x 1111000 00000 ..... 000 ..... 1010011 @r2 | ||
259 | |||
260 | +# *** RV64F Standard Extension (in addition to RV32F) *** | ||
261 | +fcvt_l_s 1100000 00010 ..... ... ..... 1010011 @r2_rm | ||
262 | +fcvt_lu_s 1100000 00011 ..... ... ..... 1010011 @r2_rm | ||
263 | +fcvt_s_l 1101000 00010 ..... ... ..... 1010011 @r2_rm | ||
264 | +fcvt_s_lu 1101000 00011 ..... ... ..... 1010011 @r2_rm | ||
265 | + | ||
266 | # *** RV32D Standard Extension *** | ||
267 | fld ............ ..... 011 ..... 0000111 @i | ||
268 | fsd ....... ..... ..... 011 ..... 0100111 @s | ||
269 | @@ -XXX,XX +XXX,XX @@ fcvt_wu_d 1100001 00001 ..... ... ..... 1010011 @r2_rm | ||
270 | fcvt_d_w 1101001 00000 ..... ... ..... 1010011 @r2_rm | ||
271 | fcvt_d_wu 1101001 00001 ..... ... ..... 1010011 @r2_rm | ||
272 | |||
273 | +# *** RV64D Standard Extension (in addition to RV32D) *** | ||
274 | +fcvt_l_d 1100001 00010 ..... ... ..... 1010011 @r2_rm | ||
275 | +fcvt_lu_d 1100001 00011 ..... ... ..... 1010011 @r2_rm | ||
276 | +fmv_x_d 1110001 00000 ..... 000 ..... 1010011 @r2 | ||
277 | +fcvt_d_l 1101001 00010 ..... ... ..... 1010011 @r2_rm | ||
278 | +fcvt_d_lu 1101001 00011 ..... ... ..... 1010011 @r2_rm | ||
279 | +fmv_d_x 1111001 00000 ..... 000 ..... 1010011 @r2 | ||
280 | + | ||
281 | # *** RV32H Base Instruction Set *** | ||
282 | hlv_b 0110000 00000 ..... 100 ..... 1110011 @r2 | ||
283 | hlv_bu 0110000 00001 ..... 100 ..... 1110011 @r2 | ||
284 | @@ -XXX,XX +XXX,XX @@ hsv_w 0110101 ..... ..... 100 00000 1110011 @r2_s | ||
285 | hfence_gvma 0110001 ..... ..... 000 00000 1110011 @hfence_gvma | ||
286 | hfence_vvma 0010001 ..... ..... 000 00000 1110011 @hfence_vvma | ||
287 | |||
288 | -# *** RV32V Extension *** | ||
289 | +# *** RV32H Base Instruction Set *** | ||
290 | +hlv_wu 0110100 00001 ..... 100 ..... 1110011 @r2 | ||
291 | +hlv_d 0110110 00000 ..... 100 ..... 1110011 @r2 | ||
292 | +hsv_d 0110111 ..... ..... 100 00000 1110011 @r2_s | ||
293 | |||
294 | # *** Vector loads and stores are encoded within LOADFP/STORE-FP *** | ||
295 | vlb_v ... 100 . 00000 ..... 000 ..... 0000111 @r2_nfvm | ||
296 | @@ -XXX,XX +XXX,XX @@ vcompress_vm 010111 - ..... ..... 010 ..... 1010111 @r | ||
297 | |||
298 | vsetvli 0 ........... ..... 111 ..... 1010111 @r2_zimm | ||
299 | vsetvl 1000000 ..... ..... 111 ..... 1010111 @r | ||
300 | + | ||
301 | +#*** Vector AMO operations (in addition to Zvamo) *** | ||
302 | +vamoswapd_v 00001 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
303 | +vamoaddd_v 00000 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
304 | +vamoxord_v 00100 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
305 | +vamoandd_v 01100 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
306 | +vamoord_v 01000 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
307 | +vamomind_v 10000 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
308 | +vamomaxd_v 10100 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
309 | +vamominud_v 11000 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
310 | +vamomaxud_v 11100 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
311 | diff --git a/target/riscv/fpu_helper.c b/target/riscv/fpu_helper.c | ||
312 | index XXXXXXX..XXXXXXX 100644 | ||
313 | --- a/target/riscv/fpu_helper.c | ||
314 | +++ b/target/riscv/fpu_helper.c | ||
315 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_fcvt_wu_s(CPURISCVState *env, uint64_t rs1) | ||
316 | return (int32_t)float32_to_uint32(frs1, &env->fp_status); | ||
317 | } | ||
318 | |||
319 | -uint64_t helper_fcvt_l_s(CPURISCVState *env, uint64_t rs1) | ||
320 | +target_ulong helper_fcvt_l_s(CPURISCVState *env, uint64_t rs1) | ||
321 | { | ||
322 | float32 frs1 = check_nanbox_s(rs1); | ||
323 | return float32_to_int64(frs1, &env->fp_status); | ||
324 | } | ||
325 | |||
326 | -uint64_t helper_fcvt_lu_s(CPURISCVState *env, uint64_t rs1) | ||
327 | +target_ulong helper_fcvt_lu_s(CPURISCVState *env, uint64_t rs1) | ||
328 | { | ||
329 | float32 frs1 = check_nanbox_s(rs1); | ||
330 | return float32_to_uint64(frs1, &env->fp_status); | ||
331 | @@ -XXX,XX +XXX,XX @@ uint64_t helper_fcvt_s_wu(CPURISCVState *env, target_ulong rs1) | ||
332 | return nanbox_s(uint32_to_float32((uint32_t)rs1, &env->fp_status)); | ||
333 | } | ||
334 | |||
335 | -uint64_t helper_fcvt_s_l(CPURISCVState *env, uint64_t rs1) | ||
336 | +uint64_t helper_fcvt_s_l(CPURISCVState *env, target_ulong rs1) | ||
337 | { | ||
338 | return nanbox_s(int64_to_float32(rs1, &env->fp_status)); | ||
339 | } | ||
340 | |||
341 | -uint64_t helper_fcvt_s_lu(CPURISCVState *env, uint64_t rs1) | ||
342 | +uint64_t helper_fcvt_s_lu(CPURISCVState *env, target_ulong rs1) | ||
343 | { | ||
344 | return nanbox_s(uint64_to_float32(rs1, &env->fp_status)); | ||
345 | } | ||
346 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_fcvt_wu_d(CPURISCVState *env, uint64_t frs1) | ||
347 | return (int32_t)float64_to_uint32(frs1, &env->fp_status); | ||
348 | } | ||
349 | |||
350 | -uint64_t helper_fcvt_l_d(CPURISCVState *env, uint64_t frs1) | ||
351 | +target_ulong helper_fcvt_l_d(CPURISCVState *env, uint64_t frs1) | ||
352 | { | ||
353 | return float64_to_int64(frs1, &env->fp_status); | ||
354 | } | ||
355 | |||
356 | -uint64_t helper_fcvt_lu_d(CPURISCVState *env, uint64_t frs1) | ||
357 | +target_ulong helper_fcvt_lu_d(CPURISCVState *env, uint64_t frs1) | ||
358 | { | ||
359 | return float64_to_uint64(frs1, &env->fp_status); | ||
360 | } | ||
361 | @@ -XXX,XX +XXX,XX @@ uint64_t helper_fcvt_d_wu(CPURISCVState *env, target_ulong rs1) | ||
362 | return uint32_to_float64((uint32_t)rs1, &env->fp_status); | ||
363 | } | ||
364 | |||
365 | -uint64_t helper_fcvt_d_l(CPURISCVState *env, uint64_t rs1) | ||
366 | +uint64_t helper_fcvt_d_l(CPURISCVState *env, target_ulong rs1) | ||
367 | { | ||
368 | return int64_to_float64(rs1, &env->fp_status); | ||
369 | } | ||
370 | |||
371 | -uint64_t helper_fcvt_d_lu(CPURISCVState *env, uint64_t rs1) | ||
372 | +uint64_t helper_fcvt_d_lu(CPURISCVState *env, target_ulong rs1) | ||
373 | { | ||
374 | return uint64_to_float64(rs1, &env->fp_status); | ||
375 | } | ||
376 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | ||
377 | index XXXXXXX..XXXXXXX 100644 | ||
378 | --- a/target/riscv/translate.c | ||
379 | +++ b/target/riscv/translate.c | ||
380 | @@ -XXX,XX +XXX,XX @@ EX_SH(12) | ||
381 | } \ | ||
382 | } while (0) | ||
383 | |||
384 | +#define REQUIRE_64BIT(ctx) do { \ | ||
385 | + if (is_32bit(ctx)) { \ | ||
386 | + return false; \ | ||
387 | + } \ | ||
388 | +} while (0) | ||
389 | + | ||
390 | static int ex_rvc_register(DisasContext *ctx, int reg) | ||
391 | { | ||
392 | return 8 + reg; | ||
393 | @@ -XXX,XX +XXX,XX @@ static bool gen_arith_imm_tl(DisasContext *ctx, arg_i *a, | ||
394 | return true; | ||
395 | } | ||
396 | |||
397 | -#ifdef TARGET_RISCV64 | ||
398 | static void gen_addw(TCGv ret, TCGv arg1, TCGv arg2) | ||
399 | { | ||
400 | tcg_gen_add_tl(ret, arg1, arg2); | ||
401 | @@ -XXX,XX +XXX,XX @@ static bool gen_arith_div_uw(DisasContext *ctx, arg_r *a, | ||
402 | return true; | ||
403 | } | ||
404 | |||
405 | -#endif | ||
406 | - | ||
407 | static bool gen_arith(DisasContext *ctx, arg_r *a, | ||
408 | void(*func)(TCGv, TCGv, TCGv)) | ||
409 | { | ||
410 | diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c | ||
411 | index XXXXXXX..XXXXXXX 100644 | ||
412 | --- a/target/riscv/vector_helper.c | ||
413 | +++ b/target/riscv/vector_helper.c | ||
414 | @@ -XXX,XX +XXX,XX @@ GEN_VEXT_AMO_NOATOMIC_OP(vamominw_v_w, 32, 32, H4, DO_MIN, l) | ||
415 | GEN_VEXT_AMO_NOATOMIC_OP(vamomaxw_v_w, 32, 32, H4, DO_MAX, l) | ||
416 | GEN_VEXT_AMO_NOATOMIC_OP(vamominuw_v_w, 32, 32, H4, DO_MINU, l) | ||
417 | GEN_VEXT_AMO_NOATOMIC_OP(vamomaxuw_v_w, 32, 32, H4, DO_MAXU, l) | ||
418 | -#ifdef TARGET_RISCV64 | ||
419 | GEN_VEXT_AMO_NOATOMIC_OP(vamoswapw_v_d, 64, 32, H8, DO_SWAP, l) | ||
420 | GEN_VEXT_AMO_NOATOMIC_OP(vamoswapd_v_d, 64, 64, H8, DO_SWAP, q) | ||
421 | GEN_VEXT_AMO_NOATOMIC_OP(vamoaddw_v_d, 64, 32, H8, DO_ADD, l) | ||
422 | @@ -XXX,XX +XXX,XX @@ GEN_VEXT_AMO_NOATOMIC_OP(vamominuw_v_d, 64, 32, H8, DO_MINU, l) | ||
423 | GEN_VEXT_AMO_NOATOMIC_OP(vamominud_v_d, 64, 64, H8, DO_MINU, q) | ||
424 | GEN_VEXT_AMO_NOATOMIC_OP(vamomaxuw_v_d, 64, 32, H8, DO_MAXU, l) | ||
425 | GEN_VEXT_AMO_NOATOMIC_OP(vamomaxud_v_d, 64, 64, H8, DO_MAXU, q) | ||
426 | -#endif | ||
427 | |||
428 | static inline void | ||
429 | vext_amo_noatomic(void *vs3, void *v0, target_ulong base, | ||
430 | @@ -XXX,XX +XXX,XX @@ void HELPER(NAME)(void *vs3, void *v0, target_ulong base, \ | ||
431 | GETPC()); \ | ||
432 | } | ||
433 | |||
434 | -#ifdef TARGET_RISCV64 | ||
435 | GEN_VEXT_AMO(vamoswapw_v_d, int32_t, int64_t, idx_d, clearq) | ||
436 | GEN_VEXT_AMO(vamoswapd_v_d, int64_t, int64_t, idx_d, clearq) | ||
437 | GEN_VEXT_AMO(vamoaddw_v_d, int32_t, int64_t, idx_d, clearq) | ||
438 | @@ -XXX,XX +XXX,XX @@ GEN_VEXT_AMO(vamominuw_v_d, uint32_t, uint64_t, idx_d, clearq) | ||
439 | GEN_VEXT_AMO(vamominud_v_d, uint64_t, uint64_t, idx_d, clearq) | ||
440 | GEN_VEXT_AMO(vamomaxuw_v_d, uint32_t, uint64_t, idx_d, clearq) | ||
441 | GEN_VEXT_AMO(vamomaxud_v_d, uint64_t, uint64_t, idx_d, clearq) | ||
442 | -#endif | ||
443 | GEN_VEXT_AMO(vamoswapw_v_w, int32_t, int32_t, idx_w, clearl) | ||
444 | GEN_VEXT_AMO(vamoaddw_v_w, int32_t, int32_t, idx_w, clearl) | ||
445 | GEN_VEXT_AMO(vamoxorw_v_w, int32_t, int32_t, idx_w, clearl) | ||
446 | diff --git a/target/riscv/insn_trans/trans_rva.c.inc b/target/riscv/insn_trans/trans_rva.c.inc | ||
447 | index XXXXXXX..XXXXXXX 100644 | ||
448 | --- a/target/riscv/insn_trans/trans_rva.c.inc | ||
449 | +++ b/target/riscv/insn_trans/trans_rva.c.inc | ||
450 | @@ -XXX,XX +XXX,XX @@ static bool trans_amomaxu_w(DisasContext *ctx, arg_amomaxu_w *a) | ||
451 | return gen_amo(ctx, a, &tcg_gen_atomic_fetch_umax_tl, (MO_ALIGN | MO_TESL)); | ||
452 | } | ||
453 | |||
454 | -#ifdef TARGET_RISCV64 | ||
455 | - | ||
456 | static bool trans_lr_d(DisasContext *ctx, arg_lr_d *a) | ||
457 | { | ||
458 | + REQUIRE_64BIT(ctx); | ||
459 | return gen_lr(ctx, a, MO_ALIGN | MO_TEQ); | ||
460 | } | ||
461 | |||
462 | static bool trans_sc_d(DisasContext *ctx, arg_sc_d *a) | ||
463 | { | ||
464 | + REQUIRE_64BIT(ctx); | ||
465 | return gen_sc(ctx, a, (MO_ALIGN | MO_TEQ)); | ||
466 | } | ||
467 | |||
468 | static bool trans_amoswap_d(DisasContext *ctx, arg_amoswap_d *a) | ||
469 | { | ||
470 | + REQUIRE_64BIT(ctx); | ||
471 | return gen_amo(ctx, a, &tcg_gen_atomic_xchg_tl, (MO_ALIGN | MO_TEQ)); | ||
472 | } | ||
473 | |||
474 | static bool trans_amoadd_d(DisasContext *ctx, arg_amoadd_d *a) | ||
475 | { | ||
476 | + REQUIRE_64BIT(ctx); | ||
477 | return gen_amo(ctx, a, &tcg_gen_atomic_fetch_add_tl, (MO_ALIGN | MO_TEQ)); | ||
478 | } | ||
479 | |||
480 | static bool trans_amoxor_d(DisasContext *ctx, arg_amoxor_d *a) | ||
481 | { | ||
482 | + REQUIRE_64BIT(ctx); | ||
483 | return gen_amo(ctx, a, &tcg_gen_atomic_fetch_xor_tl, (MO_ALIGN | MO_TEQ)); | ||
484 | } | ||
485 | |||
486 | static bool trans_amoand_d(DisasContext *ctx, arg_amoand_d *a) | ||
487 | { | ||
488 | + REQUIRE_64BIT(ctx); | ||
489 | return gen_amo(ctx, a, &tcg_gen_atomic_fetch_and_tl, (MO_ALIGN | MO_TEQ)); | ||
490 | } | ||
491 | |||
492 | static bool trans_amoor_d(DisasContext *ctx, arg_amoor_d *a) | ||
493 | { | ||
494 | + REQUIRE_64BIT(ctx); | ||
495 | return gen_amo(ctx, a, &tcg_gen_atomic_fetch_or_tl, (MO_ALIGN | MO_TEQ)); | ||
496 | } | ||
497 | |||
498 | static bool trans_amomin_d(DisasContext *ctx, arg_amomin_d *a) | ||
499 | { | ||
500 | + REQUIRE_64BIT(ctx); | ||
501 | return gen_amo(ctx, a, &tcg_gen_atomic_fetch_smin_tl, (MO_ALIGN | MO_TEQ)); | ||
502 | } | ||
503 | |||
504 | static bool trans_amomax_d(DisasContext *ctx, arg_amomax_d *a) | ||
505 | { | ||
506 | + REQUIRE_64BIT(ctx); | ||
507 | return gen_amo(ctx, a, &tcg_gen_atomic_fetch_smax_tl, (MO_ALIGN | MO_TEQ)); | ||
508 | } | ||
509 | |||
510 | static bool trans_amominu_d(DisasContext *ctx, arg_amominu_d *a) | ||
511 | { | ||
512 | + REQUIRE_64BIT(ctx); | ||
513 | return gen_amo(ctx, a, &tcg_gen_atomic_fetch_umin_tl, (MO_ALIGN | MO_TEQ)); | ||
514 | } | ||
515 | |||
516 | static bool trans_amomaxu_d(DisasContext *ctx, arg_amomaxu_d *a) | ||
517 | { | ||
518 | + REQUIRE_64BIT(ctx); | ||
519 | return gen_amo(ctx, a, &tcg_gen_atomic_fetch_umax_tl, (MO_ALIGN | MO_TEQ)); | ||
520 | } | ||
521 | -#endif | ||
522 | diff --git a/target/riscv/insn_trans/trans_rvd.c.inc b/target/riscv/insn_trans/trans_rvd.c.inc | ||
523 | index XXXXXXX..XXXXXXX 100644 | ||
524 | --- a/target/riscv/insn_trans/trans_rvd.c.inc | ||
525 | +++ b/target/riscv/insn_trans/trans_rvd.c.inc | ||
526 | @@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_d_wu(DisasContext *ctx, arg_fcvt_d_wu *a) | ||
527 | return true; | ||
528 | } | ||
529 | |||
530 | -#ifdef TARGET_RISCV64 | ||
531 | - | ||
532 | static bool trans_fcvt_l_d(DisasContext *ctx, arg_fcvt_l_d *a) | ||
533 | { | ||
534 | + REQUIRE_64BIT(ctx); | ||
535 | REQUIRE_FPU; | ||
536 | REQUIRE_EXT(ctx, RVD); | ||
537 | |||
538 | @@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_l_d(DisasContext *ctx, arg_fcvt_l_d *a) | ||
539 | |||
540 | static bool trans_fcvt_lu_d(DisasContext *ctx, arg_fcvt_lu_d *a) | ||
541 | { | ||
542 | + REQUIRE_64BIT(ctx); | ||
543 | REQUIRE_FPU; | ||
544 | REQUIRE_EXT(ctx, RVD); | ||
545 | |||
546 | @@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_lu_d(DisasContext *ctx, arg_fcvt_lu_d *a) | ||
547 | |||
548 | static bool trans_fmv_x_d(DisasContext *ctx, arg_fmv_x_d *a) | ||
549 | { | ||
550 | + REQUIRE_64BIT(ctx); | ||
551 | REQUIRE_FPU; | ||
552 | REQUIRE_EXT(ctx, RVD); | ||
553 | |||
554 | +#ifdef TARGET_RISCV64 | ||
555 | gen_set_gpr(a->rd, cpu_fpr[a->rs1]); | ||
556 | return true; | ||
557 | +#else | ||
558 | + qemu_build_not_reached(); | ||
559 | +#endif | ||
560 | } | ||
561 | |||
562 | static bool trans_fcvt_d_l(DisasContext *ctx, arg_fcvt_d_l *a) | ||
563 | { | ||
564 | + REQUIRE_64BIT(ctx); | ||
565 | REQUIRE_FPU; | ||
566 | REQUIRE_EXT(ctx, RVD); | ||
567 | |||
568 | @@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_d_l(DisasContext *ctx, arg_fcvt_d_l *a) | ||
569 | |||
570 | static bool trans_fcvt_d_lu(DisasContext *ctx, arg_fcvt_d_lu *a) | ||
571 | { | ||
572 | + REQUIRE_64BIT(ctx); | ||
573 | REQUIRE_FPU; | ||
574 | REQUIRE_EXT(ctx, RVD); | ||
575 | |||
576 | @@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_d_lu(DisasContext *ctx, arg_fcvt_d_lu *a) | ||
577 | |||
578 | static bool trans_fmv_d_x(DisasContext *ctx, arg_fmv_d_x *a) | ||
579 | { | ||
580 | + REQUIRE_64BIT(ctx); | ||
581 | REQUIRE_FPU; | ||
582 | REQUIRE_EXT(ctx, RVD); | ||
583 | |||
584 | +#ifdef TARGET_RISCV64 | ||
585 | TCGv t0 = tcg_temp_new(); | ||
586 | gen_get_gpr(t0, a->rs1); | ||
587 | |||
588 | @@ -XXX,XX +XXX,XX @@ static bool trans_fmv_d_x(DisasContext *ctx, arg_fmv_d_x *a) | ||
589 | tcg_temp_free(t0); | ||
590 | mark_fs_dirty(ctx); | ||
591 | return true; | ||
592 | -} | ||
593 | +#else | ||
594 | + qemu_build_not_reached(); | ||
595 | #endif | ||
596 | +} | ||
597 | diff --git a/target/riscv/insn_trans/trans_rvf.c.inc b/target/riscv/insn_trans/trans_rvf.c.inc | ||
598 | index XXXXXXX..XXXXXXX 100644 | ||
599 | --- a/target/riscv/insn_trans/trans_rvf.c.inc | ||
600 | +++ b/target/riscv/insn_trans/trans_rvf.c.inc | ||
601 | @@ -XXX,XX +XXX,XX @@ static bool trans_fmv_w_x(DisasContext *ctx, arg_fmv_w_x *a) | ||
602 | return true; | ||
603 | } | ||
604 | |||
605 | -#ifdef TARGET_RISCV64 | ||
606 | static bool trans_fcvt_l_s(DisasContext *ctx, arg_fcvt_l_s *a) | ||
607 | { | ||
608 | + REQUIRE_64BIT(ctx); | ||
609 | REQUIRE_FPU; | ||
610 | REQUIRE_EXT(ctx, RVF); | ||
611 | |||
612 | @@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_l_s(DisasContext *ctx, arg_fcvt_l_s *a) | ||
613 | |||
614 | static bool trans_fcvt_lu_s(DisasContext *ctx, arg_fcvt_lu_s *a) | ||
615 | { | ||
616 | + REQUIRE_64BIT(ctx); | ||
617 | REQUIRE_FPU; | ||
618 | REQUIRE_EXT(ctx, RVF); | ||
619 | |||
620 | @@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_lu_s(DisasContext *ctx, arg_fcvt_lu_s *a) | ||
621 | |||
622 | static bool trans_fcvt_s_l(DisasContext *ctx, arg_fcvt_s_l *a) | ||
623 | { | ||
624 | + REQUIRE_64BIT(ctx); | ||
625 | REQUIRE_FPU; | ||
626 | REQUIRE_EXT(ctx, RVF); | ||
627 | |||
628 | @@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_s_l(DisasContext *ctx, arg_fcvt_s_l *a) | ||
629 | |||
630 | static bool trans_fcvt_s_lu(DisasContext *ctx, arg_fcvt_s_lu *a) | ||
631 | { | ||
632 | + REQUIRE_64BIT(ctx); | ||
633 | REQUIRE_FPU; | ||
634 | REQUIRE_EXT(ctx, RVF); | ||
635 | |||
636 | @@ -XXX,XX +XXX,XX @@ static bool trans_fcvt_s_lu(DisasContext *ctx, arg_fcvt_s_lu *a) | ||
637 | tcg_temp_free(t0); | ||
638 | return true; | ||
639 | } | ||
640 | -#endif | ||
641 | diff --git a/target/riscv/insn_trans/trans_rvh.c.inc b/target/riscv/insn_trans/trans_rvh.c.inc | ||
642 | index XXXXXXX..XXXXXXX 100644 | ||
643 | --- a/target/riscv/insn_trans/trans_rvh.c.inc | ||
644 | +++ b/target/riscv/insn_trans/trans_rvh.c.inc | ||
645 | @@ -XXX,XX +XXX,XX @@ static bool trans_hsv_w(DisasContext *ctx, arg_hsv_w *a) | ||
646 | #endif | ||
647 | } | ||
648 | |||
649 | -#ifdef TARGET_RISCV64 | ||
650 | static bool trans_hlv_wu(DisasContext *ctx, arg_hlv_wu *a) | ||
651 | { | ||
652 | + REQUIRE_64BIT(ctx); | ||
653 | REQUIRE_EXT(ctx, RVH); | ||
654 | + | ||
655 | #ifndef CONFIG_USER_ONLY | ||
656 | TCGv t0 = tcg_temp_new(); | ||
657 | TCGv t1 = tcg_temp_new(); | ||
658 | @@ -XXX,XX +XXX,XX @@ static bool trans_hlv_wu(DisasContext *ctx, arg_hlv_wu *a) | ||
659 | |||
660 | static bool trans_hlv_d(DisasContext *ctx, arg_hlv_d *a) | ||
661 | { | ||
662 | + REQUIRE_64BIT(ctx); | ||
663 | REQUIRE_EXT(ctx, RVH); | ||
664 | + | ||
665 | #ifndef CONFIG_USER_ONLY | ||
666 | TCGv t0 = tcg_temp_new(); | ||
667 | TCGv t1 = tcg_temp_new(); | ||
668 | @@ -XXX,XX +XXX,XX @@ static bool trans_hlv_d(DisasContext *ctx, arg_hlv_d *a) | ||
669 | |||
670 | static bool trans_hsv_d(DisasContext *ctx, arg_hsv_d *a) | ||
671 | { | ||
672 | + REQUIRE_64BIT(ctx); | ||
673 | REQUIRE_EXT(ctx, RVH); | ||
674 | + | ||
675 | #ifndef CONFIG_USER_ONLY | ||
676 | TCGv t0 = tcg_temp_new(); | ||
677 | TCGv dat = tcg_temp_new(); | ||
678 | @@ -XXX,XX +XXX,XX @@ static bool trans_hsv_d(DisasContext *ctx, arg_hsv_d *a) | ||
679 | return false; | ||
680 | #endif | ||
681 | } | ||
682 | -#endif | ||
683 | |||
684 | static bool trans_hlvx_hu(DisasContext *ctx, arg_hlvx_hu *a) | ||
685 | { | ||
686 | diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_trans/trans_rvi.c.inc | ||
687 | index XXXXXXX..XXXXXXX 100644 | ||
688 | --- a/target/riscv/insn_trans/trans_rvi.c.inc | ||
689 | +++ b/target/riscv/insn_trans/trans_rvi.c.inc | ||
690 | @@ -XXX,XX +XXX,XX @@ static bool trans_sw(DisasContext *ctx, arg_sw *a) | ||
691 | return gen_store(ctx, a, MO_TESL); | ||
692 | } | ||
693 | |||
694 | -#ifdef TARGET_RISCV64 | ||
695 | static bool trans_lwu(DisasContext *ctx, arg_lwu *a) | ||
696 | { | ||
697 | + REQUIRE_64BIT(ctx); | ||
698 | return gen_load(ctx, a, MO_TEUL); | ||
699 | } | ||
700 | |||
701 | static bool trans_ld(DisasContext *ctx, arg_ld *a) | ||
702 | { | ||
703 | + REQUIRE_64BIT(ctx); | ||
704 | return gen_load(ctx, a, MO_TEQ); | ||
705 | } | ||
706 | |||
707 | static bool trans_sd(DisasContext *ctx, arg_sd *a) | ||
708 | { | ||
709 | + REQUIRE_64BIT(ctx); | ||
710 | return gen_store(ctx, a, MO_TEQ); | ||
711 | } | ||
712 | -#endif | ||
713 | |||
714 | static bool trans_addi(DisasContext *ctx, arg_addi *a) | ||
715 | { | ||
716 | @@ -XXX,XX +XXX,XX @@ static bool trans_and(DisasContext *ctx, arg_and *a) | ||
717 | return gen_arith(ctx, a, &tcg_gen_and_tl); | ||
718 | } | ||
719 | |||
720 | -#ifdef TARGET_RISCV64 | ||
721 | static bool trans_addiw(DisasContext *ctx, arg_addiw *a) | ||
722 | { | ||
723 | + REQUIRE_64BIT(ctx); | ||
724 | return gen_arith_imm_tl(ctx, a, &gen_addw); | ||
725 | } | ||
726 | |||
727 | static bool trans_slliw(DisasContext *ctx, arg_slliw *a) | ||
728 | { | ||
729 | + REQUIRE_64BIT(ctx); | ||
730 | TCGv source1; | ||
731 | source1 = tcg_temp_new(); | ||
732 | gen_get_gpr(source1, a->rs1); | ||
733 | @@ -XXX,XX +XXX,XX @@ static bool trans_slliw(DisasContext *ctx, arg_slliw *a) | ||
734 | |||
735 | static bool trans_srliw(DisasContext *ctx, arg_srliw *a) | ||
736 | { | ||
737 | + REQUIRE_64BIT(ctx); | ||
738 | TCGv t = tcg_temp_new(); | ||
739 | gen_get_gpr(t, a->rs1); | ||
740 | tcg_gen_extract_tl(t, t, a->shamt, 32 - a->shamt); | ||
741 | @@ -XXX,XX +XXX,XX @@ static bool trans_srliw(DisasContext *ctx, arg_srliw *a) | ||
742 | |||
743 | static bool trans_sraiw(DisasContext *ctx, arg_sraiw *a) | ||
744 | { | ||
745 | + REQUIRE_64BIT(ctx); | ||
746 | TCGv t = tcg_temp_new(); | ||
747 | gen_get_gpr(t, a->rs1); | ||
748 | tcg_gen_sextract_tl(t, t, a->shamt, 32 - a->shamt); | ||
749 | @@ -XXX,XX +XXX,XX @@ static bool trans_sraiw(DisasContext *ctx, arg_sraiw *a) | ||
750 | |||
751 | static bool trans_addw(DisasContext *ctx, arg_addw *a) | ||
752 | { | ||
753 | + REQUIRE_64BIT(ctx); | ||
754 | return gen_arith(ctx, a, &gen_addw); | ||
755 | } | ||
756 | |||
757 | static bool trans_subw(DisasContext *ctx, arg_subw *a) | ||
758 | { | ||
759 | + REQUIRE_64BIT(ctx); | ||
760 | return gen_arith(ctx, a, &gen_subw); | ||
761 | } | ||
762 | |||
763 | static bool trans_sllw(DisasContext *ctx, arg_sllw *a) | ||
764 | { | ||
765 | + REQUIRE_64BIT(ctx); | ||
766 | TCGv source1 = tcg_temp_new(); | ||
767 | TCGv source2 = tcg_temp_new(); | ||
768 | |||
769 | @@ -XXX,XX +XXX,XX @@ static bool trans_sllw(DisasContext *ctx, arg_sllw *a) | ||
770 | |||
771 | static bool trans_srlw(DisasContext *ctx, arg_srlw *a) | ||
772 | { | ||
773 | + REQUIRE_64BIT(ctx); | ||
774 | TCGv source1 = tcg_temp_new(); | ||
775 | TCGv source2 = tcg_temp_new(); | ||
776 | |||
777 | @@ -XXX,XX +XXX,XX @@ static bool trans_srlw(DisasContext *ctx, arg_srlw *a) | ||
778 | |||
779 | static bool trans_sraw(DisasContext *ctx, arg_sraw *a) | ||
780 | { | ||
781 | + REQUIRE_64BIT(ctx); | ||
782 | TCGv source1 = tcg_temp_new(); | ||
783 | TCGv source2 = tcg_temp_new(); | ||
784 | |||
785 | @@ -XXX,XX +XXX,XX @@ static bool trans_sraw(DisasContext *ctx, arg_sraw *a) | ||
786 | |||
787 | return true; | ||
788 | } | ||
789 | -#endif | ||
790 | |||
791 | static bool trans_fence(DisasContext *ctx, arg_fence *a) | ||
792 | { | ||
793 | diff --git a/target/riscv/insn_trans/trans_rvm.c.inc b/target/riscv/insn_trans/trans_rvm.c.inc | ||
794 | index XXXXXXX..XXXXXXX 100644 | ||
795 | --- a/target/riscv/insn_trans/trans_rvm.c.inc | ||
796 | +++ b/target/riscv/insn_trans/trans_rvm.c.inc | ||
797 | @@ -XXX,XX +XXX,XX @@ static bool trans_remu(DisasContext *ctx, arg_remu *a) | ||
798 | return gen_arith(ctx, a, &gen_remu); | ||
799 | } | ||
800 | |||
801 | -#ifdef TARGET_RISCV64 | ||
802 | static bool trans_mulw(DisasContext *ctx, arg_mulw *a) | ||
803 | { | ||
804 | + REQUIRE_64BIT(ctx); | ||
805 | REQUIRE_EXT(ctx, RVM); | ||
806 | + | ||
807 | return gen_arith(ctx, a, &gen_mulw); | ||
808 | } | ||
809 | |||
810 | static bool trans_divw(DisasContext *ctx, arg_divw *a) | ||
811 | { | ||
812 | + REQUIRE_64BIT(ctx); | ||
813 | REQUIRE_EXT(ctx, RVM); | ||
814 | + | ||
815 | return gen_arith_div_w(ctx, a, &gen_div); | ||
816 | } | ||
817 | |||
818 | static bool trans_divuw(DisasContext *ctx, arg_divuw *a) | ||
819 | { | ||
820 | + REQUIRE_64BIT(ctx); | ||
821 | REQUIRE_EXT(ctx, RVM); | ||
822 | + | ||
823 | return gen_arith_div_uw(ctx, a, &gen_divu); | ||
824 | } | ||
825 | |||
826 | static bool trans_remw(DisasContext *ctx, arg_remw *a) | ||
827 | { | ||
828 | + REQUIRE_64BIT(ctx); | ||
829 | REQUIRE_EXT(ctx, RVM); | ||
830 | + | ||
831 | return gen_arith_div_w(ctx, a, &gen_rem); | ||
832 | } | ||
833 | |||
834 | static bool trans_remuw(DisasContext *ctx, arg_remuw *a) | ||
835 | { | ||
836 | + REQUIRE_64BIT(ctx); | ||
837 | REQUIRE_EXT(ctx, RVM); | ||
838 | + | ||
839 | return gen_arith_div_uw(ctx, a, &gen_remu); | ||
840 | } | ||
841 | -#endif | ||
842 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | ||
843 | index XXXXXXX..XXXXXXX 100644 | ||
844 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | ||
845 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | ||
846 | @@ -XXX,XX +XXX,XX @@ static bool amo_op(DisasContext *s, arg_rwdvm *a, uint8_t seq) | ||
847 | gen_helper_vamominuw_v_w, | ||
848 | gen_helper_vamomaxuw_v_w | ||
849 | }; | ||
850 | -#ifdef TARGET_RISCV64 | ||
851 | static gen_helper_amo *const fnsd[18] = { | ||
852 | gen_helper_vamoswapw_v_d, | ||
853 | gen_helper_vamoaddw_v_d, | ||
854 | @@ -XXX,XX +XXX,XX @@ static bool amo_op(DisasContext *s, arg_rwdvm *a, uint8_t seq) | ||
855 | gen_helper_vamominud_v_d, | ||
856 | gen_helper_vamomaxud_v_d | ||
857 | }; | ||
858 | -#endif | ||
859 | |||
860 | if (tb_cflags(s->base.tb) & CF_PARALLEL) { | ||
861 | gen_helper_exit_atomic(cpu_env); | ||
862 | @@ -XXX,XX +XXX,XX @@ static bool amo_op(DisasContext *s, arg_rwdvm *a, uint8_t seq) | ||
863 | return true; | ||
864 | } else { | ||
865 | if (s->sew == 3) { | ||
866 | -#ifdef TARGET_RISCV64 | ||
867 | - fn = fnsd[seq]; | ||
868 | -#else | ||
869 | - /* Check done in amo_check(). */ | ||
870 | - g_assert_not_reached(); | ||
871 | -#endif | ||
872 | + if (!is_32bit(s)) { | ||
873 | + fn = fnsd[seq]; | ||
874 | + } else { | ||
875 | + /* Check done in amo_check(). */ | ||
876 | + g_assert_not_reached(); | ||
877 | + } | ||
878 | } else { | ||
879 | assert(seq < ARRAY_SIZE(fnsw)); | ||
880 | fn = fnsw[seq]; | ||
881 | @@ -XXX,XX +XXX,XX @@ static bool amo_check(DisasContext *s, arg_rwdvm* a) | ||
882 | ((1 << s->sew) >= 4)); | ||
883 | } | ||
884 | |||
885 | +static bool amo_check64(DisasContext *s, arg_rwdvm* a) | ||
64 | +{ | 886 | +{ |
65 | + memset(env->ctr_src, 0x0, sizeof(env->ctr_src)); | 887 | + return !is_32bit(s) && amo_check(s, a); |
66 | + memset(env->ctr_dst, 0x0, sizeof(env->ctr_dst)); | ||
67 | + memset(env->ctr_data, 0x0, sizeof(env->ctr_data)); | ||
68 | +} | 888 | +} |
69 | + | 889 | + |
70 | static uint64_t riscv_ctr_priv_to_mask(target_ulong priv, bool virt) | 890 | GEN_VEXT_TRANS(vamoswapw_v, 0, rwdvm, amo_op, amo_check) |
71 | { | 891 | GEN_VEXT_TRANS(vamoaddw_v, 1, rwdvm, amo_op, amo_check) |
72 | switch (priv) { | 892 | GEN_VEXT_TRANS(vamoxorw_v, 2, rwdvm, amo_op, amo_check) |
73 | diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c | 893 | @@ -XXX,XX +XXX,XX @@ GEN_VEXT_TRANS(vamominw_v, 5, rwdvm, amo_op, amo_check) |
74 | index XXXXXXX..XXXXXXX 100644 | 894 | GEN_VEXT_TRANS(vamomaxw_v, 6, rwdvm, amo_op, amo_check) |
75 | --- a/target/riscv/op_helper.c | 895 | GEN_VEXT_TRANS(vamominuw_v, 7, rwdvm, amo_op, amo_check) |
76 | +++ b/target/riscv/op_helper.c | 896 | GEN_VEXT_TRANS(vamomaxuw_v, 8, rwdvm, amo_op, amo_check) |
77 | @@ -XXX,XX +XXX,XX @@ void helper_ctr_add_entry(CPURISCVState *env, target_ulong src, | 897 | -#ifdef TARGET_RISCV64 |
78 | env->priv, env->virt_enabled); | 898 | -GEN_VEXT_TRANS(vamoswapd_v, 9, rwdvm, amo_op, amo_check) |
79 | } | 899 | -GEN_VEXT_TRANS(vamoaddd_v, 10, rwdvm, amo_op, amo_check) |
80 | 900 | -GEN_VEXT_TRANS(vamoxord_v, 11, rwdvm, amo_op, amo_check) | |
81 | +void helper_ctr_clear(CPURISCVState *env) | 901 | -GEN_VEXT_TRANS(vamoandd_v, 12, rwdvm, amo_op, amo_check) |
82 | +{ | 902 | -GEN_VEXT_TRANS(vamoord_v, 13, rwdvm, amo_op, amo_check) |
83 | + /* | 903 | -GEN_VEXT_TRANS(vamomind_v, 14, rwdvm, amo_op, amo_check) |
84 | + * It's safe to call smstateen_acc_ok() for umode access regardless of the | 904 | -GEN_VEXT_TRANS(vamomaxd_v, 15, rwdvm, amo_op, amo_check) |
85 | + * state of bit 54 (CTR bit in case of m/hstateen) of sstateen. If the bit | 905 | -GEN_VEXT_TRANS(vamominud_v, 16, rwdvm, amo_op, amo_check) |
86 | + * is zero, smstateen_acc_ok() will return the correct exception code and | 906 | -GEN_VEXT_TRANS(vamomaxud_v, 17, rwdvm, amo_op, amo_check) |
87 | + * if it's one, smstateen_acc_ok() will return RISCV_EXCP_NONE. In that | 907 | -#endif |
88 | + * scenario the U-mode check below will handle that case. | 908 | +GEN_VEXT_TRANS(vamoswapd_v, 9, rwdvm, amo_op, amo_check64) |
89 | + */ | 909 | +GEN_VEXT_TRANS(vamoaddd_v, 10, rwdvm, amo_op, amo_check64) |
90 | + RISCVException ret = smstateen_acc_ok(env, 0, SMSTATEEN0_CTR); | 910 | +GEN_VEXT_TRANS(vamoxord_v, 11, rwdvm, amo_op, amo_check64) |
91 | + if (ret != RISCV_EXCP_NONE) { | 911 | +GEN_VEXT_TRANS(vamoandd_v, 12, rwdvm, amo_op, amo_check64) |
92 | + riscv_raise_exception(env, ret, GETPC()); | 912 | +GEN_VEXT_TRANS(vamoord_v, 13, rwdvm, amo_op, amo_check64) |
93 | + } | 913 | +GEN_VEXT_TRANS(vamomind_v, 14, rwdvm, amo_op, amo_check64) |
94 | + | 914 | +GEN_VEXT_TRANS(vamomaxd_v, 15, rwdvm, amo_op, amo_check64) |
95 | + if (env->priv == PRV_U) { | 915 | +GEN_VEXT_TRANS(vamominud_v, 16, rwdvm, amo_op, amo_check64) |
96 | + /* | 916 | +GEN_VEXT_TRANS(vamomaxud_v, 17, rwdvm, amo_op, amo_check64) |
97 | + * One corner case is when sctrclr is executed from VU-mode and | 917 | |
98 | + * mstateen.CTR = 0, in which case we are supposed to raise | 918 | /* |
99 | + * RISCV_EXCP_ILLEGAL_INST. This case is already handled in | 919 | *** Vector Integer Arithmetic Instructions |
100 | + * smstateen_acc_ok(). | 920 | diff --git a/target/riscv/meson.build b/target/riscv/meson.build |
101 | + */ | 921 | index XXXXXXX..XXXXXXX 100644 |
102 | + uint32_t excep = env->virt_enabled ? RISCV_EXCP_VIRT_INSTRUCTION_FAULT : | 922 | --- a/target/riscv/meson.build |
103 | + RISCV_EXCP_ILLEGAL_INST; | 923 | +++ b/target/riscv/meson.build |
104 | + riscv_raise_exception(env, excep, GETPC()); | 924 | @@ -XXX,XX +XXX,XX @@ gen32 = [ |
105 | + } | 925 | |
106 | + | 926 | gen64 = [ |
107 | + riscv_ctr_clear(env); | 927 | decodetree.process('insn16.decode', extra_args: [dir / 'insn16-64.decode', '--static-decode=decode_insn16', '--insnwidth=16']), |
108 | +} | 928 | - decodetree.process('insn32.decode', extra_args: [dir / 'insn32-64.decode', '--static-decode=decode_insn32']), |
109 | + | 929 | + decodetree.process('insn32.decode', extra_args: '--static-decode=decode_insn32'), |
110 | void helper_wfi(CPURISCVState *env) | 930 | ] |
111 | { | 931 | |
112 | CPUState *cs = env_cpu(env); | 932 | riscv_ss = ss.source_set() |
113 | diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc | ||
114 | index XXXXXXX..XXXXXXX 100644 | ||
115 | --- a/target/riscv/insn_trans/trans_privileged.c.inc | ||
116 | +++ b/target/riscv/insn_trans/trans_privileged.c.inc | ||
117 | @@ -XXX,XX +XXX,XX @@ static bool trans_ebreak(DisasContext *ctx, arg_ebreak *a) | ||
118 | return true; | ||
119 | } | ||
120 | |||
121 | +static bool trans_sctrclr(DisasContext *ctx, arg_sctrclr *a) | ||
122 | +{ | ||
123 | +#ifndef CONFIG_USER_ONLY | ||
124 | + if (ctx->cfg_ptr->ext_smctr || ctx->cfg_ptr->ext_ssctr) { | ||
125 | + gen_helper_ctr_clear(tcg_env); | ||
126 | + return true; | ||
127 | + } | ||
128 | +#endif | ||
129 | + return false; | ||
130 | +} | ||
131 | + | ||
132 | static bool trans_uret(DisasContext *ctx, arg_uret *a) | ||
133 | { | ||
134 | return false; | ||
135 | -- | 933 | -- |
136 | 2.48.1 | 934 | 2.31.1 |
935 | |||
936 | diff view generated by jsdifflib |
1 | From: Tomasz Jeznach <tjeznach@rivosinc.com> | 1 | This patch removes the insn16-32.decode and insn16-64.decode decode |
---|---|---|---|
2 | files and consolidates the instructions into the general RISC-V | ||
3 | insn16.decode decode tree. | ||
2 | 4 | ||
3 | RISCV_IOMMU_REG_IOCOUNTINH is done by riscv_iommu_process_iocntinh_cy(), | 5 | This means that all of the instructions are avaliable in both the 32-bit |
4 | which is called during riscv_iommu_mmio_write() callback via a new | 6 | and 64-bit builds. This also means that we run a check to ensure we are |
5 | riscv_iommu_pricess_hpm_writes() helper. | 7 | running a 64-bit softmmu before we execute the 64-bit only instructions. |
8 | This allows us to include the 32-bit instructions in the 64-bit build, | ||
9 | while also ensuring that 32-bit only software can not execute the | ||
10 | instructions. | ||
6 | 11 | ||
7 | Signed-off-by: Tomasz Jeznach <tjeznach@rivosinc.com> | ||
8 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
9 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | Message-ID: <20250224190826.1858473-7-dbarboza@ventanamicro.com> | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
14 | Message-id: 01e2b0efeae311adc7ebf133c2cde6a7a37224d7.1619234854.git.alistair.francis@wdc.com | ||
12 | --- | 15 | --- |
13 | hw/riscv/riscv-iommu-hpm.h | 1 + | 16 | target/riscv/insn16-32.decode | 28 ------------------- |
14 | hw/riscv/riscv-iommu-hpm.c | 60 ++++++++++++++++++++++++++++++++++++++ | 17 | target/riscv/insn16-64.decode | 36 ------------------------- |
15 | hw/riscv/riscv-iommu.c | 38 ++++++++++++++++++++++++ | 18 | target/riscv/insn16.decode | 30 +++++++++++++++++++++ |
16 | 3 files changed, 99 insertions(+) | 19 | target/riscv/insn_trans/trans_rvi.c.inc | 6 +++++ |
20 | target/riscv/meson.build | 11 +++----- | ||
21 | 5 files changed, 39 insertions(+), 72 deletions(-) | ||
22 | delete mode 100644 target/riscv/insn16-32.decode | ||
23 | delete mode 100644 target/riscv/insn16-64.decode | ||
17 | 24 | ||
18 | diff --git a/hw/riscv/riscv-iommu-hpm.h b/hw/riscv/riscv-iommu-hpm.h | 25 | diff --git a/target/riscv/insn16-32.decode b/target/riscv/insn16-32.decode |
26 | deleted file mode 100644 | ||
27 | index XXXXXXX..XXXXXXX | ||
28 | --- a/target/riscv/insn16-32.decode | ||
29 | +++ /dev/null | ||
30 | @@ -XXX,XX +XXX,XX @@ | ||
31 | -# | ||
32 | -# RISC-V translation routines for the RVXI Base Integer Instruction Set. | ||
33 | -# | ||
34 | -# Copyright (c) 2018 Peer Adelt, peer.adelt@hni.uni-paderborn.de | ||
35 | -# Bastian Koppelmann, kbastian@mail.uni-paderborn.de | ||
36 | -# | ||
37 | -# This program is free software; you can redistribute it and/or modify it | ||
38 | -# under the terms and conditions of the GNU General Public License, | ||
39 | -# version 2 or later, as published by the Free Software Foundation. | ||
40 | -# | ||
41 | -# This program is distributed in the hope it will be useful, but WITHOUT | ||
42 | -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
43 | -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
44 | -# more details. | ||
45 | -# | ||
46 | -# You should have received a copy of the GNU General Public License along with | ||
47 | -# this program. If not, see <http://www.gnu.org/licenses/>. | ||
48 | - | ||
49 | -# *** RV32C Standard Extension (Quadrant 0) *** | ||
50 | -flw 011 ... ... .. ... 00 @cl_w | ||
51 | -fsw 111 ... ... .. ... 00 @cs_w | ||
52 | - | ||
53 | -# *** RV32C Standard Extension (Quadrant 1) *** | ||
54 | -jal 001 ........... 01 @cj rd=1 # C.JAL | ||
55 | - | ||
56 | -# *** RV32C Standard Extension (Quadrant 2) *** | ||
57 | -flw 011 . ..... ..... 10 @c_lwsp | ||
58 | -fsw 111 . ..... ..... 10 @c_swsp | ||
59 | diff --git a/target/riscv/insn16-64.decode b/target/riscv/insn16-64.decode | ||
60 | deleted file mode 100644 | ||
61 | index XXXXXXX..XXXXXXX | ||
62 | --- a/target/riscv/insn16-64.decode | ||
63 | +++ /dev/null | ||
64 | @@ -XXX,XX +XXX,XX @@ | ||
65 | -# | ||
66 | -# RISC-V translation routines for the RVXI Base Integer Instruction Set. | ||
67 | -# | ||
68 | -# Copyright (c) 2018 Peer Adelt, peer.adelt@hni.uni-paderborn.de | ||
69 | -# Bastian Koppelmann, kbastian@mail.uni-paderborn.de | ||
70 | -# | ||
71 | -# This program is free software; you can redistribute it and/or modify it | ||
72 | -# under the terms and conditions of the GNU General Public License, | ||
73 | -# version 2 or later, as published by the Free Software Foundation. | ||
74 | -# | ||
75 | -# This program is distributed in the hope it will be useful, but WITHOUT | ||
76 | -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
77 | -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
78 | -# more details. | ||
79 | -# | ||
80 | -# You should have received a copy of the GNU General Public License along with | ||
81 | -# this program. If not, see <http://www.gnu.org/licenses/>. | ||
82 | - | ||
83 | -# *** RV64C Standard Extension (Quadrant 0) *** | ||
84 | -ld 011 ... ... .. ... 00 @cl_d | ||
85 | -sd 111 ... ... .. ... 00 @cs_d | ||
86 | - | ||
87 | -# *** RV64C Standard Extension (Quadrant 1) *** | ||
88 | -{ | ||
89 | - illegal 001 - 00000 ----- 01 # c.addiw, RES rd=0 | ||
90 | - addiw 001 . ..... ..... 01 @ci | ||
91 | -} | ||
92 | -subw 100 1 11 ... 00 ... 01 @cs_2 | ||
93 | -addw 100 1 11 ... 01 ... 01 @cs_2 | ||
94 | - | ||
95 | -# *** RV64C Standard Extension (Quadrant 2) *** | ||
96 | -{ | ||
97 | - illegal 011 - 00000 ----- 10 # c.ldsp, RES rd=0 | ||
98 | - ld 011 . ..... ..... 10 @c_ldsp | ||
99 | -} | ||
100 | -sd 111 . ..... ..... 10 @c_sdsp | ||
101 | diff --git a/target/riscv/insn16.decode b/target/riscv/insn16.decode | ||
19 | index XXXXXXX..XXXXXXX 100644 | 102 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/hw/riscv/riscv-iommu-hpm.h | 103 | --- a/target/riscv/insn16.decode |
21 | +++ b/hw/riscv/riscv-iommu-hpm.h | 104 | +++ b/target/riscv/insn16.decode |
22 | @@ -XXX,XX +XXX,XX @@ uint64_t riscv_iommu_hpmcycle_read(RISCVIOMMUState *s); | 105 | @@ -XXX,XX +XXX,XX @@ lw 010 ... ... .. ... 00 @cl_w |
23 | void riscv_iommu_hpm_incr_ctr(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, | 106 | fsd 101 ... ... .. ... 00 @cs_d |
24 | unsigned event_id); | 107 | sw 110 ... ... .. ... 00 @cs_w |
25 | void riscv_iommu_hpm_timer_cb(void *priv); | 108 | |
26 | +void riscv_iommu_process_iocntinh_cy(RISCVIOMMUState *s, bool prev_cy_inh); | 109 | +# *** RV32C and RV64C specific Standard Extension (Quadrant 0) *** |
27 | |||
28 | #endif | ||
29 | diff --git a/hw/riscv/riscv-iommu-hpm.c b/hw/riscv/riscv-iommu-hpm.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/hw/riscv/riscv-iommu-hpm.c | ||
32 | +++ b/hw/riscv/riscv-iommu-hpm.c | ||
33 | @@ -XXX,XX +XXX,XX @@ void riscv_iommu_hpm_timer_cb(void *priv) | ||
34 | riscv_iommu_notify(s, RISCV_IOMMU_INTR_PM); | ||
35 | } | ||
36 | } | ||
37 | + | ||
38 | +static void hpm_setup_timer(RISCVIOMMUState *s, uint64_t value) | ||
39 | +{ | 110 | +{ |
40 | + const uint32_t inhibit = riscv_iommu_reg_get32( | 111 | + ld 011 ... ... .. ... 00 @cl_d |
41 | + s, RISCV_IOMMU_REG_IOCOUNTINH); | 112 | + flw 011 ... ... .. ... 00 @cl_w |
42 | + uint64_t overflow_at, overflow_ns; | 113 | +} |
43 | + | 114 | +{ |
44 | + if (get_field(inhibit, RISCV_IOMMU_IOCOUNTINH_CY)) { | 115 | + sd 111 ... ... .. ... 00 @cs_d |
45 | + return; | 116 | + fsw 111 ... ... .. ... 00 @cs_w |
46 | + } | ||
47 | + | ||
48 | + /* | ||
49 | + * We are using INT64_MAX here instead to UINT64_MAX because cycle counter | ||
50 | + * has 63-bit precision and INT64_MAX is the maximum it can store. | ||
51 | + */ | ||
52 | + if (value) { | ||
53 | + overflow_ns = INT64_MAX - value + 1; | ||
54 | + } else { | ||
55 | + overflow_ns = INT64_MAX; | ||
56 | + } | ||
57 | + | ||
58 | + overflow_at = (uint64_t)qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + overflow_ns; | ||
59 | + | ||
60 | + if (overflow_at > INT64_MAX) { | ||
61 | + s->irq_overflow_left = overflow_at - INT64_MAX; | ||
62 | + overflow_at = INT64_MAX; | ||
63 | + } | ||
64 | + | ||
65 | + timer_mod_anticipate_ns(s->hpm_timer, overflow_at); | ||
66 | +} | 117 | +} |
67 | + | 118 | + |
68 | +/* Updates the internal cycle counter state when iocntinh:CY is changed. */ | 119 | # *** RV32/64C Standard Extension (Quadrant 1) *** |
69 | +void riscv_iommu_process_iocntinh_cy(RISCVIOMMUState *s, bool prev_cy_inh) | 120 | addi 000 . ..... ..... 01 @ci |
121 | addi 010 . ..... ..... 01 @c_li | ||
122 | @@ -XXX,XX +XXX,XX @@ jal 101 ........... 01 @cj rd=0 # C.J | ||
123 | beq 110 ... ... ..... 01 @cb_z | ||
124 | bne 111 ... ... ..... 01 @cb_z | ||
125 | |||
126 | +# *** RV64C and RV32C specific Standard Extension (Quadrant 1) *** | ||
70 | +{ | 127 | +{ |
71 | + const uint32_t inhibit = riscv_iommu_reg_get32( | 128 | + c64_illegal 001 - 00000 ----- 01 # c.addiw, RES rd=0 |
72 | + s, RISCV_IOMMU_REG_IOCOUNTINH); | 129 | + addiw 001 . ..... ..... 01 @ci |
130 | + jal 001 ........... 01 @cj rd=1 # C.JAL | ||
131 | +} | ||
132 | +subw 100 1 11 ... 00 ... 01 @cs_2 | ||
133 | +addw 100 1 11 ... 01 ... 01 @cs_2 | ||
73 | + | 134 | + |
74 | + /* We only need to process CY bit toggle. */ | 135 | # *** RV32/64C Standard Extension (Quadrant 2) *** |
75 | + if (!(inhibit ^ prev_cy_inh)) { | 136 | slli 000 . ..... ..... 10 @c_shift2 |
76 | + return; | 137 | fld 001 . ..... ..... 10 @c_ldsp |
77 | + } | 138 | @@ -XXX,XX +XXX,XX @@ fld 001 . ..... ..... 10 @c_ldsp |
139 | } | ||
140 | fsd 101 ...... ..... 10 @c_sdsp | ||
141 | sw 110 . ..... ..... 10 @c_swsp | ||
78 | + | 142 | + |
79 | + if (!(inhibit & RISCV_IOMMU_IOCOUNTINH_CY)) { | 143 | +# *** RV32C and RV64C specific Standard Extension (Quadrant 2) *** |
80 | + /* | 144 | +{ |
81 | + * Cycle counter is enabled. Just start the timer again and update | 145 | + c64_illegal 011 - 00000 ----- 10 # c.ldsp, RES rd=0 |
82 | + * the clock snapshot value to point to the current time to make | 146 | + ld 011 . ..... ..... 10 @c_ldsp |
83 | + * sure iohpmcycles read is correct. | 147 | + flw 011 . ..... ..... 10 @c_lwsp |
84 | + */ | ||
85 | + s->hpmcycle_prev = get_cycles(); | ||
86 | + hpm_setup_timer(s, s->hpmcycle_val); | ||
87 | + } else { | ||
88 | + /* | ||
89 | + * Cycle counter is disabled. Stop the timer and update the cycle | ||
90 | + * counter to record the current value which is last programmed | ||
91 | + * value + the cycles passed so far. | ||
92 | + */ | ||
93 | + s->hpmcycle_val = s->hpmcycle_val + (get_cycles() - s->hpmcycle_prev); | ||
94 | + timer_del(s->hpm_timer); | ||
95 | + } | ||
96 | +} | 148 | +} |
97 | diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c | 149 | +{ |
150 | + sd 111 . ..... ..... 10 @c_sdsp | ||
151 | + fsw 111 . ..... ..... 10 @c_swsp | ||
152 | +} | ||
153 | diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_trans/trans_rvi.c.inc | ||
98 | index XXXXXXX..XXXXXXX 100644 | 154 | index XXXXXXX..XXXXXXX 100644 |
99 | --- a/hw/riscv/riscv-iommu.c | 155 | --- a/target/riscv/insn_trans/trans_rvi.c.inc |
100 | +++ b/hw/riscv/riscv-iommu.c | 156 | +++ b/target/riscv/insn_trans/trans_rvi.c.inc |
101 | @@ -XXX,XX +XXX,XX @@ static void riscv_iommu_update_ipsr(RISCVIOMMUState *s, uint64_t data) | 157 | @@ -XXX,XX +XXX,XX @@ static bool trans_illegal(DisasContext *ctx, arg_empty *a) |
102 | riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_IPSR, ipsr_set, ipsr_clr); | 158 | return true; |
103 | } | 159 | } |
104 | 160 | ||
105 | +static void riscv_iommu_process_hpm_writes(RISCVIOMMUState *s, | 161 | +static bool trans_c64_illegal(DisasContext *ctx, arg_empty *a) |
106 | + uint32_t regb, | ||
107 | + bool prev_cy_inh) | ||
108 | +{ | 162 | +{ |
109 | + switch (regb) { | 163 | + REQUIRE_64BIT(ctx); |
110 | + case RISCV_IOMMU_REG_IOCOUNTINH: | 164 | + return trans_illegal(ctx, a); |
111 | + riscv_iommu_process_iocntinh_cy(s, prev_cy_inh); | ||
112 | + break; | ||
113 | + | ||
114 | + case RISCV_IOMMU_REG_IOHPMCYCLES: | ||
115 | + case RISCV_IOMMU_REG_IOHPMCYCLES + 4: | ||
116 | + /* not yet implemented */ | ||
117 | + break; | ||
118 | + | ||
119 | + case RISCV_IOMMU_REG_IOHPMEVT_BASE ... | ||
120 | + RISCV_IOMMU_REG_IOHPMEVT(RISCV_IOMMU_IOCOUNT_NUM) + 4: | ||
121 | + /* not yet implemented */ | ||
122 | + break; | ||
123 | + } | ||
124 | +} | 165 | +} |
125 | + | 166 | + |
126 | /* | 167 | static bool trans_lui(DisasContext *ctx, arg_lui *a) |
127 | * Write the resulting value of 'data' for the reg specified | 168 | { |
128 | * by 'reg_addr', after considering read-only/read-write/write-clear | 169 | if (a->rd != 0) { |
129 | @@ -XXX,XX +XXX,XX @@ static MemTxResult riscv_iommu_mmio_write(void *opaque, hwaddr addr, | 170 | diff --git a/target/riscv/meson.build b/target/riscv/meson.build |
130 | uint32_t regb = addr & ~3; | 171 | index XXXXXXX..XXXXXXX 100644 |
131 | uint32_t busy = 0; | 172 | --- a/target/riscv/meson.build |
132 | uint64_t val = 0; | 173 | +++ b/target/riscv/meson.build |
133 | + bool cy_inh = false; | 174 | @@ -XXX,XX +XXX,XX @@ |
134 | 175 | # FIXME extra_args should accept files() | |
135 | if ((addr & (size - 1)) != 0) { | 176 | dir = meson.current_source_dir() |
136 | /* Unsupported MMIO alignment or access size */ | 177 | -gen32 = [ |
137 | @@ -XXX,XX +XXX,XX @@ static MemTxResult riscv_iommu_mmio_write(void *opaque, hwaddr addr, | 178 | - decodetree.process('insn16.decode', extra_args: [dir / 'insn16-32.decode', '--static-decode=decode_insn16', '--insnwidth=16']), |
138 | busy = RISCV_IOMMU_TR_REQ_CTL_GO_BUSY; | 179 | - decodetree.process('insn32.decode', extra_args: '--static-decode=decode_insn32'), |
139 | break; | 180 | -] |
140 | 181 | ||
141 | + case RISCV_IOMMU_REG_IOCOUNTINH: | 182 | -gen64 = [ |
142 | + if (addr != RISCV_IOMMU_REG_IOCOUNTINH) { | 183 | - decodetree.process('insn16.decode', extra_args: [dir / 'insn16-64.decode', '--static-decode=decode_insn16', '--insnwidth=16']), |
143 | + break; | 184 | +gen = [ |
144 | + } | 185 | + decodetree.process('insn16.decode', extra_args: ['--static-decode=decode_insn16', '--insnwidth=16']), |
145 | + /* Store previous value of CY bit. */ | 186 | decodetree.process('insn32.decode', extra_args: '--static-decode=decode_insn32'), |
146 | + cy_inh = !!(riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_IOCOUNTINH) & | 187 | ] |
147 | + RISCV_IOMMU_IOCOUNTINH_CY); | 188 | |
148 | + break; | 189 | riscv_ss = ss.source_set() |
149 | + | 190 | -riscv_ss.add(when: 'TARGET_RISCV32', if_true: gen32) |
150 | + | 191 | -riscv_ss.add(when: 'TARGET_RISCV64', if_true: gen64) |
151 | default: | 192 | +riscv_ss.add(gen) |
152 | break; | 193 | riscv_ss.add(files( |
153 | } | 194 | 'cpu.c', |
154 | @@ -XXX,XX +XXX,XX @@ static MemTxResult riscv_iommu_mmio_write(void *opaque, hwaddr addr, | 195 | 'cpu_helper.c', |
155 | stl_le_p(&s->regs_rw[regb], rw | busy); | ||
156 | } | ||
157 | |||
158 | + /* Process HPM writes and update any internal state if needed. */ | ||
159 | + if (regb >= RISCV_IOMMU_REG_IOCOUNTOVF && | ||
160 | + regb <= (RISCV_IOMMU_REG_IOHPMEVT(RISCV_IOMMU_IOCOUNT_NUM) + 4)) { | ||
161 | + riscv_iommu_process_hpm_writes(s, regb, cy_inh); | ||
162 | + } | ||
163 | + | ||
164 | if (process_fn) { | ||
165 | process_fn(s); | ||
166 | } | ||
167 | -- | 196 | -- |
168 | 2.48.1 | 197 | 2.31.1 |
198 | |||
199 | diff view generated by jsdifflib |
1 | From: Rajnesh Kanwal <rkanwal@rivosinc.com> | 1 | BugLink: https://gitlab.com/qemu-project/qemu/-/issues/47 |
---|---|---|---|
2 | |||
3 | Signed-off-by: Rajnesh Kanwal <rkanwal@rivosinc.com> | ||
4 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
5 | Reviewed-by: Jason Chien <jason.chien@sifive.com> | ||
6 | Message-ID: <20250205-b4-ctr_upstream_v6-v6-1-439d8e06c8ef@rivosinc.com> | ||
7 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 2 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
3 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
4 | Message-id: 024ce841221c1d15c74b253512428c4baca7e4ba.1619234854.git.alistair.francis@wdc.com | ||
8 | --- | 5 | --- |
9 | target/riscv/insn32.decode | 1 - | 6 | target/riscv/insn32.decode | 2 +- |
10 | target/riscv/insn_trans/trans_privileged.c.inc | 5 ----- | 7 | 1 file changed, 1 insertion(+), 1 deletion(-) |
11 | 2 files changed, 6 deletions(-) | ||
12 | 8 | ||
13 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | 9 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode |
14 | index XXXXXXX..XXXXXXX 100644 | 10 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/riscv/insn32.decode | 11 | --- a/target/riscv/insn32.decode |
16 | +++ b/target/riscv/insn32.decode | 12 | +++ b/target/riscv/insn32.decode |
17 | @@ -XXX,XX +XXX,XX @@ sret 0001000 00010 00000 000 00000 1110011 | 13 | @@ -XXX,XX +XXX,XX @@ hsv_w 0110101 ..... ..... 100 00000 1110011 @r2_s |
18 | mret 0011000 00010 00000 000 00000 1110011 | 14 | hfence_gvma 0110001 ..... ..... 000 00000 1110011 @hfence_gvma |
19 | wfi 0001000 00101 00000 000 00000 1110011 | 15 | hfence_vvma 0010001 ..... ..... 000 00000 1110011 @hfence_vvma |
20 | sfence_vma 0001001 ..... ..... 000 00000 1110011 @sfence_vma | 16 | |
21 | -sfence_vm 0001000 00100 ..... 000 00000 1110011 @sfence_vm | 17 | -# *** RV32H Base Instruction Set *** |
22 | 18 | +# *** RV64H Base Instruction Set *** | |
23 | # *** NMI *** | 19 | hlv_wu 0110100 00001 ..... 100 ..... 1110011 @r2 |
24 | mnret 0111000 00010 00000 000 00000 1110011 | 20 | hlv_d 0110110 00000 ..... 100 ..... 1110011 @r2 |
25 | diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc | 21 | hsv_d 0110111 ..... ..... 100 00000 1110011 @r2_s |
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/target/riscv/insn_trans/trans_privileged.c.inc | ||
28 | +++ b/target/riscv/insn_trans/trans_privileged.c.inc | ||
29 | @@ -XXX,XX +XXX,XX @@ static bool trans_sfence_vma(DisasContext *ctx, arg_sfence_vma *a) | ||
30 | #endif | ||
31 | return false; | ||
32 | } | ||
33 | - | ||
34 | -static bool trans_sfence_vm(DisasContext *ctx, arg_sfence_vm *a) | ||
35 | -{ | ||
36 | - return false; | ||
37 | -} | ||
38 | -- | 22 | -- |
39 | 2.48.1 | 23 | 2.31.1 |
24 | |||
25 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Rajnesh Kanwal <rkanwal@rivosinc.com> | ||
2 | 1 | ||
3 | Add a subsection to machine.c to migrate CTR CSR state | ||
4 | |||
5 | Signed-off-by: Rajnesh Kanwal <rkanwal@rivosinc.com> | ||
6 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
7 | Message-ID: <20250205-b4-ctr_upstream_v6-v6-6-439d8e06c8ef@rivosinc.com> | ||
8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | --- | ||
10 | target/riscv/machine.c | 25 +++++++++++++++++++++++++ | ||
11 | 1 file changed, 25 insertions(+) | ||
12 | |||
13 | diff --git a/target/riscv/machine.c b/target/riscv/machine.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/target/riscv/machine.c | ||
16 | +++ b/target/riscv/machine.c | ||
17 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_envcfg = { | ||
18 | } | ||
19 | }; | ||
20 | |||
21 | +static bool ctr_needed(void *opaque) | ||
22 | +{ | ||
23 | + RISCVCPU *cpu = opaque; | ||
24 | + | ||
25 | + return cpu->cfg.ext_smctr || cpu->cfg.ext_ssctr; | ||
26 | +} | ||
27 | + | ||
28 | +static const VMStateDescription vmstate_ctr = { | ||
29 | + .name = "cpu/ctr", | ||
30 | + .version_id = 1, | ||
31 | + .minimum_version_id = 1, | ||
32 | + .needed = ctr_needed, | ||
33 | + .fields = (const VMStateField[]) { | ||
34 | + VMSTATE_UINT64(env.mctrctl, RISCVCPU), | ||
35 | + VMSTATE_UINT32(env.sctrdepth, RISCVCPU), | ||
36 | + VMSTATE_UINT32(env.sctrstatus, RISCVCPU), | ||
37 | + VMSTATE_UINT64(env.vsctrctl, RISCVCPU), | ||
38 | + VMSTATE_UINT64_ARRAY(env.ctr_src, RISCVCPU, 16 << SCTRDEPTH_MAX), | ||
39 | + VMSTATE_UINT64_ARRAY(env.ctr_dst, RISCVCPU, 16 << SCTRDEPTH_MAX), | ||
40 | + VMSTATE_UINT64_ARRAY(env.ctr_data, RISCVCPU, 16 << SCTRDEPTH_MAX), | ||
41 | + VMSTATE_END_OF_LIST() | ||
42 | + } | ||
43 | +}; | ||
44 | + | ||
45 | static bool pmu_needed(void *opaque) | ||
46 | { | ||
47 | RISCVCPU *cpu = opaque; | ||
48 | @@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_riscv_cpu = { | ||
49 | &vmstate_jvt, | ||
50 | &vmstate_elp, | ||
51 | &vmstate_ssp, | ||
52 | + &vmstate_ctr, | ||
53 | NULL | ||
54 | } | ||
55 | }; | ||
56 | -- | ||
57 | 2.48.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Rob Bradford <rbradford@rivosinc.com> | ||
2 | 1 | ||
3 | Some extra spaces made into into the RISC-V opcode data table. | ||
4 | |||
5 | Signed-off-by: Rob Bradford <rbradford@rivosinc.com> | ||
6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
7 | Message-ID: <20250206153410.236636-2-rbradford@rivosinc.com> | ||
8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | --- | ||
10 | disas/riscv.c | 12 ++++++------ | ||
11 | 1 file changed, 6 insertions(+), 6 deletions(-) | ||
12 | |||
13 | diff --git a/disas/riscv.c b/disas/riscv.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/disas/riscv.c | ||
16 | +++ b/disas/riscv.c | ||
17 | @@ -XXX,XX +XXX,XX @@ const rv_opcode_data rvi_opcode_data[] = { | ||
18 | { "aes32esi", rv_codec_k_bs, rv_fmt_rs1_rs2_bs, NULL, 0, 0, 0 }, | ||
19 | { "aes32dsmi", rv_codec_k_bs, rv_fmt_rs1_rs2_bs, NULL, 0, 0, 0 }, | ||
20 | { "aes32dsi", rv_codec_k_bs, rv_fmt_rs1_rs2_bs, NULL, 0, 0, 0 }, | ||
21 | - { "aes64ks1i", rv_codec_k_rnum, rv_fmt_rd_rs1_rnum, NULL, 0, 0, 0 }, | ||
22 | + { "aes64ks1i", rv_codec_k_rnum, rv_fmt_rd_rs1_rnum, NULL, 0, 0, 0 }, | ||
23 | { "aes64ks2", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
24 | { "aes64im", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0 }, | ||
25 | { "aes64esm", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
26 | @@ -XXX,XX +XXX,XX @@ const rv_opcode_data rvi_opcode_data[] = { | ||
27 | { "mop.rr.5", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
28 | { "mop.rr.6", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
29 | { "mop.rr.7", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
30 | - { "c.mop.1", rv_codec_ci_none, rv_fmt_none, NULL, 0, 0, 0 }, | ||
31 | - { "c.mop.3", rv_codec_ci_none, rv_fmt_none, NULL, 0, 0, 0 }, | ||
32 | - { "c.mop.5", rv_codec_ci_none, rv_fmt_none, NULL, 0, 0, 0 }, | ||
33 | - { "c.mop.7", rv_codec_ci_none, rv_fmt_none, NULL, 0, 0, 0 }, | ||
34 | - { "c.mop.9", rv_codec_ci_none, rv_fmt_none, NULL, 0, 0, 0 }, | ||
35 | + { "c.mop.1", rv_codec_ci_none, rv_fmt_none, NULL, 0, 0, 0 }, | ||
36 | + { "c.mop.3", rv_codec_ci_none, rv_fmt_none, NULL, 0, 0, 0 }, | ||
37 | + { "c.mop.5", rv_codec_ci_none, rv_fmt_none, NULL, 0, 0, 0 }, | ||
38 | + { "c.mop.7", rv_codec_ci_none, rv_fmt_none, NULL, 0, 0, 0 }, | ||
39 | + { "c.mop.9", rv_codec_ci_none, rv_fmt_none, NULL, 0, 0, 0 }, | ||
40 | { "c.mop.11", rv_codec_ci_none, rv_fmt_none, NULL, 0, 0, 0 }, | ||
41 | { "c.mop.13", rv_codec_ci_none, rv_fmt_none, NULL, 0, 0, 0 }, | ||
42 | { "c.mop.15", rv_codec_ci_none, rv_fmt_none, NULL, 0, 0, 0 }, | ||
43 | -- | ||
44 | 2.48.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Rob Bradford <rbradford@rivosinc.com> | ||
2 | 1 | ||
3 | This reflects the latest frozen version of the RISC-V Debug | ||
4 | specification (1.0.0-rc4) which includes the Sdtrig extension. | ||
5 | |||
6 | Signed-off-by: Rob Bradford <rbradford@rivosinc.com> | ||
7 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Message-ID: <20250206153410.236636-3-rbradford@rivosinc.com> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | --- | ||
11 | disas/riscv.c | 4 +++- | ||
12 | 1 file changed, 3 insertions(+), 1 deletion(-) | ||
13 | |||
14 | diff --git a/disas/riscv.c b/disas/riscv.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/disas/riscv.c | ||
17 | +++ b/disas/riscv.c | ||
18 | @@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno) | ||
19 | case 0x07a1: return "tdata1"; | ||
20 | case 0x07a2: return "tdata2"; | ||
21 | case 0x07a3: return "tdata3"; | ||
22 | + case 0x07a4: return "tinfo"; | ||
23 | case 0x07b0: return "dcsr"; | ||
24 | case 0x07b1: return "dpc"; | ||
25 | - case 0x07b2: return "dscratch"; | ||
26 | + case 0x07b2: return "dscratch0"; | ||
27 | + case 0x07b3: return "dscratch1"; | ||
28 | case 0x0b00: return "mcycle"; | ||
29 | case 0x0b01: return "mtime"; | ||
30 | case 0x0b02: return "minstret"; | ||
31 | -- | ||
32 | 2.48.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
3 | Update headers to retrieve the latest KVM caps for RISC-V. | ||
4 | |||
5 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
6 | Message-ID: <20250221153758.652078-2-dbarboza@ventanamicro.com> | ||
7 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | --- | ||
9 | include/standard-headers/linux/ethtool.h | 4 + | ||
10 | include/standard-headers/linux/fuse.h | 76 ++++++++++++++++++- | ||
11 | .../linux/input-event-codes.h | 1 + | ||
12 | include/standard-headers/linux/pci_regs.h | 16 ++-- | ||
13 | include/standard-headers/linux/virtio_pci.h | 14 ++++ | ||
14 | linux-headers/asm-arm64/kvm.h | 3 - | ||
15 | linux-headers/asm-loongarch/kvm_para.h | 1 + | ||
16 | linux-headers/asm-riscv/kvm.h | 7 +- | ||
17 | linux-headers/asm-x86/kvm.h | 1 + | ||
18 | linux-headers/linux/iommufd.h | 35 ++++++--- | ||
19 | linux-headers/linux/kvm.h | 8 +- | ||
20 | linux-headers/linux/stddef.h | 13 +++- | ||
21 | linux-headers/linux/vduse.h | 2 +- | ||
22 | 13 files changed, 146 insertions(+), 35 deletions(-) | ||
23 | |||
24 | diff --git a/include/standard-headers/linux/ethtool.h b/include/standard-headers/linux/ethtool.h | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/include/standard-headers/linux/ethtool.h | ||
27 | +++ b/include/standard-headers/linux/ethtool.h | ||
28 | @@ -XXX,XX +XXX,XX @@ enum ethtool_link_ext_substate_module { | ||
29 | * @ETH_SS_STATS_ETH_MAC: names of IEEE 802.3 MAC statistics | ||
30 | * @ETH_SS_STATS_ETH_CTRL: names of IEEE 802.3 MAC Control statistics | ||
31 | * @ETH_SS_STATS_RMON: names of RMON statistics | ||
32 | + * @ETH_SS_STATS_PHY: names of PHY(dev) statistics | ||
33 | + * @ETH_SS_TS_FLAGS: hardware timestamping flags | ||
34 | * | ||
35 | * @ETH_SS_COUNT: number of defined string sets | ||
36 | */ | ||
37 | @@ -XXX,XX +XXX,XX @@ enum ethtool_stringset { | ||
38 | ETH_SS_STATS_ETH_MAC, | ||
39 | ETH_SS_STATS_ETH_CTRL, | ||
40 | ETH_SS_STATS_RMON, | ||
41 | + ETH_SS_STATS_PHY, | ||
42 | + ETH_SS_TS_FLAGS, | ||
43 | |||
44 | /* add new constants above here */ | ||
45 | ETH_SS_COUNT | ||
46 | diff --git a/include/standard-headers/linux/fuse.h b/include/standard-headers/linux/fuse.h | ||
47 | index XXXXXXX..XXXXXXX 100644 | ||
48 | --- a/include/standard-headers/linux/fuse.h | ||
49 | +++ b/include/standard-headers/linux/fuse.h | ||
50 | @@ -XXX,XX +XXX,XX @@ | ||
51 | * | ||
52 | * 7.41 | ||
53 | * - add FUSE_ALLOW_IDMAP | ||
54 | + * 7.42 | ||
55 | + * - Add FUSE_OVER_IO_URING and all other io-uring related flags and data | ||
56 | + * structures: | ||
57 | + * - struct fuse_uring_ent_in_out | ||
58 | + * - struct fuse_uring_req_header | ||
59 | + * - struct fuse_uring_cmd_req | ||
60 | + * - FUSE_URING_IN_OUT_HEADER_SZ | ||
61 | + * - FUSE_URING_OP_IN_OUT_SZ | ||
62 | + * - enum fuse_uring_cmd | ||
63 | */ | ||
64 | |||
65 | #ifndef _LINUX_FUSE_H | ||
66 | @@ -XXX,XX +XXX,XX @@ | ||
67 | #define FUSE_KERNEL_VERSION 7 | ||
68 | |||
69 | /** Minor version number of this interface */ | ||
70 | -#define FUSE_KERNEL_MINOR_VERSION 41 | ||
71 | +#define FUSE_KERNEL_MINOR_VERSION 42 | ||
72 | |||
73 | /** The node ID of the root inode */ | ||
74 | #define FUSE_ROOT_ID 1 | ||
75 | @@ -XXX,XX +XXX,XX @@ struct fuse_file_lock { | ||
76 | * FUSE_HAS_RESEND: kernel supports resending pending requests, and the high bit | ||
77 | * of the request ID indicates resend requests | ||
78 | * FUSE_ALLOW_IDMAP: allow creation of idmapped mounts | ||
79 | + * FUSE_OVER_IO_URING: Indicate that client supports io-uring | ||
80 | */ | ||
81 | #define FUSE_ASYNC_READ (1 << 0) | ||
82 | #define FUSE_POSIX_LOCKS (1 << 1) | ||
83 | @@ -XXX,XX +XXX,XX @@ struct fuse_file_lock { | ||
84 | /* Obsolete alias for FUSE_DIRECT_IO_ALLOW_MMAP */ | ||
85 | #define FUSE_DIRECT_IO_RELAX FUSE_DIRECT_IO_ALLOW_MMAP | ||
86 | #define FUSE_ALLOW_IDMAP (1ULL << 40) | ||
87 | +#define FUSE_OVER_IO_URING (1ULL << 41) | ||
88 | |||
89 | /** | ||
90 | * CUSE INIT request/reply flags | ||
91 | @@ -XXX,XX +XXX,XX @@ struct fuse_supp_groups { | ||
92 | uint32_t groups[]; | ||
93 | }; | ||
94 | |||
95 | +/** | ||
96 | + * Size of the ring buffer header | ||
97 | + */ | ||
98 | +#define FUSE_URING_IN_OUT_HEADER_SZ 128 | ||
99 | +#define FUSE_URING_OP_IN_OUT_SZ 128 | ||
100 | + | ||
101 | +/* Used as part of the fuse_uring_req_header */ | ||
102 | +struct fuse_uring_ent_in_out { | ||
103 | + uint64_t flags; | ||
104 | + | ||
105 | + /* | ||
106 | + * commit ID to be used in a reply to a ring request (see also | ||
107 | + * struct fuse_uring_cmd_req) | ||
108 | + */ | ||
109 | + uint64_t commit_id; | ||
110 | + | ||
111 | + /* size of user payload buffer */ | ||
112 | + uint32_t payload_sz; | ||
113 | + uint32_t padding; | ||
114 | + | ||
115 | + uint64_t reserved; | ||
116 | +}; | ||
117 | + | ||
118 | +/** | ||
119 | + * Header for all fuse-io-uring requests | ||
120 | + */ | ||
121 | +struct fuse_uring_req_header { | ||
122 | + /* struct fuse_in_header / struct fuse_out_header */ | ||
123 | + char in_out[FUSE_URING_IN_OUT_HEADER_SZ]; | ||
124 | + | ||
125 | + /* per op code header */ | ||
126 | + char op_in[FUSE_URING_OP_IN_OUT_SZ]; | ||
127 | + | ||
128 | + struct fuse_uring_ent_in_out ring_ent_in_out; | ||
129 | +}; | ||
130 | + | ||
131 | +/** | ||
132 | + * sqe commands to the kernel | ||
133 | + */ | ||
134 | +enum fuse_uring_cmd { | ||
135 | + FUSE_IO_URING_CMD_INVALID = 0, | ||
136 | + | ||
137 | + /* register the request buffer and fetch a fuse request */ | ||
138 | + FUSE_IO_URING_CMD_REGISTER = 1, | ||
139 | + | ||
140 | + /* commit fuse request result and fetch next request */ | ||
141 | + FUSE_IO_URING_CMD_COMMIT_AND_FETCH = 2, | ||
142 | +}; | ||
143 | + | ||
144 | +/** | ||
145 | + * In the 80B command area of the SQE. | ||
146 | + */ | ||
147 | +struct fuse_uring_cmd_req { | ||
148 | + uint64_t flags; | ||
149 | + | ||
150 | + /* entry identifier for commits */ | ||
151 | + uint64_t commit_id; | ||
152 | + | ||
153 | + /* queue the command is for (queue index) */ | ||
154 | + uint16_t qid; | ||
155 | + uint8_t padding[6]; | ||
156 | +}; | ||
157 | + | ||
158 | #endif /* _LINUX_FUSE_H */ | ||
159 | diff --git a/include/standard-headers/linux/input-event-codes.h b/include/standard-headers/linux/input-event-codes.h | ||
160 | index XXXXXXX..XXXXXXX 100644 | ||
161 | --- a/include/standard-headers/linux/input-event-codes.h | ||
162 | +++ b/include/standard-headers/linux/input-event-codes.h | ||
163 | @@ -XXX,XX +XXX,XX @@ | ||
164 | #define KEY_NOTIFICATION_CENTER 0x1bc /* Show/hide the notification center */ | ||
165 | #define KEY_PICKUP_PHONE 0x1bd /* Answer incoming call */ | ||
166 | #define KEY_HANGUP_PHONE 0x1be /* Decline incoming call */ | ||
167 | +#define KEY_LINK_PHONE 0x1bf /* AL Phone Syncing */ | ||
168 | |||
169 | #define KEY_DEL_EOL 0x1c0 | ||
170 | #define KEY_DEL_EOS 0x1c1 | ||
171 | diff --git a/include/standard-headers/linux/pci_regs.h b/include/standard-headers/linux/pci_regs.h | ||
172 | index XXXXXXX..XXXXXXX 100644 | ||
173 | --- a/include/standard-headers/linux/pci_regs.h | ||
174 | +++ b/include/standard-headers/linux/pci_regs.h | ||
175 | @@ -XXX,XX +XXX,XX @@ | ||
176 | #define PCI_EXP_DEVSTA_TRPND 0x0020 /* Transactions Pending */ | ||
177 | #define PCI_CAP_EXP_RC_ENDPOINT_SIZEOF_V1 12 /* v1 endpoints without link end here */ | ||
178 | #define PCI_EXP_LNKCAP 0x0c /* Link Capabilities */ | ||
179 | -#define PCI_EXP_LNKCAP_SLS 0x0000000f /* Supported Link Speeds */ | ||
180 | +#define PCI_EXP_LNKCAP_SLS 0x0000000f /* Max Link Speed (prior to PCIe r3.0: Supported Link Speeds) */ | ||
181 | #define PCI_EXP_LNKCAP_SLS_2_5GB 0x00000001 /* LNKCAP2 SLS Vector bit 0 */ | ||
182 | #define PCI_EXP_LNKCAP_SLS_5_0GB 0x00000002 /* LNKCAP2 SLS Vector bit 1 */ | ||
183 | #define PCI_EXP_LNKCAP_SLS_8_0GB 0x00000003 /* LNKCAP2 SLS Vector bit 2 */ | ||
184 | @@ -XXX,XX +XXX,XX @@ | ||
185 | #define PCI_EXP_DEVCAP2_OBFF_MSG 0x00040000 /* New message signaling */ | ||
186 | #define PCI_EXP_DEVCAP2_OBFF_WAKE 0x00080000 /* Re-use WAKE# for OBFF */ | ||
187 | #define PCI_EXP_DEVCAP2_EE_PREFIX 0x00200000 /* End-End TLP Prefix */ | ||
188 | +#define PCI_EXP_DEVCAP2_EE_PREFIX_MAX 0x00c00000 /* Max End-End TLP Prefixes */ | ||
189 | #define PCI_EXP_DEVCTL2 0x28 /* Device Control 2 */ | ||
190 | #define PCI_EXP_DEVCTL2_COMP_TIMEOUT 0x000f /* Completion Timeout Value */ | ||
191 | #define PCI_EXP_DEVCTL2_COMP_TMOUT_DIS 0x0010 /* Completion Timeout Disable */ | ||
192 | @@ -XXX,XX +XXX,XX @@ | ||
193 | /* Same bits as above */ | ||
194 | #define PCI_ERR_CAP 0x18 /* Advanced Error Capabilities & Ctrl*/ | ||
195 | #define PCI_ERR_CAP_FEP(x) ((x) & 0x1f) /* First Error Pointer */ | ||
196 | -#define PCI_ERR_CAP_ECRC_GENC 0x00000020 /* ECRC Generation Capable */ | ||
197 | -#define PCI_ERR_CAP_ECRC_GENE 0x00000040 /* ECRC Generation Enable */ | ||
198 | -#define PCI_ERR_CAP_ECRC_CHKC 0x00000080 /* ECRC Check Capable */ | ||
199 | -#define PCI_ERR_CAP_ECRC_CHKE 0x00000100 /* ECRC Check Enable */ | ||
200 | +#define PCI_ERR_CAP_ECRC_GENC 0x00000020 /* ECRC Generation Capable */ | ||
201 | +#define PCI_ERR_CAP_ECRC_GENE 0x00000040 /* ECRC Generation Enable */ | ||
202 | +#define PCI_ERR_CAP_ECRC_CHKC 0x00000080 /* ECRC Check Capable */ | ||
203 | +#define PCI_ERR_CAP_ECRC_CHKE 0x00000100 /* ECRC Check Enable */ | ||
204 | +#define PCI_ERR_CAP_PREFIX_LOG_PRESENT 0x00000800 /* TLP Prefix Log Present */ | ||
205 | #define PCI_ERR_HEADER_LOG 0x1c /* Header Log Register (16 bytes) */ | ||
206 | #define PCI_ERR_ROOT_COMMAND 0x2c /* Root Error Command */ | ||
207 | #define PCI_ERR_ROOT_CMD_COR_EN 0x00000001 /* Correctable Err Reporting Enable */ | ||
208 | @@ -XXX,XX +XXX,XX @@ | ||
209 | #define PCI_ERR_ROOT_FATAL_RCV 0x00000040 /* Fatal Received */ | ||
210 | #define PCI_ERR_ROOT_AER_IRQ 0xf8000000 /* Advanced Error Interrupt Message Number */ | ||
211 | #define PCI_ERR_ROOT_ERR_SRC 0x34 /* Error Source Identification */ | ||
212 | +#define PCI_ERR_PREFIX_LOG 0x38 /* TLP Prefix LOG Register (up to 16 bytes) */ | ||
213 | |||
214 | /* Virtual Channel */ | ||
215 | #define PCI_VC_PORT_CAP1 0x04 | ||
216 | @@ -XXX,XX +XXX,XX @@ | ||
217 | #define PCI_ACS_CTRL 0x06 /* ACS Control Register */ | ||
218 | #define PCI_ACS_EGRESS_CTL_V 0x08 /* ACS Egress Control Vector */ | ||
219 | |||
220 | -#define PCI_VSEC_HDR 4 /* extended cap - vendor-specific */ | ||
221 | -#define PCI_VSEC_HDR_LEN_SHIFT 20 /* shift for length field */ | ||
222 | - | ||
223 | /* SATA capability */ | ||
224 | #define PCI_SATA_REGS 4 /* SATA REGs specifier */ | ||
225 | #define PCI_SATA_REGS_MASK 0xF /* location - BAR#/inline */ | ||
226 | diff --git a/include/standard-headers/linux/virtio_pci.h b/include/standard-headers/linux/virtio_pci.h | ||
227 | index XXXXXXX..XXXXXXX 100644 | ||
228 | --- a/include/standard-headers/linux/virtio_pci.h | ||
229 | +++ b/include/standard-headers/linux/virtio_pci.h | ||
230 | @@ -XXX,XX +XXX,XX @@ | ||
231 | #define VIRTIO_PCI_CAP_PCI_CFG 5 | ||
232 | /* Additional shared memory capability */ | ||
233 | #define VIRTIO_PCI_CAP_SHARED_MEMORY_CFG 8 | ||
234 | +/* PCI vendor data configuration */ | ||
235 | +#define VIRTIO_PCI_CAP_VENDOR_CFG 9 | ||
236 | |||
237 | /* This is the PCI capability header: */ | ||
238 | struct virtio_pci_cap { | ||
239 | @@ -XXX,XX +XXX,XX @@ struct virtio_pci_cap { | ||
240 | uint32_t length; /* Length of the structure, in bytes. */ | ||
241 | }; | ||
242 | |||
243 | +/* This is the PCI vendor data capability header: */ | ||
244 | +struct virtio_pci_vndr_data { | ||
245 | + uint8_t cap_vndr; /* Generic PCI field: PCI_CAP_ID_VNDR */ | ||
246 | + uint8_t cap_next; /* Generic PCI field: next ptr. */ | ||
247 | + uint8_t cap_len; /* Generic PCI field: capability length */ | ||
248 | + uint8_t cfg_type; /* Identifies the structure. */ | ||
249 | + uint16_t vendor_id; /* Identifies the vendor-specific format. */ | ||
250 | + /* For Vendor Definition */ | ||
251 | + /* Pads structure to a multiple of 4 bytes */ | ||
252 | + /* Reads must not have side effects */ | ||
253 | +}; | ||
254 | + | ||
255 | struct virtio_pci_cap64 { | ||
256 | struct virtio_pci_cap cap; | ||
257 | uint32_t offset_hi; /* Most sig 32 bits of offset */ | ||
258 | diff --git a/linux-headers/asm-arm64/kvm.h b/linux-headers/asm-arm64/kvm.h | ||
259 | index XXXXXXX..XXXXXXX 100644 | ||
260 | --- a/linux-headers/asm-arm64/kvm.h | ||
261 | +++ b/linux-headers/asm-arm64/kvm.h | ||
262 | @@ -XXX,XX +XXX,XX @@ | ||
263 | #define KVM_COALESCED_MMIO_PAGE_OFFSET 1 | ||
264 | #define KVM_DIRTY_LOG_PAGE_OFFSET 64 | ||
265 | |||
266 | -#define KVM_REG_SIZE(id) \ | ||
267 | - (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT)) | ||
268 | - | ||
269 | struct kvm_regs { | ||
270 | struct user_pt_regs regs; /* sp = sp_el0 */ | ||
271 | |||
272 | diff --git a/linux-headers/asm-loongarch/kvm_para.h b/linux-headers/asm-loongarch/kvm_para.h | ||
273 | index XXXXXXX..XXXXXXX 100644 | ||
274 | --- a/linux-headers/asm-loongarch/kvm_para.h | ||
275 | +++ b/linux-headers/asm-loongarch/kvm_para.h | ||
276 | @@ -XXX,XX +XXX,XX @@ | ||
277 | #define KVM_FEATURE_STEAL_TIME 2 | ||
278 | /* BIT 24 - 31 are features configurable by user space vmm */ | ||
279 | #define KVM_FEATURE_VIRT_EXTIOI 24 | ||
280 | +#define KVM_FEATURE_USER_HCALL 25 | ||
281 | |||
282 | #endif /* _ASM_KVM_PARA_H */ | ||
283 | diff --git a/linux-headers/asm-riscv/kvm.h b/linux-headers/asm-riscv/kvm.h | ||
284 | index XXXXXXX..XXXXXXX 100644 | ||
285 | --- a/linux-headers/asm-riscv/kvm.h | ||
286 | +++ b/linux-headers/asm-riscv/kvm.h | ||
287 | @@ -XXX,XX +XXX,XX @@ enum KVM_RISCV_ISA_EXT_ID { | ||
288 | KVM_RISCV_ISA_EXT_SSNPM, | ||
289 | KVM_RISCV_ISA_EXT_SVADE, | ||
290 | KVM_RISCV_ISA_EXT_SVADU, | ||
291 | + KVM_RISCV_ISA_EXT_SVVPTC, | ||
292 | + KVM_RISCV_ISA_EXT_ZABHA, | ||
293 | + KVM_RISCV_ISA_EXT_ZICCRSE, | ||
294 | KVM_RISCV_ISA_EXT_MAX, | ||
295 | }; | ||
296 | |||
297 | @@ -XXX,XX +XXX,XX @@ enum KVM_RISCV_SBI_EXT_ID { | ||
298 | KVM_RISCV_SBI_EXT_VENDOR, | ||
299 | KVM_RISCV_SBI_EXT_DBCN, | ||
300 | KVM_RISCV_SBI_EXT_STA, | ||
301 | + KVM_RISCV_SBI_EXT_SUSP, | ||
302 | KVM_RISCV_SBI_EXT_MAX, | ||
303 | }; | ||
304 | |||
305 | @@ -XXX,XX +XXX,XX @@ struct kvm_riscv_sbi_sta { | ||
306 | #define KVM_RISCV_TIMER_STATE_OFF 0 | ||
307 | #define KVM_RISCV_TIMER_STATE_ON 1 | ||
308 | |||
309 | -#define KVM_REG_SIZE(id) \ | ||
310 | - (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT)) | ||
311 | - | ||
312 | /* If you need to interpret the index values, here is the key: */ | ||
313 | #define KVM_REG_RISCV_TYPE_MASK 0x00000000FF000000 | ||
314 | #define KVM_REG_RISCV_TYPE_SHIFT 24 | ||
315 | diff --git a/linux-headers/asm-x86/kvm.h b/linux-headers/asm-x86/kvm.h | ||
316 | index XXXXXXX..XXXXXXX 100644 | ||
317 | --- a/linux-headers/asm-x86/kvm.h | ||
318 | +++ b/linux-headers/asm-x86/kvm.h | ||
319 | @@ -XXX,XX +XXX,XX @@ struct kvm_hyperv_eventfd { | ||
320 | #define KVM_X86_SEV_VM 2 | ||
321 | #define KVM_X86_SEV_ES_VM 3 | ||
322 | #define KVM_X86_SNP_VM 4 | ||
323 | +#define KVM_X86_TDX_VM 5 | ||
324 | |||
325 | #endif /* _ASM_X86_KVM_H */ | ||
326 | diff --git a/linux-headers/linux/iommufd.h b/linux-headers/linux/iommufd.h | ||
327 | index XXXXXXX..XXXXXXX 100644 | ||
328 | --- a/linux-headers/linux/iommufd.h | ||
329 | +++ b/linux-headers/linux/iommufd.h | ||
330 | @@ -XXX,XX +XXX,XX @@ struct iommu_ioas_unmap { | ||
331 | * ioctl(IOMMU_OPTION_HUGE_PAGES) | ||
332 | * @IOMMU_OPTION_RLIMIT_MODE: | ||
333 | * Change how RLIMIT_MEMLOCK accounting works. The caller must have privilege | ||
334 | - * to invoke this. Value 0 (default) is user based accouting, 1 uses process | ||
335 | + * to invoke this. Value 0 (default) is user based accounting, 1 uses process | ||
336 | * based accounting. Global option, object_id must be 0 | ||
337 | * @IOMMU_OPTION_HUGE_PAGES: | ||
338 | * Value 1 (default) allows contiguous pages to be combined when generating | ||
339 | @@ -XXX,XX +XXX,XX @@ struct iommu_vfio_ioas { | ||
340 | * @IOMMU_HWPT_ALLOC_PASID: Requests a domain that can be used with PASID. The | ||
341 | * domain can be attached to any PASID on the device. | ||
342 | * Any domain attached to the non-PASID part of the | ||
343 | - * device must also be flaged, otherwise attaching a | ||
344 | + * device must also be flagged, otherwise attaching a | ||
345 | * PASID will blocked. | ||
346 | * If IOMMU does not support PASID it will return | ||
347 | * error (-EOPNOTSUPP). | ||
348 | @@ -XXX,XX +XXX,XX @@ struct iommu_hw_info_vtd { | ||
349 | * For the details of @idr, @iidr and @aidr, please refer to the chapters | ||
350 | * from 6.3.1 to 6.3.6 in the SMMUv3 Spec. | ||
351 | * | ||
352 | - * User space should read the underlying ARM SMMUv3 hardware information for | ||
353 | - * the list of supported features. | ||
354 | + * This reports the raw HW capability, and not all bits are meaningful to be | ||
355 | + * read by userspace. Only the following fields should be used: | ||
356 | * | ||
357 | - * Note that these values reflect the raw HW capability, without any insight if | ||
358 | - * any required kernel driver support is present. Bits may be set indicating the | ||
359 | - * HW has functionality that is lacking kernel software support, such as BTM. If | ||
360 | - * a VMM is using this information to construct emulated copies of these | ||
361 | - * registers it should only forward bits that it knows it can support. | ||
362 | + * idr[0]: ST_LEVEL, TERM_MODEL, STALL_MODEL, TTENDIAN , CD2L, ASID16, TTF | ||
363 | + * idr[1]: SIDSIZE, SSIDSIZE | ||
364 | + * idr[3]: BBML, RIL | ||
365 | + * idr[5]: VAX, GRAN64K, GRAN16K, GRAN4K | ||
366 | * | ||
367 | - * In future, presence of required kernel support will be indicated in flags. | ||
368 | + * - S1P should be assumed to be true if a NESTED HWPT can be created | ||
369 | + * - VFIO/iommufd only support platforms with COHACC, it should be assumed to be | ||
370 | + * true. | ||
371 | + * - ATS is a per-device property. If the VMM describes any devices as ATS | ||
372 | + * capable in ACPI/DT it should set the corresponding idr. | ||
373 | + * | ||
374 | + * This list may expand in future (eg E0PD, AIE, PBHA, D128, DS etc). It is | ||
375 | + * important that VMMs do not read bits outside the list to allow for | ||
376 | + * compatibility with future kernels. Several features in the SMMUv3 | ||
377 | + * architecture are not currently supported by the kernel for nesting: HTTU, | ||
378 | + * BTM, MPAM and others. | ||
379 | */ | ||
380 | struct iommu_hw_info_arm_smmuv3 { | ||
381 | __u32 flags; | ||
382 | @@ -XXX,XX +XXX,XX @@ struct iommu_hwpt_vtd_s1_invalidate { | ||
383 | }; | ||
384 | |||
385 | /** | ||
386 | - * struct iommu_viommu_arm_smmuv3_invalidate - ARM SMMUv3 cahce invalidation | ||
387 | + * struct iommu_viommu_arm_smmuv3_invalidate - ARM SMMUv3 cache invalidation | ||
388 | * (IOMMU_VIOMMU_INVALIDATE_DATA_ARM_SMMUV3) | ||
389 | * @cmd: 128-bit cache invalidation command that runs in SMMU CMDQ. | ||
390 | * Must be little-endian. | ||
391 | @@ -XXX,XX +XXX,XX @@ enum iommu_hwpt_pgfault_perm { | ||
392 | * @pasid: Process Address Space ID | ||
393 | * @grpid: Page Request Group Index | ||
394 | * @perm: Combination of enum iommu_hwpt_pgfault_perm | ||
395 | + * @__reserved: Must be 0. | ||
396 | * @addr: Fault address | ||
397 | * @length: a hint of how much data the requestor is expecting to fetch. For | ||
398 | * example, if the PRI initiator knows it is going to do a 10MB | ||
399 | @@ -XXX,XX +XXX,XX @@ struct iommu_hwpt_pgfault { | ||
400 | __u32 pasid; | ||
401 | __u32 grpid; | ||
402 | __u32 perm; | ||
403 | - __u64 addr; | ||
404 | + __u32 __reserved; | ||
405 | + __aligned_u64 addr; | ||
406 | __u32 length; | ||
407 | __u32 cookie; | ||
408 | }; | ||
409 | diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h | ||
410 | index XXXXXXX..XXXXXXX 100644 | ||
411 | --- a/linux-headers/linux/kvm.h | ||
412 | +++ b/linux-headers/linux/kvm.h | ||
413 | @@ -XXX,XX +XXX,XX @@ struct kvm_ioeventfd { | ||
414 | #define KVM_X86_DISABLE_EXITS_HLT (1 << 1) | ||
415 | #define KVM_X86_DISABLE_EXITS_PAUSE (1 << 2) | ||
416 | #define KVM_X86_DISABLE_EXITS_CSTATE (1 << 3) | ||
417 | -#define KVM_X86_DISABLE_VALID_EXITS (KVM_X86_DISABLE_EXITS_MWAIT | \ | ||
418 | - KVM_X86_DISABLE_EXITS_HLT | \ | ||
419 | - KVM_X86_DISABLE_EXITS_PAUSE | \ | ||
420 | - KVM_X86_DISABLE_EXITS_CSTATE) | ||
421 | |||
422 | /* for KVM_ENABLE_CAP */ | ||
423 | struct kvm_enable_cap { | ||
424 | @@ -XXX,XX +XXX,XX @@ struct kvm_dirty_tlb { | ||
425 | |||
426 | #define KVM_REG_SIZE_SHIFT 52 | ||
427 | #define KVM_REG_SIZE_MASK 0x00f0000000000000ULL | ||
428 | + | ||
429 | +#define KVM_REG_SIZE(id) \ | ||
430 | + (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT)) | ||
431 | + | ||
432 | #define KVM_REG_SIZE_U8 0x0000000000000000ULL | ||
433 | #define KVM_REG_SIZE_U16 0x0010000000000000ULL | ||
434 | #define KVM_REG_SIZE_U32 0x0020000000000000ULL | ||
435 | diff --git a/linux-headers/linux/stddef.h b/linux-headers/linux/stddef.h | ||
436 | index XXXXXXX..XXXXXXX 100644 | ||
437 | --- a/linux-headers/linux/stddef.h | ||
438 | +++ b/linux-headers/linux/stddef.h | ||
439 | @@ -XXX,XX +XXX,XX @@ | ||
440 | #define __always_inline __inline__ | ||
441 | #endif | ||
442 | |||
443 | +/* Not all C++ standards support type declarations inside an anonymous union */ | ||
444 | +#ifndef __cplusplus | ||
445 | +#define __struct_group_tag(TAG) TAG | ||
446 | +#else | ||
447 | +#define __struct_group_tag(TAG) | ||
448 | +#endif | ||
449 | + | ||
450 | /** | ||
451 | * __struct_group() - Create a mirrored named and anonyomous struct | ||
452 | * | ||
453 | @@ -XXX,XX +XXX,XX @@ | ||
454 | * and size: one anonymous and one named. The former's members can be used | ||
455 | * normally without sub-struct naming, and the latter can be used to | ||
456 | * reason about the start, end, and size of the group of struct members. | ||
457 | - * The named struct can also be explicitly tagged for layer reuse, as well | ||
458 | - * as both having struct attributes appended. | ||
459 | + * The named struct can also be explicitly tagged for layer reuse (C only), | ||
460 | + * as well as both having struct attributes appended. | ||
461 | */ | ||
462 | #define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \ | ||
463 | union { \ | ||
464 | struct { MEMBERS } ATTRS; \ | ||
465 | - struct TAG { MEMBERS } ATTRS NAME; \ | ||
466 | + struct __struct_group_tag(TAG) { MEMBERS } ATTRS NAME; \ | ||
467 | } ATTRS | ||
468 | |||
469 | #ifdef __cplusplus | ||
470 | diff --git a/linux-headers/linux/vduse.h b/linux-headers/linux/vduse.h | ||
471 | index XXXXXXX..XXXXXXX 100644 | ||
472 | --- a/linux-headers/linux/vduse.h | ||
473 | +++ b/linux-headers/linux/vduse.h | ||
474 | @@ -XXX,XX +XXX,XX @@ | ||
475 | -/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ | ||
476 | +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ | ||
477 | #ifndef _VDUSE_H_ | ||
478 | #define _VDUSE_H_ | ||
479 | |||
480 | -- | ||
481 | 2.48.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
3 | Expose ziccrse, zabha and svvptc. | ||
4 | |||
5 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
6 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
7 | Message-ID: <20250221153758.652078-4-dbarboza@ventanamicro.com> | ||
8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | --- | ||
10 | target/riscv/kvm/kvm-cpu.c | 3 +++ | ||
11 | 1 file changed, 3 insertions(+) | ||
12 | |||
13 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/target/riscv/kvm/kvm-cpu.c | ||
16 | +++ b/target/riscv/kvm/kvm-cpu.c | ||
17 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_update_cpu_misa_ext(RISCVCPU *cpu, CPUState *cs) | ||
18 | static KVMCPUConfig kvm_multi_ext_cfgs[] = { | ||
19 | KVM_EXT_CFG("zicbom", ext_zicbom, KVM_RISCV_ISA_EXT_ZICBOM), | ||
20 | KVM_EXT_CFG("zicboz", ext_zicboz, KVM_RISCV_ISA_EXT_ZICBOZ), | ||
21 | + KVM_EXT_CFG("ziccrse", ext_ziccrse, KVM_RISCV_ISA_EXT_ZICCRSE), | ||
22 | KVM_EXT_CFG("zicntr", ext_zicntr, KVM_RISCV_ISA_EXT_ZICNTR), | ||
23 | KVM_EXT_CFG("zicond", ext_zicond, KVM_RISCV_ISA_EXT_ZICOND), | ||
24 | KVM_EXT_CFG("zicsr", ext_zicsr, KVM_RISCV_ISA_EXT_ZICSR), | ||
25 | @@ -XXX,XX +XXX,XX @@ static KVMCPUConfig kvm_multi_ext_cfgs[] = { | ||
26 | KVM_EXT_CFG("zihpm", ext_zihpm, KVM_RISCV_ISA_EXT_ZIHPM), | ||
27 | KVM_EXT_CFG("zimop", ext_zimop, KVM_RISCV_ISA_EXT_ZIMOP), | ||
28 | KVM_EXT_CFG("zcmop", ext_zcmop, KVM_RISCV_ISA_EXT_ZCMOP), | ||
29 | + KVM_EXT_CFG("zabha", ext_zabha, KVM_RISCV_ISA_EXT_ZABHA), | ||
30 | KVM_EXT_CFG("zacas", ext_zacas, KVM_RISCV_ISA_EXT_ZACAS), | ||
31 | KVM_EXT_CFG("zawrs", ext_zawrs, KVM_RISCV_ISA_EXT_ZAWRS), | ||
32 | KVM_EXT_CFG("zfa", ext_zfa, KVM_RISCV_ISA_EXT_ZFA), | ||
33 | @@ -XXX,XX +XXX,XX @@ static KVMCPUConfig kvm_multi_ext_cfgs[] = { | ||
34 | KVM_EXT_CFG("svinval", ext_svinval, KVM_RISCV_ISA_EXT_SVINVAL), | ||
35 | KVM_EXT_CFG("svnapot", ext_svnapot, KVM_RISCV_ISA_EXT_SVNAPOT), | ||
36 | KVM_EXT_CFG("svpbmt", ext_svpbmt, KVM_RISCV_ISA_EXT_SVPBMT), | ||
37 | + KVM_EXT_CFG("svvptc", ext_svvptc, KVM_RISCV_ISA_EXT_SVVPTC), | ||
38 | }; | ||
39 | |||
40 | static void *kvmconfig_get_cfg_addr(RISCVCPU *cpu, KVMCPUConfig *kvmcfg) | ||
41 | -- | ||
42 | 2.48.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Tomasz Jeznach <tjeznach@rivosinc.com> | ||
2 | 1 | ||
3 | Add the relevant HPM (High Performance Monitor) bits that we'll be using | ||
4 | in the next patches. | ||
5 | |||
6 | Signed-off-by: Tomasz Jeznach <tjeznach@rivosinc.com> | ||
7 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
8 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | Message-ID: <20250224190826.1858473-3-dbarboza@ventanamicro.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | --- | ||
12 | hw/riscv/riscv-iommu-bits.h | 47 +++++++++++++++++++++++++++++++++++++ | ||
13 | 1 file changed, 47 insertions(+) | ||
14 | |||
15 | diff --git a/hw/riscv/riscv-iommu-bits.h b/hw/riscv/riscv-iommu-bits.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/hw/riscv/riscv-iommu-bits.h | ||
18 | +++ b/hw/riscv/riscv-iommu-bits.h | ||
19 | @@ -XXX,XX +XXX,XX @@ struct riscv_iommu_pq_record { | ||
20 | #define RISCV_IOMMU_CAP_ATS BIT_ULL(25) | ||
21 | #define RISCV_IOMMU_CAP_T2GPA BIT_ULL(26) | ||
22 | #define RISCV_IOMMU_CAP_IGS GENMASK_ULL(29, 28) | ||
23 | +#define RISCV_IOMMU_CAP_HPM BIT_ULL(30) | ||
24 | #define RISCV_IOMMU_CAP_DBG BIT_ULL(31) | ||
25 | #define RISCV_IOMMU_CAP_PAS GENMASK_ULL(37, 32) | ||
26 | #define RISCV_IOMMU_CAP_PD8 BIT_ULL(38) | ||
27 | @@ -XXX,XX +XXX,XX @@ enum { | ||
28 | RISCV_IOMMU_INTR_COUNT | ||
29 | }; | ||
30 | |||
31 | +#define RISCV_IOMMU_IOCOUNT_NUM 31 | ||
32 | + | ||
33 | +/* 5.19 Performance monitoring counter overflow status (32bits) */ | ||
34 | +#define RISCV_IOMMU_REG_IOCOUNTOVF 0x0058 | ||
35 | +#define RISCV_IOMMU_IOCOUNTOVF_CY BIT(0) | ||
36 | + | ||
37 | +/* 5.20 Performance monitoring counter inhibits (32bits) */ | ||
38 | +#define RISCV_IOMMU_REG_IOCOUNTINH 0x005C | ||
39 | +#define RISCV_IOMMU_IOCOUNTINH_CY BIT(0) | ||
40 | + | ||
41 | +/* 5.21 Performance monitoring cycles counter (64bits) */ | ||
42 | +#define RISCV_IOMMU_REG_IOHPMCYCLES 0x0060 | ||
43 | +#define RISCV_IOMMU_IOHPMCYCLES_COUNTER GENMASK_ULL(62, 0) | ||
44 | +#define RISCV_IOMMU_IOHPMCYCLES_OVF BIT_ULL(63) | ||
45 | + | ||
46 | +/* 5.22 Performance monitoring event counters (31 * 64bits) */ | ||
47 | +#define RISCV_IOMMU_REG_IOHPMCTR_BASE 0x0068 | ||
48 | +#define RISCV_IOMMU_REG_IOHPMCTR(_n) \ | ||
49 | + (RISCV_IOMMU_REG_IOHPMCTR_BASE + (_n * 0x8)) | ||
50 | + | ||
51 | +/* 5.23 Performance monitoring event selectors (31 * 64bits) */ | ||
52 | +#define RISCV_IOMMU_REG_IOHPMEVT_BASE 0x0160 | ||
53 | +#define RISCV_IOMMU_REG_IOHPMEVT(_n) \ | ||
54 | + (RISCV_IOMMU_REG_IOHPMEVT_BASE + (_n * 0x8)) | ||
55 | +#define RISCV_IOMMU_IOHPMEVT_EVENT_ID GENMASK_ULL(14, 0) | ||
56 | +#define RISCV_IOMMU_IOHPMEVT_DMASK BIT_ULL(15) | ||
57 | +#define RISCV_IOMMU_IOHPMEVT_PID_PSCID GENMASK_ULL(35, 16) | ||
58 | +#define RISCV_IOMMU_IOHPMEVT_DID_GSCID GENMASK_ULL(59, 36) | ||
59 | +#define RISCV_IOMMU_IOHPMEVT_PV_PSCV BIT_ULL(60) | ||
60 | +#define RISCV_IOMMU_IOHPMEVT_DV_GSCV BIT_ULL(61) | ||
61 | +#define RISCV_IOMMU_IOHPMEVT_IDT BIT_ULL(62) | ||
62 | +#define RISCV_IOMMU_IOHPMEVT_OF BIT_ULL(63) | ||
63 | + | ||
64 | +enum RISCV_IOMMU_HPMEVENT_id { | ||
65 | + RISCV_IOMMU_HPMEVENT_INVALID = 0, | ||
66 | + RISCV_IOMMU_HPMEVENT_URQ = 1, | ||
67 | + RISCV_IOMMU_HPMEVENT_TRQ = 2, | ||
68 | + RISCV_IOMMU_HPMEVENT_ATS_RQ = 3, | ||
69 | + RISCV_IOMMU_HPMEVENT_TLB_MISS = 4, | ||
70 | + RISCV_IOMMU_HPMEVENT_DD_WALK = 5, | ||
71 | + RISCV_IOMMU_HPMEVENT_PD_WALK = 6, | ||
72 | + RISCV_IOMMU_HPMEVENT_S_VS_WALKS = 7, | ||
73 | + RISCV_IOMMU_HPMEVENT_G_WALKS = 8, | ||
74 | + RISCV_IOMMU_HPMEVENT_MAX = 9 | ||
75 | +}; | ||
76 | + | ||
77 | /* 5.24 Translation request IOVA (64bits) */ | ||
78 | #define RISCV_IOMMU_REG_TR_REQ_IOVA 0x0258 | ||
79 | |||
80 | -- | ||
81 | 2.48.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Tomasz Jeznach <tjeznach@rivosinc.com> | ||
2 | 1 | ||
3 | The next HPM related changes requires the HPM overflow timer to be | ||
4 | initialized by the riscv-iommu base emulation. | ||
5 | |||
6 | Signed-off-by: Tomasz Jeznach <tjeznach@rivosinc.com> | ||
7 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
8 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | Message-ID: <20250224190826.1858473-6-dbarboza@ventanamicro.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | --- | ||
12 | hw/riscv/riscv-iommu-hpm.h | 1 + | ||
13 | hw/riscv/riscv-iommu.h | 2 ++ | ||
14 | hw/riscv/riscv-iommu-hpm.c | 36 ++++++++++++++++++++++++++++++++++++ | ||
15 | hw/riscv/riscv-iommu.c | 3 +++ | ||
16 | 4 files changed, 42 insertions(+) | ||
17 | |||
18 | diff --git a/hw/riscv/riscv-iommu-hpm.h b/hw/riscv/riscv-iommu-hpm.h | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/hw/riscv/riscv-iommu-hpm.h | ||
21 | +++ b/hw/riscv/riscv-iommu-hpm.h | ||
22 | @@ -XXX,XX +XXX,XX @@ | ||
23 | uint64_t riscv_iommu_hpmcycle_read(RISCVIOMMUState *s); | ||
24 | void riscv_iommu_hpm_incr_ctr(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, | ||
25 | unsigned event_id); | ||
26 | +void riscv_iommu_hpm_timer_cb(void *priv); | ||
27 | |||
28 | #endif | ||
29 | diff --git a/hw/riscv/riscv-iommu.h b/hw/riscv/riscv-iommu.h | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/hw/riscv/riscv-iommu.h | ||
32 | +++ b/hw/riscv/riscv-iommu.h | ||
33 | @@ -XXX,XX +XXX,XX @@ struct RISCVIOMMUState { | ||
34 | QLIST_HEAD(, RISCVIOMMUSpace) spaces; | ||
35 | |||
36 | /* HPM cycle counter */ | ||
37 | + QEMUTimer *hpm_timer; | ||
38 | uint64_t hpmcycle_val; /* Current value of cycle register */ | ||
39 | uint64_t hpmcycle_prev; /* Saved value of QEMU_CLOCK_VIRTUAL clock */ | ||
40 | + uint64_t irq_overflow_left; /* Value beyond INT64_MAX after overflow */ | ||
41 | |||
42 | /* HPM event counters */ | ||
43 | GHashTable *hpm_event_ctr_map; /* Mapping of events to counters */ | ||
44 | diff --git a/hw/riscv/riscv-iommu-hpm.c b/hw/riscv/riscv-iommu-hpm.c | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/hw/riscv/riscv-iommu-hpm.c | ||
47 | +++ b/hw/riscv/riscv-iommu-hpm.c | ||
48 | @@ -XXX,XX +XXX,XX @@ void riscv_iommu_hpm_incr_ctr(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, | ||
49 | hpm_incr_ctr(s, ctr_idx); | ||
50 | } | ||
51 | } | ||
52 | + | ||
53 | +/* Timer callback for cycle counter overflow. */ | ||
54 | +void riscv_iommu_hpm_timer_cb(void *priv) | ||
55 | +{ | ||
56 | + RISCVIOMMUState *s = priv; | ||
57 | + const uint32_t inhibit = riscv_iommu_reg_get32( | ||
58 | + s, RISCV_IOMMU_REG_IOCOUNTINH); | ||
59 | + uint32_t ovf; | ||
60 | + | ||
61 | + if (get_field(inhibit, RISCV_IOMMU_IOCOUNTINH_CY)) { | ||
62 | + return; | ||
63 | + } | ||
64 | + | ||
65 | + if (s->irq_overflow_left > 0) { | ||
66 | + uint64_t irq_trigger_at = | ||
67 | + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + s->irq_overflow_left; | ||
68 | + timer_mod_anticipate_ns(s->hpm_timer, irq_trigger_at); | ||
69 | + s->irq_overflow_left = 0; | ||
70 | + return; | ||
71 | + } | ||
72 | + | ||
73 | + ovf = riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_IOCOUNTOVF); | ||
74 | + if (!get_field(ovf, RISCV_IOMMU_IOCOUNTOVF_CY)) { | ||
75 | + /* | ||
76 | + * We don't need to set hpmcycle_val to zero and update hpmcycle_prev to | ||
77 | + * current clock value. The way we calculate iohpmcycs will overflow | ||
78 | + * and return the correct value. This avoids the need to synchronize | ||
79 | + * timer callback and write callback. | ||
80 | + */ | ||
81 | + riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_IOCOUNTOVF, | ||
82 | + RISCV_IOMMU_IOCOUNTOVF_CY, 0); | ||
83 | + riscv_iommu_reg_mod64(s, RISCV_IOMMU_REG_IOHPMCYCLES, | ||
84 | + RISCV_IOMMU_IOHPMCYCLES_OVF, 0); | ||
85 | + riscv_iommu_notify(s, RISCV_IOMMU_INTR_PM); | ||
86 | + } | ||
87 | +} | ||
88 | diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c | ||
89 | index XXXXXXX..XXXXXXX 100644 | ||
90 | --- a/hw/riscv/riscv-iommu.c | ||
91 | +++ b/hw/riscv/riscv-iommu.c | ||
92 | @@ -XXX,XX +XXX,XX @@ static void riscv_iommu_realize(DeviceState *dev, Error **errp) | ||
93 | address_space_init(&s->trap_as, &s->trap_mr, "riscv-iommu-trap-as"); | ||
94 | |||
95 | if (s->cap & RISCV_IOMMU_CAP_HPM) { | ||
96 | + s->hpm_timer = | ||
97 | + timer_new_ns(QEMU_CLOCK_VIRTUAL, riscv_iommu_hpm_timer_cb, s); | ||
98 | s->hpm_event_ctr_map = g_hash_table_new(g_direct_hash, g_direct_equal); | ||
99 | } | ||
100 | } | ||
101 | @@ -XXX,XX +XXX,XX @@ static void riscv_iommu_unrealize(DeviceState *dev) | ||
102 | |||
103 | if (s->cap & RISCV_IOMMU_CAP_HPM) { | ||
104 | g_hash_table_unref(s->hpm_event_ctr_map); | ||
105 | + timer_free(s->hpm_timer); | ||
106 | } | ||
107 | } | ||
108 | |||
109 | -- | ||
110 | 2.48.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Tomasz Jeznach <tjeznach@rivosinc.com> | ||
2 | 1 | ||
3 | RISCV_IOMMU_REG_IOHPMCYCLES writes are done by | ||
4 | riscv_iommu_process_hpmcycle_write(), called by the mmio write callback | ||
5 | via riscv_iommu_process_hpm_writes(). | ||
6 | |||
7 | Signed-off-by: Tomasz Jeznach <tjeznach@rivosinc.com> | ||
8 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | Message-ID: <20250224190826.1858473-8-dbarboza@ventanamicro.com> | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | --- | ||
13 | hw/riscv/riscv-iommu-hpm.h | 1 + | ||
14 | hw/riscv/riscv-iommu-hpm.c | 19 +++++++++++++++++++ | ||
15 | hw/riscv/riscv-iommu.c | 2 +- | ||
16 | 3 files changed, 21 insertions(+), 1 deletion(-) | ||
17 | |||
18 | diff --git a/hw/riscv/riscv-iommu-hpm.h b/hw/riscv/riscv-iommu-hpm.h | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/hw/riscv/riscv-iommu-hpm.h | ||
21 | +++ b/hw/riscv/riscv-iommu-hpm.h | ||
22 | @@ -XXX,XX +XXX,XX @@ void riscv_iommu_hpm_incr_ctr(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, | ||
23 | unsigned event_id); | ||
24 | void riscv_iommu_hpm_timer_cb(void *priv); | ||
25 | void riscv_iommu_process_iocntinh_cy(RISCVIOMMUState *s, bool prev_cy_inh); | ||
26 | +void riscv_iommu_process_hpmcycle_write(RISCVIOMMUState *s); | ||
27 | |||
28 | #endif | ||
29 | diff --git a/hw/riscv/riscv-iommu-hpm.c b/hw/riscv/riscv-iommu-hpm.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/hw/riscv/riscv-iommu-hpm.c | ||
32 | +++ b/hw/riscv/riscv-iommu-hpm.c | ||
33 | @@ -XXX,XX +XXX,XX @@ void riscv_iommu_process_iocntinh_cy(RISCVIOMMUState *s, bool prev_cy_inh) | ||
34 | timer_del(s->hpm_timer); | ||
35 | } | ||
36 | } | ||
37 | + | ||
38 | +void riscv_iommu_process_hpmcycle_write(RISCVIOMMUState *s) | ||
39 | +{ | ||
40 | + const uint64_t val = riscv_iommu_reg_get64(s, RISCV_IOMMU_REG_IOHPMCYCLES); | ||
41 | + const uint32_t ovf = riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_IOCOUNTOVF); | ||
42 | + | ||
43 | + /* | ||
44 | + * Clear OF bit in IOCNTOVF if it's being cleared in IOHPMCYCLES register. | ||
45 | + */ | ||
46 | + if (get_field(ovf, RISCV_IOMMU_IOCOUNTOVF_CY) && | ||
47 | + !get_field(val, RISCV_IOMMU_IOHPMCYCLES_OVF)) { | ||
48 | + riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_IOCOUNTOVF, 0, | ||
49 | + RISCV_IOMMU_IOCOUNTOVF_CY); | ||
50 | + } | ||
51 | + | ||
52 | + s->hpmcycle_val = val & ~RISCV_IOMMU_IOHPMCYCLES_OVF; | ||
53 | + s->hpmcycle_prev = get_cycles(); | ||
54 | + hpm_setup_timer(s, s->hpmcycle_val); | ||
55 | +} | ||
56 | diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c | ||
57 | index XXXXXXX..XXXXXXX 100644 | ||
58 | --- a/hw/riscv/riscv-iommu.c | ||
59 | +++ b/hw/riscv/riscv-iommu.c | ||
60 | @@ -XXX,XX +XXX,XX @@ static void riscv_iommu_process_hpm_writes(RISCVIOMMUState *s, | ||
61 | |||
62 | case RISCV_IOMMU_REG_IOHPMCYCLES: | ||
63 | case RISCV_IOMMU_REG_IOHPMCYCLES + 4: | ||
64 | - /* not yet implemented */ | ||
65 | + riscv_iommu_process_hpmcycle_write(s); | ||
66 | break; | ||
67 | |||
68 | case RISCV_IOMMU_REG_IOHPMEVT_BASE ... | ||
69 | -- | ||
70 | 2.48.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
3 | Add a handful of trace events to allow for an easier time debugging the | ||
4 | HPM feature. | ||
5 | |||
6 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
7 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Message-ID: <20250224190826.1858473-11-dbarboza@ventanamicro.com> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | --- | ||
11 | hw/riscv/riscv-iommu-hpm.c | 10 ++++++++++ | ||
12 | hw/riscv/trace-events | 5 +++++ | ||
13 | 2 files changed, 15 insertions(+) | ||
14 | |||
15 | diff --git a/hw/riscv/riscv-iommu-hpm.c b/hw/riscv/riscv-iommu-hpm.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/hw/riscv/riscv-iommu-hpm.c | ||
18 | +++ b/hw/riscv/riscv-iommu-hpm.c | ||
19 | @@ -XXX,XX +XXX,XX @@ uint64_t riscv_iommu_hpmcycle_read(RISCVIOMMUState *s) | ||
20 | const uint64_t ctr_prev = s->hpmcycle_prev; | ||
21 | const uint64_t ctr_val = s->hpmcycle_val; | ||
22 | |||
23 | + trace_riscv_iommu_hpm_read(cycle, inhibit, ctr_prev, ctr_val); | ||
24 | + | ||
25 | if (get_field(inhibit, RISCV_IOMMU_IOCOUNTINH_CY)) { | ||
26 | /* | ||
27 | * Counter should not increment if inhibit bit is set. We can't really | ||
28 | @@ -XXX,XX +XXX,XX @@ static void hpm_incr_ctr(RISCVIOMMUState *s, uint32_t ctr_idx) | ||
29 | cntr_val = ldq_le_p(&s->regs_rw[RISCV_IOMMU_REG_IOHPMCTR_BASE + off]); | ||
30 | stq_le_p(&s->regs_rw[RISCV_IOMMU_REG_IOHPMCTR_BASE + off], cntr_val + 1); | ||
31 | |||
32 | + trace_riscv_iommu_hpm_incr_ctr(cntr_val); | ||
33 | + | ||
34 | /* Handle the overflow scenario. */ | ||
35 | if (cntr_val == UINT64_MAX) { | ||
36 | /* | ||
37 | @@ -XXX,XX +XXX,XX @@ void riscv_iommu_process_iocntinh_cy(RISCVIOMMUState *s, bool prev_cy_inh) | ||
38 | return; | ||
39 | } | ||
40 | |||
41 | + trace_riscv_iommu_hpm_iocntinh_cy(prev_cy_inh); | ||
42 | + | ||
43 | if (!(inhibit & RISCV_IOMMU_IOCOUNTINH_CY)) { | ||
44 | /* | ||
45 | * Cycle counter is enabled. Just start the timer again and update | ||
46 | @@ -XXX,XX +XXX,XX @@ void riscv_iommu_process_hpmcycle_write(RISCVIOMMUState *s) | ||
47 | const uint64_t val = riscv_iommu_reg_get64(s, RISCV_IOMMU_REG_IOHPMCYCLES); | ||
48 | const uint32_t ovf = riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_IOCOUNTOVF); | ||
49 | |||
50 | + trace_riscv_iommu_hpm_cycle_write(ovf, val); | ||
51 | + | ||
52 | /* | ||
53 | * Clear OF bit in IOCNTOVF if it's being cleared in IOHPMCYCLES register. | ||
54 | */ | ||
55 | @@ -XXX,XX +XXX,XX @@ void riscv_iommu_process_hpmevt_write(RISCVIOMMUState *s, uint32_t evt_reg) | ||
56 | return; | ||
57 | } | ||
58 | |||
59 | + trace_riscv_iommu_hpm_evt_write(ctr_idx, ovf, val); | ||
60 | + | ||
61 | /* Clear OF bit in IOCNTOVF if it's being cleared in IOHPMEVT register. */ | ||
62 | if (get_field(ovf, BIT(ctr_idx + 1)) && | ||
63 | !get_field(val, RISCV_IOMMU_IOHPMEVT_OF)) { | ||
64 | diff --git a/hw/riscv/trace-events b/hw/riscv/trace-events | ||
65 | index XXXXXXX..XXXXXXX 100644 | ||
66 | --- a/hw/riscv/trace-events | ||
67 | +++ b/hw/riscv/trace-events | ||
68 | @@ -XXX,XX +XXX,XX @@ riscv_iommu_sys_irq_sent(uint32_t vector) "IRQ sent to vector %u" | ||
69 | riscv_iommu_sys_msi_sent(uint32_t vector, uint64_t msi_addr, uint32_t msi_data, uint32_t result) "MSI sent to vector %u msi_addr 0x%"PRIx64" msi_data 0x%x result %u" | ||
70 | riscv_iommu_sys_reset_hold(int reset_type) "reset type %d" | ||
71 | riscv_iommu_pci_reset_hold(int reset_type) "reset type %d" | ||
72 | +riscv_iommu_hpm_read(uint64_t cycle, uint32_t inhibit, uint64_t ctr_prev, uint64_t ctr_val) "cycle 0x%"PRIx64" inhibit 0x%x ctr_prev 0x%"PRIx64" ctr_val 0x%"PRIx64 | ||
73 | +riscv_iommu_hpm_incr_ctr(uint64_t cntr_val) "cntr_val 0x%"PRIx64 | ||
74 | +riscv_iommu_hpm_iocntinh_cy(bool prev_cy_inh) "prev_cy_inh %d" | ||
75 | +riscv_iommu_hpm_cycle_write(uint32_t ovf, uint64_t val) "ovf 0x%x val 0x%"PRIx64 | ||
76 | +riscv_iommu_hpm_evt_write(uint32_t ctr_idx, uint32_t ovf, uint64_t val) "ctr_idx 0x%x ovf 0x%x val 0x%"PRIx64 | ||
77 | -- | ||
78 | 2.48.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
3 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
4 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
5 | Message-ID: <20250224190826.1858473-12-dbarboza@ventanamicro.com> | ||
6 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
7 | --- | ||
8 | docs/specs/riscv-iommu.rst | 2 ++ | ||
9 | 1 file changed, 2 insertions(+) | ||
10 | |||
11 | diff --git a/docs/specs/riscv-iommu.rst b/docs/specs/riscv-iommu.rst | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/docs/specs/riscv-iommu.rst | ||
14 | +++ b/docs/specs/riscv-iommu.rst | ||
15 | @@ -XXX,XX +XXX,XX @@ Several options are available to control the capabilities of the device, namely: | ||
16 | - "off" (Out-of-reset translation mode: 'on' for DMA disabled, 'off' for 'BARE' (passthrough)) | ||
17 | - "s-stage": enable s-stage support | ||
18 | - "g-stage": enable g-stage support | ||
19 | +- "hpm-counters": number of hardware performance counters available. Maximum value is 31. | ||
20 | + Default value is 31. Use 0 (zero) to disable HPM support | ||
21 | |||
22 | riscv-iommu-sys device | ||
23 | ---------------------- | ||
24 | -- | ||
25 | 2.48.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Quan Zhou <zhouquan@iscas.ac.cn> | ||
2 | 1 | ||
3 | When the Sscofpmf/Svade/Svadu/Smnpm/Ssnpm exts is available | ||
4 | expose it to the guest so that guest can use it. | ||
5 | |||
6 | Signed-off-by: Quan Zhou <zhouquan@iscas.ac.cn> | ||
7 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
8 | Message-ID: <303616ccad2b5309768157b50d93b3e89fecc9cb.1740371468.git.zhouquan@iscas.ac.cn> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | --- | ||
11 | target/riscv/kvm/kvm-cpu.c | 5 +++++ | ||
12 | 1 file changed, 5 insertions(+) | ||
13 | |||
14 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/target/riscv/kvm/kvm-cpu.c | ||
17 | +++ b/target/riscv/kvm/kvm-cpu.c | ||
18 | @@ -XXX,XX +XXX,XX @@ static KVMCPUConfig kvm_multi_ext_cfgs[] = { | ||
19 | KVM_EXT_CFG("zvksed", ext_zvksed, KVM_RISCV_ISA_EXT_ZVKSED), | ||
20 | KVM_EXT_CFG("zvksh", ext_zvksh, KVM_RISCV_ISA_EXT_ZVKSH), | ||
21 | KVM_EXT_CFG("zvkt", ext_zvkt, KVM_RISCV_ISA_EXT_ZVKT), | ||
22 | + KVM_EXT_CFG("smnpm", ext_smnpm, KVM_RISCV_ISA_EXT_SMNPM), | ||
23 | KVM_EXT_CFG("smstateen", ext_smstateen, KVM_RISCV_ISA_EXT_SMSTATEEN), | ||
24 | KVM_EXT_CFG("ssaia", ext_ssaia, KVM_RISCV_ISA_EXT_SSAIA), | ||
25 | + KVM_EXT_CFG("sscofpmf", ext_sscofpmf, KVM_RISCV_ISA_EXT_SSCOFPMF), | ||
26 | + KVM_EXT_CFG("ssnpm", ext_ssnpm, KVM_RISCV_ISA_EXT_SSNPM), | ||
27 | KVM_EXT_CFG("sstc", ext_sstc, KVM_RISCV_ISA_EXT_SSTC), | ||
28 | + KVM_EXT_CFG("svade", ext_svade, KVM_RISCV_ISA_EXT_SVADE), | ||
29 | + KVM_EXT_CFG("svadu", ext_svadu, KVM_RISCV_ISA_EXT_SVADU), | ||
30 | KVM_EXT_CFG("svinval", ext_svinval, KVM_RISCV_ISA_EXT_SVINVAL), | ||
31 | KVM_EXT_CFG("svnapot", ext_svnapot, KVM_RISCV_ISA_EXT_SVNAPOT), | ||
32 | KVM_EXT_CFG("svpbmt", ext_svpbmt, KVM_RISCV_ISA_EXT_SVPBMT), | ||
33 | -- | ||
34 | 2.48.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Andrea Bolognani <abologna@redhat.com> | ||
2 | 1 | ||
3 | This should make no difference from the functional point of | ||
4 | view and it's just preparation for upcoming changes. | ||
5 | |||
6 | Signed-off-by: Andrea Bolognani <abologna@redhat.com> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Reviewed-by: Laurent Vivier <laurent@vivier.eu> | ||
9 | Message-ID: <20250127182924.103510-2-abologna@redhat.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | --- | ||
12 | scripts/qemu-binfmt-conf.sh | 17 ++++++++++------- | ||
13 | 1 file changed, 10 insertions(+), 7 deletions(-) | ||
14 | |||
15 | diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh | ||
16 | index XXXXXXX..XXXXXXX 100755 | ||
17 | --- a/scripts/qemu-binfmt-conf.sh | ||
18 | +++ b/scripts/qemu-binfmt-conf.sh | ||
19 | @@ -XXX,XX +XXX,XX @@ qemu_set_binfmts() { | ||
20 | mask=$(eval echo \$${cpu}_mask) | ||
21 | family=$(eval echo \$${cpu}_family) | ||
22 | |||
23 | + target="$cpu" | ||
24 | + if [ "$cpu" = "i486" ] ; then | ||
25 | + target="i386" | ||
26 | + fi | ||
27 | + | ||
28 | + qemu="$QEMU_PATH/qemu-$target$QEMU_SUFFIX" | ||
29 | + | ||
30 | if [ "$magic" = "" ] || [ "$mask" = "" ] || [ "$family" = "" ] ; then | ||
31 | echo "INTERNAL ERROR: unknown cpu $cpu" 1>&2 | ||
32 | continue | ||
33 | fi | ||
34 | |||
35 | - qemu="$QEMU_PATH/qemu-$cpu" | ||
36 | - if [ "$cpu" = "i486" ] ; then | ||
37 | - qemu="$QEMU_PATH/qemu-i386" | ||
38 | + if [ "$host_family" = "$family" ] ; then | ||
39 | + continue | ||
40 | fi | ||
41 | |||
42 | - qemu="$qemu$QEMU_SUFFIX" | ||
43 | - if [ "$host_family" != "$family" ] ; then | ||
44 | - $BINFMT_SET | ||
45 | - fi | ||
46 | + $BINFMT_SET | ||
47 | done | ||
48 | } | ||
49 | |||
50 | -- | ||
51 | 2.48.1 | diff view generated by jsdifflib |