Definitions.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /*
  2. * Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/RefCounted.h>
  8. #include <AK/Types.h>
  9. #include <AK/Vector.h>
  10. #include <Kernel/PhysicalAddress.h>
  11. namespace Kernel::ACPI {
  12. namespace FADTFlags {
  13. // https://uefi.org/specs/ACPI/6.4/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#fixed-acpi-description-table-fixed-feature-flags
  14. enum class FeatureFlags : u32 {
  15. WBINVD = 1 << 0,
  16. WBINVD_FLUSH = 1 << 1,
  17. PROC_C1 = 1 << 2,
  18. P_LVL2_UP = 1 << 3,
  19. PWR_BUTTON = 1 << 4,
  20. SLP_BUTTON = 1 << 5,
  21. FIX_RTC = 1 << 6,
  22. RTC_s4 = 1 << 7,
  23. TMR_VAL_EXT = 1 << 8,
  24. DCK_CAP = 1 << 9,
  25. RESET_REG_SUPPORTED = 1 << 10,
  26. SEALED_CASE = 1 << 11,
  27. HEADLESS = 1 << 12,
  28. CPU_SW_SLP = 1 << 13,
  29. PCI_EXP_WAK = 1 << 14,
  30. USE_PLATFORM_CLOCK = 1 << 15,
  31. S4_RTC_STS_VALID = 1 << 16,
  32. REMOTE_POWER_ON_CAPABLE = 1 << 17,
  33. FORCE_APIC_CLUSTER_MODEL = 1 << 18,
  34. FORCE_APIC_PHYSICAL_DESTINATION_MODE = 1 << 19,
  35. HW_REDUCED_ACPI = 1 << 20,
  36. LOW_POWER_S0_IDLE_CAPABLE = 1 << 21
  37. };
  38. // https://uefi.org/specs/ACPI/6.4/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#fixed-acpi-description-table-boot-ia-pc-boot-architecture-flags
  39. enum class IA_PC_Flags : u8 {
  40. Legacy_Devices = 1 << 0,
  41. PS2_8042 = 1 << 1,
  42. VGA_Not_Present = 1 << 2,
  43. MSI_Not_Supported = 1 << 3,
  44. PCIe_ASPM_Controls = 1 << 4,
  45. CMOS_RTC_Not_Present = 1 << 5
  46. };
  47. struct [[gnu::packed]] HardwareFeatures {
  48. bool wbinvd : 1;
  49. bool wbinvd_flush : 1;
  50. bool processor_c1 : 1;
  51. bool multiprocessor_c2 : 1;
  52. bool power_button : 1;
  53. bool sleep_button : 1;
  54. bool fix_rtc : 1;
  55. bool rtc_s4 : 1;
  56. bool timer_value_extension : 1;
  57. bool docking_capability : 1;
  58. bool reset_register_supported : 1;
  59. bool sealed_case : 1;
  60. bool headless : 1;
  61. bool cpu_software_sleep : 1;
  62. bool pci_express_wake : 1;
  63. bool use_platform_clock : 1;
  64. bool s4_rtc_status_valid : 1;
  65. bool remote_power_on_capable : 1;
  66. bool force_apic_cluster_model : 1;
  67. bool force_apic_physical_destination_mode : 1;
  68. bool hardware_reduced_acpi : 1;
  69. bool low_power_s0_idle_capable : 1;
  70. };
  71. struct [[gnu::packed]] x86_Specific_Flags {
  72. bool legacy_devices : 1;
  73. bool keyboard_8042 : 1;
  74. bool vga_not_present : 1;
  75. bool msi_not_supported : 1;
  76. bool cmos_rtc_not_present : 1;
  77. };
  78. };
  79. namespace GenericAddressStructure {
  80. enum class AddressSpace {
  81. SystemMemory = 0,
  82. SystemIO = 1,
  83. PCIConfigurationSpace = 2,
  84. EmbeddedController = 3,
  85. SMBus = 4,
  86. PCC = 0xA,
  87. FunctionalFixedHardware = 0x7F
  88. };
  89. enum class AccessSize {
  90. Undefined = 0,
  91. Byte = 1,
  92. Word = 2,
  93. DWord = 3,
  94. QWord = 4
  95. };
  96. enum class BitWidth {
  97. Undefined = 0,
  98. Byte = 8,
  99. Word = 16,
  100. DWord = 32,
  101. QWord = 64
  102. };
  103. }
  104. namespace Structures {
  105. // https://uefi.org/specs/ACPI/6.4/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#root-system-description-pointer-rsdp-structure
  106. struct [[gnu::packed]] RSDPDescriptor {
  107. char sig[8];
  108. u8 checksum;
  109. char oem_id[6];
  110. u8 revision;
  111. u32 rsdt_ptr;
  112. };
  113. struct [[gnu::packed]] RSDPDescriptor20 {
  114. RSDPDescriptor base;
  115. u32 length;
  116. u64 xsdt_ptr;
  117. u8 ext_checksum;
  118. u8 reserved[3];
  119. };
  120. // https://uefi.org/specs/ACPI/6.4/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#system-description-table-header
  121. struct [[gnu::packed]] SDTHeader {
  122. char sig[4];
  123. u32 length;
  124. u8 revision;
  125. u8 checksum;
  126. char oem_id[6];
  127. char oem_table_id[8];
  128. u32 oem_revision;
  129. u32 creator_id;
  130. u32 creator_revision;
  131. };
  132. // https://uefi.org/specs/ACPI/6.4/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#root-system-description-table-rsdt
  133. struct [[gnu::packed]] RSDT {
  134. SDTHeader h;
  135. u32 table_ptrs[];
  136. };
  137. // https://uefi.org/specs/ACPI/6.4/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#extended-system-description-table-xsdt
  138. struct [[gnu::packed]] XSDT {
  139. SDTHeader h;
  140. u64 table_ptrs[];
  141. };
  142. struct [[gnu::packed]] GenericAddressStructure {
  143. u8 address_space;
  144. u8 bit_width;
  145. u8 bit_offset;
  146. u8 access_size;
  147. u64 address;
  148. };
  149. struct [[gnu::packed]] HPET {
  150. SDTHeader h;
  151. u8 hardware_revision_id;
  152. u8 attributes;
  153. u16 pci_vendor_id;
  154. GenericAddressStructure event_timer_block;
  155. u8 hpet_number;
  156. u16 mininum_clock_tick;
  157. u8 page_protection;
  158. };
  159. // https://uefi.org/specs/ACPI/6.4/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#fixed-acpi-description-table-fadt
  160. struct [[gnu::packed]] FADT {
  161. SDTHeader h;
  162. u32 firmware_ctrl;
  163. u32 dsdt_ptr;
  164. u8 reserved;
  165. u8 preferred_pm_profile;
  166. u16 sci_int;
  167. u32 smi_cmd;
  168. u8 acpi_enable_value;
  169. u8 acpi_disable_value;
  170. u8 s4bios_req;
  171. u8 pstate_cnt;
  172. u32 PM1a_EVT_BLK;
  173. u32 PM1b_EVT_BLK;
  174. u32 PM1a_CNT_BLK;
  175. u32 PM1b_CNT_BLK;
  176. u32 PM2_CNT_BLK;
  177. u32 PM_TMR_BLK;
  178. u32 GPE0_BLK;
  179. u32 GPE1_BLK;
  180. u8 PM1_EVT_LEN;
  181. u8 PM1_CNT_LEN;
  182. u8 PM2_CNT_LEN;
  183. u8 PM_TMR_LEN;
  184. u8 GPE0_BLK_LEN;
  185. u8 GPE1_BLK_LEN;
  186. u8 GPE1_BASE;
  187. u8 cst_cnt;
  188. u16 P_LVL2_LAT;
  189. u16 P_LVL3_LAT;
  190. u16 flush_size;
  191. u16 flush_stride;
  192. u8 duty_offset;
  193. u8 duty_width;
  194. u8 day_alrm;
  195. u8 mon_alrm;
  196. u8 century;
  197. u16 ia_pc_boot_arch_flags;
  198. u8 reserved2;
  199. u32 flags;
  200. GenericAddressStructure reset_reg;
  201. u8 reset_value;
  202. u16 arm_boot_arch;
  203. u8 fadt_minor_version;
  204. u64 x_firmware_ctrl;
  205. u64 x_dsdt;
  206. GenericAddressStructure x_pm1a_evt_blk;
  207. GenericAddressStructure x_pm1b_evt_blk;
  208. GenericAddressStructure x_pm1a_cnt_blk;
  209. GenericAddressStructure x_pm1b_cnt_blk;
  210. GenericAddressStructure x_pm2_cnt_blk;
  211. GenericAddressStructure x_pm_tmr_blk;
  212. GenericAddressStructure x_gpe0_blk;
  213. GenericAddressStructure x_gpe1_blk;
  214. GenericAddressStructure sleep_control;
  215. GenericAddressStructure sleep_status;
  216. u64 hypervisor_vendor_identity;
  217. };
  218. // https://uefi.org/specs/ACPI/6.4/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#interrupt-controller-structure-types
  219. enum class MADTEntryType {
  220. LocalAPIC = 0x0,
  221. IOAPIC = 0x1,
  222. InterruptSourceOverride = 0x2,
  223. NMI_Source = 0x3,
  224. LocalAPIC_NMI = 0x4,
  225. LocalAPIC_Address_Override = 0x5,
  226. IO_SAPIC = 0x6,
  227. Local_SAPIC = 0x7,
  228. Platform_interrupt_Sources = 0x8,
  229. Local_x2APIC = 0x9,
  230. Local_x2APIC_NMI = 0xA,
  231. GIC_CPU = 0xB,
  232. GIC_Distributor = 0xC,
  233. GIC_MSI = 0xD,
  234. GIC_Redistrbutor = 0xE,
  235. GIC_Interrupt_Translation = 0xF
  236. };
  237. struct [[gnu::packed]] MADTEntryHeader {
  238. u8 type;
  239. u8 length;
  240. };
  241. namespace MADTEntries {
  242. // https://uefi.org/specs/ACPI/6.4/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#i-o-apic-structure
  243. struct [[gnu::packed]] IOAPIC {
  244. MADTEntryHeader h;
  245. u8 ioapic_id;
  246. u8 reserved;
  247. u32 ioapic_address;
  248. u32 gsi_base;
  249. };
  250. // https://uefi.org/specs/ACPI/6.4/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#processor-local-apic-structure
  251. struct [[gnu::packed]] ProcessorLocalAPIC {
  252. MADTEntryHeader h;
  253. u8 acpi_processor_id;
  254. u8 apic_id;
  255. u32 flags;
  256. };
  257. // https://uefi.org/specs/ACPI/6.4/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#processor-local-x2apic-structure
  258. struct [[gnu::packed]] ProcessorLocalX2APIC {
  259. MADTEntryHeader h;
  260. u16 reserved;
  261. u32 apic_id;
  262. u32 flags;
  263. u32 acpi_processor_id;
  264. };
  265. // https://uefi.org/specs/ACPI/6.4/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#interrupt-source-override-structure
  266. struct [[gnu::packed]] InterruptSourceOverride {
  267. MADTEntryHeader h;
  268. u8 bus;
  269. u8 source;
  270. u32 global_system_interrupt;
  271. u16 flags;
  272. };
  273. }
  274. // https://uefi.org/specs/ACPI/6.4/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#multiple-apic-description-table-madt-format
  275. struct [[gnu::packed]] MADT {
  276. SDTHeader h;
  277. u32 lapic_address;
  278. u32 flags;
  279. MADTEntryHeader entries[];
  280. };
  281. struct [[gnu::packed]] AMLTable {
  282. SDTHeader h;
  283. char aml_code[];
  284. };
  285. struct [[gnu::packed]] PCI_MMIO_Descriptor {
  286. u64 base_addr;
  287. u16 seg_group_number;
  288. u8 start_pci_bus;
  289. u8 end_pci_bus;
  290. u32 reserved;
  291. };
  292. struct [[gnu::packed]] MCFG {
  293. SDTHeader header;
  294. u64 reserved;
  295. PCI_MMIO_Descriptor descriptors[];
  296. };
  297. }
  298. class StaticParser;
  299. class DynamicParser;
  300. class Parser;
  301. namespace StaticParsing {
  302. Optional<PhysicalAddress> find_rsdp();
  303. PhysicalAddress find_table(PhysicalAddress rsdp, const StringView& signature);
  304. }
  305. }