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>
22 #include <asm/processor.h>
24 #include <asm/sn/sgi.h>
26 #include <asm/system.h>
27 #include <asm/delay.h>
31 #include <asm/bitops.h>
32 #include <asm/hw_irq.h>
33 #include <asm/current.h>
34 #include <asm/sn/sn_cpuid.h>
35 #include <asm/sn/addrs.h>
36 #include <asm/sn/sn2/shub_mmr.h>
37 #include <asm/sn/nodepda.h>
38 #include <asm/sn/rw_mmr.h>
40 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;
48 static inline unsigned long
51 volatile unsigned long *piows;
54 piows = pda->pio_write_status_addr;
57 } while (((ws = *piows) & SH_PIO_WRITE_STATUS_0_PENDING_WRITE_COUNT_MASK) !=
58 SH_PIO_WRITE_STATUS_0_PENDING_WRITE_COUNT_MASK);
65 * sn2_global_tlb_purge - globally purge translation cache of virtual address range
66 * @start: start of virtual address range
67 * @end: end of virtual address range
68 * @nbits: specifies number of bytes to purge per instruction (num = 1<<(nbits & 0xfc))
70 * Purges the translation caches of all processors of the given virtual address
74 * - cpu_vm_mask is a bit mask that indicates which cpus have loaded the context.
75 * - cpu_vm_mask is converted into a nodemask of the nodes containing the
76 * cpus in cpu_vm_mask.
77 * - if only one bit is set in cpu_vm_mask & it is the current cpu,
78 * then only the local TLB needs to be flushed. This flushing can be done
79 * using ptc.l. This is the common case & avoids the global spinlock.
80 * - if multiple cpus have loaded the context, then flushing has to be
81 * done with ptc.g/MMRs under protection of the global ptc_lock.
85 sn2_global_tlb_purge (unsigned long start, unsigned long end, unsigned long nbits)
87 int i, cnode, mynasid, cpu, lcpu=0, nasid, flushed=0;
88 volatile unsigned long *ptc0, *ptc1;
89 unsigned long flags=0, data0, data1;
90 struct mm_struct *mm=current->active_mm;
91 short nasids[NR_NODES], nix;
92 DECLARE_BITMAP(nodes_flushed, NR_NODES);
94 bitmap_zero(nodes_flushed, NR_NODES);
98 for_each_cpu_mask(cpu, mm->cpu_vm_mask) {
99 cnode = cpu_to_node(cpu);
100 __set_bit(cnode, nodes_flushed);
107 if (likely(i == 1 && lcpu == smp_processor_id())) {
109 ia64_ptcl(start, nbits<<2);
110 start += (1UL << nbits);
111 } while (start < end);
118 for (cnode=find_first_bit(&nodes_flushed, NR_NODES); cnode < NR_NODES;
119 cnode=find_next_bit(&nodes_flushed, NR_NODES, ++cnode))
120 nasids[nix++] = cnodeid_to_nasid(cnode);
123 data0 = (1UL<<SH_PTC_0_A_SHFT) |
124 (nbits<<SH_PTC_0_PS_SHFT) |
125 ((ia64_get_rr(start)>>8)<<SH_PTC_0_RID_SHFT) |
126 (1UL<<SH_PTC_0_START_SHFT);
128 ptc0 = (long*)GLOBAL_MMR_PHYS_ADDR(0, SH_PTC_0);
129 ptc1 = (long*)GLOBAL_MMR_PHYS_ADDR(0, SH_PTC_1);
132 mynasid = smp_physical_node_id();
134 spin_lock_irqsave(&sn2_global_ptc_lock, flags);
137 data1 = start | (1UL<<SH_PTC_1_START_SHFT);
138 for (i=0; i<nix; i++) {
140 if (likely(nasid == mynasid)) {
141 ia64_ptcga(start, nbits<<2);
144 ptc0 = CHANGE_NASID(nasid, ptc0);
145 ptc1 = CHANGE_NASID(nasid, ptc1);
146 pio_atomic_phys_write_mmrs(ptc0, data0, ptc1, data1);
151 if (flushed && (wait_piowc() & SH_PIO_WRITE_STATUS_0_WRITE_DEADLOCK_MASK)) {
152 sn2_ptc_deadlock_recovery(data0, data1);
155 start += (1UL << nbits);
157 } while (start < end);
159 spin_unlock_irqrestore(&sn2_global_ptc_lock, flags);
165 * sn2_ptc_deadlock_recovery
167 * Recover from PTC deadlocks conditions. Recovery requires stepping thru each
168 * TLB flush transaction. The recovery sequence is somewhat tricky & is
169 * coded in assembly language.
172 sn2_ptc_deadlock_recovery(unsigned long data0, unsigned long data1)
174 extern void sn2_ptc_deadlock_recovery_core(long*, long, long*, long, long*);
175 int cnode, mycnode, nasid;
176 long *ptc0, *ptc1, *piows;
178 sn2_ptc_deadlock_count++;
180 ptc0 = (long*)GLOBAL_MMR_PHYS_ADDR(0, SH_PTC_0);
181 ptc1 = (long*)GLOBAL_MMR_PHYS_ADDR(0, SH_PTC_1);
182 piows = (long*)pda->pio_write_status_addr;
184 mycnode = numa_node_id();
186 for (cnode = 0; cnode < numnodes; cnode++) {
187 if (is_headless_node(cnode) || cnode == mycnode)
189 nasid = cnodeid_to_nasid(cnode);
190 ptc0 = CHANGE_NASID(nasid, ptc0);
191 ptc1 = CHANGE_NASID(nasid, ptc1);
192 sn2_ptc_deadlock_recovery_core(ptc0, data0, ptc1, data1, piows);
197 * sn_send_IPI_phys - send an IPI to a Nasid and slice
198 * @physid: physical cpuid to receive the interrupt.
199 * @vector: command to send
200 * @delivery_mode: delivery mechanism
202 * Sends an IPI (interprocessor interrupt) to the processor specified by
205 * @delivery_mode can be one of the following
207 * %IA64_IPI_DM_INT - pend an interrupt
208 * %IA64_IPI_DM_PMI - pend a PMI
209 * %IA64_IPI_DM_NMI - pend an NMI
210 * %IA64_IPI_DM_INIT - pend an INIT interrupt
213 sn_send_IPI_phys(long physid, int vector, int delivery_mode)
215 long nasid, slice, val;
216 unsigned long flags=0;
219 nasid = cpu_physical_id_to_nasid(physid);
220 slice = cpu_physical_id_to_slice(physid);
222 p = (long*)GLOBAL_MMR_PHYS_ADDR(nasid, SH_IPI_INT);
223 val = (1UL<<SH_IPI_INT_SEND_SHFT) |
224 (physid<<SH_IPI_INT_PID_SHFT) |
225 ((long)delivery_mode<<SH_IPI_INT_TYPE_SHFT) |
226 ((long)vector<<SH_IPI_INT_IDX_SHFT) |
227 (0x000feeUL<<SH_IPI_INT_BASE_SHFT);
230 if (enable_shub_wars_1_1() ) {
231 spin_lock_irqsave(&sn2_global_ptc_lock, flags);
233 pio_phys_write_mmr(p, val);
234 if (enable_shub_wars_1_1() ) {
236 spin_unlock_irqrestore(&sn2_global_ptc_lock, flags);
240 EXPORT_SYMBOL(sn_send_IPI_phys);
243 * sn2_send_IPI - send an IPI to a processor
244 * @cpuid: target of the IPI
245 * @vector: command to send
246 * @delivery_mode: delivery mechanism
247 * @redirect: redirect the IPI?
249 * Sends an IPI (InterProcessor Interrupt) to the processor specified by
250 * @cpuid. @vector specifies the command to send, while @delivery_mode can
251 * be one of the following
253 * %IA64_IPI_DM_INT - pend an interrupt
254 * %IA64_IPI_DM_PMI - pend a PMI
255 * %IA64_IPI_DM_NMI - pend an NMI
256 * %IA64_IPI_DM_INIT - pend an INIT interrupt
259 sn2_send_IPI(int cpuid, int vector, int delivery_mode, int redirect)
263 physid = cpu_physical_id(cpuid);
265 sn_send_IPI_phys(physid, vector, delivery_mode);