Home | History | Annotate | Line # | Download | only in pic
ipi.c revision 1.6
      1  1.6    rmind /* $NetBSD: ipi.c,v 1.6 2010/06/25 19:00:05 rmind Exp $ */
      2  1.2  garbled /*-
      3  1.2  garbled  * Copyright (c) 2007 The NetBSD Foundation, Inc.
      4  1.2  garbled  * All rights reserved.
      5  1.2  garbled  *
      6  1.2  garbled  * This code is derived from software contributed to The NetBSD Foundation
      7  1.2  garbled  * by Tim Rightnour
      8  1.2  garbled  *
      9  1.2  garbled  * Redistribution and use in source and binary forms, with or without
     10  1.2  garbled  * modification, are permitted provided that the following conditions
     11  1.2  garbled  * are met:
     12  1.2  garbled  * 1. Redistributions of source code must retain the above copyright
     13  1.2  garbled  *    notice, this list of conditions and the following disclaimer.
     14  1.2  garbled  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.2  garbled  *    notice, this list of conditions and the following disclaimer in the
     16  1.2  garbled  *    documentation and/or other materials provided with the distribution.
     17  1.2  garbled  *
     18  1.2  garbled  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     19  1.2  garbled  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     20  1.2  garbled  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21  1.2  garbled  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     22  1.2  garbled  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23  1.2  garbled  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24  1.2  garbled  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25  1.2  garbled  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26  1.2  garbled  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27  1.2  garbled  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28  1.2  garbled  * POSSIBILITY OF SUCH DAMAGE.
     29  1.2  garbled  */
     30  1.2  garbled 
     31  1.2  garbled #include <sys/cdefs.h>
     32  1.6    rmind __KERNEL_RCSID(0, "$NetBSD: ipi.c,v 1.6 2010/06/25 19:00:05 rmind Exp $");
     33  1.2  garbled 
     34  1.2  garbled #include "opt_multiprocessor.h"
     35  1.2  garbled #include "opt_pic.h"
     36  1.2  garbled #include "opt_interrupt.h"
     37  1.2  garbled #include "opt_altivec.h"
     38  1.2  garbled 
     39  1.2  garbled #include <sys/param.h>
     40  1.2  garbled #include <sys/kernel.h>
     41  1.6    rmind #include <sys/xcall.h>
     42  1.2  garbled 
     43  1.2  garbled #include <powerpc/atomic.h>
     44  1.2  garbled #include <powerpc/fpu.h>
     45  1.2  garbled #include <powerpc/altivec.h>
     46  1.2  garbled 
     47  1.2  garbled #include <arch/powerpc/pic/picvar.h>
     48  1.2  garbled #include <arch/powerpc/pic/ipivar.h>
     49  1.2  garbled #include "opt_ipi.h"
     50  1.2  garbled 
     51  1.2  garbled #ifdef MULTIPROCESSOR
     52  1.2  garbled 
     53  1.2  garbled struct ipi_ops ipiops;
     54  1.2  garbled volatile u_long IPI[CPU_MAXNUM];
     55  1.2  garbled 
     56  1.2  garbled /* Process an actual IPI */
     57  1.2  garbled 
     58  1.2  garbled int
     59  1.2  garbled ppcipi_intr(void *v)
     60  1.2  garbled {
     61  1.3  garbled 	int cpu_id = curcpu()->ci_index;
     62  1.2  garbled 	int msr;
     63  1.2  garbled 	u_long ipi;
     64  1.2  garbled 
     65  1.2  garbled 	curcpu()->ci_ev_ipi.ev_count++;
     66  1.2  garbled 	ipi = atomic_loadlatch_ulong(&IPI[cpu_id], 0);
     67  1.2  garbled 
     68  1.2  garbled 	if (ipi == PPC_IPI_NOMESG)
     69  1.2  garbled 		return 1;
     70  1.2  garbled 
     71  1.2  garbled 	if (ipi & PPC_IPI_FLUSH_FPU)
     72  1.2  garbled 		save_fpu_cpu();
     73  1.2  garbled 
     74  1.2  garbled #ifdef ALTIVEC
     75  1.2  garbled 	if (ipi & PPC_IPI_FLUSH_VEC)
     76  1.2  garbled 		save_vec_cpu();
     77  1.2  garbled #endif
     78  1.2  garbled 
     79  1.5    rmind 	if (ipi & PPC_IPI_XCALL)
     80  1.5    rmind 		xc_ipi_handler();
     81  1.5    rmind 
     82  1.2  garbled 	if (ipi & PPC_IPI_HALT) {
     83  1.2  garbled 		aprint_normal("halting CPU %d\n", cpu_id);
     84  1.2  garbled 		msr = (mfmsr() & ~PSL_EE) | PSL_POW;
     85  1.2  garbled 		for (;;) {
     86  1.2  garbled 			__asm volatile ("sync; isync");
     87  1.2  garbled 			mtmsr(msr);
     88  1.2  garbled 		}
     89  1.2  garbled 	}
     90  1.5    rmind 
     91  1.2  garbled 	return 1;
     92  1.2  garbled }
     93  1.2  garbled 
     94  1.5    rmind /*
     95  1.5    rmind  * MD support for xcall(9) interface.
     96  1.5    rmind  */
     97  1.5    rmind 
     98  1.5    rmind void
     99  1.5    rmind xc_send_ipi(struct cpu_info *ci)
    100  1.5    rmind {
    101  1.5    rmind 
    102  1.5    rmind 	KASSERT(kpreempt_disabled());
    103  1.5    rmind 	KASSERT(curcpu() != ci);
    104  1.5    rmind 
    105  1.5    rmind 	if (ci) {
    106  1.5    rmind 		/* Unicast: remote CPU. */
    107  1.5    rmind 		ppc_send_ipi(ci->ci_cpuid, PPC_IPI_XCALL);
    108  1.5    rmind 	} else {
    109  1.5    rmind 		/* Broadcast: all, but local CPU (caller will handle it). */
    110  1.5    rmind 		ppc_send_ipi(IPI_T_NOTME, PPC_IPI_XCALL);
    111  1.5    rmind 	}
    112  1.5    rmind }
    113  1.5    rmind 
    114  1.2  garbled #endif /*MULTIPROCESSOR*/
    115