blob: 2c687173a8bfe5ddc45e73a61089cc17230dd929 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk38635852002-08-27 05:55:31 +00002/*
3 * (C) Copyright 2000
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenk38635852002-08-27 05:55:31 +00005 */
6
7/*
8 * Cache support: switch on or off, get status
9 */
10#include <common.h>
11#include <command.h>
Matthew McClintockd0c4c332011-05-24 10:09:05 +000012#include <linux/compiler.h>
wdenk38635852002-08-27 05:55:31 +000013
Matthew McClintockd0c4c332011-05-24 10:09:05 +000014static int parse_argv(const char *);
15
Stefan Kristiansson23498932011-10-31 18:21:12 +000016void __weak invalidate_icache_all(void)
Matthew McClintockd0c4c332011-05-24 10:09:05 +000017{
Stefan Kristiansson23498932011-10-31 18:21:12 +000018 /* please define arch specific invalidate_icache_all */
19 puts("No arch specific invalidate_icache_all available!\n");
Matthew McClintockd0c4c332011-05-24 10:09:05 +000020}
wdenk38635852002-08-27 05:55:31 +000021
Jeroen Hofstee0e350f82014-06-23 00:22:08 +020022static int do_icache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000023{
24 switch (argc) {
Eric Perief043dc22019-07-13 14:54:58 -040025 case 2: /* on / off / flush */
Matthew McClintockd0c4c332011-05-24 10:09:05 +000026 switch (parse_argv(argv[1])) {
Joe Hershbergere9455fc2012-10-03 10:56:16 +000027 case 0:
28 icache_disable();
wdenk38635852002-08-27 05:55:31 +000029 break;
Joe Hershbergere9455fc2012-10-03 10:56:16 +000030 case 1:
31 icache_enable();
wdenk38635852002-08-27 05:55:31 +000032 break;
Joe Hershbergere9455fc2012-10-03 10:56:16 +000033 case 2:
34 invalidate_icache_all();
Matthew McClintockd0c4c332011-05-24 10:09:05 +000035 break;
Eric Perief043dc22019-07-13 14:54:58 -040036 default:
37 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000038 }
Joe Hershberger36180d92012-10-03 10:56:17 +000039 break;
wdenk38635852002-08-27 05:55:31 +000040 case 1: /* get status */
Joe Hershbergere9455fc2012-10-03 10:56:16 +000041 printf("Instruction Cache is %s\n",
wdenk38635852002-08-27 05:55:31 +000042 icache_status() ? "ON" : "OFF");
43 return 0;
44 default:
Simon Glass4c12eeb2011-12-10 08:44:01 +000045 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000046 }
47 return 0;
48}
49
Stefan Kristiansson23498932011-10-31 18:21:12 +000050void __weak flush_dcache_all(void)
Matthew McClintockd0c4c332011-05-24 10:09:05 +000051{
Stefan Kristiansson23498932011-10-31 18:21:12 +000052 puts("No arch specific flush_dcache_all available!\n");
53 /* please define arch specific flush_dcache_all */
Matthew McClintockd0c4c332011-05-24 10:09:05 +000054}
55
Jeroen Hofstee0e350f82014-06-23 00:22:08 +020056static int do_dcache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000057{
58 switch (argc) {
Eric Perief043dc22019-07-13 14:54:58 -040059 case 2: /* on / off / flush */
Matthew McClintockd0c4c332011-05-24 10:09:05 +000060 switch (parse_argv(argv[1])) {
Joe Hershbergere9455fc2012-10-03 10:56:16 +000061 case 0:
62 dcache_disable();
wdenk38635852002-08-27 05:55:31 +000063 break;
Joe Hershbergere9455fc2012-10-03 10:56:16 +000064 case 1:
65 dcache_enable();
wdenk38635852002-08-27 05:55:31 +000066 break;
Joe Hershbergere9455fc2012-10-03 10:56:16 +000067 case 2:
68 flush_dcache_all();
Matthew McClintockd0c4c332011-05-24 10:09:05 +000069 break;
Eric Perief043dc22019-07-13 14:54:58 -040070 default:
71 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000072 }
Joe Hershbergere9455fc2012-10-03 10:56:16 +000073 break;
wdenk38635852002-08-27 05:55:31 +000074 case 1: /* get status */
Joe Hershbergere9455fc2012-10-03 10:56:16 +000075 printf("Data (writethrough) Cache is %s\n",
wdenk38635852002-08-27 05:55:31 +000076 dcache_status() ? "ON" : "OFF");
77 return 0;
78 default:
Simon Glass4c12eeb2011-12-10 08:44:01 +000079 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000080 }
81 return 0;
wdenk38635852002-08-27 05:55:31 +000082}
83
Matthew McClintockd0c4c332011-05-24 10:09:05 +000084static int parse_argv(const char *s)
wdenk38635852002-08-27 05:55:31 +000085{
Joe Hershbergere9455fc2012-10-03 10:56:16 +000086 if (strcmp(s, "flush") == 0)
87 return 2;
88 else if (strcmp(s, "on") == 0)
89 return 1;
90 else if (strcmp(s, "off") == 0)
91 return 0;
92
93 return -1;
wdenk38635852002-08-27 05:55:31 +000094}
95
wdenk8bde7f72003-06-27 21:31:46 +000096
wdenk0d498392003-07-01 21:06:45 +000097U_BOOT_CMD(
98 icache, 2, 1, do_icache,
Peter Tyser2fb26042009-01-27 18:03:12 -060099 "enable or disable instruction cache",
Matthew McClintockd0c4c332011-05-24 10:09:05 +0000100 "[on, off, flush]\n"
101 " - enable, disable, or flush instruction cache"
wdenk8bde7f72003-06-27 21:31:46 +0000102);
103
wdenk0d498392003-07-01 21:06:45 +0000104U_BOOT_CMD(
105 dcache, 2, 1, do_dcache,
Peter Tyser2fb26042009-01-27 18:03:12 -0600106 "enable or disable data cache",
Matthew McClintockd0c4c332011-05-24 10:09:05 +0000107 "[on, off, flush]\n"
108 " - enable, disable, or flush data (writethrough) cache"
wdenk8bde7f72003-06-27 21:31:46 +0000109);