diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9827b32..de6348a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: - name: Install dependencies run: | sudo apt install --yes make - rustup show + rustup show active-toolchain || rustup toolchain install - name: Build UEFI application env: diff --git a/src/gop_policy.rs b/src/gop_policy.rs index 174b66b..ba7f928 100644 --- a/src/gop_policy.rs +++ b/src/gop_policy.rs @@ -1,42 +1,63 @@ // SPDX-License-Identifier: GPL-3.0-only +#![allow(non_snake_case)] +#![allow(unused)] + use std::prelude::*; use std::uefi::boot::InterfaceType; use std::uefi::memory::PhysicalAddress; static VBT: &[u8] = include_bytes!(env!("FIRMWARE_OPEN_VBT")); -pub static GOP_POLICY_GUID: Guid = guid!("ec2e931b-3281-48a5-8107-df8a8bed3c5d"); -pub const GOP_POLICY_REVISION: u32 = 0x03; +#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)] +#[repr(transparent)] +pub struct LidStatus(u32); -#[allow(unused)] -#[repr(C)] -pub enum LidStatus { - LidClosed, - LidOpen, - LidStatusMax, +impl LidStatus { + pub const CLOSED: Self = Self(0); + pub const OPEN: Self = Self(1); + pub const MAX: Self = Self(2); +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)] +#[repr(transparent)] +pub struct DockStatus(u32); + +impl DockStatus { + pub const DOCKED: Self = Self(0); + pub const UNDOCKED: Self = Self(1); + pub const MAX: Self = Self(2); } -#[allow(unused)] +#[rustfmt::skip] +#[derive(Debug)] #[repr(C)] -pub enum DockStatus { - Docked, - UnDocked, - DockStatusMax, +pub struct GopPolicy { + pub Revision: u32, + pub GetPlatformLidStatus: extern "efiapi" fn (CurrentLidStatus: *mut LidStatus) -> Status, + pub GetVbtData: extern "efiapi" fn (VbtAddress: *mut PhysicalAddress, VbtSize: *mut u32) -> Status, + pub GetPlatformDockStatus: extern "efiapi" fn (CurrentDockStatus: DockStatus) -> Status, + pub GopOverrideGuid: Guid, } -extern "win64" fn GetPlatformLidStatus(CurrentLidStatus: *mut LidStatus) -> Status { +impl GopPolicy { + pub const GUID: Guid = guid!("ec2e931b-3281-48a5-8107-df8a8bed3c5d"); + pub const REVISION_01: u32 = 0x01; + pub const REVISION_03: u32 = 0x03; +} + +extern "efiapi" fn GetPlatformLidStatus(CurrentLidStatus: *mut LidStatus) -> Status { if CurrentLidStatus.is_null() { return Status::INVALID_PARAMETER; } // TODO: Get real lid status - unsafe { *CurrentLidStatus = LidStatus::LidOpen }; + unsafe { *CurrentLidStatus = LidStatus::OPEN }; Status::SUCCESS } -extern "win64" fn GetVbtData(VbtAddress: *mut PhysicalAddress, VbtSize: *mut u32) -> Status { +extern "efiapi" fn GetVbtData(VbtAddress: *mut PhysicalAddress, VbtSize: *mut u32) -> Status { if VbtAddress.is_null() || VbtSize.is_null() { return Status::INVALID_PARAMETER; } @@ -44,26 +65,17 @@ extern "win64" fn GetVbtData(VbtAddress: *mut PhysicalAddress, VbtSize: *mut u32 unsafe { *VbtAddress = PhysicalAddress(VBT.as_ptr() as u64) }; unsafe { *VbtSize = VBT.len() as u32 }; - Status(0) + Status::SUCCESS } -extern "win64" fn GetPlatformDockStatus(_CurrentDockStatus: DockStatus) -> Status { +extern "efiapi" fn GetPlatformDockStatus(_CurrentDockStatus: DockStatus) -> Status { Status::UNSUPPORTED } -#[repr(C)] -pub struct GopPolicy { - pub Revision: u32, - pub GetPlatformLidStatus: extern "win64" fn (CurrentLidStatus: *mut LidStatus) -> Status, - pub GetVbtData: extern "win64" fn (VbtAddress: *mut PhysicalAddress, VbtSize: *mut u32) -> Status, - pub GetPlatformDockStatus: extern "win64" fn (CurrentDockStatus: DockStatus) -> Status, - pub GopOverrideGuid: Guid, -} - impl GopPolicy { pub fn new() -> Box { Box::new(Self { - Revision: GOP_POLICY_REVISION, + Revision: Self::REVISION_03, GetPlatformLidStatus, GetVbtData, GetPlatformDockStatus, @@ -78,13 +90,11 @@ impl GopPolicy { let mut handle = Handle(0); Result::from((uefi.BootServices.InstallProtocolInterface)( &mut handle, - &GOP_POLICY_GUID, + &Self::GUID, InterfaceType::Native, - self_ptr as usize + self_ptr as usize, ))?; - //let _ = (uefi.BootServices.UninstallProtocolInterface)(handle, &GOP_POLICY_GUID, self_ptr as usize); - Ok(()) } } diff --git a/src/main.rs b/src/main.rs index 3136c1b..ee52ffe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,6 @@ #![no_std] #![no_main] -#![allow(non_snake_case)] #[macro_use] extern crate uefi_std as std;