cache.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * (C) Copyright 2007
  3. * Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com>
  4. *
  5. * Copyright (C) 2007, 2008 Nobobuhiro Iwamatsu <iwamatsu@nigauri.org>
  6. * Copyright (C) 2008 Renesas Solutions Corp.
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <command.h>
  28. #include <asm/processor.h>
  29. #include <asm/io.h>
  30. /*
  31. * Jump to P2 area.
  32. * When handling TLB or caches, we need to do it from P2 area.
  33. */
  34. #define jump_to_P2() \
  35. do { \
  36. unsigned long __dummy; \
  37. __asm__ __volatile__( \
  38. "mov.l 1f, %0\n\t" \
  39. "or %1, %0\n\t" \
  40. "jmp @%0\n\t" \
  41. " nop\n\t" \
  42. ".balign 4\n" \
  43. "1: .long 2f\n" \
  44. "2:" \
  45. : "=&r" (__dummy) \
  46. : "r" (0x20000000)); \
  47. } while (0)
  48. /*
  49. * Back to P1 area.
  50. */
  51. #define back_to_P1() \
  52. do { \
  53. unsigned long __dummy; \
  54. __asm__ __volatile__( \
  55. "nop;nop;nop;nop;nop;nop;nop\n\t" \
  56. "mov.l 1f, %0\n\t" \
  57. "jmp @%0\n\t" \
  58. " nop\n\t" \
  59. ".balign 4\n" \
  60. "1: .long 2f\n" \
  61. "2:" \
  62. : "=&r" (__dummy)); \
  63. } while (0)
  64. #define CACHE_VALID 1
  65. #define CACHE_UPDATED 2
  66. static inline void cache_wback_all(void)
  67. {
  68. unsigned long addr, data, i, j;
  69. jump_to_P2();
  70. for (i = 0; i < CACHE_OC_NUM_ENTRIES; i++) {
  71. for (j = 0; j < CACHE_OC_NUM_WAYS; j++) {
  72. addr = CACHE_OC_ADDRESS_ARRAY
  73. | (j << CACHE_OC_WAY_SHIFT)
  74. | (i << CACHE_OC_ENTRY_SHIFT);
  75. data = inl(addr);
  76. if (data & CACHE_UPDATED) {
  77. data &= ~CACHE_UPDATED;
  78. outl(data, addr);
  79. }
  80. }
  81. }
  82. back_to_P1();
  83. }
  84. #define CACHE_ENABLE 0
  85. #define CACHE_DISABLE 1
  86. int cache_control(unsigned int cmd)
  87. {
  88. unsigned long ccr;
  89. jump_to_P2();
  90. ccr = inl(CCR);
  91. if (ccr & CCR_CACHE_ENABLE)
  92. cache_wback_all();
  93. if (cmd == CACHE_DISABLE)
  94. outl(CCR_CACHE_STOP, CCR);
  95. else
  96. outl(CCR_CACHE_INIT, CCR);
  97. back_to_P1();
  98. return 0;
  99. }