intr.h revision 1.6
11.6Stsubai/* $NetBSD: intr.h,v 1.6 2000/02/11 13:15:44 tsubai Exp $ */ 21.1Stsubai 31.3Smycroft/*- 41.3Smycroft * Copyright (c) 1998 The NetBSD Foundation, Inc. 51.3Smycroft * All rights reserved. 61.3Smycroft * 71.3Smycroft * This code is derived from software contributed to The NetBSD Foundation 81.3Smycroft * by Charles M. Hannum. 91.1Stsubai * 101.1Stsubai * Redistribution and use in source and binary forms, with or without 111.1Stsubai * modification, are permitted provided that the following conditions 121.1Stsubai * are met: 131.1Stsubai * 1. Redistributions of source code must retain the above copyright 141.1Stsubai * notice, this list of conditions and the following disclaimer. 151.1Stsubai * 2. Redistributions in binary form must reproduce the above copyright 161.1Stsubai * notice, this list of conditions and the following disclaimer in the 171.1Stsubai * documentation and/or other materials provided with the distribution. 181.1Stsubai * 3. All advertising materials mentioning features or use of this software 191.1Stsubai * must display the following acknowledgement: 201.3Smycroft * This product includes software developed by the NetBSD 211.3Smycroft * Foundation, Inc. and its contributors. 221.3Smycroft * 4. Neither the name of The NetBSD Foundation nor the names of its 231.3Smycroft * contributors may be used to endorse or promote products derived 241.3Smycroft * from this software without specific prior written permission. 251.1Stsubai * 261.3Smycroft * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 271.3Smycroft * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 281.3Smycroft * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 291.3Smycroft * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 301.3Smycroft * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 311.3Smycroft * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 321.3Smycroft * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 331.3Smycroft * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 341.3Smycroft * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 351.3Smycroft * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 361.3Smycroft * POSSIBILITY OF SUCH DAMAGE. 371.1Stsubai */ 381.1Stsubai 391.4Stsubai#ifndef _MACPPC_INTR_H_ 401.4Stsubai#define _MACPPC_INTR_H_ 411.1Stsubai 421.1Stsubai/* Interrupt priority `levels'. */ 431.1Stsubai#define IPL_NONE 9 /* nothing */ 441.1Stsubai#define IPL_SOFTCLOCK 8 /* timeouts */ 451.1Stsubai#define IPL_SOFTNET 7 /* protocol stacks */ 461.1Stsubai#define IPL_BIO 6 /* block I/O */ 471.1Stsubai#define IPL_NET 5 /* network */ 481.1Stsubai#define IPL_SOFTSERIAL 4 /* serial */ 491.1Stsubai#define IPL_TTY 3 /* terminal */ 501.1Stsubai#define IPL_IMP 3 /* memory allocation */ 511.1Stsubai#define IPL_AUDIO 2 /* audio */ 521.1Stsubai#define IPL_CLOCK 1 /* clock */ 531.1Stsubai#define IPL_HIGH 1 /* everything */ 541.1Stsubai#define IPL_SERIAL 0 /* serial */ 551.1Stsubai#define NIPL 10 561.1Stsubai 571.1Stsubai/* Interrupt sharing types. */ 581.1Stsubai#define IST_NONE 0 /* none */ 591.1Stsubai#define IST_PULSE 1 /* pulsed */ 601.1Stsubai#define IST_EDGE 2 /* edge-triggered */ 611.1Stsubai#define IST_LEVEL 3 /* level-triggered */ 621.1Stsubai 631.1Stsubai#ifndef _LOCORE 641.1Stsubai 651.1Stsubai/* 661.1Stsubai * Interrupt handler chains. intr_establish() inserts a handler into 671.1Stsubai * the list. The handler is called with its (single) argument. 681.1Stsubai */ 691.1Stsubaistruct intrhand { 701.1Stsubai int (*ih_fun) __P((void *)); 711.1Stsubai void *ih_arg; 721.1Stsubai u_long ih_count; 731.1Stsubai struct intrhand *ih_next; 741.1Stsubai int ih_level; 751.1Stsubai int ih_irq; 761.1Stsubai}; 771.1Stsubai 781.1Stsubaivoid setsoftclock __P((void)); 791.1Stsubaivoid clearsoftclock __P((void)); 801.1Stsubaiint splsoftclock __P((void)); 811.1Stsubaivoid setsoftnet __P((void)); 821.1Stsubaivoid clearsoftnet __P((void)); 831.1Stsubaiint splsoftnet __P((void)); 841.1Stsubai 851.1Stsubaivoid do_pending_int __P((void)); 861.1Stsubai 871.1Stsubaistatic __inline int splraise __P((int)); 881.1Stsubaistatic __inline int spllower __P((int)); 891.1Stsubaistatic __inline void splx __P((int)); 901.1Stsubaistatic __inline void softintr __P((int)); 911.1Stsubai 921.1Stsubaiextern volatile int cpl, ipending, astpending, tickspending; 931.1Stsubaiextern int imask[]; 941.1Stsubai 951.1Stsubai/* 961.1Stsubai * Reorder protection in the following inline functions is 971.1Stsubai * achived with the "eieio" instruction which the assembler 981.1Stsubai * seems to detect and then doen't move instructions past.... 991.1Stsubai */ 1001.1Stsubaistatic __inline int 1011.1Stsubaisplraise(ncpl) 1021.1Stsubai int ncpl; 1031.1Stsubai{ 1041.1Stsubai int ocpl; 1051.1Stsubai 1061.1Stsubai __asm__ volatile("sync; eieio\n"); /* don't reorder.... */ 1071.1Stsubai ocpl = cpl; 1081.1Stsubai cpl = ocpl | ncpl; 1091.1Stsubai __asm__ volatile("sync; eieio\n"); /* reorder protect */ 1101.1Stsubai return (ocpl); 1111.1Stsubai} 1121.1Stsubai 1131.1Stsubaistatic __inline void 1141.1Stsubaisplx(ncpl) 1151.1Stsubai int ncpl; 1161.1Stsubai{ 1171.1Stsubai 1181.1Stsubai __asm__ volatile("sync; eieio\n"); /* reorder protect */ 1191.1Stsubai cpl = ncpl; 1201.1Stsubai if (ipending & ~ncpl) 1211.1Stsubai do_pending_int(); 1221.1Stsubai __asm__ volatile("sync; eieio\n"); /* reorder protect */ 1231.1Stsubai} 1241.1Stsubai 1251.1Stsubaistatic __inline int 1261.1Stsubaispllower(ncpl) 1271.1Stsubai int ncpl; 1281.1Stsubai{ 1291.1Stsubai int ocpl; 1301.1Stsubai 1311.1Stsubai __asm__ volatile("sync; eieio\n"); /* reorder protect */ 1321.1Stsubai ocpl = cpl; 1331.1Stsubai cpl = ncpl; 1341.1Stsubai if (ipending & ~ncpl) 1351.1Stsubai do_pending_int(); 1361.1Stsubai __asm__ volatile("sync; eieio\n"); /* reorder protect */ 1371.1Stsubai return (ocpl); 1381.1Stsubai} 1391.1Stsubai 1401.1Stsubai/* Following code should be implemented with lwarx/stwcx to avoid 1411.1Stsubai * the disable/enable. i need to read the manual once more.... */ 1421.1Stsubaistatic __inline void 1431.1Stsubaisoftintr(ipl) 1441.1Stsubai int ipl; 1451.1Stsubai{ 1461.1Stsubai int msrsave; 1471.1Stsubai 1481.1Stsubai __asm__ volatile("mfmsr %0" : "=r"(msrsave)); 1491.1Stsubai __asm__ volatile("mtmsr %0" :: "r"(msrsave & ~PSL_EE)); 1501.1Stsubai ipending |= 1 << ipl; 1511.1Stsubai __asm__ volatile("mtmsr %0" :: "r"(msrsave)); 1521.1Stsubai} 1531.1Stsubai 1541.6Stsubai#define ICU_LEN 64 1551.1Stsubai 1561.1Stsubai/* Soft interrupt masks. */ 1571.1Stsubai#define SIR_CLOCK 28 1581.1Stsubai#define SIR_NET 29 1591.1Stsubai#define SIR_SERIAL 30 1601.1Stsubai#define SPL_CLOCK 31 1611.1Stsubai 1621.1Stsubai/* 1631.1Stsubai * Hardware interrupt masks 1641.1Stsubai */ 1651.1Stsubai#define splbio() splraise(imask[IPL_BIO]) 1661.1Stsubai#define splnet() splraise(imask[IPL_NET]) 1671.1Stsubai#define spltty() splraise(imask[IPL_TTY]) 1681.1Stsubai#define splaudio() splraise(imask[IPL_AUDIO]) 1691.1Stsubai#define splclock() splraise(imask[IPL_CLOCK]) 1701.1Stsubai#define splstatclock() splclock() 1711.1Stsubai#define splserial() splraise(imask[IPL_SERIAL]) 1721.2Sis 1731.2Sis#define spllpt() spltty() 1741.1Stsubai 1751.1Stsubai/* 1761.1Stsubai * Software interrupt masks 1771.1Stsubai * 1781.1Stsubai * NOTE: splsoftclock() is used by hardclock() to lower the priority from 1791.1Stsubai * clock to softclock before it calls softclock(). 1801.1Stsubai */ 1811.5Sthorpej#define spllowersoftclock() spllower(imask[IPL_SOFTCLOCK]) 1821.5Sthorpej#define splsoftclock() splraise(imask[IPL_SOFTCLOCK]) 1831.1Stsubai#define splsoftnet() splraise(imask[IPL_SOFTNET]) 1841.1Stsubai#define splsoftserial() splraise(imask[IPL_SOFTSERIAL]) 1851.1Stsubai 1861.1Stsubai/* 1871.1Stsubai * Miscellaneous 1881.1Stsubai */ 1891.1Stsubai#define splimp() splraise(imask[IPL_IMP]) 1901.1Stsubai#define splhigh() splraise(imask[IPL_HIGH]) 1911.1Stsubai#define spl0() spllower(0) 1921.1Stsubai 1931.1Stsubai#define setsoftclock() softintr(SIR_CLOCK) 1941.1Stsubai#define setsoftnet() softintr(SIR_NET) 1951.1Stsubai#define setsoftserial() softintr(SIR_SERIAL) 1961.1Stsubai 1971.4Stsubaiextern long intrcnt[]; 1981.4Stsubai 1991.4Stsubai#define CNT_IRQ0 0 2001.4Stsubai#define CNT_CLOCK 64 2011.4Stsubai#define CNT_SOFTCLOCK 65 2021.4Stsubai#define CNT_SOFTNET 66 2031.4Stsubai#define CNT_SOFTSERIAL 67 2041.4Stsubai 2051.1Stsubai#endif /* !_LOCORE */ 2061.1Stsubai 2071.4Stsubai#endif /* !_MACPPC_INTR_H_ */ 208