Writing a FreeBSD Kernel Module That Handles Arbitrary Interrupt and Device Output

I would like to write a FreeBSD kernel module that can accept some arbitrary interrupts and, upon receiving this interrupt, output some data to an arbitrary device. I am currently facing several problems:

  • How do I get interrupts through a specific IRQ? There is a call on Linux request_irq()

    , but there seems to be no similar API for FreeBSD ... Let's say I want to be able to detect all keyboard interrupts through my kernel module (the keyboard is on irq1), how would I do what? (On Linux, this is possible when invoked free_irq(1, NULL)

    and request_irq(1, ...)

    , correct me if I'm wrong though).

  • Is it possible at all to write a device file under / dev via a kernel module? I read the question Example for reading text files in a FreeBSD kernel module ; after this example, I was able to read / write on regular files, but not the device file in / dev ("device" was a pseudo "echo device" , the classic used in char device examples). I was able to open the file though.
    I do understand that there is a bad file I / O practice in the kernel, but I couldn't think otherwise. If anyone has a better solution please tell me. (i.e. write to device via its device_t

    node?)

The reason I did this in the kernel is because I really need all the interrupts to hit, and running in user space has the risk of no interruptions due to kernel threads preempting user threads (interrupts can occur very often).

I would also appreciate it if someone could provide me with other ideas on how to implement this program (basically the idea is a kernel module that could do work with a microcontroller ...)

+3


source to share


1 answer


You can register an IRQ handler with bus_setup_intr

.



Typically, what to do in this situation is for the driver to collect interrupts and any other useful data and export it through the device, and then (in real time, perhaps?) A process in user space can read from one device, do everything what he needs, and record to another device.

0


source







All Articles