blob: eebeb37830b8d672314031262fd2048b2797e72f [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>
Michal Simek98c19792007-05-07 23:58:31 +02009#include <asm/asm.h>
Michal Simek952d5142007-03-11 13:42:58 +010010
Michal Simek952d5142007-03-11 13:42:58 +010011int dcache_status (void)
12{
13 int i = 0;
14 int mask = 0x80;
15 __asm__ __volatile__ ("mfs %0,rmsr"::"r" (i):"memory");
16 /* i&=0x80 */
17 __asm__ __volatile__ ("and %0,%0,%1"::"r" (i), "r" (mask):"memory");
18 return i;
19}
20
21int icache_status (void)
22{
23 int i = 0;
24 int mask = 0x20;
25 __asm__ __volatile__ ("mfs %0,rmsr"::"r" (i):"memory");
26 /* i&=0x20 */
27 __asm__ __volatile__ ("and %0,%0,%1"::"r" (i), "r" (mask):"memory");
28 return i;
29}
Michal Simekc4f5ef82007-05-07 19:25:08 +020030
31void icache_enable (void) {
Michal Simek98c19792007-05-07 23:58:31 +020032 MSRSET(0x20);
Michal Simekc4f5ef82007-05-07 19:25:08 +020033}
34
35void icache_disable(void) {
Michal Simek08a30cb2010-04-16 12:56:33 +020036 /* we are not generate ICACHE size -> flush whole cache */
37 flush_cache(0, 32768);
Michal Simek98c19792007-05-07 23:58:31 +020038 MSRCLR(0x20);
Michal Simekc4f5ef82007-05-07 19:25:08 +020039}
40
41void dcache_enable (void) {
Michal Simek98c19792007-05-07 23:58:31 +020042 MSRSET(0x80);
Michal Simekc4f5ef82007-05-07 19:25:08 +020043}
44
45void dcache_disable(void) {
Michal Simek08a30cb2010-04-16 12:56:33 +020046#ifdef XILINX_USE_DCACHE
Michal Simek08a30cb2010-04-16 12:56:33 +020047 flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
Michal Simek08a30cb2010-04-16 12:56:33 +020048#endif
Michal Simek98c19792007-05-07 23:58:31 +020049 MSRCLR(0x80);
Michal Simekc4f5ef82007-05-07 19:25:08 +020050}
Michal Simek08a30cb2010-04-16 12:56:33 +020051
52void flush_cache (ulong addr, ulong size)
53{
54 int i;
55 for (i = 0; i < size; i += 4)
56 asm volatile (
57#ifdef CONFIG_ICACHE
58 "wic %0, r0;"
59#endif
60 "nop;"
61#ifdef CONFIG_DCACHE
62 "wdc.flush %0, r0;"
63#endif
64 "nop;"
65 :
66 : "r" (addr + i)
67 : "memory");
68}