From patchwork Wed Jan 16 05:04:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q0sgSHUgKOiDoeS/iuWFiSk=?= X-Patchwork-Id: 10765409 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5A4B013BF for ; Wed, 16 Jan 2019 05:07:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 488822B1AF for ; Wed, 16 Jan 2019 05:07:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C46B2B1E8; Wed, 16 Jan 2019 05:07:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D974D2B1AF for ; Wed, 16 Jan 2019 05:07:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ZGDLLu4x7DVmbQljnE0qWVeaTLii4mEybOWjDQvzh5c=; b=k47VoMBTHaU8wm 4EsfeGKPwPkOUXAIL87JXu72cuL6kLz4iez0ieIWLoYai1CWduXW92zLFNpqIjlSO9tmELQjp1nn5 /ya22RDXHYlyRsZVCR1wpyedmc7pRtWJnqaq6Qdhpgysdksvw8s8kWW4y/Yyfk5tZjo1FsOJpSZB/ QHRXG1AB5BXIMAorQSVk0HGdf6BYs18j8jzVfritM8VOHwFFdfuUXHWI8dnGtA3CViIdpBK7VvKNO Yr7Ci0OPA7B9Q7qpaKQ1zmgBJ91zsBUUpFfem6XikvXJEJVLooWLK9dF9TCC8TIq55KkxlGL6IRLr OqRw6LburGf4aZ/ODhjQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gjdQT-0005nL-7C; Wed, 16 Jan 2019 05:07:41 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gjdQI-0005e8-DP; Wed, 16 Jan 2019 05:07:32 +0000 X-UUID: 8b5212d391bf4da7ab5536a35a87e50f-20190115 X-UUID: 8b5212d391bf4da7ab5536a35a87e50f-20190115 Received: from mtkcas68.mediatek.inc [(172.29.94.19)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1264960476; Tue, 15 Jan 2019 21:07:25 -0800 Received: from mtkmbs03n1.mediatek.inc (172.21.101.181) by MTKMBS62DR.mediatek.inc (172.29.94.18) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 15 Jan 2019 21:07:24 -0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs03n1.mediatek.inc (172.21.101.181) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 16 Jan 2019 13:07:22 +0800 Received: from mtkslt305.mediatek.inc (10.21.14.140) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Wed, 16 Jan 2019 13:07:22 +0800 From: CK Hu To: Jassi Brar , Matthias Brugger , Houlong Wei Subject: [PATCH 1/3] mailbox: Add ability for clients to abort data in channel Date: Wed, 16 Jan 2019 13:04:33 +0800 Message-ID: <20190116050435.11624-2-ck.hu@mediatek.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20190116050435.11624-1-ck.hu@mediatek.com> References: <20190116050435.11624-1-ck.hu@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190115_210730_459907_B0239ED7 X-CRM114-Status: GOOD ( 13.85 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: CK Hu , srv_heupstream@mediatek.com, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch supplies a new framework API, mbox_abort_channel(), and a new controller interface, abort_data(). For some client's application, it need to clean up the data in channel but keep the channel so it could send data to channel later. Signed-off-by: CK Hu --- drivers/mailbox/mailbox.c | 23 +++++++++++++++++++++++ include/linux/mailbox_client.h | 1 + include/linux/mailbox_controller.h | 4 ++++ 3 files changed, 28 insertions(+) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index c6a7d4582dc6..281647162c76 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -428,6 +428,29 @@ struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl, } EXPORT_SYMBOL_GPL(mbox_request_channel_byname); +/** + * mbox_abort_channel - The client abort all data in a mailbox + * channel by this call. + * @chan: The mailbox channel to be aborted. + */ +void mbox_abort_channel(struct mbox_chan *chan) +{ + unsigned long flags; + + if (!chan || !chan->cl) + return; + + if (chan->mbox->ops->abort_data) + chan->mbox->ops->abort_data(chan); + + /* The queued TX requests are simply aborted, no callbacks are made */ + spin_lock_irqsave(&chan->lock, flags); + chan->cl = NULL; + chan->active_req = NULL; + spin_unlock_irqrestore(&chan->lock, flags); +} +EXPORT_SYMBOL_GPL(mbox_abort_channel); + /** * mbox_free_channel - The client relinquishes control of a mailbox * channel by this call. diff --git a/include/linux/mailbox_client.h b/include/linux/mailbox_client.h index faa7da3c9c8b..209d1d458029 100644 --- a/include/linux/mailbox_client.h +++ b/include/linux/mailbox_client.h @@ -47,6 +47,7 @@ int mbox_send_message(struct mbox_chan *chan, void *mssg); int mbox_flush(struct mbox_chan *chan, unsigned long timeout); void mbox_client_txdone(struct mbox_chan *chan, int r); /* atomic */ bool mbox_client_peek_data(struct mbox_chan *chan); /* atomic */ +void mbox_abort_channel(struct mbox_chan *chan); /* may sleep */ void mbox_free_channel(struct mbox_chan *chan); /* may sleep */ #endif /* __MAILBOX_CLIENT_H */ diff --git a/include/linux/mailbox_controller.h b/include/linux/mailbox_controller.h index 4994a438444c..518aa4ca2fe4 100644 --- a/include/linux/mailbox_controller.h +++ b/include/linux/mailbox_controller.h @@ -27,6 +27,9 @@ struct mbox_chan; * @flush: Called when a client requests transmissions to be blocking but * the context doesn't allow sleeping. Typically the controller * will implement a busy loop waiting for the data to flush out. + * @abort_data: Called when a client relinquishes control of a chan. + * This call may block too. The controller may do stuff + * that need to sleep. * @startup: Called when a client requests the chan. The controller * could ask clients for additional parameters of communication * to be provided via client's chan_data. This call may @@ -50,6 +53,7 @@ struct mbox_chan; struct mbox_chan_ops { int (*send_data)(struct mbox_chan *chan, void *data); int (*flush)(struct mbox_chan *chan, unsigned long timeout); + void (*abort_data)(struct mbox_chan *chan); int (*startup)(struct mbox_chan *chan); void (*shutdown)(struct mbox_chan *chan); bool (*last_tx_done)(struct mbox_chan *chan); From patchwork Wed Jan 16 05:04:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q0sgSHUgKOiDoeS/iuWFiSk=?= X-Patchwork-Id: 10765419 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3FEC713BF for ; Wed, 16 Jan 2019 05:08:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C8462B1AF for ; Wed, 16 Jan 2019 05:08:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F04A2B1E8; Wed, 16 Jan 2019 05:08:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C94522B1AF for ; Wed, 16 Jan 2019 05:08:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=65e30x8BDKrW1CselS3CKbOOinUOUY8tFkdfzmNdNy4=; b=kTj9/5LxvApyHL ozQlNL8XYytocMAdKCmhyBYoMiaBBLGGMI9aSOmhaJMvw3PTcEgmrq18IvUSl87m3jbKTyBXJDr4y +QjMG7D7rqIpulkOT7lXfdQm3Y9oucMY/sj/mRZfTnz14naNa9MRMhWPqY1BV1ffBDFU+sO/xTEpy OKDndNd/iO2Pg0cBLvemJHs2RrQKqunD8IinIos8RECNEveWxwglf3tZFLSgT7+BT58vY1brVEKFE tqMbUbrslYiaCVgeacw+P64ojzVp2ngvcz5x/RgCg8Fju5D9a87sem6lMp9D5RKdDhDb5+78dExJM g9P9DT4Y2o34XDTnx2/w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gjdRG-0006i7-HR; Wed, 16 Jan 2019 05:08:30 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gjdQK-0005e8-Ai; Wed, 16 Jan 2019 05:07:33 +0000 X-UUID: 25ffdfcfd0044776b5b577dced84ea70-20190115 X-UUID: 25ffdfcfd0044776b5b577dced84ea70-20190115 Received: from mtkcas68.mediatek.inc [(172.29.94.19)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1678661172; Tue, 15 Jan 2019 21:07:26 -0800 Received: from mtkmbs03n2.mediatek.inc (172.21.101.182) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 15 Jan 2019 21:07:24 -0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs03n2.mediatek.inc (172.21.101.182) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 16 Jan 2019 13:07:22 +0800 Received: from mtkslt305.mediatek.inc (10.21.14.140) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Wed, 16 Jan 2019 13:07:22 +0800 From: CK Hu To: Jassi Brar , Matthias Brugger , Houlong Wei Subject: [PATCH 2/3] mailbox: mediatek: Implement abort_data function. Date: Wed, 16 Jan 2019 13:04:34 +0800 Message-ID: <20190116050435.11624-3-ck.hu@mediatek.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20190116050435.11624-1-ck.hu@mediatek.com> References: <20190116050435.11624-1-ck.hu@mediatek.com> MIME-Version: 1.0 X-TM-SNTS-SMTP: 69A7877979E11386BBE973F251CDFD145478041FA21F307B5E29E033EBCC8AFE2000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190115_210732_369915_0C60CD45 X-CRM114-Status: UNSURE ( 9.87 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: CK Hu , srv_heupstream@mediatek.com, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP For client driver which need to reorganize the command buffer, it could use this function to abort the sent but not executed command buffer. Signed-off-by: CK Hu --- drivers/mailbox/mtk-cmdq-mailbox.c | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/mailbox/mtk-cmdq-mailbox.c b/drivers/mailbox/mtk-cmdq-mailbox.c index 22811784dc7d..f2219f263ef6 100644 --- a/drivers/mailbox/mtk-cmdq-mailbox.c +++ b/drivers/mailbox/mtk-cmdq-mailbox.c @@ -417,6 +417,45 @@ static int cmdq_mbox_send_data(struct mbox_chan *chan, void *data) return 0; } +static void cmdq_mbox_abort_data(struct mbox_chan *chan) +{ + struct cmdq_thread *thread = (struct cmdq_thread *)chan->con_priv; + struct cmdq *cmdq = dev_get_drvdata(chan->mbox->dev); + struct cmdq_task *task, *tmp; + unsigned long flags; + u32 enable; + + spin_lock_irqsave(&thread->chan->lock, flags); + if (list_empty(&thread->task_busy_list)) + goto out; + + WARN_ON(cmdq_thread_suspend(cmdq, thread) < 0); + if (!cmdq_thread_is_in_wfe(thread)) + goto wait; + + list_for_each_entry_safe(task, tmp, &thread->task_busy_list, + list_entry) { + list_del(&task->list_entry); + kfree(task); + } + + cmdq_thread_resume(thread); + cmdq_thread_disable(cmdq, thread); + clk_disable(cmdq->clock); + +out: + spin_unlock_irqrestore(&thread->chan->lock, flags); + return; + +wait: + cmdq_thread_resume(thread); + spin_unlock_irqrestore(&thread->chan->lock, flags); + if (readl_poll_timeout_atomic(thread->base + CMDQ_THR_ENABLE_TASK, + enable, !enable, 1, 20)) + dev_err(cmdq->mbox.dev, "Fail to wait GCE thread 0x%x done\n", + (u32)(thread->base - cmdq->base)); +} + static int cmdq_mbox_startup(struct mbox_chan *chan) { return 0; @@ -427,6 +466,7 @@ static void cmdq_mbox_shutdown(struct mbox_chan *chan) } static const struct mbox_chan_ops cmdq_mbox_chan_ops = { + .abort_data = cmdq_mbox_abort_data, .send_data = cmdq_mbox_send_data, .startup = cmdq_mbox_startup, .shutdown = cmdq_mbox_shutdown, From patchwork Wed Jan 16 05:04:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q0sgSHUgKOiDoeS/iuWFiSk=?= X-Patchwork-Id: 10765413 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6DA0E13A4 for ; Wed, 16 Jan 2019 05:08:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A9572B1AF for ; Wed, 16 Jan 2019 05:08:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E8692B1E8; Wed, 16 Jan 2019 05:08:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8E69D2B1AF for ; Wed, 16 Jan 2019 05:08:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Uz1ACX4BjQWjZ6CTl7iIwT13gR2pATSHDcORyYxp+Uc=; b=GPPeb9A2VFydLm AAsozC08cl/mYKwlxRJ0V9Dafte1XCsK6iqS/Tds1hVivUe3l98XY7MFqXYrWs4xZjXlVcJj6D/C6 /dLBcG67mMNAw7f+7J5fAjsCMqk69TH9SCsJxBX4+wo5N/nnkxUvwJRpXNKddZB5fdw/L1GNJXvkr qxfYXdaEEd/LhOzh7avukaBqspOOnOpCJEZ86QNEpuSiM5KiYSqmcSYAHD1WWfQwwFrqW8Z68exMg 4Ic6iUfLzTPWQDwUV8VFELtXMrGADDUhPq7ef/JKvqzRq1QZyksS+TH/yhwqBFVmHGtIaf97Z7mvt 1kgg2ujv6vdffjJo3Y7w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gjdQm-0006B8-1n; Wed, 16 Jan 2019 05:08:00 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gjdQI-0005e9-DQ; Wed, 16 Jan 2019 05:07:32 +0000 X-UUID: 5b97101bab24493f9a1a83a7d88e840e-20190115 X-UUID: 5b97101bab24493f9a1a83a7d88e840e-20190115 Received: from mtkcas68.mediatek.inc [(172.29.94.19)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 2007656019; Tue, 15 Jan 2019 21:07:25 -0800 Received: from mtkmbs03n1.mediatek.inc (172.21.101.181) by MTKMBS62DR.mediatek.inc (172.29.94.18) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 15 Jan 2019 21:07:24 -0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs03n1.mediatek.inc (172.21.101.181) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 16 Jan 2019 13:07:22 +0800 Received: from mtkslt305.mediatek.inc (10.21.14.140) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Wed, 16 Jan 2019 13:07:22 +0800 From: CK Hu To: Jassi Brar , Matthias Brugger , Houlong Wei Subject: [PATCH 3/3] mailbox: mediatek: Remove busylist Date: Wed, 16 Jan 2019 13:04:35 +0800 Message-ID: <20190116050435.11624-4-ck.hu@mediatek.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20190116050435.11624-1-ck.hu@mediatek.com> References: <20190116050435.11624-1-ck.hu@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190115_210730_530001_3DA04BBB X-CRM114-Status: GOOD ( 17.81 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: CK Hu , srv_heupstream@mediatek.com, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP After implement abort_data, controller need not to implement its own queue. Remove busylist because it's useless. Signed-off-by: CK Hu --- drivers/mailbox/mtk-cmdq-mailbox.c | 255 ++++------------------------- 1 file changed, 29 insertions(+), 226 deletions(-) diff --git a/drivers/mailbox/mtk-cmdq-mailbox.c b/drivers/mailbox/mtk-cmdq-mailbox.c index f2219f263ef6..45c59f677ecb 100644 --- a/drivers/mailbox/mtk-cmdq-mailbox.c +++ b/drivers/mailbox/mtk-cmdq-mailbox.c @@ -16,9 +16,7 @@ #include #include -#define CMDQ_OP_CODE_MASK (0xff << CMDQ_OP_CODE_SHIFT) #define CMDQ_IRQ_MASK 0xffff -#define CMDQ_NUM_CMD(t) (t->cmd_buf_size / CMDQ_INST_SIZE) #define CMDQ_CURR_IRQ_STATUS 0x10 #define CMDQ_THR_SLOT_CYCLES 0x30 @@ -47,22 +45,10 @@ #define CMDQ_THR_IRQ_EN (CMDQ_THR_IRQ_ERROR | CMDQ_THR_IRQ_DONE) #define CMDQ_THR_IS_WAITING BIT(31) -#define CMDQ_JUMP_BY_OFFSET 0x10000000 -#define CMDQ_JUMP_BY_PA 0x10000001 - struct cmdq_thread { struct mbox_chan *chan; void __iomem *base; - struct list_head task_busy_list; u32 priority; - bool atomic_exec; -}; - -struct cmdq_task { - struct cmdq *cmdq; - struct list_head list_entry; - dma_addr_t pa_base; - struct cmdq_thread *thread; struct cmdq_pkt *pkt; /* the packet sent from mailbox client */ }; @@ -130,171 +116,47 @@ static void cmdq_thread_disable(struct cmdq *cmdq, struct cmdq_thread *thread) writel(CMDQ_THR_DISABLED, thread->base + CMDQ_THR_ENABLE_TASK); } -/* notify GCE to re-fetch commands by setting GCE thread PC */ -static void cmdq_thread_invalidate_fetched_data(struct cmdq_thread *thread) -{ - writel(readl(thread->base + CMDQ_THR_CURR_ADDR), - thread->base + CMDQ_THR_CURR_ADDR); -} - -static void cmdq_task_insert_into_thread(struct cmdq_task *task) -{ - struct device *dev = task->cmdq->mbox.dev; - struct cmdq_thread *thread = task->thread; - struct cmdq_task *prev_task = list_last_entry( - &thread->task_busy_list, typeof(*task), list_entry); - u64 *prev_task_base = prev_task->pkt->va_base; - - /* let previous task jump to this task */ - dma_sync_single_for_cpu(dev, prev_task->pa_base, - prev_task->pkt->cmd_buf_size, DMA_TO_DEVICE); - prev_task_base[CMDQ_NUM_CMD(prev_task->pkt) - 1] = - (u64)CMDQ_JUMP_BY_PA << 32 | task->pa_base; - dma_sync_single_for_device(dev, prev_task->pa_base, - prev_task->pkt->cmd_buf_size, DMA_TO_DEVICE); - - cmdq_thread_invalidate_fetched_data(thread); -} - -static bool cmdq_command_is_wfe(u64 cmd) -{ - u64 wfe_option = CMDQ_WFE_UPDATE | CMDQ_WFE_WAIT | CMDQ_WFE_WAIT_VALUE; - u64 wfe_op = (u64)(CMDQ_CODE_WFE << CMDQ_OP_CODE_SHIFT) << 32; - u64 wfe_mask = (u64)CMDQ_OP_CODE_MASK << 32 | 0xffffffff; - - return ((cmd & wfe_mask) == (wfe_op | wfe_option)); -} - -/* we assume tasks in the same display GCE thread are waiting the same event. */ -static void cmdq_task_remove_wfe(struct cmdq_task *task) -{ - struct device *dev = task->cmdq->mbox.dev; - u64 *base = task->pkt->va_base; - int i; - - dma_sync_single_for_cpu(dev, task->pa_base, task->pkt->cmd_buf_size, - DMA_TO_DEVICE); - for (i = 0; i < CMDQ_NUM_CMD(task->pkt); i++) - if (cmdq_command_is_wfe(base[i])) - base[i] = (u64)CMDQ_JUMP_BY_OFFSET << 32 | - CMDQ_JUMP_PASS; - dma_sync_single_for_device(dev, task->pa_base, task->pkt->cmd_buf_size, - DMA_TO_DEVICE); -} - static bool cmdq_thread_is_in_wfe(struct cmdq_thread *thread) { return readl(thread->base + CMDQ_THR_WAIT_TOKEN) & CMDQ_THR_IS_WAITING; } -static void cmdq_thread_wait_end(struct cmdq_thread *thread, - unsigned long end_pa) -{ - struct device *dev = thread->chan->mbox->dev; - unsigned long curr_pa; - - if (readl_poll_timeout_atomic(thread->base + CMDQ_THR_CURR_ADDR, - curr_pa, curr_pa == end_pa, 1, 20)) - dev_err(dev, "GCE thread cannot run to end.\n"); -} - -static void cmdq_task_exec_done(struct cmdq_task *task, enum cmdq_cb_status sta) -{ - struct cmdq_task_cb *cb = &task->pkt->async_cb; - struct cmdq_cb_data data; - - WARN_ON(cb->cb == (cmdq_async_flush_cb)NULL); - data.sta = sta; - data.data = cb->data; - cb->cb(data); - - list_del(&task->list_entry); -} - -static void cmdq_task_handle_error(struct cmdq_task *task) -{ - struct cmdq_thread *thread = task->thread; - struct cmdq_task *next_task; - - dev_err(task->cmdq->mbox.dev, "task 0x%p error\n", task); - WARN_ON(cmdq_thread_suspend(task->cmdq, thread) < 0); - next_task = list_first_entry_or_null(&thread->task_busy_list, - struct cmdq_task, list_entry); - if (next_task) - writel(next_task->pa_base, thread->base + CMDQ_THR_CURR_ADDR); - cmdq_thread_resume(thread); -} - static void cmdq_thread_irq_handler(struct cmdq *cmdq, struct cmdq_thread *thread) { - struct cmdq_task *task, *tmp, *curr_task = NULL; - u32 curr_pa, irq_flag, task_end_pa; - bool err; + unsigned long flags; + u32 curr_pa, irq_flag, end_pa; + int ret = 0; + spin_lock_irqsave(&thread->chan->lock, flags); irq_flag = readl(thread->base + CMDQ_THR_IRQ_STATUS); writel(~irq_flag, thread->base + CMDQ_THR_IRQ_STATUS); - /* - * When ISR call this function, another CPU core could run - * "release task" right before we acquire the spin lock, and thus - * reset / disable this GCE thread, so we need to check the enable - * bit of this GCE thread. - */ - if (!(readl(thread->base + CMDQ_THR_ENABLE_TASK) & CMDQ_THR_ENABLED)) - return; - - if (irq_flag & CMDQ_THR_IRQ_ERROR) - err = true; - else if (irq_flag & CMDQ_THR_IRQ_DONE) - err = false; - else - return; - curr_pa = readl(thread->base + CMDQ_THR_CURR_ADDR); + end_pa = readl(thread->base + CMDQ_THR_END_ADDR); - list_for_each_entry_safe(task, tmp, &thread->task_busy_list, - list_entry) { - task_end_pa = task->pa_base + task->pkt->cmd_buf_size; - if (curr_pa >= task->pa_base && curr_pa < task_end_pa) - curr_task = task; - - if (!curr_task || curr_pa == task_end_pa - CMDQ_INST_SIZE) { - cmdq_task_exec_done(task, CMDQ_CB_NORMAL); - kfree(task); - } else if (err) { - cmdq_task_exec_done(task, CMDQ_CB_ERROR); - cmdq_task_handle_error(curr_task); - kfree(task); - } - - if (curr_task) - break; - } + if (curr_pa != end_pa || irq_flag & CMDQ_THR_IRQ_ERROR) + ret = -EFAULT; - if (list_empty(&thread->task_busy_list)) { - cmdq_thread_disable(cmdq, thread); - clk_disable(cmdq->clock); - } + thread->pkt = NULL; + cmdq_thread_disable(cmdq, thread); + clk_disable(cmdq->clock); + spin_unlock_irqrestore(&thread->chan->lock, flags); + mbox_chan_txdone(thread->chan, ret); } static irqreturn_t cmdq_irq_handler(int irq, void *dev) { struct cmdq *cmdq = dev; - unsigned long irq_status, flags = 0L; + unsigned long irq_status; int bit; irq_status = readl(cmdq->base + CMDQ_CURR_IRQ_STATUS) & CMDQ_IRQ_MASK; if (!(irq_status ^ CMDQ_IRQ_MASK)) return IRQ_NONE; - for_each_clear_bit(bit, &irq_status, fls(CMDQ_IRQ_MASK)) { - struct cmdq_thread *thread = &cmdq->thread[bit]; - - spin_lock_irqsave(&thread->chan->lock, flags); - cmdq_thread_irq_handler(cmdq, thread); - spin_unlock_irqrestore(&thread->chan->lock, flags); - } + for_each_clear_bit(bit, &irq_status, fls(CMDQ_IRQ_MASK)) + cmdq_thread_irq_handler(cmdq, &cmdq->thread[bit]); return IRQ_HANDLED; } @@ -310,7 +172,7 @@ static int cmdq_suspend(struct device *dev) for (i = 0; i < cmdq->thread_nr; i++) { thread = &cmdq->thread[i]; - if (!list_empty(&thread->task_busy_list)) { + if (thread->pkt) { task_running = true; break; } @@ -347,72 +209,21 @@ static int cmdq_mbox_send_data(struct mbox_chan *chan, void *data) struct cmdq_pkt *pkt = (struct cmdq_pkt *)data; struct cmdq_thread *thread = (struct cmdq_thread *)chan->con_priv; struct cmdq *cmdq = dev_get_drvdata(chan->mbox->dev); - struct cmdq_task *task; - unsigned long curr_pa, end_pa; /* Client should not flush new tasks if suspended. */ WARN_ON(cmdq->suspended); - task = kzalloc(sizeof(*task), GFP_ATOMIC); - if (!task) - return -ENOMEM; + thread->pkt = pkt; - task->cmdq = cmdq; - INIT_LIST_HEAD(&task->list_entry); - task->pa_base = pkt->pa_base; - task->thread = thread; - task->pkt = pkt; - - if (list_empty(&thread->task_busy_list)) { - WARN_ON(clk_enable(cmdq->clock) < 0); - WARN_ON(cmdq_thread_reset(cmdq, thread) < 0); - - writel(task->pa_base, thread->base + CMDQ_THR_CURR_ADDR); - writel(task->pa_base + pkt->cmd_buf_size, - thread->base + CMDQ_THR_END_ADDR); - writel(thread->priority, thread->base + CMDQ_THR_PRIORITY); - writel(CMDQ_THR_IRQ_EN, thread->base + CMDQ_THR_IRQ_ENABLE); - writel(CMDQ_THR_ENABLED, thread->base + CMDQ_THR_ENABLE_TASK); - } else { - WARN_ON(cmdq_thread_suspend(cmdq, thread) < 0); - curr_pa = readl(thread->base + CMDQ_THR_CURR_ADDR); - end_pa = readl(thread->base + CMDQ_THR_END_ADDR); - - /* - * Atomic execution should remove the following wfe, i.e. only - * wait event at first task, and prevent to pause when running. - */ - if (thread->atomic_exec) { - /* GCE is executing if command is not WFE */ - if (!cmdq_thread_is_in_wfe(thread)) { - cmdq_thread_resume(thread); - cmdq_thread_wait_end(thread, end_pa); - WARN_ON(cmdq_thread_suspend(cmdq, thread) < 0); - /* set to this task directly */ - writel(task->pa_base, - thread->base + CMDQ_THR_CURR_ADDR); - } else { - cmdq_task_insert_into_thread(task); - cmdq_task_remove_wfe(task); - smp_mb(); /* modify jump before enable thread */ - } - } else { - /* check boundary */ - if (curr_pa == end_pa - CMDQ_INST_SIZE || - curr_pa == end_pa) { - /* set to this task directly */ - writel(task->pa_base, - thread->base + CMDQ_THR_CURR_ADDR); - } else { - cmdq_task_insert_into_thread(task); - smp_mb(); /* modify jump before enable thread */ - } - } - writel(task->pa_base + pkt->cmd_buf_size, - thread->base + CMDQ_THR_END_ADDR); - cmdq_thread_resume(thread); - } - list_move_tail(&task->list_entry, &thread->task_busy_list); + WARN_ON(clk_enable(cmdq->clock) < 0); + WARN_ON(cmdq_thread_reset(cmdq, thread) < 0); + + writel(thread->pkt->pa_base, thread->base + CMDQ_THR_CURR_ADDR); + writel(thread->pkt->pa_base + pkt->cmd_buf_size, + thread->base + CMDQ_THR_END_ADDR); + writel(thread->priority, thread->base + CMDQ_THR_PRIORITY); + writel(CMDQ_THR_IRQ_EN, thread->base + CMDQ_THR_IRQ_ENABLE); + writel(CMDQ_THR_ENABLED, thread->base + CMDQ_THR_ENABLE_TASK); return 0; } @@ -421,23 +232,18 @@ static void cmdq_mbox_abort_data(struct mbox_chan *chan) { struct cmdq_thread *thread = (struct cmdq_thread *)chan->con_priv; struct cmdq *cmdq = dev_get_drvdata(chan->mbox->dev); - struct cmdq_task *task, *tmp; unsigned long flags; u32 enable; spin_lock_irqsave(&thread->chan->lock, flags); - if (list_empty(&thread->task_busy_list)) + if (!thread->pkt) goto out; WARN_ON(cmdq_thread_suspend(cmdq, thread) < 0); if (!cmdq_thread_is_in_wfe(thread)) goto wait; - list_for_each_entry_safe(task, tmp, &thread->task_busy_list, - list_entry) { - list_del(&task->list_entry); - kfree(task); - } + thread->pkt = NULL; cmdq_thread_resume(thread); cmdq_thread_disable(cmdq, thread); @@ -483,7 +289,6 @@ static struct mbox_chan *cmdq_xlate(struct mbox_controller *mbox, thread = (struct cmdq_thread *)mbox->chans[ind].con_priv; thread->priority = sp->args[1]; - thread->atomic_exec = (sp->args[2] != 0); thread->chan = &mbox->chans[ind]; return &mbox->chans[ind]; @@ -539,8 +344,7 @@ static int cmdq_probe(struct platform_device *pdev) cmdq->mbox.ops = &cmdq_mbox_chan_ops; cmdq->mbox.of_xlate = cmdq_xlate; - /* make use of TXDONE_BY_ACK */ - cmdq->mbox.txdone_irq = false; + cmdq->mbox.txdone_irq = true; cmdq->mbox.txdone_poll = false; cmdq->thread = devm_kcalloc(dev, cmdq->thread_nr, @@ -551,7 +355,6 @@ static int cmdq_probe(struct platform_device *pdev) for (i = 0; i < cmdq->thread_nr; i++) { cmdq->thread[i].base = cmdq->base + CMDQ_THR_BASE + CMDQ_THR_SIZE * i; - INIT_LIST_HEAD(&cmdq->thread[i].task_busy_list); cmdq->mbox.chans[i].con_priv = (void *)&cmdq->thread[i]; }