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