blob: d3c480e79ed2b1da00449af6038a7162ba34fd80 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +09002/*
Vladimir Zapolskiyf34743c2016-11-28 00:15:18 +02003 * (C) Copyright 2016 Vladimir Zapolskiy <vz@mleia.com>
4 * (C) Copyright 2007 Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +09005 */
6
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +09007#include <command.h>
Simon Glass1d91ba72019-11-14 12:57:37 -07008#include <cpu_func.h>
Tom Rini15c64692024-06-19 15:27:56 -06009#include <stdio.h>
Simon Glass274e0b02020-05-10 11:39:56 -060010#include <asm/cache.h>
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090011#include <asm/io.h>
Vladimir Zapolskiy57e56ef2016-11-28 00:15:16 +020012#include <asm/processor.h>
13#include <asm/system.h>
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090014
15#define CACHE_VALID 1
16#define CACHE_UPDATED 2
17
18static inline void cache_wback_all(void)
19{
20 unsigned long addr, data, i, j;
21
Vladimir Zapolskiye8529962016-11-28 00:15:17 +020022 for (i = 0; i < CACHE_OC_NUM_ENTRIES; i++) {
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090023 for (j = 0; j < CACHE_OC_NUM_WAYS; j++) {
Vladimir Zapolskiye8529962016-11-28 00:15:17 +020024 addr = CACHE_OC_ADDRESS_ARRAY
25 | (j << CACHE_OC_WAY_SHIFT)
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090026 | (i << CACHE_OC_ENTRY_SHIFT);
Wolfgang Denka1be4762008-05-20 16:00:29 +020027 data = inl(addr);
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090028 if (data & CACHE_UPDATED) {
29 data &= ~CACHE_UPDATED;
30 outl(data, addr);
31 }
32 }
33 }
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090034}
35
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090036#define CACHE_ENABLE 0
37#define CACHE_DISABLE 1
38
Vladimir Zapolskiyf34743c2016-11-28 00:15:18 +020039static int cache_control(unsigned int cmd)
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090040{
41 unsigned long ccr;
42
43 jump_to_P2();
44 ccr = inl(CCR);
45
46 if (ccr & CCR_CACHE_ENABLE)
47 cache_wback_all();
48
49 if (cmd == CACHE_DISABLE)
50 outl(CCR_CACHE_STOP, CCR);
51 else
52 outl(CCR_CACHE_INIT, CCR);
53 back_to_P1();
54
55 return 0;
56}
Mike Frysingerb99910e2011-10-27 04:59:59 -040057
Nobuhiro Iwamatsu5b96baf2013-08-22 08:43:47 +090058void flush_dcache_range(unsigned long start, unsigned long end)
Mike Frysingerb99910e2011-10-27 04:59:59 -040059{
60 u32 v;
61
62 start &= ~(L1_CACHE_BYTES - 1);
63 for (v = start; v < end; v += L1_CACHE_BYTES) {
Vladimir Zapolskiy7a22f7a2016-11-28 00:15:13 +020064 asm volatile ("ocbp %0" : /* no output */
Mike Frysingerb99910e2011-10-27 04:59:59 -040065 : "m" (__m(v)));
66 }
67}
68
Tom Rinic1beb762024-06-19 15:27:55 -060069/*
70 * Default implementation:
71 * do a range flush for the entire range
72 */
73void flush_dcache_all(void)
74{
75 flush_dcache_range(0, ~0);
76}
77
Nobuhiro Iwamatsu5b96baf2013-08-22 08:43:47 +090078void invalidate_dcache_range(unsigned long start, unsigned long end)
Mike Frysingerb99910e2011-10-27 04:59:59 -040079{
80 u32 v;
81
82 start &= ~(L1_CACHE_BYTES - 1);
83 for (v = start; v < end; v += L1_CACHE_BYTES) {
84 asm volatile ("ocbi %0" : /* no output */
85 : "m" (__m(v)));
86 }
87}
Vladimir Zapolskiyf34743c2016-11-28 00:15:18 +020088
89void flush_cache(unsigned long addr, unsigned long size)
90{
91 flush_dcache_range(addr , addr + size);
92}
93
94void icache_enable(void)
95{
96 cache_control(CACHE_ENABLE);
97}
98
99void icache_disable(void)
100{
101 cache_control(CACHE_DISABLE);
102}
103
Tom Rini15c64692024-06-19 15:27:56 -0600104void invalidate_icache_all(void)
105{
106 puts("No arch specific invalidate_icache_all available!\n");
107}
108
Vladimir Zapolskiyf34743c2016-11-28 00:15:18 +0200109int icache_status(void)
110{
111 return 0;
112}
113
114void dcache_enable(void)
115{
116}
117
118void dcache_disable(void)
119{
120}
121
122int dcache_status(void)
123{
124 return 0;
125}