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 | d0c4c33 | 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 | d0c4c33 | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 31 | static int parse_argv(const char *); |
| 32 | |
| 33 | void __weak flush_icache(void) |
| 34 | { |
| 35 | /* please define arch specific flush_icache */ |
| 36 | puts("No arch specific flush_icache available!\n"); |
| 37 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 38 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [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 | d0c4c33 | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 43 | switch (parse_argv(argv[1])) { |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 44 | case 0: icache_disable(); |
| 45 | break; |
| 46 | case 1: icache_enable (); |
| 47 | break; |
Matthew McClintock | d0c4c33 | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 48 | case 2: flush_icache(); |
| 49 | break; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 50 | } |
| 51 | /* FALL TROUGH */ |
| 52 | case 1: /* get status */ |
| 53 | printf ("Instruction Cache is %s\n", |
| 54 | icache_status() ? "ON" : "OFF"); |
| 55 | return 0; |
| 56 | default: |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 57 | return cmd_usage(cmdtp); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 58 | } |
| 59 | return 0; |
| 60 | } |
| 61 | |
Matthew McClintock | d0c4c33 | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 62 | void __weak flush_dcache(void) |
| 63 | { |
| 64 | puts("No arch specific flush_dcache available!\n"); |
| 65 | /* please define arch specific flush_dcache */ |
| 66 | } |
| 67 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 68 | 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] | 69 | { |
| 70 | switch (argc) { |
| 71 | case 2: /* on / off */ |
Matthew McClintock | d0c4c33 | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 72 | switch (parse_argv(argv[1])) { |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 73 | case 0: dcache_disable(); |
| 74 | break; |
| 75 | case 1: dcache_enable (); |
| 76 | break; |
Matthew McClintock | d0c4c33 | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 77 | case 2: flush_dcache(); |
| 78 | break; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 79 | } |
| 80 | /* FALL TROUGH */ |
| 81 | case 1: /* get status */ |
| 82 | printf ("Data (writethrough) Cache is %s\n", |
| 83 | dcache_status() ? "ON" : "OFF"); |
| 84 | return 0; |
| 85 | default: |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 86 | return cmd_usage(cmdtp); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 87 | } |
| 88 | return 0; |
| 89 | |
| 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 | { |
Matthew McClintock | d0c4c33 | 2011-05-24 10:09:05 +0000 | [diff] [blame] | 94 | if (strcmp(s, "flush") == 0) { |
| 95 | return (2); |
| 96 | } else if (strcmp(s, "on") == 0) { |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 97 | return (1); |
| 98 | } else if (strcmp(s, "off") == 0) { |
| 99 | return (0); |
| 100 | } |
| 101 | return (-1); |
| 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 | ); |