bootinfo.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* Boot information block at 0x500.
  2. *
  3. * The legacy VESA stage (vesa_stage.S) does not fill this in; it clears the
  4. * magic so a BIOS boot takes exactly the old code paths. The UEFI loader
  5. * fills it in with the ACPI RSDP address, the boot source and the GOP pixel
  6. * order. A checksum over the eight dwords (with the checksum field set so
  7. * the sum is zero) keeps stale low memory from being mistaken for a valid
  8. * block after a kexec or a legacy boot.
  9. */
  10. #ifndef BOOTINFO_H
  11. #define BOOTINFO_H
  12. #define BOOT_INFO_ADDR 0x500
  13. #define BOOT_INFO_MAGIC 0x4E425349u /* "NBSI" */
  14. #define BOOT_INFO_VERSION 1u
  15. #define BOOTINFO_FLAG_EFI 0x00000001u
  16. #define BOOTINFO_FLAG_RGBX 0x00000002u /* GOP 32bpp byte order R,G,B,X */
  17. struct boot_info {
  18. unsigned int magic;
  19. unsigned int version;
  20. unsigned int checksum;
  21. unsigned int rsdp; /* physical ACPI RSDP address, 0 = scan */
  22. unsigned int flags;
  23. unsigned int reserved[3];
  24. } __attribute__((packed));
  25. /* Fixed low-memory pointer, hidden from -Warray-bounds like the other boot
  26. * structures (see vga.c / acpi.c). */
  27. static inline const volatile unsigned int *bootinfo_words(void)
  28. {
  29. const volatile unsigned int *p =
  30. (const volatile unsigned int *)BOOT_INFO_ADDR;
  31. __asm__ volatile ("" : "+r"(p));
  32. return p;
  33. }
  34. static inline int bootinfo_valid(void)
  35. {
  36. const volatile unsigned int *p = bootinfo_words();
  37. unsigned int i, sum = 0;
  38. if (p[0] != BOOT_INFO_MAGIC || p[1] != BOOT_INFO_VERSION)
  39. return 0;
  40. for (i = 0; i < 8; i++)
  41. sum += p[i];
  42. return sum == 0;
  43. }
  44. static inline unsigned int bootinfo_flags(void)
  45. {
  46. return bootinfo_valid() ? bootinfo_words()[4] : 0;
  47. }
  48. static inline int bootinfo_efi(void)
  49. {
  50. return (bootinfo_flags() & BOOTINFO_FLAG_EFI) != 0;
  51. }
  52. static inline int bootinfo_rgbx(void)
  53. {
  54. return (bootinfo_flags() & BOOTINFO_FLAG_RGBX) != 0;
  55. }
  56. static inline unsigned int bootinfo_rsdp(void)
  57. {
  58. return bootinfo_valid() ? bootinfo_words()[3] : 0;
  59. }
  60. #endif