Beispiel #1
0
int main(int argc, char **argv)
{
    int r;

    UHCI_DEBUG("starting\n");

    // UHCI_DEBUG("connecting to the SKB...\n");
    // skb_client_connect();
    // UHCI_DEBUG("connected to SKB\n");

    UHCI_DEBUG("connecting to PCI...\n");
    r = pci_client_connect();
    assert(err_is_ok(r));
    UHCI_DEBUG("connected to PCI\n");

    r = pci_register_legacy_driver_irq(uhci_legacy_init, 
				       UHCI_PORTBASE,
				       UHCI_PORTEND,
				       UHCI_IRQ, 
				       uhci_interrupt_handler,
				       NULL );
    if (err_is_ok(r)) {
	UHCI_DEBUG("uhci[legacy]: found controller.");
	goto finish;
    }

    int i;
    for( i=0; device_ids[i] != 0; i++) {
	r = pci_register_driver_irq(uhci_init,	// Init. fn
				    PCI_CLASS_SERIAL,	// Class
				    PCI_SUB_USB,	// Subclass
				    PCI_IF_USB_UHCI,	// Prog. if
				    PCI_VENDOR_INTEL,	// Vendor ID
				    device_ids[i],	// Device ID
				    PCI_DONT_CARE,	// Bus
				    PCI_DONT_CARE,	// Dev
				    PCI_DONT_CARE,	// Fun
				    uhci_interrupt_handler,	// IRQ handler
				    NULL		// IRQ argument
				    );
	if (err_is_ok(r)) {
	    UHCI_DEBUG("uhci: found controller %" PRIx16 ":%" PRIx16 ".\n", 
		       PCI_VENDOR_INTEL, device_ids[i]);
	    goto finish;
	}
	printf("uhci: no device ID %" PRIx16 " found.\n", device_ids[i]);
    }

    printf("uhci: no devices recognized; giving up.");
    return 1;

finish:
    UHCI_DEBUG("registered driver: retval=%d; now polling...\n", r);

    errval_t err;
    struct waitset *ws = get_default_waitset();
    while (1) {
        err = event_dispatch(ws);
        if (err_is_fail(err)) {
            DEBUG_ERR(err, "in event_dispatch");
            break;
        }
    }
}
Beispiel #2
0
errval_t ioat_device_discovery(struct pci_addr addr,
                               enum device_type devtype,
                               uint8_t is_dev_mgr)
{

    errval_t err;

    uint16_t *dev_ids = NULL;
    uint16_t dev_cnt = 0;

    err = pci_client_connect();
    if (err_is_fail(err)) {
        return err;
    }

    switch (devtype) {
        case IOAT_DEVICE_IVB:
            DEV_DEBUG("Doing device discovery: Ivy Bridge\n");
            if (addr.device != 4) {
                /* the IOAT DMA engine should be on device 4 on Ivy Bridge */
                return DMA_ERR_PCI_ADDRESS;
            }
            dev_ids = calloc(PCI_DEVICE_IOAT_IVB_CNT, sizeof(uint16_t));
            if (dev_ids == NULL) {
                return LIB_ERR_MALLOC_FAIL;
            }
            dev_ids[0] = PCI_DEVICE_IOAT_IVB0;
            dev_ids[1] = PCI_DEVICE_IOAT_IVB1;
            dev_ids[2] = PCI_DEVICE_IOAT_IVB2;
            dev_ids[3] = PCI_DEVICE_IOAT_IVB3;
            dev_ids[4] = PCI_DEVICE_IOAT_IVB4;
            dev_ids[5] = PCI_DEVICE_IOAT_IVB5;
            dev_ids[6] = PCI_DEVICE_IOAT_IVB6;
            dev_ids[7] = PCI_DEVICE_IOAT_IVB7;
            dev_ids[8] = PCI_DEVICE_IOAT_IVB8;
            dev_ids[9] = PCI_DEVICE_IOAT_IVB9;
            dev_cnt = PCI_DEVICE_IOAT_IVB_CNT;
            addr.function = 0;
            break;
        case IOAT_DEVICE_HSW:
            DEV_DEBUG("Doing device discovery: Haswell\n");
            if (addr.device != 4) {
                /* the IOAT DMA engine should be on device 4 on Haswell */
                return DMA_ERR_PCI_ADDRESS;
            }
            dev_ids = calloc(PCI_DEVICE_IOAT_HSW_CNT, sizeof(uint16_t));
            if (dev_ids == NULL) {
                return LIB_ERR_MALLOC_FAIL;
            }
            dev_ids[0] = PCI_DEVICE_IOAT_HSW0;
            dev_ids[1] = PCI_DEVICE_IOAT_HSW1;
            dev_ids[2] = PCI_DEVICE_IOAT_HSW2;
            dev_ids[3] = PCI_DEVICE_IOAT_HSW3;
            dev_ids[4] = PCI_DEVICE_IOAT_HSW4;
            dev_ids[5] = PCI_DEVICE_IOAT_HSW5;
            dev_ids[6] = PCI_DEVICE_IOAT_HSW6;
            dev_ids[7] = PCI_DEVICE_IOAT_HSW7;
            dev_ids[8] = PCI_DEVICE_IOAT_HSW8;
            dev_ids[9] = PCI_DEVICE_IOAT_HSW9;
            dev_cnt = PCI_DEVICE_IOAT_HSW_CNT;
            addr.function = 0;
            break;
            break;
        default:
            return DMA_ERR_DEVICE_UNSUPPORTED;
            break;
    }

    devices = calloc(dev_cnt, sizeof(struct ioat_dma_device *));
    if (devices == NULL) {
        free(dev_ids);
        return LIB_ERR_MALLOC_FAIL;
    }

    if (is_dev_mgr == IOAT_DMA_OPERATION_LIBRARY) {
        err = ioat_mgr_svc_init();
        if (err_is_fail(err)) {
            return err;
        }
    }

    /**
     * enumerating all the devices
     *
     * The devices on Haswell and Ivy Bridge are located on
     * Bus x, Device 4, Function 0..7
     */
    for (uint8_t i = 0; i < dev_cnt; ++i) {
        if (is_dev_mgr == IOAT_DMA_OPERATION_LIBRARY) {
            /*
             * discover devices as manager i.e. don't initialize them as they
             * are handed over to the domains upon request
             */
            err = pci_register_driver_noirq(pci_dev_init_manager,
            PCI_DONT_CARE,
                                            PCI_DONT_CARE,
                                            PCI_DONT_CARE,
                                            PCI_VENDOR_INTEL, dev_ids[i], addr.bus,
                                            addr.device, addr.function + i);
        } else {
            /*
             * discover devices as a service i.e. initialize and map devices
             */
            err = pci_register_driver_irq(pci_dev_init_service, PCI_DONT_CARE,
            PCI_DONT_CARE,
                                          PCI_DONT_CARE,
                                          PCI_VENDOR_INTEL,
                                          dev_ids[i], addr.bus, addr.device,
                                          addr.function + i, handle_device_interrupt,
                                          devices[i]);
        }
        if (err_is_fail(err)) {
            if (i == 0) {
                /* XXX: if a system does not implement all devices listed above,
                 *      the registration will fail which is ok. However if it
                 *      happens on the first device this is an error.
                 */
                return err;
            }
        }
    }

    DEV_DEBUG("Device discovery done: got %u devices.\n", device_count);

    free(dev_ids);

    return SYS_ERR_OK;
}