ACPI: NHLT: Access and query helpers
Subsystems (2)
v4 cover ACPI: NHLT: Access and query helpers
The goal of this patchset is to enhance existing interface of NonHDAudioLinkTable (NHLT), that is, accessing device and format configuration spaces as well as adding query functions for finding specific endpoints and format configurations. Once that is done, existing sound-drivers can move from utilizing sound/hda/intel-nhlt.c to this very code and ultimately the former file can be removed.
It's important to highlight that currently presented implementation is not final and intention is to first transfer sound-driver to new API and then provide incremental updates to internal code in drivers/acpi/nhlt.c to improve reliability and safety.
Series starts with addition of devcfg-access helpers. The main reasoning for adding access function is inability for a user to predict whether given space (device config) is valid or not. While inheritance in the specification is allowed, e.g.: mic_devcfg being inherited by mic_vendor_devcfg, until size is verified, one shall not be accessing fields which are not guaranteed by the spec. The only field guaranteed is "capabilities_size".
The xxx_devcfg structs added here kind of duplicate few existing ones in actbl2.h. This is mainly motivated by usage improvements - simplicity, shorten wording. Intention is to have them replacing existing actbl2.h members in the future.
Follow up is the declaration of acpi_gbl_NHLT. Motivation is to make sound-drivers life easier i.e.: release them from storing pointer to the first NHLT in the system internally. Such drivers may utilize acpi_gbl_NHLT when querying endpoints and formats instead.
Table manipulation functions and macros serve as a base for the follow-up query functions. So called query functions represent standard operations performed by user (a sound driver) when attempting to open an audio stream. These more or less mimic what's present in sound/hda/intel-nhlt.c.
Changes in v4:
- relocated ACPI_NHLT kconfig in the drivers/acpi/Kconfig to more relevant area within the file
Changes in v3:
- uncapitalized acpi_gbl_NHLT
- fixed compilation problems when CONFIG_ACPI_NHLT is disabled
- dropped Reviewed-by tags in the 2/4 patch due to above, those were not one-line changes
Changes in v2:
- minor wording improvements in kernel-doc for patch 3/4
- dropped parentheses around loop cursors in for_each_nhlt_*() macros
- readability improvements in compound if-statements within query functions
- dropped NULL-checks in query functions
Cezary Rojewski (4):
ACPI: NHLT: Device configuration access interface
ACPI: NHLT: Introduce acpi_gbl_nhlt
ACPI: NHLT: Table manipulation helpers
ACPI: NHLT: Add query functions
drivers/acpi/Kconfig | 3 + drivers/acpi/Makefile | 1 + drivers/acpi/nhlt.c | 221 ++++++++++++++++++++++++++++++++++++++++++ include/acpi/actbl2.h | 28 ++++++ include/acpi/nhlt.h | 212 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 465 insertions(+) create mode 100644 drivers/acpi/nhlt.c create mode 100644 include/acpi/nhlt.h
Signature · 1 line
2.25.1
PATCH v4 1/4 ACPI: NHLT: Device configuration access interface
Device configuration structures are plenty so declare a struct for each known variant. As neither of them shall be accessed without verifying the memory block first, introduce macros to make it easy to do so.
--- include/acpi/actbl2.h | 28 ++++++++++++++++++ include/acpi/nhlt.h | 66 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 include/acpi/nhlt.h
include/acpi/actbl2.h +28 -0
@@ -2014,6 +2014,25 @@ struct acpi_nhlt_vendor_mic_count {u8 microphone_count; }; +/* The only guaranteed configuration space header. Any other requires validation. */ +struct acpi_nhlt_cfg { +u32 capabilities_size; +u8 capabilities[]; +}; + +struct acpi_nhlt_devcfg { +u32 capabilities_size; +u8 virtual_slot; +u8 config_type; +}; + +struct acpi_nhlt_mic_devcfg { +u32 capabilities_size; +u8 virtual_slot; +u8 config_type; +u8 array_type; +}; +struct acpi_nhlt_vendor_mic_config {u8 type;u8 panel;
@@ -2030,6 +2049,15 @@ struct acpi_nhlt_vendor_mic_config {u16 work_horizontal_angle_end;/* -180 - + 180 with 2 deg step */ }; +struct acpi_nhlt_vendor_mic_devcfg { +u32 capabilities_size; +u8 virtual_slot; +u8 config_type; +u8 array_type; +u8 num_mics; +struct acpi_nhlt_vendor_mic_config mics[]; +}; +/* Values for Type field above */ #define ACPI_NHLT_MIC_OMNIDIRECTIONAL 0
include/acpi/nhlt.h new file +66 -0
66 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v4 1/4] ACPI: NHLT: Device configuration access interface
Fri, Jul 21, 2023 at 05:48:10PM +0200, Cezary Rojewski kirjoitti:
Quoted 5 lines
Device configuration structures are plenty so declare a struct for each known variant. As neither of them shall be accessed without verifying the memory block first, introduce macros to make it easy to do so.
Thinking of this over night (as I replied in the above)...
Quoted 1 line
Reviewed-by Andy Shevchenko <[email protected]>
Sorry, but seems I have to retract my tag and even more, NAK to the ACPICA changes.
I have thought that this is something new to the header there, but it appears that it duplicates (in a wrong way in my opinion) existing data types.
Existing data types are crafted (as far as I get them) in a way to be able to be combined in the union. In the similar way how _CRS is parsed in DSDT (first that comes to my mind). Hence that "simplification" is quite wrong in a few ways:
- it breaks ACPICA agreement on naming schema
- it duplicates existing data
- it made it even partially
- it is fine and correct in ACPICA to have long dereferenced data, again see for the union of acpi_object
I trully believe now that the above change in ACPICA must be reverted.
Again, sorry for this late bad news from my side. I have no clue why it was merged, perhaps lack of review? Or anything subtle I so miserably missed?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v4 1/4] ACPI: NHLT: Device configuration access interface
Quoted 25 lines · On 2023-08-09 7:00 AM, [email protected] wrote:
Fri, Jul 21, 2023 at 05:48:10PM +0200, Cezary Rojewski kirjoitti:
Quoted 5 lines
Device configuration structures are plenty so declare a struct for each known variant. As neither of them shall be accessed without verifying the memory block first, introduce macros to make it easy to do so.
Thinking of this over night (as I replied in the above)...
Quoted 1 line
Reviewed-by Andy Shevchenko <[email protected]>Sorry, but seems I have to retract my tag and even more, NAK to the ACPICA changes.
I have thought that this is something new to the header there, but it appears that it duplicates (in a wrong way in my opinion) existing data types.
Existing data types are crafted (as far as I get them) in a way to be able to be combined in the union. In the similar way how
_CRSis parsed in DSDT (first that comes to my mind). Hence that "simplification" is quite wrong in a few ways:
- it breaks ACPICA agreement on naming schema
- it duplicates existing data
- it made it even partially
- it is fine and correct in ACPICA to have long dereferenced data, again see for the union ofacpi_object
Quoted 5 lines
I trully believe now that the above change in ACPICA must be reverted.
Again, sorry for this late bad news from my side. I have no clue why it was merged, perhaps lack of review? Or anything subtle I so miserably missed?
First, you took the review seriously and provided a ton of valid feedback. And your reviews and expertise helped me grow as a developer, so from my perspective no need to sorry about spotting bad things late.
Now, I admit, a bit surprised given the number of revisions and age of the initial patchset. The cover-letter, attached for each revision, made the intentions clear. Our goal is to help actual users of NHLT i.e.: audio teams. While part of ACPICA, NHLT-code is hidden within sound/ so no one asks questions. Leaving things at status quo does not improve the situation. Thus I believe simple "no" is not an option here. To make the code better overall, relevant pieces should be made part of drivers/acpi.
Original problems stem from the fact that audio teams were not looped in during initial integration of NHLT-code. Turned out that no users utilize it in its current form. The problems are subtle, but a discussion wouldn't hurt.
To avoid double posting, should we continue the discussion here or in the PR on github?
Kind regards,
Czarek
Re: [PATCH v4 1/4] ACPI: NHLT: Device configuration access interface
Quoted 33 lines · Cezary Rojewski
Quoted 25 lines · On 2023-08-09 7:00 AM, [email protected] wrote:
Fri, Jul 21, 2023 at 05:48:10PM +0200, Cezary Rojewski kirjoitti:
Quoted 5 lines
Device configuration structures are plenty so declare a struct for each known variant. As neither of them shall be accessed without verifying the memory block first, introduce macros to make it easy to do so.
Thinking of this over night (as I replied in the above)...
Quoted 1 line
Reviewed-by Andy Shevchenko <[email protected]>Sorry, but seems I have to retract my tag and even more, NAK to the ACPICA changes.
I have thought that this is something new to the header there, but it appears that it duplicates (in a wrong way in my opinion) existing data types.
Existing data types are crafted (as far as I get them) in a way to be able to be combined in the union. In the similar way how
_CRSis parsed in DSDT (first that comes to my mind). Hence that "simplification" is quite wrong in a few ways:
- it breaks ACPICA agreement on naming schema
- it duplicates existing data
- it made it even partially
- it is fine and correct in ACPICA to have long dereferenced data, again see for the union ofacpi_objectQuoted 5 lines
I trully believe now that the above change in ACPICA must be reverted.
Again, sorry for this late bad news from my side. I have no clue why it was merged, perhaps lack of review? Or anything subtle I so miserably missed?
Quoted 7 lines
First, you took the review seriously and provided a ton of valid feedback. And your reviews and expertise helped me grow as a developer, so from my perspective no need to sorry about spotting bad things late.
Now, I admit, a bit surprised given the number of revisions and age of the initial patchset. The cover-letter, attached for each revision, made the intentions clear.
As you may notice I'm not against code that is done as a part of the Linux kernel and my surprise is the ACPICA change. My focus for review was a Linux kernel and it was just by a chance I looked at the PR on GitHub. There is neither good explanation in the commit message nor discussion of the change. What I probably miss (and that may help me to understand better the change) are:
- the examples of the code snippets that are using data types before and after
- explanation why not all data types were covered (there are more "strange" names like with _a, _b suffix)
- how this is supposed to be maintained as the ACPICA has users outside of the kernel and how the change
makes their life easier (to me it's the opposite).
Quoted 4 lines
Our goal is to help actual users of NHLT i.e.:
audio teams. While part of ACPICA, NHLT-code is hidden withinsound/so no one asks questions. Leaving things at status quo does not improve the situation.
What situation? To me it makes it worse. (Again, I'm talking solely for ACPICA change, the rest I have reviewed and I am fine with the direction taken.)
Quoted 10 lines
Thus I believe simple "no" is not an option here. To make the code better overall, relevant pieces should be made part of
drivers/acpi.Original problems stem from the fact that audio teams were not looped in during initial integration of NHLT-code. Turned out that no users utilize it in its current form. The problems are subtle, but a discussion wouldn't hurt.
To avoid double posting, should we continue the discussion here or in the PR on github?
Let's do it there, as it's purely about ACPICA.
The kernel part will be affected depending on the result of the discussion.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v4 1/4] ACPI: NHLT: Device configuration access interface
Quoted 2 lines · Andy Shevchenko
On Wed, Aug 9, 2023 at 11:48 AM Cezary Rojewski
<[email protected]> wrote:
...
Quoted 8 lines
Quoted 7 lines
First, you took the review seriously and provided a ton of valid feedback. And your reviews and expertise helped me grow as a developer, so from my perspective no need to sorry about spotting bad things late.
Now, I admit, a bit surprised given the number of revisions and age of the initial patchset. The cover-letter, attached for each revision, made the intentions clear.
Quoted 12 lines
As you may notice I'm not against code that is done as a part of the Linux kernel and my surprise is the ACPICA change. My focus for review was a Linux kernel and it was just by a chance I looked at the PR on GitHub. There is neither good explanation in the commit message nor discussion of the change. What I probably miss (and that may help me to understand better the change) are:
- the examples of the code snippets that are using data types before and after
- explanation why not all data types were covered (there are more "strange" names like with _a, _b suffix)
- how this is supposed to be maintained as the ACPICA has users outside of the kernel and how the change
makes their life easier (to me it's the opposite).
In general, many types are bogus or redundant. I'd argue that having types defined as _a, _b, _c, _d make the life harder :)
struct acpi_nhlt_device_specific_config_a
bogus, there is no '_a', it's called mic device config instead
struct acpi_nhlt_device_specific_config_d
bogus, such thing does not exist
it breaks the spec as the "CapabilitiesSize" is missing
struct acpi_nhlt_device_specific_config_b
bogus, such thing does not exist
it's the header of any dev config but just header alone is
invalid
struct acpi_nhlt_device_specific_config_c
bogus, describes an invalid type. Such thing can be encountered only when parsing damaged NHLT
struct acpi_nhlt_render_device_specific_config
redundant
Then we have constants such as:
#define ACPI_NHLT_PDM 2
#define ACPI_NHLT_SSP 3
_PDM/_SSP what? There is no NHLT of type PDM or of type SSP. These specify link types but it's not mentioned in constants names.
I believe that by now you see where am going. The patch focuses on device-specific-config area as it's the area that requires most help.
Quoted 8 lines
Quoted 4 lines
Our goal is to help actual users of NHLT i.e.:
audio teams. While part of ACPICA, NHLT-code is hidden withinsound/so no one asks questions. Leaving things at status quo does not improve the situation.What situation? To me it makes it worse. (Again, I'm talking solely for ACPICA change, the rest I have reviewed and I am fine with the direction taken.)
Situation = on top of above, NHLT-code is currently within sound/.
Let the handlers be part of drivers/acpi as is the case for all ACPI tables. The handlers themselves do not (and shall not) belong to ACPICA if I'm not mistaken.
Quoted 8 lines
Quoted 8 lines
Thus I believe simple "no" is not an option here. To make the code better overall, relevant pieces should be made part of
drivers/acpi.Original problems stem from the fact that audio teams were not looped in during initial integration of NHLT-code. Turned out that no users utilize it in its current form. The problems are subtle, but a discussion wouldn't hurt.
Quoted 5 lines
Quoted 2 lines
To avoid double posting, should we continue the discussion here or in the PR on github?
Let's do it there, as it's purely about ACPICA.
The kernel part will be affected depending on the result of the discussion.
Ok.
PATCH v4 2/4 ACPI: NHLT: Introduce acpi_gbl_nhlt
In reply to Cezary RojewskiWhile there is no strict limit to amount of NHLT tables present, usually just the first one is utilized. To simplify implementation of sound drivers, provide publicly accessible pointer. Accessing it after calling acpi_nhlt_get_gbl_table() yields the first NHLT table met during the scan.
--- drivers/acpi/Kconfig | 3 +++ drivers/acpi/Makefile | 1 + drivers/acpi/nhlt.c | 47 +++++++++++++++++++++++++++++++++++++++++++ include/acpi/nhlt.h | 30 +++++++++++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 drivers/acpi/nhlt.c
drivers/acpi/Kconfig +3 -0
@@ -101,6 +101,9 @@ config ACPI_LPIT depends on X86_64 default y +config ACPI_NHLT + bool + config ACPI_SLEEP bool depends on SUSPEND || HIBERNATION
drivers/acpi/Makefile +1 -0
@@ -93,6 +93,7 @@ obj-$(CONFIG_ACPI) += container.o obj-$(CONFIG_ACPI_THERMAL) += thermal.o obj-$(CONFIG_ACPI_PLATFORM_PROFILE) += platform_profile.o obj-$(CONFIG_ACPI_NFIT) += nfit/ +obj-$(CONFIG_ACPI_NHLT) += nhlt.o obj-$(CONFIG_ACPI_NUMA) += numa/ obj-$(CONFIG_ACPI) += acpi_memhotplug.o obj-$(CONFIG_ACPI_HOTPLUG_IOAPIC) += ioapic.o
drivers/acpi/nhlt.c new file +47 -0
47 lines not on this page · raw message
include/acpi/nhlt.h +30 -0
@@ -63,4 +63,34 @@ __cfg->capabilities_size ==struct_size (__cfg, mics, __cfg->num_mics) ? \ __cfg : NULL; }) +#if IS_ENABLED (CONFIG_ACPI_NHLT ) + +/* +* System-wide pointer to the first NHLT table. +* +* A sound driver may utilize acpi_nhlt_get/put_gbl_table() on its +* initialization and removal respectively to avoid excessive mapping +* and unmapping of the memory occupied by the table between streaming +* operations. +*/ +extern struct acpi_table_nhlt *acpi_gbl_nhlt; + +acpi_status acpi_nhlt_get_gbl_table (void ); +void acpi_nhlt_put_gbl_table (void ); + +#else /* !CONFIG_ACPI_NHLT */ + +#define acpi_gbl_nhlt NULL + +static inline acpi_status acpi_nhlt_get_gbl_table (void ) +{ +return AE_NOT_FOUND ; +} + +static inline void acpi_nhlt_put_gbl_table (void ) +{ +} + +#endif /* CONFIG_ACPI_NHLT */ +#endif /* __ACPI_NHLT_H__ */
Signature · 1 line
2.25.1
PATCH v4 3/4 ACPI: NHLT: Table manipulation helpers
In reply to Cezary RojewskiThe table is composed of a range of endpoints with each describing audio formats they support. Thus most of the operations involve iterating over elements of the table. Simplify the process by implementing range of getters.
--- include/acpi/nhlt.h | 68 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+)
include/acpi/nhlt.h +68 -0
@@ -63,6 +63,74 @@ __cfg->capabilities_size ==struct_size (__cfg, mics, __cfg->num_mics) ? \ __cfg : NULL; }) +/** +* acpi_nhlt_endpoint_fmtscfg - Get the formats configuration space. +* @ep: the endpoint to retrieve the space for. +* +* Return: A pointer to the formats configuration space. +*/ +static inline struct acpi_nhlt_formats_config * +acpi_nhlt_endpoint_fmtscfg (const struct acpi_nhlt_endpoint *ep) +{ +struct acpi_nhlt_cfg *cfg =__acpi_nhlt_endpoint_cfg (ep); + +return (struct acpi_nhlt_formats_config *)((u8 *)(cfg +1 ) + cfg->capabilities_size); +} + +#define __acpi_nhlt_first_endpoint (tb) \ + ((void *)(tb + 1)) + +#define __acpi_nhlt_next_endpoint (ep) \ + ((void *)((u8 *)(ep) + (ep)->descriptor_length)) + +#define __acpi_nhlt_get_endpoint (tb, ep, i) \ + ((i) ? __acpi_nhlt_next_endpoint(ep) : __acpi_nhlt_first_endpoint(tb)) + +#define __acpi_nhlt_first_fmtcfg (fmts) \ + ((void *)(fmts + 1)) + +#define __acpi_nhlt_next_fmtcfg (fmt) \ + ((void *)((u8 *)((fmt) + 1) + (fmt)->capability_size)) + +#define __acpi_nhlt_get_fmtcfg (fmts, fmt, i) \ + ((i) ? __acpi_nhlt_next_fmtcfg(fmt) : __acpi_nhlt_first_fmtcfg(fmts)) + +/* +* The for_each_nhlt_*() macros rely on an iterator to deal with the +* variable length of each endpoint structure and the possible presence +* of an OED-Config used by Windows only. +*/ + +/** +* for_each_nhlt_endpoint - Iterate over endpoints in a NHLT table. +* @tb: the pointer to a NHLT table. +* @ep: the pointer to endpoint to use as loop cursor. +*/ +#define for_each_nhlt_endpoint (tb, ep) \ + for (unsigned int __i = 0; \ + __i < (tb)->endpoint_count && \ + (ep = __acpi_nhlt_get_endpoint(tb, ep, __i)); \ + __i++) + +/** +* for_each_nhlt_fmtcfg - Iterate over format configurations. +* @fmts: the pointer to formats configuration space. +* @fmt: the pointer to format to use as loop cursor. +*/ +#define for_each_nhlt_fmtcfg (fmts, fmt) \ + for (unsigned int __i = 0; \ + __i < (fmts)->formats_count && \ + (fmt = __acpi_nhlt_get_fmtcfg(fmts, fmt, __i)); \ + __i++) + +/** +* for_each_nhlt_endpoint_fmtcfg - Iterate over format configurations in an endpoint. +* @ep: the pointer to an endpoint. +* @fmt: the pointer to format to use as loop cursor. +*/ +#define for_each_nhlt_endpoint_fmtcfg (ep, fmt) \ + for_each_nhlt_fmtcfg(acpi_nhlt_endpoint_fmtscfg(ep), fmt) +#if IS_ENABLED (CONFIG_ACPI_NHLT )/*
Signature · 1 line
2.25.1
PATCH v4 4/4 ACPI: NHLT: Add query functions
In reply to Cezary RojewskiWith iteration helpers added there is a room for more complex query tasks which are commonly performed by sound drivers. Implement them in common API so that a unified mechanism is available for all of them.
While the acpi_nhlt_endpoint_dmic_count() stands out a bit, it is a critical component for any AudioDSP driver to know how many digital microphones it is dealing with. There is no one perfect method, but the best one available is provided.
--- drivers/acpi/nhlt.c | 174 ++++++++++++++++++++++++++++++++++++++++++++ include/acpi/nhlt.h | 48 ++++++++++++ 2 files changed, 222 insertions(+)
drivers/acpi/nhlt.c +174 -0
@@ -6,6 +6,8 @@// Amadeusz Slawinski <[email protected]> // +#define pr_fmt (fmt) "ACPI: NHLT: " fmt +#include <linux/export.h> #include <acpi/nhlt.h>
@@ -45,3 +47,175 @@ void acpi_nhlt_put_gbl_table(void)acpi_put_table ((struct acpi_table_header *)acpi_gbl_nhlt); }EXPORT_SYMBOL_GPL (acpi_nhlt_put_gbl_table); + +/** +* acpi_nhlt_endpoint_match - Verify if an endpoint matches criteria. +* @ep: the endpoint to check. +* @link_type: the hardware link type, e.g.: PDM or SSP. +* @dev_type: the device type. +* @dir: stream direction. +* @bus_id: the ID of virtual bus hosting the endpoint. +* +* Either of @link_type, @dev_type, @dir or @bus_id may be set to a negative +* value to ignore the parameter when matching. +* +* Return: %true if endpoint matches specified criteria or %false otherwise. +*/ +bool acpi_nhlt_endpoint_match (const struct acpi_nhlt_endpoint *ep, +int link_type,int dev_type,int dir,int bus_id) +{ +return ep && + (link_type <0 || ep->link_type == link_type) && + (dev_type <0 || ep->device_type == dev_type) && + (bus_id <0 || ep->virtual_bus_id == bus_id) && + (dir <0 || ep->direction == dir); +} +EXPORT_SYMBOL_GPL (acpi_nhlt_endpoint_match); + +/** +* acpi_nhlt_find_endpoint - Search a NHLT table for an endpoint. +* @tb: the table to search. +* @link_type: the hardware link type, e.g.: PDM or SSP. +* @dev_type: the device type. +* @dir: stream direction. +* @bus_id: the ID of virtual bus hosting the endpoint. +* +* Either of @link_type, @dev_type, @dir or @bus_id may be set to a negative +* value to ignore the parameter during the search. +* +* Return: A pointer to endpoint matching the criteria, %NULL if not found or +* an ERR_PTR() otherwise. +*/ +struct acpi_nhlt_endpoint * +acpi_nhlt_find_endpoint (const struct acpi_table_nhlt *tb, +int link_type,int dev_type,int dir,int bus_id) +{ +struct acpi_nhlt_endpoint *ep; + +for_each_nhlt_endpoint (tb, ep) +if (acpi_nhlt_endpoint_match (ep, link_type, dev_type, dir, bus_id)) +return ep; +return NULL ; +} +EXPORT_SYMBOL_GPL (acpi_nhlt_find_endpoint); + +/** +* acpi_nhlt_endpoint_find_fmtcfg - Search endpoint's formats configuration space +* for a specific format. +* @ep: the endpoint to search. +* @ch: number of channels. +* @rate: samples per second. +* @vbps: valid bits per sample. +* @bps: bits per sample. +* +* Return: A pointer to format matching the criteria, %NULL if not found or +* an ERR_PTR() otherwise. +*/ +struct acpi_nhlt_format_config * +acpi_nhlt_endpoint_find_fmtcfg (const struct acpi_nhlt_endpoint *ep, +u16 ch,u32 rate,u16 vbps,u16 bps) +{ +struct acpi_nhlt_wave_extensible *wav; +struct acpi_nhlt_format_config *fmt; + +for_each_nhlt_endpoint_fmtcfg (ep, fmt) { + wav = &fmt->format; + +if (wav->valid_bits_per_sample == vbps && + wav->samples_per_sec == rate && + wav->bits_per_sample == bps && + wav->channel_count == ch) +return fmt; + } + +return NULL ; +} +EXPORT_SYMBOL_GPL (acpi_nhlt_endpoint_find_fmtcfg); + +/** +* acpi_nhlt_find_fmtcfg - Search a NHLT table for a specific format. +* @tb: the table to search. +* @link_type: the hardware link type, e.g.: PDM or SSP. +* @dev_type: the device type. +* @dir: stream direction. +* @bus_id: the ID of virtual bus hosting the endpoint. +* +* @ch: number of channels. +* @rate: samples per second. +* @vbps: valid bits per sample. +* @bps: bits per sample. +* +* Either of @link_type, @dev_type, @dir or @bus_id may be set to a negative +* value to ignore the parameter during the search. +* +* Return: A pointer to format matching the criteria, %NULL if not found or +* an ERR_PTR() otherwise. +*/ +struct acpi_nhlt_format_config * +acpi_nhlt_find_fmtcfg (const struct acpi_table_nhlt *tb, +int link_type,int dev_type,int dir,int bus_id, +u16 ch,u32 rate,u16 vbps,u16 bps) +{ +struct acpi_nhlt_format_config *fmt; +struct acpi_nhlt_endpoint *ep; + +for_each_nhlt_endpoint (tb, ep) { +if (!acpi_nhlt_endpoint_match (ep, link_type, dev_type, dir, bus_id)) +continue ; + + fmt =acpi_nhlt_endpoint_find_fmtcfg (ep, ch, rate, vbps, bps); +if (fmt) +return fmt; + } + +return NULL ; +} +EXPORT_SYMBOL_GPL (acpi_nhlt_find_fmtcfg); + +/** +* acpi_nhlt_endpoint_dmic_count - Retrieve number of digital microphones for a PDM endpoint. +* @ep: the endpoint to return microphones count for. +* +* Return: A number of microphones or an error code if an invalid endpoint is provided. +*/ +int acpi_nhlt_endpoint_dmic_count (const struct acpi_nhlt_endpoint *ep) +{ +struct acpi_nhlt_vendor_mic_devcfg *vendor_cfg; +struct acpi_nhlt_format_config *fmt; +struct acpi_nhlt_mic_devcfg *devcfg; +u16 max_ch =0 ; + +if (!ep || ep->link_type !=ACPI_NHLT_PDM ) +return -EINVAL ; + +/* Find max number of channels based on formats configuration. */ +for_each_nhlt_endpoint_fmtcfg (ep, fmt) + max_ch =max (fmt->format.channel_count, max_ch); + +/* If @ep not a mic array, fallback to channels count. */ + devcfg =acpi_nhlt_endpoint_mic_devcfg (ep); +if (!devcfg || devcfg->config_type !=ACPI_NHLT_CONFIG_TYPE_MIC_ARRAY ) +return max_ch; + +switch (devcfg->array_type) { +case ACPI_NHLT_SMALL_LINEAR_2ELEMENT : +case ACPI_NHLT_BIG_LINEAR_2ELEMENT : +return 2 ; + +case ACPI_NHLT_FIRST_GEOMETRY_LINEAR_4ELEMENT : +case ACPI_NHLT_PLANAR_LSHAPED_4ELEMENT : +case ACPI_NHLT_SECOND_GEOMETRY_LINEAR_4ELEMENT : +return 4 ; + +case ACPI_NHLT_VENDOR_DEFINED : + vendor_cfg =acpi_nhlt_endpoint_vendor_mic_devcfg (ep); +if (!vendor_cfg) +return -EINVAL ; +return vendor_cfg->num_mics; + +default : +pr_warn ("undefined mic array type: %#x\n" , devcfg->array_type); +return max_ch; + } +} +EXPORT_SYMBOL_GPL (acpi_nhlt_endpoint_dmic_count);
include/acpi/nhlt.h +48 -0
60 lines not on this page · raw message
Signature · 1 line
2.25.1