1 /* $NetBSD: intr.h,v 1.12 2001/12/08 04:09:19 gmcgarry Exp $ */ 2 3 /*- 4 * Copyright (c) 1996, 1997, 1999 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe. 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 by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND 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 THE FOUNDATION OR CONTRIBUTORS 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 _HP300_INTR_H_ 40 #define _HP300_INTR_H_ 41 42 #include <sys/device.h> 43 #include <sys/queue.h> 44 #include <machine/psl.h> 45 46 /* 47 * Interrupt "levels". These are a more abstract representation 48 * of interrupt levels, and do not have the same meaning as m68k 49 * CPU interrupt levels. They serve two purposes: 50 * 51 * - properly order ISRs in the list for that CPU ipl 52 * - compute CPU PSL values for the spl*() calls. 53 */ 54 #define IPL_NONE 0 /* disable only this interrupt */ 55 #define IPL_BIO 1 /* disable block I/O interrupts */ 56 #define IPL_NET 2 /* disable network interrupts */ 57 #define IPL_TTY 3 /* disable terminal interrupts */ 58 #define IPL_TTYNOBUF 4 /* IPL_TTY + higher ISR priority */ 59 #define IPL_CLOCK 5 /* disable clock interrupts */ 60 #define IPL_HIGH 6 /* disable all interrupts */ 61 62 /* Copied from alpha/include/intr.h */ 63 #define IPL_SOFTSERIAL 0 /* serial software interrupts */ 64 #define IPL_SOFTNET 1 /* network software interrupts */ 65 #define IPL_SOFTCLOCK 2 /* clock software interrupts */ 66 #define IPL_SOFT 3 /* other software interrupts */ 67 #define IPL_NSOFT 4 68 69 #define IPL_SOFTNAMES { \ 70 "serial", \ 71 "net", \ 72 "clock", \ 73 "misc", \ 74 } 75 76 /* 77 * Convert PSL values to CPU IPLs and vice-versa. 78 */ 79 #define PSLTOIPL(x) (((x) >> 8) & 0xf) 80 #define IPLTOPSL(x) ((((x) & 0xf) << 8) | PSL_S) 81 82 #ifdef _KERNEL 83 /* 84 * This array contains the appropriate PSL_S|PSL_IPL? values 85 * to raise interrupt priority to the requested level. 86 */ 87 extern unsigned short hp300_ipls[]; 88 89 #define HP300_IPL_SOFT 0 90 #define HP300_IPL_BIO 1 91 #define HP300_IPL_NET 2 92 #define HP300_IPL_TTY 3 93 #define HP300_IPL_VM 4 94 #define HP300_IPL_CLOCK 5 95 #define HP300_IPL_HIGH 6 96 #define HP300_NIPLS 7 97 98 /* These spl calls are _not_ to be used by machine-independent code. */ 99 #define splhil() splraise1() 100 #define splkbd() splhil() 101 102 /* These spl calls are used by machine-independent code. */ 103 /* spl0 requires checking for software interrupts */ 104 #define spllowersoftclock() spl1() 105 #define splsoft() splraise1() 106 #define splsoftclock() splsoft() 107 #define splsoftnet() splsoft() 108 #define splsoftserial splsoft() 109 #define splbio() _splraise(hp300_ipls[HP300_IPL_BIO]) 110 #define splnet() _splraise(hp300_ipls[HP300_IPL_NET]) 111 #define spltty() _splraise(hp300_ipls[HP300_IPL_TTY]) 112 #define splvm() _splraise(hp300_ipls[HP300_IPL_VM]) 113 #define splclock() spl6() 114 #define splstatclock() splclock() 115 #define splhigh() spl7() 116 #define splsched() spl7() 117 #define spllock() spl7() 118 119 /* watch out for side effects */ 120 #define splx(s) ((s) & PSL_IPL ? _spl((s)) : spl0()) 121 122 struct hp300_intrhand { 123 LIST_ENTRY(hp300_intrhand) ih_q; 124 int (*ih_fn)(void *); 125 void *ih_arg; 126 int ih_ipl; 127 int ih_priority; 128 }; 129 130 struct hp300_intr { 131 LIST_HEAD(, hp300_intrhand) hi_q; 132 struct evcnt hi_evcnt; 133 }; 134 135 /* 136 * Software Interrupts. 137 */ 138 139 struct hp300_soft_intrhand { 140 LIST_ENTRY(hp300_soft_intrhand) sih_q; 141 struct hp300_soft_intr *sih_intrhead; 142 void (*sih_fn)(void *); 143 void *sih_arg; 144 volatile int sih_pending; 145 }; 146 147 struct hp300_soft_intr { 148 LIST_HEAD(, hp300_soft_intrhand) hsi_q; 149 struct evcnt hsi_evcnt; 150 uint8_t hsi_ipl; 151 }; 152 153 void *softintr_establish(int, void (*)(void *), void *); 154 void softintr_disestablish(void *); 155 void softintr_init(void); 156 void softintr_dispatch(void); 157 158 extern volatile u_int8_t ssir; 159 #define setsoft(x) ssir |= (1<<(x)) 160 161 #define softintr_schedule(arg) \ 162 do { \ 163 struct hp300_soft_intrhand *__sih = (arg); \ 164 __sih->sih_pending = 1; \ 165 setsoft(__sih->sih_intrhead->hsi_ipl); \ 166 } while (0) 167 168 /* XXX For legacy software interrupts */ 169 extern struct hp300_soft_intrhand *softnet_intrhand; 170 #define setsoftnet() softintr_schedule(softnet_intrhand) 171 172 /* locore.s */ 173 int spl0(void); 174 175 /* intr.c */ 176 void intr_init(void); 177 void *intr_establish(int (*)(void *), void *, int, int); 178 void intr_disestablish(void *); 179 void intr_dispatch(int); 180 void intr_printlevels(void); 181 void netintr(void); 182 183 #endif /* _KERNEL */ 184 185 #endif /* _HP300_INTR_H_ */ 186