ip27-nmi.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/kernel.h>
  3. #include <linux/mmzone.h>
  4. #include <linux/nodemask.h>
  5. #include <linux/spinlock.h>
  6. #include <linux/smp.h>
  7. #include <linux/atomic.h>
  8. #include <asm/sn/types.h>
  9. #include <asm/sn/addrs.h>
  10. #include <asm/sn/nmi.h>
  11. #include <asm/sn/arch.h>
  12. #include <asm/sn/sn0/hub.h>
  13. #if 0
  14. #define NODE_NUM_CPUS(n) CNODE_NUM_CPUS(n)
  15. #else
  16. #define NODE_NUM_CPUS(n) CPUS_PER_NODE
  17. #endif
  18. #define CNODEID_NONE (cnodeid_t)-1
  19. typedef unsigned long machreg_t;
  20. static arch_spinlock_t nmi_lock = __ARCH_SPIN_LOCK_UNLOCKED;
  21. /*
  22. * Let's see what else we need to do here. Set up sp, gp?
  23. */
  24. void nmi_dump(void)
  25. {
  26. void cont_nmi_dump(void);
  27. cont_nmi_dump();
  28. }
  29. void install_cpu_nmi_handler(int slice)
  30. {
  31. nmi_t *nmi_addr;
  32. nmi_addr = (nmi_t *)NMI_ADDR(get_nasid(), slice);
  33. if (nmi_addr->call_addr)
  34. return;
  35. nmi_addr->magic = NMI_MAGIC;
  36. nmi_addr->call_addr = (void *)nmi_dump;
  37. nmi_addr->call_addr_c =
  38. (void *)(~((unsigned long)(nmi_addr->call_addr)));
  39. nmi_addr->call_parm = 0;
  40. }
  41. /*
  42. * Copy the cpu registers which have been saved in the IP27prom format
  43. * into the eframe format for the node under consideration.
  44. */
  45. void nmi_cpu_eframe_save(nasid_t nasid, int slice)
  46. {
  47. struct reg_struct *nr;
  48. int i;
  49. /* Get the pointer to the current cpu's register set. */
  50. nr = (struct reg_struct *)
  51. (TO_UNCAC(TO_NODE(nasid, IP27_NMI_KREGS_OFFSET)) +
  52. slice * IP27_NMI_KREGS_CPU_SIZE);
  53. printk("NMI nasid %d: slice %d\n", nasid, slice);
  54. /*
  55. * Saved main processor registers
  56. */
  57. for (i = 0; i < 32; ) {
  58. if ((i % 4) == 0)
  59. printk("$%2d :", i);
  60. printk(" %016lx", nr->gpr[i]);
  61. i++;
  62. if ((i % 4) == 0)
  63. printk("\n");
  64. }
  65. printk("Hi : (value lost)\n");
  66. printk("Lo : (value lost)\n");
  67. /*
  68. * Saved cp0 registers
  69. */
  70. printk("epc : %016lx %pS\n", nr->epc, (void *) nr->epc);
  71. printk("%s\n", print_tainted());
  72. printk("ErrEPC: %016lx %pS\n", nr->error_epc, (void *) nr->error_epc);
  73. printk("ra : %016lx %pS\n", nr->gpr[31], (void *) nr->gpr[31]);
  74. printk("Status: %08lx ", nr->sr);
  75. if (nr->sr & ST0_KX)
  76. printk("KX ");
  77. if (nr->sr & ST0_SX)
  78. printk("SX ");
  79. if (nr->sr & ST0_UX)
  80. printk("UX ");
  81. switch (nr->sr & ST0_KSU) {
  82. case KSU_USER:
  83. printk("USER ");
  84. break;
  85. case KSU_SUPERVISOR:
  86. printk("SUPERVISOR ");
  87. break;
  88. case KSU_KERNEL:
  89. printk("KERNEL ");
  90. break;
  91. default:
  92. printk("BAD_MODE ");
  93. break;
  94. }
  95. if (nr->sr & ST0_ERL)
  96. printk("ERL ");
  97. if (nr->sr & ST0_EXL)
  98. printk("EXL ");
  99. if (nr->sr & ST0_IE)
  100. printk("IE ");
  101. printk("\n");
  102. printk("Cause : %08lx\n", nr->cause);
  103. printk("PrId : %08x\n", read_c0_prid());
  104. printk("BadVA : %016lx\n", nr->badva);
  105. printk("CErr : %016lx\n", nr->cache_err);
  106. printk("NMI_SR: %016lx\n", nr->nmi_sr);
  107. printk("\n");
  108. }
  109. void nmi_dump_hub_irq(nasid_t nasid, int slice)
  110. {
  111. hubreg_t mask0, mask1, pend0, pend1;
  112. if (slice == 0) { /* Slice A */
  113. mask0 = REMOTE_HUB_L(nasid, PI_INT_MASK0_A);
  114. mask1 = REMOTE_HUB_L(nasid, PI_INT_MASK1_A);
  115. } else { /* Slice B */
  116. mask0 = REMOTE_HUB_L(nasid, PI_INT_MASK0_B);
  117. mask1 = REMOTE_HUB_L(nasid, PI_INT_MASK1_B);
  118. }
  119. pend0 = REMOTE_HUB_L(nasid, PI_INT_PEND0);
  120. pend1 = REMOTE_HUB_L(nasid, PI_INT_PEND1);
  121. printk("PI_INT_MASK0: %16Lx PI_INT_MASK1: %16Lx\n", mask0, mask1);
  122. printk("PI_INT_PEND0: %16Lx PI_INT_PEND1: %16Lx\n", pend0, pend1);
  123. printk("\n\n");
  124. }
  125. /*
  126. * Copy the cpu registers which have been saved in the IP27prom format
  127. * into the eframe format for the node under consideration.
  128. */
  129. void nmi_node_eframe_save(cnodeid_t cnode)
  130. {
  131. nasid_t nasid;
  132. int slice;
  133. /* Make sure that we have a valid node */
  134. if (cnode == CNODEID_NONE)
  135. return;
  136. nasid = COMPACT_TO_NASID_NODEID(cnode);
  137. if (nasid == INVALID_NASID)
  138. return;
  139. /* Save the registers into eframe for each cpu */
  140. for (slice = 0; slice < NODE_NUM_CPUS(slice); slice++) {
  141. nmi_cpu_eframe_save(nasid, slice);
  142. nmi_dump_hub_irq(nasid, slice);
  143. }
  144. }
  145. /*
  146. * Save the nmi cpu registers for all cpus in the system.
  147. */
  148. void
  149. nmi_eframes_save(void)
  150. {
  151. cnodeid_t cnode;
  152. for_each_online_node(cnode)
  153. nmi_node_eframe_save(cnode);
  154. }
  155. void
  156. cont_nmi_dump(void)
  157. {
  158. #ifndef REAL_NMI_SIGNAL
  159. static atomic_t nmied_cpus = ATOMIC_INIT(0);
  160. atomic_inc(&nmied_cpus);
  161. #endif
  162. /*
  163. * Only allow 1 cpu to proceed
  164. */
  165. arch_spin_lock(&nmi_lock);
  166. #ifdef REAL_NMI_SIGNAL
  167. /*
  168. * Wait up to 15 seconds for the other cpus to respond to the NMI.
  169. * If a cpu has not responded after 10 sec, send it 1 additional NMI.
  170. * This is for 2 reasons:
  171. * - sometimes a MMSC fail to NMI all cpus.
  172. * - on 512p SN0 system, the MMSC will only send NMIs to
  173. * half the cpus. Unfortunately, we don't know which cpus may be
  174. * NMIed - it depends on how the site chooses to configure.
  175. *
  176. * Note: it has been measure that it takes the MMSC up to 2.3 secs to
  177. * send NMIs to all cpus on a 256p system.
  178. */
  179. for (i=0; i < 1500; i++) {
  180. for_each_online_node(node)
  181. if (NODEPDA(node)->dump_count == 0)
  182. break;
  183. if (node == MAX_NUMNODES)
  184. break;
  185. if (i == 1000) {
  186. for_each_online_node(node)
  187. if (NODEPDA(node)->dump_count == 0) {
  188. cpu = cpumask_first(cpumask_of_node(node));
  189. for (n=0; n < CNODE_NUM_CPUS(node); cpu++, n++) {
  190. CPUMASK_SETB(nmied_cpus, cpu);
  191. /*
  192. * cputonasid, cputoslice
  193. * needs kernel cpuid
  194. */
  195. SEND_NMI((cputonasid(cpu)), (cputoslice(cpu)));
  196. }
  197. }
  198. }
  199. udelay(10000);
  200. }
  201. #else
  202. while (atomic_read(&nmied_cpus) != num_online_cpus());
  203. #endif
  204. /*
  205. * Save the nmi cpu registers for all cpu in the eframe format.
  206. */
  207. nmi_eframes_save();
  208. LOCAL_HUB_S(NI_PORT_RESET, NPR_PORTRESET | NPR_LOCALRESET);
  209. }