Skip to contentSkip to conversation

PCI<->PCI bridges, transparent resource fix

DISCUSSION Benjamin Herrenschmidt 2 participants 7 messages Aug 7, 2002 – Aug 9, 2002 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 11 lines

Not true. Closed means closed by firmware - in the terms of the PCI-PCI bridge, this means that window base > limit. There are _only_ two reasons for "closed" state:
1. There is no io or memory behind the bridge, which is perfectly valid. This bridge (and its respective bus) resource must be ignored (flags = 0).
2. BIOS bug. There _are_ io/mem resources behind the bridge, but any access to these resources will cause machine checks, lockups etc., depends on platform.
In either case "assuming transparent" is totally wrong if the bridge is normal (positive) decoder.

Quoted 4 lines

Not configured (i.e. after reset) state for vast majority of bridges is base == limit == 0, which means minimal io (4K) or mem (1M) window enabled at address 0. Obviously, this is not acceptable for most architectures.

Ok, right, I was indeed talking about ranges that have been disabled by the firmware.

Quoted 3 lines

I'm a bit puzzled. How do these windows look from a) CPU b) PCI bus point of view? And what was a reason for having more than one MMIO window per PCI controller?

Well, it's definitely not that specific since I know several host bridges that have several programmable windows to PCI, and those aren't PPC specifc. In the case of pmacs, the UniNorth bridge forwards up to 7 regions of 256Mb (0x80000000..0x8fffffff, 0x90000000..0x9fffffff, etc... up to 0xe0000000..0xefffffff), each of them beeing selected by a bit setup by the firmware. It then have additional 16 regions of type 0xfx000000 than can also be individually selected, some of them beeing reserved for IO and config space, but one of them beeing typically an additional memory window to the PCI bus.

Quoted 11 lines
Quoted 3 lines

You are clearly talking about (CPU) architecture specific code. PCI-PCI bridges can only forward 3 ranges.

Surely.

Quoted 2 lines
Quoted 2 lines

Currently, that mean we are hard-coding yet another x86 crap in the core kernel code :(

PPC seems to be the only arch with such a weird host bridge design, so I'd talk about PPC rather than x86 crap ;-)

Yes, well ... ;)

Quoted 9 lines
Quoted 8 lines

By chance, is this comment confusing?

	/*
	 * Ugh. We don't know enough about this bridge. Just assume
	 * that it's entirely transparent.
	 */

"entirely" just refers to that one range.

Quoted 7 lines

The comment is _extremely_ confusing. P2P bridge specs are quite clear:
the bridge can support the subtractive decoding (i.e. "transparent") mode, and the way how to place it in this mode is indeed not standardized. But, the subtractive decoding bridge _MUST_ have bit 0 in the ProgIf set to 1. For some reasons, I don't believe that there are any exceptions. And even if they are, we can easily handle them with "quirks".

Ok, here we need Linus answert. We did have a patch in the PPC tree that was consideing closed resources as really closed instead of transparent, and we were told by Linus that there were non standard bridges and various issues in the x86 world with that, and that those would remain transparent. I don't have pointers at hand, but I think this was dicusssed on lkml several monthes ago.

I would _love_ beeing able to simplify even more my code by assuming that the resources are closed (what I really need in most of my cases), or the bridge fully transparent, according to such a bit.

Quoted 6 lines
Quoted 5 lines

Earlier Benjamin wrote:

| - The current code for setting up a transparent resource is broken in
| a couple of ways. It makes assumptions about the layout of the parent
| resources (0 beeing IO, 1 memory, 2 prefetchable memory), while this
| is just not true, especially if your parent is the host bridge.
Quoted 7 lines

Your parent is not a bridge - it's a pci_bus, and this resource layout is pci_bus specific. Note that it's _pointers_ to resources, either to standard PCI-PCI bridge resources, or arch specific resources in the case of the root bus.
The "transparency" code is broken by no means though.
I'm keen to fix that, but at this moment I've ~100K of pending alpha patches which are of higher priority for me... :-\

Well, I do have a case of conflict here where a device below a bridge can't get it's resources allocated because it's considered as conflicting with the bridge itself. The problem disappear if I set the bridge as closed (thoough I get another problem where the IO region is not enabled by the firmware, but that's another matter, I can quirk here).

In most cases, I have to trust the firmware setup as a critical ASIC (the "mac-io" ASIC) tend to be behind a PCI<->PCI bridge and I cannot afford to have access to it disabled nor moved at any time.

