cache.c 2.0 KB

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