You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

acpi.h 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. #ifndef _IPXE_ACPI_H
  2. #define _IPXE_ACPI_H
  3. /** @file
  4. *
  5. * ACPI data structures
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <stdint.h>
  10. #include <byteswap.h>
  11. #include <ipxe/refcnt.h>
  12. #include <ipxe/list.h>
  13. #include <ipxe/interface.h>
  14. #include <ipxe/uaccess.h>
  15. #include <ipxe/tables.h>
  16. #include <ipxe/api.h>
  17. #include <config/general.h>
  18. /**
  19. * An ACPI description header
  20. *
  21. * This is the structure common to the start of all ACPI system
  22. * description tables.
  23. */
  24. struct acpi_header {
  25. /** ACPI signature (4 ASCII characters) */
  26. uint32_t signature;
  27. /** Length of table, in bytes, including header */
  28. uint32_t length;
  29. /** ACPI Specification minor version number */
  30. uint8_t revision;
  31. /** To make sum of entire table == 0 */
  32. uint8_t checksum;
  33. /** OEM identification */
  34. char oem_id[6];
  35. /** OEM table identification */
  36. char oem_table_id[8];
  37. /** OEM revision number */
  38. uint32_t oem_revision;
  39. /** ASL compiler vendor ID */
  40. char asl_compiler_id[4];
  41. /** ASL compiler revision number */
  42. uint32_t asl_compiler_revision;
  43. } __attribute__ (( packed ));
  44. /**
  45. * Transcribe ACPI table signature (for debugging)
  46. *
  47. * @v signature ACPI table signature
  48. * @ret name ACPI table signature name
  49. */
  50. static inline const char * acpi_name ( uint32_t signature ) {
  51. static union {
  52. uint32_t signature;
  53. char name[5];
  54. } u;
  55. u.signature = cpu_to_le32 ( signature );
  56. return u.name;
  57. }
  58. /**
  59. * Build ACPI signature
  60. *
  61. * @v a First character of ACPI signature
  62. * @v b Second character of ACPI signature
  63. * @v c Third character of ACPI signature
  64. * @v d Fourth character of ACPI signature
  65. * @ret signature ACPI signature
  66. */
  67. #define ACPI_SIGNATURE( a, b, c, d ) \
  68. ( ( (a) << 0 ) | ( (b) << 8 ) | ( (c) << 16 ) | ( (d) << 24 ) )
  69. /** Root System Description Pointer signature */
  70. #define RSDP_SIGNATURE { 'R', 'S', 'D', ' ', 'P', 'T', 'R', ' ' }
  71. /** Root System Description Pointer */
  72. struct acpi_rsdp {
  73. /** Signature */
  74. char signature[8];
  75. /** To make sum of entire table == 0 */
  76. uint8_t checksum;
  77. /** OEM identification */
  78. char oem_id[6];
  79. /** Revision */
  80. uint8_t revision;
  81. /** Physical address of RSDT */
  82. uint32_t rsdt;
  83. } __attribute__ (( packed ));
  84. /** Root System Description Table (RSDT) signature */
  85. #define RSDT_SIGNATURE ACPI_SIGNATURE ( 'R', 'S', 'D', 'T' )
  86. /** ACPI Root System Description Table (RSDT) */
  87. struct acpi_rsdt {
  88. /** ACPI header */
  89. struct acpi_header acpi;
  90. /** ACPI table entries */
  91. uint32_t entry[0];
  92. } __attribute__ (( packed ));
  93. /** Fixed ACPI Description Table (FADT) signature */
  94. #define FADT_SIGNATURE ACPI_SIGNATURE ( 'F', 'A', 'C', 'P' )
  95. /** Fixed ACPI Description Table (FADT) */
  96. struct acpi_fadt {
  97. /** ACPI header */
  98. struct acpi_header acpi;
  99. /** Physical address of FACS */
  100. uint32_t facs;
  101. /** Physical address of DSDT */
  102. uint32_t dsdt;
  103. /** Unused by iPXE */
  104. uint8_t unused[20];
  105. /** PM1a Control Register Block */
  106. uint32_t pm1a_cnt_blk;
  107. /** PM1b Control Register Block */
  108. uint32_t pm1b_cnt_blk;
  109. /** PM2 Control Register Block */
  110. uint32_t pm2_cnt_blk;
  111. /** PM Timer Control Register Block */
  112. uint32_t pm_tmr_blk;
  113. } __attribute__ (( packed ));
  114. /** ACPI PM1 Control Register (within PM1a_CNT_BLK or PM1A_CNT_BLK) */
  115. #define ACPI_PM1_CNT 0
  116. #define ACPI_PM1_CNT_SLP_TYP(x) ( (x) << 10 ) /**< Sleep type */
  117. #define ACPI_PM1_CNT_SLP_EN ( 1 << 13 ) /**< Sleep enable */
  118. /** ACPI PM Timer Register (within PM_TMR_BLK) */
  119. #define ACPI_PM_TMR 0
  120. /** Differentiated System Description Table (DSDT) signature */
  121. #define DSDT_SIGNATURE ACPI_SIGNATURE ( 'D', 'S', 'D', 'T' )
  122. /** Secondary System Description Table (SSDT) signature */
  123. #define SSDT_SIGNATURE ACPI_SIGNATURE ( 'S', 'S', 'D', 'T' )
  124. /** An ACPI descriptor (used to construct ACPI tables) */
  125. struct acpi_descriptor {
  126. /** Reference count of containing object */
  127. struct refcnt *refcnt;
  128. /** Table model */
  129. struct acpi_model *model;
  130. /** List of ACPI descriptors for this model */
  131. struct list_head list;
  132. };
  133. /**
  134. * Initialise ACPI descriptor
  135. *
  136. * @v desc ACPI descriptor
  137. * @v model Table model
  138. * @v refcnt Reference count
  139. */
  140. static inline __attribute__ (( always_inline )) void
  141. acpi_init ( struct acpi_descriptor *desc, struct acpi_model *model,
  142. struct refcnt *refcnt ) {
  143. desc->refcnt = refcnt;
  144. desc->model = model;
  145. INIT_LIST_HEAD ( &desc->list );
  146. }
  147. /** An ACPI table model */
  148. struct acpi_model {
  149. /** List of descriptors */
  150. struct list_head descs;
  151. /**
  152. * Check if ACPI descriptor is complete
  153. *
  154. * @v desc ACPI descriptor
  155. * @ret rc Return status code
  156. */
  157. int ( * complete ) ( struct acpi_descriptor *desc );
  158. /**
  159. * Install ACPI tables
  160. *
  161. * @v install Installation method
  162. * @ret rc Return status code
  163. */
  164. int ( * install ) ( int ( * install ) ( struct acpi_header *acpi ) );
  165. };
  166. /** ACPI models */
  167. #define ACPI_MODELS __table ( struct acpi_model, "acpi_models" )
  168. /** Declare an ACPI model */
  169. #define __acpi_model __table_entry ( ACPI_MODELS, 01 )
  170. /**
  171. * Calculate static inline ACPI API function name
  172. *
  173. * @v _prefix Subsystem prefix
  174. * @v _api_func API function
  175. * @ret _subsys_func Subsystem API function
  176. */
  177. #define ACPI_INLINE( _subsys, _api_func ) \
  178. SINGLE_API_INLINE ( ACPI_PREFIX_ ## _subsys, _api_func )
  179. /**
  180. * Provide an ACPI API implementation
  181. *
  182. * @v _prefix Subsystem prefix
  183. * @v _api_func API function
  184. * @v _func Implementing function
  185. */
  186. #define PROVIDE_ACPI( _subsys, _api_func, _func ) \
  187. PROVIDE_SINGLE_API ( ACPI_PREFIX_ ## _subsys, _api_func, _func )
  188. /**
  189. * Provide a static inline ACPI API implementation
  190. *
  191. * @v _prefix Subsystem prefix
  192. * @v _api_func API function
  193. */
  194. #define PROVIDE_ACPI_INLINE( _subsys, _api_func ) \
  195. PROVIDE_SINGLE_API_INLINE ( ACPI_PREFIX_ ## _subsys, _api_func )
  196. /* Include all architecture-independent ACPI API headers */
  197. #include <ipxe/null_acpi.h>
  198. #include <ipxe/efi/efi_acpi.h>
  199. /* Include all architecture-dependent ACPI API headers */
  200. #include <bits/acpi.h>
  201. /**
  202. * Locate ACPI root system description table
  203. *
  204. * @ret rsdt ACPI root system description table, or UNULL
  205. */
  206. userptr_t acpi_find_rsdt ( void );
  207. extern struct acpi_descriptor *
  208. acpi_describe ( struct interface *interface );
  209. #define acpi_describe_TYPE( object_type ) \
  210. typeof ( struct acpi_descriptor * ( object_type ) )
  211. extern void acpi_fix_checksum ( struct acpi_header *acpi );
  212. extern userptr_t acpi_find ( uint32_t signature, unsigned int index );
  213. extern int acpi_sx ( uint32_t signature );
  214. extern void acpi_add ( struct acpi_descriptor *desc );
  215. extern void acpi_del ( struct acpi_descriptor *desc );
  216. extern int acpi_install ( int ( * install ) ( struct acpi_header *acpi ) );
  217. #endif /* _IPXE_ACPI_H */