1 /* $NetBSD: intr.h,v 1.25 2024/01/19 20:55:42 thorpej 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 #if defined(_KERNEL) || defined(_KMEMUSER)
52 typedef struct {
53 uint16_t _psl;
54 } ipl_cookie_t;
55 #endif
56
57 /*
58 * spl functions; all but spl0 are done in-line
59 */
60 #include <machine/psl.h>
61
62 /* spl0 requires checking for software interrupts */
63
64 #define splsoftclock() splraise1()
65 #define splsoftbio() splraise1()
66 #define splsoftnet() splraise1()
67 #define splsoftserial() splraise1()
68 #define splvm() splraise4()
69 #define splsched() splraise6()
70 #define splhigh() spl7()
71 #define splx(s) ((s) & PSL_IPL ? _spl(s) : spl0())
72
73 #ifdef _KERNEL
74 int spl0(void);
75
76 extern const uint16_t ipl2psl_table[NIPL];
77 extern volatile unsigned int intr_depth;
78
79 typedef int ipl_t;
80
81 static inline ipl_cookie_t
makeiplcookie(ipl_t ipl)82 makeiplcookie(ipl_t ipl)
83 {
84
85 return (ipl_cookie_t){._psl = ipl2psl_table[ipl]};
86 }
87
88 static inline int
splraiseipl(ipl_cookie_t icookie)89 splraiseipl(ipl_cookie_t icookie)
90 {
91
92 return _splraise(icookie._psl);
93 }
94
95 #include <sys/queue.h>
96 #include <machine/cpu.h> /* XXX: for clockframe */
97
98 struct clockframe;
99
100 #define AUTO_VEC 0x0001 /* We're dealing with an auto-vector */
101 #define USER_VEC 0x0002 /* We're dealing with an user-vector */
102
103 #define FAST_VEC 0x0010 /* Fast, stash right into vector-table */
104 #define ARG_CLOCKFRAME 0x0020 /* Supply clockframe as an argument */
105
106 /*
107 * Interrupt handler chains. intr_establish() inserts a handler into
108 * the list. The handler is called with its (single) argument or with a
109 * 'standard' clockframe. This depends on 'ih_type'.
110 */
111 typedef int (*hw_ifun_t)(void *, int);
112
113 struct intrhand {
114 LIST_ENTRY(intrhand) ih_link;
115 hw_ifun_t ih_fun;
116 void *ih_arg;
117 int ih_type;
118 int ih_pri;
119 int ih_vector;
120 u_int *ih_intrcnt;
121 };
122
123 void intr_init(void);
124 struct intrhand *intr_establish(int, int, int, hw_ifun_t, void *);
125 int intr_disestablish(struct intrhand *);
126 void intr_dispatch(struct clockframe);
127 void intr_glue(void);
128
129 /*
130 * Exported by intrcnt.h
131 */
132 extern u_long autovects[];
133 extern u_int intrcnt_auto[];
134 extern u_long uservects[];
135 extern u_int intrcnt_user[];
136
137 #endif /* _KERNEL */
138
139 #endif /* _ATARI_INTR_H_ */
140