Home | History | Annotate | Line # | Download | only in footbridge
footbridge_intr.h revision 1.2
      1 /* 	$NetBSD: footbridge_intr.h,v 1.2 2002/11/03 21:43:31 chris Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997 Mark Brinicombe.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by Mark Brinicombe
     18  *	for the NetBSD Project.
     19  * 4. The name of the company nor the name of the author may be used to
     20  *    endorse or promote products derived from this software without specific
     21  *    prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     24  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     27  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  */
     35 
     36 #ifndef _FOOTBRIDGE_INTR_H_
     37 #define _FOOTBRIDGE_INTR_H_
     38 
     39 #include <arm/armreg.h>
     40 
     41 /* Define the various Interrupt Priority Levels */
     42 
     43 /* Hardware Interrupt Priority Levels are not mutually exclusive. */
     44 
     45 #define IPL_NONE	0	/* nothing */
     46 #define IPL_SOFT	1	/* generic soft interrupts */
     47 #define IPL_SOFTCLOCK	2	/* clock software interrupts */
     48 #define IPL_SOFTNET	3	/* network software interrupts */
     49 #define IPL_BIO		4	/* block I/O */
     50 #define IPL_NET		5	/* network */
     51 #define IPL_SOFTSERIAL	6	/* serial software interrupts */
     52 #define IPL_TTY		7	/* terminal */
     53 #define IPL_IMP		8	/* memory allocation */
     54 #define IPL_AUDIO	9	/* audio */
     55 #define IPL_CLOCK	10	/* clock */
     56 #define IPL_STATCLOCK	11	/* statclock */
     57 #define IPL_HIGH	12	/* everything */
     58 #define IPL_SERIAL	13	/* serial */
     59 
     60 #define NIPL		14
     61 
     62 #define	IST_UNUSABLE	-1	/* interrupt cannot be used */
     63 #define	IST_NONE	0	/* none (dummy) */
     64 #define	IST_PULSE	1	/* pulsed */
     65 #define	IST_EDGE	2	/* edge-triggered */
     66 #define	IST_LEVEL	3	/* level-triggered */
     67 
     68 #define	__NEWINTR	/* enables new hooks in cpu_fork()/cpu_switch() */
     69 
     70 #ifndef _LOCORE
     71 #include <arm/cpufunc.h>
     72 
     73 #include <arm/footbridge/dc21285mem.h>
     74 #include <arm/footbridge/dc21285reg.h>
     75 
     76 #define INT_SWMASK							\
     77 	((1U << IRQ_SOFTINT) | (1U << IRQ_RESERVED0) |			\
     78 	 (1U << IRQ_RESERVED1) | (1U << IRQ_RESERVED2))
     79 #define ICU_INT_HWMASK	(0xffffffff & ~(INT_SWMASK |  (1U << IRQ_RESERVED3)))
     80 
     81 /* only call this with interrupts off */
     82 static __inline void __attribute__((__unused__))
     83     footbridge_set_intrmask(void)
     84 {
     85     extern __volatile uint32_t intr_enabled;
     86     /* fetch once so we write the same number to both registers */
     87     uint32_t tmp = intr_enabled & ICU_INT_HWMASK;
     88 
     89     ((__volatile uint32_t*)(DC21285_ARMCSR_VBASE))[IRQ_ENABLE_SET>>2] = tmp;
     90     ((__volatile uint32_t*)(DC21285_ARMCSR_VBASE))[IRQ_ENABLE_CLEAR>>2] = ~tmp;
     91 }
     92 
     93 static __inline void __attribute__((__unused__))
     94 footbridge_splx(int newspl)
     95 {
     96 	extern __volatile uint32_t intr_enabled;
     97 	extern __volatile int current_spl_level;
     98 	extern __volatile int footbridge_ipending;
     99 	extern void footbridge_do_pending(void);
    100 	int oldirqstate, hwpend;
    101 
    102 	current_spl_level = newspl;
    103 
    104 	hwpend = (footbridge_ipending & ICU_INT_HWMASK) & ~newspl;
    105 	if (hwpend != 0) {
    106 		oldirqstate = disable_interrupts(I32_bit);
    107 		intr_enabled |= hwpend;
    108 		footbridge_set_intrmask();
    109 		restore_interrupts(oldirqstate);
    110 	}
    111 
    112 	if ((footbridge_ipending & INT_SWMASK) & ~newspl)
    113 		footbridge_do_pending();
    114 }
    115 
    116 static __inline int __attribute__((__unused__))
    117 footbridge_splraise(int ipl)
    118 {
    119 	extern __volatile int current_spl_level;
    120 	extern int footbridge_imask[];
    121 	int	old;
    122 
    123 	old = current_spl_level;
    124 	current_spl_level |= footbridge_imask[ipl];
    125 
    126 	return (old);
    127 }
    128 
    129 static __inline int __attribute__((__unused__))
    130 footbridge_spllower(int ipl)
    131 {
    132 	extern __volatile int current_spl_level;
    133 	extern int footbridge_imask[];
    134 	int old = current_spl_level;
    135 
    136 	footbridge_splx(footbridge_imask[ipl]);
    137 	return(old);
    138 }
    139 
    140 /* should only be defined in footbridge_intr.c */
    141 #if !defined(ARM_SPL_NOINLINE)
    142 
    143 #define splx(newspl)		footbridge_splx(newspl)
    144 #define	_spllower(ipl)		footbridge_spllower(ipl)
    145 #define	_splraise(ipl)		footbridge_splraise(ipl)
    146 void	_setsoftintr(int);
    147 
    148 #else
    149 
    150 int	_splraise(int);
    151 int	_spllower(int);
    152 void	splx(int);
    153 void	_setsoftintr(int);
    154 
    155 #endif /* ! ARM_SPL_NOINLINE */
    156 
    157 #include <sys/device.h>
    158 #include <sys/queue.h>
    159 #include <machine/irqhandler.h>
    160 
    161 #define	splsoft()	_splraise(IPL_SOFT)
    162 #define	splsoftclock()	_splraise(IPL_SOFTCLOCK)
    163 #define	splsoftnet()	_splraise(IPL_SOFTNET)
    164 #define	splbio()	_splraise(IPL_BIO)
    165 #define	splnet()	_splraise(IPL_NET)
    166 #define splsoftserial()	_splraise(IPL_SOFTSERIAL)
    167 #define	spltty()	_splraise(IPL_TTY)
    168 #define spllpt()        spltty()
    169 #define	splvm()		_splraise(IPL_IMP)
    170 #define	splaudio()	_splraise(IPL_AUDIO)
    171 #define	splclock()	_splraise(IPL_CLOCK)
    172 #define	splstatclock()	_splraise(IPL_STATCLOCK)
    173 #define	splhigh()	_splraise(IPL_HIGH)
    174 #define	splserial()	_splraise(IPL_SERIAL)
    175 
    176 #define	spl0()		(void)_spllower(IPL_NONE)
    177 #define	spllowersoftclock() (void)_spllower(IPL_SOFTCLOCK)
    178 
    179 #define	splsched()	splhigh()
    180 #define	spllock()	splhigh()
    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