Page MenuHomeFreeBSD

riscv: Always use the EFI-provided FDT for boot-hartid
Needs ReviewPublic

Authored by jrtc27 on Jun 19 2021, 5:35 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 17 2024, 3:27 AM
Unknown Object (File)
Feb 28 2024, 10:18 PM
Unknown Object (File)
Jan 27 2024, 1:31 PM
Unknown Object (File)
Jan 11 2024, 5:59 PM
Unknown Object (File)
Jan 9 2024, 3:07 AM
Unknown Object (File)
Dec 25 2023, 7:33 PM
Unknown Object (File)
Jul 15 2023, 10:32 PM
Unknown Object (File)
Jun 30 2023, 4:39 PM
Subscribers

Details

Reviewers
manu
tsoome
mhorne
Group Reviewers
riscv
Summary

When booting via SBI, the hartid is available in a1. When booting via
EFI, the hartid is present in the FDT as /chosen/boot-hartid. There is
no other way to retrieve this information, as mhartid is an M-mode CSR
and no S-mode equivalent exists (nor is there an SBI call to get it).

Currently we extract boot-hartid from the FDT in the kernel. This works
if the FDT provided to the kernel is the one from EFI, but if a custom
FDT is loaded then it will no longer have /chosen/boot-hartid, causing
the kernel to be unable to get the hartid and thus panic. Instead, pass
it in metadata from loader (and put the SBI-provided value in the fake
metadata for SBI booting) as it always has access to the EFI-provided
FDT.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 39991
Build 36880: arc lint + arc unit

Event Timeline

stand/efi/loader/bootinfo.c
330

This whole block being here and using FDT functions is really ugly, but I don't see a better place to hook this. Suggestions welcome.

sys/riscv/riscv/machdep.c
840

I have one concern with this and that's that MD_FETCH returns 0 for unknown metadata, so if you use an old loader with a new kernel it'll start thinking boot_hart is 0 even when it might not be. I don't know if that's something we're really concerned about though.

I have not messed around with loading a new DTB from loader myself, but I have thought a bit about this problem of maintaining boot-hartid before. I guess you did something like load -t dtb /path/to/dtb?

u-boot solves this problem by copying fixups from the previous stage's DTB to any new DTB it loads. In practice, I believe they copy the entirety of the /chosen node, but you might want to check this. Did you consider an approach like this here? It would eliminate the need to modify the kernel.

I can see the idea of copying fixups from the EFI DTB being generally useful, not only for riscv. If there were changes made under /chosen in an earlier boot stage it would be good not to discard them.

sys/riscv/include/machdep.h
46

why insert this here? It seems to break the ABI between boot loader and kernel...

sys/riscv/include/machdep.h
46

This isn't from loader, this is from locore so there's no ABI issue