Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
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.
  1. #1
    Just 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;
    }

  2. #2
    Just Joined!
    Join Date
    Jan 2005
    Location
    Toronto, ON, Canada
    Posts
    79
    From www.freeos.com

    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
    I hope it help,

    afrolinux

  3. #3
    Just 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..

  4. #4
    Just Joined!
    Join Date
    Jan 2005
    Location
    Toronto, ON, Canada
    Posts
    79
    Put in Makefile the following entry

    Code:
    obj-m += hello.o
    and compile with :


    Code:
    $make -C /usr/src/linux-`uname -r` SUBDIRS=$PWD modules
    Insert the module with is (extension '.ko' for 2.6.x kernels and '.o' for formers):

    Code:
    insmod ./hello.ko
    For removing

    Code:
    rmmod hello

    afrolinux

  5. #5
    Just Joined!
    Join Date
    Jan 2005
    Location
    Toronto, ON, Canada
    Posts
    79
    Code:
    TARGET  &#58;= hello-1
    WARN    &#58;= -W -Wall -Wstrict-prototypes -Wmissing-prototypes
    INCLUDE &#58;= -isystem /lib/modules/`uname -r`/build/include
    CFLAGS  &#58;= -O2 -DMODULE -D__KERNEL__ $&#123;WARN&#125; $&#123;INCLUDE&#125;
    CC      &#58;= gcc-3.0
    	
    $&#123;TARGET&#125;.o&#58; $&#123;TARGET&#125;.c
    
    .PHONY&#58; clean
    
    clean&#58;
        rm -rf &#123;TARGET&#125;.o
    if you are using 2.4.x kernel you can use the above Makefile and compile just with

    $make

    $insmod hello.o

    afrolinux

  6. #6
    Just Joined!
    Join Date
    Jan 2005
    Posts
    3

    make problem

    this time I got this problem
    /usr/src/linux- no such file or directory..

  7. #7
    Just 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

  8. #8
    Just Joined!
    Join Date
    Jan 2005
    Posts
    3
    thanks for ur advice..

  9. #9
    Just 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

  10. #10
    Just 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?

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •