Exemplo n.º 1
0
static int hpt_attach(device_t dev)
{
	PHBA hba = (PHBA)device_get_softc(dev);
	HIM *him = hba->ldm_adapter.him;
	PCI_ID pci_id;
	HPT_UINT size;
	PVBUS vbus;
	PVBUS_EXT vbus_ext;

	KdPrint(("hpt_attach(%d/%d/%d)", pci_get_bus(dev), pci_get_slot(dev), pci_get_function(dev)));

	pci_enable_busmaster(dev);

	pci_id.vid = pci_get_vendor(dev);
	pci_id.did = pci_get_device(dev);
	pci_id.rev = pci_get_revid(dev);
	pci_id.subsys = (HPT_U32)(pci_get_subdevice(dev)) << 16 | pci_get_subvendor(dev);

	size = him->get_adapter_size(&pci_id);
	hba->ldm_adapter.him_handle = kmalloc(size, M_DEVBUF, M_WAITOK);
	if (!hba->ldm_adapter.him_handle)
		return ENXIO;

	hba->pcidev = dev;
	hba->pciaddr.tree = 0;
	hba->pciaddr.bus = pci_get_bus(dev);
	hba->pciaddr.device = pci_get_slot(dev);
	hba->pciaddr.function = pci_get_function(dev);

	if (!him->create_adapter(&pci_id, hba->pciaddr, hba->ldm_adapter.him_handle, hba)) {
		kfree(hba->ldm_adapter.him_handle, M_DEVBUF);
		return -1;
	}

	os_printk("adapter at PCI %d:%d:%d, IRQ %d",
		hba->pciaddr.bus, hba->pciaddr.device, hba->pciaddr.function, pci_get_irq(dev));

	if (!ldm_register_adapter(&hba->ldm_adapter)) {
		size = ldm_get_vbus_size();
		vbus_ext = kmalloc(sizeof(VBUS_EXT) + size, M_DEVBUF, M_WAITOK);
		if (!vbus_ext) {
			kfree(hba->ldm_adapter.him_handle, M_DEVBUF);
			return -1;
		}
		memset(vbus_ext, 0, sizeof(VBUS_EXT));
		vbus_ext->ext_type = EXT_TYPE_VBUS;
		ldm_create_vbus((PVBUS)vbus_ext->vbus, vbus_ext);
		ldm_register_adapter(&hba->ldm_adapter);
	}

	ldm_for_each_vbus(vbus, vbus_ext) {
		if (hba->ldm_adapter.vbus==vbus) {
			hba->vbus_ext = vbus_ext;
			hba->next = vbus_ext->hba_list;
			vbus_ext->hba_list = hba;
			break;
		}
	}
	return 0;
}
Exemplo n.º 2
0
static int hpt_probe(device_t dev)
{
	PCI_ID pci_id;
	HIM *him;
	int i;
	PHBA hba;

	for (him = him_list; him; him = him->next) {
		for (i=0; him->get_supported_device_id(i, &pci_id); i++) {
			if (him->get_controller_count)
				him->get_controller_count(&pci_id,0,0);
			if ((pci_get_vendor(dev) == pci_id.vid) &&
				(pci_get_device(dev) == pci_id.did)){
				KdPrint(("hpt_probe: adapter at PCI %d:%d:%d, IRQ %d",
					pci_get_bus(dev), pci_get_slot(dev), pci_get_function(dev), pci_get_irq(dev)
				));
				device_set_desc(dev, him->name);
				hba = (PHBA)device_get_softc(dev);
				memset(hba, 0, sizeof(HBA));
				hba->ext_type = EXT_TYPE_HBA;
				hba->ldm_adapter.him = him;
				return 0;
			}
		}
	}

	return (ENXIO);
}
Exemplo n.º 3
0
static int hpt_probe(device_t dev)
{
	PCI_ID pci_id;
	HIM *him;
	int i;
	PHBA hba;

	/* Some of supported chips are used not only by HPT. */
	if (pci_get_vendor(dev) != 0x1103 && !attach_generic)
		return (ENXIO);
	for (him = him_list; him; him = him->next) {
		for (i=0; him->get_supported_device_id(i, &pci_id); i++) {
			if ((pci_get_vendor(dev) == pci_id.vid) &&
				(pci_get_device(dev) == pci_id.did)){
				KdPrint(("hpt_probe: adapter at PCI %d:%d:%d, IRQ %d",
					pci_get_bus(dev), pci_get_slot(dev), pci_get_function(dev), pci_get_irq(dev)
				));
				device_set_desc(dev, him->name);
				hba = (PHBA)device_get_softc(dev);
				memset(hba, 0, sizeof(HBA));
				hba->ext_type = EXT_TYPE_HBA;
				hba->ldm_adapter.him = him;
				return 0;
			}
		}
	}

	return (ENXIO);
}
Exemplo n.º 4
0
int __init pcibios_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
{
	/* SMSC SLC90E66 IDE uses irq 14, 15 (default) */
	if (!(dev->vendor == PCI_VENDOR_ID_EFAR &&
	      dev->device == PCI_DEVICE_ID_EFAR_SLC90E66_1))
		return pci_get_irq(dev, pin);

	dev->irq = irq;
}
Exemplo n.º 5
0
/*
 * Tell the hypervisor how to contact us for event channel callbacks.
 */
void
xen_hvm_set_callback(device_t dev)
{
	struct xen_hvm_param xhp;
	int irq;

	if (xen_vector_callback_enabled)
		return;

	xhp.domid = DOMID_SELF;
	xhp.index = HVM_PARAM_CALLBACK_IRQ;
	if (xen_feature(XENFEAT_hvm_callback_vector) != 0) {
		int error;

		error = set_percpu_callback(0);
		if (error == 0) {
			xen_evtchn_needs_ack = true;
			/* Trick toolstack to think we are enlightened */
			xhp.value = 1;
		} else
			xhp.value = HVM_CALLBACK_VECTOR(IDT_EVTCHN);
		error = HYPERVISOR_hvm_op(HVMOP_set_param, &xhp);
		if (error == 0) {
			xen_vector_callback_enabled = 1;
			return;
		} else if (xen_evtchn_needs_ack)
			panic("Unable to setup fake HVM param: %d", error);

		printf("Xen HVM callback vector registration failed (%d). "
		    "Falling back to emulated device interrupt\n", error);
	}
	xen_vector_callback_enabled = 0;
	if (dev == NULL) {
		/*
		 * Called from early boot or resume.
		 * xenpci will invoke us again later.
		 */
		return;
	}

	irq = pci_get_irq(dev);
	if (irq < 16) {
		xhp.value = HVM_CALLBACK_GSI(irq);
	} else {
		u_int slot;
		u_int pin;

		slot = pci_get_slot(dev);
		pin = pci_get_intpin(dev) - 1;
		xhp.value = HVM_CALLBACK_PCI_INTX(slot, pin);
	}

	if (HYPERVISOR_hvm_op(HVMOP_set_param, &xhp) != 0)
		panic("Can't set evtchn callback");
}
Exemplo n.º 6
0
int __init pcibios_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
{
	unsigned char irq = 0;

	irq = pci_get_irq(dev, pin);

	printk(KERN_INFO "PCI: 0x%02x:0x%02x(0x%02x,0x%02x) IRQ=%d\n",
	       dev->bus->number, dev->devfn, PCI_SLOT(dev->devfn),
	       PCI_FUNC(dev->devfn), irq);

	return irq;
}
Exemplo n.º 7
0
static int hpt_probe(device_t dev)
{
	HIM *him;

	him = hpt_match(dev);
	if (him != NULL) {
		KdPrint(("hpt_probe: adapter at PCI %d:%d:%d, IRQ %d",
			pci_get_bus(dev), pci_get_slot(dev), pci_get_function(dev), pci_get_irq(dev)
			));
		device_set_desc(dev, him->name);
		return (BUS_PROBE_DEFAULT);
	}

	return (ENXIO);
}
Exemplo n.º 8
0
static void
cardbus_device_setup_regs(pcicfgregs *cfg)
{
	device_t dev = cfg->dev;
	int i;

	/*
	 * Some cards power up with garbage in their BARs.  This
	 * code clears all that junk out.
	 */
	for (i = 0; i < PCIR_MAX_BAR_0; i++)
		pci_write_config(dev, PCIR_BAR(i), 0, 4);

	cfg->intline =
	    pci_get_irq(device_get_parent(device_get_parent(dev)));
	pci_write_config(dev, PCIR_INTLINE, cfg->intline, 1);
	pci_write_config(dev, PCIR_CACHELNSZ, 0x08, 1);
	pci_write_config(dev, PCIR_LATTIMER, 0xa8, 1);
	pci_write_config(dev, PCIR_MINGNT, 0x14, 1);
	pci_write_config(dev, PCIR_MAXLAT, 0x14, 1);
}
Exemplo n.º 9
0
static int
mptable_pci_route_interrupt(device_t pcib, device_t dev, int pin)
{
	int line, bus, slot, irq;

	bus = pci_get_bus(dev);
	slot = pci_get_slot(dev);
	irq = pci_get_irq(dev);

	line = mptable_pci_int_route(bus, slot, pin, irq);
	if (line >= 0)
		goto done;

	kprintf("MPTABLE: Unable to route for bus %d slot %d INT%c\n",
		bus, slot, 'A' + pin - 1);
	return PCI_INVALID_IRQ;

done:
	BUS_CONFIG_INTR(dev, dev, line, INTR_TRIGGER_LEVEL, INTR_POLARITY_LOW);
	return line;
}
Exemplo n.º 10
0
/*
 * Tell the hypervisor how to contact us for event channel callbacks.
 */
