SlideShare a Scribd company logo
Introduction to OpenSBI
I’m Nylon Chen
Work for Andes Tech
Hello!
Outline
• SBI
• OpenSBI
• How to add a new SBI call
Ring 2
Ring 1
Ring 0
Least Privileged
Most Privileged
User Space (U-Mode)
Operating System (S-Mode)
Hypervisor(H-Mode)
Firmware(M-Mode)
RISC-V Privilege Modes
X-86 Protection ring
User Space (EL0)
Operating System
(EL1)
Hypervisor(EL2)
Firmware(EL3)
ARM64 Exception Levels
SBI
• SBI stands for RISC-V Supervisor Binary Interface
• The System call type interface layer between Firmware
runtime, M-Mode to Operating system(S-Mode)
• Avoid fragmentation of various OEM silicon providers
specific runtime firmware implementations
• Standard, generic runtime firmware interface
specification across all OSes, different cpu and silicon
platforms
• Specification in SBI v0.2 in usage
• Documentation available at
– https://github.com/riscv/riscv-sbi-doc
App 1 App 2 App 3
ABI ABI ABI
OS (S-Mode)
Open SBI (M-Mode)
SBI
OpenSBI
• Berkeley Boot Loader(BBL)
• OpenSBI is an open-source implementation of the RISC-
V Supervisor Binary Interface (SBI) specifications
• Aimed at providing RUNTIME services in M-mode
• Provides support for reference platforms
• Platforms supports Andes AE350, Ariane FPGA, Kendryte
K210, Nuclei ux600, SiFive U540, Thead c910, QEMU
• firmware implementations
– FW_PAYLOAD
– FW_JUMP
– FW_DYNAMIC
OpenSBI Calling Convention
• S mode traps into M mode using ecall instructions
• Arguments are passed via registers a0-a5
• a7 encodes the SBI extension ID
• a6 encodes the Function ID
• SBI functions must return a pair of values in a0 & a1
• Unsupported SBI returns -2 (SBI_ENOTSUPP in
Linux) [arch/riscv/include/asm/sbi.h]
…
#define SBI_SUCCESS 0
#define SBI_ERR_FAILURE -1
#define SBI_ERR_NOT_SUPPORTED -2
...
struct sbiret {
long error;
long value;
};
SBI Call
[arch/riscv/kernel/sbi.c]
struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
unsigned long arg1, unsigned long arg2,…)
{
…
register uintptr_t a6 asm ("a6") = (uintptr_t)(fid);
register uintptr_t a7 asm ("a7") = (uintptr_t)(ext);
asm volatile ("ecall"
: "+r" (a0), "+r" (a1)
: "r" (a2), "r" (a3), "r" (a4), "r" (a5), "r" (a6), "r" (a7)
: "memory");
ret.error = a0;
ret.value = a1;
return ret;
}
Linux kernel
User mode
Supervisor mode
Machine mode
mret
sret
ecall
sbi_trap_handl
e
mtvec
SBI Call (Cont’)
[lib/sbi/sbi_ecall.c]
int sbi_ecall_handler(struct sbi_trap_regs *regs)
{
…
unsigned long extension_id = regs->a7
unsigned long func_id = regs->a6;
unsigned long args[6];
args[0] = regs->a0;
…
ext = sbi_ecall_find_extension(extension_id);
if (ext && ext->handle) {
ret = ext->handle(extension_id, func_id,
args, &out_val, &trap);
….
}
regs->a0 = ret;
if (!is_0_1_spec)
regs->a1 = out_val;
}
User mode
Supervisor mode
Machine mode
mret
sret
ecall
mepc
OpenSBI
Legacy SBI Extension
BBL & SBI-v0.1
Function Name Function ID Extension ID Replacement Extension
sbi_set_timer 0 0x00 N/A
sbi_console_putchar 0 0x01 N/A
sbi_console_getchar 0 0x02 N/A
sbi_clear_ipi 0 0x03 N/A
sbi_send_ipi 0 0x04 N/A
sbi_remote_fence_i 0 0x05 N/A
sbi_remote_sfence_vma 0 0x06 N/A
sbi_remote_sfence_vma_asid 0 0x07 N/A
sbi_shutdown 0 0x08 N/A
RESERVED 0x09-0x0F
SBI Base Functionality
Function Name Function ID Extension ID
sbi_get_sbi_spec_version 0 0x10
sbi_get_sbi_impl_id 1 0x10
sbi_get_sbi_impl_version 2 0x10
sbi_probe_extension 3 0x10
sbi_get_mvendorid 4 0x10
sbi_get_marchid 5 0x10
sbi_get_mimpid 6 0x10
Vendor-Specific SBI Extension Space, Extension Ids 0x09000000 ~ 0x09FFFFFF
sbi_get_mvendorid = 0x31e
andes’s extension ID = 0x0900031E
RFENCE Extension
Function Name Function ID Extension ID
sbi_remote_fence_i 0 0x52464E43
sbi_remote_sfence_vma 1 0x52464E43
sbi_remote_sfence_vma_asid 2 0x52464E43
sbi_remote_hfence_gvma_vmid 3 0x52464E43
sbi_remote_hfence_gvma 4 0x52464E43
sbi_remote_hfence_vvma_asid 5 0x52464E43
sbi_remote_hfence_vvma 6 0x52464E43
Function Name Function ID Extension ID
sbi_set_timer 0 0x54494D45
Function Name Function ID Extension ID
sbi_send_ipi 0 0x735049
LinuxKernel>=5.7
Function Name Function ID Extension ID
sbi_hart_start 0 0x48534D
sbi_hart_stop 1 0x48534D
sbi_hart_get_status 2 0x48534D
Timer, IPI, Hart State Management
Extension
How to Add a New SBI Call
• Platform-specific: If the platform has an extension ID, you can direct-
contribute to OpenSBI mailing list
• Vendor-Specific SBI Extension Space, Extension Ids 0x09000000 through
0x09FFFFFF
• Step 1. Check Low bits from mvendorid
–e.g. andes’s mvendorid = 0x31e -> 0x0900031E
• Step 2. Add sbi_ext_id to Linux
• Step 3. Add a new enum about platform SBI call’s number to Linux
• Step 4. Add platform’s SBI function call by sbi_ecall()
–e.g. sbi_ecall(Platform’s sbi_ext_id, Platform’s sbi number, 0, 0, 0…);
• Step 5. Add hook function to your platform’s SBI handler
–e.g. .vendor_ext_provider = platform_vendor_ext_provider
Add Extension & Function ID
[arch/riscv/include/asm/sbi.h]
enum sbi_ext_id {
#ifdef CONFIG_RISCV_SBI_V01
SBI_EXT_0_1_SET_TIMER = 0x0,
SBI_EXT_0_1_CONSOLE_PUTCHAR = 0x1,
SBI_EXT_0_1_CONSOLE_GETCHAR = 0x2,
SBI_EXT_0_1_CLEAR_IPI = 0x3,
SBI_EXT_0_1_SEND_IPI = 0x4,
SBI_EXT_0_1_REMOTE_FENCE_I = 0x5,
SBI_EXT_0_1_REMOTE_SFENCE_VMA = 0x6,
SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID = 0x7,
SBI_EXT_0_1_SHUTDOWN = 0x8,
#endif
SBI_EXT_BASE = 0x10,
SBI_EXT_TIME = 0x54494D45,
SBI_EXT_IPI = 0x735049,
SBI_EXT_RFENCE = 0x52464E43,
SBI_EXT_HSM = 0x48534D,
SBI_EXT_ANDES = 0x0900031E,
};
enum sbi_ext_andes_fid {
SBI_EXT_ANDES_GET_MCACHE_CTL_STATUS = 0
….
}
[include/sbi/sbi_ecall_interface.h]
/* SBI Extension IDs */
#define SBI_EXT_0_1_SET_TIMER 0x0
#define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1
#define SBI_EXT_0_1_CONSOLE_GETCHAR 0x2
#define SBI_EXT_BASE 0x10
#define SBI_EXT_TIME 0x54494D45
#define SBI_EXT_IPI 0x735049
#define SBI_EXT_RFENCE 0x52464E43
#define SBI_EXT_HSM 0x48534D
….
/* SBI function IDs for HSM extension */
#define SBI_EXT_HSM_HART_START 0x0
#define SBI_EXT_HSM_HART_STOP 0x1
#define SBI_EXT_HSM_HART_GET_STATUS 0x2
…
#define SBI_EXT_VENDOR_START 0x09000000
#define SBI_EXT_VENDOR_END 0x09FFFFFF
Linux kernel
OpenSBI
R
Add Hook Function to SBI Handler
[platform/andes/ae350/platform.c]
…
/* Vendor-Specific SBI handler */
static int ae350_vendor_ext_provider(long extid, long funcid,
unsigned long *args, unsigned long *out_value,
struct sbi_trap_info *out_trap)
{
int ret = 0;
switch (funcid) {
case SBI_EXT_ANDES_GET_MCACHE_CTL_STATUS:
*out_value = csr_read(CSR_MCACHECTL);
break;
…
default:
sbi_printf("Unsupported vendor sbi call : %ldn", funcid);
}
…
return ret;
}
const struct sbi_platform_operations platform_ops = {
…
.vendor_ext_provider = ae350_vendor_ext_provider
…
}
OpenSBI
R
How to add a new SBI call
• non-platform-specific:
–Think about whether it fits into an existing extension or
else create a new extension
–Think about all of the details of the behaviour and
error cases
–Document that in a patch for the SBI document
–Send it to the (Mailing List] (You need to be subscribed
to be able to post) and create a PR on GitHub
–Argue for it
• How to decide Extension ID
–TIME: 0x54, 0x49, 0x4D, 0x45 - by ASCII
How to add a new SBI call
References
• Working experience on RISC-V
• SBI
• OpenSBI
• Atish Patra “RISC-V Boot Process: One step at a time”
• Atish Patra “Fixing the boot process in RISC-V”
• Anup Patel “Xvisor: Embedded Hypervisor for RISC-V”
• Anup Patel “OpenSBI Deep Dive”
• Jagan Teki “An Introduction to RISC-V Boot flow: Overview, Blob vs
Blobfree standards”

