/* NOTE: we do not run the func for devices that do not appear to be PCI except for the start node which we assume (this is good because the start node is often a phb which may be missing PCI properties). We use the class-code as an indicator. If we run into one of these nodes we also assume its siblings are non-pci for performance.  */
void* traverse_pci_devices(struct device_node *start, traverse_func pre, void *data)
/* NOTE: we do not run the func for devices that do not appear to be PCI except for the start node which we assume (this is good because the start node is often a phb which may be missing PCI properties). We use the class-code as an indicator. If we run into one of these nodes we also assume its siblings are non-pci for performance.  */
void* traverse_pci_devices(struct device_node *start, traverse_func pre, void *data)
{
	struct device_node *dn, *nextdn;
	void *ret;
	for (dn = start->child; dn; dn = nextdn) {
		const u32 *classp;
		u32 class;
		nextdn = NULL;
		classp = of_get_property(dn, "class-code", NULL);
		class = classp ? *classp : 0;
		if (pre && ((ret = pre(dn, data)) != NULL))
			return ret;
		if (dn->child && ((class >> 8) == PCI_CLASS_BRIDGE_PCI ||
				  (class >> 8) == PCI_CLASS_BRIDGE_CARDBUS))
			nextdn = dn->child;
		else if (dn->sibling)
			nextdn = dn->sibling;
		if (!nextdn) {
			do {
				dn = dn->parent;
				if (dn == start)
					return NULL;
			} while (dn->sibling == NULL);
			nextdn = dn->sibling;
		}
	}
	return NULL;
}