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 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * Cache support: switch on or off, get status |
| 26 | */ |
| 27 | #include <common.h> |
| 28 | #include <command.h> |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 29 | #include <linux/compiler.h> |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 30 | |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 31 | static int parse_argv(const char *); |
| 32 | |
Stefan Kristiansson | a741605 | 2011-10-31 18:21:12 +0000 | [diff] [blame] | 33 | void __weak invalidate_icache_all(void) |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 34 | { |
Stefan Kristiansson | a741605 | 2011-10-31 18:21:12 +0000 | [diff] [blame] | 35 | /* please define arch specific invalidate_icache_all */ |
| 36 | puts("No arch specific invalidate_icache_all available!\n"); |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 37 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 38 | |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 39 | 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] | 40 | { |
| 41 | switch (argc) { |
| 42 | case 2: /* on / off */ |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 43 | switch (parse_argv(argv[1])) { |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 44 | case 0: |
| 45 | icache_disable(); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 46 | break; |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 47 | case 1: |
| 48 | icache_enable(); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 49 | break; |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 50 | case 2: |
| 51 | invalidate_icache_all(); |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 52 | break; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 53 | } |
Joe Hershberger | 8cab156 | 2012-10-03 10:56:17 +0000 | [diff] [blame] | 54 | break; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 55 | case 1: /* get status */ |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 56 | printf("Instruction Cache is %s\n", |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 57 | icache_status() ? "ON" : "OFF"); |
| 58 | return 0; |
| 59 | default: |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 60 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 61 | } |
| 62 | return 0; |
| 63 | } |
| 64 | |
Stefan Kristiansson | a741605 | 2011-10-31 18:21:12 +0000 | [diff] [blame] | 65 | void __weak flush_dcache_all(void) |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 66 | { |
Stefan Kristiansson | a741605 | 2011-10-31 18:21:12 +0000 | [diff] [blame] | 67 | puts("No arch specific flush_dcache_all available!\n"); |
| 68 | /* please define arch specific flush_dcache_all */ |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 71 | 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] | 72 | { |
| 73 | switch (argc) { |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 74 | case 2: /* on / off */ |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 75 | switch (parse_argv(argv[1])) { |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 76 | case 0: |
| 77 | dcache_disable(); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 78 | break; |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 79 | case 1: |
| 80 | dcache_enable(); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 81 | break; |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 82 | case 2: |
| 83 | flush_dcache_all(); |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 84 | break; |
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 | break; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 87 | case 1: /* get status */ |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 88 | printf("Data (writethrough) Cache is %s\n", |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 89 | dcache_status() ? "ON" : "OFF"); |
| 90 | return 0; |
| 91 | default: |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 92 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 93 | } |
| 94 | return 0; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 97 | static int parse_argv(const char *s) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 98 | { |
Joe Hershberger | 3745b8c | 2012-10-03 10:56:16 +0000 | [diff] [blame] | 99 | if (strcmp(s, "flush") == 0) |
| 100 | return 2; |
| 101 | else if (strcmp(s, "on") == 0) |
| 102 | return 1; |
| 103 | else if (strcmp(s, "off") == 0) |
| 104 | return 0; |
| 105 | |
| 106 | return -1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 107 | } |
| 108 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 109 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 110 | U_BOOT_CMD( |
| 111 | icache, 2, 1, do_icache, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 112 | "enable or disable instruction cache", |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 113 | "[on, off, flush]\n" |
| 114 | " - enable, disable, or flush instruction cache" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 115 | ); |
| 116 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 117 | U_BOOT_CMD( |
| 118 | dcache, 2, 1, do_dcache, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 119 | "enable or disable data cache", |
Matthew McClintock | a14695e | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 120 | "[on, off, flush]\n" |
| 121 | " - enable, disable, or flush data (writethrough) cache" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 122 | ); |