intr.h revision 1.15
1/*	$NetBSD: intr.h,v 1.15 2023/07/11 10:55:02 riastradh Exp $	*/
2
3/*
4 * Copyright (c) 1988 University of Utah.
5 * Copyright (c) 1982, 1986, 1990, 1993
6 *	The Regents of the University of California.  All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * the Systems Programming Group of the University of Utah Computer
10 * Science Department.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 *    notice, this list of conditions and the following disclaimer in the
19 *    documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 *    may be used to endorse or promote products derived from this software
22 *    without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * from: Utah $Hdr: machparam.h 1.16 92/12/20$
37 *
38 *	from: @(#)param.h	8.1 (Berkeley) 6/10/93
39 */
40
41#ifndef _CESFIC_INTR_H_
42#define _CESFIC_INTR_H_
43
44/*
45 * spl functions; all but spl0 are done in-line
46 */
47#include <machine/psl.h>
48
49#if (defined(_KERNEL) || defined(_KMEMUSER)) && !defined(_LOCORE)
50
51typedef struct {
52	uint16_t _psl;
53} ipl_cookie_t;
54
55#endif
56
57#if defined(_KERNEL) && !defined(_LOCORE)
58/* spl0 requires checking for software interrupts */
59#define spl1()  _spl(PSL_S|PSL_IPL1)
60#define spl2()  _spl(PSL_S|PSL_IPL2)
61#define spl3()  _spl(PSL_S|PSL_IPL3)
62#define spl4()  _spl(PSL_S|PSL_IPL4)
63#define spl5()  _spl(PSL_S|PSL_IPL5)
64#define spl6()  _spl(PSL_S|PSL_IPL6)
65#define spl7()  _spl(PSL_S|PSL_IPL7)
66
67/* These spl calls are used by machine-independent code. */
68#define splsoftclock()	splraise1()
69#define splsoftbio()	splraise1()
70#define splsoftnet()	splraise1()
71#define splsoftserial()	splraise1()
72#define splvm()		splraise4()
73#define splsched()	spl6()
74#define splhigh()	spl7()
75
76/* watch out for side effects */
77#define splx(s)         (s & PSL_IPL ? _spl(s) : spl0())
78
79int	spl0(void);
80
81#define	IPL_NONE	0
82#define	IPL_SOFTCLOCK	1
83#define	IPL_SOFTBIO	1
84#define	IPL_SOFTNET	3
85#define	IPL_SOFTSERIAL	4
86#define	IPL_VM		5
87#define	IPL_SCHED	6
88#define	IPL_HIGH	7
89#define	NIPL		8
90
91extern const uint16_t ipl2psl_table[NIPL];
92
93typedef int ipl_t;
94
95static inline ipl_cookie_t
96makeiplcookie(ipl_t ipl)
97{
98
99	return (ipl_cookie_t){._psl = ipl2psl_table[ipl]};
100}
101
102static inline int
103splraiseipl(ipl_cookie_t icookie)
104{
105
106	return _splraise(icookie._psl);
107}
108
109#endif /* _KERNEL && !_LOCORE */
110
111#endif /* !_CESFIC_INTR_H_ */
112