From b5117dbfc62ebdcb07036d52bd7227801f6f5aa1 Mon Sep 17 00:00:00 2001 From: Denis Orlov Date: Mon, 13 Mar 2023 13:53:07 +0300 Subject: MIPS: dma-default: use virtual addresses when flushing caches Cache flushing functions expect virtual addresses, so make sure those are properly converted from the physical ones in dma_sync_single_for_*. QEMU doesn't care as it ignores cache instructions, but without such change this code would result in TLB exceptions on real hardware. Signed-off-by: Denis Orlov Link: https://lore.barebox.org/20230313105308.3108127-3-denorl2009@gmail.com Signed-off-by: Sascha Hauer --- arch/mips/lib/dma-default.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'arch/mips') diff --git a/arch/mips/lib/dma-default.c b/arch/mips/lib/dma-default.c index 48176e5d28..f6c750b8ac 100644 --- a/arch/mips/lib/dma-default.c +++ b/arch/mips/lib/dma-default.c @@ -30,11 +30,15 @@ static inline void __dma_sync_mips(unsigned long addr, size_t size, void dma_sync_single_for_cpu(dma_addr_t address, size_t size, enum dma_data_direction dir) { - __dma_sync_mips(address, size, dir); + unsigned long virt = (unsigned long)phys_to_virt(address); + + __dma_sync_mips(virt, size, dir); } void dma_sync_single_for_device(dma_addr_t address, size_t size, enum dma_data_direction dir) { - __dma_sync_mips(address, size, dir); + unsigned long virt = (unsigned long)phys_to_virt(address); + + __dma_sync_mips(virt, size, dir); } -- cgit v1.2.3 From 26c785d000810fc048e4a57d8366e218f1f6ea1a Mon Sep 17 00:00:00 2001 From: Denis Orlov Date: Mon, 13 Mar 2023 13:53:08 +0300 Subject: MIPS: dma-default: do not flush caches in dma_sync_single_* excessively Change the logic to be different depending on whether we are doing synchronization for a cpu or a device. This gets rid of unnecessary cache flushing in some cases. While at it, also simplify code a bit, collapsing two cases with the same code in a switch statement in dma_sync_single_for_device(). The functional change itself is taken from Linux commit 'MIPS: make dma_sync_*_for_cpu a little less overzealous' (hash: cbf1449ba5aec9cf4c68b69f899391a8d42e9b8f). Signed-off-by: Denis Orlov Link: https://lore.barebox.org/20230313105308.3108127-4-denorl2009@gmail.com Signed-off-by: Sascha Hauer --- arch/mips/lib/dma-default.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'arch/mips') diff --git a/arch/mips/lib/dma-default.c b/arch/mips/lib/dma-default.c index f6c750b8ac..0347d7a7db 100644 --- a/arch/mips/lib/dma-default.c +++ b/arch/mips/lib/dma-default.c @@ -6,39 +6,37 @@ #include #include -static inline void __dma_sync_mips(unsigned long addr, size_t size, - enum dma_data_direction direction) +void dma_sync_single_for_cpu(dma_addr_t address, size_t size, + enum dma_data_direction dir) { - switch (direction) { + unsigned long virt = (unsigned long)phys_to_virt(address); + + switch (dir) { case DMA_TO_DEVICE: - dma_flush_range(addr, addr + size); break; - case DMA_FROM_DEVICE: - dma_inv_range(addr, addr + size); - break; - case DMA_BIDIRECTIONAL: - dma_flush_range(addr, addr + size); + dma_inv_range(virt, virt + size); break; - default: BUG(); } } -void dma_sync_single_for_cpu(dma_addr_t address, size_t size, - enum dma_data_direction dir) -{ - unsigned long virt = (unsigned long)phys_to_virt(address); - - __dma_sync_mips(virt, size, dir); -} - void dma_sync_single_for_device(dma_addr_t address, size_t size, enum dma_data_direction dir) { unsigned long virt = (unsigned long)phys_to_virt(address); - __dma_sync_mips(virt, size, dir); + switch (dir) { + case DMA_FROM_DEVICE: + dma_inv_range(virt, virt + size); + break; + case DMA_TO_DEVICE: + case DMA_BIDIRECTIONAL: + dma_flush_range(virt, virt + size); + break; + default: + BUG(); + } } -- cgit v1.2.3 From 2706e8921a87fbdef2643810dfead0a5f3c12718 Mon Sep 17 00:00:00 2001 From: Denis Orlov Date: Wed, 15 Mar 2023 11:59:51 +0300 Subject: MIPS: bootm: do not free fdt pointer that contains an error Also add a proper error message. Signed-off-by: Denis Orlov Link: https://lore.barebox.org/20230315085953.4094660-2-denorl2009@gmail.com Signed-off-by: Sascha Hauer --- arch/mips/lib/bootm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'arch/mips') diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index 655535737e..95e9dc0d7d 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -57,8 +57,8 @@ static int do_bootm_elf(struct image_data *data) fdt = bootm_get_devicetree(data); if (IS_ERR(fdt)) { - ret = PTR_ERR(fdt); - goto bootm_free_fdt; + pr_err("Failed to load dtb\n"); + return PTR_ERR(fdt); } pr_info("Starting application at 0x%08lx, dts 0x%08lx...\n", -- cgit v1.2.3 From 2158810cc8c6524d5d95fe93e802277b81b862d3 Mon Sep 17 00:00:00 2001 From: Denis Orlov Date: Wed, 15 Mar 2023 11:59:52 +0300 Subject: MIPS: bootm: do not leak memory on error in of_overlay_load_firmware() Signed-off-by: Denis Orlov Link: https://lore.barebox.org/20230315085953.4094660-3-denorl2009@gmail.com Signed-off-by: Sascha Hauer --- arch/mips/lib/bootm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arch/mips') diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index 95e9dc0d7d..69ce9b3904 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -69,7 +69,7 @@ static int do_bootm_elf(struct image_data *data) ret = of_overlay_load_firmware(); if (ret) - return ret; + goto bootm_free_fdt; shutdown_barebox(); -- cgit v1.2.3 From 840cbe82579563346ee9097524123c17818fbf60 Mon Sep 17 00:00:00 2001 From: Denis Orlov Date: Wed, 15 Mar 2023 11:59:53 +0300 Subject: MIPS: bootm: remove unnecessary phys/virt conversions They are not doing anything there - we should already have proper virtual addresses represented by those pointers. Signed-off-by: Denis Orlov Link: https://lore.barebox.org/20230315085953.4094660-4-denorl2009@gmail.com Signed-off-by: Sascha Hauer --- arch/mips/lib/bootm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'arch/mips') diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index 69ce9b3904..19d82ec375 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -62,7 +62,7 @@ static int do_bootm_elf(struct image_data *data) } pr_info("Starting application at 0x%08lx, dts 0x%08lx...\n", - phys_to_virt(data->os_address), data->of_root_node); + data->os_address, data->of_root_node); if (data->dryrun) goto bootm_free_fdt; @@ -75,7 +75,7 @@ static int do_bootm_elf(struct image_data *data) entry = (void *) (unsigned long) data->os_address; - entry(-2, phys_to_virt((unsigned long)fdt)); + entry(-2, fdt); pr_err("ELF application terminated\n"); ret = -EINVAL; -- cgit v1.2.3