blob: 02f66f9087d176a97d4855a023b096e57e6ba371 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simek76316a32007-03-11 13:42:58 +01002/*
3 * (C) Copyright 2007 Michal Simek
4 *
Michal Simekdb14d772007-09-24 00:18:46 +02005 * Michal SIMEK <monstr@monstr.eu>
Michal Simek76316a32007-03-11 13:42:58 +01006 */
7
8#include <common.h>
Simon Glass9edefc22019-11-14 12:57:37 -07009#include <cpu_func.h>
Michal Simekfb05f6d2007-05-07 23:58:31 +020010#include <asm/asm.h>
Michal Simek76316a32007-03-11 13:42:58 +010011
Simon Glass6cc915b2019-11-14 12:57:36 -070012int dcache_status(void)
Michal Simek76316a32007-03-11 13:42:58 +010013{
14 int i = 0;
15 int mask = 0x80;
16 __asm__ __volatile__ ("mfs %0,rmsr"::"r" (i):"memory");
17 /* i&=0x80 */
18 __asm__ __volatile__ ("and %0,%0,%1"::"r" (i), "r" (mask):"memory");
19 return i;
20}
21
Simon Glass6cc915b2019-11-14 12:57:36 -070022int icache_status(void)
Michal Simek76316a32007-03-11 13:42:58 +010023{
24 int i = 0;
25 int mask = 0x20;
26 __asm__ __volatile__ ("mfs %0,rmsr"::"r" (i):"memory");
27 /* i&=0x20 */
28 __asm__ __volatile__ ("and %0,%0,%1"::"r" (i), "r" (mask):"memory");
29 return i;
30}
Michal Simekf3f001a2007-05-07 19:25:08 +020031
Simon Glass6cc915b2019-11-14 12:57:36 -070032void icache_enable(void)
33{
Michal Simekfb05f6d2007-05-07 23:58:31 +020034 MSRSET(0x20);
Michal Simekf3f001a2007-05-07 19:25:08 +020035}
36
Simon Glass6cc915b2019-11-14 12:57:36 -070037void icache_disable(void)
38{
Michal Simek8ff972c2010-04-16 12:56:33 +020039 /* we are not generate ICACHE size -> flush whole cache */
40 flush_cache(0, 32768);
Michal Simekfb05f6d2007-05-07 23:58:31 +020041 MSRCLR(0x20);
Michal Simekf3f001a2007-05-07 19:25:08 +020042}
43
Simon Glass6cc915b2019-11-14 12:57:36 -070044void dcache_enable(void)
45{
Michal Simekfb05f6d2007-05-07 23:58:31 +020046 MSRSET(0x80);
Michal Simekf3f001a2007-05-07 19:25:08 +020047}
48
Simon Glass6cc915b2019-11-14 12:57:36 -070049void dcache_disable(void)
50{
Michal Simek8ff972c2010-04-16 12:56:33 +020051#ifdef XILINX_USE_DCACHE
Michal Simek8ff972c2010-04-16 12:56:33 +020052 flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
Michal Simek8ff972c2010-04-16 12:56:33 +020053#endif
Michal Simekfb05f6d2007-05-07 23:58:31 +020054 MSRCLR(0x80);
Michal Simekf3f001a2007-05-07 19:25:08 +020055}
Michal Simek8ff972c2010-04-16 12:56:33 +020056
Simon Glass6cc915b2019-11-14 12:57:36 -070057void flush_cache(ulong addr, ulong size)
Michal Simek8ff972c2010-04-16 12:56:33 +020058{
59 int i;
60 for (i = 0; i < size; i += 4)
61 asm volatile (
62#ifdef CONFIG_ICACHE
63 "wic %0, r0;"
64#endif
65 "nop;"
66#ifdef CONFIG_DCACHE
67 "wdc.flush %0, r0;"
68#endif
69 "nop;"
70 :
71 : "r" (addr + i)
72 : "memory");
73}