intr.h revision 1.7
11.7Ssakamoto/* $NetBSD: intr.h,v 1.7 1999/06/24 01:33:08 sakamoto Exp $ */ 21.1Ssakamoto 31.6Smycroft/*- 41.6Smycroft * Copyright (c) 1998 The NetBSD Foundation, Inc. 51.6Smycroft * All rights reserved. 61.6Smycroft * 71.6Smycroft * This code is derived from software contributed to The NetBSD Foundation 81.6Smycroft * by Charles M. Hannum. 91.1Ssakamoto * 101.1Ssakamoto * Redistribution and use in source and binary forms, with or without 111.1Ssakamoto * modification, are permitted provided that the following conditions 121.1Ssakamoto * are met: 131.1Ssakamoto * 1. Redistributions of source code must retain the above copyright 141.1Ssakamoto * notice, this list of conditions and the following disclaimer. 151.1Ssakamoto * 2. Redistributions in binary form must reproduce the above copyright 161.1Ssakamoto * notice, this list of conditions and the following disclaimer in the 171.1Ssakamoto * documentation and/or other materials provided with the distribution. 181.1Ssakamoto * 3. All advertising materials mentioning features or use of this software 191.1Ssakamoto * must display the following acknowledgement: 201.6Smycroft * This product includes software developed by the NetBSD 211.6Smycroft * Foundation, Inc. and its contributors. 221.6Smycroft * 4. Neither the name of The NetBSD Foundation nor the names of its 231.6Smycroft * contributors may be used to endorse or promote products derived 241.6Smycroft * from this software without specific prior written permission. 251.1Ssakamoto * 261.6Smycroft * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 271.6Smycroft * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 281.6Smycroft * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 291.6Smycroft * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 301.6Smycroft * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 311.6Smycroft * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 321.6Smycroft * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 331.6Smycroft * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 341.6Smycroft * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 351.6Smycroft * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 361.6Smycroft * POSSIBILITY OF SUCH DAMAGE. 371.1Ssakamoto */ 381.1Ssakamoto 391.1Ssakamoto#ifndef _BEBOX_INTR_H_ 401.1Ssakamoto#define _BEBOX_INTR_H_ 411.1Ssakamoto 421.1Ssakamoto/* Interrupt priority `levels'. */ 431.1Ssakamoto#define IPL_NONE 9 /* nothing */ 441.1Ssakamoto#define IPL_SOFTCLOCK 8 /* software clock interrupt */ 451.1Ssakamoto#define IPL_SOFTNET 7 /* software network interrupt */ 461.1Ssakamoto#define IPL_BIO 6 /* block I/O */ 471.1Ssakamoto#define IPL_NET 5 /* network */ 481.1Ssakamoto#define IPL_TTY 4 /* terminal */ 491.1Ssakamoto#define IPL_IMP 3 /* memory allocation */ 501.1Ssakamoto#define IPL_AUDIO 2 /* audio */ 511.1Ssakamoto#define IPL_CLOCK 1 /* clock */ 521.1Ssakamoto#define IPL_HIGH 0 /* everything */ 531.4Ssakamoto#define IPL_SERIAL 0 /* serial */ 541.1Ssakamoto#define NIPL 10 551.1Ssakamoto 561.1Ssakamoto/* Interrupt sharing types. */ 571.1Ssakamoto#define IST_NONE 0 /* none */ 581.1Ssakamoto#define IST_PULSE 1 /* pulsed */ 591.1Ssakamoto#define IST_EDGE 2 /* edge-triggered */ 601.1Ssakamoto#define IST_LEVEL 3 /* level-triggered */ 611.1Ssakamoto 621.1Ssakamoto#ifndef _LOCORE 631.1Ssakamoto 641.2Ssakamoto/* 651.2Ssakamoto * Interrupt handler chains. intr_establish() inserts a handler into 661.2Ssakamoto * the list. The handler is called with its (single) argument. 671.2Ssakamoto */ 681.2Ssakamotostruct intrhand { 691.2Ssakamoto int (*ih_fun) __P((void *)); 701.2Ssakamoto void *ih_arg; 711.2Ssakamoto u_long ih_count; 721.2Ssakamoto struct intrhand *ih_next; 731.2Ssakamoto int ih_level; 741.2Ssakamoto int ih_irq; 751.2Ssakamoto}; 761.2Ssakamoto 771.2Ssakamotovoid setsoftclock __P((void)); 781.2Ssakamotovoid clearsoftclock __P((void)); 791.2Ssakamotoint splsoftclock __P((void)); 801.2Ssakamotovoid setsoftnet __P((void)); 811.2Ssakamotovoid clearsoftnet __P((void)); 821.2Ssakamotoint splsoftnet __P((void)); 831.2Ssakamoto 841.2Ssakamotovoid do_pending_int __P((void)); 851.2Ssakamoto 861.7Ssakamotostatic __inline int splraise __P((int)); 871.7Ssakamotostatic __inline int spllower __P((int)); 881.7Ssakamotostatic __inline void splx __P((int)); 891.7Ssakamotostatic __inline void set_sint __P((int)); 901.2Ssakamoto 911.2Ssakamotoextern volatile int cpl, ipending, astpending, tickspending; 921.2Ssakamotoextern int imask[]; 931.7Ssakamotoextern long intrcnt[]; 941.2Ssakamoto 951.2Ssakamoto/* 961.2Ssakamoto * Reorder protection in the following inline functions is 971.2Ssakamoto * achived with the "eieio" instruction which the assembler 981.2Ssakamoto * seems to detect and then doen't move instructions past.... 991.2Ssakamoto */ 1001.2Ssakamotostatic __inline int 1011.2Ssakamotosplraise(newcpl) 1021.2Ssakamoto int newcpl; 1031.2Ssakamoto{ 1041.2Ssakamoto int oldcpl; 1051.2Ssakamoto 1061.2Ssakamoto __asm__ volatile("sync; eieio\n"); /* don't reorder.... */ 1071.2Ssakamoto oldcpl = cpl; 1081.2Ssakamoto cpl = oldcpl | newcpl; 1091.2Ssakamoto __asm__ volatile("sync; eieio\n"); /* reorder protect */ 1101.2Ssakamoto return(oldcpl); 1111.2Ssakamoto} 1121.2Ssakamoto 1131.2Ssakamotostatic __inline void 1141.2Ssakamotosplx(newcpl) 1151.2Ssakamoto int newcpl; 1161.2Ssakamoto{ 1171.2Ssakamoto __asm__ volatile("sync; eieio\n"); /* reorder protect */ 1181.2Ssakamoto cpl = newcpl; 1191.2Ssakamoto if(ipending & ~newcpl) 1201.2Ssakamoto do_pending_int(); 1211.2Ssakamoto __asm__ volatile("sync; eieio\n"); /* reorder protect */ 1221.2Ssakamoto} 1231.2Ssakamoto 1241.2Ssakamotostatic __inline int 1251.2Ssakamotospllower(newcpl) 1261.2Ssakamoto int newcpl; 1271.2Ssakamoto{ 1281.2Ssakamoto int oldcpl; 1291.2Ssakamoto 1301.2Ssakamoto __asm__ volatile("sync; eieio\n"); /* reorder protect */ 1311.2Ssakamoto oldcpl = cpl; 1321.2Ssakamoto cpl = newcpl; 1331.2Ssakamoto if(ipending & ~newcpl) 1341.2Ssakamoto do_pending_int(); 1351.2Ssakamoto __asm__ volatile("sync; eieio\n"); /* reorder protect */ 1361.2Ssakamoto return(oldcpl); 1371.2Ssakamoto} 1381.2Ssakamoto 1391.2Ssakamoto/* Following code should be implemented with lwarx/stwcx to avoid 1401.2Ssakamoto * the disable/enable. i need to read the manual once more.... */ 1411.2Ssakamotostatic __inline void 1421.2Ssakamotoset_sint(pending) 1431.2Ssakamoto int pending; 1441.2Ssakamoto{ 1451.2Ssakamoto int msrsave; 1461.2Ssakamoto 1471.2Ssakamoto __asm__ ("mfmsr %0" : "=r"(msrsave)); 1481.2Ssakamoto __asm__ volatile ("mtmsr %0" :: "r"(msrsave & ~PSL_EE)); 1491.2Ssakamoto ipending |= pending; 1501.2Ssakamoto __asm__ volatile ("mtmsr %0" :: "r"(msrsave)); 1511.2Ssakamoto} 1521.2Ssakamoto 1531.2Ssakamoto#define ICU_LEN 32 1541.2Ssakamoto#define IRQ_SLAVE 2 1551.2Ssakamoto#define LEGAL_IRQ(x) ((x) >= 0 && (x) < ICU_LEN && (x) != IRQ_SLAVE) 1561.2Ssakamoto 1571.2Ssakamoto#define MOTHER_BOARD_REG 0x7ffff000 1581.2Ssakamoto#define CPU0_INT_MASK 0x0f0 1591.2Ssakamoto#define CPU1_INT_MASK 0x1f0 1601.2Ssakamoto#define INT_STATE_REG 0x2f0 1611.2Ssakamoto 1621.3Ssakamoto#define SINT_CLOCK 0x20000000 1631.3Ssakamoto#define SINT_NET 0x40000000 1641.4Ssakamoto#define SINT_SERIAL 0x80000000 1651.3Ssakamoto#define SPL_CLOCK 0x00000001 1661.4Ssakamoto#define SINT_MASK (SINT_CLOCK|SINT_NET|SINT_SERIAL) 1671.2Ssakamoto 1681.2Ssakamoto#define CNT_SINT_NET 29 1691.2Ssakamoto#define CNT_SINT_CLOCK 30 1701.4Ssakamoto#define CNT_SINT_SERIAL 31 1711.3Ssakamoto#define CNT_CLOCK 0 1721.2Ssakamoto 1731.2Ssakamoto#define splbio() splraise(imask[IPL_BIO]) 1741.2Ssakamoto#define splnet() splraise(imask[IPL_NET]) 1751.2Ssakamoto#define spltty() splraise(imask[IPL_TTY]) 1761.2Ssakamoto#define splclock() splraise(SPL_CLOCK|SINT_CLOCK|SINT_NET) 1771.2Ssakamoto#define splimp() splraise(imask[IPL_IMP]) 1781.4Ssakamoto#define splserial() splraise(imask[IPL_SERIAL]) 1791.2Ssakamoto#define splstatclock() splhigh() 1801.2Ssakamoto#define splsoftclock() spllower(SINT_CLOCK) 1811.2Ssakamoto#define splsoftnet() splraise(SINT_NET) 1821.4Ssakamoto#define splsoftserial() splraise(SINT_SERIAL) 1831.5Sis 1841.5Sis#define spllpt() spltty() 1851.2Ssakamoto 1861.2Ssakamoto#define setsoftclock() set_sint(SINT_CLOCK); 1871.2Ssakamoto#define setsoftnet() set_sint(SINT_NET); 1881.4Ssakamoto#define setsoftserial() set_sint(SINT_SERIAL); 1891.2Ssakamoto 1901.2Ssakamoto#define splhigh() splraise(0xffffffff) 1911.2Ssakamoto#define spl0() spllower(0) 1921.1Ssakamoto 1931.1Ssakamoto#endif /* !_LOCORE */ 1941.1Ssakamoto 1951.1Ssakamoto#endif /* !_BEBOX_INTR_H_ */ 196