cpu.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * (C) Copyright 2008 Texas Insturments
  3. *
  4. * (C) Copyright 2002
  5. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  6. * Marius Groeger <mgroeger@sysgo.de>
  7. *
  8. * (C) Copyright 2002
  9. * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. /*
  30. * CPU specific code
  31. */
  32. #include <common.h>
  33. #include <command.h>
  34. #include <asm/arch/sys_proto.h>
  35. #include <asm/system.h>
  36. #ifndef CONFIG_L2_OFF
  37. void l2cache_disable(void);
  38. #endif
  39. static void cache_flush(void);
  40. int cleanup_before_linux(void)
  41. {
  42. unsigned int i;
  43. /*
  44. * this function is called just before we call linux
  45. * it prepares the processor for linux
  46. *
  47. * we turn off caches etc ...
  48. */
  49. disable_interrupts();
  50. /* turn off I/D-cache */
  51. icache_disable();
  52. dcache_disable();
  53. /* invalidate I-cache */
  54. cache_flush();
  55. #ifndef CONFIG_L2_OFF
  56. /* turn off L2 cache */
  57. l2cache_disable();
  58. /* invalidate L2 cache also */
  59. v7_flush_dcache_all(get_device_type());
  60. #endif
  61. i = 0;
  62. /* mem barrier to sync up things */
  63. asm("mcr p15, 0, %0, c7, c10, 4": :"r"(i));
  64. #ifndef CONFIG_L2_OFF
  65. l2cache_enable();
  66. #endif
  67. return 0;
  68. }
  69. void l2cache_enable()
  70. {
  71. unsigned long i;
  72. volatile unsigned int j;
  73. /* ES2 onwards we can disable/enable L2 ourselves */
  74. if (get_cpu_rev() >= CPU_3XX_ES20) {
  75. __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
  76. __asm__ __volatile__("orr %0, %0, #0x2":"=r"(i));
  77. __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
  78. } else {
  79. /* Save r0, r12 and restore them after usage */
  80. __asm__ __volatile__("mov %0, r12":"=r"(j));
  81. __asm__ __volatile__("mov %0, r0":"=r"(i));
  82. /*
  83. * GP Device ROM code API usage here
  84. * r12 = AUXCR Write function and r0 value
  85. */
  86. __asm__ __volatile__("mov r12, #0x3");
  87. __asm__ __volatile__("mrc p15, 0, r0, c1, c0, 1");
  88. __asm__ __volatile__("orr r0, r0, #0x2");
  89. /* SMI instruction to call ROM Code API */
  90. __asm__ __volatile__(".word 0xE1600070");
  91. __asm__ __volatile__("mov r0, %0":"=r"(i));
  92. __asm__ __volatile__("mov r12, %0":"=r"(j));
  93. }
  94. }
  95. void l2cache_disable()
  96. {
  97. unsigned long i;
  98. volatile unsigned int j;
  99. /* ES2 onwards we can disable/enable L2 ourselves */
  100. if (get_cpu_rev() >= CPU_3XX_ES20) {
  101. __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
  102. __asm__ __volatile__("bic %0, %0, #0x2":"=r"(i));
  103. __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
  104. } else {
  105. /* Save r0, r12 and restore them after usage */
  106. __asm__ __volatile__("mov %0, r12":"=r"(j));
  107. __asm__ __volatile__("mov %0, r0":"=r"(i));
  108. /*
  109. * GP Device ROM code API usage here
  110. * r12 = AUXCR Write function and r0 value
  111. */
  112. __asm__ __volatile__("mov r12, #0x3");
  113. __asm__ __volatile__("mrc p15, 0, r0, c1, c0, 1");
  114. __asm__ __volatile__("bic r0, r0, #0x2");
  115. /* SMI instruction to call ROM Code API */
  116. __asm__ __volatile__(".word 0xE1600070");
  117. __asm__ __volatile__("mov r0, %0":"=r"(i));
  118. __asm__ __volatile__("mov r12, %0":"=r"(j));
  119. }
  120. }
  121. static void cache_flush(void)
  122. {
  123. asm ("mcr p15, 0, %0, c7, c5, 0": :"r" (0));
  124. }