cmd_cache.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * (C) Copyright 2000
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  24. * Cache support: switch on or off, get status
  25. */
  26. #include <common.h>
  27. #include <command.h>
  28. #include <linux/compiler.h>
  29. static int parse_argv(const char *);
  30. void __weak invalidate_icache_all(void)
  31. {
  32. /* please define arch specific invalidate_icache_all */
  33. puts("No arch specific invalidate_icache_all available!\n");
  34. }
  35. int do_icache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  36. {
  37. switch (argc) {
  38. case 2: /* on / off */
  39. switch (parse_argv(argv[1])) {
  40. case 0:
  41. icache_disable();
  42. break;
  43. case 1:
  44. icache_enable();
  45. break;
  46. case 2:
  47. invalidate_icache_all();
  48. break;
  49. }
  50. break;
  51. case 1: /* get status */
  52. printf("Instruction Cache is %s\n",
  53. icache_status() ? "ON" : "OFF");
  54. return 0;
  55. default:
  56. return CMD_RET_USAGE;
  57. }
  58. return 0;
  59. }
  60. void __weak flush_dcache_all(void)
  61. {
  62. puts("No arch specific flush_dcache_all available!\n");
  63. /* please define arch specific flush_dcache_all */
  64. }
  65. int do_dcache(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  66. {
  67. switch (argc) {
  68. case 2: /* on / off */
  69. switch (parse_argv(argv[1])) {
  70. case 0:
  71. dcache_disable();
  72. break;
  73. case 1:
  74. dcache_enable();
  75. break;
  76. case 2:
  77. flush_dcache_all();
  78. break;
  79. }
  80. break;
  81. case 1: /* get status */
  82. printf("Data (writethrough) Cache is %s\n",
  83. dcache_status() ? "ON" : "OFF");
  84. return 0;
  85. default:
  86. return CMD_RET_USAGE;
  87. }
  88. return 0;
  89. }
  90. static int parse_argv(const char *s)
  91. {
  92. if (strcmp(s, "flush") == 0)
  93. return 2;
  94. else if (strcmp(s, "on") == 0)
  95. return 1;
  96. else if (strcmp(s, "off") == 0)
  97. return 0;
  98. return -1;
  99. }
  100. U_BOOT_CMD(
  101. icache, 2, 1, do_icache,
  102. "enable or disable instruction cache",
  103. "[on, off, flush]\n"
  104. " - enable, disable, or flush instruction cache"
  105. );
  106. U_BOOT_CMD(
  107. dcache, 2, 1, do_dcache,
  108. "enable or disable data cache",
  109. "[on, off, flush]\n"
  110. " - enable, disable, or flush data (writethrough) cache"
  111. );