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 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 4FCF9CD5BB1 for ; Fri, 22 May 2026 10:01:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A80CD10F533; Fri, 22 May 2026 10:01:43 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.b="RlcEFI4D"; dkim=pass (2048-bit key; unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="h2evXaDS"; dkim-atps=neutral Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by gabe.freedesktop.org (Postfix) with ESMTPS id AF42910F533 for ; Fri, 22 May 2026 10:01:42 +0000 (UTC) Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 64M8hObI399191 for ; Fri, 22 May 2026 10:01:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 5DXeyrdoWr0DcgBTdRbVLV0jwA0imqVGVhlRKg6Geqg=; b=RlcEFI4DbYPXiWK4 QIlBKbaRJedey4Bt6BSXn+z+qgw4dOjuyVZIn6+f4an/HrlkBJNeKn0426wyIWID DWGe0brdpGtxASKeEc9MAkgbfRunDdZwezz8A0DGQgex6gFV8Z2extNKtZ/1dmYL ZZOtc7ZT1PobKIdaS79++SrbhMjyh+cve2dXWjCyGPU5OGYMvMqND7Lxoke7LbzA cT5AtlMq/0QACA3d8DTQ/PMFAU489910ptdIyDy99iyevn9v2c1GnzjVbNN+aOaR h5D9tH3ylLKZkfS5CetSbU3z4mGceFP11qQRbDBZT81idOZgoyyuY7BTPDWutLQo FHdDAA== Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4ea5p9us40-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 22 May 2026 10:01:41 +0000 (GMT) Received: by mail-pg1-f199.google.com with SMTP id 41be03b00d2f7-c8514f8ed5dso1211206a12.3 for ; Fri, 22 May 2026 03:01:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1779444101; x=1780048901; darn=lists.freedesktop.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=5DXeyrdoWr0DcgBTdRbVLV0jwA0imqVGVhlRKg6Geqg=; b=h2evXaDSyMXrTJ8WXnrKacFIWWPJ6UerBVk2ZnzfGUZf/cHhrFnJvY7G0fihJTpTWc kT6rCc/3lPUJXQLvg+D9+RGmDW5GCQrx9OkTldgHY/rhyPnaUXZFLo50R/WYZmc5ioQ3 C8Lk5mZ8KDGBeiTYylBQ80CvOnHk+LvCQd+VNEv0JdHHjArSed3zw46X3SLNMGfTofC2 hk6OpF3n9OXPlnEW7FZp1R4x3bgUTcaeaX8hoLAvLa6l3OB05TZ58jcpi/ISyGDWhzuM kKmbZ9luSl7ZKAGVDyFKJm1zmjaXRwkLfY5GdgQw30NTDZ5RrFffd9lLkswm2GL4N/Bh WEHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779444101; x=1780048901; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=5DXeyrdoWr0DcgBTdRbVLV0jwA0imqVGVhlRKg6Geqg=; b=jK85FDAi5kZYYQrVdP8XJz5oi7pb4Lsw1QQnYBZD2UCZ53PxbWW/RbiMzEYO5Q3DLs 7FFctNdEUDzt2cGXz1uxmWe/7iGpLKELEboQ2256BLD0cepJy+mkYL6dN5ivEJqhlel6 HWdAmGFK+PHIFzZzxwWH3MvVprVVDf4U90c/BtK848UHPQjOjSU1lM4D9VI7v5aF2Cmk TfEPHOWBdA6Y5vASEu1soF0GH3Lt4ai7vwGuW24JN7Tb5D3ztllIKTPXbNb3yabB9s/b kDvA5crNLSUFkycMpZZGUwNb8+MxgCTYjGhn2rB0h/MGDts6cjsaafI45X9rqo8tqraV 2Vuw== X-Forwarded-Encrypted: i=1; AFNElJ86UbQUv8SQH0psISYaOhwglCSWXDKIFYWIXHkGufiiE5snU36fYhYu9vlto0inOjEQoYrCdEc4ooI=@lists.freedesktop.org X-Gm-Message-State: AOJu0YzJget6ZRK2p+MuYChNMx9JNXQ2NfTYIOmhR+ibrldqIxFCDQtD j2CZS3hSW3Jpp9dL2Wm2aLzkd35Rxqpn2aGRgL/Ql+HyVuwYDKS0KDUxPMyHBcQiibn+T8Vuk3f ARF5C7Eb0fbuxjWCZ3vIlUmxBbEqTnZsKTVh6rhpoWnca4moI7ej6ewqNQA9hmpKsuwXoIEQ= X-Gm-Gg: Acq92OGXjI6P0ridO8QUUSZkm5PEN7Pkr++YKRb7S33CbnfC6xx4+x9p5wPchLCyzuE XP7/kl29NLV0JPGOrOL6v2sNKFX0EBsCo18Qerje2VUf2IhDDdyqFQHv5z6jDKNqKgFjUu2rB4q r2QkfGzxfkxTAcyRvTB2QiEKxGB8a13y8LsC07J4WPg5N5iz9k4trUMaBl/8ZEadvQ9P3fxyFoE utfdcyFuP9G91TqxoF0NYPXNKDu6DWO1m0xeqTlsNL5TPBbG18HbBRo0+B+SmQ+kxBi0di9hlkD ed8wtvsGcXh8WhbR9dixtdpMiyJUThyy5Zz5k9tUY5UXEcgmrnkUYnwLcPyQwzL2cxxXHgktZ/2 7GSu+9tj2zj2p37HRqPCsznJ5U8+n2PuvmtcAuGMtsZSd4GWZhLx1vNYWftrmZsizIEU= X-Received: by 2002:a05:6a00:bd11:b0:82f:24e:6a48 with SMTP id d2e1a72fcca58-8415f2e0caamr3187497b3a.5.1779444100739; Fri, 22 May 2026 03:01:40 -0700 (PDT) X-Received: by 2002:a05:6a00:bd11:b0:82f:24e:6a48 with SMTP id d2e1a72fcca58-8415f2e0caamr3187406b3a.5.1779444099822; Fri, 22 May 2026 03:01:39 -0700 (PDT) Received: from hu-krichai-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84164ac9b74sm1516641b3a.3.2026.05.22.03.01.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 03:01:39 -0700 (PDT) From: Krishna Chaitanya Chundru Date: Fri, 22 May 2026 15:30:37 +0530 Subject: [PATCH v2 6/6] bus: mhi: host: Fix runtime PM ownership between clients and controller MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260522-mhi_runtimepm-v2-6-fbebf41a82bb@oss.qualcomm.com> References: <20260522-mhi_runtimepm-v2-0-fbebf41a82bb@oss.qualcomm.com> In-Reply-To: <20260522-mhi_runtimepm-v2-0-fbebf41a82bb@oss.qualcomm.com> To: Manivannan Sadhasivam , Jeff Hugo , Carl Vanderlip , Oded Gabbay , Jeff Johnson , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Loic Poulain , Sergey Ryazanov , Johannes Berg Cc: mhi@lists.linux.dev, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-wireless@vger.kernel.org, ath11k@lists.infradead.org, ath12k@lists.infradead.org, netdev@vger.kernel.org, mayank.rana@oss.qualcomm.com, quic_vbadigan@quicinc.com, vivek.pernamitta@oss.qualcomm.com, Krishna Chaitanya Chundru X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779444039; l=7532; i=krishna.chundru@oss.qualcomm.com; s=20230907; h=from:subject:message-id; bh=iFHxbTO6wE35Tl3kqwnkO8A1IQ+NptFsGOPDlaw/GEs=; b=Leraca11cxKZ9kv0wOGI3YHGBWBAYMU7jDrEbEBi0YqgqfKAQk5bm2D7Lfh9uEh0W7ZzT5vKK DtD9ugdBFwRClFNTiqzjFY0NRel2cgOG3a2qFCZJSiB8OgzBE27Wzzh X-Developer-Key: i=krishna.chundru@oss.qualcomm.com; a=ed25519; pk=10CL2pdAKFyzyOHbfSWHCD0X0my7CXxj8gJScmn1FAg= X-Authority-Analysis: v=2.4 cv=DKm/JSNb c=1 sm=1 tr=0 ts=6a102985 cx=c_pps a=Oh5Dbbf/trHjhBongsHeRQ==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=IkcTkHD0fZMA:10 a=NGcC8JguVDcA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=eoimf2acIAo5FJnRuUoq:22 a=EUspDBNiAAAA:8 a=A8rfxp3GyOsx1I41rDQA:9 a=QEXdDO2ut3YA:10 a=_Vgx9l1VpLgwpw_dHYaR:22 X-Proofpoint-GUID: GnRCJgwkrxQ6sUos02G8jYdahGbA_IIF X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTIyMDA5OSBTYWx0ZWRfX8Py3of1VmEUs tBO38enBYT7Eqeee4t5O3tWvLFinxgNaEJXCxpTvmwwz4KjWKdJEnGdPdlSDAGmJiBgCKZeKo60 GZ3/1Vxpry3aoXo4GRiB/tBRRPrsF3iJH2WFGjAPX3Z4A6SgDl59LPCjS6hfvDBWKyLhdAA+i+R +WRpobh7IQkBDjGhtpY6sng57FqTy1TucZ6+6yT454OhpAZfecDQRnaTuyejeGqlDYPiLQNS0jU yhdAjEAA4bj3CnpKI6pN16Bhmzk6cOMJ6xZ78A7/FI+bCPTwKrpwvsB+G6AGhSl4wZphPPZsiqE rxwK2ArluKsTos93+B6QstUZolObHylRbStDgWmjJntkfvsuNPjGJ/Va+sKbC4YC1jJ4KXXJisi nlsQLTGAKXV6kikgKyH+y3KfI5dCjZ5EOGqO12QC0ld1yM7tBbEDQfKU3O75xzVQz6eG08oU67A MYA+IHSOWIzscjXCfPA== X-Proofpoint-ORIG-GUID: GnRCJgwkrxQ6sUos02G8jYdahGbA_IIF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-22_02,2026-05-18_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 malwarescore=0 spamscore=0 phishscore=0 suspectscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 adultscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2605130000 definitions=main-2605220099 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The current MHI runtime PM model allows the core to take power references directly on the controller device without visibility into client driver activity. As a result, a controller driver may runtime-suspend the hardware while one or more MHI client devices are still actively in use. This happens because the MHI core historically managed runtime PM internally, rather than relying on standard parent-child PM dependency tracking. The controller driver therefore has no way to infer whether MHI clients still require the controller to remain active. Fix this by enabling runtime PM on the MHI bus device (mhi_dev) and routing runtime PM references through it. Client drivers now hold runtime PM references on their own mhi_dev, allowing the PM framework to naturally propagate activity to the controller via the device hierarchy. The existing mhi_device_get_sync() and mhi_device_put() helpers are retained, as they serve as the synchronization point between the MHI power state machine and runtime PM, combining runtime PM reference management with MHI wake handling. Signed-off-by: Krishna Chaitanya Chundru --- drivers/bus/mhi/host/init.c | 3 +++ drivers/bus/mhi/host/internal.h | 6 +++--- drivers/bus/mhi/host/main.c | 26 ++------------------------ drivers/bus/mhi/host/pm.c | 18 ++++++++---------- 4 files changed, 16 insertions(+), 37 deletions(-) diff --git a/drivers/bus/mhi/host/init.c b/drivers/bus/mhi/host/init.c index 9f3ee4a14418..002f3abb8103 100644 --- a/drivers/bus/mhi/host/init.c +++ b/drivers/bus/mhi/host/init.c @@ -1034,6 +1034,9 @@ int mhi_register_controller(struct mhi_controller *mhi_cntrl, mhi_cntrl->mhi_dev = mhi_dev; + pm_runtime_no_callbacks(&mhi_cntrl->mhi_dev->dev); + devm_pm_runtime_set_active_enabled(&mhi_cntrl->mhi_dev->dev); + mhi_create_debugfs(mhi_cntrl); return 0; diff --git a/drivers/bus/mhi/host/internal.h b/drivers/bus/mhi/host/internal.h index a7493aabc6fa..434ed4705d25 100644 --- a/drivers/bus/mhi/host/internal.h +++ b/drivers/bus/mhi/host/internal.h @@ -354,9 +354,9 @@ static inline bool mhi_is_active(struct mhi_controller *mhi_cntrl) static inline void mhi_trigger_resume(struct mhi_controller *mhi_cntrl) { pm_wakeup_event(&mhi_cntrl->mhi_dev->dev, 0); - pm_runtime_get(mhi_cntrl->cntrl_dev); - pm_runtime_mark_last_busy(mhi_cntrl->cntrl_dev); - pm_runtime_put(mhi_cntrl->cntrl_dev); + pm_runtime_get(&mhi_cntrl->mhi_dev->dev); + pm_runtime_mark_last_busy(&mhi_cntrl->mhi_dev->dev); + pm_runtime_put(&mhi_cntrl->mhi_dev->dev); } /* Register access methods */ diff --git a/drivers/bus/mhi/host/main.c b/drivers/bus/mhi/host/main.c index 71919c2e9462..f0b09657de29 100644 --- a/drivers/bus/mhi/host/main.c +++ b/drivers/bus/mhi/host/main.c @@ -658,12 +658,8 @@ static int parse_xfer_event(struct mhi_controller *mhi_cntrl, /* notify client */ mhi_chan->xfer_cb(mhi_chan->mhi_dev, &result); - if (mhi_chan->dir == DMA_TO_DEVICE) { + if (mhi_chan->dir == DMA_TO_DEVICE) atomic_dec(&mhi_cntrl->pending_pkts); - /* Release the reference got from mhi_queue() */ - pm_runtime_mark_last_busy(mhi_cntrl->cntrl_dev); - pm_runtime_put(mhi_cntrl->cntrl_dev); - } read_lock_bh(&mhi_chan->lock); } @@ -1135,12 +1131,6 @@ static int mhi_queue(struct mhi_device *mhi_dev, struct mhi_buf_info *buf_info, read_lock_irqsave(&mhi_cntrl->pm_lock, flags); - /* Packet is queued, take a usage ref to exit M3 if necessary - * for host->device buffer, balanced put is done on buffer completion - * for device->host buffer, balanced put is after ringing the DB - */ - pm_runtime_get(mhi_cntrl->cntrl_dev); - /* Assert dev_wake (to exit/prevent M1/M2)*/ mhi_cntrl->wake_toggle(mhi_cntrl); @@ -1150,11 +1140,6 @@ static int mhi_queue(struct mhi_device *mhi_dev, struct mhi_buf_info *buf_info, if (likely(MHI_DB_ACCESS_VALID(mhi_cntrl))) mhi_ring_chan_db(mhi_cntrl, mhi_chan); - if (dir == DMA_FROM_DEVICE) { - pm_runtime_mark_last_busy(mhi_cntrl->cntrl_dev); - pm_runtime_put(mhi_cntrl->cntrl_dev); - } - read_unlock_irqrestore(&mhi_cntrl->pm_lock, flags); return ret; @@ -1355,7 +1340,6 @@ static int mhi_update_channel_state(struct mhi_controller *mhi_cntrl, ret = mhi_device_get_sync(mhi_cntrl->mhi_dev); if (ret) return ret; - pm_runtime_get(mhi_cntrl->cntrl_dev); reinit_completion(&mhi_chan->completion); ret = mhi_send_cmd(mhi_cntrl, mhi_chan, cmd); @@ -1386,8 +1370,6 @@ static int mhi_update_channel_state(struct mhi_controller *mhi_cntrl, trace_mhi_channel_command_end(mhi_cntrl, mhi_chan, to_state, TPS("Updated")); exit_channel_update: - pm_runtime_mark_last_busy(mhi_cntrl->cntrl_dev); - pm_runtime_put(mhi_cntrl->cntrl_dev); mhi_device_put(mhi_cntrl->mhi_dev); return ret; @@ -1525,12 +1507,8 @@ static void mhi_reset_data_chan(struct mhi_controller *mhi_cntrl, while (tre_ring->rp != tre_ring->wp) { struct mhi_buf_info *buf_info = buf_ring->rp; - if (mhi_chan->dir == DMA_TO_DEVICE) { + if (mhi_chan->dir == DMA_TO_DEVICE) atomic_dec(&mhi_cntrl->pending_pkts); - /* Release the reference got from mhi_queue() */ - pm_runtime_mark_last_busy(mhi_cntrl->cntrl_dev); - pm_runtime_put(mhi_cntrl->cntrl_dev); - } if (!buf_info->pre_mapped) mhi_cntrl->unmap_single(mhi_cntrl, buf_info); diff --git a/drivers/bus/mhi/host/pm.c b/drivers/bus/mhi/host/pm.c index f799503c8f36..278fc2ffb820 100644 --- a/drivers/bus/mhi/host/pm.c +++ b/drivers/bus/mhi/host/pm.c @@ -429,6 +429,7 @@ static int mhi_pm_mission_mode_transition(struct mhi_controller *mhi_cntrl) if (MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state)) { ret = -EIO; + read_unlock_bh(&mhi_cntrl->pm_lock); goto error_mission_mode; } @@ -459,11 +460,9 @@ static int mhi_pm_mission_mode_transition(struct mhi_controller *mhi_cntrl) */ mhi_create_devices(mhi_cntrl); - read_lock_bh(&mhi_cntrl->pm_lock); error_mission_mode: - mhi_cntrl->wake_put(mhi_cntrl, false); - read_unlock_bh(&mhi_cntrl->pm_lock); + mhi_device_put(mhi_cntrl->mhi_dev); return ret; } @@ -1038,9 +1037,11 @@ int __mhi_device_get_sync(struct mhi_controller *mhi_cntrl) read_unlock_bh(&mhi_cntrl->pm_lock); return -EIO; } + read_unlock_bh(&mhi_cntrl->pm_lock); + + pm_runtime_get_sync(&mhi_cntrl->mhi_dev->dev); + read_lock_bh(&mhi_cntrl->pm_lock); mhi_cntrl->wake_get(mhi_cntrl, true); - if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state)) - mhi_trigger_resume(mhi_cntrl); read_unlock_bh(&mhi_cntrl->pm_lock); ret = wait_event_timeout(mhi_cntrl->state_event, @@ -1049,9 +1050,7 @@ int __mhi_device_get_sync(struct mhi_controller *mhi_cntrl) msecs_to_jiffies(mhi_cntrl->timeout_ms)); if (!ret || MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state)) { - read_lock_bh(&mhi_cntrl->pm_lock); - mhi_cntrl->wake_put(mhi_cntrl, false); - read_unlock_bh(&mhi_cntrl->pm_lock); + mhi_device_put(mhi_cntrl->mhi_dev); return -EIO; } @@ -1339,11 +1338,10 @@ void mhi_device_put(struct mhi_device *mhi_dev) mhi_dev->dev_wake--; read_lock_bh(&mhi_cntrl->pm_lock); - if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state)) - mhi_trigger_resume(mhi_cntrl); mhi_cntrl->wake_put(mhi_cntrl, false); read_unlock_bh(&mhi_cntrl->pm_lock); + pm_runtime_put(&mhi_cntrl->mhi_dev->dev); } EXPORT_SYMBOL_GPL(mhi_device_put); -- 2.34.1