I programming a device driver to control some hardware via I/O port outputs. In particular, my hardware takes a 16-bit value which is calculated by a rather extensive floating point algorithm (several thousand lines of code).
Naturally, I do not want to be executing floating point code within kernelspace; but I'm in a pickle since my device driver code continually polls an input byte before executing the floating point function.
floating point function:
Code:
unsigned calculate_output(char input){
unsigned output;
/* perform extensive floating point algorithm here to determine output */
return output; /* top 16-bit are don't-care */
}
kernel loop:
Code:
while(inb(LIFE_PORT) & STAY_ALIVE_BIT){
char seed = inb(SEED_PORT);
u16 output = calculate_output(seed); /* evil floating point operations */
u8 lobyte = output & 0xFF;
u8 hibyte = output >> 8;
outb(lobyte, MECHA_PORT1);
outb(hibyte, MECHA_PORT2);
}
I suppose I'm looking for the inverse of
ioctl, where the kernelspace program sends a request data command to the userspace program. Using the
read and
write function on a device file seems difficult since the kernel code is in a loop (would I require a kernel thread?).
I also considered using
ioperm.h, but executing I/O port commands from userspace seems "dirty." Does anyone have any suggestions on how I could achieve the behavior I'm imagining (i.e. separating the floating point algorithm to userspace, while I/O interactions remain in kernelspace)?