• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <cpu_func.h>
13 #include <linux/compiler.h>
14 
15 static int parse_argv(const char *);
16 
invalidate_icache_all(void)17 void __weak invalidate_icache_all(void)
18 {
19 	/* please define arch specific invalidate_icache_all */
20 	puts("No arch specific invalidate_icache_all available!\n");
21 }
22 
do_icache(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])23 static int do_icache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
24 {
25 	switch (argc) {
26 	case 2:			/* on / off / flush */
27 		switch (parse_argv(argv[1])) {
28 		case 0:
29 			icache_disable();
30 			break;
31 		case 1:
32 			icache_enable();
33 			break;
34 		case 2:
35 			invalidate_icache_all();
36 			break;
37 		default:
38 			return CMD_RET_USAGE;
39 		}
40 		break;
41 	case 1:			/* get status */
42 		printf("Instruction Cache is %s\n",
43 			icache_status() ? "ON" : "OFF");
44 		return 0;
45 	default:
46 		return CMD_RET_USAGE;
47 	}
48 	return 0;
49 }
50 
flush_dcache_all(void)51 void __weak flush_dcache_all(void)
52 {
53 	puts("No arch specific flush_dcache_all available!\n");
54 	/* please define arch specific flush_dcache_all */
55 }
56 
do_dcache(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])57 static int do_dcache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
58 {
59 	switch (argc) {
60 	case 2:			/* on / off / flush */
61 		switch (parse_argv(argv[1])) {
62 		case 0:
63 			dcache_disable();
64 			break;
65 		case 1:
66 			dcache_enable();
67 			break;
68 		case 2:
69 			flush_dcache_all();
70 			break;
71 		default:
72 			return CMD_RET_USAGE;
73 		}
74 		break;
75 	case 1:			/* get status */
76 		printf("Data (writethrough) Cache is %s\n",
77 			dcache_status() ? "ON" : "OFF");
78 		return 0;
79 	default:
80 		return CMD_RET_USAGE;
81 	}
82 	return 0;
83 }
84 
parse_argv(const char * s)85 static int parse_argv(const char *s)
86 {
87 	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;
95 }
96 
97 
98 U_BOOT_CMD(
99 	icache,   2,   1,     do_icache,
100 	"enable or disable instruction cache",
101 	"[on, off, flush]\n"
102 	"    - enable, disable, or flush instruction cache"
103 );
104 
105 U_BOOT_CMD(
106 	dcache,   2,   1,     do_dcache,
107 	"enable or disable data cache",
108 	"[on, off, flush]\n"
109 	"    - enable, disable, or flush data (writethrough) cache"
110 );
111