2 * Copyright (c) 2009 Wind River Systems, Inc.
3 * Tom Rix <Tom.Rix@windriver.com>
5 * This file is based on and replaces the existing cache.c file
6 * The copyrights for the cache.c file are:
8 * (C) Copyright 2008 Texas Insturments
11 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
12 * Marius Groeger <mgroeger@sysgo.de>
15 * Gary Jennejohn, DENX Software Engineering, <gj@denx.de>
17 * See file CREDITS for list of people who contributed to this
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.
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.
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,
36 #include <asm/arch/omap4.h>
43 .global v7_flush_dcache_all
44 .global v7_flush_cache_all
47 * v7_flush_dcache_all()
49 * Flush the whole D-cache.
51 * Corrupted registers: r0-r7, r9-r11 (r6 only in Thumb mode)
53 * - mm - mm_struct describing address space
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
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)
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
79 ands r7, r7, r1, lsr #13 @ extract max number of the index size
81 mov r9, r4 @ create working copy of max way size
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
88 subs r7, r7, #1 @ decrement the index
91 add r10, r10, #2 @ increment cache number
95 mov r10, #0 @ swith back to cache level 0
96 mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
98 mcr p15, 0, r10, c7, c5, 4 @ flush prefetch buffer,
99 @ with armv7 this is 'isb',
100 @ but we compile with armv5
104 * v7_flush_cache_all()
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.
115 stmfd sp!, {r0-r7, r9-r11, lr}
116 bl v7_flush_dcache_all
118 mcr p15, 0, r0, c7, c5, 0 @ I+BTB cache invalidate
119 ldmfd sp!, {r0-r7, r9-r11, lr}