Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2000 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * Cache support: switch on or off, get status |
| 9 | */ |
| 10 | #include <common.h> |
| 11 | #include <command.h> |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 12 | #include <linux/compiler.h> |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 13 | |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 14 | static int parse_argv(const char *); |
| 15 | |
Stefan Kristiansson | a741605 | 2011-10-31 18:21:12 +0000 | [diff] [blame] | 16 | void __weak invalidate_icache_all(void) |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 17 | { |
Stefan Kristiansson | a741605 | 2011-10-31 18:21:12 +0000 | [diff] [blame] | 18 | /* please define arch specific invalidate_icache_all */ |
| 19 | puts("No arch specific invalidate_icache_all available!\n"); |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 20 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 21 | |
Jeroen Hofstee | f384fbf | 2014-06-23 00:22:08 +0200 | [diff] [blame] | 22 | static int do_icache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 23 | { |
| 24 | switch (argc) { |
Eric Perie | 86b7ba5 | 2019-07-13 14:54:58 -0400 | [diff] [blame] | 25 | case 2: /* on / off / flush */ |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 26 | switch (parse_argv(argv[1])) { |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 27 | case 0: |
| 28 | icache_disable(); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 29 | break; |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 30 | case 1: |
| 31 | icache_enable(); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 32 | break; |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 33 | case 2: |
| 34 | invalidate_icache_all(); |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 35 | break; |
Eric Perie | 86b7ba5 | 2019-07-13 14:54:58 -0400 | [diff] [blame] | 36 | default: |
| 37 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 38 | } |
Joe Hershberger | 8cab156 | 2012-10-03 10:56:17 +0000 | [diff] [blame] | 39 | break; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 40 | case 1: /* get status */ |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 41 | printf("Instruction Cache is %s\n", |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 42 | icache_status() ? "ON" : "OFF"); |
| 43 | return 0; |
| 44 | default: |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 45 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 46 | } |
| 47 | return 0; |
| 48 | } |
| 49 | |
Stefan Kristiansson | a741605 | 2011-10-31 18:21:12 +0000 | [diff] [blame] | 50 | void __weak flush_dcache_all(void) |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 51 | { |
Stefan Kristiansson | a741605 | 2011-10-31 18:21:12 +0000 | [diff] [blame] | 52 | puts("No arch specific flush_dcache_all available!\n"); |
| 53 | /* please define arch specific flush_dcache_all */ |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Jeroen Hofstee | f384fbf | 2014-06-23 00:22:08 +0200 | [diff] [blame] | 56 | static int do_dcache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 57 | { |
| 58 | switch (argc) { |
Eric Perie | 86b7ba5 | 2019-07-13 14:54:58 -0400 | [diff] [blame] | 59 | case 2: /* on / off / flush */ |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 60 | switch (parse_argv(argv[1])) { |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 61 | case 0: |
| 62 | dcache_disable(); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 63 | break; |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 64 | case 1: |
| 65 | dcache_enable(); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 66 | break; |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 67 | case 2: |
| 68 | flush_dcache_all(); |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 69 | break; |
Eric Perie | 86b7ba5 | 2019-07-13 14:54:58 -0400 | [diff] [blame] | 70 | default: |
| 71 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 72 | } |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 73 | break; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 74 | case 1: /* get status */ |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 75 | printf("Data (writethrough) Cache is %s\n", |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 76 | dcache_status() ? "ON" : "OFF"); |
| 77 | return 0; |
| 78 | default: |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 79 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 80 | } |
| 81 | return 0; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 84 | static int parse_argv(const char *s) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 85 | { |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 86 | if (strcmp(s, "flush") == 0) |
| 87 | return 2; |
| 88 | else if (strcmp(s, "on") == 0) |
| 89 | return 1; |
| 90 | else if (strcmp(s, "off") == 0) |
| 91 | return 0; |
| 92 | |
| 93 | return -1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 94 | } |
| 95 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 96 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 97 | U_BOOT_CMD( |
| 98 | icache, 2, 1, do_icache, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 99 | "enable or disable instruction cache", |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 100 | "[on, off, flush]\n" |
| 101 | " - enable, disable, or flush instruction cache" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 102 | ); |
| 103 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 104 | U_BOOT_CMD( |
| 105 | dcache, 2, 1, do_dcache, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 106 | "enable or disable data cache", |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 107 | "[on, off, flush]\n" |
| 108 | " - enable, disable, or flush data (writethrough) cache" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 109 | ); |