proc-v7-3level.S 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * arch/arm/mm/proc-v7-3level.S
  3. *
  4. * Copyright (C) 2001 Deep Blue Solutions Ltd.
  5. * Copyright (C) 2011 ARM Ltd.
  6. * Author: Catalin Marinas <catalin.marinas@arm.com>
  7. * based on arch/arm/mm/proc-v7-2level.S
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  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, MA 02111-1307 USA
  21. */
  22. #include <asm/assembler.h>
  23. #define TTB_IRGN_NC (0 << 8)
  24. #define TTB_IRGN_WBWA (1 << 8)
  25. #define TTB_IRGN_WT (2 << 8)
  26. #define TTB_IRGN_WB (3 << 8)
  27. #define TTB_RGN_NC (0 << 10)
  28. #define TTB_RGN_OC_WBWA (1 << 10)
  29. #define TTB_RGN_OC_WT (2 << 10)
  30. #define TTB_RGN_OC_WB (3 << 10)
  31. #define TTB_S (3 << 12)
  32. #define TTB_EAE (1 << 31)
  33. /* PTWs cacheable, inner WB not shareable, outer WB not shareable */
  34. #define TTB_FLAGS_UP (TTB_IRGN_WB|TTB_RGN_OC_WB)
  35. #define PMD_FLAGS_UP (PMD_SECT_WB)
  36. /* PTWs cacheable, inner WBWA shareable, outer WBWA not shareable */
  37. #define TTB_FLAGS_SMP (TTB_IRGN_WBWA|TTB_S|TTB_RGN_OC_WBWA)
  38. #define PMD_FLAGS_SMP (PMD_SECT_WBWA|PMD_SECT_S)
  39. #ifndef __ARMEB__
  40. # define rpgdl r0
  41. # define rpgdh r1
  42. #else
  43. # define rpgdl r1
  44. # define rpgdh r0
  45. #endif
  46. /*
  47. * cpu_v7_switch_mm(pgd_phys, tsk)
  48. *
  49. * Set the translation table base pointer to be pgd_phys (physical address of
  50. * the new TTB).
  51. */
  52. ENTRY(cpu_v7_switch_mm)
  53. #ifdef CONFIG_MMU
  54. mmid r2, r2
  55. asid r2, r2
  56. orr rpgdh, rpgdh, r2, lsl #(48 - 32) @ upper 32-bits of pgd
  57. mcrr p15, 0, rpgdl, rpgdh, c2 @ set TTB 0
  58. isb
  59. #endif
  60. ret lr
  61. ENDPROC(cpu_v7_switch_mm)
  62. #ifdef __ARMEB__
  63. #define rl r3
  64. #define rh r2
  65. #else
  66. #define rl r2
  67. #define rh r3
  68. #endif
  69. /*
  70. * cpu_v7_set_pte_ext(ptep, pte)
  71. *
  72. * Set a level 2 translation table entry.
  73. * - ptep - pointer to level 3 translation table entry
  74. * - pte - PTE value to store (64-bit in r2 and r3)
  75. */
  76. ENTRY(cpu_v7_set_pte_ext)
  77. #ifdef CONFIG_MMU
  78. tst rl, #L_PTE_VALID
  79. beq 1f
  80. tst rh, #1 << (57 - 32) @ L_PTE_NONE
  81. bicne rl, #L_PTE_VALID
  82. bne 1f
  83. eor ip, rh, #1 << (55 - 32) @ toggle L_PTE_DIRTY in temp reg to
  84. @ test for !L_PTE_DIRTY || L_PTE_RDONLY
  85. tst ip, #1 << (55 - 32) | 1 << (58 - 32)
  86. orrne rl, #PTE_AP2
  87. biceq rl, #PTE_AP2
  88. 1: strd r2, r3, [r0]
  89. ALT_SMP(W(nop))
  90. ALT_UP (mcr p15, 0, r0, c7, c10, 1) @ flush_pte
  91. #endif
  92. ret lr
  93. ENDPROC(cpu_v7_set_pte_ext)
  94. /*
  95. * Memory region attributes for LPAE (defined in pgtable-3level.h):
  96. *
  97. * n = AttrIndx[2:0]
  98. *
  99. * n MAIR
  100. * UNCACHED 000 00000000
  101. * BUFFERABLE 001 01000100
  102. * DEV_WC 001 01000100
  103. * WRITETHROUGH 010 10101010
  104. * WRITEBACK 011 11101110
  105. * DEV_CACHED 011 11101110
  106. * DEV_SHARED 100 00000100
  107. * DEV_NONSHARED 100 00000100
  108. * unused 101
  109. * unused 110
  110. * WRITEALLOC 111 11111111
  111. */
  112. .equ PRRR, 0xeeaa4400 @ MAIR0
  113. .equ NMRR, 0xff000004 @ MAIR1
  114. /*
  115. * Macro for setting up the TTBRx and TTBCR registers.
  116. * - \ttbr1 updated.
  117. */
  118. .macro v7_ttb_setup, zero, ttbr0l, ttbr0h, ttbr1, tmp
  119. ldr \tmp, =swapper_pg_dir @ swapper_pg_dir virtual address
  120. cmp \ttbr1, \tmp, lsr #12 @ PHYS_OFFSET > PAGE_OFFSET?
  121. mrc p15, 0, \tmp, c2, c0, 2 @ TTB control egister
  122. orr \tmp, \tmp, #TTB_EAE
  123. ALT_SMP(orr \tmp, \tmp, #TTB_FLAGS_SMP)
  124. ALT_UP(orr \tmp, \tmp, #TTB_FLAGS_UP)
  125. ALT_SMP(orr \tmp, \tmp, #TTB_FLAGS_SMP << 16)
  126. ALT_UP(orr \tmp, \tmp, #TTB_FLAGS_UP << 16)
  127. /*
  128. * Only use split TTBRs if PHYS_OFFSET <= PAGE_OFFSET (cmp above),
  129. * otherwise booting secondary CPUs would end up using TTBR1 for the
  130. * identity mapping set up in TTBR0.
  131. */
  132. orrls \tmp, \tmp, #TTBR1_SIZE @ TTBCR.T1SZ
  133. mcr p15, 0, \tmp, c2, c0, 2 @ TTBCR
  134. mov \tmp, \ttbr1, lsr #20
  135. mov \ttbr1, \ttbr1, lsl #12
  136. addls \ttbr1, \ttbr1, #TTBR1_OFFSET
  137. mcrr p15, 1, \ttbr1, \tmp, c2 @ load TTBR1
  138. .endm
  139. /*
  140. * AT
  141. * TFR EV X F IHD LR S
  142. * .EEE ..EE PUI. .TAT 4RVI ZWRS BLDP WCAM
  143. * rxxx rrxx xxx0 0101 xxxx xxxx x111 xxxx < forced
  144. * 11 0 110 0 0011 1100 .111 1101 < we want
  145. */
  146. .align 2
  147. .type v7_crval, #object
  148. v7_crval:
  149. crval clear=0x0122c302, mmuset=0x30c03c7d, ucset=0x00c01c7c