]>
Commit | Line | Data |
---|---|---|
3863585b WD |
1 | /* |
2 | * (C) Copyright 2000 | |
3 | * Wolfgang Denk, DENX Software Engineering, [email protected]. | |
4 | * | |
1a459660 | 5 | * SPDX-License-Identifier: GPL-2.0+ |
3863585b WD |
6 | */ |
7 | ||
8 | /* | |
9 | * Cache support: switch on or off, get status | |
10 | */ | |
11 | #include <common.h> | |
12 | #include <command.h> | |
d0c4c338 | 13 | #include <linux/compiler.h> |
3863585b | 14 | |
d0c4c338 MM |
15 | static int parse_argv(const char *); |
16 | ||
23498935 | 17 | void __weak invalidate_icache_all(void) |
d0c4c338 | 18 | { |
23498935 SK |
19 | /* please define arch specific invalidate_icache_all */ |
20 | puts("No arch specific invalidate_icache_all available!\n"); | |
d0c4c338 | 21 | } |
3863585b | 22 | |
0e350f81 | 23 | static int do_icache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
3863585b WD |
24 | { |
25 | switch (argc) { | |
26 | case 2: /* on / off */ | |
d0c4c338 | 27 | switch (parse_argv(argv[1])) { |
e9455fcc JH |
28 | case 0: |
29 | icache_disable(); | |
3863585b | 30 | break; |
e9455fcc JH |
31 | case 1: |
32 | icache_enable(); | |
3863585b | 33 | break; |
e9455fcc JH |
34 | case 2: |
35 | invalidate_icache_all(); | |
d0c4c338 | 36 | break; |
3863585b | 37 | } |
36180d96 | 38 | break; |
3863585b | 39 | case 1: /* get status */ |
e9455fcc | 40 | printf("Instruction Cache is %s\n", |
3863585b WD |
41 | icache_status() ? "ON" : "OFF"); |
42 | return 0; | |
43 | default: | |
4c12eeb8 | 44 | return CMD_RET_USAGE; |
3863585b WD |
45 | } |
46 | return 0; | |
47 | } | |
48 | ||
23498935 | 49 | void __weak flush_dcache_all(void) |
d0c4c338 | 50 | { |
23498935 SK |
51 | puts("No arch specific flush_dcache_all available!\n"); |
52 | /* please define arch specific flush_dcache_all */ | |
d0c4c338 MM |
53 | } |
54 | ||
0e350f81 | 55 | static int do_dcache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
3863585b WD |
56 | { |
57 | switch (argc) { | |
e9455fcc | 58 | case 2: /* on / off */ |
d0c4c338 | 59 | switch (parse_argv(argv[1])) { |
e9455fcc JH |
60 | case 0: |
61 | dcache_disable(); | |
3863585b | 62 | break; |
e9455fcc JH |
63 | case 1: |
64 | dcache_enable(); | |
3863585b | 65 | break; |
e9455fcc JH |
66 | case 2: |
67 | flush_dcache_all(); | |
d0c4c338 | 68 | break; |
3863585b | 69 | } |
e9455fcc | 70 | break; |
3863585b | 71 | case 1: /* get status */ |
e9455fcc | 72 | printf("Data (writethrough) Cache is %s\n", |
3863585b WD |
73 | dcache_status() ? "ON" : "OFF"); |
74 | return 0; | |
75 | default: | |
4c12eeb8 | 76 | return CMD_RET_USAGE; |
3863585b WD |
77 | } |
78 | return 0; | |
3863585b WD |
79 | } |
80 | ||
d0c4c338 | 81 | static int parse_argv(const char *s) |
3863585b | 82 | { |
e9455fcc JH |
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; | |
3863585b WD |
91 | } |
92 | ||
8bde7f77 | 93 | |
0d498393 WD |
94 | U_BOOT_CMD( |
95 | icache, 2, 1, do_icache, | |
2fb2604d | 96 | "enable or disable instruction cache", |
d0c4c338 MM |
97 | "[on, off, flush]\n" |
98 | " - enable, disable, or flush instruction cache" | |
8bde7f77 WD |
99 | ); |
100 | ||
0d498393 WD |
101 | U_BOOT_CMD( |
102 | dcache, 2, 1, do_dcache, | |
2fb2604d | 103 | "enable or disable data cache", |
d0c4c338 MM |
104 | "[on, off, flush]\n" |
105 | " - enable, disable, or flush data (writethrough) cache" | |
8bde7f77 | 106 | ); |