FreeBSD/sys/dev/pci/pci_pci.c
/*
 * Allocate a suitable secondary bus for this bridge if needed and
 * initialize the resource manager for the secondary bus range.  Note
 * that the minimum count is a desired value and this may allocate a
 * smaller range.
 */
Allocate a suitable secondary bus for this bridge if needed and
initialize the resource manager for the secondary bus range.  Note
that the minimum count is a desired value and this may allocate a
smaller range.
Allocate a suitable secondary bus for this bridge if needed and initialize the resource manager for the secondary bus range . Note that the minimum count is a desired value and this may allocate a smaller range .
void
pcib_setup_secbus(device_t dev, struct pcib_secbus *bus, int min_count)
{
	char buf[64];
	int error, rid, sec_reg;
	switch (pci_read_config(dev, PCIR_HDRTYPE, 1) & PCIM_HDRTYPE) {
	case PCIM_HDRTYPE_BRIDGE:
		sec_reg = PCIR_SECBUS_1;
		bus->sub_reg = PCIR_SUBBUS_1;
		break;
	case PCIM_HDRTYPE_CARDBUS:
		sec_reg = PCIR_SECBUS_2;
		bus->sub_reg = PCIR_SUBBUS_2;
		break;
	default:
		panic("not a PCI bridge");
	}
	bus->sec = pci_read_config(dev, sec_reg, 1);
	bus->sub = pci_read_config(dev, bus->sub_reg, 1);
	bus->dev = dev;
	bus->rman.rm_start = 0;
	bus->rman.rm_end = PCI_BUSMAX;
	bus->rman.rm_type = RMAN_ARRAY;
	snprintf(buf, sizeof(buf), "%s bus numbers", device_get_nameunit(dev));
	bus->rman.rm_descr = strdup(buf, M_DEVBUF);
	error = rman_init(&bus->rman);
	if (error)
		panic("Failed to initialize %s bus number rman",
		    device_get_nameunit(dev));
	rid = 0;
	bus->res = bus_alloc_resource_anywhere(dev, PCI_RES_BUS, &rid,
	    min_count, 0);
	if (bus->res == NULL) {
		bus->res = bus_alloc_resource_anywhere(dev, PCI_RES_BUS, &rid,
		    1, 0);
	} else if (rman_get_size(bus->res) < min_count)
		(void)bus_adjust_resource(dev, PCI_RES_BUS, bus->res,
		    rman_get_start(bus->res), rman_get_start(bus->res) +
		    min_count - 1);
	if (bus->res != NULL) {
		error = rman_manage_region(&bus->rman, rman_get_start(bus->res),
		    rman_get_end(bus->res));
		if (error)
			panic("Failed to add resource to rman");
		bus->sec = rman_get_start(bus->res);
		bus->sub = rman_get_end(bus->res);
	}
}
void pcib_setup_secbus ( device_t dev , struct pcib_secbus * bus , int min_count ) { char buf [ 64 ] ; int error , rid , sec_reg ; switch ( pci_read_config ( dev , PCIR_HDRTYPE , 1 ) & PCIM_HDRTYPE ) { case PCIM_HDRTYPE_BRIDGE : sec_reg = PCIR_SECBUS_1 ; bus -> sub_reg = PCIR_SUBBUS_1 ; break ; case PCIM_HDRTYPE_CARDBUS : sec_reg = PCIR_SECBUS_2 ; bus -> sub_reg = PCIR_SUBBUS_2 ; break ; default : panic ( " " ) ; } bus -> sec = pci_read_config ( dev , sec_reg , 1 ) ; bus -> sub = pci_read_config ( dev , bus -> sub_reg , 1 ) ; bus -> dev = dev ; bus -> rman . rm_start = 0 ; bus -> rman . rm_end = PCI_BUSMAX ; bus -> rman . rm_type = RMAN_ARRAY ; snprintf ( buf , sizeof ( buf ) , " " , device_get_nameunit ( dev ) ) ; bus -> rman . rm_descr = strdup ( buf , M_DEVBUF ) ; error = rman_init ( & bus -> rman ) ; if ( error ) panic ( " " , device_get_nameunit ( dev ) ) ; rid = 0 ; bus -> res = bus_alloc_resource_anywhere ( dev , PCI_RES_BUS , & rid , min_count , 0 ) ; if ( bus -> res == NULL ) { bus -> res = bus_alloc_resource_anywhere ( dev , PCI_RES_BUS , & rid , 1 , 0 ) ; } else if ( rman_get_size ( bus -> res ) < min_count ) ( void ) bus_adjust_resource ( dev , PCI_RES_BUS , bus -> res , rman_get_start ( bus -> res ) , rman_get_start ( bus -> res ) + min_count - 1 ) ; if ( bus -> res != NULL ) { error = rman_manage_region ( & bus -> rman , rman_get_start ( bus -> res ) , rman_get_end ( bus -> res ) ) ; if ( error ) panic ( " " ) ; bus -> sec = rman_get_start ( bus -> res ) ; bus -> sub = rman_get_end ( bus -> res ) ; } }
Allocate a suitable secondary bus for this bridge if needed and
 initialize the resource manager for the secondary bus range.
Allocate a suitable secondary bus for this bridge if needed and initialize the resource manager for the secondary bus range .
/*
	 * Allocate a bus range.  This will return an existing bus range
	 * if one exists, or a new bus range if one does not.
	 */ /*
		 * Fall back to just allocating a range of a single bus
		 * number.
		 */ /*
		 * Attempt to grow the existing range to satisfy the
		 * minimum desired count.
		 */ /*
	 * Add the initial resource to the rman.
	 */