That (walking all parent nodes) is probably the safest thing to do. I'm not sure whether it's optimal. It would likely depend on whether you can meaningfully have a bridge that's faster on the downstream side than on the upstream.
This is architecture goo at heart - would this be better as a helper in the PCI and arch PCI code ?
Alan