Merge branch '2019-10-28-azure-ci-support'
[oweals/u-boot.git] / cmd / cache.c
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
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
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 / flush */
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                 default:
37                         return CMD_RET_USAGE;
38                 }
39                 break;
40         case 1:                 /* get status */
41                 printf("Instruction Cache is %s\n",
42                         icache_status() ? "ON" : "OFF");
43                 return 0;
44         default:
45                 return CMD_RET_USAGE;
46         }
47         return 0;
48 }
49
50 void __weak flush_dcache_all(void)
51 {
52         puts("No arch specific flush_dcache_all available!\n");
53         /* please define arch specific flush_dcache_all */
54 }
55
56 static int do_dcache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
57 {
58         switch (argc) {
59         case 2:                 /* on / off / flush */
60                 switch (parse_argv(argv[1])) {
61                 case 0:
62                         dcache_disable();
63                         break;
64                 case 1:
65                         dcache_enable();
66                         break;
67                 case 2:
68                         flush_dcache_all();
69                         break;
70                 default:
71                         return CMD_RET_USAGE;
72                 }
73                 break;
74         case 1:                 /* get status */
75                 printf("Data (writethrough) Cache is %s\n",
76                         dcache_status() ? "ON" : "OFF");
77                 return 0;
78         default:
79                 return CMD_RET_USAGE;
80         }
81         return 0;
82 }
83
84 static int parse_argv(const char *s)
85 {
86         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;
94 }
95
96
97 U_BOOT_CMD(
98         icache,   2,   1,     do_icache,
99         "enable or disable instruction cache",
100         "[on, off, flush]\n"
101         "    - enable, disable, or flush instruction cache"
102 );
103
104 U_BOOT_CMD(
105         dcache,   2,   1,     do_dcache,
106         "enable or disable data cache",
107         "[on, off, flush]\n"
108         "    - enable, disable, or flush data (writethrough) cache"
109 );