blob: 02f66f9087d176a97d4855a023b096e57e6ba371 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simek952d5142007-03-11 13:42:58 +01002/*
3 * (C) Copyright 2007 Michal Simek
4 *
Michal Simek571bce12007-09-24 00:18:46 +02005 * Michal SIMEK <monstr@monstr.eu>
Michal Simek952d5142007-03-11 13:42:58 +01006 */
7
8#include <common.h>
Simon Glass1d91ba72019-11-14 12:57:37 -07009#include <cpu_func.h>
Michal Simek98c19792007-05-07 23:58:31 +020010#include <asm/asm.h>
Michal Simek952d5142007-03-11 13:42:58 +010011
Simon Glassfbf091b2019-11-14 12:57:36 -070012int dcache_status(void)
Michal Simek952d5142007-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 Glassfbf091b2019-11-14 12:57:36 -070022int icache_status(void)
Michal Simek952d5142007-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 Simekc4f5ef82007-05-07 19:25:08 +020031
Simon Glassfbf091b2019-11-14 12:57:36 -070032void icache_enable(void)
33{
Michal Simek98c19792007-05-07 23:58:31 +020034 MSRSET(0x20);
Michal Simekc4f5ef82007-05-07 19:25:08 +020035}
36
Simon Glassfbf091b2019-11-14 12:57:36 -070037void icache_disable(void)
38{
Michal Simek08a30cb2010-04-16 12:56:33 +020039 /* we are not generate ICACHE size -> flush whole cache */
40 flush_cache(0, 32768);
Michal Simek98c19792007-05-07 23:58:31 +020041 MSRCLR(0x20);
Michal Simekc4f5ef82007-05-07 19:25:08 +020042}
43
Simon Glassfbf091b2019-11-14 12:57:36 -070044void dcache_enable(void)
45{
Michal Simek98c19792007-05-07 23:58:31 +020046 MSRSET(0x80);
Michal Simekc4f5ef82007-05-07 19:25:08 +020047}
48
Simon Glassfbf091b2019-11-14 12:57:36 -070049void dcache_disable(void)
50{
Michal Simek08a30cb2010-04-16 12:56:33 +020051#ifdef XILINX_USE_DCACHE
Michal Simek08a30cb2010-04-16 12:56:33 +020052 flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
Michal Simek08a30cb2010-04-16 12:56:33 +020053#endif
Michal Simek98c19792007-05-07 23:58:31 +020054 MSRCLR(0x80);
Michal Simekc4f5ef82007-05-07 19:25:08 +020055}
Michal Simek08a30cb2010-04-16 12:56:33 +020056
Simon Glassfbf091b2019-11-14 12:57:36 -070057void flush_cache(ulong addr, ulong size)
Michal Simek08a30cb2010-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}