Path: blob/master/arch/arm/include/asm/cacheflush.h
17302 views
/*1* arch/arm/include/asm/cacheflush.h2*3* Copyright (C) 1999-2002 Russell King4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License version 2 as7* published by the Free Software Foundation.8*/9#ifndef _ASMARM_CACHEFLUSH_H10#define _ASMARM_CACHEFLUSH_H1112#include <linux/mm.h>1314#include <asm/glue-cache.h>15#include <asm/shmparam.h>16#include <asm/cachetype.h>17#include <asm/outercache.h>1819#define CACHE_COLOUR(vaddr) ((vaddr & (SHMLBA - 1)) >> PAGE_SHIFT)2021/*22* This flag is used to indicate that the page pointed to by a pte is clean23* and does not require cleaning before returning it to the user.24*/25#define PG_dcache_clean PG_arch_12627/*28* MM Cache Management29* ===================30*31* The arch/arm/mm/cache-*.S and arch/arm/mm/proc-*.S files32* implement these methods.33*34* Start addresses are inclusive and end addresses are exclusive;35* start addresses should be rounded down, end addresses up.36*37* See Documentation/cachetlb.txt for more information.38* Please note that the implementation of these, and the required39* effects are cache-type (VIVT/VIPT/PIPT) specific.40*41* flush_icache_all()42*43* Unconditionally clean and invalidate the entire icache.44* Currently only needed for cache-v6.S and cache-v7.S, see45* __flush_icache_all for the generic implementation.46*47* flush_kern_all()48*49* Unconditionally clean and invalidate the entire cache.50*51* flush_user_all()52*53* Clean and invalidate all user space cache entries54* before a change of page tables.55*56* flush_user_range(start, end, flags)57*58* Clean and invalidate a range of cache entries in the59* specified address space before a change of page tables.60* - start - user start address (inclusive, page aligned)61* - end - user end address (exclusive, page aligned)62* - flags - vma->vm_flags field63*64* coherent_kern_range(start, end)65*66* Ensure coherency between the Icache and the Dcache in the67* region described by start, end. If you have non-snooping68* Harvard caches, you need to implement this function.69* - start - virtual start address70* - end - virtual end address71*72* coherent_user_range(start, end)73*74* Ensure coherency between the Icache and the Dcache in the75* region described by start, end. If you have non-snooping76* Harvard caches, you need to implement this function.77* - start - virtual start address78* - end - virtual end address79*80* flush_kern_dcache_area(kaddr, size)81*82* Ensure that the data held in page is written back.83* - kaddr - page address84* - size - region size85*86* DMA Cache Coherency87* ===================88*89* dma_flush_range(start, end)90*91* Clean and invalidate the specified virtual address range.92* - start - virtual start address93* - end - virtual end address94*/9596struct cpu_cache_fns {97void (*flush_icache_all)(void);98void (*flush_kern_all)(void);99void (*flush_user_all)(void);100void (*flush_user_range)(unsigned long, unsigned long, unsigned int);101102void (*coherent_kern_range)(unsigned long, unsigned long);103void (*coherent_user_range)(unsigned long, unsigned long);104void (*flush_kern_dcache_area)(void *, size_t);105106void (*dma_map_area)(const void *, size_t, int);107void (*dma_unmap_area)(const void *, size_t, int);108109void (*dma_flush_range)(const void *, const void *);110};111112/*113* Select the calling method114*/115#ifdef MULTI_CACHE116117extern struct cpu_cache_fns cpu_cache;118119#define __cpuc_flush_icache_all cpu_cache.flush_icache_all120#define __cpuc_flush_kern_all cpu_cache.flush_kern_all121#define __cpuc_flush_user_all cpu_cache.flush_user_all122#define __cpuc_flush_user_range cpu_cache.flush_user_range123#define __cpuc_coherent_kern_range cpu_cache.coherent_kern_range124#define __cpuc_coherent_user_range cpu_cache.coherent_user_range125#define __cpuc_flush_dcache_area cpu_cache.flush_kern_dcache_area126127/*128* These are private to the dma-mapping API. Do not use directly.129* Their sole purpose is to ensure that data held in the cache130* is visible to DMA, or data written by DMA to system memory is131* visible to the CPU.132*/133#define dmac_map_area cpu_cache.dma_map_area134#define dmac_unmap_area cpu_cache.dma_unmap_area135#define dmac_flush_range cpu_cache.dma_flush_range136137#else138139extern void __cpuc_flush_icache_all(void);140extern void __cpuc_flush_kern_all(void);141extern void __cpuc_flush_user_all(void);142extern void __cpuc_flush_user_range(unsigned long, unsigned long, unsigned int);143extern void __cpuc_coherent_kern_range(unsigned long, unsigned long);144extern void __cpuc_coherent_user_range(unsigned long, unsigned long);145extern void __cpuc_flush_dcache_area(void *, size_t);146147/*148* These are private to the dma-mapping API. Do not use directly.149* Their sole purpose is to ensure that data held in the cache150* is visible to DMA, or data written by DMA to system memory is151* visible to the CPU.152*/153extern void dmac_map_area(const void *, size_t, int);154extern void dmac_unmap_area(const void *, size_t, int);155extern void dmac_flush_range(const void *, const void *);156157#endif158159/*160* Copy user data from/to a page which is mapped into a different161* processes address space. Really, we want to allow our "user162* space" model to handle this.163*/164extern void copy_to_user_page(struct vm_area_struct *, struct page *,165unsigned long, void *, const void *, unsigned long);166#define copy_from_user_page(vma, page, vaddr, dst, src, len) \167do { \168memcpy(dst, src, len); \169} while (0)170171/*172* Convert calls to our calling convention.173*/174175/* Invalidate I-cache */176#define __flush_icache_all_generic() \177asm("mcr p15, 0, %0, c7, c5, 0" \178: : "r" (0));179180/* Invalidate I-cache inner shareable */181#define __flush_icache_all_v7_smp() \182asm("mcr p15, 0, %0, c7, c1, 0" \183: : "r" (0));184185/*186* Optimized __flush_icache_all for the common cases. Note that UP ARMv7187* will fall through to use __flush_icache_all_generic.188*/189#if (defined(CONFIG_CPU_V7) && \190(defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_V6K))) || \191defined(CONFIG_SMP_ON_UP)192#define __flush_icache_preferred __cpuc_flush_icache_all193#elif __LINUX_ARM_ARCH__ >= 7 && defined(CONFIG_SMP)194#define __flush_icache_preferred __flush_icache_all_v7_smp195#elif __LINUX_ARM_ARCH__ == 6 && defined(CONFIG_ARM_ERRATA_411920)196#define __flush_icache_preferred __cpuc_flush_icache_all197#else198#define __flush_icache_preferred __flush_icache_all_generic199#endif200201static inline void __flush_icache_all(void)202{203__flush_icache_preferred();204}205206#define flush_cache_all() __cpuc_flush_kern_all()207208static inline void vivt_flush_cache_mm(struct mm_struct *mm)209{210if (cpumask_test_cpu(smp_processor_id(), mm_cpumask(mm)))211__cpuc_flush_user_all();212}213214static inline void215vivt_flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)216{217if (cpumask_test_cpu(smp_processor_id(), mm_cpumask(vma->vm_mm)))218__cpuc_flush_user_range(start & PAGE_MASK, PAGE_ALIGN(end),219vma->vm_flags);220}221222static inline void223vivt_flush_cache_page(struct vm_area_struct *vma, unsigned long user_addr, unsigned long pfn)224{225if (cpumask_test_cpu(smp_processor_id(), mm_cpumask(vma->vm_mm))) {226unsigned long addr = user_addr & PAGE_MASK;227__cpuc_flush_user_range(addr, addr + PAGE_SIZE, vma->vm_flags);228}229}230231#ifndef CONFIG_CPU_CACHE_VIPT232#define flush_cache_mm(mm) \233vivt_flush_cache_mm(mm)234#define flush_cache_range(vma,start,end) \235vivt_flush_cache_range(vma,start,end)236#define flush_cache_page(vma,addr,pfn) \237vivt_flush_cache_page(vma,addr,pfn)238#else239extern void flush_cache_mm(struct mm_struct *mm);240extern void flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);241extern void flush_cache_page(struct vm_area_struct *vma, unsigned long user_addr, unsigned long pfn);242#endif243244#define flush_cache_dup_mm(mm) flush_cache_mm(mm)245246/*247* flush_cache_user_range is used when we want to ensure that the248* Harvard caches are synchronised for the user space address range.249* This is used for the ARM private sys_cacheflush system call.250*/251#define flush_cache_user_range(vma,start,end) \252__cpuc_coherent_user_range((start) & PAGE_MASK, PAGE_ALIGN(end))253254/*255* Perform necessary cache operations to ensure that data previously256* stored within this range of addresses can be executed by the CPU.257*/258#define flush_icache_range(s,e) __cpuc_coherent_kern_range(s,e)259260/*261* Perform necessary cache operations to ensure that the TLB will262* see data written in the specified area.263*/264#define clean_dcache_area(start,size) cpu_dcache_clean_area(start, size)265266/*267* flush_dcache_page is used when the kernel has written to the page268* cache page at virtual address page->virtual.269*270* If this page isn't mapped (ie, page_mapping == NULL), or it might271* have userspace mappings, then we _must_ always clean + invalidate272* the dcache entries associated with the kernel mapping.273*274* Otherwise we can defer the operation, and clean the cache when we are275* about to change to user space. This is the same method as used on SPARC64.276* See update_mmu_cache for the user space part.277*/278#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1279extern void flush_dcache_page(struct page *);280281static inline void flush_kernel_vmap_range(void *addr, int size)282{283if ((cache_is_vivt() || cache_is_vipt_aliasing()))284__cpuc_flush_dcache_area(addr, (size_t)size);285}286static inline void invalidate_kernel_vmap_range(void *addr, int size)287{288if ((cache_is_vivt() || cache_is_vipt_aliasing()))289__cpuc_flush_dcache_area(addr, (size_t)size);290}291292#define ARCH_HAS_FLUSH_ANON_PAGE293static inline void flush_anon_page(struct vm_area_struct *vma,294struct page *page, unsigned long vmaddr)295{296extern void __flush_anon_page(struct vm_area_struct *vma,297struct page *, unsigned long);298if (PageAnon(page))299__flush_anon_page(vma, page, vmaddr);300}301302#define ARCH_HAS_FLUSH_KERNEL_DCACHE_PAGE303static inline void flush_kernel_dcache_page(struct page *page)304{305}306307#define flush_dcache_mmap_lock(mapping) \308spin_lock_irq(&(mapping)->tree_lock)309#define flush_dcache_mmap_unlock(mapping) \310spin_unlock_irq(&(mapping)->tree_lock)311312#define flush_icache_user_range(vma,page,addr,len) \313flush_dcache_page(page)314315/*316* We don't appear to need to do anything here. In fact, if we did, we'd317* duplicate cache flushing elsewhere performed by flush_dcache_page().318*/319#define flush_icache_page(vma,page) do { } while (0)320321/*322* flush_cache_vmap() is used when creating mappings (eg, via vmap,323* vmalloc, ioremap etc) in kernel space for pages. On non-VIPT324* caches, since the direct-mappings of these pages may contain cached325* data, we need to do a full cache flush to ensure that writebacks326* don't corrupt data placed into these pages via the new mappings.327*/328static inline void flush_cache_vmap(unsigned long start, unsigned long end)329{330if (!cache_is_vipt_nonaliasing())331flush_cache_all();332else333/*334* set_pte_at() called from vmap_pte_range() does not335* have a DSB after cleaning the cache line.336*/337dsb();338}339340static inline void flush_cache_vunmap(unsigned long start, unsigned long end)341{342if (!cache_is_vipt_nonaliasing())343flush_cache_all();344}345346#endif347348349