More Related Content

What's hot

03_03_Implementing_PCIe_ATS_in_ARM-based_SoCs_Final
03_03_Implementing_PCIe_ATS_in_ARM-based_SoCs_Final03_03_Implementing_PCIe_ATS_in_ARM-based_SoCs_Final
03_03_Implementing_PCIe_ATS_in_ARM-based_SoCs_FinalGopi Krishnamurthy
 
An Introduction to RISC-V bootflow
An Introduction to RISC-V bootflowAn Introduction to RISC-V bootflow
An Introduction to RISC-V bootflow
Atish Patra
 
Static partitioning virtualization on RISC-V
Static partitioning virtualization on RISC-VStatic partitioning virtualization on RISC-V
Static partitioning virtualization on RISC-V
RISC-V International
 
Spi drivers
Spi driversSpi drivers
Spi drivers
pradeep_tewani
 
BPF - in-kernel virtual machine
BPF - in-kernel virtual machineBPF - in-kernel virtual machine
BPF - in-kernel virtual machine
Alexei Starovoitov
 
Uboot startup sequence
Uboot startup sequenceUboot startup sequence
Uboot startup sequenceHoucheng Lin
 
HKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
HKG15-505: Power Management interactions with OP-TEE and Trusted FirmwareHKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
HKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
Linaro
 
