acpi.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Core ACPI (Advanced Configuration and Power Interface) support
  4. *
  5. * Copyright 2019 Google LLC
  6. * Written by Simon Glass <sjg@chromium.org>
  7. */
  8. #ifndef __DM_ACPI_H__
  9. #define __DM_ACPI_H__
  10. /* Allow operations to be optional for ACPI */
  11. #if CONFIG_IS_ENABLED(ACPIGEN)
  12. #define ACPI_OPS_PTR(_ptr) .acpi_ops = _ptr,
  13. #else
  14. #define ACPI_OPS_PTR(_ptr)
  15. #endif
  16. /* Length of an ACPI name string, excluding null terminator */
  17. #define ACPI_NAME_LEN 4
  18. /* Length of an ACPI name string including nul terminator */
  19. #define ACPI_NAME_MAX (ACPI_NAME_LEN + 1)
  20. /* Number of nested objects supported */
  21. #define ACPIGEN_LENSTACK_SIZE 10
  22. #if !defined(__ACPI__)
  23. struct nhlt;
  24. /** enum acpi_dump_option - selects what ACPI information to dump */
  25. enum acpi_dump_option {
  26. ACPI_DUMP_LIST, /* Just the list of items */
  27. ACPI_DUMP_CONTENTS, /* Include the binary contents also */
  28. };
  29. /**
  30. * struct acpi_ctx - Context used for writing ACPI tables
  31. *
  32. * This contains a few useful pieces of information used when writing
  33. *
  34. * @base: Base address of ACPI tables
  35. * @current: Current address for writing
  36. * @rsdp: Pointer to the Root System Description Pointer, typically used when
  37. * adding a new table. The RSDP holds pointers to the RSDT and XSDT.
  38. * @rsdt: Pointer to the Root System Description Table
  39. * @xsdt: Pointer to the Extended System Description Table
  40. * @nhlt: Intel Non-High-Definition-Audio Link Table (NHLT) pointer, used to
  41. * build up information that audio codecs need to provide in the NHLT ACPI
  42. * table
  43. * @len_stack: Stack of 'length' words to fix up later
  44. * @ltop: Points to current top of stack (0 = empty)
  45. */
  46. struct acpi_ctx {
  47. void *base;
  48. void *current;
  49. struct acpi_rsdp *rsdp;
  50. struct acpi_rsdt *rsdt;
  51. struct acpi_xsdt *xsdt;
  52. struct nhlt *nhlt;
  53. char *len_stack[ACPIGEN_LENSTACK_SIZE];
  54. int ltop;
  55. };
  56. /**
  57. * struct acpi_ops - ACPI operations supported by driver model
  58. */
  59. struct acpi_ops {
  60. /**
  61. * get_name() - Obtain the ACPI name of a device
  62. *
  63. * @dev: Device to check
  64. * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
  65. * bytes
  66. * @return 0 if OK, -ENOENT if no name is available, other -ve value on
  67. * other error
  68. */
  69. int (*get_name)(const struct udevice *dev, char *out_name);
  70. /**
  71. * write_tables() - Write out any tables required by this device
  72. *
  73. * @dev: Device to write
  74. * @ctx: ACPI context to use
  75. * @return 0 if OK, -ve on error
  76. */
  77. int (*write_tables)(const struct udevice *dev, struct acpi_ctx *ctx);
  78. /**
  79. * fill_ssdt() - Generate SSDT code for a device
  80. *
  81. * This is called to create the SSDT code. The method should write out
  82. * whatever ACPI code is needed by this device. It will end up in the
  83. * SSDT table.
  84. *
  85. * Note that this is called 'fill' because the entire contents of the
  86. * SSDT is build by calling this method on all devices.
  87. *
  88. * @dev: Device to write
  89. * @ctx: ACPI context to use
  90. * @return 0 if OK, -ve on error
  91. */
  92. int (*fill_ssdt)(const struct udevice *dev, struct acpi_ctx *ctx);
  93. /**
  94. * inject_dsdt() - Generate DSDT code for a device
  95. *
  96. * This is called to create the DSDT code. The method should write out
  97. * whatever ACPI code is needed by this device. It will end up in the
  98. * DSDT table.
  99. *
  100. * Note that this is called 'inject' because the output of calling this
  101. * method on all devices is injected into the DSDT, the bulk of which
  102. * is written in .asl files for the board.
  103. *
  104. * @dev: Device to write
  105. * @ctx: ACPI context to use
  106. * @return 0 if OK, -ve on error
  107. */
  108. int (*inject_dsdt)(const struct udevice *dev, struct acpi_ctx *ctx);
  109. /**
  110. * setup_nhlt() - Set up audio information for this device
  111. *
  112. * The method can add information to ctx->nhlt if it likes
  113. *
  114. * @return 0 if OK, -ENODATA if nothing to add, -ve on error
  115. */
  116. int (*setup_nhlt)(const struct udevice *dev, struct acpi_ctx *ctx);
  117. };
  118. #define device_get_acpi_ops(dev) ((dev)->driver->acpi_ops)
  119. /**
  120. * acpi_get_name() - Obtain the ACPI name of a device
  121. *
  122. * @dev: Device to check
  123. * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
  124. * bytes
  125. * @return 0 if OK, -ENOENT if no name is available, other -ve value on
  126. * other error
  127. */
  128. int acpi_get_name(const struct udevice *dev, char *out_name);
  129. /**
  130. * acpi_copy_name() - Copy an ACPI name to an output buffer
  131. *
  132. * This convenience function can be used to return a literal string as a name
  133. * in functions that implement the get_name() method.
  134. *
  135. * For example:
  136. *
  137. * static int mydev_get_name(const struct udevice *dev, char *out_name)
  138. * {
  139. * return acpi_copy_name(out_name, "WIBB");
  140. * }
  141. *
  142. * @out_name: Place to put the name
  143. * @name: Name to copy
  144. * @return 0 (always)
  145. */
  146. int acpi_copy_name(char *out_name, const char *name);
  147. /**
  148. * acpi_write_dev_tables() - Write ACPI tables required by devices
  149. *
  150. * This scans through all devices and tells them to write any tables they want
  151. * to write.
  152. *
  153. * @return 0 if OK, -ve if any device returned an error
  154. */
  155. int acpi_write_dev_tables(struct acpi_ctx *ctx);
  156. /**
  157. * acpi_fill_ssdt() - Generate ACPI tables for SSDT
  158. *
  159. * This is called to create the SSDT code for all devices.
  160. *
  161. * @ctx: ACPI context to use
  162. * @return 0 if OK, -ve on error
  163. */
  164. int acpi_fill_ssdt(struct acpi_ctx *ctx);
  165. /**
  166. * acpi_inject_dsdt() - Generate ACPI tables for DSDT
  167. *
  168. * This is called to create the DSDT code for all devices.
  169. *
  170. * @ctx: ACPI context to use
  171. * @return 0 if OK, -ve on error
  172. */
  173. int acpi_inject_dsdt(struct acpi_ctx *ctx);
  174. /**
  175. * acpi_setup_nhlt() - Set up audio information
  176. *
  177. * This is called to set up the nhlt information for all devices.
  178. *
  179. * @ctx: ACPI context to use
  180. * @nhlt: Pointer to nhlt information to add to
  181. * @return 0 if OK, -ve on error
  182. */
  183. int acpi_setup_nhlt(struct acpi_ctx *ctx, struct nhlt *nhlt);
  184. /**
  185. * acpi_dump_items() - Dump out the collected ACPI items
  186. *
  187. * This lists the ACPI DSDT and SSDT items generated by the various U-Boot
  188. * drivers.
  189. *
  190. * @option: Sets what should be dumpyed
  191. */
  192. void acpi_dump_items(enum acpi_dump_option option);
  193. /**
  194. * acpi_get_path() - Get the full ACPI path for a device
  195. *
  196. * This checks for any override in the device tree and calls acpi_device_path()
  197. * if not
  198. *
  199. * @dev: Device to check
  200. * @out_path: Buffer to place the path in (should be ACPI_PATH_MAX long)
  201. * @maxlen: Size of buffer (typically ACPI_PATH_MAX)
  202. * @return 0 if OK, -ve on error
  203. */
  204. int acpi_get_path(const struct udevice *dev, char *out_path, int maxlen);
  205. /**
  206. * acpi_reset_items() - Reset the list of ACPI items to empty
  207. *
  208. * This list keeps track of DSDT and SSDT items that are generated
  209. * programmatically. The 'acpi items' command shows the list. Use this function
  210. * to empty the list, before writing new items.
  211. */
  212. void acpi_reset_items(void);
  213. #endif /* __ACPI__ */
  214. #endif