intr.h revision 1.4
11.4Shpeyerl/* $NetBSD: intr.h,v 1.4 2003/04/01 17:34:10 hpeyerl Exp $ */ 21.1Ssimonb 31.1Ssimonb/*- 41.1Ssimonb * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc. 51.1Ssimonb * All rights reserved. 61.1Ssimonb * 71.1Ssimonb * This code is derived from software contributed to The NetBSD Foundation 81.1Ssimonb * by Jason R. Thorpe. 91.1Ssimonb * 101.1Ssimonb * Redistribution and use in source and binary forms, with or without 111.1Ssimonb * modification, are permitted provided that the following conditions 121.1Ssimonb * are met: 131.1Ssimonb * 1. Redistributions of source code must retain the above copyright 141.1Ssimonb * notice, this list of conditions and the following disclaimer. 151.1Ssimonb * 2. Redistributions in binary form must reproduce the above copyright 161.1Ssimonb * notice, this list of conditions and the following disclaimer in the 171.1Ssimonb * documentation and/or other materials provided with the distribution. 181.1Ssimonb * 3. All advertising materials mentioning features or use of this software 191.1Ssimonb * must display the following acknowledgement: 201.1Ssimonb * This product includes software developed by the NetBSD 211.1Ssimonb * Foundation, Inc. and its contributors. 221.1Ssimonb * 4. Neither the name of The NetBSD Foundation nor the names of its 231.1Ssimonb * contributors may be used to endorse or promote products derived 241.1Ssimonb * from this software without specific prior written permission. 251.1Ssimonb * 261.1Ssimonb * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 271.1Ssimonb * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 281.1Ssimonb * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 291.1Ssimonb * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 301.1Ssimonb * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 311.1Ssimonb * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 321.1Ssimonb * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 331.1Ssimonb * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 341.1Ssimonb * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 351.1Ssimonb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 361.1Ssimonb * POSSIBILITY OF SUCH DAMAGE. 371.1Ssimonb */ 381.1Ssimonb 391.1Ssimonb#ifndef _EVBMIPS_INTR_H_ 401.1Ssimonb#define _EVBMIPS_INTR_H_ 411.1Ssimonb 421.1Ssimonb#include <sys/device.h> 431.1Ssimonb#include <sys/lock.h> 441.1Ssimonb#include <sys/queue.h> 451.1Ssimonb 461.1Ssimonb#define IPL_NONE 0 /* disable only this interrupt */ 471.1Ssimonb 481.2Ssimonb#define IPL_SOFT 1 /* generic software interrupts */ 491.2Ssimonb#define IPL_SOFTCLOCK 2 /* clock software interrupts */ 501.2Ssimonb#define IPL_SOFTNET 3 /* network software interrupts */ 511.2Ssimonb#define IPL_SOFTSERIAL 4 /* serial software interrupts */ 521.1Ssimonb 531.1Ssimonb#define IPL_BIO 5 /* disable block I/O interrupts */ 541.1Ssimonb#define IPL_NET 6 /* disable network interrupts */ 551.1Ssimonb#define IPL_TTY 7 /* disable terminal interrupts */ 561.1Ssimonb#define IPL_SERIAL 7 /* disable serial interrupts */ 571.1Ssimonb#define IPL_CLOCK 8 /* disable clock interrupts */ 581.1Ssimonb#define IPL_HIGH 8 /* disable all interrupts */ 591.1Ssimonb 601.2Ssimonb#define _IPL_NSOFT 4 /* max soft IPL + 1 */ 611.2Ssimonb#define _IPL_N 9 /* max IPL + 1 */ 621.1Ssimonb 631.1Ssimonb#define _IPL_SI0_FIRST IPL_SOFT 641.1Ssimonb#define _IPL_SI0_LAST IPL_SOFTCLOCK 651.1Ssimonb 661.1Ssimonb#define _IPL_SI1_FIRST IPL_SOFTNET 671.1Ssimonb#define _IPL_SI1_LAST IPL_SOFTSERIAL 681.1Ssimonb 691.1Ssimonb#define IPL_SOFTNAMES { \ 701.1Ssimonb "misc", \ 711.1Ssimonb "clock", \ 721.1Ssimonb "net", \ 731.1Ssimonb "serial", \ 741.1Ssimonb} 751.1Ssimonb 761.1Ssimonb#define IST_UNUSABLE -1 /* interrupt cannot be used */ 771.1Ssimonb#define IST_NONE 0 /* none (dummy) */ 781.1Ssimonb#define IST_PULSE 1 /* pulsed */ 791.1Ssimonb#define IST_EDGE 2 /* edge-triggered */ 801.1Ssimonb#define IST_LEVEL 3 /* level-triggered */ 811.4Shpeyerl#define IST_LEVEL_HIGH 4 /* level triggered, active high */ 821.4Shpeyerl#define IST_LEVEL_LOW 5 /* level triggered, active low */ 831.1Ssimonb 841.1Ssimonb#ifdef _KERNEL 851.1Ssimonb 861.1Ssimonbextern const u_int32_t ipl_sr_bits[_IPL_N]; 871.1Ssimonbextern const u_int32_t ipl_si_to_sr[_IPL_NSOFT]; 881.1Ssimonb 891.1Ssimonbextern int _splraise(int); 901.1Ssimonbextern int _spllower(int); 911.1Ssimonbextern int _splset(int); 921.1Ssimonbextern int _splget(int); 931.1Ssimonbextern int _splnone(int); 941.1Ssimonbextern int _setsoftintr(int); 951.1Ssimonbextern int _clrsoftintr(int); 961.1Ssimonb 971.1Ssimonb#define splhigh() _splraise(ipl_sr_bits[IPL_HIGH]) 981.1Ssimonb#define spl0() (void) _spllower(0) 991.1Ssimonb#define splx(s) (void) _splset(s) 1001.1Ssimonb#define splbio() _splraise(ipl_sr_bits[IPL_BIO]) 1011.1Ssimonb#define splnet() _splraise(ipl_sr_bits[IPL_NET]) 1021.1Ssimonb#define spltty() _splraise(ipl_sr_bits[IPL_TTY]) 1031.1Ssimonb#define splserial() _splraise(ipl_sr_bits[IPL_SERIAL]) 1041.1Ssimonb#define splvm() spltty() 1051.1Ssimonb#define splclock() _splraise(ipl_sr_bits[IPL_CLOCK]) 1061.1Ssimonb#define splstatclock() splclock() 1071.1Ssimonb 1081.1Ssimonb#define splsched() splclock() 1091.1Ssimonb#define spllock() splhigh() 1101.1Ssimonb#define spllpt() spltty() 1111.1Ssimonb 1121.1Ssimonb#define splsoft() _splraise(ipl_sr_bits[IPL_SOFT]) 1131.1Ssimonb#define splsoftclock() _splraise(ipl_sr_bits[IPL_SOFTCLOCK]) 1141.1Ssimonb#define splsoftnet() _splraise(ipl_sr_bits[IPL_SOFTNET]) 1151.1Ssimonb#define splsoftserial() _splraise(ipl_sr_bits[IPL_SOFTSERIAL]) 1161.1Ssimonb 1171.1Ssimonb#define spllowersoftclock() _spllower(ipl_sr_bits[IPL_SOFTCLOCK]) 1181.1Ssimonb 1191.1Ssimonbstruct evbmips_intrhand { 1201.1Ssimonb LIST_ENTRY(evbmips_intrhand) ih_q; 1211.1Ssimonb int (*ih_func)(void *); 1221.1Ssimonb void *ih_arg; 1231.1Ssimonb int ih_irq; 1241.1Ssimonb}; 1251.1Ssimonb 1261.1Ssimonb#define setsoft(x) \ 1271.1Ssimonbdo { \ 1281.1Ssimonb _setsoftintr(ipl_si_to_sr[(x) - IPL_SOFT]); \ 1291.1Ssimonb} while (0) 1301.1Ssimonb 1311.1Ssimonbstruct evbmips_soft_intrhand { 1321.1Ssimonb TAILQ_ENTRY(evbmips_soft_intrhand) 1331.1Ssimonb sih_q; 1341.1Ssimonb struct evbmips_soft_intr *sih_intrhead; 1351.1Ssimonb void (*sih_fn)(void *); 1361.1Ssimonb void *sih_arg; 1371.1Ssimonb int sih_pending; 1381.1Ssimonb}; 1391.1Ssimonb 1401.1Ssimonbstruct evbmips_soft_intr { 1411.1Ssimonb TAILQ_HEAD(, evbmips_soft_intrhand) 1421.1Ssimonb softintr_q; 1431.1Ssimonb struct evcnt softintr_evcnt; 1441.1Ssimonb struct simplelock softintr_slock; 1451.1Ssimonb unsigned long softintr_ipl; 1461.1Ssimonb}; 1471.1Ssimonb 1481.1Ssimonbvoid *softintr_establish(int, void (*)(void *), void *); 1491.1Ssimonbvoid softintr_disestablish(void *); 1501.1Ssimonbvoid softintr_init(void); 1511.1Ssimonb 1521.1Ssimonb#define softintr_schedule(arg) \ 1531.1Ssimonbdo { \ 1541.1Ssimonb struct evbmips_soft_intrhand *__sih = (arg); \ 1551.1Ssimonb struct evbmips_soft_intr *__si = __sih->sih_intrhead; \ 1561.1Ssimonb int __s; \ 1571.1Ssimonb \ 1581.1Ssimonb __s = splhigh(); \ 1591.1Ssimonb simple_lock(&__si->softintr_slock); \ 1601.1Ssimonb if (__sih->sih_pending == 0) { \ 1611.1Ssimonb TAILQ_INSERT_TAIL(&__si->softintr_q, __sih, sih_q); \ 1621.1Ssimonb __sih->sih_pending = 1; \ 1631.1Ssimonb setsoft(__si->softintr_ipl); \ 1641.1Ssimonb } \ 1651.1Ssimonb simple_unlock(&__si->softintr_slock); \ 1661.1Ssimonb splx(__s); \ 1671.1Ssimonb} while (0) 1681.1Ssimonb 1691.1Ssimonb/* XXX For legacy software interrupts. */ 1701.1Ssimonbextern struct evbmips_soft_intrhand *softnet_intrhand; 1711.1Ssimonb 1721.1Ssimonb#define setsoftnet() softintr_schedule(softnet_intrhand) 1731.1Ssimonb 1741.1Ssimonbvoid evbmips_intr_init(void); 1751.1Ssimonbvoid intr_init(void); 1761.1Ssimonbvoid evbmips_iointr(u_int32_t, u_int32_t, u_int32_t, u_int32_t); 1771.1Ssimonbvoid *evbmips_intr_establish(int, int (*)(void *), void *); 1781.1Ssimonbvoid evbmips_intr_disestablish(void *); 1791.1Ssimonb#endif /* _KERNEL */ 1801.1Ssimonb#endif /* ! _EVBMIPS_INTR_H_ */ 181