1 /* $OpenBSD: intr.h,v 1.10 2016/01/15 18:53:26 deraadt Exp $ */ 2 /* $NetBSD: intr.h,v 1.22 2006/01/24 23:51:42 uwe Exp $ */ 3 4 /*- 5 * Copyright (c) 2002 The NetBSD Foundation, Inc. 6 * All rights reserved. 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 * 17 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 * POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #ifndef _SH_INTR_H_ 31 #define _SH_INTR_H_ 32 33 #ifdef _KERNEL 34 35 #include <sys/device.h> 36 #include <sys/evcount.h> 37 #include <sys/mutex.h> 38 #include <sys/queue.h> 39 #include <sh/psl.h> 40 41 /* Interrupt sharing types. */ 42 #define IST_NONE 0 /* none */ 43 #define IST_PULSE 1 /* pulsed */ 44 #define IST_EDGE 2 /* edge-triggered */ 45 #define IST_LEVEL 3 /* level-triggered */ 46 47 /* Interrupt priority levels */ 48 #define _IPL_N 15 49 #define _IPL_NSOFT 4 50 51 #define IPL_NONE 0 /* nothing */ 52 #define IPL_SOFT 1 53 #define IPL_SOFTCLOCK 2 /* timeouts */ 54 #define IPL_SOFTNET 3 /* protocol stacks */ 55 #define IPL_SOFTSERIAL 4 /* serial */ 56 57 #define IPL_SOFTNAMES { \ 58 "misc", \ 59 "clock", \ 60 "net", \ 61 "serial", \ 62 } 63 64 struct intc_intrhand { 65 int (*ih_func)(void *); 66 void *ih_arg; 67 int ih_level; /* SR.I[0:3] value */ 68 int ih_evtcode; /* INTEVT or INTEVT2(SH7709/SH7709A) */ 69 int ih_idx; /* evtcode -> intrhand mapping */ 70 int ih_irq; 71 struct evcount ih_count; 72 const char *ih_name; 73 }; 74 75 void intr_barrier(void *); 76 77 /* from 0x200 by 0x20 -> from 0 by 1 */ 78 #define EVTCODE_TO_MAP_INDEX(x) (((x) >> 5) - 0x10) 79 #define EVTCODE_TO_IH_INDEX(x) \ 80 __intc_evtcode_to_ih[EVTCODE_TO_MAP_INDEX(x)] 81 #define EVTCODE_IH(x) (&__intc_intrhand[EVTCODE_TO_IH_INDEX(x)]) 82 extern int8_t __intc_evtcode_to_ih[]; 83 extern struct intc_intrhand __intc_intrhand[]; 84 85 void intc_init(void); 86 void *intc_intr_establish(int, int, int, int (*)(void *), void *, const char *); 87 void intc_intr_disestablish(void *); 88 void intc_intr_enable(int); 89 void intc_intr_disable(int); 90 void intc_intr(int, int, int); 91 92 void intpri_intr_priority(int evtcode, int level); 93 94 /* 95 * software simulated interrupt 96 */ 97 struct sh_soft_intrhand { 98 TAILQ_ENTRY(sh_soft_intrhand) sih_q; 99 struct sh_soft_intr *sih_intrhead; 100 void (*sih_fn)(void *); 101 void *sih_arg; 102 int sih_pending; 103 }; 104 105 struct sh_soft_intr { 106 TAILQ_HEAD(, sh_soft_intrhand) 107 softintr_q; 108 unsigned long softintr_ipl; 109 struct mutex softintr_lock; 110 }; 111 112 void softintr_disestablish(void *); 113 void softintr_dispatch(int); 114 void *softintr_establish(int, void (*)(void *), void *); 115 void softintr_init(void); 116 void softintr_schedule(void *); 117 118 #endif /* _KERNEL */ 119 120 #endif /* !_SH_INTR_H_ */ 121