Home | History | Annotate | Line # | Download | only in xscale
pxa2x0_intr.h revision 1.10.8.1
      1 /*	$NetBSD: pxa2x0_intr.h,v 1.10.8.1 2007/04/19 01:04:21 thorpej Exp $ */
      2 
      3 /* Derived from i80321_intr.h */
      4 
      5 /*
      6  * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
      7  * All rights reserved.
      8  *
      9  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
     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 for the NetBSD Project by
     22  *	Wasabi Systems, Inc.
     23  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     24  *    or promote products derived from this software without specific prior
     25  *    written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 #ifndef _PXA2X0_INTR_H_
     41 #define _PXA2X0_INTR_H_
     42 
     43 #define	ARM_IRQ_HANDLER	_C_LABEL(pxa2x0_irq_handler)
     44 
     45 #ifndef _LOCORE
     46 
     47 #include <sys/atomic.h>
     48 
     49 #include <arm/cpu.h>
     50 #include <arm/armreg.h>
     51 #include <arm/cpufunc.h>
     52 #include <machine/intr.h>
     53 #include <arm/softintr.h>
     54 
     55 #include <arm/xscale/pxa2x0reg.h>
     56 
     57 vaddr_t pxaic_base;		/* Shared with pxa2x0_irq.S */
     58 #define read_icu(offset) (*(volatile uint32_t *)(pxaic_base + (offset)))
     59 #define write_icu(offset,value) \
     60  (*(volatile uint32_t *)(pxaic_base + (offset)) = (value))
     61 
     62 extern volatile int current_spl_level;
     63 extern volatile int intr_mask;
     64 extern volatile int softint_pending;
     65 extern int pxa2x0_imask[];
     66 void pxa2x0_do_pending(void);
     67 
     68 /*
     69  * Cotulla's integrated ICU doesn't have IRQ0..7, so
     70  * we map software interrupts to bit 0..3
     71  */
     72 #define SI_TO_IRQBIT(si)  (1U<<(si))
     73 
     74 static inline void
     75 pxa2x0_setipl(int new)
     76 {
     77 
     78 	current_spl_level = new;
     79 	intr_mask = pxa2x0_imask[current_spl_level];
     80 	write_icu(SAIPIC_MR, intr_mask);
     81 }
     82 
     83 
     84 static inline void
     85 pxa2x0_splx(int new)
     86 {
     87 	int psw;
     88 
     89 	psw = disable_interrupts(I32_bit);
     90 	pxa2x0_setipl(new);
     91 	restore_interrupts(psw);
     92 
     93 	/* If there are software interrupts to process, do it. */
     94 	if (softint_pending & intr_mask)
     95 		pxa2x0_do_pending();
     96 }
     97 
     98 
     99 static inline int
    100 pxa2x0_splraise(int ipl)
    101 {
    102 	int old, psw;
    103 
    104 	old = current_spl_level;
    105 	if (ipl > current_spl_level) {
    106 		psw = disable_interrupts(I32_bit);
    107 		pxa2x0_setipl(ipl);
    108 		restore_interrupts(psw);
    109 	}
    110 
    111 	return old;
    112 }
    113 
    114 static inline int
    115 pxa2x0_spllower(int ipl)
    116 {
    117 	int old = current_spl_level;
    118 	int psw = disable_interrupts(I32_bit);
    119 
    120 	pxa2x0_splx(ipl);
    121 	restore_interrupts(psw);
    122 	return old;
    123 }
    124 
    125 static inline void
    126 pxa2x0_setsoftintr(int si)
    127 {
    128 
    129 	atomic_or_uint((u_int *)__UNVOLATILE(&softint_pending),
    130 	    SI_TO_IRQBIT(si));
    131 
    132 	/* Process unmasked pending soft interrupts. */
    133 	if (softint_pending & intr_mask)
    134 		pxa2x0_do_pending();
    135 }
    136 
    137 
    138 /*
    139  * An useful function for interrupt handlers.
    140  * XXX: This shouldn't be here.
    141  */
    142 static inline int
    143 find_first_bit(uint32_t bits)
    144 {
    145 	int count;
    146 
    147 	/*
    148 	 * Since CLZ is available only on ARMv5, this isn't portable
    149 	 * to all ARM CPUs.  This file is for PXA2[15]0 processor.
    150 	 */
    151 	__asm( "clz %0, %1" : "=r" (count) : "r" (bits) );
    152 	return 31 - count;
    153 }
    154 
    155 
    156 int	_splraise(int);
    157 int	_spllower(int);
    158 void	splx(int);
    159 void	_setsoftintr(int);
    160 
    161 #if !defined(EVBARM_SPL_NOINLINE)
    162 
    163 #define splx(new)		pxa2x0_splx(new)
    164 #define	_spllower(ipl)		pxa2x0_spllower(ipl)
    165 #define	_splraise(ipl)		pxa2x0_splraise(ipl)
    166 #define	_setsoftintr(si)	pxa2x0_setsoftintr(si)
    167 
    168 #endif	/* !EVBARM_SPL_NOINTR */
    169 
    170 /*
    171  * This function *MUST* be called very early on in a port's
    172  * initarm() function, before ANY spl*() functions are called.
    173  *
    174  * The parameter is the virtual address of the PXA2x0's Interrupt
    175  * Controller registers.
    176  */
    177 void pxa2x0_intr_bootstrap(vaddr_t);
    178 
    179 void pxa2x0_irq_handler(void *);
    180 void *pxa2x0_intr_establish(int irqno, int level,
    181 			    int (*func)(void *), void *cookie);
    182 void pxa2x0_intr_disestablish(void *cookie);
    183 void pxa2x0_update_intr_masks(int irqno, int level);
    184 extern volatile int current_spl_level;
    185 
    186 #endif /* ! _LOCORE */
    187 
    188 #endif /* _PXA2X0_INTR_H_ */
    189