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 | */ |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 10 | #include <command.h> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 11 | #include <cpu_func.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 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 16 | static int do_icache(struct cmd_tbl *cmdtp, int flag, int argc, |
| 17 | char *const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 18 | { |
| 19 | switch (argc) { |
Eric Perie | 86b7ba5 | 2019-07-13 14:54:58 -0400 | [diff] [blame] | 20 | case 2: /* on / off / flush */ |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 21 | switch (parse_argv(argv[1])) { |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 22 | case 0: |
| 23 | icache_disable(); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 24 | break; |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 25 | case 1: |
| 26 | icache_enable(); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 27 | break; |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 28 | case 2: |
| 29 | invalidate_icache_all(); |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 30 | break; |
Eric Perie | 86b7ba5 | 2019-07-13 14:54:58 -0400 | [diff] [blame] | 31 | default: |
| 32 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 33 | } |
Joe Hershberger | 8cab156 | 2012-10-03 10:56:17 +0000 | [diff] [blame] | 34 | break; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 35 | case 1: /* get status */ |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 36 | printf("Instruction Cache is %s\n", |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 37 | icache_status() ? "ON" : "OFF"); |
| 38 | return 0; |
| 39 | default: |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 40 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 41 | } |
| 42 | return 0; |
| 43 | } |
| 44 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 45 | static int do_dcache(struct cmd_tbl *cmdtp, int flag, int argc, |
| 46 | char *const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 47 | { |
| 48 | switch (argc) { |
Eric Perie | 86b7ba5 | 2019-07-13 14:54:58 -0400 | [diff] [blame] | 49 | case 2: /* on / off / flush */ |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 50 | switch (parse_argv(argv[1])) { |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 51 | case 0: |
| 52 | dcache_disable(); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 53 | break; |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 54 | case 1: |
| 55 | dcache_enable(); |
Tom Rini | f773232 | 2024-06-19 15:27:59 -0600 | [diff] [blame] | 56 | #ifdef CONFIG_SYS_NONCACHED_MEMORY |
Patrice Chotard | e2eb721 | 2020-04-28 11:38:03 +0200 | [diff] [blame] | 57 | noncached_set_region(); |
Tom Rini | f773232 | 2024-06-19 15:27:59 -0600 | [diff] [blame] | 58 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 59 | break; |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 60 | case 2: |
| 61 | flush_dcache_all(); |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 62 | break; |
Eric Perie | 86b7ba5 | 2019-07-13 14:54:58 -0400 | [diff] [blame] | 63 | default: |
| 64 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 65 | } |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 66 | break; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 67 | case 1: /* get status */ |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 68 | printf("Data (writethrough) Cache is %s\n", |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 69 | dcache_status() ? "ON" : "OFF"); |
| 70 | return 0; |
| 71 | default: |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 72 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 73 | } |
| 74 | return 0; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 77 | static int parse_argv(const char *s) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 78 | { |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 79 | if (strcmp(s, "flush") == 0) |
| 80 | return 2; |
| 81 | else if (strcmp(s, "on") == 0) |
| 82 | return 1; |
| 83 | else if (strcmp(s, "off") == 0) |
| 84 | return 0; |
| 85 | |
| 86 | return -1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 87 | } |
| 88 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 89 | U_BOOT_CMD( |
| 90 | icache, 2, 1, do_icache, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 91 | "enable or disable instruction cache", |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 92 | "[on, off, flush]\n" |
| 93 | " - enable, disable, or flush instruction cache" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 94 | ); |
| 95 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 96 | U_BOOT_CMD( |
| 97 | dcache, 2, 1, do_dcache, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 98 | "enable or disable data cache", |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 99 | "[on, off, flush]\n" |
| 100 | " - enable, disable, or flush data (writethrough) cache" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 101 | ); |