1 /* $OpenBSD: intr.h,v 1.7 2009/04/19 18:54:06 oga 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/lock.h> 38 #include <sys/mutex.h> 39 #include <sys/queue.h> 40 #include <sh/psl.h> 41 42 /* Interrupt sharing types. */ 43 #define IST_NONE 0 /* none */ 44 #define IST_PULSE 1 /* pulsed */ 45 #define IST_EDGE 2 /* edge-triggered */ 46 #define IST_LEVEL 3 /* level-triggered */ 47 48 /* Interrupt priority levels */ 49 #define _IPL_N 15 50 #define _IPL_NSOFT 4 51 52 #define IPL_NONE 0 /* nothing */ 53 #define IPL_SOFT 1 54 #define IPL_SOFTCLOCK 2 /* timeouts */ 55 #define IPL_SOFTNET 3 /* protocol stacks */ 56 #define IPL_SOFTSERIAL 4 /* serial */ 57 58 #define IPL_SOFTNAMES { \ 59 "misc", \ 60 "clock", \ 61 "net", \ 62 "serial", \ 63 } 64 65 struct intc_intrhand { 66 int (*ih_func)(void *); 67 void *ih_arg; 68 int ih_level; /* SR.I[0:3] value */ 69 int ih_evtcode; /* INTEVT or INTEVT2(SH7709/SH7709A) */ 70 int ih_idx; /* evtcode -> intrhand mapping */ 71 int ih_irq; 72 struct evcount ih_count; 73 const char *ih_name; 74 }; 75 76 /* from 0x200 by 0x20 -> from 0 by 1 */ 77 #define EVTCODE_TO_MAP_INDEX(x) (((x) >> 5) - 0x10) 78 #define EVTCODE_TO_IH_INDEX(x) \ 79 __intc_evtcode_to_ih[EVTCODE_TO_MAP_INDEX(x)] 80 #define EVTCODE_IH(x) (&__intc_intrhand[EVTCODE_TO_IH_INDEX(x)]) 81 extern int8_t __intc_evtcode_to_ih[]; 82 extern struct intc_intrhand __intc_intrhand[]; 83 84 void intc_init(void); 85 void *intc_intr_establish(int, int, int, int (*)(void *), void *, const char *); 86 void intc_intr_disestablish(void *); 87 void intc_intr_enable(int); 88 void intc_intr_disable(int); 89 void intc_intr(int, int, int); 90 91 void intpri_intr_priority(int evtcode, int level); 92 93 /* 94 * software simulated interrupt 95 */ 96 struct sh_soft_intrhand { 97 TAILQ_ENTRY(sh_soft_intrhand) sih_q; 98 struct sh_soft_intr *sih_intrhead; 99 void (*sih_fn)(void *); 100 void *sih_arg; 101 int sih_pending; 102 }; 103 104 struct sh_soft_intr { 105 TAILQ_HEAD(, sh_soft_intrhand) 106 softintr_q; 107 unsigned long softintr_ipl; 108 struct mutex softintr_lock; 109 }; 110 111 void softintr_disestablish(void *); 112 void softintr_dispatch(int); 113 void *softintr_establish(int, void (*)(void *), void *); 114 void softintr_init(void); 115 void softintr_schedule(void *); 116 117 /* XXX For legacy software interrupts. */ 118 extern struct sh_soft_intrhand *softnet_intrhand; 119 120 #define setsoftnet() softintr_schedule(softnet_intrhand) 121 122 #endif /* _KERNEL */ 123 124 #endif /* !_SH_INTR_H_ */ 125