Page MenuHomeFreeBSD

riscv: add custom T-HEAD dcache ops
ClosedPublic

Authored by mhorne on Nov 5 2024, 8:41 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Dec 23, 6:57 AM
Unknown Object (File)
Wed, Dec 11, 8:51 AM
Unknown Object (File)
Tue, Dec 10, 3:30 AM
Unknown Object (File)
Sun, Dec 8, 11:45 PM
Unknown Object (File)
Wed, Nov 27, 2:43 AM
Unknown Object (File)
Nov 25 2024, 9:09 PM
Unknown Object (File)
Nov 24 2024, 5:35 AM
Unknown Object (File)
Nov 21 2024, 10:11 PM
Subscribers

Details

Summary

This is the first major errata we need to support in order to run on
current T-HEAD/XuanTie CPUs, e.g. the C906 or C910, found in several
existing RISC-V SBCs. With these custom dcache routines installed,
busdma can reliably communicate with devices which are not coherent
w.r.t. the CPU's data caches.

This patch introduces the first errata handling functions to identcpu.c,
and thus is forced to make some decisions about how this code is
structured. It will be amended with the changes that follow in the
series, yet I feel the final result is (unavoidably) somewhat clumsy. I
expect the CPU identification code will continue to evolve as more CPUs
and their errata are eventually supported.

T-HEAD specific code is added to a new file, and the custom instructions
can fortunately be enabled on a per-function basis.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

mhorne requested review of this revision.Nov 5 2024, 8:41 PM
sys/riscv/thead/thead.c
41

This won't build with older Clang, this was added quite recently

Don't rely on new compiler features for the THEAD custom instructions. Instead, specify the raw bytes.

sys/riscv/riscv/identcpu.c
495

I would be tempted to use "handle" instead of "update" for the functions in this file, e.g. handle_cpu_errata_thead seems more accurate to me. These also might be more like quirks than errata per se. An errata is when the processor fails to implement its architecture. In this case T-HEAD is just implementing a variant architecture, so maybe handle_cpu_quirks() -> handle_thead_quirks() -> thead_setup_cache(). I might be tempted to just inline the body of the first new function into the second btw unless it is going to grow more things in the near future.

sys/riscv/thead/thead.c
61

If you use register __asm("t0") for va (or a temporary), like is done for SBI calls, you can let the register allocator do the move for you or, more likely, use t0 in the first place (and also not require marking it as clobbered).

Better use of t0 register.

Use jhb's suggested naming.

This revision was not accepted when it landed; it landed in state Needs Review.Nov 25 2024, 9:09 PM
This revision was automatically updated to reflect the committed changes.
sys/riscv/thead/thead.c
92

on stack?

sys/riscv/thead/thead.c
92

oh you're copying them later, sorry :)