This is btw a problem with the current kernel code as the PCI probe code will disable IO/MEM forwarding during probe on the bridge. That means there is a small window of time during which, if I take an interrupt for example, I'll be dead because my interrupt controller (which is part of that "mac-io" ASIC) will be unreachable. But this is a different issue.

Quoted 5 lines

Basically, I suggest something like this for people trusting their firmware setup and therefore using pci_read_bridge_bases():
1. Check bit 0 of the P2P bridge classcode/progif; if set, assume transparent - set all 3 resource pointers to those of the parent bus; ignore windows settings.

I'd set all 4 then, thus the bridge would really be seen as forwarding all the regions of the host bridge, whatever they are.

Since pci_read_bridge_bases() is called by the arch code, I can implement a version doing what you suggest in the arch code and use that. I'll try and let you know.

Quoted 9 lines

2. If cleared, check base/limit settings of windows 0,1,2. If they seem ok, i.e base != 0 && base < limit, allocate these resources properly in the resource tree.
3. At the end of arch specific PCI setup, call either pci_assign_unassigned_resources, or more fine-grained helpers from pci/setup_bus.c. These routines will take care of
a) unallocated P2P bridge resources;
b) regular resources, unassigned due to resource conflicts and other BIOS bugs.

That makes sense. This would also allow to spot that there is no device below a PCI<->PCI bridge when doing that assignement of unassigned resources, and thus to spot that the firmware may have indeed been right to close them and not to bother.

Quoted 2 lines

The above was one of the purposes of the new 2.5 PCI allocation code, although some (relatively small) changes are still needed...

Ok, I'll look into implementing that in the PPC arch code for now

Thanks for your comments,
Ben.

#2 lore raw
Quoted 10 lines · Benjamin Herrenschmidt

Well, it's definitely not that specific since I know several host bridges that have several programmable windows to PCI, and those aren't PPC specifc. In the case of pmacs, the UniNorth bridge forwards up to 7 regions of 256Mb (0x80000000..0x8fffffff, 0x90000000..0x9fffffff, etc... up to 0xe0000000..0xefffffff), each of them beeing selected by a bit setup by the firmware. It then have additional 16 regions of type 0xfx000000 than can also be individually selected, some of them beeing reserved for IO and config space, but one of them beeing typically an additional memory window to the PCI bus.

Ok. Assume that additional window is 0xf2000000-0xf2ffffff.
I'd try the following:
- set the _single_ memory resource of the root bus to 0x80000000-0xf2ffffff;
- create dummy memory type resource 0xf0000000-0xf1ffffff and "claim" it on the root bus. This will prevent all further allocations in the gap between two MMIO windows.
I think it should seriously simplify the things.

Quoted 6 lines

Ok, here we need Linus answert. We did have a patch in the PPC tree that was consideing closed resources as really closed instead of transparent, and we were told by Linus that there were non standard bridges and various issues in the x86 world with that, and that those would remain transparent. I don't have pointers at hand, but I think this was dicusssed on lkml several monthes ago.

I recall that. I do agree with Linus, but only about bridges with class code 0x60401 (subtractive decoders). The details of operating in subtractive decoding mode are beyond the scope of the P2P bridge specs, and probably we don't want to know these details either. "Assuming transparent" is a sufficient workaround in this case.

Some additional notes. The P2P bridge specification says:
"The primary use of a subtractive decoding bridge is to connect
a laptop system to a docking station and support legacy ISA devices in the docking station."

Indeed, that "transparency" code had been added to fix P2P bridge problems on some Dell docking station (reported by Jamal) back in the 2.4.0-test times. Unfortunately, lspci output of that machine hasn't been posted (or I just missed that). However, I'm sure that the problematic bridge did have ProgIf code 1, otherwise that type of machines would have problems running Windows, as MS says:
"A bridge indicates that it performs subtractive decode if its
Programming Interface bit in the PCI Configuration Register is set to

   01h.  Not  all  PCI-to-PCI bridges support subtractive decode. Windows
   will  not  switch  a bridge from positive decode to subtractive decode
   (or  vice  versa) because there is no standard method defined for this

action."

For those who are interested, the entire document (zipped .doc) is
http://download.microsoft.com/download/whistler/hwdev3/1.0/WXP/EN-US/pcibridge-cardbus.exe
Not in the human readable form, sorry. ;-)

Quoted 2 lines

I'd set all 4 then, thus the bridge would really be seen as forwarding all the regions of the host bridge, whatever they are.

There are only 3, as Grant pointed out. :-)

Quoted 4 lines

