intr.h revision 1.5
11.5Sad/*	$NetBSD: intr.h,v 1.5 2007/12/03 15:34:31 ad Exp $	*/
21.1Sober
31.1Sober/*
41.1Sober * Copyright (c) 2001, 2003 Wasabi Systems, Inc.
51.1Sober * All rights reserved.
61.1Sober *
71.1Sober * Written by Jason R. Thorpe for Wasabi Systems, Inc.
81.1Sober *
91.1Sober * Redistribution and use in source and binary forms, with or without
101.1Sober * modification, are permitted provided that the following conditions
111.1Sober * are met:
121.1Sober * 1. Redistributions of source code must retain the above copyright
131.1Sober *    notice, this list of conditions and the following disclaimer.
141.1Sober * 2. Redistributions in binary form must reproduce the above copyright
151.1Sober *    notice, this list of conditions and the following disclaimer in the
161.1Sober *    documentation and/or other materials provided with the distribution.
171.1Sober * 3. All advertising materials mentioning features or use of this software
181.1Sober *    must display the following acknowledgement:
191.1Sober *	This product includes software developed for the NetBSD Project by
201.1Sober *	Wasabi Systems, Inc.
211.1Sober * 4. The name of Wasabi Systems, Inc. may not be used to endorse
221.1Sober *    or promote products derived from this software without specific prior
231.1Sober *    written permission.
241.1Sober *
251.1Sober * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
261.1Sober * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
271.1Sober * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
281.1Sober * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
291.1Sober * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
301.1Sober * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
311.1Sober * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
321.1Sober * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
331.1Sober * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
341.1Sober * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
351.1Sober * POSSIBILITY OF SUCH DAMAGE.
361.1Sober */
371.1Sober
381.1Sober#ifndef	_ZAURUS_INTR_H_
391.1Sober#define	_ZAURUS_INTR_H_
401.1Sober
411.1Sober#ifdef _KERNEL
421.1Sober
431.1Sober/* Interrupt priority "levels". */
441.1Sober#define	IPL_NONE	0	/* nothing */
451.5Sad#define	IPL_SOFTCLOCK	1	/* timeouts */
461.5Sad#define	IPL_SOFTBIO	2	/* block I/O */
471.1Sober#define	IPL_SOFTNET	3	/* software network interrupt */
481.5Sad#define	IPL_SOFTSERIAL	4	/* software serial interrupt */
491.5Sad#define	IPL_VM		5	/* memory allocation */
501.5Sad#define	IPL_SCHED	6	/* clock interrupt */
511.5Sad#define	IPL_HIGH	7	/* everything */
521.1Sober
531.5Sad#define	NIPL		8
541.1Sober
551.1Sober/* Interrupt sharing types. */
561.1Sober#define	IST_NONE	0	/* none */
571.1Sober#define	IST_PULSE	1	/* pulsed */
581.1Sober#define	IST_EDGE	2	/* edge-triggered */
591.1Sober#define	IST_LEVEL	3	/* level-triggered */
601.1Sober
611.1Sober#define IST_LEVEL_LOW	 IST_LEVEL
621.1Sober#define IST_LEVEL_HIGH   4
631.1Sober#define IST_EDGE_FALLING IST_EDGE
641.1Sober#define IST_EDGE_RISING  5
651.1Sober#define IST_EDGE_BOTH    6
661.1Sober
671.1Sober#ifdef __OLD_INTERRUPT_CODE	/* XXX XXX XXX */
681.1Sober
691.1Sober/* Software interrupt priority levels */
701.1Sober
711.1Sober#define SOFTIRQ_CLOCK   0
721.1Sober#define SOFTIRQ_NET     1
731.1Sober#define SOFTIRQ_SERIAL  2
741.1Sober
751.1Sober#define SOFTIRQ_BIT(x)  (1 << x)
761.1Sober
771.1Sober#include <arm/arm32/psl.h>
781.1Sober
791.1Sober#else /* ! __OLD_INTERRUPT_CODE */
801.1Sober
811.1Sober#define	__NEWINTR	/* enables new hooks in cpu_fork()/cpu_switch() */
821.1Sober
831.1Sober#ifndef _LOCORE
841.1Sober
851.1Sober#include <sys/device.h>
861.1Sober#include <sys/queue.h>
871.1Sober
881.1Sober#if defined(_LKM)
891.1Sober
901.1Soberint	_splraise(int);
911.1Soberint	_spllower(int);
921.1Sobervoid	splx(int);
931.1Sobervoid	_setsoftintr(int);
941.1Sober
951.1Sober#else	/* _LKM */
961.1Sober
971.1Sober#include "opt_arm_intr_impl.h"
981.1Sober
991.1Sober#if defined(ARM_INTR_IMPL)
1001.1Sober
1011.1Sober/*
1021.1Sober * Each board needs to define the following functions:
1031.1Sober *
1041.1Sober * int	_splraise(int);
1051.1Sober * int	_spllower(int);
1061.1Sober * void	splx(int);
1071.1Sober * void	_setsoftintr(int);
1081.1Sober *
1091.1Sober * These may be defined as functions, static inline functions, or macros,
1101.1Sober * but there must be a _spllower() and splx() defined as functions callable
1111.1Sober * from assembly language (for cpu_switch()).  However, since it's quite
1121.1Sober * useful to be able to inline splx(), you could do something like the
1131.1Sober * following:
1141.1Sober *
1151.1Sober * in <boardtype>_intr.h:
1161.1Sober * 	static inline int
1171.1Sober *	boardtype_splx(int spl)
1181.1Sober *	{...}
1191.1Sober *
1201.1Sober *	#define splx(nspl)	boardtype_splx(nspl)
1211.1Sober *	...
1221.1Sober * and in boardtype's machdep code:
1231.1Sober *
1241.1Sober *	...
1251.1Sober *	#undef splx
1261.1Sober *	int
1271.1Sober *	splx(int spl)
1281.1Sober *	{
1291.1Sober *		return boardtype_splx(spl);
1301.1Sober *	}
1311.1Sober */
1321.1Sober
1331.1Sober#include ARM_INTR_IMPL
1341.1Sober
1351.1Sober#else /* ARM_INTR_IMPL */
1361.1Sober
1371.1Sober#error ARM_INTR_IMPL not defined.
1381.1Sober
1391.1Sober#endif	/* ARM_INTR_IMPL */
1401.1Sober
1411.1Sober#endif /* _LKM */
1421.1Sober
1431.1Sober#define	splsoft()	_splraise(IPL_SOFT)
1441.2Syamt
1451.4Sthorpejtypedef uint8_t ipl_t;
1461.2Syamttypedef struct {
1471.2Syamt	ipl_t _ipl;
1481.2Syamt} ipl_cookie_t;
1491.2Syamt
1501.2Syamtstatic inline ipl_cookie_t
1511.2Syamtmakeiplcookie(ipl_t ipl)
1521.2Syamt{
1531.2Syamt
1541.2Syamt	return (ipl_cookie_t){._ipl = ipl};
1551.2Syamt}
1561.2Syamt
1571.2Syamtstatic inline int
1581.2Syamtsplraiseipl(ipl_cookie_t icookie)
1591.2Syamt{
1601.2Syamt
1611.2Syamt	return _splraise(icookie._ipl);
1621.2Syamt}
1631.1Sober
1641.1Sober#define	spl0()		_spllower(IPL_NONE)
1651.1Sober
1661.1Sober#include <sys/spl.h>
1671.1Sober
1681.1Sober/* Use generic software interrupt support. */
1691.1Sober#include <arm/softintr.h>
1701.1Sober
1711.1Sober#endif /* ! _LOCORE */
1721.1Sober
1731.1Sober#endif /* __OLD_INTERRUPT_CODE */
1741.1Sober
1751.1Sober#endif /* _KERNEL */
1761.1Sober
1771.1Sober#endif	/* _ZAURUS_INTR_H_ */
178