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