1*864f2f83Svisa /* $OpenBSD: intr.h,v 1.56 2018/08/20 15:02:07 visa Exp $ */ 2f33a460bSpefo 3f33a460bSpefo /* 4f33a460bSpefo * Copyright (c) 1997 Per Fogelstrom, Opsycon AB and RTMX Inc, USA. 5f33a460bSpefo * 6f33a460bSpefo * Redistribution and use in source and binary forms, with or without 7f33a460bSpefo * modification, are permitted provided that the following conditions 8f33a460bSpefo * are met: 9f33a460bSpefo * 1. Redistributions of source code must retain the above copyright 10f33a460bSpefo * notice, this list of conditions and the following disclaimer. 11f33a460bSpefo * 2. Redistributions in binary form must reproduce the above copyright 12f33a460bSpefo * notice, this list of conditions and the following disclaimer in the 13f33a460bSpefo * documentation and/or other materials provided with the distribution. 14f33a460bSpefo * 3. All advertising materials mentioning features or use of this software 15f33a460bSpefo * must display the following acknowledgement: 16f33a460bSpefo * This product includes software developed under OpenBSD by 17f33a460bSpefo * Per Fogelstrom, Opsycon AB, Sweden for RTMX Inc, North Carolina USA. 18f33a460bSpefo * 4. The name of the author may not be used to endorse or promote products 19f33a460bSpefo * derived from this software without specific prior written permission. 20f33a460bSpefo * 21f33a460bSpefo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 22f33a460bSpefo * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23f33a460bSpefo * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24f33a460bSpefo * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 25f33a460bSpefo * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26f33a460bSpefo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27f33a460bSpefo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28f33a460bSpefo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29f33a460bSpefo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30f33a460bSpefo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31f33a460bSpefo * SUCH DAMAGE. 32f33a460bSpefo * 33f33a460bSpefo */ 34f33a460bSpefo 3552c13d20Sdrahn #ifndef _POWERPC_INTR_H_ 3652c13d20Sdrahn #define _POWERPC_INTR_H_ 37f33a460bSpefo 38e94c3ce2Sdrahn #define IPL_NONE 0 39d7469fedSdrahn #define IPL_SOFT 1 40d7469fedSdrahn #define IPL_SOFTCLOCK 2 41d7469fedSdrahn #define IPL_SOFTNET 3 42d7469fedSdrahn #define IPL_SOFTTTY 4 43d7469fedSdrahn #define IPL_BIO 5 44d7469fedSdrahn #define IPL_NET 6 45d7469fedSdrahn #define IPL_TTY 7 46d7469fedSdrahn #define IPL_VM 8 47bb536b7dSmpi #define IPL_AUDIO 9 48bb536b7dSmpi #define IPL_CLOCK 10 49bb536b7dSmpi #define IPL_SCHED 11 50bb536b7dSmpi #define IPL_HIGH 12 51bb536b7dSmpi #define IPL_NUM 13 52f33a460bSpefo 534965d1a4Smpi #define IPL_MPFLOOR IPL_TTY 54bb536b7dSmpi #define IPL_MPSAFE 0x100 55ee8a2a3cSkettenis 56f33a460bSpefo #define IST_NONE 0 57f33a460bSpefo #define IST_PULSE 1 58f33a460bSpefo #define IST_EDGE 2 59f33a460bSpefo #define IST_LEVEL 3 60f33a460bSpefo 61a4867f13Saaron #if defined(_KERNEL) && !defined(_LOCORE) 62a4867f13Saaron 63a4867f13Saaron #include <sys/evcount.h> 643fc5ddaaSmiod #include <machine/atomic.h> 65f33a460bSpefo 66c7893909Sdrahn #define PPC_NIRQ 66 67267c6cfcSrahnds #define PPC_CLK_IRQ 64 68c7893909Sdrahn #define PPC_STAT_IRQ 65 69267c6cfcSrahnds 709b6fc7d4Sthib int splraise(int); 719b6fc7d4Sthib int spllower(int); 729b6fc7d4Sthib void splx(int); 739b6fc7d4Sthib 74d7469fedSdrahn typedef int (ppc_splraise_t) (int); 75d7469fedSdrahn typedef int (ppc_spllower_t) (int); 76d7469fedSdrahn typedef void (ppc_splx_t) (int); 77d7469fedSdrahn 78d7469fedSdrahn extern struct ppc_intr_func { 79d7469fedSdrahn ppc_splraise_t *raise; 80d7469fedSdrahn ppc_spllower_t *lower; 81d7469fedSdrahn ppc_splx_t *x; 82d7469fedSdrahn }ppc_intr_func; 83d7469fedSdrahn 84d7469fedSdrahn extern int ppc_smask[IPL_NUM]; 85d7469fedSdrahn 86d7469fedSdrahn void ppc_smask_init(void); 87d7469fedSdrahn char *ppc_intr_typename(int type); 889b6fc7d4Sthib 89c4071fd1Smillert void do_pending_int(void); 90f33a460bSpefo 9157f0881cSmiod /* SPL asserts */ 921c471f42Smpi #ifdef DIAGNOSTIC 931c471f42Smpi /* 941c471f42Smpi * Although this function is implemented in MI code, it must be in this MD 951c471f42Smpi * header because we don't want this header to include MI includes. 961c471f42Smpi */ 971c471f42Smpi void splassert_fail(int, int, const char *); 981c471f42Smpi extern int splassert_ctl; 991c471f42Smpi void splassert_check(int, const char *); 1001c471f42Smpi #define splassert(__wantipl) do { \ 1011c471f42Smpi if (splassert_ctl > 0) { \ 1021c471f42Smpi splassert_check(__wantipl, __func__); \ 1031c471f42Smpi } \ 1041c471f42Smpi } while (0) 1051c471f42Smpi #define splsoftassert(wantipl) splassert(wantipl) 1061c471f42Smpi #else 1071c471f42Smpi #define splassert(wantipl) do { /* nada */ } while (0) 1081c471f42Smpi #define splsoftassert(wantipl) do { /* nada */ } while (0) 1091c471f42Smpi #endif 11057f0881cSmiod 111d7469fedSdrahn #define set_sint(p) atomic_setbits_int(&curcpu()->ci_ipending, p) 112f33a460bSpefo 113d7469fedSdrahn #define splbio() splraise(IPL_BIO) 114d7469fedSdrahn #define splnet() splraise(IPL_NET) 115d7469fedSdrahn #define spltty() splraise(IPL_TTY) 116d7469fedSdrahn #define splaudio() splraise(IPL_AUDIO) 117d7469fedSdrahn #define splclock() splraise(IPL_CLOCK) 118d7469fedSdrahn #define splvm() splraise(IPL_VM) 119d7469fedSdrahn #define splsched() splhigh() 120d7469fedSdrahn #define splstatclock() splhigh() 121d7469fedSdrahn #define splsoftclock() splraise(IPL_SOFTCLOCK) 122d7469fedSdrahn #define splsoftnet() splraise(IPL_SOFTNET) 123d7469fedSdrahn #define splsofttty() splraise(IPL_SOFTTTY) 124b9d85be1Skettenis 125d7469fedSdrahn #define SI_TO_IRQBIT(x) (1 << (x)) 126b9d85be1Skettenis 127b9d85be1Skettenis #define SI_SOFTCLOCK 0 /* for IPL_SOFTCLOCK */ 128b9d85be1Skettenis #define SI_SOFTNET 1 /* for IPL_SOFTNET */ 129d7469fedSdrahn #define SI_SOFTTTY 2 /* for IPL_SOFTSERIAL */ 130b9d85be1Skettenis 131b9d85be1Skettenis #define SI_NQUEUES 3 132b9d85be1Skettenis 1337f349538Smpi #include <sys/mutex.h> 134b9d85be1Skettenis #include <sys/queue.h> 135b9d85be1Skettenis 136b9d85be1Skettenis struct soft_intrhand { 137b9d85be1Skettenis TAILQ_ENTRY(soft_intrhand) sih_list; 138b9d85be1Skettenis void (*sih_func)(void *); 139b9d85be1Skettenis void *sih_arg; 140b9d85be1Skettenis struct soft_intrq *sih_siq; 141b9d85be1Skettenis int sih_pending; 142b9d85be1Skettenis }; 143b9d85be1Skettenis 144b9d85be1Skettenis struct soft_intrq { 145b9d85be1Skettenis TAILQ_HEAD(, soft_intrhand) siq_list; 146b9d85be1Skettenis int siq_si; 147b9d85be1Skettenis struct mutex siq_mtx; 148b9d85be1Skettenis }; 149b9d85be1Skettenis 150b9d85be1Skettenis void softintr_disestablish(void *); 151b9d85be1Skettenis void softintr_dispatch(int); 152b9d85be1Skettenis void *softintr_establish(int, void (*)(void *), void *); 153b9d85be1Skettenis void softintr_init(void); 154d7469fedSdrahn 155b9d85be1Skettenis void softintr_schedule(void *); 1561c471f42Smpi void dosoftint(int); 157b9d85be1Skettenis 158d7469fedSdrahn #define splhigh() splraise(IPL_HIGH) 159d7469fedSdrahn #define spl0() spllower(IPL_NONE) 160f33a460bSpefo 1619cf068caSrahnds /* 1629cf068caSrahnds * Interrupt control struct used to control the ICU setup. 1639cf068caSrahnds */ 1649cf068caSrahnds 1659cf068caSrahnds struct intrhand { 166d7469fedSdrahn TAILQ_ENTRY(intrhand) ih_list; 167c4071fd1Smillert int (*ih_fun)(void *); 1689cf068caSrahnds void *ih_arg; 169a4867f13Saaron struct evcount ih_count; 1704c904650Skettenis int ih_type; 1719cf068caSrahnds int ih_level; 172bb536b7dSmpi int ih_flags; 1739cf068caSrahnds int ih_irq; 174c03b1b92Smk const char *ih_what; 1759cf068caSrahnds }; 176d7469fedSdrahn 177d7469fedSdrahn struct intrq { 178d7469fedSdrahn TAILQ_HEAD(, intrhand) iq_list; /* handler list */ 179d7469fedSdrahn int iq_ipl; /* IPL_ to mask while handling */ 180d7469fedSdrahn int iq_ist; /* share type */ 181d7469fedSdrahn }; 182d7469fedSdrahn 183a674e76bSrahnds extern int ppc_configed_intr_cnt; 184a674e76bSrahnds #define MAX_PRECONF_INTR 16 185a674e76bSrahnds extern struct intrhand ppc_configed_intr[MAX_PRECONF_INTR]; 1869cf068caSrahnds 18711078ddaSkettenis void intr_barrier(void *); 18811078ddaSkettenis 189d90fe081Sdrahn #define PPC_IPI_NOP 0 190d90fe081Sdrahn #define PPC_IPI_DDB 1 191d90fe081Sdrahn 192d90fe081Sdrahn void ppc_send_ipi(struct cpu_info *, int); 193d90fe081Sdrahn 194f33a460bSpefo #endif /* _LOCORE */ 19552c13d20Sdrahn #endif /* _POWERPC_INTR_H_ */ 196