int __ref cpci_configure_slot(struct slot *slot)
{
	struct pci_bus *parent;
	int fn;

	dbg("%s - enter", __func__);

	if (slot->dev == NULL) {
		dbg("pci_dev null, finding %02x:%02x:%x",
		    slot->bus->number, PCI_SLOT(slot->devfn), PCI_FUNC(slot->devfn));
		slot->dev = pci_get_slot(slot->bus, slot->devfn);
	}

	/* Still NULL? Well then scan for it! */
	if (slot->dev == NULL) {
		int n;
		dbg("pci_dev still null");

		/*
		 * This will generate pci_dev structures for all functions, but
		 * we will only call this case when lookup fails.
		 */
		n = pci_scan_slot(slot->bus, slot->devfn);
		dbg("%s: pci_scan_slot returned %d", __func__, n);
		slot->dev = pci_get_slot(slot->bus, slot->devfn);
		if (slot->dev == NULL) {
			err("Could not find PCI device for slot %02x", slot->number);
			return -ENODEV;
		}
	}
	parent = slot->dev->bus;

	for (fn = 0; fn < 8; fn++) {
		struct pci_dev *dev;

		dev = pci_get_slot(parent,
				   PCI_DEVFN(PCI_SLOT(slot->devfn), fn));
		if (!dev)
			continue;
		if ((dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) ||
		    (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS))
			pci_hp_add_bridge(dev);
		pci_dev_put(dev);
	}

	pci_assign_unassigned_bridge_resources(parent->self);

	pci_bus_add_devices(parent);

	dbg("%s - exit", __func__);
	return 0;
}
Exemplo n.º 2
0
Arquivo: ltp_tpci.c Projeto: 1587/ltp
/*
 * test_slot_scan
 *	make call to pci_scan_slot, which will
 *	find the device pointer and setup the
 *	device info
 */
static int test_slot_scan(void)
{
	int ret, num = ltp_pci.dev->devfn;
	struct pci_bus *bus = ltp_pci.bus;

	prk_info("scan pci slot");

	ret = pci_scan_slot(bus, num);
	if (ret >= 0) {
		prk_info("found '%d' devices from scan slot", ret);
		return TPASS;
	}

	prk_err("pci_scan_slot failed");
	return TFAIL;
}
Exemplo n.º 3
0
int __ref shpchp_configure_device(struct slot *p_slot)
{
	struct pci_dev *dev;
	struct pci_bus *parent = p_slot->ctrl->pci_dev->subordinate;
	int num, fn;
	struct controller *ctrl = p_slot->ctrl;

	dev = pci_get_slot(parent, PCI_DEVFN(p_slot->device, 0));
	if (dev) {
		ctrl_err(ctrl, "Device %s already exists "
			 "at %04x:%02x:%02x, cannot hot-add\n", pci_name(dev),
			 pci_domain_nr(parent), p_slot->bus, p_slot->device);
		pci_dev_put(dev);
		return -EINVAL;
	}

	num = pci_scan_slot(parent, PCI_DEVFN(p_slot->device, 0));
	if (num == 0) {
		ctrl_err(ctrl, "No new device found\n");
		return -ENODEV;
	}

	for (fn = 0; fn < 8; fn++) {
		dev = pci_get_slot(parent, PCI_DEVFN(p_slot->device, fn));
		if (!dev)
			continue;
		if ((dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) ||
				(dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)) {
			/* Find an unused bus number for the new bridge */
			struct pci_bus *child;
			unsigned char busnr, start = parent->secondary;
			unsigned char end = parent->subordinate;
			for (busnr = start; busnr <= end; busnr++) {
				if (!pci_find_bus(pci_domain_nr(parent),
							busnr))
					break;
			}
			if (busnr > end) {
				ctrl_err(ctrl,
					 "No free bus for hot-added bridge\n");
				pci_dev_put(dev);
				continue;
			}
			child = pci_add_new_bus(parent, dev, busnr);
			if (!child) {
				ctrl_err(ctrl, "Cannot add new bus for %s\n",
					 pci_name(dev));
				pci_dev_put(dev);
				continue;
			}
			child->subordinate = pci_do_scan_bus(child);
			pci_bus_size_bridges(child);
		}
		pci_configure_slot(dev);
		pci_dev_put(dev);
	}

	pci_bus_assign_resources(parent);
	pci_bus_add_devices(parent);
	pci_enable_bridges(parent);
	return 0;
}
Exemplo n.º 4
0
int __ref cpci_configure_slot(struct slot *slot)
{
    struct pci_bus *parent;
    int fn;

    dbg("%s - enter", __func__);

    if (slot->dev == NULL) {
        dbg("pci_dev null, finding %02x:%02x:%x",
            slot->bus->number, PCI_SLOT(slot->devfn), PCI_FUNC(slot->devfn));
        slot->dev = pci_get_slot(slot->bus, slot->devfn);
    }

    /* Still NULL? Well then scan for it! */
    if (slot->dev == NULL) {
        int n;
        dbg("pci_dev still null");

        /*
         * This will generate pci_dev structures for all functions, but
         * we will only call this case when lookup fails.
         */
        n = pci_scan_slot(slot->bus, slot->devfn);
        dbg("%s: pci_scan_slot returned %d", __func__, n);
        slot->dev = pci_get_slot(slot->bus, slot->devfn);
        if (slot->dev == NULL) {
            err("Could not find PCI device for slot %02x", slot->number);
            return -ENODEV;
        }
    }
    parent = slot->dev->bus;

    for (fn = 0; fn < 8; fn++) {
        struct pci_dev *dev;

        dev = pci_get_slot(parent, PCI_DEVFN(PCI_SLOT(slot->devfn), fn));
        if (!dev)
            continue;
        if ((dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) ||
            (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)) {
            /* Find an unused bus number for the new bridge */
            struct pci_bus *child;
            unsigned char busnr, start = parent->secondary;
            unsigned char end = parent->subordinate;

            for (busnr = start; busnr <= end; busnr++) {
                if (!pci_find_bus(pci_domain_nr(parent),
                          busnr))
                    break;
            }
            if (busnr >= end) {
                err("No free bus for hot-added bridge\n");
                pci_dev_put(dev);
                continue;
            }
            child = pci_add_new_bus(parent, dev, busnr);
            if (!child) {
                err("Cannot add new bus for %s\n",
                    pci_name(dev));
                pci_dev_put(dev);
                continue;
            }
            child->subordinate = pci_do_scan_bus(child);
            pci_bus_size_bridges(child);
        }
        pci_dev_put(dev);
    }

    pci_bus_assign_resources(parent);
    pci_bus_add_devices(parent);
    pci_enable_bridges(parent);

    dbg("%s - exit", __func__);
    return 0;
}
Exemplo n.º 5
0
void pci_scan_bus(pci_func_t f, int type, int bus) {
	for (int slot = 0; slot < 32; ++slot) {
		pci_scan_slot(f, type, bus, slot);
	}
}