Results 1 to 10 of 18
PROJECT :To write a generic device driver for pci device.
SOURCES : pci.c & pci.h files in the linux source files.
/usr/src/linux/drivers/pci/pci.c
/usr/include/linux/pci.h
CURRENT STEP : To link the files ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 01-30-2005 #1Just Joined!
- Join Date
- Jan 2005
- Posts
- 12
doubts :To write a generic device driver for pci device.
PROJECT :To write a generic device driver for pci device.
SOURCES : pci.c & pci.h files in the linux source files.
/usr/src/linux/drivers/pci/pci.c
/usr/include/linux/pci.h
CURRENT STEP : To link the files My_prog.c and pci.c
PROBLEM_1 : Unable to form pci.o and to solve its dependencies. Trying to write makefile for it.
PROBLEM_2 : What all #define's and #include's to place in My_prog.c.
My_prog.c is written with just one function call from file pci.h.
Just to see if the whole thing compiles. But we are unable to suceed.
Unable to deal with
#define __KERNEL__. and
#include<modules.h>
#include<linux/config.h>
#include<pci.h>
Code:
//******************My_prog.c**********************
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#include <linux/config.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/proc_fs.h>
#include <linux/pci.h>
int main()
{
struct pci_dev *dev=NULL;
dev = (struct pci_dev *)pci_find_device( 1 , 1 , dev);
if(!dev)
{
printf("\n\n\t\tNO DEVICE FOUND...!!!");
}
else
{
printf("\n\n\t\tDEVICE FOUND...!!!");
}
return 0;
}
- 01-30-2005 #2Just Joined!
- Join Date
- Jan 2005
- Location
- Toronto, ON, Canada
- Posts
- 79
From www.freeos.com
I hope it help,Device drivers in Linux are known as modules and can be loaded dynamically
into the kernel using the insmod command.
A single module can be compiled alone, and also can be linked to the
kernel (here, care has to be taken on the type of driver).
eg: A simple module
#define MODULE
#include <linux/module.h>
int init_module (void) /* Loads a module in the kernel */
{
printk("Hello kernel n");
return 0;
}
void cleanup_module(void) /* Removes module from kernel */
{
printk("GoodBye Kerneln");
}
Compiling the module
# gcc -c hello.c
# insmod hello.o
The output is
Hello kernel
# rmmod hello.o
GoodBye Kernel
afrolinux
- 01-31-2005 #3Just Joined!
- Join Date
- Jan 2005
- Posts
- 3
About insmod problem
I tried ur program in Fedora 3 .I can successfully complie using gcc.
but I got this problem
hello.o (-1 : invalid module format)
I think it may be the problem of insmod.
Anything u wanna suggest to debug..
- 01-31-2005 #4Just Joined!
- Join Date
- Jan 2005
- Location
- Toronto, ON, Canada
- Posts
- 79
Put in Makefile the following entry
and compile with :Code:obj-m += hello.o
Insert the module with is (extension '.ko' for 2.6.x kernels and '.o' for formers):Code:$make -C /usr/src/linux-`uname -r` SUBDIRS=$PWD modules
For removingCode:insmod ./hello.ko
Code:rmmod hello
afrolinux
- 01-31-2005 #5Just Joined!
- Join Date
- Jan 2005
- Location
- Toronto, ON, Canada
- Posts
- 79
if you are using 2.4.x kernel you can use the above Makefile and compile just withCode:TARGET := hello-1 WARN := -W -Wall -Wstrict-prototypes -Wmissing-prototypes INCLUDE := -isystem /lib/modules/`uname -r`/build/include CFLAGS := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE} CC := gcc-3.0 ${TARGET}.o: ${TARGET}.c .PHONY: clean clean: rm -rf {TARGET}.o
$make
$insmod hello.o
afrolinux
- 01-31-2005 #6Just Joined!
- Join Date
- Jan 2005
- Posts
- 3
make problem
this time I got this problem
/usr/src/linux- no such file or directory..
- 01-31-2005 #7Just Joined!
- Join Date
- Jan 2005
- Location
- Toronto, ON, Canada
- Posts
- 79
You have to install the linux source code in order to compile any driver. Most of the header files are in that path. I am sure you have in your distro an rpm which is the source code for linux that match with your current kernel. You should install it. May be for this small program you do not need it (I am not sure in kernels 2.6 though) but any other implementations you need those files.
afrolinux
- 02-04-2005 #8Just Joined!
- Join Date
- Jan 2005
- Posts
- 3
thanks for ur advice..
- 02-04-2005 #9Just Joined!
- Join Date
- Jan 2005
- Location
- Toronto, ON, Canada
- Posts
- 79
You should post in the same treahd your questions if they are related.
The kernel module should be capable of interact with pci functions in kernel and send back and forth to user space in order to be useful to some user space program. You can do this by implementing :
ioctl's in kernel modules :
http://www.tldp.org/LDP/lkmpg/2.6/html/c878.htm#AEN880
proc file inkernel modules:
http://www.tldp.org/LDP/lkmpg/2.6/html/c740.htm#AEN742
Implementing your own syscalls (Not recomended):
http://www.tldp.org/LDP/lkmpg/2.6/html/c964.htm#AEN966
- 05-12-2005 #10Just Joined!
- Join Date
- May 2005
- Posts
- 5
writing pci driver
hello,
iam writing linux pci driver so i have some doubts
what are the different modules ?
how is the flow of this project?


Reply With Quote
