blob: 7dfcec4700fef0355372cbf7d4c2f11176c914d6 [file] [log] [blame]
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +00001/*
2 * Based on arch/arm/include/asm/cacheflush.h
3 *
4 * Copyright (C) 1999-2002 Russell King.
5 * Copyright (C) 2012 ARM Ltd.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#ifndef __ASM_CACHEFLUSH_H
20#define __ASM_CACHEFLUSH_H
21
22#include <linux/mm.h>
23
24/*
25 * This flag is used to indicate that the page pointed to by a pte is clean
26 * and does not require cleaning before returning it to the user.
27 */
28#define PG_dcache_clean PG_arch_1
29
30/*
31 * MM Cache Management
32 * ===================
33 *
34 * The arch/arm64/mm/cache.S implements these methods.
35 *
36 * Start addresses are inclusive and end addresses are exclusive; start
37 * addresses should be rounded down, end addresses up.
38 *
39 * See Documentation/cachetlb.txt for more information. Please note that
40 * the implementation assumes non-aliasing VIPT D-cache and (aliasing)
Mark Rutlandf81a3482017-11-21 11:59:13 +000041 * VIPT I-cache.
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +000042 *
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +000043 * flush_cache_mm(mm)
44 *
45 * Clean and invalidate all user space cache entries
46 * before a change of page tables.
47 *
48 * flush_icache_range(start, end)
49 *
50 * Ensure coherency between the I-cache and the D-cache in the
51 * region described by start, end.
52 * - start - virtual start address
53 * - end - virtual end address
54 *
Marc Zyngier4fee9472017-10-23 17:11:16 +010055 * invalidate_icache_range(start, end)
56 *
57 * Invalidate the I-cache in the region described by start, end.
58 * - start - virtual start address
59 * - end - virtual end address
60 *
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +000061 * __flush_cache_user_range(start, end)
62 *
63 * Ensure coherency between the I-cache and the D-cache in the
64 * region described by start, end.
65 * - start - virtual start address
66 * - end - virtual end address
67 *
68 * __flush_dcache_area(kaddr, size)
69 *
70 * Ensure that the data held in page is written back.
71 * - kaddr - page address
72 * - size - region size
73 */
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +000074extern void flush_icache_range(unsigned long start, unsigned long end);
Marc Zyngier4fee9472017-10-23 17:11:16 +010075extern int invalidate_icache_range(unsigned long start, unsigned long end);
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +000076extern void __flush_dcache_area(void *addr, size_t len);
Robin Murphyd46befe2017-07-25 11:55:39 +010077extern void __inval_dcache_area(void *addr, size_t len);
Kwangwoo Leed34fdb72016-08-02 09:50:50 +090078extern void __clean_dcache_area_poc(void *addr, size_t len);
Robin Murphyd50e0712017-07-25 11:55:42 +010079extern void __clean_dcache_area_pop(void *addr, size_t len);
Ashok Kumar0a287142015-12-17 01:38:32 -080080extern void __clean_dcache_area_pou(void *addr, size_t len);
Vladimir Murzina2d25a52014-12-01 10:53:08 +000081extern long __flush_cache_user_range(unsigned long start, unsigned long end);
Pratyush Anand9842cea2016-11-02 14:40:46 +053082extern void sync_icache_aliases(void *kaddr, unsigned long len);
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +000083
Catalin Marinas8f3bfa52012-11-23 18:15:32 +000084static inline void flush_cache_mm(struct mm_struct *mm)
85{
86}
87
88static inline void flush_cache_page(struct vm_area_struct *vma,
89 unsigned long user_addr, unsigned long pfn)
90{
91}
92
Catalin Marinasee6a7fc2016-11-23 18:05:52 +000093static inline void flush_cache_range(struct vm_area_struct *vma,
94 unsigned long start, unsigned long end)
95{
96}
97
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +000098/*
Catalin Marinas73635902013-05-21 17:35:19 +010099 * Cache maintenance functions used by the DMA API. No to be used directly.
100 */
101extern void __dma_map_area(const void *, size_t, int);
102extern void __dma_unmap_area(const void *, size_t, int);
Kwangwoo Leed34fdb72016-08-02 09:50:50 +0900103extern void __dma_flush_area(const void *, size_t);
Catalin Marinas73635902013-05-21 17:35:19 +0100104
105/*
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +0000106 * Copy user data from/to a page which is mapped into a different
107 * processes address space. Really, we want to allow our "user
108 * space" model to handle this.
109 */
110extern void copy_to_user_page(struct vm_area_struct *, struct page *,
111 unsigned long, void *, const void *, unsigned long);
112#define copy_from_user_page(vma, page, vaddr, dst, src, len) \
113 do { \
114 memcpy(dst, src, len); \
115 } while (0)
116
117#define flush_cache_dup_mm(mm) flush_cache_mm(mm)
118
119/*
120 * flush_dcache_page is used when the kernel has written to the page
121 * cache page at virtual address page->virtual.
122 *
123 * If this page isn't mapped (ie, page_mapping == NULL), or it might
124 * have userspace mappings, then we _must_ always clean + invalidate
125 * the dcache entries associated with the kernel mapping.
126 *
127 * Otherwise we can defer the operation, and clean the cache when we are
128 * about to change to user space. This is the same method as used on SPARC64.
129 * See update_mmu_cache for the user space part.
130 */
131#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
132extern void flush_dcache_page(struct page *);
133
134static inline void __flush_icache_all(void)
135{
Shanker Donthineni6ae4b6e2018-03-07 09:00:08 -0600136 if (cpus_have_const_cap(ARM64_HAS_CACHE_DIC))
137 return;
138
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +0000139 asm("ic ialluis");
Will Deacon98f76852014-05-02 16:24:10 +0100140 dsb(ish);
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +0000141}
142
143#define flush_dcache_mmap_lock(mapping) \
144 spin_lock_irq(&(mapping)->tree_lock)
145#define flush_dcache_mmap_unlock(mapping) \
146 spin_unlock_irq(&(mapping)->tree_lock)
147
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +0000148/*
149 * We don't appear to need to do anything here. In fact, if we did, we'd
150 * duplicate cache flushing elsewhere performed by flush_dcache_page().
151 */
152#define flush_icache_page(vma,page) do { } while (0)
153
154/*
Catalin Marinas7f0b1bf2014-06-09 11:55:03 +0100155 * Not required on AArch64 (PIPT or VIPT non-aliasing D-cache).
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +0000156 */
157static inline void flush_cache_vmap(unsigned long start, unsigned long end)
158{
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +0000159}
160
161static inline void flush_cache_vunmap(unsigned long start, unsigned long end)
162{
163}
164
Robin Murphy09c2a7d2017-07-25 11:55:38 +0100165int set_memory_valid(unsigned long addr, int numpages, int enable);
Laura Abbottda141702015-01-21 17:36:06 -0800166
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +0000167#endif