LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 08-12-2008, 06:24 PM   #1
knockout_artist
Member
 
Registered: Sep 2005
Distribution: fedora core 9
Posts: 324

Rep: Reputation: 33
Printk won't "print" from probe() ::::A hello world module-pci device


Good Day,

A very simple hello world kind of module.
It does print message from init and exit routine but from with in probe() function it won't print ant thing.

I suspect probe wont get executed.

Code:
#include <linux/module.h>       /* Needed by all modules */
#include <linux/kernel.h>       /* Needed for KERN_INFO */
#include<linux/pci.h>

#define MY_VENDOR_ID  0x109e
#define MY_DEVICE_ID  0x036e

struct pci_device_id my_driver_pci_table[] __devinitdata = {
  {
   MY_VENDOR_ID,
   PCI_ANY_ID,
   MY_DEVICE_ID,
    0,0
  }, {0},
};

static int __devinit  my_driver_probe(struct pci_dev *pdev, const struct pci_device_id *id)
     {
        pci_enable_device(pdev);
        printk("--------------------------------\n");
        printk("message from inside of probe function \n\n");
        printk("--------------------------------\n");

      }


struct pci_driver  my_pci_driver = {
     .name = "mydrv",
     .probe = my_driver_probe,
//   .remove = __devexit_p(my_driver_remove),
     .id_table = my_driver_pci_table,
     };

static int __init my_driver_init(void)
     {
         pci_register_driver(&my_pci_driver);
         printk("--------------------------------\n");
         printk("Msg from init fonction\n\n");
         printk("--------------------------------\n");
         return 0;
     }

static void __exit my_driver_exit(void)
    {
    pci_unregister_driver(&my_pci_driver);
    printk("un registering hello-1\n");
    }


module_init(my_driver_init);
module_exit(my_driver_exit);
MODULE_DEVICE_TABLE(pci,my_driver_pci_table);
output from /var/log/message

Code:
[root@ku backup]# tail -n 10 /var/log/messages 
Aug 12 14:45:36 ku kernel: --------------------------------
Aug 12 14:46:39 ku kernel: un registering hello-1--------------------------------
Aug 12 14:46:39 ku kernel: Msg from init fonction
Aug 12 14:46:39 ku kernel: 
Aug 12 14:46:39 ku kernel: --------------------------------
Aug 12 14:55:12 ku kernel: un registering hello-1
Aug 12 14:56:49 ku kernel: --------------------------------
Aug 12 14:56:49 ku kernel: Msg from init fonction
Aug 12 14:56:49 ku kernel: 
Aug 12 14:56:49 ku kernel: --------------------------------
[root@ku backup]#
Thanks.
 
Old 08-14-2008, 03:41 AM   #2
giri_blr
LQ Newbie
 
Registered: Jul 2008
Posts: 24

Rep: Reputation: 15
Quote:
Originally Posted by knockout_artist View Post
Good Day,

A very simple hello world kind of module.
It does print message from init and exit routine but from with in probe() function it won't print ant thing.

I suspect probe wont get executed.

Code:
#include <linux/module.h>       /* Needed by all modules */
#include <linux/kernel.h>       /* Needed for KERN_INFO */
#include<linux/pci.h>

#define MY_VENDOR_ID  0x109e
#define MY_DEVICE_ID  0x036e

struct pci_device_id my_driver_pci_table[] __devinitdata = {
  {
   MY_VENDOR_ID,
   PCI_ANY_ID,
   MY_DEVICE_ID,
    0,0
  }, {0},
};

static int __devinit  my_driver_probe(struct pci_dev *pdev, const struct pci_device_id *id)
     {
        pci_enable_device(pdev);
        printk("--------------------------------\n");
        printk("message from inside of probe function \n\n");
        printk("--------------------------------\n");

      }


struct pci_driver  my_pci_driver = {
     .name = "mydrv",
     .probe = my_driver_probe,
//   .remove = __devexit_p(my_driver_remove),
     .id_table = my_driver_pci_table,
     };

static int __init my_driver_init(void)
     {
         pci_register_driver(&my_pci_driver);
         printk("--------------------------------\n");
         printk("Msg from init fonction\n\n");
         printk("--------------------------------\n");
         return 0;
     }

static void __exit my_driver_exit(void)
    {
    pci_unregister_driver(&my_pci_driver);
    printk("un registering hello-1\n");
    }


module_init(my_driver_init);
module_exit(my_driver_exit);
MODULE_DEVICE_TABLE(pci,my_driver_pci_table);
output from /var/log/message

Code:
[root@ku backup]# tail -n 10 /var/log/messages 
Aug 12 14:45:36 ku kernel: --------------------------------
Aug 12 14:46:39 ku kernel: un registering hello-1--------------------------------
Aug 12 14:46:39 ku kernel: Msg from init fonction
Aug 12 14:46:39 ku kernel: 
Aug 12 14:46:39 ku kernel: --------------------------------
Aug 12 14:55:12 ku kernel: un registering hello-1
Aug 12 14:56:49 ku kernel: --------------------------------
Aug 12 14:56:49 ku kernel: Msg from init fonction
Aug 12 14:56:49 ku kernel: 
Aug 12 14:56:49 ku kernel: --------------------------------
[root@ku backup]#
Thanks.
Give a function call to my_driver_probe() from my_driver_init(). Even my_driver_init() is not needed. You can do all your operations from module_init() as follows...
Code:
static int module_init(void)
{
        pci_register_driver(&my_pci_driver);
        printk("--------------------------------\n");
        printk("Msg from init fonction\n\n");
        printk("--------------------------------\n");
        pci_enable_device(pdev);
        printk("--------------------------------\n");
        printk("message from inside of probe function \n\n");
        printk("--------------------------------\n");
        return 0;

}

cheers,
Giri
 
  


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
Trying to Compile "hello world" Kernel Module (please help!) antdengineer Programming 9 12-04-2010 04:07 AM
Unable to compile "hello world" module on openSuse11 knockout_artist Linux - Kernel 6 08-12-2008 04:58 AM
rh9 installation hangs at "PCI: enabling device" rodhatlinux Linux - Newbie 2 05-08-2005 05:35 PM
ls pci shows "Subsystem: Intel Corp.: Unknown device 1011" hugle Linux - Software 0 07-10-2004 02:11 AM
A7N266-VM Motherboard; Hang at "Checking Module Dependencies" if USB Device Connected jfxberns Linux - General 2 04-19-2003 11:12 AM


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

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