Qemu Introduction
Qemu IntroductionQemu Introduction
Qemu Introduction
Chiawei Wang
 
DPDK & Layer 4 Packet Processing
DPDK & Layer 4 Packet ProcessingDPDK & Layer 4 Packet Processing
DPDK & Layer 4 Packet Processing
Michelle Holley
 
Interrupts
InterruptsInterrupts
Interrupts
Anil Kumar Pugalia
 
Kernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMI
Kernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMIKernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMI
Kernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMI
Anne Nicolas
 
OSC2011 Tokyo/Fall 濃いバナ(virtio)
OSC2011 Tokyo/Fall 濃いバナ(virtio)OSC2011 Tokyo/Fall 濃いバナ(virtio)
OSC2011 Tokyo/Fall 濃いバナ(virtio)Takeshi HASEGAWA
 
SFO15-TR9: PSCI, ACPI (and UEFI to boot)
SFO15-TR9: PSCI, ACPI (and UEFI to boot)SFO15-TR9: PSCI, ACPI (and UEFI to boot)
SFO15-TR9: PSCI, ACPI (and UEFI to boot)
Linaro
 
Linux PCI device driver
Linux PCI device driverLinux PCI device driver
Linux PCI device driver
艾鍗科技
 
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
Linaro
 
Qemu device prototyping
Qemu device prototypingQemu device prototyping
Qemu device prototyping
Yan Vugenfirer
 
