[PATCH v2 5/9] lib: sbi_hart: add WID protection mechanism
Radim Krcmar
rkrcmar at qti.qualcomm.com
Fri Oct 16 11:33:17 PDT 2026
2026-10-16T17:24:07+00:00, Radim Krcmar <rkrcmar at qti.qualcomm.com>:
> 2026-08-17T17:04:59+08:00, Yu-Chien Peter Lin <peter.lin at sifive.com>:
>> +static struct sbi_hart_protection wid_protection = {
>> + .name = "wid",
>> + .rating = 100,
>> + .type = SBI_HART_PROTECTION_TYPE_ID,
>> + .configure = sbi_hart_worlds_configure,
>> + .unconfigure = NULL
>> +};
>> +
>> +int sbi_hart_worlds_init(struct sbi_scratch *scratch)
>> +{
>> + if (!sbi_hart_has_extension(scratch, SBI_HART_EXT_SMLWID))
>> + return 0;
>> +
>> + return sbi_hart_protection_register(&wid_protection);
>
> All that I said above applies to domain intialization.
> The actual code during context switch should be much simpler:
>
> {
> csr_write(CSR_MLWID, dom->wid);
> if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SMWIDDELEG))
> csr_write(CSR_MWIDDELEG, dom->widdeleg);
> }
>
> Or only
>
> {
> csr_write(CSR_MLWID, dom->wid);
> }
>
> since we have to touch mwiddeleg when switching slwid anyway and the
> unconfigure/configure is not good.
> Alternatively, we can add a `switch` function to sbi_hart_protection and
> move the slwid switching here.
Taking a step back, what is actually the benefit of fitting WID into
sbi_hart_protection instead of simple domain state?
Thanks.
More information about the opensbi
mailing list