cmd_cache.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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: icache_disable();
  41. break;
  42. case 1: icache_enable ();
  43. break;
  44. case 2: invalidate_icache_all();
  45. break;
  46. }
  47. /* FALL TROUGH */
  48. case 1: /* get status */
  49. printf ("Instruction Cache is %s\n",
  50. icache_status() ? "ON" : "OFF");
  51. return 0;
  52. default:
  53. return CMD_RET_USAGE;
  54. }
  55. return 0;
  56. }
  57. void __weak flush_dcache_all(void)
  58. {
  59. puts("No arch specific flush_dcache_all available!\n");
  60. /* please define arch specific flush_dcache_all */
  61. }
  62. int do_dcache ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  63. {
  64. switch (argc) {
  65. case 2: /* on / off */
  66. switch (parse_argv(argv[1])) {
  67. case 0: dcache_disable();
  68. break;
  69. case 1: dcache_enable ();
  70. break;
  71. case 2: flush_dcache_all();
  72. break;
  73. }
  74. /* FALL TROUGH */
  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. }
  93. return (-1);
  94. }
  95. U_BOOT_CMD(
  96. icache, 2, 1, do_icache,
  97. "enable or disable instruction cache",
  98. "[on, off, flush]\n"
  99. " - enable, disable, or flush instruction cache"
  100. );
  101. U_BOOT_CMD(
  102. dcache, 2, 1, do_dcache,
  103. "enable or disable data cache",
  104. "[on, off, flush]\n"
  105. " - enable, disable, or flush data (writethrough) cache"
  106. );