static void
xenpci_set_callback(device_t dev)
{
	int irq;
	uint64_t callback;
	struct xen_hvm_param xhp;

	irq = pci_get_irq(dev);
	if (irq < 16) {
		callback = irq;
	} else {
		callback = (pci_get_intpin(dev) - 1) & 3;
		callback |= pci_get_slot(dev) << 11;
		callback |= 1ull << 56;
	}

	xhp.domid = DOMID_SELF;
	xhp.index = HVM_PARAM_CALLBACK_IRQ;
	xhp.value = callback;
	if (HYPERVISOR_hvm_op(HVMOP_set_param, &xhp))
		panic("Can't set evtchn callback");
}
Exemplo n.º 11
0
void __init pcibios_fixup_irqs(void)
{
	unsigned char irq;
        struct pci_dev *dev;

	pci_for_each_dev(dev) {
		pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &irq);
		if (irq == 0)
			return;

		/* SMSC SLC90E66 IDE uses irq 14, 15 (default) */
		if (!(dev->vendor == PCI_VENDOR_ID_EFAR &&
		      dev->device == PCI_DEVICE_ID_EFAR_SLC90E66_1)) {
			irq = pci_get_irq(dev, irq);
			pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
		}

		pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq);
		printk(KERN_INFO "PCI: %02x:%02x IRQ %02x\n",
		       dev->bus->number, dev->devfn, irq);
		dev->irq = irq;
	}
}
Exemplo n.º 12
0
void __init pcibios_fixup_irqs(void)
{
	unsigned char pin;
	unsigned char irq;
	struct pci_dev *dev;
	unsigned int id;

#ifdef  TX4927_SUPPORT_PCI_66
	if (tx4927_pci66_check()) {
		tx4927_pci66_setup();
		tx4927_pci_setup();	/* Reinitialize PCIC */
	}
#endif

	pci_for_each_dev(dev) {
		DBG("FIXUP:\n");
		DBG(" devfn=0x%02x (0x%02x:0x%02x)\n",
		    dev->devfn, PCI_SLOT(dev->devfn),
		    PCI_FUNC(dev->devfn));

		pci_read_config_dword(dev, PCI_VENDOR_ID, &id);
		DBG(" id=0x%08x\n", id);

		pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq);
		DBG(" line=0x%02x/%d\n", irq, irq);

		pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
		DBG(" pin=%d\n", pin);

#ifdef DEBUG
		{
			unsigned int tmp;
			pci_read_config_dword(dev, 0x10, &tmp);
			DBG(" bar0:0x10=0x%08x\n", tmp);
			pci_read_config_dword(dev, 0x14, &tmp);
			DBG(" bar1:0x14=0x%08x\n", tmp);
			pci_read_config_dword(dev, 0x1c, &tmp);
			DBG(" bar2:0x1c=0x%08x\n", tmp);
			pci_read_config_dword(dev, 0x20, &tmp);
			DBG(" bar3:0x20=0x%08x\n", tmp);
			pci_read_config_dword(dev, 0x24, &tmp);
			DBG(" bar4:0x24=0x%08x\n", tmp);
		}
#endif

		irq = 0;

		if (id == 0x91301055) {	/* ide */
			irq = 14;
		}

		if (pin == 0) {
			DBG(" auto irq (now=%d) -- skipping pin=0\n", irq);
		} else if (irq) {
			DBG(" auto irq (now=%d) -- skipping hardcoded irq\n", irq);
		} else {
			DBG(" auto irq (was=%d)\n", irq);
			irq = pci_get_irq(dev, pin);
			pci_write_config_byte(dev, PCI_INTERRUPT_LINE,
					      irq);
			dev->irq = irq;
			DBG(" auto irq (now=%d)\n", irq);
		}

		pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq);
		printk(KERN_INFO
		       "PCI: 0x%02x:0x%02x(0x%02x,0x%02x) IRQ=%d\n",
		       dev->bus->number, dev->devfn, PCI_SLOT(dev->devfn),
		       PCI_FUNC(dev->devfn), irq);

	}
}