Received: by 10.223.185.116 with SMTP id b49csp7628599wrg; Thu, 1 Mar 2018 08:27:38 -0800 (PST) X-Google-Smtp-Source: AG47ELt2fIUEQKMKX5zrmQw7l2HSqsmIz78UD2ajHPWT4S4PEze+9fV1VCY/93FetKUkesdo+yEi X-Received: by 10.98.37.132 with SMTP id l126mr2561921pfl.102.1519921658425; Thu, 01 Mar 2018 08:27:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519921658; cv=none; d=google.com; s=arc-20160816; b=PwVVD7jL4y33pDD0LS52exTX6XFR7Wd/2e4Qi1/F9ZIArqiBCnuiKT8076cBNEaAdm JPnzGNjaQqUwdP2CbLGzuwirY7WuvB4ZEbYL+MKw/o2MIb3kiRpDVyeFbbTNwBren2Nc nMAAlEKO165gYsiN0Sj0IbQNSF7vF39OYNOZql1fFY8ucvQUKjZVPiB/KjOCtdgdaKE9 N87eQI6YLzHVJZ1TX5qdARYZx1EguY6Lf8VhfznDZJ+sqJ+V+MtF7yvfwktvu9NxpGQ+ KOvNsHY5O77H/+okYUa60fZeduFCNPJH4osGd+VzlBRIreA9+BHlBqaA3CnxK7ur1yvA 5WIg== 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=JmBF2xWgiHjsLnxcIfj1h59uq6YBRkGGPAgVHStyBPc=; b=Dqxn3FpkEYoL9sYoKUQ7CmwPsZd9Sa+oLZyjlPNhocWKn8Bk2JTTdvf3GdY65d0hIw uEDzWAOKAS0gypRgsvRVt0kDopbcXLBfgSmH0/jc6Mk+5tKc6x/fcnTcq2MEBDVHBO2r 42Lzy9Zebw0kIFi+h+7lznhu/0jKKvlwkB6DiDSta2EpgBRvZ/YsOCDE8XKA8RAvhKOY 7BoQLJ0spQwJALHs2CJqIBVZ5m4IOy0a4pJ23A1y2Rh2vPu6c6xPBGoQLYcQ9AHFjZOj qGublfxJK2mwdrCoQ6LMsRXuxkeAFIwzz8CGn3/sPHK39QopAN6/YpT6GJFVF6jAmTeA UzDQ== 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 q11si3200375pfd.242.2018.03.01.08.27.24; Thu, 01 Mar 2018 08:27:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; 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 S1033099AbeCAQ0K (ORCPT + 99 others); Thu, 1 Mar 2018 11:26:10 -0500 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:50735 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1032981AbeCAQYT (ORCPT ); Thu, 1 Mar 2018 11:24:19 -0500 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 w21GJPRf025428; Thu, 1 Mar 2018 17:24:17 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2gax28ujkm-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 01 Mar 2018 17:24:17 +0100 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 1CF9738; Thu, 1 Mar 2018 16:24: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 01EC251FD; Thu, 1 Mar 2018 16:24:17 +0000 (GMT) Received: from localhost (10.75.127.44) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Thu, 1 Mar 2018 17:24:16 +0100 From: Loic Pallardy To: , CC: , , , , Loic Pallardy Subject: [PATCH v3 09/13] remoteproc: modify rproc_handle_carveout to support pre-registered region Date: Thu, 1 Mar 2018 17:23:56 +0100 Message-ID: <1519921440-21356-10-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1519921440-21356-1-git-send-email-loic.pallardy@st.com> References: <1519921440-21356-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.44] X-ClientProxiedBy: SFHDAG5NODE1.st.com (10.75.127.13) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-03-01_08:,, 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 support only dynamic region 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 no name match found, original allocation is used. Signed-off-by: Loic Pallardy --- drivers/remoteproc/remoteproc_core.c | 49 +++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 0ebbc4f..49b28a0 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -679,7 +679,7 @@ static int rproc_handle_carveout(struct rproc *rproc, struct fw_rsc_carveout *rsc, int offset, int avail) { - struct rproc_mem_entry *carveout, *mapping = NULL; + struct rproc_mem_entry *carveout, *mapping = NULL, *mem; struct device *dev = &rproc->dev; dma_addr_t dma; void *va; @@ -699,6 +699,51 @@ 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 */ + mem = rproc_find_carveout_by_name(rproc, rsc->name); + if (mem) { + int delta = 0; + + if (rsc->da != FW_RSC_ADDR_ANY) { + delta = rsc->da - mem->da; + + /* Check requested resource belongs to registered carveout */ + if (delta < 0) { + dev_err(dev->parent, + "Registered carveout doesn't fit da request\n"); + return -ENOMEM; + } + + if (delta + rsc->len > mem->len) { + dev_err(dev->parent, + "Registered carveout doesn't fit len request\n"); + return -ENOMEM; + } + } else { + /* Check requested resource length */ + if (rsc->len > mem->len) { + dev_err(dev->parent, + "Registered carveout doesn't fit len request\n"); + return -ENOMEM; + } + /* Update resource da with registered resource value */ + rsc->da = mem->da; + } + + /* + * Update resource pa + * Use va if defined else dma to generate pa + */ + if (mem->va) + rsc->pa = rproc_va_to_pa(mem->va) + delta; + else + rsc->pa = (u32)mem->dma + delta; + + return 0; + } + + /* No registered carveout found, allocate a new one */ va = dma_alloc_coherent(dev->parent, rsc->len, &dma, GFP_KERNEL); if (!va) { dev_err(dev->parent, @@ -761,6 +806,8 @@ static int rproc_handle_carveout(struct rproc *rproc, dev_dbg(dev, "carveout mapped 0x%x to %pad\n", rsc->da, &dma); + } else { + rsc->da = (u32)dma; } /* -- 1.9.1