From patchwork Fri Jul 27 13:14:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 143048 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp806662ljj; Fri, 27 Jul 2018 06:15:26 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd3o/mcAp+pWshN5DYHVlxKJjQJGi2QZVPjHFqAkWOMUNk+K3KosNIgQSRPUQnuKPlXTLMr X-Received: by 2002:a17:902:bd97:: with SMTP id q23-v6mr6059314pls.311.1532697325855; Fri, 27 Jul 2018 06:15:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532697325; cv=none; d=google.com; s=arc-20160816; b=wxOmtyRwwrZka0BcqPlDOqwvjzr++MkmoPrh5urfH5Z054kbBWPc/055S+g/TPdAAT IYcBjM55xR5BlpDV+1QGXvTHssXWhH1tYnKcR7LgBV3luvWrO1pJs+U/lJ1zmY1Df3b8 UE2QAST1VjsMvCYS93k66BOplMVdjKg7CH2R9faJtSJ5+KJyUCZSOOVEhAscaltCh2AR U0oL50mLsHE7RjBh8R2sga+9nYvTAiVbJ9GLq7YIsRAwk+7RZcNwefYSb/3L57JscFXF hrlh/WlVrk7HVeEfJ1kq540pOpj4jP7dU7Qb2QHxfThmDlce8qh5p6XyXDscD1ffmjn7 /4Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=61HX4v53lFjf1VRtWI8OhT8O5R/DU69bxHb7w5OJaSI=; b=S3HrlzDUy75zKF9zDd3sJgee0gHTNJZRAxcG8KmUoukGlvracOi32/QU5mgmLk/tzV XKfSZrKzIsmyOdVJGnJ5D5Ffz88AVxrBHqYSSq7AWkNwmfKZw4pR7pZ5RraogIvc3Uhd 8GnGqfCxXH1PgyWKd8BJYKfZAVGu7cNSWx8z29Dk9328AjS4r+yG4FknvtuO/Dm5QIWz fD+ThT7mvshxSsk936bnhiUxXgGD1xH+S1AkRWpPk5Nl1lFW7uZS87wcoJ3NNf4nBIgz ZHCG4XCV61QuoQEC1D9N5LxHck4t+oMpk0kw1ilksdiDuNvadYkKroO0JwlQAD6xtt8s ovLA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 184-v6si3992936pgj.421.2018.07.27.06.15.25; Fri, 27 Jul 2018 06:15:25 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388141AbeG0OhQ (ORCPT + 31 others); Fri, 27 Jul 2018 10:37:16 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:39841 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730395AbeG0OhQ (ORCPT ); Fri, 27 Jul 2018 10:37:16 -0400 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w6RDE18o014480; Fri, 27 Jul 2018 15:15:18 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2kg1tj8psw-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Jul 2018 15:15:18 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id D4FF431; Fri, 27 Jul 2018 13:15:17 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id B1138577A; Fri, 27 Jul 2018 13:15:17 +0000 (GMT) Received: from localhost (10.75.127.48) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Jul 2018 15:15:17 +0200 From: Loic Pallardy To: , CC: , , , , , Loic Pallardy Subject: [PATCH v4 01/17] remoteproc: configure IOMMU only if device address requested Date: Fri, 27 Jul 2018 15:14:36 +0200 Message-ID: <1532697292-14272-2-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> References: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.48] X-ClientProxiedBy: SFHDAG6NODE1.st.com (10.75.127.16) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-27_06:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If there is no IOMMU associate to remote processor device, remoteproc_core won't be able to satisfy device address requested in firmware resource table. Return an error as configuration won't be coherent. Signed-off-by: Loic Pallardy --- drivers/remoteproc/remoteproc_core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) -- 1.9.1 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 4cd1a8e..437fabf 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -657,7 +657,15 @@ static int rproc_handle_carveout(struct rproc *rproc, * to use the iommu-based DMA API: we expect 'dma' to contain the * physical address in this case. */ - if (rproc->domain) { + + if (rsc->da != FW_RSC_ADDR_ANY && !rproc->domain) { + dev_err(dev->parent, + "Bad carveout rsc configuration\n"); + ret = -ENOMEM; + goto dma_free; + } + + if (rsc->da != FW_RSC_ADDR_ANY && rproc->domain) { mapping = kzalloc(sizeof(*mapping), GFP_KERNEL); if (!mapping) { ret = -ENOMEM; From patchwork Fri Jul 27 13:14:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 143049 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp806694ljj; Fri, 27 Jul 2018 06:15:27 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcokhEAz7zxI4bwzdZk/T8vL3kW5b9soK4J2UDF9Qk7sGi3VgUmYSOB63j8SIejis0O9/bR X-Received: by 2002:a62:4147:: with SMTP id o68-v6mr6580092pfa.111.1532697327660; Fri, 27 Jul 2018 06:15:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532697327; cv=none; d=google.com; s=arc-20160816; b=ilnxNBNh3BRYH1Z5tx8vpnfRQGxQilfBfwGHMSl12VcEAkvTp4rx7Rya/nmhGCp2kM mTjb6GmeecLf7M+/LmFJ2qHtkg8Y/ZTtJpwEwoexNZAneVhqjAAcaY1mMfuo8GqphD7J ULfqgF72x7zaVvUuooS4QEDzf3tZPnBNLPQymagDljSVKkGDcyE5szv99oF4OWbrY/Kj BOn0viM8PZLPH27vsHnKH00x8FMowYJRCKqrEp6kxhVUGZgSQ6FQH+pud35eNn1vX81q aIEJpgCkCfnAg6MQZ4gHbAb+5JFqRmYK/m2lmjc45HwKnyJQfuYyfZYMU7CMJhggGpoy CX7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=Mk5PSJv/y65Km+C/zhPHVNNtcOAlXH0JttrBMNiZUWk=; b=LVPkeQrVyl3+V1p5a65O1QSFynrNmUzLyximrBBP7x5uooQToBWvhkKkqZ/nitI7On L9dZzc9myXrEXI8hn4smfoLfxqJApyURCIRD7Cdquxh8BrZQUqlN8tcX2UBn+y+XC+zM jDNxlfJEpXTUSTpCUq9KVw+4jXUilTNk5AS5qB/xC4RZbi3CrVTrcb6v/IGs6ZDtxDIW BdbsOmWnxhlcB+Yr6agqzR/xmkD01u0mhIE3XuNCLmcri2/GLhmH6d/HVQTiJ+0GHR4p KEzGsXvx4Etvb/Ebsk3el/RY9sgXa3BZfcjtyDNy7JsLDcKI4me16/96f8qnkuspSYR6 xGNQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n1-v6si3509716pld.429.2018.07.27.06.15.27; Fri, 27 Jul 2018 06:15:27 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388449AbeG0OhS (ORCPT + 31 others); Fri, 27 Jul 2018 10:37:18 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:39847 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732452AbeG0OhR (ORCPT ); Fri, 27 Jul 2018 10:37:17 -0400 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w6RDE242014483; Fri, 27 Jul 2018 15:15:21 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2kg1tj8pt1-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Jul 2018 15:15:21 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 7DB0338; Fri, 27 Jul 2018 13:15:20 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 4FCA75780; Fri, 27 Jul 2018 13:15:20 +0000 (GMT) Received: from localhost (10.75.127.51) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Jul 2018 15:15:19 +0200 From: Loic Pallardy To: , CC: , , , , , Loic Pallardy Subject: [PATCH v4 02/17] remoteproc: add rproc_va_to_pa function Date: Fri, 27 Jul 2018 15:14:37 +0200 Message-ID: <1532697292-14272-3-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> References: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.51] X-ClientProxiedBy: SFHDAG4NODE3.st.com (10.75.127.12) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-27_06:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This new function translates CPU virtual address in CPU physical one according to virtual address location. Signed-off-by: Loic Pallardy Acked-by: Bjorn Andersson --- drivers/remoteproc/remoteproc_core.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) -- 1.9.1 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 437fabf..8e5fe1e 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -140,6 +140,22 @@ static void rproc_disable_iommu(struct rproc *rproc) iommu_domain_free(domain); } +static phys_addr_t rproc_va_to_pa(void *cpu_addr) +{ + /* + * Return physical address according to virtual address location + * - in vmalloc: if region ioremapped or defined as dma_alloc_coherent + * - in kernel: if region allocated in generic dma memory pool + */ + if (is_vmalloc_addr(cpu_addr)) { + return page_to_phys(vmalloc_to_page(cpu_addr)) + + offset_in_page(cpu_addr); + } + + WARN_ON(!virt_addr_valid(cpu_addr)); + return virt_to_phys(cpu_addr); +} + /** * rproc_da_to_va() - lookup the kernel virtual address for a remoteproc address * @rproc: handle of a remote processor @@ -711,7 +727,7 @@ static int rproc_handle_carveout(struct rproc *rproc, * In this case, the device address and the physical address * are the same. */ - rsc->pa = dma; + rsc->pa = (u32)rproc_va_to_pa(va); carveout->va = va; carveout->len = rsc->len; From patchwork Fri Jul 27 13:14:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 143064 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp808056ljj; Fri, 27 Jul 2018 06:16:48 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfd5Ue3I/awetRMRzGX6t+1/1XPX0EYngxpk3tZDCoOyMATNRH2K2ueTMeO0HxZ2u8vHJBF X-Received: by 2002:a17:902:780d:: with SMTP id p13-v6mr5915105pll.119.1532697408277; Fri, 27 Jul 2018 06:16:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532697408; cv=none; d=google.com; s=arc-20160816; b=y5EQEobDAN7/5cG99ry69u9rN6igxlqz4cbXECFSN+ImVlwaMQ1IF8vlUxdvURb8aN AXCFvraUTn2kBDZUnnH8wJL5RWJ+fzqZSUpNgUcyrU1+zOa/rSAIRdX6oNMAeJKZ26e3 8LllSxnvd+J2hkOv1ISBc6Qe8uZFgNR1H+75xMY7og3auIHEfoASbLg8sEbuHVpmBA4Y IhmIbJxMesBOGqAyDmBXDN4GTY31B+lzsOG69xJyxPDnNfTYSeohgObSPPzC8iBytK/A 9BUFiQ995ccawsnE1Rsf7OKXCk6VFXX8xDsfZfFVQy6CGFsIfic0qus/HSTCPlBXA2xG tJuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=NNokiySKr4QlH/hYeXNKT4XxMmXIooCouRBqOmtPx5o=; b=LD5PLAcU1Q7CC6ju15AswFygoc3zyK77grqmc4nI07ZIwwTvn3Vue1tdYHkK1b1GLd 1vVb4Aqkvmh+Z/PyhLawNnmmhjUIMzyrQF1u7rhjStwDXCR76GSaUOMIWgy1PsnLkDKv UIzKsYfPJeE5kgSK0MgVkpIMj9BixhpEZeCLkFODpuHZgJ4dRg+5r52w/FUYXdh8nSfX 8NakRWaiTvdA/k5PN58Hish6XN0oAjWmFZfSWUYP882/4YXcL9mPGMMhl4Wz2vvD/wMy xorfWcXjKDk4CaeE8hBgCteJvnqMAqHtWyj9nRRYnxW9d4zIXhmLkIX+YzKU0IG922E4 huVg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b25-v6si3817540pgf.545.2018.07.27.06.16.47; Fri, 27 Jul 2018 06:16:48 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388925AbeG0Oij (ORCPT + 31 others); Fri, 27 Jul 2018 10:38:39 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:31524 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732452AbeG0OhU (ORCPT ); Fri, 27 Jul 2018 10:37:20 -0400 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w6RDEOMl020459; Fri, 27 Jul 2018 15:15:22 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2kg25fgjtj-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Jul 2018 15:15:22 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 6DCCA3D; Fri, 27 Jul 2018 13:15:21 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 49C0A577A; Fri, 27 Jul 2018 13:15:21 +0000 (GMT) Received: from localhost (10.75.127.51) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Jul 2018 15:15:20 +0200 From: Loic Pallardy To: , CC: , , , , , Loic Pallardy Subject: [PATCH v4 03/17] remoteproc: add release ops in rproc_mem_entry struct Date: Fri, 27 Jul 2018 15:14:38 +0200 Message-ID: <1532697292-14272-4-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> References: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.51] X-ClientProxiedBy: SFHDAG3NODE2.st.com (10.75.127.8) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-27_06:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Memory entry could be allocated in different ways (ioremap, dma_alloc_coherent, internal RAM allocator...). This patch introduces a release ops in rproc_mem_entry structure to associate dedicated release mechanism to each memory entry descriptor in order to keep remoteproc core generic. Signed-off-by: Loic Pallardy Acked-by: Bjorn Andersson --- drivers/remoteproc/remoteproc_core.c | 23 +++++++++++++++++++++-- include/linux/remoteproc.h | 5 ++++- 2 files changed, 25 insertions(+), 3 deletions(-) -- 1.9.1 Acked-by: Suman Anna diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 8e5fe1e..24fe11f 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -600,6 +600,24 @@ static int rproc_handle_devmem(struct rproc *rproc, struct fw_rsc_devmem *rsc, } /** + * rproc_release_carveout() - release acquired carveout + * @rproc: rproc handle + * @mem: the memory entry to release + * + * This function releases specified memory entry @mem allocated via + * dma_alloc_coherent() function by @rproc. + */ +static int rproc_release_carveout(struct rproc *rproc, + struct rproc_mem_entry *mem) +{ + struct device *dev = &rproc->dev; + + /* clean up carveout allocations */ + dma_free_coherent(dev->parent, mem->len, mem->va, mem->dma); + return 0; +} + +/** * rproc_handle_carveout() - handle phys contig memory allocation requests * @rproc: rproc handle * @rsc: the resource entry @@ -733,6 +751,7 @@ static int rproc_handle_carveout(struct rproc *rproc, carveout->len = rsc->len; carveout->dma = dma; carveout->da = rsc->da; + carveout->release = rproc_release_carveout; list_add_tail(&carveout->node, &rproc->carveouts); @@ -920,8 +939,8 @@ static void rproc_resource_cleanup(struct rproc *rproc) /* clean up carveout allocations */ list_for_each_entry_safe(entry, tmp, &rproc->carveouts, node) { - dma_free_coherent(dev->parent, entry->len, entry->va, - entry->dma); + if (entry->release) + entry->release(rproc, entry); list_del(&entry->node); kfree(entry); } diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index e3c5d85..bef2e83 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -305,12 +305,15 @@ struct fw_rsc_vdev { struct fw_rsc_vdev_vring vring[0]; } __packed; +struct rproc; + /** * struct rproc_mem_entry - memory entry descriptor * @va: virtual address * @dma: dma address * @len: length, in bytes * @da: device address + * @release: release associated memory * @priv: associated data * @node: list node */ @@ -321,9 +324,9 @@ struct rproc_mem_entry { u32 da; void *priv; struct list_head node; + int (*release)(struct rproc *rproc, struct rproc_mem_entry *mem); }; -struct rproc; struct firmware; /** From patchwork Fri Jul 27 13:14:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 143050 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp806722ljj; Fri, 27 Jul 2018 06:15:30 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfhuz7A/SXlXMyHNYuEtV9c+/ojfDClINuG1kV1RYm2aZyjQbecIhB7Ja8VWSa6blpkSf9f X-Received: by 2002:a63:214f:: with SMTP id s15-v6mr6024019pgm.267.1532697330070; Fri, 27 Jul 2018 06:15:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532697330; cv=none; d=google.com; s=arc-20160816; b=MpI1ppJyrersgprZ3DJM81qnbMFFU2q/erbNREDXCZ1kcjD8KPiq2QiToTHFgLSzbD DitonNz4tl329KIdGCgD/FyyqoHhXOGRhz+M6T97rzds2TxpXelGqwMmfL5Z6g+1Aj2/ Y1wdA/IopBNuXC7RxiS1KnOsuimMpu0OdIVLjS5MnkYVzcGRyB9XbVVIJaueCfxrU8Pi Za8kZYhgpvHjvfulCYeh/ORF2Lj9GIkDTFA4Vd1ZgM20oIqaipij9FyYbXL1zr55tq2+ O+i6ZmfjQOdVF/O6KnaWgqknoHW1NVtHk75JzVCx4zxPFucNt1bZd77eU74kRZpbOVwA /UtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=8mDzmvDIerlajglodCdgrmpc+S+5EzPLDY3ctAMnq5k=; b=ioB5355lR0xjfcPWB4DVKHqF9jYWanIshKzVv1TfYsTiJsQjebz/lHSGPEupm3yaTD zU5Rhp7wT/TXwoVUMYASp1peJ2jsr0tZvqrwD+OgiadLJSqh8U7RybL70M8iogp24bFn e2Bsw79d0NbDkwg/IXcCExd2+P/zVlPhg77y8MJnveHF9liZJnjNGpAPOIZnY76m12EY 3GwFy7wln1j2coy6gDG0nIObTBIX9ESDEcOvjXAD+XHZDhdx6aMuI+HzfvI9AjaCr1tj dLUn1q0TibBLymfGOCA06hJJWn7ffdKDw8YT0/xnCGMobMC1JdaeZhTh7lX0qdgazQzz mc0w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s184-v6si3849499pgb.161.2018.07.27.06.15.29; Fri, 27 Jul 2018 06:15:30 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388533AbeG0OhU (ORCPT + 31 others); Fri, 27 Jul 2018 10:37:20 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:46594 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388298AbeG0OhU (ORCPT ); Fri, 27 Jul 2018 10:37:20 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w6RDEjsq025001; Fri, 27 Jul 2018 15:15:23 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2kg1up0ns3-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Jul 2018 15:15:22 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 454F938; Fri, 27 Jul 2018 13:15:22 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 26E80577A; Fri, 27 Jul 2018 13:15:22 +0000 (GMT) Received: from localhost (10.75.127.50) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Jul 2018 15:15:21 +0200 From: Loic Pallardy To: , CC: , , , , , Loic Pallardy Subject: [PATCH v4 04/17] remoteproc: add name in rproc_mem_entry struct Date: Fri, 27 Jul 2018 15:14:39 +0200 Message-ID: <1532697292-14272-5-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> References: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG1NODE2.st.com (10.75.127.2) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-27_06:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add name field in struct rproc_mem_entry. This new field will be used to match memory area requested in resource table with pre-registered carveout. Signed-off-by: Loic Pallardy Acked-by: Bjorn Andersson --- drivers/remoteproc/remoteproc_core.c | 1 + drivers/remoteproc/remoteproc_debugfs.c | 1 + include/linux/remoteproc.h | 2 ++ 3 files changed, 4 insertions(+) -- 1.9.1 Acked-by: Suman Anna diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 24fe11f..d7e3138 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -752,6 +752,7 @@ static int rproc_handle_carveout(struct rproc *rproc, carveout->dma = dma; carveout->da = rsc->da; carveout->release = rproc_release_carveout; + strlcpy(carveout->name, rsc->name, sizeof(carveout->name)); list_add_tail(&carveout->node, &rproc->carveouts); diff --git a/drivers/remoteproc/remoteproc_debugfs.c b/drivers/remoteproc/remoteproc_debugfs.c index a5c29f2..e90135c 100644 --- a/drivers/remoteproc/remoteproc_debugfs.c +++ b/drivers/remoteproc/remoteproc_debugfs.c @@ -260,6 +260,7 @@ static int rproc_carveouts_show(struct seq_file *seq, void *p) list_for_each_entry(carveout, &rproc->carveouts, node) { seq_puts(seq, "Carveout memory entry:\n"); + seq_printf(seq, "\tName: %s\n", carveout->name); seq_printf(seq, "\tVirtual address: %pK\n", carveout->va); seq_printf(seq, "\tDMA address: %pad\n", &carveout->dma); seq_printf(seq, "\tDevice address: 0x%x\n", carveout->da); diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index bef2e83..0e21098 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -315,6 +315,7 @@ struct fw_rsc_vdev { * @da: device address * @release: release associated memory * @priv: associated data + * @name: associated memory region name (optional) * @node: list node */ struct rproc_mem_entry { @@ -323,6 +324,7 @@ struct rproc_mem_entry { int len; u32 da; void *priv; + char name[32]; struct list_head node; int (*release)(struct rproc *rproc, struct rproc_mem_entry *mem); }; From patchwork Fri Jul 27 13:14:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 143051 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp806766ljj; Fri, 27 Jul 2018 06:15:31 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeGwYRZABlUAlQQ1plsGhsdkMwlm1Mh89YlOx94cxuKWePAcIh7PW+xffinB7QnEwh0Y/oN X-Received: by 2002:a63:1844:: with SMTP id 4-v6mr6213425pgy.313.1532697331687; Fri, 27 Jul 2018 06:15:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532697331; cv=none; d=google.com; s=arc-20160816; b=B8C5N0kyagy7yvgR6m5/KX88V//juNUCdgd0nLLpKMzFax4nv0RjVvuzHG3QjIKz6p c8H56Cmds276BlpLJPXyOpR4zaczda6ng2la7fZSB+ZuMyt+nH1pltexwevnhQdQyTRJ 4wBNNNEEZLWHnJYiOMJxtCyzuqdTK6O3qryUxtOp2Wpfq/9CU2uo4BTbqyklsvdEVWwU KKIh7HuRSkpT2WXnnasreZGw32xrgNsZWBDLNs1JCCAQ93cScHVzTiMmrTkCgoUtr0lS LHP7oJM7Znn2eTLkVDdo69kVRRME3Q97rIyPdkCW3kNw0UZdre+TLZY1lhjaqsDlWfxd LUCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=54JLXTC/9R6UWi3Zn6oyeYx3SovOE+bPfzbfcmmtNok=; b=R5tXy5pc4DCxNMeiJeKZOKht1fLQGoMDVWxPhZi9kXUSbxfzREgrbJCuTWwYyGf7GV 28wSbtb0x27XRyF5+KrwFiN2gD+cNxzUHVD3j200W6wrp7YAlwGb1pLPq+FmB8IHJ0wM VJrvbLTU6uwh5XayJxSA073yTB77dmyxqirRTRROTVqr4iK5yUx8QI2TDr9T1tJiJhDU Cuv6Z4HVkxMFrNi5LouEEsgrTDRxOq/Ygyh8xbnjwnnS16qD0fNW+f/YKjIyNqnuZ9S3 tz1FNpQBHPY4+Rc+BmOtdfuRsjmEXAFk0hx35nMsCXy9umItgDH9byWzSvh3xW8Bf2Oz Z0Tw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s2-v6si4368858pfs.2.2018.07.27.06.15.31; Fri, 27 Jul 2018 06:15:31 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388580AbeG0OhV (ORCPT + 31 others); Fri, 27 Jul 2018 10:37:21 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:39639 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388468AbeG0OhV (ORCPT ); Fri, 27 Jul 2018 10:37:21 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w6RDETgH024981; Fri, 27 Jul 2018 15:15:24 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2kg1up0ns6-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Jul 2018 15:15:24 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 4747D3D; Fri, 27 Jul 2018 13:15:23 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 23CC2577E; Fri, 27 Jul 2018 13:15:23 +0000 (GMT) Received: from localhost (10.75.127.49) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Jul 2018 15:15:22 +0200 From: Loic Pallardy To: , CC: , , , , , Loic Pallardy Subject: [PATCH v4 05/17] remoteproc: add helper function to allocate and init rproc_mem_entry struct Date: Fri, 27 Jul 2018 15:14:40 +0200 Message-ID: <1532697292-14272-6-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> References: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.49] X-ClientProxiedBy: SFHDAG8NODE1.st.com (10.75.127.22) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-27_06:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch introduces rproc_mem_entry_init helper function to simplify rproc_mem_entry structure allocation and filling by client. Signed-off-by: Loic Pallardy --- drivers/remoteproc/remoteproc_core.c | 65 +++++++++++++++++++++++++++--------- include/linux/remoteproc.h | 6 ++++ 2 files changed, 55 insertions(+), 16 deletions(-) -- 1.9.1 Reviewed-by: Suman Anna diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index d7e3138..b76760e 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -639,7 +639,7 @@ static int rproc_handle_carveout(struct rproc *rproc, struct fw_rsc_carveout *rsc, int offset, int avail) { - struct rproc_mem_entry *carveout, *mapping; + struct rproc_mem_entry *carveout, *mapping = NULL; struct device *dev = &rproc->dev; dma_addr_t dma; void *va; @@ -659,16 +659,11 @@ static int rproc_handle_carveout(struct rproc *rproc, dev_dbg(dev, "carveout rsc: name: %s, da 0x%x, pa 0x%x, len 0x%x, flags 0x%x\n", rsc->name, rsc->da, rsc->pa, rsc->len, rsc->flags); - carveout = kzalloc(sizeof(*carveout), GFP_KERNEL); - if (!carveout) - return -ENOMEM; - va = dma_alloc_coherent(dev->parent, rsc->len, &dma, GFP_KERNEL); if (!va) { dev_err(dev->parent, "failed to allocate dma memory: len 0x%x\n", rsc->len); - ret = -ENOMEM; - goto free_carv; + return -ENOMEM; } dev_dbg(dev, "carveout va %pK, dma %pad, len 0x%x\n", @@ -747,27 +742,65 @@ static int rproc_handle_carveout(struct rproc *rproc, */ rsc->pa = (u32)rproc_va_to_pa(va); - carveout->va = va; - carveout->len = rsc->len; - carveout->dma = dma; - carveout->da = rsc->da; - carveout->release = rproc_release_carveout; - strlcpy(carveout->name, rsc->name, sizeof(carveout->name)); + carveout = rproc_mem_entry_init(dev, va, dma, rsc->len, rsc->da, + rproc_release_carveout, rsc->name); + if (!carveout) + goto free_carv; list_add_tail(&carveout->node, &rproc->carveouts); return 0; +free_carv: + kfree(carveout); free_mapping: kfree(mapping); dma_free: dma_free_coherent(dev->parent, rsc->len, va, dma); -free_carv: - kfree(carveout); return ret; } -/* +/** + * rproc_mem_entry_init() - allocate and initialize rproc_mem_entry struct + * @dev: pointer on device struct + * @va: virtual address + * @dma: dma address + * @len: memory carveout length + * @da: device address + * @release: memory carveout function + * @name: carveout name + * + * This function allocates a rproc_mem_entry struct and fill it with parameters + * provided by client. + */ +struct rproc_mem_entry * +rproc_mem_entry_init(struct device *dev, + void *va, dma_addr_t dma, int len, u32 da, + int (*release)(struct rproc *, struct rproc_mem_entry *), + const char *name, ...) +{ + struct rproc_mem_entry *mem; + va_list args; + + mem = kzalloc(sizeof(*mem), GFP_KERNEL); + if (!mem) + return mem; + + mem->va = va; + mem->dma = dma; + mem->da = da; + mem->len = len; + mem->release = release; + + va_start(args, name); + vsnprintf(mem->name, sizeof(mem->name), name, args); + va_end(args); + + return mem; +} +EXPORT_SYMBOL(rproc_mem_entry_init); + +/** * A lookup table for resource handlers. The indices are defined in * enum fw_resource_type. */ diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 0e21098..4bc961f 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -558,6 +558,12 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, int rproc_del(struct rproc *rproc); void rproc_free(struct rproc *rproc); +struct rproc_mem_entry * +rproc_mem_entry_init(struct device *dev, + void *va, dma_addr_t dma, int len, u32 da, + int (*release)(struct rproc *, struct rproc_mem_entry *), + const char *name, ...); + int rproc_boot(struct rproc *rproc); void rproc_shutdown(struct rproc *rproc); void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type); From patchwork Fri Jul 27 13:14:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 143052 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp806833ljj; Fri, 27 Jul 2018 06:15:34 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdBQXe7kUYj9Y6yetJqykUELDDksRW0qg8IjKSwW4gx1wGn4w4EM5UGhcBe2zjeYh+SuYBS X-Received: by 2002:a62:930c:: with SMTP id b12-v6mr6587299pfe.193.1532697334837; Fri, 27 Jul 2018 06:15:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532697334; cv=none; d=google.com; s=arc-20160816; b=DYgRn4PZXzb2g692Mqff6i+H8MMohU86D9R1QXF19g3GVIBidlld+ijeDCe+yCzF3i R8Avq3fXKzPaGnFB5jQdEiNvrhA8ZtAcACVgp5e4fG0KgEQxor5fkhaKjWJ1sh8Yp3bz /X/HnoVIeSubs51HsrFzkGlR9zqgUJyYTEQJv5j+0UvaggUTfnuqxeEHnCm59HDwnbcq O/Qhm0JQ9c1OwFLIbJIMY8AMH0uVhD4p5a2XJUi39flyVwZjN8JeEKty83hUUbRKsR0D ONRyX2HIdgQI+E+kQLId9aJfh95gs5KRdKVkh1BNNyn+7gzwUKupyze9S+bgG76LwqVR S4WQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=SU6oL5C41eMdM75R/9RdopIvVstMgU/EmV4oKroYMGk=; b=j/NtywSaXHcGNaMc4ytok9N02DxzSGh4kQbEAZrD2lqgy2bpHaX50oHLvvlUhFUu/F IOorawBk24QkJz66p6b2NqNS1KqaQpqgTyywOGfKCfF/pxCJFehjkF3bcPWOqRX1Ohq2 UMm1UvvVllIRBrSc+ASuWBCElFxxLm2yBgRU8L0CRrjwD2ntfNkjs0ULTyds0l4DNtHH BG3wdn7S/ogJR8SpTVDB35SG/yYQfFLVh6ILikMHe2fXRLf1fOvGcI+5oEZ57RnLu26c z7hZ4m3FQKVoqPA7k3X9W6XsiJbWBnxs6J+TsM8CR4U5iUrsgI9d0RD8+PPLwJC9vH5p On1g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m76-v6si3980007pfg.323.2018.07.27.06.15.34; Fri, 27 Jul 2018 06:15:34 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388651AbeG0OhZ (ORCPT + 31 others); Fri, 27 Jul 2018 10:37:25 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:11802 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388298AbeG0OhY (ORCPT ); Fri, 27 Jul 2018 10:37:24 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w6RDEjsr025001; Fri, 27 Jul 2018 15:15:24 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2kg1up0ns8-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Jul 2018 15:15:24 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 2DA6631; Fri, 27 Jul 2018 13:15:24 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 156EB577A; Fri, 27 Jul 2018 13:15:24 +0000 (GMT) Received: from localhost (10.75.127.50) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Jul 2018 15:15:23 +0200 From: Loic Pallardy To: , CC: , , , , , Loic Pallardy Subject: [PATCH v4 06/17] remoteproc: introduce rproc_add_carveout function Date: Fri, 27 Jul 2018 15:14:41 +0200 Message-ID: <1532697292-14272-7-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> References: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG8NODE3.st.com (10.75.127.24) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-27_06:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch introduces a new API to allow platform driver to register platform specific carveout regions. Signed-off-by: Loic Pallardy Acked-by: Bjorn Andersson --- drivers/remoteproc/remoteproc_core.c | 16 +++++++++++++++- include/linux/remoteproc.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) -- 1.9.1 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index b76760e..fe6c4e4 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -747,7 +747,7 @@ static int rproc_handle_carveout(struct rproc *rproc, if (!carveout) goto free_carv; - list_add_tail(&carveout->node, &rproc->carveouts); + rproc_add_carveout(rproc, carveout); return 0; @@ -761,6 +761,20 @@ static int rproc_handle_carveout(struct rproc *rproc, } /** + * rproc_add_carveout() - register an allocated carveout region + * @rproc: rproc handle + * @mem: memory entry to register + * + * This function registers specified memory entry in @rproc carveouts list. + * Specified carveout should have been allocated before registering. + */ +void rproc_add_carveout(struct rproc *rproc, struct rproc_mem_entry *mem) +{ + list_add_tail(&mem->node, &rproc->carveouts); +} +EXPORT_SYMBOL(rproc_add_carveout); + +/** * rproc_mem_entry_init() - allocate and initialize rproc_mem_entry struct * @dev: pointer on device struct * @va: virtual address diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 4bc961f..55f30fc 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -558,6 +558,8 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, int rproc_del(struct rproc *rproc); void rproc_free(struct rproc *rproc); +void rproc_add_carveout(struct rproc *rproc, struct rproc_mem_entry *mem); + struct rproc_mem_entry * rproc_mem_entry_init(struct device *dev, void *va, dma_addr_t dma, int len, u32 da, From patchwork Fri Jul 27 13:14:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 143063 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp807859ljj; Fri, 27 Jul 2018 06:16:35 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfbdkrbHBp45VIqRpJGbcKPg4ssk9+QEInCB8/aYa2Yhyva0dQxiv8BfsR2kpgkHMHkAKnh X-Received: by 2002:a63:704f:: with SMTP id a15-v6mr6105781pgn.443.1532697395479; Fri, 27 Jul 2018 06:16:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532697395; cv=none; d=google.com; s=arc-20160816; b=jYirkdkta+LTykqxb4bEe+SOlCucdaWZaXvUJP4pR00ybAW6Z9YRcUV7QB10HX29Sx ilq0KaMpolcafhlnffM+TgZvEZo6nPiHwMOMkvGpryVwnf9clAD7IdtYbwquArH2hyq4 pMbASIKbgHexseBySIzwCwAF6gG295cmo2cv4f8j36OK9B6+voVqC+ZXXoxD6uXxd2fP 5FbjnEE0jUimO5nojyd53lXzl3IQiODPG34Hf/0/v5VLmqvUbM+JLHaAueeY2b52Eh7E IlARXDW6+KQP81oqJlImTa9j2MtaGZFSbeoxTRxFlVodCs2xwkKPRbZIW8ov0uvWtKFT fGWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=MSUXWCe7DU2ElRflWW5l/3VZhdQHDGFRLu+FX4fCplk=; b=g/DAyYG9BH6VvQw78O9mF38QHewn6INo4zn4lX4kpd1nWVdTZSihykKAGD8r4UxZxx 5w6MdjOB/X24UhrwGLWpnkq3VvvhDAvuR2qH0EwQMkAdypsDl3mJLjhK7YA8HEPwVp0j JCF0ltFgu84pWFehpWctxl2SV28yplET5fQtYnX6LLzsHRELHZw5Y3KDkymveafNY/SF 7sqFkaql2ukyy2FTDA1jMORvlCm+dJ9Azlwbo0D+bOy6e3xcqi9pMMF+Wso17pRol5/+ 7VG5Ospl5eqNMVBNrs/2KWCC7qr6JgXvExMwoq2b4h9sAHYx5WSBb1izEszgO9avWJaM Y7fQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x23-v6si3964348pgj.543.2018.07.27.06.16.35; Fri, 27 Jul 2018 06:16:35 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388619AbeG0OhZ (ORCPT + 31 others); Fri, 27 Jul 2018 10:37:25 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:39855 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388468AbeG0OhY (ORCPT ); Fri, 27 Jul 2018 10:37:24 -0400 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w6RDE1rD014441; Fri, 27 Jul 2018 15:15:25 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2kg1tj8ptj-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Jul 2018 15:15:25 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 092C531; Fri, 27 Jul 2018 13:15:25 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id E4AA0577A; Fri, 27 Jul 2018 13:15:24 +0000 (GMT) Received: from localhost (10.75.127.50) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Jul 2018 15:15:24 +0200 From: Loic Pallardy To: , CC: , , , , , Loic Pallardy Subject: [PATCH v4 07/17] remoteproc: introduce rproc_find_carveout_by_name function Date: Fri, 27 Jul 2018 15:14:42 +0200 Message-ID: <1532697292-14272-8-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> References: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG7NODE2.st.com (10.75.127.20) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-27_06:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch provides a new function to find a carveout according to a name. If match found, this function returns a pointer on the corresponding carveout (rproc_mem_entry structure). Signed-off-by: Loic Pallardy --- drivers/remoteproc/remoteproc_core.c | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) -- 1.9.1 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index fe6c4e4..77b39ba 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -217,6 +217,48 @@ void *rproc_da_to_va(struct rproc *rproc, u64 da, int len) } EXPORT_SYMBOL(rproc_da_to_va); +/** + * rproc_find_carveout_by_name() - lookup the carveout region by a name + * @rproc: handle of a remote processor + * @name,..: carveout name to find (standard printf format) + * + * Platform driver has the capability to register some pre-allacoted carveout + * (physically contiguous memory regions) before rproc firmware loading and + * associated resource table analysis. These regions may be dedicated memory + * regions internal to the coprocessor or specified DDR region with specific + * attributes + * + * This function is a helper function with which we can go over the + * allocated carveouts and return associated region characteristics like + * coprocessor address, length or processor virtual address. + * + * Return: a valid pointer on carveout entry on success or NULL on failure. + */ +struct rproc_mem_entry * +rproc_find_carveout_by_name(struct rproc *rproc, const char *name, ...) +{ + va_list args; + char _name[32]; + struct rproc_mem_entry *carveout, *mem = NULL; + + if (!name) + return NULL; + + va_start(args, name); + vsnprintf(_name, sizeof(_name), name, args); + va_end(args); + + list_for_each_entry(carveout, &rproc->carveouts, node) { + /* Compare carveout and requested names */ + if (!strcmp(carveout->name, _name)) { + mem = carveout; + break; + } + } + + return mem; +} + int rproc_alloc_vring(struct rproc_vdev *rvdev, int i) { struct rproc *rproc = rvdev->rproc; From patchwork Fri Jul 27 13:14:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 143060 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp807459ljj; Fri, 27 Jul 2018 06:16:11 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe+VyIL1c0HijOPcSHK8mE8Lef2DMp7OlH5oQJJqCiHGdz3Is2zgZ9UtDyN+A+C6SoaC5vb X-Received: by 2002:a63:1c13:: with SMTP id c19-v6mr6212711pgc.332.1532697371740; Fri, 27 Jul 2018 06:16:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532697371; cv=none; d=google.com; s=arc-20160816; b=ETQ+HD+qKxzB2Pjsr7ZB+tDNp8StjxiD2ARTJERaEgal02bN0NulWpSTzFGzRAmmml vE2tlYAnMIOPseO4a444RtV8AN0zQIB+bWV4JEic/HTIDQ5US08UMuTlbp98yR0Mfl7H WfuZELpfs1EPjj9GsnfhhLJkjYJ8e5XYynfTpuUHnXnlk7wOCNPC7rW/cHYroNaP6HHv SnjRvuBb6asHwnpg0OeyxE0DEUJ09qXfWu1LsEnOicV2vFRwxF2o8fj8O+QJL497winn yGwnO6l89+QUO5n1rLlMC7H6p5szYhyKIbp/kOmCzuZD0CrZH7+53uA1w3VbUwKg4OIj rj5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=6FpVYjz0Z4XN6FcluBJRwNYJMo3yzze3i1zzaYQBmz4=; b=Azz+IPCwcolgQSJq8BlMIw/j6z1JARdLALuvYwKpgcmMy16LbsjHM2pxkVgi2OONhh jeXZHHAzsssVgBKakgm8L2aRUgpUW6xY3b/akR7l66uPEqB/PK7/cRI2PUmV2WIgk+D2 zKmrI1R/kjbCs2zxyJwYSlIy7k8zOBTDfZGKIU9JhH81/iRzfwMCOtuyV10nByB+Y8fs rZ3KuLW3aZBYGmDo3Wqnr9E9aIIwOwRbOYAu6Ei4FX9WmYNMlwRZ3H3KbhTt9uWx59ae sguZmiKRXXXjMIPdzhlJU8XdEzMK1gml/jRMGwvDDsqbuFZcampSQStPkcdfR7xnERth o+jw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 69-v6si4275108pft.235.2018.07.27.06.16.11; Fri, 27 Jul 2018 06:16:11 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388868AbeG0OiC (ORCPT + 31 others); Fri, 27 Jul 2018 10:38:02 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:43928 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730706AbeG0Oh2 (ORCPT ); Fri, 27 Jul 2018 10:37:28 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w6RDETgI024981; Fri, 27 Jul 2018 15:15:26 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2kg1up0nsa-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Jul 2018 15:15:26 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 1B40D31; Fri, 27 Jul 2018 13:15:26 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id F138A577A; Fri, 27 Jul 2018 13:15:25 +0000 (GMT) Received: from localhost (10.75.127.49) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Jul 2018 15:15:25 +0200 From: Loic Pallardy To: , CC: , , , , , Loic Pallardy Subject: [PATCH v4 08/17] remoteproc: add alloc ops in rproc_mem_entry struct Date: Fri, 27 Jul 2018 15:14:43 +0200 Message-ID: <1532697292-14272-9-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> References: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.49] X-ClientProxiedBy: SFHDAG4NODE1.st.com (10.75.127.10) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-27_06:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Memory entry could be allocated in different ways (ioremap, dma_alloc_coherent, internal RAM allocator...). This patch introduces an alloc ops in rproc_mem_entry structure to associate dedicated allocation mechanism to each memory entry descriptor in order to do remote core agnostic from memory allocators. The introduction of this ops allows to perform allocation of all registered carveout at the same time, just before calling rproc_start(). It simplifies and makes uniform carveout management whatever origin. Signed-off-by: Loic Pallardy --- drivers/remoteproc/remoteproc_core.c | 261 ++++++++++++++++++++++------------- include/linux/remoteproc.h | 7 + 2 files changed, 175 insertions(+), 93 deletions(-) -- 1.9.1 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 77b39ba..2c51549 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -642,74 +642,31 @@ static int rproc_handle_devmem(struct rproc *rproc, struct fw_rsc_devmem *rsc, } /** - * rproc_release_carveout() - release acquired carveout + * rproc_alloc_carveout() - allocated specified carveout * @rproc: rproc handle - * @mem: the memory entry to release - * - * This function releases specified memory entry @mem allocated via - * dma_alloc_coherent() function by @rproc. - */ -static int rproc_release_carveout(struct rproc *rproc, - struct rproc_mem_entry *mem) -{ - struct device *dev = &rproc->dev; - - /* clean up carveout allocations */ - dma_free_coherent(dev->parent, mem->len, mem->va, mem->dma); - return 0; -} - -/** - * rproc_handle_carveout() - handle phys contig memory allocation requests - * @rproc: rproc handle - * @rsc: the resource entry - * @avail: size of available data (for image validation) - * - * This function will handle firmware requests for allocation of physically - * contiguous memory regions. - * - * These request entries should come first in the firmware's resource table, - * as other firmware entries might request placing other data objects inside - * these memory regions (e.g. data/code segments, trace resource entries, ...). + * @mem: the memory entry to allocate * - * Allocating memory this way helps utilizing the reserved physical memory - * (e.g. CMA) more efficiently, and also minimizes the number of TLB entries - * needed to map it (in case @rproc is using an IOMMU). Reducing the TLB - * pressure is important; it may have a substantial impact on performance. + * This function allocate specified memory entry @mem using + * dma_alloc_coherent() as default allocator */ -static int rproc_handle_carveout(struct rproc *rproc, - struct fw_rsc_carveout *rsc, - int offset, int avail) +static int rproc_alloc_carveout(struct rproc *rproc, + struct rproc_mem_entry *mem) { - struct rproc_mem_entry *carveout, *mapping = NULL; + struct rproc_mem_entry *mapping = NULL; struct device *dev = &rproc->dev; dma_addr_t dma; void *va; int ret; - if (sizeof(*rsc) > avail) { - dev_err(dev, "carveout rsc is truncated\n"); - return -EINVAL; - } - - /* make sure reserved bytes are zeroes */ - if (rsc->reserved) { - dev_err(dev, "carveout rsc has non zero reserved bytes\n"); - return -EINVAL; - } - - dev_dbg(dev, "carveout rsc: name: %s, da 0x%x, pa 0x%x, len 0x%x, flags 0x%x\n", - rsc->name, rsc->da, rsc->pa, rsc->len, rsc->flags); - - va = dma_alloc_coherent(dev->parent, rsc->len, &dma, GFP_KERNEL); + va = dma_alloc_coherent(dev->parent, mem->len, &dma, GFP_KERNEL); if (!va) { dev_err(dev->parent, - "failed to allocate dma memory: len 0x%x\n", rsc->len); + "failed to allocate dma memory: len 0x%x\n", mem->len); return -ENOMEM; } dev_dbg(dev, "carveout va %pK, dma %pad, len 0x%x\n", - va, &dma, rsc->len); + va, &dma, mem->len); /* * Ok, this is non-standard. @@ -729,22 +686,22 @@ static int rproc_handle_carveout(struct rproc *rproc, * physical address in this case. */ - if (rsc->da != FW_RSC_ADDR_ANY && !rproc->domain) { - dev_err(dev->parent, - "Bad carveout rsc configuration\n"); - ret = -ENOMEM; - goto dma_free; - } + if (mem->da != FW_RSC_ADDR_ANY) { + if (!rproc->domain) { + dev_err(dev->parent, + "Bad carveout rsc configuration\n"); + ret = -ENOMEM; + goto dma_free; + } - if (rsc->da != FW_RSC_ADDR_ANY && rproc->domain) { mapping = kzalloc(sizeof(*mapping), GFP_KERNEL); if (!mapping) { ret = -ENOMEM; goto dma_free; } - ret = iommu_map(rproc->domain, rsc->da, dma, rsc->len, - rsc->flags); + ret = iommu_map(rproc->domain, mem->da, dma, mem->len, + mem->flags); if (ret) { dev_err(dev, "iommu_map failed: %d\n", ret); goto free_mapping; @@ -757,52 +714,102 @@ static int rproc_handle_carveout(struct rproc *rproc, * We can't trust the remote processor not to change the * resource table, so we must maintain this info independently. */ - mapping->da = rsc->da; - mapping->len = rsc->len; + mapping->da = mem->da; + mapping->len = mem->len; list_add_tail(&mapping->node, &rproc->mappings); dev_dbg(dev, "carveout mapped 0x%x to %pad\n", - rsc->da, &dma); + mem->da, &dma); + } else { + mem->da = (u32)dma; } - /* - * Some remote processors might need to know the pa - * even though they are behind an IOMMU. E.g., OMAP4's - * remote M3 processor needs this so it can control - * on-chip hardware accelerators that are not behind - * the IOMMU, and therefor must know the pa. - * - * Generally we don't want to expose physical addresses - * if we don't have to (remote processors are generally - * _not_ trusted), so we might want to do this only for - * remote processor that _must_ have this (e.g. OMAP4's - * dual M3 subsystem). - * - * Non-IOMMU processors might also want to have this info. - * In this case, the device address and the physical address - * are the same. - */ - rsc->pa = (u32)rproc_va_to_pa(va); - - carveout = rproc_mem_entry_init(dev, va, dma, rsc->len, rsc->da, - rproc_release_carveout, rsc->name); - if (!carveout) - goto free_carv; - - rproc_add_carveout(rproc, carveout); + mem->dma = (u32)dma; + mem->va = va; return 0; -free_carv: - kfree(carveout); free_mapping: kfree(mapping); dma_free: - dma_free_coherent(dev->parent, rsc->len, va, dma); + dma_free_coherent(dev->parent, mem->len, va, dma); return ret; } /** + * rproc_release_carveout() - release acquired carveout + * @rproc: rproc handle + * @mem: the memory entry to release + * + * This function releases specified memory entry @mem allocated via + * rproc_alloc_carveout() function by @rproc. + */ +static int rproc_release_carveout(struct rproc *rproc, + struct rproc_mem_entry *mem) +{ + struct device *dev = &rproc->dev; + + /* clean up carveout allocations */ + dma_free_coherent(dev->parent, mem->len, mem->va, mem->dma); + return 0; +} + +/** + * rproc_handle_carveout() - handle phys contig memory allocation requests + * @rproc: rproc handle + * @rsc: the resource entry + * @avail: size of available data (for image validation) + * + * This function will handle firmware requests for allocation of physically + * contiguous memory regions. + * + * These request entries should come first in the firmware's resource table, + * as other firmware entries might request placing other data objects inside + * these memory regions (e.g. data/code segments, trace resource entries, ...). + * + * Allocating memory this way helps utilizing the reserved physical memory + * (e.g. CMA) more efficiently, and also minimizes the number of TLB entries + * needed to map it (in case @rproc is using an IOMMU). Reducing the TLB + * pressure is important; it may have a substantial impact on performance. + */ +static int rproc_handle_carveout(struct rproc *rproc, + struct fw_rsc_carveout *rsc, + int offset, int avail) +{ + struct rproc_mem_entry *carveout; + struct device *dev = &rproc->dev; + + if (sizeof(*rsc) > avail) { + dev_err(dev, "carveout rsc is truncated\n"); + return -EINVAL; + } + + /* make sure reserved bytes are zeroes */ + if (rsc->reserved) { + dev_err(dev, "carveout rsc has non zero reserved bytes\n"); + return -EINVAL; + } + + dev_dbg(dev, "carveout rsc: name: %s, da 0x%x, pa 0x%x, len 0x%x, flags 0x%x\n", + rsc->name, rsc->da, rsc->pa, rsc->len, rsc->flags); + + /* Register carveout in in list */ + carveout = rproc_mem_entry_init(dev, 0, 0, rsc->len, rsc->da, + rproc_alloc_carveout, + rproc_release_carveout, rsc->name); + if (!carveout) { + dev_err(dev, "Can't allocate memory entry structure\n"); + return -ENOMEM; + } + + carveout->flags = rsc->flags; + carveout->rsc_offset = offset; + rproc_add_carveout(rproc, carveout); + + return 0; +} + +/** * rproc_add_carveout() - register an allocated carveout region * @rproc: rproc handle * @mem: memory entry to register @@ -832,6 +839,7 @@ void rproc_add_carveout(struct rproc *rproc, struct rproc_mem_entry *mem) struct rproc_mem_entry * rproc_mem_entry_init(struct device *dev, void *va, dma_addr_t dma, int len, u32 da, + int (*alloc)(struct rproc *, struct rproc_mem_entry *), int (*release)(struct rproc *, struct rproc_mem_entry *), const char *name, ...) { @@ -846,7 +854,9 @@ struct rproc_mem_entry * mem->dma = dma; mem->da = da; mem->len = len; + mem->alloc = alloc; mem->release = release; + mem->rsc_offset = FW_RSC_ADDR_ANY; va_start(args, name); vsnprintf(mem->name, sizeof(mem->name), name, args); @@ -978,6 +988,63 @@ static void rproc_unprepare_subdevices(struct rproc *rproc) } /** + * rproc_alloc_registered_carveouts() - allocate all carveouts registered + * in the list + * @rproc: the remote processor handle + * + * This function parses registered carveout list, performs allocation + * if alloc() ops registered and updates resource table information + * if rsc_offset set. + * + * Return: 0 on success + */ +static int rproc_alloc_registered_carveouts(struct rproc *rproc) +{ + struct rproc_mem_entry *entry, *tmp; + struct fw_rsc_carveout *rsc; + struct device *dev = &rproc->dev; + int ret; + + list_for_each_entry_safe(entry, tmp, &rproc->carveouts, node) { + if (entry->alloc) { + ret = entry->alloc(rproc, entry); + if (ret) { + dev_err(dev, "Unable to allocate carveout %s: %d\n", + entry->name, ret); + return -ENOMEM; + } + } + + if (entry->rsc_offset != FW_RSC_ADDR_ANY) { + /* update resource table */ + rsc = (void *)rproc->table_ptr + entry->rsc_offset; + + /* + * Some remote processors might need to know the pa + * even though they are behind an IOMMU. E.g., OMAP4's + * remote M3 processor needs this so it can control + * on-chip hardware accelerators that are not behind + * the IOMMU, and therefor must know the pa. + * + * Generally we don't want to expose physical addresses + * if we don't have to (remote processors are generally + * _not_ trusted), so we might want to do this only for + * remote processor that _must_ have this (e.g. OMAP4's + * dual M3 subsystem). + * + * Non-IOMMU processors might also want to have this info. + * In this case, the device address and the physical address + * are the same. + */ + if (entry->va) + rsc->pa = (u32)rproc_va_to_pa(entry->va); + } + } + + return 0; +} + +/** * rproc_coredump_cleanup() - clean up dump_segments list * @rproc: the remote processor handle */ @@ -1148,6 +1215,14 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) goto clean_up_resources; } + /* Allocate carveout resources associated to rproc */ + ret = rproc_alloc_registered_carveouts(rproc); + if (ret) { + dev_err(dev, "Failed to allocate associated carveouts: %d\n", + ret); + goto clean_up_resources; + } + ret = rproc_start(rproc, fw); if (ret) goto clean_up_resources; diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 55f30fc..ea95b04 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -317,6 +317,9 @@ struct fw_rsc_vdev { * @priv: associated data * @name: associated memory region name (optional) * @node: list node + * @rsc_offset: offset in resource table + * @flags: iommu protection flags + * @alloc: specific memory allocator function */ struct rproc_mem_entry { void *va; @@ -326,6 +329,9 @@ struct rproc_mem_entry { void *priv; char name[32]; struct list_head node; + u32 rsc_offset; + u32 flags; + int (*alloc)(struct rproc *rproc, struct rproc_mem_entry *mem); int (*release)(struct rproc *rproc, struct rproc_mem_entry *mem); }; @@ -563,6 +569,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, struct rproc_mem_entry * rproc_mem_entry_init(struct device *dev, void *va, dma_addr_t dma, int len, u32 da, + int (*alloc)(struct rproc *, struct rproc_mem_entry *), int (*release)(struct rproc *, struct rproc_mem_entry *), const char *name, ...); From patchwork Fri Jul 27 13:14:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 143053 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp806860ljj; Fri, 27 Jul 2018 06:15:36 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdcQdjtdaqjkMS40emHaTlGgejME8QuT5kVko7BTuZ/JwGvIHLSxPA0luICqyTPx6okcKvI X-Received: by 2002:a63:3f05:: with SMTP id m5-v6mr6052580pga.51.1532697336408; Fri, 27 Jul 2018 06:15:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532697336; cv=none; d=google.com; s=arc-20160816; b=EelwONF4y+LWkrYGYRRXhNYadbUM5n1otEJ1jcFdrSDVdtmoVOvsa8E7dm8zA9lJNU yRx5V7nccQLi/9Wi+2kOAql1P3GsvrutEqdXMBMuzyp+FQ2mQx0tW+WDjFWAQcFOOb9M dk5WBsf2ZCLKDbtmfyTBMopLo44ohsRygF3HgGDN/dR1aSi+S0iyTTVoUe/XYtLnw0kd +9dAjrMBxQFVMY7jjsLJbCCeWrwRju/AvRGViyJHKo7SsOaiH9z7eNJm8A16OicRYNaJ +CZGY2OivOuVuq5LRrDOqMObz+OiyDAUIQDY3n8rc5YqPWxJwhqe/9c46W3je6lGjjL2 /AtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=L5zCVhRUKKQ7fmLYZpB2xE7K4yGvjeygGTO1OkPy+Bg=; b=B/vbSRmPWRHBgV73ySqRDbSNgBOgiphXQGWIpsZvcJ9tbm8kqm8J0YxhovFKlB37NP nEHxZCGQ6B8RAeJNk1U0nUMoF85543YLtrRCkAw0BMhloYm6aVa8y+R3MN3wLA6far0N 60nILBj16BTZVR3LtN4L9MC//zvyBR+6NSRmKAH8tXli32ZazprQxmqIq4qUMehZUVXI qb2EcQhXwvIcmIGnM2xa3RwgotAO3/02Pf0xAFMgOZBAQ2IGedMMghvyKt4WsnxuqdvR rd6iSH00MCoiPvuywBA51WqSX3Q+nESl3+DH+Tr9suPXXK7IqAoTWGzE0HJbMm7HTh6X xEIA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p1-v6si4137818pfp.237.2018.07.27.06.15.36; Fri, 27 Jul 2018 06:15:36 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388678AbeG0Oh0 (ORCPT + 31 others); Fri, 27 Jul 2018 10:37:26 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:25781 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732124AbeG0Oh0 (ORCPT ); Fri, 27 Jul 2018 10:37:26 -0400 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w6RDEJ0x016198; Fri, 27 Jul 2018 15:15:27 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2kg26xrjvt-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Jul 2018 15:15:27 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 2C30531; Fri, 27 Jul 2018 13:15:27 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 0C7C5577E; Fri, 27 Jul 2018 13:15:27 +0000 (GMT) Received: from localhost (10.75.127.48) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Jul 2018 15:15:26 +0200 From: Loic Pallardy To: , CC: , , , , , Loic Pallardy Subject: [PATCH v4 09/17] remoteproc: add helper function to allocate rproc_mem_entry from reserved memory Date: Fri, 27 Jul 2018 15:14:44 +0200 Message-ID: <1532697292-14272-10-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> References: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.48] X-ClientProxiedBy: SFHDAG2NODE3.st.com (10.75.127.6) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-27_06:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch introduces rproc_res_mem_entry_init() helper function to allocate a rproc_mem_entry structure from a reserved memory region. In that case, rproc_mem_entry structure has no alloc and release ops. It will be used to assigned the specified reserved memory to any rproc sub device. Relation between rproc_mem_entry and rproc sub device will be done by name. Signed-off-by: Loic Pallardy --- drivers/remoteproc/remoteproc_core.c | 37 ++++++++++++++++++++++++++++++++++++ include/linux/remoteproc.h | 6 ++++++ 2 files changed, 43 insertions(+) -- 1.9.1 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 2c51549..1e0fe3e 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -857,6 +857,7 @@ struct rproc_mem_entry * mem->alloc = alloc; mem->release = release; mem->rsc_offset = FW_RSC_ADDR_ANY; + mem->of_resm_idx = -1; va_start(args, name); vsnprintf(mem->name, sizeof(mem->name), name, args); @@ -867,6 +868,42 @@ struct rproc_mem_entry * EXPORT_SYMBOL(rproc_mem_entry_init); /** + * rproc_of_resm_mem_entry_init() - allocate and initialize rproc_mem_entry struct + * from a reserved memory phandle + * @dev: pointer on device struct + * @of_resm_idx: reserved memory phandle index in "memory-region" + * @len: memory carveout length + * @da: device address + * @name: carveout name + * + * This function allocates a rproc_mem_entry struct and fill it with parameters + * provided by client. + */ +struct rproc_mem_entry * +rproc_of_resm_mem_entry_init(struct device *dev, u32 of_resm_idx, int len, + u32 da, const char *name, ...) +{ + struct rproc_mem_entry *mem; + va_list args; + + mem = kzalloc(sizeof(*mem), GFP_KERNEL); + if (!mem) + return mem; + + mem->da = da; + mem->len = len; + mem->rsc_offset = FW_RSC_ADDR_ANY; + mem->of_resm_idx = of_resm_idx; + + va_start(args, name); + vsnprintf(mem->name, sizeof(mem->name), name, args); + va_end(args); + + return mem; +} +EXPORT_SYMBOL(rproc_of_resm_mem_entry_init); + +/** * A lookup table for resource handlers. The indices are defined in * enum fw_resource_type. */ diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index ea95b04..4cdd0c6 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -319,6 +319,7 @@ struct fw_rsc_vdev { * @node: list node * @rsc_offset: offset in resource table * @flags: iommu protection flags + * @of_resm_idx: reserved memory phandle index * @alloc: specific memory allocator function */ struct rproc_mem_entry { @@ -331,6 +332,7 @@ struct rproc_mem_entry { struct list_head node; u32 rsc_offset; u32 flags; + u32 of_resm_idx; int (*alloc)(struct rproc *rproc, struct rproc_mem_entry *mem); int (*release)(struct rproc *rproc, struct rproc_mem_entry *mem); }; @@ -573,6 +575,10 @@ struct rproc_mem_entry * int (*release)(struct rproc *, struct rproc_mem_entry *), const char *name, ...); +struct rproc_mem_entry * +rproc_of_resm_mem_entry_init(struct device *dev, u32 of_resm_idx, int len, + u32 da, const char *name, ...); + int rproc_boot(struct rproc *rproc); void rproc_shutdown(struct rproc *rproc); void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type); From patchwork Fri Jul 27 13:14:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 143061 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp807614ljj; Fri, 27 Jul 2018 06:16:20 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf+XKf1R4jDeZp689Vm0QC9jkFo0AeOUzi87/thnMLoCpiNwArjO5020FcXWQlpTjeQ7AEv X-Received: by 2002:a63:bf08:: with SMTP id v8-v6mr5992219pgf.3.1532697380842; Fri, 27 Jul 2018 06:16:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532697380; cv=none; d=google.com; s=arc-20160816; b=0t3du6U8YwpfuJz5GmOdHUYJsR9iHP8jsDzlnkzucAiGjud2TznQnotnTjgWeGU1c5 4XnOdMU+orINLHsSaJl+Ru/YRsSa3XBxebosTHa5uCC9k6Ny7boj+00hXcFLAn83qVcZ cXJfAm5pbtea3+6SNw8vcbd00pU33HwWjKLOtCqJnDYtniR8CcmSrRWAiBNY8szrhCpa H8JC0ia3oKHDRzK+xoxjJSaI373HFfL0i3ov9KSFl+pr7IXcgNzAqeJktvlo5q0Qmdyt RoupRugL53I1FzOBlYH9HDPOVyu5HZ5YK/xiDOnXg8xXWTst2T7ZhZQ7bfSZTsueoOaf q2LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=etiXzHOo9EfgiVfySm9CH2I3ht+bul2Bej4z4g2ADA0=; b=BlqyVSnu09pdOVvtWU43MtR+4w2mct1Uv9/xEb/dFyWbUhVHsBO7FoDFQwhIf7UoZE KwRFRP5vokQBgR/UjdvJVKyGCQuDs2t7+dnC49n3vlkyUagbmrFrev7OimNNhpsbQjSd HbC23ifK+hWGC/cLFCztReeipgC3HVLATDks45FxFHMyslYnvvx/256BzEfMWmxF/sdN 7rT3Gxwqyrg39zDBlOrImNOTJ1JSmmuPNEQOVhfWaZGtGklnndr5Avm7FYyMDnsGWPUy aDnLX2wTuv7P7I9S0YP8AP4xx/qccqgsMkKiDjlXTnXE4jlC11oe6gxxfcddpSn6r+jW uGCA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e98-v6si3665119plb.150.2018.07.27.06.16.20; Fri, 27 Jul 2018 06:16:20 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388909AbeG0OiM (ORCPT + 31 others); Fri, 27 Jul 2018 10:38:12 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:10721 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388585AbeG0OhZ (ORCPT ); Fri, 27 Jul 2018 10:37:25 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w6RDESkq024978; Fri, 27 Jul 2018 15:15:28 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2kg1up0nsm-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Jul 2018 15:15:28 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id EECF238; Fri, 27 Jul 2018 13:15:27 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id D4B21577A; Fri, 27 Jul 2018 13:15:27 +0000 (GMT) Received: from localhost (10.75.127.48) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Jul 2018 15:15:27 +0200 From: Loic Pallardy To: , CC: , , , , , Loic Pallardy Subject: [PATCH v4 10/17] remoteproc: add helper function to check carveout device address Date: Fri, 27 Jul 2018 15:14:45 +0200 Message-ID: <1532697292-14272-11-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> References: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.48] X-ClientProxiedBy: SFHDAG8NODE1.st.com (10.75.127.22) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-27_06:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch introduces a function to verify that a specified carveout is fitting request device address and associated length Signed-off-by: Loic Pallardy --- drivers/remoteproc/remoteproc_core.c | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) -- 1.9.1 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 1e0fe3e..5dd5edf 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -259,6 +259,53 @@ struct rproc_mem_entry * return mem; } +/** + * rproc_check_carveout_da() - Check specified carveout da configuration + * @rproc: handle of a remote processor + * @mem: pointer on carveout to check + * @da: area device address + * @len: associated area size + * + * This function is a helper function to verify requested device area (couple + * da, len) is part of specified carevout. + * + * Return: 0 if carveout matchs request else -ENOMEM + */ +int rproc_check_carveout_da(struct rproc *rproc, struct rproc_mem_entry *mem, + u32 da, u32 len) +{ + struct device *dev = &rproc->dev; + int delta = 0; + + /* Check requested resource length */ + if (len > mem->len) { + dev_err(dev, "Registered carveout doesn't fit len request\n"); + return -ENOMEM; + } + + if (da != FW_RSC_ADDR_ANY && mem->da == FW_RSC_ADDR_ANY) { + /* Update existing carveout da */ + mem->da = da; + } else if (da != FW_RSC_ADDR_ANY && mem->da != FW_RSC_ADDR_ANY) { + delta = da - mem->da; + + /* Check requested resource belongs to registered carveout */ + if (delta < 0) { + dev_err(dev, + "Registered carveout doesn't fit da request\n"); + return -ENOMEM; + } + + if (delta + len > mem->len) { + dev_err(dev, + "Registered carveout doesn't fit len request\n"); + return -ENOMEM; + } + } + + return 0; +} + int rproc_alloc_vring(struct rproc_vdev *rvdev, int i) { struct rproc *rproc = rvdev->rproc; From patchwork Fri Jul 27 13:14:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 143062 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp807701ljj; Fri, 27 Jul 2018 06:16:26 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc0qx/0PGlFnk5m0pL5cusFektlZzLQRqwiEEB4k1qV4/gPj5Nu5o26IlzrL71EgfKWgDg6 X-Received: by 2002:a63:f206:: with SMTP id v6-v6mr6071178pgh.319.1532697386390; Fri, 27 Jul 2018 06:16:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532697386; cv=none; d=google.com; s=arc-20160816; b=yrgDp6+8Cin+Q5bK0MstOtQnSvzDKsAUAC1nlvXTnb8wRIVbq4iyouTdKwVrYr2qAh CIbfKkvIDrrpdyhtW4d4Wn2ebgFCULsvrCSZEZrtXd+jglsT6tVsn038T/p8e9pgcmJU k/6m5NLhCM90sQ+4/xYgRvLe+LzZJWQeRQFsZh+0qHkGaEDOk0jD6ICHKl3NGXlrNl0N v+3suEuyK7Lft+kckpn2IoNEWY6G9jMTxHz0J9H18SndlANtj9SLO0mUnKKATlleQmMb vMKYuA7ft6WmdyNaS8idJ3FCoPe6S0pVD9QwAwIeX+Confjvl71pVfe09TYmH8Svnwqz BLeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=NL32liJace6XLmVtTt1gqTLNcIC3JsCfnfjVXqQKTYM=; b=a+FnyssIgtDqjvNYOxyZ7Kd/fhgBIS7TjXn8F8Cfz0ZacQjjtKiIRKRNKl38KHWOiV j/kX+S4wke0KqwBxfOa5kHRbwYfqSxCIkszZJjp8SVl8eqQypx/6KgVG5R7tPg67Tz+0 hkVh56/Gk3np7T5othWVpIfLmPDvz7pus7QPPUo5k4pI1hgE6duL2OKMLdAMmMPOXm/P d5JjrNyoanvasdKOJxn+cKkFHQPF2hiIgs0VxLKLep2mww0T3zle95rn07fFvyr0+FRl Ou5OWT9zAvVsgpWXu20XDooCPdsYmUhWEC7CS/uMJtRn25I9liO4U6fPzzk7N9H1IeEH GXkw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c13-v6si3913944pgh.627.2018.07.27.06.16.26; Fri, 27 Jul 2018 06:16:26 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388886AbeG0OiL (ORCPT + 31 others); Fri, 27 Jul 2018 10:38:11 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:39860 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388587AbeG0Oh0 (ORCPT ); Fri, 27 Jul 2018 10:37:26 -0400 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w6RDE4if014486; Fri, 27 Jul 2018 15:15:29 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2kg1tj8pu4-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Jul 2018 15:15:29 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 054C431; Fri, 27 Jul 2018 13:15:29 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id DDBD5577A; Fri, 27 Jul 2018 13:15:28 +0000 (GMT) Received: from localhost (10.75.127.49) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Jul 2018 15:15:28 +0200 From: Loic Pallardy To: , CC: , , , , , Loic Pallardy Subject: [PATCH v4 11/17] remoteproc: modify rproc_handle_carveout to support pre-registered region Date: Fri, 27 Jul 2018 15:14:46 +0200 Message-ID: <1532697292-14272-12-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> References: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.49] X-ClientProxiedBy: SFHDAG5NODE2.st.com (10.75.127.14) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-27_06:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In current version rproc_handle_carveout() function registers carveout for allocation. This patch extends rproc_handle_carveout() function to support pre-registered region. Match is done on region name, then requested device address and length are checked. If match found, pre-registered region is associated with resource table request. If no name match found, new carveout is registered for allocation. Signed-off-by: Loic Pallardy --- drivers/remoteproc/remoteproc_core.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) -- 1.9.1 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 5dd5edf..c543d04 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -840,6 +840,29 @@ static int rproc_handle_carveout(struct rproc *rproc, dev_dbg(dev, "carveout rsc: name: %s, da 0x%x, pa 0x%x, len 0x%x, flags 0x%x\n", rsc->name, rsc->da, rsc->pa, rsc->len, rsc->flags); + /* + * Check carveout rsc already part of a registered carveout, + * Search by name, then check the da and length + */ + carveout = rproc_find_carveout_by_name(rproc, rsc->name); + + if (carveout) { + if (carveout->rsc_offset != FW_RSC_ADDR_ANY) { + dev_err(dev, + "Carveout already associated to resource table\n"); + return -ENOMEM; + } + + if (rproc_check_carveout_da(rproc, carveout, rsc->da, rsc->len)) + return -ENOMEM; + + /* Update memory carveout with resource table info */ + carveout->rsc_offset = offset; + carveout->flags = rsc->flags; + + return 0; + } + /* Register carveout in in list */ carveout = rproc_mem_entry_init(dev, 0, 0, rsc->len, rsc->da, rproc_alloc_carveout, @@ -1120,8 +1143,15 @@ static int rproc_alloc_registered_carveouts(struct rproc *rproc) * In this case, the device address and the physical address * are the same. */ + + /* Use va if defined else dma to generate pa */ if (entry->va) rsc->pa = (u32)rproc_va_to_pa(entry->va); + else + rsc->pa = (u32)entry->dma; + + rsc->da = entry->da; + rsc->len = entry->len; } } From patchwork Fri Jul 27 13:14:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 143054 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp806889ljj; Fri, 27 Jul 2018 06:15:38 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdvgNJQC8RV8+3S48ATg08rWuAr7G1O+4pK862doMEtaSR+SLhHNOSFHVQ9vrp+LIvhtNOw X-Received: by 2002:a63:b256:: with SMTP id t22-v6mr6277486pgo.101.1532697338338; Fri, 27 Jul 2018 06:15:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532697338; cv=none; d=google.com; s=arc-20160816; b=jrozzySPfXaOKSKbgHjGnOjDrP3e36HMEMVFuUJNM/fP90IkF6qsI4LcUaf0sPTkxI ZX//1mPPPqPPKzqXM3jPp9MJ2lx94VNZ4FncIONjOrRjk6Lhh12lZOCBVOSlmAnuAoBX 7HYJtbGQSyb2Wt5xCvlrcPd65aixT4KymTZRh4IRar/BVHFIYJ5yQR+/eh6RM4sOne8G Mlp7U4Fiq//0vcZTWVhHwPXf902QTsDN2cRLLNzcQkQFN9CkNUo5VwTkVhjV3XsYw1tk f3tow+gFUmGvBL8pR9/QztOBLW80lT+6nYJYD54zNO+nib40DXreIzR6o7hp092K11cY cmMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=mryNBanbhdKJvFFPgGoaOnsw9i8bZDaXVeUxWioc0dU=; b=hpyMDM3AJhvd/8ToILKsO2LsPcH/A5mY+yb7eWT4A9DTLhVBFtob36kVOaBDdpD+4Q oEIpMvRnJjFKsJtZFAcFfu9w66rbw/PC/rtoKpziwUZuEHX/dzl0E6arGiecYHfiDmCS UKPT1y/oLauWRMirR0MUVE7+1njCEgmnS1IECmUd63Imuu3+kdzPWnmi/IACrIGjjlNr oYbQtuHlyebNQIi4c4+DzRJ20aReMx9N088qYTXg91t8inRDyKX+RtVbH+SiumGk3Jxl 9zFukvXwrxKK6kiblxoPcDH0E75saV7I5PnZMmWKHXkm8a1ckllScEceRHvvdqOoTpId zLvg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x25-v6si4172436pfi.138.2018.07.27.06.15.37; Fri, 27 Jul 2018 06:15:38 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388745AbeG0Oh3 (ORCPT + 31 others); Fri, 27 Jul 2018 10:37:29 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:14997 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388298AbeG0Oh2 (ORCPT ); Fri, 27 Jul 2018 10:37:28 -0400 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w6RDEJ10016198; Fri, 27 Jul 2018 15:15:31 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2kg26xrjw3-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Jul 2018 15:15:31 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 2757F31; Fri, 27 Jul 2018 13:15:30 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 04A96577A; Fri, 27 Jul 2018 13:15:30 +0000 (GMT) Received: from localhost (10.75.127.51) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Jul 2018 15:15:29 +0200 From: Loic Pallardy To: , CC: , , , , , Loic Pallardy Subject: [PATCH v4 12/17] remoteproc: modify vring allocation to rely on centralized carveout allocator Date: Fri, 27 Jul 2018 15:14:47 +0200 Message-ID: <1532697292-14272-13-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> References: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.51] X-ClientProxiedBy: SFHDAG7NODE2.st.com (10.75.127.20) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-27_06:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Current version of rproc_alloc_vring function supports only dynamic vring allocation. This patch allows to allocate vrings based on memory region declatation. Vrings are now manage like memory carveouts, to communize memory management code in rproc_alloc_registered_carveouts(). Allocated buffer is retrieved in rp_find_vq() thanks to rproc_find_carveout_by_name() functions for. This patch sets vrings names to vdev"x"vring"y" with x vdev index in resource table and y vring index in vdev. This will be updated when name will be associated to vdev in firmware resource table. Signed-off-by: Loic Pallardy --- drivers/remoteproc/remoteproc_core.c | 61 +++++++++++++++++--------------- drivers/remoteproc/remoteproc_internal.h | 2 ++ drivers/remoteproc/remoteproc_virtio.c | 14 +++++++- include/linux/remoteproc.h | 6 ++-- 4 files changed, 51 insertions(+), 32 deletions(-) -- 1.9.1 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index c543d04..4edc6f0 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -53,6 +53,11 @@ typedef int (*rproc_handle_resources_t)(struct rproc *rproc, typedef int (*rproc_handle_resource_t)(struct rproc *rproc, void *, int offset, int avail); +static int rproc_alloc_carveout(struct rproc *rproc, + struct rproc_mem_entry *mem); +static int rproc_release_carveout(struct rproc *rproc, + struct rproc_mem_entry *mem); + /* Unique indices for remoteproc devices */ static DEFINE_IDA(rproc_dev_index); @@ -312,21 +317,33 @@ int rproc_alloc_vring(struct rproc_vdev *rvdev, int i) struct device *dev = &rproc->dev; struct rproc_vring *rvring = &rvdev->vring[i]; struct fw_rsc_vdev *rsc; - dma_addr_t dma; - void *va; int ret, size, notifyid; + struct rproc_mem_entry *mem; /* actual size of vring (in bytes) */ size = PAGE_ALIGN(vring_size(rvring->len, rvring->align)); - /* - * Allocate non-cacheable memory for the vring. In the future - * this call will also configure the IOMMU for us - */ - va = dma_alloc_coherent(dev->parent, size, &dma, GFP_KERNEL); - if (!va) { - dev_err(dev->parent, "dma_alloc_coherent failed\n"); - return -EINVAL; + rsc = (void *)rproc->table_ptr + rvdev->rsc_offset; + + /* Search for pre-registered carveout */ + mem = rproc_find_carveout_by_name(rproc, "vdev%dvring%d", rvdev->index, + i); + if (mem) { + if (rproc_check_carveout_da(rproc, mem, rsc->vring[i].da, size)) + return -ENOMEM; + } else { + /* Register carveout in in list */ + mem = rproc_mem_entry_init(dev, 0, 0, size, rsc->vring[i].da, + rproc_alloc_carveout, + rproc_release_carveout, + "vdev%dvring%d", + rvdev->index, i); + if (!mem) { + dev_err(dev, "Can't allocate memory entry structure\n"); + return -ENOMEM; + } + + rproc_add_carveout(rproc, mem); } /* @@ -337,7 +354,6 @@ int rproc_alloc_vring(struct rproc_vdev *rvdev, int i) ret = idr_alloc(&rproc->notifyids, rvring, 0, 0, GFP_KERNEL); if (ret < 0) { dev_err(dev, "idr_alloc failed: %d\n", ret); - dma_free_coherent(dev->parent, size, va, dma); return ret; } notifyid = ret; @@ -346,21 +362,9 @@ int rproc_alloc_vring(struct rproc_vdev *rvdev, int i) if (notifyid > rproc->max_notifyid) rproc->max_notifyid = notifyid; - dev_dbg(dev, "vring%d: va %pK dma %pad size 0x%x idr %d\n", - i, va, &dma, size, notifyid); - - rvring->va = va; - rvring->dma = dma; rvring->notifyid = notifyid; - /* - * Let the rproc know the notifyid and da of this vring. - * Not all platforms use dma_alloc_coherent to automatically - * set up the iommu. In this case the device address (da) will - * hold the physical address and not the device address. - */ - rsc = (void *)rproc->table_ptr + rvdev->rsc_offset; - rsc->vring[i].da = dma; + /* Let the rproc know the notifyid of this vring.*/ rsc->vring[i].notifyid = notifyid; return 0; } @@ -392,12 +396,10 @@ int rproc_alloc_vring(struct rproc_vdev *rvdev, int i) void rproc_free_vring(struct rproc_vring *rvring) { - int size = PAGE_ALIGN(vring_size(rvring->len, rvring->align)); struct rproc *rproc = rvring->rvdev->rproc; int idx = rvring->rvdev->vring - rvring; struct fw_rsc_vdev *rsc; - dma_free_coherent(rproc->dev.parent, size, rvring->va, rvring->dma); idr_remove(&rproc->notifyids, rvring->notifyid); /* reset resource entry info */ @@ -484,6 +486,7 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc, rvdev->id = rsc->id; rvdev->rproc = rproc; + rvdev->index = rproc->nb_vdev++; /* parse the vrings */ for (i = 0; i < rsc->num_of_vrings; i++) { @@ -528,9 +531,6 @@ void rproc_vdev_release(struct kref *ref) for (id = 0; id < ARRAY_SIZE(rvdev->vring); id++) { rvring = &rvdev->vring[id]; - if (!rvring->va) - continue; - rproc_free_vring(rvring); } @@ -1322,6 +1322,9 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) /* reset max_notifyid */ rproc->max_notifyid = -1; + /* reset handled vdev */ + rproc->nb_vdev = 0; + /* handle fw resources which are required to boot rproc */ ret = rproc_handle_resources(rproc, rproc_loading_handlers); if (ret) { diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h index 7570beb..f6cad24 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h @@ -60,6 +60,8 @@ struct dentry *rproc_create_trace_file(const char *name, struct rproc *rproc, int rproc_elf_load_rsc_table(struct rproc *rproc, const struct firmware *fw); struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc, const struct firmware *fw); +struct rproc_mem_entry * +rproc_find_carveout_by_name(struct rproc *rproc, const char *name, ...); static inline int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw) diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c index bbecd44..de21f62 100644 --- a/drivers/remoteproc/remoteproc_virtio.c +++ b/drivers/remoteproc/remoteproc_virtio.c @@ -76,7 +76,9 @@ static struct virtqueue *rp_find_vq(struct virtio_device *vdev, struct rproc_vdev *rvdev = vdev_to_rvdev(vdev); struct rproc *rproc = vdev_to_rproc(vdev); struct device *dev = &rproc->dev; + struct rproc_mem_entry *mem; struct rproc_vring *rvring; + struct fw_rsc_vdev *rsc; struct virtqueue *vq; void *addr; int len, size; @@ -88,8 +90,14 @@ static struct virtqueue *rp_find_vq(struct virtio_device *vdev, if (!name) return NULL; + /* Search allocated memory region by name */ + mem = rproc_find_carveout_by_name(rproc, "vdev%dvring%d", rvdev->index, + id); + if (!mem || !mem->va) + return ERR_PTR(-ENOMEM); + rvring = &rvdev->vring[id]; - addr = rvring->va; + addr = mem->va; len = rvring->len; /* zero vring */ @@ -114,6 +122,10 @@ static struct virtqueue *rp_find_vq(struct virtio_device *vdev, rvring->vq = vq; vq->priv = rvring; + /* Update vring in resource table */ + rsc = (void *)rproc->table_ptr + rvdev->rsc_offset; + rsc->vring[id].da = mem->da; + return vq; } diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 4cdd0c6..6b3a234 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -453,6 +453,7 @@ struct rproc_dump_segment { * @table_sz: size of @cached_table * @has_iommu: flag to indicate if remote processor is behind an MMU * @dump_segments: list of segments in the firmware + * @nb_vdev: number of vdev currently handled by rproc */ struct rproc { struct list_head node; @@ -485,6 +486,7 @@ struct rproc { bool has_iommu; bool auto_boot; struct list_head dump_segments; + int nb_vdev; }; /** @@ -512,7 +514,6 @@ struct rproc_subdev { /** * struct rproc_vring - remoteproc vring state * @va: virtual address - * @dma: dma address * @len: length, in bytes * @da: device address * @align: vring alignment @@ -522,7 +523,6 @@ struct rproc_subdev { */ struct rproc_vring { void *va; - dma_addr_t dma; int len; u32 da; u32 align; @@ -541,6 +541,7 @@ struct rproc_vring { * @vdev: the virio device * @vring: the vrings for this vdev * @rsc_offset: offset of the vdev's resource entry + * @index: vdev position versus other vdev declared in resource table */ struct rproc_vdev { struct kref refcount; @@ -553,6 +554,7 @@ struct rproc_vdev { struct virtio_device vdev; struct rproc_vring vring[RVDEV_NUM_VRINGS]; u32 rsc_offset; + u32 index; }; struct rproc *rproc_get_by_phandle(phandle phandle); From patchwork Fri Jul 27 13:14:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 143059 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp807359ljj; Fri, 27 Jul 2018 06:16:05 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfhTBo3vnXAx9d7AVBtla7q6+vnMNhpKwfoWgydcPdW3TpI1GlmRa7apdH0JE+YZ5fBaYSo X-Received: by 2002:a17:902:8e81:: with SMTP id bg1-v6mr5997757plb.129.1532697365072; Fri, 27 Jul 2018 06:16:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532697365; cv=none; d=google.com; s=arc-20160816; b=yqODXU5SXc5Jw0LUseshdBmd8CFjWlc9qJ2y0lHcQtrQSfZlKyy7SoWlwp7+kF23RO NH548EZdGl9kRY1ufmw73KNLVPCpDBVynfo2GUpGOC/FOQgzz0HnEzCNlppVqV4IY2lo OA3tU5suG/CVjE71SjJofWXpoJbe6G0XVFbqvX4quLJ7wf6sOeBkxkUZkqjj9HaN3qZ+ rHnx6r47GIwj0RcXclNT2hznNaJgZodN1O0yfWGvD6qi02xF5xk8uP2rUeq/4UanglaF hQEAMLThoRBDa2Ub0wgW4Qm83fZlx/ZgUIUTTCWSB8mcVWfGw4qGmpq+KyLMp6qUq/sg 1S+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=113K0zOPXmCdee+pGvviSk436ED55lvfeAaYm/FF0E4=; b=UE89xA/TujEjjQNixTYociSnsPBMbHAzMY8EP2WRz1PnwUtdT+B7h6jGAp65+SII8d 5PVyj4jRYUWWaKQr+RntVOjOleRn1KXWsi5z76Qd1Mn3iHnTnNkQirCDpPhesmxs3SZj edOBcANNg9NBjrudLdoHAyg0bmvR4pPMX2SlEUL02m1BGCe8Dou+JlW9Iv+5MLKK/G0j he7fsqwHA/q0hZ1sra3QSUCJhQFvd6VFCbstOY9HCHDNJx2voVGo1BIr61XyhIQsRlrQ uy2jqfWgIb1iLTiNN9JjrorS6MXdz/eiBVH83fSEyuXPVNEzNA/TYSW2KwCLhCYr0o/M Wotg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 31-v6si3487382plz.217.2018.07.27.06.16.04; Fri, 27 Jul 2018 06:16:05 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388712AbeG0Oh2 (ORCPT + 31 others); Fri, 27 Jul 2018 10:37:28 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:39866 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388662AbeG0Oh1 (ORCPT ); Fri, 27 Jul 2018 10:37:27 -0400 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w6RDE244014483; Fri, 27 Jul 2018 15:15:31 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2kg1tj8pu9-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Jul 2018 15:15:31 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 1CDD834; Fri, 27 Jul 2018 13:15:31 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id EEB92577A; Fri, 27 Jul 2018 13:15:30 +0000 (GMT) Received: from localhost (10.75.127.50) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Jul 2018 15:15:30 +0200 From: Loic Pallardy To: , CC: , , , , , Loic Pallardy Subject: [PATCH v4 13/17] remoteproc: create vdev subdevice with specific dma memory pool Date: Fri, 27 Jul 2018 15:14:48 +0200 Message-ID: <1532697292-14272-14-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> References: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG8NODE1.st.com (10.75.127.22) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-27_06:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch creates a dedicated vdev subdevice for each vdev declared in firmware resource table and associates carveout named "vdev%dbuffer" (with %d vdev index in resource table) if any as dma coherent memory pool. Then vdev subdevice is used as parent for virtio device. Signed-off-by: Loic Pallardy --- drivers/remoteproc/remoteproc_core.c | 35 +++++++++++++++++++++++--- drivers/remoteproc/remoteproc_internal.h | 1 + drivers/remoteproc/remoteproc_virtio.c | 42 +++++++++++++++++++++++++++++++- include/linux/remoteproc.h | 1 + 4 files changed, 75 insertions(+), 4 deletions(-) -- 1.9.1 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 4edc6f0..adcc66e 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -145,7 +146,7 @@ static void rproc_disable_iommu(struct rproc *rproc) iommu_domain_free(domain); } -static phys_addr_t rproc_va_to_pa(void *cpu_addr) +phys_addr_t rproc_va_to_pa(void *cpu_addr) { /* * Return physical address according to virtual address location @@ -160,6 +161,7 @@ static phys_addr_t rproc_va_to_pa(void *cpu_addr) WARN_ON(!virt_addr_valid(cpu_addr)); return virt_to_phys(cpu_addr); } +EXPORT_SYMBOL(rproc_va_to_pa); /** * rproc_da_to_va() - lookup the kernel virtual address for a remoteproc address @@ -423,6 +425,20 @@ static void rproc_vdev_do_stop(struct rproc_subdev *subdev, bool crashed) } /** + * rproc_rvdev_release() - release the existence of a rvdev + * + * @dev: the subdevice's dev + */ +static void rproc_rvdev_release(struct device *dev) +{ + struct rproc_vdev *rvdev = container_of(dev, struct rproc_vdev, dev); + + of_reserved_mem_device_release(dev); + + kfree(rvdev); +} + +/** * rproc_handle_vdev() - handle a vdev fw resource * @rproc: the remote processor * @rsc: the vring resource descriptor @@ -455,6 +471,7 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc, struct device *dev = &rproc->dev; struct rproc_vdev *rvdev; int i, ret; + char name[16]; /* make sure resource isn't truncated */ if (sizeof(*rsc) + rsc->num_of_vrings * sizeof(struct fw_rsc_vdev_vring) @@ -488,6 +505,18 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc, rvdev->rproc = rproc; rvdev->index = rproc->nb_vdev++; + /* Initialise vdev subdevice */ + snprintf(name, sizeof(name), "vdev%dbuffer", rvdev->index); + rvdev->dev.parent = rproc->dev.parent; + rvdev->dev.release = rproc_rvdev_release; + dev_set_name(&rvdev->dev, "%s#%s", dev_name(rvdev->dev.parent), name); + dev_set_drvdata(&rvdev->dev, rvdev); + dma_set_coherent_mask(&rvdev->dev, DMA_BIT_MASK(32)); + + ret = device_register(&rvdev->dev); + if (ret) + goto free_rvdev; + /* parse the vrings */ for (i = 0; i < rsc->num_of_vrings; i++) { ret = rproc_parse_vring(rvdev, rsc, i); @@ -518,7 +547,7 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc, for (i--; i >= 0; i--) rproc_free_vring(&rvdev->vring[i]); free_rvdev: - kfree(rvdev); + device_unregister(&rvdev->dev); return ret; } @@ -536,7 +565,7 @@ void rproc_vdev_release(struct kref *ref) rproc_remove_subdev(rproc, &rvdev->subdev); list_del(&rvdev->node); - kfree(rvdev); + device_unregister(&rvdev->dev); } /** diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h index f6cad24..bfeacfd 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h @@ -52,6 +52,7 @@ struct dentry *rproc_create_trace_file(const char *name, struct rproc *rproc, int rproc_alloc_vring(struct rproc_vdev *rvdev, int i); void *rproc_da_to_va(struct rproc *rproc, u64 da, int len); +phys_addr_t rproc_va_to_pa(void *cpu_addr); int rproc_trigger_recovery(struct rproc *rproc); int rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw); diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c index de21f62..9ee63c0 100644 --- a/drivers/remoteproc/remoteproc_virtio.c +++ b/drivers/remoteproc/remoteproc_virtio.c @@ -17,7 +17,9 @@ * GNU General Public License for more details. */ +#include #include +#include #include #include #include @@ -315,10 +317,48 @@ static void rproc_virtio_dev_release(struct device *dev) int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id) { struct rproc *rproc = rvdev->rproc; - struct device *dev = &rproc->dev; + struct device *dev = &rvdev->dev; struct virtio_device *vdev = &rvdev->vdev; + struct rproc_mem_entry *mem; int ret; + /* Try to find dedicated vdev buffer carveout */ + mem = rproc_find_carveout_by_name(rproc, "vdev%dbuffer", rvdev->index); + if (mem) { + phys_addr_t pa; + + if (mem->of_resm_idx != -1) { + struct device_node *np = rproc->dev.parent->of_node; + + /* Associate reserved memory to vdev device */ + ret = of_reserved_mem_device_init_by_idx(dev, np, + mem->of_resm_idx); + if (ret) { + dev_err(dev, "Can't associate reserved memory\n"); + goto out; + } + } else { + if (mem->va) { + dev_warn(dev, "vdev %d buffer already mapped\n", + rvdev->index); + pa = rproc_va_to_pa(mem->va); + } else { + /* Use dma address as carveout no memmapped yet */ + pa = (phys_addr_t)mem->dma; + } + + /* Associate vdev buffer memory pool to vdev subdev */ + ret = dmam_declare_coherent_memory(dev, pa, + mem->da, + mem->len, + DMA_MEMORY_EXCLUSIVE); + if (ret < 0) { + dev_err(dev, "Failed to associate buffer\n"); + goto out; + } + } + } + vdev->id.device = id, vdev->config = &rproc_virtio_config_ops, vdev->dev.parent = dev; diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 6b3a234..2921dd2 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -547,6 +547,7 @@ struct rproc_vdev { struct kref refcount; struct rproc_subdev subdev; + struct device dev; unsigned int id; struct list_head node; From patchwork Fri Jul 27 13:14:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 143055 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp806926ljj; Fri, 27 Jul 2018 06:15:40 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfvCfBovxpRsf433gssO/+E72XOJ+bvUay7s2L7GUmifEbtVwS/6xhdG0NuKlylaV/ohkN+ X-Received: by 2002:a63:91c8:: with SMTP id l191-v6mr5993732pge.180.1532697340473; Fri, 27 Jul 2018 06:15:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532697340; cv=none; d=google.com; s=arc-20160816; b=jwhNi5nNZHou+/0rVcOmyKH1JDRA1lQucFb2LfNfK+I+oqjbwbswReqBRQF8+zupM6 vXFvsUwpEle816dWKbHQePI2DaAnaZxq/qj8D2MZyGq6iptcnqx+6atfp2ni32CDK4+J G27NupNgY9nKB2HlXVTFVsT/F0n7izgBoZXi6MI+QEfj+OgPm0d23rTsYuB2cjrjW5mj o8IEQFXVbOX/dNj2sQV9Dle9f6B26hbW7QfMmMo1ue5WMIdCvYlBajAD4Xt1LrqfLY3V mDNXCW4naeq+15UYOYCDWqSptzfwPTG4s1t8U55prT1mLdyrBpPkpSjOkxDtDrLoX1yN qD3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=bonyMP6ToHXcnmBe8uNkrs7Gb5UrnzaxnxHSphica2U=; b=HRR+99jtdtfRNyStdM+qQtfder0HTKGjcCyq0mxrYMvkEjHOqj8uaLzA/4HE53tFIw sNb3Hs59GcuNm7z7gtk+58NNSjKSdvragVdD5iv3+DbWbB/kuJueSoDncwsM0saKTzlA JWjLPb160VRbykXYWEEmfjqRm8Z237ufHZIHW+YCyhXvnHIC4mo01qHL+lRVMC8IJt/H g6Pvgel7QimJj9idrp/MSI07oBGXD7v1nQTx1b3In07Xvu7FsnGKWQ6TOjT5ifwNXCtW 2k+ku1d+p6NPPHZu4NI3e6eTgXMuXpTGxuojWqzdgbfwTYS2v/f3alBGfVL8zdDZKvRB 2ppQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u186-v6si3619849pgd.578.2018.07.27.06.15.40; Fri, 27 Jul 2018 06:15:40 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388775AbeG0Oha (ORCPT + 31 others); Fri, 27 Jul 2018 10:37:30 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:55205 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732124AbeG0Oh3 (ORCPT ); Fri, 27 Jul 2018 10:37:29 -0400 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w6RDEJ11016198; Fri, 27 Jul 2018 15:15:32 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2kg26xrjwa-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Jul 2018 15:15:32 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id E7D9638; Fri, 27 Jul 2018 13:15:31 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id CDCE4577E; Fri, 27 Jul 2018 13:15:31 +0000 (GMT) Received: from localhost (10.75.127.49) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Jul 2018 15:15:31 +0200 From: Loic Pallardy To: , CC: , , , , , Loic Pallardy Subject: [PATCH v4 14/17] remoteproc: keystone: declare reserved memory region for vdev device Date: Fri, 27 Jul 2018 15:14:49 +0200 Message-ID: <1532697292-14272-15-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> References: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.49] X-ClientProxiedBy: SFHDAG3NODE2.st.com (10.75.127.8) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-27_06:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch introduces keystone_rproc_parse_fw() to declare a carveout region based on reserved memory for vdev buffer allocation, if a memory region has been declared on rproc DT node. Signed-off-by: Loic Pallardy --- drivers/remoteproc/keystone_remoteproc.c | 53 +++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 4 deletions(-) -- 1.9.1 diff --git a/drivers/remoteproc/keystone_remoteproc.c b/drivers/remoteproc/keystone_remoteproc.c index aaac311..ef542f2 100644 --- a/drivers/remoteproc/keystone_remoteproc.c +++ b/drivers/remoteproc/keystone_remoteproc.c @@ -293,11 +293,56 @@ static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, int len) return (__force void *)va; } +/* + * Custom function to register platform specific memory region(s) + * before loading firmware resource table thanks to generic + * rproc_elf_load_rsc_table() function. + */ +static int keystone_rproc_parse_fw(struct rproc *rproc, + const struct firmware *fw) +{ + struct device *dev = rproc->dev.parent; + struct rproc_mem_entry *mem; + struct device_node *node; + struct resource res; + int err; + + node = of_parse_phandle(dev->of_node, "memory-region", 0); + if (!node) { + dev_warn(dev, "No memory-region specified\n"); + goto out; + } + + err = of_address_to_resource(node, 0, &res); + if (err) { + dev_err(dev, "Bad memory-region definition\n"); + return err; + } + + /* Register memory region for vdev buffer allocation */ + mem = rproc_of_resm_mem_entry_init(dev, 0, resource_size(&res), + res.start, "vdev0buffer"); + + if (!mem) + return -ENOMEM; + + rproc_add_carveout(rproc, mem); + +out: + return rproc_elf_load_rsc_table(rproc, fw); +} + static const struct rproc_ops keystone_rproc_ops = { - .start = keystone_rproc_start, - .stop = keystone_rproc_stop, - .kick = keystone_rproc_kick, - .da_to_va = keystone_rproc_da_to_va, + .start = keystone_rproc_start, + .stop = keystone_rproc_stop, + .kick = keystone_rproc_kick, + .da_to_va = keystone_rproc_da_to_va, + .parse_fw = keystone_rproc_parse_fw, + .load = rproc_elf_load_segments, + .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, + .sanity_check = rproc_elf_sanity_check, + .get_boot_addr = rproc_elf_get_boot_addr, + }; static int keystone_rproc_of_get_memories(struct platform_device *pdev, From patchwork Fri Jul 27 13:14:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 143056 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp806947ljj; Fri, 27 Jul 2018 06:15:42 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfXJjFLYmi4C9fewnxMlTjxr50xZsI3XSxQ97S8apif7iG+GgDqYhBzLkXhGbIdEKjsVnNx X-Received: by 2002:a63:710d:: with SMTP id m13-v6mr6145093pgc.66.1532697341919; Fri, 27 Jul 2018 06:15:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532697341; cv=none; d=google.com; s=arc-20160816; b=FGiT7GCKcuJhyxml0Jj2e7Pq4Eci2MzhOZWQMgNqKg+VNayhtdluQxkBlM6c/tJqGv Q5615dA5Qhg2VORHkw78HTHsJ+DIAhalh70cJMW2GeAHs2G2LA+gI7ZMuWEIoMDewaR8 Su5YeZPWG4ycO3EifqfztirXibB+sfwHm1BLC4S8SW7iCc5lwZwZrRJTaemZGN4ptpS4 U5UF9vqmfX6b8N66asAdAWSGlf++MoPvFZmUX4xxrZIsfZiZ/HGrZE0SOurU6oegI0wV 74pAxSdoMd3o8WWvRuFl0wjZhHtjDtmWUjHF6bQMBaZJvAfaVeYMI1Mmcs9mcPzonyZi toAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=MvQQcWrSeKYRyeq5FM06IIGX6N1pZtDnLL+eDwWkSII=; b=Gxi6vNxisJ2Y+fMd6nlgrmWTu48fyyAc6yNP3kgI+KkMgPQTLnZG2YAqq1Hrs+CFd5 IDaGiDG03HL5Iu2UncfsntjtgOu65PfC18QNhvpzAwX1enC/Z8wn83PeapwmV8IjMx1C vB30OtMQ1wUNuiYDWmPGaowG8unlO8MUIYrROq66DOyjhS5KbcUKHt6OwZtAxwBgnEq3 zaQyS2LyXJG4Byy38MlNm0tGb12x/dbWhUB/oosWwD4Yl4yoG1MEj0wUw0W4swJrx+Y+ 2JOYWaYuLDTw84aTlnzJjJLGTts2p/hAU98Y2dByaVfPHOpKGrH12yBkA03tILrqLrFH E6bQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z4-v6si3391930pgp.580.2018.07.27.06.15.41; Fri, 27 Jul 2018 06:15:41 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388806AbeG0Ohc (ORCPT + 31 others); Fri, 27 Jul 2018 10:37:32 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:39878 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388746AbeG0Ohb (ORCPT ); Fri, 27 Jul 2018 10:37:31 -0400 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w6RDE18u014480; Fri, 27 Jul 2018 15:15:33 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2kg1tj8puj-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Jul 2018 15:15:33 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id E53533A; Fri, 27 Jul 2018 13:15:32 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id C2B58577E; Fri, 27 Jul 2018 13:15:32 +0000 (GMT) Received: from localhost (10.75.127.50) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Jul 2018 15:15:32 +0200 From: Loic Pallardy To: , CC: , , , , , Loic Pallardy Subject: [PATCH v4 15/17] remoteproc: da8xx: declare reserved memory region for vdev device Date: Fri, 27 Jul 2018 15:14:50 +0200 Message-ID: <1532697292-14272-16-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> References: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG2NODE1.st.com (10.75.127.4) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-27_06:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch introduces da8xx_rproc_parse_fw() to declare a carveout region based on reserved memory for vdev buffer allocation. Signed-off-by: Loic Pallardy --- drivers/remoteproc/da8xx_remoteproc.c | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) -- 1.9.1 diff --git a/drivers/remoteproc/da8xx_remoteproc.c b/drivers/remoteproc/da8xx_remoteproc.c index b668e32..679a076 100644 --- a/drivers/remoteproc/da8xx_remoteproc.c +++ b/drivers/remoteproc/da8xx_remoteproc.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -179,10 +180,47 @@ static void da8xx_rproc_kick(struct rproc *rproc, int vqid) writel(SYSCFG_CHIPSIG2, drproc->chipsig); } +static int da8xx_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw) +{ + struct device *dev = rproc->dev.parent; + struct rproc_mem_entry *mem; + struct device_node *node; + struct resource res; + int err; + + node = of_parse_phandle(dev->of_node, "memory-region", 0); + if (!node) { + dev_err(dev, "No memory-region specified\n"); + return -EINVAL; + } + + err = of_address_to_resource(node, 0, &res); + if (err) { + dev_err(dev, "Bad memory-region definition\n"); + return err; + } + + /* Register memory region for vdev buffer allocation */ + mem = rproc_of_resm_mem_entry_init(dev, 0, resource_size(&res), + res.start, "vdev0buffer"); + + if (!mem) + return -ENOMEM; + + rproc_add_carveout(rproc, mem); + + return rproc_elf_load_rsc_table(rproc, fw); +} + static const struct rproc_ops da8xx_rproc_ops = { .start = da8xx_rproc_start, .stop = da8xx_rproc_stop, .kick = da8xx_rproc_kick, + .parse_fw = da8xx_rproc_parse_fw, + .load = rproc_elf_load_segments, + .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, + .sanity_check = rproc_elf_sanity_check, + .get_boot_addr = rproc_elf_get_boot_addr, }; static int da8xx_rproc_get_internal_memories(struct platform_device *pdev, From patchwork Fri Jul 27 13:14:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 143058 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp807146ljj; Fri, 27 Jul 2018 06:15:52 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdoXyipiR8rCd8epXq0u/6MDnsRqrS8YN6FkyaOeESJxZeTQBbFXCdcudOJD8qBICKqbhgt X-Received: by 2002:a63:4506:: with SMTP id s6-v6mr6282690pga.422.1532697352380; Fri, 27 Jul 2018 06:15:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532697352; cv=none; d=google.com; s=arc-20160816; b=a70GYdEMdQ45xah257C+7Eu6aOrRYg9i/EhqKLFV1sl0eekQ9Jb6exo/8V4SUXmopD oaqUxMpTuwLAzHRoVtpGPQP6Cz7g4CaU4ZorjIVug7qKGs3bcyScH55uqJReZ3RMwTEc tBFomqTurDYw8G3oBUUvKpsg9jDdzwMrnPRNKHvduCkjcd6+uFb1JUUM3ovLnL+7QIrP z5moNLhXODVfSoUycLEdEFDpuy+dmsF68w9y4FJhDoVMQLGcY222A8DzSMGrYBqnoVxi HN195j4mfK/yA85Yrul2ZL+WL0Ln22gJ208M56zHqok3FkZwvCbVqb9z2n4PEyI9y1uh 2X9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=vV1e3C/6vb16XqKlc6W9osebkgTykn8nifNSe0HPs5Q=; b=HsO47cBytm6uStAZDim8vrgAQirgQk28LhTCzp+0fLZYTa2mgjI6jBz6PWb7UbkI6o L6LokuqtGLh+3XDEnVnfqXhOKEOzltxd+XHi/G46DF1nYTnf4U03pu9PjmPiW/GBKrus 6lX2pKQzQKPY1Y1dNBgOCKgWq+7RewYKyes2iqfcnkU3uvATmvcSTRRXjPwqEgVYd5Yg KJ9LrBhBaVZpnqBjBmpcnqQXO/mIhILrx1xjhm6fFLlKu33eq06mlmgXykCcY0vGCPAt tle8hMSE9pNbh/3kOHu6pTQOIMiv213uaSiCKjbb2SmIVNmjLFKEjaRzKdG+9yJACIbH 7xxQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t16-v6si3364096plo.319.2018.07.27.06.15.52; Fri, 27 Jul 2018 06:15:52 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388848AbeG0Ohn (ORCPT + 31 others); Fri, 27 Jul 2018 10:37:43 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:10631 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388298AbeG0Ohb (ORCPT ); Fri, 27 Jul 2018 10:37:31 -0400 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w6RDEIkv016195; Fri, 27 Jul 2018 15:15:35 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2kg26xrjwm-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Jul 2018 15:15:35 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 56D3A34; Fri, 27 Jul 2018 13:15:34 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 37CBA577E; Fri, 27 Jul 2018 13:15:34 +0000 (GMT) Received: from localhost (10.75.127.48) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Jul 2018 15:15:33 +0200 From: Loic Pallardy To: , CC: , , , , , Loic Pallardy Subject: [PATCH v4 16/17] remoteproc: st: add reserved memory support Date: Fri, 27 Jul 2018 15:14:51 +0200 Message-ID: <1532697292-14272-17-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> References: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.48] X-ClientProxiedBy: SFHDAG8NODE1.st.com (10.75.127.22) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-27_06:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ST remote processor needs some specified memory regions for firmware and IPC. Memory regions are defined as reserved memory and should be registered in remoteproc core thanks to rproc_add_carveout function before rproc_start. For this, st rproc driver implements prepare ops. Signed-off-by: Loic Pallardy --- drivers/remoteproc/st_remoteproc.c | 96 +++++++++++++++++++++++++++++++++----- 1 file changed, 85 insertions(+), 11 deletions(-) -- 1.9.1 diff --git a/drivers/remoteproc/st_remoteproc.c b/drivers/remoteproc/st_remoteproc.c index aacef0e..45958d5 100644 --- a/drivers/remoteproc/st_remoteproc.c +++ b/drivers/remoteproc/st_remoteproc.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -91,6 +92,82 @@ static void st_rproc_kick(struct rproc *rproc, int vqid) dev_err(dev, "failed to send message via mbox: %d\n", ret); } +static int st_rproc_mem_alloc(struct rproc *rproc, + struct rproc_mem_entry *mem) +{ + struct device *dev = rproc->dev.parent; + void *va; + + va = ioremap_wc(mem->dma, mem->len); + if (!va) { + dev_err(dev, "Unable to map memory region: %pa+%zx\n", + &mem->dma, mem->len); + return -ENOMEM; + } + + /* Update memory entry va */ + mem->va = va; + + return 0; +} + +static int st_rproc_mem_release(struct rproc *rproc, + struct rproc_mem_entry *mem) +{ + iounmap(mem->va); + + return 0; +} + +static int st_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw) +{ + struct device *dev = rproc->dev.parent; + struct device_node *np = dev->of_node; + struct rproc_mem_entry *mem; + void *va; + struct reserved_mem *rmem; + struct of_phandle_iterator it; + int err, index = 0; + + of_phandle_iterator_init(&it, np, "memory-region", NULL, 0); + while ((err = of_phandle_iterator_next(&it)) == 0) { + va = NULL; + rmem = of_reserved_mem_lookup(it.node); + + /* No need to map vdev buffer */ + if (strcmp(it.node->name, "vdev0buffer")) { + va = devm_ioremap_wc(dev, rmem->base, rmem->size); + if (!va) { + dev_err(dev, "Unable to map memory region: %pa+%zx\n", + &rmem->base, rmem->size); + return -ENOMEM; + } + + /* Register memory region */ + mem = rproc_mem_entry_init(dev, va, + (dma_addr_t)rmem->base, + rmem->size, rmem->base, + st_rproc_mem_alloc, + st_rproc_mem_release, + it.node->name); + } else { + /* Register reserved memory for vdev buffer allocation */ + mem = rproc_of_resm_mem_entry_init(dev, index, + rmem->size, + rmem->base, + it.node->name); + } + + if (!mem) + return -ENOMEM; + + rproc_add_carveout(rproc, mem); + index++; + } + + return rproc_elf_load_rsc_table(rproc, fw); +} + static int st_rproc_start(struct rproc *rproc) { struct st_rproc *ddata = rproc->priv; @@ -158,9 +235,14 @@ static int st_rproc_stop(struct rproc *rproc) } static const struct rproc_ops st_rproc_ops = { - .kick = st_rproc_kick, - .start = st_rproc_start, - .stop = st_rproc_stop, + .kick = st_rproc_kick, + .start = st_rproc_start, + .stop = st_rproc_stop, + .parse_fw = st_rproc_parse_fw, + .load = rproc_elf_load_segments, + .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, + .sanity_check = rproc_elf_sanity_check, + .get_boot_addr = rproc_elf_get_boot_addr, }; /* @@ -254,12 +336,6 @@ static int st_rproc_parse_dt(struct platform_device *pdev) return -EINVAL; } - err = of_reserved_mem_device_init(dev); - if (err) { - dev_err(dev, "Failed to obtain shared memory\n"); - return err; - } - err = clk_prepare(ddata->clk); if (err) dev_err(dev, "failed to get clock\n"); @@ -387,8 +463,6 @@ static int st_rproc_remove(struct platform_device *pdev) clk_disable_unprepare(ddata->clk); - of_reserved_mem_device_release(&pdev->dev); - for (i = 0; i < ST_RPROC_MAX_VRING * MBOX_MAX; i++) mbox_free_channel(ddata->mbox_chan[i]); From patchwork Fri Jul 27 13:14:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 143057 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp806989ljj; Fri, 27 Jul 2018 06:15:43 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeF0OUtppoe5ivseOHRtujIoqvg2FVGIHIngDBAEjqrVvpv3gy1oy4C5PjPYwV0oUyzK42b X-Received: by 2002:a63:6188:: with SMTP id v130-v6mr6136290pgb.100.1532697343582; Fri, 27 Jul 2018 06:15:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532697343; cv=none; d=google.com; s=arc-20160816; b=so9ERtWFPa5DQHUH26VQ7z8uSNmjXB3RfLbypLXXw4KqBA4i0c0n8VVNfSi1rCWQSW urXWTblsa8yGpYJWst8b6xrS4NgL0UP0rK1dpYSXynKasDSIP96z4YSkzrqkaNAfpBJ7 PhKmR7pjakkzuKKnjVOqOo4OmGfyUdeYw6V2mrJArFURPlRcgO59YL7yUZV3hzc1uUYh z+4hBv946CEkJ7rOMGOLZzzU2cPCaKInQZNl0vKwkG91nnCn/fdeEO/1t9niTV9wedID JuxrJvaGMg+ufnEtFNVexCb0usampAWtZ28cNsfuOeKlkyDyPyKhibjC5jGEk/OWsv+I SJIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=erVfU5vV1SHre22hycRC8OkiExOSCcuHne6RBxDfpn8=; b=tjg3XcHTvUdKA9EFlFYLiooSlV/GFWoAo/g+U4MNDlYYsmwXNimvxqe2bK/rua6W7g RZ21A1Tk66W8BFmVrNUjlErKmPFln8R5xDFiZXFWuqLf9KpiVCI1BLTBf4TOJa8QAfk8 SL6EVTzYK7SC2h0gsyhDiAMyQ39yj+zsEinyDLcQZAD9S95ZRJvM+lsCgpkbRh13HddZ GQcjXxJXCNAxOkn0gDGt1seCvnMbIYA5RDy/lwRgWffJhMIvXyVGJ/9bULcTOF5SpP+6 Pb6aQB1CqTykIGewIM92T/UqIqUXs78yZ43U3IvBNxj2EJgU8D4jjlicj3g3y5Kv+9jk gxQg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v36-v6si3876653pga.336.2018.07.27.06.15.43; Fri, 27 Jul 2018 06:15: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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388832AbeG0Ohd (ORCPT + 31 others); Fri, 27 Jul 2018 10:37:33 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:18766 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732124AbeG0Ohc (ORCPT ); Fri, 27 Jul 2018 10:37:32 -0400 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w6RDEJ13016198; Fri, 27 Jul 2018 15:15:36 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2kg26xrjws-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Jul 2018 15:15:36 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 52F6F3D; Fri, 27 Jul 2018 13:15:35 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 180B75782; Fri, 27 Jul 2018 13:15:35 +0000 (GMT) Received: from localhost (10.75.127.48) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 27 Jul 2018 15:15:34 +0200 From: Loic Pallardy To: , CC: , , , , , Loic Pallardy Subject: [PATCH v4 17/17] rpmsg: virtio: allocate buffer from parent Date: Fri, 27 Jul 2018 15:14:52 +0200 Message-ID: <1532697292-14272-18-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> References: <1532697292-14272-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.48] X-ClientProxiedBy: SFHDAG6NODE3.st.com (10.75.127.18) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-27_06:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Remoteproc is now capable to create one specific sub-device per virtio link to associate a dedicated memory pool. This implies to change device used by virtio_rpmsg for buffer allocation from grand-parent to parent. Signed-off-by: Loic Pallardy --- drivers/rpmsg/virtio_rpmsg_bus.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) -- 1.9.1 Reviewed-by: Anup Patel Tested-by: Anup Patel diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 664f957..5c89201 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -912,7 +912,7 @@ static int rpmsg_probe(struct virtio_device *vdev) total_buf_space = vrp->num_bufs * vrp->buf_size; /* allocate coherent memory for the buffers */ - bufs_va = dma_alloc_coherent(vdev->dev.parent->parent, + bufs_va = dma_alloc_coherent(vdev->dev.parent, total_buf_space, &vrp->bufs_dma, GFP_KERNEL); if (!bufs_va) { @@ -980,7 +980,7 @@ static int rpmsg_probe(struct virtio_device *vdev) return 0; free_coherent: - dma_free_coherent(vdev->dev.parent->parent, total_buf_space, + dma_free_coherent(vdev->dev.parent, total_buf_space, bufs_va, vrp->bufs_dma); vqs_del: vdev->config->del_vqs(vrp->vdev); @@ -1015,7 +1015,7 @@ static void rpmsg_remove(struct virtio_device *vdev) vdev->config->del_vqs(vrp->vdev); - dma_free_coherent(vdev->dev.parent->parent, total_buf_space, + dma_free_coherent(vdev->dev.parent, total_buf_space, vrp->rbufs, vrp->bufs_dma); kfree(vrp);