Re: Getting bus ID of root bus behind a bridge

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, May 02, 2009 at 11:57:57AM +0000, Lifesaver wrote:
> Matthew Wilcox <matthew <at> wil.cx> writes:
> > You need to be one level down ... stop before you reach bus->self == NULL.
> 
> I am stopping before bus becomes null. which is why bus is not null, but 
> bus->self is. I will try your suggestion tomorrow - stopping one level
> earlier. 

OK, given your explanation below, this isn't the right answer; you need
to stop when you get to a device which is in a slot; on machines with
deep PCIe hierarchies, you might find the wrong bus.

> > I might be able to give a better answer if I understood what you were
> > trying to do here.  Are you looking for something that matches the slot
> > number on the back of the machine?  Are you trying to determine whether
> > two devices are on the same plugin card?  Something else?
> 
> Yes I am trying to programatically find the slot position on the back by 
> looking at pci_dev structure of a device on the card (there are upto 4 such 
> devices on one board)

OK, so we have a different way to find that.  Let me digress for a moment.
There are two different things called 'slot number' in PCI.  The one that
we get from PCI_SLOT(devfn) is simply the number this device has on its
parent bus.  That doesn't necessarily match up to the slot number that
is written on the back of the box.

There are a number of ways to get the slot name that's written on the
back of the box.  ACPI has a suggestion for what it's called (through
the _SUN method).  The DMI tables also have a suggestion.  PCI Hotplug
data structures have a suggestion.  PCI Express sometimes tells you a
slot name.  Sometimes several of these suggestions exist on the same
machine, and they all give you different names for the slot.

Something I started when I was at HP (and Alex Chiang has been improving
and getting merged) is a way for the PCI layer to give that name to you.
It might not always be right, but it's our best guess at the slot name.

You can get this name like so:

while (pdev && !pdev->slot)
	pdev = pdev->bus->self;

if (pdev)
	printk("PCI slot %s\n", pci_slot_name(pdev->slot));
else
	printk("No slot information found\n");

You may need to enable CONFIG_ACPI_PCI_SLOT to get it to work on your
system.

-- 
Matthew Wilcox				Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux