Re: [Qemu-devel] RFC: Add a new boot parameter to set delay time before seabios retry to boot

2012-09-06 Thread Gleb Natapov
On Thu, Sep 06, 2012 at 12:15:13PM +0800, Amos Kong wrote:
 Hi all,
 
 Seabios supports automatically reboot after X second delay on failed
 boot [1],
 I want to add a parameter for qemu, it's used put a boot parameter
 into romfile
 for seabios to set the delay time.
 
 # qemu ... -boot order=n,menu=on,delay=5 ...
 
 
 Comments  suggestions ? Thanks!
 
It is not cleat what delay mean. May be call it reboot-timeout.

 
 [1] commit b8fcf46826e77c835da0ad8127a17895bb2e2fca
 Author: Kevin O'Connor ke...@koconnor.net
 Date:   Sat May 12 22:12:22 2012 -0400
 
 Automatically reboot after 60 second delay on failed boot.
 
 If no valid boot devices are found, display the error for 60 seconds
 (by default) and then reboot.  This enables a periodic retry in case
 one of the boot devices is still coming online.
 
 Signed-off-by: Kevin O'Connor ke...@koconnor.net
 
 
 
 -- 
   Amos.

--
Gleb.



Re: [Qemu-devel] [PATCH 0/5 v3] convert system_powerdown command to notifiers

2012-09-06 Thread Paolo Bonzini
Il 05/09/2012 23:06, Igor Mammedov ha scritto:
 global variable qemu_system_powerdown in sysemu.h is the only dep for qemu_irq
 and qemu_rise_irq is not a generic way to signal guest that it should 
 shutdown.
 
 replace it by notifiers and allow each implementation to have it's own way
 to notify guest.
 
 git repo for testing:
 https://github.com/imammedo/qemu/tree/shutdown_notifier.v3
 
 compile tested:
target-list=x86_64-linux-user,x86_64-softmmu,sparc-softmmu,arm-softmmu
 runtime tested:
x86_64-softmmu + win7 guest
 
 v3-v2:
 - fixed bisectably issues of series
 - make series independed of cpu_as_device series
  
 Igor Mammedov (5):
   Introduce powerdown_notifiers
   acpi: use notifier for signaling guest system_powerdown command
   target-arm: use notifier for signaling guest system_powerdown command
   target-sparc: use notifier for signaling guest system_powerdown
 command
   Cleanup unused global var qemu_system_powerdown
 
  hw/acpi_piix4.c |  8 +---
  hw/nseries.c| 14 +-
  hw/sun4m.c  | 14 +-
  sysemu.h|  2 +-
  vl.c| 18 ++
  5 files changed, 46 insertions(+), 10 deletions(-)
 

Series

Reviewed-by: Paolo Bonzini pbozn...@redhat.com

Paolo



[Qemu-devel] [PATCH 36/54] xhci: trace cc codes in cleartext

2012-09-06 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-xhci.c |   48 +++-
 trace-events  |2 +-
 2 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 3c61bb8..ab32a7b 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -465,6 +465,45 @@ static const char *TRBType_names[] = {
 [CR_VENDOR_NEC_CHALLENGE_RESPONSE] = CR_VENDOR_NEC_CHALLENGE_RESPONSE,
 };
 
+static const char *TRBCCode_names[] = {
+[CC_INVALID]   = CC_INVALID,
+[CC_SUCCESS]   = CC_SUCCESS,
+[CC_DATA_BUFFER_ERROR] = CC_DATA_BUFFER_ERROR,
+[CC_BABBLE_DETECTED]   = CC_BABBLE_DETECTED,
+[CC_USB_TRANSACTION_ERROR] = CC_USB_TRANSACTION_ERROR,
+[CC_TRB_ERROR] = CC_TRB_ERROR,
+[CC_STALL_ERROR]   = CC_STALL_ERROR,
+[CC_RESOURCE_ERROR]= CC_RESOURCE_ERROR,
+[CC_BANDWIDTH_ERROR]   = CC_BANDWIDTH_ERROR,
+[CC_NO_SLOTS_ERROR]= CC_NO_SLOTS_ERROR,
+[CC_INVALID_STREAM_TYPE_ERROR] = CC_INVALID_STREAM_TYPE_ERROR,
+[CC_SLOT_NOT_ENABLED_ERROR]= CC_SLOT_NOT_ENABLED_ERROR,
+[CC_EP_NOT_ENABLED_ERROR]  = CC_EP_NOT_ENABLED_ERROR,
+[CC_SHORT_PACKET]  = CC_SHORT_PACKET,
+[CC_RING_UNDERRUN] = CC_RING_UNDERRUN,
+[CC_RING_OVERRUN]  = CC_RING_OVERRUN,
+[CC_VF_ER_FULL]= CC_VF_ER_FULL,
+[CC_PARAMETER_ERROR]   = CC_PARAMETER_ERROR,
+[CC_BANDWIDTH_OVERRUN] = CC_BANDWIDTH_OVERRUN,
+[CC_CONTEXT_STATE_ERROR]   = CC_CONTEXT_STATE_ERROR,
+[CC_NO_PING_RESPONSE_ERROR]= CC_NO_PING_RESPONSE_ERROR,
+[CC_EVENT_RING_FULL_ERROR] = CC_EVENT_RING_FULL_ERROR,
+[CC_INCOMPATIBLE_DEVICE_ERROR] = CC_INCOMPATIBLE_DEVICE_ERROR,
+[CC_MISSED_SERVICE_ERROR]  = CC_MISSED_SERVICE_ERROR,
+[CC_COMMAND_RING_STOPPED]  = CC_COMMAND_RING_STOPPED,
+[CC_COMMAND_ABORTED]   = CC_COMMAND_ABORTED,
+[CC_STOPPED]   = CC_STOPPED,
+[CC_STOPPED_LENGTH_INVALID]= CC_STOPPED_LENGTH_INVALID,
+[CC_MAX_EXIT_LATENCY_TOO_LARGE_ERROR]
+= CC_MAX_EXIT_LATENCY_TOO_LARGE_ERROR,
+[CC_ISOCH_BUFFER_OVERRUN]  = CC_ISOCH_BUFFER_OVERRUN,
+[CC_EVENT_LOST_ERROR]  = CC_EVENT_LOST_ERROR,
+[CC_UNDEFINED_ERROR]   = CC_UNDEFINED_ERROR,
+[CC_INVALID_STREAM_ID_ERROR]   = CC_INVALID_STREAM_ID_ERROR,
+[CC_SECONDARY_BANDWIDTH_ERROR] = CC_SECONDARY_BANDWIDTH_ERROR,
+[CC_SPLIT_TRANSACTION_ERROR]   = CC_SPLIT_TRANSACTION_ERROR,
+};
+
 static const char *lookup_name(uint32_t index, const char **list, uint32_t 
llen)
 {
 if (index = llen || list[index] == NULL) {
@@ -479,6 +518,12 @@ static const char *trb_name(XHCITRB *trb)
ARRAY_SIZE(TRBType_names));
 }
 
+static const char *event_name(XHCIEvent *event)
+{
+return lookup_name(event-ccode, TRBCCode_names,
+   ARRAY_SIZE(TRBCCode_names));
+}
+
 static uint64_t xhci_mfindex_get(XHCIState *xhci)
 {
 int64_t now = qemu_get_clock_ns(vm_clock);
@@ -574,7 +619,8 @@ static void xhci_write_event(XHCIState *xhci, XHCIEvent 
*event)
 ev_trb.control = cpu_to_le32(ev_trb.control);
 
 trace_usb_xhci_queue_event(xhci-er_ep_idx, trb_name(ev_trb),
-   ev_trb.parameter, ev_trb.status, 
ev_trb.control);
+   event_name(event), ev_trb.parameter,
+   ev_trb.status, ev_trb.control);
 
 addr = xhci-er_start + TRB_SIZE*xhci-er_ep_idx;
 pci_dma_write(xhci-pci_dev, addr, ev_trb, TRB_SIZE);
diff --git a/trace-events b/trace-events
index ba4b112..a642fad 100644
--- a/trace-events
+++ b/trace-events
@@ -313,7 +313,7 @@ usb_xhci_runtime_write(uint32_t off, uint32_t val) off 
0x%04x, val 0x%08x
 usb_xhci_doorbell_write(uint32_t off, uint32_t val) off 0x%04x, val 0x%08x
 usb_xhci_irq_intx(uint32_t level) level %d
 usb_xhci_irq_msi(uint32_t nr) nr %d
-usb_xhci_queue_event(uint32_t idx, const char *name, uint64_t param, uint32_t 
status, uint32_t control) idx %d, %s, p %016 PRIx64 , s %08x, c 0x%08x
+usb_xhci_queue_event(uint32_t idx, const char *trb, const char *evt, uint64_t 
param, uint32_t status, uint32_t control) idx %d, %s, %s, p %016 PRIx64 , s 
%08x, c 0x%08x
 usb_xhci_fetch_trb(uint64_t addr, const char *name, uint64_t param, uint32_t 
status, uint32_t control) addr %016 PRIx64 , %s, p %016 PRIx64 , s %08x, c 
0x%08x
 usb_xhci_slot_enable(uint32_t slotid) slotid %d
 usb_xhci_slot_disable(uint32_t slotid) slotid %d
-- 
1.7.1




[Qemu-devel] [PATCH 45/54] xhci: fix cleanup msi.

2012-09-06 Thread Gerd Hoffmann
Drop custom write_config function which isn't needed any more.
Make the msi property a bit property so it accepts 'on'  'off'.
Enable MSI by default.

TODO: add compat property to disable on old machine types.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-xhci.c |   27 +--
 1 files changed, 9 insertions(+), 18 deletions(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index e08312e..e1d5d2a 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -386,7 +386,7 @@ struct XHCIState {
 /* properties */
 uint32_t numports_2;
 uint32_t numports_3;
-uint32_t msi;
+uint32_t flags;
 
 /* Operational Registers */
 uint32_t usbcmd;
@@ -435,6 +435,10 @@ typedef struct XHCIEvRingSeg {
 uint32_t rsvd;
 } XHCIEvRingSeg;
 
+enum xhci_flags {
+XHCI_FLAG_USE_MSI = 1,
+};
+
 static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
  unsigned int epid);
 static void xhci_event(XHCIState *xhci, XHCIEvent *event);
@@ -617,7 +621,7 @@ static void xhci_irq_update(XHCIState *xhci)
 level = 1;
 }
 
