bgrt.rs 1.6 KB

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