Simplify the interrupt code a bit:
- Always include the ie_disable and ie_eoi methods in 'struct intr_event' and collapse down to one intr_event_create() routine. The disable and eoi hooks simply aren't used currently in the !INTR_FILTER case. - Expand 'disab' to 'disable' in a few places. - Use function casts for arm and i386:intr_eoi_src() instead of wrapper routines since to trim one extra indirection. Compiled on: {arm,amd64,i386,ia64,ppc,sparc64} x {FILTER, !FILTER} Tested on: {amd64,i386} x {FILTER, !FILTER}
This commit is contained in:
parent
f6efbc8842
commit
6d2d1c044f
@ -77,12 +77,6 @@ static struct sx intr_table_lock;
|
||||
static struct mtx intrcnt_lock;
|
||||
static STAILQ_HEAD(, pic) pics;
|
||||
|
||||
#ifdef INTR_FILTER
|
||||
static void intr_eoi_src(void *arg);
|
||||
static void intr_disab_eoi_src(void *arg);
|
||||
static void intr_event_stray(void *cookie);
|
||||
#endif
|
||||
|
||||
#ifdef SMP
|
||||
static int assign_cpu;
|
||||
|
||||
@ -90,6 +84,10 @@ static void intr_assign_next_cpu(struct intsrc *isrc);
|
||||
#endif
|
||||
|
||||
static int intr_assign_cpu(void *arg, u_char cpu);
|
||||
static void intr_disable_src(void *arg);
|
||||
#ifdef INTR_FILTER
|
||||
static void intr_event_stray(void *cookie);
|
||||
#endif
|
||||
static void intr_init(void *__dummy);
|
||||
static int intr_pic_registered(struct pic *pic);
|
||||
static void intrcnt_setname(const char *name, int index);
|
||||
@ -144,16 +142,10 @@ intr_register_source(struct intsrc *isrc)
|
||||
vector = isrc->is_pic->pic_vector(isrc);
|
||||
if (interrupt_sources[vector] != NULL)
|
||||
return (EEXIST);
|
||||
#ifdef INTR_FILTER
|
||||
error = intr_event_create(&isrc->is_event, isrc, 0,
|
||||
(mask_fn)isrc->is_pic->pic_enable_source,
|
||||
intr_eoi_src, intr_disab_eoi_src, intr_assign_cpu, "irq%d:",
|
||||
intr_disable_src, (mask_fn)isrc->is_pic->pic_enable_source,
|
||||
(mask_fn)isrc->is_pic->pic_eoi_source, intr_assign_cpu, "irq%d:",
|
||||
vector);
|
||||
#else
|
||||
error = intr_event_create(&isrc->is_event, isrc, 0,
|
||||
(mask_fn)isrc->is_pic->pic_enable_source, intr_assign_cpu, "irq%d:",
|
||||
vector);
|
||||
#endif
|
||||
if (error)
|
||||
return (error);
|
||||
sx_xlock(&intr_table_lock);
|
||||
@ -237,6 +229,15 @@ intr_config_intr(int vector, enum intr_trigger trig, enum intr_polarity pol)
|
||||
return (isrc->is_pic->pic_config_intr(isrc, trig, pol));
|
||||
}
|
||||
|
||||
static void
|
||||
intr_disable_src(void *arg)
|
||||
{
|
||||
struct intsrc *isrc;
|
||||
|
||||
isrc = arg;
|
||||
isrc->is_pic->pic_disable_source(isrc, PIC_EOI);
|
||||
}
|
||||
|
||||
#ifdef INTR_FILTER
|
||||
void
|
||||
intr_execute_handlers(struct intsrc *isrc, struct trapframe *frame)
|
||||
@ -289,24 +290,6 @@ intr_event_stray(void *cookie)
|
||||
"too many stray irq %d's: not logging anymore\n",
|
||||
isrc->is_pic->pic_vector(isrc));
|
||||
}
|
||||
|
||||
static void
|
||||
intr_eoi_src(void *arg)
|
||||
{
|
||||
struct intsrc *isrc;
|
||||
|
||||
isrc = arg;
|
||||
isrc->is_pic->pic_eoi_source(isrc);
|
||||
}
|
||||
|
||||
static void
|
||||
intr_disab_eoi_src(void *arg)
|
||||
{
|
||||
struct intsrc *isrc;
|
||||
|
||||
isrc = arg;
|
||||
isrc->is_pic->pic_disable_source(isrc, PIC_EOI);
|
||||
}
|
||||
#else
|
||||
void
|
||||
intr_execute_handlers(struct intsrc *isrc, struct trapframe *frame)
|
||||
|
@ -50,6 +50,8 @@ __FBSDID("$FreeBSD$");
|
||||
#include <machine/intr.h>
|
||||
#include <machine/cpu.h>
|
||||
|
||||
typedef void (*mask_fn)(void *);
|
||||
|
||||
static struct intr_event *intr_events[NIRQ];
|
||||
static int intrcnt_tab[NIRQ];
|
||||
static int intrcnt_index = 0;
|
||||
@ -57,27 +59,6 @@ static int last_printed = 0;
|
||||
|
||||
void arm_handler_execute(struct trapframe *, int);
|
||||
|
||||
#ifdef INTR_FILTER
|
||||
static void
|
||||
intr_disab_eoi_src(void *arg)
|
||||
{
|
||||
uintptr_t nb;
|
||||
|
||||
nb = (uintptr_t)arg;
|
||||
arm_mask_irq(nb);
|
||||
}
|
||||
|
||||
static void
|
||||
intr_eoi_src(void *arg)
|
||||
{
|
||||
uintptr_t nb;
|
||||
|
||||
nb = (uintptr_t)arg;
|
||||
arm_unmask_irq(nb);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void
|
||||
arm_setup_irqhandler(const char *name, driver_filter_t *filt,
|
||||
void (*hand)(void*), void *arg, int irq, int flags, void **cookiep)
|
||||
@ -89,14 +70,9 @@ arm_setup_irqhandler(const char *name, driver_filter_t *filt,
|
||||
return;
|
||||
event = intr_events[irq];
|
||||
if (event == NULL) {
|
||||
#ifdef INTR_FILTER
|
||||
error = intr_event_create(&event, (void *)irq, 0,
|
||||
(void (*)(void *))arm_unmask_irq, intr_eoi_src,
|
||||
intr_disab_eoi_src, NULL, "intr%d:", irq);
|
||||
#else
|
||||
error = intr_event_create(&event, (void *)irq, 0,
|
||||
(void (*)(void *))arm_unmask_irq, NULL, "intr%d:", irq);
|
||||
#endif
|
||||
(mask_fn)arm_mask_irq, (mask_fn)arm_unmask_irq,
|
||||
(mask_fn)arm_unmask_irq, NULL, "intr%d:", irq);
|
||||
if (error)
|
||||
return;
|
||||
intr_events[irq] = event;
|
||||
|
@ -68,12 +68,6 @@ static struct sx intr_table_lock;
|
||||
static struct mtx intrcnt_lock;
|
||||
static STAILQ_HEAD(, pic) pics;
|
||||
|
||||
#ifdef INTR_FILTER
|
||||
static void intr_eoi_src(void *arg);
|
||||
static void intr_disab_eoi_src(void *arg);
|
||||
static void intr_event_stray(void *cookie);
|
||||
#endif
|
||||
|
||||
#ifdef SMP
|
||||
static int assign_cpu;
|
||||
|
||||
@ -81,6 +75,10 @@ static void intr_assign_next_cpu(struct intsrc *isrc);
|
||||
#endif
|
||||
|
||||
static int intr_assign_cpu(void *arg, u_char cpu);
|
||||
static void intr_disable_src(void *arg);
|
||||
#ifdef INTR_FILTER
|
||||
static void intr_event_stray(void *cookie);
|
||||
#endif
|
||||
static void intr_init(void *__dummy);
|
||||
static int intr_pic_registered(struct pic *pic);
|
||||
static void intrcnt_setname(const char *name, int index);
|
||||
@ -135,16 +133,10 @@ intr_register_source(struct intsrc *isrc)
|
||||
vector = isrc->is_pic->pic_vector(isrc);
|
||||
if (interrupt_sources[vector] != NULL)
|
||||
return (EEXIST);
|
||||
#ifdef INTR_FILTER
|
||||
error = intr_event_create(&isrc->is_event, isrc, 0,
|
||||
(mask_fn)isrc->is_pic->pic_enable_source,
|
||||
intr_eoi_src, intr_disab_eoi_src, intr_assign_cpu, "irq%d:",
|
||||
intr_disable_src, (mask_fn)isrc->is_pic->pic_enable_source,
|
||||
(mask_fn)isrc->is_pic->pic_eoi_source, intr_assign_cpu, "irq%d:",
|
||||
vector);
|
||||
#else
|
||||
error = intr_event_create(&isrc->is_event, isrc, 0,
|
||||
(mask_fn)isrc->is_pic->pic_enable_source, intr_assign_cpu, "irq%d:",
|
||||
vector);
|
||||
#endif
|
||||
if (error)
|
||||
return (error);
|
||||
sx_xlock(&intr_table_lock);
|
||||
@ -228,6 +220,15 @@ intr_config_intr(int vector, enum intr_trigger trig, enum intr_polarity pol)
|
||||
return (isrc->is_pic->pic_config_intr(isrc, trig, pol));
|
||||
}
|
||||
|
||||
static void
|
||||
intr_disable_src(void *arg)
|
||||
{
|
||||
struct intsrc *isrc;
|
||||
|
||||
isrc = arg;
|
||||
isrc->is_pic->pic_disable_source(isrc, PIC_EOI);
|
||||
}
|
||||
|
||||
#ifdef INTR_FILTER
|
||||
void
|
||||
intr_execute_handlers(struct intsrc *isrc, struct trapframe *frame)
|
||||
@ -280,24 +281,6 @@ intr_event_stray(void *cookie)
|
||||
"too many stray irq %d's: not logging anymore\n",
|
||||
isrc->is_pic->pic_vector(isrc));
|
||||
}
|
||||
|
||||
static void
|
||||
intr_eoi_src(void *arg)
|
||||
{
|
||||
struct intsrc *isrc;
|
||||
|
||||
isrc = arg;
|
||||
isrc->is_pic->pic_eoi_source(isrc);
|
||||
}
|
||||
|
||||
static void
|
||||
intr_disab_eoi_src(void *arg)
|
||||
{
|
||||
struct intsrc *isrc;
|
||||
|
||||
isrc = arg;
|
||||
isrc->is_pic->pic_disable_source(isrc, PIC_EOI);
|
||||
}
|
||||
#else
|
||||
void
|
||||
intr_execute_handlers(struct intsrc *isrc, struct trapframe *frame)
|
||||
|
@ -340,10 +340,7 @@ ia64_setup_intr(const char *name, int irq, driver_filter_t filter,
|
||||
return (ENOMEM);
|
||||
|
||||
error = intr_event_create(&i->event, (void *)(uintptr_t)vector,
|
||||
0, ia64_intr_unmask,
|
||||
#ifdef INTR_FILTER
|
||||
ia64_intr_eoi, ia64_intr_mask,
|
||||
#endif
|
||||
0, ia64_intr_mask, ia64_intr_unmask, ia64_intr_eoi,
|
||||
NULL, "irq%u:", irq);
|
||||
if (error) {
|
||||
free(i, M_DEVBUF);
|
||||
|
@ -238,43 +238,9 @@ intr_event_update(struct intr_event *ie)
|
||||
CTR2(KTR_INTR, "%s: updated %s", __func__, ie->ie_fullname);
|
||||
}
|
||||
|
||||
#ifndef INTR_FILTER
|
||||
int
|
||||
intr_event_create(struct intr_event **event, void *source, int flags,
|
||||
void (*enable)(void *), int (*assign_cpu)(void *, u_char), const char *fmt,
|
||||
...)
|
||||
{
|
||||
struct intr_event *ie;
|
||||
va_list ap;
|
||||
|
||||
/* The only valid flag during creation is IE_SOFT. */
|
||||
if ((flags & ~IE_SOFT) != 0)
|
||||
return (EINVAL);
|
||||
ie = malloc(sizeof(struct intr_event), M_ITHREAD, M_WAITOK | M_ZERO);
|
||||
ie->ie_source = source;
|
||||
ie->ie_enable = enable;
|
||||
ie->ie_assign_cpu = assign_cpu;
|
||||
ie->ie_flags = flags;
|
||||
ie->ie_cpu = NOCPU;
|
||||
TAILQ_INIT(&ie->ie_handlers);
|
||||
mtx_init(&ie->ie_lock, "intr event", NULL, MTX_DEF);
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(ie->ie_name, sizeof(ie->ie_name), fmt, ap);
|
||||
va_end(ap);
|
||||
strlcpy(ie->ie_fullname, ie->ie_name, sizeof(ie->ie_fullname));
|
||||
mtx_pool_lock(mtxpool_sleep, &event_list);
|
||||
TAILQ_INSERT_TAIL(&event_list, ie, ie_list);
|
||||
mtx_pool_unlock(mtxpool_sleep, &event_list);
|
||||
if (event != NULL)
|
||||
*event = ie;
|
||||
CTR2(KTR_INTR, "%s: created %s", __func__, ie->ie_name);
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
int
|
||||
intr_event_create(struct intr_event **event, void *source, int flags,
|
||||
void (*enable)(void *), void (*eoi)(void *), void (*disab)(void *),
|
||||
intr_event_create(struct intr_event **event, void *source,int flags,
|
||||
void (*disable)(void *), void (*enable)(void *), void (*eoi)(void *),
|
||||
int (*assign_cpu)(void *, u_char), const char *fmt, ...)
|
||||
{
|
||||
struct intr_event *ie;
|
||||
@ -285,10 +251,10 @@ intr_event_create(struct intr_event **event, void *source, int flags,
|
||||
return (EINVAL);
|
||||
ie = malloc(sizeof(struct intr_event), M_ITHREAD, M_WAITOK | M_ZERO);
|
||||
ie->ie_source = source;
|
||||
ie->ie_disable = disable;
|
||||
ie->ie_enable = enable;
|
||||
ie->ie_assign_cpu = assign_cpu;
|
||||
ie->ie_eoi = eoi;
|
||||
ie->ie_disab = disab;
|
||||
ie->ie_assign_cpu = assign_cpu;
|
||||
ie->ie_flags = flags;
|
||||
ie->ie_cpu = NOCPU;
|
||||
TAILQ_INIT(&ie->ie_handlers);
|
||||
@ -306,7 +272,6 @@ intr_event_create(struct intr_event **event, void *source, int flags,
|
||||
CTR2(KTR_INTR, "%s: created %s", __func__, ie->ie_name);
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Bind an interrupt event to the specified CPU. Note that not all
|
||||
@ -943,13 +908,8 @@ swi_add(struct intr_event **eventp, const char *name, driver_intr_t handler,
|
||||
if (!(ie->ie_flags & IE_SOFT))
|
||||
return (EINVAL);
|
||||
} else {
|
||||
#ifdef INTR_FILTER
|
||||
error = intr_event_create(&ie, NULL, IE_SOFT,
|
||||
NULL, NULL, NULL, NULL, "swi%d:", pri);
|
||||
#else
|
||||
error = intr_event_create(&ie, NULL, IE_SOFT,
|
||||
NULL, NULL, "swi%d:", pri);
|
||||
#endif
|
||||
if (error)
|
||||
return (error);
|
||||
if (eventp != NULL)
|
||||
@ -1405,8 +1365,8 @@ intr_event_handle(struct intr_event *ie, struct trapframe *frame)
|
||||
if (ie->ie_eoi != NULL)
|
||||
ie->ie_eoi(ie->ie_source);
|
||||
} else {
|
||||
if (ie->ie_disab != NULL)
|
||||
ie->ie_disab(ie->ie_source);
|
||||
if (ie->ie_disable != NULL)
|
||||
ie->ie_disable(ie->ie_source);
|
||||
}
|
||||
critical_exit();
|
||||
|
||||
|
@ -161,7 +161,6 @@ intr_lookup(u_int irq)
|
||||
return (i);
|
||||
}
|
||||
|
||||
#ifdef INTR_FILTER
|
||||
static void
|
||||
powerpc_intr_eoi(void *arg)
|
||||
{
|
||||
@ -177,7 +176,6 @@ powerpc_intr_mask(void *arg)
|
||||
|
||||
PIC_MASK(pic, irq);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
powerpc_intr_unmask(void *arg)
|
||||
@ -229,10 +227,7 @@ powerpc_setup_intr(const char *name, u_int irq, driver_filter_t filter,
|
||||
|
||||
if (i->event == NULL) {
|
||||
error = intr_event_create(&i->event, (void *)irq, 0,
|
||||
powerpc_intr_unmask,
|
||||
#ifdef INTR_FILTER
|
||||
powerpc_intr_eoi, powerpc_intr_mask,
|
||||
#endif
|
||||
powerpc_intr_mask, powerpc_intr_unmask, powerpc_intr_eoi,
|
||||
NULL, "irq%u:", irq);
|
||||
if (error)
|
||||
return (error);
|
||||
|
@ -329,12 +329,8 @@ intr_controller_register(int vec, const struct intr_controller *ic,
|
||||
* CPU as long as the source of a level sensitive interrupt is
|
||||
* not cleared.
|
||||
*/
|
||||
error = intr_event_create(&ie, iv, 0, intr_enable_eoi,
|
||||
#ifdef INTR_FILTER
|
||||
ic->ic_eoi, ic->ic_disable, NULL, "vec%d:", vec);
|
||||
#else
|
||||
NULL, "vec%d:", vec);
|
||||
#endif
|
||||
error = intr_event_create(&ie, iv, 0, ic->ic_disable, intr_enable_eoi,
|
||||
ic->ic_eoi, NULL, "vec%d:", vec);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
mtx_lock_spin(&intr_table_lock);
|
||||
|
@ -72,12 +72,10 @@ struct intr_event {
|
||||
struct mtx ie_lock;
|
||||
void *ie_source; /* Cookie used by MD code. */
|
||||
struct intr_thread *ie_thread; /* Thread we are connected to. */
|
||||
void (*ie_disable)(void *);
|
||||
void (*ie_enable)(void *);
|
||||
int (*ie_assign_cpu)(void *, u_char);
|
||||
#ifdef INTR_FILTER
|
||||
void (*ie_eoi)(void *);
|
||||
void (*ie_disab)(void *);
|
||||
#endif
|
||||
int (*ie_assign_cpu)(void *, u_char);
|
||||
int ie_flags;
|
||||
int ie_count; /* Loop counter. */
|
||||
int ie_warncnt; /* Rate-check interrupt storm warns. */
|
||||
@ -130,18 +128,11 @@ int intr_event_add_handler(struct intr_event *ie, const char *name,
|
||||
driver_filter_t filter, driver_intr_t handler, void *arg,
|
||||
u_char pri, enum intr_type flags, void **cookiep);
|
||||
int intr_event_bind(struct intr_event *ie, u_char cpu);
|
||||
#ifndef INTR_FILTER
|
||||
int intr_event_create(struct intr_event **event, void *source,
|
||||
int flags, void (*enable)(void *),
|
||||
int (*assign_cpu)(void *, u_char), const char *fmt, ...)
|
||||
__printflike(6, 7);
|
||||
#else
|
||||
int intr_event_create(struct intr_event **event, void *source,
|
||||
int flags, void (*enable)(void *), void (*eoi)(void *),
|
||||
void (*disab)(void *), int (*assign_cpu)(void *, u_char),
|
||||
int flags, void (*disable)(void *), void (*enable)(void *),
|
||||
void (*eoi)(void *), int (*assign_cpu)(void *, u_char),
|
||||
const char *fmt, ...)
|
||||
__printflike(8, 9);
|
||||
#endif
|
||||
int intr_event_destroy(struct intr_event *ie);
|
||||
int intr_event_remove_handler(void *cookie);
|
||||
#ifndef INTR_FILTER
|
||||
|
Loading…
Reference in New Issue
Block a user