Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2004 Texas Insturments |
| 4 | * |
| 5 | * (C) Copyright 2002 |
| 6 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 7 | * Marius Groeger <mgroeger@sysgo.de> |
| 8 | * |
| 9 | * (C) Copyright 2002 |
Detlev Zundel | 792a09e | 2009-05-13 10:54:10 +0200 | [diff] [blame] | 10 | * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de> |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | /* |
| 14 | * CPU specific code |
| 15 | */ |
| 16 | |
| 17 | #include <common.h> |
| 18 | #include <command.h> |
Simon Glass | 9edefc2 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 19 | #include <cpu_func.h> |
Simon Glass | 36bf446 | 2019-11-14 12:57:42 -0700 | [diff] [blame] | 20 | #include <irq_func.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 21 | #include <asm/cache.h> |
Jean-Christophe PLAGNIOL-VILLARD | 677e62f | 2009-04-05 13:02:43 +0200 | [diff] [blame] | 22 | #include <asm/system.h> |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 23 | |
Jean-Christophe PLAGNIOL-VILLARD | b3acb6c | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 24 | static void cache_flush(void); |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 25 | |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 26 | int cleanup_before_linux (void) |
| 27 | { |
| 28 | /* |
| 29 | * this function is called just before we call linux |
| 30 | * it prepares the processor for linux |
| 31 | * |
| 32 | * we turn off caches etc ... |
| 33 | */ |
| 34 | |
Simon Glass | 9d3915b | 2019-11-14 12:57:40 -0700 | [diff] [blame] | 35 | disable_interrupts(); |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 36 | |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 37 | /* turn off I/D-cache */ |
Jean-Christophe PLAGNIOL-VILLARD | b3acb6c | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 38 | icache_disable(); |
| 39 | dcache_disable(); |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 40 | /* flush I/D-cache */ |
Jean-Christophe PLAGNIOL-VILLARD | b3acb6c | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 41 | cache_flush(); |
| 42 | |
| 43 | return 0; |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Jean-Christophe PLAGNIOL-VILLARD | b3acb6c | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 46 | static void cache_flush(void) |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 47 | { |
Jean-Christophe PLAGNIOL-VILLARD | b3acb6c | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 48 | unsigned long i = 0; |
Stefano Babic | fbf4a07 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 49 | /* clean entire data cache */ |
| 50 | asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (i)); |
| 51 | /* invalidate both caches and flush btb */ |
| 52 | asm volatile("mcr p15, 0, %0, c7, c7, 0" : : "r" (i)); |
| 53 | /* mem barrier to sync things */ |
| 54 | asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (i)); |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 55 | } |
Anatolij Gustschin | 219872c | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 56 | |
Trevor Woerner | 1001502 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 57 | #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
Anatolij Gustschin | 219872c | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 58 | void invalidate_dcache_all(void) |
| 59 | { |
Stefano Babic | fbf4a07 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 60 | asm volatile("mcr p15, 0, %0, c7, c6, 0" : : "r" (0)); |
Anatolij Gustschin | 219872c | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void flush_dcache_all(void) |
| 64 | { |
Stefano Babic | fbf4a07 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 65 | asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (0)); |
| 66 | asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0)); |
Anatolij Gustschin | 219872c | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Anatolij Gustschin | 219872c | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 69 | void invalidate_dcache_range(unsigned long start, unsigned long stop) |
| 70 | { |
Benoît Thébaudeau | f8f09dd | 2012-07-19 01:35:32 +0000 | [diff] [blame] | 71 | if (!check_cache_range(start, stop)) |
Anatolij Gustschin | 219872c | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 72 | return; |
| 73 | |
| 74 | while (start < stop) { |
Stefano Babic | fbf4a07 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 75 | asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start)); |
Anatolij Gustschin | 219872c | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 76 | start += CONFIG_SYS_CACHELINE_SIZE; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | void flush_dcache_range(unsigned long start, unsigned long stop) |
| 81 | { |
Benoît Thébaudeau | f8f09dd | 2012-07-19 01:35:32 +0000 | [diff] [blame] | 82 | if (!check_cache_range(start, stop)) |
Anatolij Gustschin | 219872c | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 83 | return; |
| 84 | |
| 85 | while (start < stop) { |
Stefano Babic | fbf4a07 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 86 | asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start)); |
Anatolij Gustschin | 219872c | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 87 | start += CONFIG_SYS_CACHELINE_SIZE; |
| 88 | } |
| 89 | |
Stefano Babic | fbf4a07 | 2012-04-09 13:33:04 +0200 | [diff] [blame] | 90 | asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0)); |
Anatolij Gustschin | 219872c | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Trevor Woerner | 1001502 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 93 | #else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */ |
Anatolij Gustschin | 219872c | 2012-04-02 06:18:00 +0000 | [diff] [blame] | 94 | void invalidate_dcache_all(void) |
| 95 | { |
| 96 | } |
| 97 | |
| 98 | void flush_dcache_all(void) |
| 99 | { |
| 100 | } |
Trevor Woerner | 1001502 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 101 | #endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */ |
Benoît Thébaudeau | ccfa398 | 2012-10-04 10:04:02 +0000 | [diff] [blame] | 102 | |
Trevor Woerner | 1001502 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 103 | #if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) |
Benoît Thébaudeau | ccfa398 | 2012-10-04 10:04:02 +0000 | [diff] [blame] | 104 | void enable_caches(void) |
| 105 | { |
Trevor Woerner | 1001502 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 106 | #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF) |
Benoît Thébaudeau | ccfa398 | 2012-10-04 10:04:02 +0000 | [diff] [blame] | 107 | icache_enable(); |
| 108 | #endif |
Trevor Woerner | 1001502 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 109 | #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
Benoît Thébaudeau | ccfa398 | 2012-10-04 10:04:02 +0000 | [diff] [blame] | 110 | dcache_enable(); |
| 111 | #endif |
| 112 | } |
| 113 | #endif |