acpi.h 5.3 KB

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