Linux on RISC-V
Drew Fustini <dfustini@baylibre.com>
Slides: tinyurl.com/riscv-kr-22
June 1-3, 2022
$ whoami
RISC-V: a Free and Open ISA
What is different about RISC-V?
(source: Instruction Sets Want to be Free, Krste Asanovic)
RISC-V base integer ISAs
(source: RISC-V Summit 2019: State of the Union, Krste Asanovic)
RISC-V base integer registers
RISC-V ABI
(source: RISC-V Assembly Programmer's Manual)
RISC-V Standard Extensions
(source: RISC-V Summit 2019: State of the Union, Krste Asanovic)
Ratified in 2021
Learn more about RISC-V
Learn more about RISC-V
RISC-V and Industry
(source: State of the Union, Krste Asanovic)
RISC-V and Industry
“Is RISC-V an Open Source processor?”
RISC-V open source cores
RISC-V open source cores
RISC-V software ecosystem
Control and Status Registers (CSRs)
(source: Introduction to the RISC-V Architecture [PDF],Drew Barbier)
RISC-V Virtual Memory
(source: Demystifying the RISC-V Linux software stack, Nick Kossifidis)
RISC-V Trap Handling
(source: RISC-V Privileged Architecture [PDF], Allen Baum)
What is a Hart?
(source: Section 1.1 in RISC-V Unprivileged spec)
RISC-V Interrupts
(source: RISC-V Fast Interrupts [PDF], Krste Asanovic)
RISC-V Boot Flow
Boot ROM
M-mode
First stage bootloader
(U-Boot SPL or vendor firmware)
U-Boot
S-mode
Linux
kernel
RISC-V Boot Flow
Boot ROM
M-mode
U-Boot
S-mode
Linux
kernel
SBI
First stage bootloader
(U-Boot SPL or vendor firmware)
SBI Extensions
Hypervisor extension
(source: OpenSBI Deep Dive, Anup Patel)
OpenSBI Domain Support
UEFI Support
UEFI Support
RISC-V emulation in QEMU
RISC-V in the Linux kernel
Recently added to Linux
New in Linux 5.18
New in Linux 5.18
Coming in Linux 5.19…
Work in progress
Work in progress
Linux distro: Fedora
Linux distro: Debian
Linux distro: Ubuntu
Linux distros
OpenEmbedded and Yocto
BuildRoot
Allwinner D1 open source community
Allwinner D1 mainline Linux support
How to handle non-coherent interconnects?
T-Head PTE format
� … but those bits were already marked reserved in RISC-V priv spec
| 63 | 62 | 61 | 60 | 59-8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
SO C B SH RSW D A G U X W R V
^ ^ ^ ^
BIT(63): SO - Strong Order
BIT(62): C - Cacheable
BIT(61): B - Bufferable
BIT(60): SH - Shareable��0000 - NC Weakly-ordered, Non-cacheable, Non-bufferable, Non-shareable
0111 - PMA Weakly-ordered, Cacheable, Bufferable, Shareable
1000 - IO Strongly-ordered, Non-cacheable, Non-bufferable, Non-shareable
Page-Based Memory Types extension
Here is the svpbmt PTE format:
| 63 | 62-61 | 60-8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
N MT RSW D A G U X W R V
^
RISC-V
Encoding &
MemType RISC-V Description
---------- ------------------------------------------------
00 - PMA Normal Cacheable, No change to implied PMA memory type
01 - NC Non-cacheable, idempotent, weakly-ordered Main Memory
10 - IO Non-cacheable, non-idempotent, strongly-ordered I/O memory
11 - Rsvd Reserved for future standard use
Svpbmt support in Linux
CMO support in Linux
* cbo.clean rs1
* | 31 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 |
* 0...01 rs1 010 00000 0001111
*
* cbo.flush rs1
* | 31 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 |
* 0...10 rs1 010 00000 0001111
*
* cbo.inval rs1
* | 31 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 |
* 0...00 rs1 010 00000 0001111
#define CBO_INVAL_A0 ".long 0x15200F"
#define CBO_CLEAN_A0 ".long 0x25200F"
#define CBO_FLUSH_A0 ".long 0x05200F"
CMO support in Linux
* dcache.ipa rs1 (invalidate, physical address)
* | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 |
* 0000001 01010 rs1 000 00000 0001011
* dache.iva rs1 (invalida, virtual address)
* 0000001 00110 rs1 000 00000 0001011
*
* dcache.cpa rs1 (clean, physical address)
* | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 |
* 0000001 01001 rs1 000 00000 0001011
* dcache.cva rs1 (clean, virtual address)
* 0000001 00100 rs1 000 00000 0001011
*
* dcache.cipa rs1 (clean then invalidate, physical address)
* | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 |
* 0000001 01011 rs1 000 00000 0001011
* dcache.civa rs1 (... virtual address)
* 0000001 00111 rs1 000 00000 0001011
#define THEAD_INVAL_A0 ".long 0x0265000b"
#define THEAD_CLEAN_A0 ".long 0x0245000b"
#define THEAD_FLUSH_A0 ".long 0x0275000b"
CMO support in Linux
Allwinner D1 IOMMU support
RISC-V Lab
No hardware? Try Renode!
How to get involved with RISC-V International?
How to get involved with RISC-V International?
RISC-V Summit 2021
Embedded Linux Conf 2021
RISC-V meetups around the world
Find more at: community.riscv.org
Linux on RISC-V
Drew Fustini <dfustini@baylibre.com>
Slides: tinyurl.com/riscv-kr-22
June 1-3, 2022
BONUS:�What about RISC-V on FPGAs?
Introduction
Open source FPGA toolchains
Hackaday Supercon badge
Why design an SoC in Python?
Open Source ECP5 FPGA boards
Open Source ECP5 FPGA boards
Want to learn FPGAs? Try Fomu!