From owner-freebsd-drivers@FreeBSD.ORG Wed Sep 29 17:57:13 2010 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EAFB3106566C for ; Wed, 29 Sep 2010 17:57:13 +0000 (UTC) (envelope-from dsriniv@ncsu.edu) Received: from mail-wy0-f182.google.com (mail-wy0-f182.google.com [74.125.82.182]) by mx1.freebsd.org (Postfix) with ESMTP id 96CDA8FC14 for ; Wed, 29 Sep 2010 17:57:02 +0000 (UTC) Received: by wyb32 with SMTP id 32so5688wyb.13 for ; Wed, 29 Sep 2010 10:56:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.188.211 with SMTP id a61mr2851187wen.15.1285782819378; Wed, 29 Sep 2010 10:53:39 -0700 (PDT) Received: by 10.216.133.89 with HTTP; Wed, 29 Sep 2010 10:53:39 -0700 (PDT) In-Reply-To: <201009291341.13483.jhb@freebsd.org> References: <201009291341.13483.jhb@freebsd.org> Date: Wed, 29 Sep 2010 13:53:39 -0400 Message-ID: From: Deepa Srinivasan To: John Baldwin Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-drivers@freebsd.org Subject: Re: Requesting an IRQ X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Sep 2010 17:57:14 -0000 Thanks for your prompt response. I made an error in my earlier post - I'm using FreeBSD 8.1 not 5.0. I'll look into the PCI bus driver code. I've also been looking at the Xenbus code since it does something similar to what I need. - Deepa On Wed, Sep 29, 2010 at 1:41 PM, John Baldwin wrote: > 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 >