From patchwork Fri Oct 27 12:44:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 117317 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp728099qgn; Fri, 27 Oct 2017 05:45:43 -0700 (PDT) X-Google-Smtp-Source: ABhQp+SsCt98kaeIlOZ+tM/gAZM/mBpW34mqLqFGSvJMzpq4ze1N9Kqk44a+rFYiDxdHC/o7Z9wh X-Received: by 10.99.116.25 with SMTP id p25mr227222pgc.26.1509108342899; Fri, 27 Oct 2017 05:45:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509108342; cv=none; d=google.com; s=arc-20160816; b=cebUtAx4e7b1+nHAfLTpgPz88Fai5uZzBg5R5trOSaW/eGd86OaHZo/wc2ShR1CZh8 KPZNAjhbKjp0QrQdfrIY0R9615ONjz2ohJ+2H2NgTZBPxdIRFlPZs0DnLG0/sR1nggxK zEukgy6lmJt2uX6pYUtyny8FJeukVD3X9kYYsbxrFl3//5IVHryQbGLZmNPYlhhC9hXw /N9EmxvabxQrdEA4dpI4/XBFAAF0m25G8RwEBHVS9DaV7ko+AfmUJaTR7gJdEneFzFX5 obZ+3ZXyTVMYRBzgmB+jq3Ym7aylV1sdu+5YTxOmQvToUdgbGwIUYyrW4XOnnKIRKNpG 7qzA== 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=ouvP6P5WHynhrRXV45C5nh+umaspcEBsd9ktqVZcoeM=; b=Qpc2WBWag5fhGQV40c1K4FErns9y/HHm34e0W2BOBCAHHTEeBhRd4FYHgZcOJfcUUz MrucHHdHpxzYzWeNxo1Yr6GuYmgi2TeFQO1rcDVtLrpe9dfL1ttb3lTu1nQ6OgKny5QD JleJzkDrbdfUOEd4bYlCeAaLcVIscKQ2XT7Z3JZdSKSjIZZ5Hn8wwDhU0A/xj7obxnOW W684hT7sABx9KW+QB1n0ItxHcVwUUqqH+D/kf/MtyaKsRE83rn3hLB49fR9b9fiSf/1N FoOrwyGGt+89QQUXjtEKlF+85/iU7+xKdClMUZ6kKJAHC1lzaDXHGBJuud4Y1ddvZMe7 9OLQ== 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 i6si4336946plt.797.2017.10.27.05.45.42; Fri, 27 Oct 2017 05:45:42 -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 S1752757AbdJ0Mpl (ORCPT + 27 others); Fri, 27 Oct 2017 08:45:41 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:33914 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752473AbdJ0Mof (ORCPT ); Fri, 27 Oct 2017 08:44:35 -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 v9RChcgw000587; Fri, 27 Oct 2017 14:44:34 +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 2duapy893a-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Oct 2017 14:44:34 +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 78D3531; Fri, 27 Oct 2017 12:44:33 +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 61EB726E0; Fri, 27 Oct 2017 12:44:33 +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 Oct 2017 14:44:32 +0200 From: Loic Pallardy To: , CC: , , , , Loic Pallardy Subject: [PATCH 4/7] remoteproc: introduce rproc_find_carveout_by_da Date: Fri, 27 Oct 2017 14:44:11 +0200 Message-ID: <1509108254-22296-5-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1509108254-22296-1-git-send-email-loic.pallardy@st.com> References: <1509108254-22296-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.50] 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.10432:, , definitions=2017-10-27_07:, , 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 device address (da). If match found, this function returns CPU virtual address corresponding to specified da. 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 279320a..78525d1 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -211,6 +211,48 @@ void *rproc_da_to_va(struct rproc *rproc, u64 da, int len) } EXPORT_SYMBOL(rproc_da_to_va); +/** + * rproc_find_carveout_by_da() - lookup the carveout region for a remoteproc address + * @rproc: handle of a remote processor + * @da: remoteproc device address to find + * @len: length of the memory region @da is pointing to + * + * 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 translate specific device addresse to virtual + * addresse so we can fill firmware resource table. + * + * The function returns a valid virtual address on success or NULL on failure. + */ +void *rproc_find_carveout_by_da(struct rproc *rproc, u64 da, int len) +{ + struct rproc_mem_entry *carveout; + void *va = NULL; + + list_for_each_entry(carveout, &rproc->carveouts, node) { + int offset = da - carveout->da; + + /* try next carveout if da is too small */ + if (offset < 0) + continue; + + /* try next carveout if da is too large */ + if (offset + len > carveout->len) + continue; + + va = carveout->va + offset; + + break; + } + + return va; +} + int rproc_alloc_vring(struct rproc_vdev *rvdev, int i) { struct rproc *rproc = rvdev->rproc;