cache.c 2.1 KB

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