2 * SN2 Platform specific SMP Support
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
8 * Copyright (C) 2000-2004 Silicon Graphics, Inc. All rights reserved.
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <linux/spinlock.h>
14 #include <linux/threads.h>
15 #include <linux/sched.h>
16 #include <linux/smp.h>
17 #include <linux/interrupt.h>
18 #include <linux/irq.h>
19 #include <linux/mmzone.h>
20 #include <linux/module.h>
21 #include <linux/bitops.h>
23 #include <asm/processor.h>
26 #include <asm/system.h>
27 #include <asm/delay.h>
32 #include <asm/hw_irq.h>
33 #include <asm/current.h>
34 #include <asm/sn/sn_cpuid.h>
35 #include <asm/sn/sn_sal.h>
36 #include <asm/sn/addrs.h>
37 #include <asm/sn/shub_mmr.h>
38 #include <asm/sn/nodepda.h>
39 #include <asm/sn/rw_mmr.h>
41 void sn2_ptc_deadlock_recovery(unsigned long data0, unsigned long data1);
43 static spinlock_t sn2_global_ptc_lock __cacheline_aligned = SPIN_LOCK_UNLOCKED;
45 static unsigned long sn2_ptc_deadlock_count;
47 static inline unsigned long wait_piowc(void)
49 volatile unsigned long *piows;
52 piows = pda->pio_write_status_addr;
56 *piows) & SH_PIO_WRITE_STATUS_0_PENDING_WRITE_COUNT_MASK) !=
57 SH_PIO_WRITE_STATUS_0_PENDING_WRITE_COUNT_MASK);
61 void sn_tlb_migrate_finish(struct mm_struct *mm)
63 if (mm == current->mm)
68 * sn2_global_tlb_purge - globally purge translation cache of virtual address range
69 * @start: start of virtual address range
70 * @end: end of virtual address range
71 * @nbits: specifies number of bytes to purge per instruction (num = 1<<(nbits & 0xfc))
73 * Purges the translation caches of all processors of the given virtual address
77 * - cpu_vm_mask is a bit mask that indicates which cpus have loaded the context.
78 * - cpu_vm_mask is converted into a nodemask of the nodes containing the
79 * cpus in cpu_vm_mask.
80 * - if only one bit is set in cpu_vm_mask & it is the current cpu,
81 * then only the local TLB needs to be flushed. This flushing can be done
82 * using ptc.l. This is the common case & avoids the global spinlock.
83 * - if multiple cpus have loaded the context, then flushing has to be
84 * done with ptc.g/MMRs under protection of the global ptc_lock.
88 sn2_global_tlb_purge(unsigned long start, unsigned long end,
91 int i, cnode, mynasid, cpu, lcpu = 0, nasid, flushed = 0;
92 volatile unsigned long *ptc0, *ptc1;
93 unsigned long flags = 0, data0, data1;
94 struct mm_struct *mm = current->active_mm;
95 short nasids[NR_NODES], nix;
96 DECLARE_BITMAP(nodes_flushed, NR_NODES);
98 bitmap_zero(nodes_flushed, NR_NODES);
102 for_each_cpu_mask(cpu, mm->cpu_vm_mask) {
103 cnode = cpu_to_node(cpu);
104 __set_bit(cnode, nodes_flushed);
111 if (likely(i == 1 && lcpu == smp_processor_id())) {
113 ia64_ptcl(start, nbits << 2);
114 start += (1UL << nbits);
115 } while (start < end);
121 if (atomic_read(&mm->mm_users) == 1) {
128 for (cnode = find_first_bit(&nodes_flushed, NR_NODES); cnode < NR_NODES;
129 cnode = find_next_bit(&nodes_flushed, NR_NODES, ++cnode))
130 nasids[nix++] = cnodeid_to_nasid(cnode);
132 data0 = (1UL << SH_PTC_0_A_SHFT) |
133 (nbits << SH_PTC_0_PS_SHFT) |
134 ((ia64_get_rr(start) >> 8) << SH_PTC_0_RID_SHFT) |
135 (1UL << SH_PTC_0_START_SHFT);
137 ptc0 = (long *)GLOBAL_MMR_PHYS_ADDR(0, SH_PTC_0);
138 ptc1 = (long *)GLOBAL_MMR_PHYS_ADDR(0, SH_PTC_1);
140 mynasid = get_nasid();
142 spin_lock_irqsave(&sn2_global_ptc_lock, flags);
145 data1 = start | (1UL << SH_PTC_1_START_SHFT);
146 for (i = 0; i < nix; i++) {
148 if (likely(nasid == mynasid)) {
149 ia64_ptcga(start, nbits << 2);
152 ptc0 = CHANGE_NASID(nasid, ptc0);
153 ptc1 = CHANGE_NASID(nasid, ptc1);
154 pio_atomic_phys_write_mmrs(ptc0, data0, ptc1,
162 SH_PIO_WRITE_STATUS_0_WRITE_DEADLOCK_MASK)) {
163 sn2_ptc_deadlock_recovery(data0, data1);
166 start += (1UL << nbits);
168 } while (start < end);
170 spin_unlock_irqrestore(&sn2_global_ptc_lock, flags);
176 * sn2_ptc_deadlock_recovery
178 * Recover from PTC deadlocks conditions. Recovery requires stepping thru each
179 * TLB flush transaction. The recovery sequence is somewhat tricky & is
180 * coded in assembly language.
182 void sn2_ptc_deadlock_recovery(unsigned long data0, unsigned long data1)
184 extern void sn2_ptc_deadlock_recovery_core(long *, long, long *, long,
186 int cnode, mycnode, nasid;
187 long *ptc0, *ptc1, *piows;
189 sn2_ptc_deadlock_count++;
191 ptc0 = (long *)GLOBAL_MMR_PHYS_ADDR(0, SH_PTC_0);
192 ptc1 = (long *)GLOBAL_MMR_PHYS_ADDR(0, SH_PTC_1);
193 piows = (long *)pda->pio_write_status_addr;
195 mycnode = numa_node_id();
197 for (cnode = 0; cnode < numnodes; cnode++) {
198 if (is_headless_node(cnode) || cnode == mycnode)
200 nasid = cnodeid_to_nasid(cnode);
201 ptc0 = CHANGE_NASID(nasid, ptc0);
202 ptc1 = CHANGE_NASID(nasid, ptc1);
203 sn2_ptc_deadlock_recovery_core(ptc0, data0, ptc1, data1, piows);
208 * sn_send_IPI_phys - send an IPI to a Nasid and slice
209 * @nasid: nasid to receive the interrupt (may be outside partition)
210 * @physid: physical cpuid to receive the interrupt.
211 * @vector: command to send
212 * @delivery_mode: delivery mechanism
214 * Sends an IPI (interprocessor interrupt) to the processor specified by
217 * @delivery_mode can be one of the following
219 * %IA64_IPI_DM_INT - pend an interrupt
220 * %IA64_IPI_DM_PMI - pend a PMI
221 * %IA64_IPI_DM_NMI - pend an NMI
222 * %IA64_IPI_DM_INIT - pend an INIT interrupt
224 void sn_send_IPI_phys(int nasid, long physid, int vector, int delivery_mode)
227 unsigned long flags = 0;
230 p = (long *)GLOBAL_MMR_PHYS_ADDR(nasid, SH_IPI_INT);
231 val = (1UL << SH_IPI_INT_SEND_SHFT) |
232 (physid << SH_IPI_INT_PID_SHFT) |
233 ((long)delivery_mode << SH_IPI_INT_TYPE_SHFT) |
234 ((long)vector << SH_IPI_INT_IDX_SHFT) |
235 (0x000feeUL << SH_IPI_INT_BASE_SHFT);
238 if (enable_shub_wars_1_1()) {
239 spin_lock_irqsave(&sn2_global_ptc_lock, flags);
241 pio_phys_write_mmr(p, val);
242 if (enable_shub_wars_1_1()) {
244 spin_unlock_irqrestore(&sn2_global_ptc_lock, flags);
249 EXPORT_SYMBOL(sn_send_IPI_phys);
252 * sn2_send_IPI - send an IPI to a processor
253 * @cpuid: target of the IPI
254 * @vector: command to send
255 * @delivery_mode: delivery mechanism
256 * @redirect: redirect the IPI?
258 * Sends an IPI (InterProcessor Interrupt) to the processor specified by
259 * @cpuid. @vector specifies the command to send, while @delivery_mode can
260 * be one of the following
262 * %IA64_IPI_DM_INT - pend an interrupt
263 * %IA64_IPI_DM_PMI - pend a PMI
264 * %IA64_IPI_DM_NMI - pend an NMI
265 * %IA64_IPI_DM_INIT - pend an INIT interrupt
267 void sn2_send_IPI(int cpuid, int vector, int delivery_mode, int redirect)
272 physid = cpu_physical_id(cpuid);
273 nasid = cpuid_to_nasid(cpuid);
275 /* the following is used only when starting cpus at boot time */
276 if (unlikely(nasid == -1))
277 ia64_sn_get_sapic_info(physid, &nasid, NULL, NULL);
279 sn_send_IPI_phys(nasid, physid, vector, delivery_mode);