Nothing to see here, move along
1use crate::proc::context::CpuContext;
2use crate::syscall::SyscallResult;
3
4pub const KEY_COM1_GSI: u64 = 0;
5pub const KEY_KBD_GSI: u64 = 1;
6pub const KEY_VIRTIO_NET_GSI: u64 = 2;
7pub const KEY_HAS_FRAMEBUFFER: u64 = 3;
8pub const KEY_HAS_IOMMU: u64 = 4;
9
10struct BootPlatformInfo {
11 com1_gsi: i64,
12 kbd_gsi: i64,
13 virtio_net_gsi: i64,
14}
15
16static mut PLATFORM_INFO: BootPlatformInfo = BootPlatformInfo {
17 com1_gsi: -1,
18 kbd_gsi: -1,
19 virtio_net_gsi: -1,
20};
21
22static PLATFORM_INITIALIZED: core::sync::atomic::AtomicBool =
23 core::sync::atomic::AtomicBool::new(false);
24
25#[allow(clippy::deref_addrof)]
26pub fn store_platform_info(
27 com1_gsi: Option<crate::arch::ioapic::Gsi>,
28 kbd_gsi: Option<crate::arch::ioapic::Gsi>,
29 virtio_net_gsi: Option<crate::arch::ioapic::Gsi>,
30) {
31 unsafe {
32 let info = &mut *(&raw mut PLATFORM_INFO);
33 info.com1_gsi = com1_gsi.map_or(-1, |g| g.raw() as i64);
34 info.kbd_gsi = kbd_gsi.map_or(-1, |g| g.raw() as i64);
35 info.virtio_net_gsi = virtio_net_gsi.map_or(-1, |g| g.raw() as i64);
36 }
37 PLATFORM_INITIALIZED.store(true, core::sync::atomic::Ordering::Release);
38}
39
40#[allow(clippy::deref_addrof)]
41pub fn sys_platform_info(ctx: &mut CpuContext) {
42 let pid = crate::arch::syscall::current_pid();
43 if pid != crate::types::Pid::new(0) {
44 ctx.rax = SyscallResult::error(crate::error::KernelError::PermissionDenied).raw();
45 return;
46 }
47
48 let key = ctx.rdi;
49
50 ctx.rax = match key {
51 KEY_COM1_GSI => unsafe { (&*(&raw const PLATFORM_INFO)).com1_gsi as u64 },
52 KEY_KBD_GSI => unsafe { (&*(&raw const PLATFORM_INFO)).kbd_gsi as u64 },
53 KEY_VIRTIO_NET_GSI => unsafe { (&*(&raw const PLATFORM_INFO)).virtio_net_gsi as u64 },
54 KEY_HAS_FRAMEBUFFER => match crate::arch::boot::framebuffer().is_some() {
55 true => 1,
56 false => 0,
57 },
58 KEY_HAS_IOMMU => match crate::iommu::is_available() {
59 true => 1,
60 false => 0,
61 },
62 _ => SyscallResult::error(crate::error::KernelError::InvalidParameter).raw(),
63 };
64}