Tizen 2.0 Release
[platform/kernel/u-boot.git] / arch / arm / cpu / armv7 / omap4 / cache.S
1 /*
2  * Copyright (c) 2009 Wind River Systems, Inc.
3  * Tom Rix <Tom.Rix@windriver.com>
4  *
5  * This file is based on and replaces the existing cache.c file
6  * The copyrights for the cache.c file are:
7  *
8  * (C) Copyright 2008 Texas Insturments
9  *
10  * (C) Copyright 2002
11  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
12  * Marius Groeger <mgroeger@sysgo.de>
13  *
14  * (C) Copyright 2002
15  * Gary Jennejohn, DENX Software Engineering, <gj@denx.de>
16  *
17  * See file CREDITS for list of people who contributed to this
18  * project.
19  *
20  * This program is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU General Public License as
22  * published by the Free Software Foundation; either version 2 of
23  * the License, or (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28  * GNU General Public License for more details.
29  *
30  * You should have received a copy of the GNU General Public License
31  * along with this program; if not, write to the Free Software
32  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
33  * MA 02111-1307 USA
34  */
35
36 #include <asm/arch/omap4.h>
37
38 /*
39  * omap4 cache code
40  */
41
42 .align 5
43 .global v7_flush_dcache_all
44 .global v7_flush_cache_all
45
46 /*
47  *      v7_flush_dcache_all()
48  *
49  *      Flush the whole D-cache.
50  *
51  *      Corrupted registers: r0-r7, r9-r11 (r6 only in Thumb mode)
52  *
53  *      - mm    - mm_struct describing address space
54  */
55 v7_flush_dcache_all:
56 #       dmb                                     @ ensure ordering with previous memory accesses
57         mrc     p15, 1, r0, c0, c0, 1           @ read clidr
58         ands    r3, r0, #0x7000000              @ extract loc from clidr
59         mov     r3, r3, lsr #23                 @ left align loc bit field
60         beq     finished                        @ if loc is 0, then no need to clean
61         mov     r10, #0                         @ start clean at cache level 0
62 loop1:
63         add     r2, r10, r10, lsr #1            @ work out 3x current cache level
64         mov     r1, r0, lsr r2                  @ extract cache type bits from clidr
65         and     r1, r1, #7                      @ mask of the bits for current cache only
66         cmp     r1, #2                          @ see what cache we have at this level
67         blt     skip                            @ skip if no cache, or just i-cache
68         mcr     p15, 2, r10, c0, c0, 0          @ select current cache level in cssr
69         mcr     p15, 0, r10, c7, c5, 4          @ flush prefetch buffer,
70                                                 @ with armv7 this is 'isb',
71                                                 @ but we compile with armv5
72         mrc     p15, 1, r1, c0, c0, 0           @ read the new csidr
73         and     r2, r1, #7                      @ extract the length of the cache lines
74         add     r2, r2, #4                      @ add 4 (line length offset)
75         ldr     r4, =0x3ff
76         ands    r4, r4, r1, lsr #3              @ find maximum number on the way size
77         clz     r5, r4                          @ find bit position of way size increment
78         ldr     r7, =0x7fff
79         ands    r7, r7, r1, lsr #13             @ extract max number of the index size
80 loop2:
81         mov     r9, r4                          @ create working copy of max way size
82 loop3:
83         orr     r11, r10, r9, lsl r5            @ factor way and cache number into r11
84         orr     r11, r11, r7, lsl r2            @ factor index number into r11
85         mcr     p15, 0, r11, c7, c14, 2         @ clean & invalidate by set/way
86         subs    r9, r9, #1                      @ decrement the way
87         bge     loop3
88         subs    r7, r7, #1                      @ decrement the index
89         bge     loop2
90 skip:
91         add     r10, r10, #2                    @ increment cache number
92         cmp     r3, r10
93         bgt     loop1
94 finished:
95         mov     r10, #0                         @ swith back to cache level 0
96         mcr     p15, 2, r10, c0, c0, 0          @ select current cache level in cssr
97 #       dsb
98         mcr     p15, 0, r10, c7, c5, 4          @ flush prefetch buffer,
99                                                 @ with armv7 this is 'isb',
100                                                 @ but we compile with armv5
101         mov     pc, lr
102
103 /*
104  *      v7_flush_cache_all()
105  *
106  *      Flush the entire cache system.
107  *  The data cache flush is now achieved using atomic clean / invalidates
108  *  working outwards from L1 cache. This is done using Set/Way based cache
109  *  maintainance instructions.
110  *  The instruction cache can still be invalidated back to the point of
111  *  unification in a single instruction.
112  *
113  */
114 v7_flush_cache_all:
115         stmfd   sp!, {r0-r7, r9-r11, lr}
116         bl      v7_flush_dcache_all
117         mov     r0, #0
118         mcr     p15, 0, r0, c7, c5, 0           @ I+BTB cache invalidate
119         ldmfd   sp!, {r0-r7, r9-r11, lr}
120         mov     pc, lr