FreeBSD/sys/dev/pci/pci.c
/* Find the upstream port of a given PCI device in a root complex. */
Find the upstream port of a given PCI device in a root complex.
Find the upstream port of a given PCI device in a root complex .
device_t
pci_find_pcie_root_port(device_t dev)
{
	struct pci_devinfo *dinfo;
	devclass_t pci_class;
	device_t pcib, bus;
	pci_class = devclass_find("pci");
	KASSERT(device_get_devclass(device_get_parent(dev)) == pci_class,
	    ("%s: non-pci device %s", __func__, device_get_nameunit(dev)));
	for (;;) {
		bus = device_get_parent(dev);
		KASSERT(bus != NULL, ("%s: null parent of %s", __func__,
		    device_get_nameunit(dev)));
		pcib = device_get_parent(bus);
		KASSERT(pcib != NULL, ("%s: null bridge of %s", __func__,
		    device_get_nameunit(bus)));
		if (device_get_devclass(device_get_parent(pcib)) != pci_class)
			return (NULL);
		dinfo = device_get_ivars(pcib);
		if (dinfo->cfg.pcie.pcie_location != 0 &&
		    dinfo->cfg.pcie.pcie_type == PCIEM_TYPE_ROOT_PORT)
			return (pcib);
		dev = pcib;
	}
}
device_t pci_find_pcie_root_port ( device_t dev ) { struct pci_devinfo * dinfo ; devclass_t pci_class ; device_t pcib , bus ; pci_class = devclass_find ( " " ) ; KASSERT ( device_get_devclass ( device_get_parent ( dev ) ) == pci_class , ( " " , __func__ , device_get_nameunit ( dev ) ) ) ; for ( ; ; ) { bus = device_get_parent ( dev ) ; KASSERT ( bus != NULL , ( " " , __func__ , device_get_nameunit ( dev ) ) ) ; pcib = device_get_parent ( bus ) ; KASSERT ( pcib != NULL , ( " " , __func__ , device_get_nameunit ( bus ) ) ) ; if ( device_get_devclass ( device_get_parent ( pcib ) ) != pci_class ) return ( NULL ) ; dinfo = device_get_ivars ( pcib ) ; if ( dinfo -> cfg . pcie . pcie_location != 0 && dinfo -> cfg . pcie . pcie_type == PCIEM_TYPE_ROOT_PORT ) return ( pcib ) ; dev = pcib ; } }
Find the upstream port of a given PCI device in a root complex.
Find the upstream port of a given PCI device in a root complex .
/*
	 * Walk the bridge hierarchy until we find a PCI-e root
	 * port or a non-PCI device.
	 */ /*
		 * pcib's parent must be a PCI bus for this to be a
		 * PCI-PCI bridge.
		 */