2 * Copyright (c) 2011-2017 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #include <mach/arm/syscall_sw.h>
25 #include <mach/arm64/asm.h>
26 #include <machine/cpu_capabilities.h>
28 #define MMU_I_CLINE 6 // cache line size as 1<<MMU_I_CLINE (64)
30 /* void sys_icache_invalidate(void *start, size_t length) */
31 .globl _sys_icache_invalidate
33 _sys_icache_invalidate:
34 // see InvalidatePoU_IcacheRegion() in xnu/osfmk/arm64/caches_asm.s
35 cbz x1, 2f // length > 0 ?
36 MOV64 x8, _COMM_PAGE_CPU_CAPABILITIES
38 and x9, x0, #~((1<<MMU_I_CLINE)-1) // cacheline align address
39 and x10, x0, #((1<<MMU_I_CLINE)-1) // extend length by alignment
43 eor x10, x11, x10, lsr #MMU_I_CLINE // compute cacheline counter
46 ic ivau, x9 // invalidate icache line
47 add x9, x9, #1<<MMU_I_CLINE // next cacheline address
48 adds x10, x10, #1 // decrement cacheline counter
51 tbnz w8, kHasICDSBShift, 2f
56 /* void sys_dcache_flush(void *start, size_t length) */
57 .globl _sys_dcache_flush
60 // see FlushPoC_DcacheRegion() in xnu/osfmk/arm64/caches_asm.s
61 dsb ish // noop, we are fully coherent
65 // Above based on output generated by clang from:
66 static void __attribute((used))
67 sys_icache_invalidate(uintptr_t start, size_t length)
70 boolean_t hasICDSB = (*(uint32_t*)(uintptr_t)_COMM_PAGE_CPU_CAPABILITIES) & kHasICDSB;
71 uintptr_t addr = start & ~((1 << MMU_I_CLINE) - 1);
72 length += start & ((1 << MMU_I_CLINE) - 1);
73 size_t count = ((length - 1) >> MMU_I_CLINE) + 1;
74 asm volatile("dsb ish" ::: "memory");
76 asm("ic ivau, %[addr]" :: [addr] "r" (addr) : "memory");
77 addr += (1 << MMU_I_CLINE);
80 asm volatile("dsb ish" ::: "memory");
82 asm volatile("dsb ish" ::: "memory");
83 asm volatile("isb" ::: "memory");
91 and x9, x0, #0xffffffffffffffc0
96 eor x10, x11, x10, lsr #6