cache-cp15.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * (C) Copyright 2002
  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. #include <common.h>
  24. #include <asm/system.h>
  25. #if !(defined(CONFIG_SYS_NO_ICACHE) && defined(CONFIG_SYS_NO_DCACHE))
  26. static void cp_delay (void)
  27. {
  28. volatile int i;
  29. /* copro seems to need some delay between reading and writing */
  30. for (i = 0; i < 100; i++)
  31. nop();
  32. }
  33. /* cache_bit must be either CR_I or CR_C */
  34. static void cache_enable(uint32_t cache_bit)
  35. {
  36. uint32_t reg;
  37. reg = get_cr(); /* get control reg. */
  38. cp_delay();
  39. set_cr(reg | cache_bit);
  40. }
  41. /* cache_bit must be either CR_I or CR_C */
  42. static void cache_disable(uint32_t cache_bit)
  43. {
  44. uint32_t reg;
  45. reg = get_cr();
  46. cp_delay();
  47. set_cr(reg & ~cache_bit);
  48. }
  49. #endif
  50. #ifdef CONFIG_SYS_NO_ICACHE
  51. void icache_enable (void)
  52. {
  53. return;
  54. }
  55. void icache_disable (void)
  56. {
  57. return;
  58. }
  59. int icache_status (void)
  60. {
  61. return 0; /* always off */
  62. }
  63. #else
  64. void icache_enable(void)
  65. {
  66. cache_enable(CR_I);
  67. }
  68. void icache_disable(void)
  69. {
  70. cache_disable(CR_I);
  71. }
  72. int icache_status(void)
  73. {
  74. return (get_cr() & CR_I) != 0;
  75. }
  76. #endif
  77. #ifdef CONFIG_SYS_NO_DCACHE
  78. void dcache_enable (void)
  79. {
  80. return;
  81. }
  82. void dcache_disable (void)
  83. {
  84. return;
  85. }
  86. int dcache_status (void)
  87. {
  88. return 0; /* always off */
  89. }
  90. #else
  91. void dcache_enable(void)
  92. {
  93. cache_enable(CR_C);
  94. }
  95. void dcache_disable(void)
  96. {
  97. cache_disable(CR_C);
  98. }
  99. int dcache_status(void)
  100. {
  101. return (get_cr() & CR_C) != 0;
  102. }
  103. #endif