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 ulong start, size; 58 59 switch (argc) { 60 case 4: 61 start = simple_strtoul(argv[2], NULL, 16); 62 size = simple_strtoul(argv[3], NULL, 16); 63 64 switch (parse_argv(argv[1])) { 65 case 2: 66 printf("flush dcache: 0x%08lx - 0x%08lx\n", start, start + size); 67 flush_dcache_range(start, start + size); 68 break; 69 case 3: 70 printf("invalidate dcache: 0x%08lx - 0x%08lx\n", start, start + size); 71 invalidate_dcache_range(start, start + size); 72 break; 73 } 74 break; 75 case 2: /* on / off */ 76 switch (parse_argv(argv[1])) { 77 case 0: 78 dcache_disable(); 79 break; 80 case 1: 81 dcache_enable(); 82 break; 83 case 2: 84 flush_dcache_all(); 85 break; 86 case 3: 87 printf("error: dcache invalidate require [start] [size]\n"); 88 break; 89 } 90 break; 91 case 1: /* get status */ 92 printf("Data (writethrough) Cache is %s\n", 93 dcache_status() ? "ON" : "OFF"); 94 return 0; 95 default: 96 return CMD_RET_USAGE; 97 } 98 return 0; 99 } 100 101 static int parse_argv(const char *s) 102 { 103 if (strcmp(s, "invalidate") == 0) 104 return 3; 105 else if (strcmp(s, "flush") == 0) 106 return 2; 107 else if (strcmp(s, "on") == 0) 108 return 1; 109 else if (strcmp(s, "off") == 0) 110 return 0; 111 112 return -1; 113 } 114 115 116 U_BOOT_CMD( 117 icache, 2, 1, do_icache, 118 "enable or disable instruction cache", 119 "[on, off, flush]\n" 120 " - enable, disable, or flush instruction cache" 121 ); 122 123 U_BOOT_CMD( 124 dcache, 4, 1, do_dcache, 125 "enable or disable data cache", 126 "[on, off, flush, invalidate] [start] [size]\n" 127 " - enable, disable, or flush data (writethrough) cache" 128 ); 129