Page MenuHomeFreeBSD

RISC-V: add support for SBI spec v0.2
ClosedPublic

Authored by mhorne on Nov 12 2019, 4:50 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Dec 9, 8:51 PM
Unknown Object (File)
Nov 17 2024, 5:33 AM
Unknown Object (File)
Nov 15 2024, 7:18 PM
Unknown Object (File)
Nov 12 2024, 10:12 PM
Unknown Object (File)
Nov 8 2024, 9:58 PM
Unknown Object (File)
Sep 19 2024, 9:35 AM
Unknown Object (File)
Sep 15 2024, 3:34 PM
Unknown Object (File)
Sep 8 2024, 1:59 PM
Subscribers

Details

Summary

The Supervisor Binary Interface (SBI) specification v0.2 is a backwards
incompatible update to the SBI call interface for kernels running in
supervisor mode. The goal of this update was to make it easier for new
and optional functionality to be added to the SBI.

SBI functions are now called by passing an "extension ID" and a
"function ID" which are passed in a7 and a6 respectively. SBI calls
will also return an error and value in the following struct:

struct sbi_ret {

long error;
long value;

}

This version introduces several new functions under the "base"
extension. It is expected that all SBI implementations >= 0.2 will
support this base set of functions, as they implement some essential
services such as obtaining the SBI version, CPU implementation info, and
extension probing.

Existing SBI functions have been designated as "legacy". For the time
being they will remain implemented, but it is expected that in the
future their functionality will be duplicated or replaced by new SBI
extensions. Each legacy function has been assigned its own extension ID,
and for now we simply probe and assert for their existence.

Compatibility with legacy SBI implementations (such as BBL) is
maintained by checking the output of sbi_get_spec_version(). This
function is guaranteed to succeed by the new spec, but will return an
error in legacy implementations. We use this as an indicator of whether
or not we can rely on the new SBI base extensions.

For further info on the Supervisor Binary Interface, see:
https://github.com/riscv/riscv-sbi-doc/blob/master/riscv-sbi.adoc

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kp requested changes to this revision.Nov 12 2019, 12:12 PM
kp added a subscriber: kp.
kp added inline comments.
sys/riscv/include/sbi.h
116 ↗(On Diff #64222)

I think this breaks legacy BBL.

BBL returns its value in a0, not a1, so when we try to read something through SBI (e.g. SBI_CONSOLE_GETCHAR) we'll return data from the wrong register.

I initially thought you'd misunderstood the standard, because I'd have expected the extension to use a previously unused (at least for returning data) register, but that's not the case.

We can probably work around this by making the legacy functions look at the error field rather than the value field. Happily that's only sbi_console_getchar().

This revision now requires changes to proceed.Nov 12 2019, 12:12 PM
This revision is now accepted and ready to land.Nov 13 2019, 10:04 AM
This revision was automatically updated to reflect the committed changes.