intr.h revision 1.19
1/* $NetBSD: intr.h,v 1.19 2008/01/06 01:37:58 matt Exp $ */ 2 3/* 4 * Copyright (c) 2001, 2003 Wasabi Systems, Inc. 5 * All rights reserved. 6 * 7 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed for the NetBSD Project by 20 * Wasabi Systems, Inc. 21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22 * or promote products derived from this software without specific prior 23 * written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38#ifndef _EVBARM_INTR_H_ 39#define _EVBARM_INTR_H_ 40 41#ifdef _KERNEL 42 43/* Interrupt priority "levels". */ 44#ifdef __HAVE_FAST_SOFTINTS 45#define IPL_NONE 0 /* nothing */ 46#define IPL_SOFTCLOCK 1 /* clock */ 47#define IPL_SOFTBIO 2 /* block I/O */ 48#define IPL_SOFTNET 3 /* software network interrupt */ 49#define IPL_SOFTSERIAL 4 /* software serial interrupt */ 50#define IPL_VM 5 /* memory allocation */ 51#define IPL_SCHED 6 /* clock interrupt */ 52#define IPL_HIGH 7 /* everything */ 53 54#define NIPL 8 55#else 56#define IPL_NONE 0 /* nothing */ 57#define IPL_SOFTCLOCK IPL_NONE /* clock */ 58#define IPL_SOFTBIO IPL_NONE /* block I/O */ 59#define IPL_SOFTNET IPL_NONE /* software network interrupt */ 60#define IPL_SOFTSERIAL IPL_NONE /* software serial interrupt */ 61#define IPL_VM 1 /* memory allocation */ 62#define IPL_SCHED 2 /* clock interrupt */ 63#define IPL_HIGH 3 /* everything */ 64 65#define NIPL 4 66#endif 67 68/* Interrupt sharing types. */ 69#define IST_NONE 0 /* none */ 70#define IST_PULSE 1 /* pulsed */ 71#define IST_EDGE 2 /* edge-triggered */ 72#define IST_LEVEL 3 /* level-triggered */ 73 74#define IST_LEVEL_LOW IST_LEVEL 75#define IST_LEVEL_HIGH 4 76#define IST_EDGE_FALLING IST_EDGE 77#define IST_EDGE_RISING 5 78#define IST_EDGE_BOTH 6 79 80#ifdef __OLD_INTERRUPT_CODE /* XXX XXX XXX */ 81 82/* Software interrupt priority levels */ 83 84#ifdef __HAVE_FAST_SOFTINTS 85#define SOFTIRQ_CLOCK 0 86#define SOFTIRQ_BIO 1 87#define SOFTIRQ_NET 2 88#define SOFTIRQ_SERIAL 3 89 90#define SOFTIRQ_BIT(x) (1 << x) 91#endif 92 93#include <arm/arm32/psl.h> 94 95#else /* ! __OLD_INTERRUPT_CODE */ 96 97#define __NEWINTR /* enables new hooks in cpu_fork()/cpu_switch() */ 98 99#ifndef _LOCORE 100 101#include <sys/device.h> 102#include <sys/queue.h> 103 104#if defined(_LKM) 105 106int _splraise(int); 107int _spllower(int); 108void splx(int); 109#ifdef __HAVE_FAST_SOFTINTS 110void _setsoftintr(int); 111#endif 112 113#else /* _LKM */ 114 115#include "opt_arm_intr_impl.h" 116 117#if defined(ARM_INTR_IMPL) 118 119/* 120 * Each board needs to define the following functions: 121 * 122 * int _splraise(int); 123 * int _spllower(int); 124 * void splx(int); 125 * 126 * These may be defined as functions, static inline functions, or macros, 127 * but there must be a _spllower() and splx() defined as functions callable 128 * from assembly language (for cpu_switch()). However, since it's quite 129 * useful to be able to inline splx(), you could do something like the 130 * following: 131 * 132 * in <boardtype>_intr.h: 133 * static inline int 134 * boardtype_splx(int spl) 135 * {...} 136 * 137 * #define splx(nspl) boardtype_splx(nspl) 138 * ... 139 * and in boardtype's machdep code: 140 * 141 * ... 142 * #undef splx 143 * int 144 * splx(int spl) 145 * { 146 * return boardtype_splx(spl); 147 * } 148 */ 149 150#include ARM_INTR_IMPL 151 152#else /* ARM_INTR_IMPL */ 153 154#error ARM_INTR_IMPL not defined. 155 156#endif /* ARM_INTR_IMPL */ 157 158#endif /* _LKM */ 159 160typedef uint8_t ipl_t; 161typedef struct { 162 ipl_t _ipl; 163} ipl_cookie_t; 164 165static inline ipl_cookie_t 166makeiplcookie(ipl_t ipl) 167{ 168 169 return (ipl_cookie_t){._ipl = ipl}; 170} 171 172static inline int 173splraiseipl(ipl_cookie_t icookie) 174{ 175 176 return _splraise(icookie._ipl); 177} 178 179#define spl0() _spllower(IPL_NONE) 180 181#include <sys/spl.h> 182 183#endif /* ! _LOCORE */ 184 185#endif /* __OLD_INTERRUPT_CODE */ 186 187#endif /* _KERNEL */ 188 189#endif /* _EVBARM_INTR_H_ */ 190