]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm/arm/cpufunc_asm_armv7.S
Import CK as of commit b19ed4c6a56ec93215ab567ba18ba61bf1cfbac8
[FreeBSD/FreeBSD.git] / sys / arm / arm / cpufunc_asm_armv7.S
1 /*-
2  * Copyright (c) 2010 Per Odlund <per.odlund@armagedon.se>
3  * Copyright (C) 2011 MARVELL INTERNATIONAL LTD.
4  * All rights reserved.
5  *
6  * Developed by Semihalf.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of MARVELL nor the names of contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32
33 #include <machine/asm.h>
34 __FBSDID("$FreeBSD$");
35
36 #include <machine/sysreg.h>
37
38         .cpu cortex-a8
39
40 #ifdef ELF_TRAMPOLINE
41 .Lcoherency_level:
42         .word   _C_LABEL(arm_cache_loc)
43 .Lcache_type:
44         .word   _C_LABEL(arm_cache_type)
45 .Lway_mask:
46         .word   0x3ff
47 .Lmax_index:
48         .word   0x7fff
49
50 /* Based on algorithm from ARM Architecture Reference Manual */
51 ENTRY(armv7_dcache_wbinv_all)
52         stmdb   sp!, {r4, r5, r6, r7, r8, r9}
53
54         /* Get cache level */
55         ldr     r0, .Lcoherency_level
56         ldr     r3, [r0]
57         cmp     r3, #0
58         beq     Finished
59         /* For each cache level */
60         mov     r8, #0
61 Loop1:
62         /* Get cache type for given level */
63         mov     r2, r8, lsl #2
64         add     r2, r2, r2
65         ldr     r0, .Lcache_type
66         ldr     r1, [r0, r2]
67
68         /* Get line size */
69         and     r2, r1, #7
70         add     r2, r2, #4
71
72         /* Get number of ways */
73         ldr     r4, .Lway_mask
74         ands    r4, r4, r1, lsr #3
75         clz     r5, r4
76
77         /* Get max index */
78         ldr     r7, .Lmax_index
79         ands    r7, r7, r1, lsr #13
80 Loop2:
81         mov     r9, r4
82 Loop3:
83         mov     r6, r8, lsl #1
84         orr     r6, r6, r9, lsl r5
85         orr     r6, r6, r7, lsl r2
86
87         /* Clean and invalidate data cache by way/index */
88         mcr     CP15_DCCISW(r6)
89         subs    r9, r9, #1
90         bge     Loop3
91         subs    r7, r7, #1
92         bge     Loop2
93 Skip:
94         add     r8, r8, #1
95         cmp     r3, r8
96         bne Loop1
97 Finished:
98         dsb
99         ldmia   sp!, {r4, r5, r6, r7, r8, r9}
100         RET
101 END(armv7_dcache_wbinv_all)
102
103 ENTRY(armv7_idcache_wbinv_all)
104         stmdb   sp!, {lr}
105         bl armv7_dcache_wbinv_all
106 #ifdef SMP
107         mcr     CP15_ICIALLUIS
108 #else
109         mcr     CP15_ICIALLU
110 #endif
111         dsb
112         isb
113         ldmia   sp!, {lr}
114         RET
115 END(armv7_idcache_wbinv_all)
116 #endif
117
118 ENTRY(armv7_cpu_sleep)
119         dsb                             /* data synchronization barrier */
120         wfi                             /* wait for interrupt */
121         RET
122 END(armv7_cpu_sleep)
123
124 ENTRY(armv7_drain_writebuf)
125         dsb
126         RET
127 END(armv7_drain_writebuf)