hpmc.S 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /*
  2. * HPMC (High Priority Machine Check) handler.
  3. *
  4. * Copyright (C) 1999 Philipp Rumpf <prumpf@tux.org>
  5. * Copyright (C) 1999 Hewlett-Packard (Frank Rowand)
  6. * Copyright (C) 2000 Hewlett-Packard (John Marvin)
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2, or (at your option)
  11. * any later version.
  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. /*
  23. * This HPMC handler retrieves the HPMC pim data, resets IO and
  24. * returns to the default trap handler with code set to 1 (HPMC).
  25. * The default trap handler calls handle interruption, which
  26. * does a stack and register dump. This at least allows kernel
  27. * developers to get back to C code in virtual mode, where they
  28. * have the option to examine and print values from memory that
  29. * would help in debugging an HPMC caused by a software bug.
  30. *
  31. * There is more to do here:
  32. *
  33. * 1) On MP systems we need to synchronize processors
  34. * before calling pdc/iodc.
  35. * 2) We should be checking the system state and not
  36. * returning to the fault handler if things are really
  37. * bad.
  38. *
  39. */
  40. .level 1.1
  41. #include <asm/assembly.h>
  42. #include <asm/pdc.h>
  43. #include <asm/psw.h>
  44. #include <linux/linkage.h>
  45. #include <linux/init.h>
  46. /*
  47. * stack for os_hpmc, the HPMC handler.
  48. * buffer for IODC procedures (for the HPMC handler).
  49. *
  50. * IODC requires 7K byte stack. That leaves 1K byte for os_hpmc.
  51. */
  52. __PAGE_ALIGNED_BSS
  53. .align 4096
  54. hpmc_stack:
  55. .block 16384
  56. #define HPMC_IODC_BUF_SIZE 0x8000
  57. __PAGE_ALIGNED_BSS
  58. .align 4096
  59. hpmc_iodc_buf:
  60. .block HPMC_IODC_BUF_SIZE
  61. .section .bss
  62. .align 8
  63. hpmc_raddr:
  64. .block 128
  65. #define HPMC_PIM_DATA_SIZE 896 /* Enough to hold all architected 2.0 state */
  66. .section .bss
  67. .align 8
  68. ENTRY(hpmc_pim_data)
  69. .block HPMC_PIM_DATA_SIZE
  70. END(hpmc_pim_data)
  71. .text
  72. .import intr_save, code
  73. .align 16
  74. ENTRY(os_hpmc)
  75. .os_hpmc:
  76. /*
  77. * registers modified:
  78. *
  79. * Using callee saves registers without saving them. The
  80. * original values are in the pim dump if we need them.
  81. *
  82. * r2 (rp) return pointer
  83. * r3 address of PDCE_PROC
  84. * r4 scratch
  85. * r5 scratch
  86. * r23 (arg3) procedure arg
  87. * r24 (arg2) procedure arg
  88. * r25 (arg1) procedure arg
  89. * r26 (arg0) procedure arg
  90. * r30 (sp) stack pointer
  91. *
  92. * registers read:
  93. *
  94. * r26 contains address of PDCE_PROC on entry
  95. * r28 (ret0) return value from procedure
  96. */
  97. copy arg0, %r3 /* save address of PDCE_PROC */
  98. /*
  99. * disable nested HPMCs
  100. *
  101. * Increment os_hpmc checksum to invalidate it.
  102. * Do this before turning the PSW M bit off.
  103. */
  104. mfctl %cr14, %r4
  105. ldw 52(%r4),%r5
  106. addi 1,%r5,%r5
  107. stw %r5,52(%r4)
  108. /* MP_FIXME: synchronize all processors. */
  109. /* Setup stack pointer. */
  110. load32 PA(hpmc_stack),sp
  111. ldo 128(sp),sp /* leave room for arguments */
  112. /*
  113. * Most PDC routines require that the M bit be off.
  114. * So turn on the Q bit and turn off the M bit.
  115. */
  116. ldi PSW_SM_Q,%r4 /* PSW Q on, PSW M off */
  117. mtctl %r4,ipsw
  118. mtctl %r0,pcsq
  119. mtctl %r0,pcsq
  120. load32 PA(os_hpmc_1),%r4
  121. mtctl %r4,pcoq
  122. ldo 4(%r4),%r4
  123. mtctl %r4,pcoq
  124. rfi
  125. nop
  126. os_hpmc_1:
  127. /* Call PDC_PIM to get HPMC pim info */
  128. /*
  129. * Note that on some newer boxes, PDC_PIM must be called
  130. * before PDC_IO if you want IO to be reset. PDC_PIM sets
  131. * a flag that PDC_IO examines.
  132. */
  133. ldo PDC_PIM(%r0), arg0
  134. ldo PDC_PIM_HPMC(%r0),arg1 /* Transfer HPMC data */
  135. load32 PA(hpmc_raddr),arg2
  136. load32 PA(hpmc_pim_data),arg3
  137. load32 HPMC_PIM_DATA_SIZE,%r4
  138. stw %r4,-52(sp)
  139. ldil L%PA(os_hpmc_2), rp
  140. bv (r3) /* call pdce_proc */
  141. ldo R%PA(os_hpmc_2)(rp), rp
  142. os_hpmc_2:
  143. comib,<> 0,ret0, os_hpmc_fail
  144. /* Reset IO by calling the hversion dependent PDC_IO routine */
  145. ldo PDC_IO(%r0),arg0
  146. ldo 0(%r0),arg1 /* log IO errors */
  147. ldo 0(%r0),arg2 /* reserved */
  148. ldo 0(%r0),arg3 /* reserved */
  149. stw %r0,-52(sp) /* reserved */
  150. ldil L%PA(os_hpmc_3),rp
  151. bv (%r3) /* call pdce_proc */
  152. ldo R%PA(os_hpmc_3)(rp),rp
  153. os_hpmc_3:
  154. /* FIXME? Check for errors from PDC_IO (-1 might be OK) */
  155. /*
  156. * Initialize the IODC console device (HPA,SPA, path etc.
  157. * are stored on page 0.
  158. */
  159. /*
  160. * Load IODC into hpmc_iodc_buf by calling PDC_IODC.
  161. * Note that PDC_IODC handles flushing the appropriate
  162. * data and instruction cache lines.
  163. */
  164. ldo PDC_IODC(%r0),arg0
  165. ldo PDC_IODC_READ(%r0),arg1
  166. load32 PA(hpmc_raddr),arg2
  167. ldw BOOT_CONSOLE_HPA_OFFSET(%r0),arg3 /* console hpa */
  168. ldo PDC_IODC_RI_INIT(%r0),%r4
  169. stw %r4,-52(sp)
  170. load32 PA(hpmc_iodc_buf),%r4
  171. stw %r4,-56(sp)
  172. load32 HPMC_IODC_BUF_SIZE,%r4
  173. stw %r4,-60(sp)
  174. ldil L%PA(os_hpmc_4),rp
  175. bv (%r3) /* call pdce_proc */
  176. ldo R%PA(os_hpmc_4)(rp),rp
  177. os_hpmc_4:
  178. comib,<> 0,ret0,os_hpmc_fail
  179. /* Call the entry init (just loaded by PDC_IODC) */
  180. ldw BOOT_CONSOLE_HPA_OFFSET(%r0),arg0 /* console hpa */
  181. ldo ENTRY_INIT_MOD_DEV(%r0), arg1
  182. ldw BOOT_CONSOLE_SPA_OFFSET(%r0),arg2 /* console spa */
  183. depi 0,31,11,arg2 /* clear bits 21-31 */
  184. ldo BOOT_CONSOLE_PATH_OFFSET(%r0),arg3 /* console path */
  185. load32 PA(hpmc_raddr),%r4
  186. stw %r4, -52(sp)
  187. stw %r0, -56(sp) /* HV */
  188. stw %r0, -60(sp) /* HV */
  189. stw %r0, -64(sp) /* HV */
  190. stw %r0, -68(sp) /* lang, must be zero */
  191. load32 PA(hpmc_iodc_buf),%r5
  192. ldil L%PA(os_hpmc_5),rp
  193. bv (%r5)
  194. ldo R%PA(os_hpmc_5)(rp),rp
  195. os_hpmc_5:
  196. comib,<> 0,ret0,os_hpmc_fail
  197. /* Prepare to call intr_save */
  198. /*
  199. * Load kernel page directory (load into user also, since
  200. * we don't intend to ever return to user land anyway)
  201. */
  202. load32 PA(swapper_pg_dir),%r4
  203. mtctl %r4,%cr24 /* Initialize kernel root pointer */
  204. mtctl %r4,%cr25 /* Initialize user root pointer */
  205. /* Clear sr4-sr7 */
  206. mtsp %r0, %sr4
  207. mtsp %r0, %sr5
  208. mtsp %r0, %sr6
  209. mtsp %r0, %sr7
  210. tovirt_r1 %r30 /* make sp virtual */
  211. rsm PSW_SM_Q,%r0 /* Clear Q bit */
  212. ldi 1,%r8 /* Set trap code to "1" for HPMC */
  213. load32 PA(intr_save),%r1
  214. be 0(%sr7,%r1)
  215. nop
  216. os_hpmc_fail:
  217. /*
  218. * Reset the system
  219. *
  220. * Some systems may lockup from a broadcast reset, so try the
  221. * hversion PDC_BROADCAST_RESET() first.
  222. * MP_FIXME: reset all processors if more than one central bus.
  223. */
  224. /* PDC_BROADCAST_RESET() */
  225. ldo PDC_BROADCAST_RESET(%r0),arg0
  226. ldo 0(%r0),arg1 /* do reset */
  227. ldil L%PA(os_hpmc_6),rp
  228. bv (%r3) /* call pdce_proc */
  229. ldo R%PA(os_hpmc_6)(rp),rp
  230. os_hpmc_6:
  231. /*
  232. * possible return values:
  233. * -1 non-existent procedure
  234. * -2 non-existent option
  235. * -16 unaligned stack
  236. *
  237. * If call returned, do a broadcast reset.
  238. */
  239. ldil L%0xfffc0000,%r4 /* IO_BROADCAST */
  240. ldo 5(%r0),%r5
  241. stw %r5,48(%r4) /* CMD_RESET to IO_COMMAND offset */
  242. b .
  243. nop
  244. .align 16 /* make function length multiple of 16 bytes */
  245. .os_hpmc_end:
  246. __INITRODATA
  247. .globl os_hpmc_size
  248. .align 4
  249. .type os_hpmc_size, @object
  250. .size os_hpmc_size, 4
  251. os_hpmc_size:
  252. .word .os_hpmc_end-.os_hpmc