~ubuntu-branches/ubuntu/saucy/qemu/saucy-proposed

« back to all changes in this revision

Viewing changes to hw/usb/host-linux.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2013-05-28 08:18:30 UTC
  • mfrom: (1.8.2) (10.1.37 sid)
  • Revision ID: package-import@ubuntu.com-20130528081830-87xl2z9fq516a814
Tags: 1.5.0+dfsg-2ubuntu1
* Merge 1.5.0+dfs-2 from debian unstable.  Remaining changes:
  - debian/control
    * update maintainer
    * remove libiscsi, usb-redir, vde, vnc-jpeg, and libssh2-1-dev
      from build-deps
    * enable rbd
    * add qemu-system and qemu-common B/R to qemu-keymaps
    * add D:udev, R:qemu, R:qemu-common and B:qemu-common to
      qemu-system-common
    * qemu-system-arm, qemu-system-ppc, qemu-system-sparc:
      - add qemu-kvm to Provides
      - add qemu-common, qemu-kvm, kvm to B/R
      - remove openbios-sparc from qemu-system-sparc D
    * qemu-system-x86:
      - add qemu-common to Breaks/Replaces.
      - add cpu-checker to Recommends.
    * qemu-user: add B/R:qemu-kvm
    * qemu-kvm:
      - add armhf armel powerpc sparc to Architecture
      - C/R/P: qemu-kvm-spice
    * add qemu-common package
    * drop qemu-slof which is not packaged in ubuntu
  - add qemu-system-common.links for tap ifup/down scripts and OVMF link.
  - qemu-system-x86.links:
    * remove pxe rom links which are in kvm-ipxe
    * add symlink for kvm.1 manpage
  - debian/rules
    * add kvm-spice symlink to qemu-kvm
    * call dh_installmodules for qemu-system-x86
    * update dh_installinit to install upstart script
    * run dh_installman (Closes: #709241) (cherrypicked from 1.5.0+dfsg-2)
  - Add qemu-utils.links for kvm-* symlinks.
  - Add qemu-system-x86.qemu-kvm.upstart and .default
  - Add qemu-system-x86.modprobe to set nesting=1
  - Add qemu-system-common.preinst to add kvm group
  - qemu-system-common.postinst: remove bad group acl if there, then have
    udev relabel /dev/kvm.
  - Dropped patches:
    * 0001-fix-wrong-output-with-info-chardev-for-tcp-socket.patch
  - Kept patches:
    * expose_vms_qemu64cpu.patch - updated
    * gridcentric patch - updated
    * linaro arm patches from qemu-linaro rebasing branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
#include <linux/version.h>
44
44
#include "hw/usb.h"
45
45
#include "hw/usb/desc.h"
 
46
#include "hw/usb/host.h"
 
47
 
 
48
#ifdef CONFIG_USB_LIBUSB
 
49
# define DEVNAME "usb-host-linux"
 
50
#else
 
51
# define DEVNAME "usb-host"
 
52
#endif
46
53
 
47
54
/* We redefine it to avoid version problems */
48
55
struct usb_ctrltransfer {
87
94
    int inflight;
88
95
};
89
96
 
90
 
struct USBAutoFilter {
91
 
    uint32_t bus_num;
92
 
    uint32_t addr;
93
 
    char     *port;
94
 
    uint32_t vendor_id;
95
 
    uint32_t product_id;
96
 
};
97
 
 
98
97
enum USBHostDeviceOptions {
99
98
    USB_HOST_OPT_PIPELINE,
100
99
};
131
130
static QTAILQ_HEAD(, USBHostDevice) hostdevs = QTAILQ_HEAD_INITIALIZER(hostdevs);
132
131
 
133
132
static int usb_host_close(USBHostDevice *dev);
134
 
static int parse_filter(const char *spec, struct USBAutoFilter *f);
135
133
static void usb_host_auto_check(void *unused);
136
134
static int usb_host_read_file(char *line, size_t line_size,
137
135
                            const char *device_file, const char *device_name);
653
651
 
654
652
    trace_usb_host_reset(s->bus_num, s->addr);
655
653
 
656
 
    usb_host_do_reset(s);;
 
654
    usb_host_do_reset(s);
657
655
 
658
656
    usb_host_claim_interfaces(s, 0);
659
657
    usb_linux_update_endp_table(s);
1431
1429
 
1432
1430
    usb_host_release_port(s);
1433
1431
    if (s->fd != -1) {
1434
 
        usb_host_do_reset(s);;
 
1432
        usb_host_do_reset(s);
1435
1433
    }
1436
1434
}
1437
1435
 
1495
1493
}
1496
1494
 
1497
1495
static const VMStateDescription vmstate_usb_host = {
1498
 
    .name = "usb-host",
 
1496
    .name = DEVNAME,
1499
1497
    .version_id = 1,
1500
1498
    .minimum_version_id = 1,
1501
1499
    .post_load = usb_host_post_load,
1535
1533
}
1536
1534
 
