| 1 | /*	$OpenBSD: intr.h,v 1.58 2026/01/04 23:51:12 jsg Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | * Copyright (c) 1997 Per Fogelstrom, Opsycon AB and RTMX Inc, USA. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
| 14 | * 3. All advertising materials mentioning features or use of this software |
| 15 | * must display the following acknowledgement: |
| 16 | *	This product includes software developed under OpenBSD by |
| 17 | *	Per Fogelstrom, Opsycon AB, Sweden for RTMX Inc, North Carolina USA. |
| 18 | * 4. The name of the author may not be used to endorse or promote products |
| 19 | * derived from this software without specific prior written permission. |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 22 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 25 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 31 | * SUCH DAMAGE. |
| 32 | * |
| 33 | */ |
| 34 | |
| 35 | #ifndef _POWERPC_INTR_H_ |
| 36 | #define _POWERPC_INTR_H_ |
| 37 | |
| 38 | #define	IPL_NONE	0 |
| 39 | #define	IPL_SOFTCLOCK	2 |
| 40 | #define	IPL_SOFTNET	3 |
| 41 | #define	IPL_SOFTTTY	4 |
| 42 | #define	IPL_BIO		5 |
| 43 | #define	IPL_NET		6 |
| 44 | #define	IPL_TTY		7 |
| 45 | #define	IPL_VM		8 |
| 46 | #define	IPL_AUDIO	9 |
| 47 | #define	IPL_CLOCK	10 |
| 48 | #define	IPL_SCHED	11 |
| 49 | #define	IPL_HIGH	12 |
| 50 | #define	IPL_NUM		13 |
| 51 | |
| 52 | #define	IPL_MPFLOOR	IPL_TTY |
| 53 | #define	IPL_MPSAFE	0x100 |
| 54 | |
| 55 | #define	IST_NONE	0 |
| 56 | #define	IST_PULSE	1 |
| 57 | #define	IST_EDGE	2 |
| 58 | #define	IST_LEVEL	3 |
| 59 | |
| 60 | #define __USE_MI_SOFTINTR |
| 61 | |
| 62 | #include <sys/softintr.h> |
| 63 | |
| 64 | #if defined(_KERNEL) && !defined(_LOCORE) |
| 65 | |
| 66 | #include <sys/evcount.h> |
| 67 | |
| 68 | #define	PPC_NIRQ	66 |
| 69 | #define	PPC_CLK_IRQ	64 |
| 70 | #define	PPC_STAT_IRQ	65 |
| 71 | |
| 72 | int	splraise(int); |
| 73 | int	spllower(int); |
| 74 | void	splx(int); |
| 75 | |
| 76 | typedef int (ppc_splraise_t) (int); |
| 77 | typedef int (ppc_spllower_t) (int); |
| 78 | typedef void (ppc_splx_t) (int); |
| 79 | |
| 80 | extern struct ppc_intr_func { |
| 81 | 	ppc_splraise_t *raise; |
| 82 | 	ppc_spllower_t *lower; |
| 83 | 	ppc_splx_t *x; |
| 84 | }ppc_intr_func; |
| 85 | |
| 86 | extern int ppc_smask[IPL_NUM]; |
| 87 | |
| 88 | void ppc_smask_init(void); |
| 89 | char *ppc_intr_typename(int type); |
| 90 | |
| 91 | void do_pending_int(void); |
| 92 | |
| 93 | /* SPL asserts */ |
| 94 | #ifdef DIAGNOSTIC |
| 95 | /* |
| 96 | * Although this function is implemented in MI code, it must be in this MD |
| 97 | * header because we don't want this header to include MI includes. |
| 98 | */ |
| 99 | void splassert_fail(int, int, const char *); |
| 100 | extern int splassert_ctl; |
| 101 | void splassert_check(int, const char *); |
| 102 | #define splassert(__wantipl) do {			\ |
| 103 | 	if (splassert_ctl > 0) {			\ |
| 104 | 		splassert_check(__wantipl, __func__);	\ |
| 105 | 	}						\ |
| 106 | } while (0) |
| 107 | #define splsoftassert(wantipl) splassert(wantipl) |
| 108 | #else |
| 109 | #define splassert(wantipl)	do { /* nada */ } while (0) |
| 110 | #define splsoftassert(wantipl)	do { /* nada */ } while (0) |
| 111 | #endif |
| 112 | |
| 113 | #define	splbio()	splraise(IPL_BIO) |
| 114 | #define	splnet()	splraise(IPL_NET) |
| 115 | #define	spltty()	splraise(IPL_TTY) |
| 116 | #define	splaudio()	splraise(IPL_AUDIO) |
| 117 | #define	splclock()	splraise(IPL_CLOCK) |
| 118 | #define	splvm()		splraise(IPL_VM) |
| 119 | #define	splsched()	splhigh() |
| 120 | #define	splstatclock()	splhigh() |
| 121 | #define	splsoftclock()	splraise(IPL_SOFTCLOCK) |
| 122 | #define	splsoftnet()	splraise(IPL_SOFTNET) |
| 123 | #define	splsofttty()	splraise(IPL_SOFTTTY) |
| 124 | |
| 125 | #define	SI_TO_IRQBIT(x) (1 << (x)) |
| 126 | |
| 127 | void	softintr(int); |
| 128 | void	dosoftint(int); |
| 129 | |
| 130 | #define	splhigh()	splraise(IPL_HIGH) |
| 131 | #define	spl0()		spllower(IPL_NONE) |
| 132 | |
| 133 | /* |
| 134 | *	Interrupt control struct used to control the ICU setup. |
| 135 | */ |
| 136 | |
| 137 | struct intrhand { |
| 138 | 	TAILQ_ENTRY(intrhand) ih_list; |
| 139 | 	int		(*ih_fun)(void *); |
| 140 | 	void		*ih_arg; |
| 141 | 	struct evcount	ih_count; |
| 142 | 	int		ih_type; |
| 143 | 	int		ih_level; |
| 144 | 	int		ih_flags; |
| 145 | 	int		ih_irq; |
| 146 | 	const char	*ih_what; |
| 147 | }; |
| 148 | |
| 149 | struct intrq { |
| 150 | 	TAILQ_HEAD(, intrhand) iq_list; /* handler list */ |
| 151 | 	int iq_ipl;			/* IPL_ to mask while handling */ |
| 152 | 	int iq_ist;			/* share type */ |
| 153 | }; |
| 154 | |
| 155 | extern int ppc_configed_intr_cnt; |
| 156 | #define	MAX_PRECONF_INTR 16 |
| 157 | extern struct intrhand ppc_configed_intr[MAX_PRECONF_INTR]; |
| 158 | |
| 159 | void intr_barrier(void *); |
| 160 | |
| 161 | #define PPC_IPI_NOP		0 |
| 162 | #define PPC_IPI_DDB		1 |
| 163 | |
| 164 | void ppc_send_ipi(struct cpu_info *, int); |
| 165 | |
| 166 | #endif /* _LOCORE */ |
| 167 | #endif /* _POWERPC_INTR_H_ */ |