From patchwork Mon Jun 1 17:55:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11582475 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D3F2690 for ; Mon, 1 Jun 2020 17:58:37 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id B0B702074B for ; Mon, 1 Jun 2020 17:58:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="BuUQwlib"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="jEjCzgdu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B0B702074B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=EcdwJk4IRWdUlOM8sMWiUNgHVyXr+JoZj9N0LlrAk5o=; b=BuUQwlibijIBfO JtLjkVAeF+L8gsjpzYER2D71ZZ2BVGXo9MRsyu5nSMnw3VKmyHGGACXU08Z40KO4lmX0qeUIdJqZr OXyTj62lqxtLyFU+joRLzOWJvrx8moW6btCT3Iw6OpCUompZqCSUOLhBtzeAelluZ+TlQj9ihtL3l O/DFBVor0kvpXLm+T6vi9uiURCcLFJF9xr1ohkhk8N7v4Hf1j6oAgg1GsYyr9q4QL4SN4pXgYCBMI os2SMbsJ1XpD+jkZdUctbHKN39J9JY6x1sIZxcqDNfVRctAs0HhPORUUOJjC7edQitCieQ5y61G/Y wJFTNLjvu1bjsyPQez8Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jfohj-00074s-3l; Mon, 01 Jun 2020 17:58:31 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jfofP-0004bz-8y for linux-arm-kernel@lists.infradead.org; Mon, 01 Jun 2020 17:56:08 +0000 Received: by mail-pl1-x643.google.com with SMTP id m7so255713plt.5 for ; Mon, 01 Jun 2020 10:56:06 -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=XWgUrN+UJxeOnEn8O9BSntxA58isuMWyp3M6ttChdiM=; b=jEjCzgdu5MsL5KccNh8vxCzKIljzLYVxhF3CBPDDYzqJeFnwEgyE8ZgD0pRMbJAhkG JDFcly9sdSc6Jmt3XMaBExC/AbuJ4wqIMhj+/Vywvdp2RGTqWD7BXg+NhFODVOe2vDS7 G5RTS985vDgtn5vBmfAqKzRnMZRbNI0p6JBtZnbhnvLKdelLH3H8kDXIyjtwYCu7Wccc uViDjvO9CCj9SHisEwviLNpAowii6v9jDA27zw/pqj39NxoPRW16fmxdmTezuDFagk0o R++/uvxlwxMGzUjBApiUUQ34SB129LvaYp9iVl0PwBhb5wbUwyAUYofiiomx3kLMqLnN JE9Q== 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=XWgUrN+UJxeOnEn8O9BSntxA58isuMWyp3M6ttChdiM=; b=EZ02YCWqkkBCwvLZJNwnwsQvFeL5KjeQ11L0tXnhhhCsh5hzEnVlqqEaAleLC71tDc eJk3OVB/VcCNte39eO61FckHQ8cyC7WhJpOQO2/EA9hUxnF48YOLhx+cEZlCLI+M1RQw 7Z9KVayBfyFGwHD1gp7FNmXiah9dqi5UQ4GWuUL/i4LXouXxYpG+O6aEb3JU7mrGm5QC cx0f68jDkTQ/1VgYrA2AmVvD1JMyXFXSYULf1J2eoEL5hmn9zH2Mve62hYD/xdPCII9w lAuaGfu+LUTaTj8rXY4iiOCaVTRIxGlT1/E0HbVZq9AYSqjcq/t+k7j36twgUgIcG/ke y+YQ== X-Gm-Message-State: AOAM530AJi4i/epJ3yb4rCPk/1oKnBa+PSQCyUVYYRbjpJyUTs34jLQU 8XTQa4c0xyCgFLf3+mQSQcxr+Q== X-Google-Smtp-Source: ABdhPJz6Uzgkggx9J2O27bgymb95HzErcAQMVBeWDG+YypocdNA0Y4UMUYMBvXdoeRv4M7+EppSTbg== X-Received: by 2002:a17:90a:a515:: with SMTP id a21mr628227pjq.158.1591034166120; Mon, 01 Jun 2020 10:56:06 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id p7sm64771pfq.184.2020.06.01.10.56.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2020 10:56:05 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com Subject: [PATCH v4 09/11] remoteproc: stm32: Properly handle the resource table when attaching Date: Mon, 1 Jun 2020 11:55:50 -0600 Message-Id: <20200601175552.22286-10-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200601175552.22286-1-mathieu.poirier@linaro.org> References: <20200601175552.22286-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200601_105607_332873_4426CFF3 X-CRM114-Status: GOOD ( 13.74 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:643 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: loic.pallardy@st.com, arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Properly set the remote processor's resource table based on where it was loaded by the external entity when attaching to a remote processor. Mainly based on the work published by Arnaud Pouliquen [1]. [1]. https://patchwork.kernel.org/project/linux-remoteproc/list/?series=239877 Signed-off-by: Mathieu Poirier --- drivers/remoteproc/stm32_rproc.c | 75 ++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c index 9316ce3b03c2..7c8789164af7 100644 --- a/drivers/remoteproc/stm32_rproc.c +++ b/drivers/remoteproc/stm32_rproc.c @@ -38,6 +38,8 @@ #define STM32_MBX_VQ1_ID 1 #define STM32_MBX_SHUTDOWN "shutdown" +#define RSC_TBL_SIZE 1024 + #define M4_STATE_OFF 0 #define M4_STATE_INI 1 #define M4_STATE_CRUN 2 @@ -85,6 +87,7 @@ struct stm32_rproc { struct stm32_mbox mb[MBOX_NB_MBX]; struct workqueue_struct *workqueue; bool secured_soc; + void __iomem *rsc_va; }; static int stm32_rproc_pa_to_da(struct rproc *rproc, phys_addr_t pa, u64 *da) @@ -668,6 +671,74 @@ static int stm32_rproc_get_m4_status(struct stm32_rproc *ddata, return regmap_read(ddata->m4_state.map, ddata->m4_state.reg, state); } +static int stm32_rproc_da_to_pa(struct platform_device *pdev, + struct stm32_rproc *ddata, + u64 da, phys_addr_t *pa) +{ + struct device *dev = &pdev->dev; + struct stm32_rproc_mem *p_mem; + unsigned int i; + + for (i = 0; i < ddata->nb_rmems; i++) { + p_mem = &ddata->rmems[i]; + + if (da < p_mem->dev_addr || + da >= p_mem->dev_addr + p_mem->size) + continue; + + *pa = da - p_mem->dev_addr + p_mem->bus_addr; + dev_dbg(dev, "da %llx to pa %#x\n", da, *pa); + + return 0; + } + + dev_err(dev, "can't translate da %llx\n", da); + + return -EINVAL; +} + +static int stm32_rproc_get_loaded_rsc_table(struct platform_device *pdev, + struct rproc *rproc, + struct stm32_rproc *ddata) +{ + struct device *dev = &pdev->dev; + phys_addr_t rsc_pa; + u32 rsc_da; + int err; + + err = regmap_read(ddata->rsctbl.map, ddata->rsctbl.reg, &rsc_da); + if (err) { + dev_err(dev, "failed to read rsc tbl addr\n"); + return err; + } + + if (!rsc_da) + /* no rsc table */ + return 0; + + err = stm32_rproc_da_to_pa(pdev, ddata, rsc_da, &rsc_pa); + if (err) + return err; + + ddata->rsc_va = devm_ioremap_wc(dev, rsc_pa, RSC_TBL_SIZE); + if (IS_ERR_OR_NULL(ddata->rsc_va)) { + dev_err(dev, "Unable to map memory region: %pa+%zx\n", + &rsc_pa, RSC_TBL_SIZE); + ddata->rsc_va = NULL; + return -ENOMEM; + } + + /* + * The resource table is already loaded in device memory, no need + * to work with a cached table. + */ + rproc->cached_table = NULL; + /* Assuming the resource table fits in 1kB is fair */ + rproc->table_sz = RSC_TBL_SIZE; + rproc->table_ptr = (struct resource_table *)ddata->rsc_va; + + return 0; +} static int stm32_rproc_probe(struct platform_device *pdev) { @@ -708,6 +779,10 @@ static int stm32_rproc_probe(struct platform_device *pdev) ret = stm32_rproc_parse_memory_regions(rproc); if (ret) goto free_resources; + + ret = stm32_rproc_get_loaded_rsc_table(pdev, rproc, ddata); + if (ret) + goto free_resources; } rproc->has_iommu = false;