2
0

bgrt.rs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. use crate::{sdt::SdtHeader, AcpiTable};
  2. use bit_field::BitField;
  3. /// The BGRT table contains information about a boot graphic that was displayed
  4. /// by firmware.
  5. #[repr(C, packed)]
  6. #[derive(Clone, Copy)]
  7. pub struct Bgrt {
  8. header: SdtHeader,
  9. pub version: u16,
  10. status: u8,
  11. image_type: u8,
  12. pub image_address: u64,
  13. image_offset_x: u32,
  14. image_offset_y: u32,
  15. }
  16. impl AcpiTable for Bgrt {
  17. fn header(&self) -> &SdtHeader {
  18. &self.header
  19. }
  20. }
  21. impl Bgrt {
  22. pub fn image_type(&self) -> ImageType {
  23. let img_type = self.image_type;
  24. match img_type {
  25. 0 => ImageType::Bitmap,
  26. _ => ImageType::Reserved,
  27. }
  28. }
  29. /// Gets the orientation offset of the image.
  30. /// Degrees are clockwise from the images default orientation.
  31. pub fn orientation_offset(&self) -> u16 {
  32. let status = self.status;
  33. match status.get_bits(1..3) {
  34. 0 => 0,
  35. 1 => 90,
  36. 2 => 180,
  37. 3 => 270,
  38. _ => unreachable!(), // will never happen
  39. }
  40. }
  41. pub fn was_displayed(&self) -> bool {
  42. let status = self.status;
  43. status.get_bit(0)
  44. }
  45. pub fn image_offset(&self) -> (u32, u32) {
  46. let x = self.image_offset_x;
  47. let y = self.image_offset_y;
  48. (x, y)
  49. }
  50. }
  51. #[repr(u8)]
  52. #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
  53. pub enum ImageType {
  54. Bitmap,
  55. Reserved,
  56. }