cache.c 2 KB
Newer Older
wdenk's avatar
wdenk committed
1 2 3 4
/*
 * (C) Copyright 2000
 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
 *
5
 * SPDX-License-Identifier:	GPL-2.0+
wdenk's avatar
wdenk committed
6 7 8 9 10 11 12
 */

/*
 * Cache support: switch on or off, get status
 */
#include <common.h>
#include <command.h>
13
#include <linux/compiler.h>
wdenk's avatar
wdenk committed
14

15 16
static int parse_argv(const char *);

17
void __weak invalidate_icache_all(void)
18
{
19 20
	/* please define arch specific invalidate_icache_all */
	puts("No arch specific invalidate_icache_all available!\n");
21
}
wdenk's avatar
wdenk committed
22

23
static int do_icache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk's avatar
wdenk committed
24 25 26
{
	switch (argc) {
	case 2:			/* on / off	*/
27
		switch (parse_argv(argv[1])) {
28 29
		case 0:
			icache_disable();
wdenk's avatar
wdenk committed
30
			break;
31 32
		case 1:
			icache_enable();
wdenk's avatar
wdenk committed
33
			break;
34 35
		case 2:
			invalidate_icache_all();
36
			break;
wdenk's avatar
wdenk committed
37
		}
38
		break;
wdenk's avatar
wdenk committed
39
	case 1:			/* get status */
40
		printf("Instruction Cache is %s\n",
wdenk's avatar
wdenk committed
41 42 43
			icache_status() ? "ON" : "OFF");
		return 0;
	default:
44
		return CMD_RET_USAGE;
wdenk's avatar
wdenk committed
45 46 47 48
	}
	return 0;
}

49
void __weak flush_dcache_all(void)
50
{
51 52
	puts("No arch specific flush_dcache_all available!\n");
	/* 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[])
wdenk's avatar
wdenk committed
56 57
{
	switch (argc) {
58
	case 2:			/* on / off */
59
		switch (parse_argv(argv[1])) {
60 61
		case 0:
			dcache_disable();
wdenk's avatar
wdenk committed
62
			break;
63 64
		case 1:
			dcache_enable();
wdenk's avatar
wdenk committed
65
			break;
66 67
		case 2:
			flush_dcache_all();
68
			break;
wdenk's avatar
wdenk committed
69
		}
70
		break;
wdenk's avatar
wdenk committed
71
	case 1:			/* get status */
72
		printf("Data (writethrough) Cache is %s\n",
wdenk's avatar
wdenk committed
73 74 75
			dcache_status() ? "ON" : "OFF");
		return 0;
	default:
76
		return CMD_RET_USAGE;
wdenk's avatar
wdenk committed
77 78 79 80
	}
	return 0;
}

81
static int parse_argv(const char *s)
wdenk's avatar
wdenk committed
82
{
83 84 85 86 87 88 89 90
	if (strcmp(s, "flush") == 0)
		return 2;
	else if (strcmp(s, "on") == 0)
		return 1;
	else if (strcmp(s, "off") == 0)
		return 0;

	return -1;
wdenk's avatar
wdenk committed
91 92
}

wdenk's avatar
wdenk committed
93

94 95
U_BOOT_CMD(
	icache,   2,   1,     do_icache,
Peter Tyser's avatar
Peter Tyser committed
96
	"enable or disable instruction cache",
97 98
	"[on, off, flush]\n"
	"    - enable, disable, or flush instruction cache"
wdenk's avatar
wdenk committed
99 100
);

101 102
U_BOOT_CMD(
	dcache,   2,   1,     do_dcache,
Peter Tyser's avatar
Peter Tyser committed
103
	"enable or disable data cache",
104 105
	"[on, off, flush]\n"
	"    - enable, disable, or flush data (writethrough) cache"
wdenk's avatar
wdenk committed
106
);