book3s_64_slb.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License, version 2, as
  4. * published by the Free Software Foundation.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. * GNU General Public License for more details.
  10. *
  11. * You should have received a copy of the GNU General Public License
  12. * along with this program; if not, write to the Free Software
  13. * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  14. *
  15. * Copyright SUSE Linux Products GmbH 2009
  16. *
  17. * Authors: Alexander Graf <agraf@suse.de>
  18. */
  19. #include <asm/asm-compat.h>
  20. #include <asm/feature-fixups.h>
  21. #define SHADOW_SLB_ENTRY_LEN 0x10
  22. #define OFFSET_ESID(x) (SHADOW_SLB_ENTRY_LEN * x)
  23. #define OFFSET_VSID(x) ((SHADOW_SLB_ENTRY_LEN * x) + 8)
  24. /******************************************************************************
  25. * *
  26. * Entry code *
  27. * *
  28. *****************************************************************************/
  29. .macro LOAD_GUEST_SEGMENTS
  30. /* Required state:
  31. *
  32. * MSR = ~IR|DR
  33. * R13 = PACA
  34. * R1 = host R1
  35. * R2 = host R2
  36. * R3 = shadow vcpu
  37. * all other volatile GPRS = free except R4, R6
  38. * SVCPU[CR] = guest CR
  39. * SVCPU[XER] = guest XER
  40. * SVCPU[CTR] = guest CTR
  41. * SVCPU[LR] = guest LR
  42. */
  43. BEGIN_FW_FTR_SECTION
  44. /* Declare SLB shadow as 0 entries big */
  45. ld r11, PACA_SLBSHADOWPTR(r13)
  46. li r8, 0
  47. stb r8, 3(r11)
  48. END_FW_FTR_SECTION_IFSET(FW_FEATURE_LPAR)
  49. /* Flush SLB */
  50. li r10, 0
  51. slbmte r10, r10
  52. slbia
  53. /* Fill SLB with our shadow */
  54. lbz r12, SVCPU_SLB_MAX(r3)
  55. mulli r12, r12, 16
  56. addi r12, r12, SVCPU_SLB
  57. add r12, r12, r3
  58. /* for (r11 = kvm_slb; r11 < kvm_slb + kvm_slb_size; r11+=slb_entry) */
  59. li r11, SVCPU_SLB
  60. add r11, r11, r3
  61. slb_loop_enter:
  62. ld r10, 0(r11)
  63. andis. r9, r10, SLB_ESID_V@h
  64. beq slb_loop_enter_skip
  65. ld r9, 8(r11)
  66. slbmte r9, r10
  67. slb_loop_enter_skip:
  68. addi r11, r11, 16
  69. cmpd cr0, r11, r12
  70. blt slb_loop_enter
  71. slb_do_enter:
  72. .endm
  73. /******************************************************************************
  74. * *
  75. * Exit code *
  76. * *
  77. *****************************************************************************/
  78. .macro LOAD_HOST_SEGMENTS
  79. /* Register usage at this point:
  80. *
  81. * R1 = host R1
  82. * R2 = host R2
  83. * R12 = exit handler id
  84. * R13 = shadow vcpu - SHADOW_VCPU_OFF [=PACA on PPC64]
  85. * SVCPU.* = guest *
  86. * SVCPU[CR] = guest CR
  87. * SVCPU[XER] = guest XER
  88. * SVCPU[CTR] = guest CTR
  89. * SVCPU[LR] = guest LR
  90. *
  91. */
  92. /* Remove all SLB entries that are in use. */
  93. li r0, 0
  94. slbmte r0, r0
  95. slbia
  96. /* Restore bolted entries from the shadow */
  97. ld r11, PACA_SLBSHADOWPTR(r13)
  98. BEGIN_FW_FTR_SECTION
  99. /* Declare SLB shadow as SLB_NUM_BOLTED entries big */
  100. li r8, SLB_NUM_BOLTED
  101. stb r8, 3(r11)
  102. END_FW_FTR_SECTION_IFSET(FW_FEATURE_LPAR)
  103. /* Manually load all entries from shadow SLB */
  104. li r8, SLBSHADOW_SAVEAREA
  105. li r7, SLBSHADOW_SAVEAREA + 8
  106. .rept SLB_NUM_BOLTED
  107. LDX_BE r10, r11, r8
  108. cmpdi r10, 0
  109. beq 1f
  110. LDX_BE r9, r11, r7
  111. slbmte r9, r10
  112. 1: addi r7, r7, SHADOW_SLB_ENTRY_LEN
  113. addi r8, r8, SHADOW_SLB_ENTRY_LEN
  114. .endr
  115. isync
  116. sync
  117. slb_do_exit:
  118. .endm