Home | History | Annotate | Line # | Download | only in s3c2xx0
s3c2xx0_intr.h revision 1.1
      1  1.1  bsh /*	$NetBSD: s3c2xx0_intr.h,v 1.1 2002/11/20 17:52:51 bsh Exp $ */
      2  1.1  bsh 
      3  1.1  bsh /*
      4  1.1  bsh  * Copyright (c) 2002 Fujitsu Component Limited
      5  1.1  bsh  * Copyright (c) 2002 Genetec Corporation
      6  1.1  bsh  * All rights reserved.
      7  1.1  bsh  *
      8  1.1  bsh  * Redistribution and use in source and binary forms, with or without
      9  1.1  bsh  * modification, are permitted provided that the following conditions
     10  1.1  bsh  * are met:
     11  1.1  bsh  * 1. Redistributions of source code must retain the above copyright
     12  1.1  bsh  *    notice, this list of conditions and the following disclaimer.
     13  1.1  bsh  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1  bsh  *    notice, this list of conditions and the following disclaimer in the
     15  1.1  bsh  *    documentation and/or other materials provided with the distribution.
     16  1.1  bsh  * 3. Neither the name of The Fujitsu Component Limited nor the name of
     17  1.1  bsh  *    Genetec corporation may not be used to endorse or promote products
     18  1.1  bsh  *    derived from this software without specific prior written permission.
     19  1.1  bsh  *
     20  1.1  bsh  * THIS SOFTWARE IS PROVIDED BY FUJITSU COMPONENT LIMITED AND GENETEC
     21  1.1  bsh  * CORPORATION ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
     22  1.1  bsh  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     23  1.1  bsh  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     24  1.1  bsh  * DISCLAIMED.  IN NO EVENT SHALL FUJITSU COMPONENT LIMITED OR GENETEC
     25  1.1  bsh  * CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     26  1.1  bsh  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     27  1.1  bsh  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
     28  1.1  bsh  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     29  1.1  bsh  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     30  1.1  bsh  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     31  1.1  bsh  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.1  bsh  * SUCH DAMAGE.
     33  1.1  bsh  */
     34  1.1  bsh 
     35  1.1  bsh /* Derived from i80321_intr.h */
     36  1.1  bsh 
     37  1.1  bsh /*
     38  1.1  bsh  * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
     39  1.1  bsh  * All rights reserved.
     40  1.1  bsh  *
     41  1.1  bsh  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
     42  1.1  bsh  *
     43  1.1  bsh  * Redistribution and use in source and binary forms, with or without
     44  1.1  bsh  * modification, are permitted provided that the following conditions
     45  1.1  bsh  * are met:
     46  1.1  bsh  * 1. Redistributions of source code must retain the above copyright
     47  1.1  bsh  *    notice, this list of conditions and the following disclaimer.
     48  1.1  bsh  * 2. Redistributions in binary form must reproduce the above copyright
     49  1.1  bsh  *    notice, this list of conditions and the following disclaimer in the
     50  1.1  bsh  *    documentation and/or other materials provided with the distribution.
     51  1.1  bsh  * 3. All advertising materials mentioning features or use of this software
     52  1.1  bsh  *    must display the following acknowledgement:
     53  1.1  bsh  *	This product includes software developed for the NetBSD Project by
     54  1.1  bsh  *	Wasabi Systems, Inc.
     55  1.1  bsh  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     56  1.1  bsh  *    or promote products derived from this software without specific prior
     57  1.1  bsh  *    written permission.
     58  1.1  bsh  *
     59  1.1  bsh  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     60  1.1  bsh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     61  1.1  bsh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     62  1.1  bsh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     63  1.1  bsh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     64  1.1  bsh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     65  1.1  bsh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     66  1.1  bsh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     67  1.1  bsh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     68  1.1  bsh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     69  1.1  bsh  * POSSIBILITY OF SUCH DAMAGE.
     70  1.1  bsh  */
     71  1.1  bsh 
     72  1.1  bsh #ifndef _S3C2XX0_INTR_H_
     73  1.1  bsh #define _S3C2XX0_INTR_H_
     74  1.1  bsh 
     75  1.1  bsh #include <arm/cpu.h>
     76  1.1  bsh #include <arm/armreg.h>
     77  1.1  bsh #include <arm/cpufunc.h>
     78  1.1  bsh #include <machine/atomic.h>
     79  1.1  bsh #include <machine/intr.h>
     80  1.1  bsh #include <arm/softintr.h>
     81  1.1  bsh 
     82  1.1  bsh #include <arm/s3c2xx0/s3c2xx0reg.h>
     83  1.1  bsh 
     84  1.1  bsh #if EVBARM_BOARDTYPE == EVBARM_BOARDTYPE_S3C2800
     85  1.1  bsh #include <arm/s3c2xx0/s3c2800reg.h>
     86  1.1  bsh 
     87  1.1  bsh /*
     88  1.1  bsh  * on S3C2800's interrupt controller, interrupt source bits 9, and 29..31 are
     89  1.1  bsh  * reserved. we map software interrupts to those unused bits.
     90  1.1  bsh  */
     91  1.1  bsh #define SI_TO_IRQBIT(si)  ((si)==SI_SOFTSERIAL? (1<<9) : (1U<<(ICU_LEN+(si))))
     92  1.1  bsh #endif
     93  1.1  bsh 
     94  1.1  bsh #if EVBARM_BOARDTYPE == EVBARM_BOARTYPE_S3C24X0
     95  1.1  bsh /*
     96  1.1  bsh  * XXX
     97  1.1  bsh  * on S3c24[10]0, we don't have unused bits in interrupt controller.
     98  1.1  bsh  * what should we do?
     99  1.1  bsh  */
    100  1.1  bsh #endif
    101  1.1  bsh 
    102  1.1  bsh typedef int (* s3c2xx0_irq_handler_t)(void *);
    103  1.1  bsh 
    104  1.1  bsh extern volatile uint32_t *s3c2xx0_intr_mask_reg;
    105  1.1  bsh 
    106  1.1  bsh extern __volatile int current_spl_level;
    107  1.1  bsh extern __volatile int intr_mask;
    108  1.1  bsh extern __volatile int softint_pending;
    109  1.1  bsh extern int s3c2xx0_imask[];
    110  1.1  bsh extern int s3c2xx0_ilevel[];
    111  1.1  bsh 
    112  1.1  bsh void s3c2xx0_do_pending(void);
    113  1.1  bsh void s3c2xx0_update_intr_masks( int, int );
    114  1.1  bsh void s3c2xx0_mask_interrupts(int);
    115  1.1  bsh void s3c2xx0_unmask_interrupts(int);
    116  1.1  bsh 
    117  1.1  bsh static __inline void
    118  1.1  bsh s3c2xx0_setipl(int new)
    119  1.1  bsh {
    120  1.1  bsh 	current_spl_level = new;
    121  1.1  bsh 	intr_mask = s3c2xx0_imask[current_spl_level];
    122  1.1  bsh 	*s3c2xx0_intr_mask_reg = intr_mask;
    123  1.1  bsh }
    124  1.1  bsh 
    125  1.1  bsh 
    126  1.1  bsh static __inline void
    127  1.1  bsh s3c2xx0_splx(int new)
    128  1.1  bsh {
    129  1.1  bsh 	int psw;
    130  1.1  bsh 
    131  1.1  bsh 	psw = disable_interrupts(I32_bit);
    132  1.1  bsh 	s3c2xx0_setipl(new);
    133  1.1  bsh 	restore_interrupts(psw);
    134  1.1  bsh 
    135  1.1  bsh 	/* If there are software interrupts to process, do it. */
    136  1.1  bsh 	if (softint_pending & intr_mask)
    137  1.1  bsh 		s3c2xx0_do_pending();
    138  1.1  bsh }
    139  1.1  bsh 
    140  1.1  bsh 
    141  1.1  bsh static __inline int
    142  1.1  bsh s3c2xx0_splraise(int ipl)
    143  1.1  bsh {
    144  1.1  bsh 	int	old, psw;
    145  1.1  bsh 
    146  1.1  bsh 	old = current_spl_level;
    147  1.1  bsh 	if( ipl > current_spl_level ){
    148  1.1  bsh 		psw = disable_interrupts(I32_bit);
    149  1.1  bsh 		s3c2xx0_setipl(ipl);
    150  1.1  bsh 		restore_interrupts(psw);
    151  1.1  bsh 	}
    152  1.1  bsh 
    153  1.1  bsh 	return (old);
    154  1.1  bsh }
    155  1.1  bsh 
    156  1.1  bsh static __inline int
    157  1.1  bsh s3c2xx0_spllower(int ipl)
    158  1.1  bsh {
    159  1.1  bsh 	int old = current_spl_level;
    160  1.1  bsh 	int psw = disable_interrupts(I32_bit);
    161  1.1  bsh 	s3c2xx0_splx(ipl);
    162  1.1  bsh 	restore_interrupts(psw);
    163  1.1  bsh 	return(old);
    164  1.1  bsh }
    165  1.1  bsh 
    166  1.1  bsh static __inline void
    167  1.1  bsh s3c2xx0_setsoftintr(int si)
    168  1.1  bsh {
    169  1.1  bsh 	atomic_set_bit( (u_int *)&softint_pending, SI_TO_IRQBIT(si) );
    170  1.1  bsh 
    171  1.1  bsh 	/* Process unmasked pending soft interrupts. */
    172  1.1  bsh 	if ( softint_pending & intr_mask )
    173  1.1  bsh 		s3c2xx0_do_pending();
    174  1.1  bsh }
    175  1.1  bsh 
    176  1.1  bsh 
    177  1.1  bsh int	_splraise(int);
    178  1.1  bsh int	_spllower(int);
    179  1.1  bsh void	splx(int);
    180  1.1  bsh void	_setsoftintr(int);
    181  1.1  bsh 
    182  1.1  bsh #if !defined(EVBARM_SPL_NOINLINE)
    183  1.1  bsh 
    184  1.1  bsh #define splx(new)		s3c2xx0_splx(new)
    185  1.1  bsh #define	_spllower(ipl)		s3c2xx0_spllower(ipl)
    186  1.1  bsh #define	_splraise(ipl)		s3c2xx0_splraise(ipl)
    187  1.1  bsh #define	_setsoftintr(si)	s3c2xx0_setsoftintr(si)
    188  1.1  bsh 
    189  1.1  bsh #endif	/* !EVBARM_SPL_NOINTR */
    190  1.1  bsh 
    191  1.1  bsh 
    192  1.1  bsh /*
    193  1.1  bsh  * interrupt dispatch table.
    194  1.1  bsh  */
    195  1.1  bsh #ifdef MULTIPLE_HANDLERS_ON_ONE_IRQ
    196  1.1  bsh struct intrhand {
    197  1.1  bsh 	TAILQ_ENTRY(intrhand) ih_list;	/* link on intrq list */
    198  1.1  bsh 	s3c2xx0_irq_handler_t ih_func;	/* handler */
    199  1.1  bsh 	void *ih_arg;			/* arg for handler */
    200  1.1  bsh };
    201  1.1  bsh #endif
    202  1.1  bsh 
    203  1.1  bsh struct s3c2xx0_intr_dispatch {
    204  1.1  bsh #ifdef MULTIPLE_HANDLERS_ON_ONE_IRQ
    205  1.1  bsh 	TAILQ_HEAD(,intrhand) list;
    206  1.1  bsh #else
    207  1.1  bsh 	s3c2xx0_irq_handler_t func;
    208  1.1  bsh #endif
    209  1.1  bsh 	void *cookie;		/* NULL for stackframe */
    210  1.1  bsh 	int level;
    211  1.1  bsh 	/* struct evbnt ev; */
    212  1.1  bsh };
    213  1.1  bsh 
    214  1.1  bsh /* used by s3c2{80,40,41}0 interrupt handler */
    215  1.1  bsh void s3c2xx0_intr_init(struct s3c2xx0_intr_dispatch *, int );
    216  1.1  bsh 
    217  1.1  bsh #endif _S3C2XX0_INTR_H_
    218  1.1  bsh 
    219