]> git.ipfire.org Git - thirdparty/ipxe.git/commit
[riscv] Support T-Head CPUs using non-standard Memory Attribute Extension
authorMichael Brown <mcb30@ipxe.org>
Mon, 2 Jun 2025 12:57:03 +0000 (13:57 +0100)
committerMichael Brown <mcb30@ipxe.org>
Mon, 2 Jun 2025 13:19:15 +0000 (14:19 +0100)
commit5b3ebf8b24ae40a6f9f9f78491702d508f843e56
treeea074a9d29bb9fa3e4933b74d4ed387b46de3304
parent817145fe015f494721f3c857c362f9d1d130c18c
[riscv] Support T-Head CPUs using non-standard Memory Attribute Extension

Xuantie/T-Head processors such as the C910 (as used in the Sipeed
Lichee Pi 4A) use the high bits of the PTE in a very non-standard way
that is incompatible with the RISC-V specification.

As per the "Memory Attribute Extension (XTheadMae)", bits 62 and 61
represent cacheability and "bufferability" (write-back cacheability)
respectively.  If we do not enable these bits, then the processor gets
incredibly confused at the point that paging is enabled.  The symptom
is that cache lines will occasionally fail to fill, and so reads from
any address may return unrelated data from a previously read cache
line for a different address.

Work around these hardware flaws by detecting T-Head CPUs (via the
"get machine vendor ID" SBI call), then reading the vendor-specific
SXSTATUS register to determine whether or not the vendor-specific
Memory Attribute Extension has been enabled by the M-mode firmware.
If it has, then set bits 61 and 62 in each page table entry that is
used to access normal memory.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/riscv/prefix/libprefix.S