]> git.sur5r.net Git - u-boot/blob - common/cmd_cache.c
bfin: make env offset sector aligned for bct-brettl2 and ibf-dsp561 boards
[u-boot] / common / cmd_cache.c
1 /*
2  * (C) Copyright 2000
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 /*
9  * Cache support: switch on or off, get status
10  */
11 #include <common.h>
12 #include <command.h>
13 #include <linux/compiler.h>
14
15 static int parse_argv(const char *);
16
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
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     */
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                 }
38                 break;
39         case 1:                 /* get status */
40                 printf("Instruction Cache is %s\n",
41                         icache_status() ? "ON" : "OFF");
42                 return 0;
43         default:
44                 return CMD_RET_USAGE;
45         }
46         return 0;
47 }
48
49 void __weak flush_dcache_all(void)
50 {
51         puts("No arch specific flush_dcache_all available!\n");
52         /* please define arch specific flush_dcache_all */
53 }
54
55 static int do_dcache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
56 {
57         switch (argc) {
58         case 2:                 /* on / off */
59                 switch (parse_argv(argv[1])) {
60                 case 0:
61                         dcache_disable();
62                         break;
63                 case 1:
64                         dcache_enable();
65                         break;
66                 case 2:
67                         flush_dcache_all();
68                         break;
69                 }
70                 break;
71         case 1:                 /* get status */
72                 printf("Data (writethrough) Cache is %s\n",
73                         dcache_status() ? "ON" : "OFF");
74                 return 0;
75         default:
76                 return CMD_RET_USAGE;
77         }
78         return 0;
79 }
80
81 static int parse_argv(const char *s)
82 {
83         if (strcmp(s, "flush") == 0)
84                 return 2;
85         else if (strcmp(s, "on") == 0)
86                 return 1;
87         else if (strcmp(s, "off") == 0)
88                 return 0;
89
90         return -1;
91 }
92
93
94 U_BOOT_CMD(
95         icache,   2,   1,     do_icache,
96         "enable or disable instruction cache",
97         "[on, off, flush]\n"
98         "    - enable, disable, or flush instruction cache"
99 );
100
101 U_BOOT_CMD(
102         dcache,   2,   1,     do_dcache,
103         "enable or disable data cache",
104         "[on, off, flush]\n"
105         "    - enable, disable, or flush data (writethrough) cache"
106 );