1 /* $OpenBSD: intr.h,v 1.11 2009/03/15 20:39:53 miod Exp $ */ 2 /* 3 * Copyright (c) 2001 Wasabi Systems, Inc. 4 * All rights reserved. 5 * 6 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed for the NetBSD Project by 19 * Wasabi Systems, Inc. 20 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 21 * or promote products derived from this software without specific prior 22 * written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 28 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 * POSSIBILITY OF SUCH DAMAGE. 35 */ 36 /* 37 * Copyright (C) 2000 Steve Murphree, Jr. 38 * All rights reserved. 39 * 40 * Redistribution and use in source and binary forms, with or without 41 * modification, are permitted provided that the following conditions 42 * are met: 43 * 1. Redistributions of source code must retain the above copyright 44 * notice, this list of conditions and the following disclaimer. 45 * 2. Redistributions in binary form must reproduce the above copyright 46 * notice, this list of conditions and the following disclaimer in the 47 * documentation and/or other materials provided with the distribution. 48 * 3. The name of the author may not be used to endorse or promote products 49 * derived from this software without specific prior written permission. 50 * 51 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 52 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 53 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 54 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 55 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 56 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 60 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 61 */ 62 63 #ifndef _M88K_INTR_H_ 64 #define _M88K_INTR_H_ 65 66 #ifdef _KERNEL 67 #ifndef _LOCORE 68 int getipl(void); 69 int setipl(int level); 70 int raiseipl(int level); 71 int spl0(void); 72 73 /* SPL asserts */ 74 #ifdef DIAGNOSTIC 75 /* 76 * Although this function is implemented in MI code, it must be in this MD 77 * header because we don't want this header to include MI includes. 78 */ 79 void splassert_fail(int, int, const char *); 80 extern int splassert_ctl; 81 void splassert_check(int, const char *); 82 #define splassert(__wantipl) do { \ 83 if (splassert_ctl > 0) { \ 84 splassert_check(__wantipl, __func__); \ 85 } \ 86 } while (0) 87 #define splsoftassert(wantipl) splassert(IPL_SOFTINT) 88 #else 89 #define splassert(wantipl) do { /* nothing */ } while (0) 90 #define splsoftassert(wantipl) do { /* nothing */ } while (0) 91 #endif 92 93 #endif /* _LOCORE */ 94 95 #define splsoftclock() raiseipl(IPL_SOFTINT) 96 #define splsoftnet() raiseipl(IPL_SOFTINT) 97 #define splbio() raiseipl(IPL_BIO) 98 #define splnet() raiseipl(IPL_NET) 99 #define spltty() raiseipl(IPL_TTY) 100 #define splclock() raiseipl(IPL_CLOCK) 101 #define splstatclock() raiseipl(IPL_STATCLOCK) 102 #define splsched() raiseipl(IPL_SCHED) 103 #define splvm() raiseipl(IPL_VM) 104 #define splhigh() setipl(IPL_HIGH) 105 106 #define spllock() splhigh() 107 108 #define splx(x) ((x) ? setipl((x)) : spl0()) 109 110 /* 111 * Generic software interrupt support for all m88k platforms. 112 */ 113 114 #ifndef _LOCORE 115 116 #define IPL_SOFT 0 117 #define IPL_SOFTCLOCK 1 118 #define IPL_SOFTNET 2 119 #define IPL_SOFTTTY 3 120 121 #define SI_SOFT 0 /* for IPL_SOFT */ 122 #define SI_SOFTCLOCK 1 /* for IPL_SOFTCLOCK */ 123 #define SI_SOFTNET 2 /* for IPL_SOFTNET */ 124 #define SI_SOFTTTY 3 /* for IPL_SOFTTTY */ 125 126 #define SI_NQUEUES 4 127 128 #include <machine/mutex.h> 129 #include <sys/queue.h> 130 131 struct soft_intrhand { 132 TAILQ_ENTRY(soft_intrhand) sih_list; 133 void (*sih_func)(void *); 134 void *sih_arg; 135 struct soft_intrq *sih_siq; 136 int sih_pending; 137 }; 138 139 struct soft_intrq { 140 TAILQ_HEAD(, soft_intrhand) siq_list; 141 int siq_si; 142 struct mutex siq_mtx; 143 }; 144 145 void softintr_disestablish(void *); 146 void softintr_dispatch(int); 147 void *softintr_establish(int, void (*)(void *), void *); 148 void softintr_init(void); 149 void softintr_schedule(void *); 150 151 extern int softpending; 152 153 /* XXX For legacy software interrupts. */ 154 extern struct soft_intrhand *softnet_intrhand; 155 156 #define setsoftnet() softintr_schedule(softnet_intrhand) 157 158 #endif /* _LOCORE */ 159 160 #endif /* _KERNEL */ 161 #endif /* _M88K_INTR_H_ */ 162