uboot/cmd/cache.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0+
   2/*
   3 * (C) Copyright 2000
   4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
   5 */
   6
   7/*
   8 * Cache support: switch on or off, get status
   9 */
  10#include <common.h>
  11#include <command.h>
  12#include <cpu_func.h>
  13#include <linux/compiler.h>
  14
  15static int parse_argv(const char *);
  16
  17void __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__weak void noncached_set_region(void)
  24{
  25}
  26
  27static int do_icache(struct cmd_tbl *cmdtp, int flag, int argc,
  28                     char *const argv[])
  29{
  30        switch (argc) {
  31        case 2:                 /* on / off / flush */
  32                switch (parse_argv(argv[1])) {
  33                case 0:
  34                        icache_disable();
  35                        break;
  36                case 1:
  37                        icache_enable();
  38                        break;
  39                case 2:
  40                        invalidate_icache_all();
  41                        break;
  42                default:
  43                        return CMD_RET_USAGE;
  44                }
  45                break;
  46        case 1:                 /* get status */
  47                printf("Instruction Cache is %s\n",
  48                        icache_status() ? "ON" : "OFF");
  49                return 0;
  50        default:
  51                return CMD_RET_USAGE;
  52        }
  53        return 0;
  54}
  55
  56void __weak flush_dcache_all(void)
  57{
  58        puts("No arch specific flush_dcache_all available!\n");
  59        /* please define arch specific flush_dcache_all */
  60}
  61
  62static int do_dcache(struct cmd_tbl *cmdtp, int flag, int argc,
  63                     char *const argv[])
  64{
  65        switch (argc) {
  66        case 2:                 /* on / off / flush */
  67                switch (parse_argv(argv[1])) {
  68                case 0:
  69                        dcache_disable();
  70                        break;
  71                case 1:
  72                        dcache_enable();
  73                        noncached_set_region();
  74                        break;
  75                case 2:
  76                        flush_dcache_all();
  77                        break;
  78                default:
  79                        return CMD_RET_USAGE;
  80                }
  81                break;
  82        case 1:                 /* get status */
  83                printf("Data (writethrough) Cache is %s\n",
  84                        dcache_status() ? "ON" : "OFF");
  85                return 0;
  86        default:
  87                return CMD_RET_USAGE;
  88        }
  89        return 0;
  90}
  91
  92static int parse_argv(const char *s)
  93{
  94        if (strcmp(s, "flush") == 0)
  95                return 2;
  96        else if (strcmp(s, "on") == 0)
  97                return 1;
  98        else if (strcmp(s, "off") == 0)
  99                return 0;
 100
 101        return -1;
 102}
 103
 104
 105U_BOOT_CMD(
 106        icache,   2,   1,     do_icache,
 107        "enable or disable instruction cache",
 108        "[on, off, flush]\n"
 109        "    - enable, disable, or flush instruction cache"
 110);
 111
 112U_BOOT_CMD(
 113        dcache,   2,   1,     do_dcache,
 114        "enable or disable data cache",
 115        "[on, off, flush]\n"
 116        "    - enable, disable, or flush data (writethrough) cache"
 117);
 118