sn2_smp.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*
  2. * SN2 Platform specific SMP Support
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * Copyright (C) 2000-2004 Silicon Graphics, Inc. All rights reserved.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/kernel.h>
  12. #include <linux/spinlock.h>
  13. #include <linux/threads.h>
  14. #include <linux/sched.h>
  15. #include <linux/smp.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/irq.h>
  18. #include <linux/mmzone.h>
  19. #include <linux/module.h>
  20. #include <linux/bitops.h>
  21. #include <linux/nodemask.h>
  22. #include <asm/processor.h>
  23. #include <asm/irq.h>
  24. #include <asm/sal.h>
  25. #include <asm/system.h>
  26. #include <asm/delay.h>
  27. #include <asm/io.h>
  28. #include <asm/smp.h>
  29. #include <asm/tlb.h>
  30. #include <asm/numa.h>
  31. #include <asm/hw_irq.h>
  32. #include <asm/current.h>
  33. #include <asm/sn/sn_cpuid.h>
  34. #include <asm/sn/sn_sal.h>
  35. #include <asm/sn/addrs.h>
  36. #include <asm/sn/shub_mmr.h>
  37. #include <asm/sn/nodepda.h>
  38. #include <asm/sn/rw_mmr.h>
  39. void sn2_ptc_deadlock_recovery(volatile unsigned long *, unsigned long data0,
  40. volatile unsigned long *, unsigned long data1);
  41. static __cacheline_aligned DEFINE_SPINLOCK(sn2_global_ptc_lock);
  42. static unsigned long sn2_ptc_deadlock_count;
  43. static inline unsigned long wait_piowc(void)
  44. {
  45. volatile unsigned long *piows, zeroval;
  46. unsigned long ws;
  47. piows = pda->pio_write_status_addr;
  48. zeroval = pda->pio_write_status_val;
  49. do {
  50. cpu_relax();
  51. } while (((ws = *piows) & SH_PIO_WRITE_STATUS_PENDING_WRITE_COUNT_MASK) != zeroval);
  52. return ws;
  53. }
  54. void sn_tlb_migrate_finish(struct mm_struct *mm)
  55. {
  56. if (mm == current->mm)
  57. flush_tlb_mm(mm);
  58. }
  59. /**
  60. * sn2_global_tlb_purge - globally purge translation cache of virtual address range
  61. * @start: start of virtual address range
  62. * @end: end of virtual address range
  63. * @nbits: specifies number of bytes to purge per instruction (num = 1<<(nbits & 0xfc))
  64. *
  65. * Purges the translation caches of all processors of the given virtual address
  66. * range.
  67. *
  68. * Note:
  69. * - cpu_vm_mask is a bit mask that indicates which cpus have loaded the context.
  70. * - cpu_vm_mask is converted into a nodemask of the nodes containing the
  71. * cpus in cpu_vm_mask.
  72. * - if only one bit is set in cpu_vm_mask & it is the current cpu,
  73. * then only the local TLB needs to be flushed. This flushing can be done
  74. * using ptc.l. This is the common case & avoids the global spinlock.
  75. * - if multiple cpus have loaded the context, then flushing has to be
  76. * done with ptc.g/MMRs under protection of the global ptc_lock.
  77. */
  78. void
  79. sn2_global_tlb_purge(unsigned long start, unsigned long end,
  80. unsigned long nbits)
  81. {
  82. int i, shub1, cnode, mynasid, cpu, lcpu = 0, nasid, flushed = 0;
  83. volatile unsigned long *ptc0, *ptc1;
  84. unsigned long flags = 0, data0 = 0, data1 = 0;
  85. struct mm_struct *mm = current->active_mm;
  86. short nasids[MAX_NUMNODES], nix;
  87. nodemask_t nodes_flushed;
  88. nodes_clear(nodes_flushed);
  89. i = 0;
  90. for_each_cpu_mask(cpu, mm->cpu_vm_mask) {
  91. cnode = cpu_to_node(cpu);
  92. node_set(cnode, nodes_flushed);
  93. lcpu = cpu;
  94. i++;
  95. }
  96. preempt_disable();
  97. if (likely(i == 1 && lcpu == smp_processor_id())) {
  98. do {
  99. ia64_ptcl(start, nbits << 2);
  100. start += (1UL << nbits);
  101. } while (start < end);
  102. ia64_srlz_i();
  103. preempt_enable();
  104. return;
  105. }
  106. if (atomic_read(&mm->mm_users) == 1) {
  107. flush_tlb_mm(mm);
  108. preempt_enable();
  109. return;
  110. }
  111. nix = 0;
  112. for_each_node_mask(cnode, nodes_flushed)
  113. nasids[nix++] = cnodeid_to_nasid(cnode);
  114. shub1 = is_shub1();
  115. if (shub1) {
  116. data0 = (1UL << SH1_PTC_0_A_SHFT) |
  117. (nbits << SH1_PTC_0_PS_SHFT) |
  118. ((ia64_get_rr(start) >> 8) << SH1_PTC_0_RID_SHFT) |
  119. (1UL << SH1_PTC_0_START_SHFT);
  120. ptc0 = (long *)GLOBAL_MMR_PHYS_ADDR(0, SH1_PTC_0);
  121. ptc1 = (long *)GLOBAL_MMR_PHYS_ADDR(0, SH1_PTC_1);
  122. } else {
  123. data0 = (1UL << SH2_PTC_A_SHFT) |
  124. (nbits << SH2_PTC_PS_SHFT) |
  125. (1UL << SH2_PTC_START_SHFT);
  126. ptc0 = (long *)GLOBAL_MMR_PHYS_ADDR(0, SH2_PTC +
  127. ((ia64_get_rr(start) >> 8) << SH2_PTC_RID_SHFT) );
  128. ptc1 = NULL;
  129. }
  130. mynasid = get_nasid();
  131. spin_lock_irqsave(&sn2_global_ptc_lock, flags);
  132. do {
  133. if (shub1)
  134. data1 = start | (1UL << SH1_PTC_1_START_SHFT);
  135. else
  136. data0 = (data0 & ~SH2_PTC_ADDR_MASK) | (start & SH2_PTC_ADDR_MASK);
  137. for (i = 0; i < nix; i++) {
  138. nasid = nasids[i];
  139. if (unlikely(nasid == mynasid)) {
  140. ia64_ptcga(start, nbits << 2);
  141. ia64_srlz_i();
  142. } else {
  143. ptc0 = CHANGE_NASID(nasid, ptc0);
  144. if (ptc1)
  145. ptc1 = CHANGE_NASID(nasid, ptc1);
  146. pio_atomic_phys_write_mmrs(ptc0, data0, ptc1,
  147. data1);
  148. flushed = 1;
  149. }
  150. }
  151. if (flushed
  152. && (wait_piowc() &
  153. SH_PIO_WRITE_STATUS_WRITE_DEADLOCK_MASK)) {
  154. sn2_ptc_deadlock_recovery(ptc0, data0, ptc1, data1);
  155. }
  156. start += (1UL << nbits);
  157. } while (start < end);
  158. spin_unlock_irqrestore(&sn2_global_ptc_lock, flags);
  159. preempt_enable();
  160. }
  161. /*
  162. * sn2_ptc_deadlock_recovery
  163. *
  164. * Recover from PTC deadlocks conditions. Recovery requires stepping thru each
  165. * TLB flush transaction. The recovery sequence is somewhat tricky & is
  166. * coded in assembly language.
  167. */
  168. void sn2_ptc_deadlock_recovery(volatile unsigned long *ptc0, unsigned long data0,
  169. volatile unsigned long *ptc1, unsigned long data1)
  170. {
  171. extern void sn2_ptc_deadlock_recovery_core(volatile unsigned long *, unsigned long,
  172. volatile unsigned long *, unsigned long, volatile unsigned long *, unsigned long);
  173. int cnode, mycnode, nasid;
  174. volatile unsigned long *piows;
  175. volatile unsigned long zeroval;
  176. sn2_ptc_deadlock_count++;
  177. piows = pda->pio_write_status_addr;
  178. zeroval = pda->pio_write_status_val;
  179. mycnode = numa_node_id();
  180. for_each_online_node(cnode) {
  181. if (is_headless_node(cnode) || cnode == mycnode)
  182. continue;
  183. nasid = cnodeid_to_nasid(cnode);
  184. ptc0 = CHANGE_NASID(nasid, ptc0);
  185. if (ptc1)
  186. ptc1 = CHANGE_NASID(nasid, ptc1);
  187. sn2_ptc_deadlock_recovery_core(ptc0, data0, ptc1, data1, piows, zeroval);
  188. }
  189. }
  190. /**
  191. * sn_send_IPI_phys - send an IPI to a Nasid and slice
  192. * @nasid: nasid to receive the interrupt (may be outside partition)
  193. * @physid: physical cpuid to receive the interrupt.
  194. * @vector: command to send
  195. * @delivery_mode: delivery mechanism
  196. *
  197. * Sends an IPI (interprocessor interrupt) to the processor specified by
  198. * @physid
  199. *
  200. * @delivery_mode can be one of the following
  201. *
  202. * %IA64_IPI_DM_INT - pend an interrupt
  203. * %IA64_IPI_DM_PMI - pend a PMI
  204. * %IA64_IPI_DM_NMI - pend an NMI
  205. * %IA64_IPI_DM_INIT - pend an INIT interrupt
  206. */
  207. void sn_send_IPI_phys(int nasid, long physid, int vector, int delivery_mode)
  208. {
  209. long val;
  210. unsigned long flags = 0;
  211. volatile long *p;
  212. p = (long *)GLOBAL_MMR_PHYS_ADDR(nasid, SH_IPI_INT);
  213. val = (1UL << SH_IPI_INT_SEND_SHFT) |
  214. (physid << SH_IPI_INT_PID_SHFT) |
  215. ((long)delivery_mode << SH_IPI_INT_TYPE_SHFT) |
  216. ((long)vector << SH_IPI_INT_IDX_SHFT) |
  217. (0x000feeUL << SH_IPI_INT_BASE_SHFT);
  218. mb();
  219. if (enable_shub_wars_1_1()) {
  220. spin_lock_irqsave(&sn2_global_ptc_lock, flags);
  221. }
  222. pio_phys_write_mmr(p, val);
  223. if (enable_shub_wars_1_1()) {
  224. wait_piowc();
  225. spin_unlock_irqrestore(&sn2_global_ptc_lock, flags);
  226. }
  227. }
  228. EXPORT_SYMBOL(sn_send_IPI_phys);
  229. /**
  230. * sn2_send_IPI - send an IPI to a processor
  231. * @cpuid: target of the IPI
  232. * @vector: command to send
  233. * @delivery_mode: delivery mechanism
  234. * @redirect: redirect the IPI?
  235. *
  236. * Sends an IPI (InterProcessor Interrupt) to the processor specified by
  237. * @cpuid. @vector specifies the command to send, while @delivery_mode can
  238. * be one of the following
  239. *
  240. * %IA64_IPI_DM_INT - pend an interrupt
  241. * %IA64_IPI_DM_PMI - pend a PMI
  242. * %IA64_IPI_DM_NMI - pend an NMI
  243. * %IA64_IPI_DM_INIT - pend an INIT interrupt
  244. */
  245. void sn2_send_IPI(int cpuid, int vector, int delivery_mode, int redirect)
  246. {
  247. long physid;
  248. int nasid;
  249. physid = cpu_physical_id(cpuid);
  250. nasid = cpuid_to_nasid(cpuid);
  251. /* the following is used only when starting cpus at boot time */
  252. if (unlikely(nasid == -1))
  253. ia64_sn_get_sapic_info(physid, &nasid, NULL, NULL);
  254. sn_send_IPI_phys(nasid, physid, vector, delivery_mode);
  255. }