2002-02-09 06:52:31 +03:00
|
|
|
/* $NetBSD: iq80310_intr.c,v 1.9 2002/02/09 03:52:31 thorpej Exp $ */
|
2001-11-07 03:33:22 +03:00
|
|
|
|
|
|
|
/*
|
2002-01-30 06:59:39 +03:00
|
|
|
* Copyright (c) 2001, 2002 Wasabi Systems, Inc.
|
2001-11-07 03:33:22 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Written by Jason R. Thorpe for Wasabi Systems, Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed for the NetBSD Project by
|
|
|
|
* Wasabi Systems, Inc.
|
|
|
|
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interrupt support for the Intel IQ80310.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
2001-11-07 03:33:22 +03:00
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/intr.h>
|
2002-01-30 06:59:39 +03:00
|
|
|
|
2001-11-23 22:36:48 +03:00
|
|
|
#include <arm/cpufunc.h>
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2001-12-01 09:15:36 +03:00
|
|
|
#include <arm/xscale/i80200reg.h>
|
2002-01-30 06:59:39 +03:00
|
|
|
#include <arm/xscale/i80200var.h>
|
2001-12-01 09:15:36 +03:00
|
|
|
|
2001-11-07 03:33:22 +03:00
|
|
|
#include <evbarm/iq80310/iq80310reg.h>
|
|
|
|
#include <evbarm/iq80310/iq80310var.h>
|
|
|
|
#include <evbarm/iq80310/obiovar.h>
|
|
|
|
|
2002-02-09 06:52:31 +03:00
|
|
|
#if defined(IOP310_TEAMASA_NPWR)
|
|
|
|
/*
|
|
|
|
* We have 5 interrupt source bits -- all in XINT3. All interrupts
|
|
|
|
* can be masked in the CPLD.
|
|
|
|
*/
|
|
|
|
#define IRQ_BITS 0x1f
|
|
|
|
#define IRQ_BITS_ALWAYS_ON 0x00
|
|
|
|
#else /* Default to stock IQ80310 */
|
2002-01-30 06:59:39 +03:00
|
|
|
/*
|
|
|
|
* We have 8 interrupt source bits -- 5 in the XINT3 register, and 3
|
|
|
|
* in the XINT0 register (the upper 3). Note that the XINT0 IRQs
|
|
|
|
* (SPCI INTA, INTB, and INTC) are always enabled, since they can not
|
|
|
|
* be masked out in the CPLD (it provides only status, not masking,
|
|
|
|
* for those interrupts).
|
|
|
|
*/
|
|
|
|
#define IRQ_BITS 0xff
|
|
|
|
#define IRQ_BITS_ALWAYS_ON 0xe0
|
2002-02-09 06:52:31 +03:00
|
|
|
#define IRQ_READ_XINT0 1 /* XXX only if board rev >= F */
|
|
|
|
#endif /* list of IQ80310-based designs */
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
/* Interrupt handler queues. */
|
|
|
|
struct intrq intrq[NIRQ];
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
/* Interrupts to mask at each level. */
|
|
|
|
static int imask[NIPL];
|
2001-12-01 09:15:36 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
/* Current interrupt priority level. */
|
|
|
|
__volatile int current_spl_level;
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
/* Interrupts pending. */
|
|
|
|
static __volatile int ipending;
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
/* Software copy of the IRQs we have enabled. */
|
|
|
|
uint32_t intr_enabled;
|
2001-11-07 03:33:22 +03:00
|
|
|
|
|
|
|
/*
|
2002-01-30 06:59:39 +03:00
|
|
|
* Map a software interrupt queue index (at the top of the word, and
|
|
|
|
* highest priority softintr is encountered first in an ffs()).
|
2001-11-07 03:33:22 +03:00
|
|
|
*/
|
2002-01-30 06:59:39 +03:00
|
|
|
#define SI_TO_IRQBIT(si) (1U << (31 - (si)))
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
/*
|
|
|
|
* Map a software interrupt queue to an interrupt priority level.
|
|
|
|
*/
|
|
|
|
static const int si_to_ipl[SI_NQUEUES] = {
|
|
|
|
IPL_SOFT, /* SI_SOFT */
|
|
|
|
IPL_SOFTCLOCK, /* SI_SOFTCLOCK */
|
|
|
|
IPL_SOFTNET, /* SI_SOFTNET */
|
|
|
|
IPL_SOFTSERIAL, /* SI_SOFTSERIAL */
|
|
|
|
};
|
|
|
|
|
|
|
|
void iq80310_intr_dispatch(struct clockframe *frame);
|
|
|
|
|
|
|
|
static __inline uint32_t
|
|
|
|
iq80310_intstat_read(void)
|
2001-11-07 03:33:22 +03:00
|
|
|
{
|
2002-01-30 06:59:39 +03:00
|
|
|
uint32_t intstat;
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
intstat = CPLD_READ(IQ80310_XINT3_STATUS) & 0x1f;
|
2002-02-09 06:52:31 +03:00
|
|
|
#if defined(IRQ_READ_XINT0)
|
|
|
|
if (IRQ_READ_XINT0)
|
2002-01-30 06:59:39 +03:00
|
|
|
intstat |= (CPLD_READ(IQ80310_XINT0_STATUS) & 0x7) << 5;
|
2002-02-09 06:52:31 +03:00
|
|
|
#endif
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
/* XXX Why do we have to mask off? */
|
|
|
|
return (intstat & intr_enabled);
|
|
|
|
}
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
static __inline void
|
|
|
|
iq80310_set_intrmask(void)
|
|
|
|
{
|
|
|
|
uint32_t disabled;
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
intr_enabled |= IRQ_BITS_ALWAYS_ON;
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
/* The XINT_MASK register sets a bit to *disable*. */
|
|
|
|
disabled = (~intr_enabled) & IRQ_BITS;
|
2001-12-01 09:15:36 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
CPLD_WRITE(IQ80310_XINT_MASK, disabled & 0x1f);
|
|
|
|
}
|
2001-12-01 09:15:36 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
static __inline void
|
|
|
|
iq80310_enable_irq(int irq)
|
|
|
|
{
|
|
|
|
|
|
|
|
intr_enabled |= (1U << irq);
|
|
|
|
iq80310_set_intrmask();
|
2001-11-07 03:33:22 +03:00
|
|
|
}
|
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
static __inline void
|
|
|
|
iq80310_disable_irq(int irq)
|
2001-11-07 03:33:22 +03:00
|
|
|
{
|
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
intr_enabled &= ~(1U << irq);
|
|
|
|
iq80310_set_intrmask();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE: This routine must be called with interrupts disabled in the CPSR.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
iq80310_intr_calculate_masks(void)
|
|
|
|
{
|
|
|
|
struct intrq *iq;
|
|
|
|
struct intrhand *ih;
|
|
|
|
int irq, ipl;
|
|
|
|
|
|
|
|
/* First, figure out which IPLs each IRQ has. */
|
|
|
|
for (irq = 0; irq < NIRQ; irq++) {
|
|
|
|
int levels = 0;
|
|
|
|
iq = &intrq[irq];
|
|
|
|
iq80310_disable_irq(irq);
|
|
|
|
for (ih = TAILQ_FIRST(&iq->iq_list); ih != NULL;
|
|
|
|
ih = TAILQ_NEXT(ih, ih_list))
|
|
|
|
levels |= (1U << ih->ih_ipl);
|
|
|
|
iq->iq_levels = levels;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Next, figure out which IRQs are used by each IPL. */
|
|
|
|
for (ipl = 0; ipl < NIPL; ipl++) {
|
|
|
|
int irqs = 0;
|
|
|
|
for (irq = 0; irq < NIRQ; irq++) {
|
|
|
|
if (intrq[irq].iq_levels & (1U << ipl))
|
|
|
|
irqs |= (1U << irq);
|
|
|
|
}
|
|
|
|
imask[ipl] = irqs;
|
|
|
|
}
|
|
|
|
|
|
|
|
imask[IPL_NONE] = 0;
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2001-12-01 09:15:36 +03:00
|
|
|
/*
|
2002-01-30 06:59:39 +03:00
|
|
|
* Initialize the soft interrupt masks to block themselves.
|
2001-12-01 09:15:36 +03:00
|
|
|
*/
|
2002-01-30 06:59:39 +03:00
|
|
|
imask[IPL_SOFT] = SI_TO_IRQBIT(SI_SOFT);
|
|
|
|
imask[IPL_SOFTCLOCK] = SI_TO_IRQBIT(SI_SOFTCLOCK);
|
|
|
|
imask[IPL_SOFTNET] = SI_TO_IRQBIT(SI_SOFTNET);
|
|
|
|
imask[IPL_SOFTSERIAL] = SI_TO_IRQBIT(SI_SOFTSERIAL);
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
/*
|
|
|
|
* splsoftclock() is the only interface that users of the
|
|
|
|
* generic software interrupt facility have to block their
|
|
|
|
* soft intrs, so splsoftclock() must also block IPL_SOFT.
|
|
|
|
*/
|
|
|
|
imask[IPL_SOFTCLOCK] |= imask[IPL_SOFT];
|
2002-01-20 06:41:47 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
/*
|
|
|
|
* splsoftnet() must also block splsoftclock(), since we don't
|
|
|
|
* want timer-driven network events to occur while we're
|
|
|
|
* processing incoming packets.
|
|
|
|
*/
|
|
|
|
imask[IPL_SOFTNET] |= imask[IPL_SOFTCLOCK];
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
/*
|
|
|
|
* Enforce a heirarchy that gives "slow" device (or devices with
|
|
|
|
* limited input buffer space/"real-time" requirements) a better
|
|
|
|
* chance at not dropping data.
|
|
|
|
*/
|
|
|
|
imask[IPL_BIO] |= imask[IPL_SOFTNET];
|
|
|
|
imask[IPL_NET] |= imask[IPL_BIO];
|
|
|
|
imask[IPL_SOFTSERIAL] |= imask[IPL_NET];
|
|
|
|
imask[IPL_TTY] |= imask[IPL_SOFTSERIAL];
|
2001-12-01 09:15:36 +03:00
|
|
|
|
2001-11-07 03:33:22 +03:00
|
|
|
/*
|
2002-01-30 06:59:39 +03:00
|
|
|
* splvm() blocks all interrupts that use the kernel memory
|
|
|
|
* allocation facilities.
|
2001-11-07 03:33:22 +03:00
|
|
|
*/
|
2002-01-30 06:59:39 +03:00
|
|
|
imask[IPL_IMP] |= imask[IPL_TTY];
|
2001-11-07 03:33:22 +03:00
|
|
|
|
|
|
|
/*
|
2002-01-30 06:59:39 +03:00
|
|
|
* Audio devices are not allowed to perform memory allocation
|
|
|
|
* in their interrupt routines, and they have fairly "real-time"
|
|
|
|
* requirements, so give them a high interrupt priority.
|
2001-11-07 03:33:22 +03:00
|
|
|
*/
|
2002-01-30 06:59:39 +03:00
|
|
|
imask[IPL_AUDIO] |= imask[IPL_IMP];
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
/*
|
|
|
|
* splclock() must block anything that uses the scheduler.
|
|
|
|
*/
|
|
|
|
imask[IPL_CLOCK] |= imask[IPL_AUDIO];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No separate statclock on the IQ80310.
|
|
|
|
*/
|
|
|
|
imask[IPL_STATCLOCK] |= imask[IPL_CLOCK];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* splhigh() must block "everything".
|
|
|
|
*/
|
|
|
|
imask[IPL_HIGH] |= imask[IPL_STATCLOCK];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX We need serial drivers to run at the absolute highest priority
|
|
|
|
* in order to avoid overruns, so serial > high.
|
|
|
|
*/
|
|
|
|
imask[IPL_SERIAL] |= imask[IPL_HIGH];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now compute which IRQs must be blocked when servicing any
|
|
|
|
* given IRQ.
|
|
|
|
*/
|
|
|
|
for (irq = 0; irq < NIRQ; irq++) {
|
|
|
|
int irqs = (1U << irq);
|
|
|
|
iq = &intrq[irq];
|
|
|
|
if (TAILQ_FIRST(&iq->iq_list) != NULL)
|
|
|
|
iq80310_enable_irq(irq);
|
|
|
|
for (ih = TAILQ_FIRST(&iq->iq_list); ih != NULL;
|
|
|
|
ih = TAILQ_NEXT(ih, ih_list))
|
|
|
|
irqs |= imask[ih->ih_ipl];
|
|
|
|
iq->iq_mask = irqs;
|
|
|
|
}
|
2001-11-07 03:33:22 +03:00
|
|
|
}
|
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
static void
|
|
|
|
iq80310_do_pending(void)
|
2001-11-07 03:33:22 +03:00
|
|
|
{
|
2002-01-30 06:59:39 +03:00
|
|
|
static __cpu_simple_lock_t processing = __SIMPLELOCK_UNLOCKED;
|
|
|
|
int new, oldirqstate;
|
|
|
|
|
|
|
|
if (__cpu_simple_lock_try(&processing) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
new = current_spl_level;
|
2001-11-07 03:33:22 +03:00
|
|
|
|
|
|
|
oldirqstate = disable_interrupts(I32_bit);
|
2002-01-30 06:59:39 +03:00
|
|
|
|
|
|
|
#define DO_SOFTINT(si) \
|
|
|
|
if ((ipending & ~new) & SI_TO_IRQBIT(si)) { \
|
|
|
|
ipending &= ~SI_TO_IRQBIT(si); \
|
|
|
|
current_spl_level |= imask[si_to_ipl[(si)]]; \
|
|
|
|
restore_interrupts(oldirqstate); \
|
|
|
|
softintr_dispatch(si); \
|
|
|
|
oldirqstate = disable_interrupts(I32_bit); \
|
|
|
|
current_spl_level = new; \
|
|
|
|
}
|
|
|
|
|
|
|
|
DO_SOFTINT(SI_SOFTSERIAL);
|
|
|
|
DO_SOFTINT(SI_SOFTNET);
|
|
|
|
DO_SOFTINT(SI_SOFTCLOCK);
|
|
|
|
DO_SOFTINT(SI_SOFT);
|
|
|
|
|
|
|
|
__cpu_simple_unlock(&processing);
|
|
|
|
|
2001-11-07 03:33:22 +03:00
|
|
|
restore_interrupts(oldirqstate);
|
|
|
|
}
|
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
int
|
|
|
|
_splraise(int ipl)
|
|
|
|
{
|
|
|
|
int old, oldirqstate;
|
|
|
|
|
|
|
|
oldirqstate = disable_interrupts(I32_bit);
|
|
|
|
old = current_spl_level;
|
|
|
|
current_spl_level |= imask[ipl];
|
|
|
|
|
|
|
|
restore_interrupts(oldirqstate);
|
|
|
|
|
|
|
|
return (old);
|
|
|
|
}
|
|
|
|
|
|
|
|
__inline void
|
|
|
|
splx(int new)
|
|
|
|
{
|
|
|
|
int old;
|
|
|
|
|
|
|
|
old = current_spl_level;
|
|
|
|
current_spl_level = new;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there are pending hardware interrupts (i.e. the
|
|
|
|
* external interrupt is disabled in the ICU), and all
|
|
|
|
* hardware interrupts are being unblocked, then re-enable
|
|
|
|
* the external hardware interrupt.
|
|
|
|
*
|
|
|
|
* XXX We have to wait for ALL hardware interrupts to
|
|
|
|
* XXX be unblocked, because we currently lose if we
|
|
|
|
* XXX get nested interrupts, and I don't know why yet.
|
|
|
|
*/
|
|
|
|
if ((new & IRQ_BITS) == 0 && (ipending & IRQ_BITS))
|
|
|
|
i80200_intr_enable(INTCTL_IM);
|
|
|
|
|
|
|
|
/* If there are software interrupts to process, do it. */
|
|
|
|
if ((ipending & ~IRQ_BITS) & ~new)
|
|
|
|
iq80310_do_pending();
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
_spllower(int ipl)
|
2001-11-07 03:33:22 +03:00
|
|
|
{
|
2002-01-30 06:59:39 +03:00
|
|
|
int old = current_spl_level;
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
splx(imask[ipl]);
|
|
|
|
return (old);
|
2001-11-07 03:33:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-01-30 06:59:39 +03:00
|
|
|
_setsoftintr(int si)
|
2001-11-07 03:33:22 +03:00
|
|
|
{
|
2002-01-30 06:59:39 +03:00
|
|
|
int oldirqstate;
|
|
|
|
|
|
|
|
oldirqstate = disable_interrupts(I32_bit);
|
|
|
|
ipending |= SI_TO_IRQBIT(si);
|
|
|
|
restore_interrupts(oldirqstate);
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
/* Process unmasked pending soft interrupts. */
|
|
|
|
if ((ipending & ~IRQ_BITS) & ~current_spl_level)
|
|
|
|
iq80310_do_pending();
|
2001-11-07 03:33:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-01-30 06:59:39 +03:00
|
|
|
iq80310_intr_init(void)
|
2001-11-07 03:33:22 +03:00
|
|
|
{
|
2002-01-30 06:59:39 +03:00
|
|
|
struct intrq *iq;
|
|
|
|
int i;
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
/*
|
|
|
|
* The Secondary PCI interrupts INTA, INTB, and INTC
|
|
|
|
* area always enabled, since they cannot be masked
|
|
|
|
* in the CPLD.
|
|
|
|
*/
|
|
|
|
intr_enabled |= IRQ_BITS_ALWAYS_ON;
|
|
|
|
|
|
|
|
for (i = 0; i < NIRQ; i++) {
|
|
|
|
iq = &intrq[i];
|
|
|
|
TAILQ_INIT(&iq->iq_list);
|
|
|
|
|
|
|
|
sprintf(iq->iq_name, "irq %d", i);
|
|
|
|
evcnt_attach_dynamic(&iq->iq_ev, EVCNT_TYPE_INTR,
|
|
|
|
NULL, "iq80310", iq->iq_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
iq80310_intr_calculate_masks();
|
|
|
|
|
|
|
|
/* Enable external interrupts on the i80200. */
|
|
|
|
i80200_extirq_dispatch = iq80310_intr_dispatch;
|
|
|
|
i80200_intr_enable(INTCTL_IM);
|
|
|
|
|
|
|
|
/* Enable IRQs (don't yet use FIQs). */
|
|
|
|
enable_interrupts(I32_bit);
|
2001-11-07 03:33:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
iq80310_intr_establish(int irq, int ipl, int (*func)(void *), void *arg)
|
|
|
|
{
|
2002-01-30 06:59:39 +03:00
|
|
|
struct intrq *iq;
|
|
|
|
struct intrhand *ih;
|
2001-11-07 03:33:22 +03:00
|
|
|
u_int oldirqstate;
|
2002-01-30 06:59:39 +03:00
|
|
|
|
|
|
|
if (irq < 0 || irq > NIRQ)
|
|
|
|
panic("iq80310_intr_establish: IRQ %d out of range", irq);
|
2001-11-07 03:33:22 +03:00
|
|
|
|
|
|
|
ih = malloc(sizeof(*ih), M_DEVBUF, M_NOWAIT);
|
|
|
|
if (ih == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
ih->ih_func = func;
|
|
|
|
ih->ih_arg = arg;
|
2002-01-30 06:59:39 +03:00
|
|
|
ih->ih_ipl = ipl;
|
|
|
|
ih->ih_irq = irq;
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
iq = &intrq[irq];
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
/* All IQ80310 interrupts are level-triggered. */
|
|
|
|
iq->iq_ist = IST_LEVEL;
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
oldirqstate = disable_interrupts(I32_bit);
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
TAILQ_INSERT_TAIL(&iq->iq_list, ih, ih_list);
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
iq80310_intr_calculate_masks();
|
2001-11-07 03:33:22 +03:00
|
|
|
|
|
|
|
restore_interrupts(oldirqstate);
|
|
|
|
|
|
|
|
return (ih);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
iq80310_intr_disestablish(void *cookie)
|
|
|
|
{
|
2002-01-30 06:59:39 +03:00
|
|
|
struct intrhand *ih = cookie;
|
|
|
|
struct intrq *iq = &intrq[ih->ih_irq];
|
|
|
|
int oldirqstate;
|
|
|
|
|
|
|
|
oldirqstate = disable_interrupts(I32_bit);
|
|
|
|
|
|
|
|
TAILQ_REMOVE(&iq->iq_list, ih, ih_list);
|
|
|
|
|
|
|
|
iq80310_intr_calculate_masks();
|
2001-11-07 03:33:22 +03:00
|
|
|
|
2002-01-30 06:59:39 +03:00
|
|
|
restore_interrupts(oldirqstate);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
iq80310_intr_dispatch(struct clockframe *frame)
|
|
|
|
{
|
|
|
|
struct intrq *iq;
|
|
|
|
struct intrhand *ih;
|
|
|
|
int oldirqstate, pcpl, irq, ibit, hwpend;
|
|
|
|
|
|
|
|
/* First, disable external IRQs. */
|
|
|
|
i80200_intr_disable(INTCTL_IM);
|
|
|
|
|
|
|
|
pcpl = current_spl_level;
|
|
|
|
|
|
|
|
for (hwpend = iq80310_intstat_read(); hwpend != 0;) {
|
|
|
|
irq = ffs(hwpend) - 1;
|
|
|
|
ibit = (1U << irq);
|
|
|
|
|
|
|
|
hwpend &= ~ibit;
|
|
|
|
|
|
|
|
if (pcpl & ibit) {
|
|
|
|
/*
|
|
|
|
* IRQ is masked; mark it as pending and check
|
|
|
|
* the next one. Note: external IRQs are already
|
|
|
|
* disabled.
|
|
|
|
*/
|
|
|
|
ipending |= ibit;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ipending &= ~ibit;
|
|
|
|
|
|
|
|
iq = &intrq[irq];
|
|
|
|
iq->iq_ev.ev_count++;
|
|
|
|
uvmexp.intrs++;
|
|
|
|
current_spl_level |= iq->iq_mask;
|
|
|
|
oldirqstate = enable_interrupts(I32_bit);
|
|
|
|
for (ih = TAILQ_FIRST(&iq->iq_list); ih != NULL;
|
|
|
|
ih = TAILQ_NEXT(ih, ih_list)) {
|
|
|
|
(void) (*ih->ih_func)(ih->ih_arg ? ih->ih_arg : frame);
|
|
|
|
}
|
|
|
|
restore_interrupts(oldirqstate);
|
|
|
|
|
|
|
|
current_spl_level = pcpl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for pendings soft intrs. */
|
|
|
|
if ((ipending & ~IRQ_BITS) & ~current_spl_level) {
|
|
|
|
oldirqstate = enable_interrupts(I32_bit);
|
|
|
|
iq80310_do_pending();
|
|
|
|
restore_interrupts(oldirqstate);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If no hardware interrupts are masked, re-enable external
|
|
|
|
* interrupts.
|
|
|
|
*/
|
|
|
|
if ((ipending & IRQ_BITS) == 0)
|
|
|
|
i80200_intr_enable(INTCTL_IM);
|
2001-11-07 03:33:22 +03:00
|
|
|
}
|