usb: misc fixes.

-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.22 (GNU/Linux)
 
 iQIcBAABAgAGBQJXXrB7AAoJEEy22O7T6HE405AP/AxWSyfiENz1h+DMTNjx+78p
 Q/U0vYVWI7GiRW1wuWVSaVDBRH7x2cMdn4Iy/MjSEd6fP7oxPTlvx5O181Rif3va
 Pdkz0Uk/OHaPgTGjeXbnT6cHuU1K5YqR5SwHJhFdV3yLEGN30GkM1yRbCan/z5Ev
 XFOXvI1RttRia2RH23FL+/oqAIvlsc68NnAHmyHyQGqjj2nuVo4BtF9DuiQ15Xu2
 mGmSyKybRv3CaRnVtC0Rirw9aVu4lBaxHfm6K7xR/s7Jg1zGNKWs99u9glrjCFDi
 OnYbsfSGqppMTxbiH4jfla4WUUZB8yqM5sOFubz3hzdoWv5bcRaYCqvnKFn41SF0
 xdWqxyk5DbzrqJLQPq5lrwge17V6DwhbB+VAekbQoRk8dGIUSpLjy+BJBdU3sRGa
 EQPTjcwRGZVDLpbWtFDzoNMFxk/UsJ65Ajq7w5r+S4JAhun+FJ2j2b1bQJwpqkqm
 Sqsyronxovp6FkoWsJnt7TjfOtxKjcc4XSw+9QOhm9NJRCOqNmWfOF1UwMRTUsNZ
 aToXezBsVU6o4eY1HLO2S4m0l3gCNE6niYn3rhKz9/BFClTIWHt7elU952ND3L9B
 NG3r9P8oKbE6p9B0/XhefPhkaGxKcjpMBed8rZd+2vk0bkkCtXq3OUwT6kpL1aGC
 8K+PcVIQv3ooNuMpD8D8
 =Nfum
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/kraxel/tags/pull-usb-20160613-1' into staging

usb: misc fixes.

# gpg: Signature made Mon 13 Jun 2016 14:09:15 BST
# gpg:                using RSA key 0x4CB6D8EED3E87138
# gpg: Good signature from "Gerd Hoffmann (work) <kraxel@redhat.com>"
# gpg:                 aka "Gerd Hoffmann <gerd@kraxel.org>"
# gpg:                 aka "Gerd Hoffmann (private) <kraxel@gmail.com>"
# Primary key fingerprint: A032 8CFF B93A 17A7 9901  FE7D 4CB6 D8EE D3E8 7138

* remotes/kraxel/tags/pull-usb-20160613-1:
  vl: Eliminate usb_enabled()
  pxa2xx: Unconditionally enable USB controller
  hw/usb/dev-network.c: Use ldl_le_p() and stl_le_p()
  usb-host: add special case for bus+addr

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2016-06-13 15:15:03 +01:00
commit 2c96c379ac
12 changed files with 96 additions and 61 deletions

View File

