nhlt.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright(c) 2023-2024 Intel Corporation
  4. *
  5. * Authors: Cezary Rojewski <cezary.rojewski@intel.com>
  6. * Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com>
  7. */
  8. #ifndef __ACPI_NHLT_H__
  9. #define __ACPI_NHLT_H__
  10. #include <linux/acpi.h>
  11. #include <linux/kconfig.h>
  12. #include <linux/overflow.h>
  13. #include <linux/types.h>
  14. #define __acpi_nhlt_endpoint_config(ep) ((void *)((ep) + 1))
  15. #define __acpi_nhlt_config_caps(cfg) ((void *)((cfg) + 1))
  16. /**
  17. * acpi_nhlt_endpoint_fmtscfg - Get the formats configuration space.
  18. * @ep: the endpoint to retrieve the space for.
  19. *
  20. * Return: A pointer to the formats configuration space.
  21. */
  22. static inline struct acpi_nhlt_formats_config *
  23. acpi_nhlt_endpoint_fmtscfg(const struct acpi_nhlt_endpoint *ep)
  24. {
  25. struct acpi_nhlt_config *cfg = __acpi_nhlt_endpoint_config(ep);
  26. return (struct acpi_nhlt_formats_config *)((u8 *)(cfg + 1) + cfg->capabilities_size);
  27. }
  28. #define __acpi_nhlt_first_endpoint(tb) \
  29. ((void *)(tb + 1))
  30. #define __acpi_nhlt_next_endpoint(ep) \
  31. ((void *)((u8 *)(ep) + (ep)->length))
  32. #define __acpi_nhlt_get_endpoint(tb, ep, i) \
  33. ((i) ? __acpi_nhlt_next_endpoint(ep) : __acpi_nhlt_first_endpoint(tb))
  34. #define __acpi_nhlt_first_fmtcfg(fmts) \
  35. ((void *)(fmts + 1))
  36. #define __acpi_nhlt_next_fmtcfg(fmt) \
  37. ((void *)((u8 *)((fmt) + 1) + (fmt)->config.capabilities_size))
  38. #define __acpi_nhlt_get_fmtcfg(fmts, fmt, i) \
  39. ((i) ? __acpi_nhlt_next_fmtcfg(fmt) : __acpi_nhlt_first_fmtcfg(fmts))
  40. /*
  41. * The for_each_nhlt_*() macros rely on an iterator to deal with the
  42. * variable length of each endpoint structure and the possible presence
  43. * of an OED-Config used by Windows only.
  44. */
  45. /**
  46. * for_each_nhlt_endpoint - Iterate over endpoints in a NHLT table.
  47. * @tb: the pointer to a NHLT table.
  48. * @ep: the pointer to endpoint to use as loop cursor.
  49. */
  50. #define for_each_nhlt_endpoint(tb, ep) \
  51. for (unsigned int __i = 0; \
  52. __i < (tb)->endpoints_count && \
  53. (ep = __acpi_nhlt_get_endpoint(tb, ep, __i)); \
  54. __i++)
  55. /**
  56. * for_each_nhlt_fmtcfg - Iterate over format configurations.
  57. * @fmts: the pointer to formats configuration space.
  58. * @fmt: the pointer to format to use as loop cursor.
  59. */
  60. #define for_each_nhlt_fmtcfg(fmts, fmt) \
  61. for (unsigned int __i = 0; \
  62. __i < (fmts)->formats_count && \
  63. (fmt = __acpi_nhlt_get_fmtcfg(fmts, fmt, __i)); \
  64. __i++)
  65. /**
  66. * for_each_nhlt_endpoint_fmtcfg - Iterate over format configurations in an endpoint.
  67. * @ep: the pointer to an endpoint.
  68. * @fmt: the pointer to format to use as loop cursor.
  69. */
  70. #define for_each_nhlt_endpoint_fmtcfg(ep, fmt) \
  71. for_each_nhlt_fmtcfg(acpi_nhlt_endpoint_fmtscfg(ep), fmt)
  72. #if IS_ENABLED(CONFIG_ACPI_NHLT)
  73. /*
  74. * System-wide pointer to the first NHLT table.
  75. *
  76. * A sound driver may utilize acpi_nhlt_get/put_gbl_table() on its
  77. * initialization and removal respectively to avoid excessive mapping
  78. * and unmapping of the memory occupied by the table between streaming
  79. * operations.
  80. */
  81. acpi_status acpi_nhlt_get_gbl_table(void);
  82. void acpi_nhlt_put_gbl_table(void);
  83. bool acpi_nhlt_endpoint_match(const struct acpi_nhlt_endpoint *ep,
  84. int link_type, int dev_type, int dir, int bus_id);
  85. struct acpi_nhlt_endpoint *
  86. acpi_nhlt_tb_find_endpoint(const struct acpi_table_nhlt *tb,
  87. int link_type, int dev_type, int dir, int bus_id);
  88. struct acpi_nhlt_endpoint *
  89. acpi_nhlt_find_endpoint(int link_type, int dev_type, int dir, int bus_id);
  90. struct acpi_nhlt_format_config *
  91. acpi_nhlt_endpoint_find_fmtcfg(const struct acpi_nhlt_endpoint *ep,
  92. u16 ch, u32 rate, u16 vbps, u16 bps);
  93. struct acpi_nhlt_format_config *
  94. acpi_nhlt_tb_find_fmtcfg(const struct acpi_table_nhlt *tb,
  95. int link_type, int dev_type, int dir, int bus_id,
  96. u16 ch, u32 rate, u16 vpbs, u16 bps);
  97. struct acpi_nhlt_format_config *
  98. acpi_nhlt_find_fmtcfg(int link_type, int dev_type, int dir, int bus_id,
  99. u16 ch, u32 rate, u16 vpbs, u16 bps);
  100. int acpi_nhlt_endpoint_mic_count(const struct acpi_nhlt_endpoint *ep);
  101. #else /* !CONFIG_ACPI_NHLT */
  102. static inline acpi_status acpi_nhlt_get_gbl_table(void)
  103. {
  104. return AE_NOT_FOUND;
  105. }
  106. static inline void acpi_nhlt_put_gbl_table(void)
  107. {
  108. }
  109. static inline bool
  110. acpi_nhlt_endpoint_match(const struct acpi_nhlt_endpoint *ep,
  111. int link_type, int dev_type, int dir, int bus_id)
  112. {
  113. return false;
  114. }
  115. static inline struct acpi_nhlt_endpoint *
  116. acpi_nhlt_tb_find_endpoint(const struct acpi_table_nhlt *tb,
  117. int link_type, int dev_type, int dir, int bus_id)
  118. {
  119. return NULL;
  120. }
  121. static inline struct acpi_nhlt_format_config *
  122. acpi_nhlt_endpoint_find_fmtcfg(const struct acpi_nhlt_endpoint *ep,
  123. u16 ch, u32 rate, u16 vbps, u16 bps)
  124. {
  125. return NULL;
  126. }
  127. static inline struct acpi_nhlt_format_config *
  128. acpi_nhlt_tb_find_fmtcfg(const struct acpi_table_nhlt *tb,
  129. int link_type, int dev_type, int dir, int bus_id,
  130. u16 ch, u32 rate, u16 vpbs, u16 bps)
  131. {
  132. return NULL;
  133. }
  134. static inline int acpi_nhlt_endpoint_mic_count(const struct acpi_nhlt_endpoint *ep)
  135. {
  136. return 0;
  137. }
  138. static inline struct acpi_nhlt_endpoint *
  139. acpi_nhlt_find_endpoint(int link_type, int dev_type, int dir, int bus_id)
  140. {
  141. return NULL;
  142. }
  143. static inline struct acpi_nhlt_format_config *
  144. acpi_nhlt_find_fmtcfg(int link_type, int dev_type, int dir, int bus_id,
  145. u16 ch, u32 rate, u16 vpbs, u16 bps)
  146. {
  147. return NULL;
  148. }
  149. #endif /* CONFIG_ACPI_NHLT */
  150. #endif /* __ACPI_NHLT_H__ */