intr.h revision 1.3
11.3Ssakamoto/* $NetBSD: intr.h,v 1.3 1997/12/11 09:04:28 sakamoto Exp $ */ 21.2Ssakamoto/* $OpenBSD: intr.h,v 1.1 1997/10/13 10:53:45 pefo Exp $ */ 31.1Ssakamoto 41.1Ssakamoto/* 51.1Ssakamoto * Copyright (c) 1996, 1997 Charles M. Hannum. All rights reserved. 61.1Ssakamoto * 71.1Ssakamoto * Redistribution and use in source and binary forms, with or without 81.1Ssakamoto * modification, are permitted provided that the following conditions 91.1Ssakamoto * are met: 101.1Ssakamoto * 1. Redistributions of source code must retain the above copyright 111.1Ssakamoto * notice, this list of conditions and the following disclaimer. 121.1Ssakamoto * 2. Redistributions in binary form must reproduce the above copyright 131.1Ssakamoto * notice, this list of conditions and the following disclaimer in the 141.1Ssakamoto * documentation and/or other materials provided with the distribution. 151.1Ssakamoto * 3. All advertising materials mentioning features or use of this software 161.1Ssakamoto * must display the following acknowledgement: 171.1Ssakamoto * This product includes software developed by Charles M. Hannum. 181.1Ssakamoto * 4. The name of the author may not be used to endorse or promote products 191.1Ssakamoto * derived from this software without specific prior written permission. 201.1Ssakamoto * 211.1Ssakamoto * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 221.1Ssakamoto * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 231.1Ssakamoto * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 241.1Ssakamoto * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 251.1Ssakamoto * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 261.1Ssakamoto * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 271.1Ssakamoto * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 281.1Ssakamoto * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 291.1Ssakamoto * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 301.1Ssakamoto * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 311.1Ssakamoto */ 321.1Ssakamoto 331.1Ssakamoto#ifndef _BEBOX_INTR_H_ 341.1Ssakamoto#define _BEBOX_INTR_H_ 351.1Ssakamoto 361.1Ssakamoto/* Interrupt priority `levels'. */ 371.1Ssakamoto#define IPL_NONE 9 /* nothing */ 381.1Ssakamoto#define IPL_SOFTCLOCK 8 /* software clock interrupt */ 391.1Ssakamoto#define IPL_SOFTNET 7 /* software network interrupt */ 401.1Ssakamoto#define IPL_BIO 6 /* block I/O */ 411.1Ssakamoto#define IPL_NET 5 /* network */ 421.1Ssakamoto#define IPL_TTY 4 /* terminal */ 431.1Ssakamoto#define IPL_IMP 3 /* memory allocation */ 441.1Ssakamoto#define IPL_AUDIO 2 /* audio */ 451.1Ssakamoto#define IPL_CLOCK 1 /* clock */ 461.1Ssakamoto#define IPL_HIGH 0 /* everything */ 471.1Ssakamoto#define NIPL 10 481.1Ssakamoto 491.1Ssakamoto/* Interrupt sharing types. */ 501.1Ssakamoto#define IST_NONE 0 /* none */ 511.1Ssakamoto#define IST_PULSE 1 /* pulsed */ 521.1Ssakamoto#define IST_EDGE 2 /* edge-triggered */ 531.1Ssakamoto#define IST_LEVEL 3 /* level-triggered */ 541.1Ssakamoto 551.1Ssakamoto#ifndef _LOCORE 561.1Ssakamoto 571.2Ssakamoto/* 581.2Ssakamoto * Interrupt handler chains. intr_establish() inserts a handler into 591.2Ssakamoto * the list. The handler is called with its (single) argument. 601.2Ssakamoto */ 611.2Ssakamotostruct intrhand { 621.2Ssakamoto int (*ih_fun) __P((void *)); 631.2Ssakamoto void *ih_arg; 641.2Ssakamoto u_long ih_count; 651.2Ssakamoto struct intrhand *ih_next; 661.2Ssakamoto int ih_level; 671.2Ssakamoto int ih_irq; 681.2Ssakamoto}; 691.2Ssakamoto 701.2Ssakamotovoid setsoftclock __P((void)); 711.2Ssakamotovoid clearsoftclock __P((void)); 721.2Ssakamotoint splsoftclock __P((void)); 731.2Ssakamotovoid setsoftnet __P((void)); 741.2Ssakamotovoid clearsoftnet __P((void)); 751.2Ssakamotoint splsoftnet __P((void)); 761.2Ssakamoto 771.2Ssakamotovoid do_pending_int __P((void)); 781.2Ssakamoto 791.2Ssakamoto 801.2Ssakamotoextern volatile int cpl, ipending, astpending, tickspending; 811.2Ssakamotoextern int imask[]; 821.2Ssakamoto 831.2Ssakamoto/* 841.2Ssakamoto * Reorder protection in the following inline functions is 851.2Ssakamoto * achived with the "eieio" instruction which the assembler 861.2Ssakamoto * seems to detect and then doen't move instructions past.... 871.2Ssakamoto */ 881.2Ssakamotostatic __inline int 891.2Ssakamotosplraise(newcpl) 901.2Ssakamoto int newcpl; 911.2Ssakamoto{ 921.2Ssakamoto int oldcpl; 931.2Ssakamoto 941.2Ssakamoto __asm__ volatile("sync; eieio\n"); /* don't reorder.... */ 951.2Ssakamoto oldcpl = cpl; 961.2Ssakamoto cpl = oldcpl | newcpl; 971.2Ssakamoto __asm__ volatile("sync; eieio\n"); /* reorder protect */ 981.2Ssakamoto return(oldcpl); 991.2Ssakamoto} 1001.2Ssakamoto 1011.2Ssakamotostatic __inline void 1021.2Ssakamotosplx(newcpl) 1031.2Ssakamoto int newcpl; 1041.2Ssakamoto{ 1051.2Ssakamoto __asm__ volatile("sync; eieio\n"); /* reorder protect */ 1061.2Ssakamoto cpl = newcpl; 1071.2Ssakamoto if(ipending & ~newcpl) 1081.2Ssakamoto do_pending_int(); 1091.2Ssakamoto __asm__ volatile("sync; eieio\n"); /* reorder protect */ 1101.2Ssakamoto} 1111.2Ssakamoto 1121.2Ssakamotostatic __inline int 1131.2Ssakamotospllower(newcpl) 1141.2Ssakamoto int newcpl; 1151.2Ssakamoto{ 1161.2Ssakamoto int oldcpl; 1171.2Ssakamoto 1181.2Ssakamoto __asm__ volatile("sync; eieio\n"); /* reorder protect */ 1191.2Ssakamoto oldcpl = cpl; 1201.2Ssakamoto cpl = newcpl; 1211.2Ssakamoto if(ipending & ~newcpl) 1221.2Ssakamoto do_pending_int(); 1231.2Ssakamoto __asm__ volatile("sync; eieio\n"); /* reorder protect */ 1241.2Ssakamoto return(oldcpl); 1251.2Ssakamoto} 1261.2Ssakamoto 1271.2Ssakamoto/* Following code should be implemented with lwarx/stwcx to avoid 1281.2Ssakamoto * the disable/enable. i need to read the manual once more.... */ 1291.2Ssakamotostatic __inline void 1301.2Ssakamotoset_sint(pending) 1311.2Ssakamoto int pending; 1321.2Ssakamoto{ 1331.2Ssakamoto int msrsave; 1341.2Ssakamoto 1351.2Ssakamoto __asm__ ("mfmsr %0" : "=r"(msrsave)); 1361.2Ssakamoto __asm__ volatile ("mtmsr %0" :: "r"(msrsave & ~PSL_EE)); 1371.2Ssakamoto ipending |= pending; 1381.2Ssakamoto __asm__ volatile ("mtmsr %0" :: "r"(msrsave)); 1391.2Ssakamoto} 1401.2Ssakamoto 1411.2Ssakamoto#define ICU_LEN 32 1421.2Ssakamoto#define IRQ_SLAVE 2 1431.2Ssakamoto#define LEGAL_IRQ(x) ((x) >= 0 && (x) < ICU_LEN && (x) != IRQ_SLAVE) 1441.2Ssakamoto 1451.2Ssakamoto#define MOTHER_BOARD_REG 0x7ffff000 1461.2Ssakamoto#define CPU0_INT_MASK 0x0f0 1471.2Ssakamoto#define CPU1_INT_MASK 0x1f0 1481.2Ssakamoto#define INT_STATE_REG 0x2f0 1491.2Ssakamoto 1501.3Ssakamoto#define SINT_CLOCK 0x20000000 1511.3Ssakamoto#define SINT_NET 0x40000000 1521.3Ssakamoto#define SINT_TTY 0x80000000 1531.3Ssakamoto#define SPL_CLOCK 0x00000001 1541.2Ssakamoto#define SINT_MASK (SINT_CLOCK|SINT_NET|SINT_TTY) 1551.2Ssakamoto 1561.2Ssakamoto#define CNT_SINT_NET 29 1571.2Ssakamoto#define CNT_SINT_CLOCK 30 1581.3Ssakamoto#define CNT_SINT_TTY 31 1591.3Ssakamoto#define CNT_CLOCK 0 1601.2Ssakamoto 1611.2Ssakamoto#define splbio() splraise(imask[IPL_BIO]) 1621.2Ssakamoto#define splnet() splraise(imask[IPL_NET]) 1631.2Ssakamoto#define spltty() splraise(imask[IPL_TTY]) 1641.2Ssakamoto#define splclock() splraise(SPL_CLOCK|SINT_CLOCK|SINT_NET) 1651.2Ssakamoto#define splimp() splraise(imask[IPL_IMP]) 1661.2Ssakamoto#define splstatclock() splhigh() 1671.2Ssakamoto#define splsoftclock() spllower(SINT_CLOCK) 1681.2Ssakamoto#define splsoftnet() splraise(SINT_NET) 1691.2Ssakamoto#define splsofttty() splraise(SINT_TTY) 1701.2Ssakamoto 1711.2Ssakamoto#define setsoftclock() set_sint(SINT_CLOCK); 1721.2Ssakamoto#define setsoftnet() set_sint(SINT_NET); 1731.2Ssakamoto#define setsofttty() set_sint(SINT_TTY); 1741.2Ssakamoto 1751.2Ssakamoto#define splhigh() splraise(0xffffffff) 1761.2Ssakamoto#define spl0() spllower(0) 1771.1Ssakamoto 1781.1Ssakamoto#endif /* !_LOCORE */ 1791.1Ssakamoto 1801.1Ssakamoto#endif /* !_BEBOX_INTR_H_ */ 181