Skip to contentSkip to conversation

PCIe device tree support

DISCUSSION Thierry Reding 7 participants 13 messages Feb 20, 2012 – Feb 28, 2012 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,

I would like to add device tree support for the Tegra2 PCIe controller. From what I understand this will require the PCIe code to be rewritten as a proper platform driver in order to be able to instantiate it via the device tree. Is that correct?

Thierry

A message that is not in the archive (sent off-list or not yet received): 20120220191804.GA14499-RM9K5IK7kjIyiCvfTdI0JKcOhU4Rzj621B7CTYaBSLdn68oJJulU0Q@public.gmane.org

#2 lore raw

Thierry Reding wrote at Monday, February 20, 2012 12:18 PM:

Quoted 4 lines

I would like to add device tree support for the Tegra2 PCIe controller. From what I understand this will require the PCIe code to be rewritten as a proper platform driver in order to be able to instantiate it via the device tree. Is that correct?

That's probably the cleanest way, yes.

Is there a drivers/ directory for PCI/PCIe host controllers? Moving the code there might be nice if so, although IIRC when I asked Olof about that a number of months back, he said quite a few host controllers were in arch/...

Thanks for contemplating this; I had it in the back of my mind to do this to get everything converted to DT, but there were always other things going on.

Signature · 1 line
nvpublic
#3 lore raw

[Adding Jesse Barnes and the linux-pci mailing list to CC.]

Quoted 6 lines · Stephen Warren

Thierry Reding wrote at Monday, February 20, 2012 12:18 PM:

Quoted 4 lines

I would like to add device tree support for the Tegra2 PCIe controller. From what I understand this will require the PCIe code to be rewritten as a proper platform driver in order to be able to instantiate it via the device tree. Is that correct?

Quoted 6 lines

That's probably the cleanest way, yes.

Is there a drivers/ directory for PCI/PCIe host controllers? Moving the code there might be nice if so, although IIRC when I asked Olof about that a number of months back, he said quite a few host controllers were in arch/...

Most PCI/PCIe host controller drivers seem to currently be in arch/. Is there a specific reason for this? Would it be acceptable to put any new drivers below drivers/pci/?

Thierry

maintainer
#4 lore raw
Quoted 11 lines · Thierry Reding

[Adding Jesse Barnes and the linux-pci mailing list to CC.]

Quoted 8 lines · Stephen Warren

Thierry Reding wrote at Monday, February 20, 2012 12:18 PM:

Quoted 4 lines

I would like to add device tree support for the Tegra2 PCIe controller. From what I understand this will require the PCIe code to be rewritten as a proper platform driver in order to be able to instantiate it via the device tree. Is that correct?

That's probably the cleanest way, yes.

Quoted 8 lines
Quoted 4 lines

Is there a drivers/ directory for PCI/PCIe host controllers? Moving the code there might be nice if so, although IIRC when I asked Olof about that a number of months back, he said quite a few host controllers were in arch/...

Most PCI/PCIe host controller drivers seem to currently be in arch/. Is there a specific reason for this? Would it be acceptable to put any new drivers below drivers/pci/?

PCI host bridges aren't architected, so discovering them and their properties has historically been mostly architecture-specific. ACPI is one exception (with a driver in drivers/acpi/pci_root.c) and it sounds like device tree might be a similar exception. If you can make a non-arch-specific driver and put it somewhere other than arch/, I'm all in favor of that, especially if you can make it usable by other arches that use device tree. Where to put it? I dunno. drivers/pci/ sounds like a reasonable possibility.

Bjorn

#5 lore raw
Quoted 22 lines · Bjorn Helgaas
Quoted 11 lines · Thierry Reding

[Adding Jesse Barnes and the linux-pci mailing list to CC.]

Quoted 8 lines · Stephen Warren

Thierry Reding wrote at Monday, February 20, 2012 12:18 PM:

Quoted 4 lines

I would like to add device tree support for the Tegra2 PCIe controller. From what I understand this will require the PCIe code to be rewritten as a proper platform driver in order to be able to instantiate it via the device tree. Is that correct?

That's probably the cleanest way, yes.

Quoted 8 lines
Quoted 4 lines

Is there a drivers/ directory for PCI/PCIe host controllers? Moving the code there might be nice if so, although IIRC when I asked Olof about that a number of months back, he said quite a few host controllers were in arch/...

Most PCI/PCIe host controller drivers seem to currently be in arch/. Is there a specific reason for this? Would it be acceptable to put any new drivers below drivers/pci/?

