Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2496964pxj; Mon, 10 May 2021 04:32:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6kBRP18kA830PqE2uL8tjzf82vAxWiSZyaFF3a4TQ1mGynkYQdBofiX/yJgertvaqxTa0 X-Received: by 2002:a92:c749:: with SMTP id y9mr21695539ilp.141.1620646327781; Mon, 10 May 2021 04:32:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620646327; cv=none; d=google.com; s=arc-20160816; b=gEVUA7U1ME1aPAGQbKODb6f7PTLWvsPB/VGkSyKSPn0zeYZ4DsXWIfFNVuNlPtt0iN uUN8wOx/ugmXiVc5qG6C8xJli65Eow4bK+cMT0Ua0uu6b+gLGkElp/xRWB9XLn4aIWxU qiM6Oyv40w0hR9g7DHM+s0+Y8GVVgtxeUVPnuvDuzpwOCvHDUnJ8T2gqr6hUg87IJ1O4 UEg8ZwatGqBz4zw14hG0RphPUVcopAIrqMj1hjfsepvsggHOujcphG3SLpzxI9s/T8E2 mta0QjqPAHhAWDmWc7IjTyXAWXHE+q+SMsf+/komoDBZ3U5w/Sbu5lbc2Ti0GP2dLbPF k+SQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rMEXNh5lJLwLOGmM3/dW/QT9SC481eQy9FHZa8CmWwI=; b=gIwFvf9pvYY/00NdymsZi/BazaAALllS3TzUKiwKEguzmDI8PBPd29xLqZk7nJ0ixT a4CX/5EYlNhY9BNzvvK1PWSikNlPjnLK295C2VEZtsoi3h/NLf6I8Ji1EQR0C8Hzr/+D PWwxa2LIMI4h+qWZtqCHdKskhvfCPKc7dWlAeFvhn4/DBiIOtkparW1wc/g7BIRl5oEF CEDIroV04/Et2loQ/Z6iAtBbkaACTG2wKix3v5jfBW8V76VHWttgZX9S3XEh4Mk5yMhu BvpLC5LNbfZkseMJIEO32HW/Nt43KRyWRkagVphI4KGKZydLfAgSd4k/s9r3Hju0TX+c uTuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Tc3bsd0l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r2si14701897ioh.103.2021.05.10.04.31.54; Mon, 10 May 2021 04:32:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Tc3bsd0l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239501AbhEJL04 (ORCPT + 99 others); Mon, 10 May 2021 07:26:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:52740 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234439AbhEJK4Y (ORCPT ); Mon, 10 May 2021 06:56:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 74E086192B; Mon, 10 May 2021 10:46:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620643565; bh=c0BOmcozvhdT+W6M6/9jXBKa7TlPfWtL2Sq+zi5NOOs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tc3bsd0lf8Lxy2HV/M+VQ1YYr2dnw8438gX/4tjN1w4kMl4C6NL19NkeAwhrFWLAb EEJN8UMuJjJOo2Js1lKTHwVksw6/NBYmzPQrFuAG6DBkDm1fZsh9A6ptb4okfcvLDt fwPTk1e5pn0p/Bpn8290stcLt0r6n/HL4UgG3Z6o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bhaumik Bhatt , Loic Poulain , Hemant Kumar , Manivannan Sadhasivam , Sasha Levin Subject: [PATCH 5.11 067/342] bus: mhi: core: Destroy SBL devices when moving to mission mode Date: Mon, 10 May 2021 12:17:37 +0200 Message-Id: <20210510102012.335034152@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102010.096403571@linuxfoundation.org> References: <20210510102010.096403571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bhaumik Bhatt [ Upstream commit 925089c1900f588615db5bf4e1d9064a5f2c18c7 ] Currently, client devices are created in SBL or AMSS (mission mode) and only destroyed after power down or SYS ERROR. When moving between certain execution environments, such as from SBL to AMSS, no clean-up is required. This presents an issue where SBL-specific channels are left open and client drivers now run in an execution environment where they cannot operate. Fix this by expanding the mhi_destroy_device() to do an execution environment specific clean-up if one is requested. Close the gap and destroy devices in such scenarios that allow SBL client drivers to clean up once device enters mission mode. Signed-off-by: Bhaumik Bhatt Reviewed-by: Loic Poulain Reviewed-by: Hemant Kumar Reviewed-by: Manivannan Sadhasivam Link: https://lore.kernel.org/r/1614208985-20851-2-git-send-email-bbhatt@codeaurora.org Signed-off-by: Manivannan Sadhasivam Signed-off-by: Sasha Levin --- drivers/bus/mhi/core/main.c | 29 +++++++++++++++++++++++++---- drivers/bus/mhi/core/pm.c | 3 +++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/drivers/bus/mhi/core/main.c b/drivers/bus/mhi/core/main.c index 947e58f3dfdc..fb51b2a47095 100644 --- a/drivers/bus/mhi/core/main.c +++ b/drivers/bus/mhi/core/main.c @@ -229,8 +229,10 @@ static bool is_valid_ring_ptr(struct mhi_ring *ring, dma_addr_t addr) int mhi_destroy_device(struct device *dev, void *data) { + struct mhi_chan *ul_chan, *dl_chan; struct mhi_device *mhi_dev; struct mhi_controller *mhi_cntrl; + enum mhi_ee_type ee = MHI_EE_MAX; if (dev->bus != &mhi_bus_type) return 0; @@ -242,6 +244,17 @@ int mhi_destroy_device(struct device *dev, void *data) if (mhi_dev->dev_type == MHI_DEVICE_CONTROLLER) return 0; + ul_chan = mhi_dev->ul_chan; + dl_chan = mhi_dev->dl_chan; + + /* + * If execution environment is specified, remove only those devices that + * started in them based on ee_mask for the channels as we move on to a + * different execution environment + */ + if (data) + ee = *(enum mhi_ee_type *)data; + /* * For the suspend and resume case, this function will get called * without mhi_unregister_controller(). Hence, we need to drop the @@ -249,11 +262,19 @@ int mhi_destroy_device(struct device *dev, void *data) * be sure that there will be no instances of mhi_dev left after * this. */ - if (mhi_dev->ul_chan) - put_device(&mhi_dev->ul_chan->mhi_dev->dev); + if (ul_chan) { + if (ee != MHI_EE_MAX && !(ul_chan->ee_mask & BIT(ee))) + return 0; - if (mhi_dev->dl_chan) - put_device(&mhi_dev->dl_chan->mhi_dev->dev); + put_device(&ul_chan->mhi_dev->dev); + } + + if (dl_chan) { + if (ee != MHI_EE_MAX && !(dl_chan->ee_mask & BIT(ee))) + return 0; + + put_device(&dl_chan->mhi_dev->dev); + } dev_dbg(&mhi_cntrl->mhi_dev->dev, "destroy device for chan:%s\n", mhi_dev->name); diff --git a/drivers/bus/mhi/core/pm.c b/drivers/bus/mhi/core/pm.c index 36ab7aa14174..1edce7917b6b 100644 --- a/drivers/bus/mhi/core/pm.c +++ b/drivers/bus/mhi/core/pm.c @@ -377,6 +377,7 @@ static int mhi_pm_mission_mode_transition(struct mhi_controller *mhi_cntrl) { struct mhi_event *mhi_event; struct device *dev = &mhi_cntrl->mhi_dev->dev; + enum mhi_ee_type current_ee = mhi_cntrl->ee; int i, ret; dev_dbg(dev, "Processing Mission Mode transition\n"); @@ -395,6 +396,8 @@ static int mhi_pm_mission_mode_transition(struct mhi_controller *mhi_cntrl) wake_up_all(&mhi_cntrl->state_event); + device_for_each_child(&mhi_cntrl->mhi_dev->dev, ¤t_ee, + mhi_destroy_device); mhi_cntrl->status_cb(mhi_cntrl, MHI_CB_EE_MISSION_MODE); /* Force MHI to be in M0 state before continuing */ -- 2.30.2