From 4bfd98733bfd80b51aa4c0ac2ff0076e5b298966 Mon Sep 17 00:00:00 2001 From: Mikael Olsson Date: Tue, 16 Apr 2024 16:36:47 +0200 Subject: Change remoteproc to map ROM as device memory The ROM is memory attached to the remote processor and should be mapped as device memory rather than normal memory to ensure memory transactions are handled correctly. To ensure this, the remoteproc driver will now map the ROM as device memory. Change-Id: I1b5f1dcd7af06bb9e1656f653d65813f7af424c3 Signed-off-by: Mikael Olsson --- remoteproc/ethosu_remoteproc.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/remoteproc/ethosu_remoteproc.c b/remoteproc/ethosu_remoteproc.c index 344627d..18f2789 100644 --- a/remoteproc/ethosu_remoteproc.c +++ b/remoteproc/ethosu_remoteproc.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: Copyright 2021-2023 Arm Limited and/or its affiliates + * SPDX-FileCopyrightText: Copyright 2021-2024 Arm Limited and/or its affiliates * SPDX-License-Identifier: GPL-2.0-only * * This program is free software and is provided to you under the terms of the @@ -128,7 +128,11 @@ static int ethosu_mem_alloc(struct rproc *rproc, struct device *dev = rproc->dev.parent; void *va; - va = (__force void *)devm_ioremap_wc(dev, mem->dma, mem->len); + if (mem->is_iomem) + va = (__force void *)devm_ioremap(dev, mem->dma, mem->len); + else + va = devm_memremap(dev, mem->dma, mem->len, MEMREMAP_WC); + if (IS_ERR_OR_NULL(va)) { dev_err(dev, "Failed to remap address. pa=%pa, len=%zu", &mem->dma, @@ -138,7 +142,6 @@ static int ethosu_mem_alloc(struct rproc *rproc, } mem->va = va; - mem->is_iomem = true; return 0; } @@ -148,8 +151,19 @@ static int ethosu_mem_release(struct rproc *rproc, { struct device *dev = rproc->dev.parent; - if (mem->va) + if (!mem->va) { + dev_warn(dev, + "Memory release. No mapping for memory %s pa=%p len=%zu", + mem->name, &mem->dma, mem->len); + goto done; + } + + if (mem->is_iomem) devm_iounmap(dev, (__force __iomem void *)mem->va); + else + devm_memunmap(dev, mem->va); + +done: return 0; } @@ -157,7 +171,8 @@ static int ethosu_mem_release(struct rproc *rproc, static int ethosu_add_carveout(struct rproc *rproc, const phys_addr_t pa, const size_t size, - const char *name) + const char *name, + bool is_iomem) { struct device *dev = rproc->dev.parent; dma_addr_t da; @@ -177,6 +192,8 @@ static int ethosu_add_carveout(struct rproc *rproc, if (!mem) return -ENOMEM; + mem->is_iomem = is_iomem; + dev_dbg(dev, "Add carveout mapping. dma=%pad, da=%x, va=%p, len=%zu", &mem->dma, mem->da, mem->va, mem->len); @@ -200,7 +217,8 @@ static int ethosu_rproc_prepare(struct rproc *rproc) res.start, resource_size(&res)); ret = ethosu_add_carveout(rproc, res.start, - resource_size(&res), res.name); + resource_size(&res), res.name, + !strncmp(res.name, "rom", 3)); if (ret) return ret; } @@ -221,7 +239,7 @@ static int ethosu_rproc_prepare(struct rproc *rproc) res_mem->base, res_mem->size, it.node->name); ret = ethosu_add_carveout(rproc, res_mem->base, res_mem->size, - it.node->name); + it.node->name, false); if (ret) return ret; } -- cgit v1.2.1