proc-macros.S 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Based on arch/arm/mm/proc-macros.S
  3. *
  4. * Copyright (C) 2012 ARM Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <asm/asm-offsets.h>
  19. #include <asm/thread_info.h>
  20. /*
  21. * vma_vm_mm - get mm pointer from vma pointer (vma->vm_mm)
  22. */
  23. .macro vma_vm_mm, rd, rn
  24. ldr \rd, [\rn, #VMA_VM_MM]
  25. .endm
  26. /*
  27. * mmid - get context id from mm pointer (mm->context.id)
  28. */
  29. .macro mmid, rd, rn
  30. ldr \rd, [\rn, #MM_CONTEXT_ID]
  31. .endm
  32. /*
  33. * dcache_line_size - get the minimum D-cache line size from the CTR register.
  34. */
  35. .macro dcache_line_size, reg, tmp
  36. mrs \tmp, ctr_el0 // read CTR
  37. ubfm \tmp, \tmp, #16, #19 // cache line size encoding
  38. mov \reg, #4 // bytes per word
  39. lsl \reg, \reg, \tmp // actual cache line size
  40. .endm
  41. /*
  42. * icache_line_size - get the minimum I-cache line size from the CTR register.
  43. */
  44. .macro icache_line_size, reg, tmp
  45. mrs \tmp, ctr_el0 // read CTR
  46. and \tmp, \tmp, #0xf // cache line size encoding
  47. mov \reg, #4 // bytes per word
  48. lsl \reg, \reg, \tmp // actual cache line size
  49. .endm
  50. /*
  51. * tcr_set_idmap_t0sz - update TCR.T0SZ so that we can load the ID map
  52. */
  53. .macro tcr_set_idmap_t0sz, valreg, tmpreg
  54. #ifndef CONFIG_ARM64_VA_BITS_48
  55. ldr_l \tmpreg, idmap_t0sz
  56. bfi \valreg, \tmpreg, #TCR_T0SZ_OFFSET, #TCR_TxSZ_WIDTH
  57. #endif
  58. .endm
  59. /*
  60. * Macro to perform a data cache maintenance for the interval
  61. * [kaddr, kaddr + size)
  62. *
  63. * op: operation passed to dc instruction
  64. * domain: domain used in dsb instruciton
  65. * kaddr: starting virtual address of the region
  66. * size: size of the region
  67. * Corrupts: kaddr, size, tmp1, tmp2
  68. */
  69. .macro dcache_by_line_op op, domain, kaddr, size, tmp1, tmp2
  70. dcache_line_size \tmp1, \tmp2
  71. add \size, \kaddr, \size
  72. sub \tmp2, \tmp1, #1
  73. bic \kaddr, \kaddr, \tmp2
  74. 9998: dc \op, \kaddr
  75. add \kaddr, \kaddr, \tmp1
  76. cmp \kaddr, \size
  77. b.lo 9998b
  78. dsb \domain
  79. .endm
  80. /*
  81. * reset_pmuserenr_el0 - reset PMUSERENR_EL0 if PMUv3 present
  82. */
  83. .macro reset_pmuserenr_el0, tmpreg
  84. mrs \tmpreg, id_aa64dfr0_el1 // Check ID_AA64DFR0_EL1 PMUVer
  85. sbfx \tmpreg, \tmpreg, #8, #4
  86. cmp \tmpreg, #1 // Skip if no PMU present
  87. b.lt 9000f
  88. msr pmuserenr_el0, xzr // Disable PMU access from EL0
  89. 9000:
  90. .endm