pci device driver

Manoj Nayak manojnayak2005 at gmail.com
Thu Mar 31 09:43:00 EDT 2016


>I am completely new to this PCI device driver so I just wanted to know that
>how kernel build pci_dev structure during pci initialization time. what are
>the pci function are being called


The sequence of routines that lead to pci device initialization.

pci_legacy_init() -> pcibios_scan_root() -> pci_scan_child_bus()->
pci_scan_slot()-> pci_scan_single_device()
->pci_device_add()-> device_add(&dev->dev) -> bus_probe_device() ->
device_attach()




struct pci_dev *pci_scan_single_device(struct pci_bus *bus, int devfn)
{
        struct pci_dev *dev;

        dev = pci_get_slot(bus, devfn);
        if (dev) {
                pci_dev_put(dev);
                return dev;
        }

        dev = pci_scan_device(bus, devfn);
        if (!dev)
                return NULL;

        pci_device_add(dev, bus);

        return dev;
}



/*
 * Read the config data for a PCI device, sanity-check it
 * and fill in the dev structure...
 */
static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn)
{
        struct pci_dev *dev;
        u32 l;

        if (!pci_bus_read_dev_vendor_id(bus, devfn, &l, 60*1000))
                return NULL;

        dev = pci_alloc_dev(bus);
        if (!dev)
                return NULL;

        dev->devfn = devfn;
        dev->vendor = l & 0xffff;
        dev->device = (l >> 16) & 0xffff;

        pci_set_of_node(dev);

        if (pci_setup_device(dev)) {
                pci_bus_put(dev->bus);
                kfree(dev);
                return NULL;
        }

        return dev;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160331/12a88e9b/attachment.html 


More information about the Kernelnewbies mailing list