From patchwork Fri Jun 14 04:01:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SmFzb24tSkggTGluICjmnpfnnb/npaUp?= X-Patchwork-Id: 13697863 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8B49FC27C6E for ; Fri, 14 Jun 2024 04:02:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:CC:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=cp3S0hz+UCEESDzdQhAQa+QViRBu+pLWKLmQYRPjW3w=; b=SvOPXYyPzXPXsDes1J/dgdvkpE XniTNTmOwrNcS2qaQ50/GKKHd4hFnkNkUKIrS/xSBqzyj4f7yNL1vcTYSDaz1ZQeh1olbCfptTuEy Gw4dqqxcxJr71uQVaqlNY1ZqSew7hsNGoM4EwkGVfPH4hMM3PwM9cJ3yFzFjCl3ZHn21diR5wm3fD Ws9r5v7ccset6UfOvwy9KUZ6w4pHbVkK3JpFD3prmwfanPt69B4kCgbn0AF7PSgam42tNDRVAkoTY 37WDENc+Eic2J32My2VrriTGThqx7dCucEazXWGlq9agKVdVN6Y2aY/quKG6LvuIvD86q7fKpORI/ DOxSFrNg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sHy8r-00000001LYa-2WYO; Fri, 14 Jun 2024 04:02:21 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sHy8m-00000001LW0-0u97; Fri, 14 Jun 2024 04:02:17 +0000 X-UUID: e0e4e32a2a0211efaf04eb0598667787-20240613 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=cp3S0hz+UCEESDzdQhAQa+QViRBu+pLWKLmQYRPjW3w=; b=tiUulQyWu5uveW22hqmxKiSpxrId1yzHhV/qHfrW04kooHXLpOK6A1IQkf7ezoMV7LiWUPu+oa9c8QDFq9CJKQd0qfoj01gP6WIA+oLE8e6K9bkN9KWEF1c/sdzsCic55DZQ03ddpOT5WLOnBfebRaI+LbVb/i0ZYPRe41aEoOU=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.39,REQID:5ad7a17c-68a9-400c-b610-ef5ec797c900,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:393d96e,CLOUDID:def01285-4f93-4875-95e7-8c66ea833d57,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: e0e4e32a2a0211efaf04eb0598667787-20240613 Received: from mtkmbs14n2.mediatek.inc [(172.21.101.76)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1854478214; Thu, 13 Jun 2024 21:02:12 -0700 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Fri, 14 Jun 2024 12:01:34 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Fri, 14 Jun 2024 12:01:34 +0800 From: Jason-JH.Lin To: Jassi Brar , Chun-Kuang Hu , AngeloGioacchino Del Regno CC: Matthias Brugger , "Jason-JH . Lin" , Singo Chang , "Nancy Lin" , , , , Subject: [PATCH 1/2] mailbox: Add power_get/power_put API to mbox_chan_ops Date: Fri, 14 Jun 2024 12:01:32 +0800 Message-ID: <20240614040133.24967-2-jason-jh.lin@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20240614040133.24967-1-jason-jh.lin@mediatek.com> References: <20240614040133.24967-1-jason-jh.lin@mediatek.com> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--5.890200-8.000000 X-TMASE-MatchedRID: +MT4sN6PwkkpDniSMR+7FVz+axQLnAVBsuIso71Vk6Is/uUAk6xP7PlY oV6p/cSxYZon4ysgRFozZkzSKaTDyzWBtSWZ+bE6tw+xHnsmQjM2UosmN5oMuL/A+0D1to6PddB i3uMAVYvJpEwYgGDKGNWPKFYziUDIOVzKEd+ERcpIcJTn2HkqsTtSuYjPEOig2+mPn502VC/Irl nIALCsEkeSgWObrJ9MSHd+RjLgi2MYB2fOueQzjxRFJJyf5BJe3QfwsVk0UbtuRXh7bFKB7lnBE Jr8G5ea7U/yd1J/CA0ZGZ1zIaaRD2avzr9xB9L8aAZk0sEcY14= X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--5.890200-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: BF68BF4C9A3210864A913116E970F109AD5F2EDC8CDFB3354B6315FD3C8B6D502000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240613_210216_297071_C1407671 X-CRM114-Status: GOOD ( 15.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org To avoid pm_runtime APIs calling sleep in all the atomic context APIs in mbox_chan_ops, we add power_get/power_put API to let the controllers implement them with pm_runtime APIs outside the other atomic context APIs in mbox_chan_ops. Signed-off-by: Jason-JH.Lin --- drivers/mailbox/mailbox.c | 55 ++++++++++++++++++++++++++++++ include/linux/mailbox_controller.h | 11 ++++++ 2 files changed, 66 insertions(+) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index ebff3baf3045..bafcc7b0c0b8 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -58,6 +58,12 @@ static void msg_submit(struct mbox_chan *chan) void *data; int err = -EBUSY; + if (chan->mbox->ops->power_get) { + err = chan->mbox->ops->power_get(chan); + if (err < 0) + return; + } + spin_lock_irqsave(&chan->lock, flags); if (!chan->msg_count || chan->active_req) @@ -89,12 +95,16 @@ static void msg_submit(struct mbox_chan *chan) hrtimer_start(&chan->mbox->poll_hrt, 0, HRTIMER_MODE_REL); spin_unlock_irqrestore(&chan->mbox->poll_hrt_lock, flags); } + + if (chan->mbox->ops->power_put) + chan->mbox->ops->power_put(chan); } static void tx_tick(struct mbox_chan *chan, int r) { unsigned long flags; void *mssg; + int ret; spin_lock_irqsave(&chan->lock, flags); mssg = chan->active_req; @@ -107,10 +117,19 @@ static void tx_tick(struct mbox_chan *chan, int r) if (!mssg) return; + if (chan->mbox->ops->power_get) { + ret = chan->mbox->ops->power_get(chan); + if (ret < 0) + return; + } + /* Notify the client */ if (chan->cl->tx_done) chan->cl->tx_done(chan->cl, mssg, r); + if (chan->mbox->ops->power_put) + chan->mbox->ops->power_put(chan); + if (r != -ETIME && chan->cl->tx_block) complete(&chan->tx_complete); } @@ -223,9 +242,16 @@ EXPORT_SYMBOL_GPL(mbox_client_txdone); */ bool mbox_client_peek_data(struct mbox_chan *chan) { + if (chan->mbox->ops->power_get) + if (chan->mbox->ops->power_get(chan) < 0) + return false; + if (chan->mbox->ops->peek_data) return chan->mbox->ops->peek_data(chan); + if (chan->mbox->ops->power_put) + chan->mbox->ops->power_put(chan); + return false; } EXPORT_SYMBOL_GPL(mbox_client_peek_data); @@ -310,10 +336,19 @@ int mbox_flush(struct mbox_chan *chan, unsigned long timeout) if (!chan->mbox->ops->flush) return -ENOTSUPP; + if (chan->mbox->ops->power_get) { + ret = chan->mbox->ops->power_get(chan); + if (ret < 0) + return ret; + } + ret = chan->mbox->ops->flush(chan, timeout); if (ret < 0) tx_tick(chan, ret); + if (chan->mbox->ops->power_put) + chan->mbox->ops->power_put(chan); + return ret; } EXPORT_SYMBOL_GPL(mbox_flush); @@ -341,6 +376,12 @@ static int __mbox_bind_client(struct mbox_chan *chan, struct mbox_client *cl) spin_unlock_irqrestore(&chan->lock, flags); + if (chan->mbox->ops->power_get) { + ret = chan->mbox->ops->power_get(chan); + if (ret < 0) + return ERR_PTR(ret); + } + if (chan->mbox->ops->startup) { ret = chan->mbox->ops->startup(chan); @@ -441,7 +482,11 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index) if (ret) chan = ERR_PTR(ret); + if (chan->mbox->ops->power_put) + chan->mbox->ops->power_put(chan); + mutex_unlock(&con_mutex); + return chan; } EXPORT_SYMBOL_GPL(mbox_request_channel); @@ -485,13 +530,23 @@ EXPORT_SYMBOL_GPL(mbox_request_channel_byname); void mbox_free_channel(struct mbox_chan *chan) { unsigned long flags; + int ret; if (!chan || !chan->cl) return; + if (chan->mbox->ops->power_get) { + ret = chan->mbox->ops->power_get(chan); + if (ret < 0) + return; + } + if (chan->mbox->ops->shutdown) chan->mbox->ops->shutdown(chan); + if (chan->mbox->ops->power_put) + chan->mbox->ops->power_put(chan); + /* The queued TX requests are simply aborted, no callbacks are made */ spin_lock_irqsave(&chan->lock, flags); chan->cl = NULL; diff --git a/include/linux/mailbox_controller.h b/include/linux/mailbox_controller.h index 6fee33cb52f5..e8f26e7dabfd 100644 --- a/include/linux/mailbox_controller.h +++ b/include/linux/mailbox_controller.h @@ -42,6 +42,15 @@ struct mbox_chan; * Used only if txdone_poll:=true && txdone_irq:=false * @peek_data: Atomic check for any received data. Return true if controller * has some data to push to the client. False otherwise. + * @power_get: Called when the controller need to get the reference to keep + * the power on for the device of mailbox controller. It is + * optional to implement this function with pm_runtime APIs or + * more complicated operation. + * Return 0 is success, otherwise are fail. + * @power_put: Called when the controller need to put the reference to release + * the power for the device of mailbox controller. It is optional + * to implement this function with pm_runtime APIs or more + * complicated operation. */ struct mbox_chan_ops { int (*send_data)(struct mbox_chan *chan, void *data); @@ -50,6 +59,8 @@ struct mbox_chan_ops { void (*shutdown)(struct mbox_chan *chan); bool (*last_tx_done)(struct mbox_chan *chan); bool (*peek_data)(struct mbox_chan *chan); + int (*power_get)(struct mbox_chan *chan); + void (*power_put)(struct mbox_chan *chan); }; /** From patchwork Fri Jun 14 04:01:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SmFzb24tSkggTGluICjmnpfnnb/npaUp?= X-Patchwork-Id: 13697861 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 15E4FC27C77 for ; Fri, 14 Jun 2024 04:01:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:CC:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=oNX/6xJwVVdxINFYHElAcSxjFjZW+WO3wSYq/VQB9l8=; b=WYtR6hC4lKB6nVbPpbQRf/LiOS YDGaDCyx/AcH7ALxOG3BF1FTZh6GGKcKuON2DwmgW4DWF5hqhDLWGv4Xz4TLd2nEoiVaRKgYQHsEv zEnnw5BIYyPL2arPN0QWwsV3iDJ8f6fguKEsd7zY2Wxw9bpDpGpjyxoQzy7iFp4rwwyvvOpsfpPt8 Xogo76yDBAuHPvBup6LE30ldkxVUsKIrR9bVe6MvINsSRWPB+bSYlMRQ8dyckWjxIv+KKVBck+3hR 1OG2es8CTTM3TRj/871F6WFuttwHwKaLG0ac3v01mFmT3D8Zy/KbrwbLY4JCwhjY+SwCvubEGuMCE bIPI6GYA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sHy8I-00000001LMD-0rHI; Fri, 14 Jun 2024 04:01:46 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sHy8E-00000001LLT-3gzV; Fri, 14 Jun 2024 04:01:44 +0000 X-UUID: cbfd43262a0211efba8bfb22b0451c12-20240613 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=oNX/6xJwVVdxINFYHElAcSxjFjZW+WO3wSYq/VQB9l8=; b=sjXL8UqGlWgIsnSo9lrwDIATD+jETQMlrfUpOs7JNrM2puod97FJGW150fc/atq+ZdTIxQR9BPCPpOjgCURwu1LN3l1FPAtdijzMcGzyarVHe9WBr441yHuZEGf2Y6lLcPa7qoJC/xqe+4WjsU6SOFGm50leCcm1mNmJOexY8yc=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.39,REQID:19b4b44b-d2d5-4b68-806e-c722f812b85b,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:393d96e,CLOUDID:50d09288-8d4f-477b-89d2-1e3bdbef96d1,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:11|1,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES :1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_ULN X-UUID: cbfd43262a0211efba8bfb22b0451c12-20240613 Received: from mtkmbs13n2.mediatek.inc [(172.21.101.108)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1866911281; Thu, 13 Jun 2024 21:01:37 -0700 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs11n1.mediatek.inc (172.21.101.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Fri, 14 Jun 2024 12:01:34 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Fri, 14 Jun 2024 12:01:34 +0800 From: Jason-JH.Lin To: Jassi Brar , Chun-Kuang Hu , AngeloGioacchino Del Regno CC: Matthias Brugger , "Jason-JH . Lin" , Singo Chang , Nancy Lin , , , , Subject: [PATCH 2/2] mailbox: mtk-cmdq: Move pm_runimte_get and put to mbox_chan_ops API Date: Fri, 14 Jun 2024 12:01:33 +0800 Message-ID: <20240614040133.24967-3-jason-jh.lin@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20240614040133.24967-1-jason-jh.lin@mediatek.com> References: <20240614040133.24967-1-jason-jh.lin@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-20240613_210143_207602_7BAC219B X-CRM114-Status: GOOD ( 13.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When we run kernel with lockdebug option, we will get the BUG below: BUG: sleeping function called from invalid context at drivers/base/power/runtime.c:1164 in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 3616, name: kworker/u17:3 preempt_count: 1, expected: 0 RCU nest depth: 0, expected: 0 INFO: lockdep is turned off. irq event stamp: 0 CPU: 1 PID: 3616 Comm: kworker/u17:3 Not tainted 6.1.87-lockdep-14133-g26e933aca785 #1 Hardware name: Google Ciri sku0/unprovisioned board (DT) Workqueue: imgsys_runner imgsys_runner_func Call trace: dump_backtrace+0x100/0x120 show_stack+0x20/0x2c dump_stack_lvl+0x84/0xb4 dump_stack+0x18/0x48 __might_resched+0x354/0x4c0 __might_sleep+0x98/0xe4 __pm_runtime_resume+0x70/0x124 cmdq_mbox_send_data+0xe4/0xb1c msg_submit+0x194/0x2dc mbox_send_message+0x190/0x330 imgsys_cmdq_sendtask+0x1618/0x2224 imgsys_runner_func+0xac/0x11c process_one_work+0x638/0xf84 worker_thread+0x808/0xcd0 kthread+0x24c/0x324 ret_from_fork+0x10/0x20 We found that there is a spin_lock_irqsave protection in msg_submit() of mailbox.c and it is in the atomic context. So when cmdq driver calls pm_runtime_get_sync() in cmdq_mbox_send_data(), it will get this BUG report. To avoid using sleep in atomic context, move pm_runtime_get_sync to mbox_chan_ops->power_get and also move pm_runtime_put_autosuspend to mbox_chan_ops->power_put. Fixes: 8afe816b0c99 ("mailbox: mtk-cmdq-mailbox: Implement Runtime PM with autosuspend") Signed-off-by: Jason-JH.Lin --- drivers/mailbox/mtk-cmdq-mailbox.c | 37 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/drivers/mailbox/mtk-cmdq-mailbox.c b/drivers/mailbox/mtk-cmdq-mailbox.c index 4aa394e91109..02cef3eee35a 100644 --- a/drivers/mailbox/mtk-cmdq-mailbox.c +++ b/drivers/mailbox/mtk-cmdq-mailbox.c @@ -387,20 +387,13 @@ static int cmdq_mbox_send_data(struct mbox_chan *chan, void *data) struct cmdq *cmdq = dev_get_drvdata(chan->mbox->dev); struct cmdq_task *task; unsigned long curr_pa, end_pa; - int ret; /* Client should not flush new tasks if suspended. */ WARN_ON(cmdq->suspended); - ret = pm_runtime_get_sync(cmdq->mbox.dev); - if (ret < 0) - return ret; - task = kzalloc(sizeof(*task), GFP_ATOMIC); - if (!task) { - pm_runtime_put_autosuspend(cmdq->mbox.dev); + if (!task) return -ENOMEM; - } task->cmdq = cmdq; INIT_LIST_HEAD(&task->list_entry); @@ -448,7 +441,6 @@ static int cmdq_mbox_send_data(struct mbox_chan *chan, void *data) list_move_tail(&task->list_entry, &thread->task_busy_list); pm_runtime_mark_last_busy(cmdq->mbox.dev); - pm_runtime_put_autosuspend(cmdq->mbox.dev); return 0; } @@ -465,8 +457,6 @@ static void cmdq_mbox_shutdown(struct mbox_chan *chan) struct cmdq_task *task, *tmp; unsigned long flags; - WARN_ON(pm_runtime_get_sync(cmdq->mbox.dev) < 0); - spin_lock_irqsave(&thread->chan->lock, flags); if (list_empty(&thread->task_busy_list)) goto done; @@ -496,7 +486,6 @@ static void cmdq_mbox_shutdown(struct mbox_chan *chan) spin_unlock_irqrestore(&thread->chan->lock, flags); pm_runtime_mark_last_busy(cmdq->mbox.dev); - pm_runtime_put_autosuspend(cmdq->mbox.dev); } static int cmdq_mbox_flush(struct mbox_chan *chan, unsigned long timeout) @@ -507,11 +496,6 @@ static int cmdq_mbox_flush(struct mbox_chan *chan, unsigned long timeout) struct cmdq_task *task, *tmp; unsigned long flags; u32 enable; - int ret; - - ret = pm_runtime_get_sync(cmdq->mbox.dev); - if (ret < 0) - return ret; spin_lock_irqsave(&thread->chan->lock, flags); if (list_empty(&thread->task_busy_list)) @@ -536,7 +520,6 @@ static int cmdq_mbox_flush(struct mbox_chan *chan, unsigned long timeout) out: spin_unlock_irqrestore(&thread->chan->lock, flags); pm_runtime_mark_last_busy(cmdq->mbox.dev); - pm_runtime_put_autosuspend(cmdq->mbox.dev); return 0; @@ -551,15 +534,31 @@ static int cmdq_mbox_flush(struct mbox_chan *chan, unsigned long timeout) return -EFAULT; } pm_runtime_mark_last_busy(cmdq->mbox.dev); - pm_runtime_put_autosuspend(cmdq->mbox.dev); + return 0; } +static int cmdq_mbox_pm_resume(struct mbox_chan *chan) +{ + struct cmdq *cmdq = dev_get_drvdata(chan->mbox->dev); + + return pm_runtime_get_sync(cmdq->mbox.dev); +} + +static void cmdq_mbox_pm_susepnd(struct mbox_chan *chan) +{ + struct cmdq *cmdq = dev_get_drvdata(chan->mbox->dev); + + pm_runtime_put_autosuspend(cmdq->mbox.dev); +} + static const struct mbox_chan_ops cmdq_mbox_chan_ops = { .send_data = cmdq_mbox_send_data, .startup = cmdq_mbox_startup, .shutdown = cmdq_mbox_shutdown, .flush = cmdq_mbox_flush, + .power_get = cmdq_mbox_pm_resume, + .power_put = cmdq_mbox_pm_susepnd, }; static struct mbox_chan *cmdq_xlate(struct mbox_controller *mbox,