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