Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 2 | /* |
Vladimir Zapolskiy | f34743c | 2016-11-28 00:15:18 +0200 | [diff] [blame] | 3 | * (C) Copyright 2016 Vladimir Zapolskiy <vz@mleia.com> |
| 4 | * (C) Copyright 2007 Nobuhiro Iwamatsu <iwamatsu@nigauri.org> |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <command.h> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 9 | #include <cpu_func.h> |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 10 | #include <asm/io.h> |
Vladimir Zapolskiy | 57e56ef | 2016-11-28 00:15:16 +0200 | [diff] [blame] | 11 | #include <asm/processor.h> |
| 12 | #include <asm/system.h> |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 13 | |
| 14 | #define CACHE_VALID 1 |
| 15 | #define CACHE_UPDATED 2 |
| 16 | |
| 17 | static inline void cache_wback_all(void) |
| 18 | { |
| 19 | unsigned long addr, data, i, j; |
| 20 | |
Vladimir Zapolskiy | e852996 | 2016-11-28 00:15:17 +0200 | [diff] [blame] | 21 | for (i = 0; i < CACHE_OC_NUM_ENTRIES; i++) { |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 22 | for (j = 0; j < CACHE_OC_NUM_WAYS; j++) { |
Vladimir Zapolskiy | e852996 | 2016-11-28 00:15:17 +0200 | [diff] [blame] | 23 | addr = CACHE_OC_ADDRESS_ARRAY |
| 24 | | (j << CACHE_OC_WAY_SHIFT) |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 25 | | (i << CACHE_OC_ENTRY_SHIFT); |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 26 | data = inl(addr); |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 27 | if (data & CACHE_UPDATED) { |
| 28 | data &= ~CACHE_UPDATED; |
| 29 | outl(data, addr); |
| 30 | } |
| 31 | } |
| 32 | } |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 33 | } |
| 34 | |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 35 | #define CACHE_ENABLE 0 |
| 36 | #define CACHE_DISABLE 1 |
| 37 | |
Vladimir Zapolskiy | f34743c | 2016-11-28 00:15:18 +0200 | [diff] [blame] | 38 | static int cache_control(unsigned int cmd) |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 39 | { |
| 40 | unsigned long ccr; |
| 41 | |
| 42 | jump_to_P2(); |
| 43 | ccr = inl(CCR); |
| 44 | |
| 45 | if (ccr & CCR_CACHE_ENABLE) |
| 46 | cache_wback_all(); |
| 47 | |
| 48 | if (cmd == CACHE_DISABLE) |
| 49 | outl(CCR_CACHE_STOP, CCR); |
| 50 | else |
| 51 | outl(CCR_CACHE_INIT, CCR); |
| 52 | back_to_P1(); |
| 53 | |
| 54 | return 0; |
| 55 | } |
Mike Frysinger | b99910e | 2011-10-27 04:59:59 -0400 | [diff] [blame] | 56 | |
Nobuhiro Iwamatsu | 5b96baf | 2013-08-22 08:43:47 +0900 | [diff] [blame] | 57 | void flush_dcache_range(unsigned long start, unsigned long end) |
Mike Frysinger | b99910e | 2011-10-27 04:59:59 -0400 | [diff] [blame] | 58 | { |
| 59 | u32 v; |
| 60 | |
| 61 | start &= ~(L1_CACHE_BYTES - 1); |
| 62 | for (v = start; v < end; v += L1_CACHE_BYTES) { |
Vladimir Zapolskiy | 7a22f7a | 2016-11-28 00:15:13 +0200 | [diff] [blame] | 63 | asm volatile ("ocbp %0" : /* no output */ |
Mike Frysinger | b99910e | 2011-10-27 04:59:59 -0400 | [diff] [blame] | 64 | : "m" (__m(v))); |
| 65 | } |
| 66 | } |
| 67 | |
Nobuhiro Iwamatsu | 5b96baf | 2013-08-22 08:43:47 +0900 | [diff] [blame] | 68 | void invalidate_dcache_range(unsigned long start, unsigned long end) |
Mike Frysinger | b99910e | 2011-10-27 04:59:59 -0400 | [diff] [blame] | 69 | { |
| 70 | u32 v; |
| 71 | |
| 72 | start &= ~(L1_CACHE_BYTES - 1); |
| 73 | for (v = start; v < end; v += L1_CACHE_BYTES) { |
| 74 | asm volatile ("ocbi %0" : /* no output */ |
| 75 | : "m" (__m(v))); |
| 76 | } |
| 77 | } |
Vladimir Zapolskiy | f34743c | 2016-11-28 00:15:18 +0200 | [diff] [blame] | 78 | |
| 79 | void flush_cache(unsigned long addr, unsigned long size) |
| 80 | { |
| 81 | flush_dcache_range(addr , addr + size); |
| 82 | } |
| 83 | |
| 84 | void icache_enable(void) |
| 85 | { |
| 86 | cache_control(CACHE_ENABLE); |
| 87 | } |
| 88 | |
| 89 | void icache_disable(void) |
| 90 | { |
| 91 | cache_control(CACHE_DISABLE); |
| 92 | } |
| 93 | |
| 94 | int icache_status(void) |
| 95 | { |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | void dcache_enable(void) |
| 100 | { |
| 101 | } |
| 102 | |
| 103 | void dcache_disable(void) |
| 104 | { |
| 105 | } |
| 106 | |
| 107 | int dcache_status(void) |
| 108 | { |
| 109 | return 0; |
| 110 | } |