3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * Author: Igor Lisitsin <igor@emcraft.com>
7 * See file CREDITS for list of people who contributed to this
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 #include <ppc_asm.tmpl>
33 #include <asm/cache.h>
36 #if CONFIG_POST & CFG_POST_CACHE
41 * All 44x variants deal with cache management differently
42 * because they have the address translation always enabled.
43 * The 40x ppc's don't use address translation in U-Boot at all,
44 * so we have to distinguish here between 40x and 44x.
47 /* void cache_post_disable (int tlb)
51 ori r0, r0, TLB_WORD2_I_ENABLE@l
57 /* void cache_post_wt (int tlb)
61 ori r0, r0, TLB_WORD2_W_ENABLE@l
62 andi. r0, r0, ~TLB_WORD2_I_ENABLE@l
68 /* void cache_post_wb (int tlb)
72 andi. r0, r0, ~TLB_WORD2_W_ENABLE@l
73 andi. r0, r0, ~TLB_WORD2_I_ENABLE@l
79 /* void cache_post_disable (int tlb)
89 /* void cache_post_wt (int tlb)
102 /* void cache_post_wb (int tlb)
116 /* void cache_post_dinvalidate (void *p, int size)
118 cache_post_dinvalidate:
120 addi r3, r3, CFG_CACHELINE_SIZE
121 subic. r4, r4, CFG_CACHELINE_SIZE
122 bgt cache_post_dinvalidate
126 /* void cache_post_dstore (void *p, int size)
130 addi r3, r3, CFG_CACHELINE_SIZE
131 subic. r4, r4, CFG_CACHELINE_SIZE
132 bgt cache_post_dstore
136 /* void cache_post_dtouch (void *p, int size)
140 addi r3, r3, CFG_CACHELINE_SIZE
141 subic. r4, r4, CFG_CACHELINE_SIZE
142 bgt cache_post_dtouch
146 /* void cache_post_iinvalidate (void)
148 cache_post_iinvalidate:
153 /* void cache_post_memset (void *p, int val, int size)
163 /* int cache_post_check (void *p, int size)
179 #define CACHE_POST_DISABLE() \
181 bl cache_post_disable
183 #define CACHE_POST_WT() \
187 #define CACHE_POST_WB() \
191 #define CACHE_POST_DINVALIDATE() \
194 bl cache_post_dinvalidate
196 #define CACHE_POST_DFLUSH() \
201 #define CACHE_POST_DSTORE() \
206 #define CACHE_POST_DTOUCH() \
211 #define CACHE_POST_IINVALIDATE() \
212 bl cache_post_iinvalidate
214 #define CACHE_POST_MEMSET(val) \
220 #define CACHE_POST_CHECK() \
223 bl cache_post_check; \
227 * Write and read 0xff pattern with caching enabled.
229 .global cache_post_test1
234 mr r12, r5 /* size */
237 CACHE_POST_DINVALIDATE()
239 /* Write the negative pattern to the test area */
240 CACHE_POST_MEMSET(0xff)
242 /* Read the test area */
245 CACHE_POST_DINVALIDATE()
253 * Write zeroes with caching enabled.
254 * Write 0xff pattern with caching disabled.
255 * Read 0xff pattern with caching enabled.
257 .global cache_post_test2
262 mr r12, r5 /* size */
265 CACHE_POST_DINVALIDATE()
267 /* Write the zero pattern to the test area */
270 CACHE_POST_DINVALIDATE()
273 /* Write the negative pattern to the test area */
274 CACHE_POST_MEMSET(0xff)
278 /* Read the test area */
281 CACHE_POST_DINVALIDATE()
289 * Write-through mode test.
290 * Write zeroes, store the cache, write 0xff pattern.
291 * Invalidate the cache.
292 * Check that 0xff pattern is read.
294 .global cache_post_test3
299 mr r12, r5 /* size */
302 CACHE_POST_DINVALIDATE()
304 /* Cache the test area */
307 /* Write the zero pattern to the test area */
312 /* Write the negative pattern to the test area */
313 CACHE_POST_MEMSET(0xff)
315 CACHE_POST_DINVALIDATE()
318 /* Read the test area */
326 * Write-back mode test.
327 * Write 0xff pattern, store the cache, write zeroes.
328 * Invalidate the cache.
329 * Check that 0xff pattern is read.
331 .global cache_post_test4
336 mr r12, r5 /* size */
339 CACHE_POST_DINVALIDATE()
341 /* Cache the test area */
344 /* Write the negative pattern to the test area */
345 CACHE_POST_MEMSET(0xff)
349 /* Write the zero pattern to the test area */
352 CACHE_POST_DINVALIDATE()
355 /* Read the test area */
363 * Load the test instructions into the instruction cache.
364 * Replace the test instructions.
365 * Check that the original instructions are executed.
367 .global cache_post_test5
372 mr r12, r5 /* size */
375 CACHE_POST_IINVALIDATE()
377 /* Compute r13 = cache_post_test_inst */
378 bl cache_post_test5_reloc
379 cache_post_test5_reloc:
381 lis r0, (cache_post_test_inst - cache_post_test5_reloc)@h
382 ori r0, r0, (cache_post_test_inst - cache_post_test5_reloc)@l
385 /* Copy the test instructions to the test area */
392 /* Invalidate the cache line */
397 /* Execute the test instructions */
401 /* Replace the test instruction */
406 /* Do not invalidate the cache line */
409 /* Execute the test instructions */
414 CACHE_POST_IINVALIDATE()
415 CACHE_POST_DINVALIDATE()
423 * Load the test instructions into the instruction cache.
424 * Replace the test instructions and invalidate the cache.
425 * Check that the replaced instructions are executed.
427 .global cache_post_test6
432 mr r12, r5 /* size */
435 CACHE_POST_IINVALIDATE()
437 /* Compute r13 = cache_post_test_inst */
438 bl cache_post_test6_reloc
439 cache_post_test6_reloc:
441 lis r0, (cache_post_test_inst - cache_post_test6_reloc)@h
442 ori r0, r0, (cache_post_test_inst - cache_post_test6_reloc)@l
445 /* Copy the test instructions to the test area */
452 /* Invalidate the cache line */
457 /* Execute the test instructions */
461 /* Replace the test instruction */
466 /* Invalidate the cache line */
471 /* Execute the test instructions */
476 CACHE_POST_IINVALIDATE()
477 CACHE_POST_DINVALIDATE()
484 /* Test instructions.
486 cache_post_test_inst:
491 #endif /* CONFIG_POST & CFG_POST_CACHE */
492 #endif /* CONFIG_POST */