Home | History | Annotate | Line # | Download | only in pic
ipi_openpic.c revision 1.4.28.1
      1  1.4.28.1   jruoho /* $NetBSD: ipi_openpic.c,v 1.4.28.1 2011/06/06 09:06:30 jruoho 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.4.28.1   jruoho __KERNEL_RCSID(0, "$NetBSD: ipi_openpic.c,v 1.4.28.1 2011/06/06 09:06:30 jruoho Exp $");
     33       1.2  garbled 
     34       1.2  garbled #include "opt_multiprocessor.h"
     35       1.2  garbled #include <sys/param.h>
     36       1.2  garbled #include <sys/malloc.h>
     37       1.2  garbled #include <sys/kernel.h>
     38  1.4.28.1   jruoho #include <sys/atomic.h>
     39  1.4.28.1   jruoho #include <sys/cpu.h>
     40       1.2  garbled 
     41       1.2  garbled #include <uvm/uvm_extern.h>
     42       1.2  garbled 
     43       1.2  garbled #include <machine/pio.h>
     44       1.2  garbled #include <powerpc/openpic.h>
     45       1.2  garbled 
     46       1.2  garbled #include <arch/powerpc/pic/picvar.h>
     47       1.2  garbled #include <arch/powerpc/pic/ipivar.h>
     48       1.2  garbled 
     49       1.2  garbled #ifdef MULTIPROCESSOR
     50       1.2  garbled 
     51       1.2  garbled extern struct ipi_ops ipiops;
     52  1.4.28.1   jruoho static void openpic_send_ipi(cpuid_t, uint32_t);
     53       1.2  garbled static void openpic_establish_ipi(int, int, void *);
     54       1.2  garbled 
     55       1.2  garbled void
     56       1.2  garbled setup_openpic_ipi(void)
     57       1.2  garbled {
     58       1.2  garbled 	uint32_t x;
     59       1.2  garbled 
     60       1.2  garbled 	ipiops.ppc_send_ipi = openpic_send_ipi;
     61       1.2  garbled 	ipiops.ppc_establish_ipi = openpic_establish_ipi;
     62       1.2  garbled 	ipiops.ppc_ipi_vector = IPI_VECTOR;
     63       1.2  garbled 
     64       1.3  garbled 	/* Some (broken) openpic's byteswap on read, but not write. */
     65       1.3  garbled 	openpic_write(OPENPIC_IPI_VECTOR(0), OPENPIC_IMASK);
     66       1.3  garbled 	x = openpic_read(OPENPIC_IPI_VECTOR(0));
     67       1.3  garbled 	if (x != OPENPIC_IMASK)
     68       1.3  garbled 		x = bswap32(openpic_read(OPENPIC_IPI_VECTOR(1)));
     69       1.3  garbled 	else
     70       1.3  garbled 		x = openpic_read(OPENPIC_IPI_VECTOR(1));
     71       1.2  garbled 	x &= ~(OPENPIC_IMASK | OPENPIC_PRIORITY_MASK | OPENPIC_VECTOR_MASK);
     72       1.2  garbled 	x |= (15 << OPENPIC_PRIORITY_SHIFT) | ipiops.ppc_ipi_vector;
     73       1.2  garbled 	openpic_write(OPENPIC_IPI_VECTOR(1), x);
     74       1.2  garbled }
     75       1.2  garbled 
     76       1.2  garbled static void
     77  1.4.28.1   jruoho openpic_send_ipi(cpuid_t target, uint32_t mesg)
     78       1.2  garbled {
     79  1.4.28.1   jruoho 	struct cpu_info * const ci = curcpu();
     80  1.4.28.1   jruoho 	uint32_t cpumask = 0;
     81       1.2  garbled 
     82  1.4.28.1   jruoho 	switch (target) {
     83  1.4.28.1   jruoho 		case IPI_DST_ALL:
     84  1.4.28.1   jruoho 		case IPI_DST_NOTME:
     85  1.4.28.1   jruoho 			for (u_int i = 0; i < ncpu; i++) {
     86  1.4.28.1   jruoho 				struct cpu_info * const dst_ci = cpu_lookup(i);
     87  1.4.28.1   jruoho 				if (target == IPI_DST_ALL || dst_ci != ci) {
     88  1.4.28.1   jruoho 					cpumask |= 1 << cpu_index(dst_ci);
     89  1.4.28.1   jruoho 					atomic_or_32(&dst_ci->ci_pending_ipis,
     90  1.4.28.1   jruoho 					    mesg);
     91  1.4.28.1   jruoho 				}
     92       1.2  garbled 			}
     93       1.2  garbled 			break;
     94  1.4.28.1   jruoho 		default: {
     95  1.4.28.1   jruoho 			struct cpu_info * const dst_ci = cpu_lookup(target);
     96  1.4.28.1   jruoho 			cpumask = 1 << cpu_index(dst_ci);
     97  1.4.28.1   jruoho 			atomic_or_32(&dst_ci->ci_pending_ipis, mesg);
     98       1.2  garbled 			break;
     99  1.4.28.1   jruoho 		}
    100       1.2  garbled 	}
    101  1.4.28.1   jruoho 	openpic_write(OPENPIC_IPI(cpu_index(ci), 1), cpumask);
    102       1.2  garbled }
    103       1.2  garbled 
    104       1.2  garbled static void
    105       1.2  garbled openpic_establish_ipi(int type, int level, void *ih_args)
    106       1.2  garbled {
    107       1.2  garbled /*
    108       1.2  garbled  * XXX
    109       1.2  garbled  * for now we catch IPIs early in pic_handle_intr() so no need to do anything
    110       1.2  garbled  * here
    111       1.2  garbled  */
    112       1.2  garbled #if 0
    113       1.2  garbled 	intr_establish(ipiops.ppc_ipi_vector, type, level, ppcipi_intr,
    114       1.2  garbled 	    ih_args);
    115       1.2  garbled #endif
    116       1.2  garbled }
    117       1.2  garbled 
    118       1.2  garbled #endif /*MULTIPROCESSOR*/
    119