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