Thomas Gleixner | 5b497af | 2019-05-29 07:18:09 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Oliver O'Halloran | 32ce386 | 2017-10-19 18:13:54 +1100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright(c) 2017 IBM Corporation. All rights reserved. |
Oliver O'Halloran | 32ce386 | 2017-10-19 18:13:54 +1100 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <linux/string.h> |
| 7 | #include <linux/export.h> |
Oliver O'Halloran | 6c44741 | 2017-10-19 18:13:55 +1100 | [diff] [blame] | 8 | #include <linux/uaccess.h> |
Oliver O'Halloran | 32ce386 | 2017-10-19 18:13:54 +1100 | [diff] [blame] | 9 | |
| 10 | #include <asm/cacheflush.h> |
| 11 | |
| 12 | /* |
| 13 | * CONFIG_ARCH_HAS_PMEM_API symbols |
| 14 | */ |
| 15 | void arch_wb_cache_pmem(void *addr, size_t size) |
| 16 | { |
| 17 | unsigned long start = (unsigned long) addr; |
Christophe Leroy | 1cfb725 | 2019-05-14 09:05:13 +0000 | [diff] [blame] | 18 | flush_dcache_range(start, start + size); |
Oliver O'Halloran | 32ce386 | 2017-10-19 18:13:54 +1100 | [diff] [blame] | 19 | } |
Aneesh Kumar K.V | 551003f | 2019-12-02 12:10:18 +0530 | [diff] [blame] | 20 | EXPORT_SYMBOL_GPL(arch_wb_cache_pmem); |
Oliver O'Halloran | 32ce386 | 2017-10-19 18:13:54 +1100 | [diff] [blame] | 21 | |
| 22 | void arch_invalidate_pmem(void *addr, size_t size) |
| 23 | { |
| 24 | unsigned long start = (unsigned long) addr; |
Christophe Leroy | 1cfb725 | 2019-05-14 09:05:13 +0000 | [diff] [blame] | 25 | flush_dcache_range(start, start + size); |
Oliver O'Halloran | 32ce386 | 2017-10-19 18:13:54 +1100 | [diff] [blame] | 26 | } |
Aneesh Kumar K.V | 551003f | 2019-12-02 12:10:18 +0530 | [diff] [blame] | 27 | EXPORT_SYMBOL_GPL(arch_invalidate_pmem); |
Oliver O'Halloran | 6c44741 | 2017-10-19 18:13:55 +1100 | [diff] [blame] | 28 | |
| 29 | /* |
| 30 | * CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE symbols |
| 31 | */ |
| 32 | long __copy_from_user_flushcache(void *dest, const void __user *src, |
| 33 | unsigned size) |
| 34 | { |
| 35 | unsigned long copied, start = (unsigned long) dest; |
| 36 | |
| 37 | copied = __copy_from_user(dest, src, size); |
Christophe Leroy | 1cfb725 | 2019-05-14 09:05:13 +0000 | [diff] [blame] | 38 | flush_dcache_range(start, start + size); |
Oliver O'Halloran | 6c44741 | 2017-10-19 18:13:55 +1100 | [diff] [blame] | 39 | |
| 40 | return copied; |
| 41 | } |
| 42 | |
| 43 | void *memcpy_flushcache(void *dest, const void *src, size_t size) |
| 44 | { |
| 45 | unsigned long start = (unsigned long) dest; |
| 46 | |
| 47 | memcpy(dest, src, size); |
Christophe Leroy | 1cfb725 | 2019-05-14 09:05:13 +0000 | [diff] [blame] | 48 | flush_dcache_range(start, start + size); |
Oliver O'Halloran | 6c44741 | 2017-10-19 18:13:55 +1100 | [diff] [blame] | 49 | |
| 50 | return dest; |
| 51 | } |
| 52 | EXPORT_SYMBOL(memcpy_flushcache); |
| 53 | |
| 54 | void memcpy_page_flushcache(char *to, struct page *page, size_t offset, |
| 55 | size_t len) |
| 56 | { |
| 57 | memcpy_flushcache(to, page_to_virt(page) + offset, len); |
| 58 | } |
| 59 | EXPORT_SYMBOL(memcpy_page_flushcache); |