11.22Schristos/* 	$NetBSD: intr.h,v 1.22 2021/06/05 21:24:17 christos Exp $	*/
21.1Sichiro
31.1Sichiro/*
41.1Sichiro * Copyright (c) 1997 Mark Brinicombe.
51.1Sichiro * All rights reserved.
61.1Sichiro *
71.1Sichiro * Redistribution and use in source and binary forms, with or without
81.1Sichiro * modification, are permitted provided that the following conditions
91.1Sichiro * are met:
101.1Sichiro * 1. Redistributions of source code must retain the above copyright
111.1Sichiro *    notice, this list of conditions and the following disclaimer.
121.1Sichiro * 2. Redistributions in binary form must reproduce the above copyright
131.1Sichiro *    notice, this list of conditions and the following disclaimer in the
141.1Sichiro *    documentation and/or other materials provided with the distribution.
151.1Sichiro * 3. All advertising materials mentioning features or use of this software
161.1Sichiro *    must display the following acknowledgement:
171.1Sichiro *	This product includes software developed by Mark Brinicombe
181.1Sichiro *	for the NetBSD Project.
191.1Sichiro * 4. The name of the company nor the name of the author may be used to
201.1Sichiro *    endorse or promote products derived from this software without specific
211.1Sichiro *    prior written permission.
221.1Sichiro *
231.1Sichiro * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
241.1Sichiro * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
251.1Sichiro * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
261.1Sichiro * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
271.1Sichiro * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
281.1Sichiro * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
291.1Sichiro * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
301.1Sichiro * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
311.1Sichiro * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
321.1Sichiro * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
331.1Sichiro * SUCH DAMAGE.
341.1Sichiro */
351.1Sichiro
361.3Stoshii#ifndef _HPCARM_INTR_H_
371.3Stoshii#define _HPCARM_INTR_H_
381.1Sichiro
391.13Snonaka#ifdef _KERNEL
401.13Snonaka
411.12Smatt#define IPL_NONE	0
421.12Smatt#define IPL_SOFTCLOCK	1
431.12Smatt#define IPL_SOFTBIO	2
441.12Smatt#define IPL_SOFTNET	3
451.12Smatt#define IPL_SOFTSERIAL	4
461.12Smatt#define IPL_VM		5
471.12Smatt#define IPL_SCHED	6
481.12Smatt#define IPL_HIGH	7
491.1Sichiro
501.11Sad#define NIPL		8
511.1Sichiro
521.1Sichiro#define	IST_UNUSABLE	-1	/* interrupt cannot be used */
531.1Sichiro#define	IST_NONE	0	/* none (dummy) */
541.1Sichiro#define	IST_PULSE	1	/* pulsed */
551.1Sichiro#define	IST_EDGE	2	/* edge-triggered */
561.1Sichiro#define	IST_LEVEL	3	/* level-triggered */
571.1Sichiro
581.13Snonaka#define	IST_LEVEL_LOW	IST_LEVEL
591.13Snonaka#define	IST_LEVEL_HIGH	4
601.13Snonaka#define	IST_EDGE_FALLING IST_EDGE
611.13Snonaka#define	IST_EDGE_RISING	5
621.13Snonaka#define	IST_EDGE_BOTH	6
631.13Snonaka
641.13Snonaka#ifdef __OLD_INTERRUPT_CODE	/* XXX XXX XXX */
651.13Snonaka
661.1Sichiro#include <machine/irqhandler.h>
671.6Sthorpej#include <arm/arm32/psl.h>
681.4Stoshii
691.13Snonaka#else	/* !__OLD_INTERRUPT_CODE */
701.13Snonaka
711.13Snonaka#ifndef _LOCORE
721.13Snonaka
731.13Snonaka#include <sys/queue.h>
741.13Snonaka
751.21Sskrll#if defined(_MODULE)
761.21Sskrll
771.21Sskrllint	_splraise(int);
781.21Sskrllint	_spllower(int);
791.21Sskrllvoid	splx(int);
801.21Sskrll
811.21Sskrll#else	/* _MODULE */
821.21Sskrll
831.13Snonaka#include "opt_arm_intr_impl.h"
841.13Snonaka
851.13Snonaka#if defined(ARM_INTR_IMPL)
861.13Snonaka
871.13Snonaka/*
881.13Snonaka * Each board needs to define the following functions:
891.13Snonaka *
901.13Snonaka * int	_splraise(int);
911.13Snonaka * int	_spllower(int);
921.13Snonaka * void	splx(int);
931.13Snonaka * void	_setsoftintr(int);
941.13Snonaka *
951.13Snonaka * These may be defined as functions, static inline functions, or macros,
961.13Snonaka * but there must be a _spllower() and splx() defined as functions callable
971.13Snonaka * from assembly language (for cpu_switch()).  However, since it's quite
981.13Snonaka * useful to be able to inline splx(), you could do something like the
991.13Snonaka * following:
1001.13Snonaka *
1011.13Snonaka * in <boardtype>_intr.h:
1021.13Snonaka * 	static inline int
1031.13Snonaka *	boardtype_splx(int spl)
1041.13Snonaka *	{...}
1051.13Snonaka *
1061.13Snonaka *	#define splx(nspl)	boardtype_splx(nspl)
1071.13Snonaka *	...
1081.13Snonaka * and in boardtype's machdep code:
1091.13Snonaka *
1101.13Snonaka *	...
1111.13Snonaka *	#undef splx
1121.13Snonaka *	int
1131.13Snonaka *	splx(int spl)
1141.13Snonaka *	{
1151.13Snonaka *		return boardtype_splx(spl);
1161.13Snonaka *	}
1171.13Snonaka */
1181.13Snonaka
1191.13Snonaka#include ARM_INTR_IMPL
1201.13Snonaka
1211.13Snonaka#else	/* ARM_INTR_IMPL */
1221.13Snonaka
1231.13Snonaka#error ARM_INTR_IMPL not defined.
1241.13Snonaka
1251.13Snonaka#endif	/* ARM_INTR_IMPL */
1261.13Snonaka
1271.21Sskrll#endif /* _MODULE */
1281.21Sskrll
1291.13Snonakatypedef uint8_t ipl_t;
1301.13Snonakatypedef struct {
1311.13Snonaka	ipl_t _ipl;
1321.13Snonaka} ipl_cookie_t;
1331.13Snonaka
1341.13Snonakastatic inline ipl_cookie_t
1351.13Snonakamakeiplcookie(ipl_t ipl)
1361.13Snonaka{
1371.13Snonaka
1381.13Snonaka	return (ipl_cookie_t){._ipl = ipl};
1391.13Snonaka}
1401.13Snonaka
1411.13Snonakastatic inline int
1421.13Snonakasplraiseipl(ipl_cookie_t icookie)
1431.13Snonaka{
1441.13Snonaka
1451.13Snonaka	return _splraise(icookie._ipl);
1461.13Snonaka}
1471.13Snonaka
1481.13Snonaka#define	spl0()		_spllower(IPL_NONE)
1491.13Snonaka
1501.13Snonaka#include <sys/spl.h>
1511.13Snonaka
1521.13Snonaka#endif	/* ! _LOCORE */
1531.13Snonaka
1541.13Snonaka#endif	/* __OLD_INTERRUPT_CODE */
1551.13Snonaka
1561.13Snonaka#endif	/* _KERNEL */
1571.13Snonaka
1581.3Stoshii#endif	/* _HPCARM_INTR_H */
159