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