Quoted 8 lines

PCI host bridges aren't architected, so discovering them and their properties has historically been mostly architecture-specific. ACPI is one exception (with a driver in drivers/acpi/pci_root.c) and it sounds like device tree might be a similar exception. If you can make a non-arch-specific driver and put it somewhere other than arch/, I'm all in favor of that, especially if you can make it usable by other arches that use device tree. Where to put it? I dunno. drivers/pci/ sounds like a reasonable possibility.

I don't think it would be possible to write a driver that works for all device tree based boards or architectures. As you said the implementation is very hardware specific and probably couldn't even be generalized among two chipsets of the same architecture.

However there has recently been a lot of work to move out arch-specific drivers for PWM, GPIO and others out of arch/ and into respective directories below drivers/. The reason I asked was because I think the same could be done for PCI/PCIe.

Thierry

#6 lore raw
Quoted 37 lines · On Thu, 23 Feb 2012 07:03:55 +0100 Thierry Reding…
Quoted 22 lines · Bjorn Helgaas
Quoted 11 lines · Thierry Reding

[Adding Jesse Barnes and the linux-pci mailing list to CC.]

Quoted 8 lines · Stephen Warren

Thierry Reding wrote at Monday, February 20, 2012 12:18 PM:

Quoted 4 lines

I would like to add device tree support for the Tegra2 PCIe controller. From what I understand this will require the PCIe code to be rewritten as a proper platform driver in order to be able to instantiate it via the device tree. Is that correct?

That's probably the cleanest way, yes.

Quoted 8 lines
Quoted 4 lines

Is there a drivers/ directory for PCI/PCIe host controllers? Moving the code there might be nice if so, although IIRC when I asked Olof about that a number of months back, he said quite a few host controllers were in arch/...

Most PCI/PCIe host controller drivers seem to currently be in arch/. Is there a specific reason for this? Would it be acceptable to put any new drivers below drivers/pci/?

Quoted 8 lines

PCI host bridges aren't architected, so discovering them and their properties has historically been mostly architecture-specific. ACPI is one exception (with a driver in drivers/acpi/pci_root.c) and it sounds like device tree might be a similar exception. If you can make a non-arch-specific driver and put it somewhere other than arch/, I'm all in favor of that, especially if you can make it usable by other arches that use device tree. Where to put it? I dunno. drivers/pci/ sounds like a reasonable possibility.

I don't think it would be possible to write a driver that works for all device tree based boards or architectures. As you said the implementation is very hardware specific and probably couldn't even be generalized among two chipsets of the same architecture.

Quoted 4 lines

However there has recently been a lot of work to move out arch-specific drivers for PWM, GPIO and others out of arch/ and into respective directories below drivers/. The reason I asked was because I think the same could be done for PCI/PCIe.

I think that makes sense for stuff that may be shared between arches, but host bridges are generally part of the core architecture of the system, so factoring them out would just be code shuffling without any real gain.

But for shared code, drivers/pci is definitely the right place.

Thanks,
Jesse

#7 lore raw
In reply to Thierry Reding

Hi,

Quoted 37 lines · Thierry Reding
Quoted 22 lines · Bjorn Helgaas
Quoted 11 lines · Thierry Reding

[Adding Jesse Barnes and the linux-pci mailing list to CC.]

Quoted 8 lines · Stephen Warren

Thierry Reding wrote at Monday, February 20, 2012 12:18 PM:

Quoted 4 lines

I would like to add device tree support for the Tegra2 PCIe controller. From what I understand this will require the PCIe code to be rewritten as a proper platform driver in order to be able to instantiate it via the device tree. Is that correct?

That's probably the cleanest way, yes.

Quoted 8 lines
Quoted 4 lines

Is there a drivers/ directory for PCI/PCIe host controllers? Moving the code there might be nice if so, although IIRC when I asked Olof about that a number of months back, he said quite a few host controllers were in arch/...

Most PCI/PCIe host controller drivers seem to currently be in arch/. Is there a specific reason for this? Would it be acceptable to put any new drivers below drivers/pci/?

Quoted 8 lines

PCI host bridges aren't architected, so discovering them and their properties has historically been mostly architecture-specific.  ACPI is one exception (with a driver in drivers/acpi/pci_root.c) and it sounds like device tree might be a similar exception.  If you can make a non-arch-specific driver and put it somewhere other than arch/, I'm all in favor of that, especially if you can make it usable by other arches that use device tree.  Where to put it?  I dunno.  drivers/pci/ sounds like a reasonable possibility.

