cache.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * (C) Copyright 2007
  3. * Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
  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 <command.h>
  25. #include <asm/processor.h>
  26. #include <asm/io.h>
  27. /*
  28. * Jump to P2 area.
  29. * When handling TLB or caches, we need to do it from P2 area.
  30. */
  31. #define jump_to_P2() \
  32. do { \
  33. unsigned long __dummy; \
  34. __asm__ __volatile__( \
  35. "mov.l 1f, %0\n\t" \
  36. "or %1, %0\n\t" \
  37. "jmp @%0\n\t" \
  38. " nop\n\t" \
  39. ".balign 4\n" \
  40. "1: .long 2f\n" \
  41. "2:" \
  42. : "=&r" (__dummy) \
  43. : "r" (0x20000000)); \
  44. } while (0)
  45. /*
  46. * Back to P1 area.
  47. */
  48. #define back_to_P1() \
  49. do { \
  50. unsigned long __dummy; \
  51. __asm__ __volatile__( \
  52. "nop;nop;nop;nop;nop;nop;nop\n\t" \
  53. "mov.l 1f, %0\n\t" \
  54. "jmp @%0\n\t" \
  55. " nop\n\t" \
  56. ".balign 4\n" \
  57. "1: .long 2f\n" \
  58. "2:" \
  59. : "=&r" (__dummy)); \
  60. } while (0)
  61. #define CACHE_VALID 1
  62. #define CACHE_UPDATED 2
  63. static inline void cache_wback_all(void)
  64. {
  65. unsigned long addr, data, i, j;
  66. jump_to_P2();
  67. for (i = 0; i < CACHE_OC_NUM_ENTRIES; i++){
  68. for (j = 0; j < CACHE_OC_NUM_WAYS; j++) {
  69. addr = CACHE_OC_ADDRESS_ARRAY | (j << CACHE_OC_WAY_SHIFT)
  70. | (i << CACHE_OC_ENTRY_SHIFT);
  71. data = inl(addr);
  72. if (data & CACHE_UPDATED) {
  73. data &= ~CACHE_UPDATED;
  74. outl(data, addr);
  75. }
  76. }
  77. }
  78. back_to_P1();
  79. }
  80. #define CACHE_ENABLE 0
  81. #define CACHE_DISABLE 1
  82. int cache_control(unsigned int cmd)
  83. {
  84. unsigned long ccr;
  85. jump_to_P2();
  86. ccr = inl(CCR);
  87. if (ccr & CCR_CACHE_ENABLE)
  88. cache_wback_all();
  89. if (cmd == CACHE_DISABLE)
  90. outl(CCR_CACHE_STOP, CCR);
  91. else
  92. outl(CCR_CACHE_INIT, CCR);
  93. back_to_P1();
  94. return 0;
  95. }