From nobody Wed Nov 27 16:59:03 2024 Received: from mx08-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 120D41B3F3D; Tue, 26 Nov 2024 09:13:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.207.212.93 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732612411; cv=none; b=R+ve95HXMcZJgtdFyOcyYVnqVfeQhtuVWh7Uj8lZMsVQu2Ih52toIzdvQJ7tbF0wPXKxle+c6oxDfnxUoFqjL29rlhDE8v+tXCtodLvpeLpm9NUD9nBP5GGhcZAHQKMqtX2iYwgrXkH06eU2HnOvYVEgzQnhjOsd1UEYh9MnMzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732612411; c=relaxed/simple; bh=DOMHloKF4UN4qlkttRPn0qxlabsJq5KTXbS9OAb2WUc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nN5w6Jigm0pnvcpBmHVLuGC07azwuws04PFy7AWGn45uihrRBM4gAY5HASPGu7xXuOdJi+0urngymF7E+6RlSvWPS7ZnFx6g0lWIf16MtQ1skCU/Npguz6XMCFExZ1aYFrOOhmRP6/Uwq/KEycpn0POn1ukB7qNPLi5CZB/2+WM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b=CzPdDa8O; arc=none smtp.client-ip=91.207.212.93 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="CzPdDa8O" Received: from pps.filterd (m0369457.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4AQ7VaLq030348; Tue, 26 Nov 2024 10:13:23 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=selector1; bh= GC977nshZkMWBVY/wKvcQDvyN5arEAKIKgjZHxchAjQ=; b=CzPdDa8ONoMdXZlT Kor+Xu5/g1BSKPvbAm+p54oZtu3EwFpnQj+wrktsJLHjwn0d3R5zU4r7zMzvBB67 N12eSebyLlJZUAok+jQq0fzZNe90CMK1rayUDLhpUDoUkSSMU4Ls9V6yOEjWdWBs /cyguU3P0zeyVvNHlV+u62ziIZOaArhNuhZgidt85No5T40LgRyotJ7Q4+u9kcl1 VMn/3dKfkecnM3Dn0i055IDdRmco6Uixuu2oHk5AwE4oi7acJWsr7BUeHk3SMO9c rUte4nusagMqNxf96Z2VTFwWjMRe6oVi3Esi4UGcAwPfZJD1+vMgK9VgnTApOZZd l+IU/A== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 433tvnhanv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 26 Nov 2024 10:13:22 +0100 (CET) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 343554006F; Tue, 26 Nov 2024 10:12:18 +0100 (CET) Received: from Webmail-eu.st.com (eqndag1node6.st.com [10.75.129.135]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id F1F1A26B648; Tue, 26 Nov 2024 10:11:07 +0100 (CET) Received: from SAFDAG1NODE1.st.com (10.75.90.17) by EQNDAG1NODE6.st.com (10.75.129.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.37; Tue, 26 Nov 2024 10:11:07 +0100 Received: from localhost (10.48.86.121) by SAFDAG1NODE1.st.com (10.75.90.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.37; Tue, 26 Nov 2024 10:11:07 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier CC: Arnaud Pouliquen , , Subject: [PATCH v14 1/8] remoteproc: core: Introduce rproc_pa_to_va helper Date: Tue, 26 Nov 2024 10:10:32 +0100 Message-ID: <20241126091042.918144-2-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241126091042.918144-1-arnaud.pouliquen@foss.st.com> References: <20241126091042.918144-1-arnaud.pouliquen@foss.st.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SAFCAS1NODE1.st.com (10.75.90.11) To SAFDAG1NODE1.st.com (10.75.90.17) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 Content-Type: text/plain; charset="utf-8" When a resource table is loaded by an external entity such as U-boot or OP-TEE, we do not necessarily get the device address(da) but the physical address(pa). This helper performs similar translation than the rproc_da_to_va() but based on a physical address. Signed-off-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 46 ++++++++++++++++++++++++++++ include/linux/remoteproc.h | 1 + 2 files changed, 47 insertions(+) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remo= teproc_core.c index f276956f2c5c..ace11ea17097 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -230,6 +230,52 @@ void *rproc_da_to_va(struct rproc *rproc, u64 da, size= _t len, bool *is_iomem) } EXPORT_SYMBOL(rproc_da_to_va); =20 +/** + * rproc_pa_to_va() - lookup the kernel virtual address for a physical add= ress of a remoteproc + * memory + * + * @rproc: handle of a remote processor + * @pa: remoteproc physical address + * @len: length of the memory region @pa is pointing to + * @is_iomem: optional pointer filled in to indicate if @da is iomapped me= mory + * + * This function is a helper function similar to rproc_da_to_va() but it d= eals with physical + * addresses instead of device addresses. + * + * Return: a valid kernel address on success or NULL on failure + */ +void *rproc_pa_to_va(struct rproc *rproc, phys_addr_t pa, size_t len, bool= *is_iomem) +{ + struct rproc_mem_entry *carveout; + void *ptr =3D NULL; + + list_for_each_entry(carveout, &rproc->carveouts, node) { + int offset =3D pa - carveout->dma; + + /* Verify that carveout is allocated */ + if (!carveout->va) + continue; + + /* 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; + + ptr =3D carveout->va + offset; + + if (is_iomem) + *is_iomem =3D carveout->is_iomem; + + break; + } + + return ptr; +} +EXPORT_SYMBOL(rproc_pa_to_va); + /** * rproc_find_carveout_by_name() - lookup the carveout region by a name * @rproc: handle of a remote processor diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index b4795698d8c2..8fd0d7f63c8e 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -690,6 +690,7 @@ int rproc_detach(struct rproc *rproc); int rproc_set_firmware(struct rproc *rproc, const char *fw_name); void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type); void *rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iom= em); +void *rproc_pa_to_va(struct rproc *rproc, phys_addr_t pa, size_t len, bool= *is_iomem); =20 /* from remoteproc_coredump.c */ void rproc_coredump_cleanup(struct rproc *rproc); --=20 2.25.1