static struct pci_bus *
scan_root_bus (int bus, struct pci_ops *ops, void *sysdata)
{
	struct pci_bus *b;

	/*
	 * We know this is a new root bus we haven't seen before, so
	 * scan it, even if we've seen the same bus number in a different
	 * segment.
	 */
	b = kmalloc(sizeof(*b), GFP_KERNEL);
	if (!b)
		return NULL;

	memset(b, 0, sizeof(*b));
	INIT_LIST_HEAD(&b->children);
	INIT_LIST_HEAD(&b->devices);

	list_add_tail(&b->node, &pci_root_buses);

	b->number = b->secondary = bus;
	b->resource[0] = &ioport_resource;
	b->resource[1] = &iomem_resource;

	b->sysdata = sysdata;
	b->ops = ops;
	b->subordinate = pci_do_scan_bus(b);

	return b;
}
Exemple #2
0
static int dde_linux26_init_pci(void)
{
    /* initialize DDE kit to get virtual bus hierarchy with all PCI devices */
    dde_kit_pci_init(0, 0);

    /*
     * TODO check if all devices on all buses are scanned/added here.
     */

    struct pci_bus *pci_bus = pci_create_bus(0, 0, &dde_linux26_pcibus_ops, 0);
    pci_do_scan_bus(pci_bus);

    INITIALIZE_INITVAR(dde_linux26_pci);

    return 0;
}
Exemple #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;
}
Exemple #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;
}
Exemple #5
0
/*
 * Initialization. Try all known PCI access methods. Note that we support
 * using both PCI BIOS and direct access: in such cases, we use I/O ports
 * to access config space, but we still keep BIOS order of cards to be
 * compatible with 2.0.X. This should go away some day.
 */
static int __init pcibios_init(void)
{
	ioport_resource.start	= 0xA0000000;
	ioport_resource.end	= 0xDFFFFFFF;
	iomem_resource.start	= 0xA0000000;
	iomem_resource.end	= 0xDFFFFFFF;

	if (!pci_probe)
		return 0;

	if (pci_check_direct() < 0) {
		printk(KERN_WARNING "PCI: No PCI bus detected\n");
		return 0;
	}

	printk(KERN_INFO "PCI: Probing PCI hardware [mempage %08x]\n",
	       MEM_PAGING_REG);

	{
#if 0
		static struct pci_bus am33_root_bus = {
			.children  = LIST_HEAD_INIT(am33_root_bus.children),
			.devices   = LIST_HEAD_INIT(am33_root_bus.devices),
			.number    = 0,
			.secondary = 0,
			.resource = { &ioport_resource, &iomem_resource },
		};

		am33_root_bus.ops = pci_root_ops;
		list_add_tail(&am33_root_bus.node, &pci_root_buses);

		am33_root_bus.subordinate = pci_do_scan_bus(0);

		pci_root_bus = &am33_root_bus;
#else
		pci_root_bus = pci_scan_bus(0, &pci_direct_ampci, NULL);
#endif
	}

	pcibios_irq_init();
	pcibios_fixup_irqs();
#if 0
	pcibios_resource_survey();
#endif
	return 0;
}

arch_initcall(pcibios_init);

char *__init pcibios_setup(char *str)
{
	if (!strcmp(str, "off")) {
		pci_probe = 0;
		return NULL;

	} else if (!strncmp(str, "lastbus=", 8)) {
		pcibios_last_bus = simple_strtol(str+8, NULL, 0);
		return NULL;
	}

	return str;
}

int pcibios_enable_device(struct pci_dev *dev, int mask)
{
	int err;

	err = pcibios_enable_resources(dev, mask);
	if (err == 0)
		pcibios_enable_irq(dev);
	return err;
}