acpi.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /**
  2. * 解析acpi信息的模块
  3. **/
  4. #pragma once
  5. #include "../../common/glib.h"
  6. #include "../../mm/mm.h"
  7. #define ACPI_ICS_TYPE_PROCESSOR_LOCAL_APIC 0
  8. #define ACPI_ICS_TYPE_IO_APIC 1
  9. #define ACPI_ICS_TYPE_INTERRUPT_SOURCE_OVERRIDE 2
  10. #define ACPI_ICS_TYPE_NMI_SOURCE 3
  11. #define ACPI_ICS_TYPE_LOCAL_APIC_NMI 4
  12. #define ACPI_ICS_TYPE_LOCAL_APIC_ADDRESS_OVERRIDE 5
  13. #define ACPI_ICS_TYPE_IO_SAPIC 6
  14. #define ACPI_ICS_TYPE_LOCAL_SAPIC 7
  15. #define ACPI_ICS_TYPE_PLATFORM_INTERRUPT_SOURCES 8
  16. #define ACPI_ICS_TYPE_PROCESSOR_LOCAL_x2APIC 9
  17. #define ACPI_ICS_TYPE_PROCESSOR_LOCAL_x2APIC_NMI 0xA
  18. #define ACPI_ICS_TYPE_PROCESSOR_GICC 0xB
  19. #define ACPI_ICS_TYPE_PROCESSOR_GICD 0xC
  20. #define ACPI_ICS_TYPE_PROCESSOR_GIC_MSI_Frame 0xD
  21. #define ACPI_ICS_TYPE_PROCESSOR_GICR 0xE
  22. #define ACPI_ICS_TYPE_PROCESSOR_GIC_ITS 0xF
  23. // 0x10-0x7f Reserved. OSPM skips structures of the reserved type.
  24. // 0x80-0xff Reserved for OEM use
  25. #define ACPI_RSDT_VIRT_ADDR_BASE SPECIAL_MEMOEY_MAPPING_VIRT_ADDR_BASE + ACPI_RSDT_MAPPING_OFFSET
  26. #define ACPI_XSDT_VIRT_ADDR_BASE SPECIAL_MEMOEY_MAPPING_VIRT_ADDR_BASE + ACPI_XSDT_MAPPING_OFFSET
  27. #define ACPI_DESCRIPTION_HEDERS_BASE ACPI_RSDT_VIRT_ADDR_BASE + (PAGE_2M_SIZE)
  28. #define ACPI_XSDT_DESCRIPTION_HEDERS_BASE ACPI_XSDT_VIRT_ADDR_BASE + (PAGE_2M_SIZE)
  29. bool acpi_use_xsdt = false;
  30. struct acpi_RSDP_t
  31. {
  32. unsigned char Signature[8];
  33. unsigned char Checksum;
  34. unsigned char OEMID[6];
  35. unsigned char Revision;
  36. // 32bit physical address of the RSDT
  37. uint RsdtAddress;
  38. };
  39. struct acpi_RSDP_2_t
  40. {
  41. struct acpi_RSDP_t rsdp1;
  42. // fields below are only valid when the revision value is 2 or above
  43. // 表的长度(单位:字节)从offset=0开始算
  44. uint Length;
  45. // 64bit的XSDT的物理地址
  46. ul XsdtAddress;
  47. unsigned char ExtendedChecksum; // 整个表的checksum,包括了之前的checksum区域
  48. unsigned char Reserved[3];
  49. };
  50. struct acpi_system_description_table_header_t
  51. {
  52. // The ascii string representation of the table header.
  53. unsigned char Signature[4];
  54. // 整个表的长度(单位:字节),包括了header,从偏移量0处开始
  55. uint Length;
  56. // The revision of the structure corresponding to the signature field for this table.
  57. unsigned char Revision;
  58. // The entire table, including the checksum field, must add to zero to be considered valid.
  59. char Checksum;
  60. unsigned char OEMID[6];
  61. unsigned char OEM_Table_ID[8];
  62. uint OEMRevision;
  63. uint CreatorID;
  64. uint CreatorRevision;
  65. };
  66. // =========== MADT结构,其中Signature为APIC ============
  67. struct acpi_Multiple_APIC_Description_Table_t
  68. {
  69. struct acpi_system_description_table_header_t header;
  70. // 32bit的,每个处理器可访问的local中断控制器的物理地址
  71. uint Local_Interrupt_Controller_Address;
  72. // Multiple APIC flags, 详见 ACPI Specification Version 6.3, Table 5-44
  73. uint flags;
  74. // 接下来的(length-44)字节是Interrupt Controller Structure
  75. };
  76. struct apic_Interrupt_Controller_Structure_header_t
  77. {
  78. unsigned char type;
  79. unsigned char length;
  80. };
  81. struct acpi_Processor_Local_APIC_Structure_t
  82. {
  83. // type=0
  84. struct apic_Interrupt_Controller_Structure_header_t header;
  85. unsigned char ACPI_Processor_UID;
  86. // 处理器的local apic id
  87. unsigned char ACPI_ID;
  88. //详见 ACPI Specification Version 6.3, Table 5-47
  89. uint flags;
  90. };
  91. struct acpi_IO_APIC_Structure_t
  92. {
  93. // type=1
  94. struct apic_Interrupt_Controller_Structure_header_t header;
  95. unsigned char IO_APIC_ID;
  96. unsigned char Reserved;
  97. // 32bit的IO APIC物理地址 (每个IO APIC都有一个独立的物理地址)
  98. uint IO_APIC_Address;
  99. // 当前IO APIC的全局系统中断向量号起始值
  100. // The number of intr inputs is determined by the IO APIC's Max Redir Entry register.
  101. uint Global_System_Interrupt_Base;
  102. };
  103. // =========== RSDT 结构 =============
  104. struct acpi_RSDT_Structure_t
  105. {
  106. // 通过RSDT的header->Length可以计算出entry的数量n
  107. // n = (length - 32)/4
  108. struct acpi_system_description_table_header_t header;
  109. // 一个包含了n个32bit物理地址的数组,指向了其他的description headers
  110. uint Entry;
  111. };
  112. // =========== XSDT 结构 =============
  113. struct acpi_XSDT_Structure_t
  114. {
  115. // 通过RSDT的header->Length可以计算出entry的数量n
  116. // n = (length - 36)/8
  117. struct acpi_system_description_table_header_t header;
  118. // 一个包含了n个64bit物理地址的数组,指向了其他的description headers
  119. ul Entry;
  120. };
  121. /**
  122. * @brief 迭代器,用于迭代描述符头(位于ACPI标准文件的Table 5-29)
  123. * @param _fun 迭代操作调用的函数
  124. * @param _data 数据
  125. */
  126. void acpi_iter_SDT(bool (*_fun)(const struct acpi_system_description_table_header_t *, void *),
  127. void *_data);
  128. /**
  129. * @brief 获取MADT信息 Multiple APIC Description Table
  130. *
  131. * @param _iter_data 要被迭代的信息的结构体
  132. * @param _data 返回的MADT的虚拟地址
  133. * @param count 返回数组的长度
  134. * @return true
  135. * @return false
  136. */
  137. bool acpi_get_MADT(const struct acpi_system_description_table_header_t *_iter_data, void *_data);
  138. // 初始化acpi模块
  139. void acpi_init();