1 /* $OpenBSD: intr.h,v 1.1 2013/09/04 14:38:27 patrick Exp $ */ 2 /* $NetBSD: intr.h,v 1.12 2003/06/16 20:00:59 thorpej Exp $ */ 3 4 /* 5 * Copyright (c) 2001, 2003 Wasabi Systems, Inc. 6 * All rights reserved. 7 * 8 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed for the NetBSD Project by 21 * Wasabi Systems, Inc. 22 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 23 * or promote products derived from this software without specific prior 24 * written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 #ifndef _MACHINE_INTR_H_ 40 #define _MACHINE_INTR_H_ 41 42 #ifdef _KERNEL 43 44 /* Interrupt priority "levels". */ 45 #define IPL_NONE 0 /* nothing */ 46 #define IPL_SOFT 1 /* generic software interrupts */ 47 #define IPL_SOFTCLOCK 2 /* software clock interrupt */ 48 #define IPL_SOFTNET 3 /* software network interrupt */ 49 #define IPL_SOFTTTY 4 /* software serial interrupt */ 50 #define IPL_BIO 5 /* block I/O */ 51 #define IPL_NET 6 /* network */ 52 #define IPL_TTY 7 /* terminals */ 53 #define IPL_VM 8 /* memory allocation */ 54 #define IPL_AUDIO 9 /* audio device */ 55 #define IPL_CLOCK 10 /* clock interrupt */ 56 #define IPL_STATCLOCK 11 /* statistics clock interrupt */ 57 #define IPL_SCHED 12 /* everything */ 58 #define IPL_HIGH 12 /* everything */ 59 60 #define NIPL 13 61 62 /* Interrupt priority "flags". */ 63 #define IPL_MPSAFE 0 /* no "mpsafe" interrupts */ 64 65 /* Interrupt sharing types. */ 66 #define IST_NONE 0 /* none */ 67 #define IST_PULSE 1 /* pulsed */ 68 #define IST_EDGE 2 /* edge-triggered */ 69 #define IST_LEVEL 3 /* level-triggered */ 70 71 #define IST_LEVEL_LOW IST_LEVEL 72 #define IST_LEVEL_HIGH 4 73 #define IST_EDGE_FALLING IST_EDGE 74 #define IST_EDGE_RISING 5 75 #define IST_EDGE_BOTH 6 76 77 #ifndef _LOCORE 78 #include <sys/device.h> 79 #include <sys/queue.h> 80 81 int splraise(int); 82 int spllower(int); 83 void splx(int); 84 85 void arm_do_pending_intr(int); 86 void arm_set_intr_handler(int (*raise)(int), int (*lower)(int), 87 void (*x)(int), void (*setipl)(int), 88 void *(*intr_establish)(int irqno, int level, int (*func)(void *), 89 void *cookie, char *name), 90 void (*intr_disestablish)(void *cookie), 91 const char *(*intr_string)(void *cookie), 92 void (*intr_handle)(void *)); 93 94 struct arm_intr_func { 95 int (*raise)(int); 96 int (*lower)(int); 97 void (*x)(int); 98 void (*setipl)(int); 99 void *(*intr_establish)(int irqno, int level, int (*func)(void *), 100 void *cookie, char *name); 101 void (*intr_disestablish)(void *cookie); 102 const char *(*intr_string)(void *cookie); 103 }; 104 105 extern struct arm_intr_func arm_intr_func; 106 107 #define splraise(cpl) (arm_intr_func.raise(cpl)) 108 #define _splraise(cpl) (arm_intr_func.raise(cpl)) 109 #define spllower(cpl) (arm_intr_func.lower(cpl)) 110 #define splx(cpl) (arm_intr_func.x(cpl)) 111 112 #define splhigh() splraise(IPL_HIGH) 113 #define splsoft() splraise(IPL_SOFT) 114 #define splsoftclock() splraise(IPL_SOFTCLOCK) 115 #define splsoftnet() splraise(IPL_SOFTNET) 116 #define splbio() splraise(IPL_BIO) 117 #define splnet() splraise(IPL_NET) 118 #define spltty() splraise(IPL_TTY) 119 #define splvm() splraise(IPL_VM) 120 #define splaudio() splraise(IPL_AUDIO) 121 #define splclock() splraise(IPL_CLOCK) 122 #define splstatclock() splraise(IPL_STATCLOCK) 123 124 #define spl0() spllower(IPL_NONE) 125 126 #define splsched() splhigh() 127 #define spllock() splhigh() 128 129 void arm_init_smask(void); /* XXX */ 130 extern uint32_t arm_smask[NIPL]; 131 void arm_setsoftintr(int si); 132 133 #define _setsoftintr arm_setsoftintr 134 135 #include <arm/softintr.h> 136 137 void *arm_intr_establish(int irqno, int level, int (*func)(void *), 138 void *cookie, char *name); 139 void arm_intr_disestablish(void *cookie); 140 const char *arm_intr_string(void *cookie); 141 142 /* XXX - this is probably the wrong location for this */ 143 void arm_clock_register(void (*)(void), void (*)(u_int), void (*)(int), 144 void (*)(void)); 145 146 #ifdef DIAGNOSTIC 147 /* 148 * Although this function is implemented in MI code, it must be in this MD 149 * header because we don't want this header to include MI includes. 150 */ 151 void splassert_fail(int, int, const char *); 152 extern int splassert_ctl; 153 void arm_splassert_check(int, const char *); 154 #define splassert(__wantipl) do { \ 155 if (splassert_ctl > 0) { \ 156 arm_splassert_check(__wantipl, __func__); \ 157 } \ 158 } while (0) 159 #define splsoftassert(wantipl) splassert(wantipl) 160 #else 161 #define splassert(wantipl) do { /* nothing */ } while (0) 162 #define splsoftassert(wantipl) do { /* nothing */ } while (0) 163 #endif 164 165 #endif /* ! _LOCORE */ 166 167 #define ARM_IRQ_HANDLER arm_intr 168 169 #endif /* _KERNEL */ 170 171 #endif /* _MACHINE_INTR_H_ */ 172 173