intr.h revision 1.24
1/*	$NetBSD: intr.h,v 1.24 2006/12/21 15:55:23 yamt Exp $	*/
2
3/*
4 * Copyright (C) 1997 Scott Reynolds
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 *    derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef _MAC68K_INTR_H_
31#define _MAC68K_INTR_H_
32
33#include <machine/psl.h>
34
35#ifdef _KERNEL
36
37/* spl0 requires checking for software interrupts */
38
39/*
40 * This array contains the appropriate PSL_S|PSL_IPL? values
41 * to raise interrupt priority to the requested level.
42 */
43extern unsigned short mac68k_ipls[];
44
45#define	MAC68K_IPL_NONE		0
46#define	MAC68K_IPL_SOFT		1
47#define	MAC68K_IPL_BIO		2
48#define	MAC68K_IPL_NET		3
49#define	MAC68K_IPL_TTY		4
50#define	MAC68K_IPL_IMP		5
51#define	MAC68K_IPL_AUDIO	6
52#define	MAC68K_IPL_SERIAL	7
53#define	MAC68K_IPL_ADB		8
54#define	MAC68K_IPL_CLOCK	9
55#define	MAC68K_IPL_STATCLOCK	10
56#define	MAC68K_IPL_SCHED	11
57#define	MAC68K_IPL_HIGH		12
58#define	MAC68K_NIPLS		13
59
60/* These spl calls are _not_ to be used by machine-independent code. */
61#define	spladb()	_splraise(mac68k_ipls[MAC68K_IPL_ADB])
62#define	splzs()		splserial()
63
64/*
65 * These should be used for:
66 * 1) ensuring mutual exclusion (why use processor level?)
67 * 2) allowing faster devices to take priority
68 */
69#define	spllowersoftclock() spl1()
70
71/* watch out for side effects */
72#define splx(s)         ((s) & PSL_IPL ? _spl(s) : spl0())
73
74#define	IPL_NONE	MAC68K_IPL_NONE
75#define	IPL_SOFTCLOCK	MAC68K_IPL_SOFT
76#define	IPL_SOFTNET	MAC68K_IPL_SOFT
77#define	IPL_BIO		MAC68K_IPL_BIO
78#define	IPL_NET		MAC68K_IPL_NET
79#define	IPL_TTY		MAC68K_IPL_TTY
80#define	IPL_VM		MAC68K_IPL_IMP
81#define	IPL_AUDIO	MAC68K_IPL_AUDIO
82#define	IPL_CLOCK	MAC68K_IPL_CLOCK
83#define	IPL_STATCLOCK	MAC68K_IPL_STATCLOCK
84#define	IPL_SCHED	MAC68K_IPL_SCHED
85#define	IPL_HIGH	MAC68K_IPL_HIGH
86#define	IPL_LOCK	MAC68K_IPL_HIGH
87#define	IPL_SERIAL	MAC68K_IPL_SERIAL
88
89typedef int ipl_t;
90typedef struct {
91	ipl_t _ipl;
92} ipl_cookie_t;
93
94static inline ipl_cookie_t
95makeiplcookie(ipl_t ipl)
96{
97
98	return (ipl_cookie_t){._ipl = ipl};
99}
100
101static inline int
102splraiseipl(ipl_cookie_t icookie)
103{
104
105	return _splraise(mac68k_ipls[icookie._ipl]);
106}
107
108#include <sys/spl.h>
109
110/*
111 * simulated software interrupt register
112 */
113extern volatile u_int8_t ssir;
114
115#define	SIR_NET		0x01
116#define	SIR_CLOCK	0x02
117#define	SIR_SERIAL	0x04
118#define SIR_DTMGR	0x08
119#define SIR_ADB		0x10
120
121#define	siron(mask)	\
122	__asm volatile ( "orb %1,%0" : "=m" (ssir) : "i" (mask))
123#define	siroff(mask)	\
124	__asm volatile ( "andb %1,%0" : "=m" (ssir) : "ir" (~(mask)));
125
126#define	setsoftnet()	siron(SIR_NET)
127#define	setsoftclock()	siron(SIR_CLOCK)
128#define	setsoftserial()	siron(SIR_SERIAL)
129#define	setsoftdtmgr()	siron(SIR_DTMGR)
130#define	setsoftadb()	siron(SIR_ADB)
131
132/* intr.c */
133void	intr_init(void);
134void	intr_establish(int (*)(void *), void *, int);
135void	intr_disestablish(int);
136void	intr_dispatch(int);
137
138/* locore.s */
139int	spl0(void);
140#endif /* _KERNEL */
141
142#endif /* _MAC68K_INTR_H_ */
143