That makes sense. This would also allow to spot that there is no device below a PCI<->PCI bridge when doing that assignement of unassigned resources, and thus to spot that the firmware may have indeed been right to close them and not to bother.

Exactly.

Ivan.

#3 lore raw
Quoted 7 lines

Ok. Assume that additional window is 0xf2000000-0xf2ffffff.
I'd try the following:
- set the _single_ memory resource of the root bus to 0x80000000-0xf2ffffff;
- create dummy memory type resource 0xf0000000-0xf1ffffff and "claim" it on the root bus. This will prevent all further allocations in the gap between two MMIO windows.
I think it should seriously simplify the things.

Unfortunately that wouldn't work as I actually have 3 host bridges on these models, and the windows can be "mixed". One host can have 0x80000000 to 0x9ffffffff (and one region at 0xfx000000), The next one can have 0xa0000000 to 0xaffffffff and another region at 0xfx000000, etc...

Quoted 7 lines
Quoted 6 lines

Ok, here we need Linus answert. We did have a patch in the PPC tree that was consideing closed resources as really closed instead of transparent, and we were told by Linus that there were non standard bridges and various issues in the x86 world with that, and that those would remain transparent. I don't have pointers at hand, but I think this was dicusssed on lkml several monthes ago.

Quoted 5 lines

I recall that. I do agree with Linus, but only about bridges with class code 0x60401 (subtractive decoders). The details of operating in subtractive decoding mode are beyond the scope of the P2P bridge specs, and probably we don't want to know these details either. "Assuming transparent" is a sufficient workaround in this case.

Agreed.

Quoted 23 lines

Some additional notes. The P2P bridge specification says:
"The primary use of a subtractive decoding bridge is to connect a laptop system to a docking station and support legacy ISA devices in the docking station."

Indeed, that "transparency" code had been added to fix P2P bridge problems on some Dell docking station (reported by Jamal) back in the 2.4.0-test times. Unfortunately, lspci output of that machine hasn't been posted (or I just missed that). However, I'm sure that the problematic bridge did have ProgIf code 1, otherwise that type of machines would have problems running Windows, as MS says:
"A bridge indicates that it performs subtractive decode if its
Programming Interface bit in the PCI Configuration Register is set to

  01h.  Not  all  PCI-to-PCI bridges support subtractive decode. Windows
  will  not  switch  a bridge from positive decode to subtractive decode
  (or  vice  versa) because there is no standard method defined for this

action."

For those who are interested, the entire document (zipped .doc) is
http://download.microsoft.com/download/whistler/hwdev3/1.0/WXP/EN-US/
pcibridge-cardbus.exe
Not in the human readable form, sorry. ;-)

Quoted 4 lines
Quoted 2 lines

I'd set all 4 then, thus the bridge would really be seen as forwarding all the regions of the host bridge, whatever they are.

There are only 3, as Grant pointed out. :-)

Well, I as pointed out, I may actually need all 4 regions of the host ;)

Anyway, since we agree on copying down the parent regions, and the pci_bus stucture holds 4 resource slots, then let's copy them all down.

I'll write some code about that when I'm back from vacation and we'll see what's up. I may end up adding a quirk call inside the pci_read_bridge_bases
functions so that it's behaviour can be easily overriden if we ever meet a non-strandard enough bridge to be transparent without having ProgIf code 1

Ben.

#4 lore raw
Quoted 5 lines · Benjamin Herrenschmidt

Unfortunately that wouldn't work as I actually have 3 host bridges on these models, and the windows can be "mixed". One host can have 0x80000000 to 0x9ffffffff (and one region at 0xfx000000), The next one can have 0xa0000000 to 0xaffffffff and another region at 0xfx000000, etc...

Please elaborate. I always thought that 3 host bridges (controllers, hoses and so on) mean 3 physically separated PCI buses. In this case the approach with only one root bus structure is plain wrong - resource allocation won't work correctly.
You should have 3 root buses, and apply suggested workaround to all 3. Or am I missing something?

Quoted 3 lines
Quoted 1 line

There are only 3, as Grant pointed out. :-)

Well, I as pointed out, I may actually need all 4 regions of the host ;)

I still hope you won't :-)

Quoted 2 lines

Anyway, since we agree on copying down the parent regions, and the pci_bus stucture holds 4 resource slots, then let's copy them all down.

I think 4th slot makes no sense in terms of the PCI bus and should be killed. I guess that initially it was intended for cardbus drivers (for 2nd IO window), but it seems that they don't use pci_bus->resource pointers at all.

Quoted 5 lines

