cache.c 2.2 KB

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