cache.c 2.0 KB

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