Home | History | Annotate | Line # | Download | only in include
intr.h revision 1.16
      1  1.16      yamt /*	$NetBSD: intr.h,v 1.16 2006/12/21 15:55:22 yamt Exp $	*/
      2   1.1   thorpej 
      3   1.1   thorpej /*-
      4   1.6   thorpej  * Copyright (c) 1996, 1997, 1999 The NetBSD Foundation, Inc.
      5   1.1   thorpej  * All rights reserved.
      6   1.1   thorpej  *
      7   1.1   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1   thorpej  * by Jason R. Thorpe.
      9   1.1   thorpej  *
     10   1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     11   1.1   thorpej  * modification, are permitted provided that the following conditions
     12   1.1   thorpej  * are met:
     13   1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     14   1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     15   1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     17   1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     18   1.1   thorpej  * 3. All advertising materials mentioning features or use of this software
     19   1.1   thorpej  *    must display the following acknowledgement:
     20   1.1   thorpej  *        This product includes software developed by the NetBSD
     21   1.1   thorpej  *        Foundation, Inc. and its contributors.
     22   1.1   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.1   thorpej  *    contributors may be used to endorse or promote products derived
     24   1.1   thorpej  *    from this software without specific prior written permission.
     25   1.1   thorpej  *
     26   1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.1   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.3       jtc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.3       jtc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1   thorpej  */
     38   1.1   thorpej 
     39   1.1   thorpej #ifndef _HP300_INTR_H_
     40   1.1   thorpej #define	_HP300_INTR_H_
     41   1.1   thorpej 
     42  1.12  gmcgarry #include <sys/device.h>
     43  1.12  gmcgarry #include <sys/queue.h>
     44   1.1   thorpej #include <machine/psl.h>
     45   1.1   thorpej 
     46   1.1   thorpej /*
     47   1.1   thorpej  * Interrupt "levels".  These are a more abstract representation
     48   1.1   thorpej  * of interrupt levels, and do not have the same meaning as m68k
     49  1.16      yamt  * CPU interrupt levels.  They serve the following purposes:
     50   1.1   thorpej  *
     51   1.1   thorpej  *	- properly order ISRs in the list for that CPU ipl
     52   1.1   thorpej  *	- compute CPU PSL values for the spl*() calls.
     53  1.16      yamt  *	- used to create cookie for the splraiseipl().
     54   1.1   thorpej  */
     55  1.16      yamt #define	IPL_NONE	0
     56  1.16      yamt #define	IPL_SOFTCLOCK	1
     57  1.16      yamt #define	IPL_SOFTNET	2
     58  1.16      yamt #define	IPL_SOFTSERIAL	3
     59  1.16      yamt #define	IPL_SOFT	4	/* disable all software interrupts */
     60  1.16      yamt #define	IPL_BIO		5
     61  1.16      yamt #define	IPL_NET		6
     62  1.16      yamt #define	IPL_TTY		7
     63  1.16      yamt #define	IPL_TTYNOBUF	8	/* IPL_TTY + higher ISR priority */
     64  1.16      yamt #define	IPL_VM		9
     65  1.16      yamt #define	IPL_CLOCK	10
     66  1.16      yamt #define	IPL_STATCLOCK	IPL_CLOCK
     67  1.16      yamt #define	IPL_HIGH	11
     68  1.16      yamt #define	IPL_SCHED	IPL_HIGH
     69  1.16      yamt #define	IPL_LOCK	IPL_HIGH
     70  1.16      yamt #define	NIPL		12
     71  1.16      yamt 
     72  1.16      yamt #define	_IPL_SOFTSERIAL	0	/* serial software interrupts */
     73  1.16      yamt #define	_IPL_SOFTNET	1	/* network software interrupts */
     74  1.16      yamt #define	_IPL_SOFTCLOCK	2	/* clock software interrupts */
     75  1.16      yamt #define	_IPL_SOFT	3	/* other software interrupts */
     76  1.12  gmcgarry #define	IPL_NSOFT	4
     77  1.12  gmcgarry 
     78  1.12  gmcgarry #define	IPL_SOFTNAMES {							\
     79  1.12  gmcgarry 	"serial",							\
     80  1.12  gmcgarry 	"net",								\
     81  1.12  gmcgarry 	"clock",							\
     82  1.12  gmcgarry 	"misc",								\
     83  1.12  gmcgarry }
     84  1.12  gmcgarry 
     85   1.1   thorpej /*
     86  1.16      yamt  * Convert PSL values to m68k CPU IPLs and vice-versa.
     87  1.16      yamt  * Note: CPU IPL values are different from IPL_* used by splraiseipl().
     88   1.1   thorpej  */
     89   1.1   thorpej #define	PSLTOIPL(x)	(((x) >> 8) & 0xf)
     90   1.1   thorpej #define	IPLTOPSL(x)	((((x) & 0xf) << 8) | PSL_S)
     91   1.1   thorpej 
     92   1.1   thorpej #ifdef _KERNEL
     93   1.6   thorpej 
     94  1.16      yamt extern u_short hp300_ipl2psl[];
     95  1.16      yamt 
     96  1.16      yamt typedef int ipl_t;
     97  1.16      yamt typedef struct {
     98  1.16      yamt 	int _psl;
     99  1.16      yamt } ipl_cookie_t;
    100  1.16      yamt 
    101  1.16      yamt static inline ipl_cookie_t
    102  1.16      yamt makeiplcookie(ipl_t ipl)
    103  1.16      yamt {
    104  1.16      yamt 
    105  1.16      yamt 	return (ipl_cookie_t){._psl = hp300_ipl2psl[ipl]};
    106  1.16      yamt }
    107  1.16      yamt 
    108  1.16      yamt static inline int
    109  1.16      yamt splraiseipl(ipl_cookie_t icookie)
    110  1.16      yamt {
    111  1.16      yamt 
    112  1.16      yamt 	return _splraise(icookie._psl);
    113  1.16      yamt }
    114   1.1   thorpej 
    115   1.1   thorpej /* These spl calls are _not_ to be used by machine-independent code. */
    116   1.7   thorpej #define	splhil()	splraise1()
    117   1.1   thorpej #define	splkbd()	splhil()
    118   1.1   thorpej 
    119   1.1   thorpej /* These spl calls are used by machine-independent code. */
    120  1.12  gmcgarry /* spl0 requires checking for software interrupts */
    121   1.7   thorpej #define	spllowersoftclock() spl1()
    122   1.7   thorpej #define	splsoft()	splraise1()
    123   1.7   thorpej #define	splsoftclock()	splsoft()
    124   1.7   thorpej #define	splsoftnet()	splsoft()
    125  1.16      yamt #define	splsoftserial()	splsoft()
    126  1.16      yamt #define	splbio()	_splraise(hp300_ipl2psl[IPL_BIO])
    127  1.16      yamt #define	splnet()	_splraise(hp300_ipl2psl[IPL_NET])
    128  1.16      yamt #define	spltty()	_splraise(hp300_ipl2psl[IPL_TTY])
    129  1.16      yamt #define	splserial()	_splraise(hp300_ipl2psl[IPL_TTY])
    130  1.16      yamt #define	splvm()		_splraise(hp300_ipl2psl[IPL_VM])
    131   1.1   thorpej #define	splclock()	spl6()
    132   1.6   thorpej #define	splstatclock()	splclock()
    133   1.1   thorpej #define	splhigh()	spl7()
    134   1.8   thorpej #define	splsched()	spl7()
    135   1.9   thorpej #define	spllock()	spl7()
    136   1.1   thorpej 
    137   1.1   thorpej /* watch out for side effects */
    138   1.1   thorpej #define	splx(s)		((s) & PSL_IPL ? _spl((s)) : spl0())
    139   1.1   thorpej 
    140  1.12  gmcgarry struct hp300_intrhand {
    141  1.12  gmcgarry 	LIST_ENTRY(hp300_intrhand) ih_q;
    142  1.12  gmcgarry 	int (*ih_fn)(void *);
    143  1.12  gmcgarry 	void *ih_arg;
    144  1.12  gmcgarry 	int ih_ipl;
    145  1.12  gmcgarry 	int ih_priority;
    146  1.12  gmcgarry };
    147  1.12  gmcgarry 
    148  1.12  gmcgarry struct hp300_intr {
    149  1.12  gmcgarry 	LIST_HEAD(, hp300_intrhand) hi_q;
    150  1.12  gmcgarry 	struct evcnt hi_evcnt;
    151  1.12  gmcgarry };
    152  1.12  gmcgarry 
    153   1.1   thorpej /*
    154  1.12  gmcgarry  * Software Interrupts.
    155   1.1   thorpej  */
    156   1.1   thorpej 
    157  1.12  gmcgarry struct hp300_soft_intrhand {
    158  1.12  gmcgarry 	LIST_ENTRY(hp300_soft_intrhand) sih_q;
    159  1.12  gmcgarry 	struct hp300_soft_intr *sih_intrhead;
    160  1.12  gmcgarry 	void (*sih_fn)(void *);
    161  1.12  gmcgarry 	void *sih_arg;
    162  1.12  gmcgarry 	volatile int sih_pending;
    163  1.12  gmcgarry };
    164  1.12  gmcgarry 
    165  1.12  gmcgarry struct hp300_soft_intr {
    166  1.12  gmcgarry 	LIST_HEAD(, hp300_soft_intrhand) hsi_q;
    167  1.12  gmcgarry 	struct evcnt hsi_evcnt;
    168  1.12  gmcgarry 	uint8_t hsi_ipl;
    169  1.12  gmcgarry };
    170   1.1   thorpej 
    171  1.12  gmcgarry void	*softintr_establish(int, void (*)(void *), void *);
    172  1.12  gmcgarry void	softintr_disestablish(void *);
    173  1.12  gmcgarry void	softintr_init(void);
    174  1.12  gmcgarry void	softintr_dispatch(void);
    175   1.1   thorpej 
    176  1.14   tsutsui extern volatile uint8_t ssir;
    177  1.12  gmcgarry #define setsoft(x)	ssir |= (1<<(x))
    178  1.12  gmcgarry 
    179  1.12  gmcgarry #define softintr_schedule(arg)				\
    180  1.12  gmcgarry do {							\
    181  1.12  gmcgarry 	struct hp300_soft_intrhand *__sih = (arg);	\
    182  1.12  gmcgarry 	__sih->sih_pending = 1;				\
    183  1.12  gmcgarry 	setsoft(__sih->sih_intrhead->hsi_ipl);		\
    184  1.12  gmcgarry } while (0)
    185  1.12  gmcgarry 
    186  1.12  gmcgarry /* XXX For legacy software interrupts */
    187  1.12  gmcgarry extern struct hp300_soft_intrhand *softnet_intrhand;
    188  1.12  gmcgarry #define setsoftnet()	softintr_schedule(softnet_intrhand)
    189   1.1   thorpej 
    190   1.1   thorpej /* locore.s */
    191  1.12  gmcgarry int	spl0(void);
    192   1.1   thorpej 
    193   1.1   thorpej /* intr.c */
    194  1.12  gmcgarry void	intr_init(void);
    195  1.12  gmcgarry void	*intr_establish(int (*)(void *), void *, int, int);
    196  1.12  gmcgarry void	intr_disestablish(void *);
    197  1.12  gmcgarry void	intr_dispatch(int);
    198  1.12  gmcgarry void	intr_printlevels(void);
    199  1.12  gmcgarry void	netintr(void);
    200  1.12  gmcgarry 
    201   1.1   thorpej #endif /* _KERNEL */
    202   1.1   thorpej 
    203   1.1   thorpej #endif /* _HP300_INTR_H_ */
    204