Home | History | Annotate | Line # | Download | only in include
intr.h revision 1.11
      1  1.11     yamt /*	$NetBSD: intr.h,v 1.11 2006/12/21 15:55:24 yamt Exp $	*/
      2   1.1   briggs 
      3   1.1   briggs /*-
      4   1.1   briggs  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5   1.1   briggs  * All rights reserved.
      6   1.1   briggs  *
      7   1.1   briggs  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1   briggs  * by Charles M. Hannum.
      9   1.1   briggs  *
     10   1.1   briggs  * Redistribution and use in source and binary forms, with or without
     11   1.1   briggs  * modification, are permitted provided that the following conditions
     12   1.1   briggs  * are met:
     13   1.1   briggs  * 1. Redistributions of source code must retain the above copyright
     14   1.1   briggs  *    notice, this list of conditions and the following disclaimer.
     15   1.1   briggs  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1   briggs  *    notice, this list of conditions and the following disclaimer in the
     17   1.1   briggs  *    documentation and/or other materials provided with the distribution.
     18   1.1   briggs  * 3. All advertising materials mentioning features or use of this software
     19   1.1   briggs  *    must display the following acknowledgement:
     20   1.1   briggs  *        This product includes software developed by the NetBSD
     21   1.1   briggs  *        Foundation, Inc. and its contributors.
     22   1.1   briggs  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.1   briggs  *    contributors may be used to endorse or promote products derived
     24   1.1   briggs  *    from this software without specific prior written permission.
     25   1.1   briggs  *
     26   1.1   briggs  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.1   briggs  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1   briggs  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1   briggs  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.1   briggs  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1   briggs  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1   briggs  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1   briggs  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1   briggs  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1   briggs  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1   briggs  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1   briggs  */
     38   1.1   briggs /*
     39   1.1   briggs  * Sandpoint-specific code developed
     40   1.1   briggs  * by Allen Briggs for Wasabi Systems, Inc.
     41   1.1   briggs  *
     42   1.1   briggs  * OpenPIC code derived from code with the following notice.
     43   1.1   briggs  */
     44   1.1   briggs /*-
     45   1.1   briggs  * Copyright (c) 2000 Tsubai Masanari.  All rights reserved.
     46   1.1   briggs  *
     47   1.1   briggs  * Redistribution and use in source and binary forms, with or without
     48   1.1   briggs  * modification, are permitted provided that the following conditions
     49   1.1   briggs  * are met:
     50   1.1   briggs  * 1. Redistributions of source code must retain the above copyright
     51   1.1   briggs  *    notice, this list of conditions and the following disclaimer.
     52   1.1   briggs  * 2. Redistributions in binary form must reproduce the above copyright
     53   1.1   briggs  *    notice, this list of conditions and the following disclaimer in the
     54   1.1   briggs  *    documentation and/or other materials provided with the distribution.
     55   1.1   briggs  * 3. The name of the author may not be used to endorse or promote products
     56   1.1   briggs  *    derived from this software without specific prior written permission.
     57   1.1   briggs  *
     58   1.1   briggs  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     59   1.1   briggs  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     60   1.1   briggs  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     61   1.1   briggs  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     62   1.1   briggs  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     63   1.1   briggs  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     64   1.1   briggs  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     65   1.1   briggs  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     66   1.1   briggs  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     67   1.1   briggs  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     68   1.1   briggs  */
     69   1.1   briggs 
     70   1.1   briggs #ifndef _SANDPOINT_INTR_H_
     71   1.1   briggs #define _SANDPOINT_INTR_H_
     72   1.1   briggs 
     73   1.1   briggs /* Interrupt priority `levels'. */
     74   1.1   briggs #define	IPL_NONE	9	/* nothing */
     75   1.1   briggs #define	IPL_SOFTCLOCK	8	/* software clock interrupt */
     76   1.1   briggs #define	IPL_SOFTNET	7	/* software network interrupt */
     77   1.1   briggs #define	IPL_BIO		6	/* block I/O */
     78   1.1   briggs #define	IPL_NET		5	/* network */
     79   1.1   briggs #define	IPL_SOFTSERIAL	4	/* software serial interrupt */
     80   1.1   briggs #define	IPL_TTY		3	/* terminal */
     81   1.5  thorpej #define	IPL_VM		3	/* memory allocation */
     82   1.1   briggs #define	IPL_AUDIO	2	/* audio */
     83   1.1   briggs #define	IPL_CLOCK	1	/* clock */
     84  1.11     yamt #define	IPL_STATCLOCK	IPL_CLOCK
     85   1.1   briggs #define	IPL_HIGH	1	/* everything */
     86  1.11     yamt #define	IPL_SCHED	IPL_HIGH
     87  1.11     yamt #define	IPL_LOCK	IPL_HIGH
     88   1.1   briggs #define	IPL_SERIAL	0	/* serial */
     89   1.1   briggs #define	NIPL		10
     90   1.1   briggs 
     91   1.1   briggs /* Interrupt sharing types. */
     92   1.1   briggs #define	IST_NONE	0	/* none */
     93   1.1   briggs #define	IST_PULSE	1	/* pulsed */
     94   1.1   briggs #define	IST_EDGE	2	/* edge-triggered */
     95   1.1   briggs #define	IST_LEVEL	3	/* level-triggered */
     96   1.1   briggs 
     97   1.1   briggs #ifndef _LOCORE
     98   1.6     matt #define	CLKF_BASEPRI(frame)	((frame)->pri == 0)
     99   1.1   briggs 
    100   1.1   briggs /*
    101   1.1   briggs  * Interrupt handler chains.  intr_establish() inserts a handler into
    102   1.1   briggs  * the list.  The handler is called with its (single) argument.
    103   1.1   briggs  */
    104   1.1   briggs struct intrhand {
    105   1.1   briggs 	int	(*ih_fun)(void *);
    106   1.1   briggs 	void	*ih_arg;
    107   1.1   briggs 	u_long	ih_count;
    108   1.1   briggs 	struct	intrhand *ih_next;
    109   1.1   briggs 	int	ih_level;
    110   1.1   briggs 	int	ih_irq;
    111   1.1   briggs };
    112   1.1   briggs 
    113   1.1   briggs void	do_pending_int(void);
    114   1.1   briggs void	*intr_establish(int, int, int, int (*)(void *), void *);
    115   1.1   briggs void	intr_disestablish(void *);
    116   1.1   briggs 
    117  1.10    perry static __inline int splraise(int);
    118  1.10    perry static __inline int spllower(int);
    119  1.10    perry static __inline void splx(int);
    120  1.10    perry static __inline void set_sint(int);
    121   1.1   briggs 
    122   1.1   briggs extern volatile int cpl, ipending, astpending, tickspending;
    123   1.1   briggs extern int imask[];
    124   1.1   briggs extern long intrcnt[];
    125   1.1   briggs 
    126   1.1   briggs /*
    127   1.1   briggs  * Reorder protection in the following inline functions is
    128   1.1   briggs  * protected with the "eieio" instruction.
    129   1.1   briggs  */
    130  1.10    perry static __inline int
    131   1.1   briggs splraise(newcpl)
    132   1.1   briggs 	int newcpl;
    133   1.1   briggs {
    134   1.1   briggs 	int oldcpl;
    135   1.1   briggs 
    136   1.9    perry 	__asm volatile("sync; eieio\n");	/* don't reorder.... */
    137   1.1   briggs 	oldcpl = cpl;
    138   1.1   briggs 	cpl = oldcpl | newcpl;
    139   1.9    perry 	__asm volatile("sync; eieio\n");	/* reorder protect */
    140   1.1   briggs 	return(oldcpl);
    141   1.1   briggs }
    142   1.1   briggs 
    143  1.10    perry static __inline void
    144   1.1   briggs splx(newcpl)
    145   1.1   briggs 	int newcpl;
    146   1.1   briggs {
    147   1.9    perry 	__asm volatile("sync; eieio\n");	/* reorder protect */
    148   1.1   briggs 	cpl = newcpl;
    149   1.1   briggs 	if(ipending & ~newcpl)
    150   1.1   briggs 		do_pending_int();
    151   1.9    perry 	__asm volatile("sync; eieio\n");	/* reorder protect */
    152   1.1   briggs }
    153   1.1   briggs 
    154  1.10    perry static __inline int
    155   1.1   briggs spllower(newcpl)
    156   1.1   briggs 	int newcpl;
    157   1.1   briggs {
    158   1.1   briggs 	int oldcpl;
    159   1.1   briggs 
    160   1.9    perry 	__asm volatile("sync; eieio\n");	/* reorder protect */
    161   1.1   briggs 	oldcpl = cpl;
    162   1.1   briggs 	cpl = newcpl;
    163   1.1   briggs 	if(ipending & ~newcpl)
    164   1.1   briggs 		do_pending_int();
    165   1.9    perry 	__asm volatile("sync; eieio\n");	/* reorder protect */
    166   1.1   briggs 	return(oldcpl);
    167   1.1   briggs }
    168   1.1   briggs 
    169   1.1   briggs /* Following code should be implemented with lwarx/stwcx to avoid
    170   1.1   briggs  * the disable/enable. i need to read the manual once more.... */
    171  1.10    perry static __inline void
    172   1.1   briggs set_sint(pending)
    173   1.1   briggs 	int	pending;
    174   1.1   briggs {
    175   1.1   briggs 	int	msrsave;
    176   1.1   briggs 
    177   1.9    perry 	__asm ("mfmsr %0" : "=r"(msrsave));
    178   1.9    perry 	__asm volatile ("mtmsr %0" :: "r"(msrsave & ~PSL_EE));
    179   1.1   briggs 	ipending |= pending;
    180   1.9    perry 	__asm volatile ("mtmsr %0" :: "r"(msrsave));
    181   1.1   briggs }
    182   1.1   briggs 
    183   1.1   briggs /*
    184   1.1   briggs  * Motorola SandPoint PPC eval board interrupt list
    185   1.1   briggs  */
    186   1.3   briggs #define	ICU_LEN		25
    187   1.3   briggs #define	ICU_MASK	0x01ffffff
    188   1.1   briggs 
    189   1.1   briggs #define	LEGAL_IRQ(x)	((x) >= 0 && (x) < ICU_LEN)
    190   1.1   briggs 
    191   1.1   briggs #define	SINT_ISA	0x10000000
    192   1.1   briggs #define	SINT_NET	0x20000000
    193   1.1   briggs #define	SINT_CLOCK	0x40000000
    194   1.1   briggs #define	SINT_SERIAL	0x80000000
    195   1.1   briggs #define	SPL_CLOCK	0x00000001
    196   1.1   briggs #define	SINT_MASK	(SINT_ISA|SINT_CLOCK|SINT_NET|SINT_SERIAL)
    197   1.1   briggs 
    198   1.1   briggs #define	CNT_SINT_ISA	28
    199   1.1   briggs #define	CNT_SINT_NET	29
    200   1.1   briggs #define	CNT_SINT_CLOCK	30
    201   1.1   briggs #define	CNT_SINT_SERIAL	31
    202   1.1   briggs #define	CNT_CLOCK	0
    203   1.1   briggs 
    204   1.1   briggs #define splbio()	splraise(imask[IPL_BIO])
    205   1.1   briggs #define splnet()	splraise(imask[IPL_NET])
    206   1.1   briggs #define spltty()	splraise(imask[IPL_TTY])
    207   1.1   briggs #define splclock()	splraise(imask[IPL_CLOCK])
    208   1.5  thorpej #define splvm()		splraise(imask[IPL_VM])
    209   1.1   briggs #define	splserial()	splraise(imask[IPL_SERIAL])
    210   1.1   briggs #define splstatclock()	splclock()
    211   1.1   briggs #define	spllowersoftclock() spllower(imask[IPL_SOFTCLOCK])
    212   1.1   briggs #define	splsoftclock()	splraise(imask[IPL_SOFTCLOCK])
    213   1.1   briggs #define	splsoftnet()	splraise(imask[IPL_SOFTNET])
    214   1.1   briggs #define	splsoftserial()	splraise(imask[IPL_SOFTSERIAL])
    215   1.1   briggs 
    216   1.1   briggs #define spllpt()	spltty()
    217   1.1   briggs 
    218   1.1   briggs #define	setsoftisa()	set_sint(SINT_ISA);
    219   1.1   briggs #define	setsoftclock()	set_sint(SINT_CLOCK);
    220   1.1   briggs #define	setsoftnet()	set_sint(SINT_NET);
    221   1.1   briggs #define	setsoftserial()	set_sint(SINT_SERIAL);
    222   1.1   briggs 
    223   1.1   briggs #define	splhigh()	splraise(imask[IPL_HIGH])
    224   1.1   briggs #define	spl0()		spllower(0)
    225   1.1   briggs 
    226   1.1   briggs #define splsched()	splhigh()
    227   1.1   briggs #define spllock()	splhigh()
    228   1.1   briggs 
    229  1.11     yamt typedef int ipl_t;
    230  1.11     yamt typedef struct {
    231  1.11     yamt 	ipl_t _ipl;
    232  1.11     yamt } ipl_cookie_t;
    233  1.11     yamt 
    234  1.11     yamt static inline ipl_cookie_t
    235  1.11     yamt makeiplcookie(ipl_t ipl)
    236  1.11     yamt {
    237  1.11     yamt 
    238  1.11     yamt 	return (ipl_cookie_t){._ipl = ipl};
    239  1.11     yamt }
    240  1.11     yamt 
    241  1.11     yamt static inline int
    242  1.11     yamt splraiseipl(ipl_cookie_t icookie)
    243  1.11     yamt {
    244  1.11     yamt 
    245  1.11     yamt 	return splraise(imask[icookie._ipl]);
    246  1.11     yamt }
    247  1.11     yamt 
    248   1.1   briggs #endif /* !_LOCORE */
    249   1.1   briggs 
    250   1.1   briggs #endif /* !_SANDPOINT_INTR_H_ */
    251