cache.c 2.1 KB

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