Home | History | Annotate | Line # | Download | only in footbridge
footbridge_intr.h revision 1.8
      1 /* 	$NetBSD: footbridge_intr.h,v 1.8 2006/04/16 23:31:54 chris Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2001, 2002 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 _FOOTBRIDGE_INTR_H_
     39 #define _FOOTBRIDGE_INTR_H_
     40 
     41 #include <arm/armreg.h>
     42 
     43 /* Define the various Interrupt Priority Levels */
     44 
     45 /* Hardware Interrupt Priority Levels are not mutually exclusive. */
     46 
     47 #define IPL_NONE	0	/* nothing */
     48 #define IPL_SOFT	1	/* generic soft interrupts */
     49 #define IPL_SOFTCLOCK	2	/* clock software interrupts */
     50 #define IPL_SOFTNET	3	/* network software interrupts */
     51 #define IPL_BIO		4	/* block I/O */
     52 #define IPL_NET		5	/* network */
     53 #define IPL_SOFTSERIAL	6	/* serial software interrupts */
     54 #define IPL_TTY		7	/* terminal */
     55 #define	IPL_LPT		IPL_TTY
     56 #define IPL_VM		8	/* memory allocation */
     57 #define IPL_AUDIO	9	/* audio */
     58 #define IPL_CLOCK	10	/* clock */
     59 #define IPL_STATCLOCK	11	/* statclock */
     60 #define IPL_HIGH	12	/* everything */
     61 #define	IPL_SCHED	IPL_HIGH
     62 #define	IPL_LOCK	IPL_HIGH
     63 #define IPL_SERIAL	13	/* serial */
     64 
     65 #define NIPL		14
     66 
     67 #define	IST_UNUSABLE	-1	/* interrupt cannot be used */
     68 #define	IST_NONE	0	/* none (dummy) */
     69 #define	IST_PULSE	1	/* pulsed */
     70 #define	IST_EDGE	2	/* edge-triggered */
     71 #define	IST_LEVEL	3	/* level-triggered */
     72 
     73 #define	__NEWINTR	/* enables new hooks in cpu_fork()/cpu_switch() */
     74 
     75 #define	ARM_IRQ_HANDLER	_C_LABEL(footbridge_intr_dispatch)
     76 
     77 #ifndef _LOCORE
     78 #include <arm/cpufunc.h>
     79 
     80 #include <arm/footbridge/dc21285mem.h>
     81 #include <arm/footbridge/dc21285reg.h>
     82 
     83 #define INT_SWMASK							\
     84 	((1U << IRQ_SOFTINT) | (1U << IRQ_RESERVED0) |			\
     85 	 (1U << IRQ_RESERVED1) | (1U << IRQ_RESERVED2))
     86 #define ICU_INT_HWMASK	(0xffffffff & ~(INT_SWMASK |  (1U << IRQ_RESERVED3)))
     87 
     88 /* only call this with interrupts off */
     89 static inline void __attribute__((__unused__))
     90     footbridge_set_intrmask(void)
     91 {
     92     extern volatile uint32_t intr_enabled;
     93     /* fetch once so we write the same number to both registers */
     94     uint32_t tmp = intr_enabled & ICU_INT_HWMASK;
     95 
     96     ((volatile uint32_t*)(DC21285_ARMCSR_VBASE))[IRQ_ENABLE_SET>>2] = tmp;
     97     ((volatile uint32_t*)(DC21285_ARMCSR_VBASE))[IRQ_ENABLE_CLEAR>>2] = ~tmp;
     98 }
     99 
    100 static inline void __attribute__((__unused__))
    101 footbridge_splx(int newspl)
    102 {
    103 	extern volatile uint32_t intr_enabled;
    104 	extern volatile int current_spl_level;
    105 	extern volatile int footbridge_ipending;
    106 	extern void footbridge_do_pending(void);
    107 	int oldirqstate, hwpend;
    108 
    109 	/* Don't let the compiler re-order this code with preceding code */
    110 	__insn_barrier();
    111 
    112 	current_spl_level = newspl;
    113 
    114 	hwpend = (footbridge_ipending & ICU_INT_HWMASK) & ~newspl;
    115 	if (hwpend != 0) {
    116 		oldirqstate = disable_interrupts(I32_bit);
    117 		intr_enabled |= hwpend;
    118 		footbridge_set_intrmask();
    119 		restore_interrupts(oldirqstate);
    120 	}
    121 
    122 	if ((footbridge_ipending & INT_SWMASK) & ~newspl)
    123 		footbridge_do_pending();
    124 }
    125 
    126 static inline int __attribute__((__unused__))
    127 footbridge_splraise(int ipl)
    128 {
    129 	extern volatile int current_spl_level;
    130 	extern int footbridge_imask[];
    131 	int	old;
    132 
    133 	old = current_spl_level;
    134 	current_spl_level |= footbridge_imask[ipl];
    135 
    136 	/* Don't let the compiler re-order this code with subsequent code */
    137 	__insn_barrier();
    138 
    139 	return (old);
    140 }
    141 
    142 static inline int __attribute__((__unused__))
    143 footbridge_spllower(int ipl)
    144 {
    145 	extern volatile int current_spl_level;
    146 	extern int footbridge_imask[];
    147 	int old = current_spl_level;
    148 
    149 	footbridge_splx(footbridge_imask[ipl]);
    150 	return(old);
    151 }
    152 
    153 /* should only be defined in footbridge_intr.c */
    154 #if !defined(ARM_SPL_NOINLINE)
    155 
    156 #define splx(newspl)		footbridge_splx(newspl)
    157 #define	_spllower(ipl)		footbridge_spllower(ipl)
    158 #define	_splraise(ipl)		footbridge_splraise(ipl)
    159 void	_setsoftintr(int);
    160 
    161 #else
    162 
    163 int	_splraise(int);
    164 int	_spllower(int);
    165 void	splx(int);
    166 void	_setsoftintr(int);
    167 
    168 #endif /* ! ARM_SPL_NOINLINE */
    169 
    170 #include <sys/device.h>
    171 #include <sys/queue.h>
    172 #include <machine/irqhandler.h>
    173 
    174 #define	splsoft()	_splraise(IPL_SOFT)
    175 #define	splraiseipl(x)	_splraise(x)
    176 
    177 #define	spl0()		(void)_spllower(IPL_NONE)
    178 #define	spllowersoftclock() (void)_spllower(IPL_SOFTCLOCK)
    179 
    180 #include <sys/spl.h>
    181 
    182 /* Use generic software interrupt support. */
    183 #include <arm/softintr.h>
    184 
    185 /* footbridge has 32 interrupt lines */
    186 #define	NIRQ		32
    187 
    188 struct intrhand {
    189 	TAILQ_ENTRY(intrhand) ih_list;	/* link on intrq list */
    190 	int (*ih_func)(void *);		/* handler */
    191 	void *ih_arg;			/* arg for handler */
    192 	int ih_ipl;			/* IPL_* */
    193 	int ih_irq;			/* IRQ number */
    194 };
    195 
    196 #define	IRQNAMESIZE	sizeof("footbridge irq 31")
    197 
    198 struct intrq {
    199 	TAILQ_HEAD(, intrhand) iq_list;	/* handler list */
    200 	struct evcnt iq_ev;		/* event counter */
    201 	int iq_mask;			/* IRQs to mask while handling */
    202 	int iq_levels;			/* IPL_*'s this IRQ has */
    203 	int iq_ist;			/* share type */
    204 	char iq_name[IRQNAMESIZE];	/* interrupt name */
    205 };
    206 
    207 #endif /* _LOCORE */
    208 
    209 #endif	/* _FOOTBRIDGE_INTR_H */
    210