1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006,2007 by Greg White
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
24 /* TTB routines not used */
26 /** Cache coherency **/
31 * Write DCache back to RAM for the given range and remove cache lines
32 * from DCache afterwards
33 * void commit_discard_dcache_range(const void *base, unsigned int size);
35 .section .text.commit_discard_dcache_range, "ax", %progbits
37 .global commit_discard_dcache_range
38 .type commit_discard_dcache_range, %function
40 @ MVA format: 31:5 = Modified virtual address, 4:0 = SBZ
41 commit_discard_dcache_range:
42 add r1, r0, r1 @ size -> end
43 cmp r1, r0 @ end <= start?
44 subhi r1, r1, #1 @ round it down
46 mcrrhi p15, 0, r1, r0, c14 @ Clean and invalidate DCache range
47 mcrhi p15, 0, r2, c7, c10, 4 @ Data synchronization barrier
49 .size commit_discard_dcache_range, .-commit_discard_dcache_range
51 #endif /* unused function */
54 * Write DCache back to RAM for the given range
55 * void commit_dcache_range(const void *base, unsigned int size);
57 .section .text.commit_dcache_range, "ax", %progbits
59 .global commit_dcache_range
60 .type commit_dcache_range, %function
62 @ MVA format: 31:5 = Modified virtual address, 4:0 = SBZ
64 add r1, r0, r1 @ size -> end
65 cmp r1, r0 @ end <= start?
66 subhi r1, r1, #1 @ round it down
68 mcrrhi p15, 0, r1, r0, c12 @ Clean DCache range
69 mcrhi p15, 0, r2, c7, c10, 4 @ Data synchronization barrier
71 .size commit_dcache_range, .-commit_dcache_range
74 * Remove cache lines for the given range from DCache
75 * will *NOT* do write back except for buffer edges not on a line boundary
76 * void discard_dcache_range(const void *base, unsigned int size);
78 .section .text.discard_dcache_range, "ax", %progbits
80 .global discard_dcache_range
81 .type discard_dcache_range, %function
83 @ MVA format: 31:5 = Modified virtual address, 4:0 = SBZ
85 add r1, r0, r1 @ size -> end
86 cmp r1, r0 @ end <= start?
88 tst r0, #31 @ Check first line for bits set
89 bicne r0, r0, #31 @ Clear low five bits (down)
90 mcrne p15, 0, r0, c7, c14, 1 @ Clean and invalidate line by MVA
91 @ if not cache aligned
92 addne r0, r0, #32 @ Move to the next cache line
94 tst r1, #31 @ Check last line for bits set
95 bicne r1, r1, #31 @ Clear low five bits (down)
96 mcrne p15, 0, r1, c7, c14, 1 @ Clean and invalidate line by MVA
97 @ if not cache aligned
98 sub r1, r1, #32 @ Move to the previous cache line
99 cmp r1, r0 @ end < start now?
100 mcrrhs p15, 0, r1, r0, c6 @ Invalidate DCache range
102 mcr p15, 0, r0, c7, c10, 4 @ Data synchronization barrier
104 .size discard_dcache_range, .-discard_dcache_range
108 * Write entire DCache back to RAM
109 * void commit_dcache(void);
111 .section .text.commit_dcache, "ax", %progbits
113 .global commit_dcache
114 .type commit_dcache, %function
118 mcr p15, 0, r0, c7, c10, 0 @ Clean entire DCache
119 mcr p15, 0, r0, c7, c10, 4 @ Data synchronization barrier
121 .size commit_dcache, .-commit_dcache
124 * Clean and invalidate entire DCache, will do writeback
125 * void commit_discard_dcache(void);
127 .section .icode.commit_discard_dcache, "ax", %progbits
129 .global commit_discard_dcache
130 .type commit_discard_dcache, %function
132 commit_discard_dcache:
134 mcr p15, 0, r0, c7, c14, 0 @ Clean and invalidate entire DCache
135 mcr p15, 0, r0, c7, c10, 4 @ Data synchronization barrier
137 .size commit_discard_dcache, .-commit_discard_dcache
141 * Discards the entire ICache, and commit+discards the entire DCache
142 * void commit_discard_idcache(void);
144 .section .icode.commit_discard_idcache, "ax", %progbits
146 .global commit_discard_idcache
147 .type commit_discard_idcache, %function
149 commit_discard_idcache:
151 mcr p15, 0, r0, c7, c14, 0 @ Clean and invalidate entire DCache
152 mcr p15, 0, r0, c7, c5, 0 @ Invalidate entire ICache
153 @ Also flushes the branch target cache
154 mcr p15, 0, r0, c7, c10, 4 @ Data synchronization barrier
155 mcr p15, 0, r0, c7, c5, 4 @ Flush prefetch buffer (IMB)
157 .size commit_discard_idcache, .-commit_discard_idcache