^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright(c) 2017 IBM Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <asm/cacheflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) static inline void __clean_pmem_range(unsigned long start, unsigned long stop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) unsigned long shift = l1_dcache_shift();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) unsigned long bytes = l1_dcache_bytes();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) void *addr = (void *)(start & ~(bytes - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) unsigned long size = stop - (unsigned long)addr + (bytes - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) unsigned long i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) for (i = 0; i < size >> shift; i++, addr += bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) asm volatile(PPC_DCBSTPS(%0, %1): :"i"(0), "r"(addr): "memory");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static inline void __flush_pmem_range(unsigned long start, unsigned long stop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) unsigned long shift = l1_dcache_shift();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) unsigned long bytes = l1_dcache_bytes();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) void *addr = (void *)(start & ~(bytes - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) unsigned long size = stop - (unsigned long)addr + (bytes - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) unsigned long i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) for (i = 0; i < size >> shift; i++, addr += bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) asm volatile(PPC_DCBFPS(%0, %1): :"i"(0), "r"(addr): "memory");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static inline void clean_pmem_range(unsigned long start, unsigned long stop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) if (cpu_has_feature(CPU_FTR_ARCH_207S))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) return __clean_pmem_range(start, stop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static inline void flush_pmem_range(unsigned long start, unsigned long stop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) if (cpu_has_feature(CPU_FTR_ARCH_207S))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) return __flush_pmem_range(start, stop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * CONFIG_ARCH_HAS_PMEM_API symbols
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) void arch_wb_cache_pmem(void *addr, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) unsigned long start = (unsigned long) addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) clean_pmem_range(start, start + size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) EXPORT_SYMBOL_GPL(arch_wb_cache_pmem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) void arch_invalidate_pmem(void *addr, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) unsigned long start = (unsigned long) addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) flush_pmem_range(start, start + size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) EXPORT_SYMBOL_GPL(arch_invalidate_pmem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE symbols
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) long __copy_from_user_flushcache(void *dest, const void __user *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) unsigned size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) unsigned long copied, start = (unsigned long) dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) copied = __copy_from_user(dest, src, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) clean_pmem_range(start, start + size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) void memcpy_flushcache(void *dest, const void *src, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) unsigned long start = (unsigned long) dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) memcpy(dest, src, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) clean_pmem_range(start, start + size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) EXPORT_SYMBOL(memcpy_flushcache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) void memcpy_page_flushcache(char *to, struct page *page, size_t offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) memcpy_flushcache(to, page_to_virt(page) + offset, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) EXPORT_SYMBOL(memcpy_page_flushcache);