LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-09-2008, 12:09 PM   #1
marcm
LQ Newbie
 
Registered: Oct 2008
Posts: 2

Rep: Reputation: 0
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.

Last edited by marcm; 10-09-2008 at 12:11 PM. Reason: addition of CC info
 
Old 10-10-2008, 06:24 AM   #2
marcm
LQ Newbie
 
Registered: Oct 2008
Posts: 2

Original Poster
Rep: Reputation: 0
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux kernel driver question niteshg Programming 11 08-06-2008 01:21 AM
usb kernel driver and garmin 200w question unixshell101 Linux - Hardware 3 07-19-2008 06:47 AM
Wireless driver/kernel question Scrapnon Linux - Hardware 1 08-20-2007 11:55 PM
Merging driver w/ kernel question Palamides Slackware 4 05-20-2005 04:02 AM
kernel question - IDE-chipset driver bailmann Debian 1 01-14-2005 09:22 AM


All times are GMT -5. The time now is 07:59 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration