blob: e5ea5335e3b44e1b762be0e75fea5cc183eb1d06 [file] [log] [blame]
Sergei Poselenovb4489622007-07-05 08:17:37 +02001/*
2 * (C) Copyright 2007
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * Author: Igor Lisitsin <igor@emcraft.com>
6 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Sergei Poselenovb4489622007-07-05 08:17:37 +02008 */
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 Poselenovb4489622007-07-05 08:17:37 +020018#include <post.h>
19
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020020#if CONFIG_POST & CONFIG_SYS_POST_CACHE
Sergei Poselenovb4489622007-07-05 08:17:37 +020021
22#include <asm/mmu.h>
23#include <watchdog.h>
24
25#define CACHE_POST_SIZE 1024
26
Sergei Poselenovb4489622007-07-05 08:17:37 +020027int cache_post_test1 (int tlb, void *p, int size);
28int cache_post_test2 (int tlb, void *p, int size);
29int cache_post_test3 (int tlb, void *p, int size);
30int cache_post_test4 (int tlb, void *p, int size);
31int cache_post_test5 (int tlb, void *p, int size);
32int cache_post_test6 (int tlb, void *p, int size);
33
Stefan Roeseeb2b4012007-08-14 14:39:44 +020034#ifdef CONFIG_440
Sergei Poselenovb4489622007-07-05 08:17:37 +020035static unsigned char testarea[CACHE_POST_SIZE]
36__attribute__((__aligned__(CACHE_POST_SIZE)));
Stefan Roeseeb2b4012007-08-14 14:39:44 +020037#endif
Sergei Poselenovb4489622007-07-05 08:17:37 +020038
39int cache_post_test (int flags)
40{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020041 void *virt = (void *)CONFIG_SYS_POST_CACHE_ADDR;
Stefan Roeseeb2b4012007-08-14 14:39:44 +020042 int ints;
43 int res = 0;
Stefan Roese2e583d62007-12-26 20:20:19 +010044 int tlb = -1; /* index to the victim TLB entry */
Stefan Roeseeb2b4012007-08-14 14:39:44 +020045
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 Poselenovb4489622007-07-05 08:17:37 +020054
Stefan Roesed9172212007-12-22 12:18:26 +010055 /*
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 Poselenovb4489622007-07-05 08:17:37 +020061
Stefan Roesed9172212007-12-22 12:18:26 +010062 /* 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 Poselenovb4489622007-07-05 08:17:37 +020072 }
73 }
Stefan Roeseeb2b4012007-08-14 14:39:44 +020074#endif
Sergei Poselenovb4489622007-07-05 08:17:37 +020075 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 Roesea2685902007-10-31 20:45:53 +010099#ifdef CONFIG_440
Stefan Roese06713772007-10-23 18:03:12 +0200100 remove_tlb((u32)virt, CACHE_POST_SIZE);
Stefan Roesea2685902007-10-31 20:45:53 +0100101#endif
Stefan Roese6fa397d2007-10-23 14:40:30 +0200102
Sergei Poselenovb4489622007-07-05 08:17:37 +0200103 return res;
104}
105
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200106#endif /* CONFIG_POST & CONFIG_SYS_POST_CACHE */