arch.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (c) 2008 Travis Geiselbrecht
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files
  6. * (the "Software"), to deal in the Software without restriction,
  7. * including without limitation the rights to use, copy, modify, merge,
  8. * publish, distribute, sublicense, and/or sell copies of the Software,
  9. * and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #include <debug.h>
  24. #include <arch.h>
  25. #include <arch/ops.h>
  26. #include <arch/arm.h>
  27. #include <arch/arm/mmu.h>
  28. #include <platform.h>
  29. #ifdef MTK_FORCE_CLUSTER1
  30. #include <platform/boot_mode.h>
  31. #endif
  32. extern void isb(void);
  33. extern void dsb(void);
  34. #if ARM_ISA_ARMV7
  35. static void set_vector_base(addr_t addr)
  36. {
  37. __asm__ volatile("mcr p15, 0, %0, c12, c0, 0" :: "r" (addr));
  38. }
  39. #endif
  40. void arch_early_init(void)
  41. {
  42. /* turn off the cache */
  43. arch_disable_cache(UCACHE);
  44. #ifdef ENABLE_L2_SHARING
  45. config_L2_size();
  46. #endif
  47. #ifdef MTK_FORCE_CLUSTER1
  48. if (mt_get_chip_sw_ver() < CHIP_SW_VER_02) {
  49. /* set L2 data latency to 1 */
  50. uint32_t tmp;
  51. __asm__ volatile("mrc p15, 1, %0, c9, c0, 2" : "=r" (tmp));
  52. tmp &= 0xfffc0000;
  53. tmp |= 0x9251;
  54. isb();
  55. dsb();
  56. __asm__ volatile("mcr p15, 1, %0, c9, c0, 2" :: "r" (tmp));
  57. dsb();
  58. isb();
  59. }
  60. #endif
  61. /* set the vector base to our exception vectors so we dont need to double map at 0 */
  62. #if ARM_ISA_ARMV7
  63. set_vector_base(MEMBASE);
  64. #endif
  65. #if ARM_WITH_MMU
  66. #ifdef MTK_3LEVEL_PAGETABLE
  67. platform_init_mmu();
  68. #else //!MTK_3LEVEL_PAGETABLE
  69. #ifndef MTK_LM_MODE
  70. platform_init_mmu_mappings();
  71. #else
  72. platform_init_mmu();
  73. #endif
  74. #endif //MTK_3LEVEL_PAGETABLE
  75. #endif
  76. /* turn the cache back on */
  77. arch_enable_cache(UCACHE);
  78. #ifdef HAVE_CACHE_PL310
  79. arch_enable_l2cache();
  80. #endif
  81. #if ARM_WITH_NEON
  82. /* enable cp10 and cp11 */
  83. uint32_t val;
  84. __asm__ volatile("mrc p15, 0, %0, c1, c0, 2" : "=r" (val));
  85. val |= (3<<22)|(3<<20);
  86. __asm__ volatile("mcr p15, 0, %0, c1, c0, 2" :: "r" (val));
  87. /* set enable bit in fpexc */
  88. __asm__ volatile("mrc p10, 7, %0, c8, c0, 0" : "=r" (val));
  89. val |= (1<<30);
  90. __asm__ volatile("mcr p10, 7, %0, c8, c0, 0" :: "r" (val));
  91. #endif
  92. #if 0
  93. #if ARM_ISA_ARMV7
  94. /* enable the cycle count register */
  95. uint32_t en;
  96. __asm__ volatile("mrc p15, 0, %0, c9, c12, 0" : "=r" (en));
  97. en &= ~(1<<3); /* cycle count every cycle */
  98. en |= 1; /* enable all performance counters */
  99. __asm__ volatile("mcr p15, 0, %0, c9, c12, 0" :: "r" (en));
  100. /* enable cycle counter */
  101. en = (1<<31);
  102. __asm__ volatile("mcr p15, 0, %0, c9, c12, 1" :: "r" (en));
  103. #endif
  104. #endif
  105. }
  106. void arch_init(void)
  107. {
  108. }
  109. void arch_uninit(void)
  110. {
  111. #if ARM_WITH_NEON
  112. uint32_t val;
  113. /* set disable bit in fpexc */
  114. __asm__ volatile("mrc p10, 7, %0, c8, c0, 0" : "=r" (val));
  115. val &= ~(1<<30);
  116. __asm__ volatile("mcr p10, 7, %0, c8, c0, 0" :: "r" (val));
  117. /* disable cp10 and cp11 */
  118. __asm__ volatile("mrc p15, 0, %0, c1, c0, 2" : "=r" (val));
  119. val &= ~((3<<22)|(3<<20));
  120. __asm__ volatile("mcr p15, 0, %0, c1, c0, 2" :: "r" (val));
  121. #endif
  122. #if ARM_WITH_CP15
  123. /* disable alignment faults */
  124. arm_write_cr1(arm_read_cr1() & ~(0x1<<1));
  125. dsb();
  126. #endif
  127. }