Home | History | Annotate | Line # | Download | only in ixp12x0
ixp12x0_intr.c revision 1.17
      1  1.17    matt /* $NetBSD: ixp12x0_intr.c,v 1.17 2008/01/08 02:07:51 matt Exp $ */
      2   1.1  ichiro 
      3   1.1  ichiro /*
      4   1.1  ichiro  * Copyright (c) 2002 The NetBSD Foundation, Inc.
      5   1.1  ichiro  * All rights reserved.
      6   1.1  ichiro  *
      7   1.1  ichiro  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1  ichiro  * by Ichiro FUKUHARA and Naoto Shimazaki.
      9   1.1  ichiro  *
     10   1.1  ichiro  * Redistribution and use in source and binary forms, with or without
     11   1.1  ichiro  * modification, are permitted provided that the following conditions
     12   1.1  ichiro  * are met:
     13   1.1  ichiro  * 1. Redistributions of source code must retain the above copyright
     14   1.1  ichiro  *    notice, this list of conditions and the following disclaimer.
     15   1.1  ichiro  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1  ichiro  *    notice, this list of conditions and the following disclaimer in the
     17   1.1  ichiro  *    documentation and/or other materials provided with the distribution.
     18   1.1  ichiro  * 3. All advertising materials mentioning features or use of this software
     19   1.1  ichiro  *    must display the following acknowledgement:
     20   1.1  ichiro  *        This product includes software developed by the NetBSD
     21   1.1  ichiro  *        Foundation, Inc. and its contributors.
     22   1.1  ichiro  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.1  ichiro  *    contributors may be used to endorse or promote products derived
     24   1.1  ichiro  *    from this software without specific prior written permission.
     25   1.1  ichiro  *
     26   1.1  ichiro  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.1  ichiro  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1  ichiro  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1  ichiro  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.1  ichiro  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1  ichiro  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1  ichiro  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1  ichiro  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1  ichiro  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1  ichiro  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1  ichiro  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1  ichiro  */
     38   1.7     igy 
     39   1.7     igy #include <sys/cdefs.h>
     40  1.17    matt __KERNEL_RCSID(0, "$NetBSD: ixp12x0_intr.c,v 1.17 2008/01/08 02:07:51 matt Exp $");
     41   1.1  ichiro 
     42   1.1  ichiro /*
     43   1.1  ichiro  * Interrupt support for the Intel ixp12x0
     44   1.1  ichiro  */
     45   1.1  ichiro 
     46   1.1  ichiro #include <sys/param.h>
     47   1.1  ichiro #include <sys/systm.h>
     48   1.1  ichiro #include <sys/malloc.h>
     49  1.17    matt #include <sys/simplelock.h>
     50   1.4  ichiro #include <sys/termios.h>
     51   1.1  ichiro 
     52   1.1  ichiro #include <uvm/uvm_extern.h>
     53   1.1  ichiro 
     54   1.1  ichiro #include <machine/bus.h>
     55   1.1  ichiro #include <machine/intr.h>
     56   1.1  ichiro 
     57   1.1  ichiro #include <arm/cpufunc.h>
     58   1.1  ichiro 
     59   1.1  ichiro #include <arm/ixp12x0/ixp12x0reg.h>
     60   1.1  ichiro #include <arm/ixp12x0/ixp12x0var.h>
     61   1.1  ichiro #include <arm/ixp12x0/ixp12x0_comreg.h>
     62   1.4  ichiro #include <arm/ixp12x0/ixp12x0_comvar.h>
     63   1.1  ichiro #include <arm/ixp12x0/ixp12x0_pcireg.h>
     64   1.1  ichiro 
     65  1.10     igy 
     66   1.1  ichiro extern u_int32_t	ixpcom_cr;	/* current cr from *_com.c */
     67   1.1  ichiro extern u_int32_t	ixpcom_imask;	/* tell mask to *_com.c */
     68   1.1  ichiro 
     69   1.1  ichiro /* Interrupt handler queues. */
     70   1.1  ichiro struct intrq intrq[NIRQ];
     71   1.1  ichiro 
     72   1.1  ichiro /* Interrupts to mask at each level. */
     73   1.1  ichiro static u_int32_t imask[NIPL];
     74   1.1  ichiro static u_int32_t pci_imask[NIPL];
     75   1.1  ichiro 
     76   1.1  ichiro /* Current interrupt priority level. */
     77  1.14   perry volatile int current_spl_level;
     78  1.14   perry volatile int hardware_spl_level;
     79   1.1  ichiro 
     80   1.1  ichiro /* Software copy of the IRQs we have enabled. */
     81  1.14   perry volatile u_int32_t intr_enabled;
     82  1.14   perry volatile u_int32_t pci_intr_enabled;
     83   1.1  ichiro 
     84   1.1  ichiro /* Interrupts pending. */
     85  1.14   perry static volatile int ipending;
     86   1.1  ichiro 
     87  1.17    matt #ifdef __HAVE_FAST_SOFTINTS
     88   1.1  ichiro /*
     89   1.1  ichiro  * Map a software interrupt queue index (to the unused bits in the
     90   1.1  ichiro  * ICU registers -- XXX will need to revisit this if those bits are
     91   1.1  ichiro  * ever used in future steppings).
     92   1.1  ichiro  */
     93   1.6     igy static const u_int32_t si_to_irqbit[SI_NQUEUES] = {
     94   1.1  ichiro 	IXP12X0_INTR_bit30,		/* SI_SOFT */
     95   1.1  ichiro 	IXP12X0_INTR_bit29,		/* SI_SOFTCLOCK */
     96   1.1  ichiro 	IXP12X0_INTR_bit28,		/* SI_SOFTNET */
     97   1.1  ichiro 	IXP12X0_INTR_bit27,		/* SI_SOFTSERIAL */
     98   1.1  ichiro };
     99   1.1  ichiro 
    100   1.1  ichiro #define	INT_SWMASK							\
    101   1.1  ichiro 	((1U << IXP12X0_INTR_bit30) | (1U << IXP12X0_INTR_bit29) |	\
    102   1.1  ichiro 	 (1U << IXP12X0_INTR_bit28) | (1U << IXP12X0_INTR_bit27))
    103   1.1  ichiro 
    104   1.1  ichiro #define	SI_TO_IRQBIT(si)	(1U << si_to_irqbit[(si)])
    105   1.1  ichiro 
    106   1.1  ichiro /*
    107   1.1  ichiro  * Map a software interrupt queue to an interrupt priority level.
    108   1.1  ichiro  */
    109  1.17    matt static const int si_to_ipl[] = {
    110  1.17    matt 	[SI_SOFTBIO] =		IPL_SOFTBIO,
    111  1.17    matt 	[SI_SOFTCLOCK] =	IPL_SOFTCLOCK,
    112  1.17    matt 	[SI_SOFTNET] =		IPL_SOFTNET,
    113  1.17    matt 	[SI_SOFTSERIAL] =	IPL_SOFTSERIAL,
    114   1.1  ichiro };
    115  1.17    matt #endif /* __HAVE_FAST_SOFTINTS */
    116   1.1  ichiro 
    117   1.1  ichiro void	ixp12x0_intr_dispatch(struct irqframe *frame);
    118   1.9     igy 
    119   1.9     igy #define IXPREG(reg)	*((volatile u_int32_t*) (reg))
    120   1.1  ichiro 
    121  1.14   perry static inline u_int32_t
    122   1.1  ichiro ixp12x0_irq_read(void)
    123   1.1  ichiro {
    124   1.1  ichiro 	return IXPREG(IXP12X0_IRQ_VBASE) & IXP12X0_INTR_MASK;
    125   1.1  ichiro }
    126   1.1  ichiro 
    127  1.14   perry static inline u_int32_t
    128   1.1  ichiro ixp12x0_pci_irq_read(void)
    129   1.1  ichiro {
    130   1.1  ichiro 	return IXPREG(IXPPCI_IRQ_STATUS);
    131   1.1  ichiro }
    132   1.1  ichiro 
    133   1.1  ichiro static void
    134   1.1  ichiro ixp12x0_enable_uart_irq(void)
    135   1.1  ichiro {
    136   1.1  ichiro 	ixpcom_imask = 0;
    137   1.4  ichiro 	if (ixpcom_sc)
    138   1.4  ichiro 		bus_space_write_4(ixpcom_sc->sc_iot, ixpcom_sc->sc_ioh,
    139   1.4  ichiro 				  IXPCOM_CR, ixpcom_cr & ~ixpcom_imask);
    140   1.1  ichiro }
    141   1.1  ichiro 
    142   1.1  ichiro static void
    143   1.1  ichiro ixp12x0_disable_uart_irq(void)
    144   1.1  ichiro {
    145   1.1  ichiro 	ixpcom_imask = CR_RIE | CR_XIE;
    146   1.4  ichiro 	if (ixpcom_sc)
    147   1.4  ichiro 		bus_space_write_4(ixpcom_sc->sc_iot, ixpcom_sc->sc_ioh,
    148   1.4  ichiro 				  IXPCOM_CR, ixpcom_cr & ~ixpcom_imask);
    149   1.1  ichiro }
    150   1.1  ichiro 
    151   1.1  ichiro static void
    152   1.1  ichiro ixp12x0_set_intrmask(u_int32_t irqs, u_int32_t pci_irqs)
    153   1.1  ichiro {
    154   1.1  ichiro 	if (irqs & (1U << IXP12X0_INTR_UART)) {
    155   1.1  ichiro 		ixp12x0_disable_uart_irq();
    156   1.1  ichiro 	} else {
    157   1.1  ichiro 		ixp12x0_enable_uart_irq();
    158   1.1  ichiro 	}
    159   1.1  ichiro 	IXPREG(IXPPCI_IRQ_ENABLE_CLEAR) = pci_irqs;
    160   1.1  ichiro 	IXPREG(IXPPCI_IRQ_ENABLE_SET) = pci_intr_enabled & ~pci_irqs;
    161   1.1  ichiro }
    162   1.1  ichiro 
    163   1.1  ichiro static void
    164   1.1  ichiro ixp12x0_enable_irq(int irq)
    165   1.1  ichiro {
    166   1.1  ichiro 	if (irq < SYS_NIRQ) {
    167   1.1  ichiro 		intr_enabled |= (1U << irq);
    168   1.1  ichiro 		switch (irq) {
    169   1.1  ichiro 		case IXP12X0_INTR_UART:
    170   1.1  ichiro 			ixp12x0_enable_uart_irq();
    171   1.1  ichiro 			break;
    172   1.1  ichiro 
    173   1.1  ichiro 		case IXP12X0_INTR_PCI:
    174   1.1  ichiro 			/* nothing to do */
    175   1.1  ichiro 			break;
    176   1.1  ichiro 		default:
    177   1.3  provos 			panic("enable_irq:bad IRQ %d", irq);
    178   1.1  ichiro 		}
    179   1.1  ichiro 	} else {
    180   1.1  ichiro 		pci_intr_enabled |= (1U << (irq - SYS_NIRQ));
    181   1.1  ichiro 		IXPREG(IXPPCI_IRQ_ENABLE_SET) = (1U << (irq - SYS_NIRQ));
    182   1.1  ichiro 	}
    183   1.1  ichiro }
    184   1.1  ichiro 
    185  1.14   perry static inline void
    186   1.1  ichiro ixp12x0_disable_irq(int irq)
    187   1.1  ichiro {
    188   1.1  ichiro 	if (irq < SYS_NIRQ) {
    189   1.1  ichiro 		intr_enabled ^= ~(1U << irq);
    190   1.1  ichiro 		switch (irq) {
    191   1.1  ichiro 		case IXP12X0_INTR_UART:
    192   1.1  ichiro 			ixp12x0_disable_uart_irq();
    193   1.1  ichiro 			break;
    194   1.1  ichiro 
    195   1.1  ichiro 		case IXP12X0_INTR_PCI:
    196   1.1  ichiro 			/* nothing to do */
    197   1.1  ichiro 			break;
    198   1.1  ichiro 		default:
    199   1.1  ichiro 			/* nothing to do */
    200  1.11    matt 			break;
    201   1.1  ichiro 		}
    202   1.1  ichiro 	} else {
    203   1.2  ichiro 		pci_intr_enabled &= ~(1U << (irq - SYS_NIRQ));
    204   1.1  ichiro 		IXPREG(IXPPCI_IRQ_ENABLE_CLEAR) = (1U << (irq - SYS_NIRQ));
    205   1.1  ichiro 	}
    206   1.1  ichiro }
    207   1.1  ichiro 
    208   1.1  ichiro /*
    209   1.1  ichiro  * NOTE: This routine must be called with interrupts disabled in the CPSR.
    210   1.1  ichiro  */
    211   1.1  ichiro static void
    212   1.1  ichiro ixp12x0_intr_calculate_masks(void)
    213   1.1  ichiro {
    214   1.1  ichiro 	struct intrq *iq;
    215   1.1  ichiro 	struct intrhand *ih;
    216   1.1  ichiro 	int irq, ipl;
    217   1.1  ichiro 
    218   1.1  ichiro 	/* First, figure out which IPLs each IRQ has. */
    219   1.1  ichiro 	for (irq = 0; irq < NIRQ; irq++) {
    220   1.1  ichiro 		int levels = 0;
    221   1.1  ichiro 		iq = &intrq[irq];
    222   1.1  ichiro 		ixp12x0_disable_irq(irq);
    223   1.1  ichiro 		for (ih = TAILQ_FIRST(&iq->iq_list); ih != NULL;
    224   1.1  ichiro 		     ih = TAILQ_NEXT(ih, ih_list))
    225   1.1  ichiro 			levels |= (1U << ih->ih_ipl);
    226   1.1  ichiro 		iq->iq_levels = levels;
    227   1.1  ichiro 	}
    228   1.1  ichiro 
    229   1.1  ichiro 	/* Next, figure out which IRQs are used by each IPL. */
    230   1.1  ichiro 	for (ipl = 0; ipl < NIPL; ipl++) {
    231   1.1  ichiro 		int irqs = 0;
    232   1.1  ichiro 		int pci_irqs = 0;
    233   1.1  ichiro 		for (irq = 0; irq < SYS_NIRQ; irq++) {
    234   1.1  ichiro 			if (intrq[irq].iq_levels & (1U << ipl))
    235   1.1  ichiro 				irqs |= (1U << irq);
    236   1.1  ichiro 		}
    237   1.1  ichiro 		imask[ipl] = irqs;
    238   1.1  ichiro 		for (irq = 0; irq < SYS_NIRQ; irq++) {
    239   1.1  ichiro 			if (intrq[irq + SYS_NIRQ].iq_levels & (1U << ipl))
    240   1.1  ichiro 				pci_irqs |= (1U << irq);
    241   1.1  ichiro 		}
    242   1.1  ichiro 		pci_imask[ipl] = pci_irqs;
    243   1.1  ichiro 	}
    244   1.1  ichiro 
    245  1.17    matt 	KASSERT(imask[IPL_NONE] == 0);
    246  1.17    matt 	KASSERT(pci_imask[IPL_NONE] == 0);
    247   1.1  ichiro 
    248  1.17    matt #ifdef __HAVE_FAST_SOFTINTS
    249   1.1  ichiro 	/*
    250   1.1  ichiro 	 * Initialize the soft interrupt masks to block themselves.
    251   1.1  ichiro 	 */
    252  1.17    matt 	imask[IPL_SOFTBIO] = SI_TO_IRQBIT(SI_SOFTBIO);
    253   1.1  ichiro 	imask[IPL_SOFTCLOCK] = SI_TO_IRQBIT(SI_SOFTCLOCK);
    254   1.1  ichiro 	imask[IPL_SOFTNET] = SI_TO_IRQBIT(SI_SOFTNET);
    255   1.1  ichiro 	imask[IPL_SOFTSERIAL] = SI_TO_IRQBIT(SI_SOFTSERIAL);
    256  1.17    matt #endif
    257   1.1  ichiro 
    258   1.1  ichiro 	/*
    259   1.1  ichiro 	 * splsoftclock() is the only interface that users of the
    260   1.1  ichiro 	 * generic software interrupt facility have to block their
    261   1.1  ichiro 	 * soft intrs, so splsoftclock() must also block IPL_SOFT.
    262   1.1  ichiro 	 */
    263  1.17    matt 	imask[IPL_SOFTCLOCK] |= imask[IPL_SOFTBIO];
    264  1.17    matt 	pci_imask[IPL_SOFTCLOCK] |= pci_imask[IPL_SOFTBIO];
    265   1.1  ichiro 
    266   1.1  ichiro 	/*
    267   1.1  ichiro 	 * splsoftnet() must also block splsoftclock(), since we don't
    268   1.1  ichiro 	 * want timer-driven network events to occur while we're
    269   1.1  ichiro 	 * processing incoming packets.
    270   1.1  ichiro 	 */
    271   1.1  ichiro 	imask[IPL_SOFTNET] |= imask[IPL_SOFTCLOCK];
    272   1.1  ichiro 	pci_imask[IPL_SOFTNET] |= pci_imask[IPL_SOFTCLOCK];
    273   1.1  ichiro 
    274   1.1  ichiro 	/*
    275  1.15     wiz 	 * Enforce a hierarchy that gives "slow" device (or devices with
    276   1.1  ichiro 	 * limited input buffer space/"real-time" requirements) a better
    277   1.1  ichiro 	 * chance at not dropping data.
    278   1.1  ichiro 	 */
    279  1.17    matt 	imask[IPL_SOFTSERIAL] |= imask[IPL_SOFTNET];
    280  1.17    matt 	pci_imask[IPL_SOFTSERIAL] |= pci_imask[IPL_SOFTNET];
    281   1.1  ichiro 
    282   1.1  ichiro 	/*
    283   1.1  ichiro 	 * splvm() blocks all interrupts that use the kernel memory
    284   1.1  ichiro 	 * allocation facilities.
    285   1.1  ichiro 	 */
    286  1.17    matt 	imask[IPL_VM] |= imask[IPL_SOFTSERIAL];
    287  1.17    matt 	pci_imask[IPL_VM] |= pci_imask[IPL_SOFTSERIAL];
    288   1.1  ichiro 
    289   1.1  ichiro 	/*
    290   1.1  ichiro 	 * splclock() must block anything that uses the scheduler.
    291   1.1  ichiro 	 */
    292  1.17    matt 	imask[IPL_CLOCK] |= imask[IPL_VM];
    293  1.17    matt 	pci_imask[IPL_CLOCK] |= pci_imask[IPL_VM];
    294   1.1  ichiro 
    295   1.1  ichiro 	/*
    296   1.1  ichiro 	 * splhigh() must block "everything".
    297   1.1  ichiro 	 */
    298  1.17    matt 	imask[IPL_HIGH] |= imask[IPL_CLOCK];
    299  1.17    matt 	pci_imask[IPL_HIGH] |= pci_imask[IPL_CLOCK];
    300   1.1  ichiro 
    301   1.1  ichiro 	/*
    302   1.1  ichiro 	 * Now compute which IRQs must be blocked when servicing any
    303   1.1  ichiro 	 * given IRQ.
    304   1.1  ichiro 	 */
    305   1.1  ichiro 	for (irq = 0; irq < NIRQ; irq++) {
    306   1.1  ichiro 		int	irqs;
    307   1.1  ichiro 		int	pci_irqs;
    308   1.1  ichiro 
    309   1.1  ichiro 		if (irq < SYS_NIRQ) {
    310   1.1  ichiro 			irqs = (1U << irq);
    311   1.1  ichiro 			pci_irqs = 0;
    312   1.1  ichiro 		} else {
    313   1.1  ichiro 			irqs = 0;
    314   1.1  ichiro 			pci_irqs = (1U << (irq - SYS_NIRQ));
    315   1.1  ichiro 		}
    316   1.1  ichiro 		iq = &intrq[irq];
    317   1.1  ichiro 		if (TAILQ_FIRST(&iq->iq_list) != NULL)
    318   1.1  ichiro 			ixp12x0_enable_irq(irq);
    319   1.1  ichiro 		for (ih = TAILQ_FIRST(&iq->iq_list); ih != NULL;
    320   1.1  ichiro 		     ih = TAILQ_NEXT(ih, ih_list)) {
    321   1.1  ichiro 			irqs |= imask[ih->ih_ipl];
    322   1.1  ichiro 			pci_irqs |= pci_imask[ih->ih_ipl];
    323   1.1  ichiro 		}
    324   1.1  ichiro 		iq->iq_mask = irqs;
    325   1.1  ichiro 		iq->iq_pci_mask = pci_irqs;
    326   1.1  ichiro 	}
    327   1.1  ichiro }
    328   1.1  ichiro 
    329  1.17    matt #ifdef __HAVE_FAST_SOFTINTS
    330   1.1  ichiro static void
    331   1.1  ichiro ixp12x0_do_pending(void)
    332   1.1  ichiro {
    333   1.1  ichiro 	static __cpu_simple_lock_t processing = __SIMPLELOCK_UNLOCKED;
    334   1.1  ichiro 	int	new;
    335   1.1  ichiro 	u_int	oldirqstate;
    336   1.1  ichiro 
    337   1.1  ichiro 	if (__cpu_simple_lock_try(&processing) == 0)
    338   1.1  ichiro 		return;
    339   1.1  ichiro 
    340   1.1  ichiro 	new = current_spl_level;
    341   1.1  ichiro 
    342   1.1  ichiro 	oldirqstate = disable_interrupts(I32_bit);
    343   1.1  ichiro 
    344   1.1  ichiro #define	DO_SOFTINT(si)							\
    345   1.1  ichiro 	if ((ipending & ~imask[new]) & SI_TO_IRQBIT(si)) {		\
    346   1.1  ichiro 		ipending &= ~SI_TO_IRQBIT(si);				\
    347   1.1  ichiro 		current_spl_level = si_to_ipl[(si)];			\
    348   1.1  ichiro 		restore_interrupts(oldirqstate);			\
    349   1.1  ichiro 		softintr_dispatch(si);					\
    350   1.1  ichiro 		oldirqstate = disable_interrupts(I32_bit);		\
    351   1.1  ichiro 		current_spl_level = new;				\
    352   1.1  ichiro 	}
    353   1.1  ichiro 
    354   1.1  ichiro 	DO_SOFTINT(SI_SOFTSERIAL);
    355   1.1  ichiro 	DO_SOFTINT(SI_SOFTNET);
    356   1.1  ichiro 	DO_SOFTINT(SI_SOFTCLOCK);
    357   1.1  ichiro 	DO_SOFTINT(SI_SOFT);
    358   1.1  ichiro 
    359   1.1  ichiro 	__cpu_simple_unlock(&processing);
    360   1.1  ichiro 
    361   1.1  ichiro 	restore_interrupts(oldirqstate);
    362   1.1  ichiro }
    363  1.17    matt #endif
    364   1.1  ichiro 
    365  1.14   perry inline void
    366   1.1  ichiro splx(int new)
    367   1.1  ichiro {
    368   1.1  ichiro 	int	old;
    369   1.1  ichiro 	u_int	oldirqstate;
    370   1.1  ichiro 
    371   1.1  ichiro 	oldirqstate = disable_interrupts(I32_bit);
    372   1.1  ichiro 	old = current_spl_level;
    373   1.1  ichiro 	current_spl_level = new;
    374  1.10     igy 	if (new != hardware_spl_level) {
    375  1.10     igy 		hardware_spl_level = new;
    376  1.10     igy 		ixp12x0_set_intrmask(imask[new], pci_imask[new]);
    377  1.10     igy 	}
    378   1.1  ichiro 	restore_interrupts(oldirqstate);
    379   1.1  ichiro 
    380  1.17    matt #ifdef __HAVE_FAST_SOFTINTS
    381   1.1  ichiro 	/* If there are software interrupts to process, do it. */
    382   1.1  ichiro 	if ((ipending & INT_SWMASK) & ~imask[new])
    383   1.1  ichiro 		ixp12x0_do_pending();
    384  1.17    matt #endif
    385   1.1  ichiro }
    386   1.1  ichiro 
    387   1.1  ichiro int
    388   1.1  ichiro _splraise(int ipl)
    389   1.1  ichiro {
    390  1.10     igy 	int	old;
    391  1.10     igy 	u_int	oldirqstate;
    392   1.1  ichiro 
    393  1.10     igy 	oldirqstate = disable_interrupts(I32_bit);
    394  1.10     igy 	old = current_spl_level;
    395  1.10     igy 	current_spl_level = ipl;
    396  1.10     igy 	restore_interrupts(oldirqstate);
    397   1.1  ichiro 	return (old);
    398   1.1  ichiro }
    399   1.1  ichiro 
    400   1.1  ichiro int
    401   1.1  ichiro _spllower(int ipl)
    402   1.1  ichiro {
    403   1.1  ichiro 	int	old = current_spl_level;
    404   1.1  ichiro 
    405   1.1  ichiro 	if (old <= ipl)
    406   1.1  ichiro 		return (old);
    407   1.1  ichiro 	splx(ipl);
    408   1.1  ichiro 	return (old);
    409   1.1  ichiro }
    410   1.1  ichiro 
    411  1.17    matt #ifdef __HAVE_FAST_SOFTINTS
    412   1.1  ichiro void
    413   1.1  ichiro _setsoftintr(int si)
    414   1.1  ichiro {
    415   1.1  ichiro 	u_int	oldirqstate;
    416   1.1  ichiro 
    417   1.1  ichiro 	oldirqstate = disable_interrupts(I32_bit);
    418   1.1  ichiro 	ipending |= SI_TO_IRQBIT(si);
    419   1.1  ichiro 	restore_interrupts(oldirqstate);
    420   1.1  ichiro 
    421   1.1  ichiro 	/* Process unmasked pending soft interrupts. */
    422   1.1  ichiro 	if ((ipending & INT_SWMASK) & ~imask[current_spl_level])
    423   1.1  ichiro 		ixp12x0_do_pending();
    424   1.1  ichiro }
    425  1.17    matt #endif
    426   1.1  ichiro 
    427   1.1  ichiro /*
    428   1.1  ichiro  * ixp12x0_intr_init:
    429   1.1  ichiro  *
    430   1.1  ichiro  *	Initialize the rest of the interrupt subsystem, making it
    431   1.1  ichiro  *	ready to handle interrupts from devices.
    432   1.1  ichiro  */
    433   1.1  ichiro void
    434   1.1  ichiro ixp12x0_intr_init(void)
    435   1.1  ichiro {
    436   1.1  ichiro 	struct intrq *iq;
    437   1.1  ichiro 	int i;
    438   1.1  ichiro 
    439   1.1  ichiro 	intr_enabled = 0;
    440   1.1  ichiro 	pci_intr_enabled = 0;
    441   1.1  ichiro 
    442   1.1  ichiro 	for (i = 0; i < NIRQ; i++) {
    443   1.1  ichiro 		iq = &intrq[i];
    444   1.1  ichiro 		TAILQ_INIT(&iq->iq_list);
    445   1.1  ichiro 
    446   1.1  ichiro 		sprintf(iq->iq_name, "ipl %d", i);
    447   1.1  ichiro 		evcnt_attach_dynamic(&iq->iq_ev, EVCNT_TYPE_INTR,
    448   1.1  ichiro 				     NULL, "ixpintr", iq->iq_name);
    449   1.1  ichiro 	}
    450   1.1  ichiro 	current_spl_level = 0;
    451  1.10     igy 	hardware_spl_level = 0;
    452   1.1  ichiro 
    453   1.5  ichiro 	ixp12x0_intr_calculate_masks();
    454   1.5  ichiro 
    455   1.1  ichiro 	/* Enable IRQs (don't yet use FIQs). */
    456   1.1  ichiro 	enable_interrupts(I32_bit);
    457   1.1  ichiro }
    458   1.1  ichiro 
    459   1.1  ichiro void *
    460   1.1  ichiro ixp12x0_intr_establish(int irq, int ipl, int (*ih_func)(void *), void *arg)
    461   1.1  ichiro {
    462   1.1  ichiro 	struct intrq*		iq;
    463   1.1  ichiro 	struct intrhand*	ih;
    464   1.1  ichiro 	u_int			oldirqstate;
    465   1.1  ichiro #ifdef DEBUG
    466   1.5  ichiro 	printf("ixp12x0_intr_establish(irq=%d, ipl=%d, ih_func=%08x, arg=%08x)\n",
    467   1.1  ichiro 	       irq, ipl, (u_int32_t) ih_func, (u_int32_t) arg);
    468   1.1  ichiro #endif
    469   1.1  ichiro 	if (irq < 0 || irq > NIRQ)
    470   1.1  ichiro 		panic("ixp12x0_intr_establish: IRQ %d out of range", ipl);
    471   1.1  ichiro 	if (ipl < 0 || ipl > NIPL)
    472   1.1  ichiro 		panic("ixp12x0_intr_establish: IPL %d out of range", ipl);
    473   1.1  ichiro 
    474   1.1  ichiro 	ih = malloc(sizeof(*ih), M_DEVBUF, M_NOWAIT);
    475   1.1  ichiro 	if (ih == NULL)
    476   1.1  ichiro 		return (NULL);
    477   1.1  ichiro 
    478   1.1  ichiro 	ih->ih_func = ih_func;
    479   1.1  ichiro 	ih->ih_arg = arg;
    480   1.1  ichiro 	ih->ih_irq = irq;
    481   1.1  ichiro 	ih->ih_ipl = ipl;
    482   1.1  ichiro 
    483   1.1  ichiro 	iq = &intrq[irq];
    484   1.5  ichiro 	iq->iq_ist = IST_LEVEL;
    485   1.1  ichiro 
    486   1.1  ichiro 	oldirqstate = disable_interrupts(I32_bit);
    487   1.1  ichiro 	TAILQ_INSERT_TAIL(&iq->iq_list, ih, ih_list);
    488   1.1  ichiro 	ixp12x0_intr_calculate_masks();
    489   1.1  ichiro 	restore_interrupts(oldirqstate);
    490   1.1  ichiro 
    491   1.1  ichiro 	return (ih);
    492   1.1  ichiro }
    493   1.1  ichiro 
    494   1.1  ichiro void
    495   1.1  ichiro ixp12x0_intr_disestablish(void *cookie)
    496   1.1  ichiro {
    497   1.1  ichiro 	struct intrhand*	ih = cookie;
    498   1.1  ichiro 	struct intrq*		iq = &intrq[ih->ih_ipl];
    499   1.1  ichiro 	u_int			oldirqstate;
    500   1.1  ichiro 
    501   1.1  ichiro 	oldirqstate = disable_interrupts(I32_bit);
    502   1.1  ichiro 	TAILQ_REMOVE(&iq->iq_list, ih, ih_list);
    503   1.1  ichiro 	ixp12x0_intr_calculate_masks();
    504   1.1  ichiro 	restore_interrupts(oldirqstate);
    505   1.1  ichiro }
    506   1.1  ichiro 
    507   1.1  ichiro void
    508  1.12      he ixp12x0_intr_dispatch(struct irqframe *frame)
    509   1.1  ichiro {
    510   1.1  ichiro 	struct intrq*		iq;
    511   1.1  ichiro 	struct intrhand*	ih;
    512   1.1  ichiro 	u_int			oldirqstate;
    513   1.1  ichiro 	int			pcpl;
    514   1.1  ichiro 	u_int32_t		hwpend;
    515   1.1  ichiro 	u_int32_t		pci_hwpend;
    516   1.1  ichiro 	int			irq;
    517   1.1  ichiro 	u_int32_t		ibit;
    518   1.1  ichiro 
    519   1.1  ichiro 	pcpl = current_spl_level;
    520   1.1  ichiro 
    521   1.1  ichiro 	hwpend = ixp12x0_irq_read();
    522   1.1  ichiro 	pci_hwpend = ixp12x0_pci_irq_read();
    523   1.1  ichiro 
    524  1.10     igy 	hardware_spl_level = pcpl;
    525  1.10     igy 	ixp12x0_set_intrmask(imask[pcpl] | hwpend,
    526  1.10     igy 			     pci_imask[pcpl] | pci_hwpend);
    527  1.10     igy 
    528  1.10     igy 	hwpend &= ~imask[pcpl];
    529  1.10     igy 	pci_hwpend &= ~pci_imask[pcpl];
    530  1.10     igy 
    531   1.1  ichiro 	while (hwpend) {
    532   1.1  ichiro 		irq = ffs(hwpend) - 1;
    533   1.1  ichiro 		ibit = (1U << irq);
    534   1.1  ichiro 
    535   1.1  ichiro 		iq = &intrq[irq];
    536   1.1  ichiro 		iq->iq_ev.ev_count++;
    537   1.1  ichiro 		uvmexp.intrs++;
    538   1.1  ichiro 		for (ih = TAILQ_FIRST(&iq->iq_list); ih != NULL;
    539   1.1  ichiro 		     ih = TAILQ_NEXT(ih, ih_list)) {
    540  1.10     igy 			int	ipl;
    541  1.10     igy 
    542   1.1  ichiro 			current_spl_level = ipl = ih->ih_ipl;
    543   1.1  ichiro 			oldirqstate = enable_interrupts(I32_bit);
    544   1.1  ichiro 			(void) (*ih->ih_func)(ih->ih_arg ? ih->ih_arg : frame);
    545   1.1  ichiro 			restore_interrupts(oldirqstate);
    546   1.1  ichiro 			hwpend &= ~ibit;
    547   1.1  ichiro 		}
    548   1.1  ichiro 	}
    549   1.1  ichiro 	while (pci_hwpend) {
    550   1.1  ichiro 		irq = ffs(pci_hwpend) - 1;
    551   1.1  ichiro 		ibit = (1U << irq);
    552   1.1  ichiro 
    553   1.1  ichiro 		iq = &intrq[irq + SYS_NIRQ];
    554   1.1  ichiro 		iq->iq_ev.ev_count++;
    555   1.1  ichiro 		uvmexp.intrs++;
    556   1.1  ichiro 		for (ih = TAILQ_FIRST(&iq->iq_list); ih != NULL;
    557   1.1  ichiro 		     ih = TAILQ_NEXT(ih, ih_list)) {
    558   1.1  ichiro 			int	ipl;
    559   1.1  ichiro 
    560   1.1  ichiro 			current_spl_level = ipl = ih->ih_ipl;
    561   1.1  ichiro 			oldirqstate = enable_interrupts(I32_bit);
    562   1.1  ichiro 			(void) (*ih->ih_func)(ih->ih_arg ? ih->ih_arg : frame);
    563   1.1  ichiro 			restore_interrupts(oldirqstate);
    564   1.1  ichiro 			pci_hwpend &= ~ibit;
    565   1.1  ichiro 		}
    566   1.1  ichiro 	}
    567   1.1  ichiro 
    568  1.10     igy 	current_spl_level = pcpl;
    569  1.10     igy 	hardware_spl_level = pcpl;
    570  1.10     igy 	ixp12x0_set_intrmask(imask[pcpl], pci_imask[pcpl]);
    571   1.1  ichiro 
    572  1.17    matt #ifdef __HAVE_FAST_SOFTINTS
    573   1.1  ichiro 	/* Check for pendings soft intrs. */
    574   1.1  ichiro 	if ((ipending & INT_SWMASK) & ~imask[pcpl]) {
    575   1.1  ichiro 		oldirqstate = enable_interrupts(I32_bit);
    576   1.1  ichiro 		ixp12x0_do_pending();
    577   1.1  ichiro 		restore_interrupts(oldirqstate);
    578   1.1  ichiro 	}
    579  1.17    matt #endif
    580   1.1  ichiro }
    581