blob: 5512f924b1808c0aa8b6f9ec3682dd55498c16d1 [file] [log] [blame]
wdenk38635852002-08-27 05:55:31 +00001/*
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 McClintocka14695e2011-05-24 10:09:05 +000029#include <linux/compiler.h>
wdenk38635852002-08-27 05:55:31 +000030
Matthew McClintocka14695e2011-05-24 10:09:05 +000031static int parse_argv(const char *);
32
Stefan Kristianssona7416052011-10-31 18:21:12 +000033void __weak invalidate_icache_all(void)
Matthew McClintocka14695e2011-05-24 10:09:05 +000034{
Stefan Kristianssona7416052011-10-31 18:21:12 +000035 /* please define arch specific invalidate_icache_all */
36 puts("No arch specific invalidate_icache_all available!\n");
Matthew McClintocka14695e2011-05-24 10:09:05 +000037}
wdenk38635852002-08-27 05:55:31 +000038
Joe Hershberger3745b8c2012-10-03 10:56:16 +000039int do_icache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000040{
41 switch (argc) {
42 case 2: /* on / off */
Matthew McClintocka14695e2011-05-24 10:09:05 +000043 switch (parse_argv(argv[1])) {
Joe Hershberger3745b8c2012-10-03 10:56:16 +000044 case 0:
45 icache_disable();
wdenk38635852002-08-27 05:55:31 +000046 break;
Joe Hershberger3745b8c2012-10-03 10:56:16 +000047 case 1:
48 icache_enable();
wdenk38635852002-08-27 05:55:31 +000049 break;
Joe Hershberger3745b8c2012-10-03 10:56:16 +000050 case 2:
51 invalidate_icache_all();
Matthew McClintocka14695e2011-05-24 10:09:05 +000052 break;
wdenk38635852002-08-27 05:55:31 +000053 }
Joe Hershberger8cab1562012-10-03 10:56:17 +000054 break;
wdenk38635852002-08-27 05:55:31 +000055 case 1: /* get status */
Joe Hershberger3745b8c2012-10-03 10:56:16 +000056 printf("Instruction Cache is %s\n",
wdenk38635852002-08-27 05:55:31 +000057 icache_status() ? "ON" : "OFF");
58 return 0;
59 default:
Simon Glassa06dfc72011-12-10 08:44:01 +000060 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000061 }
62 return 0;
63}
64
Stefan Kristianssona7416052011-10-31 18:21:12 +000065void __weak flush_dcache_all(void)
Matthew McClintocka14695e2011-05-24 10:09:05 +000066{
Stefan Kristianssona7416052011-10-31 18:21:12 +000067 puts("No arch specific flush_dcache_all available!\n");
68 /* please define arch specific flush_dcache_all */
Matthew McClintocka14695e2011-05-24 10:09:05 +000069}
70
Joe Hershberger3745b8c2012-10-03 10:56:16 +000071int do_dcache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000072{
73 switch (argc) {
Joe Hershberger3745b8c2012-10-03 10:56:16 +000074 case 2: /* on / off */
Matthew McClintocka14695e2011-05-24 10:09:05 +000075 switch (parse_argv(argv[1])) {
Joe Hershberger3745b8c2012-10-03 10:56:16 +000076 case 0:
77 dcache_disable();
wdenk38635852002-08-27 05:55:31 +000078 break;
Joe Hershberger3745b8c2012-10-03 10:56:16 +000079 case 1:
80 dcache_enable();
wdenk38635852002-08-27 05:55:31 +000081 break;
Joe Hershberger3745b8c2012-10-03 10:56:16 +000082 case 2:
83 flush_dcache_all();
Matthew McClintocka14695e2011-05-24 10:09:05 +000084 break;
wdenk38635852002-08-27 05:55:31 +000085 }
Joe Hershberger3745b8c2012-10-03 10:56:16 +000086 break;
wdenk38635852002-08-27 05:55:31 +000087 case 1: /* get status */
Joe Hershberger3745b8c2012-10-03 10:56:16 +000088 printf("Data (writethrough) Cache is %s\n",
wdenk38635852002-08-27 05:55:31 +000089 dcache_status() ? "ON" : "OFF");
90 return 0;
91 default:
Simon Glassa06dfc72011-12-10 08:44:01 +000092 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000093 }
94 return 0;
wdenk38635852002-08-27 05:55:31 +000095}
96
Matthew McClintocka14695e2011-05-24 10:09:05 +000097static int parse_argv(const char *s)
wdenk38635852002-08-27 05:55:31 +000098{
Joe Hershberger3745b8c2012-10-03 10:56:16 +000099 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;
wdenk38635852002-08-27 05:55:31 +0000107}
108
wdenk57b2d802003-06-27 21:31:46 +0000109
wdenkf287a242003-07-01 21:06:45 +0000110U_BOOT_CMD(
111 icache, 2, 1, do_icache,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600112 "enable or disable instruction cache",
Matthew McClintocka14695e2011-05-24 10:09:05 +0000113 "[on, off, flush]\n"
114 " - enable, disable, or flush instruction cache"
wdenk57b2d802003-06-27 21:31:46 +0000115);
116
wdenkf287a242003-07-01 21:06:45 +0000117U_BOOT_CMD(
118 dcache, 2, 1, do_dcache,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600119 "enable or disable data cache",
Matthew McClintocka14695e2011-05-24 10:09:05 +0000120 "[on, off, flush]\n"
121 " - enable, disable, or flush data (writethrough) cache"
wdenk57b2d802003-06-27 21:31:46 +0000122);