I2c drivers
I2c driversI2c drivers
I2c drivers
pradeep_tewani
 
Linux Porting
Linux PortingLinux Porting
Linux Porting
Champ Yen
 
I2C Drivers
I2C DriversI2C Drivers
I2C Subsystem In Linux-2.6.24
I2C Subsystem In Linux-2.6.24I2C Subsystem In Linux-2.6.24
I2C Subsystem In Linux-2.6.24Varun Mahajan
 

What's hot (20)

03_03_Implementing_PCIe_ATS_in_ARM-based_SoCs_Final
03_03_Implementing_PCIe_ATS_in_ARM-based_SoCs_Final03_03_Implementing_PCIe_ATS_in_ARM-based_SoCs_Final
03_03_Implementing_PCIe_ATS_in_ARM-based_SoCs_Final
 
An Introduction to RISC-V bootflow
An Introduction to RISC-V bootflowAn Introduction to RISC-V bootflow
An Introduction to RISC-V bootflow
 
Static partitioning virtualization on RISC-V
Static partitioning virtualization on RISC-VStatic partitioning virtualization on RISC-V
Static partitioning virtualization on RISC-V
 
Spi drivers
Spi driversSpi drivers
Spi drivers
 
BPF - in-kernel virtual machine
BPF - in-kernel virtual machineBPF - in-kernel virtual machine
BPF - in-kernel virtual machine
 
Uboot startup sequence
Uboot startup sequenceUboot startup sequence
Uboot startup sequence
 
HKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
HKG15-505: Power Management interactions with OP-TEE and Trusted FirmwareHKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
HKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
 
Qemu Introduction
Qemu IntroductionQemu Introduction
Qemu Introduction
 
DPDK & Layer 4 Packet Processing
DPDK & Layer 4 Packet ProcessingDPDK & Layer 4 Packet Processing
DPDK & Layer 4 Packet Processing
 
Interrupts
InterruptsInterrupts
Interrupts
 
Kernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMI
Kernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMIKernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMI
Kernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMI
 
OSC2011 Tokyo/Fall 濃いバナ(virtio)
OSC2011 Tokyo/Fall 濃いバナ(virtio)OSC2011 Tokyo/Fall 濃いバナ(virtio)
OSC2011 Tokyo/Fall 濃いバナ(virtio)
 
SFO15-TR9: PSCI, ACPI (and UEFI to boot)
SFO15-TR9: PSCI, ACPI (and UEFI to boot)SFO15-TR9: PSCI, ACPI (and UEFI to boot)
SFO15-TR9: PSCI, ACPI (and UEFI to boot)
 
Linux PCI device driver
Linux PCI device driverLinux PCI device driver
Linux PCI device driver
 
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
 
Qemu device prototyping
Qemu device prototypingQemu device prototyping
Qemu device prototyping
 
I2c drivers
I2c driversI2c drivers
I2c drivers
 
Linux Porting
Linux PortingLinux Porting
Linux Porting
 
I2C Drivers
I2C DriversI2C Drivers
I2C Drivers
 
I2C Subsystem In Linux-2.6.24
I2C Subsystem In Linux-2.6.24I2C Subsystem In Linux-2.6.24
I2C Subsystem In Linux-2.6.24
 

Similar to Introduction to open_sbi

0x01 - Breaking into Linux VMs for Fun and Profit
0x01 - Breaking into Linux VMs for Fun and Profit0x01 - Breaking into Linux VMs for Fun and Profit
0x01 - Breaking into Linux VMs for Fun and Profit
Russell Sanford
 
CCA security answers chapter 2 test
CCA security answers chapter 2 testCCA security answers chapter 2 test
CCA security answers chapter 2 test
Soporte Yottatec
 
