1 | The following changes since commit 8f6330a807f2642dc2a3cdf33347aa28a4c00a87: | 1 | The following changes since commit c5ea91da443b458352c1b629b490ee6631775cb4: |
---|---|---|---|
2 | 2 | ||
3 | Merge tag 'pull-maintainer-updates-060324-1' of https://gitlab.com/stsquad/qemu into staging (2024-03-06 16:56:20 +0000) | 3 | Merge tag 'pull-trivial-patches' of https://gitlab.com/mjt0k/qemu into staging (2023-09-08 10:06:25 -0400) |
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-20240308-1 | 7 | https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20230911 |
8 | 8 | ||
9 | for you to fetch changes up to 301876597112218c1e465ecc2b2fef6b27d5c27b: | 9 | for you to fetch changes up to e7a03409f29e2da59297d55afbaec98c96e43e3a: |
10 | 10 | ||
11 | target/riscv: fix ACPI MCFG table (2024-03-08 21:00:37 +1000) | 11 | target/riscv: don't read CSR in riscv_csrrw_do64 (2023-09-11 11:45:55 +1000) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | RISC-V PR for 9.0 | 14 | First RISC-V PR for 8.2 |
15 | 15 | ||
16 | * Update $ra with current $pc in trans_cm_jalt | 16 | * Remove 'host' CPU from TCG |
17 | * Enable SPCR for SCPI virt machine | 17 | * riscv_htif Fixup printing on big endian hosts |
18 | * Allow large kernels to boot by moving the initrd further away in RAM | 18 | * Add zmmul isa string |
19 | * Sync hwprobe keys with kernel | 19 | * Add smepmp isa string |
20 | * Named features riscv,isa, 'svade' rework | 20 | * Fix page_check_range use in fault-only-first |
21 | * FIX xATP_MODE validation | 21 | * Use existing lookup tables for MixColumns |
22 | * Add missing include guard in pmu.h | 22 | * Add RISC-V vector cryptographic instruction set support |
23 | * Add SRAT and SLIT ACPI tables | 23 | * Implement WARL behaviour for mcountinhibit/mcounteren |
24 | * libqos fixes and add a riscv machine | 24 | * Add Zihintntl extension ISA string to DTS |
25 | * Add Ztso extension | 25 | * Fix zfa fleq.d and fltq.d |
26 | * Use 'zfa' instead of 'Zfa' | 26 | * Fix upper/lower mtime write calculation |
27 | * Update KVM exts to Linux 6.8 | 27 | * Make rtc variable names consistent |
28 | * move ratified/frozen exts to non-experimental | 28 | * Use abi type for linux-user target_ucontext |
29 | * Ensure mcountinhibit, mcounteren, scounteren, hcounteren are 32-bit | 29 | * Add RISC-V KVM AIA Support |
30 | * mark_vs_dirty() before loads and stores | 30 | * Fix riscv,pmu DT node path in the virt machine |
31 | * Remove 'is_store' bool from load/store fns | 31 | * Update CSR bits name for svadu extension |
32 | * Fix shift count overflow | 32 | * Mark zicond non-experimental |
33 | * Fix setipnum_le write emulation for APLIC MSI-mode | 33 | * Fix satp_mode_finalize() when satp_mode.supported = 0 |
34 | * Fix in_clrip[x] read emulation | 34 | * Fix non-KVM --enable-debug build |
35 | * Fix privilege mode of G-stage translation for debugging | 35 | * Add new extensions to hwprobe |
36 | * Fix ACPI MCFG table for virt machine | 36 | * Use accelerated helper for AES64KS1I |
37 | * Allocate itrigger timers only once | ||
38 | * Respect mseccfg.RLB for pmpaddrX changes | ||
39 | * Align the AIA model to v1.0 ratified spec | ||
40 | * Don't read the CSR in riscv_csrrw_do64 | ||
37 | 41 | ||
38 | ---------------------------------------------------------------- | 42 | ---------------------------------------------------------------- |
39 | Alexandre Ghiti (1): | 43 | Akihiko Odaki (1): |
40 | hw: riscv: Allow large kernels to boot by moving the initrd further away in RAM | 44 | target/riscv: Allocate itrigger timers only once |
41 | 45 | ||
42 | Andrew Jones (3): | 46 | Ard Biesheuvel (2): |
43 | target/riscv: Reset henvcfg to zero | 47 | target/riscv: Use existing lookup tables for MixColumns |
44 | target/riscv: Gate hardware A/D PTE bit updating | 48 | target/riscv: Use accelerated helper for AES64KS1I |
45 | target/riscv: Promote svade to a normal extension | ||
46 | 49 | ||
47 | Anup Patel (2): | 50 | Conor Dooley (1): |
48 | hw/intc/riscv_aplic: Fix setipnum_le write emulation for APLIC MSI-mode | 51 | hw/riscv: virt: Fix riscv,pmu DT node path |
49 | hw/intc/riscv_aplic: Fix in_clrip[x] read emulation | ||
50 | 52 | ||
51 | Christoph Müllner (4): | 53 | Daniel Henrique Barboza (6): |
52 | linux-user/riscv: Add Zicboz extensions to hwprobe | 54 | target/riscv/cpu.c: do not run 'host' CPU with TCG |
53 | linux-user/riscv: Sync hwprobe keys with Linux | 55 | target/riscv/cpu.c: add zmmul isa string |
54 | linux-user/riscv: Add Ztso extension to hwprobe | 56 | target/riscv/cpu.c: add smepmp isa string |
55 | tests: riscv64: Use 'zfa' instead of 'Zfa' | 57 | target/riscv: fix satp_mode_finalize() when satp_mode.supported = 0 |
58 | hw/riscv/virt.c: fix non-KVM --enable-debug build | ||
59 | hw/intc/riscv_aplic.c fix non-KVM --enable-debug build | ||
56 | 60 | ||
57 | Daniel Henrique Barboza (12): | 61 | Dickon Hood (2): |
58 | target/riscv/tcg: set 'mmu' with 'satp' in cpu_set_profile() | 62 | target/riscv: Refactor translation of vector-widening instruction |
59 | target/riscv: add riscv,isa to named features | 63 | target/riscv: Add Zvbb ISA extension support |
60 | target/riscv: add remaining named features | ||
61 | hw/riscv/virt.c: create '/soc/pci@...' fdt node earlier | ||
62 | hw/riscv/virt.c: add virtio-iommu-pci hotplug support | ||
63 | hw/riscv/virt.c: make aclint compatible with 'qtest' accel | ||
64 | tests/libqos: add riscv/virt machine nodes | ||
65 | linux-headers: Update to Linux v6.8-rc6 | ||
66 | target/riscv/kvm: update KVM exts to Linux 6.8 | ||
67 | target/riscv: move ratified/frozen exts to non-experimental | ||
68 | trans_rvv.c.inc: mark_vs_dirty() before loads and stores | ||
69 | trans_rvv.c.inc: remove 'is_store' bool from load/store fns | ||
70 | 64 | ||
71 | Frank Chang (1): | 65 | Jason Chien (3): |
72 | target/riscv: Add missing include guard in pmu.h | 66 | target/riscv: Add Zihintntl extension ISA string to DTS |
67 | hw/intc: Fix upper/lower mtime write calculation | ||
68 | hw/intc: Make rtc variable names consistent | ||
73 | 69 | ||
74 | Haibo Xu (1): | 70 | Kiran Ostrolenk (4): |
75 | hw/riscv/virt-acpi-build.c: Add SRAT and SLIT ACPI tables | 71 | target/riscv: Refactor some of the generic vector functionality |
72 | target/riscv: Refactor vector-vector translation macro | ||
73 | target/riscv: Refactor some of the generic vector functionality | ||
74 | target/riscv: Add Zvknh ISA extension support | ||
76 | 75 | ||
77 | Hiroaki Yamamoto (1): | 76 | LIU Zhiwei (3): |
78 | target/riscv: Fix privilege mode of G-stage translation for debugging | 77 | target/riscv: Fix page_check_range use in fault-only-first |
78 | target/riscv: Fix zfa fleq.d and fltq.d | ||
79 | linux-user/riscv: Use abi type for target_ucontext | ||
79 | 80 | ||
80 | Ilya Chugin (1): | 81 | Lawrence Hunter (2): |
81 | target/riscv: fix ACPI MCFG table | 82 | target/riscv: Add Zvbc ISA extension support |
83 | target/riscv: Add Zvksh ISA extension support | ||
82 | 84 | ||
83 | Irina Ryapolova (2): | 85 | Leon Schuermann (1): |
84 | target/riscv: FIX xATP_MODE validation | 86 | target/riscv/pmp.c: respect mseccfg.RLB for pmpaddrX changes |
85 | target/riscv: UPDATE xATP write CSR | ||
86 | 87 | ||
87 | Jason Chien (1): | 88 | Max Chou (3): |
88 | target/riscv: Update $ra with current $pc in trans_cm_jalt() | 89 | crypto: Create sm4_subword |
90 | crypto: Add SM4 constant parameter CK | ||
91 | target/riscv: Add Zvksed ISA extension support | ||
89 | 92 | ||
90 | Palmer Dabbelt (1): | 93 | Nazar Kazakov (4): |
91 | RISC-V: Add support for Ztso | 94 | target/riscv: Remove redundant "cpu_vl == 0" checks |
95 | target/riscv: Move vector translation checks | ||
96 | target/riscv: Add Zvkned ISA extension support | ||
97 | target/riscv: Add Zvkg ISA extension support | ||
92 | 98 | ||
93 | Sia Jee Heng (2): | 99 | Nikita Shubin (1): |
94 | hw/arm/virt-acpi-build.c: Migrate SPCR creation to common location | 100 | target/riscv: don't read CSR in riscv_csrrw_do64 |
95 | hw/riscv/virt-acpi-build.c: Generate SPCR table | ||
96 | 101 | ||
97 | Vadim Shakirov (1): | 102 | Rob Bradford (1): |
98 | target/riscv: mcountinhibit, mcounteren, scounteren, hcounteren is 32-bit | 103 | target/riscv: Implement WARL behaviour for mcountinhibit/mcounteren |
99 | 104 | ||
100 | demin.han (1): | 105 | Robbin Ehn (1): |
101 | target/riscv: Fix shift count overflow | 106 | linux-user/riscv: Add new extensions to hwprobe |
102 | 107 | ||
103 | include/hw/acpi/acpi-defs.h | 33 ++++++ | 108 | Thomas Huth (2): |
104 | include/hw/acpi/aml-build.h | 4 + | 109 | hw/char/riscv_htif: Fix printing of console characters on big endian hosts |
105 | include/standard-headers/drm/drm_fourcc.h | 10 +- | 110 | hw/char/riscv_htif: Fix the console syscall on big endian hosts |
106 | include/standard-headers/linux/ethtool.h | 41 +++++--- | ||
107 | include/standard-headers/linux/virtio_config.h | 8 +- | ||
108 | include/standard-headers/linux/virtio_pci.h | 68 ++++++++++++ | ||
109 | include/standard-headers/linux/virtio_pmem.h | 7 ++ | ||
110 | linux-headers/asm-generic/unistd.h | 15 ++- | ||
111 | linux-headers/asm-mips/mman.h | 2 +- | ||
112 | linux-headers/asm-mips/unistd_n32.h | 5 + | ||
113 | linux-headers/asm-mips/unistd_n64.h | 5 + | ||
114 | linux-headers/asm-mips/unistd_o32.h | 5 + | ||
115 | linux-headers/asm-powerpc/unistd_32.h | 5 + | ||
116 | linux-headers/asm-powerpc/unistd_64.h | 5 + | ||
117 | linux-headers/asm-riscv/kvm.h | 40 +++++++ | ||
118 | linux-headers/asm-s390/unistd_32.h | 5 + | ||
119 | linux-headers/asm-s390/unistd_64.h | 5 + | ||
120 | linux-headers/asm-x86/kvm.h | 3 + | ||
121 | linux-headers/asm-x86/unistd_32.h | 5 + | ||
122 | linux-headers/asm-x86/unistd_64.h | 5 + | ||
123 | linux-headers/asm-x86/unistd_x32.h | 5 + | ||
124 | linux-headers/linux/iommufd.h | 79 ++++++++++++++ | ||
125 | linux-headers/linux/kvm.h | 140 +++++++++---------------- | ||
126 | linux-headers/linux/userfaultfd.h | 29 ++++- | ||
127 | linux-headers/linux/vfio.h | 1 + | ||
128 | target/riscv/cpu.h | 8 +- | ||
129 | target/riscv/cpu_cfg.h | 13 ++- | ||
130 | target/riscv/pmu.h | 5 + | ||
131 | hw/acpi/aml-build.c | 53 ++++++++++ | ||
132 | hw/arm/virt-acpi-build.c | 68 +++++------- | ||
133 | hw/intc/riscv_aplic.c | 37 +++++-- | ||
134 | hw/riscv/boot.c | 12 +-- | ||
135 | hw/riscv/virt-acpi-build.c | 103 +++++++++++++++++- | ||
136 | hw/riscv/virt.c | 97 ++++++++++++----- | ||
137 | linux-user/syscall.c | 104 ++++++++++++++++-- | ||
138 | target/riscv/cpu.c | 94 +++++++++++------ | ||
139 | target/riscv/cpu_helper.c | 21 +++- | ||
140 | target/riscv/csr.c | 58 +++++----- | ||
141 | target/riscv/kvm/kvm-cpu.c | 29 +++++ | ||
142 | target/riscv/machine.c | 16 +-- | ||
143 | target/riscv/tcg/tcg-cpu.c | 34 +++--- | ||
144 | target/riscv/translate.c | 3 + | ||
145 | target/riscv/vector_helper.c | 5 +- | ||
146 | tests/qtest/libqos/riscv-virt-machine.c | 137 ++++++++++++++++++++++++ | ||
147 | target/riscv/insn_trans/trans_rva.c.inc | 11 +- | ||
148 | target/riscv/insn_trans/trans_rvi.c.inc | 16 ++- | ||
149 | target/riscv/insn_trans/trans_rvv.c.inc | 97 +++++++++-------- | ||
150 | target/riscv/insn_trans/trans_rvzce.c.inc | 6 +- | ||
151 | tests/qtest/libqos/meson.build | 1 + | ||
152 | tests/tcg/riscv64/Makefile.target | 2 +- | ||
153 | 50 files changed, 1213 insertions(+), 347 deletions(-) | ||
154 | create mode 100644 tests/qtest/libqos/riscv-virt-machine.c | ||
155 | 111 | ||
112 | Tommy Wu (1): | ||
113 | target/riscv: Align the AIA model to v1.0 ratified spec | ||
114 | |||
115 | Vineet Gupta (1): | ||
116 | riscv: zicond: make non-experimental | ||
117 | |||
118 | Weiwei Li (1): | ||
119 | target/riscv: Update CSR bits name for svadu extension | ||
120 | |||
121 | Yong-Xuan Wang (5): | ||
122 | target/riscv: support the AIA device emulation with KVM enabled | ||
123 | target/riscv: check the in-kernel irqchip support | ||
124 | target/riscv: Create an KVM AIA irqchip | ||
125 | target/riscv: update APLIC and IMSIC to support KVM AIA | ||
126 | target/riscv: select KVM AIA in riscv virt machine | ||
127 | |||
128 | include/crypto/aes.h | 7 + | ||
129 | include/crypto/sm4.h | 9 + | ||
130 | target/riscv/cpu_bits.h | 8 +- | ||
131 | target/riscv/cpu_cfg.h | 9 + | ||
132 | target/riscv/debug.h | 3 +- | ||
133 | target/riscv/helper.h | 98 +++ | ||
134 | target/riscv/kvm_riscv.h | 5 + | ||
135 | target/riscv/vector_internals.h | 228 +++++++ | ||
136 | target/riscv/insn32.decode | 58 ++ | ||
137 | crypto/aes.c | 4 +- | ||
138 | crypto/sm4.c | 10 + | ||
139 | hw/char/riscv_htif.c | 12 +- | ||
140 | hw/intc/riscv_aclint.c | 11 +- | ||
141 | hw/intc/riscv_aplic.c | 52 +- | ||
142 | hw/intc/riscv_imsic.c | 25 +- | ||
143 | hw/riscv/virt.c | 374 ++++++------ | ||
144 | linux-user/riscv/signal.c | 4 +- | ||
145 | linux-user/syscall.c | 14 +- | ||
146 | target/arm/tcg/crypto_helper.c | 10 +- | ||
147 | target/riscv/cpu.c | 83 ++- | ||
148 | target/riscv/cpu_helper.c | 6 +- | ||
149 | target/riscv/crypto_helper.c | 51 +- | ||
150 | target/riscv/csr.c | 54 +- | ||
151 | target/riscv/debug.c | 15 +- | ||
152 | target/riscv/kvm.c | 201 ++++++- | ||
153 | target/riscv/pmp.c | 4 + | ||
154 | target/riscv/translate.c | 1 + | ||
155 | target/riscv/vcrypto_helper.c | 970 ++++++++++++++++++++++++++++++ | ||
156 | target/riscv/vector_helper.c | 245 +------- | ||
157 | target/riscv/vector_internals.c | 81 +++ | ||
158 | target/riscv/insn_trans/trans_rvv.c.inc | 171 +++--- | ||
159 | target/riscv/insn_trans/trans_rvvk.c.inc | 606 +++++++++++++++++++ | ||
160 | target/riscv/insn_trans/trans_rvzfa.c.inc | 4 +- | ||
161 | target/riscv/meson.build | 4 +- | ||
162 | 34 files changed, 2785 insertions(+), 652 deletions(-) | ||
163 | create mode 100644 target/riscv/vector_internals.h | ||
164 | create mode 100644 target/riscv/vcrypto_helper.c | ||
165 | create mode 100644 target/riscv/vector_internals.c | ||
166 | create mode 100644 target/riscv/insn_trans/trans_rvvk.c.inc | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | smaia and ssaia were ratified in August 25th 2023 [1]. | 3 | The 'host' CPU is available in a CONFIG_KVM build and it's currently |
4 | available for all accels, but is a KVM only CPU. This means that in a | ||
5 | RISC-V KVM capable host we can do things like this: | ||
4 | 6 | ||
5 | zvfh and zvfhmin were ratified in August 2nd 2023 [2]. | 7 | $ ./build/qemu-system-riscv64 -M virt,accel=tcg -cpu host --nographic |
8 | qemu-system-riscv64: H extension requires priv spec 1.12.0 | ||
6 | 9 | ||
7 | zfbfmin and zvfbf(min|wma) are frozen and moved to public review since | 10 | This CPU does not have a priv spec because we don't filter its extensions |
8 | Dec 16th 2023 [3]. | 11 | via priv spec. We shouldn't be reaching riscv_cpu_realize_tcg() at all |
12 | with the 'host' CPU. | ||
9 | 13 | ||
10 | zaamo and zalrsc are both marked as "Frozen" since January 24th 2024 | 14 | We don't have a way to filter the 'host' CPU out of the available CPU |
11 | [4]. | 15 | options (-cpu help) if the build includes both KVM and TCG. What we can |
16 | do is to error out during riscv_cpu_realize_tcg() if the user chooses | ||
17 | the 'host' CPU with accel=tcg: | ||
12 | 18 | ||
13 | [1] https://jira.riscv.org/browse/RVS-438 | 19 | $ ./build/qemu-system-riscv64 -M virt,accel=tcg -cpu host --nographic |
14 | [2] https://jira.riscv.org/browse/RVS-871 | 20 | qemu-system-riscv64: 'host' CPU is not compatible with TCG acceleration |
15 | [3] https://jira.riscv.org/browse/RVS-704 | ||
16 | [4] https://jira.riscv.org/browse/RVS-1995 | ||
17 | 21 | ||
18 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 22 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
19 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 23 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
20 | Message-ID: <20240301144053.265964-1-dbarboza@ventanamicro.com> | 24 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
25 | Message-Id: <20230721133411.474105-1-dbarboza@ventanamicro.com> | ||
21 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 26 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
22 | --- | 27 | --- |
23 | target/riscv/cpu.c | 22 +++++++++------------- | 28 | target/riscv/cpu.c | 5 +++++ |
24 | 1 file changed, 9 insertions(+), 13 deletions(-) | 29 | 1 file changed, 5 insertions(+) |
25 | 30 | ||
26 | 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 |
27 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/target/riscv/cpu.c | 33 | --- a/target/riscv/cpu.c |
29 | +++ b/target/riscv/cpu.c | 34 | +++ b/target/riscv/cpu.c |
30 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { | 35 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize_tcg(DeviceState *dev, Error **errp) |
31 | MULTI_EXT_CFG_BOOL("zihintntl", ext_zihintntl, true), | 36 | CPURISCVState *env = &cpu->env; |
32 | MULTI_EXT_CFG_BOOL("zihintpause", ext_zihintpause, true), | 37 | Error *local_err = NULL; |
33 | MULTI_EXT_CFG_BOOL("zacas", ext_zacas, false), | 38 | |
34 | + MULTI_EXT_CFG_BOOL("zaamo", ext_zaamo, false), | 39 | + if (object_dynamic_cast(OBJECT(dev), TYPE_RISCV_CPU_HOST)) { |
35 | + MULTI_EXT_CFG_BOOL("zalrsc", ext_zalrsc, false), | 40 | + error_setg(errp, "'host' CPU is not compatible with TCG acceleration"); |
36 | MULTI_EXT_CFG_BOOL("zawrs", ext_zawrs, true), | 41 | + return; |
37 | MULTI_EXT_CFG_BOOL("zfa", ext_zfa, true), | 42 | + } |
38 | + MULTI_EXT_CFG_BOOL("zfbfmin", ext_zfbfmin, false), | 43 | + |
39 | MULTI_EXT_CFG_BOOL("zfh", ext_zfh, false), | 44 | riscv_cpu_validate_misa_mxl(cpu, &local_err); |
40 | MULTI_EXT_CFG_BOOL("zfhmin", ext_zfhmin, false), | 45 | if (local_err != NULL) { |
41 | MULTI_EXT_CFG_BOOL("zve32f", ext_zve32f, false), | 46 | error_propagate(errp, local_err); |
42 | MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false), | ||
43 | MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false), | ||
44 | + MULTI_EXT_CFG_BOOL("zvfbfmin", ext_zvfbfmin, false), | ||
45 | + MULTI_EXT_CFG_BOOL("zvfbfwma", ext_zvfbfwma, false), | ||
46 | + MULTI_EXT_CFG_BOOL("zvfh", ext_zvfh, false), | ||
47 | + MULTI_EXT_CFG_BOOL("zvfhmin", ext_zvfhmin, false), | ||
48 | MULTI_EXT_CFG_BOOL("sstc", ext_sstc, true), | ||
49 | |||
50 | + MULTI_EXT_CFG_BOOL("smaia", ext_smaia, false), | ||
51 | MULTI_EXT_CFG_BOOL("smepmp", ext_smepmp, false), | ||
52 | MULTI_EXT_CFG_BOOL("smstateen", ext_smstateen, false), | ||
53 | + MULTI_EXT_CFG_BOOL("ssaia", ext_ssaia, false), | ||
54 | MULTI_EXT_CFG_BOOL("svade", ext_svade, false), | ||
55 | MULTI_EXT_CFG_BOOL("svadu", ext_svadu, true), | ||
56 | MULTI_EXT_CFG_BOOL("svinval", ext_svinval, false), | ||
57 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[] = { | ||
58 | |||
59 | /* These are experimental so mark with 'x-' */ | ||
60 | const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = { | ||
61 | - MULTI_EXT_CFG_BOOL("x-smaia", ext_smaia, false), | ||
62 | - MULTI_EXT_CFG_BOOL("x-ssaia", ext_ssaia, false), | ||
63 | - | ||
64 | - MULTI_EXT_CFG_BOOL("x-zaamo", ext_zaamo, false), | ||
65 | - MULTI_EXT_CFG_BOOL("x-zalrsc", ext_zalrsc, false), | ||
66 | - | ||
67 | - MULTI_EXT_CFG_BOOL("x-zvfh", ext_zvfh, false), | ||
68 | - MULTI_EXT_CFG_BOOL("x-zvfhmin", ext_zvfhmin, false), | ||
69 | - | ||
70 | - MULTI_EXT_CFG_BOOL("x-zfbfmin", ext_zfbfmin, false), | ||
71 | - MULTI_EXT_CFG_BOOL("x-zvfbfmin", ext_zvfbfmin, false), | ||
72 | - MULTI_EXT_CFG_BOOL("x-zvfbfwma", ext_zvfbfwma, false), | ||
73 | - | ||
74 | DEFINE_PROP_END_OF_LIST(), | ||
75 | }; | ||
76 | |||
77 | -- | 47 | -- |
78 | 2.44.0 | 48 | 2.41.0 |
49 | |||
50 | diff view generated by jsdifflib |
1 | From: Frank Chang <frank.chang@sifive.com> | 1 | From: Thomas Huth <thuth@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Add missing include guard in pmu.h to avoid the problem of double | 3 | The character that should be printed is stored in the 64 bit "payload" |
4 | inclusion. | 4 | variable. The code currently tries to print it by taking the address |
5 | of the variable and passing this pointer to qemu_chr_fe_write(). However, | ||
6 | this only works on little endian hosts where the least significant bits | ||
7 | are stored on the lowest address. To do this in a portable way, we have | ||
8 | to store the value in an uint8_t variable instead. | ||
5 | 9 | ||
6 | Signed-off-by: Frank Chang <frank.chang@sifive.com> | 10 | Fixes: 5033606780 ("RISC-V HTIF Console") |
7 | Reviewed-by: Atish Patra <atishp@rivosinc.com> | 11 | Signed-off-by: Thomas Huth <thuth@redhat.com> |
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | Reviewed-by: Bin Meng <bmeng@tinylab.org> | ||
8 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 14 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
9 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 15 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 16 | Message-Id: <20230721094720.902454-2-thuth@redhat.com> |
11 | Message-ID: <20240220110907.10479-1-frank.chang@sifive.com> | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 17 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | --- | 18 | --- |
14 | target/riscv/pmu.h | 5 +++++ | 19 | hw/char/riscv_htif.c | 3 ++- |
15 | 1 file changed, 5 insertions(+) | 20 | 1 file changed, 2 insertions(+), 1 deletion(-) |
16 | 21 | ||
17 | diff --git a/target/riscv/pmu.h b/target/riscv/pmu.h | 22 | diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c |
18 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/target/riscv/pmu.h | 24 | --- a/hw/char/riscv_htif.c |
20 | +++ b/target/riscv/pmu.h | 25 | +++ b/hw/char/riscv_htif.c |
21 | @@ -XXX,XX +XXX,XX @@ | 26 | @@ -XXX,XX +XXX,XX @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written) |
22 | * this program. If not, see <http://www.gnu.org/licenses/>. | 27 | s->tohost = 0; /* clear to indicate we read */ |
23 | */ | 28 | return; |
24 | 29 | } else if (cmd == HTIF_CONSOLE_CMD_PUTC) { | |
25 | +#ifndef RISCV_PMU_H | 30 | - qemu_chr_fe_write(&s->chr, (uint8_t *)&payload, 1); |
26 | +#define RISCV_PMU_H | 31 | + uint8_t ch = (uint8_t)payload; |
27 | + | 32 | + qemu_chr_fe_write(&s->chr, &ch, 1); |
28 | #include "cpu.h" | 33 | resp = 0x100 | (uint8_t)payload; |
29 | #include "qapi/error.h" | 34 | } else { |
30 | 35 | qemu_log("HTIF device %d: unknown command\n", device); | |
31 | @@ -XXX,XX +XXX,XX @@ int riscv_pmu_incr_ctr(RISCVCPU *cpu, enum riscv_pmu_event_idx event_idx); | ||
32 | void riscv_pmu_generate_fdt_node(void *fdt, uint32_t cmask, char *pmu_name); | ||
33 | int riscv_pmu_setup_timer(CPURISCVState *env, uint64_t value, | ||
34 | uint32_t ctr_idx); | ||
35 | + | ||
36 | +#endif /* RISCV_PMU_H */ | ||
37 | -- | 36 | -- |
38 | 2.44.0 | 37 | 2.41.0 |
39 | 38 | ||
40 | 39 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Thomas Huth <thuth@redhat.com> | ||
1 | 2 | ||
3 | Values that have been read via cpu_physical_memory_read() from the | ||
4 | guest's memory have to be swapped in case the host endianess differs | ||
5 | from the guest. | ||
6 | |||
7 | Fixes: a6e13e31d5 ("riscv_htif: Support console output via proxy syscall") | ||
8 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | Reviewed-by: Bin Meng <bmeng@tinylab.org> | ||
11 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
12 | Message-Id: <20230721094720.902454-3-thuth@redhat.com> | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
14 | --- | ||
15 | hw/char/riscv_htif.c | 9 +++++---- | ||
16 | 1 file changed, 5 insertions(+), 4 deletions(-) | ||
17 | |||
18 | diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/hw/char/riscv_htif.c | ||
21 | +++ b/hw/char/riscv_htif.c | ||
22 | @@ -XXX,XX +XXX,XX @@ | ||
23 | #include "qemu/timer.h" | ||
24 | #include "qemu/error-report.h" | ||
25 | #include "exec/address-spaces.h" | ||
26 | +#include "exec/tswap.h" | ||
27 | #include "sysemu/dma.h" | ||
28 | |||
29 | #define RISCV_DEBUG_HTIF 0 | ||
30 | @@ -XXX,XX +XXX,XX @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written) | ||
31 | } else { | ||
32 | uint64_t syscall[8]; | ||
33 | cpu_physical_memory_read(payload, syscall, sizeof(syscall)); | ||
34 | - if (syscall[0] == PK_SYS_WRITE && | ||
35 | - syscall[1] == HTIF_DEV_CONSOLE && | ||
36 | - syscall[3] == HTIF_CONSOLE_CMD_PUTC) { | ||
37 | + if (tswap64(syscall[0]) == PK_SYS_WRITE && | ||
38 | + tswap64(syscall[1]) == HTIF_DEV_CONSOLE && | ||
39 | + tswap64(syscall[3]) == HTIF_CONSOLE_CMD_PUTC) { | ||
40 | uint8_t ch; | ||
41 | - cpu_physical_memory_read(syscall[2], &ch, 1); | ||
42 | + cpu_physical_memory_read(tswap64(syscall[2]), &ch, 1); | ||
43 | qemu_chr_fe_write(&s->chr, &ch, 1); | ||
44 | resp = 0x100 | (uint8_t)payload; | ||
45 | } else { | ||
46 | -- | ||
47 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | The last KVM extensions added were back in 6.6. Sync them to Linux 6.8. | 3 | zmmul was promoted from experimental to ratified in commit 6d00ffad4e95. |
4 | Add a riscv,isa string for it. | ||
4 | 5 | ||
6 | Fixes: 6d00ffad4e95 ("target/riscv: move zmmul out of the experimental properties") | ||
5 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 7 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
6 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Reviewed-by: Weiwei Li <liweiwei@iscas.ac.cn> |
7 | Message-ID: <20240304134732.386590-3-dbarboza@ventanamicro.com> | 9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
10 | Message-Id: <20230720132424.371132-2-dbarboza@ventanamicro.com> | ||
8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
9 | --- | 12 | --- |
10 | target/riscv/kvm/kvm-cpu.c | 29 +++++++++++++++++++++++++++++ | 13 | target/riscv/cpu.c | 1 + |
11 | 1 file changed, 29 insertions(+) | 14 | 1 file changed, 1 insertion(+) |
12 | 15 | ||
13 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c | 16 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
14 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/riscv/kvm/kvm-cpu.c | 18 | --- a/target/riscv/cpu.c |
16 | +++ b/target/riscv/kvm/kvm-cpu.c | 19 | +++ b/target/riscv/cpu.c |
17 | @@ -XXX,XX +XXX,XX @@ static KVMCPUConfig kvm_multi_ext_cfgs[] = { | 20 | @@ -XXX,XX +XXX,XX @@ static const struct isa_ext_data isa_edata_arr[] = { |
18 | KVM_EXT_CFG("zicbom", ext_zicbom, KVM_RISCV_ISA_EXT_ZICBOM), | 21 | ISA_EXT_DATA_ENTRY(zicsr, PRIV_VERSION_1_10_0, ext_icsr), |
19 | KVM_EXT_CFG("zicboz", ext_zicboz, KVM_RISCV_ISA_EXT_ZICBOZ), | 22 | ISA_EXT_DATA_ENTRY(zifencei, PRIV_VERSION_1_10_0, ext_ifencei), |
20 | KVM_EXT_CFG("zicntr", ext_zicntr, KVM_RISCV_ISA_EXT_ZICNTR), | 23 | ISA_EXT_DATA_ENTRY(zihintpause, PRIV_VERSION_1_10_0, ext_zihintpause), |
21 | + KVM_EXT_CFG("zicond", ext_zicond, KVM_RISCV_ISA_EXT_ZICOND), | 24 | + ISA_EXT_DATA_ENTRY(zmmul, PRIV_VERSION_1_12_0, ext_zmmul), |
22 | KVM_EXT_CFG("zicsr", ext_zicsr, KVM_RISCV_ISA_EXT_ZICSR), | 25 | ISA_EXT_DATA_ENTRY(zawrs, PRIV_VERSION_1_12_0, ext_zawrs), |
23 | KVM_EXT_CFG("zifencei", ext_zifencei, KVM_RISCV_ISA_EXT_ZIFENCEI), | 26 | ISA_EXT_DATA_ENTRY(zfa, PRIV_VERSION_1_12_0, ext_zfa), |
24 | + KVM_EXT_CFG("zihintntl", ext_zihintntl, KVM_RISCV_ISA_EXT_ZIHINTNTL), | 27 | ISA_EXT_DATA_ENTRY(zfbfmin, PRIV_VERSION_1_12_0, ext_zfbfmin), |
25 | KVM_EXT_CFG("zihintpause", ext_zihintpause, KVM_RISCV_ISA_EXT_ZIHINTPAUSE), | ||
26 | KVM_EXT_CFG("zihpm", ext_zihpm, KVM_RISCV_ISA_EXT_ZIHPM), | ||
27 | + KVM_EXT_CFG("zfa", ext_zfa, KVM_RISCV_ISA_EXT_ZFA), | ||
28 | + KVM_EXT_CFG("zfh", ext_zfh, KVM_RISCV_ISA_EXT_ZFH), | ||
29 | + KVM_EXT_CFG("zfhmin", ext_zfhmin, KVM_RISCV_ISA_EXT_ZFHMIN), | ||
30 | KVM_EXT_CFG("zba", ext_zba, KVM_RISCV_ISA_EXT_ZBA), | ||
31 | KVM_EXT_CFG("zbb", ext_zbb, KVM_RISCV_ISA_EXT_ZBB), | ||
32 | + KVM_EXT_CFG("zbc", ext_zbc, KVM_RISCV_ISA_EXT_ZBC), | ||
33 | + KVM_EXT_CFG("zbkb", ext_zbkb, KVM_RISCV_ISA_EXT_ZBKB), | ||
34 | + KVM_EXT_CFG("zbkc", ext_zbkc, KVM_RISCV_ISA_EXT_ZBKC), | ||
35 | + KVM_EXT_CFG("zbkx", ext_zbkx, KVM_RISCV_ISA_EXT_ZBKX), | ||
36 | KVM_EXT_CFG("zbs", ext_zbs, KVM_RISCV_ISA_EXT_ZBS), | ||
37 | + KVM_EXT_CFG("zknd", ext_zknd, KVM_RISCV_ISA_EXT_ZKND), | ||
38 | + KVM_EXT_CFG("zkne", ext_zkne, KVM_RISCV_ISA_EXT_ZKNE), | ||
39 | + KVM_EXT_CFG("zknh", ext_zknh, KVM_RISCV_ISA_EXT_ZKNH), | ||
40 | + KVM_EXT_CFG("zkr", ext_zkr, KVM_RISCV_ISA_EXT_ZKR), | ||
41 | + KVM_EXT_CFG("zksed", ext_zksed, KVM_RISCV_ISA_EXT_ZKSED), | ||
42 | + KVM_EXT_CFG("zksh", ext_zksh, KVM_RISCV_ISA_EXT_ZKSH), | ||
43 | + KVM_EXT_CFG("zkt", ext_zkt, KVM_RISCV_ISA_EXT_ZKT), | ||
44 | + KVM_EXT_CFG("zvbb", ext_zvbb, KVM_RISCV_ISA_EXT_ZVBB), | ||
45 | + KVM_EXT_CFG("zvbc", ext_zvbc, KVM_RISCV_ISA_EXT_ZVBC), | ||
46 | + KVM_EXT_CFG("zvfh", ext_zvfh, KVM_RISCV_ISA_EXT_ZVFH), | ||
47 | + KVM_EXT_CFG("zvfhmin", ext_zvfhmin, KVM_RISCV_ISA_EXT_ZVFHMIN), | ||
48 | + KVM_EXT_CFG("zvkb", ext_zvkb, KVM_RISCV_ISA_EXT_ZVKB), | ||
49 | + KVM_EXT_CFG("zvkg", ext_zvkg, KVM_RISCV_ISA_EXT_ZVKG), | ||
50 | + KVM_EXT_CFG("zvkned", ext_zvkned, KVM_RISCV_ISA_EXT_ZVKNED), | ||
51 | + KVM_EXT_CFG("zvknha", ext_zvknha, KVM_RISCV_ISA_EXT_ZVKNHA), | ||
52 | + KVM_EXT_CFG("zvknhb", ext_zvknhb, KVM_RISCV_ISA_EXT_ZVKNHB), | ||
53 | + KVM_EXT_CFG("zvksed", ext_zvksed, KVM_RISCV_ISA_EXT_ZVKSED), | ||
54 | + KVM_EXT_CFG("zvksh", ext_zvksh, KVM_RISCV_ISA_EXT_ZVKSH), | ||
55 | + KVM_EXT_CFG("zvkt", ext_zvkt, KVM_RISCV_ISA_EXT_ZVKT), | ||
56 | + KVM_EXT_CFG("smstateen", ext_smstateen, KVM_RISCV_ISA_EXT_SMSTATEEN), | ||
57 | KVM_EXT_CFG("ssaia", ext_ssaia, KVM_RISCV_ISA_EXT_SSAIA), | ||
58 | KVM_EXT_CFG("sstc", ext_sstc, KVM_RISCV_ISA_EXT_SSTC), | ||
59 | KVM_EXT_CFG("svinval", ext_svinval, KVM_RISCV_ISA_EXT_SVINVAL), | ||
60 | -- | 28 | -- |
61 | 2.44.0 | 29 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Recent changes in options handling removed the 'mmu' default the bare | 3 | The cpu->cfg.epmp extension is still experimental, but it already has a |
4 | CPUs had, meaning that we must enable 'mmu' by hand when using the | 4 | 'smepmp' riscv,isa string. Add it. |
5 | rva22s64 profile CPU. | ||
6 | |||
7 | Given that this profile is setting a satp mode, it already implies that | ||
8 | we need a 'mmu'. Enable the 'mmu' in this case. | ||
9 | 5 | ||
10 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 6 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
7 | Reviewed-by: Weiwei Li <liweiwei@iscas.ac.cn> | ||
11 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
12 | Message-ID: <20240215223955.969568-2-dbarboza@ventanamicro.com> | 9 | Message-Id: <20230720132424.371132-3-dbarboza@ventanamicro.com> |
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
14 | --- | 11 | --- |
15 | target/riscv/tcg/tcg-cpu.c | 1 + | 12 | target/riscv/cpu.c | 1 + |
16 | 1 file changed, 1 insertion(+) | 13 | 1 file changed, 1 insertion(+) |
17 | 14 | ||
18 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | 15 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
19 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/riscv/tcg/tcg-cpu.c | 17 | --- a/target/riscv/cpu.c |
21 | +++ b/target/riscv/tcg/tcg-cpu.c | 18 | +++ b/target/riscv/cpu.c |
22 | @@ -XXX,XX +XXX,XX @@ static void cpu_set_profile(Object *obj, Visitor *v, const char *name, | 19 | @@ -XXX,XX +XXX,XX @@ static const struct isa_ext_data isa_edata_arr[] = { |
23 | 20 | ISA_EXT_DATA_ENTRY(zhinx, PRIV_VERSION_1_12_0, ext_zhinx), | |
24 | #ifndef CONFIG_USER_ONLY | 21 | ISA_EXT_DATA_ENTRY(zhinxmin, PRIV_VERSION_1_12_0, ext_zhinxmin), |
25 | if (profile->satp_mode != RISCV_PROFILE_ATTR_UNUSED) { | 22 | ISA_EXT_DATA_ENTRY(smaia, PRIV_VERSION_1_12_0, ext_smaia), |
26 | + object_property_set_bool(obj, "mmu", true, NULL); | 23 | + ISA_EXT_DATA_ENTRY(smepmp, PRIV_VERSION_1_12_0, epmp), |
27 | const char *satp_prop = satp_mode_str(profile->satp_mode, | 24 | ISA_EXT_DATA_ENTRY(smstateen, PRIV_VERSION_1_12_0, ext_smstateen), |
28 | riscv_cpu_is_32bit(cpu)); | 25 | ISA_EXT_DATA_ENTRY(ssaia, PRIV_VERSION_1_12_0, ext_ssaia), |
29 | object_property_set_bool(obj, satp_prop, profile->enabled, NULL); | 26 | ISA_EXT_DATA_ENTRY(sscofpmf, PRIV_VERSION_1_12_0, ext_sscofpmf), |
30 | -- | 27 | -- |
31 | 2.44.0 | 28 | 2.41.0 | diff view generated by jsdifflib |
1 | From: "demin.han" <demin.han@starfivetech.com> | 1 | From: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
---|---|---|---|
2 | 2 | ||
3 | The result of (8 - 3 - vlmul) is negative when vlmul >= 6, | 3 | Commit bef6f008b98(accel/tcg: Return bool from page_check_range) converts |
4 | and results in wrong vill. | 4 | integer return value to bool type. However, it wrongly converted the use |
5 | of the API in riscv fault-only-first, where page_check_range < = 0, should | ||
6 | be converted to !page_check_range. | ||
5 | 7 | ||
6 | Signed-off-by: demin.han <demin.han@starfivetech.com> | 8 | Signed-off-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
7 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Message-ID: <20240225174114.5298-1-demin.han@starfivetech.com> | 10 | Message-ID: <20230729031618.821-1-zhiwei_liu@linux.alibaba.com> |
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 12 | --- |
11 | target/riscv/vector_helper.c | 5 ++--- | 13 | target/riscv/vector_helper.c | 2 +- |
12 | 1 file changed, 2 insertions(+), 3 deletions(-) | 14 | 1 file changed, 1 insertion(+), 1 deletion(-) |
13 | 15 | ||
14 | diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c | 16 | diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c |
15 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/riscv/vector_helper.c | 18 | --- a/target/riscv/vector_helper.c |
17 | +++ b/target/riscv/vector_helper.c | 19 | +++ b/target/riscv/vector_helper.c |
18 | @@ -XXX,XX +XXX,XX @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1, | 20 | @@ -XXX,XX +XXX,XX @@ vext_ldff(void *vd, void *v0, target_ulong base, |
19 | target_ulong reserved = s2 & | 21 | cpu_mmu_index(env, false)); |
20 | MAKE_64BIT_MASK(R_VTYPE_RESERVED_SHIFT, | 22 | if (host) { |
21 | xlen - 1 - R_VTYPE_RESERVED_SHIFT); | 23 | #ifdef CONFIG_USER_ONLY |
22 | + uint16_t vlen = cpu->cfg.vlenb << 3; | 24 | - if (page_check_range(addr, offset, PAGE_READ)) { |
23 | int8_t lmul; | 25 | + if (!page_check_range(addr, offset, PAGE_READ)) { |
24 | 26 | vl = i; | |
25 | if (vlmul & 4) { | 27 | goto ProbeSuccess; |
26 | @@ -XXX,XX +XXX,XX @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1, | 28 | } |
27 | * VLEN * LMUL >= SEW | ||
28 | * VLEN >> (8 - lmul) >= sew | ||
29 | * (vlenb << 3) >> (8 - lmul) >= sew | ||
30 | - * vlenb >> (8 - 3 - lmul) >= sew | ||
31 | */ | ||
32 | - if (vlmul == 4 || | ||
33 | - cpu->cfg.vlenb >> (8 - 3 - vlmul) < sew) { | ||
34 | + if (vlmul == 4 || (vlen >> (8 - vlmul)) < sew) { | ||
35 | vill = true; | ||
36 | } | ||
37 | } | ||
38 | -- | 29 | -- |
39 | 2.44.0 | 30 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Christoph Müllner <christoph.muellner@vrull.eu> | 1 | From: Ard Biesheuvel <ardb@kernel.org> |
---|---|---|---|
2 | 2 | ||
3 | Upstream Linux recently added RISC-V Zicboz support to the hwprobe API. | 3 | The AES MixColumns and InvMixColumns operations are relatively |
4 | This patch introduces this for QEMU's user space emulator. | 4 | expensive 4x4 matrix multiplications in GF(2^8), which is why C |
5 | implementations usually rely on precomputed lookup tables rather than | ||
6 | performing the calculations on demand. | ||
5 | 7 | ||
6 | Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu> | 8 | Given that we already carry those tables in QEMU, we can just grab the |
7 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 9 | right value in the implementation of the RISC-V AES32 instructions. Note |
8 | Message-ID: <20240207115926.887816-2-christoph.muellner@vrull.eu> | 10 | that the tables in question are permuted according to the respective |
11 | Sbox, so we can omit the Sbox lookup as well in this case. | ||
12 | |||
13 | Cc: Richard Henderson <richard.henderson@linaro.org> | ||
14 | Cc: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
15 | Cc: Zewen Ye <lustrew@foxmail.com> | ||
16 | Cc: Weiwei Li <liweiwei@iscas.ac.cn> | ||
17 | Cc: Junqiang Wang <wangjunqiang@iscas.ac.cn> | ||
18 | Signed-off-by: Ard Biesheuvel <ardb@kernel.org> | ||
19 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
20 | Message-ID: <20230731084043.1791984-1-ardb@kernel.org> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 21 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 22 | --- |
11 | linux-user/syscall.c | 3 +++ | 23 | include/crypto/aes.h | 7 +++++++ |
12 | 1 file changed, 3 insertions(+) | 24 | crypto/aes.c | 4 ++-- |
25 | target/riscv/crypto_helper.c | 34 ++++------------------------------ | ||
26 | 3 files changed, 13 insertions(+), 32 deletions(-) | ||
13 | 27 | ||
14 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c | 28 | diff --git a/include/crypto/aes.h b/include/crypto/aes.h |
15 | index XXXXXXX..XXXXXXX 100644 | 29 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/linux-user/syscall.c | 30 | --- a/include/crypto/aes.h |
17 | +++ b/linux-user/syscall.c | 31 | +++ b/include/crypto/aes.h |
18 | @@ -XXX,XX +XXX,XX @@ static int do_getdents64(abi_long dirfd, abi_long arg2, abi_long count) | 32 | @@ -XXX,XX +XXX,XX @@ void AES_decrypt(const unsigned char *in, unsigned char *out, |
19 | #define RISCV_HWPROBE_EXT_ZBA (1 << 3) | 33 | extern const uint8_t AES_sbox[256]; |
20 | #define RISCV_HWPROBE_EXT_ZBB (1 << 4) | 34 | extern const uint8_t AES_isbox[256]; |
21 | #define RISCV_HWPROBE_EXT_ZBS (1 << 5) | 35 | |
22 | +#define RISCV_HWPROBE_EXT_ZICBOZ (1 << 6) | 36 | +/* |
23 | 37 | +AES_Te0[x] = S [x].[02, 01, 01, 03]; | |
24 | #define RISCV_HWPROBE_KEY_CPUPERF_0 5 | 38 | +AES_Td0[x] = Si[x].[0e, 09, 0d, 0b]; |
25 | #define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0) | 39 | +*/ |
26 | @@ -XXX,XX +XXX,XX @@ static void risc_hwprobe_fill_pairs(CPURISCVState *env, | 40 | + |
27 | RISCV_HWPROBE_EXT_ZBB : 0; | 41 | +extern const uint32_t AES_Te0[256], AES_Td0[256]; |
28 | value |= cfg->ext_zbs ? | 42 | + |
29 | RISCV_HWPROBE_EXT_ZBS : 0; | 43 | #endif |
30 | + value |= cfg->ext_zicboz ? | 44 | diff --git a/crypto/aes.c b/crypto/aes.c |
31 | + RISCV_HWPROBE_EXT_ZICBOZ : 0; | 45 | index XXXXXXX..XXXXXXX 100644 |
32 | __put_user(value, &pair->value); | 46 | --- a/crypto/aes.c |
33 | break; | 47 | +++ b/crypto/aes.c |
34 | case RISCV_HWPROBE_KEY_CPUPERF_0: | 48 | @@ -XXX,XX +XXX,XX @@ AES_Td3[x] = Si[x].[09, 0d, 0b, 0e]; |
49 | AES_Td4[x] = Si[x].[01, 01, 01, 01]; | ||
50 | */ | ||
51 | |||
52 | -static const uint32_t AES_Te0[256] = { | ||
53 | +const uint32_t AES_Te0[256] = { | ||
54 | 0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU, | ||
55 | 0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U, | ||
56 | 0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU, | ||
57 | @@ -XXX,XX +XXX,XX @@ static const uint32_t AES_Te4[256] = { | ||
58 | 0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U, | ||
59 | }; | ||
60 | |||
61 | -static const uint32_t AES_Td0[256] = { | ||
62 | +const uint32_t AES_Td0[256] = { | ||
63 | 0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U, | ||
64 | 0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U, | ||
65 | 0x2030fa55U, 0xad766df6U, 0x88cc7691U, 0xf5024c25U, | ||
66 | diff --git a/target/riscv/crypto_helper.c b/target/riscv/crypto_helper.c | ||
67 | index XXXXXXX..XXXXXXX 100644 | ||
68 | --- a/target/riscv/crypto_helper.c | ||
69 | +++ b/target/riscv/crypto_helper.c | ||
70 | @@ -XXX,XX +XXX,XX @@ | ||
71 | #include "crypto/aes-round.h" | ||
72 | #include "crypto/sm4.h" | ||
73 | |||
74 | -#define AES_XTIME(a) \ | ||
75 | - ((a << 1) ^ ((a & 0x80) ? 0x1b : 0)) | ||
76 | - | ||
77 | -#define AES_GFMUL(a, b) (( \ | ||
78 | - (((b) & 0x1) ? (a) : 0) ^ \ | ||
79 | - (((b) & 0x2) ? AES_XTIME(a) : 0) ^ \ | ||
80 | - (((b) & 0x4) ? AES_XTIME(AES_XTIME(a)) : 0) ^ \ | ||
81 | - (((b) & 0x8) ? AES_XTIME(AES_XTIME(AES_XTIME(a))) : 0)) & 0xFF) | ||
82 | - | ||
83 | -static inline uint32_t aes_mixcolumn_byte(uint8_t x, bool fwd) | ||
84 | -{ | ||
85 | - uint32_t u; | ||
86 | - | ||
87 | - if (fwd) { | ||
88 | - u = (AES_GFMUL(x, 3) << 24) | (x << 16) | (x << 8) | | ||
89 | - (AES_GFMUL(x, 2) << 0); | ||
90 | - } else { | ||
91 | - u = (AES_GFMUL(x, 0xb) << 24) | (AES_GFMUL(x, 0xd) << 16) | | ||
92 | - (AES_GFMUL(x, 0x9) << 8) | (AES_GFMUL(x, 0xe) << 0); | ||
93 | - } | ||
94 | - return u; | ||
95 | -} | ||
96 | - | ||
97 | #define sext32_xlen(x) (target_ulong)(int32_t)(x) | ||
98 | |||
99 | static inline target_ulong aes32_operation(target_ulong shamt, | ||
100 | @@ -XXX,XX +XXX,XX @@ static inline target_ulong aes32_operation(target_ulong shamt, | ||
101 | bool enc, bool mix) | ||
102 | { | ||
103 | uint8_t si = rs2 >> shamt; | ||
104 | - uint8_t so; | ||
105 | uint32_t mixed; | ||
106 | target_ulong res; | ||
107 | |||
108 | if (enc) { | ||
109 | - so = AES_sbox[si]; | ||
110 | if (mix) { | ||
111 | - mixed = aes_mixcolumn_byte(so, true); | ||
112 | + mixed = be32_to_cpu(AES_Te0[si]); | ||
113 | } else { | ||
114 | - mixed = so; | ||
115 | + mixed = AES_sbox[si]; | ||
116 | } | ||
117 | } else { | ||
118 | - so = AES_isbox[si]; | ||
119 | if (mix) { | ||
120 | - mixed = aes_mixcolumn_byte(so, false); | ||
121 | + mixed = be32_to_cpu(AES_Td0[si]); | ||
122 | } else { | ||
123 | - mixed = so; | ||
124 | + mixed = AES_isbox[si]; | ||
125 | } | ||
126 | } | ||
127 | mixed = rol32(mixed, shamt); | ||
35 | -- | 128 | -- |
36 | 2.44.0 | 129 | 2.41.0 |
37 | 130 | ||
38 | 131 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Kiran Ostrolenk <kiran.ostrolenk@codethink.co.uk> | ||
1 | 2 | ||
3 | Take some functions/macros out of `vector_helper` and put them in a new | ||
4 | module called `vector_internals`. This ensures they can be used by both | ||
5 | vector and vector-crypto helpers (latter implemented in proceeding | ||
6 | commits). | ||
7 | |||
8 | Signed-off-by: Kiran Ostrolenk <kiran.ostrolenk@codethink.co.uk> | ||
9 | Reviewed-by: Weiwei Li <liweiwei@iscas.ac.cn> | ||
10 | Signed-off-by: Max Chou <max.chou@sifive.com> | ||
11 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | Message-ID: <20230711165917.2629866-2-max.chou@sifive.com> | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
14 | --- | ||
15 | target/riscv/vector_internals.h | 182 +++++++++++++++++++++++++++++ | ||
16 | target/riscv/vector_helper.c | 201 +------------------------------- | ||
17 | target/riscv/vector_internals.c | 81 +++++++++++++ | ||
18 | target/riscv/meson.build | 1 + | ||
19 | 4 files changed, 265 insertions(+), 200 deletions(-) | ||
20 | create mode 100644 target/riscv/vector_internals.h | ||
21 | create mode 100644 target/riscv/vector_internals.c | ||
22 | |||
23 | diff --git a/target/riscv/vector_internals.h b/target/riscv/vector_internals.h | ||
24 | new file mode 100644 | ||
25 | index XXXXXXX..XXXXXXX | ||
26 | --- /dev/null | ||
27 | +++ b/target/riscv/vector_internals.h | ||
28 | @@ -XXX,XX +XXX,XX @@ | ||
29 | +/* | ||
30 | + * RISC-V Vector Extension Internals | ||
31 | + * | ||
32 | + * Copyright (c) 2020 T-Head Semiconductor Co., Ltd. All rights reserved. | ||
33 | + * | ||
34 | + * This program is free software; you can redistribute it and/or modify it | ||
35 | + * under the terms and conditions of the GNU General Public License, | ||
36 | + * version 2 or later, as published by the Free Software Foundation. | ||
37 | + * | ||
38 | + * This program is distributed in the hope it will be useful, but WITHOUT | ||
39 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
40 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
41 | + * more details. | ||
42 | + * | ||
43 | + * You should have received a copy of the GNU General Public License along with | ||
44 | + * this program. If not, see <http://www.gnu.org/licenses/>. | ||
45 | + */ | ||
46 | + | ||
47 | +#ifndef TARGET_RISCV_VECTOR_INTERNALS_H | ||
48 | +#define TARGET_RISCV_VECTOR_INTERNALS_H | ||
49 | + | ||
50 | +#include "qemu/osdep.h" | ||
51 | +#include "qemu/bitops.h" | ||
52 | +#include "cpu.h" | ||
53 | +#include "tcg/tcg-gvec-desc.h" | ||
54 | +#include "internals.h" | ||
55 | + | ||
56 | +static inline uint32_t vext_nf(uint32_t desc) | ||
57 | +{ | ||
58 | + return FIELD_EX32(simd_data(desc), VDATA, NF); | ||
59 | +} | ||
60 | + | ||
61 | +/* | ||
62 | + * Note that vector data is stored in host-endian 64-bit chunks, | ||
63 | + * so addressing units smaller than that needs a host-endian fixup. | ||
64 | + */ | ||
65 | +#if HOST_BIG_ENDIAN | ||
66 | +#define H1(x) ((x) ^ 7) | ||
67 | +#define H1_2(x) ((x) ^ 6) | ||
68 | +#define H1_4(x) ((x) ^ 4) | ||
69 | +#define H2(x) ((x) ^ 3) | ||
70 | +#define H4(x) ((x) ^ 1) | ||
71 | +#define H8(x) ((x)) | ||
72 | +#else | ||
73 | +#define H1(x) (x) | ||
74 | +#define H1_2(x) (x) | ||
75 | +#define H1_4(x) (x) | ||
76 | +#define H2(x) (x) | ||
77 | +#define H4(x) (x) | ||
78 | +#define H8(x) (x) | ||
79 | +#endif | ||
80 | + | ||
81 | +/* | ||
82 | + * Encode LMUL to lmul as following: | ||
83 | + * LMUL vlmul lmul | ||
84 | + * 1 000 0 | ||
85 | + * 2 001 1 | ||
86 | + * 4 010 2 | ||
87 | + * 8 011 3 | ||
88 | + * - 100 - | ||
89 | + * 1/8 101 -3 | ||
90 | + * 1/4 110 -2 | ||
91 | + * 1/2 111 -1 | ||
92 | + */ | ||
93 | +static inline int32_t vext_lmul(uint32_t desc) | ||
94 | +{ | ||
95 | + return sextract32(FIELD_EX32(simd_data(desc), VDATA, LMUL), 0, 3); | ||
96 | +} | ||
97 | + | ||
98 | +static inline uint32_t vext_vm(uint32_t desc) | ||
99 | +{ | ||
100 | + return FIELD_EX32(simd_data(desc), VDATA, VM); | ||
101 | +} | ||
102 | + | ||
103 | +static inline uint32_t vext_vma(uint32_t desc) | ||
104 | +{ | ||
105 | + return FIELD_EX32(simd_data(desc), VDATA, VMA); | ||
106 | +} | ||
107 | + | ||
108 | +static inline uint32_t vext_vta(uint32_t desc) | ||
109 | +{ | ||
110 | + return FIELD_EX32(simd_data(desc), VDATA, VTA); | ||
111 | +} | ||
112 | + | ||
113 | +static inline uint32_t vext_vta_all_1s(uint32_t desc) | ||
114 | +{ | ||
115 | + return FIELD_EX32(simd_data(desc), VDATA, VTA_ALL_1S); | ||
116 | +} | ||
117 | + | ||
118 | +/* | ||
119 | + * Earlier designs (pre-0.9) had a varying number of bits | ||
120 | + * per mask value (MLEN). In the 0.9 design, MLEN=1. | ||
121 | + * (Section 4.5) | ||
122 | + */ | ||
123 | +static inline int vext_elem_mask(void *v0, int index) | ||
124 | +{ | ||
125 | + int idx = index / 64; | ||
126 | + int pos = index % 64; | ||
127 | + return (((uint64_t *)v0)[idx] >> pos) & 1; | ||
128 | +} | ||
129 | + | ||
130 | +/* | ||
131 | + * Get number of total elements, including prestart, body and tail elements. | ||
132 | + * Note that when LMUL < 1, the tail includes the elements past VLMAX that | ||
133 | + * are held in the same vector register. | ||
134 | + */ | ||
135 | +static inline uint32_t vext_get_total_elems(CPURISCVState *env, uint32_t desc, | ||
136 | + uint32_t esz) | ||
137 | +{ | ||
138 | + uint32_t vlenb = simd_maxsz(desc); | ||
139 | + uint32_t sew = 1 << FIELD_EX64(env->vtype, VTYPE, VSEW); | ||
140 | + int8_t emul = ctzl(esz) - ctzl(sew) + vext_lmul(desc) < 0 ? 0 : | ||
141 | + ctzl(esz) - ctzl(sew) + vext_lmul(desc); | ||
142 | + return (vlenb << emul) / esz; | ||
143 | +} | ||
144 | + | ||
145 | +/* set agnostic elements to 1s */ | ||
146 | +void vext_set_elems_1s(void *base, uint32_t is_agnostic, uint32_t cnt, | ||
147 | + uint32_t tot); | ||
148 | + | ||
149 | +/* expand macro args before macro */ | ||
150 | +#define RVVCALL(macro, ...) macro(__VA_ARGS__) | ||
151 | + | ||
152 | +/* (TD, T1, T2, TX1, TX2) */ | ||
153 | +#define OP_UUU_B uint8_t, uint8_t, uint8_t, uint8_t, uint8_t | ||
154 | +#define OP_UUU_H uint16_t, uint16_t, uint16_t, uint16_t, uint16_t | ||
155 | +#define OP_UUU_W uint32_t, uint32_t, uint32_t, uint32_t, uint32_t | ||
156 | +#define OP_UUU_D uint64_t, uint64_t, uint64_t, uint64_t, uint64_t | ||
157 | + | ||
158 | +/* operation of two vector elements */ | ||
159 | +typedef void opivv2_fn(void *vd, void *vs1, void *vs2, int i); | ||
160 | + | ||
161 | +#define OPIVV2(NAME, TD, T1, T2, TX1, TX2, HD, HS1, HS2, OP) \ | ||
162 | +static void do_##NAME(void *vd, void *vs1, void *vs2, int i) \ | ||
163 | +{ \ | ||
164 | + TX1 s1 = *((T1 *)vs1 + HS1(i)); \ | ||
165 | + TX2 s2 = *((T2 *)vs2 + HS2(i)); \ | ||
166 | + *((TD *)vd + HD(i)) = OP(s2, s1); \ | ||
167 | +} | ||
168 | + | ||
169 | +void do_vext_vv(void *vd, void *v0, void *vs1, void *vs2, | ||
170 | + CPURISCVState *env, uint32_t desc, | ||
171 | + opivv2_fn *fn, uint32_t esz); | ||
172 | + | ||
173 | +/* generate the helpers for OPIVV */ | ||
174 | +#define GEN_VEXT_VV(NAME, ESZ) \ | ||
175 | +void HELPER(NAME)(void *vd, void *v0, void *vs1, \ | ||
176 | + void *vs2, CPURISCVState *env, \ | ||
177 | + uint32_t desc) \ | ||
178 | +{ \ | ||
179 | + do_vext_vv(vd, v0, vs1, vs2, env, desc, \ | ||
180 | + do_##NAME, ESZ); \ | ||
181 | +} | ||
182 | + | ||
183 | +typedef void opivx2_fn(void *vd, target_long s1, void *vs2, int i); | ||
184 | + | ||
185 | +/* | ||
186 | + * (T1)s1 gives the real operator type. | ||
187 | + * (TX1)(T1)s1 expands the operator type of widen or narrow operations. | ||
188 | + */ | ||
189 | +#define OPIVX2(NAME, TD, T1, T2, TX1, TX2, HD, HS2, OP) \ | ||
190 | +static void do_##NAME(void *vd, target_long s1, void *vs2, int i) \ | ||
191 | +{ \ | ||
192 | + TX2 s2 = *((T2 *)vs2 + HS2(i)); \ | ||
193 | + *((TD *)vd + HD(i)) = OP(s2, (TX1)(T1)s1); \ | ||
194 | +} | ||
195 | + | ||
196 | +void do_vext_vx(void *vd, void *v0, target_long s1, void *vs2, | ||
197 | + CPURISCVState *env, uint32_t desc, | ||
198 | + opivx2_fn fn, uint32_t esz); | ||
199 | + | ||
200 | +/* generate the helpers for OPIVX */ | ||
201 | +#define GEN_VEXT_VX(NAME, ESZ) \ | ||
202 | +void HELPER(NAME)(void *vd, void *v0, target_ulong s1, \ | ||
203 | + void *vs2, CPURISCVState *env, \ | ||
204 | + uint32_t desc) \ | ||
205 | +{ \ | ||
206 | + do_vext_vx(vd, v0, s1, vs2, env, desc, \ | ||
207 | + do_##NAME, ESZ); \ | ||
208 | +} | ||
209 | + | ||
210 | +#endif /* TARGET_RISCV_VECTOR_INTERNALS_H */ | ||
211 | diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c | ||
212 | index XXXXXXX..XXXXXXX 100644 | ||
213 | --- a/target/riscv/vector_helper.c | ||
214 | +++ b/target/riscv/vector_helper.c | ||
215 | @@ -XXX,XX +XXX,XX @@ | ||
216 | #include "fpu/softfloat.h" | ||
217 | #include "tcg/tcg-gvec-desc.h" | ||
218 | #include "internals.h" | ||
219 | +#include "vector_internals.h" | ||
220 | #include <math.h> | ||
221 | |||
222 | target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1, | ||
223 | @@ -XXX,XX +XXX,XX @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1, | ||
224 | return vl; | ||
225 | } | ||
226 | |||
227 | -/* | ||
228 | - * Note that vector data is stored in host-endian 64-bit chunks, | ||
229 | - * so addressing units smaller than that needs a host-endian fixup. | ||
230 | - */ | ||
231 | -#if HOST_BIG_ENDIAN | ||
232 | -#define H1(x) ((x) ^ 7) | ||
233 | -#define H1_2(x) ((x) ^ 6) | ||
234 | -#define H1_4(x) ((x) ^ 4) | ||
235 | -#define H2(x) ((x) ^ 3) | ||
236 | -#define H4(x) ((x) ^ 1) | ||
237 | -#define H8(x) ((x)) | ||
238 | -#else | ||
239 | -#define H1(x) (x) | ||
240 | -#define H1_2(x) (x) | ||
241 | -#define H1_4(x) (x) | ||
242 | -#define H2(x) (x) | ||
243 | -#define H4(x) (x) | ||
244 | -#define H8(x) (x) | ||
245 | -#endif | ||
246 | - | ||
247 | -static inline uint32_t vext_nf(uint32_t desc) | ||
248 | -{ | ||
249 | - return FIELD_EX32(simd_data(desc), VDATA, NF); | ||
250 | -} | ||
251 | - | ||
252 | -static inline uint32_t vext_vm(uint32_t desc) | ||
253 | -{ | ||
254 | - return FIELD_EX32(simd_data(desc), VDATA, VM); | ||
255 | -} | ||
256 | - | ||
257 | -/* | ||
258 | - * Encode LMUL to lmul as following: | ||
259 | - * LMUL vlmul lmul | ||
260 | - * 1 000 0 | ||
261 | - * 2 001 1 | ||
262 | - * 4 010 2 | ||
263 | - * 8 011 3 | ||
264 | - * - 100 - | ||
265 | - * 1/8 101 -3 | ||
266 | - * 1/4 110 -2 | ||
267 | - * 1/2 111 -1 | ||
268 | - */ | ||
269 | -static inline int32_t vext_lmul(uint32_t desc) | ||
270 | -{ | ||
271 | - return sextract32(FIELD_EX32(simd_data(desc), VDATA, LMUL), 0, 3); | ||
272 | -} | ||
273 | - | ||
274 | -static inline uint32_t vext_vta(uint32_t desc) | ||
275 | -{ | ||
276 | - return FIELD_EX32(simd_data(desc), VDATA, VTA); | ||
277 | -} | ||
278 | - | ||
279 | -static inline uint32_t vext_vma(uint32_t desc) | ||
280 | -{ | ||
281 | - return FIELD_EX32(simd_data(desc), VDATA, VMA); | ||
282 | -} | ||
283 | - | ||
284 | -static inline uint32_t vext_vta_all_1s(uint32_t desc) | ||
285 | -{ | ||
286 | - return FIELD_EX32(simd_data(desc), VDATA, VTA_ALL_1S); | ||
287 | -} | ||
288 | - | ||
289 | /* | ||
290 | * Get the maximum number of elements can be operated. | ||
291 | * | ||
292 | @@ -XXX,XX +XXX,XX @@ static inline uint32_t vext_max_elems(uint32_t desc, uint32_t log2_esz) | ||
293 | return scale < 0 ? vlenb >> -scale : vlenb << scale; | ||
294 | } | ||
295 | |||
296 | -/* | ||
297 | - * Get number of total elements, including prestart, body and tail elements. | ||
298 | - * Note that when LMUL < 1, the tail includes the elements past VLMAX that | ||
299 | - * are held in the same vector register. | ||
300 | - */ | ||
301 | -static inline uint32_t vext_get_total_elems(CPURISCVState *env, uint32_t desc, | ||
302 | - uint32_t esz) | ||
303 | -{ | ||
304 | - uint32_t vlenb = simd_maxsz(desc); | ||
305 | - uint32_t sew = 1 << FIELD_EX64(env->vtype, VTYPE, VSEW); | ||
306 | - int8_t emul = ctzl(esz) - ctzl(sew) + vext_lmul(desc) < 0 ? 0 : | ||
307 | - ctzl(esz) - ctzl(sew) + vext_lmul(desc); | ||
308 | - return (vlenb << emul) / esz; | ||
309 | -} | ||
310 | - | ||
311 | static inline target_ulong adjust_addr(CPURISCVState *env, target_ulong addr) | ||
312 | { | ||
313 | return (addr & ~env->cur_pmmask) | env->cur_pmbase; | ||
314 | @@ -XXX,XX +XXX,XX @@ static void probe_pages(CPURISCVState *env, target_ulong addr, | ||
315 | } | ||
316 | } | ||
317 | |||
318 | -/* set agnostic elements to 1s */ | ||
319 | -static void vext_set_elems_1s(void *base, uint32_t is_agnostic, uint32_t cnt, | ||
320 | - uint32_t tot) | ||
321 | -{ | ||
322 | - if (is_agnostic == 0) { | ||
323 | - /* policy undisturbed */ | ||
324 | - return; | ||
325 | - } | ||
326 | - if (tot - cnt == 0) { | ||
327 | - return; | ||
328 | - } | ||
329 | - memset(base + cnt, -1, tot - cnt); | ||
330 | -} | ||
331 | - | ||
332 | static inline void vext_set_elem_mask(void *v0, int index, | ||
333 | uint8_t value) | ||
334 | { | ||
335 | @@ -XXX,XX +XXX,XX @@ static inline void vext_set_elem_mask(void *v0, int index, | ||
336 | ((uint64_t *)v0)[idx] = deposit64(old, pos, 1, value); | ||
337 | } | ||
338 | |||
339 | -/* | ||
340 | - * Earlier designs (pre-0.9) had a varying number of bits | ||
341 | - * per mask value (MLEN). In the 0.9 design, MLEN=1. | ||
342 | - * (Section 4.5) | ||
343 | - */ | ||
344 | -static inline int vext_elem_mask(void *v0, int index) | ||
345 | -{ | ||
346 | - int idx = index / 64; | ||
347 | - int pos = index % 64; | ||
348 | - return (((uint64_t *)v0)[idx] >> pos) & 1; | ||
349 | -} | ||
350 | - | ||
351 | /* elements operations for load and store */ | ||
352 | typedef void vext_ldst_elem_fn(CPURISCVState *env, abi_ptr addr, | ||
353 | uint32_t idx, void *vd, uintptr_t retaddr); | ||
354 | @@ -XXX,XX +XXX,XX @@ GEN_VEXT_ST_WHOLE(vs8r_v, int8_t, ste_b) | ||
355 | * Vector Integer Arithmetic Instructions | ||
356 | */ | ||
357 | |||
358 | -/* expand macro args before macro */ | ||
359 | -#define RVVCALL(macro, ...) macro(__VA_ARGS__) | ||
360 | - | ||
361 | /* (TD, T1, T2, TX1, TX2) */ | ||
362 | #define OP_SSS_B int8_t, int8_t, int8_t, int8_t, int8_t | ||
363 | #define OP_SSS_H int16_t, int16_t, int16_t, int16_t, int16_t | ||
364 | #define OP_SSS_W int32_t, int32_t, int32_t, int32_t, int32_t | ||
365 | #define OP_SSS_D int64_t, int64_t, int64_t, int64_t, int64_t | ||
366 | -#define OP_UUU_B uint8_t, uint8_t, uint8_t, uint8_t, uint8_t | ||
367 | -#define OP_UUU_H uint16_t, uint16_t, uint16_t, uint16_t, uint16_t | ||
368 | -#define OP_UUU_W uint32_t, uint32_t, uint32_t, uint32_t, uint32_t | ||
369 | -#define OP_UUU_D uint64_t, uint64_t, uint64_t, uint64_t, uint64_t | ||
370 | #define OP_SUS_B int8_t, uint8_t, int8_t, uint8_t, int8_t | ||
371 | #define OP_SUS_H int16_t, uint16_t, int16_t, uint16_t, int16_t | ||
372 | #define OP_SUS_W int32_t, uint32_t, int32_t, uint32_t, int32_t | ||
373 | @@ -XXX,XX +XXX,XX @@ GEN_VEXT_ST_WHOLE(vs8r_v, int8_t, ste_b) | ||
374 | #define NOP_UUU_H uint16_t, uint16_t, uint32_t, uint16_t, uint32_t | ||
375 | #define NOP_UUU_W uint32_t, uint32_t, uint64_t, uint32_t, uint64_t | ||
376 | |||
377 | -/* operation of two vector elements */ | ||
378 | -typedef void opivv2_fn(void *vd, void *vs1, void *vs2, int i); | ||
379 | - | ||
380 | -#define OPIVV2(NAME, TD, T1, T2, TX1, TX2, HD, HS1, HS2, OP) \ | ||
381 | -static void do_##NAME(void *vd, void *vs1, void *vs2, int i) \ | ||
382 | -{ \ | ||
383 | - TX1 s1 = *((T1 *)vs1 + HS1(i)); \ | ||
384 | - TX2 s2 = *((T2 *)vs2 + HS2(i)); \ | ||
385 | - *((TD *)vd + HD(i)) = OP(s2, s1); \ | ||
386 | -} | ||
387 | #define DO_SUB(N, M) (N - M) | ||
388 | #define DO_RSUB(N, M) (M - N) | ||
389 | |||
390 | @@ -XXX,XX +XXX,XX @@ RVVCALL(OPIVV2, vsub_vv_h, OP_SSS_H, H2, H2, H2, DO_SUB) | ||
391 | RVVCALL(OPIVV2, vsub_vv_w, OP_SSS_W, H4, H4, H4, DO_SUB) | ||
392 | RVVCALL(OPIVV2, vsub_vv_d, OP_SSS_D, H8, H8, H8, DO_SUB) | ||
393 | |||
394 | -static void do_vext_vv(void *vd, void *v0, void *vs1, void *vs2, | ||
395 | - CPURISCVState *env, uint32_t desc, | ||
396 | - opivv2_fn *fn, uint32_t esz) | ||
397 | -{ | ||
398 | - uint32_t vm = vext_vm(desc); | ||
399 | - uint32_t vl = env->vl; | ||
400 | - uint32_t total_elems = vext_get_total_elems(env, desc, esz); | ||
401 | - uint32_t vta = vext_vta(desc); | ||
402 | - uint32_t vma = vext_vma(desc); | ||
403 | - uint32_t i; | ||
404 | - | ||
405 | - for (i = env->vstart; i < vl; i++) { | ||
406 | - if (!vm && !vext_elem_mask(v0, i)) { | ||
407 | - /* set masked-off elements to 1s */ | ||
408 | - vext_set_elems_1s(vd, vma, i * esz, (i + 1) * esz); | ||
409 | - continue; | ||
410 | - } | ||
411 | - fn(vd, vs1, vs2, i); | ||
412 | - } | ||
413 | - env->vstart = 0; | ||
414 | - /* set tail elements to 1s */ | ||
415 | - vext_set_elems_1s(vd, vta, vl * esz, total_elems * esz); | ||
416 | -} | ||
417 | - | ||
418 | -/* generate the helpers for OPIVV */ | ||
419 | -#define GEN_VEXT_VV(NAME, ESZ) \ | ||
420 | -void HELPER(NAME)(void *vd, void *v0, void *vs1, \ | ||
421 | - void *vs2, CPURISCVState *env, \ | ||
422 | - uint32_t desc) \ | ||
423 | -{ \ | ||
424 | - do_vext_vv(vd, v0, vs1, vs2, env, desc, \ | ||
425 | - do_##NAME, ESZ); \ | ||
426 | -} | ||
427 | - | ||
428 | GEN_VEXT_VV(vadd_vv_b, 1) | ||
429 | GEN_VEXT_VV(vadd_vv_h, 2) | ||
430 | GEN_VEXT_VV(vadd_vv_w, 4) | ||
431 | @@ -XXX,XX +XXX,XX @@ GEN_VEXT_VV(vsub_vv_h, 2) | ||
432 | GEN_VEXT_VV(vsub_vv_w, 4) | ||
433 | GEN_VEXT_VV(vsub_vv_d, 8) | ||
434 | |||
435 | -typedef void opivx2_fn(void *vd, target_long s1, void *vs2, int i); | ||
436 | - | ||
437 | -/* | ||
438 | - * (T1)s1 gives the real operator type. | ||
439 | - * (TX1)(T1)s1 expands the operator type of widen or narrow operations. | ||
440 | - */ | ||
441 | -#define OPIVX2(NAME, TD, T1, T2, TX1, TX2, HD, HS2, OP) \ | ||
442 | -static void do_##NAME(void *vd, target_long s1, void *vs2, int i) \ | ||
443 | -{ \ | ||
444 | - TX2 s2 = *((T2 *)vs2 + HS2(i)); \ | ||
445 | - *((TD *)vd + HD(i)) = OP(s2, (TX1)(T1)s1); \ | ||
446 | -} | ||
447 | |||
448 | RVVCALL(OPIVX2, vadd_vx_b, OP_SSS_B, H1, H1, DO_ADD) | ||
449 | RVVCALL(OPIVX2, vadd_vx_h, OP_SSS_H, H2, H2, DO_ADD) | ||
450 | @@ -XXX,XX +XXX,XX @@ RVVCALL(OPIVX2, vrsub_vx_h, OP_SSS_H, H2, H2, DO_RSUB) | ||
451 | RVVCALL(OPIVX2, vrsub_vx_w, OP_SSS_W, H4, H4, DO_RSUB) | ||
452 | RVVCALL(OPIVX2, vrsub_vx_d, OP_SSS_D, H8, H8, DO_RSUB) | ||
453 | |||
454 | -static void do_vext_vx(void *vd, void *v0, target_long s1, void *vs2, | ||
455 | - CPURISCVState *env, uint32_t desc, | ||
456 | - opivx2_fn fn, uint32_t esz) | ||
457 | -{ | ||
458 | - uint32_t vm = vext_vm(desc); | ||
459 | - uint32_t vl = env->vl; | ||
460 | - uint32_t total_elems = vext_get_total_elems(env, desc, esz); | ||
461 | - uint32_t vta = vext_vta(desc); | ||
462 | - uint32_t vma = vext_vma(desc); | ||
463 | - uint32_t i; | ||
464 | - | ||
465 | - for (i = env->vstart; i < vl; i++) { | ||
466 | - if (!vm && !vext_elem_mask(v0, i)) { | ||
467 | - /* set masked-off elements to 1s */ | ||
468 | - vext_set_elems_1s(vd, vma, i * esz, (i + 1) * esz); | ||
469 | - continue; | ||
470 | - } | ||
471 | - fn(vd, s1, vs2, i); | ||
472 | - } | ||
473 | - env->vstart = 0; | ||
474 | - /* set tail elements to 1s */ | ||
475 | - vext_set_elems_1s(vd, vta, vl * esz, total_elems * esz); | ||
476 | -} | ||
477 | - | ||
478 | -/* generate the helpers for OPIVX */ | ||
479 | -#define GEN_VEXT_VX(NAME, ESZ) \ | ||
480 | -void HELPER(NAME)(void *vd, void *v0, target_ulong s1, \ | ||
481 | - void *vs2, CPURISCVState *env, \ | ||
482 | - uint32_t desc) \ | ||
483 | -{ \ | ||
484 | - do_vext_vx(vd, v0, s1, vs2, env, desc, \ | ||
485 | - do_##NAME, ESZ); \ | ||
486 | -} | ||
487 | - | ||
488 | GEN_VEXT_VX(vadd_vx_b, 1) | ||
489 | GEN_VEXT_VX(vadd_vx_h, 2) | ||
490 | GEN_VEXT_VX(vadd_vx_w, 4) | ||
491 | diff --git a/target/riscv/vector_internals.c b/target/riscv/vector_internals.c | ||
492 | new file mode 100644 | ||
493 | index XXXXXXX..XXXXXXX | ||
494 | --- /dev/null | ||
495 | +++ b/target/riscv/vector_internals.c | ||
496 | @@ -XXX,XX +XXX,XX @@ | ||
497 | +/* | ||
498 | + * RISC-V Vector Extension Internals | ||
499 | + * | ||
500 | + * Copyright (c) 2020 T-Head Semiconductor Co., Ltd. All rights reserved. | ||
501 | + * | ||
502 | + * This program is free software; you can redistribute it and/or modify it | ||
503 | + * under the terms and conditions of the GNU General Public License, | ||
504 | + * version 2 or later, as published by the Free Software Foundation. | ||
505 | + * | ||
506 | + * This program is distributed in the hope it will be useful, but WITHOUT | ||
507 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
508 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
509 | + * more details. | ||
510 | + * | ||
511 | + * You should have received a copy of the GNU General Public License along with | ||
512 | + * this program. If not, see <http://www.gnu.org/licenses/>. | ||
513 | + */ | ||
514 | + | ||
515 | +#include "vector_internals.h" | ||
516 | + | ||
517 | +/* set agnostic elements to 1s */ | ||
518 | +void vext_set_elems_1s(void *base, uint32_t is_agnostic, uint32_t cnt, | ||
519 | + uint32_t tot) | ||
520 | +{ | ||
521 | + if (is_agnostic == 0) { | ||
522 | + /* policy undisturbed */ | ||
523 | + return; | ||
524 | + } | ||
525 | + if (tot - cnt == 0) { | ||
526 | + return ; | ||
527 | + } | ||
528 | + memset(base + cnt, -1, tot - cnt); | ||
529 | +} | ||
530 | + | ||
531 | +void do_vext_vv(void *vd, void *v0, void *vs1, void *vs2, | ||
532 | + CPURISCVState *env, uint32_t desc, | ||
533 | + opivv2_fn *fn, uint32_t esz) | ||
534 | +{ | ||
535 | + uint32_t vm = vext_vm(desc); | ||
536 | + uint32_t vl = env->vl; | ||
537 | + uint32_t total_elems = vext_get_total_elems(env, desc, esz); | ||
538 | + uint32_t vta = vext_vta(desc); | ||
539 | + uint32_t vma = vext_vma(desc); | ||
540 | + uint32_t i; | ||
541 | + | ||
542 | + for (i = env->vstart; i < vl; i++) { | ||
543 | + if (!vm && !vext_elem_mask(v0, i)) { | ||
544 | + /* set masked-off elements to 1s */ | ||
545 | + vext_set_elems_1s(vd, vma, i * esz, (i + 1) * esz); | ||
546 | + continue; | ||
547 | + } | ||
548 | + fn(vd, vs1, vs2, i); | ||
549 | + } | ||
550 | + env->vstart = 0; | ||
551 | + /* set tail elements to 1s */ | ||
552 | + vext_set_elems_1s(vd, vta, vl * esz, total_elems * esz); | ||
553 | +} | ||
554 | + | ||
555 | +void do_vext_vx(void *vd, void *v0, target_long s1, void *vs2, | ||
556 | + CPURISCVState *env, uint32_t desc, | ||
557 | + opivx2_fn fn, uint32_t esz) | ||
558 | +{ | ||
559 | + uint32_t vm = vext_vm(desc); | ||
560 | + uint32_t vl = env->vl; | ||
561 | + uint32_t total_elems = vext_get_total_elems(env, desc, esz); | ||
562 | + uint32_t vta = vext_vta(desc); | ||
563 | + uint32_t vma = vext_vma(desc); | ||
564 | + uint32_t i; | ||
565 | + | ||
566 | + for (i = env->vstart; i < vl; i++) { | ||
567 | + if (!vm && !vext_elem_mask(v0, i)) { | ||
568 | + /* set masked-off elements to 1s */ | ||
569 | + vext_set_elems_1s(vd, vma, i * esz, (i + 1) * esz); | ||
570 | + continue; | ||
571 | + } | ||
572 | + fn(vd, s1, vs2, i); | ||
573 | + } | ||
574 | + env->vstart = 0; | ||
575 | + /* set tail elements to 1s */ | ||
576 | + vext_set_elems_1s(vd, vta, vl * esz, total_elems * esz); | ||
577 | +} | ||
578 | diff --git a/target/riscv/meson.build b/target/riscv/meson.build | ||
579 | index XXXXXXX..XXXXXXX 100644 | ||
580 | --- a/target/riscv/meson.build | ||
581 | +++ b/target/riscv/meson.build | ||
582 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(files( | ||
583 | 'gdbstub.c', | ||
584 | 'op_helper.c', | ||
585 | 'vector_helper.c', | ||
586 | + 'vector_internals.c', | ||
587 | 'bitmanip_helper.c', | ||
588 | 'translate.c', | ||
589 | 'm128_helper.c', | ||
590 | -- | ||
591 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Kiran Ostrolenk <kiran.ostrolenk@codethink.co.uk> | ||
1 | 2 | ||
3 | Refactor the non SEW-specific stuff out of `GEN_OPIVV_TRANS` into | ||
4 | function `opivv_trans` (similar to `opivi_trans`). `opivv_trans` will be | ||
5 | used in proceeding vector-crypto commits. | ||
6 | |||
7 | Signed-off-by: Kiran Ostrolenk <kiran.ostrolenk@codethink.co.uk> | ||
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | Reviewed-by: Weiwei Li <liweiwei@iscas.ac.cn> | ||
11 | Signed-off-by: Max Chou <max.chou@sifive.com> | ||
12 | Message-ID: <20230711165917.2629866-3-max.chou@sifive.com> | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
14 | --- | ||
15 | target/riscv/insn_trans/trans_rvv.c.inc | 62 +++++++++++++------------ | ||
16 | 1 file changed, 32 insertions(+), 30 deletions(-) | ||
17 | |||
18 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | ||
21 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | ||
22 | @@ -XXX,XX +XXX,XX @@ GEN_OPIWX_WIDEN_TRANS(vwadd_wx) | ||
23 | GEN_OPIWX_WIDEN_TRANS(vwsubu_wx) | ||
24 | GEN_OPIWX_WIDEN_TRANS(vwsub_wx) | ||
25 | |||
26 | +static bool opivv_trans(uint32_t vd, uint32_t vs1, uint32_t vs2, uint32_t vm, | ||
27 | + gen_helper_gvec_4_ptr *fn, DisasContext *s) | ||
28 | +{ | ||
29 | + uint32_t data = 0; | ||
30 | + TCGLabel *over = gen_new_label(); | ||
31 | + tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); | ||
32 | + tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); | ||
33 | + | ||
34 | + data = FIELD_DP32(data, VDATA, VM, vm); | ||
35 | + data = FIELD_DP32(data, VDATA, LMUL, s->lmul); | ||
36 | + data = FIELD_DP32(data, VDATA, VTA, s->vta); | ||
37 | + data = FIELD_DP32(data, VDATA, VTA_ALL_1S, s->cfg_vta_all_1s); | ||
38 | + data = FIELD_DP32(data, VDATA, VMA, s->vma); | ||
39 | + tcg_gen_gvec_4_ptr(vreg_ofs(s, vd), vreg_ofs(s, 0), vreg_ofs(s, vs1), | ||
40 | + vreg_ofs(s, vs2), cpu_env, s->cfg_ptr->vlen / 8, | ||
41 | + s->cfg_ptr->vlen / 8, data, fn); | ||
42 | + mark_vs_dirty(s); | ||
43 | + gen_set_label(over); | ||
44 | + return true; | ||
45 | +} | ||
46 | + | ||
47 | /* Vector Integer Add-with-Carry / Subtract-with-Borrow Instructions */ | ||
48 | /* OPIVV without GVEC IR */ | ||
49 | -#define GEN_OPIVV_TRANS(NAME, CHECK) \ | ||
50 | -static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ | ||
51 | -{ \ | ||
52 | - if (CHECK(s, a)) { \ | ||
53 | - uint32_t data = 0; \ | ||
54 | - static gen_helper_gvec_4_ptr * const fns[4] = { \ | ||
55 | - gen_helper_##NAME##_b, gen_helper_##NAME##_h, \ | ||
56 | - gen_helper_##NAME##_w, gen_helper_##NAME##_d, \ | ||
57 | - }; \ | ||
58 | - TCGLabel *over = gen_new_label(); \ | ||
59 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); \ | ||
60 | - tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); \ | ||
61 | - \ | ||
62 | - data = FIELD_DP32(data, VDATA, VM, a->vm); \ | ||
63 | - data = FIELD_DP32(data, VDATA, LMUL, s->lmul); \ | ||
64 | - data = FIELD_DP32(data, VDATA, VTA, s->vta); \ | ||
65 | - data = \ | ||
66 | - FIELD_DP32(data, VDATA, VTA_ALL_1S, s->cfg_vta_all_1s);\ | ||
67 | - data = FIELD_DP32(data, VDATA, VMA, s->vma); \ | ||
68 | - tcg_gen_gvec_4_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, 0), \ | ||
69 | - vreg_ofs(s, a->rs1), \ | ||
70 | - vreg_ofs(s, a->rs2), cpu_env, \ | ||
71 | - s->cfg_ptr->vlen / 8, \ | ||
72 | - s->cfg_ptr->vlen / 8, data, \ | ||
73 | - fns[s->sew]); \ | ||
74 | - mark_vs_dirty(s); \ | ||
75 | - gen_set_label(over); \ | ||
76 | - return true; \ | ||
77 | - } \ | ||
78 | - return false; \ | ||
79 | +#define GEN_OPIVV_TRANS(NAME, CHECK) \ | ||
80 | +static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ | ||
81 | +{ \ | ||
82 | + if (CHECK(s, a)) { \ | ||
83 | + static gen_helper_gvec_4_ptr * const fns[4] = { \ | ||
84 | + gen_helper_##NAME##_b, gen_helper_##NAME##_h, \ | ||
85 | + gen_helper_##NAME##_w, gen_helper_##NAME##_d, \ | ||
86 | + }; \ | ||
87 | + return opivv_trans(a->rd, a->rs1, a->rs2, a->vm, fns[s->sew], s);\ | ||
88 | + } \ | ||
89 | + return false; \ | ||
90 | } | ||
91 | |||
92 | /* | ||
93 | -- | ||
94 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Nazar Kazakov <nazar.kazakov@codethink.co.uk> |
---|---|---|---|
2 | 2 | ||
3 | While discussing a problem with how we're (not) setting vstart_eq_zero | 3 | Remove the redundant "vl == 0" check which is already included within the vstart >= vl check, when vl == 0. |
4 | Richard had the following to say w.r.t the conditional mark_vs_dirty() | ||
5 | calls on load/store functions [1]: | ||
6 | 4 | ||
7 | "I think it's required to have stores set dirty unconditionally, before | 5 | Signed-off-by: Nazar Kazakov <nazar.kazakov@codethink.co.uk> |
8 | the operation. | 6 | Reviewed-by: Weiwei Li <liweiwei@iscas.ac.cn> |
9 | 7 | Signed-off-by: Max Chou <max.chou@sifive.com> | |
10 | Consider a store that traps on the 2nd element, leaving vstart = 2, and | 8 | Acked-by: Alistair Francis <alistair.francis@wdc.com> |
11 | exiting to the main loop via exception. The exception enters the kernel | 9 | Message-ID: <20230711165917.2629866-4-max.chou@sifive.com> |
12 | page fault handler. The kernel may need to fault in the page for the | ||
13 | process, and in the meantime task switch. | ||
14 | |||
15 | If vs dirty is not already set, the kernel won't know to save vector | ||
16 | state on task switch." | ||
17 | |||
18 | Do a mark_vs_dirty() before both loads and stores. | ||
19 | |||
20 | [1] https://lore.kernel.org/qemu-riscv/72c7503b-0f43-44b8-aa82-fbafed2aac0c@linaro.org/ | ||
21 | |||
22 | Suggested-by: Richard Henderson <richard.henderson@linaro.org> | ||
23 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
24 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
25 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
26 | Message-ID: <20240306171932.549549-2-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/insn_trans/trans_rvv.c.inc | 23 ++++++++--------------- | 12 | target/riscv/insn_trans/trans_rvv.c.inc | 31 +------------------------ |
30 | 1 file changed, 8 insertions(+), 15 deletions(-) | 13 | 1 file changed, 1 insertion(+), 30 deletions(-) |
31 | 14 | ||
32 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | 15 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc |
33 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
34 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | 17 | --- a/target/riscv/insn_trans/trans_rvv.c.inc |
35 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | 18 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc |
36 | @@ -XXX,XX +XXX,XX @@ static bool ldst_us_trans(uint32_t vd, uint32_t rs1, uint32_t data, | 19 | @@ -XXX,XX +XXX,XX @@ static bool ldst_us_trans(uint32_t vd, uint32_t rs1, uint32_t data, |
37 | tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL); | 20 | TCGv_i32 desc; |
21 | |||
22 | TCGLabel *over = gen_new_label(); | ||
23 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); | ||
24 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); | ||
25 | |||
26 | dest = tcg_temp_new_ptr(); | ||
27 | @@ -XXX,XX +XXX,XX @@ static bool ldst_stride_trans(uint32_t vd, uint32_t rs1, uint32_t rs2, | ||
28 | TCGv_i32 desc; | ||
29 | |||
30 | TCGLabel *over = gen_new_label(); | ||
31 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); | ||
32 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); | ||
33 | |||
34 | dest = tcg_temp_new_ptr(); | ||
35 | @@ -XXX,XX +XXX,XX @@ static bool ldst_index_trans(uint32_t vd, uint32_t rs1, uint32_t vs2, | ||
36 | TCGv_i32 desc; | ||
37 | |||
38 | TCGLabel *over = gen_new_label(); | ||
39 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); | ||
40 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); | ||
41 | |||
42 | dest = tcg_temp_new_ptr(); | ||
43 | @@ -XXX,XX +XXX,XX @@ static bool ldff_trans(uint32_t vd, uint32_t rs1, uint32_t data, | ||
44 | TCGv_i32 desc; | ||
45 | |||
46 | TCGLabel *over = gen_new_label(); | ||
47 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); | ||
48 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); | ||
49 | |||
50 | dest = tcg_temp_new_ptr(); | ||
51 | @@ -XXX,XX +XXX,XX @@ do_opivv_gvec(DisasContext *s, arg_rmrr *a, GVecGen3Fn *gvec_fn, | ||
52 | return false; | ||
38 | } | 53 | } |
39 | 54 | ||
40 | + mark_vs_dirty(s); | 55 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); |
41 | + | 56 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); |
42 | fn(dest, mask, base, tcg_env, desc); | 57 | |
43 | 58 | if (a->vm && s->vl_eq_vlmax && !(s->vta && s->lmul < 0)) { | |
44 | if (!is_store && s->ztso) { | 59 | @@ -XXX,XX +XXX,XX @@ static bool opivx_trans(uint32_t vd, uint32_t rs1, uint32_t vs2, uint32_t vm, |
45 | tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ); | 60 | uint32_t data = 0; |
46 | } | 61 | |
47 | 62 | TCGLabel *over = gen_new_label(); | |
48 | - if (!is_store) { | 63 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); |
49 | - mark_vs_dirty(s); | 64 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); |
50 | - } | 65 | |
51 | - | 66 | dest = tcg_temp_new_ptr(); |
52 | gen_set_label(over); | 67 | @@ -XXX,XX +XXX,XX @@ static bool opivi_trans(uint32_t vd, uint32_t imm, uint32_t vs2, uint32_t vm, |
53 | return true; | 68 | uint32_t data = 0; |
54 | } | 69 | |
55 | @@ -XXX,XX +XXX,XX @@ static bool ldst_stride_trans(uint32_t vd, uint32_t rs1, uint32_t rs2, | 70 | TCGLabel *over = gen_new_label(); |
56 | tcg_gen_addi_ptr(dest, tcg_env, vreg_ofs(s, vd)); | 71 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); |
57 | tcg_gen_addi_ptr(mask, tcg_env, vreg_ofs(s, 0)); | 72 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); |
58 | 73 | ||
59 | - fn(dest, mask, base, stride, tcg_env, desc); | 74 | dest = tcg_temp_new_ptr(); |
60 | + mark_vs_dirty(s); | 75 | @@ -XXX,XX +XXX,XX @@ static bool do_opivv_widen(DisasContext *s, arg_rmrr *a, |
61 | 76 | if (checkfn(s, a)) { | |
62 | - if (!is_store) { | 77 | uint32_t data = 0; |
63 | - mark_vs_dirty(s); | 78 | TCGLabel *over = gen_new_label(); |
64 | - } | 79 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); |
65 | + fn(dest, mask, base, stride, tcg_env, desc); | 80 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); |
66 | 81 | ||
67 | gen_set_label(over); | 82 | data = FIELD_DP32(data, VDATA, VM, a->vm); |
68 | return true; | 83 | @@ -XXX,XX +XXX,XX @@ static bool do_opiwv_widen(DisasContext *s, arg_rmrr *a, |
69 | @@ -XXX,XX +XXX,XX @@ static bool ldst_index_trans(uint32_t vd, uint32_t rs1, uint32_t vs2, | 84 | if (opiwv_widen_check(s, a)) { |
70 | tcg_gen_addi_ptr(index, tcg_env, vreg_ofs(s, vs2)); | 85 | uint32_t data = 0; |
71 | tcg_gen_addi_ptr(mask, tcg_env, vreg_ofs(s, 0)); | 86 | TCGLabel *over = gen_new_label(); |
72 | 87 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); | |
73 | - fn(dest, mask, base, index, tcg_env, desc); | 88 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); |
74 | + mark_vs_dirty(s); | 89 | |
75 | 90 | data = FIELD_DP32(data, VDATA, VM, a->vm); | |
76 | - if (!is_store) { | 91 | @@ -XXX,XX +XXX,XX @@ static bool opivv_trans(uint32_t vd, uint32_t vs1, uint32_t vs2, uint32_t vm, |
77 | - mark_vs_dirty(s); | 92 | { |
78 | - } | 93 | uint32_t data = 0; |
79 | + fn(dest, mask, base, index, tcg_env, desc); | 94 | TCGLabel *over = gen_new_label(); |
80 | 95 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); | |
81 | gen_set_label(over); | 96 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); |
82 | return true; | 97 | |
83 | @@ -XXX,XX +XXX,XX @@ static bool ldst_whole_trans(uint32_t vd, uint32_t rs1, uint32_t nf, | 98 | data = FIELD_DP32(data, VDATA, VM, vm); |
84 | base = get_gpr(s, rs1, EXT_NONE); | 99 | @@ -XXX,XX +XXX,XX @@ static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ |
85 | tcg_gen_addi_ptr(dest, tcg_env, vreg_ofs(s, vd)); | 100 | gen_helper_##NAME##_w, \ |
86 | 101 | }; \ | |
87 | + mark_vs_dirty(s); | 102 | TCGLabel *over = gen_new_label(); \ |
88 | + | 103 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); \ |
89 | fn(dest, base, tcg_env, desc); | 104 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); \ |
90 | 105 | \ | |
91 | - if (!is_store) { | 106 | data = FIELD_DP32(data, VDATA, VM, a->vm); \ |
92 | - mark_vs_dirty(s); | 107 | @@ -XXX,XX +XXX,XX @@ static bool trans_vmv_v_v(DisasContext *s, arg_vmv_v_v *a) |
93 | - } | 108 | gen_helper_vmv_v_v_w, gen_helper_vmv_v_v_d, |
94 | gen_set_label(over); | 109 | }; |
95 | 110 | TCGLabel *over = gen_new_label(); | |
96 | return true; | 111 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); |
112 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); | ||
113 | |||
114 | tcg_gen_gvec_2_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, a->rs1), | ||
115 | @@ -XXX,XX +XXX,XX @@ static bool trans_vmv_v_x(DisasContext *s, arg_vmv_v_x *a) | ||
116 | vext_check_ss(s, a->rd, 0, 1)) { | ||
117 | TCGv s1; | ||
118 | TCGLabel *over = gen_new_label(); | ||
119 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); | ||
120 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); | ||
121 | |||
122 | s1 = get_gpr(s, a->rs1, EXT_SIGN); | ||
123 | @@ -XXX,XX +XXX,XX @@ static bool trans_vmv_v_i(DisasContext *s, arg_vmv_v_i *a) | ||
124 | gen_helper_vmv_v_x_w, gen_helper_vmv_v_x_d, | ||
125 | }; | ||
126 | TCGLabel *over = gen_new_label(); | ||
127 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); | ||
128 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); | ||
129 | |||
130 | s1 = tcg_constant_i64(simm); | ||
131 | @@ -XXX,XX +XXX,XX @@ static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ | ||
132 | }; \ | ||
133 | TCGLabel *over = gen_new_label(); \ | ||
134 | gen_set_rm(s, RISCV_FRM_DYN); \ | ||
135 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); \ | ||
136 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); \ | ||
137 | \ | ||
138 | data = FIELD_DP32(data, VDATA, VM, a->vm); \ | ||
139 | @@ -XXX,XX +XXX,XX @@ static bool opfvf_trans(uint32_t vd, uint32_t rs1, uint32_t vs2, | ||
140 | TCGv_i64 t1; | ||
141 | |||
142 | TCGLabel *over = gen_new_label(); | ||
143 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); | ||
144 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); | ||
145 | |||
146 | dest = tcg_temp_new_ptr(); | ||
147 | @@ -XXX,XX +XXX,XX @@ static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ | ||
148 | }; \ | ||
149 | TCGLabel *over = gen_new_label(); \ | ||
150 | gen_set_rm(s, RISCV_FRM_DYN); \ | ||
151 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); \ | ||
152 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over);\ | ||
153 | \ | ||
154 | data = FIELD_DP32(data, VDATA, VM, a->vm); \ | ||
155 | @@ -XXX,XX +XXX,XX @@ static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ | ||
156 | }; \ | ||
157 | TCGLabel *over = gen_new_label(); \ | ||
158 | gen_set_rm(s, RISCV_FRM_DYN); \ | ||
159 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); \ | ||
160 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); \ | ||
161 | \ | ||
162 | data = FIELD_DP32(data, VDATA, VM, a->vm); \ | ||
163 | @@ -XXX,XX +XXX,XX @@ static bool do_opfv(DisasContext *s, arg_rmr *a, | ||
164 | uint32_t data = 0; | ||
165 | TCGLabel *over = gen_new_label(); | ||
166 | gen_set_rm_chkfrm(s, rm); | ||
167 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); | ||
168 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); | ||
169 | |||
170 | data = FIELD_DP32(data, VDATA, VM, a->vm); | ||
171 | @@ -XXX,XX +XXX,XX @@ static bool trans_vfmv_v_f(DisasContext *s, arg_vfmv_v_f *a) | ||
172 | gen_helper_vmv_v_x_d, | ||
173 | }; | ||
174 | TCGLabel *over = gen_new_label(); | ||
175 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); | ||
176 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); | ||
177 | |||
178 | t1 = tcg_temp_new_i64(); | ||
179 | @@ -XXX,XX +XXX,XX @@ static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ | ||
180 | }; \ | ||
181 | TCGLabel *over = gen_new_label(); \ | ||
182 | gen_set_rm_chkfrm(s, FRM); \ | ||
183 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); \ | ||
184 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); \ | ||
185 | \ | ||
186 | data = FIELD_DP32(data, VDATA, VM, a->vm); \ | ||
187 | @@ -XXX,XX +XXX,XX @@ static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ | ||
188 | }; \ | ||
189 | TCGLabel *over = gen_new_label(); \ | ||
190 | gen_set_rm(s, RISCV_FRM_DYN); \ | ||
191 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); \ | ||
192 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); \ | ||
193 | \ | ||
194 | data = FIELD_DP32(data, VDATA, VM, a->vm); \ | ||
195 | @@ -XXX,XX +XXX,XX @@ static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ | ||
196 | }; \ | ||
197 | TCGLabel *over = gen_new_label(); \ | ||
198 | gen_set_rm_chkfrm(s, FRM); \ | ||
199 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); \ | ||
200 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); \ | ||
201 | \ | ||
202 | data = FIELD_DP32(data, VDATA, VM, a->vm); \ | ||
203 | @@ -XXX,XX +XXX,XX @@ static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ | ||
204 | }; \ | ||
205 | TCGLabel *over = gen_new_label(); \ | ||
206 | gen_set_rm_chkfrm(s, FRM); \ | ||
207 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); \ | ||
208 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); \ | ||
209 | \ | ||
210 | data = FIELD_DP32(data, VDATA, VM, a->vm); \ | ||
211 | @@ -XXX,XX +XXX,XX @@ static bool trans_##NAME(DisasContext *s, arg_r *a) \ | ||
212 | uint32_t data = 0; \ | ||
213 | gen_helper_gvec_4_ptr *fn = gen_helper_##NAME; \ | ||
214 | TCGLabel *over = gen_new_label(); \ | ||
215 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); \ | ||
216 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); \ | ||
217 | \ | ||
218 | data = FIELD_DP32(data, VDATA, LMUL, s->lmul); \ | ||
219 | @@ -XXX,XX +XXX,XX @@ static bool trans_vid_v(DisasContext *s, arg_vid_v *a) | ||
220 | require_vm(a->vm, a->rd)) { | ||
221 | uint32_t data = 0; | ||
222 | TCGLabel *over = gen_new_label(); | ||
223 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); | ||
224 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); | ||
225 | |||
226 | data = FIELD_DP32(data, VDATA, VM, a->vm); | ||
227 | @@ -XXX,XX +XXX,XX @@ static bool trans_vmv_s_x(DisasContext *s, arg_vmv_s_x *a) | ||
228 | TCGv s1; | ||
229 | TCGLabel *over = gen_new_label(); | ||
230 | |||
231 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); | ||
232 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); | ||
233 | |||
234 | t1 = tcg_temp_new_i64(); | ||
235 | @@ -XXX,XX +XXX,XX @@ static bool trans_vfmv_s_f(DisasContext *s, arg_vfmv_s_f *a) | ||
236 | TCGv_i64 t1; | ||
237 | TCGLabel *over = gen_new_label(); | ||
238 | |||
239 | - /* if vl == 0 or vstart >= vl, skip vector register write back */ | ||
240 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); | ||
241 | + /* if vstart >= vl, skip vector register write back */ | ||
242 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); | ||
243 | |||
244 | /* NaN-box f[rs1] */ | ||
245 | @@ -XXX,XX +XXX,XX @@ static bool int_ext_op(DisasContext *s, arg_rmr *a, uint8_t seq) | ||
246 | uint32_t data = 0; | ||
247 | gen_helper_gvec_3_ptr *fn; | ||
248 | TCGLabel *over = gen_new_label(); | ||
249 | - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); | ||
250 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); | ||
251 | |||
252 | static gen_helper_gvec_3_ptr * const fns[6][4] = { | ||
97 | -- | 253 | -- |
98 | 2.44.0 | 254 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Palmer Dabbelt <palmer@rivosinc.com> | 1 | From: Lawrence Hunter <lawrence.hunter@codethink.co.uk> |
---|---|---|---|
2 | 2 | ||
3 | The Ztso extension is already ratified, this adds it as a CPU property | 3 | This commit adds support for the Zvbc vector-crypto extension, which |
4 | and adds various fences throughout the port in order to allow TSO | 4 | consists of the following instructions: |
5 | targets to function on weaker hosts. We need no fences for AMOs as | 5 | |
6 | they're already SC, the places we need barriers are described. | 6 | * vclmulh.[vx,vv] |
7 | These fences are placed in the RISC-V backend rather than TCG as is | 7 | * vclmul.[vx,vv] |
8 | planned for x86-on-arm64 because RISC-V allows heterogeneous (and | 8 | |
9 | likely soon dynamic) hart memory models. | 9 | Translation functions are defined in |
10 | 10 | `target/riscv/insn_trans/trans_rvvk.c.inc` and helpers are defined in | |
11 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 11 | `target/riscv/vcrypto_helper.c`. |
12 | Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com> | 12 | |
13 | Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu> | 13 | Co-authored-by: Nazar Kazakov <nazar.kazakov@codethink.co.uk> |
14 | Message-ID: <20240207122256.902627-2-christoph.muellner@vrull.eu> | 14 | Co-authored-by: Max Chou <max.chou@sifive.com> |
15 | Signed-off-by: Nazar Kazakov <nazar.kazakov@codethink.co.uk> | ||
16 | Signed-off-by: Lawrence Hunter <lawrence.hunter@codethink.co.uk> | ||
17 | Signed-off-by: Max Chou <max.chou@sifive.com> | ||
18 | [max.chou@sifive.com: Exposed x-zvbc property] | ||
19 | Message-ID: <20230711165917.2629866-5-max.chou@sifive.com> | ||
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 20 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
16 | --- | 21 | --- |
17 | target/riscv/cpu_cfg.h | 1 + | 22 | target/riscv/cpu_cfg.h | 1 + |
18 | target/riscv/cpu.c | 2 ++ | 23 | target/riscv/helper.h | 6 +++ |
19 | target/riscv/translate.c | 3 +++ | 24 | target/riscv/insn32.decode | 6 +++ |
20 | target/riscv/insn_trans/trans_rva.c.inc | 11 ++++++++--- | 25 | target/riscv/cpu.c | 9 ++++ |
21 | target/riscv/insn_trans/trans_rvi.c.inc | 16 ++++++++++++++-- | 26 | target/riscv/translate.c | 1 + |
22 | target/riscv/insn_trans/trans_rvv.c.inc | 20 ++++++++++++++++++++ | 27 | target/riscv/vcrypto_helper.c | 59 ++++++++++++++++++++++ |
23 | 6 files changed, 48 insertions(+), 5 deletions(-) | 28 | target/riscv/insn_trans/trans_rvvk.c.inc | 62 ++++++++++++++++++++++++ |
29 | target/riscv/meson.build | 3 +- | ||
30 | 8 files changed, 146 insertions(+), 1 deletion(-) | ||
31 | create mode 100644 target/riscv/vcrypto_helper.c | ||
32 | create mode 100644 target/riscv/insn_trans/trans_rvvk.c.inc | ||
24 | 33 | ||
25 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h | 34 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h |
26 | index XXXXXXX..XXXXXXX 100644 | 35 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/target/riscv/cpu_cfg.h | 36 | --- a/target/riscv/cpu_cfg.h |
28 | +++ b/target/riscv/cpu_cfg.h | 37 | +++ b/target/riscv/cpu_cfg.h |
29 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { | 38 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { |
30 | bool ext_zihintntl; | 39 | bool ext_zve32f; |
31 | bool ext_zihintpause; | 40 | bool ext_zve64f; |
32 | bool ext_zihpm; | 41 | bool ext_zve64d; |
33 | + bool ext_ztso; | 42 | + bool ext_zvbc; |
34 | bool ext_smstateen; | 43 | bool ext_zmmul; |
35 | bool ext_sstc; | 44 | bool ext_zvfbfmin; |
36 | bool ext_svadu; | 45 | bool ext_zvfbfwma; |
46 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h | ||
47 | index XXXXXXX..XXXXXXX 100644 | ||
48 | --- a/target/riscv/helper.h | ||
49 | +++ b/target/riscv/helper.h | ||
50 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_5(vfwcvtbf16_f_f_v, void, ptr, ptr, ptr, env, i32) | ||
51 | |||
52 | DEF_HELPER_6(vfwmaccbf16_vv, void, ptr, ptr, ptr, ptr, env, i32) | ||
53 | DEF_HELPER_6(vfwmaccbf16_vf, void, ptr, ptr, i64, ptr, env, i32) | ||
54 | + | ||
55 | +/* Vector crypto functions */ | ||
56 | +DEF_HELPER_6(vclmul_vv, void, ptr, ptr, ptr, ptr, env, i32) | ||
57 | +DEF_HELPER_6(vclmul_vx, void, ptr, ptr, tl, ptr, env, i32) | ||
58 | +DEF_HELPER_6(vclmulh_vv, void, ptr, ptr, ptr, ptr, env, i32) | ||
59 | +DEF_HELPER_6(vclmulh_vx, void, ptr, ptr, tl, ptr, env, i32) | ||
60 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | ||
61 | index XXXXXXX..XXXXXXX 100644 | ||
62 | --- a/target/riscv/insn32.decode | ||
63 | +++ b/target/riscv/insn32.decode | ||
64 | @@ -XXX,XX +XXX,XX @@ vfwcvtbf16_f_f_v 010010 . ..... 01101 001 ..... 1010111 @r2_vm | ||
65 | # *** Zvfbfwma Standard Extension *** | ||
66 | vfwmaccbf16_vv 111011 . ..... ..... 001 ..... 1010111 @r_vm | ||
67 | vfwmaccbf16_vf 111011 . ..... ..... 101 ..... 1010111 @r_vm | ||
68 | + | ||
69 | +# *** Zvbc vector crypto extension *** | ||
70 | +vclmul_vv 001100 . ..... ..... 010 ..... 1010111 @r_vm | ||
71 | +vclmul_vx 001100 . ..... ..... 110 ..... 1010111 @r_vm | ||
72 | +vclmulh_vv 001101 . ..... ..... 010 ..... 1010111 @r_vm | ||
73 | +vclmulh_vx 001101 . ..... ..... 110 ..... 1010111 @r_vm | ||
37 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 74 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
38 | index XXXXXXX..XXXXXXX 100644 | 75 | index XXXXXXX..XXXXXXX 100644 |
39 | --- a/target/riscv/cpu.c | 76 | --- a/target/riscv/cpu.c |
40 | +++ b/target/riscv/cpu.c | 77 | +++ b/target/riscv/cpu.c |
41 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { | 78 | @@ -XXX,XX +XXX,XX @@ static const struct isa_ext_data isa_edata_arr[] = { |
42 | ISA_EXT_DATA_ENTRY(zksed, PRIV_VERSION_1_12_0, ext_zksed), | 79 | ISA_EXT_DATA_ENTRY(zksed, PRIV_VERSION_1_12_0, ext_zksed), |
43 | ISA_EXT_DATA_ENTRY(zksh, PRIV_VERSION_1_12_0, ext_zksh), | 80 | ISA_EXT_DATA_ENTRY(zksh, PRIV_VERSION_1_12_0, ext_zksh), |
44 | ISA_EXT_DATA_ENTRY(zkt, PRIV_VERSION_1_12_0, ext_zkt), | 81 | ISA_EXT_DATA_ENTRY(zkt, PRIV_VERSION_1_12_0, ext_zkt), |
45 | + ISA_EXT_DATA_ENTRY(ztso, PRIV_VERSION_1_12_0, ext_ztso), | 82 | + ISA_EXT_DATA_ENTRY(zvbc, PRIV_VERSION_1_12_0, ext_zvbc), |
46 | ISA_EXT_DATA_ENTRY(zvbb, PRIV_VERSION_1_12_0, ext_zvbb), | ||
47 | ISA_EXT_DATA_ENTRY(zvbc, PRIV_VERSION_1_12_0, ext_zvbc), | ||
48 | ISA_EXT_DATA_ENTRY(zve32f, PRIV_VERSION_1_10_0, ext_zve32f), | 83 | ISA_EXT_DATA_ENTRY(zve32f, PRIV_VERSION_1_10_0, ext_zve32f), |
49 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { | 84 | ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f), |
50 | MULTI_EXT_CFG_BOOL("zksed", ext_zksed, false), | 85 | ISA_EXT_DATA_ENTRY(zve64d, PRIV_VERSION_1_10_0, ext_zve64d), |
51 | MULTI_EXT_CFG_BOOL("zksh", ext_zksh, false), | 86 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) |
52 | MULTI_EXT_CFG_BOOL("zkt", ext_zkt, false), | 87 | return; |
53 | + MULTI_EXT_CFG_BOOL("ztso", ext_ztso, false), | 88 | } |
54 | 89 | ||
55 | MULTI_EXT_CFG_BOOL("zdinx", ext_zdinx, false), | 90 | + if (cpu->cfg.ext_zvbc && !cpu->cfg.ext_zve64f) { |
56 | MULTI_EXT_CFG_BOOL("zfinx", ext_zfinx, false), | 91 | + error_setg(errp, "Zvbc extension requires V or Zve64{f,d} extensions"); |
92 | + return; | ||
93 | + } | ||
94 | + | ||
95 | if (cpu->cfg.ext_zk) { | ||
96 | cpu->cfg.ext_zkn = true; | ||
97 | cpu->cfg.ext_zkr = true; | ||
98 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = { | ||
99 | DEFINE_PROP_BOOL("x-zvfbfmin", RISCVCPU, cfg.ext_zvfbfmin, false), | ||
100 | DEFINE_PROP_BOOL("x-zvfbfwma", RISCVCPU, cfg.ext_zvfbfwma, false), | ||
101 | |||
102 | + /* Vector cryptography extensions */ | ||
103 | + DEFINE_PROP_BOOL("x-zvbc", RISCVCPU, cfg.ext_zvbc, false), | ||
104 | + | ||
105 | DEFINE_PROP_END_OF_LIST(), | ||
106 | }; | ||
107 | |||
57 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | 108 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c |
58 | index XXXXXXX..XXXXXXX 100644 | 109 | index XXXXXXX..XXXXXXX 100644 |
59 | --- a/target/riscv/translate.c | 110 | --- a/target/riscv/translate.c |
60 | +++ b/target/riscv/translate.c | 111 | +++ b/target/riscv/translate.c |
61 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { | 112 | @@ -XXX,XX +XXX,XX @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc) |
62 | /* PointerMasking extension */ | 113 | #include "insn_trans/trans_rvzfa.c.inc" |
63 | bool pm_mask_enabled; | 114 | #include "insn_trans/trans_rvzfh.c.inc" |
64 | bool pm_base_enabled; | 115 | #include "insn_trans/trans_rvk.c.inc" |
65 | + /* Ztso */ | 116 | +#include "insn_trans/trans_rvvk.c.inc" |
66 | + bool ztso; | 117 | #include "insn_trans/trans_privileged.c.inc" |
67 | /* Use icount trigger for native debug */ | 118 | #include "insn_trans/trans_svinval.c.inc" |
68 | bool itrigger; | 119 | #include "insn_trans/trans_rvbf16.c.inc" |
69 | /* FRM is known to contain a valid value. */ | 120 | diff --git a/target/riscv/vcrypto_helper.c b/target/riscv/vcrypto_helper.c |
70 | @@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) | 121 | new file mode 100644 |
71 | ctx->cs = cs; | 122 | index XXXXXXX..XXXXXXX |
72 | ctx->pm_mask_enabled = FIELD_EX32(tb_flags, TB_FLAGS, PM_MASK_ENABLED); | 123 | --- /dev/null |
73 | ctx->pm_base_enabled = FIELD_EX32(tb_flags, TB_FLAGS, PM_BASE_ENABLED); | 124 | +++ b/target/riscv/vcrypto_helper.c |
74 | + ctx->ztso = cpu->cfg.ext_ztso; | 125 | @@ -XXX,XX +XXX,XX @@ |
75 | ctx->itrigger = FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER); | 126 | +/* |
76 | ctx->zero = tcg_constant_tl(0); | 127 | + * RISC-V Vector Crypto Extension Helpers for QEMU. |
77 | ctx->virt_inst_excp = false; | 128 | + * |
78 | diff --git a/target/riscv/insn_trans/trans_rva.c.inc b/target/riscv/insn_trans/trans_rva.c.inc | 129 | + * Copyright (C) 2023 SiFive, Inc. |
79 | index XXXXXXX..XXXXXXX 100644 | 130 | + * Written by Codethink Ltd and SiFive. |
80 | --- a/target/riscv/insn_trans/trans_rva.c.inc | 131 | + * |
81 | +++ b/target/riscv/insn_trans/trans_rva.c.inc | 132 | + * This program is free software; you can redistribute it and/or modify it |
82 | @@ -XXX,XX +XXX,XX @@ static bool gen_lr(DisasContext *ctx, arg_atomic *a, MemOp mop) | 133 | + * under the terms and conditions of the GNU General Public License, |
83 | tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL); | 134 | + * version 2 or later, as published by the Free Software Foundation. |
84 | } | 135 | + * |
85 | tcg_gen_qemu_ld_tl(load_val, src1, ctx->mem_idx, mop); | 136 | + * This program is distributed in the hope it will be useful, but WITHOUT |
86 | - if (a->aq) { | 137 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
87 | + /* | 138 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
88 | + * TSO defines AMOs as acquire+release-RCsc, but does not define LR/SC as | 139 | + * more details. |
89 | + * AMOs. Instead treat them like loads. | 140 | + * |
90 | + */ | 141 | + * You should have received a copy of the GNU General Public License along with |
91 | + if (a->aq || ctx->ztso) { | 142 | + * this program. If not, see <http://www.gnu.org/licenses/>. |
92 | tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ); | 143 | + */ |
93 | } | 144 | + |
94 | 145 | +#include "qemu/osdep.h" | |
95 | @@ -XXX,XX +XXX,XX @@ static bool gen_sc(DisasContext *ctx, arg_atomic *a, MemOp mop) | 146 | +#include "qemu/host-utils.h" |
96 | gen_set_label(l1); | 147 | +#include "qemu/bitops.h" |
97 | /* | 148 | +#include "cpu.h" |
98 | * Address comparison failure. However, we still need to | 149 | +#include "exec/memop.h" |
99 | - * provide the memory barrier implied by AQ/RL. | 150 | +#include "exec/exec-all.h" |
100 | + * provide the memory barrier implied by AQ/RL/TSO. | 151 | +#include "exec/helper-proto.h" |
101 | */ | 152 | +#include "internals.h" |
102 | - tcg_gen_mb(TCG_MO_ALL + a->aq * TCG_BAR_LDAQ + a->rl * TCG_BAR_STRL); | 153 | +#include "vector_internals.h" |
103 | + TCGBar bar_strl = (ctx->ztso || a->rl) ? TCG_BAR_STRL : 0; | 154 | + |
104 | + tcg_gen_mb(TCG_MO_ALL + a->aq * TCG_BAR_LDAQ + bar_strl); | 155 | +static uint64_t clmul64(uint64_t y, uint64_t x) |
105 | gen_set_gpr(ctx, a->rd, tcg_constant_tl(1)); | 156 | +{ |
106 | 157 | + uint64_t result = 0; | |
107 | gen_set_label(l2); | 158 | + for (int j = 63; j >= 0; j--) { |
108 | diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_trans/trans_rvi.c.inc | 159 | + if ((y >> j) & 1) { |
109 | index XXXXXXX..XXXXXXX 100644 | 160 | + result ^= (x << j); |
110 | --- a/target/riscv/insn_trans/trans_rvi.c.inc | 161 | + } |
111 | +++ b/target/riscv/insn_trans/trans_rvi.c.inc | 162 | + } |
112 | @@ -XXX,XX +XXX,XX @@ static bool gen_load_i128(DisasContext *ctx, arg_lb *a, MemOp memop) | 163 | + return result; |
113 | 164 | +} | |
114 | static bool gen_load(DisasContext *ctx, arg_lb *a, MemOp memop) | 165 | + |
115 | { | 166 | +static uint64_t clmulh64(uint64_t y, uint64_t x) |
116 | + bool out; | 167 | +{ |
117 | + | 168 | + uint64_t result = 0; |
118 | decode_save_opc(ctx); | 169 | + for (int j = 63; j >= 1; j--) { |
119 | if (get_xl(ctx) == MXL_RV128) { | 170 | + if ((y >> j) & 1) { |
120 | - return gen_load_i128(ctx, a, memop); | 171 | + result ^= (x >> (64 - j)); |
121 | + out = gen_load_i128(ctx, a, memop); | 172 | + } |
122 | } else { | 173 | + } |
123 | - return gen_load_tl(ctx, a, memop); | 174 | + return result; |
124 | + out = gen_load_tl(ctx, a, memop); | 175 | +} |
125 | + } | 176 | + |
126 | + | 177 | +RVVCALL(OPIVV2, vclmul_vv, OP_UUU_D, H8, H8, H8, clmul64) |
127 | + if (ctx->ztso) { | 178 | +GEN_VEXT_VV(vclmul_vv, 8) |
128 | + tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ); | 179 | +RVVCALL(OPIVX2, vclmul_vx, OP_UUU_D, H8, H8, clmul64) |
129 | } | 180 | +GEN_VEXT_VX(vclmul_vx, 8) |
130 | + | 181 | +RVVCALL(OPIVV2, vclmulh_vv, OP_UUU_D, H8, H8, H8, clmulh64) |
131 | + return out; | 182 | +GEN_VEXT_VV(vclmulh_vv, 8) |
132 | } | 183 | +RVVCALL(OPIVX2, vclmulh_vx, OP_UUU_D, H8, H8, clmulh64) |
133 | 184 | +GEN_VEXT_VX(vclmulh_vx, 8) | |
134 | static bool trans_lb(DisasContext *ctx, arg_lb *a) | 185 | diff --git a/target/riscv/insn_trans/trans_rvvk.c.inc b/target/riscv/insn_trans/trans_rvvk.c.inc |
135 | @@ -XXX,XX +XXX,XX @@ static bool gen_store_tl(DisasContext *ctx, arg_sb *a, MemOp memop) | 186 | new file mode 100644 |
136 | TCGv addr = get_address(ctx, a->rs1, a->imm); | 187 | index XXXXXXX..XXXXXXX |
137 | TCGv data = get_gpr(ctx, a->rs2, EXT_NONE); | 188 | --- /dev/null |
138 | 189 | +++ b/target/riscv/insn_trans/trans_rvvk.c.inc | |
139 | + if (ctx->ztso) { | 190 | @@ -XXX,XX +XXX,XX @@ |
140 | + tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL); | 191 | +/* |
141 | + } | 192 | + * RISC-V translation routines for the vector crypto extension. |
142 | + | 193 | + * |
143 | tcg_gen_qemu_st_tl(data, addr, ctx->mem_idx, memop); | 194 | + * Copyright (C) 2023 SiFive, Inc. |
144 | return true; | 195 | + * Written by Codethink Ltd and SiFive. |
145 | } | 196 | + * |
146 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | 197 | + * This program is free software; you can redistribute it and/or modify it |
147 | index XXXXXXX..XXXXXXX 100644 | 198 | + * under the terms and conditions of the GNU General Public License, |
148 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | 199 | + * version 2 or later, as published by the Free Software Foundation. |
149 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | 200 | + * |
150 | @@ -XXX,XX +XXX,XX @@ static bool ldst_us_trans(uint32_t vd, uint32_t rs1, uint32_t data, | 201 | + * This program is distributed in the hope it will be useful, but WITHOUT |
151 | tcg_gen_addi_ptr(dest, tcg_env, vreg_ofs(s, vd)); | 202 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
152 | tcg_gen_addi_ptr(mask, tcg_env, vreg_ofs(s, 0)); | 203 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
153 | 204 | + * more details. | |
154 | + /* | 205 | + * |
155 | + * According to the specification | 206 | + * You should have received a copy of the GNU General Public License along with |
156 | + * | 207 | + * this program. If not, see <http://www.gnu.org/licenses/>. |
157 | + * Additionally, if the Ztso extension is implemented, then vector memory | 208 | + */ |
158 | + * instructions in the V extension and Zve family of extensions follow | 209 | + |
159 | + * RVTSO at the instruction level. The Ztso extension does not | 210 | +/* |
160 | + * strengthen the ordering of intra-instruction element accesses. | 211 | + * Zvbc |
161 | + * | 212 | + */ |
162 | + * as a result neither ordered nor unordered accesses from the V | 213 | + |
163 | + * instructions need ordering within the loop but we do still need barriers | 214 | +#define GEN_VV_MASKED_TRANS(NAME, CHECK) \ |
164 | + * around the loop. | 215 | + static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ |
165 | + */ | 216 | + { \ |
166 | + if (is_store && s->ztso) { | 217 | + if (CHECK(s, a)) { \ |
167 | + tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL); | 218 | + return opivv_trans(a->rd, a->rs1, a->rs2, a->vm, \ |
168 | + } | 219 | + gen_helper_##NAME, s); \ |
169 | + | 220 | + } \ |
170 | fn(dest, mask, base, tcg_env, desc); | 221 | + return false; \ |
171 | 222 | + } | |
172 | + if (!is_store && s->ztso) { | 223 | + |
173 | + tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ); | 224 | +static bool vclmul_vv_check(DisasContext *s, arg_rmrr *a) |
174 | + } | 225 | +{ |
175 | + | 226 | + return opivv_check(s, a) && |
176 | if (!is_store) { | 227 | + s->cfg_ptr->ext_zvbc == true && |
177 | mark_vs_dirty(s); | 228 | + s->sew == MO_64; |
178 | } | 229 | +} |
230 | + | ||
231 | +GEN_VV_MASKED_TRANS(vclmul_vv, vclmul_vv_check) | ||
232 | +GEN_VV_MASKED_TRANS(vclmulh_vv, vclmul_vv_check) | ||
233 | + | ||
234 | +#define GEN_VX_MASKED_TRANS(NAME, CHECK) \ | ||
235 | + static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ | ||
236 | + { \ | ||
237 | + if (CHECK(s, a)) { \ | ||
238 | + return opivx_trans(a->rd, a->rs1, a->rs2, a->vm, \ | ||
239 | + gen_helper_##NAME, s); \ | ||
240 | + } \ | ||
241 | + return false; \ | ||
242 | + } | ||
243 | + | ||
244 | +static bool vclmul_vx_check(DisasContext *s, arg_rmrr *a) | ||
245 | +{ | ||
246 | + return opivx_check(s, a) && | ||
247 | + s->cfg_ptr->ext_zvbc == true && | ||
248 | + s->sew == MO_64; | ||
249 | +} | ||
250 | + | ||
251 | +GEN_VX_MASKED_TRANS(vclmul_vx, vclmul_vx_check) | ||
252 | +GEN_VX_MASKED_TRANS(vclmulh_vx, vclmul_vx_check) | ||
253 | diff --git a/target/riscv/meson.build b/target/riscv/meson.build | ||
254 | index XXXXXXX..XXXXXXX 100644 | ||
255 | --- a/target/riscv/meson.build | ||
256 | +++ b/target/riscv/meson.build | ||
257 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(files( | ||
258 | 'translate.c', | ||
259 | 'm128_helper.c', | ||
260 | 'crypto_helper.c', | ||
261 | - 'zce_helper.c' | ||
262 | + 'zce_helper.c', | ||
263 | + 'vcrypto_helper.c' | ||
264 | )) | ||
265 | riscv_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c'), if_false: files('kvm-stub.c')) | ||
266 | |||
179 | -- | 267 | -- |
180 | 2.44.0 | 268 | 2.41.0 |
181 | |||
182 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Nazar Kazakov <nazar.kazakov@codethink.co.uk> |
---|---|---|---|
2 | 2 | ||
3 | After the 'mark_vs_dirty' changes from the previous patch the 'is_store' | 3 | Move the checks out of `do_opiv{v,x,i}_gvec{,_shift}` functions |
4 | bool is unused in some load/store functions that were changed. Remove it. | 4 | and into the corresponding macros. This enables the functions to be |
5 | reused in proceeding commits without check duplication. | ||
5 | 6 | ||
6 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 7 | Signed-off-by: Nazar Kazakov <nazar.kazakov@codethink.co.uk> |
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 9 | Reviewed-by: Weiwei Li <liweiwei@iscas.ac.cn> |
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Max Chou <max.chou@sifive.com> |
10 | Message-ID: <20240306171932.549549-3-dbarboza@ventanamicro.com> | 11 | Message-ID: <20230711165917.2629866-6-max.chou@sifive.com> |
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 13 | --- |
13 | target/riscv/insn_trans/trans_rvv.c.inc | 58 ++++++++++++------------- | 14 | target/riscv/insn_trans/trans_rvv.c.inc | 28 +++++++++++-------------- |
14 | 1 file changed, 29 insertions(+), 29 deletions(-) | 15 | 1 file changed, 12 insertions(+), 16 deletions(-) |
15 | 16 | ||
16 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | 17 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc |
17 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | 19 | --- a/target/riscv/insn_trans/trans_rvv.c.inc |
19 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | 20 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc |
20 | @@ -XXX,XX +XXX,XX @@ typedef void gen_helper_ldst_stride(TCGv_ptr, TCGv_ptr, TCGv, | 21 | @@ -XXX,XX +XXX,XX @@ do_opivv_gvec(DisasContext *s, arg_rmrr *a, GVecGen3Fn *gvec_fn, |
21 | 22 | gen_helper_gvec_4_ptr *fn) | |
22 | static bool ldst_stride_trans(uint32_t vd, uint32_t rs1, uint32_t rs2, | ||
23 | uint32_t data, gen_helper_ldst_stride *fn, | ||
24 | - DisasContext *s, bool is_store) | ||
25 | + DisasContext *s) | ||
26 | { | 23 | { |
27 | TCGv_ptr dest, mask; | 24 | TCGLabel *over = gen_new_label(); |
28 | TCGv base, stride; | 25 | - if (!opivv_check(s, a)) { |
29 | @@ -XXX,XX +XXX,XX @@ static bool ld_stride_op(DisasContext *s, arg_rnfvm *a, uint8_t eew) | 26 | - return false; |
30 | data = FIELD_DP32(data, VDATA, NF, a->nf); | 27 | - } |
31 | data = FIELD_DP32(data, VDATA, VTA, s->vta); | 28 | |
32 | data = FIELD_DP32(data, VDATA, VMA, s->vma); | 29 | tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); |
33 | - return ldst_stride_trans(a->rd, a->rs1, a->rs2, data, fn, s, false); | 30 | |
34 | + return ldst_stride_trans(a->rd, a->rs1, a->rs2, data, fn, s); | 31 | @@ -XXX,XX +XXX,XX @@ static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ |
32 | gen_helper_##NAME##_b, gen_helper_##NAME##_h, \ | ||
33 | gen_helper_##NAME##_w, gen_helper_##NAME##_d, \ | ||
34 | }; \ | ||
35 | + if (!opivv_check(s, a)) { \ | ||
36 | + return false; \ | ||
37 | + } \ | ||
38 | return do_opivv_gvec(s, a, tcg_gen_gvec_##SUF, fns[s->sew]); \ | ||
35 | } | 39 | } |
36 | 40 | ||
37 | static bool ld_stride_check(DisasContext *s, arg_rnfvm* a, uint8_t eew) | 41 | @@ -XXX,XX +XXX,XX @@ static inline bool |
38 | @@ -XXX,XX +XXX,XX @@ static bool st_stride_op(DisasContext *s, arg_rnfvm *a, uint8_t eew) | 42 | do_opivx_gvec(DisasContext *s, arg_rmrr *a, GVecGen2sFn *gvec_fn, |
39 | return false; | 43 | gen_helper_opivx *fn) |
40 | } | 44 | { |
41 | 45 | - if (!opivx_check(s, a)) { | |
42 | - return ldst_stride_trans(a->rd, a->rs1, a->rs2, data, fn, s, true); | 46 | - return false; |
43 | + return ldst_stride_trans(a->rd, a->rs1, a->rs2, data, fn, s); | 47 | - } |
48 | - | ||
49 | if (a->vm && s->vl_eq_vlmax && !(s->vta && s->lmul < 0)) { | ||
50 | TCGv_i64 src1 = tcg_temp_new_i64(); | ||
51 | |||
52 | @@ -XXX,XX +XXX,XX @@ static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ | ||
53 | gen_helper_##NAME##_b, gen_helper_##NAME##_h, \ | ||
54 | gen_helper_##NAME##_w, gen_helper_##NAME##_d, \ | ||
55 | }; \ | ||
56 | + if (!opivx_check(s, a)) { \ | ||
57 | + return false; \ | ||
58 | + } \ | ||
59 | return do_opivx_gvec(s, a, tcg_gen_gvec_##SUF, fns[s->sew]); \ | ||
44 | } | 60 | } |
45 | 61 | ||
46 | static bool st_stride_check(DisasContext *s, arg_rnfvm* a, uint8_t eew) | 62 | @@ -XXX,XX +XXX,XX @@ static inline bool |
47 | @@ -XXX,XX +XXX,XX @@ typedef void gen_helper_ldst_index(TCGv_ptr, TCGv_ptr, TCGv, | 63 | do_opivi_gvec(DisasContext *s, arg_rmrr *a, GVecGen2iFn *gvec_fn, |
48 | 64 | gen_helper_opivx *fn, imm_mode_t imm_mode) | |
49 | static bool ldst_index_trans(uint32_t vd, uint32_t rs1, uint32_t vs2, | ||
50 | uint32_t data, gen_helper_ldst_index *fn, | ||
51 | - DisasContext *s, bool is_store) | ||
52 | + DisasContext *s) | ||
53 | { | 65 | { |
54 | TCGv_ptr dest, mask, index; | 66 | - if (!opivx_check(s, a)) { |
55 | TCGv base; | 67 | - return false; |
56 | @@ -XXX,XX +XXX,XX @@ static bool ld_index_op(DisasContext *s, arg_rnfvm *a, uint8_t eew) | 68 | - } |
57 | data = FIELD_DP32(data, VDATA, NF, a->nf); | 69 | - |
58 | data = FIELD_DP32(data, VDATA, VTA, s->vta); | 70 | if (a->vm && s->vl_eq_vlmax && !(s->vta && s->lmul < 0)) { |
59 | data = FIELD_DP32(data, VDATA, VMA, s->vma); | 71 | gvec_fn(s->sew, vreg_ofs(s, a->rd), vreg_ofs(s, a->rs2), |
60 | - return ldst_index_trans(a->rd, a->rs1, a->rs2, data, fn, s, false); | 72 | extract_imm(s, a->rs1, imm_mode), MAXSZ(s), MAXSZ(s)); |
61 | + return ldst_index_trans(a->rd, a->rs1, a->rs2, data, fn, s); | 73 | @@ -XXX,XX +XXX,XX @@ static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ |
74 | gen_helper_##OPIVX##_b, gen_helper_##OPIVX##_h, \ | ||
75 | gen_helper_##OPIVX##_w, gen_helper_##OPIVX##_d, \ | ||
76 | }; \ | ||
77 | + if (!opivx_check(s, a)) { \ | ||
78 | + return false; \ | ||
79 | + } \ | ||
80 | return do_opivi_gvec(s, a, tcg_gen_gvec_##SUF, \ | ||
81 | fns[s->sew], IMM_MODE); \ | ||
62 | } | 82 | } |
63 | 83 | @@ -XXX,XX +XXX,XX @@ static inline bool | |
64 | static bool ld_index_check(DisasContext *s, arg_rnfvm* a, uint8_t eew) | 84 | do_opivx_gvec_shift(DisasContext *s, arg_rmrr *a, GVecGen2sFn32 *gvec_fn, |
65 | @@ -XXX,XX +XXX,XX @@ static bool st_index_op(DisasContext *s, arg_rnfvm *a, uint8_t eew) | 85 | gen_helper_opivx *fn) |
66 | data = FIELD_DP32(data, VDATA, VM, a->vm); | 86 | { |
67 | data = FIELD_DP32(data, VDATA, LMUL, emul); | 87 | - if (!opivx_check(s, a)) { |
68 | data = FIELD_DP32(data, VDATA, NF, a->nf); | 88 | - return false; |
69 | - return ldst_index_trans(a->rd, a->rs1, a->rs2, data, fn, s, true); | 89 | - } |
70 | + return ldst_index_trans(a->rd, a->rs1, a->rs2, data, fn, s); | 90 | - |
91 | if (a->vm && s->vl_eq_vlmax && !(s->vta && s->lmul < 0)) { | ||
92 | TCGv_i32 src1 = tcg_temp_new_i32(); | ||
93 | |||
94 | @@ -XXX,XX +XXX,XX @@ static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ | ||
95 | gen_helper_##NAME##_b, gen_helper_##NAME##_h, \ | ||
96 | gen_helper_##NAME##_w, gen_helper_##NAME##_d, \ | ||
97 | }; \ | ||
98 | - \ | ||
99 | + if (!opivx_check(s, a)) { \ | ||
100 | + return false; \ | ||
101 | + } \ | ||
102 | return do_opivx_gvec_shift(s, a, tcg_gen_gvec_##SUF, fns[s->sew]); \ | ||
71 | } | 103 | } |
72 | 104 | ||
73 | static bool st_index_check(DisasContext *s, arg_rnfvm* a, uint8_t eew) | ||
74 | @@ -XXX,XX +XXX,XX @@ typedef void gen_helper_ldst_whole(TCGv_ptr, TCGv, TCGv_env, TCGv_i32); | ||
75 | |||
76 | static bool ldst_whole_trans(uint32_t vd, uint32_t rs1, uint32_t nf, | ||
77 | uint32_t width, gen_helper_ldst_whole *fn, | ||
78 | - DisasContext *s, bool is_store) | ||
79 | + DisasContext *s) | ||
80 | { | ||
81 | uint32_t evl = s->cfg_ptr->vlenb * nf / width; | ||
82 | TCGLabel *over = gen_new_label(); | ||
83 | @@ -XXX,XX +XXX,XX @@ static bool ldst_whole_trans(uint32_t vd, uint32_t rs1, uint32_t nf, | ||
84 | * load and store whole register instructions ignore vtype and vl setting. | ||
85 | * Thus, we don't need to check vill bit. (Section 7.9) | ||
86 | */ | ||
87 | -#define GEN_LDST_WHOLE_TRANS(NAME, ARG_NF, WIDTH, IS_STORE) \ | ||
88 | +#define GEN_LDST_WHOLE_TRANS(NAME, ARG_NF, WIDTH) \ | ||
89 | static bool trans_##NAME(DisasContext *s, arg_##NAME * a) \ | ||
90 | { \ | ||
91 | if (require_rvv(s) && \ | ||
92 | QEMU_IS_ALIGNED(a->rd, ARG_NF)) { \ | ||
93 | return ldst_whole_trans(a->rd, a->rs1, ARG_NF, WIDTH, \ | ||
94 | - gen_helper_##NAME, s, IS_STORE); \ | ||
95 | + gen_helper_##NAME, s); \ | ||
96 | } \ | ||
97 | return false; \ | ||
98 | } | ||
99 | |||
100 | -GEN_LDST_WHOLE_TRANS(vl1re8_v, 1, 1, false) | ||
101 | -GEN_LDST_WHOLE_TRANS(vl1re16_v, 1, 2, false) | ||
102 | -GEN_LDST_WHOLE_TRANS(vl1re32_v, 1, 4, false) | ||
103 | -GEN_LDST_WHOLE_TRANS(vl1re64_v, 1, 8, false) | ||
104 | -GEN_LDST_WHOLE_TRANS(vl2re8_v, 2, 1, false) | ||
105 | -GEN_LDST_WHOLE_TRANS(vl2re16_v, 2, 2, false) | ||
106 | -GEN_LDST_WHOLE_TRANS(vl2re32_v, 2, 4, false) | ||
107 | -GEN_LDST_WHOLE_TRANS(vl2re64_v, 2, 8, false) | ||
108 | -GEN_LDST_WHOLE_TRANS(vl4re8_v, 4, 1, false) | ||
109 | -GEN_LDST_WHOLE_TRANS(vl4re16_v, 4, 2, false) | ||
110 | -GEN_LDST_WHOLE_TRANS(vl4re32_v, 4, 4, false) | ||
111 | -GEN_LDST_WHOLE_TRANS(vl4re64_v, 4, 8, false) | ||
112 | -GEN_LDST_WHOLE_TRANS(vl8re8_v, 8, 1, false) | ||
113 | -GEN_LDST_WHOLE_TRANS(vl8re16_v, 8, 2, false) | ||
114 | -GEN_LDST_WHOLE_TRANS(vl8re32_v, 8, 4, false) | ||
115 | -GEN_LDST_WHOLE_TRANS(vl8re64_v, 8, 8, false) | ||
116 | +GEN_LDST_WHOLE_TRANS(vl1re8_v, 1, 1) | ||
117 | +GEN_LDST_WHOLE_TRANS(vl1re16_v, 1, 2) | ||
118 | +GEN_LDST_WHOLE_TRANS(vl1re32_v, 1, 4) | ||
119 | +GEN_LDST_WHOLE_TRANS(vl1re64_v, 1, 8) | ||
120 | +GEN_LDST_WHOLE_TRANS(vl2re8_v, 2, 1) | ||
121 | +GEN_LDST_WHOLE_TRANS(vl2re16_v, 2, 2) | ||
122 | +GEN_LDST_WHOLE_TRANS(vl2re32_v, 2, 4) | ||
123 | +GEN_LDST_WHOLE_TRANS(vl2re64_v, 2, 8) | ||
124 | +GEN_LDST_WHOLE_TRANS(vl4re8_v, 4, 1) | ||
125 | +GEN_LDST_WHOLE_TRANS(vl4re16_v, 4, 2) | ||
126 | +GEN_LDST_WHOLE_TRANS(vl4re32_v, 4, 4) | ||
127 | +GEN_LDST_WHOLE_TRANS(vl4re64_v, 4, 8) | ||
128 | +GEN_LDST_WHOLE_TRANS(vl8re8_v, 8, 1) | ||
129 | +GEN_LDST_WHOLE_TRANS(vl8re16_v, 8, 2) | ||
130 | +GEN_LDST_WHOLE_TRANS(vl8re32_v, 8, 4) | ||
131 | +GEN_LDST_WHOLE_TRANS(vl8re64_v, 8, 8) | ||
132 | |||
133 | /* | ||
134 | * The vector whole register store instructions are encoded similar to | ||
135 | * unmasked unit-stride store of elements with EEW=8. | ||
136 | */ | ||
137 | -GEN_LDST_WHOLE_TRANS(vs1r_v, 1, 1, true) | ||
138 | -GEN_LDST_WHOLE_TRANS(vs2r_v, 2, 1, true) | ||
139 | -GEN_LDST_WHOLE_TRANS(vs4r_v, 4, 1, true) | ||
140 | -GEN_LDST_WHOLE_TRANS(vs8r_v, 8, 1, true) | ||
141 | +GEN_LDST_WHOLE_TRANS(vs1r_v, 1, 1) | ||
142 | +GEN_LDST_WHOLE_TRANS(vs2r_v, 2, 1) | ||
143 | +GEN_LDST_WHOLE_TRANS(vs4r_v, 4, 1) | ||
144 | +GEN_LDST_WHOLE_TRANS(vs8r_v, 8, 1) | ||
145 | |||
146 | /* | ||
147 | *** Vector Integer Arithmetic Instructions | ||
148 | -- | 105 | -- |
149 | 2.44.0 | 106 | 2.41.0 |
150 | |||
151 | diff view generated by jsdifflib |
1 | From: Sia Jee Heng <jeeheng.sia@starfivetech.com> | 1 | From: Dickon Hood <dickon.hood@codethink.co.uk> |
---|---|---|---|
2 | 2 | ||
3 | RISC-V should also generate the SPCR in a manner similar to ARM. | 3 | Zvbb (implemented in later commit) has a widening instruction, which |
4 | Therefore, instead of replicating the code, relocate this function | 4 | requires an extra check on the enabled extensions. Refactor |
5 | to the common AML build. | 5 | GEN_OPIVX_WIDEN_TRANS() to take a check function to avoid reimplementing |
6 | it. | ||
6 | 7 | ||
7 | Signed-off-by: Sia Jee Heng <jeeheng.sia@starfivetech.com> | 8 | Signed-off-by: Dickon Hood <dickon.hood@codethink.co.uk> |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
9 | Message-ID: <20240129021440.17640-2-jeeheng.sia@starfivetech.com> | 10 | Reviewed-by: Weiwei Li <liweiwei@iscas.ac.cn> |
10 | [ Changes by AF: | 11 | Signed-off-by: Max Chou <max.chou@sifive.com> |
11 | - Add missing Language SPCR entry | 12 | Message-ID: <20230711165917.2629866-7-max.chou@sifive.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 | include/hw/acpi/acpi-defs.h | 33 ++++++++++++++++++ | 15 | target/riscv/insn_trans/trans_rvv.c.inc | 52 +++++++++++-------------- |
16 | include/hw/acpi/aml-build.h | 4 +++ | 16 | 1 file changed, 23 insertions(+), 29 deletions(-) |
17 | hw/acpi/aml-build.c | 53 +++++++++++++++++++++++++++++ | ||
18 | hw/arm/virt-acpi-build.c | 68 +++++++++++++++---------------------- | ||
19 | 4 files changed, 117 insertions(+), 41 deletions(-) | ||
20 | 17 | ||
21 | diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h | 18 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc |
22 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/include/hw/acpi/acpi-defs.h | 20 | --- a/target/riscv/insn_trans/trans_rvv.c.inc |
24 | +++ b/include/hw/acpi/acpi-defs.h | 21 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc |
25 | @@ -XXX,XX +XXX,XX @@ typedef struct AcpiFadtData { | 22 | @@ -XXX,XX +XXX,XX @@ static bool opivx_widen_check(DisasContext *s, arg_rmrr *a) |
26 | unsigned *xdsdt_tbl_offset; | 23 | vext_check_ds(s, a->rd, a->rs2, a->vm); |
27 | } AcpiFadtData; | ||
28 | |||
29 | +typedef struct AcpiGas { | ||
30 | + uint8_t id; /* Address space ID */ | ||
31 | + uint8_t width; /* Register bit width */ | ||
32 | + uint8_t offset; /* Register bit offset */ | ||
33 | + uint8_t size; /* Access size */ | ||
34 | + uint64_t addr; /* Address */ | ||
35 | +} AcpiGas; | ||
36 | + | ||
37 | +/* SPCR (Serial Port Console Redirection table) */ | ||
38 | +typedef struct AcpiSpcrData { | ||
39 | + uint8_t interface_type; | ||
40 | + uint8_t reserved[3]; | ||
41 | + struct AcpiGas base_addr; | ||
42 | + uint8_t interrupt_type; | ||
43 | + uint8_t pc_interrupt; | ||
44 | + uint32_t interrupt; /* Global system interrupt */ | ||
45 | + uint8_t baud_rate; | ||
46 | + uint8_t parity; | ||
47 | + uint8_t stop_bits; | ||
48 | + uint8_t flow_control; | ||
49 | + uint8_t terminal_type; | ||
50 | + uint8_t language; | ||
51 | + uint8_t reserved1; | ||
52 | + uint16_t pci_device_id; /* Must be 0xffff if not PCI device */ | ||
53 | + uint16_t pci_vendor_id; /* Must be 0xffff if not PCI device */ | ||
54 | + uint8_t pci_bus; | ||
55 | + uint8_t pci_device; | ||
56 | + uint8_t pci_function; | ||
57 | + uint32_t pci_flags; | ||
58 | + uint8_t pci_segment; | ||
59 | + uint32_t reserved2; | ||
60 | +} AcpiSpcrData; | ||
61 | + | ||
62 | #define ACPI_FADT_ARM_PSCI_COMPLIANT (1 << 0) | ||
63 | #define ACPI_FADT_ARM_PSCI_USE_HVC (1 << 1) | ||
64 | |||
65 | diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h | ||
66 | index XXXXXXX..XXXXXXX 100644 | ||
67 | --- a/include/hw/acpi/aml-build.h | ||
68 | +++ b/include/hw/acpi/aml-build.h | ||
69 | @@ -XXX,XX +XXX,XX @@ void build_fadt(GArray *tbl, BIOSLinker *linker, const AcpiFadtData *f, | ||
70 | |||
71 | void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog, | ||
72 | const char *oem_id, const char *oem_table_id); | ||
73 | + | ||
74 | +void build_spcr(GArray *table_data, BIOSLinker *linker, | ||
75 | + const AcpiSpcrData *f, const uint8_t rev, | ||
76 | + const char *oem_id, const char *oem_table_id); | ||
77 | #endif | ||
78 | diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c | ||
79 | index XXXXXXX..XXXXXXX 100644 | ||
80 | --- a/hw/acpi/aml-build.c | ||
81 | +++ b/hw/acpi/aml-build.c | ||
82 | @@ -XXX,XX +XXX,XX @@ static void build_processor_hierarchy_node(GArray *tbl, uint32_t flags, | ||
83 | } | ||
84 | } | 24 | } |
85 | 25 | ||
86 | +void build_spcr(GArray *table_data, BIOSLinker *linker, | 26 | -static bool do_opivx_widen(DisasContext *s, arg_rmrr *a, |
87 | + const AcpiSpcrData *f, const uint8_t rev, | 27 | - gen_helper_opivx *fn) |
88 | + const char *oem_id, const char *oem_table_id) | 28 | -{ |
89 | +{ | 29 | - if (opivx_widen_check(s, a)) { |
90 | + AcpiTable table = { .sig = "SPCR", .rev = rev, .oem_id = oem_id, | 30 | - return opivx_trans(a->rd, a->rs1, a->rs2, a->vm, fn, s); |
91 | + .oem_table_id = oem_table_id }; | 31 | - } |
92 | + | 32 | - return false; |
93 | + acpi_table_begin(&table, table_data); | 33 | -} |
94 | + /* Interface type */ | ||
95 | + build_append_int_noprefix(table_data, f->interface_type, 1); | ||
96 | + /* Reserved */ | ||
97 | + build_append_int_noprefix(table_data, 0, 3); | ||
98 | + /* Base Address */ | ||
99 | + build_append_gas(table_data, f->base_addr.id, f->base_addr.width, | ||
100 | + f->base_addr.offset, f->base_addr.size, | ||
101 | + f->base_addr.addr); | ||
102 | + /* Interrupt type */ | ||
103 | + build_append_int_noprefix(table_data, f->interrupt_type, 1); | ||
104 | + /* IRQ */ | ||
105 | + build_append_int_noprefix(table_data, f->pc_interrupt, 1); | ||
106 | + /* Global System Interrupt */ | ||
107 | + build_append_int_noprefix(table_data, f->interrupt, 4); | ||
108 | + /* Baud Rate */ | ||
109 | + build_append_int_noprefix(table_data, f->baud_rate, 1); | ||
110 | + /* Parity */ | ||
111 | + build_append_int_noprefix(table_data, f->parity, 1); | ||
112 | + /* Stop Bits */ | ||
113 | + build_append_int_noprefix(table_data, f->stop_bits, 1); | ||
114 | + /* Flow Control */ | ||
115 | + build_append_int_noprefix(table_data, f->flow_control, 1); | ||
116 | + /* Language */ | ||
117 | + build_append_int_noprefix(table_data, f->language, 1); | ||
118 | + /* Terminal Type */ | ||
119 | + build_append_int_noprefix(table_data, f->terminal_type, 1); | ||
120 | + /* PCI Device ID */ | ||
121 | + build_append_int_noprefix(table_data, f->pci_device_id, 2); | ||
122 | + /* PCI Vendor ID */ | ||
123 | + build_append_int_noprefix(table_data, f->pci_vendor_id, 2); | ||
124 | + /* PCI Bus Number */ | ||
125 | + build_append_int_noprefix(table_data, f->pci_bus, 1); | ||
126 | + /* PCI Device Number */ | ||
127 | + build_append_int_noprefix(table_data, f->pci_device, 1); | ||
128 | + /* PCI Function Number */ | ||
129 | + build_append_int_noprefix(table_data, f->pci_function, 1); | ||
130 | + /* PCI Flags */ | ||
131 | + build_append_int_noprefix(table_data, f->pci_flags, 4); | ||
132 | + /* PCI Segment */ | ||
133 | + build_append_int_noprefix(table_data, f->pci_segment, 1); | ||
134 | + /* Reserved */ | ||
135 | + build_append_int_noprefix(table_data, 0, 4); | ||
136 | + | ||
137 | + acpi_table_end(linker, &table); | ||
138 | +} | ||
139 | /* | ||
140 | * ACPI spec, Revision 6.3 | ||
141 | * 5.2.29 Processor Properties Topology Table (PPTT) | ||
142 | diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c | ||
143 | index XXXXXXX..XXXXXXX 100644 | ||
144 | --- a/hw/arm/virt-acpi-build.c | ||
145 | +++ b/hw/arm/virt-acpi-build.c | ||
146 | @@ -XXX,XX +XXX,XX @@ build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) | ||
147 | * Rev: 1.07 | ||
148 | */ | ||
149 | static void | ||
150 | -build_spcr(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) | ||
151 | +spcr_setup(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) | ||
152 | { | ||
153 | - AcpiTable table = { .sig = "SPCR", .rev = 2, .oem_id = vms->oem_id, | ||
154 | - .oem_table_id = vms->oem_table_id }; | ||
155 | - | 34 | - |
156 | - acpi_table_begin(&table, table_data); | 35 | -#define GEN_OPIVX_WIDEN_TRANS(NAME) \ |
157 | - | 36 | -static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ |
158 | - /* Interface Type */ | 37 | -{ \ |
159 | - build_append_int_noprefix(table_data, 3, 1); /* ARM PL011 UART */ | 38 | - static gen_helper_opivx * const fns[3] = { \ |
160 | - build_append_int_noprefix(table_data, 0, 3); /* Reserved */ | 39 | - gen_helper_##NAME##_b, \ |
161 | - /* Base Address */ | 40 | - gen_helper_##NAME##_h, \ |
162 | - build_append_gas(table_data, AML_AS_SYSTEM_MEMORY, 32, 0, 3, | 41 | - gen_helper_##NAME##_w \ |
163 | - vms->memmap[VIRT_UART].base); | 42 | - }; \ |
164 | - /* Interrupt Type */ | 43 | - return do_opivx_widen(s, a, fns[s->sew]); \ |
165 | - build_append_int_noprefix(table_data, | 44 | +#define GEN_OPIVX_WIDEN_TRANS(NAME, CHECK) \ |
166 | - (1 << 3) /* Bit[3] ARMH GIC interrupt */, 1); | 45 | +static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ |
167 | - build_append_int_noprefix(table_data, 0, 1); /* IRQ */ | 46 | +{ \ |
168 | - /* Global System Interrupt */ | 47 | + if (CHECK(s, a)) { \ |
169 | - build_append_int_noprefix(table_data, | 48 | + static gen_helper_opivx * const fns[3] = { \ |
170 | - vms->irqmap[VIRT_UART] + ARM_SPI_BASE, 4); | 49 | + gen_helper_##NAME##_b, \ |
171 | - build_append_int_noprefix(table_data, 3 /* 9600 */, 1); /* Baud Rate */ | 50 | + gen_helper_##NAME##_h, \ |
172 | - build_append_int_noprefix(table_data, 0 /* No Parity */, 1); /* Parity */ | 51 | + gen_helper_##NAME##_w \ |
173 | - /* Stop Bits */ | 52 | + }; \ |
174 | - build_append_int_noprefix(table_data, 1 /* 1 Stop bit */, 1); | 53 | + return opivx_trans(a->rd, a->rs1, a->rs2, a->vm, fns[s->sew], s); \ |
175 | - /* Flow Control */ | 54 | + } \ |
176 | - build_append_int_noprefix(table_data, | 55 | + return false; \ |
177 | - (1 << 1) /* RTS/CTS hardware flow control */, 1); | ||
178 | - /* Terminal Type */ | ||
179 | - build_append_int_noprefix(table_data, 0 /* VT100 */, 1); | ||
180 | - build_append_int_noprefix(table_data, 0, 1); /* Language */ | ||
181 | - /* PCI Device ID */ | ||
182 | - build_append_int_noprefix(table_data, 0xffff /* not a PCI device*/, 2); | ||
183 | - /* PCI Vendor ID */ | ||
184 | - build_append_int_noprefix(table_data, 0xffff /* not a PCI device*/, 2); | ||
185 | - build_append_int_noprefix(table_data, 0, 1); /* PCI Bus Number */ | ||
186 | - build_append_int_noprefix(table_data, 0, 1); /* PCI Device Number */ | ||
187 | - build_append_int_noprefix(table_data, 0, 1); /* PCI Function Number */ | ||
188 | - build_append_int_noprefix(table_data, 0, 4); /* PCI Flags */ | ||
189 | - build_append_int_noprefix(table_data, 0, 1); /* PCI Segment */ | ||
190 | - build_append_int_noprefix(table_data, 0, 4); /* Reserved */ | ||
191 | + AcpiSpcrData serial = { | ||
192 | + .interface_type = 3, /* ARM PL011 UART */ | ||
193 | + .base_addr.id = AML_AS_SYSTEM_MEMORY, | ||
194 | + .base_addr.width = 32, | ||
195 | + .base_addr.offset = 0, | ||
196 | + .base_addr.size = 3, | ||
197 | + .base_addr.addr = vms->memmap[VIRT_UART].base, | ||
198 | + .interrupt_type = (1 << 3),/* Bit[3] ARMH GIC interrupt*/ | ||
199 | + .pc_interrupt = 0, /* IRQ */ | ||
200 | + .interrupt = (vms->irqmap[VIRT_UART] + ARM_SPI_BASE), | ||
201 | + .baud_rate = 3, /* 9600 */ | ||
202 | + .parity = 0, /* No Parity */ | ||
203 | + .stop_bits = 1, /* 1 Stop bit */ | ||
204 | + .flow_control = 1 << 1, /* RTS/CTS hardware flow control */ | ||
205 | + .terminal_type = 0, /* VT100 */ | ||
206 | + .language = 0, /* Language */ | ||
207 | + .pci_device_id = 0xffff, /* not a PCI device*/ | ||
208 | + .pci_vendor_id = 0xffff, /* not a PCI device*/ | ||
209 | + .pci_bus = 0, | ||
210 | + .pci_device = 0, | ||
211 | + .pci_function = 0, | ||
212 | + .pci_flags = 0, | ||
213 | + .pci_segment = 0, | ||
214 | + }; | ||
215 | |||
216 | - acpi_table_end(linker, &table); | ||
217 | + build_spcr(table_data, linker, &serial, 2, vms->oem_id, vms->oem_table_id); | ||
218 | } | 56 | } |
219 | 57 | ||
220 | /* | 58 | -GEN_OPIVX_WIDEN_TRANS(vwaddu_vx) |
221 | @@ -XXX,XX +XXX,XX @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables) | 59 | -GEN_OPIVX_WIDEN_TRANS(vwadd_vx) |
222 | } | 60 | -GEN_OPIVX_WIDEN_TRANS(vwsubu_vx) |
223 | 61 | -GEN_OPIVX_WIDEN_TRANS(vwsub_vx) | |
224 | acpi_add_table(table_offsets, tables_blob); | 62 | +GEN_OPIVX_WIDEN_TRANS(vwaddu_vx, opivx_widen_check) |
225 | - build_spcr(tables_blob, tables->linker, vms); | 63 | +GEN_OPIVX_WIDEN_TRANS(vwadd_vx, opivx_widen_check) |
226 | + spcr_setup(tables_blob, tables->linker, vms); | 64 | +GEN_OPIVX_WIDEN_TRANS(vwsubu_vx, opivx_widen_check) |
227 | 65 | +GEN_OPIVX_WIDEN_TRANS(vwsub_vx, opivx_widen_check) | |
228 | acpi_add_table(table_offsets, tables_blob); | 66 | |
229 | build_dbg2(tables_blob, tables->linker, vms); | 67 | /* WIDEN OPIVV with WIDEN */ |
68 | static bool opiwv_widen_check(DisasContext *s, arg_rmrr *a) | ||
69 | @@ -XXX,XX +XXX,XX @@ GEN_OPIVX_TRANS(vrem_vx, opivx_check) | ||
70 | GEN_OPIVV_WIDEN_TRANS(vwmul_vv, opivv_widen_check) | ||
71 | GEN_OPIVV_WIDEN_TRANS(vwmulu_vv, opivv_widen_check) | ||
72 | GEN_OPIVV_WIDEN_TRANS(vwmulsu_vv, opivv_widen_check) | ||
73 | -GEN_OPIVX_WIDEN_TRANS(vwmul_vx) | ||
74 | -GEN_OPIVX_WIDEN_TRANS(vwmulu_vx) | ||
75 | -GEN_OPIVX_WIDEN_TRANS(vwmulsu_vx) | ||
76 | +GEN_OPIVX_WIDEN_TRANS(vwmul_vx, opivx_widen_check) | ||
77 | +GEN_OPIVX_WIDEN_TRANS(vwmulu_vx, opivx_widen_check) | ||
78 | +GEN_OPIVX_WIDEN_TRANS(vwmulsu_vx, opivx_widen_check) | ||
79 | |||
80 | /* Vector Single-Width Integer Multiply-Add Instructions */ | ||
81 | GEN_OPIVV_TRANS(vmacc_vv, opivv_check) | ||
82 | @@ -XXX,XX +XXX,XX @@ GEN_OPIVX_TRANS(vnmsub_vx, opivx_check) | ||
83 | GEN_OPIVV_WIDEN_TRANS(vwmaccu_vv, opivv_widen_check) | ||
84 | GEN_OPIVV_WIDEN_TRANS(vwmacc_vv, opivv_widen_check) | ||
85 | GEN_OPIVV_WIDEN_TRANS(vwmaccsu_vv, opivv_widen_check) | ||
86 | -GEN_OPIVX_WIDEN_TRANS(vwmaccu_vx) | ||
87 | -GEN_OPIVX_WIDEN_TRANS(vwmacc_vx) | ||
88 | -GEN_OPIVX_WIDEN_TRANS(vwmaccsu_vx) | ||
89 | -GEN_OPIVX_WIDEN_TRANS(vwmaccus_vx) | ||
90 | +GEN_OPIVX_WIDEN_TRANS(vwmaccu_vx, opivx_widen_check) | ||
91 | +GEN_OPIVX_WIDEN_TRANS(vwmacc_vx, opivx_widen_check) | ||
92 | +GEN_OPIVX_WIDEN_TRANS(vwmaccsu_vx, opivx_widen_check) | ||
93 | +GEN_OPIVX_WIDEN_TRANS(vwmaccus_vx, opivx_widen_check) | ||
94 | |||
95 | /* Vector Integer Merge and Move Instructions */ | ||
96 | static bool trans_vmv_v_v(DisasContext *s, arg_vmv_v_v *a) | ||
230 | -- | 97 | -- |
231 | 2.44.0 | 98 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Kiran Ostrolenk <kiran.ostrolenk@codethink.co.uk> | ||
1 | 2 | ||
3 | Move some macros out of `vector_helper` and into `vector_internals`. | ||
4 | This ensures they can be used by both vector and vector-crypto helpers | ||
5 | (latter implemented in proceeding commits). | ||
6 | |||
7 | Signed-off-by: Kiran Ostrolenk <kiran.ostrolenk@codethink.co.uk> | ||
8 | Reviewed-by: Weiwei Li <liweiwei@iscas.ac.cn> | ||
9 | Signed-off-by: Max Chou <max.chou@sifive.com> | ||
10 | Message-ID: <20230711165917.2629866-8-max.chou@sifive.com> | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | --- | ||
13 | target/riscv/vector_internals.h | 46 +++++++++++++++++++++++++++++++++ | ||
14 | target/riscv/vector_helper.c | 42 ------------------------------ | ||
15 | 2 files changed, 46 insertions(+), 42 deletions(-) | ||
16 | |||
17 | diff --git a/target/riscv/vector_internals.h b/target/riscv/vector_internals.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/target/riscv/vector_internals.h | ||
20 | +++ b/target/riscv/vector_internals.h | ||
21 | @@ -XXX,XX +XXX,XX @@ void vext_set_elems_1s(void *base, uint32_t is_agnostic, uint32_t cnt, | ||
22 | /* expand macro args before macro */ | ||
23 | #define RVVCALL(macro, ...) macro(__VA_ARGS__) | ||
24 | |||
25 | +/* (TD, T2, TX2) */ | ||
26 | +#define OP_UU_B uint8_t, uint8_t, uint8_t | ||
27 | +#define OP_UU_H uint16_t, uint16_t, uint16_t | ||
28 | +#define OP_UU_W uint32_t, uint32_t, uint32_t | ||
29 | +#define OP_UU_D uint64_t, uint64_t, uint64_t | ||
30 | + | ||
31 | /* (TD, T1, T2, TX1, TX2) */ | ||
32 | #define OP_UUU_B uint8_t, uint8_t, uint8_t, uint8_t, uint8_t | ||
33 | #define OP_UUU_H uint16_t, uint16_t, uint16_t, uint16_t, uint16_t | ||
34 | #define OP_UUU_W uint32_t, uint32_t, uint32_t, uint32_t, uint32_t | ||
35 | #define OP_UUU_D uint64_t, uint64_t, uint64_t, uint64_t, uint64_t | ||
36 | |||
37 | +#define OPIVV1(NAME, TD, T2, TX2, HD, HS2, OP) \ | ||
38 | +static void do_##NAME(void *vd, void *vs2, int i) \ | ||
39 | +{ \ | ||
40 | + TX2 s2 = *((T2 *)vs2 + HS2(i)); \ | ||
41 | + *((TD *)vd + HD(i)) = OP(s2); \ | ||
42 | +} | ||
43 | + | ||
44 | +#define GEN_VEXT_V(NAME, ESZ) \ | ||
45 | +void HELPER(NAME)(void *vd, void *v0, void *vs2, \ | ||
46 | + CPURISCVState *env, uint32_t desc) \ | ||
47 | +{ \ | ||
48 | + uint32_t vm = vext_vm(desc); \ | ||
49 | + uint32_t vl = env->vl; \ | ||
50 | + uint32_t total_elems = \ | ||
51 | + vext_get_total_elems(env, desc, ESZ); \ | ||
52 | + uint32_t vta = vext_vta(desc); \ | ||
53 | + uint32_t vma = vext_vma(desc); \ | ||
54 | + uint32_t i; \ | ||
55 | + \ | ||
56 | + for (i = env->vstart; i < vl; i++) { \ | ||
57 | + if (!vm && !vext_elem_mask(v0, i)) { \ | ||
58 | + /* set masked-off elements to 1s */ \ | ||
59 | + vext_set_elems_1s(vd, vma, i * ESZ, \ | ||
60 | + (i + 1) * ESZ); \ | ||
61 | + continue; \ | ||
62 | + } \ | ||
63 | + do_##NAME(vd, vs2, i); \ | ||
64 | + } \ | ||
65 | + env->vstart = 0; \ | ||
66 | + /* set tail elements to 1s */ \ | ||
67 | + vext_set_elems_1s(vd, vta, vl * ESZ, \ | ||
68 | + total_elems * ESZ); \ | ||
69 | +} | ||
70 | + | ||
71 | /* operation of two vector elements */ | ||
72 | typedef void opivv2_fn(void *vd, void *vs1, void *vs2, int i); | ||
73 | |||
74 | @@ -XXX,XX +XXX,XX @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, \ | ||
75 | do_##NAME, ESZ); \ | ||
76 | } | ||
77 | |||
78 | +/* Three of the widening shortening macros: */ | ||
79 | +/* (TD, T1, T2, TX1, TX2) */ | ||
80 | +#define WOP_UUU_B uint16_t, uint8_t, uint8_t, uint16_t, uint16_t | ||
81 | +#define WOP_UUU_H uint32_t, uint16_t, uint16_t, uint32_t, uint32_t | ||
82 | +#define WOP_UUU_W uint64_t, uint32_t, uint32_t, uint64_t, uint64_t | ||
83 | + | ||
84 | #endif /* TARGET_RISCV_VECTOR_INTERNALS_H */ | ||
85 | diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c | ||
86 | index XXXXXXX..XXXXXXX 100644 | ||
87 | --- a/target/riscv/vector_helper.c | ||
88 | +++ b/target/riscv/vector_helper.c | ||
89 | @@ -XXX,XX +XXX,XX @@ GEN_VEXT_ST_WHOLE(vs8r_v, int8_t, ste_b) | ||
90 | #define OP_SUS_H int16_t, uint16_t, int16_t, uint16_t, int16_t | ||
91 | #define OP_SUS_W int32_t, uint32_t, int32_t, uint32_t, int32_t | ||
92 | #define OP_SUS_D int64_t, uint64_t, int64_t, uint64_t, int64_t | ||
93 | -#define WOP_UUU_B uint16_t, uint8_t, uint8_t, uint16_t, uint16_t | ||
94 | -#define WOP_UUU_H uint32_t, uint16_t, uint16_t, uint32_t, uint32_t | ||
95 | -#define WOP_UUU_W uint64_t, uint32_t, uint32_t, uint64_t, uint64_t | ||
96 | #define WOP_SSS_B int16_t, int8_t, int8_t, int16_t, int16_t | ||
97 | #define WOP_SSS_H int32_t, int16_t, int16_t, int32_t, int32_t | ||
98 | #define WOP_SSS_W int64_t, int32_t, int32_t, int64_t, int64_t | ||
99 | @@ -XXX,XX +XXX,XX @@ GEN_VEXT_VF(vfwnmsac_vf_h, 4) | ||
100 | GEN_VEXT_VF(vfwnmsac_vf_w, 8) | ||
101 | |||
102 | /* Vector Floating-Point Square-Root Instruction */ | ||
103 | -/* (TD, T2, TX2) */ | ||
104 | -#define OP_UU_H uint16_t, uint16_t, uint16_t | ||
105 | -#define OP_UU_W uint32_t, uint32_t, uint32_t | ||
106 | -#define OP_UU_D uint64_t, uint64_t, uint64_t | ||
107 | - | ||
108 | #define OPFVV1(NAME, TD, T2, TX2, HD, HS2, OP) \ | ||
109 | static void do_##NAME(void *vd, void *vs2, int i, \ | ||
110 | CPURISCVState *env) \ | ||
111 | @@ -XXX,XX +XXX,XX @@ GEN_VEXT_CMP_VF(vmfge_vf_w, uint32_t, H4, vmfge32) | ||
112 | GEN_VEXT_CMP_VF(vmfge_vf_d, uint64_t, H8, vmfge64) | ||
113 | |||
114 | /* Vector Floating-Point Classify Instruction */ | ||
115 | -#define OPIVV1(NAME, TD, T2, TX2, HD, HS2, OP) \ | ||
116 | -static void do_##NAME(void *vd, void *vs2, int i) \ | ||
117 | -{ \ | ||
118 | - TX2 s2 = *((T2 *)vs2 + HS2(i)); \ | ||
119 | - *((TD *)vd + HD(i)) = OP(s2); \ | ||
120 | -} | ||
121 | - | ||
122 | -#define GEN_VEXT_V(NAME, ESZ) \ | ||
123 | -void HELPER(NAME)(void *vd, void *v0, void *vs2, \ | ||
124 | - CPURISCVState *env, uint32_t desc) \ | ||
125 | -{ \ | ||
126 | - uint32_t vm = vext_vm(desc); \ | ||
127 | - uint32_t vl = env->vl; \ | ||
128 | - uint32_t total_elems = \ | ||
129 | - vext_get_total_elems(env, desc, ESZ); \ | ||
130 | - uint32_t vta = vext_vta(desc); \ | ||
131 | - uint32_t vma = vext_vma(desc); \ | ||
132 | - uint32_t i; \ | ||
133 | - \ | ||
134 | - for (i = env->vstart; i < vl; i++) { \ | ||
135 | - if (!vm && !vext_elem_mask(v0, i)) { \ | ||
136 | - /* set masked-off elements to 1s */ \ | ||
137 | - vext_set_elems_1s(vd, vma, i * ESZ, \ | ||
138 | - (i + 1) * ESZ); \ | ||
139 | - continue; \ | ||
140 | - } \ | ||
141 | - do_##NAME(vd, vs2, i); \ | ||
142 | - } \ | ||
143 | - env->vstart = 0; \ | ||
144 | - /* set tail elements to 1s */ \ | ||
145 | - vext_set_elems_1s(vd, vta, vl * ESZ, \ | ||
146 | - total_elems * ESZ); \ | ||
147 | -} | ||
148 | - | ||
149 | target_ulong fclass_h(uint64_t frs1) | ||
150 | { | ||
151 | float16 f = frs1; | ||
152 | -- | ||
153 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Dickon Hood <dickon.hood@codethink.co.uk> |
---|---|---|---|
2 | 2 | ||
3 | Add a RISC-V 'virt' machine to the graph. This implementation is a | 3 | This commit adds support for the Zvbb vector-crypto extension, which |
4 | modified copy of the existing arm machine in arm-virt-machine.c | 4 | consists of the following instructions: |
5 | 5 | ||
6 | It contains a virtio-mmio and a generic-pcihost controller. The | 6 | * vrol.[vv,vx] |
7 | generic-pcihost controller hardcodes assumptions from the ARM 'virt' | 7 | * vror.[vv,vx,vi] |
8 | machine, like ecam and pio_base addresses, so we'll add an extra step to | 8 | * vbrev8.v |
9 | set its parameters after creating it. | 9 | * vrev8.v |
10 | * vandn.[vv,vx] | ||
11 | * vbrev.v | ||
12 | * vclz.v | ||
13 | * vctz.v | ||
14 | * vcpop.v | ||
15 | * vwsll.[vv,vx,vi] | ||
10 | 16 | ||
11 | Our command line is incremented with 'aclint' parameters to allow the | 17 | Translation functions are defined in |
12 | machine to run MSI tests. | 18 | `target/riscv/insn_trans/trans_rvvk.c.inc` and helpers are defined in |
19 | `target/riscv/vcrypto_helper.c`. | ||
13 | 20 | ||
14 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 21 | Co-authored-by: Nazar Kazakov <nazar.kazakov@codethink.co.uk> |
15 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | 22 | Co-authored-by: William Salmon <will.salmon@codethink.co.uk> |
16 | Acked-by: Thomas Huth <thuth@redhat.com> | 23 | Co-authored-by: Kiran Ostrolenk <kiran.ostrolenk@codethink.co.uk> |
17 | Message-ID: <20240217192607.32565-7-dbarboza@ventanamicro.com> | 24 | [max.chou@sifive.com: Fix imm mode of vror.vi] |
25 | Signed-off-by: Nazar Kazakov <nazar.kazakov@codethink.co.uk> | ||
26 | Signed-off-by: William Salmon <will.salmon@codethink.co.uk> | ||
27 | Signed-off-by: Kiran Ostrolenk <kiran.ostrolenk@codethink.co.uk> | ||
28 | Signed-off-by: Dickon Hood <dickon.hood@codethink.co.uk> | ||
29 | Signed-off-by: Max Chou <max.chou@sifive.com> | ||
30 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
31 | [max.chou@sifive.com: Exposed x-zvbb property] | ||
32 | Message-ID: <20230711165917.2629866-9-max.chou@sifive.com> | ||
18 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 33 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
19 | --- | 34 | --- |
20 | tests/qtest/libqos/riscv-virt-machine.c | 137 ++++++++++++++++++++++++ | 35 | target/riscv/cpu_cfg.h | 1 + |
21 | tests/qtest/libqos/meson.build | 1 + | 36 | target/riscv/helper.h | 62 +++++++++ |
22 | 2 files changed, 138 insertions(+) | 37 | target/riscv/insn32.decode | 20 +++ |
23 | create mode 100644 tests/qtest/libqos/riscv-virt-machine.c | 38 | target/riscv/cpu.c | 12 ++ |
39 | target/riscv/vcrypto_helper.c | 138 +++++++++++++++++++ | ||
40 | target/riscv/insn_trans/trans_rvvk.c.inc | 164 +++++++++++++++++++++++ | ||
41 | 6 files changed, 397 insertions(+) | ||
24 | 42 | ||
25 | diff --git a/tests/qtest/libqos/riscv-virt-machine.c b/tests/qtest/libqos/riscv-virt-machine.c | 43 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h |
26 | new file mode 100644 | 44 | index XXXXXXX..XXXXXXX 100644 |
27 | index XXXXXXX..XXXXXXX | 45 | --- a/target/riscv/cpu_cfg.h |
28 | --- /dev/null | 46 | +++ b/target/riscv/cpu_cfg.h |
29 | +++ b/tests/qtest/libqos/riscv-virt-machine.c | 47 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { |
48 | bool ext_zve32f; | ||
49 | bool ext_zve64f; | ||
50 | bool ext_zve64d; | ||
51 | + bool ext_zvbb; | ||
52 | bool ext_zvbc; | ||
53 | bool ext_zmmul; | ||
54 | bool ext_zvfbfmin; | ||
55 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h | ||
56 | index XXXXXXX..XXXXXXX 100644 | ||
57 | --- a/target/riscv/helper.h | ||
58 | +++ b/target/riscv/helper.h | ||
59 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_6(vclmul_vv, void, ptr, ptr, ptr, ptr, env, i32) | ||
60 | DEF_HELPER_6(vclmul_vx, void, ptr, ptr, tl, ptr, env, i32) | ||
61 | DEF_HELPER_6(vclmulh_vv, void, ptr, ptr, ptr, ptr, env, i32) | ||
62 | DEF_HELPER_6(vclmulh_vx, void, ptr, ptr, tl, ptr, env, i32) | ||
63 | + | ||
64 | +DEF_HELPER_6(vror_vv_b, void, ptr, ptr, ptr, ptr, env, i32) | ||
65 | +DEF_HELPER_6(vror_vv_h, void, ptr, ptr, ptr, ptr, env, i32) | ||
66 | +DEF_HELPER_6(vror_vv_w, void, ptr, ptr, ptr, ptr, env, i32) | ||
67 | +DEF_HELPER_6(vror_vv_d, void, ptr, ptr, ptr, ptr, env, i32) | ||
68 | + | ||
69 | +DEF_HELPER_6(vror_vx_b, void, ptr, ptr, tl, ptr, env, i32) | ||
70 | +DEF_HELPER_6(vror_vx_h, void, ptr, ptr, tl, ptr, env, i32) | ||
71 | +DEF_HELPER_6(vror_vx_w, void, ptr, ptr, tl, ptr, env, i32) | ||
72 | +DEF_HELPER_6(vror_vx_d, void, ptr, ptr, tl, ptr, env, i32) | ||
73 | + | ||
74 | +DEF_HELPER_6(vrol_vv_b, void, ptr, ptr, ptr, ptr, env, i32) | ||
75 | +DEF_HELPER_6(vrol_vv_h, void, ptr, ptr, ptr, ptr, env, i32) | ||
76 | +DEF_HELPER_6(vrol_vv_w, void, ptr, ptr, ptr, ptr, env, i32) | ||
77 | +DEF_HELPER_6(vrol_vv_d, void, ptr, ptr, ptr, ptr, env, i32) | ||
78 | + | ||
79 | +DEF_HELPER_6(vrol_vx_b, void, ptr, ptr, tl, ptr, env, i32) | ||
80 | +DEF_HELPER_6(vrol_vx_h, void, ptr, ptr, tl, ptr, env, i32) | ||
81 | +DEF_HELPER_6(vrol_vx_w, void, ptr, ptr, tl, ptr, env, i32) | ||
82 | +DEF_HELPER_6(vrol_vx_d, void, ptr, ptr, tl, ptr, env, i32) | ||
83 | + | ||
84 | +DEF_HELPER_5(vrev8_v_b, void, ptr, ptr, ptr, env, i32) | ||
85 | +DEF_HELPER_5(vrev8_v_h, void, ptr, ptr, ptr, env, i32) | ||
86 | +DEF_HELPER_5(vrev8_v_w, void, ptr, ptr, ptr, env, i32) | ||
87 | +DEF_HELPER_5(vrev8_v_d, void, ptr, ptr, ptr, env, i32) | ||
88 | +DEF_HELPER_5(vbrev8_v_b, void, ptr, ptr, ptr, env, i32) | ||
89 | +DEF_HELPER_5(vbrev8_v_h, void, ptr, ptr, ptr, env, i32) | ||
90 | +DEF_HELPER_5(vbrev8_v_w, void, ptr, ptr, ptr, env, i32) | ||
91 | +DEF_HELPER_5(vbrev8_v_d, void, ptr, ptr, ptr, env, i32) | ||
92 | +DEF_HELPER_5(vbrev_v_b, void, ptr, ptr, ptr, env, i32) | ||
93 | +DEF_HELPER_5(vbrev_v_h, void, ptr, ptr, ptr, env, i32) | ||
94 | +DEF_HELPER_5(vbrev_v_w, void, ptr, ptr, ptr, env, i32) | ||
95 | +DEF_HELPER_5(vbrev_v_d, void, ptr, ptr, ptr, env, i32) | ||
96 | + | ||
97 | +DEF_HELPER_5(vclz_v_b, void, ptr, ptr, ptr, env, i32) | ||
98 | +DEF_HELPER_5(vclz_v_h, void, ptr, ptr, ptr, env, i32) | ||
99 | +DEF_HELPER_5(vclz_v_w, void, ptr, ptr, ptr, env, i32) | ||
100 | +DEF_HELPER_5(vclz_v_d, void, ptr, ptr, ptr, env, i32) | ||
101 | +DEF_HELPER_5(vctz_v_b, void, ptr, ptr, ptr, env, i32) | ||
102 | +DEF_HELPER_5(vctz_v_h, void, ptr, ptr, ptr, env, i32) | ||
103 | +DEF_HELPER_5(vctz_v_w, void, ptr, ptr, ptr, env, i32) | ||
104 | +DEF_HELPER_5(vctz_v_d, void, ptr, ptr, ptr, env, i32) | ||
105 | +DEF_HELPER_5(vcpop_v_b, void, ptr, ptr, ptr, env, i32) | ||
106 | +DEF_HELPER_5(vcpop_v_h, void, ptr, ptr, ptr, env, i32) | ||
107 | +DEF_HELPER_5(vcpop_v_w, void, ptr, ptr, ptr, env, i32) | ||
108 | +DEF_HELPER_5(vcpop_v_d, void, ptr, ptr, ptr, env, i32) | ||
109 | + | ||
110 | +DEF_HELPER_6(vwsll_vv_b, void, ptr, ptr, ptr, ptr, env, i32) | ||
111 | +DEF_HELPER_6(vwsll_vv_h, void, ptr, ptr, ptr, ptr, env, i32) | ||
112 | +DEF_HELPER_6(vwsll_vv_w, void, ptr, ptr, ptr, ptr, env, i32) | ||
113 | +DEF_HELPER_6(vwsll_vx_b, void, ptr, ptr, tl, ptr, env, i32) | ||
114 | +DEF_HELPER_6(vwsll_vx_h, void, ptr, ptr, tl, ptr, env, i32) | ||
115 | +DEF_HELPER_6(vwsll_vx_w, void, ptr, ptr, tl, ptr, env, i32) | ||
116 | + | ||
117 | +DEF_HELPER_6(vandn_vv_b, void, ptr, ptr, ptr, ptr, env, i32) | ||
118 | +DEF_HELPER_6(vandn_vv_h, void, ptr, ptr, ptr, ptr, env, i32) | ||
119 | +DEF_HELPER_6(vandn_vv_w, void, ptr, ptr, ptr, ptr, env, i32) | ||
120 | +DEF_HELPER_6(vandn_vv_d, void, ptr, ptr, ptr, ptr, env, i32) | ||
121 | +DEF_HELPER_6(vandn_vx_b, void, ptr, ptr, tl, ptr, env, i32) | ||
122 | +DEF_HELPER_6(vandn_vx_h, void, ptr, ptr, tl, ptr, env, i32) | ||
123 | +DEF_HELPER_6(vandn_vx_w, void, ptr, ptr, tl, ptr, env, i32) | ||
124 | +DEF_HELPER_6(vandn_vx_d, void, ptr, ptr, tl, ptr, env, i32) | ||
125 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | ||
126 | index XXXXXXX..XXXXXXX 100644 | ||
127 | --- a/target/riscv/insn32.decode | ||
128 | +++ b/target/riscv/insn32.decode | ||
30 | @@ -XXX,XX +XXX,XX @@ | 129 | @@ -XXX,XX +XXX,XX @@ |
130 | %imm_u 12:s20 !function=ex_shift_12 | ||
131 | %imm_bs 30:2 !function=ex_shift_3 | ||
132 | %imm_rnum 20:4 | ||
133 | +%imm_z6 26:1 15:5 | ||
134 | |||
135 | # Argument sets: | ||
136 | &empty | ||
137 | @@ -XXX,XX +XXX,XX @@ | ||
138 | @r_vm ...... vm:1 ..... ..... ... ..... ....... &rmrr %rs2 %rs1 %rd | ||
139 | @r_vm_1 ...... . ..... ..... ... ..... ....... &rmrr vm=1 %rs2 %rs1 %rd | ||
140 | @r_vm_0 ...... . ..... ..... ... ..... ....... &rmrr vm=0 %rs2 %rs1 %rd | ||
141 | +@r2_zimm6 ..... . vm:1 ..... ..... ... ..... ....... &rmrr %rs2 rs1=%imm_z6 %rd | ||
142 | @r2_zimm11 . zimm:11 ..... ... ..... ....... %rs1 %rd | ||
143 | @r2_zimm10 .. zimm:10 ..... ... ..... ....... %rs1 %rd | ||
144 | @r2_s ....... ..... ..... ... ..... ....... %rs2 %rs1 | ||
145 | @@ -XXX,XX +XXX,XX @@ vclmul_vv 001100 . ..... ..... 010 ..... 1010111 @r_vm | ||
146 | vclmul_vx 001100 . ..... ..... 110 ..... 1010111 @r_vm | ||
147 | vclmulh_vv 001101 . ..... ..... 010 ..... 1010111 @r_vm | ||
148 | vclmulh_vx 001101 . ..... ..... 110 ..... 1010111 @r_vm | ||
149 | + | ||
150 | +# *** Zvbb vector crypto extension *** | ||
151 | +vrol_vv 010101 . ..... ..... 000 ..... 1010111 @r_vm | ||
152 | +vrol_vx 010101 . ..... ..... 100 ..... 1010111 @r_vm | ||
153 | +vror_vv 010100 . ..... ..... 000 ..... 1010111 @r_vm | ||
154 | +vror_vx 010100 . ..... ..... 100 ..... 1010111 @r_vm | ||
155 | +vror_vi 01010. . ..... ..... 011 ..... 1010111 @r2_zimm6 | ||
156 | +vbrev8_v 010010 . ..... 01000 010 ..... 1010111 @r2_vm | ||
157 | +vrev8_v 010010 . ..... 01001 010 ..... 1010111 @r2_vm | ||
158 | +vandn_vv 000001 . ..... ..... 000 ..... 1010111 @r_vm | ||
159 | +vandn_vx 000001 . ..... ..... 100 ..... 1010111 @r_vm | ||
160 | +vbrev_v 010010 . ..... 01010 010 ..... 1010111 @r2_vm | ||
161 | +vclz_v 010010 . ..... 01100 010 ..... 1010111 @r2_vm | ||
162 | +vctz_v 010010 . ..... 01101 010 ..... 1010111 @r2_vm | ||
163 | +vcpop_v 010010 . ..... 01110 010 ..... 1010111 @r2_vm | ||
164 | +vwsll_vv 110101 . ..... ..... 000 ..... 1010111 @r_vm | ||
165 | +vwsll_vx 110101 . ..... ..... 100 ..... 1010111 @r_vm | ||
166 | +vwsll_vi 110101 . ..... ..... 011 ..... 1010111 @r_vm | ||
167 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
168 | index XXXXXXX..XXXXXXX 100644 | ||
169 | --- a/target/riscv/cpu.c | ||
170 | +++ b/target/riscv/cpu.c | ||
171 | @@ -XXX,XX +XXX,XX @@ static const struct isa_ext_data isa_edata_arr[] = { | ||
172 | ISA_EXT_DATA_ENTRY(zksed, PRIV_VERSION_1_12_0, ext_zksed), | ||
173 | ISA_EXT_DATA_ENTRY(zksh, PRIV_VERSION_1_12_0, ext_zksh), | ||
174 | ISA_EXT_DATA_ENTRY(zkt, PRIV_VERSION_1_12_0, ext_zkt), | ||
175 | + ISA_EXT_DATA_ENTRY(zvbb, PRIV_VERSION_1_12_0, ext_zvbb), | ||
176 | ISA_EXT_DATA_ENTRY(zvbc, PRIV_VERSION_1_12_0, ext_zvbc), | ||
177 | ISA_EXT_DATA_ENTRY(zve32f, PRIV_VERSION_1_10_0, ext_zve32f), | ||
178 | ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f), | ||
179 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
180 | return; | ||
181 | } | ||
182 | |||
183 | + /* | ||
184 | + * In principle Zve*x would also suffice here, were they supported | ||
185 | + * in qemu | ||
186 | + */ | ||
187 | + if (cpu->cfg.ext_zvbb && !cpu->cfg.ext_zve32f) { | ||
188 | + error_setg(errp, | ||
189 | + "Vector crypto extensions require V or Zve* extensions"); | ||
190 | + return; | ||
191 | + } | ||
192 | + | ||
193 | if (cpu->cfg.ext_zvbc && !cpu->cfg.ext_zve64f) { | ||
194 | error_setg(errp, "Zvbc extension requires V or Zve64{f,d} extensions"); | ||
195 | return; | ||
196 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = { | ||
197 | DEFINE_PROP_BOOL("x-zvfbfwma", RISCVCPU, cfg.ext_zvfbfwma, false), | ||
198 | |||
199 | /* Vector cryptography extensions */ | ||
200 | + DEFINE_PROP_BOOL("x-zvbb", RISCVCPU, cfg.ext_zvbb, false), | ||
201 | DEFINE_PROP_BOOL("x-zvbc", RISCVCPU, cfg.ext_zvbc, false), | ||
202 | |||
203 | DEFINE_PROP_END_OF_LIST(), | ||
204 | diff --git a/target/riscv/vcrypto_helper.c b/target/riscv/vcrypto_helper.c | ||
205 | index XXXXXXX..XXXXXXX 100644 | ||
206 | --- a/target/riscv/vcrypto_helper.c | ||
207 | +++ b/target/riscv/vcrypto_helper.c | ||
208 | @@ -XXX,XX +XXX,XX @@ | ||
209 | #include "qemu/osdep.h" | ||
210 | #include "qemu/host-utils.h" | ||
211 | #include "qemu/bitops.h" | ||
212 | +#include "qemu/bswap.h" | ||
213 | #include "cpu.h" | ||
214 | #include "exec/memop.h" | ||
215 | #include "exec/exec-all.h" | ||
216 | @@ -XXX,XX +XXX,XX @@ RVVCALL(OPIVV2, vclmulh_vv, OP_UUU_D, H8, H8, H8, clmulh64) | ||
217 | GEN_VEXT_VV(vclmulh_vv, 8) | ||
218 | RVVCALL(OPIVX2, vclmulh_vx, OP_UUU_D, H8, H8, clmulh64) | ||
219 | GEN_VEXT_VX(vclmulh_vx, 8) | ||
220 | + | ||
221 | +RVVCALL(OPIVV2, vror_vv_b, OP_UUU_B, H1, H1, H1, ror8) | ||
222 | +RVVCALL(OPIVV2, vror_vv_h, OP_UUU_H, H2, H2, H2, ror16) | ||
223 | +RVVCALL(OPIVV2, vror_vv_w, OP_UUU_W, H4, H4, H4, ror32) | ||
224 | +RVVCALL(OPIVV2, vror_vv_d, OP_UUU_D, H8, H8, H8, ror64) | ||
225 | +GEN_VEXT_VV(vror_vv_b, 1) | ||
226 | +GEN_VEXT_VV(vror_vv_h, 2) | ||
227 | +GEN_VEXT_VV(vror_vv_w, 4) | ||
228 | +GEN_VEXT_VV(vror_vv_d, 8) | ||
229 | + | ||
230 | +RVVCALL(OPIVX2, vror_vx_b, OP_UUU_B, H1, H1, ror8) | ||
231 | +RVVCALL(OPIVX2, vror_vx_h, OP_UUU_H, H2, H2, ror16) | ||
232 | +RVVCALL(OPIVX2, vror_vx_w, OP_UUU_W, H4, H4, ror32) | ||
233 | +RVVCALL(OPIVX2, vror_vx_d, OP_UUU_D, H8, H8, ror64) | ||
234 | +GEN_VEXT_VX(vror_vx_b, 1) | ||
235 | +GEN_VEXT_VX(vror_vx_h, 2) | ||
236 | +GEN_VEXT_VX(vror_vx_w, 4) | ||
237 | +GEN_VEXT_VX(vror_vx_d, 8) | ||
238 | + | ||
239 | +RVVCALL(OPIVV2, vrol_vv_b, OP_UUU_B, H1, H1, H1, rol8) | ||
240 | +RVVCALL(OPIVV2, vrol_vv_h, OP_UUU_H, H2, H2, H2, rol16) | ||
241 | +RVVCALL(OPIVV2, vrol_vv_w, OP_UUU_W, H4, H4, H4, rol32) | ||
242 | +RVVCALL(OPIVV2, vrol_vv_d, OP_UUU_D, H8, H8, H8, rol64) | ||
243 | +GEN_VEXT_VV(vrol_vv_b, 1) | ||
244 | +GEN_VEXT_VV(vrol_vv_h, 2) | ||
245 | +GEN_VEXT_VV(vrol_vv_w, 4) | ||
246 | +GEN_VEXT_VV(vrol_vv_d, 8) | ||
247 | + | ||
248 | +RVVCALL(OPIVX2, vrol_vx_b, OP_UUU_B, H1, H1, rol8) | ||
249 | +RVVCALL(OPIVX2, vrol_vx_h, OP_UUU_H, H2, H2, rol16) | ||
250 | +RVVCALL(OPIVX2, vrol_vx_w, OP_UUU_W, H4, H4, rol32) | ||
251 | +RVVCALL(OPIVX2, vrol_vx_d, OP_UUU_D, H8, H8, rol64) | ||
252 | +GEN_VEXT_VX(vrol_vx_b, 1) | ||
253 | +GEN_VEXT_VX(vrol_vx_h, 2) | ||
254 | +GEN_VEXT_VX(vrol_vx_w, 4) | ||
255 | +GEN_VEXT_VX(vrol_vx_d, 8) | ||
256 | + | ||
257 | +static uint64_t brev8(uint64_t val) | ||
258 | +{ | ||
259 | + val = ((val & 0x5555555555555555ull) << 1) | | ||
260 | + ((val & 0xAAAAAAAAAAAAAAAAull) >> 1); | ||
261 | + val = ((val & 0x3333333333333333ull) << 2) | | ||
262 | + ((val & 0xCCCCCCCCCCCCCCCCull) >> 2); | ||
263 | + val = ((val & 0x0F0F0F0F0F0F0F0Full) << 4) | | ||
264 | + ((val & 0xF0F0F0F0F0F0F0F0ull) >> 4); | ||
265 | + | ||
266 | + return val; | ||
267 | +} | ||
268 | + | ||
269 | +RVVCALL(OPIVV1, vbrev8_v_b, OP_UU_B, H1, H1, brev8) | ||
270 | +RVVCALL(OPIVV1, vbrev8_v_h, OP_UU_H, H2, H2, brev8) | ||
271 | +RVVCALL(OPIVV1, vbrev8_v_w, OP_UU_W, H4, H4, brev8) | ||
272 | +RVVCALL(OPIVV1, vbrev8_v_d, OP_UU_D, H8, H8, brev8) | ||
273 | +GEN_VEXT_V(vbrev8_v_b, 1) | ||
274 | +GEN_VEXT_V(vbrev8_v_h, 2) | ||
275 | +GEN_VEXT_V(vbrev8_v_w, 4) | ||
276 | +GEN_VEXT_V(vbrev8_v_d, 8) | ||
277 | + | ||
278 | +#define DO_IDENTITY(a) (a) | ||
279 | +RVVCALL(OPIVV1, vrev8_v_b, OP_UU_B, H1, H1, DO_IDENTITY) | ||
280 | +RVVCALL(OPIVV1, vrev8_v_h, OP_UU_H, H2, H2, bswap16) | ||
281 | +RVVCALL(OPIVV1, vrev8_v_w, OP_UU_W, H4, H4, bswap32) | ||
282 | +RVVCALL(OPIVV1, vrev8_v_d, OP_UU_D, H8, H8, bswap64) | ||
283 | +GEN_VEXT_V(vrev8_v_b, 1) | ||
284 | +GEN_VEXT_V(vrev8_v_h, 2) | ||
285 | +GEN_VEXT_V(vrev8_v_w, 4) | ||
286 | +GEN_VEXT_V(vrev8_v_d, 8) | ||
287 | + | ||
288 | +#define DO_ANDN(a, b) ((a) & ~(b)) | ||
289 | +RVVCALL(OPIVV2, vandn_vv_b, OP_UUU_B, H1, H1, H1, DO_ANDN) | ||
290 | +RVVCALL(OPIVV2, vandn_vv_h, OP_UUU_H, H2, H2, H2, DO_ANDN) | ||
291 | +RVVCALL(OPIVV2, vandn_vv_w, OP_UUU_W, H4, H4, H4, DO_ANDN) | ||
292 | +RVVCALL(OPIVV2, vandn_vv_d, OP_UUU_D, H8, H8, H8, DO_ANDN) | ||
293 | +GEN_VEXT_VV(vandn_vv_b, 1) | ||
294 | +GEN_VEXT_VV(vandn_vv_h, 2) | ||
295 | +GEN_VEXT_VV(vandn_vv_w, 4) | ||
296 | +GEN_VEXT_VV(vandn_vv_d, 8) | ||
297 | + | ||
298 | +RVVCALL(OPIVX2, vandn_vx_b, OP_UUU_B, H1, H1, DO_ANDN) | ||
299 | +RVVCALL(OPIVX2, vandn_vx_h, OP_UUU_H, H2, H2, DO_ANDN) | ||
300 | +RVVCALL(OPIVX2, vandn_vx_w, OP_UUU_W, H4, H4, DO_ANDN) | ||
301 | +RVVCALL(OPIVX2, vandn_vx_d, OP_UUU_D, H8, H8, DO_ANDN) | ||
302 | +GEN_VEXT_VX(vandn_vx_b, 1) | ||
303 | +GEN_VEXT_VX(vandn_vx_h, 2) | ||
304 | +GEN_VEXT_VX(vandn_vx_w, 4) | ||
305 | +GEN_VEXT_VX(vandn_vx_d, 8) | ||
306 | + | ||
307 | +RVVCALL(OPIVV1, vbrev_v_b, OP_UU_B, H1, H1, revbit8) | ||
308 | +RVVCALL(OPIVV1, vbrev_v_h, OP_UU_H, H2, H2, revbit16) | ||
309 | +RVVCALL(OPIVV1, vbrev_v_w, OP_UU_W, H4, H4, revbit32) | ||
310 | +RVVCALL(OPIVV1, vbrev_v_d, OP_UU_D, H8, H8, revbit64) | ||
311 | +GEN_VEXT_V(vbrev_v_b, 1) | ||
312 | +GEN_VEXT_V(vbrev_v_h, 2) | ||
313 | +GEN_VEXT_V(vbrev_v_w, 4) | ||
314 | +GEN_VEXT_V(vbrev_v_d, 8) | ||
315 | + | ||
316 | +RVVCALL(OPIVV1, vclz_v_b, OP_UU_B, H1, H1, clz8) | ||
317 | +RVVCALL(OPIVV1, vclz_v_h, OP_UU_H, H2, H2, clz16) | ||
318 | +RVVCALL(OPIVV1, vclz_v_w, OP_UU_W, H4, H4, clz32) | ||
319 | +RVVCALL(OPIVV1, vclz_v_d, OP_UU_D, H8, H8, clz64) | ||
320 | +GEN_VEXT_V(vclz_v_b, 1) | ||
321 | +GEN_VEXT_V(vclz_v_h, 2) | ||
322 | +GEN_VEXT_V(vclz_v_w, 4) | ||
323 | +GEN_VEXT_V(vclz_v_d, 8) | ||
324 | + | ||
325 | +RVVCALL(OPIVV1, vctz_v_b, OP_UU_B, H1, H1, ctz8) | ||
326 | +RVVCALL(OPIVV1, vctz_v_h, OP_UU_H, H2, H2, ctz16) | ||
327 | +RVVCALL(OPIVV1, vctz_v_w, OP_UU_W, H4, H4, ctz32) | ||
328 | +RVVCALL(OPIVV1, vctz_v_d, OP_UU_D, H8, H8, ctz64) | ||
329 | +GEN_VEXT_V(vctz_v_b, 1) | ||
330 | +GEN_VEXT_V(vctz_v_h, 2) | ||
331 | +GEN_VEXT_V(vctz_v_w, 4) | ||
332 | +GEN_VEXT_V(vctz_v_d, 8) | ||
333 | + | ||
334 | +RVVCALL(OPIVV1, vcpop_v_b, OP_UU_B, H1, H1, ctpop8) | ||
335 | +RVVCALL(OPIVV1, vcpop_v_h, OP_UU_H, H2, H2, ctpop16) | ||
336 | +RVVCALL(OPIVV1, vcpop_v_w, OP_UU_W, H4, H4, ctpop32) | ||
337 | +RVVCALL(OPIVV1, vcpop_v_d, OP_UU_D, H8, H8, ctpop64) | ||
338 | +GEN_VEXT_V(vcpop_v_b, 1) | ||
339 | +GEN_VEXT_V(vcpop_v_h, 2) | ||
340 | +GEN_VEXT_V(vcpop_v_w, 4) | ||
341 | +GEN_VEXT_V(vcpop_v_d, 8) | ||
342 | + | ||
343 | +#define DO_SLL(N, M) (N << (M & (sizeof(N) * 8 - 1))) | ||
344 | +RVVCALL(OPIVV2, vwsll_vv_b, WOP_UUU_B, H2, H1, H1, DO_SLL) | ||
345 | +RVVCALL(OPIVV2, vwsll_vv_h, WOP_UUU_H, H4, H2, H2, DO_SLL) | ||
346 | +RVVCALL(OPIVV2, vwsll_vv_w, WOP_UUU_W, H8, H4, H4, DO_SLL) | ||
347 | +GEN_VEXT_VV(vwsll_vv_b, 2) | ||
348 | +GEN_VEXT_VV(vwsll_vv_h, 4) | ||
349 | +GEN_VEXT_VV(vwsll_vv_w, 8) | ||
350 | + | ||
351 | +RVVCALL(OPIVX2, vwsll_vx_b, WOP_UUU_B, H2, H1, DO_SLL) | ||
352 | +RVVCALL(OPIVX2, vwsll_vx_h, WOP_UUU_H, H4, H2, DO_SLL) | ||
353 | +RVVCALL(OPIVX2, vwsll_vx_w, WOP_UUU_W, H8, H4, DO_SLL) | ||
354 | +GEN_VEXT_VX(vwsll_vx_b, 2) | ||
355 | +GEN_VEXT_VX(vwsll_vx_h, 4) | ||
356 | +GEN_VEXT_VX(vwsll_vx_w, 8) | ||
357 | diff --git a/target/riscv/insn_trans/trans_rvvk.c.inc b/target/riscv/insn_trans/trans_rvvk.c.inc | ||
358 | index XXXXXXX..XXXXXXX 100644 | ||
359 | --- a/target/riscv/insn_trans/trans_rvvk.c.inc | ||
360 | +++ b/target/riscv/insn_trans/trans_rvvk.c.inc | ||
361 | @@ -XXX,XX +XXX,XX @@ static bool vclmul_vx_check(DisasContext *s, arg_rmrr *a) | ||
362 | |||
363 | GEN_VX_MASKED_TRANS(vclmul_vx, vclmul_vx_check) | ||
364 | GEN_VX_MASKED_TRANS(vclmulh_vx, vclmul_vx_check) | ||
365 | + | ||
31 | +/* | 366 | +/* |
32 | + * libqos driver framework for risc-v | 367 | + * Zvbb |
33 | + * | ||
34 | + * Initial version based on arm-virt-machine.c | ||
35 | + * | ||
36 | + * Copyright (c) 2024 Ventana Micro | ||
37 | + * | ||
38 | + * This library is free software; you can redistribute it and/or | ||
39 | + * modify it under the terms of the GNU Lesser General Public | ||
40 | + * License version 2.1 as published by the Free Software Foundation. | ||
41 | + * | ||
42 | + * This library is distributed in the hope that it will be useful, | ||
43 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
44 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
45 | + * Lesser General Public License for more details. | ||
46 | + * | ||
47 | + * You should have received a copy of the GNU Lesser General Public | ||
48 | + * License along with this library; if not, see <http://www.gnu.org/licenses/> | ||
49 | + */ | 368 | + */ |
50 | + | 369 | + |
51 | +#include "qemu/osdep.h" | 370 | +#define GEN_OPIVI_GVEC_TRANS_CHECK(NAME, IMM_MODE, OPIVX, SUF, CHECK) \ |
52 | +#include "../libqtest.h" | 371 | + static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ |
53 | +#include "qemu/module.h" | 372 | + { \ |
54 | +#include "libqos-malloc.h" | 373 | + if (CHECK(s, a)) { \ |
55 | +#include "qgraph.h" | 374 | + static gen_helper_opivx *const fns[4] = { \ |
56 | +#include "virtio-mmio.h" | 375 | + gen_helper_##OPIVX##_b, \ |
57 | +#include "generic-pcihost.h" | 376 | + gen_helper_##OPIVX##_h, \ |
58 | +#include "hw/pci/pci_regs.h" | 377 | + gen_helper_##OPIVX##_w, \ |
59 | + | 378 | + gen_helper_##OPIVX##_d, \ |
60 | +#define RISCV_PAGE_SIZE 4096 | 379 | + }; \ |
61 | + | 380 | + return do_opivi_gvec(s, a, tcg_gen_gvec_##SUF, fns[s->sew], \ |
62 | +/* VIRT_DRAM */ | 381 | + IMM_MODE); \ |
63 | +#define RISCV_VIRT_RAM_ADDR 0x80000000 | 382 | + } \ |
64 | +#define RISCV_VIRT_RAM_SIZE 0x20000000 | 383 | + return false; \ |
65 | + | 384 | + } |
66 | +/* | 385 | + |
67 | + * VIRT_VIRTIO. BASE_ADDR points to the last | 386 | +#define GEN_OPIVV_GVEC_TRANS_CHECK(NAME, SUF, CHECK) \ |
68 | + * virtio_mmio device. | 387 | + static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ |
69 | + */ | 388 | + { \ |
70 | +#define VIRTIO_MMIO_BASE_ADDR 0x10008000 | 389 | + if (CHECK(s, a)) { \ |
71 | +#define VIRTIO_MMIO_SIZE 0x00001000 | 390 | + static gen_helper_gvec_4_ptr *const fns[4] = { \ |
72 | + | 391 | + gen_helper_##NAME##_b, \ |
73 | +/* VIRT_PCIE_PIO */ | 392 | + gen_helper_##NAME##_h, \ |
74 | +#define RISCV_GPEX_PIO_BASE 0x3000000 | 393 | + gen_helper_##NAME##_w, \ |
75 | +#define RISCV_BUS_PIO_LIMIT 0x10000 | 394 | + gen_helper_##NAME##_d, \ |
76 | + | 395 | + }; \ |
77 | +/* VIRT_PCIE_MMIO */ | 396 | + return do_opivv_gvec(s, a, tcg_gen_gvec_##SUF, fns[s->sew]); \ |
78 | +#define RISCV_BUS_MMIO_ALLOC_PTR 0x40000000 | 397 | + } \ |
79 | +#define RISCV_BUS_MMIO_LIMIT 0x80000000 | 398 | + return false; \ |
80 | + | 399 | + } |
81 | +/* VIRT_PCIE_ECAM */ | 400 | + |
82 | +#define RISCV_ECAM_ALLOC_PTR 0x30000000 | 401 | +#define GEN_OPIVX_GVEC_SHIFT_TRANS_CHECK(NAME, SUF, CHECK) \ |
83 | + | 402 | + static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ |
84 | +typedef struct QVirtMachine QVirtMachine; | 403 | + { \ |
85 | + | 404 | + if (CHECK(s, a)) { \ |
86 | +struct QVirtMachine { | 405 | + static gen_helper_opivx *const fns[4] = { \ |
87 | + QOSGraphObject obj; | 406 | + gen_helper_##NAME##_b, \ |
88 | + QGuestAllocator alloc; | 407 | + gen_helper_##NAME##_h, \ |
89 | + QVirtioMMIODevice virtio_mmio; | 408 | + gen_helper_##NAME##_w, \ |
90 | + QGenericPCIHost bridge; | 409 | + gen_helper_##NAME##_d, \ |
91 | +}; | 410 | + }; \ |
92 | + | 411 | + return do_opivx_gvec_shift(s, a, tcg_gen_gvec_##SUF, \ |
93 | +static void virt_destructor(QOSGraphObject *obj) | 412 | + fns[s->sew]); \ |
413 | + } \ | ||
414 | + return false; \ | ||
415 | + } | ||
416 | + | ||
417 | +static bool zvbb_vv_check(DisasContext *s, arg_rmrr *a) | ||
94 | +{ | 418 | +{ |
95 | + QVirtMachine *machine = (QVirtMachine *) obj; | 419 | + return opivv_check(s, a) && s->cfg_ptr->ext_zvbb == true; |
96 | + alloc_destroy(&machine->alloc); | ||
97 | +} | 420 | +} |
98 | + | 421 | + |
99 | +static void *virt_get_driver(void *object, const char *interface) | 422 | +static bool zvbb_vx_check(DisasContext *s, arg_rmrr *a) |
100 | +{ | 423 | +{ |
101 | + QVirtMachine *machine = object; | 424 | + return opivx_check(s, a) && s->cfg_ptr->ext_zvbb == true; |
102 | + if (!g_strcmp0(interface, "memory")) { | ||
103 | + return &machine->alloc; | ||
104 | + } | ||
105 | + | ||
106 | + fprintf(stderr, "%s not present in riscv/virtio\n", interface); | ||
107 | + g_assert_not_reached(); | ||
108 | +} | 425 | +} |
109 | + | 426 | + |
110 | +static QOSGraphObject *virt_get_device(void *obj, const char *device) | 427 | +/* vrol.v[vx] */ |
428 | +GEN_OPIVV_GVEC_TRANS_CHECK(vrol_vv, rotlv, zvbb_vv_check) | ||
429 | +GEN_OPIVX_GVEC_SHIFT_TRANS_CHECK(vrol_vx, rotls, zvbb_vx_check) | ||
430 | + | ||
431 | +/* vror.v[vxi] */ | ||
432 | +GEN_OPIVV_GVEC_TRANS_CHECK(vror_vv, rotrv, zvbb_vv_check) | ||
433 | +GEN_OPIVX_GVEC_SHIFT_TRANS_CHECK(vror_vx, rotrs, zvbb_vx_check) | ||
434 | +GEN_OPIVI_GVEC_TRANS_CHECK(vror_vi, IMM_TRUNC_SEW, vror_vx, rotri, zvbb_vx_check) | ||
435 | + | ||
436 | +#define GEN_OPIVX_GVEC_TRANS_CHECK(NAME, SUF, CHECK) \ | ||
437 | + static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ | ||
438 | + { \ | ||
439 | + if (CHECK(s, a)) { \ | ||
440 | + static gen_helper_opivx *const fns[4] = { \ | ||
441 | + gen_helper_##NAME##_b, \ | ||
442 | + gen_helper_##NAME##_h, \ | ||
443 | + gen_helper_##NAME##_w, \ | ||
444 | + gen_helper_##NAME##_d, \ | ||
445 | + }; \ | ||
446 | + return do_opivx_gvec(s, a, tcg_gen_gvec_##SUF, fns[s->sew]); \ | ||
447 | + } \ | ||
448 | + return false; \ | ||
449 | + } | ||
450 | + | ||
451 | +/* vandn.v[vx] */ | ||
452 | +GEN_OPIVV_GVEC_TRANS_CHECK(vandn_vv, andc, zvbb_vv_check) | ||
453 | +GEN_OPIVX_GVEC_TRANS_CHECK(vandn_vx, andcs, zvbb_vx_check) | ||
454 | + | ||
455 | +#define GEN_OPIV_TRANS(NAME, CHECK) \ | ||
456 | + static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ | ||
457 | + { \ | ||
458 | + if (CHECK(s, a)) { \ | ||
459 | + uint32_t data = 0; \ | ||
460 | + static gen_helper_gvec_3_ptr *const fns[4] = { \ | ||
461 | + gen_helper_##NAME##_b, \ | ||
462 | + gen_helper_##NAME##_h, \ | ||
463 | + gen_helper_##NAME##_w, \ | ||
464 | + gen_helper_##NAME##_d, \ | ||
465 | + }; \ | ||
466 | + TCGLabel *over = gen_new_label(); \ | ||
467 | + tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); \ | ||
468 | + \ | ||
469 | + data = FIELD_DP32(data, VDATA, VM, a->vm); \ | ||
470 | + data = FIELD_DP32(data, VDATA, LMUL, s->lmul); \ | ||
471 | + data = FIELD_DP32(data, VDATA, VTA, s->vta); \ | ||
472 | + data = FIELD_DP32(data, VDATA, VTA_ALL_1S, s->cfg_vta_all_1s); \ | ||
473 | + data = FIELD_DP32(data, VDATA, VMA, s->vma); \ | ||
474 | + tcg_gen_gvec_3_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, 0), \ | ||
475 | + vreg_ofs(s, a->rs2), cpu_env, \ | ||
476 | + s->cfg_ptr->vlen / 8, s->cfg_ptr->vlen / 8, \ | ||
477 | + data, fns[s->sew]); \ | ||
478 | + mark_vs_dirty(s); \ | ||
479 | + gen_set_label(over); \ | ||
480 | + return true; \ | ||
481 | + } \ | ||
482 | + return false; \ | ||
483 | + } | ||
484 | + | ||
485 | +static bool zvbb_opiv_check(DisasContext *s, arg_rmr *a) | ||
111 | +{ | 486 | +{ |
112 | + QVirtMachine *machine = obj; | 487 | + return s->cfg_ptr->ext_zvbb == true && |
113 | + if (!g_strcmp0(device, "generic-pcihost")) { | 488 | + require_rvv(s) && |
114 | + return &machine->bridge.obj; | 489 | + vext_check_isa_ill(s) && |
115 | + } else if (!g_strcmp0(device, "virtio-mmio")) { | 490 | + vext_check_ss(s, a->rd, a->rs2, a->vm); |
116 | + return &machine->virtio_mmio.obj; | ||
117 | + } | ||
118 | + | ||
119 | + fprintf(stderr, "%s not present in riscv/virt\n", device); | ||
120 | + g_assert_not_reached(); | ||
121 | +} | 491 | +} |
122 | + | 492 | + |
123 | +static void riscv_config_qpci_bus(QGenericPCIBus *qpci) | 493 | +GEN_OPIV_TRANS(vbrev8_v, zvbb_opiv_check) |
494 | +GEN_OPIV_TRANS(vrev8_v, zvbb_opiv_check) | ||
495 | +GEN_OPIV_TRANS(vbrev_v, zvbb_opiv_check) | ||
496 | +GEN_OPIV_TRANS(vclz_v, zvbb_opiv_check) | ||
497 | +GEN_OPIV_TRANS(vctz_v, zvbb_opiv_check) | ||
498 | +GEN_OPIV_TRANS(vcpop_v, zvbb_opiv_check) | ||
499 | + | ||
500 | +static bool vwsll_vv_check(DisasContext *s, arg_rmrr *a) | ||
124 | +{ | 501 | +{ |
125 | + qpci->gpex_pio_base = RISCV_GPEX_PIO_BASE; | 502 | + return s->cfg_ptr->ext_zvbb && opivv_widen_check(s, a); |
126 | + qpci->bus.pio_limit = RISCV_BUS_PIO_LIMIT; | ||
127 | + | ||
128 | + qpci->bus.mmio_alloc_ptr = RISCV_BUS_MMIO_ALLOC_PTR; | ||
129 | + qpci->bus.mmio_limit = RISCV_BUS_MMIO_LIMIT; | ||
130 | + | ||
131 | + qpci->ecam_alloc_ptr = RISCV_ECAM_ALLOC_PTR; | ||
132 | +} | 503 | +} |
133 | + | 504 | + |
134 | +static void *qos_create_machine_riscv_virt(QTestState *qts) | 505 | +static bool vwsll_vx_check(DisasContext *s, arg_rmrr *a) |
135 | +{ | 506 | +{ |
136 | + QVirtMachine *machine = g_new0(QVirtMachine, 1); | 507 | + return s->cfg_ptr->ext_zvbb && opivx_widen_check(s, a); |
137 | + | ||
138 | + alloc_init(&machine->alloc, 0, | ||
139 | + RISCV_VIRT_RAM_ADDR, | ||
140 | + RISCV_VIRT_RAM_ADDR + RISCV_VIRT_RAM_SIZE, | ||
141 | + RISCV_PAGE_SIZE); | ||
142 | + qvirtio_mmio_init_device(&machine->virtio_mmio, qts, VIRTIO_MMIO_BASE_ADDR, | ||
143 | + VIRTIO_MMIO_SIZE); | ||
144 | + | ||
145 | + qos_create_generic_pcihost(&machine->bridge, qts, &machine->alloc); | ||
146 | + riscv_config_qpci_bus(&machine->bridge.pci); | ||
147 | + | ||
148 | + machine->obj.get_device = virt_get_device; | ||
149 | + machine->obj.get_driver = virt_get_driver; | ||
150 | + machine->obj.destructor = virt_destructor; | ||
151 | + return machine; | ||
152 | +} | 508 | +} |
153 | + | 509 | + |
154 | +static void virt_machine_register_nodes(void) | 510 | +/* OPIVI without GVEC IR */ |
155 | +{ | 511 | +#define GEN_OPIVI_WIDEN_TRANS(NAME, IMM_MODE, OPIVX, CHECK) \ |
156 | + qos_node_create_machine_args("riscv32/virt", qos_create_machine_riscv_virt, | 512 | + static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ |
157 | + "aclint=on,aia=aplic-imsic"); | 513 | + { \ |
158 | + qos_node_contains("riscv32/virt", "virtio-mmio", NULL); | 514 | + if (CHECK(s, a)) { \ |
159 | + qos_node_contains("riscv32/virt", "generic-pcihost", NULL); | 515 | + static gen_helper_opivx *const fns[3] = { \ |
160 | + | 516 | + gen_helper_##OPIVX##_b, \ |
161 | + qos_node_create_machine_args("riscv64/virt", qos_create_machine_riscv_virt, | 517 | + gen_helper_##OPIVX##_h, \ |
162 | + "aclint=on,aia=aplic-imsic"); | 518 | + gen_helper_##OPIVX##_w, \ |
163 | + qos_node_contains("riscv64/virt", "virtio-mmio", NULL); | 519 | + }; \ |
164 | + qos_node_contains("riscv64/virt", "generic-pcihost", NULL); | 520 | + return opivi_trans(a->rd, a->rs1, a->rs2, a->vm, fns[s->sew], s, \ |
165 | +} | 521 | + IMM_MODE); \ |
166 | + | 522 | + } \ |
167 | +libqos_init(virt_machine_register_nodes); | 523 | + return false; \ |
168 | diff --git a/tests/qtest/libqos/meson.build b/tests/qtest/libqos/meson.build | 524 | + } |
169 | index XXXXXXX..XXXXXXX 100644 | 525 | + |
170 | --- a/tests/qtest/libqos/meson.build | 526 | +GEN_OPIVV_WIDEN_TRANS(vwsll_vv, vwsll_vv_check) |
171 | +++ b/tests/qtest/libqos/meson.build | 527 | +GEN_OPIVX_WIDEN_TRANS(vwsll_vx, vwsll_vx_check) |
172 | @@ -XXX,XX +XXX,XX @@ libqos_srcs = files( | 528 | +GEN_OPIVI_WIDEN_TRANS(vwsll_vi, IMM_ZX, vwsll_vx, vwsll_vx_check) |
173 | 'arm-xilinx-zynq-a9-machine.c', | ||
174 | 'ppc64_pseries-machine.c', | ||
175 | 'x86_64_pc-machine.c', | ||
176 | + 'riscv-virt-machine.c', | ||
177 | ) | ||
178 | |||
179 | if have_virtfs | ||
180 | -- | 529 | -- |
181 | 2.44.0 | 530 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Nazar Kazakov <nazar.kazakov@codethink.co.uk> | ||
1 | 2 | ||
3 | This commit adds support for the Zvkned vector-crypto extension, which | ||
4 | consists of the following instructions: | ||
5 | |||
6 | * vaesef.[vv,vs] | ||
7 | * vaesdf.[vv,vs] | ||
8 | * vaesdm.[vv,vs] | ||
9 | * vaesz.vs | ||
10 | * vaesem.[vv,vs] | ||
11 | * vaeskf1.vi | ||
12 | * vaeskf2.vi | ||
13 | |||
14 | Translation functions are defined in | ||
15 | `target/riscv/insn_trans/trans_rvvk.c.inc` and helpers are defined in | ||
16 | `target/riscv/vcrypto_helper.c`. | ||
17 | |||
18 | Co-authored-by: Lawrence Hunter <lawrence.hunter@codethink.co.uk> | ||
19 | Co-authored-by: William Salmon <will.salmon@codethink.co.uk> | ||
20 | [max.chou@sifive.com: Replaced vstart checking by TCG op] | ||
21 | Signed-off-by: Lawrence Hunter <lawrence.hunter@codethink.co.uk> | ||
22 | Signed-off-by: William Salmon <will.salmon@codethink.co.uk> | ||
23 | Signed-off-by: Nazar Kazakov <nazar.kazakov@codethink.co.uk> | ||
24 | Signed-off-by: Max Chou <max.chou@sifive.com> | ||
25 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
26 | [max.chou@sifive.com: Imported aes-round.h and exposed x-zvkned | ||
27 | property] | ||
28 | [max.chou@sifive.com: Fixed endian issues and replaced the vstart & vl | ||
29 | egs checking by helper function] | ||
30 | [max.chou@sifive.com: Replaced bswap32 calls in aes key expanding] | ||
31 | Message-ID: <20230711165917.2629866-10-max.chou@sifive.com> | ||
32 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
33 | --- | ||
34 | target/riscv/cpu_cfg.h | 1 + | ||
35 | target/riscv/helper.h | 14 ++ | ||
36 | target/riscv/insn32.decode | 14 ++ | ||
37 | target/riscv/cpu.c | 4 +- | ||
38 | target/riscv/vcrypto_helper.c | 202 +++++++++++++++++++++++ | ||
39 | target/riscv/insn_trans/trans_rvvk.c.inc | 147 +++++++++++++++++ | ||
40 | 6 files changed, 381 insertions(+), 1 deletion(-) | ||
41 | |||
42 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/target/riscv/cpu_cfg.h | ||
45 | +++ b/target/riscv/cpu_cfg.h | ||
46 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { | ||
47 | bool ext_zve64d; | ||
48 | bool ext_zvbb; | ||
49 | bool ext_zvbc; | ||
50 | + bool ext_zvkned; | ||
51 | bool ext_zmmul; | ||
52 | bool ext_zvfbfmin; | ||
53 | bool ext_zvfbfwma; | ||
54 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h | ||
55 | index XXXXXXX..XXXXXXX 100644 | ||
56 | --- a/target/riscv/helper.h | ||
57 | +++ b/target/riscv/helper.h | ||
58 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_6(vandn_vx_b, void, ptr, ptr, tl, ptr, env, i32) | ||
59 | DEF_HELPER_6(vandn_vx_h, void, ptr, ptr, tl, ptr, env, i32) | ||
60 | DEF_HELPER_6(vandn_vx_w, void, ptr, ptr, tl, ptr, env, i32) | ||
61 | DEF_HELPER_6(vandn_vx_d, void, ptr, ptr, tl, ptr, env, i32) | ||
62 | + | ||
63 | +DEF_HELPER_2(egs_check, void, i32, env) | ||
64 | + | ||
65 | +DEF_HELPER_4(vaesef_vv, void, ptr, ptr, env, i32) | ||
66 | +DEF_HELPER_4(vaesef_vs, void, ptr, ptr, env, i32) | ||
67 | +DEF_HELPER_4(vaesdf_vv, void, ptr, ptr, env, i32) | ||
68 | +DEF_HELPER_4(vaesdf_vs, void, ptr, ptr, env, i32) | ||
69 | +DEF_HELPER_4(vaesem_vv, void, ptr, ptr, env, i32) | ||
70 | +DEF_HELPER_4(vaesem_vs, void, ptr, ptr, env, i32) | ||
71 | +DEF_HELPER_4(vaesdm_vv, void, ptr, ptr, env, i32) | ||
72 | +DEF_HELPER_4(vaesdm_vs, void, ptr, ptr, env, i32) | ||
73 | +DEF_HELPER_4(vaesz_vs, void, ptr, ptr, env, i32) | ||
74 | +DEF_HELPER_5(vaeskf1_vi, void, ptr, ptr, i32, env, i32) | ||
75 | +DEF_HELPER_5(vaeskf2_vi, void, ptr, ptr, i32, env, i32) | ||
76 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | ||
77 | index XXXXXXX..XXXXXXX 100644 | ||
78 | --- a/target/riscv/insn32.decode | ||
79 | +++ b/target/riscv/insn32.decode | ||
80 | @@ -XXX,XX +XXX,XX @@ | ||
81 | @r_rm ....... ..... ..... ... ..... ....... %rs2 %rs1 %rm %rd | ||
82 | @r2_rm ....... ..... ..... ... ..... ....... %rs1 %rm %rd | ||
83 | @r2 ....... ..... ..... ... ..... ....... &r2 %rs1 %rd | ||
84 | +@r2_vm_1 ...... . ..... ..... ... ..... ....... &rmr vm=1 %rs2 %rd | ||
85 | @r2_nfvm ... ... vm:1 ..... ..... ... ..... ....... &r2nfvm %nf %rs1 %rd | ||
86 | @r2_vm ...... vm:1 ..... ..... ... ..... ....... &rmr %rs2 %rd | ||
87 | @r1_vm ...... vm:1 ..... ..... ... ..... ....... %rd | ||
88 | @@ -XXX,XX +XXX,XX @@ vcpop_v 010010 . ..... 01110 010 ..... 1010111 @r2_vm | ||
89 | vwsll_vv 110101 . ..... ..... 000 ..... 1010111 @r_vm | ||
90 | vwsll_vx 110101 . ..... ..... 100 ..... 1010111 @r_vm | ||
91 | vwsll_vi 110101 . ..... ..... 011 ..... 1010111 @r_vm | ||
92 | + | ||
93 | +# *** Zvkned vector crypto extension *** | ||
94 | +vaesef_vv 101000 1 ..... 00011 010 ..... 1110111 @r2_vm_1 | ||
95 | +vaesef_vs 101001 1 ..... 00011 010 ..... 1110111 @r2_vm_1 | ||
96 | +vaesdf_vv 101000 1 ..... 00001 010 ..... 1110111 @r2_vm_1 | ||
97 | +vaesdf_vs 101001 1 ..... 00001 010 ..... 1110111 @r2_vm_1 | ||
98 | +vaesem_vv 101000 1 ..... 00010 010 ..... 1110111 @r2_vm_1 | ||
99 | +vaesem_vs 101001 1 ..... 00010 010 ..... 1110111 @r2_vm_1 | ||
100 | +vaesdm_vv 101000 1 ..... 00000 010 ..... 1110111 @r2_vm_1 | ||
101 | +vaesdm_vs 101001 1 ..... 00000 010 ..... 1110111 @r2_vm_1 | ||
102 | +vaesz_vs 101001 1 ..... 00111 010 ..... 1110111 @r2_vm_1 | ||
103 | +vaeskf1_vi 100010 1 ..... ..... 010 ..... 1110111 @r_vm_1 | ||
104 | +vaeskf2_vi 101010 1 ..... ..... 010 ..... 1110111 @r_vm_1 | ||
105 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
106 | index XXXXXXX..XXXXXXX 100644 | ||
107 | --- a/target/riscv/cpu.c | ||
108 | +++ b/target/riscv/cpu.c | ||
109 | @@ -XXX,XX +XXX,XX @@ static const struct isa_ext_data isa_edata_arr[] = { | ||
110 | ISA_EXT_DATA_ENTRY(zvfbfwma, PRIV_VERSION_1_12_0, ext_zvfbfwma), | ||
111 | ISA_EXT_DATA_ENTRY(zvfh, PRIV_VERSION_1_12_0, ext_zvfh), | ||
112 | ISA_EXT_DATA_ENTRY(zvfhmin, PRIV_VERSION_1_12_0, ext_zvfhmin), | ||
113 | + ISA_EXT_DATA_ENTRY(zvkned, PRIV_VERSION_1_12_0, ext_zvkned), | ||
114 | ISA_EXT_DATA_ENTRY(zhinx, PRIV_VERSION_1_12_0, ext_zhinx), | ||
115 | ISA_EXT_DATA_ENTRY(zhinxmin, PRIV_VERSION_1_12_0, ext_zhinxmin), | ||
116 | ISA_EXT_DATA_ENTRY(smaia, PRIV_VERSION_1_12_0, ext_smaia), | ||
117 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
118 | * In principle Zve*x would also suffice here, were they supported | ||
119 | * in qemu | ||
120 | */ | ||
121 | - if (cpu->cfg.ext_zvbb && !cpu->cfg.ext_zve32f) { | ||
122 | + if ((cpu->cfg.ext_zvbb || cpu->cfg.ext_zvkned) && !cpu->cfg.ext_zve32f) { | ||
123 | error_setg(errp, | ||
124 | "Vector crypto extensions require V or Zve* extensions"); | ||
125 | return; | ||
126 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = { | ||
127 | /* Vector cryptography extensions */ | ||
128 | DEFINE_PROP_BOOL("x-zvbb", RISCVCPU, cfg.ext_zvbb, false), | ||
129 | DEFINE_PROP_BOOL("x-zvbc", RISCVCPU, cfg.ext_zvbc, false), | ||
130 | + DEFINE_PROP_BOOL("x-zvkned", RISCVCPU, cfg.ext_zvkned, false), | ||
131 | |||
132 | DEFINE_PROP_END_OF_LIST(), | ||
133 | }; | ||
134 | diff --git a/target/riscv/vcrypto_helper.c b/target/riscv/vcrypto_helper.c | ||
135 | index XXXXXXX..XXXXXXX 100644 | ||
136 | --- a/target/riscv/vcrypto_helper.c | ||
137 | +++ b/target/riscv/vcrypto_helper.c | ||
138 | @@ -XXX,XX +XXX,XX @@ | ||
139 | #include "qemu/bitops.h" | ||
140 | #include "qemu/bswap.h" | ||
141 | #include "cpu.h" | ||
142 | +#include "crypto/aes.h" | ||
143 | +#include "crypto/aes-round.h" | ||
144 | #include "exec/memop.h" | ||
145 | #include "exec/exec-all.h" | ||
146 | #include "exec/helper-proto.h" | ||
147 | @@ -XXX,XX +XXX,XX @@ RVVCALL(OPIVX2, vwsll_vx_w, WOP_UUU_W, H8, H4, DO_SLL) | ||
148 | GEN_VEXT_VX(vwsll_vx_b, 2) | ||
149 | GEN_VEXT_VX(vwsll_vx_h, 4) | ||
150 | GEN_VEXT_VX(vwsll_vx_w, 8) | ||
151 | + | ||
152 | +void HELPER(egs_check)(uint32_t egs, CPURISCVState *env) | ||
153 | +{ | ||
154 | + uint32_t vl = env->vl; | ||
155 | + uint32_t vstart = env->vstart; | ||
156 | + | ||
157 | + if (vl % egs != 0 || vstart % egs != 0) { | ||
158 | + riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); | ||
159 | + } | ||
160 | +} | ||
161 | + | ||
162 | +static inline void xor_round_key(AESState *round_state, AESState *round_key) | ||
163 | +{ | ||
164 | + round_state->v = round_state->v ^ round_key->v; | ||
165 | +} | ||
166 | + | ||
167 | +#define GEN_ZVKNED_HELPER_VV(NAME, ...) \ | ||
168 | + void HELPER(NAME)(void *vd, void *vs2, CPURISCVState *env, \ | ||
169 | + uint32_t desc) \ | ||
170 | + { \ | ||
171 | + uint32_t vl = env->vl; \ | ||
172 | + uint32_t total_elems = vext_get_total_elems(env, desc, 4); \ | ||
173 | + uint32_t vta = vext_vta(desc); \ | ||
174 | + \ | ||
175 | + for (uint32_t i = env->vstart / 4; i < env->vl / 4; i++) { \ | ||
176 | + AESState round_key; \ | ||
177 | + round_key.d[0] = *((uint64_t *)vs2 + H8(i * 2 + 0)); \ | ||
178 | + round_key.d[1] = *((uint64_t *)vs2 + H8(i * 2 + 1)); \ | ||
179 | + AESState round_state; \ | ||
180 | + round_state.d[0] = *((uint64_t *)vd + H8(i * 2 + 0)); \ | ||
181 | + round_state.d[1] = *((uint64_t *)vd + H8(i * 2 + 1)); \ | ||
182 | + __VA_ARGS__; \ | ||
183 | + *((uint64_t *)vd + H8(i * 2 + 0)) = round_state.d[0]; \ | ||
184 | + *((uint64_t *)vd + H8(i * 2 + 1)) = round_state.d[1]; \ | ||
185 | + } \ | ||
186 | + env->vstart = 0; \ | ||
187 | + /* set tail elements to 1s */ \ | ||
188 | + vext_set_elems_1s(vd, vta, vl * 4, total_elems * 4); \ | ||
189 | + } | ||
190 | + | ||
191 | +#define GEN_ZVKNED_HELPER_VS(NAME, ...) \ | ||
192 | + void HELPER(NAME)(void *vd, void *vs2, CPURISCVState *env, \ | ||
193 | + uint32_t desc) \ | ||
194 | + { \ | ||
195 | + uint32_t vl = env->vl; \ | ||
196 | + uint32_t total_elems = vext_get_total_elems(env, desc, 4); \ | ||
197 | + uint32_t vta = vext_vta(desc); \ | ||
198 | + \ | ||
199 | + for (uint32_t i = env->vstart / 4; i < env->vl / 4; i++) { \ | ||
200 | + AESState round_key; \ | ||
201 | + round_key.d[0] = *((uint64_t *)vs2 + H8(0)); \ | ||
202 | + round_key.d[1] = *((uint64_t *)vs2 + H8(1)); \ | ||
203 | + AESState round_state; \ | ||
204 | + round_state.d[0] = *((uint64_t *)vd + H8(i * 2 + 0)); \ | ||
205 | + round_state.d[1] = *((uint64_t *)vd + H8(i * 2 + 1)); \ | ||
206 | + __VA_ARGS__; \ | ||
207 | + *((uint64_t *)vd + H8(i * 2 + 0)) = round_state.d[0]; \ | ||
208 | + *((uint64_t *)vd + H8(i * 2 + 1)) = round_state.d[1]; \ | ||
209 | + } \ | ||
210 | + env->vstart = 0; \ | ||
211 | + /* set tail elements to 1s */ \ | ||
212 | + vext_set_elems_1s(vd, vta, vl * 4, total_elems * 4); \ | ||
213 | + } | ||
214 | + | ||
215 | +GEN_ZVKNED_HELPER_VV(vaesef_vv, aesenc_SB_SR_AK(&round_state, | ||
216 | + &round_state, | ||
217 | + &round_key, | ||
218 | + false);) | ||
219 | +GEN_ZVKNED_HELPER_VS(vaesef_vs, aesenc_SB_SR_AK(&round_state, | ||
220 | + &round_state, | ||
221 | + &round_key, | ||
222 | + false);) | ||
223 | +GEN_ZVKNED_HELPER_VV(vaesdf_vv, aesdec_ISB_ISR_AK(&round_state, | ||
224 | + &round_state, | ||
225 | + &round_key, | ||
226 | + false);) | ||
227 | +GEN_ZVKNED_HELPER_VS(vaesdf_vs, aesdec_ISB_ISR_AK(&round_state, | ||
228 | + &round_state, | ||
229 | + &round_key, | ||
230 | + false);) | ||
231 | +GEN_ZVKNED_HELPER_VV(vaesem_vv, aesenc_SB_SR_MC_AK(&round_state, | ||
232 | + &round_state, | ||
233 | + &round_key, | ||
234 | + false);) | ||
235 | +GEN_ZVKNED_HELPER_VS(vaesem_vs, aesenc_SB_SR_MC_AK(&round_state, | ||
236 | + &round_state, | ||
237 | + &round_key, | ||
238 | + false);) | ||
239 | +GEN_ZVKNED_HELPER_VV(vaesdm_vv, aesdec_ISB_ISR_AK_IMC(&round_state, | ||
240 | + &round_state, | ||
241 | + &round_key, | ||
242 | + false);) | ||
243 | +GEN_ZVKNED_HELPER_VS(vaesdm_vs, aesdec_ISB_ISR_AK_IMC(&round_state, | ||
244 | + &round_state, | ||
245 | + &round_key, | ||
246 | + false);) | ||
247 | +GEN_ZVKNED_HELPER_VS(vaesz_vs, xor_round_key(&round_state, &round_key);) | ||
248 | + | ||
249 | +void HELPER(vaeskf1_vi)(void *vd_vptr, void *vs2_vptr, uint32_t uimm, | ||
250 | + CPURISCVState *env, uint32_t desc) | ||
251 | +{ | ||
252 | + uint32_t *vd = vd_vptr; | ||
253 | + uint32_t *vs2 = vs2_vptr; | ||
254 | + uint32_t vl = env->vl; | ||
255 | + uint32_t total_elems = vext_get_total_elems(env, desc, 4); | ||
256 | + uint32_t vta = vext_vta(desc); | ||
257 | + | ||
258 | + uimm &= 0b1111; | ||
259 | + if (uimm > 10 || uimm == 0) { | ||
260 | + uimm ^= 0b1000; | ||
261 | + } | ||
262 | + | ||
263 | + for (uint32_t i = env->vstart / 4; i < env->vl / 4; i++) { | ||
264 | + uint32_t rk[8], tmp; | ||
265 | + static const uint32_t rcon[] = { | ||
266 | + 0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010, | ||
267 | + 0x00000020, 0x00000040, 0x00000080, 0x0000001B, 0x00000036, | ||
268 | + }; | ||
269 | + | ||
270 | + rk[0] = vs2[i * 4 + H4(0)]; | ||
271 | + rk[1] = vs2[i * 4 + H4(1)]; | ||
272 | + rk[2] = vs2[i * 4 + H4(2)]; | ||
273 | + rk[3] = vs2[i * 4 + H4(3)]; | ||
274 | + tmp = ror32(rk[3], 8); | ||
275 | + | ||
276 | + rk[4] = rk[0] ^ (((uint32_t)AES_sbox[(tmp >> 24) & 0xff] << 24) | | ||
277 | + ((uint32_t)AES_sbox[(tmp >> 16) & 0xff] << 16) | | ||
278 | + ((uint32_t)AES_sbox[(tmp >> 8) & 0xff] << 8) | | ||
279 | + ((uint32_t)AES_sbox[(tmp >> 0) & 0xff] << 0)) | ||
280 | + ^ rcon[uimm - 1]; | ||
281 | + rk[5] = rk[1] ^ rk[4]; | ||
282 | + rk[6] = rk[2] ^ rk[5]; | ||
283 | + rk[7] = rk[3] ^ rk[6]; | ||
284 | + | ||
285 | + vd[i * 4 + H4(0)] = rk[4]; | ||
286 | + vd[i * 4 + H4(1)] = rk[5]; | ||
287 | + vd[i * 4 + H4(2)] = rk[6]; | ||
288 | + vd[i * 4 + H4(3)] = rk[7]; | ||
289 | + } | ||
290 | + env->vstart = 0; | ||
291 | + /* set tail elements to 1s */ | ||
292 | + vext_set_elems_1s(vd, vta, vl * 4, total_elems * 4); | ||
293 | +} | ||
294 | + | ||
295 | +void HELPER(vaeskf2_vi)(void *vd_vptr, void *vs2_vptr, uint32_t uimm, | ||
296 | + CPURISCVState *env, uint32_t desc) | ||
297 | +{ | ||
298 | + uint32_t *vd = vd_vptr; | ||
299 | + uint32_t *vs2 = vs2_vptr; | ||
300 | + uint32_t vl = env->vl; | ||
301 | + uint32_t total_elems = vext_get_total_elems(env, desc, 4); | ||
302 | + uint32_t vta = vext_vta(desc); | ||
303 | + | ||
304 | + uimm &= 0b1111; | ||
305 | + if (uimm > 14 || uimm < 2) { | ||
306 | + uimm ^= 0b1000; | ||
307 | + } | ||
308 | + | ||
309 | + for (uint32_t i = env->vstart / 4; i < env->vl / 4; i++) { | ||
310 | + uint32_t rk[12], tmp; | ||
311 | + static const uint32_t rcon[] = { | ||
312 | + 0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010, | ||
313 | + 0x00000020, 0x00000040, 0x00000080, 0x0000001B, 0x00000036, | ||
314 | + }; | ||
315 | + | ||
316 | + rk[0] = vd[i * 4 + H4(0)]; | ||
317 | + rk[1] = vd[i * 4 + H4(1)]; | ||
318 | + rk[2] = vd[i * 4 + H4(2)]; | ||
319 | + rk[3] = vd[i * 4 + H4(3)]; | ||
320 | + rk[4] = vs2[i * 4 + H4(0)]; | ||
321 | + rk[5] = vs2[i * 4 + H4(1)]; | ||
322 | + rk[6] = vs2[i * 4 + H4(2)]; | ||
323 | + rk[7] = vs2[i * 4 + H4(3)]; | ||
324 | + | ||
325 | + if (uimm % 2 == 0) { | ||
326 | + tmp = ror32(rk[7], 8); | ||
327 | + rk[8] = rk[0] ^ (((uint32_t)AES_sbox[(tmp >> 24) & 0xff] << 24) | | ||
328 | + ((uint32_t)AES_sbox[(tmp >> 16) & 0xff] << 16) | | ||
329 | + ((uint32_t)AES_sbox[(tmp >> 8) & 0xff] << 8) | | ||
330 | + ((uint32_t)AES_sbox[(tmp >> 0) & 0xff] << 0)) | ||
331 | + ^ rcon[(uimm - 1) / 2]; | ||
332 | + } else { | ||
333 | + rk[8] = rk[0] ^ (((uint32_t)AES_sbox[(rk[7] >> 24) & 0xff] << 24) | | ||
334 | + ((uint32_t)AES_sbox[(rk[7] >> 16) & 0xff] << 16) | | ||
335 | + ((uint32_t)AES_sbox[(rk[7] >> 8) & 0xff] << 8) | | ||
336 | + ((uint32_t)AES_sbox[(rk[7] >> 0) & 0xff] << 0)); | ||
337 | + } | ||
338 | + rk[9] = rk[1] ^ rk[8]; | ||
339 | + rk[10] = rk[2] ^ rk[9]; | ||
340 | + rk[11] = rk[3] ^ rk[10]; | ||
341 | + | ||
342 | + vd[i * 4 + H4(0)] = rk[8]; | ||
343 | + vd[i * 4 + H4(1)] = rk[9]; | ||
344 | + vd[i * 4 + H4(2)] = rk[10]; | ||
345 | + vd[i * 4 + H4(3)] = rk[11]; | ||
346 | + } | ||
347 | + env->vstart = 0; | ||
348 | + /* set tail elements to 1s */ | ||
349 | + vext_set_elems_1s(vd, vta, vl * 4, total_elems * 4); | ||
350 | +} | ||
351 | diff --git a/target/riscv/insn_trans/trans_rvvk.c.inc b/target/riscv/insn_trans/trans_rvvk.c.inc | ||
352 | index XXXXXXX..XXXXXXX 100644 | ||
353 | --- a/target/riscv/insn_trans/trans_rvvk.c.inc | ||
354 | +++ b/target/riscv/insn_trans/trans_rvvk.c.inc | ||
355 | @@ -XXX,XX +XXX,XX @@ static bool vwsll_vx_check(DisasContext *s, arg_rmrr *a) | ||
356 | GEN_OPIVV_WIDEN_TRANS(vwsll_vv, vwsll_vv_check) | ||
357 | GEN_OPIVX_WIDEN_TRANS(vwsll_vx, vwsll_vx_check) | ||
358 | GEN_OPIVI_WIDEN_TRANS(vwsll_vi, IMM_ZX, vwsll_vx, vwsll_vx_check) | ||
359 | + | ||
360 | +/* | ||
361 | + * Zvkned | ||
362 | + */ | ||
363 | + | ||
364 | +#define ZVKNED_EGS 4 | ||
365 | + | ||
366 | +#define GEN_V_UNMASKED_TRANS(NAME, CHECK, EGS) \ | ||
367 | + static bool trans_##NAME(DisasContext *s, arg_##NAME *a) \ | ||
368 | + { \ | ||
369 | + if (CHECK(s, a)) { \ | ||
370 | + TCGv_ptr rd_v, rs2_v; \ | ||
371 | + TCGv_i32 desc, egs; \ | ||
372 | + uint32_t data = 0; \ | ||
373 | + TCGLabel *over = gen_new_label(); \ | ||
374 | + \ | ||
375 | + if (!s->vstart_eq_zero || !s->vl_eq_vlmax) { \ | ||
376 | + /* save opcode for unwinding in case we throw an exception */ \ | ||
377 | + decode_save_opc(s); \ | ||
378 | + egs = tcg_constant_i32(EGS); \ | ||
379 | + gen_helper_egs_check(egs, cpu_env); \ | ||
380 | + tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); \ | ||
381 | + } \ | ||
382 | + \ | ||
383 | + data = FIELD_DP32(data, VDATA, VM, a->vm); \ | ||
384 | + data = FIELD_DP32(data, VDATA, LMUL, s->lmul); \ | ||
385 | + data = FIELD_DP32(data, VDATA, VTA, s->vta); \ | ||
386 | + data = FIELD_DP32(data, VDATA, VTA_ALL_1S, s->cfg_vta_all_1s); \ | ||
387 | + data = FIELD_DP32(data, VDATA, VMA, s->vma); \ | ||
388 | + rd_v = tcg_temp_new_ptr(); \ | ||
389 | + rs2_v = tcg_temp_new_ptr(); \ | ||
390 | + desc = tcg_constant_i32( \ | ||
391 | + simd_desc(s->cfg_ptr->vlen / 8, s->cfg_ptr->vlen / 8, data)); \ | ||
392 | + tcg_gen_addi_ptr(rd_v, cpu_env, vreg_ofs(s, a->rd)); \ | ||
393 | + tcg_gen_addi_ptr(rs2_v, cpu_env, vreg_ofs(s, a->rs2)); \ | ||
394 | + gen_helper_##NAME(rd_v, rs2_v, cpu_env, desc); \ | ||
395 | + mark_vs_dirty(s); \ | ||
396 | + gen_set_label(over); \ | ||
397 | + return true; \ | ||
398 | + } \ | ||
399 | + return false; \ | ||
400 | + } | ||
401 | + | ||
402 | +static bool vaes_check_vv(DisasContext *s, arg_rmr *a) | ||
403 | +{ | ||
404 | + int egw_bytes = ZVKNED_EGS << s->sew; | ||
405 | + return s->cfg_ptr->ext_zvkned == true && | ||
406 | + require_rvv(s) && | ||
407 | + vext_check_isa_ill(s) && | ||
408 | + MAXSZ(s) >= egw_bytes && | ||
409 | + require_align(a->rd, s->lmul) && | ||
410 | + require_align(a->rs2, s->lmul) && | ||
411 | + s->sew == MO_32; | ||
412 | +} | ||
413 | + | ||
414 | +static bool vaes_check_overlap(DisasContext *s, int vd, int vs2) | ||
415 | +{ | ||
416 | + int8_t op_size = s->lmul <= 0 ? 1 : 1 << s->lmul; | ||
417 | + return !is_overlapped(vd, op_size, vs2, 1); | ||
418 | +} | ||
419 | + | ||
420 | +static bool vaes_check_vs(DisasContext *s, arg_rmr *a) | ||
421 | +{ | ||
422 | + int egw_bytes = ZVKNED_EGS << s->sew; | ||
423 | + return vaes_check_overlap(s, a->rd, a->rs2) && | ||
424 | + MAXSZ(s) >= egw_bytes && | ||
425 | + s->cfg_ptr->ext_zvkned == true && | ||
426 | + require_rvv(s) && | ||
427 | + vext_check_isa_ill(s) && | ||
428 | + require_align(a->rd, s->lmul) && | ||
429 | + s->sew == MO_32; | ||
430 | +} | ||
431 | + | ||
432 | +GEN_V_UNMASKED_TRANS(vaesef_vv, vaes_check_vv, ZVKNED_EGS) | ||
433 | +GEN_V_UNMASKED_TRANS(vaesef_vs, vaes_check_vs, ZVKNED_EGS) | ||
434 | +GEN_V_UNMASKED_TRANS(vaesdf_vv, vaes_check_vv, ZVKNED_EGS) | ||
435 | +GEN_V_UNMASKED_TRANS(vaesdf_vs, vaes_check_vs, ZVKNED_EGS) | ||
436 | +GEN_V_UNMASKED_TRANS(vaesdm_vv, vaes_check_vv, ZVKNED_EGS) | ||
437 | +GEN_V_UNMASKED_TRANS(vaesdm_vs, vaes_check_vs, ZVKNED_EGS) | ||
438 | +GEN_V_UNMASKED_TRANS(vaesz_vs, vaes_check_vs, ZVKNED_EGS) | ||
439 | +GEN_V_UNMASKED_TRANS(vaesem_vv, vaes_check_vv, ZVKNED_EGS) | ||
440 | +GEN_V_UNMASKED_TRANS(vaesem_vs, vaes_check_vs, ZVKNED_EGS) | ||
441 | + | ||
442 | +#define GEN_VI_UNMASKED_TRANS(NAME, CHECK, EGS) \ | ||
443 | + static bool trans_##NAME(DisasContext *s, arg_##NAME *a) \ | ||
444 | + { \ | ||
445 | + if (CHECK(s, a)) { \ | ||
446 | + TCGv_ptr rd_v, rs2_v; \ | ||
447 | + TCGv_i32 uimm_v, desc, egs; \ | ||
448 | + uint32_t data = 0; \ | ||
449 | + TCGLabel *over = gen_new_label(); \ | ||
450 | + \ | ||
451 | + if (!s->vstart_eq_zero || !s->vl_eq_vlmax) { \ | ||
452 | + /* save opcode for unwinding in case we throw an exception */ \ | ||
453 | + decode_save_opc(s); \ | ||
454 | + egs = tcg_constant_i32(EGS); \ | ||
455 | + gen_helper_egs_check(egs, cpu_env); \ | ||
456 | + tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); \ | ||
457 | + } \ | ||
458 | + \ | ||
459 | + data = FIELD_DP32(data, VDATA, VM, a->vm); \ | ||
460 | + data = FIELD_DP32(data, VDATA, LMUL, s->lmul); \ | ||
461 | + data = FIELD_DP32(data, VDATA, VTA, s->vta); \ | ||
462 | + data = FIELD_DP32(data, VDATA, VTA_ALL_1S, s->cfg_vta_all_1s); \ | ||
463 | + data = FIELD_DP32(data, VDATA, VMA, s->vma); \ | ||
464 | + \ | ||
465 | + rd_v = tcg_temp_new_ptr(); \ | ||
466 | + rs2_v = tcg_temp_new_ptr(); \ | ||
467 | + uimm_v = tcg_constant_i32(a->rs1); \ | ||
468 | + desc = tcg_constant_i32( \ | ||
469 | + simd_desc(s->cfg_ptr->vlen / 8, s->cfg_ptr->vlen / 8, data)); \ | ||
470 | + tcg_gen_addi_ptr(rd_v, cpu_env, vreg_ofs(s, a->rd)); \ | ||
471 | + tcg_gen_addi_ptr(rs2_v, cpu_env, vreg_ofs(s, a->rs2)); \ | ||
472 | + gen_helper_##NAME(rd_v, rs2_v, uimm_v, cpu_env, desc); \ | ||
473 | + mark_vs_dirty(s); \ | ||
474 | + gen_set_label(over); \ | ||
475 | + return true; \ | ||
476 | + } \ | ||
477 | + return false; \ | ||
478 | + } | ||
479 | + | ||
480 | +static bool vaeskf1_check(DisasContext *s, arg_vaeskf1_vi *a) | ||
481 | +{ | ||
482 | + int egw_bytes = ZVKNED_EGS << s->sew; | ||
483 | + return s->cfg_ptr->ext_zvkned == true && | ||
484 | + require_rvv(s) && | ||
485 | + vext_check_isa_ill(s) && | ||
486 | + MAXSZ(s) >= egw_bytes && | ||
487 | + s->sew == MO_32 && | ||
488 | + require_align(a->rd, s->lmul) && | ||
489 | + require_align(a->rs2, s->lmul); | ||
490 | +} | ||
491 | + | ||
492 | +static bool vaeskf2_check(DisasContext *s, arg_vaeskf2_vi *a) | ||
493 | +{ | ||
494 | + int egw_bytes = ZVKNED_EGS << s->sew; | ||
495 | + return s->cfg_ptr->ext_zvkned == true && | ||
496 | + require_rvv(s) && | ||
497 | + vext_check_isa_ill(s) && | ||
498 | + MAXSZ(s) >= egw_bytes && | ||
499 | + s->sew == MO_32 && | ||
500 | + require_align(a->rd, s->lmul) && | ||
501 | + require_align(a->rs2, s->lmul); | ||
502 | +} | ||
503 | + | ||
504 | +GEN_VI_UNMASKED_TRANS(vaeskf1_vi, vaeskf1_check, ZVKNED_EGS) | ||
505 | +GEN_VI_UNMASKED_TRANS(vaeskf2_vi, vaeskf2_check, ZVKNED_EGS) | ||
506 | -- | ||
507 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Kiran Ostrolenk <kiran.ostrolenk@codethink.co.uk> |
---|---|---|---|
2 | 2 | ||
3 | Further discussions after the introduction of rva22 support in QEMU | 3 | This commit adds support for the Zvknh vector-crypto extension, which |
4 | revealed that what we've been calling 'named features' are actually | 4 | consists of the following instructions: |
5 | regular extensions, with their respective riscv,isa DTs. This is | ||
6 | clarified in [1]. [2] is a bug tracker asking for the profile spec to be | ||
7 | less cryptic about it. | ||
8 | 5 | ||
9 | As far as QEMU goes we understand extensions as something that the user | 6 | * vsha2ms.vv |
10 | can enable/disable in the command line. This isn't the case for named | 7 | * vsha2c[hl].vv |
11 | features, so we'll have to reach a middle ground. | ||
12 | 8 | ||
13 | We'll keep our existing nomenclature 'named features' to refer to any | 9 | Translation functions are defined in |
14 | extension that the user can't control in the command line. We'll also do | 10 | `target/riscv/insn_trans/trans_rvvk.c.inc` and helpers are defined in |
15 | the following: | 11 | `target/riscv/vcrypto_helper.c`. |
16 | 12 | ||
17 | - 'svade' and 'zic64b' flags are renamed to 'ext_svade' and | 13 | Co-authored-by: Nazar Kazakov <nazar.kazakov@codethink.co.uk> |
18 | 'ext_zic64b'. 'ext_svade' and 'ext_zic64b' now have riscv,isa strings and | 14 | Co-authored-by: Lawrence Hunter <lawrence.hunter@codethink.co.uk> |
19 | priv_spec versions; | 15 | [max.chou@sifive.com: Replaced vstart checking by TCG op] |
20 | 16 | Signed-off-by: Nazar Kazakov <nazar.kazakov@codethink.co.uk> | |
21 | - skip name feature check in cpu_bump_multi_ext_priv_ver(). Now that | 17 | Signed-off-by: Lawrence Hunter <lawrence.hunter@codethink.co.uk> |
22 | named features have a riscv,isa and an entry in isa_edata_arr[] we | 18 | Signed-off-by: Kiran Ostrolenk <kiran.ostrolenk@codethink.co.uk> |
23 | don't need to gate the call to cpu_cfg_ext_get_min_version() anymore. | 19 | Signed-off-by: Max Chou <max.chou@sifive.com> |
24 | 20 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | |
25 | [1] https://github.com/riscv/riscv-profiles/issues/121 | 21 | [max.chou@sifive.com: Exposed x-zvknha & x-zvknhb properties] |
26 | [2] https://github.com/riscv/riscv-profiles/issues/142 | 22 | [max.chou@sifive.com: Replaced SEW selection to happened during |
27 | 23 | translation] | |
28 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 24 | Message-ID: <20230711165917.2629866-11-max.chou@sifive.com> |
29 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
30 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
31 | Message-ID: <20240215223955.969568-3-dbarboza@ventanamicro.com> | ||
32 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 25 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
33 | --- | 26 | --- |
34 | target/riscv/cpu_cfg.h | 6 ++++-- | 27 | target/riscv/cpu_cfg.h | 2 + |
35 | target/riscv/cpu.c | 17 +++++++++++++---- | 28 | target/riscv/helper.h | 6 + |
36 | target/riscv/tcg/tcg-cpu.c | 16 ++++++---------- | 29 | target/riscv/insn32.decode | 5 + |
37 | 3 files changed, 23 insertions(+), 16 deletions(-) | 30 | target/riscv/cpu.c | 13 +- |
31 | target/riscv/vcrypto_helper.c | 238 +++++++++++++++++++++++ | ||
32 | target/riscv/insn_trans/trans_rvvk.c.inc | 129 ++++++++++++ | ||
33 | 6 files changed, 390 insertions(+), 3 deletions(-) | ||
38 | 34 | ||
39 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h | 35 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h |
40 | index XXXXXXX..XXXXXXX 100644 | 36 | index XXXXXXX..XXXXXXX 100644 |
41 | --- a/target/riscv/cpu_cfg.h | 37 | --- a/target/riscv/cpu_cfg.h |
42 | +++ b/target/riscv/cpu_cfg.h | 38 | +++ b/target/riscv/cpu_cfg.h |
43 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { | 39 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { |
44 | bool ext_smepmp; | 40 | bool ext_zvbb; |
45 | bool rvv_ta_all_1s; | 41 | bool ext_zvbc; |
46 | bool rvv_ma_all_1s; | 42 | bool ext_zvkned; |
47 | - bool svade; | 43 | + bool ext_zvknha; |
48 | - bool zic64b; | 44 | + bool ext_zvknhb; |
49 | 45 | bool ext_zmmul; | |
50 | uint32_t mvendorid; | 46 | bool ext_zvfbfmin; |
51 | uint64_t marchid; | 47 | bool ext_zvfbfwma; |
52 | uint64_t mimpid; | 48 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h |
53 | 49 | index XXXXXXX..XXXXXXX 100644 | |
54 | + /* Named features */ | 50 | --- a/target/riscv/helper.h |
55 | + bool ext_svade; | 51 | +++ b/target/riscv/helper.h |
56 | + bool ext_zic64b; | 52 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_4(vaesdm_vs, void, ptr, ptr, env, i32) |
57 | + | 53 | DEF_HELPER_4(vaesz_vs, void, ptr, ptr, env, i32) |
58 | /* Vendor-specific custom extensions */ | 54 | DEF_HELPER_5(vaeskf1_vi, void, ptr, ptr, i32, env, i32) |
59 | bool ext_xtheadba; | 55 | DEF_HELPER_5(vaeskf2_vi, void, ptr, ptr, i32, env, i32) |
60 | bool ext_xtheadbb; | 56 | + |
57 | +DEF_HELPER_5(vsha2ms_vv, void, ptr, ptr, ptr, env, i32) | ||
58 | +DEF_HELPER_5(vsha2ch32_vv, void, ptr, ptr, ptr, env, i32) | ||
59 | +DEF_HELPER_5(vsha2ch64_vv, void, ptr, ptr, ptr, env, i32) | ||
60 | +DEF_HELPER_5(vsha2cl32_vv, void, ptr, ptr, ptr, env, i32) | ||
61 | +DEF_HELPER_5(vsha2cl64_vv, void, ptr, ptr, ptr, env, i32) | ||
62 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | ||
63 | index XXXXXXX..XXXXXXX 100644 | ||
64 | --- a/target/riscv/insn32.decode | ||
65 | +++ b/target/riscv/insn32.decode | ||
66 | @@ -XXX,XX +XXX,XX @@ vaesdm_vs 101001 1 ..... 00000 010 ..... 1110111 @r2_vm_1 | ||
67 | vaesz_vs 101001 1 ..... 00111 010 ..... 1110111 @r2_vm_1 | ||
68 | vaeskf1_vi 100010 1 ..... ..... 010 ..... 1110111 @r_vm_1 | ||
69 | vaeskf2_vi 101010 1 ..... ..... 010 ..... 1110111 @r_vm_1 | ||
70 | + | ||
71 | +# *** Zvknh vector crypto extension *** | ||
72 | +vsha2ms_vv 101101 1 ..... ..... 010 ..... 1110111 @r_vm_1 | ||
73 | +vsha2ch_vv 101110 1 ..... ..... 010 ..... 1110111 @r_vm_1 | ||
74 | +vsha2cl_vv 101111 1 ..... ..... 010 ..... 1110111 @r_vm_1 | ||
61 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 75 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
62 | index XXXXXXX..XXXXXXX 100644 | 76 | index XXXXXXX..XXXXXXX 100644 |
63 | --- a/target/riscv/cpu.c | 77 | --- a/target/riscv/cpu.c |
64 | +++ b/target/riscv/cpu.c | 78 | +++ b/target/riscv/cpu.c |
65 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_option_set(const char *optname) | 79 | @@ -XXX,XX +XXX,XX @@ static const struct isa_ext_data isa_edata_arr[] = { |
66 | * instead. | 80 | ISA_EXT_DATA_ENTRY(zvfh, PRIV_VERSION_1_12_0, ext_zvfh), |
67 | */ | 81 | ISA_EXT_DATA_ENTRY(zvfhmin, PRIV_VERSION_1_12_0, ext_zvfhmin), |
68 | const RISCVIsaExtData isa_edata_arr[] = { | 82 | ISA_EXT_DATA_ENTRY(zvkned, PRIV_VERSION_1_12_0, ext_zvkned), |
69 | + ISA_EXT_DATA_ENTRY(zic64b, PRIV_VERSION_1_12_0, ext_zic64b), | 83 | + ISA_EXT_DATA_ENTRY(zvknha, PRIV_VERSION_1_12_0, ext_zvknha), |
70 | ISA_EXT_DATA_ENTRY(zicbom, PRIV_VERSION_1_12_0, ext_zicbom), | 84 | + ISA_EXT_DATA_ENTRY(zvknhb, PRIV_VERSION_1_12_0, ext_zvknhb), |
71 | ISA_EXT_DATA_ENTRY(zicbop, PRIV_VERSION_1_12_0, ext_zicbop), | 85 | ISA_EXT_DATA_ENTRY(zhinx, PRIV_VERSION_1_12_0, ext_zhinx), |
72 | ISA_EXT_DATA_ENTRY(zicboz, PRIV_VERSION_1_12_0, ext_zicboz), | 86 | ISA_EXT_DATA_ENTRY(zhinxmin, PRIV_VERSION_1_12_0, ext_zhinxmin), |
73 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { | 87 | ISA_EXT_DATA_ENTRY(smaia, PRIV_VERSION_1_12_0, ext_smaia), |
74 | ISA_EXT_DATA_ENTRY(ssaia, PRIV_VERSION_1_12_0, ext_ssaia), | 88 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) |
75 | ISA_EXT_DATA_ENTRY(sscofpmf, PRIV_VERSION_1_12_0, ext_sscofpmf), | 89 | * In principle Zve*x would also suffice here, were they supported |
76 | ISA_EXT_DATA_ENTRY(sstc, PRIV_VERSION_1_12_0, ext_sstc), | 90 | * in qemu |
77 | + ISA_EXT_DATA_ENTRY(svade, PRIV_VERSION_1_11_0, ext_svade), | 91 | */ |
78 | ISA_EXT_DATA_ENTRY(svadu, PRIV_VERSION_1_12_0, ext_svadu), | 92 | - if ((cpu->cfg.ext_zvbb || cpu->cfg.ext_zvkned) && !cpu->cfg.ext_zve32f) { |
79 | ISA_EXT_DATA_ENTRY(svinval, PRIV_VERSION_1_12_0, ext_svinval), | 93 | + if ((cpu->cfg.ext_zvbb || cpu->cfg.ext_zvkned || cpu->cfg.ext_zvknha) && |
80 | ISA_EXT_DATA_ENTRY(svnapot, PRIV_VERSION_1_12_0, ext_svnapot), | 94 | + !cpu->cfg.ext_zve32f) { |
81 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = { | 95 | error_setg(errp, |
96 | "Vector crypto extensions require V or Zve* extensions"); | ||
97 | return; | ||
98 | } | ||
99 | |||
100 | - if (cpu->cfg.ext_zvbc && !cpu->cfg.ext_zve64f) { | ||
101 | - error_setg(errp, "Zvbc extension requires V or Zve64{f,d} extensions"); | ||
102 | + if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64f) { | ||
103 | + error_setg( | ||
104 | + errp, | ||
105 | + "Zvbc and Zvknhb extensions require V or Zve64{f,d} extensions"); | ||
106 | return; | ||
107 | } | ||
108 | |||
109 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = { | ||
110 | DEFINE_PROP_BOOL("x-zvbb", RISCVCPU, cfg.ext_zvbb, false), | ||
111 | DEFINE_PROP_BOOL("x-zvbc", RISCVCPU, cfg.ext_zvbc, false), | ||
112 | DEFINE_PROP_BOOL("x-zvkned", RISCVCPU, cfg.ext_zvkned, false), | ||
113 | + DEFINE_PROP_BOOL("x-zvknha", RISCVCPU, cfg.ext_zvknha, false), | ||
114 | + DEFINE_PROP_BOOL("x-zvknhb", RISCVCPU, cfg.ext_zvknhb, false), | ||
115 | |||
82 | DEFINE_PROP_END_OF_LIST(), | 116 | DEFINE_PROP_END_OF_LIST(), |
83 | }; | 117 | }; |
84 | 118 | diff --git a/target/riscv/vcrypto_helper.c b/target/riscv/vcrypto_helper.c | |
119 | index XXXXXXX..XXXXXXX 100644 | ||
120 | --- a/target/riscv/vcrypto_helper.c | ||
121 | +++ b/target/riscv/vcrypto_helper.c | ||
122 | @@ -XXX,XX +XXX,XX @@ void HELPER(vaeskf2_vi)(void *vd_vptr, void *vs2_vptr, uint32_t uimm, | ||
123 | /* set tail elements to 1s */ | ||
124 | vext_set_elems_1s(vd, vta, vl * 4, total_elems * 4); | ||
125 | } | ||
126 | + | ||
127 | +static inline uint32_t sig0_sha256(uint32_t x) | ||
128 | +{ | ||
129 | + return ror32(x, 7) ^ ror32(x, 18) ^ (x >> 3); | ||
130 | +} | ||
131 | + | ||
132 | +static inline uint32_t sig1_sha256(uint32_t x) | ||
133 | +{ | ||
134 | + return ror32(x, 17) ^ ror32(x, 19) ^ (x >> 10); | ||
135 | +} | ||
136 | + | ||
137 | +static inline uint64_t sig0_sha512(uint64_t x) | ||
138 | +{ | ||
139 | + return ror64(x, 1) ^ ror64(x, 8) ^ (x >> 7); | ||
140 | +} | ||
141 | + | ||
142 | +static inline uint64_t sig1_sha512(uint64_t x) | ||
143 | +{ | ||
144 | + return ror64(x, 19) ^ ror64(x, 61) ^ (x >> 6); | ||
145 | +} | ||
146 | + | ||
147 | +static inline void vsha2ms_e32(uint32_t *vd, uint32_t *vs1, uint32_t *vs2) | ||
148 | +{ | ||
149 | + uint32_t res[4]; | ||
150 | + res[0] = sig1_sha256(vs1[H4(2)]) + vs2[H4(1)] + sig0_sha256(vd[H4(1)]) + | ||
151 | + vd[H4(0)]; | ||
152 | + res[1] = sig1_sha256(vs1[H4(3)]) + vs2[H4(2)] + sig0_sha256(vd[H4(2)]) + | ||
153 | + vd[H4(1)]; | ||
154 | + res[2] = | ||
155 | + sig1_sha256(res[0]) + vs2[H4(3)] + sig0_sha256(vd[H4(3)]) + vd[H4(2)]; | ||
156 | + res[3] = | ||
157 | + sig1_sha256(res[1]) + vs1[H4(0)] + sig0_sha256(vs2[H4(0)]) + vd[H4(3)]; | ||
158 | + vd[H4(3)] = res[3]; | ||
159 | + vd[H4(2)] = res[2]; | ||
160 | + vd[H4(1)] = res[1]; | ||
161 | + vd[H4(0)] = res[0]; | ||
162 | +} | ||
163 | + | ||
164 | +static inline void vsha2ms_e64(uint64_t *vd, uint64_t *vs1, uint64_t *vs2) | ||
165 | +{ | ||
166 | + uint64_t res[4]; | ||
167 | + res[0] = sig1_sha512(vs1[2]) + vs2[1] + sig0_sha512(vd[1]) + vd[0]; | ||
168 | + res[1] = sig1_sha512(vs1[3]) + vs2[2] + sig0_sha512(vd[2]) + vd[1]; | ||
169 | + res[2] = sig1_sha512(res[0]) + vs2[3] + sig0_sha512(vd[3]) + vd[2]; | ||
170 | + res[3] = sig1_sha512(res[1]) + vs1[0] + sig0_sha512(vs2[0]) + vd[3]; | ||
171 | + vd[3] = res[3]; | ||
172 | + vd[2] = res[2]; | ||
173 | + vd[1] = res[1]; | ||
174 | + vd[0] = res[0]; | ||
175 | +} | ||
176 | + | ||
177 | +void HELPER(vsha2ms_vv)(void *vd, void *vs1, void *vs2, CPURISCVState *env, | ||
178 | + uint32_t desc) | ||
179 | +{ | ||
180 | + uint32_t sew = FIELD_EX64(env->vtype, VTYPE, VSEW); | ||
181 | + uint32_t esz = sew == MO_32 ? 4 : 8; | ||
182 | + uint32_t total_elems; | ||
183 | + uint32_t vta = vext_vta(desc); | ||
184 | + | ||
185 | + for (uint32_t i = env->vstart / 4; i < env->vl / 4; i++) { | ||
186 | + if (sew == MO_32) { | ||
187 | + vsha2ms_e32(((uint32_t *)vd) + i * 4, ((uint32_t *)vs1) + i * 4, | ||
188 | + ((uint32_t *)vs2) + i * 4); | ||
189 | + } else { | ||
190 | + /* If not 32 then SEW should be 64 */ | ||
191 | + vsha2ms_e64(((uint64_t *)vd) + i * 4, ((uint64_t *)vs1) + i * 4, | ||
192 | + ((uint64_t *)vs2) + i * 4); | ||
193 | + } | ||
194 | + } | ||
195 | + /* set tail elements to 1s */ | ||
196 | + total_elems = vext_get_total_elems(env, desc, esz); | ||
197 | + vext_set_elems_1s(vd, vta, env->vl * esz, total_elems * esz); | ||
198 | + env->vstart = 0; | ||
199 | +} | ||
200 | + | ||
201 | +static inline uint64_t sum0_64(uint64_t x) | ||
202 | +{ | ||
203 | + return ror64(x, 28) ^ ror64(x, 34) ^ ror64(x, 39); | ||
204 | +} | ||
205 | + | ||
206 | +static inline uint32_t sum0_32(uint32_t x) | ||
207 | +{ | ||
208 | + return ror32(x, 2) ^ ror32(x, 13) ^ ror32(x, 22); | ||
209 | +} | ||
210 | + | ||
211 | +static inline uint64_t sum1_64(uint64_t x) | ||
212 | +{ | ||
213 | + return ror64(x, 14) ^ ror64(x, 18) ^ ror64(x, 41); | ||
214 | +} | ||
215 | + | ||
216 | +static inline uint32_t sum1_32(uint32_t x) | ||
217 | +{ | ||
218 | + return ror32(x, 6) ^ ror32(x, 11) ^ ror32(x, 25); | ||
219 | +} | ||
220 | + | ||
221 | +#define ch(x, y, z) ((x & y) ^ ((~x) & z)) | ||
222 | + | ||
223 | +#define maj(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) | ||
224 | + | ||
225 | +static void vsha2c_64(uint64_t *vs2, uint64_t *vd, uint64_t *vs1) | ||
226 | +{ | ||
227 | + uint64_t a = vs2[3], b = vs2[2], e = vs2[1], f = vs2[0]; | ||
228 | + uint64_t c = vd[3], d = vd[2], g = vd[1], h = vd[0]; | ||
229 | + uint64_t W0 = vs1[0], W1 = vs1[1]; | ||
230 | + uint64_t T1 = h + sum1_64(e) + ch(e, f, g) + W0; | ||
231 | + uint64_t T2 = sum0_64(a) + maj(a, b, c); | ||
232 | + | ||
233 | + h = g; | ||
234 | + g = f; | ||
235 | + f = e; | ||
236 | + e = d + T1; | ||
237 | + d = c; | ||
238 | + c = b; | ||
239 | + b = a; | ||
240 | + a = T1 + T2; | ||
241 | + | ||
242 | + T1 = h + sum1_64(e) + ch(e, f, g) + W1; | ||
243 | + T2 = sum0_64(a) + maj(a, b, c); | ||
244 | + h = g; | ||
245 | + g = f; | ||
246 | + f = e; | ||
247 | + e = d + T1; | ||
248 | + d = c; | ||
249 | + c = b; | ||
250 | + b = a; | ||
251 | + a = T1 + T2; | ||
252 | + | ||
253 | + vd[0] = f; | ||
254 | + vd[1] = e; | ||
255 | + vd[2] = b; | ||
256 | + vd[3] = a; | ||
257 | +} | ||
258 | + | ||
259 | +static void vsha2c_32(uint32_t *vs2, uint32_t *vd, uint32_t *vs1) | ||
260 | +{ | ||
261 | + uint32_t a = vs2[H4(3)], b = vs2[H4(2)], e = vs2[H4(1)], f = vs2[H4(0)]; | ||
262 | + uint32_t c = vd[H4(3)], d = vd[H4(2)], g = vd[H4(1)], h = vd[H4(0)]; | ||
263 | + uint32_t W0 = vs1[H4(0)], W1 = vs1[H4(1)]; | ||
264 | + uint32_t T1 = h + sum1_32(e) + ch(e, f, g) + W0; | ||
265 | + uint32_t T2 = sum0_32(a) + maj(a, b, c); | ||
266 | + | ||
267 | + h = g; | ||
268 | + g = f; | ||
269 | + f = e; | ||
270 | + e = d + T1; | ||
271 | + d = c; | ||
272 | + c = b; | ||
273 | + b = a; | ||
274 | + a = T1 + T2; | ||
275 | + | ||
276 | + T1 = h + sum1_32(e) + ch(e, f, g) + W1; | ||
277 | + T2 = sum0_32(a) + maj(a, b, c); | ||
278 | + h = g; | ||
279 | + g = f; | ||
280 | + f = e; | ||
281 | + e = d + T1; | ||
282 | + d = c; | ||
283 | + c = b; | ||
284 | + b = a; | ||
285 | + a = T1 + T2; | ||
286 | + | ||
287 | + vd[H4(0)] = f; | ||
288 | + vd[H4(1)] = e; | ||
289 | + vd[H4(2)] = b; | ||
290 | + vd[H4(3)] = a; | ||
291 | +} | ||
292 | + | ||
293 | +void HELPER(vsha2ch32_vv)(void *vd, void *vs1, void *vs2, CPURISCVState *env, | ||
294 | + uint32_t desc) | ||
295 | +{ | ||
296 | + const uint32_t esz = 4; | ||
297 | + uint32_t total_elems; | ||
298 | + uint32_t vta = vext_vta(desc); | ||
299 | + | ||
300 | + for (uint32_t i = env->vstart / 4; i < env->vl / 4; i++) { | ||
301 | + vsha2c_32(((uint32_t *)vs2) + 4 * i, ((uint32_t *)vd) + 4 * i, | ||
302 | + ((uint32_t *)vs1) + 4 * i + 2); | ||
303 | + } | ||
304 | + | ||
305 | + /* set tail elements to 1s */ | ||
306 | + total_elems = vext_get_total_elems(env, desc, esz); | ||
307 | + vext_set_elems_1s(vd, vta, env->vl * esz, total_elems * esz); | ||
308 | + env->vstart = 0; | ||
309 | +} | ||
310 | + | ||
311 | +void HELPER(vsha2ch64_vv)(void *vd, void *vs1, void *vs2, CPURISCVState *env, | ||
312 | + uint32_t desc) | ||
313 | +{ | ||
314 | + const uint32_t esz = 8; | ||
315 | + uint32_t total_elems; | ||
316 | + uint32_t vta = vext_vta(desc); | ||
317 | + | ||
318 | + for (uint32_t i = env->vstart / 4; i < env->vl / 4; i++) { | ||
319 | + vsha2c_64(((uint64_t *)vs2) + 4 * i, ((uint64_t *)vd) + 4 * i, | ||
320 | + ((uint64_t *)vs1) + 4 * i + 2); | ||
321 | + } | ||
322 | + | ||
323 | + /* set tail elements to 1s */ | ||
324 | + total_elems = vext_get_total_elems(env, desc, esz); | ||
325 | + vext_set_elems_1s(vd, vta, env->vl * esz, total_elems * esz); | ||
326 | + env->vstart = 0; | ||
327 | +} | ||
328 | + | ||
329 | +void HELPER(vsha2cl32_vv)(void *vd, void *vs1, void *vs2, CPURISCVState *env, | ||
330 | + uint32_t desc) | ||
331 | +{ | ||
332 | + const uint32_t esz = 4; | ||
333 | + uint32_t total_elems; | ||
334 | + uint32_t vta = vext_vta(desc); | ||
335 | + | ||
336 | + for (uint32_t i = env->vstart / 4; i < env->vl / 4; i++) { | ||
337 | + vsha2c_32(((uint32_t *)vs2) + 4 * i, ((uint32_t *)vd) + 4 * i, | ||
338 | + (((uint32_t *)vs1) + 4 * i)); | ||
339 | + } | ||
340 | + | ||
341 | + /* set tail elements to 1s */ | ||
342 | + total_elems = vext_get_total_elems(env, desc, esz); | ||
343 | + vext_set_elems_1s(vd, vta, env->vl * esz, total_elems * esz); | ||
344 | + env->vstart = 0; | ||
345 | +} | ||
346 | + | ||
347 | +void HELPER(vsha2cl64_vv)(void *vd, void *vs1, void *vs2, CPURISCVState *env, | ||
348 | + uint32_t desc) | ||
349 | +{ | ||
350 | + uint32_t esz = 8; | ||
351 | + uint32_t total_elems; | ||
352 | + uint32_t vta = vext_vta(desc); | ||
353 | + | ||
354 | + for (uint32_t i = env->vstart / 4; i < env->vl / 4; i++) { | ||
355 | + vsha2c_64(((uint64_t *)vs2) + 4 * i, ((uint64_t *)vd) + 4 * i, | ||
356 | + (((uint64_t *)vs1) + 4 * i)); | ||
357 | + } | ||
358 | + | ||
359 | + /* set tail elements to 1s */ | ||
360 | + total_elems = vext_get_total_elems(env, desc, esz); | ||
361 | + vext_set_elems_1s(vd, vta, env->vl * esz, total_elems * esz); | ||
362 | + env->vstart = 0; | ||
363 | +} | ||
364 | diff --git a/target/riscv/insn_trans/trans_rvvk.c.inc b/target/riscv/insn_trans/trans_rvvk.c.inc | ||
365 | index XXXXXXX..XXXXXXX 100644 | ||
366 | --- a/target/riscv/insn_trans/trans_rvvk.c.inc | ||
367 | +++ b/target/riscv/insn_trans/trans_rvvk.c.inc | ||
368 | @@ -XXX,XX +XXX,XX @@ static bool vaeskf2_check(DisasContext *s, arg_vaeskf2_vi *a) | ||
369 | |||
370 | GEN_VI_UNMASKED_TRANS(vaeskf1_vi, vaeskf1_check, ZVKNED_EGS) | ||
371 | GEN_VI_UNMASKED_TRANS(vaeskf2_vi, vaeskf2_check, ZVKNED_EGS) | ||
372 | + | ||
85 | +/* | 373 | +/* |
86 | + * 'Named features' is the name we give to extensions that we | 374 | + * Zvknh |
87 | + * don't want to expose to users. They are either immutable | ||
88 | + * (always enabled/disable) or they'll vary depending on | ||
89 | + * the resulting CPU state. They have riscv,isa strings | ||
90 | + * and priv_ver like regular extensions. | ||
91 | + */ | 375 | + */ |
92 | const RISCVCPUMultiExtConfig riscv_cpu_named_features[] = { | 376 | + |
93 | - MULTI_EXT_CFG_BOOL("svade", svade, true), | 377 | +#define ZVKNH_EGS 4 |
94 | - MULTI_EXT_CFG_BOOL("zic64b", zic64b, true), | 378 | + |
95 | + MULTI_EXT_CFG_BOOL("svade", ext_svade, true), | 379 | +#define GEN_VV_UNMASKED_TRANS(NAME, CHECK, EGS) \ |
96 | + MULTI_EXT_CFG_BOOL("zic64b", ext_zic64b, true), | 380 | + static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ |
97 | 381 | + { \ | |
98 | DEFINE_PROP_END_OF_LIST(), | 382 | + if (CHECK(s, a)) { \ |
99 | }; | 383 | + uint32_t data = 0; \ |
100 | @@ -XXX,XX +XXX,XX @@ static RISCVCPUProfile RVA22U64 = { | 384 | + TCGLabel *over = gen_new_label(); \ |
101 | CPU_CFG_OFFSET(ext_zicbop), CPU_CFG_OFFSET(ext_zicboz), | 385 | + TCGv_i32 egs; \ |
102 | 386 | + \ | |
103 | /* mandatory named features for this profile */ | 387 | + if (!s->vstart_eq_zero || !s->vl_eq_vlmax) { \ |
104 | - CPU_CFG_OFFSET(zic64b), | 388 | + /* save opcode for unwinding in case we throw an exception */ \ |
105 | + CPU_CFG_OFFSET(ext_zic64b), | 389 | + decode_save_opc(s); \ |
106 | 390 | + egs = tcg_constant_i32(EGS); \ | |
107 | RISCV_PROFILE_EXT_LIST_END | 391 | + gen_helper_egs_check(egs, cpu_env); \ |
108 | } | 392 | + tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); \ |
109 | @@ -XXX,XX +XXX,XX @@ static RISCVCPUProfile RVA22S64 = { | 393 | + } \ |
110 | CPU_CFG_OFFSET(ext_svinval), | 394 | + \ |
111 | 395 | + data = FIELD_DP32(data, VDATA, VM, a->vm); \ | |
112 | /* rva22s64 named features */ | 396 | + data = FIELD_DP32(data, VDATA, LMUL, s->lmul); \ |
113 | - CPU_CFG_OFFSET(svade), | 397 | + data = FIELD_DP32(data, VDATA, VTA, s->vta); \ |
114 | + CPU_CFG_OFFSET(ext_svade), | 398 | + data = FIELD_DP32(data, VDATA, VTA_ALL_1S, s->cfg_vta_all_1s); \ |
115 | 399 | + data = FIELD_DP32(data, VDATA, VMA, s->vma); \ | |
116 | RISCV_PROFILE_EXT_LIST_END | 400 | + \ |
117 | } | 401 | + tcg_gen_gvec_3_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, a->rs1), \ |
118 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | 402 | + vreg_ofs(s, a->rs2), cpu_env, \ |
119 | index XXXXXXX..XXXXXXX 100644 | 403 | + s->cfg_ptr->vlen / 8, s->cfg_ptr->vlen / 8, \ |
120 | --- a/target/riscv/tcg/tcg-cpu.c | 404 | + data, gen_helper_##NAME); \ |
121 | +++ b/target/riscv/tcg/tcg-cpu.c | 405 | + \ |
122 | @@ -XXX,XX +XXX,XX @@ static bool cpu_cfg_offset_is_named_feat(uint32_t ext_offset) | 406 | + mark_vs_dirty(s); \ |
123 | static void riscv_cpu_enable_named_feat(RISCVCPU *cpu, uint32_t feat_offset) | 407 | + gen_set_label(over); \ |
124 | { | 408 | + return true; \ |
125 | switch (feat_offset) { | 409 | + } \ |
126 | - case CPU_CFG_OFFSET(zic64b): | 410 | + return false; \ |
127 | + case CPU_CFG_OFFSET(ext_zic64b): | 411 | + } |
128 | cpu->cfg.cbom_blocksize = 64; | 412 | + |
129 | cpu->cfg.cbop_blocksize = 64; | 413 | +static bool vsha_check_sew(DisasContext *s) |
130 | cpu->cfg.cboz_blocksize = 64; | 414 | +{ |
131 | break; | 415 | + return (s->cfg_ptr->ext_zvknha == true && s->sew == MO_32) || |
132 | - case CPU_CFG_OFFSET(svade): | 416 | + (s->cfg_ptr->ext_zvknhb == true && |
133 | + case CPU_CFG_OFFSET(ext_svade): | 417 | + (s->sew == MO_32 || s->sew == MO_64)); |
134 | cpu->cfg.ext_svadu = false; | 418 | +} |
135 | break; | 419 | + |
136 | default: | 420 | +static bool vsha_check(DisasContext *s, arg_rmrr *a) |
137 | @@ -XXX,XX +XXX,XX @@ static void cpu_bump_multi_ext_priv_ver(CPURISCVState *env, | 421 | +{ |
138 | return; | 422 | + int egw_bytes = ZVKNH_EGS << s->sew; |
139 | } | 423 | + int mult = 1 << MAX(s->lmul, 0); |
140 | 424 | + return opivv_check(s, a) && | |
141 | - if (cpu_cfg_offset_is_named_feat(ext_offset)) { | 425 | + vsha_check_sew(s) && |
142 | - return; | 426 | + MAXSZ(s) >= egw_bytes && |
143 | - } | 427 | + !is_overlapped(a->rd, mult, a->rs1, mult) && |
144 | - | 428 | + !is_overlapped(a->rd, mult, a->rs2, mult) && |
145 | ext_priv_ver = cpu_cfg_ext_get_min_version(ext_offset); | 429 | + s->lmul >= 0; |
146 | 430 | +} | |
147 | if (env->priv_ver < ext_priv_ver) { | 431 | + |
148 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) | 432 | +GEN_VV_UNMASKED_TRANS(vsha2ms_vv, vsha_check, ZVKNH_EGS) |
149 | 433 | + | |
150 | static void riscv_cpu_update_named_features(RISCVCPU *cpu) | 434 | +static bool trans_vsha2cl_vv(DisasContext *s, arg_rmrr *a) |
151 | { | 435 | +{ |
152 | - cpu->cfg.zic64b = cpu->cfg.cbom_blocksize == 64 && | 436 | + if (vsha_check(s, a)) { |
153 | - cpu->cfg.cbop_blocksize == 64 && | 437 | + uint32_t data = 0; |
154 | - cpu->cfg.cboz_blocksize == 64; | 438 | + TCGLabel *over = gen_new_label(); |
155 | + cpu->cfg.ext_zic64b = cpu->cfg.cbom_blocksize == 64 && | 439 | + TCGv_i32 egs; |
156 | + cpu->cfg.cbop_blocksize == 64 && | 440 | + |
157 | + cpu->cfg.cboz_blocksize == 64; | 441 | + if (!s->vstart_eq_zero || !s->vl_eq_vlmax) { |
158 | 442 | + /* save opcode for unwinding in case we throw an exception */ | |
159 | - cpu->cfg.svade = !cpu->cfg.ext_svadu; | 443 | + decode_save_opc(s); |
160 | + cpu->cfg.ext_svade = !cpu->cfg.ext_svadu; | 444 | + egs = tcg_constant_i32(ZVKNH_EGS); |
161 | } | 445 | + gen_helper_egs_check(egs, cpu_env); |
162 | 446 | + tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); | |
163 | static void riscv_cpu_validate_g(RISCVCPU *cpu) | 447 | + } |
448 | + | ||
449 | + data = FIELD_DP32(data, VDATA, VM, a->vm); | ||
450 | + data = FIELD_DP32(data, VDATA, LMUL, s->lmul); | ||
451 | + data = FIELD_DP32(data, VDATA, VTA, s->vta); | ||
452 | + data = FIELD_DP32(data, VDATA, VTA_ALL_1S, s->cfg_vta_all_1s); | ||
453 | + data = FIELD_DP32(data, VDATA, VMA, s->vma); | ||
454 | + | ||
455 | + tcg_gen_gvec_3_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, a->rs1), | ||
456 | + vreg_ofs(s, a->rs2), cpu_env, s->cfg_ptr->vlen / 8, | ||
457 | + s->cfg_ptr->vlen / 8, data, | ||
458 | + s->sew == MO_32 ? | ||
459 | + gen_helper_vsha2cl32_vv : gen_helper_vsha2cl64_vv); | ||
460 | + | ||
461 | + mark_vs_dirty(s); | ||
462 | + gen_set_label(over); | ||
463 | + return true; | ||
464 | + } | ||
465 | + return false; | ||
466 | +} | ||
467 | + | ||
468 | +static bool trans_vsha2ch_vv(DisasContext *s, arg_rmrr *a) | ||
469 | +{ | ||
470 | + if (vsha_check(s, a)) { | ||
471 | + uint32_t data = 0; | ||
472 | + TCGLabel *over = gen_new_label(); | ||
473 | + TCGv_i32 egs; | ||
474 | + | ||
475 | + if (!s->vstart_eq_zero || !s->vl_eq_vlmax) { | ||
476 | + /* save opcode for unwinding in case we throw an exception */ | ||
477 | + decode_save_opc(s); | ||
478 | + egs = tcg_constant_i32(ZVKNH_EGS); | ||
479 | + gen_helper_egs_check(egs, cpu_env); | ||
480 | + tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); | ||
481 | + } | ||
482 | + | ||
483 | + data = FIELD_DP32(data, VDATA, VM, a->vm); | ||
484 | + data = FIELD_DP32(data, VDATA, LMUL, s->lmul); | ||
485 | + data = FIELD_DP32(data, VDATA, VTA, s->vta); | ||
486 | + data = FIELD_DP32(data, VDATA, VTA_ALL_1S, s->cfg_vta_all_1s); | ||
487 | + data = FIELD_DP32(data, VDATA, VMA, s->vma); | ||
488 | + | ||
489 | + tcg_gen_gvec_3_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, a->rs1), | ||
490 | + vreg_ofs(s, a->rs2), cpu_env, s->cfg_ptr->vlen / 8, | ||
491 | + s->cfg_ptr->vlen / 8, data, | ||
492 | + s->sew == MO_32 ? | ||
493 | + gen_helper_vsha2ch32_vv : gen_helper_vsha2ch64_vv); | ||
494 | + | ||
495 | + mark_vs_dirty(s); | ||
496 | + gen_set_label(over); | ||
497 | + return true; | ||
498 | + } | ||
499 | + return false; | ||
500 | +} | ||
164 | -- | 501 | -- |
165 | 2.44.0 | 502 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Lawrence Hunter <lawrence.hunter@codethink.co.uk> |
---|---|---|---|
2 | 2 | ||
3 | The RVA22U64 and RVA22S64 profiles mandates certain extensions that, | 3 | This commit adds support for the Zvksh vector-crypto extension, which |
4 | until now, we were implying that they were available. | 4 | consists of the following instructions: |
5 | 5 | ||
6 | We can't do this anymore since named features also has a riscv,isa | 6 | * vsm3me.vv |
7 | entry. Let's add them to riscv_cpu_named_features[]. | 7 | * vsm3c.vi |
8 | 8 | ||
9 | Instead of adding one bool for each named feature that we'll always | 9 | Translation functions are defined in |
10 | implement, i.e. can't be turned off, add a 'ext_always_enabled' bool in | 10 | `target/riscv/insn_trans/trans_rvvk.c.inc` and helpers are defined in |
11 | cpu->cfg. This bool will be set to 'true' in TCG accel init, and all | 11 | `target/riscv/vcrypto_helper.c`. |
12 | named features will point to it. This also means that KVM won't see | 12 | |
13 | these features as always enable, which is our intention. | 13 | Co-authored-by: Kiran Ostrolenk <kiran.ostrolenk@codethink.co.uk> |
14 | 14 | [max.chou@sifive.com: Replaced vstart checking by TCG op] | |
15 | If any accelerator adds support to disable one of these features, we'll | 15 | Signed-off-by: Kiran Ostrolenk <kiran.ostrolenk@codethink.co.uk> |
16 | have to promote them to regular extensions and allow users to disable it | 16 | Signed-off-by: Lawrence Hunter <lawrence.hunter@codethink.co.uk> |
17 | via command line. | 17 | Signed-off-by: Max Chou <max.chou@sifive.com> |
18 | 18 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | |
19 | After this patch, here's the riscv,isa from a buildroot using the | 19 | [max.chou@sifive.com: Exposed x-zvksh property] |
20 | 'rva22s64' CPU: | 20 | Message-ID: <20230711165917.2629866-12-max.chou@sifive.com> |
21 | |||
22 | # cat /proc/device-tree/cpus/cpu@0/riscv,isa | ||
23 | rv64imafdc_zic64b_zicbom_zicbop_zicboz_ziccamoa_ziccif_zicclsm_ziccrse_ | ||
24 | zicntr_zicsr_zifencei_zihintpause_zihpm_za64rs_zfhmin_zca_zcd_zba_zbb_ | ||
25 | zbs_zkt_ssccptr_sscounterenw_sstvala_sstvecd_svade_svinval_svpbmt# | ||
26 | |||
27 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
28 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
29 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
30 | Message-ID: <20240215223955.969568-4-dbarboza@ventanamicro.com> | ||
31 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 21 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
32 | --- | 22 | --- |
33 | target/riscv/cpu_cfg.h | 6 ++++++ | 23 | target/riscv/cpu_cfg.h | 1 + |
34 | target/riscv/cpu.c | 42 +++++++++++++++++++++++++++++++------- | 24 | target/riscv/helper.h | 3 + |
35 | target/riscv/tcg/tcg-cpu.c | 2 ++ | 25 | target/riscv/insn32.decode | 4 + |
36 | 3 files changed, 43 insertions(+), 7 deletions(-) | 26 | target/riscv/cpu.c | 6 +- |
27 | target/riscv/vcrypto_helper.c | 134 +++++++++++++++++++++++ | ||
28 | target/riscv/insn_trans/trans_rvvk.c.inc | 31 ++++++ | ||
29 | 6 files changed, 177 insertions(+), 2 deletions(-) | ||
37 | 30 | ||
38 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h | 31 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h |
39 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
40 | --- a/target/riscv/cpu_cfg.h | 33 | --- a/target/riscv/cpu_cfg.h |
41 | +++ b/target/riscv/cpu_cfg.h | 34 | +++ b/target/riscv/cpu_cfg.h |
42 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { | 35 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { |
43 | bool ext_svade; | 36 | bool ext_zvkned; |
44 | bool ext_zic64b; | 37 | bool ext_zvknha; |
45 | 38 | bool ext_zvknhb; | |
46 | + /* | 39 | + bool ext_zvksh; |
47 | + * Always 'true' boolean for named features | 40 | bool ext_zmmul; |
48 | + * TCG always implement/can't be disabled. | 41 | bool ext_zvfbfmin; |
49 | + */ | 42 | bool ext_zvfbfwma; |
50 | + bool ext_always_enabled; | 43 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h |
51 | + | 44 | index XXXXXXX..XXXXXXX 100644 |
52 | /* Vendor-specific custom extensions */ | 45 | --- a/target/riscv/helper.h |
53 | bool ext_xtheadba; | 46 | +++ b/target/riscv/helper.h |
54 | bool ext_xtheadbb; | 47 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_5(vsha2ch32_vv, void, ptr, ptr, ptr, env, i32) |
48 | DEF_HELPER_5(vsha2ch64_vv, void, ptr, ptr, ptr, env, i32) | ||
49 | DEF_HELPER_5(vsha2cl32_vv, void, ptr, ptr, ptr, env, i32) | ||
50 | DEF_HELPER_5(vsha2cl64_vv, void, ptr, ptr, ptr, env, i32) | ||
51 | + | ||
52 | +DEF_HELPER_5(vsm3me_vv, void, ptr, ptr, ptr, env, i32) | ||
53 | +DEF_HELPER_5(vsm3c_vi, void, ptr, ptr, i32, env, i32) | ||
54 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | ||
55 | index XXXXXXX..XXXXXXX 100644 | ||
56 | --- a/target/riscv/insn32.decode | ||
57 | +++ b/target/riscv/insn32.decode | ||
58 | @@ -XXX,XX +XXX,XX @@ vaeskf2_vi 101010 1 ..... ..... 010 ..... 1110111 @r_vm_1 | ||
59 | vsha2ms_vv 101101 1 ..... ..... 010 ..... 1110111 @r_vm_1 | ||
60 | vsha2ch_vv 101110 1 ..... ..... 010 ..... 1110111 @r_vm_1 | ||
61 | vsha2cl_vv 101111 1 ..... ..... 010 ..... 1110111 @r_vm_1 | ||
62 | + | ||
63 | +# *** Zvksh vector crypto extension *** | ||
64 | +vsm3me_vv 100000 1 ..... ..... 010 ..... 1110111 @r_vm_1 | ||
65 | +vsm3c_vi 101011 1 ..... ..... 010 ..... 1110111 @r_vm_1 | ||
55 | 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 |
56 | index XXXXXXX..XXXXXXX 100644 | 67 | index XXXXXXX..XXXXXXX 100644 |
57 | --- a/target/riscv/cpu.c | 68 | --- a/target/riscv/cpu.c |
58 | +++ b/target/riscv/cpu.c | 69 | +++ b/target/riscv/cpu.c |
59 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { | 70 | @@ -XXX,XX +XXX,XX @@ static const struct isa_ext_data isa_edata_arr[] = { |
60 | ISA_EXT_DATA_ENTRY(zicbom, PRIV_VERSION_1_12_0, ext_zicbom), | 71 | ISA_EXT_DATA_ENTRY(zvkned, PRIV_VERSION_1_12_0, ext_zvkned), |
61 | ISA_EXT_DATA_ENTRY(zicbop, PRIV_VERSION_1_12_0, ext_zicbop), | 72 | ISA_EXT_DATA_ENTRY(zvknha, PRIV_VERSION_1_12_0, ext_zvknha), |
62 | ISA_EXT_DATA_ENTRY(zicboz, PRIV_VERSION_1_12_0, ext_zicboz), | 73 | ISA_EXT_DATA_ENTRY(zvknhb, PRIV_VERSION_1_12_0, ext_zvknhb), |
63 | + ISA_EXT_DATA_ENTRY(ziccamoa, PRIV_VERSION_1_11_0, ext_always_enabled), | 74 | + ISA_EXT_DATA_ENTRY(zvksh, PRIV_VERSION_1_12_0, ext_zvksh), |
64 | + ISA_EXT_DATA_ENTRY(ziccif, PRIV_VERSION_1_11_0, ext_always_enabled), | 75 | ISA_EXT_DATA_ENTRY(zhinx, PRIV_VERSION_1_12_0, ext_zhinx), |
65 | + ISA_EXT_DATA_ENTRY(zicclsm, PRIV_VERSION_1_11_0, ext_always_enabled), | 76 | ISA_EXT_DATA_ENTRY(zhinxmin, PRIV_VERSION_1_12_0, ext_zhinxmin), |
66 | + ISA_EXT_DATA_ENTRY(ziccrse, PRIV_VERSION_1_11_0, ext_always_enabled), | 77 | ISA_EXT_DATA_ENTRY(smaia, PRIV_VERSION_1_12_0, ext_smaia), |
67 | ISA_EXT_DATA_ENTRY(zicond, PRIV_VERSION_1_12_0, ext_zicond), | 78 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) |
68 | ISA_EXT_DATA_ENTRY(zicntr, PRIV_VERSION_1_12_0, ext_zicntr), | 79 | * In principle Zve*x would also suffice here, were they supported |
69 | ISA_EXT_DATA_ENTRY(zicsr, PRIV_VERSION_1_10_0, ext_zicsr), | 80 | * in qemu |
70 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { | 81 | */ |
71 | ISA_EXT_DATA_ENTRY(zihintpause, PRIV_VERSION_1_10_0, ext_zihintpause), | 82 | - if ((cpu->cfg.ext_zvbb || cpu->cfg.ext_zvkned || cpu->cfg.ext_zvknha) && |
72 | ISA_EXT_DATA_ENTRY(zihpm, PRIV_VERSION_1_12_0, ext_zihpm), | 83 | - !cpu->cfg.ext_zve32f) { |
73 | ISA_EXT_DATA_ENTRY(zmmul, PRIV_VERSION_1_12_0, ext_zmmul), | 84 | + if ((cpu->cfg.ext_zvbb || cpu->cfg.ext_zvkned || cpu->cfg.ext_zvknha || |
74 | + ISA_EXT_DATA_ENTRY(za64rs, PRIV_VERSION_1_12_0, ext_always_enabled), | 85 | + cpu->cfg.ext_zvksh) && !cpu->cfg.ext_zve32f) { |
75 | ISA_EXT_DATA_ENTRY(zaamo, PRIV_VERSION_1_12_0, ext_zaamo), | 86 | error_setg(errp, |
76 | ISA_EXT_DATA_ENTRY(zacas, PRIV_VERSION_1_12_0, ext_zacas), | 87 | "Vector crypto extensions require V or Zve* extensions"); |
77 | ISA_EXT_DATA_ENTRY(zalrsc, PRIV_VERSION_1_12_0, ext_zalrsc), | 88 | return; |
78 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { | 89 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = { |
79 | ISA_EXT_DATA_ENTRY(smepmp, PRIV_VERSION_1_12_0, ext_smepmp), | 90 | DEFINE_PROP_BOOL("x-zvkned", RISCVCPU, cfg.ext_zvkned, false), |
80 | ISA_EXT_DATA_ENTRY(smstateen, PRIV_VERSION_1_12_0, ext_smstateen), | 91 | DEFINE_PROP_BOOL("x-zvknha", RISCVCPU, cfg.ext_zvknha, false), |
81 | ISA_EXT_DATA_ENTRY(ssaia, PRIV_VERSION_1_12_0, ext_ssaia), | 92 | DEFINE_PROP_BOOL("x-zvknhb", RISCVCPU, cfg.ext_zvknhb, false), |
82 | + ISA_EXT_DATA_ENTRY(ssccptr, PRIV_VERSION_1_11_0, ext_always_enabled), | 93 | + DEFINE_PROP_BOOL("x-zvksh", RISCVCPU, cfg.ext_zvksh, false), |
83 | ISA_EXT_DATA_ENTRY(sscofpmf, PRIV_VERSION_1_12_0, ext_sscofpmf), | 94 | |
84 | + ISA_EXT_DATA_ENTRY(sscounterenw, PRIV_VERSION_1_12_0, ext_always_enabled), | ||
85 | ISA_EXT_DATA_ENTRY(sstc, PRIV_VERSION_1_12_0, ext_sstc), | ||
86 | + ISA_EXT_DATA_ENTRY(sstvala, PRIV_VERSION_1_12_0, ext_always_enabled), | ||
87 | + ISA_EXT_DATA_ENTRY(sstvecd, PRIV_VERSION_1_12_0, ext_always_enabled), | ||
88 | ISA_EXT_DATA_ENTRY(svade, PRIV_VERSION_1_11_0, ext_svade), | ||
89 | ISA_EXT_DATA_ENTRY(svadu, PRIV_VERSION_1_12_0, ext_svadu), | ||
90 | ISA_EXT_DATA_ENTRY(svinval, PRIV_VERSION_1_12_0, ext_svinval), | ||
91 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = { | ||
92 | DEFINE_PROP_END_OF_LIST(), | 95 | DEFINE_PROP_END_OF_LIST(), |
93 | }; | 96 | }; |
94 | 97 | diff --git a/target/riscv/vcrypto_helper.c b/target/riscv/vcrypto_helper.c | |
95 | +#define ALWAYS_ENABLED_FEATURE(_name) \ | 98 | index XXXXXXX..XXXXXXX 100644 |
96 | + {.name = _name, \ | 99 | --- a/target/riscv/vcrypto_helper.c |
97 | + .offset = CPU_CFG_OFFSET(ext_always_enabled), \ | 100 | +++ b/target/riscv/vcrypto_helper.c |
98 | + .enabled = true} | 101 | @@ -XXX,XX +XXX,XX @@ void HELPER(vsha2cl64_vv)(void *vd, void *vs1, void *vs2, CPURISCVState *env, |
99 | + | 102 | vext_set_elems_1s(vd, vta, env->vl * esz, total_elems * esz); |
100 | /* | 103 | env->vstart = 0; |
101 | * 'Named features' is the name we give to extensions that we | 104 | } |
102 | * don't want to expose to users. They are either immutable | 105 | + |
103 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_named_features[] = { | 106 | +static inline uint32_t p1(uint32_t x) |
104 | MULTI_EXT_CFG_BOOL("svade", ext_svade, true), | 107 | +{ |
105 | MULTI_EXT_CFG_BOOL("zic64b", ext_zic64b, true), | 108 | + return x ^ rol32(x, 15) ^ rol32(x, 23); |
106 | 109 | +} | |
107 | + /* | 110 | + |
108 | + * cache-related extensions that are always enabled | 111 | +static inline uint32_t zvksh_w(uint32_t m16, uint32_t m9, uint32_t m3, |
109 | + * in TCG since QEMU RISC-V does not have a cache | 112 | + uint32_t m13, uint32_t m6) |
110 | + * model. | 113 | +{ |
111 | + */ | 114 | + return p1(m16 ^ m9 ^ rol32(m3, 15)) ^ rol32(m13, 7) ^ m6; |
112 | + ALWAYS_ENABLED_FEATURE("za64rs"), | 115 | +} |
113 | + ALWAYS_ENABLED_FEATURE("ziccif"), | 116 | + |
114 | + ALWAYS_ENABLED_FEATURE("ziccrse"), | 117 | +void HELPER(vsm3me_vv)(void *vd_vptr, void *vs1_vptr, void *vs2_vptr, |
115 | + ALWAYS_ENABLED_FEATURE("ziccamoa"), | 118 | + CPURISCVState *env, uint32_t desc) |
116 | + ALWAYS_ENABLED_FEATURE("zicclsm"), | 119 | +{ |
117 | + ALWAYS_ENABLED_FEATURE("ssccptr"), | 120 | + uint32_t esz = memop_size(FIELD_EX64(env->vtype, VTYPE, VSEW)); |
118 | + | 121 | + uint32_t total_elems = vext_get_total_elems(env, desc, esz); |
119 | + /* Other named features that TCG always implements */ | 122 | + uint32_t vta = vext_vta(desc); |
120 | + ALWAYS_ENABLED_FEATURE("sstvecd"), | 123 | + uint32_t *vd = vd_vptr; |
121 | + ALWAYS_ENABLED_FEATURE("sstvala"), | 124 | + uint32_t *vs1 = vs1_vptr; |
122 | + ALWAYS_ENABLED_FEATURE("sscounterenw"), | 125 | + uint32_t *vs2 = vs2_vptr; |
123 | + | 126 | + |
124 | DEFINE_PROP_END_OF_LIST(), | 127 | + for (int i = env->vstart / 8; i < env->vl / 8; i++) { |
125 | }; | 128 | + uint32_t w[24]; |
126 | 129 | + for (int j = 0; j < 8; j++) { | |
127 | @@ -XXX,XX +XXX,XX @@ static const PropertyInfo prop_marchid = { | 130 | + w[j] = bswap32(vs1[H4((i * 8) + j)]); |
128 | }; | 131 | + w[j + 8] = bswap32(vs2[H4((i * 8) + j)]); |
129 | 132 | + } | |
130 | /* | 133 | + for (int j = 0; j < 8; j++) { |
131 | - * RVA22U64 defines some 'named features' or 'synthetic extensions' | 134 | + w[j + 16] = |
132 | - * that are cache related: Za64rs, Zic64b, Ziccif, Ziccrse, Ziccamoa | 135 | + zvksh_w(w[j], w[j + 7], w[j + 13], w[j + 3], w[j + 10]); |
133 | - * and Zicclsm. We do not implement caching in QEMU so we'll consider | 136 | + } |
134 | - * all these named features as always enabled. | 137 | + for (int j = 0; j < 8; j++) { |
135 | - * | 138 | + vd[(i * 8) + j] = bswap32(w[H4(j + 16)]); |
136 | - * There's no riscv,isa update for them (nor for zic64b, despite it | 139 | + } |
137 | - * having a cfg offset) at this moment. | 140 | + } |
138 | + * RVA22U64 defines some 'named features' that are cache | 141 | + vext_set_elems_1s(vd_vptr, vta, env->vl * esz, total_elems * esz); |
139 | + * related: Za64rs, Zic64b, Ziccif, Ziccrse, Ziccamoa | 142 | + env->vstart = 0; |
140 | + * and Zicclsm. They are always implemented in TCG and | 143 | +} |
141 | + * doesn't need to be manually enabled by the profile. | 144 | + |
142 | */ | 145 | +static inline uint32_t ff1(uint32_t x, uint32_t y, uint32_t z) |
143 | static RISCVCPUProfile RVA22U64 = { | 146 | +{ |
144 | .parent = NULL, | 147 | + return x ^ y ^ z; |
145 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | 148 | +} |
146 | index XXXXXXX..XXXXXXX 100644 | 149 | + |
147 | --- a/target/riscv/tcg/tcg-cpu.c | 150 | +static inline uint32_t ff2(uint32_t x, uint32_t y, uint32_t z) |
148 | +++ b/target/riscv/tcg/tcg-cpu.c | 151 | +{ |
149 | @@ -XXX,XX +XXX,XX @@ static void riscv_tcg_cpu_instance_init(CPUState *cs) | 152 | + return (x & y) | (x & z) | (y & z); |
150 | RISCVCPU *cpu = RISCV_CPU(cs); | 153 | +} |
151 | Object *obj = OBJECT(cpu); | 154 | + |
152 | 155 | +static inline uint32_t ff_j(uint32_t x, uint32_t y, uint32_t z, uint32_t j) | |
153 | + cpu->cfg.ext_always_enabled = true; | 156 | +{ |
154 | + | 157 | + return (j <= 15) ? ff1(x, y, z) : ff2(x, y, z); |
155 | misa_ext_user_opts = g_hash_table_new(NULL, g_direct_equal); | 158 | +} |
156 | multi_ext_user_opts = g_hash_table_new(NULL, g_direct_equal); | 159 | + |
157 | riscv_cpu_add_user_properties(obj); | 160 | +static inline uint32_t gg1(uint32_t x, uint32_t y, uint32_t z) |
161 | +{ | ||
162 | + return x ^ y ^ z; | ||
163 | +} | ||
164 | + | ||
165 | +static inline uint32_t gg2(uint32_t x, uint32_t y, uint32_t z) | ||
166 | +{ | ||
167 | + return (x & y) | (~x & z); | ||
168 | +} | ||
169 | + | ||
170 | +static inline uint32_t gg_j(uint32_t x, uint32_t y, uint32_t z, uint32_t j) | ||
171 | +{ | ||
172 | + return (j <= 15) ? gg1(x, y, z) : gg2(x, y, z); | ||
173 | +} | ||
174 | + | ||
175 | +static inline uint32_t t_j(uint32_t j) | ||
176 | +{ | ||
177 | + return (j <= 15) ? 0x79cc4519 : 0x7a879d8a; | ||
178 | +} | ||
179 | + | ||
180 | +static inline uint32_t p_0(uint32_t x) | ||
181 | +{ | ||
182 | + return x ^ rol32(x, 9) ^ rol32(x, 17); | ||
183 | +} | ||
184 | + | ||
185 | +static void sm3c(uint32_t *vd, uint32_t *vs1, uint32_t *vs2, uint32_t uimm) | ||
186 | +{ | ||
187 | + uint32_t x0, x1; | ||
188 | + uint32_t j; | ||
189 | + uint32_t ss1, ss2, tt1, tt2; | ||
190 | + x0 = vs2[0] ^ vs2[4]; | ||
191 | + x1 = vs2[1] ^ vs2[5]; | ||
192 | + j = 2 * uimm; | ||
193 | + ss1 = rol32(rol32(vs1[0], 12) + vs1[4] + rol32(t_j(j), j % 32), 7); | ||
194 | + ss2 = ss1 ^ rol32(vs1[0], 12); | ||
195 | + tt1 = ff_j(vs1[0], vs1[1], vs1[2], j) + vs1[3] + ss2 + x0; | ||
196 | + tt2 = gg_j(vs1[4], vs1[5], vs1[6], j) + vs1[7] + ss1 + vs2[0]; | ||
197 | + vs1[3] = vs1[2]; | ||
198 | + vd[3] = rol32(vs1[1], 9); | ||
199 | + vs1[1] = vs1[0]; | ||
200 | + vd[1] = tt1; | ||
201 | + vs1[7] = vs1[6]; | ||
202 | + vd[7] = rol32(vs1[5], 19); | ||
203 | + vs1[5] = vs1[4]; | ||
204 | + vd[5] = p_0(tt2); | ||
205 | + j = 2 * uimm + 1; | ||
206 | + ss1 = rol32(rol32(vd[1], 12) + vd[5] + rol32(t_j(j), j % 32), 7); | ||
207 | + ss2 = ss1 ^ rol32(vd[1], 12); | ||
208 | + tt1 = ff_j(vd[1], vs1[1], vd[3], j) + vs1[3] + ss2 + x1; | ||
209 | + tt2 = gg_j(vd[5], vs1[5], vd[7], j) + vs1[7] + ss1 + vs2[1]; | ||
210 | + vd[2] = rol32(vs1[1], 9); | ||
211 | + vd[0] = tt1; | ||
212 | + vd[6] = rol32(vs1[5], 19); | ||
213 | + vd[4] = p_0(tt2); | ||
214 | +} | ||
215 | + | ||
216 | +void HELPER(vsm3c_vi)(void *vd_vptr, void *vs2_vptr, uint32_t uimm, | ||
217 | + CPURISCVState *env, uint32_t desc) | ||
218 | +{ | ||
219 | + uint32_t esz = memop_size(FIELD_EX64(env->vtype, VTYPE, VSEW)); | ||
220 | + uint32_t total_elems = vext_get_total_elems(env, desc, esz); | ||
221 | + uint32_t vta = vext_vta(desc); | ||
222 | + uint32_t *vd = vd_vptr; | ||
223 | + uint32_t *vs2 = vs2_vptr; | ||
224 | + uint32_t v1[8], v2[8], v3[8]; | ||
225 | + | ||
226 | + for (int i = env->vstart / 8; i < env->vl / 8; i++) { | ||
227 | + for (int k = 0; k < 8; k++) { | ||
228 | + v2[k] = bswap32(vd[H4(i * 8 + k)]); | ||
229 | + v3[k] = bswap32(vs2[H4(i * 8 + k)]); | ||
230 | + } | ||
231 | + sm3c(v1, v2, v3, uimm); | ||
232 | + for (int k = 0; k < 8; k++) { | ||
233 | + vd[i * 8 + k] = bswap32(v1[H4(k)]); | ||
234 | + } | ||
235 | + } | ||
236 | + vext_set_elems_1s(vd_vptr, vta, env->vl * esz, total_elems * esz); | ||
237 | + env->vstart = 0; | ||
238 | +} | ||
239 | diff --git a/target/riscv/insn_trans/trans_rvvk.c.inc b/target/riscv/insn_trans/trans_rvvk.c.inc | ||
240 | index XXXXXXX..XXXXXXX 100644 | ||
241 | --- a/target/riscv/insn_trans/trans_rvvk.c.inc | ||
242 | +++ b/target/riscv/insn_trans/trans_rvvk.c.inc | ||
243 | @@ -XXX,XX +XXX,XX @@ static bool trans_vsha2ch_vv(DisasContext *s, arg_rmrr *a) | ||
244 | } | ||
245 | return false; | ||
246 | } | ||
247 | + | ||
248 | +/* | ||
249 | + * Zvksh | ||
250 | + */ | ||
251 | + | ||
252 | +#define ZVKSH_EGS 8 | ||
253 | + | ||
254 | +static inline bool vsm3_check(DisasContext *s, arg_rmrr *a) | ||
255 | +{ | ||
256 | + int egw_bytes = ZVKSH_EGS << s->sew; | ||
257 | + int mult = 1 << MAX(s->lmul, 0); | ||
258 | + return s->cfg_ptr->ext_zvksh == true && | ||
259 | + require_rvv(s) && | ||
260 | + vext_check_isa_ill(s) && | ||
261 | + !is_overlapped(a->rd, mult, a->rs2, mult) && | ||
262 | + MAXSZ(s) >= egw_bytes && | ||
263 | + s->sew == MO_32; | ||
264 | +} | ||
265 | + | ||
266 | +static inline bool vsm3me_check(DisasContext *s, arg_rmrr *a) | ||
267 | +{ | ||
268 | + return vsm3_check(s, a) && vext_check_sss(s, a->rd, a->rs1, a->rs2, a->vm); | ||
269 | +} | ||
270 | + | ||
271 | +static inline bool vsm3c_check(DisasContext *s, arg_rmrr *a) | ||
272 | +{ | ||
273 | + return vsm3_check(s, a) && vext_check_ss(s, a->rd, a->rs2, a->vm); | ||
274 | +} | ||
275 | + | ||
276 | +GEN_VV_UNMASKED_TRANS(vsm3me_vv, vsm3me_check, ZVKSH_EGS) | ||
277 | +GEN_VI_UNMASKED_TRANS(vsm3c_vi, vsm3c_check, ZVKSH_EGS) | ||
158 | -- | 278 | -- |
159 | 2.44.0 | 279 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Nazar Kazakov <nazar.kazakov@codethink.co.uk> | |
2 | |||
3 | This commit adds support for the Zvkg vector-crypto extension, which | ||
4 | consists of the following instructions: | ||
5 | |||
6 | * vgmul.vv | ||
7 | * vghsh.vv | ||
8 | |||
9 | Translation functions are defined in | ||
10 | `target/riscv/insn_trans/trans_rvvk.c.inc` and helpers are defined in | ||
11 | `target/riscv/vcrypto_helper.c`. | ||
12 | |||
13 | Co-authored-by: Lawrence Hunter <lawrence.hunter@codethink.co.uk> | ||
14 | [max.chou@sifive.com: Replaced vstart checking by TCG op] | ||
15 | Signed-off-by: Lawrence Hunter <lawrence.hunter@codethink.co.uk> | ||
16 | Signed-off-by: Nazar Kazakov <nazar.kazakov@codethink.co.uk> | ||
17 | Signed-off-by: Max Chou <max.chou@sifive.com> | ||
18 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
19 | [max.chou@sifive.com: Exposed x-zvkg property] | ||
20 | [max.chou@sifive.com: Replaced uint by int for cross win32 build] | ||
21 | Message-ID: <20230711165917.2629866-13-max.chou@sifive.com> | ||
22 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
23 | --- | ||
24 | target/riscv/cpu_cfg.h | 1 + | ||
25 | target/riscv/helper.h | 3 + | ||
26 | target/riscv/insn32.decode | 4 ++ | ||
27 | target/riscv/cpu.c | 6 +- | ||
28 | target/riscv/vcrypto_helper.c | 72 ++++++++++++++++++++++++ | ||
29 | target/riscv/insn_trans/trans_rvvk.c.inc | 30 ++++++++++ | ||
30 | 6 files changed, 114 insertions(+), 2 deletions(-) | ||
31 | |||
32 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/target/riscv/cpu_cfg.h | ||
35 | +++ b/target/riscv/cpu_cfg.h | ||
36 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { | ||
37 | bool ext_zve64d; | ||
38 | bool ext_zvbb; | ||
39 | bool ext_zvbc; | ||
40 | + bool ext_zvkg; | ||
41 | bool ext_zvkned; | ||
42 | bool ext_zvknha; | ||
43 | bool ext_zvknhb; | ||
44 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/target/riscv/helper.h | ||
47 | +++ b/target/riscv/helper.h | ||
48 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_5(vsha2cl64_vv, void, ptr, ptr, ptr, env, i32) | ||
49 | |||
50 | DEF_HELPER_5(vsm3me_vv, void, ptr, ptr, ptr, env, i32) | ||
51 | DEF_HELPER_5(vsm3c_vi, void, ptr, ptr, i32, env, i32) | ||
52 | + | ||
53 | +DEF_HELPER_5(vghsh_vv, void, ptr, ptr, ptr, env, i32) | ||
54 | +DEF_HELPER_4(vgmul_vv, void, ptr, ptr, env, i32) | ||
55 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | ||
56 | index XXXXXXX..XXXXXXX 100644 | ||
57 | --- a/target/riscv/insn32.decode | ||
58 | +++ b/target/riscv/insn32.decode | ||
59 | @@ -XXX,XX +XXX,XX @@ vsha2cl_vv 101111 1 ..... ..... 010 ..... 1110111 @r_vm_1 | ||
60 | # *** Zvksh vector crypto extension *** | ||
61 | vsm3me_vv 100000 1 ..... ..... 010 ..... 1110111 @r_vm_1 | ||
62 | vsm3c_vi 101011 1 ..... ..... 010 ..... 1110111 @r_vm_1 | ||
63 | + | ||
64 | +# *** Zvkg vector crypto extension *** | ||
65 | +vghsh_vv 101100 1 ..... ..... 010 ..... 1110111 @r_vm_1 | ||
66 | +vgmul_vv 101000 1 ..... 10001 010 ..... 1110111 @r2_vm_1 | ||
67 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
68 | index XXXXXXX..XXXXXXX 100644 | ||
69 | --- a/target/riscv/cpu.c | ||
70 | +++ b/target/riscv/cpu.c | ||
71 | @@ -XXX,XX +XXX,XX @@ static const struct isa_ext_data isa_edata_arr[] = { | ||
72 | ISA_EXT_DATA_ENTRY(zvfbfwma, PRIV_VERSION_1_12_0, ext_zvfbfwma), | ||
73 | ISA_EXT_DATA_ENTRY(zvfh, PRIV_VERSION_1_12_0, ext_zvfh), | ||
74 | ISA_EXT_DATA_ENTRY(zvfhmin, PRIV_VERSION_1_12_0, ext_zvfhmin), | ||
75 | + ISA_EXT_DATA_ENTRY(zvkg, PRIV_VERSION_1_12_0, ext_zvkg), | ||
76 | ISA_EXT_DATA_ENTRY(zvkned, PRIV_VERSION_1_12_0, ext_zvkned), | ||
77 | ISA_EXT_DATA_ENTRY(zvknha, PRIV_VERSION_1_12_0, ext_zvknha), | ||
78 | ISA_EXT_DATA_ENTRY(zvknhb, PRIV_VERSION_1_12_0, ext_zvknhb), | ||
79 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
80 | * In principle Zve*x would also suffice here, were they supported | ||
81 | * in qemu | ||
82 | */ | ||
83 | - if ((cpu->cfg.ext_zvbb || cpu->cfg.ext_zvkned || cpu->cfg.ext_zvknha || | ||
84 | - cpu->cfg.ext_zvksh) && !cpu->cfg.ext_zve32f) { | ||
85 | + if ((cpu->cfg.ext_zvbb || cpu->cfg.ext_zvkg || cpu->cfg.ext_zvkned || | ||
86 | + cpu->cfg.ext_zvknha || cpu->cfg.ext_zvksh) && !cpu->cfg.ext_zve32f) { | ||
87 | error_setg(errp, | ||
88 | "Vector crypto extensions require V or Zve* extensions"); | ||
89 | return; | ||
90 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = { | ||
91 | /* Vector cryptography extensions */ | ||
92 | DEFINE_PROP_BOOL("x-zvbb", RISCVCPU, cfg.ext_zvbb, false), | ||
93 | DEFINE_PROP_BOOL("x-zvbc", RISCVCPU, cfg.ext_zvbc, false), | ||
94 | + DEFINE_PROP_BOOL("x-zvkg", RISCVCPU, cfg.ext_zvkg, false), | ||
95 | DEFINE_PROP_BOOL("x-zvkned", RISCVCPU, cfg.ext_zvkned, false), | ||
96 | DEFINE_PROP_BOOL("x-zvknha", RISCVCPU, cfg.ext_zvknha, false), | ||
97 | DEFINE_PROP_BOOL("x-zvknhb", RISCVCPU, cfg.ext_zvknhb, false), | ||
98 | diff --git a/target/riscv/vcrypto_helper.c b/target/riscv/vcrypto_helper.c | ||
99 | index XXXXXXX..XXXXXXX 100644 | ||
100 | --- a/target/riscv/vcrypto_helper.c | ||
101 | +++ b/target/riscv/vcrypto_helper.c | ||
102 | @@ -XXX,XX +XXX,XX @@ void HELPER(vsm3c_vi)(void *vd_vptr, void *vs2_vptr, uint32_t uimm, | ||
103 | vext_set_elems_1s(vd_vptr, vta, env->vl * esz, total_elems * esz); | ||
104 | env->vstart = 0; | ||
105 | } | ||
106 | + | ||
107 | +void HELPER(vghsh_vv)(void *vd_vptr, void *vs1_vptr, void *vs2_vptr, | ||
108 | + CPURISCVState *env, uint32_t desc) | ||
109 | +{ | ||
110 | + uint64_t *vd = vd_vptr; | ||
111 | + uint64_t *vs1 = vs1_vptr; | ||
112 | + uint64_t *vs2 = vs2_vptr; | ||
113 | + uint32_t vta = vext_vta(desc); | ||
114 | + uint32_t total_elems = vext_get_total_elems(env, desc, 4); | ||
115 | + | ||
116 | + for (uint32_t i = env->vstart / 4; i < env->vl / 4; i++) { | ||
117 | + uint64_t Y[2] = {vd[i * 2 + 0], vd[i * 2 + 1]}; | ||
118 | + uint64_t H[2] = {brev8(vs2[i * 2 + 0]), brev8(vs2[i * 2 + 1])}; | ||
119 | + uint64_t X[2] = {vs1[i * 2 + 0], vs1[i * 2 + 1]}; | ||
120 | + uint64_t Z[2] = {0, 0}; | ||
121 | + | ||
122 | + uint64_t S[2] = {brev8(Y[0] ^ X[0]), brev8(Y[1] ^ X[1])}; | ||
123 | + | ||
124 | + for (int j = 0; j < 128; j++) { | ||
125 | + if ((S[j / 64] >> (j % 64)) & 1) { | ||
126 | + Z[0] ^= H[0]; | ||
127 | + Z[1] ^= H[1]; | ||
128 | + } | ||
129 | + bool reduce = ((H[1] >> 63) & 1); | ||
130 | + H[1] = H[1] << 1 | H[0] >> 63; | ||
131 | + H[0] = H[0] << 1; | ||
132 | + if (reduce) { | ||
133 | + H[0] ^= 0x87; | ||
134 | + } | ||
135 | + } | ||
136 | + | ||
137 | + vd[i * 2 + 0] = brev8(Z[0]); | ||
138 | + vd[i * 2 + 1] = brev8(Z[1]); | ||
139 | + } | ||
140 | + /* set tail elements to 1s */ | ||
141 | + vext_set_elems_1s(vd, vta, env->vl * 4, total_elems * 4); | ||
142 | + env->vstart = 0; | ||
143 | +} | ||
144 | + | ||
145 | +void HELPER(vgmul_vv)(void *vd_vptr, void *vs2_vptr, CPURISCVState *env, | ||
146 | + uint32_t desc) | ||
147 | +{ | ||
148 | + uint64_t *vd = vd_vptr; | ||
149 | + uint64_t *vs2 = vs2_vptr; | ||
150 | + uint32_t vta = vext_vta(desc); | ||
151 | + uint32_t total_elems = vext_get_total_elems(env, desc, 4); | ||
152 | + | ||
153 | + for (uint32_t i = env->vstart / 4; i < env->vl / 4; i++) { | ||
154 | + uint64_t Y[2] = {brev8(vd[i * 2 + 0]), brev8(vd[i * 2 + 1])}; | ||
155 | + uint64_t H[2] = {brev8(vs2[i * 2 + 0]), brev8(vs2[i * 2 + 1])}; | ||
156 | + uint64_t Z[2] = {0, 0}; | ||
157 | + | ||
158 | + for (int j = 0; j < 128; j++) { | ||
159 | + if ((Y[j / 64] >> (j % 64)) & 1) { | ||
160 | + Z[0] ^= H[0]; | ||
161 | + Z[1] ^= H[1]; | ||
162 | + } | ||
163 | + bool reduce = ((H[1] >> 63) & 1); | ||
164 | + H[1] = H[1] << 1 | H[0] >> 63; | ||
165 | + H[0] = H[0] << 1; | ||
166 | + if (reduce) { | ||
167 | + H[0] ^= 0x87; | ||
168 | + } | ||
169 | + } | ||
170 | + | ||
171 | + vd[i * 2 + 0] = brev8(Z[0]); | ||
172 | + vd[i * 2 + 1] = brev8(Z[1]); | ||
173 | + } | ||
174 | + /* set tail elements to 1s */ | ||
175 | + vext_set_elems_1s(vd, vta, env->vl * 4, total_elems * 4); | ||
176 | + env->vstart = 0; | ||
177 | +} | ||
178 | diff --git a/target/riscv/insn_trans/trans_rvvk.c.inc b/target/riscv/insn_trans/trans_rvvk.c.inc | ||
179 | index XXXXXXX..XXXXXXX 100644 | ||
180 | --- a/target/riscv/insn_trans/trans_rvvk.c.inc | ||
181 | +++ b/target/riscv/insn_trans/trans_rvvk.c.inc | ||
182 | @@ -XXX,XX +XXX,XX @@ static inline bool vsm3c_check(DisasContext *s, arg_rmrr *a) | ||
183 | |||
184 | GEN_VV_UNMASKED_TRANS(vsm3me_vv, vsm3me_check, ZVKSH_EGS) | ||
185 | GEN_VI_UNMASKED_TRANS(vsm3c_vi, vsm3c_check, ZVKSH_EGS) | ||
186 | + | ||
187 | +/* | ||
188 | + * Zvkg | ||
189 | + */ | ||
190 | + | ||
191 | +#define ZVKG_EGS 4 | ||
192 | + | ||
193 | +static bool vgmul_check(DisasContext *s, arg_rmr *a) | ||
194 | +{ | ||
195 | + int egw_bytes = ZVKG_EGS << s->sew; | ||
196 | + return s->cfg_ptr->ext_zvkg == true && | ||
197 | + vext_check_isa_ill(s) && | ||
198 | + require_rvv(s) && | ||
199 | + MAXSZ(s) >= egw_bytes && | ||
200 | + vext_check_ss(s, a->rd, a->rs2, a->vm) && | ||
201 | + s->sew == MO_32; | ||
202 | +} | ||
203 | + | ||
204 | +GEN_V_UNMASKED_TRANS(vgmul_vv, vgmul_check, ZVKG_EGS) | ||
205 | + | ||
206 | +static bool vghsh_check(DisasContext *s, arg_rmrr *a) | ||
207 | +{ | ||
208 | + int egw_bytes = ZVKG_EGS << s->sew; | ||
209 | + return s->cfg_ptr->ext_zvkg == true && | ||
210 | + opivv_check(s, a) && | ||
211 | + MAXSZ(s) >= egw_bytes && | ||
212 | + s->sew == MO_32; | ||
213 | +} | ||
214 | + | ||
215 | +GEN_VV_UNMASKED_TRANS(vghsh_vv, vghsh_check, ZVKG_EGS) | ||
216 | -- | ||
217 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Hiroaki Yamamoto <hrak1529@gmail.com> | 1 | From: Max Chou <max.chou@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | G-stage translation should be considered to be user-level access in | 3 | Allows sharing of sm4_subword between different targets. |
4 | riscv_cpu_get_phys_page_debug(), as already done in riscv_cpu_tlb_fill(). | ||
5 | 4 | ||
6 | This fixes a bug that prevents gdb from reading memory while the VM is | 5 | Signed-off-by: Max Chou <max.chou@sifive.com> |
7 | running in VS-mode. | 6 | Reviewed-by: Frank Chang <frank.chang@sifive.com> |
8 | 7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | |
9 | Signed-off-by: Hiroaki Yamamoto <hrak1529@gmail.com> | 8 | Signed-off-by: Max Chou <max.chou@sifive.com> |
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Message-ID: <20230711165917.2629866-14-max.chou@sifive.com> |
11 | Message-ID: <20240228081028.35081-1-hrak1529@gmail.com> | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | --- | 11 | --- |
14 | target/riscv/cpu_helper.c | 2 +- | 12 | include/crypto/sm4.h | 8 ++++++++ |
15 | 1 file changed, 1 insertion(+), 1 deletion(-) | 13 | target/arm/tcg/crypto_helper.c | 10 ++-------- |
14 | 2 files changed, 10 insertions(+), 8 deletions(-) | ||
16 | 15 | ||
17 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 16 | diff --git a/include/crypto/sm4.h b/include/crypto/sm4.h |
18 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/target/riscv/cpu_helper.c | 18 | --- a/include/crypto/sm4.h |
20 | +++ b/target/riscv/cpu_helper.c | 19 | +++ b/include/crypto/sm4.h |
21 | @@ -XXX,XX +XXX,XX @@ hwaddr riscv_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) | 20 | @@ -XXX,XX +XXX,XX @@ |
22 | 21 | ||
23 | if (env->virt_enabled) { | 22 | extern const uint8_t sm4_sbox[256]; |
24 | if (get_physical_address(env, &phys_addr, &prot, phys_addr, NULL, | 23 | |
25 | - 0, mmu_idx, false, true, true)) { | 24 | +static inline uint32_t sm4_subword(uint32_t word) |
26 | + 0, MMUIdx_U, false, true, true)) { | 25 | +{ |
27 | return -1; | 26 | + return sm4_sbox[word & 0xff] | |
28 | } | 27 | + sm4_sbox[(word >> 8) & 0xff] << 8 | |
28 | + sm4_sbox[(word >> 16) & 0xff] << 16 | | ||
29 | + sm4_sbox[(word >> 24) & 0xff] << 24; | ||
30 | +} | ||
31 | + | ||
32 | #endif | ||
33 | diff --git a/target/arm/tcg/crypto_helper.c b/target/arm/tcg/crypto_helper.c | ||
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/target/arm/tcg/crypto_helper.c | ||
36 | +++ b/target/arm/tcg/crypto_helper.c | ||
37 | @@ -XXX,XX +XXX,XX @@ static void do_crypto_sm4e(uint64_t *rd, uint64_t *rn, uint64_t *rm) | ||
38 | CR_ST_WORD(d, (i + 3) % 4) ^ | ||
39 | CR_ST_WORD(n, i); | ||
40 | |||
41 | - t = sm4_sbox[t & 0xff] | | ||
42 | - sm4_sbox[(t >> 8) & 0xff] << 8 | | ||
43 | - sm4_sbox[(t >> 16) & 0xff] << 16 | | ||
44 | - sm4_sbox[(t >> 24) & 0xff] << 24; | ||
45 | + t = sm4_subword(t); | ||
46 | |||
47 | CR_ST_WORD(d, i) ^= t ^ rol32(t, 2) ^ rol32(t, 10) ^ rol32(t, 18) ^ | ||
48 | rol32(t, 24); | ||
49 | @@ -XXX,XX +XXX,XX @@ static void do_crypto_sm4ekey(uint64_t *rd, uint64_t *rn, uint64_t *rm) | ||
50 | CR_ST_WORD(d, (i + 3) % 4) ^ | ||
51 | CR_ST_WORD(m, i); | ||
52 | |||
53 | - t = sm4_sbox[t & 0xff] | | ||
54 | - sm4_sbox[(t >> 8) & 0xff] << 8 | | ||
55 | - sm4_sbox[(t >> 16) & 0xff] << 16 | | ||
56 | - sm4_sbox[(t >> 24) & 0xff] << 24; | ||
57 | + t = sm4_subword(t); | ||
58 | |||
59 | CR_ST_WORD(d, i) ^= t ^ rol32(t, 13) ^ rol32(t, 23); | ||
29 | } | 60 | } |
30 | -- | 61 | -- |
31 | 2.44.0 | 62 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Chou <max.chou@sifive.com> | ||
1 | 2 | ||
3 | Adds sm4_ck constant for use in sm4 cryptography across different targets. | ||
4 | |||
5 | Signed-off-by: Max Chou <max.chou@sifive.com> | ||
6 | Reviewed-by: Frank Chang <frank.chang@sifive.com> | ||
7 | Signed-off-by: Max Chou <max.chou@sifive.com> | ||
8 | Message-ID: <20230711165917.2629866-15-max.chou@sifive.com> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | --- | ||
11 | include/crypto/sm4.h | 1 + | ||
12 | crypto/sm4.c | 10 ++++++++++ | ||
13 | 2 files changed, 11 insertions(+) | ||
14 | |||
15 | diff --git a/include/crypto/sm4.h b/include/crypto/sm4.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/include/crypto/sm4.h | ||
18 | +++ b/include/crypto/sm4.h | ||
19 | @@ -XXX,XX +XXX,XX @@ | ||
20 | #define QEMU_SM4_H | ||
21 | |||
22 | extern const uint8_t sm4_sbox[256]; | ||
23 | +extern const uint32_t sm4_ck[32]; | ||
24 | |||
25 | static inline uint32_t sm4_subword(uint32_t word) | ||
26 | { | ||
27 | diff --git a/crypto/sm4.c b/crypto/sm4.c | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/crypto/sm4.c | ||
30 | +++ b/crypto/sm4.c | ||
31 | @@ -XXX,XX +XXX,XX @@ uint8_t const sm4_sbox[] = { | ||
32 | 0x79, 0xee, 0x5f, 0x3e, 0xd7, 0xcb, 0x39, 0x48, | ||
33 | }; | ||
34 | |||
35 | +uint32_t const sm4_ck[] = { | ||
36 | + 0x00070e15, 0x1c232a31, 0x383f464d, 0x545b6269, | ||
37 | + 0x70777e85, 0x8c939aa1, 0xa8afb6bd, 0xc4cbd2d9, | ||
38 | + 0xe0e7eef5, 0xfc030a11, 0x181f262d, 0x343b4249, | ||
39 | + 0x50575e65, 0x6c737a81, 0x888f969d, 0xa4abb2b9, | ||
40 | + 0xc0c7ced5, 0xdce3eaf1, 0xf8ff060d, 0x141b2229, | ||
41 | + 0x30373e45, 0x4c535a61, 0x686f767d, 0x848b9299, | ||
42 | + 0xa0a7aeb5, 0xbcc3cad1, 0xd8dfe6ed, 0xf4fb0209, | ||
43 | + 0x10171e25, 0x2c333a41, 0x484f565d, 0x646b7279 | ||
44 | +}; | ||
45 | -- | ||
46 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Max Chou <max.chou@sifive.com> | |
2 | |||
3 | This commit adds support for the Zvksed vector-crypto extension, which | ||
4 | consists of the following instructions: | ||
5 | |||
6 | * vsm4k.vi | ||
7 | * vsm4r.[vv,vs] | ||
8 | |||
9 | Translation functions are defined in | ||
10 | `target/riscv/insn_trans/trans_rvvk.c.inc` and helpers are defined in | ||
11 | `target/riscv/vcrypto_helper.c`. | ||
12 | |||
13 | Signed-off-by: Max Chou <max.chou@sifive.com> | ||
14 | Reviewed-by: Frank Chang <frank.chang@sifive.com> | ||
15 | [lawrence.hunter@codethink.co.uk: Moved SM4 functions from | ||
16 | crypto_helper.c to vcrypto_helper.c] | ||
17 | [nazar.kazakov@codethink.co.uk: Added alignment checks, refactored code to | ||
18 | use macros, and minor style changes] | ||
19 | Signed-off-by: Max Chou <max.chou@sifive.com> | ||
20 | Message-ID: <20230711165917.2629866-16-max.chou@sifive.com> | ||
21 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
22 | --- | ||
23 | target/riscv/cpu_cfg.h | 1 + | ||
24 | target/riscv/helper.h | 4 + | ||
25 | target/riscv/insn32.decode | 5 + | ||
26 | target/riscv/cpu.c | 5 +- | ||
27 | target/riscv/vcrypto_helper.c | 127 +++++++++++++++++++++++ | ||
28 | target/riscv/insn_trans/trans_rvvk.c.inc | 43 ++++++++ | ||
29 | 6 files changed, 184 insertions(+), 1 deletion(-) | ||
30 | |||
31 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/target/riscv/cpu_cfg.h | ||
34 | +++ b/target/riscv/cpu_cfg.h | ||
35 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { | ||
36 | bool ext_zvkned; | ||
37 | bool ext_zvknha; | ||
38 | bool ext_zvknhb; | ||
39 | + bool ext_zvksed; | ||
40 | bool ext_zvksh; | ||
41 | bool ext_zmmul; | ||
42 | bool ext_zvfbfmin; | ||
43 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h | ||
44 | index XXXXXXX..XXXXXXX 100644 | ||
45 | --- a/target/riscv/helper.h | ||
46 | +++ b/target/riscv/helper.h | ||
47 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_5(vsm3c_vi, void, ptr, ptr, i32, env, i32) | ||
48 | |||
49 | DEF_HELPER_5(vghsh_vv, void, ptr, ptr, ptr, env, i32) | ||
50 | DEF_HELPER_4(vgmul_vv, void, ptr, ptr, env, i32) | ||
51 | + | ||
52 | +DEF_HELPER_5(vsm4k_vi, void, ptr, ptr, i32, env, i32) | ||
53 | +DEF_HELPER_4(vsm4r_vv, void, ptr, ptr, env, i32) | ||
54 | +DEF_HELPER_4(vsm4r_vs, void, ptr, ptr, env, i32) | ||
55 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | ||
56 | index XXXXXXX..XXXXXXX 100644 | ||
57 | --- a/target/riscv/insn32.decode | ||
58 | +++ b/target/riscv/insn32.decode | ||
59 | @@ -XXX,XX +XXX,XX @@ vsm3c_vi 101011 1 ..... ..... 010 ..... 1110111 @r_vm_1 | ||
60 | # *** Zvkg vector crypto extension *** | ||
61 | vghsh_vv 101100 1 ..... ..... 010 ..... 1110111 @r_vm_1 | ||
62 | vgmul_vv 101000 1 ..... 10001 010 ..... 1110111 @r2_vm_1 | ||
63 | + | ||
64 | +# *** Zvksed vector crypto extension *** | ||
65 | +vsm4k_vi 100001 1 ..... ..... 010 ..... 1110111 @r_vm_1 | ||
66 | +vsm4r_vv 101000 1 ..... 10000 010 ..... 1110111 @r2_vm_1 | ||
67 | +vsm4r_vs 101001 1 ..... 10000 010 ..... 1110111 @r2_vm_1 | ||
68 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
69 | index XXXXXXX..XXXXXXX 100644 | ||
70 | --- a/target/riscv/cpu.c | ||
71 | +++ b/target/riscv/cpu.c | ||
72 | @@ -XXX,XX +XXX,XX @@ static const struct isa_ext_data isa_edata_arr[] = { | ||
73 | ISA_EXT_DATA_ENTRY(zvkned, PRIV_VERSION_1_12_0, ext_zvkned), | ||
74 | ISA_EXT_DATA_ENTRY(zvknha, PRIV_VERSION_1_12_0, ext_zvknha), | ||
75 | ISA_EXT_DATA_ENTRY(zvknhb, PRIV_VERSION_1_12_0, ext_zvknhb), | ||
76 | + ISA_EXT_DATA_ENTRY(zvksed, PRIV_VERSION_1_12_0, ext_zvksed), | ||
77 | ISA_EXT_DATA_ENTRY(zvksh, PRIV_VERSION_1_12_0, ext_zvksh), | ||
78 | ISA_EXT_DATA_ENTRY(zhinx, PRIV_VERSION_1_12_0, ext_zhinx), | ||
79 | ISA_EXT_DATA_ENTRY(zhinxmin, PRIV_VERSION_1_12_0, ext_zhinxmin), | ||
80 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
81 | * in qemu | ||
82 | */ | ||
83 | if ((cpu->cfg.ext_zvbb || cpu->cfg.ext_zvkg || cpu->cfg.ext_zvkned || | ||
84 | - cpu->cfg.ext_zvknha || cpu->cfg.ext_zvksh) && !cpu->cfg.ext_zve32f) { | ||
85 | + cpu->cfg.ext_zvknha || cpu->cfg.ext_zvksed || cpu->cfg.ext_zvksh) && | ||
86 | + !cpu->cfg.ext_zve32f) { | ||
87 | error_setg(errp, | ||
88 | "Vector crypto extensions require V or Zve* extensions"); | ||
89 | return; | ||
90 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = { | ||
91 | DEFINE_PROP_BOOL("x-zvkned", RISCVCPU, cfg.ext_zvkned, false), | ||
92 | DEFINE_PROP_BOOL("x-zvknha", RISCVCPU, cfg.ext_zvknha, false), | ||
93 | DEFINE_PROP_BOOL("x-zvknhb", RISCVCPU, cfg.ext_zvknhb, false), | ||
94 | + DEFINE_PROP_BOOL("x-zvksed", RISCVCPU, cfg.ext_zvksed, false), | ||
95 | DEFINE_PROP_BOOL("x-zvksh", RISCVCPU, cfg.ext_zvksh, false), | ||
96 | |||
97 | DEFINE_PROP_END_OF_LIST(), | ||
98 | diff --git a/target/riscv/vcrypto_helper.c b/target/riscv/vcrypto_helper.c | ||
99 | index XXXXXXX..XXXXXXX 100644 | ||
100 | --- a/target/riscv/vcrypto_helper.c | ||
101 | +++ b/target/riscv/vcrypto_helper.c | ||
102 | @@ -XXX,XX +XXX,XX @@ | ||
103 | #include "cpu.h" | ||
104 | #include "crypto/aes.h" | ||
105 | #include "crypto/aes-round.h" | ||
106 | +#include "crypto/sm4.h" | ||
107 | #include "exec/memop.h" | ||
108 | #include "exec/exec-all.h" | ||
109 | #include "exec/helper-proto.h" | ||
110 | @@ -XXX,XX +XXX,XX @@ void HELPER(vgmul_vv)(void *vd_vptr, void *vs2_vptr, CPURISCVState *env, | ||
111 | vext_set_elems_1s(vd, vta, env->vl * 4, total_elems * 4); | ||
112 | env->vstart = 0; | ||
113 | } | ||
114 | + | ||
115 | +void HELPER(vsm4k_vi)(void *vd, void *vs2, uint32_t uimm5, CPURISCVState *env, | ||
116 | + uint32_t desc) | ||
117 | +{ | ||
118 | + const uint32_t egs = 4; | ||
119 | + uint32_t rnd = uimm5 & 0x7; | ||
120 | + uint32_t group_start = env->vstart / egs; | ||
121 | + uint32_t group_end = env->vl / egs; | ||
122 | + uint32_t esz = sizeof(uint32_t); | ||
123 | + uint32_t total_elems = vext_get_total_elems(env, desc, esz); | ||
124 | + | ||
125 | + for (uint32_t i = group_start; i < group_end; ++i) { | ||
126 | + uint32_t vstart = i * egs; | ||
127 | + uint32_t vend = (i + 1) * egs; | ||
128 | + uint32_t rk[4] = {0}; | ||
129 | + uint32_t tmp[8] = {0}; | ||
130 | + | ||
131 | + for (uint32_t j = vstart; j < vend; ++j) { | ||
132 | + rk[j - vstart] = *((uint32_t *)vs2 + H4(j)); | ||
133 | + } | ||
134 | + | ||
135 | + for (uint32_t j = 0; j < egs; ++j) { | ||
136 | + tmp[j] = rk[j]; | ||
137 | + } | ||
138 | + | ||
139 | + for (uint32_t j = 0; j < egs; ++j) { | ||
140 | + uint32_t b, s; | ||
141 | + b = tmp[j + 1] ^ tmp[j + 2] ^ tmp[j + 3] ^ sm4_ck[rnd * 4 + j]; | ||
142 | + | ||
143 | + s = sm4_subword(b); | ||
144 | + | ||
145 | + tmp[j + 4] = tmp[j] ^ (s ^ rol32(s, 13) ^ rol32(s, 23)); | ||
146 | + } | ||
147 | + | ||
148 | + for (uint32_t j = vstart; j < vend; ++j) { | ||
149 | + *((uint32_t *)vd + H4(j)) = tmp[egs + (j - vstart)]; | ||
150 | + } | ||
151 | + } | ||
152 | + | ||
153 | + env->vstart = 0; | ||
154 | + /* set tail elements to 1s */ | ||
155 | + vext_set_elems_1s(vd, vext_vta(desc), env->vl * esz, total_elems * esz); | ||
156 | +} | ||
157 | + | ||
158 | +static void do_sm4_round(uint32_t *rk, uint32_t *buf) | ||
159 | +{ | ||
160 | + const uint32_t egs = 4; | ||
161 | + uint32_t s, b; | ||
162 | + | ||
163 | + for (uint32_t j = egs; j < egs * 2; ++j) { | ||
164 | + b = buf[j - 3] ^ buf[j - 2] ^ buf[j - 1] ^ rk[j - 4]; | ||
165 | + | ||
166 | + s = sm4_subword(b); | ||
167 | + | ||
168 | + buf[j] = buf[j - 4] ^ (s ^ rol32(s, 2) ^ rol32(s, 10) ^ rol32(s, 18) ^ | ||
169 | + rol32(s, 24)); | ||
170 | + } | ||
171 | +} | ||
172 | + | ||
173 | +void HELPER(vsm4r_vv)(void *vd, void *vs2, CPURISCVState *env, uint32_t desc) | ||
174 | +{ | ||
175 | + const uint32_t egs = 4; | ||
176 | + uint32_t group_start = env->vstart / egs; | ||
177 | + uint32_t group_end = env->vl / egs; | ||
178 | + uint32_t esz = sizeof(uint32_t); | ||
179 | + uint32_t total_elems = vext_get_total_elems(env, desc, esz); | ||
180 | + | ||
181 | + for (uint32_t i = group_start; i < group_end; ++i) { | ||
182 | + uint32_t vstart = i * egs; | ||
183 | + uint32_t vend = (i + 1) * egs; | ||
184 | + uint32_t rk[4] = {0}; | ||
185 | + uint32_t tmp[8] = {0}; | ||
186 | + | ||
187 | + for (uint32_t j = vstart; j < vend; ++j) { | ||
188 | + rk[j - vstart] = *((uint32_t *)vs2 + H4(j)); | ||
189 | + } | ||
190 | + | ||
191 | + for (uint32_t j = vstart; j < vend; ++j) { | ||
192 | + tmp[j - vstart] = *((uint32_t *)vd + H4(j)); | ||
193 | + } | ||
194 | + | ||
195 | + do_sm4_round(rk, tmp); | ||
196 | + | ||
197 | + for (uint32_t j = vstart; j < vend; ++j) { | ||
198 | + *((uint32_t *)vd + H4(j)) = tmp[egs + (j - vstart)]; | ||
199 | + } | ||
200 | + } | ||
201 | + | ||
202 | + env->vstart = 0; | ||
203 | + /* set tail elements to 1s */ | ||
204 | + vext_set_elems_1s(vd, vext_vta(desc), env->vl * esz, total_elems * esz); | ||
205 | +} | ||
206 | + | ||
207 | +void HELPER(vsm4r_vs)(void *vd, void *vs2, CPURISCVState *env, uint32_t desc) | ||
208 | +{ | ||
209 | + const uint32_t egs = 4; | ||
210 | + uint32_t group_start = env->vstart / egs; | ||
211 | + uint32_t group_end = env->vl / egs; | ||
212 | + uint32_t esz = sizeof(uint32_t); | ||
213 | + uint32_t total_elems = vext_get_total_elems(env, desc, esz); | ||
214 | + | ||
215 | + for (uint32_t i = group_start; i < group_end; ++i) { | ||
216 | + uint32_t vstart = i * egs; | ||
217 | + uint32_t vend = (i + 1) * egs; | ||
218 | + uint32_t rk[4] = {0}; | ||
219 | + uint32_t tmp[8] = {0}; | ||
220 | + | ||
221 | + for (uint32_t j = 0; j < egs; ++j) { | ||
222 | + rk[j] = *((uint32_t *)vs2 + H4(j)); | ||
223 | + } | ||
224 | + | ||
225 | + for (uint32_t j = vstart; j < vend; ++j) { | ||
226 | + tmp[j - vstart] = *((uint32_t *)vd + H4(j)); | ||
227 | + } | ||
228 | + | ||
229 | + do_sm4_round(rk, tmp); | ||
230 | + | ||
231 | + for (uint32_t j = vstart; j < vend; ++j) { | ||
232 | + *((uint32_t *)vd + H4(j)) = tmp[egs + (j - vstart)]; | ||
233 | + } | ||
234 | + } | ||
235 | + | ||
236 | + env->vstart = 0; | ||
237 | + /* set tail elements to 1s */ | ||
238 | + vext_set_elems_1s(vd, vext_vta(desc), env->vl * esz, total_elems * esz); | ||
239 | +} | ||
240 | diff --git a/target/riscv/insn_trans/trans_rvvk.c.inc b/target/riscv/insn_trans/trans_rvvk.c.inc | ||
241 | index XXXXXXX..XXXXXXX 100644 | ||
242 | --- a/target/riscv/insn_trans/trans_rvvk.c.inc | ||
243 | +++ b/target/riscv/insn_trans/trans_rvvk.c.inc | ||
244 | @@ -XXX,XX +XXX,XX @@ static bool vghsh_check(DisasContext *s, arg_rmrr *a) | ||
245 | } | ||
246 | |||
247 | GEN_VV_UNMASKED_TRANS(vghsh_vv, vghsh_check, ZVKG_EGS) | ||
248 | + | ||
249 | +/* | ||
250 | + * Zvksed | ||
251 | + */ | ||
252 | + | ||
253 | +#define ZVKSED_EGS 4 | ||
254 | + | ||
255 | +static bool zvksed_check(DisasContext *s) | ||
256 | +{ | ||
257 | + int egw_bytes = ZVKSED_EGS << s->sew; | ||
258 | + return s->cfg_ptr->ext_zvksed == true && | ||
259 | + require_rvv(s) && | ||
260 | + vext_check_isa_ill(s) && | ||
261 | + MAXSZ(s) >= egw_bytes && | ||
262 | + s->sew == MO_32; | ||
263 | +} | ||
264 | + | ||
265 | +static bool vsm4k_vi_check(DisasContext *s, arg_rmrr *a) | ||
266 | +{ | ||
267 | + return zvksed_check(s) && | ||
268 | + require_align(a->rd, s->lmul) && | ||
269 | + require_align(a->rs2, s->lmul); | ||
270 | +} | ||
271 | + | ||
272 | +GEN_VI_UNMASKED_TRANS(vsm4k_vi, vsm4k_vi_check, ZVKSED_EGS) | ||
273 | + | ||
274 | +static bool vsm4r_vv_check(DisasContext *s, arg_rmr *a) | ||
275 | +{ | ||
276 | + return zvksed_check(s) && | ||
277 | + require_align(a->rd, s->lmul) && | ||
278 | + require_align(a->rs2, s->lmul); | ||
279 | +} | ||
280 | + | ||
281 | +GEN_V_UNMASKED_TRANS(vsm4r_vv, vsm4r_vv_check, ZVKSED_EGS) | ||
282 | + | ||
283 | +static bool vsm4r_vs_check(DisasContext *s, arg_rmr *a) | ||
284 | +{ | ||
285 | + return zvksed_check(s) && | ||
286 | + !is_overlapped(a->rd, 1 << MAX(s->lmul, 0), a->rs2, 1) && | ||
287 | + require_align(a->rd, s->lmul); | ||
288 | +} | ||
289 | + | ||
290 | +GEN_V_UNMASKED_TRANS(vsm4r_vs, vsm4r_vs_check, ZVKSED_EGS) | ||
291 | -- | ||
292 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Irina Ryapolova <irina.ryapolova@syntacore.com> | 1 | From: Rob Bradford <rbradford@rivosinc.com> |
---|---|---|---|
2 | 2 | ||
3 | Added xATP_MODE validation for vsatp/hgatp CSRs. | 3 | These are WARL fields - zero out the bits for unavailable counters and |
4 | The xATP register is an SXLEN-bit read/write WARL register, so | 4 | special case the TM bit in mcountinhibit which is hardwired to zero. |
5 | the legal value must be returned (See riscv-privileged-20211203, SATP/VSATP/HGATP CSRs). | 5 | This patch achieves this by modifying the value written so that any use |
6 | of the field will see the correctly masked bits. | ||
6 | 7 | ||
7 | Signed-off-by: Irina Ryapolova <irina.ryapolova@syntacore.com> | 8 | Tested by modifying OpenSBI to write max value to these CSRs and upon |
8 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 9 | subsequent read the appropriate number of bits for number of PMUs is |
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 10 | enabled and the TM bit is zero in mcountinhibit. |
10 | Message-ID: <20240109145923.37893-2-irina.ryapolova@syntacore.com> | 11 | |
12 | Signed-off-by: Rob Bradford <rbradford@rivosinc.com> | ||
13 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
14 | Reviewed-by: Atish Patra <atishp@rivosinc.com> | ||
15 | Message-ID: <20230802124906.24197-1-rbradford@rivosinc.com> | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 17 | --- |
13 | target/riscv/csr.c | 52 ++++++++++++++++++++++++++-------------------- | 18 | target/riscv/csr.c | 11 +++++++++-- |
14 | 1 file changed, 29 insertions(+), 23 deletions(-) | 19 | 1 file changed, 9 insertions(+), 2 deletions(-) |
15 | 20 | ||
16 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 21 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
17 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/riscv/csr.c | 23 | --- a/target/riscv/csr.c |
19 | +++ b/target/riscv/csr.c | 24 | +++ b/target/riscv/csr.c |
20 | @@ -XXX,XX +XXX,XX @@ static bool validate_vm(CPURISCVState *env, target_ulong vm) | 25 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_mcountinhibit(CPURISCVState *env, int csrno, |
21 | return get_field(mode_supported, (1 << vm)); | 26 | { |
22 | } | 27 | int cidx; |
23 | 28 | PMUCTRState *counter; | |
24 | +static target_ulong legalize_xatp(CPURISCVState *env, target_ulong old_xatp, | 29 | + RISCVCPU *cpu = env_archcpu(env); |
25 | + target_ulong val) | 30 | |
26 | +{ | 31 | - env->mcountinhibit = val; |
27 | + target_ulong mask; | 32 | + /* WARL register - disable unavailable counters; TM bit is always 0 */ |
28 | + bool vm; | 33 | + env->mcountinhibit = |
29 | + if (riscv_cpu_mxl(env) == MXL_RV32) { | 34 | + val & (cpu->pmu_avail_ctrs | COUNTEREN_CY | COUNTEREN_IR); |
30 | + vm = validate_vm(env, get_field(val, SATP32_MODE)); | 35 | |
31 | + mask = (val ^ old_xatp) & (SATP32_MODE | SATP32_ASID | SATP32_PPN); | 36 | /* Check if any other counter is also monitoring cycles/instructions */ |
32 | + } else { | 37 | for (cidx = 0; cidx < RV_MAX_MHPMCOUNTERS; cidx++) { |
33 | + vm = validate_vm(env, get_field(val, SATP64_MODE)); | 38 | @@ -XXX,XX +XXX,XX @@ static RISCVException read_mcounteren(CPURISCVState *env, int csrno, |
34 | + mask = (val ^ old_xatp) & (SATP64_MODE | SATP64_ASID | SATP64_PPN); | 39 | static RISCVException write_mcounteren(CPURISCVState *env, int csrno, |
35 | + } | 40 | target_ulong val) |
41 | { | ||
42 | - env->mcounteren = val; | ||
43 | + RISCVCPU *cpu = env_archcpu(env); | ||
36 | + | 44 | + |
37 | + if (vm && mask) { | 45 | + /* WARL register - disable unavailable counters */ |
38 | + /* | 46 | + env->mcounteren = val & (cpu->pmu_avail_ctrs | COUNTEREN_CY | COUNTEREN_TM | |
39 | + * The ISA defines SATP.MODE=Bare as "no translation", but we still | 47 | + COUNTEREN_IR); |
40 | + * pass these through QEMU's TLB emulation as it improves | ||
41 | + * performance. Flushing the TLB on SATP writes with paging | ||
42 | + * enabled avoids leaking those invalid cached mappings. | ||
43 | + */ | ||
44 | + tlb_flush(env_cpu(env)); | ||
45 | + return val; | ||
46 | + } | ||
47 | + return old_xatp; | ||
48 | +} | ||
49 | + | ||
50 | static target_ulong legalize_mpp(CPURISCVState *env, target_ulong old_mpp, | ||
51 | target_ulong val) | ||
52 | { | ||
53 | @@ -XXX,XX +XXX,XX @@ static RISCVException read_satp(CPURISCVState *env, int csrno, | ||
54 | static RISCVException write_satp(CPURISCVState *env, int csrno, | ||
55 | target_ulong val) | ||
56 | { | ||
57 | - target_ulong mask; | ||
58 | - bool vm; | ||
59 | - | ||
60 | if (!riscv_cpu_cfg(env)->mmu) { | ||
61 | return RISCV_EXCP_NONE; | ||
62 | } | ||
63 | |||
64 | - if (riscv_cpu_mxl(env) == MXL_RV32) { | ||
65 | - vm = validate_vm(env, get_field(val, SATP32_MODE)); | ||
66 | - mask = (val ^ env->satp) & (SATP32_MODE | SATP32_ASID | SATP32_PPN); | ||
67 | - } else { | ||
68 | - vm = validate_vm(env, get_field(val, SATP64_MODE)); | ||
69 | - mask = (val ^ env->satp) & (SATP64_MODE | SATP64_ASID | SATP64_PPN); | ||
70 | - } | ||
71 | - | ||
72 | - if (vm && mask) { | ||
73 | - /* | ||
74 | - * The ISA defines SATP.MODE=Bare as "no translation", but we still | ||
75 | - * pass these through QEMU's TLB emulation as it improves | ||
76 | - * performance. Flushing the TLB on SATP writes with paging | ||
77 | - * enabled avoids leaking those invalid cached mappings. | ||
78 | - */ | ||
79 | - tlb_flush(env_cpu(env)); | ||
80 | - env->satp = val; | ||
81 | - } | ||
82 | + env->satp = legalize_xatp(env, env->satp, val); | ||
83 | return RISCV_EXCP_NONE; | 48 | return RISCV_EXCP_NONE; |
84 | } | 49 | } |
85 | 50 | ||
86 | @@ -XXX,XX +XXX,XX @@ static RISCVException read_hgatp(CPURISCVState *env, int csrno, | ||
87 | static RISCVException write_hgatp(CPURISCVState *env, int csrno, | ||
88 | target_ulong val) | ||
89 | { | ||
90 | - env->hgatp = val; | ||
91 | + env->hgatp = legalize_xatp(env, env->hgatp, val); | ||
92 | return RISCV_EXCP_NONE; | ||
93 | } | ||
94 | |||
95 | @@ -XXX,XX +XXX,XX @@ static RISCVException read_vsatp(CPURISCVState *env, int csrno, | ||
96 | static RISCVException write_vsatp(CPURISCVState *env, int csrno, | ||
97 | target_ulong val) | ||
98 | { | ||
99 | - env->vsatp = val; | ||
100 | + env->vsatp = legalize_xatp(env, env->vsatp, val); | ||
101 | return RISCV_EXCP_NONE; | ||
102 | } | ||
103 | |||
104 | -- | 51 | -- |
105 | 2.44.0 | 52 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Jason Chien <jason.chien@sifive.com> | ||
1 | 2 | ||
3 | RVA23 Profiles states: | ||
4 | The RVA23 profiles are intended to be used for 64-bit application | ||
5 | processors that will run rich OS stacks from standard binary OS | ||
6 | distributions and with a substantial number of third-party binary user | ||
7 | applications that will be supported over a considerable length of time | ||
8 | in the field. | ||
9 | |||
10 | The chapter 4 of the unprivileged spec introduces the Zihintntl extension | ||
11 | and Zihintntl is a mandatory extension presented in RVA23 Profiles, whose | ||
12 | purpose is to enable application and operating system portability across | ||
13 | different implementations. Thus the DTS should contain the Zihintntl ISA | ||
14 | string in order to pass to software. | ||
15 | |||
16 | The unprivileged spec states: | ||
17 | Like any HINTs, these instructions may be freely ignored. Hence, although | ||
18 | they are described in terms of cache-based memory hierarchies, they do not | ||
19 | mandate the provision of caches. | ||
20 | |||
21 | These instructions are encoded with non-used opcode, e.g. ADD x0, x0, x2, | ||
22 | which QEMU already supports, and QEMU does not emulate cache. Therefore | ||
23 | these instructions can be considered as a no-op, and we only need to add | ||
24 | a new property for the Zihintntl extension. | ||
25 | |||
26 | Reviewed-by: Frank Chang <frank.chang@sifive.com> | ||
27 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
28 | Signed-off-by: Jason Chien <jason.chien@sifive.com> | ||
29 | Message-ID: <20230726074049.19505-2-jason.chien@sifive.com> | ||
30 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
31 | --- | ||
32 | target/riscv/cpu_cfg.h | 1 + | ||
33 | target/riscv/cpu.c | 2 ++ | ||
34 | 2 files changed, 3 insertions(+) | ||
35 | |||
36 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/target/riscv/cpu_cfg.h | ||
39 | +++ b/target/riscv/cpu_cfg.h | ||
40 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { | ||
41 | bool ext_icbom; | ||
42 | bool ext_icboz; | ||
43 | bool ext_zicond; | ||
44 | + bool ext_zihintntl; | ||
45 | bool ext_zihintpause; | ||
46 | bool ext_smstateen; | ||
47 | bool ext_sstc; | ||
48 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
49 | index XXXXXXX..XXXXXXX 100644 | ||
50 | --- a/target/riscv/cpu.c | ||
51 | +++ b/target/riscv/cpu.c | ||
52 | @@ -XXX,XX +XXX,XX @@ static const struct isa_ext_data isa_edata_arr[] = { | ||
53 | ISA_EXT_DATA_ENTRY(zicond, PRIV_VERSION_1_12_0, ext_zicond), | ||
54 | ISA_EXT_DATA_ENTRY(zicsr, PRIV_VERSION_1_10_0, ext_icsr), | ||
55 | ISA_EXT_DATA_ENTRY(zifencei, PRIV_VERSION_1_10_0, ext_ifencei), | ||
56 | + ISA_EXT_DATA_ENTRY(zihintntl, PRIV_VERSION_1_10_0, ext_zihintntl), | ||
57 | ISA_EXT_DATA_ENTRY(zihintpause, PRIV_VERSION_1_10_0, ext_zihintpause), | ||
58 | ISA_EXT_DATA_ENTRY(zmmul, PRIV_VERSION_1_12_0, ext_zmmul), | ||
59 | ISA_EXT_DATA_ENTRY(zawrs, PRIV_VERSION_1_12_0, ext_zawrs), | ||
60 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = { | ||
61 | DEFINE_PROP_BOOL("sscofpmf", RISCVCPU, cfg.ext_sscofpmf, false), | ||
62 | DEFINE_PROP_BOOL("Zifencei", RISCVCPU, cfg.ext_ifencei, true), | ||
63 | DEFINE_PROP_BOOL("Zicsr", RISCVCPU, cfg.ext_icsr, true), | ||
64 | + DEFINE_PROP_BOOL("Zihintntl", RISCVCPU, cfg.ext_zihintntl, true), | ||
65 | DEFINE_PROP_BOOL("Zihintpause", RISCVCPU, cfg.ext_zihintpause, true), | ||
66 | DEFINE_PROP_BOOL("Zawrs", RISCVCPU, cfg.ext_zawrs, true), | ||
67 | DEFINE_PROP_BOOL("Zfa", RISCVCPU, cfg.ext_zfa, true), | ||
68 | -- | ||
69 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
1 | 2 | ||
3 | Commit a47842d ("riscv: Add support for the Zfa extension") implemented the zfa extension. | ||
4 | However, it has some typos for fleq.d and fltq.d. Both of them misused the fltq.s | ||
5 | helper function. | ||
6 | |||
7 | Fixes: a47842d ("riscv: Add support for the Zfa extension") | ||
8 | Signed-off-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
9 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
10 | Reviewed-by: Weiwei Li <liweiwei@iscas.ac.cn> | ||
11 | Message-ID: <20230728003906.768-1-zhiwei_liu@linux.alibaba.com> | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | --- | ||
14 | target/riscv/insn_trans/trans_rvzfa.c.inc | 4 ++-- | ||
15 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
16 | |||
17 | diff --git a/target/riscv/insn_trans/trans_rvzfa.c.inc b/target/riscv/insn_trans/trans_rvzfa.c.inc | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/target/riscv/insn_trans/trans_rvzfa.c.inc | ||
20 | +++ b/target/riscv/insn_trans/trans_rvzfa.c.inc | ||
21 | @@ -XXX,XX +XXX,XX @@ bool trans_fleq_d(DisasContext *ctx, arg_fleq_d *a) | ||
22 | TCGv_i64 src1 = get_fpr_hs(ctx, a->rs1); | ||
23 | TCGv_i64 src2 = get_fpr_hs(ctx, a->rs2); | ||
24 | |||
25 | - gen_helper_fltq_s(dest, cpu_env, src1, src2); | ||
26 | + gen_helper_fleq_d(dest, cpu_env, src1, src2); | ||
27 | gen_set_gpr(ctx, a->rd, dest); | ||
28 | return true; | ||
29 | } | ||
30 | @@ -XXX,XX +XXX,XX @@ bool trans_fltq_d(DisasContext *ctx, arg_fltq_d *a) | ||
31 | TCGv_i64 src1 = get_fpr_hs(ctx, a->rs1); | ||
32 | TCGv_i64 src2 = get_fpr_hs(ctx, a->rs2); | ||
33 | |||
34 | - gen_helper_fltq_s(dest, cpu_env, src1, src2); | ||
35 | + gen_helper_fltq_d(dest, cpu_env, src1, src2); | ||
36 | gen_set_gpr(ctx, a->rd, dest); | ||
37 | return true; | ||
38 | } | ||
39 | -- | ||
40 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Jason Chien <jason.chien@sifive.com> | ||
1 | 2 | ||
3 | When writing the upper mtime, we should keep the original lower mtime | ||
4 | whose value is given by cpu_riscv_read_rtc() instead of | ||
5 | cpu_riscv_read_rtc_raw(). The same logic applies to writes to lower mtime. | ||
6 | |||
7 | Signed-off-by: Jason Chien <jason.chien@sifive.com> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | Message-ID: <20230728082502.26439-1-jason.chien@sifive.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | --- | ||
12 | hw/intc/riscv_aclint.c | 5 +++-- | ||
13 | 1 file changed, 3 insertions(+), 2 deletions(-) | ||
14 | |||
15 | diff --git a/hw/intc/riscv_aclint.c b/hw/intc/riscv_aclint.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/hw/intc/riscv_aclint.c | ||
18 | +++ b/hw/intc/riscv_aclint.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static void riscv_aclint_mtimer_write(void *opaque, hwaddr addr, | ||
20 | return; | ||
21 | } else if (addr == mtimer->time_base || addr == mtimer->time_base + 4) { | ||
22 | uint64_t rtc_r = cpu_riscv_read_rtc_raw(mtimer->timebase_freq); | ||
23 | + uint64_t rtc = cpu_riscv_read_rtc(mtimer); | ||
24 | |||
25 | if (addr == mtimer->time_base) { | ||
26 | if (size == 4) { | ||
27 | /* time_lo for RV32/RV64 */ | ||
28 | - mtimer->time_delta = ((rtc_r & ~0xFFFFFFFFULL) | value) - rtc_r; | ||
29 | + mtimer->time_delta = ((rtc & ~0xFFFFFFFFULL) | value) - rtc_r; | ||
30 | } else { | ||
31 | /* time for RV64 */ | ||
32 | mtimer->time_delta = value - rtc_r; | ||
33 | @@ -XXX,XX +XXX,XX @@ static void riscv_aclint_mtimer_write(void *opaque, hwaddr addr, | ||
34 | } else { | ||
35 | if (size == 4) { | ||
36 | /* time_hi for RV32/RV64 */ | ||
37 | - mtimer->time_delta = (value << 32 | (rtc_r & 0xFFFFFFFF)) - rtc_r; | ||
38 | + mtimer->time_delta = (value << 32 | (rtc & 0xFFFFFFFF)) - rtc_r; | ||
39 | } else { | ||
40 | qemu_log_mask(LOG_GUEST_ERROR, | ||
41 | "aclint-mtimer: invalid time_hi write: %08x", | ||
42 | -- | ||
43 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Jason Chien <jason.chien@sifive.com> | 1 | From: Jason Chien <jason.chien@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | The original implementation sets $pc to the address read from the jump | 3 | The variables whose values are given by cpu_riscv_read_rtc() should be named |
4 | vector table first and links $ra with the address of the next instruction | 4 | "rtc". The variables whose value are given by cpu_riscv_read_rtc_raw() |
5 | after the updated $pc. After jumping to the updated $pc and executing the | 5 | should be named "rtc_r". |
6 | next ret instruction, the program jumps to $ra, which is in the same | ||
7 | function currently executing, which results in an infinite loop. | ||
8 | This commit stores the jump address in a temporary, updates $ra with the | ||
9 | current $pc, and copies the temporary to $pc. | ||
10 | 6 | ||
11 | Signed-off-by: Jason Chien <jason.chien@sifive.com> | 7 | Signed-off-by: Jason Chien <jason.chien@sifive.com> |
12 | Reviewed-by: Frank Chang <frank.chang@sifive.com> | 8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
13 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 9 | Message-ID: <20230728082502.26439-2-jason.chien@sifive.com> |
14 | Message-ID: <20240207081820.28559-1-jason.chien@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/insn_trans/trans_rvzce.c.inc | 6 +++++- | 12 | hw/intc/riscv_aclint.c | 6 +++--- |
18 | 1 file changed, 5 insertions(+), 1 deletion(-) | 13 | 1 file changed, 3 insertions(+), 3 deletions(-) |
19 | 14 | ||
20 | diff --git a/target/riscv/insn_trans/trans_rvzce.c.inc b/target/riscv/insn_trans/trans_rvzce.c.inc | 15 | diff --git a/hw/intc/riscv_aclint.c b/hw/intc/riscv_aclint.c |
21 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/target/riscv/insn_trans/trans_rvzce.c.inc | 17 | --- a/hw/intc/riscv_aclint.c |
23 | +++ b/target/riscv/insn_trans/trans_rvzce.c.inc | 18 | +++ b/hw/intc/riscv_aclint.c |
24 | @@ -XXX,XX +XXX,XX @@ static bool trans_cm_jalt(DisasContext *ctx, arg_cm_jalt *a) | 19 | @@ -XXX,XX +XXX,XX @@ static void riscv_aclint_mtimer_write_timecmp(RISCVAclintMTimerState *mtimer, |
25 | { | 20 | uint64_t next; |
26 | REQUIRE_ZCMT(ctx); | 21 | uint64_t diff; |
27 | 22 | ||
28 | + TCGv addr = tcg_temp_new(); | 23 | - uint64_t rtc_r = cpu_riscv_read_rtc(mtimer); |
29 | + | 24 | + uint64_t rtc = cpu_riscv_read_rtc(mtimer); |
30 | /* | 25 | |
31 | * Update pc to current for the non-unwinding exception | 26 | /* Compute the relative hartid w.r.t the socket */ |
32 | * that might come from cpu_ld*_code() in the helper. | 27 | hartid = hartid - mtimer->hartid_base; |
33 | */ | 28 | |
34 | gen_update_pc(ctx, 0); | 29 | mtimer->timecmp[hartid] = value; |
35 | - gen_helper_cm_jalt(cpu_pc, tcg_env, tcg_constant_i32(a->index)); | 30 | - if (mtimer->timecmp[hartid] <= rtc_r) { |
36 | + gen_helper_cm_jalt(addr, tcg_env, tcg_constant_i32(a->index)); | 31 | + if (mtimer->timecmp[hartid] <= rtc) { |
37 | 32 | /* | |
38 | /* c.jt vs c.jalt depends on the index. */ | 33 | * If we're setting an MTIMECMP value in the "past", |
39 | if (a->index >= 32) { | 34 | * immediately raise the timer interrupt |
40 | @@ -XXX,XX +XXX,XX @@ static bool trans_cm_jalt(DisasContext *ctx, arg_cm_jalt *a) | 35 | @@ -XXX,XX +XXX,XX @@ static void riscv_aclint_mtimer_write_timecmp(RISCVAclintMTimerState *mtimer, |
41 | gen_set_gpr(ctx, xRA, succ_pc); | 36 | |
42 | } | 37 | /* otherwise, set up the future timer interrupt */ |
43 | 38 | qemu_irq_lower(mtimer->timer_irqs[hartid]); | |
44 | + tcg_gen_mov_tl(cpu_pc, addr); | 39 | - diff = mtimer->timecmp[hartid] - rtc_r; |
45 | + | 40 | + diff = mtimer->timecmp[hartid] - rtc; |
46 | tcg_gen_lookup_and_goto_ptr(); | 41 | /* back to ns (note args switched in muldiv64) */ |
47 | ctx->base.is_jmp = DISAS_NORETURN; | 42 | uint64_t ns_diff = muldiv64(diff, NANOSECONDS_PER_SECOND, timebase_freq); |
48 | return true; | 43 | |
49 | -- | 44 | -- |
50 | 2.44.0 | 45 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Ilya Chugin <danger_mail@list.ru> | 1 | From: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
---|---|---|---|
2 | 2 | ||
3 | MCFG segments should point to PCI configuration range, not BAR MMIO. | 3 | We should not use types dependend on host arch for target_ucontext. |
4 | This bug is found when run rv32 applications. | ||
4 | 5 | ||
5 | Signed-off-by: Ilya Chugin <danger_mail@list.ru> | 6 | Signed-off-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
6 | Fixes: 55ecd83b36 ("hw/riscv/virt-acpi-build.c: Add IO controllers and devices") | 7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 9 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
8 | Reviewed-by: Sunil V L <sunilvl@ventanamicro.com> | 10 | Message-ID: <20230811055438.1945-1-zhiwei_liu@linux.alibaba.com> |
9 | Message-ID: <180d236d-c8e4-411a-b4d2-632eb82092fa@list.ru> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 12 | --- |
12 | hw/riscv/virt-acpi-build.c | 4 ++-- | 13 | linux-user/riscv/signal.c | 4 ++-- |
13 | 1 file changed, 2 insertions(+), 2 deletions(-) | 14 | 1 file changed, 2 insertions(+), 2 deletions(-) |
14 | 15 | ||
15 | diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c | 16 | diff --git a/linux-user/riscv/signal.c b/linux-user/riscv/signal.c |
16 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/hw/riscv/virt-acpi-build.c | 18 | --- a/linux-user/riscv/signal.c |
18 | +++ b/hw/riscv/virt-acpi-build.c | 19 | +++ b/linux-user/riscv/signal.c |
19 | @@ -XXX,XX +XXX,XX @@ static void virt_acpi_build(RISCVVirtState *s, AcpiBuildTables *tables) | 20 | @@ -XXX,XX +XXX,XX @@ struct target_sigcontext { |
20 | acpi_add_table(table_offsets, tables_blob); | 21 | }; /* cf. riscv-linux:arch/riscv/include/uapi/asm/ptrace.h */ |
21 | { | 22 | |
22 | AcpiMcfgInfo mcfg = { | 23 | struct target_ucontext { |
23 | - .base = s->memmap[VIRT_PCIE_MMIO].base, | 24 | - unsigned long uc_flags; |
24 | - .size = s->memmap[VIRT_PCIE_MMIO].size, | 25 | - struct target_ucontext *uc_link; |
25 | + .base = s->memmap[VIRT_PCIE_ECAM].base, | 26 | + abi_ulong uc_flags; |
26 | + .size = s->memmap[VIRT_PCIE_ECAM].size, | 27 | + abi_ptr uc_link; |
27 | }; | 28 | target_stack_t uc_stack; |
28 | build_mcfg(tables_blob, tables->linker, &mcfg, s->oem_id, | 29 | target_sigset_t uc_sigmask; |
29 | s->oem_table_id); | 30 | uint8_t __unused[1024 / 8 - sizeof(target_sigset_t)]; |
30 | -- | 31 | -- |
31 | 2.44.0 | 32 | 2.41.0 |
32 | 33 | ||
33 | 34 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Yong-Xuan Wang <yongxuan.wang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | We want to add a RISC-V 'virt' libqos machine to increase our test | 3 | In this patch, we create the APLIC and IMSIC FDT helper functions and |
4 | coverage. Some of the tests will try to plug a virtio-iommu-pci | 4 | remove M mode AIA devices when using KVM acceleration. |
5 | device into the board and do some tests with it. | ||
6 | 5 | ||
7 | Enable virtio-iommu-pci in the 'virt' machine. | 6 | Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com> |
8 | 7 | Reviewed-by: Jim Shu <jim.shu@sifive.com> | |
9 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 8 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
10 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> |
11 | Message-ID: <20240217192607.32565-5-dbarboza@ventanamicro.com> | 10 | Message-ID: <20230727102439.22554-2-yongxuan.wang@sifive.com> |
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | --- | 12 | --- |
14 | hw/riscv/virt.c | 36 +++++++++++++++++++++++++++++++++++- | 13 | hw/riscv/virt.c | 290 +++++++++++++++++++++++------------------------- |
15 | 1 file changed, 35 insertions(+), 1 deletion(-) | 14 | 1 file changed, 137 insertions(+), 153 deletions(-) |
16 | 15 | ||
17 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | 16 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c |
18 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/hw/riscv/virt.c | 18 | --- a/hw/riscv/virt.c |
20 | +++ b/hw/riscv/virt.c | 19 | +++ b/hw/riscv/virt.c |
21 | @@ -XXX,XX +XXX,XX @@ | 20 | @@ -XXX,XX +XXX,XX @@ static uint32_t imsic_num_bits(uint32_t count) |
22 | #include "hw/display/ramfb.h" | 21 | return ret; |
23 | #include "hw/acpi/aml-build.h" | ||
24 | #include "qapi/qapi-visit-common.h" | ||
25 | +#include "hw/virtio/virtio-iommu.h" | ||
26 | |||
27 | /* KVM AIA only supports APLIC MSI. APLIC Wired is always emulated by QEMU. */ | ||
28 | static bool virt_use_kvm_aia(RISCVVirtState *s) | ||
29 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_fw_cfg(RISCVVirtState *s, const MemMapEntry *memmap) | ||
30 | qemu_fdt_setprop(ms->fdt, nodename, "dma-coherent", NULL, 0); | ||
31 | } | 22 | } |
32 | 23 | ||
33 | +static void create_fdt_virtio_iommu(RISCVVirtState *s, uint16_t bdf) | 24 | -static void create_fdt_imsic(RISCVVirtState *s, const MemMapEntry *memmap, |
25 | - uint32_t *phandle, uint32_t *intc_phandles, | ||
26 | - uint32_t *msi_m_phandle, uint32_t *msi_s_phandle) | ||
27 | +static void create_fdt_one_imsic(RISCVVirtState *s, hwaddr base_addr, | ||
28 | + uint32_t *intc_phandles, uint32_t msi_phandle, | ||
29 | + bool m_mode, uint32_t imsic_guest_bits) | ||
30 | { | ||
31 | int cpu, socket; | ||
32 | char *imsic_name; | ||
33 | MachineState *ms = MACHINE(s); | ||
34 | int socket_count = riscv_socket_count(ms); | ||
35 | - uint32_t imsic_max_hart_per_socket, imsic_guest_bits; | ||
36 | + uint32_t imsic_max_hart_per_socket; | ||
37 | uint32_t *imsic_cells, *imsic_regs, imsic_addr, imsic_size; | ||
38 | |||
39 | - *msi_m_phandle = (*phandle)++; | ||
40 | - *msi_s_phandle = (*phandle)++; | ||
41 | imsic_cells = g_new0(uint32_t, ms->smp.cpus * 2); | ||
42 | imsic_regs = g_new0(uint32_t, socket_count * 4); | ||
43 | |||
44 | - /* M-level IMSIC node */ | ||
45 | for (cpu = 0; cpu < ms->smp.cpus; cpu++) { | ||
46 | imsic_cells[cpu * 2 + 0] = cpu_to_be32(intc_phandles[cpu]); | ||
47 | - imsic_cells[cpu * 2 + 1] = cpu_to_be32(IRQ_M_EXT); | ||
48 | + imsic_cells[cpu * 2 + 1] = cpu_to_be32(m_mode ? IRQ_M_EXT : IRQ_S_EXT); | ||
49 | } | ||
50 | - imsic_max_hart_per_socket = 0; | ||
51 | - for (socket = 0; socket < socket_count; socket++) { | ||
52 | - imsic_addr = memmap[VIRT_IMSIC_M].base + | ||
53 | - socket * VIRT_IMSIC_GROUP_MAX_SIZE; | ||
54 | - imsic_size = IMSIC_HART_SIZE(0) * s->soc[socket].num_harts; | ||
55 | - imsic_regs[socket * 4 + 0] = 0; | ||
56 | - imsic_regs[socket * 4 + 1] = cpu_to_be32(imsic_addr); | ||
57 | - imsic_regs[socket * 4 + 2] = 0; | ||
58 | - imsic_regs[socket * 4 + 3] = cpu_to_be32(imsic_size); | ||
59 | - if (imsic_max_hart_per_socket < s->soc[socket].num_harts) { | ||
60 | - imsic_max_hart_per_socket = s->soc[socket].num_harts; | ||
61 | - } | ||
62 | - } | ||
63 | - imsic_name = g_strdup_printf("/soc/imsics@%lx", | ||
64 | - (unsigned long)memmap[VIRT_IMSIC_M].base); | ||
65 | - qemu_fdt_add_subnode(ms->fdt, imsic_name); | ||
66 | - qemu_fdt_setprop_string(ms->fdt, imsic_name, "compatible", | ||
67 | - "riscv,imsics"); | ||
68 | - qemu_fdt_setprop_cell(ms->fdt, imsic_name, "#interrupt-cells", | ||
69 | - FDT_IMSIC_INT_CELLS); | ||
70 | - qemu_fdt_setprop(ms->fdt, imsic_name, "interrupt-controller", | ||
71 | - NULL, 0); | ||
72 | - qemu_fdt_setprop(ms->fdt, imsic_name, "msi-controller", | ||
73 | - NULL, 0); | ||
74 | - qemu_fdt_setprop(ms->fdt, imsic_name, "interrupts-extended", | ||
75 | - imsic_cells, ms->smp.cpus * sizeof(uint32_t) * 2); | ||
76 | - qemu_fdt_setprop(ms->fdt, imsic_name, "reg", imsic_regs, | ||
77 | - socket_count * sizeof(uint32_t) * 4); | ||
78 | - qemu_fdt_setprop_cell(ms->fdt, imsic_name, "riscv,num-ids", | ||
79 | - VIRT_IRQCHIP_NUM_MSIS); | ||
80 | - if (socket_count > 1) { | ||
81 | - qemu_fdt_setprop_cell(ms->fdt, imsic_name, "riscv,hart-index-bits", | ||
82 | - imsic_num_bits(imsic_max_hart_per_socket)); | ||
83 | - qemu_fdt_setprop_cell(ms->fdt, imsic_name, "riscv,group-index-bits", | ||
84 | - imsic_num_bits(socket_count)); | ||
85 | - qemu_fdt_setprop_cell(ms->fdt, imsic_name, "riscv,group-index-shift", | ||
86 | - IMSIC_MMIO_GROUP_MIN_SHIFT); | ||
87 | - } | ||
88 | - qemu_fdt_setprop_cell(ms->fdt, imsic_name, "phandle", *msi_m_phandle); | ||
89 | - | ||
90 | - g_free(imsic_name); | ||
91 | |||
92 | - /* S-level IMSIC node */ | ||
93 | - for (cpu = 0; cpu < ms->smp.cpus; cpu++) { | ||
94 | - imsic_cells[cpu * 2 + 0] = cpu_to_be32(intc_phandles[cpu]); | ||
95 | - imsic_cells[cpu * 2 + 1] = cpu_to_be32(IRQ_S_EXT); | ||
96 | - } | ||
97 | - imsic_guest_bits = imsic_num_bits(s->aia_guests + 1); | ||
98 | imsic_max_hart_per_socket = 0; | ||
99 | for (socket = 0; socket < socket_count; socket++) { | ||
100 | - imsic_addr = memmap[VIRT_IMSIC_S].base + | ||
101 | - socket * VIRT_IMSIC_GROUP_MAX_SIZE; | ||
102 | + imsic_addr = base_addr + socket * VIRT_IMSIC_GROUP_MAX_SIZE; | ||
103 | imsic_size = IMSIC_HART_SIZE(imsic_guest_bits) * | ||
104 | s->soc[socket].num_harts; | ||
105 | imsic_regs[socket * 4 + 0] = 0; | ||
106 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_imsic(RISCVVirtState *s, const MemMapEntry *memmap, | ||
107 | imsic_max_hart_per_socket = s->soc[socket].num_harts; | ||
108 | } | ||
109 | } | ||
110 | - imsic_name = g_strdup_printf("/soc/imsics@%lx", | ||
111 | - (unsigned long)memmap[VIRT_IMSIC_S].base); | ||
112 | + | ||
113 | + imsic_name = g_strdup_printf("/soc/imsics@%lx", (unsigned long)base_addr); | ||
114 | qemu_fdt_add_subnode(ms->fdt, imsic_name); | ||
115 | - qemu_fdt_setprop_string(ms->fdt, imsic_name, "compatible", | ||
116 | - "riscv,imsics"); | ||
117 | + qemu_fdt_setprop_string(ms->fdt, imsic_name, "compatible", "riscv,imsics"); | ||
118 | qemu_fdt_setprop_cell(ms->fdt, imsic_name, "#interrupt-cells", | ||
119 | - FDT_IMSIC_INT_CELLS); | ||
120 | - qemu_fdt_setprop(ms->fdt, imsic_name, "interrupt-controller", | ||
121 | - NULL, 0); | ||
122 | - qemu_fdt_setprop(ms->fdt, imsic_name, "msi-controller", | ||
123 | - NULL, 0); | ||
124 | + FDT_IMSIC_INT_CELLS); | ||
125 | + qemu_fdt_setprop(ms->fdt, imsic_name, "interrupt-controller", NULL, 0); | ||
126 | + qemu_fdt_setprop(ms->fdt, imsic_name, "msi-controller", NULL, 0); | ||
127 | qemu_fdt_setprop(ms->fdt, imsic_name, "interrupts-extended", | ||
128 | - imsic_cells, ms->smp.cpus * sizeof(uint32_t) * 2); | ||
129 | + imsic_cells, ms->smp.cpus * sizeof(uint32_t) * 2); | ||
130 | qemu_fdt_setprop(ms->fdt, imsic_name, "reg", imsic_regs, | ||
131 | - socket_count * sizeof(uint32_t) * 4); | ||
132 | + socket_count * sizeof(uint32_t) * 4); | ||
133 | qemu_fdt_setprop_cell(ms->fdt, imsic_name, "riscv,num-ids", | ||
134 | - VIRT_IRQCHIP_NUM_MSIS); | ||
135 | + VIRT_IRQCHIP_NUM_MSIS); | ||
136 | + | ||
137 | if (imsic_guest_bits) { | ||
138 | qemu_fdt_setprop_cell(ms->fdt, imsic_name, "riscv,guest-index-bits", | ||
139 | - imsic_guest_bits); | ||
140 | + imsic_guest_bits); | ||
141 | } | ||
142 | + | ||
143 | if (socket_count > 1) { | ||
144 | qemu_fdt_setprop_cell(ms->fdt, imsic_name, "riscv,hart-index-bits", | ||
145 | - imsic_num_bits(imsic_max_hart_per_socket)); | ||
146 | + imsic_num_bits(imsic_max_hart_per_socket)); | ||
147 | qemu_fdt_setprop_cell(ms->fdt, imsic_name, "riscv,group-index-bits", | ||
148 | - imsic_num_bits(socket_count)); | ||
149 | + imsic_num_bits(socket_count)); | ||
150 | qemu_fdt_setprop_cell(ms->fdt, imsic_name, "riscv,group-index-shift", | ||
151 | - IMSIC_MMIO_GROUP_MIN_SHIFT); | ||
152 | + IMSIC_MMIO_GROUP_MIN_SHIFT); | ||
153 | } | ||
154 | - qemu_fdt_setprop_cell(ms->fdt, imsic_name, "phandle", *msi_s_phandle); | ||
155 | - g_free(imsic_name); | ||
156 | + qemu_fdt_setprop_cell(ms->fdt, imsic_name, "phandle", msi_phandle); | ||
157 | |||
158 | + g_free(imsic_name); | ||
159 | g_free(imsic_regs); | ||
160 | g_free(imsic_cells); | ||
161 | } | ||
162 | |||
163 | -static void create_fdt_socket_aplic(RISCVVirtState *s, | ||
164 | - const MemMapEntry *memmap, int socket, | ||
165 | - uint32_t msi_m_phandle, | ||
166 | - uint32_t msi_s_phandle, | ||
167 | - uint32_t *phandle, | ||
168 | - uint32_t *intc_phandles, | ||
169 | - uint32_t *aplic_phandles) | ||
170 | +static void create_fdt_imsic(RISCVVirtState *s, const MemMapEntry *memmap, | ||
171 | + uint32_t *phandle, uint32_t *intc_phandles, | ||
172 | + uint32_t *msi_m_phandle, uint32_t *msi_s_phandle) | ||
34 | +{ | 173 | +{ |
35 | + const char compat[] = "virtio,pci-iommu\0pci1af4,1057"; | 174 | + *msi_m_phandle = (*phandle)++; |
36 | + void *fdt = MACHINE(s)->fdt; | 175 | + *msi_s_phandle = (*phandle)++; |
37 | + uint32_t iommu_phandle; | 176 | + |
38 | + g_autofree char *iommu_node = NULL; | 177 | + if (!kvm_enabled()) { |
39 | + g_autofree char *pci_node = NULL; | 178 | + /* M-level IMSIC node */ |
40 | + | 179 | + create_fdt_one_imsic(s, memmap[VIRT_IMSIC_M].base, intc_phandles, |
41 | + pci_node = g_strdup_printf("/soc/pci@%lx", | 180 | + *msi_m_phandle, true, 0); |
42 | + (long) virt_memmap[VIRT_PCIE_ECAM].base); | 181 | + } |
43 | + iommu_node = g_strdup_printf("%s/virtio_iommu@%x,%x", pci_node, | 182 | + |
44 | + PCI_SLOT(bdf), PCI_FUNC(bdf)); | 183 | + /* S-level IMSIC node */ |
45 | + iommu_phandle = qemu_fdt_alloc_phandle(fdt); | 184 | + create_fdt_one_imsic(s, memmap[VIRT_IMSIC_S].base, intc_phandles, |
46 | + | 185 | + *msi_s_phandle, false, |
47 | + qemu_fdt_add_subnode(fdt, iommu_node); | 186 | + imsic_num_bits(s->aia_guests + 1)); |
48 | + | 187 | + |
49 | + qemu_fdt_setprop(fdt, iommu_node, "compatible", compat, sizeof(compat)); | ||
50 | + qemu_fdt_setprop_sized_cells(fdt, iommu_node, "reg", | ||
51 | + 1, bdf << 8, 1, 0, 1, 0, | ||
52 | + 1, 0, 1, 0); | ||
53 | + qemu_fdt_setprop_cell(fdt, iommu_node, "#iommu-cells", 1); | ||
54 | + qemu_fdt_setprop_cell(fdt, iommu_node, "phandle", iommu_phandle); | ||
55 | + | ||
56 | + qemu_fdt_setprop_cells(fdt, pci_node, "iommu-map", | ||
57 | + 0, iommu_phandle, 0, bdf, | ||
58 | + bdf + 1, iommu_phandle, bdf + 1, 0xffff - bdf); | ||
59 | +} | 188 | +} |
60 | + | 189 | + |
61 | static void finalize_fdt(RISCVVirtState *s) | 190 | +static void create_fdt_one_aplic(RISCVVirtState *s, int socket, |
191 | + unsigned long aplic_addr, uint32_t aplic_size, | ||
192 | + uint32_t msi_phandle, | ||
193 | + uint32_t *intc_phandles, | ||
194 | + uint32_t aplic_phandle, | ||
195 | + uint32_t aplic_child_phandle, | ||
196 | + bool m_mode) | ||
62 | { | 197 | { |
63 | uint32_t phandle = 1, irq_mmio_phandle = 1, msi_pcie_phandle = 1; | 198 | int cpu; |
64 | @@ -XXX,XX +XXX,XX @@ static HotplugHandler *virt_machine_get_hotplug_handler(MachineState *machine, | 199 | char *aplic_name; |
65 | { | 200 | uint32_t *aplic_cells; |
66 | MachineClass *mc = MACHINE_GET_CLASS(machine); | 201 | - unsigned long aplic_addr; |
67 | 202 | MachineState *ms = MACHINE(s); | |
68 | - if (device_is_dynamic_sysbus(mc, dev)) { | 203 | - uint32_t aplic_m_phandle, aplic_s_phandle; |
69 | + if (device_is_dynamic_sysbus(mc, dev) || | 204 | |
70 | + object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) { | 205 | - aplic_m_phandle = (*phandle)++; |
71 | return HOTPLUG_HANDLER(machine); | 206 | - aplic_s_phandle = (*phandle)++; |
72 | } | 207 | aplic_cells = g_new0(uint32_t, s->soc[socket].num_harts * 2); |
73 | return NULL; | 208 | |
74 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev, | 209 | - /* M-level APLIC node */ |
75 | SYS_BUS_DEVICE(dev)); | 210 | for (cpu = 0; cpu < s->soc[socket].num_harts; cpu++) { |
211 | aplic_cells[cpu * 2 + 0] = cpu_to_be32(intc_phandles[cpu]); | ||
212 | - aplic_cells[cpu * 2 + 1] = cpu_to_be32(IRQ_M_EXT); | ||
213 | + aplic_cells[cpu * 2 + 1] = cpu_to_be32(m_mode ? IRQ_M_EXT : IRQ_S_EXT); | ||
214 | } | ||
215 | - aplic_addr = memmap[VIRT_APLIC_M].base + | ||
216 | - (memmap[VIRT_APLIC_M].size * socket); | ||
217 | + | ||
218 | aplic_name = g_strdup_printf("/soc/aplic@%lx", aplic_addr); | ||
219 | qemu_fdt_add_subnode(ms->fdt, aplic_name); | ||
220 | qemu_fdt_setprop_string(ms->fdt, aplic_name, "compatible", "riscv,aplic"); | ||
221 | qemu_fdt_setprop_cell(ms->fdt, aplic_name, | ||
222 | - "#interrupt-cells", FDT_APLIC_INT_CELLS); | ||
223 | + "#interrupt-cells", FDT_APLIC_INT_CELLS); | ||
224 | qemu_fdt_setprop(ms->fdt, aplic_name, "interrupt-controller", NULL, 0); | ||
225 | + | ||
226 | if (s->aia_type == VIRT_AIA_TYPE_APLIC) { | ||
227 | qemu_fdt_setprop(ms->fdt, aplic_name, "interrupts-extended", | ||
228 | - aplic_cells, s->soc[socket].num_harts * sizeof(uint32_t) * 2); | ||
229 | + aplic_cells, | ||
230 | + s->soc[socket].num_harts * sizeof(uint32_t) * 2); | ||
231 | } else { | ||
232 | - qemu_fdt_setprop_cell(ms->fdt, aplic_name, "msi-parent", | ||
233 | - msi_m_phandle); | ||
234 | + qemu_fdt_setprop_cell(ms->fdt, aplic_name, "msi-parent", msi_phandle); | ||
235 | } | ||
236 | + | ||
237 | qemu_fdt_setprop_cells(ms->fdt, aplic_name, "reg", | ||
238 | - 0x0, aplic_addr, 0x0, memmap[VIRT_APLIC_M].size); | ||
239 | + 0x0, aplic_addr, 0x0, aplic_size); | ||
240 | qemu_fdt_setprop_cell(ms->fdt, aplic_name, "riscv,num-sources", | ||
241 | - VIRT_IRQCHIP_NUM_SOURCES); | ||
242 | - qemu_fdt_setprop_cell(ms->fdt, aplic_name, "riscv,children", | ||
243 | - aplic_s_phandle); | ||
244 | - qemu_fdt_setprop_cells(ms->fdt, aplic_name, "riscv,delegate", | ||
245 | - aplic_s_phandle, 0x1, VIRT_IRQCHIP_NUM_SOURCES); | ||
246 | + VIRT_IRQCHIP_NUM_SOURCES); | ||
247 | + | ||
248 | + if (aplic_child_phandle) { | ||
249 | + qemu_fdt_setprop_cell(ms->fdt, aplic_name, "riscv,children", | ||
250 | + aplic_child_phandle); | ||
251 | + qemu_fdt_setprop_cells(ms->fdt, aplic_name, "riscv,delegate", | ||
252 | + aplic_child_phandle, 0x1, | ||
253 | + VIRT_IRQCHIP_NUM_SOURCES); | ||
254 | + } | ||
255 | + | ||
256 | riscv_socket_fdt_write_id(ms, aplic_name, socket); | ||
257 | - qemu_fdt_setprop_cell(ms->fdt, aplic_name, "phandle", aplic_m_phandle); | ||
258 | + qemu_fdt_setprop_cell(ms->fdt, aplic_name, "phandle", aplic_phandle); | ||
259 | + | ||
260 | g_free(aplic_name); | ||
261 | + g_free(aplic_cells); | ||
262 | +} | ||
263 | |||
264 | - /* S-level APLIC node */ | ||
265 | - for (cpu = 0; cpu < s->soc[socket].num_harts; cpu++) { | ||
266 | - aplic_cells[cpu * 2 + 0] = cpu_to_be32(intc_phandles[cpu]); | ||
267 | - aplic_cells[cpu * 2 + 1] = cpu_to_be32(IRQ_S_EXT); | ||
268 | +static void create_fdt_socket_aplic(RISCVVirtState *s, | ||
269 | + const MemMapEntry *memmap, int socket, | ||
270 | + uint32_t msi_m_phandle, | ||
271 | + uint32_t msi_s_phandle, | ||
272 | + uint32_t *phandle, | ||
273 | + uint32_t *intc_phandles, | ||
274 | + uint32_t *aplic_phandles) | ||
275 | +{ | ||
276 | + char *aplic_name; | ||
277 | + unsigned long aplic_addr; | ||
278 | + MachineState *ms = MACHINE(s); | ||
279 | + uint32_t aplic_m_phandle, aplic_s_phandle; | ||
280 | + | ||
281 | + aplic_m_phandle = (*phandle)++; | ||
282 | + aplic_s_phandle = (*phandle)++; | ||
283 | + | ||
284 | + if (!kvm_enabled()) { | ||
285 | + /* M-level APLIC node */ | ||
286 | + aplic_addr = memmap[VIRT_APLIC_M].base + | ||
287 | + (memmap[VIRT_APLIC_M].size * socket); | ||
288 | + create_fdt_one_aplic(s, socket, aplic_addr, memmap[VIRT_APLIC_M].size, | ||
289 | + msi_m_phandle, intc_phandles, | ||
290 | + aplic_m_phandle, aplic_s_phandle, | ||
291 | + true); | ||
292 | } | ||
293 | + | ||
294 | + /* S-level APLIC node */ | ||
295 | aplic_addr = memmap[VIRT_APLIC_S].base + | ||
296 | (memmap[VIRT_APLIC_S].size * socket); | ||
297 | + create_fdt_one_aplic(s, socket, aplic_addr, memmap[VIRT_APLIC_S].size, | ||
298 | + msi_s_phandle, intc_phandles, | ||
299 | + aplic_s_phandle, 0, | ||
300 | + false); | ||
301 | + | ||
302 | aplic_name = g_strdup_printf("/soc/aplic@%lx", aplic_addr); | ||
303 | - qemu_fdt_add_subnode(ms->fdt, aplic_name); | ||
304 | - qemu_fdt_setprop_string(ms->fdt, aplic_name, "compatible", "riscv,aplic"); | ||
305 | - qemu_fdt_setprop_cell(ms->fdt, aplic_name, | ||
306 | - "#interrupt-cells", FDT_APLIC_INT_CELLS); | ||
307 | - qemu_fdt_setprop(ms->fdt, aplic_name, "interrupt-controller", NULL, 0); | ||
308 | - if (s->aia_type == VIRT_AIA_TYPE_APLIC) { | ||
309 | - qemu_fdt_setprop(ms->fdt, aplic_name, "interrupts-extended", | ||
310 | - aplic_cells, s->soc[socket].num_harts * sizeof(uint32_t) * 2); | ||
311 | - } else { | ||
312 | - qemu_fdt_setprop_cell(ms->fdt, aplic_name, "msi-parent", | ||
313 | - msi_s_phandle); | ||
314 | - } | ||
315 | - qemu_fdt_setprop_cells(ms->fdt, aplic_name, "reg", | ||
316 | - 0x0, aplic_addr, 0x0, memmap[VIRT_APLIC_S].size); | ||
317 | - qemu_fdt_setprop_cell(ms->fdt, aplic_name, "riscv,num-sources", | ||
318 | - VIRT_IRQCHIP_NUM_SOURCES); | ||
319 | - riscv_socket_fdt_write_id(ms, aplic_name, socket); | ||
320 | - qemu_fdt_setprop_cell(ms->fdt, aplic_name, "phandle", aplic_s_phandle); | ||
321 | |||
322 | if (!socket) { | ||
323 | platform_bus_add_all_fdt_nodes(ms->fdt, aplic_name, | ||
324 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_aplic(RISCVVirtState *s, | ||
325 | |||
326 | g_free(aplic_name); | ||
327 | |||
328 | - g_free(aplic_cells); | ||
329 | aplic_phandles[socket] = aplic_s_phandle; | ||
330 | } | ||
331 | |||
332 | @@ -XXX,XX +XXX,XX @@ static DeviceState *virt_create_aia(RISCVVirtAIAType aia_type, int aia_guests, | ||
333 | int i; | ||
334 | hwaddr addr; | ||
335 | uint32_t guest_bits; | ||
336 | - DeviceState *aplic_m; | ||
337 | - bool msimode = (aia_type == VIRT_AIA_TYPE_APLIC_IMSIC) ? true : false; | ||
338 | + DeviceState *aplic_s = NULL; | ||
339 | + DeviceState *aplic_m = NULL; | ||
340 | + bool msimode = aia_type == VIRT_AIA_TYPE_APLIC_IMSIC; | ||
341 | |||
342 | if (msimode) { | ||
343 | - /* Per-socket M-level IMSICs */ | ||
344 | - addr = memmap[VIRT_IMSIC_M].base + socket * VIRT_IMSIC_GROUP_MAX_SIZE; | ||
345 | - for (i = 0; i < hart_count; i++) { | ||
346 | - riscv_imsic_create(addr + i * IMSIC_HART_SIZE(0), | ||
347 | - base_hartid + i, true, 1, | ||
348 | - VIRT_IRQCHIP_NUM_MSIS); | ||
349 | + if (!kvm_enabled()) { | ||
350 | + /* Per-socket M-level IMSICs */ | ||
351 | + addr = memmap[VIRT_IMSIC_M].base + | ||
352 | + socket * VIRT_IMSIC_GROUP_MAX_SIZE; | ||
353 | + for (i = 0; i < hart_count; i++) { | ||
354 | + riscv_imsic_create(addr + i * IMSIC_HART_SIZE(0), | ||
355 | + base_hartid + i, true, 1, | ||
356 | + VIRT_IRQCHIP_NUM_MSIS); | ||
357 | + } | ||
76 | } | 358 | } |
77 | } | 359 | |
78 | + | 360 | /* Per-socket S-level IMSICs */ |
79 | + if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) { | 361 | @@ -XXX,XX +XXX,XX @@ static DeviceState *virt_create_aia(RISCVVirtAIAType aia_type, int aia_guests, |
80 | + create_fdt_virtio_iommu(s, pci_get_bdf(PCI_DEVICE(dev))); | 362 | } |
81 | + } | 363 | } |
364 | |||
365 | - /* Per-socket M-level APLIC */ | ||
366 | - aplic_m = riscv_aplic_create( | ||
367 | - memmap[VIRT_APLIC_M].base + socket * memmap[VIRT_APLIC_M].size, | ||
368 | - memmap[VIRT_APLIC_M].size, | ||
369 | - (msimode) ? 0 : base_hartid, | ||
370 | - (msimode) ? 0 : hart_count, | ||
371 | - VIRT_IRQCHIP_NUM_SOURCES, | ||
372 | - VIRT_IRQCHIP_NUM_PRIO_BITS, | ||
373 | - msimode, true, NULL); | ||
374 | - | ||
375 | - if (aplic_m) { | ||
376 | - /* Per-socket S-level APLIC */ | ||
377 | - riscv_aplic_create( | ||
378 | - memmap[VIRT_APLIC_S].base + socket * memmap[VIRT_APLIC_S].size, | ||
379 | - memmap[VIRT_APLIC_S].size, | ||
380 | - (msimode) ? 0 : base_hartid, | ||
381 | - (msimode) ? 0 : hart_count, | ||
382 | - VIRT_IRQCHIP_NUM_SOURCES, | ||
383 | - VIRT_IRQCHIP_NUM_PRIO_BITS, | ||
384 | - msimode, false, aplic_m); | ||
385 | + if (!kvm_enabled()) { | ||
386 | + /* Per-socket M-level APLIC */ | ||
387 | + aplic_m = riscv_aplic_create(memmap[VIRT_APLIC_M].base + | ||
388 | + socket * memmap[VIRT_APLIC_M].size, | ||
389 | + memmap[VIRT_APLIC_M].size, | ||
390 | + (msimode) ? 0 : base_hartid, | ||
391 | + (msimode) ? 0 : hart_count, | ||
392 | + VIRT_IRQCHIP_NUM_SOURCES, | ||
393 | + VIRT_IRQCHIP_NUM_PRIO_BITS, | ||
394 | + msimode, true, NULL); | ||
395 | } | ||
396 | |||
397 | - return aplic_m; | ||
398 | + /* Per-socket S-level APLIC */ | ||
399 | + aplic_s = riscv_aplic_create(memmap[VIRT_APLIC_S].base + | ||
400 | + socket * memmap[VIRT_APLIC_S].size, | ||
401 | + memmap[VIRT_APLIC_S].size, | ||
402 | + (msimode) ? 0 : base_hartid, | ||
403 | + (msimode) ? 0 : hart_count, | ||
404 | + VIRT_IRQCHIP_NUM_SOURCES, | ||
405 | + VIRT_IRQCHIP_NUM_PRIO_BITS, | ||
406 | + msimode, false, aplic_m); | ||
407 | + | ||
408 | + return kvm_enabled() ? aplic_s : aplic_m; | ||
82 | } | 409 | } |
83 | 410 | ||
84 | static void virt_machine_class_init(ObjectClass *oc, void *data) | 411 | static void create_platform_bus(RISCVVirtState *s, DeviceState *irqchip) |
85 | -- | 412 | -- |
86 | 2.44.0 | 413 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Sia Jee Heng <jeeheng.sia@starfivetech.com> | 1 | From: Yong-Xuan Wang <yongxuan.wang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Generate Serial Port Console Redirection Table (SPCR) for RISC-V | 3 | We check the in-kernel irqchip support when using KVM acceleration. |
4 | virtual machine. | ||
5 | 4 | ||
6 | Signed-off-by: Sia Jee Heng <jeeheng.sia@starfivetech.com> | 5 | Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com> |
6 | Reviewed-by: Jim Shu <jim.shu@sifive.com> | ||
7 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 7 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
8 | Message-ID: <20240129021440.17640-3-jeeheng.sia@starfivetech.com> | 8 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> |
9 | Message-ID: <20230727102439.22554-3-yongxuan.wang@sifive.com> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 11 | --- |
11 | hw/riscv/virt-acpi-build.c | 39 ++++++++++++++++++++++++++++++++++++++ | 12 | target/riscv/kvm.c | 10 +++++++++- |
12 | 1 file changed, 39 insertions(+) | 13 | 1 file changed, 9 insertions(+), 1 deletion(-) |
13 | 14 | ||
14 | diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c | 15 | diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c |
15 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/riscv/virt-acpi-build.c | 17 | --- a/target/riscv/kvm.c |
17 | +++ b/hw/riscv/virt-acpi-build.c | 18 | +++ b/target/riscv/kvm.c |
18 | @@ -XXX,XX +XXX,XX @@ acpi_dsdt_add_uart(Aml *scope, const MemMapEntry *uart_memmap, | 19 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_init(MachineState *ms, KVMState *s) |
19 | aml_append(scope, dev); | 20 | |
21 | int kvm_arch_irqchip_create(KVMState *s) | ||
22 | { | ||
23 | - return 0; | ||
24 | + if (kvm_kernel_irqchip_split()) { | ||
25 | + error_report("-machine kernel_irqchip=split is not supported on RISC-V."); | ||
26 | + exit(1); | ||
27 | + } | ||
28 | + | ||
29 | + /* | ||
30 | + * We can create the VAIA using the newer device control API. | ||
31 | + */ | ||
32 | + return kvm_check_extension(s, KVM_CAP_DEVICE_CTRL); | ||
20 | } | 33 | } |
21 | 34 | ||
22 | +/* | 35 | int kvm_arch_process_async_events(CPUState *cs) |
23 | + * Serial Port Console Redirection Table (SPCR) | ||
24 | + * Rev: 1.07 | ||
25 | + */ | ||
26 | + | ||
27 | +static void | ||
28 | +spcr_setup(GArray *table_data, BIOSLinker *linker, RISCVVirtState *s) | ||
29 | +{ | ||
30 | + AcpiSpcrData serial = { | ||
31 | + .interface_type = 0, /* 16550 compatible */ | ||
32 | + .base_addr.id = AML_AS_SYSTEM_MEMORY, | ||
33 | + .base_addr.width = 32, | ||
34 | + .base_addr.offset = 0, | ||
35 | + .base_addr.size = 1, | ||
36 | + .base_addr.addr = s->memmap[VIRT_UART0].base, | ||
37 | + .interrupt_type = (1 << 4),/* Bit[4] RISC-V PLIC/APLIC */ | ||
38 | + .pc_interrupt = 0, | ||
39 | + .interrupt = UART0_IRQ, | ||
40 | + .baud_rate = 7, /* 15200 */ | ||
41 | + .parity = 0, | ||
42 | + .stop_bits = 1, | ||
43 | + .flow_control = 0, | ||
44 | + .terminal_type = 3, /* ANSI */ | ||
45 | + .language = 0, /* Language */ | ||
46 | + .pci_device_id = 0xffff, /* not a PCI device*/ | ||
47 | + .pci_vendor_id = 0xffff, /* not a PCI device*/ | ||
48 | + .pci_bus = 0, | ||
49 | + .pci_device = 0, | ||
50 | + .pci_function = 0, | ||
51 | + .pci_flags = 0, | ||
52 | + .pci_segment = 0, | ||
53 | + }; | ||
54 | + | ||
55 | + build_spcr(table_data, linker, &serial, 2, s->oem_id, s->oem_table_id); | ||
56 | +} | ||
57 | + | ||
58 | /* RHCT Node[N] starts at offset 56 */ | ||
59 | #define RHCT_NODE_ARRAY_OFFSET 56 | ||
60 | |||
61 | @@ -XXX,XX +XXX,XX @@ static void virt_acpi_build(RISCVVirtState *s, AcpiBuildTables *tables) | ||
62 | acpi_add_table(table_offsets, tables_blob); | ||
63 | build_rhct(tables_blob, tables->linker, s); | ||
64 | |||
65 | + acpi_add_table(table_offsets, tables_blob); | ||
66 | + spcr_setup(tables_blob, tables->linker, s); | ||
67 | + | ||
68 | acpi_add_table(table_offsets, tables_blob); | ||
69 | { | ||
70 | AcpiMcfgInfo mcfg = { | ||
71 | -- | 36 | -- |
72 | 2.44.0 | 37 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Haibo Xu <haibo1.xu@intel.com> | 1 | From: Yong-Xuan Wang <yongxuan.wang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Enable ACPI NUMA support by adding the following 2 ACPI tables: | 3 | We create a vAIA chip by using the KVM_DEV_TYPE_RISCV_AIA and then set up |
4 | SRAT: provides the association for memory/Harts and Proximity Domains | 4 | the chip with the KVM_DEV_RISCV_AIA_GRP_* APIs. |
5 | SLIT: provides the relative distance between Proximity Domains | 5 | We also extend KVM accelerator to specify the KVM AIA mode. The "riscv-aia" |
6 | parameter is passed along with --accel in QEMU command-line. | ||
7 | 1) "riscv-aia=emul": IMSIC is emulated by hypervisor | ||
8 | 2) "riscv-aia=hwaccel": use hardware guest IMSIC | ||
9 | 3) "riscv-aia=auto": use the hardware guest IMSICs whenever available | ||
10 | otherwise we fallback to software emulation. | ||
6 | 11 | ||
7 | The SRAT RINTC Affinity Structure definition[1] was based on the recently | 12 | Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com> |
8 | approved ACPI CodeFirst ECR[2]. | 13 | Reviewed-by: Jim Shu <jim.shu@sifive.com> |
9 | 14 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | |
10 | [1] https://github.com/riscv-non-isa/riscv-acpi/issues/25 | ||
11 | [2] https://mantis.uefi.org/mantis/view.php?id=2433 | ||
12 | |||
13 | Signed-off-by: Haibo Xu <haibo1.xu@intel.com> | ||
14 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | 15 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> |
15 | Message-ID: <20240129094200.3581037-1-haibo1.xu@intel.com> | 16 | Message-ID: <20230727102439.22554-4-yongxuan.wang@sifive.com> |
16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 17 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
17 | --- | 18 | --- |
18 | hw/riscv/virt-acpi-build.c | 60 ++++++++++++++++++++++++++++++++++++++ | 19 | target/riscv/kvm_riscv.h | 4 + |
19 | 1 file changed, 60 insertions(+) | 20 | target/riscv/kvm.c | 186 +++++++++++++++++++++++++++++++++++++++ |
21 | 2 files changed, 190 insertions(+) | ||
20 | 22 | ||
21 | diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c | 23 | diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h |
22 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/hw/riscv/virt-acpi-build.c | 25 | --- a/target/riscv/kvm_riscv.h |
24 | +++ b/hw/riscv/virt-acpi-build.c | 26 | +++ b/target/riscv/kvm_riscv.h |
25 | @@ -XXX,XX +XXX,XX @@ static void build_madt(GArray *table_data, | 27 | @@ -XXX,XX +XXX,XX @@ |
26 | acpi_table_end(linker, &table); | 28 | void kvm_riscv_init_user_properties(Object *cpu_obj); |
29 | void kvm_riscv_reset_vcpu(RISCVCPU *cpu); | ||
30 | void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level); | ||
31 | +void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, | ||
32 | + uint64_t aia_irq_num, uint64_t aia_msi_num, | ||
33 | + uint64_t aplic_base, uint64_t imsic_base, | ||
34 | + uint64_t guest_num); | ||
35 | |||
36 | #endif | ||
37 | diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/target/riscv/kvm.c | ||
40 | +++ b/target/riscv/kvm.c | ||
41 | @@ -XXX,XX +XXX,XX @@ | ||
42 | #include "exec/address-spaces.h" | ||
43 | #include "hw/boards.h" | ||
44 | #include "hw/irq.h" | ||
45 | +#include "hw/intc/riscv_imsic.h" | ||
46 | #include "qemu/log.h" | ||
47 | #include "hw/loader.h" | ||
48 | #include "kvm_riscv.h" | ||
49 | @@ -XXX,XX +XXX,XX @@ | ||
50 | #include "chardev/char-fe.h" | ||
51 | #include "migration/migration.h" | ||
52 | #include "sysemu/runstate.h" | ||
53 | +#include "hw/riscv/numa.h" | ||
54 | |||
55 | static uint64_t kvm_riscv_reg_id(CPURISCVState *env, uint64_t type, | ||
56 | uint64_t idx) | ||
57 | @@ -XXX,XX +XXX,XX @@ bool kvm_arch_cpu_check_are_resettable(void) | ||
58 | return true; | ||
27 | } | 59 | } |
28 | 60 | ||
29 | +/* | 61 | +static int aia_mode; |
30 | + * ACPI spec, Revision 6.5+ | 62 | + |
31 | + * 5.2.16 System Resource Affinity Table (SRAT) | 63 | +static const char *kvm_aia_mode_str(uint64_t mode) |
32 | + * REF: https://github.com/riscv-non-isa/riscv-acpi/issues/25 | 64 | +{ |
33 | + * https://drive.google.com/file/d/1YTdDx2IPm5IeZjAW932EYU-tUtgS08tX/view | 65 | + switch (mode) { |
34 | + */ | 66 | + case KVM_DEV_RISCV_AIA_MODE_EMUL: |
35 | +static void | 67 | + return "emul"; |
36 | +build_srat(GArray *table_data, BIOSLinker *linker, RISCVVirtState *vms) | 68 | + case KVM_DEV_RISCV_AIA_MODE_HWACCEL: |
37 | +{ | 69 | + return "hwaccel"; |
38 | + int i; | 70 | + case KVM_DEV_RISCV_AIA_MODE_AUTO: |
39 | + uint64_t mem_base; | 71 | + default: |
40 | + MachineClass *mc = MACHINE_GET_CLASS(vms); | 72 | + return "auto"; |
41 | + MachineState *ms = MACHINE(vms); | 73 | + }; |
42 | + const CPUArchIdList *cpu_list = mc->possible_cpu_arch_ids(ms); | 74 | +} |
43 | + AcpiTable table = { .sig = "SRAT", .rev = 3, .oem_id = vms->oem_id, | 75 | + |
44 | + .oem_table_id = vms->oem_table_id }; | 76 | +static char *riscv_get_kvm_aia(Object *obj, Error **errp) |
45 | + | 77 | +{ |
46 | + acpi_table_begin(&table, table_data); | 78 | + return g_strdup(kvm_aia_mode_str(aia_mode)); |
47 | + build_append_int_noprefix(table_data, 1, 4); /* Reserved */ | 79 | +} |
48 | + build_append_int_noprefix(table_data, 0, 8); /* Reserved */ | 80 | + |
49 | + | 81 | +static void riscv_set_kvm_aia(Object *obj, const char *val, Error **errp) |
50 | + for (i = 0; i < cpu_list->len; ++i) { | 82 | +{ |
51 | + uint32_t nodeid = cpu_list->cpus[i].props.node_id; | 83 | + if (!strcmp(val, "emul")) { |
52 | + /* | 84 | + aia_mode = KVM_DEV_RISCV_AIA_MODE_EMUL; |
53 | + * 5.2.16.8 RINTC Affinity Structure | 85 | + } else if (!strcmp(val, "hwaccel")) { |
54 | + */ | 86 | + aia_mode = KVM_DEV_RISCV_AIA_MODE_HWACCEL; |
55 | + build_append_int_noprefix(table_data, 7, 1); /* Type */ | 87 | + } else if (!strcmp(val, "auto")) { |
56 | + build_append_int_noprefix(table_data, 20, 1); /* Length */ | 88 | + aia_mode = KVM_DEV_RISCV_AIA_MODE_AUTO; |
57 | + build_append_int_noprefix(table_data, 0, 2); /* Reserved */ | 89 | + } else { |
58 | + build_append_int_noprefix(table_data, nodeid, 4); /* Proximity Domain */ | 90 | + error_setg(errp, "Invalid KVM AIA mode"); |
59 | + build_append_int_noprefix(table_data, i, 4); /* ACPI Processor UID */ | 91 | + error_append_hint(errp, "Valid values are emul, hwaccel, and auto.\n"); |
60 | + /* Flags, Table 5-70 */ | 92 | + } |
61 | + build_append_int_noprefix(table_data, 1 /* Flags: Enabled */, 4); | 93 | +} |
62 | + build_append_int_noprefix(table_data, 0, 4); /* Clock Domain */ | 94 | + |
63 | + } | 95 | void kvm_arch_accel_class_init(ObjectClass *oc) |
64 | + | 96 | { |
65 | + mem_base = vms->memmap[VIRT_DRAM].base; | 97 | + object_class_property_add_str(oc, "riscv-aia", riscv_get_kvm_aia, |
66 | + for (i = 0; i < ms->numa_state->num_nodes; ++i) { | 98 | + riscv_set_kvm_aia); |
67 | + if (ms->numa_state->nodes[i].node_mem > 0) { | 99 | + object_class_property_set_description(oc, "riscv-aia", |
68 | + build_srat_memory(table_data, mem_base, | 100 | + "Set KVM AIA mode. Valid values are " |
69 | + ms->numa_state->nodes[i].node_mem, i, | 101 | + "emul, hwaccel, and auto. Default " |
70 | + MEM_AFFINITY_ENABLED); | 102 | + "is auto."); |
71 | + mem_base += ms->numa_state->nodes[i].node_mem; | 103 | + object_property_set_default_str(object_class_property_find(oc, "riscv-aia"), |
104 | + "auto"); | ||
105 | +} | ||
106 | + | ||
107 | +void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, | ||
108 | + uint64_t aia_irq_num, uint64_t aia_msi_num, | ||
109 | + uint64_t aplic_base, uint64_t imsic_base, | ||
110 | + uint64_t guest_num) | ||
111 | +{ | ||
112 | + int ret, i; | ||
113 | + int aia_fd = -1; | ||
114 | + uint64_t default_aia_mode; | ||
115 | + uint64_t socket_count = riscv_socket_count(machine); | ||
116 | + uint64_t max_hart_per_socket = 0; | ||
117 | + uint64_t socket, base_hart, hart_count, socket_imsic_base, imsic_addr; | ||
118 | + uint64_t socket_bits, hart_bits, guest_bits; | ||
119 | + | ||
120 | + aia_fd = kvm_create_device(kvm_state, KVM_DEV_TYPE_RISCV_AIA, false); | ||
121 | + | ||
122 | + if (aia_fd < 0) { | ||
123 | + error_report("Unable to create in-kernel irqchip"); | ||
124 | + exit(1); | ||
125 | + } | ||
126 | + | ||
127 | + ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG, | ||
128 | + KVM_DEV_RISCV_AIA_CONFIG_MODE, | ||
129 | + &default_aia_mode, false, NULL); | ||
130 | + if (ret < 0) { | ||
131 | + error_report("KVM AIA: failed to get current KVM AIA mode"); | ||
132 | + exit(1); | ||
133 | + } | ||
134 | + qemu_log("KVM AIA: default mode is %s\n", | ||
135 | + kvm_aia_mode_str(default_aia_mode)); | ||
136 | + | ||
137 | + if (default_aia_mode != aia_mode) { | ||
138 | + ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG, | ||
139 | + KVM_DEV_RISCV_AIA_CONFIG_MODE, | ||
140 | + &aia_mode, true, NULL); | ||
141 | + if (ret < 0) | ||
142 | + warn_report("KVM AIA: failed to set KVM AIA mode"); | ||
143 | + else | ||
144 | + qemu_log("KVM AIA: set current mode to %s\n", | ||
145 | + kvm_aia_mode_str(aia_mode)); | ||
146 | + } | ||
147 | + | ||
148 | + ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG, | ||
149 | + KVM_DEV_RISCV_AIA_CONFIG_SRCS, | ||
150 | + &aia_irq_num, true, NULL); | ||
151 | + if (ret < 0) { | ||
152 | + error_report("KVM AIA: failed to set number of input irq lines"); | ||
153 | + exit(1); | ||
154 | + } | ||
155 | + | ||
156 | + ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG, | ||
157 | + KVM_DEV_RISCV_AIA_CONFIG_IDS, | ||
158 | + &aia_msi_num, true, NULL); | ||
159 | + if (ret < 0) { | ||
160 | + error_report("KVM AIA: failed to set number of msi"); | ||
161 | + exit(1); | ||
162 | + } | ||
163 | + | ||
164 | + socket_bits = find_last_bit(&socket_count, BITS_PER_LONG) + 1; | ||
165 | + ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG, | ||
166 | + KVM_DEV_RISCV_AIA_CONFIG_GROUP_BITS, | ||
167 | + &socket_bits, true, NULL); | ||
168 | + if (ret < 0) { | ||
169 | + error_report("KVM AIA: failed to set group_bits"); | ||
170 | + exit(1); | ||
171 | + } | ||
172 | + | ||
173 | + ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG, | ||
174 | + KVM_DEV_RISCV_AIA_CONFIG_GROUP_SHIFT, | ||
175 | + &group_shift, true, NULL); | ||
176 | + if (ret < 0) { | ||
177 | + error_report("KVM AIA: failed to set group_shift"); | ||
178 | + exit(1); | ||
179 | + } | ||
180 | + | ||
181 | + guest_bits = guest_num == 0 ? 0 : | ||
182 | + find_last_bit(&guest_num, BITS_PER_LONG) + 1; | ||
183 | + ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG, | ||
184 | + KVM_DEV_RISCV_AIA_CONFIG_GUEST_BITS, | ||
185 | + &guest_bits, true, NULL); | ||
186 | + if (ret < 0) { | ||
187 | + error_report("KVM AIA: failed to set guest_bits"); | ||
188 | + exit(1); | ||
189 | + } | ||
190 | + | ||
191 | + ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_ADDR, | ||
192 | + KVM_DEV_RISCV_AIA_ADDR_APLIC, | ||
193 | + &aplic_base, true, NULL); | ||
194 | + if (ret < 0) { | ||
195 | + error_report("KVM AIA: failed to set the base address of APLIC"); | ||
196 | + exit(1); | ||
197 | + } | ||
198 | + | ||
199 | + for (socket = 0; socket < socket_count; socket++) { | ||
200 | + socket_imsic_base = imsic_base + socket * (1U << group_shift); | ||
201 | + hart_count = riscv_socket_hart_count(machine, socket); | ||
202 | + base_hart = riscv_socket_first_hartid(machine, socket); | ||
203 | + | ||
204 | + if (max_hart_per_socket < hart_count) { | ||
205 | + max_hart_per_socket = hart_count; | ||
72 | + } | 206 | + } |
73 | + } | 207 | + |
74 | + | 208 | + for (i = 0; i < hart_count; i++) { |
75 | + acpi_table_end(linker, &table); | 209 | + imsic_addr = socket_imsic_base + i * IMSIC_HART_SIZE(guest_bits); |
76 | +} | 210 | + ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_ADDR, |
77 | + | 211 | + KVM_DEV_RISCV_AIA_ADDR_IMSIC(i + base_hart), |
78 | static void virt_acpi_build(RISCVVirtState *s, AcpiBuildTables *tables) | 212 | + &imsic_addr, true, NULL); |
79 | { | 213 | + if (ret < 0) { |
80 | GArray *table_offsets; | 214 | + error_report("KVM AIA: failed to set the IMSIC address for hart %d", i); |
81 | unsigned dsdt, xsdt; | 215 | + exit(1); |
82 | GArray *tables_blob = tables->table_data; | 216 | + } |
83 | + MachineState *ms = MACHINE(s); | ||
84 | |||
85 | table_offsets = g_array_new(false, true, | ||
86 | sizeof(uint32_t)); | ||
87 | @@ -XXX,XX +XXX,XX @@ static void virt_acpi_build(RISCVVirtState *s, AcpiBuildTables *tables) | ||
88 | s->oem_table_id); | ||
89 | } | ||
90 | |||
91 | + if (ms->numa_state->num_nodes > 0) { | ||
92 | + acpi_add_table(table_offsets, tables_blob); | ||
93 | + build_srat(tables_blob, tables->linker, s); | ||
94 | + if (ms->numa_state->have_numa_distance) { | ||
95 | + acpi_add_table(table_offsets, tables_blob); | ||
96 | + build_slit(tables_blob, tables->linker, ms, s->oem_id, | ||
97 | + s->oem_table_id); | ||
98 | + } | 217 | + } |
99 | + } | 218 | + } |
100 | + | 219 | + |
101 | /* XSDT is pointed to by RSDP */ | 220 | + hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1; |
102 | xsdt = tables_blob->len; | 221 | + ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG, |
103 | build_xsdt(tables_blob, tables->linker, table_offsets, s->oem_id, | 222 | + KVM_DEV_RISCV_AIA_CONFIG_HART_BITS, |
223 | + &hart_bits, true, NULL); | ||
224 | + if (ret < 0) { | ||
225 | + error_report("KVM AIA: failed to set hart_bits"); | ||
226 | + exit(1); | ||
227 | + } | ||
228 | + | ||
229 | + if (kvm_has_gsi_routing()) { | ||
230 | + for (uint64_t idx = 0; idx < aia_irq_num + 1; ++idx) { | ||
231 | + /* KVM AIA only has one APLIC instance */ | ||
232 | + kvm_irqchip_add_irq_route(kvm_state, idx, 0, idx); | ||
233 | + } | ||
234 | + kvm_gsi_routing_allowed = true; | ||
235 | + kvm_irqchip_commit_routes(kvm_state); | ||
236 | + } | ||
237 | + | ||
238 | + ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CTRL, | ||
239 | + KVM_DEV_RISCV_AIA_CTRL_INIT, | ||
240 | + NULL, true, NULL); | ||
241 | + if (ret < 0) { | ||
242 | + error_report("KVM AIA: initialized fail"); | ||
243 | + exit(1); | ||
244 | + } | ||
245 | + | ||
246 | + kvm_msi_via_irqfd_allowed = kvm_irqfds_enabled(); | ||
247 | } | ||
104 | -- | 248 | -- |
105 | 2.44.0 | 249 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Anup Patel <apatel@ventanamicro.com> | 1 | From: Yong-Xuan Wang <yongxuan.wang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | The writes to setipnum_le register in APLIC MSI-mode have special | 3 | KVM AIA can't emulate APLIC only. When "aia=aplic" parameter is passed, |
4 | consideration for level-triggered interrupts as-per section "4.9.2 | 4 | APLIC devices is emulated by QEMU. For "aia=aplic-imsic", remove the |
5 | Special consideration for level-sensitive interrupt sources" of the | 5 | mmio operations of APLIC when using KVM AIA and send wired interrupt |
6 | RISC-V AIA specification. | 6 | signal via KVM_IRQ_LINE API. |
7 | After KVM AIA enabled, MSI messages are delivered by KVM_SIGNAL_MSI API | ||
8 | when the IMSICs receive mmio write requests. | ||
7 | 9 | ||
8 | Particularly, the below text from the RISC-V specification defines | 10 | Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com> |
9 | the behaviour of writes to setipnum_le for level-triggered interrupts: | 11 | Reviewed-by: Jim Shu <jim.shu@sifive.com> |
10 | |||
11 | "A second option is for the interrupt service routine to write the | ||
12 | APLIC’s source identity number for the interrupt to the domain’s | ||
13 | setipnum register just before exiting. This will cause the interrupt’s | ||
14 | pending bit to be set to one again if the source is still asserting | ||
15 | an interrupt, but not if the source is not asserting an interrupt." | ||
16 | |||
17 | Fix setipnum_le write emulation for APLIC MSI-mode by implementing | ||
18 | the above behaviour in riscv_aplic_set_pending() function. | ||
19 | |||
20 | Fixes: e8f79343cfc8 ("hw/intc: Add RISC-V AIA APLIC device emulation") | ||
21 | Signed-off-by: Anup Patel <apatel@ventanamicro.com> | ||
22 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 12 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
23 | Message-ID: <20240306095722.463296-2-apatel@ventanamicro.com> | 13 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> |
14 | Message-ID: <20230727102439.22554-5-yongxuan.wang@sifive.com> | ||
24 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
25 | --- | 16 | --- |
26 | hw/intc/riscv_aplic.c | 20 ++++++++++++++++---- | 17 | hw/intc/riscv_aplic.c | 56 ++++++++++++++++++++++++++++++------------- |
27 | 1 file changed, 16 insertions(+), 4 deletions(-) | 18 | hw/intc/riscv_imsic.c | 25 +++++++++++++++---- |
19 | 2 files changed, 61 insertions(+), 20 deletions(-) | ||
28 | 20 | ||
29 | diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c | 21 | diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c |
30 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
31 | --- a/hw/intc/riscv_aplic.c | 23 | --- a/hw/intc/riscv_aplic.c |
32 | +++ b/hw/intc/riscv_aplic.c | 24 | +++ b/hw/intc/riscv_aplic.c |
33 | @@ -XXX,XX +XXX,XX @@ static void riscv_aplic_set_pending(RISCVAPLICState *aplic, | 25 | @@ -XXX,XX +XXX,XX @@ |
26 | #include "hw/irq.h" | ||
27 | #include "target/riscv/cpu.h" | ||
28 | #include "sysemu/sysemu.h" | ||
29 | +#include "sysemu/kvm.h" | ||
30 | #include "migration/vmstate.h" | ||
31 | |||
32 | #define APLIC_MAX_IDC (1UL << 14) | ||
33 | @@ -XXX,XX +XXX,XX @@ | ||
34 | |||
35 | #define APLIC_IDC_CLAIMI 0x1c | ||
36 | |||
37 | +/* | ||
38 | + * KVM AIA only supports APLIC MSI, fallback to QEMU emulation if we want to use | ||
39 | + * APLIC Wired. | ||
40 | + */ | ||
41 | +static bool is_kvm_aia(bool msimode) | ||
42 | +{ | ||
43 | + return kvm_irqchip_in_kernel() && msimode; | ||
44 | +} | ||
45 | + | ||
46 | static uint32_t riscv_aplic_read_input_word(RISCVAPLICState *aplic, | ||
47 | uint32_t word) | ||
48 | { | ||
49 | @@ -XXX,XX +XXX,XX @@ static uint32_t riscv_aplic_idc_claimi(RISCVAPLICState *aplic, uint32_t idc) | ||
50 | return topi; | ||
51 | } | ||
52 | |||
53 | +static void riscv_kvm_aplic_request(void *opaque, int irq, int level) | ||
54 | +{ | ||
55 | + kvm_set_irq(kvm_state, irq, !!level); | ||
56 | +} | ||
57 | + | ||
58 | static void riscv_aplic_request(void *opaque, int irq, int level) | ||
59 | { | ||
60 | bool update = false; | ||
61 | @@ -XXX,XX +XXX,XX @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp) | ||
62 | uint32_t i; | ||
63 | RISCVAPLICState *aplic = RISCV_APLIC(dev); | ||
64 | |||
65 | - aplic->bitfield_words = (aplic->num_irqs + 31) >> 5; | ||
66 | - aplic->sourcecfg = g_new0(uint32_t, aplic->num_irqs); | ||
67 | - aplic->state = g_new0(uint32_t, aplic->num_irqs); | ||
68 | - aplic->target = g_new0(uint32_t, aplic->num_irqs); | ||
69 | - if (!aplic->msimode) { | ||
70 | - for (i = 0; i < aplic->num_irqs; i++) { | ||
71 | - aplic->target[i] = 1; | ||
72 | + if (!is_kvm_aia(aplic->msimode)) { | ||
73 | + aplic->bitfield_words = (aplic->num_irqs + 31) >> 5; | ||
74 | + aplic->sourcecfg = g_new0(uint32_t, aplic->num_irqs); | ||
75 | + aplic->state = g_new0(uint32_t, aplic->num_irqs); | ||
76 | + aplic->target = g_new0(uint32_t, aplic->num_irqs); | ||
77 | + if (!aplic->msimode) { | ||
78 | + for (i = 0; i < aplic->num_irqs; i++) { | ||
79 | + aplic->target[i] = 1; | ||
80 | + } | ||
81 | } | ||
82 | - } | ||
83 | - aplic->idelivery = g_new0(uint32_t, aplic->num_harts); | ||
84 | - aplic->iforce = g_new0(uint32_t, aplic->num_harts); | ||
85 | - aplic->ithreshold = g_new0(uint32_t, aplic->num_harts); | ||
86 | + aplic->idelivery = g_new0(uint32_t, aplic->num_harts); | ||
87 | + aplic->iforce = g_new0(uint32_t, aplic->num_harts); | ||
88 | + aplic->ithreshold = g_new0(uint32_t, aplic->num_harts); | ||
89 | |||
90 | - memory_region_init_io(&aplic->mmio, OBJECT(dev), &riscv_aplic_ops, aplic, | ||
91 | - TYPE_RISCV_APLIC, aplic->aperture_size); | ||
92 | - sysbus_init_mmio(SYS_BUS_DEVICE(dev), &aplic->mmio); | ||
93 | + memory_region_init_io(&aplic->mmio, OBJECT(dev), &riscv_aplic_ops, | ||
94 | + aplic, TYPE_RISCV_APLIC, aplic->aperture_size); | ||
95 | + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &aplic->mmio); | ||
96 | + } | ||
97 | |||
98 | /* | ||
99 | * Only root APLICs have hardware IRQ lines. All non-root APLICs | ||
100 | * have IRQ lines delegated by their parent APLIC. | ||
101 | */ | ||
102 | if (!aplic->parent) { | ||
103 | - qdev_init_gpio_in(dev, riscv_aplic_request, aplic->num_irqs); | ||
104 | + if (is_kvm_aia(aplic->msimode)) { | ||
105 | + qdev_init_gpio_in(dev, riscv_kvm_aplic_request, aplic->num_irqs); | ||
106 | + } else { | ||
107 | + qdev_init_gpio_in(dev, riscv_aplic_request, aplic->num_irqs); | ||
108 | + } | ||
34 | } | 109 | } |
35 | 110 | ||
36 | sm = sourcecfg & APLIC_SOURCECFG_SM_MASK; | 111 | /* Create output IRQ lines for non-MSI mode */ |
37 | - if ((sm == APLIC_SOURCECFG_SM_INACTIVE) || | 112 | @@ -XXX,XX +XXX,XX @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, |
38 | - ((!aplic->msimode || (aplic->msimode && !pending)) && | 113 | qdev_prop_set_bit(dev, "mmode", mmode); |
39 | - ((sm == APLIC_SOURCECFG_SM_LEVEL_HIGH) || | 114 | |
40 | - (sm == APLIC_SOURCECFG_SM_LEVEL_LOW)))) { | 115 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); |
41 | + if (sm == APLIC_SOURCECFG_SM_INACTIVE) { | 116 | - sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); |
42 | return; | 117 | + |
118 | + if (!is_kvm_aia(msimode)) { | ||
119 | + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); | ||
120 | + } | ||
121 | |||
122 | if (parent) { | ||
123 | riscv_aplic_add_child(parent, dev); | ||
124 | diff --git a/hw/intc/riscv_imsic.c b/hw/intc/riscv_imsic.c | ||
125 | index XXXXXXX..XXXXXXX 100644 | ||
126 | --- a/hw/intc/riscv_imsic.c | ||
127 | +++ b/hw/intc/riscv_imsic.c | ||
128 | @@ -XXX,XX +XXX,XX @@ | ||
129 | #include "target/riscv/cpu.h" | ||
130 | #include "target/riscv/cpu_bits.h" | ||
131 | #include "sysemu/sysemu.h" | ||
132 | +#include "sysemu/kvm.h" | ||
133 | #include "migration/vmstate.h" | ||
134 | |||
135 | #define IMSIC_MMIO_PAGE_LE 0x00 | ||
136 | @@ -XXX,XX +XXX,XX @@ static void riscv_imsic_write(void *opaque, hwaddr addr, uint64_t value, | ||
137 | goto err; | ||
43 | } | 138 | } |
44 | 139 | ||
45 | + if ((sm == APLIC_SOURCECFG_SM_LEVEL_HIGH) || | 140 | +#if defined(CONFIG_KVM) |
46 | + (sm == APLIC_SOURCECFG_SM_LEVEL_LOW)) { | 141 | + if (kvm_irqchip_in_kernel()) { |
47 | + if (!aplic->msimode || (aplic->msimode && !pending)) { | 142 | + struct kvm_msi msi; |
48 | + return; | 143 | + |
49 | + } | 144 | + msi.address_lo = extract64(imsic->mmio.addr + addr, 0, 32); |
50 | + if ((aplic->state[irq] & APLIC_ISTATE_INPUT) && | 145 | + msi.address_hi = extract64(imsic->mmio.addr + addr, 32, 32); |
51 | + (sm == APLIC_SOURCECFG_SM_LEVEL_LOW)) { | 146 | + msi.data = le32_to_cpu(value); |
52 | + return; | 147 | + |
53 | + } | 148 | + kvm_vm_ioctl(kvm_state, KVM_SIGNAL_MSI, &msi); |
54 | + if (!(aplic->state[irq] & APLIC_ISTATE_INPUT) && | 149 | + |
55 | + (sm == APLIC_SOURCECFG_SM_LEVEL_HIGH)) { | 150 | + return; |
56 | + return; | ||
57 | + } | ||
58 | + } | 151 | + } |
152 | +#endif | ||
59 | + | 153 | + |
60 | riscv_aplic_set_pending_raw(aplic, irq, pending); | 154 | /* Writes only supported for MSI little-endian registers */ |
61 | } | 155 | page = addr >> IMSIC_MMIO_PAGE_SHIFT; |
62 | 156 | if ((addr & (IMSIC_MMIO_PAGE_SZ - 1)) == IMSIC_MMIO_PAGE_LE) { | |
157 | @@ -XXX,XX +XXX,XX @@ static void riscv_imsic_realize(DeviceState *dev, Error **errp) | ||
158 | CPUState *cpu = cpu_by_arch_id(imsic->hartid); | ||
159 | CPURISCVState *env = cpu ? cpu->env_ptr : NULL; | ||
160 | |||
161 | - imsic->num_eistate = imsic->num_pages * imsic->num_irqs; | ||
162 | - imsic->eidelivery = g_new0(uint32_t, imsic->num_pages); | ||
163 | - imsic->eithreshold = g_new0(uint32_t, imsic->num_pages); | ||
164 | - imsic->eistate = g_new0(uint32_t, imsic->num_eistate); | ||
165 | + if (!kvm_irqchip_in_kernel()) { | ||
166 | + imsic->num_eistate = imsic->num_pages * imsic->num_irqs; | ||
167 | + imsic->eidelivery = g_new0(uint32_t, imsic->num_pages); | ||
168 | + imsic->eithreshold = g_new0(uint32_t, imsic->num_pages); | ||
169 | + imsic->eistate = g_new0(uint32_t, imsic->num_eistate); | ||
170 | + } | ||
171 | |||
172 | memory_region_init_io(&imsic->mmio, OBJECT(dev), &riscv_imsic_ops, | ||
173 | imsic, TYPE_RISCV_IMSIC, | ||
63 | -- | 174 | -- |
64 | 2.44.0 | 175 | 2.41.0 |
65 | |||
66 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Yong-Xuan Wang <yongxuan.wang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | The 'virt' machine makes assumptions on the Advanced Core-Local | 3 | Select KVM AIA when the host kernel has in-kernel AIA chip support. |
4 | Interruptor, or aclint, based on 'tcg_enabled()' conditionals. This | 4 | Since KVM AIA only has one APLIC instance, we map the QEMU APLIC |
5 | will impact MSI related tests support when adding a RISC-V 'virt' libqos | 5 | devices to KVM APLIC. |
6 | machine. The accelerator used in that case, 'qtest', isn't being | ||
7 | accounted for and we'll error out if we try to enable aclint. | ||
8 | 6 | ||
9 | Create a new virt_aclint_allowed() helper to gate the aclint code | 7 | Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com> |
10 | considering both TCG and 'qtest' accelerators. The error message is | 8 | Reviewed-by: Jim Shu <jim.shu@sifive.com> |
11 | left untouched, mentioning TCG only, because we don't expect the | 9 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
12 | regular user to be aware of 'qtest'. | 10 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> |
13 | 11 | Message-ID: <20230727102439.22554-6-yongxuan.wang@sifive.com> | |
14 | We want to add 'qtest' support for aclint only, leaving the TCG specific | ||
15 | bits out of it. This is done by changing the current format we use | ||
16 | today: | ||
17 | |||
18 | if (tcg_enabled()) { | ||
19 | if (s->have_aclint) { - aclint logic - } | ||
20 | else { - non-aclint, TCG logic - } | ||
21 | } | ||
22 | |||
23 | into: | ||
24 | |||
25 | if (virt_aclint_allowed() && s->have_aclint) { | ||
26 | - aclint logic - | ||
27 | } else if (tcg_enabled()) { | ||
28 | - non-aclint, TCG logic - | ||
29 | } | ||
30 | |||
31 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
32 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
33 | Message-ID: <20240217192607.32565-6-dbarboza@ventanamicro.com> | ||
34 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
35 | --- | 13 | --- |
36 | hw/riscv/virt.c | 52 +++++++++++++++++++++++++------------------------ | 14 | hw/riscv/virt.c | 94 +++++++++++++++++++++++++++++++++---------------- |
37 | 1 file changed, 27 insertions(+), 25 deletions(-) | 15 | 1 file changed, 63 insertions(+), 31 deletions(-) |
38 | 16 | ||
39 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | 17 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c |
40 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
41 | --- a/hw/riscv/virt.c | 19 | --- a/hw/riscv/virt.c |
42 | +++ b/hw/riscv/virt.c | 20 | +++ b/hw/riscv/virt.c |
43 | @@ -XXX,XX +XXX,XX @@ | 21 | @@ -XXX,XX +XXX,XX @@ |
44 | #include "sysemu/tcg.h" | 22 | #include "hw/riscv/virt.h" |
45 | #include "sysemu/kvm.h" | 23 | #include "hw/riscv/boot.h" |
46 | #include "sysemu/tpm.h" | 24 | #include "hw/riscv/numa.h" |
47 | +#include "sysemu/qtest.h" | 25 | +#include "kvm_riscv.h" |
48 | #include "hw/pci/pci.h" | 26 | #include "hw/intc/riscv_aclint.h" |
49 | #include "hw/pci-host/gpex.h" | 27 | #include "hw/intc/riscv_aplic.h" |
50 | #include "hw/display/ramfb.h" | 28 | #include "hw/intc/riscv_imsic.h" |
51 | @@ -XXX,XX +XXX,XX @@ static bool virt_use_kvm_aia(RISCVVirtState *s) | 29 | @@ -XXX,XX +XXX,XX @@ |
52 | return kvm_irqchip_in_kernel() && s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC; | 30 | #error "Can't accommodate all IMSIC groups in address space" |
53 | } | 31 | #endif |
54 | 32 | ||
55 | +static bool virt_aclint_allowed(void) | 33 | +/* KVM AIA only supports APLIC MSI. APLIC Wired is always emulated by QEMU. */ |
34 | +static bool virt_use_kvm_aia(RISCVVirtState *s) | ||
56 | +{ | 35 | +{ |
57 | + return tcg_enabled() || qtest_enabled(); | 36 | + return kvm_irqchip_in_kernel() && s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC; |
58 | +} | 37 | +} |
59 | + | 38 | + |
60 | static const MemMapEntry virt_memmap[] = { | 39 | static const MemMapEntry virt_memmap[] = { |
61 | [VIRT_DEBUG] = { 0x0, 0x100 }, | 40 | [VIRT_DEBUG] = { 0x0, 0x100 }, |
62 | [VIRT_MROM] = { 0x1000, 0xf000 }, | 41 | [VIRT_MROM] = { 0x1000, 0xf000 }, |
42 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_one_aplic(RISCVVirtState *s, int socket, | ||
43 | uint32_t *intc_phandles, | ||
44 | uint32_t aplic_phandle, | ||
45 | uint32_t aplic_child_phandle, | ||
46 | - bool m_mode) | ||
47 | + bool m_mode, int num_harts) | ||
48 | { | ||
49 | int cpu; | ||
50 | char *aplic_name; | ||
51 | uint32_t *aplic_cells; | ||
52 | MachineState *ms = MACHINE(s); | ||
53 | |||
54 | - aplic_cells = g_new0(uint32_t, s->soc[socket].num_harts * 2); | ||
55 | + aplic_cells = g_new0(uint32_t, num_harts * 2); | ||
56 | |||
57 | - for (cpu = 0; cpu < s->soc[socket].num_harts; cpu++) { | ||
58 | + for (cpu = 0; cpu < num_harts; cpu++) { | ||
59 | aplic_cells[cpu * 2 + 0] = cpu_to_be32(intc_phandles[cpu]); | ||
60 | aplic_cells[cpu * 2 + 1] = cpu_to_be32(m_mode ? IRQ_M_EXT : IRQ_S_EXT); | ||
61 | } | ||
62 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_one_aplic(RISCVVirtState *s, int socket, | ||
63 | |||
64 | if (s->aia_type == VIRT_AIA_TYPE_APLIC) { | ||
65 | qemu_fdt_setprop(ms->fdt, aplic_name, "interrupts-extended", | ||
66 | - aplic_cells, | ||
67 | - s->soc[socket].num_harts * sizeof(uint32_t) * 2); | ||
68 | + aplic_cells, num_harts * sizeof(uint32_t) * 2); | ||
69 | } else { | ||
70 | qemu_fdt_setprop_cell(ms->fdt, aplic_name, "msi-parent", msi_phandle); | ||
71 | } | ||
72 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_aplic(RISCVVirtState *s, | ||
73 | uint32_t msi_s_phandle, | ||
74 | uint32_t *phandle, | ||
75 | uint32_t *intc_phandles, | ||
76 | - uint32_t *aplic_phandles) | ||
77 | + uint32_t *aplic_phandles, | ||
78 | + int num_harts) | ||
79 | { | ||
80 | char *aplic_name; | ||
81 | unsigned long aplic_addr; | ||
82 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_aplic(RISCVVirtState *s, | ||
83 | create_fdt_one_aplic(s, socket, aplic_addr, memmap[VIRT_APLIC_M].size, | ||
84 | msi_m_phandle, intc_phandles, | ||
85 | aplic_m_phandle, aplic_s_phandle, | ||
86 | - true); | ||
87 | + true, num_harts); | ||
88 | } | ||
89 | |||
90 | /* S-level APLIC node */ | ||
91 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_aplic(RISCVVirtState *s, | ||
92 | create_fdt_one_aplic(s, socket, aplic_addr, memmap[VIRT_APLIC_S].size, | ||
93 | msi_s_phandle, intc_phandles, | ||
94 | aplic_s_phandle, 0, | ||
95 | - false); | ||
96 | + false, num_harts); | ||
97 | |||
98 | aplic_name = g_strdup_printf("/soc/aplic@%lx", aplic_addr); | ||
99 | |||
63 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, | 100 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, |
64 | 101 | *msi_pcie_phandle = msi_s_phandle; | |
65 | create_fdt_socket_memory(s, memmap, socket); | 102 | } |
66 | 103 | ||
67 | - if (tcg_enabled()) { | 104 | - phandle_pos = ms->smp.cpus; |
68 | - if (s->have_aclint) { | 105 | - for (socket = (socket_count - 1); socket >= 0; socket--) { |
69 | - create_fdt_socket_aclint(s, memmap, socket, | 106 | - phandle_pos -= s->soc[socket].num_harts; |
70 | - &intc_phandles[phandle_pos]); | 107 | - |
71 | - } else { | 108 | - if (s->aia_type == VIRT_AIA_TYPE_NONE) { |
72 | - create_fdt_socket_clint(s, memmap, socket, | 109 | - create_fdt_socket_plic(s, memmap, socket, phandle, |
73 | - &intc_phandles[phandle_pos]); | 110 | - &intc_phandles[phandle_pos], xplic_phandles); |
74 | - } | 111 | - } else { |
75 | + if (virt_aclint_allowed() && s->have_aclint) { | 112 | - create_fdt_socket_aplic(s, memmap, socket, |
76 | + create_fdt_socket_aclint(s, memmap, socket, | 113 | - msi_m_phandle, msi_s_phandle, phandle, |
77 | + &intc_phandles[phandle_pos]); | 114 | - &intc_phandles[phandle_pos], xplic_phandles); |
78 | + } else if (tcg_enabled()) { | 115 | + /* KVM AIA only has one APLIC instance */ |
79 | + create_fdt_socket_clint(s, memmap, socket, | 116 | + if (virt_use_kvm_aia(s)) { |
80 | + &intc_phandles[phandle_pos]); | 117 | + create_fdt_socket_aplic(s, memmap, 0, |
118 | + msi_m_phandle, msi_s_phandle, phandle, | ||
119 | + &intc_phandles[0], xplic_phandles, | ||
120 | + ms->smp.cpus); | ||
121 | + } else { | ||
122 | + phandle_pos = ms->smp.cpus; | ||
123 | + for (socket = (socket_count - 1); socket >= 0; socket--) { | ||
124 | + phandle_pos -= s->soc[socket].num_harts; | ||
125 | + | ||
126 | + if (s->aia_type == VIRT_AIA_TYPE_NONE) { | ||
127 | + create_fdt_socket_plic(s, memmap, socket, phandle, | ||
128 | + &intc_phandles[phandle_pos], | ||
129 | + xplic_phandles); | ||
130 | + } else { | ||
131 | + create_fdt_socket_aplic(s, memmap, socket, | ||
132 | + msi_m_phandle, msi_s_phandle, phandle, | ||
133 | + &intc_phandles[phandle_pos], | ||
134 | + xplic_phandles, | ||
135 | + s->soc[socket].num_harts); | ||
136 | + } | ||
81 | } | 137 | } |
82 | } | 138 | } |
83 | 139 | ||
140 | g_free(intc_phandles); | ||
141 | |||
142 | - for (socket = 0; socket < socket_count; socket++) { | ||
143 | - if (socket == 0) { | ||
144 | - *irq_mmio_phandle = xplic_phandles[socket]; | ||
145 | - *irq_virtio_phandle = xplic_phandles[socket]; | ||
146 | - *irq_pcie_phandle = xplic_phandles[socket]; | ||
147 | - } | ||
148 | - if (socket == 1) { | ||
149 | - *irq_virtio_phandle = xplic_phandles[socket]; | ||
150 | - *irq_pcie_phandle = xplic_phandles[socket]; | ||
151 | - } | ||
152 | - if (socket == 2) { | ||
153 | - *irq_pcie_phandle = xplic_phandles[socket]; | ||
154 | + if (virt_use_kvm_aia(s)) { | ||
155 | + *irq_mmio_phandle = xplic_phandles[0]; | ||
156 | + *irq_virtio_phandle = xplic_phandles[0]; | ||
157 | + *irq_pcie_phandle = xplic_phandles[0]; | ||
158 | + } else { | ||
159 | + for (socket = 0; socket < socket_count; socket++) { | ||
160 | + if (socket == 0) { | ||
161 | + *irq_mmio_phandle = xplic_phandles[socket]; | ||
162 | + *irq_virtio_phandle = xplic_phandles[socket]; | ||
163 | + *irq_pcie_phandle = xplic_phandles[socket]; | ||
164 | + } | ||
165 | + if (socket == 1) { | ||
166 | + *irq_virtio_phandle = xplic_phandles[socket]; | ||
167 | + *irq_pcie_phandle = xplic_phandles[socket]; | ||
168 | + } | ||
169 | + if (socket == 2) { | ||
170 | + *irq_pcie_phandle = xplic_phandles[socket]; | ||
171 | + } | ||
172 | } | ||
173 | } | ||
174 | |||
84 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine) | 175 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine) |
85 | exit(1); | 176 | } |
86 | } | 177 | } |
87 | 178 | ||
88 | - if (!tcg_enabled() && s->have_aclint) { | 179 | + if (virt_use_kvm_aia(s)) { |
89 | + if (!virt_aclint_allowed() && s->have_aclint) { | 180 | + kvm_riscv_aia_create(machine, IMSIC_MMIO_GROUP_MIN_SHIFT, |
90 | error_report("'aclint' is only available with TCG acceleration"); | 181 | + VIRT_IRQCHIP_NUM_SOURCES, VIRT_IRQCHIP_NUM_MSIS, |
91 | exit(1); | 182 | + memmap[VIRT_APLIC_S].base, |
92 | } | 183 | + memmap[VIRT_IMSIC_S].base, |
93 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine) | 184 | + s->aia_guests); |
94 | hart_count, &error_abort); | 185 | + } |
95 | sysbus_realize(SYS_BUS_DEVICE(&s->soc[i]), &error_fatal); | 186 | + |
96 | 187 | if (riscv_is_32bit(&s->soc[0])) { | |
97 | - if (tcg_enabled()) { | 188 | #if HOST_LONG_BITS == 64 |
98 | - if (s->have_aclint) { | 189 | /* limit RAM size in a 32-bit system */ |
99 | - if (s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC) { | ||
100 | - /* Per-socket ACLINT MTIMER */ | ||
101 | - riscv_aclint_mtimer_create(memmap[VIRT_CLINT].base + | ||
102 | + if (virt_aclint_allowed() && s->have_aclint) { | ||
103 | + if (s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC) { | ||
104 | + /* Per-socket ACLINT MTIMER */ | ||
105 | + riscv_aclint_mtimer_create(memmap[VIRT_CLINT].base + | ||
106 | i * RISCV_ACLINT_DEFAULT_MTIMER_SIZE, | ||
107 | RISCV_ACLINT_DEFAULT_MTIMER_SIZE, | ||
108 | base_hartid, hart_count, | ||
109 | RISCV_ACLINT_DEFAULT_MTIMECMP, | ||
110 | RISCV_ACLINT_DEFAULT_MTIME, | ||
111 | RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, true); | ||
112 | - } else { | ||
113 | - /* Per-socket ACLINT MSWI, MTIMER, and SSWI */ | ||
114 | - riscv_aclint_swi_create(memmap[VIRT_CLINT].base + | ||
115 | + } else { | ||
116 | + /* Per-socket ACLINT MSWI, MTIMER, and SSWI */ | ||
117 | + riscv_aclint_swi_create(memmap[VIRT_CLINT].base + | ||
118 | i * memmap[VIRT_CLINT].size, | ||
119 | base_hartid, hart_count, false); | ||
120 | - riscv_aclint_mtimer_create(memmap[VIRT_CLINT].base + | ||
121 | + riscv_aclint_mtimer_create(memmap[VIRT_CLINT].base + | ||
122 | i * memmap[VIRT_CLINT].size + | ||
123 | RISCV_ACLINT_SWI_SIZE, | ||
124 | RISCV_ACLINT_DEFAULT_MTIMER_SIZE, | ||
125 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine) | ||
126 | RISCV_ACLINT_DEFAULT_MTIMECMP, | ||
127 | RISCV_ACLINT_DEFAULT_MTIME, | ||
128 | RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, true); | ||
129 | - riscv_aclint_swi_create(memmap[VIRT_ACLINT_SSWI].base + | ||
130 | + riscv_aclint_swi_create(memmap[VIRT_ACLINT_SSWI].base + | ||
131 | i * memmap[VIRT_ACLINT_SSWI].size, | ||
132 | base_hartid, hart_count, true); | ||
133 | - } | ||
134 | - } else { | ||
135 | - /* Per-socket SiFive CLINT */ | ||
136 | - riscv_aclint_swi_create( | ||
137 | + } | ||
138 | + } else if (tcg_enabled()) { | ||
139 | + /* Per-socket SiFive CLINT */ | ||
140 | + riscv_aclint_swi_create( | ||
141 | memmap[VIRT_CLINT].base + i * memmap[VIRT_CLINT].size, | ||
142 | base_hartid, hart_count, false); | ||
143 | - riscv_aclint_mtimer_create(memmap[VIRT_CLINT].base + | ||
144 | + riscv_aclint_mtimer_create(memmap[VIRT_CLINT].base + | ||
145 | i * memmap[VIRT_CLINT].size + RISCV_ACLINT_SWI_SIZE, | ||
146 | RISCV_ACLINT_DEFAULT_MTIMER_SIZE, base_hartid, hart_count, | ||
147 | RISCV_ACLINT_DEFAULT_MTIMECMP, RISCV_ACLINT_DEFAULT_MTIME, | ||
148 | RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, true); | ||
149 | - } | ||
150 | } | ||
151 | |||
152 | /* Per-socket interrupt controller */ | ||
153 | -- | 190 | -- |
154 | 2.44.0 | 191 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Christoph Müllner <christoph.muellner@vrull.eu> | 1 | From: Conor Dooley <conor.dooley@microchip.com> |
---|---|---|---|
2 | 2 | ||
3 | Running test-fcvtmod triggers the following deprecation warning: | 3 | On a dtb dumped from the virt machine, dt-validate complains: |
4 | warning: CPU property 'Zfa' is deprecated. Please use 'zfa' instead | 4 | soc: pmu: {'riscv,event-to-mhpmcounters': [[1, 1, 524281], [2, 2, 524284], [65561, 65561, 524280], [65563, 65563, 524280], [65569, 65569, 524280]], 'compatible': ['riscv,pmu']} should not be valid under {'type': 'object'} |
5 | Let's fix that. | 5 | from schema $id: http://devicetree.org/schemas/simple-bus.yaml# |
6 | That's pretty cryptic, but running the dtb back through dtc produces | ||
7 | something a lot more reasonable: | ||
8 | Warning (simple_bus_reg): /soc/pmu: missing or empty reg/ranges property | ||
6 | 9 | ||
7 | Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu> | 10 | Moving the riscv,pmu node out of the soc bus solves the problem. |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 11 | |
12 | Signed-off-by: Conor Dooley <conor.dooley@microchip.com> | ||
13 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 14 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 15 | Message-ID: <20230727-groom-decline-2c57ce42841c@spud> |
11 | Message-ID: <20240229180656.1208881-1-christoph.muellner@vrull.eu> | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | --- | 17 | --- |
14 | tests/tcg/riscv64/Makefile.target | 2 +- | 18 | hw/riscv/virt.c | 2 +- |
15 | 1 file changed, 1 insertion(+), 1 deletion(-) | 19 | 1 file changed, 1 insertion(+), 1 deletion(-) |
16 | 20 | ||
17 | diff --git a/tests/tcg/riscv64/Makefile.target b/tests/tcg/riscv64/Makefile.target | 21 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c |
18 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/tests/tcg/riscv64/Makefile.target | 23 | --- a/hw/riscv/virt.c |
20 | +++ b/tests/tcg/riscv64/Makefile.target | 24 | +++ b/hw/riscv/virt.c |
21 | @@ -XXX,XX +XXX,XX @@ run-test-aes: QEMU_OPTS += -cpu rv64,zk=on | 25 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_pmu(RISCVVirtState *s) |
22 | TESTS += test-fcvtmod | 26 | MachineState *ms = MACHINE(s); |
23 | test-fcvtmod: CFLAGS += -march=rv64imafdc | 27 | RISCVCPU hart = s->soc[0].harts[0]; |
24 | test-fcvtmod: LDFLAGS += -static | 28 | |
25 | -run-test-fcvtmod: QEMU_OPTS += -cpu rv64,d=true,Zfa=true | 29 | - pmu_name = g_strdup_printf("/soc/pmu"); |
26 | +run-test-fcvtmod: QEMU_OPTS += -cpu rv64,d=true,zfa=true | 30 | + pmu_name = g_strdup_printf("/pmu"); |
31 | qemu_fdt_add_subnode(ms->fdt, pmu_name); | ||
32 | qemu_fdt_setprop_string(ms->fdt, pmu_name, "compatible", "riscv,pmu"); | ||
33 | riscv_pmu_generate_fdt_node(ms->fdt, hart.cfg.pmu_num, pmu_name); | ||
27 | -- | 34 | -- |
28 | 2.44.0 | 35 | 2.41.0 |
29 | |||
30 | diff view generated by jsdifflib |
1 | From: Andrew Jones <ajones@ventanamicro.com> | 1 | From: Weiwei Li <liweiwei@iscas.ac.cn> |
---|---|---|---|
2 | 2 | ||
3 | Gate hardware A/D PTE bit updating on {m,h}envcfg.ADUE and only | 3 | The Svadu specification updated the name of the *envcfg bit from |
4 | enable menvcfg.ADUE on reset if svade has not been selected. Now | 4 | HADE to ADUE. |
5 | that we also consider svade, we have four possible configurations: | ||
6 | 5 | ||
7 | 1) !svade && !svadu | 6 | Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn> |
8 | use hardware updating and there's no way to disable it | 7 | Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn> |
9 | (the default, which maintains past behavior. Maintaining | ||
10 | the default, even with !svadu is a change that fixes [1]) | ||
11 | |||
12 | 2) !svade && svadu | ||
13 | use hardware updating, but also provide {m,h}envcfg.ADUE, | ||
14 | allowing software to switch to exception mode | ||
15 | (being able to switch is a change which fixes [1]) | ||
16 | |||
17 | 3) svade && !svadu | ||
18 | use exception mode and there's no way to switch to hardware | ||
19 | updating | ||
20 | (this behavior change fixes [2]) | ||
21 | |||
22 | 4) svade && svadu | ||
23 | use exception mode, but also provide {m,h}envcfg.ADUE, | ||
24 | allowing software to switch to hardware updating | ||
25 | (this behavior change fixes [2]) | ||
26 | |||
27 | Fixes: 0af3f115e68e ("target/riscv: Add *envcfg.HADE related check in address translation") [1] | ||
28 | Fixes: 48531f5adb2a ("target/riscv: implement svade") [2] | ||
29 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 8 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
30 | Signed-off-by: Andrew Jones <ajones@ventanamicro.com> | 9 | Message-ID: <20230816141916.66898-1-liweiwei@iscas.ac.cn> |
31 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
32 | Message-ID: <20240215223955.969568-6-dbarboza@ventanamicro.com> | ||
33 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
34 | --- | 11 | --- |
35 | target/riscv/cpu.c | 3 ++- | 12 | target/riscv/cpu_bits.h | 8 ++++---- |
36 | target/riscv/cpu_helper.c | 19 +++++++++++++++---- | 13 | target/riscv/cpu.c | 4 ++-- |
37 | target/riscv/tcg/tcg-cpu.c | 15 +++++---------- | 14 | target/riscv/cpu_helper.c | 6 +++--- |
38 | 3 files changed, 22 insertions(+), 15 deletions(-) | 15 | target/riscv/csr.c | 12 ++++++------ |
16 | 4 files changed, 15 insertions(+), 15 deletions(-) | ||
39 | 17 | ||
18 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/target/riscv/cpu_bits.h | ||
21 | +++ b/target/riscv/cpu_bits.h | ||
22 | @@ -XXX,XX +XXX,XX @@ typedef enum RISCVException { | ||
23 | #define MENVCFG_CBIE (3UL << 4) | ||
24 | #define MENVCFG_CBCFE BIT(6) | ||
25 | #define MENVCFG_CBZE BIT(7) | ||
26 | -#define MENVCFG_HADE (1ULL << 61) | ||
27 | +#define MENVCFG_ADUE (1ULL << 61) | ||
28 | #define MENVCFG_PBMTE (1ULL << 62) | ||
29 | #define MENVCFG_STCE (1ULL << 63) | ||
30 | |||
31 | /* For RV32 */ | ||
32 | -#define MENVCFGH_HADE BIT(29) | ||
33 | +#define MENVCFGH_ADUE BIT(29) | ||
34 | #define MENVCFGH_PBMTE BIT(30) | ||
35 | #define MENVCFGH_STCE BIT(31) | ||
36 | |||
37 | @@ -XXX,XX +XXX,XX @@ typedef enum RISCVException { | ||
38 | #define HENVCFG_CBIE MENVCFG_CBIE | ||
39 | #define HENVCFG_CBCFE MENVCFG_CBCFE | ||
40 | #define HENVCFG_CBZE MENVCFG_CBZE | ||
41 | -#define HENVCFG_HADE MENVCFG_HADE | ||
42 | +#define HENVCFG_ADUE MENVCFG_ADUE | ||
43 | #define HENVCFG_PBMTE MENVCFG_PBMTE | ||
44 | #define HENVCFG_STCE MENVCFG_STCE | ||
45 | |||
46 | /* For RV32 */ | ||
47 | -#define HENVCFGH_HADE MENVCFGH_HADE | ||
48 | +#define HENVCFGH_ADUE MENVCFGH_ADUE | ||
49 | #define HENVCFGH_PBMTE MENVCFGH_PBMTE | ||
50 | #define HENVCFGH_STCE MENVCFGH_STCE | ||
51 | |||
40 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 52 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
41 | index XXXXXXX..XXXXXXX 100644 | 53 | index XXXXXXX..XXXXXXX 100644 |
42 | --- a/target/riscv/cpu.c | 54 | --- a/target/riscv/cpu.c |
43 | +++ b/target/riscv/cpu.c | 55 | +++ b/target/riscv/cpu.c |
44 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset_hold(Object *obj) | 56 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset_hold(Object *obj) |
45 | env->two_stage_lookup = false; | 57 | env->two_stage_lookup = false; |
46 | 58 | ||
47 | env->menvcfg = (cpu->cfg.ext_svpbmt ? MENVCFG_PBMTE : 0) | | 59 | env->menvcfg = (cpu->cfg.ext_svpbmt ? MENVCFG_PBMTE : 0) | |
48 | - (cpu->cfg.ext_svadu ? MENVCFG_ADUE : 0); | 60 | - (cpu->cfg.ext_svadu ? MENVCFG_HADE : 0); |
49 | + (!cpu->cfg.ext_svade && cpu->cfg.ext_svadu ? | 61 | + (cpu->cfg.ext_svadu ? MENVCFG_ADUE : 0); |
50 | + MENVCFG_ADUE : 0); | 62 | env->henvcfg = (cpu->cfg.ext_svpbmt ? HENVCFG_PBMTE : 0) | |
51 | env->henvcfg = 0; | 63 | - (cpu->cfg.ext_svadu ? HENVCFG_HADE : 0); |
64 | + (cpu->cfg.ext_svadu ? HENVCFG_ADUE : 0); | ||
52 | 65 | ||
53 | /* Initialized default priorities of local interrupts. */ | 66 | /* Initialized default priorities of local interrupts. */ |
67 | for (i = 0; i < ARRAY_SIZE(env->miprio); i++) { | ||
54 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 68 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
55 | index XXXXXXX..XXXXXXX 100644 | 69 | index XXXXXXX..XXXXXXX 100644 |
56 | --- a/target/riscv/cpu_helper.c | 70 | --- a/target/riscv/cpu_helper.c |
57 | +++ b/target/riscv/cpu_helper.c | 71 | +++ b/target/riscv/cpu_helper.c |
58 | @@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, | 72 | @@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, |
59 | } | 73 | } |
60 | 74 | ||
61 | bool pbmte = env->menvcfg & MENVCFG_PBMTE; | 75 | bool pbmte = env->menvcfg & MENVCFG_PBMTE; |
62 | - bool adue = env->menvcfg & MENVCFG_ADUE; | 76 | - bool hade = env->menvcfg & MENVCFG_HADE; |
63 | + bool svade = riscv_cpu_cfg(env)->ext_svade; | 77 | + bool adue = env->menvcfg & MENVCFG_ADUE; |
64 | + bool svadu = riscv_cpu_cfg(env)->ext_svadu; | ||
65 | + bool adue = svadu ? env->menvcfg & MENVCFG_ADUE : !svade; | ||
66 | 78 | ||
67 | if (first_stage && two_stage && env->virt_enabled) { | 79 | if (first_stage && two_stage && env->virt_enabled) { |
68 | pbmte = pbmte && (env->henvcfg & HENVCFG_PBMTE); | 80 | pbmte = pbmte && (env->henvcfg & HENVCFG_PBMTE); |
81 | - hade = hade && (env->henvcfg & HENVCFG_HADE); | ||
82 | + adue = adue && (env->henvcfg & HENVCFG_ADUE); | ||
83 | } | ||
84 | |||
85 | int ptshift = (levels - 1) * ptidxbits; | ||
69 | @@ -XXX,XX +XXX,XX @@ restart: | 86 | @@ -XXX,XX +XXX,XX @@ restart: |
70 | return TRANSLATE_FAIL; | ||
71 | } | ||
72 | |||
73 | - /* If necessary, set accessed and dirty bits. */ | ||
74 | - target_ulong updated_pte = pte | PTE_A | | ||
75 | - (access_type == MMU_DATA_STORE ? PTE_D : 0); | ||
76 | + target_ulong updated_pte = pte; | ||
77 | + | ||
78 | + /* | ||
79 | + * If ADUE is enabled, set accessed and dirty bits. | ||
80 | + * Otherwise raise an exception if necessary. | ||
81 | + */ | ||
82 | + if (adue) { | ||
83 | + updated_pte |= PTE_A | (access_type == MMU_DATA_STORE ? PTE_D : 0); | ||
84 | + } else if (!(pte & PTE_A) || | ||
85 | + (access_type == MMU_DATA_STORE && !(pte & PTE_D))) { | ||
86 | + return TRANSLATE_FAIL; | ||
87 | + } | ||
88 | 87 | ||
89 | /* Page table updates need to be atomic with MTTCG enabled */ | 88 | /* Page table updates need to be atomic with MTTCG enabled */ |
90 | if (updated_pte != pte && !is_debug) { | 89 | if (updated_pte != pte && !is_debug) { |
91 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | 90 | - if (!hade) { |
91 | + if (!adue) { | ||
92 | return TRANSLATE_FAIL; | ||
93 | } | ||
94 | |||
95 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | ||
92 | index XXXXXXX..XXXXXXX 100644 | 96 | index XXXXXXX..XXXXXXX 100644 |
93 | --- a/target/riscv/tcg/tcg-cpu.c | 97 | --- a/target/riscv/csr.c |
94 | +++ b/target/riscv/tcg/tcg-cpu.c | 98 | +++ b/target/riscv/csr.c |
95 | @@ -XXX,XX +XXX,XX @@ static bool cpu_cfg_offset_is_named_feat(uint32_t ext_offset) | 99 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_menvcfg(CPURISCVState *env, int csrno, |
96 | 100 | if (riscv_cpu_mxl(env) == MXL_RV64) { | |
97 | static void riscv_cpu_enable_named_feat(RISCVCPU *cpu, uint32_t feat_offset) | 101 | mask |= (cfg->ext_svpbmt ? MENVCFG_PBMTE : 0) | |
102 | (cfg->ext_sstc ? MENVCFG_STCE : 0) | | ||
103 | - (cfg->ext_svadu ? MENVCFG_HADE : 0); | ||
104 | + (cfg->ext_svadu ? MENVCFG_ADUE : 0); | ||
105 | } | ||
106 | env->menvcfg = (env->menvcfg & ~mask) | (val & mask); | ||
107 | |||
108 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_menvcfgh(CPURISCVState *env, int csrno, | ||
109 | const RISCVCPUConfig *cfg = riscv_cpu_cfg(env); | ||
110 | uint64_t mask = (cfg->ext_svpbmt ? MENVCFG_PBMTE : 0) | | ||
111 | (cfg->ext_sstc ? MENVCFG_STCE : 0) | | ||
112 | - (cfg->ext_svadu ? MENVCFG_HADE : 0); | ||
113 | + (cfg->ext_svadu ? MENVCFG_ADUE : 0); | ||
114 | uint64_t valh = (uint64_t)val << 32; | ||
115 | |||
116 | env->menvcfg = (env->menvcfg & ~mask) | (valh & mask); | ||
117 | @@ -XXX,XX +XXX,XX @@ static RISCVException read_henvcfg(CPURISCVState *env, int csrno, | ||
118 | * henvcfg.stce is read_only 0 when menvcfg.stce = 0 | ||
119 | * henvcfg.hade is read_only 0 when menvcfg.hade = 0 | ||
120 | */ | ||
121 | - *val = env->henvcfg & (~(HENVCFG_PBMTE | HENVCFG_STCE | HENVCFG_HADE) | | ||
122 | + *val = env->henvcfg & (~(HENVCFG_PBMTE | HENVCFG_STCE | HENVCFG_ADUE) | | ||
123 | env->menvcfg); | ||
124 | return RISCV_EXCP_NONE; | ||
125 | } | ||
126 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_henvcfg(CPURISCVState *env, int csrno, | ||
127 | } | ||
128 | |||
129 | if (riscv_cpu_mxl(env) == MXL_RV64) { | ||
130 | - mask |= env->menvcfg & (HENVCFG_PBMTE | HENVCFG_STCE | HENVCFG_HADE); | ||
131 | + mask |= env->menvcfg & (HENVCFG_PBMTE | HENVCFG_STCE | HENVCFG_ADUE); | ||
132 | } | ||
133 | |||
134 | env->henvcfg = (env->henvcfg & ~mask) | (val & mask); | ||
135 | @@ -XXX,XX +XXX,XX @@ static RISCVException read_henvcfgh(CPURISCVState *env, int csrno, | ||
136 | return ret; | ||
137 | } | ||
138 | |||
139 | - *val = (env->henvcfg & (~(HENVCFG_PBMTE | HENVCFG_STCE | HENVCFG_HADE) | | ||
140 | + *val = (env->henvcfg & (~(HENVCFG_PBMTE | HENVCFG_STCE | HENVCFG_ADUE) | | ||
141 | env->menvcfg)) >> 32; | ||
142 | return RISCV_EXCP_NONE; | ||
143 | } | ||
144 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_henvcfgh(CPURISCVState *env, int csrno, | ||
145 | target_ulong val) | ||
98 | { | 146 | { |
99 | - switch (feat_offset) { | 147 | uint64_t mask = env->menvcfg & (HENVCFG_PBMTE | HENVCFG_STCE | |
100 | - case CPU_CFG_OFFSET(ext_zic64b): | 148 | - HENVCFG_HADE); |
101 | + /* | 149 | + HENVCFG_ADUE); |
102 | + * All other named features are already enabled | 150 | uint64_t valh = (uint64_t)val << 32; |
103 | + * in riscv_tcg_cpu_instance_init(). | 151 | RISCVException ret; |
104 | + */ | 152 | |
105 | + if (feat_offset == CPU_CFG_OFFSET(ext_zic64b)) { | ||
106 | cpu->cfg.cbom_blocksize = 64; | ||
107 | cpu->cfg.cbop_blocksize = 64; | ||
108 | cpu->cfg.cboz_blocksize = 64; | ||
109 | - break; | ||
110 | - case CPU_CFG_OFFSET(ext_svade): | ||
111 | - cpu->cfg.ext_svadu = false; | ||
112 | - break; | ||
113 | - default: | ||
114 | - g_assert_not_reached(); | ||
115 | } | ||
116 | } | ||
117 | |||
118 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_update_named_features(RISCVCPU *cpu) | ||
119 | cpu->cfg.ext_zic64b = cpu->cfg.cbom_blocksize == 64 && | ||
120 | cpu->cfg.cbop_blocksize == 64 && | ||
121 | cpu->cfg.cboz_blocksize == 64; | ||
122 | - | ||
123 | - cpu->cfg.ext_svade = !cpu->cfg.ext_svadu; | ||
124 | } | ||
125 | |||
126 | static void riscv_cpu_validate_g(RISCVCPU *cpu) | ||
127 | -- | 153 | -- |
128 | 2.44.0 | 154 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | The idea with this update is to get the latest KVM caps for RISC-V. | 3 | In the same emulated RISC-V host, the 'host' KVM CPU takes 4 times |
4 | longer to boot than the 'rv64' KVM CPU. | ||
4 | 5 | ||
6 | The reason is an unintended behavior of riscv_cpu_satp_mode_finalize() | ||
7 | when satp_mode.supported = 0, i.e. when cpu_init() does not set | ||
8 | satp_mode_max_supported(). satp_mode_max_from_map(map) does: | ||
9 | |||
10 | 31 - __builtin_clz(map) | ||
11 | |||
12 | This means that, if satp_mode.supported = 0, satp_mode_supported_max | ||
13 | wil be '31 - 32'. But this is C, so satp_mode_supported_max will gladly | ||
14 | set it to UINT_MAX (4294967295). After that, if the user didn't set a | ||
15 | satp_mode, set_satp_mode_default_map(cpu) will make | ||
16 | |||
17 | cfg.satp_mode.map = cfg.satp_mode.supported | ||
18 | |||
19 | So satp_mode.map = 0. And then satp_mode_map_max will be set to | ||
20 | satp_mode_max_from_map(cpu->cfg.satp_mode.map), i.e. also UINT_MAX. The | ||
21 | guard "satp_mode_map_max > satp_mode_supported_max" doesn't protect us | ||
22 | here since both are UINT_MAX. | ||
23 | |||
24 | And finally we have 2 loops: | ||
25 | |||
26 | for (int i = satp_mode_map_max - 1; i >= 0; --i) { | ||
27 | |||
28 | Which are, in fact, 2 loops from UINT_MAX -1 to -1. This is where the | ||
29 | extra delay when booting the 'host' CPU is coming from. | ||
30 | |||
31 | Commit 43d1de32f8 already set a precedence for satp_mode.supported = 0 | ||
32 | in a different manner. We're doing the same here. If supported == 0, | ||
33 | interpret as 'the CPU wants the OS to handle satp mode alone' and skip | ||
34 | satp_mode_finalize(). | ||
35 | |||
36 | We'll also put a guard in satp_mode_max_from_map() to assert out if map | ||
37 | is 0 since the function is not ready to deal with it. | ||
38 | |||
39 | Cc: Alexandre Ghiti <alexghiti@rivosinc.com> | ||
40 | Fixes: 6f23aaeb9b ("riscv: Allow user to set the satp mode") | ||
5 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 41 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
6 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | 42 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> |
7 | Message-ID: <20240304134732.386590-2-dbarboza@ventanamicro.com> | 43 | Message-ID: <20230817152903.694926-1-dbarboza@ventanamicro.com> |
8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 44 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
9 | --- | 45 | --- |
10 | include/standard-headers/drm/drm_fourcc.h | 10 +- | 46 | target/riscv/cpu.c | 23 ++++++++++++++++++++--- |
11 | include/standard-headers/linux/ethtool.h | 41 +++-- | 47 | 1 file changed, 20 insertions(+), 3 deletions(-) |
12 | .../standard-headers/linux/virtio_config.h | 8 +- | ||
13 | include/standard-headers/linux/virtio_pci.h | 68 +++++++++ | ||
14 | include/standard-headers/linux/virtio_pmem.h | 7 + | ||
15 | linux-headers/asm-generic/unistd.h | 15 +- | ||
16 | linux-headers/asm-mips/mman.h | 2 +- | ||
17 | linux-headers/asm-mips/unistd_n32.h | 5 + | ||
18 | linux-headers/asm-mips/unistd_n64.h | 5 + | ||
19 | linux-headers/asm-mips/unistd_o32.h | 5 + | ||
20 | linux-headers/asm-powerpc/unistd_32.h | 5 + | ||
21 | linux-headers/asm-powerpc/unistd_64.h | 5 + | ||
22 | linux-headers/asm-riscv/kvm.h | 40 +++++ | ||
23 | linux-headers/asm-s390/unistd_32.h | 5 + | ||
24 | linux-headers/asm-s390/unistd_64.h | 5 + | ||
25 | linux-headers/asm-x86/kvm.h | 3 + | ||
26 | linux-headers/asm-x86/unistd_32.h | 5 + | ||
27 | linux-headers/asm-x86/unistd_64.h | 5 + | ||
28 | linux-headers/asm-x86/unistd_x32.h | 5 + | ||
29 | linux-headers/linux/iommufd.h | 79 ++++++++++ | ||
30 | linux-headers/linux/kvm.h | 140 +++++++----------- | ||
31 | linux-headers/linux/userfaultfd.h | 29 +++- | ||
32 | linux-headers/linux/vfio.h | 1 + | ||
33 | 23 files changed, 381 insertions(+), 112 deletions(-) | ||
34 | 48 | ||
35 | diff --git a/include/standard-headers/drm/drm_fourcc.h b/include/standard-headers/drm/drm_fourcc.h | 49 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
36 | index XXXXXXX..XXXXXXX 100644 | 50 | index XXXXXXX..XXXXXXX 100644 |
37 | --- a/include/standard-headers/drm/drm_fourcc.h | 51 | --- a/target/riscv/cpu.c |
38 | +++ b/include/standard-headers/drm/drm_fourcc.h | 52 | +++ b/target/riscv/cpu.c |
39 | @@ -XXX,XX +XXX,XX @@ extern "C" { | 53 | @@ -XXX,XX +XXX,XX @@ static uint8_t satp_mode_from_str(const char *satp_mode_str) |
40 | * Format modifiers may change any property of the buffer, including the number | 54 | |
41 | * of planes and/or the required allocation size. Format modifiers are | 55 | uint8_t satp_mode_max_from_map(uint32_t map) |
42 | * vendor-namespaced, and as such the relationship between a fourcc code and a | 56 | { |
43 | - * modifier is specific to the modifer being used. For example, some modifiers | 57 | + /* |
44 | + * modifier is specific to the modifier being used. For example, some modifiers | 58 | + * 'map = 0' will make us return (31 - 32), which C will |
45 | * may preserve meaning - such as number of planes - from the fourcc code, | 59 | + * happily overflow to UINT_MAX. There's no good result to |
46 | * whereas others may not. | 60 | + * return if 'map = 0' (e.g. returning 0 will be ambiguous |
47 | * | 61 | + * with the result for 'map = 1'). |
48 | @@ -XXX,XX +XXX,XX @@ extern "C" { | 62 | + * |
49 | * format. | 63 | + * Assert out if map = 0. Callers will have to deal with |
50 | * - Higher-level programs interfacing with KMS/GBM/EGL/Vulkan/etc: these users | 64 | + * it outside of this function. |
51 | * see modifiers as opaque tokens they can check for equality and intersect. | 65 | + */ |
52 | - * These users musn't need to know to reason about the modifier value | 66 | + g_assert(map > 0); |
53 | + * These users mustn't need to know to reason about the modifier value | ||
54 | * (i.e. they are not expected to extract information out of the modifier). | ||
55 | * | ||
56 | * Vendors should document their modifier usage in as much detail as | ||
57 | @@ -XXX,XX +XXX,XX @@ extern "C" { | ||
58 | * This is a tiled layout using 4Kb tiles in row-major layout. | ||
59 | * Within the tile pixels are laid out in 16 256 byte units / sub-tiles which | ||
60 | * are arranged in four groups (two wide, two high) with column-major layout. | ||
61 | - * Each group therefore consits out of four 256 byte units, which are also laid | ||
62 | + * Each group therefore consists out of four 256 byte units, which are also laid | ||
63 | * out as 2x2 column-major. | ||
64 | * 256 byte units are made out of four 64 byte blocks of pixels, producing | ||
65 | * either a square block or a 2:1 unit. | ||
66 | @@ -XXX,XX +XXX,XX @@ drm_fourcc_canonicalize_nvidia_format_mod(uint64_t modifier) | ||
67 | */ | ||
68 | |||
69 | /* | ||
70 | - * The top 4 bits (out of the 56 bits alloted for specifying vendor specific | ||
71 | + * The top 4 bits (out of the 56 bits allotted for specifying vendor specific | ||
72 | * modifiers) denote the category for modifiers. Currently we have three | ||
73 | * categories of modifiers ie AFBC, MISC and AFRC. We can have a maximum of | ||
74 | * sixteen different categories. | ||
75 | @@ -XXX,XX +XXX,XX @@ drm_fourcc_canonicalize_nvidia_format_mod(uint64_t modifier) | ||
76 | * Amlogic FBC Memory Saving mode | ||
77 | * | ||
78 | * Indicates the storage is packed when pixel size is multiple of word | ||
79 | - * boudaries, i.e. 8bit should be stored in this mode to save allocation | ||
80 | + * boundaries, i.e. 8bit should be stored in this mode to save allocation | ||
81 | * memory. | ||
82 | * | ||
83 | * This mode reduces body layout to 3072 bytes per 64x32 superblock with | ||
84 | diff --git a/include/standard-headers/linux/ethtool.h b/include/standard-headers/linux/ethtool.h | ||
85 | index XXXXXXX..XXXXXXX 100644 | ||
86 | --- a/include/standard-headers/linux/ethtool.h | ||
87 | +++ b/include/standard-headers/linux/ethtool.h | ||
88 | @@ -XXX,XX +XXX,XX @@ struct ethtool_rxfh_indir { | ||
89 | * hardware hash key. | ||
90 | * @hfunc: Defines the current RSS hash function used by HW (or to be set to). | ||
91 | * Valid values are one of the %ETH_RSS_HASH_*. | ||
92 | + * @input_xfrm: Defines how the input data is transformed. Valid values are one | ||
93 | + * of %RXH_XFRM_*. | ||
94 | * @rsvd8: Reserved for future use; see the note on reserved space. | ||
95 | * @rsvd32: Reserved for future use; see the note on reserved space. | ||
96 | * @rss_config: RX ring/queue index for each hash value i.e., indirection table | ||
97 | @@ -XXX,XX +XXX,XX @@ struct ethtool_rxfh { | ||
98 | uint32_t indir_size; | ||
99 | uint32_t key_size; | ||
100 | uint8_t hfunc; | ||
101 | - uint8_t rsvd8[3]; | ||
102 | + uint8_t input_xfrm; | ||
103 | + uint8_t rsvd8[2]; | ||
104 | uint32_t rsvd32; | ||
105 | uint32_t rss_config[]; | ||
106 | }; | ||
107 | @@ -XXX,XX +XXX,XX @@ static inline int ethtool_validate_duplex(uint8_t duplex) | ||
108 | |||
109 | #define WOL_MODE_COUNT 8 | ||
110 | |||
111 | +/* RSS hash function data | ||
112 | + * XOR the corresponding source and destination fields of each specified | ||
113 | + * protocol. Both copies of the XOR'ed fields are fed into the RSS and RXHASH | ||
114 | + * calculation. Note that this XORing reduces the input set entropy and could | ||
115 | + * be exploited to reduce the RSS queue spread. | ||
116 | + */ | ||
117 | +#define RXH_XFRM_SYM_XOR (1 << 0) | ||
118 | +#define RXH_XFRM_NO_CHANGE 0xff | ||
119 | + | 67 | + |
120 | /* L2-L4 network traffic flow types */ | 68 | /* map here has at least one bit set, so no problem with clz */ |
121 | #define TCP_V4_FLOW 0x01 /* hash or spec (tcp_ip4_spec) */ | 69 | return 31 - __builtin_clz(map); |
122 | #define UDP_V4_FLOW 0x02 /* hash or spec (udp_ip4_spec) */ | 70 | } |
123 | @@ -XXX,XX +XXX,XX @@ enum ethtool_reset_flags { | 71 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) |
124 | * refused. For drivers: ignore this field (use kernel's | 72 | static void riscv_cpu_satp_mode_finalize(RISCVCPU *cpu, Error **errp) |
125 | * __ETHTOOL_LINK_MODE_MASK_NBITS instead), any change to it will | 73 | { |
126 | * be overwritten by kernel. | 74 | bool rv32 = riscv_cpu_mxl(&cpu->env) == MXL_RV32; |
127 | - * @supported: Bitmap with each bit meaning given by | 75 | - uint8_t satp_mode_map_max; |
128 | - * %ethtool_link_mode_bit_indices for the link modes, physical | 76 | - uint8_t satp_mode_supported_max = |
129 | - * connectors and other link features for which the interface | 77 | - satp_mode_max_from_map(cpu->cfg.satp_mode.supported); |
130 | - * supports autonegotiation or auto-detection. Read-only. | 78 | + uint8_t satp_mode_map_max, satp_mode_supported_max; |
131 | - * @advertising: Bitmap with each bit meaning given by | ||
132 | - * %ethtool_link_mode_bit_indices for the link modes, physical | ||
133 | - * connectors and other link features that are advertised through | ||
134 | - * autonegotiation or enabled for auto-detection. | ||
135 | - * @lp_advertising: Bitmap with each bit meaning given by | ||
136 | - * %ethtool_link_mode_bit_indices for the link modes, and other | ||
137 | - * link features that the link partner advertised through | ||
138 | - * autonegotiation; 0 if unknown or not applicable. Read-only. | ||
139 | * @transceiver: Used to distinguish different possible PHY types, | ||
140 | * reported consistently by PHYLIB. Read-only. | ||
141 | * @master_slave_cfg: Master/slave port mode. | ||
142 | @@ -XXX,XX +XXX,XX @@ enum ethtool_reset_flags { | ||
143 | * %set_link_ksettings() should validate all fields other than @cmd | ||
144 | * and @link_mode_masks_nwords that are not described as read-only or | ||
145 | * deprecated, and must ignore all fields described as read-only. | ||
146 | + * | ||
147 | + * @link_mode_masks is divided into three bitfields, each of length | ||
148 | + * @link_mode_masks_nwords: | ||
149 | + * - supported: Bitmap with each bit meaning given by | ||
150 | + * %ethtool_link_mode_bit_indices for the link modes, physical | ||
151 | + * connectors and other link features for which the interface | ||
152 | + * supports autonegotiation or auto-detection. Read-only. | ||
153 | + * - advertising: Bitmap with each bit meaning given by | ||
154 | + * %ethtool_link_mode_bit_indices for the link modes, physical | ||
155 | + * connectors and other link features that are advertised through | ||
156 | + * autonegotiation or enabled for auto-detection. | ||
157 | + * - lp_advertising: Bitmap with each bit meaning given by | ||
158 | + * %ethtool_link_mode_bit_indices for the link modes, and other | ||
159 | + * link features that the link partner advertised through | ||
160 | + * autonegotiation; 0 if unknown or not applicable. Read-only. | ||
161 | */ | ||
162 | struct ethtool_link_settings { | ||
163 | uint32_t cmd; | ||
164 | diff --git a/include/standard-headers/linux/virtio_config.h b/include/standard-headers/linux/virtio_config.h | ||
165 | index XXXXXXX..XXXXXXX 100644 | ||
166 | --- a/include/standard-headers/linux/virtio_config.h | ||
167 | +++ b/include/standard-headers/linux/virtio_config.h | ||
168 | @@ -XXX,XX +XXX,XX @@ | ||
169 | * rest are per-device feature bits. | ||
170 | */ | ||
171 | #define VIRTIO_TRANSPORT_F_START 28 | ||
172 | -#define VIRTIO_TRANSPORT_F_END 41 | ||
173 | +#define VIRTIO_TRANSPORT_F_END 42 | ||
174 | |||
175 | #ifndef VIRTIO_CONFIG_NO_LEGACY | ||
176 | /* Do we get callbacks when the ring is completely used, even if we've | ||
177 | @@ -XXX,XX +XXX,XX @@ | ||
178 | * This feature indicates that the driver can reset a queue individually. | ||
179 | */ | ||
180 | #define VIRTIO_F_RING_RESET 40 | ||
181 | + | 79 | + |
182 | +/* | 80 | + /* The CPU wants the OS to decide which satp mode to use */ |
183 | + * This feature indicates that the device support administration virtqueues. | 81 | + if (cpu->cfg.satp_mode.supported == 0) { |
184 | + */ | 82 | + return; |
185 | +#define VIRTIO_F_ADMIN_VQ 41 | 83 | + } |
186 | + | 84 | + |
187 | #endif /* _LINUX_VIRTIO_CONFIG_H */ | 85 | + satp_mode_supported_max = |
188 | diff --git a/include/standard-headers/linux/virtio_pci.h b/include/standard-headers/linux/virtio_pci.h | 86 | + satp_mode_max_from_map(cpu->cfg.satp_mode.supported); |
189 | index XXXXXXX..XXXXXXX 100644 | 87 | |
190 | --- a/include/standard-headers/linux/virtio_pci.h | 88 | if (cpu->cfg.satp_mode.map == 0) { |
191 | +++ b/include/standard-headers/linux/virtio_pci.h | 89 | if (cpu->cfg.satp_mode.init == 0) { |
192 | @@ -XXX,XX +XXX,XX @@ struct virtio_pci_modern_common_cfg { | ||
193 | |||
194 | uint16_t queue_notify_data; /* read-write */ | ||
195 | uint16_t queue_reset; /* read-write */ | ||
196 | + | ||
197 | + uint16_t admin_queue_index; /* read-only */ | ||
198 | + uint16_t admin_queue_num; /* read-only */ | ||
199 | }; | ||
200 | |||
201 | /* Fields in VIRTIO_PCI_CAP_PCI_CFG: */ | ||
202 | @@ -XXX,XX +XXX,XX @@ struct virtio_pci_cfg_cap { | ||
203 | #define VIRTIO_PCI_COMMON_Q_USEDHI 52 | ||
204 | #define VIRTIO_PCI_COMMON_Q_NDATA 56 | ||
205 | #define VIRTIO_PCI_COMMON_Q_RESET 58 | ||
206 | +#define VIRTIO_PCI_COMMON_ADM_Q_IDX 60 | ||
207 | +#define VIRTIO_PCI_COMMON_ADM_Q_NUM 62 | ||
208 | |||
209 | #endif /* VIRTIO_PCI_NO_MODERN */ | ||
210 | |||
211 | +/* Admin command status. */ | ||
212 | +#define VIRTIO_ADMIN_STATUS_OK 0 | ||
213 | + | ||
214 | +/* Admin command opcode. */ | ||
215 | +#define VIRTIO_ADMIN_CMD_LIST_QUERY 0x0 | ||
216 | +#define VIRTIO_ADMIN_CMD_LIST_USE 0x1 | ||
217 | + | ||
218 | +/* Admin command group type. */ | ||
219 | +#define VIRTIO_ADMIN_GROUP_TYPE_SRIOV 0x1 | ||
220 | + | ||
221 | +/* Transitional device admin command. */ | ||
222 | +#define VIRTIO_ADMIN_CMD_LEGACY_COMMON_CFG_WRITE 0x2 | ||
223 | +#define VIRTIO_ADMIN_CMD_LEGACY_COMMON_CFG_READ 0x3 | ||
224 | +#define VIRTIO_ADMIN_CMD_LEGACY_DEV_CFG_WRITE 0x4 | ||
225 | +#define VIRTIO_ADMIN_CMD_LEGACY_DEV_CFG_READ 0x5 | ||
226 | +#define VIRTIO_ADMIN_CMD_LEGACY_NOTIFY_INFO 0x6 | ||
227 | + | ||
228 | +struct QEMU_PACKED virtio_admin_cmd_hdr { | ||
229 | + uint16_t opcode; | ||
230 | + /* | ||
231 | + * 1 - SR-IOV | ||
232 | + * 2-65535 - reserved | ||
233 | + */ | ||
234 | + uint16_t group_type; | ||
235 | + /* Unused, reserved for future extensions. */ | ||
236 | + uint8_t reserved1[12]; | ||
237 | + uint64_t group_member_id; | ||
238 | +}; | ||
239 | + | ||
240 | +struct QEMU_PACKED virtio_admin_cmd_status { | ||
241 | + uint16_t status; | ||
242 | + uint16_t status_qualifier; | ||
243 | + /* Unused, reserved for future extensions. */ | ||
244 | + uint8_t reserved2[4]; | ||
245 | +}; | ||
246 | + | ||
247 | +struct QEMU_PACKED virtio_admin_cmd_legacy_wr_data { | ||
248 | + uint8_t offset; /* Starting offset of the register(s) to write. */ | ||
249 | + uint8_t reserved[7]; | ||
250 | + uint8_t registers[]; | ||
251 | +}; | ||
252 | + | ||
253 | +struct QEMU_PACKED virtio_admin_cmd_legacy_rd_data { | ||
254 | + uint8_t offset; /* Starting offset of the register(s) to read. */ | ||
255 | +}; | ||
256 | + | ||
257 | +#define VIRTIO_ADMIN_CMD_NOTIFY_INFO_FLAGS_END 0 | ||
258 | +#define VIRTIO_ADMIN_CMD_NOTIFY_INFO_FLAGS_OWNER_DEV 0x1 | ||
259 | +#define VIRTIO_ADMIN_CMD_NOTIFY_INFO_FLAGS_OWNER_MEM 0x2 | ||
260 | + | ||
261 | +#define VIRTIO_ADMIN_CMD_MAX_NOTIFY_INFO 4 | ||
262 | + | ||
263 | +struct QEMU_PACKED virtio_admin_cmd_notify_info_data { | ||
264 | + uint8_t flags; /* 0 = end of list, 1 = owner device, 2 = member device */ | ||
265 | + uint8_t bar; /* BAR of the member or the owner device */ | ||
266 | + uint8_t padding[6]; | ||
267 | + uint64_t offset; /* Offset within bar. */ | ||
268 | +}; | ||
269 | + | ||
270 | +struct virtio_admin_cmd_notify_info_result { | ||
271 | + struct virtio_admin_cmd_notify_info_data entries[VIRTIO_ADMIN_CMD_MAX_NOTIFY_INFO]; | ||
272 | +}; | ||
273 | + | ||
274 | #endif | ||
275 | diff --git a/include/standard-headers/linux/virtio_pmem.h b/include/standard-headers/linux/virtio_pmem.h | ||
276 | index XXXXXXX..XXXXXXX 100644 | ||
277 | --- a/include/standard-headers/linux/virtio_pmem.h | ||
278 | +++ b/include/standard-headers/linux/virtio_pmem.h | ||
279 | @@ -XXX,XX +XXX,XX @@ | ||
280 | #include "standard-headers/linux/virtio_ids.h" | ||
281 | #include "standard-headers/linux/virtio_config.h" | ||
282 | |||
283 | +/* Feature bits */ | ||
284 | +/* guest physical address range will be indicated as shared memory region 0 */ | ||
285 | +#define VIRTIO_PMEM_F_SHMEM_REGION 0 | ||
286 | + | ||
287 | +/* shmid of the shared memory region corresponding to the pmem */ | ||
288 | +#define VIRTIO_PMEM_SHMEM_REGION_ID 0 | ||
289 | + | ||
290 | struct virtio_pmem_config { | ||
291 | uint64_t start; | ||
292 | uint64_t size; | ||
293 | diff --git a/linux-headers/asm-generic/unistd.h b/linux-headers/asm-generic/unistd.h | ||
294 | index XXXXXXX..XXXXXXX 100644 | ||
295 | --- a/linux-headers/asm-generic/unistd.h | ||
296 | +++ b/linux-headers/asm-generic/unistd.h | ||
297 | @@ -XXX,XX +XXX,XX @@ __SYSCALL(__NR_futex_wait, sys_futex_wait) | ||
298 | #define __NR_futex_requeue 456 | ||
299 | __SYSCALL(__NR_futex_requeue, sys_futex_requeue) | ||
300 | |||
301 | +#define __NR_statmount 457 | ||
302 | +__SYSCALL(__NR_statmount, sys_statmount) | ||
303 | + | ||
304 | +#define __NR_listmount 458 | ||
305 | +__SYSCALL(__NR_listmount, sys_listmount) | ||
306 | + | ||
307 | +#define __NR_lsm_get_self_attr 459 | ||
308 | +__SYSCALL(__NR_lsm_get_self_attr, sys_lsm_get_self_attr) | ||
309 | +#define __NR_lsm_set_self_attr 460 | ||
310 | +__SYSCALL(__NR_lsm_set_self_attr, sys_lsm_set_self_attr) | ||
311 | +#define __NR_lsm_list_modules 461 | ||
312 | +__SYSCALL(__NR_lsm_list_modules, sys_lsm_list_modules) | ||
313 | + | ||
314 | #undef __NR_syscalls | ||
315 | -#define __NR_syscalls 457 | ||
316 | +#define __NR_syscalls 462 | ||
317 | |||
318 | /* | ||
319 | * 32 bit systems traditionally used different | ||
320 | diff --git a/linux-headers/asm-mips/mman.h b/linux-headers/asm-mips/mman.h | ||
321 | index XXXXXXX..XXXXXXX 100644 | ||
322 | --- a/linux-headers/asm-mips/mman.h | ||
323 | +++ b/linux-headers/asm-mips/mman.h | ||
324 | @@ -XXX,XX +XXX,XX @@ | ||
325 | #define MADV_HUGEPAGE 14 /* Worth backing with hugepages */ | ||
326 | #define MADV_NOHUGEPAGE 15 /* Not worth backing with hugepages */ | ||
327 | |||
328 | -#define MADV_DONTDUMP 16 /* Explicity exclude from the core dump, | ||
329 | +#define MADV_DONTDUMP 16 /* Explicitly exclude from core dump, | ||
330 | overrides the coredump filter bits */ | ||
331 | #define MADV_DODUMP 17 /* Clear the MADV_NODUMP flag */ | ||
332 | |||
333 | diff --git a/linux-headers/asm-mips/unistd_n32.h b/linux-headers/asm-mips/unistd_n32.h | ||
334 | index XXXXXXX..XXXXXXX 100644 | ||
335 | --- a/linux-headers/asm-mips/unistd_n32.h | ||
336 | +++ b/linux-headers/asm-mips/unistd_n32.h | ||
337 | @@ -XXX,XX +XXX,XX @@ | ||
338 | #define __NR_futex_wake (__NR_Linux + 454) | ||
339 | #define __NR_futex_wait (__NR_Linux + 455) | ||
340 | #define __NR_futex_requeue (__NR_Linux + 456) | ||
341 | +#define __NR_statmount (__NR_Linux + 457) | ||
342 | +#define __NR_listmount (__NR_Linux + 458) | ||
343 | +#define __NR_lsm_get_self_attr (__NR_Linux + 459) | ||
344 | +#define __NR_lsm_set_self_attr (__NR_Linux + 460) | ||
345 | +#define __NR_lsm_list_modules (__NR_Linux + 461) | ||
346 | |||
347 | #endif /* _ASM_UNISTD_N32_H */ | ||
348 | diff --git a/linux-headers/asm-mips/unistd_n64.h b/linux-headers/asm-mips/unistd_n64.h | ||
349 | index XXXXXXX..XXXXXXX 100644 | ||
350 | --- a/linux-headers/asm-mips/unistd_n64.h | ||
351 | +++ b/linux-headers/asm-mips/unistd_n64.h | ||
352 | @@ -XXX,XX +XXX,XX @@ | ||
353 | #define __NR_futex_wake (__NR_Linux + 454) | ||
354 | #define __NR_futex_wait (__NR_Linux + 455) | ||
355 | #define __NR_futex_requeue (__NR_Linux + 456) | ||
356 | +#define __NR_statmount (__NR_Linux + 457) | ||
357 | +#define __NR_listmount (__NR_Linux + 458) | ||
358 | +#define __NR_lsm_get_self_attr (__NR_Linux + 459) | ||
359 | +#define __NR_lsm_set_self_attr (__NR_Linux + 460) | ||
360 | +#define __NR_lsm_list_modules (__NR_Linux + 461) | ||
361 | |||
362 | #endif /* _ASM_UNISTD_N64_H */ | ||
363 | diff --git a/linux-headers/asm-mips/unistd_o32.h b/linux-headers/asm-mips/unistd_o32.h | ||
364 | index XXXXXXX..XXXXXXX 100644 | ||
365 | --- a/linux-headers/asm-mips/unistd_o32.h | ||
366 | +++ b/linux-headers/asm-mips/unistd_o32.h | ||
367 | @@ -XXX,XX +XXX,XX @@ | ||
368 | #define __NR_futex_wake (__NR_Linux + 454) | ||
369 | #define __NR_futex_wait (__NR_Linux + 455) | ||
370 | #define __NR_futex_requeue (__NR_Linux + 456) | ||
371 | +#define __NR_statmount (__NR_Linux + 457) | ||
372 | +#define __NR_listmount (__NR_Linux + 458) | ||
373 | +#define __NR_lsm_get_self_attr (__NR_Linux + 459) | ||
374 | +#define __NR_lsm_set_self_attr (__NR_Linux + 460) | ||
375 | +#define __NR_lsm_list_modules (__NR_Linux + 461) | ||
376 | |||
377 | #endif /* _ASM_UNISTD_O32_H */ | ||
378 | diff --git a/linux-headers/asm-powerpc/unistd_32.h b/linux-headers/asm-powerpc/unistd_32.h | ||
379 | index XXXXXXX..XXXXXXX 100644 | ||
380 | --- a/linux-headers/asm-powerpc/unistd_32.h | ||
381 | +++ b/linux-headers/asm-powerpc/unistd_32.h | ||
382 | @@ -XXX,XX +XXX,XX @@ | ||
383 | #define __NR_futex_wake 454 | ||
384 | #define __NR_futex_wait 455 | ||
385 | #define __NR_futex_requeue 456 | ||
386 | +#define __NR_statmount 457 | ||
387 | +#define __NR_listmount 458 | ||
388 | +#define __NR_lsm_get_self_attr 459 | ||
389 | +#define __NR_lsm_set_self_attr 460 | ||
390 | +#define __NR_lsm_list_modules 461 | ||
391 | |||
392 | |||
393 | #endif /* _ASM_UNISTD_32_H */ | ||
394 | diff --git a/linux-headers/asm-powerpc/unistd_64.h b/linux-headers/asm-powerpc/unistd_64.h | ||
395 | index XXXXXXX..XXXXXXX 100644 | ||
396 | --- a/linux-headers/asm-powerpc/unistd_64.h | ||
397 | +++ b/linux-headers/asm-powerpc/unistd_64.h | ||
398 | @@ -XXX,XX +XXX,XX @@ | ||
399 | #define __NR_futex_wake 454 | ||
400 | #define __NR_futex_wait 455 | ||
401 | #define __NR_futex_requeue 456 | ||
402 | +#define __NR_statmount 457 | ||
403 | +#define __NR_listmount 458 | ||
404 | +#define __NR_lsm_get_self_attr 459 | ||
405 | +#define __NR_lsm_set_self_attr 460 | ||
406 | +#define __NR_lsm_list_modules 461 | ||
407 | |||
408 | |||
409 | #endif /* _ASM_UNISTD_64_H */ | ||
410 | diff --git a/linux-headers/asm-riscv/kvm.h b/linux-headers/asm-riscv/kvm.h | ||
411 | index XXXXXXX..XXXXXXX 100644 | ||
412 | --- a/linux-headers/asm-riscv/kvm.h | ||
413 | +++ b/linux-headers/asm-riscv/kvm.h | ||
414 | @@ -XXX,XX +XXX,XX @@ enum KVM_RISCV_ISA_EXT_ID { | ||
415 | KVM_RISCV_ISA_EXT_ZIHPM, | ||
416 | KVM_RISCV_ISA_EXT_SMSTATEEN, | ||
417 | KVM_RISCV_ISA_EXT_ZICOND, | ||
418 | + KVM_RISCV_ISA_EXT_ZBC, | ||
419 | + KVM_RISCV_ISA_EXT_ZBKB, | ||
420 | + KVM_RISCV_ISA_EXT_ZBKC, | ||
421 | + KVM_RISCV_ISA_EXT_ZBKX, | ||
422 | + KVM_RISCV_ISA_EXT_ZKND, | ||
423 | + KVM_RISCV_ISA_EXT_ZKNE, | ||
424 | + KVM_RISCV_ISA_EXT_ZKNH, | ||
425 | + KVM_RISCV_ISA_EXT_ZKR, | ||
426 | + KVM_RISCV_ISA_EXT_ZKSED, | ||
427 | + KVM_RISCV_ISA_EXT_ZKSH, | ||
428 | + KVM_RISCV_ISA_EXT_ZKT, | ||
429 | + KVM_RISCV_ISA_EXT_ZVBB, | ||
430 | + KVM_RISCV_ISA_EXT_ZVBC, | ||
431 | + KVM_RISCV_ISA_EXT_ZVKB, | ||
432 | + KVM_RISCV_ISA_EXT_ZVKG, | ||
433 | + KVM_RISCV_ISA_EXT_ZVKNED, | ||
434 | + KVM_RISCV_ISA_EXT_ZVKNHA, | ||
435 | + KVM_RISCV_ISA_EXT_ZVKNHB, | ||
436 | + KVM_RISCV_ISA_EXT_ZVKSED, | ||
437 | + KVM_RISCV_ISA_EXT_ZVKSH, | ||
438 | + KVM_RISCV_ISA_EXT_ZVKT, | ||
439 | + KVM_RISCV_ISA_EXT_ZFH, | ||
440 | + KVM_RISCV_ISA_EXT_ZFHMIN, | ||
441 | + KVM_RISCV_ISA_EXT_ZIHINTNTL, | ||
442 | + KVM_RISCV_ISA_EXT_ZVFH, | ||
443 | + KVM_RISCV_ISA_EXT_ZVFHMIN, | ||
444 | + KVM_RISCV_ISA_EXT_ZFA, | ||
445 | KVM_RISCV_ISA_EXT_MAX, | ||
446 | }; | ||
447 | |||
448 | @@ -XXX,XX +XXX,XX @@ enum KVM_RISCV_SBI_EXT_ID { | ||
449 | KVM_RISCV_SBI_EXT_EXPERIMENTAL, | ||
450 | KVM_RISCV_SBI_EXT_VENDOR, | ||
451 | KVM_RISCV_SBI_EXT_DBCN, | ||
452 | + KVM_RISCV_SBI_EXT_STA, | ||
453 | KVM_RISCV_SBI_EXT_MAX, | ||
454 | }; | ||
455 | |||
456 | +/* SBI STA extension registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ | ||
457 | +struct kvm_riscv_sbi_sta { | ||
458 | + unsigned long shmem_lo; | ||
459 | + unsigned long shmem_hi; | ||
460 | +}; | ||
461 | + | ||
462 | /* Possible states for kvm_riscv_timer */ | ||
463 | #define KVM_RISCV_TIMER_STATE_OFF 0 | ||
464 | #define KVM_RISCV_TIMER_STATE_ON 1 | ||
465 | @@ -XXX,XX +XXX,XX @@ enum KVM_RISCV_SBI_EXT_ID { | ||
466 | #define KVM_REG_RISCV_VECTOR_REG(n) \ | ||
467 | ((n) + sizeof(struct __riscv_v_ext_state) / sizeof(unsigned long)) | ||
468 | |||
469 | +/* Registers for specific SBI extensions are mapped as type 10 */ | ||
470 | +#define KVM_REG_RISCV_SBI_STATE (0x0a << KVM_REG_RISCV_TYPE_SHIFT) | ||
471 | +#define KVM_REG_RISCV_SBI_STA (0x0 << KVM_REG_RISCV_SUBTYPE_SHIFT) | ||
472 | +#define KVM_REG_RISCV_SBI_STA_REG(name) \ | ||
473 | + (offsetof(struct kvm_riscv_sbi_sta, name) / sizeof(unsigned long)) | ||
474 | + | ||
475 | /* Device Control API: RISC-V AIA */ | ||
476 | #define KVM_DEV_RISCV_APLIC_ALIGN 0x1000 | ||
477 | #define KVM_DEV_RISCV_APLIC_SIZE 0x4000 | ||
478 | diff --git a/linux-headers/asm-s390/unistd_32.h b/linux-headers/asm-s390/unistd_32.h | ||
479 | index XXXXXXX..XXXXXXX 100644 | ||
480 | --- a/linux-headers/asm-s390/unistd_32.h | ||
481 | +++ b/linux-headers/asm-s390/unistd_32.h | ||
482 | @@ -XXX,XX +XXX,XX @@ | ||
483 | #define __NR_futex_wake 454 | ||
484 | #define __NR_futex_wait 455 | ||
485 | #define __NR_futex_requeue 456 | ||
486 | +#define __NR_statmount 457 | ||
487 | +#define __NR_listmount 458 | ||
488 | +#define __NR_lsm_get_self_attr 459 | ||
489 | +#define __NR_lsm_set_self_attr 460 | ||
490 | +#define __NR_lsm_list_modules 461 | ||
491 | |||
492 | #endif /* _ASM_S390_UNISTD_32_H */ | ||
493 | diff --git a/linux-headers/asm-s390/unistd_64.h b/linux-headers/asm-s390/unistd_64.h | ||
494 | index XXXXXXX..XXXXXXX 100644 | ||
495 | --- a/linux-headers/asm-s390/unistd_64.h | ||
496 | +++ b/linux-headers/asm-s390/unistd_64.h | ||
497 | @@ -XXX,XX +XXX,XX @@ | ||
498 | #define __NR_futex_wake 454 | ||
499 | #define __NR_futex_wait 455 | ||
500 | #define __NR_futex_requeue 456 | ||
501 | +#define __NR_statmount 457 | ||
502 | +#define __NR_listmount 458 | ||
503 | +#define __NR_lsm_get_self_attr 459 | ||
504 | +#define __NR_lsm_set_self_attr 460 | ||
505 | +#define __NR_lsm_list_modules 461 | ||
506 | |||
507 | #endif /* _ASM_S390_UNISTD_64_H */ | ||
508 | diff --git a/linux-headers/asm-x86/kvm.h b/linux-headers/asm-x86/kvm.h | ||
509 | index XXXXXXX..XXXXXXX 100644 | ||
510 | --- a/linux-headers/asm-x86/kvm.h | ||
511 | +++ b/linux-headers/asm-x86/kvm.h | ||
512 | @@ -XXX,XX +XXX,XX @@ struct kvm_pmu_event_filter { | ||
513 | /* x86-specific KVM_EXIT_HYPERCALL flags. */ | ||
514 | #define KVM_EXIT_HYPERCALL_LONG_MODE BIT(0) | ||
515 | |||
516 | +#define KVM_X86_DEFAULT_VM 0 | ||
517 | +#define KVM_X86_SW_PROTECTED_VM 1 | ||
518 | + | ||
519 | #endif /* _ASM_X86_KVM_H */ | ||
520 | diff --git a/linux-headers/asm-x86/unistd_32.h b/linux-headers/asm-x86/unistd_32.h | ||
521 | index XXXXXXX..XXXXXXX 100644 | ||
522 | --- a/linux-headers/asm-x86/unistd_32.h | ||
523 | +++ b/linux-headers/asm-x86/unistd_32.h | ||
524 | @@ -XXX,XX +XXX,XX @@ | ||
525 | #define __NR_futex_wake 454 | ||
526 | #define __NR_futex_wait 455 | ||
527 | #define __NR_futex_requeue 456 | ||
528 | +#define __NR_statmount 457 | ||
529 | +#define __NR_listmount 458 | ||
530 | +#define __NR_lsm_get_self_attr 459 | ||
531 | +#define __NR_lsm_set_self_attr 460 | ||
532 | +#define __NR_lsm_list_modules 461 | ||
533 | |||
534 | |||
535 | #endif /* _ASM_UNISTD_32_H */ | ||
536 | diff --git a/linux-headers/asm-x86/unistd_64.h b/linux-headers/asm-x86/unistd_64.h | ||
537 | index XXXXXXX..XXXXXXX 100644 | ||
538 | --- a/linux-headers/asm-x86/unistd_64.h | ||
539 | +++ b/linux-headers/asm-x86/unistd_64.h | ||
540 | @@ -XXX,XX +XXX,XX @@ | ||
541 | #define __NR_futex_wake 454 | ||
542 | #define __NR_futex_wait 455 | ||
543 | #define __NR_futex_requeue 456 | ||
544 | +#define __NR_statmount 457 | ||
545 | +#define __NR_listmount 458 | ||
546 | +#define __NR_lsm_get_self_attr 459 | ||
547 | +#define __NR_lsm_set_self_attr 460 | ||
548 | +#define __NR_lsm_list_modules 461 | ||
549 | |||
550 | |||
551 | #endif /* _ASM_UNISTD_64_H */ | ||
552 | diff --git a/linux-headers/asm-x86/unistd_x32.h b/linux-headers/asm-x86/unistd_x32.h | ||
553 | index XXXXXXX..XXXXXXX 100644 | ||
554 | --- a/linux-headers/asm-x86/unistd_x32.h | ||
555 | +++ b/linux-headers/asm-x86/unistd_x32.h | ||
556 | @@ -XXX,XX +XXX,XX @@ | ||
557 | #define __NR_futex_wake (__X32_SYSCALL_BIT + 454) | ||
558 | #define __NR_futex_wait (__X32_SYSCALL_BIT + 455) | ||
559 | #define __NR_futex_requeue (__X32_SYSCALL_BIT + 456) | ||
560 | +#define __NR_statmount (__X32_SYSCALL_BIT + 457) | ||
561 | +#define __NR_listmount (__X32_SYSCALL_BIT + 458) | ||
562 | +#define __NR_lsm_get_self_attr (__X32_SYSCALL_BIT + 459) | ||
563 | +#define __NR_lsm_set_self_attr (__X32_SYSCALL_BIT + 460) | ||
564 | +#define __NR_lsm_list_modules (__X32_SYSCALL_BIT + 461) | ||
565 | #define __NR_rt_sigaction (__X32_SYSCALL_BIT + 512) | ||
566 | #define __NR_rt_sigreturn (__X32_SYSCALL_BIT + 513) | ||
567 | #define __NR_ioctl (__X32_SYSCALL_BIT + 514) | ||
568 | diff --git a/linux-headers/linux/iommufd.h b/linux-headers/linux/iommufd.h | ||
569 | index XXXXXXX..XXXXXXX 100644 | ||
570 | --- a/linux-headers/linux/iommufd.h | ||
571 | +++ b/linux-headers/linux/iommufd.h | ||
572 | @@ -XXX,XX +XXX,XX @@ enum { | ||
573 | IOMMUFD_CMD_GET_HW_INFO, | ||
574 | IOMMUFD_CMD_HWPT_SET_DIRTY_TRACKING, | ||
575 | IOMMUFD_CMD_HWPT_GET_DIRTY_BITMAP, | ||
576 | + IOMMUFD_CMD_HWPT_INVALIDATE, | ||
577 | }; | ||
578 | |||
579 | /** | ||
580 | @@ -XXX,XX +XXX,XX @@ struct iommu_hwpt_get_dirty_bitmap { | ||
581 | #define IOMMU_HWPT_GET_DIRTY_BITMAP _IO(IOMMUFD_TYPE, \ | ||
582 | IOMMUFD_CMD_HWPT_GET_DIRTY_BITMAP) | ||
583 | |||
584 | +/** | ||
585 | + * enum iommu_hwpt_invalidate_data_type - IOMMU HWPT Cache Invalidation | ||
586 | + * Data Type | ||
587 | + * @IOMMU_HWPT_INVALIDATE_DATA_VTD_S1: Invalidation data for VTD_S1 | ||
588 | + */ | ||
589 | +enum iommu_hwpt_invalidate_data_type { | ||
590 | + IOMMU_HWPT_INVALIDATE_DATA_VTD_S1, | ||
591 | +}; | ||
592 | + | ||
593 | +/** | ||
594 | + * enum iommu_hwpt_vtd_s1_invalidate_flags - Flags for Intel VT-d | ||
595 | + * stage-1 cache invalidation | ||
596 | + * @IOMMU_VTD_INV_FLAGS_LEAF: Indicates whether the invalidation applies | ||
597 | + * to all-levels page structure cache or just | ||
598 | + * the leaf PTE cache. | ||
599 | + */ | ||
600 | +enum iommu_hwpt_vtd_s1_invalidate_flags { | ||
601 | + IOMMU_VTD_INV_FLAGS_LEAF = 1 << 0, | ||
602 | +}; | ||
603 | + | ||
604 | +/** | ||
605 | + * struct iommu_hwpt_vtd_s1_invalidate - Intel VT-d cache invalidation | ||
606 | + * (IOMMU_HWPT_INVALIDATE_DATA_VTD_S1) | ||
607 | + * @addr: The start address of the range to be invalidated. It needs to | ||
608 | + * be 4KB aligned. | ||
609 | + * @npages: Number of contiguous 4K pages to be invalidated. | ||
610 | + * @flags: Combination of enum iommu_hwpt_vtd_s1_invalidate_flags | ||
611 | + * @__reserved: Must be 0 | ||
612 | + * | ||
613 | + * The Intel VT-d specific invalidation data for user-managed stage-1 cache | ||
614 | + * invalidation in nested translation. Userspace uses this structure to | ||
615 | + * tell the impacted cache scope after modifying the stage-1 page table. | ||
616 | + * | ||
617 | + * Invalidating all the caches related to the page table by setting @addr | ||
618 | + * to be 0 and @npages to be U64_MAX. | ||
619 | + * | ||
620 | + * The device TLB will be invalidated automatically if ATS is enabled. | ||
621 | + */ | ||
622 | +struct iommu_hwpt_vtd_s1_invalidate { | ||
623 | + __aligned_u64 addr; | ||
624 | + __aligned_u64 npages; | ||
625 | + __u32 flags; | ||
626 | + __u32 __reserved; | ||
627 | +}; | ||
628 | + | ||
629 | +/** | ||
630 | + * struct iommu_hwpt_invalidate - ioctl(IOMMU_HWPT_INVALIDATE) | ||
631 | + * @size: sizeof(struct iommu_hwpt_invalidate) | ||
632 | + * @hwpt_id: ID of a nested HWPT for cache invalidation | ||
633 | + * @data_uptr: User pointer to an array of driver-specific cache invalidation | ||
634 | + * data. | ||
635 | + * @data_type: One of enum iommu_hwpt_invalidate_data_type, defining the data | ||
636 | + * type of all the entries in the invalidation request array. It | ||
637 | + * should be a type supported by the hwpt pointed by @hwpt_id. | ||
638 | + * @entry_len: Length (in bytes) of a request entry in the request array | ||
639 | + * @entry_num: Input the number of cache invalidation requests in the array. | ||
640 | + * Output the number of requests successfully handled by kernel. | ||
641 | + * @__reserved: Must be 0. | ||
642 | + * | ||
643 | + * Invalidate the iommu cache for user-managed page table. Modifications on a | ||
644 | + * user-managed page table should be followed by this operation to sync cache. | ||
645 | + * Each ioctl can support one or more cache invalidation requests in the array | ||
646 | + * that has a total size of @entry_len * @entry_num. | ||
647 | + * | ||
648 | + * An empty invalidation request array by setting @entry_num==0 is allowed, and | ||
649 | + * @entry_len and @data_uptr would be ignored in this case. This can be used to | ||
650 | + * check if the given @data_type is supported or not by kernel. | ||
651 | + */ | ||
652 | +struct iommu_hwpt_invalidate { | ||
653 | + __u32 size; | ||
654 | + __u32 hwpt_id; | ||
655 | + __aligned_u64 data_uptr; | ||
656 | + __u32 data_type; | ||
657 | + __u32 entry_len; | ||
658 | + __u32 entry_num; | ||
659 | + __u32 __reserved; | ||
660 | +}; | ||
661 | +#define IOMMU_HWPT_INVALIDATE _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HWPT_INVALIDATE) | ||
662 | #endif | ||
663 | diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h | ||
664 | index XXXXXXX..XXXXXXX 100644 | ||
665 | --- a/linux-headers/linux/kvm.h | ||
666 | +++ b/linux-headers/linux/kvm.h | ||
667 | @@ -XXX,XX +XXX,XX @@ | ||
668 | |||
669 | #define KVM_API_VERSION 12 | ||
670 | |||
671 | -/* *** Deprecated interfaces *** */ | ||
672 | - | ||
673 | -#define KVM_TRC_SHIFT 16 | ||
674 | - | ||
675 | -#define KVM_TRC_ENTRYEXIT (1 << KVM_TRC_SHIFT) | ||
676 | -#define KVM_TRC_HANDLER (1 << (KVM_TRC_SHIFT + 1)) | ||
677 | - | ||
678 | -#define KVM_TRC_VMENTRY (KVM_TRC_ENTRYEXIT + 0x01) | ||
679 | -#define KVM_TRC_VMEXIT (KVM_TRC_ENTRYEXIT + 0x02) | ||
680 | -#define KVM_TRC_PAGE_FAULT (KVM_TRC_HANDLER + 0x01) | ||
681 | - | ||
682 | -#define KVM_TRC_HEAD_SIZE 12 | ||
683 | -#define KVM_TRC_CYCLE_SIZE 8 | ||
684 | -#define KVM_TRC_EXTRA_MAX 7 | ||
685 | - | ||
686 | -#define KVM_TRC_INJ_VIRQ (KVM_TRC_HANDLER + 0x02) | ||
687 | -#define KVM_TRC_REDELIVER_EVT (KVM_TRC_HANDLER + 0x03) | ||
688 | -#define KVM_TRC_PEND_INTR (KVM_TRC_HANDLER + 0x04) | ||
689 | -#define KVM_TRC_IO_READ (KVM_TRC_HANDLER + 0x05) | ||
690 | -#define KVM_TRC_IO_WRITE (KVM_TRC_HANDLER + 0x06) | ||
691 | -#define KVM_TRC_CR_READ (KVM_TRC_HANDLER + 0x07) | ||
692 | -#define KVM_TRC_CR_WRITE (KVM_TRC_HANDLER + 0x08) | ||
693 | -#define KVM_TRC_DR_READ (KVM_TRC_HANDLER + 0x09) | ||
694 | -#define KVM_TRC_DR_WRITE (KVM_TRC_HANDLER + 0x0A) | ||
695 | -#define KVM_TRC_MSR_READ (KVM_TRC_HANDLER + 0x0B) | ||
696 | -#define KVM_TRC_MSR_WRITE (KVM_TRC_HANDLER + 0x0C) | ||
697 | -#define KVM_TRC_CPUID (KVM_TRC_HANDLER + 0x0D) | ||
698 | -#define KVM_TRC_INTR (KVM_TRC_HANDLER + 0x0E) | ||
699 | -#define KVM_TRC_NMI (KVM_TRC_HANDLER + 0x0F) | ||
700 | -#define KVM_TRC_VMMCALL (KVM_TRC_HANDLER + 0x10) | ||
701 | -#define KVM_TRC_HLT (KVM_TRC_HANDLER + 0x11) | ||
702 | -#define KVM_TRC_CLTS (KVM_TRC_HANDLER + 0x12) | ||
703 | -#define KVM_TRC_LMSW (KVM_TRC_HANDLER + 0x13) | ||
704 | -#define KVM_TRC_APIC_ACCESS (KVM_TRC_HANDLER + 0x14) | ||
705 | -#define KVM_TRC_TDP_FAULT (KVM_TRC_HANDLER + 0x15) | ||
706 | -#define KVM_TRC_GTLB_WRITE (KVM_TRC_HANDLER + 0x16) | ||
707 | -#define KVM_TRC_STLB_WRITE (KVM_TRC_HANDLER + 0x17) | ||
708 | -#define KVM_TRC_STLB_INVAL (KVM_TRC_HANDLER + 0x18) | ||
709 | -#define KVM_TRC_PPC_INSTR (KVM_TRC_HANDLER + 0x19) | ||
710 | - | ||
711 | -struct kvm_user_trace_setup { | ||
712 | - __u32 buf_size; | ||
713 | - __u32 buf_nr; | ||
714 | -}; | ||
715 | - | ||
716 | -#define __KVM_DEPRECATED_MAIN_W_0x06 \ | ||
717 | - _IOW(KVMIO, 0x06, struct kvm_user_trace_setup) | ||
718 | -#define __KVM_DEPRECATED_MAIN_0x07 _IO(KVMIO, 0x07) | ||
719 | -#define __KVM_DEPRECATED_MAIN_0x08 _IO(KVMIO, 0x08) | ||
720 | - | ||
721 | -#define __KVM_DEPRECATED_VM_R_0x70 _IOR(KVMIO, 0x70, struct kvm_assigned_irq) | ||
722 | - | ||
723 | -struct kvm_breakpoint { | ||
724 | - __u32 enabled; | ||
725 | - __u32 padding; | ||
726 | - __u64 address; | ||
727 | -}; | ||
728 | - | ||
729 | -struct kvm_debug_guest { | ||
730 | - __u32 enabled; | ||
731 | - __u32 pad; | ||
732 | - struct kvm_breakpoint breakpoints[4]; | ||
733 | - __u32 singlestep; | ||
734 | -}; | ||
735 | - | ||
736 | -#define __KVM_DEPRECATED_VCPU_W_0x87 _IOW(KVMIO, 0x87, struct kvm_debug_guest) | ||
737 | - | ||
738 | -/* *** End of deprecated interfaces *** */ | ||
739 | - | ||
740 | - | ||
741 | /* for KVM_SET_USER_MEMORY_REGION */ | ||
742 | struct kvm_userspace_memory_region { | ||
743 | __u32 slot; | ||
744 | @@ -XXX,XX +XXX,XX @@ struct kvm_userspace_memory_region { | ||
745 | __u64 userspace_addr; /* start of the userspace allocated memory */ | ||
746 | }; | ||
747 | |||
748 | +/* for KVM_SET_USER_MEMORY_REGION2 */ | ||
749 | +struct kvm_userspace_memory_region2 { | ||
750 | + __u32 slot; | ||
751 | + __u32 flags; | ||
752 | + __u64 guest_phys_addr; | ||
753 | + __u64 memory_size; | ||
754 | + __u64 userspace_addr; | ||
755 | + __u64 guest_memfd_offset; | ||
756 | + __u32 guest_memfd; | ||
757 | + __u32 pad1; | ||
758 | + __u64 pad2[14]; | ||
759 | +}; | ||
760 | + | ||
761 | /* | ||
762 | * The bit 0 ~ bit 15 of kvm_userspace_memory_region::flags are visible for | ||
763 | * userspace, other bits are reserved for kvm internal use which are defined | ||
764 | @@ -XXX,XX +XXX,XX @@ struct kvm_userspace_memory_region { | ||
765 | */ | ||
766 | #define KVM_MEM_LOG_DIRTY_PAGES (1UL << 0) | ||
767 | #define KVM_MEM_READONLY (1UL << 1) | ||
768 | +#define KVM_MEM_GUEST_MEMFD (1UL << 2) | ||
769 | |||
770 | /* for KVM_IRQ_LINE */ | ||
771 | struct kvm_irq_level { | ||
772 | @@ -XXX,XX +XXX,XX @@ struct kvm_xen_exit { | ||
773 | #define KVM_EXIT_RISCV_CSR 36 | ||
774 | #define KVM_EXIT_NOTIFY 37 | ||
775 | #define KVM_EXIT_LOONGARCH_IOCSR 38 | ||
776 | +#define KVM_EXIT_MEMORY_FAULT 39 | ||
777 | |||
778 | /* For KVM_EXIT_INTERNAL_ERROR */ | ||
779 | /* Emulate instruction failed. */ | ||
780 | @@ -XXX,XX +XXX,XX @@ struct kvm_run { | ||
781 | #define KVM_NOTIFY_CONTEXT_INVALID (1 << 0) | ||
782 | __u32 flags; | ||
783 | } notify; | ||
784 | + /* KVM_EXIT_MEMORY_FAULT */ | ||
785 | + struct { | ||
786 | +#define KVM_MEMORY_EXIT_FLAG_PRIVATE (1ULL << 3) | ||
787 | + __u64 flags; | ||
788 | + __u64 gpa; | ||
789 | + __u64 size; | ||
790 | + } memory_fault; | ||
791 | /* Fix the size of the union. */ | ||
792 | char padding[256]; | ||
793 | }; | ||
794 | @@ -XXX,XX +XXX,XX @@ struct kvm_ppc_resize_hpt { | ||
795 | */ | ||
796 | #define KVM_GET_VCPU_MMAP_SIZE _IO(KVMIO, 0x04) /* in bytes */ | ||
797 | #define KVM_GET_SUPPORTED_CPUID _IOWR(KVMIO, 0x05, struct kvm_cpuid2) | ||
798 | -#define KVM_TRACE_ENABLE __KVM_DEPRECATED_MAIN_W_0x06 | ||
799 | -#define KVM_TRACE_PAUSE __KVM_DEPRECATED_MAIN_0x07 | ||
800 | -#define KVM_TRACE_DISABLE __KVM_DEPRECATED_MAIN_0x08 | ||
801 | #define KVM_GET_EMULATED_CPUID _IOWR(KVMIO, 0x09, struct kvm_cpuid2) | ||
802 | #define KVM_GET_MSR_FEATURE_INDEX_LIST _IOWR(KVMIO, 0x0a, struct kvm_msr_list) | ||
803 | |||
804 | @@ -XXX,XX +XXX,XX @@ struct kvm_ppc_resize_hpt { | ||
805 | #define KVM_CAP_ARM_EAGER_SPLIT_CHUNK_SIZE 228 | ||
806 | #define KVM_CAP_ARM_SUPPORTED_BLOCK_SIZES 229 | ||
807 | #define KVM_CAP_ARM_SUPPORTED_REG_MASK_RANGES 230 | ||
808 | +#define KVM_CAP_USER_MEMORY2 231 | ||
809 | +#define KVM_CAP_MEMORY_FAULT_INFO 232 | ||
810 | +#define KVM_CAP_MEMORY_ATTRIBUTES 233 | ||
811 | +#define KVM_CAP_GUEST_MEMFD 234 | ||
812 | +#define KVM_CAP_VM_TYPES 235 | ||
813 | |||
814 | #ifdef KVM_CAP_IRQ_ROUTING | ||
815 | |||
816 | @@ -XXX,XX +XXX,XX @@ struct kvm_x86_mce { | ||
817 | #define KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL (1 << 4) | ||
818 | #define KVM_XEN_HVM_CONFIG_EVTCHN_SEND (1 << 5) | ||
819 | #define KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG (1 << 6) | ||
820 | +#define KVM_XEN_HVM_CONFIG_PVCLOCK_TSC_UNSTABLE (1 << 7) | ||
821 | |||
822 | struct kvm_xen_hvm_config { | ||
823 | __u32 flags; | ||
824 | @@ -XXX,XX +XXX,XX @@ struct kvm_vfio_spapr_tce { | ||
825 | struct kvm_userspace_memory_region) | ||
826 | #define KVM_SET_TSS_ADDR _IO(KVMIO, 0x47) | ||
827 | #define KVM_SET_IDENTITY_MAP_ADDR _IOW(KVMIO, 0x48, __u64) | ||
828 | +#define KVM_SET_USER_MEMORY_REGION2 _IOW(KVMIO, 0x49, \ | ||
829 | + struct kvm_userspace_memory_region2) | ||
830 | |||
831 | /* enable ucontrol for s390 */ | ||
832 | struct kvm_s390_ucas_mapping { | ||
833 | @@ -XXX,XX +XXX,XX @@ struct kvm_s390_ucas_mapping { | ||
834 | _IOW(KVMIO, 0x67, struct kvm_coalesced_mmio_zone) | ||
835 | #define KVM_UNREGISTER_COALESCED_MMIO \ | ||
836 | _IOW(KVMIO, 0x68, struct kvm_coalesced_mmio_zone) | ||
837 | -#define KVM_ASSIGN_PCI_DEVICE _IOR(KVMIO, 0x69, \ | ||
838 | - struct kvm_assigned_pci_dev) | ||
839 | #define KVM_SET_GSI_ROUTING _IOW(KVMIO, 0x6a, struct kvm_irq_routing) | ||
840 | -/* deprecated, replaced by KVM_ASSIGN_DEV_IRQ */ | ||
841 | -#define KVM_ASSIGN_IRQ __KVM_DEPRECATED_VM_R_0x70 | ||
842 | -#define KVM_ASSIGN_DEV_IRQ _IOW(KVMIO, 0x70, struct kvm_assigned_irq) | ||
843 | #define KVM_REINJECT_CONTROL _IO(KVMIO, 0x71) | ||
844 | -#define KVM_DEASSIGN_PCI_DEVICE _IOW(KVMIO, 0x72, \ | ||
845 | - struct kvm_assigned_pci_dev) | ||
846 | -#define KVM_ASSIGN_SET_MSIX_NR _IOW(KVMIO, 0x73, \ | ||
847 | - struct kvm_assigned_msix_nr) | ||
848 | -#define KVM_ASSIGN_SET_MSIX_ENTRY _IOW(KVMIO, 0x74, \ | ||
849 | - struct kvm_assigned_msix_entry) | ||
850 | -#define KVM_DEASSIGN_DEV_IRQ _IOW(KVMIO, 0x75, struct kvm_assigned_irq) | ||
851 | #define KVM_IRQFD _IOW(KVMIO, 0x76, struct kvm_irqfd) | ||
852 | #define KVM_CREATE_PIT2 _IOW(KVMIO, 0x77, struct kvm_pit_config) | ||
853 | #define KVM_SET_BOOT_CPU_ID _IO(KVMIO, 0x78) | ||
854 | @@ -XXX,XX +XXX,XX @@ struct kvm_s390_ucas_mapping { | ||
855 | * KVM_CAP_VM_TSC_CONTROL to set defaults for a VM */ | ||
856 | #define KVM_SET_TSC_KHZ _IO(KVMIO, 0xa2) | ||
857 | #define KVM_GET_TSC_KHZ _IO(KVMIO, 0xa3) | ||
858 | -/* Available with KVM_CAP_PCI_2_3 */ | ||
859 | -#define KVM_ASSIGN_SET_INTX_MASK _IOW(KVMIO, 0xa4, \ | ||
860 | - struct kvm_assigned_pci_dev) | ||
861 | /* Available with KVM_CAP_SIGNAL_MSI */ | ||
862 | #define KVM_SIGNAL_MSI _IOW(KVMIO, 0xa5, struct kvm_msi) | ||
863 | /* Available with KVM_CAP_PPC_GET_SMMU_INFO */ | ||
864 | @@ -XXX,XX +XXX,XX @@ struct kvm_s390_ucas_mapping { | ||
865 | #define KVM_SET_SREGS _IOW(KVMIO, 0x84, struct kvm_sregs) | ||
866 | #define KVM_TRANSLATE _IOWR(KVMIO, 0x85, struct kvm_translation) | ||
867 | #define KVM_INTERRUPT _IOW(KVMIO, 0x86, struct kvm_interrupt) | ||
868 | -/* KVM_DEBUG_GUEST is no longer supported, use KVM_SET_GUEST_DEBUG instead */ | ||
869 | -#define KVM_DEBUG_GUEST __KVM_DEPRECATED_VCPU_W_0x87 | ||
870 | #define KVM_GET_MSRS _IOWR(KVMIO, 0x88, struct kvm_msrs) | ||
871 | #define KVM_SET_MSRS _IOW(KVMIO, 0x89, struct kvm_msrs) | ||
872 | #define KVM_SET_CPUID _IOW(KVMIO, 0x8a, struct kvm_cpuid) | ||
873 | @@ -XXX,XX +XXX,XX @@ struct kvm_s390_zpci_op { | ||
874 | /* flags for kvm_s390_zpci_op->u.reg_aen.flags */ | ||
875 | #define KVM_S390_ZPCIOP_REGAEN_HOST (1 << 0) | ||
876 | |||
877 | +/* Available with KVM_CAP_MEMORY_ATTRIBUTES */ | ||
878 | +#define KVM_SET_MEMORY_ATTRIBUTES _IOW(KVMIO, 0xd2, struct kvm_memory_attributes) | ||
879 | + | ||
880 | +struct kvm_memory_attributes { | ||
881 | + __u64 address; | ||
882 | + __u64 size; | ||
883 | + __u64 attributes; | ||
884 | + __u64 flags; | ||
885 | +}; | ||
886 | + | ||
887 | +#define KVM_MEMORY_ATTRIBUTE_PRIVATE (1ULL << 3) | ||
888 | + | ||
889 | +#define KVM_CREATE_GUEST_MEMFD _IOWR(KVMIO, 0xd4, struct kvm_create_guest_memfd) | ||
890 | + | ||
891 | +struct kvm_create_guest_memfd { | ||
892 | + __u64 size; | ||
893 | + __u64 flags; | ||
894 | + __u64 reserved[6]; | ||
895 | +}; | ||
896 | + | ||
897 | #endif /* __LINUX_KVM_H */ | ||
898 | diff --git a/linux-headers/linux/userfaultfd.h b/linux-headers/linux/userfaultfd.h | ||
899 | index XXXXXXX..XXXXXXX 100644 | ||
900 | --- a/linux-headers/linux/userfaultfd.h | ||
901 | +++ b/linux-headers/linux/userfaultfd.h | ||
902 | @@ -XXX,XX +XXX,XX @@ | ||
903 | UFFD_FEATURE_WP_HUGETLBFS_SHMEM | \ | ||
904 | UFFD_FEATURE_WP_UNPOPULATED | \ | ||
905 | UFFD_FEATURE_POISON | \ | ||
906 | - UFFD_FEATURE_WP_ASYNC) | ||
907 | + UFFD_FEATURE_WP_ASYNC | \ | ||
908 | + UFFD_FEATURE_MOVE) | ||
909 | #define UFFD_API_IOCTLS \ | ||
910 | ((__u64)1 << _UFFDIO_REGISTER | \ | ||
911 | (__u64)1 << _UFFDIO_UNREGISTER | \ | ||
912 | @@ -XXX,XX +XXX,XX @@ | ||
913 | ((__u64)1 << _UFFDIO_WAKE | \ | ||
914 | (__u64)1 << _UFFDIO_COPY | \ | ||
915 | (__u64)1 << _UFFDIO_ZEROPAGE | \ | ||
916 | + (__u64)1 << _UFFDIO_MOVE | \ | ||
917 | (__u64)1 << _UFFDIO_WRITEPROTECT | \ | ||
918 | (__u64)1 << _UFFDIO_CONTINUE | \ | ||
919 | (__u64)1 << _UFFDIO_POISON) | ||
920 | @@ -XXX,XX +XXX,XX @@ | ||
921 | #define _UFFDIO_WAKE (0x02) | ||
922 | #define _UFFDIO_COPY (0x03) | ||
923 | #define _UFFDIO_ZEROPAGE (0x04) | ||
924 | +#define _UFFDIO_MOVE (0x05) | ||
925 | #define _UFFDIO_WRITEPROTECT (0x06) | ||
926 | #define _UFFDIO_CONTINUE (0x07) | ||
927 | #define _UFFDIO_POISON (0x08) | ||
928 | @@ -XXX,XX +XXX,XX @@ | ||
929 | struct uffdio_copy) | ||
930 | #define UFFDIO_ZEROPAGE _IOWR(UFFDIO, _UFFDIO_ZEROPAGE, \ | ||
931 | struct uffdio_zeropage) | ||
932 | +#define UFFDIO_MOVE _IOWR(UFFDIO, _UFFDIO_MOVE, \ | ||
933 | + struct uffdio_move) | ||
934 | #define UFFDIO_WRITEPROTECT _IOWR(UFFDIO, _UFFDIO_WRITEPROTECT, \ | ||
935 | struct uffdio_writeprotect) | ||
936 | #define UFFDIO_CONTINUE _IOWR(UFFDIO, _UFFDIO_CONTINUE, \ | ||
937 | @@ -XXX,XX +XXX,XX @@ struct uffdio_api { | ||
938 | * asynchronous mode is supported in which the write fault is | ||
939 | * automatically resolved and write-protection is un-set. | ||
940 | * It implies UFFD_FEATURE_WP_UNPOPULATED. | ||
941 | + * | ||
942 | + * UFFD_FEATURE_MOVE indicates that the kernel supports moving an | ||
943 | + * existing page contents from userspace. | ||
944 | */ | ||
945 | #define UFFD_FEATURE_PAGEFAULT_FLAG_WP (1<<0) | ||
946 | #define UFFD_FEATURE_EVENT_FORK (1<<1) | ||
947 | @@ -XXX,XX +XXX,XX @@ struct uffdio_api { | ||
948 | #define UFFD_FEATURE_WP_UNPOPULATED (1<<13) | ||
949 | #define UFFD_FEATURE_POISON (1<<14) | ||
950 | #define UFFD_FEATURE_WP_ASYNC (1<<15) | ||
951 | +#define UFFD_FEATURE_MOVE (1<<16) | ||
952 | __u64 features; | ||
953 | |||
954 | __u64 ioctls; | ||
955 | @@ -XXX,XX +XXX,XX @@ struct uffdio_poison { | ||
956 | __s64 updated; | ||
957 | }; | ||
958 | |||
959 | +struct uffdio_move { | ||
960 | + __u64 dst; | ||
961 | + __u64 src; | ||
962 | + __u64 len; | ||
963 | + /* | ||
964 | + * Especially if used to atomically remove memory from the | ||
965 | + * address space the wake on the dst range is not needed. | ||
966 | + */ | ||
967 | +#define UFFDIO_MOVE_MODE_DONTWAKE ((__u64)1<<0) | ||
968 | +#define UFFDIO_MOVE_MODE_ALLOW_SRC_HOLES ((__u64)1<<1) | ||
969 | + __u64 mode; | ||
970 | + /* | ||
971 | + * "move" is written by the ioctl and must be at the end: the | ||
972 | + * copy_from_user will not read the last 8 bytes. | ||
973 | + */ | ||
974 | + __s64 move; | ||
975 | +}; | ||
976 | + | ||
977 | /* | ||
978 | * Flags for the userfaultfd(2) system call itself. | ||
979 | */ | ||
980 | diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h | ||
981 | index XXXXXXX..XXXXXXX 100644 | ||
982 | --- a/linux-headers/linux/vfio.h | ||
983 | +++ b/linux-headers/linux/vfio.h | ||
984 | @@ -XXX,XX +XXX,XX @@ enum vfio_device_mig_state { | ||
985 | VFIO_DEVICE_STATE_RUNNING_P2P = 5, | ||
986 | VFIO_DEVICE_STATE_PRE_COPY = 6, | ||
987 | VFIO_DEVICE_STATE_PRE_COPY_P2P = 7, | ||
988 | + VFIO_DEVICE_STATE_NR, | ||
989 | }; | ||
990 | |||
991 | /** | ||
992 | -- | 90 | -- |
993 | 2.44.0 | 91 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Andrew Jones <ajones@ventanamicro.com> | 1 | From: Vineet Gupta <vineetg@rivosinc.com> |
---|---|---|---|
2 | 2 | ||
3 | Named features are extensions which don't make sense for users to | 3 | zicond is now codegen supported in both llvm and gcc. |
4 | control and are therefore not exposed on the command line. However, | ||
5 | svade is an extension which makes sense for users to control, so treat | ||
6 | it like a "normal" extension. The default is false, even for the max | ||
7 | cpu type, since QEMU has always implemented hardware A/D PTE bit | ||
8 | updating, so users must opt into svade (or get it from a CPU type | ||
9 | which enables it by default). | ||
10 | 4 | ||
11 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 5 | This change allows seamless enabling/testing of zicond in downstream |
12 | Signed-off-by: Andrew Jones <ajones@ventanamicro.com> | 6 | projects. e.g. currently riscv-gnu-toolchain parses elf attributes |
7 | to create a cmdline for qemu but fails short of enabling it because of | ||
8 | the "x-" prefix. | ||
9 | |||
10 | Signed-off-by: Vineet Gupta <vineetg@rivosinc.com> | ||
11 | Message-ID: <20230808181715.436395-1-vineetg@rivosinc.com> | ||
13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
14 | Message-ID: <20240215223955.969568-7-dbarboza@ventanamicro.com> | ||
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
16 | --- | 14 | --- |
17 | target/riscv/cpu.c | 9 ++------- | 15 | target/riscv/cpu.c | 2 +- |
18 | target/riscv/tcg/tcg-cpu.c | 6 ++++++ | 16 | 1 file changed, 1 insertion(+), 1 deletion(-) |
19 | 2 files changed, 8 insertions(+), 7 deletions(-) | ||
20 | 17 | ||
21 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 18 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
22 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/target/riscv/cpu.c | 20 | --- a/target/riscv/cpu.c |
24 | +++ b/target/riscv/cpu.c | 21 | +++ b/target/riscv/cpu.c |
25 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { | 22 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = { |
26 | 23 | DEFINE_PROP_BOOL("zcf", RISCVCPU, cfg.ext_zcf, false), | |
27 | MULTI_EXT_CFG_BOOL("smepmp", ext_smepmp, false), | 24 | DEFINE_PROP_BOOL("zcmp", RISCVCPU, cfg.ext_zcmp, false), |
28 | MULTI_EXT_CFG_BOOL("smstateen", ext_smstateen, false), | 25 | DEFINE_PROP_BOOL("zcmt", RISCVCPU, cfg.ext_zcmt, false), |
29 | + MULTI_EXT_CFG_BOOL("svade", ext_svade, false), | 26 | + DEFINE_PROP_BOOL("zicond", RISCVCPU, cfg.ext_zicond, false), |
30 | MULTI_EXT_CFG_BOOL("svadu", ext_svadu, true), | 27 | |
31 | MULTI_EXT_CFG_BOOL("svinval", ext_svinval, false), | 28 | /* Vendor-specific custom extensions */ |
32 | MULTI_EXT_CFG_BOOL("svnapot", ext_svnapot, false), | 29 | DEFINE_PROP_BOOL("xtheadba", RISCVCPU, cfg.ext_xtheadba, false), |
33 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = { | 30 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = { |
34 | * and priv_ver like regular extensions. | 31 | DEFINE_PROP_BOOL("xventanacondops", RISCVCPU, cfg.ext_XVentanaCondOps, false), |
35 | */ | 32 | |
36 | const RISCVCPUMultiExtConfig riscv_cpu_named_features[] = { | 33 | /* These are experimental so mark with 'x-' */ |
37 | - MULTI_EXT_CFG_BOOL("svade", ext_svade, true), | 34 | - DEFINE_PROP_BOOL("x-zicond", RISCVCPU, cfg.ext_zicond, false), |
38 | MULTI_EXT_CFG_BOOL("zic64b", ext_zic64b, true), | 35 | |
39 | 36 | /* ePMP 0.9.3 */ | |
40 | /* | 37 | DEFINE_PROP_BOOL("x-epmp", RISCVCPU, cfg.epmp, false), |
41 | @@ -XXX,XX +XXX,XX @@ static RISCVCPUProfile RVA22U64 = { | ||
42 | * Other named features that we already implement: Sstvecd, Sstvala, | ||
43 | * Sscounterenw | ||
44 | * | ||
45 | - * Named features that we need to enable: svade | ||
46 | - * | ||
47 | * The remaining features/extensions comes from RVA22U64. | ||
48 | */ | ||
49 | static RISCVCPUProfile RVA22S64 = { | ||
50 | @@ -XXX,XX +XXX,XX @@ static RISCVCPUProfile RVA22S64 = { | ||
51 | .ext_offsets = { | ||
52 | /* rva22s64 exts */ | ||
53 | CPU_CFG_OFFSET(ext_zifencei), CPU_CFG_OFFSET(ext_svpbmt), | ||
54 | - CPU_CFG_OFFSET(ext_svinval), | ||
55 | - | ||
56 | - /* rva22s64 named features */ | ||
57 | - CPU_CFG_OFFSET(ext_svade), | ||
58 | + CPU_CFG_OFFSET(ext_svinval), CPU_CFG_OFFSET(ext_svade), | ||
59 | |||
60 | RISCV_PROFILE_EXT_LIST_END | ||
61 | } | ||
62 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
63 | index XXXXXXX..XXXXXXX 100644 | ||
64 | --- a/target/riscv/tcg/tcg-cpu.c | ||
65 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
66 | @@ -XXX,XX +XXX,XX @@ static void riscv_init_max_cpu_extensions(Object *obj) | ||
67 | isa_ext_update_enabled(cpu, prop->offset, true); | ||
68 | } | ||
69 | |||
70 | + /* | ||
71 | + * Some extensions can't be added without backward compatibilty concerns. | ||
72 | + * Disable those, the user can still opt in to them on the command line. | ||
73 | + */ | ||
74 | + cpu->cfg.ext_svade = false; | ||
75 | + | ||
76 | /* set vector version */ | ||
77 | env->vext_ver = VEXT_VERSION_1_00_0; | ||
78 | |||
79 | -- | 38 | -- |
80 | 2.44.0 | 39 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Hotplugged FDT nodes will attempt to write this node that, at this | 3 | A build with --enable-debug and without KVM will fail as follows: |
4 | moment, is being created only in create_fdt_pcie() during | ||
5 | finalize_fdt(). | ||
6 | 4 | ||
7 | Create it earlier. | 5 | /usr/bin/ld: libqemu-riscv64-softmmu.fa.p/hw_riscv_virt.c.o: in function `virt_machine_init': |
6 | ./qemu/build/../hw/riscv/virt.c:1465: undefined reference to `kvm_riscv_aia_create' | ||
8 | 7 | ||
8 | This happens because the code block with "if virt_use_kvm_aia(s)" isn't | ||
9 | being ignored by the debug build, resulting in an undefined reference to | ||
10 | a KVM only function. | ||
11 | |||
12 | Add a 'kvm_enabled()' conditional together with virt_use_kvm_aia() will | ||
13 | make the compiler crop the kvm_riscv_aia_create() call entirely from a | ||
14 | non-KVM build. Note that adding the 'kvm_enabled()' conditional inside | ||
15 | virt_use_kvm_aia() won't fix the build because this function would need | ||
16 | to be inlined multiple times to make the compiler zero out the entire | ||
17 | block. | ||
18 | |||
19 | While we're at it, use kvm_enabled() in all instances where | ||
20 | virt_use_kvm_aia() is checked to allow the compiler to elide these other | ||
21 | kvm-only instances as well. | ||
22 | |||
23 | Suggested-by: Richard Henderson <richard.henderson@linaro.org> | ||
24 | Fixes: dbdb99948e ("target/riscv: select KVM AIA in riscv virt machine") | ||
9 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 25 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 26 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> |
11 | Message-ID: <20240217192607.32565-4-dbarboza@ventanamicro.com> | 27 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
28 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
29 | Message-ID: <20230830133503.711138-2-dbarboza@ventanamicro.com> | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 30 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | --- | 31 | --- |
14 | hw/riscv/virt.c | 9 ++++++++- | 32 | hw/riscv/virt.c | 6 +++--- |
15 | 1 file changed, 8 insertions(+), 1 deletion(-) | 33 | 1 file changed, 3 insertions(+), 3 deletions(-) |
16 | 34 | ||
17 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | 35 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c |
18 | index XXXXXXX..XXXXXXX 100644 | 36 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/hw/riscv/virt.c | 37 | --- a/hw/riscv/virt.c |
20 | +++ b/hw/riscv/virt.c | 38 | +++ b/hw/riscv/virt.c |
21 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_pcie(RISCVVirtState *s, const MemMapEntry *memmap, | 39 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, |
22 | 40 | } | |
23 | name = g_strdup_printf("/soc/pci@%lx", | 41 | |
24 | (long) memmap[VIRT_PCIE_ECAM].base); | 42 | /* KVM AIA only has one APLIC instance */ |
25 | - qemu_fdt_add_subnode(ms->fdt, name); | 43 | - if (virt_use_kvm_aia(s)) { |
26 | qemu_fdt_setprop_cell(ms->fdt, name, "#address-cells", | 44 | + if (kvm_enabled() && virt_use_kvm_aia(s)) { |
27 | FDT_PCI_ADDR_CELLS); | 45 | create_fdt_socket_aplic(s, memmap, 0, |
28 | qemu_fdt_setprop_cell(ms->fdt, name, "#interrupt-cells", | 46 | msi_m_phandle, msi_s_phandle, phandle, |
29 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(RISCVVirtState *s, const MemMapEntry *memmap) | 47 | &intc_phandles[0], xplic_phandles, |
30 | { | 48 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, |
31 | MachineState *ms = MACHINE(s); | 49 | |
32 | uint8_t rng_seed[32]; | 50 | g_free(intc_phandles); |
33 | + g_autofree char *name = NULL; | 51 | |
34 | 52 | - if (virt_use_kvm_aia(s)) { | |
35 | ms->fdt = create_device_tree(&s->fdt_size); | 53 | + if (kvm_enabled() && virt_use_kvm_aia(s)) { |
36 | if (!ms->fdt) { | 54 | *irq_mmio_phandle = xplic_phandles[0]; |
37 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(RISCVVirtState *s, const MemMapEntry *memmap) | 55 | *irq_virtio_phandle = xplic_phandles[0]; |
38 | qemu_fdt_setprop_cell(ms->fdt, "/soc", "#size-cells", 0x2); | 56 | *irq_pcie_phandle = xplic_phandles[0]; |
39 | qemu_fdt_setprop_cell(ms->fdt, "/soc", "#address-cells", 0x2); | 57 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine) |
40 | 58 | } | |
41 | + /* | 59 | } |
42 | + * The "/soc/pci@..." node is needed for PCIE hotplugs | 60 | |
43 | + * that might happen before finalize_fdt(). | 61 | - if (virt_use_kvm_aia(s)) { |
44 | + */ | 62 | + if (kvm_enabled() && virt_use_kvm_aia(s)) { |
45 | + name = g_strdup_printf("/soc/pci@%lx", (long) memmap[VIRT_PCIE_ECAM].base); | 63 | kvm_riscv_aia_create(machine, IMSIC_MMIO_GROUP_MIN_SHIFT, |
46 | + qemu_fdt_add_subnode(ms->fdt, name); | 64 | VIRT_IRQCHIP_NUM_SOURCES, VIRT_IRQCHIP_NUM_MSIS, |
47 | + | 65 | memmap[VIRT_APLIC_S].base, |
48 | qemu_fdt_add_subnode(ms->fdt, "/chosen"); | ||
49 | |||
50 | /* Pass seed to RNG */ | ||
51 | -- | 66 | -- |
52 | 2.44.0 | 67 | 2.41.0 |
68 | |||
69 | diff view generated by jsdifflib |
1 | From: Anup Patel <apatel@ventanamicro.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | The reads to in_clrip[x] registers return rectified input values of the | 3 | Commit 6df0b37e2ab breaks a --enable-debug build in a non-KVM |
4 | interrupt sources. | 4 | environment with the following error: |
5 | 5 | ||
6 | A rectified input value of an interrupt source is defined by the section | 6 | /usr/bin/ld: libqemu-riscv64-softmmu.fa.p/hw_intc_riscv_aplic.c.o: in function `riscv_kvm_aplic_request': |
7 | "4.5.2 Source configurations (sourcecfg[1]–sourcecfg[1023])" of the RISC-V | 7 | ./qemu/build/../hw/intc/riscv_aplic.c:486: undefined reference to `kvm_set_irq' |
8 | AIA specification as: | 8 | collect2: error: ld returned 1 exit status |
9 | "rectified input value = (incoming wire value) XOR (source is inverted)" | ||
10 | 9 | ||
11 | Update the riscv_aplic_read_input_word() implementation to match the above. | 10 | This happens because the debug build will poke into the |
11 | 'if (is_kvm_aia(aplic->msimode))' block and fail to find a reference to | ||
12 | the KVM only function riscv_kvm_aplic_request(). | ||
12 | 13 | ||
13 | Fixes: e8f79343cfc8 ("hw/intc: Add RISC-V AIA APLIC device emulation") | 14 | There are multiple solutions to fix this. We'll go with the same |
14 | Signed-off-by: Anup Patel <apatel@ventanamicro.com> | 15 | solution from the previous patch, i.e. add a kvm_enabled() conditional |
15 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 16 | to filter out the block. But there's a catch: riscv_kvm_aplic_request() |
16 | Message-ID: <20240306095722.463296-3-apatel@ventanamicro.com> | 17 | is a local function that would end up being used if the compiler crops |
18 | the block, and this won't work. Quoting Richard Henderson's explanation | ||
19 | in [1]: | ||
20 | |||
21 | "(...) the compiler won't eliminate entire unused functions with -O0" | ||
22 | |||
23 | We'll solve it by moving riscv_kvm_aplic_request() to kvm.c and add its | ||
24 | declaration in kvm_riscv.h, where all other KVM specific public | ||
25 | functions are already declared. Other archs handles KVM specific code in | ||
26 | this manner and we expect to do the same from now on. | ||
27 | |||
28 | [1] https://lore.kernel.org/qemu-riscv/d2f1ad02-eb03-138f-9d08-db676deeed05@linaro.org/ | ||
29 | |||
30 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
31 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
32 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
33 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
34 | Message-ID: <20230830133503.711138-3-dbarboza@ventanamicro.com> | ||
17 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 35 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
18 | --- | 36 | --- |
19 | hw/intc/riscv_aplic.c | 17 +++++++++++++++-- | 37 | target/riscv/kvm_riscv.h | 1 + |
20 | 1 file changed, 15 insertions(+), 2 deletions(-) | 38 | hw/intc/riscv_aplic.c | 8 ++------ |
39 | target/riscv/kvm.c | 5 +++++ | ||
40 | 3 files changed, 8 insertions(+), 6 deletions(-) | ||
21 | 41 | ||
42 | diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/target/riscv/kvm_riscv.h | ||
45 | +++ b/target/riscv/kvm_riscv.h | ||
46 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, | ||
47 | uint64_t aia_irq_num, uint64_t aia_msi_num, | ||
48 | uint64_t aplic_base, uint64_t imsic_base, | ||
49 | uint64_t guest_num); | ||
50 | +void riscv_kvm_aplic_request(void *opaque, int irq, int level); | ||
51 | |||
52 | #endif | ||
22 | diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c | 53 | diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c |
23 | index XXXXXXX..XXXXXXX 100644 | 54 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/hw/intc/riscv_aplic.c | 55 | --- a/hw/intc/riscv_aplic.c |
25 | +++ b/hw/intc/riscv_aplic.c | 56 | +++ b/hw/intc/riscv_aplic.c |
26 | @@ -XXX,XX +XXX,XX @@ static bool is_kvm_aia(bool msimode) | 57 | @@ -XXX,XX +XXX,XX @@ |
27 | static uint32_t riscv_aplic_read_input_word(RISCVAPLICState *aplic, | 58 | #include "target/riscv/cpu.h" |
28 | uint32_t word) | 59 | #include "sysemu/sysemu.h" |
60 | #include "sysemu/kvm.h" | ||
61 | +#include "kvm_riscv.h" | ||
62 | #include "migration/vmstate.h" | ||
63 | |||
64 | #define APLIC_MAX_IDC (1UL << 14) | ||
65 | @@ -XXX,XX +XXX,XX @@ static uint32_t riscv_aplic_idc_claimi(RISCVAPLICState *aplic, uint32_t idc) | ||
66 | return topi; | ||
67 | } | ||
68 | |||
69 | -static void riscv_kvm_aplic_request(void *opaque, int irq, int level) | ||
70 | -{ | ||
71 | - kvm_set_irq(kvm_state, irq, !!level); | ||
72 | -} | ||
73 | - | ||
74 | static void riscv_aplic_request(void *opaque, int irq, int level) | ||
29 | { | 75 | { |
30 | - uint32_t i, irq, ret = 0; | 76 | bool update = false; |
31 | + uint32_t i, irq, sourcecfg, sm, raw_input, irq_inverted, ret = 0; | 77 | @@ -XXX,XX +XXX,XX @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp) |
32 | 78 | * have IRQ lines delegated by their parent APLIC. | |
33 | for (i = 0; i < 32; i++) { | 79 | */ |
34 | irq = word * 32 + i; | 80 | if (!aplic->parent) { |
35 | @@ -XXX,XX +XXX,XX @@ static uint32_t riscv_aplic_read_input_word(RISCVAPLICState *aplic, | 81 | - if (is_kvm_aia(aplic->msimode)) { |
36 | continue; | 82 | + if (kvm_enabled() && is_kvm_aia(aplic->msimode)) { |
37 | } | 83 | qdev_init_gpio_in(dev, riscv_kvm_aplic_request, aplic->num_irqs); |
38 | 84 | } else { | |
39 | - ret |= ((aplic->state[irq] & APLIC_ISTATE_INPUT) ? 1 : 0) << i; | 85 | qdev_init_gpio_in(dev, riscv_aplic_request, aplic->num_irqs); |
40 | + sourcecfg = aplic->sourcecfg[irq]; | 86 | diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c |
41 | + if (sourcecfg & APLIC_SOURCECFG_D) { | 87 | index XXXXXXX..XXXXXXX 100644 |
42 | + continue; | 88 | --- a/target/riscv/kvm.c |
43 | + } | 89 | +++ b/target/riscv/kvm.c |
90 | @@ -XXX,XX +XXX,XX @@ | ||
91 | #include "sysemu/runstate.h" | ||
92 | #include "hw/riscv/numa.h" | ||
93 | |||
94 | +void riscv_kvm_aplic_request(void *opaque, int irq, int level) | ||
95 | +{ | ||
96 | + kvm_set_irq(kvm_state, irq, !!level); | ||
97 | +} | ||
44 | + | 98 | + |
45 | + sm = sourcecfg & APLIC_SOURCECFG_SM_MASK; | 99 | static uint64_t kvm_riscv_reg_id(CPURISCVState *env, uint64_t type, |
46 | + if (sm == APLIC_SOURCECFG_SM_INACTIVE) { | 100 | uint64_t idx) |
47 | + continue; | 101 | { |
48 | + } | ||
49 | + | ||
50 | + raw_input = (aplic->state[irq] & APLIC_ISTATE_INPUT) ? 1 : 0; | ||
51 | + irq_inverted = (sm == APLIC_SOURCECFG_SM_LEVEL_LOW || | ||
52 | + sm == APLIC_SOURCECFG_SM_EDGE_FALL) ? 1 : 0; | ||
53 | + ret |= (raw_input ^ irq_inverted) << i; | ||
54 | } | ||
55 | |||
56 | return ret; | ||
57 | -- | 102 | -- |
58 | 2.44.0 | 103 | 2.41.0 |
59 | 104 | ||
60 | 105 | diff view generated by jsdifflib |
1 | From: Christoph Müllner <christoph.muellner@vrull.eu> | 1 | From: Robbin Ehn <rehn@rivosinc.com> |
---|---|---|---|
2 | 2 | ||
3 | Upstream Linux recently added many additional keys to the hwprobe API. | 3 | This patch adds the new extensions in |
4 | This patch adds support for all of them with the exception of Ztso, | 4 | linux 6.5 to the hwprobe syscall. |
5 | which is currently not supported in QEMU. | ||
6 | 5 | ||
7 | Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu> | 6 | And fixes RVC check to OR with correct value. |
8 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 7 | The previous variable contains 0 therefore it |
9 | Message-ID: <20240207115926.887816-3-christoph.muellner@vrull.eu> | 8 | did work. |
10 | [ Changes by AF: | 9 | |
11 | - Fixup whitespace | 10 | Signed-off-by: Robbin Ehn <rehn@rivosinc.com> |
12 | ] | 11 | Acked-by: Richard Henderson <richard.henderson@linaro.org> |
12 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | Message-ID: <bc82203b72d7efb30f1b4a8f9eb3d94699799dc8.camel@rivosinc.com> | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
14 | --- | 15 | --- |
15 | linux-user/syscall.c | 100 +++++++++++++++++++++++++++++++++++++++---- | 16 | linux-user/syscall.c | 14 +++++++++++++- |
16 | 1 file changed, 92 insertions(+), 8 deletions(-) | 17 | 1 file changed, 13 insertions(+), 1 deletion(-) |
17 | 18 | ||
18 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c | 19 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c |
19 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/linux-user/syscall.c | 21 | --- a/linux-user/syscall.c |
21 | +++ b/linux-user/syscall.c | 22 | +++ b/linux-user/syscall.c |
22 | @@ -XXX,XX +XXX,XX @@ static int do_getdents64(abi_long dirfd, abi_long arg2, abi_long count) | 23 | @@ -XXX,XX +XXX,XX @@ static int do_getdents64(abi_long dirfd, abi_long arg2, abi_long count) |
23 | #define RISCV_HWPROBE_KEY_BASE_BEHAVIOR 3 | 24 | #define RISCV_HWPROBE_KEY_IMA_EXT_0 4 |
24 | #define RISCV_HWPROBE_BASE_BEHAVIOR_IMA (1 << 0) | 25 | #define RISCV_HWPROBE_IMA_FD (1 << 0) |
25 | 26 | #define RISCV_HWPROBE_IMA_C (1 << 1) | |
26 | -#define RISCV_HWPROBE_KEY_IMA_EXT_0 4 | 27 | +#define RISCV_HWPROBE_IMA_V (1 << 2) |
27 | -#define RISCV_HWPROBE_IMA_FD (1 << 0) | 28 | +#define RISCV_HWPROBE_EXT_ZBA (1 << 3) |
28 | -#define RISCV_HWPROBE_IMA_C (1 << 1) | 29 | +#define RISCV_HWPROBE_EXT_ZBB (1 << 4) |
29 | -#define RISCV_HWPROBE_IMA_V (1 << 2) | 30 | +#define RISCV_HWPROBE_EXT_ZBS (1 << 5) |
30 | -#define RISCV_HWPROBE_EXT_ZBA (1 << 3) | ||
31 | -#define RISCV_HWPROBE_EXT_ZBB (1 << 4) | ||
32 | -#define RISCV_HWPROBE_EXT_ZBS (1 << 5) | ||
33 | -#define RISCV_HWPROBE_EXT_ZICBOZ (1 << 6) | ||
34 | +#define RISCV_HWPROBE_KEY_IMA_EXT_0 4 | ||
35 | +#define RISCV_HWPROBE_IMA_FD (1 << 0) | ||
36 | +#define RISCV_HWPROBE_IMA_C (1 << 1) | ||
37 | +#define RISCV_HWPROBE_IMA_V (1 << 2) | ||
38 | +#define RISCV_HWPROBE_EXT_ZBA (1 << 3) | ||
39 | +#define RISCV_HWPROBE_EXT_ZBB (1 << 4) | ||
40 | +#define RISCV_HWPROBE_EXT_ZBS (1 << 5) | ||
41 | +#define RISCV_HWPROBE_EXT_ZICBOZ (1 << 6) | ||
42 | +#define RISCV_HWPROBE_EXT_ZBC (1 << 7) | ||
43 | +#define RISCV_HWPROBE_EXT_ZBKB (1 << 8) | ||
44 | +#define RISCV_HWPROBE_EXT_ZBKC (1 << 9) | ||
45 | +#define RISCV_HWPROBE_EXT_ZBKX (1 << 10) | ||
46 | +#define RISCV_HWPROBE_EXT_ZKND (1 << 11) | ||
47 | +#define RISCV_HWPROBE_EXT_ZKNE (1 << 12) | ||
48 | +#define RISCV_HWPROBE_EXT_ZKNH (1 << 13) | ||
49 | +#define RISCV_HWPROBE_EXT_ZKSED (1 << 14) | ||
50 | +#define RISCV_HWPROBE_EXT_ZKSH (1 << 15) | ||
51 | +#define RISCV_HWPROBE_EXT_ZKT (1 << 16) | ||
52 | +#define RISCV_HWPROBE_EXT_ZVBB (1 << 17) | ||
53 | +#define RISCV_HWPROBE_EXT_ZVBC (1 << 18) | ||
54 | +#define RISCV_HWPROBE_EXT_ZVKB (1 << 19) | ||
55 | +#define RISCV_HWPROBE_EXT_ZVKG (1 << 20) | ||
56 | +#define RISCV_HWPROBE_EXT_ZVKNED (1 << 21) | ||
57 | +#define RISCV_HWPROBE_EXT_ZVKNHA (1 << 22) | ||
58 | +#define RISCV_HWPROBE_EXT_ZVKNHB (1 << 23) | ||
59 | +#define RISCV_HWPROBE_EXT_ZVKSED (1 << 24) | ||
60 | +#define RISCV_HWPROBE_EXT_ZVKSH (1 << 25) | ||
61 | +#define RISCV_HWPROBE_EXT_ZVKT (1 << 26) | ||
62 | +#define RISCV_HWPROBE_EXT_ZFH (1 << 27) | ||
63 | +#define RISCV_HWPROBE_EXT_ZFHMIN (1 << 28) | ||
64 | +#define RISCV_HWPROBE_EXT_ZIHINTNTL (1 << 29) | ||
65 | +#define RISCV_HWPROBE_EXT_ZVFH (1 << 30) | ||
66 | +#define RISCV_HWPROBE_EXT_ZVFHMIN (1 << 31) | ||
67 | +#define RISCV_HWPROBE_EXT_ZFA (1ULL << 32) | ||
68 | +#define RISCV_HWPROBE_EXT_ZACAS (1ULL << 34) | ||
69 | +#define RISCV_HWPROBE_EXT_ZICOND (1ULL << 35) | ||
70 | 31 | ||
71 | #define RISCV_HWPROBE_KEY_CPUPERF_0 5 | 32 | #define RISCV_HWPROBE_KEY_CPUPERF_0 5 |
72 | #define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0) | 33 | #define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0) |
73 | @@ -XXX,XX +XXX,XX @@ static void risc_hwprobe_fill_pairs(CPURISCVState *env, | 34 | @@ -XXX,XX +XXX,XX @@ static void risc_hwprobe_fill_pairs(CPURISCVState *env, |
74 | RISCV_HWPROBE_EXT_ZBS : 0; | 35 | riscv_has_ext(env, RVD) ? |
75 | value |= cfg->ext_zicboz ? | 36 | RISCV_HWPROBE_IMA_FD : 0; |
76 | RISCV_HWPROBE_EXT_ZICBOZ : 0; | 37 | value |= riscv_has_ext(env, RVC) ? |
77 | + value |= cfg->ext_zbc ? | 38 | - RISCV_HWPROBE_IMA_C : pair->value; |
78 | + RISCV_HWPROBE_EXT_ZBC : 0; | 39 | + RISCV_HWPROBE_IMA_C : 0; |
79 | + value |= cfg->ext_zbkb ? | 40 | + value |= riscv_has_ext(env, RVV) ? |
80 | + RISCV_HWPROBE_EXT_ZBKB : 0; | 41 | + RISCV_HWPROBE_IMA_V : 0; |
81 | + value |= cfg->ext_zbkc ? | 42 | + value |= cfg->ext_zba ? |
82 | + RISCV_HWPROBE_EXT_ZBKC : 0; | 43 | + RISCV_HWPROBE_EXT_ZBA : 0; |
83 | + value |= cfg->ext_zbkx ? | 44 | + value |= cfg->ext_zbb ? |
84 | + RISCV_HWPROBE_EXT_ZBKX : 0; | 45 | + RISCV_HWPROBE_EXT_ZBB : 0; |
85 | + value |= cfg->ext_zknd ? | 46 | + value |= cfg->ext_zbs ? |
86 | + RISCV_HWPROBE_EXT_ZKND : 0; | 47 | + RISCV_HWPROBE_EXT_ZBS : 0; |
87 | + value |= cfg->ext_zkne ? | ||
88 | + RISCV_HWPROBE_EXT_ZKNE : 0; | ||
89 | + value |= cfg->ext_zknh ? | ||
90 | + RISCV_HWPROBE_EXT_ZKNH : 0; | ||
91 | + value |= cfg->ext_zksed ? | ||
92 | + RISCV_HWPROBE_EXT_ZKSED : 0; | ||
93 | + value |= cfg->ext_zksh ? | ||
94 | + RISCV_HWPROBE_EXT_ZKSH : 0; | ||
95 | + value |= cfg->ext_zkt ? | ||
96 | + RISCV_HWPROBE_EXT_ZKT : 0; | ||
97 | + value |= cfg->ext_zvbb ? | ||
98 | + RISCV_HWPROBE_EXT_ZVBB : 0; | ||
99 | + value |= cfg->ext_zvbc ? | ||
100 | + RISCV_HWPROBE_EXT_ZVBC : 0; | ||
101 | + value |= cfg->ext_zvkb ? | ||
102 | + RISCV_HWPROBE_EXT_ZVKB : 0; | ||
103 | + value |= cfg->ext_zvkg ? | ||
104 | + RISCV_HWPROBE_EXT_ZVKG : 0; | ||
105 | + value |= cfg->ext_zvkned ? | ||
106 | + RISCV_HWPROBE_EXT_ZVKNED : 0; | ||
107 | + value |= cfg->ext_zvknha ? | ||
108 | + RISCV_HWPROBE_EXT_ZVKNHA : 0; | ||
109 | + value |= cfg->ext_zvknhb ? | ||
110 | + RISCV_HWPROBE_EXT_ZVKNHB : 0; | ||
111 | + value |= cfg->ext_zvksed ? | ||
112 | + RISCV_HWPROBE_EXT_ZVKSED : 0; | ||
113 | + value |= cfg->ext_zvksh ? | ||
114 | + RISCV_HWPROBE_EXT_ZVKSH : 0; | ||
115 | + value |= cfg->ext_zvkt ? | ||
116 | + RISCV_HWPROBE_EXT_ZVKT : 0; | ||
117 | + value |= cfg->ext_zfh ? | ||
118 | + RISCV_HWPROBE_EXT_ZFH : 0; | ||
119 | + value |= cfg->ext_zfhmin ? | ||
120 | + RISCV_HWPROBE_EXT_ZFHMIN : 0; | ||
121 | + value |= cfg->ext_zihintntl ? | ||
122 | + RISCV_HWPROBE_EXT_ZIHINTNTL : 0; | ||
123 | + value |= cfg->ext_zvfh ? | ||
124 | + RISCV_HWPROBE_EXT_ZVFH : 0; | ||
125 | + value |= cfg->ext_zvfhmin ? | ||
126 | + RISCV_HWPROBE_EXT_ZVFHMIN : 0; | ||
127 | + value |= cfg->ext_zfa ? | ||
128 | + RISCV_HWPROBE_EXT_ZFA : 0; | ||
129 | + value |= cfg->ext_zacas ? | ||
130 | + RISCV_HWPROBE_EXT_ZACAS : 0; | ||
131 | + value |= cfg->ext_zicond ? | ||
132 | + RISCV_HWPROBE_EXT_ZICOND : 0; | ||
133 | __put_user(value, &pair->value); | 48 | __put_user(value, &pair->value); |
134 | break; | 49 | break; |
135 | case RISCV_HWPROBE_KEY_CPUPERF_0: | 50 | case RISCV_HWPROBE_KEY_CPUPERF_0: |
136 | -- | 51 | -- |
137 | 2.44.0 | 52 | 2.41.0 |
138 | |||
139 | diff view generated by jsdifflib |
1 | From: Christoph Müllner <christoph.muellner@vrull.eu> | 1 | From: Ard Biesheuvel <ardb@kernel.org> |
---|---|---|---|
2 | 2 | ||
3 | This patch exposes Ztso via hwprobe in QEMU's user space emulator. | 3 | Use the accelerated SubBytes/ShiftRows/AddRoundKey AES helper to |
4 | implement the first half of the key schedule derivation. This does not | ||
5 | actually involve shifting rows, so clone the same value into all four | ||
6 | columns of the AES vector to counter that operation. | ||
4 | 7 | ||
5 | Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu> | 8 | Cc: Richard Henderson <richard.henderson@linaro.org> |
6 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 9 | Cc: Philippe Mathieu-Daudé <philmd@linaro.org> |
7 | Message-ID: <20240207122256.902627-3-christoph.muellner@vrull.eu> | 10 | Cc: Palmer Dabbelt <palmer@dabbelt.com> |
11 | Cc: Alistair Francis <alistair.francis@wdc.com> | ||
12 | Signed-off-by: Ard Biesheuvel <ardb@kernel.org> | ||
13 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
14 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
15 | Message-ID: <20230831154118.138727-1-ardb@kernel.org> | ||
8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
9 | --- | 17 | --- |
10 | linux-user/syscall.c | 3 +++ | 18 | target/riscv/crypto_helper.c | 17 +++++------------ |
11 | 1 file changed, 3 insertions(+) | 19 | 1 file changed, 5 insertions(+), 12 deletions(-) |
12 | 20 | ||
13 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c | 21 | diff --git a/target/riscv/crypto_helper.c b/target/riscv/crypto_helper.c |
14 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/linux-user/syscall.c | 23 | --- a/target/riscv/crypto_helper.c |
16 | +++ b/linux-user/syscall.c | 24 | +++ b/target/riscv/crypto_helper.c |
17 | @@ -XXX,XX +XXX,XX @@ static int do_getdents64(abi_long dirfd, abi_long arg2, abi_long count) | 25 | @@ -XXX,XX +XXX,XX @@ target_ulong HELPER(aes64ks1i)(target_ulong rs1, target_ulong rnum) |
18 | #define RISCV_HWPROBE_EXT_ZVFH (1 << 30) | 26 | |
19 | #define RISCV_HWPROBE_EXT_ZVFHMIN (1 << 31) | 27 | uint8_t enc_rnum = rnum; |
20 | #define RISCV_HWPROBE_EXT_ZFA (1ULL << 32) | 28 | uint32_t temp = (RS1 >> 32) & 0xFFFFFFFF; |
21 | +#define RISCV_HWPROBE_EXT_ZTSO (1ULL << 33) | 29 | - uint8_t rcon_ = 0; |
22 | #define RISCV_HWPROBE_EXT_ZACAS (1ULL << 34) | 30 | - target_ulong result; |
23 | #define RISCV_HWPROBE_EXT_ZICOND (1ULL << 35) | 31 | + AESState t, rc = {}; |
24 | 32 | ||
25 | @@ -XXX,XX +XXX,XX @@ static void risc_hwprobe_fill_pairs(CPURISCVState *env, | 33 | if (enc_rnum != 0xA) { |
26 | RISCV_HWPROBE_EXT_ZVFHMIN : 0; | 34 | temp = ror32(temp, 8); /* Rotate right by 8 */ |
27 | value |= cfg->ext_zfa ? | 35 | - rcon_ = round_consts[enc_rnum]; |
28 | RISCV_HWPROBE_EXT_ZFA : 0; | 36 | + rc.w[0] = rc.w[1] = round_consts[enc_rnum]; |
29 | + value |= cfg->ext_ztso ? | 37 | } |
30 | + RISCV_HWPROBE_EXT_ZTSO : 0; | 38 | |
31 | value |= cfg->ext_zacas ? | 39 | - temp = ((uint32_t)AES_sbox[(temp >> 24) & 0xFF] << 24) | |
32 | RISCV_HWPROBE_EXT_ZACAS : 0; | 40 | - ((uint32_t)AES_sbox[(temp >> 16) & 0xFF] << 16) | |
33 | value |= cfg->ext_zicond ? | 41 | - ((uint32_t)AES_sbox[(temp >> 8) & 0xFF] << 8) | |
42 | - ((uint32_t)AES_sbox[(temp >> 0) & 0xFF] << 0); | ||
43 | + t.w[0] = t.w[1] = t.w[2] = t.w[3] = temp; | ||
44 | + aesenc_SB_SR_AK(&t, &t, &rc, false); | ||
45 | |||
46 | - temp ^= rcon_; | ||
47 | - | ||
48 | - result = ((uint64_t)temp << 32) | temp; | ||
49 | - | ||
50 | - return result; | ||
51 | + return t.d[0]; | ||
52 | } | ||
53 | |||
54 | target_ulong HELPER(aes64im)(target_ulong rs1) | ||
34 | -- | 55 | -- |
35 | 2.44.0 | 56 | 2.41.0 |
36 | 57 | ||
37 | 58 | diff view generated by jsdifflib |
1 | From: Andrew Jones <ajones@ventanamicro.com> | 1 | From: Akihiko Odaki <akihiko.odaki@daynix.com> |
---|---|---|---|
2 | 2 | ||
3 | The hypervisor should decide what it wants to enable. Zero all | 3 | riscv_trigger_init() had been called on reset events that can happen |
4 | configuration enable bits on reset. | 4 | several times for a CPU and it allocated timers for itrigger. If old |
5 | timers were present, they were simply overwritten by the new timers, | ||
6 | resulting in a memory leak. | ||
5 | 7 | ||
6 | Also, commit ed67d63798f2 ("target/riscv: Update CSR bits name for | 8 | Divide riscv_trigger_init() into two functions, namely |
7 | svadu extension") missed one reference to 'hade'. Change it now. | 9 | riscv_trigger_realize() and riscv_trigger_reset() and call them in |
10 | appropriate timing. The timer allocation will happen only once for a | ||
11 | CPU in riscv_trigger_realize(). | ||
8 | 12 | ||
9 | Fixes: 0af3f115e68e ("target/riscv: Add *envcfg.HADE related check in address translation") | 13 | Fixes: 5a4ae64cac ("target/riscv: Add itrigger support when icount is enabled") |
10 | Fixes: ed67d63798f2 ("target/riscv: Update CSR bits name for svadu extension") | 14 | Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com> |
11 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 15 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
12 | Signed-off-by: Andrew Jones <ajones@ventanamicro.com> | 16 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 17 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
14 | Message-ID: <20240215223955.969568-5-dbarboza@ventanamicro.com> | 18 | Message-ID: <20230818034059.9146-1-akihiko.odaki@daynix.com> |
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 19 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
16 | --- | 20 | --- |
17 | target/riscv/cpu.c | 3 +-- | 21 | target/riscv/debug.h | 3 ++- |
18 | target/riscv/csr.c | 2 +- | 22 | target/riscv/cpu.c | 8 +++++++- |
19 | 2 files changed, 2 insertions(+), 3 deletions(-) | 23 | target/riscv/debug.c | 15 ++++++++++++--- |
24 | 3 files changed, 21 insertions(+), 5 deletions(-) | ||
20 | 25 | ||
26 | diff --git a/target/riscv/debug.h b/target/riscv/debug.h | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/target/riscv/debug.h | ||
29 | +++ b/target/riscv/debug.h | ||
30 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_debug_excp_handler(CPUState *cs); | ||
31 | bool riscv_cpu_debug_check_breakpoint(CPUState *cs); | ||
32 | bool riscv_cpu_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp); | ||
33 | |||
34 | -void riscv_trigger_init(CPURISCVState *env); | ||
35 | +void riscv_trigger_realize(CPURISCVState *env); | ||
36 | +void riscv_trigger_reset_hold(CPURISCVState *env); | ||
37 | |||
38 | bool riscv_itrigger_enabled(CPURISCVState *env); | ||
39 | void riscv_itrigger_update_priv(CPURISCVState *env); | ||
21 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 40 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
22 | index XXXXXXX..XXXXXXX 100644 | 41 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/target/riscv/cpu.c | 42 | --- a/target/riscv/cpu.c |
24 | +++ b/target/riscv/cpu.c | 43 | +++ b/target/riscv/cpu.c |
25 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset_hold(Object *obj) | 44 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset_hold(Object *obj) |
26 | 45 | ||
27 | env->menvcfg = (cpu->cfg.ext_svpbmt ? MENVCFG_PBMTE : 0) | | 46 | #ifndef CONFIG_USER_ONLY |
28 | (cpu->cfg.ext_svadu ? MENVCFG_ADUE : 0); | 47 | if (cpu->cfg.debug) { |
29 | - env->henvcfg = (cpu->cfg.ext_svpbmt ? HENVCFG_PBMTE : 0) | | 48 | - riscv_trigger_init(env); |
30 | - (cpu->cfg.ext_svadu ? HENVCFG_ADUE : 0); | 49 | + riscv_trigger_reset_hold(env); |
31 | + env->henvcfg = 0; | 50 | } |
32 | 51 | ||
33 | /* Initialized default priorities of local interrupts. */ | 52 | if (kvm_enabled()) { |
34 | for (i = 0; i < ARRAY_SIZE(env->miprio); i++) { | 53 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) |
35 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 54 | |
55 | riscv_cpu_register_gdb_regs_for_features(cs); | ||
56 | |||
57 | +#ifndef CONFIG_USER_ONLY | ||
58 | + if (cpu->cfg.debug) { | ||
59 | + riscv_trigger_realize(&cpu->env); | ||
60 | + } | ||
61 | +#endif | ||
62 | + | ||
63 | qemu_init_vcpu(cs); | ||
64 | cpu_reset(cs); | ||
65 | |||
66 | diff --git a/target/riscv/debug.c b/target/riscv/debug.c | ||
36 | index XXXXXXX..XXXXXXX 100644 | 67 | index XXXXXXX..XXXXXXX 100644 |
37 | --- a/target/riscv/csr.c | 68 | --- a/target/riscv/debug.c |
38 | +++ b/target/riscv/csr.c | 69 | +++ b/target/riscv/debug.c |
39 | @@ -XXX,XX +XXX,XX @@ static RISCVException read_henvcfg(CPURISCVState *env, int csrno, | 70 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp) |
40 | /* | 71 | return false; |
41 | * henvcfg.pbmte is read_only 0 when menvcfg.pbmte = 0 | 72 | } |
42 | * henvcfg.stce is read_only 0 when menvcfg.stce = 0 | 73 | |
43 | - * henvcfg.hade is read_only 0 when menvcfg.hade = 0 | 74 | -void riscv_trigger_init(CPURISCVState *env) |
44 | + * henvcfg.adue is read_only 0 when menvcfg.adue = 0 | 75 | +void riscv_trigger_realize(CPURISCVState *env) |
45 | */ | 76 | +{ |
46 | *val = env->henvcfg & (~(HENVCFG_PBMTE | HENVCFG_STCE | HENVCFG_ADUE) | | 77 | + int i; |
47 | env->menvcfg); | 78 | + |
79 | + for (i = 0; i < RV_MAX_TRIGGERS; i++) { | ||
80 | + env->itrigger_timer[i] = timer_new_ns(QEMU_CLOCK_VIRTUAL, | ||
81 | + riscv_itrigger_timer_cb, env); | ||
82 | + } | ||
83 | +} | ||
84 | + | ||
85 | +void riscv_trigger_reset_hold(CPURISCVState *env) | ||
86 | { | ||
87 | target_ulong tdata1 = build_tdata1(env, TRIGGER_TYPE_AD_MATCH, 0, 0); | ||
88 | int i; | ||
89 | @@ -XXX,XX +XXX,XX @@ void riscv_trigger_init(CPURISCVState *env) | ||
90 | env->tdata3[i] = 0; | ||
91 | env->cpu_breakpoint[i] = NULL; | ||
92 | env->cpu_watchpoint[i] = NULL; | ||
93 | - env->itrigger_timer[i] = timer_new_ns(QEMU_CLOCK_VIRTUAL, | ||
94 | - riscv_itrigger_timer_cb, env); | ||
95 | + timer_del(env->itrigger_timer[i]); | ||
96 | } | ||
97 | } | ||
48 | -- | 98 | -- |
49 | 2.44.0 | 99 | 2.41.0 |
100 | |||
101 | diff view generated by jsdifflib |
1 | From: Vadim Shakirov <vadim.shakirov@syntacore.com> | 1 | From: Leon Schuermann <leons@opentitan.org> |
---|---|---|---|
2 | 2 | ||
3 | mcountinhibit, mcounteren, scounteren and hcounteren must always be 32-bit | 3 | When the rule-lock bypass (RLB) bit is set in the mseccfg CSR, the PMP |
4 | by privileged spec | 4 | configuration lock bits must not apply. While this behavior is |
5 | implemented for the pmpcfgX CSRs, this bit is not respected for | ||
6 | changes to the pmpaddrX CSRs. This patch ensures that pmpaddrX CSR | ||
7 | writes work even on locked regions when the global rule-lock bypass is | ||
8 | enabled. | ||
5 | 9 | ||
6 | Signed-off-by: Vadim Shakirov <vadim.shakirov@syntacore.com> | 10 | Signed-off-by: Leon Schuermann <leons@opentitan.org> |
11 | Reviewed-by: Mayuresh Chitale <mchitale@ventanamicro.com> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
8 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | 13 | Message-ID: <20230829215046.1430463-1-leon@is.currently.online> |
9 | Message-ID: <20240202113919.18236-1-vadim.shakirov@syntacore.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 15 | --- |
12 | target/riscv/cpu.h | 8 ++++---- | 16 | target/riscv/pmp.c | 4 ++++ |
13 | target/riscv/machine.c | 16 ++++++++-------- | 17 | 1 file changed, 4 insertions(+) |
14 | 2 files changed, 12 insertions(+), 12 deletions(-) | ||
15 | 18 | ||
16 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 19 | diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c |
17 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/riscv/cpu.h | 21 | --- a/target/riscv/pmp.c |
19 | +++ b/target/riscv/cpu.h | 22 | +++ b/target/riscv/pmp.c |
20 | @@ -XXX,XX +XXX,XX @@ struct CPUArchState { | 23 | @@ -XXX,XX +XXX,XX @@ static inline uint8_t pmp_get_a_field(uint8_t cfg) |
21 | target_ulong hstatus; | 24 | */ |
22 | target_ulong hedeleg; | 25 | static inline int pmp_is_locked(CPURISCVState *env, uint32_t pmp_index) |
23 | uint64_t hideleg; | 26 | { |
24 | - target_ulong hcounteren; | 27 | + /* mseccfg.RLB is set */ |
25 | + uint32_t hcounteren; | 28 | + if (MSECCFG_RLB_ISSET(env)) { |
26 | target_ulong htval; | 29 | + return 0; |
27 | target_ulong htinst; | 30 | + } |
28 | target_ulong hgatp; | 31 | |
29 | @@ -XXX,XX +XXX,XX @@ struct CPUArchState { | 32 | if (env->pmp_state.pmp[pmp_index].cfg_reg & PMP_LOCK) { |
30 | */ | 33 | return 1; |
31 | bool two_stage_indirect_lookup; | ||
32 | |||
33 | - target_ulong scounteren; | ||
34 | - target_ulong mcounteren; | ||
35 | + uint32_t scounteren; | ||
36 | + uint32_t mcounteren; | ||
37 | |||
38 | - target_ulong mcountinhibit; | ||
39 | + uint32_t mcountinhibit; | ||
40 | |||
41 | /* PMU counter state */ | ||
42 | PMUCTRState pmu_ctrs[RV_MAX_MHPMCOUNTERS]; | ||
43 | diff --git a/target/riscv/machine.c b/target/riscv/machine.c | ||
44 | index XXXXXXX..XXXXXXX 100644 | ||
45 | --- a/target/riscv/machine.c | ||
46 | +++ b/target/riscv/machine.c | ||
47 | @@ -XXX,XX +XXX,XX @@ static bool hyper_needed(void *opaque) | ||
48 | |||
49 | static const VMStateDescription vmstate_hyper = { | ||
50 | .name = "cpu/hyper", | ||
51 | - .version_id = 3, | ||
52 | - .minimum_version_id = 3, | ||
53 | + .version_id = 4, | ||
54 | + .minimum_version_id = 4, | ||
55 | .needed = hyper_needed, | ||
56 | .fields = (const VMStateField[]) { | ||
57 | VMSTATE_UINTTL(env.hstatus, RISCVCPU), | ||
58 | VMSTATE_UINTTL(env.hedeleg, RISCVCPU), | ||
59 | VMSTATE_UINT64(env.hideleg, RISCVCPU), | ||
60 | - VMSTATE_UINTTL(env.hcounteren, RISCVCPU), | ||
61 | + VMSTATE_UINT32(env.hcounteren, RISCVCPU), | ||
62 | VMSTATE_UINTTL(env.htval, RISCVCPU), | ||
63 | VMSTATE_UINTTL(env.htinst, RISCVCPU), | ||
64 | VMSTATE_UINTTL(env.hgatp, RISCVCPU), | ||
65 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_jvt = { | ||
66 | |||
67 | const VMStateDescription vmstate_riscv_cpu = { | ||
68 | .name = "cpu", | ||
69 | - .version_id = 9, | ||
70 | - .minimum_version_id = 9, | ||
71 | + .version_id = 10, | ||
72 | + .minimum_version_id = 10, | ||
73 | .post_load = riscv_cpu_post_load, | ||
74 | .fields = (const VMStateField[]) { | ||
75 | VMSTATE_UINTTL_ARRAY(env.gpr, RISCVCPU, 32), | ||
76 | @@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_riscv_cpu = { | ||
77 | VMSTATE_UINTTL(env.mtval, RISCVCPU), | ||
78 | VMSTATE_UINTTL(env.miselect, RISCVCPU), | ||
79 | VMSTATE_UINTTL(env.siselect, RISCVCPU), | ||
80 | - VMSTATE_UINTTL(env.scounteren, RISCVCPU), | ||
81 | - VMSTATE_UINTTL(env.mcounteren, RISCVCPU), | ||
82 | - VMSTATE_UINTTL(env.mcountinhibit, RISCVCPU), | ||
83 | + VMSTATE_UINT32(env.scounteren, RISCVCPU), | ||
84 | + VMSTATE_UINT32(env.mcounteren, RISCVCPU), | ||
85 | + VMSTATE_UINT32(env.mcountinhibit, RISCVCPU), | ||
86 | VMSTATE_STRUCT_ARRAY(env.pmu_ctrs, RISCVCPU, RV_MAX_MHPMCOUNTERS, 0, | ||
87 | vmstate_pmu_ctr_state, PMUCTRState), | ||
88 | VMSTATE_UINTTL_ARRAY(env.mhpmevent_val, RISCVCPU, RV_MAX_MHPMEVENTS), | ||
89 | -- | 34 | -- |
90 | 2.44.0 | 35 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Irina Ryapolova <irina.ryapolova@syntacore.com> | 1 | From: Tommy Wu <tommy.wu@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | The SATP register is an SXLEN-bit read/write WARL register. It means that CSR fields are only defined | 3 | According to the new spec, when vsiselect has a reserved value, attempts |
4 | for a subset of bit encodings, but allow any value to be written while guaranteeing to return a legal | 4 | from M-mode or HS-mode to access vsireg, or from VS-mode to access |
5 | value whenever read (See riscv-privileged-20211203, SATP CSR). | 5 | sireg, should preferably raise an illegal instruction exception. |
6 | 6 | ||
7 | For example on rv64 we are trying to write to SATP CSR val = 0x1000000000000000 (SATP_MODE = 1 - Reserved for standard use) | 7 | Signed-off-by: Tommy Wu <tommy.wu@sifive.com> |
8 | and after that we are trying to read SATP_CSR. We read from the SATP CSR value = 0x1000000000000000, which is not a correct | 8 | Reviewed-by: Frank Chang <frank.chang@sifive.com> |
9 | operation (return illegal value). | 9 | Message-ID: <20230816061647.600672-1-tommy.wu@sifive.com> |
10 | |||
11 | Signed-off-by: Irina Ryapolova <irina.ryapolova@syntacore.com> | ||
12 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
14 | Message-ID: <20240109145923.37893-1-irina.ryapolova@syntacore.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/csr.c | 4 ++-- | 12 | target/riscv/csr.c | 7 +++++-- |
18 | 1 file changed, 2 insertions(+), 2 deletions(-) | 13 | 1 file changed, 5 insertions(+), 2 deletions(-) |
19 | 14 | ||
20 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 15 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
21 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/target/riscv/csr.c | 17 | --- a/target/riscv/csr.c |
23 | +++ b/target/riscv/csr.c | 18 | +++ b/target/riscv/csr.c |
24 | @@ -XXX,XX +XXX,XX @@ static RISCVException read_mstatus(CPURISCVState *env, int csrno, | 19 | @@ -XXX,XX +XXX,XX @@ static int rmw_iprio(target_ulong xlen, |
25 | 20 | static int rmw_xireg(CPURISCVState *env, int csrno, target_ulong *val, | |
26 | static bool validate_vm(CPURISCVState *env, target_ulong vm) | 21 | target_ulong new_val, target_ulong wr_mask) |
27 | { | 22 | { |
28 | - return (vm & 0xf) <= | 23 | - bool virt; |
29 | - satp_mode_max_from_map(riscv_cpu_cfg(env)->satp_mode.map); | 24 | + bool virt, isel_reserved; |
30 | + uint64_t mode_supported = riscv_cpu_cfg(env)->satp_mode.map; | 25 | uint8_t *iprio; |
31 | + return get_field(mode_supported, (1 << vm)); | 26 | int ret = -EINVAL; |
32 | } | 27 | target_ulong priv, isel, vgein; |
33 | 28 | @@ -XXX,XX +XXX,XX @@ static int rmw_xireg(CPURISCVState *env, int csrno, target_ulong *val, | |
34 | static target_ulong legalize_mpp(CPURISCVState *env, target_ulong old_mpp, | 29 | |
30 | /* Decode register details from CSR number */ | ||
31 | virt = false; | ||
32 | + isel_reserved = false; | ||
33 | switch (csrno) { | ||
34 | case CSR_MIREG: | ||
35 | iprio = env->miprio; | ||
36 | @@ -XXX,XX +XXX,XX @@ static int rmw_xireg(CPURISCVState *env, int csrno, target_ulong *val, | ||
37 | riscv_cpu_mxl_bits(env)), | ||
38 | val, new_val, wr_mask); | ||
39 | } | ||
40 | + } else { | ||
41 | + isel_reserved = true; | ||
42 | } | ||
43 | |||
44 | done: | ||
45 | if (ret) { | ||
46 | - return (env->virt_enabled && virt) ? | ||
47 | + return (env->virt_enabled && virt && !isel_reserved) ? | ||
48 | RISCV_EXCP_VIRT_INSTRUCTION_FAULT : RISCV_EXCP_ILLEGAL_INST; | ||
49 | } | ||
50 | return RISCV_EXCP_NONE; | ||
35 | -- | 51 | -- |
36 | 2.44.0 | 52 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Alexandre Ghiti <alexghiti@rivosinc.com> | 1 | From: Nikita Shubin <n.shubin@yadro.com> |
---|---|---|---|
2 | 2 | ||
3 | Currently, the initrd is placed at 128MB, which overlaps with the kernel | 3 | As per ISA: |
4 | when it is large (for example syzbot kernels are). From the kernel side, | ||
5 | there is no reason we could not push the initrd further away in memory | ||
6 | to accommodate large kernels, so move the initrd at 512MB when possible. | ||
7 | 4 | ||
8 | The ideal solution would have been to place the initrd based on the | 5 | "For CSRRWI, if rd=x0, then the instruction shall not read the CSR and |
9 | kernel size but we actually can't since the bss size is not known when | 6 | shall not cause any of the side effects that might occur on a CSR read." |
10 | the image is loaded by load_image_targphys_as() and the initrd would | ||
11 | then overlap with this section. | ||
12 | 7 | ||
13 | Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com> | 8 | trans_csrrwi() and trans_csrrw() call do_csrw() if rd=x0, do_csrw() calls |
9 | riscv_csrrw_do64(), via helper_csrw() passing NULL as *ret_value. | ||
10 | |||
11 | Signed-off-by: Nikita Shubin <n.shubin@yadro.com> | ||
14 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
15 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 13 | Message-ID: <20230808090914.17634-1-nikita.shubin@maquefel.me> |
16 | Message-ID: <20240206154042.514698-1-alexghiti@rivosinc.com> | ||
17 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
18 | --- | 15 | --- |
19 | hw/riscv/boot.c | 12 ++++++------ | 16 | target/riscv/csr.c | 24 +++++++++++++++--------- |
20 | 1 file changed, 6 insertions(+), 6 deletions(-) | 17 | 1 file changed, 15 insertions(+), 9 deletions(-) |
21 | 18 | ||
22 | diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c | 19 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
23 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/hw/riscv/boot.c | 21 | --- a/target/riscv/csr.c |
25 | +++ b/hw/riscv/boot.c | 22 | +++ b/target/riscv/csr.c |
26 | @@ -XXX,XX +XXX,XX @@ static void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry) | 23 | @@ -XXX,XX +XXX,XX @@ static RISCVException riscv_csrrw_do64(CPURISCVState *env, int csrno, |
27 | * kernel is uncompressed it will not clobber the initrd. However | 24 | target_ulong write_mask) |
28 | * on boards without much RAM we must ensure that we still leave | 25 | { |
29 | * enough room for a decent sized initrd, and on boards with large | 26 | RISCVException ret; |
30 | - * amounts of RAM we must avoid the initrd being so far up in RAM | 27 | - target_ulong old_value; |
31 | - * that it is outside lowmem and inaccessible to the kernel. | 28 | + target_ulong old_value = 0; |
32 | - * So for boards with less than 256MB of RAM we put the initrd | 29 | |
33 | - * halfway into RAM, and for boards with 256MB of RAM or more we put | 30 | /* execute combined read/write operation if it exists */ |
34 | - * the initrd at 128MB. | 31 | if (csr_ops[csrno].op) { |
35 | + * amounts of RAM, we put the initrd at 512MB to allow large kernels | 32 | return csr_ops[csrno].op(env, csrno, ret_value, new_value, write_mask); |
36 | + * to boot. | 33 | } |
37 | + * So for boards with less than 1GB of RAM we put the initrd | 34 | |
38 | + * halfway into RAM, and for boards with 1GB of RAM or more we put | 35 | - /* if no accessor exists then return failure */ |
39 | + * the initrd at 512MB. | 36 | - if (!csr_ops[csrno].read) { |
40 | */ | 37 | - return RISCV_EXCP_ILLEGAL_INST; |
41 | - start = kernel_entry + MIN(mem_size / 2, 128 * MiB); | 38 | - } |
42 | + start = kernel_entry + MIN(mem_size / 2, 512 * MiB); | 39 | - /* read old value */ |
43 | 40 | - ret = csr_ops[csrno].read(env, csrno, &old_value); | |
44 | size = load_ramdisk(filename, start, mem_size - start); | 41 | - if (ret != RISCV_EXCP_NONE) { |
45 | if (size == -1) { | 42 | - return ret; |
43 | + /* | ||
44 | + * ret_value == NULL means that rd=x0 and we're coming from helper_csrw() | ||
45 | + * and we can't throw side effects caused by CSR reads. | ||
46 | + */ | ||
47 | + if (ret_value) { | ||
48 | + /* if no accessor exists then return failure */ | ||
49 | + if (!csr_ops[csrno].read) { | ||
50 | + return RISCV_EXCP_ILLEGAL_INST; | ||
51 | + } | ||
52 | + /* read old value */ | ||
53 | + ret = csr_ops[csrno].read(env, csrno, &old_value); | ||
54 | + if (ret != RISCV_EXCP_NONE) { | ||
55 | + return ret; | ||
56 | + } | ||
57 | } | ||
58 | |||
59 | /* write value if writable and write mask set, otherwise drop writes */ | ||
46 | -- | 60 | -- |
47 | 2.44.0 | 61 | 2.41.0 | diff view generated by jsdifflib |