Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 7eaacc5 | 2003-08-29 22:00:43 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2002 |
| 4 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 5 | * Marius Groeger <mgroeger@sysgo.de> |
| 6 | * |
| 7 | * (C) Copyright 2002 |
Detlev Zundel | f1b3f2b | 2009-05-13 10:54:10 +0200 | [diff] [blame] | 8 | * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de> |
wdenk | 7eaacc5 | 2003-08-29 22:00:43 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * CPU specific code |
| 13 | */ |
| 14 | |
wdenk | 7eaacc5 | 2003-08-29 22:00:43 +0000 | [diff] [blame] | 15 | #include <command.h> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 16 | #include <cpu_func.h> |
Simon Glass | 8f3f761 | 2019-11-14 12:57:42 -0700 | [diff] [blame] | 17 | #include <irq_func.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 18 | #include <asm/cache.h> |
Jean-Christophe PLAGNIOL-VILLARD | 9053b5a | 2009-04-05 13:02:43 +0200 | [diff] [blame] | 19 | #include <asm/system.h> |
wdenk | 7eaacc5 | 2003-08-29 22:00:43 +0000 | [diff] [blame] | 20 | |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 21 | static void cache_flush(void); |
wdenk | 7eaacc5 | 2003-08-29 22:00:43 +0000 | [diff] [blame] | 22 | |
Icenowy Zheng | b198c2e | 2022-01-29 10:23:02 -0500 | [diff] [blame] | 23 | /************************************************************ |
| 24 | * sdelay() - simple spin loop. Will be constant time as |
| 25 | * its generally used in bypass conditions only. This |
| 26 | * is necessary until timers are accessible. |
| 27 | * |
| 28 | * not inline to increase chances its in cache when called |
| 29 | *************************************************************/ |
| 30 | void sdelay(unsigned long loops) |
| 31 | { |
| 32 | __asm__ volatile ("1:\n" "subs %0, %1, #1\n" |
| 33 | "bne 1b":"=r" (loops):"0"(loops)); |
| 34 | } |
| 35 | |
wdenk | 7eaacc5 | 2003-08-29 22:00:43 +0000 | [diff] [blame] | 36 | int cleanup_before_linux (void) |
| 37 | { |
| 38 | /* |
| 39 | * this function is called just before we call linux |
| 40 | * it prepares the processor for linux |
| 41 | * |
| 42 | * we turn off caches etc ... |
| 43 | */ |
| 44 | |
Simon Glass | f87959b | 2019-11-14 12:57:40 -0700 | [diff] [blame] | 45 | disable_interrupts(); |
wdenk | 7eaacc5 | 2003-08-29 22:00:43 +0000 | [diff] [blame] | 46 | |
wdenk | 7eaacc5 | 2003-08-29 22:00:43 +0000 | [diff] [blame] | 47 | |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 48 | /* turn off I/D-cache */ |
| 49 | icache_disable(); |
| 50 | dcache_disable(); |
Michael Walle | 5ae3eec | 2012-02-06 22:42:10 +0530 | [diff] [blame] | 51 | l2_cache_disable(); |
| 52 | |
wdenk | 7eaacc5 | 2003-08-29 22:00:43 +0000 | [diff] [blame] | 53 | /* flush I/D-cache */ |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 54 | cache_flush(); |
Wolfgang Denk | adf20a1 | 2005-09-25 01:48:28 +0200 | [diff] [blame] | 55 | |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 56 | return 0; |
wdenk | 7eaacc5 | 2003-08-29 22:00:43 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 59 | /* flush I/D-cache */ |
| 60 | static void cache_flush (void) |
Hugo Villeneuve | 82a8437 | 2008-07-10 10:46:33 -0400 | [diff] [blame] | 61 | { |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 62 | #if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 63 | unsigned long i = 0; |
Hugo Villeneuve | 82a8437 | 2008-07-10 10:46:33 -0400 | [diff] [blame] | 64 | |
Jean-Christophe PLAGNIOL-VILLARD | e6b5f1b | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 65 | asm ("mcr p15, 0, %0, c7, c7, 0": :"r" (i)); |
Heiko Schocher | b642d83 | 2014-11-18 09:41:56 +0100 | [diff] [blame] | 66 | #endif |
wdenk | 7eaacc5 | 2003-08-29 22:00:43 +0000 | [diff] [blame] | 67 | } |