intr.h revision 1.4
1/* $NetBSD: intr.h,v 1.4 2007/02/16 02:53:50 ad 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 99void spllowersofthigh(void); 100 101/* 102 * Miscellaneous 103 */ 104#define splx(s) splset(s) 105#define splhigh() splraise(__icu_mask[IPL_HIGH]) 106#define splsched() splhigh() 107#define spllock() splhigh() 108 109/* 110 * software simulated interrupt 111 */ 112struct playstation2_soft_intrhand { 113 TAILQ_ENTRY(playstation2_soft_intrhand) sih_q; 114 struct playstation2_soft_intr *sih_intrhead; 115 void (*sih_fn)(void *); 116 void *sih_arg; 117 int sih_pending; 118}; 119 120struct playstation2_soft_intr { 121 TAILQ_HEAD(, playstation2_soft_intrhand) softintr_q; 122 struct evcnt softintr_evcnt; 123 struct simplelock softintr_slock; 124 unsigned long softintr_ipl; 125}; 126 127#define softintr_schedule(arg) \ 128do { \ 129 struct playstation2_soft_intrhand *__sih = (arg); \ 130 struct playstation2_soft_intr *__si = __sih->sih_intrhead; \ 131 int __s; \ 132 \ 133 __s = _intr_suspend(); \ 134 simple_lock(&__si->softintr_slock); \ 135 if (__sih->sih_pending == 0) { \ 136 TAILQ_INSERT_TAIL(&__si->softintr_q, __sih, sih_q); \ 137 __sih->sih_pending = 1; \ 138 setsoft(__si->softintr_ipl); \ 139 } \ 140 simple_unlock(&__si->softintr_slock); \ 141 _intr_resume(__s); \ 142} while (0) 143 144void *softintr_establish(int, void (*)(void *), void *); 145void softintr_disestablish(void *); 146void setsoft(int); 147 148/* XXX For legacy software interrupts. */ 149extern struct playstation2_soft_intrhand *softnet_intrhand; 150 151#define setsoftnet() softintr_schedule(softnet_intrhand) 152 153extern int splraise(int); 154extern void splset(int); 155extern void spl0(void); 156extern int _splset(int); 157 158/* R5900 EI/DI instruction */ 159extern int _intr_suspend(void); 160extern void _intr_resume(int); 161 162#endif /* _KERNEL */ 163#endif /* _PLAYSTATION2_INTR_H_ */ 164