/* * Copyright (c) 2006 Jon Sevy * All rights reserved. * * Based on code by Jason R. Thorpe * * Copyright (c) 2002 Wasabi Systems, Inc. * All rights reserved. * * Written by Jason R. Thorpe for Wasabi Systems, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: *This product includes software developed for the NetBSD Project by *Wasabi Systems, Inc. * 4. The name of Wasabi Systems, Inc. may not be used to endorse * or promote products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef _VX115_INTR_H_ #define _VX115_INTR_H_ #define ARM_IRQ_HANDLER _C_LABEL(vx115_irq_dispatcher) #ifndef _LOCORE #include #include #include #include #include #include #include #include typedef int (* vx115_irq_handler_t)(void *); #define NR_IRQS 32 #define VALID_IRQ(i) ((i!=24) && (i!=27) && (isc_iot, vx115_pic_sc->sc_ioh, offset) #define vx115_write_pic(offset, value) bus_space_write_4(vx115_pic_sc->sc_iot, vx115_pic_sc->sc_ioh, offset, value) /* * Utility function for interrupt handler. */ static __inline int find_first_bit( uint32_t bits ) { int count; /* CLZ is available only on ARMv5 */ asm( "clz %0, %1" : "=r" (count) : "r" (bits) ); return 31-count; } static __inline void vx115_setipl(int new) { current_spl_level = new; /* enable hardware interrupts appropriate to current spl level */ vx115_write_pic(PIC_ENABLE_SET, vx115_pic_spl_mask[current_spl_level]); /* clear hardware interrupts not appropriate to current spl level */ vx115_write_pic(PIC_ENABLE_CLEAR, ~vx115_pic_spl_mask[current_spl_level]); } static __inline void vx115_splx(int new) { int psw; psw = disable_interrupts(I32_bit); vx115_setipl(new); restore_interrupts(psw); /* if there are software interrupts pending, process */ if (softint_pending & vx115_pic_spl_soft_mask[current_spl_level]) vx115_do_pending(); } static __inline int vx115_splraise(int ipl) { int old, psw; psw = disable_interrupts(I32_bit); old = current_spl_level; if( ipl > old ) vx115_setipl(ipl); restore_interrupts(psw); return (old); } static __inline int vx115_spllower(int ipl) { int old, psw; psw = disable_interrupts(I32_bit); old = current_spl_level; if( ipl < old ) vx115_setipl(ipl); restore_interrupts(psw); /* if there are software interrupts pending, process */ if (softint_pending & vx115_pic_spl_soft_mask[current_spl_level]) vx115_do_pending(); return(old); } static __inline void vx115_setsoftintr(int si) { atomic_set_bit( (u_int *)&softint_pending, SI_TO_IRQBIT(si) ); /* Process unmasked pending soft interrupts. */ if ( softint_pending & vx115_pic_spl_soft_mask[current_spl_level] ) vx115_do_pending(); } int _splraise(int); int _spllower(int); void splx(int); void _setsoftintr(int); #if !defined(EVBARM_SPL_NOINLINE) #define splx(new) vx115_splx(new) #define _spllower(ipl) vx115_spllower(ipl) #define _splraise(ipl) vx115_splraise(ipl) #define _setsoftintr(si) vx115_setsoftintr(si) #endif /* !EVBARM_SPL_NOINTR */ /* * This function *MUST* be called very early on in a port's * initarm() function, before ANY spl*() functions are called. * * The parameters are the virtual address of the Vx115's Interrupt * Controller registers and the size of the reg region. */ void vx115_intr_bootstrap(bus_addr_t addr, bus_size_t size); void vx115_irq_dispatcher(void *); void *vx115_intr_establish(int irqno, int level, int (*func)(void *), void *cookie); void vx115_update_intr_masks(int irqno, int level); #define VX115_INT_DISABLED (unsigned int)0x00000000 #define VX115_INT_ENABLED (unsigned int)0x00000001 #define VX115_INT_SENSE_LEVEL (unsigned int)0x00000000 #define VX115_INT_SENSE_EDGE (unsigned int)0x00000002 #define VX115_INT_POLARITY_LOW (unsigned int)0x00000000 #define VX115_INT_POLARITY_HIGH (unsigned int)0x00000004 #define VX115_INT_POLARITY_HIGH_LOW (unsigned int)0x00000000 #define VX115_INT_POLARITY_LOW_HIGH (unsigned int)0x00000004 int vx115_configure_irq(unsigned int irq, unsigned int sense, unsigned int polarity); void vx115_enable_irq(unsigned int irq); void vx115_disable_irq(unsigned int irq); #endif /* ! _LOCORE */ #endif /* _VX115_INTR_H_ */