FreeBSD/sys/x86/pci/pci_bus.c
/*
 * Scan the first pci bus for host-pci bridges and add pcib instances
 * to the nexus for each bridge.
 */
Scan the first pci bus for host-pci bridges and add pcib instances
to the nexus for each bridge.
Scan the first pci bus for host - pci bridges and add pcib instances to the nexus for each bridge .
static void
legacy_pcib_identify(driver_t *driver, device_t parent)
{
	int bus, slot, func;
	uint8_t  hdrtype;
	int found = 0;
	int pcifunchigh;
	int found824xx = 0;
	int found_orion = 0;
	device_t child;
	devclass_t pci_devclass;
	if (pci_cfgregopen() == 0)
		return;
	if ((pci_devclass = devclass_find("pci")) &&
		devclass_get_device(pci_devclass, 0))
		return;
	bus = 0;
 retry:
	for (slot = 0; slot <= PCI_SLOTMAX; slot++) {
		func = 0;
		hdrtype = legacy_pcib_read_config(0, bus, slot, func,
						 PCIR_HDRTYPE, 1);
		if ((hdrtype & PCIM_HDRTYPE) > PCI_MAXHDRTYPE)
			continue;
		if ((hdrtype & PCIM_MFDEV) &&
		    (!found_orion || hdrtype != 0xff))
			pcifunchigh = PCI_FUNCMAX;
		else
			pcifunchigh = 0;
		for (func = 0; func <= pcifunchigh; func++) {
			uint32_t id;
			uint8_t class, subclass, busnum;
			const char *s;
			device_t *devs;
			int ndevs, i;
			id = legacy_pcib_read_config(0, bus, slot, func,
						    PCIR_DEVVENDOR, 4);
			if (id == -1)
				continue;
			class = legacy_pcib_read_config(0, bus, slot, func,
						       PCIR_CLASS, 1);
			subclass = legacy_pcib_read_config(0, bus, slot, func,
							  PCIR_SUBCLASS, 1);
			s = legacy_pcib_is_host_bridge(bus, slot, func,
						      id, class, subclass,
						      &busnum);
			if (s == NULL)
				continue;
			if (device_get_children(parent, &devs, &ndevs) == 0) {
				for (i = 0; s != NULL && i < ndevs; i++) {
					if (strcmp(device_get_name(devs[i]),
					    "pcib") != 0)
						continue;
					if (legacy_get_pcibus(devs[i]) == busnum)
						s = NULL;
				}
				free(devs, M_TEMP);
			}
			if (s == NULL)
				continue;
			child = BUS_ADD_CHILD(parent, 100,
					      "pcib", busnum);
			device_set_desc(child, s);
			legacy_set_pcibus(child, busnum);
			legacy_set_pcislot(child, slot);
			legacy_set_pcifunc(child, func);
			found = 1;
			if (id == 0x12258086)
				found824xx = 1;
			if (id == 0x84c48086)
				found_orion = 1;
		}
	}
	if (found824xx && bus == 0) {
		bus++;
		goto retry;
	}
	if (!found) {
		if (bootverbose)
			printf(
	"legacy_pcib_identify: no bridge found, adding pcib0 anyway\n");
		child = BUS_ADD_CHILD(parent, 100, "pcib", 0);
		legacy_set_pcibus(child, 0);
	}
}
static void legacy_pcib_identify ( driver_t * driver , device_t parent ) { int bus , slot , func ; uint8_t hdrtype ; int found = 0 ; int pcifunchigh ; int found824xx = 0 ; int found_orion = 0 ; device_t child ; devclass_t pci_devclass ; if ( pci_cfgregopen ( ) == 0 ) return ; if ( ( pci_devclass = devclass_find ( " " ) ) && devclass_get_device ( pci_devclass , 0 ) ) return ; bus = 0 ; retry : for ( slot = 0 ; slot <= PCI_SLOTMAX ; slot ++ ) { func = 0 ; hdrtype = legacy_pcib_read_config ( 0 , bus , slot , func , PCIR_HDRTYPE , 1 ) ; if ( ( hdrtype & PCIM_HDRTYPE ) > PCI_MAXHDRTYPE ) continue ; if ( ( hdrtype & PCIM_MFDEV ) && ( ! found_orion || hdrtype != 0xff ) ) pcifunchigh = PCI_FUNCMAX ; else pcifunchigh = 0 ; for ( func = 0 ; func <= pcifunchigh ; func ++ ) { uint32_t id ; uint8_t class , subclass , busnum ; const char * s ; device_t * devs ; int ndevs , i ; id = legacy_pcib_read_config ( 0 , bus , slot , func , PCIR_DEVVENDOR , 4 ) ; if ( id == -1 ) continue ; class = legacy_pcib_read_config ( 0 , bus , slot , func , PCIR_CLASS , 1 ) ; subclass = legacy_pcib_read_config ( 0 , bus , slot , func , PCIR_SUBCLASS , 1 ) ; s = legacy_pcib_is_host_bridge ( bus , slot , func , id , class , subclass , & busnum ) ; if ( s == NULL ) continue ; if ( device_get_children ( parent , & devs , & ndevs ) == 0 ) { for ( i = 0 ; s != NULL && i < ndevs ; i ++ ) { if ( strcmp ( device_get_name ( devs [ i ] ) , " " ) != 0 ) continue ; if ( legacy_get_pcibus ( devs [ i ] ) == busnum ) s = NULL ; } free ( devs , M_TEMP ) ; } if ( s == NULL ) continue ; child = BUS_ADD_CHILD ( parent , 100 , " " , busnum ) ; device_set_desc ( child , s ) ; legacy_set_pcibus ( child , busnum ) ; legacy_set_pcislot ( child , slot ) ; legacy_set_pcifunc ( child , func ) ; found = 1 ; if ( id == 0x12258086 ) found824xx = 1 ; if ( id == 0x84c48086 ) found_orion = 1 ; } } if ( found824xx && bus == 0 ) { bus ++ ; goto retry ; } if ( ! found ) { if ( bootverbose ) printf ( " \n " ) ; child = BUS_ADD_CHILD ( parent , 100 , " " , 0 ) ; legacy_set_pcibus ( child , 0 ) ; } }
Scan the first pci bus for host-pci bridges and add pcib instances
 to the nexus for each bridge.
Scan the first pci bus for host - pci bridges and add pcib instances to the nexus for each bridge .
/*
	 * Check to see if we haven't already had a PCI bus added
	 * via some other means.  If we have, bail since otherwise
	 * we're going to end up duplicating it.
	 */ /*
		 * When enumerating bus devices, the standard says that
		 * one should check the header type and ignore the slots whose
		 * header types that the software doesn't know about.  We use
		 * this to filter out devices.
		 */ /*
			 * Read the IDs and class from the device.
			 */ /*
			 * Check to see if the physical bus has already
			 * been seen.  Eg: hybrid 32 and 64 bit host
			 * bridges to the same logical bus.
			 */ /*
			 * Add at priority 100 to make sure we
			 * go after any motherboard resources
			 */ /*
	 * Make sure we add at least one bridge since some old
	 * hardware doesn't actually have a host-pci bridge device.
	 * Note that pci_cfgregopen() thinks we have PCI devices..
	 */