xref: /netbsd-src/sys/arch/macppc/macppc/ipi_hammerhead.c (revision d16b7486a53dcb8072b60ec6fcb4373a2d0c27b7)
1 /* $NetBSD: ipi_hammerhead.c,v 1.6 2021/03/05 07:15:53 rin 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_hammerhead.c,v 1.6 2021/03/05 07:15:53 rin Exp $");
33 
34 #include "opt_multiprocessor.h"
35 #include <sys/param.h>
36 #include <sys/malloc.h>
37 #include <sys/kernel.h>
38 #include <sys/atomic.h>
39 
40 #include <machine/pio.h>
41 
42 #include <arch/powerpc/pic/picvar.h>
43 #include <arch/powerpc/pic/ipivar.h>
44 
45 #ifdef MULTIPROCESSOR
46 
47 extern struct ipi_ops ipiops;
48 static void hh_send_ipi(cpuid_t, uint32_t);
49 static void hh_establish_ipi(int, int, void *);
50 
51 #define HH_INTR_SECONDARY	0xf80000c0
52 #define HH_INTR_PRIMARY		0xf3019000
53 #define GC_IPI_IRQ		30
54 
55 void
56 setup_hammerhead_ipi(void)
57 {
58 	ipiops.ppc_send_ipi = hh_send_ipi;
59 	ipiops.ppc_establish_ipi = hh_establish_ipi;
60 	ipiops.ppc_ipi_vector = GC_IPI_IRQ;
61 }
62 
63 static void
64 hh_send_ipi(cpuid_t target, uint32_t mesg)
65 {
66 	int cpu_id = target;
67 
68 	if (target == IPI_DST_ALL) {
69 		atomic_or_32(&cpu_info[0].ci_pending_ipis, mesg);
70 		atomic_or_32(&cpu_info[1].ci_pending_ipis, mesg);
71 		in32(HH_INTR_PRIMARY);
72 		out32(HH_INTR_SECONDARY, ~0);
73 		out32(HH_INTR_SECONDARY, 0);
74 		return;
75 	}
76 
77 	if (target == IPI_DST_NOTME) {
78 		cpu_id = cpu_number() ^ 1;
79 	}
80 
81 	atomic_or_32(&cpu_info[cpu_id].ci_pending_ipis, mesg);
82 	switch (cpu_id) {
83 	case 0:
84 		in32(HH_INTR_PRIMARY);
85 		break;
86 	case 1:
87 		out32(HH_INTR_SECONDARY, ~0);
88 		out32(HH_INTR_SECONDARY, 0);
89 		break;
90 	}
91 }
92 
93 static void
94 hh_establish_ipi(int type, int level, void *ih_args)
95 {
96 	intr_establish_xname(ipiops.ppc_ipi_vector, type, level, ipi_intr,
97 	    ih_args, "hh ipi");
98 }
99 
100 #endif /*MULTIPROCESSOR*/
101