opal-takeover.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * PowerNV OPAL takeover assembly code, for use by prom_init.c
  3. *
  4. * Copyright 2011 IBM Corp.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <asm/ppc_asm.h>
  12. #include <asm/hvcall.h>
  13. #include <asm/asm-offsets.h>
  14. #include <asm/opal.h>
  15. #define H_HAL_TAKEOVER 0x5124
  16. #define H_HAL_TAKEOVER_QUERY_MAGIC -1
  17. .text
  18. _GLOBAL(opal_query_takeover)
  19. mfcr r0
  20. stw r0,8(r1)
  21. std r3,STK_PARAM(R3)(r1)
  22. std r4,STK_PARAM(R4)(r1)
  23. li r3,H_HAL_TAKEOVER
  24. li r4,H_HAL_TAKEOVER_QUERY_MAGIC
  25. HVSC
  26. ld r10,STK_PARAM(R3)(r1)
  27. std r4,0(r10)
  28. ld r10,STK_PARAM(R4)(r1)
  29. std r5,0(r10)
  30. lwz r0,8(r1)
  31. mtcrf 0xff,r0
  32. blr
  33. _GLOBAL(opal_do_takeover)
  34. mfcr r0
  35. stw r0,8(r1)
  36. mflr r0
  37. std r0,16(r1)
  38. bl __opal_do_takeover
  39. ld r0,16(r1)
  40. mtlr r0
  41. lwz r0,8(r1)
  42. mtcrf 0xff,r0
  43. blr
  44. __opal_do_takeover:
  45. ld r4,0(r3)
  46. ld r5,0x8(r3)
  47. ld r6,0x10(r3)
  48. ld r7,0x18(r3)
  49. ld r8,0x20(r3)
  50. ld r9,0x28(r3)
  51. ld r10,0x30(r3)
  52. ld r11,0x38(r3)
  53. li r3,H_HAL_TAKEOVER
  54. HVSC
  55. blr
  56. .globl opal_secondary_entry
  57. opal_secondary_entry:
  58. mr r31,r3
  59. mfmsr r11
  60. li r12,(MSR_SF | MSR_ISF)@highest
  61. sldi r12,r12,48
  62. or r11,r11,r12
  63. mtmsrd r11
  64. isync
  65. mfspr r4,SPRN_PIR
  66. std r4,0(r3)
  67. 1: HMT_LOW
  68. ld r4,8(r3)
  69. cmpli cr0,r4,0
  70. beq 1b
  71. HMT_MEDIUM
  72. 1: addi r3,r31,16
  73. bl __opal_do_takeover
  74. b 1b
  75. _GLOBAL(opal_enter_rtas)
  76. mflr r0
  77. std r0,16(r1)
  78. stdu r1,-PROM_FRAME_SIZE(r1) /* Save SP and create stack space */
  79. /* Because PROM is running in 32b mode, it clobbers the high order half
  80. * of all registers that it saves. We therefore save those registers
  81. * PROM might touch to the stack. (r0, r3-r13 are caller saved)
  82. */
  83. SAVE_GPR(2, r1)
  84. SAVE_GPR(13, r1)
  85. SAVE_8GPRS(14, r1)
  86. SAVE_10GPRS(22, r1)
  87. mfcr r10
  88. mfmsr r11
  89. std r10,_CCR(r1)
  90. std r11,_MSR(r1)
  91. /* Get the PROM entrypoint */
  92. mtlr r5
  93. /* Switch MSR to 32 bits mode
  94. */
  95. li r12,1
  96. rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
  97. andc r11,r11,r12
  98. li r12,1
  99. rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
  100. andc r11,r11,r12
  101. mtmsrd r11
  102. isync
  103. /* Enter RTAS here... */
  104. blrl
  105. /* Just make sure that r1 top 32 bits didn't get
  106. * corrupt by OF
  107. */
  108. rldicl r1,r1,0,32
  109. /* Restore the MSR (back to 64 bits) */
  110. ld r0,_MSR(r1)
  111. MTMSRD(r0)
  112. isync
  113. /* Restore other registers */
  114. REST_GPR(2, r1)
  115. REST_GPR(13, r1)
  116. REST_8GPRS(14, r1)
  117. REST_10GPRS(22, r1)
  118. ld r4,_CCR(r1)
  119. mtcr r4
  120. addi r1,r1,PROM_FRAME_SIZE
  121. ld r0,16(r1)
  122. mtlr r0
  123. blr