coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
nhlt.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef _NHLT_H_
4 #define _NHLT_H_
5 
6 #include <stdint.h>
7 #include <stddef.h>
8 
9 struct nhlt;
10 struct nhlt_endpoint;
11 struct nhlt_format;
12 struct nhlt_format_config;
13 
14 /*
15  * Non HD Audio ACPI support. This table is typically used for Intel Smart
16  * Sound Technology DSP. It provides a way to encode opaque settings in
17  * the ACPI tables.
18  *
19  * While the structure fields of the NHLT structs are exposed below
20  * the SoC/chipset code should be the only other user manipulating the
21  * fields directly aside from the library itself.
22  *
23  * The NHLT table consists of endpoints which in turn contain different
24  * supporting stream formats. Each endpoint may contain a device specific
25  * configuration payload as well as each stream format.
26  *
27  * Most code should use the SoC variants of the functions because
28  * there is required logic needed to be performed by the SoC. The SoC
29  * code should be abstracting the inner details of these functions that
30  * specically apply to NHLT objects for that SoC.
31  *
32  * An example sequence:
33  *
34  * nhlt = nhlt_init()
35  * ep = nhlt_add_endpoint()
36  * nhlt_endpoint_append_config(ep)
37  * nhlt_endpoint_add_formats(ep)
38  * nhlt_soc_serialize()
39  */
40 
41 /* Obtain an nhlt object for adding endpoints. Returns NULL on error. */
42 struct nhlt *nhlt_init(void);
43 
44 /* Return the size of the NHLT table including ACPI header. */
45 size_t nhlt_current_size(struct nhlt *nhlt);
46 
47 /*
48  * Helper functions for adding NHLT devices utilizing an nhlt_endp_descriptor
49  * to drive the logic.
50  */
51 
53  /* NHLT endpoint types. */
54  int link;
55  int device;
56  int direction;
59  /* Optional endpoint specific configuration data. */
60  const void *cfg;
61  size_t cfg_size;
62  /* Formats supported for endpoint. */
63  const struct nhlt_format_config *formats;
64  size_t num_formats;
65 };
66 
67 /*
68  * Add the number of endpoints described by each descriptor. The virtual bus
69  * id for each descriptor is the default value of 0.
70  * Returns < 0 on error, 0 on success.
71  */
72 int nhlt_add_endpoints(struct nhlt *nhlt,
73  const struct nhlt_endp_descriptor *epds,
74  size_t num_epds);
75 
76 /*
77  * Add the number of endpoints associated with a single NHLT SSP instance id.
78  * Each endpoint described in the endpoint descriptor array uses the provided
79  * virtual bus id. Returns < 0 on error, 0 on success.
80  */
81 int nhlt_add_ssp_endpoints(struct nhlt *nhlt, int virtual_bus_id,
82  const struct nhlt_endp_descriptor *epds, size_t num_epds);
83 
84 /*
85  * Add endpoint to NHLT object. Returns NULL on error.
86  *
87  * generic nhlt_add_endpoint() is called by the SoC code to provide
88  * the specific assumptions/uses for NHLT for that platform. All fields
89  * are the NHLT enumerations found within this header file.
90  */
92  int device_type, int dir,
94 
95 /*
96  * Append blob of configuration to the endpoint proper. Returns 0 on
97  * success, < 0 on error. A copy of the configuration is made so any
98  * resources pointed to by config can be freed after the call.
99  */
100 int nhlt_endpoint_append_config(struct nhlt_endpoint *endpoint,
101  const void *config, size_t config_sz);
102 
103 /* Add a format type to the provided endpoint. Returns NULL on error. */
104 struct nhlt_format *nhlt_add_format(struct nhlt_endpoint *endpoint,
105  int num_channels,
106  int sample_freq_khz,
107  int container_bits_per_sample,
108  int valid_bits_per_sample,
109  uint32_t speaker_mask);
110 
111 /*
112  * Append blob of configuration to the format proper. Returns 0 on
113  * success, < 0 on error. A copy of the configuration is made so any
114  * resources pointed to by config can be freed after the call.
115  */
116 int nhlt_format_append_config(struct nhlt_format *format, const void *config,
117  size_t config_sz);
118 
119 /*
120  * Add num_formats described by formats to the endpoint. This function
121  * effectively wraps nhlt_add_format() and nhlt_format_config() using the
122  * data found in each nhlt_format_config object. Returns 0 on success, < 0
123  * on error.
124  */
125 int nhlt_endpoint_add_formats(struct nhlt_endpoint *endpoint,
126  const struct nhlt_format_config *formats,
127  size_t num_formats);
128 
129 /*
130  * Increment the instance id for a given link type. This function is
131  * used for marking a device being completely added to the NHLT object.
132  * Subsequent endpoints added to the nhlt object with the same link type
133  * will use incremented instance id.
134  */
135 void nhlt_next_instance(struct nhlt *nhlt, int link_type);
136 
137 /*
138  * Serialize NHLT object to ACPI table. Take in the beginning address of where
139  * the table will reside and return the address of the next ACPI table. On
140  * error 0 will be returned. The NHLT object is no longer valid after this
141  * function is called.
142  */
143 uintptr_t nhlt_serialize(struct nhlt *nhlt, uintptr_t acpi_addr);
144 
145 /*
146  * Serialize NHLT object to ACPI table. Take in the beginning address of where
147  * the table will reside oem_id and oem_table_id and return the address of the
148  * next ACPI table. On error 0 will be returned. The NHLT object is no longer
149  * valid after thisfunction is called.
150  */
152  const char *oem_id, const char *oem_table_id,
153  uint32_t oem_revision);
154 
155 /*
156  * While very similar to nhlt_serialize() the SoC specific function allows
157  * the chipset to perform any needed accounting work such as updating ACPI
158  * field references for the serialized structure.
159  */
160 uintptr_t nhlt_soc_serialize(struct nhlt *nhlt, uintptr_t acpi_addr);
161 
162 /*
163  * While very similar to nhlt_serialize_oem_overrides() the SoC specific
164  * function allows the chipset to perform any needed accounting work such
165  * as updating ACPI field references for the serialized structure.
166  */
168  uintptr_t acpi_addr, const char *oem_id, const char *oem_table_id,
169  uint32_t oem_revision);
170 
171 /* Link and device types. */
172 enum {
178 };
179 
180 enum {
181  NHLT_SSP_DEV_BT, /* Bluetooth */
186 };
187 
188 enum {
190  NHLT_PDM_DEV_CAVS15, // NHLT_PDM_DEV on cAVS1.5 (KBL) based platforms
191 };
192 
193 /* Endpoint direction. */
194 enum {
198 };
199 
200 /* Channel Mask for an endpoint. While they are prefixed with 'SPEAKER' the
201  * channel masks are also used for capture devices. */
202 enum {
221 };
222 
223 /* Supporting structures. Only SoC/chipset and the library code directly should
224  * be manipulating these structures. */
225 struct sub_format {
230 };
231 
235 };
236 
247  struct sub_format sub_format;
248 };
249 
250 struct nhlt_format {
251  struct nhlt_waveform waveform;
253 };
254 
255 /*
256  * This struct is used by nhlt_endpoint_add_formats() for easily adding
257  * waveform formats with associated settings file.
258  */
265  const char *settings_file;
266 };
267 
268 /* Arbitrary max number of formats per endpoint. */
269 #define MAX_FORMATS 2
284 };
285 
286 #define MAX_ENDPOINTS 8
287 struct nhlt {
292 };
293 
297 };
298 
299 enum {
302 };
303 
307 };
308 
309 /*
310  * Microphone array definitions may be found here:
311  * https://msdn.microsoft.com/en-us/library/windows/hardware/dn613960%28v=vs.85%29.aspx
312  */
313 enum {
320 };
321 
322 #endif
uint16_t vid
Definition: tis.c:15
uint16_t did
Definition: tis.c:16
uintptr_t nhlt_soc_serialize(struct nhlt *nhlt, uintptr_t acpi_addr)
Definition: nhlt.c:7
@ NHLT_LINK_HDA
Definition: nhlt.h:173
@ NHLT_LINK_DSP
Definition: nhlt.h:174
@ NHLT_LINK_SSP
Definition: nhlt.h:176
@ NHLT_MAX_LINK_TYPES
Definition: nhlt.h:177
@ NHLT_LINK_PDM
Definition: nhlt.h:175
int nhlt_format_append_config(struct nhlt_format *format, const void *config, size_t config_sz)
Definition: nhlt.c:138
uintptr_t nhlt_serialize(struct nhlt *nhlt, uintptr_t acpi_addr)
Definition: nhlt.c:371
@ NHLT_TDM_BASIC
Definition: nhlt.h:300
@ NHLT_TDM_MIC_ARRAY
Definition: nhlt.h:301
@ NHLT_MIC_ARRAY_4CH_2ND_GEOM
Definition: nhlt.h:318
@ NHLT_MIC_ARRAY_2CH_BIG
Definition: nhlt.h:315
@ NHLT_MIC_ARRAY_4CH_L_SHAPED
Definition: nhlt.h:317
@ NHLT_MIC_ARRAY_2CH_SMALL
Definition: nhlt.h:314
@ NHLT_MIC_ARRAY_VENDOR_DEFINED
Definition: nhlt.h:319
@ NHLT_MIC_ARRAY_4CH_1ST_GEOM
Definition: nhlt.h:316
struct nhlt * nhlt_init(void)
Definition: nhlt.c:23
@ NHLT_PDM_DEV
Definition: nhlt.h:189
@ NHLT_PDM_DEV_CAVS15
Definition: nhlt.h:190
struct nhlt_endpoint * nhlt_add_endpoint(struct nhlt *nhlt, int link_type, int device_type, int dir, uint16_t vid, uint16_t did)
Definition: nhlt.c:38
int nhlt_add_ssp_endpoints(struct nhlt *nhlt, int virtual_bus_id, const struct nhlt_endp_descriptor *epds, size_t num_epds)
Definition: nhlt.c:468
uintptr_t nhlt_soc_serialize_oem_overrides(struct nhlt *nhlt, uintptr_t acpi_addr, const char *oem_id, const char *oem_table_id, uint32_t oem_revision)
Definition: nhlt.c:12
size_t nhlt_current_size(struct nhlt *nhlt)
Definition: nhlt.c:256
@ NHLT_SSP_DEV_FM
Definition: nhlt.h:183
@ NHLT_SSP_DEV_I2S
Definition: nhlt.h:185
@ NHLT_SSP_DEV_BT
Definition: nhlt.h:181
@ NHLT_SSP_DEV_RESERVED
Definition: nhlt.h:184
@ NHLT_SSP_DEV_MODEM
Definition: nhlt.h:182
#define MAX_ENDPOINTS
Definition: nhlt.h:286
@ SPEAKER_SIDE_RIGHT
Definition: nhlt.h:213
@ SPEAKER_TOP_FRONT_RIGHT
Definition: nhlt.h:217
@ SPEAKER_FRONT_LEFT
Definition: nhlt.h:203
@ SPEAKER_TOP_BACK_RIGHT
Definition: nhlt.h:220
@ SPEAKER_TOP_FRONT_LEFT
Definition: nhlt.h:215
@ SPEAKER_TOP_FRONT_CENTER
Definition: nhlt.h:216
@ SPEAKER_FRONT_RIGHT_OF_CENTER
Definition: nhlt.h:210
@ SPEAKER_TOP_CENTER
Definition: nhlt.h:214
@ SPEAKER_BACK_LEFT
Definition: nhlt.h:207
@ SPEAKER_FRONT_RIGHT
Definition: nhlt.h:204
@ SPEAKER_TOP_BACK_CENTER
Definition: nhlt.h:219
@ SPEAKER_LOW_FREQUENCY
Definition: nhlt.h:206
@ SPEAKER_TOP_BACK_LEFT
Definition: nhlt.h:218
@ SPEAKER_SIDE_LEFT
Definition: nhlt.h:212
@ SPEAKER_FRONT_LEFT_OF_CENTER
Definition: nhlt.h:209
@ SPEAKER_FRONT_CENTER
Definition: nhlt.h:205
@ SPEAKER_BACK_RIGHT
Definition: nhlt.h:208
@ SPEAKER_BACK_CENTER
Definition: nhlt.h:211
void nhlt_next_instance(struct nhlt *nhlt, int link_type)
Definition: nhlt.c:184
@ NHLT_DIR_RENDER
Definition: nhlt.h:195
@ NHLT_DIR_BIDIRECTIONAL
Definition: nhlt.h:197
@ NHLT_DIR_CAPTURE
Definition: nhlt.h:196
int nhlt_add_endpoints(struct nhlt *nhlt, const struct nhlt_endp_descriptor *epds, size_t num_epds)
Definition: nhlt.c:459
uintptr_t nhlt_serialize_oem_overrides(struct nhlt *nhlt, uintptr_t acpi_addr, const char *oem_id, const char *oem_table_id, uint32_t oem_revision)
Definition: nhlt.c:376
#define MAX_FORMATS
Definition: nhlt.h:269
int nhlt_endpoint_add_formats(struct nhlt_endpoint *endpoint, const struct nhlt_format_config *formats, size_t num_formats)
Definition: nhlt.c:144
struct nhlt_format * nhlt_add_format(struct nhlt_endpoint *endpoint, int num_channels, int sample_freq_khz, int container_bits_per_sample, int valid_bits_per_sample, uint32_t speaker_mask)
Definition: nhlt.c:102
int nhlt_endpoint_append_config(struct nhlt_endpoint *endpoint, const void *config, size_t config_sz)
Definition: nhlt.c:96
enum board_config config
Definition: memory.c:448
unsigned short uint16_t
Definition: stdint.h:11
unsigned int uint32_t
Definition: stdint.h:14
unsigned long uintptr_t
Definition: stdint.h:21
unsigned char uint8_t
Definition: stdint.h:8
uint8_t array_type
Definition: nhlt.h:306
struct nhlt_tdm_config tdm_config
Definition: nhlt.h:305
const struct nhlt_format_config * formats
Definition: nhlt.h:63
size_t cfg_size
Definition: nhlt.h:61
const void * cfg
Definition: nhlt.h:60
size_t num_formats
Definition: nhlt.h:64
uint16_t vid
Definition: nhlt.h:57
uint16_t did
Definition: nhlt.h:58
struct nhlt_specific_config config
Definition: nhlt.h:281
struct nhlt_format formats[MAX_FORMATS]
Definition: nhlt.h:283
uint16_t device_id
Definition: nhlt.h:275
uint16_t revision_id
Definition: nhlt.h:276
uint32_t subsystem_id
Definition: nhlt.h:277
uint8_t device_type
Definition: nhlt.h:278
uint8_t num_formats
Definition: nhlt.h:282
uint16_t vendor_id
Definition: nhlt.h:274
uint8_t virtual_bus_id
Definition: nhlt.h:280
uint8_t link_type
Definition: nhlt.h:272
uint8_t instance_id
Definition: nhlt.h:273
uint32_t length
Definition: nhlt.h:271
uint8_t direction
Definition: nhlt.h:279
uint32_t speaker_mask
Definition: nhlt.h:264
int num_channels
Definition: nhlt.h:260
int container_bits_per_sample
Definition: nhlt.h:262
int valid_bits_per_sample
Definition: nhlt.h:263
int sample_freq_khz
Definition: nhlt.h:261
const char * settings_file
Definition: nhlt.h:265
struct nhlt_specific_config config
Definition: nhlt.h:252
struct nhlt_waveform waveform
Definition: nhlt.h:251
uint32_t size
Definition: nhlt.h:233
void * capabilities
Definition: nhlt.h:234
uint8_t config_type
Definition: nhlt.h:296
uint8_t virtual_slot
Definition: nhlt.h:295
uint32_t channel_mask
Definition: nhlt.h:246
uint16_t num_channels
Definition: nhlt.h:239
uint32_t bytes_per_second
Definition: nhlt.h:241
uint16_t extra_size
Definition: nhlt.h:244
uint16_t tag
Definition: nhlt.h:238
uint32_t samples_per_second
Definition: nhlt.h:240
uint16_t valid_bits_per_sample
Definition: nhlt.h:245
uint16_t block_align
Definition: nhlt.h:242
uint16_t bits_per_sample
Definition: nhlt.h:243
Definition: nhlt.h:287
uint8_t num_endpoints
Definition: nhlt.h:289
uint32_t subsystem_id
Definition: nhlt.h:288
struct nhlt_endpoint endpoints[MAX_ENDPOINTS]
Definition: nhlt.h:290
uint8_t current_instance_id[NHLT_MAX_LINK_TYPES]
Definition: nhlt.h:291
uint32_t data1
Definition: nhlt.h:226
uint16_t data2
Definition: nhlt.h:227
uint16_t data3
Definition: nhlt.h:228
uint8_t data4[8]
Definition: nhlt.h:229