Re: [Qemu-devel] classic emulator Vs QEMU-TCG

2010-12-17 Thread Stefano Bonifazi

On 12/16/2010 04:57 PM, Mulyadi Santosa wrote:

With my limited C knowledge, I saw that as a instruction jump (to
tb_ptr). The code_gen_prologue seems to me like a cast. casting
each opcode in tb_ptr as uint8_t with maximum length=1024

Hi! Thank you for your reply!

I've got an explanation from a C guru :)


((long REGPARM (*)(void *))code_gen_prologue)(tb_ptr)
-
(long REGPARM (*)(void *)) is a type: a pointer pointing to a function, which takes 
one (void*) parameter. code_gen_prologue is anarray, array's name when used is 
considered to be a pointer to its first element, thus you are casting here pointer to 
the first byte ofarray to pointer to function (...).
Ellipsis with tb_ptr mean 'call function under this address and pass there 
whatever tb_ptr is'


Now everything is very clear for me :)
I do know pointer to functions, and if I had got:


long REGPARM (*myfunc)(void *)


I would have recognized it.. but removing the function pointer name, 
leaving only the * was enough for me to be lost :[

also the definition of code_gen_prologue was tricky:

uint8_t code_gen_prologue[1024] code_gen_section;
that code_gen_section at first confused my idea of a normal variable 
definition as type identifier .. until I found out it was a define for 
a compiler directive (alignment) :[


So inside code_gen_prologue array there is stored some function (in 
binary code) that takes a tb_ptr as argument and returns a long .. I 
have to check what it is inside there for understanding how the 
translated target code is run now ;)



I hope that's the right interpretation...I must admit Qemu is full of
gcc and C tricks here and there...
Yes! I've only had some experience in OO programming, really always 
avoided defines and odd compiler directives in my code before..


 Best Regards!
Stefano B.



Re: [Qemu-devel] -snapshot

2010-12-17 Thread Kevin Wolf
Am 16.12.2010 19:16, schrieb Stefan Weil:
 Am 16.12.2010 18:45, schrieb Stefan Hajnoczi:
 On Thu, Dec 16, 2010 at 4:34 PM, Amador Pahim ama...@pahim.org wrote:
 Thank you for your answer. Just one more question: If, while my
 snapshot vms are running, the main disk is modified by a non
 snapshot vm? For example, installing some extra software.. this can
 freeze vms or something?

 Correct, it is not safe to modify the base image while there is
 another disk image backed off it.

 The reason for this is that the image only needs to store the changes
 that were made on top of the base image. For anything which hasn't
 been modified it will go back to the base image and read data from
 there.

 If you modify the base image, then the filesystem in the base image is
 not longer what your image file was created from and you have an
 inconsistent view of the disk. It leads to odd behavior and is
 unsafe.

 Stefan
 
 There are useful scenarios where using the same disk
 simultaneously from a snapshot vm and a real system
 works.
 
 If you have a hard disk with a dual boot configuration,
 it is sometimes useful to boot one configuration with
 the real system, then start qemu and boot the second
 configuration.
 
 Even booting the same configuration twice
 (once with the real machine, once with qemu snapshot)
 is sometimes useful and works to a limited degree.
 It is a simple way to try new bootloader configurations
 or other boot setups.

Right, though this doesn't contradict what Stefan said. It only works
because in fact you don't modify the parts that your guest reads.

Kevin



Re: [Qemu-devel] classic emulator Vs QEMU-TCG

2010-12-17 Thread Mulyadi Santosa
On Fri, Dec 17, 2010 at 16:47, Stefano Bonifazi
stefboombas...@gmail.com wrote:
 On 12/16/2010 04:57 PM, Mulyadi Santosa wrote:

 With my limited C knowledge, I saw that as a instruction jump (to
 tb_ptr). The code_gen_prologue seems to me like a cast. casting
 each opcode in tb_ptr as uint8_t with maximum length=1024

 Hi! Thank you for your reply!

 I've got an explanation from a C guru :)

Thanks a lot for sharing it.:) Hopefully your C skill is better now :)

-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com



Re: [Qemu-devel] [PATCH 3/3] raw-posix: add discard support

2010-12-17 Thread Kevin Wolf
Am 16.12.2010 19:36, schrieb Christoph Hellwig:
 Add support to discard blocks in a raw image residing on an XFS filesystem
 by calling the XFS_IOC_UNRESVSP64 ioctl to punch holes.  Support for other
 hole punching mechanisms can be added when they become available.
 
 Signed-off-by: Christoph Hellwig h...@lst.de
 
 Index: qemu/block/raw-posix.c
 ===
 --- qemu.orig/block/raw-posix.c   2010-12-15 10:05:37.0 +0100
 +++ qemu/block/raw-posix.c2010-12-16 17:40:47.617253460 +0100
 @@ -69,6 +69,10 @@
  #include sys/diskslice.h
  #endif
  
 +#ifdef CONFIG_XFS
 +#include xfs/xfs.h
 +#endif
 +
  //#define DEBUG_FLOPPY
  
  //#define DEBUG_BLOCK
 @@ -120,6 +124,9 @@ typedef struct BDRVRawState {
  #endif
  uint8_t *aligned_buf;
  unsigned aligned_buf_size;
 +#ifdef CONFIG_XFS
 +bool is_xfs : 1;
 +#endif
  } BDRVRawState;
  
  static int fd_open(BlockDriverState *bs);
 @@ -196,6 +203,12 @@ static int raw_open_common(BlockDriverSt
  #endif
  }
  
 +#ifdef CONFIG_XFS
 +if (platform_test_xfs_fd(s-fd)) {
 +s-is_xfs = 1;
 +}
 +#endif
 +
  return 0;
  
  out_free_buf:
 @@ -740,6 +753,36 @@ static int raw_flush(BlockDriverState *b
  return qemu_fdatasync(s-fd);
  }
  
 +#ifdef CONFIG_XFS
 +static int xfs_discard(BDRVRawState *s, int64_t sector_num, int nb_sectors)
 +{
 +struct xfs_flock64 fl;
 +
 +memset(fl, 0, sizeof(fl));
 +fl.l_whence = SEEK_SET;
 +fl.l_start = sector_num  9;
 +fl.l_len = (int64_t)nb_sectors  9;
 +
 +if (xfsctl(NULL, s-fd, XFS_IOC_UNRESVSP64, fl)  0) {
 +printf(cannot punch hole (%s)\n, strerror(errno));

Debugging leftover? Block drivers shouldn't print anything to stdout.

 +return -errno;
 +}
 +
 +return 0;
 +}
 +#endif
 +
 +static int raw_discard(BlockDriverState *bs, int64_t sector_num, int 
 nb_sectors)
 +{
 +#ifdef CONFIG_XFS
 +BDRVRawState *s = bs-opaque;
 +
 +if (s-is_xfs)
 +return xfs_discard(s, sector_num, nb_sectors);

Missing braces.

I have already applied patch 1 and 2 to the block branch, so sending a
v5 for this one is enough.

Kevin



[Qemu-devel] Re: [PATCH] qemu-io: Add discard command

2010-12-17 Thread Kevin Wolf
Am 13.12.2010 10:36, schrieb Stefan Hajnoczi:
 discard [-Cq] off len -- discards a number of bytes at a specified
 offset
 
  discards a range of bytes from the given offset
 
  Example:
  'discard 512 1k' - discards 1 kilobyte from 512 bytes into the file
 
  Discards a segment of the currently open file.
  -C, -- report statistics in a machine parsable format
  -q, -- quite mode, do not show I/O statistics
 
 Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com

Thanks, applied to the block branch.

Kevin



[Qemu-devel] [PATCH v5] raw-posix: add discard support

2010-12-17 Thread Christoph Hellwig
Add support to discard blocks in a raw image residing on an XFS filesystem
by calling the XFS_IOC_UNRESVSP64 ioctl to punch holes.  Support for other
hole punching mechanisms can be added when they become available.

Signed-off-by: Christoph Hellwig h...@lst.de

Index: qemu/block/raw-posix.c
===
--- qemu.orig/block/raw-posix.c 2010-12-17 11:30:21.455262819 +0100
+++ qemu/block/raw-posix.c  2010-12-17 11:32:00.131003705 +0100
@@ -69,6 +69,10 @@
 #include sys/diskslice.h
 #endif
 
+#ifdef CONFIG_XFS
+#include xfs/xfs.h
+#endif
+
 //#define DEBUG_FLOPPY
 
 //#define DEBUG_BLOCK
@@ -120,6 +124,9 @@ typedef struct BDRVRawState {
 #endif
 uint8_t *aligned_buf;
 unsigned aligned_buf_size;
+#ifdef CONFIG_XFS
+bool is_xfs : 1;
+#endif
 } BDRVRawState;
 
 static int fd_open(BlockDriverState *bs);
@@ -196,6 +203,12 @@ static int raw_open_common(BlockDriverSt
 #endif
 }
 
+#ifdef CONFIG_XFS
+if (platform_test_xfs_fd(s-fd)) {
+s-is_xfs = 1;
+}
+#endif
+
 return 0;
 
 out_free_buf:
@@ -740,6 +753,37 @@ static int raw_flush(BlockDriverState *b
 return qemu_fdatasync(s-fd);
 }
 
+#ifdef CONFIG_XFS
+static int xfs_discard(BDRVRawState *s, int64_t sector_num, int nb_sectors)
+{
+struct xfs_flock64 fl;
+
+memset(fl, 0, sizeof(fl));
+fl.l_whence = SEEK_SET;
+fl.l_start = sector_num  9;
+fl.l_len = (int64_t)nb_sectors  9;
+
+if (xfsctl(NULL, s-fd, XFS_IOC_UNRESVSP64, fl)  0) {
+DEBUG_BLOCK_PRINT(cannot punch hole (%s)\n, strerror(errno));
+return -errno;
+}
+
+return 0;
+}
+#endif
+
+static int raw_discard(BlockDriverState *bs, int64_t sector_num, int 
nb_sectors)
+{
+#ifdef CONFIG_XFS
+BDRVRawState *s = bs-opaque;
+
+if (s-is_xfs) {
+return xfs_discard(s, sector_num, nb_sectors);
+}
+#endif
+
+return 0;
+}
 
 static QEMUOptionParameter raw_create_options[] = {
 {
@@ -761,6 +805,7 @@ static BlockDriver bdrv_file = {
 .bdrv_close = raw_close,
 .bdrv_create = raw_create,
 .bdrv_flush = raw_flush,
+.bdrv_discard = raw_discard,
 
 .bdrv_aio_readv = raw_aio_readv,
 .bdrv_aio_writev = raw_aio_writev,
Index: qemu/configure
===
--- qemu.orig/configure 2010-12-17 11:30:21.468254368 +0100
+++ qemu/configure  2010-12-17 11:30:40.080023610 +0100
@@ -288,6 +288,7 @@ xen=
 linux_aio=
 attr=
 vhost_net=
+xfs=
 
 gprof=no
 debug_tcg=no
@@ -1399,6 +1400,27 @@ EOF
 fi
 
 ##
+# xfsctl() probe, used for raw-posix
+if test $xfs != no ; then
+  cat  $TMPC  EOF
+#include xfs/xfs.h
+int main(void)
+{
+xfsctl(NULL, 0, 0, NULL);
+return 0;
+}
+EOF
+  if compile_prog   ; then
+xfs=yes
+  else
+if test $xfs = yes ; then
+  feature_not_found xfs
+fi
+xfs=no
+  fi
+fi
+
+##
 # vde libraries probe
 if test $vde != no ; then
   vde_libs=-lvdeplug
@@ -2403,6 +2425,7 @@ echo Trace backend $trace_backend
 echo Trace output file $trace_file-pid
 echo spice support $spice
 echo rbd support   $rbd
+echo xfsctl support$xfs
 
 if test $sdl_too_old = yes; then
 echo - Your SDL version is too old - please upgrade to have SDL support
@@ -2548,6 +2571,9 @@ fi
 if test $uuid = yes ; then
   echo CONFIG_UUID=y  $config_host_mak
 fi
+if test $xfs = yes ; then
+  echo CONFIG_XFS=y  $config_host_mak
+fi
 qemu_version=`head $source_path/VERSION`
 echo VERSION=$qemu_version $config_host_mak
 echo PKGVERSION=$pkgversion $config_host_mak



[Qemu-devel] Re: [PATCH v5] raw-posix: add discard support

2010-12-17 Thread Kevin Wolf
Am 17.12.2010 11:41, schrieb Christoph Hellwig:
 Add support to discard blocks in a raw image residing on an XFS filesystem
 by calling the XFS_IOC_UNRESVSP64 ioctl to punch holes.  Support for other
 hole punching mechanisms can be added when they become available.
 
 Signed-off-by: Christoph Hellwig h...@lst.de

Thanks, applied to the block branch.

Kevin



[Qemu-devel] [PATCH] qemu-io: Fix typo in help texts

2010-12-17 Thread Kevin Wolf
Signed-off-by: Kevin Wolf kw...@redhat.com
---
 qemu-io.c |   14 +++---
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/qemu-io.c b/qemu-io.c
index 2318a28..65dee13 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -326,7 +326,7 @@ read_help(void)
  -l, -- length for pattern verification (only with -P)\n
  -p, -- use bdrv_pread to read the file\n
  -P, -- use a pattern to verify read data\n
- -q, -- quite mode, do not show I/O statistics\n
+ -q, -- quiet mode, do not show I/O statistics\n
  -s, -- start offset for pattern verification (only with -P)\n
  -v, -- dump buffer to standard output\n
 \n);
@@ -509,7 +509,7 @@ readv_help(void)
  -C, -- report statistics in a machine parsable format\n
  -P, -- use a pattern to verify read data\n
  -v, -- dump buffer to standard output\n
- -q, -- quite mode, do not show I/O statistics\n
+ -q, -- quiet mode, do not show I/O statistics\n
 \n);
 }
 
@@ -633,7 +633,7 @@ write_help(void)
  -p, -- use bdrv_pwrite to write the file\n
  -P, -- use different pattern to fill file\n
  -C, -- report statistics in a machine parsable format\n
- -q, -- quite mode, do not show I/O statistics\n
+ -q, -- quiet mode, do not show I/O statistics\n
 \n);
 }
 
@@ -765,7 +765,7 @@ writev_help(void)
  filled with a set pattern (0xcdcdcdcd).\n
  -P, -- use different pattern to fill file\n
  -C, -- report statistics in a machine parsable format\n
- -q, -- quite mode, do not show I/O statistics\n
+ -q, -- quiet mode, do not show I/O statistics\n
 \n);
 }
 
@@ -1100,7 +1100,7 @@ aio_read_help(void)
  -C, -- report statistics in a machine parsable format\n
  -P, -- use a pattern to verify read data\n
  -v, -- dump buffer to standard output\n
- -q, -- quite mode, do not show I/O statistics\n
+ -q, -- quiet mode, do not show I/O statistics\n
 \n);
 }
 
@@ -1198,7 +1198,7 @@ aio_write_help(void)
  used to ensure all outstanding aio requests have been completed\n
  -P, -- use different pattern to fill file\n
  -C, -- report statistics in a machine parsable format\n
- -q, -- quite mode, do not show I/O statistics\n
+ -q, -- quiet mode, do not show I/O statistics\n
 \n);
 }
 
@@ -1406,7 +1406,7 @@ discard_help(void)
 \n
  Discards a segment of the currently open file.\n
  -C, -- report statistics in a machine parsable format\n
- -q, -- quite mode, do not show I/O statistics\n
+ -q, -- quiet mode, do not show I/O statistics\n
 \n);
 }
 
-- 
1.7.2.3




Re: [Qemu-devel] [PATCH] qemu-io: Fix typo in help texts

2010-12-17 Thread Christoph Hellwig
On Fri, Dec 17, 2010 at 11:56:24AM +0100, Kevin Wolf wrote:
 Signed-off-by: Kevin Wolf kw...@redhat.com

Looks good.




Re: [Qemu-devel] Re: [PATCH v3] qemu, qmp: convert do_inject_nmi() to QObject, QError

2010-12-17 Thread Luiz Capitulino
On Fri, 17 Dec 2010 14:20:15 +0800
Lai Jiangshan la...@cn.fujitsu.com wrote:

 On 12/16/2010 09:17 PM, Luiz Capitulino wrote:
  On Thu, 16 Dec 2010 15:11:50 +0200
  Avi Kivity a...@redhat.com wrote:
 
  Why have an argument at all?  Always nmi to all cpus.
  
 
 I think Avi's suggest is better, and I will use
 inject-nmi (without cpu-index argument) to send NMI to all cpus,
 like physical GUI. If some one want to send NMI to a set of cpus, 
 he can use inject-nmi multiple times.

His suggestion is to drop _all_ arguments, right Avi?

This will simplify things, but you'll need a small refactoring to keep
the human monitor behavior (which accepts a cpu index).

 I also like cpu-index, so I have to add another patch for
 coverting current cpu_index to cpu-index.
 
 Thanks,
 Lai
 




[Qemu-devel] [PATCH 01/30] usb: update MAINTAINERS

2010-12-17 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 MAINTAINERS |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 59effc7..4b07192 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -329,8 +329,8 @@ F: hw/lsi53c895a.c
 F: hw/scsi*
 
 USB
-M: qemu-devel@nongnu.org
-S: Odd Fixes
+M: Gerd Hoffmann kra...@redhat.com
+S: Maintained
 F: hw/usb*
 
 vhost
-- 
1.7.1




[Qemu-devel] [PATCH 00/30] usb descriptor overhaul + more

2010-12-17 Thread Gerd Hoffmann
  Hi,

Here is a update of the usb descriptor patches and a bunch of
improvements on top of that.  This patch series features:

  * Update USB section in MAINTAINERS
  * A major overhaul for the usb descriptor handling for
emulated devices.  This is in preparation for USB 2.0
support entering qemu which will need a bit more
sophisticated descriptor handling.  This is also for
moving descriptor handling to common code instead of
having each driver duplicate it.
  * Improved usb port management.
  * Remote wakeup support, which allows guests to suspend
the usb bus when all devices are idle, so qemu will
not wakeup at usb frame rate (1000 Hz).
  * A bunch of improvements and fixes for the usb-storage
emulation.  It features full USB 2.0 support now, although
due to the lack of a EHCI controller the only thing you'll
notice is that the linux kernel logs a message which suggests
to connect the device to a high-speed port.

The patches are available in the git repository at:
  git://anongit.freedesktop.org/spice/qemu usb.3

I think it would be very good to have in 0.14 (especially the remote
wakeup support and the storage fixes).  Most patches have been on the
list already and are unmodified compared to the usb.2 branch posted a
week ago.

Note that I'll go disappear for x-mas and newyear holidays in a few
hours though, so I wouldn't be available to help fixing up any issues
which might pop up until january.  Assuming we stick to the original
release schedule this isn't ideal of course.  Given that the master
branch hasn't seen any commits this week I have my doubts that we see
rc0 today though.


FYI: I have some more experimental stuff which isn't ready for merge
yet in the queue:

  * EHCI controller.
  * Initial migration support for usb (not complete yet, not all devices
are covered, doesn't handle usb transactions which are in flight at
migration time, should already work fine for idle usb devices though).
  * First bits of packet workflow cleanups.

If you wanna play with this: the git tree with these experimental and
in-progress bits is here:
  git://anongit.freedesktop.org/spice/qemu usb.3.wip


enjoy  happy x-mas,
  Gerd


Gerd Hoffmann (30):
  usb: update MAINTAINERS
  usb: data structs and helpers for usb descriptors.
  usb hid: use new descriptor infrastructure.
  usb serial: use new descriptor infrastructure.
  usb storage: use new descriptor infrastructure.
  usb wacom: use new descriptor infrastructure.
  usb bluetooth: use new descriptor infrastructure.
  usb hub: use new descriptor infrastructure.
  usb descriptors: add settable strings.
  usb storage: serial number support
  usb network: use new descriptor infrastructure.
  usb: move USB_REQ_SET_ADDRESS handling to common code
  usb: move USB_REQ_{GET,SET}_CONFIGURATION handling to common code
  usb: move remote wakeup handling to common code
  usb: create USBPortOps, move attach there.
  usb: rework attach/detach workflow
  usb: add usb_wakeup() + wakeup callback to port ops
  usb: uhci: remote wakeup support.
  usb: hub: remote wakeup support.
  usb: hid: remote wakeup support.
  usb: hid: change serial number to 42.
  usb: add speed mask to ports
  usb: add attach callback
  usb: add usb_desc_attach
  usb: add device qualifier support
  usb storage: high speed support
  usb storage: fix status reporting
  usb storage: handle long responses
  usb: keep track of physical port address.
  usb: add port property.

 MAINTAINERS |4 +-
 Makefile.objs   |2 +-
 hw/usb-bt.c |  525 ++
 hw/usb-bus.c|   57 +-
 hw/usb-desc.c   |  406 ++
 hw/usb-desc.h   |   92 ++
 hw/usb-hid.c|  486 ++-
 hw/usb-hub.c|  250 +-
 hw/usb-msd.c|  267 +---
 hw/usb-musb.c   |   44 ++---
 hw/usb-net.c|  528 +++
 hw/usb-ohci.c   |   88 +-
 hw/usb-serial.c |  236 +
 hw/usb-uhci.c   |   98 ++-
 hw/usb-wacom.c  |  214 ---
 hw/usb.c|   34 -
 hw/usb.h|   49 +-
 trace-events|   11 ++
 18 files changed, 1813 insertions(+), 1578 deletions(-)
 create mode 100644 hw/usb-desc.c
 create mode 100644 hw/usb-desc.h




[Qemu-devel] [PATCH 03/30] usb hid: use new descriptor infrastructure.

2010-12-17 Thread Gerd Hoffmann
Switch the usb hid drivers (keyboard, mouse, tablet) over to the
new descriptor infrastructure.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb-hid.c |  448 +++---
 1 files changed, 205 insertions(+), 243 deletions(-)

diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index 882d933..74d17fc 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -25,6 +25,7 @@
 #include hw.h
 #include console.h
 #include usb.h
+#include usb-desc.h
 #include sysemu.h
 
 /* HID interface requests */
@@ -73,190 +74,206 @@ typedef struct USBHIDState {
 void (*datain)(void *);
 } USBHIDState;
 