I don't think it would be possible to write a driver that works for all device tree based boards or architectures. As you said the implementation is very hardware specific and probably couldn't even be generalized among two chipsets of the same architecture.

Quoted 4 lines

However there has recently been a lot of work to move out arch-specific drivers for PWM, GPIO and others out of arch/ and into respective directories below drivers/. The reason I asked was because I think the same could be done for PCI/PCIe.

Right. PCI/PCIe host bridges tend to be custom. Well, I'm sure some vendors share some of the IP, but I'm not sure how much of the programming interface comes with that and how much is actually their own. So, either way, there's only a few ARM platforms so far with PCI/PCIe, and I think we can keep the logic under arch/arm for them for now. If more start to show up and we want to move it out, we can do so.

Sorry for being silent on this thread as well -- I've been travelling and offline a bit. It shouldn't be too hard to modify the tegra pcie driver to probe through the device tree, to start with you pretty much just need to describe the register range with a reg property and a compatible field to bind against. Some of the powerpc platforms do similar things, so take a look at how they do it.

-Olof

maintainer
#8 lore raw
In reply to Thierry Reding
Quoted 32 lines · Thierry Reding
Quoted 22 lines · Bjorn Helgaas
Quoted 11 lines · Thierry Reding

[Adding Jesse Barnes and the linux-pci mailing list to CC.]

Quoted 8 lines · Stephen Warren

Thierry Reding wrote at Monday, February 20, 2012 12:18 PM:

Quoted 4 lines

I would like to add device tree support for the Tegra2 PCIe controller. From what I understand this will require the PCIe code to be rewritten as a proper platform driver in order to be able to instantiate it via the device tree. Is that correct?

That's probably the cleanest way, yes.

Quoted 8 lines
Quoted 4 lines

Is there a drivers/ directory for PCI/PCIe host controllers? Moving the code there might be nice if so, although IIRC when I asked Olof about that a number of months back, he said quite a few host controllers were in arch/...

Most PCI/PCIe host controller drivers seem to currently be in arch/. Is there a specific reason for this? Would it be acceptable to put any new drivers below drivers/pci/?

Quoted 8 lines

PCI host bridges aren't architected, so discovering them and their properties has historically been mostly architecture-specific.  ACPI is one exception (with a driver in drivers/acpi/pci_root.c) and it sounds like device tree might be a similar exception.  If you can make a non-arch-specific driver and put it somewhere other than arch/, I'm all in favor of that, especially if you can make it usable by other arches that use device tree.  Where to put it?  I dunno.  drivers/pci/ sounds like a reasonable possibility.

Quoted 4 lines

I don't think it would be possible to write a driver that works for all device tree based boards or architectures. As you said the implementation is very hardware specific and probably couldn't even be generalized among two chipsets of the same architecture.

Host bridges may be hardware-specific, but the PCI core really only needs an abstract description. It needs the bus number aperture, the I/O port apertures, the MMIO apertures, and associated offsets between CPU and PCI bus addresses. I don't know anything about device tree, but I'd be surprised and disappointed if it encodes this basic information in platform-specific ways.

I agree that if the code isn't shared at all, there's no point in putting it in a generic place like drivers/pci/.

Bjorn

#9 lore raw
Quoted 2 lines · Bjorn Helgaas

I agree that if the code isn't shared at all, there's no point in putting it in a generic place like drivers/pci/.

Alright, I'll keep the driver in arch/arm/mach-tegra/ then.

Thierry

#10 lore raw

I too had similar query.
I have written a PCIe host driver for SPEAr platform (ARM Arch). This driver is registered on paltform bus.
It is for Designware IP, so I believe that most of its part can be re-usaable for other person.
have kept common and SPEAr specific part separately.
But, I am not sure about its best location.
I believe best would have been to keep in driver/pci/pcie/hosts/. But it uses pci_common_init function which is specific to ARM platform. So it limits option to arch/arm.
But, if I keep it in arch/arm/mach-spear13xx/ , then it will limit others from using synopsys specific code.

What do you suggest?

Regards
Pratyush

Quoted 7 lines · Thierry Reding
Quoted 2 lines · Bjorn Helgaas

I agree that if the code isn't shared at all, there's no point in putting it in a generic place like drivers/pci/.

Alright, I'll keep the driver in arch/arm/mach-tegra/ then.

Thierry

maintainer
#11 lore raw
Quoted 13 lines · Pratyush Anand

