From patchwork Thu Oct 31 18:46:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 178235 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3252379ill; Thu, 31 Oct 2019 11:46:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqz4s2f+3SqfGlE7HHjKfTcXgS3vknA7ohe6y4l2yWXZGenWHgHZZMtWyimoJ9HTLweRSesy X-Received: by 2002:a17:906:4bd7:: with SMTP id x23mr5543117ejv.320.1572547603433; Thu, 31 Oct 2019 11:46:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572547603; cv=none; d=google.com; s=arc-20160816; b=vJeXQnISkraPPLvDYb0k74WaUKGHVWGootgMYZEuOtWl9IMEpgP88oVFNND/534yFI 1y7r4TtjeXfUhVun9qLkC0uLw6HKV3Whr1JiAVMZX36D4WRQaoAQU72r19FIVUUwZEQM cshe15Oh0k5WfRzhhF6nolQoMuPlLNabe//Lda69tMbok/b8wN/QzFcWP/42nK/QTOZ2 5Lnz4fGk6Ynt+2abtInHGGk/t7gf5upf8roZX/ji/b1kwSO4yYhpBkA/DIkLRfKqjy9M S+Tl/JdXvcZAoTUZEUmH09kABbQsRhJ8cLjt5NFU3EBvgk/Kxiar2bMd7YrpZXmepak9 SpdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WuFs+AMjdDKhamzQV8PIhDJ9khhpt9bix4gVbxAEv5k=; b=XaWU6V/EeUcXONqTGcoishdnkFUgCfZOJ9u+MHEfzBMpc0xAWwGrA3nSvMe4t5rhww wI+LtKy1DVOI/+Vnx+APw2nqPQs00TjSTCJwIoOYiUUUBo70cdgkbd6tIKdyDMcC0lov XmsOiIrqxnUWbs93mCtfehgDkHoTWYZUfvCOc/EYjoxFgKM+LTYYOfpB5K8EvnCZ34sl mmTdv0cnrlOW6py/ZdspY+FQuipxAPwBDdSSj/DY1Waxt5KysW3+4Rxvz0LobYn1lp9J m3j2XGAseudJ7RbR8x7iruaXJ+sKM/VbUWfgxk/L+arhM86VJUUk8hA8bVFkMXhr1D0k sq4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xb5T9zfH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e45si4831004edb.177.2019.10.31.11.46.43; Thu, 31 Oct 2019 11:46:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xb5T9zfH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729428AbfJaSqk (ORCPT + 26 others); Thu, 31 Oct 2019 14:46:40 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:36323 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729379AbfJaSqi (ORCPT ); Thu, 31 Oct 2019 14:46:38 -0400 Received: by mail-pl1-f194.google.com with SMTP id g9so3086293plp.3 for ; Thu, 31 Oct 2019 11:46:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WuFs+AMjdDKhamzQV8PIhDJ9khhpt9bix4gVbxAEv5k=; b=xb5T9zfHZejq85gO7jFd2zwpcyRjEnFCa9jXw/a1BGYBwqiwPHqwXTp9crC//hhHBa P5W8qYXn5P38liorEw8r1uSL0xAUNDvmDxyV+IVzflal+6BpyC+0RAJnGsV9zkXPiSV3 NX3O2JYP5+8nsz4MK9QAd6yQZBiDXV1dsxyAWjiOPlDrwyipQhs4yUn3P8XJnLyou9Le oaQvShGAI9coypED6Vks17iWdIGWBU2/ZB9RbsWxUc0skHGl4Q3zuT6JWaQBQBh7/W3g hVni+YYwokAHkK52tCBKlRATf5xhM3BGYzJ1whHDf8BZuN4gW5CxqdtN5W01iF31EAgG Th0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WuFs+AMjdDKhamzQV8PIhDJ9khhpt9bix4gVbxAEv5k=; b=lgFNXmfXceVfJTVjxFKY8QiFkjgDC+LCtcbhyCoOtUHOkfyVJjB4r5qqmG1m7Kn9fk 2YhWlh+hMMWCvHzCQR8b0fB6C8LPcl56MBVS8Mcm1ajBporcLMFZbuyGpORmOuNcVyhG Ppu6+4KPpdqvx3DaCOHw4TdOVwawJI4iuMpH77QPWasxs8jjlnNG6FAEi2HG4wbkXNat UOIcz0tSwroUyYT2aM99wg6g8WigNK/76g7BhIrqvzt2tRWYJjGr/vqzLJIpI/gG5wur pskP2eL4Rt4JhjHnRjXf6fGDUWH0iMaj8AbGH1l6yeKqmMhnUhgD6a0dRv2L6lSsONQU NaLA== X-Gm-Message-State: APjAAAV8qg4Hi3PFtxXSBAZyfFGSVGjCb91XwHy4LLZSu7BRAl0zEaoi nGjgBWWOw0RJ8EPTC/1yCt9fug== X-Received: by 2002:a17:902:b612:: with SMTP id b18mr7933212pls.309.1572547597107; Thu, 31 Oct 2019 11:46:37 -0700 (PDT) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id b82sm3950874pfb.33.2019.10.31.11.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2019 11:46:36 -0700 (PDT) From: Bjorn Andersson To: Ohad Ben-Cohen , Bjorn Andersson Cc: Avaneesh Kumar Dwivedi , linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, Jeffrey Hugo , Sibi Sankar , stable@vger.kernel.org Subject: [PATCH 1/2] remoteproc: qcom_q6v5_mss: Don't reassign mpss region on shutdown Date: Thu, 31 Oct 2019 11:46:31 -0700 Message-Id: <20191031184632.2938295-2-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191031184632.2938295-1-bjorn.andersson@linaro.org> References: <20191031184632.2938295-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Trying to reclaim mpss memory while the mba is not running causes the system to crash on devices with security fuses blown, so leave it assigned to the remote on shutdown and recover it on a subsequent boot. Fixes: 6c5a9dc2481b ("remoteproc: qcom: Make secure world call for mem ownership switch") Cc: stable@vger.kernel.org Signed-off-by: Bjorn Andersson --- drivers/remoteproc/qcom_q6v5_mss.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) -- 2.23.0 diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c index de919f2e8b94..f4a02105d539 100644 --- a/drivers/remoteproc/qcom_q6v5_mss.c +++ b/drivers/remoteproc/qcom_q6v5_mss.c @@ -875,11 +875,6 @@ static void q6v5_mba_reclaim(struct q6v5 *qproc) writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG); } - ret = q6v5_xfer_mem_ownership(qproc, &qproc->mpss_perm, - false, qproc->mpss_phys, - qproc->mpss_size); - WARN_ON(ret); - q6v5_reset_assert(qproc); q6v5_clk_disable(qproc->dev, qproc->reset_clks, @@ -969,6 +964,10 @@ static int q6v5_mpss_load(struct q6v5 *qproc) max_addr = ALIGN(phdr->p_paddr + phdr->p_memsz, SZ_4K); } + /* Try to reset ownership back to Linux */ + q6v5_xfer_mem_ownership(qproc, &qproc->mpss_perm, false, + qproc->mpss_phys, qproc->mpss_size); + mpss_reloc = relocate ? min_addr : qproc->mpss_phys; qproc->mpss_reloc = mpss_reloc; /* Load firmware segments */ @@ -1111,10 +1110,6 @@ static int q6v5_start(struct rproc *rproc) return 0; reclaim_mpss: - xfermemop_ret = q6v5_xfer_mem_ownership(qproc, &qproc->mpss_perm, - false, qproc->mpss_phys, - qproc->mpss_size); - WARN_ON(xfermemop_ret); q6v5_mba_reclaim(qproc); return ret; From patchwork Thu Oct 31 18:46:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 178236 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3252429ill; Thu, 31 Oct 2019 11:46:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqzRw4+WYDzr3vO5H79f/LdaCGZUxMQ37DlPh1cwdK8QA1Zp5bGx2K/KJiJMwe3eax3ERHHz X-Received: by 2002:a17:906:524b:: with SMTP id y11mr5664472ejm.82.1572547606110; Thu, 31 Oct 2019 11:46:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572547606; cv=none; d=google.com; s=arc-20160816; b=J/w8veD6Gu6C25Ylq80XX399IIlM0sNSQbmMugELqrns5KjMW9kgKnYS1XPgVQ4cEk zrNrhZbRP8G7gqZWEXrY926XrR43mcmWR+xarTPY3Ftmosidtmem2b3u9h0fwGSClZ2s ZM526oUPREs4robSOrmV3mIszlm7cNKk0JLU1yMWkp7eepcI95Cown/NqkQTnVfwz1ZR QwIctX66BPcxyag51TPgCbvwKr5s4zkwL7bZ/eofj+6LZMMft5UTfSELoczcqE0dLR+J 5CI0vmCjchR6kC7/+67wFpSsqxZNqExeAPCl/TnY/ipOjbosmj6F3GuVhXP17xo9VcLo R8jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fT2QZouQmQ2Ctrmo6ejwMTUc59KuMwwwRwqJVgbyZyY=; b=M9rB2qdp6nDHFS67ywyBKTpGK8nNZZfNBYZVis5H/ZpLbK1J9Gf8iCX/q2dth0v7Zv UVJFk5bnaBdrh8+fiEolDCHWS2Z7Lmpemf7ViQ9eeJOdg5Pc9HI7urNlGd5sNZIufXP8 Dp6UIYCqrxMcoi2fSxCJItRPHCD9Mbe9zj9K0yK4HLCdWYOfaTeB2etc+Wht+jTEC26A yQEX07txzTf45RISMOvOrbytwbN//iPZXJnZNge8DoEDtcz+Z6IRCxjtlEv2URz/HWSs DXkraEFDpffcdLxRykyQTF7u5mwFwJgAVDrv2Rmp8cBMT/XnG6JEJgZMKozEShde15iI HjxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yBR0GiSV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y71si5100522ede.135.2019.10.31.11.46.45; Thu, 31 Oct 2019 11:46:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yBR0GiSV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729452AbfJaSqn (ORCPT + 26 others); Thu, 31 Oct 2019 14:46:43 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:43679 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729402AbfJaSqj (ORCPT ); Thu, 31 Oct 2019 14:46:39 -0400 Received: by mail-pl1-f196.google.com with SMTP id a18so1936472plm.10 for ; Thu, 31 Oct 2019 11:46:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fT2QZouQmQ2Ctrmo6ejwMTUc59KuMwwwRwqJVgbyZyY=; b=yBR0GiSVnWg50XjdcAlI/ULSEky12wxmCJywQBEnNlUGiXIlpfedN2UqEsTHg0DQle HIkGcEMry7uKcbhlUGk7RvBVupzYaY4B4Xscr5b9OTl18yRZAvd8RJMgZuBU8jv55ROM t9YsrAINhQZHgrUSVVShm7WS5BvhvGP953XEVCVK+OixISTdil/fhZgR3oW5CEk6NAx7 p5u8AZzAiAEqui/EhnSS657cwdAa2YrXb/qOv3tY/KbcxPePoKQsrATr2uPO/Ca0iCpk +6nh7YLe9rykgNXcpOejFqVDGxuJuTv7rrL9M5YKRLfXCcQm1pyJJK9PEk4JCmq/jKYL J4Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fT2QZouQmQ2Ctrmo6ejwMTUc59KuMwwwRwqJVgbyZyY=; b=Awof+Ta/V7/Yc8nQakSExhnlldPUvuJb36+jLzJ2qSHcDd4c3S8A62pwHGYVMr3tQH TpuQMNYE6z6veHgGrjJd0wqy2rRi+KUhTaHSD1v6p5GEF0VNAtFQdJCGaIca8PByxIqo FVWWTQASqAg9Erht0zM4iTnNB7CEN2MlcRhJQB3l9/uj6mdNdoS1QALe7e3yM+JUmhD0 1OqZQhSuBoS4w4U5+DmXOHxbQoCLlNyVLe27ofb//gDHnYUeUps9WBLFTKbNVcOlqoqY 9SNW+JuIVtG+rsKYUJxDlqIcl7w/CK5s6xnbBbCT74khBidpfPQ/Em/XLj0XyE4dTBjq a19Q== X-Gm-Message-State: APjAAAV5gvAB34d/iYRJMDBGwivmxzCLzIiEmIe9olHvM/Defu+DOjCj WsWQ8XaliTnDyKBUfjcngsrQgQ== X-Received: by 2002:a17:902:4a:: with SMTP id 68mr7999842pla.8.1572547598423; Thu, 31 Oct 2019 11:46:38 -0700 (PDT) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id b82sm3950874pfb.33.2019.10.31.11.46.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2019 11:46:37 -0700 (PDT) From: Bjorn Andersson To: Ohad Ben-Cohen , Bjorn Andersson Cc: Avaneesh Kumar Dwivedi , linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, Jeffrey Hugo , Sibi Sankar Subject: [PATCH 2/2] remoteproc: qcom_q6v5_mss: Validate each segment during loading Date: Thu, 31 Oct 2019 11:46:32 -0700 Message-Id: <20191031184632.2938295-3-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191031184632.2938295-1-bjorn.andersson@linaro.org> References: <20191031184632.2938295-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The code used to sync with the MBA after each segment loaded and this is still what's done downstream. So reduce the delta towards downstream by switching to a model where the content is iteratively validated. Signed-off-by: Bjorn Andersson --- drivers/remoteproc/qcom_q6v5_mss.c | 74 ++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 24 deletions(-) -- 2.23.0 diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c index f4a02105d539..bdf1dd00b89b 100644 --- a/drivers/remoteproc/qcom_q6v5_mss.c +++ b/drivers/remoteproc/qcom_q6v5_mss.c @@ -358,23 +358,29 @@ static void q6v5_pds_disable(struct q6v5 *qproc, struct device **pds, } static int q6v5_xfer_mem_ownership(struct q6v5 *qproc, int *current_perm, - bool remote_owner, phys_addr_t addr, + bool local, bool remote, phys_addr_t addr, size_t size) { - struct qcom_scm_vmperm next; + struct qcom_scm_vmperm next[2]; + int perms = 0; if (!qproc->need_mem_protection) return 0; - if (remote_owner && *current_perm == BIT(QCOM_SCM_VMID_MSS_MSA)) - return 0; - if (!remote_owner && *current_perm == BIT(QCOM_SCM_VMID_HLOS)) - return 0; - next.vmid = remote_owner ? QCOM_SCM_VMID_MSS_MSA : QCOM_SCM_VMID_HLOS; - next.perm = remote_owner ? QCOM_SCM_PERM_RW : QCOM_SCM_PERM_RWX; + if (local) { + next[perms].vmid = QCOM_SCM_VMID_HLOS; + next[perms].perm = QCOM_SCM_PERM_RWX; + perms++; + } + + if (remote) { + next[perms].vmid = QCOM_SCM_VMID_MSS_MSA; + next[perms].perm = QCOM_SCM_PERM_RW; + perms++; + } return qcom_scm_assign_mem(addr, ALIGN(size, SZ_4K), - current_perm, &next, 1); + current_perm, next, perms); } static int q6v5_load(struct rproc *rproc, const struct firmware *fw) @@ -681,7 +687,7 @@ static int q6v5_mpss_init_image(struct q6v5 *qproc, const struct firmware *fw) /* Hypervisor mapping to access metadata by modem */ mdata_perm = BIT(QCOM_SCM_VMID_HLOS); - ret = q6v5_xfer_mem_ownership(qproc, &mdata_perm, true, phys, size); + ret = q6v5_xfer_mem_ownership(qproc, &mdata_perm, false, true, phys, size); if (ret) { dev_err(qproc->dev, "assigning Q6 access to metadata failed: %d\n", ret); @@ -699,7 +705,7 @@ static int q6v5_mpss_init_image(struct q6v5 *qproc, const struct firmware *fw) dev_err(qproc->dev, "MPSS header authentication failed: %d\n", ret); /* Metadata authentication done, remove modem access */ - xferop_ret = q6v5_xfer_mem_ownership(qproc, &mdata_perm, false, phys, size); + xferop_ret = q6v5_xfer_mem_ownership(qproc, &mdata_perm, true, false, phys, size); if (xferop_ret) dev_warn(qproc->dev, "mdt buffer not reclaimed system may become unstable\n"); @@ -786,7 +792,7 @@ static int q6v5_mba_load(struct q6v5 *qproc) } /* Assign MBA image access in DDR to q6 */ - ret = q6v5_xfer_mem_ownership(qproc, &qproc->mba_perm, true, + ret = q6v5_xfer_mem_ownership(qproc, &qproc->mba_perm, false, true, qproc->mba_phys, qproc->mba_size); if (ret) { dev_err(qproc->dev, @@ -820,8 +826,8 @@ static int q6v5_mba_load(struct q6v5 *qproc) q6v5proc_halt_axi_port(qproc, qproc->halt_map, qproc->halt_nc); reclaim_mba: - xfermemop_ret = q6v5_xfer_mem_ownership(qproc, &qproc->mba_perm, false, - qproc->mba_phys, + xfermemop_ret = q6v5_xfer_mem_ownership(qproc, &qproc->mba_perm, true, + false, qproc->mba_phys, qproc->mba_size); if (xfermemop_ret) { dev_err(qproc->dev, @@ -888,7 +894,7 @@ static void q6v5_mba_reclaim(struct q6v5 *qproc) /* In case of failure or coredump scenario where reclaiming MBA memory * could not happen reclaim it here. */ - ret = q6v5_xfer_mem_ownership(qproc, &qproc->mba_perm, false, + ret = q6v5_xfer_mem_ownership(qproc, &qproc->mba_perm, true, false, qproc->mba_phys, qproc->mba_size); WARN_ON(ret); @@ -915,6 +921,7 @@ static int q6v5_mpss_load(struct q6v5 *qproc) phys_addr_t boot_addr; phys_addr_t min_addr = PHYS_ADDR_MAX; phys_addr_t max_addr = 0; + u32 code_length; bool relocate = false; char *fw_name; size_t fw_name_len; @@ -965,9 +972,19 @@ static int q6v5_mpss_load(struct q6v5 *qproc) } /* Try to reset ownership back to Linux */ - q6v5_xfer_mem_ownership(qproc, &qproc->mpss_perm, false, + q6v5_xfer_mem_ownership(qproc, &qproc->mpss_perm, true, false, qproc->mpss_phys, qproc->mpss_size); + /* Share ownership between Linux and MSS, during segment loading */ + ret = q6v5_xfer_mem_ownership(qproc, &qproc->mpss_perm, true, true, + qproc->mpss_phys, qproc->mpss_size); + if (ret) { + dev_err(qproc->dev, + "assigning Q6 access to mpss memory failed: %d\n", ret); + ret = -EAGAIN; + goto release_firmware; + } + mpss_reloc = relocate ? min_addr : qproc->mpss_phys; qproc->mpss_reloc = mpss_reloc; /* Load firmware segments */ @@ -1016,10 +1033,24 @@ static int q6v5_mpss_load(struct q6v5 *qproc) phdr->p_memsz - phdr->p_filesz); } size += phdr->p_memsz; + + code_length = readl(qproc->rmb_base + RMB_PMI_CODE_LENGTH_REG); + if (!code_length) { + boot_addr = relocate ? qproc->mpss_phys : min_addr; + writel(boot_addr, qproc->rmb_base + RMB_PMI_CODE_START_REG); + writel(RMB_CMD_LOAD_READY, qproc->rmb_base + RMB_MBA_COMMAND_REG); + } + writel(size, qproc->rmb_base + RMB_PMI_CODE_LENGTH_REG); + + ret = readl(qproc->rmb_base + RMB_MBA_STATUS_REG); + if (ret < 0) { + dev_err(qproc->dev, "MPSS authentication failed: %d\n", ret); + goto release_firmware; + } } /* Transfer ownership of modem ddr region to q6 */ - ret = q6v5_xfer_mem_ownership(qproc, &qproc->mpss_perm, true, + ret = q6v5_xfer_mem_ownership(qproc, &qproc->mpss_perm, false, true, qproc->mpss_phys, qproc->mpss_size); if (ret) { dev_err(qproc->dev, @@ -1028,11 +1059,6 @@ static int q6v5_mpss_load(struct q6v5 *qproc) goto release_firmware; } - boot_addr = relocate ? qproc->mpss_phys : min_addr; - writel(boot_addr, qproc->rmb_base + RMB_PMI_CODE_START_REG); - writel(RMB_CMD_LOAD_READY, qproc->rmb_base + RMB_MBA_COMMAND_REG); - writel(size, qproc->rmb_base + RMB_PMI_CODE_LENGTH_REG); - ret = q6v5_rmb_mba_wait(qproc, RMB_MBA_AUTH_COMPLETE, 10000); if (ret == -ETIMEDOUT) dev_err(qproc->dev, "MPSS authentication timed out\n"); @@ -1096,8 +1122,8 @@ static int q6v5_start(struct rproc *rproc) goto reclaim_mpss; } - xfermemop_ret = q6v5_xfer_mem_ownership(qproc, &qproc->mba_perm, false, - qproc->mba_phys, + xfermemop_ret = q6v5_xfer_mem_ownership(qproc, &qproc->mba_perm, true, + false, qproc->mba_phys, qproc->mba_size); if (xfermemop_ret) dev_err(qproc->dev,