Skip to contentSkip to conversation

lib: sbi: Fix typo CSR_CYCLE -> CSR_TIME

PATCH New dramforever 2 participants 3 messages Feb 26, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: sbi: Fix typo CSR_CYCLE -> CSR_TIME

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")

---
 lib/sbi/sbi_emulate_csr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/sbi/sbi_emulate_csr.c +0 -0
index c2253c8..73b371e 100644
@@ -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

Signature · 1 line
2.47.2
#1 lore raw

PATCH 1/1 lib: sbi: Fix typo CSR_CYCLE -> CSR_TIME

? 2025-02-26?? 17:02 +0800?dramforever???

Quoted 6 lines

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")

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.

NACK

Regards,
Xiang W

Quoted 22 lines

---
?lib/sbi/sbi_emulate_csr.c | 2 +-
?1 file changed, 1 insertion(+), 1 deletion(-)

lib/sbi/sbi_emulate_csr.c +0 -0
index c2253c8..73b371e 100644
@@ -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:

lib/sbi/sbi_emulate_csr.c +1 -1
-		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

Signature · 1 line
2.47.2
#2 lore raw

PATCH 1/1 lib: sbi: Fix typo CSR_CYCLE -> CSR_TIME

Quoted 24 lines · Xiang W

? 2025-02-26?? 17:02 +0800?dramforever???

Quoted 6 lines

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")

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

Quoted 3 lines

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

Quoted 28 lines

NACK

Regards,
Xiang W

Quoted 22 lines

---
?lib/sbi/sbi_emulate_csr.c | 2 +-
?1 file changed, 1 insertion(+), 1 deletion(-)

lib/sbi/sbi_emulate_csr.c +0 -0
index c2253c8..73b371e 100644
@@ -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:

lib/sbi/sbi_emulate_csr.c +1 -1
-		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

Signature · 1 line
2.47.2