Skip to content

Commit 4c3c1ed

Browse files
ranj063kv2019i
authored andcommitted
plugin: alsaplug: pcm: Init the global context earlier
Initialize the shared memory for the global context during init so that it can be used to store the kcontrol info during topology parsing. Move the glb_ctx field from struct snd_sof_pcm to struct snd_sof_plug so that it can be accessed during topology parsing. Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
1 parent 40c1a7d commit 4c3c1ed

2 files changed

Lines changed: 22 additions & 22 deletions

File tree

tools/plugin/alsaplug/pcm.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ typedef struct snd_sof_pcm {
4747
/* pipeline IPC response queues */
4848
struct plug_mq_desc pipeline_ipc_rx[TPLG_MAX_PCM_PIPELINES];
4949

50-
struct plug_shm_desc glb_ctx;
5150
struct plug_shm_desc shm_pcm;
5251

5352
int frame_us;
@@ -550,29 +549,13 @@ static int plug_pcm_hw_params(snd_pcm_ioplug_t *io, snd_pcm_hw_params_t *params)
550549
}
551550
}
552551

553-
/* init global status shm name */
554-
err = plug_shm_init(&pcm->glb_ctx, plug->tplg_file, "ctx", 0);
555-
if (err < 0) {
556-
SNDERR("error: invalid name for global SHM %s\n", plug->tplg_file);
557-
return err;
558-
}
559-
560552
/* init PCM shm name */
561553
err = plug_shm_init(&pcm->shm_pcm, plug->tplg_file, "pcm", plug->pcm_id);
562554
if (err < 0) {
563555
SNDERR("error: invalid name for PCM SHM %s\n", plug->tplg_file);
564556
return err;
565557
}
566558

567-
/* open the global sof-pipe context via SHM */
568-
pcm->glb_ctx.size = 128 * 1024;
569-
err = plug_shm_open(&pcm->glb_ctx);
570-
if (err < 0) {
571-
SNDERR("error: failed to open sof-pipe context: %s:%s",
572-
pcm->glb_ctx.name, strerror(err));
573-
return err;
574-
}
575-
576559
/* open audio PCM SHM data endpoint */
577560
err = plug_shm_open(&pcm->shm_pcm);
578561
if (err < 0) {
@@ -585,7 +568,7 @@ static int plug_pcm_hw_params(snd_pcm_ioplug_t *io, snd_pcm_hw_params_t *params)
585568
err = plug_init_shm_ctx(plug);
586569
if (err < 0) {
587570
SNDERR("error: failed to init sof-pipe ep context: %s:%s",
588-
pcm->glb_ctx.name, strerror(err));
571+
pcm->shm_pcm.name, strerror(err));
589572
return -err;
590573
}
591574

@@ -652,7 +635,7 @@ static int plug_pcm_close(snd_pcm_ioplug_t *io)
652635
{
653636
snd_sof_plug_t *plug = io->private_data;
654637
snd_sof_pcm_t *pcm = plug->module_prv;
655-
struct plug_shm_glb_state *ctx = pcm->glb_ctx.addr;
638+
struct plug_shm_glb_state *ctx = plug->glb_ctx.addr;
656639
int err = 0;
657640

658641
printf("%s %d\n", __func__, __LINE__);
@@ -692,7 +675,7 @@ static int plug_pcm_hw_free(snd_pcm_ioplug_t *io)
692675
return ret;
693676

694677
close(pcm->shm_pcm.fd);
695-
close(pcm->glb_ctx.fd);
678+
close(plug->glb_ctx.fd);
696679

697680
for (i = 0; i < pipeline_list->count; i++) {
698681
struct tplg_pipeline_info *pipe_info = pipeline_list->pipelines[i];
@@ -857,8 +840,7 @@ static int plug_create(snd_sof_plug_t *plug, snd_pcm_t **pcmp, const char *name,
857840

858841
static int plug_init_shm_ctx(snd_sof_plug_t *plug)
859842
{
860-
snd_sof_pcm_t *pcm = plug->module_prv;
861-
struct plug_shm_glb_state *glb = pcm->glb_ctx.addr;
843+
struct plug_shm_glb_state *glb = plug->glb_ctx.addr;
862844
struct endpoint_hw_config *ep;
863845
struct plug_cmdline_item *ci;
864846
struct plug_config *pc;
@@ -932,6 +914,22 @@ static int plug_init_sof_pipe(snd_sof_plug_t *plug, snd_pcm_t **pcmp,
932914
/* plugin only works with IPC4 */
933915
plug->tplg.ipc_major = 4;
934916

917+
/* init global status hsm name */
918+
err = plug_shm_init(&plug->glb_ctx, plug->tplg_file, "ctx", 0);
919+
if (err < 0) {
920+
SNDERR("error: invalid name for global SHM %s\n", plug->tplg_file);
921+
return err;
922+
}
923+
924+
/* open the global context via SHM */
925+
plug->glb_ctx.size = 128 * 1024;
926+
err = plug_shm_open(&plug->glb_ctx);
927+
if (err < 0) {
928+
SNDERR("error: failed to open plugin context: %s:%s",
929+
plug->glb_ctx.name, strerror(err));
930+
return err;
931+
}
932+
935933
/* parse topology file */
936934
err = plug_parse_topology(plug);
937935
if (err < 0) {

tools/plugin/alsaplug/plugin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ typedef struct snd_sof_plug {
4242
struct plug_mq_desc ipc_tx;
4343
struct plug_mq_desc ipc_rx;
4444

45+
struct plug_shm_desc glb_ctx;
46+
4547
int pcm_id;
4648
struct tplg_pcm_info *pcm_info;
4749

0 commit comments

Comments
 (0)