C++InputOutput.PPT
C++InputOutput.PPTC++InputOutput.PPT
C++InputOutput.PPT
KamranAli649587
 
0x01 - Breaking into Linux VMs for Fun and Profit.pdf
0x01 - Breaking into Linux VMs for Fun and Profit.pdf0x01 - Breaking into Linux VMs for Fun and Profit.pdf
0x01 - Breaking into Linux VMs for Fun and Profit.pdf
scribdsituation719
 
How to Connect SystemVerilog with Octave
How to Connect SystemVerilog with OctaveHow to Connect SystemVerilog with Octave
How to Connect SystemVerilog with Octave
Amiq Consulting
 
Labs_BT_20221017.pptx
Labs_BT_20221017.pptxLabs_BT_20221017.pptx
Labs_BT_20221017.pptx
ssuserb4d806
 
Is your code ready for PHP 7 ?
Is your code ready for PHP 7 ?Is your code ready for PHP 7 ?
Is your code ready for PHP 7 ?
Wim Godden
 
The Ring programming language version 1.5.2 book - Part 77 of 181
The Ring programming language version 1.5.2 book - Part 77 of 181The Ring programming language version 1.5.2 book - Part 77 of 181
The Ring programming language version 1.5.2 book - Part 77 of 181
Mahmoud Samir Fayed
 
Georgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software securityGeorgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software securityDefconRussia
 
Embedded system - introduction to arm7
Embedded system -  introduction to arm7Embedded system -  introduction to arm7
Embedded system - introduction to arm7
Vibrant Technologies & Computers
 
Burp Suite Extension Development
Burp Suite Extension DevelopmentBurp Suite Extension Development
Burp Suite Extension Development
NSConclave
 
Brillo/Weave Part 2: Deep Dive
Brillo/Weave Part 2: Deep DiveBrillo/Weave Part 2: Deep Dive
Brillo/Weave Part 2: Deep Dive
Jalal Rohani
 
C++InputOutput.pptx
C++InputOutput.pptxC++InputOutput.pptx
C++InputOutput.pptx
ansariparveen06
 
Cisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-oneCisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-one
DefconRussia
 
CCNA ppt Day 4
CCNA ppt Day 4CCNA ppt Day 4
CCNA ppt Day 4
VISHNU N
 
r2con 2017 r2cLEMENCy
r2con 2017 r2cLEMENCyr2con 2017 r2cLEMENCy
r2con 2017 r2cLEMENCy
Ray Song
 
The Ring programming language version 1.4 book - Part 22 of 30
The Ring programming language version 1.4 book - Part 22 of 30The Ring programming language version 1.4 book - Part 22 of 30
The Ring programming language version 1.4 book - Part 22 of 30
Mahmoud Samir Fayed
 
RenderMan*: The Role of Open Shading Language (OSL) with Intel® Advanced Vect...
RenderMan*: The Role of Open Shading Language (OSL) with Intel® Advanced Vect...RenderMan*: The Role of Open Shading Language (OSL) with Intel® Advanced Vect...
RenderMan*: The Role of Open Shading Language (OSL) with Intel® Advanced Vect...
Intel® Software
 
Attack your Trusted Core
Attack your Trusted CoreAttack your Trusted Core
Attack your Trusted Core
Di Shen
 

Similar to Introduction to open_sbi (20)

Rsockets ofa12
Rsockets ofa12Rsockets ofa12
Rsockets ofa12
 
0x01 - Breaking into Linux VMs for Fun and Profit
0x01 - Breaking into Linux VMs for Fun and Profit0x01 - Breaking into Linux VMs for Fun and Profit
0x01 - Breaking into Linux VMs for Fun and Profit
 
CCA security answers chapter 2 test
CCA security answers chapter 2 testCCA security answers chapter 2 test
CCA security answers chapter 2 test
 
C++InputOutput.PPT
C++InputOutput.PPTC++InputOutput.PPT
C++InputOutput.PPT
 
0x01 - Breaking into Linux VMs for Fun and Profit.pdf
0x01 - Breaking into Linux VMs for Fun and Profit.pdf0x01 - Breaking into Linux VMs for Fun and Profit.pdf
0x01 - Breaking into Linux VMs for Fun and Profit.pdf
 
