]> Git Repo - u-boot.git/blob - cmd/cache.c
Merge patch series "Generate all SR boot binaries"
[u-boot.git] / cmd / cache.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2000
4  * Wolfgang Denk, DENX Software Engineering, [email protected].
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
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 __weak void noncached_set_region(void)
23 {
24 }
25
26 static int do_icache(struct cmd_tbl *cmdtp, int flag, int argc,
27                      char *const argv[])
28 {
29         switch (argc) {
30         case 2:                 /* on / off / flush */
31                 switch (parse_argv(argv[1])) {
32                 case 0:
33                         icache_disable();
34                         break;
35                 case 1:
36                         icache_enable();
37                         break;
38                 case 2:
39                         invalidate_icache_all();
40                         break;
41                 default:
42                         return CMD_RET_USAGE;
43                 }
44                 break;
45         case 1:                 /* get status */
46                 printf("Instruction Cache is %s\n",
47                         icache_status() ? "ON" : "OFF");
48                 return 0;
49         default:
50                 return CMD_RET_USAGE;
51         }
52         return 0;
53 }
54
55 void __weak flush_dcache_all(void)
56 {
57         puts("No arch specific flush_dcache_all available!\n");
58         /* please define arch specific flush_dcache_all */
59 }
60
61 static int do_dcache(struct cmd_tbl *cmdtp, int flag, int argc,
62                      char *const argv[])
63 {
64         switch (argc) {
65         case 2:                 /* on / off / flush */
66                 switch (parse_argv(argv[1])) {
67                 case 0:
68                         dcache_disable();
69                         break;
70                 case 1:
71                         dcache_enable();
72                         noncached_set_region();
73                         break;
74                 case 2:
75                         flush_dcache_all();
76                         break;
77                 default:
78                         return CMD_RET_USAGE;
79                 }
80                 break;
81         case 1:                 /* get status */
82                 printf("Data (writethrough) Cache is %s\n",
83                         dcache_status() ? "ON" : "OFF");
84                 return 0;
85         default:
86                 return CMD_RET_USAGE;
87         }
88         return 0;
89 }
90
91 static int parse_argv(const char *s)
92 {
93         if (strcmp(s, "flush") == 0)
94                 return 2;
95         else if (strcmp(s, "on") == 0)
96                 return 1;
97         else if (strcmp(s, "off") == 0)
98                 return 0;
99
100         return -1;
101 }
102
103
104 U_BOOT_CMD(
105         icache,   2,   1,     do_icache,
106         "enable or disable instruction cache",
107         "[on, off, flush]\n"
108         "    - enable, disable, or flush instruction cache"
109 );
110
111 U_BOOT_CMD(
112         dcache,   2,   1,     do_dcache,
113         "enable or disable data cache",
114         "[on, off, flush]\n"
115         "    - enable, disable, or flush data (writethrough) cache"
116 );
This page took 0.032636 seconds and 4 git commands to generate.