Call user space function from Linux kernel module

I am programming a simple Linux character device driver to output data to a piece of equipment through I / O ports. I have a function that performs floating point operations to calculate the correct output for hardware; unfortunately, this means that I need to store this function in user space, since the Linux kernel does not handle floating point operations very well.

Here's the pseudo-view of the installation (note that this code does nothing concrete, it just shows the relative layout of my code):

User Space Function :

char calculate_output(char x){
    double y = 2.5*x;
    double z = sqrt(y);

    char output = 0xA3;

    if(z > 35.67){
        output = 0xC0;
    }

    return output;
}

Kernelspace Code :

unsigned i;
for(i = 0; i < 300; i++){
    if(inb(INPUT_PORT) & NEED_DATA){
        char seed = inb(SEED_PORT);
        char output = calculate_output(seed);
        outb(output, OUTPUT_PORT);
    }

    /* do some random stuff here */
}

ioctl , , , , calculate_output .

, :

  • (, ioctl)
  • userpace
    • kernelspace ,
    • userpace , (ioctl?),
    • kernelspace
  • kernelspace
  • userpace

, , , , , ?


: , ; , , , , , .

+5
2

, . O_RDWR. :

  • read - , ​​ . , read(), , , .

  • write - , . ​​ .

:

while (1) {
    read(fd, buf, sizeof buf);
    calculate_output(buf, output);
    write(fd, output, sizeof output);
}

- , , / .

, " " , , . , , input_data, input_ready, output_data output_ready, .

, input_ready input_ready waitqueue, wait_event(<output_ready is set>). read wait_event(<input_ready is set>) , . write , , output_data output_ready .

( , ) - - ioperm, iopl /dev/port, , .

+4

, " " , 300 .

, . , , , , , "", , " " ( , , , , ). , , , usermode .

0

All Articles