bootinfo.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* Boot information block at 0x500.
  2. *
  3. * Written by the legacy VESA stage, the UEFI loader or the kexec receiver,
  4. * and read by the kernel very early. It carries the ACPI RSDP, the boot
  5. * source / GOP pixel order and the physical location of the command-pack
  6. * rootfs that the boot path copied into high memory (see ramfs.c).
  7. *
  8. * A checksum over the twelve dwords (with the checksum field set so the sum
  9. * is zero) keeps stale low memory from being mistaken for a valid block
  10. * after a kexec or a legacy boot.
  11. */
  12. #ifndef BOOTINFO_H
  13. #define BOOTINFO_H
  14. #define BOOT_INFO_ADDR 0x500
  15. #define BOOT_INFO_MAGIC 0x4E425349u /* "NBSI" */
  16. #define BOOT_INFO_VERSION 2u
  17. #define BOOT_INFO_WORDS 12u
  18. #define BOOTINFO_FLAG_EFI 0x00000001u
  19. #define BOOTINFO_FLAG_RGBX 0x00000002u /* GOP 32bpp byte order R,G,B,X */
  20. struct boot_info {
  21. unsigned int magic;
  22. unsigned int version;
  23. unsigned int checksum;
  24. unsigned int rsdp; /* physical ACPI RSDP address, 0 = scan */
  25. unsigned int flags;
  26. unsigned int pack_addr; /* boot-time rootfs pack, 0 = none */
  27. unsigned int pack_size; /* exact pack bytes (gzip or raw) */
  28. unsigned int reserved[5];
  29. } __attribute__((packed));
  30. /* Fixed low-memory pointer, hidden from -Warray-bounds like the other boot
  31. * structures (see vga.c / acpi.c). */
  32. static inline const volatile unsigned int *bootinfo_words(void)
  33. {
  34. const volatile unsigned int *p =
  35. (const volatile unsigned int *)BOOT_INFO_ADDR;
  36. __asm__ volatile ("" : "+r"(p));
  37. return p;
  38. }
  39. static inline int bootinfo_valid(void)
  40. {
  41. const volatile unsigned int *p = bootinfo_words();
  42. unsigned int i, sum = 0;
  43. if (p[0] != BOOT_INFO_MAGIC || p[1] != BOOT_INFO_VERSION)
  44. return 0;
  45. for (i = 0; i < BOOT_INFO_WORDS; i++)
  46. sum += p[i];
  47. return sum == 0;
  48. }
  49. static inline unsigned int bootinfo_flags(void)
  50. {
  51. return bootinfo_valid() ? bootinfo_words()[4] : 0;
  52. }
  53. static inline int bootinfo_efi(void)
  54. {
  55. return (bootinfo_flags() & BOOTINFO_FLAG_EFI) != 0;
  56. }
  57. static inline int bootinfo_rgbx(void)
  58. {
  59. return (bootinfo_flags() & BOOTINFO_FLAG_RGBX) != 0;
  60. }
  61. static inline unsigned int bootinfo_rsdp(void)
  62. {
  63. return bootinfo_valid() ? bootinfo_words()[3] : 0;
  64. }
  65. static inline unsigned int bootinfo_pack_addr(void)
  66. {
  67. return bootinfo_valid() ? bootinfo_words()[5] : 0;
  68. }
  69. static inline unsigned int bootinfo_pack_size(void)
  70. {
  71. return bootinfo_valid() ? bootinfo_words()[6] : 0;
  72. }
  73. #endif