summaryrefslogtreecommitdiff
path: root/src/bgrt.rs
blob: ab231511a5d3e6d4616e7fed809265f87f1b5b19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use crate::{
    sdt::{SdtHeader, Signature},
    AcpiTable,
};
use bit_field::BitField;

/// The BGRT table contains information about a boot graphic that was displayed
/// by firmware.
#[repr(C, packed)]
#[derive(Debug, Clone, Copy)]
pub struct Bgrt {
    header: SdtHeader,
    pub version: u16,
    status: u8,
    image_type: u8,
    pub image_address: u64,
    image_offset_x: u32,
    image_offset_y: u32,
}

/// ### Safety: Implementation properly represents a valid BGRT.
unsafe impl AcpiTable for Bgrt {
    const SIGNATURE: Signature = Signature::BGRT;

    fn header(&self) -> &SdtHeader {
        &self.header
    }
}

impl Bgrt {
    pub fn image_type(&self) -> ImageType {
        let img_type = self.image_type;
        match img_type {
            0 => ImageType::Bitmap,
            _ => ImageType::Reserved,
        }
    }

    /// Gets the orientation offset of the image.
    /// Degrees are clockwise from the images default orientation.
    pub fn orientation_offset(&self) -> u16 {
        let status = self.status;
        match status.get_bits(1..3) {
            0 => 0,
            1 => 90,
            2 => 180,
            3 => 270,
            _ => unreachable!(), // will never happen
        }
    }

    pub fn was_displayed(&self) -> bool {
        let status = self.status;
        status.get_bit(0)
    }

    pub fn image_offset(&self) -> (u32, u32) {
        let x = self.image_offset_x;
        let y = self.image_offset_y;
        (x, y)
    }
}

#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum ImageType {
    Bitmap,
    Reserved,
}