How to Connect SystemVerilog with Octave
How to Connect SystemVerilog with OctaveHow to Connect SystemVerilog with Octave
How to Connect SystemVerilog with Octave
 
Labs_BT_20221017.pptx
Labs_BT_20221017.pptxLabs_BT_20221017.pptx
Labs_BT_20221017.pptx
 
Is your code ready for PHP 7 ?
Is your code ready for PHP 7 ?Is your code ready for PHP 7 ?
Is your code ready for PHP 7 ?
 
The Ring programming language version 1.5.2 book - Part 77 of 181
The Ring programming language version 1.5.2 book - Part 77 of 181The Ring programming language version 1.5.2 book - Part 77 of 181
The Ring programming language version 1.5.2 book - Part 77 of 181
 
Georgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software securityGeorgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software security
 
Embedded system - introduction to arm7
Embedded system -  introduction to arm7Embedded system -  introduction to arm7
Embedded system - introduction to arm7
 
Burp Suite Extension Development
Burp Suite Extension DevelopmentBurp Suite Extension Development
Burp Suite Extension Development
 
Brillo/Weave Part 2: Deep Dive
Brillo/Weave Part 2: Deep DiveBrillo/Weave Part 2: Deep Dive
Brillo/Weave Part 2: Deep Dive
 
C++InputOutput.pptx
C++InputOutput.pptxC++InputOutput.pptx
C++InputOutput.pptx
 
Cisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-oneCisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-one
 
CCNA ppt Day 4
CCNA ppt Day 4CCNA ppt Day 4
CCNA ppt Day 4
 
r2con 2017 r2cLEMENCy
r2con 2017 r2cLEMENCyr2con 2017 r2cLEMENCy
r2con 2017 r2cLEMENCy
 
The Ring programming language version 1.4 book - Part 22 of 30
The Ring programming language version 1.4 book - Part 22 of 30The Ring programming language version 1.4 book - Part 22 of 30
The Ring programming language version 1.4 book - Part 22 of 30
 
RenderMan*: The Role of Open Shading Language (OSL) with Intel® Advanced Vect...
RenderMan*: The Role of Open Shading Language (OSL) with Intel® Advanced Vect...RenderMan*: The Role of Open Shading Language (OSL) with Intel® Advanced Vect...
RenderMan*: The Role of Open Shading Language (OSL) with Intel® Advanced Vect...
 
Attack your Trusted Core
Attack your Trusted CoreAttack your Trusted Core
Attack your Trusted Core
 

Recently uploaded

Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
KrzysztofKkol1
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 

Recently uploaded (20)

Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 

