@samitouri / QOSamiQemu / commits / b73a0fcf4d

target/riscv: Fix pmp.h/cpu.h circular inclusion

pmp.h is only needed and included for system mode, however relevant macros (MAX_RISCV_PMPS, OLD_MAX_RISCV_PMPS, MIN_RISCV_PMP_GRANULARITY) are required unconditionally by cpu.c, and so are defined in cpu.h. pmp.h then defines pmp_table_t depending on these macros and so requires cpu.h, and cpu.h in turn uses pmp_table_t resulting in circular inclusion. Move PMP macros to pmp.h and only expose PMP properties in system mode. Signed-off-by: Anton Johansson <anjo@rev.ng> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Message-ID: <20260520125406.28693-28-anjo@rev.ng> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>

Anton Johansson committed May 20, 2026 at 14:54 UTC b73a0fcf4dd0f7a30e6c8c2b6f1a7e3f8077ad06
3 files changed +9 -5
target/riscv/cpu.c
+6
@@ -1147,7 +1147,9 @@ static void riscv_cpu_init(Object *obj)
1147 cpu->cfg.cbop_blocksize = 64;
1148 cpu->cfg.cboz_blocksize = 64;
1149 cpu->cfg.pmp_regions = 16;
1150 +#ifndef CONFIG_USER_ONLY
1151 cpu->cfg.pmp_granularity = MIN_RISCV_PMP_GRANULARITY;
1152 +#endif
1153 cpu->env.vext_ver = VEXT_VERSION_1_00_0;
1154 cpu->cfg.max_satp_mode = -1;
1155
@@ -1385,6 +1387,7 @@ static const PropertyInfo prop_mmu = {
1387 .set = prop_mmu_set,
1388 };
1389
1390 +#ifndef CONFIG_USER_ONLY
1391 static void prop_pmp_set(Object *obj, Visitor *v, const char *name,
1392 void *opaque, Error **errp)
1393 {
@@ -1493,6 +1496,7 @@ static const PropertyInfo prop_pmp_granularity = {
1496 .get = prop_pmp_granularity_get,
1497 .set = prop_pmp_granularity_set,
1498 };
1499 +#endif /* !CONFIG_USER_ONLY */
1500
1501 static int priv_spec_from_str(const char *priv_spec_str)
1502 {
@@ -2522,9 +2526,11 @@ static const Property riscv_cpu_properties[] = {
2526 {.name = "pmu-num", .info = &prop_pmu_num}, /* Deprecated */
2527
2528 {.name = "mmu", .info = &prop_mmu},
2529 +#ifndef CONFIG_USER_ONLY
2530 {.name = "pmp", .info = &prop_pmp},
2531 {.name = "num-pmp-regions", .info = &prop_num_pmp_regions},
2532 {.name = "pmp-granularity", .info = &prop_pmp_granularity},
2533 +#endif
2534
2535 {.name = "priv_spec", .info = &prop_priv_spec},
2536 {.name = "vext_spec", .info = &prop_vext_spec},
target/riscv/cpu.h
-4
@@ -181,10 +181,6 @@ extern RISCVCPUImpliedExtsRule *riscv_multi_ext_implied_rules[];
181
182 #define MMU_USER_IDX 3
183
184 -#define MAX_RISCV_PMPS (64)
185 -#define OLD_MAX_RISCV_PMPS (16)
186 -#define MIN_RISCV_PMP_GRANULARITY 4
187 -
184 #if !defined(CONFIG_USER_ONLY)
185 #include "pmp.h"
186 #endif
target/riscv/pmp.h
+3 -1
@@ -22,7 +22,9 @@
22 #ifndef RISCV_PMP_H
23 #define RISCV_PMP_H
24
25 -#include "cpu.h"
25 +#define MAX_RISCV_PMPS (64)
26 +#define OLD_MAX_RISCV_PMPS (16)
27 +#define MIN_RISCV_PMP_GRANULARITY 4
28
29 typedef enum {
30 PMP_READ = 1 << 0,