Sergei Poselenov | b448962 | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * Author: Igor Lisitsin <igor@emcraft.com> |
| 6 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Sergei Poselenov | b448962 | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | |
| 12 | /* Cache test |
| 13 | * |
| 14 | * This test verifies the CPU data and instruction cache using |
| 15 | * several test scenarios. |
| 16 | */ |
| 17 | |
Sergei Poselenov | b448962 | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 18 | #include <post.h> |
| 19 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 20 | #if CONFIG_POST & CONFIG_SYS_POST_CACHE |
Sergei Poselenov | b448962 | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 21 | |
| 22 | #include <asm/mmu.h> |
| 23 | #include <watchdog.h> |
| 24 | |
| 25 | #define CACHE_POST_SIZE 1024 |
| 26 | |
Sergei Poselenov | b448962 | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 27 | int cache_post_test1 (int tlb, void *p, int size); |
| 28 | int cache_post_test2 (int tlb, void *p, int size); |
| 29 | int cache_post_test3 (int tlb, void *p, int size); |
| 30 | int cache_post_test4 (int tlb, void *p, int size); |
| 31 | int cache_post_test5 (int tlb, void *p, int size); |
| 32 | int cache_post_test6 (int tlb, void *p, int size); |
| 33 | |
Stefan Roese | eb2b401 | 2007-08-14 14:39:44 +0200 | [diff] [blame] | 34 | #ifdef CONFIG_440 |
Sergei Poselenov | b448962 | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 35 | static unsigned char testarea[CACHE_POST_SIZE] |
| 36 | __attribute__((__aligned__(CACHE_POST_SIZE))); |
Stefan Roese | eb2b401 | 2007-08-14 14:39:44 +0200 | [diff] [blame] | 37 | #endif |
Sergei Poselenov | b448962 | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 38 | |
| 39 | int cache_post_test (int flags) |
| 40 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 41 | void *virt = (void *)CONFIG_SYS_POST_CACHE_ADDR; |
Stefan Roese | eb2b401 | 2007-08-14 14:39:44 +0200 | [diff] [blame] | 42 | int ints; |
| 43 | int res = 0; |
Stefan Roese | 2e583d6 | 2007-12-26 20:20:19 +0100 | [diff] [blame] | 44 | int tlb = -1; /* index to the victim TLB entry */ |
Stefan Roese | eb2b401 | 2007-08-14 14:39:44 +0200 | [diff] [blame] | 45 | |
| 46 | /* |
| 47 | * All 44x variants deal with cache management differently |
| 48 | * because they have the address translation always enabled. |
| 49 | * The 40x ppc's don't use address translation in U-Boot at all, |
| 50 | * so we have to distinguish here between 40x and 44x. |
| 51 | */ |
| 52 | #ifdef CONFIG_440 |
| 53 | int word0, i; |
Sergei Poselenov | b448962 | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 54 | |
Stefan Roese | d917221 | 2007-12-22 12:18:26 +0100 | [diff] [blame] | 55 | /* |
| 56 | * Allocate a new TLB entry, since we are going to modify |
| 57 | * the write-through and caching inhibited storage attributes. |
| 58 | */ |
| 59 | program_tlb((u32)testarea, (u32)virt, CACHE_POST_SIZE, |
| 60 | TLB_WORD2_I_ENABLE); |
Sergei Poselenov | b448962 | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 61 | |
Stefan Roese | d917221 | 2007-12-22 12:18:26 +0100 | [diff] [blame] | 62 | /* Find the TLB entry */ |
| 63 | for (i = 0;; i++) { |
| 64 | if (i >= PPC4XX_TLB_SIZE) { |
| 65 | printf ("Failed to program tlb entry\n"); |
| 66 | return -1; |
| 67 | } |
| 68 | word0 = mftlb1(i); |
| 69 | if (TLB_WORD0_EPN_DECODE(word0) == (u32)virt) { |
| 70 | tlb = i; |
| 71 | break; |
Sergei Poselenov | b448962 | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 72 | } |
| 73 | } |
Stefan Roese | eb2b401 | 2007-08-14 14:39:44 +0200 | [diff] [blame] | 74 | #endif |
Sergei Poselenov | b448962 | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 75 | ints = disable_interrupts (); |
| 76 | |
| 77 | WATCHDOG_RESET (); |
| 78 | if (res == 0) |
| 79 | res = cache_post_test1 (tlb, virt, CACHE_POST_SIZE); |
| 80 | WATCHDOG_RESET (); |
| 81 | if (res == 0) |
| 82 | res = cache_post_test2 (tlb, virt, CACHE_POST_SIZE); |
| 83 | WATCHDOG_RESET (); |
| 84 | if (res == 0) |
| 85 | res = cache_post_test3 (tlb, virt, CACHE_POST_SIZE); |
| 86 | WATCHDOG_RESET (); |
| 87 | if (res == 0) |
| 88 | res = cache_post_test4 (tlb, virt, CACHE_POST_SIZE); |
| 89 | WATCHDOG_RESET (); |
| 90 | if (res == 0) |
| 91 | res = cache_post_test5 (tlb, virt, CACHE_POST_SIZE); |
| 92 | WATCHDOG_RESET (); |
| 93 | if (res == 0) |
| 94 | res = cache_post_test6 (tlb, virt, CACHE_POST_SIZE); |
| 95 | |
| 96 | if (ints) |
| 97 | enable_interrupts (); |
| 98 | |
Stefan Roese | a268590 | 2007-10-31 20:45:53 +0100 | [diff] [blame] | 99 | #ifdef CONFIG_440 |
Stefan Roese | 0671377 | 2007-10-23 18:03:12 +0200 | [diff] [blame] | 100 | remove_tlb((u32)virt, CACHE_POST_SIZE); |
Stefan Roese | a268590 | 2007-10-31 20:45:53 +0100 | [diff] [blame] | 101 | #endif |
Stefan Roese | 6fa397d | 2007-10-23 14:40:30 +0200 | [diff] [blame] | 102 | |
Sergei Poselenov | b448962 | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 103 | return res; |
| 104 | } |
| 105 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 106 | #endif /* CONFIG_POST & CONFIG_SYS_POST_CACHE */ |