intr.h revision 1.1
1/* $NetBSD: intr.h,v 1.1 2001/10/16 15:38:46 uch Exp $ */ 2 3/*- 4 * Copyright (c) 2001 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, UCHIYAMA Yasushi. 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 _PLAYSTATION2_INTR_H_ 40#define _PLAYSTATION2_INTR_H_ 41#ifdef _KERNEL 42 43#include <sys/device.h> 44#include <sys/lock.h> 45#include <sys/queue.h> 46 47/* Interrupt sharing types. */ 48#define IST_NONE 0 /* none */ 49#define IST_PULSE 1 /* pulsed */ 50#define IST_EDGE 2 /* edge-triggered */ 51#define IST_LEVEL 3 /* level-triggered */ 52 53/* Interrupt priority levels */ 54#define IPL_NONE 0 /* nothing */ 55 56#define IPL_SOFT 1 /* generic */ 57#define IPL_SOFTCLOCK 2 /* timeouts */ 58#define IPL_SOFTNET 3 /* protocol stacks */ 59#define IPL_SOFTSERIAL 4 /* serial */ 60 61#define IPL_BIO 5 /* block I/O */ 62#define IPL_NET 6 /* network */ 63#define IPL_TTY 7 /* terminal */ 64#define IPL_SERIAL 7 /* serial */ 65#define IPL_CLOCK 8 /* clock */ 66#define IPL_HIGH 8 /* everything */ 67 68#define _IPL_NSOFT 4 69#define _IPL_N 9 70#define IPL_SOFTNAMES { \ 71 "misc", \ 72 "clock", \ 73 "net", \ 74 "serial", \ 75} 76 77/* 78 * Hardware interrupt masks 79 */ 80extern u_int32_t __icu_mask[_IPL_N]; 81 82#define splbio() splraise(__icu_mask[IPL_BIO]) 83#define splnet() splraise(__icu_mask[IPL_NET]) 84#define spltty() splraise(__icu_mask[IPL_TTY]) 85#define splserial() splraise(__icu_mask[IPL_SERIAL]) 86#define splclock() splraise(__icu_mask[IPL_CLOCK]) 87 88#define splstatclock() splclock() 89#define splvm() spltty() 90 91/* 92 * Software interrupt masks 93 */ 94#define splsoft() splraise(__icu_mask[IPL_SOFT]) 95#define splsoftclock() splraise(__icu_mask[IPL_SOFTCLOCK]) 96#define splsoftnet() splraise(__icu_mask[IPL_SOFTNET]) 97#define splsoftserial() splraise(__icu_mask[IPL_SOFTSERIAL]) 98 99#define spllowersoftclock() splset(__icu_mask[IPL_SOFTCLOCK]) 100void spllowersofthigh(void); 101 102/* 103 * Miscellaneous 104 */ 105#define splx(s) splset(s) 106#define splhigh() splraise(__icu_mask[IPL_HIGH]) 107#define splsched() splhigh() 108#define spllock() splhigh() 109 110/* 111 * software simulated interrupt 112 */ 113struct playstation2_soft_intrhand { 114 TAILQ_ENTRY(playstation2_soft_intrhand) sih_q; 115 struct playstation2_soft_intr *sih_intrhead; 116 void (*sih_fn)(void *); 117 void *sih_arg; 118 int sih_pending; 119}; 120 121struct playstation2_soft_intr { 122 TAILQ_HEAD(, playstation2_soft_intrhand) softintr_q; 123 struct evcnt softintr_evcnt; 124 struct simplelock softintr_slock; 125 unsigned long softintr_ipl; 126}; 127 128#define softintr_schedule(arg) \ 129do { \ 130 struct playstation2_soft_intrhand *__sih = (arg); \ 131 struct playstation2_soft_intr *__si = __sih->sih_intrhead; \ 132 int __s; \ 133 \ 134 __s = _intr_suspend(); \ 135 simple_lock(&__si->softintr_slock); \ 136 if (__sih->sih_pending == 0) { \ 137 TAILQ_INSERT_TAIL(&__si->softintr_q, __sih, sih_q); \ 138 __sih->sih_pending = 1; \ 139 setsoft(__si->softintr_ipl); \ 140 } \ 141 simple_unlock(&__si->softintr_slock); \ 142 _intr_resume(__s); \ 143} while (0) 144 145void *softintr_establish(int, void (*)(void *), void *); 146void softintr_disestablish(void *); 147void setsoft(int); 148 149/* XXX For legacy software interrupts. */ 150extern struct playstation2_soft_intrhand *softnet_intrhand; 151 152#define setsoftnet() softintr_schedule(softnet_intrhand) 153 154extern int splraise(int); 155extern void splset(int); 156extern void spl0(void); 157extern int _splset(int); 158 159/* fast interrupt locking for MD use. */ 160extern int _intr_suspend(void); 161extern void _intr_resume(int); 162 163#endif /* _KERNEL */ 164#endif /* _PLAYSTATION2_INTR_H_ */ 165