intr.h revision 1.25
1/*	$NetBSD: intr.h,v 1.25 2007/02/16 02:53:48 ad 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
70/* watch out for side effects */
71#define splx(s)         ((s) & PSL_IPL ? _spl(s) : spl0())
72
73#define	IPL_NONE	MAC68K_IPL_NONE
74#define	IPL_SOFTCLOCK	MAC68K_IPL_SOFT
75#define	IPL_SOFTNET	MAC68K_IPL_SOFT
76#define	IPL_BIO		MAC68K_IPL_BIO
77#define	IPL_NET		MAC68K_IPL_NET
78#define	IPL_TTY		MAC68K_IPL_TTY
79#define	IPL_VM		MAC68K_IPL_IMP
80#define	IPL_AUDIO	MAC68K_IPL_AUDIO
81#define	IPL_CLOCK	MAC68K_IPL_CLOCK
82#define	IPL_STATCLOCK	MAC68K_IPL_STATCLOCK
83#define	IPL_SCHED	MAC68K_IPL_SCHED
84#define	IPL_HIGH	MAC68K_IPL_HIGH
85#define	IPL_LOCK	MAC68K_IPL_HIGH
86#define	IPL_SERIAL	MAC68K_IPL_SERIAL
87
88typedef int ipl_t;
89typedef struct {
90	ipl_t _ipl;
91} ipl_cookie_t;
92
93static inline ipl_cookie_t
94makeiplcookie(ipl_t ipl)
95{
96
97	return (ipl_cookie_t){._ipl = ipl};
98}
99
100static inline int
101splraiseipl(ipl_cookie_t icookie)
102{
103
104	return _splraise(mac68k_ipls[icookie._ipl]);
105}
106
107#include <sys/spl.h>
108
109/*
110 * simulated software interrupt register
111 */
112extern volatile u_int8_t ssir;
113
114#define	SIR_NET		0x01
115#define	SIR_CLOCK	0x02
116#define	SIR_SERIAL	0x04
117#define SIR_DTMGR	0x08
118#define SIR_ADB		0x10
119
120#define	siron(mask)	\
121	__asm volatile ( "orb %1,%0" : "=m" (ssir) : "i" (mask))
122#define	siroff(mask)	\
123	__asm volatile ( "andb %1,%0" : "=m" (ssir) : "ir" (~(mask)));
124
125#define	setsoftnet()	siron(SIR_NET)
126#define	setsoftclock()	siron(SIR_CLOCK)
127#define	setsoftserial()	siron(SIR_SERIAL)
128#define	setsoftdtmgr()	siron(SIR_DTMGR)
129#define	setsoftadb()	siron(SIR_ADB)
130
131/* intr.c */
132void	intr_init(void);
133void	intr_establish(int (*)(void *), void *, int);
134void	intr_disestablish(int);
135void	intr_dispatch(int);
136
137/* locore.s */
138int	spl0(void);
139#endif /* _KERNEL */
140
141#endif /* _MAC68K_INTR_H_ */
142