Annotation of sys/arch/amd64/amd64/ipi.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: ipi.c,v 1.7 2007/05/25 16:22:11 art Exp $ */
2: /* $NetBSD: ipi.c,v 1.2 2003/03/01 13:05:37 fvdl Exp $ */
3:
4: /*-
5: * Copyright (c) 2000 The NetBSD Foundation, Inc.
6: * All rights reserved.
7: *
8: * This code is derived from software contributed to The NetBSD Foundation
9: * by RedBack Networks Inc.
10: *
11: * Author: Bill Sommerfeld
12: *
13: * Redistribution and use in source and binary forms, with or without
14: * modification, are permitted provided that the following conditions
15: * are met:
16: * 1. Redistributions of source code must retain the above copyright
17: * notice, this list of conditions and the following disclaimer.
18: * 2. Redistributions in binary form must reproduce the above copyright
19: * notice, this list of conditions and the following disclaimer in the
20: * documentation and/or other materials provided with the distribution.
21: * 3. All advertising materials mentioning features or use of this software
22: * must display the following acknowledgement:
23: * This product includes software developed by the NetBSD
24: * Foundation, Inc. and its contributors.
25: * 4. Neither the name of The NetBSD Foundation nor the names of its
26: * contributors may be used to endorse or promote products derived
27: * from this software without specific prior written permission.
28: *
29: * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
30: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
31: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
33: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39: * POSSIBILITY OF SUCH DAMAGE.
40: */
41:
42: #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
43:
44: #include <sys/param.h>
45: #include <sys/device.h>
46: #include <sys/systm.h>
47:
48: #include <machine/intr.h>
49: #include <machine/atomic.h>
50: #include <machine/cpuvar.h>
51: #include <machine/i82093var.h>
52: #include <machine/i82489reg.h>
53: #include <machine/i82489var.h>
54:
55: int
56: x86_send_ipi(struct cpu_info *ci, int ipimask)
57: {
58: int ret;
59:
60: x86_atomic_setbits_l(&ci->ci_ipis, ipimask);
61:
62: /* Don't send IPI to cpu which isn't (yet) running. */
63: if (!(ci->ci_flags & CPUF_RUNNING))
64: return ENOENT;
65:
66: ret = x86_ipi(LAPIC_IPI_VECTOR, ci->ci_apicid, LAPIC_DLMODE_FIXED);
67: if (ret != 0) {
68: printf("ipi of %x from %s to %s failed\n",
69: ipimask,
70: curcpu()->ci_dev->dv_xname,
71: ci->ci_dev->dv_xname);
72: }
73:
74: return ret;
75: }
76:
77: int
78: x86_fast_ipi(struct cpu_info *ci, int ipi)
79: {
80: if (!(ci->ci_flags & CPUF_RUNNING))
81: return (ENOENT);
82:
83: return (x86_ipi(ipi, ci->ci_apicid, LAPIC_DLMODE_FIXED));
84: }
85:
86: void
87: x86_broadcast_ipi(int ipimask)
88: {
89: struct cpu_info *ci, *self = curcpu();
90: int count = 0;
91: CPU_INFO_ITERATOR cii;
92:
93: CPU_INFO_FOREACH(cii, ci) {
94: if (ci == self)
95: continue;
96: if ((ci->ci_flags & CPUF_RUNNING) == 0)
97: continue;
98: x86_atomic_setbits_l(&ci->ci_ipis, ipimask);
99: count++;
100: }
101: if (!count)
102: return;
103:
104: x86_ipi(LAPIC_IPI_VECTOR, LAPIC_DEST_ALLEXCL, LAPIC_DLMODE_FIXED);
105: }
106:
107: void
108: x86_multicast_ipi(int cpumask, int ipimask)
109: {
110: struct cpu_info *ci;
111: CPU_INFO_ITERATOR cii;
112:
113: cpumask &= ~(1U << cpu_number());
114: if (cpumask == 0)
115: return;
116:
117: CPU_INFO_FOREACH(cii, ci) {
118: if ((cpumask & (1U << ci->ci_cpuid)) == 0)
119: continue;
120: x86_send_ipi(ci, ipimask);
121: }
122: }
123:
124: void
125: x86_ipi_handler(void)
126: {
127: extern struct evcount ipi_count;
128: struct cpu_info *ci = curcpu();
129: u_int32_t pending;
130: int bit;
131:
132: pending = x86_atomic_testset_ul(&ci->ci_ipis, 0);
133:
134: for (bit = 0; bit < X86_NIPI && pending; bit++) {
135: if (pending & (1<<bit)) {
136: pending &= ~(1<<bit);
137: (*ipifunc[bit])(ci);
138: ipi_count.ec_count++;
139: }
140: }
141: }
CVSweb