1 /* $NetBSD: ipi_openpic.c,v 1.7 2012/02/01 09:54:03 matt Exp $ */ 2 /*- 3 * Copyright (c) 2007 The NetBSD Foundation, Inc. 4 * All rights reserved. 5 * 6 * This code is derived from software contributed to The NetBSD Foundation 7 * by Tim Rightnour 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #include <sys/cdefs.h> 32 __KERNEL_RCSID(0, "$NetBSD: ipi_openpic.c,v 1.7 2012/02/01 09:54:03 matt Exp $"); 33 34 #include "opt_multiprocessor.h" 35 #include <sys/param.h> 36 #include <sys/kernel.h> 37 #include <sys/atomic.h> 38 #include <sys/cpu.h> 39 40 #include <uvm/uvm_extern.h> 41 42 #include <machine/pio.h> 43 #include <powerpc/openpic.h> 44 45 #include <powerpc/pic/picvar.h> 46 #include <powerpc/pic/ipivar.h> 47 48 #ifdef MULTIPROCESSOR 49 50 extern struct ipi_ops ipiops; 51 static void openpic_send_ipi(cpuid_t, uint32_t); 52 static void openpic_establish_ipi(int, int, void *); 53 54 void 55 setup_openpic_ipi(void) 56 { 57 uint32_t x; 58 59 ipiops.ppc_send_ipi = openpic_send_ipi; 60 ipiops.ppc_establish_ipi = openpic_establish_ipi; 61 ipiops.ppc_ipi_vector = IPI_VECTOR; 62 63 /* Some (broken) openpic's byteswap on read, but not write. */ 64 openpic_write(OPENPIC_IPI_VECTOR(0), OPENPIC_IMASK); 65 x = openpic_read(OPENPIC_IPI_VECTOR(0)); 66 if (x != OPENPIC_IMASK) 67 x = bswap32(openpic_read(OPENPIC_IPI_VECTOR(1))); 68 else 69 x = openpic_read(OPENPIC_IPI_VECTOR(1)); 70 x &= ~(OPENPIC_IMASK | OPENPIC_PRIORITY_MASK | OPENPIC_VECTOR_MASK); 71 x |= (15 << OPENPIC_PRIORITY_SHIFT) | ipiops.ppc_ipi_vector; 72 openpic_write(OPENPIC_IPI_VECTOR(1), x); 73 } 74 75 static void 76 openpic_send_ipi(cpuid_t target, uint32_t mesg) 77 { 78 struct cpu_info * const ci = curcpu(); 79 uint32_t cpumask = 0; 80 81 switch (target) { 82 case IPI_DST_ALL: 83 case IPI_DST_NOTME: 84 for (u_int i = 0; i < ncpu; i++) { 85 struct cpu_info * const dst_ci = cpu_lookup(i); 86 if (target == IPI_DST_ALL || dst_ci != ci) { 87 cpumask |= 1 << cpu_index(dst_ci); 88 atomic_or_32(&dst_ci->ci_pending_ipis, 89 mesg); 90 } 91 } 92 break; 93 default: { 94 struct cpu_info * const dst_ci = cpu_lookup(target); 95 cpumask = 1 << cpu_index(dst_ci); 96 atomic_or_32(&dst_ci->ci_pending_ipis, mesg); 97 break; 98 } 99 } 100 openpic_write(OPENPIC_IPI(cpu_index(ci), 1), cpumask); 101 } 102 103 static void 104 openpic_establish_ipi(int type, int level, void *ih_args) 105 { 106 /* 107 * XXX 108 * for now we catch IPIs early in pic_handle_intr() so no need to do anything 109 * here 110 */ 111 #if 0 112 intr_establish(ipiops.ppc_ipi_vector, type, level, ppcipi_intr, 113 ih_args); 114 #endif 115 } 116 117 #endif /*MULTIPROCESSOR*/ 118