topology: Upgrade ABI to match kernel v4.8
cover topology: Upgrade ABI to match kernel v4.8
From: Mengdong Lin <[email protected]>
Now the topology ABI version in kernel is 5, added types for BE (Backend) DAIs and sig_bits in stream caps. But the ABI version in alsa-lib is still 4, without above ABI update.
Since the kernel merge window is open and the remaining topology ABI update (v3 kernel patch series) cannot be accepted atm. So we use this series to fix the ABI mismatch between kernel v4.8 and user space, by adding types for BE DAIs and sig_bits to stream caps and pumping topolpgy ABI version to 5 as well.
This patch series also completes the support for BE DAIs.
Guneshwor Singh (3):
topology: Parse BE DAIs in text conf file
topology: Support configuring BE DAIs by C API
topology: Export BE DAIs to the binary for kernel
Mengdong Lin (2):
topology: ABI - Add the types for BE DAI
topology: ABI - Add sig_bits to stream caps
include/sound/asoc.h | 35 ++++++- include/topology.h | 45 +++++++++ src/topology/builder.c | 11 +++ src/topology/data.c | 4 + src/topology/elem.c | 4 + src/topology/parser.c | 16 ++++ src/topology/pcm.c | 238 ++++++++++++++++++++++++++++++++++++++++++++++ src/topology/tplg_local.h | 7 ++ 8 files changed, 358 insertions(+), 2 deletions(-)
Signature · 1 line
2.5.0
PATCH 1/5 topology: ABI - Add the types for BE DAI
From: Mengdong Lin <[email protected]>
Define the type and ABI struct for BE (Back End) DAIs. Add the number of BE DAIs to manifest, and add some reserved fields for future extensions. Kernel will use this ABI struct to configure existing BE DAIs registered by driver.
Pump the version number to 5.
Topology kernel driver will check size of ABI objects to detect version mismatch between user space and kernel.
include/sound/asoc.h +32 -2
@@ -74,7 +74,7 @@#define SND_SOC_TPLG_NUM_TEXTS 16/* ABI version */ -#define SND_SOC_TPLG_ABI_VERSION 0x4 +#define SND_SOC_TPLG_ABI_VERSION 0x5/* Max size of TLV data */ #define SND_SOC_TPLG_TLV_SIZE 32
@@ -96,7 +96,8 @@#define SND_SOC_TPLG_TYPE_CODEC_LINK 9#define SND_SOC_TPLG_TYPE_BACKEND_LINK 10#define SND_SOC_TPLG_TYPE_PDATA 11 -#define SND_SOC_TPLG_TYPE_MAX SND_SOC_TPLG_TYPE_PDATA +#define SND_SOC_TPLG_TYPE_BE_DAI 12 +#define SND_SOC_TPLG_TYPE_MAX SND_SOC_TPLG_TYPE_BE_DAI/* vendor block IDs - please add new vendor types to end */ #define SND_SOC_TPLG_TYPE_VENDOR_FW 1000
@@ -115,6 +116,11 @@#define SND_SOC_TPLG_TUPLE_TYPE_WORD 4#define SND_SOC_TPLG_TUPLE_TYPE_SHORT 5 +/* BE DAI flags */ +#define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_RATES (1 << 0) +#define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_CHANNELS (1 << 1) +#define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_SAMPLEBITS (1 << 2) +/* * Block Header. * This header precedes all object and object arrays below.
@@ -276,6 +282,8 @@ struct snd_soc_tplg_manifest {__le32 graph_elems;/* number of graph elements */ __le32 pcm_elems;/* number of PCM elements */ __le32 dai_link_elems;/* number of DAI link elements */ +__le32 be_dai_elems;/* number of BE DAI elements */ +__le32 reserved[20 ];/* reserved for new ABI element types */ struct snd_soc_tplg_private priv; } __attribute__((packed));
@@ -441,4 +449,26 @@ struct snd_soc_tplg_link_config {struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX ];/* supported configs playback and captrure */ __le32 num_streams;/* number of streams */ } __attribute__((packed)); + +/* +* Describes SW/FW specific features of BE DAI. +* +* File block representation for BE DAI :- +* +-----------------------------------+-----+ +* | struct snd_soc_tplg_hdr | 1 | +* +-----------------------------------+-----+ +* | struct snd_soc_tplg_be_dai | N | +* +-----------------------------------+-----+ +*/ +struct snd_soc_tplg_be_dai { +__le32 size;/* in bytes of this structure */ +char dai_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN ];/* name - used to match */ +__le32 dai_id;/* unique ID - used to match */ +__le32 playback;/* supports playback mode */ +__le32 capture;/* supports capture mode */ +struct snd_soc_tplg_stream_caps caps[2 ];/* playback and capture for DAI */ +__le32 flag_mask;/* bitmask of flags to configure */ +__le32 flags;/* SND_SOC_TPLG_DAI_FLGBIT_* */ +struct snd_soc_tplg_private priv; +} __attribute__((packed));#endif
Signature · 1 line
2.5.0
PATCH 2/5 topology: Parse BE DAIs in text conf file
In reply to [email protected]From: Guneshwor Singh <[email protected]>
Add support for parsing BE (Back End) DAIs in the text configuration file. The syntax of BE DAIs is described in document in topology.h
include/topology.h +28 -0
@@ -609,6 +609,33 @@ extern "C" {* } * </pre> * +* <h4>Back End DAI</h4> +* A BE (Back End) DAI is defined as a new section that can include a +* unique ID, playback and capture stream capabilities and optional flags. +* <br> Its PCM stream capablities are same as those for PCM objects, +* please refer to section 'PCM Capabilities'. +* +* <pre> +* SectionBEDAI."name" { +* +* index "1" # Index number +* +* id "0" # used for binding to the Backend DAI +* +* pcm."playback" { +* capabilities "capabilities1" # capabilities for playback +* } +* +* pcm."capture" { +* capabilities "capabilities2" # capabilities for capture +* } +* +* symmetric_rates "true" # optional flags +* symmetric_channels "true" +* symmetric_sample_bits "false" +* } +* </pre> +* * <h4>Manifest Private Data</h4> * Manfiest may have private data. Users need to define a manifest section * and add the references to 1 or multiple data sections. Please refer to
@@ -644,6 +671,7 @@ enum snd_tplg_type {SND_TPLG_TYPE_PCM ,/*!< PCM stream device */ SND_TPLG_TYPE_DAPM_WIDGET ,/*!< DAPM widget */ SND_TPLG_TYPE_DAPM_GRAPH ,/*!< DAPM graph elements */ +SND_TPLG_TYPE_BE_DAI ,SND_TPLG_TYPE_BE ,/*!< BE DAI link */ SND_TPLG_TYPE_CC ,/*!< Hostless codec <-> codec link */ SND_TPLG_TYPE_MANIFEST, /*!< Topology manifest */
src/topology/data.c +4 -0
@@ -46,6 +46,10 @@ struct snd_soc_tplg_private *get_priv_data(struct tplg_elem *elem) priv = &elem->widget->priv;break ; +case SND_TPLG_TYPE_BE_DAI : + priv = &elem->be_dai->priv; +break ; +default :SNDERR ("error: '%s': no support for private data for type %d\n" , elem->id, elem->type);
src/topology/elem.c +4 -0
@@ -189,6 +189,10 @@ struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg,list_add_tail (&elem->list, &tplg->pcm_list); obj_size =sizeof (struct snd_soc_tplg_pcm );break ; +case SND_TPLG_TYPE_BE_DAI : +list_add_tail (&elem->list, &tplg->be_dai_list); + obj_size =sizeof (struct snd_soc_tplg_be_dai ); +break ;case SND_TPLG_TYPE_BE :list_add_tail (&elem->list, &tplg->be_list); obj_size =sizeof (struct snd_soc_tplg_link_config );
src/topology/parser.c +10 -0
@@ -133,6 +133,14 @@ static int tplg_parse_config(snd_tplg_t *tplg, snd_config_t *cfg)continue ; } +if (strcmp (id,"SectionBEDAI" ) ==0 ) { + err =tplg_parse_compound (tplg, n, + tplg_parse_be_dai,NULL ); +if (err <0 ) +return err; +continue ; + } +if (strcmp (id,"SectionBE" ) ==0 ) { err =tplg_parse_compound (tplg, n, tplg_parse_be,NULL );
@@ -440,6 +448,7 @@ snd_tplg_t *snd_tplg_new(void)INIT_LIST_HEAD (&tplg->tlv_list);INIT_LIST_HEAD (&tplg->widget_list);INIT_LIST_HEAD (&tplg->pcm_list); +INIT_LIST_HEAD (&tplg->be_dai_list);INIT_LIST_HEAD (&tplg->be_list);INIT_LIST_HEAD (&tplg->cc_list);INIT_LIST_HEAD (&tplg->route_list);
@@ -465,6 +474,7 @@ void snd_tplg_free(snd_tplg_t *tplg)tplg_elem_free_list (&tplg->tlv_list);tplg_elem_free_list (&tplg->widget_list);tplg_elem_free_list (&tplg->pcm_list); +tplg_elem_free_list (&tplg->be_dai_list);tplg_elem_free_list (&tplg->be_list);tplg_elem_free_list (&tplg->cc_list);tplg_elem_free_list (&tplg->route_list);
src/topology/pcm.c +126 -0
144 lines not on this page · raw message
src/topology/tplg_local.h +5 -0
@@ -64,6 +64,7 @@ struct snd_tplg {struct list_head tlv_list;struct list_head widget_list;struct list_head pcm_list; +struct list_head be_dai_list;struct list_head be_list;struct list_head cc_list;struct list_head route_list;
@@ -144,6 +145,7 @@ struct tplg_elem {struct snd_soc_tplg_bytes_control *bytes_ext;struct snd_soc_tplg_dapm_widget *widget;struct snd_soc_tplg_pcm *pcm; +struct snd_soc_tplg_be_dai *be_dai;struct snd_soc_tplg_link_config *be;struct snd_soc_tplg_link_config *cc;struct snd_soc_tplg_dapm_graph_elem *route;
@@ -221,6 +223,9 @@ int tplg_parse_stream_caps(snd_tplg_t *tplg,int tplg_parse_pcm (snd_tplg_t *tplg, snd_config_t *cfg, void *private ATTRIBUTE_UNUSED); +int tplg_parse_be_dai (snd_tplg_t *tplg, + snd_config_t *cfg, void *private ATTRIBUTE_UNUSED); +int tplg_parse_be (snd_tplg_t *tplg, snd_config_t *cfg, void *private ATTRIBUTE_UNUSED);
Signature · 1 line
2.5.0
PATCH 3/5 topology: Support configuring BE DAIs by C API
In reply to [email protected]From: Guneshwor Singh <[email protected]>
In addition to text conf file, BE (Back End) DAI configurations can also be added by C API. This patch defines the template to add BE DAI configurations from C API.
include/topology.h +16 -0
@@ -894,6 +894,21 @@ struct snd_tplg_pcm_template {struct snd_tplg_stream_template stream[0 ];/*!< supported configs */ }; +/** \struct snd_tplg_be_dai_template +* \brief Template type for Back End DAI. +*/ +struct snd_tplg_be_dai_template { +const char *dai_name;/*!< DAI name */ +unsigned int dai_id;/*!< unique ID - used to match */ +unsigned int playback;/*!< supports playback mode */ +unsigned int capture;/*!< supports capture mode */ +struct snd_tplg_stream_caps_template *caps[2 ];/*!< playback & capture for DAI */ +unsigned int flag_mask;/*!< bitmask of flags to configure */ +unsigned int flags;/*!< SND_SOC_TPLG_DAI_FLGBIT_* */ +struct snd_soc_tplg_private *priv;/*!< private data */ + +}; +/** \struct snd_tplg_link_template * \brief Template type for BE and CC DAI Links. */
@@ -919,6 +934,7 @@ typedef struct snd_tplg_obj_template {struct snd_tplg_enum_template *enum_ctl;/*!< Enum control */ struct snd_tplg_graph_template *graph;/*!< Graph elements */ struct snd_tplg_pcm_template *pcm;/*!< PCM elements */ +struct snd_tplg_be_dai_template *be_dai;/*!< BE DAI elements */ struct snd_tplg_link_template *link;/*!< BE and CC Links */ }; } snd_tplg_obj_template_t;
src/topology/parser.c +2 -0
@@ -355,6 +355,8 @@ int snd_tplg_add_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)return tplg_add_graph_object (tplg, t);case SND_TPLG_TYPE_PCM :return tplg_add_pcm_object (tplg, t); +case SND_TPLG_TYPE_BE_DAI : +return tplg_add_be_dai_object (tplg, t);case SND_TPLG_TYPE_BE :case SND_TPLG_TYPE_CC :return tplg_add_link_object (tplg, t);
src/topology/pcm.c +55 -0
58 lines not on this page · raw message
src/topology/tplg_local.h +1 -0
@@ -293,3 +293,4 @@ int tplg_build_pcm(snd_tplg_t *tplg, unsigned int type);int tplg_build_link_cfg (snd_tplg_t *tplg,unsigned int type);int tplg_add_link_object (snd_tplg_t *tplg,snd_tplg_obj_template_t *t);int tplg_add_pcm_object (snd_tplg_t *tplg,snd_tplg_obj_template_t *t); +int tplg_add_be_dai_object (snd_tplg_t *tplg,snd_tplg_obj_template_t *t);
Signature · 1 line
2.5.0
PATCH 4/5 topology: Export BE DAIs to the binary for kernel
In reply to [email protected]From: Guneshwor Singh <[email protected]>
Export the BE (back-end) DAI objects to the binary output file for kernel. For BE DAIs defined by the text conf file, find and merge their stream capablities before exporting.
src/topology/builder.c +11 -0
@@ -204,6 +204,9 @@ static int write_block(snd_tplg_t *tplg, struct list_head *base,case SND_TPLG_TYPE_DATA :return write_elem_block (tplg, base, size,SND_SOC_TPLG_TYPE_PDATA ,"data" ); +case SND_TPLG_TYPE_BE_DAI : +return write_elem_block (tplg, base, size, +SND_SOC_TPLG_TYPE_BE_DAI ,"be_dai" );default :return -EINVAL ; }
@@ -293,6 +296,14 @@ int tplg_write_data(snd_tplg_t *tplg)return ret; } +/* write be dai elems */ + ret =write_block (tplg, &tplg->be_dai_list, +SND_TPLG_TYPE_BE_DAI ); +if (ret <0 ) { +SNDERR ("failed to write be dai elems %d\n" , ret); +return ret; + } +/* write be elems */ ret =write_block (tplg, &tplg->be_list,SND_TPLG_TYPE_BE );
src/topology/parser.c +4 -0
@@ -279,6 +279,10 @@ static int tplg_build_integ(snd_tplg_t *tplg)if (err <0 )return err; + err =tplg_build_be_dais (tplg,SND_TPLG_TYPE_BE_DAI ); +if (err <0 ) +return err; + err =tplg_build_link_cfg (tplg,SND_TPLG_TYPE_BE );if (err <0 )return err;
src/topology/pcm.c +56 -0
62 lines not on this page · raw message
src/topology/tplg_local.h +1 -0
@@ -290,6 +290,7 @@ int tplg_add_bytes(snd_tplg_t *tplg, struct snd_tplg_bytes_template *bytes_ctl, struct tplg_elem **e);int tplg_build_pcm (snd_tplg_t *tplg,unsigned int type); +int tplg_build_be_dais (snd_tplg_t *tplg,unsigned int type);int tplg_build_link_cfg (snd_tplg_t *tplg,unsigned int type);int tplg_add_link_object (snd_tplg_t *tplg,snd_tplg_obj_template_t *t);int tplg_add_pcm_object (snd_tplg_t *tplg,snd_tplg_obj_template_t *t);
Signature · 1 line
2.5.0
PATCH 5/5 topology: ABI - Add sig_bits to stream caps
In reply to [email protected]From: Mengdong Lin <[email protected]>
Add sig_bits to stream caps and also add it to stream caps template of C API.
include/sound/asoc.h +1 -0
@@ -248,6 +248,7 @@ struct snd_soc_tplg_stream_caps {__le32 period_size_max;/* max period size bytes */ __le32 buffer_size_min;/* min buffer size bytes */ __le32 buffer_size_max;/* max buffer size bytes */ +__le32 sig_bits;/* number of bits of content */ } __attribute__((packed));/*
include/topology.h +1 -0
@@ -876,6 +876,7 @@ struct snd_tplg_stream_caps_template {unsigned int period_size_max;/*!< max period size bytes */ unsigned int buffer_size_min;/*!< min buffer size bytes */ unsigned int buffer_size_max;/*!< max buffer size bytes */ +unsigned int sig_bits;/*!< number of bits of content */ };/** \struct snd_tplg_pcm_template
src/topology/pcm.c +1 -0
@@ -754,6 +754,7 @@ static void tplg_add_stream_caps(struct snd_soc_tplg_stream_caps *caps, caps->period_size_max = caps_tpl->period_size_max; caps->buffer_size_min = caps_tpl->buffer_size_min; caps->buffer_size_max = caps_tpl->buffer_size_max; + caps->sig_bits = caps_tpl->sig_bits; }int tplg_add_pcm_object (snd_tplg_t *tplg,snd_tplg_obj_template_t *t)
Signature · 1 line
2.5.0
Re: [PATCH 1/5] topology: ABI - Add the types for BE DAI
In reply to [email protected]Quoted 1 line · On Mon, Oct 03, 2016 at 11:03:50PM +0800, [email protected] wrote:
Pump the version number to 5.
So, we just had a user on IRC complaining that the last round of incompatible changes in v4.7 broke their laptop audio - they had a laptop that shipped with Linux and suddenly the topology file didn't work. I think that's an indication that at this point we have an ABI we need to maintain compatibility with rather than just break things. That doesn't explicitly affect this patch but does mean that the parsing code ought to cope which is likely to have some impact here.
Quoted 2 lines
Topology kernel driver will check size of ABI objects to detect version mismatch between user space and kernel.
The ABI wasn't explicitly reved which suggests that it's this that triggered the issue for the user.
include/sound/asoc.h line 122
Quoted 4 lines
include/sound/asoc.h +4
-0+/* BE DAI flags */ +#define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_RATES (1 << 0) +#define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_CHANNELS (1 << 1) +#define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_SAMPLEBITS (1 << 2)
These don't seem specific to back ends, people can use topologies for DSPs on off-SoC devices which might also want to use these.
include/sound/asoc.h struct snd_soc_tplg_manifest { · line 286
Quoted 2 lines
include/sound/asoc.h +2
-0+__le32 be_dai_elems;/* number of BE DAI elements */ +__le32 reserved[20 ];/* reserved for new ABI element types */
Thinking about the above I'm wondering if it doesn't make more sense to call these physical links rather than back ends - that term is going to be clearer to people who don't use DPCM.
Re: [PATCH 1/5] topology: ABI - Add the types for BE DAI
Quoted 12 lines · Mark Brown
Quoted 1 line · On Mon, Oct 03, 2016 at 11:03:50PM +0800, [email protected] wrote:
Pump the version number to 5.
So, we just had a user on IRC complaining that the last round of incompatible changes in v4.7 broke their laptop audio - they had a laptop that shipped with Linux and suddenly the topology file didn't work. I think that's an indication that at this point we have an ABI we need to maintain compatibility with rather than just break things. That doesn't explicitly affect this patch but does mean that the parsing code ought to cope which is likely to have some impact here.
Quoted 5 lines
Quoted 2 lines
Topology kernel driver will check size of ABI objects to detect version mismatch between user space and kernel.
The ABI wasn't explicitly reved which suggests that it's this that triggered the issue for the user.
Yes. Now if the kernel finds a mismatch of ABI object size, it will just return error and so old version of topology files cannot work. We'll try to support ABI version 4 and new versions in kernel. It seems topology have real users from version 4.
Quoted 8 lines
include/sound/asoc.h line 122
Quoted 5 lines
include/sound/asoc.h +4
-0+/* BE DAI flags */ +#define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_RATES (1 << 0) +#define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_CHANNELS (1 << 1) +#define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_SAMPLEBITS (1 << 2)These don't seem specific to back ends, people can use topologies for DSPs on off-SoC devices which might also want to use these.
Yes. Can we take them as generic flags for DAI and DAI links?
Quoted 8 lines
include/sound/asoc.h struct snd_soc_tplg_manifest { · line 286
Quoted 3 lines
include/sound/asoc.h +2
-0+__le32 be_dai_elems;/* number of BE DAI elements */ +__le32 reserved[20 ];/* reserved for new ABI element types */ Thinking about the above I'm wondering if it doesn't make more sense to call these physical links rather than back ends - that term is going to be clearer to people who don't use DPCM.
May we call it a "phy_dai_elems", to indicate physical DAIs?
Now the ABI struct "snd_soc_tplg_be_dai" is already in kernel but no real users in user space. Can we rename it? Or add a new ABI struct?
Thanks
Mengdong
Re: [PATCH 1/5] topology: ABI - Add the types for BE DAI
In reply to Mark BrownQuoted 12 lines · Mark Brown
Quoted 1 line · On Mon, Oct 03, 2016 at 11:03:50PM +0800, [email protected] wrote:
Pump the version number to 5.
So, we just had a user on IRC complaining that the last round of incompatible changes in v4.7 broke their laptop audio - they had a laptop that shipped with Linux and suddenly the topology file didn't work. I think that's an indication that at this point we have an ABI we need to maintain compatibility with rather than just break things. That doesn't explicitly affect this patch but does mean that the parsing code ought to cope which is likely to have some impact here.
Quoted 5 lines
Quoted 2 lines
Topology kernel driver will check size of ABI objects to detect version mismatch between user space and kernel.
The ABI wasn't explicitly reved which suggests that it's this that triggered the issue for the user.
I've submitted topology kernel patches v6 to solve the compatibility issue caused by ABI mismatch. Now the kernel can handle topology files generated by ABI v4, which is published by alsa-lib v1.1.0 in last November. Please review.
So we can hold on user space ABI updates until all kernel patches being reviewed and merged.
Quoted 7 lines
include/sound/asoc.h line 122
Quoted 4 lines
include/sound/asoc.h +4
-0+/* BE DAI flags */ +#define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_RATES (1 << 0) +#define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_CHANNELS (1 << 1) +#define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_SAMPLEBITS (1 << 2)These don't seem specific to back ends, people can use topologies for DSPs on off-SoC devices which might also want to use these.
'BE' is removed in the comments, in kernel side at first.
Quoted 8 lines
include/sound/asoc.h struct snd_soc_tplg_manifest { · line 286
Quoted 3 lines
include/sound/asoc.h +2
-0+__le32 be_dai_elems;/* number of BE DAI elements */ +__le32 reserved[20 ];/* reserved for new ABI element types */ Thinking about the above I'm wondering if it doesn't make more sense to call these physical links rather than back ends - that term is going to be clearer to people who don't use DPCM.
"be_dai_elems" is renamed to "dai_elems" in kernel side at first, and this change is backward compatible.
Thanks
Mengdong