book3s_64_slb.S 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. #define SHADOW_SLB_ENTRY_LEN 0x10
  20. #define OFFSET_ESID(x) (SHADOW_SLB_ENTRY_LEN * x)
  21. #define OFFSET_VSID(x) ((SHADOW_SLB_ENTRY_LEN * x) + 8)
  22. /******************************************************************************
  23. * *
  24. * Entry code *
  25. * *
  26. *****************************************************************************/
  27. .macro LOAD_GUEST_SEGMENTS
  28. /* Required state:
  29. *
  30. * MSR = ~IR|DR
  31. * R13 = PACA
  32. * R1 = host R1
  33. * R2 = host R2
  34. * R3 = shadow vcpu
  35. * all other volatile GPRS = free except R4, R6
  36. * SVCPU[CR] = guest CR
  37. * SVCPU[XER] = guest XER
  38. * SVCPU[CTR] = guest CTR
  39. * SVCPU[LR] = guest LR
  40. */
  41. BEGIN_FW_FTR_SECTION
  42. /* Declare SLB shadow as 0 entries big */
  43. ld r11, PACA_SLBSHADOWPTR(r13)
  44. li r8, 0
  45. stb r8, 3(r11)
  46. END_FW_FTR_SECTION_IFSET(FW_FEATURE_LPAR)
  47. /* Flush SLB */
  48. li r10, 0
  49. slbmte r10, r10
  50. slbia
  51. /* Fill SLB with our shadow */
  52. lbz r12, SVCPU_SLB_MAX(r3)
  53. mulli r12, r12, 16
  54. addi r12, r12, SVCPU_SLB
  55. add r12, r12, r3
  56. /* for (r11 = kvm_slb; r11 < kvm_slb + kvm_slb_size; r11+=slb_entry) */
  57. li r11, SVCPU_SLB
  58. add r11, r11, r3
  59. slb_loop_enter:
  60. ld r10, 0(r11)
  61. andis. r9, r10, SLB_ESID_V@h
  62. beq slb_loop_enter_skip
  63. ld r9, 8(r11)
  64. slbmte r9, r10
  65. slb_loop_enter_skip:
  66. addi r11, r11, 16
  67. cmpd cr0, r11, r12
  68. blt slb_loop_enter
  69. slb_do_enter:
  70. .endm
  71. /******************************************************************************
  72. * *
  73. * Exit code *
  74. * *
  75. *****************************************************************************/
  76. .macro LOAD_HOST_SEGMENTS
  77. /* Register usage at this point:
  78. *
  79. * R1 = host R1
  80. * R2 = host R2
  81. * R12 = exit handler id
  82. * R13 = shadow vcpu - SHADOW_VCPU_OFF [=PACA on PPC64]
  83. * SVCPU.* = guest *
  84. * SVCPU[CR] = guest CR
  85. * SVCPU[XER] = guest XER
  86. * SVCPU[CTR] = guest CTR
  87. * SVCPU[LR] = guest LR
  88. *
  89. */
  90. /* Remove all SLB entries that are in use. */
  91. li r0, r0
  92. slbmte r0, r0
  93. slbia
  94. /* Restore bolted entries from the shadow */
  95. ld r11, PACA_SLBSHADOWPTR(r13)
  96. BEGIN_FW_FTR_SECTION
  97. /* Declare SLB shadow as SLB_NUM_BOLTED entries big */
  98. li r8, SLB_NUM_BOLTED
  99. stb r8, 3(r11)
  100. END_FW_FTR_SECTION_IFSET(FW_FEATURE_LPAR)
  101. /* Manually load all entries from shadow SLB */
  102. li r8, SLBSHADOW_SAVEAREA
  103. li r7, SLBSHADOW_SAVEAREA + 8
  104. .rept SLB_NUM_BOLTED
  105. LDX_BE r10, r11, r8
  106. cmpdi r10, 0
  107. beq 1f
  108. LDX_BE r9, r11, r7
  109. slbmte r9, r10
  110. 1: addi r7, r7, SHADOW_SLB_ENTRY_LEN
  111. addi r8, r8, SHADOW_SLB_ENTRY_LEN
  112. .endr
  113. isync
  114. sync
  115. slb_do_exit:
  116. .endm