Skip to content

Commit 5cd1cbd

Browse files
author
BillXiang
committed
riscv64: Handle KVM_EXIT_RISCV_SBI exit
Handle console sbi call, which implement early console io while apply 'earlycon=sbi' into kernel parameters. Signed-off-by: BillXiang <[email protected]>
1 parent 97dbb98 commit 5cd1cbd

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

kvm-ioctls/src/ioctls/vcpu.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ pub enum VcpuExit<'a> {
184184
/// size
185185
size: u64,
186186
},
187+
/// Corresponds to SBI_EXT_0_1_CONSOLE_PUTCHAR.
188+
SbiExt0_1ConsolePutchar(u64),
189+
/// Corresponds to SBI_EXT_0_1_CONSOLE_GETCHAR.
190+
SbiExt0_1ConsoleGetchar(&'a mut [u64]),
187191
/// Corresponds to an exit reason that is unknown from the current version
188192
/// of the kvm-ioctls crate. Let the consumer decide about what to do with
189193
/// it.
@@ -1688,6 +1692,26 @@ impl VcpuFd {
16881692
Ok(VcpuExit::IoapicEoi(eoi.vector))
16891693
}
16901694
KVM_EXIT_HYPERV => Ok(VcpuExit::Hyperv),
1695+
#[cfg(target_arch = "riscv64")]
1696+
KVM_EXIT_RISCV_SBI => {
1697+
// SAFETY: Safe because the exit_reason (which comes from the kernel) told us
1698+
// which union field to use and the type of extension_id is 'enum sbi_ext_id'.
1699+
match unsafe { run.__bindgen_anon_1.riscv_sbi.extension_id } as u32 {
1700+
SBI_EXT_0_1_CONSOLE_PUTCHAR => {
1701+
// SAFETY: Safe because the exit_reason (which comes from the kernel) told us
1702+
// which union field to use
1703+
let ch = unsafe { run.__bindgen_anon_1.riscv_sbi.args[0] };
1704+
Ok(VcpuExit::SbiExt0_1ConsolePutchar(ch))
1705+
}
1706+
SBI_EXT_0_1_CONSOLE_GETCHAR => {
1707+
// SAFETY: Safe because the exit_reason (which comes from the kernel) told us
1708+
// which union field to use
1709+
let ch = unsafe { &mut run.__bindgen_anon_1.riscv_sbi.ret[..1] };
1710+
Ok(VcpuExit::SbiExt0_1ConsoleGetchar(ch))
1711+
}
1712+
r => Ok(VcpuExit::Unsupported(r)),
1713+
}
1714+
}
16911715
r => Ok(VcpuExit::Unsupported(r)),
16921716
}
16931717
} else {

0 commit comments

Comments
 (0)