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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. } __attribute__ (( packed ));
  110. /** ACPI PM1 Control Register (within PM1a_CNT_BLK or PM1A_CNT_BLK) */
  111. #define ACPI_PM1_CNT 0
  112. #define ACPI_PM1_CNT_SLP_TYP(x) ( (x) << 10 ) /**< Sleep type */
  113. #define ACPI_PM1_CNT_SLP_EN ( 1 << 13 ) /**< Sleep enable */
  114. /** Differentiated System Description Table (DSDT) signature */
  115. #define DSDT_SIGNATURE ACPI_SIGNATURE ( 'D', 'S', 'D', 'T' )
  116. /** Secondary System Description Table (SSDT) signature */
  117. #define SSDT_SIGNATURE ACPI_SIGNATURE ( 'S', 'S', 'D', 'T' )
  118. /** An ACPI descriptor (used to construct ACPI tables) */
  119. struct acpi_descriptor {
  120. /** Reference count of containing object */
  121. struct refcnt *refcnt;
  122. /** Table model */
  123. struct acpi_model *model;
  124. /** List of ACPI descriptors for this model */
  125. struct list_head list;
  126. };
  127. /**
  128. * Initialise ACPI descriptor
  129. *
  130. * @v desc ACPI descriptor
  131. * @v model Table model
  132. * @v refcnt Reference count
  133. */
  134. static inline __attribute__ (( always_inline )) void
  135. acpi_init ( struct acpi_descriptor *desc, struct acpi_model *model,
  136. struct refcnt *refcnt ) {
  137. desc->refcnt = refcnt;
  138. desc->model = model;
  139. INIT_LIST_HEAD ( &desc->list );
  140. }
  141. /** An ACPI table model */
  142. struct acpi_model {
  143. /** List of descriptors */
  144. struct list_head descs;
  145. /**
  146. * Check if ACPI descriptor is complete
  147. *
  148. * @v desc ACPI descriptor
  149. * @ret rc Return status code
  150. */
  151. int ( * complete ) ( struct acpi_descriptor *desc );
  152. /**
  153. * Install ACPI tables
  154. *
  155. * @v install Installation method
  156. * @ret rc Return status code
  157. */
  158. int ( * install ) ( int ( * install ) ( struct acpi_header *acpi ) );
  159. };
  160. /** ACPI models */
  161. #define ACPI_MODELS __table ( struct acpi_model, "acpi_models" )
  162. /** Declare an ACPI model */
  163. #define __acpi_model __table_entry ( ACPI_MODELS, 01 )
  164. /**
  165. * Calculate static inline ACPI API function name
  166. *
  167. * @v _prefix Subsystem prefix
  168. * @v _api_func API function
  169. * @ret _subsys_func Subsystem API function
  170. */
  171. #define ACPI_INLINE( _subsys, _api_func ) \
  172. SINGLE_API_INLINE ( ACPI_PREFIX_ ## _subsys, _api_func )
  173. /**
  174. * Provide an ACPI API implementation
  175. *
  176. * @v _prefix Subsystem prefix
  177. * @v _api_func API function
  178. * @v _func Implementing function
  179. */
  180. #define PROVIDE_ACPI( _subsys, _api_func, _func ) \
  181. PROVIDE_SINGLE_API ( ACPI_PREFIX_ ## _subsys, _api_func, _func )
  182. /**
  183. * Provide a static inline ACPI API implementation
  184. *
  185. * @v _prefix Subsystem prefix
  186. * @v _api_func API function
  187. */
  188. #define PROVIDE_ACPI_INLINE( _subsys, _api_func ) \
  189. PROVIDE_SINGLE_API_INLINE ( ACPI_PREFIX_ ## _subsys, _api_func )
  190. /* Include all architecture-independent ACPI API headers */
  191. #include <ipxe/null_acpi.h>
  192. /* Include all architecture-dependent ACPI API headers */
  193. #include <bits/acpi.h>
  194. /**
  195. * Locate ACPI root system description table
  196. *
  197. * @ret rsdt ACPI root system description table, or UNULL
  198. */
  199. userptr_t acpi_find_rsdt ( void );
  200. extern struct acpi_descriptor *
  201. acpi_describe ( struct interface *interface );
  202. #define acpi_describe_TYPE( object_type ) \
  203. typeof ( struct acpi_descriptor * ( object_type ) )
  204. extern void acpi_fix_checksum ( struct acpi_header *acpi );
  205. extern userptr_t acpi_find ( uint32_t signature, unsigned int index );
  206. extern int acpi_sx ( uint32_t signature );
  207. extern void acpi_add ( struct acpi_descriptor *desc );
  208. extern void acpi_del ( struct acpi_descriptor *desc );
  209. extern int acpi_install ( int ( * install ) ( struct acpi_header *acpi ) );
  210. #endif /* _IPXE_ACPI_H */