From patchwork Mon Jun 15 06:21:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 6606261 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 99BD89F399 for ; Mon, 15 Jun 2015 06:22:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 96FFD20569 for ; Mon, 15 Jun 2015 06:22:10 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 46A6520567 for ; Mon, 15 Jun 2015 06:22:09 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 4A3A926128B; Mon, 15 Jun 2015 08:22:08 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 12FC126068D; Mon, 15 Jun 2015 08:21:39 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 98B6826069D; Mon, 15 Jun 2015 08:21:38 +0200 (CEST) Received: from relmlie1.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by alsa0.perex.cz (Postfix) with ESMTP id D9219260410 for ; Mon, 15 Jun 2015 08:21:19 +0200 (CEST) Received: from unknown (HELO relmlir3.idc.renesas.com) ([10.200.68.153]) by relmlie1.idc.renesas.com with ESMTP; 15 Jun 2015 15:21:18 +0900 Received: from relmlac4.idc.renesas.com (relmlac4.idc.renesas.com [10.200.69.24]) by relmlir3.idc.renesas.com (Postfix) with ESMTP id 1B8F0456AE; Mon, 15 Jun 2015 15:21:18 +0900 (JST) Received: by relmlac4.idc.renesas.com (Postfix, from userid 0) id 05774480A4; Mon, 15 Jun 2015 15:21:17 +0900 (JST) Received: from relmlac4.idc.renesas.com (localhost [127.0.0.1]) by relmlac4.idc.renesas.com (Postfix) with ESMTP id E6FA7480A3; Mon, 15 Jun 2015 15:21:17 +0900 (JST) Received: from relmlii1.idc.renesas.com [10.200.68.65] by relmlac4.idc.renesas.com with ESMTP id RAA06689; Mon, 15 Jun 2015 15:21:17 +0900 X-IronPort-AV: E=Sophos;i="5.13,617,1427727600"; d="scan'";a="188302057" Received: from mail-hk1lp0117.outbound.protection.outlook.com (HELO APAC01-HK1-obe.outbound.protection.outlook.com) ([207.46.51.117]) by relmlii1.idc.renesas.com with ESMTP/TLS/AES256-SHA; 15 Jun 2015 15:21:16 +0900 Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none; Received: from morimoto-PC.renesas.com (211.11.155.132) by SIXPR06MB318.apcprd06.prod.outlook.com (10.141.125.144) with Microsoft SMTP Server (TLS) id 15.1.190.14; Mon, 15 Jun 2015 06:21:15 +0000 Message-ID: <87r3pdv6ic.wl%kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto User-Agent: Wanderlust/2.15.9 Emacs/24.3 Mule/6.0 To: Mark Brown In-Reply-To: <87twu9v6kn.wl%kuninori.morimoto.gx@renesas.com> References: <87twu9v6kn.wl%kuninori.morimoto.gx@renesas.com> MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Date: Mon, 15 Jun 2015 06:21:15 +0000 X-Originating-IP: [211.11.155.132] X-ClientProxiedBy: OS1PR01CA0045.jpnprd01.prod.outlook.com (25.164.162.9) To SIXPR06MB318.apcprd06.prod.outlook.com (10.141.125.144) X-Microsoft-Exchange-Diagnostics: 1; SIXPR06MB318; 2:Xo33Zv9EZLpzeGQQV1LGczPoWrMeSgy74otHxQzqoWXAtKDqQnHnSaRdX8p5bmaq; 2:czQCm6MWw6IHczuvltUojYDK7huwkiXMdJY4MtAXwVuH7q9XPE4Ya/dQqiPYbyTf4I9xsJL/fgiTpX/KlCos/uXrD+2Jll1mPHD92aFw0+1hzMOt2HsoLrHrfOafccHmF9NaUnmig9wxq2GjgjlyxQ==; 6:jHk7UmB86+E3QkJ+GA2O0HLH4rK4Vs2oRj6ehPKDv08eeb/2uRIiwiTbPXAtop9iAWUG013PwLykJf+1kkVjccWGavlIrHHxUZIvxtFcQugae7TA6X7m2FWnsBaWN4udTjrutO7rDEhw+tAB375EhAyvVsKlI6plhQ2d679yzehmBEVA33zEf5KcHwU2YJgccrhRH1T5X0tfjD8KnGIGBJwDGGSoKyd3Zq4FPffmh62lXtUi+bmKPIf36GvL4reXBAFSz3l4Ljkrke4xDfa17as727dDOWPAIBtCZHvdGlB+Ef8Tkc8RNfBtXJJmka0LZyk6RyxLOBJW+aVUAfD+3ciiws/m340N8tsZKBOK2EwdIEOIHx5z12i25PhRc9zFxsYsz7qF/0Cyc9MtE9e3CV5ZqYeHeJUrDocp2AVBsW+3U100KvfBVIrdjDTAkQs+JvH9zxSzGvVAYIbelfT1O1xbbAly4PRsBTqoCMNGFRsX7P/XX4uewNBWwgkwrRrB X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SIXPR06MB318; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(520003)(3002001); SRVR:SIXPR06MB318; BCL:0; PCL:0; RULEID:; SRVR:SIXPR06MB318; X-Microsoft-Exchange-Diagnostics: 1; SIXPR06MB318; 3:dGctcgTQ/x/EoNki+p3BVU1TBnF8OTvohJpgo36n88g87PrZu6sMxJVFAc0WjBFfra8dkZH4hRMOg3UHVChvifj4LCDxpx4pO3qSZuMqwaxexPCiIhhTsQfxAxwpQgOLZSm+QrSpaQ9LdsylasrdWepG4krfBEfHiD1NcoHo+EEsEpBH2fPEIsAdyAbO0LME3Ubofo4Hj366enVBri8x/0MPdmAILoFaYEkfO/z2wSDQJdZSftphBdHWfFmo4xIB2iUB1u+lQy6jKLO/IqrwP3ZMsxQBkQ6BPupgnRToV+/KWJFBpNf6/zqXtGr0k2M5 X-Forefront-PRVS: 0608DEDB67 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(2950100001)(66066001)(50986999)(76176999)(54356999)(4001350100001)(42186005)(19580405001)(46102003)(87976001)(86362001)(33646002)(229853001)(47776003)(19580395003)(92566002)(36756003)(77096005)(23726002)(189998001)(77156002)(62966003)(122386002)(40100003)(83506001)(53416004)(50466002)(5001960100002)(110136002); DIR:OUT; SFP:1102; SCL:1; SRVR:SIXPR06MB318; H:morimoto-PC.renesas.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; SIXPR06MB318; 9:FHlI6cx1ELaWNMDRBEQhUHp43QuaDQml593+ukCU6Oi4pT2S74LiJuO3LSR7BHGD6mw1fHNSotdPPYPwcVFMl9AriTwK4MJdSNRKS1x58cn9inBnw4gK26HZLW4MUNrAoy3UJ+HOSPglme1aZt+/B3AzpoJNLGG87OmZew9kqjRLhz/VDOdAD0ATzHJ9HHdE6imq6c1+3s4a27Dt1HsGPQi0IZ0DJYjaPhzuD2dHzqXUQSVV9TududEAhf7hOCrnw/bRlVH/WwoX9srjmnHXNqsCTaKyIjzKUhHWs0oZlrJAb6ZwIIUmeMazpmFgc6Job6dceKhNkohoKY0CrET+hoqBbcoIfj15TNttgWz7zAMCzD2c3HqLcnB1VrH+2UUIdyapWZVS2doCUaWCjHLNtm1vw7tx1pa3qtWmtWA3iKMFYqu7WsNfqu5wNDAxBdif7A9/mHRsedN9/hEKHEMf8jFed7QYvkTjUA4bNcuwj9946HYhvraLeRxc7CCTrqkwXZJHzpuGfEh6KoxV0+Wk1/E5C1MCdqyRjJwqhCQG/3sA8iLZXjAcCL2CrSI5KZGFsXo4D7pwTfBjXByhJwdQIQ7mRHn+Oln0mXF/di8fUDNzw8OWy2ZWLEsqOE725R3b0XWByFLJEc1TibHGKBZMrZpSgQYaeBh7qOQXKhxu0z+46+Ba0hS8OvvNQD0DH6yAYScTokpnuKVBZ4MLQPe+n8oNqkx/d9zFMXhAczXUGaJdvgCN52qvfSZtUVHcxHpzT3g4BRqhkMH6u68Xgw/nQuwOPVBWTxiHl6XHbAlMcAKjkUa0ahBw0EgdqX7i/5cw6BGM/PmlKTgI6YPFuOkUYA== X-Microsoft-Exchange-Diagnostics: 1; SIXPR06MB318; 3:e3D2Okvt6xt4MtuAah8URS69ZSpBE+8e1XYqQYq7eSOAODHEm2iqxkqUq6/bwsvUfkJ1GYL5A5vWyI2smLr1ulo/v7PdS+WzxEvv2xoLKZ32UEN2eCwZN03Wr2W5nDMTD/4wAEPPALvQIY7lMdYAgA==; 10:PtRywDxdtyMCUSVjNEDwXwy36oyfmmh45s/tQnGLaBwaA0OjgCVGqPifYV2qZm+hj+NaYbYOSDd0m0sPRv75WMjRj4JI+qEOtagif3bZz/0=; 6:iM4xFEdewzrTVwUJs+MGUlfPEbAkkm2QesISwn78kTJhIDccP+1xuuyObdW+MjRKDX2sLa7NctX1qLEPZym4pvCeBKQcHl/CIzkJ+AhH9tUGh8za7X1EtihT6EAI9F76bCvxN096zgi3xlcrHipfCQ== X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jun 2015 06:21:15.4734 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SIXPR06MB318 Cc: Linux-ALSA , Simon , Liam Girdwood Subject: [alsa-devel] [PATCH 02/21] ASoC: rsnd: don't call snd_pcm_period_elapsed() under spin lock X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Kuninori Morimoto 'a9e1ac1a9e4585b5("ASoC: rsnd: spin lock for interrupt handler")' added spin lock under interrupt handler to solve HW restart issue. OTOH, current rsnd driver calls snd_pcm_period_elapsed() from rsnd_dai_pointer_update(). but, it will be called under spin lock if SSI was PIO mode. If it was called under spin lock, it will call snd_pcm_update_state() -> snd_pcm_drain_done(). Then, it calls rsnd_soc_dai_trigger() and will be dead-lock. This patch doesn't call rsnd_dai_pointer_update() under spin lock Signed-off-by: Kuninori Morimoto Tested-by: Keita Kobayashi --- sound/soc/sh/rcar/core.c | 20 ++++++++++++++++++-- sound/soc/sh/rcar/dma.c | 11 ++++++++++- sound/soc/sh/rcar/rsnd.h | 3 ++- sound/soc/sh/rcar/ssi.c | 6 +++++- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c index d460d2a..027b043 100644 --- a/sound/soc/sh/rcar/core.c +++ b/sound/soc/sh/rcar/core.c @@ -302,7 +302,7 @@ int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional) return pos; } -void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int byte) +bool rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int byte) { io->byte_pos += byte; @@ -319,8 +319,24 @@ void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int byte) io->next_period_byte = io->byte_per_period; } - snd_pcm_period_elapsed(substream); + return true; } + + return false; +} + +void rsnd_dai_period_elapsed(struct rsnd_dai_stream *io) +{ + struct snd_pcm_substream *substream = io->substream; + + /* + * this function should be called... + * + * - if rsnd_dai_pointer_update() returns true + * - without spin lock + */ + + snd_pcm_period_elapsed(substream); } static void rsnd_dai_stream_init(struct rsnd_dai_stream *io, diff --git a/sound/soc/sh/rcar/dma.c b/sound/soc/sh/rcar/dma.c index 144308f..ac19ab1 100644 --- a/sound/soc/sh/rcar/dma.c +++ b/sound/soc/sh/rcar/dma.c @@ -36,7 +36,10 @@ static void rsnd_dmaen_complete(void *data) { struct rsnd_dma *dma = (struct rsnd_dma *)data; struct rsnd_mod *mod = rsnd_dma_to_mod(dma); + struct rsnd_priv *priv = rsnd_mod_to_priv(mod); struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); + bool elapsed = false; + unsigned long flags; /* * Renesas sound Gen1 needs 1 DMAC, @@ -49,8 +52,14 @@ static void rsnd_dmaen_complete(void *data) * rsnd_dai_pointer_update() will be called twice, * ant it will breaks io->byte_pos */ + spin_lock_irqsave(&priv->lock, flags); + + elapsed = rsnd_dai_pointer_update(io, io->byte_per_period); + + spin_unlock_irqrestore(&priv->lock, flags); - rsnd_dai_pointer_update(io, io->byte_per_period); + if (elapsed) + rsnd_dai_period_elapsed(io); } static void rsnd_dmaen_stop(struct rsnd_dma *dma) diff --git a/sound/soc/sh/rcar/rsnd.h b/sound/soc/sh/rcar/rsnd.h index 03ff071..e37234e 100644 --- a/sound/soc/sh/rcar/rsnd.h +++ b/sound/soc/sh/rcar/rsnd.h @@ -355,7 +355,8 @@ struct rsnd_dai { struct rsnd_dai *rsnd_rdai_get(struct rsnd_priv *priv, int id); -void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int cnt); +bool rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int cnt); +void rsnd_dai_period_elapsed(struct rsnd_dai_stream *io); int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional); /* diff --git a/sound/soc/sh/rcar/ssi.c b/sound/soc/sh/rcar/ssi.c index 8569173..2548321 100644 --- a/sound/soc/sh/rcar/ssi.c +++ b/sound/soc/sh/rcar/ssi.c @@ -426,6 +426,7 @@ static irqreturn_t rsnd_ssi_interrupt(int irq, void *data) struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); int is_dma = rsnd_ssi_is_dma_mode(mod); u32 status; + bool elapsed = false; spin_lock(&priv->lock); @@ -451,7 +452,7 @@ static irqreturn_t rsnd_ssi_interrupt(int irq, void *data) else *buf = rsnd_mod_read(mod, SSIRDR); - rsnd_dai_pointer_update(io, sizeof(*buf)); + elapsed = rsnd_dai_pointer_update(io, sizeof(*buf)); } /* DMA only */ @@ -476,6 +477,9 @@ static irqreturn_t rsnd_ssi_interrupt(int irq, void *data) rsnd_ssi_interrupt_out: spin_unlock(&priv->lock); + if (elapsed) + rsnd_dai_period_elapsed(io); + return IRQ_HANDLED; }