Re: [PATCH v5 04/13] riscv: sbi: add SBI FWFT extension calls

Clément Léger
2025-04-24T13:49:24Z

On 24/04/2025 13:06, Andrew Jones wrote:
> On Thu, Apr 17, 2025 at 02:19:51PM +0200, Clément Léger wrote:
>> Add FWFT extension calls. This will be ratified in SBI V3.0 hence, it is
>> provided as a separate commit that can be left out if needed.
>>
>> Signed-off-by: Clément Léger <cleger@rivosinc.com>
>> ---
>> arch/riscv/kernel/sbi.c | 20 +++++++++++++++++++-
>> 1 file changed, 19 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
>> index 379981c2bb21..7b062189b184 100644
>> --- a/arch/riscv/kernel/sbi.c
>> +++ b/arch/riscv/kernel/sbi.c
>> @@ -299,6 +299,8 @@ static int __sbi_rfence_v02(int fid, const struct cpumask *cpu_mask,
>> return 0;
>> }
>>
>> +static bool sbi_fwft_supported;
>
> At some point we may want an SBI extension bitmap, but this is only the
> second SBI extension supported boolean that I'm aware of, so I guess we're
> still OK for now.

That seems reasonable to have a bitmap rather than duplicating
*ext*_supported. If that's something that bothers you, I can take care
of it and use a bitmap. SSE will also have a sse_supported boolean but
in it's own driver file though.

>
>> +
>> /**
>> * sbi_fwft_set() - Set a feature on the local hart
>> * @feature: The feature ID to be set
>> @@ -309,7 +311,15 @@ static int __sbi_rfence_v02(int fid, const struct cpumask *cpu_mask,
>> */
>> int sbi_fwft_set(u32 feature, unsigned long value, unsigned long flags)
>> {
>> - return -EOPNOTSUPP;
>> + struct sbiret ret;
>> +
>> + if (!sbi_fwft_supported)
>> + return -EOPNOTSUPP;
>> +
>> + ret = sbi_ecall(SBI_EXT_FWFT, SBI_EXT_FWFT_SET,
>> + feature, value, flags, 0, 0, 0);
>> +
>> + return sbi_err_map_linux_errno(ret.error);
>> }
>>
>> struct fwft_set_req {
>> @@ -348,6 +358,9 @@ int sbi_fwft_local_set_cpumask(const cpumask_t *mask, u32 feature,
>> .error = ATOMIC_INIT(0),
>> };
>>
>> + if (!sbi_fwft_supported)
>> + return -EOPNOTSUPP;
>> +
>> if (feature & SBI_FWFT_GLOBAL_FEATURE_BIT)
>> return -EINVAL;
>>
>> @@ -679,6 +692,11 @@ void __init sbi_init(void)
>> pr_info("SBI DBCN extension detected\n");
>> sbi_debug_console_available = true;
>> }
>> + if ((sbi_spec_version >= sbi_mk_version(3, 0)) &&
>> + (sbi_probe_extension(SBI_EXT_FWFT) > 0)) {
>
> Unnecessary (), but I see it's consistent with the expressions above.

I can fix the other ones as well in another commit.

>
>> + pr_info("SBI FWFT extension detected\n");
>> + sbi_fwft_supported = true;
>> + }
>> } else {
>> __sbi_set_timer = __sbi_set_timer_v01;
>> __sbi_send_ipi = __sbi_send_ipi_v01;
>> --
>> 2.49.0
>>

Thanks,

Clément

>
> Besides the () nit
>
> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>