bootinfo.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. /* The kexec receiver carried the running IPv4 configuration across the
  21. * jump: reserved[0..3] hold ip/mask/gateway/DNS (byte 0 in the low byte). */
  22. #define BOOTINFO_FLAG_NET 0x00000004u
  23. struct boot_info {
  24. unsigned int magic;
  25. unsigned int version;
  26. unsigned int checksum;
  27. unsigned int rsdp; /* physical ACPI RSDP address, 0 = scan */
  28. unsigned int flags;
  29. unsigned int pack_addr; /* boot-time rootfs pack, 0 = none */
  30. unsigned int pack_size; /* exact pack bytes (gzip or raw) */
  31. unsigned int reserved[5];
  32. } __attribute__((packed));
  33. /* Fixed low-memory pointer, hidden from -Warray-bounds like the other boot
  34. * structures (see vga.c / acpi.c). */
  35. static inline const volatile unsigned int *bootinfo_words(void)
  36. {
  37. const volatile unsigned int *p =
  38. (const volatile unsigned int *)BOOT_INFO_ADDR;
  39. __asm__ volatile ("" : "+r"(p));
  40. return p;
  41. }
  42. static inline int bootinfo_valid(void)
  43. {
  44. const volatile unsigned int *p = bootinfo_words();
  45. unsigned int i, sum = 0;
  46. if (p[0] != BOOT_INFO_MAGIC || p[1] != BOOT_INFO_VERSION)
  47. return 0;
  48. for (i = 0; i < BOOT_INFO_WORDS; i++)
  49. sum += p[i];
  50. return sum == 0;
  51. }
  52. static inline unsigned int bootinfo_flags(void)
  53. {
  54. return bootinfo_valid() ? bootinfo_words()[4] : 0;
  55. }
  56. static inline int bootinfo_efi(void)
  57. {
  58. return (bootinfo_flags() & BOOTINFO_FLAG_EFI) != 0;
  59. }
  60. static inline int bootinfo_rgbx(void)
  61. {
  62. return (bootinfo_flags() & BOOTINFO_FLAG_RGBX) != 0;
  63. }
  64. static inline unsigned int bootinfo_rsdp(void)
  65. {
  66. return bootinfo_valid() ? bootinfo_words()[3] : 0;
  67. }
  68. static inline unsigned int bootinfo_pack_addr(void)
  69. {
  70. return bootinfo_valid() ? bootinfo_words()[5] : 0;
  71. }
  72. static inline unsigned int bootinfo_pack_size(void)
  73. {
  74. return bootinfo_valid() ? bootinfo_words()[6] : 0;
  75. }
  76. #endif