intr.h revision 1.28
11.28Sriastrad/*	$NetBSD: intr.h,v 1.28 2023/07/11 11:09:13 riastradh Exp $	*/
21.1Stsutsui
31.21Stsutsui/*-
41.21Stsutsui * Copyright (c) 1998 The NetBSD Foundation, Inc.
51.1Stsutsui * All rights reserved.
61.1Stsutsui *
71.1Stsutsui * This code is derived from software contributed to The NetBSD Foundation
81.1Stsutsui * by Minoura Makoto and Jason R. Thorpe.
91.1Stsutsui *
101.1Stsutsui * Redistribution and use in source and binary forms, with or without
111.1Stsutsui * modification, are permitted provided that the following conditions
121.1Stsutsui * are met:
131.1Stsutsui * 1. Redistributions of source code must retain the above copyright
141.1Stsutsui *    notice, this list of conditions and the following disclaimer.
151.1Stsutsui * 2. Redistributions in binary form must reproduce the above copyright
161.1Stsutsui *    notice, this list of conditions and the following disclaimer in the
171.1Stsutsui *    documentation and/or other materials provided with the distribution.
181.1Stsutsui *
191.21Stsutsui * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.21Stsutsui * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.21Stsutsui * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.21Stsutsui * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.21Stsutsui * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.21Stsutsui * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.21Stsutsui * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.21Stsutsui * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.21Stsutsui * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.21Stsutsui * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.21Stsutsui * POSSIBILITY OF SUCH DAMAGE.
301.1Stsutsui */
311.1Stsutsui
321.1Stsutsui#ifndef _NEWS68K_INTR_H_
331.1Stsutsui#define	_NEWS68K_INTR_H_
341.1Stsutsui
351.28Sriastrad#include <sys/types.h>
361.28Sriastrad
371.25Stsutsui#include <sys/evcnt.h>
381.14Stsutsui#include <sys/queue.h>
391.28Sriastrad#include <sys/stdbool.h>
401.28Sriastrad
411.1Stsutsui#include <machine/psl.h>
421.28Sriastrad
431.5Stsutsui#include <m68k/asm_single.h>
441.1Stsutsui
451.13Syamt#define	IPL_NONE	0
461.14Stsutsui#define	IPL_SOFTCLOCK	1
471.19Sad#define	IPL_SOFTBIO	2
481.19Sad#define	IPL_SOFTNET	3
491.19Sad#define	IPL_SOFTSERIAL	4
501.19Sad#define	IPL_VM		5
511.19Sad#define	IPL_SCHED	6
521.22Stsutsui#define	IPL_HIGH	7
531.22Stsutsui#define	NIPL		8
541.13Syamt
551.20Stsutsuiextern int idepth;
561.23Stsutsui
571.27Schristosstatic __inline bool
581.23Stsutsuicpu_intr_p(void)
591.23Stsutsui{
601.23Stsutsui
611.23Stsutsui	return idepth != 0;
621.26Stsutsui}
631.26Stsutsui
641.22Stsutsuiextern const uint16_t ipl2psl_table[NIPL];
651.20Stsutsui
661.13Syamttypedef int ipl_t;
671.13Syamttypedef struct {
681.18Sthorpej	uint16_t _psl;
691.13Syamt} ipl_cookie_t;
701.13Syamt
711.28Sriastrad#ifdef _KERNEL
721.28Sriastrad
731.27Schristosstatic __inline ipl_cookie_t
741.22Stsutsuimakeiplcookie(ipl_t ipl)
751.22Stsutsui{
761.22Stsutsui
771.22Stsutsui	return (ipl_cookie_t){._psl = ipl2psl_table[ipl]};
781.22Stsutsui}
791.13Syamt
801.27Schristosstatic __inline int
811.13Syamtsplraiseipl(ipl_cookie_t icookie)
821.13Syamt{
831.13Syamt
841.14Stsutsui	return _splraise(icookie._psl);
851.13Syamt}
861.13Syamt
871.27Schristosstatic __inline void
881.9Stsutsuisplx(int sr)
891.9Stsutsui{
901.9Stsutsui
911.11Sperry	__asm volatile("movw %0,%%sr" : : "di" (sr));
921.9Stsutsui}
931.1Stsutsui
941.1Stsutsui/*
951.14Stsutsui * news68k can handle software interrupts by its own hardware
961.14Stsutsui * so has no need to check for any simulated interrupts, etc.
971.14Stsutsui */
981.14Stsutsui#define	spl0()		_spl0()
991.14Stsutsui
1001.19Sad#define	splsoftbio()	splraise2()
1011.19Sad#define	splsoftclock()	splraise2()
1021.19Sad#define	splsoftnet()	splraise2()
1031.19Sad#define	splsoftserial()	splraise2()
1041.14Stsutsui#define	splvm()		splraise5()
1051.14Stsutsui#define	splhigh()	spl7()
1061.14Stsutsui#define	splsched()	spl7()
1071.1Stsutsui
1081.28Sriastrad#endif
1091.28Sriastrad
1101.1Stsutsui#endif /* _NEWS68K_INTR_H_ */
111