I too had similar query.
I have written a PCIe host driver for SPEAr platform (ARM Arch). This driver is registered on paltform bus.
It is for Designware IP, so I believe that most of its part can be re-usaable for other person.
 have kept common and SPEAr specific part separately.
But,  I am not sure about its best location.
I believe best would have been to keep in driver/pci/pcie/hosts/. But it uses pci_common_init function which is specific to ARM platform. So it limits option to arch/arm.
But, if I keep it in arch/arm/mach-spear13xx/ , then it will limit others from using synopsys specific code.

Quoted 1 line

What do you suggest?

If it uses ARM-specific functions, I think somewhere in arch/arm/ makes the most sense. There are some arches (parisc comes to mind) that do have arch-specific code in drivers/, but until it can be usefully shared, that doesn't seem worthwhile to me. We can always move it later.

Bjorn

#12 lore raw
In reply to Pratyush Anand
Quoted 13 lines · On Fri, 24 Feb 2012 22:46:06 +0530 Pratyush Anand…

I too had similar query.
I have written a PCIe host driver for SPEAr platform (ARM Arch). This driver is registered on paltform bus.
It is for Designware IP, so I believe that most of its part can be re-usaable for other person.
have kept common and SPEAr specific part separately.
But, I am not sure about its best location.
I believe best would have been to keep in driver/pci/pcie/hosts/. But it uses pci_common_init function which is specific to ARM platform. So it limits option to arch/arm.
But, if I keep it in arch/arm/mach-spear13xx/ , then it will limit others from using synopsys specific code.

Quoted 1 line

What do you suggest?

Maybe arch/arm/pci until there are non-ARM users of the IP? In fact, you may want to put off moving it to arch/arm/pci until you have someone to share it with. Premature sharing is like premature optimization after all...

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
maintainer
#13 lore raw
In reply to Bjorn Helgaas
Quoted 39 lines · Bjorn Helgaas
Quoted 32 lines · Thierry Reding
Quoted 22 lines · Bjorn Helgaas
Quoted 11 lines · Thierry Reding

[Adding Jesse Barnes and the linux-pci mailing list to CC.]

Quoted 8 lines · Stephen Warren

Thierry Reding wrote at Monday, February 20, 2012 12:18 PM:

Quoted 4 lines

I would like to add device tree support for the Tegra2 PCIe controller. From what I understand this will require the PCIe code to be rewritten as a proper platform driver in order to be able to instantiate it via the device tree. Is that correct?

That's probably the cleanest way, yes.

Quoted 8 lines
Quoted 4 lines

Is there a drivers/ directory for PCI/PCIe host controllers? Moving the code there might be nice if so, although IIRC when I asked Olof about that a number of months back, he said quite a few host controllers were in arch/...

Most PCI/PCIe host controller drivers seem to currently be in arch/. Is there a specific reason for this? Would it be acceptable to put any new drivers below drivers/pci/?

Quoted 8 lines

PCI host bridges aren't architected, so discovering them and their properties has historically been mostly architecture-specific.  ACPI is one exception (with a driver in drivers/acpi/pci_root.c) and it sounds like device tree might be a similar exception.  If you can make a non-arch-specific driver and put it somewhere other than arch/, I'm all in favor of that, especially if you can make it usable by other arches that use device tree.  Where to put it?  I dunno.  drivers/pci/ sounds like a reasonable possibility.

Quoted 4 lines

I don't think it would be possible to write a driver that works for all device tree based boards or architectures. As you said the implementation is very hardware specific and probably couldn't even be generalized among two chipsets of the same architecture.

Quoted 6 lines

Host bridges may be hardware-specific, but the PCI core really only needs an abstract description.  It needs the bus number aperture, the I/O port apertures, the MMIO apertures, and associated offsets between CPU and PCI bus addresses.  I don't know anything about device tree, but I'd be surprised and disappointed if it encodes this basic information in platform-specific ways.

This made me curious, so I poked around at the callers of of_get_property("bus-range"). Most of these callers are basically PCI host bridge drivers, though they aren't really structured as drivers. They have a very consistent structure of the form:

    for_each_compatible_node(np, "pci", "mpc10x-pci")
        pcibios_alloc_controller()
        of_get_property(dev, "bus-range", &len)
        pci_process_bridge_OF_ranges()
            of_get_property(dev, "ranges", &rlen)
            ...
        pci_create_root_bus()

This basic pattern is used twenty or more times already! There are definitely variations and some platform-specific pieces, but I think there's certainly the possibility of making some of this code more generic, since the information used by the PCI core seems to be described consistently across platforms.

Bjorn