Skip to content

Commit

Permalink
Misc cleanups
Browse files Browse the repository at this point in the history
- replace win64 with efiapi for ABI
- replace enums with newtype structs
- add useful derives to the structs
- make GUID and revisions associated constants
- handle installing toolchain with rustup 1.28.0

Signed-off-by: Tim Crawford <[email protected]>
  • Loading branch information
crawfxrd committed Dec 12, 2024
1 parent 8cf24ab commit 530583c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
74 changes: 42 additions & 32 deletions src/gop_policy.rs
Original file line number Diff line number Diff line change
@@ -1,69 +1,81 @@
// 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;
}

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<Self> {
Box::new(Self {
Revision: GOP_POLICY_REVISION,
Revision: Self::REVISION_03,
GetPlatformLidStatus,
GetVbtData,
GetPlatformDockStatus,
Expand All @@ -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(())
}
}
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#![no_std]
#![no_main]
#![allow(non_snake_case)]

#[macro_use]
extern crate uefi_std as std;
Expand Down

0 comments on commit 530583c

Please sign in to comment.