intr.h revision 1.25
1/* $NetBSD: intr.h,v 1.25 2007/02/16 02:53:45 ad Exp $ */ 2 3/*- 4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Charles M. Hannum. 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 _BEBOX_INTR_H_ 40#define _BEBOX_INTR_H_ 41 42/* Interrupt priority `levels'. */ 43#define IPL_NONE 9 /* nothing */ 44#define IPL_SOFTCLOCK 8 /* software clock interrupt */ 45#define IPL_SOFTNET 7 /* software network interrupt */ 46#define IPL_BIO 6 /* block I/O */ 47#define IPL_NET 5 /* network */ 48#define IPL_SOFTSERIAL 4 /* software serial interrupt */ 49#define IPL_TTY 3 /* terminal */ 50#define IPL_LPT IPL_TTY 51#define IPL_VM 3 /* memory allocation */ 52#define IPL_AUDIO 2 /* audio */ 53#define IPL_CLOCK 1 /* clock */ 54#define IPL_STATCLOCK IPL_CLOCK 55#define IPL_HIGH 1 /* everything */ 56#define IPL_SCHED IPL_HIGH 57#define IPL_LOCK IPL_HIGH 58#define IPL_SERIAL 0 /* serial */ 59#define NIPL 10 60 61/* Interrupt sharing types. */ 62#define IST_NONE 0 /* none */ 63#define IST_PULSE 1 /* pulsed */ 64#define IST_EDGE 2 /* edge-triggered */ 65#define IST_LEVEL 3 /* level-triggered */ 66 67#ifndef _LOCORE 68 69/* 70 * Interrupt handler chains. intr_establish() inserts a handler into 71 * the list. The handler is called with its (single) argument. 72 */ 73struct intrhand { 74 int (*ih_fun) __P((void *)); 75 void *ih_arg; 76 u_long ih_count; 77 struct intrhand *ih_next; 78 int ih_level; 79 int ih_irq; 80}; 81 82void do_pending_int __P((void)); 83 84void ext_intr __P((void)); 85void *intr_establish __P((int, int, int, int (*)(void *), void *)); 86void intr_disestablish __P((void *)); 87void intr_calculatemasks __P((void)); 88int isa_intr __P((void)); 89void isa_intr_mask __P((int)); 90void isa_intr_clr __P((int)); 91 92void enable_intr __P((void)); 93void disable_intr __P((void)); 94 95static __inline int splraise __P((int)); 96static __inline int spllower __P((int)); 97static __inline void splx __P((int)); 98static __inline void set_sint __P((int)); 99 100extern volatile int cpl, ipending, astpending, tickspending; 101extern int imask[]; 102extern long intrcnt[]; 103 104/* 105 * Reorder protection in the following inline functions is 106 * achieved with the "eieio" instruction which the assembler 107 * seems to detect and then doesn't move instructions past.... 108 */ 109static __inline int 110splraise(newcpl) 111 int newcpl; 112{ 113 int oldcpl; 114 115 __asm volatile("sync; eieio\n"); /* don't reorder.... */ 116 oldcpl = cpl; 117 cpl = oldcpl | newcpl; 118 __asm volatile("sync; eieio\n"); /* reorder protect */ 119 return(oldcpl); 120} 121 122static __inline void 123splx(newcpl) 124 int newcpl; 125{ 126 __asm volatile("sync; eieio\n"); /* reorder protect */ 127 cpl = newcpl; 128 if(ipending & ~newcpl) 129 do_pending_int(); 130 __asm volatile("sync; eieio\n"); /* reorder protect */ 131} 132 133static __inline int 134spllower(newcpl) 135 int newcpl; 136{ 137 int oldcpl; 138 139 __asm volatile("sync; eieio\n"); /* reorder protect */ 140 oldcpl = cpl; 141 cpl = newcpl; 142 if(ipending & ~newcpl) 143 do_pending_int(); 144 __asm volatile("sync; eieio\n"); /* reorder protect */ 145 return(oldcpl); 146} 147 148/* Following code should be implemented with lwarx/stwcx to avoid 149 * the disable/enable. i need to read the manual once more.... */ 150static __inline void 151set_sint(pending) 152 int pending; 153{ 154 int msrsave; 155 156 __asm ("mfmsr %0" : "=r"(msrsave)); 157 __asm volatile ("mtmsr %0" :: "r"(msrsave & ~PSL_EE)); 158 ipending |= pending; 159 __asm volatile ("mtmsr %0" :: "r"(msrsave)); 160} 161 162#define ICU_LEN 32 163#define IRQ_SLAVE 2 164#define LEGAL_IRQ(x) ((x) >= 0 && (x) < ICU_LEN && (x) != IRQ_SLAVE) 165 166#define MOTHER_BOARD_REG 0x7ffff000 167#define CPU0_INT_MASK 0x0f0 168#define CPU1_INT_MASK 0x1f0 169#define INT_STATE_REG 0x2f0 170 171#define SINT_CLOCK 0x20000000 172#define SINT_NET 0x40000000 173#define SINT_SERIAL 0x80000000 174#define SPL_CLOCK 0x00000001 175#define SINT_MASK (SINT_CLOCK|SINT_NET|SINT_SERIAL) 176 177#define CNT_SINT_NET 29 178#define CNT_SINT_CLOCK 30 179#define CNT_SINT_SERIAL 31 180#define CNT_CLOCK 0 181 182#define setsoftclock() set_sint(SINT_CLOCK); 183#define setsoftnet() set_sint(SINT_NET); 184#define setsoftserial() set_sint(SINT_SERIAL); 185 186#define spl0() spllower(0) 187 188typedef int ipl_t; 189typedef struct { 190 ipl_t _ipl; 191} ipl_cookie_t; 192 193static inline ipl_cookie_t 194makeiplcookie(ipl_t ipl) 195{ 196 197 return (ipl_cookie_t){._ipl = ipl}; 198} 199 200static inline int 201splraiseipl(ipl_cookie_t icookie) 202{ 203 204 return splraise(imask[icookie._ipl]); 205} 206 207#include <sys/spl.h> 208 209#endif /* !_LOCORE */ 210 211#endif /* !_BEBOX_INTR_H_ */ 212