From patchwork Sat Nov 9 00:40: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: 179007 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp3509321ilf; Fri, 8 Nov 2019 16:40:48 -0800 (PST) X-Google-Smtp-Source: APXvYqzruCe5E/+xWE0ytPfgaYzDqe7H79Zqre5QgZoQ2baIWGS19uluLe0v+QSfVKCMKhhL9zXz X-Received: by 2002:a50:a2e5:: with SMTP id 92mr7656230edm.195.1573260048727; Fri, 08 Nov 2019 16:40:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573260048; cv=none; d=google.com; s=arc-20160816; b=D3dZ+qOF924qRGm140D3+ZhZ4YlmrEAyAfd2txuaSB8gVMb7ubpfTi/v9sQ4yVD3Ei 760IIBlJ14cWNOrjzuLh3UBXPJQSGOQfiww8HH58ebgtugZn33bes09CtjeuglfCtRao BKPiRgF6Wx/HPuV2HDD7RECQ+l1nd5aPXRu3zEwgCp4XNFcXGI/GSGt2a9DUvxhKNhsC YtHz+s18WmC4mCHh76R6PoSu6JZg3p78fnI3nnXgH7xU1YKKuZKtlyA/Ql5KKO60EpmZ lRwYYygLCwRIZ2EdC5PyfNYBDPrsIxe9u3VOWIJ9rGmKNVEr7vZ3PsA89vTusq6b9HUx JUkw== 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=4W4ty972DPX71Iw49mefl5BsapRNw/bFopLDHz4kFy0=; b=CLnp+TzZCIYzkClvqFpGDfOL00CQS9iasR5kP9fTEch28w2bo1ppp2Bsno0bzNqlIj kyOIAkJCTD5aL2AXMs1JsawWK7FHqYd9bq29F7qaf3EijY49AUPwoRL9x1kNXJCcwdD2 eYdtqEgjbz8W2OoVzb+LHfDSIxqZBo+lNMy5KHNVRyvdOyCxyqGvDBzAQfsxiO3U348v kI0X0qUuGSrafCdokjauIBge82WpHII5D7EuKnciuzZ8BvOiVluJ0NmJ6xYxXfMLYpoe MN6VgyvZcjtlakS3C9kF1spctMUZeM0Coj93MWvKqPJ9nUBv8iuWmvoFPd3PNuv1eaL8 luUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CFZtI7nA; 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 b10si5378008eds.63.2019.11.08.16.40.48; Fri, 08 Nov 2019 16:40:48 -0800 (PST) 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=CFZtI7nA; 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 S1730110AbfKIAkk (ORCPT + 26 others); Fri, 8 Nov 2019 19:40:40 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:38261 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729623AbfKIAkj (ORCPT ); Fri, 8 Nov 2019 19:40:39 -0500 Received: by mail-pf1-f195.google.com with SMTP id c13so6147743pfp.5 for ; Fri, 08 Nov 2019 16:40:39 -0800 (PST) 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=4W4ty972DPX71Iw49mefl5BsapRNw/bFopLDHz4kFy0=; b=CFZtI7nAK1OzKUd0yQ8Ucz4zhcGHsvZXBa7pbCuF3Iw5ce+GN2RnxFaThLYdKjRr4N VUOWWPrciOcC6LB7ds6ZMWBV41BBKZCFw/huTrjo8WUNmqrA3hb8h+mdz9ssZnetIUJM W4TiVcCV5GVpmG2UJyCQhCOjLVGjLURU/WRYkl/Rf3eKyi0FcppC8jK7UFj4WqgslSPZ yvIKApcRA0PtNPP6198Oph7PibWznozNKCdeQWC/BD6ZgH3SRSH1RIKKudkonFZyP3gr N3zFICoIEtiVzPwzU8ablbXLkEPWGFrH05XlWnxra9TmzATq5qEUzYh5zABljevOW8mW uOMw== 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=4W4ty972DPX71Iw49mefl5BsapRNw/bFopLDHz4kFy0=; b=Igod96IkbyVdgDhZ0eJC9Nt11IVCsxG0dqMK/3Nwt7WMiOMev+Q6jMx0BJ3kuz03Uq h5mtMTSFJeTUPZv8MvDAaNTlRUKVAp5iBk9rFef2YahaLuaEcMyjoTTplrKY9CljFuQS +GqR66xJDG9jcA6yfOdjZjt9WLRdt5y5OfgiRAgBhdswcPTv9Wkky81Vt0AGBAA7ai3h XBF13uGuLOZwer6QxAdFZ/aMczILdplTX6d2cJ1alDnDJqzyMbVSpUT5Pz/S6d1Pw1U8 JF1207Qb3zIrqnNm89+cHZl5eLEG6UUsAjOpu4ORlr9Nae38LEm9CjDiGvmKEUYl+C8g Cckg== X-Gm-Message-State: APjAAAU0zZhIr1kMQ76IdIBHF4oT5PE28P+esv6EbDHq7vJFEuOn3JRb /bO6S/JH7yFZsSOKEfF5+JXezA== X-Received: by 2002:a63:5511:: with SMTP id j17mr4827052pgb.70.1573260038698; Fri, 08 Nov 2019 16:40:38 -0800 (PST) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id y36sm6681461pgk.66.2019.11.08.16.40.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2019 16:40:38 -0800 (PST) From: Bjorn Andersson To: Ohad Ben-Cohen , Bjorn Andersson , Avaneesh Kumar Dwivedi Cc: linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, Sibi Sankar , Jeffrey Hugo , stable@vger.kernel.org Subject: [PATCH v2 1/2] remoteproc: qcom_q6v5_mss: Don't reassign mpss region on shutdown Date: Fri, 8 Nov 2019 16:40:32 -0800 Message-Id: <20191109004033.1496871-2-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191109004033.1496871-1-bjorn.andersson@linaro.org> References: <20191109004033.1496871-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 --- Changes since v1: - Assign memory back to Linux in coredump case drivers/remoteproc/qcom_q6v5_mss.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) -- 2.23.0 Reviewed-by: Jeffrey Hugo Tested-by: Jeffrey Hugo diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c index de919f2e8b94..efab574b2e12 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 */ @@ -1058,9 +1057,14 @@ static void qcom_q6v5_dump_segment(struct rproc *rproc, void *ptr = rproc_da_to_va(rproc, segment->da, segment->size); /* Unlock mba before copying segments */ - if (!qproc->dump_mba_loaded) + if (!qproc->dump_mba_loaded) { ret = q6v5_mba_load(qproc); + /* Try to reset ownership back to Linux */ + q6v5_xfer_mem_ownership(qproc, &qproc->mpss_perm, false, + qproc->mpss_phys, qproc->mpss_size); + } + if (!ptr || ret) memset(dest, 0xff, segment->size); else @@ -1111,10 +1115,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 Sat Nov 9 00:40:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 179008 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp3509330ilf; Fri, 8 Nov 2019 16:40:49 -0800 (PST) X-Google-Smtp-Source: APXvYqzxbuM7Xbv1aT9A8NLftywT1eVWCb2p4J8IDktLGBQ9iHqiKNwNiV7qOc6OtefAAmgnPmd8 X-Received: by 2002:aa7:d295:: with SMTP id w21mr13485020edq.13.1573260049155; Fri, 08 Nov 2019 16:40:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573260049; cv=none; d=google.com; s=arc-20160816; b=WREokO0XsBNt3HOYgMQzoEfezagTfKKugjYTudUU8LDblmgEtYz3cJkw7QYyElyBTQ 8RNQGCeV89/njJUA/gBz+XRaquazXViqS1Ba7NdBwXyuJKI2EdQsnsLngtBB26gsVnIC SC6euEtvI6uI+pAOt2eugJEn5w6FmqQ4IDa21GIBOSJ0BlIBlkx8Lyt/UdA+BCf3Futp eF/xkX5YIRJZ8fASFGSM7WN5DIdf5zlNqS3eIsh9+r+9MXsN78UYQk3sRscMX3rApOGz igxyW1H9O35CN34rkI2ql2oZ+d1H30PwT7hZXL0XI2raFFTd4fERKJs3XWIJD5uiAQvo kogA== 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=705HB2azoG200nwS3o3zO3rtDYqxCRBnG4hOOCQq8EM=; b=EKNkgtd2xSCW+JrC1vQD9RRk7ZWmL3K/cQ4pmfY+as7Xl1//eD1w6Gztds1btpdM5A OZztQMSlOALL8wDi95UH8dAvg2S762rVIcFqbmtZlQsZLpQZh6Tf7Zuen/QrKR4buClE p3m0eRuotGpC/YUHwL96XZaAmAdsmG/dg/i4Ti+uADeJDPQwmvGcmwdqXTz1R/gKVi+T lNwH8XgUYsHJ6QYld0LlRHfdGKvrRAyrC4Jm3qoJtaA64oFSbjW8Vlw+/iN5SRgNqySO WUQJYsoLocVOYyMa+wehKW2+wjVMGMinBRKz3eVMDUW4uVHM3cqZwahuUC7ie55c12OT Q81Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vBtJh5iZ; 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 b10si5378008eds.63.2019.11.08.16.40.48; Fri, 08 Nov 2019 16:40:49 -0800 (PST) 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=vBtJh5iZ; 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 S1730614AbfKIAkl (ORCPT + 26 others); Fri, 8 Nov 2019 19:40:41 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:42478 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730154AbfKIAkl (ORCPT ); Fri, 8 Nov 2019 19:40:41 -0500 Received: by mail-pf1-f195.google.com with SMTP id s5so6128684pfh.9 for ; Fri, 08 Nov 2019 16:40:40 -0800 (PST) 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=705HB2azoG200nwS3o3zO3rtDYqxCRBnG4hOOCQq8EM=; b=vBtJh5iZty4ax9mbgk+Lt9/4w+HA8JQ8hKBUrXr3gdOy84AhmP8L4Ltjt+B3mrqM4x WViU03gq39CuEruIjdcPij9fd0OMEGBpGV58E8SVMW+xZv5Ozklur6FJI0JTcqs9VZQQ ra7XVIIKa9KXR9/g5uIAav0qS41V9/dwBscejKuHM5cd5i7KTUXIa7yzA+jmtR4Jazfh UqoE4mdJLnhjSIvuTvJS99sTo6C5vaD/9HHUgJkQfDRxqEr4b6k0r9VpS9Ect6Id3LPy DjAOf5XHZskq3Sp8nzUKAOmbOQNd5zccJVRbegg+zM/IUPKAQx6hCgqcbFZA1zIhV7xb zP2A== 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=705HB2azoG200nwS3o3zO3rtDYqxCRBnG4hOOCQq8EM=; b=P/GvZcbRZ1AyzpdCnGU9N98wXlk4Fkck3JcmeqsPhiC+3CaCHxzW2OZfqPV0Pwy40X 52GbrFGbYftlthDJVcmp8mQIBvxQpaTGGyyPECUmruPaywH2zDhu/7EyzF/64FhXnWrs ILmxmpQyQCzLCbkk+SpvTENDi/zDhqj8Ll+waqNumsQe8GTf0QXdaQbfVKBGAtgZFH7A 4TSes8MBT8/tqOUMU68JzvFLZqcY/0RUPcsnabePsI59Bf3JtD1Xzzt3wDOFokANgQO6 sx2FMRtK6Gk4ooQVigbu11QPsxsE0l2GPjiphngyGy9IfeDKCSWWNcc1CZJ5+UsDxQGs LDwA== X-Gm-Message-State: APjAAAUazjbcST9RhYaxPPbWuiyi8Qsgu38t0dl8M7T90gFHYImI50ty jAakUiu9S30QvPk92Ql666xHwA== X-Received: by 2002:a63:f441:: with SMTP id p1mr15349274pgk.362.1573260040059; Fri, 08 Nov 2019 16:40:40 -0800 (PST) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id y36sm6681461pgk.66.2019.11.08.16.40.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2019 16:40:39 -0800 (PST) From: Bjorn Andersson To: Ohad Ben-Cohen , Bjorn Andersson , Avaneesh Kumar Dwivedi Cc: linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, Sibi Sankar , Jeffrey Hugo Subject: [PATCH v2 2/2] remoteproc: qcom_q6v5_mss: Validate each segment during loading Date: Fri, 8 Nov 2019 16:40:33 -0800 Message-Id: <20191109004033.1496871-3-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191109004033.1496871-1-bjorn.andersson@linaro.org> References: <20191109004033.1496871-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. Reviewed-by: Jeffrey Hugo Tested-by: Jeffrey Hugo Signed-off-by: Bjorn Andersson --- Changes since v1: - Picked up Jeff's r-b and t-b drivers/remoteproc/qcom_q6v5_mss.c | 76 ++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 25 deletions(-) -- 2.23.0 diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c index efab574b2e12..914d5546e1cf 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"); @@ -1061,7 +1087,7 @@ static void qcom_q6v5_dump_segment(struct rproc *rproc, ret = q6v5_mba_load(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); } @@ -1101,8 +1127,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,