From patchwork Wed Sep 4 10:31:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lokesh Vutla X-Patchwork-Id: 1157578 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=ti.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="eTP+19BG"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46NgDn3MGQz9sBF for ; Wed, 4 Sep 2019 20:34:49 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 0D2C5C21E30; Wed, 4 Sep 2019 10:33:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 15A9DC21E6A; Wed, 4 Sep 2019 10:33:02 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 76331C21E53; Wed, 4 Sep 2019 10:32:48 +0000 (UTC) Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) by lists.denx.de (Postfix) with ESMTPS id C1817C21E53 for ; Wed, 4 Sep 2019 10:32:44 +0000 (UTC) Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id x84AWhDY126988; Wed, 4 Sep 2019 05:32:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1567593163; bh=Db59JOOThNgWcF1EbpNJ0KaSXfBxVmKIsTJFTTwhgI0=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=eTP+19BGZRlVblic9k8VzcjgxJ3ijvB82H2OP/1kSjCY+k1++tsKBHw2admrdAmBi /7MpRkP0FDgikCmLFY0TDLaZUtlNoxyHTaUaJ6zbvFbv97nrCVFjB3QCZlg0X6te1Q vp7QLn7pAEKF3RO/2BN4J28mrbRhY47rU4AQkTKQ= Received: from DLEE100.ent.ti.com (dlee100.ent.ti.com [157.170.170.30]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTP id x84AWgpP025856; Wed, 4 Sep 2019 05:32:42 -0500 Received: from DLEE114.ent.ti.com (157.170.170.25) by DLEE100.ent.ti.com (157.170.170.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Wed, 4 Sep 2019 05:32:42 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DLEE114.ent.ti.com (157.170.170.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Wed, 4 Sep 2019 05:32:42 -0500 Received: from uda0131933.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id x84AWYUf122466; Wed, 4 Sep 2019 05:32:40 -0500 From: Lokesh Vutla To: Tom Rini , Date: Wed, 4 Sep 2019 16:01:27 +0530 Message-ID: <20190904103151.20121-3-lokeshvutla@ti.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190904103151.20121-1-lokeshvutla@ti.com> References: <20190904103151.20121-1-lokeshvutla@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Cc: fabien.dessenne@st.com, Tero Kristo Subject: [U-Boot] [PATCH v2 02/26] remoteproc: ops: Add elf section size as input parameter to device_to_virt api X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Introduce a new parameter "size" that accepts size of the region to remoteproc ops callback device_to_virt(). This can enforce more checks on the region that device_to_virt() is dealing with. Signed-off-by: Lokesh Vutla Tested-by: Fabien Dessenne Reviewed-by: Fabien Dessenne --- drivers/remoteproc/rproc-elf-loader.c | 3 ++- drivers/remoteproc/sandbox_testproc.c | 4 +++- drivers/remoteproc/stm32_copro.c | 12 ++++++++++-- include/remoteproc.h | 3 ++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/remoteproc/rproc-elf-loader.c b/drivers/remoteproc/rproc-elf-loader.c index 67937a7595..7574ba3fb3 100644 --- a/drivers/remoteproc/rproc-elf-loader.c +++ b/drivers/remoteproc/rproc-elf-loader.c @@ -86,7 +86,8 @@ int rproc_elf32_load_image(struct udevice *dev, unsigned long addr) continue; if (ops->device_to_virt) - dst = ops->device_to_virt(dev, (ulong)dst); + dst = ops->device_to_virt(dev, (ulong)dst, + phdr->p_memsz); dev_dbg(dev, "Loading phdr %i to 0x%p (%i bytes)\n", i, dst, phdr->p_filesz); diff --git a/drivers/remoteproc/sandbox_testproc.c b/drivers/remoteproc/sandbox_testproc.c index 5f35119ab7..eeee49c4dd 100644 --- a/drivers/remoteproc/sandbox_testproc.c +++ b/drivers/remoteproc/sandbox_testproc.c @@ -306,9 +306,11 @@ static int sandbox_testproc_ping(struct udevice *dev) * sandbox_testproc_device_to_virt() - Convert device address to virtual address * @dev: device to operate upon * @da: device address + * @size: Size of the memory region @da is pointing to * @return converted virtual address */ -static void *sandbox_testproc_device_to_virt(struct udevice *dev, ulong da) +static void *sandbox_testproc_device_to_virt(struct udevice *dev, ulong da, + ulong size) { u64 paddr; diff --git a/drivers/remoteproc/stm32_copro.c b/drivers/remoteproc/stm32_copro.c index ad941f67e8..71895daf9c 100644 --- a/drivers/remoteproc/stm32_copro.c +++ b/drivers/remoteproc/stm32_copro.c @@ -107,11 +107,13 @@ static int stm32_copro_set_hold_boot(struct udevice *dev, bool hold) * stm32_copro_device_to_virt() - Convert device address to virtual address * @dev: corresponding STM32 remote processor device * @da: device address + * @size: Size of the memory region @da is pointing to * @return converted virtual address */ -static void *stm32_copro_device_to_virt(struct udevice *dev, ulong da) +static void *stm32_copro_device_to_virt(struct udevice *dev, ulong da, + ulong size) { - fdt32_t in_addr = cpu_to_be32(da); + fdt32_t in_addr = cpu_to_be32(da), end_addr; u64 paddr; paddr = dev_translate_dma_address(dev, &in_addr); @@ -120,6 +122,12 @@ static void *stm32_copro_device_to_virt(struct udevice *dev, ulong da) return NULL; } + end_addr = cpu_to_be32(da + size - 1); + if (dev_translate_dma_address(dev, &end_addr) == OF_BAD_ADDR) { + dev_err(dev, "Unable to convert address %ld\n", da + size - 1); + return NULL; + } + return phys_to_virt(paddr); } diff --git a/include/remoteproc.h b/include/remoteproc.h index 4987194905..dbff1ce3cf 100644 --- a/include/remoteproc.h +++ b/include/remoteproc.h @@ -122,9 +122,10 @@ struct dm_rproc_ops { * * @dev: Remote proc device * @da: Device address + * @size: Size of the memory region @da is pointing to * @return virtual address. */ - void * (*device_to_virt)(struct udevice *dev, ulong da); + void * (*device_to_virt)(struct udevice *dev, ulong da, ulong size); }; /* Accessor */