public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* PCI device driver writing newbie trouble
@ 2006-04-20 15:04 Bert Thomas
  2006-04-22  6:00 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Bert Thomas @ 2006-04-20 15:04 UTC (permalink / raw)
  To: linux-kernel

Hi All,

I'm attempting to write a PCI device driver. I've read chapters 2, 9 and 
12 of the linux device driver book (3rd ed) and it got me going with the 
code below. However, I never see the message printed from cif50_probe, 
so appearantly the kernel doesn't consider my driver the correct driver 
for the hardware.

I tried to load the driver with insmod, but I also rebooted the system 
in the hope that some part of the kernel would find the hardware and try 
to load my driver. Is that how it is supposed to work? At least my 
driver is listed in /lib/modules/2.6.15.7/modules.pcimap. Modprobe 
doesn't find it, I don't know why. The hardware contains a PLX chip. The 
hardware is found by the kernel, as it correctly shows up in /proc/pci:

   Bus  1, device  13, function  0:
     Class 0680: PCI device 10b5:9050 (rev 1).
       IRQ 5.
       Non-prefetchable 32 bit memory at 0xd1005000 [0xd100507f].
       I/O at 0xd100 [0xd17f].
       Non-prefetchable 32 bit memory at 0xd1000000 [0xd1001fff].

Also in the corresponding /sys files.

Does anyone have a suggestion why my probe function is not being called?

TIA
Bert

#include <linux/init.h>
#include <linux/module.h>
#include <linux/pci.h>
MODULE_LICENSE("Dual BSD/GPL");

static const struct pci_device_id cif50_ids[] = {
         {
         .vendor = 0x10B5,
         .device = 0x9050,
         .subvendor = PCI_ANY_ID, //0x10B5,
         .subdevice = PCI_ANY_ID, //0x1080,
         .class = PCI_ANY_ID,
         .class_mask = PCI_ANY_ID
         },
         { 0 }
};

MODULE_DEVICE_TABLE(pci,cif50_ids);

int cif50_probe(struct pci_dev *dev, const struct pci_device_id *id)
{
   printk("<1>Joehoe, de kernel wil me een PCI device geven!\n");
   return -1;
}

void cif50_remove(struct pci_dev *dev)
{
}

static struct pci_driver pci_driver = {
         .name = "cif50pb",
         .id_table = cif50_ids,
         .probe = cif50_probe,
         .remove = cif50_remove,
};
static int hello_init(void)
{
   printk("<1>Hello, world\n");
   return pci_register_driver(&pci_driver);
}
static void hello_exit(void)
{
   printk("<1>Goodbye cruel world\n");
   pci_unregister_driver(&pci_driver);
}
module_init(hello_init);
module_exit(hello_exit);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PCI device driver writing newbie trouble
  2006-04-20 15:04 PCI device driver writing newbie trouble Bert Thomas
@ 2006-04-22  6:00 ` Greg KH
  2006-04-23  7:50   ` Pekka Enberg
  0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2006-04-22  6:00 UTC (permalink / raw)
  To: Bert Thomas; +Cc: linux-kernel

