BACKPORT: ASoC: expand snd_soc_dpcm_mutex_lock/unlock()
soc-pcm.c has snd_soc_dpcm_mutex_lock/unlock(), but other files can't use it because it is static function. It requests snd_soc_pcm_runtime as parameter (A), but sometimes we want to use it by snd_soc_card (B). (A) static inline void snd_soc_dpcm_mutex_lock(struct snd_soc_pcm_runtime *rtd) { mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); } ^^^^^^^^^ (B) mutex_lock_nested(&card->pcm_mutex, card->pcm_subclass); ^^^^ We want to use it with both "rtd" and "card" for dapm lock/unlock. To enable it, this patch uses _Generic macro. This patch makes snd_soc_dpcm_mutex_{un}lock() global function, and use it on each files. Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Link: https://lore.kernel.org/r/87bkk1x3ud.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown <broonie@kernel.org> Bug: 303236405 (cherry picked from commit 38e42f6d6c6702bbfc633fce9b579fb80cec2d59) [ Yixuan Jiang: Fix minor conflict ] Change-Id: Id942841c7ca1642b44b1229a7bf4ab1bc5373707 Signed-off-by: Yixuan Jiang <yixuanjiang@google.com>
This commit is contained in:
parent
52771d9792
commit
edfef8fdc9
@ -1445,6 +1445,51 @@ static inline void _snd_soc_dapm_mutex_assert_held_d(struct snd_soc_dapm_context
|
||||
struct snd_soc_card * : _snd_soc_dapm_mutex_assert_held_c, \
|
||||
struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_assert_held_d)(x)
|
||||
|
||||
/*
|
||||
* PCM helper functions
|
||||
*/
|
||||
static inline void _snd_soc_dpcm_mutex_lock_c(struct snd_soc_card *card)
|
||||
{
|
||||
mutex_lock_nested(&card->pcm_mutex, card->pcm_subclass);
|
||||
}
|
||||
|
||||
static inline void _snd_soc_dpcm_mutex_unlock_c(struct snd_soc_card *card)
|
||||
{
|
||||
mutex_unlock(&card->pcm_mutex);
|
||||
}
|
||||
|
||||
static inline void _snd_soc_dpcm_mutex_assert_held_c(struct snd_soc_card *card)
|
||||
{
|
||||
lockdep_assert_held(&card->pcm_mutex);
|
||||
}
|
||||
|
||||
static inline void _snd_soc_dpcm_mutex_lock_r(struct snd_soc_pcm_runtime *rtd)
|
||||
{
|
||||
_snd_soc_dpcm_mutex_lock_c(rtd->card);
|
||||
}
|
||||
|
||||
static inline void _snd_soc_dpcm_mutex_unlock_r(struct snd_soc_pcm_runtime *rtd)
|
||||
{
|
||||
_snd_soc_dpcm_mutex_unlock_c(rtd->card);
|
||||
}
|
||||
|
||||
static inline void _snd_soc_dpcm_mutex_assert_held_r(struct snd_soc_pcm_runtime *rtd)
|
||||
{
|
||||
_snd_soc_dpcm_mutex_assert_held_c(rtd->card);
|
||||
}
|
||||
|
||||
#define snd_soc_dpcm_mutex_lock(x) _Generic((x), \
|
||||
struct snd_soc_card * : _snd_soc_dpcm_mutex_lock_c, \
|
||||
struct snd_soc_pcm_runtime * : _snd_soc_dpcm_mutex_lock_r)(x)
|
||||
|
||||
#define snd_soc_dpcm_mutex_unlock(x) _Generic((x), \
|
||||
struct snd_soc_card * : _snd_soc_dpcm_mutex_unlock_c, \
|
||||
struct snd_soc_pcm_runtime * : _snd_soc_dpcm_mutex_unlock_r)(x)
|
||||
|
||||
#define snd_soc_dpcm_mutex_assert_held(x) _Generic((x), \
|
||||
struct snd_soc_card * : _snd_soc_dpcm_mutex_assert_held_c, \
|
||||
struct snd_soc_pcm_runtime * : _snd_soc_dpcm_mutex_assert_held_r)(x)
|
||||
|
||||
#include <sound/soc-component.h>
|
||||
#include <sound/soc-card.h>
|
||||
#include <sound/soc-jack.h>
|
||||
|
@ -530,7 +530,7 @@ int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream,
|
||||
struct snd_soc_component *component;
|
||||
int i, ret = 0;
|
||||
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(rtd);
|
||||
|
||||
for_each_rtd_components(rtd, i, component) {
|
||||
if (component->driver->compress_ops &&
|
||||
@ -541,7 +541,7 @@ int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream,
|
||||
}
|
||||
}
|
||||
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
|
||||
return soc_component_ret(component, ret);
|
||||
}
|
||||
@ -554,7 +554,7 @@ int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream,
|
||||
struct snd_soc_component *component;
|
||||
int i, ret = 0;
|
||||
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(rtd);
|
||||
|
||||
for_each_rtd_components(rtd, i, component) {
|
||||
if (component->driver->compress_ops &&
|
||||
@ -565,7 +565,7 @@ int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream,
|
||||
}
|
||||
}
|
||||
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
|
||||
return soc_component_ret(component, ret);
|
||||
}
|
||||
@ -618,7 +618,7 @@ int snd_soc_component_compr_copy(struct snd_compr_stream *cstream,
|
||||
struct snd_soc_component *component;
|
||||
int i, ret = 0;
|
||||
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(rtd);
|
||||
|
||||
for_each_rtd_components(rtd, i, component) {
|
||||
if (component->driver->compress_ops &&
|
||||
@ -629,7 +629,7 @@ int snd_soc_component_compr_copy(struct snd_compr_stream *cstream,
|
||||
}
|
||||
}
|
||||
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
|
||||
return soc_component_ret(component, ret);
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ static int soc_compr_clean(struct snd_compr_stream *cstream, int rollback)
|
||||
struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
|
||||
int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
|
||||
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(rtd);
|
||||
|
||||
if (!rollback)
|
||||
snd_soc_runtime_deactivate(rtd, stream);
|
||||
@ -84,7 +84,7 @@ static int soc_compr_clean(struct snd_compr_stream *cstream, int rollback)
|
||||
if (!rollback)
|
||||
snd_soc_dapm_stream_stop(rtd, stream);
|
||||
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
|
||||
snd_soc_pcm_component_pm_runtime_put(rtd, cstream, rollback);
|
||||
|
||||
@ -107,7 +107,7 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
|
||||
if (ret < 0)
|
||||
goto err_no_lock;
|
||||
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(rtd);
|
||||
|
||||
ret = snd_soc_dai_compr_startup(cpu_dai, cstream);
|
||||
if (ret < 0)
|
||||
@ -123,7 +123,7 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
|
||||
|
||||
snd_soc_runtime_activate(rtd, stream);
|
||||
err:
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
err_no_lock:
|
||||
if (ret < 0)
|
||||
soc_compr_clean(cstream, 1);
|
||||
@ -149,7 +149,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
|
||||
if (ret < 0)
|
||||
goto be_err;
|
||||
|
||||
mutex_lock_nested(&fe->card->pcm_mutex, fe->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(fe);
|
||||
|
||||
/* calculate valid and active FE <-> BE dpcms */
|
||||
dpcm_process_paths(fe, stream, &list, 1);
|
||||
@ -187,7 +187,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
|
||||
fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
|
||||
|
||||
snd_soc_runtime_activate(fe, stream);
|
||||
mutex_unlock(&fe->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(fe);
|
||||
|
||||
mutex_unlock(&fe->card->mutex);
|
||||
|
||||
@ -214,7 +214,7 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream)
|
||||
|
||||
mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
|
||||
|
||||
mutex_lock_nested(&fe->card->pcm_mutex, fe->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(fe);
|
||||
snd_soc_runtime_deactivate(fe, stream);
|
||||
|
||||
fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
|
||||
@ -234,7 +234,7 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream)
|
||||
|
||||
dpcm_be_disconnect(fe, stream);
|
||||
|
||||
mutex_unlock(&fe->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(fe);
|
||||
|
||||
fe->dpcm[stream].runtime = NULL;
|
||||
|
||||
@ -256,7 +256,7 @@ static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd)
|
||||
int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
|
||||
int ret;
|
||||
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(rtd);
|
||||
|
||||
ret = snd_soc_component_compr_trigger(cstream, cmd);
|
||||
if (ret < 0)
|
||||
@ -276,7 +276,7 @@ static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd)
|
||||
}
|
||||
|
||||
out:
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -334,7 +334,7 @@ static int soc_compr_set_params(struct snd_compr_stream *cstream,
|
||||
int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
|
||||
int ret;
|
||||
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(rtd);
|
||||
|
||||
/*
|
||||
* First we call set_params for the CPU DAI, then the component
|
||||
@ -359,14 +359,14 @@ static int soc_compr_set_params(struct snd_compr_stream *cstream,
|
||||
|
||||
/* cancel any delayed stream shutdown that is pending */
|
||||
rtd->pop_wait = 0;
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
|
||||
cancel_delayed_work_sync(&rtd->delayed_work);
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -411,9 +411,9 @@ static int soc_compr_set_params_fe(struct snd_compr_stream *cstream,
|
||||
ret = snd_soc_link_compr_set_params(cstream);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
mutex_lock_nested(&fe->card->pcm_mutex, fe->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(fe);
|
||||
dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START);
|
||||
mutex_unlock(&fe->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(fe);
|
||||
fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
|
||||
|
||||
out:
|
||||
@ -429,7 +429,7 @@ static int soc_compr_get_params(struct snd_compr_stream *cstream,
|
||||
struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
|
||||
int ret = 0;
|
||||
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(rtd);
|
||||
|
||||
ret = snd_soc_dai_compr_get_params(cpu_dai, cstream, params);
|
||||
if (ret < 0)
|
||||
@ -437,7 +437,7 @@ static int soc_compr_get_params(struct snd_compr_stream *cstream,
|
||||
|
||||
ret = snd_soc_component_compr_get_params(cstream, params);
|
||||
err:
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -447,7 +447,7 @@ static int soc_compr_ack(struct snd_compr_stream *cstream, size_t bytes)
|
||||
struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
|
||||
int ret;
|
||||
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(rtd);
|
||||
|
||||
ret = snd_soc_dai_compr_ack(cpu_dai, cstream, bytes);
|
||||
if (ret < 0)
|
||||
@ -455,7 +455,7 @@ static int soc_compr_ack(struct snd_compr_stream *cstream, size_t bytes)
|
||||
|
||||
ret = snd_soc_component_compr_ack(cstream, bytes);
|
||||
err:
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -466,7 +466,7 @@ static int soc_compr_pointer(struct snd_compr_stream *cstream,
|
||||
int ret;
|
||||
struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
|
||||
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(rtd);
|
||||
|
||||
ret = snd_soc_dai_compr_pointer(cpu_dai, cstream, tstamp);
|
||||
if (ret < 0)
|
||||
@ -474,7 +474,7 @@ static int soc_compr_pointer(struct snd_compr_stream *cstream,
|
||||
|
||||
ret = snd_soc_component_compr_pointer(cstream, tstamp);
|
||||
out:
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -348,7 +348,7 @@ void snd_soc_close_delayed_work(struct snd_soc_pcm_runtime *rtd)
|
||||
struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
|
||||
int playback = SNDRV_PCM_STREAM_PLAYBACK;
|
||||
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(rtd);
|
||||
|
||||
dev_dbg(rtd->dev,
|
||||
"ASoC: pop wq checking: %s status: %s waiting: %s\n",
|
||||
@ -364,7 +364,7 @@ void snd_soc_close_delayed_work(struct snd_soc_pcm_runtime *rtd)
|
||||
SND_SOC_DAPM_STREAM_STOP);
|
||||
}
|
||||
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(snd_soc_close_delayed_work);
|
||||
|
||||
|
@ -49,19 +49,6 @@ static inline int _soc_pcm_ret(struct snd_soc_pcm_runtime *rtd,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline void snd_soc_dpcm_mutex_lock(struct snd_soc_pcm_runtime *rtd)
|
||||
{
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
}
|
||||
|
||||
static inline void snd_soc_dpcm_mutex_unlock(struct snd_soc_pcm_runtime *rtd)
|
||||
{
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
}
|
||||
|
||||
#define snd_soc_dpcm_mutex_assert_held(rtd) \
|
||||
lockdep_assert_held(&(rtd)->card->pcm_mutex)
|
||||
|
||||
static inline void snd_soc_dpcm_stream_lock_irq(struct snd_soc_pcm_runtime *rtd,
|
||||
int stream)
|
||||
{
|
||||
@ -2652,7 +2639,7 @@ int snd_soc_dpcm_runtime_update(struct snd_soc_card *card)
|
||||
struct snd_soc_pcm_runtime *fe;
|
||||
int ret = 0;
|
||||
|
||||
mutex_lock_nested(&card->pcm_mutex, card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(card);
|
||||
/* shutdown all old paths first */
|
||||
for_each_card_rtds(card, fe) {
|
||||
ret = soc_dpcm_fe_runtime_update(fe, 0);
|
||||
@ -2668,7 +2655,7 @@ int snd_soc_dpcm_runtime_update(struct snd_soc_card *card)
|
||||
}
|
||||
|
||||
out:
|
||||
mutex_unlock(&card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(card);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(snd_soc_dpcm_runtime_update);
|
||||
|
Loading…
Reference in New Issue
Block a user