initialize_mmu.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * arch/xtensa/include/asm/initialize_mmu.h
  3. *
  4. * Initializes MMU:
  5. *
  6. * For the new V3 MMU we remap the TLB from virtual == physical
  7. * to the standard Linux mapping used in earlier MMU's.
  8. *
  9. * The the MMU we also support a new configuration register that
  10. * specifies how the S32C1I instruction operates with the cache
  11. * controller.
  12. *
  13. * This file is subject to the terms and conditions of the GNU General
  14. * Public License. See the file "COPYING" in the main directory of
  15. * this archive for more details.
  16. *
  17. * Copyright (C) 2008 - 2012 Tensilica, Inc.
  18. *
  19. * Marc Gauthier <marc@tensilica.com>
  20. * Pete Delaney <piet@tensilica.com>
  21. */
  22. #ifndef _XTENSA_INITIALIZE_MMU_H
  23. #define _XTENSA_INITIALIZE_MMU_H
  24. #include <asm/pgtable.h>
  25. #include <asm/vectors.h>
  26. #ifdef __ASSEMBLY__
  27. #define XTENSA_HWVERSION_RC_2009_0 230000
  28. .macro initialize_mmu
  29. #if XCHAL_HAVE_S32C1I && (XCHAL_HW_MIN_VERSION >= XTENSA_HWVERSION_RC_2009_0)
  30. /*
  31. * We Have Atomic Operation Control (ATOMCTL) Register; Initialize it.
  32. * For details see Documentation/xtensa/atomctl.txt
  33. */
  34. #if XCHAL_DCACHE_IS_COHERENT
  35. movi a3, 0x25 /* For SMP/MX -- internal for writeback,
  36. * RCW otherwise
  37. */
  38. #else
  39. movi a3, 0x29 /* non-MX -- Most cores use Std Memory
  40. * Controlers which usually can't use RCW
  41. */
  42. #endif
  43. wsr a3, atomctl
  44. #endif /* XCHAL_HAVE_S32C1I &&
  45. * (XCHAL_HW_MIN_VERSION >= XTENSA_HWVERSION_RC_2009_0)
  46. */
  47. #if defined(CONFIG_MMU) && XCHAL_HAVE_PTP_MMU && XCHAL_HAVE_SPANNING_WAY
  48. /*
  49. * Have MMU v3
  50. */
  51. #if !XCHAL_HAVE_VECBASE
  52. # error "MMU v3 requires reloc vectors"
  53. #endif
  54. movi a1, 0
  55. _call0 1f
  56. _j 2f
  57. .align 4
  58. 1: movi a2, 0x10000000
  59. movi a3, 0x18000000
  60. add a2, a2, a0
  61. 9: bgeu a2, a3, 9b /* PC is out of the expected range */
  62. /* Step 1: invalidate mapping at 0x40000000..0x5FFFFFFF. */
  63. movi a2, 0x40000006
  64. idtlb a2
  65. iitlb a2
  66. isync
  67. /* Step 2: map 0x40000000..0x47FFFFFF to paddr containing this code
  68. * and jump to the new mapping.
  69. */
  70. #define CA_BYPASS (_PAGE_CA_BYPASS | _PAGE_HW_WRITE | _PAGE_HW_EXEC)
  71. #define CA_WRITEBACK (_PAGE_CA_WB | _PAGE_HW_WRITE | _PAGE_HW_EXEC)
  72. srli a3, a0, 27
  73. slli a3, a3, 27
  74. addi a3, a3, CA_BYPASS
  75. addi a7, a2, -1
  76. wdtlb a3, a7
  77. witlb a3, a7
  78. isync
  79. slli a4, a0, 5
  80. srli a4, a4, 5
  81. addi a5, a2, -6
  82. add a4, a4, a5
  83. jx a4
  84. /* Step 3: unmap everything other than current area.
  85. * Start at 0x60000000, wrap around, and end with 0x20000000
  86. */
  87. 2: movi a4, 0x20000000
  88. add a5, a2, a4
  89. 3: idtlb a5
  90. iitlb a5
  91. add a5, a5, a4
  92. bne a5, a2, 3b
  93. /* Step 4: Setup MMU with the old V2 mappings. */
  94. movi a6, 0x01000000
  95. wsr a6, ITLBCFG
  96. wsr a6, DTLBCFG
  97. isync
  98. movi a5, 0xd0000005
  99. movi a4, CA_WRITEBACK
  100. wdtlb a4, a5
  101. witlb a4, a5
  102. movi a5, 0xd8000005
  103. movi a4, CA_BYPASS
  104. wdtlb a4, a5
  105. witlb a4, a5
  106. movi a5, 0xe0000006
  107. movi a4, 0xf0000000 + CA_WRITEBACK
  108. wdtlb a4, a5
  109. witlb a4, a5
  110. movi a5, 0xf0000006
  111. movi a4, 0xf0000000 + CA_BYPASS
  112. wdtlb a4, a5
  113. witlb a4, a5
  114. isync
  115. /* Jump to self, using MMU v2 mappings. */
  116. movi a4, 1f
  117. jx a4
  118. 1:
  119. movi a2, VECBASE_RESET_VADDR
  120. wsr a2, vecbase
  121. /* Step 5: remove temporary mapping. */
  122. idtlb a7
  123. iitlb a7
  124. isync
  125. movi a0, 0
  126. wsr a0, ptevaddr
  127. rsync
  128. #endif /* defined(CONFIG_MMU) && XCHAL_HAVE_PTP_MMU &&
  129. XCHAL_HAVE_SPANNING_WAY */
  130. .endm
  131. #endif /*__ASSEMBLY__*/
  132. #endif /* _XTENSA_INITIALIZE_MMU_H */