acpi.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2009 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef GRUB_ACPI_HEADER
  19. #define GRUB_ACPI_HEADER 1
  20. #ifndef GRUB_DSDT_TEST
  21. #include <grub/types.h>
  22. #include <grub/err.h>
  23. #else
  24. #define GRUB_PACKED __attribute__ ((packed))
  25. #endif
  26. #define GRUB_RSDP_SIGNATURE "RSD PTR "
  27. #define GRUB_RSDP_SIGNATURE_SIZE 8
  28. struct grub_acpi_rsdp_v10
  29. {
  30. grub_uint8_t signature[GRUB_RSDP_SIGNATURE_SIZE];
  31. grub_uint8_t checksum;
  32. grub_uint8_t oemid[6];
  33. grub_uint8_t revision;
  34. grub_uint32_t rsdt_addr;
  35. } GRUB_PACKED;
  36. struct grub_acpi_rsdp_v20
  37. {
  38. struct grub_acpi_rsdp_v10 rsdpv1;
  39. grub_uint32_t length;
  40. grub_uint64_t xsdt_addr;
  41. grub_uint8_t checksum;
  42. grub_uint8_t reserved[3];
  43. } GRUB_PACKED;
  44. struct grub_acpi_table_header
  45. {
  46. grub_uint8_t signature[4];
  47. grub_uint32_t length;
  48. grub_uint8_t revision;
  49. grub_uint8_t checksum;
  50. grub_uint8_t oemid[6];
  51. grub_uint8_t oemtable[8];
  52. grub_uint32_t oemrev;
  53. grub_uint8_t creator_id[4];
  54. grub_uint32_t creator_rev;
  55. } GRUB_PACKED;
  56. #define GRUB_ACPI_FADT_SIGNATURE "FACP"
  57. struct grub_acpi_fadt
  58. {
  59. struct grub_acpi_table_header hdr;
  60. grub_uint32_t facs_addr;
  61. grub_uint32_t dsdt_addr;
  62. grub_uint8_t somefields1[20];
  63. grub_uint32_t pm1a;
  64. grub_uint8_t somefields2[8];
  65. grub_uint32_t pmtimer;
  66. grub_uint8_t somefields3[32];
  67. grub_uint32_t flags;
  68. grub_uint8_t somefields4[16];
  69. grub_uint64_t facs_xaddr;
  70. grub_uint64_t dsdt_xaddr;
  71. grub_uint8_t somefields5[96];
  72. } GRUB_PACKED;
  73. #define GRUB_ACPI_MADT_SIGNATURE "APIC"
  74. /* Note: here GRUB_PACKED is not needed because we have grub_uint8_t only. */
  75. struct grub_acpi_madt_entry_header
  76. {
  77. grub_uint8_t type;
  78. grub_uint8_t len;
  79. };
  80. struct grub_acpi_madt
  81. {
  82. struct grub_acpi_table_header hdr;
  83. grub_uint32_t lapic_addr;
  84. grub_uint32_t flags;
  85. struct grub_acpi_madt_entry_header entries[0];
  86. } GRUB_PACKED;
  87. enum
  88. {
  89. GRUB_ACPI_MADT_ENTRY_TYPE_LAPIC = 0,
  90. GRUB_ACPI_MADT_ENTRY_TYPE_IOAPIC = 1,
  91. GRUB_ACPI_MADT_ENTRY_TYPE_INTERRUPT_OVERRIDE = 2,
  92. GRUB_ACPI_MADT_ENTRY_TYPE_LAPIC_NMI = 4,
  93. GRUB_ACPI_MADT_ENTRY_TYPE_SAPIC = 6,
  94. GRUB_ACPI_MADT_ENTRY_TYPE_LSAPIC = 7,
  95. GRUB_ACPI_MADT_ENTRY_TYPE_PLATFORM_INT_SOURCE = 8
  96. };
  97. struct grub_acpi_madt_entry_lapic
  98. {
  99. struct grub_acpi_madt_entry_header hdr;
  100. grub_uint8_t acpiid;
  101. grub_uint8_t apicid;
  102. grub_uint32_t flags;
  103. } GRUB_PACKED;
  104. struct grub_acpi_madt_entry_ioapic
  105. {
  106. struct grub_acpi_madt_entry_header hdr;
  107. grub_uint8_t id;
  108. grub_uint8_t pad;
  109. grub_uint32_t address;
  110. grub_uint32_t global_sys_interrupt;
  111. } GRUB_PACKED;
  112. struct grub_acpi_madt_entry_interrupt_override
  113. {
  114. struct grub_acpi_madt_entry_header hdr;
  115. grub_uint8_t bus;
  116. grub_uint8_t source;
  117. grub_uint32_t global_sys_interrupt;
  118. grub_uint16_t flags;
  119. } GRUB_PACKED;
  120. struct grub_acpi_madt_entry_lapic_nmi
  121. {
  122. struct grub_acpi_madt_entry_header hdr;
  123. grub_uint8_t acpiid;
  124. grub_uint16_t flags;
  125. grub_uint8_t lint;
  126. } GRUB_PACKED;
  127. struct grub_acpi_madt_entry_sapic
  128. {
  129. struct grub_acpi_madt_entry_header hdr;
  130. grub_uint8_t id;
  131. grub_uint8_t pad;
  132. grub_uint32_t global_sys_interrupt_base;
  133. grub_uint64_t addr;
  134. } GRUB_PACKED;
  135. struct grub_acpi_madt_entry_lsapic
  136. {
  137. struct grub_acpi_madt_entry_header hdr;
  138. grub_uint8_t cpu_id;
  139. grub_uint8_t id;
  140. grub_uint8_t eid;
  141. grub_uint8_t pad[3];
  142. grub_uint32_t flags;
  143. grub_uint32_t cpu_uid;
  144. grub_uint8_t cpu_uid_str[0];
  145. } GRUB_PACKED;
  146. struct grub_acpi_madt_entry_platform_int_source
  147. {
  148. struct grub_acpi_madt_entry_header hdr;
  149. grub_uint16_t flags;
  150. grub_uint8_t inttype;
  151. grub_uint8_t cpu_id;
  152. grub_uint8_t cpu_eid;
  153. grub_uint8_t sapic_vector;
  154. grub_uint32_t global_sys_int;
  155. grub_uint32_t src_flags;
  156. } GRUB_PACKED;
  157. enum
  158. {
  159. GRUB_ACPI_MADT_ENTRY_SAPIC_FLAGS_ENABLED = 1
  160. };
  161. struct grub_acpi_genaddr {
  162. grub_uint8_t space_id;
  163. #define GRUB_ACPI_GENADDR_MEM_SPACE 0x00
  164. #define GRUB_ACPI_GENADDR_IO_SPACE 0x01
  165. grub_uint8_t bit_width;
  166. grub_uint8_t bit_offset;
  167. grub_uint8_t access_size;
  168. #define GRUB_ACPI_GENADDR_SIZE_LGCY 0x00
  169. #define GRUB_ACPI_GENADDR_SIZE_BYTE 0x01
  170. #define GRUB_ACPI_GENADDR_SIZE_WORD 0x02
  171. #define GRUB_ACPI_GENADDR_SIZE_DWORD 0x03
  172. #define GRUB_ACPI_GENADDR_SIZE_QWORD 0x04
  173. grub_uint64_t addr;
  174. } GRUB_PACKED;
  175. #define GRUB_ACPI_SPCR_SIGNATURE "SPCR"
  176. struct grub_acpi_spcr {
  177. struct grub_acpi_table_header hdr;
  178. grub_uint8_t intf_type;
  179. #define GRUB_ACPI_SPCR_INTF_TYPE_16550 0x00
  180. #define GRUB_ACPI_SPCR_INTF_TYPE_16550_DBGP 0x01
  181. #define GRUB_ACPI_SPCR_INTF_TYPE_16550_DBG2 0x12
  182. grub_uint8_t reserved_0[3];
  183. struct grub_acpi_genaddr base_addr;
  184. grub_uint8_t interrupt_type;
  185. grub_uint8_t irq;
  186. grub_uint32_t gsi;
  187. grub_uint8_t baud_rate;
  188. #define GRUB_ACPI_SPCR_BAUD_CURRENT 0x00
  189. #define GRUB_ACPI_SPCR_BAUD_9600 0x03
  190. #define GRUB_ACPI_SPCR_BAUD_19200 0x04
  191. #define GRUB_ACPI_SPCR_BAUD_57600 0x06
  192. #define GRUB_ACPI_SPCR_BAUD_115200 0x07
  193. grub_uint8_t parity;
  194. grub_uint8_t stop_bits;
  195. grub_uint8_t flow_control;
  196. #define GRUB_ACPI_SPCR_FC_DCD_TX (1 << 0)
  197. #define GRUB_ACPI_SPCR_FC_RTSCTS (1 << 1)
  198. #define GRUB_ACPI_SPCR_FC_XONXOFF (1 << 2)
  199. grub_uint8_t terminal_type;
  200. grub_uint8_t language;
  201. grub_uint16_t pci_device_id;
  202. grub_uint16_t pci_vendor_id;
  203. grub_uint8_t pci_bus;
  204. grub_uint8_t pci_device;
  205. grub_uint8_t pci_function;
  206. grub_uint32_t pci_flags;
  207. grub_uint8_t pci_segment;
  208. grub_uint32_t reserved_1;
  209. } GRUB_PACKED;
  210. #ifndef GRUB_DSDT_TEST
  211. struct grub_acpi_rsdp_v10 *grub_acpi_get_rsdpv1 (void);
  212. struct grub_acpi_rsdp_v20 *grub_acpi_get_rsdpv2 (void);
  213. struct grub_acpi_rsdp_v10 *EXPORT_FUNC(grub_machine_acpi_get_rsdpv1) (void);
  214. struct grub_acpi_rsdp_v20 *EXPORT_FUNC(grub_machine_acpi_get_rsdpv2) (void);
  215. grub_uint8_t EXPORT_FUNC(grub_byte_checksum) (void *base, grub_size_t size);
  216. grub_err_t grub_acpi_create_ebda (void);
  217. void grub_acpi_halt (void);
  218. #endif
  219. #define GRUB_ACPI_SLP_EN (1 << 13)
  220. #define GRUB_ACPI_SLP_TYP_OFFSET 10
  221. enum
  222. {
  223. GRUB_ACPI_OPCODE_ZERO = 0, GRUB_ACPI_OPCODE_ONE = 1,
  224. GRUB_ACPI_OPCODE_NAME = 8, GRUB_ACPI_OPCODE_ALIAS = 0x06,
  225. GRUB_ACPI_OPCODE_BYTE_CONST = 0x0a,
  226. GRUB_ACPI_OPCODE_WORD_CONST = 0x0b,
  227. GRUB_ACPI_OPCODE_DWORD_CONST = 0x0c,
  228. GRUB_ACPI_OPCODE_STRING_CONST = 0x0d,
  229. GRUB_ACPI_OPCODE_SCOPE = 0x10,
  230. GRUB_ACPI_OPCODE_BUFFER = 0x11,
  231. GRUB_ACPI_OPCODE_PACKAGE = 0x12,
  232. GRUB_ACPI_OPCODE_METHOD = 0x14, GRUB_ACPI_OPCODE_EXTOP = 0x5b,
  233. GRUB_ACPI_OPCODE_ADD = 0x72,
  234. GRUB_ACPI_OPCODE_CONCAT = 0x73,
  235. GRUB_ACPI_OPCODE_SUBTRACT = 0x74,
  236. GRUB_ACPI_OPCODE_MULTIPLY = 0x77,
  237. GRUB_ACPI_OPCODE_DIVIDE = 0x78,
  238. GRUB_ACPI_OPCODE_LSHIFT = 0x79,
  239. GRUB_ACPI_OPCODE_RSHIFT = 0x7a,
  240. GRUB_ACPI_OPCODE_AND = 0x7b,
  241. GRUB_ACPI_OPCODE_NAND = 0x7c,
  242. GRUB_ACPI_OPCODE_OR = 0x7d,
  243. GRUB_ACPI_OPCODE_NOR = 0x7e,
  244. GRUB_ACPI_OPCODE_XOR = 0x7f,
  245. GRUB_ACPI_OPCODE_CONCATRES = 0x84,
  246. GRUB_ACPI_OPCODE_MOD = 0x85,
  247. GRUB_ACPI_OPCODE_INDEX = 0x88,
  248. GRUB_ACPI_OPCODE_CREATE_DWORD_FIELD = 0x8a,
  249. GRUB_ACPI_OPCODE_CREATE_WORD_FIELD = 0x8b,
  250. GRUB_ACPI_OPCODE_CREATE_BYTE_FIELD = 0x8c,
  251. GRUB_ACPI_OPCODE_TOSTRING = 0x9c,
  252. GRUB_ACPI_OPCODE_IF = 0xa0, GRUB_ACPI_OPCODE_ONES = 0xff
  253. };
  254. enum
  255. {
  256. GRUB_ACPI_EXTOPCODE_MUTEX = 0x01,
  257. GRUB_ACPI_EXTOPCODE_EVENT_OP = 0x02,
  258. GRUB_ACPI_EXTOPCODE_OPERATION_REGION = 0x80,
  259. GRUB_ACPI_EXTOPCODE_FIELD_OP = 0x81,
  260. GRUB_ACPI_EXTOPCODE_DEVICE_OP = 0x82,
  261. GRUB_ACPI_EXTOPCODE_PROCESSOR_OP = 0x83,
  262. GRUB_ACPI_EXTOPCODE_POWER_RES_OP = 0x84,
  263. GRUB_ACPI_EXTOPCODE_THERMAL_ZONE_OP = 0x85,
  264. GRUB_ACPI_EXTOPCODE_INDEX_FIELD_OP = 0x86,
  265. GRUB_ACPI_EXTOPCODE_BANK_FIELD_OP = 0x87,
  266. };
  267. struct grub_acpi_fadt *
  268. EXPORT_FUNC(grub_acpi_find_fadt) (void);
  269. void *
  270. EXPORT_FUNC(grub_acpi_find_table) (const char *sig);
  271. #endif /* ! GRUB_ACPI_HEADER */