xref: /titanic_51/usr/src/uts/sun4/os/mp_call.c (revision b885580b43755ee4ea1e280b85428893d2ba9291)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*b885580bSAlexander Kolbasov  * Common Development and Distribution License (the "License").
6*b885580bSAlexander Kolbasov  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*b885580bSAlexander Kolbasov  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * Facilities for cross-processor subroutine calls using "mailbox" interrupts.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <sys/types.h>
317c478bd9Sstevel@tonic-gate #include <sys/thread.h>
327c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
337c478bd9Sstevel@tonic-gate #include <sys/x_call.h>
347c478bd9Sstevel@tonic-gate #include <sys/systm.h>
357c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
367c478bd9Sstevel@tonic-gate #include <sys/intr.h>
37*b885580bSAlexander Kolbasov #include <sys/xc_impl.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * Interrupt another CPU.
417c478bd9Sstevel@tonic-gate  * 	This is useful to make the other CPU go through a trap so that
427c478bd9Sstevel@tonic-gate  *	it recognizes an address space trap (AST) for preempting a thread.
437c478bd9Sstevel@tonic-gate  *
447c478bd9Sstevel@tonic-gate  *	It is possible to be preempted here and be resumed on the CPU
457c478bd9Sstevel@tonic-gate  *	being poked, so it isn't an error to poke the current CPU.
467c478bd9Sstevel@tonic-gate  *	We could check this and still get preempted after the check, so
477c478bd9Sstevel@tonic-gate  *	we don't bother.
487c478bd9Sstevel@tonic-gate  */
497c478bd9Sstevel@tonic-gate void
507c478bd9Sstevel@tonic-gate poke_cpu(int cpun)
517c478bd9Sstevel@tonic-gate {
527c478bd9Sstevel@tonic-gate 	uint32_t *ptr = (uint32_t *)&cpu[cpun]->cpu_m.poke_cpu_outstanding;
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate 	/*
557c478bd9Sstevel@tonic-gate 	 * If panicstr is set or a poke_cpu is already pending,
567c478bd9Sstevel@tonic-gate 	 * no need to send another one. Use atomic swap to protect
577c478bd9Sstevel@tonic-gate 	 * against multiple CPUs sending redundant pokes.
587c478bd9Sstevel@tonic-gate 	 */
597c478bd9Sstevel@tonic-gate 	if (panicstr || *ptr == B_TRUE ||
607c478bd9Sstevel@tonic-gate 	    atomic_swap_32(ptr, B_TRUE) == B_TRUE)
617c478bd9Sstevel@tonic-gate 		return;
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate 	xt_one(cpun, setsoftint_tl1, poke_cpu_inum, 0);
647c478bd9Sstevel@tonic-gate }
65*b885580bSAlexander Kolbasov 
66*b885580bSAlexander Kolbasov extern int xc_spl_enter[];
67*b885580bSAlexander Kolbasov 
68*b885580bSAlexander Kolbasov /*
69*b885580bSAlexander Kolbasov  * Call a function on a target CPU
70*b885580bSAlexander Kolbasov  */
71*b885580bSAlexander Kolbasov void
72*b885580bSAlexander Kolbasov cpu_call(cpu_t *cp, cpu_call_func_t func, uintptr_t arg1, uintptr_t arg2)
73*b885580bSAlexander Kolbasov {
74*b885580bSAlexander Kolbasov 	if (panicstr)
75*b885580bSAlexander Kolbasov 		return;
76*b885580bSAlexander Kolbasov 
77*b885580bSAlexander Kolbasov 	/*
78*b885580bSAlexander Kolbasov 	 * Prevent CPU from going offline
79*b885580bSAlexander Kolbasov 	 */
80*b885580bSAlexander Kolbasov 	kpreempt_disable();
81*b885580bSAlexander Kolbasov 
82*b885580bSAlexander Kolbasov 	/*
83*b885580bSAlexander Kolbasov 	 * If we are on the target CPU, call the function directly, but raise
84*b885580bSAlexander Kolbasov 	 * the PIL to XC_PIL.
85*b885580bSAlexander Kolbasov 	 * This guarantees that functions called via cpu_call() can not ever
86*b885580bSAlexander Kolbasov 	 * interrupt each other.
87*b885580bSAlexander Kolbasov 	 */
88*b885580bSAlexander Kolbasov 	if (CPU != cp) {
89*b885580bSAlexander Kolbasov 		xc_one(cp->cpu_id, (xcfunc_t *)func, (uint64_t)arg1,
90*b885580bSAlexander Kolbasov 		    (uint64_t)arg2);
91*b885580bSAlexander Kolbasov 	} else {
92*b885580bSAlexander Kolbasov 		int lcx;
93*b885580bSAlexander Kolbasov 		int opl;
94*b885580bSAlexander Kolbasov 
95*b885580bSAlexander Kolbasov 		XC_SPL_ENTER(lcx, opl);
96*b885580bSAlexander Kolbasov 		func(arg1, arg2);
97*b885580bSAlexander Kolbasov 		XC_SPL_EXIT(lcx, opl);
98*b885580bSAlexander Kolbasov 	}
99*b885580bSAlexander Kolbasov 
100*b885580bSAlexander Kolbasov 	kpreempt_enable();
101*b885580bSAlexander Kolbasov }
102