Home | History | Annotate | Line # | Download | only in include
intr.h revision 1.5.16.3
      1  1.5.16.3     yamt /*	$NetBSD: intr.h,v 1.5.16.3 2007/02/26 09:07:34 yamt Exp $	*/
      2       1.1      scw 
      3       1.1      scw /*-
      4       1.2      scw  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5       1.1      scw  * All rights reserved.
      6       1.1      scw  *
      7       1.1      scw  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1      scw  * by Charles M. Hannum.
      9       1.1      scw  *
     10       1.1      scw  * Redistribution and use in source and binary forms, with or without
     11       1.1      scw  * modification, are permitted provided that the following conditions
     12       1.1      scw  * are met:
     13       1.1      scw  * 1. Redistributions of source code must retain the above copyright
     14       1.1      scw  *    notice, this list of conditions and the following disclaimer.
     15       1.1      scw  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1      scw  *    notice, this list of conditions and the following disclaimer in the
     17       1.1      scw  *    documentation and/or other materials provided with the distribution.
     18       1.1      scw  * 3. All advertising materials mentioning features or use of this software
     19       1.1      scw  *    must display the following acknowledgement:
     20       1.1      scw  *        This product includes software developed by the NetBSD
     21       1.1      scw  *        Foundation, Inc. and its contributors.
     22       1.1      scw  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.1      scw  *    contributors may be used to endorse or promote products derived
     24       1.1      scw  *    from this software without specific prior written permission.
     25       1.1      scw  *
     26       1.1      scw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.1      scw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.1      scw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.1      scw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.1      scw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.1      scw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.1      scw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.1      scw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.1      scw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.1      scw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.1      scw  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1      scw  */
     38       1.1      scw 
     39       1.1      scw #ifndef _MVMEPPC_INTR_H_
     40       1.1      scw #define _MVMEPPC_INTR_H_
     41       1.1      scw 
     42       1.1      scw /* Interrupt priority `levels'. */
     43       1.1      scw #define	IPL_NONE	9	/* nothing */
     44       1.1      scw #define	IPL_SOFTCLOCK	8	/* software clock interrupt */
     45       1.1      scw #define	IPL_SOFTNET	7	/* software network interrupt */
     46       1.1      scw #define	IPL_BIO		6	/* block I/O */
     47       1.1      scw #define	IPL_NET		5	/* network */
     48       1.1      scw #define	IPL_SOFTSERIAL	4	/* software serial interrupt */
     49       1.1      scw #define	IPL_TTY		3	/* terminal */
     50  1.5.16.2     yamt #define	IPL_LPT		IPL_TTY
     51       1.4  thorpej #define	IPL_VM		3	/* memory allocation */
     52       1.1      scw #define	IPL_AUDIO	2	/* audio */
     53       1.1      scw #define	IPL_CLOCK	1	/* clock */
     54  1.5.16.2     yamt #define	IPL_STATCLOCK	IPL_CLOCK
     55       1.1      scw #define	IPL_HIGH	1	/* everything */
     56  1.5.16.2     yamt #define	IPL_SCHED	IPL_HIGH
     57  1.5.16.2     yamt #define	IPL_LOCK	IPL_HIGH
     58       1.1      scw #define	IPL_SERIAL	0	/* serial */
     59       1.1      scw #define	NIPL		10
     60       1.1      scw 
     61  1.5.16.2     yamt 
     62       1.1      scw /* Interrupt sharing types. */
     63       1.1      scw #define	IST_NONE	0	/* none */
     64       1.1      scw #define	IST_PULSE	1	/* pulsed */
     65       1.1      scw #define	IST_EDGE	2	/* edge-triggered */
     66       1.1      scw #define	IST_LEVEL	3	/* level-triggered */
     67       1.1      scw 
     68       1.1      scw #ifndef _LOCORE
     69       1.1      scw 
     70       1.1      scw /*
     71       1.1      scw  * Interrupt handler chains.  intr_establish() inserts a handler into
     72       1.1      scw  * the list.  The handler is called with its (single) argument.
     73       1.1      scw  */
     74       1.1      scw struct intrhand {
     75       1.1      scw 	int	(*ih_fun)(void *);
     76       1.1      scw 	void	*ih_arg;
     77       1.1      scw 	u_long	ih_count;
     78       1.1      scw 	struct	intrhand *ih_next;
     79       1.1      scw 	int	ih_level;
     80       1.1      scw 	int	ih_irq;
     81       1.1      scw };
     82       1.1      scw 
     83       1.2      scw void do_pending_int(void);
     84       1.2      scw 
     85       1.2      scw void ext_intr(void);
     86       1.2      scw void ext_intr_ivr(void);
     87       1.2      scw 
     88       1.2      scw void enable_intr(void);
     89       1.2      scw void disable_intr(void);
     90       1.2      scw 
     91       1.2      scw void *intr_establish(int, int, int, int (*)(void *), void *);
     92       1.2      scw void intr_disestablish(void *);
     93       1.1      scw 
     94       1.3     matt void softnet(int);
     95       1.1      scw void softserial(void);
     96       1.1      scw int isa_intr(void);
     97       1.1      scw void isa_intr_mask(int);
     98       1.1      scw void isa_intr_clr(int);
     99       1.1      scw void isa_setirqstat(int, int, int);
    100       1.1      scw 
    101       1.2      scw static __inline int splraise(int);
    102       1.2      scw static __inline void spllower(int);
    103       1.2      scw static __inline void set_sint(int);
    104       1.1      scw 
    105       1.1      scw extern volatile int cpl, ipending, astpending, tickspending;
    106       1.2      scw extern int imen;
    107       1.1      scw extern int imask[];
    108       1.1      scw extern long intrcnt[];
    109       1.2      scw extern unsigned intrcnt2[];
    110       1.2      scw extern struct intrhand *intrhand[];
    111       1.1      scw extern int intrtype[];
    112       1.2      scw extern vaddr_t mvmeppc_intr_reg;
    113       1.1      scw 
    114       1.1      scw /*
    115       1.2      scw  *  Reorder protection in the following inline functions is
    116       1.2      scw  * achieved with the "eieio" instruction which the assembler
    117       1.2      scw  * seems to detect and then doesn't move instructions past....
    118       1.1      scw  */
    119       1.1      scw static __inline int
    120       1.2      scw splraise(int newcpl)
    121       1.1      scw {
    122       1.1      scw 	int oldcpl;
    123       1.1      scw 
    124  1.5.16.1     yamt 	__asm volatile("sync; eieio\n");	/* don't reorder.... */
    125       1.1      scw 	oldcpl = cpl;
    126       1.1      scw 	cpl = oldcpl | newcpl;
    127  1.5.16.1     yamt 	__asm volatile("sync; eieio\n");	/* reorder protect */
    128       1.1      scw 	return(oldcpl);
    129       1.1      scw }
    130       1.1      scw 
    131       1.1      scw static __inline void
    132       1.2      scw spllower(int newcpl)
    133       1.1      scw {
    134       1.1      scw 
    135  1.5.16.1     yamt 	__asm volatile("sync; eieio\n");	/* reorder protect */
    136       1.1      scw 	cpl = newcpl;
    137       1.1      scw 	if(ipending & ~newcpl)
    138       1.1      scw 		do_pending_int();
    139  1.5.16.1     yamt 	__asm volatile("sync; eieio\n");	/* reorder protect */
    140       1.1      scw }
    141       1.1      scw 
    142       1.1      scw /* Following code should be implemented with lwarx/stwcx to avoid
    143       1.1      scw  * the disable/enable. i need to read the manual once more.... */
    144       1.1      scw static __inline void
    145       1.2      scw set_sint(int pending)
    146       1.1      scw {
    147       1.1      scw 	int	msrsave;
    148       1.1      scw 
    149  1.5.16.1     yamt 	__asm ("mfmsr %0" : "=r"(msrsave));
    150  1.5.16.1     yamt 	__asm volatile ("mtmsr %0" :: "r"(msrsave & ~PSL_EE));
    151       1.1      scw 	ipending |= pending;
    152  1.5.16.1     yamt 	__asm volatile ("mtmsr %0" :: "r"(msrsave));
    153       1.1      scw }
    154       1.1      scw 
    155       1.1      scw #define	ICU_LEN		32
    156       1.1      scw #define	IRQ_SLAVE	2
    157       1.1      scw #define	LEGAL_IRQ(x)	((x) >= 0 && (x) < ICU_LEN && (x) != IRQ_SLAVE)
    158       1.1      scw 
    159       1.1      scw #define	MVMEPPC_INTR_REG	0xbffff000
    160       1.1      scw #define	INTR_VECTOR_REG	0xff0
    161       1.1      scw 
    162       1.1      scw #define	SINT_CLOCK	0x20000000
    163       1.1      scw #define	SINT_NET	0x40000000
    164       1.1      scw #define	SINT_SERIAL	0x80000000
    165       1.1      scw #define	SPL_CLOCK	0x00000001
    166       1.1      scw #define	SINT_MASK	(SINT_CLOCK|SINT_NET|SINT_SERIAL)
    167       1.1      scw 
    168       1.1      scw #define	CNT_SINT_NET	29
    169       1.1      scw #define	CNT_SINT_CLOCK	30
    170       1.1      scw #define	CNT_SINT_SERIAL	31
    171       1.1      scw #define	CNT_CLOCK	0
    172       1.1      scw 
    173       1.1      scw #define	setsoftclock()	set_sint(SINT_CLOCK);
    174       1.1      scw #define	setsoftnet()	set_sint(SINT_NET);
    175       1.1      scw #define	setsoftserial()	set_sint(SINT_SERIAL);
    176       1.2      scw 
    177       1.2      scw #define	splx(x)		spllower(x)
    178       1.2      scw #define	spl0()		spllower(0)
    179       1.1      scw 
    180  1.5.16.2     yamt typedef int ipl_t;
    181  1.5.16.2     yamt typedef struct {
    182  1.5.16.2     yamt 	ipl_t _ipl;
    183  1.5.16.2     yamt } ipl_cookie_t;
    184  1.5.16.2     yamt 
    185  1.5.16.2     yamt static inline ipl_cookie_t
    186  1.5.16.2     yamt makeiplcookie(ipl_t ipl)
    187  1.5.16.2     yamt {
    188  1.5.16.2     yamt 
    189  1.5.16.2     yamt 	return (ipl_cookie_t){._ipl = ipl};
    190  1.5.16.2     yamt }
    191  1.5.16.2     yamt 
    192  1.5.16.2     yamt static inline int
    193  1.5.16.2     yamt splraiseipl(ipl_cookie_t icookie)
    194  1.5.16.2     yamt {
    195  1.5.16.2     yamt 
    196  1.5.16.2     yamt 	return splraise(imask[icookie._ipl]);
    197  1.5.16.2     yamt }
    198  1.5.16.2     yamt 
    199  1.5.16.2     yamt #include <sys/spl.h>
    200  1.5.16.2     yamt 
    201       1.1      scw #endif /* !_LOCORE */
    202       1.1      scw 
    203       1.1      scw #endif /* !_MVMEPPC_INTR_H_ */
    204