blob: 0254ff17f9b242f7e8e63058f90f3529b186e455 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk38635852002-08-27 05:55:31 +00002/*
3 * (C) Copyright 2000
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenk38635852002-08-27 05:55:31 +00005 */
6
7/*
8 * Cache support: switch on or off, get status
9 */
wdenk38635852002-08-27 05:55:31 +000010#include <command.h>
Simon Glass1d91ba72019-11-14 12:57:37 -070011#include <cpu_func.h>
Matthew McClintocka14695e2011-05-24 10:09:05 +000012#include <linux/compiler.h>
wdenk38635852002-08-27 05:55:31 +000013
Matthew McClintocka14695e2011-05-24 10:09:05 +000014static int parse_argv(const char *);
15
Stefan Kristianssona7416052011-10-31 18:21:12 +000016void __weak invalidate_icache_all(void)
Matthew McClintocka14695e2011-05-24 10:09:05 +000017{
Stefan Kristianssona7416052011-10-31 18:21:12 +000018 /* please define arch specific invalidate_icache_all */
19 puts("No arch specific invalidate_icache_all available!\n");
Matthew McClintocka14695e2011-05-24 10:09:05 +000020}
wdenk38635852002-08-27 05:55:31 +000021
Patrice Chotarde2eb7212020-04-28 11:38:03 +020022__weak void noncached_set_region(void)
23{
24}
25
Simon Glassed38aef2020-05-10 11:40:03 -060026static int do_icache(struct cmd_tbl *cmdtp, int flag, int argc,
27 char *const argv[])
wdenk38635852002-08-27 05:55:31 +000028{
29 switch (argc) {
Eric Perie86b7ba52019-07-13 14:54:58 -040030 case 2: /* on / off / flush */
Matthew McClintocka14695e2011-05-24 10:09:05 +000031 switch (parse_argv(argv[1])) {
Joe Hershberger3745b8c2012-10-03 10:56:16 +000032 case 0:
33 icache_disable();
wdenk38635852002-08-27 05:55:31 +000034 break;
Joe Hershberger3745b8c2012-10-03 10:56:16 +000035 case 1:
36 icache_enable();
wdenk38635852002-08-27 05:55:31 +000037 break;
Joe Hershberger3745b8c2012-10-03 10:56:16 +000038 case 2:
39 invalidate_icache_all();
Matthew McClintocka14695e2011-05-24 10:09:05 +000040 break;
Eric Perie86b7ba52019-07-13 14:54:58 -040041 default:
42 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000043 }
Joe Hershberger8cab1562012-10-03 10:56:17 +000044 break;
wdenk38635852002-08-27 05:55:31 +000045 case 1: /* get status */
Joe Hershberger3745b8c2012-10-03 10:56:16 +000046 printf("Instruction Cache is %s\n",
wdenk38635852002-08-27 05:55:31 +000047 icache_status() ? "ON" : "OFF");
48 return 0;
49 default:
Simon Glassa06dfc72011-12-10 08:44:01 +000050 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000051 }
52 return 0;
53}
54
Stefan Kristianssona7416052011-10-31 18:21:12 +000055void __weak flush_dcache_all(void)
Matthew McClintocka14695e2011-05-24 10:09:05 +000056{
Stefan Kristianssona7416052011-10-31 18:21:12 +000057 puts("No arch specific flush_dcache_all available!\n");
58 /* please define arch specific flush_dcache_all */
Matthew McClintocka14695e2011-05-24 10:09:05 +000059}
60
Simon Glassed38aef2020-05-10 11:40:03 -060061static int do_dcache(struct cmd_tbl *cmdtp, int flag, int argc,
62 char *const argv[])
wdenk38635852002-08-27 05:55:31 +000063{
64 switch (argc) {
Eric Perie86b7ba52019-07-13 14:54:58 -040065 case 2: /* on / off / flush */
Matthew McClintocka14695e2011-05-24 10:09:05 +000066 switch (parse_argv(argv[1])) {
Joe Hershberger3745b8c2012-10-03 10:56:16 +000067 case 0:
68 dcache_disable();
wdenk38635852002-08-27 05:55:31 +000069 break;
Joe Hershberger3745b8c2012-10-03 10:56:16 +000070 case 1:
71 dcache_enable();
Patrice Chotarde2eb7212020-04-28 11:38:03 +020072 noncached_set_region();
wdenk38635852002-08-27 05:55:31 +000073 break;
Joe Hershberger3745b8c2012-10-03 10:56:16 +000074 case 2:
75 flush_dcache_all();
Matthew McClintocka14695e2011-05-24 10:09:05 +000076 break;
Eric Perie86b7ba52019-07-13 14:54:58 -040077 default:
78 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000079 }
Joe Hershberger3745b8c2012-10-03 10:56:16 +000080 break;
wdenk38635852002-08-27 05:55:31 +000081 case 1: /* get status */
Joe Hershberger3745b8c2012-10-03 10:56:16 +000082 printf("Data (writethrough) Cache is %s\n",
wdenk38635852002-08-27 05:55:31 +000083 dcache_status() ? "ON" : "OFF");
84 return 0;
85 default:
Simon Glassa06dfc72011-12-10 08:44:01 +000086 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000087 }
88 return 0;
wdenk38635852002-08-27 05:55:31 +000089}
90
Matthew McClintocka14695e2011-05-24 10:09:05 +000091static int parse_argv(const char *s)
wdenk38635852002-08-27 05:55:31 +000092{
Joe Hershberger3745b8c2012-10-03 10:56:16 +000093 if (strcmp(s, "flush") == 0)
94 return 2;
95 else if (strcmp(s, "on") == 0)
96 return 1;
97 else if (strcmp(s, "off") == 0)
98 return 0;
99
100 return -1;
wdenk38635852002-08-27 05:55:31 +0000101}
102
wdenk57b2d802003-06-27 21:31:46 +0000103
wdenkf287a242003-07-01 21:06:45 +0000104U_BOOT_CMD(
105 icache, 2, 1, do_icache,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600106 "enable or disable instruction cache",
Matthew McClintocka14695e2011-05-24 10:09:05 +0000107 "[on, off, flush]\n"
108 " - enable, disable, or flush instruction cache"
wdenk57b2d802003-06-27 21:31:46 +0000109);
110
wdenkf287a242003-07-01 21:06:45 +0000111U_BOOT_CMD(
112 dcache, 2, 1, do_dcache,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600113 "enable or disable data cache",
Matthew McClintocka14695e2011-05-24 10:09:05 +0000114 "[on, off, flush]\n"
115 " - enable, disable, or flush data (writethrough) cache"
wdenk57b2d802003-06-27 21:31:46 +0000116);