pci <-> device node mapping

Linda Xie lxie at us.ibm.com
Tue Jun 24 00:29:35 EST 2003


Here is what I have in my driver code for getting pci_dev:

    const struct list head *tmp;
    struct pci_dev *dev;
    list_for_each (tmp, &pci_devices) {
      dev = (struct pci_dev *) pci_dev_g(tmp);
      if(dev && strstr(dev->dev.name, slot->name))
            return dev;

    }
    return NULL;

I think this is more efficient than using pci_device_to_OF_node().

                      Todd Inglett

[ I wrote: ]

> On Fri, 2003-06-20 at 17:14, linas at austin.ibm.com wrote:
> [...]
> > Linda Xie over here is doing some device driver work, where she
> > gets an RTAS event with a firmware location code in it. Based on
> > the location code, she wants to be able to find the corresponding
> > pci_dev structure. What's the best way to do this?
>
> This is nearly trivial in the current implementation by observing the
> subject of this thread :). Loop through the pci_dev's and do this for
> each one until you get a hit:
>
>              struct device_node *dn = pci_device_to_OF_node(dev);
>
>              if (dev) {
>                          char *loc = (char *)get_property(dn,
> "ibm,loc-code", 0);
>                          if (loc && strcmp(loc, myloc_code) == 0)
>                                      return dev;
>              }
>
> I think Greg KH recently eliminated pci_for_each_dev in 2.5 so you'll
> have to iterate with another mechanism.  IIRC, he patched everything to
> iterate with pci_find_device() so you might do the same.

** Sent via the linuxppc64-dev mail list. See http://lists.linuxppc.org/





More information about the Linuxppc64-dev mailing list