diff options
Diffstat (limited to 'hw')
-rw-r--r-- | hw/ac97.c | 139 | ||||
-rw-r--r-- | hw/acpi_piix4.c | 134 | ||||
-rw-r--r-- | hw/ivshmem.c | 48 | ||||
-rw-r--r-- | hw/pc.c | 8 | ||||
-rw-r--r-- | hw/pc_piix.c | 301 | ||||
-rw-r--r-- | hw/pci_host.c | 3 | ||||
-rw-r--r-- | hw/pcnet.c | 13 | ||||
-rw-r--r-- | hw/pcnet.h | 1 | ||||
-rw-r--r-- | hw/piix_pci.c | 2 | ||||
-rw-r--r-- | hw/qxl-render.c | 1 | ||||
-rw-r--r-- | hw/qxl.c | 4 | ||||
-rw-r--r-- | hw/usb.h | 5 | ||||
-rw-r--r-- | hw/usb/bus.c | 17 | ||||
-rw-r--r-- | hw/usb/core.c | 17 | ||||
-rw-r--r-- | hw/usb/desc.c | 126 | ||||
-rw-r--r-- | hw/usb/desc.h | 63 | ||||
-rw-r--r-- | hw/usb/dev-hub.c | 43 | ||||
-rw-r--r-- | hw/usb/hcd-ehci.c | 16 | ||||
-rw-r--r-- | hw/usb/hcd-uhci.c | 16 | ||||
-rw-r--r-- | hw/usb/host-linux.c | 237 | ||||
-rw-r--r-- | hw/usb/redirect.c | 11 | ||||
-rw-r--r-- | hw/vhost.c | 10 | ||||
-rw-r--r-- | hw/virtio-pci.c | 8 | ||||
-rw-r--r-- | hw/xen.h | 1 | ||||
-rw-r--r-- | hw/xen_apic.c | 90 | ||||
-rw-r--r-- | hw/xen_backend.c | 17 | ||||
-rw-r--r-- | hw/xen_disk.c | 4 |
27 files changed, 753 insertions, 582 deletions
@@ -118,7 +118,6 @@ enum { #define EACS_VRA 1 #define EACS_VRM 8 -#define VOL_MASK 0x1f #define MUTE_SHIFT 15 #define REC_MASK 7 @@ -437,83 +436,55 @@ static void reset_voices (AC97LinkState *s, uint8_t active[LAST_INDEX]) AUD_set_active_in (s->voice_mc, active[MC_INDEX]); } -#ifdef USE_MIXER -static void set_volume (AC97LinkState *s, int index, - audmixerctl_t mt, uint32_t val) +static void get_volume (uint16_t vol, uint16_t mask, int inverse, + int *mute, uint8_t *lvol, uint8_t *rvol) { - int mute = (val >> MUTE_SHIFT) & 1; - uint8_t rvol = VOL_MASK - (val & VOL_MASK); - uint8_t lvol = VOL_MASK - ((val >> 8) & VOL_MASK); - rvol = 255 * rvol / VOL_MASK; - lvol = 255 * lvol / VOL_MASK; - -#ifdef SOFT_VOLUME - if (index == AC97_Master_Volume_Mute) { - AUD_set_volume_out (s->voice_po, mute, lvol, rvol); - } - else { - AUD_set_volume (mt, &mute, &lvol, &rvol); - } -#else - AUD_set_volume (mt, &mute, &lvol, &rvol); -#endif + *mute = (vol >> MUTE_SHIFT) & 1; + *rvol = (255 * (vol & mask)) / mask; + *lvol = (255 * ((vol >> 8) & mask)) / mask; - rvol = VOL_MASK - ((VOL_MASK * rvol) / 255); - lvol = VOL_MASK - ((VOL_MASK * lvol) / 255); - mixer_store (s, index, val); + if (inverse) { + *rvol = 255 - *rvol; + *lvol = 255 - *lvol; + } } -static audrecsource_t ac97_to_aud_record_source (uint8_t i) +static void update_combined_volume_out (AC97LinkState *s) { - switch (i) { - case REC_MIC: - return AUD_REC_MIC; - - case REC_CD: - return AUD_REC_CD; + uint8_t lvol, rvol, plvol, prvol; + int mute, pmute; - case REC_VIDEO: - return AUD_REC_VIDEO; + get_volume (mixer_load (s, AC97_Master_Volume_Mute), 0x3f, 1, + &mute, &lvol, &rvol); + /* FIXME: should be 1f according to spec */ + get_volume (mixer_load (s, AC97_PCM_Out_Volume_Mute), 0x3f, 1, + &pmute, &plvol, &prvol); - case REC_AUX: - return AUD_REC_AUX; + mute = mute | pmute; + lvol = (lvol * plvol) / 255; + rvol = (rvol * prvol) / 255; - case REC_LINE_IN: - return AUD_REC_LINE_IN; - - case REC_PHONE: - return AUD_REC_PHONE; - - default: - dolog ("Unknown record source %d, using MIC\n", i); - return AUD_REC_MIC; - } + AUD_set_volume_out (s->voice_po, mute, lvol, rvol); } -static uint8_t aud_to_ac97_record_source (audrecsource_t rs) +static void update_volume_in (AC97LinkState *s) { - switch (rs) { - case AUD_REC_MIC: - return REC_MIC; - - case AUD_REC_CD: - return REC_CD; - - case AUD_REC_VIDEO: - return REC_VIDEO; - - case AUD_REC_AUX: - return REC_AUX; + uint8_t lvol, rvol; + int mute; - case AUD_REC_LINE_IN: - return REC_LINE_IN; + get_volume (mixer_load (s, AC97_Record_Gain_Mute), 0x0f, 0, + &mute, &lvol, &rvol); - case AUD_REC_PHONE: - return REC_PHONE; + AUD_set_volume_in (s->voice_pi, mute, lvol, rvol); +} - default: - dolog ("Unknown audio recording source %d using MIC\n", rs); - return REC_MIC; +static void set_volume (AC97LinkState *s, int index, uint32_t val) +{ + mixer_store (s, index, val); + if (index == AC97_Master_Volume_Mute || index == AC97_PCM_Out_Volume_Mute) { + update_combined_volume_out (s); + } else if (index == AC97_Record_Gain_Mute) { + update_volume_in (s); } } @@ -521,14 +492,8 @@ static void record_select (AC97LinkState *s, uint32_t val) { uint8_t rs = val & REC_MASK; uint8_t ls = (val >> 8) & REC_MASK; - audrecsource_t ars = ac97_to_aud_record_source (rs); - audrecsource_t als = ac97_to_aud_record_source (ls); - AUD_set_record_source (&als, &ars); - rs = aud_to_ac97_record_source (ars); - ls = aud_to_ac97_record_source (als); mixer_store (s, AC97_Record_Select, rs | (ls << 8)); } -#endif static void mixer_reset (AC97LinkState *s) { @@ -564,12 +529,11 @@ static void mixer_reset (AC97LinkState *s) mixer_store (s, AC97_PCM_LR_ADC_Rate , 0xbb80); mixer_store (s, AC97_MIC_ADC_Rate , 0xbb80); -#ifdef USE_MIXER record_select (s, 0); - set_volume (s, AC97_Master_Volume_Mute, AUD_MIXER_VOLUME , 0x8000); - set_volume (s, AC97_PCM_Out_Volume_Mute, AUD_MIXER_PCM , 0x8808); - set_volume (s, AC97_Line_In_Volume_Mute, AUD_MIXER_LINE_IN, 0x8808); -#endif + set_volume (s, AC97_Master_Volume_Mute, 0x8000); + set_volume (s, AC97_PCM_Out_Volume_Mute, 0x8808); + set_volume (s, AC97_Line_In_Volume_Mute, 0x8808); + reset_voices (s, active); } @@ -628,20 +592,15 @@ static void nam_writew (void *opaque, uint32_t addr, uint32_t val) val |= mixer_load (s, index) & 0xf; mixer_store (s, index, val); break; -#ifdef USE_MIXER - case AC97_Master_Volume_Mute: - set_volume (s, index, AUD_MIXER_VOLUME, val); - break; case AC97_PCM_Out_Volume_Mute: - set_volume (s, index, AUD_MIXER_PCM, val); - break; + case AC97_Master_Volume_Mute: + case AC97_Record_Gain_Mute: case AC97_Line_In_Volume_Mute: - set_volume (s, index, AUD_MIXER_LINE_IN, val); + set_volume (s, index, val); break; case AC97_Record_Select: record_select (s, val); break; -#endif case AC97_Vendor_ID1: case AC97_Vendor_ID2: dolog ("Attempt to write vendor ID to %#x\n", val); @@ -1194,14 +1153,14 @@ static int ac97_post_load (void *opaque, int version_id) uint8_t active[LAST_INDEX]; AC97LinkState *s = opaque; -#ifdef USE_MIXER record_select (s, mixer_load (s, AC97_Record_Select)); -#define V_(a, b) set_volume (s, a, b, mixer_load (s, a)) - V_ (AC97_Master_Volume_Mute, AUD_MIXER_VOLUME); - V_ (AC97_PCM_Out_Volume_Mute, AUD_MIXER_PCM); - V_ (AC97_Line_In_Volume_Mute, AUD_MIXER_LINE_IN); -#undef V_ -#endif + set_volume (s, AC97_Master_Volume_Mute, + mixer_load (s, AC97_Master_Volume_Mute)); + set_volume (s, AC97_PCM_Out_Volume_Mute, + mixer_load (s, AC97_PCM_Out_Volume_Mute)); + set_volume (s, AC97_Line_In_Volume_Mute, + mixer_load (s, AC97_Line_In_Volume_Mute)); + active[PI_INDEX] = !!(s->bm_regs[PI_INDEX].cr & CR_RPBM); active[PO_INDEX] = !!(s->bm_regs[PO_INDEX].cr & CR_RPBM); active[MC_INDEX] = !!(s->bm_regs[MC_INDEX].cr & CR_RPBM); diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c index 797ed245fc..585da4e3eb 100644 --- a/hw/acpi_piix4.c +++ b/hw/acpi_piix4.c @@ -40,14 +40,15 @@ #define GPE_BASE 0xafe0 #define GPE_LEN 4 -#define PCI_BASE 0xae00 +#define PCI_UP_BASE 0xae00 +#define PCI_DOWN_BASE 0xae04 #define PCI_EJ_BASE 0xae08 #define PCI_RMV_BASE 0xae0c #define PIIX4_PCI_HOTPLUG_STATUS 2 struct pci_status { - uint32_t up; + uint32_t up; /* deprecated, maintained for migration compatibility */ uint32_t down; }; @@ -69,6 +70,7 @@ typedef struct PIIX4PMState { /* for pci hotplug */ struct pci_status pci0_status; uint32_t pci0_hotplug_enable; + uint32_t pci0_slot_device_present; } PIIX4PMState; static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s); @@ -204,6 +206,17 @@ static void pm_write_config(PCIDevice *d, pm_io_space_update((PIIX4PMState *)d); } +static void vmstate_pci_status_pre_save(void *opaque) +{ + struct pci_status *pci0_status = opaque; + PIIX4PMState *s = container_of(pci0_status, PIIX4PMState, pci0_status); + + /* We no longer track up, so build a safe value for migrating + * to a version that still does... of course these might get lost + * by an old buggy implementation, but we try. */ + pci0_status->up = s->pci0_slot_device_present & s->pci0_hotplug_enable; +} + static int vmstate_acpi_post_load(void *opaque, int version_id) { PIIX4PMState *s = opaque; @@ -240,6 +253,7 @@ static const VMStateDescription vmstate_pci_status = { .version_id = 1, .minimum_version_id = 1, .minimum_version_id_old = 1, + .pre_save = vmstate_pci_status_pre_save, .fields = (VMStateField []) { VMSTATE_UINT32(up, struct pci_status), VMSTATE_UINT32(down, struct pci_status), @@ -268,13 +282,45 @@ static const VMStateDescription vmstate_acpi = { } }; +static void acpi_piix_eject_slot(PIIX4PMState *s, unsigned slots) +{ + DeviceState *qdev, *next; + BusState *bus = qdev_get_parent_bus(&s->dev.qdev); + int slot = ffs(slots) - 1; + bool slot_free = true; + + /* Mark request as complete */ + s->pci0_status.down &= ~(1U << slot); + + QTAILQ_FOREACH_SAFE(qdev, &bus->children, sibling, next) { + PCIDevice *dev = PCI_DEVICE(qdev); + PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev); + if (PCI_SLOT(dev->devfn) == slot) { + if (pc->no_hotplug) { + slot_free = false; + } else { + qdev_free(qdev); + } + } + } + if (slot_free) { + s->pci0_slot_device_present &= ~(1U << slot); + } +} + static void piix4_update_hotplug(PIIX4PMState *s) { PCIDevice *dev = &s->dev; BusState *bus = qdev_get_parent_bus(&dev->qdev); DeviceState *qdev, *next; + /* Execute any pending removes during reset */ + while (s->pci0_status.down) { + acpi_piix_eject_slot(s, s->pci0_status.down); + } + s->pci0_hotplug_enable = ~0; + s->pci0_slot_device_present = 0; QTAILQ_FOREACH_SAFE(qdev, &bus->children, sibling, next) { PCIDevice *pdev = PCI_DEVICE(qdev); @@ -282,8 +328,10 @@ static void piix4_update_hotplug(PIIX4PMState *s) int slot = PCI_SLOT(pdev->devfn); if (pc->no_hotplug) { - s->pci0_hotplug_enable &= ~(1 << slot); + s->pci0_hotplug_enable &= ~(1U << slot); } + + s->pci0_slot_device_present |= (1U << slot); } } @@ -448,60 +496,38 @@ static void gpe_writeb(void *opaque, uint32_t addr, uint32_t val) PIIX4_DPRINTF("gpe write %x <== %d\n", addr, val); } -static uint32_t pcihotplug_read(void *opaque, uint32_t addr) +static uint32_t pci_up_read(void *opaque, uint32_t addr) { - uint32_t val = 0; - struct pci_status *g = opaque; - switch (addr) { - case PCI_BASE: - val = g->up; - break; - case PCI_BASE + 4: - val = g->down; - break; - default: - break; - } + PIIX4PMState *s = opaque; + uint32_t val; - PIIX4_DPRINTF("pcihotplug read %x == %x\n", addr, val); + /* Manufacture an "up" value to cause a device check on any hotplug + * slot with a device. Extra device checks are harmless. */ + val = s->pci0_slot_device_present & s->pci0_hotplug_enable; + + PIIX4_DPRINTF("pci_up_read %x\n", val); return val; } -static void pcihotplug_write(void *opaque, uint32_t addr, uint32_t val) +static uint32_t pci_down_read(void *opaque, uint32_t addr) { - struct pci_status *g = opaque; - switch (addr) { - case PCI_BASE: - g->up = val; - break; - case PCI_BASE + 4: - g->down = val; - break; - } - - PIIX4_DPRINTF("pcihotplug write %x <== %d\n", addr, val); + PIIX4PMState *s = opaque; + uint32_t val = s->pci0_status.down; + + PIIX4_DPRINTF("pci_down_read %x\n", val); + return val; } -static uint32_t pciej_read(void *opaque, uint32_t addr) +static uint32_t pci_features_read(void *opaque, uint32_t addr) { - PIIX4_DPRINTF("pciej read %x\n", addr); + /* No feature defined yet */ + PIIX4_DPRINTF("pci_features_read %x\n", 0); return 0; } static void pciej_write(void *opaque, uint32_t addr, uint32_t val) { - BusState *bus = opaque; - DeviceState *qdev, *next; - int slot = ffs(val) - 1; - - QTAILQ_FOREACH_SAFE(qdev, &bus->children, sibling, next) { - PCIDevice *dev = PCI_DEVICE(qdev); - PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev); - if (PCI_SLOT(dev->devfn) == slot && !pc->no_hotplug) { - qdev_free(qdev); - } - } - + acpi_piix_eject_slot(opaque, val); PIIX4_DPRINTF("pciej write %x <== %d\n", addr, val); } @@ -513,29 +539,22 @@ static uint32_t pcirmv_read(void *opaque, uint32_t addr) return s->pci0_hotplug_enable; } -static void pcirmv_write(void *opaque, uint32_t addr, uint32_t val) -{ - return; -} - static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev, PCIHotplugState state); static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s) { - struct pci_status *pci0_status = &s->pci0_status; register_ioport_write(GPE_BASE, GPE_LEN, 1, gpe_writeb, s); register_ioport_read(GPE_BASE, GPE_LEN, 1, gpe_readb, s); acpi_gpe_blk(&s->ar, GPE_BASE); - register_ioport_write(PCI_BASE, 8, 4, pcihotplug_write, pci0_status); - register_ioport_read(PCI_BASE, 8, 4, pcihotplug_read, pci0_status); + register_ioport_read(PCI_UP_BASE, 4, 4, pci_up_read, s); + register_ioport_read(PCI_DOWN_BASE, 4, 4, pci_down_read, s); - register_ioport_write(PCI_EJ_BASE, 4, 4, pciej_write, bus); - register_ioport_read(PCI_EJ_BASE, 4, 4, pciej_read, bus); + register_ioport_write(PCI_EJ_BASE, 4, 4, pciej_write, s); + register_ioport_read(PCI_EJ_BASE, 4, 4, pci_features_read, s); - register_ioport_write(PCI_RMV_BASE, 4, 4, pcirmv_write, s); register_ioport_read(PCI_RMV_BASE, 4, 4, pcirmv_read, s); pci_bus_hotplug(bus, piix4_device_hotplug, &s->dev.qdev); @@ -544,13 +563,13 @@ static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s) static void enable_device(PIIX4PMState *s, int slot) { s->ar.gpe.sts[0] |= PIIX4_PCI_HOTPLUG_STATUS; - s->pci0_status.up |= (1 << slot); + s->pci0_slot_device_present |= (1U << slot); } static void disable_device(PIIX4PMState *s, int slot) { s->ar.gpe.sts[0] |= PIIX4_PCI_HOTPLUG_STATUS; - s->pci0_status.down |= (1 << slot); + s->pci0_status.down |= (1U << slot); } static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev, @@ -564,11 +583,10 @@ static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev, * it is present on boot, no hotplug event is necessary. We do send an * event when the device is disabled later. */ if (state == PCI_COLDPLUG_ENABLED) { + s->pci0_slot_device_present |= (1U << slot); return 0; } - s->pci0_status.up = 0; - s->pci0_status.down = 0; if (state == PCI_HOTPLUG_ENABLED) { enable_device(s, slot); } else { diff --git a/hw/ivshmem.c b/hw/ivshmem.c index df4f50a092..d48e5f9906 100644 --- a/hw/ivshmem.c +++ b/hw/ivshmem.c @@ -509,11 +509,29 @@ static void ivshmem_read(void *opaque, const uint8_t * buf, int flags) return; } +/* Select the MSI-X vectors used by device. + * ivshmem maps events to vectors statically, so + * we just enable all vectors on init and after reset. */ +static void ivshmem_use_msix(IVShmemState * s) +{ + int i; + + if (!msix_present(&s->dev)) { + return; + } + + for (i = 0; i < s->vectors; i++) { + msix_vector_use(&s->dev, i); + } +} + static void ivshmem_reset(DeviceState *d) { IVShmemState *s = DO_UPCAST(IVShmemState, dev.qdev, d); s->intrstatus = 0; + msix_reset(&s->dev); + ivshmem_use_msix(s); return; } @@ -544,12 +562,8 @@ static uint64_t ivshmem_get_size(IVShmemState * s) { return value; } -static void ivshmem_setup_msi(IVShmemState * s) { - - int i; - - /* allocate the MSI-X vectors */ - +static void ivshmem_setup_msi(IVShmemState * s) +{ memory_region_init(&s->msix_bar, "ivshmem-msix", 4096); if (!msix_init(&s->dev, s->vectors, &s->msix_bar, 1, 0)) { pci_register_bar(&s->dev, 1, PCI_BASE_ADDRESS_SPACE_MEMORY, @@ -560,13 +574,10 @@ static void ivshmem_setup_msi(IVShmemState * s) { exit(1); } - /* 'activate' the vectors */ - for (i = 0; i < s->vectors; i++) { - msix_vector_use(&s->dev, i); - } - /* allocate QEMU char devices for receiving interrupts */ s->eventfd_table = g_malloc0(s->vectors * sizeof(EventfdEntry)); + + ivshmem_use_msix(s); } static void ivshmem_save(QEMUFile* f, void *opaque) @@ -590,7 +601,7 @@ static int ivshmem_load(QEMUFile* f, void *opaque, int version_id) IVSHMEM_DPRINTF("ivshmem_load\n"); IVShmemState *proxy = opaque; - int ret, i; + int ret; if (version_id > 0) { return -EINVAL; @@ -608,9 +619,7 @@ static int ivshmem_load(QEMUFile* f, void *opaque, int version_id) if (ivshmem_has_feature(proxy, IVSHMEM_MSI)) { msix_load(&proxy->dev, f); - for (i = 0; i < proxy->vectors; i++) { - msix_vector_use(&proxy->dev, i); - } + ivshmem_use_msix(proxy); } else { proxy->intrstatus = qemu_get_be32(f); proxy->intrmask = qemu_get_be32(f); @@ -619,6 +628,13 @@ static int ivshmem_load(QEMUFile* f, void *opaque, int version_id) return 0; } +static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t address, + uint32_t val, int len) +{ + pci_default_write_config(pci_dev, address, val, len); + msix_write_config(pci_dev, address, val, len); +} + static int pci_ivshmem_init(PCIDevice *dev) { IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev); @@ -744,6 +760,8 @@ static int pci_ivshmem_init(PCIDevice *dev) } + s->dev.config_write = ivshmem_write_config; + return 0; } @@ -42,6 +42,7 @@ #include "sysbus.h" #include "sysemu.h" #include "kvm.h" +#include "xen.h" #include "blockdev.h" #include "ui/qemu-spice.h" #include "memory.h" @@ -891,9 +892,12 @@ static DeviceState *apic_init(void *env, uint8_t apic_id) if (kvm_irqchip_in_kernel()) { dev = qdev_create(NULL, "kvm-apic"); + } else if (xen_enabled()) { + dev = qdev_create(NULL, "xen-apic"); } else { dev = qdev_create(NULL, "apic"); } + qdev_prop_set_uint8(dev, "id", apic_id); qdev_prop_set_ptr(dev, "cpu_env", env); qdev_init_nofail(dev); @@ -912,6 +916,10 @@ static DeviceState *apic_init(void *env, uint8_t apic_id) msi_supported = true; } + if (xen_enabled()) { + msi_supported = true; + } + return dev; } diff --git a/hw/pc_piix.c b/hw/pc_piix.c index fadca4c710..6a75718fbb 100644 --- a/hw/pc_piix.c +++ b/hw/pc_piix.c @@ -28,6 +28,7 @@ #include "pc.h" #include "apic.h" #include "pci.h" +#include "pci_ids.h" #include "net.h" #include "boards.h" #include "ide.h" @@ -359,50 +360,81 @@ static QEMUMachine pc_machine_v1_1 = { .is_default = 1, }; +#define PC_COMPAT_1_0 \ + {\ + .driver = "pc-sysfw",\ + .property = "rom_only",\ + .value = stringify(1),\ + }, {\ + .driver = "isa-fdc",\ + .property = "check_media_rate",\ + .value = "off",\ + }, {\ + .driver = "virtio-balloon-pci",\ + .property = "class",\ + .value = stringify(PCI_CLASS_MEMORY_RAM),\ + },{\ + .driver = "apic",\ + .property = "vapic",\ + .value = "off",\ + },{\ + .driver = "USB",\ + .property = "full-path",\ + .value = "no",\ + } + static QEMUMachine pc_machine_v1_0 = { .name = "pc-1.0", .desc = "Standard PC", .init = pc_init_pci, .max_cpus = 255, .compat_props = (GlobalProperty[]) { - { - .driver = "pc-sysfw", - .property = "rom_only", - .value = stringify(1), - }, { - .driver = "isa-fdc", - .property = "check_media_rate", - .value = "off", - }, + PC_COMPAT_1_0, { /* end of list */ } }, }; +#define PC_COMPAT_0_15 \ + PC_COMPAT_1_0 + static QEMUMachine pc_machine_v0_15 = { .name = "pc-0.15", .desc = "Standard PC", .init = pc_init_pci, .max_cpus = 255, .compat_props = (GlobalProperty[]) { - { - .driver = "pc-sysfw", - .property = "rom_only", - .value = stringify(1), - }, { - .driver = "isa-fdc", - .property = "check_media_rate", - .value = "off", - }, + PC_COMPAT_0_15, { /* end of list */ } }, }; +#define PC_COMPAT_0_14 \ + PC_COMPAT_0_15,\ + {\ + .driver = "virtio-blk-pci",\ + .property = "event_idx",\ + .value = "off",\ + },{\ + .driver = "virtio-serial-pci",\ + .property = "event_idx",\ + .value = "off",\ + },{\ + .driver = "virtio-net-pci",\ + .property = "event_idx",\ + .value = "off",\ + },{\ + .driver = "virtio-balloon-pci",\ + .property = "event_idx",\ + .value = "off",\ + } + static QEMUMachine pc_machine_v0_14 = { .name = "pc-0.14", .desc = "Standard PC", .init = pc_init_pci, .max_cpus = 255, .compat_props = (GlobalProperty[]) { + PC_COMPAT_0_14, { .driver = "qxl", .property = "revision", @@ -411,42 +443,30 @@ static QEMUMachine pc_machine_v0_14 = { .driver = "qxl-vga", .property = "revision", .value = stringify(2), - },{ - .driver = "virtio-blk-pci", - .property = "event_idx", - .value = "off", - },{ - .driver = "virtio-serial-pci", - .property = "event_idx", - .value = "off", - },{ - .driver = "virtio-net-pci", - .property = "event_idx", - .value = "off", - },{ - .driver = "virtio-balloon-pci", - .property = "event_idx", - .value = "off", - },{ - .driver = "isa-fdc", - .property = "check_media_rate", - .value = "off", - }, - { - .driver = "pc-sysfw", - .property = "rom_only", - .value = stringify(1), }, { /* end of list */ } }, }; +#define PC_COMPAT_0_13 \ + PC_COMPAT_0_14,\ + {\ + .driver = "PCI",\ + .property = "command_serr_enable",\ + .value = "off",\ + },{\ + .driver = "AC97",\ + .property = "use_broken_id",\ + .value = stringify(1),\ + } + static QEMUMachine pc_machine_v0_13 = { .name = "pc-0.13", .desc = "Standard PC", .init = pc_init_pci_no_kvmclock, .max_cpus = 255, .compat_props = (GlobalProperty[]) { + PC_COMPAT_0_13, { .driver = "virtio-9p-pci", .property = "vectors", @@ -459,59 +479,31 @@ static QEMUMachine pc_machine_v0_13 = { .driver = "vmware-svga", .property = "rombar", .value = stringify(0), - },{ - .driver = "PCI", - .property = "command_serr_enable", - .value = "off", - },{ - .driver = "virtio-blk-pci", - .property = "event_idx", - .value = "off", - },{ - .driver = "virtio-serial-pci", - .property = "event_idx", - .value = "off", - },{ - .driver = "virtio-net-pci", - .property = "event_idx", - .value = "off", - },{ - .driver = "virtio-balloon-pci", - .property = "event_idx", - .value = "off", - },{ - .driver = "AC97", - .property = "use_broken_id", - .value = stringify(1), - },{ - .driver = "isa-fdc", - .property = "check_media_rate", - .value = "off", - }, - { - .driver = "pc-sysfw", - .property = "rom_only", - .value = stringify(1), }, { /* end of list */ } }, }; +#define PC_COMPAT_0_12 \ + PC_COMPAT_0_13,\ + {\ + .driver = "virtio-serial-pci",\ + .property = "max_ports",\ + .value = stringify(1),\ + },{\ + .driver = "virtio-serial-pci",\ + .property = "vectors",\ + .value = stringify(0),\ + } + static QEMUMachine pc_machine_v0_12 = { .name = "pc-0.12", .desc = "Standard PC", .init = pc_init_pci_no_kvmclock, .max_cpus = 255, .compat_props = (GlobalProperty[]) { + PC_COMPAT_0_12, { - .driver = "virtio-serial-pci", - .property = "max_ports", - .value = stringify(1), - },{ - .driver = "virtio-serial-pci", - .property = "vectors", - .value = stringify(0), - },{ .driver = "VGA", .property = "rombar", .value = stringify(0), @@ -519,63 +511,27 @@ static QEMUMachine pc_machine_v0_12 = { .driver = "vmware-svga", .property = "rombar", .value = stringify(0), - },{ - .driver = "PCI", - .property = "command_serr_enable", - .value = "off", - },{ - .driver = "virtio-blk-pci", - .property = "event_idx", - .value = "off", - },{ - .driver = "virtio-serial-pci", - .property = "event_idx", - .value = "off", - },{ - .driver = "virtio-net-pci", - .property = "event_idx", - .value = "off", - },{ - .driver = "virtio-balloon-pci", - .property = "event_idx", - .value = "off", - },{ - .driver = "AC97", - .property = "use_broken_id", - .value = stringify(1), - },{ - .driver = "isa-fdc", - .property = "check_media_rate", - .value = "off", - }, - { - .driver = "pc-sysfw", - .property = "rom_only", - .value = stringify(1), }, { /* end of list */ } } }; +#define PC_COMPAT_0_11 \ + PC_COMPAT_0_12,\ + {\ + .driver = "virtio-blk-pci",\ + .property = "vectors",\ + .value = stringify(0),\ + } + static QEMUMachine pc_machine_v0_11 = { .name = "pc-0.11", .desc = "Standard PC, qemu 0.11", .init = pc_init_pci_no_kvmclock, .max_cpus = 255, .compat_props = (GlobalProperty[]) { + PC_COMPAT_0_11, { - .driver = "virtio-blk-pci", - .property = "vectors", - .value = stringify(0), - },{ - .driver = "virtio-serial-pci", - .property = "max_ports", - .value = stringify(1), - },{ - .driver = "virtio-serial-pci", - .property = "vectors", - .value = stringify(0), - },{ .driver = "ide-drive", .property = "ver", .value = "0.11", @@ -583,43 +539,6 @@ static QEMUMachine pc_machine_v0_11 = { .driver = "scsi-disk", .property = "ver", .value = "0.11", - },{ - .driver = "PCI", - .property = "rombar", - .value = stringify(0), - },{ - .driver = "PCI", - .property = "command_serr_enable", - .value = "off", - },{ - .driver = "virtio-blk-pci", - .property = "event_idx", - .value = "off", - },{ - .driver = "virtio-serial-pci", - .property = "event_idx", - .value = "off", - },{ - .driver = "virtio-net-pci", - .property = "event_idx", - .value = "off", - },{ - .driver = "virtio-balloon-pci", - .property = "event_idx", - .value = "off", - },{ - .driver = "AC97", - .property = "use_broken_id", - .value = stringify(1), - },{ - .driver = "isa-fdc", - .property = "check_media_rate", - .value = "off", - }, - { - .driver = "pc-sysfw", - .property = "rom_only", - .value = stringify(1), }, { /* end of list */ } } @@ -631,6 +550,7 @@ static QEMUMachine pc_machine_v0_10 = { .init = pc_init_pci_no_kvmclock, .max_cpus = 255, .compat_props = (GlobalProperty[]) { + PC_COMPAT_0_11, { .driver = "virtio-blk-pci", .property = "class", @@ -640,22 +560,10 @@ static QEMUMachine pc_machine_v0_10 = { .property = "class", .value = stringify(PCI_CLASS_DISPLAY_OTHER), },{ - .driver = "virtio-serial-pci", - .property = "max_ports", - .value = stringify(1), - },{ - .driver = "virtio-serial-pci", - .property = "vectors", - .value = stringify(0), - },{ .driver = "virtio-net-pci", .property = "vectors", .value = stringify(0), },{ - .driver = "virtio-blk-pci", - .property = "vectors", - .value = stringify(0), - },{ .driver = "ide-drive", .property = "ver", .value = "0.10", @@ -663,43 +571,6 @@ static QEMUMachine pc_machine_v0_10 = { .driver = "scsi-disk", .property = "ver", .value = "0.10", - },{ - .driver = "PCI", - .property = "rombar", - .value = stringify(0), - },{ - .driver = "PCI", - .property = "command_serr_enable", - .value = "off", - },{ - .driver = "virtio-blk-pci", - .property = "event_idx", - .value = "off", - },{ - .driver = "virtio-serial-pci", - .property = "event_idx", - .value = "off", - },{ - .driver = "virtio-net-pci", - .property = "event_idx", - .value = "off", - },{ - .driver = "virtio-balloon-pci", - .property = "event_idx", - .value = "off", - },{ - .driver = "AC97", - .property = "use_broken_id", - .value = stringify(1), - },{ - .driver = "isa-fdc", - .property = "check_media_rate", - .value = "off", - }, - { - .driver = "pc-sysfw", - .property = "rom_only", - .value = stringify(1), }, { /* end of list */ } }, diff --git a/hw/pci_host.c b/hw/pci_host.c index 44c6c207a9..804177891a 100644 --- a/hw/pci_host.c +++ b/hw/pci_host.c @@ -101,6 +101,9 @@ static void pci_host_config_write(void *opaque, target_phys_addr_t addr, PCI_DPRINTF("%s addr " TARGET_FMT_plx " len %d val %"PRIx64"\n", __func__, addr, len, val); + if (addr != 0 || len != 4) { + return; + } s->config_reg = val; } diff --git a/hw/pcnet.c b/hw/pcnet.c index c53f06ef3b..d769b08b78 100644 --- a/hw/pcnet.c +++ b/hw/pcnet.c @@ -77,6 +77,7 @@ struct qemu_ether_header { #define CSR_DTX(S) !!(((S)->csr[15])&0x0002) #define CSR_LOOP(S) !!(((S)->csr[15])&0x0004) #define CSR_DXMTFCS(S) !!(((S)->csr[15])&0x0008) +#define CSR_INTL(S) !!(((S)->csr[15])&0x0040) #define CSR_DRCVPA(S) !!(((S)->csr[15])&0x2000) #define CSR_DRCVBC(S) !!(((S)->csr[15])&0x4000) #define CSR_PROM(S) !!(((S)->csr[15])&0x8000) @@ -884,7 +885,7 @@ static void pcnet_stop(PCNetState *s) #ifdef PCNET_DEBUG printf("pcnet_stop\n"); #endif - s->csr[0] &= ~0x7feb; + s->csr[0] &= ~0xffeb; s->csr[0] |= 0x0014; s->csr[4] &= ~0x02c2; s->csr[5] &= ~0x0011; @@ -1234,6 +1235,15 @@ static void pcnet_transmit(PCNetState *s) if (BCR_SWSTYLE(s) != 1) add_crc = GET_FIELD(tmd.status, TMDS, ADDFCS); } + if (s->lnkst == 0 && + (!CSR_LOOP(s) || (!CSR_INTL(s) && !BCR_TMAULOOP(s)))) { + SET_FIELD(&tmd.misc, TMDM, LCAR, 1); + SET_FIELD(&tmd.status, TMDS, ERR, 1); + SET_FIELD(&tmd.status, TMDS, OWN, 0); + s->csr[0] |= 0xa000; /* ERR | CERR */ + s->xmit_pos = -1; + goto txdone; + } if (!GET_FIELD(tmd.status, TMDS, ENP)) { int bcnt = 4096 - GET_FIELD(tmd.length, TMDL, BCNT); s->phys_mem_read(s->dma_opaque, PHYSADDR(s, tmd.tbadr), @@ -1262,6 +1272,7 @@ static void pcnet_transmit(PCNetState *s) s->xmit_pos = -1; } + txdone: SET_FIELD(&tmd.status, TMDS, OWN, 0); TMDSTORE(&tmd, PHYSADDR(s,CSR_CXDA(s))); if (!CSR_TOKINTD(s) || (CSR_LTINTEN(s) && GET_FIELD(tmd.status, TMDS, LTINT))) diff --git a/hw/pcnet.h b/hw/pcnet.h index edc81c90ac..803a2cc1ec 100644 --- a/hw/pcnet.h +++ b/hw/pcnet.h @@ -20,6 +20,7 @@ #define BCR_SWS 20 #define BCR_PLAT 22 +#define BCR_TMAULOOP(S) !!((S)->bcr[BCR_MC ] & 0x4000) #define BCR_APROMWE(S) !!((S)->bcr[BCR_MC ] & 0x0100) #define BCR_DWIO(S) !!((S)->bcr[BCR_BSBC] & 0x0080) #define BCR_SSIZE32(S) !!((S)->bcr[BCR_SWS ] & 0x0100) diff --git a/hw/piix_pci.c b/hw/piix_pci.c index 179d9a6bb9..09e84f59b6 100644 --- a/hw/piix_pci.c +++ b/hw/piix_pci.c @@ -349,7 +349,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn, b = i440fx_common_init("i440FX", pi440fx_state, piix3_devfn, isa_bus, pic, address_space_mem, address_space_io, ram_size, pci_hole_start, pci_hole_size, - pci_hole64_size, pci_hole64_size, + pci_hole64_start, pci_hole64_size, pci_memory, ram_memory); return b; } diff --git a/hw/qxl-render.c b/hw/qxl-render.c index 28ab182226..f7f1bfda04 100644 --- a/hw/qxl-render.c +++ b/hw/qxl-render.c @@ -127,6 +127,7 @@ static void qxl_render_update_area_unlocked(PCIQXLDevice *qxl) qxl->guest_primary.surface.width, qxl->guest_primary.surface.height); } + dpy_resize(vga->ds); } for (i = 0; i < qxl->num_dirty_rects; i++) { if (qemu_spice_rect_is_empty(qxl->dirty+i)) { @@ -1959,8 +1959,8 @@ static Property qxl_properties[] = { DEFINE_PROP_UINT32("guestdebug", PCIQXLDevice, guestdebug, 0), DEFINE_PROP_UINT32("cmdlog", PCIQXLDevice, cmdlog, 0), DEFINE_PROP_UINT32("ram_size_mb", PCIQXLDevice, ram_size_mb, -1), - DEFINE_PROP_UINT32("vram_size_mb", PCIQXLDevice, vram32_size_mb, 0), - DEFINE_PROP_UINT32("vram64_size_mb", PCIQXLDevice, vram_size_mb, 0), + DEFINE_PROP_UINT32("vram_size_mb", PCIQXLDevice, vram32_size_mb, -1), + DEFINE_PROP_UINT32("vram64_size_mb", PCIQXLDevice, vram_size_mb, -1), DEFINE_PROP_END_OF_LIST(), }; @@ -182,12 +182,17 @@ struct USBEndpoint { QTAILQ_HEAD(, USBPacket) queue; }; +enum USBDeviceFlags { + USB_DEV_FLAG_FULL_PATH, +}; + /* definition of a USB device */ struct USBDevice { DeviceState qdev; USBPort *port; char *port_path; void *opaque; + uint32_t flags; /* Actual connected speed */ int speed; diff --git a/hw/usb/bus.c b/hw/usb/bus.c index d3f835895d..2068640a58 100644 --- a/hw/usb/bus.c +++ b/hw/usb/bus.c @@ -19,6 +19,8 @@ static struct BusInfo usb_bus_info = { .get_fw_dev_path = usb_get_fw_dev_path, .props = (Property[]) { DEFINE_PROP_STRING("port", USBDevice, port_path), + DEFINE_PROP_BIT("full-path", USBDevice, flags, + USB_DEV_FLAG_FULL_PATH, true), DEFINE_PROP_END_OF_LIST() }, }; @@ -460,7 +462,20 @@ static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent) static char *usb_get_dev_path(DeviceState *qdev) { USBDevice *dev = USB_DEVICE(qdev); - return g_strdup(dev->port->path); + DeviceState *hcd = qdev->parent_bus->parent; + char *id = NULL; + + if ((dev->flags & (1 << USB_DEV_FLAG_FULL_PATH)) && + hcd && hcd->parent_bus && hcd->parent_bus->info->get_dev_path) { + id = hcd->parent_bus->info->get_dev_path(hcd); + } + if (id) { + char *ret = g_strdup_printf("%s/%s", id, dev->port->path); + g_free(id); + return ret; + } else { + return g_strdup(dev->port->path); + } } static char *usb_get_fw_dev_path(DeviceState *qdev) diff --git a/hw/usb/core.c b/hw/usb/core.c index a4048fe3e0..9a14a53852 100644 --- a/hw/usb/core.c +++ b/hw/usb/core.c @@ -484,12 +484,17 @@ void usb_packet_check_state(USBPacket *p, USBPacketState expected) void usb_packet_set_state(USBPacket *p, USBPacketState state) { - USBDevice *dev = p->ep->dev; - USBBus *bus = usb_bus_from_device(dev); - - trace_usb_packet_state_change(bus->busnr, dev->port->path, p->ep->nr, p, - usb_packet_state_name(p->state), - usb_packet_state_name(state)); + if (p->ep) { + USBDevice *dev = p->ep->dev; + USBBus *bus = usb_bus_from_device(dev); + trace_usb_packet_state_change(bus->busnr, dev->port->path, p->ep->nr, p, + usb_packet_state_name(p->state), + usb_packet_state_name(state)); + } else { + trace_usb_packet_state_change(-1, "", -1, p, + usb_packet_state_name(p->state), + usb_packet_state_name(state)); + } p->state = state; } diff --git a/hw/usb/desc.c b/hw/usb/desc.c index 9847a75b83..3c77368cb0 100644 --- a/hw/usb/desc.c +++ b/hw/usb/desc.c @@ -18,32 +18,33 @@ int usb_desc_device(const USBDescID *id, const USBDescDevice *dev, uint8_t *dest, size_t len) { uint8_t bLength = 0x12; + USBDescriptor *d = (void *)dest; if (len < bLength) { return -1; } - dest[0x00] = bLength; - dest[0x01] = USB_DT_DEVICE; - - dest[0x02] = usb_lo(dev->bcdUSB); - dest[0x03] = usb_hi(dev->bcdUSB); - dest[0x04] = dev->bDeviceClass; - dest[0x05] = dev->bDeviceSubClass; - dest[0x06] = dev->bDeviceProtocol; - dest[0x07] = dev->bMaxPacketSize0; - - dest[0x08] = usb_lo(id->idVendor); - dest[0x09] = usb_hi(id->idVendor); - dest[0x0a] = usb_lo(id->idProduct); - dest[0x0b] = usb_hi(id->idProduct); - dest[0x0c] = usb_lo(id->bcdDevice); - dest[0x0d] = usb_hi(id->bcdDevice); - dest[0x0e] = id->iManufacturer; - dest[0x0f] = id->iProduct; - dest[0x10] = id->iSerialNumber; - - dest[0x11] = dev->bNumConfigurations; + d->bLength = bLength; + d->bDescriptorType = USB_DT_DEVICE; + + d->u.device.bcdUSB_lo = usb_lo(dev->bcdUSB); + d->u.device.bcdUSB_hi = usb_hi(dev->bcdUSB); + d->u.device.bDeviceClass = dev->bDeviceClass; + d->u.device.bDeviceSubClass = dev->bDeviceSubClass; + d->u.device.bDeviceProtocol = dev->bDeviceProtocol; + d->u.device.bMaxPacketSize0 = dev->bMaxPacketSize0; + + d->u.device.idVendor_lo = usb_lo(id->idVendor); + d->u.device.idVendor_hi = usb_hi(id->idVendor); + d->u.device.idProduct_lo = usb_lo(id->idProduct); + d->u.device.idProduct_hi = usb_hi(id->idProduct); + d->u.device.bcdDevice_lo = usb_lo(id->bcdDevice); + d->u.device.bcdDevice_hi = usb_hi(id->bcdDevice); + d->u.device.iManufacturer = id->iManufacturer; + d->u.device.iProduct = id->iProduct; + d->u.device.iSerialNumber = id->iSerialNumber; + + d->u.device.bNumConfigurations = dev->bNumConfigurations; return bLength; } @@ -52,22 +53,23 @@ int usb_desc_device_qualifier(const USBDescDevice *dev, uint8_t *dest, size_t len) { uint8_t bLength = 0x0a; + USBDescriptor *d = (void *)dest; if (len < bLength) { return -1; } - dest[0x00] = bLength; - dest[0x01] = USB_DT_DEVICE_QUALIFIER; + d->bLength = bLength; + d->bDescriptorType = USB_DT_DEVICE_QUALIFIER; - dest[0x02] = usb_lo(dev->bcdUSB); - dest[0x03] = usb_hi(dev->bcdUSB); - dest[0x04] = dev->bDeviceClass; - dest[0x05] = dev->bDeviceSubClass; - dest[0x06] = dev->bDeviceProtocol; - dest[0x07] = dev->bMaxPacketSize0; - dest[0x08] = dev->bNumConfigurations; - dest[0x09] = 0; /* reserved */ + d->u.device_qualifier.bcdUSB_lo = usb_lo(dev->bcdUSB); + d->u.device_qualifier.bcdUSB_hi = usb_hi(dev->bcdUSB); + d->u.device_qualifier.bDeviceClass = dev->bDeviceClass; + d->u.device_qualifier.bDeviceSubClass = dev->bDeviceSubClass; + d->u.device_qualifier.bDeviceProtocol = dev->bDeviceProtocol; + d->u.device_qualifier.bMaxPacketSize0 = dev->bMaxPacketSize0; + d->u.device_qualifier.bNumConfigurations = dev->bNumConfigurations; + d->u.device_qualifier.bReserved = 0; return bLength; } @@ -76,22 +78,24 @@ int usb_desc_config(const USBDescConfig *conf, uint8_t *dest, size_t len) { uint8_t bLength = 0x09; uint16_t wTotalLength = 0; + USBDescriptor *d = (void *)dest; int i, rc; if (len < bLength) { return -1; } - dest[0x00] = bLength; - dest[0x01] = USB_DT_CONFIG; - dest[0x04] = conf->bNumInterfaces; - dest[0x05] = conf->bConfigurationValue; - dest[0x06] = conf->iConfiguration; - dest[0x07] = conf->bmAttributes; - dest[0x08] = conf->bMaxPower; + d->bLength = bLength; + d->bDescriptorType = USB_DT_CONFIG; + + d->u.config.bNumInterfaces = conf->bNumInterfaces; + d->u.config.bConfigurationValue = conf->bConfigurationValue; + d->u.config.iConfiguration = conf->iConfiguration; + d->u.config.bmAttributes = conf->bmAttributes; + d->u.config.bMaxPower = conf->bMaxPower; wTotalLength += bLength; - /* handle grouped interfaces if any*/ + /* handle grouped interfaces if any */ for (i = 0; i < conf->nif_groups; i++) { rc = usb_desc_iface_group(&(conf->if_groups[i]), dest + wTotalLength, @@ -111,8 +115,8 @@ int usb_desc_config(const USBDescConfig *conf, uint8_t *dest, size_t len) wTotalLength += rc; } - dest[0x02] = usb_lo(wTotalLength); - dest[0x03] = usb_hi(wTotalLength); + d->u.config.wTotalLength_lo = usb_lo(wTotalLength); + d->u.config.wTotalLength_hi = usb_hi(wTotalLength); return wTotalLength; } @@ -155,20 +159,22 @@ int usb_desc_iface(const USBDescIface *iface, uint8_t *dest, size_t len) { uint8_t bLength = 0x09; int i, rc, pos = 0; + USBDescriptor *d = (void *)dest; if (len < bLength) { return -1; } - dest[0x00] = bLength; - dest[0x01] = USB_DT_INTERFACE; - dest[0x02] = iface->bInterfaceNumber; - dest[0x03] = iface->bAlternateSetting; - dest[0x04] = iface->bNumEndpoints; - dest[0x05] = iface->bInterfaceClass; - dest[0x06] = iface->bInterfaceSubClass; - dest[0x07] = iface->bInterfaceProtocol; - dest[0x08] = iface->iInterface; + d->bLength = bLength; + d->bDescriptorType = USB_DT_INTERFACE; + + d->u.interface.bInterfaceNumber = iface->bInterfaceNumber; + d->u.interface.bAlternateSetting = iface->bAlternateSetting; + d->u.interface.bNumEndpoints = iface->bNumEndpoints; + d->u.interface.bInterfaceClass = iface->bInterfaceClass; + d->u.interface.bInterfaceSubClass = iface->bInterfaceSubClass; + d->u.interface.bInterfaceProtocol = iface->bInterfaceProtocol; + d->u.interface.iInterface = iface->iInterface; pos += bLength; for (i = 0; i < iface->ndesc; i++) { @@ -194,21 +200,23 @@ int usb_desc_endpoint(const USBDescEndpoint *ep, uint8_t *dest, size_t len) { uint8_t bLength = ep->is_audio ? 0x09 : 0x07; uint8_t extralen = ep->extra ? ep->extra[0] : 0; + USBDescriptor *d = (void *)dest; if (len < bLength + extralen) { return -1; } - dest[0x00] = bLength; - dest[0x01] = USB_DT_ENDPOINT; - dest[0x02] = ep->bEndpointAddress; - dest[0x03] = ep->bmAttributes; - dest[0x04] = usb_lo(ep->wMaxPacketSize); - dest[0x05] = usb_hi(ep->wMaxPacketSize); - dest[0x06] = ep->bInterval; + d->bLength = bLength; + d->bDescriptorType = USB_DT_ENDPOINT; + + d->u.endpoint.bEndpointAddress = ep->bEndpointAddress; + d->u.endpoint.bmAttributes = ep->bmAttributes; + d->u.endpoint.wMaxPacketSize_lo = usb_lo(ep->wMaxPacketSize); + d->u.endpoint.wMaxPacketSize_hi = usb_hi(ep->wMaxPacketSize); + d->u.endpoint.bInterval = ep->bInterval; if (ep->is_audio) { - dest[0x07] = ep->bRefresh; - dest[0x08] = ep->bSynchAddress; + d->u.endpoint.bRefresh = ep->bRefresh; + d->u.endpoint.bSynchAddress = ep->bSynchAddress; } if (ep->extra) { memcpy(dest + bLength, ep->extra, extralen); diff --git a/hw/usb/desc.h b/hw/usb/desc.h index d6e07ea5d2..d164e8f891 100644 --- a/hw/usb/desc.h +++ b/hw/usb/desc.h @@ -3,6 +3,69 @@ #include <inttypes.h> +/* binary representation */ +typedef struct USBDescriptor { + uint8_t bLength; + uint8_t bDescriptorType; + union { + struct { + uint8_t bcdUSB_lo; + uint8_t bcdUSB_hi; + uint8_t bDeviceClass; + uint8_t bDeviceSubClass; + uint8_t bDeviceProtocol; + uint8_t bMaxPacketSize0; + uint8_t idVendor_lo; + uint8_t idVendor_hi; + uint8_t idProduct_lo; + uint8_t idProduct_hi; + uint8_t bcdDevice_lo; + uint8_t bcdDevice_hi; + uint8_t iManufacturer; + uint8_t iProduct; + uint8_t iSerialNumber; + uint8_t bNumConfigurations; + } device; + struct { + uint8_t bcdUSB_lo; + uint8_t bcdUSB_hi; + uint8_t bDeviceClass; + uint8_t bDeviceSubClass; + uint8_t bDeviceProtocol; + uint8_t bMaxPacketSize0; + uint8_t bNumConfigurations; + uint8_t bReserved; + } device_qualifier; + struct { + uint8_t wTotalLength_lo; + uint8_t wTotalLength_hi; + uint8_t bNumInterfaces; + uint8_t bConfigurationValue; + uint8_t iConfiguration; + uint8_t bmAttributes; + uint8_t bMaxPower; + } config; + struct { + uint8_t bInterfaceNumber; + uint8_t bAlternateSetting; + uint8_t bNumEndpoints; + uint8_t bInterfaceClass; + uint8_t bInterfaceSubClass; + uint8_t bInterfaceProtocol; + uint8_t iInterface; + } interface; + struct { + uint8_t bEndpointAddress; + uint8_t bmAttributes; + uint8_t wMaxPacketSize_lo; + uint8_t wMaxPacketSize_hi; + uint8_t bInterval; + uint8_t bRefresh; /* only audio ep */ + uint8_t bSynchAddress; /* only audio ep */ + } endpoint; + } u; +} QEMU_PACKED USBDescriptor; + struct USBDescID { uint16_t idVendor; uint16_t idProduct; diff --git a/hw/usb/dev-hub.c b/hw/usb/dev-hub.c index eb4e711207..9c9166551e 100644 --- a/hw/usb/dev-hub.c +++ b/hw/usb/dev-hub.c @@ -22,11 +22,10 @@ * THE SOFTWARE. */ #include "qemu-common.h" +#include "trace.h" #include "hw/usb.h" #include "hw/usb/desc.h" -//#define DEBUG - #define NUM_PORTS 8 typedef struct USBHubPort { @@ -157,6 +156,7 @@ static void usb_hub_attach(USBPort *port1) USBHubState *s = port1->opaque; USBHubPort *port = &s->ports[port1->index]; + trace_usb_hub_attach(s->dev.addr, port1->index + 1); port->wPortStatus |= PORT_STAT_CONNECTION; port->wPortChange |= PORT_STAT_C_CONNECTION; if (port->port.dev->speed == USB_SPEED_LOW) { @@ -172,6 +172,7 @@ static void usb_hub_detach(USBPort *port1) USBHubState *s = port1->opaque; USBHubPort *port = &s->ports[port1->index]; + trace_usb_hub_detach(s->dev.addr, port1->index + 1); usb_wakeup(s->intr); /* Let upstream know the device on this port is gone */ @@ -247,6 +248,7 @@ static void usb_hub_handle_reset(USBDevice *dev) USBHubPort *port; int i; + trace_usb_hub_reset(s->dev.addr); for (i = 0; i < NUM_PORTS; i++) { port = s->ports + i; port->wPortStatus = PORT_STAT_POWER; @@ -261,12 +263,39 @@ static void usb_hub_handle_reset(USBDevice *dev) } } +static const char *feature_name(int feature) +{ + static const char *name[] = { + [PORT_CONNECTION] = "connection", + [PORT_ENABLE] = "enable", + [PORT_SUSPEND] = "suspend", + [PORT_OVERCURRENT] = "overcurrent", + [PORT_RESET] = "reset", + [PORT_POWER] = "power", + [PORT_LOWSPEED] = "lowspeed", + [PORT_HIGHSPEED] = "highspeed", + [PORT_C_CONNECTION] = "change connection", + [PORT_C_ENABLE] = "change enable", + [PORT_C_SUSPEND] = "change suspend", + [PORT_C_OVERCURRENT] = "change overcurrent", + [PORT_C_RESET] = "change reset", + [PORT_TEST] = "test", + [PORT_INDICATOR] = "indicator", + }; + if (feature < 0 || feature >= ARRAY_SIZE(name)) { + return "?"; + } + return name[feature] ?: "?"; +} + static int usb_hub_handle_control(USBDevice *dev, USBPacket *p, int request, int value, int index, int length, uint8_t *data) { USBHubState *s = (USBHubState *)dev; int ret; + trace_usb_hub_control(s->dev.addr, request, value, index, length); + ret = usb_desc_handle_control(dev, p, request, value, index, length, data); if (ret >= 0) { return ret; @@ -295,6 +324,9 @@ static int usb_hub_handle_control(USBDevice *dev, USBPacket *p, goto fail; } port = &s->ports[n]; + trace_usb_hub_get_port_status(s->dev.addr, index, + port->wPortStatus, + port->wPortChange); data[0] = port->wPortStatus; data[1] = port->wPortStatus >> 8; data[2] = port->wPortChange; @@ -315,6 +347,10 @@ static int usb_hub_handle_control(USBDevice *dev, USBPacket *p, unsigned int n = index - 1; USBHubPort *port; USBDevice *dev; + + trace_usb_hub_set_port_feature(s->dev.addr, index, + feature_name(value)); + if (n >= NUM_PORTS) { goto fail; } @@ -345,6 +381,9 @@ static int usb_hub_handle_control(USBDevice *dev, USBPacket *p, unsigned int n = index - 1; USBHubPort *port; + trace_usb_hub_clear_port_feature(s->dev.addr, index, + feature_name(value)); + if (n >= NUM_PORTS) { goto fail; } diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c index 60f9f5bdb5..23631a47c9 100644 --- a/hw/usb/hcd-ehci.c +++ b/hw/usb/hcd-ehci.c @@ -403,7 +403,6 @@ struct EHCIState { /* * Internal states, shadow registers, etc */ - uint32_t sofv; QEMUTimer *frame_timer; int attach_poll_counter; int astate; // Current state in asynchronous schedule @@ -797,7 +796,6 @@ static void ehci_child_detach(USBPort *port, USBDevice *child) if (portsc & PORTSC_POWNER) { USBPort *companion = s->companion_ports[port->index]; companion->ops->child_detach(companion, child); - companion->dev = NULL; return; } @@ -1103,10 +1101,6 @@ static void ehci_mem_writel(void *ptr, target_phys_addr_t addr, uint32_t val) val &= USBINTR_MASK; break; - case FRINDEX: - s->sofv = val >> 3; - break; - case CONFIGFLAG: val &= 0x1; if (val) { @@ -2015,7 +2009,6 @@ static void ehci_advance_state(EHCIState *ehci, fprintf(stderr, "processing error - resetting ehci HC\n"); ehci_reset(ehci); again = 0; - assert(0); } } while (again); @@ -2150,13 +2143,14 @@ static void ehci_frame_timer(void *opaque) if ( !(ehci->usbsts & USBSTS_HALT)) { ehci->frindex += 8; - if (ehci->frindex > 0x00001fff) { - ehci->frindex = 0; + if (ehci->frindex == 0x00002000) { ehci_set_interrupt(ehci, USBSTS_FLR); } - ehci->sofv = (ehci->frindex - 1) >> 3; - ehci->sofv &= 0x000003ff; + if (ehci->frindex == 0x00004000) { + ehci_set_interrupt(ehci, USBSTS_FLR); + ehci->frindex = 0; + } } if (frames - i > ehci->maxframes) { diff --git a/hw/usb/hcd-uhci.c b/hw/usb/hcd-uhci.c index e55dad914c..266d550b9c 100644 --- a/hw/usb/hcd-uhci.c +++ b/hw/usb/hcd-uhci.c @@ -795,7 +795,8 @@ out: return TD_RESULT_NEXT_QH; } -static int uhci_handle_td(UHCIState *s, uint32_t addr, UHCI_TD *td, uint32_t *int_mask) +static int uhci_handle_td(UHCIState *s, uint32_t addr, UHCI_TD *td, + uint32_t *int_mask, bool queuing) { UHCIAsync *async; int len = 0, max_len; @@ -814,6 +815,12 @@ static int uhci_handle_td(UHCIState *s, uint32_t addr, UHCI_TD *td, uint32_t *in if (!async->done) return TD_RESULT_ASYNC_CONT; + if (queuing) { + /* we are busy filling the queue, we are not prepared + to consume completed packages then, just leave them + in async state */ + return TD_RESULT_ASYNC_CONT; + } uhci_async_unlink(async); goto done; @@ -964,7 +971,10 @@ static void uhci_fill_queue(UHCIState *s, UHCI_TD *td) break; } trace_usb_uhci_td_queue(plink & ~0xf, ptd.ctrl, ptd.token); - ret = uhci_handle_td(s, plink, &ptd, &int_mask); + ret = uhci_handle_td(s, plink, &ptd, &int_mask, true); + if (ret == TD_RESULT_ASYNC_CONT) { + break; + } assert(ret == TD_RESULT_ASYNC_START); assert(int_mask == 0); plink = ptd.link; @@ -1045,7 +1055,7 @@ static void uhci_process_frame(UHCIState *s) trace_usb_uhci_td_load(curr_qh & ~0xf, link & ~0xf, td.ctrl, td.token); old_td_ctrl = td.ctrl; - ret = uhci_handle_td(s, link, &td, &int_mask); + ret = uhci_handle_td(s, link, &td, &int_mask, false); if (old_td_ctrl != td.ctrl) { /* update the status bits of the TD */ val = cpu_to_le32(td.ctrl); diff --git a/hw/usb/host-linux.c b/hw/usb/host-linux.c index 90919c242a..061a1b7825 100644 --- a/hw/usb/host-linux.c +++ b/hw/usb/host-linux.c @@ -42,6 +42,7 @@ #include <linux/usbdevice_fs.h> #include <linux/version.h> #include "hw/usb.h" +#include "hw/usb/desc.h" /* We redefine it to avoid version problems */ struct usb_ctrltransfer { @@ -94,6 +95,10 @@ struct USBAutoFilter { uint32_t product_id; }; +enum USBHostDeviceOptions { + USB_HOST_OPT_PIPELINE, +}; + typedef struct USBHostDevice { USBDevice dev; int fd; @@ -104,6 +109,7 @@ typedef struct USBHostDevice { int descr_len; int closing; uint32_t iso_urb_count; + uint32_t options; Notifier exit; struct endp_data ep_in[USB_MAX_ENDPOINTS]; @@ -115,6 +121,7 @@ typedef struct USBHostDevice { int addr; char port[MAX_PORTLEN]; struct USBAutoFilter match; + int32_t bootindex; int seen, errcount; QTAILQ_ENTRY(USBHostDevice) next; @@ -374,10 +381,10 @@ static void async_complete(void *opaque) } if (aurb->urb.type == USBDEVFS_URB_TYPE_CONTROL) { - trace_usb_host_req_complete(s->bus_num, s->addr, p->result); + trace_usb_host_req_complete(s->bus_num, s->addr, p, p->result); usb_generic_async_ctrl_complete(&s->dev, p); } else if (!aurb->more) { - trace_usb_host_req_complete(s->bus_num, s->addr, p->result); + trace_usb_host_req_complete(s->bus_num, s->addr, p, p->result); usb_packet_complete(&s->dev, p); } } @@ -391,12 +398,14 @@ static void usb_host_async_cancel(USBDevice *dev, USBPacket *p) USBHostDevice *s = DO_UPCAST(USBHostDevice, dev, dev); AsyncURB *aurb; + trace_usb_host_req_canceled(s->bus_num, s->addr, p); + QLIST_FOREACH(aurb, &s->aurbs, next) { if (p != aurb->packet) { continue; } - DPRINTF("husb: async cancel: packet %p, aurb %p\n", p, aurb); + trace_usb_host_urb_canceled(s->bus_num, s->addr, aurb); /* Mark it as dead (see async_complete above) */ aurb->packet = NULL; @@ -844,12 +853,12 @@ static int usb_host_handle_data(USBDevice *dev, USBPacket *p) uint8_t *pbuf; uint8_t ep; - trace_usb_host_req_data(s->bus_num, s->addr, + trace_usb_host_req_data(s->bus_num, s->addr, p, p->pid == USB_TOKEN_IN, p->ep->nr, p->iov.size); if (!is_valid(s, p->pid, p->ep->nr)) { - trace_usb_host_req_complete(s->bus_num, s->addr, USB_RET_NAK); + trace_usb_host_req_complete(s->bus_num, s->addr, p, USB_RET_NAK); return USB_RET_NAK; } @@ -864,7 +873,7 @@ static int usb_host_handle_data(USBDevice *dev, USBPacket *p) ret = ioctl(s->fd, USBDEVFS_CLEAR_HALT, &arg); if (ret < 0) { perror("USBDEVFS_CLEAR_HALT"); - trace_usb_host_req_complete(s->bus_num, s->addr, USB_RET_NAK); + trace_usb_host_req_complete(s->bus_num, s->addr, p, USB_RET_NAK); return USB_RET_NAK; } clear_halt(s, p->pid, p->ep->nr); @@ -919,11 +928,13 @@ static int usb_host_handle_data(USBDevice *dev, USBPacket *p) switch(errno) { case ETIMEDOUT: - trace_usb_host_req_complete(s->bus_num, s->addr, USB_RET_NAK); + trace_usb_host_req_complete(s->bus_num, s->addr, p, + USB_RET_NAK); return USB_RET_NAK; case EPIPE: default: - trace_usb_host_req_complete(s->bus_num, s->addr, USB_RET_STALL); + trace_usb_host_req_complete(s->bus_num, s->addr, p, + USB_RET_STALL); return USB_RET_STALL; } } @@ -1030,17 +1041,23 @@ static int usb_host_handle_control(USBDevice *dev, USBPacket *p, */ /* Note request is (bRequestType << 8) | bRequest */ - trace_usb_host_req_control(s->bus_num, s->addr, request, value, index); + trace_usb_host_req_control(s->bus_num, s->addr, p, request, value, index); switch (request) { case DeviceOutRequest | USB_REQ_SET_ADDRESS: - return usb_host_set_address(s, value); + ret = usb_host_set_address(s, value); + trace_usb_host_req_emulated(s->bus_num, s->addr, p, ret); + return ret; case DeviceOutRequest | USB_REQ_SET_CONFIGURATION: - return usb_host_set_config(s, value & 0xff); + ret = usb_host_set_config(s, value & 0xff); + trace_usb_host_req_emulated(s->bus_num, s->addr, p, ret); + return ret; case InterfaceOutRequest | USB_REQ_SET_INTERFACE: - return usb_host_set_interface(s, index, value); + ret = usb_host_set_interface(s, index, value); + trace_usb_host_req_emulated(s->bus_num, s->addr, p, ret); + return ret; } /* The rest are asynchronous */ @@ -1092,120 +1109,128 @@ static int usb_host_handle_control(USBDevice *dev, USBPacket *p, return USB_RET_ASYNC; } -static uint8_t usb_linux_get_alt_setting(USBHostDevice *s, - uint8_t configuration, uint8_t interface) -{ - char device_name[64], line[1024]; - int alt_setting; - - sprintf(device_name, "%d-%s:%d.%d", s->bus_num, s->port, - (int)configuration, (int)interface); - - if (!usb_host_read_file(line, sizeof(line), "bAlternateSetting", - device_name)) { - /* Assume alt 0 on error */ - return 0; - } - if (sscanf(line, "%d", &alt_setting) != 1) { - /* Assume alt 0 on error */ - return 0; - } - return alt_setting; -} - /* returns 1 on problem encountered or 0 for success */ static int usb_linux_update_endp_table(USBHostDevice *s) { - uint8_t *descriptors; - uint8_t devep, type, alt_interface; - uint16_t raw; - int interface, length, i, ep, pid; + static const char *tname[] = { + [USB_ENDPOINT_XFER_CONTROL] = "control", + [USB_ENDPOINT_XFER_ISOC] = "isoc", + [USB_ENDPOINT_XFER_BULK] = "bulk", + [USB_ENDPOINT_XFER_INT] = "int", + }; + uint8_t devep, type; + uint16_t mps, v, p; + int ep, pid; + unsigned int i, configuration = -1, interface = -1, altsetting = -1; struct endp_data *epd; + USBDescriptor *d; + bool active = false; usb_ep_init(&s->dev); - if (s->dev.configuration == 0) { - /* not configured yet -- leave all endpoints disabled */ - return 0; - } - - /* get the desired configuration, interface, and endpoint descriptors - * from device description */ - descriptors = &s->descr[18]; - length = s->descr_len - 18; - i = 0; - - while (i < length) { - if (descriptors[i + 1] != USB_DT_CONFIG) { - fprintf(stderr, "invalid descriptor data\n"); - return 1; - } else if (descriptors[i + 5] != s->dev.configuration) { - DPRINTF("not requested configuration %d\n", s->dev.configuration); - i += (descriptors[i + 3] << 8) + descriptors[i + 2]; - continue; + for (i = 0;; i += d->bLength) { + if (i+2 >= s->descr_len) { + break; } - i += descriptors[i]; - - if (descriptors[i + 1] != USB_DT_INTERFACE || - (descriptors[i + 1] == USB_DT_INTERFACE && - descriptors[i + 4] == 0)) { - i += descriptors[i]; - continue; + d = (void *)(s->descr + i); + if (d->bLength < 2) { + trace_usb_host_parse_error(s->bus_num, s->addr, + "descriptor too short"); + goto error; } - - interface = descriptors[i + 2]; - alt_interface = usb_linux_get_alt_setting(s, s->dev.configuration, - interface); - - /* the current interface descriptor is the active interface - * and has endpoints */ - if (descriptors[i + 3] != alt_interface) { - i += descriptors[i]; - continue; - } - - /* advance to the endpoints */ - while (i < length && descriptors[i +1] != USB_DT_ENDPOINT) { - i += descriptors[i]; + if (i + d->bLength > s->descr_len) { + trace_usb_host_parse_error(s->bus_num, s->addr, + "descriptor too long"); + goto error; } - - if (i >= length) + switch (d->bDescriptorType) { + case 0: + trace_usb_host_parse_error(s->bus_num, s->addr, + "invalid descriptor type"); + goto error; + case USB_DT_DEVICE: + if (d->bLength < 0x12) { + trace_usb_host_parse_error(s->bus_num, s->addr, + "device descriptor too short"); + goto error; + } + v = (d->u.device.idVendor_hi << 8) | d->u.device.idVendor_lo; + p = (d->u.device.idProduct_hi << 8) | d->u.device.idProduct_lo; + trace_usb_host_parse_device(s->bus_num, s->addr, v, p); break; - - while (i < length) { - if (descriptors[i + 1] != USB_DT_ENDPOINT) { - break; + case USB_DT_CONFIG: + if (d->bLength < 0x09) { + trace_usb_host_parse_error(s->bus_num, s->addr, + "config descriptor too short"); + goto error; } - - devep = descriptors[i + 2]; + configuration = d->u.config.bConfigurationValue; + active = (configuration == s->dev.configuration); + trace_usb_host_parse_config(s->bus_num, s->addr, + configuration, active); + break; + case USB_DT_INTERFACE: + if (d->bLength < 0x09) { + trace_usb_host_parse_error(s->bus_num, s->addr, + "interface descriptor too short"); + goto error; + } + interface = d->u.interface.bInterfaceNumber; + altsetting = d->u.interface.bAlternateSetting; + active = (configuration == s->dev.configuration) && + (altsetting == s->dev.altsetting[interface]); + trace_usb_host_parse_interface(s->bus_num, s->addr, + interface, altsetting, active); + break; + case USB_DT_ENDPOINT: + if (d->bLength < 0x07) { + trace_usb_host_parse_error(s->bus_num, s->addr, + "endpoint descriptor too short"); + goto error; + } + devep = d->u.endpoint.bEndpointAddress; pid = (devep & USB_DIR_IN) ? USB_TOKEN_IN : USB_TOKEN_OUT; ep = devep & 0xf; if (ep == 0) { - fprintf(stderr, "usb-linux: invalid ep descriptor, ep == 0\n"); - return 1; + trace_usb_host_parse_error(s->bus_num, s->addr, + "invalid endpoint address"); + goto error; } - type = descriptors[i + 3] & 0x3; - raw = descriptors[i + 4] + (descriptors[i + 5] << 8); - usb_ep_set_max_packet_size(&s->dev, pid, ep, raw); - assert(usb_ep_get_type(&s->dev, pid, ep) == - USB_ENDPOINT_XFER_INVALID); - usb_ep_set_type(&s->dev, pid, ep, type); - usb_ep_set_ifnum(&s->dev, pid, ep, interface); - if (type == USB_ENDPOINT_XFER_BULK) { - usb_ep_set_pipeline(&s->dev, pid, ep, true); - } + type = d->u.endpoint.bmAttributes & 0x3; + mps = d->u.endpoint.wMaxPacketSize_lo | + (d->u.endpoint.wMaxPacketSize_hi << 8); + trace_usb_host_parse_endpoint(s->bus_num, s->addr, ep, + (devep & USB_DIR_IN) ? "in" : "out", + tname[type], active); + + if (active) { + usb_ep_set_max_packet_size(&s->dev, pid, ep, mps); + assert(usb_ep_get_type(&s->dev, pid, ep) == + USB_ENDPOINT_XFER_INVALID); + usb_ep_set_type(&s->dev, pid, ep, type); + usb_ep_set_ifnum(&s->dev, pid, ep, interface); + if ((s->options & (1 << USB_HOST_OPT_PIPELINE)) && + (type == USB_ENDPOINT_XFER_BULK)) { + usb_ep_set_pipeline(&s->dev, pid, ep, true); + } - epd = get_endp(s, pid, ep); - epd->halted = 0; + epd = get_endp(s, pid, ep); + epd->halted = 0; + } - i += descriptors[i]; + break; + default: + trace_usb_host_parse_unknown(s->bus_num, s->addr, + d->bLength, d->bDescriptorType); + break; } } -#ifdef DEBUG - usb_ep_dump(&s->dev); -#endif return 0; + +error: + usb_ep_init(&s->dev); + return 1; } /* @@ -1403,6 +1428,7 @@ static int usb_host_initfn(USBDevice *dev) if (s->match.bus_num != 0 && s->match.port != NULL) { usb_host_claim_port(s); } + add_boot_device_path(s->bootindex, &dev->qdev, NULL); return 0; } @@ -1418,6 +1444,9 @@ static Property usb_host_dev_properties[] = { DEFINE_PROP_HEX32("vendorid", USBHostDevice, match.vendor_id, 0), DEFINE_PROP_HEX32("productid", USBHostDevice, match.product_id, 0), DEFINE_PROP_UINT32("isobufs", USBHostDevice, iso_urb_count, 4), + DEFINE_PROP_INT32("bootindex", USBHostDevice, bootindex, -1), + DEFINE_PROP_BIT("pipeline", USBHostDevice, options, + USB_HOST_OPT_PIPELINE, true), DEFINE_PROP_END_OF_LIST(), }; diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c index 8e9f175dbb..94ab4632ca 100644 --- a/hw/usb/redirect.c +++ b/hw/usb/redirect.c @@ -74,6 +74,7 @@ struct USBRedirDevice { CharDriverState *cs; uint8_t debug; char *filter_str; + int32_t bootindex; /* Data passed from chardev the fd_read cb to the usbredirparser read cb */ const uint8_t *read_buf; int read_buf_size; @@ -835,7 +836,13 @@ static void usbredir_do_attach(void *opaque) { USBRedirDevice *dev = opaque; - usb_device_attach(&dev->dev); + if (usb_device_attach(&dev->dev) != 0) { + usbredir_device_disconnect(dev); + if (usbredirparser_peer_has_cap(dev->parser, usb_redir_cap_filter)) { + usbredirparser_send_filter_reject(dev->parser); + usbredirparser_do_write(dev->parser); + } + } } /* @@ -923,6 +930,7 @@ static int usbredir_initfn(USBDevice *udev) qemu_chr_add_handlers(dev->cs, usbredir_chardev_can_read, usbredir_chardev_read, usbredir_chardev_event, dev); + add_boot_device_path(dev->bootindex, &udev->qdev, NULL); return 0; } @@ -1452,6 +1460,7 @@ static Property usbredir_properties[] = { DEFINE_PROP_CHR("chardev", USBRedirDevice, cs), DEFINE_PROP_UINT8("debug", USBRedirDevice, debug, 0), DEFINE_PROP_STRING("filter", USBRedirDevice, filter_str), + DEFINE_PROP_INT32("bootindex", USBRedirDevice, bootindex, -1), DEFINE_PROP_END_OF_LIST(), }; diff --git a/hw/vhost.c b/hw/vhost.c index 8d3ba5b608..43664e7f4d 100644 --- a/hw/vhost.c +++ b/hw/vhost.c @@ -31,11 +31,12 @@ static void vhost_dev_sync_region(struct vhost_dev *dev, vhost_log_chunk_t *to = dev->log + end / VHOST_LOG_CHUNK + 1; uint64_t addr = (start / VHOST_LOG_CHUNK) * VHOST_LOG_CHUNK; - assert(end / VHOST_LOG_CHUNK < dev->log_size); - assert(start / VHOST_LOG_CHUNK < dev->log_size); if (end < start) { return; } + assert(end / VHOST_LOG_CHUNK < dev->log_size); + assert(start / VHOST_LOG_CHUNK < dev->log_size); + for (;from < to; ++from) { vhost_log_chunk_t log; int bit; @@ -277,8 +278,9 @@ static inline void vhost_dev_log_resize(struct vhost_dev* dev, uint64_t size) r = ioctl(dev->control, VHOST_SET_LOG_BASE, &log_base); assert(r >= 0); for (i = 0; i < dev->n_mem_sections; ++i) { - vhost_sync_dirty_bitmap(dev, &dev->mem_sections[i], - 0, (target_phys_addr_t)~0x0ull); + /* Sync only the range covered by the old log */ + vhost_sync_dirty_bitmap(dev, &dev->mem_sections[i], 0, + dev->log_size * VHOST_LOG_CHUNK - 1); } if (dev->log) { g_free(dev->log); diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index a0fb7c1b9c..4a4413d52c 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -790,6 +790,11 @@ static int virtio_balloon_init_pci(PCIDevice *pci_dev) VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); VirtIODevice *vdev; + if (proxy->class_code != PCI_CLASS_OTHERS && + proxy->class_code != PCI_CLASS_MEMORY_RAM) { /* qemu < 1.1 */ + proxy->class_code = PCI_CLASS_OTHERS; + } + vdev = virtio_balloon_init(&pci_dev->qdev); if (!vdev) { return -1; @@ -906,6 +911,7 @@ static TypeInfo virtio_serial_info = { static Property virtio_balloon_properties[] = { DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features), + DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0), DEFINE_PROP_END_OF_LIST(), }; @@ -919,7 +925,7 @@ static void virtio_balloon_class_init(ObjectClass *klass, void *data) k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; k->device_id = PCI_DEVICE_ID_VIRTIO_BALLOON; k->revision = VIRTIO_PCI_ABI_VERSION; - k->class_id = PCI_CLASS_MEMORY_RAM; + k->class_id = PCI_CLASS_OTHERS; dc->reset = virtio_pci_reset; dc->props = virtio_balloon_properties; } @@ -34,6 +34,7 @@ static inline int xen_enabled(void) int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num); void xen_piix3_set_irq(void *opaque, int irq_num, int level); void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len); +void xen_hvm_inject_msi(uint64_t addr, uint32_t data); void xen_cmos_set_s3_resume(void *opaque, int irq, int level); qemu_irq *xen_interrupt_controller_init(void); diff --git a/hw/xen_apic.c b/hw/xen_apic.c new file mode 100644 index 0000000000..1725ff67dd --- /dev/null +++ b/hw/xen_apic.c @@ -0,0 +1,90 @@ +/* + * Xen basic APIC support + * + * Copyright (c) 2012 Citrix + * + * Authors: + * Wei Liu <wei.liu2@citrix.com> + * + * This work is licensed under the terms of the GNU GPL version 2 or + * later. See the COPYING file in the top-level directory. + */ +#include "hw/apic_internal.h" +#include "hw/msi.h" +#include "xen.h" + +static uint64_t xen_apic_mem_read(void *opaque, target_phys_addr_t addr, + unsigned size) +{ + return ~(uint64_t)0; +} + +static void xen_apic_mem_write(void *opaque, target_phys_addr_t addr, + uint64_t data, unsigned size) +{ + if (size != sizeof(uint32_t)) { + fprintf(stderr, "Xen: APIC write data size = %d, invalid\n", size); + return; + } + + xen_hvm_inject_msi(addr, data); +} + +static const MemoryRegionOps xen_apic_io_ops = { + .read = xen_apic_mem_read, + .write = xen_apic_mem_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static void xen_apic_init(APICCommonState *s) +{ + memory_region_init_io(&s->io_memory, &xen_apic_io_ops, s, "xen-apic-msi", + MSI_SPACE_SIZE); +} + +static void xen_apic_set_base(APICCommonState *s, uint64_t val) +{ +} + +static void xen_apic_set_tpr(APICCommonState *s, uint8_t val) +{ +} + +static uint8_t xen_apic_get_tpr(APICCommonState *s) +{ + return 0; +} + +static void xen_apic_vapic_base_update(APICCommonState *s) +{ +} + +static void xen_apic_external_nmi(APICCommonState *s) +{ +} + +static void xen_apic_class_init(ObjectClass *klass, void *data) +{ + APICCommonClass *k = APIC_COMMON_CLASS(klass); + + k->init = xen_apic_init; + k->set_base = xen_apic_set_base; + k->set_tpr = xen_apic_set_tpr; + k->get_tpr = xen_apic_get_tpr; + k->vapic_base_update = xen_apic_vapic_base_update; + k->external_nmi = xen_apic_external_nmi; +} + +static TypeInfo xen_apic_info = { + .name = "xen-apic", + .parent = TYPE_APIC_COMMON, + .instance_size = sizeof(APICCommonState), + .class_init = xen_apic_class_init, +}; + +static void xen_apic_register_types(void) +{ + type_register_static(&xen_apic_info); +} + +type_init(xen_apic_register_types) diff --git a/hw/xen_backend.c b/hw/xen_backend.c index 2673ace185..66cb144397 100644 --- a/hw/xen_backend.c +++ b/hw/xen_backend.c @@ -592,7 +592,7 @@ static void xenstore_update_be(char *watch, char *type, int dom, struct XenDevOps *ops) { struct XenDevice *xendev; - char path[XEN_BUFSIZE], *dom0; + char path[XEN_BUFSIZE], *dom0, *bepath; unsigned int len, dev; dom0 = xs_get_domain_path(xenstore, 0); @@ -611,15 +611,16 @@ static void xenstore_update_be(char *watch, char *type, int dom, return; } - if (0) { - /* FIXME: detect devices being deleted from xenstore ... */ - xen_be_del_xendev(dom, dev); - } - xendev = xen_be_get_xendev(type, dom, dev, ops); if (xendev != NULL) { - xen_be_backend_changed(xendev, path); - xen_be_check_state(xendev); + bepath = xs_read(xenstore, 0, xendev->be, &len); + if (bepath == NULL) { + xen_be_del_xendev(dom, dev); + } else { + free(bepath); + xen_be_backend_changed(xendev, path); + xen_be_check_state(xendev); + } } } diff --git a/hw/xen_disk.c b/hw/xen_disk.c index 9719395b09..22dbd10303 100644 --- a/hw/xen_disk.c +++ b/hw/xen_disk.c @@ -745,6 +745,10 @@ static int blk_free(struct XenDevice *xendev) struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev); struct ioreq *ioreq; + if (blkdev->bs || blkdev->sring) { + blk_disconnect(xendev); + } + while (!QLIST_EMPTY(&blkdev->freelist)) { ioreq = QLIST_FIRST(&blkdev->freelist); QLIST_REMOVE(ioreq, list); |