Introduction to open_sbi

  • 2. I’m Nylon Chen Work for Andes Tech Hello!
  • 3. Outline • SBI • OpenSBI • How to add a new SBI call
  • 4. Ring 2 Ring 1 Ring 0 Least Privileged Most Privileged User Space (U-Mode) Operating System (S-Mode) Hypervisor(H-Mode) Firmware(M-Mode) RISC-V Privilege Modes X-86 Protection ring User Space (EL0) Operating System (EL1) Hypervisor(EL2) Firmware(EL3) ARM64 Exception Levels
  • 5. SBI • SBI stands for RISC-V Supervisor Binary Interface • The System call type interface layer between Firmware runtime, M-Mode to Operating system(S-Mode) • Avoid fragmentation of various OEM silicon providers specific runtime firmware implementations • Standard, generic runtime firmware interface specification across all OSes, different cpu and silicon platforms • Specification in SBI v0.2 in usage • Documentation available at – https://github.com/riscv/riscv-sbi-doc App 1 App 2 App 3 ABI ABI ABI OS (S-Mode) Open SBI (M-Mode) SBI
  • 6. OpenSBI • Berkeley Boot Loader(BBL) • OpenSBI is an open-source implementation of the RISC- V Supervisor Binary Interface (SBI) specifications • Aimed at providing RUNTIME services in M-mode • Provides support for reference platforms • Platforms supports Andes AE350, Ariane FPGA, Kendryte K210, Nuclei ux600, SiFive U540, Thead c910, QEMU • firmware implementations – FW_PAYLOAD – FW_JUMP – FW_DYNAMIC
  • 7. OpenSBI Calling Convention • S mode traps into M mode using ecall instructions • Arguments are passed via registers a0-a5 • a7 encodes the SBI extension ID • a6 encodes the Function ID • SBI functions must return a pair of values in a0 & a1 • Unsupported SBI returns -2 (SBI_ENOTSUPP in Linux) [arch/riscv/include/asm/sbi.h] … #define SBI_SUCCESS 0 #define SBI_ERR_FAILURE -1 #define SBI_ERR_NOT_SUPPORTED -2 ... struct sbiret { long error; long value; };
  • 8. SBI Call [arch/riscv/kernel/sbi.c] struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, unsigned long arg1, unsigned long arg2,…) { … register uintptr_t a6 asm ("a6") = (uintptr_t)(fid); register uintptr_t a7 asm ("a7") = (uintptr_t)(ext); asm volatile ("ecall" : "+r" (a0), "+r" (a1) : "r" (a2), "r" (a3), "r" (a4), "r" (a5), "r" (a6), "r" (a7) : "memory"); ret.error = a0; ret.value = a1; return ret; } Linux kernel User mode Supervisor mode Machine mode mret sret ecall sbi_trap_handl e mtvec
  • 9. SBI Call (Cont’) [lib/sbi/sbi_ecall.c] int sbi_ecall_handler(struct sbi_trap_regs *regs) { … unsigned long extension_id = regs->a7 unsigned long func_id = regs->a6; unsigned long args[6]; args[0] = regs->a0; … ext = sbi_ecall_find_extension(extension_id); if (ext && ext->handle) { ret = ext->handle(extension_id, func_id, args, &out_val, &trap); …. } regs->a0 = ret; if (!is_0_1_spec) regs->a1 = out_val; } User mode Supervisor mode Machine mode mret sret ecall mepc OpenSBI
  • 10. Legacy SBI Extension BBL & SBI-v0.1 Function Name Function ID Extension ID Replacement Extension sbi_set_timer 0 0x00 N/A sbi_console_putchar 0 0x01 N/A sbi_console_getchar 0 0x02 N/A sbi_clear_ipi 0 0x03 N/A sbi_send_ipi 0 0x04 N/A sbi_remote_fence_i 0 0x05 N/A sbi_remote_sfence_vma 0 0x06 N/A sbi_remote_sfence_vma_asid 0 0x07 N/A sbi_shutdown 0 0x08 N/A RESERVED 0x09-0x0F
  • 11. SBI Base Functionality Function Name Function ID Extension ID sbi_get_sbi_spec_version 0 0x10 sbi_get_sbi_impl_id 1 0x10 sbi_get_sbi_impl_version 2 0x10 sbi_probe_extension 3 0x10 sbi_get_mvendorid 4 0x10 sbi_get_marchid 5 0x10 sbi_get_mimpid 6 0x10 Vendor-Specific SBI Extension Space, Extension Ids 0x09000000 ~ 0x09FFFFFF sbi_get_mvendorid = 0x31e andes’s extension ID = 0x0900031E
  • 12. RFENCE Extension Function Name Function ID Extension ID sbi_remote_fence_i 0 0x52464E43 sbi_remote_sfence_vma 1 0x52464E43 sbi_remote_sfence_vma_asid 2 0x52464E43 sbi_remote_hfence_gvma_vmid 3 0x52464E43 sbi_remote_hfence_gvma 4 0x52464E43 sbi_remote_hfence_vvma_asid 5 0x52464E43 sbi_remote_hfence_vvma 6 0x52464E43
  • 13. Function Name Function ID Extension ID sbi_set_timer 0 0x54494D45 Function Name Function ID Extension ID sbi_send_ipi 0 0x735049 LinuxKernel>=5.7 Function Name Function ID Extension ID sbi_hart_start 0 0x48534D sbi_hart_stop 1 0x48534D sbi_hart_get_status 2 0x48534D Timer, IPI, Hart State Management Extension
  • 14. How to Add a New SBI Call • Platform-specific: If the platform has an extension ID, you can direct- contribute to OpenSBI mailing list • Vendor-Specific SBI Extension Space, Extension Ids 0x09000000 through 0x09FFFFFF • Step 1. Check Low bits from mvendorid –e.g. andes’s mvendorid = 0x31e -> 0x0900031E • Step 2. Add sbi_ext_id to Linux • Step 3. Add a new enum about platform SBI call’s number to Linux • Step 4. Add platform’s SBI function call by sbi_ecall() –e.g. sbi_ecall(Platform’s sbi_ext_id, Platform’s sbi number, 0, 0, 0…); • Step 5. Add hook function to your platform’s SBI handler –e.g. .vendor_ext_provider = platform_vendor_ext_provider
  • 15. Add Extension & Function ID [arch/riscv/include/asm/sbi.h] enum sbi_ext_id { #ifdef CONFIG_RISCV_SBI_V01 SBI_EXT_0_1_SET_TIMER = 0x0, SBI_EXT_0_1_CONSOLE_PUTCHAR = 0x1, SBI_EXT_0_1_CONSOLE_GETCHAR = 0x2, SBI_EXT_0_1_CLEAR_IPI = 0x3, SBI_EXT_0_1_SEND_IPI = 0x4, SBI_EXT_0_1_REMOTE_FENCE_I = 0x5, SBI_EXT_0_1_REMOTE_SFENCE_VMA = 0x6, SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID = 0x7, SBI_EXT_0_1_SHUTDOWN = 0x8, #endif SBI_EXT_BASE = 0x10, SBI_EXT_TIME = 0x54494D45, SBI_EXT_IPI = 0x735049, SBI_EXT_RFENCE = 0x52464E43, SBI_EXT_HSM = 0x48534D, SBI_EXT_ANDES = 0x0900031E, }; enum sbi_ext_andes_fid { SBI_EXT_ANDES_GET_MCACHE_CTL_STATUS = 0 …. } [include/sbi/sbi_ecall_interface.h] /* SBI Extension IDs */ #define SBI_EXT_0_1_SET_TIMER 0x0 #define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1 #define SBI_EXT_0_1_CONSOLE_GETCHAR 0x2 #define SBI_EXT_BASE 0x10 #define SBI_EXT_TIME 0x54494D45 #define SBI_EXT_IPI 0x735049 #define SBI_EXT_RFENCE 0x52464E43 #define SBI_EXT_HSM 0x48534D …. /* SBI function IDs for HSM extension */ #define SBI_EXT_HSM_HART_START 0x0 #define SBI_EXT_HSM_HART_STOP 0x1 #define SBI_EXT_HSM_HART_GET_STATUS 0x2 … #define SBI_EXT_VENDOR_START 0x09000000 #define SBI_EXT_VENDOR_END 0x09FFFFFF Linux kernel OpenSBI R
  • 16. Add Hook Function to SBI Handler [platform/andes/ae350/platform.c] … /* Vendor-Specific SBI handler */ static int ae350_vendor_ext_provider(long extid, long funcid, unsigned long *args, unsigned long *out_value, struct sbi_trap_info *out_trap) { int ret = 0; switch (funcid) { case SBI_EXT_ANDES_GET_MCACHE_CTL_STATUS: *out_value = csr_read(CSR_MCACHECTL); break; … default: sbi_printf("Unsupported vendor sbi call : %ldn", funcid); } … return ret; } const struct sbi_platform_operations platform_ops = { … .vendor_ext_provider = ae350_vendor_ext_provider … } OpenSBI R
  • 17. How to add a new SBI call • non-platform-specific: –Think about whether it fits into an existing extension or else create a new extension –Think about all of the details of the behaviour and error cases –Document that in a patch for the SBI document –Send it to the (Mailing List] (You need to be subscribed to be able to post) and create a PR on GitHub –Argue for it • How to decide Extension ID –TIME: 0x54, 0x49, 0x4D, 0x45 - by ASCII
  • 18. How to add a new SBI call
  • 19. References • Working experience on RISC-V • SBI • OpenSBI • Atish Patra “RISC-V Boot Process: One step at a time” • Atish Patra “Fixing the boot process in RISC-V” • Anup Patel “Xvisor: Embedded Hypervisor for RISC-V” • Anup Patel “OpenSBI Deep Dive” • Jagan Teki “An Introduction to RISC-V Boot flow: Overview, Blob vs Blobfree standards”