LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   kernel driver question 2.6.12 (https://www.linuxquestions.org/questions/programming-9/kernel-driver-question-2-6-12-a-675329/)

marcm 10-09-2008 11:09 AM

kernel driver question 2.6.12
 
Hello all,
I am fairly new to linux but not to C (fairly compitent) and understand some about the operating system.

I have been trying to implement some code that has been working well in user space but the overhead is too much and there is no simple way to open its functionality to more user.

I have currently implemented a pipe to allow a user to read the data that I have available in my fifo.

So I get an callback from hardware
memcpy into my fifo
pthread listens via non blocking open on pipe.
I then do non blocking writes to pipe.

I have subsiqently attempted to move the code into a kernel driver so that I can act as a basic char device and using the open close and read functions so I can serve multiple readers.

All is simple I can get the basic framework compiling and I can do the simple cat of the device to show the open read and close in operation.

I then ported accross the code that receives the callback from hardware and copies into a buffer. The problem I am facing is that in order to access the hardware now it is in another kernel driver (which I had hacked into previously but i need to be stand alone)

To access this kernel driver I need to use ioctls but from what I am experiencing I cannot open a dev device from a .ko and I cannot use ioctls from a .ko

I get a problem when linking that there are unknown references;

*** Warning: "b__set_error" [/opt/sandbox/module.ko] undefined!
*** Warning: "pthread_mutex_lock" [/opt/sandbox/module.ko] undefined!
*** Warning: "pthread_mutex_unlock" [/opt/sandbox/module.ko] undefined!
*** Warning: "b_kernel2user" [/opt/sandbox/module.ko] undefined!
*** Warning: "proc_open" [/opt/sandbox/module.ko] undefined!
*** Warning: "errno" [/opt/sandbox/module.ko] undefined!
*** Warning: "ioctl" [/opt/sandbox/module.ko] undefined!


but I have included the appropriate header files.


#include <linux/proc_fs.h>
#include <sys/ioctl.h>
#include <linux/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <bits/sigset.h>
#include <pthread.h>
//#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>


I cant find anywhere a list of functionality that is available to me from a .ko

If anyone can help or point me in the right direction I would be greatful.


I should add that I am cross compiling for an embedded platform that is using the UcLinux and 2.6.12 kernel.

Thanks
Marc.

marcm 10-10-2008 05:24 AM

Ok I'll answer my own question.

The Warning is nothing to worry about as long as you know that the appropriate kenel driver will be loaded before you try and instigate the driver with the warning. The linker is just letting you know that it doesn't know where the exported functions are.

I'm sure that this warning could be removed if I included the .ko's at linking stage so that they can be referenced.

With regards to the ioctl calls. DONT DO IT, or at least you shouldnt need to if you are in kernel space you have access the the public functions of the other drivers you should be accessing. If you do have a need to ioctl in user space it can be done by wrapping the calls with the following

mm_segment_t fs;

fs = get_fs(); /* save previous value */
set_fs (get_ds()); /* use kernel limit */

/* system calls can be invoked */

set_fs(fs); /* restore before returning to user space */


So hopefully this will help someone somewhere who has the same problem.


All times are GMT -5. The time now is 12:18 AM.