Skip to content

Commit dc8bffc

Browse files
Alexandre Ghitialistair23
authored andcommitted
target: riscv: Add Svrsw60t59b extension support
The Svrsw60t59b extension allows to free the PTE reserved bits 60 and 59 for software to use. Reviewed-by: Deepak Gupta <[email protected]> Signed-off-by: Alexandre Ghiti <[email protected]> Reviewed-by: Daniel Henrique Barboza <[email protected]> Reviewed-by: Nutty Liu<[email protected]> Message-ID: <[email protected]> Signed-off-by: Alistair Francis <[email protected]>
1 parent 5625817 commit dc8bffc

File tree

7 files changed

+18
-3
lines changed

7 files changed

+18
-3
lines changed

hw/riscv/riscv-iommu-bits.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct riscv_iommu_pq_record {
7979
#define RISCV_IOMMU_CAP_SV39 BIT_ULL(9)
8080
#define RISCV_IOMMU_CAP_SV48 BIT_ULL(10)
8181
#define RISCV_IOMMU_CAP_SV57 BIT_ULL(11)
82+
#define RISCV_IOMMU_CAP_SVRSW60T59B BIT_ULL(14)
8283
#define RISCV_IOMMU_CAP_SV32X4 BIT_ULL(16)
8384
#define RISCV_IOMMU_CAP_SV39X4 BIT_ULL(17)
8485
#define RISCV_IOMMU_CAP_SV48X4 BIT_ULL(18)

hw/riscv/riscv-iommu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2351,7 +2351,8 @@ static void riscv_iommu_realize(DeviceState *dev, Error **errp)
23512351
}
23522352
if (s->enable_g_stage) {
23532353
s->cap |= RISCV_IOMMU_CAP_SV32X4 | RISCV_IOMMU_CAP_SV39X4 |
2354-
RISCV_IOMMU_CAP_SV48X4 | RISCV_IOMMU_CAP_SV57X4;
2354+
RISCV_IOMMU_CAP_SV48X4 | RISCV_IOMMU_CAP_SV57X4 |
2355+
RISCV_IOMMU_CAP_SVRSW60T59B;
23552356
}
23562357

23572358
if (s->hpm_cntrs > 0) {

target/riscv/cpu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ const RISCVIsaExtData isa_edata_arr[] = {
230230
ISA_EXT_DATA_ENTRY(svinval, PRIV_VERSION_1_12_0, ext_svinval),
231231
ISA_EXT_DATA_ENTRY(svnapot, PRIV_VERSION_1_12_0, ext_svnapot),
232232
ISA_EXT_DATA_ENTRY(svpbmt, PRIV_VERSION_1_12_0, ext_svpbmt),
233+
ISA_EXT_DATA_ENTRY(svrsw60t59b, PRIV_VERSION_1_13_0, ext_svrsw60t59b),
233234
ISA_EXT_DATA_ENTRY(svukte, PRIV_VERSION_1_13_0, ext_svukte),
234235
ISA_EXT_DATA_ENTRY(svvptc, PRIV_VERSION_1_13_0, ext_svvptc),
235236
ISA_EXT_DATA_ENTRY(xtheadba, PRIV_VERSION_1_11_0, ext_xtheadba),
@@ -1285,6 +1286,7 @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
12851286
MULTI_EXT_CFG_BOOL("svinval", ext_svinval, false),
12861287
MULTI_EXT_CFG_BOOL("svnapot", ext_svnapot, false),
12871288
MULTI_EXT_CFG_BOOL("svpbmt", ext_svpbmt, false),
1289+
MULTI_EXT_CFG_BOOL("svrsw60t59b", ext_svrsw60t59b, false),
12881290
MULTI_EXT_CFG_BOOL("svvptc", ext_svvptc, true),
12891291

12901292
MULTI_EXT_CFG_BOOL("zicntr", ext_zicntr, true),

target/riscv/cpu_bits.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,8 @@ typedef enum {
735735
#define PTE_SOFT 0x300 /* Reserved for Software */
736736
#define PTE_PBMT 0x6000000000000000ULL /* Page-based memory types */
737737
#define PTE_N 0x8000000000000000ULL /* NAPOT translation */
738-
#define PTE_RESERVED 0x1FC0000000000000ULL /* Reserved bits */
738+
#define PTE_RESERVED(svrsw60t59b) \
739+
(svrsw60t59b ? 0x07C0000000000000ULL : 0x1FC0000000000000ULL) /* Reserved bits */
739740
#define PTE_ATTR (PTE_N | PTE_PBMT) /* All attributes bits */
740741

741742
/* Page table PPN shift amount */

target/riscv/cpu_cfg_fields.h.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ BOOL_FIELD(ext_svadu)
5757
BOOL_FIELD(ext_svinval)
5858
BOOL_FIELD(ext_svnapot)
5959
BOOL_FIELD(ext_svpbmt)
60+
BOOL_FIELD(ext_svrsw60t59b)
6061
BOOL_FIELD(ext_svvptc)
6162
BOOL_FIELD(ext_svukte)
6263
BOOL_FIELD(ext_zdinx)

target/riscv/cpu_helper.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,7 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,
13091309
bool svade = riscv_cpu_cfg(env)->ext_svade;
13101310
bool svadu = riscv_cpu_cfg(env)->ext_svadu;
13111311
bool adue = svadu ? env->menvcfg & MENVCFG_ADUE : !svade;
1312+
bool svrsw60t59b = riscv_cpu_cfg(env)->ext_svrsw60t59b;
13121313

13131314
if (first_stage && two_stage && env->virt_enabled) {
13141315
pbmte = pbmte && (env->henvcfg & HENVCFG_PBMTE);
@@ -1376,7 +1377,7 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,
13761377
if (riscv_cpu_sxl(env) == MXL_RV32) {
13771378
ppn = pte >> PTE_PPN_SHIFT;
13781379
} else {
1379-
if (pte & PTE_RESERVED) {
1380+
if (pte & PTE_RESERVED(svrsw60t59b)) {
13801381
qemu_log_mask(LOG_GUEST_ERROR, "%s: reserved bits set in PTE: "
13811382
"addr: 0x%" HWADDR_PRIx " pte: 0x" TARGET_FMT_lx "\n",
13821383
__func__, pte_addr, pte);

target/riscv/tcg/tcg-cpu.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,12 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
839839
cpu->cfg.ext_ssctr = false;
840840
}
841841

842+
if (cpu->cfg.ext_svrsw60t59b &&
843+
(!cpu->cfg.mmu || mcc->def->misa_mxl_max == MXL_RV32)) {
844+
error_setg(errp, "svrsw60t59b is not supported on RV32 and MMU-less platforms");
845+
return;
846+
}
847+
842848
/*
843849
* Disable isa extensions based on priv spec after we
844850
* validated and set everything we need.
@@ -1588,6 +1594,8 @@ static void riscv_init_max_cpu_extensions(Object *obj)
15881594

15891595
if (env->misa_mxl != MXL_RV32) {
15901596
isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zcf), false);
1597+
} else {
1598+
isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_svrsw60t59b), false);
15911599
}
15921600

15931601
/*

0 commit comments

Comments
 (0)