[alsa-devel] [PATCH 0/2] ALSA: control: export all of TLV related macros to user land
Hi,
This patchset updates my previous RFCs, and they're now for merging to upstream.
[alsa-devel] [RFC][PATCH 0/2] ALSA: control: export all of TLV related macros to user land http://mailman.alsa-project.org/pipermail/alsa-devel/2016-September/112645.h...
Currently, TLV related protocol is not shared to user land. This is not good in a point of application interfaces, because application developers can't realize the protocol just to see UAPI headers, and they're forced to look for TLV-related codes in kernel land.
This patchset moves all of macros related to TLV into UAPI header. To avoid confusions such as name conflict in user land, these macros have prefixes of 'SNDRV_CTL_TLVT_' and 'SNDRV_CTL_TLVD_'. When adding new items to the protocol, developers should use these prefixes and add them to the UAPI header.
Changes from RFC: - Drop second patch to replace include statements - Rename each macros to prevent applications from name conflict
Takashi Sakamoto (2): ALSA: control: export layout of TLV payload to UAPI header ALSA: rename TLV-related macros so that they're friendly to user applications
include/sound/tlv.h | 73 +++++++++++++----------------------------------- include/uapi/sound/tlv.h | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 54 deletions(-)
In ALSA control interface, each element set can have threshold level information. This information is transferred between drivers/applications, in a shape of tlv packet. The layout of this packet is defined in 'uapi/sound/asound.h' (struct snd_ctl_tlv):
struct snd_ctl_tlv { unsigned int numid; unsigned int length; unsigned int tlv[0]; };
Data in the payload (struct snd_ctl_tlv.tlv) is expected to be filled according to our own protocol. This protocol is described in 'include/sound/tlv.h'. A layout of the payload is expected as:
struct snd_ctl_tlv.tlv[0]: one of SNDRV_CTL_TLVT_XXX struct snd_ctl_tlv.tlv[1]: Length of data struct snd_ctl_tlv.tlv[2...]: data
Unfortunately, the macro is not exported to user land yet, thus applications cannot get to know the protocol.
Additionally, ALSA control core has a feature called as 'user-defined' element set. This allows applications to add/remove arbitrary element sets with elements to control devices. Elements in the element set can be operated by the same way as the ones added by in-kernel implementation.
For threshold level information of 'user-defined' element set, applications need to register the information to an element set. However, as described above, layout of the payload is closed in kernel land. This is quite inconvenient, too.
This commit moves the protocol to UAPI header for TLV.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- include/sound/tlv.h | 61 ------------------------------------------------ include/uapi/sound/tlv.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 61 deletions(-)
diff --git a/include/sound/tlv.h b/include/sound/tlv.h index df97d19..1f593b6 100644 --- a/include/sound/tlv.h +++ b/include/sound/tlv.h @@ -22,67 +22,6 @@ * */
-/* - * TLV structure is right behind the struct snd_ctl_tlv: - * unsigned int type - see SNDRV_CTL_TLVT_* - * unsigned int length - * .... data aligned to sizeof(unsigned int), use - * block_length = (length + (sizeof(unsigned int) - 1)) & - * ~(sizeof(unsigned int) - 1)) .... - */ - #include <uapi/sound/tlv.h>
-#define TLV_ITEM(type, ...) \ - (type), TLV_LENGTH(__VA_ARGS__), __VA_ARGS__ -#define TLV_LENGTH(...) \ - ((unsigned int)sizeof((const unsigned int[]) { __VA_ARGS__ })) - -#define TLV_CONTAINER_ITEM(...) \ - TLV_ITEM(SNDRV_CTL_TLVT_CONTAINER, __VA_ARGS__) -#define DECLARE_TLV_CONTAINER(name, ...) \ - unsigned int name[] = { TLV_CONTAINER_ITEM(__VA_ARGS__) } - -#define TLV_DB_SCALE_MASK 0xffff -#define TLV_DB_SCALE_MUTE 0x10000 -#define TLV_DB_SCALE_ITEM(min, step, mute) \ - TLV_ITEM(SNDRV_CTL_TLVT_DB_SCALE, \ - (min), \ - ((step) & TLV_DB_SCALE_MASK) | \ - ((mute) ? TLV_DB_SCALE_MUTE : 0)) -#define DECLARE_TLV_DB_SCALE(name, min, step, mute) \ - unsigned int name[] = { TLV_DB_SCALE_ITEM(min, step, mute) } - -/* dB scale specified with min/max values instead of step */ -#define TLV_DB_MINMAX_ITEM(min_dB, max_dB) \ - TLV_ITEM(SNDRV_CTL_TLVT_DB_MINMAX, (min_dB), (max_dB)) -#define TLV_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \ - TLV_ITEM(SNDRV_CTL_TLVT_DB_MINMAX_MUTE, (min_dB), (max_dB)) -#define DECLARE_TLV_DB_MINMAX(name, min_dB, max_dB) \ - unsigned int name[] = { TLV_DB_MINMAX_ITEM(min_dB, max_dB) } -#define DECLARE_TLV_DB_MINMAX_MUTE(name, min_dB, max_dB) \ - unsigned int name[] = { TLV_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) } - -/* linear volume between min_dB and max_dB (.01dB unit) */ -#define TLV_DB_LINEAR_ITEM(min_dB, max_dB) \ - TLV_ITEM(SNDRV_CTL_TLVT_DB_LINEAR, (min_dB), (max_dB)) -#define DECLARE_TLV_DB_LINEAR(name, min_dB, max_dB) \ - unsigned int name[] = { TLV_DB_LINEAR_ITEM(min_dB, max_dB) } - -/* dB range container: - * Items in dB range container must be ordered by their values and by their - * dB values. This implies that larger values must correspond with larger - * dB values (which is also required for all other mixer controls). - */ -/* Each item is: <min> <max> <TLV> */ -#define TLV_DB_RANGE_ITEM(...) \ - TLV_ITEM(SNDRV_CTL_TLVT_DB_RANGE, __VA_ARGS__) -#define DECLARE_TLV_DB_RANGE(name, ...) \ - unsigned int name[] = { TLV_DB_RANGE_ITEM(__VA_ARGS__) } -/* The below assumes that each item TLV is 4 words like DB_SCALE or LINEAR */ -#define TLV_DB_RANGE_HEAD(num) \ - SNDRV_CTL_TLVT_DB_RANGE, 6 * (num) * sizeof(unsigned int) - -#define TLV_DB_GAIN_MUTE -9999999 - #endif /* __SOUND_TLV_H */ diff --git a/include/uapi/sound/tlv.h b/include/uapi/sound/tlv.h index ffc4f20..b741e0e 100644 --- a/include/uapi/sound/tlv.h +++ b/include/uapi/sound/tlv.h @@ -28,4 +28,64 @@ #define SNDRV_CTL_TLVT_CHMAP_VAR 0x102 /* channels freely swappable */ #define SNDRV_CTL_TLVT_CHMAP_PAIRED 0x103 /* pair-wise swappable */
+/* + * TLV structure is right behind the struct snd_ctl_tlv: + * unsigned int type - see SNDRV_CTL_TLVT_* + * unsigned int length + * .... data aligned to sizeof(unsigned int), use + * block_length = (length + (sizeof(unsigned int) - 1)) & + * ~(sizeof(unsigned int) - 1)) .... + */ +#define TLV_ITEM(type, ...) \ + (type), TLV_LENGTH(__VA_ARGS__), __VA_ARGS__ +#define TLV_LENGTH(...) \ + ((unsigned int)sizeof((const unsigned int[]) { __VA_ARGS__ })) + +#define TLV_CONTAINER_ITEM(...) \ + TLV_ITEM(SNDRV_CTL_TLVT_CONTAINER, __VA_ARGS__) +#define DECLARE_TLV_CONTAINER(name, ...) \ + unsigned int name[] = { TLV_CONTAINER_ITEM(__VA_ARGS__) } + +#define TLV_DB_SCALE_MASK 0xffff +#define TLV_DB_SCALE_MUTE 0x10000 +#define TLV_DB_SCALE_ITEM(min, step, mute) \ + TLV_ITEM(SNDRV_CTL_TLVT_DB_SCALE, \ + (min), \ + ((step) & TLV_DB_SCALE_MASK) | \ + ((mute) ? TLV_DB_SCALE_MUTE : 0)) +#define DECLARE_TLV_DB_SCALE(name, min, step, mute) \ + unsigned int name[] = { TLV_DB_SCALE_ITEM(min, step, mute) } + +/* dB scale specified with min/max values instead of step */ +#define TLV_DB_MINMAX_ITEM(min_dB, max_dB) \ + TLV_ITEM(SNDRV_CTL_TLVT_DB_MINMAX, (min_dB), (max_dB)) +#define TLV_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \ + TLV_ITEM(SNDRV_CTL_TLVT_DB_MINMAX_MUTE, (min_dB), (max_dB)) +#define DECLARE_TLV_DB_MINMAX(name, min_dB, max_dB) \ + unsigned int name[] = { TLV_DB_MINMAX_ITEM(min_dB, max_dB) } +#define DECLARE_TLV_DB_MINMAX_MUTE(name, min_dB, max_dB) \ + unsigned int name[] = { TLV_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) } + +/* linear volume between min_dB and max_dB (.01dB unit) */ +#define TLV_DB_LINEAR_ITEM(min_dB, max_dB) \ + TLV_ITEM(SNDRV_CTL_TLVT_DB_LINEAR, (min_dB), (max_dB)) +#define DECLARE_TLV_DB_LINEAR(name, min_dB, max_dB) \ + unsigned int name[] = { TLV_DB_LINEAR_ITEM(min_dB, max_dB) } + +/* dB range container: + * Items in dB range container must be ordered by their values and by their + * dB values. This implies that larger values must correspond with larger + * dB values (which is also required for all other mixer controls). + */ +/* Each item is: <min> <max> <TLV> */ +#define TLV_DB_RANGE_ITEM(...) \ + TLV_ITEM(SNDRV_CTL_TLVT_DB_RANGE, __VA_ARGS__) +#define DECLARE_TLV_DB_RANGE(name, ...) \ + unsigned int name[] = { TLV_DB_RANGE_ITEM(__VA_ARGS__) } +/* The below assumes that each item TLV is 4 words like DB_SCALE or LINEAR */ +#define TLV_DB_RANGE_HEAD(num) \ + SNDRV_CTL_TLVT_DB_RANGE, 6 * (num) * sizeof(unsigned int) + +#define TLV_DB_GAIN_MUTE -9999999 + #endif
In a previous commit, some macros newly appeared to UAPI header for TLV packet. These macros have short names and they easily bring name conflist to applications. The conflict can be avoided to rename them with a proper prefix.
For this purpose, this commit renames these macros with prefix 'SNDRV_CTL_TLVD_'.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- include/sound/tlv.h | 26 ++++++++++++++++ include/uapi/sound/tlv.h | 80 ++++++++++++++++++++++++++++-------------------- 2 files changed, 72 insertions(+), 34 deletions(-)
diff --git a/include/sound/tlv.h b/include/sound/tlv.h index 1f593b6..6e2e773 100644 --- a/include/sound/tlv.h +++ b/include/sound/tlv.h @@ -24,4 +24,30 @@
#include <uapi/sound/tlv.h>
+/* For historical reasons, these macros are aliases to the ones in UAPI. */ +#define TLV_ITEM SNDRV_CTL_TLVD_ITEM +#define TLV_LENGTH SNDRV_CTL_TLVD_LENGTH + +#define TLV_CONTAINER_ITEM SNDRV_CTL_TLVD_CONTAINER_ITEM +#define DECLARE_TLV_CONTAINER SNDRV_CTL_TLVD_DECLARE_CONTAINER + +#define TLV_DB_SCALE_MASK SNDRV_CTL_TLVD_DB_SCALE_MASK +#define TLV_DB_SCALE_MUTE SNDRV_CTL_TLVD_DB_SCALE_MUTE +#define TLV_DB_SCALE_ITEM SNDRV_CTL_TLVD_DB_SCALE_ITEM +#define DECLARE_TLV_DB_SCALE SNDRV_CTL_TLVD_DECLARE_DB_SCALE + +#define TLV_DB_MINMAX_ITEM SNDRV_CTL_TLVD_DB_MINMAX_ITEM +#define TLV_DB_MINMAX_MUTE_ITEM SNDRV_CTL_TLVD_DB_MINMAX_MUTE_ITEM +#define DECLARE_TLV_DB_MINMAX SNDRV_CTL_TLVD_DECLARE_DB_MINMAX +#define DECLARE_TLV_DB_MINMAX_MUTE SNDRV_CTL_TLVD_DECLARE_DB_MINMAX_MUTE + +#define TLV_DB_LINEAR_ITEM SNDRV_CTL_TLVD_DB_LINEAR_ITEM +#define DECLARE_TLV_DB_LINEAR SNDRV_CTL_TLVD_DECLARE_DB_LINEAR + +#define TLV_DB_RANGE_ITEM SNDRV_CTL_TLVD_DB_RANGE_ITEM +#define DECLARE_TLV_DB_RANGE SNDRV_CTL_TLVD_DECLARE_DB_RANGE +#define TLV_DB_RANGE_HEAD SNDRV_CTL_TLVD_DB_RANGE_HEAD + +#define TLV_DB_GAIN_MUTE SNDRV_CTL_TLVD_DB_GAIN_MUTE + #endif /* __SOUND_TLV_H */ diff --git a/include/uapi/sound/tlv.h b/include/uapi/sound/tlv.h index b741e0e..f3c198f 100644 --- a/include/uapi/sound/tlv.h +++ b/include/uapi/sound/tlv.h @@ -36,41 +36,51 @@ * block_length = (length + (sizeof(unsigned int) - 1)) & * ~(sizeof(unsigned int) - 1)) .... */ -#define TLV_ITEM(type, ...) \ - (type), TLV_LENGTH(__VA_ARGS__), __VA_ARGS__ -#define TLV_LENGTH(...) \ +#define SNDRV_CTL_TLVD_ITEM(type, ...) \ + (type), SNDRV_CTL_TLVD_LENGTH(__VA_ARGS__), __VA_ARGS__ +#define SNDRV_CTL_TLVD_LENGTH(...) \ ((unsigned int)sizeof((const unsigned int[]) { __VA_ARGS__ }))
-#define TLV_CONTAINER_ITEM(...) \ - TLV_ITEM(SNDRV_CTL_TLVT_CONTAINER, __VA_ARGS__) -#define DECLARE_TLV_CONTAINER(name, ...) \ - unsigned int name[] = { TLV_CONTAINER_ITEM(__VA_ARGS__) } +#define SNDRV_CTL_TLVD_CONTAINER_ITEM(...) \ + SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_CONTAINER, __VA_ARGS__) +#define SNDRV_CTL_TLVD_DECLARE_CONTAINER(name, ...) \ + unsigned int name[] = { \ + SNDRV_CTL_TLVD_CONTAINER_ITEM(__VA_ARGS__) \ + }
-#define TLV_DB_SCALE_MASK 0xffff -#define TLV_DB_SCALE_MUTE 0x10000 -#define TLV_DB_SCALE_ITEM(min, step, mute) \ - TLV_ITEM(SNDRV_CTL_TLVT_DB_SCALE, \ - (min), \ - ((step) & TLV_DB_SCALE_MASK) | \ - ((mute) ? TLV_DB_SCALE_MUTE : 0)) -#define DECLARE_TLV_DB_SCALE(name, min, step, mute) \ - unsigned int name[] = { TLV_DB_SCALE_ITEM(min, step, mute) } +#define SNDRV_CTL_TLVD_DB_SCALE_MASK 0xffff +#define SNDRV_CTL_TLVD_DB_SCALE_MUTE 0x10000 +#define SNDRV_CTL_TLVD_DB_SCALE_ITEM(min, step, mute) \ + SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_SCALE, \ + (min), \ + ((step) & SNDRV_CTL_TLVD_DB_SCALE_MASK) | \ + ((mute) ? SNDRV_CTL_TLVD_DB_SCALE_MUTE : 0)) +#define SNDRV_CTL_TLVD_DECLARE_DB_SCALE(name, min, step, mute) \ + unsigned int name[] = { \ + SNDRV_CTL_TLVD_DB_SCALE_ITEM(min, step, mute) \ + }
/* dB scale specified with min/max values instead of step */ -#define TLV_DB_MINMAX_ITEM(min_dB, max_dB) \ - TLV_ITEM(SNDRV_CTL_TLVT_DB_MINMAX, (min_dB), (max_dB)) -#define TLV_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \ - TLV_ITEM(SNDRV_CTL_TLVT_DB_MINMAX_MUTE, (min_dB), (max_dB)) -#define DECLARE_TLV_DB_MINMAX(name, min_dB, max_dB) \ - unsigned int name[] = { TLV_DB_MINMAX_ITEM(min_dB, max_dB) } -#define DECLARE_TLV_DB_MINMAX_MUTE(name, min_dB, max_dB) \ - unsigned int name[] = { TLV_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) } +#define SNDRV_CTL_TLVD_DB_MINMAX_ITEM(min_dB, max_dB) \ + SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_MINMAX, (min_dB), (max_dB)) +#define SNDRV_CTL_TLVD_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \ + SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_MINMAX_MUTE, (min_dB), (max_dB)) +#define SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(name, min_dB, max_dB) \ + unsigned int name[] = { \ + SNDRV_CTL_TLVD_DB_MINMAX_ITEM(min_dB, max_dB) \ + } +#define SNDRV_CTL_TLVD_DECLARE_DB_MINMAX_MUTE(name, min_dB, max_dB) \ + unsigned int name[] = { \ + SNDRV_CTL_TLVD_DB_MINMAX_MUTE_ITEM(min_dB, max_dB) \ + }
/* linear volume between min_dB and max_dB (.01dB unit) */ -#define TLV_DB_LINEAR_ITEM(min_dB, max_dB) \ - TLV_ITEM(SNDRV_CTL_TLVT_DB_LINEAR, (min_dB), (max_dB)) -#define DECLARE_TLV_DB_LINEAR(name, min_dB, max_dB) \ - unsigned int name[] = { TLV_DB_LINEAR_ITEM(min_dB, max_dB) } +#define SNDRV_CTL_TLVD_DB_LINEAR_ITEM(min_dB, max_dB) \ + SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_LINEAR, (min_dB), (max_dB)) +#define SNDRV_CTL_TLVD_DECLARE_DB_LINEAR(name, min_dB, max_dB) \ + unsigned int name[] = { \ + SNDRV_CTL_TLVD_DB_LINEAR_ITEM(min_dB, max_dB) \ + }
/* dB range container: * Items in dB range container must be ordered by their values and by their @@ -78,14 +88,16 @@ * dB values (which is also required for all other mixer controls). */ /* Each item is: <min> <max> <TLV> */ -#define TLV_DB_RANGE_ITEM(...) \ - TLV_ITEM(SNDRV_CTL_TLVT_DB_RANGE, __VA_ARGS__) -#define DECLARE_TLV_DB_RANGE(name, ...) \ - unsigned int name[] = { TLV_DB_RANGE_ITEM(__VA_ARGS__) } +#define SNDRV_CTL_TLVD_DB_RANGE_ITEM(...) \ + SNDRV_CTL_TLVD_ITEM(SNDRV_CTL_TLVT_DB_RANGE, __VA_ARGS__) +#define SNDRV_CTL_TLVD_DECLARE_DB_RANGE(name, ...) \ + unsigned int name[] = { \ + SNDRV_CTL_TLVD_DB_RANGE_ITEM(__VA_ARGS__) \ + } /* The below assumes that each item TLV is 4 words like DB_SCALE or LINEAR */ -#define TLV_DB_RANGE_HEAD(num) \ +#define SNDRV_CTL_TLVD_DB_RANGE_HEAD(num) \ SNDRV_CTL_TLVT_DB_RANGE, 6 * (num) * sizeof(unsigned int)
-#define TLV_DB_GAIN_MUTE -9999999 +#define SNDRV_CTL_TLVD_DB_GAIN_MUTE -9999999
#endif
On Thu, 15 Sep 2016 00:25:18 +0200, Takashi Sakamoto wrote:
Hi,
This patchset updates my previous RFCs, and they're now for merging to upstream.
[alsa-devel] [RFC][PATCH 0/2] ALSA: control: export all of TLV related macros to user land http://mailman.alsa-project.org/pipermail/alsa-devel/2016-September/112645.h...
Currently, TLV related protocol is not shared to user land. This is not good in a point of application interfaces, because application developers can't realize the protocol just to see UAPI headers, and they're forced to look for TLV-related codes in kernel land.
This patchset moves all of macros related to TLV into UAPI header. To avoid confusions such as name conflict in user land, these macros have prefixes of 'SNDRV_CTL_TLVT_' and 'SNDRV_CTL_TLVD_'. When adding new items to the protocol, developers should use these prefixes and add them to the UAPI header.
Changes from RFC:
- Drop second patch to replace include statements
- Rename each macros to prevent applications from name conflict
This looks far better now, thanks. Applied now.
Takashi
participants (2)
-
Takashi Iwai
-
Takashi Sakamoto