I'll write some code about that when I'm back from vacation and we'll see what's up. I may end up adding a quirk call inside the pci_read_bridge_bases
functions so that it's behaviour can be easily overriden if we ever meet a non-strandard enough bridge to be transparent without having ProgIf code 1

This can be easily done with generic quirks:

	{ PCI_FIXUP_HEADER, PCI_VENDOR_ID_XXX, PCI_DEVICE_ID_BAD_BRIDGE,
	  quirk_transparent_bridge }
...
static void __init
quirk_transparent_bridge(struct pci_dev *dev)
{
	dev->class |= 1;
}

Ivan.

#5 lore raw
Quoted 7 lines · Benjamin Herrenschmidt
Quoted 5 lines

Unfortunately that wouldn't work as I actually have 3 host bridges on these models, and the windows can be "mixed". One host can have 0x80000000 to 0x9ffffffff (and one region at 0xfx000000), The next one can have 0xa0000000 to 0xaffffffff and another region at 0xfx000000, etc...

Quoted 6 lines

Please elaborate. I always thought that 3 host bridges (controllers, hoses and so on) mean 3 physically separated PCI buses. In this case the approach with only one root bus structure is plain wrong - resource allocation won't work correctly.
You should have 3 root buses, and apply suggested workaround to all 3. Or am I missing something?

I do have 3 root busses, that's not a problem. But their resources are all childs of the global iomem_resources which sorta represents the system memory bus. (I do eventually declare additional resources as child of this one, not behind any pci host bridge, like some memory controller registers).

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

There are only 3, as Grant pointed out. :-)

Well, I as pointed out, I may actually need all 4 regions of the host ;)

I still hope you won't :-)

Well... at one point, I had more than that :( I added some code to coalesce the ranges provided by the firmware and figured out it mostly turned into 1 big range of 256 or 512Mb, one small in the 0xfx000000 region, and one IO. So that should fit. But nothing prevents the firmware from setting things up differently.
But yes, at least on pmac, I think we now don't have more than 3 in real life, though I can't speak for IBM high end stations.

We have a routine that takes whatever ranges are provided by openfirmware and then populates the host bridge resources. This routine can fill up to 4 slots and doesn't force any ordering on the way those are filled. This may have to be changed, though currently, I think the case of pci_read_bridge_bases() with a transparent bridge was the only common routine we used that relied on this parent resource ordering assumption, and this will be going away with your proposed patch.

Quoted 7 lines
Quoted 2 lines

Anyway, since we agree on copying down the parent regions, and the pci_bus stucture holds 4 resource slots, then let's copy them all down.

I think 4th slot makes no sense in terms of the PCI bus and should be killed. I guess that initially it was intended for cardbus drivers (for 2nd IO window), but it seems that they don't use pci_bus->resource pointers at all.

They should probably then, but I haven't quite looked at the cardbus code yet. I still think the resource management should be generic enough not to rely on ordering & number of resources, as the actual informations we want out of the parent resources are already encoded in the flags (that is knowing if we deal with the parent IO window, MEM window, or MEM+prefetch window). We have generic routines working only on flags for finding parents when populating the tree already.

But that isn't an urgent issue nor difficult to work around if needed, so let's put that on hold until I can prove we really need all of those ;)

Quoted 5 lines
Quoted 5 lines

I'll write some code about that when I'm back from vacation and we'll see what's up. I may end up adding a quirk call inside the pci_read_bridge_bases
functions so that it's behaviour can be easily overriden if we ever meet a non-strandard enough bridge to be transparent without having ProgIf

code 1

Quoted 11 lines

This can be easily done with generic quirks:

	{ PCI_FIXUP_HEADER, PCI_VENDOR_ID_XXX, PCI_DEVICE_ID_BAD_BRIDGE,
	  quirk_transparent_bridge }
...
static void __init
quirk_transparent_bridge(struct pci_dev *dev)
{
	dev->class |= 1;
}

Yah, that would make it.

Thanks for your enlightenment
Ben.

#6 lore raw
Quoted 3 lines · Benjamin Herrenschmidt

I do have 3 root busses, that's not a problem. But their resources are all childs of the global iomem_resources which sorta represents the system memory bus.

Child<->parent resource relationship between system and PCI buses not only isn't required, but might be simply impossible in some situations. Consider non-linear (or linear, but just not 1:1) mapping between system and PCI bus addressing. Or even no mapping at all. ;-) Yes, most architectures use global resources as parents of PCI resources - just because it happens to work and is convenient. But this doesn't mean that everybody must do the same.

