11.33Sthorpej/*	$NetBSD: intr.h,v 1.33 2024/02/28 13:05:40 thorpej Exp $	*/
21.2Sscottr
31.2Sscottr/*
41.2Sscottr * Copyright (C) 1997 Scott Reynolds
51.2Sscottr * All rights reserved.
61.2Sscottr *
71.2Sscottr * Redistribution and use in source and binary forms, with or without
81.2Sscottr * modification, are permitted provided that the following conditions
91.2Sscottr * are met:
101.2Sscottr * 1. Redistributions of source code must retain the above copyright
111.2Sscottr *    notice, this list of conditions and the following disclaimer.
121.2Sscottr * 2. Redistributions in binary form must reproduce the above copyright
131.2Sscottr *    notice, this list of conditions and the following disclaimer in the
141.2Sscottr *    documentation and/or other materials provided with the distribution.
151.6Sscottr * 3. The name of the author may not be used to endorse or promote products
161.2Sscottr *    derived from this software without specific prior written permission.
171.2Sscottr *
181.2Sscottr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
191.2Sscottr * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
201.2Sscottr * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
211.2Sscottr * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
221.2Sscottr * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
231.2Sscottr * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
241.2Sscottr * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
251.2Sscottr * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
261.2Sscottr * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
271.2Sscottr * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
281.2Sscottr */
291.1Sscottr
301.1Sscottr#ifndef _MAC68K_INTR_H_
311.1Sscottr#define _MAC68K_INTR_H_
321.1Sscottr
331.16Sthorpej#include <machine/psl.h>
341.16Sthorpej
351.32Sriastrad#if defined(_KERNEL) || defined(_KMEMUSER)
361.32Sriastradtypedef struct {
371.32Sriastrad	uint16_t _ipl;
381.32Sriastrad} ipl_cookie_t;
391.32Sriastrad#endif
401.32Sriastrad
411.1Sscottr#ifdef _KERNEL
421.1Sscottr
431.1Sscottr/* spl0 requires checking for software interrupts */
441.1Sscottr
451.26Stsutsui#define	IPL_NONE	0
461.26Stsutsui#define	IPL_SOFTCLOCK	1
471.28Sad#define	IPL_SOFTBIO	2
481.28Sad#define	IPL_SOFTNET	3
491.28Sad#define	IPL_SOFTSERIAL	4
501.28Sad#define	IPL_VM		5
511.28Sad#define	IPL_SCHED	6
521.28Sad#define	IPL_HIGH	7
531.28Sad#define	NIPL		8
541.15Sthorpej
551.30Stsutsui/*
561.30Stsutsui * This array contains the appropriate PSL_S|PSL_IPL? values
571.30Stsutsui * to raise interrupt priority to the requested level.
581.30Stsutsui */
591.30Stsutsuiextern uint16_t ipl2psl_table[NIPL];
601.30Stsutsui
611.4Sscottr/* These spl calls are _not_ to be used by machine-independent code. */
621.4Sscottr#define	splzs()		splserial()
631.7Sbriggs
641.7Sbriggs/*
651.1Sscottr * These should be used for:
661.1Sscottr * 1) ensuring mutual exclusion (why use processor level?)
671.1Sscottr * 2) allowing faster devices to take priority
681.1Sscottr */
691.1Sscottr
701.1Sscottr/* watch out for side effects */
711.1Sscottr#define splx(s)         ((s) & PSL_IPL ? _spl(s) : spl0())
721.1Sscottr
731.22Syamt
741.24Syamttypedef int ipl_t;
751.24Syamt
761.24Syamtstatic inline ipl_cookie_t
771.24Syamtmakeiplcookie(ipl_t ipl)
781.24Syamt{
791.24Syamt
801.31Stsutsui	return (ipl_cookie_t){._ipl = ipl};
811.24Syamt}
821.24Syamt
831.24Syamtstatic inline int
841.24Syamtsplraiseipl(ipl_cookie_t icookie)
851.24Syamt{
861.24Syamt
871.31Stsutsui	return _splraise(ipl2psl_table[icookie._ipl]);
881.24Syamt}
891.22Syamt
901.22Syamt#include <sys/spl.h>
911.22Syamt
921.9Sscottr/* intr.c */
931.33Sthorpejstruct clockframe;
941.21Schsvoid	intr_init(void);
951.21Schsvoid	intr_establish(int (*)(void *), void *, int);
961.21Schsvoid	intr_disestablish(int);
971.33Sthorpejvoid	intr_dispatch(struct clockframe);
981.1Sscottr
991.1Sscottr/* locore.s */
1001.21Schsint	spl0(void);
1011.1Sscottr#endif /* _KERNEL */
1021.1Sscottr
1031.1Sscottr#endif /* _MAC68K_INTR_H_ */
104