-if (xhci-msi  msi_enabled(xhci-pci_dev)) {
+if (msi_enabled(xhci-pci_dev)) {
 if (level) {
 trace_usb_xhci_irq_msi(0);
 msi_notify(xhci-pci_dev, 0);
@@ -2859,32 +2863,20 @@ static int usb_xhci_initfn(struct PCIDevice *dev)
 ret = pcie_cap_init(xhci-pci_dev, 0xa0, PCI_EXP_TYPE_ENDPOINT, 0);
 assert(ret = 0);
 
-if (xhci-msi) {
-ret = msi_init(xhci-pci_dev, 0x70, 1, true, false);
-assert(ret = 0);
+if (xhci-flags  (1  XHCI_FLAG_USE_MSI)) {
+msi_init(xhci-pci_dev, 0x70, MAXINTRS, true, false);
 }
 
 return 0;
 }
 
-static void xhci_write_config(PCIDevice *dev, uint32_t addr, uint32_t val,
-  int len)
-{
-XHCIState *xhci = DO_UPCAST(XHCIState, pci_dev, dev);
-
-pci_default_write_config(dev, addr, val, len);
-if (xhci-msi) {
-msi_write_config(dev, addr, val, len);
-}
-}
-
 static const VMStateDescription vmstate_xhci = {
 .name = xhci,
 .unmigratable = 1,
 };
 
 static Property xhci_properties[] = {
-DEFINE_PROP_UINT32(msi, XHCIState, msi, 0),
+DEFINE_PROP_BIT(msi,XHCIState, flags, XHCI_FLAG_USE_MSI, true),
 DEFINE_PROP_UINT32(p2,  XHCIState, numports_2, 4),
 DEFINE_PROP_UINT32(p3,  XHCIState, numports_3, 4),
 DEFINE_PROP_END_OF_LIST(),
@@ -2904,7 +2896,6 @@ static void xhci_class_init(ObjectClass *klass, void 
*data)
 k-class_id = PCI_CLASS_SERIAL_USB;
 k-revision = 0x03;
 k-is_express   = 1;
-k-config_write = xhci_write_config;
 }
 
 static TypeInfo xhci_info = {
-- 
1.7.1




[Qemu-devel] [PATCH 47/54] xhci: add msix support

2012-09-06 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-xhci.c |   47 ++-
 trace-events  |3 +++
 2 files changed, 49 insertions(+), 1 deletions(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 5eae32e..3bac99a 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -23,6 +23,7 @@
 #include hw/usb.h
 #include hw/pci.h
 #include hw/msi.h
+#include hw/msix.h
 #include trace.h
 
 //#define DEBUG_XHCI
@@ -59,6 +60,8 @@
 #define OFF_OPERLEN_CAP
 #define OFF_RUNTIME 0x1000
 #define OFF_DOORBELL0x2000
+#define OFF_MSIX_TABLE  0x3000
+#define OFF_MSIX_PBA0x3800
 /* must be power of 2 */
 #define LEN_REGS0x4000
 
@@ -411,6 +414,7 @@ struct XHCIState {
 uint32_t erstba_high;
 uint32_t erdp_low;
 uint32_t erdp_high;
+bool msix_used;
 
 int64_t mfindex_start;
 QEMUTimer *mfwrap_timer;
@@ -437,6 +441,7 @@ typedef struct XHCIEvRingSeg {
 
 enum xhci_flags {
 XHCI_FLAG_USE_MSI = 1,
+XHCI_FLAG_USE_MSI_X,
 };
 
 static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
@@ -616,7 +621,8 @@ static void xhci_intx_update(XHCIState *xhci)
 {
 int level = 0;
 
-if (msi_enabled(xhci-pci_dev)) {
+if (msix_enabled(xhci-pci_dev) ||
+msi_enabled(xhci-pci_dev)) {
 return;
 }
 
@@ -630,6 +636,30 @@ static void xhci_intx_update(XHCIState *xhci)
 qemu_set_irq(xhci-irq, level);
 }
 
+static void xhci_msix_update(XHCIState *xhci)
+{
+bool enabled;
+
+if (!msix_enabled(xhci-pci_dev)) {
+return;
+}
+
+enabled = xhci-iman  IMAN_IE;
+if (enabled == xhci-msix_used) {
+return;
+}
+
+if (enabled) {
+trace_usb_xhci_irq_msix_use(0);
+msix_vector_use(xhci-pci_dev, 0);
+xhci-msix_used = true;
+} else {
+trace_usb_xhci_irq_msix_unuse(0);
+msix_vector_unuse(xhci-pci_dev, 0);
+xhci-msix_used = false;
+}
+}
+
 static void xhci_intr_raise(XHCIState *xhci)
 {
 if (!(xhci-iman  IMAN_IP) ||
@@ -641,6 +671,12 @@ static void xhci_intr_raise(XHCIState *xhci)
 return;
 }
 
+if (msix_enabled(xhci-pci_dev)) {
+trace_usb_xhci_irq_msix(0);
+msix_notify(xhci-pci_dev, 0);
+return;
+}
+
 if (msi_enabled(xhci-pci_dev)) {
 trace_usb_xhci_irq_msi(0);
 msi_notify(xhci-pci_dev, 0);
@@ -2284,6 +2320,7 @@ static void xhci_reset(DeviceState *dev)
 xhci-erstba_high = 0;
 xhci-erdp_low = 0;
 xhci-erdp_high = 0;
+xhci-msix_used = 0;
 
 xhci-er_ep_idx = 0;
 xhci-er_pcs = 1;
@@ -2592,6 +2629,7 @@ static void xhci_runtime_write(XHCIState *xhci, uint32_t 
reg, uint32_t val)
 xhci-iman = ~IMAN_IE;
 xhci-iman |= val  IMAN_IE;
 xhci_intx_update(xhci);
+xhci_msix_update(xhci);
 break;
 case 0x24: /* IMOD */
 xhci-imod = val;
@@ -2885,6 +2923,12 @@ static int usb_xhci_initfn(struct PCIDevice *dev)
 if (xhci-flags  (1  XHCI_FLAG_USE_MSI)) {
 msi_init(xhci-pci_dev, 0x70, MAXINTRS, true, false);
 }
+if (xhci-flags  (1  XHCI_FLAG_USE_MSI_X)) {
+msix_init(xhci-pci_dev, MAXINTRS,
+  xhci-mem, 0, OFF_MSIX_TABLE,
+  xhci-mem, 0, OFF_MSIX_PBA,
+  0x90);
+}
 
 return 0;
 }
@@ -2896,6 +2940,7 @@ static const VMStateDescription vmstate_xhci = {
 
 static Property xhci_properties[] = {
 DEFINE_PROP_BIT(msi,XHCIState, flags, XHCI_FLAG_USE_MSI, true),
+DEFINE_PROP_BIT(msix,   XHCIState, flags, XHCI_FLAG_USE_MSI_X, true),
 DEFINE_PROP_UINT32(p2,  XHCIState, numports_2, 4),
 DEFINE_PROP_UINT32(p3,  XHCIState, numports_3, 4),
 DEFINE_PROP_END_OF_LIST(),
diff --git a/trace-events b/trace-events
index 09972ad..f03745c 100644
--- a/trace-events
+++ b/trace-events
@@ -313,6 +313,9 @@ usb_xhci_runtime_write(uint32_t off, uint32_t val) off 
0x%04x, val 0x%08x
 usb_xhci_doorbell_write(uint32_t off, uint32_t val) off 0x%04x, val 0x%08x
 usb_xhci_irq_intx(uint32_t level) level %d
 usb_xhci_irq_msi(uint32_t nr) nr %d
+usb_xhci_irq_msix(uint32_t nr) nr %d
+usb_xhci_irq_msix_use(uint32_t nr) nr %d
+usb_xhci_irq_msix_unuse(uint32_t nr) nr %d
 usb_xhci_queue_event(uint32_t idx, const char *trb, const char *evt, uint64_t 
param, uint32_t status, uint32_t control) idx %d, %s, %s, p %016 PRIx64 , s 
%08x, c 0x%08x
 usb_xhci_fetch_trb(uint64_t addr, const char *name, uint64_t param, uint32_t 
status, uint32_t control) addr %016 PRIx64 , %s, p %016 PRIx64 , s %08x, c 
0x%08x
 usb_xhci_slot_enable(uint32_t slotid) slotid %d
-- 
1.7.1




[Qemu-devel] [PATCH 07/14] spice: increase the verbosity of spice section in qemu --help

2012-09-06 Thread Gerd Hoffmann
From: Yonit Halperin yhalp...@redhat.com

Added all spice options to the help string. This can be used by libvirt
to determine which spice related features are supported by qemu.

Signed-off-by: Yonit Halperin yhalp...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 qemu-options.hx |   18 +-
 1 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index 96a7bb1..804a2d1 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -838,7 +838,23 @@ Enable SDL.
 ETEXI
 
 DEF(spice, HAS_ARG, QEMU_OPTION_spice,
--spice args   enable spice\n, QEMU_ARCH_ALL)
+-spice [port=port][,tls-port=secured-port][,x509-dir=dir]\n
+   [,x509-key-file=file][,x509-key-password=file]\n
+   [,x509-cert-file=file][,x509-cacert-file=file]\n
+   [,x509-dh-key-file=file][,addr=addr][,ipv4|ipv6]\n
+   [,tls-ciphers=list]\n
+   [,tls-channel=[main|display|cursor|inputs|record|playback]]\n
+   
[,plaintext-channel=[main|display|cursor|inputs|record|playback]]\n
+   [,sasl][,password=secret][,disable-ticketing]\n
+   [,image-compression=[auto_glz|auto_lz|quic|glz|lz|off]]\n
+   [,jpeg-wan-compression=[auto|never|always]]\n
+   [,zlib-glz-wan-compression=[auto|never|always]]\n
+   [,streaming-video=[off|all|filter]][,disable-copy-paste]\n
+   [,agent-mouse=[on|off]][,playback-compression=[on|off]]\n
+   [,seamless-migration=[on|off]]\n
+   enable spice\n
+   at least one of {port, tls-port} is mandatory\n,
+QEMU_ARCH_ALL)
 STEXI
 @item -spice @var{option}[,@var{option}[,...]]
 @findex -spice
-- 
1.7.1




[Qemu-devel] [PATCH 04/14] spice migration: add QEVENT_SPICE_MIGRATE_COMPLETED

2012-09-06 Thread Gerd Hoffmann
From: Yonit Halperin yhalp...@redhat.com

When migrating, libvirt queries the migration status, and upon migration
completions, it closes the migration src. On the other hand, when
migration is completed, spice transfers data from the src to destination
via the client. This data is required for keeping the spice session
after migration, without suffering from data loss and inconsistencies.
In order to allow this data transfer, we add QEVENT for signaling
libvirt that spice migration has completed, and libvirt needs to wait
for this event before quitting the src process.

Signed-off-by: Yonit Halperin yhalp...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 monitor.c   |1 +
 monitor.h   |1 +
 ui/spice-core.c |9 -
 3 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/monitor.c b/monitor.c
index b17b1bb..413edf4 100644
--- a/monitor.c
+++ b/monitor.c
@@ -455,6 +455,7 @@ static const char *monitor_event_names[] = {
 [QEVENT_SUSPEND_DISK] = SUSPEND_DISK,
 [QEVENT_WAKEUP] = WAKEUP,
 [QEVENT_BALLOON_CHANGE] = BALLOON_CHANGE,
+[QEVENT_SPICE_MIGRATE_COMPLETED] = SPICE_MIGRATE_COMPLETED,
 };
 QEMU_BUILD_BUG_ON(ARRAY_SIZE(monitor_event_names) != QEVENT_MAX)
 
diff --git a/monitor.h b/monitor.h
index 47d556b..5fc2983 100644
--- a/monitor.h
+++ b/monitor.h
@@ -43,6 +43,7 @@ typedef enum MonitorEvent {
 QEVENT_SUSPEND_DISK,
 QEVENT_WAKEUP,
 QEVENT_BALLOON_CHANGE,
+QEVENT_SPICE_MIGRATE_COMPLETED,
 
 /* Add to 'monitor_event_names' array in monitor.c when
  * defining new events here */
diff --git a/ui/spice-core.c b/ui/spice-core.c
index 1a7a773..851e869 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -285,6 +285,7 @@ typedef struct SpiceMigration {
 } SpiceMigration;
 
 static void migrate_connect_complete_cb(SpiceMigrateInstance *sin);
+static void migrate_end_complete_cb(SpiceMigrateInstance *sin);
 
 static const SpiceMigrateInterface migrate_interface = {
 .base.type = SPICE_INTERFACE_MIGRATION,
@@ -292,7 +293,7 @@ static const SpiceMigrateInterface migrate_interface = {
 .base.major_version = SPICE_INTERFACE_MIGRATION_MAJOR,
 .base.minor_version = SPICE_INTERFACE_MIGRATION_MINOR,
 .migrate_connect_complete = migrate_connect_complete_cb,
-.migrate_end_complete = NULL,
+.migrate_end_complete = migrate_end_complete_cb,
 };
 
 static SpiceMigration spice_migrate;
@@ -305,6 +306,11 @@ static void 
migrate_connect_complete_cb(SpiceMigrateInstance *sin)
 }
 sm-connect_complete.cb = NULL;
 }
+
+static void migrate_end_complete_cb(SpiceMigrateInstance *sin)
+{
+monitor_protocol_event(QEVENT_SPICE_MIGRATE_COMPLETED, NULL);
+}
 #endif
 
 /* config string parsing */
@@ -489,6 +495,7 @@ static void migration_state_notifier(Notifier *notifier, 
void *data)
 } else if (migration_has_finished(s)) {
 #ifndef SPICE_INTERFACE_MIGRATION
 spice_server_migrate_switch(spice_server);
+monitor_protocol_event(QEVENT_SPICE_MIGRATE_COMPLETED, NULL);
 #else
 spice_server_migrate_end(spice_server, true);
 } else if (migration_has_failed(s)) {
-- 
1.7.1




Re: [Qemu-devel] [PATCH v6 2/2] block: Support GlusterFS as a QEMU block backend

2012-09-06 Thread Paolo Bonzini
Il 05/09/2012 11:57, Bharata B Rao ha scritto:
  What could be the issue here ? In general, how do I ensure that my
  aio calls get completed correctly in such scenarios where bdrv_read etc
  are called from coroutine context rather than from main thread context ?
 One way to handle this is not to do completion from gluster thread but
 instead schedule a BH that does the completion. In fact I had this approach
 in the earlier versions, but resorted to directly calling completion from
 gluster thread as I didn't see the value of using a BH for completion.
 But I guess its indeed needed to support such scenarios (qcow2 image creation
 on gluster backend).

I think the problem is that we're calling bdrv_drain_all() from
coroutine context.  This is problematic because then the current
coroutine won't yield and won't give other coroutines an occasion to run.

This could be fixed by checking whether we're in coroutine context in
bdrv_drain_all().  If so, instead of draining the queues directly,
schedule a bottom half that does bdrv_drain_all() followed by
qemu_coroutine_enter(), and yield.

If it works, I think this change would be preferrable to using a magic
BH in every driver.

Paolo



[Qemu-devel] [PATCH 48/54] xhci: move register update into xhci_intr_raise

2012-09-06 Thread Gerd Hoffmann
Now that we have a separate function to raise an IRQ we can move
some comon code into the function.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-xhci.c |   14 +-
 1 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 3bac99a..e39fe04 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -662,8 +662,11 @@ static void xhci_msix_update(XHCIState *xhci)
 
 static void xhci_intr_raise(XHCIState *xhci)
 {
-if (!(xhci-iman  IMAN_IP) ||
-!(xhci-iman  IMAN_IE)) {
+xhci-erdp_low |= ERDP_EHB;
+xhci-iman |= IMAN_IP;
+xhci-usbsts |= USBSTS_EINT;
+
+if (!(xhci-iman  IMAN_IE)) {
 return;
 }
 
@@ -784,9 +787,6 @@ static void xhci_events_update(XHCIState *xhci)
 }
 
 if (do_irq) {
-xhci-erdp_low |= ERDP_EHB;
-xhci-iman |= IMAN_IP;
-xhci-usbsts |= USBSTS_EINT;
 xhci_intr_raise(xhci);
 }
 
@@ -847,10 +847,6 @@ static void xhci_event(XHCIState *xhci, XHCIEvent *event)
 xhci_write_event(xhci, event);
 }
 
-xhci-erdp_low |= ERDP_EHB;
-xhci-iman |= IMAN_IP;
-xhci-usbsts |= USBSTS_EINT;
-
 xhci_intr_raise(xhci);
 }
 
-- 
1.7.1




[Qemu-devel] [PATCH 44/54] usb-storage: usb3 support

2012-09-06 Thread Gerd Hoffmann
Add usb3 descriptors to usb-storage, so it shows up as superspeed
device when connected to xhci.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/dev-storage.c |   46 +++---
 1 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
index ff48d91..e732191 100644
--- a/hw/usb/dev-storage.c
+++ b/hw/usb/dev-storage.c
@@ -78,6 +78,7 @@ enum {
 STR_SERIALNUMBER,
 STR_CONFIG_FULL,
 STR_CONFIG_HIGH,
+STR_CONFIG_SUPER,
 };
 
 static const USBDescStrings desc_strings = {
@@ -86,6 +87,7 @@ static const USBDescStrings desc_strings = {
 [STR_SERIALNUMBER] = 1,
 [STR_CONFIG_FULL]  = Full speed config (usb 1.1),
 [STR_CONFIG_HIGH]  = High speed config (usb 2.0),
+[STR_CONFIG_SUPER] = Super speed config (usb 3.0),
 };
 
 static const USBDescIface desc_iface_full = {
@@ -158,6 +160,43 @@ static const USBDescDevice desc_device_high = {
 },
 };
 
+static const USBDescIface desc_iface_super = {
+.bInterfaceNumber  = 0,
+.bNumEndpoints = 2,
+.bInterfaceClass   = USB_CLASS_MASS_STORAGE,
+.bInterfaceSubClass= 0x06, /* SCSI */
+.bInterfaceProtocol= 0x50, /* Bulk */
+.eps = (USBDescEndpoint[]) {
+{
+.bEndpointAddress  = USB_DIR_IN | 0x01,
+.bmAttributes  = USB_ENDPOINT_XFER_BULK,
+.wMaxPacketSize= 1024,
+.bMaxBurst = 15,
+},{
+.bEndpointAddress  = USB_DIR_OUT | 0x02,
+.bmAttributes  = USB_ENDPOINT_XFER_BULK,
+.wMaxPacketSize= 1024,
+.bMaxBurst = 15,
+},
+}
+};
+
+static const USBDescDevice desc_device_super = {
+.bcdUSB= 0x0300,
+.bMaxPacketSize0   = 9,
+.bNumConfigurations= 1,
+.confs = (USBDescConfig[]) {
+{
+.bNumInterfaces= 1,
+.bConfigurationValue   = 1,
+.iConfiguration= STR_CONFIG_SUPER,
+.bmAttributes  = 0xc0,
+.nif = 1,
+.ifs = desc_iface_super,
+},
+},
+};
+
 static const USBDesc desc = {
 .id = {
 .idVendor  = 0x46f4, /* CRC16() of QEMU */
@@ -167,9 +206,10 @@ static const USBDesc desc = {
 .iProduct  = STR_PRODUCT,
 .iSerialNumber = STR_SERIALNUMBER,
 },
-.full = desc_device_full,
-.high = desc_device_high,
-.str  = desc_strings,
+.full  = desc_device_full,
+.high  = desc_device_high,
+.super = desc_device_super,
+.str   = desc_strings,
 };
 
 static void usb_msd_copy_data(MSDState *s, USBPacket *p)
-- 
1.7.1




[Qemu-devel] [PATCH 46/54] xhci: rework interrupt handling

2012-09-06 Thread Gerd Hoffmann
Split xhci_irq_update into a function which handles intx updates
(including lowering the irq line once the guests acks the interrupt)
and one which is used for raising an irq only.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-xhci.c |   47 +--
 1 files changed, 33 insertions(+), 14 deletions(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index e1d5d2a..5eae32e 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -612,24 +612,43 @@ static XHCIPort *xhci_lookup_port(XHCIState *xhci, struct 
USBPort *uport)
 return xhci-ports[index];
 }
 
-static void xhci_irq_update(XHCIState *xhci)
+static void xhci_intx_update(XHCIState *xhci)
 {
 int level = 0;
 
-if (xhci-iman  IMAN_IP  xhci-iman  IMAN_IE 
+if (msi_enabled(xhci-pci_dev)) {
+return;
+}
+
+if (xhci-iman  IMAN_IP 
+xhci-iman  IMAN_IE 
 xhci-usbcmd  USBCMD_INTE) {
 level = 1;
 }
 
+trace_usb_xhci_irq_intx(level);
+qemu_set_irq(xhci-irq, level);
+}
+
+static void xhci_intr_raise(XHCIState *xhci)
+{
+if (!(xhci-iman  IMAN_IP) ||
+!(xhci-iman  IMAN_IE)) {
+return;
+}
+
+if (!(xhci-usbcmd  USBCMD_INTE)) {
+return;
+}
+
 if (msi_enabled(xhci-pci_dev)) {
-if (level) {
-trace_usb_xhci_irq_msi(0);
-msi_notify(xhci-pci_dev, 0);
-}
-} else {
-trace_usb_xhci_irq_intx(level);
-qemu_set_irq(xhci-irq, level);
+trace_usb_xhci_irq_msi(0);
+msi_notify(xhci-pci_dev, 0);
+return;
 }
+
+trace_usb_xhci_irq_intx(1);
+qemu_set_irq(xhci-irq, 1);
 }
 
 static inline int xhci_running(XHCIState *xhci)
@@ -732,7 +751,7 @@ static void xhci_events_update(XHCIState *xhci)
 xhci-erdp_low |= ERDP_EHB;
 xhci-iman |= IMAN_IP;
 xhci-usbsts |= USBSTS_EINT;
-xhci_irq_update(xhci);
+xhci_intr_raise(xhci);
 }
 
 if (xhci-er_full  xhci-ev_buffer_put == xhci-ev_buffer_get) {
@@ -796,7 +815,7 @@ static void xhci_event(XHCIState *xhci, XHCIEvent *event)
 xhci-iman |= IMAN_IP;
 xhci-usbsts |= USBSTS_EINT;
 
-xhci_irq_update(xhci);
+xhci_intr_raise(xhci);
 }
 
 static void xhci_ring_init(XHCIState *xhci, XHCIRing *ring,
@@ -2481,13 +2500,13 @@ static void xhci_oper_write(XHCIState *xhci, uint32_t 
reg, uint32_t val)
 if (val  USBCMD_HCRST) {
 xhci_reset(xhci-pci_dev.qdev);
 }
-xhci_irq_update(xhci);
+xhci_intx_update(xhci);
 break;
 
 case 0x04: /* USBSTS */
 /* these bits are write-1-to-clear */
 xhci-usbsts = ~(val  
(USBSTS_HSE|USBSTS_EINT|USBSTS_PCD|USBSTS_SRE));
-xhci_irq_update(xhci);
+xhci_intx_update(xhci);
 break;
 
 case 0x14: /* DNCTRL */
@@ -2572,7 +2591,7 @@ static void xhci_runtime_write(XHCIState *xhci, uint32_t 
reg, uint32_t val)
 }
 xhci-iman = ~IMAN_IE;
 xhci-iman |= val  IMAN_IE;
-xhci_irq_update(xhci);
+xhci_intx_update(xhci);
 break;
 case 0x24: /* IMOD */
 xhci-imod = val;
-- 
1.7.1




Re: [Qemu-devel] [PATCH v6 2/2] block: Support GlusterFS as a QEMU block backend

2012-09-06 Thread Paolo Bonzini
Il 09/08/2012 15:02, Bharata B Rao ha scritto:
 block: Support GlusterFS as a QEMU block backend.
 
 From: Bharata B Rao bhar...@linux.vnet.ibm.com
 
 This patch adds gluster as the new block backend in QEMU. This gives
 QEMU the ability to boot VM images from gluster volumes. Its already
 possible to boot from VM images on gluster volumes using FUSE mount, but
 this patchset provides the ability to boot VM images from gluster volumes
 by by-passing the FUSE layer in gluster. This is made possible by
 using libgfapi routines to perform IO on gluster volumes directly.
 
 VM Image on gluster volume is specified like this:
 
 file=gluster://server:[port]/volname/image[?transport=socket]
 
 'gluster' is the protocol.
 
 'server' specifies the server where the volume file specification for
 the given volume resides. This can be either hostname or ipv4 address
 or ipv6 address. ipv6 address needs to be with in square brackets [ ].
 
 port' is the port number on which gluster management daemon (glusterd) is
 listening. This is optional and if not specified, QEMU will send 0 which
 will make libgfapi to use the default port.
 
 'volname' is the name of the gluster volume which contains the VM image.
 
 'image' is the path to the actual VM image in the gluster volume.
 
 'transport' specifies the transport used to connect to glusterd. This is
 optional and if not specified, socket transport is used.
 
 Examples:
 
 file=gluster://1.2.3.4/testvol/a.img
 file=gluster://1.2.3.4:5000/testvol/dir/a.img?transport=socket
 file=gluster://[1:2:3:4:5:6:7:8]/testvol/dir/a.img
 file=gluster://[1:2:3:4:5:6:7:8]:5000/testvol/dir/a.img?transport=socket
 file=gluster://server.domain.com:5000/testvol/dir/a.img
 
 Signed-off-by: Bharata B Rao bhar...@linux.vnet.ibm.com
 Reviewed-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
 ---
 
  block/Makefile.objs |1 
  block/gluster.c |  623 
 +++
  2 files changed, 624 insertions(+), 0 deletions(-)
  create mode 100644 block/gluster.c
 
 
 diff --git a/block/Makefile.objs b/block/Makefile.objs
 index b5754d3..a1ae67f 100644
 --- a/block/Makefile.objs
 +++ b/block/Makefile.objs
 @@ -9,3 +9,4 @@ block-obj-$(CONFIG_POSIX) += raw-posix.o
  block-obj-$(CONFIG_LIBISCSI) += iscsi.o
  block-obj-$(CONFIG_CURL) += curl.o
  block-obj-$(CONFIG_RBD) += rbd.o
 +block-obj-$(CONFIG_GLUSTERFS) += gluster.o
 diff --git a/block/gluster.c b/block/gluster.c
 new file mode 100644
 index 000..bbbaea8
 --- /dev/null
 +++ b/block/gluster.c
 @@ -0,0 +1,623 @@
 +/*
 + * GlusterFS backend for QEMU
 + *
 + * (AIO implementation is derived from block/rbd.c)
 + *
 + * Copyright (C) 2012 Bharata B Rao bhar...@linux.vnet.ibm.com
 + *
 + * This work is licensed under the terms of the GNU GPL, version 2 or
 + * (at your option) any later version. See the COPYING file in the top-level
 + * directory.
 + */
 +#include glusterfs/api/glfs.h
 +#include block_int.h
 +
 +typedef struct GlusterAIOCB {
 +BlockDriverAIOCB common;
 +bool canceled;
 +int64_t size;
 +int ret;
 +} GlusterAIOCB;
 +
 +typedef struct BDRVGlusterState {
 +struct glfs *glfs;
 +int fds[2];
 +struct glfs_fd *fd;
 +int qemu_aio_count;
 +} BDRVGlusterState;
 +
 +#define GLUSTER_FD_READ 0
 +#define GLUSTER_FD_WRITE 1
 +
 +typedef struct GlusterURI {
 +char *server;
 +int port;
 +char *volname;
 +char *image;
 +char *transport;
 +} GlusterURI;
 +
 +static void qemu_gluster_uri_free(GlusterURI *uri)
 +{
 +g_free(uri-server);
 +g_free(uri-volname);
 +g_free(uri-image);
 +g_free(uri-transport);
 +g_free(uri);
 +}
 +
 +/*
 + * We don't validate the transport option obtained here but
 + * instead depend on gluster to flag an error.
 + */
 +static int parse_transport(GlusterURI *uri, char *transport)
 +{
 +char *token, *saveptr;
 +int ret = -EINVAL;
 +
 +if (!transport) {
 +uri-transport = g_strdup(socket);
 +ret = 0;
 +goto out;
 +}
 +
 +token = strtok_r(transport, =, saveptr);
 +if (!token) {
 +goto out;
 +}
 +if (strcmp(token, transport)) {
 +goto out;
 +}
 +token = strtok_r(NULL, =, saveptr);
 +if (!token) {
 +goto out;
 +}
 +uri-transport = g_strdup(token);
 +ret = 0;
 +out:
 +return ret;
 +}
 +
 +static int parse_server(GlusterURI *uri, char *server)
 +{
 +int ret = -EINVAL;
 +char *token, *saveptr;
 +char *p, *q = server;
 +
 +p = strchr(server, '[');
 +if (p) {
 +/* [ipv6] */
 +if (p != server) {
 +/* [ not in the beginning */
 +goto out;
 +}
 +q++;
 +p = strrchr(p, ']');
 +if (!p) {
 +/* No matching ] */
 +goto out;
 +}
 +*p++ = '\0';
 +uri-server = g_strdup(q);
 +
 +if (*p) {
 +if (*p != ':') {
 +/* [ipv6] followed by something other than : */
 +

[Qemu-devel] [PATCH 12/54] ehci: add doorbell trace events

2012-09-06 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-ehci.c |3 ++-
 trace-events  |2 ++
 2 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 4564615..398f5e0 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -1241,6 +1241,7 @@ static void ehci_mem_writel(void *ptr, target_phys_addr_t 
addr, uint32_t val)
  */
 s-async_stepdown = 0;
 qemu_bh_schedule(s-async_bh);
+trace_usb_ehci_doorbell_ring();
 }
 
 if (((USBCMD_RUNSTOP | USBCMD_PSE | USBCMD_ASE)  val) !=
@@ -2335,7 +2336,7 @@ static void ehci_advance_async_state(EHCIState *ehci)
 if (ehci-usbcmd  USBCMD_IAAD) {
 /* Remove all unseen qhs from the async qhs queue */
 ehci_queues_rip_unused(ehci, async, 1);
-DPRINTF(ASYNC: doorbell request acknowledged\n);
+trace_usb_ehci_doorbell_ack();
 ehci-usbcmd = ~USBCMD_IAAD;
 ehci_raise_irq(ehci, USBSTS_IAA);
 }
diff --git a/trace-events b/trace-events
index 0c7ffc7..8dc4f45 100644
--- a/trace-events
+++ b/trace-events
@@ -264,6 +264,8 @@ usb_ehci_queue_action(void *q, const char *action) q %p: 
%s
 usb_ehci_packet_action(void *q, void *p, const char *action) q %p p %p: %s
 usb_ehci_irq(uint32_t level, uint32_t frindex, uint32_t sts, uint32_t mask) 
level %d, frindex 0x%04x, sts 0x%x, mask 0x%x
 usb_ehci_guest_bug(const char *reason) %s
+usb_ehci_doorbell_ring(void) 
+usb_ehci_doorbell_ack(void) 
 
 # hw/usb/hcd-uhci.c
 usb_uhci_reset(void) === RESET ===
-- 
1.7.1




[Qemu-devel] [PULL 0/4] wakeup: make wakeup events guest-configurable

2012-09-06 Thread Gerd Hoffmann
  Hi,

This patch series allows the guest to enable and disable s3 wakeup
events per device via acpi.  It also adds support for waking up
the guest from uhci.  Each device gets a GPE pin assigned.

With this patch series applied and seabios updated (for the dsdt updates
needed to tell guests about the GPE assignments) /proc/acpi/wakeup
looks like this:

[root@fedora ~]# cat /proc/acpi/wakeup 
Device  S-state   Status   Sysfs node
UHCI  S3*enabled   pci::00:01.2
KBD   S3*enabled   pnp:00:02
MOU   S3*disabled  pnp:00:03
COM1  S3*disabled  pnp:00:05

Patches have been posted for review a while back, pull req got delayed
due to vacation and 1.2 freeze, now I'm finally aiming for merge.

seabios changes needed are available from
  git://git.kraxel.org/seabios wakeup

please pull,
  Gerd

The following changes since commit 8db972cfa469b4e4afd9c65e54e796b83b5ce3a2:

  Update version for 1.2.0 (2012-09-05 07:50:01 -0500)

are available in the git repository at:
  git://git.kraxel.org/qemu wakeup.1

Gerd Hoffmann (4):
  wakeup: add acpi gpe wakeup reasons
  wakeup: make ps/2 configurable
  wakeup: make serial configurable
  wakeup: uhci support

 hw/acpi.c |   26 ++
 hw/ps2.c  |4 ++--
 hw/serial.c   |   10 +-
 hw/usb/hcd-uhci.c |   35 +++
 sysemu.h  |4 
 5 files changed, 76 insertions(+), 3 deletions(-)



[Qemu-devel] [PATCH 3/4] wakeup: make serial configurable

2012-09-06 Thread Gerd Hoffmann
serial port #1 gets gpe 0x0a.  Now that the wakeup is guest-configurable
via acpi we also enable it unconditionally.

Other serial ports are unchanged: they continue to use the other exit
reason and are disabled unless explicitly enabled via wakeup property.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/serial.c |   10 +-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/hw/serial.c b/hw/serial.c
index a421d1e..06f7e28 100644
--- a/hw/serial.c
+++ b/hw/serial.c
@@ -140,6 +140,7 @@ struct SerialState {
 int baudbase;
 int tsr_retry;
 uint32_t wakeup;
+WakeupReason reason;
 
 uint64_t last_xmit_ts;  /* Time when the last byte was 
successfully sent out of the tsr */
 SerialFIFO recv_fifo;
@@ -641,7 +642,7 @@ static void serial_receive1(void *opaque, const uint8_t 
*buf, int size)
 SerialState *s = opaque;
 
 if (s-wakeup) {
-qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
+qemu_system_wakeup_request(s-reason);
 }
 if(s-fcr  UART_FCR_FE) {
 int i;
@@ -789,6 +790,13 @@ static int serial_isa_initfn(ISADevice *dev)
 isa-isairq = isa_serial_irq[isa-index];
 index++;
 
+if (isa-iobase == 0x3f8) {
+s-reason = QEMU_WAKEUP_REASON_GPE_a;
+s-wakeup = 1;
+} else {
+s-reason = QEMU_WAKEUP_REASON_OTHER;
+}
+
 s-baudbase = 115200;
 isa_init_irq(dev, s-irq, isa-isairq);
 serial_init_core(s);
-- 
1.7.1




[Qemu-devel] [PATCH 1/4] wakeup: add acpi gpe wakeup reasons

2012-09-06 Thread Gerd Hoffmann
Allocate four acpi gpe bits (0x08 - 0x0b) for s3 wakeup
configuration and notification.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/acpi.c |   26 ++
 sysemu.h  |4 
 2 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/hw/acpi.c b/hw/acpi.c
index f7950be..4d6bc71 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -263,6 +263,22 @@ static void acpi_notify_wakeup(Notifier *notifier, void 
*data)
 ar-pm1.evt.sts |=
 (ACPI_BITMASK_WAKE_STATUS | ACPI_BITMASK_TIMER_STATUS);
 break;
+case QEMU_WAKEUP_REASON_GPE_8:
+ar-pm1.evt.sts |= ACPI_BITMASK_WAKE_STATUS;
+ar-gpe.sts[1] |= (1  0);
+break;
+case QEMU_WAKEUP_REASON_GPE_9:
+ar-pm1.evt.sts |= ACPI_BITMASK_WAKE_STATUS;
+ar-gpe.sts[1] |= (1  1);
+break;
+case QEMU_WAKEUP_REASON_GPE_a:
+ar-pm1.evt.sts |= ACPI_BITMASK_WAKE_STATUS;
+ar-gpe.sts[1] |= (1  2);
+break;
+case QEMU_WAKEUP_REASON_GPE_b:
+ar-pm1.evt.sts |= ACPI_BITMASK_WAKE_STATUS;
+ar-gpe.sts[1] |= (1  3);
+break;
 case QEMU_WAKEUP_REASON_OTHER:
 default:
 /* ACPI_BITMASK_WAKE_STATUS should be set on resume.
@@ -428,6 +444,10 @@ void acpi_gpe_reset(ACPIREGS *ar)
 {
 memset(ar-gpe.sts, 0, ar-gpe.len / 2);
 memset(ar-gpe.en, 0, ar-gpe.len / 2);
+qemu_system_wakeup_enable(QEMU_WAKEUP_REASON_GPE_8, 0);
+qemu_system_wakeup_enable(QEMU_WAKEUP_REASON_GPE_9, 0);
+qemu_system_wakeup_enable(QEMU_WAKEUP_REASON_GPE_a, 0);
+qemu_system_wakeup_enable(QEMU_WAKEUP_REASON_GPE_b, 0);
 }
 
 static uint8_t *acpi_gpe_ioport_get_ptr(ACPIREGS *ar, uint32_t addr)
@@ -457,6 +477,12 @@ void acpi_gpe_ioport_writeb(ACPIREGS *ar, uint32_t addr, 
uint32_t val)
 } else if (addr  ar-gpe.len) {
 /* GPE_EN */
 *cur = val;
+if (addr == ar-gpe.len / 2 + 1) {
+qemu_system_wakeup_enable(QEMU_WAKEUP_REASON_GPE_8, val  (1  
0));
+qemu_system_wakeup_enable(QEMU_WAKEUP_REASON_GPE_9, val  (1  
1));
+qemu_system_wakeup_enable(QEMU_WAKEUP_REASON_GPE_a, val  (1  
2));
+qemu_system_wakeup_enable(QEMU_WAKEUP_REASON_GPE_b, val  (1  
3));
+}
 } else {
 abort();
 }
diff --git a/sysemu.h b/sysemu.h
index 65552ac..af04941 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -42,6 +42,10 @@ typedef enum WakeupReason {
 QEMU_WAKEUP_REASON_OTHER = 0,
 QEMU_WAKEUP_REASON_RTC,
 QEMU_WAKEUP_REASON_PMTIMER,
+QEMU_WAKEUP_REASON_GPE_8,
+QEMU_WAKEUP_REASON_GPE_9,
+QEMU_WAKEUP_REASON_GPE_a,
+QEMU_WAKEUP_REASON_GPE_b,
 } WakeupReason;
 
 void qemu_system_reset_request(void);
-- 
1.7.1




[Qemu-devel] [PATCH 23/54] usb-redir: Return babble when getting more bulk data then requested

2012-09-06 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

Babble is the appropriate error in this case (rather then signalling a stall).

Signed-off-by: Hans de Goede hdego...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/redirect.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index fd1f8cc..ee75217 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -1324,9 +1324,9 @@ static void usbredir_bulk_packet(void *priv, uint32_t id,
 if (data_len = p-iov.size) {
 usb_packet_copy(p, data, data_len);
 } else {
-ERROR(bulk buffer too small (%d  %zd)\n, data_len,
-  p-iov.size);
-len = USB_RET_STALL;
+ERROR(bulk got more data then requested (%d  %zd)\n,
+  data_len, p-iov.size);
+len = USB_RET_BABBLE;
 }
 }
 p-result = len;
-- 
1.7.1




Re: [Qemu-devel] [PATCH 3/4] wakeup: make serial configurable

2012-09-06 Thread Peter Maydell
On 6 September 2012 08:42, Gerd Hoffmann kra...@redhat.com wrote:
 @@ -789,6 +790,13 @@ static int serial_isa_initfn(ISADevice *dev)
  isa-isairq = isa_serial_irq[isa-index];
  index++;

 +if (isa-iobase == 0x3f8) {
 +s-reason = QEMU_WAKEUP_REASON_GPE_a;
 +s-wakeup = 1;
 +} else {
 +s-reason = QEMU_WAKEUP_REASON_OTHER;
 +}
 +

It seems a bit odd that this is done in the ISA serial model
itself and not by the next level up wiring up some output
of the ISA serial device to some appropriate input...

-- PMM



Re: [Qemu-devel] [PATCH] qxl: dont update invalid area

2012-09-06 Thread Gerd Hoffmann
On 08/30/12 18:44, riegama...@gmail.com wrote:
 This patch fixes the following error:
 
 $ ~/usr/bin/qemu-system-x86_64 -enable-kvm -m 1024 -spice 
 port=5900,disable-ticketing -vga qxl -cdrom 
 ~/Images/linuxmint-13-mate-dvd-32bit.iso
 (/home/mathslinux/usr/bin/qemu-system-x86_64:10068): SpiceWorker-CRITICAL **: 
 red_worker.c:4599:red_update_area: condition `area-left = 0  area-top = 
 0  area-left  area-right  area-top  area-bottom' failed
 Aborted
 
 spice server terminates QEMU process if we pass invalid area to it,
 so dont update those invalid areas.

Patch added to spice patch queue.

thanks,
  Gerd



[Qemu-devel] [PATCH 40/54] xhci: update port handling

2012-09-06 Thread Gerd Hoffmann
This patch changes the way xhci ports are linked to USBPorts.  The fixed
1:1 relationship between xhci ports and USBPorts is gone.  Now each
USBPort represents a physical plug which has usually two xhci ports
assigned: one usb2 and ond usb3 port.  usb devices show up at one or the
other, depending on whenever they support superspeed or not.

This patch also makes the number of usb2 and usb3 ports runtime
configurable by adding 'p2' and 'p3' properties.  It is allowed to
have different numbers of usb2 and usb3 ports.  Specifying p2=4,p3=2
will give you an xhci adapter which supports all speeds on physical
ports 1+2 and usb2 only on ports 3+4.
---
 hw/usb/hcd-xhci.c |  137 +---
 1 files changed, 97 insertions(+), 40 deletions(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 414b633..e08312e 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -36,10 +36,10 @@
 #define FIXME() do { fprintf(stderr, FIXME %s:%d\n, \
  __func__, __LINE__); abort(); } while (0)
 
-#define USB2_PORTS 4
-#define USB3_PORTS 4
+#define MAXPORTS_2 8
+#define MAXPORTS_3 8
 
-#define MAXPORTS (USB2_PORTS+USB3_PORTS)
+#define MAXPORTS (MAXPORTS_2+MAXPORTS_3)
 #define MAXSLOTS MAXPORTS
 #define MAXINTRS 1 /* MAXPORTS */
 
@@ -300,8 +300,10 @@ typedef struct XHCIRing {
 } XHCIRing;
 
 typedef struct XHCIPort {
-USBPort port;
 uint32_t portsc;
+uint32_t portnr;
+USBPort  *uport;
+uint32_t speedmask;
 } XHCIPort;
 
 struct XHCIState;
@@ -379,9 +381,13 @@ struct XHCIState {
 qemu_irq irq;
 MemoryRegion mem;
 const char *name;
-uint32_t msi;
 unsigned int devaddr;
 
+/* properties */
+uint32_t numports_2;
+uint32_t numports_3;
+uint32_t msi;
+
 /* Operational Registers */
 uint32_t usbcmd;
 uint32_t usbsts;
@@ -392,8 +398,10 @@ struct XHCIState {
 uint32_t dcbaap_high;
 uint32_t config;
 
+USBPort  uports[MAX(MAXPORTS_2, MAXPORTS_3)];
 XHCIPort ports[MAXPORTS];
 XHCISlot slots[MAXSLOTS];
+uint32_t numports;
 
 /* Runtime Registers */
 uint32_t iman;
@@ -578,6 +586,28 @@ static inline dma_addr_t xhci_mask64(uint64_t addr)
 }
 }
 
+static XHCIPort *xhci_lookup_port(XHCIState *xhci, struct USBPort *uport)
+{
+int index;
+
+if (!uport-dev) {
+return NULL;
+}
+switch (uport-dev-speed) {
+case USB_SPEED_LOW:
+case USB_SPEED_FULL:
+case USB_SPEED_HIGH:
+index = uport-index;
+break;
+case USB_SPEED_SUPER:
+index = uport-index + xhci-numports_2;
+break;
+default:
+return NULL;
+}
+return xhci-ports[index];
+}
+
 static void xhci_irq_update(XHCIState *xhci)
 {
 int level = 0;
@@ -1126,7 +1156,7 @@ static TRBCCode xhci_reset_ep(XHCIState *xhci, unsigned 
int slotid,
 ep |= 0x80;
 }
 
-dev = xhci-ports[xhci-slots[slotid-1].port-1].port.dev;
+dev = xhci-ports[xhci-slots[slotid-1].port-1].uport-dev;
 if (!dev) {
 return CC_USB_TRANSACTION_ERROR;
 }
@@ -1313,7 +1343,7 @@ static USBDevice *xhci_find_device(XHCIPort *port, 
uint8_t addr)
 if (!(port-portsc  PORTSC_PED)) {
 return NULL;
 }
-return usb_find_device(port-port, addr);
+return usb_find_device(port-uport, addr);
 }
 
 static int xhci_setup_packet(XHCITransfer *xfer)
@@ -1736,9 +1766,9 @@ static TRBCCode xhci_address_slot(XHCIState *xhci, 
unsigned int slotid,
 ep0_ctx[0], ep0_ctx[1], ep0_ctx[2], ep0_ctx[3], ep0_ctx[4]);
 
 port = (slot_ctx[1]16)  0xFF;
-dev = xhci-ports[port-1].port.dev;
+dev = xhci-ports[port-1].uport-dev;
 
-if (port  1 || port  MAXPORTS) {
+if (port  1 || port  xhci-numports) {
 fprintf(stderr, xhci: bad port %d\n, port);
 return CC_TRB_ERROR;
 } else if (!dev) {
@@ -1987,7 +2017,7 @@ static unsigned int xhci_get_slot(XHCIState *xhci, 
XHCIEvent *event, XHCITRB *tr
 static TRBCCode xhci_get_port_bandwidth(XHCIState *xhci, uint64_t pctx)
 {
 dma_addr_t ctx;
-uint8_t bw_ctx[MAXPORTS+1];
+uint8_t bw_ctx[xhci-numports+1];
 
 DPRINTF(xhci_get_port_bandwidth()\n);
 
@@ -1997,7 +2027,7 @@ static TRBCCode xhci_get_port_bandwidth(XHCIState *xhci, 
uint64_t pctx)
 
 /* TODO: actually implement real values here */
 bw_ctx[0] = 0;
-memset(bw_ctx[1], 80, MAXPORTS); /* 80% */
+memset(bw_ctx[1], 80, xhci-numports); /* 80% */
 pci_dma_write(xhci-pci_dev, ctx, bw_ctx, sizeof(bw_ctx));
 
 return CC_SUCCESS;
@@ -2167,12 +2197,11 @@ static void xhci_process_commands(XHCIState *xhci)
 
 static void xhci_update_port(XHCIState *xhci, XHCIPort *port, int is_detach)
 {
-int nr = port-port.index + 1;
-
 port-portsc = PORTSC_PP;
-if (port-port.dev  port-port.dev-attached  !is_detach) {
+if (port-uport-dev  port-uport-dev-attached  !is_detach 
+(1  port-uport-dev-speed)  port-speedmask) {
 port-portsc |= PORTSC_CCS;
-switch 

[Qemu-devel] [PATCH 03/14] spice: notify on vm state change only via spice_server_vm_start/stop

2012-09-06 Thread Gerd Hoffmann
From: Yonit Halperin yhalp...@redhat.com

QXLWorker-start/stop are deprecated since spice-server 0.11.2

Signed-off-by: Yonit Halperin yhalp...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/qxl.c   |7 ---
 ui/spice-core.c|4 
 ui/spice-display.c |   32 ++--
 ui/spice-display.h |9 +++--
 4 files changed, 45 insertions(+), 7 deletions(-)

diff --git a/hw/qxl.c b/hw/qxl.c
index c2dd3b4..95bbc03 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -958,9 +958,10 @@ static void qxl_update_irq(PCIQXLDevice *d)
 static void qxl_check_state(PCIQXLDevice *d)
 {
 QXLRam *ram = d-ram;
+int spice_display_running = qemu_spice_display_is_running(d-ssd);
 
-assert(!d-ssd.running || SPICE_RING_IS_EMPTY(ram-cmd_ring));
-assert(!d-ssd.running || SPICE_RING_IS_EMPTY(ram-cursor_ring));
+assert(!spice_display_running || SPICE_RING_IS_EMPTY(ram-cmd_ring));
+assert(!spice_display_running || SPICE_RING_IS_EMPTY(ram-cursor_ring));
 }
 
 static void qxl_reset_state(PCIQXLDevice *d)
@@ -1538,7 +1539,7 @@ static void qxl_send_events(PCIQXLDevice *d, uint32_t 
events)
 uint32_t old_pending;
 uint32_t le_events = cpu_to_le32(events);
 
-assert(d-ssd.running);
+assert(qemu_spice_display_is_running(d-ssd));
 old_pending = __sync_fetch_and_or(d-ram-int_pending, le_events);
 if ((old_pending  le_events) == le_events) {
 return;
diff --git a/ui/spice-core.c b/ui/spice-core.c
index a515c94..1a7a773 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -37,6 +37,7 @@
 #include migration.h
 #include monitor.h
 #include hw/hw.h
+#include spice-display.h
 
 /* core bits */
 
@@ -551,9 +552,11 @@ static void vm_change_state_handler(void *opaque, int 
running,
 {
 #if SPICE_SERVER_VERSION = 0x000b02 /* 0.11.2 */
 if (running) {
+qemu_spice_display_start();
 spice_server_vm_start(spice_server);
 } else {
 spice_server_vm_stop(spice_server);
+qemu_spice_display_stop();
 }
 #endif
 }
@@ -755,6 +758,7 @@ int qemu_spice_add_interface(SpiceBaseInstance *sin)
 spice_server = spice_server_new();
 spice_server_init(spice_server, core_interface);
 }
+
 return spice_server_add_interface(spice_server, sin);
 }
 
diff --git a/ui/spice-display.c b/ui/spice-display.c
index 3e8f0b3..1c31418 100644
--- a/ui/spice-display.c
+++ b/ui/spice-display.c
@@ -126,18 +126,44 @@ void qemu_spice_wakeup(SimpleSpiceDisplay *ssd)
 ssd-worker-wakeup(ssd-worker);
 }
 
-void qemu_spice_start(SimpleSpiceDisplay *ssd)
+#if SPICE_SERVER_VERSION  0x000b02 /* before 0.11.2 */
+static void qemu_spice_start(SimpleSpiceDisplay *ssd)
 {
 trace_qemu_spice_start(ssd-qxl.id);
 ssd-worker-start(ssd-worker);
 }
 
-void qemu_spice_stop(SimpleSpiceDisplay *ssd)
+static void qemu_spice_stop(SimpleSpiceDisplay *ssd)
 {
 trace_qemu_spice_stop(ssd-qxl.id);
 ssd-worker-stop(ssd-worker);
 }
 
+#else
+
+static int spice_display_is_running;
+
+void qemu_spice_display_start(void)
+{
+spice_display_is_running = true;
+}
+
+void qemu_spice_display_stop(void)
+{
+spice_display_is_running = false;
+}
+
+#endif
+
+int qemu_spice_display_is_running(SimpleSpiceDisplay *ssd)
+{
+#if SPICE_SERVER_VERSION  0x000b02 /* before 0.11.2 */
+return ssd-running;
+#else
+return spice_display_is_running;
+#endif
+}
+
 static SimpleSpiceUpdate *qemu_spice_create_update(SimpleSpiceDisplay *ssd)
 {
 SimpleSpiceUpdate *update;
@@ -272,6 +298,7 @@ void qemu_spice_destroy_host_primary(SimpleSpiceDisplay 
*ssd)
 void qemu_spice_vm_change_state_handler(void *opaque, int running,
 RunState state)
 {
+#if SPICE_SERVER_VERSION  0x000b02 /* before 0.11.2 */
 SimpleSpiceDisplay *ssd = opaque;
 
 if (running) {
@@ -281,6 +308,7 @@ void qemu_spice_vm_change_state_handler(void *opaque, int 
running,
 qemu_spice_stop(ssd);
 ssd-running = false;
 }
+#endif
 }
 
 void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd, DisplayState *ds)
diff --git a/ui/spice-display.h b/ui/spice-display.h
index 12e50b6..672d65e 100644
--- a/ui/spice-display.h
+++ b/ui/spice-display.h
@@ -82,7 +82,9 @@ struct SimpleSpiceDisplay {
 
 QXLRect dirty;
 int notify;
+#if SPICE_SERVER_VERSION  0x000b02 /* before 0.11.2 */
 int running;
+#endif
 
 /*
  * All struct members below this comment can be accessed from
@@ -129,5 +131,8 @@ void qemu_spice_create_primary_surface(SimpleSpiceDisplay 
*ssd, uint32_t id,
 void qemu_spice_destroy_primary_surface(SimpleSpiceDisplay *ssd,
 uint32_t id, qxl_async_io async);
 void qemu_spice_wakeup(SimpleSpiceDisplay *ssd);
-void qemu_spice_start(SimpleSpiceDisplay *ssd);
-void qemu_spice_stop(SimpleSpiceDisplay *ssd);
+#if SPICE_SERVER_VERSION = 0x000b02 /* before 0.11.2 */
+void qemu_spice_display_start(void);
+void qemu_spice_display_stop(void);
+#endif
+int 

[Qemu-devel] [PATCH 4/4] wakeup: uhci support

2012-09-06 Thread Gerd Hoffmann
Implement the (intel-specific) pci configuration register 0xc4, which is
a bitmask saying which ports are allowed to wakeup the system.

Also assign gpe bit 0x0b (used only in case uhci handles device 01.2).

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-uhci.c |   35 +++
 1 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/hw/usb/hcd-uhci.c b/hw/usb/hcd-uhci.c
index b0db921..cc0e2de 100644
--- a/hw/usb/hcd-uhci.c
+++ b/hw/usb/hcd-uhci.c
@@ -32,6 +32,7 @@
 #include iov.h
 #include dma.h
 #include trace.h
+#include sysemu.h
 
 //#define DEBUG
 //#define DEBUG_DUMP_DATA
@@ -129,6 +130,7 @@ struct UHCIState {
 uint32_t fl_base_addr; /* frame list base address */
 uint8_t sof_timing;
 uint8_t status2; /* bit 0 and 1 are used to generate UHCI_STS_USBINT */
+uint8_t system_wakeup;
 int64_t expire_time;
 QEMUTimer *frame_timer;
 QEMUBH *bh;
@@ -677,6 +679,22 @@ static void uhci_wakeup(USBPort *port1)
 }
 }
 
+static void uhci_wakeup_endpoint(USBBus *bus, USBEndpoint *ep)
+{
+USBPort *port1 = ep-dev-port;
+UHCIState *s = port1-opaque;
+
+if (!(s-system_wakeup  (1  port1-index))) {
+return;
+}
+if (s-dev.devfn == PCI_DEVFN(1, 2)) {
+/* piix3/4 chipset uhci controller */
+qemu_system_wakeup_request(QEMU_WAKEUP_REASON_GPE_b);
+} else {
+qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
+}
+}
+
 static USBDevice *uhci_find_device(UHCIState *s, uint8_t addr)
 {
 USBDevice *dev;
@@ -1209,6 +1227,7 @@ static USBPortOps uhci_port_ops = {
 };
 
 static USBBusOps uhci_bus_ops = {
+.wakeup_endpoint = uhci_wakeup_endpoint,
 };
 
 static int usb_uhci_common_initfn(PCIDevice *dev)
@@ -1270,6 +1289,17 @@ static int usb_uhci_common_initfn(PCIDevice *dev)
 return 0;
 }
 
+static void usb_uhci_intel_write_config(PCIDevice *dev, uint32_t addr,
+uint32_t val, int len)
+{
+UHCIState *s = DO_UPCAST(UHCIState, dev, dev);
+
+pci_default_write_config(dev, addr, val, len);
+if (addr == 0xc4) {
+s-system_wakeup = val;
+}
+}
+
 static int usb_uhci_vt82c686b_initfn(PCIDevice *dev)
 {
 UHCIState *s = DO_UPCAST(UHCIState, dev, dev);
@@ -1306,6 +1336,7 @@ static void piix3_uhci_class_init(ObjectClass *klass, 
void *data)
 
 k-init = usb_uhci_common_initfn;
 k-exit = usb_uhci_exit;
+k-config_write = usb_uhci_intel_write_config;
 k-vendor_id = PCI_VENDOR_ID_INTEL;
 k-device_id = PCI_DEVICE_ID_INTEL_82371SB_2;
 k-revision = 0x01;
@@ -1328,6 +1359,7 @@ static void piix4_uhci_class_init(ObjectClass *klass, 
void *data)
 
 k-init = usb_uhci_common_initfn;
 k-exit = usb_uhci_exit;
+k-config_write = usb_uhci_intel_write_config;
 k-vendor_id = PCI_VENDOR_ID_INTEL;
 k-device_id = PCI_DEVICE_ID_INTEL_82371AB_2;
 k-revision = 0x01;
@@ -1371,6 +1403,7 @@ static void ich9_uhci1_class_init(ObjectClass *klass, 
void *data)
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
 k-init = usb_uhci_common_initfn;
+k-config_write = usb_uhci_intel_write_config;
 k-vendor_id = PCI_VENDOR_ID_INTEL;
 k-device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI1;
 k-revision = 0x03;
@@ -1392,6 +1425,7 @@ static void ich9_uhci2_class_init(ObjectClass *klass, 
void *data)
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
 k-init = usb_uhci_common_initfn;
+k-config_write = usb_uhci_intel_write_config;
 k-vendor_id = PCI_VENDOR_ID_INTEL;
 k-device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI2;
 k-revision = 0x03;
@@ -1413,6 +1447,7 @@ static void ich9_uhci3_class_init(ObjectClass *klass, 
void *data)
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
 k-init = usb_uhci_common_initfn;
+k-config_write = usb_uhci_intel_write_config;
 k-vendor_id = PCI_VENDOR_ID_INTEL;
 k-device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI3;
 k-revision = 0x03;
-- 
1.7.1




[Qemu-devel] [PATCH 18/54] usb-redir: Don't delay handling of open events to a bottom half

2012-09-06 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

There is no need for this, and doing so means that a backend trying to
write immediately after an open event will see qemu_chr_be_can_write
returning 0, which not all backends handle well as there is no wakeup
mechanism to detect when the frontend does become writable.

Signed-off-by: Hans de Goede hdego...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/redirect.c |  100 -
 1 files changed, 53 insertions(+), 47 deletions(-)

diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index 7f3719b..5cc3334 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -79,8 +79,8 @@ struct USBRedirDevice {
 /* Data passed from chardev the fd_read cb to the usbredirparser read cb */
 const uint8_t *read_buf;
 int read_buf_size;
-/* For async handling of open/close */
-QEMUBH *open_close_bh;
+/* For async handling of close */
+QEMUBH *chardev_close_bh;
 /* To delay the usb attach in case of quick chardev close + open */
 QEMUTimer *attach_timer;
 int64_t next_attach_time;
@@ -784,18 +784,11 @@ static int usbredir_handle_control(USBDevice *udev, 
USBPacket *p,
  * from within the USBDevice data / control packet callbacks and doing a
  * usb_detach from within these callbacks is not a good idea.
  *
- * So we use a bh handler to take care of close events. We also handle
- * open events from this callback to make sure that a close directly followed
- * by an open gets handled in the right order.
+ * So we use a bh handler to take care of close events.
  */
-static void usbredir_open_close_bh(void *opaque)
+static void usbredir_chardev_close_bh(void *opaque)
 {
 USBRedirDevice *dev = opaque;
-uint32_t caps[USB_REDIR_CAPS_SIZE] = { 0, };
-char version[32];
-
-strcpy(version, qemu usb-redir guest );
-pstrcat(version, sizeof(version), qemu_get_version());
 
 usbredir_device_disconnect(dev);
 
@@ -803,36 +796,47 @@ static void usbredir_open_close_bh(void *opaque)
 usbredirparser_destroy(dev-parser);
 dev-parser = NULL;
 }
+}
 
-if (dev-cs-opened) {
-dev-parser = qemu_oom_check(usbredirparser_create());
-dev-parser-priv = dev;
-dev-parser-log_func = usbredir_log;
-dev-parser-read_func = usbredir_read;
-dev-parser-write_func = usbredir_write;
-dev-parser-hello_func = usbredir_hello;
-dev-parser-device_connect_func = usbredir_device_connect;
-dev-parser-device_disconnect_func = usbredir_device_disconnect;
-dev-parser-interface_info_func = usbredir_interface_info;
-dev-parser-ep_info_func = usbredir_ep_info;
-dev-parser-configuration_status_func = usbredir_configuration_status;
-dev-parser-alt_setting_status_func = usbredir_alt_setting_status;
-dev-parser-iso_stream_status_func = usbredir_iso_stream_status;
-dev-parser-interrupt_receiving_status_func =
-usbredir_interrupt_receiving_status;
-dev-parser-bulk_streams_status_func = usbredir_bulk_streams_status;
-dev-parser-control_packet_func = usbredir_control_packet;
-dev-parser-bulk_packet_func = usbredir_bulk_packet;
-dev-parser-iso_packet_func = usbredir_iso_packet;
-dev-parser-interrupt_packet_func = usbredir_interrupt_packet;
-dev-read_buf = NULL;
-dev-read_buf_size = 0;
+static void usbredir_chardev_open(USBRedirDevice *dev)
+{
+uint32_t caps[USB_REDIR_CAPS_SIZE] = { 0, };
+char version[32];
 
-usbredirparser_caps_set_cap(caps, 
usb_redir_cap_connect_device_version);
-usbredirparser_caps_set_cap(caps, usb_redir_cap_filter);
-usbredirparser_init(dev-parser, version, caps, USB_REDIR_CAPS_SIZE, 
0);
-usbredirparser_do_write(dev-parser);
-}
+/* Make sure any pending closes are handled (no-op if none pending) */
+usbredir_chardev_close_bh(dev);
+qemu_bh_cancel(dev-chardev_close_bh);
+
+strcpy(version, qemu usb-redir guest );
+pstrcat(version, sizeof(version), qemu_get_version());
+
+dev-parser = qemu_oom_check(usbredirparser_create());
+dev-parser-priv = dev;
+dev-parser-log_func = usbredir_log;
+dev-parser-read_func = usbredir_read;
+dev-parser-write_func = usbredir_write;
+dev-parser-hello_func = usbredir_hello;
+dev-parser-device_connect_func = usbredir_device_connect;
+dev-parser-device_disconnect_func = usbredir_device_disconnect;
+dev-parser-interface_info_func = usbredir_interface_info;
+dev-parser-ep_info_func = usbredir_ep_info;
+dev-parser-configuration_status_func = usbredir_configuration_status;
+dev-parser-alt_setting_status_func = usbredir_alt_setting_status;
+dev-parser-iso_stream_status_func = usbredir_iso_stream_status;
+dev-parser-interrupt_receiving_status_func =
+usbredir_interrupt_receiving_status;
+dev-parser-bulk_streams_status_func = 

[Qemu-devel] [PATCH 06/14] spice: adding seamless-migration option to the command line

2012-09-06 Thread Gerd Hoffmann
From: Yonit Halperin yhalp...@redhat.com

The seamless-migration flag is required in order to identify
whether libvirt supports the new QEVENT_SPICE_MIGRATE_COMPLETED or not
(by default the flag is off).
New libvirt versions that wait for QEVENT_SPICE_MIGRATE_COMPLETED should turn 
on this flag.
When this flag is off, spice fallbacks to its old migration method, which
can result in data loss.

Signed-off-by: Yonit Halperin yhalp...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 qemu-config.c   |3 +++
 qemu-options.hx |3 +++
 ui/spice-core.c |7 +++
 3 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/qemu-config.c b/qemu-config.c
index c05ffbc..eba977e 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -537,6 +537,9 @@ QemuOptsList qemu_spice_opts = {
 },{
 .name = playback-compression,
 .type = QEMU_OPT_BOOL,
+}, {
+.name = seamless-migration,
+.type = QEMU_OPT_BOOL,
 },
 { /* end of list */ }
 },
diff --git a/qemu-options.hx b/qemu-options.hx
index 3c411c4..96a7bb1 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -920,6 +920,9 @@ Enable/disable passing mouse events via vdagent.  Default 
is on.
 @item playback-compression=[on|off]
 Enable/disable audio stream compression (using celt 0.5.1).  Default is on.
 
+@item seamless-migration=[on|off]
+Enable/disable spice seamless migration. Default is off.
+
 @end table
 ETEXI
 
diff --git a/ui/spice-core.c b/ui/spice-core.c
index ab069c5..ba0d0bd 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -585,6 +585,9 @@ void qemu_spice_init(void)
 int port, tls_port, len, addr_flags;
 spice_image_compression_t compression;
 spice_wan_compression_t wan_compr;
+#if SPICE_SERVER_VERSION = 0x000b02 /* 0.11.2 */
+bool seamless_migration;
+#endif
 
 qemu_thread_get_self(me);
 
@@ -728,6 +731,10 @@ void qemu_spice_init(void)
 spice_server_set_uuid(spice_server, qemu_uuid);
 #endif
 
+#if SPICE_SERVER_VERSION = 0x000b02 /* 0.11.2 */
+seamless_migration = qemu_opt_get_bool(opts, seamless-migration, 0);
+spice_server_set_seamless_migration(spice_server, seamless_migration);
+#endif
 if (0 != spice_server_init(spice_server, core_interface)) {
 error_report(failed to initialize spice server);
 exit(1);
-- 
1.7.1




[Qemu-devel] [PATCH 09/54] ehci: Properly report completed but not yet processed packets to the guest

2012-09-06 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

Reported packets which have completed before being cancelled as such to the
host. Note that the new code path this patch adds is untested since it I've
been unable to actually trigger the race which needs this code path.

Signed-off-by: Hans de Goede hdego...@redhat.com
---
 hw/usb/hcd-ehci.c |   13 +
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 4fe85c8..0a6c9ef 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -489,6 +489,9 @@ static const char *ehci_mmio_names[] = {
 [CONFIGFLAG]= CONFIGFLAG,
 };
 
+static int ehci_state_executing(EHCIQueue *q);
+static int ehci_state_writeback(EHCIQueue *q);
+
 static const char *nr2str(const char **n, size_t len, uint32_t nr)
 {
 if (nr  len  n[nr] != NULL) {
@@ -750,6 +753,16 @@ static void ehci_free_packet(EHCIPacket *p)
 usb_packet_unmap(p-packet, p-sgl);
 qemu_sglist_destroy(p-sgl);
 }
+if (p-async == EHCI_ASYNC_FINISHED) {
+int state = ehci_get_state(p-queue-ehci, p-queue-async);
+/* This is a normal, but rare condition (cancel racing completion) */
+fprintf(stderr, EHCI: Warning packet completed but not processed\n);
+ehci_state_executing(p-queue);
+ehci_state_writeback(p-queue);
+ehci_set_state(p-queue-ehci, p-queue-async, state);
+/* state_writeback recurses into us with async == EHCI_ASYNC_NONE!! */
+return;
+}
 QTAILQ_REMOVE(p-queue-packets, p, next);
 usb_packet_cleanup(p-packet);
 g_free(p);
-- 
1.7.1




[Qemu-devel] [PATCH 49/54] xhci: add XHCIInterrupter

2012-09-06 Thread Gerd Hoffmann
Move all state belonging to the (single) interrupter into a separate
struct.  First step in adding support for multiple interrupters.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-xhci.c |  307 -
 trace-events  |2 +-
 2 files changed, 161 insertions(+), 148 deletions(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index e39fe04..ddc3825 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -378,6 +378,27 @@ typedef struct XHCIEvent {
 uint8_t epid;
 } XHCIEvent;
 
+typedef struct XHCIInterrupter {
+uint32_t iman;
+uint32_t imod;
+uint32_t erstsz;
+uint32_t erstba_low;
+uint32_t erstba_high;
+uint32_t erdp_low;
+uint32_t erdp_high;
+
+bool msix_used, er_pcs, er_full;
+
+dma_addr_t er_start;
+uint32_t er_size;
+unsigned int er_ep_idx;
+
+XHCIEvent ev_buffer[EV_QUEUE];
+unsigned int ev_buffer_put;
+unsigned int ev_buffer_get;
+
+} XHCIInterrupter;
+
 struct XHCIState {
 PCIDevice pci_dev;
 USBBus bus;
@@ -407,27 +428,9 @@ struct XHCIState {
 uint32_t numports;
 
 /* Runtime Registers */
-uint32_t iman;
-uint32_t imod;
-uint32_t erstsz;
-uint32_t erstba_low;
-uint32_t erstba_high;
-uint32_t erdp_low;
-uint32_t erdp_high;
-bool msix_used;
-
 int64_t mfindex_start;
 QEMUTimer *mfwrap_timer;
-
-dma_addr_t er_start;
-uint32_t er_size;
-bool er_pcs;
-unsigned int er_ep_idx;
-bool er_full;
-
-XHCIEvent ev_buffer[EV_QUEUE];
-unsigned int ev_buffer_put;
-unsigned int ev_buffer_get;
+XHCIInterrupter intr[MAXINTRS];
 
 XHCIRing cmd_ring;
 };
@@ -446,8 +449,8 @@ enum xhci_flags {
 
 static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
  unsigned int epid);
-static void xhci_event(XHCIState *xhci, XHCIEvent *event);
-static void xhci_write_event(XHCIState *xhci, XHCIEvent *event);
+static void xhci_event(XHCIState *xhci, XHCIEvent *event, int v);
+static void xhci_write_event(XHCIState *xhci, XHCIEvent *event, int v);
 
 static const char *TRBType_names[] = {
 [TRB_RESERVED] = TRB_RESERVED,
@@ -573,7 +576,7 @@ static void xhci_mfwrap_timer(void *opaque)
 XHCIState *xhci = opaque;
 XHCIEvent wrap = { ER_MFINDEX_WRAP, CC_SUCCESS };
 
-xhci_event(xhci, wrap);
+xhci_event(xhci, wrap, 0);
 xhci_mfwrap_update(xhci);
 }
 
@@ -626,8 +629,8 @@ static void xhci_intx_update(XHCIState *xhci)
 return;
 }
 
-if (xhci-iman  IMAN_IP 
-xhci-iman  IMAN_IE 
+if (xhci-intr[0].iman  IMAN_IP 
+xhci-intr[0].iman  IMAN_IE 
 xhci-usbcmd  USBCMD_INTE) {
 level = 1;
 }
@@ -636,7 +639,7 @@ static void xhci_intx_update(XHCIState *xhci)
 qemu_set_irq(xhci-irq, level);
 }
 
-static void xhci_msix_update(XHCIState *xhci)
+static void xhci_msix_update(XHCIState *xhci, int v)
 {
 bool enabled;
 
@@ -644,29 +647,29 @@ static void xhci_msix_update(XHCIState *xhci)
 return;
 }
 
-enabled = xhci-iman  IMAN_IE;
-if (enabled == xhci-msix_used) {
+enabled = xhci-intr[v].iman  IMAN_IE;
+if (enabled == xhci-intr[v].msix_used) {
 return;
 }
 
 if (enabled) {
-trace_usb_xhci_irq_msix_use(0);
-msix_vector_use(xhci-pci_dev, 0);
-xhci-msix_used = true;
+trace_usb_xhci_irq_msix_use(v);
+msix_vector_use(xhci-pci_dev, v);
+xhci-intr[v].msix_used = true;
 } else {
-trace_usb_xhci_irq_msix_unuse(0);
-msix_vector_unuse(xhci-pci_dev, 0);
-xhci-msix_used = false;
+trace_usb_xhci_irq_msix_unuse(v);
+msix_vector_unuse(xhci-pci_dev, v);
+xhci-intr[v].msix_used = false;
 }
 }
 
-static void xhci_intr_raise(XHCIState *xhci)
+static void xhci_intr_raise(XHCIState *xhci, int v)
 {
-xhci-erdp_low |= ERDP_EHB;
-xhci-iman |= IMAN_IP;
+xhci-intr[v].erdp_low |= ERDP_EHB;
+xhci-intr[v].iman |= IMAN_IP;
 xhci-usbsts |= USBSTS_EINT;
 
-if (!(xhci-iman  IMAN_IE)) {
+if (!(xhci-intr[v].iman  IMAN_IE)) {
 return;
 }
 
@@ -675,24 +678,26 @@ static void xhci_intr_raise(XHCIState *xhci)
 }
 
 if (msix_enabled(xhci-pci_dev)) {
-trace_usb_xhci_irq_msix(0);
-msix_notify(xhci-pci_dev, 0);
+trace_usb_xhci_irq_msix(v);
+msix_notify(xhci-pci_dev, v);
 return;
 }
 
 if (msi_enabled(xhci-pci_dev)) {
-trace_usb_xhci_irq_msi(0);
-msi_notify(xhci-pci_dev, 0);
+trace_usb_xhci_irq_msi(v);
+msi_notify(xhci-pci_dev, v);
 return;
 }
 
-trace_usb_xhci_irq_intx(1);
-qemu_set_irq(xhci-irq, 1);
+if (v == 0) {
+trace_usb_xhci_irq_intx(1);
+qemu_set_irq(xhci-irq, 1);
+}
 }
 
 static inline int xhci_running(XHCIState *xhci)
 {
-return !(xhci-usbsts  USBSTS_HCH)  !xhci-er_full;
+return !(xhci-usbsts  USBSTS_HCH)  

Re: [Qemu-devel] [PATCH v6 2/2] block: Support GlusterFS as a QEMU block backend

2012-09-06 Thread Avi Kivity
On 08/14/2012 12:58 PM, Kevin Wolf wrote:
 
 While we are at this, let me bring out another issue. Gluster supports 3
 transport types:
 
 - socket in which case the server will be hostname, ipv4 or ipv4 address.
 - rdma in which case server will be interpreted similar to socket.
 - unix in which case server will be a path to unix domain socket and this
   will look like any other filesystem path. (Eg. /tmp/glusterd.socket)
 
 I don't think we can fit 'unix' within the standard URI scheme (RFC 3986)
 easily, but I am planning to specify the 'unix' transport as below:
 
 gluster://[/path/to/unix/domain/socket]/volname/image?transport=unix
 
 i,e., I am asking the user to put the unix domain socket path within
 square brackets when transport type is unix.
 
 Do you think this is fine ?
 
 Never saw something like this before, but it does seem reasonable to me.
 Excludes ] from the valid characters in the file name of the socket, but
 that shouldn't be a problem in practice.

Bikeshedding, but I prefer

  gluster:///path/to/unix/domain/socket:/volname/image?transport=unix

as being more similar to file://, or even

  gluster:///path/to/unix/domain/socket/volname/image?transport=unix

with the last two components implied to be part of the payload, not the
path.

-- 
error compiling committee.c: too many arguments to function



[Qemu-devel] [PATCH 20/54] usb-redir: Get rid of local shadow copy of packet headers

2012-09-06 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

The shadow copy only serves as an extra check (besides the packet-id) to
ensure the packet we get back is a reply to the packet we think it is.

This check has never triggered in all the time usb-redir is in use now,
and since the verified data in the returned packet-header is not used
otherwise, removing the check does not open any possibilities for the
usbredirhost to confuse us.

This is a preparation patch for completely getting rid of the async-packet
struct in usb-redir, instead relying on the (new) per ep queues in the
qemu usb core.

Signed-off-by: Hans de Goede hdego...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/redirect.c |   27 ---
 1 files changed, 0 insertions(+), 27 deletions(-)

diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index 2cae8c5..e4ef372 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -99,11 +99,6 @@ struct AsyncURB {
 USBRedirDevice *dev;
 USBPacket *packet;
 uint32_t packet_id;
-union {
-struct usb_redir_control_packet_header control_packet;
-struct usb_redir_bulk_packet_header bulk_packet;
-struct usb_redir_interrupt_packet_header interrupt_packet;
-};
 QTAILQ_ENTRY(AsyncURB)next;
 };
 
@@ -500,7 +495,6 @@ static int usbredir_handle_bulk_data(USBRedirDevice *dev, 
USBPacket *p,
 bulk_packet.endpoint  = ep;
 bulk_packet.length= p-iov.size;
 bulk_packet.stream_id = 0;
-aurb-bulk_packet = bulk_packet;
 
 if (ep  USB_DIR_IN) {
 usbredirparser_send_bulk_packet(dev-parser, aurb-packet_id,
@@ -581,7 +575,6 @@ static int usbredir_handle_interrupt_data(USBRedirDevice 
*dev,
 
 interrupt_packet.endpoint  = ep;
 interrupt_packet.length= p-iov.size;
-aurb-interrupt_packet = interrupt_packet;
 
 usb_packet_copy(p, buf, p-iov.size);
 usbredir_log_data(dev, interrupt data out:, buf, p-iov.size);
@@ -762,7 +755,6 @@ static int usbredir_handle_control(USBDevice *udev, 
USBPacket *p,
 control_packet.value   = value;
 control_packet.index   = index;
 control_packet.length  = length;
-aurb-control_packet   = control_packet;
 
 if (control_packet.requesttype  USB_DIR_IN) {
 usbredirparser_send_control_packet(dev-parser, aurb-packet_id,
@@ -1326,14 +1318,6 @@ static void usbredir_control_packet(void *priv, uint32_t 
id,
 return;
 }
 
-aurb-control_packet.status = control_packet-status;
-aurb-control_packet.length = control_packet-length;
-if (memcmp(aurb-control_packet, control_packet,
-   sizeof(*control_packet))) {
-ERROR(return control packet mismatch, please report this!\n);
-len = USB_RET_NAK;
-}
-
 if (aurb-packet) {
 len = usbredir_handle_status(dev, control_packet-status, len);
 if (len  0) {
@@ -1371,12 +1355,6 @@ static void usbredir_bulk_packet(void *priv, uint32_t id,
 return;
 }
 
-if (aurb-bulk_packet.endpoint != bulk_packet-endpoint ||
-aurb-bulk_packet.stream_id != bulk_packet-stream_id) {
-ERROR(return bulk packet mismatch, please report this!\n);
-len = USB_RET_NAK;
-}
-
 if (aurb-packet) {
 len = usbredir_handle_status(dev, bulk_packet-status, len);
 if (len  0) {
@@ -1455,11 +1433,6 @@ static void usbredir_interrupt_packet(void *priv, 
uint32_t id,
 return;
 }
 
-if (aurb-interrupt_packet.endpoint != interrupt_packet-endpoint) {
-ERROR(return int packet mismatch, please report this!\n);
-len = USB_RET_NAK;
-}
-
 if (aurb-packet) {
 aurb-packet-result = usbredir_handle_status(dev,
interrupt_packet-status, len);
-- 
1.7.1




[Qemu-devel] [PATCH 34/54] xhci: implement mfindex

2012-09-06 Thread Gerd Hoffmann
Implement mfindex register and mfindex wrap event.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-xhci.c |   53 ++---
 1 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 303e1ac..9077cb3 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -380,8 +380,6 @@ struct XHCIState {
 XHCISlot slots[MAXSLOTS];
 
 /* Runtime Registers */
-uint32_t mfindex;
-/* note: we only support one interrupter */
 uint32_t iman;
 uint32_t imod;
 uint32_t erstsz;
@@ -390,6 +388,9 @@ struct XHCIState {
 uint32_t erdp_low;
 uint32_t erdp_high;
 
+int64_t mfindex_start;
+QEMUTimer *mfwrap_timer;
+
 dma_addr_t er_start;
 uint32_t er_size;
 bool er_pcs;
@@ -410,6 +411,11 @@ typedef struct XHCIEvRingSeg {
 uint32_t rsvd;
 } XHCIEvRingSeg;
 
+static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
+ unsigned int epid);
+static void xhci_event(XHCIState *xhci, XHCIEvent *event);
+static void xhci_write_event(XHCIState *xhci, XHCIEvent *event);
+
 static const char *TRBType_names[] = {
 [TRB_RESERVED] = TRB_RESERVED,
 [TR_NORMAL]= TR_NORMAL,
@@ -462,8 +468,36 @@ static const char *trb_name(XHCITRB *trb)
ARRAY_SIZE(TRBType_names));
 }
 
-static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
- unsigned int epid);
+static uint64_t xhci_mfindex_get(XHCIState *xhci)
+{
+int64_t now = qemu_get_clock_ns(vm_clock);
+return (now - xhci-mfindex_start) / 125000;
+}
+
+static void xhci_mfwrap_update(XHCIState *xhci)
+{
+const uint32_t bits = USBCMD_RS | USBCMD_EWE;
+uint32_t mfindex, left;
+int64_t now;
+
+if ((xhci-usbcmd  bits) == bits) {
+now = qemu_get_clock_ns(vm_clock);
+mfindex = ((now - xhci-mfindex_start) / 125000)  0x3fff;
+left = 0x4000 - mfindex;
+qemu_mod_timer(xhci-mfwrap_timer, now + left * 125000);
+} else {
+qemu_del_timer(xhci-mfwrap_timer);
+}
+}
+
+static void xhci_mfwrap_timer(void *opaque)
+{
+XHCIState *xhci = opaque;
+XHCIEvent wrap = { ER_MFINDEX_WRAP, CC_SUCCESS };
+
+xhci_event(xhci, wrap);
+xhci_mfwrap_update(xhci);
+}
 
 static inline dma_addr_t xhci_addr64(uint32_t low, uint32_t high)
 {
@@ -793,6 +827,7 @@ static void xhci_run(XHCIState *xhci)
 {
 trace_usb_xhci_run();
 xhci-usbsts = ~USBSTS_HCH;
+xhci-mfindex_start = qemu_get_clock_ns(vm_clock);
 }
 
 static void xhci_stop(XHCIState *xhci)
@@ -2050,7 +2085,6 @@ static void xhci_reset(DeviceState *dev)
 xhci_update_port(xhci, xhci-ports + i, 0);
 }
 
-xhci-mfindex = 0;
 xhci-iman = 0;
 xhci-imod = 0;
 xhci-erstsz = 0;
@@ -2064,6 +2098,9 @@ static void xhci_reset(DeviceState *dev)
 xhci-er_full = 0;
 xhci-ev_buffer_put = 0;
 xhci-ev_buffer_get = 0;
+
+xhci-mfindex_start = qemu_get_clock_ns(vm_clock);
+xhci_mfwrap_update(xhci);
 }
 
 static uint32_t xhci_cap_read(XHCIState *xhci, uint32_t reg)
@@ -2266,6 +2303,7 @@ static void xhci_oper_write(XHCIState *xhci, uint32_t 
reg, uint32_t val)
 xhci_stop(xhci);
 }
 xhci-usbcmd = val  0xc0f;
+xhci_mfwrap_update(xhci);
 if (val  USBCMD_HCRST) {
 xhci_reset(xhci-pci_dev.qdev);
 }
@@ -2317,8 +2355,7 @@ static uint32_t xhci_runtime_read(XHCIState *xhci, 
uint32_t reg)
 
 switch (reg) {
 case 0x00: /* MFINDEX */
-fprintf(stderr, xhci_runtime_read: MFINDEX not yet implemented\n);
-ret = xhci-mfindex;
+ret = xhci_mfindex_get(xhci)  0x3fff;
 break;
 case 0x20: /* IMAN */
 ret = xhci-iman;
@@ -2618,6 +2655,8 @@ static int usb_xhci_initfn(struct PCIDevice *dev)
 
 usb_xhci_init(xhci, dev-qdev);
 
+xhci-mfwrap_timer = qemu_new_timer_ns(vm_clock, xhci_mfwrap_timer, xhci);
+
 xhci-irq = xhci-pci_dev.irq[0];
 
 memory_region_init_io(xhci-mem, xhci_mem_ops, xhci,
-- 
1.7.1




Re: [Qemu-devel] [PATCH 12/18] savevm: add error parameter to qemu_loadvm_state()

2012-09-06 Thread Pavel Hrdina

On 08/30/2012 07:09 PM, Luiz Capitulino wrote:

On Wed, 15 Aug 2012 09:41:53 +0200
Pavel Hrdina phrd...@redhat.com wrote:


Signed-off-by: Pavel Hrdina phrd...@redhat.com
---
  migration.c |  2 +-
  savevm.c| 44 
  sysemu.h|  3 ++-
  3 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/migration.c b/migration.c
index ec2f267..f048faf 100644
--- a/migration.c
+++ b/migration.c
@@ -88,7 +88,7 @@ int qemu_start_incoming_migration(const char *uri, Error 
**errp)
  
  void process_incoming_migration(QEMUFile *f)

  {
-if (qemu_loadvm_state(f)  0) {
+if (qemu_loadvm_state(f, NULL)  0) {
  fprintf(stderr, load of migration failed\n);
  exit(0);
  }
diff --git a/savevm.c b/savevm.c
index 0d54115..500eb72 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1916,7 +1916,8 @@ typedef struct LoadStateEntry {
  int version_id;
  } LoadStateEntry;
  
-int qemu_loadvm_state(QEMUFile *f)

+int qemu_loadvm_state(QEMUFile *f,
+  Error **errp)
  {
  QLIST_HEAD(, LoadStateEntry) loadvm_handlers =
  QLIST_HEAD_INITIALIZER(loadvm_handlers);
@@ -1925,21 +1926,26 @@ int qemu_loadvm_state(QEMUFile *f)
  unsigned int v;
  int ret;
  
-if (qemu_savevm_state_blocked(NULL)) {

-return -EINVAL;
+if (qemu_savevm_state_blocked(errp)) {
+return -ENOTSUP;
  }
  
  v = qemu_get_be32(f);

-if (v != QEMU_VM_FILE_MAGIC)
+if (v != QEMU_VM_FILE_MAGIC) {
+error_set(errp, ERROR_CLASS_GENERIC_ERROR,
+  Unknown vm-state file magic);
  return -EINVAL;
+}
  
  v = qemu_get_be32(f);

  if (v == QEMU_VM_FILE_VERSION_COMPAT) {
-fprintf(stderr, SaveVM v2 format is obsolete and don't work 
anymore\n);
+error_set(errp, QERR_NOT_SUPPORTED);
  return -ENOTSUP;
  }
-if (v != QEMU_VM_FILE_VERSION)
+if (v != QEMU_VM_FILE_VERSION) {
+error_set(errp, QERR_NOT_SUPPORTED);
  return -ENOTSUP;
+}
  
  while ((section_type = qemu_get_byte(f)) != QEMU_VM_EOF) {

  uint32_t instance_id, version_id, section_id;
@@ -1961,15 +1967,18 @@ int qemu_loadvm_state(QEMUFile *f)
  /* Find savevm section */
  se = find_se(idstr, instance_id);
  if (se == NULL) {
-fprintf(stderr, Unknown savevm section or instance '%s' 
%d\n, idstr, instance_id);
+error_set(errp, ERROR_CLASS_GENERIC_ERROR,
+  Unknown savevm section or instance '%s' %d,
+  idstr, instance_id);
  ret = -EINVAL;
  goto out;
  }
  
  /* Validate version */

  if (version_id  se-version_id) {
-fprintf(stderr, savevm: unsupported version %d for '%s' 
v%d\n,
-version_id, idstr, se-version_id);
+error_set(errp, ERROR_CLASS_GENERIC_ERROR,
+  savevm: unsupported version %d for '%s' v%d,
+  version_id, idstr, se-version_id);
  ret = -EINVAL;
  goto out;
  }
@@ -1984,8 +1993,7 @@ int qemu_loadvm_state(QEMUFile *f)
  
  ret = vmstate_load(f, le-se, le-version_id);

  if (ret  0) {
-fprintf(stderr, qemu: warning: error while loading state for 
instance 0x%x of device '%s'\n,
-instance_id, idstr);
+error_set(errp, QERR_GENERIC_ERROR, ret);
  goto out;
  }
  break;
@@ -1999,20 +2007,21 @@ int qemu_loadvm_state(QEMUFile *f)
  }
  }
  if (le == NULL) {
-fprintf(stderr, Unknown savevm section %d\n, section_id);
+error_set(errp, ERROR_CLASS_GENERIC_ERROR,
+  Unknown savevm section %d, section_id);

You sure that this error message will be printed to the terminal? This has
to be done by the caller.


While loading snapshot yes, but while migrating no. I think, that we 
should rewrite migration error propagation too.



  ret = -EINVAL;
  goto out;
  }
  
  ret = vmstate_load(f, le-se, le-version_id);

  if (ret  0) {
-fprintf(stderr, qemu: warning: error while loading state section 
id %d\n,
-section_id);
+error_set(errp, QERR_GENERIC_ERROR, ret);
  goto out;
  }
  break;
  default:
-fprintf(stderr, Unknown savevm section type %d\n, section_type);
+error_set(errp, ERROR_CLASS_GENERIC_ERROR,
+  Unknown savevm section type %d, section_type);
  ret = -EINVAL;
  goto out;
  }
@@ -2030,6 +2039,9 @@ out:
  
  if (ret == 0) {

  ret = qemu_file_get_error(f);
+if (ret  0) 

Re: [Qemu-devel] [PATCH 01/18] qerror: introduce QERR_GENERIC_ERROR

2012-09-06 Thread Pavel Hrdina

On 08/30/2012 02:11 PM, Luiz Capitulino wrote:

On Wed, 15 Aug 2012 09:41:42 +0200
Pavel Hrdina phrd...@redhat.com wrote:


Signed-off-by: Pavel Hrdina phrd...@redhat.com
---
  qerror.h | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/qerror.h b/qerror.h
index d0a76a4..7e0bae7 100644
--- a/qerror.h
+++ b/qerror.h
@@ -120,6 +120,9 @@ void assert_no_error(Error *err);
  #define QERR_FEATURE_DISABLED \
  ERROR_CLASS_GENERIC_ERROR, The feature '%s' is not enabled
  
+#define QERR_GENERIC_ERROR \

+ERROR_CLASS_GENERIC_ERROR, An (Errno %d) error has occurred
+

You should use error_setg() instead:


I'll fix it for whole patch-series.


  http://lists.gnu.org/archive/html/qemu-devel/2012-08/msg04980.html

There usage examples in the series introducing it. It would be better
to wait for it to be merged before you use it though, as it's always
possible for people to ask for changes.


  #define QERR_INVALID_BLOCK_FORMAT \
  ERROR_CLASS_GENERIC_ERROR, Invalid block format '%s'
  





[Qemu-devel] [PATCH 13/14] qxl: Add set_client_capabilities() interface to QXLInterface

2012-09-06 Thread Gerd Hoffmann
From: Søren Sandmann Pedersen s...@redhat.com

This new interface lets spice server inform the guest whether

(a) a client is connected
(b) what capabilities the client has

There is a fixed number (464) of bits reserved for capabilities, and
when the capabilities bits change, the QXL_INTERRUPT_CLIENT interrupt
is generated.

Signed-off-by: Soren Sandmann s...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/qxl.c |   23 +++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/hw/qxl.c b/hw/qxl.c
index 8725f67..2aa5848 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -944,6 +944,26 @@ static void interface_async_complete(QXLInstance *sin, 
uint64_t cookie_token)
 }
 }
 
+#if SPICE_SERVER_VERSION = 0x000b04
+
+/* called from spice server thread context only */
+static void interface_set_client_capabilities(QXLInstance *sin,
+  uint8_t client_present,
+  uint8_t caps[58])
+{
+PCIQXLDevice *qxl = container_of(sin, PCIQXLDevice, ssd.qxl);
+
+qxl-shadow_rom.client_present = client_present;
+memcpy(qxl-shadow_rom.client_capabilities, caps, sizeof(caps));
+qxl-rom-client_present = client_present;
+memcpy(qxl-rom-client_capabilities, caps, sizeof(caps));
+qxl_rom_set_dirty(qxl);
+
+qxl_send_events(qxl, QXL_INTERRUPT_CLIENT);
+}
+
+#endif
+
 static const QXLInterface qxl_interface = {
 .base.type   = SPICE_INTERFACE_QXL,
 .base.description= qxl gpu,
@@ -965,6 +985,9 @@ static const QXLInterface qxl_interface = {
 .flush_resources = interface_flush_resources,
 .async_complete  = interface_async_complete,
 .update_area_complete= interface_update_area_complete,
+#if SPICE_SERVER_VERSION = 0x000b04
+.set_client_capabilities = interface_set_client_capabilities,
+#endif
 };
 
 static void qxl_enter_vga_mode(PCIQXLDevice *d)
-- 
1.7.1




[Qemu-devel] [PATCH 41/54] usb3: superspeed descriptors

2012-09-06 Thread Gerd Hoffmann
Add superspeed descriptor entry to USBDesc,
advertise superspeed support when present.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/desc.c |   10 +-
 hw/usb/desc.h |1 +
 2 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/hw/usb/desc.c b/hw/usb/desc.c
index 0a9d3c9..3e8c6cb 100644
--- a/hw/usb/desc.c
+++ b/hw/usb/desc.c
@@ -359,6 +359,9 @@ static void usb_desc_setdefaults(USBDevice *dev)
 case USB_SPEED_HIGH:
 dev-device = desc-high;
 break;
+case USB_SPEED_SUPER:
+dev-device = desc-super;
+break;
 }
 usb_desc_set_config(dev, 0);
 }
@@ -376,6 +379,9 @@ void usb_desc_init(USBDevice *dev)
 if (desc-high) {
 dev-speedmask |= USB_SPEED_MASK_HIGH;
 }
+if (desc-super) {
+dev-speedmask |= USB_SPEED_MASK_SUPER;
+}
 usb_desc_setdefaults(dev);
 }
 
@@ -384,7 +390,9 @@ void usb_desc_attach(USBDevice *dev)
 const USBDesc *desc = usb_device_get_usb_desc(dev);
 
 assert(desc != NULL);
-if (desc-high  (dev-port-speedmask  USB_SPEED_MASK_HIGH)) {
+if (desc-super  (dev-port-speedmask  USB_SPEED_MASK_SUPER)) {
+dev-speed = USB_SPEED_SUPER;
+} else if (desc-high  (dev-port-speedmask  USB_SPEED_MASK_HIGH)) {
 dev-speed = USB_SPEED_HIGH;
 } else if (desc-full  (dev-port-speedmask  USB_SPEED_MASK_FULL)) {
 dev-speed = USB_SPEED_FULL;
diff --git a/hw/usb/desc.h b/hw/usb/desc.h
index 7cf5442..d89fa41 100644
--- a/hw/usb/desc.h
+++ b/hw/usb/desc.h
@@ -152,6 +152,7 @@ struct USBDesc {
 USBDescID id;
 const USBDescDevice   *full;
 const USBDescDevice   *high;
+const USBDescDevice   *super;
 const char* const *str;
 };
 
-- 
1.7.1




[Qemu-devel] [PATCH 05/14] spice: add 'migrated' flag to spice info

2012-09-06 Thread Gerd Hoffmann
From: Yonit Halperin yhalp...@redhat.com

The flag is 'true' when spice migration has completed on the src side.
It is needed for a case where libvirt dies before migration completes
and it misses the event QEVENT_SPICE_MIGRATE_COMPLETED.
When libvirt is restored and queries the migration status, it also needs
to query spice and check if its migration has completed.

Signed-off-by: Yonit Halperin yhalp...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hmp.c|2 ++
 qapi-schema.json |5 -
 ui/spice-core.c  |4 
 3 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/hmp.c b/hmp.c
index 81c8acb..ec4274b 100644
--- a/hmp.c
+++ b/hmp.c
@@ -413,6 +413,8 @@ void hmp_info_spice(Monitor *mon)
 monitor_printf(mon,  address: %s:% PRId64  [tls]\n,
info-host, info-tls_port);
 }
+monitor_printf(mon, migrated: %s\n,
+   info-migrated ? true : false);
 monitor_printf(mon, auth: %s\n, info-auth);
 monitor_printf(mon, compiled: %s\n, info-compiled_version);
 monitor_printf(mon,   mouse-mode: %s\n,
diff --git a/qapi-schema.json b/qapi-schema.json
index bd8ad74..8ddde12 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -808,6 +808,9 @@
 #
 # @enabled: true if the SPICE server is enabled, false otherwise
 #
+# @migrated: true if the last guest migration completed and spice
+#migration had completed as well. false otherwise.
+#
 # @host: #optional The hostname the SPICE server is bound to.  This depends on
 #the name resolution on the host and may be an IP address.
 #
@@ -833,7 +836,7 @@
 # Since: 0.14.0
 ##
 { 'type': 'SpiceInfo',
-  'data': {'enabled': 'bool', '*host': 'str', '*port': 'int',
+  'data': {'enabled': 'bool', 'migrated': 'bool', '*host': 'str', '*port': 
'int',
'*tls-port': 'int', '*auth': 'str', '*compiled-version': 'str',
'mouse-mode': 'SpiceQueryMouseMode', '*channels': ['SpiceChannel']} 
}
 
diff --git a/ui/spice-core.c b/ui/spice-core.c
index 851e869..ab069c5 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -46,6 +46,7 @@ static Notifier migration_state;
 static const char *auth = spice;
 static char *auth_passwd;
 static time_t auth_expires = TIME_MAX;
+static int spice_migration_completed;
 int using_spice = 0;
 
 static QemuThread me;
@@ -310,6 +311,7 @@ static void 
migrate_connect_complete_cb(SpiceMigrateInstance *sin)
 static void migrate_end_complete_cb(SpiceMigrateInstance *sin)
 {
 monitor_protocol_event(QEVENT_SPICE_MIGRATE_COMPLETED, NULL);
+spice_migration_completed = true;
 }
 #endif
 
@@ -443,6 +445,7 @@ SpiceInfo *qmp_query_spice(Error **errp)
 }
 
 info-enabled = true;
+info-migrated = spice_migration_completed;
 
 addr = qemu_opt_get(opts, addr);
 port = qemu_opt_get_number(opts, port, 0);
@@ -496,6 +499,7 @@ static void migration_state_notifier(Notifier *notifier, 
void *data)
 #ifndef SPICE_INTERFACE_MIGRATION
 spice_server_migrate_switch(spice_server);
 monitor_protocol_event(QEVENT_SPICE_MIGRATE_COMPLETED, NULL);
+spice_migration_completed = true;
 #else
 spice_server_migrate_end(spice_server, true);
 } else if (migration_has_failed(s)) {
-- 
1.7.1




[Qemu-devel] [PATCH 02/54] usb-core: Don't set packet state to complete on a nak

2012-09-06 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

This way the hcd can re-use the same packet to retry without needing
to re-init it.

Signed-off-by: Hans de Goede hdego...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/core.c |6 --
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/hw/usb/core.c b/hw/usb/core.c
index 2da38e7..be6d936 100644
--- a/hw/usb/core.c
+++ b/hw/usb/core.c
@@ -399,8 +399,10 @@ int usb_handle_packet(USBDevice *dev, USBPacket *p)
  * otherwise packets can complete out of order!
  */
 assert(!p-ep-pipeline);
-p-result = ret;
-usb_packet_set_state(p, USB_PACKET_COMPLETE);
+if (ret != USB_RET_NAK) {
+p-result = ret;
+usb_packet_set_state(p, USB_PACKET_COMPLETE);
+}
 }
 } else {
 ret = USB_RET_ASYNC;
-- 
1.7.1




[Qemu-devel] [PATCH 08/14] qxl/update_area_io: guest_bug on invalid parameters

2012-09-06 Thread Gerd Hoffmann
From: Alon Levy al...@redhat.com

Signed-off-by: Alon Levy al...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/qxl.c |   12 
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/hw/qxl.c b/hw/qxl.c
index 95bbc03..baf9bb4 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -1386,6 +1386,18 @@ async_common:
 QXLCookie *cookie = NULL;
 QXLRect update = d-ram-update_area;
 
+if (d-ram-update_surface  NUM_SURFACES) {
+qxl_set_guest_bug(d, QXL_IO_UPDATE_AREA: invalid surface id %d\n,
+  d-ram-update_surface);
+return;
+}
+if (update.left = update.right || update.top = update.bottom) {
+qxl_set_guest_bug(d,
+QXL_IO_UPDATE_AREA: invalid area (%ux%u)x(%ux%u)\n,
+update.left, update.top, update.right, update.bottom);
+return;
+}
+
 if (async == QXL_ASYNC) {
 cookie = qxl_cookie_new(QXL_COOKIE_TYPE_IO,
 QXL_IO_UPDATE_AREA_ASYNC);
-- 
1.7.1




[Qemu-devel] [PATCH 52/54] xhci: support multiple interrupters

2012-09-06 Thread Gerd Hoffmann
Everything is in place, flip the big switch now
and enable support for multiple interrupters.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-xhci.c |6 +-
 1 files changed, 1 insertions(+), 5 deletions(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index d6ab0c6..55e31ec 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -42,7 +42,7 @@
 
 #define MAXPORTS (MAXPORTS_2+MAXPORTS_3)
 #define MAXSLOTS MAXPORTS
-#define MAXINTRS 1 /* MAXPORTS */
+#define MAXINTRS MAXPORTS
 
 #define TD_QUEUE 24
 
@@ -75,10 +75,6 @@
 # error Increase LEN_REGS
 #endif
 
-#if MAXINTRS  1
-# error TODO: only one interrupter supported
-#endif
-
 /* bit definitions */
 #define USBCMD_RS   (10)
 #define USBCMD_HCRST(11)
-- 
1.7.1




Re: [Qemu-devel] [PATCH v3 4/4] kvm: i386: Add classic PCI device assignment

2012-09-06 Thread Jan Kiszka
On 2012-08-30 20:30, Jan Kiszka wrote:
 This adds PCI device assignment for i386 targets using the classic KVM
 interfaces. This version is 100% identical to what is being maintained
 in qemu-kvm for several years and is supported by libvirt as well. It is
 expected to remain relevant for another couple of years until kernels
 without full-features and performance-wise equivalent VFIO support are
 obsolete.
 
 A refactoring to-do that should be done in-tree is to model MSI and
 MSI-X support via the generic PCI layer, similar to what VFIO is already
 doing for MSI-X. This should improve the correctness and clean up the
 code from duplicate logic.
 
 Signed-off-by: Jan Kiszka jan.kis...@siemens.com
 ---
 
 Changes in v3:
  - addressed comment by Peter (changed device name to kvm-pci-assign +
alias)
  - addressed (most) comments by Michael
  - fixed INT pin regression

Does someone _disagree_ that there are no open (and reasonably solvable)
issues and that this can now be merged through uq/master?

Jan

-- 
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux



Re: [Qemu-devel] [PATCH 4/4] kvm: i386: Add classic PCI device assignment

2012-09-06 Thread Avi Kivity
On 09/05/2012 10:04 PM, Blue Swirl wrote:

 Reinventing a disassembler for ever growing x86 assembly is
 no fun.

We can try linking to a disassembler library.  I use udis86 to
disassemble instructions in kvm tracepoints
(http://udis86.git.sourceforge.net/git/gitweb.cgi?p=udis86/udis86;a=shortlog),
it's maintained but not heavily so.

Of course for non-x86 we'd need to continue using binutils; this is
about copying code vs. libraries, not about licensing.


-- 
error compiling committee.c: too many arguments to function



[Qemu-devel] [PATCH 02/14] spice: notify spice server on vm start/stop

2012-09-06 Thread Gerd Hoffmann
From: Yonit Halperin yhalp...@redhat.com

Spice server needs to know about the vm state in order to prevent
attempts to write to devices when they are stopped, mainly during
the non-live stage of migration.
Instead, spice will take care of restoring this writes, on the migration
target side, after migration completes.

Signed-off-by: Yonit Halperin yhalp...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/spice-core.c |   14 ++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/ui/spice-core.c b/ui/spice-core.c
index bb4f585..a515c94 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -546,6 +546,18 @@ static int add_channel(const char *name, const char 
*value, void *opaque)
 return 0;
 }
 
+static void vm_change_state_handler(void *opaque, int running,
+RunState state)
+{
+#if SPICE_SERVER_VERSION = 0x000b02 /* 0.11.2 */
+if (running) {
+spice_server_vm_start(spice_server);
+} else {
+spice_server_vm_stop(spice_server);
+}
+#endif
+}
+
 void qemu_spice_init(void)
 {
 QemuOpts *opts = QTAILQ_FIRST(qemu_spice_opts.head);
@@ -719,6 +731,8 @@ void qemu_spice_init(void)
 qemu_spice_input_init();
 qemu_spice_audio_init();
 
+qemu_add_vm_change_state_handler(vm_change_state_handler, spice_server);
+
 g_free(x509_key_file);
 g_free(x509_cert_file);
 g_free(x509_cacert_file);
-- 
1.7.1




[Qemu-devel] [PATCH 17/54] usb-redir: Never return USB_RET_NAK for async handled packets

2012-09-06 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

USB_RET_NAK is not a valid response for async handled packets (and will
trigger an assert as such).

Also drop the warning when receiving a status of cancelled for packets not
cancelled by qemu itself, this can happen when a device gets unredirected
by the usbredir-host while transfers are pending.

Signed-off-by: Hans de Goede hdego...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/redirect.c |9 ++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index 10b4fbb..7f3719b 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -1028,11 +1028,14 @@ static int usbredir_handle_status(USBRedirDevice *dev,
 case usb_redir_stall:
 return USB_RET_STALL;
 case usb_redir_cancelled:
-WARNING(returning cancelled packet to HC?\n);
-return USB_RET_NAK;
+/*
+ * When the usbredir-host unredirects a device, it will report a status
+ * of cancelled for all pending packets, followed by a disconnect msg.
+ */
+return USB_RET_IOERROR;
 case usb_redir_inval:
 WARNING(got invalid param error from usb-host?\n);
-return USB_RET_NAK;
+return USB_RET_IOERROR;
 case usb_redir_babble:
 return USB_RET_BABBLE;
 case usb_redir_ioerror:
-- 
1.7.1




[Qemu-devel] [PATCH 54/54] xhci: allow bytewise capability register reads

2012-09-06 Thread Gerd Hoffmann
Some guests need this according to
Alejandro Martinez Ruiz a...@securiforest.com

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-xhci.c |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 500892d..2918e64 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -2748,8 +2748,10 @@ static void xhci_doorbell_write(void *ptr, 
target_phys_addr_t reg,
 
 static const MemoryRegionOps xhci_cap_ops = {
 .read = xhci_cap_read,
-.valid.min_access_size = 4,
+.valid.min_access_size = 1,
 .valid.max_access_size = 4,
+.impl.min_access_size = 4,
+.impl.max_access_size = 4,
 .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
-- 
1.7.1




[Qemu-devel] [PATCH 33/54] xhci: move device lookup into xhci_setup_packet

2012-09-06 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-xhci.c |   74 +++-
 1 files changed, 38 insertions(+), 36 deletions(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index c858b6d..303e1ac 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -1196,13 +1196,38 @@ static void xhci_stall_ep(XHCITransfer *xfer)
 static int xhci_submit(XHCIState *xhci, XHCITransfer *xfer,
XHCIEPContext *epctx);
 
-static int xhci_setup_packet(XHCITransfer *xfer, USBDevice *dev)
+static USBDevice *xhci_find_device(XHCIPort *port, uint8_t addr)
 {
+if (!(port-portsc  PORTSC_PED)) {
+return NULL;
+}
+return usb_find_device(port-port, addr);
+}
+
+static int xhci_setup_packet(XHCITransfer *xfer)
+{
+XHCIState *xhci = xfer-xhci;
+XHCIPort *port;
+USBDevice *dev;
 USBEndpoint *ep;
 int dir;
 
 dir = xfer-in_xfer ? USB_TOKEN_IN : USB_TOKEN_OUT;
-ep = usb_ep_get(dev, dir, xfer-epid  1);
+
+if (xfer-packet.ep) {
+ep = xfer-packet.ep;
+dev = ep-dev;
+} else {
+port = xhci-ports[xhci-slots[xfer-slotid-1].port-1];
+dev = xhci_find_device(port, xhci-slots[xfer-slotid-1].devaddr);
+if (!dev) {
+fprintf(stderr, xhci: slot %d port %d has no device\n,
+xfer-slotid, xhci-slots[xfer-slotid-1].port);
+return -1;
+}
+ep = usb_ep_get(dev, dir, xfer-epid  1);
+}
+
 usb_packet_setup(xfer-packet, dir, ep, xfer-trbs[0].addr);
 xhci_xfer_map(xfer);
 DPRINTF(xhci: setup packet pid 0x%x addr %d ep %d\n,
@@ -1260,21 +1285,11 @@ static int xhci_complete_packet(XHCITransfer *xfer, int 
ret)
 return 0;
 }
 
-static USBDevice *xhci_find_device(XHCIPort *port, uint8_t addr)
-{
-if (!(port-portsc  PORTSC_PED)) {
-return NULL;
-}
-return usb_find_device(port-port, addr);
-}
-
 static int xhci_fire_ctl_transfer(XHCIState *xhci, XHCITransfer *xfer)
 {
 XHCITRB *trb_setup, *trb_status;
 uint8_t bmRequestType;
 uint16_t wLength;
-XHCIPort *port;
-USBDevice *dev;
 int ret;
 
 trb_setup = xfer-trbs[0];
@@ -1311,21 +1326,15 @@ static int xhci_fire_ctl_transfer(XHCIState *xhci, 
XHCITransfer *xfer)
 bmRequestType = trb_setup-parameter;
 wLength = trb_setup-parameter  48;
 
-port = xhci-ports[xhci-slots[xfer-slotid-1].port-1];
-dev = xhci_find_device(port, xhci-slots[xfer-slotid-1].devaddr);
-if (!dev) {
-fprintf(stderr, xhci: slot %d port %d has no device\n, xfer-slotid,
-xhci-slots[xfer-slotid-1].port);
-return -1;
-}
-
 xfer-in_xfer = bmRequestType  USB_DIR_IN;
 xfer-iso_xfer = false;
 
-xhci_setup_packet(xfer, dev);
+if (xhci_setup_packet(xfer)  0) {
+return -1;
+}
 xfer-packet.parameter = trb_setup-parameter;
 
-ret = usb_handle_packet(dev, xfer-packet);
+ret = usb_handle_packet(xfer-packet.ep-dev, xfer-packet);
 
 xhci_complete_packet(xfer, ret);
 if (!xfer-running_async  !xfer-running_retry) {
@@ -1336,8 +1345,6 @@ static int xhci_fire_ctl_transfer(XHCIState *xhci, 
XHCITransfer *xfer)
 
 static int xhci_submit(XHCIState *xhci, XHCITransfer *xfer, XHCIEPContext 
*epctx)
 {
-XHCIPort *port;
-USBDevice *dev;
 int ret;
 
 DPRINTF(xhci_submit(slotid=%d,epid=%d)\n, xfer-slotid, xfer-epid);
@@ -1350,16 +1357,6 @@ static int xhci_submit(XHCIState *xhci, XHCITransfer 
*xfer, XHCIEPContext *epctx
 xfer-pkts = 0;
 }
 
-port = xhci-ports[xhci-slots[xfer-slotid-1].port-1];
-dev = xhci_find_device(port, xhci-slots[xfer-slotid-1].devaddr);
-if (!dev) {
-fprintf(stderr, xhci: slot %d port %d has no device\n, xfer-slotid,
-xhci-slots[xfer-slotid-1].port);
-return -1;
-}
-
-xhci_setup_packet(xfer, dev);
-
 switch(epctx-type) {
 case ET_INTR_OUT:
 case ET_INTR_IN:
@@ -1377,7 +1374,10 @@ static int xhci_submit(XHCIState *xhci, XHCITransfer 
*xfer, XHCIEPContext *epctx
 return -1;
 }
 
-ret = usb_handle_packet(dev, xfer-packet);
+if (xhci_setup_packet(xfer)  0) {
+return -1;
+}
+ret = usb_handle_packet(xfer-packet.ep-dev, xfer-packet);
 
 xhci_complete_packet(xfer, ret);
 if (!xfer-running_async  !xfer-running_retry) {
@@ -1420,7 +1420,9 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int 
slotid, unsigned int epid
 
 trace_usb_xhci_xfer_retry(xfer);
 assert(xfer-running_retry);
-xhci_setup_packet(xfer, xfer-packet.ep-dev);
+if (xhci_setup_packet(xfer)  0) {
+return;
+}
 result = usb_handle_packet(xfer-packet.ep-dev, xfer-packet);
 if (result == USB_RET_NAK) {
 return;
-- 
1.7.1




Re: [Qemu-devel] [PATCH v3 4/4] kvm: i386: Add classic PCI device assignment

2012-09-06 Thread Michael S. Tsirkin
On Thu, Sep 06, 2012 at 10:44:15AM +0200, Jan Kiszka wrote:
 On 2012-08-30 20:30, Jan Kiszka wrote:
  This adds PCI device assignment for i386 targets using the classic KVM
  interfaces. This version is 100% identical to what is being maintained
  in qemu-kvm for several years and is supported by libvirt as well. It is
  expected to remain relevant for another couple of years until kernels
  without full-features and performance-wise equivalent VFIO support are
  obsolete.
  
  A refactoring to-do that should be done in-tree is to model MSI and
  MSI-X support via the generic PCI layer, similar to what VFIO is already
  doing for MSI-X. This should improve the correctness and clean up the
  code from duplicate logic.
  
  Signed-off-by: Jan Kiszka jan.kis...@siemens.com
  ---
  
  Changes in v3:
   - addressed comment by Peter (changed device name to kvm-pci-assign +
 alias)
   - addressed (most) comments by Michael
   - fixed INT pin regression
 
 Does someone _disagree_ that there are no open (and reasonably solvable)
 issues and that this can now be merged through uq/master?
 
 Jan

Ugh this thread was shamelessly highjacked by coding style
bike-shedding. I am guilty to.
In hopes of making amends:

Acked-by: Michael S. Tsirkin m...@redhat.com

 -- 
 Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
 Corporate Competence Center Embedded Linux



[Qemu-devel] [PATCH 11/14] configure: print spice-protocol and spice-server versions

2012-09-06 Thread Gerd Hoffmann
From: Alon Levy al...@redhat.com

Signed-off-by: Alon Levy al...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 configure |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/configure b/configure
index 59521ea..9592095 100755
--- a/configure
+++ b/configure
@@ -2701,6 +2701,8 @@ EOF
 spice=yes
 libs_softmmu=$libs_softmmu $spice_libs
 QEMU_CFLAGS=$QEMU_CFLAGS $spice_cflags
+spice_protocol_version=$($pkg_config --modversion spice-protocol)
+spice_server_version=$($pkg_config --modversion spice-server)
 if $pkg_config --atleast-version=0.12.0 spice-protocol /dev/null 21; 
then
 spice_qxl_io_monitors_config_async=yes
 fi
@@ -3159,7 +3161,7 @@ echo libcap-ng support $cap_ng
 echo vhost-net support $vhost_net
 echo Trace backend $trace_backend
 echo Trace output file $trace_file-pid
-echo spice support $spice
+echo spice support $spice ($spice_protocol_version/$spice_server_version)
 echo rbd support   $rbd
 echo xfsctl support$xfs
 echo nss used  $smartcard_nss
-- 
1.7.1




[Qemu-devel] [PATCH 29/54] Better name usb braille device

2012-09-06 Thread Gerd Hoffmann
From: Samuel Thibault samuel.thiba...@ens-lyon.org

Windows users need to know that they have to use the Baum driver to make
the qemu braille device work.

Signed-off-by: Samuel Thibault samuel.thiba...@ens-lyon.org
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/dev-serial.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c
index 8aa6552..69b6e48 100644
--- a/hw/usb/dev-serial.c
+++ b/hw/usb/dev-serial.c
@@ -113,7 +113,7 @@ enum {
 static const USBDescStrings desc_strings = {
 [STR_MANUFACTURER]= QEMU,
 [STR_PRODUCT_SERIAL]  = QEMU USB SERIAL,
-[STR_PRODUCT_BRAILLE] = QEMU USB BRAILLE,
+[STR_PRODUCT_BRAILLE] = QEMU USB BAUM BRAILLE,
 [STR_SERIALNUMBER]= 1,
 };
 
-- 
1.7.1




[Qemu-devel] [PATCH 43/54] usb3: bos decriptor

2012-09-06 Thread Gerd Hoffmann
Add support for creating BOS descriptor and
device cappability descriptors.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb.h  |6 +++
 hw/usb/desc.c |  109 +
 hw/usb/desc.h |   25 +
 trace-events  |1 +
 4 files changed, 141 insertions(+), 0 deletions(-)

diff --git a/hw/usb.h b/hw/usb.h
index 78ffdf4..48c8926 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -135,10 +135,16 @@
 #define USB_DT_OTHER_SPEED_CONFIG   0x07
 #define USB_DT_DEBUG0x0A
 #define USB_DT_INTERFACE_ASSOC  0x0B
+#define USB_DT_BOS  0x0F
+#define USB_DT_DEVICE_CAPABILITY0x10
 #define USB_DT_CS_INTERFACE 0x24
 #define USB_DT_CS_ENDPOINT  0x25
 #define USB_DT_ENDPOINT_COMPANION   0x30
 
+#define USB_DEV_CAP_WIRELESS0x01
+#define USB_DEV_CAP_USB2_EXT0x02
+#define USB_DEV_CAP_SUPERSPEED  0x03
+
 #define USB_ENDPOINT_XFER_CONTROL  0
 #define USB_ENDPOINT_XFER_ISOC 1
 #define USB_ENDPOINT_XFER_BULK 2
diff --git a/hw/usb/desc.c b/hw/usb/desc.c
index 8f5a8e5..1f12eae 100644
--- a/hw/usb/desc.c
+++ b/hw/usb/desc.c
@@ -258,6 +258,111 @@ int usb_desc_other(const USBDescOther *desc, uint8_t 
*dest, size_t len)
 return bLength;
 }
 
+static int usb_desc_cap_usb2_ext(const USBDesc *desc, uint8_t *dest, size_t 
len)
+{
+uint8_t  bLength = 0x07;
+USBDescriptor *d = (void *)dest;
+
+if (len  bLength) {
+return -1;
+}
+
+d-bLength  = bLength;
+d-bDescriptorType  = USB_DT_DEVICE_CAPABILITY;
+d-u.cap.bDevCapabilityType = USB_DEV_CAP_USB2_EXT;
+
+d-u.cap.u.usb2_ext.bmAttributes_1  = (1  1);  /* LPM */
+d-u.cap.u.usb2_ext.bmAttributes_2  = 0;
+d-u.cap.u.usb2_ext.bmAttributes_3  = 0;
+d-u.cap.u.usb2_ext.bmAttributes_4  = 0;
+
+return bLength;
+}
+
+static int usb_desc_cap_super(const USBDesc *desc, uint8_t *dest, size_t len)
+{
+uint8_t  bLength = 0x0a;
+USBDescriptor *d = (void *)dest;
+
+if (len  bLength) {
+return -1;
+}
+
+d-bLength   = bLength;
+d-bDescriptorType   = USB_DT_DEVICE_CAPABILITY;
+d-u.cap.bDevCapabilityType  = USB_DEV_CAP_SUPERSPEED;
+
+d-u.cap.u.super.bmAttributes= 0;
+d-u.cap.u.super.wSpeedsSupported_lo = 0;
+d-u.cap.u.super.wSpeedsSupported_hi = 0;
+d-u.cap.u.super.bFunctionalitySupport = 0;
+d-u.cap.u.super.bU1DevExitLat   = 0x0a;
+d-u.cap.u.super.wU2DevExitLat_lo= 0x20;
+d-u.cap.u.super.wU2DevExitLat_hi= 0;
+
+if (desc-full) {
+d-u.cap.u.super.wSpeedsSupported_lo |= (1  1);
+d-u.cap.u.super.bFunctionalitySupport = 1;
+}
+if (desc-high) {
+d-u.cap.u.super.wSpeedsSupported_lo |= (1  2);
+if (!d-u.cap.u.super.bFunctionalitySupport) {
+d-u.cap.u.super.bFunctionalitySupport = 2;
+}
+}
+if (desc-super) {
+d-u.cap.u.super.wSpeedsSupported_lo |= (1  3);
+if (!d-u.cap.u.super.bFunctionalitySupport) {
+d-u.cap.u.super.bFunctionalitySupport = 3;
+}
+}
+
+return bLength;
+}
+
+static int usb_desc_bos(const USBDesc *desc, uint8_t *dest, size_t len)
+{
+uint8_t  bLength = 0x05;
+uint16_t wTotalLength = 0;
+uint8_t  bNumDeviceCaps = 0;
+USBDescriptor *d = (void *)dest;
+int rc;
+
+if (len  bLength) {
+return -1;
+}
+
+d-bLength  = bLength;
+d-bDescriptorType  = USB_DT_BOS;
+
+wTotalLength += bLength;
+
+if (desc-high != NULL) {
+rc = usb_desc_cap_usb2_ext(desc, dest + wTotalLength,
+   len - wTotalLength);
+if (rc  0) {
+return rc;
+}
+wTotalLength += rc;
+bNumDeviceCaps++;
+}
+
+if (desc-super != NULL) {
+rc = usb_desc_cap_super(desc, dest + wTotalLength,
+len - wTotalLength);
+if (rc  0) {
+return rc;
+}
+wTotalLength += rc;
+bNumDeviceCaps++;
+}
+
+d-u.bos.wTotalLength_lo = usb_lo(wTotalLength);
+d-u.bos.wTotalLength_hi = usb_hi(wTotalLength);
+d-u.bos.bNumDeviceCaps  = bNumDeviceCaps;
+return wTotalLength;
+}
+
 /* -- */
 
 static void usb_desc_ep_init(USBDevice *dev)
@@ -571,6 +676,10 @@ int usb_desc_get_descriptor(USBDevice *dev, int value, 
uint8_t *dest, size_t len
 }
 trace_usb_desc_other_speed_config(dev-addr, index, len, ret);
 break;
+case USB_DT_BOS:
+ret = usb_desc_bos(desc, buf, sizeof(buf));
+trace_usb_desc_bos(dev-addr, len, ret);
+break;
 
 case USB_DT_DEBUG:
 /* ignore silently */
diff --git a/hw/usb/desc.h b/hw/usb/desc.h
index 4b5e88d..68bb570 100644
--- 

[Qemu-devel] [PATCH 14/54] ehci: Fix memory leak in handling of NAK-ed packets

2012-09-06 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

Currently each time we try to execute a NAK-ed packet we redo
ehci_init_transfer, and usb_packet_map, re-allocing (without freeing) the
sg list every time.

This patch fixes this, it does this by introducing another async state, so
that we also properly cleanup a NAK-ed packet on cancel.

Signed-off-by: Hans de Goede hdego...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-ehci.c |   38 +++---
 1 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 5a88268..d87aca8 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -345,6 +345,7 @@ typedef struct EHCIState EHCIState;
 
 enum async_state {
 EHCI_ASYNC_NONE = 0,
+EHCI_ASYNC_INITIALIZED,
 EHCI_ASYNC_INFLIGHT,
 EHCI_ASYNC_FINISHED,
 };
@@ -764,6 +765,10 @@ static void ehci_free_packet(EHCIPacket *p)
 return;
 }
 trace_usb_ehci_packet_action(p-queue, p, free);
+if (p-async == EHCI_ASYNC_INITIALIZED) {
+usb_packet_unmap(p-packet, p-sgl);
+qemu_sglist_destroy(p-sgl);
+}
 if (p-async == EHCI_ASYNC_INFLIGHT) {
 usb_cancel_packet(p-packet);
 usb_packet_unmap(p-packet, p-sgl);
@@ -1485,8 +1490,8 @@ static void ehci_execute_complete(EHCIQueue *q)
 
 assert(p != NULL);
 assert(p-qtdaddr == q-qtdaddr);
-assert(p-async != EHCI_ASYNC_INFLIGHT);
-p-async = EHCI_ASYNC_NONE;
+assert(p-async == EHCI_ASYNC_INITIALIZED ||
+   p-async == EHCI_ASYNC_FINISHED);
 
 DPRINTF(execute_complete: qhaddr 0x%x, next %x, qtdaddr 0x%x, status 
%d\n,
 q-qhaddr, q-qh.next, q-qtdaddr, q-usb_status);
@@ -1531,6 +1536,7 @@ static void ehci_execute_complete(EHCIQueue *q)
 ehci_finish_transfer(q, p-usb_status);
 usb_packet_unmap(p-packet, p-sgl);
 qemu_sglist_destroy(p-sgl);
+p-async = EHCI_ASYNC_NONE;
 
 q-qh.token ^= QTD_TOKEN_DTOGGLE;
 q-qh.token = ~QTD_TOKEN_ACTIVE;
@@ -1548,6 +1554,9 @@ static int ehci_execute(EHCIPacket *p, const char *action)
 int ret;
 int endp;
 
+assert(p-async == EHCI_ASYNC_NONE ||
+   p-async == EHCI_ASYNC_INITIALIZED);
+
 if (!(p-qtd.token  QTD_TOKEN_ACTIVE)) {
 fprintf(stderr, Attempting to execute inactive qtd\n);
 return USB_RET_PROCERR;
@@ -1576,15 +1585,18 @@ static int ehci_execute(EHCIPacket *p, const char 
*action)
 break;
 }
 
-if (ehci_init_transfer(p) != 0) {
-return USB_RET_PROCERR;
-}
-
 endp = get_field(p-queue-qh.epchar, QH_EPCHAR_EP);
 ep = usb_ep_get(p-queue-dev, p-pid, endp);
 
-usb_packet_setup(p-packet, p-pid, ep, p-qtdaddr);
-usb_packet_map(p-packet, p-sgl);
+if (p-async == EHCI_ASYNC_NONE) {
+if (ehci_init_transfer(p) != 0) {
+return USB_RET_PROCERR;
+}
+
+usb_packet_setup(p-packet, p-pid, ep, p-qtdaddr);
+usb_packet_map(p-packet, p-sgl);
+p-async = EHCI_ASYNC_INITIALIZED;
+}
 
 trace_usb_ehci_packet_action(p-queue, p, action);
 ret = usb_handle_packet(p-queue-dev, p-packet);
@@ -2021,11 +2033,15 @@ static int ehci_state_fetchqtd(EHCIQueue *q)
 } else if (p != NULL) {
 switch (p-async) {
 case EHCI_ASYNC_NONE:
+/* Should never happen packet should at least be initialized */
+assert(0);
+break;
+case EHCI_ASYNC_INITIALIZED:
 /* Previously nacked packet (likely interrupt ep) */
-   ehci_set_state(q-ehci, q-async, EST_EXECUTE);
-   break;
+ehci_set_state(q-ehci, q-async, EST_EXECUTE);
+break;
 case EHCI_ASYNC_INFLIGHT:
-/* Unfinyshed async handled packet, go horizontal */
+/* Unfinished async handled packet, go horizontal */
 ehci_set_state(q-ehci, q-async, EST_HORIZONTALQH);
 break;
 case EHCI_ASYNC_FINISHED:
-- 
1.7.1




[Qemu-devel] [PATCH 42/54] usb3: superspeed endpoint companion

2012-09-06 Thread Gerd Hoffmann
Add support for building superspeed endpoint companion descriptors,
create them for superspeed usb devices.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb.h  |1 +
 hw/usb/desc.c |   55 ---
 hw/usb/desc.h |   26 +-
 3 files changed, 62 insertions(+), 20 deletions(-)

diff --git a/hw/usb.h b/hw/usb.h
index 684e3f4..78ffdf4 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -137,6 +137,7 @@
 #define USB_DT_INTERFACE_ASSOC  0x0B
 #define USB_DT_CS_INTERFACE 0x24
 #define USB_DT_CS_ENDPOINT  0x25
+#define USB_DT_ENDPOINT_COMPANION   0x30
 
 #define USB_ENDPOINT_XFER_CONTROL  0
 #define USB_ENDPOINT_XFER_ISOC 1
diff --git a/hw/usb/desc.c b/hw/usb/desc.c
index 3e8c6cb..8f5a8e5 100644
--- a/hw/usb/desc.c
+++ b/hw/usb/desc.c
@@ -76,7 +76,8 @@ int usb_desc_device_qualifier(const USBDescDevice *dev,
 return bLength;
 }
 
-int usb_desc_config(const USBDescConfig *conf, uint8_t *dest, size_t len)
+int usb_desc_config(const USBDescConfig *conf, int flags,
+uint8_t *dest, size_t len)
 {
 uint8_t  bLength = 0x09;
 uint16_t wTotalLength = 0;
@@ -99,7 +100,7 @@ int usb_desc_config(const USBDescConfig *conf, uint8_t 
*dest, size_t len)
 
 /* handle grouped interfaces if any */
 for (i = 0; i  conf-nif_groups; i++) {
-rc = usb_desc_iface_group((conf-if_groups[i]),
+rc = usb_desc_iface_group((conf-if_groups[i]), flags,
   dest + wTotalLength,
   len - wTotalLength);
 if (rc  0) {
@@ -110,7 +111,8 @@ int usb_desc_config(const USBDescConfig *conf, uint8_t 
*dest, size_t len)
 
 /* handle normal (ungrouped / no IAD) interfaces if any */
 for (i = 0; i  conf-nif; i++) {
-rc = usb_desc_iface(conf-ifs + i, dest + wTotalLength, len - 
wTotalLength);
+rc = usb_desc_iface(conf-ifs + i, flags,
+dest + wTotalLength, len - wTotalLength);
 if (rc  0) {
 return rc;
 }
@@ -122,8 +124,8 @@ int usb_desc_config(const USBDescConfig *conf, uint8_t 
*dest, size_t len)
 return wTotalLength;
 }
 
-int usb_desc_iface_group(const USBDescIfaceAssoc *iad, uint8_t *dest,
- size_t len)
+int usb_desc_iface_group(const USBDescIfaceAssoc *iad, int flags,
+ uint8_t *dest, size_t len)
 {
 int pos = 0;
 int i = 0;
@@ -147,7 +149,7 @@ int usb_desc_iface_group(const USBDescIfaceAssoc *iad, 
uint8_t *dest,
 
 /* handle associated interfaces in this group */
 for (i = 0; i  iad-nif; i++) {
-int rc = usb_desc_iface((iad-ifs[i]), dest + pos, len - pos);
+int rc = usb_desc_iface((iad-ifs[i]), flags, dest + pos, len - pos);
 if (rc  0) {
 return rc;
 }
@@ -157,7 +159,8 @@ int usb_desc_iface_group(const USBDescIfaceAssoc *iad, 
uint8_t *dest,
 return pos;
 }
 
-int usb_desc_iface(const USBDescIface *iface, uint8_t *dest, size_t len)
+int usb_desc_iface(const USBDescIface *iface, int flags,
+   uint8_t *dest, size_t len)
 {
 uint8_t bLength = 0x09;
 int i, rc, pos = 0;
@@ -188,7 +191,7 @@ int usb_desc_iface(const USBDescIface *iface, uint8_t 
*dest, size_t len)
 }
 
 for (i = 0; i  iface-bNumEndpoints; i++) {
-rc = usb_desc_endpoint(iface-eps + i, dest + pos, len - pos);
+rc = usb_desc_endpoint(iface-eps + i, flags, dest + pos, len - pos);
 if (rc  0) {
 return rc;
 }
@@ -198,13 +201,15 @@ int usb_desc_iface(const USBDescIface *iface, uint8_t 
*dest, size_t len)
 return pos;
 }
 
-int usb_desc_endpoint(const USBDescEndpoint *ep, uint8_t *dest, size_t len)
+int usb_desc_endpoint(const USBDescEndpoint *ep, int flags,
+  uint8_t *dest, size_t len)
 {
 uint8_t bLength = ep-is_audio ? 0x09 : 0x07;
 uint8_t extralen = ep-extra ? ep-extra[0] : 0;
+uint8_t superlen = (flags  USB_DESC_FLAG_SUPER) ? 0x06 : 0;
 USBDescriptor *d = (void *)dest;
 
-if (len  bLength + extralen) {
+if (len  bLength + extralen + superlen) {
 return -1;
 }
 
@@ -224,7 +229,21 @@ int usb_desc_endpoint(const USBDescEndpoint *ep, uint8_t 
*dest, size_t len)
 memcpy(dest + bLength, ep-extra, extralen);
 }
 
-return bLength + extralen;
+if (superlen) {
+USBDescriptor *d = (void *)(dest + bLength + extralen);
+
+d-bLength   = 0x06;
+d-bDescriptorType   = USB_DT_ENDPOINT_COMPANION;
+
+d-u.super_endpoint.bMaxBurst= ep-bMaxBurst;
+d-u.super_endpoint.bmAttributes = ep-bmAttributes_super;
+d-u.super_endpoint.wBytesPerInterval_lo =
+usb_lo(ep-wBytesPerInterval);
+d-u.super_endpoint.wBytesPerInterval_hi =
+usb_hi(ep-wBytesPerInterval);
+}
+
+return bLength + extralen + superlen;
 }
 
 int 

[Qemu-devel] [PATCH 35/54] xhci: iso xfer support

2012-09-06 Thread Gerd Hoffmann
Add support for iso transfers.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-xhci.c |  117 +---
 1 files changed, 101 insertions(+), 16 deletions(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 9077cb3..3c61bb8 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -325,9 +325,15 @@ typedef struct XHCITransfer {
 unsigned int pkts;
 unsigned int pktsize;
 unsigned int cur_pkt;
+
+uint64_t mfindex_kick;
 } XHCITransfer;
 
 typedef struct XHCIEPContext {
+XHCIState *xhci;
+unsigned int slotid;
+unsigned int epid;
+
 XHCIRing ring;
 unsigned int next_xfer;
 unsigned int comp_xfer;
@@ -337,6 +343,11 @@ typedef struct XHCIEPContext {
 dma_addr_t pctx;
 unsigned int max_psize;
 uint32_t state;
+
+/* iso xfer scheduling */
+unsigned int interval;
+int64_t mfindex_last;
+QEMUTimer *kick_timer;
 } XHCIEPContext;
 
 typedef struct XHCISlot {
@@ -856,6 +867,12 @@ static void xhci_set_ep_state(XHCIState *xhci, 
XHCIEPContext *epctx,
 epctx-state = state;
 }
 
+static void xhci_ep_kick_timer(void *opaque)
+{
+XHCIEPContext *epctx = opaque;
+xhci_kick_ep(epctx-xhci, epctx-slotid, epctx-epid);
+}
+
 static TRBCCode xhci_enable_ep(XHCIState *xhci, unsigned int slotid,
unsigned int epid, dma_addr_t pctx,
uint32_t *ctx)
@@ -877,6 +894,9 @@ static TRBCCode xhci_enable_ep(XHCIState *xhci, unsigned 
int slotid,
 
 epctx = g_malloc(sizeof(XHCIEPContext));
 memset(epctx, 0, sizeof(XHCIEPContext));
+epctx-xhci = xhci;
+epctx-slotid = slotid;
+epctx-epid = epid;
 
 slot-eps[epid-1] = epctx;
 
@@ -895,6 +915,10 @@ static TRBCCode xhci_enable_ep(XHCIState *xhci, unsigned 
int slotid,
 usb_packet_init(epctx-transfers[i].packet);
 }
 
+epctx-interval = 1  (ctx[0]  16)  0xff;
+epctx-mfindex_last = 0;
+epctx-kick_timer = qemu_new_timer_ns(vm_clock, xhci_ep_kick_timer, epctx);
+
 epctx-state = EP_RUNNING;
 ctx[0] = ~EP_STATE_MASK;
 ctx[0] |= EP_RUNNING;
@@ -934,6 +958,7 @@ static int xhci_ep_nuke_xfers(XHCIState *xhci, unsigned int 
slotid,
 if (t-running_retry) {
 t-running_retry = 0;
 epctx-retry = NULL;
+qemu_del_timer(epctx-kick_timer);
 }
 if (t-trbs) {
 g_free(t-trbs);
@@ -969,6 +994,7 @@ static TRBCCode xhci_disable_ep(XHCIState *xhci, unsigned 
int slotid,
 
 xhci_set_ep_state(xhci, epctx, EP_DISABLED);
 
+qemu_free_timer(epctx-kick_timer);
 g_free(epctx);
 slot-eps[epid-1] = NULL;
 
@@ -1378,29 +1404,70 @@ static int xhci_fire_ctl_transfer(XHCIState *xhci, 
XHCITransfer *xfer)
 return 0;
 }
 
+static void xhci_calc_iso_kick(XHCIState *xhci, XHCITransfer *xfer,
+   XHCIEPContext *epctx, uint64_t mfindex)
+{
+if (xfer-trbs[0].control  TRB_TR_SIA) {
+uint64_t asap = ((mfindex + epctx-interval - 1) 
+ ~(epctx-interval-1));
+if (asap = epctx-mfindex_last 
+asap = epctx-mfindex_last + epctx-interval * 4) {
+xfer-mfindex_kick = epctx-mfindex_last + epctx-interval;
+} else {
+xfer-mfindex_kick = asap;
+}
+} else {
+xfer-mfindex_kick = (xfer-trbs[0].control  TRB_TR_FRAMEID_SHIFT)
+ TRB_TR_FRAMEID_MASK;
+xfer-mfindex_kick |= mfindex  ~0x3fff;
+if (xfer-mfindex_kick  mfindex) {
+xfer-mfindex_kick += 0x4000;
+}
+}
+}
+
+static void xhci_check_iso_kick(XHCIState *xhci, XHCITransfer *xfer,
+XHCIEPContext *epctx, uint64_t mfindex)
+{
+if (xfer-mfindex_kick  mfindex) {
+qemu_mod_timer(epctx-kick_timer, qemu_get_clock_ns(vm_clock) +
+   (xfer-mfindex_kick - mfindex) * 125000);
+xfer-running_retry = 1;
+} else {
+epctx-mfindex_last = xfer-mfindex_kick;
+qemu_del_timer(epctx-kick_timer);
+xfer-running_retry = 0;
+}
+}
+
+
 static int xhci_submit(XHCIState *xhci, XHCITransfer *xfer, XHCIEPContext 
*epctx)
 {
+uint64_t mfindex;
 int ret;
 
 DPRINTF(xhci_submit(slotid=%d,epid=%d)\n, xfer-slotid, xfer-epid);
 
 xfer-in_xfer = epctx-type2;
 
-if (epctx-type == ET_ISO_IN || epctx-type == ET_ISO_OUT) {
-xfer-pkts = 1;
-} else {
-xfer-pkts = 0;
-}
-
 switch(epctx-type) {
 case ET_INTR_OUT:
 case ET_INTR_IN:
 case ET_BULK_OUT:
 case ET_BULK_IN:
+xfer-pkts = 0;
+xfer-iso_xfer = false;
 break;
 case ET_ISO_OUT:
 case ET_ISO_IN:
-FIXME();
+xfer-pkts = 1;
+xfer-iso_xfer = true;
+mfindex = xhci_mfindex_get(xhci);
+xhci_calc_iso_kick(xhci, xfer, epctx, mfindex);
+xhci_check_iso_kick(xhci, xfer, epctx, mfindex);
+if (xfer-running_retry) {
+

[Qemu-devel] [PATCH 11/54] ehci: trace guest bugs

2012-09-06 Thread Gerd Hoffmann
make qemu_queue_{cancel,reset} return the number of packets released,
so the caller can figure whenever there have been active packets even
though there shouldn't have been any.  Add tracepoint to log this.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-ehci.c |   26 --
 trace-events  |1 +
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 23221d0..4564615 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -716,6 +716,12 @@ static void ehci_trace_sitd(EHCIState *s, 
target_phys_addr_t addr,
 (bool)(sitd-results  SITD_RESULTS_ACTIVE));
 }
 
+static void ehci_trace_guest_bug(EHCIState *s, const char *message)
+{
+trace_usb_ehci_guest_bug(message);
+fprintf(stderr, ehci warning: %s\n, message);
+}
+
 static inline bool ehci_enabled(EHCIState *s)
 {
 return s-usbcmd  USBCMD_RUNSTOP;
@@ -785,27 +791,33 @@ static EHCIQueue *ehci_alloc_queue(EHCIState *ehci, 
uint32_t addr, int async)
 return q;
 }
 
-static void ehci_cancel_queue(EHCIQueue *q)
+static int ehci_cancel_queue(EHCIQueue *q)
 {
 EHCIPacket *p;
+int packets = 0;
 
 p = QTAILQ_FIRST(q-packets);
 if (p == NULL) {
-return;
+return 0;
 }
 
 trace_usb_ehci_queue_action(q, cancel);
 do {
 ehci_free_packet(p);
+packets++;
 } while ((p = QTAILQ_FIRST(q-packets)) != NULL);
+return packets;
 }
 
-static void ehci_reset_queue(EHCIQueue *q)
+static int ehci_reset_queue(EHCIQueue *q)
 {
+int packets;
+
 trace_usb_ehci_queue_action(q, reset);
-ehci_cancel_queue(q);
+packets = ehci_cancel_queue(q);
 q-dev = NULL;
 q-qtdaddr = 0;
+return packets;
 }
 
 static void ehci_free_queue(EHCIQueue *q)
@@ -1817,7 +1829,9 @@ static EHCIQueue *ehci_state_fetchqh(EHCIState *ehci, int 
async)
 (memcmp(qh.current_qtd, q-qh.current_qtd,
  9 * sizeof(uint32_t)) != 0) ||
 (q-dev != NULL  q-dev-addr != devaddr)) {
-ehci_reset_queue(q);
+if (ehci_reset_queue(q)  0) {
+ehci_trace_guest_bug(ehci, guest updated active QH);
+}
 p = NULL;
 }
 q-qh = qh;
@@ -1979,8 +1993,8 @@ static int ehci_state_fetchqtd(EHCIQueue *q)
 (!NLPTR_TBIT(p-qtd.next)  (p-qtd.next != qtd.next)) ||
 (!NLPTR_TBIT(p-qtd.altnext)  (p-qtd.altnext != qtd.altnext)) ||
 p-qtd.bufptr[0] != qtd.bufptr[0]) {
-/* guest bug: guest updated active QH or qTD underneath us */
 ehci_cancel_queue(q);
+ehci_trace_guest_bug(q-ehci, guest updated active QH or qTD);
 p = NULL;
 } else {
 p-qtd = qtd;
diff --git a/trace-events b/trace-events
index 04b0723..0c7ffc7 100644
--- a/trace-events
+++ b/trace-events
@@ -263,6 +263,7 @@ usb_ehci_data(int rw, uint32_t cpage, uint32_t offset, 
uint32_t addr, uint32_t l
 usb_ehci_queue_action(void *q, const char *action) q %p: %s
 usb_ehci_packet_action(void *q, void *p, const char *action) q %p p %p: %s
 usb_ehci_irq(uint32_t level, uint32_t frindex, uint32_t sts, uint32_t mask) 
level %d, frindex 0x%04x, sts 0x%x, mask 0x%x
+usb_ehci_guest_bug(const char *reason) %s
 
 # hw/usb/hcd-uhci.c
 usb_uhci_reset(void) === RESET ===
-- 
1.7.1




[Qemu-devel] [PATCH 22/54] usb-redir: Move to core packet id and queue handling

2012-09-06 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

Signed-off-by: Hans de Goede hdego...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/redirect.c |  226 ++---
 1 files changed, 92 insertions(+), 134 deletions(-)

diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index 6593d50..fd1f8cc 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -43,7 +43,7 @@
 #define EP2I(ep_address) (((ep_address  0x80)  3) | (ep_address  0x0f))
 #define I2EP(i) (((i  0x10)  3) | (i  0x0f))
 
-typedef struct AsyncURB AsyncURB;
+typedef struct Cancelled Cancelled;
 typedef struct USBRedirDevice USBRedirDevice;
 
 /* Struct to hold buffered packets (iso or int input packets) */
@@ -86,8 +86,7 @@ struct USBRedirDevice {
 int64_t next_attach_time;
 struct usbredirparser *parser;
 struct endp_data endpoint[MAX_ENDPOINTS];
-uint32_t packet_id;
-QTAILQ_HEAD(, AsyncURB) asyncq;
+QTAILQ_HEAD(, Cancelled) cancelled;
 /* Data for device filtering */
 struct usb_redir_device_connect_header device_info;
 struct usb_redir_interface_info_header interface_info;
@@ -95,10 +94,9 @@ struct USBRedirDevice {
 int filter_rules_count;
 };
 
-struct AsyncURB {
-USBPacket *packet;
-uint32_t packet_id;
-QTAILQ_ENTRY(AsyncURB)next;
+struct Cancelled {
+uint64_t id;
+QTAILQ_ENTRY(Cancelled)next;
 };
 
 static void usbredir_hello(void *priv, struct usb_redir_hello_header *h);
@@ -238,57 +236,58 @@ static int usbredir_write(void *priv, uint8_t *data, int 
count)
 }
 
 /*
- * Async and buffered packets helpers
+ * Cancelled and buffered packets helpers
  */
 
-static AsyncURB *async_alloc(USBRedirDevice *dev, USBPacket *p)
+static void usbredir_cancel_packet(USBDevice *udev, USBPacket *p)
 {
-AsyncURB *aurb = (AsyncURB *) g_malloc0(sizeof(AsyncURB));
-aurb-packet = p;
-aurb-packet_id = dev-packet_id;
-QTAILQ_INSERT_TAIL(dev-asyncq, aurb, next);
-dev-packet_id++;
+USBRedirDevice *dev = DO_UPCAST(USBRedirDevice, dev, udev);
+Cancelled *c;
 
-return aurb;
-}
+DPRINTF(cancel packet id %PRIu64\n, p-id);
 
-static void async_free(USBRedirDevice *dev, AsyncURB *aurb)
-{
-QTAILQ_REMOVE(dev-asyncq, aurb, next);
-g_free(aurb);
+c = g_malloc0(sizeof(Cancelled));
+c-id = p-id;
+QTAILQ_INSERT_TAIL(dev-cancelled, c, next);
+
+usbredirparser_send_cancel_data_packet(dev-parser, p-id);
+usbredirparser_do_write(dev-parser);
 }
 
-static AsyncURB *async_find(USBRedirDevice *dev, uint32_t packet_id)
+static int usbredir_is_cancelled(USBRedirDevice *dev, uint64_t id)
 {
-AsyncURB *aurb;
+Cancelled *c;
+
+if (!dev-dev.attached) {
+return 1; /* Treat everything as cancelled after a disconnect */
+}
 
-QTAILQ_FOREACH(aurb, dev-asyncq, next) {
-if (aurb-packet_id == packet_id) {
-return aurb;
+QTAILQ_FOREACH(c, dev-cancelled, next) {
+if (c-id == id) {
+QTAILQ_REMOVE(dev-cancelled, c, next);
+g_free(c);
+return 1;
 }
 }
-DPRINTF(could not find async urb for packet_id %u\n, packet_id);
-return NULL;
+return 0;
 }
 
-static void usbredir_cancel_packet(USBDevice *udev, USBPacket *p)
+static USBPacket *usbredir_find_packet_by_id(USBRedirDevice *dev,
+uint8_t ep, uint64_t id)
 {
-USBRedirDevice *dev = DO_UPCAST(USBRedirDevice, dev, udev);
-AsyncURB *aurb;
-
-QTAILQ_FOREACH(aurb, dev-asyncq, next) {
-if (p != aurb-packet) {
-continue;
-}
+USBPacket *p;
 
-DPRINTF(async cancel id %u\n, aurb-packet_id);
-usbredirparser_send_cancel_data_packet(dev-parser, aurb-packet_id);
-usbredirparser_do_write(dev-parser);
+if (usbredir_is_cancelled(dev, id)) {
+return NULL;
+}
 
-/* Mark it as dead */
-aurb-packet = NULL;
-break;
+p = usb_ep_find_packet_by_id(dev-dev,
+(ep  USB_DIR_IN) ? USB_TOKEN_IN : USB_TOKEN_OUT,
+ep  0x0f, id);
+if (p == NULL) {
+ERROR(could not find packet with id %PRIu64\n, id);
 }
+return p;
 }
 
 static void bufp_alloc(USBRedirDevice *dev,
@@ -484,24 +483,22 @@ static void usbredir_stop_iso_stream(USBRedirDevice *dev, 
uint8_t ep)
 static int usbredir_handle_bulk_data(USBRedirDevice *dev, USBPacket *p,
   uint8_t ep)
 {
-AsyncURB *aurb = async_alloc(dev, p);
 struct usb_redir_bulk_packet_header bulk_packet;
 
-DPRINTF(bulk-out ep %02X len %zd id %u\n, ep,
-p-iov.size, aurb-packet_id);
+DPRINTF(bulk-out ep %02X len %zd id %PRIu64\n, ep, p-iov.size, p-id);
 
 bulk_packet.endpoint  = ep;
 bulk_packet.length= p-iov.size;
 bulk_packet.stream_id = 0;
 
 if (ep  USB_DIR_IN) {
-usbredirparser_send_bulk_packet(dev-parser, aurb-packet_id,
+usbredirparser_send_bulk_packet(dev-parser, p-id,

[Qemu-devel] [PULL 00/14] spice patch queue

2012-09-06 Thread Gerd Hoffmann
  Hi,

Here comes the spice patch queue with a bunch of fresh patches for 1.3.
A new qmp event is there, to fix spice client migration races, and a
bunch of patches needed to make use of the new goodies the upcoming
spice-server version (0.12) brings.  The later is disabled by default,
we'll flip the switch once 0.12 is finally released and all patches
needed are merged.

cheers,
  Gerd

The following changes since commit 8db972cfa469b4e4afd9c65e54e796b83b5ce3a2:

  Update version for 1.2.0 (2012-09-05 07:50:01 -0500)

are available in the git repository at:
  git://anongit.freedesktop.org/spice/qemu spice.v59

Alon Levy (4):
  qxl/update_area_io: guest_bug on invalid parameters
  qxl: disallow unknown revisions
  qxl: add QXL_IO_MONITORS_CONFIG_ASYNC
  configure: print spice-protocol and spice-server versions

Christophe Fergeau (1):
  spice: abort on invalid streaming cmdline params

Gerd Hoffmann (1):
  spice: make number of surfaces runtime-configurable.

Søren Sandmann Pedersen (2):
  qxl: Add set_client_capabilities() interface to QXLInterface
  Remove #ifdef QXL_COMMAND_FLAG_COMPAT_16BPP

Yonit Halperin (6):
  spice: notify spice server on vm start/stop
  spice: notify on vm state change only via spice_server_vm_start/stop
  spice migration: add QEVENT_SPICE_MIGRATE_COMPLETED
  spice: add 'migrated' flag to spice info
  spice: adding seamless-migration option to the command line
  spice: increase the verbosity of spice section in qemu --help

 configure  |   11 +++-
 hmp.c  |2 +
 hw/qxl.c   |  175 +---
 hw/qxl.h   |   10 +++-
 monitor.c  |1 +
 monitor.h  |1 +
 qapi-schema.json   |5 +-
 qemu-config.c  |3 +
 qemu-options.hx|   21 ++-
 trace-events   |1 +
 ui/spice-core.c|   41 -
 ui/spice-display.c |   37 ++-
 ui/spice-display.h |   13 +++-
 13 files changed, 284 insertions(+), 37 deletions(-)



Re: [Qemu-devel] [PATCH v6 2/2] block: Support GlusterFS as a QEMU block backend

2012-09-06 Thread Kevin Wolf
Am 06.09.2012 09:23, schrieb Paolo Bonzini:
 Il 05/09/2012 11:57, Bharata B Rao ha scritto:
 What could be the issue here ? In general, how do I ensure that my
 aio calls get completed correctly in such scenarios where bdrv_read etc
 are called from coroutine context rather than from main thread context ?
 One way to handle this is not to do completion from gluster thread but
 instead schedule a BH that does the completion. In fact I had this approach
 in the earlier versions, but resorted to directly calling completion from
 gluster thread as I didn't see the value of using a BH for completion.
 But I guess its indeed needed to support such scenarios (qcow2 image creation
 on gluster backend).
 
 I think the problem is that we're calling bdrv_drain_all() from
 coroutine context.  This is problematic because then the current
 coroutine won't yield and won't give other coroutines an occasion to run.
 
 This could be fixed by checking whether we're in coroutine context in
 bdrv_drain_all().  If so, instead of draining the queues directly,
 schedule a bottom half that does bdrv_drain_all() followed by
 qemu_coroutine_enter(), and yield.

Hm, could be an option, but I'm not sure if there's too much magic going
on then...

 If it works, I think this change would be preferrable to using a magic
 BH in every driver.

The way it works in posix-aio-compat is that the request is first
removed from the list and then the callback is called. This way
posix_aio_flush() can return 0 and bdrv_drain_all() completes.

Kevin



Re: [Qemu-devel] [PATCH 02/18] block: add error parameter to bdrv_snapshot_create() and related functions

2012-09-06 Thread Pavel Hrdina

On 08/30/2012 04:47 PM, Luiz Capitulino wrote:

On Wed, 15 Aug 2012 09:41:43 +0200
Pavel Hrdina phrd...@redhat.com wrote:


Signed-off-by: Pavel Hrdina phrd...@redhat.com
---
  block.c| 25 +
  block.h|  3 ++-
  block/qcow2-snapshot.c |  9 -
  block/qcow2.h  |  4 +++-
  block/rbd.c| 20 ++--
  block/sheepdog.c   | 17 +
  block_int.h|  3 ++-
  qemu-img.c |  2 +-
  savevm.c   |  2 +-
  9 files changed, 57 insertions(+), 28 deletions(-)

diff --git a/block.c b/block.c
index 016858b..8bc49b7 100644
--- a/block.c
+++ b/block.c
@@ -2661,16 +2661,25 @@ BlockDriverState *bdrv_snapshots(void)
  }
  
  int bdrv_snapshot_create(BlockDriverState *bs,

- QEMUSnapshotInfo *sn_info)
+ QEMUSnapshotInfo *sn_info,
+ Error **errp)
  {
  BlockDriver *drv = bs-drv;
-if (!drv)
-return -ENOMEDIUM;
-if (drv-bdrv_snapshot_create)
-return drv-bdrv_snapshot_create(bs, sn_info);
-if (bs-file)
-return bdrv_snapshot_create(bs-file, sn_info);
-return -ENOTSUP;
+int ret;
+
+if (!drv) {
+error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, bdrv_get_device_name(bs));

We should only use QERR_ macros for the errors listed in the ErrorClass enum
(except GenericError), all other errors should generally use error_setg(), like
this:

  error_setg(errp, device '%s' has no medium);


I agree that we should use error_setg() for all GenericError, but I 
think that would be better have macros for errors which are used 
many-times . For example:


#define QERR_ERRMSG_DEVICE_HAS_NO_MEDIUM Device '%s' has no medium

and use error_setg(errp, QERR_ERRMSG_DEVICE_HAS_NO_MEDIUM, 
bdrv_get_device_name(bs));


I think that the consistency of error messages is important and an error 
message should be the same for every error occurrence.



+ret = -ENOMEDIUM;

And, usually, we should get rid of errno propagation. There are two cases here:

  1. errno is propagated up so that upper layers can print a decent error
 message to the user.

 In this case, it's safe to eliminate errno. error_setg() will store a
 decent message already and the Error object can be propagated up.

  2. errno is propagated up so that upper layers can distinguish among
 error causes and take different actions accordingly.

 Doesn't seem to be the case of bdrv_snapshot_create() (ie. errno is only
 used to communicate the error to the user). However, I'm pretty sure that
 such usage exists in qemu and the error API will break it, as most of our
 errors are generic.

 I see two solutions to this problem:

A. Add specific errors to ErrorClass. I don't like this very much,
   as it's possible that such errors are going to be useful only 
internally.

B. Add two new functions:

 void error_sete(Error **err, ErrorClass err_class, int errno, 
const char *fmt, ...);
 int error_get_errno(const Error **err);

  So that we can maintain errno when it's used to communicate
  error cause among functions.


+} else if (drv-bdrv_snapshot_create) {
+ret = drv-bdrv_snapshot_create(bs, sn_info, errp);
+} else if (bs-file) {
+ret = bdrv_snapshot_create(bs-file, sn_info, errp);
+} else {
+error_set(errp, QERR_NOT_SUPPORTED);
+ret = -ENOTSUP;
+}
+
+return ret;
  }
  
  int bdrv_snapshot_goto(BlockDriverState *bs,

diff --git a/block.h b/block.h
index 2e2be11..92e782b 100644
--- a/block.h
+++ b/block.h
@@ -296,7 +296,8 @@ int bdrv_can_snapshot(BlockDriverState *bs);
  int bdrv_is_snapshot(BlockDriverState *bs);
  BlockDriverState *bdrv_snapshots(void);
  int bdrv_snapshot_create(BlockDriverState *bs,
- QEMUSnapshotInfo *sn_info);
+ QEMUSnapshotInfo *sn_info,
+ Error **errp);
  int bdrv_snapshot_goto(BlockDriverState *bs,
 const char *snapshot_id);
  int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id);
diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
index 4e7c93b..cf86dae 100644
--- a/block/qcow2-snapshot.c
+++ b/block/qcow2-snapshot.c
@@ -25,6 +25,7 @@
  #include qemu-common.h
  #include block_int.h
  #include block/qcow2.h
+#include qerror.h
  
  typedef struct QEMU_PACKED QCowSnapshotHeader {

  /* header is 8 byte aligned */
@@ -312,7 +313,9 @@ static int find_snapshot_by_id_or_name(BlockDriverState 
*bs, const char *name)
  }
  
  /* if no id is provided, a new one is constructed */

-int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
+int qcow2_snapshot_create(BlockDriverState *bs,
+  QEMUSnapshotInfo *sn_info,
+  Error **errp)
  {
  BDRVQcowState *s = bs-opaque;
  

[Qemu-devel] [PATCH 01/14] spice: abort on invalid streaming cmdline params

2012-09-06 Thread Gerd Hoffmann
From: Christophe Fergeau cferg...@redhat.com

When parsing its command line parameters, spice aborts when it
finds unexpected values, except for the 'streaming-video' option.
This happens because the parsing of the parameters for this option
is done using the 'name2enum' helper, which does not error out
on unknown values. Using the 'parse_name' helper makes sure we
error out in this case. Looking at git history, the use of
'name2enum' instead of 'parse_name' seems to have been an oversight,
so let's change to that now.

Fixes rhbz#831708

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/spice-core.c |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/ui/spice-core.c b/ui/spice-core.c
index 4fc48f8..bb4f585 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -344,7 +344,8 @@ static const char *stream_video_names[] = {
 [ SPICE_STREAM_VIDEO_FILTER ] = filter,
 };
 #define parse_stream_video(_name) \
-name2enum(_name, stream_video_names, ARRAY_SIZE(stream_video_names))
+parse_name(_name, stream video control, \
+   stream_video_names, ARRAY_SIZE(stream_video_names))
 
 static const char *compression_names[] = {
 [ SPICE_IMAGE_COMPRESS_OFF ]  = off,
-- 
1.7.1




[Qemu-devel] [PATCH 10/14] qxl: add QXL_IO_MONITORS_CONFIG_ASYNC

2012-09-06 Thread Gerd Hoffmann
From: Alon Levy al...@redhat.com

Revision bumped to 4 for new IO support, enabled for spice-server =
0.11.1. New io enabled if revision is 4. Revision can be set to 4.

[ kraxel: 3 continues to be the default revision.  Once we have a new
  stable spice-server release and the qemu patches to enable
  the new bits merged we'll go flip the switch and make rev4
  the default ]

This io calls the corresponding new spice api
spice_qxl_monitors_config_async to let spice-server read a new guest set
monitors config and notify the client.

On migration reissue spice_qxl_monitors_config_async.

RHBZ: 770842

Signed-off-by: Alon Levy al...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com

fixup

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 configure  |7 
 hw/qxl.c   |   97 +--
 hw/qxl.h   |7 
 trace-events   |1 +
 ui/spice-display.h |1 +
 5 files changed, 109 insertions(+), 4 deletions(-)

diff --git a/configure b/configure
index d97fd81..59521ea 100755
--- a/configure
+++ b/configure
@@ -2701,6 +2701,9 @@ EOF
 spice=yes
 libs_softmmu=$libs_softmmu $spice_libs
 QEMU_CFLAGS=$QEMU_CFLAGS $spice_cflags
+if $pkg_config --atleast-version=0.12.0 spice-protocol /dev/null 21; 
then
+spice_qxl_io_monitors_config_async=yes
+fi
   else
 if test $spice = yes ; then
   feature_not_found spice
@@ -3438,6 +3441,10 @@ if test $spice = yes ; then
   echo CONFIG_SPICE=y  $config_host_mak
 fi
 
+if test $spice_qxl_io_monitors_config_async = yes ; then
+  echo CONFIG_QXL_IO_MONITORS_CONFIG_ASYNC=y  $config_host_mak
+fi
+
 if test $smartcard = yes ; then
   echo CONFIG_SMARTCARD=y  $config_host_mak
 fi
diff --git a/hw/qxl.c b/hw/qxl.c
index d134a70..adf17fd 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -27,6 +27,11 @@
 
 #include qxl.h
 
+#ifndef CONFIG_QXL_IO_MONITORS_CONFIG_ASYNC
+/* spice-protocol is too old, add missing definitions */
+#define QXL_IO_MONITORS_CONFIG_ASYNC (QXL_IO_FLUSH_RELEASE + 1)
+#endif
+
 /*
  * NOTE: SPICE_RING_PROD_ITEM accesses memory on the pci bar and as
  * such can be changed by the guest, so to avoid a guest trigerrable
@@ -249,6 +254,39 @@ static void qxl_spice_destroy_surfaces(PCIQXLDevice *qxl, 
qxl_async_io async)
 }
 }
 
+static void qxl_spice_monitors_config_async(PCIQXLDevice *qxl, int replay)
+{
+trace_qxl_spice_monitors_config(qxl-id);
+/* 0x000b01 == 0.11.1 */
+#if SPICE_SERVER_VERSION = 0x000b01  \
+defined(CONFIG_QXL_IO_MONITORS_CONFIG_ASYNC)
+if (replay) {
+/*
+ * don't use QXL_COOKIE_TYPE_IO:
+ *  - we are not running yet (post_load), we will assert
+ *in send_events
+ *  - this is not a guest io, but a reply, so async_io isn't set.
+ */
+spice_qxl_monitors_config_async(qxl-ssd.qxl,
+qxl-guest_monitors_config,
+MEMSLOT_GROUP_GUEST,
+(uintptr_t)qxl_cookie_new(
+QXL_COOKIE_TYPE_POST_LOAD_MONITORS_CONFIG,
+0));
+} else {
+qxl-guest_monitors_config = qxl-ram-monitors_config;
+spice_qxl_monitors_config_async(qxl-ssd.qxl,
+qxl-ram-monitors_config,
+MEMSLOT_GROUP_GUEST,
+(uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO,
+  QXL_IO_MONITORS_CONFIG_ASYNC));
+}
+#else
+fprintf(stderr, qxl: too old spice-protocol/spice-server for 
+QXL_IO_MONITORS_CONFIG_ASYNC\n);
+#endif
+}
+
 void qxl_spice_reset_image_cache(PCIQXLDevice *qxl)
 {
 trace_qxl_spice_reset_image_cache(qxl-id);
@@ -538,6 +576,7 @@ static const char *io_port_to_string(uint32_t io_port)
 = QXL_IO_DESTROY_ALL_SURFACES_ASYNC,
 [QXL_IO_FLUSH_SURFACES_ASYNC]   = QXL_IO_FLUSH_SURFACES_ASYNC,
 [QXL_IO_FLUSH_RELEASE]  = QXL_IO_FLUSH_RELEASE,
+[QXL_IO_MONITORS_CONFIG_ASYNC]  = QXL_IO_MONITORS_CONFIG_ASYNC,
 };
 return io_port_to_string[io_port];
 }
@@ -819,6 +858,7 @@ static void interface_async_complete_io(PCIQXLDevice *qxl, 
QXLCookie *cookie)
 case QXL_IO_DESTROY_PRIMARY_ASYNC:
 case QXL_IO_UPDATE_AREA_ASYNC:
 case QXL_IO_FLUSH_SURFACES_ASYNC:
+case QXL_IO_MONITORS_CONFIG_ASYNC:
 break;
 case QXL_IO_CREATE_PRIMARY_ASYNC:
 qxl_create_guest_primary_complete(qxl);
@@ -894,6 +934,8 @@ static void interface_async_complete(QXLInstance *sin, 
uint64_t cookie_token)
 case QXL_COOKIE_TYPE_RENDER_UPDATE_AREA:
 qxl_render_update_area_done(qxl, cookie);
 break;
+case QXL_COOKIE_TYPE_POST_LOAD_MONITORS_CONFIG:
+break;
 default:
 fprintf(stderr, qxl: %s: unexpected cookie type %d\n,
 __func__, cookie-type);
@@ -1315,6 +1357,13 @@ static void ioport_write(void *opaque, 
target_phys_addr_t addr,
 return;
 }
 
+if 

[Qemu-devel] [PATCH 51/54] xhci: pick target interrupter

2012-09-06 Thread Gerd Hoffmann
Pick the correct interrupter when queuing an event.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-xhci.c |   22 --
 1 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 68a19ab..d6ab0c6 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -264,6 +264,10 @@ typedef enum TRBCCode {
 
 #define TRB_LK_TC   (11)
 
+#define TRB_INTR_SHIFT  22
+#define TRB_INTR_MASK   0x3ff
+#define TRB_INTR(t) (((t).status  TRB_INTR_SHIFT)  TRB_INTR_MASK)
+
 #define EP_TYPE_MASK0x7
 #define EP_TYPE_SHIFT   3
 
@@ -806,10 +810,16 @@ static void xhci_events_update(XHCIState *xhci, int v)
 
 static void xhci_event(XHCIState *xhci, XHCIEvent *event, int v)
 {
-XHCIInterrupter *intr = xhci-intr[v];
+XHCIInterrupter *intr;
 dma_addr_t erdp;
 unsigned int dp_idx;
 
+if (v = MAXINTRS) {
+DPRINTF(intr nr out of range (%d = %d)\n, v, MAXINTRS);
+return;
+}
+intr = xhci-intr[v];
+
 if (intr-er_full) {
 DPRINTF(xhci_event(): ER full, queueing\n);
 if (((intr-ev_buffer_put+1) % EV_QUEUE) == intr-ev_buffer_get) {
@@ -1377,7 +1387,7 @@ static void xhci_xfer_report(XHCITransfer *xfer)
 DPRINTF(xhci_xfer_data: EDTLA=%d\n, event.length);
 edtla = 0;
 }
-xhci_event(xhci, event, 0 /* FIXME */);
+xhci_event(xhci, event, TRB_INTR(*trb));
 reported = 1;
 if (xfer-status != CC_SUCCESS) {
 return;
@@ -2255,7 +2265,7 @@ static void xhci_process_commands(XHCIState *xhci)
 break;
 }
 event.slotid = slotid;
-xhci_event(xhci, event, 0 /* FIXME */);
+xhci_event(xhci, event, 0);
 }
 }
 
@@ -2285,7 +2295,7 @@ static void xhci_update_port(XHCIState *xhci, XHCIPort 
*port, int is_detach)
 port-portsc |= PORTSC_CSC;
 XHCIEvent ev = { ER_PORT_STATUS_CHANGE, CC_SUCCESS,
  port-portnr  24};
-xhci_event(xhci, ev, 0 /* FIXME */);
+xhci_event(xhci, ev, 0);
 DPRINTF(xhci: port change event for port %d\n, port-portnr);
 }
 }
@@ -2564,7 +2574,7 @@ static void xhci_oper_write(XHCIState *xhci, uint32_t 
reg, uint32_t val)
 if (xhci-crcr_low  (CRCR_CA|CRCR_CS)  (xhci-crcr_low  CRCR_CRR)) 
{
 XHCIEvent event = {ER_COMMAND_COMPLETE, CC_COMMAND_RING_STOPPED};
 xhci-crcr_low = ~CRCR_CRR;
-xhci_event(xhci, event, 0 /* FIXME */);
+xhci_event(xhci, event, 0);
 DPRINTF(xhci: command ring stopped (CRCR=%08x)\n, 
xhci-crcr_low);
 } else {
 dma_addr_t base = xhci_addr64(xhci-crcr_low  ~0x3f, val);
@@ -2807,7 +2817,7 @@ static void xhci_wakeup(USBPort *usbport)
 return;
 }
 port-portsc |= PORTSC_PLC;
-xhci_event(xhci, ev, 0 /* FIXME */);
+xhci_event(xhci, ev, 0);
 }
 
 static void xhci_complete(USBPort *port, USBPacket *packet)
-- 
1.7.1




[Qemu-devel] [PATCH 24/54] usb-redir: Convert to new libusbredirparser 0.5 API

2012-09-06 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

This gives us support for 64 bit ids which is needed for using XHCI with
the new hcd generated ids.

Signed-off-by: Hans de Goede hdego...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 configure |2 +-
 hw/usb/redirect.c |   62 ++--
 2 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/configure b/configure
index d97fd81..ea2925b 100755
--- a/configure
+++ b/configure
@@ -2750,7 +2750,7 @@ fi
 
 # check for usbredirparser for usb network redirection support
 if test $usb_redir != no ; then
-if $pkg_config --atleast-version=0.3.4 libusbredirparser /dev/null 21 ; 
then
+if $pkg_config --atleast-version=0.5 libusbredirparser /dev/null 21 ; 
then
 usb_redir=yes
 usb_redir_cflags=$($pkg_config --cflags libusbredirparser 2/dev/null)
 usb_redir_libs=$($pkg_config --libs libusbredirparser 2/dev/null)
diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index ee75217..eeeb003 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -107,27 +107,27 @@ static void usbredir_interface_info(void *priv,
 struct usb_redir_interface_info_header *interface_info);
 static void usbredir_ep_info(void *priv,
 struct usb_redir_ep_info_header *ep_info);
-static void usbredir_configuration_status(void *priv, uint32_t id,
+static void usbredir_configuration_status(void *priv, uint64_t id,
 struct usb_redir_configuration_status_header *configuration_status);
-static void usbredir_alt_setting_status(void *priv, uint32_t id,
+static void usbredir_alt_setting_status(void *priv, uint64_t id,
 struct usb_redir_alt_setting_status_header *alt_setting_status);
-static void usbredir_iso_stream_status(void *priv, uint32_t id,
+static void usbredir_iso_stream_status(void *priv, uint64_t id,
 struct usb_redir_iso_stream_status_header *iso_stream_status);
-static void usbredir_interrupt_receiving_status(void *priv, uint32_t id,
+static void usbredir_interrupt_receiving_status(void *priv, uint64_t id,
 struct usb_redir_interrupt_receiving_status_header
 *interrupt_receiving_status);
-static void usbredir_bulk_streams_status(void *priv, uint32_t id,
+static void usbredir_bulk_streams_status(void *priv, uint64_t id,
 struct usb_redir_bulk_streams_status_header *bulk_streams_status);
-static void usbredir_control_packet(void *priv, uint32_t id,
+static void usbredir_control_packet(void *priv, uint64_t id,
 struct usb_redir_control_packet_header *control_packet,
 uint8_t *data, int data_len);
-static void usbredir_bulk_packet(void *priv, uint32_t id,
+static void usbredir_bulk_packet(void *priv, uint64_t id,
 struct usb_redir_bulk_packet_header *bulk_packet,
 uint8_t *data, int data_len);
-static void usbredir_iso_packet(void *priv, uint32_t id,
+static void usbredir_iso_packet(void *priv, uint64_t id,
 struct usb_redir_iso_packet_header *iso_packet,
 uint8_t *data, int data_len);
-static void usbredir_interrupt_packet(void *priv, uint32_t id,
+static void usbredir_interrupt_packet(void *priv, uint64_t id,
 struct usb_redir_interrupt_packet_header *interrupt_header,
 uint8_t *data, int data_len);
 
@@ -805,6 +805,7 @@ static void usbredir_chardev_open(USBRedirDevice *dev)
 
 usbredirparser_caps_set_cap(caps, usb_redir_cap_connect_device_version);
 usbredirparser_caps_set_cap(caps, usb_redir_cap_filter);
+usbredirparser_caps_set_cap(caps, usb_redir_cap_64bits_ids);
 usbredirparser_init(dev-parser, version, caps, USB_REDIR_CAPS_SIZE, 0);
 usbredirparser_do_write(dev-parser);
 }
@@ -1182,15 +1183,15 @@ static void usbredir_ep_info(void *priv,
 }
 }
 
-static void usbredir_configuration_status(void *priv, uint32_t id,
+static void usbredir_configuration_status(void *priv, uint64_t id,
 struct usb_redir_configuration_status_header *config_status)
 {
 USBRedirDevice *dev = priv;
 USBPacket *p;
 int len = 0;
 
-DPRINTF(set config status %d config %d id %u\n, config_status-status,
-config_status-configuration, id);
+DPRINTF(set config status %d config %d id %PRIu64\n,
+config_status-status, config_status-configuration, id);
 
 p = usbredir_find_packet_by_id(dev, 0, id);
 if (p) {
@@ -1203,16 +1204,15 @@ static void usbredir_configuration_status(void *priv, 
uint32_t id,
 }
 }
 
-static void usbredir_alt_setting_status(void *priv, uint32_t id,
+static void usbredir_alt_setting_status(void *priv, uint64_t id,
 struct usb_redir_alt_setting_status_header *alt_setting_status)
 {
 USBRedirDevice *dev = priv;
 USBPacket *p;
 int len = 0;
 
-DPRINTF(alt status %d intf %d alt %d id: %u\n,
-alt_setting_status-status,
-alt_setting_status-interface,
+DPRINTF(alt status %d intf %d alt %d id: %PRIu64\n,
+alt_setting_status-status, alt_setting_status-interface,
 alt_setting_status-alt, id);
 
 p 

[Qemu-devel] [PATCH 2/4] wakeup: make ps/2 configurable

2012-09-06 Thread Gerd Hoffmann
ps/2 gets gpe bits 0x08 (keyboard) and 0x09 (mouse).

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/ps2.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/ps2.c b/hw/ps2.c
index f93cd24..a3cd124 100644
--- a/hw/ps2.c
+++ b/hw/ps2.c
@@ -155,7 +155,7 @@ static void ps2_put_keycode(void *opaque, int keycode)
 {
 PS2KbdState *s = opaque;
 
-qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
+qemu_system_wakeup_request(QEMU_WAKEUP_REASON_GPE_8);
 /* XXX: add support for scancode set 1 */
 if (!s-translate  keycode  0xe0  s-scancode_set  1) {
 if (keycode  0x80) {
@@ -371,7 +371,7 @@ static void ps2_mouse_event(void *opaque,
 s-mouse_buttons = buttons_state;
 
 if (buttons_state) {
-qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
+qemu_system_wakeup_request(QEMU_WAKEUP_REASON_GPE_9);
 }
 
 if (!(s-mouse_status  MOUSE_STATUS_REMOTE) 
-- 
1.7.1




[Qemu-devel] [PATCH 37/54] xhci: add trace_usb_xhci_ep_set_dequeue

2012-09-06 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-xhci.c |2 +-
 trace-events  |1 +
 2 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index ab32a7b..5cdaf76 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -1145,7 +1145,7 @@ static TRBCCode xhci_set_ep_dequeue(XHCIState *xhci, 
unsigned int slotid,
 return CC_TRB_ERROR;
 }
 
-DPRINTF(xhci_set_ep_dequeue(%d, %d, %016PRIx64)\n, slotid, epid, 
pdequeue);
+trace_usb_xhci_ep_set_dequeue(slotid, epid, pdequeue);
 dequeue = xhci_mask64(pdequeue);
 
 slot = xhci-slots[slotid-1];
diff --git a/trace-events b/trace-events
index a642fad..8fa683d 100644
--- a/trace-events
+++ b/trace-events
@@ -323,6 +323,7 @@ usb_xhci_slot_evaluate(uint32_t slotid) slotid %d
 usb_xhci_slot_reset(uint32_t slotid) slotid %d
 usb_xhci_ep_enable(uint32_t slotid, uint32_t epid) slotid %d, epid %d
 usb_xhci_ep_disable(uint32_t slotid, uint32_t epid) slotid %d, epid %d
+usb_xhci_ep_set_dequeue(uint32_t slotid, uint32_t epid, uint64_t param) 
slotid %d, epid %d, ptr %016 PRIx64
 usb_xhci_ep_kick(uint32_t slotid, uint32_t epid) slotid %d, epid %d
 usb_xhci_ep_stop(uint32_t slotid, uint32_t epid) slotid %d, epid %d
 usb_xhci_ep_reset(uint32_t slotid, uint32_t epid) slotid %d, epid %d
-- 
1.7.1




[Qemu-devel] [PATCH 04/54] usb-core: Allow the first packet of a pipelined ep to complete immediately

2012-09-06 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

This can happen with usb-redir live-migration when the packet gets re-queued
after the migration and the original queuing from the migration source side
has already finished.

Signed-off-by: Hans de Goede hdego...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/core.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/usb/core.c b/hw/usb/core.c
index fe431d0..b9f1f7a 100644
--- a/hw/usb/core.c
+++ b/hw/usb/core.c
@@ -398,7 +398,7 @@ int usb_handle_packet(USBDevice *dev, USBPacket *p)
  * When pipelining is enabled usb-devices must always return async,
  * otherwise packets can complete out of order!
  */
-assert(!p-ep-pipeline);
+assert(!p-ep-pipeline || QTAILQ_EMPTY(p-ep-queue));
 if (ret != USB_RET_NAK) {
 p-result = ret;
 usb_packet_set_state(p, USB_PACKET_COMPLETE);
-- 
1.7.1




[Qemu-devel] [PATCH 15/54] ehci: Handle USB_RET_PROCERR in ehci_fill_queue

2012-09-06 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

USB_RET_PROCERR can be triggered by the guest (by for example requesting more
then BUFFSIZE bytes), so don't assert on it.

Signed-off-by: Hans de Goede hdego...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-ehci.c |9 ++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index d87aca8..2534394 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -2076,7 +2076,7 @@ static int ehci_state_horizqh(EHCIQueue *q)
 return again;
 }
 
-static void ehci_fill_queue(EHCIPacket *p)
+static int ehci_fill_queue(EHCIPacket *p)
 {
 EHCIQueue *q = p-queue;
 EHCIqtd qtd = p-qtd;
@@ -2100,9 +2100,13 @@ static void ehci_fill_queue(EHCIPacket *p)
 p-qtdaddr = qtdaddr;
 p-qtd = qtd;
 p-usb_status = ehci_execute(p, queue);
+if (p-usb_status == USB_RET_PROCERR) {
+break;
+}
 assert(p-usb_status == USB_RET_ASYNC);
 p-async = EHCI_ASYNC_INFLIGHT;
 }
+return p-usb_status;
 }
 
 static int ehci_state_execute(EHCIQueue *q)
@@ -2144,8 +2148,7 @@ static int ehci_state_execute(EHCIQueue *q)
 trace_usb_ehci_packet_action(p-queue, p, async);
 p-async = EHCI_ASYNC_INFLIGHT;
 ehci_set_state(q-ehci, q-async, EST_HORIZONTALQH);
-again = 1;
-ehci_fill_queue(p);
+again = (ehci_fill_queue(p) == USB_RET_PROCERR) ? -1 : 1;
 goto out;
 }
 
-- 
1.7.1




[Qemu-devel] [PATCH 50/54] xhci: prepare xhci_runtime_{read, write} for multiple interrupters

2012-09-06 Thread Gerd Hoffmann
Prepare xhci runtime register access function for multiple interrupters.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-xhci.c |  100 ++---
 1 files changed, 57 insertions(+), 43 deletions(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index ddc3825..68a19ab 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -2588,37 +2588,43 @@ static void xhci_oper_write(XHCIState *xhci, uint32_t 
reg, uint32_t val)
 
 static uint32_t xhci_runtime_read(XHCIState *xhci, uint32_t reg)
 {
-XHCIInterrupter *intr = xhci-intr[0];
-uint32_t ret;
+uint32_t ret = 0;
 
-switch (reg) {
-case 0x00: /* MFINDEX */
-ret = xhci_mfindex_get(xhci)  0x3fff;
-break;
-case 0x20: /* IMAN */
-ret = intr-iman;
-break;
-case 0x24: /* IMOD */
-ret = intr-imod;
-break;
-case 0x28: /* ERSTSZ */
-ret = intr-erstsz;
-break;
-case 0x30: /* ERSTBA low */
-ret = intr-erstba_low;
-break;
-case 0x34: /* ERSTBA high */
-ret = intr-erstba_high;
-break;
-case 0x38: /* ERDP low */
-ret = intr-erdp_low;
-break;
-case 0x3c: /* ERDP high */
-ret = intr-erdp_high;
-break;
-default:
-fprintf(stderr, xhci_runtime_read: reg 0x%x unimplemented\n, reg);
-ret = 0;
+if (reg  0x20) {
+switch (reg) {
+case 0x00: /* MFINDEX */
+ret = xhci_mfindex_get(xhci)  0x3fff;
+break;
+default:
+fprintf(stderr, xhci_runtime_read: reg 0x%x unimplemented\n, 
reg);
+break;
+}
+} else {
+int v = (reg - 0x20) / 0x20;
+XHCIInterrupter *intr = xhci-intr[v];
+switch (reg  0x1f) {
+case 0x00: /* IMAN */
+ret = intr-iman;
+break;
+case 0x04: /* IMOD */
+ret = intr-imod;
+break;
+case 0x08: /* ERSTSZ */
+ret = intr-erstsz;
+break;
+case 0x10: /* ERSTBA low */
+ret = intr-erstba_low;
+break;
+case 0x14: /* ERSTBA high */
+ret = intr-erstba_high;
+break;
+case 0x18: /* ERDP low */
+ret = intr-erdp_low;
+break;
+case 0x1c: /* ERDP high */
+ret = intr-erdp_high;
+break;
+}
 }
 
 trace_usb_xhci_runtime_read(reg, ret);
@@ -2627,43 +2633,51 @@ static uint32_t xhci_runtime_read(XHCIState *xhci, 
uint32_t reg)
 
 static void xhci_runtime_write(XHCIState *xhci, uint32_t reg, uint32_t val)
 {
-XHCIInterrupter *intr = xhci-intr[0];
+int v = (reg - 0x20) / 0x20;
+XHCIInterrupter *intr = xhci-intr[v];
 trace_usb_xhci_runtime_write(reg, val);
 
-switch (reg) {
-case 0x20: /* IMAN */
+if (reg  0x20) {
+fprintf(stderr, xhci_oper_write: reg 0x%x unimplemented\n, reg);
+return;
+}
+
+switch (reg  0x1f) {
+case 0x00: /* IMAN */
 if (val  IMAN_IP) {
 intr-iman = ~IMAN_IP;
 }
 intr-iman = ~IMAN_IE;
 intr-iman |= val  IMAN_IE;
-xhci_intx_update(xhci);
-xhci_msix_update(xhci, 0);
+if (v == 0) {
+xhci_intx_update(xhci);
+}
+xhci_msix_update(xhci, v);
 break;
-case 0x24: /* IMOD */
+case 0x04: /* IMOD */
 intr-imod = val;
 break;
-case 0x28: /* ERSTSZ */
+case 0x08: /* ERSTSZ */
 intr-erstsz = val  0x;
 break;
-case 0x30: /* ERSTBA low */
+case 0x10: /* ERSTBA low */
 /* XXX NEC driver bug: it doesn't align this to 64 bytes
 intr-erstba_low = val  0xffc0; */
 intr-erstba_low = val  0xfff0;
 break;
-case 0x34: /* ERSTBA high */
+case 0x14: /* ERSTBA high */
 intr-erstba_high = val;
-xhci_er_reset(xhci, 0);
+xhci_er_reset(xhci, v);
 break;
-case 0x38: /* ERDP low */
+case 0x18: /* ERDP low */
 if (val  ERDP_EHB) {
 intr-erdp_low = ~ERDP_EHB;
 }
 intr-erdp_low = (val  ~ERDP_EHB) | (intr-erdp_low  ERDP_EHB);
 break;
-case 0x3c: /* ERDP high */
+case 0x1c: /* ERDP high */
 intr-erdp_high = val;
-xhci_events_update(xhci, 0);
+xhci_events_update(xhci, v);
 break;
 default:
 fprintf(stderr, xhci_oper_write: reg 0x%x unimplemented\n, reg);
-- 
1.7.1




Re: [Qemu-devel] [PATCH] xhci: allow 1 and 2 bytes accesses to capability registers

2012-09-06 Thread Alejandro Martinez
Gerd,

On Tue, Sep 4, 2012 at 3:30 PM, Gerd Hoffmann kra...@redhat.com wrote:
 On 08/30/12 14:49, Alejandro Martinez Ruiz wrote:
 Some xHC drivers (most notably on Windows and BSD systems) read
 the first capability registers using 1 and 2 bytes accesses, since
 this is how they are defined in section 5.3 of the xHCI specs.

 Enabling these kind of read accesses allows Windows and FreeBSD
 guests to properly recognize the host controller.

 As this is an exception to the general 4-byte aligned accesses rule,
 we special-case the code path for capability reading and implement
 checks to guard against wrong size/alignment combinations.

 No need to do that by hand, the memory api can handle it.  Can you check
 whenever usb-next
 (http://www.kraxel.org/cgit/qemu/log/?h=rebase/usb-next) works for you?

usb-next will fail to compile using -Werror with:
hcd-xhci.c: In function ‘xhci_fire_ctl_transfer’:
hcd-xhci.c:1508:14: error: variable ‘wLength’ set but not used
[-Werror=unused-but-set-variable]

It will also crash at runtime at
host-linux.c:usb_handle_control_packet(), since a NULL value is passed
from xhci_address_slot() for the USBPacket *p argument, and an assert
is testing for p-result == 0.

Other than that, this problem is resolved. I will perform further
testing and report back, since the in-tree xHC driver has never really
worked with any guest other than Linux.

Thanks,
  Alex



Re: [Qemu-devel] [PATCH 3/7] block: raw-posix image file reopen

2012-09-06 Thread Kevin Wolf
Am 05.09.2012 18:43, schrieb Jeff Cody:
 +}
 +
 +int fcntl_flags = O_APPEND | O_ASYNC | O_NONBLOCK;
 +#ifdef O_NOATIME
 +fcntl_flags |= O_NOATIME;
 +#endif
 +if ((raw_s-open_flags  ~fcntl_flags) == (s-open_flags  
 ~fcntl_flags)) {
 +/* dup the original fd */
 +/* TODO: use qemu fcntl wrapper */
 +raw_s-fd = fcntl(s-fd, F_DUPFD_CLOEXEC, 0);
 +if (raw_s-fd == -1) {
 +ret = -1;
 +goto error;
 +}
 +ret = fcntl_setfl(raw_s-fd, raw_s-open_flags);
 +} else {
 +raw_s-fd = qemu_open(state-bs-filename, raw_s-open_flags, 
 0644);
 +if (raw_s-fd == -1) {
 +ret = -1;
 +}

 Ignoring this part for now, with qemu_dup_flags() it's going to look a
 bit different. In particular, I'm hoping that we don't get a second
 fcntl_flags enumeration here, but can just fall back to qemu_open()
 whenever qemu_dup_flags() fails.
 
 That will require modification to qemu_dup_flags()... I believe
 qemu_dup_flags() silently filters out fcntl incompatible flags.
 
 Maybe it would be best to create a small helper function in osdep.c, that
 fetches the fcntl_flags.  Then qemu_dup_flags() and this function would
 use the same helper to fetch fcntl_flags.  The results of that would
 determine if we call qemu_dup_flags() or qemu_open().
 
 Although, I do think it makes sense to always try qemu_open() if
 qemu_dup_flags() fails for some reason.

If we can modify qemu_dup_flags() to fail if it can't provide the right
set of flags, then I think we should do it - and I think we can. Even
for the existing cases with fd passing it shouldn't break anything, but
only add an additional safety check.

And if touching the function motivates Corey to write some fd passing
test cases so that you can't break it, even better. ;-)

Kevin



Re: [Qemu-devel] [PATCH v6 2/2] block: Support GlusterFS as a QEMU block backend

2012-09-06 Thread Paolo Bonzini
Il 06/09/2012 11:06, Kevin Wolf ha scritto:
  If it works, I think this change would be preferrable to using a magic
  BH in every driver.
 The way it works in posix-aio-compat is that the request is first
 removed from the list and then the callback is called. This way
 posix_aio_flush() can return 0 and bdrv_drain_all() completes.

So the same could be done in gluster: first decrease qemu_aio_count,
then call the callback, then call qemu_aio_release.

But in either case, wouldn't that leak the AIOCBs until the end of
qcow2_create?

The AIOCB is already invalid at the time the callback is entered, so we
could release it before the call.  However, not all implementation of
AIO are ready for that and I'm not really in the mood for large scale
refactoring...

Paolo



[Qemu-devel] [PATCH 25/54] usb-redir: Set ep max_packet_size if available

2012-09-06 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

This is needed for usb-redir to work properly with the xhci emulation.

Signed-off-by: Hans de Goede hdego...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/redirect.c |5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index eeeb003..a91e073 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -805,6 +805,7 @@ static void usbredir_chardev_open(USBRedirDevice *dev)
 
 usbredirparser_caps_set_cap(caps, usb_redir_cap_connect_device_version);
 usbredirparser_caps_set_cap(caps, usb_redir_cap_filter);
+usbredirparser_caps_set_cap(caps, usb_redir_cap_ep_info_max_packet_size);
 usbredirparser_caps_set_cap(caps, usb_redir_cap_64bits_ids);
 usbredirparser_init(dev-parser, version, caps, USB_REDIR_CAPS_SIZE, 0);
 usbredirparser_do_write(dev-parser);
@@ -1180,6 +1181,10 @@ static void usbredir_ep_info(void *priv,
 i  0x0f);
 usb_ep-type = dev-endpoint[i].type;
 usb_ep-ifnum = dev-endpoint[i].interface;
+if (usbredirparser_peer_has_cap(dev-parser,
+ usb_redir_cap_ep_info_max_packet_size)) {
+usb_ep-max_packet_size = ep_info-max_packet_size[i];
+}
 }
 }
 
-- 
1.7.1




[Qemu-devel] [PATCH 10/54] ehci: check for EHCI_ASYNC_FINISHED first in ehci_free_packet

2012-09-06 Thread Gerd Hoffmann
Otherwise we'll see the packet free twice in the trace log even though
it actually happens only once.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-ehci.c |   12 ++--
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 0a6c9ef..23221d0 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -747,12 +747,6 @@ static EHCIPacket *ehci_alloc_packet(EHCIQueue *q)
 
 static void ehci_free_packet(EHCIPacket *p)
 {
-trace_usb_ehci_packet_action(p-queue, p, free);
-if (p-async == EHCI_ASYNC_INFLIGHT) {
-usb_cancel_packet(p-packet);
-usb_packet_unmap(p-packet, p-sgl);
-qemu_sglist_destroy(p-sgl);
-}
 if (p-async == EHCI_ASYNC_FINISHED) {
 int state = ehci_get_state(p-queue-ehci, p-queue-async);
 /* This is a normal, but rare condition (cancel racing completion) */
@@ -763,6 +757,12 @@ static void ehci_free_packet(EHCIPacket *p)
 /* state_writeback recurses into us with async == EHCI_ASYNC_NONE!! */
 return;
 }
+trace_usb_ehci_packet_action(p-queue, p, free);
+if (p-async == EHCI_ASYNC_INFLIGHT) {
+usb_cancel_packet(p-packet);
+usb_packet_unmap(p-packet, p-sgl);
+qemu_sglist_destroy(p-sgl);
+}
 QTAILQ_REMOVE(p-queue-packets, p, next);
 usb_packet_cleanup(p-packet);
 g_free(p);
-- 
1.7.1




[Qemu-devel] [PATCH 13/54] ehci: Add some additional ehci_trace_guest_bug() calls

2012-09-06 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

Signed-off-by: Hans de Goede hdego...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-ehci.c |   19 +--
 1 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 398f5e0..5a88268 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -820,12 +820,16 @@ static int ehci_reset_queue(EHCIQueue *q)
 return packets;
 }
 
-static void ehci_free_queue(EHCIQueue *q)
+static void ehci_free_queue(EHCIQueue *q, const char *warn)
 {
 EHCIQueueHead *head = q-async ? q-ehci-aqueues : q-ehci-pqueues;
+int cancelled;
 
 trace_usb_ehci_queue_action(q, free);
-ehci_cancel_queue(q);
+cancelled = ehci_cancel_queue(q);
+if (warn  cancelled  0) {
+ehci_trace_guest_bug(q-ehci, warn);
+}
 QTAILQ_REMOVE(head, q, next);
 g_free(q);
 }
@@ -847,6 +851,7 @@ static EHCIQueue *ehci_find_queue_by_qh(EHCIState *ehci, 
uint32_t addr,
 static void ehci_queues_rip_unused(EHCIState *ehci, int async, int flush)
 {
 EHCIQueueHead *head = async ? ehci-aqueues : ehci-pqueues;
+const char *warn = (async  !flush) ? guest unlinked busy QH : NULL;
 uint64_t maxage = FRAME_TIMER_NS * ehci-maxframes * 4;
 EHCIQueue *q, *tmp;
 
@@ -859,7 +864,7 @@ static void ehci_queues_rip_unused(EHCIState *ehci, int 
async, int flush)
 if (!flush  ehci-last_run_ns  q-ts + maxage) {
 continue;
 }
-ehci_free_queue(q);
+ehci_free_queue(q, warn);
 }
 }
 
@@ -872,17 +877,18 @@ static void ehci_queues_rip_device(EHCIState *ehci, 
USBDevice *dev, int async)
 if (q-dev != dev) {
 continue;
 }
-ehci_free_queue(q);
+ehci_free_queue(q, NULL);
 }
 }
 
 static void ehci_queues_rip_all(EHCIState *ehci, int async)
 {
 EHCIQueueHead *head = async ? ehci-aqueues : ehci-pqueues;
+const char *warn = async ? guest stopped busy async schedule : NULL;
 EHCIQueue *q, *tmp;
 
 QTAILQ_FOREACH_SAFE(q, head, next, tmp) {
-ehci_free_queue(q);
+ehci_free_queue(q, warn);
 }
 }
 
@@ -1549,7 +1555,8 @@ static int ehci_execute(EHCIPacket *p, const char *action)
 
 p-tbytes = (p-qtd.token  QTD_TOKEN_TBYTES_MASK)  QTD_TOKEN_TBYTES_SH;
 if (p-tbytes  BUFF_SIZE) {
-fprintf(stderr, Request for more bytes than allowed\n);
+ehci_trace_guest_bug(p-queue-ehci,
+ guest requested more bytes than allowed);
 return USB_RET_PROCERR;
 }
 
-- 
1.7.1




[Qemu-devel] [PATCH 03/54] usb-core: Add a usb_ep_find_packet_by_id() helper function

2012-09-06 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

Signed-off-by: Hans de Goede hdego...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb.h  |2 ++
 hw/usb/core.c |   15 +++
 2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/hw/usb.h b/hw/usb.h
index b8fceec..684e3f4 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -377,6 +377,8 @@ void usb_ep_set_max_packet_size(USBDevice *dev, int pid, 
int ep,
 uint16_t raw);
 int usb_ep_get_max_packet_size(USBDevice *dev, int pid, int ep);
 void usb_ep_set_pipeline(USBDevice *dev, int pid, int ep, bool enabled);
+USBPacket *usb_ep_find_packet_by_id(USBDevice *dev, int pid, int ep,
+uint64_t id);
 
 void usb_attach(USBPort *port);
 void usb_detach(USBPort *port);
diff --git a/hw/usb/core.c b/hw/usb/core.c
index be6d936..fe431d0 100644
--- a/hw/usb/core.c
+++ b/hw/usb/core.c
@@ -726,3 +726,18 @@ void usb_ep_set_pipeline(USBDevice *dev, int pid, int ep, 
bool enabled)
 struct USBEndpoint *uep = usb_ep_get(dev, pid, ep);
 uep-pipeline = enabled;
 }
+
+USBPacket *usb_ep_find_packet_by_id(USBDevice *dev, int pid, int ep,
+uint64_t id)
+{
+struct USBEndpoint *uep = usb_ep_get(dev, pid, ep);
+USBPacket *p;
+
+while ((p = QTAILQ_FIRST(uep-queue)) != NULL) {
+if (p-id == id) {
+return p;
+}
+}
+
+return NULL;
+}
-- 
1.7.1




Re: [Qemu-devel] [PATCH] usb: Fix host-side endian bugs in hcd-ehci

2012-09-06 Thread Gerd Hoffmann
On 08/22/12 05:04, David Gibson wrote:
 The EHCI device model is horribly broken for big-endian hosts.  It uses a
 union of 'mmio' a byte array which is as-is as the device's MMIO space
 with the various internal registers.  The IO routines assume that mmio is
 laid out in little-endian order, but everything else in the code accesses
 the register variables directly assuming (host) native endian.
 
 This fix is fairly ugly - a nicer approach would involve converting
 hcd-ehci to use the new-style memory region .read and .write functions -
 but it's the most minimal fix I can see to apply for the qemu 1.2 release.

Oops.  This one slipped through.  Just found it -- to late for 1.2 --
while wading through my inbox looking for unprocessed stuff.

Doing the real thing instead (i.e. convert memory regions) doesn't look
that horrible though, I think we can put that into stable-1.2.  I'll
send out the patch in a few moments.

cheers,
  Gerd



[Qemu-devel] [PATCH] ehci: switch to new-style memory ops

2012-09-06 Thread Gerd Hoffmann
Also register different memory regions for capabilities,
operational registers and port status registers.  Create
separate tracepoints for operational regs and port status
regs.  Ditch a bunch of sanity checks because the memory
core will do this for us now.

Offloading the byte, word and dword access handling to the
memory core also has the side effect of fixing ehci register
access on bigendian hosts.

Cc: David Gibson da...@gibson.dropbear.id.au
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-ehci.c |  173 ++---
 trace-events  |9 ++-
 2 files changed, 90 insertions(+), 92 deletions(-)

diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 2f3e9c0..f5ba8e1 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -389,6 +389,9 @@ struct EHCIState {
 USBBus bus;
 qemu_irq irq;
 MemoryRegion mem;
+MemoryRegion mem_caps;
+MemoryRegion mem_opreg;
+MemoryRegion mem_ports;
 int companion_count;
 
 /* properties */
@@ -398,10 +401,10 @@ struct EHCIState {
  *  EHCI spec version 1.0 Section 2.3
  *  Host Controller Operational Registers
  */
+uint8_t caps[OPREGBASE];
 union {
-uint8_t mmio[MMIO_SIZE];
+uint32_t opreg[(PORTSC_BEGIN-OPREGBASE)/sizeof(uint32_t)];
 struct {
-uint8_t cap[OPREGBASE];
 uint32_t usbcmd;
 uint32_t usbsts;
 uint32_t usbintr;
@@ -411,9 +414,9 @@ struct EHCIState {
 uint32_t asynclistaddr;
 uint32_t notused[9];
 uint32_t configflag;
-uint32_t portsc[NB_PORTS];
 };
 };
+uint32_t portsc[NB_PORTS];
 
 /*
  *  Internal states, shadow registers, etc
@@ -471,22 +474,12 @@ static const char *ehci_state_names[] = {
 };
 
 static const char *ehci_mmio_names[] = {
-[CAPLENGTH] = CAPLENGTH,
-[HCIVERSION]= HCIVERSION,
-[HCSPARAMS] = HCSPARAMS,
-[HCCPARAMS] = HCCPARAMS,
 [USBCMD]= USBCMD,
 [USBSTS]= USBSTS,
 [USBINTR]   = USBINTR,
 [FRINDEX]   = FRINDEX,
 [PERIODICLISTBASE]  = P-LIST BASE,
 [ASYNCLISTADDR] = A-LIST ADDR,
-[PORTSC_BEGIN]  = PORTSC #0,
-[PORTSC_BEGIN + 4]  = PORTSC #1,
-[PORTSC_BEGIN + 8]  = PORTSC #2,
-[PORTSC_BEGIN + 12] = PORTSC #3,
-[PORTSC_BEGIN + 16] = PORTSC #4,
-[PORTSC_BEGIN + 20] = PORTSC #5,
 [CONFIGFLAG]= CONFIGFLAG,
 };
 
@@ -509,7 +502,8 @@ static const char *state2str(uint32_t state)
 
 static const char *addr2str(target_phys_addr_t addr)
 {
-return nr2str(ehci_mmio_names, ARRAY_SIZE(ehci_mmio_names), addr);
+return nr2str(ehci_mmio_names, ARRAY_SIZE(ehci_mmio_names),
+  addr + OPREGBASE);
 }
 
 static void ehci_trace_usbsts(uint32_t mask, int state)
@@ -1018,7 +1012,7 @@ static int ehci_register_companion(USBBus *bus, USBPort 
*ports[],
 }
 
 s-companion_count++;
-s-mmio[0x05] = (s-companion_count  4) | portcount;
+s-caps[0x05] = (s-companion_count  4) | portcount;
 
 return 0;
 }
@@ -1063,7 +1057,8 @@ static void ehci_reset(void *opaque)
 }
 }
 
-memset(s-mmio[OPREGBASE], 0x00, MMIO_SIZE - OPREGBASE);
+memset(s-opreg, 0x00, sizeof(s-opreg));
+memset(s-portsc, 0x00, sizeof(s-portsc));
 
 s-usbcmd = NB_MAXINTRATE  USBCMD_ITC_SH;
 s-usbsts = USBSTS_HALT;
@@ -1090,50 +1085,35 @@ static void ehci_reset(void *opaque)
 qemu_bh_cancel(s-async_bh);
 }
 
-static uint32_t ehci_mem_readb(void *ptr, target_phys_addr_t addr)
+static uint64_t ehci_caps_read(void *ptr, target_phys_addr_t addr,
+   unsigned size)
 {
 EHCIState *s = ptr;
-uint32_t val;
-
-val = s-mmio[addr];
-
-return val;
+return s-caps[addr];
 }
 
-static uint32_t ehci_mem_readw(void *ptr, target_phys_addr_t addr)
+static uint64_t ehci_opreg_read(void *ptr, target_phys_addr_t addr,
+unsigned size)
 {
 EHCIState *s = ptr;
 uint32_t val;
 
-val = s-mmio[addr] | (s-mmio[addr+1]  8);
-
+val = s-opreg[addr  2];
+trace_usb_ehci_opreg_read(addr + OPREGBASE, addr2str(addr), val);
 return val;
 }
 
-static uint32_t ehci_mem_readl(void *ptr, target_phys_addr_t addr)
+static uint64_t ehci_port_read(void *ptr, target_phys_addr_t addr,
+   unsigned size)
 {
 EHCIState *s = ptr;
 uint32_t val;
 
-val = s-mmio[addr] | (s-mmio[addr+1]  8) |
-  (s-mmio[addr+2]  16) | (s-mmio[addr+3]  24);
-
-trace_usb_ehci_mmio_readl(addr, addr2str(addr), val);
+val = s-portsc[addr  2];
+trace_usb_ehci_portsc_read(addr + PORTSC_BEGIN, addr  2, val);
 return val;
 }
 
-static void ehci_mem_writeb(void *ptr, target_phys_addr_t addr, uint32_t val)
-{
-fprintf(stderr, EHCI doesn't handle byte writes to MMIO\n);
-exit(1);
-}
-
-static void ehci_mem_writew(void *ptr, target_phys_addr_t 

[Qemu-devel] [PATCH 16/54] ehci: Correct a comment in fetchqtd packet processing

2012-09-06 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

Since my previous comment said Should never happen, I tried changing the
next line to an assert(0), which did not go well, which as the new comments
explains is logical if you think about it for a moment.

Signed-off-by: Hans de Goede hdego...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-ehci.c |5 -
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 2534394..2f3e9c0 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -2045,7 +2045,10 @@ static int ehci_state_fetchqtd(EHCIQueue *q)
 ehci_set_state(q-ehci, q-async, EST_HORIZONTALQH);
 break;
 case EHCI_ASYNC_FINISHED:
-/* Should never happen, as this case is caught by fetchqh */
+/*
+ * We get here when advqueue moves to a packet which is already
+ * finished, which can happen with packets queued up by fill_queue
+ */
 ehci_set_state(q-ehci, q-async, EST_EXECUTING);
 break;
 }
-- 
1.7.1




[Qemu-devel] [PATCH 26/54] usb-redir: Add a usbredir_reject_device helper function

2012-09-06 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

Signed-off-by: Hans de Goede hdego...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/redirect.c |   21 +++--
 1 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index a91e073..c518201 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -811,16 +811,21 @@ static void usbredir_chardev_open(USBRedirDevice *dev)
 usbredirparser_do_write(dev-parser);
 }
 
+static void usbredir_reject_device(USBRedirDevice *dev)
+{
+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);
+}
+}
+
 static void usbredir_do_attach(void *opaque)
 {
 USBRedirDevice *dev = opaque;
 
 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);
-}
+usbredir_reject_device(dev);
 }
 }
 
@@ -986,11 +991,7 @@ static int usbredir_check_filter(USBRedirDevice *dev)
 return 0;
 
 error:
-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);
-}
+usbredir_reject_device(dev);
 return -1;
 }
 
-- 
1.7.1




[Qemu-devel] [PATCH 05/54] Revert ehci: don't flush cache on doorbell rings.

2012-09-06 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

This reverts commit 9bc3a3a216e2689bfcdd36c3e079333bbdbf3ba0, which got
added to fix an issue where the real, underlying cause was not stopping
the ep queue on an error.

Now that the underlying cause is fixed by the usb: Halt ep queue and
cancel pending packets on a packet error patch, the don't flush fix
is no longer needed.

Not only is it not needed, it causes us to see cancellations (unlinks)
done by the Linux EHCI driver too late, which in combination with the new
usb-core packet-id generation where qtd addresses are used as ids, causes
duplicate ids for in flight packets.

Signed-off-by: Hans de Goede hdego...@redhat.com
---
 hw/usb/hcd-ehci.c |   35 ++-
 1 files changed, 6 insertions(+), 29 deletions(-)

diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 9523247..e7c36f4 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -365,7 +365,6 @@ struct EHCIQueue {
 uint32_t seen;
 uint64_t ts;
 int async;
-int revalidate;
 
 /* cached data from guest - needs to be flushed
  * when guest removes an entry (doorbell, handshake sequence)
@@ -805,18 +804,7 @@ static EHCIQueue *ehci_find_queue_by_qh(EHCIState *ehci, 
uint32_t addr,
 return NULL;
 }
 
-static void ehci_queues_tag_unused_async(EHCIState *ehci)
-{
-EHCIQueue *q;
-
-QTAILQ_FOREACH(q, ehci-aqueues, next) {
-if (!q-seen) {
-q-revalidate = 1;
-}
-}
-}
-
-static void ehci_queues_rip_unused(EHCIState *ehci, int async)
+static void ehci_queues_rip_unused(EHCIState *ehci, int async, int flush)
 {
 EHCIQueueHead *head = async ? ehci-aqueues : ehci-pqueues;
 uint64_t maxage = FRAME_TIMER_NS * ehci-maxframes * 4;
@@ -828,7 +816,7 @@ static void ehci_queues_rip_unused(EHCIState *ehci, int 
async)
 q-ts = ehci-last_run_ns;
 continue;
 }
-if (ehci-last_run_ns  q-ts + maxage) {
+if (!flush  ehci-last_run_ns  q-ts + maxage) {
 continue;
 }
 ehci_free_queue(q);
@@ -1684,7 +1672,7 @@ static int ehci_state_waitlisthead(EHCIState *ehci,  int 
async)
 ehci_set_usbsts(ehci, USBSTS_REC);
 }
 
-ehci_queues_rip_unused(ehci, async);
+ehci_queues_rip_unused(ehci, async, 0);
 
 /*  Find the head of the list (4.9.1.1) */
 for(i = 0; i  MAX_QH; i++) {
@@ -1769,7 +1757,6 @@ static EHCIQueue *ehci_state_fetchqh(EHCIState *ehci, int 
async)
 EHCIPacket *p;
 uint32_t entry, devaddr;
 EHCIQueue *q;
-EHCIqh qh;
 
 entry = ehci_get_fetch_addr(ehci, async);
 q = ehci_find_queue_by_qh(ehci, entry, async);
@@ -1787,17 +1774,7 @@ static EHCIQueue *ehci_state_fetchqh(EHCIState *ehci, 
int async)
 }
 
 get_dwords(ehci, NLPTR_GET(q-qhaddr),
-   (uint32_t *) qh, sizeof(EHCIqh)  2);
-if (q-revalidate  (q-qh.epchar  != qh.epchar ||
-  q-qh.epcap   != qh.epcap  ||
-  q-qh.current_qtd != qh.current_qtd)) {
-ehci_free_queue(q);
-q = ehci_alloc_queue(ehci, entry, async);
-q-seen++;
-p = NULL;
-}
-q-qh = qh;
-q-revalidate = 0;
+   (uint32_t *) q-qh, sizeof(EHCIqh)  2);
 ehci_trace_qh(q, NLPTR_GET(q-qhaddr), q-qh);
 
 devaddr = get_field(q-qh.epchar, QH_EPCHAR_DEVADDR);
@@ -2306,7 +2283,7 @@ static void ehci_advance_async_state(EHCIState *ehci)
  */
 if (ehci-usbcmd  USBCMD_IAAD) {
 /* Remove all unseen qhs from the async qhs queue */
-ehci_queues_tag_unused_async(ehci);
+ehci_queues_rip_unused(ehci, async, 1);
 DPRINTF(ASYNC: doorbell request acknowledged\n);
 ehci-usbcmd = ~USBCMD_IAAD;
 ehci_raise_irq(ehci, USBSTS_IAA);
@@ -2359,7 +2336,7 @@ static void ehci_advance_periodic_state(EHCIState *ehci)
 ehci_set_fetch_addr(ehci, async,entry);
 ehci_set_state(ehci, async, EST_FETCHENTRY);
 ehci_advance_state(ehci, async);
-ehci_queues_rip_unused(ehci, async);
+ehci_queues_rip_unused(ehci, async, 0);
 break;
 
 default:
-- 
1.7.1




[Qemu-devel] [PATCH 12/14] spice: make number of surfaces runtime-configurable.

2012-09-06 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/qxl.c   |   31 +--
 hw/qxl.h   |3 +--
 ui/spice-display.c |5 -
 ui/spice-display.h |3 +--
 4 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/hw/qxl.c b/hw/qxl.c
index adf17fd..8725f67 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -236,7 +236,8 @@ static void 
qxl_spice_destroy_surfaces_complete(PCIQXLDevice *qxl)
 {
 trace_qxl_spice_destroy_surfaces_complete(qxl-id);
 qemu_mutex_lock(qxl-track_lock);
-memset(qxl-guest_surfaces.cmds, 0, sizeof(qxl-guest_surfaces.cmds));
+memset(qxl-guest_surfaces.cmds, 0,
+   sizeof(qxl-guest_surfaces.cmds) * qxl-ssd.num_surfaces);
 qxl-guest_surfaces.count = 0;
 qemu_mutex_unlock(qxl-track_lock);
 }
@@ -345,7 +346,7 @@ static void init_qxl_rom(PCIQXLDevice *d)
 rom-slot_id_bits  = MEMSLOT_SLOT_BITS;
 rom-slots_start   = 1;
 rom-slots_end = NUM_MEMSLOTS - 1;
-rom-n_surfaces= cpu_to_le32(NUM_SURFACES);
+rom-n_surfaces= cpu_to_le32(d-ssd.num_surfaces);
 
 for (i = 0, n = 0; i  ARRAY_SIZE(qxl_modes); i++) {
 fb = qxl_modes[i].y_res * qxl_modes[i].stride;
@@ -449,9 +450,9 @@ static int qxl_track_command(PCIQXLDevice *qxl, struct 
QXLCommandExt *ext)
 }
 uint32_t id = le32_to_cpu(cmd-surface_id);
 
-if (id = NUM_SURFACES) {
+if (id = qxl-ssd.num_surfaces) {
 qxl_set_guest_bug(qxl, QXL_CMD_SURFACE id %d = %d, id,
-  NUM_SURFACES);
+  qxl-ssd.num_surfaces);
 return 1;
 }
 qemu_mutex_lock(qxl-track_lock);
@@ -527,7 +528,7 @@ static void interface_get_init_info(QXLInstance *sin, 
QXLDevInitInfo *info)
 info-num_memslots_groups = NUM_MEMSLOTS_GROUPS;
 info-internal_groupslot_id = 0;
 info-qxl_ram_size = le32_to_cpu(qxl-shadow_rom.num_pages)  
TARGET_PAGE_BITS;
-info-n_surfaces = NUM_SURFACES;
+info-n_surfaces = qxl-ssd.num_surfaces;
 }
 
 static const char *qxl_mode_to_string(int mode)
@@ -1436,7 +1437,7 @@ async_common:
 QXLCookie *cookie = NULL;
 QXLRect update = d-ram-update_area;
 
-if (d-ram-update_surface  NUM_SURFACES) {
+if (d-ram-update_surface  d-ssd.num_surfaces) {
 qxl_set_guest_bug(d, QXL_IO_UPDATE_AREA: invalid surface id %d\n,
   d-ram-update_surface);
 return;
@@ -1529,7 +1530,7 @@ async_common:
 }
 break;
 case QXL_IO_DESTROY_SURFACE_WAIT:
-if (val = NUM_SURFACES) {
+if (val = d-ssd.num_surfaces) {
 qxl_set_guest_bug(d, QXL_IO_DESTROY_SURFACE (async=%d):
  % PRIu64  = NUM_SURFACES, async, val);
 goto cancel_async;
@@ -1707,7 +1708,7 @@ static void qxl_dirty_surfaces(PCIQXLDevice *qxl)
 vram_start =  (intptr_t)memory_region_get_ram_ptr(qxl-vram_bar);
 
 /* dirty the off-screen surfaces */
-for (i = 0; i  NUM_SURFACES; i++) {
+for (i = 0; i  qxl-ssd.num_surfaces; i++) {
 QXLSurfaceCmd *cmd;
 intptr_t surface_offset;
 int surface_size;
@@ -1835,7 +1836,6 @@ static int qxl_init_common(PCIQXLDevice *qxl)
 qxl-mode = QXL_MODE_UNDEFINED;
 qxl-generation = 1;
 qxl-num_memslots = NUM_MEMSLOTS;
-qxl-num_surfaces = NUM_SURFACES;
 qemu_mutex_init(qxl-track_lock);
 qemu_mutex_init(qxl-async_lock);
 qxl-current_async = QXL_UNDEFINED_IO;
@@ -1877,6 +1877,7 @@ static int qxl_init_common(PCIQXLDevice *qxl)
 init_qxl_rom(qxl);
 init_qxl_ram(qxl);
 
+qxl-guest_surfaces.cmds = g_new0(QXLPHYSICAL, qxl-ssd.num_surfaces);
 memory_region_init_ram(qxl-vram_bar, qxl.vram, qxl-vram_size);
 vmstate_register_ram(qxl-vram_bar, qxl-pci.qdev);
 memory_region_init_alias(qxl-vram32_bar, qxl.vram32, qxl-vram_bar,
@@ -2042,8 +2043,8 @@ static int qxl_post_load(void *opaque, int version)
 qxl_create_guest_primary(d, 1, QXL_SYNC);
 
 /* replay surface-create and cursor-set commands */
-cmds = g_malloc0(sizeof(QXLCommandExt) * (NUM_SURFACES + 1));
-for (in = 0, out = 0; in  NUM_SURFACES; in++) {
+cmds = g_malloc0(sizeof(QXLCommandExt) * (d-ssd.num_surfaces + 1));
+for (in = 0, out = 0; in  d-ssd.num_surfaces; in++) {
 if (d-guest_surfaces.cmds[in] == 0) {
 continue;
 }
@@ -2143,9 +2144,10 @@ static VMStateDescription qxl_vmstate = {
  qxl_memslot, struct guest_slots),
 VMSTATE_STRUCT(guest_primary.surface, PCIQXLDevice, 0,
qxl_surface, QXLSurfaceCreate),
-VMSTATE_INT32_EQUAL(num_surfaces, PCIQXLDevice),
-VMSTATE_ARRAY(guest_surfaces.cmds, PCIQXLDevice, NUM_SURFACES, 0,
-  vmstate_info_uint64, uint64_t),
+VMSTATE_INT32_EQUAL(ssd.num_surfaces, PCIQXLDevice),
+VMSTATE_VARRAY_INT32(guest_surfaces.cmds, 

Re: [Qemu-devel] [PATCH v6 2/2] block: Support GlusterFS as a QEMU block backend

2012-09-06 Thread Kevin Wolf
Am 06.09.2012 11:38, schrieb Paolo Bonzini:
 Il 06/09/2012 11:06, Kevin Wolf ha scritto:
 If it works, I think this change would be preferrable to using a magic
 BH in every driver.
 The way it works in posix-aio-compat is that the request is first
 removed from the list and then the callback is called. This way
 posix_aio_flush() can return 0 and bdrv_drain_all() completes.
 
 So the same could be done in gluster: first decrease qemu_aio_count,
 then call the callback, then call qemu_aio_release.
 
 But in either case, wouldn't that leak the AIOCBs until the end of
 qcow2_create?
 
 The AIOCB is already invalid at the time the callback is entered, so we
 could release it before the call.  However, not all implementation of
 AIO are ready for that and I'm not really in the mood for large scale
 refactoring...

But the way, what I'd really want to see in the end is to get rid of
qemu_aio_flush() and replace it by .bdrv_drain() callbacks in each
BlockDriver. The way we're doing it today is a layering violation.

Doesn't change anything about this problem, though. So the options that
we have are:

1. Delay the callback using a BH. Doing this in each driver is ugly.
   But is there actually more than one possible callback in today's
   coroutine world? I only see bdrv_co_io_em_complete(), which could
   reenter the coroutine from a BH.

2. Delay the callback by just calling it later when the cleanup has
   been completed and .io_flush() can return 0. You say that it's hard
   to implement for some drivers, except if the AIOCB are leaked until
   the end of functions like qcow2_create().

3. Add a delay only later in functions like bdrv_drain_all() that assume
   that the request has completed. Are there more of this type? AIOCBs
   are leaked until a bdrv_drain_all() call. Does it work with draining
   specific BDSes instead of everything?

Unless I forgot some important point, it almost looks like option 1 is
the easiest and safest.

Kevin



[Qemu-devel] [PATCH 53/54] xhci: kill xhci_mem_{read, write} dispatcher functions

2012-09-06 Thread Gerd Hoffmann
... and register subregions instead, so we offload the dispatching
to the the memory subsystem which is designed to handle it.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-xhci.c |  140 
 1 files changed, 75 insertions(+), 65 deletions(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 55e31ec..500892d 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -404,6 +404,10 @@ struct XHCIState {
 USBBus bus;
 qemu_irq irq;
 MemoryRegion mem;
+MemoryRegion mem_cap;
+MemoryRegion mem_oper;
+MemoryRegion mem_runtime;
+MemoryRegion mem_doorbell;
 const char *name;
 unsigned int devaddr;
 
@@ -2345,8 +2349,9 @@ static void xhci_reset(DeviceState *dev)
 xhci_mfwrap_update(xhci);
 }
 
-static uint32_t xhci_cap_read(XHCIState *xhci, uint32_t reg)
+static uint64_t xhci_cap_read(void *ptr, target_phys_addr_t reg, unsigned size)
 {
+XHCIState *xhci = ptr;
 uint32_t ret;
 
 switch (reg) {
@@ -2403,7 +2408,7 @@ static uint32_t xhci_cap_read(XHCIState *xhci, uint32_t 
reg)
 ret = 0x; /* reserved */
 break;
 default:
-fprintf(stderr, xhci_cap_read: reg %d unimplemented\n, reg);
+fprintf(stderr, xhci_cap_read: reg %d unimplemented\n, (int)reg);
 ret = 0;
 }
 
@@ -2484,8 +2489,9 @@ static void xhci_port_write(XHCIState *xhci, uint32_t 
reg, uint32_t val)
 }
 }
 
-static uint32_t xhci_oper_read(XHCIState *xhci, uint32_t reg)
+static uint64_t xhci_oper_read(void *ptr, target_phys_addr_t reg, unsigned 
size)
 {
+XHCIState *xhci = ptr;
 uint32_t ret;
 
 if (reg = 0x400) {
@@ -2521,7 +2527,7 @@ static uint32_t xhci_oper_read(XHCIState *xhci, uint32_t 
reg)
 ret = xhci-config;
 break;
 default:
-fprintf(stderr, xhci_oper_read: reg 0x%x unimplemented\n, reg);
+fprintf(stderr, xhci_oper_read: reg 0x%x unimplemented\n, (int)reg);
 ret = 0;
 }
 
@@ -2529,8 +2535,11 @@ static uint32_t xhci_oper_read(XHCIState *xhci, uint32_t 
reg)
 return ret;
 }
 
-static void xhci_oper_write(XHCIState *xhci, uint32_t reg, uint32_t val)
+static void xhci_oper_write(void *ptr, target_phys_addr_t reg,
+uint64_t val, unsigned size)
 {
+XHCIState *xhci = ptr;
+
 if (reg = 0x400) {
 xhci_port_write(xhci, reg - 0x400, val);
 return;
@@ -2588,12 +2597,14 @@ static void xhci_oper_write(XHCIState *xhci, uint32_t 
reg, uint32_t val)
 xhci-config = val  0xff;
 break;
 default:
-fprintf(stderr, xhci_oper_write: reg 0x%x unimplemented\n, reg);
+fprintf(stderr, xhci_oper_write: reg 0x%x unimplemented\n, (int)reg);
 }
 }
 
-static uint32_t xhci_runtime_read(XHCIState *xhci, uint32_t reg)
+static uint64_t xhci_runtime_read(void *ptr, target_phys_addr_t reg,
+  unsigned size)
 {
+XHCIState *xhci = ptr;
 uint32_t ret = 0;
 
 if (reg  0x20) {
@@ -2602,7 +2613,8 @@ static uint32_t xhci_runtime_read(XHCIState *xhci, 
uint32_t reg)
 ret = xhci_mfindex_get(xhci)  0x3fff;
 break;
 default:
-fprintf(stderr, xhci_runtime_read: reg 0x%x unimplemented\n, 
reg);
+fprintf(stderr, xhci_runtime_read: reg 0x%x unimplemented\n,
+(int)reg);
 break;
 }
 } else {
@@ -2637,14 +2649,16 @@ static uint32_t xhci_runtime_read(XHCIState *xhci, 
uint32_t reg)
 return ret;
 }
 
-static void xhci_runtime_write(XHCIState *xhci, uint32_t reg, uint32_t val)
+static void xhci_runtime_write(void *ptr, target_phys_addr_t reg,
+   uint64_t val, unsigned size)
 {
+XHCIState *xhci = ptr;
 int v = (reg - 0x20) / 0x20;
 XHCIInterrupter *intr = xhci-intr[v];
 trace_usb_xhci_runtime_write(reg, val);
 
 if (reg  0x20) {
-fprintf(stderr, xhci_oper_write: reg 0x%x unimplemented\n, reg);
+fprintf(stderr, xhci_oper_write: reg 0x%x unimplemented\n, (int)reg);
 return;
 }
 
@@ -2686,19 +2700,24 @@ static void xhci_runtime_write(XHCIState *xhci, 
uint32_t reg, uint32_t val)
 xhci_events_update(xhci, v);
 break;
 default:
-fprintf(stderr, xhci_oper_write: reg 0x%x unimplemented\n, reg);
+fprintf(stderr, xhci_oper_write: reg 0x%x unimplemented\n,
+(int)reg);
 }
 }
 
-static uint32_t xhci_doorbell_read(XHCIState *xhci, uint32_t reg)
+static uint64_t xhci_doorbell_read(void *ptr, target_phys_addr_t reg,
+   unsigned size)
 {
 /* doorbells always read as 0 */
 trace_usb_xhci_doorbell_read(reg, 0);
 return 0;
 }
 
-static void xhci_doorbell_write(XHCIState *xhci, uint32_t reg, uint32_t val)
+static void xhci_doorbell_write(void *ptr, target_phys_addr_t reg,
+uint64_t val, unsigned size)
 {
+XHCIState *xhci = ptr;
+
 

[Qemu-devel] [PATCH 27/54] usb-redir: Ensure our peer has the necessary caps when redirecting to XHCI

2012-09-06 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

In order for redirection to work properly when redirecting to an emulated
XHCI controller, the usb-redir-host must support both
usb_redir_cap_ep_info_max_packet_size and usb_redir_cap_64bits_ids,
reject any devices redirected to an XHCI controller when these are not
supported.

Signed-off-by: Hans de Goede hdego...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/redirect.c |   11 +++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index c518201..7fb0fb3 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -824,6 +824,17 @@ static void usbredir_do_attach(void *opaque)
 {
 USBRedirDevice *dev = opaque;
 
+/* In order to work properly with XHCI controllers we need these caps */
+if ((dev-dev.port-speedmask  USB_SPEED_MASK_SUPER)  !(
+usbredirparser_peer_has_cap(dev-parser,
+usb_redir_cap_ep_info_max_packet_size) 
+usbredirparser_peer_has_cap(dev-parser,
+usb_redir_cap_64bits_ids))) {
+ERROR(usb-redir-host lacks capabilities needed for use with XHCI\n);
+usbredir_reject_device(dev);
+return;
+}
+
 if (usb_device_attach(dev-dev) != 0) {
 usbredir_reject_device(dev);
 }
-- 
1.7.1




Re: [Qemu-devel] [PATCH] xhci: allow 1 and 2 bytes accesses to capability registers

2012-09-06 Thread Gerd Hoffmann
  Hi,

 usb-next will fail to compile using -Werror with:
 hcd-xhci.c: In function ‘xhci_fire_ctl_transfer’:
 hcd-xhci.c:1508:14: error: variable ‘wLength’ set but not used
 [-Werror=unused-but-set-variable]

Fixed.

Which gcc is this?  Must be pretty cutting edge, even on Fedora 17 (gcc
4.7.0) I don't see that one ...

 It will also crash at runtime at
 host-linux.c:usb_handle_control_packet(), since a NULL value is passed
 from xhci_address_slot() for the USBPacket *p argument, and an assert
 is testing for p-result == 0.

Fixed  pushed to usb-next.

thanks,
  Gerd




[Qemu-devel] [PATCH 2/2] usb-host: allow emulated (non-async) control requests without USBPacket

2012-09-06 Thread Gerd Hoffmann
xhci needs this for USB_REQ_SET_ADDRESS due to the way
usb addressing is handled by the xhci hardware.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/host-linux.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/usb/host-linux.c b/hw/usb/host-linux.c
index 8df9207..44f1a64 100644
--- a/hw/usb/host-linux.c
+++ b/hw/usb/host-linux.c
@@ -1045,7 +1045,6 @@ 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, p, request, value, index);
-assert(p-result == 0);
 
 switch (request) {
 case DeviceOutRequest | USB_REQ_SET_ADDRESS:
@@ -1074,6 +1073,7 @@ static int usb_host_handle_control(USBDevice *dev, 
USBPacket *p,
 }
 
 /* The rest are asynchronous */
+assert(p  p-result == 0);
 
 if (length  sizeof(dev-data_buf)) {
 fprintf(stderr, husb: ctrl buffer too small (%d  %zu)\n,
-- 
1.7.1




[Qemu-devel] [PATCH 1/2] xhci: drop unused wlength

2012-09-06 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-xhci.c |2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 2918e64..e0ca690 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -1505,7 +1505,6 @@ static int xhci_fire_ctl_transfer(XHCIState *xhci, 
XHCITransfer *xfer)
 {
 XHCITRB *trb_setup, *trb_status;
 uint8_t bmRequestType;
-uint16_t wLength;
 int ret;
 
 trb_setup = xfer-trbs[0];
@@ -1540,7 +1539,6 @@ static int xhci_fire_ctl_transfer(XHCIState *xhci, 
XHCITransfer *xfer)
 }
 
 bmRequestType = trb_setup-parameter;
-wLength = trb_setup-parameter  48;
 
 xfer-in_xfer = bmRequestType  USB_DIR_IN;
 xfer-iso_xfer = false;
-- 
1.7.1




[Qemu-devel] [PATCH 32/54] xhci: drop buffering

2012-09-06 Thread Gerd Hoffmann
This patch splits the xhci_xfer_data function into three.
The xhci_xfer_data function used to do does two things:

  (1) copy transfer data between guest memory and a temporary buffer.
  (2) report transfer results to the guest using events.

Now we three functions to handle this:

  (1) xhci_xfer_map creates a scatter list for the transfer and
  uses that (instead of the temporary buffer) to build a
  USBPacket.
  (2) xhci_xfer_unmap undoes the mapping.
  (3) xhci_xfer_report sends out events.

The patch also fixes reporting of transaction errors which must be
reported unconditinally, not only in case the guest asks for it
using the ISP flag.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-xhci.c |  183 +
 trace-events  |2 +-
 2 files changed, 72 insertions(+), 113 deletions(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index c0a2476..c858b6d 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -305,6 +305,7 @@ typedef struct XHCIState XHCIState;
 typedef struct XHCITransfer {
 XHCIState *xhci;
 USBPacket packet;
+QEMUSGList sgl;
 bool running_async;
 bool running_retry;
 bool cancelled;
@@ -319,10 +320,6 @@ typedef struct XHCITransfer {
 unsigned int trb_alloced;
 XHCITRB *trbs;
 
-unsigned int data_length;
-unsigned int data_alloced;
-uint8_t *data;
-
 TRBCCode status;
 
 unsigned int pkts;
@@ -906,14 +903,9 @@ static int xhci_ep_nuke_xfers(XHCIState *xhci, unsigned 
int slotid,
 if (t-trbs) {
 g_free(t-trbs);
 }
-if (t-data) {
-g_free(t-data);
-}
 
 t-trbs = NULL;
-t-data = NULL;
 t-trb_count = t-trb_alloced = 0;
-t-data_length = t-data_alloced = 0;
 xferi = (xferi + 1) % TD_QUEUE;
 }
 return killed;
@@ -1072,24 +1064,13 @@ static TRBCCode xhci_set_ep_dequeue(XHCIState *xhci, 
unsigned int slotid,
 return CC_SUCCESS;
 }
 
-static int xhci_xfer_data(XHCITransfer *xfer, uint8_t *data,
-  unsigned int length, bool in_xfer, bool out_xfer,
-  bool report)
+static int xhci_xfer_map(XHCITransfer *xfer)
 {
-int i;
-uint32_t edtla = 0;
-unsigned int transferred = 0;
-unsigned int left = length;
-bool reported = 0;
-bool shortpkt = 0;
-XHCIEvent event = {ER_TRANSFER, CC_SUCCESS};
+int in_xfer = (xfer-packet.pid == USB_TOKEN_IN);
 XHCIState *xhci = xfer-xhci;
+int i;
 
-DPRINTF(xhci_xfer_data(len=%d, in_xfer=%d, out_xfer=%d, report=%d)\n,
-length, in_xfer, out_xfer, report);
-
-assert(!(in_xfer  out_xfer));
-
+pci_dma_sglist_init(xfer-sgl, xhci-pci_dev, xfer-trb_count);
 for (i = 0; i  xfer-trb_count; i++) {
 XHCITRB *trb = xfer-trbs[i];
 dma_addr_t addr;
@@ -1099,54 +1080,70 @@ static int xhci_xfer_data(XHCITransfer *xfer, uint8_t 
*data,
 case TR_DATA:
 if ((!(trb-control  TRB_TR_DIR)) != (!in_xfer)) {
 fprintf(stderr, xhci: data direction mismatch for TR_DATA\n);
-xhci_die(xhci);
-return transferred;
+goto err;
 }
 /* fallthrough */
 case TR_NORMAL:
 case TR_ISOCH:
 addr = xhci_mask64(trb-parameter);
 chunk = trb-status  0x1;
+if (trb-control  TRB_TR_IDT) {
+if (chunk  8 || in_xfer) {
+fprintf(stderr, xhci: invalid immediate data TRB\n);
+goto err;
+}
+qemu_sglist_add(xfer-sgl, trb-addr, chunk);
+} else {
+qemu_sglist_add(xfer-sgl, addr, chunk);
+}
+break;
+}
+}
+
+usb_packet_map(xfer-packet, xfer-sgl);
+return 0;
+
+err:
+qemu_sglist_destroy(xfer-sgl);
+xhci_die(xhci);
+return -1;
+}
+
+static void xhci_xfer_unmap(XHCITransfer *xfer)
+{
+usb_packet_unmap(xfer-packet, xfer-sgl);
+qemu_sglist_destroy(xfer-sgl);
+}
+
+static void xhci_xfer_report(XHCITransfer *xfer)
+{
+uint32_t edtla = 0;
+unsigned int left;
+bool reported = 0;
+bool shortpkt = 0;
+XHCIEvent event = {ER_TRANSFER, CC_SUCCESS};
+XHCIState *xhci = xfer-xhci;
+int i;
+
+left = xfer-packet.result  0 ? 0 : xfer-packet.result;
+
+for (i = 0; i  xfer-trb_count; i++) {
+XHCITRB *trb = xfer-trbs[i];
+unsigned int chunk = 0;
+
+switch (TRB_TYPE(*trb)) {
+case TR_DATA:
+case TR_NORMAL:
+case TR_ISOCH:
+chunk = trb-status  0x1;
 if (chunk  left) {
 chunk = left;
-shortpkt = 1;
-}
-if (in_xfer || out_xfer) {
-if (trb-control  TRB_TR_IDT) {
-uint64_t idata;
-if (chunk  8 || in_xfer) {
-

Re: [Qemu-devel] [PATCH v6 2/2] block: Support GlusterFS as a QEMU block backend

2012-09-06 Thread Paolo Bonzini
Il 06/09/2012 12:07, Kevin Wolf ha scritto:
 The AIOCB is already invalid at the time the callback is entered, so we
 could release it before the call.  However, not all implementation of
 AIO are ready for that and I'm not really in the mood for large scale
 refactoring...
 
 But the way, what I'd really want to see in the end is to get rid of
 qemu_aio_flush() and replace it by .bdrv_drain() callbacks in each
 BlockDriver. The way we're doing it today is a layering violation.

That's quite difficult.  Completion of an I/O operation can trigger
another I/O operation on another block device, and so on until we go
back to the first device (think of a hypothetical RAID-5 device).

 Doesn't change anything about this problem, though. So the options that
 we have are:
 
 1. Delay the callback using a BH. Doing this in each driver is ugly.
But is there actually more than one possible callback in today's
coroutine world? I only see bdrv_co_io_em_complete(), which could
reenter the coroutine from a BH.

Easy and safe, but it feels a bit like a timebomb.  Also, I'm not
entirely sure of _why_ the bottom half works. :)

 2. Delay the callback by just calling it later when the cleanup has
been completed and .io_flush() can return 0. You say that it's hard
to implement for some drivers, except if the AIOCB are leaked until
the end of functions like qcow2_create().

... which is what we do in posix-aio-compat.c; nobody screamed so far.

Not really hard, it just has to be assessed for each driver separately.
 We can just do it in gluster and refactor it later.

 3. Add a delay only later in functions like bdrv_drain_all() that assume
that the request has completed. Are there more of this type? AIOCBs
are leaked until a bdrv_drain_all() call. Does it work with draining
specific BDSes instead of everything?
 
 Unless I forgot some important point, it almost looks like option 1 is
 the easiest and safest.

I agree with your opinion, but I would feel better if I understood
better why it works.  (2) can be done easily in each driver (no
ugliness) and refactored later.

Paolo



[Qemu-devel] [PATCH 07/54] ehci: Update copyright headers to reflect recent work

2012-09-06 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

Update copyright headers to reflect all the work Gerd and I have been doing
on the EHCI emulation.

Signed-off-by: Hans de Goede hdego...@redhat.com
---
 hw/usb/hcd-ehci.c |5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 35eb441..78a248f 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -2,6 +2,11 @@
  * QEMU USB EHCI Emulation
  *
  * Copyright(c) 2008  Emutex Ltd. (address@hidden)
+ * Copyright(c) 2011-2012 Red Hat, Inc.
+ *
+ * Red Hat Authors:
+ * Gerd Hoffmann kra...@redhat.com
+ * Hans de Goede hdego...@redhat.com
  *
  * EHCI project was started by Mark Burkley, with contributions by
  * Niels de Vos.  David S. Ahern continued working on it.  Kevin Wolf,
-- 
1.7.1




Re: [Qemu-devel] [PATCH] target-i386: Allow changing of Hypervisor CPUIDs.

2012-09-06 Thread Andreas Färber
Am 30.08.2012 21:20, schrieb Don Slutz:
 This is primarily done so that the guest will think it is running
 under vmware when hypervisor=vmware is specified as a property of a
 cpu.
 
 Also allow this to work in accel=tcg mode.
 
 The new cpu properties hyper_level, hyper_extra, hyper_extra_a, and
 hyper_extra_b can be used to further adjust what the guest sees.
 
 Signed-off-by: Don Slutz d...@cloudswitch.com
 ---
  target-i386/cpu.c |  178 
 +
  target-i386/cpu.h |9 +++
  target-i386/kvm.c |   33 --
  3 files changed, 214 insertions(+), 6 deletions(-)

Please don't add new CPU command line options without matching QOM
properties. There are patch series in the works that convert the CPU
definitions to QOM subclasses, the parameters then need to be set on the
X86CPU object instance.

Note that the convention for QOM properties is
descriptive-name-with-dashes rather than shortened_abbrev_with_underscore.

Regards,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg



Re: [Qemu-devel] [PATCH v6 2/2] block: Support GlusterFS as a QEMU block backend

2012-09-06 Thread Kevin Wolf
Am 06.09.2012 12:18, schrieb Paolo Bonzini:
 Il 06/09/2012 12:07, Kevin Wolf ha scritto:
 The AIOCB is already invalid at the time the callback is entered, so we
 could release it before the call.  However, not all implementation of
 AIO are ready for that and I'm not really in the mood for large scale
 refactoring...

 But the way, what I'd really want to see in the end is to get rid of
 qemu_aio_flush() and replace it by .bdrv_drain() callbacks in each
 BlockDriver. The way we're doing it today is a layering violation.
 
 That's quite difficult.  Completion of an I/O operation can trigger
 another I/O operation on another block device, and so on until we go
 back to the first device (think of a hypothetical RAID-5 device).

You always have a tree of BDSes, and children should only ever trigger
completion of I/O operations in their parents. Am I missing anything?

 Doesn't change anything about this problem, though. So the options that
 we have are:

 1. Delay the callback using a BH. Doing this in each driver is ugly.
But is there actually more than one possible callback in today's
coroutine world? I only see bdrv_co_io_em_complete(), which could
reenter the coroutine from a BH.
 
 Easy and safe, but it feels a bit like a timebomb.  Also, I'm not
 entirely sure of _why_ the bottom half works. :)

Hm, safe and time bomb is contradictory in my book. :-)

The bottom half work because we're not reentering the qcow2_create
coroutine immediately, so the gluster AIO callback can complete all of
its cleanup work without being interrupted by code that might wait on
this particular request and create a deadlock this way.

 2. Delay the callback by just calling it later when the cleanup has
been completed and .io_flush() can return 0. You say that it's hard
to implement for some drivers, except if the AIOCB are leaked until
the end of functions like qcow2_create().
 
 ... which is what we do in posix-aio-compat.c; nobody screamed so far.

True. Would be easy to fix in posix-aio-compat, though, or can a
callback expect that the AIOCB is still valid?

 Not really hard, it just has to be assessed for each driver separately.
  We can just do it in gluster and refactor it later.

Okay, so let's keep it as an option for now.

 3. Add a delay only later in functions like bdrv_drain_all() that assume
that the request has completed. Are there more of this type? AIOCBs
are leaked until a bdrv_drain_all() call. Does it work with draining
specific BDSes instead of everything?

 Unless I forgot some important point, it almost looks like option 1 is
 the easiest and safest.
 
 I agree with your opinion, but I would feel better if I understood
 better why it works.  (2) can be done easily in each driver (no
 ugliness) and refactored later.

I think option 2 must be done in each driver by design, or do you see
even a theoretical way how to do it generically?

Kevin



Re: [Qemu-devel] [PATCH v2 0/4] CHECKPATCH: Add warning for single else statement.

2012-09-06 Thread Andreas Färber
Am 05.09.2012 21:46, schrieb Blue Swirl:
 Thanks, applied all.

Question: Are additions to checkpatch.pl supposed to be in QEMU Coding
Style as done here? Do you plan to convert it consistently then?
checkpatch.pl uses tabs consistently, making checkpatch.pl complain. ;)
The alternative would be to stick to upstream formatting and exempt
checkpatch.pl from its own checks.

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg



Re: [Qemu-devel] [PATCH] xhci: allow 1 and 2 bytes accesses to capability registers

2012-09-06 Thread Alejandro Martinez
Hi Gerd,

On Thu, Sep 6, 2012 at 12:15 PM, Gerd Hoffmann kra...@redhat.com wrote:
   Hi,

 usb-next will fail to compile using -Werror with:
 hcd-xhci.c: In function ‘xhci_fire_ctl_transfer’:
 hcd-xhci.c:1508:14: error: variable ‘wLength’ set but not used
 [-Werror=unused-but-set-variable]

 Fixed.

 Which gcc is this?  Must be pretty cutting edge, even on Fedora 17 (gcc
 4.7.0) I don't see that one ...

Actually it is from OpenSuSE's 12.1 rpm, at version 4.6.2.

 It will also crash at runtime at
 host-linux.c:usb_handle_control_packet(), since a NULL value is passed
 from xhci_address_slot() for the USBPacket *p argument, and an assert
 is testing for p-result == 0.

 Fixed  pushed to usb-next.

Thanks, will try it out.

Thanks,
  Alex



[Qemu-devel] [PATCH 31/54] xhci: rip out background transfer code

2012-09-06 Thread Gerd Hoffmann
original xhci code (the one which used libusb directly) used to use
'background transfers' for iso streams.  In upstream qemu the iso
stream buffering is handled by usb-host  usb-redir, so we will
never ever need this.  It has been left in as reference, but is dead
code anyway.  Rip it out.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-xhci.c |  223 +
 1 files changed, 4 insertions(+), 219 deletions(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 3eb27fa..c0a2476 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -45,8 +45,6 @@
 #define MAXPORTS (USB2_PORTS+USB3_PORTS)
 
 #define TD_QUEUE 24
-#define BG_XFERS 8
-#define BG_PKTS 8
 
 /* Very pessimistic, let's hope it's enough for all cases */
 #define EV_QUEUE (((3*TD_QUEUE)+16)*MAXSLOTS)
@@ -311,13 +309,11 @@ typedef struct XHCITransfer {
 bool running_retry;
 bool cancelled;
 bool complete;
-bool backgrounded;
 unsigned int iso_pkts;
 unsigned int slotid;
 unsigned int epid;
 bool in_xfer;
 bool iso_xfer;
-bool bg_xfer;
 
 unsigned int trb_count;
 unsigned int trb_alloced;
@@ -340,14 +336,9 @@ typedef struct XHCIEPContext {
 unsigned int comp_xfer;
 XHCITransfer transfers[TD_QUEUE];
 XHCITransfer *retry;
-bool bg_running;
-bool bg_updating;
-unsigned int next_bg;
-XHCITransfer bg_transfers[BG_XFERS];
 EPType type;
 dma_addr_t pctx;
 unsigned int max_psize;
-bool has_bg;
 uint32_t state;
 } XHCIEPContext;
 
@@ -866,10 +857,6 @@ static TRBCCode xhci_enable_ep(XHCIState *xhci, unsigned 
int slotid,
 epctx-pctx = pctx;
 epctx-max_psize = ctx[1]16;
 epctx-max_psize *= 1+((ctx[1]8)0xff);
-epctx-has_bg = false;
-if (epctx-type == ET_ISO_IN) {
-epctx-has_bg = true;
-}
 DPRINTF(xhci: endpoint %d.%d max transaction (burst) size is %d\n,
 epid/2, epid%2, epctx-max_psize);
 for (i = 0; i  ARRAY_SIZE(epctx-transfers); i++) {
@@ -916,9 +903,6 @@ static int xhci_ep_nuke_xfers(XHCIState *xhci, unsigned int 
slotid,
 t-running_retry = 0;
 epctx-retry = NULL;
 }
-if (t-backgrounded) {
-t-backgrounded = 0;
-}
 if (t-trbs) {
 g_free(t-trbs);
 }
@@ -932,25 +916,6 @@ static int xhci_ep_nuke_xfers(XHCIState *xhci, unsigned 
int slotid,
 t-data_length = t-data_alloced = 0;
 xferi = (xferi + 1) % TD_QUEUE;
 }
-if (epctx-has_bg) {
-xferi = epctx-next_bg;
-for (i = 0; i  BG_XFERS; i++) {
-XHCITransfer *t = epctx-bg_transfers[xferi];
-if (t-running_async) {
-usb_cancel_packet(t-packet);
-t-running_async = 0;
-t-cancelled = 1;
-DPRINTF(xhci: cancelling bg transfer %d, waiting for it to 
complete...\n, i);
-killed++;
-}
-if (t-data) {
-g_free(t-data);
-}
-
-t-data = NULL;
-xferi = (xferi + 1) % BG_XFERS;
-}
-}
 return killed;
 }
 
@@ -1231,160 +1196,6 @@ static void xhci_stall_ep(XHCITransfer *xfer)
 static int xhci_submit(XHCIState *xhci, XHCITransfer *xfer,
XHCIEPContext *epctx);
 
-static void xhci_bg_update(XHCIState *xhci, XHCIEPContext *epctx)
-{
-if (epctx-bg_updating) {
-return;
-}
-DPRINTF(xhci_bg_update(%p, %p)\n, xhci, epctx);
-assert(epctx-has_bg);
-DPRINTF(xhci: fg=%d bg=%d\n, epctx-comp_xfer, epctx-next_bg);
-epctx-bg_updating = 1;
-while (epctx-transfers[epctx-comp_xfer].backgrounded 
-   epctx-bg_transfers[epctx-next_bg].complete) {
-XHCITransfer *fg = epctx-transfers[epctx-comp_xfer];
-XHCITransfer *bg = epctx-bg_transfers[epctx-next_bg];
-#if 0
-DPRINTF(xhci: completing fg %d from bg %d.%d (stat: %d)\n,
-epctx-comp_xfer, epctx-next_bg, bg-cur_pkt,
-bg-usbxfer-iso_packet_desc[bg-cur_pkt].status
-   );
-#endif
-assert(epctx-type == ET_ISO_IN);
-assert(bg-iso_xfer);
-assert(bg-in_xfer);
-uint8_t *p = bg-data + bg-cur_pkt * bg-pktsize;
-#if 0
-int len = bg-usbxfer-iso_packet_desc[bg-cur_pkt].actual_length;
-fg-status = 
libusb_to_ccode(bg-usbxfer-iso_packet_desc[bg-cur_pkt].status);
-#else
-int len = 0;
-FIXME();
-#endif
-fg-complete = 1;
-fg-backgrounded = 0;
-
-if (fg-status == CC_STALL_ERROR) {
-xhci_stall_ep(fg);
-}
-
-xhci_xfer_data(fg, p, len, 1, 0, 1);
-
-epctx-comp_xfer++;
-if (epctx-comp_xfer == TD_QUEUE) {
-epctx-comp_xfer = 0;
-}
-DPRINTF(next fg xfer: %d\n, epctx-comp_xfer);
-bg-cur_pkt++;
-if (bg-cur_pkt == bg-pkts) {
-bg-complete = 0;
-if (xhci_submit(xhci, bg, epctx)  0) {

Re: [Qemu-devel] [PATCH 3/4] wakeup: make serial configurable

2012-09-06 Thread Gerd Hoffmann
On 09/06/12 09:48, Peter Maydell wrote:
 On 6 September 2012 08:42, Gerd Hoffmann kra...@redhat.com wrote:
 @@ -789,6 +790,13 @@ static int serial_isa_initfn(ISADevice *dev)
  isa-isairq = isa_serial_irq[isa-index];
  index++;

 +if (isa-iobase == 0x3f8) {
 +s-reason = QEMU_WAKEUP_REASON_GPE_a;
 +s-wakeup = 1;
 +} else {
 +s-reason = QEMU_WAKEUP_REASON_OTHER;
 +}
 +
 
 It seems a bit odd that this is done in the ISA serial model
 itself and not by the next level up wiring up some output
 of the ISA serial device to some appropriate input...

Suggestions how to do that are welcome.  Preferably some which don't
break on 'qemu -nodefault -device isa-serial,chardev=foo'.

cheers,
  Gerd




[Qemu-devel] [PATCH 08/54] ehci: Properly cleanup packets on cancel

2012-09-06 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

Signed-off-by: Hans de Goede hdego...@redhat.com
---
 hw/usb/hcd-ehci.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 78a248f..4fe85c8 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -747,6 +747,8 @@ static void ehci_free_packet(EHCIPacket *p)
 trace_usb_ehci_packet_action(p-queue, p, free);
 if (p-async == EHCI_ASYNC_INFLIGHT) {
 usb_cancel_packet(p-packet);
+usb_packet_unmap(p-packet, p-sgl);
+qemu_sglist_destroy(p-sgl);
 }
 QTAILQ_REMOVE(p-queue-packets, p, next);
 usb_packet_cleanup(p-packet);
-- 
1.7.1




[Qemu-devel] [PATCH 21/54] usb-redir: Get rid of unused async-struct dev member

2012-09-06 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

This is a preparation patch for completely getting rid of the async-packet
struct in usb-redir, instead relying on the (new) per ep queues in the
qemu usb core.

Signed-off-by: Hans de Goede hdego...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/redirect.c |2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index e4ef372..6593d50 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -96,7 +96,6 @@ struct USBRedirDevice {
 };
 
 struct AsyncURB {
-USBRedirDevice *dev;
 USBPacket *packet;
 uint32_t packet_id;
 QTAILQ_ENTRY(AsyncURB)next;
@@ -245,7 +244,6 @@ static int usbredir_write(void *priv, uint8_t *data, int 
count)
 static AsyncURB *async_alloc(USBRedirDevice *dev, USBPacket *p)
 {
 AsyncURB *aurb = (AsyncURB *) g_malloc0(sizeof(AsyncURB));
-aurb-dev = dev;
 aurb-packet = p;
 aurb-packet_id = dev-packet_id;
 QTAILQ_INSERT_TAIL(dev-asyncq, aurb, next);
-- 
1.7.1




Re: [Qemu-devel] [PATCH v6 2/2] block: Support GlusterFS as a QEMU block backend

2012-09-06 Thread Paolo Bonzini
Il 06/09/2012 12:29, Kevin Wolf ha scritto:
 That's quite difficult.  Completion of an I/O operation can trigger
 another I/O operation on another block device, and so on until we go
 back to the first device (think of a hypothetical RAID-5 device).
 
 You always have a tree of BDSes, and children should only ever trigger
 completion of I/O operations in their parents. Am I missing anything?

Yes, it can only ever trigger completion in the parents.  So if you had
bdrv_drain in the children, it could leave other I/O pending on the
siblings, but that's okay.  Very nice!!  I hadn't thought of the tree.

 Doesn't change anything about this problem, though. So the options that
 we have are:

 1. Delay the callback using a BH. Doing this in each driver is ugly.
But is there actually more than one possible callback in today's
coroutine world? I only see bdrv_co_io_em_complete(), which could
reenter the coroutine from a BH.

 Easy and safe, but it feels a bit like a timebomb.  Also, I'm not
 entirely sure of _why_ the bottom half works. :)
 
 Hm, safe and time bomb is contradictory in my book. :-)

Well, safe for now. :)

 The bottom half work because we're not reentering the qcow2_create
 coroutine immediately, so the gluster AIO callback can complete all of
 its cleanup work without being interrupted by code that might wait on
 this particular request and create a deadlock this way.

Got it now.  It's just (2) with a bottom half instead of simple code
reorganization.

 2. Delay the callback by just calling it later when the cleanup has
been completed and .io_flush() can return 0. You say that it's hard
to implement for some drivers, except if the AIOCB are leaked until
the end of functions like qcow2_create().

 ... which is what we do in posix-aio-compat.c; nobody screamed so far.
 
 True. Would be easy to fix in posix-aio-compat, though, or can a
 callback expect that the AIOCB is still valid?

IMO no.  What would you use it for, anyway?  It's opaque, all you could
do is bdrv_aio_cancel it.  I checked all of the callers of
bdrv_aio_cancel.  SCSI always zeroes their aiocb pointers on entry to
the AIO callback.  IDE is a bit less explicit, but in the end will
always zero the aiocb as well.  AHCI probably has a bug there (it does
not NULL the aiocb in ncq_cb).

virtio and Xen do not even store the aiocb, i.e. they couldn't care less.

 Not really hard, it just has to be assessed for each driver separately.
  We can just do it in gluster and refactor it later.
 
 Okay, so let's keep it as an option for now.
 
 3. Add a delay only later in functions like bdrv_drain_all() that assume
that the request has completed. Are there more of this type? AIOCBs
are leaked until a bdrv_drain_all() call. Does it work with draining
specific BDSes instead of everything?

 Unless I forgot some important point, it almost looks like option 1 is
 the easiest and safest.

 I agree with your opinion, but I would feel better if I understood
 better why it works.  (2) can be done easily in each driver (no
 ugliness) and refactored later.
 
 I think option 2 must be done in each driver by design, or do you see
 even a theoretical way how to do it generically?

Yes, it has to be done in every driver.  If we added something like
qemu_aio_complete(acb, ret) that does

cb = acb-cb;
opaque = acb-opaque;
qemu_aio_release(acb);
cb(opaque, ret);

by converting the driver to qemu_aio_complete you would avoid the leak.

Paolo



[Qemu-devel] [PATCH 06/54] ehci: Validate qh is not changed unexpectedly by the guest

2012-09-06 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

-combine the qh check with the check for devaddr changes
-also ensure that p gets set to NULL when the queue gets cancelled on
 devaddr change, which was not done properly before this patch

Signed-off-by: Hans de Goede hdego...@redhat.com
---
 hw/usb/hcd-ehci.c |   41 +
 1 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index e7c36f4..35eb441 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -780,6 +780,14 @@ static void ehci_cancel_queue(EHCIQueue *q)
 } while ((p = QTAILQ_FIRST(q-packets)) != NULL);
 }
 
+static void ehci_reset_queue(EHCIQueue *q)
+{
+trace_usb_ehci_queue_action(q, reset);
+ehci_cancel_queue(q);
+q-dev = NULL;
+q-qtdaddr = 0;
+}
+
 static void ehci_free_queue(EHCIQueue *q)
 {
 EHCIQueueHead *head = q-async ? q-ehci-aqueues : q-ehci-pqueues;
@@ -1755,8 +1763,9 @@ out:
 static EHCIQueue *ehci_state_fetchqh(EHCIState *ehci, int async)
 {
 EHCIPacket *p;
-uint32_t entry, devaddr;
+uint32_t entry, devaddr, endp;
 EHCIQueue *q;
+EHCIqh qh;
 
 entry = ehci_get_fetch_addr(ehci, async);
 q = ehci_find_queue_by_qh(ehci, entry, async);
@@ -1774,17 +1783,25 @@ static EHCIQueue *ehci_state_fetchqh(EHCIState *ehci, 
int async)
 }
 
 get_dwords(ehci, NLPTR_GET(q-qhaddr),
-   (uint32_t *) q-qh, sizeof(EHCIqh)  2);
-ehci_trace_qh(q, NLPTR_GET(q-qhaddr), q-qh);
+   (uint32_t *) qh, sizeof(EHCIqh)  2);
+ehci_trace_qh(q, NLPTR_GET(q-qhaddr), qh);
+
+/*
+ * The overlay area of the qh should never be changed by the guest,
+ * except when idle, in which case the reset is a nop.
+ */
+devaddr = get_field(qh.epchar, QH_EPCHAR_DEVADDR);
+endp= get_field(qh.epchar, QH_EPCHAR_EP);
+if ((devaddr != get_field(q-qh.epchar, QH_EPCHAR_DEVADDR)) ||
+(endp!= get_field(q-qh.epchar, QH_EPCHAR_EP)) ||
+(memcmp(qh.current_qtd, q-qh.current_qtd,
+ 9 * sizeof(uint32_t)) != 0) ||
+(q-dev != NULL  q-dev-addr != devaddr)) {
+ehci_reset_queue(q);
+p = NULL;
+}
+q-qh = qh;
 
-devaddr = get_field(q-qh.epchar, QH_EPCHAR_DEVADDR);
-if (q-dev != NULL  q-dev-addr != devaddr) {
-if (!QTAILQ_EMPTY(q-packets)) {
-/* should not happen (guest bug) */
-ehci_cancel_queue(q);
-}
-q-dev = NULL;
-}
 if (q-dev == NULL) {
 q-dev = ehci_find_device(q-ehci, devaddr);
 }
-- 
1.7.1




[Qemu-devel] [PATCH 28/54] usb-redir: Enable pipelining for bulk endpoints

2012-09-06 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

Signed-off-by: Hans de Goede hdego...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/redirect.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index 7fb0fb3..5301a69 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -1197,6 +1197,9 @@ static void usbredir_ep_info(void *priv,
  usb_redir_cap_ep_info_max_packet_size)) {
 usb_ep-max_packet_size = ep_info-max_packet_size[i];
 }
+if (ep_info-type[i] == usb_redir_type_bulk) {
+usb_ep-pipeline = true;
+}
 }
 }
 
-- 
1.7.1




Re: [Qemu-devel] [PATCH v7 12/14] target-mips-ase-dsp: Add MIPS DSP processors

2012-09-06 Thread Aurelien Jarno
On Tue, Aug 28, 2012 at 02:36:23PM +0800, Jia Liu wrote:
 Add MIPS[32|64] ASE DSP[R1|R2] generic cpu model for test.
 
 Signed-off-by: Jia Liu pro...@gmail.com
 ---
  target-mips/translate_init.c |   55 
 ++
  1 file changed, 55 insertions(+)
 
 diff --git a/target-mips/translate_init.c b/target-mips/translate_init.c
 index c39138f..65ba547 100644
 --- a/target-mips/translate_init.c
 +++ b/target-mips/translate_init.c
 @@ -311,6 +311,32 @@ static const mips_def_t mips_defs[] =
  .insn_flags = CPU_MIPS32R2 | ASE_MIPS16 | ASE_DSP | ASE_MT,
  .mmu_type = MMU_TYPE_R4000,
  },
 +{
 +/* A generic CPU providing MIPS32 ASE DSP Release 2 features.
 +   FIXME: Eventually this should be replaced by a real CPU model. */

Is it something that could be fixed now? I guess MIPS produces core with
this instruction set.

 +.name = mips32dspr2,
 +.CP0_PRid = 0x00019300,
 +.CP0_Config0 = MIPS_CONFIG0 | (0x1  CP0C0_AR) |
 +(MMU_TYPE_R4000  CP0C0_MT),
 +.CP0_Config1 = MIPS_CONFIG1 | (1  CP0C1_FP) | (15  CP0C1_MMU) |
 +   (0  CP0C1_IS) | (3  CP0C1_IL) | (1  CP0C1_IA) |
 +   (0  CP0C1_DS) | (3  CP0C1_DL) | (1  CP0C1_DA) |
 +   (1  CP0C1_CA),
 +.CP0_Config2 = MIPS_CONFIG2,
 +.CP0_Config3 = MIPS_CONFIG3 | (0  CP0C3_VInt) | (1  CP0C3_DSPP),
 +.CP0_LLAddr_rw_bitmask = 0,
 +.CP0_LLAddr_shift = 4,
 +.SYNCI_Step = 32,
 +.CCRes = 2,
 +/* No DSP implemented. */
 +.CP0_Status_rw_bitmask = 0x3778FF1F,
 +.CP1_fcr0 = (1  FCR0_F64) | (1  FCR0_L) | (1  FCR0_W) |
 +(1  FCR0_D) | (1  FCR0_S) | (0x93  FCR0_PRID),
 +.SEGBITS = 32,
 +.PABITS = 32,
 +.insn_flags = CPU_MIPS32R2 | ASE_MIPS16 | ASE_DSP | ASE_DSPR2,
 +.mmu_type = MMU_TYPE_R4000,
 +},
  #if defined(TARGET_MIPS64)
  {
  .name = R4000,
 @@ -484,6 +510,35 @@ static const mips_def_t mips_defs[] =
.insn_flags = CPU_LOONGSON2F,
.mmu_type = MMU_TYPE_R4000,
  },
 +{
 +/* A generic CPU providing MIPS64 ASE DSP Release 2 features.
 +   FIXME: Eventually this should be replaced by a real CPU model. */
 +.name = mips64dspr2,
 +/* We emulate a later version of the 20Kc, earlier ones had a broken
 +   WAIT instruction. */
 +.CP0_PRid = 0x000182a0,
 +.CP0_Config0 = MIPS_CONFIG0 | (0x2  CP0C0_AT) |
 +(MMU_TYPE_R4000  CP0C0_MT) | (1  CP0C0_VI),
 +.CP0_Config1 = MIPS_CONFIG1 | (1  CP0C1_FP) | (47  CP0C1_MMU) |
 +   (2  CP0C1_IS) | (4  CP0C1_IL) | (3  CP0C1_IA) |
 +   (2  CP0C1_DS) | (4  CP0C1_DL) | (3  CP0C1_DA) |
 +   (1  CP0C1_PC) | (1  CP0C1_WR) | (1  CP0C1_EP),
 +.CP0_Config2 = MIPS_CONFIG2,
 +.CP0_Config3 = MIPS_CONFIG3 | (1  CP0C3_DSPP),
 +.CP0_LLAddr_rw_bitmask = 0,
 +.CP0_LLAddr_shift = 0,
 +.SYNCI_Step = 32,
 +.CCRes = 1,
 +.CP0_Status_rw_bitmask = 0x37FB,
 +/* The 20Kc has F64 / L / W but doesn't use the fcr0 bits. */
 +.CP1_fcr0 = (1  FCR0_3D) | (1  FCR0_PS) |
 +(1  FCR0_D) | (1  FCR0_S) |
 +(0x82  FCR0_PRID) | (0x0  FCR0_REV),
 +.SEGBITS = 40,
 +.PABITS = 36,
 +.insn_flags = CPU_MIPS64R2 | ASE_DSP | ASE_DSPR2,
 +.mmu_type = MMU_TYPE_R4000,
 +},
  
  #endif
  };
 -- 
 1.7.9.5
 
 

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] [PATCH v7 01/14] target-mips-ase-dsp: Add internal functions

2012-09-06 Thread Aurelien Jarno
On Tue, Aug 28, 2012 at 02:36:12PM +0800, Jia Liu wrote:
 Add internal functions using by MIPS ASE DSP instructions.
 
 Signed-off-by: Jia Liu pro...@gmail.com
 ---
  target-mips/Makefile.objs |2 +-
  target-mips/dsp_helper.c  | 1277 
 +
  2 files changed, 1278 insertions(+), 1 deletion(-)
  create mode 100644 target-mips/dsp_helper.c

As a general comment, I think the code is too verbose. For example the
following code:

|uint16_t tempA, tempB, temp;
|
|tempA = a;
|tempB = b;
|temp = tempA + tempB;

can be replaced by:

|uint16_t temp;
|
|temp = (uint16_t)a + (uint16_t)b;

This way it's shorter and easier to read.


 diff --git a/target-mips/Makefile.objs b/target-mips/Makefile.objs
 index 2e0e093..55b252d 100644
 --- a/target-mips/Makefile.objs
 +++ b/target-mips/Makefile.objs
 @@ -1,4 +1,4 @@
 -obj-y += translate.o op_helper.o helper.o cpu.o
 +obj-y += translate.o dsp_helper.o op_helper.o helper.o cpu.o
  obj-$(CONFIG_SOFTMMU) += machine.o
  
  $(obj)/op_helper.o: QEMU_CFLAGS += $(HELPER_CFLAGS)
 diff --git a/target-mips/dsp_helper.c b/target-mips/dsp_helper.c
 new file mode 100644
 index 000..a7d6c7e
 --- /dev/null
 +++ b/target-mips/dsp_helper.c
 @@ -0,0 +1,1277 @@
 +/*
 + * MIPS ASE DSP Instruction emulation helpers for QEMU.
 + *
 + * Copyright (c) 2012  Jia Liu pro...@gmail.com
 + * Dongxue Zhang elat@gmail.com
 + * This library is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU Lesser General Public
 + * License as published by the Free Software Foundation; either
 + * version 2 of the License, or (at your option) any later version.
 + *
 + * This library is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 + * Lesser General Public License for more details.
 + *
 + * You should have received a copy of the GNU Lesser General Public
 + * License along with this library; if not, see 
 http://www.gnu.org/licenses/.
 + */
 +
 +#include cpu.h
 +#include helper.h
 +
 +/*** MIPS DSP internal functions begin ***/
 +static inline int not_word_value(target_long value)
 +{
 +target_ulong temp;
 +
 +temp = (target_long)(int32_t)(value  0x);
 +if (value == temp) {
 +return 0;
 +} else {
 +return 1;
 +}
 +}
 +
 +static inline void set_DSPControl_overflow_flag(CPUMIPSState *env,
 +uint32_t flag, int position)
 +{
 +env-active_tc.DSPControl |= (target_ulong)flag  position;
 +}
 +
 +static inline void set_DSPControl_carryflag(CPUMIPSState *env, uint32_t flag)
 +{
 +env-active_tc.DSPControl |= (target_ulong)flag  13;
 +}
 +
 +static inline uint32_t get_DSPControl_carryflag(CPUMIPSState *env)
 +{
 +uint32_t flag;
 +
 +flag = (env-active_tc.DSPControl  13)  0x01;
 +
 +return flag;
 +}
 +
 +static inline void set_DSPControl_24(CPUMIPSState *env, uint32_t flag, int 
 len)
 +{
 +  uint32_t filter;
 +
 +  filter = ((0x01  len) - 1)  24;
 +  filter = ~filter;
 +
 +  env-active_tc.DSPControl = filter;
 +  env-active_tc.DSPControl |= (target_ulong)flag  24;
 +}
 +
 +static inline uint32_t get_DSPControl_24(CPUMIPSState *env, int len)
 +{
 +  uint32_t cond;
 +  uint32_t filter;
 +
 +  filter = (0x01  len) - 1;
 +
 +  cond = (env-active_tc.DSPControl  24)  filter;
 +
 +  return cond;
 +}
 +
 +static inline void set_DSPControl_pos(CPUMIPSState *env, uint32_t pos)
 +{
 +target_ulong dspc;
 +
 +dspc = env-active_tc.DSPControl;
 +#ifndef TARGET_MIPS64
 +dspc = dspc  0xFFC0;
 +dspc |= pos;
 +#else
 +dspc = dspc  0xFF80;
 +dspc |= pos;
 +#endif
 +env-active_tc.DSPControl = dspc;
 +}
 +
 +static inline uint32_t get_DSPControl_pos(CPUMIPSState *env)
 +{
 +target_ulong dspc;
 +uint32_t pos;
 +
 +dspc = env-active_tc.DSPControl;
 +
 +#ifndef TARGET_MIPS64
 +pos = dspc  0x3F;
 +#else
 +pos = dspc  0x7F;
 +#endif
 +
 +return pos;
 +}
 +
 +static inline void set_DSPControl_efi(CPUMIPSState *env, uint32_t flag)
 +{
 +env-active_tc.DSPControl = 0xBFFF;
 +env-active_tc.DSPControl |= (target_ulong)flag  14;
 +}
 +
 +/* get abs value */
 +static inline int8_t mipsdsp_sat_abs_u8(CPUMIPSState *env, uint8_t a)
 +{
 +int8_t temp;
 +temp = a;
 +
 +if (a == 0x80) {
 +set_DSPControl_overflow_flag(env, 1, 20);
 +temp = 0x7f;
 +} else {
 +if ((a  0x80) == 0x80) {
 +temp = -temp;
 +}
 +}
 +
 +return temp;
 +}
 +
 +static inline int16_t mipsdsp_sat_abs_u16(CPUMIPSState *env, uint16_t a)
 +{
 +int16_t temp;
 +temp = a;
 +
 +if (a == 0x8000) {
 +set_DSPControl_overflow_flag(env, 1, 20);
 +temp = 0x7fff;
 +} else {
 +if ((a  0x8000) == 0x8000) {
 +temp = -temp;
 +}
 +}
 +
 

[Qemu-devel] [PATCH 14/14] Remove #ifdef QXL_COMMAND_FLAG_COMPAT_16BPP

2012-09-06 Thread Gerd Hoffmann
From: Søren Sandmann Pedersen s...@redhat.com

We require spice = 0.8 now, so this flag is always present.

Signed-off-by: Soren Sandmann s...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/qxl.c |2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/hw/qxl.c b/hw/qxl.c
index 2aa5848..b726c19 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -1359,11 +1359,9 @@ static void qxl_set_mode(PCIQXLDevice *d, int modenr, 
int loadvm)
 
 d-mode = QXL_MODE_COMPAT;
 d-cmdflags = QXL_COMMAND_FLAG_COMPAT;
-#ifdef QXL_COMMAND_FLAG_COMPAT_16BPP /* new in spice 0.6.1 */
 if (mode-bits == 16) {
 d-cmdflags |= QXL_COMMAND_FLAG_COMPAT_16BPP;
 }
-#endif
 d-shadow_rom.mode = cpu_to_le32(modenr);
 d-rom-mode = cpu_to_le32(modenr);
 qxl_rom_set_dirty(d);
-- 
1.7.1




  1   2   3   >