blob: 27dcec093169e1294235e4ef31770b4bfdd65d6c [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>
Simon Glass9edefc22019-11-14 12:57:37 -070012#include <cpu_func.h>
Matthew McClintockd0c4c332011-05-24 10:09:05 +000013#include <linux/compiler.h>
wdenk38635852002-08-27 05:55:31 +000014
Matthew McClintockd0c4c332011-05-24 10:09:05 +000015static int parse_argv(const char *);
16
Stefan Kristiansson23498932011-10-31 18:21:12 +000017void __weak invalidate_icache_all(void)
Matthew McClintockd0c4c332011-05-24 10:09:05 +000018{
Stefan Kristiansson23498932011-10-31 18:21:12 +000019 /* please define arch specific invalidate_icache_all */
20 puts("No arch specific invalidate_icache_all available!\n");
Matthew McClintockd0c4c332011-05-24 10:09:05 +000021}
wdenk38635852002-08-27 05:55:31 +000022
Jeroen Hofstee0e350f82014-06-23 00:22:08 +020023static int do_icache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000024{
25 switch (argc) {
Eric Perief043dc22019-07-13 14:54:58 -040026 case 2: /* on / off / flush */
Matthew McClintockd0c4c332011-05-24 10:09:05 +000027 switch (parse_argv(argv[1])) {
Joe Hershbergere9455fc2012-10-03 10:56:16 +000028 case 0:
29 icache_disable();
wdenk38635852002-08-27 05:55:31 +000030 break;
Joe Hershbergere9455fc2012-10-03 10:56:16 +000031 case 1:
32 icache_enable();
wdenk38635852002-08-27 05:55:31 +000033 break;
Joe Hershbergere9455fc2012-10-03 10:56:16 +000034 case 2:
35 invalidate_icache_all();
Matthew McClintockd0c4c332011-05-24 10:09:05 +000036 break;
Eric Perief043dc22019-07-13 14:54:58 -040037 default:
38 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000039 }
Joe Hershberger36180d92012-10-03 10:56:17 +000040 break;
wdenk38635852002-08-27 05:55:31 +000041 case 1: /* get status */
Joe Hershbergere9455fc2012-10-03 10:56:16 +000042 printf("Instruction Cache is %s\n",
wdenk38635852002-08-27 05:55:31 +000043 icache_status() ? "ON" : "OFF");
44 return 0;
45 default:
Simon Glass4c12eeb2011-12-10 08:44:01 +000046 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000047 }
48 return 0;
49}
50
Stefan Kristiansson23498932011-10-31 18:21:12 +000051void __weak flush_dcache_all(void)
Matthew McClintockd0c4c332011-05-24 10:09:05 +000052{
Stefan Kristiansson23498932011-10-31 18:21:12 +000053 puts("No arch specific flush_dcache_all available!\n");
54 /* please define arch specific flush_dcache_all */
Matthew McClintockd0c4c332011-05-24 10:09:05 +000055}
56
Jeroen Hofstee0e350f82014-06-23 00:22:08 +020057static int do_dcache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000058{
59 switch (argc) {
Eric Perief043dc22019-07-13 14:54:58 -040060 case 2: /* on / off / flush */
Matthew McClintockd0c4c332011-05-24 10:09:05 +000061 switch (parse_argv(argv[1])) {
Joe Hershbergere9455fc2012-10-03 10:56:16 +000062 case 0:
63 dcache_disable();
wdenk38635852002-08-27 05:55:31 +000064 break;
Joe Hershbergere9455fc2012-10-03 10:56:16 +000065 case 1:
66 dcache_enable();
wdenk38635852002-08-27 05:55:31 +000067 break;
Joe Hershbergere9455fc2012-10-03 10:56:16 +000068 case 2:
69 flush_dcache_all();
Matthew McClintockd0c4c332011-05-24 10:09:05 +000070 break;
Eric Perief043dc22019-07-13 14:54:58 -040071 default:
72 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000073 }
Joe Hershbergere9455fc2012-10-03 10:56:16 +000074 break;
wdenk38635852002-08-27 05:55:31 +000075 case 1: /* get status */
Joe Hershbergere9455fc2012-10-03 10:56:16 +000076 printf("Data (writethrough) Cache is %s\n",
wdenk38635852002-08-27 05:55:31 +000077 dcache_status() ? "ON" : "OFF");
78 return 0;
79 default:
Simon Glass4c12eeb2011-12-10 08:44:01 +000080 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000081 }
82 return 0;
wdenk38635852002-08-27 05:55:31 +000083}
84
Matthew McClintockd0c4c332011-05-24 10:09:05 +000085static int parse_argv(const char *s)
wdenk38635852002-08-27 05:55:31 +000086{
Joe Hershbergere9455fc2012-10-03 10:56:16 +000087 if (strcmp(s, "flush") == 0)
88 return 2;
89 else if (strcmp(s, "on") == 0)
90 return 1;
91 else if (strcmp(s, "off") == 0)
92 return 0;
93
94 return -1;
wdenk38635852002-08-27 05:55:31 +000095}
96
wdenk8bde7f72003-06-27 21:31:46 +000097
wdenk0d498392003-07-01 21:06:45 +000098U_BOOT_CMD(
99 icache, 2, 1, do_icache,
Peter Tyser2fb26042009-01-27 18:03:12 -0600100 "enable or disable instruction cache",
Matthew McClintockd0c4c332011-05-24 10:09:05 +0000101 "[on, off, flush]\n"
102 " - enable, disable, or flush instruction cache"
wdenk8bde7f72003-06-27 21:31:46 +0000103);
104
wdenk0d498392003-07-01 21:06:45 +0000105U_BOOT_CMD(
106 dcache, 2, 1, do_dcache,
Peter Tyser2fb26042009-01-27 18:03:12 -0600107 "enable or disable data cache",
Matthew McClintockd0c4c332011-05-24 10:09:05 +0000108 "[on, off, flush]\n"
109 " - enable, disable, or flush data (writethrough) cache"
wdenk8bde7f72003-06-27 21:31:46 +0000110);