xref: /netbsd-src/sys/arch/powerpc/include/intr.h (revision 1e94ed3446718d1d096c5d0046640d6eb9185dd7)
1*1e94ed34Smartin /*	$NetBSD: intr.h,v 1.19 2022/07/11 09:39:10 martin Exp $ */
2d974db0aSgarbled 
3d974db0aSgarbled /*-
4d974db0aSgarbled  * Copyright (c) 2007 Michael Lorenz
5d974db0aSgarbled  * All rights reserved.
6d974db0aSgarbled  *
7d974db0aSgarbled  * Redistribution and use in source and binary forms, with or without
8d974db0aSgarbled  * modification, are permitted provided that the following conditions
9d974db0aSgarbled  * are met:
10d974db0aSgarbled  * 1. Redistributions of source code must retain the above copyright
11d974db0aSgarbled  *    notice, this list of conditions and the following disclaimer.
12d974db0aSgarbled  * 2. Redistributions in binary form must reproduce the above copyright
13d974db0aSgarbled  *    notice, this list of conditions and the following disclaimer in the
14d974db0aSgarbled  *    documentation and/or other materials provided with the distribution.
15d974db0aSgarbled  *
16d974db0aSgarbled  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17d974db0aSgarbled  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18d974db0aSgarbled  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19d974db0aSgarbled  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20d974db0aSgarbled  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21d974db0aSgarbled  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22d974db0aSgarbled  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23d974db0aSgarbled  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24d974db0aSgarbled  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25d974db0aSgarbled  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26d974db0aSgarbled  * POSSIBILITY OF SUCH DAMAGE.
27d974db0aSgarbled  */
28d974db0aSgarbled 
2972d26a2dSrin #ifndef _LOCORE
3072d26a2dSrin #include <sys/cdefs.h>
31*1e94ed34Smartin __KERNEL_RCSID(0, "$NetBSD: intr.h,v 1.19 2022/07/11 09:39:10 martin Exp $");
3272d26a2dSrin #endif
3372d26a2dSrin 
34ba182b7aSmatt #ifndef _POWERPC_INTR_MACHDEP_H_
35ba182b7aSmatt #define _POWERPC_INTR_MACHDEP_H_
36d974db0aSgarbled 
37*1e94ed34Smartin #if 0	/* PR port-powerpc/56922: fast softints are broken on powerpc */
38b5ffed75Smacallan #define	__HAVE_FAST_SOFTINTS	1
39*1e94ed34Smartin #endif
40b5ffed75Smacallan 
41d974db0aSgarbled 
42d974db0aSgarbled /* Interrupt priority `levels'. */
43d974db0aSgarbled #define	IPL_NONE		0	/* nothing */
44d974db0aSgarbled #define	IPL_SOFTCLOCK		1	/* timeouts */
454b293a84Sad #define	IPL_SOFTBIO		2	/* block I/O */
464b293a84Sad #define	IPL_SOFTNET		3	/* protocol stacks */
474b293a84Sad #define	IPL_SOFTSERIAL		4	/* serial */
484b293a84Sad #define	IPL_VM			5	/* memory allocation */
494b293a84Sad #define	IPL_SCHED		6
504b293a84Sad #define	IPL_HIGH		7	/* everything */
514b293a84Sad #define	NIPL			8
52d974db0aSgarbled 
53d974db0aSgarbled /* Interrupt sharing types. */
54d974db0aSgarbled #define	IST_NONE		0	/* none */
55d974db0aSgarbled #define	IST_PULSE		1	/* pulsed */
56ab57155fSphx #define	IST_EDGE		2	/* falling edge triggered */
57ab57155fSphx #define	IST_LEVEL		3	/* low level triggered */
58ab57155fSphx 
59ab57155fSphx #define IST_EDGE_FALLING	IST_EDGE
60ab57155fSphx #define IST_EDGE_RISING		4	/* rising edge triggered */
61ab57155fSphx #define IST_LEVEL_LOW		IST_LEVEL
62ab57155fSphx #define IST_LEVEL_HIGH		5	/* high level triggered */
63d974db0aSgarbled 
64fc311b77Smatt #if !defined(_LOCORE)
65fc311b77Smatt void *	intr_establish(int, int, int, int (*)(void *), void *);
66e4a54b41Snonaka void *	intr_establish_xname(int, int, int, int (*)(void *), void *,
67e4a54b41Snonaka 	    const char *);
68fc311b77Smatt void	intr_disestablish(void *);
69fc311b77Smatt const char *
70fc311b77Smatt 	intr_typename(int);
71fc311b77Smatt 
72fc311b77Smatt int	splraise(int);
73fc311b77Smatt int	spllower(int);
74fc311b77Smatt void	splx(int);
75fc311b77Smatt 
76fc311b77Smatt #if !defined(_MODULE)
77fc311b77Smatt 
78ba182b7aSmatt #include <powerpc/softint.h>
79ba182b7aSmatt 
80fc311b77Smatt void	genppc_cpu_configure(void);
81fc311b77Smatt 
82d974db0aSgarbled /*
83d974db0aSgarbled  * Interrupt handler chains.  intr_establish() inserts a handler into
84d974db0aSgarbled  * the list.  The handler is called with its (single) argument.
85d974db0aSgarbled  */
86d974db0aSgarbled struct intrhand {
87d974db0aSgarbled 	int	(*ih_fun)(void *);
88d974db0aSgarbled 	void	*ih_arg;
89d974db0aSgarbled 	struct	intrhand *ih_next;
9006d8da7dSmatt 	int	ih_ipl;
91e2a71f6cSmatt 	int	ih_virq;
92e4a54b41Snonaka 	char	ih_xname[INTRDEVNAMEBUF];
93d974db0aSgarbled };
94d974db0aSgarbled 
95b5ffed75Smacallan void softint_fast_dispatch(struct lwp *, int);
96b5ffed75Smacallan 
97f45ae8fdSrin #ifdef __HAVE_FAST_SOFTINTS
98b5ffed75Smacallan #define softint_init_md		powerpc_softint_init_md
99b5ffed75Smacallan #define softint_trigger		powerpc_softint_trigger
100f45ae8fdSrin #endif
101d974db0aSgarbled 
102e2a71f6cSmatt #ifdef __IMASK_T
103e2a71f6cSmatt typedef __IMASK_T imask_t;
104e2a71f6cSmatt #else
105e2a71f6cSmatt typedef uint32_t imask_t;
106e2a71f6cSmatt #endif
107e2a71f6cSmatt 
108e2a71f6cSmatt #define NVIRQ		(sizeof(imask_t)*8)	/* 32 virtual IRQs */
109e2a71f6cSmatt #ifndef NIRQ
110a192f6aaSmacallan #define NIRQ		256	/* up to 256 HW IRQs */
111e2a71f6cSmatt #endif
1124a9e14b9Skiyohara 
113e2a71f6cSmatt #define HWIRQ_MAX       (NVIRQ - 1)
114e2a71f6cSmatt #define HWIRQ_MASK     	(~(imask_t)0 >> 1)
1154a9e14b9Skiyohara 
116e2a71f6cSmatt #define	PIC_VIRQ_TO_MASK(v)	__BIT(HWIRQ_MAX - (v))
117e2a71f6cSmatt #define PIC_VIRQ_MS_PENDING(p)	__builtin_clz(p)
118d974db0aSgarbled 
119fc311b77Smatt #endif /* !_MODULE */
120fc311b77Smatt 
121d974db0aSgarbled #define spl0()		spllower(0)
122d974db0aSgarbled 
123d974db0aSgarbled typedef int ipl_t;
124d974db0aSgarbled typedef struct {
125d974db0aSgarbled 	ipl_t _ipl;
126d974db0aSgarbled } ipl_cookie_t;
127d974db0aSgarbled 
12887fd18f8Schristos static __inline ipl_cookie_t
makeiplcookie(ipl_t ipl)129d974db0aSgarbled makeiplcookie(ipl_t ipl)
130d974db0aSgarbled {
131d974db0aSgarbled 
132d974db0aSgarbled 	return (ipl_cookie_t){._ipl = ipl};
133d974db0aSgarbled }
134d974db0aSgarbled 
13587fd18f8Schristos static __inline int
splraiseipl(ipl_cookie_t icookie)136d974db0aSgarbled splraiseipl(ipl_cookie_t icookie)
137d974db0aSgarbled {
138d974db0aSgarbled 
139b5ffed75Smacallan 	return splraise(icookie._ipl);
140d974db0aSgarbled }
141d974db0aSgarbled 
142d974db0aSgarbled #include <sys/spl.h>
143d974db0aSgarbled 
144d974db0aSgarbled #endif /* _LOCORE */
145d974db0aSgarbled 
146ba182b7aSmatt #endif /* _POWERPC_INTR_MACHDEP_H_ */
147