1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * (C) Copyright 2000
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 */
6
7 /*
8 * Cache support: switch on or off, get status
9 */
10 #include <common.h>
11 #include <command.h>
12 #include <linux/compiler.h>
13
14 static int parse_argv(const char *);
15
invalidate_icache_all(void)16 void __weak invalidate_icache_all(void)
17 {
18 /* please define arch specific invalidate_icache_all */
19 puts("No arch specific invalidate_icache_all available!\n");
20 }
21
do_icache(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])22 static int do_icache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
23 {
24 switch (argc) {
25 case 2: /* on / off */
26 switch (parse_argv(argv[1])) {
27 case 0:
28 icache_disable();
29 break;
30 case 1:
31 icache_enable();
32 break;
33 case 2:
34 invalidate_icache_all();
35 break;
36 }
37 break;
38 case 1: /* get status */
39 printf("Instruction Cache is %s\n",
40 icache_status() ? "ON" : "OFF");
41 return 0;
42 default:
43 return CMD_RET_USAGE;
44 }
45 return 0;
46 }
47
flush_dcache_all(void)48 void __weak flush_dcache_all(void)
49 {
50 puts("No arch specific flush_dcache_all available!\n");
51 /* please define arch specific flush_dcache_all */
52 }
53
do_dcache(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])54 static int do_dcache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
55 {
56 switch (argc) {
57 case 2: /* on / off */
58 switch (parse_argv(argv[1])) {
59 case 0:
60 dcache_disable();
61 break;
62 case 1:
63 dcache_enable();
64 break;
65 case 2:
66 flush_dcache_all();
67 break;
68 }
69 break;
70 case 1: /* get status */
71 printf("Data (writethrough) Cache is %s\n",
72 dcache_status() ? "ON" : "OFF");
73 return 0;
74 default:
75 return CMD_RET_USAGE;
76 }
77 return 0;
78 }
79
parse_argv(const char * s)80 static int parse_argv(const char *s)
81 {
82 if (strcmp(s, "flush") == 0)
83 return 2;
84 else if (strcmp(s, "on") == 0)
85 return 1;
86 else if (strcmp(s, "off") == 0)
87 return 0;
88
89 return -1;
90 }
91
92
93 U_BOOT_CMD(
94 icache, 2, 1, do_icache,
95 "enable or disable instruction cache",
96 "[on, off, flush]\n"
97 " - enable, disable, or flush instruction cache"
98 );
99
100 U_BOOT_CMD(
101 dcache, 2, 1, do_dcache,
102 "enable or disable data cache",
103 "[on, off, flush]\n"
104 " - enable, disable, or flush data (writethrough) cache"
105 );
106