On Thu, Apr 20, 2006 at 04:04:07PM +0100, Bert Thomas wrote:
> Hi All,
> 
> I'm attempting to write a PCI device driver. I've read chapters 2, 9 and 
> 12 of the linux device driver book (3rd ed) and it got me going with the 
> code below. However, I never see the message printed from cif50_probe, 
> so appearantly the kernel doesn't consider my driver the correct driver 
> for the hardware.
> 
> I tried to load the driver with insmod, but I also rebooted the system 
> in the hope that some part of the kernel would find the hardware and try 
> to load my driver. Is that how it is supposed to work? At least my 
> driver is listed in /lib/modules/2.6.15.7/modules.pcimap. Modprobe 
> doesn't find it, I don't know why. The hardware contains a PLX chip. The 
> hardware is found by the kernel, as it correctly shows up in /proc/pci:
> 
>   Bus  1, device  13, function  0:
>     Class 0680: PCI device 10b5:9050 (rev 1).
>       IRQ 5.
>       Non-prefetchable 32 bit memory at 0xd1005000 [0xd100507f].
>       I/O at 0xd100 [0xd17f].
>       Non-prefetchable 32 bit memory at 0xd1000000 [0xd1001fff].
> 
> Also in the corresponding /sys files.
> 
> Does anyone have a suggestion why my probe function is not being called?
> 
> TIA
> Bert
> 
> #include <linux/init.h>
> #include <linux/module.h>
> #include <linux/pci.h>
> MODULE_LICENSE("Dual BSD/GPL");
> 
> static const struct pci_device_id cif50_ids[] = {
>         {
>         .vendor = 0x10B5,
>         .device = 0x9050,
>         .subvendor = PCI_ANY_ID, //0x10B5,
>         .subdevice = PCI_ANY_ID, //0x1080,
>         .class = PCI_ANY_ID,
>         .class_mask = PCI_ANY_ID
>         },

Try the PCI_DEVICE() macro here instead.

But that should not matter, this should work, I don't know why it
doesn't sorry.

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PCI device driver writing newbie trouble
  2006-04-22  6:00 ` Greg KH
@ 2006-04-23  7:50   ` Pekka Enberg
  2006-04-23 16:02     ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Pekka Enberg @ 2006-04-23  7:50 UTC (permalink / raw)
  To: Greg KH; +Cc: Bert Thomas, linux-kernel

On Thu, Apr 20, 2006 at 04:04:07PM +0100, Bert Thomas wrote:
> > static const struct pci_device_id cif50_ids[] = {
> >         {
> >         .vendor = 0x10B5,
> >         .device = 0x9050,
> >         .subvendor = PCI_ANY_ID, //0x10B5,
> >         .subdevice = PCI_ANY_ID, //0x1080,
> >         .class = PCI_ANY_ID,
> >         .class_mask = PCI_ANY_ID
> >         },

On 4/22/06, Greg KH <greg@kroah.com> wrote:
> Try the PCI_DEVICE() macro here instead.
>
> But that should not matter, this should work, I don't know why it
> doesn't sorry.

No device class will ever match the above class and class_mask.
Changing them to zero makes it work according to Bert.

                                                   Pekka

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PCI device driver writing newbie trouble
  2006-04-23  7:50   ` Pekka Enberg
@ 2006-04-23 16:02     ` Greg KH
  0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2006-04-23 16:02 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Bert Thomas, linux-kernel

On Sun, Apr 23, 2006 at 10:50:38AM +0300, Pekka Enberg wrote:
> On Thu, Apr 20, 2006 at 04:04:07PM +0100, Bert Thomas wrote:
> > > static const struct pci_device_id cif50_ids[] = {
> > >         {
> > >         .vendor = 0x10B5,
> > >         .device = 0x9050,
> > >         .subvendor = PCI_ANY_ID, //0x10B5,
> > >         .subdevice = PCI_ANY_ID, //0x1080,
> > >         .class = PCI_ANY_ID,
> > >         .class_mask = PCI_ANY_ID
> > >         },
> 
> On 4/22/06, Greg KH <greg@kroah.com> wrote:
> > Try the PCI_DEVICE() macro here instead.
> >
> > But that should not matter, this should work, I don't know why it
> > doesn't sorry.
> 
> No device class will ever match the above class and class_mask.
> Changing them to zero makes it work according to Bert.

Ah, yeah, that would work, good catch.  If you used the PCI_DEVICE()
macro, it would have also worked :)

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-04-23 16:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-20 15:04 PCI device driver writing newbie trouble Bert Thomas
2006-04-22  6:00 ` Greg KH
2006-04-23  7:50   ` Pekka Enberg
2006-04-23 16:02     ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox