1 /* $OpenBSD: intr.h,v 1.5 2016/08/06 17:25:15 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 intr_barrier(void *); 130 131 void arm_init_smask(void); /* XXX */ 132 extern uint32_t arm_smask[NIPL]; 133 void arm_setsoftintr(int si); 134 135 #define _setsoftintr arm_setsoftintr 136 137 #include <arm/softintr.h> 138 139 void *arm_intr_establish(int irqno, int level, int (*func)(void *), 140 void *cookie, char *name); 141 void arm_intr_disestablish(void *cookie); 142 const char *arm_intr_string(void *cookie); 143 144 /* XXX - this is probably the wrong location for this */ 145 void arm_clock_register(void (*)(void), void (*)(u_int), void (*)(int), 146 void (*)(void)); 147 148 struct interrupt_controller { 149 int ic_node; 150 void *ic_cookie; 151 void *(*ic_establish)(void *, int *, int, int (*)(void *), 152 void *, char *); 153 void (*ic_disestablish)(void *); 154 155 LIST_ENTRY(interrupt_controller) ic_list; 156 uint32_t ic_phandle; 157 uint32_t ic_cells; 158 }; 159 160 void arm_intr_init_fdt(void); 161 void arm_intr_register_fdt(struct interrupt_controller *); 162 void *arm_intr_establish_fdt(int, int, int (*)(void *), 163 void *, char *); 164 void *arm_intr_establish_fdt_idx(int, int, int, int (*)(void *), 165 void *, char *); 166 void arm_intr_disestablish_fdt(void *); 167 168 void *arm_intr_parent_establish_fdt(void *, int *, int, 169 int (*)(void *), void *, char *); 170 void arm_intr_parent_disestablish_fdt(void *); 171 172 #ifdef DIAGNOSTIC 173 /* 174 * Although this function is implemented in MI code, it must be in this MD 175 * header because we don't want this header to include MI includes. 176 */ 177 void splassert_fail(int, int, const char *); 178 extern int splassert_ctl; 179 void arm_splassert_check(int, const char *); 180 #define splassert(__wantipl) do { \ 181 if (splassert_ctl > 0) { \ 182 arm_splassert_check(__wantipl, __func__); \ 183 } \ 184 } while (0) 185 #define splsoftassert(wantipl) splassert(wantipl) 186 #else 187 #define splassert(wantipl) do { /* nothing */ } while (0) 188 #define splsoftassert(wantipl) do { /* nothing */ } while (0) 189 #endif 190 191 #endif /* ! _LOCORE */ 192 193 #define ARM_IRQ_HANDLER arm_intr 194 195 #endif /* _KERNEL */ 196 197 #endif /* _MACHINE_INTR_H_ */ 198 199