"Das U-Boot" Source Tree
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 <command.h>
11#include <cpu_func.h>
12#include <linux/compiler.h>
13
14static int parse_argv(const char *);
15
16static int do_icache(struct cmd_tbl *cmdtp, int flag, int argc,
17 char *const argv[])
18{
19 switch (argc) {
20 case 2: /* on / off / flush */
21 switch (parse_argv(argv[1])) {
22 case 0:
23 icache_disable();
24 break;
25 case 1:
26 icache_enable();
27 break;
28 case 2:
29 invalidate_icache_all();
30 break;
31 default:
32 return CMD_RET_USAGE;
33 }
34 break;
35 case 1: /* get status */
36 printf("Instruction Cache is %s\n",
37 icache_status() ? "ON" : "OFF");
38 return 0;
39 default:
40 return CMD_RET_USAGE;
41 }
42 return 0;
43}
44
45static int do_dcache(struct cmd_tbl *cmdtp, int flag, int argc,
46 char *const argv[])
47{
48 switch (argc) {
49 case 2: /* on / off / flush */
50 switch (parse_argv(argv[1])) {
51 case 0:
52 dcache_disable();
53 break;
54 case 1:
55 dcache_enable();
56#ifdef CONFIG_SYS_NONCACHED_MEMORY
57 noncached_set_region();
58#endif
59 break;
60 case 2:
61 flush_dcache_all();
62 break;
63 default:
64 return CMD_RET_USAGE;
65 }
66 break;
67 case 1: /* get status */
68 printf("Data (writethrough) Cache is %s\n",
69 dcache_status() ? "ON" : "OFF");
70 return 0;
71 default:
72 return CMD_RET_USAGE;
73 }
74 return 0;
75}
76
77static int parse_argv(const char *s)
78{
79 if (strcmp(s, "flush") == 0)
80 return 2;
81 else if (strcmp(s, "on") == 0)
82 return 1;
83 else if (strcmp(s, "off") == 0)
84 return 0;
85
86 return -1;
87}
88
89U_BOOT_CMD(
90 icache, 2, 1, do_icache,
91 "enable or disable instruction cache",
92 "[on, off, flush]\n"
93 " - enable, disable, or flush instruction cache"
94);
95
96U_BOOT_CMD(
97 dcache, 2, 1, do_dcache,
98 "enable or disable data cache",
99 "[on, off, flush]\n"
100 " - enable, disable, or flush data (writethrough) cache"
101);