Requesting an IRQ

John Baldwin jhb at freebsd.org
Wed Sep 29 17:44:35 UTC 2010


On Wednesday, September 29, 2010 12:07:27 pm Deepa Srinivasan wrote:
> I'm writing a "pseudo" device driver for FreeBSD 5.0 - i.e. there is no
> physical device backing it. But I need to be able to send an interrupt to it
> from an underlying hypervisor (KVM). FreeBSD runs as a guest OS. I have done
> the same in Linux - wrote a kernel module and used the "request_irq"
> function to allocate an unused interrupt number. When the underlying KVM
> injects an interrupt into the guest OS, the registered interrupt handler
> gets called as expected.
> 
> However, in FreeBSD, I cannot find an equivalent function to "request_irq".
> Going with the available documentation and sample code, I tried modifying a
> PCI driver (this may be overkill for what I'm doing, but still...) and used
> the bus_alloc_resource() and bus_setup_intr() functions. In my OS
> configuration, this results in the "irq9" being allocated to my driver. But
> the same IRQ is also allocated to "acpi0". Now, when I inject an interrupt
> from the hypervisor, it immediately causes an "interrupt storm" and I see
> this message continuously printed: "interrupt storm detected on irq9;
> throttling interrupt source". This happens even without my driver being
> loaded. In the KVM hypervisor code, I set the interrupt to "1" and
> immediately to "0" and I know for sure that this code path is being
> executed.
> 
> My question is:
> - Is it possible to write a pseudo device driver and use something like the
> "request_irq" in Linux to just be able to invoke a callback function in the
> driver?
> - Is it possible to specify the interrupt number that needs to be allocated
> to my device driver so I can ensure that it is not shared with anything
> else?

You can do 2), but you will need to do it by overriding what the bus thinks 
the IRQ is.  Part of the problem is that you need a way to hook up your fake 
IRQ to the MD interrupt code.  This may be hackish to do in 5.0 was the x86 
code does not have the interrupt source abstraction that later versions use to 
implement support for PCI MSI.  In newer versions you would basically provide 
some sort of interrupt provider similar to MSI and then use a modified PCI bus 
driver to allocate an interrupt from your provider and return it via 
bus_alloc_resource().

-- 
John Baldwin


More information about the freebsd-drivers mailing list