Quoted 5 lines

Well... at one point, I had more than that :( I added some code to coalesce the ranges provided by the firmware and figured out it mostly turned into 1 big range of 256 or 512Mb, one small in the 0xfx000000 region, and one IO. So that should fit. But nothing prevents the firmware from setting things up differently.

Exactly. One day, after firmware update, you may end up asking for a bit more resource slots. :-)
BTW, do you really need that additional small IOMEM range?

Quoted 8 lines

They should probably then, but I haven't quite looked at the cardbus code yet. I still think the resource management should be generic enough not to rely on ordering & number of resources, as the actual informations we want out of the parent resources are already encoded in the flags (that is knowing if we deal with the parent IO window, MEM window, or MEM+prefetch window). We have generic routines working only on flags for finding parents when populating the tree already.

This would add a lot of unneeded complexity to the code in drivers/pci/setup-bus.c. Also, this would make impossible configurations like this:
root bus windows 0x80000000-0x8fffffff

			0xf0000000-0xf0ffffff

pci-pci bridge window 0x80200000-0xf02fffff

which is perfectly valid in your setup unless you
place some device resources in the range 0x90000000-0xefffffff. BTW, you can avoid that range with properly coded pcibios_align_resource() - maybe this would be cleaner solution than allocating dummy resource.

Quoted 3 lines

But that isn't an urgent issue nor difficult to work around if needed, so let's put that on hold until I can prove we really need all of those ;)

Ok. But IMO, you're trying to expose your host bridge internals to the generic code instead of hiding it...

Ivan.

#7 lore raw
Quoted 7 lines

Child<->parent resource relationship between system and PCI buses not only isn't required, but might be simply impossible in some situations. Consider non-linear (or linear, but just not 1:1) mapping between system and PCI bus addressing. Or even no mapping at all. ;-) Yes, most architectures use global resources as parents of PCI resources - just because it happens to work and is convenient. But this doesn't mean that everybody must do the same.

Right. Though it's convenient that way on ppc32 ;)

Quoted 8 lines
Quoted 5 lines

Well... at one point, I had more than that :( I added some code to coalesce the ranges provided by the firmware and figured out it mostly turned into 1 big range of 256 or 512Mb, one small in the 0xfx000000 region, and one IO. So that should fit. But nothing prevents the firmware from setting things up differently.

Exactly. One day, after firmware update, you may end up asking for a bit more resource slots. :-)

Yup, especially since Apple does the firmware :)

Quoted 1 line

BTW, do you really need that additional small IOMEM range?

Yup. It's really used by some devices on some machines, and it's nasty to let the kernel relocate PCI devices when it turns to be Apple's ASICs. Especially when things get out of sync with the Open Firmware device tree. So we need to keep the PCI setup as close as possible as what is set by the firmware, while still having some freedom for things like bus renumbering or reallocations of some PCI devices.

Quoted 9 lines
Quoted 8 lines

They should probably then, but I haven't quite looked at the cardbus code yet. I still think the resource management should be generic enough not to rely on ordering & number of resources, as the actual informations we want out of the parent resources are already encoded in the flags (that is knowing if we deal with the parent IO window, MEM window, or MEM+prefetch window). We have generic routines working only on flags for finding parents when populating the tree already.

Quoted 6 lines

This would add a lot of unneeded complexity to the code in drivers/pci/setup-bus.c. Also, this would make impossible configurations like this:
root bus windows 0x80000000-0x8fffffff

			0xf0000000-0xf0ffffff

pci-pci bridge window 0x80200000-0xf02fffff

A bit of complexity on a rarely usesed code path (typically at boot only most of the time) for more flexibility may be worth the trade ;)

Quoted 4 lines

which is perfectly valid in your setup unless you
place some device resources in the range 0x90000000-0xefffffff. BTW, you can avoid that range with properly coded pcibios_align_resource() - maybe this would be cleaner solution than allocating dummy resource.

Yup, nasty case, but does the current code handle it cleanly anyway ?

Quoted 6 lines
Quoted 3 lines

But that isn't an urgent issue nor difficult to work around if needed, so let's put that on hold until I can prove we really need all of those ;)

Ok. But IMO, you're trying to expose your host bridge internals to the generic code instead of hiding it...

Maybe. I have a quite non-PCI centric view of it (maybe after dealing a bit with embedded stuff). I want to represent my physical bus layout with those, having a coherent tree, crossing a PCI segment or not. It makes sense to me to expose the resources of the host as they are really implemented.

Ben.