@ -1351,7 +1351,7 @@ static void n8x0_init(MachineState *machine,
n8x0_dss_setup(s);
n8x0_cbus_setup(s);
n8x0_uart_setup(s);
if (usb_enabled()) {
if (machine_usb(machine)) {
n8x0_usb_setup(s);
}

View File

@ -2165,10 +2165,8 @@ PXA2xxState *pxa270_init(MemoryRegion *address_space,
s->ssp[i] = (SSIBus *)qdev_get_child_bus(dev, "ssi");
}
if (usb_enabled()) {
sysbus_create_simple("sysbus-ohci", 0x4c000000,
qdev_get_gpio_in(s->pic, PXA2XX_PIC_USBH1));
}
sysbus_create_simple("sysbus-ohci", 0x4c000000,
qdev_get_gpio_in(s->pic, PXA2XX_PIC_USBH1));
s->pcmcia[0] = pxa2xx_pcmcia_init(address_space, 0x20000000);
s->pcmcia[1] = pxa2xx_pcmcia_init(address_space, 0x30000000);
@ -2298,10 +2296,8 @@ PXA2xxState *pxa255_init(MemoryRegion *address_space, unsigned int sdram_size)
s->ssp[i] = (SSIBus *)qdev_get_child_bus(dev, "ssi");
}
if (usb_enabled()) {
sysbus_create_simple("sysbus-ohci", 0x4c000000,
qdev_get_gpio_in(s->pic, PXA2XX_PIC_USBH1));
}
sysbus_create_simple("sysbus-ohci", 0x4c000000,
qdev_get_gpio_in(s->pic, PXA2XX_PIC_USBH1));
s->pcmcia[0] = pxa2xx_pcmcia_init(address_space, 0x20000000);
s->pcmcia[1] = pxa2xx_pcmcia_init(address_space, 0x30000000);

View File

@ -254,7 +254,7 @@ static void realview_init(MachineState *machine,
sysbus_connect_irq(busdev, 2, pic[50]);
sysbus_connect_irq(busdev, 3, pic[51]);
pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci");
if (usb_enabled()) {
if (machine_usb(machine)) {
pci_create_simple(pci_bus, -1, "pci-ohci");
}
n = drive_get_max_bus(IF_SCSI);

View File

@ -276,7 +276,7 @@ static void versatile_init(MachineState *machine, int board_id)
pci_nic_init_nofail(nd, pci_bus, "rtl8139", NULL);
}
}
if (usb_enabled()) {
if (machine_usb(machine)) {
pci_create_simple(pci_bus, -1, "pci-ohci");
}
n = drive_get_max_bus(IF_SCSI);

View File

@ -262,7 +262,7 @@ static void pc_init1(MachineState *machine,
pc_cmos_init(pcms, idebus[0], idebus[1], rtc_state);
if (pcmc->pci_enabled && usb_enabled()) {
if (pcmc->pci_enabled && machine_usb(machine)) {
pci_create_simple(pci_bus, piix3_devfn + 2, "piix3-usb-uhci");
}

View File

@ -234,7 +234,7 @@ static void pc_q35_init(MachineState *machine)
ide_drive_get(hd, ICH_AHCI(ahci)->ahci.ports);
ahci_ide_create_devs(ahci, hd);
if (usb_enabled()) {
if (machine_usb(machine)) {
/* Should we create 6 UHCI according to ich9 spec? */
ehci_create_ich9_with_companions(host_bus, 0x1d);
}

View File

@ -309,7 +309,7 @@ static void ppc_heathrow_init(MachineState *machine)
dev = qdev_create(adb_bus, TYPE_ADB_MOUSE);
qdev_init_nofail(dev);
if (usb_enabled()) {
if (machine_usb(machine)) {
pci_create_simple(pci_bus, -1, "pci-ohci");
}

View File

@ -649,7 +649,7 @@ static void ppc_prep_init(MachineState *machine)
memory_region_add_subregion(sysmem, 0xFEFF0000, xcsr);
#endif
if (usb_enabled()) {
if (machine_usb(machine)) {
pci_create_simple(pci_bus, -1, "pci-ohci");
}

View File

@ -670,48 +670,49 @@ static int ndis_query(USBNetState *s, uint32_t oid,
/* general oids (table 4-1) */
/* mandatory */
case OID_GEN_SUPPORTED_LIST:
for (i = 0; i < ARRAY_SIZE(oid_supported_list); i++)
((le32 *) outbuf)[i] = cpu_to_le32(oid_supported_list[i]);
for (i = 0; i < ARRAY_SIZE(oid_supported_list); i++) {
stl_le_p(outbuf + (i * sizeof(le32)), oid_supported_list[i]);
}
return sizeof(oid_supported_list);
/* mandatory */
case OID_GEN_HARDWARE_STATUS:
*((le32 *) outbuf) = cpu_to_le32(0);
stl_le_p(outbuf, 0);
return sizeof(le32);
/* mandatory */
case OID_GEN_MEDIA_SUPPORTED:
*((le32 *) outbuf) = cpu_to_le32(s->medium);
stl_le_p(outbuf, s->medium);
return sizeof(le32);
/* mandatory */
case OID_GEN_MEDIA_IN_USE:
*((le32 *) outbuf) = cpu_to_le32(s->medium);
stl_le_p(outbuf, s->medium);
return sizeof(le32);
/* mandatory */
case OID_GEN_MAXIMUM_FRAME_SIZE:
*((le32 *) outbuf) = cpu_to_le32(ETH_FRAME_LEN);
stl_le_p(outbuf, ETH_FRAME_LEN);
return sizeof(le32);
/* mandatory */
case OID_GEN_LINK_SPEED:
*((le32 *) outbuf) = cpu_to_le32(s->speed);
stl_le_p(outbuf, s->speed);
return sizeof(le32);
/* mandatory */
case OID_GEN_TRANSMIT_BLOCK_SIZE:
*((le32 *) outbuf) = cpu_to_le32(ETH_FRAME_LEN);
stl_le_p(outbuf, ETH_FRAME_LEN);
return sizeof(le32);
/* mandatory */
case OID_GEN_RECEIVE_BLOCK_SIZE:
*((le32 *) outbuf) = cpu_to_le32(ETH_FRAME_LEN);
stl_le_p(outbuf, ETH_FRAME_LEN);
return sizeof(le32);
/* mandatory */
case OID_GEN_VENDOR_ID:
*((le32 *) outbuf) = cpu_to_le32(s->vendorid);
stl_le_p(outbuf, s->vendorid);
return sizeof(le32);
/* mandatory */
@ -720,58 +721,57 @@ static int ndis_query(USBNetState *s, uint32_t oid,
return strlen((char *)outbuf) + 1;
case OID_GEN_VENDOR_DRIVER_VERSION:
*((le32 *) outbuf) = cpu_to_le32(1);
stl_le_p(outbuf, 1);
return sizeof(le32);
/* mandatory */
case OID_GEN_CURRENT_PACKET_FILTER:
*((le32 *) outbuf) = cpu_to_le32(s->filter);
stl_le_p(outbuf, s->filter);
return sizeof(le32);
/* mandatory */
case OID_GEN_MAXIMUM_TOTAL_SIZE:
*((le32 *) outbuf) = cpu_to_le32(RNDIS_MAX_TOTAL_SIZE);
stl_le_p(outbuf, RNDIS_MAX_TOTAL_SIZE);
return sizeof(le32);
/* mandatory */
case OID_GEN_MEDIA_CONNECT_STATUS:
*((le32 *) outbuf) = cpu_to_le32(s->media_state);
stl_le_p(outbuf, s->media_state);
return sizeof(le32);
case OID_GEN_PHYSICAL_MEDIUM:
*((le32 *) outbuf) = cpu_to_le32(0);
stl_le_p(outbuf, 0);
return sizeof(le32);
case OID_GEN_MAC_OPTIONS:
*((le32 *) outbuf) = cpu_to_le32(
NDIS_MAC_OPTION_RECEIVE_SERIALIZED |
NDIS_MAC_OPTION_FULL_DUPLEX);
stl_le_p(outbuf, NDIS_MAC_OPTION_RECEIVE_SERIALIZED |
NDIS_MAC_OPTION_FULL_DUPLEX);
return sizeof(le32);
/* statistics OIDs (table 4-2) */
/* mandatory */
case OID_GEN_XMIT_OK:
*((le32 *) outbuf) = cpu_to_le32(0);
stl_le_p(outbuf, 0);
return sizeof(le32);
/* mandatory */
case OID_GEN_RCV_OK:
*((le32 *) outbuf) = cpu_to_le32(0);
stl_le_p(outbuf, 0);
return sizeof(le32);
/* mandatory */
case OID_GEN_XMIT_ERROR:
*((le32 *) outbuf) = cpu_to_le32(0);
stl_le_p(outbuf, 0);
return sizeof(le32);
/* mandatory */
case OID_GEN_RCV_ERROR:
*((le32 *) outbuf) = cpu_to_le32(0);
stl_le_p(outbuf, 0);
return sizeof(le32);
/* mandatory */
case OID_GEN_RCV_NO_BUFFER:
*((le32 *) outbuf) = cpu_to_le32(0);
stl_le_p(outbuf, 0);
return sizeof(le32);
/* ieee802.3 OIDs (table 4-3) */
@ -787,12 +787,12 @@ static int ndis_query(USBNetState *s, uint32_t oid,
/* mandatory */
case OID_802_3_MULTICAST_LIST:
*((le32 *) outbuf) = cpu_to_le32(0xe0000000);
stl_le_p(outbuf, 0xe0000000);
return sizeof(le32);
/* mandatory */
case OID_802_3_MAXIMUM_LIST_SIZE:
*((le32 *) outbuf) = cpu_to_le32(1);
stl_le_p(outbuf, 1);
return sizeof(le32);
case OID_802_3_MAC_OPTIONS:
@ -801,17 +801,17 @@ static int ndis_query(USBNetState *s, uint32_t oid,
/* ieee802.3 statistics OIDs (table 4-4) */
/* mandatory */
case OID_802_3_RCV_ERROR_ALIGNMENT:
*((le32 *) outbuf) = cpu_to_le32(0);
stl_le_p(outbuf, 0);
return sizeof(le32);
/* mandatory */
case OID_802_3_XMIT_ONE_COLLISION:
*((le32 *) outbuf) = cpu_to_le32(0);
stl_le_p(outbuf, 0);
return sizeof(le32);
/* mandatory */
case OID_802_3_XMIT_MORE_COLLISIONS:
*((le32 *) outbuf) = cpu_to_le32(0);
stl_le_p(outbuf, 0);
return sizeof(le32);
default:
@ -826,7 +826,7 @@ static int ndis_set(USBNetState *s, uint32_t oid,
{
switch (oid) {
case OID_GEN_CURRENT_PACKET_FILTER:
s->filter = le32_to_cpup((le32 *) inbuf);
s->filter = ldl_le_p(inbuf);
if (s->filter) {
s->rndis_state = RNDIS_DATA_INITIALIZED;
} else {
@ -1026,10 +1026,7 @@ static void usb_net_reset_in_buf(USBNetState *s)
static int rndis_parse(USBNetState *s, uint8_t *data, int length)
{
uint32_t msg_type;
le32 *tmp = (le32 *) data;
msg_type = le32_to_cpup(tmp);
uint32_t msg_type = ldl_le_p(data);
switch (msg_type) {
case RNDIS_INITIALIZE_MSG:

View File

@ -81,6 +81,7 @@ struct USBHostDevice {
uint32_t iso_urb_frames;
uint32_t options;
uint32_t loglevel;
bool needs_autoscan;
/* state */
QTAILQ_ENTRY(USBHostDevice) next;
@ -974,9 +975,32 @@ static void usb_host_exit_notifier(struct Notifier *n, void *data)
}
}
static libusb_device *usb_host_find_ref(int bus, int addr)
{
libusb_device **devs = NULL;
libusb_device *ret = NULL;
int i, n;
if (usb_host_init() != 0) {
return NULL;
}
n = libusb_get_device_list(ctx, &devs);
for (i = 0; i < n; i++) {
if (libusb_get_bus_number(devs[i]) == bus &&
libusb_get_device_address(devs[i]) == addr) {
ret = libusb_ref_device(devs[i]);
break;
}
}
libusb_free_device_list(devs, 1);
return ret;
}
static void usb_host_realize(USBDevice *udev, Error **errp)
{
USBHostDevice *s = USB_HOST_DEVICE(udev);
libusb_device *ldev;
int rc;
if (s->match.vendor_id > 0xffff) {
error_setg(errp, "vendorid out of range");
@ -997,11 +1021,33 @@ static void usb_host_realize(USBDevice *udev, Error **errp)
QTAILQ_INIT(&s->requests);
QTAILQ_INIT(&s->isorings);
if (s->match.addr && s->match.bus_num &&
!s->match.vendor_id &&
!s->match.product_id &&
!s->match.port) {
s->needs_autoscan = false;
ldev = usb_host_find_ref(s->match.bus_num,
s->match.addr);
if (!ldev) {
error_setg(errp, "failed to find host usb device %d:%d",
s->match.bus_num, s->match.addr);
return;
}
rc = usb_host_open(s, ldev);
libusb_unref_device(ldev);
if (rc < 0) {
error_setg(errp, "failed to open host usb device %d:%d",
s->match.bus_num, s->match.addr);
return;
}
} else {
s->needs_autoscan = true;
QTAILQ_INSERT_TAIL(&hostdevs, s, next);
usb_host_auto_check(NULL);
}
s->exit.notify = usb_host_exit_notifier;
qemu_add_exit_notifier(&s->exit);
QTAILQ_INSERT_TAIL(&hostdevs, s, next);
usb_host_auto_check(NULL);
}
static void usb_host_instance_init(Object *obj)
@ -1019,7 +1065,9 @@ static void usb_host_handle_destroy(USBDevice *udev)
USBHostDevice *s = USB_HOST_DEVICE(udev);
qemu_remove_exit_notifier(&s->exit);
QTAILQ_REMOVE(&hostdevs, s, next);
if (s->needs_autoscan) {
QTAILQ_REMOVE(&hostdevs, s, next);
}
usb_host_close(s);
}

View File

@ -233,7 +233,6 @@ void qemu_boot_set(const char *boot_order, Error **errp);
QemuOpts *qemu_get_machine_opts(void);
bool defaults_enabled(void);
bool usb_enabled(void);
extern QemuOptsList qemu_legacy_drive_opts;
extern QemuOptsList qemu_common_drive_opts;

11
vl.c
View File

@ -1072,11 +1072,6 @@ bool defaults_enabled(void)
return has_defaults;
}
bool usb_enabled(void)
{
return machine_usb(current_machine);
}
#ifndef _WIN32
static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp)
{
@ -1393,7 +1388,7 @@ static int usb_device_add(const char *devname)
const char *p;
#endif
if (!usb_enabled()) {
if (!machine_usb(current_machine)) {
return -1;
}
@ -1425,7 +1420,7 @@ static int usb_device_del(const char *devname)
return -1;
}
if (!usb_enabled()) {
if (!machine_usb(current_machine)) {
return -1;
}
@ -4501,7 +4496,7 @@ int main(int argc, char **argv, char **envp)
}
/* init USB devices */
if (usb_enabled()) {
if (machine_usb(current_machine)) {
if (foreach_device_config(DEV_USB, usb_parse) < 0)
exit(1);
}