intr.h revision 1.4
11.4Sthorpej/*	$NetBSD: intr.h,v 1.4 2007/03/09 06:45:20 thorpej 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.1Sober#define	IPL_SOFT	1	/* generic software interrupts */
461.1Sober#define	IPL_SOFTCLOCK	2	/* software clock interrupt */
471.1Sober#define	IPL_SOFTNET	3	/* software network interrupt */
481.1Sober#define	IPL_BIO		4	/* block I/O */
491.1Sober#define	IPL_NET		5	/* network */
501.1Sober#define	IPL_SOFTSERIAL	6	/* software serial interrupt */
511.1Sober#define	IPL_TTY		7	/* terminals */
521.1Sober#define	IPL_VM		8	/* memory allocation */
531.1Sober#define	IPL_AUDIO	9	/* audio device */
541.1Sober#define	IPL_CLOCK	10	/* clock interrupt */
551.1Sober#define	IPL_STATCLOCK	11	/* statistics clock interrupt */
561.1Sober#define	IPL_HIGH	12	/* everything */
571.1Sober#define	IPL_SCHED	IPL_HIGH
581.1Sober#define	IPL_LOCK	IPL_HIGH
591.1Sober#define	IPL_SERIAL	13	/* serial device */
601.1Sober
611.1Sober#define	NIPL		14
621.1Sober
631.1Sober/* Interrupt sharing types. */
641.1Sober#define	IST_NONE	0	/* none */
651.1Sober#define	IST_PULSE	1	/* pulsed */
661.1Sober#define	IST_EDGE	2	/* edge-triggered */
671.1Sober#define	IST_LEVEL	3	/* level-triggered */
681.1Sober
691.1Sober#define IST_LEVEL_LOW	 IST_LEVEL
701.1Sober#define IST_LEVEL_HIGH   4
711.1Sober#define IST_EDGE_FALLING IST_EDGE
721.1Sober#define IST_EDGE_RISING  5
731.1Sober#define IST_EDGE_BOTH    6
741.1Sober
751.1Sober#ifdef __OLD_INTERRUPT_CODE	/* XXX XXX XXX */
761.1Sober
771.1Sober/* Software interrupt priority levels */
781.1Sober
791.1Sober#define SOFTIRQ_CLOCK   0
801.1Sober#define SOFTIRQ_NET     1
811.1Sober#define SOFTIRQ_SERIAL  2
821.1Sober
831.1Sober#define SOFTIRQ_BIT(x)  (1 << x)
841.1Sober
851.1Sober#include <arm/arm32/psl.h>
861.1Sober
871.1Sober#else /* ! __OLD_INTERRUPT_CODE */
881.1Sober
891.1Sober#define	__NEWINTR	/* enables new hooks in cpu_fork()/cpu_switch() */
901.1Sober
911.1Sober#ifndef _LOCORE
921.1Sober
931.1Sober#include <sys/device.h>
941.1Sober#include <sys/queue.h>
951.1Sober
961.1Sober#if defined(_LKM)
971.1Sober
981.1Soberint	_splraise(int);
991.1Soberint	_spllower(int);
1001.1Sobervoid	splx(int);
1011.1Sobervoid	_setsoftintr(int);
1021.1Sober
1031.1Sober#else	/* _LKM */
1041.1Sober
1051.1Sober#include "opt_arm_intr_impl.h"
1061.1Sober
1071.1Sober#if defined(ARM_INTR_IMPL)
1081.1Sober
1091.1Sober/*
1101.1Sober * Each board needs to define the following functions:
1111.1Sober *
1121.1Sober * int	_splraise(int);
1131.1Sober * int	_spllower(int);
1141.1Sober * void	splx(int);
1151.1Sober * void	_setsoftintr(int);
1161.1Sober *
1171.1Sober * These may be defined as functions, static inline functions, or macros,
1181.1Sober * but there must be a _spllower() and splx() defined as functions callable
1191.1Sober * from assembly language (for cpu_switch()).  However, since it's quite
1201.1Sober * useful to be able to inline splx(), you could do something like the
1211.1Sober * following:
1221.1Sober *
1231.1Sober * in <boardtype>_intr.h:
1241.1Sober * 	static inline int
1251.1Sober *	boardtype_splx(int spl)
1261.1Sober *	{...}
1271.1Sober *
1281.1Sober *	#define splx(nspl)	boardtype_splx(nspl)
1291.1Sober *	...
1301.1Sober * and in boardtype's machdep code:
1311.1Sober *
1321.1Sober *	...
1331.1Sober *	#undef splx
1341.1Sober *	int
1351.1Sober *	splx(int spl)
1361.1Sober *	{
1371.1Sober *		return boardtype_splx(spl);
1381.1Sober *	}
1391.1Sober */
1401.1Sober
1411.1Sober#include ARM_INTR_IMPL
1421.1Sober
1431.1Sober#else /* ARM_INTR_IMPL */
1441.1Sober
1451.1Sober#error ARM_INTR_IMPL not defined.
1461.1Sober
1471.1Sober#endif	/* ARM_INTR_IMPL */
1481.1Sober
1491.1Sober#endif /* _LKM */
1501.1Sober
1511.1Sober#define	splsoft()	_splraise(IPL_SOFT)
1521.2Syamt
1531.4Sthorpejtypedef uint8_t ipl_t;
1541.2Syamttypedef struct {
1551.2Syamt	ipl_t _ipl;
1561.2Syamt} ipl_cookie_t;
1571.2Syamt
1581.2Syamtstatic inline ipl_cookie_t
1591.2Syamtmakeiplcookie(ipl_t ipl)
1601.2Syamt{
1611.2Syamt
1621.2Syamt	return (ipl_cookie_t){._ipl = ipl};
1631.2Syamt}
1641.2Syamt
1651.2Syamtstatic inline int
1661.2Syamtsplraiseipl(ipl_cookie_t icookie)
1671.2Syamt{
1681.2Syamt
1691.2Syamt	return _splraise(icookie._ipl);
1701.2Syamt}
1711.1Sober
1721.1Sober#define	spl0()		_spllower(IPL_NONE)
1731.1Sober
1741.1Sober#include <sys/spl.h>
1751.1Sober
1761.1Sober/* Use generic software interrupt support. */
1771.1Sober#include <arm/softintr.h>
1781.1Sober
1791.1Sober#endif /* ! _LOCORE */
1801.1Sober
1811.1Sober#endif /* __OLD_INTERRUPT_CODE */
1821.1Sober
1831.1Sober#endif /* _KERNEL */
1841.1Sober
1851.1Sober#endif	/* _ZAURUS_INTR_H_ */
186