Home | History | Annotate | Line # | Download | only in s3c2xx0
s3c2800_intr.c revision 1.1
      1  1.1  bsh /* $NetBSD: s3c2800_intr.c,v 1.1 2002/11/20 17:52:50 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 /*
     36  1.1  bsh  * IRQ handler for Samsung S3C2800 processor.
     37  1.1  bsh  * It has integrated interrupt controller.
     38  1.1  bsh  */
     39  1.1  bsh #include <sys/param.h>
     40  1.1  bsh #include <sys/systm.h>
     41  1.1  bsh #include <sys/malloc.h>
     42  1.1  bsh #include <uvm/uvm_extern.h>
     43  1.1  bsh #include <machine/bus.h>
     44  1.1  bsh #include <machine/intr.h>
     45  1.1  bsh #include <arm/cpufunc.h>
     46  1.1  bsh 
     47  1.1  bsh #include <arm/s3c2xx0/s3c2800reg.h>
     48  1.1  bsh #include <arm/s3c2xx0/s3c2800var.h>
     49  1.1  bsh #include <arm/s3c2xx0/s3c2xx0_intr.h>
     50  1.1  bsh 
     51  1.1  bsh /*
     52  1.1  bsh  * interrupt dispatch table.
     53  1.1  bsh  */
     54  1.1  bsh 
     55  1.1  bsh struct s3c2xx0_intr_dispatch handler[ICU_LEN];
     56  1.1  bsh 
     57  1.1  bsh __volatile int softint_pending;
     58  1.1  bsh 
     59  1.1  bsh __volatile int current_spl_level;
     60  1.1  bsh __volatile int intr_mask;
     61  1.1  bsh 
     62  1.1  bsh /* interrupt masks for each level */
     63  1.1  bsh int s3c2xx0_imask[NIPL];
     64  1.1  bsh int s3c2xx0_ilevel[ICU_LEN];
     65  1.1  bsh 
     66  1.1  bsh int current_intr_depth;
     67  1.1  bsh 
     68  1.1  bsh vaddr_t intctl_base;		/* interrupt controller registers */
     69  1.1  bsh #define icreg(offset) \
     70  1.1  bsh 	(*(volatile uint32_t *)(intctl_base+(offset)))
     71  1.1  bsh 
     72  1.1  bsh /*
     73  1.1  bsh  * Map a software interrupt queue to an interrupt priority level.
     74  1.1  bsh  */
     75  1.1  bsh static const int si_to_ipl[SI_NQUEUES] = {
     76  1.1  bsh 	IPL_SOFT,		/* SI_SOFT */
     77  1.1  bsh 	IPL_SOFTCLOCK,		/* SI_SOFTCLOCK */
     78  1.1  bsh 	IPL_SOFTNET,		/* SI_SOFTNET */
     79  1.1  bsh 	IPL_SOFTSERIAL,		/* SI_SOFTSERIAL */
     80  1.1  bsh };
     81  1.1  bsh /*
     82  1.1  bsh  * called from irq_entry.
     83  1.1  bsh  */
     84  1.1  bsh void s3c2800_irq_handler(struct clockframe *);
     85  1.1  bsh void
     86  1.1  bsh s3c2800_irq_handler(struct clockframe *frame)
     87  1.1  bsh {
     88  1.1  bsh 	uint32_t irqbits;
     89  1.1  bsh 	int irqno;
     90  1.1  bsh 	int saved_spl_level;
     91  1.1  bsh 
     92  1.1  bsh 	++current_intr_depth;
     93  1.1  bsh 	saved_spl_level = current_spl_level;
     94  1.1  bsh 
     95  1.1  bsh 	/* get pending IRQs */
     96  1.1  bsh 	irqbits = icreg(INTCTL_IRQPND) & ICU_INT_HWMASK;
     97  1.1  bsh 
     98  1.1  bsh 	for (irqno = 0; irqbits; ++irqno) {
     99  1.1  bsh 		if ((irqbits & (1 << irqno)) == 0)
    100  1.1  bsh 			continue;
    101  1.1  bsh 		/* raise spl to stop interrupts of lower priorities */
    102  1.1  bsh 		if (saved_spl_level < handler[irqno].level)
    103  1.1  bsh 			s3c2xx0_setipl(handler[irqno].level);
    104  1.1  bsh 
    105  1.1  bsh 		/* clear pending bit */
    106  1.1  bsh 		icreg(INTCTL_SRCPND) = 1 << irqno;
    107  1.1  bsh #ifdef notyet
    108  1.1  bsh 		/* Enable interrupt */
    109  1.1  bsh #endif
    110  1.1  bsh 		(*handler[irqno].func) (
    111  1.1  bsh 		    handler[irqno].cookie == 0
    112  1.1  bsh 		    ? frame : handler[irqno].cookie);
    113  1.1  bsh #ifdef notyet
    114  1.1  bsh 		/* Disable interrupt */
    115  1.1  bsh #endif
    116  1.1  bsh 
    117  1.1  bsh 		irqbits &= ~(1 << irqno);
    118  1.1  bsh 	}
    119  1.1  bsh 
    120  1.1  bsh 	/* restore spl to that was when this interrupt happen */
    121  1.1  bsh 	s3c2xx0_setipl(saved_spl_level);
    122  1.1  bsh 
    123  1.1  bsh 	if (softint_pending & intr_mask)
    124  1.1  bsh 		s3c2xx0_do_pending();
    125  1.1  bsh 
    126  1.1  bsh 	--current_intr_depth;
    127  1.1  bsh }
    128  1.1  bsh 
    129  1.1  bsh 
    130  1.1  bsh void *
    131  1.1  bsh s3c2800_intr_establish(int irqno, int level,
    132  1.1  bsh     int (* func) (void *), void *cookie)
    133  1.1  bsh {
    134  1.1  bsh 	int save;
    135  1.1  bsh 
    136  1.1  bsh 	if (irqno < 0 || irqno >= ICU_LEN)
    137  1.1  bsh 		panic("intr_establish: bogus irq or type");
    138  1.1  bsh 
    139  1.1  bsh 	save = disable_interrupts(I32_bit);
    140  1.1  bsh 
    141  1.1  bsh 	handler[irqno].cookie = cookie;
    142  1.1  bsh 	handler[irqno].func = func;
    143  1.1  bsh 	handler[irqno].level = level;
    144  1.1  bsh 
    145  1.1  bsh 	s3c2xx0_update_intr_masks(irqno, level);
    146  1.1  bsh 
    147  1.1  bsh 	intr_mask = s3c2xx0_imask[current_spl_level];
    148  1.1  bsh 	*s3c2xx0_intr_mask_reg = intr_mask;
    149  1.1  bsh 
    150  1.1  bsh 	restore_interrupts(save);
    151  1.1  bsh 
    152  1.1  bsh 	return (&handler[irqno]);
    153  1.1  bsh }
    154  1.1  bsh 
    155  1.1  bsh 
    156  1.1  bsh void
    157  1.1  bsh s3c2800_intr_init(struct s3c2800_softc *sc)
    158  1.1  bsh {
    159  1.1  bsh 	intctl_base = (vaddr_t) bus_space_vaddr(sc->sc_sx.sc_iot,
    160  1.1  bsh 	    sc->sc_sx.sc_intctl_ioh);
    161  1.1  bsh 
    162  1.1  bsh 	s3c2xx0_intr_mask_reg = (uint32_t *)(intctl_base + INTCTL_INTMSK);
    163  1.1  bsh 
    164  1.1  bsh 	/* clear all pending interrupt */
    165  1.1  bsh 	icreg(INTCTL_SRCPND) = 0xffffffff;
    166  1.1  bsh 
    167  1.1  bsh 	s3c2xx0_intr_init(handler, ICU_LEN);
    168  1.1  bsh }
    169