Blame view

cmd/cache.c 2 KB
3863585bb   wdenk   Initial revision
1
2
3
4
  /*
   * (C) Copyright 2000
   * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
   *
1a4596601   Wolfgang Denk   Add GPL-2.0+ SPDX...
5
   * SPDX-License-Identifier:	GPL-2.0+
3863585bb   wdenk   Initial revision
6
7
8
9
10
11
12
   */
  
  /*
   * Cache support: switch on or off, get status
   */
  #include <common.h>
  #include <command.h>
d0c4c3385   Matthew McClintock   command/cmd_cache...
13
  #include <linux/compiler.h>
3863585bb   wdenk   Initial revision
14

d0c4c3385   Matthew McClintock   command/cmd_cache...
15
  static int parse_argv(const char *);
23498935f   Stefan Kristiansson   cmd_cache: use ca...
16
  void __weak invalidate_icache_all(void)
d0c4c3385   Matthew McClintock   command/cmd_cache...
17
  {
23498935f   Stefan Kristiansson   cmd_cache: use ca...
18
19
20
  	/* please define arch specific invalidate_icache_all */
  	puts("No arch specific invalidate_icache_all available!
  ");
d0c4c3385   Matthew McClintock   command/cmd_cache...
21
  }
3863585bb   wdenk   Initial revision
22

0e350f81e   Jeroen Hofstee   common: commands:...
23
  static int do_icache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585bb   wdenk   Initial revision
24
25
26
  {
  	switch (argc) {
  	case 2:			/* on / off	*/
d0c4c3385   Matthew McClintock   command/cmd_cache...
27
  		switch (parse_argv(argv[1])) {
e9455fcc4   Joe Hershberger   Fix checkpatch.pl...
28
29
  		case 0:
  			icache_disable();
3863585bb   wdenk   Initial revision
30
  			break;
e9455fcc4   Joe Hershberger   Fix checkpatch.pl...
31
32
  		case 1:
  			icache_enable();
3863585bb   wdenk   Initial revision
33
  			break;
e9455fcc4   Joe Hershberger   Fix checkpatch.pl...
34
35
  		case 2:
  			invalidate_icache_all();
d0c4c3385   Matthew McClintock   command/cmd_cache...
36
  			break;
3863585bb   wdenk   Initial revision
37
  		}
36180d96c   Joe Hershberger   Cleanup cache com...
38
  		break;
3863585bb   wdenk   Initial revision
39
  	case 1:			/* get status */
e9455fcc4   Joe Hershberger   Fix checkpatch.pl...
40
41
  		printf("Instruction Cache is %s
  ",
3863585bb   wdenk   Initial revision
42
43
44
  			icache_status() ? "ON" : "OFF");
  		return 0;
  	default:
4c12eeb8b   Simon Glass   Convert cmd_usage...
45
  		return CMD_RET_USAGE;
3863585bb   wdenk   Initial revision
46
47
48
  	}
  	return 0;
  }
23498935f   Stefan Kristiansson   cmd_cache: use ca...
49
  void __weak flush_dcache_all(void)
d0c4c3385   Matthew McClintock   command/cmd_cache...
50
  {
23498935f   Stefan Kristiansson   cmd_cache: use ca...
51
52
53
  	puts("No arch specific flush_dcache_all available!
  ");
  	/* please define arch specific flush_dcache_all */
d0c4c3385   Matthew McClintock   command/cmd_cache...
54
  }
0e350f81e   Jeroen Hofstee   common: commands:...
55
  static int do_dcache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585bb   wdenk   Initial revision
56
57
  {
  	switch (argc) {
e9455fcc4   Joe Hershberger   Fix checkpatch.pl...
58
  	case 2:			/* on / off */
d0c4c3385   Matthew McClintock   command/cmd_cache...
59
  		switch (parse_argv(argv[1])) {
e9455fcc4   Joe Hershberger   Fix checkpatch.pl...
60
61
  		case 0:
  			dcache_disable();
3863585bb   wdenk   Initial revision
62
  			break;
e9455fcc4   Joe Hershberger   Fix checkpatch.pl...
63
64
  		case 1:
  			dcache_enable();
3863585bb   wdenk   Initial revision
65
  			break;
e9455fcc4   Joe Hershberger   Fix checkpatch.pl...
66
67
  		case 2:
  			flush_dcache_all();
d0c4c3385   Matthew McClintock   command/cmd_cache...
68
  			break;
3863585bb   wdenk   Initial revision
69
  		}
e9455fcc4   Joe Hershberger   Fix checkpatch.pl...
70
  		break;
3863585bb   wdenk   Initial revision
71
  	case 1:			/* get status */
e9455fcc4   Joe Hershberger   Fix checkpatch.pl...
72
73
  		printf("Data (writethrough) Cache is %s
  ",
3863585bb   wdenk   Initial revision
74
75
76
  			dcache_status() ? "ON" : "OFF");
  		return 0;
  	default:
4c12eeb8b   Simon Glass   Convert cmd_usage...
77
  		return CMD_RET_USAGE;
3863585bb   wdenk   Initial revision
78
79
  	}
  	return 0;
3863585bb   wdenk   Initial revision
80
  }
d0c4c3385   Matthew McClintock   command/cmd_cache...
81
  static int parse_argv(const char *s)
3863585bb   wdenk   Initial revision
82
  {
e9455fcc4   Joe Hershberger   Fix checkpatch.pl...
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;
3863585bb   wdenk   Initial revision
91
  }
8bde7f776   wdenk   * Code cleanup:
92

0d4983930   wdenk   Patch by Kenneth ...
93
94
  U_BOOT_CMD(
  	icache,   2,   1,     do_icache,
2fb2604d5   Peter Tyser   Command usage cle...
95
  	"enable or disable instruction cache",
d0c4c3385   Matthew McClintock   command/cmd_cache...
96
97
98
  	"[on, off, flush]
  "
  	"    - enable, disable, or flush instruction cache"
8bde7f776   wdenk   * Code cleanup:
99
  );
0d4983930   wdenk   Patch by Kenneth ...
100
101
  U_BOOT_CMD(
  	dcache,   2,   1,     do_dcache,
2fb2604d5   Peter Tyser   Command usage cle...
102
  	"enable or disable data cache",
d0c4c3385   Matthew McClintock   command/cmd_cache...
103
104
105
  	"[on, off, flush]
  "
  	"    - enable, disable, or flush data (writethrough) cache"
8bde7f776   wdenk   * Code cleanup:
106
  );