Skip to main content

strat9_kernel/acpi/
bgrt.rs

1//! Support for the BGRT ACPI table (Boot Graphics Resource Table).
2//! Provides information about the boot logo/image.
3//!
4//! Reference: ACPI spec 5.0+
5//! Source : https://uefi.org/sites/default/files/resources/ACPI_5_1_Errata_B.PDF
6//!
7
8use super::sdt::Sdt;
9use zerocopy::FromBytes;
10
11pub const BGRT_SIGNATURE: &[u8; 4] = b"BGRT";
12
13/// BGRT status values
14pub const BGRT_STATUS_DISPLAYED: u8 = 1;
15
16/// BGRT image format
17pub const BGRT_FORMAT_BMP: u16 = 0;
18
19/// BGRT ACPI table structure
20#[derive(Clone, Copy, Debug, FromBytes)]
21#[repr(C, packed)]
22pub struct Bgrt {
23    pub header: Sdt,
24    pub version: u16,
25    pub status: u8,
26    pub image_type: u8,
27    pub image_base: u64,
28    pub image_offset_x: u32,
29    pub image_offset_y: u32,
30}
31
32impl Bgrt {
33    /// Finds the BGRT and returns a reference to it.
34    pub fn get() -> Option<&'static Bgrt> {
35        unsafe { super::find_table(BGRT_SIGNATURE).map(|ptr| &*(ptr as *const Bgrt)) }
36    }
37
38    /// Check if the image was displayed by firmware
39    pub fn was_displayed(&self) -> bool {
40        (self.status & BGRT_STATUS_DISPLAYED) != 0
41    }
42
43    /// Get image format (0 = BMP)
44    pub fn image_format(&self) -> u16 {
45        self.image_type.into()
46    }
47
48    /// Get image base address
49    pub fn image_base(&self) -> u64 {
50        self.image_base
51    }
52
53    /// Get image X offset
54    pub fn image_offset_x(&self) -> u32 {
55        self.image_offset_x
56    }
57
58    /// Get image Y offset
59    pub fn image_offset_y(&self) -> u32 {
60        self.image_offset_y
61    }
62}