xref: /netbsd/sys/arch/atari/include/intr.h (revision 6550d01e)
1 /*	$NetBSD: intr.h,v 1.21 2009/07/08 12:23:10 tsutsui Exp $	*/
2 
3 /*-
4  * Copyright (c) 1996, 1997, 2007 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Leo Weppelman.
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  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _ATARI_INTR_H_
33 #define _ATARI_INTR_H_
34 
35 #define	IPL_NONE	0		    /* disable no interrupts	    */
36 #define	IPL_SOFTCLOCK	1
37 #define	IPL_SOFTBIO	2
38 #define	IPL_SOFTNET	3
39 #define	IPL_SOFTSERIAL	4
40 #define	IPL_VM		5
41 #define	IPL_SCHED	6
42 #define	IPL_HIGH	7
43 #define	NIPL		8
44 
45 #define	IST_UNUSABLE	-1	/* interrupt cannot be used	*/
46 #define	IST_NONE	0	/* none (dummy)			*/
47 #define	IST_PULSE	1	/* pulsed			*/
48 #define	IST_EDGE	2	/* edge-triggered		*/
49 #define	IST_LEVEL	3	/* level-triggered		*/
50 
51 /*
52  * spl functions; all but spl0 are done in-line
53  */
54 #include <machine/psl.h>
55 
56 /* spl0 requires checking for software interrupts */
57 
58 #define splsoftclock()		splraise1()
59 #define splsoftbio()		splraise1()
60 #define splsoftnet()		splraise1()
61 #define splsoftserial()		splraise1()
62 #define splvm()			splraise4()
63 #define splsched()		splraise6()
64 #define splhigh()		spl7()
65 #define splx(s)			((s) & PSL_IPL ? _spl(s) : spl0())
66 
67 #ifdef _KERNEL
68 int spl0(void);
69 
70 extern const uint16_t ipl2psl_table[NIPL];
71 extern int idepth;
72 
73 typedef int ipl_t;
74 typedef struct {
75 	uint16_t _psl;
76 } ipl_cookie_t;
77 
78 static inline ipl_cookie_t
79 makeiplcookie(ipl_t ipl)
80 {
81 
82 	return (ipl_cookie_t){._psl = ipl2psl_table[ipl]};
83 }
84 
85 static inline int
86 splraiseipl(ipl_cookie_t icookie)
87 {
88 
89 	return _splraise(icookie._psl);
90 }
91 
92 #include <sys/queue.h>
93 #include <machine/cpu.h>	/* XXX: for clockframe */
94 
95 struct clockframe;
96 
97 #define	AUTO_VEC	0x0001	/* We're dealing with an auto-vector	*/
98 #define	USER_VEC	0x0002	/* We're dealing with an user-vector	*/
99 
100 #define	FAST_VEC	0x0010	/* Fast, stash right into vector-table	*/
101 #define	ARG_CLOCKFRAME	0x0020	/* Supply clockframe as an argument	*/
102 
103 /*
104  * Interrupt handler chains.  intr_establish() inserts a handler into
105  * the list.  The handler is called with its (single) argument or with a
106  * 'standard' clockframe. This depends on 'ih_type'.
107  */
108 typedef int	(*hw_ifun_t)(void *, int);
109 
110 struct intrhand {
111 	LIST_ENTRY(intrhand)	ih_link;
112 	hw_ifun_t		ih_fun;
113 	void			*ih_arg;
114 	int			ih_type;
115 	int			ih_pri;
116 	int			ih_vector;
117 	u_long			*ih_intrcnt;
118 };
119 
120 void		intr_init(void);
121 struct intrhand *intr_establish(int, int, int, hw_ifun_t, void *);
122 int		intr_disestablish(struct intrhand *);
123 void		intr_dispatch(struct clockframe);
124 void		intr_glue(void);
125 
126 /*
127  * Exported by intrcnt.h
128  */
129 extern u_long	autovects[];
130 extern u_long	intrcnt_auto[];
131 extern u_long	uservects[];
132 extern u_long	intrcnt_user[];
133 
134 #endif /* _KERNEL */
135 
136 #endif /* _ATARI_INTR_H_ */
137