From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41DA7C4363A for ; Tue, 27 Oct 2020 10:33:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DF2AB22263 for ; Tue, 27 Oct 2020 10:33:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2898380AbgJ0KdV (ORCPT ); Tue, 27 Oct 2020 06:33:21 -0400 Received: from mx2.suse.de ([195.135.220.15]:48426 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2898364AbgJ0KdH (ORCPT ); Tue, 27 Oct 2020 06:33:07 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id ACE8FAD21; Tue, 27 Oct 2020 10:33:05 +0000 (UTC) Date: Tue, 27 Oct 2020 11:33:05 +0100 Message-ID: From: Takashi Iwai To: Maxime Ripard Cc: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Dave Stevenson , Tim Gover , Phil Elwell , Dom Cobley , dri-devel@lists.freedesktop.org, Maarten Lankhorst , Thomas Zimmermann Subject: Re: [PATCH] drm/vc4: hdmi: Avoid sleeping in atomic context In-Reply-To: <20201027101558.427256-1-maxime@cerno.tech> References: <20201027101558.427256-1-maxime@cerno.tech> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 27 Oct 2020 11:15:58 +0100, Maxime Ripard wrote: > > When running the trigger hook, ALSA by default will take a spinlock, and > thus will run the trigger hook in atomic context. > > However, our HDMI driver will send the infoframes as part of the trigger > hook, and part of that process is to wait for a bit to be cleared for up to > 100ms. To be nicer to the system, that wait has some usleep_range that > interact poorly with the atomic context. > > There's several ways we can fix this, but the more obvious one is to make > ALSA take a mutex instead by setting the nonatomic flag on the DAI link. > That doesn't work though, since now the cyclic callback installed by the > dmaengine helpers in ALSA will take a mutex, while that callback is run by > dmaengine's virt-chan code in a tasklet where sleeping is not allowed > either. > > Given the delay we need to poll the bit for, changing the usleep_range for > a udelay and keep running it from a context where interrupts are disabled > is not really a good option either. > > However, we can move the infoframe setup code in the hw_params hook, like > is usually done in other HDMI controllers, that isn't protected by a > spinlock and thus where we can sleep. Infoframes will be sent on a regular > basis anyway, and since hw_params is where the audio parameters that end up > in the infoframes are setup, this also makes a bit more sense. > > Fixes: bb7d78568814 ("drm/vc4: Add HDMI audio support") > Suggested-by: Mark Brown > Signed-off-by: Maxime Ripard Reviewed-by: Takashi Iwai thanks, Takashi > --- > drivers/gpu/drm/vc4/vc4_hdmi.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c > index 74da7c00ecd0..ec3ba3ecd32a 100644 > --- a/drivers/gpu/drm/vc4/vc4_hdmi.c > +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c > @@ -1077,6 +1077,7 @@ static int vc4_hdmi_audio_hw_params(struct snd_pcm_substream *substream, > struct snd_soc_dai *dai) > { > struct vc4_hdmi *vc4_hdmi = dai_to_hdmi(dai); > + struct drm_encoder *encoder = &vc4_hdmi->encoder.base.base; > struct device *dev = &vc4_hdmi->pdev->dev; > u32 audio_packet_config, channel_mask; > u32 channel_map; > @@ -1136,6 +1137,8 @@ static int vc4_hdmi_audio_hw_params(struct snd_pcm_substream *substream, > HDMI_WRITE(HDMI_AUDIO_PACKET_CONFIG, audio_packet_config); > vc4_hdmi_set_n_cts(vc4_hdmi); > > + vc4_hdmi_set_audio_infoframe(encoder); > + > return 0; > } > > @@ -1143,11 +1146,9 @@ static int vc4_hdmi_audio_trigger(struct snd_pcm_substream *substream, int cmd, > struct snd_soc_dai *dai) > { > struct vc4_hdmi *vc4_hdmi = dai_to_hdmi(dai); > - struct drm_encoder *encoder = &vc4_hdmi->encoder.base.base; > > switch (cmd) { > case SNDRV_PCM_TRIGGER_START: > - vc4_hdmi_set_audio_infoframe(encoder); > vc4_hdmi->audio.streaming = true; > > if (vc4_hdmi->variant->phy_rng_enable) > -- > 2.26.2 >