Changeset View
Changeset View
Standalone View
Standalone View
head/sys/x86/xen/xen_msi.c
Show All 24 Lines | |||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/bus.h> | #include <sys/bus.h> | ||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/limits.h> | |||||
#include <sys/lock.h> | #include <sys/lock.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/mutex.h> | #include <sys/mutex.h> | ||||
#include <sys/sx.h> | #include <sys/sx.h> | ||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <x86/apicreg.h> | #include <x86/apicreg.h> | ||||
#include <machine/cputypes.h> | #include <machine/cputypes.h> | ||||
#include <machine/md_var.h> | #include <machine/md_var.h> | ||||
Show All 11 Lines | |||||
static u_int msi_last_irq; | static u_int msi_last_irq; | ||||
void | void | ||||
xen_msi_init(void) | xen_msi_init(void) | ||||
{ | { | ||||
MPASS(num_io_irqs > 0); | MPASS(num_io_irqs > 0); | ||||
first_msi_irq = min(MINIMUM_MSI_INT, num_io_irqs); | first_msi_irq = min(MINIMUM_MSI_INT, num_io_irqs); | ||||
num_io_irqs = first_msi_irq + NUM_MSI_INTS; | if (num_msi_irqs > UINT_MAX - first_msi_irq) | ||||
panic("num_msi_irq too high"); | |||||
num_io_irqs = first_msi_irq + num_msi_irqs; | |||||
mtx_init(&msi_lock, "msi", NULL, MTX_DEF); | mtx_init(&msi_lock, "msi", NULL, MTX_DEF); | ||||
} | } | ||||
/* | /* | ||||
* Try to allocate 'count' interrupt sources with contiguous IDT values. | * Try to allocate 'count' interrupt sources with contiguous IDT values. | ||||
*/ | */ | ||||
int | int | ||||
xen_msi_alloc(device_t dev, int count, int maxcount, int *irqs) | xen_msi_alloc(device_t dev, int count, int maxcount, int *irqs) | ||||
{ | { | ||||
int i, ret = 0; | int i, ret = 0; | ||||
mtx_lock(&msi_lock); | mtx_lock(&msi_lock); | ||||
/* If we would exceed the max, give up. */ | /* If we would exceed the max, give up. */ | ||||
if ((msi_last_irq + count) > NUM_MSI_INTS) { | if (msi_last_irq + count > num_msi_irqs) { | ||||
mtx_unlock(&msi_lock); | mtx_unlock(&msi_lock); | ||||
return (ENXIO); | return (ENXIO); | ||||
} | } | ||||
/* Allocate MSI vectors */ | /* Allocate MSI vectors */ | ||||
for (i = 0; i < count; i++) | for (i = 0; i < count; i++) | ||||
irqs[i] = first_msi_irq + msi_last_irq++; | irqs[i] = first_msi_irq + msi_last_irq++; | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |