acpi.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 nul 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. #if !defined(__ACPI__)
  21. /**
  22. * struct acpi_ctx - Context used for writing ACPI tables
  23. *
  24. * This contains a few useful pieces of information used when writing
  25. *
  26. * @current: Current address for writing
  27. * @rsdp: Pointer to the Root System Description Pointer, typically used when
  28. * adding a new table. The RSDP holds pointers to the RSDT and XSDT.
  29. * @rsdt: Pointer to the Root System Description Table
  30. * @xsdt: Pointer to the Extended System Description Table
  31. */
  32. struct acpi_ctx {
  33. void *current;
  34. struct acpi_rsdp *rsdp;
  35. struct acpi_rsdt *rsdt;
  36. struct acpi_xsdt *xsdt;
  37. };
  38. /**
  39. * struct acpi_ops - ACPI operations supported by driver model
  40. */
  41. struct acpi_ops {
  42. /**
  43. * get_name() - Obtain the ACPI name of a device
  44. *
  45. * @dev: Device to check
  46. * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
  47. * bytes
  48. * @return 0 if OK, -ENOENT if no name is available, other -ve value on
  49. * other error
  50. */
  51. int (*get_name)(const struct udevice *dev, char *out_name);
  52. /**
  53. * write_tables() - Write out any tables required by this device
  54. *
  55. * @dev: Device to write
  56. * @ctx: ACPI context to use
  57. * @return 0 if OK, -ve on error
  58. */
  59. int (*write_tables)(const struct udevice *dev, struct acpi_ctx *ctx);
  60. };
  61. #define device_get_acpi_ops(dev) ((dev)->driver->acpi_ops)
  62. /**
  63. * acpi_get_name() - Obtain the ACPI name of a device
  64. *
  65. * @dev: Device to check
  66. * @out_name: Place to put the name, must hold at least ACPI_NAME_MAX
  67. * bytes
  68. * @return 0 if OK, -ENOENT if no name is available, other -ve value on
  69. * other error
  70. */
  71. int acpi_get_name(const struct udevice *dev, char *out_name);
  72. /**
  73. * acpi_copy_name() - Copy an ACPI name to an output buffer
  74. *
  75. * This convenience function can be used to return a literal string as a name
  76. * in functions that implement the get_name() method.
  77. *
  78. * For example:
  79. *
  80. * static int mydev_get_name(const struct udevice *dev, char *out_name)
  81. * {
  82. * return acpi_copy_name(out_name, "WIBB");
  83. * }
  84. *
  85. * @out_name: Place to put the name
  86. * @name: Name to copy
  87. * @return 0 (always)
  88. */
  89. int acpi_copy_name(char *out_name, const char *name);
  90. /**
  91. * acpi_write_dev_tables() - Write ACPI tables required by devices
  92. *
  93. * This scans through all devices and tells them to write any tables they want
  94. * to write.
  95. *
  96. * @return 0 if OK, -ve if any device returned an error
  97. */
  98. int acpi_write_dev_tables(struct acpi_ctx *ctx);
  99. #endif /* __ACPI__ */
  100. #endif