Musings on PCI busses
Hey all,
I've been having some thoughts on PCI host controller probing and how best to handle it. Currently AFAICT, the SoC platform code explicitly calls the PCI setup code. In all of the existing SoCs this works fine because there is SoC specific platform code which knows what PCI busses to expect on the SoC.
I'm now looking at the case of Xilinx Virtex FPGA support. Because it is an FPGA and the SW view of the design is so flexible and fluid, I'm trying to keep platform code unified for all Virtex platforms. (ie. two radically different board layouts can look identical from the CPU's perspective, or the behaviour of one board can be completely changed with a new bitstream).
Roderick has written a patch to support one of the Xilinx reference designs that includes a PCI host controller. Right now the patch adds a separate platform file, but I'm not comfortable with the approach (despite suggesting it to Roderick in the first place) because it relegates PCI support to only work with the ml510 reference design. ie. PCI will not be automatically supported for anyone who modifies the reference design or adds the PCI host controller to their own design. So I've been thinking of alternatives. Here's what I've come up with.
1) Probe the host controller in an of_platform driver. This has the advantage of simplicity. The probe routine will get automatically called when the PCI host controller device tree node is registered with the of_platform bus. The bus parenthood also gets reflected in the device model and sysfs. The disadvantage is that it defers PCI bus probing until after the of_platform bus is probed (maybe this is okay; maybe this already happens anyway).
2) Probe the host controller in an subsys_initcall(). Advantage is PCI can be probed earlier in the init path. Disadvantages (minor) are that it will always get called if the driver is enabled, and it needs to manually search the device tree for PCI nodes.
I'm leaning towards making it an of_platform driver. Doing so also makes it available to other powerpc processors (not just virtex) in the case where a Xilinx FPGA is welded up to a discrete SoC and a host controller instance is put into the FPGA. (one of those weird things people do when they have an FPGA in their system).
Comments? Opinions?
Cheers,
g.
Signature · 2 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd.
Quoted 7 lines · Grant Likely
1) Probe the host controller in an
of_platformdriver. =A0This has the advantage of simplicity. =A0The probe routine will get automatically called when the PCI host controller device tree node is registered with theof_platformbus. =A0The bus parenthood also gets reflected in the device model and sysfs. =A0The disadvantage is that it defers PCI bus probing until after theof_platformbus is probed (maybe this is okay; maybe this already happens anyway).
This is also what we do on 64-bit systems (well, Cell at this time). There are no fundamental problems with this, just some slightly unexpected interactions e.g. when you have use a PCI serial port as your console before probing PCI.
Making CONFIG_PPC_OF_PLATFORM_PCI probably requires some more consolidation between pci_32.c and pci_64.c, but I'd consider this a good thing.
Arnd <><
From: Arnd Bergmann <[email protected]>
Date: Tue, 19 May 2009 18:12:02 +0200
Quoted 2 lines · Grant Likely
Quoted 1 line
1) Probe the host controller in an
of_platformdriver. =A0This has t=
he
Quoted 4 lines
Quoted 4 lines
advantage of simplicity. =A0The probe routine will get automatically=
called when the PCI host controller device tree node is registered with the
of_platformbus. =A0The bus parenthood also gets reflected =
in
Quoted 1 line
Quoted 1 line
the device model and sysfs. =A0The disadvantage is that it defers PC=
I
Quoted 9 lines
Quoted 3 lines
bus probing until after the
of_platformbus is probed (maybe this is=okay; maybe this already happens anyway).
=
This is also what we do on 64-bit systems (well, Cell at this time). There are no fundamental problems with this, just some slightly unexpected interactions e.g. when you have use a PCI serial port as your console before probing PCI.
This is also what sparc64 does :-)
All of the individual sparc64 PCI controller types have a OF driver and then there is a common layer of OF PCI helper code to do most of the work.
Quoted 17 lines · David Miller
From: Arnd Bergmann <[email protected]>
Date: Tue, 19 May 2009 18:12:02 +0200Quoted 9 lines · Grant Likely
Quoted 7 lines
1) Probe the host controller in an
of_platformdriver. =A0This has the advantage of simplicity. =A0The probe routine will get automatically called when the PCI host controller device tree node is registered with theof_platformbus. =A0The bus parenthood also gets reflected in the device model and sysfs. =A0The disadvantage is that it defers PCI bus probing until after theof_platformbus is probed (maybe this is okay; maybe this already happens anyway).Quoted 4 lines
This is also what we do on 64-bit systems (well, Cell at this time). There are no fundamental problems with this, just some slightly unexpected interactions e.g. when you have use a PCI serial port as your console before probing PCI.
Quoted 5 lines
This is also what sparc64 does :-)
All of the individual sparc64 PCI controller types have a OF driver and then there is a common layer of OF PCI helper code to do most of the work.
Cool, well I have my solution then. :-)
g.
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
Quoted 6 lines · David Miller
This is also what sparc64 does :-)
All of the individual sparc64 PCI controller types have a OF driver and then there is a common layer of OF PCI helper code to do most of the work.
I agree it's a good idea in the long run, but on ppc32, I would be a bit careful due to the amount of historical crap & early board fixup we have that may need working PCI config space accesses and make assumption about when PCI is probed.
We could add the necessary bits for ppc32 to be able to "opt-in" the new scheme on a per board basis I suppose.
Cheers,
Ben.
Quoted 16 lines
1) Probe the host controller in an
of_platformdriver. This has the advantage of simplicity. The probe routine will get automatically called when the PCI host controller device tree node is registered with theof_platformbus. The bus parenthood also gets reflected in the device model and sysfs. The disadvantage is that it defers PCI bus probing until after theof_platformbus is probed (maybe this is okay; maybe this already happens anyway).
=2) Probe the host controller in an
subsys_initcall(). Advantage is PCI can be probed earlier in the init path. Disadvantages (minor) are that it will always get called if the driver is enabled, and it needs to manually search the device tree for PCI nodes.
=
Quoted 5 lines
I'm leaning towards making it an
of_platformdriver. Doing so also makes it available to other powerpc processors (not just virtex) in the case where a Xilinx FPGA is welded up to a discrete SoC and a host controller instance is put into the FPGA. (one of those weird things people do when they have an FPGA in their system).
I agree that something is called for... The first might be slightly simpler, since it would probably transparently deal with the presence of more than one PLB->PCI bridge?
Steve
This email and any attachments are intended for the sole use of the named r= ecipient(s) and contain(s) confidential information that may be proprietary= , privileged or copyrighted under applicable law. If you are not the intend= ed recipient, do not read, copy, or forward this email message or any attac= hments. Delete this email message and any attachments immediately.
Quoted 20 lines · Stephen Neuendorffer
Quoted 14 lines
1) Probe the host controller in an
of_platformdriver. =A0This has the advantage of simplicity. =A0The probe routine will get automatically called when the PCI host controller device tree node is registered with theof_platformbus. =A0The bus parenthood also gets reflected in the device model and sysfs. =A0The disadvantage is that it defers PCI bus probing until after theof_platformbus is probed (maybe this is okay; maybe this already happens anyway).2) Probe the host controller in an
subsys_initcall(). =A0Advantage is PCI can be probed earlier in the init path. =A0Disadvantages (minor) are that it will always get called if the driver is enabled, and it needs to manually search the device tree for PCI nodes.Quoted 5 lines
I'm leaning towards making it an
of_platformdriver. =A0Doing so also makes it available to other powerpc processors (not just virtex) in the case where a Xilinx FPGA is welded up to a discrete SoC and a host controller instance is put into the FPGA. =A0(one of those weird things people do when they have an FPGA in their system).
Quoted 3 lines
I agree that something is called for... =A0The first might be slightly simpler, since it would probably transparently deal with the presence of more than one
PLB->PCIbridge?
Yes, I think so.
g.
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
Quoted 3 lines · Stephen Neuendorffer
I agree that something is called for... The first might be slightly simpler, since it would probably transparently deal with the presence of more than one
PLB->PCIbridge?
The current code doesn't already ?
Cheers,
Ben.
Quoted 7 lines · Benjamin Herrenschmidt
Quoted 3 lines · Stephen Neuendorffer
I agree that something is called for... =A0The first might be slightly simpler, since it would probably transparently deal with the presence of more than one
PLB->PCIbridge?The current code doesn't already ?
Current code doesn't exist in mainline. :-)
And, no, the patch Roderick wrote doesn't handle more than one PHB. No reason it couldn't though.
g.
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
Quoted 11 lines · Grant Likely
Quoted 7 lines · Benjamin Herrenschmidt
Quoted 3 lines · Stephen Neuendorffer
I agree that something is called for... The first might be slightly simpler, since it would probably transparently deal with the presence of more than one
PLB->PCIbridge?The current code doesn't already ?
Current code doesn't exist in mainline. :-)
Well, I was thinking about ppc4xx_pci :-)
Quoted 2 lines
And, no, the patch Roderick wrote doesn't handle more than one PHB. No reason it couldn't though.
Right, it shouldn't be hard.
Cheers,
Ben.
Quoted 7 lines · Grant Likely
1) Probe the host controller in an
of_platformdriver. This has the advantage of simplicity. The probe routine will get automatically called when the PCI host controller device tree node is registered with theof_platformbus. The bus parenthood also gets reflected in the device model and sysfs. The disadvantage is that it defers PCI bus probing until after theof_platformbus is probed (maybe this is okay; maybe this already happens anyway).
We are doing that on Cell as mentioned by Arnd. However, there are a few issues with that approach. One is that it relies on PCI-hotplug related bits that currently only exist in 64-bit land. Another is that doing so tends to expose various hidden issues or subtle dependencies to the PCI stuff being setup early and probed early.
For example, some of the OF parsing bits may fail to convert memory addresses to IO addresses if the PCI host bridges have not been discovered yet, potentially causing issues with matching of resources between the early serial stuff and the generic serial driver (if you use an IO driven UART, the PCI 8250 driver may not properly figure out that what it's finding in its IO BARs is actually the same port as what it gets from the platform code as the later will end up with memory addresses rather than IO ones). That's one example.
At this stage, I much prefer if we stick to doing the PHB discovery at setup_arch() time, especially since there's other WIP in the area of PCI coming from Kumar and I don't want to mixup multiple source of problems in that area at the same time.
We can revisit that later but we'll have to be very careful.
Cheers,
Ben.
From: Benjamin Herrenschmidt <[email protected]>
Date: Wed, 20 May 2009 13:01:30 +1000
Quoted 8 lines
For example, some of the OF parsing bits may fail to convert memory addresses to IO addresses if the PCI host bridges have not been discovered yet, potentially causing issues with matching of resources between the early serial stuff and the generic serial driver (if you use an IO driven UART, the PCI 8250 driver may not properly figure out that what it's finding in its IO BARs is actually the same port as what it gets from the platform code as the later will end up with memory addresses rather than IO ones). That's one example.
FWIW, I never run into this issue on sparc64 exactly because I fully resolve all resources when I populate the OF device tree in the kernel.
Quoted 12 lines · David Miller
From: Benjamin Herrenschmidt <[email protected]>
Date: Wed, 20 May 2009 13:01:30 +1000Quoted 8 lines
For example, some of the OF parsing bits may fail to convert memory addresses to IO addresses if the PCI host bridges have not been discovered yet, potentially causing issues with matching of resources between the early serial stuff and the generic serial driver (if you use an IO driven UART, the PCI 8250 driver may not properly figure out that what it's finding in its IO BARs is actually the same port as what it gets from the platform code as the later will end up with memory addresses rather than IO ones). That's one example.
Quoted 3 lines
FWIW, I never run into this issue on sparc64 exactly because I fully resolve all resources when I populate the OF device tree in the kernel.
What do you mean by fully resolve ? IE. The issue above is specific to IO space, which you can resolve both as MMIO, or as "IO" which in linux means going through the special mapping for IO which allows the use of the inX/outX instructions...
The later can only be done after we have established the special mapping in question for a given PCI bus IO space, at which point, we know what IO "base" corresponds to the IO space of that bridge. So in the meantime, all we have is an MMIO resource, which is "resolved" in the sense that it does contain all the right bits to get the serial ports (address translation etc...) but isn't an IORESOURCE_IO type resource and thus doesn't contain a magic token we can pass to inX/outX.
One of the issues we may have here on powerpc is that our very early probe of serial ports (so we get some debug output early) may get to those resources while the serial driver later sees the actual IORESOURCE_IO resources coming from the PCI probe, and is unable to figure that they are the same things.
Currently, we do a pass of "conversion" over those early resolved resources just after the PCI bridges have been discovered to check if they happen to land into the IO space of a bridge and then turn them into IORESOURCE_IO tokens.
If we delay the probing of PCI bridges, things can get fishy there.
Cheers,
Ben.
From: Benjamin Herrenschmidt <[email protected]>
Date: Wed, 20 May 2009 16:51:07 +1000
Quoted 13 lines · David Miller
Quoted 12 lines
From: Benjamin Herrenschmidt <[email protected]>
Date: Wed, 20 May 2009 13:01:30 +1000Quoted 8 lines
For example, some of the OF parsing bits may fail to convert memory addresses to IO addresses if the PCI host bridges have not been discovered yet, potentially causing issues with matching of resources between the early serial stuff and the generic serial driver (if you use an IO driven UART, the PCI 8250 driver may not properly figure out that what it's finding in its IO BARs is actually the same port as what it gets from the platform code as the later will end up with memory addresses rather than IO ones). That's one example.
Quoted 8 lines
Quoted 3 lines
FWIW, I never run into this issue on sparc64 exactly because I fully resolve all resources when I populate the OF device tree in the kernel.
What do you mean by fully resolve ? IE. The issue above is specific to IO space, which you can resolve both as MMIO, or as "IO" which in linux means going through the special mapping for IO which allows the use of the inX/outX instructions...
I mean that all OF devices have fully resolved MMIO resources. So very early serial devices that sit in I/O space on sparc64 end up being OF device drivers. See for example, drivers/net/sunsu.c which is simply a 8250 chip that sits behind Sun's I/O space bus that sits on PCI and provides things normally found via ISA on x86 machines. Another example is drivers/serial/sunsab.c
Quoted 5 lines
One of the issues we may have here on powerpc is that our very early probe of serial ports (so we get some debug output early) may get to those resources while the serial driver later sees the actual
IORESOURCE_IOresources coming from the PCI probe, and is unable to figure that they are the same things.
I would make these device drivers OF device drivers.
Another option is to make use of the "address" property if present. You can bypass all of the hassle of figuring out what the 'reg' property resolves to by using that and if the device is the console it is pretty reliable to expect OF to provide that "address" property.
Of course this doesn't work well for non-console devices.
Quoted 11 lines · David Miller
Quoted 4 lines
What do you mean by fully resolve ? IE. The issue above is specific to IO space, which you can resolve both as MMIO, or as "IO" which in linux means going through the special mapping for IO which allows the use of the inX/outX instructions...
I mean that all OF devices have fully resolved MMIO resources. =A0So very early serial devices that sit in I/O space on sparc64 end up being OF device drivers. =A0See for example,
drivers/net/sunsu.cwhich is simply a 8250 chip that sits behind Sun's I/O space bus that sits on PCI and provides things normally found via ISA on x86 machines. =A0Another example isdrivers/serial/sunsab.c
Unfortunately in the embedded powerpc case we don't actually have real OF. We've only got the flattened device tree which usually doesn't itemize the devices behind the PCI bus. Instead we rely on the kernel probing for them.
g.
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
Quoted 13 lines · Grant Likely
Quoted 11 lines · David Miller
Quoted 4 lines
What do you mean by fully resolve ? IE. The issue above is specific to IO space, which you can resolve both as MMIO, or as "IO" which in linux means going through the special mapping for IO which allows the use of the inX/outX instructions...
I mean that all OF devices have fully resolved MMIO resources. So very early serial devices that sit in I/O space on sparc64 end up being OF device drivers. See for example,
drivers/net/sunsu.cwhich is simply a 8250 chip that sits behind Sun's I/O space bus that sits on PCI and provides things normally found via ISA on x86 machines. Another example isdrivers/serial/sunsab.c
Quoted 4 lines
Unfortunately in the embedded powerpc case we don't actually have real OF. We've only got the flattened device tree which usually doesn't itemize the devices behind the PCI bus. Instead we rely on the kernel probing for them.
We -can- itemize the PCI bus, it's up to you.
That leads to another interesting discussion...
On ppc64, we have code that can "create" the pci_bus & pci_dev hierarchy from the OF tree (avoiding the config space probing entirely). This is very efficient and has some advantages such as avoiding touching the BARs for sizing (which mean avoiding to temporarily disable access to devices behind them, which can be useful when it's your serial port or system controller there) etc...
It also have the advantage of avoiding a double PCI probe pass when the FW already did it and since most FW do ...
I'm tempted to extract that code and stick it in a drivers/pci/probe_of.c or something like that for more generic usage. We also have a per-bus hook that allows to switch to "real" config space probing at any point of the hierarchy (for example, you can setup things so that only on-board devices are in OF and probed that away and anything on your slot gets probed by linux using config space, that sort of thing).
Cheers,
Ben.
Quoted 2 lines · Benjamin Herrenschmidt
Quoted 1 line · Grant Likely
On Wed, May 20, 2009 at 1:24 PM, David Miller <[email protected]> wrot=
e:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
What do you mean by fully resolve ? IE. The issue above is specific t=
o
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
IO space, which you can resolve both as MMIO, or as "IO" which in lin=
ux
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
means going through the special mapping for IO which allows the use o=
f
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 1 line
the inX/outX instructions...
I mean that all OF devices have fully resolved MMIO resources. =A0So very early serial devices that sit in I/O space on sparc64 end up being OF device drivers. =A0See for example,
drivers/net/sunsu.cwhich is simply a 8250 chip that sits behind Sun's I/O space bus that sits on PCI and provides things normally found via ISA on x86 machines. =A0Another example isdrivers/serial/sunsab.c
Quoted 6 lines
Quoted 4 lines
Unfortunately in the embedded powerpc case we don't actually have real OF. =A0We've only got the flattened device tree which usually doesn't itemize the devices behind the PCI bus. =A0Instead we rely on the kernel probing for them.
We -can- itemize the PCI bus, it's up to you.
Yes, we could. But I don't think it makes any sense to for the FDT case. The firmware infrastructure is not in place to fill out the device tree with the PCI bus layout for the off board devices.
Quoted 13 lines
That leads to another interesting discussion...
On ppc64, we have code that can "create" the
pci_bus&pci_devhierarchy from the OF tree (avoiding the config space probing entirely). This is very efficient and has some advantages such as avoiding touching the BARs for sizing (which mean avoiding to temporarily disable access to devices behind them, which can be useful when it's your serial port or system controller there) etc...It also have the advantage of avoiding a double PCI probe pass when the FW already did it and since most FW do ...
Quoted 7 lines
I'm tempted to extract that code and stick it in a
drivers/pci/probe_of.cor something like that for more generic usage. We also have a per-bus hook that allows to switch to "real" config space probing at any point of the hierarchy (for example, you can setup things so that only on-board devices are in OF and probed that away and anything on your slot gets probed by linux using config space, that sort of thing).
That would be interesting.
g.
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
From: Benjamin Herrenschmidt <[email protected]>
Date: Thu, 21 May 2009 07:59:42 +1000
Quoted 10 lines
On ppc64, we have code that can "create" the
pci_bus&pci_devhierarchy from the OF tree (avoiding the config space probing entirely). This is very efficient and has some advantages such as avoiding touching the BARs for sizing (which mean avoiding to temporarily disable access to devices behind them, which can be useful when it's your serial port or system controller there) etc...It also have the advantage of avoiding a double PCI probe pass when the FW already did it and since most FW do ...
Quoted 7 lines
I'm tempted to extract that code and stick it in a
drivers/pci/probe_of.cor something like that for more generic usage. We also have a per-bus hook that allows to switch to "real" config space probing at any point of the hierarchy (for example, you can setup things so that only on-board devices are in OF and probed that away and anything on your slot gets probed by linux using config space, that sort of thing).
This is exactly what sparc64 does as well, I took the powerpc code. :)
It also avoids a bunch of bugs that get unearthed as a result of scanning the entire hierarchy with PCI config access "pokes". Some PCI controllers hang when certain PCI config space addresses are accessed, meanwhile some hypervisor versions don't generate the bus timeout exception properly on PCI config accesses to nonexisting devices, the list is endless.
And all of that went away when I imported the ppc64 code to do this using the OF device tree.
So if you put this in a common place, let's consolidate the differences accumulated in the sparc64 code so I can use it too :-)
Quoted 9 lines · David Miller
This is exactly what sparc64 does as well, I took the powerpc code. :)
It also avoids a bunch of bugs that get unearthed as a result of scanning the entire hierarchy with PCI config access "pokes". Some PCI controllers hang when certain PCI config space addresses are accessed, meanwhile some hypervisor versions don't generate the bus timeout exception properly on PCI config accesses to nonexisting devices, the list is endless.
Quoted 5 lines
And all of that went away when I imported the ppc64 code to do this using the OF device tree.
So if you put this in a common place, let's consolidate the differences accumulated in the sparc64 code so I can use it too :-)
Allright, I'll give that a go asap, maybe tomorrow.
Cheers,
Ben.
Quoted 7 lines
I mean that all OF devices have fully resolved MMIO resources. So very early serial devices that sit in I/O space on sparc64 end up being OF device drivers. See for example,
drivers/net/sunsu.cwhich is simply a 8250 chip that sits behind Sun's I/O space bus that sits on PCI and provides things normally found via ISA on x86 machines. Another example isdrivers/serial/sunsab.c
Right. On Cell, we use the "normal" 8250 driver, via of_serial which basically initializes it from the of device and associated resources.
It gets a bit messy because we -also- create a platform driver that can be matched by 8250, in fact, we have a bit of generic powerpc code that does that early at boot, initializes our low level very early udbg thingy with it and creates the platform devices.
And then the serial port can -also- be detected by 8250_pci.c when it's on a PCI based UART :-)
Now, generally thinks work fine even if you use all 3 drivers because they have the same resources and 8250 has some smarts to figure that out and not re-create ports. It somewhat fails in the case where we end up with IO looking like MMIO on one side and looking like PCI IO on another tho.
We -could- try to standardize on a single of those 3 methods of course. The of_serial one has some appeal but I quite like the platform driver approach at this stage because we have code to handle all sort of weirdo special cases in there (more or less insane device-tree's, weird SoC's, etc...) and still pump out something 8250_platform can grok, and that code can run -very- early and provide a udbg backend for early debug and xmon usage.
Quoted 9 lines
I would make these device drivers OF device drivers.
Another option is to make use of the "address" property if present. You can bypass all of the hassle of figuring out what the 'reg' property resolves to by using that and if the device is the console it is pretty reliable to expect OF to provide that "address" property.
Of course this doesn't work well for non-console devices.
Also we have various broken firmwares with non usable "address" properties to deal with.
Ben.