[PATCH] lib: sbi: Fix typo CSR_CYCLE -> CSR_TIME

dramforever dramforever at live.com
Wed Feb 26 05:35:33 PST 2025


On 2/26/25 20:28, Xiang W wrote:
> 在 2025-02-26三的 17:02 +0800,dramforever写道:
>> When emulating CSR_TIME, the hpm_allowed check should be for CSR_TIME,
>> not for CSR_CYCLE.
>>
>> Fixes: beef2f693785 ("lib: sbi: Respect scounteren when emulating the
>> time CSR")
>> Signed-off-by: Vivian Wang <dramforever at live.com>
> The counter enable is controlled by the bits in MCOUNTEREN/HCOUNTEREN/SCOUNTEREN.
>
> MCOUNTEREN/HCOUNTEREN/SCOUNTEREN as shown below
> +-------+-------+-------+---------------+------+----+----+----+
> | HPM31 | HPM30 | HPM29 | ...           | HPM3 | IR | TM | CY |
> +-------+-------+-------+---------------+------+----+----+----+
>
> The counters address is as follows:
> 0xc00	cycle
> 0xc01	time
> 0xc02	instret
> 0xc03	hpmcounter3
> ...
> 0xc1d	hpmcounter29
> 0xc1e	hpmcounter30
> 0xc1f	hpmcounter31
>
> The value obtained by subtracting the address of the cycle from the address of 
> the counter is the offset in xCOUNTER that corresponds to this counter enable 
> bit.

Oops, sorry, thanks for the catch

dram

> NACK
>
> Regards,
> Xiang W
>
>
>> ---
>>  lib/sbi/sbi_emulate_csr.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/lib/sbi/sbi_emulate_csr.c b/lib/sbi/sbi_emulate_csr.c
>> index c2253c8..73b371e 100644
>> --- a/lib/sbi/sbi_emulate_csr.c
>> +++ b/lib/sbi/sbi_emulate_csr.c
>> @@ -62,7 +62,7 @@ int sbi_emulate_csr_read(int csr_num, struct
>> sbi_trap_regs *regs,
>>  		*csr_val = csr_read(CSR_MCYCLE);
>>  		break;
>>  	case CSR_TIME:
>> -		if (!hpm_allowed(csr_num - CSR_CYCLE, prev_mode, virt))
>> +		if (!hpm_allowed(csr_num - CSR_TIME, prev_mode, virt))
>>  			return SBI_ENOTSUPP;
>>  		/*
>>  		 * We emulate TIME CSR for both Host (HS/U-mode) and
>> -- 
>> 2.47.2
>>
>>



More information about the opensbi mailing list