xref: /onnv-gate/usr/src/uts/i86pc/os/mp_call.c (revision 11389:dd00b884e84f)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
53446Smrj  * Common Development and Distribution License (the "License").
63446Smrj  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
213446Smrj 
220Sstevel@tonic-gate /*
239489SJoe.Bonasera@sun.com  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
243446Smrj  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #include <sys/types.h>
280Sstevel@tonic-gate #include <sys/param.h>
290Sstevel@tonic-gate #include <sys/thread.h>
300Sstevel@tonic-gate #include <sys/cpuvar.h>
310Sstevel@tonic-gate #include <sys/machsystm.h>
320Sstevel@tonic-gate #include <sys/systm.h>
333446Smrj #include <sys/promif.h>
349489SJoe.Bonasera@sun.com #include <sys/xc_levels.h>
35*11389SAlexander.Kolbasov@Sun.COM #include <sys/spl.h>
36*11389SAlexander.Kolbasov@Sun.COM #include <sys/bitmap.h>
370Sstevel@tonic-gate 
380Sstevel@tonic-gate /*
390Sstevel@tonic-gate  * Interrupt another CPU.
400Sstevel@tonic-gate  * 	This is useful to make the other CPU go through a trap so that
410Sstevel@tonic-gate  *	it recognizes an address space trap (AST) for preempting a thread.
420Sstevel@tonic-gate  *
430Sstevel@tonic-gate  *	It is possible to be preempted here and be resumed on the CPU
440Sstevel@tonic-gate  *	being poked, so it isn't an error to poke the current CPU.
450Sstevel@tonic-gate  *	We could check this and still get preempted after the check, so
460Sstevel@tonic-gate  *	we don't bother.
470Sstevel@tonic-gate  */
480Sstevel@tonic-gate void
poke_cpu(int cpun)490Sstevel@tonic-gate poke_cpu(int cpun)
500Sstevel@tonic-gate {
513446Smrj 	if (panicstr)
523446Smrj 		return;
530Sstevel@tonic-gate 	/*
540Sstevel@tonic-gate 	 * We don't need to receive an ACK from the CPU being poked,
550Sstevel@tonic-gate 	 * so just send out a directed interrupt.
560Sstevel@tonic-gate 	 */
573446Smrj 	send_dirint(cpun, XC_CPUPOKE_PIL);
580Sstevel@tonic-gate }
59*11389SAlexander.Kolbasov@Sun.COM 
60*11389SAlexander.Kolbasov@Sun.COM /*
61*11389SAlexander.Kolbasov@Sun.COM  * Call a function on a target CPU
62*11389SAlexander.Kolbasov@Sun.COM  */
63*11389SAlexander.Kolbasov@Sun.COM void
cpu_call(cpu_t * cp,cpu_call_func_t func,uintptr_t arg1,uintptr_t arg2)64*11389SAlexander.Kolbasov@Sun.COM cpu_call(cpu_t *cp, cpu_call_func_t func, uintptr_t arg1, uintptr_t arg2)
65*11389SAlexander.Kolbasov@Sun.COM {
66*11389SAlexander.Kolbasov@Sun.COM 	cpuset_t set;
67*11389SAlexander.Kolbasov@Sun.COM 
68*11389SAlexander.Kolbasov@Sun.COM 	if (panicstr)
69*11389SAlexander.Kolbasov@Sun.COM 		return;
70*11389SAlexander.Kolbasov@Sun.COM 
71*11389SAlexander.Kolbasov@Sun.COM 	/*
72*11389SAlexander.Kolbasov@Sun.COM 	 * Prevent CPU from going off-line
73*11389SAlexander.Kolbasov@Sun.COM 	 */
74*11389SAlexander.Kolbasov@Sun.COM 	kpreempt_disable();
75*11389SAlexander.Kolbasov@Sun.COM 
76*11389SAlexander.Kolbasov@Sun.COM 	/*
77*11389SAlexander.Kolbasov@Sun.COM 	 * If we are on the target CPU, call the function directly, but raise
78*11389SAlexander.Kolbasov@Sun.COM 	 * the PIL to XC_PIL.
79*11389SAlexander.Kolbasov@Sun.COM 	 * This guarantees that functions called via cpu_call() can not ever
80*11389SAlexander.Kolbasov@Sun.COM 	 * interrupt each other.
81*11389SAlexander.Kolbasov@Sun.COM 	 */
82*11389SAlexander.Kolbasov@Sun.COM 	if (CPU == cp) {
83*11389SAlexander.Kolbasov@Sun.COM 		int save_spl = splr(ipltospl(XC_HI_PIL));
84*11389SAlexander.Kolbasov@Sun.COM 
85*11389SAlexander.Kolbasov@Sun.COM 		(*func)(arg1, arg2);
86*11389SAlexander.Kolbasov@Sun.COM 		splx(save_spl);
87*11389SAlexander.Kolbasov@Sun.COM 	} else {
88*11389SAlexander.Kolbasov@Sun.COM 		CPUSET_ONLY(set, cp->cpu_id);
89*11389SAlexander.Kolbasov@Sun.COM 		xc_call((xc_arg_t)arg1, (xc_arg_t)arg2, 0, CPUSET2BV(set),
90*11389SAlexander.Kolbasov@Sun.COM 		    (xc_func_t)func);
91*11389SAlexander.Kolbasov@Sun.COM 	}
92*11389SAlexander.Kolbasov@Sun.COM 	kpreempt_enable();
93*11389SAlexander.Kolbasov@Sun.COM }
94