xref: /netbsd-src/sys/arch/powerpc/include/booke/intr.h (revision b3cb75b9857866ca6f677449263917abd782f093)
1*b3cb75b9Srin /*	$NetBSD: intr.h,v 1.13 2022/09/12 08:14:55 rin Exp $	*/
2ea2a1a36Smatt /*-
3b8ea2c8cSmatt  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
4ea2a1a36Smatt  * All rights reserved.
5ea2a1a36Smatt  *
6ea2a1a36Smatt  * This code is derived from software contributed to The NetBSD Foundation
7b8ea2c8cSmatt  * by Raytheon BBN Technologies Corp and Defense Advanced Research Projects
8b8ea2c8cSmatt  * Agency and which was developed by Matt Thomas of 3am Software Foundry.
9b8ea2c8cSmatt  *
10b8ea2c8cSmatt  * This material is based upon work supported by the Defense Advanced Research
11b8ea2c8cSmatt  * Projects Agency and Space and Naval Warfare Systems Center, Pacific, under
12b8ea2c8cSmatt  * Contract No. N66001-09-C-2073.
13b8ea2c8cSmatt  * Approved for Public Release, Distribution Unlimited
14ea2a1a36Smatt  *
15ea2a1a36Smatt  * Redistribution and use in source and binary forms, with or without
16ea2a1a36Smatt  * modification, are permitted provided that the following conditions
17ea2a1a36Smatt  * are met:
18ea2a1a36Smatt  * 1. Redistributions of source code must retain the above copyright
19ea2a1a36Smatt  *    notice, this list of conditions and the following disclaimer.
20ea2a1a36Smatt  * 2. Redistributions in binary form must reproduce the above copyright
21ea2a1a36Smatt  *    notice, this list of conditions and the following disclaimer in the
22ea2a1a36Smatt  *    documentation and/or other materials provided with the distribution.
23ea2a1a36Smatt  *
24ea2a1a36Smatt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
25ea2a1a36Smatt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26ea2a1a36Smatt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27ea2a1a36Smatt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
28ea2a1a36Smatt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29ea2a1a36Smatt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30ea2a1a36Smatt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31ea2a1a36Smatt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32ea2a1a36Smatt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33ea2a1a36Smatt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34ea2a1a36Smatt  * POSSIBILITY OF SUCH DAMAGE.
35ea2a1a36Smatt  */
36ea2a1a36Smatt 
37ea2a1a36Smatt #ifndef _BOOKE_INTR_H_
38ea2a1a36Smatt #define _BOOKE_INTR_H_
39ea2a1a36Smatt 
40ea2a1a36Smatt /* Interrupt priority `levels'. */
41ea2a1a36Smatt #define	IPL_NONE	0	/* nothing */
42ea2a1a36Smatt #define	IPL_SOFTCLOCK	1	/* software clock interrupt */
43ea2a1a36Smatt #define	IPL_SOFTBIO	2	/* software block i/o interrupt */
44ea2a1a36Smatt #define	IPL_SOFTNET	3	/* software network interrupt */
45ea2a1a36Smatt #define	IPL_SOFTSERIAL	4	/* software serial interrupt */
46ea2a1a36Smatt #define	IPL_VM		5	/* memory allocation */
47ea2a1a36Smatt #define	IPL_SCHED	6	/* clock */
48ea2a1a36Smatt #define	IPL_HIGH	7	/* everything */
49ea2a1a36Smatt #define	NIPL		8
50ea2a1a36Smatt 
51ea2a1a36Smatt /* Interrupt sharing types. */
52b8ea2c8cSmatt #define	IST_NONE	(NIPL+0) /* none */
53b8ea2c8cSmatt #define	IST_EDGE	(NIPL+1) /* edge-triggered */
54b8ea2c8cSmatt #define	IST_LEVEL	(NIPL+2) /* level-triggered active-low */
55ea2a1a36Smatt #define	IST_LEVEL_LOW	IST_LEVEL
56b8ea2c8cSmatt #define	IST_LEVEL_HIGH	(NIPL+3) /* level-triggered active-high */
573fbf2742Smatt #define	IST_PULSE	(NIPL+4) /* pulsed */
583fbf2742Smatt #define	IST_MSI		(NIPL+5) /* message signaling interrupt (PCI) */
593fbf2742Smatt #define	IST_ONCHIP	(NIPL+6) /* on-chip device */
60ea2a1a36Smatt #ifdef __INTR_PRIVATE
613fbf2742Smatt #define	IST_MSIGROUP	(NIPL+7) /* openpic msi groups */
623fbf2742Smatt #define	IST_TIMER	(NIPL+8) /* openpic timers */
633fbf2742Smatt #define	IST_IPI		(NIPL+9) /* openpic ipi */
643fbf2742Smatt #define	IST_MI		(NIPL+10) /* openpic message */
653fbf2742Smatt #define	IST_MAX		(NIPL+11)
66ea2a1a36Smatt #endif
67ea2a1a36Smatt 
6801fd9255Smatt #define	IPI_DST_ALL	((cpuid_t)-2)
6901fd9255Smatt #define	IPI_DST_NOTME	((cpuid_t)-1)
7001fd9255Smatt 
7101fd9255Smatt #define IPI_NOMESG	0x0000
7201fd9255Smatt #define IPI_HALT	0x0001
7301fd9255Smatt #define IPI_XCALL	0x0002
7401fd9255Smatt #define	IPI_KPREEMPT	0x0004
7501fd9255Smatt #define IPI_TLB1SYNC	0x0008
768011b285Srmind #define IPI_GENERIC	0x0010
77ef2e796fSnonaka #define IPI_SUSPEND	0x0020
78115c1bc0Sad #define IPI_AST		0x0040
79b3b635b9Smatt 
80*b3cb75b9Srin #if 0	/* PR port-powerpc/56922: fast softints are broken on powerpc */
81b8ea2c8cSmatt #define	__HAVE_FAST_SOFTINTS	1
82*b3cb75b9Srin #endif
8301fd9255Smatt #define	SOFTINT_KPREEMPT	SOFTINT_COUNT
84b8ea2c8cSmatt 
85ea2a1a36Smatt #ifndef _LOCORE
86ea2a1a36Smatt 
87f399d1bdSmatt struct cpu_info;
88f399d1bdSmatt 
89ea2a1a36Smatt void 	*intr_establish(int, int, int, int (*)(void *), void *);
90e4a54b41Snonaka void 	*intr_establish_xname(int, int, int, int (*)(void *), void *,
91e4a54b41Snonaka 	    const char *);
92ea2a1a36Smatt void 	intr_disestablish(void *);
9301fd9255Smatt void	intr_cpu_attach(struct cpu_info *);
9401fd9255Smatt void	intr_cpu_hatch(struct cpu_info *);
95b8ea2c8cSmatt void	intr_init(void);
96b8ea2c8cSmatt const char *
97e58a356cSchristos 	intr_string(int, int, char *, size_t);
983fbf2742Smatt const char *
993fbf2742Smatt 	intr_typename(int);
100b8ea2c8cSmatt 
10101fd9255Smatt void	cpu_send_ipi(cpuid_t, uint32_t);
102b3b635b9Smatt 
103b8ea2c8cSmatt void	spl0(void);
104ea2a1a36Smatt int 	splraise(int);
105ea2a1a36Smatt void 	splx(int);
106b8ea2c8cSmatt #ifdef __INTR_NOINLINE
107b8ea2c8cSmatt int	splhigh(void);
108b8ea2c8cSmatt int	splsched(void);
109b8ea2c8cSmatt int	splvm(void);
110b8ea2c8cSmatt int	splsoftserial(void);
111b8ea2c8cSmatt int	splsoftnet(void);
112b8ea2c8cSmatt int	splsoftbio(void);
113b8ea2c8cSmatt int	splsoftclock(void);
114b8ea2c8cSmatt #endif
115ea2a1a36Smatt 
116ea2a1a36Smatt typedef int ipl_t;
117ea2a1a36Smatt typedef struct {
118ea2a1a36Smatt 	ipl_t _ipl;
119ea2a1a36Smatt } ipl_cookie_t;
120ea2a1a36Smatt 
121ea2a1a36Smatt #ifdef __INTR_PRIVATE
122ea2a1a36Smatt 
123f399d1bdSmatt struct trapframe;
124f399d1bdSmatt 
125ea2a1a36Smatt struct intrsw {
126e4a54b41Snonaka 	void *(*intrsw_establish)(int, int, int, int (*)(void *), void *,
127e4a54b41Snonaka 	    const char *);
128ea2a1a36Smatt 	void (*intrsw_disestablish)(void *);
12901fd9255Smatt 	void (*intrsw_cpu_attach)(struct cpu_info *);
13001fd9255Smatt 	void (*intrsw_cpu_hatch)(struct cpu_info *);
13101fd9255Smatt 	void (*intrsw_cpu_send_ipi)(cpuid_t, uint32_t);
132ea2a1a36Smatt 	void (*intrsw_init)(void);
133ea2a1a36Smatt 	void (*intrsw_critintr)(struct trapframe *);
134ea2a1a36Smatt 	void (*intrsw_decrintr)(struct trapframe *);
135ea2a1a36Smatt 	void (*intrsw_extintr)(struct trapframe *);
136ea2a1a36Smatt 	void (*intrsw_fitintr)(struct trapframe *);
137ea2a1a36Smatt 	void (*intrsw_wdogintr)(struct trapframe *);
138ea2a1a36Smatt 	int (*intrsw_splraise)(int);
139b8ea2c8cSmatt 	void (*intrsw_spl0)(void);
140ea2a1a36Smatt 	void (*intrsw_splx)(int);
141e58a356cSchristos 	const char *(*intrsw_string)(int, int, char *, size_t);
1423fbf2742Smatt 	const char *(*intrsw_typename)(int);
143ea2a1a36Smatt #ifdef __HAVE_FAST_SOFTINTS
144b8ea2c8cSmatt 	void (*intrsw_softint_init_md)(struct lwp *, u_int, uintptr_t *);
145ea2a1a36Smatt 	void (*intrsw_softint_trigger)(uintptr_t);
146ea2a1a36Smatt #endif
147ea2a1a36Smatt };
148ea2a1a36Smatt 
149b8ea2c8cSmatt extern const struct intrsw *powerpc_intrsw;
150b8ea2c8cSmatt void	softint_fast_dispatch(struct lwp *, int);
151ea2a1a36Smatt #endif /* __INTR_PRIVATE */
152ea2a1a36Smatt 
153b8ea2c8cSmatt #ifndef __INTR_NOINLINE
15487fd18f8Schristos static __inline int
splhigh(void)155ea2a1a36Smatt splhigh(void)
156ea2a1a36Smatt {
157ea2a1a36Smatt 
158ea2a1a36Smatt 	return splraise(IPL_HIGH);
159ea2a1a36Smatt }
160ea2a1a36Smatt 
16187fd18f8Schristos static __inline int
splsched(void)162ea2a1a36Smatt splsched(void)
163ea2a1a36Smatt {
164ea2a1a36Smatt 
165ea2a1a36Smatt 	return splraise(IPL_SCHED);
166ea2a1a36Smatt }
167ea2a1a36Smatt 
16887fd18f8Schristos static __inline int
splvm(void)169ea2a1a36Smatt splvm(void)
170ea2a1a36Smatt {
171ea2a1a36Smatt 
172ea2a1a36Smatt 	return splraise(IPL_VM);
173ea2a1a36Smatt }
174ea2a1a36Smatt 
17587fd18f8Schristos static __inline int
splsoftserial(void)176ea2a1a36Smatt splsoftserial(void)
177ea2a1a36Smatt {
178ea2a1a36Smatt 
179ea2a1a36Smatt 	return splraise(IPL_SOFTSERIAL);
180ea2a1a36Smatt }
181ea2a1a36Smatt 
18287fd18f8Schristos static __inline int
splsoftnet(void)183ea2a1a36Smatt splsoftnet(void)
184ea2a1a36Smatt {
185ea2a1a36Smatt 
186ea2a1a36Smatt 	return splraise(IPL_SOFTNET);
187ea2a1a36Smatt }
188ea2a1a36Smatt 
18987fd18f8Schristos static __inline int
splsoftbio(void)190ea2a1a36Smatt splsoftbio(void)
191ea2a1a36Smatt {
192ea2a1a36Smatt 
193ea2a1a36Smatt 	return splraise(IPL_SOFTBIO);
194ea2a1a36Smatt }
195ea2a1a36Smatt 
19687fd18f8Schristos static __inline int
splsoftclock(void)197ea2a1a36Smatt splsoftclock(void)
198ea2a1a36Smatt {
199ea2a1a36Smatt 
200ea2a1a36Smatt 	return splraise(IPL_SOFTCLOCK);
201ea2a1a36Smatt }
202ea2a1a36Smatt 
20387fd18f8Schristos static __inline int
splraiseipl(ipl_cookie_t icookie)204ea2a1a36Smatt splraiseipl(ipl_cookie_t icookie)
205ea2a1a36Smatt {
206ea2a1a36Smatt 
207ea2a1a36Smatt 	return splraise(icookie._ipl);
208ea2a1a36Smatt }
209ea2a1a36Smatt 
21087fd18f8Schristos static __inline ipl_cookie_t
makeiplcookie(ipl_t ipl)211ea2a1a36Smatt makeiplcookie(ipl_t ipl)
212ea2a1a36Smatt {
213ea2a1a36Smatt 
214ea2a1a36Smatt 	return (ipl_cookie_t){._ipl = ipl};
215ea2a1a36Smatt }
216b8ea2c8cSmatt #endif /* !__INTR_NOINLINE */
217ea2a1a36Smatt 
218ea2a1a36Smatt #endif /* !_LOCORE */
219ea2a1a36Smatt #endif /* !_BOOKE_INTR_H_ */
220