Home | History | Annotate | Line # | Download | only in ixp12x0
ixp12x0_intr.c revision 1.21
      1  1.21     matt /* $NetBSD: ixp12x0_intr.c,v 1.21 2010/12/20 00:25:28 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  *
     19   1.1   ichiro  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1   ichiro  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1   ichiro  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1   ichiro  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1   ichiro  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1   ichiro  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1   ichiro  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1   ichiro  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1   ichiro  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1   ichiro  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1   ichiro  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1   ichiro  */
     31   1.7      igy 
     32   1.7      igy #include <sys/cdefs.h>
     33  1.21     matt __KERNEL_RCSID(0, "$NetBSD: ixp12x0_intr.c,v 1.21 2010/12/20 00:25:28 matt Exp $");
     34   1.1   ichiro 
     35   1.1   ichiro /*
     36   1.1   ichiro  * Interrupt support for the Intel ixp12x0
     37   1.1   ichiro  */
     38   1.1   ichiro 
     39   1.1   ichiro #include <sys/param.h>
     40   1.1   ichiro #include <sys/systm.h>
     41   1.1   ichiro #include <sys/malloc.h>
     42  1.17     matt #include <sys/simplelock.h>
     43   1.4   ichiro #include <sys/termios.h>
     44   1.1   ichiro 
     45   1.1   ichiro #include <machine/bus.h>
     46   1.1   ichiro #include <machine/intr.h>
     47   1.1   ichiro 
     48   1.1   ichiro #include <arm/cpufunc.h>
     49   1.1   ichiro 
     50   1.1   ichiro #include <arm/ixp12x0/ixp12x0reg.h>
     51   1.1   ichiro #include <arm/ixp12x0/ixp12x0var.h>
     52   1.1   ichiro #include <arm/ixp12x0/ixp12x0_comreg.h>
     53   1.4   ichiro #include <arm/ixp12x0/ixp12x0_comvar.h>
     54   1.1   ichiro #include <arm/ixp12x0/ixp12x0_pcireg.h>
     55   1.1   ichiro 
     56  1.10      igy 
     57   1.1   ichiro extern u_int32_t	ixpcom_cr;	/* current cr from *_com.c */
     58   1.1   ichiro extern u_int32_t	ixpcom_imask;	/* tell mask to *_com.c */
     59   1.1   ichiro 
     60   1.1   ichiro /* Interrupt handler queues. */
     61   1.1   ichiro struct intrq intrq[NIRQ];
     62   1.1   ichiro 
     63   1.1   ichiro /* Interrupts to mask at each level. */
     64   1.1   ichiro static u_int32_t imask[NIPL];
     65   1.1   ichiro static u_int32_t pci_imask[NIPL];
     66   1.1   ichiro 
     67   1.1   ichiro /* Current interrupt priority level. */
     68  1.14    perry volatile int hardware_spl_level;
     69   1.1   ichiro 
     70   1.1   ichiro /* Software copy of the IRQs we have enabled. */
     71  1.14    perry volatile u_int32_t intr_enabled;
     72  1.14    perry volatile u_int32_t pci_intr_enabled;
     73   1.1   ichiro 
     74   1.1   ichiro /* Interrupts pending. */
     75  1.14    perry static volatile int ipending;
     76   1.1   ichiro 
     77   1.1   ichiro void	ixp12x0_intr_dispatch(struct irqframe *frame);
     78   1.9      igy 
     79   1.9      igy #define IXPREG(reg)	*((volatile u_int32_t*) (reg))
     80   1.1   ichiro 
     81  1.14    perry static inline u_int32_t
     82   1.1   ichiro ixp12x0_irq_read(void)
     83   1.1   ichiro {
     84   1.1   ichiro 	return IXPREG(IXP12X0_IRQ_VBASE) & IXP12X0_INTR_MASK;
     85   1.1   ichiro }
     86   1.1   ichiro 
     87  1.14    perry static inline u_int32_t
     88   1.1   ichiro ixp12x0_pci_irq_read(void)
     89   1.1   ichiro {
     90   1.1   ichiro 	return IXPREG(IXPPCI_IRQ_STATUS);
     91   1.1   ichiro }
     92   1.1   ichiro 
     93   1.1   ichiro static void
     94   1.1   ichiro ixp12x0_enable_uart_irq(void)
     95   1.1   ichiro {
     96   1.1   ichiro 	ixpcom_imask = 0;
     97   1.4   ichiro 	if (ixpcom_sc)
     98   1.4   ichiro 		bus_space_write_4(ixpcom_sc->sc_iot, ixpcom_sc->sc_ioh,
     99   1.4   ichiro 				  IXPCOM_CR, ixpcom_cr & ~ixpcom_imask);
    100   1.1   ichiro }
    101   1.1   ichiro 
    102   1.1   ichiro static void
    103   1.1   ichiro ixp12x0_disable_uart_irq(void)
    104   1.1   ichiro {
    105   1.1   ichiro 	ixpcom_imask = CR_RIE | CR_XIE;
    106   1.4   ichiro 	if (ixpcom_sc)
    107   1.4   ichiro 		bus_space_write_4(ixpcom_sc->sc_iot, ixpcom_sc->sc_ioh,
    108   1.4   ichiro 				  IXPCOM_CR, ixpcom_cr & ~ixpcom_imask);
    109   1.1   ichiro }
    110   1.1   ichiro 
    111   1.1   ichiro static void
    112   1.1   ichiro ixp12x0_set_intrmask(u_int32_t irqs, u_int32_t pci_irqs)
    113   1.1   ichiro {
    114   1.1   ichiro 	if (irqs & (1U << IXP12X0_INTR_UART)) {
    115   1.1   ichiro 		ixp12x0_disable_uart_irq();
    116   1.1   ichiro 	} else {
    117   1.1   ichiro 		ixp12x0_enable_uart_irq();
    118   1.1   ichiro 	}
    119   1.1   ichiro 	IXPREG(IXPPCI_IRQ_ENABLE_CLEAR) = pci_irqs;
    120   1.1   ichiro 	IXPREG(IXPPCI_IRQ_ENABLE_SET) = pci_intr_enabled & ~pci_irqs;
    121   1.1   ichiro }
    122   1.1   ichiro 
    123   1.1   ichiro static void
    124   1.1   ichiro ixp12x0_enable_irq(int irq)
    125   1.1   ichiro {
    126   1.1   ichiro 	if (irq < SYS_NIRQ) {
    127   1.1   ichiro 		intr_enabled |= (1U << irq);
    128   1.1   ichiro 		switch (irq) {
    129   1.1   ichiro 		case IXP12X0_INTR_UART:
    130   1.1   ichiro 			ixp12x0_enable_uart_irq();
    131   1.1   ichiro 			break;
    132   1.1   ichiro 
    133   1.1   ichiro 		case IXP12X0_INTR_PCI:
    134   1.1   ichiro 			/* nothing to do */
    135   1.1   ichiro 			break;
    136   1.1   ichiro 		default:
    137   1.3   provos 			panic("enable_irq:bad IRQ %d", irq);
    138   1.1   ichiro 		}
    139   1.1   ichiro 	} else {
    140   1.1   ichiro 		pci_intr_enabled |= (1U << (irq - SYS_NIRQ));
    141   1.1   ichiro 		IXPREG(IXPPCI_IRQ_ENABLE_SET) = (1U << (irq - SYS_NIRQ));
    142   1.1   ichiro 	}
    143   1.1   ichiro }
    144   1.1   ichiro 
    145  1.14    perry static inline void
    146   1.1   ichiro ixp12x0_disable_irq(int irq)
    147   1.1   ichiro {
    148   1.1   ichiro 	if (irq < SYS_NIRQ) {
    149   1.1   ichiro 		intr_enabled ^= ~(1U << irq);
    150   1.1   ichiro 		switch (irq) {
    151   1.1   ichiro 		case IXP12X0_INTR_UART:
    152   1.1   ichiro 			ixp12x0_disable_uart_irq();
    153   1.1   ichiro 			break;
    154   1.1   ichiro 
    155   1.1   ichiro 		case IXP12X0_INTR_PCI:
    156   1.1   ichiro 			/* nothing to do */
    157   1.1   ichiro 			break;
    158   1.1   ichiro 		default:
    159   1.1   ichiro 			/* nothing to do */
    160  1.11     matt 			break;
    161   1.1   ichiro 		}
    162   1.1   ichiro 	} else {
    163   1.2   ichiro 		pci_intr_enabled &= ~(1U << (irq - SYS_NIRQ));
    164   1.1   ichiro 		IXPREG(IXPPCI_IRQ_ENABLE_CLEAR) = (1U << (irq - SYS_NIRQ));
    165   1.1   ichiro 	}
    166   1.1   ichiro }
    167   1.1   ichiro 
    168   1.1   ichiro /*
    169   1.1   ichiro  * NOTE: This routine must be called with interrupts disabled in the CPSR.
    170   1.1   ichiro  */
    171   1.1   ichiro static void
    172   1.1   ichiro ixp12x0_intr_calculate_masks(void)
    173   1.1   ichiro {
    174   1.1   ichiro 	struct intrq *iq;
    175   1.1   ichiro 	struct intrhand *ih;
    176   1.1   ichiro 	int irq, ipl;
    177   1.1   ichiro 
    178   1.1   ichiro 	/* First, figure out which IPLs each IRQ has. */
    179   1.1   ichiro 	for (irq = 0; irq < NIRQ; irq++) {
    180   1.1   ichiro 		int levels = 0;
    181   1.1   ichiro 		iq = &intrq[irq];
    182   1.1   ichiro 		ixp12x0_disable_irq(irq);
    183   1.1   ichiro 		for (ih = TAILQ_FIRST(&iq->iq_list); ih != NULL;
    184   1.1   ichiro 		     ih = TAILQ_NEXT(ih, ih_list))
    185   1.1   ichiro 			levels |= (1U << ih->ih_ipl);
    186   1.1   ichiro 		iq->iq_levels = levels;
    187   1.1   ichiro 	}
    188   1.1   ichiro 
    189   1.1   ichiro 	/* Next, figure out which IRQs are used by each IPL. */
    190   1.1   ichiro 	for (ipl = 0; ipl < NIPL; ipl++) {
    191   1.1   ichiro 		int irqs = 0;
    192   1.1   ichiro 		int pci_irqs = 0;
    193   1.1   ichiro 		for (irq = 0; irq < SYS_NIRQ; irq++) {
    194   1.1   ichiro 			if (intrq[irq].iq_levels & (1U << ipl))
    195   1.1   ichiro 				irqs |= (1U << irq);
    196   1.1   ichiro 		}
    197   1.1   ichiro 		imask[ipl] = irqs;
    198   1.1   ichiro 		for (irq = 0; irq < SYS_NIRQ; irq++) {
    199   1.1   ichiro 			if (intrq[irq + SYS_NIRQ].iq_levels & (1U << ipl))
    200   1.1   ichiro 				pci_irqs |= (1U << irq);
    201   1.1   ichiro 		}
    202   1.1   ichiro 		pci_imask[ipl] = pci_irqs;
    203   1.1   ichiro 	}
    204   1.1   ichiro 
    205  1.17     matt 	KASSERT(imask[IPL_NONE] == 0);
    206  1.17     matt 	KASSERT(pci_imask[IPL_NONE] == 0);
    207  1.20  tsutsui 	KASSERT(imask[IPL_SOFTCLOCK] == 0);
    208  1.20  tsutsui 	KASSERT(pci_imask[IPL_SOFTCLOCK] == 0);
    209  1.20  tsutsui 	KASSERT(imask[IPL_SOFTBIO] == 0);
    210  1.20  tsutsui 	KASSERT(pci_imask[IPL_SOFTBIO] == 0);
    211  1.20  tsutsui 	KASSERT(imask[IPL_SOFTNET] == 0);
    212  1.20  tsutsui 	KASSERT(pci_imask[IPL_SOFTNET] == 0);
    213  1.20  tsutsui 	KASSERT(imask[IPL_SOFTSERIAL] == 0);
    214  1.20  tsutsui 	KASSERT(pci_imask[IPL_SOFTSERIAL] == 0);
    215   1.1   ichiro 
    216  1.18     matt 	KASSERT(imask[IPL_VM] != 0);
    217  1.18     matt 	KASSERT(pci_imask[IPL_VM] != 0);
    218   1.1   ichiro 
    219   1.1   ichiro 	/*
    220  1.20  tsutsui 	 * splsched() must block anything that uses the scheduler.
    221   1.1   ichiro 	 */
    222  1.20  tsutsui 	imask[IPL_SCHED] |= imask[IPL_VM];
    223  1.20  tsutsui 	pci_imask[IPL_SCHED] |= pci_imask[IPL_VM];
    224   1.1   ichiro 
    225   1.1   ichiro 	/*
    226   1.1   ichiro 	 * splhigh() must block "everything".
    227   1.1   ichiro 	 */
    228  1.20  tsutsui 	imask[IPL_HIGH] |= imask[IPL_SCHED];
    229  1.20  tsutsui 	pci_imask[IPL_HIGH] |= pci_imask[IPL_SCHED];
    230   1.1   ichiro 
    231   1.1   ichiro 	/*
    232   1.1   ichiro 	 * Now compute which IRQs must be blocked when servicing any
    233   1.1   ichiro 	 * given IRQ.
    234   1.1   ichiro 	 */
    235   1.1   ichiro 	for (irq = 0; irq < NIRQ; irq++) {
    236   1.1   ichiro 		int	irqs;
    237   1.1   ichiro 		int	pci_irqs;
    238   1.1   ichiro 
    239   1.1   ichiro 		if (irq < SYS_NIRQ) {
    240   1.1   ichiro 			irqs = (1U << irq);
    241   1.1   ichiro 			pci_irqs = 0;
    242   1.1   ichiro 		} else {
    243   1.1   ichiro 			irqs = 0;
    244   1.1   ichiro 			pci_irqs = (1U << (irq - SYS_NIRQ));
    245   1.1   ichiro 		}
    246   1.1   ichiro 		iq = &intrq[irq];
    247   1.1   ichiro 		if (TAILQ_FIRST(&iq->iq_list) != NULL)
    248   1.1   ichiro 			ixp12x0_enable_irq(irq);
    249   1.1   ichiro 		for (ih = TAILQ_FIRST(&iq->iq_list); ih != NULL;
    250   1.1   ichiro 		     ih = TAILQ_NEXT(ih, ih_list)) {
    251   1.1   ichiro 			irqs |= imask[ih->ih_ipl];
    252   1.1   ichiro 			pci_irqs |= pci_imask[ih->ih_ipl];
    253   1.1   ichiro 		}
    254   1.1   ichiro 		iq->iq_mask = irqs;
    255   1.1   ichiro 		iq->iq_pci_mask = pci_irqs;
    256   1.1   ichiro 	}
    257   1.1   ichiro }
    258   1.1   ichiro 
    259  1.14    perry inline void
    260   1.1   ichiro splx(int new)
    261   1.1   ichiro {
    262   1.1   ichiro 	int	old;
    263   1.1   ichiro 	u_int	oldirqstate;
    264   1.1   ichiro 
    265   1.1   ichiro 	oldirqstate = disable_interrupts(I32_bit);
    266  1.18     matt 	old = curcpl();
    267  1.18     matt 	set_curcpl(new);
    268  1.10      igy 	if (new != hardware_spl_level) {
    269  1.10      igy 		hardware_spl_level = new;
    270  1.10      igy 		ixp12x0_set_intrmask(imask[new], pci_imask[new]);
    271  1.10      igy 	}
    272   1.1   ichiro 	restore_interrupts(oldirqstate);
    273   1.1   ichiro 
    274  1.17     matt #ifdef __HAVE_FAST_SOFTINTS
    275  1.18     matt 	cpu_dosoftints();
    276  1.17     matt #endif
    277   1.1   ichiro }
    278   1.1   ichiro 
    279   1.1   ichiro int
    280   1.1   ichiro _splraise(int ipl)
    281   1.1   ichiro {
    282  1.10      igy 	int	old;
    283  1.10      igy 	u_int	oldirqstate;
    284   1.1   ichiro 
    285  1.10      igy 	oldirqstate = disable_interrupts(I32_bit);
    286  1.18     matt 	old = curcpl();
    287  1.18     matt 	set_curcpl(ipl);
    288  1.10      igy 	restore_interrupts(oldirqstate);
    289   1.1   ichiro 	return (old);
    290   1.1   ichiro }
    291   1.1   ichiro 
    292   1.1   ichiro int
    293   1.1   ichiro _spllower(int ipl)
    294   1.1   ichiro {
    295  1.18     matt 	int	old = curcpl();
    296   1.1   ichiro 
    297   1.1   ichiro 	if (old <= ipl)
    298   1.1   ichiro 		return (old);
    299   1.1   ichiro 	splx(ipl);
    300   1.1   ichiro 	return (old);
    301   1.1   ichiro }
    302   1.1   ichiro 
    303   1.1   ichiro /*
    304   1.1   ichiro  * ixp12x0_intr_init:
    305   1.1   ichiro  *
    306   1.1   ichiro  *	Initialize the rest of the interrupt subsystem, making it
    307   1.1   ichiro  *	ready to handle interrupts from devices.
    308   1.1   ichiro  */
    309   1.1   ichiro void
    310   1.1   ichiro ixp12x0_intr_init(void)
    311   1.1   ichiro {
    312   1.1   ichiro 	struct intrq *iq;
    313   1.1   ichiro 	int i;
    314   1.1   ichiro 
    315   1.1   ichiro 	intr_enabled = 0;
    316   1.1   ichiro 	pci_intr_enabled = 0;
    317   1.1   ichiro 
    318   1.1   ichiro 	for (i = 0; i < NIRQ; i++) {
    319   1.1   ichiro 		iq = &intrq[i];
    320   1.1   ichiro 		TAILQ_INIT(&iq->iq_list);
    321   1.1   ichiro 
    322   1.1   ichiro 		sprintf(iq->iq_name, "ipl %d", i);
    323   1.1   ichiro 		evcnt_attach_dynamic(&iq->iq_ev, EVCNT_TYPE_INTR,
    324   1.1   ichiro 				     NULL, "ixpintr", iq->iq_name);
    325   1.1   ichiro 	}
    326  1.18     matt 	curcpu()->ci_intr_depth = 0;
    327  1.18     matt 	curcpu()->ci_cpl = 0;
    328  1.10      igy 	hardware_spl_level = 0;
    329   1.1   ichiro 
    330   1.5   ichiro 	ixp12x0_intr_calculate_masks();
    331   1.5   ichiro 
    332   1.1   ichiro 	/* Enable IRQs (don't yet use FIQs). */
    333   1.1   ichiro 	enable_interrupts(I32_bit);
    334   1.1   ichiro }
    335   1.1   ichiro 
    336   1.1   ichiro void *
    337   1.1   ichiro ixp12x0_intr_establish(int irq, int ipl, int (*ih_func)(void *), void *arg)
    338   1.1   ichiro {
    339   1.1   ichiro 	struct intrq*		iq;
    340   1.1   ichiro 	struct intrhand*	ih;
    341   1.1   ichiro 	u_int			oldirqstate;
    342   1.1   ichiro #ifdef DEBUG
    343   1.5   ichiro 	printf("ixp12x0_intr_establish(irq=%d, ipl=%d, ih_func=%08x, arg=%08x)\n",
    344   1.1   ichiro 	       irq, ipl, (u_int32_t) ih_func, (u_int32_t) arg);
    345   1.1   ichiro #endif
    346   1.1   ichiro 	if (irq < 0 || irq > NIRQ)
    347   1.1   ichiro 		panic("ixp12x0_intr_establish: IRQ %d out of range", ipl);
    348   1.1   ichiro 	if (ipl < 0 || ipl > NIPL)
    349   1.1   ichiro 		panic("ixp12x0_intr_establish: IPL %d out of range", ipl);
    350   1.1   ichiro 
    351   1.1   ichiro 	ih = malloc(sizeof(*ih), M_DEVBUF, M_NOWAIT);
    352   1.1   ichiro 	if (ih == NULL)
    353   1.1   ichiro 		return (NULL);
    354   1.1   ichiro 
    355   1.1   ichiro 	ih->ih_func = ih_func;
    356   1.1   ichiro 	ih->ih_arg = arg;
    357   1.1   ichiro 	ih->ih_irq = irq;
    358   1.1   ichiro 	ih->ih_ipl = ipl;
    359   1.1   ichiro 
    360   1.1   ichiro 	iq = &intrq[irq];
    361   1.5   ichiro 	iq->iq_ist = IST_LEVEL;
    362   1.1   ichiro 
    363   1.1   ichiro 	oldirqstate = disable_interrupts(I32_bit);
    364   1.1   ichiro 	TAILQ_INSERT_TAIL(&iq->iq_list, ih, ih_list);
    365   1.1   ichiro 	ixp12x0_intr_calculate_masks();
    366   1.1   ichiro 	restore_interrupts(oldirqstate);
    367   1.1   ichiro 
    368   1.1   ichiro 	return (ih);
    369   1.1   ichiro }
    370   1.1   ichiro 
    371   1.1   ichiro void
    372   1.1   ichiro ixp12x0_intr_disestablish(void *cookie)
    373   1.1   ichiro {
    374   1.1   ichiro 	struct intrhand*	ih = cookie;
    375   1.1   ichiro 	struct intrq*		iq = &intrq[ih->ih_ipl];
    376   1.1   ichiro 	u_int			oldirqstate;
    377   1.1   ichiro 
    378   1.1   ichiro 	oldirqstate = disable_interrupts(I32_bit);
    379   1.1   ichiro 	TAILQ_REMOVE(&iq->iq_list, ih, ih_list);
    380   1.1   ichiro 	ixp12x0_intr_calculate_masks();
    381   1.1   ichiro 	restore_interrupts(oldirqstate);
    382   1.1   ichiro }
    383   1.1   ichiro 
    384   1.1   ichiro void
    385  1.12       he ixp12x0_intr_dispatch(struct irqframe *frame)
    386   1.1   ichiro {
    387   1.1   ichiro 	struct intrq*		iq;
    388   1.1   ichiro 	struct intrhand*	ih;
    389  1.18     matt 	struct cpu_info* const	ci = curcpu();
    390  1.18     matt 	const int		ppl = ci->ci_cpl;
    391   1.1   ichiro 	u_int			oldirqstate;
    392   1.1   ichiro 	u_int32_t		hwpend;
    393   1.1   ichiro 	u_int32_t		pci_hwpend;
    394   1.1   ichiro 	int			irq;
    395   1.1   ichiro 	u_int32_t		ibit;
    396   1.1   ichiro 
    397   1.1   ichiro 
    398   1.1   ichiro 	hwpend = ixp12x0_irq_read();
    399   1.1   ichiro 	pci_hwpend = ixp12x0_pci_irq_read();
    400   1.1   ichiro 
    401  1.18     matt 	hardware_spl_level = ppl;
    402  1.18     matt 	ixp12x0_set_intrmask(imask[ppl] | hwpend, pci_imask[ppl] | pci_hwpend);
    403  1.10      igy 
    404  1.18     matt 	hwpend &= ~imask[ppl];
    405  1.18     matt 	pci_hwpend &= ~pci_imask[ppl];
    406  1.10      igy 
    407   1.1   ichiro 	while (hwpend) {
    408   1.1   ichiro 		irq = ffs(hwpend) - 1;
    409   1.1   ichiro 		ibit = (1U << irq);
    410   1.1   ichiro 
    411   1.1   ichiro 		iq = &intrq[irq];
    412   1.1   ichiro 		iq->iq_ev.ev_count++;
    413  1.21     matt 		ci->ci_data.cpu_nintr++;
    414  1.18     matt 		TAILQ_FOREACH(ih, &iq->iq_list, ih_list) {
    415  1.18     matt 			ci->ci_cpl = ih->ih_ipl;
    416   1.1   ichiro 			oldirqstate = enable_interrupts(I32_bit);
    417   1.1   ichiro 			(void) (*ih->ih_func)(ih->ih_arg ? ih->ih_arg : frame);
    418   1.1   ichiro 			restore_interrupts(oldirqstate);
    419   1.1   ichiro 			hwpend &= ~ibit;
    420   1.1   ichiro 		}
    421   1.1   ichiro 	}
    422   1.1   ichiro 	while (pci_hwpend) {
    423   1.1   ichiro 		irq = ffs(pci_hwpend) - 1;
    424   1.1   ichiro 		ibit = (1U << irq);
    425   1.1   ichiro 
    426   1.1   ichiro 		iq = &intrq[irq + SYS_NIRQ];
    427   1.1   ichiro 		iq->iq_ev.ev_count++;
    428  1.21     matt 		ci->ci_data.cpu_nintr++;
    429  1.18     matt 		TAILQ_FOREACH(ih, &iq->iq_list, ih_list) {
    430  1.18     matt 			ci->ci_cpl = ih->ih_ipl;
    431   1.1   ichiro 			oldirqstate = enable_interrupts(I32_bit);
    432   1.1   ichiro 			(void) (*ih->ih_func)(ih->ih_arg ? ih->ih_arg : frame);
    433   1.1   ichiro 			restore_interrupts(oldirqstate);
    434   1.1   ichiro 		}
    435  1.18     matt 		pci_hwpend &= ~ibit;
    436   1.1   ichiro 	}
    437   1.1   ichiro 
    438  1.18     matt 	ci->ci_cpl = ppl;
    439  1.18     matt 	hardware_spl_level = ppl;
    440  1.18     matt 	ixp12x0_set_intrmask(imask[ppl], pci_imask[ppl]);
    441   1.1   ichiro 
    442  1.17     matt #ifdef __HAVE_FAST_SOFTINTS
    443  1.18     matt 	cpu_dosoftints();
    444  1.17     matt #endif
    445   1.1   ichiro }
    446