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