-/* mostly the same values as the Bochs USB Mouse device */
-static const uint8_t qemu_mouse_dev_descriptor[] = {
-   0x12,   /*  u8 bLength; */
-   0x01,   /*  u8 bDescriptorType; Device */
-   0x00, 0x01, /*  u16 bcdUSB; v1.0 */
-
-   0x00,   /*  u8  bDeviceClass; */
-   0x00,   /*  u8  bDeviceSubClass; */
-   0x00,   /*  u8  bDeviceProtocol; [ low/full speeds only ] */
-   0x08,   /*  u8  bMaxPacketSize0; 8 Bytes */
-
-   0x27, 0x06, /*  u16 idVendor; */
-   0x01, 0x00, /*  u16 idProduct; */
-   0x00, 0x00, /*  u16 bcdDevice */
-
-   0x03,   /*  u8  iManufacturer; */
-   0x02,   /*  u8  iProduct; */
-   0x01,   /*  u8  iSerialNumber; */
-   0x01/*  u8  bNumConfigurations; */
+enum {
+STR_MANUFACTURER = 1,
+STR_PRODUCT_MOUSE,
+STR_PRODUCT_TABLET,
+STR_PRODUCT_KEYBOARD,
+STR_SERIALNUMBER,
+STR_CONFIG_MOUSE,
+STR_CONFIG_TABLET,
+STR_CONFIG_KEYBOARD,
 };
 
-static const uint8_t qemu_mouse_config_descriptor[] = {
-   /* one configuration */
-   0x09,   /*  u8  bLength; */
-   0x02,   /*  u8  bDescriptorType; Configuration */
-   0x22, 0x00, /*  u16 wTotalLength; */
-   0x01,   /*  u8  bNumInterfaces; (1) */
-   0x01,   /*  u8  bConfigurationValue; */
-   0x04,   /*  u8  iConfiguration; */
-   0xe0,   /*  u8  bmAttributes;
-Bit 7: must be set,
-6: Self-powered,
-5: Remote wakeup,
-4..0: resvd */
-   50, /*  u8  MaxPower; */
-
-   /* USB 1.1:
-* USB 2.0, single TT organization (mandatory):
-*  one interface, protocol 0
-*
-* USB 2.0, multiple TT organization (optional):
-*  two interfaces, protocols 1 (like single TT)
-*  and 2 (multiple TT mode) ... config is
-*  sometimes settable
-*  NOT IMPLEMENTED
-*/
-
-   /* one interface */
-   0x09,   /*  u8  if_bLength; */
-   0x04,   /*  u8  if_bDescriptorType; Interface */
-   0x00,   /*  u8  if_bInterfaceNumber; */
-   0x00,   /*  u8  if_bAlternateSetting; */
-   0x01,   /*  u8  if_bNumEndpoints; */
-   0x03,   /*  u8  if_bInterfaceClass; */
-   0x01,   /*  u8  if_bInterfaceSubClass; */
-   0x02,   /*  u8  if_bInterfaceProtocol; [usb1.1 or single tt] */
-   0x07,   /*  u8  if_iInterface; */
-
-/* HID descriptor */
-0x09,/*  u8  bLength; */
-0x21,/*  u8 bDescriptorType; */
-0x01, 0x00,  /*  u16 HID_class */
-0x00,/*  u8 country_code */
-0x01,/*  u8 num_descriptors */
-0x22,/*  u8 type; Report */
-52, 0,   /*  u16 len */
-
-   /* one endpoint (status change endpoint) */
-   0x07,   /*  u8  ep_bLength; */
-   0x05,   /*  u8  ep_bDescriptorType; Endpoint */
-   0x81,   /*  u8  ep_bEndpointAddress; IN Endpoint 1 */
-   0x03,   /*  u8  ep_bmAttributes; Interrupt */
-   0x04, 0x00, /*  u16 ep_wMaxPacketSize; */
-   0x0a,   /*  u8  ep_bInterval; (255ms -- usb 2.0 spec) */
+static const USBDescStrings desc_strings = {
+[STR_MANUFACTURER] = QEMU  QEMU_VERSION,
+[STR_PRODUCT_MOUSE]= QEMU USB Mouse,
+[STR_PRODUCT_TABLET]   = QEMU USB Tablet,
+[STR_PRODUCT_KEYBOARD] = QEMU USB Keyboard,
+[STR_SERIALNUMBER] = 1,
+[STR_CONFIG_MOUSE] = HID Mouse,
+[STR_CONFIG_TABLET]= HID Tablet,
+[STR_CONFIG_KEYBOARD]  = HID Keyboard,
 };
 
-static const uint8_t qemu_tablet_config_descriptor[] = {
-   /* one configuration */
-   0x09,   /*  u8  bLength; */
-   0x02,   /*  u8  bDescriptorType; Configuration */
-   0x22, 0x00, /*  u16 wTotalLength; */
-   0x01,   /*  u8  bNumInterfaces; (1) */
-   0x01,   /*  u8  bConfigurationValue; */
-   0x05,   /*  u8  iConfiguration; */
-   0xa0,   /*  u8  bmAttributes;
-Bit 7: must be set,
-6: Self-powered,
-5: Remote wakeup,
-4..0: resvd 

[Qemu-devel] [PATCH 04/30] usb serial: use new descriptor infrastructure.

2010-12-17 Thread Gerd Hoffmann
Switch the usb serial drivers (serial, braille) over to the
new descriptor infrastructure.

Note that this removes the freely configurable vendor and product id
properties.  I think the only reason this was configurable is that the
only difference between the serial and the braille device is the
vendor+product id.  Of course the serial and braille devices keep their
different IDs, but they can't be overritten from the command line any
more.

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

diff --git a/hw/usb-serial.c b/hw/usb-serial.c
index c19580f..f89eb9b 100644
--- a/hw/usb-serial.c
+++ b/hw/usb-serial.c
@@ -11,6 +11,7 @@
 #include qemu-common.h
 #include qemu-error.h
 #include usb.h
+#include usb-desc.h
 #include qemu-char.h
 
 //#define DEBUG_Serial
@@ -91,8 +92,6 @@ do { printf(usb-serial:  fmt , ## __VA_ARGS__); } while (0)
 
 typedef struct {
 USBDevice dev;
-uint32_t vendorid;
-uint32_t productid;
 uint8_t recv_buf[RECV_BUF];
 uint16_t recv_ptr;
 uint16_t recv_used;
@@ -104,69 +103,78 @@ typedef struct {
 CharDriverState *cs;
 } USBSerialState;
 
-static const uint8_t qemu_serial_dev_descriptor[] = {
-0x12,   /*  u8 bLength; */
-0x01,   /*  u8 bDescriptorType; Device */
-0x00, 0x02, /*  u16 bcdUSB; v2.0 */
-
-0x00,   /*  u8  bDeviceClass; */
-0x00,   /*  u8  bDeviceSubClass; */
-0x00,   /*  u8  bDeviceProtocol; [ low/full speeds only ] */
-0x08,   /*  u8  bMaxPacketSize0; 8 Bytes */
-
-/* Vendor and product id are arbitrary.  */
-0x03, 0x04, /*  u16 idVendor; */
-0x00, 0xFF, /*  u16 idProduct; */
-0x00, 0x04, /*  u16 bcdDevice */
-
-0x01,   /*  u8  iManufacturer; */
-0x02,   /*  u8  iProduct; */
-0x03,   /*  u8  iSerialNumber; */
-0x01/*  u8  bNumConfigurations; */
+enum {
+STR_MANUFACTURER = 1,
+STR_PRODUCT_SERIAL,
+STR_PRODUCT_BRAILLE,
+STR_SERIALNUMBER,
 };
 
-static const uint8_t qemu_serial_config_descriptor[] = {
-
-/* one configuration */
-0x09,   /*  u8  bLength; */
-0x02,   /*  u8  bDescriptorType; Configuration */
-0x20, 0x00, /*  u16 wTotalLength; */
-0x01,   /*  u8  bNumInterfaces; (1) */
-0x01,   /*  u8  bConfigurationValue; */
-0x00,   /*  u8  iConfiguration; */
-0x80,   /*  u8  bmAttributes;
- Bit 7: must be set,
- 6: Self-powered,
- 5: Remote wakeup,
- 4..0: resvd */
-100/2,   /*  u8  MaxPower; */
-
-/* one interface */
-0x09,   /*  u8  if_bLength; */
-0x04,   /*  u8  if_bDescriptorType; Interface */
-0x00,   /*  u8  if_bInterfaceNumber; */
-0x00,   /*  u8  if_bAlternateSetting; */
-0x02,   /*  u8  if_bNumEndpoints; */
-0xff,   /*  u8  if_bInterfaceClass; Vendor Specific */
-0xff,   /*  u8  if_bInterfaceSubClass; Vendor Specific */
-0xff,   /*  u8  if_bInterfaceProtocol; Vendor Specific */
-0x02,   /*  u8  if_iInterface; */
-
-/* Bulk-In endpoint */
-0x07,   /*  u8  ep_bLength; */
-0x05,   /*  u8  ep_bDescriptorType; Endpoint */
-0x81,   /*  u8  ep_bEndpointAddress; IN Endpoint 1 */
-0x02,   /*  u8  ep_bmAttributes; Bulk */
-0x40, 0x00, /*  u16 ep_wMaxPacketSize; */
-0x00,   /*  u8  ep_bInterval; */
-
-/* Bulk-Out endpoint */
-0x07,   /*  u8  ep_bLength; */
-0x05,   /*  u8  ep_bDescriptorType; Endpoint */
-0x02,   /*  u8  ep_bEndpointAddress; OUT Endpoint 2 */
-0x02,   /*  u8  ep_bmAttributes; Bulk */
-0x40, 0x00, /*  u16 ep_wMaxPacketSize; */
-0x00/*  u8  ep_bInterval; */
+static const USBDescStrings desc_strings = {
+[STR_MANUFACTURER]= QEMU  QEMU_VERSION,
+[STR_PRODUCT_SERIAL]  = QEMU USB SERIAL,
+[STR_PRODUCT_BRAILLE] = QEMU USB BRAILLE,
+[STR_SERIALNUMBER]= 1,
+};
+
+static const USBDescIface desc_iface0 = {
+.bInterfaceNumber  = 0,
+.bNumEndpoints = 2,
+.bInterfaceClass   = 0xff,
+.bInterfaceSubClass= 0xff,
+.bInterfaceProtocol= 0xff,
+.eps = (USBDescEndpoint[]) {
+{
+.bEndpointAddress  = USB_DIR_IN | 0x01,
+.bmAttributes  = USB_ENDPOINT_XFER_BULK,
+.wMaxPacketSize= 64,
+},{
+.bEndpointAddress  = USB_DIR_OUT | 0x02,
+.bmAttributes  = USB_ENDPOINT_XFER_BULK,
+.wMaxPacketSize= 64,
+},
+}

[Qemu-devel] [PATCH 12/30] usb: move USB_REQ_SET_ADDRESS handling to common code

2010-12-17 Thread Gerd Hoffmann
USB_REQ_SET_ADDRESS handling is identical in *all* emulated devices.
Move it to common code.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb-bt.c |4 
 hw/usb-desc.c   |6 ++
 hw/usb-hid.c|4 
 hw/usb-hub.c|4 
 hw/usb-msd.c|4 
 hw/usb-net.c|5 -
 hw/usb-serial.c |4 
 hw/usb-wacom.c  |4 
 trace-events|1 +
 9 files changed, 7 insertions(+), 29 deletions(-)

diff --git a/hw/usb-bt.c b/hw/usb-bt.c
index d7959ad..c0bfc35 100644
--- a/hw/usb-bt.c
+++ b/hw/usb-bt.c
@@ -413,10 +413,6 @@ static int usb_bt_handle_control(USBDevice *dev, int 
request, int value,
 }
 ret = 0;
 break;
-case DeviceOutRequest | USB_REQ_SET_ADDRESS:
-dev-addr = value;
-ret = 0;
-break;
 case DeviceRequest | USB_REQ_GET_CONFIGURATION:
 data[0] = 1;
 ret = 1;
diff --git a/hw/usb-desc.c b/hw/usb-desc.c
index 69ab207..3e87f46 100644
--- a/hw/usb-desc.c
+++ b/hw/usb-desc.c
@@ -266,6 +266,12 @@ int usb_desc_handle_control(USBDevice *dev, int request, 
int value,
 
 assert(desc != NULL);
 switch(request) {
+case DeviceOutRequest | USB_REQ_SET_ADDRESS:
+dev-addr = value;
+trace_usb_set_addr(dev-addr);
+ret = 0;
+break;
+
 case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
 ret = usb_desc_get_descriptor(dev, value, data, length);
 break;
diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index 74d17fc..72daddf 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -695,10 +695,6 @@ static int usb_hid_handle_control(USBDevice *dev, int 
request, int value,
 }
 ret = 0;
 break;
-case DeviceOutRequest | USB_REQ_SET_ADDRESS:
-dev-addr = value;
-ret = 0;
-break;
 case DeviceRequest | USB_REQ_GET_CONFIGURATION:
 data[0] = 1;
 ret = 1;
diff --git a/hw/usb-hub.c b/hw/usb-hub.c
index 0f8d060..51a67a2 100644
--- a/hw/usb-hub.c
+++ b/hw/usb-hub.c
@@ -297,10 +297,6 @@ static int usb_hub_handle_control(USBDevice *dev, int 
request, int value,
 }
 ret = 0;
 break;
-case DeviceOutRequest | USB_REQ_SET_ADDRESS:
-dev-addr = value;
-ret = 0;
-break;
 case DeviceRequest | USB_REQ_GET_CONFIGURATION:
 data[0] = 1;
 ret = 1;
diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index 9aa..b54ccbc 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -261,10 +261,6 @@ static int usb_msd_handle_control(USBDevice *dev, int 
request, int value,
 }
 ret = 0;
 break;
-case DeviceOutRequest | USB_REQ_SET_ADDRESS:
-dev-addr = value;
-ret = 0;
-break;
 case DeviceRequest | USB_REQ_GET_CONFIGURATION:
 data[0] = 1;
 ret = 1;
diff --git a/hw/usb-net.c b/hw/usb-net.c
index 3a34414..1a57ef7 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1075,11 +1075,6 @@ static int usb_net_handle_control(USBDevice *dev, int 
request, int value,
 ret = 0;
 break;
 
-case DeviceOutRequest | USB_REQ_SET_ADDRESS:
-dev-addr = value;
-ret = 0;
-break;
-
 case ClassInterfaceOutRequest | USB_CDC_SEND_ENCAPSULATED_COMMAND:
 if (!s-rndis || value || index != 0)
 goto fail;
diff --git a/hw/usb-serial.c b/hw/usb-serial.c
index f89eb9b..c1f31c7 100644
--- a/hw/usb-serial.c
+++ b/hw/usb-serial.c
@@ -254,10 +254,6 @@ static int usb_serial_handle_control(USBDevice *dev, int 
request, int value,
 }
 ret = 0;
 break;
-case DeviceOutRequest | USB_REQ_SET_ADDRESS:
-dev-addr = value;
-ret = 0;
-break;
 case DeviceRequest | USB_REQ_GET_CONFIGURATION:
 data[0] = 1;
 ret = 1;
diff --git a/hw/usb-wacom.c b/hw/usb-wacom.c
index ffe6ac7..ad1c3ae 100644
--- a/hw/usb-wacom.c
+++ b/hw/usb-wacom.c
@@ -284,10 +284,6 @@ static int usb_wacom_handle_control(USBDevice *dev, int 
request, int value,
 }
 ret = 0;
 break;
-case DeviceOutRequest | USB_REQ_SET_ADDRESS:
-dev-addr = value;
-ret = 0;
-break;
 case DeviceRequest | USB_REQ_GET_CONFIGURATION:
 data[0] = 1;
 ret = 1;
diff --git a/trace-events b/trace-events
index 23303c4..3372b78 100644
--- a/trace-events
+++ b/trace-events
@@ -194,6 +194,7 @@ disable sun4m_iommu_bad_addr(uint64_t addr) bad addr 
%PRIx64
 disable usb_desc_device(int addr, int len, int ret) dev %d query device, len 
%d, ret %d
 disable usb_desc_config(int addr, int index, int len, int ret) dev %d query 
config %d, len %d, ret %d
 disable usb_desc_string(int addr, int index, int len, int ret) dev %d query 
string %d, len %d, ret %d
+disable usb_set_addr(int addr) dev %d
 
 # vl.c
 disable vm_state_notify(int running, int reason) running %d reason %d
-- 
1.7.1




[Qemu-devel] [PATCH 02/30] usb: data structs and helpers for usb descriptors.

2010-12-17 Thread Gerd Hoffmann
This patch adds hw/usb-desc.[ch] files.  They carry data structures
for various usb descriptors and helper functions to generate usb
packets from the structures.

The intention is to have a internal representation of the device
desription which is more usable than the current char array blobs,
so we can have common code handle common usb device emulation using
the device description.

The usage of this infrastructure is optional for usb drivers as there
are cases such as pass-through where it probably isn't very useful.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 Makefile.objs |2 +-
 hw/usb-desc.c |  238 +
 hw/usb-desc.h |   86 +
 hw/usb.h  |9 ++
 trace-events  |5 +
 5 files changed, 339 insertions(+), 1 deletions(-)
 create mode 100644 hw/usb-desc.c
 create mode 100644 hw/usb-desc.h

diff --git a/Makefile.objs b/Makefile.objs
index 04625eb..39b1aea 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -85,7 +85,7 @@ common-obj-y += eeprom93xx.o
 common-obj-y += scsi-disk.o cdrom.o
 common-obj-y += scsi-generic.o scsi-bus.o
 common-obj-y += usb.o usb-hub.o usb-$(HOST_USB).o usb-hid.o usb-msd.o 
usb-wacom.o
-common-obj-y += usb-serial.o usb-net.o usb-bus.o
+common-obj-y += usb-serial.o usb-net.o usb-bus.o usb-desc.o
 common-obj-$(CONFIG_SSI) += ssi.o
 common-obj-$(CONFIG_SSI_SD) += ssi-sd.o
 common-obj-$(CONFIG_SD) += sd.o
diff --git a/hw/usb-desc.c b/hw/usb-desc.c
new file mode 100644
index 000..559ced7
--- /dev/null
+++ b/hw/usb-desc.c
@@ -0,0 +1,238 @@
+#include usb.h
+#include usb-desc.h
+#include trace.h
+
+/* -- */
+
+static uint8_t usb_lo(uint16_t val)
+{
+return val  0xff;
+}
+
+static uint8_t usb_hi(uint16_t val)
+{
+return (val  8)  0xff;
+}
+
+int usb_desc_device(const USBDescID *id, const USBDescDevice *dev,
+uint8_t *dest, size_t len)
+{
+uint8_t bLength = 0x12;
+
+if (len  bLength) {
+return -1;
+}
+
+dest[0x00] = bLength;
+dest[0x01] = USB_DT_DEVICE;
+
+dest[0x02] = usb_lo(dev-bcdUSB);
+dest[0x03] = usb_hi(dev-bcdUSB);
+dest[0x04] = dev-bDeviceClass;
+dest[0x05] = dev-bDeviceSubClass;
+dest[0x06] = dev-bDeviceProtocol;
+dest[0x07] = dev-bMaxPacketSize0;
+
+dest[0x08] = usb_lo(id-idVendor);
+dest[0x09] = usb_hi(id-idVendor);
+dest[0x0a] = usb_lo(id-idProduct);
+dest[0x0b] = usb_hi(id-idProduct);
+dest[0x0c] = usb_lo(id-bcdDevice);
+dest[0x0d] = usb_hi(id-bcdDevice);
+dest[0x0e] = id-iManufacturer;
+dest[0x0f] = id-iProduct;
+dest[0x10] = id-iSerialNumber;
+
+dest[0x11] = dev-bNumConfigurations;
+
+return bLength;
+}
+
+int usb_desc_config(const USBDescConfig *conf, uint8_t *dest, size_t len)
+{
+uint8_t  bLength = 0x09;
+uint16_t wTotalLength = 0;
+int i, rc, count;
+
+if (len  bLength) {
+return -1;
+}
+
+dest[0x00] = bLength;
+dest[0x01] = USB_DT_CONFIG;
+dest[0x04] = conf-bNumInterfaces;
+dest[0x05] = conf-bConfigurationValue;
+dest[0x06] = conf-iConfiguration;
+dest[0x07] = conf-bmAttributes;
+dest[0x08] = conf-bMaxPower;
+wTotalLength += bLength;
+
+count = conf-nif ? conf-nif : conf-bNumInterfaces;
+for (i = 0; i  count; i++) {
+rc = usb_desc_iface(conf-ifs + i, dest + wTotalLength, len - 
wTotalLength);
+if (rc  0) {
+return rc;
+}
+wTotalLength += rc;
+}
+
+dest[0x02] = usb_lo(wTotalLength);
+dest[0x03] = usb_hi(wTotalLength);
+return wTotalLength;
+}
+
+int usb_desc_iface(const USBDescIface *iface, uint8_t *dest, size_t len)
+{
+uint8_t bLength = 0x09;
+int i, rc, pos = 0;
+
+if (len  bLength) {
+return -1;
+}
+
+dest[0x00] = bLength;
+dest[0x01] = USB_DT_INTERFACE;
+dest[0x02] = iface-bInterfaceNumber;
+dest[0x03] = iface-bAlternateSetting;
+dest[0x04] = iface-bNumEndpoints;
+dest[0x05] = iface-bInterfaceClass;
+dest[0x06] = iface-bInterfaceSubClass;
+dest[0x07] = iface-bInterfaceProtocol;
+dest[0x08] = iface-iInterface;
+pos += bLength;
+
+for (i = 0; i  iface-ndesc; i++) {
+rc = usb_desc_other(iface-descs + i, dest + pos, len - pos);
+if (rc  0) {
+return rc;
+}
+pos += rc;
+}
+
+for (i = 0; i  iface-bNumEndpoints; i++) {
+rc = usb_desc_endpoint(iface-eps + i, dest + pos, len - pos);
+if (rc  0) {
+return rc;
+}
+pos += rc;
+}
+
+return pos;
+}
+
+int usb_desc_endpoint(const USBDescEndpoint *ep, uint8_t *dest, size_t len)
+{
+uint8_t bLength = 0x07;
+
+if (len  bLength) {
+return -1;
+}
+
+dest[0x00] = bLength;
+dest[0x01] = USB_DT_ENDPOINT;
+dest[0x02] = ep-bEndpointAddress;
+dest[0x03] = ep-bmAttributes;
+dest[0x04] = usb_lo(ep-wMaxPacketSize);
+dest[0x05] = 

[Qemu-devel] [PATCH 10/30] usb storage: serial number support

2010-12-17 Thread Gerd Hoffmann
If a serial number is present for the drive fill it into the usb
serialnumber string descriptor.

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

diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index 20ab886..9aa 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -482,6 +482,7 @@ static int usb_msd_initfn(USBDevice *dev)
 {
 MSDState *s = DO_UPCAST(MSDState, dev, dev);
 BlockDriverState *bs = s-conf.bs;
+DriveInfo *dinfo;
 
 if (!bs) {
 error_report(usb-msd: drive property not set);
@@ -500,6 +501,11 @@ static int usb_msd_initfn(USBDevice *dev)
 bdrv_detach(bs, s-dev.qdev);
 s-conf.bs = NULL;
 
+dinfo = drive_get_by_blockdev(bs);
+if (dinfo  dinfo-serial) {
+usb_desc_set_string(dev, STR_SERIALNUMBER, dinfo-serial);
+}
+
 s-dev.speed = USB_SPEED_FULL;
 scsi_bus_new(s-bus, s-dev.qdev, 0, 1, usb_msd_command_complete);
 s-scsi_dev = scsi_bus_legacy_add_drive(s-bus, bs, 0);
-- 
1.7.1




[Qemu-devel] [PATCH 05/30] usb storage: use new descriptor infrastructure.

2010-12-17 Thread Gerd Hoffmann
Switch the usb storage driver over to the
new descriptor infrastructure.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb-msd.c |  167 ++
 1 files changed, 63 insertions(+), 104 deletions(-)

diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index 0a95d8d..20ab886 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -11,6 +11,7 @@
 #include qemu-option.h
 #include qemu-config.h
 #include usb.h
+#include usb-desc.h
 #include scsi.h
 #include console.h
 #include monitor.h
@@ -72,69 +73,62 @@ struct usb_msd_csw {
 uint8_t status;
 };
 
-static const uint8_t qemu_msd_dev_descriptor[] = {
-   0x12,   /*  u8 bLength; */
-   0x01,   /*  u8 bDescriptorType; Device */
-   0x00, 0x01, /*  u16 bcdUSB; v1.0 */
-
-   0x00,   /*  u8  bDeviceClass; */
-   0x00,   /*  u8  bDeviceSubClass; */
-   0x00,   /*  u8  bDeviceProtocol; [ low/full speeds only ] */
-   0x08,   /*  u8  bMaxPacketSize0; 8 Bytes */
-
-/* Vendor and product id are arbitrary.  */
-   0x00, 0x00, /*  u16 idVendor; */
-   0x00, 0x00, /*  u16 idProduct; */
-   0x00, 0x00, /*  u16 bcdDevice */
-
-   0x01,   /*  u8  iManufacturer; */
-   0x02,   /*  u8  iProduct; */
-   0x03,   /*  u8  iSerialNumber; */
-   0x01/*  u8  bNumConfigurations; */
+enum {
+STR_MANUFACTURER = 1,
+STR_PRODUCT,
+STR_SERIALNUMBER,
 };
 
-static const uint8_t qemu_msd_config_descriptor[] = {
-
-   /* one configuration */
-   0x09,   /*  u8  bLength; */
-   0x02,   /*  u8  bDescriptorType; Configuration */
-   0x20, 0x00, /*  u16 wTotalLength; */
-   0x01,   /*  u8  bNumInterfaces; (1) */
-   0x01,   /*  u8  bConfigurationValue; */
-   0x00,   /*  u8  iConfiguration; */
-   0xc0,   /*  u8  bmAttributes;
-Bit 7: must be set,
-6: Self-powered,
-5: Remote wakeup,
-4..0: resvd */
-   0x00,   /*  u8  MaxPower; */
-
-   /* one interface */
-   0x09,   /*  u8  if_bLength; */
-   0x04,   /*  u8  if_bDescriptorType; Interface */
-   0x00,   /*  u8  if_bInterfaceNumber; */
-   0x00,   /*  u8  if_bAlternateSetting; */
-   0x02,   /*  u8  if_bNumEndpoints; */
-   0x08,   /*  u8  if_bInterfaceClass; MASS STORAGE */
-   0x06,   /*  u8  if_bInterfaceSubClass; SCSI */
-   0x50,   /*  u8  if_bInterfaceProtocol; Bulk Only */
-   0x00,   /*  u8  if_iInterface; */
-
-   /* Bulk-In endpoint */
-   0x07,   /*  u8  ep_bLength; */
-   0x05,   /*  u8  ep_bDescriptorType; Endpoint */
-   0x81,   /*  u8  ep_bEndpointAddress; IN Endpoint 1 */
-   0x02,   /*  u8  ep_bmAttributes; Bulk */
-   0x40, 0x00, /*  u16 ep_wMaxPacketSize; */
-   0x00,   /*  u8  ep_bInterval; */
-
-   /* Bulk-Out endpoint */
-   0x07,   /*  u8  ep_bLength; */
-   0x05,   /*  u8  ep_bDescriptorType; Endpoint */
-   0x02,   /*  u8  ep_bEndpointAddress; OUT Endpoint 2 */
-   0x02,   /*  u8  ep_bmAttributes; Bulk */
-   0x40, 0x00, /*  u16 ep_wMaxPacketSize; */
-   0x00/*  u8  ep_bInterval; */
+static const USBDescStrings desc_strings = {
+[STR_MANUFACTURER] = QEMU  QEMU_VERSION,
+[STR_PRODUCT]  = QEMU USB HARDDRIVE,
+[STR_SERIALNUMBER] = 1,
+};
+
+static const USBDescIface desc_iface0 = {
+.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= 64,
+},{
+.bEndpointAddress  = USB_DIR_OUT | 0x02,
+.bmAttributes  = USB_ENDPOINT_XFER_BULK,
+.wMaxPacketSize= 64,
+},
+}
+};
+
+static const USBDescDevice desc_device = {
+.bcdUSB= 0x0100,
+.bMaxPacketSize0   = 8,
+.bNumConfigurations= 1,
+.confs = (USBDescConfig[]) {
+{
+.bNumInterfaces= 1,
+.bConfigurationValue   = 1,
+.bmAttributes  = 0xc0,
+.ifs = desc_iface0,
+},
+},
+};
+
+static const USBDesc desc = {
+.id = {
+.idVendor  = 0,
+.idProduct = 0,
+.bcdDevice = 0,
+.iManufacturer = STR_MANUFACTURER,
+.iProduct  = STR_PRODUCT,
+.iSerialNumber = STR_SERIALNUMBER,
+},
+.full = desc_device,
+.str  = desc_strings,
 };
 
 static 

[Qemu-devel] [PATCH 13/30] usb: move USB_REQ_{GET, SET}_CONFIGURATION handling to common code

2010-12-17 Thread Gerd Hoffmann
This patch adds fields to the USBDevice struct for the current
speed (hard-wired to full speed for now) and current device
configuration.  Also a init function is added which inializes
these fields.  This allows USB_REQ_{GET,SET}_CONFIGURATION
handling to be moved to common code.

For most drivers the conversion is trivial ad they support a single
configuration only anyway.  One exception is bluetooth where some
device-specific setup code runs after get/set configuration.  The
other is usb-net which actually has two configurations so the
the code to check for the active configuration has been adapted.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb-bt.c |   31 ---
 hw/usb-desc.c   |   32 
 hw/usb-desc.h   |1 +
 hw/usb-hid.c|   10 ++
 hw/usb-hub.c|9 +
 hw/usb-msd.c|9 +
 hw/usb-net.c|   45 +++--
 hw/usb-serial.c |   10 ++
 hw/usb-wacom.c  |9 +
 hw/usb.h|2 ++
 trace-events|1 +
 11 files changed, 66 insertions(+), 93 deletions(-)

diff --git a/hw/usb-bt.c b/hw/usb-bt.c
index c0bfc35..36c90a3 100644
--- a/hw/usb-bt.c
+++ b/hw/usb-bt.c
@@ -380,6 +380,17 @@ static int usb_bt_handle_control(USBDevice *dev, int 
request, int value,
 
 ret = usb_desc_handle_control(dev, request, value, index, length, data);
 if (ret = 0) {
+switch (request) {
+case DeviceRequest | USB_REQ_GET_CONFIGURATION:
+s-config = 0;
+break;
+case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
+s-config = 1;
+usb_bt_fifo_reset(s-evt);
+usb_bt_fifo_reset(s-acl);
+usb_bt_fifo_reset(s-sco);
+break;
+}
 return ret;
 }
 
@@ -413,23 +424,6 @@ static int usb_bt_handle_control(USBDevice *dev, int 
request, int value,
 }
 ret = 0;
 break;
-case DeviceRequest | USB_REQ_GET_CONFIGURATION:
-data[0] = 1;
-ret = 1;
-s-config = 0;
-break;
-case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
-ret = 0;
-if (value != 1  value != 0) {
-printf(%s: Wrong SET_CONFIGURATION request (%i)\n,
-__FUNCTION__, value);
-goto fail;
-}
-s-config = 1;
-usb_bt_fifo_reset(s-evt);
-usb_bt_fifo_reset(s-acl);
-usb_bt_fifo_reset(s-sco);
-break;
 case InterfaceRequest | USB_REQ_GET_INTERFACE:
 if (value != 0 || (index  ~1) || length != 1)
 goto fail;
@@ -544,8 +538,7 @@ static void usb_bt_handle_destroy(USBDevice *dev)
 
 static int usb_bt_initfn(USBDevice *dev)
 {
-struct USBBtState *s = DO_UPCAST(struct USBBtState, dev, dev);
-s-dev.speed = USB_SPEED_HIGH;
+usb_desc_init(dev);
 return 0;
 }
 
diff --git a/hw/usb-desc.c b/hw/usb-desc.c
index 3e87f46..14c9e11 100644
--- a/hw/usb-desc.c
+++ b/hw/usb-desc.c
@@ -153,6 +153,16 @@ int usb_desc_other(const USBDescOther *desc, uint8_t 
*dest, size_t len)
 
 /* -- */
 
+void usb_desc_init(USBDevice *dev)
+{
+const USBDesc *desc = dev-info-usb_desc;
+
+assert(desc != NULL);
+dev-speed  = USB_SPEED_FULL;
+dev-device = desc-full;
+dev-config = dev-device-confs;
+}
+
 void usb_desc_set_string(USBDevice *dev, uint8_t index, const char *str)
 {
 USBDescString *s;
@@ -230,12 +240,12 @@ int usb_desc_get_descriptor(USBDevice *dev, int value, 
uint8_t *dest, size_t len
 
 switch(type) {
 case USB_DT_DEVICE:
-ret = usb_desc_device(desc-id, desc-full, buf, sizeof(buf));
+ret = usb_desc_device(desc-id, dev-device, buf, sizeof(buf));
 trace_usb_desc_device(dev-addr, len, ret);
 break;
 case USB_DT_CONFIG:
-if (index  desc-full-bNumConfigurations) {
-ret = usb_desc_config(desc-full-confs + index, buf, sizeof(buf));
+if (index  dev-device-bNumConfigurations) {
+ret = usb_desc_config(dev-device-confs + index, buf, 
sizeof(buf));
 }
 trace_usb_desc_config(dev-addr, index, len, ret);
 break;
@@ -262,7 +272,7 @@ int usb_desc_handle_control(USBDevice *dev, int request, 
int value,
 int index, int length, uint8_t *data)
 {
 const USBDesc *desc = dev-info-usb_desc;
-int ret = -1;
+int i, ret = -1;
 
 assert(desc != NULL);
 switch(request) {
@@ -275,6 +285,20 @@ int usb_desc_handle_control(USBDevice *dev, int request, 
int value,
 case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
 ret = usb_desc_get_descriptor(dev, value, data, length);
 break;
+
+case DeviceRequest | USB_REQ_GET_CONFIGURATION:
+data[0] = dev-config-bConfigurationValue;
+ret = 1;
+break;
+case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
+for (i = 0; i 

[Qemu-devel] [PATCH 17/30] usb: add usb_wakeup() + wakeup callback to port ops

2010-12-17 Thread Gerd Hoffmann
Add wakeup callback to port ops for remote wakeup handling.
Also add a usb_wakeup() function for devices which want
trigger a remote wakeup.

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

diff --git a/hw/usb.c b/hw/usb.c
index 2eda86a..ba720b4 100644
--- a/hw/usb.c
+++ b/hw/usb.c
@@ -49,6 +49,13 @@ void usb_attach(USBPort *port, USBDevice *dev)
 }
 }
 
+void usb_wakeup(USBDevice *dev)
+{
+if (dev-remote_wakeup  dev-port  dev-port-ops-wakeup) {
+dev-port-ops-wakeup(dev);
+}
+}
+
 /**/
 
 /* generic USB device helpers (you are not forced to use them when
diff --git a/hw/usb.h b/hw/usb.h
index 6b008cc..9f454e6 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -220,6 +220,7 @@ struct USBDeviceInfo {
 typedef struct USBPortOps {
 void (*attach)(USBPort *port);
 void (*detach)(USBPort *port);
+void (*wakeup)(USBDevice *dev);
 } USBPortOps;
 
 /* USB port on which a device can be connected */
@@ -274,6 +275,7 @@ static inline void usb_cancel_packet(USBPacket * p)
 }
 
 void usb_attach(USBPort *port, USBDevice *dev);
+void usb_wakeup(USBDevice *dev);
 int usb_generic_handle_packet(USBDevice *s, USBPacket *p);
 int set_usb_string(uint8_t *buf, const char *str);
 void usb_send_msg(USBDevice *dev, int msg);
-- 
1.7.1




[Qemu-devel] [PATCH 19/30] usb: hub: remote wakeup support.

2010-12-17 Thread Gerd Hoffmann
This patch makes the usb hub handle remote wakeup requests from devices
properly by updating the port status register and forwarding the wakeup
to the upstream port.

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

diff --git a/hw/usb-hub.c b/hw/usb-hub.c
index 5aa1d0b..9a073f8 100644
--- a/hw/usb-hub.c
+++ b/hw/usb-hub.c
@@ -245,6 +245,17 @@ static void usb_hub_detach(USBPort *port1)
 }
 }
 
+static void usb_hub_wakeup(USBDevice *dev)
+{
+USBHubState *s = dev-port-opaque;
+USBHubPort *port = s-ports[dev-port-index];
+
+if (port-wPortStatus  PORT_STAT_SUSPEND) {
+port-wPortChange |= PORT_STAT_C_SUSPEND;
+usb_wakeup(s-dev);
+}
+}
+
 static void usb_hub_handle_reset(USBDevice *dev)
 {
 /* XXX: do it */
@@ -502,6 +513,7 @@ static void usb_hub_handle_destroy(USBDevice *dev)
 static USBPortOps usb_hub_port_ops = {
 .attach = usb_hub_attach,
 .detach = usb_hub_detach,
+.wakeup = usb_hub_wakeup,
 };
 
 static int usb_hub_initfn(USBDevice *dev)
-- 
1.7.1




[Qemu-devel] [PATCH 07/30] usb bluetooth: use new descriptor infrastructure.

2010-12-17 Thread Gerd Hoffmann
Switch the usb bluetooth driver over to the
new descriptor infrastructure.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb-bt.c |  473 +--
 1 files changed, 202 insertions(+), 271 deletions(-)

diff --git a/hw/usb-bt.c b/hw/usb-bt.c
index 56d1a6c..d7959ad 100644
--- a/hw/usb-bt.c
+++ b/hw/usb-bt.c
@@ -20,6 +20,7 @@
 
 #include qemu-common.h
 #include usb.h
+#include usb-desc.h
 #include net.h
 #include bt.h
 
@@ -51,251 +52,202 @@ struct USBBtState {
 #define USB_ACL_EP 2
 #define USB_SCO_EP 3
 
-static const uint8_t qemu_bt_dev_descriptor[] = {
-0x12,  /*  u8 bLength; */
-USB_DT_DEVICE, /*  u8 bDescriptorType; Device */
-0x10, 0x01,/*  u16 bcdUSB; v1.10 */
+enum {
+STR_MANUFACTURER = 1,
+STR_SERIALNUMBER,
+};
 
-0xe0,  /*  u8  bDeviceClass; Wireless */
-0x01,  /*  u8  bDeviceSubClass; Radio Frequency */
-0x01,  /*  u8  bDeviceProtocol; Bluetooth */
-0x40,  /*  u8  bMaxPacketSize0; 64 Bytes */
+static const USBDescStrings desc_strings = {
+[STR_MANUFACTURER] = QEMU  QEMU_VERSION,
+[STR_SERIALNUMBER] = 1,
+};
 
-0x12, 0x0a,/*  u16 idVendor; */
-0x01, 0x00,/*  u16 idProduct; Bluetooth Dongle (HCI mode) */
-0x58, 0x19,/*  u16 bcdDevice; (some devices have 0x48, 0x02) */
+static const USBDescIface desc_iface_bluetooth[] = {
+{
+.bInterfaceNumber  = 0,
+.bNumEndpoints = 3,
+.bInterfaceClass   = 0xe0, /* Wireless */
+.bInterfaceSubClass= 0x01, /* Radio Frequency */
+.bInterfaceProtocol= 0x01, /* Bluetooth */
+.eps = (USBDescEndpoint[]) {
+{
+.bEndpointAddress  = USB_DIR_IN | USB_EVT_EP,
+.bmAttributes  = USB_ENDPOINT_XFER_INT,
+.wMaxPacketSize= 0x10,
+.bInterval = 0x02,
+},
+{
+.bEndpointAddress  = USB_DIR_OUT | USB_ACL_EP,
+.bmAttributes  = USB_ENDPOINT_XFER_BULK,
+.wMaxPacketSize= 0x40,
+.bInterval = 0x0a,
+},
+{
+.bEndpointAddress  = USB_DIR_IN | USB_ACL_EP,
+.bmAttributes  = USB_ENDPOINT_XFER_BULK,
+.wMaxPacketSize= 0x40,
+.bInterval = 0x0a,
+},
+},
+},{
+.bInterfaceNumber  = 1,
+.bAlternateSetting = 0,
+.bNumEndpoints = 2,
+.bInterfaceClass   = 0xe0, /* Wireless */
+.bInterfaceSubClass= 0x01, /* Radio Frequency */
+.bInterfaceProtocol= 0x01, /* Bluetooth */
+.eps = (USBDescEndpoint[]) {
+{
+.bEndpointAddress  = USB_DIR_OUT | USB_SCO_EP,
+.bmAttributes  = USB_ENDPOINT_XFER_INT,
+.wMaxPacketSize= 0,
+.bInterval = 0x01,
+},
+{
+.bEndpointAddress  = USB_DIR_IN | USB_SCO_EP,
+.bmAttributes  = USB_ENDPOINT_XFER_INT,
+.wMaxPacketSize= 0,
+.bInterval = 0x01,
+},
+},
+},{
+.bInterfaceNumber  = 1,
+.bAlternateSetting = 1,
+.bNumEndpoints = 2,
+.bInterfaceClass   = 0xe0, /* Wireless */
+.bInterfaceSubClass= 0x01, /* Radio Frequency */
+.bInterfaceProtocol= 0x01, /* Bluetooth */
+.eps = (USBDescEndpoint[]) {
+{
+.bEndpointAddress  = USB_DIR_OUT | USB_SCO_EP,
+.bmAttributes  = USB_ENDPOINT_XFER_INT,
+.wMaxPacketSize= 0x09,
+.bInterval = 0x01,
+},
+{
+.bEndpointAddress  = USB_DIR_IN | USB_SCO_EP,
+.bmAttributes  = USB_ENDPOINT_XFER_INT,
+.wMaxPacketSize= 0x09,
+.bInterval = 0x01,
+},
+},
+},{
+.bInterfaceNumber  = 1,
+.bAlternateSetting = 2,
+.bNumEndpoints = 2,
+.bInterfaceClass   = 0xe0, /* Wireless */
+.bInterfaceSubClass= 0x01, /* Radio Frequency */
+.bInterfaceProtocol= 0x01, /* Bluetooth */
+.eps = (USBDescEndpoint[]) {
+{
+.bEndpointAddress  = USB_DIR_OUT | USB_SCO_EP,
+.bmAttributes  = USB_ENDPOINT_XFER_INT,
+.wMaxPacketSize= 0x11,
+.bInterval   

[Qemu-devel] [PATCH 09/30] usb descriptors: add settable strings.

2010-12-17 Thread Gerd Hoffmann
This patch allows to set usb descriptor strings per device instance.

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

diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index b692503..15a42ff 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -46,6 +46,7 @@ static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base)
 pstrcpy(dev-product_desc, sizeof(dev-product_desc), info-product_desc);
 dev-info = info;
 dev-auto_attach = 1;
+QLIST_INIT(dev-strings);
 rc = dev-info-init(dev);
 if (rc == 0  dev-auto_attach)
 usb_device_attach(dev);
diff --git a/hw/usb-desc.c b/hw/usb-desc.c
index 559ced7..69ab207 100644
--- a/hw/usb-desc.c
+++ b/hw/usb-desc.c
@@ -151,9 +151,42 @@ int usb_desc_other(const USBDescOther *desc, uint8_t 
*dest, size_t len)
 return bLength;
 }
 
-int usb_desc_string(const char* const *str, int index, uint8_t *dest, size_t 
len)
+/* -- */
+
+void usb_desc_set_string(USBDevice *dev, uint8_t index, const char *str)
+{
+USBDescString *s;
+
+QLIST_FOREACH(s, dev-strings, next) {
+if (s-index == index) {
+break;
+}
+}
+if (s == NULL) {
+s = qemu_mallocz(sizeof(*s));
+s-index = index;
+QLIST_INSERT_HEAD(dev-strings, s, next);
+}
+qemu_free(s-str);
+s-str = qemu_strdup(str);
+}
+
+const char *usb_desc_get_string(USBDevice *dev, uint8_t index)
+{
+USBDescString *s;
+
+QLIST_FOREACH(s, dev-strings, next) {
+if (s-index == index) {
+return s-str;
+}
+}
+return NULL;
+}
+
+int usb_desc_string(USBDevice *dev, int index, uint8_t *dest, size_t len)
 {
 uint8_t bLength, pos, i;
+const char *str;
 
 if (len  4) {
 return -1;
@@ -168,22 +201,25 @@ int usb_desc_string(const char* const *str, int index, 
uint8_t *dest, size_t len
 return 4;
 }
 
-if (str[index] == NULL) {
-return 0;
+str = usb_desc_get_string(dev, index);
+if (str == NULL) {
+str = dev-info-usb_desc-str[index];
+if (str == NULL) {
+return 0;
+}
 }
-bLength = strlen(str[index]) * 2 + 2;
+
+bLength = strlen(str) * 2 + 2;
 dest[0] = bLength;
 dest[1] = USB_DT_STRING;
 i = 0; pos = 2;
 while (pos+1  bLength  pos+1  len) {
-dest[pos++] = str[index][i++];
+dest[pos++] = str[i++];
 dest[pos++] = 0;
 }
 return pos;
 }
 
-/* -- */
-
 int usb_desc_get_descriptor(USBDevice *dev, int value, uint8_t *dest, size_t 
len)
 {
 const USBDesc *desc = dev-info-usb_desc;
@@ -204,7 +240,7 @@ int usb_desc_get_descriptor(USBDevice *dev, int value, 
uint8_t *dest, size_t len
 trace_usb_desc_config(dev-addr, index, len, ret);
 break;
 case USB_DT_STRING:
-ret = usb_desc_string(desc-str, index, buf, sizeof(buf));
+ret = usb_desc_string(dev, index, buf, sizeof(buf));
 trace_usb_desc_string(dev-addr, index, len, ret);
 break;
 default:
diff --git a/hw/usb-desc.h b/hw/usb-desc.h
index d80efdb..20fc400 100644
--- a/hw/usb-desc.h
+++ b/hw/usb-desc.h
@@ -76,9 +76,11 @@ int usb_desc_config(const USBDescConfig *conf, uint8_t 
*dest, size_t len);
 int usb_desc_iface(const USBDescIface *iface, uint8_t *dest, size_t len);
 int usb_desc_endpoint(const USBDescEndpoint *ep, uint8_t *dest, size_t len);
 int usb_desc_other(const USBDescOther *desc, uint8_t *dest, size_t len);
-int usb_desc_string(const char* const *str, int index, uint8_t *dest, size_t 
len);
 
 /* control message emulation helpers */
+void usb_desc_set_string(USBDevice *dev, uint8_t index, const char *str);
+const char *usb_desc_get_string(USBDevice *dev, uint8_t index);
+int usb_desc_string(USBDevice *dev, int index, uint8_t *dest, size_t len);
 int usb_desc_get_descriptor(USBDevice *dev, int value, uint8_t *dest, size_t 
len);
 int usb_desc_handle_control(USBDevice *dev, int request, int value,
 int index, int length, uint8_t *data);
diff --git a/hw/usb.h b/hw/usb.h
index 3aeb975..760550d 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -135,6 +135,13 @@ typedef struct USBDescConfig USBDescConfig;
 typedef struct USBDescIface USBDescIface;
 typedef struct USBDescEndpoint USBDescEndpoint;
 typedef struct USBDescOther USBDescOther;
+typedef struct USBDescString USBDescString;
+
+struct USBDescString {
+uint8_t index;
+char *str;
+QLIST_ENTRY(USBDescString) next;
+};
 
 /* definition of a USB device */
 struct USBDevice {
@@ -155,6 +162,8 @@ struct USBDevice {
 int setup_state;
 int setup_len;
 int setup_index;
+
+QLIST_HEAD(, USBDescString) strings;
 };
 
 struct USBDeviceInfo {
-- 
1.7.1



[Qemu-devel] [PATCH 06/30] usb wacom: use new descriptor infrastructure.

2010-12-17 Thread Gerd Hoffmann
Switch the usb wavom driver over to the
new descriptor infrastructure.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb-wacom.c |  178 +++-
 1 files changed, 73 insertions(+), 105 deletions(-)

diff --git a/hw/usb-wacom.c b/hw/usb-wacom.c
index 47f26cd..ffe6ac7 100644
--- a/hw/usb-wacom.c
+++ b/hw/usb-wacom.c
@@ -28,6 +28,7 @@
 #include hw.h
 #include console.h
 #include usb.h
+#include usb-desc.h
 
 /* Interface requests */
 #define WACOM_GET_REPORT   0x2101
@@ -54,68 +55,75 @@ typedef struct USBWacomState {
 int changed;
 } USBWacomState;
 
-static const uint8_t qemu_wacom_dev_descriptor[] = {
-0x12,  /*  u8 bLength; */
-0x01,  /*  u8 bDescriptorType; Device */
-0x10, 0x10,/*  u16 bcdUSB; v1.10 */
+enum {
+STR_MANUFACTURER = 1,
+STR_PRODUCT,
+STR_SERIALNUMBER,
+};
 
-0x00,  /*  u8  bDeviceClass; */
-0x00,  /*  u8  bDeviceSubClass; */
-0x00,  /*  u8  bDeviceProtocol; [ low/full speeds only ] */
-0x08,  /*  u8  bMaxPacketSize0; 8 Bytes */
+static const USBDescStrings desc_strings = {
+[STR_MANUFACTURER] = QEMU  QEMU_VERSION,
+[STR_PRODUCT]  = Wacom PenPartner,
+[STR_SERIALNUMBER] = 1,
+};
 
-0x6a, 0x05,/*  u16 idVendor; */
-0x00, 0x00,/*  u16 idProduct; */
-0x10, 0x42,/*  u16 bcdDevice */
+static const USBDescIface desc_iface_wacom = {
+.bInterfaceNumber  = 0,
+.bNumEndpoints = 1,
+.bInterfaceClass   = USB_CLASS_HID,
+.bInterfaceSubClass= 0x01, /* boot */
+.bInterfaceProtocol= 0x02,
+.ndesc = 1,
+.descs = (USBDescOther[]) {
+{
+/* HID descriptor */
+.data = (uint8_t[]) {
+0x09,  /*  u8  bLength */
+0x21,  /*  u8  bDescriptorType */
+0x01, 0x10,/*  u16 HID_class */
+0x00,  /*  u8  country_code */
+0x01,  /*  u8  num_descriptors */
+0x22,  /*  u8  type: Report */
+0x6e, 0,   /*  u16 len */
+},
+},
+},
+.eps = (USBDescEndpoint[]) {
+{
+.bEndpointAddress  = USB_DIR_IN | 0x01,
+.bmAttributes  = USB_ENDPOINT_XFER_INT,
+.wMaxPacketSize= 8,
+.bInterval = 0x0a,
+},
+},
+};
 
-0x01,  /*  u8  iManufacturer; */
-0x02,  /*  u8  iProduct; */
-0x00,  /*  u8  iSerialNumber; */
-0x01,  /*  u8  bNumConfigurations; */
+static const USBDescDevice desc_device_wacom = {
+.bcdUSB= 0x0110,
+.bMaxPacketSize0   = 8,
+.bNumConfigurations= 1,
+.confs = (USBDescConfig[]) {
+{
+.bNumInterfaces= 1,
+.bConfigurationValue   = 1,
+.bmAttributes  = 0x80,
+.bMaxPower = 40,
+.ifs = desc_iface_wacom,
+},
+},
 };
 
-static const uint8_t qemu_wacom_config_descriptor[] = {
-/* one configuration */
-0x09,  /*  u8  bLength; */
-0x02,  /*  u8  bDescriptorType; Configuration */
-0x22, 0x00,/*  u16 wTotalLength; */
-0x01,  /*  u8  bNumInterfaces; (1) */
-0x01,  /*  u8  bConfigurationValue; */
-0x00,  /*  u8  iConfiguration; */
-0x80,  /*  u8  bmAttributes;
-Bit 7: must be set,
-6: Self-powered,
-5: Remote wakeup,
-4..0: resvd */
-40,/*  u8  MaxPower; */
-
-/* one interface */
-0x09,  /*  u8  if_bLength; */
-0x04,  /*  u8  if_bDescriptorType; Interface */
-0x00,  /*  u8  if_bInterfaceNumber; */
-0x00,  /*  u8  if_bAlternateSetting; */
-0x01,  /*  u8  if_bNumEndpoints; */
-0x03,  /*  u8  if_bInterfaceClass; HID */
-0x01,  /*  u8  if_bInterfaceSubClass; Boot */
-0x02,  /*  u8  if_bInterfaceProtocol; [usb1.1 or single tt] */
-0x00,  /*  u8  if_iInterface; */
-
-/* HID descriptor */
-0x09,  /*  u8  bLength; */
-0x21,  /*  u8  bDescriptorType; */
-0x01, 0x10,/*  u16 HID_class */
-0x00,  /*  u8  country_code */
-0x01,  /*  u8  num_descriptors */
-0x22,  /*  u8  type; Report */
-0x6e, 0x00,/*  u16 len */
-
-/* one endpoint (status change endpoint) */
-0x07,  /*  u8  ep_bLength; */
-0x05,  /*  u8  ep_bDescriptorType; Endpoint */
-0x81,  /*  u8  ep_bEndpointAddress; IN Endpoint 1 */
-0x03,  /*  u8  ep_bmAttributes; Interrupt */
-0x08, 0x00,/*  u16 ep_wMaxPacketSize; */
-0x0a,  /*  u8  ep_bInterval; */
+static 

[Qemu-devel] [PATCH 24/30] usb: add usb_desc_attach

2010-12-17 Thread Gerd Hoffmann
Add usb_desc_attach() which sets up the device according to the speed
the usb port is able to handle.  This function can be hooked into the
handle_attach callback.

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

diff --git a/hw/usb-desc.c b/hw/usb-desc.c
index 56ef734..f01e1cf 100644
--- a/hw/usb-desc.c
+++ b/hw/usb-desc.c
@@ -153,16 +153,46 @@ int usb_desc_other(const USBDescOther *desc, uint8_t 
*dest, size_t len)
 
 /* -- */
 
-void usb_desc_init(USBDevice *dev)
+static void usb_desc_setdefaults(USBDevice *dev)
 {
 const USBDesc *desc = dev-info-usb_desc;
 
 assert(desc != NULL);
-dev-speed  = USB_SPEED_FULL;
-dev-device = desc-full;
+switch (dev-speed) {
+case USB_SPEED_LOW:
+case USB_SPEED_FULL:
+dev-device = desc-full;
+break;
+case USB_SPEED_HIGH:
+dev-device = desc-high;
+break;
+}
 dev-config = dev-device-confs;
 }
 
+void usb_desc_init(USBDevice *dev)
+{
+dev-speed = USB_SPEED_FULL;
+usb_desc_setdefaults(dev);
+}
+
+void usb_desc_attach(USBDevice *dev)
+{
+const USBDesc *desc = dev-info-usb_desc;
+
+assert(desc != NULL);
+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;
+} else {
+fprintf(stderr, usb: port/device speed mismatch for \%s\\n,
+dev-info-product_desc);
+return;
+}
+usb_desc_setdefaults(dev);
+}
+
 void usb_desc_set_string(USBDevice *dev, uint8_t index, const char *str)
 {
 USBDescString *s;
diff --git a/hw/usb-desc.h b/hw/usb-desc.h
index d441725..484c7c7 100644
--- a/hw/usb-desc.h
+++ b/hw/usb-desc.h
@@ -79,6 +79,7 @@ int usb_desc_other(const USBDescOther *desc, uint8_t *dest, 
size_t len);
 
 /* control message emulation helpers */
 void usb_desc_init(USBDevice *dev);
+void usb_desc_attach(USBDevice *dev);
 void usb_desc_set_string(USBDevice *dev, uint8_t index, const char *str);
 const char *usb_desc_get_string(USBDevice *dev, uint8_t index);
 int usb_desc_string(USBDevice *dev, int index, uint8_t *dest, size_t len);
-- 
1.7.1




[Qemu-devel] [PATCH 08/30] usb hub: use new descriptor infrastructure.

2010-12-17 Thread Gerd Hoffmann
Switch the usb hub driver over to the
new descriptor infrastructure.

It also removes the nr_ports variable and MAX_PORTS define and
introduces a NUM_PORTS define instead.  The numver of ports was
(and still is) fixed at 8 anyway.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb-hub.c |  141 --
 1 files changed, 78 insertions(+), 63 deletions(-)

diff --git a/hw/usb-hub.c b/hw/usb-hub.c
index 2a1edfc..0f8d060 100644
--- a/hw/usb-hub.c
+++ b/hw/usb-hub.c
@@ -23,10 +23,11 @@
  */
 #include qemu-common.h
 #include usb.h
+#include usb-desc.h
 
 //#define DEBUG
 
-#define MAX_PORTS 8
+#define NUM_PORTS 8
 
 typedef struct USBHubPort {
 USBPort port;
@@ -36,8 +37,7 @@ typedef struct USBHubPort {
 
 typedef struct USBHubState {
 USBDevice dev;
-int nb_ports;
-USBHubPort ports[MAX_PORTS];
+USBHubPort ports[NUM_PORTS];
 } USBHubState;
 
 #define ClearHubFeature(0x2000 | USB_REQ_CLEAR_FEATURE)
@@ -83,6 +83,60 @@ typedef struct USBHubState {
 
 /* same as Linux kernel root hubs */
 
+enum {
+STR_MANUFACTURER = 1,
+STR_PRODUCT,
+STR_SERIALNUMBER,
+};
+
+static const USBDescStrings desc_strings = {
+[STR_MANUFACTURER] = QEMU  QEMU_VERSION,
+[STR_PRODUCT]  = QEMU USB Hub,
+[STR_SERIALNUMBER] = 314159,
+};
+
+static const USBDescIface desc_iface_hub = {
+.bInterfaceNumber  = 0,
+.bNumEndpoints = 1,
+.bInterfaceClass   = USB_CLASS_HUB,
+.eps = (USBDescEndpoint[]) {
+{
+.bEndpointAddress  = USB_DIR_IN | 0x01,
+.bmAttributes  = USB_ENDPOINT_XFER_INT,
+.wMaxPacketSize= 1 + (NUM_PORTS + 7) / 8,
+.bInterval = 0xff,
+},
+}
+};
+
+static const USBDescDevice desc_device_hub = {
+.bcdUSB= 0x0110,
+.bDeviceClass  = USB_CLASS_HUB,
+.bMaxPacketSize0   = 8,
+.bNumConfigurations= 1,
+.confs = (USBDescConfig[]) {
+{
+.bNumInterfaces= 1,
+.bConfigurationValue   = 1,
+.bmAttributes  = 0xe0,
+.ifs = desc_iface_hub,
+},
+},
+};
+
+static const USBDesc desc_hub = {
+.id = {
+.idVendor  = 0,
+.idProduct = 0,
+.bcdDevice = 0x0101,
+.iManufacturer = STR_MANUFACTURER,
+.iProduct  = STR_PRODUCT,
+.iSerialNumber = STR_SERIALNUMBER,
+},
+.full = desc_device_hub,
+.str  = desc_strings,
+};
+
 static const uint8_t qemu_hub_dev_descriptor[] = {
0x12,   /*  u8 bLength; */
0x01,   /*  u8 bDescriptorType; Device */
@@ -209,6 +263,11 @@ static int usb_hub_handle_control(USBDevice *dev, int 
request, int value,
 USBHubState *s = (USBHubState *)dev;
 int ret;
 
+ret = usb_desc_handle_control(dev, request, value, index, length, data);
+if (ret = 0) {
+return ret;
+}
+
 switch(request) {
 case DeviceRequest | USB_REQ_GET_STATUS:
 data[0] = (1  USB_DEVICE_SELF_POWERED) |
@@ -242,53 +301,6 @@ static int usb_hub_handle_control(USBDevice *dev, int 
request, int value,
 dev-addr = value;
 ret = 0;
 break;
-case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
-switch(value  8) {
-case USB_DT_DEVICE:
-memcpy(data, qemu_hub_dev_descriptor,
-   sizeof(qemu_hub_dev_descriptor));
-ret = sizeof(qemu_hub_dev_descriptor);
-break;
-case USB_DT_CONFIG:
-memcpy(data, qemu_hub_config_descriptor,
-   sizeof(qemu_hub_config_descriptor));
-
-/* status change endpoint size based on number
- * of ports */
-data[22] = (s-nb_ports + 1 + 7) / 8;
-
-ret = sizeof(qemu_hub_config_descriptor);
-break;
-case USB_DT_STRING:
-switch(value  0xff) {
-case 0:
-/* language ids */
-data[0] = 4;
-data[1] = 3;
-data[2] = 0x09;
-data[3] = 0x04;
-ret = 4;
-break;
-case 1:
-/* serial number */
-ret = set_usb_string(data, 314159);
-break;
-case 2:
-/* product description */
-ret = set_usb_string(data, QEMU USB Hub);
-break;
-case 3:
-/* vendor description */
-ret = set_usb_string(data, QEMU  QEMU_VERSION);
-break;
-default:
-goto fail;
-}
-break;
-default:
-goto fail;
-}
-break;
 case DeviceRequest | USB_REQ_GET_CONFIGURATION:
 data[0] = 1;
 ret = 1;
@@ -315,8 +327,9 @@ static int 

[Qemu-devel] [PATCH 14/30] usb: move remote wakeup handling to common code

2010-12-17 Thread Gerd Hoffmann
This patch moves setting and clearing the remote_wakeup feature
bit (via USB_REQ_{SET,CLEAR}_FEATURE) to common code.  Also
USB_REQ_GET_STATUS handling is moved to common code.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb-bt.c |   21 +++--
 hw/usb-desc.c   |   26 ++
 hw/usb-hid.c|   22 --
 hw/usb-hub.c|   22 --
 hw/usb-msd.c|   23 ---
 hw/usb-net.c|   25 -
 hw/usb-serial.c |   22 --
 hw/usb-wacom.c  |   23 ---
 trace-events|2 ++
 9 files changed, 31 insertions(+), 155 deletions(-)

diff --git a/hw/usb-bt.c b/hw/usb-bt.c
index 36c90a3..22e6845 100644
--- a/hw/usb-bt.c
+++ b/hw/usb-bt.c
@@ -396,33 +396,18 @@ static int usb_bt_handle_control(USBDevice *dev, int 
request, int value,
 
 ret = 0;
 switch (request) {
-case DeviceRequest | USB_REQ_GET_STATUS:
 case InterfaceRequest | USB_REQ_GET_STATUS:
 case EndpointRequest | USB_REQ_GET_STATUS:
-data[0] = (1  USB_DEVICE_SELF_POWERED) |
-(dev-remote_wakeup  USB_DEVICE_REMOTE_WAKEUP);
+data[0] = 0x00;
 data[1] = 0x00;
 ret = 2;
 break;
-case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
 case InterfaceOutRequest | USB_REQ_CLEAR_FEATURE:
 case EndpointOutRequest | USB_REQ_CLEAR_FEATURE:
-if (value == USB_DEVICE_REMOTE_WAKEUP) {
-dev-remote_wakeup = 0;
-} else {
-goto fail;
-}
-ret = 0;
-break;
-case DeviceOutRequest | USB_REQ_SET_FEATURE:
+goto fail;
 case InterfaceOutRequest | USB_REQ_SET_FEATURE:
 case EndpointOutRequest | USB_REQ_SET_FEATURE:
-if (value == USB_DEVICE_REMOTE_WAKEUP) {
-dev-remote_wakeup = 1;
-} else {
-goto fail;
-}
-ret = 0;
+goto fail;
 break;
 case InterfaceRequest | USB_REQ_GET_INTERFACE:
 if (value != 0 || (index  ~1) || length != 1)
diff --git a/hw/usb-desc.c b/hw/usb-desc.c
index 14c9e11..56ef734 100644
--- a/hw/usb-desc.c
+++ b/hw/usb-desc.c
@@ -299,6 +299,32 @@ int usb_desc_handle_control(USBDevice *dev, int request, 
int value,
 }
 trace_usb_set_config(dev-addr, value, ret);
 break;
+
+case DeviceRequest | USB_REQ_GET_STATUS:
+data[0] = 0;
+if (dev-config-bmAttributes  0x40) {
+data[0] |= 1  USB_DEVICE_SELF_POWERED;
+}
+if (dev-remote_wakeup) {
+data[0] |= 1  USB_DEVICE_REMOTE_WAKEUP;
+}
+data[1] = 0x00;
+ret = 2;
+break;
+case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
+if (value == USB_DEVICE_REMOTE_WAKEUP) {
+dev-remote_wakeup = 0;
+ret = 0;
+}
+trace_usb_clear_device_feature(dev-addr, value, ret);
+break;
+case DeviceOutRequest | USB_REQ_SET_FEATURE:
+if (value == USB_DEVICE_REMOTE_WAKEUP) {
+dev-remote_wakeup = 1;
+ret = 0;
+}
+trace_usb_set_device_feature(dev-addr, value, ret);
+break;
 }
 return ret;
 }
diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index 21c0c72..1c35960 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -673,28 +673,6 @@ static int usb_hid_handle_control(USBDevice *dev, int 
request, int value,
 
 ret = 0;
 switch(request) {
-case DeviceRequest | USB_REQ_GET_STATUS:
-data[0] = (1  USB_DEVICE_SELF_POWERED) |
-(dev-remote_wakeup  USB_DEVICE_REMOTE_WAKEUP);
-data[1] = 0x00;
-ret = 2;
-break;
-case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
-if (value == USB_DEVICE_REMOTE_WAKEUP) {
-dev-remote_wakeup = 0;
-} else {
-goto fail;
-}
-ret = 0;
-break;
-case DeviceOutRequest | USB_REQ_SET_FEATURE:
-if (value == USB_DEVICE_REMOTE_WAKEUP) {
-dev-remote_wakeup = 1;
-} else {
-goto fail;
-}
-ret = 0;
-break;
 case DeviceRequest | USB_REQ_GET_INTERFACE:
 data[0] = 0;
 ret = 1;
diff --git a/hw/usb-hub.c b/hw/usb-hub.c
index d21dfc0..5a7bc44 100644
--- a/hw/usb-hub.c
+++ b/hw/usb-hub.c
@@ -269,34 +269,12 @@ static int usb_hub_handle_control(USBDevice *dev, int 
request, int value,
 }
 
 switch(request) {
-case DeviceRequest | USB_REQ_GET_STATUS:
-data[0] = (1  USB_DEVICE_SELF_POWERED) |
-(dev-remote_wakeup  USB_DEVICE_REMOTE_WAKEUP);
-data[1] = 0x00;
-ret = 2;
-break;
-case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
-if (value == USB_DEVICE_REMOTE_WAKEUP) {
-dev-remote_wakeup = 0;
-} else {
-goto fail;
-}
-ret = 0;
-break;
 case EndpointOutRequest | USB_REQ_CLEAR_FEATURE:
 if (value == 0  index != 0x81) { /* 

[Qemu-devel] [PATCH 22/30] usb: add speed mask to ports

2010-12-17 Thread Gerd Hoffmann
Add a field to usb ports indicating the speed(s) they are
able to handle.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb-bus.c  |3 ++-
 hw/usb-hub.c  |3 ++-
 hw/usb-musb.c |3 ++-
 hw/usb-ohci.c |3 ++-
 hw/usb-uhci.c |3 ++-
 hw/usb.h  |9 -
 6 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index f534bc3..9772e1e 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -111,11 +111,12 @@ USBDevice *usb_create_simple(USBBus *bus, const char 
*name)
 }
 
 void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index,
-   USBPortOps *ops)
+   USBPortOps *ops, int speedmask)
 {
 port-opaque = opaque;
 port-index = index;
 port-ops = ops;
+port-speedmask = speedmask;
 QTAILQ_INSERT_TAIL(bus-free, port, next);
 bus-nfree++;
 }
diff --git a/hw/usb-hub.c b/hw/usb-hub.c
index 9a073f8..e2cba38 100644
--- a/hw/usb-hub.c
+++ b/hw/usb-hub.c
@@ -526,7 +526,8 @@ static int usb_hub_initfn(USBDevice *dev)
 for (i = 0; i  NUM_PORTS; i++) {
 port = s-ports[i];
 usb_register_port(usb_bus_from_device(dev),
-  port-port, s, i, usb_hub_port_ops);
+  port-port, s, i, usb_hub_port_ops,
+  USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL);
 port-wPortStatus = PORT_STAT_POWER;
 port-wPortChange = 0;
 }
diff --git a/hw/usb-musb.c b/hw/usb-musb.c
index 983a4db..1705cbf 100644
--- a/hw/usb-musb.c
+++ b/hw/usb-musb.c
@@ -349,7 +349,8 @@ struct MUSBState {
 }
 
 usb_bus_new(s-bus, NULL /* FIXME */);
-usb_register_port(s-bus, s-port, s, 0, musb_port_ops);
+usb_register_port(s-bus, s-port, s, 0, musb_port_ops,
+  USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL);
 
 return s;
 }
diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c
index ed6b3e7..32f5f69 100644
--- a/hw/usb-ohci.c
+++ b/hw/usb-ohci.c
@@ -1705,7 +1705,8 @@ static void usb_ohci_init(OHCIState *ohci, DeviceState 
*dev,
 usb_bus_new(ohci-bus, dev);
 ohci-num_ports = num_ports;
 for (i = 0; i  num_ports; i++) {
-usb_register_port(ohci-bus, ohci-rhport[i].port, ohci, i, 
ohci_port_ops);
+usb_register_port(ohci-bus, ohci-rhport[i].port, ohci, i, 
ohci_port_ops,
+  USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL);
 }
 
 ohci-async_td = 0;
diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
index 60d5d57..802352a 100644
--- a/hw/usb-uhci.c
+++ b/hw/usb-uhci.c
@@ -1129,7 +1129,8 @@ static int usb_uhci_common_initfn(UHCIState *s)
 
 usb_bus_new(s-bus, s-dev.qdev);
 for(i = 0; i  NB_PORTS; i++) {
-usb_register_port(s-bus, s-ports[i].port, s, i, uhci_port_ops);
+usb_register_port(s-bus, s-ports[i].port, s, i, uhci_port_ops,
+  USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL);
 }
 s-frame_timer = qemu_new_timer(vm_clock, uhci_frame_timer, s);
 s-expire_time = qemu_get_clock(vm_clock) +
diff --git a/hw/usb.h b/hw/usb.h
index 9f454e6..864501a 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -44,6 +44,12 @@
 #define USB_SPEED_LOW   0
 #define USB_SPEED_FULL  1
 #define USB_SPEED_HIGH  2
+#define USB_SPEED_SUPER 3
+
+#define USB_SPEED_MASK_LOW   (1  USB_SPEED_LOW)
+#define USB_SPEED_MASK_FULL  (1  USB_SPEED_FULL)
+#define USB_SPEED_MASK_HIGH  (1  USB_SPEED_HIGH)
+#define USB_SPEED_MASK_SUPER (1  USB_SPEED_SUPER)
 
 #define USB_STATE_NOTATTACHED 0
 #define USB_STATE_ATTACHED1
@@ -226,6 +232,7 @@ typedef struct USBPortOps {
 /* USB port on which a device can be connected */
 struct USBPort {
 USBDevice *dev;
+int speedmask;
 USBPortOps *ops;
 void *opaque;
 int index; /* internal port index, may be used with the opaque */
@@ -338,7 +345,7 @@ USBDevice *usb_create(USBBus *bus, const char *name);
 USBDevice *usb_create_simple(USBBus *bus, const char *name);
 USBDevice *usbdevice_create(const char *cmdline);
 void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index,
-   USBPortOps *ops);
+   USBPortOps *ops, int speedmask);
 void usb_unregister_port(USBBus *bus, USBPort *port);
 int usb_device_attach(USBDevice *dev);
 int usb_device_detach(USBDevice *dev);
-- 
1.7.1




[Qemu-devel] [PATCH 21/30] usb: hid: change serial number to 42.

2010-12-17 Thread Gerd Hoffmann
It would be nice to have some way to signal our hid devices support
remote wakeup.  There is a descriptor bit for that of course.  Problem
with using is one is that older qemu versions used to set the bit even
though they did *not* support remote wakeup.  Bummer.

This patch changes the serial number of our hid devices from 1 to 42
to signal it is safe to enable remote wakeup.  The serial number was
choosen because it isn't used for anything and it is available in sysfs
so it is easy to match it using udev rules like this:

ACTION==add, SUBSYSTEM==usb, \
ATTR{product}==QEMU USB Tablet, ATTR{serial}==42, \
RUN+=usb_enable_autosuspend %p

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

diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index 60fa57f..1fec163 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -90,7 +90,7 @@ static const USBDescStrings desc_strings = {
 [STR_PRODUCT_MOUSE]= QEMU USB Mouse,
 [STR_PRODUCT_TABLET]   = QEMU USB Tablet,
 [STR_PRODUCT_KEYBOARD] = QEMU USB Keyboard,
-[STR_SERIALNUMBER] = 1,
+[STR_SERIALNUMBER] = 42, /* == remote wakeup works */
 [STR_CONFIG_MOUSE] = HID Mouse,
 [STR_CONFIG_TABLET]= HID Tablet,
 [STR_CONFIG_KEYBOARD]  = HID Keyboard,
-- 
1.7.1




[Qemu-devel] [PATCH 15/30] usb: create USBPortOps, move attach there.

2010-12-17 Thread Gerd Hoffmann
Create USBPortOps struct, move the attach function to that struct.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb-bus.c  |4 ++--
 hw/usb-hub.c  |6 +-
 hw/usb-musb.c |6 +-
 hw/usb-ohci.c |6 +-
 hw/usb-uhci.c |6 +-
 hw/usb.c  |2 +-
 hw/usb.h  |8 +---
 7 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index 15a42ff..f534bc3 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -111,11 +111,11 @@ USBDevice *usb_create_simple(USBBus *bus, const char 
*name)
 }
 
 void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index,
-   usb_attachfn attach)
+   USBPortOps *ops)
 {
 port-opaque = opaque;
 port-index = index;
-port-attach = attach;
+port-ops = ops;
 QTAILQ_INSERT_TAIL(bus-free, port, next);
 bus-nfree++;
 }
diff --git a/hw/usb-hub.c b/hw/usb-hub.c
index 5a7bc44..1de2e0f 100644
--- a/hw/usb-hub.c
+++ b/hw/usb-hub.c
@@ -506,6 +506,10 @@ static void usb_hub_handle_destroy(USBDevice *dev)
 }
 }
 
+static USBPortOps usb_hub_port_ops = {
+.attach = usb_hub_attach,
+};
+
 static int usb_hub_initfn(USBDevice *dev)
 {
 USBHubState *s = DO_UPCAST(USBHubState, dev, dev);
@@ -516,7 +520,7 @@ static int usb_hub_initfn(USBDevice *dev)
 for (i = 0; i  NUM_PORTS; i++) {
 port = s-ports[i];
 usb_register_port(usb_bus_from_device(dev),
-  port-port, s, i, usb_hub_attach);
+  port-port, s, i, usb_hub_port_ops);
 port-wPortStatus = PORT_STAT_POWER;
 port-wPortChange = 0;
 }
diff --git a/hw/usb-musb.c b/hw/usb-musb.c
index 7f15842..916aa06 100644
--- a/hw/usb-musb.c
+++ b/hw/usb-musb.c
@@ -261,6 +261,10 @@
 
 static void musb_attach(USBPort *port, USBDevice *dev);
 
+static USBPortOps musb_port_ops = {
+.attach = musb_attach,
+};
+
 typedef struct {
 uint16_t faddr[2];
 uint8_t haddr[2];
@@ -343,7 +347,7 @@ struct MUSBState {
 }
 
 usb_bus_new(s-bus, NULL /* FIXME */);
-usb_register_port(s-bus, s-port, s, 0, musb_attach);
+usb_register_port(s-bus, s-port, s, 0, musb_port_ops);
 
 return s;
 }
diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c
index 8fb2f83..3f71291 100644
--- a/hw/usb-ohci.c
+++ b/hw/usb-ohci.c
@@ -1676,6 +1676,10 @@ static CPUWriteMemoryFunc * const ohci_writefn[3]={
 ohci_mem_write
 };
 
+static USBPortOps ohci_port_ops = {
+.attach = ohci_attach,
+};
+
 static void usb_ohci_init(OHCIState *ohci, DeviceState *dev,
   int num_ports, uint32_t localmem_base)
 {
@@ -1705,7 +1709,7 @@ static void usb_ohci_init(OHCIState *ohci, DeviceState 
*dev,
 usb_bus_new(ohci-bus, dev);
 ohci-num_ports = num_ports;
 for (i = 0; i  num_ports; i++) {
-usb_register_port(ohci-bus, ohci-rhport[i].port, ohci, i, 
ohci_attach);
+usb_register_port(ohci-bus, ohci-rhport[i].port, ohci, i, 
ohci_port_ops);
 }
 
 ohci-async_td = 0;
diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
index 1d83400..1427c2f 100644
--- a/hw/usb-uhci.c
+++ b/hw/usb-uhci.c
@@ -1101,6 +1101,10 @@ static void uhci_map(PCIDevice *pci_dev, int region_num,
 register_ioport_read(addr, 32, 1, uhci_ioport_readb, s);
 }
 
+static USBPortOps uhci_port_ops = {
+.attach = uhci_attach,
+};
+
 static int usb_uhci_common_initfn(UHCIState *s)
 {
 uint8_t *pci_conf = s-dev.config;
@@ -1115,7 +1119,7 @@ static int usb_uhci_common_initfn(UHCIState *s)
 
 usb_bus_new(s-bus, s-dev.qdev);
 for(i = 0; i  NB_PORTS; i++) {
-usb_register_port(s-bus, s-ports[i].port, s, i, uhci_attach);
+usb_register_port(s-bus, s-ports[i].port, s, i, uhci_port_ops);
 }
 s-frame_timer = qemu_new_timer(vm_clock, uhci_frame_timer, s);
 s-expire_time = qemu_get_clock(vm_clock) +
diff --git a/hw/usb.c b/hw/usb.c
index a326bcf..39d29f3 100644
--- a/hw/usb.c
+++ b/hw/usb.c
@@ -28,7 +28,7 @@
 
 void usb_attach(USBPort *port, USBDevice *dev)
 {
-port-attach(port, dev);
+port-ops-attach(port, dev);
 }
 
 /**/
diff --git a/hw/usb.h b/hw/usb.h
index b8f13cc..e98808a 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -216,12 +216,14 @@ struct USBDeviceInfo {
 USBDevice *(*usbdevice_init)(const char *params);
 };
 
-typedef void (*usb_attachfn)(USBPort *port, USBDevice *dev);
+typedef struct USBPortOps {
+void (*attach)(USBPort *port, USBDevice *dev);
+} USBPortOps;
 
 /* USB port on which a device can be connected */
 struct USBPort {
 USBDevice *dev;
-usb_attachfn attach;
+USBPortOps *ops;
 void *opaque;
 int index; /* internal port index, may be used with the opaque */
 QTAILQ_ENTRY(USBPort) next;
@@ -332,7 +334,7 @@ USBDevice *usb_create(USBBus *bus, const char *name);
 USBDevice *usb_create_simple(USBBus *bus, const char *name);
 USBDevice *usbdevice_create(const char *cmdline);
 void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int 

[Qemu-devel] [PATCH 25/30] usb: add device qualifier support

2010-12-17 Thread Gerd Hoffmann
Add support for device_qualifier and other_speed_config descriptors.
These are used to query the other speed configuration of usb 2.0
devices, i.e. in high-speed mode they return the full-speed
configuration and visa versa.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb-desc.c |   46 ++
 hw/usb-desc.h |2 ++
 hw/usb.h  |2 ++
 trace-events  |2 ++
 4 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/hw/usb-desc.c b/hw/usb-desc.c
index f01e1cf..62591f2 100644
--- a/hw/usb-desc.c
+++ b/hw/usb-desc.c
@@ -48,6 +48,30 @@ int usb_desc_device(const USBDescID *id, const USBDescDevice 
*dev,
 return bLength;
 }
 
+int usb_desc_device_qualifier(const USBDescDevice *dev,
+  uint8_t *dest, size_t len)
+{
+uint8_t bLength = 0x0a;
+
+if (len  bLength) {
+return -1;
+}
+
+dest[0x00] = bLength;
+dest[0x01] = USB_DT_DEVICE_QUALIFIER;
+
+dest[0x02] = usb_lo(dev-bcdUSB);
+dest[0x03] = usb_hi(dev-bcdUSB);
+dest[0x04] = dev-bDeviceClass;
+dest[0x05] = dev-bDeviceSubClass;
+dest[0x06] = dev-bDeviceProtocol;
+dest[0x07] = dev-bMaxPacketSize0;
+dest[0x08] = dev-bNumConfigurations;
+dest[0x09] = 0; /* reserved */
+
+return bLength;
+}
+
 int usb_desc_config(const USBDescConfig *conf, uint8_t *dest, size_t len)
 {
 uint8_t  bLength = 0x09;
@@ -263,11 +287,18 @@ int usb_desc_string(USBDevice *dev, int index, uint8_t 
*dest, size_t len)
 int usb_desc_get_descriptor(USBDevice *dev, int value, uint8_t *dest, size_t 
len)
 {
 const USBDesc *desc = dev-info-usb_desc;
+const USBDescDevice *other_dev;
 uint8_t buf[256];
 uint8_t type = value  8;
 uint8_t index = value  0xff;
 int ret = -1;
 
+if (dev-speed == USB_SPEED_HIGH) {
+other_dev = dev-info-usb_desc-full;
+} else {
+other_dev = dev-info-usb_desc-high;
+}
+
 switch(type) {
 case USB_DT_DEVICE:
 ret = usb_desc_device(desc-id, dev-device, buf, sizeof(buf));
@@ -283,6 +314,21 @@ int usb_desc_get_descriptor(USBDevice *dev, int value, 
uint8_t *dest, size_t len
 ret = usb_desc_string(dev, index, buf, sizeof(buf));
 trace_usb_desc_string(dev-addr, index, len, ret);
 break;
+
+case USB_DT_DEVICE_QUALIFIER:
+if (other_dev != NULL) {
+ret = usb_desc_device_qualifier(other_dev, buf, sizeof(buf));
+}
+trace_usb_desc_device_qualifier(dev-addr, len, ret);
+break;
+case USB_DT_OTHER_SPEED_CONFIG:
+if (other_dev != NULL  index  other_dev-bNumConfigurations) {
+ret = usb_desc_config(other_dev-confs + index, buf, sizeof(buf));
+buf[0x01] = USB_DT_OTHER_SPEED_CONFIG;
+}
+trace_usb_desc_other_speed_config(dev-addr, index, len, ret);
+break;
+
 default:
 fprintf(stderr, %s: %d unknown type %d (len %zd)\n, __FUNCTION__,
 dev-addr, type, len);
diff --git a/hw/usb-desc.h b/hw/usb-desc.h
index 484c7c7..ac734ab 100644
--- a/hw/usb-desc.h
+++ b/hw/usb-desc.h
@@ -72,6 +72,8 @@ struct USBDesc {
 /* generate usb packages from structs */
 int usb_desc_device(const USBDescID *id, const USBDescDevice *dev,
 uint8_t *dest, size_t len);
+int usb_desc_device_qualifier(const USBDescDevice *dev,
+  uint8_t *dest, size_t len);
 int usb_desc_config(const USBDescConfig *conf, uint8_t *dest, size_t len);
 int usb_desc_iface(const USBDescIface *iface, uint8_t *dest, size_t len);
 int usb_desc_endpoint(const USBDescEndpoint *ep, uint8_t *dest, size_t len);
diff --git a/hw/usb.h b/hw/usb.h
index 0219816..15d2438 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -122,6 +122,8 @@
 #define USB_DT_STRING  0x03
 #define USB_DT_INTERFACE   0x04
 #define USB_DT_ENDPOINT0x05
+#define USB_DT_DEVICE_QUALIFIER 0x06
+#define USB_DT_OTHER_SPEED_CONFIG   0x07
 
 #define USB_ENDPOINT_XFER_CONTROL  0
 #define USB_ENDPOINT_XFER_ISOC 1
diff --git a/trace-events b/trace-events
index 8bece3c..c96a77e 100644
--- a/trace-events
+++ b/trace-events
@@ -192,7 +192,9 @@ disable sun4m_iommu_bad_addr(uint64_t addr) bad addr 
%PRIx64
 
 # hw/usb-desc.c
 disable usb_desc_device(int addr, int len, int ret) dev %d query device, len 
%d, ret %d
+disable usb_desc_device_qualifier(int addr, int len, int ret) dev %d query 
device qualifier, len %d, ret %d
 disable usb_desc_config(int addr, int index, int len, int ret) dev %d query 
config %d, len %d, ret %d
+disable usb_desc_other_speed_config(int addr, int index, int len, int ret) 
dev %d query config %d, len %d, ret %d
 disable usb_desc_string(int addr, int index, int len, int ret) dev %d query 
string %d, len %d, ret %d
 disable usb_set_addr(int addr) dev %d
 disable usb_set_config(int addr, int config, int ret) dev %d, config %d, ret 
%d
-- 
1.7.1




[Qemu-devel] [PATCH v6 4/4] docs: Document virtio PCI -device ioeventfd=on|off

2010-12-17 Thread Stefan Hajnoczi
Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 docs/qdev-device-use.txt |8 +++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/docs/qdev-device-use.txt b/docs/qdev-device-use.txt
index f252c8e..f2f9b75 100644
--- a/docs/qdev-device-use.txt
+++ b/docs/qdev-device-use.txt
@@ -97,10 +97,13 @@ The -device argument differs in detail for each kind of 
drive:
 
 * if=virtio
 
-  -device virtio-blk-pci,drive=DRIVE-ID,class=C,vectors=V
+  -device virtio-blk-pci,drive=DRIVE-ID,class=C,vectors=V,ioeventfd=IOEVENTFD
 
   This lets you control PCI device class and MSI-X vectors.
 
+  IOEVENTFD controls whether or not ioeventfd is used for virtqueue notify.  It
+  can be set to on (default) or off.
+
   As for all PCI devices, you can add bus=PCI-BUS,addr=DEVFN to
   control the PCI device address.
 
@@ -240,6 +243,9 @@ For PCI devices, you can add bus=PCI-BUS,addr=DEVFN to 
control the PCI
 device address, as usual.  The old -net nic provides parameter addr
 for that, it is silently ignored when the NIC is not a PCI device.
 
+For virtio-net-pci, you can control whether or not ioeventfd is used for
+virtqueue notify by setting ioeventfd= to on or off (default).
+
 -net nic accepts vectors=V for all models, but it's silently ignored
 except for virtio-net-pci (model=virtio).  With -device, only devices
 that support it accept it.
-- 
1.7.2.3




[Qemu-devel] [PATCH 20/30] usb: hid: remote wakeup support.

2010-12-17 Thread Gerd Hoffmann
Add usb_wakeup() call to the hid driver so remote wakeup actually works.

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

diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index 1c35960..60fa57f 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -429,6 +429,8 @@ static void usb_hid_changed(USBHIDState *hs)
 
 if (hs-datain)
 hs-datain(hs-datain_opaque);
+
+usb_wakeup(hs-dev);
 }
 
 static void usb_mouse_event(void *opaque,
-- 
1.7.1




[Qemu-devel] [PATCH 18/30] usb: uhci: remote wakeup support.

2010-12-17 Thread Gerd Hoffmann
Add support for remote wakeup to the UHCI adapter.

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

diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
index debf7f7..60d5d57 100644
--- a/hw/usb-uhci.c
+++ b/hw/usb-uhci.c
@@ -57,13 +57,18 @@
 #define TD_CTRL_NAK (1  19)
 #define TD_CTRL_TIMEOUT (1  18)
 
+#define UHCI_PORT_SUSPEND (1  12)
 #define UHCI_PORT_RESET (1  9)
 #define UHCI_PORT_LSDA  (1  8)
+#define UHCI_PORT_RD(1  6)
 #define UHCI_PORT_ENC   (1  3)
 #define UHCI_PORT_EN(1  2)
 #define UHCI_PORT_CSC   (1  1)
 #define UHCI_PORT_CCS   (1  0)
 
+#define UHCI_PORT_READ_ONLY(0x1bb)
+#define UHCI_PORT_WRITE_CLEAR  (UHCI_PORT_CSC | UHCI_PORT_ENC)
+
 #define FRAME_TIMER_FREQ 1000
 
 #define FRAME_MAX_LOOPS  100
@@ -497,9 +502,10 @@ static void uhci_ioport_writew(void *opaque, uint32_t 
addr, uint32_t val)
 usb_send_msg(dev, USB_MSG_RESET);
 }
 }
-port-ctrl = (port-ctrl  0x01fb) | (val  ~0x01fb);
+port-ctrl = UHCI_PORT_READ_ONLY;
+port-ctrl |= (val  ~UHCI_PORT_READ_ONLY);
 /* some bits are reset when a '1' is written to them */
-port-ctrl = ~(val  0x000a);
+port-ctrl = ~(val  UHCI_PORT_WRITE_CLEAR);
 }
 break;
 }
@@ -629,6 +635,18 @@ static void uhci_detach(USBPort *port1)
 uhci_resume(s);
 }
 
+static void uhci_wakeup(USBDevice *dev)
+{
+USBBus *bus = usb_bus_from_device(dev);
+UHCIState *s = container_of(bus, UHCIState, bus);
+UHCIPort *port = s-ports + dev-port-index;
+
+if (port-ctrl  UHCI_PORT_SUSPEND  !(port-ctrl  UHCI_PORT_RD)) {
+port-ctrl |= UHCI_PORT_RD;
+uhci_resume(s);
+}
+}
+
 static int uhci_broadcast_packet(UHCIState *s, USBPacket *p)
 {
 int i, ret;
@@ -1094,6 +1112,7 @@ static void uhci_map(PCIDevice *pci_dev, int region_num,
 static USBPortOps uhci_port_ops = {
 .attach = uhci_attach,
 .detach = uhci_detach,
+.wakeup = uhci_wakeup,
 };
 
 static int usb_uhci_common_initfn(UHCIState *s)
-- 
1.7.1




[Qemu-devel] [PATCH 26/30] usb storage: high speed support

2010-12-17 Thread Gerd Hoffmann
Add high speed support to the usb mass storage device.  With this patch
applied the linux kernel recognises the usb storage device as highspeed
capable device and suggests to connect it to a highspeed port instead of
the uhci.  Tested with both uhci and (not-yet submitted) ehci.

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

diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index 74e657e..7b8189f 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -77,15 +77,19 @@ enum {
 STR_MANUFACTURER = 1,
 STR_PRODUCT,
 STR_SERIALNUMBER,
+STR_CONFIG_FULL,
+STR_CONFIG_HIGH,
 };
 
 static const USBDescStrings desc_strings = {
 [STR_MANUFACTURER] = QEMU  QEMU_VERSION,
 [STR_PRODUCT]  = QEMU USB HARDDRIVE,
 [STR_SERIALNUMBER] = 1,
+[STR_CONFIG_FULL]  = Full speed config (usb 1.1),
+[STR_CONFIG_HIGH]  = High speed config (usb 2.0),
 };
 
-static const USBDescIface desc_iface0 = {
+static const USBDescIface desc_iface_full = {
 .bInterfaceNumber  = 0,
 .bNumEndpoints = 2,
 .bInterfaceClass   = USB_CLASS_MASS_STORAGE,
@@ -104,16 +108,51 @@ static const USBDescIface desc_iface0 = {
 }
 };
 
-static const USBDescDevice desc_device = {
-.bcdUSB= 0x0100,
+static const USBDescDevice desc_device_full = {
+.bcdUSB= 0x0200,
 .bMaxPacketSize0   = 8,
 .bNumConfigurations= 1,
 .confs = (USBDescConfig[]) {
 {
 .bNumInterfaces= 1,
 .bConfigurationValue   = 1,
+.iConfiguration= STR_CONFIG_FULL,
 .bmAttributes  = 0xc0,
-.ifs = desc_iface0,
+.ifs = desc_iface_full,
+},
+},
+};
+
+static const USBDescIface desc_iface_high = {
+.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= 512,
+},{
+.bEndpointAddress  = USB_DIR_OUT | 0x02,
+.bmAttributes  = USB_ENDPOINT_XFER_BULK,
+.wMaxPacketSize= 512,
+},
+}
+};
+
+static const USBDescDevice desc_device_high = {
+.bcdUSB= 0x0200,
+.bMaxPacketSize0   = 64,
+.bNumConfigurations= 1,
+.confs = (USBDescConfig[]) {
+{
+.bNumInterfaces= 1,
+.bConfigurationValue   = 1,
+.iConfiguration= STR_CONFIG_HIGH,
+.bmAttributes  = 0xc0,
+.ifs = desc_iface_high,
 },
 },
 };
@@ -127,7 +166,8 @@ static const USBDesc desc = {
 .iProduct  = STR_PRODUCT,
 .iSerialNumber = STR_SERIALNUMBER,
 },
-.full = desc_device,
+.full = desc_device_full,
+.high = desc_device_high,
 .str  = desc_strings,
 };
 
@@ -558,6 +598,7 @@ static struct USBDeviceInfo msd_info = {
 .usb_desc   = desc,
 .init   = usb_msd_initfn,
 .handle_packet  = usb_generic_handle_packet,
+.handle_attach  = usb_desc_attach,
 .handle_reset   = usb_msd_handle_reset,
 .handle_control = usb_msd_handle_control,
 .handle_data= usb_msd_handle_data,
-- 
1.7.1




[Qemu-devel] [PATCH 16/30] usb: rework attach/detach workflow

2010-12-17 Thread Gerd Hoffmann
Add separate detach callback to USBPortOps, split
uhci/ohci/musb/usbhub attach functions into two.

Move common code to the usb_attach() function, only
the hardware-specific bits remain in the attach/detach
callbacks.

Keep track of the port it is attached to for each usb device.

[ v3: fix tyops in usb-musb.c ]

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb-hub.c  |   46 ++--
 hw/usb-musb.c |   36 -
 hw/usb-ohci.c |   80 +++--
 hw/usb-uhci.c |   69 +---
 hw/usb.c  |   20 +-
 hw/usb.h  |4 ++-
 6 files changed, 122 insertions(+), 133 deletions(-)

diff --git a/hw/usb-hub.c b/hw/usb-hub.c
index 1de2e0f..5aa1d0b 100644
--- a/hw/usb-hub.c
+++ b/hw/usb-hub.c
@@ -218,37 +218,30 @@ static const uint8_t qemu_hub_hub_descriptor[] =
 /* DeviceRemovable and PortPwrCtrlMask patched in later */
 };
 
-static void usb_hub_attach(USBPort *port1, USBDevice *dev)
+static void usb_hub_attach(USBPort *port1)
 {
 USBHubState *s = port1-opaque;
 USBHubPort *port = s-ports[port1-index];
 
-if (dev) {
-if (port-port.dev)
-usb_attach(port1, NULL);
-
-port-wPortStatus |= PORT_STAT_CONNECTION;
-port-wPortChange |= PORT_STAT_C_CONNECTION;
-if (dev-speed == USB_SPEED_LOW)
-port-wPortStatus |= PORT_STAT_LOW_SPEED;
-else
-port-wPortStatus = ~PORT_STAT_LOW_SPEED;
-port-port.dev = dev;
-/* send the attach message */
-usb_send_msg(dev, USB_MSG_ATTACH);
+port-wPortStatus |= PORT_STAT_CONNECTION;
+port-wPortChange |= PORT_STAT_C_CONNECTION;
+if (port-port.dev-speed == USB_SPEED_LOW) {
+port-wPortStatus |= PORT_STAT_LOW_SPEED;
 } else {
-dev = port-port.dev;
-if (dev) {
-port-wPortStatus = ~PORT_STAT_CONNECTION;
-port-wPortChange |= PORT_STAT_C_CONNECTION;
-if (port-wPortStatus  PORT_STAT_ENABLE) {
-port-wPortStatus = ~PORT_STAT_ENABLE;
-port-wPortChange |= PORT_STAT_C_ENABLE;
-}
-/* send the detach message */
-usb_send_msg(dev, USB_MSG_DETACH);
-port-port.dev = NULL;
-}
+port-wPortStatus = ~PORT_STAT_LOW_SPEED;
+}
+}
+
+static void usb_hub_detach(USBPort *port1)
+{
+USBHubState *s = port1-opaque;
+USBHubPort *port = s-ports[port1-index];
+
+port-wPortStatus = ~PORT_STAT_CONNECTION;
+port-wPortChange |= PORT_STAT_C_CONNECTION;
+if (port-wPortStatus  PORT_STAT_ENABLE) {
+port-wPortStatus = ~PORT_STAT_ENABLE;
+port-wPortChange |= PORT_STAT_C_ENABLE;
 }
 }
 
@@ -508,6 +501,7 @@ static void usb_hub_handle_destroy(USBDevice *dev)
 
 static USBPortOps usb_hub_port_ops = {
 .attach = usb_hub_attach,
+.detach = usb_hub_detach,
 };
 
 static int usb_hub_initfn(USBDevice *dev)
diff --git a/hw/usb-musb.c b/hw/usb-musb.c
index 916aa06..983a4db 100644
--- a/hw/usb-musb.c
+++ b/hw/usb-musb.c
@@ -259,10 +259,12 @@
 #endif
 
 
-static void musb_attach(USBPort *port, USBDevice *dev);
+static void musb_attach(USBPort *port);
+static void musb_detach(USBPort *port);
 
 static USBPortOps musb_port_ops = {
 .attach = musb_attach,
+.detach = musb_detach,
 };
 
 typedef struct {
@@ -464,34 +466,20 @@ static void musb_session_update(MUSBState *s, int 
prev_dev, int prev_sess)
 }
 
 /* Attach or detach a device on our only port.  */
-static void musb_attach(USBPort *port, USBDevice *dev)
+static void musb_attach(USBPort *port)
 {
 MUSBState *s = (MUSBState *) port-opaque;
-USBDevice *curr;
 
-port = s-port;
-curr = port-dev;
-
-if (dev) {
-if (curr) {
-usb_attach(port, NULL);
-/* TODO: signal some interrupts */
-}
-
-musb_intr_set(s, musb_irq_vbus_request, 1);
-
-/* Send the attach message to device */
-usb_send_msg(dev, USB_MSG_ATTACH);
-} else if (curr) {
-/* Send the detach message */
-usb_send_msg(curr, USB_MSG_DETACH);
-
-musb_intr_set(s, musb_irq_disconnect, 1);
-}
+musb_intr_set(s, musb_irq_vbus_request, 1);
+musb_session_update(s, 0, s-session);
+}
 
-port-dev = dev;
+static void musb_detach(USBPort *port)
+{
+MUSBState *s = (MUSBState *) port-opaque;
 
-musb_session_update(s, !!curr, s-session);
+musb_intr_set(s, musb_irq_disconnect, 1);
+musb_session_update(s, 1, s-session);
 }
 
 static inline void musb_cb_tick0(void *opaque)
diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c
index 3f71291..ed6b3e7 100644
--- a/hw/usb-ohci.c
+++ b/hw/usb-ohci.c
@@ -322,52 +322,46 @@ static inline void ohci_set_interrupt(OHCIState *ohci, 
uint32_t intr)
 }
 
 /* Attach or detach a device on a root hub port.  */
-static void ohci_attach(USBPort *port1, USBDevice *dev)
+static void ohci_attach(USBPort *port1)
 {
  

[Qemu-devel] [PATCH 23/30] usb: add attach callback

2010-12-17 Thread Gerd Hoffmann
Add handle_attach() callback to USBDeviceInfo which is called by the
generic package handler when the device is attached to the usb bus
(i.e. plugged into a port).

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

diff --git a/hw/usb.c b/hw/usb.c
index ba720b4..82a6217 100644
--- a/hw/usb.c
+++ b/hw/usb.c
@@ -194,6 +194,9 @@ int usb_generic_handle_packet(USBDevice *s, USBPacket *p)
 switch(p-pid) {
 case USB_MSG_ATTACH:
 s-state = USB_STATE_ATTACHED;
+if (s-info-handle_attach) {
+s-info-handle_attach(s);
+}
 return 0;
 
 case USB_MSG_DETACH:
@@ -204,7 +207,9 @@ int usb_generic_handle_packet(USBDevice *s, USBPacket *p)
 s-remote_wakeup = 0;
 s-addr = 0;
 s-state = USB_STATE_DEFAULT;
-s-info-handle_reset(s);
+if (s-info-handle_reset) {
+s-info-handle_reset(s);
+}
 return 0;
 }
 
diff --git a/hw/usb.h b/hw/usb.h
index 864501a..0219816 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -194,6 +194,11 @@ struct USBDeviceInfo {
 void (*handle_destroy)(USBDevice *dev);
 
 /*
+ * Attach the device
+ */
+void (*handle_attach)(USBDevice *dev);
+
+/*
  * Reset the device
  */
 void (*handle_reset)(USBDevice *dev);
-- 
1.7.1




[Qemu-devel] [PATCH v6 1/4] virtio-pci: Rename bugs field to flags

2010-12-17 Thread Stefan Hajnoczi
The VirtIOPCIProxy bugs field is currently used to enable workarounds
for older guests.  Rename it to flags so that other per-device behavior
can be tracked.

A later patch uses the flags field to remember whether ioeventfd should
be used for virtqueue host notification.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 hw/virtio-pci.c |   15 +++
 1 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 6186142..13dd391 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -80,9 +80,8 @@
  * 12 is historical, and due to x86 page size. */
 #define VIRTIO_PCI_QUEUE_ADDR_SHIFT12
 
-/* We can catch some guest bugs inside here so we continue supporting older
-   guests. */
-#define VIRTIO_PCI_BUG_BUS_MASTER  (1  0)
+/* Flags track per-device state like workarounds for quirks in older guests. */
+#define VIRTIO_PCI_FLAG_BUS_MASTER_BUG  (1  0)
 
 /* QEMU doesn't strictly need write barriers since everything runs in
  * lock-step.  We'll leave the calls to wmb() in though to make it obvious for
@@ -95,7 +94,7 @@
 typedef struct {
 PCIDevice pci_dev;
 VirtIODevice *vdev;
-uint32_t bugs;
+uint32_t flags;
 uint32_t addr;
 uint32_t class_code;
 uint32_t nvectors;
@@ -159,7 +158,7 @@ static int virtio_pci_load_config(void * opaque, QEMUFile 
*f)
in ready state. Then we have a buggy guest OS. */
 if ((proxy-vdev-status  VIRTIO_CONFIG_S_DRIVER_OK) 
 !(proxy-pci_dev.config[PCI_COMMAND]  PCI_COMMAND_MASTER)) {
-proxy-bugs |= VIRTIO_PCI_BUG_BUS_MASTER;
+proxy-flags |= VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
 }
 return 0;
 }
@@ -185,7 +184,7 @@ static void virtio_pci_reset(DeviceState *d)
 VirtIOPCIProxy *proxy = container_of(d, VirtIOPCIProxy, pci_dev.qdev);
 virtio_reset(proxy-vdev);
 msix_reset(proxy-pci_dev);
-proxy-bugs = 0;
+proxy-flags = 0;
 }
 
 static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
@@ -235,7 +234,7 @@ static void virtio_ioport_write(void *opaque, uint32_t 
addr, uint32_t val)
some safety checks. */
 if ((val  VIRTIO_CONFIG_S_DRIVER_OK) 
 !(proxy-pci_dev.config[PCI_COMMAND]  PCI_COMMAND_MASTER)) {
-proxy-bugs |= VIRTIO_PCI_BUG_BUS_MASTER;
+proxy-flags |= VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
 }
 break;
 case VIRTIO_MSI_CONFIG_VECTOR:
@@ -403,7 +402,7 @@ static void virtio_write_config(PCIDevice *pci_dev, 
uint32_t address,
 
 if (PCI_COMMAND == address) {
 if (!(val  PCI_COMMAND_MASTER)) {
-if (!(proxy-bugs  VIRTIO_PCI_BUG_BUS_MASTER)) {
+if (!(proxy-flags  VIRTIO_PCI_FLAG_BUS_MASTER_BUG)) {
 virtio_set_status(proxy-vdev,
   proxy-vdev-status  
~VIRTIO_CONFIG_S_DRIVER_OK);
 }
-- 
1.7.2.3




[Qemu-devel] [PATCH 29/30] usb: keep track of physical port address.

2010-12-17 Thread Gerd Hoffmann
Add a path string to USBPort.  Add usb_port_location() function to set
the physical location of the usb port.  Update all drivers implementing
usb ports to call it.  Update the monitor commands to print it.  Wind it
up in qdev.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb-bus.c  |   25 ++---
 hw/usb-hub.c  |   11 +++
 hw/usb-musb.c |1 +
 hw/usb-ohci.c |1 +
 hw/usb-uhci.c |1 +
 hw/usb.h  |2 ++
 6 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index 9772e1e..cfed593 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -5,11 +5,13 @@
 #include monitor.h
 
 static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent);
+static char *usb_get_dev_path(DeviceState *dev);
 
 static struct BusInfo usb_bus_info = {
 .name  = USB,
 .size  = sizeof(USBBus),
 .print_dev = usb_bus_dev_print,
+.get_dev_path = usb_get_dev_path,
 };
 static int next_usb_bus = 0;
 static QTAILQ_HEAD(, USBBus) busses = QTAILQ_HEAD_INITIALIZER(busses);
@@ -121,6 +123,16 @@ void usb_register_port(USBBus *bus, USBPort *port, void 
*opaque, int index,
 bus-nfree++;
 }
 
+void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr)
+{
+if (upstream) {
+snprintf(downstream-path, sizeof(downstream-path), %s.%d,
+ upstream-path, portnr);
+} else {
+snprintf(downstream-path, sizeof(downstream-path), %d, portnr);
+}
+}
+
 void usb_unregister_port(USBBus *bus, USBPort *port)
 {
 if (port-dev)
@@ -230,12 +242,19 @@ static void usb_bus_dev_print(Monitor *mon, DeviceState 
*qdev, int indent)
 USBDevice *dev = DO_UPCAST(USBDevice, qdev, qdev);
 USBBus *bus = usb_bus_from_device(dev);
 
-monitor_printf(mon, %*saddr %d.%d, speed %s, name %s%s\n,
+monitor_printf(mon, %*saddr %d.%d, port %s, speed %s, name %s%s\n,
indent, , bus-busnr, dev-addr,
+   dev-port ? dev-port-path : -,
usb_speed(dev-speed), dev-product_desc,
dev-attached ? , attached : );
 }
 
+static char *usb_get_dev_path(DeviceState *qdev)
+{
+USBDevice *dev = DO_UPCAST(USBDevice, qdev, qdev);
+return qemu_strdup(dev-port-path);
+}
+
 void usb_info(Monitor *mon)
 {
 USBBus *bus;
@@ -252,8 +271,8 @@ void usb_info(Monitor *mon)
 dev = port-dev;
 if (!dev)
 continue;
-monitor_printf(mon,   Device %d.%d, Speed %s Mb/s, Product %s\n,
-   bus-busnr, dev-addr, usb_speed(dev-speed),
+monitor_printf(mon,   Device %d.%d, Port %s, Speed %s Mb/s, 
Product %s\n,
+   bus-busnr, dev-addr, port-path, 
usb_speed(dev-speed),
dev-product_desc);
 }
 }
diff --git a/hw/usb-hub.c b/hw/usb-hub.c
index e2cba38..d68f841 100644
--- a/hw/usb-hub.c
+++ b/hw/usb-hub.c
@@ -256,6 +256,16 @@ static void usb_hub_wakeup(USBDevice *dev)
 }
 }
 
+static void usb_hub_handle_attach(USBDevice *dev)
+{
+USBHubState *s = DO_UPCAST(USBHubState, dev, dev);
+int i;
+
+for (i = 0; i  NUM_PORTS; i++) {
+usb_port_location(s-ports[i].port, dev-port, i+1);
+}
+}
+
 static void usb_hub_handle_reset(USBDevice *dev)
 {
 /* XXX: do it */
@@ -541,6 +551,7 @@ static struct USBDeviceInfo hub_info = {
 .usb_desc   = desc_hub,
 .init   = usb_hub_initfn,
 .handle_packet  = usb_hub_handle_packet,
+.handle_attach  = usb_hub_handle_attach,
 .handle_reset   = usb_hub_handle_reset,
 .handle_control = usb_hub_handle_control,
 .handle_data= usb_hub_handle_data,
diff --git a/hw/usb-musb.c b/hw/usb-musb.c
index 1705cbf..782cfa2 100644
--- a/hw/usb-musb.c
+++ b/hw/usb-musb.c
@@ -351,6 +351,7 @@ struct MUSBState {
 usb_bus_new(s-bus, NULL /* FIXME */);
 usb_register_port(s-bus, s-port, s, 0, musb_port_ops,
   USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL);
+usb_port_location(s-port, NULL, 1);
 
 return s;
 }
diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c
index 32f5f69..771c7cf 100644
--- a/hw/usb-ohci.c
+++ b/hw/usb-ohci.c
@@ -1707,6 +1707,7 @@ static void usb_ohci_init(OHCIState *ohci, DeviceState 
*dev,
 for (i = 0; i  num_ports; i++) {
 usb_register_port(ohci-bus, ohci-rhport[i].port, ohci, i, 
ohci_port_ops,
   USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL);
+usb_port_location(ohci-rhport[i].port, NULL, i+1);
 }
 
 ohci-async_td = 0;
diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
index 802352a..b384e1d 100644
--- a/hw/usb-uhci.c
+++ b/hw/usb-uhci.c
@@ -1131,6 +1131,7 @@ static int usb_uhci_common_initfn(UHCIState *s)
 for(i = 0; i  NB_PORTS; i++) {
 usb_register_port(s-bus, s-ports[i].port, s, i, uhci_port_ops,
   USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL);
+usb_port_location(s-ports[i].port, NULL, i+1);
 }
 

[Qemu-devel] [PATCH 30/30] usb: add port property.

2010-12-17 Thread Gerd Hoffmann
This allows to explictily set the physical port where you want to
plug the usb device.  Example:

  -device usb-tablet,bus=usb.0,port=2

With explicit port addressing qemu can and will not automagically add
USB Hubs.  This means that:

  (a) You can plug two devices of your choice into the two uhci
  root ports.
  (b) If you want plug in more that two devices you have to care
  about adding a hub yourself.

Plugging a hub works this way:

  -device usb-hub,bus=usb.0,port=1

Use this to add a device to the hub:

  -device usb-tablet,bus=usb.0,port=1.1

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

diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index cfed593..b0ddf04 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -12,6 +12,10 @@ static struct BusInfo usb_bus_info = {
 .size  = sizeof(USBBus),
 .print_dev = usb_bus_dev_print,
 .get_dev_path = usb_get_dev_path,
+.props  = (Property[]) {
+DEFINE_PROP_STRING(port, USBDevice, port_path),
+DEFINE_PROP_END_OF_LIST()
+},
 };
 static int next_usb_bus = 0;
 static QTAILQ_HEAD(, USBBus) busses = QTAILQ_HEAD_INITIALIZER(busses);
@@ -151,9 +155,22 @@ static void do_attach(USBDevice *dev)
 dev-product_desc);
 return;
 }
-dev-attached++;
+if (dev-port_path) {
+QTAILQ_FOREACH(port, bus-free, next) {
+if (strcmp(port-path, dev-port_path) == 0) {
+break;
+}
+}
+if (port == NULL) {
+fprintf(stderr, Warning: usb port %s (bus %s) not found\n,
+dev-port_path, bus-qbus.name);
+return;
+}
+} else {
+port = QTAILQ_FIRST(bus-free);
+}
 
-port = QTAILQ_FIRST(bus-free);
+dev-attached++;
 QTAILQ_REMOVE(bus-free, port, next);
 bus-nfree--;
 
@@ -167,8 +184,9 @@ int usb_device_attach(USBDevice *dev)
 {
 USBBus *bus = usb_bus_from_device(dev);
 
-if (bus-nfree == 1) {
-/* Create a new hub and chain it on.  */
+if (bus-nfree == 1  dev-port_path == NULL) {
+/* Create a new hub and chain it on
+   (unless a physical port location is specified). */
 usb_create_simple(bus, usb-hub);
 }
 do_attach(dev);
diff --git a/hw/usb.h b/hw/usb.h
index 08bcd1c..5c1da3e 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -156,6 +156,7 @@ struct USBDevice {
 DeviceState qdev;
 USBDeviceInfo *info;
 USBPort *port;
+char *port_path;
 void *opaque;
 
 int speed;
-- 
1.7.1




[Qemu-devel] [PATCH v6 0/4] virtio: Use ioeventfd for virtqueue notify

2010-12-17 Thread Stefan Hajnoczi
See below for the v6 changelog.

Virtqueue notify is currently handled synchronously in userspace virtio.  This
prevents the vcpu from executing guest code while hardware emulation code
handles the notify.

On systems that support KVM, the ioeventfd mechanism can be used to make
virtqueue notify a lightweight exit by deferring hardware emulation to the
iothread and allowing the VM to continue execution.  This model is similar to
how vhost receives virtqueue notifies.

The result of this change is improved performance for userspace virtio devices.
Virtio-blk throughput increases especially for multithreaded scenarios and
virtio-net transmit throughput increases substantially.

Now that this code is in virtio-pci.c it is possible to explicitly enable
devices for which virtio-ioeventfd should be used.  Only virtio-blk and
virtio-net are enabled at this time.

v6:
 * Default to ioeventfd=off for virtio-net

v5:
 * Fix spurious whitespace change in documentation
 * Test and clear event notifier when deassigning to catch race condition

v4:
 * Simpler start/stop ioeventfd mechanism using bool ioeventfd_started state
 * Support for migration
 * Handle deassign race condition to avoid dropping a virtqueue kick
 * Add missing kvm_enabled() check to kvm_has_many_ioeventfds()
 * Documentation updates for qdev -device with ioeventfd=on|off




[Qemu-devel] [PATCH v6 2/4] virtio-pci: Use ioeventfd for virtqueue notify

2010-12-17 Thread Stefan Hajnoczi
Virtqueue notify is currently handled synchronously in userspace virtio.  This
prevents the vcpu from executing guest code while hardware emulation code
handles the notify.

On systems that support KVM, the ioeventfd mechanism can be used to make
virtqueue notify a lightweight exit by deferring hardware emulation to the
iothread and allowing the VM to continue execution.  This model is similar to
how vhost receives virtqueue notifies.

The result of this change is improved performance for userspace virtio devices.
Virtio-blk throughput increases especially for multithreaded scenarios and
virtio-net transmit throughput increases substantially.

Some virtio devices are known to have guest drivers which expect a notify to be
processed synchronously and spin waiting for completion.  Only enable ioeventfd
for virtio-blk and virtio-net for now.

Care must be taken not to interfere with vhost-net, which uses host
notifiers.  If the set_host_notifier() API is used by a device
virtio-pci will disable virtio-ioeventfd and let the device deal with
host notifiers as it wishes.

After migration and on VM change state (running/paused) virtio-ioeventfd
will enable/disable itself.

 * VIRTIO_CONFIG_S_DRIVER_OK - enable virtio-ioeventfd
 * !VIRTIO_CONFIG_S_DRIVER_OK - disable virtio-ioeventfd
 * virtio_pci_set_host_notifier() - disable virtio-ioeventfd
 * vm_change_state(running=0) - disable virtio-ioeventfd
 * vm_change_state(running=1) - enable virtio-ioeventfd

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 hw/virtio-pci.c |  190 ---
 hw/virtio.c |   14 +++-
 hw/virtio.h |1 +
 3 files changed, 179 insertions(+), 26 deletions(-)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 13dd391..6b12248 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -83,6 +83,11 @@
 /* Flags track per-device state like workarounds for quirks in older guests. */
 #define VIRTIO_PCI_FLAG_BUS_MASTER_BUG  (1  0)
 
+/* Performance improves when virtqueue kick processing is decoupled from the
+ * vcpu thread using ioeventfd for some devices. */
+#define VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT 1
+#define VIRTIO_PCI_FLAG_USE_IOEVENTFD   (1  
VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
+
 /* QEMU doesn't strictly need write barriers since everything runs in
  * lock-step.  We'll leave the calls to wmb() in though to make it obvious for
  * KVM or if kqemu gets SMP support.
@@ -107,6 +112,8 @@ typedef struct {
 /* Max. number of ports we can have for a the virtio-serial device */
 uint32_t max_virtserial_ports;
 virtio_net_conf net;
+bool ioeventfd_started;
+VMChangeStateEntry *vm_change_state_entry;
 } VirtIOPCIProxy;
 
 /* virtio device */
@@ -179,12 +186,131 @@ static int virtio_pci_load_queue(void * opaque, int n, 
QEMUFile *f)
 return 0;
 }
 
+static int virtio_pci_set_host_notifier_internal(VirtIOPCIProxy *proxy,
+ int n, bool assign)
+{
+VirtQueue *vq = virtio_get_queue(proxy-vdev, n);
+EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
+int r;
+if (assign) {
+r = event_notifier_init(notifier, 1);
+if (r  0) {
+return r;
+}
+r = kvm_set_ioeventfd_pio_word(event_notifier_get_fd(notifier),
+   proxy-addr + VIRTIO_PCI_QUEUE_NOTIFY,
+   n, assign);
+if (r  0) {
+event_notifier_cleanup(notifier);
+}
+} else {
+r = kvm_set_ioeventfd_pio_word(event_notifier_get_fd(notifier),
+   proxy-addr + VIRTIO_PCI_QUEUE_NOTIFY,
+   n, assign);
+if (r  0) {
+return r;
+}
+
+/* Handle the race condition where the guest kicked and we deassigned
+ * before we got around to handling the kick.
+ */
+if (event_notifier_test_and_clear(notifier)) {
+virtio_queue_notify_vq(vq);
+}
+
+event_notifier_cleanup(notifier);
+}
+return r;
+}
+
+static void virtio_pci_host_notifier_read(void *opaque)
+{
+VirtQueue *vq = opaque;
+EventNotifier *n = virtio_queue_get_host_notifier(vq);
+if (event_notifier_test_and_clear(n)) {
+virtio_queue_notify_vq(vq);
+}
+}
+
+static void virtio_pci_set_host_notifier_fd_handler(VirtIOPCIProxy *proxy,
+int n, bool assign)
+{
+VirtQueue *vq = virtio_get_queue(proxy-vdev, n);
+EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
+if (assign) {
+qemu_set_fd_handler(event_notifier_get_fd(notifier),
+virtio_pci_host_notifier_read, NULL, vq);
+} else {
+qemu_set_fd_handler(event_notifier_get_fd(notifier),
+NULL, NULL, NULL);
+}
+}
+
+static int virtio_pci_start_ioeventfd(VirtIOPCIProxy *proxy)

[Qemu-devel] [Bug 680758] Re: balloon only resizes by 2M

2010-12-17 Thread a1bert
the same here:

host debian squeeze: qemu-kvm-0.12.5
guest: windows 2008 server 
balloon driver: 6.1.7600.16385  10.8.2010



~# virsh  -c qemu:///system dominfo 9 | grep Used
Used memory:2064384 kB
~# virsh  -c qemu:///system setmem 9 512000

~# virsh  -c qemu:///system dominfo 9 | grep Used
Used memory:2062336 kB


the same host,  but winXP guest with the same balloon driver is working, looks 
like balloon driver issue...

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/680758

Title:
  balloon only resizes by 2M

Status in QEMU:
  New

Bug description:
  when in monitor and running balloon 512 from a 1024M VM, the vm dropped the 
size to 1020 (this value changes), then every subsequent request to balloon 512 
will drop it by another 2M.  The system was running at above 60% RAM free when 
these requests were made.  also requesting to up the ram results in no change 
above 1024 (I'm guessing this is intentional, but was unable to find any 
documentation)

Versions:

qemu-kvm 0.13.0
qemu-kvm.git b377474e589e5a1fe2abc7b13fafa8bad802637a

Qemu Command Line:

./x86_64-softmmu/qemu-system-x86_64 -drive 
file=/var/machines/seven.base,if=virtio -net 
nic,model=virtio,macaddr=02:00:00:00:00:01 -net 
tap,script=/etc/qemu/qemu-ifup,downscript=/etc/qemu/qemu-ifdown -vga std -usb 
-usbdevice tablet -rtc base=localtime,clock=host -watchdog i6300esb -balloon 
virtio -m 1024 -no-quit -smp 2 -monitor stdio

Monitor Session:

QEMU 0.13.50 monitor - type 'help' for more information
(qemu) info balloon
balloon: actual=1024
(qemu) balloon 1536
(qemu) info balloon
balloon: actual=1024
(qemu) balloon 512
(qemu) info balloon
balloon: actual=1020
(qemu) info balloon
balloon: actual=1020
(qemu) balloon 512
(qemu) info balloon
balloon: actual=1018







Re: [Qemu-devel] [PATCH 1/1] spice: add chardev

2010-12-17 Thread Alon Levy
On Thu, Dec 16, 2010 at 05:53:10PM +0100, Gerd Hoffmann wrote:
   Hi,
 
 +//#define SPICE_QEMU_CHAR_USE_IOCTL
 
 Why is this disabled?
 Does it depend on the chardev patches from Amit?
 
 
 There was a long discussion that concluded we don't want IOCTL's at all,
 and that there should be some other mechanism for connection state
 communication between the two sides. Meanwhile I found out I don't need
 these (I don't remember exactly what I used instead, but basically just
 the regular results of write/read).
 
 Ok, so when it is obsolete now it can be dropped altogether I guess?

ok, I'll remove it from the patch.

 
 cheers,
   Gerd
 
 



[Qemu-devel] [PATCH v6 3/4] virtio-pci: Don't use ioeventfd on old kernels

2010-12-17 Thread Stefan Hajnoczi
There used to be a limit of 6 KVM io bus devices inside the kernel.  On
such a kernel, don't use ioeventfd for virtqueue host notification since
the limit is reached too easily.  This ensures that existing vhost-net
setups (which always use ioeventfd) have ioeventfds available so they
can continue to work.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 hw/virtio-pci.c |4 
 kvm-all.c   |   49 +
 kvm-stub.c  |5 +
 kvm.h   |1 +
 4 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 6b12248..b2181fc 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -690,6 +690,10 @@ static void virtio_init_pci(VirtIOPCIProxy *proxy, 
VirtIODevice *vdev,
 pci_register_bar(proxy-pci_dev, 0, size, PCI_BASE_ADDRESS_SPACE_IO,
virtio_map);
 
+if (!kvm_has_many_ioeventfds()) {
+proxy-flags = ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
+}
+
 virtio_bind_device(vdev, virtio_pci_bindings, proxy);
 proxy-host_features |= 0x1  VIRTIO_F_NOTIFY_ON_EMPTY;
 proxy-host_features |= 0x1  VIRTIO_F_BAD_FEATURE;
diff --git a/kvm-all.c b/kvm-all.c
index cae24bb..255b6fa 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -28,6 +28,11 @@
 #include kvm.h
 #include bswap.h
 
+/* This check must be after config-host.h is included */
+#ifdef CONFIG_EVENTFD
+#include sys/eventfd.h
+#endif
+
 /* KVM uses PAGE_SIZE in it's definition of COALESCED_MMIO_MAX */
 #define PAGE_SIZE TARGET_PAGE_SIZE
 
@@ -72,6 +77,7 @@ struct KVMState
 int irqchip_in_kernel;
 int pit_in_kernel;
 int xsave, xcrs;
+int many_ioeventfds;
 };
 
 static KVMState *kvm_state;
@@ -441,6 +447,39 @@ int kvm_check_extension(KVMState *s, unsigned int 
extension)
 return ret;
 }
 
+static int kvm_check_many_ioeventfds(void)
+{
+/* Older kernels have a 6 device limit on the KVM io bus.  Find out so we
+ * can avoid creating too many ioeventfds.
+ */
+#ifdef CONFIG_EVENTFD
+int ioeventfds[7];
+int i, ret = 0;
+for (i = 0; i  ARRAY_SIZE(ioeventfds); i++) {
+ioeventfds[i] = eventfd(0, EFD_CLOEXEC);
+if (ioeventfds[i]  0) {
+break;
+}
+ret = kvm_set_ioeventfd_pio_word(ioeventfds[i], 0, i, true);
+if (ret  0) {
+close(ioeventfds[i]);
+break;
+}
+}
+
+/* Decide whether many devices are supported or not */
+ret = i == ARRAY_SIZE(ioeventfds);
+
+while (i--  0) {
+kvm_set_ioeventfd_pio_word(ioeventfds[i], 0, i, false);
+close(ioeventfds[i]);
+}
+return ret;
+#else
+return 0;
+#endif
+}
+
 static void kvm_set_phys_mem(target_phys_addr_t start_addr,
 ram_addr_t size,
 ram_addr_t phys_offset)
@@ -717,6 +756,8 @@ int kvm_init(int smp_cpus)
 kvm_state = s;
 cpu_register_phys_memory_client(kvm_cpu_phys_memory_client);
 
+s-many_ioeventfds = kvm_check_many_ioeventfds();
+
 return 0;
 
 err:
@@ -1046,6 +1087,14 @@ int kvm_has_xcrs(void)
 return kvm_state-xcrs;
 }
 
+int kvm_has_many_ioeventfds(void)
+{
+if (!kvm_enabled()) {
+return 0;
+}
+return kvm_state-many_ioeventfds;
+}
+
 void kvm_setup_guest_memory(void *start, size_t size)
 {
 if (!kvm_has_sync_mmu()) {
diff --git a/kvm-stub.c b/kvm-stub.c
index 5384a4b..33d4476 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -99,6 +99,11 @@ int kvm_has_robust_singlestep(void)
 return 0;
 }
 
+int kvm_has_many_ioeventfds(void)
+{
+return 0;
+}
+
 void kvm_setup_guest_memory(void *start, size_t size)
 {
 }
diff --git a/kvm.h b/kvm.h
index 60a9b42..ce08d42 100644
--- a/kvm.h
+++ b/kvm.h
@@ -42,6 +42,7 @@ int kvm_has_robust_singlestep(void);
 int kvm_has_debugregs(void);
 int kvm_has_xsave(void);
 int kvm_has_xcrs(void);
+int kvm_has_many_ioeventfds(void);
 
 #ifdef NEED_CPU_H
 int kvm_init_vcpu(CPUState *env);
-- 
1.7.2.3




[Qemu-devel] Re: [PATCH v6 0/5] qed: Add QEMU Enhanced Disk format

2010-12-17 Thread Kevin Wolf
Am 06.12.2010 17:07, schrieb Stefan Hajnoczi:
 For a changelog against v5, see below.
 
 QEMU Enhanced Disk format is a disk image format that forgoes features
 found in qcow2 in favor of better levels of performance and data
 integrity.  Due to its simpler on-disk layout, it is possible to safely
 perform metadata updates more efficiently.
 
 Installations, suspend-to-disk, and other allocation-heavy I/O workloads
 will see increased performance due to fewer I/Os and syncs.  Workloads
 that do not cause new clusters to be allocated will perform similar to
 raw images due to in-memory metadata caching.
 
 The format supports sparse disk images.  It does not rely on the host
 filesystem holes feature, making it a good choice for sparse disk images
 that need to be transferred over channels where holes are not supported.
 
 Backing files are supported so only deltas against a base image can be
 stored.  The base image may be smaller than the image file.
 
 The file format is extensible so that additional features can be added
 later with graceful compatibility handling.  A specification for the file
 format is included in this patchset.
 
 Internal snapshots are not supported.  This eliminates the need for
 additional metadata to track copy-on-write clusters.
 
 Compression and encryption are not supported.  They add complexity and can be
 implemented at other layers in the stack (i.e. inside the guest or on the
 host).  Encryption has been identified as a potential future extension and the
 file format allows for this.
 
 Signed-off-by: Anthony Liguori aligu...@us.ibm.com
 Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com

Thanks, reluctantly applied to the block branch. ;-)

Kevin



[Qemu-devel] [PATCH 27/30] usb storage: fix status reporting

2010-12-17 Thread Gerd Hoffmann
Change usb_msd_send_status() to take a pointer to the status packet
instead of writing the status to s-usb_buf which might not point
to the correct location.

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

diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index 7b8189f..28c12dd 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -196,15 +196,18 @@ static void usb_msd_copy_data(MSDState *s)
 }
 }
 
-static void usb_msd_send_status(MSDState *s)
+static void usb_msd_send_status(MSDState *s, USBPacket *p)
 {
 struct usb_msd_csw csw;
+int len;
 
 csw.sig = cpu_to_le32(0x53425355);
 csw.tag = cpu_to_le32(s-tag);
 csw.residue = s-residue;
 csw.status = s-result;
-memcpy(s-usb_buf, csw, 13);
+
+len = MIN(sizeof(csw), p-len);
+memcpy(p-data, csw, len);
 }
 
 static void usb_msd_command_complete(SCSIBus *bus, int reason, uint32_t tag,
@@ -224,7 +227,7 @@ static void usb_msd_command_complete(SCSIBus *bus, int 
reason, uint32_t tag,
 if (s-data_len == 0  s-mode == USB_MSDM_DATAOUT) {
 /* A deferred packet with no write data remaining must be
the status read packet.  */
-usb_msd_send_status(s);
+usb_msd_send_status(s, p);
 s-mode = USB_MSDM_CBW;
 } else {
 if (s-data_len) {
@@ -425,9 +428,7 @@ static int usb_msd_handle_data(USBDevice *dev, USBPacket *p)
 if (len  13)
 goto fail;
 
-s-usb_len = len;
-s-usb_buf = data;
-usb_msd_send_status(s);
+usb_msd_send_status(s, p);
 s-mode = USB_MSDM_CBW;
 ret = 13;
 break;
-- 
1.7.1




[Qemu-devel] [PATCH 28/30] usb storage: handle long responses

2010-12-17 Thread Gerd Hoffmann
The scsi layer may return us more data than the guests wants to have.
Handle this by just ignoring the extra bytes and calling the
{read,write}_data callback to finish the request.

Seen happening in real life with some extended inquiry command.
With this patch applied the linux kernel stops reseting the device
once at boot.

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

diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index 28c12dd..729d96c 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -187,7 +187,7 @@ static void usb_msd_copy_data(MSDState *s)
 s-usb_buf += len;
 s-scsi_buf += len;
 s-data_len -= len;
-if (s-scsi_len == 0) {
+if (s-scsi_len == 0 || s-data_len == 0) {
 if (s-mode == USB_MSDM_DATAIN) {
 s-scsi_dev-info-read_data(s-scsi_dev, s-tag);
 } else if (s-mode == USB_MSDM_DATAOUT) {
@@ -434,7 +434,7 @@ static int usb_msd_handle_data(USBDevice *dev, USBPacket *p)
 break;
 
 case USB_MSDM_DATAIN:
-DPRINTF(Data in %d/%d\n, len, s-data_len);
+DPRINTF(Data in %d/%d, scsi_len %d\n, len, s-data_len, 
s-scsi_len);
 if (len  s-data_len)
 len = s-data_len;
 s-usb_buf = data;
-- 
1.7.1




[Qemu-devel] Re: [PATCH v2] ide: Register vm change state handler once only

2010-12-17 Thread Kevin Wolf
Am 16.12.2010 16:54, schrieb Stefan Hajnoczi:
 We register the vm change state handler in a PCI BAR map() function.
 This function can be called multiple times throughout the lifetime of a
 PCI IDE device.  This results in duplicate vm change state handlers
 being register, none of which are ever unregistered.
 
 Instead, register the vm change state handler in the device's init
 function once and for all.
 
 piix tested, cmd646 and via not tested.
 
 Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com

Thanks, applied to the block branch.

Kevin



[Qemu-devel] Re: [PATCH v6 0/5] qed: Add QEMU Enhanced Disk format

2010-12-17 Thread Stefan Hajnoczi
On Fri, Dec 17, 2010 at 02:08:16PM +0100, Kevin Wolf wrote:
 Am 06.12.2010 17:07, schrieb Stefan Hajnoczi:
  For a changelog against v5, see below.
  
  QEMU Enhanced Disk format is a disk image format that forgoes features
  found in qcow2 in favor of better levels of performance and data
  integrity.  Due to its simpler on-disk layout, it is possible to safely
  perform metadata updates more efficiently.
  
  Installations, suspend-to-disk, and other allocation-heavy I/O workloads
  will see increased performance due to fewer I/Os and syncs.  Workloads
  that do not cause new clusters to be allocated will perform similar to
  raw images due to in-memory metadata caching.
  
  The format supports sparse disk images.  It does not rely on the host
  filesystem holes feature, making it a good choice for sparse disk images
  that need to be transferred over channels where holes are not supported.
  
  Backing files are supported so only deltas against a base image can be
  stored.  The base image may be smaller than the image file.
  
  The file format is extensible so that additional features can be added
  later with graceful compatibility handling.  A specification for the file
  format is included in this patchset.
  
  Internal snapshots are not supported.  This eliminates the need for
  additional metadata to track copy-on-write clusters.
  
  Compression and encryption are not supported.  They add complexity and can 
  be
  implemented at other layers in the stack (i.e. inside the guest or on the
  host).  Encryption has been identified as a potential future extension and 
  the
  file format allows for this.
  
  Signed-off-by: Anthony Liguori aligu...@us.ibm.com
  Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
 
 Thanks, reluctantly applied to the block branch. ;-)

Thank you Kevin!

Stefan



[Qemu-devel] [PATCH] spice: add chardev (v2)

2010-12-17 Thread Alon Levy
Adding a chardev backend for spice, for usage by spice vdagent in
conjunction with a properly named virtio-serial device.

Example usage:
 qemu -device virtio-serial -chardev spicevmc,name=vdagent,id=vdagent -devic

This is equivalent to the old:
 qemu -device virtio-serial -device spicevmc,subtype=vdagent

longer to write, but generated by libvirt, and requires one less device.

v1-v2 changes:
 * removed spice-qemu-char.h, folded into spice-qemu-char.h
 * removed dead IOCTL code
 * removed comment
 * removed ifdef CONFIG_SPICE from qemu-config.c and qemu-options.hx help.
---
 Makefile.objs |2 +-
 qemu-char.c   |4 +
 qemu-config.c |6 ++
 qemu-options.hx   |   16 -
 spice-qemu-char.c |  185 +
 ui/qemu-spice.h   |3 +
 6 files changed, 214 insertions(+), 2 deletions(-)
 create mode 100644 spice-qemu-char.c

diff --git a/Makefile.objs b/Makefile.objs
index cebb945..320b2a9 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -102,7 +102,7 @@ common-obj-$(CONFIG_BRLAPI) += baum.o
 common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
 common-obj-$(CONFIG_WIN32) += version.o
 
-common-obj-$(CONFIG_SPICE) += ui/spice-core.o ui/spice-input.o 
ui/spice-display.o
+common-obj-$(CONFIG_SPICE) += ui/spice-core.o ui/spice-input.o 
ui/spice-display.o spice-qemu-char.o
 
 audio-obj-y = audio.o noaudio.o wavaudio.o mixeng.o
 audio-obj-$(CONFIG_SDL) += sdlaudio.o
diff --git a/qemu-char.c b/qemu-char.c
index edc9ad6..acc7130 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -97,6 +97,7 @@
 #endif
 
 #include qemu_socket.h
+#include ui/qemu-spice.h
 
 #define READ_BUF_LEN 4096
 
@@ -2495,6 +2496,9 @@ static const struct {
 || defined(__FreeBSD_kernel__)
 { .name = parport,   .open = qemu_chr_open_pp },
 #endif
+#ifdef CONFIG_SPICE
+{ .name = spicevmc, .open = qemu_chr_open_spice },
+#endif
 };
 
 CharDriverState *qemu_chr_open_opts(QemuOpts *opts,
diff --git a/qemu-config.c b/qemu-config.c
index 965fa46..323d3c2 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -146,6 +146,12 @@ static QemuOptsList qemu_chardev_opts = {
 },{
 .name = signal,
 .type = QEMU_OPT_BOOL,
+},{
+.name = name,
+.type = QEMU_OPT_STRING,
+},{
+.name = debug,
+.type = QEMU_OPT_NUMBER,
 },
 { /* end of list */ }
 },
diff --git a/qemu-options.hx b/qemu-options.hx
index 4d99a58..5c13f0f 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1357,6 +1357,9 @@ DEF(chardev, HAS_ARG, QEMU_OPTION_chardev,
 #if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
 -chardev parport,id=id,path=path[,mux=on|off]\n
 #endif
+#if defined(CONFIG_SPICE)
+-chardev spicevmc,id=id,debug=debug,name=name\n
+#endif
 , QEMU_ARCH_ALL
 )
 
@@ -1381,7 +1384,8 @@ Backend is one of:
 @option{stdio},
 @option{braille},
 @option{tty},
-...@option{parport}.
+...@option{parport}
+...@option{spicevmc}.
 The specific backend will determine the applicable options.
 
 All devices must have an id, which can be any string up to 127 characters long.
@@ -1557,6 +1561,16 @@ Connect to a local parallel port.
 @option{path} specifies the path to the parallel port device. @option{path} is
 required.
 
+#if defined(CONFIG_SPICE)
+...@item -chardev spicevmc ,i...@var{id} ,deb...@var{debug}, na...@var{name}
+
+...@option{debug} debug level for spicevmc
+
+...@option{name} name of spice channel to connect to
+
+Connect to a spice virtual machine channel, such as vdiport.
+#endif
+
 @end table
 ETEXI
 
diff --git a/spice-qemu-char.c b/spice-qemu-char.c
new file mode 100644
index 000..0ffa674
--- /dev/null
+++ b/spice-qemu-char.c
@@ -0,0 +1,185 @@
+#include config-host.h
+#include ui/qemu-spice.h
+#include spice.h
+#include spice-experimental.h
+
+#include osdep.h
+
+#define dprintf(_scd, _level, _fmt, ...)\
+do {\
+static unsigned __dprintf_counter = 0;  \
+if (_scd-debug = _level) {\
+fprintf(stderr, scd: %3d:  _fmt, ++__dprintf_counter, ## 
__VA_ARGS__);\
+}   \
+} while (0)
+
+#define VMC_MAX_HOST_WRITE2048
+
+typedef struct SpiceCharDriver {
+CharDriverState*  chr;
+SpiceCharDeviceInstance sin;
+char  *subtype;
+bool  active;
+uint8_t   *buffer;
+uint8_t   *datapos;
+ssize_t   bufsize, datalen;
+uint32_t  debug;
+} SpiceCharDriver;
+
+static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len)
+{
+SpiceCharDriver *scd = container_of(sin, SpiceCharDriver, sin);
+ssize_t out = 0;
+ssize_t last_out;
+uint8_t* p = (uint8_t*)buf;

[Qemu-devel] booting demo kernel with -kernel demo kernel

2010-12-17 Thread Toan Pham
Hi,

Qemu has been a great tool to boot the linux kernel using a parameter
like below.  However, I have now been experiencing with os-development
and noticed that qemu can not boot a demo kernel that is compiled as
elf format and reallocated to 0x10.  One example is a demo kernel
found as osdev.org.  I am not sure why qemu bootloader is not tailored
to boot this fundamental kernel format since it would be very
convenience for many OS enthusiasts.  Is it something you can consider
add support on feature releases?  thanks.


example 1:  can not boot demo kernel

qemu -kernel demo_kernel.bin -hda /dev/zero


example 2:  same command, boot the linux kernel alright!

qemu -kernel linux_kernel.bzImage format -hda /dev/zero


-thank you



Re: [Qemu-devel] Re: [PATCH] win32: Fix CRLF problem in make_device_config.sh

2010-12-17 Thread Andreas Färber

Am 16.12.2010 um 23:42 schrieb Paolo Bonzini:


On 12/16/2010 10:52 PM, Stefan Weil wrote:

QEMU source code with CRLF line endings
which is quite common on windows hosts
fails with current make_device_config.sh.

The awk script gets the name of the included
file with \r, so instead of pci.mak it will
search for pci.mak\r which of course does
not work.

Fix this by removing any \r at end of line.


Why isn't cygwin (or whatever you're using) removing it?


I believe Cygwin had an option to choose the line ending style once  
during setup. By default it uses Unix-style line endings.
If someone edits source files in some Windows editor, the above issue  
seems likely.


My awk foo is insufficient to ack the patch but if it doesn't break  
Unices it looks reasonable to me.


Andreas



Re: [Qemu-devel] [PATCH] spice: add chardev (v2)

2010-12-17 Thread Alon Levy
On Fri, Dec 17, 2010 at 03:22:13PM +0200, Alon Levy wrote:
 Adding a chardev backend for spice, for usage by spice vdagent in
 conjunction with a properly named virtio-serial device.
 
 Example usage:
  qemu -device virtio-serial -chardev spicevmc,name=vdagent,id=vdagent -devic
 
 This is equivalent to the old:
  qemu -device virtio-serial -device spicevmc,subtype=vdagent
 
 longer to write, but generated by libvirt, and requires one less device.
 
 v1-v2 changes:
  * removed spice-qemu-char.h, folded into spice-qemu-char.h
NAK self on account of this silly typo.

  * removed dead IOCTL code
  * removed comment
  * removed ifdef CONFIG_SPICE from qemu-config.c and qemu-options.hx help.
 ---
  Makefile.objs |2 +-
  qemu-char.c   |4 +
  qemu-config.c |6 ++
  qemu-options.hx   |   16 -
  spice-qemu-char.c |  185 
 +
  ui/qemu-spice.h   |3 +
  6 files changed, 214 insertions(+), 2 deletions(-)
  create mode 100644 spice-qemu-char.c
 
 diff --git a/Makefile.objs b/Makefile.objs
 index cebb945..320b2a9 100644
 --- a/Makefile.objs
 +++ b/Makefile.objs
 @@ -102,7 +102,7 @@ common-obj-$(CONFIG_BRLAPI) += baum.o
  common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o 
 migration-fd.o
  common-obj-$(CONFIG_WIN32) += version.o
  
 -common-obj-$(CONFIG_SPICE) += ui/spice-core.o ui/spice-input.o 
 ui/spice-display.o
 +common-obj-$(CONFIG_SPICE) += ui/spice-core.o ui/spice-input.o 
 ui/spice-display.o spice-qemu-char.o
  
  audio-obj-y = audio.o noaudio.o wavaudio.o mixeng.o
  audio-obj-$(CONFIG_SDL) += sdlaudio.o
 diff --git a/qemu-char.c b/qemu-char.c
 index edc9ad6..acc7130 100644
 --- a/qemu-char.c
 +++ b/qemu-char.c
 @@ -97,6 +97,7 @@
  #endif
  
  #include qemu_socket.h
 +#include ui/qemu-spice.h
  
  #define READ_BUF_LEN 4096
  
 @@ -2495,6 +2496,9 @@ static const struct {
  || defined(__FreeBSD_kernel__)
  { .name = parport,   .open = qemu_chr_open_pp },
  #endif
 +#ifdef CONFIG_SPICE
 +{ .name = spicevmc, .open = qemu_chr_open_spice },
 +#endif
  };
  
  CharDriverState *qemu_chr_open_opts(QemuOpts *opts,
 diff --git a/qemu-config.c b/qemu-config.c
 index 965fa46..323d3c2 100644
 --- a/qemu-config.c
 +++ b/qemu-config.c
 @@ -146,6 +146,12 @@ static QemuOptsList qemu_chardev_opts = {
  },{
  .name = signal,
  .type = QEMU_OPT_BOOL,
 +},{
 +.name = name,
 +.type = QEMU_OPT_STRING,
 +},{
 +.name = debug,
 +.type = QEMU_OPT_NUMBER,
  },
  { /* end of list */ }
  },
 diff --git a/qemu-options.hx b/qemu-options.hx
 index 4d99a58..5c13f0f 100644
 --- a/qemu-options.hx
 +++ b/qemu-options.hx
 @@ -1357,6 +1357,9 @@ DEF(chardev, HAS_ARG, QEMU_OPTION_chardev,
  #if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
  -chardev parport,id=id,path=path[,mux=on|off]\n
  #endif
 +#if defined(CONFIG_SPICE)
 +-chardev spicevmc,id=id,debug=debug,name=name\n
 +#endif
  , QEMU_ARCH_ALL
  )
  
 @@ -1381,7 +1384,8 @@ Backend is one of:
  @option{stdio},
  @option{braille},
  @option{tty},
 -...@option{parport}.
 +...@option{parport}
 +...@option{spicevmc}.
  The specific backend will determine the applicable options.
  
  All devices must have an id, which can be any string up to 127 characters 
 long.
 @@ -1557,6 +1561,16 @@ Connect to a local parallel port.
  @option{path} specifies the path to the parallel port device. @option{path} 
 is
  required.
  
 +#if defined(CONFIG_SPICE)
 +...@item -chardev spicevmc ,i...@var{id} ,deb...@var{debug}, na...@var{name}
 +
 +...@option{debug} debug level for spicevmc
 +
 +...@option{name} name of spice channel to connect to
 +
 +Connect to a spice virtual machine channel, such as vdiport.
 +#endif
 +
  @end table
  ETEXI
  
 diff --git a/spice-qemu-char.c b/spice-qemu-char.c
 new file mode 100644
 index 000..0ffa674
 --- /dev/null
 +++ b/spice-qemu-char.c
 @@ -0,0 +1,185 @@
 +#include config-host.h
 +#include ui/qemu-spice.h
 +#include spice.h
 +#include spice-experimental.h
 +
 +#include osdep.h
 +
 +#define dprintf(_scd, _level, _fmt, ...)\
 +do {\
 +static unsigned __dprintf_counter = 0;  \
 +if (_scd-debug = _level) {\
 +fprintf(stderr, scd: %3d:  _fmt, ++__dprintf_counter, ## 
 __VA_ARGS__);\
 +}   \
 +} while (0)
 +
 +#define VMC_MAX_HOST_WRITE2048
 +
 +typedef struct SpiceCharDriver {
 +CharDriverState*  chr;
 +SpiceCharDeviceInstance sin;
 +char  *subtype;
 +bool  active;
 +uint8_t   *buffer;
 +uint8_t   *datapos;
 +ssize_t   bufsize, datalen;
 +uint32_t 

[Qemu-devel] [PATCH] spice: add chardev (v3)

2010-12-17 Thread Alon Levy
Adding a chardev backend for spice, for usage by spice vdagent in
conjunction with a properly named virtio-serial device.

Example usage:
 qemu -device virtio-serial -chardev spicevmc,name=vdagent,id=vdagent -devic

This is equivalent to the old:
 qemu -device virtio-serial -device spicevmc,subtype=vdagent

longer to write, but generated by libvirt, and requires one less device.

v1-v3 changes: (v2 had a wrong commit message)
 * removed spice-qemu-char.h, folded into ui/qemu-spice.h
 * removed dead IOCTL code
 * removed comment
 * removed ifdef CONFIG_SPICE from qemu-config.c and qemu-options.hx help.
---
 Makefile.objs |2 +-
 qemu-char.c   |4 +
 qemu-config.c |6 ++
 qemu-options.hx   |   16 -
 spice-qemu-char.c |  185 +
 ui/qemu-spice.h   |3 +
 6 files changed, 214 insertions(+), 2 deletions(-)
 create mode 100644 spice-qemu-char.c

diff --git a/Makefile.objs b/Makefile.objs
index cebb945..320b2a9 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -102,7 +102,7 @@ common-obj-$(CONFIG_BRLAPI) += baum.o
 common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
 common-obj-$(CONFIG_WIN32) += version.o
 
-common-obj-$(CONFIG_SPICE) += ui/spice-core.o ui/spice-input.o 
ui/spice-display.o
+common-obj-$(CONFIG_SPICE) += ui/spice-core.o ui/spice-input.o 
ui/spice-display.o spice-qemu-char.o
 
 audio-obj-y = audio.o noaudio.o wavaudio.o mixeng.o
 audio-obj-$(CONFIG_SDL) += sdlaudio.o
diff --git a/qemu-char.c b/qemu-char.c
index edc9ad6..acc7130 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -97,6 +97,7 @@
 #endif
 
 #include qemu_socket.h
+#include ui/qemu-spice.h
 
 #define READ_BUF_LEN 4096
 
@@ -2495,6 +2496,9 @@ static const struct {
 || defined(__FreeBSD_kernel__)
 { .name = parport,   .open = qemu_chr_open_pp },
 #endif
+#ifdef CONFIG_SPICE
+{ .name = spicevmc, .open = qemu_chr_open_spice },
+#endif
 };
 
 CharDriverState *qemu_chr_open_opts(QemuOpts *opts,
diff --git a/qemu-config.c b/qemu-config.c
index 965fa46..323d3c2 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -146,6 +146,12 @@ static QemuOptsList qemu_chardev_opts = {
 },{
 .name = signal,
 .type = QEMU_OPT_BOOL,
+},{
+.name = name,
+.type = QEMU_OPT_STRING,
+},{
+.name = debug,
+.type = QEMU_OPT_NUMBER,
 },
 { /* end of list */ }
 },
diff --git a/qemu-options.hx b/qemu-options.hx
index 4d99a58..5c13f0f 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1357,6 +1357,9 @@ DEF(chardev, HAS_ARG, QEMU_OPTION_chardev,
 #if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
 -chardev parport,id=id,path=path[,mux=on|off]\n
 #endif
+#if defined(CONFIG_SPICE)
+-chardev spicevmc,id=id,debug=debug,name=name\n
+#endif
 , QEMU_ARCH_ALL
 )
 
@@ -1381,7 +1384,8 @@ Backend is one of:
 @option{stdio},
 @option{braille},
 @option{tty},
-...@option{parport}.
+...@option{parport}
+...@option{spicevmc}.
 The specific backend will determine the applicable options.
 
 All devices must have an id, which can be any string up to 127 characters long.
@@ -1557,6 +1561,16 @@ Connect to a local parallel port.
 @option{path} specifies the path to the parallel port device. @option{path} is
 required.
 
+#if defined(CONFIG_SPICE)
+...@item -chardev spicevmc ,i...@var{id} ,deb...@var{debug}, na...@var{name}
+
+...@option{debug} debug level for spicevmc
+
+...@option{name} name of spice channel to connect to
+
+Connect to a spice virtual machine channel, such as vdiport.
+#endif
+
 @end table
 ETEXI
 
diff --git a/spice-qemu-char.c b/spice-qemu-char.c
new file mode 100644
index 000..0ffa674
--- /dev/null
+++ b/spice-qemu-char.c
@@ -0,0 +1,185 @@
+#include config-host.h
+#include ui/qemu-spice.h
+#include spice.h
+#include spice-experimental.h
+
+#include osdep.h
+
+#define dprintf(_scd, _level, _fmt, ...)\
+do {\
+static unsigned __dprintf_counter = 0;  \
+if (_scd-debug = _level) {\
+fprintf(stderr, scd: %3d:  _fmt, ++__dprintf_counter, ## 
__VA_ARGS__);\
+}   \
+} while (0)
+
+#define VMC_MAX_HOST_WRITE2048
+
+typedef struct SpiceCharDriver {
+CharDriverState*  chr;
+SpiceCharDeviceInstance sin;
+char  *subtype;
+bool  active;
+uint8_t   *buffer;
+uint8_t   *datapos;
+ssize_t   bufsize, datalen;
+uint32_t  debug;
+} SpiceCharDriver;
+
+static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len)
+{
+SpiceCharDriver *scd = container_of(sin, SpiceCharDriver, sin);
+ssize_t out = 0;
+ssize_t last_out;
+   

Re: [Qemu-devel] Re: [PATCH] win32: Fix CRLF problem in make_device_config.sh

2010-12-17 Thread Paolo Bonzini

On 12/17/2010 02:34 PM, Andreas Färber wrote:


Fix this by removing any \r at end of line.


Why isn't cygwin (or whatever you're using) removing it?


I believe Cygwin had an option to choose the line ending style once
during setup. By default it uses Unix-style line endings.
If someone edits source files in some Windows editor, the above issue
seems likely.


Hmm, MSYS is more problematic: the manual says In the MSYS environment 
under Windows, `gawk' automatically uses binary mode for reading and 
writing files. Thus there is no need to use the `BINMODE' variable. 
This can cause problems with other Unix-like components that have been 
ported to Windows that expect `gawk' to do automatic translationof 
`\r\n', since it won't..



My awk foo is insufficient to ack the patch but if it doesn't break
Unices it looks reasonable to me.


I'd be worried a bit about Solaris and other proprietary OSes with 
prehistoric Unix utilities.  Perhaps using \012 instead of \r is better.


Paolo



Re: [Qemu-devel] classic emulator Vs QEMU-TCG

2010-12-17 Thread Stefano Bonifazi

On 12/16/2010 04:41 PM, Peter Maydell wrote:

Some hints:
  * go and look up the C syntax for function pointers and
casting things to function pointers

Yup! See the reply to Mr. Santosa, thank you!

  * code_gen_prologue[] contains code which has been generated
once on startup -- go and find the function which is doing this,
which ought to tell you what the prologue code actually does...

Is that the following?

/* init global prologue and epilogue */
s-code_buf = code_gen_prologue;
s-code_ptr = s-code_buf;
tcg_target_qemu_prologue(s);



Trying to understand the pseudo-assembly in tcg_target_qemu_prologue (in 
file tcg-target.c), I think it builds an assembly function scheleton 
storying it inside code_gen_prologue array..
Cosidering the implementation of that function for i386 I think the jmp 
*%eax is the actual code that jumps to the host binary produced by TCG 
from the target binary.. in fact, if I am not wrong,this binary function 
is what is actually called by tcg_qemu_tb_exec(tb_ptr) macro with tb_ptr 
passed to the function in %eax, thus jmp *%eax starts the execution of 
the binary code .. am I wrong?



  * try single stepping individual machine instructions in the
debugger as you go through tcg_qemu_tb_exec() and matching
this up with what is really happening here and with the bits of
qemu which generated that code.

-- PMM
I would have already done that.. unluckily I have always used IDE with 
integrated debuggers, and I can't find an IDE for loading this project.. 
I guess I have no other choice than learning also gdb

Thank you for your tips! :)
Best Regards!
Stefano B.



Re: [Qemu-devel] classic emulator Vs QEMU-TCG

2010-12-17 Thread Andreas Färber

Hi,

Am 17.12.2010 um 10:47 schrieb Stefano Bonifazi:


I've got an explanation from a C guru :)


((long REGPARM (*)(void *))code_gen_prologue)(tb_ptr)
-
(long REGPARM (*)(void *)) is a type: a pointer pointing to a  
function, which takes one (void*) parameter. code_gen_prologue is  
anarray, array's name when used is considered to be a pointer to  
its first element, thus you are casting here pointer to the first  
byte ofarray to pointer to function (...).
Ellipsis with tb_ptr mean 'call function under this address and  
pass there whatever tb_ptr is'


Now everything is very clear for me :)
I do know pointer to functions, and if I had got:


long REGPARM (*myfunc)(void *)


I would have recognized it.. but removing the function pointer name,  
leaving only the * was enough for me to be lost :[


Feel free to take the next step then and read CODING_GUIDELINES to  
create and submit your first Git patch to make the code more readable  
for others. Introducing a typedef for the cast might not be a bad idea.



also the definition of code_gen_prologue was tricky:

uint8_t code_gen_prologue[1024] code_gen_section;
that code_gen_section at first confused my idea of a normal variable  
definition as type identifier .. until I found out it was a define  
for a compiler directive (alignment) :[


Would capitalizing code_gen_section have helped to recognize it as a  
preprocessor define? Another patch idea. :)


Regards,
Andreas



Re: [Qemu-devel] Re: [PATCHv8 00/16] boot order specification

2010-12-17 Thread Andreas Färber

Am 15.12.2010 um 00:02 schrieb Alexander Graf:


On 14.12.2010, at 21:31, Benjamin Herrenschmidt wrote:



The only working system emulation we have are Macs (G3 beige, G4,  
G5),

so we can't just ignore Apple.
Alex even made me stick to their odd 0x41 rtas-version property. ;)


Hah :-) Nothing ever used RTAS on these... afaik, it didn't even work
properly.


Then let's not use rtas for the Mac machine, but rather go with  
Andreas' new machine. Changing the value there to what real FW uses  
on that machine is more than reasonable :)


The value is already conditional on is_apple(), so I don't think it  
needs changing.
I just mustn't forget to fix the old is_apple() {  return 1; }  
implementation for the new machines. :)


Andreas



[Qemu-devel] Re: [PATCH 1/2] block/qcow2.c: rename qcow_ functions to qcow2_

2010-12-17 Thread Kevin Wolf
Am 16.12.2010 17:05, schrieb jes.soren...@redhat.com:
 From: Jes Sorensen jes.soren...@redhat.com
 
 It doesn't really make sense for functions in qcow2.c to be named
 qcow_ so convert the names to match correctly.
 
 Signed-off-by: Jes Sorensen jes.soren...@redhat.com
 ---
  block/qcow2-cluster.c  |6 +-
  block/qcow2-snapshot.c |6 +-
  block/qcow2.c  |  210 
 +---
  3 files changed, 116 insertions(+), 106 deletions(-)
 
 diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
 index b040208..6928c63 100644
 --- a/block/qcow2-cluster.c
 +++ b/block/qcow2-cluster.c
 @@ -352,8 +352,8 @@ void qcow2_encrypt_sectors(BDRVQcowState *s, int64_t 
 sector_num,
  }
  
  
 -static int qcow_read(BlockDriverState *bs, int64_t sector_num,
 - uint8_t *buf, int nb_sectors)
 +static int qcow2_read(BlockDriverState *bs, int64_t sector_num,
 +  uint8_t *buf, int nb_sectors)
  {
  BDRVQcowState *s = bs-opaque;
  int ret, index_in_cluster, n, n1;
 @@ -419,7 +419,7 @@ static int copy_sectors(BlockDriverState *bs, uint64_t 
 start_sect,
  if (n = 0)
  return 0;
  BLKDBG_EVENT(bs-file, BLKDBG_COW_READ);
 -ret = qcow_read(bs, start_sect + n_start, s-cluster_data, n);
 +ret = qcow2_read(bs, start_sect + n_start, s-cluster_data, n);
  if (ret  0)
  return ret;
  if (s-crypt_method) {
 diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
 index aacf357..74823a5 100644
 --- a/block/qcow2-snapshot.c
 +++ b/block/qcow2-snapshot.c
 @@ -116,7 +116,7 @@ int qcow2_read_snapshots(BlockDriverState *bs)
  }
  
  /* add at the end of the file a new list of snapshots */
 -static int qcow_write_snapshots(BlockDriverState *bs)
 +static int qcow2_write_snapshots(BlockDriverState *bs)
  {
  BDRVQcowState *s = bs-opaque;
  QCowSnapshot *sn;
 @@ -300,7 +300,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, 
 QEMUSnapshotInfo *sn_info)
  s-snapshots = snapshots1;
  s-snapshots[s-nb_snapshots++] = *sn;
  
 -if (qcow_write_snapshots(bs)  0)
 +if (qcow2_write_snapshots(bs)  0)
  goto fail;
  #ifdef DEBUG_ALLOC
  qcow2_check_refcounts(bs);
 @@ -378,7 +378,7 @@ int qcow2_snapshot_delete(BlockDriverState *bs, const 
 char *snapshot_id)
  qemu_free(sn-name);
  memmove(sn, sn + 1, (s-nb_snapshots - snapshot_index - 1) * 
 sizeof(*sn));
  s-nb_snapshots--;
 -ret = qcow_write_snapshots(bs);
 +ret = qcow2_write_snapshots(bs);
  if (ret  0) {
  /* XXX: restore snapshot if error ? */
  return ret;
 diff --git a/block/qcow2.c b/block/qcow2.c
 index 537c479..d7fd167 100644
 --- a/block/qcow2.c
 +++ b/block/qcow2.c
 @@ -50,10 +50,10 @@ typedef struct {
  uint32_t magic;
  uint32_t len;
  } QCowExtension;
 -#define  QCOW_EXT_MAGIC_END 0
 -#define  QCOW_EXT_MAGIC_BACKING_FORMAT 0xE2792ACA
 +#define  QCOW2_EXT_MAGIC_END 0
 +#define  QCOW2_EXT_MAGIC_BACKING_FORMAT 0xE2792ACA
  
 -static int qcow_probe(const uint8_t *buf, int buf_size, const char *filename)
 +static int qcow2_probe(const uint8_t *buf, int buf_size, const char 
 *filename)
  {
  const QCowHeader *cow_header = (const void *)buf;
  
 @@ -73,14 +73,14 @@ static int qcow_probe(const uint8_t *buf, int buf_size, 
 const char *filename)
   * unknown magic is skipped (future extension this version knows nothing 
 about)
   * return 0 upon success, non-0 otherwise
   */
 -static int qcow_read_extensions(BlockDriverState *bs, uint64_t start_offset,
 -uint64_t end_offset)
 +static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset,
 + uint64_t end_offset)
  {
  QCowExtension ext;
  uint64_t offset;
  
  #ifdef DEBUG_EXT
 -printf(qcow_read_extensions: start=%ld end=%ld\n, start_offset, 
 end_offset);
 +printf(qcow2_read_extensions: start=%ld end=%ld\n, start_offset, 
 end_offset);
  #endif
  offset = start_offset;
  while (offset  end_offset) {
 @@ -88,13 +88,13 @@ static int qcow_read_extensions(BlockDriverState *bs, 
 uint64_t start_offset,
  #ifdef DEBUG_EXT
  /* Sanity check */
  if (offset  s-cluster_size)
 -printf(qcow_handle_extension: suspicious offset %lu\n, offset);
 +printf(qcow_read_extension: suspicious offset %lu\n, offset);

It's now qcow2_read_extensions

  
  printf(attemting to read extended header in offset %lu\n, offset);
  #endif
  
  if (bdrv_pread(bs-file, offset, ext, sizeof(ext)) != sizeof(ext)) {
 -fprintf(stderr, qcow_handle_extension: ERROR: 
 +fprintf(stderr, qcow_read_extension: ERROR: 

Same here.

  pread fail from offset % PRIu64 \n,
  offset);
  return 1;
 @@ -106,10 +106,10 @@ static int qcow_read_extensions(BlockDriverState *bs, 
 uint64_t start_offset,
  printf(ext.magic = 0x%x\n, ext.magic);
  

[Qemu-devel] Re: [PATCH 2/2] Add proper -errno error return values to qcow2_open()

2010-12-17 Thread Kevin Wolf
Am 16.12.2010 17:05, schrieb jes.soren...@redhat.com:
 From: Jes Sorensen jes.soren...@redhat.com
 
 In addition this adds missing braces to the function to be consistent
 with the coding style.
 
 Signed-off-by: Jes Sorensen jes.soren...@redhat.com
 ---
  block/qcow2.c |   61 
  1 files changed, 43 insertions(+), 18 deletions(-)
 
 diff --git a/block/qcow2.c b/block/qcow2.c
 index d7fd167..b4a9e5e 100644
 --- a/block/qcow2.c
 +++ b/block/qcow2.c
 @@ -140,12 +140,14 @@ static int qcow2_read_extensions(BlockDriverState *bs, 
 uint64_t start_offset,
  static int qcow2_open(BlockDriverState *bs, int flags)
  {
  BDRVQcowState *s = bs-opaque;
 -int len, i;
 +int len, i, ret = 0;
  QCowHeader header;
  uint64_t ext_end;
  
 -if (bdrv_pread(bs-file, 0, header, sizeof(header)) != sizeof(header))
 +if (bdrv_pread(bs-file, 0, header, sizeof(header)) != sizeof(header)) {
 +ret = -EIO; 
  goto fail;
 +}

ret = bdrv_pread(...);
if (ret  0) {
goto fail;
}

We have a specific error code, so why throw it away?

  be32_to_cpus(header.magic);
  be32_to_cpus(header.version);
  be64_to_cpus(header.backing_file_offset);
 @@ -160,16 +162,23 @@ static int qcow2_open(BlockDriverState *bs, int flags)
  be64_to_cpus(header.snapshots_offset);
  be32_to_cpus(header.nb_snapshots);
  
 -if (header.magic != QCOW_MAGIC || header.version != QCOW_VERSION)
 +if (header.magic != QCOW_MAGIC || header.version != QCOW_VERSION) {
 +ret = -EINVAL;
  goto fail;
 +}
  if (header.cluster_bits  MIN_CLUSTER_BITS ||
 -header.cluster_bits  MAX_CLUSTER_BITS)
 +header.cluster_bits  MAX_CLUSTER_BITS) {
 +ret = -EINVAL;
  goto fail;
 -if (header.crypt_method  QCOW_CRYPT_AES)
 +}
 +if (header.crypt_method  QCOW_CRYPT_AES) {
 +ret = -EINVAL;
  goto fail;
 +}
  s-crypt_method_header = header.crypt_method;
 -if (s-crypt_method_header)
 +if (s-crypt_method_header) {
  bs-encrypted = 1;
 +}
  s-cluster_bits = header.cluster_bits;
  s-cluster_size = 1  s-cluster_bits;
  s-cluster_sectors = 1  (s-cluster_bits - 9);
 @@ -191,15 +200,20 @@ static int qcow2_open(BlockDriverState *bs, int flags)
  s-l1_vm_state_index = size_to_l1(s, header.size);
  /* the L1 table must contain at least enough entries to put
 header.size bytes */
 -if (s-l1_size  s-l1_vm_state_index)
 +if (s-l1_size  s-l1_vm_state_index) {
 +ret = -EINVAL;
  goto fail;
 +}
  s-l1_table_offset = header.l1_table_offset;
  if (s-l1_size  0) {
  s-l1_table = qemu_mallocz(
  align_offset(s-l1_size * sizeof(uint64_t), 512));
 -if (bdrv_pread(bs-file, s-l1_table_offset, s-l1_table, s-l1_size 
 * sizeof(uint64_t)) !=
 -s-l1_size * sizeof(uint64_t))
 +if (bdrv_pread(bs-file, s-l1_table_offset, s-l1_table,
 +   s-l1_size * sizeof(uint64_t)) !=
 +s-l1_size * sizeof(uint64_t)) {
 +ret = -EIO;
  goto fail;
 +}

Same here.

  for(i = 0;i  s-l1_size; i++) {
  be64_to_cpus(s-l1_table[i]);
  }
 @@ -212,35 +226,46 @@ static int qcow2_open(BlockDriverState *bs, int flags)
+ 512);
  s-cluster_cache_offset = -1;
  
 -if (qcow2_refcount_init(bs)  0)
 +ret = qcow2_refcount_init(bs);
 +if (ret != 0) {
  goto fail;
 +}
  
  QLIST_INIT(s-cluster_allocs);
  
  /* read qcow2 extensions */
 -if (header.backing_file_offset)
 +if (header.backing_file_offset) {
  ext_end = header.backing_file_offset;
 -else
 +} else {
  ext_end = s-cluster_size;
 -if (qcow2_read_extensions(bs, sizeof(header), ext_end))
 +}
 +if (qcow2_read_extensions(bs, sizeof(header), ext_end)) {
 +ret = -EINVAL;
  goto fail;
 +}
  
  /* read the backing file name */
  if (header.backing_file_offset != 0) {
  len = header.backing_file_size;
 -if (len  1023)
 +if (len  1023) {
  len = 1023;
 -if (bdrv_pread(bs-file, header.backing_file_offset, 
 bs-backing_file, len) != len)
 +}
 +if (bdrv_pread(bs-file, header.backing_file_offset,
 +   bs-backing_file, len) != len) {
 +ret = -EIO;
  goto fail;
 +}

And here.

Otherwise the patch looks good to me.

Kevin



[Qemu-devel] Re: [PATCH 1/2] block/qcow2.c: rename qcow_ functions to qcow2_

2010-12-17 Thread Jes Sorensen
On 12/17/10 15:20, Kevin Wolf wrote:
  offset = start_offset;
  while (offset  end_offset) {
 @@ -88,13 +88,13 @@ static int qcow_read_extensions(BlockDriverState *bs, 
 uint64_t start_offset,
  #ifdef DEBUG_EXT
  /* Sanity check */
  if (offset  s-cluster_size)
 -printf(qcow_handle_extension: suspicious offset %lu\n, 
 offset);
 +printf(qcow_read_extension: suspicious offset %lu\n, offset);
 
 It's now qcow2_read_extensions

Fixed

 @@ -313,7 +313,7 @@ static int qcow_is_allocated(BlockDriverState *bs, 
 int64_t sector_num,
  
  /* handle reading after the end of the backing file */
  int qcow2_backing_read1(BlockDriverState *bs, QEMUIOVector *qiov,
 -  int64_t sector_num, int nb_sectors)
 +int64_t sector_num, int nb_sectors)
 
 This isn't related to renaming functions. Please don't include pure
 formatting changes, all they do is making git blame work worse.

No it makes the formatting consistent with the rest of the functions in
the file. I can leave it out, but then we just have more ugliness in the
file.

 @@ -399,10 +399,11 @@ static void qcow_aio_read_cb(void *opaque, int ret)
  } else {
  if (s-crypt_method) {
  qcow2_encrypt_sectors(s, acb-sector_num,  acb-cluster_data,
 -acb-cluster_data, acb-cur_nr_sectors, 0, 
 s-aes_decrypt_key);
 +  acb-cluster_data, acb-cur_nr_sectors,
 +  0, s-aes_decrypt_key);
 
 Same here, plus the old version wasn't obviously indented wrong, but
 just not according to your personal style.

Sorry it's broken formatting. But sure, I'll put it back to being
unreadable.

 The following changes include more lines that need not be changed for
 the rename and just change the coding style (even though CODING_STYLE
 doesn't make a statement on this, so the old version isn't wrong).
 Please leave them out.

Actually that is in the patch, I did a pure search replace, no
formatting. But I've fixed it.

Jes



Re: [Qemu-devel] [PATCH v2 2/6] qdev: reset qdev along with qdev tree

2010-12-17 Thread Peter Maydell
On 17 December 2010 00:24, Anthony Liguori aligu...@linux.vnet.ibm.com wrote:
 On 12/16/2010 05:48 PM, Michael S. Tsirkin wrote:
 Ugh, I keep forgetting about the non-qdev systems.
 Maybe it's a good way to finally make everyone to convert? If a system
 maintainer can't be bothered to convert to qdev we can declare the
 system unsupported :)

 Honestly, I think that's a fair thing to do.

I'm guessing that would be a transition/conversion to make for the
0.15 release, right?

-- PMM



[Qemu-devel] Re: [PATCH 2/2] Add proper -errno error return values to qcow2_open()

2010-12-17 Thread Jes Sorensen
On 12/17/10 15:27, Kevin Wolf wrote:
 Am 16.12.2010 17:05, schrieb jes.soren...@redhat.com:
 From: Jes Sorensen jes.soren...@redhat.com

 In addition this adds missing braces to the function to be consistent
 with the coding style.

 Signed-off-by: Jes Sorensen jes.soren...@redhat.com
 ---
  block/qcow2.c |   61 
 
  1 files changed, 43 insertions(+), 18 deletions(-)

 diff --git a/block/qcow2.c b/block/qcow2.c
 index d7fd167..b4a9e5e 100644
 --- a/block/qcow2.c
 +++ b/block/qcow2.c
 @@ -140,12 +140,14 @@ static int qcow2_read_extensions(BlockDriverState *bs, 
 uint64_t start_offset,
  static int qcow2_open(BlockDriverState *bs, int flags)
  {
  BDRVQcowState *s = bs-opaque;
 -int len, i;
 +int len, i, ret = 0;
  QCowHeader header;
  uint64_t ext_end;
  
 -if (bdrv_pread(bs-file, 0, header, sizeof(header)) != sizeof(header))
 +if (bdrv_pread(bs-file, 0, header, sizeof(header)) != sizeof(header)) 
 {
 +ret = -EIO; 
  goto fail;
 +}
 
 ret = bdrv_pread(...);
 if (ret  0) {
 goto fail;
 }

Hmmm I must have confused something and looked at a wrong pread function
where it just returned -1 on error. I'll fix it.

Thanks,
Jes



Re: [Qemu-devel] [PULL] virtio-9p patches - Request for pull

2010-12-17 Thread Anthony Liguori

On 12/02/2010 06:05 PM, Venkateswararao Jujjuri (JV) wrote:

The following changes since commit 6a8657528d94fa1be78d1be0821a01a251fa2de9:
   Anthony Liguori (1):
 Fix build

are available in the git repository at:

   git://repo.or.cz/qemu/aliguori/jvrao.git for-anthony
   


Pulled.  Thanks.

Regards,

Anthony Liguori


Harsh Prateek Bora (1):
   hw/virtio9p: Use appropriate debug print functions in TLINK path

Hidetoshi Seto (1):
   virtio-9p: fix build on !CONFIG_UTIMENSAT

Kusanagi Kouichi (1):
   virtio-9p: Check the return value of llistxattr.

Venkateswararao Jujjuri (JV) (1):
   [virtio-9p] Add datasync to server side TFSYNC/RFSYNC for dotl

  hw/file-op-9p.h  |2 +-
  hw/virtio-9p-debug.c |4 ++--
  hw/virtio-9p-local.c |   12 
  hw/virtio-9p-xattr.c |3 +++
  hw/virtio-9p.c   |   11 ++-
  oslib-posix.c|   48 
  qemu-os-posix.h  |   12 
  7 files changed, 80 insertions(+), 12 deletions(-)



   





Re: [Qemu-devel] [PULL 0/4]: Monitor queue

2010-12-17 Thread Anthony Liguori

On 12/06/2010 08:43 AM, Luiz Capitulino wrote:

Anthony,

QMP fixes pull request.

The changes (since 2c90fe2b71df2534884bce96d90cbfcc93aeedb8) are available
in the following repository:

 git://repo.or.cz/qemu/qmp-unstable.git for-anthony
   


Pulled.  Thanks.

Regards,

Anthony Liguori

Luiz Capitulino (3):
   QMP: Fix default response regression
   QMP: Drop dead code
   QMP: Simplify monitor_json_emitter()

Wen Congyang (1):
   correct migrate_set_speed's args_type

  monitor.c   |   84 --
  qmp-commands.hx |2 +-
  2 files changed, 38 insertions(+), 48 deletions(-)



   





Re: [Qemu-devel] [PULL] pci, virtio, net, migration

2010-12-17 Thread Anthony Liguori

On 12/12/2010 05:25 AM, Michael S. Tsirkin wrote:

The following changes since commit 962630f207a33b7de4316022884b5241e05491cd:

   Pass boot device list to firmware. (2010-12-11 21:32:48 +)
   


Pulled.  Thanks.

Regards,

Anthony Liguori

are available in the git repository at:
   git://git.kernel.org/pub/scm/linux/kernel/git/mst/qemu.git for_anthony

Isaku Yamahata (1):
   pci: make command SERR bit writable

Michael S. Tsirkin (10):
   cpus: flush all requests on each vm stop
   migration/savevm: no need to flush requests
   virtio-net: don't dma while vm is stopped
   virtio-net: stop/start bh when appropriate
   pci: untangle pci/msi dependency
   Makefile: make msix/msi depend on CONFIG_PCI
   pci/aer: fix error injection
   pci/aer: fix interrupt on config write
   pci/aer: remove dead code
   pci/aer: factor out common code

Mike Ryan (1):
   net/sock: option to specify local address

  Makefile.objs   |3 +-
  cpus.c  |2 +
  hw/pc_piix.c|   20 ++
  hw/pci.c|   24 ++-
  hw/pci.h|7 ++-
  hw/pcie.c   |8 ++-
  hw/pcie_aer.c   |  111 ++-
  hw/virtio-net.c |   69 ++
  migration.c |2 -
  net.c   |4 ++
  net/socket.c|   52 +++--
  qemu-options.hx |   11 -
  savevm.c|4 --
  13 files changed, 195 insertions(+), 122 deletions(-)


   





Re: [Qemu-devel] [PULL 00/14] Block patches

2010-12-17 Thread Anthony Liguori

On 12/09/2010 05:09 AM, Kevin Wolf wrote:

The following changes since commit 138b38b61bf92d4e9588acf934e532499c94e185:

   ppc: kvm: fix signedness warning (2010-12-08 21:30:19 +0100)

are available in the git repository at:
   git://repo.or.cz/qemu/kevin.git for-anthony

Christian Brunner (1):
   ceph/rbd block driver for qemu-kvm
   


Pulled.  Thanks.

Regards,

Anthony Liguori

Jes Sorensen (8):
   Add missing tracing to qemu_mallocz()
   Use qemu_mallocz() instead of calloc() in img_convert()
   img_convert(): Only try to free bs[] entries if bs is valid.
   Consolidate printing of block driver options
   Fix formatting and missing braces in qemu-img.c
   Fail if detecting an unknown option
   Make error handling more consistent in img_create() and img_resize()
   qemu-img: Deprecate obsolete -6 and -e options

Stefan Hajnoczi (5):
   block: Make bdrv_create_file() ':' handling consistent
   qemu-option: Don't reinvent append_option_parameters()
   qemu-option: Fix parse_option_parameters() documentation typo
   qemu-img: Free option parameter lists in img_create()
   qemu-img: Fail creation if backing format is invalid

  Makefile.objs |1 +
  block.c   |2 +-
  block/rbd.c   | 1059 +
  block/rbd_types.h |   71 
  block_int.h   |1 -
  configure |   52 +++
  qemu-img.c|  247 -
  qemu-malloc.c |5 +-
  qemu-option.c |   13 +-
  9 files changed, 1344 insertions(+), 107 deletions(-)
  create mode 100644 block/rbd.c
  create mode 100644 block/rbd_types.h


   





Re: [Qemu-devel] [PATCH 00/14] [PULL] ARM fixes, v2

2010-12-17 Thread Anthony Liguori

On 12/16/2010 12:07 PM, Peter Maydell wrote:

On 7 December 2010 15:50, Peter Maydellpeter.mayd...@linaro.org  wrote:
   

The following changes since commit 2c90fe2b71df2534884bce96d90cbfcc93aeedb8:
  Kirill Batuzov (1):
Speedup 'tb_find_slow' by using the same heuristic as during
memory page lookup

are available in the git repository at:

  git://git.linaro.org/qemu/qemu-arm.git for-anthony
 

Ping?
   


Pulled.  Thanks.

Regards,

Anthony Liguori

-- PMM


   





[Qemu-devel] [RFC][PATCH 3/3] mc146818rtc: Handle host clock warps

2010-12-17 Thread Jan Kiszka
Make use of the new warp notifier to update the RTC whenever rtc_clock
is the host clock and that happens to jump backward. This avoids that
the RTC stalls for the period the host clock was set back.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
---
 hw/mc146818rtc.c |   17 +
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index 6466aff..f65ea5a 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -563,6 +563,21 @@ static const VMStateDescription vmstate_rtc = {
 }
 };
 
+static void rtc_clock_warp(QEMUClock *clock, int64_t now, void *opaque)
+{
+RTCState *s = opaque;
+
+rtc_set_date_from_host(s-dev);
+s-next_second_time = now + (get_ticks_per_sec() * 99) / 100;
+qemu_mod_timer(s-second_timer2, s-next_second_time);
+rtc_timer_update(s, now);
+#ifdef TARGET_I386
+if (rtc_td_hack) {
+rtc_coalesced_timer_update(s);
+}
+#endif
+}
+
 static void rtc_reset(void *opaque)
 {
 RTCState *s = opaque;
@@ -599,6 +614,8 @@ static int rtc_initfn(ISADevice *dev)
 s-second_timer = qemu_new_timer(rtc_clock, rtc_update_second, s);
 s-second_timer2 = qemu_new_timer(rtc_clock, rtc_update_second2, s);
 
+qemu_register_clock_warp(rtc_clock, rtc_clock_warp, s);
+
 s-next_second_time =
 qemu_get_clock(rtc_clock) + (get_ticks_per_sec() * 99) / 100;
 qemu_mod_timer(s-second_timer2, s-next_second_time);
-- 
1.7.1




[Qemu-devel] [RFC][PATCH 1/3] qemu-timer: Consolidate qemu_get_clock and qemu_get_clock_ns

2010-12-17 Thread Jan Kiszka
Both functions have a lot in common, push those bits into a shared
helper.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
---
 qemu-timer.c |   27 +--
 1 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/qemu-timer.c b/qemu-timer.c
index 95814af..abad93b 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -506,11 +506,9 @@ static void qemu_run_timers(QEMUClock *clock)
 }
 }
 
-int64_t qemu_get_clock(QEMUClock *clock)
+static int64_t get_clock_common(QEMUClock *clock)
 {
 switch(clock-type) {
-case QEMU_CLOCK_REALTIME:
-return get_clock() / 100;
 default:
 case QEMU_CLOCK_VIRTUAL:
 if (use_icount) {
@@ -523,20 +521,21 @@ int64_t qemu_get_clock(QEMUClock *clock)
 }
 }
 
+int64_t qemu_get_clock(QEMUClock *clock)
+{
+if (clock-type == QEMU_CLOCK_REALTIME) {
+return get_clock() / 100;
+} else {
+return get_clock_common(clock);
+}
+}
+
 int64_t qemu_get_clock_ns(QEMUClock *clock)
 {
-switch(clock-type) {
-case QEMU_CLOCK_REALTIME:
+if (clock-type == QEMU_CLOCK_REALTIME) {
 return get_clock();
-default:
-case QEMU_CLOCK_VIRTUAL:
-if (use_icount) {
-return cpu_get_icount();
-} else {
-return cpu_get_clock();
-}
-case QEMU_CLOCK_HOST:
-return get_clock_realtime();
+} else {
+return get_clock_common(clock);
 }
 }
 
-- 
1.7.1




Re: [Qemu-devel] [PATCH v2 2/6] qdev: reset qdev along with qdev tree

2010-12-17 Thread Anthony Liguori

On 12/17/2010 08:45 AM, Peter Maydell wrote:

On 17 December 2010 00:24, Anthony Liguorialigu...@linux.vnet.ibm.com  wrote:
   

On 12/16/2010 05:48 PM, Michael S. Tsirkin wrote:
 

Ugh, I keep forgetting about the non-qdev systems.
Maybe it's a good way to finally make everyone to convert? If a system
maintainer can't be bothered to convert to qdev we can declare the
system unsupported :)
   
   

Honestly, I think that's a fair thing to do.
 

I'm guessing that would be a transition/conversion to make for the
0.15 release, right?
   


Yes.

Regards,

Anthony Liguori


-- PMM
   





[Qemu-devel] [PATCH v2 0/2] qcow2 cleanups

2010-12-17 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Hi,

These two patches tries to clean up the qcow2 code a little. First
makes the function names consistent, ie. we shouldn't have qcow_
functions in the qcow2 code. Second tries to add proper errno return
values to qcow2_open().

New in v2: Fix the bdrv_pread() handling as pointed out by Kevin. Fix
error messages, and restore a couple of cases to their unreadable
formatting to avoid formatting changes not directly related to the
qcow_-qcow2_ rename.

Jes

Jes Sorensen (2):
  block/qcow2.c: rename qcow_ functions to qcow2_
  Add proper -errno error return values to qcow2_open()

 block/qcow2-cluster.c  |6 +-
 block/qcow2-snapshot.c |6 +-
 block/qcow2.c  |  248 +++-
 3 files changed, 145 insertions(+), 115 deletions(-)

-- 
1.7.3.3




[Qemu-devel] [PATCH 1/2] block/qcow2.c: rename qcow_ functions to qcow2_

2010-12-17 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

It doesn't really make sense for functions in qcow2.c to be named
qcow_ so convert the names to match correctly.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 block/qcow2-cluster.c  |6 +-
 block/qcow2-snapshot.c |6 +-
 block/qcow2.c  |  190 +---
 3 files changed, 104 insertions(+), 98 deletions(-)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index b040208..6928c63 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -352,8 +352,8 @@ void qcow2_encrypt_sectors(BDRVQcowState *s, int64_t 
sector_num,
 }
 
 
-static int qcow_read(BlockDriverState *bs, int64_t sector_num,
- uint8_t *buf, int nb_sectors)
+static int qcow2_read(BlockDriverState *bs, int64_t sector_num,
+  uint8_t *buf, int nb_sectors)
 {
 BDRVQcowState *s = bs-opaque;
 int ret, index_in_cluster, n, n1;
@@ -419,7 +419,7 @@ static int copy_sectors(BlockDriverState *bs, uint64_t 
start_sect,
 if (n = 0)
 return 0;
 BLKDBG_EVENT(bs-file, BLKDBG_COW_READ);
-ret = qcow_read(bs, start_sect + n_start, s-cluster_data, n);
+ret = qcow2_read(bs, start_sect + n_start, s-cluster_data, n);
 if (ret  0)
 return ret;
 if (s-crypt_method) {
diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
index aacf357..74823a5 100644
--- a/block/qcow2-snapshot.c
+++ b/block/qcow2-snapshot.c
@@ -116,7 +116,7 @@ int qcow2_read_snapshots(BlockDriverState *bs)
 }
 
 /* add at the end of the file a new list of snapshots */
-static int qcow_write_snapshots(BlockDriverState *bs)
+static int qcow2_write_snapshots(BlockDriverState *bs)
 {
 BDRVQcowState *s = bs-opaque;
 QCowSnapshot *sn;
@@ -300,7 +300,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, 
QEMUSnapshotInfo *sn_info)
 s-snapshots = snapshots1;
 s-snapshots[s-nb_snapshots++] = *sn;
 
-if (qcow_write_snapshots(bs)  0)
+if (qcow2_write_snapshots(bs)  0)
 goto fail;
 #ifdef DEBUG_ALLOC
 qcow2_check_refcounts(bs);
@@ -378,7 +378,7 @@ int qcow2_snapshot_delete(BlockDriverState *bs, const char 
*snapshot_id)
 qemu_free(sn-name);
 memmove(sn, sn + 1, (s-nb_snapshots - snapshot_index - 1) * sizeof(*sn));
 s-nb_snapshots--;
-ret = qcow_write_snapshots(bs);
+ret = qcow2_write_snapshots(bs);
 if (ret  0) {
 /* XXX: restore snapshot if error ? */
 return ret;
diff --git a/block/qcow2.c b/block/qcow2.c
index 537c479..4b41190 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -50,10 +50,10 @@ typedef struct {
 uint32_t magic;
 uint32_t len;
 } QCowExtension;
-#define  QCOW_EXT_MAGIC_END 0
-#define  QCOW_EXT_MAGIC_BACKING_FORMAT 0xE2792ACA
+#define  QCOW2_EXT_MAGIC_END 0
+#define  QCOW2_EXT_MAGIC_BACKING_FORMAT 0xE2792ACA
 
-static int qcow_probe(const uint8_t *buf, int buf_size, const char *filename)
+static int qcow2_probe(const uint8_t *buf, int buf_size, const char *filename)
 {
 const QCowHeader *cow_header = (const void *)buf;
 
@@ -73,14 +73,14 @@ static int qcow_probe(const uint8_t *buf, int buf_size, 
const char *filename)
  * unknown magic is skipped (future extension this version knows nothing about)
  * return 0 upon success, non-0 otherwise
  */
-static int qcow_read_extensions(BlockDriverState *bs, uint64_t start_offset,
-uint64_t end_offset)
+static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset,
+ uint64_t end_offset)
 {
 QCowExtension ext;
 uint64_t offset;
 
 #ifdef DEBUG_EXT
-printf(qcow_read_extensions: start=%ld end=%ld\n, start_offset, 
end_offset);
+printf(qcow2_read_extensions: start=%ld end=%ld\n, start_offset, 
end_offset);
 #endif
 offset = start_offset;
 while (offset  end_offset) {
@@ -88,13 +88,13 @@ static int qcow_read_extensions(BlockDriverState *bs, 
uint64_t start_offset,
 #ifdef DEBUG_EXT
 /* Sanity check */
 if (offset  s-cluster_size)
-printf(qcow_handle_extension: suspicious offset %lu\n, offset);
+printf(qcow2_read_extension: suspicious offset %lu\n, offset);
 
 printf(attemting to read extended header in offset %lu\n, offset);
 #endif
 
 if (bdrv_pread(bs-file, offset, ext, sizeof(ext)) != sizeof(ext)) {
-fprintf(stderr, qcow_handle_extension: ERROR: 
+fprintf(stderr, qcow2_read_extension: ERROR: 
 pread fail from offset % PRIu64 \n,
 offset);
 return 1;
@@ -106,10 +106,10 @@ static int qcow_read_extensions(BlockDriverState *bs, 
uint64_t start_offset,
 printf(ext.magic = 0x%x\n, ext.magic);
 #endif
 switch (ext.magic) {
-case QCOW_EXT_MAGIC_END:
+case QCOW2_EXT_MAGIC_END:
 return 0;
 
-case QCOW_EXT_MAGIC_BACKING_FORMAT:
+case QCOW2_EXT_MAGIC_BACKING_FORMAT:
 if 

[Qemu-devel] [RFC][PATCH 2/3] qemu-timer: Introduce warp callback

2010-12-17 Thread Jan Kiszka
QEMU_CLOCK_HOST is based on the system time which may jump backward in
case the admin or NTP adjusts it. RTC emulations and other device models
can suffer in this case as timers will stall for the period the clock
was tuned back.

This adds a detection mechanism that checks on every host clock readout
if the new time is before the last result. In that case callbacks are
fired that any interested device model can register with the clock.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
---
 qemu-timer.c |   52 +++-
 qemu-timer.h |5 +
 2 files changed, 56 insertions(+), 1 deletions(-)

diff --git a/qemu-timer.c b/qemu-timer.c
index abad93b..828e4ad 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -154,9 +154,17 @@ void cpu_disable_ticks(void)
 #define QEMU_CLOCK_VIRTUAL  1
 #define QEMU_CLOCK_HOST 2
 
+struct QEMUClockWarpListener {
+QEMUClockWarpCB cb;
+void *opaque;
+QTAILQ_ENTRY(QEMUClockWarpListener) entry;
+};
+
 struct QEMUClock {
 int type;
 int enabled;
+QTAILQ_HEAD(warp_listeners, QEMUClockWarpListener) warp_listeners;
+int64_t last;
 /* XXX: add frequency */
 };
 
@@ -384,9 +392,15 @@ static QEMUTimer *active_timers[QEMU_NUM_CLOCKS];
 static QEMUClock *qemu_new_clock(int type)
 {
 QEMUClock *clock;
+
 clock = qemu_mallocz(sizeof(QEMUClock));
 clock-type = type;
 clock-enabled = 1;
+QTAILQ_INIT(clock-warp_listeners);
+/* required to detect  report backward jumps */
+if (type == QEMU_CLOCK_HOST) {
+clock-last = get_clock_realtime();
+}
 return clock;
 }
 
@@ -508,6 +522,9 @@ static void qemu_run_timers(QEMUClock *clock)
 
 static int64_t get_clock_common(QEMUClock *clock)
 {
+struct QEMUClockWarpListener *listener;
+int64_t now, last;
+
 switch(clock-type) {
 default:
 case QEMU_CLOCK_VIRTUAL:
@@ -517,7 +534,15 @@ static int64_t get_clock_common(QEMUClock *clock)
 return cpu_get_clock();
 }
 case QEMU_CLOCK_HOST:
-return get_clock_realtime();
+now = get_clock_realtime();
+last = clock-last;
+clock-last = now;
+if (now  last) {
+QTAILQ_FOREACH(listener, clock-warp_listeners, entry) {
+listener-cb(clock, now, listener-opaque);
+}
+}
+return now;
 }
 }
 
@@ -539,6 +564,31 @@ int64_t qemu_get_clock_ns(QEMUClock *clock)
 }
 }
 
+void qemu_register_clock_warp(QEMUClock *clock, QEMUClockWarpCB cb,
+  void *opaque)
+{
+struct QEMUClockWarpListener *listener =
+qemu_malloc(sizeof(struct QEMUClockWarpListener));
+
+listener-cb = cb;
+listener-opaque = opaque;
+QTAILQ_INSERT_TAIL(clock-warp_listeners, listener, entry);
+}
+
+void qemu_unregister_clock_warp(QEMUClock *clock, QEMUClockWarpCB cb,
+void *opaque)
+{
+struct QEMUClockWarpListener *listener;
+
+QTAILQ_FOREACH(listener, clock-warp_listeners, entry) {
+if (listener-cb == cb  listener-opaque == opaque) {
+QTAILQ_REMOVE(clock-warp_listeners, listener, entry);
+qemu_free(listener);
+break;
+}
+}
+}
+
 void init_clocks(void)
 {
 rt_clock = qemu_new_clock(QEMU_CLOCK_REALTIME);
diff --git a/qemu-timer.h b/qemu-timer.h
index 8cd8f83..a7b37da 100644
--- a/qemu-timer.h
+++ b/qemu-timer.h
@@ -13,6 +13,7 @@
 /* timers */
 
 typedef struct QEMUClock QEMUClock;
+typedef void (*QEMUClockWarpCB)(QEMUClock *clock, int64_t now, void *opaque);
 typedef void QEMUTimerCB(void *opaque);
 
 /* The real time clock should be used only for stuff which does not
@@ -36,6 +37,10 @@ extern QEMUClock *host_clock;
 int64_t qemu_get_clock(QEMUClock *clock);
 int64_t qemu_get_clock_ns(QEMUClock *clock);
 void qemu_clock_enable(QEMUClock *clock, int enabled);
+void qemu_register_clock_warp(QEMUClock *clock, QEMUClockWarpCB cb,
+  void *opaque);
+void qemu_unregister_clock_warp(QEMUClock *clock, QEMUClockWarpCB cb,
+void *opaque);
 
 QEMUTimer *qemu_new_timer(QEMUClock *clock, QEMUTimerCB *cb, void *opaque);
 void qemu_free_timer(QEMUTimer *ts);
-- 
1.7.1




[Qemu-devel] [RFC][PATCH 0/3] Let RTC follow backward jumps of host clock immediately

2010-12-17 Thread Jan Kiszka
By default, we base the mc146818 RTC on the host clock (CLOCK_REALTIME).
This works fine if only the frequency of the host clock is tuned (e.g.
by NTP) or if it is set to a future time. However, if the host is tuned
backward, e.g. because NTP obtained the correct time after the guest was
already started or the admin decided to tune the local time, we see an
unpleasant effect in the guest: The RTC will stall for the period the
host clock is set back.

This series tries to address the issue more gracefully. By detecting
those warps and providing a callback mechanism to device models, the
RTC is enabled to update its timers and register content immediately.
Tested successfully with a hwclock readout loop in a Linux guest while
fiddling with the host time.

Note that if this kind of RTC adjustment is not wanted, the user is
still free to decouple the RTC from the host clock and base it on the
VM clock - just like before.

Jan Kiszka (3):
  qemu-timer: Consolidate qemu_get_clock and qemu_get_clock_ns
  qemu-timer: Introduce warp callback
  mc146818rtc: Handle host clock warps

 hw/mc146818rtc.c |   17 
 qemu-timer.c |   77 --
 qemu-timer.h |5 +++
 3 files changed, 85 insertions(+), 14 deletions(-)




Re: [Qemu-devel] [PATCH] spice: add chardev (v3)

2010-12-17 Thread Anthony Liguori

On 12/17/2010 07:39 AM, Alon Levy wrote:

Adding a chardev backend for spice, for usage by spice vdagent in
conjunction with a properly named virtio-serial device.

Example usage:
  qemu -device virtio-serial -chardev spicevmc,name=vdagent,id=vdagent -devic

This is equivalent to the old:
  qemu -device virtio-serial -device spicevmc,subtype=vdagent

longer to write, but generated by libvirt, and requires one less device.

v1-v3 changes: (v2 had a wrong commit message)
  * removed spice-qemu-char.h, folded into ui/qemu-spice.h
  * removed dead IOCTL code
  * removed comment
  * removed ifdef CONFIG_SPICE from qemu-config.c and qemu-options.hx help.
   


What doe this channel do?

I really don't feel comfortable with this.  This is not connecting QEMU 
to an existing interface that happens to fit our model.


This is clearly a library that provides thin wrappers around internal 
QEMU interfaces to implement code that belongs in QEMU outside of QEMU.


It's essentially a static plugin.  It's the same problem with QXL.  I 
don't think we should be in the business of having thin shims to 
external libraries when the only reason to have the external library is 
to keep code out of QEMU.


Regards,

Anthony Liguori


---
  Makefile.objs |2 +-
  qemu-char.c   |4 +
  qemu-config.c |6 ++
  qemu-options.hx   |   16 -
  spice-qemu-char.c |  185 +
  ui/qemu-spice.h   |3 +
  6 files changed, 214 insertions(+), 2 deletions(-)
  create mode 100644 spice-qemu-char.c

diff --git a/Makefile.objs b/Makefile.objs
index cebb945..320b2a9 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -102,7 +102,7 @@ common-obj-$(CONFIG_BRLAPI) += baum.o
  common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
  common-obj-$(CONFIG_WIN32) += version.o

-common-obj-$(CONFIG_SPICE) += ui/spice-core.o ui/spice-input.o 
ui/spice-display.o
+common-obj-$(CONFIG_SPICE) += ui/spice-core.o ui/spice-input.o 
ui/spice-display.o spice-qemu-char.o

  audio-obj-y = audio.o noaudio.o wavaudio.o mixeng.o
  audio-obj-$(CONFIG_SDL) += sdlaudio.o
diff --git a/qemu-char.c b/qemu-char.c
index edc9ad6..acc7130 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -97,6 +97,7 @@
  #endif

  #include qemu_socket.h
+#include ui/qemu-spice.h

  #define READ_BUF_LEN 4096

@@ -2495,6 +2496,9 @@ static const struct {
  || defined(__FreeBSD_kernel__)
  { .name = parport,   .open = qemu_chr_open_pp },
  #endif
+#ifdef CONFIG_SPICE
+{ .name = spicevmc, .open = qemu_chr_open_spice },
+#endif
  };

  CharDriverState *qemu_chr_open_opts(QemuOpts *opts,
diff --git a/qemu-config.c b/qemu-config.c
index 965fa46..323d3c2 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -146,6 +146,12 @@ static QemuOptsList qemu_chardev_opts = {
  },{
  .name = signal,
  .type = QEMU_OPT_BOOL,
+},{
+.name = name,
+.type = QEMU_OPT_STRING,
+},{
+.name = debug,
+.type = QEMU_OPT_NUMBER,
  },
  { /* end of list */ }
  },
diff --git a/qemu-options.hx b/qemu-options.hx
index 4d99a58..5c13f0f 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1357,6 +1357,9 @@ DEF(chardev, HAS_ARG, QEMU_OPTION_chardev,
  #if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
  -chardev parport,id=id,path=path[,mux=on|off]\n
  #endif
+#if defined(CONFIG_SPICE)
+-chardev spicevmc,id=id,debug=debug,name=name\n
+#endif
  , QEMU_ARCH_ALL
  )

@@ -1381,7 +1384,8 @@ Backend is one of:
  @option{stdio},
  @option{braille},
  @option{tty},
-...@option{parport}.
+...@option{parport}
+...@option{spicevmc}.
  The specific backend will determine the applicable options.

  All devices must have an id, which can be any string up to 127 characters 
long.
@@ -1557,6 +1561,16 @@ Connect to a local parallel port.
  @option{path} specifies the path to the parallel port device. @option{path} is
  required.

+#if defined(CONFIG_SPICE)
+...@item -chardev spicevmc ,i...@var{id} ,deb...@var{debug}, na...@var{name}
+
+...@option{debug} debug level for spicevmc
+
+...@option{name} name of spice channel to connect to
+
+Connect to a spice virtual machine channel, such as vdiport.
+#endif
+
  @end table
  ETEXI

diff --git a/spice-qemu-char.c b/spice-qemu-char.c
new file mode 100644
index 000..0ffa674
--- /dev/null
+++ b/spice-qemu-char.c
@@ -0,0 +1,185 @@
+#include config-host.h
+#include ui/qemu-spice.h
+#includespice.h
+#includespice-experimental.h
+
+#include osdep.h
+
+#define dprintf(_scd, _level, _fmt, ...)\
+do {\
+static unsigned __dprintf_counter = 0;  \
+if (_scd-debug= _level) {\
+fprintf(stderr, scd: %3d:  _fmt, ++__dprintf_counter, ## 
__VA_ARGS__);\
+}  

[Qemu-devel] [PATCH 2/2] Add proper -errno error return values to qcow2_open()

2010-12-17 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

In addition this adds missing braces to the function to be consistent
with the coding style.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 block/qcow2.c |   60 +++-
 1 files changed, 42 insertions(+), 18 deletions(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index 4b41190..b6b094c 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -140,12 +140,14 @@ static int qcow2_read_extensions(BlockDriverState *bs, 
uint64_t start_offset,
 static int qcow2_open(BlockDriverState *bs, int flags)
 {
 BDRVQcowState *s = bs-opaque;
-int len, i;
+int len, i, ret = 0;
 QCowHeader header;
 uint64_t ext_end;
 
-if (bdrv_pread(bs-file, 0, header, sizeof(header)) != sizeof(header))
+ret = bdrv_pread(bs-file, 0, header, sizeof(header));
+if (ret  0) {
 goto fail;
+}
 be32_to_cpus(header.magic);
 be32_to_cpus(header.version);
 be64_to_cpus(header.backing_file_offset);
@@ -160,16 +162,23 @@ static int qcow2_open(BlockDriverState *bs, int flags)
 be64_to_cpus(header.snapshots_offset);
 be32_to_cpus(header.nb_snapshots);
 
-if (header.magic != QCOW_MAGIC || header.version != QCOW_VERSION)
+if (header.magic != QCOW_MAGIC || header.version != QCOW_VERSION) {
+ret = -EINVAL;
 goto fail;
+}
 if (header.cluster_bits  MIN_CLUSTER_BITS ||
-header.cluster_bits  MAX_CLUSTER_BITS)
+header.cluster_bits  MAX_CLUSTER_BITS) {
+ret = -EINVAL;
 goto fail;
-if (header.crypt_method  QCOW_CRYPT_AES)
+}
+if (header.crypt_method  QCOW_CRYPT_AES) {
+ret = -EINVAL;
 goto fail;
+}
 s-crypt_method_header = header.crypt_method;
-if (s-crypt_method_header)
+if (s-crypt_method_header) {
 bs-encrypted = 1;
+}
 s-cluster_bits = header.cluster_bits;
 s-cluster_size = 1  s-cluster_bits;
 s-cluster_sectors = 1  (s-cluster_bits - 9);
@@ -191,15 +200,19 @@ static int qcow2_open(BlockDriverState *bs, int flags)
 s-l1_vm_state_index = size_to_l1(s, header.size);
 /* the L1 table must contain at least enough entries to put
header.size bytes */
-if (s-l1_size  s-l1_vm_state_index)
+if (s-l1_size  s-l1_vm_state_index) {
+ret = -EINVAL;
 goto fail;
+}
 s-l1_table_offset = header.l1_table_offset;
 if (s-l1_size  0) {
 s-l1_table = qemu_mallocz(
 align_offset(s-l1_size * sizeof(uint64_t), 512));
-if (bdrv_pread(bs-file, s-l1_table_offset, s-l1_table, s-l1_size * 
sizeof(uint64_t)) !=
-s-l1_size * sizeof(uint64_t))
+ret = bdrv_pread(bs-file, s-l1_table_offset, s-l1_table,
+ s-l1_size * sizeof(uint64_t));
+if (ret  0) {
 goto fail;
+}
 for(i = 0;i  s-l1_size; i++) {
 be64_to_cpus(s-l1_table[i]);
 }
@@ -212,35 +225,46 @@ static int qcow2_open(BlockDriverState *bs, int flags)
   + 512);
 s-cluster_cache_offset = -1;
 
-if (qcow2_refcount_init(bs)  0)
+ret = qcow2_refcount_init(bs);
+if (ret != 0) {
 goto fail;
+}
 
 QLIST_INIT(s-cluster_allocs);
 
 /* read qcow2 extensions */
-if (header.backing_file_offset)
+if (header.backing_file_offset) {
 ext_end = header.backing_file_offset;
-else
+} else {
 ext_end = s-cluster_size;
-if (qcow2_read_extensions(bs, sizeof(header), ext_end))
+}
+if (qcow2_read_extensions(bs, sizeof(header), ext_end)) {
+ret = -EINVAL;
 goto fail;
+}
 
 /* read the backing file name */
 if (header.backing_file_offset != 0) {
 len = header.backing_file_size;
-if (len  1023)
+if (len  1023) {
 len = 1023;
-if (bdrv_pread(bs-file, header.backing_file_offset, bs-backing_file, 
len) != len)
+}
+ret = bdrv_pread(bs-file, header.backing_file_offset,
+ bs-backing_file, len);
+if (ret  0) {
 goto fail;
+}
 bs-backing_file[len] = '\0';
 }
-if (qcow2_read_snapshots(bs)  0)
+if (qcow2_read_snapshots(bs)  0) {
+ret = -EINVAL;
 goto fail;
+}
 
 #ifdef DEBUG_ALLOC
 qcow2_check_refcounts(bs);
 #endif
-return 0;
+return ret;
 
  fail:
 qcow2_free_snapshots(bs);
@@ -249,7 +273,7 @@ static int qcow2_open(BlockDriverState *bs, int flags)
 qemu_free(s-l2_cache);
 qemu_free(s-cluster_cache);
 qemu_free(s-cluster_data);
-return -1;
+return ret;
 }
 
 static int qcow2_set_key(BlockDriverState *bs, const char *key)
-- 
1.7.3.3




[Qemu-devel] Re: [PATCH v2 0/2] qcow2 cleanups

2010-12-17 Thread Kevin Wolf
Am 17.12.2010 16:02, schrieb jes.soren...@redhat.com:
 From: Jes Sorensen jes.soren...@redhat.com
 
 Hi,
 
 These two patches tries to clean up the qcow2 code a little. First
 makes the function names consistent, ie. we shouldn't have qcow_
 functions in the qcow2 code. Second tries to add proper errno return
 values to qcow2_open().
 
 New in v2: Fix the bdrv_pread() handling as pointed out by Kevin. Fix
 error messages, and restore a couple of cases to their unreadable
 formatting to avoid formatting changes not directly related to the
 qcow_-qcow2_ rename.
 
 Jes
 
 Jes Sorensen (2):
   block/qcow2.c: rename qcow_ functions to qcow2_
   Add proper -errno error return values to qcow2_open()
 
  block/qcow2-cluster.c  |6 +-
  block/qcow2-snapshot.c |6 +-
  block/qcow2.c  |  248 
 +++-
  3 files changed, 145 insertions(+), 115 deletions(-)

Thanks, applied to the block branch.

Kevin



Re: [Qemu-devel] Re: [PATCH v3] qemu, qmp: convert do_inject_nmi() to QObject, QError

2010-12-17 Thread Avi Kivity

On 12/17/2010 01:22 PM, Luiz Capitulino wrote:


  I think Avi's suggest is better, and I will use
  inject-nmi (without cpu-index argument) to send NMI to all cpus,
  like physical GUI. If some one want to send NMI to a set of cpus,
  he can use inject-nmi multiple times.

His suggestion is to drop _all_ arguments, right Avi?


Yes.

--
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.




[Qemu-devel] [PATCH V2] softfloat: Rename float*_is_nan() functions to float*_is_quiet_nan()

2010-12-17 Thread Peter Maydell
The softfloat functions float*_is_nan() were badly misnamed,
because they return true only for quiet NaNs, not for all NaNs.
Rename them to float*_is_quiet_nan() to more accurately reflect
what they do.

This change was produced by:
 perl -p -i -e 's/_is_nan/_is_quiet_nan/g' $(git grep -l is_nan)
(with the results manually checked.)

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
Reviewed-by: Nathan Froyd froy...@codesourcery.com
Acked-by: Edgar E. Iglesias edgar.igles...@gmail.com
---
This is just a refresh of the first patch against current master;
the only difference is that the addition of float32_maybe_silence_nan()
meant that the context for the hunk in softfloat.h changing the
prototypes is slightly different. I've therefore retained the
reviewed-by/acked-by lines from the first time around.

Can this patch be applied? (There are more ARM/softfloat patches
in my queue which will break it again otherwise...)

 fpu/softfloat-native.c|6 ++--
 fpu/softfloat-native.h|6 ++--
 fpu/softfloat-specialize.h|   24 +++---
 fpu/softfloat.h   |8 ++--
 linux-user/arm/nwfpe/fpa11_cprt.c |   14 
 target-alpha/op_helper.c  |2 +-
 target-m68k/helper.c  |6 ++--
 target-microblaze/op_helper.c |2 +-
 target-mips/op_helper.c   |8 ++--
 target-ppc/op_helper.c|   58 ++--
 10 files changed, 67 insertions(+), 67 deletions(-)

diff --git a/fpu/softfloat-native.c b/fpu/softfloat-native.c
index 049c830..008bb53 100644
--- a/fpu/softfloat-native.c
+++ b/fpu/softfloat-native.c
@@ -254,7 +254,7 @@ int float32_is_signaling_nan( float32 a1)
 return ( ( ( a22 )  0x1FF ) == 0x1FE )  ( a  0x003F );
 }
 
-int float32_is_nan( float32 a1 )
+int float32_is_quiet_nan( float32 a1 )
 {
 float32u u;
 uint64_t a;
@@ -411,7 +411,7 @@ int float64_is_signaling_nan( float64 a1)
 
 }
 
-int float64_is_nan( float64 a1 )
+int float64_is_quiet_nan( float64 a1 )
 {
 float64u u;
 uint64_t a;
@@ -504,7 +504,7 @@ int floatx80_is_signaling_nan( floatx80 a1)
  ( u.i.low == aLow );
 }
 
-int floatx80_is_nan( floatx80 a1 )
+int floatx80_is_quiet_nan( floatx80 a1 )
 {
 floatx80u u;
 u.f = a1;
diff --git a/fpu/softfloat-native.h b/fpu/softfloat-native.h
index 6da0bcb..80b5f28 100644
--- a/fpu/softfloat-native.h
+++ b/fpu/softfloat-native.h
@@ -242,7 +242,7 @@ INLINE int float32_unordered( float32 a, float32 b 
STATUS_PARAM)
 int float32_compare( float32, float32 STATUS_PARAM );
 int float32_compare_quiet( float32, float32 STATUS_PARAM );
 int float32_is_signaling_nan( float32 );
-int float32_is_nan( float32 );
+int float32_is_quiet_nan( float32 );
 
 INLINE float32 float32_abs(float32 a)
 {
@@ -351,7 +351,7 @@ INLINE int float64_unordered( float64 a, float64 b 
STATUS_PARAM)
 int float64_compare( float64, float64 STATUS_PARAM );
 int float64_compare_quiet( float64, float64 STATUS_PARAM );
 int float64_is_signaling_nan( float64 );
-int float64_is_nan( float64 );
+int float64_is_quiet_nan( float64 );
 
 INLINE float64 float64_abs(float64 a)
 {
@@ -455,7 +455,7 @@ INLINE int floatx80_unordered( floatx80 a, floatx80 b 
STATUS_PARAM)
 int floatx80_compare( floatx80, floatx80 STATUS_PARAM );
 int floatx80_compare_quiet( floatx80, floatx80 STATUS_PARAM );
 int floatx80_is_signaling_nan( floatx80 );
-int floatx80_is_nan( floatx80 );
+int floatx80_is_quiet_nan( floatx80 );
 
 INLINE floatx80 floatx80_abs(floatx80 a)
 {
diff --git a/fpu/softfloat-specialize.h b/fpu/softfloat-specialize.h
index 0746878..f382f7a 100644
--- a/fpu/softfloat-specialize.h
+++ b/fpu/softfloat-specialize.h
@@ -76,7 +76,7 @@ typedef struct {
 | NaN; otherwise returns 0.
 **/
 
-int float32_is_nan( float32 a_ )
+int float32_is_quiet_nan( float32 a_ )
 {
 uint32_t a = float32_val(a_);
 #if SNAN_BIT_IS_ONE
@@ -166,9 +166,9 @@ static float32 propagateFloat32NaN( float32 a, float32 b 
STATUS_PARAM)
 if ( STATUS(default_nan_mode) )
 return float32_default_nan;
 
-aIsNaN = float32_is_nan( a );
+aIsNaN = float32_is_quiet_nan( a );
 aIsSignalingNaN = float32_is_signaling_nan( a );
-bIsNaN = float32_is_nan( b );
+bIsNaN = float32_is_quiet_nan( b );
 bIsSignalingNaN = float32_is_signaling_nan( b );
 av = float32_val(a);
 bv = float32_val(b);
@@ -223,7 +223,7 @@ static float32 propagateFloat32NaN( float32 a, float32 b 
STATUS_PARAM)
 | NaN; otherwise returns 0.
 **/
 
-int float64_is_nan( float64 a_ )
+int float64_is_quiet_nan( float64 a_ )
 {
 bits64 a = float64_val(a_);
 #if SNAN_BIT_IS_ONE
@@ -320,9 +320,9 @@ static float64 propagateFloat64NaN( float64 a, float64 b 
STATUS_PARAM)
 if ( STATUS(default_nan_mode) )
 return float64_default_nan;
 
-aIsNaN = float64_is_nan( a );
+

[Qemu-devel] [PATCH 2/3] docs: Describe zero data clusters in QED specification

2010-12-17 Thread Stefan Hajnoczi
Zero data clusters are a space-efficient way of storing zeroed regions
of the image.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 docs/specs/qed_spec.txt |8 
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/docs/specs/qed_spec.txt b/docs/specs/qed_spec.txt
index 1d5fa87..7982e05 100644
--- a/docs/specs/qed_spec.txt
+++ b/docs/specs/qed_spec.txt
@@ -89,6 +89,7 @@ L1, L2, and data cluster offsets must be aligned to 
header.cluster_size.  The fo
 
 ===Data cluster offsets===
 * 0 - unallocated.  The data cluster is not yet allocated.
+* 1 - zero.  The data cluster contents are all zeroes and no cluster is 
allocated.
 
 Future format extensions may wish to store per-offset information.  The least 
significant 12 bits of an offset are reserved for this purpose and must be set 
to zero.  Image files with cluster_size  2^12 will have more unused bits which 
should also be zeroed.
 
@@ -97,6 +98,13 @@ Reads to an unallocated area of the image file access the 
backing file.  If ther
 
 Writes to an unallocated area cause a new data clusters to be allocated, and a 
new L2 table if that is also unallocated.  The new data cluster is populated 
with data from the backing file (or zeroes if no backing file) and the data 
being written.
 
+===Zero data clusters===
+Zero data clusters are a space-efficient way of storing zeroed regions of the 
image.
+
+Reads to a zero data cluster produce zeroes.  Note that the difference between 
an unallocated and a zero data cluster is that zero data clusters stop the 
reading of contents from the backing file.
+
+Writes to a zero data cluster cause a new data cluster to be allocated.  The 
new data cluster is populated with zeroes and the data being written.
+
 ===Logical offset translation===
 Logical offsets are translated into cluster offsets as follows:
 
-- 
1.7.2.3




[Qemu-devel] [PATCH 0/3] qed: Add support for zero clusters

2010-12-17 Thread Stefan Hajnoczi
This patch series adds zero data clusters to QED.  Clusters can be marked as
zero clusters to store zeroed regions in a space-efficient way.  The patch
never actually creates new zero clusters but includes the I/O path support code
to handle them if they are used by an image file.

Image streaming and copy-on-read take advantage of zero data clusters to avoid
expanding out zeroes from the backing file.  Those features are separate
patches that will come later but I'm presenting this patch now so we can get
this core QED image format feature in before doing the first QEMU release
containing QED.

The first patch fixes up an issue with the QED merge where '^' characters were
dropped from the QED specification.

The last two patches document and implement zero clusters, which were
originally implemented by Anthony Liguori aligu...@us.ibm.com.




[Qemu-devel] [PATCH 1/3] docs: Fix missing carets in QED specification

2010-12-17 Thread Stefan Hajnoczi
For some reason the carets ('^') in the QED specification disappeared.
This patch puts them back.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 docs/specs/qed_spec.txt |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/docs/specs/qed_spec.txt b/docs/specs/qed_spec.txt
index 446b5a2..1d5fa87 100644
--- a/docs/specs/qed_spec.txt
+++ b/docs/specs/qed_spec.txt
@@ -33,7 +33,7 @@ All fields are little-endian.
  }
 
 Field descriptions:
-* ''cluster_size'' must be a power of 2 in range [212, 226].
+* ''cluster_size'' must be a power of 2 in range [2^12, 2^26].
 * ''table_size'' must be a power of 2 in range [1, 16].
 * ''header_size'' is the number of clusters used by the header and any 
additional information stored before regular clusters.
 * ''features'', ''compat_features'', and ''autoclear_features'' are file 
format extension bitmaps.  They work as follows:
@@ -90,7 +90,7 @@ L1, L2, and data cluster offsets must be aligned to 
header.cluster_size.  The fo
 ===Data cluster offsets===
 * 0 - unallocated.  The data cluster is not yet allocated.
 
-Future format extensions may wish to store per-offset information.  The least 
significant 12 bits of an offset are reserved for this purpose and must be set 
to zero.  Image files with cluster_size  212 will have more unused bits which 
should also be zeroed.
+Future format extensions may wish to store per-offset information.  The least 
significant 12 bits of an offset are reserved for this purpose and must be set 
to zero.  Image files with cluster_size  2^12 will have more unused bits which 
should also be zeroed.
 
 ===Unallocated L2 tables and data clusters===
 Reads to an unallocated area of the image file access the backing file.  If 
there is no backing file, then zeroes are produced.  The backing file may be 
smaller than the image file and reads of unallocated areas beyond the end of 
the backing file produce zeroes.
-- 
1.7.2.3




[Qemu-devel] Re: [PATCH 11/21] ioport: insert event_tap_ioport() to ioport_write().

2010-12-17 Thread Yoshiaki Tamura
2010/12/17 Stefan Hajnoczi stefa...@gmail.com:
 On Thu, Dec 16, 2010 at 9:50 AM, Yoshiaki Tamura
 tamura.yoshi...@lab.ntt.co.jp wrote:
 2010/12/16 Michael S. Tsirkin m...@redhat.com:
 On Thu, Dec 16, 2010 at 04:37:41PM +0900, Yoshiaki Tamura wrote:
 2010/11/28 Yoshiaki Tamura tamura.yoshi...@lab.ntt.co.jp:
  2010/11/28 Michael S. Tsirkin m...@redhat.com:
  On Thu, Nov 25, 2010 at 03:06:50PM +0900, Yoshiaki Tamura wrote:
  Record ioport event to replay it upon failover.
 
  Signed-off-by: Yoshiaki Tamura tamura.yoshi...@lab.ntt.co.jp
 
  Interesting. This will have to be extended to support ioeventfd.
  Since each eventfd is really just a binary trigger
  it should be enough to read out the fd state.
 
  Haven't thought about eventfd yet.  Will try doing it in the next
  spin.

 Hi Michael,

 I looked into eventfd and realized it's only used with vhost now.

 There are patches on list to use it for block/userspace net.

 Thanks.  Now I understand.
 In that case, inserting an even-tap function to the following code
 should be appropriate?

 int event_notifier_test_and_clear(EventNotifier *e)
 {
    uint64_t value;
    int r = read(e-fd, value, sizeof(value));
    return r == sizeof(value);
 }


  However, I
 believe vhost bypass the net layer in qemu, and there is no way for Kemari 
 to
 detect the outputs.  To me, it doesn't make sense to extend this patch to
 support eventfd...

 Here is the userspace ioeventfd patch series:
 http://www.mail-archive.com/qemu-devel@nongnu.org/msg49208.html

 Instead of switching to QEMU userspace to handle the virtqueue kick
 pio write, we signal the eventfd inside the kernel and resume guest
 code execution.  The I/O thread can then process the virtqueue kick in
 parallel to guest code execution.

 I think this can still be tied into Kemari.  If you are switching to a
 pure net/block-layer event tap instead of pio/mmio, then I think it
 should just work.

That should take a while until we solve how to set correct
callbacks to the secondary upon failover.  BTW, do you have a
plan to move the eventfd framework to the upper layer as
pio/mmio.  Not only Kemari works for free, other emulators should
be able to benefit from it.

 For vhost it would be more difficult to integrate with Kemari.

At this point, it's impossible.  As Michael said, I should
prevent starting Kemari when vhost=on.

Yoshi


 Stefan
 --
 To unsubscribe from this list: send the line unsubscribe kvm in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html




Re: [Qemu-devel] [PATCH V2] softfloat: Rename float*_is_nan() functions to float*_is_quiet_nan()

2010-12-17 Thread Andreas Färber

Hello Peter,

Am 17.12.2010 um 16:56 schrieb Peter Maydell:


The softfloat functions float*_is_nan() were badly misnamed,
because they return true only for quiet NaNs, not for all NaNs.
Rename them to float*_is_quiet_nan() to more accurately reflect
what they do.

This change was produced by:
perl -p -i -e 's/_is_nan/_is_quiet_nan/g' $(git grep -l is_nan)
(with the results manually checked.)

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
Reviewed-by: Nathan Froyd froy...@codesourcery.com
Acked-by: Edgar E. Iglesias edgar.igles...@gmail.com
---
This is just a refresh of the first patch against current master;
the only difference is that the addition of  
float32_maybe_silence_nan()

meant that the context for the hunk in softfloat.h changing the
prototypes is slightly different. I've therefore retained the
reviewed-by/acked-by lines from the first time around.

Can this patch be applied? (There are more ARM/softfloat patches
in my queue which will break it again otherwise...)


If we're engaging into refactoring the softfloat library, I still have  
a large'ish patch lying around to fix signature mismatches between  
header and sources wrt to integer arguments and migrating to POSIX  
integer types (BeOS/Haiku system headers define int32 etc.  
differently). Browsing through your patch it shouldn't conflict, but I  
guess it'll be best to have it go through your queue to avoid troubles.


Regards,
Andreas



[Qemu-devel] Re: [PATCH 05/21] virtio: modify save/load handler to handle inuse varialble.

2010-12-17 Thread Yoshiaki Tamura
2010/12/17 Yoshiaki Tamura tamura.yoshi...@lab.ntt.co.jp:
 2010/12/16 Michael S. Tsirkin m...@redhat.com:
 On Thu, Dec 16, 2010 at 11:28:46PM +0900, Yoshiaki Tamura wrote:
 2010/12/16 Michael S. Tsirkin m...@redhat.com:
  On Thu, Dec 16, 2010 at 04:36:16PM +0900, Yoshiaki Tamura wrote:
  2010/12/3 Yoshiaki Tamura tamura.yoshi...@lab.ntt.co.jp:
   2010/12/2 Michael S. Tsirkin m...@redhat.com:
   On Wed, Dec 01, 2010 at 05:03:43PM +0900, Yoshiaki Tamura wrote:
   2010/11/28 Michael S. Tsirkin m...@redhat.com:
On Sun, Nov 28, 2010 at 08:27:58PM +0900, Yoshiaki Tamura wrote:
2010/11/28 Michael S. Tsirkin m...@redhat.com:
 On Thu, Nov 25, 2010 at 03:06:44PM +0900, Yoshiaki Tamura wrote:
 Modify inuse type to uint16_t, let save/load to handle, and 
 revert
 last_avail_idx with inuse if there are outstanding emulation.

 Signed-off-by: Yoshiaki Tamura tamura.yoshi...@lab.ntt.co.jp

 This changes migration format, so it will break compatibility 
 with
 existing drivers. More generally, I think migrating internal
 state that is not guest visible is always a mistake
 as it ties migration format to an internal implementation
 (yes, I know we do this sometimes, but we should at least
 try not to add such cases).  I think the right thing to do in 
 this case
 is to flush outstanding
 work when vm is stopped.  Then, we are guaranteed that inuse is 
 0.
 I sent patches that do this for virtio net and block.
   
Could you give me the link of your patches?  I'd like to test
whether they work with Kemari upon failover.  If they do, I'm
happy to drop this patch.
   
Yoshi
   
Look for this:
stable migration image on a stopped vm
sent on:
Wed, 24 Nov 2010 17:52:49 +0200
  
   Thanks for the info.
  
   However, The patch series above didn't solve the issue.  In
   case of Kemari, inuse is mostly  0 because it queues the
   output, and while last_avail_idx gets incremented
   immediately, not sending inuse makes the state inconsistent
   between Primary and Secondary.
  
   Hmm. Can we simply avoid incrementing last_avail_idx?
  
   I think we can calculate or prepare an internal last_avail_idx,
   and update the external when inuse is decremented.  I'll try
   whether it work w/ w/o Kemari.
 
  Hi Michael,
 
  Could you please take a look at the following patch?
 
  Which version is this against?

 Oops.  It should be very old.
 67f895bfe69f323b427b284430b6219c8a62e8d4

  commit 36ee7910059e6b236fe9467a609f5b4aed866912
  Author: Yoshiaki Tamura tamura.yoshi...@lab.ntt.co.jp
  Date:   Thu Dec 16 14:50:54 2010 +0900
 
      virtio: update last_avail_idx when inuse is decreased.
 
      Signed-off-by: Yoshiaki Tamura tamura.yoshi...@lab.ntt.co.jp
 
  It would be better to have a commit description explaining why a change
  is made, and why it is correct, not just repeating what can be seen from
  the diff anyway.

 Sorry for being lazy here.

  diff --git a/hw/virtio.c b/hw/virtio.c
  index c8a0fc6..6688c02 100644
  --- a/hw/virtio.c
  +++ b/hw/virtio.c
  @@ -237,6 +237,7 @@ void virtqueue_flush(VirtQueue *vq, unsigned int 
  count)
       wmb();
       trace_virtqueue_flush(vq, count);
       vring_used_idx_increment(vq, count);
  +    vq-last_avail_idx += count;
       vq-inuse -= count;
   }
 
  @@ -385,7 +386,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement 
  *elem)
       unsigned int i, head, max;
       target_phys_addr_t desc_pa = vq-vring.desc;
 
  -    if (!virtqueue_num_heads(vq, vq-last_avail_idx))
  +    if (!virtqueue_num_heads(vq, vq-last_avail_idx + vq-inuse))
           return 0;
 
       /* When we start there are none of either input nor output. */
  @@ -393,7 +394,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement 
  *elem)
 
       max = vq-vring.num;
 
  -    i = head = virtqueue_get_head(vq, vq-last_avail_idx++);
  +    i = head = virtqueue_get_head(vq, vq-last_avail_idx + vq-inuse);
 
       if (vring_desc_flags(desc_pa, i)  VRING_DESC_F_INDIRECT) {
           if (vring_desc_len(desc_pa, i) % sizeof(VRingDesc)) {
 
 
  Hmm, will virtio_queue_empty be wrong now? What about 
  virtqueue_avail_bytes?

 I think there are two problems.

 1. When to update last_avail_idx.
 2. The ordering issue you're mentioning below.

 The patch above is only trying to address 1 because last time you
 mentioned that modifying last_avail_idx upon save may break the
 guest, which I agree.  If virtio_queue_empty and
 virtqueue_avail_bytes are only used internally, meaning invisible
 to the guest, I guess the approach above can be applied too.

 So IMHO 2 is the real issue. This is what was problematic
 with the save patch, otherwise of course changes in save
 are better than changes all over the codebase.

 All right.  Then let's focus on 2 first.

  Previous patch version sure looked simpler, and this seems functionally
  equivalent, so my question still stands: here it is rephrased in a
  different 

Re: [Qemu-devel] [PATCH V2] softfloat: Rename float*_is_nan() functions to float*_is_quiet_nan()

2010-12-17 Thread Peter Maydell
On 17 December 2010 16:19, Andreas Färber andreas.faer...@web.de wrote:
 Can this patch be applied? (There are more ARM/softfloat patches
 in my queue which will break it again otherwise...)

 If we're engaging into refactoring the softfloat library, I still have a
 large'ish patch lying around to fix signature mismatches between header and
 sources wrt to integer arguments and migrating to POSIX integer types
 (BeOS/Haiku system headers define int32 etc. differently). Browsing through
 your patch it shouldn't conflict, but I guess it'll be best to have it go
 through your queue to avoid troubles.

I wasn't planning to put this patch into my ARM fixes queue to be
pulled directly, because it's a bit wider in scope than fixing things
for ARM targets. (Hence the can this be applied? request :-))

On the types issue, at the moment softfloat uses int32 etc for
a handy type holding at least 32 bits, and bits32 for exactly
32 bits. So I guess changing the 'bits' types to the POSIX int32_t
and friends would be straightforward enough, but what does your
patch do with the int32 types?

-- PMM



[Qemu-devel] [PATCH] softfloat: Fix function signature mismatches by using POSIX integer types

2010-12-17 Thread Andreas Färber
Don't reinvent C99 types like uint8_t by typedef'ing uint8 etc.
On BeOS and Haiku, system headers {be,os}/support/SupportDefs.h
do define [u]int{8,16,32,64}, but they define [u]int32 as long,
so assumptions that int32 and int can be used interchangeably
must be avoided. Inspired by mmlr's original port to Haiku.

Fix stray occurrences of softfloat-internal types outside fpu/.

Cc: Michael Lotz m...@mlotz.ch
Cc: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Andreas Färber andreas.faer...@web.de
---
 Available for testing from:
 git://repo.or.cz/qemu/afaerber.git softfloat
 
 fpu/softfloat-macros.h |   44 +++---
 fpu/softfloat-specialize.h |2 +-
 fpu/softfloat.c|  352 ++--
 fpu/softfloat.h|   55 +++-
 hw/apic.c  |2 +-
 hw/wdt_ib700.c |2 +-
 target-i386/cpu.h  |8 +-
 7 files changed, 226 insertions(+), 239 deletions(-)

diff --git a/fpu/softfloat-macros.h b/fpu/softfloat-macros.h
index 7838228..d635779 100644
--- a/fpu/softfloat-macros.h
+++ b/fpu/softfloat-macros.h
@@ -39,7 +39,7 @@ these four paragraphs for those parts of this code that are 
retained.
 | The result is stored in the location pointed to by `zPtr'.
 **/
 
-INLINE void shift32RightJamming( bits32 a, int16 count, bits32 *zPtr )
+INLINE void shift32RightJamming( bits32 a, int16_t count, bits32 *zPtr )
 {
 bits32 z;
 
@@ -65,7 +65,7 @@ INLINE void shift32RightJamming( bits32 a, int16 count, 
bits32 *zPtr )
 | The result is stored in the location pointed to by `zPtr'.
 **/
 
-INLINE void shift64RightJamming( bits64 a, int16 count, bits64 *zPtr )
+INLINE void shift64RightJamming( bits64 a, int16_t count, bits64 *zPtr )
 {
 bits64 z;
 
@@ -101,10 +101,10 @@ INLINE void shift64RightJamming( bits64 a, int16 count, 
bits64 *zPtr )
 
 INLINE void
  shift64ExtraRightJamming(
- bits64 a0, bits64 a1, int16 count, bits64 *z0Ptr, bits64 *z1Ptr )
+ bits64 a0, bits64 a1, int16_t count, bits64 *z0Ptr, bits64 *z1Ptr )
 {
 bits64 z0, z1;
-int8 negCount = ( - count )  63;
+int8_t negCount = ( - count )  63;
 
 if ( count == 0 ) {
 z1 = a1;
@@ -138,10 +138,10 @@ INLINE void
 
 INLINE void
  shift128Right(
- bits64 a0, bits64 a1, int16 count, bits64 *z0Ptr, bits64 *z1Ptr )
+ bits64 a0, bits64 a1, int16_t count, bits64 *z0Ptr, bits64 *z1Ptr )
 {
 bits64 z0, z1;
-int8 negCount = ( - count )  63;
+int8_t negCount = ( - count )  63;
 
 if ( count == 0 ) {
 z1 = a1;
@@ -173,10 +173,10 @@ INLINE void
 
 INLINE void
  shift128RightJamming(
- bits64 a0, bits64 a1, int16 count, bits64 *z0Ptr, bits64 *z1Ptr )
+ bits64 a0, bits64 a1, int16_t count, bits64 *z0Ptr, bits64 *z1Ptr )
 {
 bits64 z0, z1;
-int8 negCount = ( - count )  63;
+int8_t negCount = ( - count )  63;
 
 if ( count == 0 ) {
 z1 = a1;
@@ -227,14 +227,14 @@ INLINE void
  bits64 a0,
  bits64 a1,
  bits64 a2,
- int16 count,
+ int16_t count,
  bits64 *z0Ptr,
  bits64 *z1Ptr,
  bits64 *z2Ptr
  )
 {
 bits64 z0, z1, z2;
-int8 negCount = ( - count )  63;
+int8_t negCount = ( - count )  63;
 
 if ( count == 0 ) {
 z2 = a2;
@@ -282,7 +282,7 @@ INLINE void
 
 INLINE void
  shortShift128Left(
- bits64 a0, bits64 a1, int16 count, bits64 *z0Ptr, bits64 *z1Ptr )
+ bits64 a0, bits64 a1, int16_t count, bits64 *z0Ptr, bits64 *z1Ptr )
 {
 
 *z1Ptr = a1count;
@@ -304,14 +304,14 @@ INLINE void
  bits64 a0,
  bits64 a1,
  bits64 a2,
- int16 count,
+ int16_t count,
  bits64 *z0Ptr,
  bits64 *z1Ptr,
  bits64 *z2Ptr
  )
 {
 bits64 z0, z1, z2;
-int8 negCount;
+int8_t negCount;
 
 z2 = a2count;
 z1 = a1count;
@@ -368,7 +368,7 @@ INLINE void
  )
 {
 bits64 z0, z1, z2;
-int8 carry0, carry1;
+int8_t carry0, carry1;
 
 z2 = a2 + b2;
 carry1 = ( z2  a2 );
@@ -424,7 +424,7 @@ INLINE void
  )
 {
 bits64 z0, z1, z2;
-int8 borrow0, borrow1;
+int8_t borrow0, borrow1;
 
 z2 = a2 - b2;
 borrow1 = ( a2  b2 );
@@ -575,7 +575,7 @@ static bits64 estimateDiv128To64( bits64 a0, bits64 a1, 
bits64 b )
 | value.
 **/
 
-static bits32 estimateSqrt32( int16 aExp, bits32 a )
+static bits32 estimateSqrt32( int16_t aExp, bits32 a )
 {
 static const bits16 sqrtOddAdjustments[] = {
 0x0004, 0x0022, 0x005D, 0x00B1, 0x011D, 0x019F, 0x0236, 0x02E0,
@@ -585,7 +585,7 @@ static bits32 estimateSqrt32( int16 aExp, bits32 a )
 0x0A2D, 0x08AF, 0x075A, 0x0629, 0x051A, 0x0429, 0x0356, 0x029E,
 0x0200, 0x0179, 0x0109, 0x00AF, 0x0068, 0x0034, 0x0012, 0x0002
 };
-int8 index;
+int8_t index;
 bits32 z;
 
 index = ( a27 )  

[Qemu-devel] [PULL 00/38] Block patches

2010-12-17 Thread Kevin Wolf
The following changes since commit 9d861fa595c93f22d1d55b723a691531c36c9672:

  Merge remote branch 'arm/for-anthony' into staging (2010-12-17 08:25:17 -0600)

are available in the git repository at:

  git://repo.or.cz/qemu/kevin.git for-anthony

Alexander Graf (10):
  ide: split ide command interpretation off
  ide: fix whitespace gap in ide_exec_cmd
  ide: Split out BMDMA code from ATA core
  ide: move transfer_start after variable modification
  pci: add storage class for sata
  pci: add ich9 pci id
  ahci: add ahci emulation
  config: move ide core and pci to pci.mak
  config: add ahci for pci capable machines
  ide: honor ncq for atapi

Christoph Hellwig (3):
  block: add discard support
  scsi-disk: support WRITE SAME (16) with unmap bit
  raw-posix: add discard support

Jes Sorensen (9):
  Introduce strtosz_suffix()
  qemu-img.c: Clean up handling of image size in img_create()
  qemu-img.c: Re-factor img_create()
  Introduce do_snapshot_blkdev() and monitor command to handle it.
  Prevent creating an image with the same filename as backing file
  bdrv_img_create() use proper errno return values
  qemu.img.c: Use error_report() instead of own error() implementation
  block/qcow2.c: rename qcow_ functions to qcow2_
  Add proper -errno error return values to qcow2_open()

Kevin Wolf (3):
  qemu-img: Call error_set_progname
  Remove NULL checks for bdrv_new return value
  qemu-io: Fix typo in help texts

Roland Elek (1):
  ide: add ncq identify data for ahci sata drives

Ryan Harper (1):
  blockdev: check dinfo ptr before using

Sebastian Herbszt (1):
  ahci: set SATA Mode Select

Stefan Hajnoczi (10):
  block: Introduce path_has_protocol() function
  block: Fix the use of protocols in backing files
  ide: Register vm change state handler once only
  qemu-io: Add discard command
  docs: Add QED image format specification
  qed: Add QEMU Enhanced Disk image format
  qed: Table, L2 cache, and cluster functions
  qed: Read/write support
  qed: Consistency check support
  docs: Fix missing carets in QED specification

 Makefile.objs|3 +
 block.c  |  234 +-
 block.h  |5 +
 block/qcow2-cluster.c|6 +-
 block/qcow2-snapshot.c   |6 +-
 block/qcow2.c|  248 +++---
 block/qed-check.c|  210 +
 block/qed-cluster.c  |  154 
 block/qed-gencb.c|   32 +
 block/qed-l2-cache.c |  173 
 block/qed-table.c|  319 +++
 block/qed.c  | 1349 ++
 block/qed.h  |  301 +++
 block/raw-posix.c|   45 +
 block/raw.c  |6 +
 block_int.h  |8 +-
 blockdev.c   |   68 ++-
 blockdev.h   |1 +
 configure|   26 +
 cutils.c |   17 +-
 default-configs/arm-softmmu.mak  |1 -
 default-configs/i386-softmmu.mak |3 -
 default-configs/mips-softmmu.mak |3 -
 default-configs/mips64-softmmu.mak   |3 -
 default-configs/mips64el-softmmu.mak |3 -
 default-configs/mipsel-softmmu.mak   |3 -
 default-configs/pci.mak  |4 +
 default-configs/ppc-softmmu.mak  |3 -
 default-configs/ppc64-softmmu.mak|3 -
 default-configs/ppcemb-softmmu.mak   |3 -
 default-configs/sh4-softmmu.mak  |1 -
 default-configs/sh4eb-softmmu.mak|1 -
 default-configs/sparc64-softmmu.mak  |3 -
 default-configs/x86_64-softmmu.mak   |3 -
 docs/specs/qed_spec.txt  |  130 +++
 hmp-commands.hx  |   19 +
 hw/ide/ahci.c| 1527 ++
 hw/ide/cmd646.c  |   18 +-
 hw/ide/core.c| 1116 +++--
 hw/ide/internal.h|   73 +-
 hw/ide/pci.c |  280 ++-
 hw/ide/pci.h |   30 +
 hw/ide/piix.c|   34 +-
 hw/ide/via.c |   34 +-
 hw/pci.h |1 +
 hw/pci_ids.h |1 +
 hw/scsi-defs.h   |1 +
 hw/scsi-disk.c   |   53 ++-
 hw/xen_disk.c|   17 +-
 qemu-common.h|7 +
 qemu-img.c   |  250 ++
 qemu-io.c|  102 +++-
 qemu-nbd.c   |2 -
 trace-events |   21 +
 54 files changed, 5892 insertions(+), 1072 deletions(-)
 create mode 100644 block/qed-check.c
 create mode 

[Qemu-devel] [PATCH 04/38] Introduce strtosz_suffix()

2010-12-17 Thread Kevin Wolf
From: Jes Sorensen jes.soren...@redhat.com

This introduces strtosz_suffix() which allows the caller to specify a
default suffix in case the non default of MB is wanted.

strtosz() is kept as a wrapper for strtosz_suffix() which keeps it's
current default of MB.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
Reviewed-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
Signed-off-by: Kevin Wolf kw...@redhat.com
---
 cutils.c  |   17 ++---
 qemu-common.h |7 +++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/cutils.c b/cutils.c
index 28089aa..7984bc1 100644
--- a/cutils.c
+++ b/cutils.c
@@ -291,10 +291,10 @@ int fcntl_setfl(int fd, int flag)
  * value must be terminated by whitespace, ',' or '\0'. Return -1 on
  * error.
  */
-ssize_t strtosz(const char *nptr, char **end)
+ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
 {
 ssize_t retval = -1;
-char *endptr, c;
+char *endptr, c, d;
 int mul_required = 0;
 double val, mul, integral, fraction;
 
@@ -313,10 +313,16 @@ ssize_t strtosz(const char *nptr, char **end)
  * part of a multi token argument.
  */
 c = *endptr;
+d = c;
 if (isspace(c) || c == '\0' || c == ',') {
 c = 0;
+if (default_suffix) {
+d = default_suffix;
+} else {
+d = c;
+}
 }
-switch (c) {
+switch (d) {
 case 'B':
 case 'b':
 mul = 1;
@@ -371,3 +377,8 @@ fail:
 
 return retval;
 }
+
+ssize_t strtosz(const char *nptr, char **end)
+{
+return strtosz_suffix(nptr, end, STRTOSZ_DEFSUFFIX_MB);
+}
diff --git a/qemu-common.h b/qemu-common.h
index de82c2e..1ed32e5 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -149,7 +149,14 @@ time_t mktimegm(struct tm *tm);
 int qemu_fls(int i);
 int qemu_fdatasync(int fd);
 int fcntl_setfl(int fd, int flag);
+
+#define STRTOSZ_DEFSUFFIX_TB   'T'
+#define STRTOSZ_DEFSUFFIX_GB   'G'
+#define STRTOSZ_DEFSUFFIX_MB   'M'
+#define STRTOSZ_DEFSUFFIX_KB   'K'
+#define STRTOSZ_DEFSUFFIX_B'B'
 ssize_t strtosz(const char *nptr, char **end);
+ssize_t strtosz_suffix(const char *nptr, char **end, const char 
default_suffix);
 
 /* path.c */
 void init_paths(const char *prefix);
-- 
1.7.2.3




[Qemu-devel] [PATCH 33/38] qed: Table, L2 cache, and cluster functions

2010-12-17 Thread Kevin Wolf
From: Stefan Hajnoczi stefa...@linux.vnet.ibm.com

This patch adds code to look up data cluster offsets in the image via
the L1/L2 tables.  The L2 tables are writethrough cached in memory for
performance (each read/write requires a lookup so it is essential to
cache the tables).

With cluster lookup code in place it is possible to implement
bdrv_is_allocated() to query the number of contiguous
allocated/unallocated clusters.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
Signed-off-by: Kevin Wolf kw...@redhat.com
---
 Makefile.objs|2 +-
 block/qed-cluster.c  |  154 
 block/qed-gencb.c|   32 +
 block/qed-l2-cache.c |  173 +++
 block/qed-table.c|  319 ++
 block/qed.c  |   54 +-
 block/qed.h  |  123 +++
 trace-events |   11 ++
 8 files changed, 866 insertions(+), 2 deletions(-)
 create mode 100644 block/qed-cluster.c
 create mode 100644 block/qed-gencb.c
 create mode 100644 block/qed-l2-cache.c
 create mode 100644 block/qed-table.c

diff --git a/Makefile.objs b/Makefile.objs
index 50b91e8..1860152 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -20,7 +20,7 @@ block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 
 block-nested-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o 
vvfat.o
 block-nested-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o
-block-nested-y += qed.o
+block-nested-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
 block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o
 block-nested-$(CONFIG_WIN32) += raw-win32.o
 block-nested-$(CONFIG_POSIX) += raw-posix.o
diff --git a/block/qed-cluster.c b/block/qed-cluster.c
new file mode 100644
index 000..0ec864b
--- /dev/null
+++ b/block/qed-cluster.c
@@ -0,0 +1,154 @@
+/*
+ * QEMU Enhanced Disk Format Cluster functions
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ *  Stefan Hajnoczi   stefa...@linux.vnet.ibm.com
+ *  Anthony Liguori   aligu...@us.ibm.com
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include qed.h
+
+/**
+ * Count the number of contiguous data clusters
+ *
+ * @s:  QED state
+ * @table:  L2 table
+ * @index:  First cluster index
+ * @n:  Maximum number of clusters
+ * @offset: Set to first cluster offset
+ *
+ * This function scans tables for contiguous allocated or free clusters.
+ */
+static unsigned int qed_count_contiguous_clusters(BDRVQEDState *s,
+  QEDTable *table,
+  unsigned int index,
+  unsigned int n,
+  uint64_t *offset)
+{
+unsigned int end = MIN(index + n, s-table_nelems);
+uint64_t last = table-offsets[index];
+unsigned int i;
+
+*offset = last;
+
+for (i = index + 1; i  end; i++) {
+if (last == 0) {
+/* Counting free clusters */
+if (table-offsets[i] != 0) {
+break;
+}
+} else {
+/* Counting allocated clusters */
+if (table-offsets[i] != last + s-header.cluster_size) {
+break;
+}
+last = table-offsets[i];
+}
+}
+return i - index;
+}
+
+typedef struct {
+BDRVQEDState *s;
+uint64_t pos;
+size_t len;
+
+QEDRequest *request;
+
+/* User callback */
+QEDFindClusterFunc *cb;
+void *opaque;
+} QEDFindClusterCB;
+
+static void qed_find_cluster_cb(void *opaque, int ret)
+{
+QEDFindClusterCB *find_cluster_cb = opaque;
+BDRVQEDState *s = find_cluster_cb-s;
+QEDRequest *request = find_cluster_cb-request;
+uint64_t offset = 0;
+size_t len = 0;
+unsigned int index;
+unsigned int n;
+
+if (ret) {
+goto out;
+}
+
+index = qed_l2_index(s, find_cluster_cb-pos);
+n = qed_bytes_to_clusters(s,
+  qed_offset_into_cluster(s, find_cluster_cb-pos) 
+
+  find_cluster_cb-len);
+n = qed_count_contiguous_clusters(s, request-l2_table-table,
+  index, n, offset);
+
+ret = offset ? QED_CLUSTER_FOUND : QED_CLUSTER_L2;
+len = MIN(find_cluster_cb-len, n * s-header.cluster_size -
+  qed_offset_into_cluster(s, find_cluster_cb-pos));
+
+if (offset  !qed_check_cluster_offset(s, offset)) {
+ret = -EINVAL;
+}
+
+out:
+find_cluster_cb-cb(find_cluster_cb-opaque, ret, offset, len);
+qemu_free(find_cluster_cb);
+}
+
+/**
+ * Find the offset of a data cluster
+ *
+ * @s:  QED state
+ * @request:L2 cache entry
+ * @pos:Byte position in device
+ * @len:Number of bytes
+ * @cb:  

[Qemu-devel] [PATCH 02/38] block: Introduce path_has_protocol() function

2010-12-17 Thread Kevin Wolf
From: Stefan Hajnoczi stefa...@linux.vnet.ibm.com

The bdrv_find_protocol() function returns NULL if an unknown protocol
name is given.  It returns the file protocol when the filename
contains no protocol at all.  This makes it difficult to distinguish
between paths which contain a protocol and those which do not.

Factor out a helper function that tests whether or not a filename has a
protocol.  The next patch makes use of this function.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
Signed-off-by: Kevin Wolf kw...@redhat.com
---
 block.c |   64 +++---
 1 files changed, 36 insertions(+), 28 deletions(-)

diff --git a/block.c b/block.c
index e7a986c..65fce80 100644
--- a/block.c
+++ b/block.c
@@ -70,6 +70,39 @@ static BlockDriverState *bs_snapshots;
 /* If non-zero, use only whitelisted block drivers */
 static int use_bdrv_whitelist;
 
+#ifdef _WIN32
+static int is_windows_drive_prefix(const char *filename)
+{
+return (((filename[0] = 'a'  filename[0] = 'z') ||
+ (filename[0] = 'A'  filename[0] = 'Z')) 
+filename[1] == ':');
+}
+
+int is_windows_drive(const char *filename)
+{
+if (is_windows_drive_prefix(filename) 
+filename[2] == '\0')
+return 1;
+if (strstart(filename, .\\, NULL) ||
+strstart(filename, //./, NULL))
+return 1;
+return 0;
+}
+#endif
+
+/* check if the path starts with protocol: */
+static int path_has_protocol(const char *path)
+{
+#ifdef _WIN32
+if (is_windows_drive(path) ||
+is_windows_drive_prefix(path)) {
+return 0;
+}
+#endif
+
+return strchr(path, ':') != NULL;
+}
+
 int path_is_absolute(const char *path)
 {
 const char *p;
@@ -244,26 +277,6 @@ void get_tmp_filename(char *filename, int size)
 }
 #endif
 
-#ifdef _WIN32
-static int is_windows_drive_prefix(const char *filename)
-{
-return (((filename[0] = 'a'  filename[0] = 'z') ||
- (filename[0] = 'A'  filename[0] = 'Z')) 
-filename[1] == ':');
-}
-
-int is_windows_drive(const char *filename)
-{
-if (is_windows_drive_prefix(filename) 
-filename[2] == '\0')
-return 1;
-if (strstart(filename, .\\, NULL) ||
-strstart(filename, //./, NULL))
-return 1;
-return 0;
-}
-#endif
-
 /*
  * Detect host devices. By convention, /dev/cdrom[N] is always
  * recognized as a host CDROM.
@@ -307,16 +320,11 @@ BlockDriver *bdrv_find_protocol(const char *filename)
 return drv1;
 }
 
-#ifdef _WIN32
- if (is_windows_drive(filename) ||
- is_windows_drive_prefix(filename))
- return bdrv_find_format(file);
-#endif
-
-p = strchr(filename, ':');
-if (!p) {
+if (!path_has_protocol(filename)) {
 return bdrv_find_format(file);
 }
+p = strchr(filename, ':');
+assert(p != NULL);
 len = p - filename;
 if (len  sizeof(protocol) - 1)
 len = sizeof(protocol) - 1;
-- 
1.7.2.3




[Qemu-devel] [PATCH 09/38] ide: move transfer_start after variable modification

2010-12-17 Thread Kevin Wolf
From: Alexander Graf ag...@suse.de

We hook into transfer_start and immediately call the end function
for ahci. This means that everything needs to be in place for the
end function when we start the transfer, so let's move the function
down to where all state is in place.

Signed-off-by: Alexander Graf ag...@suse.de
Signed-off-by: Kevin Wolf kw...@redhat.com
---
 hw/ide/core.c |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 2032e20..228911d 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -814,11 +814,11 @@ static void ide_atapi_cmd_reply_end(IDEState *s)
 size = s-cd_sector_size - s-io_buffer_index;
 if (size  s-elementary_transfer_size)
 size = s-elementary_transfer_size;
-ide_transfer_start(s, s-io_buffer + s-io_buffer_index,
-   size, ide_atapi_cmd_reply_end);
 s-packet_transfer_size -= size;
 s-elementary_transfer_size -= size;
 s-io_buffer_index += size;
+ide_transfer_start(s, s-io_buffer + s-io_buffer_index - size,
+   size, ide_atapi_cmd_reply_end);
 } else {
 /* a new transfer is needed */
 s-nsector = (s-nsector  ~7) | ATAPI_INT_REASON_IO;
@@ -843,11 +843,11 @@ static void ide_atapi_cmd_reply_end(IDEState *s)
 if (size  (s-cd_sector_size - s-io_buffer_index))
 size = (s-cd_sector_size - s-io_buffer_index);
 }
-ide_transfer_start(s, s-io_buffer + s-io_buffer_index,
-   size, ide_atapi_cmd_reply_end);
 s-packet_transfer_size -= size;
 s-elementary_transfer_size -= size;
 s-io_buffer_index += size;
+ide_transfer_start(s, s-io_buffer + s-io_buffer_index - size,
+   size, ide_atapi_cmd_reply_end);
 ide_set_irq(s-bus);
 #ifdef DEBUG_IDE_ATAPI
 printf(status=0x%x\n, s-status);
-- 
1.7.2.3




[Qemu-devel] [PATCH 03/38] block: Fix the use of protocols in backing files

2010-12-17 Thread Kevin Wolf
From: Stefan Hajnoczi stefa...@linux.vnet.ibm.com

Backing filenames may contain a protocol.  The code currently doesn't
consider this case and produces filenames that embed protocol:.
Don't combine filenames if the backing filename contains a protocol.

Based on an earlier patch by Anthony Liguori aligu...@us.ibm.com.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
Signed-off-by: Kevin Wolf kw...@redhat.com
---
 block.c |   14 +++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/block.c b/block.c
index 65fce80..b4aaf41 100644
--- a/block.c
+++ b/block.c
@@ -611,10 +611,18 @@ int bdrv_open(BlockDriverState *bs, const char *filename, 
int flags,
 BlockDriver *back_drv = NULL;
 
 bs-backing_hd = bdrv_new();
-path_combine(backing_filename, sizeof(backing_filename),
- filename, bs-backing_file);
-if (bs-backing_format[0] != '\0')
+
+if (path_has_protocol(bs-backing_file)) {
+pstrcpy(backing_filename, sizeof(backing_filename),
+bs-backing_file);
+} else {
+path_combine(backing_filename, sizeof(backing_filename),
+ filename, bs-backing_file);
+}
+
+if (bs-backing_format[0] != '\0') {
 back_drv = bdrv_find_format(bs-backing_format);
+}
 
 /* backing files always opened read-only */
 back_flags =
-- 
1.7.2.3




[Qemu-devel] [PATCH 10/38] ide: add ncq identify data for ahci sata drives

2010-12-17 Thread Kevin Wolf
From: Roland Elek elek.rol...@gmail.com

I modified ide_identify() to include the zero-based queue length
value in word 75, and set bit 8 in word 76 to signal NCQ support
in the identify data for AHCI SATA drives.

Signed-off-by: Roland Elek elek.rol...@gmail.com
Signed-off-by: Kevin Wolf kw...@redhat.com
---
 hw/ide/core.c |7 +++
 hw/ide/internal.h |2 ++
 2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 228911d..9e1d4e6 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -140,6 +140,13 @@ static void ide_identify(IDEState *s)
 put_le16(p + 66, 120);
 put_le16(p + 67, 120);
 put_le16(p + 68, 120);
+
+if (s-ncq_queues) {
+put_le16(p + 75, s-ncq_queues - 1);
+/* NCQ supported */
+put_le16(p + 76, (1  8));
+}
+
 put_le16(p + 80, 0xf0); /* ata3 - ata6 supported */
 put_le16(p + 81, 0x16); /* conforms to ata5 */
 /* 14=NOP supported, 5=WCACHE supported, 0=SMART supported */
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index aadb505..697c3b4 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -447,6 +447,8 @@ struct IDEState {
 int smart_errors;
 uint8_t smart_selftest_count;
 uint8_t *smart_selftest_data;
+/* AHCI */
+int ncq_queues;
 };
 
 struct IDEDMAOps {
-- 
1.7.2.3




[Qemu-devel] [PATCH 22/38] bdrv_img_create() use proper errno return values

2010-12-17 Thread Kevin Wolf
From: Jes Sorensen jes.soren...@redhat.com

Kevin suggested to have bdrv_img_create() return proper -errno values
on error.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
Signed-off-by: Kevin Wolf kw...@redhat.com
---
 block.c |   23 ++-
 1 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/block.c b/block.c
index 0c14eee..fe07d0b 100644
--- a/block.c
+++ b/block.c
@@ -2773,14 +2773,14 @@ int bdrv_img_create(const char *filename, const char 
*fmt,
 drv = bdrv_find_format(fmt);
 if (!drv) {
 error_report(Unknown file format '%s', fmt);
-ret = -1;
+ret = -EINVAL;
 goto out;
 }
 
 proto_drv = bdrv_find_protocol(filename);
 if (!proto_drv) {
 error_report(Unknown protocol '%s', filename);
-ret = -1;
+ret = -EINVAL;
 goto out;
 }
 
@@ -2799,7 +2799,7 @@ int bdrv_img_create(const char *filename, const char *fmt,
 param = parse_option_parameters(options, create_options, param);
 if (param == NULL) {
 error_report(Invalid options for file format '%s'., fmt);
-ret = -1;
+ret = -EINVAL;
 goto out;
 }
 }
@@ -2809,7 +2809,7 @@ int bdrv_img_create(const char *filename, const char *fmt,
  base_filename)) {
 error_report(Backing file not supported for file format '%s',
  fmt);
-ret = -1;
+ret = -EINVAL;
 goto out;
 }
 }
@@ -2818,7 +2818,7 @@ int bdrv_img_create(const char *filename, const char *fmt,
 if (set_option_parameter(param, BLOCK_OPT_BACKING_FMT, base_fmt)) {
 error_report(Backing file format not supported for file 
  format '%s', fmt);
-ret = -1;
+ret = -EINVAL;
 goto out;
 }
 }
@@ -2828,7 +2828,7 @@ int bdrv_img_create(const char *filename, const char *fmt,
 if (!strcmp(filename, backing_file-value.s)) {
 error_report(Error: Trying to create an image with the 
  same filename as the backing file);
-ret = -1;
+ret = -EINVAL;
 goto out;
 }
 }
@@ -2838,7 +2838,7 @@ int bdrv_img_create(const char *filename, const char *fmt,
 if (!bdrv_find_format(backing_fmt-value.s)) {
 error_report(Unknown backing file format '%s',
  backing_fmt-value.s);
-ret = -1;
+ret = -EINVAL;
 goto out;
 }
 }
@@ -2860,7 +2860,6 @@ int bdrv_img_create(const char *filename, const char *fmt,
 ret = bdrv_open(bs, backing_file-value.s, flags, drv);
 if (ret  0) {
 error_report(Could not open '%s', filename);
-ret = -1;
 goto out;
 }
 bdrv_get_geometry(bs, size);
@@ -2870,7 +2869,7 @@ int bdrv_img_create(const char *filename, const char *fmt,
 set_option_parameter(param, BLOCK_OPT_SIZE, buf);
 } else {
 error_report(Image creation needs a size parameter);
-ret = -1;
+ret = -EINVAL;
 goto out;
 }
 }
@@ -2901,8 +2900,6 @@ out:
 if (bs) {
 bdrv_delete(bs);
 }
-if (ret) {
-return 1;
-}
-return 0;
+
+return ret;
 }
-- 
1.7.2.3




[Qemu-devel] [PATCH 01/38] blockdev: check dinfo ptr before using

2010-12-17 Thread Kevin Wolf
From: Ryan Harper ry...@us.ibm.com

If a user decides to punish a guest by revoking its block device via
drive_del, and subsequently also attempts to remove the pci device
backing it, and the device is using blockdev_auto_del() then we get a
segfault when we attempt to access dinfo-auto_del.[1]

The fix is to check if drive_get_by_blockdev() actually returns a valid
dinfo pointer or not.

1. (qemu) pci_add auto storage 
file=images/test01.raw,if=virtio,id=block1,snapshot=on
   (qemu) drive_del block1
   (qemu) pci_del 5
   *segfault*

Signed-off-by: Ryan Harper ry...@us.ibm.com
Tested-by: Luiz Capitulino lcapitul...@redhat.com
Signed-off-by: Kevin Wolf kw...@redhat.com
---
 blockdev.c |6 --
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index f6ac439..3b3b82d 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -30,14 +30,16 @@ void blockdev_mark_auto_del(BlockDriverState *bs)
 {
 DriveInfo *dinfo = drive_get_by_blockdev(bs);
 
-dinfo-auto_del = 1;
+if (dinfo) {
+dinfo-auto_del = 1;
+}
 }
 
 void blockdev_auto_del(BlockDriverState *bs)
 {
 DriveInfo *dinfo = drive_get_by_blockdev(bs);
 
-if (dinfo-auto_del) {
+if (dinfo  dinfo-auto_del) {
 drive_uninit(dinfo);
 }
 }
-- 
1.7.2.3




[Qemu-devel] [PATCH 13/38] ahci: add ahci emulation

2010-12-17 Thread Kevin Wolf
From: Alexander Graf ag...@suse.de

This patch adds an emulation layer for an ICH-9 AHCI controller. For now
this controller does not do IDE legacy emulation. It is a pure AHCI controller.

Signed-off-by: Alexander Graf ag...@suse.de
Signed-off-by: Kevin Wolf kw...@redhat.com
---
 Makefile.objs |1 +
 hw/ide/ahci.c | 1524 +
 2 files changed, 1525 insertions(+), 0 deletions(-)
 create mode 100644 hw/ide/ahci.c

diff --git a/Makefile.objs b/Makefile.objs
index 24b2f99..72c07dd 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -243,6 +243,7 @@ hw-obj-$(CONFIG_IDE_PIIX) += ide/piix.o
 hw-obj-$(CONFIG_IDE_CMD646) += ide/cmd646.o
 hw-obj-$(CONFIG_IDE_MACIO) += ide/macio.o
 hw-obj-$(CONFIG_IDE_VIA) += ide/via.o
+hw-obj-$(CONFIG_AHCI) += ide/ahci.o
 
 # SCSI layer
 hw-obj-$(CONFIG_LSI_SCSI_PCI) += lsi53c895a.o
diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
new file mode 100644
index 000..f937a92
--- /dev/null
+++ b/hw/ide/ahci.c
@@ -0,0 +1,1524 @@
+/*
+ * QEMU AHCI Emulation
+ *
+ * Copyright (c) 2010 qiaoch...@loongson.cn
+ * Copyright (c) 2010 Roland Elek elek.rol...@gmail.com
+ * Copyright (c) 2010 Sebastian Herbszt herb...@gmx.de
+ * Copyright (c) 2010 Alexander Graf ag...@suse.de
+ *
+ * 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/.
+ *
+ *
+ * lspci dump of a ICH-9 real device in IDE mode (hopefully close enough):
+ *
+ * 00:1f.2 SATA controller [0106]: Intel Corporation 82801IR/IO/IH 
(ICH9R/DO/DH) 6 port SATA AHCI Controller [8086:2922] (rev 02) (prog-if 01 
[AHCI 1.0])
+ * Subsystem: Intel Corporation 82801IR/IO/IH (ICH9R/DO/DH) 6 port 
SATA AHCI Controller [8086:2922]
+ * Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- 
Stepping- SERR- FastB2B- DisINTx+
+ * Status: Cap+ 66MHz+ UDF- FastB2B+ ParErr- DEVSEL=medium TAbort- 
TAbort- MAbort- SERR- PERR- INTx-
+ * Latency: 0
+ * Interrupt: pin B routed to IRQ 222
+ * Region 0: I/O ports at d000 [size=8]
+ * Region 1: I/O ports at cc00 [size=4]
+ * Region 2: I/O ports at c880 [size=8]
+ * Region 3: I/O ports at c800 [size=4]
+ * Region 4: I/O ports at c480 [size=32]
+ * Region 5: Memory at febf9000 (32-bit, non-prefetchable) [size=2K]
+ * Capabilities: [80] Message Signalled Interrupts: Mask- 64bit- 
Count=1/16 Enable+
+ * Address: fee0f00c  Data: 41d9
+ * Capabilities: [70] Power Management version 3
+ * Flags: PMEClk- DSI- D1- D2- AuxCurrent=0mA 
PME(D0-,D1-,D2-,D3hot+,D3cold-)
+ * Status: D0 PME-Enable- DSel=0 DScale=0 PME-
+ * Capabilities: [a8] SATA HBA ?
+ * Capabilities: [b0] Vendor Specific Information ?
+ * Kernel driver in use: ahci
+ * Kernel modules: ahci
+ * 00: 86 80 22 29 07 04 b0 02 02 01 06 01 00 00 00 00
+ * 10: 01 d0 00 00 01 cc 00 00 81 c8 00 00 01 c8 00 00
+ * 20: 81 c4 00 00 00 90 bf fe 00 00 00 00 86 80 22 29
+ * 30: 00 00 00 00 80 00 00 00 00 00 00 00 0f 02 00 00
+ * 40: 00 80 00 80 00 00 00 00 00 00 00 00 00 00 00 00
+ * 50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ * 60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ * 70: 01 a8 03 40 08 00 00 00 00 00 00 00 00 00 00 00
+ * 80: 05 70 09 00 0c f0 e0 fe d9 41 00 00 00 00 00 00
+ * 90: 40 00 0f 82 93 01 00 00 00 00 00 00 00 00 00 00
+ * a0: ac 00 00 00 0a 00 12 00 12 b0 10 00 48 00 00 00
+ * b0: 09 00 06 20 00 00 00 00 00 00 00 00 00 00 00 00
+ * c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ * d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ * e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ * f0: 00 00 00 00 00 00 00 00 86 0f 02 00 00 00 00 00
+ *
+ */
+
+#include hw/hw.h
+#include hw/msi.h
+#include hw/pc.h
+#include hw/pci.h
+
+#include monitor.h
+#include dma.h
+#include cpu-common.h
+#include blockdev.h
+#include internal.h
+#include hw/ide/pci.h
+
+/* #define DEBUG_AHCI */
+
+#ifdef DEBUG_AHCI
+#define DPRINTF(port, fmt, ...) \
+do { fprintf(stderr, ahci: %s: [%d] , __FUNCTION__, port); \
+ fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
+#else
+#define DPRINTF(port, fmt, ...) do {} while(0)
+#endif
+
+#define AHCI_PCI_BAR  5
+#define AHCI_MAX_PORTS32
+#define AHCI_MAX_SG   168 /* hardware max is 64K */
+#define AHCI_DMA_BOUNDARY 

[Qemu-devel] [PATCH 14/38] config: move ide core and pci to pci.mak

2010-12-17 Thread Kevin Wolf
From: Alexander Graf ag...@suse.de

Every device that can do PCI should also be able to do IDE. So let's move
the IDE definitions over to pci.mak.

Signed-off-by: Alexander Graf ag...@suse.de
Signed-off-by: Kevin Wolf kw...@redhat.com
---
 default-configs/arm-softmmu.mak  |1 -
 default-configs/i386-softmmu.mak |3 ---
 default-configs/mips-softmmu.mak |3 ---
 default-configs/mips64-softmmu.mak   |3 ---
 default-configs/mips64el-softmmu.mak |3 ---
 default-configs/mipsel-softmmu.mak   |3 ---
 default-configs/pci.mak  |3 +++
 default-configs/ppc-softmmu.mak  |3 ---
 default-configs/ppc64-softmmu.mak|3 ---
 default-configs/ppcemb-softmmu.mak   |3 ---
 default-configs/sh4-softmmu.mak  |1 -
 default-configs/sh4eb-softmmu.mak|1 -
 default-configs/sparc64-softmmu.mak  |3 ---
 default-configs/x86_64-softmmu.mak   |3 ---
 14 files changed, 3 insertions(+), 33 deletions(-)

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index ac48dc1..8d1174f 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -8,7 +8,6 @@ CONFIG_ECC=y
 CONFIG_SERIAL=y
 CONFIG_PTIMER=y
 CONFIG_SD=y
-CONFIG_IDE_CORE=y
 CONFIG_MAX7310=y
 CONFIG_WM8750=y
 CONFIG_TWL92230=y
diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index ce905d2..323fafb 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -13,9 +13,6 @@ CONFIG_FDC=y
 CONFIG_ACPI=y
 CONFIG_APM=y
 CONFIG_DMA=y
-CONFIG_IDE_CORE=y
-CONFIG_IDE_QDEV=y
-CONFIG_IDE_PCI=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_PIIX=y
 CONFIG_NE2000_ISA=y
diff --git a/default-configs/mips-softmmu.mak b/default-configs/mips-softmmu.mak
index 565e611..f524971 100644
--- a/default-configs/mips-softmmu.mak
+++ b/default-configs/mips-softmmu.mak
@@ -17,9 +17,6 @@ CONFIG_ACPI=y
 CONFIG_APM=y
 CONFIG_DMA=y
 CONFIG_PIIX4=y
-CONFIG_IDE_CORE=y
-CONFIG_IDE_QDEV=y
-CONFIG_IDE_PCI=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_PIIX=y
 CONFIG_NE2000_ISA=y
diff --git a/default-configs/mips64-softmmu.mak 
b/default-configs/mips64-softmmu.mak
index 03bd8eb..aeab6b2 100644
--- a/default-configs/mips64-softmmu.mak
+++ b/default-configs/mips64-softmmu.mak
@@ -17,9 +17,6 @@ CONFIG_ACPI=y
 CONFIG_APM=y
 CONFIG_DMA=y
 CONFIG_PIIX4=y
-CONFIG_IDE_CORE=y
-CONFIG_IDE_QDEV=y
-CONFIG_IDE_PCI=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_PIIX=y
 CONFIG_NE2000_ISA=y
diff --git a/default-configs/mips64el-softmmu.mak 
b/default-configs/mips64el-softmmu.mak
index 4661617..8e6511c 100644
--- a/default-configs/mips64el-softmmu.mak
+++ b/default-configs/mips64el-softmmu.mak
@@ -17,9 +17,6 @@ CONFIG_ACPI=y
 CONFIG_APM=y
 CONFIG_DMA=y
 CONFIG_PIIX4=y
-CONFIG_IDE_CORE=y
-CONFIG_IDE_QDEV=y
-CONFIG_IDE_PCI=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_PIIX=y
 CONFIG_IDE_VIA=y
diff --git a/default-configs/mipsel-softmmu.mak 
b/default-configs/mipsel-softmmu.mak
index 92fc473..a05ac25 100644
--- a/default-configs/mipsel-softmmu.mak
+++ b/default-configs/mipsel-softmmu.mak
@@ -17,9 +17,6 @@ CONFIG_ACPI=y
 CONFIG_APM=y
 CONFIG_DMA=y
 CONFIG_PIIX4=y
-CONFIG_IDE_CORE=y
-CONFIG_IDE_QDEV=y
-CONFIG_IDE_PCI=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_PIIX=y
 CONFIG_NE2000_ISA=y
diff --git a/default-configs/pci.mak b/default-configs/pci.mak
index c74a99f..d700b3c 100644
--- a/default-configs/pci.mak
+++ b/default-configs/pci.mak
@@ -10,3 +10,6 @@ CONFIG_PCNET_COMMON=y
 CONFIG_LSI_SCSI_PCI=y
 CONFIG_RTL8139_PCI=y
 CONFIG_E1000_PCI=y
+CONFIG_IDE_CORE=y
+CONFIG_IDE_QDEV=y
+CONFIG_IDE_PCI=y
diff --git a/default-configs/ppc-softmmu.mak b/default-configs/ppc-softmmu.mak
index f1cb99e..4563742 100644
--- a/default-configs/ppc-softmmu.mak
+++ b/default-configs/ppc-softmmu.mak
@@ -23,9 +23,6 @@ CONFIG_GRACKLE_PCI=y
 CONFIG_UNIN_PCI=y
 CONFIG_DEC_PCI=y
 CONFIG_PPCE500_PCI=y
-CONFIG_IDE_CORE=y
-CONFIG_IDE_QDEV=y
-CONFIG_IDE_PCI=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_CMD646=y
 CONFIG_IDE_MACIO=y
diff --git a/default-configs/ppc64-softmmu.mak 
b/default-configs/ppc64-softmmu.mak
index 83cbe97..d5073b3 100644
--- a/default-configs/ppc64-softmmu.mak
+++ b/default-configs/ppc64-softmmu.mak
@@ -23,9 +23,6 @@ CONFIG_GRACKLE_PCI=y
 CONFIG_UNIN_PCI=y
 CONFIG_DEC_PCI=y
 CONFIG_PPCE500_PCI=y
-CONFIG_IDE_CORE=y
-CONFIG_IDE_QDEV=y
-CONFIG_IDE_PCI=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_CMD646=y
 CONFIG_IDE_MACIO=y
diff --git a/default-configs/ppcemb-softmmu.mak 
b/default-configs/ppcemb-softmmu.mak
index 2b52d4a..9f0730c 100644
--- a/default-configs/ppcemb-softmmu.mak
+++ b/default-configs/ppcemb-softmmu.mak
@@ -23,9 +23,6 @@ CONFIG_GRACKLE_PCI=y
 CONFIG_UNIN_PCI=y
 CONFIG_DEC_PCI=y
 CONFIG_PPCE500_PCI=y
-CONFIG_IDE_CORE=y
-CONFIG_IDE_QDEV=y
-CONFIG_IDE_PCI=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_CMD646=y
 CONFIG_IDE_MACIO=y
diff --git a/default-configs/sh4-softmmu.mak b/default-configs/sh4-softmmu.mak
index 87247a4..5c69acc 100644
--- a/default-configs/sh4-softmmu.mak
+++ b/default-configs/sh4-softmmu.mak
@@ -3,6 +3,5 @@
 include pci.mak
 CONFIG_SERIAL=y
 

  1   2   >