Skip to content

Commit 7ea5a73

Browse files
Andrew Jonespalmer-dabbelt
authored andcommitted
RISC-V: Add Zicboz detection and block size parsing
Parse "riscv,cboz-block-size" from the DT by piggybacking on Zicbom's riscv_init_cbom_blocksize(). Additionally check the DT for the presence of the "zicboz" extension and, when it's present, validate the parsed cboz block size as we do Zicbom's cbom block size with riscv_isa_extension_check(). Signed-off-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Heiko Stuebner <heiko@sntech.de> Reviewed-by: Conor Dooley <conor.dooley@microchip.com> Link: https://lore.kernel.org/r/20230224162631.405473-5-ajones@ventanamicro.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent ea20f11 commit 7ea5a73

6 files changed

Lines changed: 30 additions & 10 deletions

File tree

arch/riscv/include/asm/cacheflush.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ void flush_icache_mm(struct mm_struct *mm, bool local);
5050
#endif /* CONFIG_SMP */
5151

5252
extern unsigned int riscv_cbom_block_size;
53-
void riscv_init_cbom_blocksize(void);
53+
extern unsigned int riscv_cboz_block_size;
54+
void riscv_init_cbo_blocksizes(void);
5455

5556
#ifdef CONFIG_RISCV_DMA_NONCOHERENT
5657
void riscv_noncoherent_supported(void);

arch/riscv/include/asm/hwcap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#define RISCV_ISA_EXT_ZBB 30
4343
#define RISCV_ISA_EXT_ZICBOM 31
4444
#define RISCV_ISA_EXT_ZIHINTPAUSE 32
45+
#define RISCV_ISA_EXT_ZICBOZ 33
4546

4647
#define RISCV_ISA_EXT_MAX 64
4748
#define RISCV_ISA_EXT_NAME_LEN_MAX 32

arch/riscv/kernel/cpu.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ arch_initcall(riscv_cpuinfo_init);
186186
*/
187187
static struct riscv_isa_ext_data isa_ext_arr[] = {
188188
__RISCV_ISA_EXT_DATA(zicbom, RISCV_ISA_EXT_ZICBOM),
189+
__RISCV_ISA_EXT_DATA(zicboz, RISCV_ISA_EXT_ZICBOZ),
189190
__RISCV_ISA_EXT_DATA(zihintpause, RISCV_ISA_EXT_ZIHINTPAUSE),
190191
__RISCV_ISA_EXT_DATA(zbb, RISCV_ISA_EXT_ZBB),
191192
__RISCV_ISA_EXT_DATA(sscofpmf, RISCV_ISA_EXT_SSCOFPMF),

arch/riscv/kernel/cpufeature.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ static bool riscv_isa_extension_check(int id)
7474
return false;
7575
}
7676
return true;
77+
case RISCV_ISA_EXT_ZICBOZ:
78+
if (!riscv_cboz_block_size) {
79+
pr_err("Zicboz detected in ISA string, but no cboz-block-size found\n");
80+
return false;
81+
} else if (!is_power_of_2(riscv_cboz_block_size)) {
82+
pr_err("cboz-block-size present, but is not a power-of-2\n");
83+
return false;
84+
}
85+
return true;
7786
}
7887

7988
return true;
@@ -222,6 +231,7 @@ void __init riscv_fill_hwcap(void)
222231
SET_ISA_EXT_MAP("svpbmt", RISCV_ISA_EXT_SVPBMT);
223232
SET_ISA_EXT_MAP("zbb", RISCV_ISA_EXT_ZBB);
224233
SET_ISA_EXT_MAP("zicbom", RISCV_ISA_EXT_ZICBOM);
234+
SET_ISA_EXT_MAP("zicboz", RISCV_ISA_EXT_ZICBOZ);
225235
SET_ISA_EXT_MAP("zihintpause", RISCV_ISA_EXT_ZIHINTPAUSE);
226236
}
227237
#undef SET_ISA_EXT_MAP

arch/riscv/kernel/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ void __init setup_arch(char **cmdline_p)
297297
setup_smp();
298298
#endif
299299

300-
riscv_init_cbom_blocksize();
300+
riscv_init_cbo_blocksizes();
301301
riscv_fill_hwcap();
302302
apply_boot_alternatives();
303303
if (IS_ENABLED(CONFIG_RISCV_ISA_ZICBOM) &&

arch/riscv/mm/cacheflush.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ void flush_icache_pte(pte_t pte)
100100
unsigned int riscv_cbom_block_size;
101101
EXPORT_SYMBOL_GPL(riscv_cbom_block_size);
102102

103+
unsigned int riscv_cboz_block_size;
104+
EXPORT_SYMBOL_GPL(riscv_cboz_block_size);
105+
103106
static void cbo_get_block_size(struct device_node *node,
104107
const char *name, u32 *block_size,
105108
unsigned long *first_hartid)
@@ -122,19 +125,23 @@ static void cbo_get_block_size(struct device_node *node,
122125
}
123126
}
124127

125-
void riscv_init_cbom_blocksize(void)
128+
void riscv_init_cbo_blocksizes(void)
126129
{
130+
unsigned long cbom_hartid, cboz_hartid;
131+
u32 cbom_block_size = 0, cboz_block_size = 0;
127132
struct device_node *node;
128-
unsigned long cbom_hartid;
129-
u32 probed_block_size;
130133

131-
probed_block_size = 0;
132134
for_each_of_cpu_node(node) {
133-
/* set block-size for cbom extension if available */
135+
/* set block-size for cbom and/or cboz extension if available */
134136
cbo_get_block_size(node, "riscv,cbom-block-size",
135-
&probed_block_size, &cbom_hartid);
137+
&cbom_block_size, &cbom_hartid);
138+
cbo_get_block_size(node, "riscv,cboz-block-size",
139+
&cboz_block_size, &cboz_hartid);
136140
}
137141

138-
if (probed_block_size)
139-
riscv_cbom_block_size = probed_block_size;
142+
if (cbom_block_size)
143+
riscv_cbom_block_size = cbom_block_size;
144+
145+
if (cboz_block_size)
146+
riscv_cboz_block_size = cboz_block_size;
140147
}

0 commit comments

Comments
 (0)