xref: /netbsd-src/sys/sys/ipi.h (revision da697e67bacb0eb6e6e69c645fd2bdbca4cbdac0)
1 /*	$NetBSD: ipi.h,v 1.5 2020/09/08 16:00:35 riastradh Exp $	*/
2 
3 /*-
4  * Copyright (c) 2014 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Mindaugas Rasiukevicius.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _SYS_IPI_H_
33 #define _SYS_IPI_H_
34 
35 #if !defined(_KERNEL) && !defined(_KMEMUSER)
36 #error "not supposed to be exposed to userland"
37 #endif
38 
39 typedef void (*ipi_func_t)(void *);
40 
41 typedef struct {
42 	/* Public: function handler and an argument. */
43 	ipi_func_t	func;
44 	void *		arg;
45 
46 	/* Private (internal) elements. */
47 	volatile u_int	_pending;
48 } ipi_msg_t;
49 
50 /*
51  * Internal constants and implementation hooks.
52  *
53  * IPI_MAXREG: the maximum number of asynchronous handlers which can
54  * be registered on the system (normally, this should not be high).
55  */
56 #define	IPI_MAXREG	32
57 
58 #define	IPI_BITW_SHIFT	5
59 #define	IPI_BITW_MASK	(32 - 1)
60 #define	IPI_BITWORDS	(IPI_MAXREG >> IPI_BITW_SHIFT)
61 
62 void	ipi_sysinit(void);
63 void	ipi_percpu_init(void);
64 void	ipi_cpu_handler(void);
65 void	cpu_ipi(struct cpu_info *);
66 
67 /* Public interface: asynchronous IPIs. */
68 u_int	ipi_register(ipi_func_t, void *);
69 void	ipi_unregister(u_int);
70 void	ipi_trigger(u_int, struct cpu_info *);
71 void	ipi_trigger_multi(u_int, const kcpuset_t *);
72 void	ipi_trigger_broadcast(u_int, bool);
73 
74 /* Public interface: synchronous IPIs. */
75 void	ipi_unicast(ipi_msg_t *, struct cpu_info *);
76 void	ipi_multicast(ipi_msg_t *, const kcpuset_t *);
77 void	ipi_broadcast(ipi_msg_t *, bool);
78 void	ipi_wait(ipi_msg_t *);
79 
80 #endif
81