David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Microblaze support for cache consistent memory. |
| 4 | * Copyright (C) 2010 Michal Simek <monstr@monstr.eu> |
| 5 | * Copyright (C) 2010 PetaLogix |
| 6 | * Copyright (C) 2005 John Williams <jwilliams@itee.uq.edu.au> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9 | #include <linux/kernel.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10 | #include <linux/string.h> |
| 11 | #include <linux/types.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12 | #include <linux/mm.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13 | #include <linux/init.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14 | #include <linux/dma-noncoherent.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15 | #include <asm/cpuinfo.h> |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 16 | #include <asm/cacheflush.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 17 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 18 | void arch_dma_prep_coherent(struct page *page, size_t size) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 19 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 20 | phys_addr_t paddr = page_to_phys(page); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 21 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 22 | flush_dcache_range(paddr, paddr + size); |
| 23 | } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 24 | |
| 25 | #ifndef CONFIG_MMU |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 26 | /* |
| 27 | * Consistent memory allocators. Used for DMA devices that want to share |
| 28 | * uncached memory with the processor core. My crufty no-MMU approach is |
| 29 | * simple. In the HW platform we can optionally mirror the DDR up above the |
| 30 | * processor cacheable region. So, memory accessed in this mirror region will |
| 31 | * not be cached. It's alloced from the same pool as normal memory, but the |
| 32 | * handle we return is shifted up into the uncached region. This will no doubt |
| 33 | * cause big problems if memory allocated here is not also freed properly. -- JW |
| 34 | * |
| 35 | * I have to use dcache values because I can't relate on ram size: |
| 36 | */ |
| 37 | #ifdef CONFIG_XILINX_UNCACHED_SHADOW |
| 38 | #define UNCACHED_SHADOW_MASK (cpuinfo.dcache_high - cpuinfo.dcache_base + 1) |
| 39 | #else |
| 40 | #define UNCACHED_SHADOW_MASK 0 |
| 41 | #endif /* CONFIG_XILINX_UNCACHED_SHADOW */ |
| 42 | |
| 43 | void *uncached_kernel_address(void *ptr) |
| 44 | { |
| 45 | unsigned long addr = (unsigned long)ptr; |
| 46 | |
| 47 | addr |= UNCACHED_SHADOW_MASK; |
| 48 | if (addr > cpuinfo.dcache_base && addr < cpuinfo.dcache_high) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 49 | pr_warn("ERROR: Your cache coherent area is CACHED!!!\n"); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 50 | return (void *)addr; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 51 | } |
| 52 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 53 | void *cached_kernel_address(void *ptr) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 54 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 55 | unsigned long addr = (unsigned long)ptr; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 56 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 57 | return (void *)(addr & ~UNCACHED_SHADOW_MASK); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 58 | } |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 59 | #endif /* CONFIG_MMU */ |