You wrote: > On Mon, Nov 22, 2010 at 10:05 PM, Greg KH <greg@xxxxxxxxx> wrote: > > The pci core can tell that a device is found and then does the work to > > I want to understand it in more detail what should I be reading? > > In your book it says in Chapter 12 > "This creates a struct pci_device_id that matches a specific PCI class." > > How is that happening? Well, by writing it down (taken randomly from drivers/scsi/megaraid.c): static struct pci_device_id megaraid_pci_tbl[] = { {PCI_VENDOR_ID_AMI, PCI_DEVICE_ID_AMI_MEGARAID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, Hm, that could get a cleanup. The basic idea is like this: The kernels PCI core scan through all PCI busses it found, collecting a list of devices. These are determined by reading the PCI config space of the corresponding hardware devices. Now that he knows for example there is a device with the vendor id 0x8086 (Intel) and device id 0x1234 (randomly chosen). Now the kernel looks if any already loaded driver said "hey, I take this combination". If it doesn't find one it will look into the modules.alias file (which is in /lib/modules/$(uname -r) and is created by depmod) if there is any driver that claims to be responsible for this device. If yes, then the corresponding module is loaded. If a driver is found by any way the kernel will allocate a struct pci_dev and pass your drivers probe function (which you declare in your struct pci_driver) a pointer to this device. Now you know that a device you feel responsible for exists. The kernel already has filled that struct with a bunch of information from the PCI config space of that device (e.g. which bus it is on). You only need to do the specific initialization for your device (usually accessing non-config space registers) and then you can use it. Eike
Attachment:
signature.asc
Description: This is a digitally signed message part.