intr.h revision 1.16
1/* $NetBSD: intr.h,v 1.16 2007/02/16 02:53:49 ad Exp $ */ 2 3/* 4 * 5 * Copyright (c) 1998 NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Minoura Makoto and Jason R. Thorpe. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by The NetBSD Foundation 22 * Inc. and its contributers. 23 * 4. The name of the author may not be used to endorse or promote products 24 * derived from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 27 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 28 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 29 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 31 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 35 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38#ifndef _NEWS68K_INTR_H_ 39#define _NEWS68K_INTR_H_ 40 41#include <sys/device.h> 42#include <sys/queue.h> 43#include <machine/psl.h> 44#include <m68k/asm_single.h> 45 46#ifdef _KERNEL 47#define IPL_NONE 0 48#define IPL_SOFTCLOCK 1 49#define IPL_SOFTNET 2 50#define IPL_SOFTSERIAL 3 51#define IPL_SOFT 4 52#define IPL_BIO 5 53#define IPL_NET 6 54#define IPL_TTY 7 55#define IPL_VM 8 56#define IPL_SERIAL 9 57#define IPL_CLOCK 10 58#define IPL_STATCLOCK IPL_CLOCK 59#define IPL_HIGH 11 60#define IPL_SCHED IPL_HIGH 61#define IPL_LOCK IPL_HIGH 62#define NIPL 12 63 64#define SI_SOFTSERIAL 0 65#define SI_SOFTNET 1 66#define SI_SOFTCLOCK 2 67#define SI_SOFT 3 68 69#define SI_NQUEUES 4 70 71#define SI_QUEUENAMES { \ 72 "serial", \ 73 "net", \ 74 "clock", \ 75 "misc", \ 76} 77 78typedef int ipl_t; 79typedef struct { 80 ipl_t _psl; 81} ipl_cookie_t; 82 83ipl_cookie_t makeiplcookie(ipl_t); 84 85static inline int 86splraiseipl(ipl_cookie_t icookie) 87{ 88 89 return _splraise(icookie._psl); 90} 91 92static __inline void 93splx(int sr) 94{ 95 96 __asm volatile("movw %0,%%sr" : : "di" (sr)); 97} 98 99/* 100 * news68k can handle software interrupts by its own hardware 101 * so has no need to check for any simulated interrupts, etc. 102 */ 103#define spl0() _spl0() 104 105#define splsoft() splraise2() 106#define splsoftclock() splsoft() 107#define splsoftnet() splsoft() 108#define splsoftserial() splsoft() 109#define splbio() splraise4() 110#define splnet() splraise4() 111#define spltty() splraise5() 112#define splvm() splraise5() 113#define splserial() splraise5() 114#define splclock() splraise6() 115#define splstatclock() splclock() 116#define splhigh() spl7() 117#define splsched() spl7() 118#define spllock() spl7() 119 120/* 121 * simulated software interrupt register 122 */ 123#define SOFTINTR_IPL 2 124extern volatile uint8_t *ctrl_int2; 125 126#define setsoft(x) (x = 0) 127#define softintr_assert() (*ctrl_int2 = 0xff) 128#define softintr_clear() (*ctrl_int2 = 0) 129 130struct news68k_soft_intrhand { 131 LIST_ENTRY(news68k_soft_intrhand) sih_q; 132 struct news68k_soft_intr *sih_intrhead; 133 void (*sih_fn)(void *); 134 void *sih_arg; 135 volatile int sih_pending; 136}; 137 138struct news68k_soft_intr { 139 LIST_HEAD(, news68k_soft_intrhand) nsi_q; 140 struct evcnt nsi_evcnt; 141 volatile unsigned char nsi_ssir; 142}; 143 144void *softintr_establish(int, void (*)(void *), void *); 145void softintr_disestablish(void *); 146void softintr_init(void); 147void softintr_dispatch(void); 148 149#define softintr_schedule(arg) \ 150 do { \ 151 struct news68k_soft_intrhand *__sih = (arg); \ 152 __sih->sih_pending = 1; \ 153 setsoft(__sih->sih_intrhead->nsi_ssir); \ 154 softintr_assert(); \ 155 } while (/*CONSTCOND*/ 0) 156 157/* XXX For legacy software interrupts */ 158extern struct news68k_soft_intrhand *softnet_intrhand; 159 160#define setsoftnet() softintr_schedule(softnet_intrhand) 161 162#endif /* _KERNEL */ 163 164#endif /* _NEWS68K_INTR_H_ */ 165