1537
1535
static const TypeInfo usb_host_dev_info = {
1538
 
    .name          = "usb-host",
 
1536
    .name          = DEVNAME,
1539
1537
    .parent        = TYPE_USB_DEVICE,
1540
1538
    .instance_size = sizeof(USBHostDevice),
1541
1539
    .class_init    = usb_host_class_initfn,
1544
1542
static void usb_host_register_types(void)
1545
1543
{
1546
1544
    type_register_static(&usb_host_dev_info);
1547
 
    usb_legacy_register("usb-host", "host", usb_host_device_open);
1548
1545
}
1549
1546
 
1550
1547
type_init(usb_host_register_types)
1551
1548
 
1552
 
USBDevice *usb_host_device_open(USBBus *bus, const char *devname)
1553
 
{
1554
 
    struct USBAutoFilter filter;
1555
 
    USBDevice *dev;
1556
 
    char *p;
1557
 
 
1558
 
    dev = usb_create(bus, "usb-host");
1559
 
 
1560
 
    if (strstr(devname, "auto:")) {
1561
 
        if (parse_filter(devname, &filter) < 0) {
1562
 
            goto fail;
1563
 
        }
1564
 
    } else {
1565
 
        if ((p = strchr(devname, '.'))) {
1566
 
            filter.bus_num    = strtoul(devname, NULL, 0);
1567
 
            filter.addr       = strtoul(p + 1, NULL, 0);
1568
 
            filter.vendor_id  = 0;
1569
 
            filter.product_id = 0;
1570
 
        } else if ((p = strchr(devname, ':'))) {
1571
 
            filter.bus_num    = 0;
1572
 
            filter.addr       = 0;
1573
 
            filter.vendor_id  = strtoul(devname, NULL, 16);
1574
 
            filter.product_id = strtoul(p + 1, NULL, 16);
1575
 
        } else {
1576
 
            goto fail;
1577
 
        }
1578
 
    }
1579
 
 
1580
 
    qdev_prop_set_uint32(&dev->qdev, "hostbus",   filter.bus_num);
1581
 
    qdev_prop_set_uint32(&dev->qdev, "hostaddr",  filter.addr);
1582
 
    qdev_prop_set_uint32(&dev->qdev, "vendorid",  filter.vendor_id);
1583
 
    qdev_prop_set_uint32(&dev->qdev, "productid", filter.product_id);
1584
 
    qdev_init_nofail(&dev->qdev);
1585
 
    return dev;
1586
 
 
1587
 
fail:
1588
 
    qdev_free(&dev->qdev);
1589
 
    return NULL;
1590
 
}
1591
 
 
1592
 
int usb_host_device_close(const char *devname)
1593
 
{
1594
 
#if 0
1595
 
    char product_name[PRODUCT_NAME_SZ];
1596
 
    int bus_num, addr;
1597
 
    USBHostDevice *s;
1598
 
 
1599
 
    if (strstr(devname, "auto:")) {
1600
 
        return usb_host_auto_del(devname);
1601
 
    }
1602
 
    if (usb_host_find_device(&bus_num, &addr, product_name,
1603
 
                                    sizeof(product_name), devname) < 0) {
1604
 
        return -1;
1605
 
    }
1606
 
    s = hostdev_find(bus_num, addr);
1607
 
    if (s) {
1608
 
        usb_device_delete_addr(s->bus_num, s->dev.addr);
1609
 
        return 0;
1610
 
    }
1611
 
#endif
1612
 
 
1613
 
    return -1;
1614
 
}
1615
 
 
1616
1549
/*
1617
1550
 * Read sys file-system device file
1618
1551
 *
1840
1773
    qemu_mod_timer(usb_auto_timer, qemu_get_clock_ms(rt_clock) + 2000);
1841
1774
}
1842
1775
 
1843
 
/*
1844
 
 * Autoconnect filter
1845
 
 * Format:
1846
 
 *    auto:bus:dev[:vid:pid]
1847
 
 *    auto:bus.dev[:vid:pid]
1848
 
 *
1849
 
 *    bus  - bus number    (dec, * means any)
1850
 
 *    dev  - device number (dec, * means any)
1851
 
 *    vid  - vendor id     (hex, * means any)
1852
 
 *    pid  - product id    (hex, * means any)
1853
 
 *
1854
 
 *    See 'lsusb' output.
1855
 
 */
1856
 
static int parse_filter(const char *spec, struct USBAutoFilter *f)
1857
 
{
1858
 
    enum { BUS, DEV, VID, PID, DONE };
1859
 
    const char *p = spec;
1860
 
    int i;
1861
 
 
1862
 
    f->bus_num    = 0;
1863
 
    f->addr       = 0;
1864
 
    f->vendor_id  = 0;
1865
 
    f->product_id = 0;
1866
 
 
1867
 
    for (i = BUS; i < DONE; i++) {
1868
 
        p = strpbrk(p, ":.");
1869
 
        if (!p) {
1870
 
            break;
1871
 
        }
1872
 
        p++;
1873
 
 
1874
 
        if (*p == '*') {
1875
 
            continue;
1876
 
        }
1877
 
        switch(i) {
1878
 
        case BUS: f->bus_num = strtol(p, NULL, 10);    break;
1879
 
        case DEV: f->addr    = strtol(p, NULL, 10);    break;
1880
 
        case VID: f->vendor_id  = strtol(p, NULL, 16); break;
1881
 
        case PID: f->product_id = strtol(p, NULL, 16); break;
1882
 
        }
1883
 
    }
1884
 
 
1885
 
    if (i < DEV) {
1886
 
        fprintf(stderr, "husb: invalid auto filter spec %s\n", spec);
1887
 
        return -1;
1888
 
    }
1889
 
 
1890
 
    return 0;
1891
 
}
 
1776
#ifndef CONFIG_USB_LIBUSB
1892
1777
 
1893
1778
/**********************/
1894
1779
/* USB host device info */
2021
1906
                       bus, addr, f->port ? f->port : "*", vid, pid);
2022
1907
    }
2023
1908
}
 
1909
 
 
1910
#endif