proc-v7-3level.S 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. #define TTB_IRGN_NC (0 << 8)
  23. #define TTB_IRGN_WBWA (1 << 8)
  24. #define TTB_IRGN_WT (2 << 8)
  25. #define TTB_IRGN_WB (3 << 8)
  26. #define TTB_RGN_NC (0 << 10)
  27. #define TTB_RGN_OC_WBWA (1 << 10)
  28. #define TTB_RGN_OC_WT (2 << 10)
  29. #define TTB_RGN_OC_WB (3 << 10)
  30. #define TTB_S (3 << 12)
  31. #define TTB_EAE (1 << 31)
  32. /* PTWs cacheable, inner WB not shareable, outer WB not shareable */
  33. #define TTB_FLAGS_UP (TTB_IRGN_WB|TTB_RGN_OC_WB)
  34. #define PMD_FLAGS_UP (PMD_SECT_WB)
  35. /* PTWs cacheable, inner WBWA shareable, outer WBWA not shareable */
  36. #define TTB_FLAGS_SMP (TTB_IRGN_WBWA|TTB_S|TTB_RGN_OC_WBWA)
  37. #define PMD_FLAGS_SMP (PMD_SECT_WBWA|PMD_SECT_S)
  38. /*
  39. * cpu_v7_switch_mm(pgd_phys, tsk)
  40. *
  41. * Set the translation table base pointer to be pgd_phys (physical address of
  42. * the new TTB).
  43. */
  44. ENTRY(cpu_v7_switch_mm)
  45. #ifdef CONFIG_MMU
  46. ldr r1, [r1, #MM_CONTEXT_ID] @ get mm->context.id
  47. and r3, r1, #0xff
  48. mov r3, r3, lsl #(48 - 32) @ ASID
  49. mcrr p15, 0, r0, r3, c2 @ set TTB 0
  50. isb
  51. #endif
  52. mov pc, lr
  53. ENDPROC(cpu_v7_switch_mm)
  54. /*
  55. * cpu_v7_set_pte_ext(ptep, pte)
  56. *
  57. * Set a level 2 translation table entry.
  58. * - ptep - pointer to level 3 translation table entry
  59. * - pte - PTE value to store (64-bit in r2 and r3)
  60. */
  61. ENTRY(cpu_v7_set_pte_ext)
  62. #ifdef CONFIG_MMU
  63. tst r2, #L_PTE_PRESENT
  64. beq 1f
  65. tst r3, #1 << (55 - 32) @ L_PTE_DIRTY
  66. orreq r2, #L_PTE_RDONLY
  67. 1: strd r2, r3, [r0]
  68. ALT_SMP(W(nop))
  69. ALT_UP (mcr p15, 0, r0, c7, c10, 1) @ flush_pte
  70. #endif
  71. mov pc, lr
  72. ENDPROC(cpu_v7_set_pte_ext)
  73. /*
  74. * Memory region attributes for LPAE (defined in pgtable-3level.h):
  75. *
  76. * n = AttrIndx[2:0]
  77. *
  78. * n MAIR
  79. * UNCACHED 000 00000000
  80. * BUFFERABLE 001 01000100
  81. * DEV_WC 001 01000100
  82. * WRITETHROUGH 010 10101010
  83. * WRITEBACK 011 11101110
  84. * DEV_CACHED 011 11101110
  85. * DEV_SHARED 100 00000100
  86. * DEV_NONSHARED 100 00000100
  87. * unused 101
  88. * unused 110
  89. * WRITEALLOC 111 11111111
  90. */
  91. .equ PRRR, 0xeeaa4400 @ MAIR0
  92. .equ NMRR, 0xff000004 @ MAIR1
  93. /*
  94. * Macro for setting up the TTBRx and TTBCR registers.
  95. * - \ttbr1 updated.
  96. */
  97. .macro v7_ttb_setup, zero, ttbr0, ttbr1, tmp
  98. ldr \tmp, =swapper_pg_dir @ swapper_pg_dir virtual address
  99. cmp \ttbr1, \tmp @ PHYS_OFFSET > PAGE_OFFSET? (branch below)
  100. mrc p15, 0, \tmp, c2, c0, 2 @ TTB control register
  101. orr \tmp, \tmp, #TTB_EAE
  102. ALT_SMP(orr \tmp, \tmp, #TTB_FLAGS_SMP)
  103. ALT_UP(orr \tmp, \tmp, #TTB_FLAGS_UP)
  104. ALT_SMP(orr \tmp, \tmp, #TTB_FLAGS_SMP << 16)
  105. ALT_UP(orr \tmp, \tmp, #TTB_FLAGS_UP << 16)
  106. /*
  107. * TTBR0/TTBR1 split (PAGE_OFFSET):
  108. * 0x40000000: T0SZ = 2, T1SZ = 0 (not used)
  109. * 0x80000000: T0SZ = 0, T1SZ = 1
  110. * 0xc0000000: T0SZ = 0, T1SZ = 2
  111. *
  112. * Only use this feature if PHYS_OFFSET <= PAGE_OFFSET, otherwise
  113. * booting secondary CPUs would end up using TTBR1 for the identity
  114. * mapping set up in TTBR0.
  115. */
  116. bhi 9001f @ PHYS_OFFSET > PAGE_OFFSET?
  117. orr \tmp, \tmp, #(((PAGE_OFFSET >> 30) - 1) << 16) @ TTBCR.T1SZ
  118. #if defined CONFIG_VMSPLIT_2G
  119. /* PAGE_OFFSET == 0x80000000, T1SZ == 1 */
  120. add \ttbr1, \ttbr1, #1 << 4 @ skip two L1 entries
  121. #elif defined CONFIG_VMSPLIT_3G
  122. /* PAGE_OFFSET == 0xc0000000, T1SZ == 2 */
  123. add \ttbr1, \ttbr1, #4096 * (1 + 3) @ only L2 used, skip pgd+3*pmd
  124. #endif
  125. /* CONFIG_VMSPLIT_1G does not need TTBR1 adjustment */
  126. 9001: mcr p15, 0, \tmp, c2, c0, 2 @ TTB control register
  127. mcrr p15, 1, \ttbr1, \zero, c2 @ load TTBR1
  128. .endm
  129. __CPUINIT
  130. /*
  131. * AT
  132. * TFR EV X F IHD LR S
  133. * .EEE ..EE PUI. .TAT 4RVI ZWRS BLDP WCAM
  134. * rxxx rrxx xxx0 0101 xxxx xxxx x111 xxxx < forced
  135. * 11 0 110 1 0011 1100 .111 1101 < we want
  136. */
  137. .align 2
  138. .type v7_crval, #object
  139. v7_crval:
  140. crval clear=0x0120c302, mmuset=0x30c23c7d, ucset=0x00c01c7c
  141. .previous