Re: [Qemu-devel] [PATCH v3 11/14] ioport: Switch dispatching to memory core layer

2013-06-24 Thread Jan Kiszka
On 2013-06-23 22:50, Hervé Poussineau wrote:
 Jan Kiszka a écrit :
 From: Jan Kiszka jan.kis...@siemens.com

 The current ioport dispatcher is a complex beast, mostly due to the
 need to deal with old portio interface users. But we can overcome it
 without converting all portio users by embedding the required base
 address of a MemoryRegionPortio access into that data structure. That
 removes the need to have the additional MemoryRegionIORange structure
 in the loop on every access.

 To handle old portio memory ops, we simply install dispatching handlers
 for portio memory regions when registering them with the memory core.
 This removes the need for the old_portio field.

 We can drop the additional aliasing of ioport regions and also the
 special address space listener. cpu_in and cpu_out now simply call
 address_space_read/write. And we can concentrate portio handling in a
 single source file.

 Signed-off-by: Jan Kiszka jan.kis...@siemens.com
 ---
 
 ...
 
 +
 +static void portio_write(void *opaque, hwaddr addr, uint64_t data,
 + unsigned size)
 +{
 +MemoryRegionPortioList *mrpio = opaque;
 +const MemoryRegionPortio *mrp = find_portio(mrpio, addr, size,
 true);
 +
 +if (mrp) {
 +mrp-write(mrpio-portio_opaque, mrp-base + addr, data);
 +} else if (size == 2) {
 +mrp = find_portio(mrpio, addr, 1, true);
 +assert(mrp);
 +mrp-write(mrpio-portio_opaque, mrp-base + addr, data  0xff);
 +mrp-write(mrpio-portio_opaque, mrp-base + addr + 1, data
  8);
 +}
 +}
 +
 +static const MemoryRegionOps portio_ops = {
 +.read = portio_read,
 +.write = portio_write,
 +.valid.unaligned = true,
 +.impl.unaligned = true,
 +};
 +
 
 You need to mark these operations as DEVICE_LITTLE_ENDIAN.
 In portio_write above, you clearly assume that data is in LE format.

Anything behind PIO is little endian, of course. Will add this.

 
 This fixes PPC PReP emulation, which would otherwise be broken with this
 patchset.

Thanks,
Jan




signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH 01/26] ohci: use realize for ohci

2013-06-24 Thread Hu Tao
On Mon, Jun 24, 2013 at 03:54:31PM +1000, Peter Crosthwaite wrote:
 Hi Hu,
 
 On Sat, Jun 22, 2013 at 6:50 PM, Hu Tao hu...@cn.fujitsu.com wrote:
  Cc: Gerd Hoffmann kra...@redhat.com
  Signed-off-by: Hu Tao hu...@cn.fujitsu.com
  ---
   hw/usb/hcd-ohci.c | 16 +++-
   1 file changed, 7 insertions(+), 9 deletions(-)
 
  diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c
  index 51241cd..79ef41b 100644
  --- a/hw/usb/hcd-ohci.c
  +++ b/hw/usb/hcd-ohci.c
  @@ -1876,17 +1876,16 @@ typedef struct {
   dma_addr_t dma_offset;
   } OHCISysBusState;
 
  -static int ohci_init_pxa(SysBusDevice *dev)
  +static void ohci_realize_pxa(DeviceState *dev, Error **errp)
   {
  -OHCISysBusState *s = FROM_SYSBUS(OHCISysBusState, dev);
  +OHCISysBusState *s = DO_UPCAST(OHCISysBusState, busdev.qdev, dev);
 
 I don't think this is an improvement. Until a QOM cast macro is
 available, FROM_SYSBUS is preferable to a DO_UPCAST I think?

patch 2 introduces QOM macro and replaces DO_UPCAST. Instead, we can
also first do QOM then realize. Which one do you prefer?

 
  +SysBusDevice *b = SYS_BUS_DEVICE(dev);
 
   /* Cannot fail as we pass NULL for masterbus */
  -usb_ohci_init(s-ohci, dev-qdev, s-num_ports, s-dma_offset, NULL, 
  0,
  +usb_ohci_init(s-ohci, dev, s-num_ports, s-dma_offset, NULL, 0,
 dma_context_memory);
 
 Rebase required due to Paolos IOMMU patches going in removing
 dma_context_memory.

Thanks for reminding. I'll do a rebase anyway, patches involving i440fx
and q35 may conflict with your `pci cleanup' series, and ehci patches
duplicates Andreas's work.




Re: [Qemu-devel] [Qemu-trivial] [PATCH 01/13] qemu-socket: zero-initialize SocketAddress

2013-06-24 Thread Gerd Hoffmann
On 06/21/13 20:15, Michael Tokarev wrote:
 21.06.2013 14:38, Gerd Hoffmann wrote:
 Signed-off-by: Gerd Hoffmann kra...@redhat.com
 ---
  util/qemu-sockets.c |2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

 diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
 index fdd8dc4..364bd8c 100644
 --- a/util/qemu-sockets.c
 +++ b/util/qemu-sockets.c
 @@ -855,7 +855,7 @@ SocketAddress *socket_parse(const char *str, Error 
 **errp)
  {
  SocketAddress *addr = NULL;
  
 -addr = g_new(SocketAddress, 1);
 +addr = g_new0(SocketAddress, 1);
 
 While at it we can remove the =NULL assignment too, guess, someting like this:
 
 --- a/util/qemu-sockets.c
 +++ b/util/qemu-sockets.c
 @@ -848,9 +848,7 @@ int unix_nonblocking_connect(const char *path,
 
  SocketAddress *socket_parse(const char *str, Error **errp)
  {
 -SocketAddress *addr = NULL;
 -
 -addr = g_new(SocketAddress, 1);
 +SocketAddress *addr = addr = g_new0(SocketAddress, 1);
  if (strstart(str, unix:, NULL)) {
  if (str[5] == '\0') {
  error_setg(errp, invalid Unix socket address);
 
 Is that okay with you? :)

Yes.

 And not that the original issue is a big issue really, because
 in each case each relevant field is initialized.

Except in the error cases.

cheers,
  Gerd





Re: [Qemu-devel] [PATCH v2] e600 core for MPC86xx processors

2013-06-24 Thread Julio Guerra
2013/6/24 Alexey Kardashevskiy a...@ozlabs.ru:
 On 06/21/2013 10:03 PM, Alexander Graf wrote:

 On 21.06.2013, at 14:01, Julio Guerra wrote:

 2013/6/21 Alexander Graf ag...@suse.de:

 On 26.05.2013, at 19:41, Julio Guerra wrote:

 MPC86xx processors are based on the e600 core, which is not the case
 in qemu where it is based on the 7400 processor.

 This patch creates the e600 core and instantiates the MPC86xx
 processors based on it. Therefore, adding the high BATs and the SPRG
 4..7 registers, which are e600-specific [1].

 This allows to define the MPC8610 processor too and my program running
 on a real MPC8610 target is now able to run on qemu :)

 [1] http://cache.freescale.com/files/32bit/doc/ref_manual/E600CORERM.pdf

 Signed-off-by: Julio Guerra gu...@julio.in

 Thanks, applied to ppc-next.


 I just retested this patch and I noticed the `handle_mmu_fault`
 default value introduced by recent A. Farber patches on the CPU
 definitions is wrong with the selected memory model. Thus qemu
 complains about the MMU model.

 The following is missing in e600 CPU definition:
 #if defined(CONFIG_SOFTMMU)
ppc-handle_mmu_fault = ppc_hash32_handle_mmu_fault;
 #endif

 Can you correct it or should I resend a patch (v3 or just the previous
 three lines) ?

 Just send a patch on top of the current one.


 I do not really understand what this patch actually does but it breaks my
 pseries/power7 setup. Please, help.


 Starting program: /home/aik/qemu-system-ppc64 -L qemu-ppc64-bios/ -trace
 events=qemu_trace_events -net nic,model=e1000,addr=0:0:0 -net
 user,hostfwd=tcp::5000-:22 -m 1024 -machine pseries -nographic -vga none
 -enable-kvm -kernel guest.vmlinux.n -initrd 1.cpio
 [Thread debugging using libthread_db enabled]
 Using host libthread_db library /lib64/libthread_db.so.1.
 **
 ERROR:/home/alexey/pcipassthru/qemu-impreza/qom/object.c:152:type_get_parent:
 assertion failed: (type-parent_type != NULL)

 Breakpoint 4, 0x0080c6eefb8c in .abort () from /lib64/libc.so.6
 Missing separate debuginfos, use: debuginfo-install SDL-1.2.15-8.fc19.ppc64
 bluez-libs-4.101-6.fc19.ppc64 boost-system-1.53.0-6.fc19.ppc64
 boost-thread-1.53.0-6.fc19.ppc64 brlapi-0.6.0-5.fc19.ppc64
 ceph-devel-0.56.4-1.fc19.ppc64 ceph-libs-0.56.4-1.fc19.ppc64
 cryptopp-5.6.2-2.fc19.ppc64 cyrus-sasl-lib-2.1.26-8.fc19.ppc64p7
 glib2-2.36.2-1.fc19.ppc64 glibc-2.17-4.fc19.ppc64p7
 glusterfs-3.4.0-0.5.beta2.fc19.ppc64
 glusterfs-api-3.4.0-0.5.beta2.fc19.ppc64 gmp-5.1.1-2.fc19.ppc64
 gnutls-3.1.11-1.fc19.ppc64 keyutils-libs-1.5.5-4.fc19.ppc64
 krb5-libs-1.11.2-10.fc19.ppc64 leveldb-1.9.0-1.fc19.ppc64
 libX11-1.5.99.902-1.fc19.ppc64 libXau-1.0.6-7.fc19.ppc64
 libcom_err-1.42.7-2.fc19.ppc64 libcurl-7.29.0-6.fc19.ppc64
 libfdt-1.3.0-6.fc19.ppc64 libgcc-4.8.0-8.fc19.ppc64
 libgcrypt-1.5.2-1.fc19.ppc64 libgpg-error-1.11-1.fc19.ppc64
 libidn-1.26-2.fc19.ppc64 libjpeg-turbo-1.2.90-2.fc19.ppc64
 libselinux-2.1.13-15.fc19.ppc64 libssh2-1.4.3-4.fc19.ppc64
 libstdc++-4.8.0-8.fc19.ppc64 libtasn1-3.3-1.fc19.ppc64
 libuuid-2.23.1-2.fc19.ppc64 libxcb-1.9-3.fc19.ppc64
 ncurses-libs-5.9-11.20130511.fc19.ppc64 nettle-2.6-2.fc19.ppc64
 nspr-4.9.6-1.fc19.ppc64 nss-3.14.3-13.0.fc19.ppc64
 nss-softokn-freebl-3.14.3-1.fc19.ppc64 nss-util-3.14.3-1.fc19.ppc64
 openldap-2.4.35-4.fc19.ppc64 openssl-libs-1.0.1e-4.fc19.ppc64p7
 p11-kit-0.18.3-1.fc19.ppc64 pcre-8.32-6.fc19.ppc64p7
 pixman-0.30.0-1.fc19.ppc64 snappy-1.1.0-1.fc19.ppc64 
 zlib-1.2.7-10.fc19.ppc64p7
 (gdb) up
 #1  0x0080c742d54c in .g_assertion_message () from /lib64/libglib-2.0.so.0
 (gdb)
 #2  0x0080c742d5f4 in .g_assertion_message_expr () from
 /lib64/libglib-2.0.so.0
 (gdb) bt
 #0  0x0080c6eefb8c in .abort () from /lib64/libc.so.6
 #1  0x0080c742d54c in .g_assertion_message () from /lib64/libglib-2.0.so.0
 #2  0x0080c742d5f4 in .g_assertion_message_expr () from
 /lib64/libglib-2.0.so.0
 #3  0x10260058 in type_get_parent (type=0x10f7b260)
 at /home/alexey/pcipassthru/qemu-impreza/qom/object.c:152
 #4  0x10260120 in type_class_get_size (ti=0x10f7b260)
 at /home/alexey/pcipassthru/qemu-impreza/qom/object.c:170
 #5  0x102603d8 in type_initialize (ti=0x10f7b260)
 at /home/alexey/pcipassthru/qemu-impreza/qom/object.c:236
 #6  0x1026175c in object_class_foreach_tramp (key=0x10f7b3e0,
 value=0x10f7b260,
 opaque=0x3fffe5e0) at
 /home/alexey/pcipassthru/qemu-impreza/qom/object.c:626
 #7  0x0080c73e0ab0 in .g_hash_table_foreach () from 
 /lib64/libglib-2.0.so.0
 #8  0x1026188c in object_class_foreach (fn=
 @0x10681290: 0x10261988 object_class_get_list_tramp,
 implements_type=0x105c7188 powerpc64-cpu, include_abstract=0x0,
 opaque=0x3fffe680)
 at /home/alexey/pcipassthru/qemu-impreza/qom/object.c:647
 #9  0x10261a3c in object_class_get_list (implements_type=0x105c7188
 powerpc64-cpu,
 include_abstract=0x0) at
 /home/alexey/pcipassthru/qemu-impreza/qom/object.c:679
 #10 0x10459dec in 

Re: [Qemu-devel] [PATCH 01/26] ohci: use realize for ohci

2013-06-24 Thread Peter Crosthwaite
Hi Hu,

On Mon, Jun 24, 2013 at 4:11 PM, Hu Tao hu...@cn.fujitsu.com wrote:
 On Mon, Jun 24, 2013 at 03:54:31PM +1000, Peter Crosthwaite wrote:
 Hi Hu,

 On Sat, Jun 22, 2013 at 6:50 PM, Hu Tao hu...@cn.fujitsu.com wrote:
  Cc: Gerd Hoffmann kra...@redhat.com
  Signed-off-by: Hu Tao hu...@cn.fujitsu.com
  ---
   hw/usb/hcd-ohci.c | 16 +++-
   1 file changed, 7 insertions(+), 9 deletions(-)
 
  diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c
  index 51241cd..79ef41b 100644
  --- a/hw/usb/hcd-ohci.c
  +++ b/hw/usb/hcd-ohci.c
  @@ -1876,17 +1876,16 @@ typedef struct {
   dma_addr_t dma_offset;
   } OHCISysBusState;
 
  -static int ohci_init_pxa(SysBusDevice *dev)
  +static void ohci_realize_pxa(DeviceState *dev, Error **errp)
   {
  -OHCISysBusState *s = FROM_SYSBUS(OHCISysBusState, dev);
  +OHCISysBusState *s = DO_UPCAST(OHCISysBusState, busdev.qdev, dev);

 I don't think this is an improvement. Until a QOM cast macro is
 available, FROM_SYSBUS is preferable to a DO_UPCAST I think?

 patch 2 introduces QOM macro and replaces DO_UPCAST. Instead, we can
 also first do QOM then realize. Which one do you prefer?


Other way round I think make more sense, as no need to have this ugly
hunk for transition sake.

Squashing is another low effort option, one patch that just does it
all makes sense to me (and ive done this a few times already with
various devices).

Regards,
Peter


  +SysBusDevice *b = SYS_BUS_DEVICE(dev);
 
   /* Cannot fail as we pass NULL for masterbus */
  -usb_ohci_init(s-ohci, dev-qdev, s-num_ports, s-dma_offset, 
  NULL, 0,
  +usb_ohci_init(s-ohci, dev, s-num_ports, s-dma_offset, NULL, 0,
 dma_context_memory);

 Rebase required due to Paolos IOMMU patches going in removing
 dma_context_memory.

 Thanks for reminding. I'll do a rebase anyway, patches involving i440fx
 and q35 may conflict with your `pci cleanup' series, and ehci patches
 duplicates Andreas's work.





Re: [Qemu-devel] [PATCH v2] vmdk: refuse to open higher version than supported

2013-06-24 Thread Fam Zheng
On Thu, 06/13 10:38, Stefan Hajnoczi wrote:
 On Thu, Jun 13, 2013 at 11:21:29AM +0800, Fam Zheng wrote:
  Refuse to open higher version for safety.
  
  Although we try to be compatible with published VMDK spec, VMware has
  newer version from ESXi 5.1 exported OVF/OVA, which we have no knowledge
  what's changed in it. And it is very likely to have more new versions in
  the future, so it's not safe to open them blindly.
  
  Signed-off-by: Fam Zheng f...@redhat.com
  
  ---
  
  v2: Report error and return -ENOTSUP.
  
  ---
   block/vmdk.c | 9 +
   1 file changed, 9 insertions(+)
 
 Reviewed-by: Stefan Hajnoczi stefa...@redhat.com

Is this OK to be applied? Thanks.

-- 
Fam



[Qemu-devel] [PATCH for mst/pci] output nc-name in NIC_RX_FILTER_CHANGED event

2013-06-24 Thread Amos Kong
netclient 'name' entry in event is useful for management to know
which device is changed. n-netclient_name is not always set.
This patch changes to use nc-name. If we don't assign 'id',
qemu will set a generated name to nc-name.

Signed-off-by: Amos Kong ak...@redhat.com
---
 hw/net/virtio-net.c | 11 +++
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index c88403a..e4d9752 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -200,14 +200,9 @@ static void rxfilter_notify(NetClientState *nc)
 VirtIONet *n = qemu_get_nic_opaque(nc);
 
 if (nc-rxfilter_notify_enabled) {
-if (n-netclient_name) {
-event_data = qobject_from_jsonf({ 'name': %s, 'path': %s },
-n-netclient_name,
-
object_get_canonical_path(OBJECT(n-qdev)));
-} else {
-event_data = qobject_from_jsonf({ 'path': %s },
-
object_get_canonical_path(OBJECT(n-qdev)));
-}
+event_data = qobject_from_jsonf({ 'name': %s, 'path': %s },
+   nc-name,
+   object_get_canonical_path(OBJECT(n-qdev)));
 monitor_protocol_event(QEVENT_NIC_RX_FILTER_CHANGED, event_data);
 qobject_decref(event_data);
 
-- 
1.8.1.4




[Qemu-devel] [PATCH v2 04/13] qemu-char: check optional fields using has_*

2013-06-24 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 qemu-char.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index 2c3cfe6..ee7c70e 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -3500,7 +3500,7 @@ static CharDriverState *qmp_chardev_open_file(ChardevFile 
*file, Error **errp)
 {
 HANDLE out;
 
-if (file-in) {
+if (file-has_in) {
 error_setg(errp, input file not supported);
 return NULL;
 }
@@ -3551,7 +3551,7 @@ static CharDriverState *qmp_chardev_open_file(ChardevFile 
*file, Error **errp)
 return NULL;
 }
 
-if (file-in) {
+if (file-has_in) {
 flags = O_RDONLY;
 in = qmp_chardev_open_file_source(file-in, flags, errp);
 if (error_is_set(errp)) {
-- 
1.7.9.7




[Qemu-devel] [PATCH v2 01/13] qemu-socket: zero-initialize SocketAddress

2013-06-24 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 util/qemu-sockets.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 96eca2a..86fb09c 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -848,9 +848,9 @@ int unix_nonblocking_connect(const char *path,
 
 SocketAddress *socket_parse(const char *str, Error **errp)
 {
-SocketAddress *addr = NULL;
+SocketAddress *addr;
 
-addr = g_new(SocketAddress, 1);
+addr = g_new0(SocketAddress, 1);
 if (strstart(str, unix:, NULL)) {
 if (str[5] == '\0') {
 error_setg(errp, invalid Unix socket address);
-- 
1.7.9.7




[Qemu-devel] [PATCH v2 00/13] A bunch of little socket + chardev fixes

2013-06-24 Thread Gerd Hoffmann
  Hi,

Here is v2 of the series, addressing Michaels review comments.

cheers,
  Gerd

Gerd Hoffmann (13):
  qemu-socket: zero-initialize SocketAddress
  qemu-socket: drop pointless allocation
  qemu-socket: catch monitor_get_fd failures
  qemu-char: check optional fields using has_*
  qemu-char: use more specific error_setg_* variants
  qemu-char: print notification to stderr
  qemu-char: fix documentation for telnet+wait socket flags
  qemu-char: don't leak opts on error
  qemu-char: use ChardevBackendKind in in CharDriver
  qemu-char: minor mux chardev fixes
  qemu-char: add -chardev mux support
  qemu-char: report udb backend errors
  qemu-socket: don't leak opts on error

 include/sysemu/char.h |2 +-
 qapi-schema.json  |7 ---
 qemu-char.c   |   45 -
 util/qemu-sockets.c   |9 -
 4 files changed, 41 insertions(+), 22 deletions(-)

-- 
1.7.9.7




[Qemu-devel] [PATCH v2 07/13] qemu-char: fix documentation for telnet+wait socket flags

2013-06-24 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 qapi-schema.json |7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/qapi-schema.json b/qapi-schema.json
index a80ee40..a29ce57 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3185,10 +3185,11 @@
 # @addr: socket address to listen on (server=true)
 #or connect to (server=false)
 # @server: #optional create server socket (default: true)
-# @wait: #optional wait for connect (not used for server
-#sockets, default: false)
+# @wait: #optional wait for incoming connection on server
+#sockets (default: false).
 # @nodelay: #optional set TCP_NODELAY socket option (default: false)
-# @telnet: #optional enable telnet protocol (default: false)
+# @telnet: #optional enable telnet protocol on server
+#  sockets (default: false)
 #
 # Since: 1.4
 ##
-- 
1.7.9.7




[Qemu-devel] [PATCH v2 03/13] qemu-socket: catch monitor_get_fd failures

2013-06-24 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 util/qemu-sockets.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 35023a8..126cbb6 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -903,7 +903,7 @@ int socket_connect(SocketAddress *addr, Error **errp,
 
 case SOCKET_ADDRESS_KIND_FD:
 fd = monitor_get_fd(cur_mon, addr-fd-str, errp);
-if (callback) {
+if (fd = 0  callback) {
 qemu_set_nonblock(fd);
 callback(fd, opaque);
 }
-- 
1.7.9.7




[Qemu-devel] [PATCH v2 06/13] qemu-char: print notification to stderr

2013-06-24 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 qemu-char.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index cfc68cd..3e0044b 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2666,8 +2666,8 @@ static CharDriverState *qemu_chr_open_socket_fd(int fd, 
bool do_nodelay,
 }
 
 if (is_listen  is_waitconnect) {
-printf(QEMU waiting for connection on: %s\n,
-   chr-filename);
+fprintf(stderr, QEMU waiting for connection on: %s\n,
+chr-filename);
 tcp_chr_accept(s-listen_chan, G_IO_IN, chr);
 qemu_set_nonblock(s-listen_fd);
 }
-- 
1.7.9.7




[Qemu-devel] [PATCH v2 05/13] qemu-char: use more specific error_setg_* variants

2013-06-24 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 qemu-char.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index ee7c70e..cfc68cd 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2604,7 +2604,7 @@ static CharDriverState *qemu_chr_open_socket_fd(int fd, 
bool do_nodelay,
 
 memset(ss, 0, ss_len);
 if (getsockname(fd, (struct sockaddr *) ss, ss_len) != 0) {
-error_setg(errp, getsockname: %s, strerror(errno));
+error_setg_errno(errp, errno, getsockname);
 return NULL;
 }
 
@@ -3536,7 +3536,7 @@ static int qmp_chardev_open_file_source(char *src, int 
flags,
 
 TFR(fd = qemu_open(src, flags, 0666));
 if (fd == -1) {
-error_setg(errp, open %s: %s, src, strerror(errno));
+error_setg_file_open(errp, errno, src);
 }
 return fd;
 }
-- 
1.7.9.7




[Qemu-devel] [PATCH v2 13/13] qemu-socket: don't leak opts on error

2013-06-24 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 util/qemu-sockets.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 126cbb6..095716e 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -963,7 +963,7 @@ int socket_dgram(SocketAddress *remote, SocketAddress 
*local, Error **errp)
 
 default:
 error_setg(errp, socket type unsupported for datagram);
-return -1;
+fd = -1;
 }
 qemu_opts_del(opts);
 return fd;
-- 
1.7.9.7




[Qemu-devel] [PATCH v2 11/13] qemu-char: add -chardev mux support

2013-06-24 Thread Gerd Hoffmann
Allow to explicitly create mux chardevs on the command line,
like you can using QMP.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 qemu-char.c |   18 ++
 1 file changed, 18 insertions(+)

diff --git a/qemu-char.c b/qemu-char.c
index e6c3157..7d072a8 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -3122,6 +3122,19 @@ static void qemu_chr_parse_memory(QemuOpts *opts, 
ChardevBackend *backend,
 }
 }
 
+static void qemu_chr_parse_mux(QemuOpts *opts, ChardevBackend *backend,
+   Error **errp)
+{
+const char *chardev = qemu_opt_get(opts, chardev);
+
+if (chardev == NULL) {
+error_setg(errp, chardev: mux: no chardev given);
+return;
+}
+backend-mux = g_new0(ChardevMux, 1);
+backend-mux-chardev = g_strdup(chardev);
+}
+
 typedef struct CharDriver {
 const char *name;
 /* old, pre qapi */
@@ -3488,6 +3501,9 @@ QemuOptsList qemu_chardev_opts = {
 },{
 .name = size,
 .type = QEMU_OPT_SIZE,
+},{
+.name = chardev,
+.type = QEMU_OPT_STRING,
 },
 { /* end of list */ }
 },
@@ -3778,6 +3794,8 @@ static void register_types(void)
 register_char_driver_qapi(console, CHARDEV_BACKEND_KIND_CONSOLE, NULL);
 register_char_driver_qapi(pipe, CHARDEV_BACKEND_KIND_PIPE,
   qemu_chr_parse_pipe);
+register_char_driver_qapi(mux, CHARDEV_BACKEND_KIND_MUX,
+  qemu_chr_parse_mux);
 }
 
 type_init(register_types);
-- 
1.7.9.7




[Qemu-devel] [PATCH v2 09/13] qemu-char: use ChardevBackendKind in in CharDriver

2013-06-24 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 include/sysemu/char.h |2 +-
 qemu-char.c   |4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/sysemu/char.h b/include/sysemu/char.h
index 066c216..e65e4a4 100644
--- a/include/sysemu/char.h
+++ b/include/sysemu/char.h
@@ -281,7 +281,7 @@ CharDriverState *qemu_chr_find(const char *name);
 QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename);
 
 void register_char_driver(const char *name, CharDriverState *(*open)(QemuOpts 
*));
-void register_char_driver_qapi(const char *name, int kind,
+void register_char_driver_qapi(const char *name, ChardevBackendKind kind,
 void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp));
 
 /* add an eventfd to the qemu devices that are polled */
diff --git a/qemu-char.c b/qemu-char.c
index 5751391..5a2291d 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -3127,7 +3127,7 @@ typedef struct CharDriver {
 /* old, pre qapi */
 CharDriverState *(*open)(QemuOpts *opts);
 /* new, qapi-based */
-int kind;
+ChardevBackendKind kind;
 void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp);
 } CharDriver;
 
@@ -3144,7 +3144,7 @@ void register_char_driver(const char *name, 
CharDriverState *(*open)(QemuOpts *)
 backends = g_slist_append(backends, s);
 }
 
-void register_char_driver_qapi(const char *name, int kind,
+void register_char_driver_qapi(const char *name, ChardevBackendKind kind,
 void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp))
 {
 CharDriver *s;
-- 
1.7.9.7




Re: [Qemu-devel] [PULL 00/21] pci,net,misc enhancements

2013-06-24 Thread Amos Kong
On Sun, Jun 23, 2013 at 02:38:04PM +0300, Michael S. Tsirkin wrote:
 On Fri, Jun 21, 2013 at 08:10:15AM -0500, Anthony Liguori wrote:
  Michael S. Tsirkin m...@redhat.com writes:
  
   From: Michael S. Tsirkin m...@redhat.com
  
   The following changes since commit 
   90a2541b763b31d2b551b07e24aae3de5266d31b:
  
 target-i386: fix over 80 chars warnings (2013-06-15 17:50:38 +)
  
   are available in the git repository at:
  
 git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_anthony
  
   for you to fetch changes up to f96c30047009f8a9c3cecf68104d8d99f989f54d:
  
 pci: Fold host_buses list into PCIHostState functionality
 (2013-06-19 18:35:05 +0300)
  
  SEGV's during pretty much any test I try to run during startup:
  
  Core was generated by 
  `/home/aliguori/build/qemu/x86_64-softmmu/qemu-system-x86_64 -kernel 
  /usr/local/'.
  Program terminated with signal 11, Segmentation fault.
  #0  qemu_get_queue (nic=0x0) at /home/aliguori/git/qemu/net/net.c:263
 
 
 It's caused by the rx filter patch, sorry about not catching it.

If we don't assign 'id' for virtio-net nic device, crash[1] will occur.
Your fix is right for that.

But anthony's calltrace seems different from that.

 I've fixed it up but will send a pull request without it,
 so it can get a bit more testing.

BTW, we can use 'nc-name' to avoid the rx-filter crash[1].
I have sent a patch for mst/pci.

-- 
Amos.

crash [1]

#0  0x759236b1 in __strlen_sse2_pminub () from /lib64/libc.so.6
#1  0x55873a8d in qstring_from_str (str=0x0) at qobject/qstring.c:72
#2  0x55876dae in parse_escape (ap=0x71c3c910, ctxt=0x7fffe4015650) 
at qobject/json-parser.c:614
#3  parse_value (ctxt=ctxt@entry=0x7fffe4015650, ap=ap@entry=0x71c3c910) at 
qobject/json-parser.c:691
#4  0x55876fd2 in parse_pair (ctxt=ctxt@entry=0x7fffe4015650, 
dict=dict@entry=0x7fffe4032400, ap=ap@entry=0x71c3c910) at 
qobject/json-parser.c:393
#5  0x558765fe in parse_object (ap=0x71c3c910, ctxt=0x7fffe4015650) 
at qobject/json-parser.c:454
#6  parse_value (ctxt=ctxt@entry=0x7fffe4015650, ap=ap@entry=0x71c3c910) at 
qobject/json-parser.c:686
#7  0x55877193 in json_parser_parse_err (tokens=optimized out, 
ap=0x71c3c910, errp=errp@entry=0x0) at qobject/json-parser.c:717
#8  0x5587729f in json_parser_parse (tokens=optimized out, 
ap=optimized out) at qobject/json-parser.c:705
#9  0x55875254 in parse_json (parser=0x71c3c8a0, tokens=optimized 
out) at qobject/qjson.c:34
#10 0x55875d6a in json_message_process_token (lexer=0x71c3c8a8, 
token=0x7fffe4015440, type=JSON_OPERATOR, x=26, y=0) at 
qobject/json-streamer.c:87
#11 0x5588a7af in json_lexer_feed_char 
(lexer=lexer@entry=0x71c3c8a8, ch=125 '}', flush=flush@entry=false) at 
qobject/json-lexer.c:303
#12 0x5588a8f6 in json_lexer_feed (lexer=lexer@entry=0x71c3c8a8, 
buffer=buffer@entry=0x558d1882 { 'name': %s, 'path': %s }, 
size=optimized out)
at qobject/json-lexer.c:356
#13 0x55875f81 in json_message_parser_feed 
(parser=parser@entry=0x71c3c8a0, buffer=buffer@entry=0x558d1882 { 
'name': %s, 'path': %s }, size=optimized out)
at qobject/json-streamer.c:110
#14 0x55875a2d in qobject_from_jsonv (string=0x558d1882 { 'name': 
%s, 'path': %s }, ap=ap@entry=0x71c3c910) at qobject/qjson.c:44
#15 0x55875b39 in qobject_from_jsonf 
(string=string@entry=0x558d1882 { 'name': %s, 'path': %s }) at 
qobject/qjson.c:66
#16 0x557b5477 in rxfilter_notify (nc=nc@entry=0x567463e0) at 
/home/devel/qemu/hw/net/virtio-net.c:203
#17 0x557b6fbe in virtio_net_handle_rx_mode (iov_cnt=optimized out, 
iov=0x71c44ab0, cmd=0 '\000', n=0x56756528) at 
/home/devel/qemu/hw/net/virtio-net.c:542
#18 virtio_net_handle_ctrl (vdev=0x56756528, vq=0x56767850) at 
/home/devel/qemu/hw/net/virtio-net.c:755
#19 0x557c7cf2 in access_with_adjusted_size (addr=addr@entry=16, 
value=value@entry=0x71c48b68, size=2, access_size_min=optimized out, 
access_size_max=optimized out, access=access@entry=0x557c8310 
memory_region_write_accessor, opaque=opaque@entry=0x567563e0) at 
/home/devel/qemu/memory.c:399
#20 0x557c93d7 in memory_region_iorange_write (iorange=optimized out, 
offset=16, width=2, data=2) at /home/devel/qemu/memory.c:475
#21 0x557c6a16 in kvm_handle_io (count=1, size=2, direction=1, 
data=optimized out, port=49232) at /home/devel/qemu/kvm-all.c:1510
#22 kvm_cpu_exec (env=env@entry=0x566d6660) at 
/home/devel/qemu/kvm-all.c:1659
#23 0x557706d5 in qemu_kvm_cpu_thread_fn (arg=0x566d6660) at 
/home/devel/qemu/cpus.c:759
#24 0x76985d15 in start_thread () from /lib64/libpthread.so.0
#25 0x758b548d in clone () from /lib64/libc.so.6




[Qemu-devel] [PATCH v2 08/13] qemu-char: don't leak opts on error

2013-06-24 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 qemu-char.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qemu-char.c b/qemu-char.c
index 3e0044b..5751391 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -3185,7 +3185,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
 if (i == NULL) {
 error_setg(errp, chardev: backend \%s\ not found,
qemu_opt_get(opts, backend));
-return NULL;
+goto err;
 }
 
 if (!cd-open) {
-- 
1.7.9.7




[Qemu-devel] [PATCH v2 12/13] qemu-char: report udb backend errors

2013-06-24 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 qemu-char.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/qemu-char.c b/qemu-char.c
index 7d072a8..dcc91bb 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2255,6 +2255,8 @@ static CharDriverState *qemu_chr_open_udp(QemuOpts *opts)
 
 fd = inet_dgram_opts(opts, local_err);
 if (fd  0) {
+qerror_report_err(local_err);
+error_free(local_err);
 return NULL;
 }
 return qemu_chr_open_udp_fd(fd);
-- 
1.7.9.7




[Qemu-devel] [PATCH v2 10/13] qemu-char: minor mux chardev fixes

2013-06-24 Thread Gerd Hoffmann
mux failure path has a memory leak.  creating a mux chardev can't
fail though, so just assert() that instead of fixing an error path
which never ever runs anyway ...

Also fix bid being leaked while being at it.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 qemu-char.c |7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index 5a2291d..e6c3157 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -3193,7 +3193,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
 ChardevBackend *backend = g_new0(ChardevBackend, 1);
 ChardevReturn *ret = NULL;
 const char *id = qemu_opts_id(opts);
-const char *bid = NULL;
+char *bid = NULL;
 
 if (qemu_opt_get_bool(opts, mux, 0)) {
 bid = g_strdup_printf(%s-base, id);
@@ -3220,9 +3220,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
 backend-kind = CHARDEV_BACKEND_KIND_MUX;
 backend-mux-chardev = g_strdup(bid);
 ret = qmp_chardev_add(id, backend, errp);
-if (error_is_set(errp)) {
-goto qapi_out;
-}
+assert(!error_is_set(errp));
 }
 
 chr = qemu_chr_find(id);
@@ -3230,6 +3228,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
 qapi_out:
 qapi_free_ChardevBackend(backend);
 qapi_free_ChardevReturn(ret);
+g_free(bid);
 return chr;
 }
 
-- 
1.7.9.7




[Qemu-devel] [PATCH v2 02/13] qemu-socket: drop pointless allocation

2013-06-24 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 util/qemu-sockets.c |1 -
 1 file changed, 1 deletion(-)

diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 86fb09c..35023a8 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -871,7 +871,6 @@ SocketAddress *socket_parse(const char *str, Error **errp)
 }
 } else {
 addr-kind = SOCKET_ADDRESS_KIND_INET;
-addr-inet = g_new(InetSocketAddress, 1);
 addr-inet = inet_parse(str, errp);
 if (addr-inet == NULL) {
 goto fail;
-- 
1.7.9.7




[Qemu-devel] [PULL 0/9] usb patch queue

2013-06-24 Thread Gerd Hoffmann
  Hi,

Here comes the usb patch queue, bringing QOM improvements for
ehci-sysbus, tegra2 ehci support and the usual share of little bug
fixes.

please pull,
  Gerd

The following changes since commit 576156ffed72ab4feb0b752979db86ff8759a2a1:

  Merge remote-tracking branch 'bonzini/iommu-for-anthony' into staging 
(2013-06-20 16:53:39 -0500)

are available in the git repository at:


  git://git.kraxel.org/qemu usb.84

for you to fetch changes up to 93c8e4dc386a243d7d417567d81dc1f1698478a4:

  usb: fix serial number for hid devices (2013-06-24 08:41:08 +0200)


Andreas Färber (3):
  usb/hcd-ehci-sysbus: Convert to QOM realize
  usb/hcd-ehci: Split off instance_init from realize
  usb/hcd-ehci: Add Tegra2 SysBus EHCI device

Gerd Hoffmann (3):
  usb-host-libusb: set USB_DEV_FLAG_IS_HOST
  usb: add serial bus property
  usb: fix serial number for hid devices

Hans de Goede (1):
  usb/host-libusb: Fix building with libusb git master code

Kuo-Jung Su (2):
  usb/hcd-ehci: Replace PORTSC macros with variables
  usb/hcd-ehci: Add Faraday FUSBH200 support

 hw/i386/pc_piix.c|   12 +
 hw/usb/bus.c |1 +
 hw/usb/desc.c|6 +++
 hw/usb/dev-hid.c |3 ++
 hw/usb/dev-storage.c |   13 ++---
 hw/usb/hcd-ehci-pci.c|   23 ++---
 hw/usb/hcd-ehci-sysbus.c |  121 +++---
 hw/usb/hcd-ehci.c|   50 +++
 hw/usb/hcd-ehci.h|   28 ---
 hw/usb/host-libusb.c |5 ++
 include/hw/usb.h |1 +
 11 files changed, 212 insertions(+), 51 deletions(-)



Re: [Qemu-devel] [PATCH v2] e600 core for MPC86xx processors

2013-06-24 Thread Alexander Graf


Am 24.06.2013 um 08:13 schrieb Julio Guerra gu...@julio.in:

 2013/6/24 Alexey Kardashevskiy a...@ozlabs.ru:
 On 06/21/2013 10:03 PM, Alexander Graf wrote:
 
 On 21.06.2013, at 14:01, Julio Guerra wrote:
 
 2013/6/21 Alexander Graf ag...@suse.de:
 
 On 26.05.2013, at 19:41, Julio Guerra wrote:
 
 MPC86xx processors are based on the e600 core, which is not the case
 in qemu where it is based on the 7400 processor.
 
 This patch creates the e600 core and instantiates the MPC86xx
 processors based on it. Therefore, adding the high BATs and the SPRG
 4..7 registers, which are e600-specific [1].
 
 This allows to define the MPC8610 processor too and my program running
 on a real MPC8610 target is now able to run on qemu :)
 
 [1] http://cache.freescale.com/files/32bit/doc/ref_manual/E600CORERM.pdf
 
 Signed-off-by: Julio Guerra gu...@julio.in
 
 Thanks, applied to ppc-next.
 
 I just retested this patch and I noticed the `handle_mmu_fault`
 default value introduced by recent A. Farber patches on the CPU
 definitions is wrong with the selected memory model. Thus qemu
 complains about the MMU model.
 
 The following is missing in e600 CPU definition:
 #if defined(CONFIG_SOFTMMU)
   ppc-handle_mmu_fault = ppc_hash32_handle_mmu_fault;
 #endif
 
 Can you correct it or should I resend a patch (v3 or just the previous
 three lines) ?
 
 Just send a patch on top of the current one.
 
 
 I do not really understand what this patch actually does but it breaks my
 pseries/power7 setup. Please, help.
 
 
 Starting program: /home/aik/qemu-system-ppc64 -L qemu-ppc64-bios/ -trace
 events=qemu_trace_events -net nic,model=e1000,addr=0:0:0 -net
 user,hostfwd=tcp::5000-:22 -m 1024 -machine pseries -nographic -vga none
 -enable-kvm -kernel guest.vmlinux.n -initrd 1.cpio
 [Thread debugging using libthread_db enabled]
 Using host libthread_db library /lib64/libthread_db.so.1.
 **
 ERROR:/home/alexey/pcipassthru/qemu-impreza/qom/object.c:152:type_get_parent:
 assertion failed: (type-parent_type != NULL)
 
 Breakpoint 4, 0x0080c6eefb8c in .abort () from /lib64/libc.so.6
 Missing separate debuginfos, use: debuginfo-install SDL-1.2.15-8.fc19.ppc64
 bluez-libs-4.101-6.fc19.ppc64 boost-system-1.53.0-6.fc19.ppc64
 boost-thread-1.53.0-6.fc19.ppc64 brlapi-0.6.0-5.fc19.ppc64
 ceph-devel-0.56.4-1.fc19.ppc64 ceph-libs-0.56.4-1.fc19.ppc64
 cryptopp-5.6.2-2.fc19.ppc64 cyrus-sasl-lib-2.1.26-8.fc19.ppc64p7
 glib2-2.36.2-1.fc19.ppc64 glibc-2.17-4.fc19.ppc64p7
 glusterfs-3.4.0-0.5.beta2.fc19.ppc64
 glusterfs-api-3.4.0-0.5.beta2.fc19.ppc64 gmp-5.1.1-2.fc19.ppc64
 gnutls-3.1.11-1.fc19.ppc64 keyutils-libs-1.5.5-4.fc19.ppc64
 krb5-libs-1.11.2-10.fc19.ppc64 leveldb-1.9.0-1.fc19.ppc64
 libX11-1.5.99.902-1.fc19.ppc64 libXau-1.0.6-7.fc19.ppc64
 libcom_err-1.42.7-2.fc19.ppc64 libcurl-7.29.0-6.fc19.ppc64
 libfdt-1.3.0-6.fc19.ppc64 libgcc-4.8.0-8.fc19.ppc64
 libgcrypt-1.5.2-1.fc19.ppc64 libgpg-error-1.11-1.fc19.ppc64
 libidn-1.26-2.fc19.ppc64 libjpeg-turbo-1.2.90-2.fc19.ppc64
 libselinux-2.1.13-15.fc19.ppc64 libssh2-1.4.3-4.fc19.ppc64
 libstdc++-4.8.0-8.fc19.ppc64 libtasn1-3.3-1.fc19.ppc64
 libuuid-2.23.1-2.fc19.ppc64 libxcb-1.9-3.fc19.ppc64
 ncurses-libs-5.9-11.20130511.fc19.ppc64 nettle-2.6-2.fc19.ppc64
 nspr-4.9.6-1.fc19.ppc64 nss-3.14.3-13.0.fc19.ppc64
 nss-softokn-freebl-3.14.3-1.fc19.ppc64 nss-util-3.14.3-1.fc19.ppc64
 openldap-2.4.35-4.fc19.ppc64 openssl-libs-1.0.1e-4.fc19.ppc64p7
 p11-kit-0.18.3-1.fc19.ppc64 pcre-8.32-6.fc19.ppc64p7
 pixman-0.30.0-1.fc19.ppc64 snappy-1.1.0-1.fc19.ppc64 
 zlib-1.2.7-10.fc19.ppc64p7
 (gdb) up
 #1  0x0080c742d54c in .g_assertion_message () from 
 /lib64/libglib-2.0.so.0
 (gdb)
 #2  0x0080c742d5f4 in .g_assertion_message_expr () from
 /lib64/libglib-2.0.so.0
 (gdb) bt
 #0  0x0080c6eefb8c in .abort () from /lib64/libc.so.6
 #1  0x0080c742d54c in .g_assertion_message () from 
 /lib64/libglib-2.0.so.0
 #2  0x0080c742d5f4 in .g_assertion_message_expr () from
 /lib64/libglib-2.0.so.0
 #3  0x10260058 in type_get_parent (type=0x10f7b260)
at /home/alexey/pcipassthru/qemu-impreza/qom/object.c:152
 #4  0x10260120 in type_class_get_size (ti=0x10f7b260)
at /home/alexey/pcipassthru/qemu-impreza/qom/object.c:170
 #5  0x102603d8 in type_initialize (ti=0x10f7b260)
at /home/alexey/pcipassthru/qemu-impreza/qom/object.c:236
 #6  0x1026175c in object_class_foreach_tramp (key=0x10f7b3e0,
 value=0x10f7b260,
opaque=0x3fffe5e0) at
 /home/alexey/pcipassthru/qemu-impreza/qom/object.c:626
 #7  0x0080c73e0ab0 in .g_hash_table_foreach () from 
 /lib64/libglib-2.0.so.0
 #8  0x1026188c in object_class_foreach (fn=
@0x10681290: 0x10261988 object_class_get_list_tramp,
implements_type=0x105c7188 powerpc64-cpu, include_abstract=0x0,
 opaque=0x3fffe680)
at /home/alexey/pcipassthru/qemu-impreza/qom/object.c:647
 #9  0x10261a3c in object_class_get_list (implements_type=0x105c7188
 powerpc64-cpu,
include_abstract=0x0) at
 

[Qemu-devel] [PATCH 6/9] usb/host-libusb: Fix building with libusb git master code

2013-06-24 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

The next libusb release will deprecate libusb_get_port_path, and since
we compile with -Werror, this breaks the build.

Signed-off-by: Hans de Goede hdego...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/host-libusb.c |4 
 1 file changed, 4 insertions(+)

diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
index 3a582c5..0c12b0f 100644
--- a/hw/usb/host-libusb.c
+++ b/hw/usb/host-libusb.c
@@ -241,7 +241,11 @@ static int usb_host_get_port(libusb_device *dev, char 
*port, size_t len)
 size_t off;
 int rc, i;
 
+#if LIBUSBX_API_VERSION = 0x01000102
+rc = libusb_get_port_numbers(dev, path, 7);
+#else
 rc = libusb_get_port_path(ctx, dev, path, 7);
+#endif
 if (rc  0) {
 return 0;
 }
-- 
1.7.9.7




[Qemu-devel] [PATCH 3/9] usb/hcd-ehci: Add Tegra2 SysBus EHCI device

2013-06-24 Thread Gerd Hoffmann
From: Andreas Färber andreas.faer...@web.de

This prepares an EHCI device for the Nvidia Tegra2 SoC family.
Values based on patch by Vincent Palatin and verified against TRM v01p.

Cc: Vincent Palatin vpala...@chromium.org
Signed-off-by: Andreas Färber andreas.faer...@web.de
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-ehci-sysbus.c |   15 +++
 hw/usb/hcd-ehci.h|1 +
 2 files changed, 16 insertions(+)

diff --git a/hw/usb/hcd-ehci-sysbus.c b/hw/usb/hcd-ehci-sysbus.c
index e450137..68667b5 100644
--- a/hw/usb/hcd-ehci-sysbus.c
+++ b/hw/usb/hcd-ehci-sysbus.c
@@ -104,11 +104,26 @@ static const TypeInfo ehci_exynos4210_type_info = {
 .class_init= ehci_exynos4210_class_init,
 };
 
+static void ehci_tegra2_class_init(ObjectClass *oc, void *data)
+{
+SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc);
+
+sec-capsbase = 0x100;
+sec-opregbase = 0x140;
+}
+
+static const TypeInfo ehci_tegra2_type_info = {
+.name  = TYPE_TEGRA2_EHCI,
+.parent= TYPE_SYS_BUS_EHCI,
+.class_init= ehci_tegra2_class_init,
+};
+
 static void ehci_sysbus_register_types(void)
 {
 type_register_static(ehci_type_info);
 type_register_static(ehci_xlnx_type_info);
 type_register_static(ehci_exynos4210_type_info);
+type_register_static(ehci_tegra2_type_info);
 }
 
 type_init(ehci_sysbus_register_types)
diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h
index 7a93957..2c03e8f 100644
--- a/hw/usb/hcd-ehci.h
+++ b/hw/usb/hcd-ehci.h
@@ -339,6 +339,7 @@ typedef struct EHCIPCIState {
 
 #define TYPE_SYS_BUS_EHCI sysbus-ehci-usb
 #define TYPE_EXYNOS4210_EHCI exynos4210-ehci-usb
+#define TYPE_TEGRA2_EHCI tegra2-ehci-usb
 
 #define SYS_BUS_EHCI(obj) \
 OBJECT_CHECK(EHCISysBusState, (obj), TYPE_SYS_BUS_EHCI)
-- 
1.7.9.7




[Qemu-devel] [PATCH 1/9] usb/hcd-ehci-sysbus: Convert to QOM realize

2013-06-24 Thread Gerd Hoffmann
From: Andreas Färber afaer...@suse.de

The SysBus qdev initfn merely calls SysBusDeviceClass::init, so we can
replace it with a realizefn already. This avoids getting into any initfn
ambiguity with the upcoming Faraday EHCI implementation.

Rename internal usb_ehci_initfn() to usb_ehci_realize() to allow to
return Errors from common initialization code as well.

Signed-off-by: Andreas Färber afaer...@suse.de
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-ehci-pci.c|2 +-
 hw/usb/hcd-ehci-sysbus.c |   13 ++---
 hw/usb/hcd-ehci.c|2 +-
 hw/usb/hcd-ehci.h|2 +-
 4 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/hw/usb/hcd-ehci-pci.c b/hw/usb/hcd-ehci-pci.c
index f1b5f5d..b352f73 100644
--- a/hw/usb/hcd-ehci-pci.c
+++ b/hw/usb/hcd-ehci-pci.c
@@ -68,7 +68,7 @@ static int usb_ehci_pci_initfn(PCIDevice *dev)
 s-capsbase = 0x00;
 s-opregbase = 0x20;
 
-usb_ehci_initfn(s, DEVICE(dev));
+usb_ehci_realize(s, DEVICE(dev), NULL);
 pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, s-mem);
 
 return 0;
diff --git a/hw/usb/hcd-ehci-sysbus.c b/hw/usb/hcd-ehci-sysbus.c
index f9e4fd3..3179e6f 100644
--- a/hw/usb/hcd-ehci-sysbus.c
+++ b/hw/usb/hcd-ehci-sysbus.c
@@ -32,8 +32,9 @@ static Property ehci_sysbus_properties[] = {
 DEFINE_PROP_END_OF_LIST(),
 };
 
-static int usb_ehci_sysbus_initfn(SysBusDevice *dev)
+static void usb_ehci_sysbus_realize(DeviceState *dev, Error **errp)
 {
+SysBusDevice *d = SYS_BUS_DEVICE(dev);
 EHCISysBusState *i = SYS_BUS_EHCI(dev);
 SysBusEHCIClass *sec = SYS_BUS_EHCI_GET_CLASS(dev);
 EHCIState *s = i-ehci;
@@ -42,18 +43,16 @@ static int usb_ehci_sysbus_initfn(SysBusDevice *dev)
 s-opregbase = sec-opregbase;
 s-as = address_space_memory;
 
-usb_ehci_initfn(s, DEVICE(dev));
-sysbus_init_irq(dev, s-irq);
-sysbus_init_mmio(dev, s-mem);
-return 0;
+usb_ehci_realize(s, dev, errp);
+sysbus_init_irq(d, s-irq);
+sysbus_init_mmio(d, s-mem);
 }
 
 static void ehci_sysbus_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k-init = usb_ehci_sysbus_initfn;
+dc-realize = usb_ehci_sysbus_realize;
 dc-vmsd = vmstate_ehci_sysbus;
 dc-props = ehci_sysbus_properties;
 }
diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 1ad2159..ea0379b 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -2508,7 +2508,7 @@ const VMStateDescription vmstate_ehci = {
 }
 };
 
-void usb_ehci_initfn(EHCIState *s, DeviceState *dev)
+void usb_ehci_realize(EHCIState *s, DeviceState *dev, Error **errp)
 {
 int i;
 
diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h
index 2fcb92f..15c7630 100644
--- a/hw/usb/hcd-ehci.h
+++ b/hw/usb/hcd-ehci.h
@@ -322,7 +322,7 @@ struct EHCIState {
 
 extern const VMStateDescription vmstate_ehci;
 
-void usb_ehci_initfn(EHCIState *s, DeviceState *dev);
+void usb_ehci_realize(EHCIState *s, DeviceState *dev, Error **errp);
 
 #define TYPE_PCI_EHCI pci-ehci-usb
 #define PCI_EHCI(obj) OBJECT_CHECK(EHCIPCIState, (obj), TYPE_PCI_EHCI)
-- 
1.7.9.7




[Qemu-devel] [PATCH 7/9] usb-host-libusb: set USB_DEV_FLAG_IS_HOST

2013-06-24 Thread Gerd Hoffmann
... like host-{linux,bsd}.c do.

Cc: qemu-sta...@nongnu.org
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/host-libusb.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
index 0c12b0f..e2f3cc8 100644
--- a/hw/usb/host-libusb.c
+++ b/hw/usb/host-libusb.c
@@ -895,6 +895,7 @@ static int usb_host_initfn(USBDevice *udev)
 USBHostDevice *s = USB_HOST_DEVICE(udev);
 
 loglevel = s-loglevel;
+udev-flags |= (1  USB_DEV_FLAG_IS_HOST);
 udev-auto_attach = 0;
 QTAILQ_INIT(s-requests);
 QTAILQ_INIT(s-isorings);
-- 
1.7.9.7




[Qemu-devel] [PATCH 8/9] usb: add serial bus property

2013-06-24 Thread Gerd Hoffmann
This patch adds a serial property for all usb devices, which can be
used to set the serial number of a usb device (as listed by lsusb -v)
to a specific value.  Applies to emulated devices only.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/bus.c |1 +
 hw/usb/desc.c|6 ++
 hw/usb/dev-hid.c |3 +++
 hw/usb/dev-storage.c |   13 +++--
 include/hw/usb.h |1 +
 5 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index d1827be..f83d1de 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -13,6 +13,7 @@ static int usb_qdev_exit(DeviceState *qdev);
 
 static Property usb_props[] = {
 DEFINE_PROP_STRING(port, USBDevice, port_path),
+DEFINE_PROP_STRING(serial, USBDevice, serial),
 DEFINE_PROP_BIT(full-path, USBDevice, flags,
 USB_DEV_FLAG_FULL_PATH, true),
 DEFINE_PROP_END_OF_LIST()
diff --git a/hw/usb/desc.c b/hw/usb/desc.c
index fce303e..bf6c522 100644
--- a/hw/usb/desc.c
+++ b/hw/usb/desc.c
@@ -566,6 +566,12 @@ void usb_desc_create_serial(USBDevice *dev)
 char *path;
 int dst;
 
+if (dev-serial) {
+/* 'serial' usb bus property has priority if present */
+usb_desc_set_string(dev, index, dev-serial);
+return;
+}
+
 assert(index != 0  desc-str[index] != NULL);
 dst = snprintf(serial, sizeof(serial), %s, desc-str[index]);
 path = qdev_get_dev_path(hcd);
diff --git a/hw/usb/dev-hid.c b/hw/usb/dev-hid.c
index b48899d..31f3cde 100644
--- a/hw/usb/dev-hid.c
+++ b/hw/usb/dev-hid.c
@@ -560,6 +560,9 @@ static int usb_hid_initfn(USBDevice *dev, int kind)
 {
 USBHIDState *us = DO_UPCAST(USBHIDState, dev, dev);
 
+if (dev-serial) {
+usb_desc_set_string(dev, STR_SERIALNUMBER, dev-serial);
+}
 usb_desc_init(dev);
 us-intr = usb_ep_get(dev, USB_TOKEN_IN, 1);
 hid_init(us-hid, kind, usb_hid_changed);
diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
index 1073901..fe914ab 100644
--- a/hw/usb/dev-storage.c
+++ b/hw/usb/dev-storage.c
@@ -58,7 +58,6 @@ typedef struct {
 USBPacket *packet;
 /* usb-storage only */
 BlockConf conf;
-char *serial;
 uint32_t removable;
 } MSDState;
 
@@ -602,7 +601,7 @@ static int usb_msd_initfn_storage(USBDevice *dev)
 return -1;
 }
 
-blkconf_serial(s-conf, s-serial);
+blkconf_serial(s-conf, dev-serial);
 
 /*
  * Hack alert: this pretends to be a block device, but it's really
@@ -616,16 +615,11 @@ static int usb_msd_initfn_storage(USBDevice *dev)
 bdrv_detach_dev(bs, s-dev.qdev);
 s-conf.bs = NULL;
 
-if (s-serial) {
-usb_desc_set_string(dev, STR_SERIALNUMBER, s-serial);
-} else {
-usb_desc_create_serial(dev);
-}
-
+usb_desc_create_serial(dev);
 usb_desc_init(dev);
 scsi_bus_new(s-bus, s-dev.qdev, usb_msd_scsi_info_storage, NULL);
 scsi_dev = scsi_bus_legacy_add_drive(s-bus, bs, 0, !!s-removable,
-s-conf.bootindex, s-serial);
+s-conf.bootindex, dev-serial);
 if (!scsi_dev) {
 return -1;
 }
@@ -734,7 +728,6 @@ static const VMStateDescription vmstate_usb_msd = {
 
 static Property msd_properties[] = {
 DEFINE_BLOCK_PROPERTIES(MSDState, conf),
-DEFINE_PROP_STRING(serial, MSDState, serial),
 DEFINE_PROP_BIT(removable, MSDState, removable, 0, false),
 DEFINE_PROP_END_OF_LIST(),
 };
diff --git a/include/hw/usb.h b/include/hw/usb.h
index 4d9d05e..901b0da 100644
--- a/include/hw/usb.h
+++ b/include/hw/usb.h
@@ -205,6 +205,7 @@ struct USBDevice {
 DeviceState qdev;
 USBPort *port;
 char *port_path;
+char *serial;
 void *opaque;
 uint32_t flags;
 
-- 
1.7.9.7




[Qemu-devel] [PATCH 9/9] usb: fix serial number for hid devices

2013-06-24 Thread Gerd Hoffmann
commit 7b074a22dab4bdda9864b933f1bc811a3db42845 changed the serial
number of hid devices.  Add compat properties to keep the old serial
number for qemu 0.12 and older.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/i386/pc_piix.c |   12 
 1 file changed, 12 insertions(+)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 97362f2..7972443 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -622,6 +622,18 @@ static QEMUMachine pc_machine_v0_13 = {
 .driver   = virtio-serial-pci,\
 .property = vectors,\
 .value= stringify(0),\
+},{\
+.driver   = usb-mouse,\
+.property = serial,\
+.value= 1,\
+},{\
+.driver   = usb-tablet,\
+.property = serial,\
+.value= 1,\
+},{\
+.driver   = usb-kbd,\
+.property = serial,\
+.value= 1,\
 }
 
 static QEMUMachine pc_machine_v0_12 = {
-- 
1.7.9.7




[Qemu-devel] [PATCH 5/9] usb/hcd-ehci: Add Faraday FUSBH200 support

2013-06-24 Thread Gerd Hoffmann
From: Kuo-Jung Su dant...@faraday-tech.com

Add Faraday FUSBH200 support, which is slightly different from EHCI spec.
(Or maybe simply a bad/wrong implementation...)

Signed-off-by: Kuo-Jung Su dant...@faraday-tech.com
Signed-off-by: Andreas Färber afaer...@suse.de
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-ehci-sysbus.c |   75 ++
 hw/usb/hcd-ehci.h|   12 
 2 files changed, 87 insertions(+)

diff --git a/hw/usb/hcd-ehci-sysbus.c b/hw/usb/hcd-ehci-sysbus.c
index bad9ca6..e7d4f74 100644
--- a/hw/usb/hcd-ehci-sysbus.c
+++ b/hw/usb/hcd-ehci-sysbus.c
@@ -124,12 +124,87 @@ static const TypeInfo ehci_tegra2_type_info = {
 .class_init= ehci_tegra2_class_init,
 };
 
+/*
+ * Faraday FUSBH200 USB 2.0 EHCI
+ */
+
+/**
+ * FUSBH200EHCIRegs:
+ * @FUSBH200_REG_EOF_ASTR: EOF/Async. Sleep Timer Register
+ * @FUSBH200_REG_BMCSR: Bus Monitor Control/Status Register
+ */
+enum FUSBH200EHCIRegs {
+FUSBH200_REG_EOF_ASTR = 0x34,
+FUSBH200_REG_BMCSR= 0x40,
+};
+
+static uint64_t fusbh200_ehci_read(void *opaque, hwaddr addr, unsigned size)
+{
+EHCIState *s = opaque;
+hwaddr off = s-opregbase + s-portscbase + 4 * s-portnr + addr;
+
+switch (off) {
+case FUSBH200_REG_EOF_ASTR:
+return 0x0041;
+case FUSBH200_REG_BMCSR:
+/* High-Speed, VBUS valid, interrupt level-high active */
+return (2  9) | (1  8) | (1  3);
+}
+
+return 0;
+}
+
+static void fusbh200_ehci_write(void *opaque, hwaddr addr, uint64_t val,
+unsigned size)
+{
+}
+
+static const MemoryRegionOps fusbh200_ehci_mmio_ops = {
+.read = fusbh200_ehci_read,
+.write = fusbh200_ehci_write,
+.valid.min_access_size = 4,
+.valid.max_access_size = 4,
+.endianness = DEVICE_LITTLE_ENDIAN,
+};
+
+static void fusbh200_ehci_init(Object *obj)
+{
+EHCISysBusState *i = SYS_BUS_EHCI(obj);
+FUSBH200EHCIState *f = FUSBH200_EHCI(obj);
+EHCIState *s = i-ehci;
+
+memory_region_init_io(f-mem_vendor, fusbh200_ehci_mmio_ops, s,
+  fusbh200, 0x4c);
+memory_region_add_subregion(s-mem,
+s-opregbase + s-portscbase + 4 * s-portnr,
+f-mem_vendor);
+}
+
+static void fusbh200_ehci_class_init(ObjectClass *oc, void *data)
+{
+SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc);
+
+sec-capsbase = 0x0;
+sec-opregbase = 0x10;
+sec-portscbase = 0x20;
+sec-portnr = 1;
+}
+
+static const TypeInfo ehci_fusbh200_type_info = {
+.name  = TYPE_FUSBH200_EHCI,
+.parent= TYPE_SYS_BUS_EHCI,
+.instance_size = sizeof(FUSBH200EHCIState),
+.instance_init = fusbh200_ehci_init,
+.class_init= fusbh200_ehci_class_init,
+};
+
 static void ehci_sysbus_register_types(void)
 {
 type_register_static(ehci_type_info);
 type_register_static(ehci_xlnx_type_info);
 type_register_static(ehci_exynos4210_type_info);
 type_register_static(ehci_tegra2_type_info);
+type_register_static(ehci_fusbh200_type_info);
 }
 
 type_init(ehci_sysbus_register_types)
diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h
index 1fb9483..15a28e8 100644
--- a/hw/usb/hcd-ehci.h
+++ b/hw/usb/hcd-ehci.h
@@ -338,6 +338,7 @@ typedef struct EHCIPCIState {
 #define TYPE_SYS_BUS_EHCI sysbus-ehci-usb
 #define TYPE_EXYNOS4210_EHCI exynos4210-ehci-usb
 #define TYPE_TEGRA2_EHCI tegra2-ehci-usb
+#define TYPE_FUSBH200_EHCI fusbh200-ehci-usb
 
 #define SYS_BUS_EHCI(obj) \
 OBJECT_CHECK(EHCISysBusState, (obj), TYPE_SYS_BUS_EHCI)
@@ -365,4 +366,15 @@ typedef struct SysBusEHCIClass {
 uint16_t portnr;
 } SysBusEHCIClass;
 
+#define FUSBH200_EHCI(obj) \
+OBJECT_CHECK(FUSBH200EHCIState, (obj), TYPE_FUSBH200_EHCI)
+
+typedef struct FUSBH200EHCIState {
+/* private */
+EHCISysBusState parent_obj;
+/* public */
+
+MemoryRegion mem_vendor;
+} FUSBH200EHCIState;
+
 #endif
-- 
1.7.9.7




[Qemu-devel] [PATCH 2/9] usb/hcd-ehci: Split off instance_init from realize

2013-06-24 Thread Gerd Hoffmann
From: Andreas Färber afaer...@suse.de

This makes the mem MemoryRegion available to derived instance_inits.

Keep the bus in realize for now since naming breaks in instance_init.

Signed-off-by: Andreas Färber afaer...@suse.de
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-ehci-pci.c|   19 ++-
 hw/usb/hcd-ehci-sysbus.c |   16 +---
 hw/usb/hcd-ehci.c|   28 
 hw/usb/hcd-ehci.h|1 +
 4 files changed, 44 insertions(+), 20 deletions(-)

diff --git a/hw/usb/hcd-ehci-pci.c b/hw/usb/hcd-ehci-pci.c
index b352f73..509867d 100644
--- a/hw/usb/hcd-ehci-pci.c
+++ b/hw/usb/hcd-ehci-pci.c
@@ -60,20 +60,28 @@ static int usb_ehci_pci_initfn(PCIDevice *dev)
 pci_conf[0x6e] = 0x00;
 pci_conf[0x6f] = 0xc0;  /* USBLEFCTLSTS */
 
-s-caps[0x09] = 0x68;/* EECP */
-
 s-irq = dev-irq[3];
 s-as = pci_get_address_space(dev);
 
-s-capsbase = 0x00;
-s-opregbase = 0x20;
-
 usb_ehci_realize(s, DEVICE(dev), NULL);
 pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, s-mem);
 
 return 0;
 }
 
+static void usb_ehci_pci_init(Object *obj)
+{
+EHCIPCIState *i = PCI_EHCI(obj);
+EHCIState *s = i-ehci;
+
+s-caps[0x09] = 0x68;/* EECP */
+
+s-capsbase = 0x00;
+s-opregbase = 0x20;
+
+usb_ehci_init(s, DEVICE(obj));
+}
+
 static void usb_ehci_pci_write_config(PCIDevice *dev, uint32_t addr,
   uint32_t val, int l)
 {
@@ -122,6 +130,7 @@ static const TypeInfo ehci_pci_type_info = {
 .name = TYPE_PCI_EHCI,
 .parent = TYPE_PCI_DEVICE,
 .instance_size = sizeof(EHCIPCIState),
+.instance_init = usb_ehci_pci_init,
 .abstract = true,
 .class_init = ehci_class_init,
 };
diff --git a/hw/usb/hcd-ehci-sysbus.c b/hw/usb/hcd-ehci-sysbus.c
index 3179e6f..e450137 100644
--- a/hw/usb/hcd-ehci-sysbus.c
+++ b/hw/usb/hcd-ehci-sysbus.c
@@ -36,15 +36,24 @@ static void usb_ehci_sysbus_realize(DeviceState *dev, Error 
**errp)
 {
 SysBusDevice *d = SYS_BUS_DEVICE(dev);
 EHCISysBusState *i = SYS_BUS_EHCI(dev);
-SysBusEHCIClass *sec = SYS_BUS_EHCI_GET_CLASS(dev);
+EHCIState *s = i-ehci;
+
+usb_ehci_realize(s, dev, errp);
+sysbus_init_irq(d, s-irq);
+}
+
+static void ehci_sysbus_init(Object *obj)
+{
+SysBusDevice *d = SYS_BUS_DEVICE(obj);
+EHCISysBusState *i = SYS_BUS_EHCI(obj);
+SysBusEHCIClass *sec = SYS_BUS_EHCI_GET_CLASS(obj);
 EHCIState *s = i-ehci;
 
 s-capsbase = sec-capsbase;
 s-opregbase = sec-opregbase;
 s-as = address_space_memory;
 
-usb_ehci_realize(s, dev, errp);
-sysbus_init_irq(d, s-irq);
+usb_ehci_init(s, DEVICE(obj));
 sysbus_init_mmio(d, s-mem);
 }
 
@@ -61,6 +70,7 @@ static const TypeInfo ehci_type_info = {
 .name  = TYPE_SYS_BUS_EHCI,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(EHCISysBusState),
+.instance_init = ehci_sysbus_init,
 .abstract  = true,
 .class_init= ehci_sysbus_class_init,
 .class_size= sizeof(SysBusEHCIClass),
diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index ea0379b..546032a 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -2512,6 +2512,22 @@ void usb_ehci_realize(EHCIState *s, DeviceState *dev, 
Error **errp)
 {
 int i;
 
+usb_bus_new(s-bus, ehci_bus_ops, dev);
+for (i = 0; i  NB_PORTS; i++) {
+usb_register_port(s-bus, s-ports[i], s, i, ehci_port_ops,
+  USB_SPEED_MASK_HIGH);
+s-ports[i].dev = 0;
+}
+
+s-frame_timer = qemu_new_timer_ns(vm_clock, ehci_frame_timer, s);
+s-async_bh = qemu_bh_new(ehci_frame_timer, s);
+
+qemu_register_reset(ehci_reset, s);
+qemu_add_vm_change_state_handler(usb_ehci_vm_state_change, s);
+}
+
+void usb_ehci_init(EHCIState *s, DeviceState *dev)
+{
 /* 2.2 host controller interface version */
 s-caps[0x00] = (uint8_t)(s-opregbase - s-capsbase);
 s-caps[0x01] = 0x00;
@@ -2525,22 +2541,10 @@ void usb_ehci_realize(EHCIState *s, DeviceState *dev, 
Error **errp)
 s-caps[0x0a] = 0x00;
 s-caps[0x0b] = 0x00;
 
-usb_bus_new(s-bus, ehci_bus_ops, dev);
-for(i = 0; i  NB_PORTS; i++) {
-usb_register_port(s-bus, s-ports[i], s, i, ehci_port_ops,
-  USB_SPEED_MASK_HIGH);
-s-ports[i].dev = 0;
-}
-
-s-frame_timer = qemu_new_timer_ns(vm_clock, ehci_frame_timer, s);
-s-async_bh = qemu_bh_new(ehci_frame_timer, s);
 QTAILQ_INIT(s-aqueues);
 QTAILQ_INIT(s-pqueues);
 usb_packet_init(s-ipacket);
 
-qemu_register_reset(ehci_reset, s);
-qemu_add_vm_change_state_handler(usb_ehci_vm_state_change, s);
-
 memory_region_init(s-mem, ehci, MMIO_SIZE);
 memory_region_init_io(s-mem_caps, ehci_mmio_caps_ops, s,
   capabilities, CAPA_SIZE);
diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h
index 15c7630..7a93957 100644
--- a/hw/usb/hcd-ehci.h
+++ b/hw/usb/hcd-ehci.h

[Qemu-devel] [PATCH 4/9] usb/hcd-ehci: Replace PORTSC macros with variables

2013-06-24 Thread Gerd Hoffmann
From: Kuo-Jung Su dant...@faraday-tech.com

Replace PORTSC macros with variables which could then be
configured in ehci__class_init(...)

Signed-off-by: Kuo-Jung Su dant...@faraday-tech.com
Signed-off-by: Andreas Färber afaer...@suse.de
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-ehci-pci.c|2 ++
 hw/usb/hcd-ehci-sysbus.c |6 ++
 hw/usb/hcd-ehci.c|   22 ++
 hw/usb/hcd-ehci.h|   12 ++--
 4 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/hw/usb/hcd-ehci-pci.c b/hw/usb/hcd-ehci-pci.c
index 509867d..5d229bc 100644
--- a/hw/usb/hcd-ehci-pci.c
+++ b/hw/usb/hcd-ehci-pci.c
@@ -78,6 +78,8 @@ static void usb_ehci_pci_init(Object *obj)
 
 s-capsbase = 0x00;
 s-opregbase = 0x20;
+s-portscbase = 0x44;
+s-portnr = NB_PORTS;
 
 usb_ehci_init(s, DEVICE(obj));
 }
diff --git a/hw/usb/hcd-ehci-sysbus.c b/hw/usb/hcd-ehci-sysbus.c
index 68667b5..bad9ca6 100644
--- a/hw/usb/hcd-ehci-sysbus.c
+++ b/hw/usb/hcd-ehci-sysbus.c
@@ -51,6 +51,8 @@ static void ehci_sysbus_init(Object *obj)
 
 s-capsbase = sec-capsbase;
 s-opregbase = sec-opregbase;
+s-portscbase = sec-portscbase;
+s-portnr = sec-portnr;
 s-as = address_space_memory;
 
 usb_ehci_init(s, DEVICE(obj));
@@ -60,6 +62,10 @@ static void ehci_sysbus_init(Object *obj)
 static void ehci_sysbus_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
+SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(klass);
+
+sec-portscbase = 0x44;
+sec-portnr = NB_PORTS;
 
 dc-realize = usb_ehci_sysbus_realize;
 dc-vmsd = vmstate_ehci_sysbus;
diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 546032a..16d6356 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -995,7 +995,7 @@ static uint64_t ehci_port_read(void *ptr, hwaddr addr,
 uint32_t val;
 
 val = s-portsc[addr  2];
-trace_usb_ehci_portsc_read(addr + PORTSC_BEGIN, addr  2, val);
+trace_usb_ehci_portsc_read(addr + s-portscbase, addr  2, val);
 return val;
 }
 
@@ -1036,7 +1036,7 @@ static void ehci_port_write(void *ptr, hwaddr addr,
 uint32_t old = *portsc;
 USBDevice *dev = s-ports[port].dev;
 
-trace_usb_ehci_portsc_write(addr + PORTSC_BEGIN, addr  2, val);
+trace_usb_ehci_portsc_write(addr + s-portscbase, addr  2, val);
 
 /* Clear rwc bits */
 *portsc = ~(val  PORTSC_RWC_MASK);
@@ -1069,7 +1069,7 @@ static void ehci_port_write(void *ptr, hwaddr addr,
 
 *portsc = ~PORTSC_RO_MASK;
 *portsc |= val;
-trace_usb_ehci_portsc_change(addr + PORTSC_BEGIN, addr  2, *portsc, old);
+trace_usb_ehci_portsc_change(addr + s-portscbase, addr  2, *portsc, 
old);
 }
 
 static void ehci_opreg_write(void *ptr, hwaddr addr,
@@ -2512,8 +2512,14 @@ void usb_ehci_realize(EHCIState *s, DeviceState *dev, 
Error **errp)
 {
 int i;
 
+if (s-portnr  NB_PORTS) {
+error_setg(errp, Too many ports! Max. port number is %d.,
+   NB_PORTS);
+return;
+}
+
 usb_bus_new(s-bus, ehci_bus_ops, dev);
-for (i = 0; i  NB_PORTS; i++) {
+for (i = 0; i  s-portnr; i++) {
 usb_register_port(s-bus, s-ports[i], s, i, ehci_port_ops,
   USB_SPEED_MASK_HIGH);
 s-ports[i].dev = 0;
@@ -2533,7 +2539,7 @@ void usb_ehci_init(EHCIState *s, DeviceState *dev)
 s-caps[0x01] = 0x00;
 s-caps[0x02] = 0x00;
 s-caps[0x03] = 0x01;/* HC version */
-s-caps[0x04] = NB_PORTS;/* Number of downstream ports */
+s-caps[0x04] = s-portnr;   /* Number of downstream ports */
 s-caps[0x05] = 0x00;/* No companion ports at present */
 s-caps[0x06] = 0x00;
 s-caps[0x07] = 0x00;
@@ -2549,13 +2555,13 @@ void usb_ehci_init(EHCIState *s, DeviceState *dev)
 memory_region_init_io(s-mem_caps, ehci_mmio_caps_ops, s,
   capabilities, CAPA_SIZE);
 memory_region_init_io(s-mem_opreg, ehci_mmio_opreg_ops, s,
-  operational, PORTSC_BEGIN);
+  operational, s-portscbase);
 memory_region_init_io(s-mem_ports, ehci_mmio_port_ops, s,
-  ports, PORTSC_END - PORTSC_BEGIN);
+  ports, 4 * s-portnr);
 
 memory_region_add_subregion(s-mem, s-capsbase, s-mem_caps);
 memory_region_add_subregion(s-mem, s-opregbase, s-mem_opreg);
-memory_region_add_subregion(s-mem, s-opregbase + PORTSC_BEGIN,
+memory_region_add_subregion(s-mem, s-opregbase + s-portscbase,
 s-mem_ports);
 }
 
diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h
index 2c03e8f..1fb9483 100644
--- a/hw/usb/hcd-ehci.h
+++ b/hw/usb/hcd-ehci.h
@@ -40,11 +40,7 @@
 #define MMIO_SIZE0x1000
 #define CAPA_SIZE0x10
 
-#define PORTSC   0x0044
-#define PORTSC_BEGIN PORTSC
-#define PORTSC_END   (PORTSC + 4 * NB_PORTS)
-
-#define NB_PORTS 6/* Number of downstream ports 

[Qemu-devel] [PATCH v2 00/30] PCI: Cleanup legacy casts in device land

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

There are a number of different cast implementations from various
stages of QEMU development out in device model land. This series cleans
up the ones involving TYPE_PCI_DEVICE to consistently use proper QOM
casts for both up and down casts.

Some were easy, some needed QOM cast macros which are added as
appropriate.

Following the recent discussion RE performance consequences of QOM
casts, im interested in any reports of possible performance regressions
here, although I am hoping that Anthony current efforts to improve
QOM casting efficiency make this a non-issue.

Changed since V1:
Removed hunks which macroified VMSD names
Dropped virtio/virtio.pci patch
Rebased


Peter Crosthwaite (30):
  net/e1000: QOM Upcast Sweep
  net/rtl8139: QOM Upcast Sweep
  net/pcnet-pci: QOM Upcast Sweep
  usb/hcd-xhci: QOM Upcast Sweep
  scsi/lsi53c895a: QOM Upcast Sweep
  scsi/megasas: QOM Upcast Sweep
  scsi/esp-pci: QOM Upcast Sweep
  ide/ich: QOM Upcast Sweep
  ide/piix: QOM casting sweep
  acpi/piix4: QOM Upcast Sweep
  misc/pci-testdev: QOM Upcast Sweep
  virtio/vmware_vga: QOM casting sweep
  misc/ivshmem: QOM Upcast Sweep
  xen/xen_platform: QOM casting sweep
  isa/*: QOM casting sweep
  pci/*: QOM casting sweep
  pci-bridge/pci_bridge_dev: Don't use DO_UPCAST
  pci-bridge/*: substitute -qdev casts with DEVICE()
  pci/pci_bridge: substitute -qdev casts with DEVICE()
  misc/vfio: substitute -qdev casts with DEVICE()
  net/eepro100: substitute -qdev casts with DEVICE()
  net/ne2000: substitute -qdev casts with DEVICE()
  usb/*: substitute -qdev casts with DEVICE()
  watchdog/wdt_i6300esb: substitute -qdev casts with DEVICE()
  scsi/vmw_pvscsi: substitute -qdev casts with DEVICE()
  i2c/smbus_ich9: substitute -qdev casts with DEVICE()
  ide/cmd646: substitute -qdev casts with DEVICE()
  ide/via: substitute -qdev casts with DEVICE()
  pci-host/*: substitute -qdev casts with DEVICE()
  i386/*: substitute -qdev casts with DEVICE()

 hw/acpi/piix4.c| 31 +--
 hw/display/vmware_vga.c| 13 -
 hw/i2c/smbus_ich9.c|  2 +-
 hw/i386/kvm/pci-assign.c   | 21 -
 hw/i386/pc.c   |  3 ++-
 hw/i386/pc_piix.c  |  4 ++--
 hw/i386/pc_q35.c   |  4 ++--
 hw/ide/ahci.h  |  5 +
 hw/ide/cmd646.c|  8 
 hw/ide/ich.c   | 10 +-
 hw/ide/piix.c  |  8 
 hw/ide/via.c   |  4 ++--
 hw/isa/i82378.c|  8 
 hw/isa/lpc_ich9.c  |  6 +++---
 hw/misc/ivshmem.c  | 18 +++---
 hw/misc/pci-testdev.c  | 11 ---
 hw/misc/vfio.c |  4 ++--
 hw/net/e1000.c | 18 --
 hw/net/eepro100.c  | 14 --
 hw/net/ne2000.c|  6 --
 hw/net/pcnet-pci.c | 14 +-
 hw/net/rtl8139.c   | 26 ++
 hw/pci-bridge/dec.c|  2 +-
 hw/pci-bridge/i82801b11.c  |  2 +-
 hw/pci-bridge/ioh3420.c|  2 +-
 hw/pci-bridge/pci_bridge_dev.c |  2 +-
 hw/pci-bridge/xio3130_downstream.c |  2 +-
 hw/pci-bridge/xio3130_upstream.c   |  2 +-
 hw/pci-host/apb.c  |  4 ++--
 hw/pci-host/q35.c  |  4 ++--
 hw/pci/pci-hotplug.c   | 18 ++
 hw/pci/pci.c   | 17 +
 hw/pci/pci_bridge.c|  7 ---
 hw/pci/pcie.c  |  4 ++--
 hw/pci/shpc.c  |  8 
 hw/scsi/esp-pci.c  | 14 +-
 hw/scsi/lsi53c895a.c   | 26 --
 hw/scsi/megasas.c  | 15 ++-
 hw/scsi/vmw_pvscsi.c   |  2 +-
 hw/usb/hcd-ehci-pci.c  | 13 -
 hw/usb/hcd-ohci.c  |  2 +-
 hw/usb/hcd-uhci.c  |  2 +-
 hw/usb/hcd-xhci.c  | 19 +--
 hw/watchdog/wdt_i6300esb.c |  2 +-
 hw/xen/xen_platform.c  | 28 
 45 files changed, 258 insertions(+), 177 deletions(-)

-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 01/30] net/e1000: QOM Upcast Sweep

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Define and use standard QOM cast macro. Remove usages of DO_UPCAST
and direct - style upcasting.

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/net/e1000.c | 18 --
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/hw/net/e1000.c b/hw/net/e1000.c
index e6f46f0..27c4221 100644
--- a/hw/net/e1000.c
+++ b/hw/net/e1000.c
@@ -138,6 +138,11 @@ typedef struct E1000State_st {
 uint32_t compat_flags;
 } E1000State;
 
+#define TYPE_E1000 e1000
+
+#define E1000(obj) \
+OBJECT_CHECK(E1000State, (obj), TYPE_E1000)
+
 #definedefreg(x)   x = (E1000_##x2)
 enum {
 defreg(CTRL),  defreg(EECD),   defreg(EERD),   defreg(GPRC),
@@ -1296,7 +1301,7 @@ e1000_cleanup(NetClientState *nc)
 static void
 pci_e1000_uninit(PCIDevice *dev)
 {
-E1000State *d = DO_UPCAST(E1000State, dev, dev);
+E1000State *d = E1000(dev);
 
 qemu_del_timer(d-autoneg_timer);
 qemu_free_timer(d-autoneg_timer);
@@ -1316,7 +1321,8 @@ static NetClientInfo net_e1000_info = {
 
 static int pci_e1000_init(PCIDevice *pci_dev)
 {
-E1000State *d = DO_UPCAST(E1000State, dev, pci_dev);
+DeviceState *dev = DEVICE(pci_dev);
+E1000State *d = E1000(pci_dev);
 uint8_t *pci_conf;
 uint16_t checksum = 0;
 int i;
@@ -1347,11 +1353,11 @@ static int pci_e1000_init(PCIDevice *pci_dev)
 d-eeprom_data[EEPROM_CHECKSUM_REG] = checksum;
 
 d-nic = qemu_new_nic(net_e1000_info, d-conf,
-  object_get_typename(OBJECT(d)), d-dev.qdev.id, d);
+  object_get_typename(OBJECT(d)), dev-id, d);
 
 qemu_format_nic_info_str(qemu_get_queue(d-nic), macaddr);
 
-add_boot_device_path(d-conf.bootindex, pci_dev-qdev, /ethernet-phy@0);
+add_boot_device_path(d-conf.bootindex, dev, /ethernet-phy@0);
 
 d-autoneg_timer = qemu_new_timer_ms(vm_clock, e1000_autoneg_timer, d);
 
@@ -1360,7 +1366,7 @@ static int pci_e1000_init(PCIDevice *pci_dev)
 
 static void qdev_e1000_reset(DeviceState *dev)
 {
-E1000State *d = DO_UPCAST(E1000State, dev.qdev, dev);
+E1000State *d = E1000(dev);
 e1000_reset(d);
 }
 
@@ -1390,7 +1396,7 @@ static void e1000_class_init(ObjectClass *klass, void 
*data)
 }
 
 static const TypeInfo e1000_info = {
-.name  = e1000,
+.name  = TYPE_E1000,
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(E1000State),
 .class_init= e1000_class_init,
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 02/30] net/rtl8139: QOM Upcast Sweep

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Define and use standard QOM cast macro. Remove usages of DO_UPCAST
and direct - style upcasting.

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/net/rtl8139.c | 26 ++
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c
index 7993f9f..955d35e 100644
--- a/hw/net/rtl8139.c
+++ b/hw/net/rtl8139.c
@@ -92,6 +92,11 @@ static inline GCC_FMT_ATTR(1, 2) int DPRINTF(const char 
*fmt, ...)
 }
 #endif
 
+#define TYPE_RTL8139 rtl8139
+
+#define RTL8139(obj) \
+ OBJECT_CHECK(RTL8139State, (obj), TYPE_RTL8139)
+
 /* Symbolic offsets to registers. */
 enum RTL8139_registers {
 MAC0 = 0,/* Ethernet hardware address. */
@@ -1197,7 +1202,7 @@ static void rtl8139_reset_rxring(RTL8139State *s, 
uint32_t bufferSize)
 
 static void rtl8139_reset(DeviceState *d)
 {
-RTL8139State *s = container_of(d, RTL8139State, dev.qdev);
+RTL8139State *s = RTL8139(d);
 int i;
 
 /* restore MAC address */
@@ -1364,6 +1369,8 @@ static const VMStateDescription vmstate_tally_counters = {
 
 static void rtl8139_ChipCmd_write(RTL8139State *s, uint32_t val)
 {
+DeviceState *d = DEVICE(s);
+
 val = 0xff;
 
 DPRINTF(ChipCmd write val=0x%08x\n, val);
@@ -1371,7 +1378,7 @@ static void rtl8139_ChipCmd_write(RTL8139State *s, 
uint32_t val)
 if (val  CmdReset)
 {
 DPRINTF(ChipCmd reset\n);
-rtl8139_reset(s-dev.qdev);
+rtl8139_reset(d);
 }
 if (val  CmdRxEnb)
 {
@@ -1525,6 +1532,8 @@ static uint32_t rtl8139_BasicModeStatus_read(RTL8139State 
*s)
 
 static void rtl8139_Cfg9346_write(RTL8139State *s, uint32_t val)
 {
+DeviceState *d = DEVICE(s);
+
 val = 0xff;
 
 DPRINTF(Cfg9346 write val=0x%02x\n, val);
@@ -1544,7 +1553,7 @@ static void rtl8139_Cfg9346_write(RTL8139State *s, 
uint32_t val)
 } else if (opmode == 0x40) {
 /* Reset.  */
 val = 0;
-rtl8139_reset(s-dev.qdev);
+rtl8139_reset(d);
 }
 
 s-Cfg9346 = val;
@@ -3439,7 +3448,7 @@ static void rtl8139_cleanup(NetClientState *nc)
 
 static void pci_rtl8139_uninit(PCIDevice *dev)
 {
-RTL8139State *s = DO_UPCAST(RTL8139State, dev, dev);
+RTL8139State *s = RTL8139(dev);
 
 memory_region_destroy(s-bar_io);
 memory_region_destroy(s-bar_mem);
@@ -3477,7 +3486,8 @@ static NetClientInfo net_rtl8139_info = {
 
 static int pci_rtl8139_init(PCIDevice *dev)
 {
-RTL8139State * s = DO_UPCAST(RTL8139State, dev, dev);
+RTL8139State *s = RTL8139(dev);
+DeviceState *d = DEVICE(dev);
 uint8_t *pci_conf;
 
 pci_conf = s-dev.config;
@@ -3505,7 +3515,7 @@ static int pci_rtl8139_init(PCIDevice *dev)
 s-eeprom.contents[9] = s-conf.macaddr.a[4] | s-conf.macaddr.a[5]  8;
 
 s-nic = qemu_new_nic(net_rtl8139_info, s-conf,
-  object_get_typename(OBJECT(dev)), dev-qdev.id, s);
+  object_get_typename(OBJECT(dev)), d-id, s);
 qemu_format_nic_info_str(qemu_get_queue(s-nic), s-conf.macaddr.a);
 
 s-cplus_txbuffer = NULL;
@@ -3516,7 +3526,7 @@ static int pci_rtl8139_init(PCIDevice *dev)
 s-timer = qemu_new_timer_ns(vm_clock, rtl8139_timer, s);
 rtl8139_set_next_tctr_time(s, qemu_get_clock_ns(vm_clock));
 
-add_boot_device_path(s-conf.bootindex, dev-qdev, /ethernet-phy@0);
+add_boot_device_path(s-conf.bootindex, d, /ethernet-phy@0);
 
 return 0;
 }
@@ -3544,7 +3554,7 @@ static void rtl8139_class_init(ObjectClass *klass, void 
*data)
 }
 
 static const TypeInfo rtl8139_info = {
-.name  = rtl8139,
+.name  = TYPE_RTL8139,
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(RTL8139State),
 .class_init= rtl8139_class_init,
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 03/30] net/pcnet-pci: QOM Upcast Sweep

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Define and use standard QOM cast macro. Remove usages of DO_UPCAST
and direct - style upcasting.

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/net/pcnet-pci.c | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/hw/net/pcnet-pci.c b/hw/net/pcnet-pci.c
index 9df2b87..b1afbf4 100644
--- a/hw/net/pcnet-pci.c
+++ b/hw/net/pcnet-pci.c
@@ -43,6 +43,10 @@
 //#define PCNET_DEBUG_TMD
 //#define PCNET_DEBUG_MATCH
 
+#define TYPE_PCI_PC_NET pcnet
+
+#define PCI_PC_NET(obj) \
+ OBJECT_CHECK(PCIPCNetState, (obj), TYPE_PCI_PC_NET)
 
 typedef struct {
 PCIDevice pci_dev;
@@ -273,7 +277,7 @@ static void pci_pcnet_cleanup(NetClientState *nc)
 
 static void pci_pcnet_uninit(PCIDevice *dev)
 {
-PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev, dev);
+PCIPCNetState *d = PCI_PC_NET(dev);
 
 memory_region_destroy(d-state.mmio);
 memory_region_destroy(d-io_bar);
@@ -293,7 +297,7 @@ static NetClientInfo net_pci_pcnet_info = {
 
 static int pci_pcnet_init(PCIDevice *pci_dev)
 {
-PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev, pci_dev);
+PCIPCNetState *d = PCI_PC_NET(pci_dev);
 PCNetState *s = d-state;
 uint8_t *pci_conf;
 
@@ -329,12 +333,12 @@ static int pci_pcnet_init(PCIDevice *pci_dev)
 s-phys_mem_write = pci_physical_memory_write;
 s-dma_opaque = pci_dev;
 
-return pcnet_common_init(pci_dev-qdev, s, net_pci_pcnet_info);
+return pcnet_common_init(DEVICE(pci_dev), s, net_pci_pcnet_info);
 }
 
 static void pci_reset(DeviceState *dev)
 {
-PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev.qdev, dev);
+PCIPCNetState *d = PCI_PC_NET(dev);
 
 pcnet_h_reset(d-state);
 }
@@ -362,7 +366,7 @@ static void pcnet_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo pcnet_info = {
-.name  = pcnet,
+.name  = TYPE_PCI_PC_NET,
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(PCIPCNetState),
 .class_init= pcnet_class_init,
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 04/30] usb/hcd-xhci: QOM Upcast Sweep

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Define and use standard QOM cast macro. Remove usages of DO_UPCAST
and direct - style upcasting.

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/usb/hcd-xhci.c | 19 +--
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 91633ed..0146711 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -482,6 +482,11 @@ struct XHCIState {
 XHCIRing cmd_ring;
 };
 
+#define TYPE_XHCI nec-usb-xhci
+
+#define XHCI(obj) \
+OBJECT_CHECK(XHCIState, (obj), TYPE_XHCI)
+
 typedef struct XHCIEvRingSeg {
 uint32_t addr_low;
 uint32_t addr_high;
@@ -2681,7 +2686,7 @@ static void xhci_port_reset(XHCIPort *port)
 
 static void xhci_reset(DeviceState *dev)
 {
-XHCIState *xhci = DO_UPCAST(XHCIState, pci_dev.qdev, dev);
+XHCIState *xhci = XHCI(dev);
 int i;
 
 trace_usb_xhci_reset();
@@ -2926,6 +2931,7 @@ static void xhci_oper_write(void *ptr, hwaddr reg,
 uint64_t val, unsigned size)
 {
 XHCIState *xhci = ptr;
+DeviceState *d = DEVICE(ptr);
 
 trace_usb_xhci_oper_write(reg, val);
 
@@ -2939,7 +2945,7 @@ static void xhci_oper_write(void *ptr, hwaddr reg,
 xhci-usbcmd = val  0xc0f;
 xhci_mfwrap_update(xhci);
 if (val  USBCMD_HCRST) {
-xhci_reset(xhci-pci_dev.qdev);
+xhci_reset(d);
 }
 xhci_intx_update(xhci);
 break;
@@ -3267,6 +3273,7 @@ static USBBusOps xhci_bus_ops = {
 
 static void usb_xhci_init(XHCIState *xhci, DeviceState *dev)
 {
+DeviceState *d = DEVICE(xhci);
 XHCIPort *port;
 int i, usbports, speedmask;
 
@@ -3281,7 +3288,7 @@ static void usb_xhci_init(XHCIState *xhci, DeviceState 
*dev)
 usbports = MAX(xhci-numports_2, xhci-numports_3);
 xhci-numports = xhci-numports_2 + xhci-numports_3;
 
-usb_bus_new(xhci-bus, xhci_bus_ops, xhci-pci_dev.qdev);
+usb_bus_new(xhci-bus, xhci_bus_ops, d);
 
 for (i = 0; i  usbports; i++) {
 speedmask = 0;
@@ -3313,14 +3320,14 @@ static int usb_xhci_initfn(struct PCIDevice *dev)
 {
 int i, ret;
 
-XHCIState *xhci = DO_UPCAST(XHCIState, pci_dev, dev);
+XHCIState *xhci = XHCI(dev);
 
 xhci-pci_dev.config[PCI_CLASS_PROG] = 0x30;/* xHCI */
 xhci-pci_dev.config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt pin 1 */
 xhci-pci_dev.config[PCI_CACHE_LINE_SIZE] = 0x10;
 xhci-pci_dev.config[0x60] = 0x30; /* release number */
 
-usb_xhci_init(xhci, dev-qdev);
+usb_xhci_init(xhci, DEVICE(dev));
 
 if (xhci-numintrs  MAXINTRS) {
 xhci-numintrs = MAXINTRS;
@@ -3581,7 +3588,7 @@ static void xhci_class_init(ObjectClass *klass, void 
*data)
 }
 
 static const TypeInfo xhci_info = {
-.name  = nec-usb-xhci,
+.name  = TYPE_XHCI,
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(XHCIState),
 .class_init= xhci_class_init,
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 05/30] scsi/lsi53c895a: QOM Upcast Sweep

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Define and use standard QOM cast macro. Remove usages of DO_UPCAST
and direct - style upcasting.

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/scsi/lsi53c895a.c | 26 --
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/hw/scsi/lsi53c895a.c b/hw/scsi/lsi53c895a.c
index 22b8e98..d488c5c 100644
--- a/hw/scsi/lsi53c895a.c
+++ b/hw/scsi/lsi53c895a.c
@@ -275,6 +275,11 @@ typedef struct {
 uint32_t script_ram[2048];
 } LSIState;
 
+#define TYPE_LSI53C895A lsi53c895a
+
+#define LSI53C895A(obj) \
+OBJECT_CHECK(LSIState, (obj), TYPE_LSI53C895A)
+
 static inline int lsi_irq_on_rsl(LSIState *s)
 {
 return (s-sien0  LSI_SIST0_RSL)  (s-scid  LSI_SCID_RRE);
@@ -653,7 +658,7 @@ static void lsi_request_free(LSIState *s, lsi_request *p)
 
 static void lsi_request_cancelled(SCSIRequest *req)
 {
-LSIState *s = DO_UPCAST(LSIState, dev.qdev, req-bus-qbus.parent);
+LSIState *s = LSI53C895A(req-bus-qbus.parent);
 lsi_request *p = req-hba_private;
 
 req-hba_private = NULL;
@@ -692,7 +697,7 @@ static int lsi_queue_req(LSIState *s, SCSIRequest *req, 
uint32_t len)
  /* Callback to indicate that the SCSI layer has completed a command.  */
 static void lsi_command_complete(SCSIRequest *req, uint32_t status, size_t 
resid)
 {
-LSIState *s = DO_UPCAST(LSIState, dev.qdev, req-bus-qbus.parent);
+LSIState *s = LSI53C895A(req-bus-qbus.parent);
 int out;
 
 out = (s-sstat1  PHASE_MASK) == PHASE_DO;
@@ -717,7 +722,7 @@ static void lsi_command_complete(SCSIRequest *req, uint32_t 
status, size_t resid
  /* Callback to indicate that the SCSI layer has completed a transfer.  */
 static void lsi_transfer_data(SCSIRequest *req, uint32_t len)
 {
-LSIState *s = DO_UPCAST(LSIState, dev.qdev, req-bus-qbus.parent);
+LSIState *s = LSI53C895A(req-bus-qbus.parent);
 int out;
 
 assert(req-hba_private);
@@ -1726,7 +1731,7 @@ static void lsi_reg_writeb(LSIState *s, int offset, 
uint8_t val)
 lsi_execute_script(s);
 }
 if (val  LSI_ISTAT0_SRST) {
-qdev_reset_all(s-dev.qdev);
+qdev_reset_all(DEVICE(s));
 }
 break;
 case 0x16: /* MBOX0 */
@@ -1960,7 +1965,7 @@ static const MemoryRegionOps lsi_io_ops = {
 
 static void lsi_scsi_reset(DeviceState *dev)
 {
-LSIState *s = DO_UPCAST(LSIState, dev.qdev, dev);
+LSIState *s = LSI53C895A(dev);
 
 lsi_soft_reset(s);
 }
@@ -2061,7 +2066,7 @@ static const VMStateDescription vmstate_lsi_scsi = {
 
 static void lsi_scsi_uninit(PCIDevice *d)
 {
-LSIState *s = DO_UPCAST(LSIState, dev, d);
+LSIState *s = LSI53C895A(d);
 
 memory_region_destroy(s-mmio_io);
 memory_region_destroy(s-ram_io);
@@ -2080,7 +2085,8 @@ static const struct SCSIBusInfo lsi_scsi_info = {
 
 static int lsi_scsi_init(PCIDevice *dev)
 {
-LSIState *s = DO_UPCAST(LSIState, dev, dev);
+LSIState *s = LSI53C895A(dev);
+DeviceState *d = DEVICE(dev);
 uint8_t *pci_conf;
 
 pci_conf = s-dev.config;
@@ -2099,8 +2105,8 @@ static int lsi_scsi_init(PCIDevice *dev)
 pci_register_bar(s-dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, s-ram_io);
 QTAILQ_INIT(s-queue);
 
-scsi_bus_new(s-bus, dev-qdev, lsi_scsi_info, NULL);
-if (!dev-qdev.hotplugged) {
+scsi_bus_new(s-bus, d, lsi_scsi_info, NULL);
+if (!d-hotplugged) {
 return scsi_bus_legacy_handle_cmdline(s-bus);
 }
 return 0;
@@ -2122,7 +2128,7 @@ static void lsi_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo lsi_info = {
-.name  = lsi53c895a,
+.name  = TYPE_LSI53C895A,
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(LSIState),
 .class_init= lsi_class_init,
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 06/30] scsi/megasas: QOM Upcast Sweep

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Define and use standard QOM cast macro. Remove usages of DO_UPCAST
and direct - style upcasting.

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/scsi/megasas.c | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c
index 65ccb09..49fcae4 100644
--- a/hw/scsi/megasas.c
+++ b/hw/scsi/megasas.c
@@ -108,6 +108,11 @@ typedef struct MegasasState {
 SCSIBus bus;
 } MegasasState;
 
+#define TYPE_MEGASAS megasas
+
+#define MEGASAS(obj) \
+OBJECT_CHECK(MegasasState, (obj), TYPE_MEGASAS)
+
 #define MEGASAS_INTR_DISABLED_MASK 0x
 
 static bool megasas_intr_enabled(MegasasState *s)
@@ -2039,7 +2044,7 @@ static void megasas_soft_reset(MegasasState *s)
 
 static void megasas_scsi_reset(DeviceState *dev)
 {
-MegasasState *s = DO_UPCAST(MegasasState, dev.qdev, dev);
+MegasasState *s = MEGASAS(dev);
 
 megasas_soft_reset(s);
 }
@@ -2064,7 +2069,7 @@ static const VMStateDescription vmstate_megasas = {
 
 static void megasas_scsi_uninit(PCIDevice *d)
 {
-MegasasState *s = DO_UPCAST(MegasasState, dev, d);
+MegasasState *s = MEGASAS(d);
 
 #ifdef USE_MSIX
 msix_uninit(s-dev, s-mmio_io);
@@ -2087,7 +2092,7 @@ static const struct SCSIBusInfo megasas_scsi_info = {
 
 static int megasas_scsi_init(PCIDevice *dev)
 {
-MegasasState *s = DO_UPCAST(MegasasState, dev, dev);
+MegasasState *s = MEGASAS(dev);
 uint8_t *pci_conf;
 int i, bar_type;
 
@@ -2158,7 +2163,7 @@ static int megasas_scsi_init(PCIDevice *dev)
 s-frames[i].state = s;
 }
 
-scsi_bus_new(s-bus, dev-qdev, megasas_scsi_info, NULL);
+scsi_bus_new(s-bus, DEVICE(dev), megasas_scsi_info, NULL);
 scsi_bus_legacy_handle_cmdline(s-bus);
 return 0;
 }
@@ -2198,7 +2203,7 @@ static void megasas_class_init(ObjectClass *oc, void 
*data)
 }
 
 static const TypeInfo megasas_info = {
-.name  = megasas,
+.name  = TYPE_MEGASAS,
 .parent = TYPE_PCI_DEVICE,
 .instance_size = sizeof(MegasasState),
 .class_init = megasas_class_init,
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 07/30] scsi/esp-pci: QOM Upcast Sweep

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Define and use standard QOM cast macro. Remove usages of DO_UPCAST
and direct - style upcasting.

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/scsi/esp-pci.c | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/hw/scsi/esp-pci.c b/hw/scsi/esp-pci.c
index 029789a..2a72da6 100644
--- a/hw/scsi/esp-pci.c
+++ b/hw/scsi/esp-pci.c
@@ -31,6 +31,9 @@
 
 #define TYPE_AM53C974_DEVICE am53c974
 
+#define PCI_ESP(obj) \
+OBJECT_CHECK(PCIESPState, (obj), TYPE_AM53C974_DEVICE)
+
 #define DMA_CMD   0x0
 #define DMA_STC   0x1
 #define DMA_SPA   0x2
@@ -288,7 +291,7 @@ static const MemoryRegionOps esp_pci_io_ops = {
 
 static void esp_pci_hard_reset(DeviceState *dev)
 {
-PCIESPState *pci = DO_UPCAST(PCIESPState, dev.qdev, dev);
+PCIESPState *pci = PCI_ESP(dev);
 esp_hard_reset(pci-esp);
 pci-dma_regs[DMA_CMD] = ~(DMA_CMD_DIR | DMA_CMD_INTE_D | DMA_CMD_INTE_P
   | DMA_CMD_MDL | DMA_CMD_DIAG | DMA_CMD_MASK);
@@ -336,7 +339,8 @@ static const struct SCSIBusInfo esp_pci_scsi_info = {
 
 static int esp_pci_scsi_init(PCIDevice *dev)
 {
-PCIESPState *pci = DO_UPCAST(PCIESPState, dev, dev);
+PCIESPState *pci = PCI_ESP(dev);
+DeviceState *d = DEVICE(dev);
 ESPState *s = pci-esp;
 uint8_t *pci_conf;
 
@@ -354,8 +358,8 @@ static int esp_pci_scsi_init(PCIDevice *dev)
 pci_register_bar(pci-dev, 0, PCI_BASE_ADDRESS_SPACE_IO, pci-io);
 s-irq = pci-dev.irq[0];
 
-scsi_bus_new(s-bus, dev-qdev, esp_pci_scsi_info, NULL);
-if (!dev-qdev.hotplugged) {
+scsi_bus_new(s-bus, d, esp_pci_scsi_info, NULL);
+if (!d-hotplugged) {
 return scsi_bus_legacy_handle_cmdline(s-bus);
 }
 return 0;
@@ -363,7 +367,7 @@ static int esp_pci_scsi_init(PCIDevice *dev)
 
 static void esp_pci_scsi_uninit(PCIDevice *d)
 {
-PCIESPState *pci = DO_UPCAST(PCIESPState, dev, d);
+PCIESPState *pci = PCI_ESP(d);
 
 memory_region_destroy(pci-io);
 }
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 08/30] ide/ich: QOM Upcast Sweep

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Define and use standard QOM cast macro. Remove usages of DO_UPCAST
and direct - style upcasting.

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/ide/ahci.h |  5 +
 hw/ide/ich.c  | 10 +-
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/hw/ide/ahci.h b/hw/ide/ahci.h
index 341a571..916bef0 100644
--- a/hw/ide/ahci.h
+++ b/hw/ide/ahci.h
@@ -305,6 +305,11 @@ typedef struct AHCIPCIState {
 AHCIState ahci;
 } AHCIPCIState;
 
+#define TYPE_ICH_AHCI ich9-ahci
+
+#define ICH_AHCI(obj) \
+OBJECT_CHECK(AHCIPCIState, (obj), TYPE_ICH_AHCI)
+
 extern const VMStateDescription vmstate_ahci;
 
 #define VMSTATE_AHCI(_field, _state) {   \
diff --git a/hw/ide/ich.c b/hw/ide/ich.c
index 6c0c0c2..c3cbf2a 100644
--- a/hw/ide/ich.c
+++ b/hw/ide/ich.c
@@ -92,7 +92,7 @@ static const VMStateDescription vmstate_ich9_ahci = {
 
 static void pci_ich9_reset(DeviceState *dev)
 {
-struct AHCIPCIState *d = DO_UPCAST(struct AHCIPCIState, card.qdev, dev);
+struct AHCIPCIState *d = ICH_AHCI(dev);
 
 ahci_reset(d-ahci);
 }
@@ -102,9 +102,9 @@ static int pci_ich9_ahci_init(PCIDevice *dev)
 struct AHCIPCIState *d;
 int sata_cap_offset;
 uint8_t *sata_cap;
-d = DO_UPCAST(struct AHCIPCIState, card, dev);
+d = ICH_AHCI(dev);
 
-ahci_init(d-ahci, dev-qdev, pci_get_address_space(dev), 6);
+ahci_init(d-ahci, DEVICE(dev), pci_get_address_space(dev), 6);
 
 pci_config_set_prog_interface(d-card.config, AHCI_PROGMODE_MAJOR_REV_1);
 
@@ -141,7 +141,7 @@ static int pci_ich9_ahci_init(PCIDevice *dev)
 static void pci_ich9_uninit(PCIDevice *dev)
 {
 struct AHCIPCIState *d;
-d = DO_UPCAST(struct AHCIPCIState, card, dev);
+d = ICH_AHCI(dev);
 
 msi_uninit(dev);
 ahci_uninit(d-ahci);
@@ -163,7 +163,7 @@ static void ich_ahci_class_init(ObjectClass *klass, void 
*data)
 }
 
 static const TypeInfo ich_ahci_info = {
-.name  = ich9-ahci,
+.name  = TYPE_ICH_AHCI,
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(AHCIPCIState),
 .class_init= ich_ahci_class_init,
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 09/30] ide/piix: QOM casting sweep

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Use standard QOM cast macro. Remove usage of DO_UPCAST and
direct - style upcasting.

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/ide/piix.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/ide/piix.c b/hw/ide/piix.c
index bf2856f..d0fdea3 100644
--- a/hw/ide/piix.c
+++ b/hw/ide/piix.c
@@ -135,7 +135,7 @@ static void pci_piix_init_ports(PCIIDEState *d) {
 int i;
 
 for (i = 0; i  2; i++) {
-ide_bus_new(d-bus[i], d-dev.qdev, i, 2);
+ide_bus_new(d-bus[i], DEVICE(d), i, 2);
 ide_init_ioport(d-bus[i], NULL, port_info[i].iobase,
 port_info[i].iobase2);
 ide_init2(d-bus[i], isa_get_irq(NULL, port_info[i].isairq));
@@ -159,7 +159,7 @@ static int pci_piix_ide_initfn(PCIDevice *dev)
 bmdma_setup_bar(d);
 pci_register_bar(d-dev, 4, PCI_BASE_ADDRESS_SPACE_IO, d-bmdma_bar);
 
-vmstate_register(d-dev.qdev, 0, vmstate_ide_pci, d);
+vmstate_register(DEVICE(dev), 0, vmstate_ide_pci, d);
 
 pci_piix_init_ports(d);
 
@@ -173,7 +173,7 @@ static int pci_piix3_xen_ide_unplug(DeviceState *dev)
 DriveInfo *di;
 int i = 0;
 
-pci_dev = DO_UPCAST(PCIDevice, qdev, dev);
+pci_dev = PCI_DEVICE(dev);
 pci_ide = DO_UPCAST(PCIIDEState, dev, pci_dev);
 
 for (; i  3; i++) {
@@ -188,7 +188,7 @@ static int pci_piix3_xen_ide_unplug(DeviceState *dev)
 drive_put_ref(di);
 }
 }
-qdev_reset_all((pci_ide-dev.qdev));
+qdev_reset_all(DEVICE(dev));
 return 0;
 }
 
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 10/30] acpi/piix4: QOM Upcast Sweep

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Use standard QOM cast macro. Remove usages of DO_UPCAST
and direct - style upcasting.

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/acpi/piix4.c | 31 +--
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 756df3b..b0f7667 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -96,6 +96,11 @@ typedef struct PIIX4PMState {
 Notifier cpu_added_notifier;
 } PIIX4PMState;
 
+#define TYPE_PIIX4_PM PIIX4_PM
+
+#define PIIX4_PM(obj) \
+OBJECT_CHECK(PIIX4PMState, (obj), TYPE_PIIX4_PM)
+
 static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
PCIBus *bus, PIIX4PMState *s);
 
@@ -300,7 +305,7 @@ static const VMStateDescription vmstate_acpi = {
 static void acpi_piix_eject_slot(PIIX4PMState *s, unsigned slots)
 {
 BusChild *kid, *next;
-BusState *bus = qdev_get_parent_bus(s-dev.qdev);
+BusState *bus = qdev_get_parent_bus(DEVICE(s));
 int slot = ffs(slots) - 1;
 bool slot_free = true;
 
@@ -326,8 +331,7 @@ static void acpi_piix_eject_slot(PIIX4PMState *s, unsigned 
slots)
 
 static void piix4_update_hotplug(PIIX4PMState *s)
 {
-PCIDevice *dev = s-dev;
-BusState *bus = qdev_get_parent_bus(dev-qdev);
+BusState *bus = qdev_get_parent_bus(DEVICE(s));
 BusChild *kid, *next;
 
 /* Execute any pending removes during reset */
@@ -395,7 +399,7 @@ static void piix4_pm_machine_ready(Notifier *n, void 
*opaque)
 
 static int piix4_pm_initfn(PCIDevice *dev)
 {
-PIIX4PMState *s = DO_UPCAST(PIIX4PMState, dev, dev);
+PIIX4PMState *s = PIIX4_PM(dev);
 uint8_t *pci_conf;
 
 pci_conf = s-dev.config;
@@ -418,7 +422,7 @@ static int piix4_pm_initfn(PCIDevice *dev)
 pci_conf[0x90] = s-smb_io_base | 1;
 pci_conf[0x91] = s-smb_io_base  8;
 pci_conf[0xd2] = 0x09;
-pm_smbus_init(s-dev.qdev, s-smb);
+pm_smbus_init(DEVICE(dev), s-smb);
 memory_region_set_enabled(s-smb.io, pci_conf[0xd2]  1);
 memory_region_add_subregion(pci_address_space_io(dev),
 s-smb_io_base, s-smb.io);
@@ -449,18 +453,18 @@ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t 
smb_io_base,
qemu_irq sci_irq, qemu_irq smi_irq,
int kvm_enabled, FWCfgState *fw_cfg)
 {
-PCIDevice *dev;
+DeviceState *dev;
 PIIX4PMState *s;
 
-dev = pci_create(bus, devfn, PIIX4_PM);
-qdev_prop_set_uint32(dev-qdev, smb_io_base, smb_io_base);
+dev = DEVICE(pci_create(bus, devfn, TYPE_PIIX4_PM));
+qdev_prop_set_uint32(dev, smb_io_base, smb_io_base);
 
-s = DO_UPCAST(PIIX4PMState, dev, dev);
+s = PIIX4_PM(dev);
 s-irq = sci_irq;
 s-smi_irq = smi_irq;
 s-kvm_enabled = kvm_enabled;
 
-qdev_init_nofail(dev-qdev);
+qdev_init_nofail(dev);
 
 if (fw_cfg) {
 uint8_t suspend[6] = {128, 0, 0, 129, 128, 128};
@@ -500,7 +504,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void 
*data)
 }
 
 static const TypeInfo piix4_pm_info = {
-.name  = PIIX4_PM,
+.name  = TYPE_PIIX4_PM,
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(PIIX4PMState),
 .class_init= piix4_pm_class_init,
@@ -678,7 +682,7 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion 
*parent,
   PCI_HOTPLUG_SIZE);
 memory_region_add_subregion(parent, PCI_HOTPLUG_ADDR,
 s-io_pci);
-pci_bus_hotplug(bus, piix4_device_hotplug, s-dev.qdev);
+pci_bus_hotplug(bus, piix4_device_hotplug, DEVICE(s));
 
 qemu_for_each_cpu(piix4_init_cpu_status, s-gpe_cpu);
 memory_region_init_io(s-io_cpu, cpu_hotplug_ops, s, apci-cpu-hotplug,
@@ -704,8 +708,7 @@ static int piix4_device_hotplug(DeviceState *qdev, 
PCIDevice *dev,
PCIHotplugState state)
 {
 int slot = PCI_SLOT(dev-devfn);
-PIIX4PMState *s = DO_UPCAST(PIIX4PMState, dev,
-PCI_DEVICE(qdev));
+PIIX4PMState *s = PIIX4_PM(qdev);
 
 /* Don't send event when device is enabled during qemu machine creation:
  * it is present on boot, no hotplug event is necessary. We do send an
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 11/30] misc/pci-testdev: QOM Upcast Sweep

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Define and use standard QOM cast macro. Remove usages of DO_UPCAST
and direct - style upcasting.

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/misc/pci-testdev.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/hw/misc/pci-testdev.c b/hw/misc/pci-testdev.c
index 71ce5a3..add58b7 100644
--- a/hw/misc/pci-testdev.c
+++ b/hw/misc/pci-testdev.c
@@ -83,6 +83,11 @@ typedef struct PCITestDevState {
 int current;
 } PCITestDevState;
 
+#define TYPE_PCI_TEST_DEV pci-testdev
+
+#define PCI_TEST_DEV(obj) \
+OBJECT_CHECK(PCITestDevState, (obj), TYPE_PCI_TEST_DEV)
+
 #define IOTEST_IS_MEM(i) (strcmp(IOTEST_TYPE(i), portio))
 #define IOTEST_REGION(d, i) (IOTEST_IS_MEM(i) ?  (d)-mmio : (d)-portio)
 #define IOTEST_SIZE(i) (IOTEST_IS_MEM(i) ? IOTEST_MEMSIZE : IOTEST_IOSIZE)
@@ -274,7 +279,7 @@ static int pci_testdev_init(PCIDevice *pci_dev)
 static void
 pci_testdev_uninit(PCIDevice *dev)
 {
-PCITestDevState *d = DO_UPCAST(PCITestDevState, dev, dev);
+PCITestDevState *d = PCI_TEST_DEV(dev);
 int i;
 
 pci_testdev_reset(d);
@@ -291,7 +296,7 @@ pci_testdev_uninit(PCIDevice *dev)
 
 static void qdev_pci_testdev_reset(DeviceState *dev)
 {
-PCITestDevState *d = DO_UPCAST(PCITestDevState, dev.qdev, dev);
+PCITestDevState *d = PCI_TEST_DEV(dev);
 pci_testdev_reset(d);
 }
 
@@ -311,7 +316,7 @@ static void pci_testdev_class_init(ObjectClass *klass, void 
*data)
 }
 
 static const TypeInfo pci_testdev_info = {
-.name  = pci-testdev,
+.name  = TYPE_PCI_TEST_DEV,
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(PCITestDevState),
 .class_init= pci_testdev_class_init,
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 12/30] virtio/vmware_vga: QOM casting sweep

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Define and use standard QOM cast macro. Remove usages of DO_UPCAST and
direct - style casting.

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/display/vmware_vga.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/hw/display/vmware_vga.c b/hw/display/vmware_vga.c
index fd3569d..0e2aa3f 100644
--- a/hw/display/vmware_vga.c
+++ b/hw/display/vmware_vga.c
@@ -81,6 +81,11 @@ struct vmsvga_state_s {
 int redraw_fifo_first, redraw_fifo_last;
 };
 
+#define TYPE_VM_SVGA vmware-svga
+
+#define VM_SVGA(obj) \
+OBJECT_CHECK(struct pci_vmsvga_state_s, (obj), TYPE_VM_SVGA)
+
 struct pci_vmsvga_state_s {
 PCIDevice card;
 struct vmsvga_state_s chip;
@@ -1092,8 +1097,7 @@ static void vmsvga_update_display(void *opaque)
 
 static void vmsvga_reset(DeviceState *dev)
 {
-struct pci_vmsvga_state_s *pci =
-DO_UPCAST(struct pci_vmsvga_state_s, card.qdev, dev);
+struct pci_vmsvga_state_s *pci = VM_SVGA(dev);
 struct vmsvga_state_s *s = pci-chip;
 
 s-index = 0;
@@ -1246,8 +1250,7 @@ static const MemoryRegionOps vmsvga_io_ops = {
 
 static int pci_vmsvga_initfn(PCIDevice *dev)
 {
-struct pci_vmsvga_state_s *s =
-DO_UPCAST(struct pci_vmsvga_state_s, card, dev);
+struct pci_vmsvga_state_s *s = VM_SVGA(dev);
 
 s-card.config[PCI_CACHE_LINE_SIZE] = 0x08; /* Cache line size */
 s-card.config[PCI_LATENCY_TIMER] = 0x40;   /* Latency timer */
@@ -1299,7 +1302,7 @@ static void vmsvga_class_init(ObjectClass *klass, void 
*data)
 }
 
 static const TypeInfo vmsvga_info = {
-.name  = vmware-svga,
+.name  = TYPE_VM_SVGA,
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(struct pci_vmsvga_state_s),
 .class_init= vmsvga_class_init,
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 13/30] misc/ivshmem: QOM Upcast Sweep

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Define and use standard QOM cast macro. Remove usages of DO_UPCAST
and direct - style upcasting.

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/misc/ivshmem.c | 18 +++---
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index 5658f73..fd40caf 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -48,6 +48,10 @@
 #define IVSHMEM_DPRINTF(fmt, ...)
 #endif
 
+#define TYPE_IVSHMEM ivshmem
+#define IVSHMEM(obj) \
+OBJECT_CHECK(IVShmemState, (obj), TYPE_IVSHMEM)
+
 typedef struct Peer {
 int nb_eventfds;
 EventNotifier *eventfds;
@@ -341,7 +345,7 @@ static void create_shared_memory_BAR(IVShmemState *s, int 
fd) {
 
 memory_region_init_ram_ptr(s-ivshmem, ivshmem.bar2,
s-ivshmem_size, ptr);
-vmstate_register_ram(s-ivshmem, s-dev.qdev);
+vmstate_register_ram(s-ivshmem, DEVICE(s-dev));
 memory_region_add_subregion(s-bar, 0, s-ivshmem);
 
 /* region for shared memory */
@@ -469,7 +473,7 @@ static void ivshmem_read(void *opaque, const uint8_t * buf, 
int flags)
 incoming_fd, 0);
 memory_region_init_ram_ptr(s-ivshmem,
ivshmem.bar2, s-ivshmem_size, map_ptr);
-vmstate_register_ram(s-ivshmem, s-dev.qdev);
+vmstate_register_ram(s-ivshmem, DEVICE(s-dev));
 
 IVSHMEM_DPRINTF(guest h/w addr = % PRIu64 , size = % PRIu64 \n,
  s-ivshmem_offset, s-ivshmem_size);
@@ -534,7 +538,7 @@ static void ivshmem_use_msix(IVShmemState * s)
 
 static void ivshmem_reset(DeviceState *d)
 {
-IVShmemState *s = DO_UPCAST(IVShmemState, dev.qdev, d);
+IVShmemState *s = IVSHMEM(d);
 
 s-intrstatus = 0;
 ivshmem_use_msix(s);
@@ -648,7 +652,7 @@ static int pci_ivshmem_init(PCIDevice *dev)
 s-ivshmem_size = ivshmem_get_size(s);
 }
 
-register_savevm(s-dev.qdev, ivshmem, 0, 0, ivshmem_save, ivshmem_load,
+register_savevm(DEVICE(dev), ivshmem, 0, 0, ivshmem_save, ivshmem_load,
 dev);
 
 /* IRQFD requires MSI */
@@ -780,10 +784,10 @@ static void pci_ivshmem_uninit(PCIDevice *dev)
 
 memory_region_destroy(s-ivshmem_mmio);
 memory_region_del_subregion(s-bar, s-ivshmem);
-vmstate_unregister_ram(s-ivshmem, s-dev.qdev);
+vmstate_unregister_ram(s-ivshmem, DEVICE(dev));
 memory_region_destroy(s-ivshmem);
 memory_region_destroy(s-bar);
-unregister_savevm(dev-qdev, ivshmem, s);
+unregister_savevm(DEVICE(dev), ivshmem, s);
 }
 
 static Property ivshmem_properties[] = {
@@ -813,7 +817,7 @@ static void ivshmem_class_init(ObjectClass *klass, void 
*data)
 }
 
 static const TypeInfo ivshmem_info = {
-.name  = ivshmem,
+.name  = TYPE_IVSHMEM,
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(IVShmemState),
 .class_init= ivshmem_class_init,
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 14/30] xen/xen_platform: QOM casting sweep

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Define and use standard QOM cast macro. Remove usages of DO_UPCAST
and direct - style upcasting.

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/xen/xen_platform.c | 28 
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/hw/xen/xen_platform.c b/hw/xen/xen_platform.c
index b6c6793..f119c44 100644
--- a/hw/xen/xen_platform.c
+++ b/hw/xen/xen_platform.c
@@ -62,6 +62,10 @@ typedef struct PCIXenPlatformState {
 int log_buffer_off;
 } PCIXenPlatformState;
 
+#define TYPE_XEN_PLATFORM xen-platform
+#define XEN_PLATFORM(obj) \
+OBJECT_CHECK(PCIXenPlatformState, (obj), TYPE_XEN_PLATFORM)
+
 #define XEN_PLATFORM_IOPORT 0x10
 
 /* Send bytes to syslog */
@@ -88,7 +92,7 @@ static void unplug_nic(PCIBus *b, PCIDevice *d, void *o)
 if (pci_get_word(d-config + PCI_CLASS_DEVICE) ==
 PCI_CLASS_NETWORK_ETHERNET
  strcmp(d-name, xen-pci-passthrough) != 0) {
-qdev_free(d-qdev);
+qdev_free(DEVICE(d));
 }
 }
 
@@ -103,7 +107,7 @@ static void unplug_disks(PCIBus *b, PCIDevice *d, void *o)
 if (pci_get_word(d-config + PCI_CLASS_DEVICE) ==
 PCI_CLASS_STORAGE_IDE
  strcmp(d-name, xen-pci-passthrough) != 0) {
-qdev_unplug((d-qdev), NULL);
+qdev_unplug(DEVICE(d), NULL);
 }
 }
 
@@ -114,7 +118,7 @@ static void pci_unplug_disks(PCIBus *bus)
 
 static void platform_fixed_ioport_writew(void *opaque, uint32_t addr, uint32_t 
val)
 {
-PCIXenPlatformState *s = opaque;
+PCIXenPlatformState *s = XEN_PLATFORM(opaque);
 
 switch (addr) {
 case 0:
@@ -164,7 +168,7 @@ static void platform_fixed_ioport_writel(void *opaque, 
uint32_t addr,
 
 static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t 
val)
 {
-PCIXenPlatformState *s = opaque;
+PCIXenPlatformState *s = XEN_PLATFORM(opaque);
 
 switch (addr) {
 case 0: /* Platform flags */ {
@@ -187,7 +191,7 @@ static void platform_fixed_ioport_writeb(void *opaque, 
uint32_t addr, uint32_t v
 
 static uint32_t platform_fixed_ioport_readw(void *opaque, uint32_t addr)
 {
-PCIXenPlatformState *s = opaque;
+PCIXenPlatformState *s = XEN_PLATFORM(opaque);
 
 switch (addr) {
 case 0:
@@ -206,7 +210,7 @@ static uint32_t platform_fixed_ioport_readw(void *opaque, 
uint32_t addr)
 
 static uint32_t platform_fixed_ioport_readb(void *opaque, uint32_t addr)
 {
-PCIXenPlatformState *s = opaque;
+PCIXenPlatformState *s = XEN_PLATFORM(opaque);
 
 switch (addr) {
 case 0:
@@ -222,7 +226,7 @@ static uint32_t platform_fixed_ioport_readb(void *opaque, 
uint32_t addr)
 
 static void platform_fixed_ioport_reset(void *opaque)
 {
-PCIXenPlatformState *s = opaque;
+PCIXenPlatformState *s = XEN_PLATFORM(opaque);
 
 platform_fixed_ioport_writeb(s, 0, 0);
 }
@@ -292,7 +296,7 @@ static uint64_t xen_platform_ioport_readb(void *opaque, 
hwaddr addr,
 static void xen_platform_ioport_writeb(void *opaque, hwaddr addr,
uint64_t val, unsigned int size)
 {
-PCIXenPlatformState *s = opaque;
+PCIXenPlatformState *s = XEN_PLATFORM(opaque);
 
 switch (addr) {
 case 0: /* Platform flags */
@@ -349,7 +353,7 @@ static void platform_mmio_setup(PCIXenPlatformState *d)
 
 static int xen_platform_post_load(void *opaque, int version_id)
 {
-PCIXenPlatformState *s = opaque;
+PCIXenPlatformState *s = XEN_PLATFORM(opaque);
 
 platform_fixed_ioport_writeb(s, 0, s-flags);
 
@@ -371,7 +375,7 @@ static const VMStateDescription vmstate_xen_platform = {
 
 static int xen_platform_initfn(PCIDevice *dev)
 {
-PCIXenPlatformState *d = DO_UPCAST(PCIXenPlatformState, pci_dev, dev);
+PCIXenPlatformState *d = XEN_PLATFORM(dev);
 uint8_t *pci_conf;
 
 pci_conf = d-pci_dev.config;
@@ -397,7 +401,7 @@ static int xen_platform_initfn(PCIDevice *dev)
 
 static void platform_reset(DeviceState *dev)
 {
-PCIXenPlatformState *s = DO_UPCAST(PCIXenPlatformState, pci_dev.qdev, dev);
+PCIXenPlatformState *s = XEN_PLATFORM(dev);
 
 platform_fixed_ioport_reset(s);
 }
@@ -420,7 +424,7 @@ static void xen_platform_class_init(ObjectClass *klass, 
void *data)
 }
 
 static const TypeInfo xen_platform_info = {
-.name  = xen-platform,
+.name  = TYPE_XEN_PLATFORM,
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(PCIXenPlatformState),
 .class_init= xen_platform_class_init,
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 15/30] isa/*: QOM casting sweep

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Use standard QOM cast macros. Remove usage of DO_UPCAST and
direct - style upcasting.

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/isa/i82378.c   | 8 
 hw/isa/lpc_ich9.c | 6 +++---
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/hw/isa/i82378.c b/hw/isa/i82378.c
index a24cb98..d6fef8c 100644
--- a/hw/isa/i82378.c
+++ b/hw/isa/i82378.c
@@ -159,8 +159,7 @@ static void i82378_request_out0_irq(void *opaque, int irq, 
int level)
 
 static void i82378_request_pic_irq(void *opaque, int irq, int level)
 {
-DeviceState *dev = opaque;
-PCIDevice *pci = DO_UPCAST(PCIDevice, qdev, dev);
+PCIDevice *pci = PCI_DEVICE(opaque);
 PCIi82378State *s = DO_UPCAST(PCIi82378State, pci_dev, pci);
 
 qemu_set_irq(s-state.i8259[irq], level);
@@ -210,6 +209,7 @@ static void i82378_init(DeviceState *dev, I82378State *s)
 static int pci_i82378_init(PCIDevice *dev)
 {
 PCIi82378State *pci = DO_UPCAST(PCIi82378State, pci_dev, dev);
+DeviceState *d = DEVICE(pci);
 I82378State *s = pci-state;
 uint8_t *pci_conf;
 
@@ -233,9 +233,9 @@ static int pci_i82378_init(PCIDevice *dev)
 pci_set_long(pci_conf + PCI_BASE_ADDRESS_0, pci-isa_io_base);
 
 isa_mem_base = pci-isa_mem_base;
-isa_bus_new(dev-qdev, pci_address_space_io(dev));
+isa_bus_new(d, pci_address_space_io(dev));
 
-i82378_init(dev-qdev, s);
+i82378_init(d, s);
 
 return 0;
 }
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index 667e882..497ced1 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -277,7 +277,7 @@ void ich9_lpc_set_irq(void *opaque, int pirq, int level)
  */
 int ich9_lpc_map_irq(PCIDevice *pci_dev, int intx)
 {
-BusState *bus = qdev_get_parent_bus(pci_dev-qdev);
+BusState *bus = qdev_get_parent_bus(DEVICE(pci_dev));
 PCIBus *pci_bus = PCI_BUS(bus);
 PCIDevice *lpc_pdev =
 pci_bus-devices[PCI_DEVFN(ICH9_LPC_DEV, ICH9_LPC_FUNC)];
@@ -364,7 +364,7 @@ void ich9_lpc_pm_init(PCIDevice *lpc_pci)
 sci_irq = qemu_allocate_irqs(ich9_set_sci, lpc, 1);
 ich9_pm_init(lpc_pci, lpc-pm, sci_irq[0]);
 
-ich9_lpc_reset(lpc-d.qdev);
+ich9_lpc_reset(DEVICE(lpc));
 }
 
 /* APM */
@@ -529,7 +529,7 @@ static int ich9_lpc_initfn(PCIDevice *d)
 ICH9LPCState *lpc = ICH9_LPC_DEVICE(d);
 ISABus *isa_bus;
 
-isa_bus = isa_bus_new(d-qdev, get_system_io());
+isa_bus = isa_bus_new(DEVICE(d), get_system_io());
 
 pci_set_long(d-wmask + ICH9_LPC_PMBASE,
  ICH9_LPC_PMBASE_BASE_ADDRESS_MASK);
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 17/30] pci-bridge/pci_bridge_dev: Don't use DO_UPCAST

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Just use the defined PCI_DEVICE cast macro.

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/pci-bridge/pci_bridge_dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/pci-bridge/pci_bridge_dev.c b/hw/pci-bridge/pci_bridge_dev.c
index 971b432..c845f38 100644
--- a/hw/pci-bridge/pci_bridge_dev.c
+++ b/hw/pci-bridge/pci_bridge_dev.c
@@ -104,7 +104,7 @@ static void pci_bridge_dev_write_config(PCIDevice *d,
 
 static void qdev_pci_bridge_dev_reset(DeviceState *qdev)
 {
-PCIDevice *dev = DO_UPCAST(PCIDevice, qdev, qdev);
+PCIDevice *dev = PCI_DEVICE(qdev);
 
 pci_bridge_reset(qdev);
 shpc_reset(dev);
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 16/30] pci/*: QOM casting sweep

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Use standard QOM cast macro. Remove usages of DO_UPCAST, container_of()
and direct - style upcasting.

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/pci/pci-hotplug.c | 18 ++
 hw/pci/pci.c | 17 +
 hw/pci/pcie.c|  4 ++--
 hw/pci/shpc.c|  8 
 4 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/hw/pci/pci-hotplug.c b/hw/pci/pci-hotplug.c
index 12287d1..0009190 100644
--- a/hw/pci/pci-hotplug.c
+++ b/hw/pci/pci-hotplug.c
@@ -129,7 +129,7 @@ int pci_drive_hot_add(Monitor *mon, const QDict *qdict, 
DriveInfo *dinfo)
 monitor_printf(mon, no pci device with address %s\n, pci_addr);
 goto err;
 }
-if (scsi_hot_add(mon, dev-qdev, dinfo, 1) != 0) {
+if (scsi_hot_add(mon, DEVICE(dev), dinfo, 1) != 0) {
 goto err;
 }
 break;
@@ -193,11 +193,12 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
 switch (type) {
 case IF_SCSI:
 dev = pci_create(bus, devfn, lsi53c895a);
-if (qdev_init(dev-qdev)  0)
+if (qdev_init(DEVICE(dev))  0) {
 dev = NULL;
+}
 if (dev  dinfo) {
-if (scsi_hot_add(mon, dev-qdev, dinfo, 0) != 0) {
-qdev_unplug(dev-qdev, NULL);
+if (scsi_hot_add(mon, DEVICE(dev), dinfo, 0) != 0) {
+qdev_unplug(DEVICE(dev), NULL);
 dev = NULL;
 }
 }
@@ -208,13 +209,14 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
 return NULL;
 }
 dev = pci_create(bus, devfn, virtio-blk-pci);
-if (qdev_prop_set_drive(dev-qdev, drive, dinfo-bdrv)  0) {
-qdev_free(dev-qdev);
+if (qdev_prop_set_drive(DEVICE(dev), drive, dinfo-bdrv)  0) {
+qdev_free(DEVICE(dev));
 dev = NULL;
 break;
 }
-if (qdev_init(dev-qdev)  0)
+if (qdev_init(DEVICE(dev))  0) {
 dev = NULL;
+}
 break;
 default:
 dev = NULL;
@@ -276,7 +278,7 @@ static int pci_device_hot_remove(Monitor *mon, const char 
*pci_addr)
 return -1;
 }
 
-qdev_unplug(d-qdev, local_err);
+qdev_unplug(DEVICE(d), local_err);
 if (error_is_set(local_err)) {
 monitor_printf(mon, %s\n, error_get_pretty(local_err));
 error_free(local_err);
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 61b681a..e3fd040 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -177,7 +177,7 @@ void pci_device_reset(PCIDevice *dev)
 {
 int r;
 
-qdev_reset_all(dev-qdev);
+qdev_reset_all(DEVICE(dev));
 
 dev-irq_state = 0;
 pci_update_irq_status(dev);
@@ -1446,6 +1446,7 @@ static PciBridgeInfo *qmp_query_pci_bridge(PCIDevice 
*dev, PCIBus *bus,
 static PciDeviceInfo *qmp_query_pci_device(PCIDevice *dev, PCIBus *bus,
int bus_num)
 {
+DeviceState *d = DEVICE(dev);
 const pci_class_desc *desc;
 PciDeviceInfo *info;
 uint8_t type;
@@ -1467,7 +1468,7 @@ static PciDeviceInfo *qmp_query_pci_device(PCIDevice 
*dev, PCIBus *bus,
 info-id.vendor = pci_get_word(dev-config + PCI_VENDOR_ID);
 info-id.device = pci_get_word(dev-config + PCI_DEVICE_ID);
 info-regions = qmp_query_pci_regions(dev);
-info-qdev_id = g_strdup(dev-qdev.id ? dev-qdev.id : );
+info-qdev_id = g_strdup(d-id ? d-id : );
 
 if (dev-config[PCI_INTERRUPT_PIN] != 0) {
 info-has_irq = true;
@@ -1591,7 +1592,7 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char 
*default_model,
 }
 
 pci_dev = pci_create(bus, devfn, pci_nic_names[i]);
-dev = pci_dev-qdev;
+dev = DEVICE(pci_dev);
 qdev_set_nic_properties(dev, nd);
 if (qdev_init(dev)  0)
 return NULL;
@@ -1731,7 +1732,7 @@ static int pci_qdev_init(DeviceState *qdev)
   qdev-hotplugged ? PCI_HOTPLUG_ENABLED:
   PCI_COLDPLUG_ENABLED);
 if (rc != 0) {
-int r = pci_unregister_device(pci_dev-qdev);
+int r = pci_unregister_device(DEVICE(pci_dev));
 assert(!r);
 return rc;
 }
@@ -1768,7 +1769,7 @@ PCIDevice *pci_create_simple_multifunction(PCIBus *bus, 
int devfn,
const char *name)
 {
 PCIDevice *dev = pci_create_multifunction(bus, devfn, multifunction, name);
-qdev_init_nofail(dev-qdev);
+qdev_init_nofail(DEVICE(dev));
 return dev;
 }
 
@@ -1946,7 +1947,7 @@ static int pci_add_option_rom(PCIDevice *pdev, bool 
is_default_rom)
 }
 pdev-has_rom = true;
 memory_region_init_ram(pdev-rom, name, size);
-vmstate_register_ram(pdev-rom, pdev-qdev);
+vmstate_register_ram(pdev-rom, DEVICE(pdev));
 ptr = memory_region_get_ram_ptr(pdev-rom);
 load_image(path, ptr);
 g_free(path);
@@ -1966,7 +1967,7 @@ static void 

[Qemu-devel] [PATCH v2 18/30] pci-bridge/*: substitute -qdev casts with DEVICE()

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/pci-bridge/i82801b11.c  | 2 +-
 hw/pci-bridge/ioh3420.c| 2 +-
 hw/pci-bridge/xio3130_downstream.c | 2 +-
 hw/pci-bridge/xio3130_upstream.c   | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/pci-bridge/i82801b11.c b/hw/pci-bridge/i82801b11.c
index 5807a92..8b20e27 100644
--- a/hw/pci-bridge/i82801b11.c
+++ b/hw/pci-bridge/i82801b11.c
@@ -108,7 +108,7 @@ PCIBus *ich9_d2pbr_init(PCIBus *bus, int devfn, int sec_bus)
 return NULL;
 }
 br = DO_UPCAST(PCIBridge, dev, d);
-qdev = br-dev.qdev;
+qdev = DEVICE(br);
 
 snprintf(buf, sizeof(buf), pci.%d, sec_bus);
 pci_bridge_map_irq(br, buf, pci_swizzle_map_irq_fn);
diff --git a/hw/pci-bridge/ioh3420.c b/hw/pci-bridge/ioh3420.c
index bb541eb..32f9ed6 100644
--- a/hw/pci-bridge/ioh3420.c
+++ b/hw/pci-bridge/ioh3420.c
@@ -173,7 +173,7 @@ PCIESlot *ioh3420_init(PCIBus *bus, int devfn, bool 
multifunction,
 }
 br = DO_UPCAST(PCIBridge, dev, d);
 
-qdev = br-dev.qdev;
+qdev = DEVICE(br);
 pci_bridge_map_irq(br, bus_name, map_irq);
 qdev_prop_set_uint8(qdev, port, port);
 qdev_prop_set_uint8(qdev, chassis, chassis);
diff --git a/hw/pci-bridge/xio3130_downstream.c 
b/hw/pci-bridge/xio3130_downstream.c
index 1810dd2..6a799e2 100644
--- a/hw/pci-bridge/xio3130_downstream.c
+++ b/hw/pci-bridge/xio3130_downstream.c
@@ -140,7 +140,7 @@ PCIESlot *xio3130_downstream_init(PCIBus *bus, int devfn, 
bool multifunction,
 }
 br = DO_UPCAST(PCIBridge, dev, d);
 
-qdev = br-dev.qdev;
+qdev = DEVICE(br);
 pci_bridge_map_irq(br, bus_name, map_irq);
 qdev_prop_set_uint8(qdev, port, port);
 qdev_prop_set_uint8(qdev, chassis, chassis);
diff --git a/hw/pci-bridge/xio3130_upstream.c b/hw/pci-bridge/xio3130_upstream.c
index 8e0d97a..9bb9daa 100644
--- a/hw/pci-bridge/xio3130_upstream.c
+++ b/hw/pci-bridge/xio3130_upstream.c
@@ -120,7 +120,7 @@ PCIEPort *xio3130_upstream_init(PCIBus *bus, int devfn, 
bool multifunction,
 }
 br = DO_UPCAST(PCIBridge, dev, d);
 
-qdev = br-dev.qdev;
+qdev = DEVICE(br);
 pci_bridge_map_irq(br, bus_name, map_irq);
 qdev_prop_set_uint8(qdev, port, port);
 qdev_init_nofail(qdev);
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 19/30] pci/pci_bridge: substitute -qdev casts with DEVICE()

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/pci/pci_bridge.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/hw/pci/pci_bridge.c b/hw/pci/pci_bridge.c
index 24be6c5..f6657e8 100644
--- a/hw/pci/pci_bridge.c
+++ b/hw/pci/pci_bridge.c
@@ -330,6 +330,7 @@ void pci_bridge_reset(DeviceState *qdev)
 /* default qdev initialization function for PCI-to-PCI bridge */
 int pci_bridge_initfn(PCIDevice *dev, const char *typename)
 {
+DeviceState *d = DEVICE(dev);
 PCIBus *parent = dev-bus;
 PCIBridge *br = DO_UPCAST(PCIBridge, dev, dev);
 PCIBus *sec_bus = br-sec_bus;
@@ -359,11 +360,11 @@ int pci_bridge_initfn(PCIDevice *dev, const char 
*typename)
  * Since PCI Bridge devices have a single bus each, we don't need the 
index:
  * let users address the bus using the device name.
  */
-if (!br-bus_name  dev-qdev.id  *dev-qdev.id) {
-   br-bus_name = dev-qdev.id;
+if (!br-bus_name  d-id  *d-id) {
+br-bus_name = d-id;
 }
 
-qbus_create_inplace(sec_bus-qbus, typename, dev-qdev, br-bus_name);
+qbus_create_inplace(sec_bus-qbus, typename, d, br-bus_name);
 sec_bus-parent_dev = dev;
 sec_bus-map_irq = br-map_irq ? br-map_irq : pci_swizzle_map_irq_fn;
 sec_bus-address_space_mem = br-address_space_mem;
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 20/30] misc/vfio: substitute -qdev casts with DEVICE()

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/misc/vfio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
index 52fb036..8e3524f 100644
--- a/hw/misc/vfio.c
+++ b/hw/misc/vfio.c
@@ -3074,7 +3074,7 @@ static int vfio_initfn(PCIDevice *pdev)
 }
 }
 
-add_boot_device_path(vdev-bootindex, pdev-qdev, NULL);
+add_boot_device_path(vdev-bootindex, DEVICE(pdev), NULL);
 
 return 0;
 
@@ -3108,7 +3108,7 @@ static void vfio_exitfn(PCIDevice *pdev)
 
 static void vfio_pci_reset(DeviceState *dev)
 {
-PCIDevice *pdev = DO_UPCAST(PCIDevice, qdev, dev);
+PCIDevice *pdev = PCI_DEVICE(dev);
 VFIODevice *vdev = DO_UPCAST(VFIODevice, pdev, pdev);
 uint16_t cmd;
 
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 21/30] net/eepro100: substitute -qdev casts with DEVICE()

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/net/eepro100.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c
index dc99ea6..f34b5dc 100644
--- a/hw/net/eepro100.c
+++ b/hw/net/eepro100.c
@@ -1842,13 +1842,14 @@ static void nic_cleanup(NetClientState *nc)
 
 static void pci_nic_uninit(PCIDevice *pci_dev)
 {
+DeviceState *d = DEVICE(pci_dev);
 EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev);
 
 memory_region_destroy(s-mmio_bar);
 memory_region_destroy(s-io_bar);
 memory_region_destroy(s-flash_bar);
-vmstate_unregister(pci_dev-qdev, s-vmstate, s);
-eeprom93xx_free(pci_dev-qdev, s-eeprom);
+vmstate_unregister(d, s-vmstate, s);
+eeprom93xx_free(d, s-eeprom);
 qemu_del_nic(s-nic);
 }
 
@@ -1862,6 +1863,7 @@ static NetClientInfo net_eepro100_info = {
 
 static int e100_nic_init(PCIDevice *pci_dev)
 {
+DeviceState *d = DEVICE(pci_dev);
 EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev);
 E100PCIDeviceInfo *info = eepro100_get_class(s);
 
@@ -1873,7 +1875,7 @@ static int e100_nic_init(PCIDevice *pci_dev)
 
 /* Add 64 * 2 EEPROM. i82557 and i82558 support a 64 word EEPROM,
  * i82559 and later support 64 or 256 word EEPROM. */
-s-eeprom = eeprom93xx_new(pci_dev-qdev, EEPROM_SIZE);
+s-eeprom = eeprom93xx_new(d, EEPROM_SIZE);
 
 /* Handler for memory-mapped I/O */
 memory_region_init_io(s-mmio_bar, eepro100_ops, s, eepro100-mmio,
@@ -1893,7 +1895,7 @@ static int e100_nic_init(PCIDevice *pci_dev)
 nic_reset(s);
 
 s-nic = qemu_new_nic(net_eepro100_info, s-conf,
-  object_get_typename(OBJECT(pci_dev)), 
pci_dev-qdev.id, s);
+  object_get_typename(OBJECT(pci_dev)), d-id, s);
 
 qemu_format_nic_info_str(qemu_get_queue(s-nic), s-conf.macaddr.a);
 TRACE(OTHER, logout(%s\n, qemu_get_queue(s-nic)-info_str));
@@ -1903,9 +1905,9 @@ static int e100_nic_init(PCIDevice *pci_dev)
 s-vmstate = g_malloc(sizeof(vmstate_eepro100));
 memcpy(s-vmstate, vmstate_eepro100, sizeof(vmstate_eepro100));
 s-vmstate-name = qemu_get_queue(s-nic)-model;
-vmstate_register(pci_dev-qdev, -1, s-vmstate, s);
+vmstate_register(d, -1, s-vmstate, s);
 
-add_boot_device_path(s-conf.bootindex, pci_dev-qdev, /ethernet-phy@0);
+add_boot_device_path(s-conf.bootindex, d, /ethernet-phy@0);
 
 return 0;
 }
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 22/30] net/ne2000: substitute -qdev casts with DEVICE()

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/net/ne2000.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/hw/net/ne2000.c b/hw/net/ne2000.c
index 33ee03e..70a7991 100644
--- a/hw/net/ne2000.c
+++ b/hw/net/ne2000.c
@@ -722,6 +722,8 @@ static NetClientInfo net_ne2000_info = {
 static int pci_ne2000_init(PCIDevice *pci_dev)
 {
 PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, pci_dev);
+DeviceState *ds = DEVICE(pci_dev);
+
 NE2000State *s;
 uint8_t *pci_conf;
 
@@ -737,10 +739,10 @@ static int pci_ne2000_init(PCIDevice *pci_dev)
 ne2000_reset(s);
 
 s-nic = qemu_new_nic(net_ne2000_info, s-c,
-  object_get_typename(OBJECT(pci_dev)), 
pci_dev-qdev.id, s);
+  object_get_typename(OBJECT(pci_dev)), ds-id, s);
 qemu_format_nic_info_str(qemu_get_queue(s-nic), s-c.macaddr.a);
 
-add_boot_device_path(s-c.bootindex, pci_dev-qdev, /ethernet-phy@0);
+add_boot_device_path(s-c.bootindex, ds, /ethernet-phy@0);
 
 return 0;
 }
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 23/30] usb/*: substitute -qdev casts with DEVICE()

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/usb/hcd-ehci-pci.c | 13 -
 hw/usb/hcd-ohci.c |  2 +-
 hw/usb/hcd-uhci.c |  2 +-
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/hw/usb/hcd-ehci-pci.c b/hw/usb/hcd-ehci-pci.c
index f1b5f5d..998a9bf 100644
--- a/hw/usb/hcd-ehci-pci.c
+++ b/hw/usb/hcd-ehci-pci.c
@@ -197,6 +197,7 @@ int ehci_create_ich9_with_companions(PCIBus *bus, int slot)
 const struct ehci_companions *comp;
 PCIDevice *ehci, *uhci;
 BusState *usbbus;
+DeviceState *dev;
 const char *name;
 int i;
 
@@ -214,15 +215,17 @@ int ehci_create_ich9_with_companions(PCIBus *bus, int 
slot)
 }
 
 ehci = pci_create_multifunction(bus, PCI_DEVFN(slot, 7), true, name);
-qdev_init_nofail(ehci-qdev);
-usbbus = QLIST_FIRST(ehci-qdev.child_bus);
+dev = DEVICE(ehci);
+qdev_init_nofail(dev);
+usbbus = QLIST_FIRST(dev-child_bus);
 
 for (i = 0; i  3; i++) {
 uhci = pci_create_multifunction(bus, PCI_DEVFN(slot, comp[i].func),
 true, comp[i].name);
-qdev_prop_set_string(uhci-qdev, masterbus, usbbus-name);
-qdev_prop_set_uint32(uhci-qdev, firstport, comp[i].port);
-qdev_init_nofail(uhci-qdev);
+dev = DEVICE(uhci);
+qdev_prop_set_string(dev, masterbus, usbbus-name);
+qdev_prop_set_uint32(dev, firstport, comp[i].port);
+qdev_init_nofail(dev);
 }
 return 0;
 }
diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c
index 5513924..2f88db6 100644
--- a/hw/usb/hcd-ohci.c
+++ b/hw/usb/hcd-ohci.c
@@ -1857,7 +1857,7 @@ static int usb_ohci_initfn_pci(struct PCIDevice *dev)
 ohci-pci_dev.config[PCI_CLASS_PROG] = 0x10; /* OHCI */
 ohci-pci_dev.config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt pin A */
 
-if (usb_ohci_init(ohci-state, dev-qdev, ohci-num_ports, 0,
+if (usb_ohci_init(ohci-state, DEVICE(dev), ohci-num_ports, 0,
   ohci-masterbus, ohci-firstport,
   pci_get_address_space(dev)) != 0) {
 return -1;
diff --git a/hw/usb/hcd-uhci.c b/hw/usb/hcd-uhci.c
index c85b203..67c13c3 100644
--- a/hw/usb/hcd-uhci.c
+++ b/hw/usb/hcd-uhci.c
@@ -1246,7 +1246,7 @@ static int usb_uhci_common_initfn(PCIDevice *dev)
 return -1;
 }
 } else {
-usb_bus_new(s-bus, uhci_bus_ops, s-dev.qdev);
+usb_bus_new(s-bus, uhci_bus_ops, DEVICE(dev));
 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);
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 24/30] watchdog/wdt_i6300esb: substitute -qdev casts with DEVICE()

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/watchdog/wdt_i6300esb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/watchdog/wdt_i6300esb.c b/hw/watchdog/wdt_i6300esb.c
index 05af0b1..93077bb 100644
--- a/hw/watchdog/wdt_i6300esb.c
+++ b/hw/watchdog/wdt_i6300esb.c
@@ -195,7 +195,7 @@ static void i6300esb_timer_expired(void *vp)
 if (d-reboot_enabled) {
 d-previous_reboot_flag = 1;
 watchdog_perform_action(); /* This reboots, exits, etc */
-i6300esb_reset(d-dev.qdev);
+i6300esb_reset(DEVICE(d));
 }
 
 /* In free running mode we start stage 1 again. */
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH v2 25/30] scsi/vmw_pvscsi: substitute -qdev casts with DEVICE()

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/scsi/vmw_pvscsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/scsi/vmw_pvscsi.c b/hw/scsi/vmw_pvscsi.c
index 7cf4044..35b971d 100644
--- a/hw/scsi/vmw_pvscsi.c
+++ b/hw/scsi/vmw_pvscsi.c
@@ -1088,7 +1088,7 @@ pvscsi_init(PCIDevice *pci_dev)
 return -ENOMEM;
 }
 
-scsi_bus_new(s-bus, pci_dev-qdev, pvscsi_scsi_info, NULL);
+scsi_bus_new(s-bus, DEVICE(pci_dev), pvscsi_scsi_info, NULL);
 pvscsi_reset_state(s);
 
 return 0;
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH V3 02/10] NUMA: Add numa_info structure to contain numa nodes info

2013-06-24 Thread Wanlong Gao
Add the numa_info structure to contain the numa nodes memory,
VCPUs information and the future added numa nodes host memory
policies.

Signed-off-by: Andre Przywara andre.przyw...@amd.com
Signed-off-by: Wanlong Gao gaowanl...@cn.fujitsu.com
---
 cpus.c  |  2 +-
 hw/i386/pc.c|  4 ++--
 hw/net/eepro100.c   |  1 -
 include/sysemu/sysemu.h |  8 ++--
 monitor.c   |  2 +-
 vl.c| 24 
 6 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/cpus.c b/cpus.c
index c8bc8ad..e123d3f 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1195,7 +1195,7 @@ void set_numa_modes(void)
 for (env = first_cpu; env != NULL; env = env-next_cpu) {
 cpu = ENV_GET_CPU(env);
 for (i = 0; i  nb_numa_nodes; i++) {
-if (test_bit(cpu-cpu_index, node_cpumask[i])) {
+if (test_bit(cpu-cpu_index, numa_info[i].node_cpu)) {
 cpu-numa_node = i;
 }
 }
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 5e8f143..32d039a 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -650,14 +650,14 @@ static FWCfgState *bochs_bios_init(void)
 unsigned int apic_id = x86_cpu_apic_id_from_index(i);
 assert(apic_id  apic_id_limit);
 for (j = 0; j  nb_numa_nodes; j++) {
-if (test_bit(i, node_cpumask[j])) {
+if (test_bit(i, numa_info[j].node_cpu)) {
 numa_fw_cfg[apic_id + 1] = cpu_to_le64(j);
 break;
 }
 }
 }
 for (i = 0; i  nb_numa_nodes; i++) {
-numa_fw_cfg[apic_id_limit + 1 + i] = cpu_to_le64(node_mem[i]);
+numa_fw_cfg[apic_id_limit + 1 + i] = 
cpu_to_le64(numa_info[i].node_mem);
 }
 fw_cfg_add_bytes(fw_cfg, FW_CFG_NUMA, numa_fw_cfg,
  (1 + apic_id_limit + nb_numa_nodes) *
diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c
index dc99ea6..478c688 100644
--- a/hw/net/eepro100.c
+++ b/hw/net/eepro100.c
@@ -105,7 +105,6 @@
 #define PCI_IO_SIZE 64
 #define PCI_FLASH_SIZE  (128 * KiB)
 
-#define BIT(n) (1  (n))
 #define BITS(n, m) (((0xU  (31 - n))  (31 - n + m))  m)
 
 /* The SCB accepts the following controls for the Tx and Rx units: */
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 2fb71af..70fd2ed 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -9,6 +9,7 @@
 #include qapi-types.h
 #include qemu/notify.h
 #include qemu/main-loop.h
+#include qemu/bitmap.h
 
 /* vl.c */
 
@@ -130,8 +131,11 @@ extern QEMUClock *rtc_clock;
 #define MAX_NODES 64
 #define MAX_CPUMASK_BITS 255
 extern int nb_numa_nodes;
-extern uint64_t node_mem[MAX_NODES];
-extern unsigned long *node_cpumask[MAX_NODES];
+struct node_info {
+uint64_t node_mem;
+DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS);
+};
+extern struct node_info numa_info[MAX_NODES];
 
 #define MAX_OPTION_ROMS 16
 typedef struct QEMUOptionRom {
diff --git a/monitor.c b/monitor.c
index 70ae8f5..61dbebb 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1819,7 +1819,7 @@ static void do_info_numa(Monitor *mon, const QDict *qdict)
 }
 monitor_printf(mon, \n);
 monitor_printf(mon, node %d size: % PRId64  MB\n, i,
-node_mem[i]  20);
+numa_info[i].node_mem  20);
 }
 }
 
diff --git a/vl.c b/vl.c
index a1e5ce9..357137b 100644
--- a/vl.c
+++ b/vl.c
@@ -250,8 +250,7 @@ static QTAILQ_HEAD(, FWBootEntry) fw_boot_order =
 QTAILQ_HEAD_INITIALIZER(fw_boot_order);
 
 int nb_numa_nodes;
-uint64_t node_mem[MAX_NODES];
-unsigned long *node_cpumask[MAX_NODES];
+struct node_info numa_info[MAX_NODES];
 
 uint8_t qemu_uuid[16];
 
@@ -1367,7 +1366,7 @@ static void numa_node_parse_cpus(int nodenr, const char 
*cpus)
 goto error;
 }
 
-bitmap_set(node_cpumask[nodenr], value, endvalue-value+1);
+bitmap_set(numa_info[nodenr].node_cpu, value, endvalue-value+1);
 return;
 
 error:
@@ -1399,7 +1398,7 @@ static int numa_init_func(QemuOpts *opts, void *opaque)
 }
 
 mem_size = qemu_opt_get_size(opts, mem, 0);
-node_mem[nodenr] = mem_size;
+numa_info[nodenr].node_mem = mem_size;
 
 if (qemu_opt_foreach(opts, numa_add_cpus, nodenr, 1)  0) {
 return -1;
@@ -2929,8 +2928,8 @@ int main(int argc, char **argv, char **envp)
 translation = BIOS_ATA_TRANSLATION_AUTO;
 
 for (i = 0; i  MAX_NODES; i++) {
-node_mem[i] = 0;
-node_cpumask[i] = bitmap_new(MAX_CPUMASK_BITS);
+numa_info[i].node_mem = 0;
+bitmap_zero(numa_info[i].node_cpu, MAX_CPUMASK_BITS);
 }
 
 nb_numa_nodes = 0;
@@ -4213,7 +4212,7 @@ int main(int argc, char **argv, char **envp)
  * and distribute the available memory equally across all nodes
  */
 for (i = 0; i  nb_numa_nodes; i++) {
-if (node_mem[i] != 0)
+if (numa_info[i].node_mem != 0)
 break;
 }
 if (i == nb_numa_nodes) {
@@ -4223,14 +4222,15 @@ int 

[Qemu-devel] [PATCH V3 05/10] NUMA: handle Error in cpus, mpol and hostnode parser

2013-06-24 Thread Wanlong Gao
As Paolo pointed out that, handle Error in mpol and hostnode parser
will make it easier to be used for example in mem-hotplug in the future.
And this will be used later in set-mpol QMP command.
Also handle Error in cpus parser to be consistent with others.

Signed-off-by: Wanlong Gao gaowanl...@cn.fujitsu.com
---
 include/sysemu/sysemu.h |  4 
 vl.c| 42 --
 2 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 993b8e0..0f135fe 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -144,6 +144,10 @@ struct node_info {
 unsigned int flags;
 };
 extern struct node_info numa_info[MAX_NODES];
+extern void numa_node_parse_mpol(int nodenr, const char *hostnode,
+ Error **errp);
+extern void numa_node_parse_hostnode(int nodenr, const char *hostnode,
+ Error **errp);
 
 #define MAX_OPTION_ROMS 16
 typedef struct QEMUOptionRom {
diff --git a/vl.c b/vl.c
index 4dbf5cc..79c39b9 100644
--- a/vl.c
+++ b/vl.c
@@ -1338,7 +1338,7 @@ char *get_boot_devices_list(size_t *size)
 return list;
 }
 
-static void numa_node_parse_cpus(int nodenr, const char *cpus)
+static void numa_node_parse_cpus(int nodenr, const char *cpus, Error **errp)
 {
 char *endptr;
 unsigned long long value, endvalue;
@@ -1378,13 +1378,14 @@ static void numa_node_parse_cpus(int nodenr, const char 
*cpus)
 return;
 
 error:
-fprintf(stderr, qemu: Invalid NUMA CPU range: %s\n, cpus);
-exit(1);
+error_setg(errp, Invalid NUMA CPU range: %s\n, cpus);
+return;
 }
 
-static void numa_node_parse_mpol(int nodenr, const char *mpol)
+void numa_node_parse_mpol(int nodenr, const char *mpol, Error **errp)
 {
 if (!mpol) {
+error_setg(errp, Should specify memory policy);
 return;
 }
 
@@ -1395,11 +1396,11 @@ static void numa_node_parse_mpol(int nodenr, const char 
*mpol)
 } else if (!strcmp(mpol, membind)) {
 numa_info[nodenr].flags |= NODE_HOST_BIND;
 } else {
-fprintf(stderr, qemu: Invalid memory policy: %s\n, mpol);
+error_setg(errp, Invalid memory policy: %s, mpol);
 }
 }
 
-static void numa_node_parse_hostnode(int nodenr, const char *hostnode)
+void numa_node_parse_hostnode(int nodenr, const char *hostnode, Error **errp)
 {
 unsigned long long value, endvalue;
 char *endptr;
@@ -1452,16 +1453,22 @@ static void numa_node_parse_hostnode(int nodenr, const 
char *hostnode)
 return;
 
 error:
-fprintf(stderr, qemu: Invalid host NUMA nodes range: %s\n, hostnode);
+error_setg(errp, Invalid host NUMA nodes range: %s, hostnode);
 return;
 }
 
 static int numa_add_cpus(const char *name, const char *value, void *opaque)
 {
 int *nodenr = opaque;
+Error *err = NULL;
 
 if (!strcmp(name, cpu)) {
-numa_node_parse_cpus(*nodenr, value);
+numa_node_parse_cpus(*nodenr, value, err);
+}
+if (error_is_set(err)) {
+fprintf(stderr, qemu: %s\n, error_get_pretty(err));
+error_free(err);
+return -1;
 }
 return 0;
 }
@@ -1469,19 +1476,34 @@ static int numa_add_cpus(const char *name, const char 
*value, void *opaque)
 static int numa_add_mpol(const char *name, const char *value, void *opaque)
 {
 int *nodenr = opaque;
+Error *err = NULL;
 
 if (!strcmp(name, mem-policy)) {
-numa_node_parse_mpol(*nodenr, value);
+numa_node_parse_mpol(*nodenr, value, err);
+}
+if (error_is_set(err)) {
+fprintf(stderr, qemu: %s\n, error_get_pretty(err));
+error_free(err);
+return -1;
 }
+
 return 0;
 }
 
 static int numa_add_hostnode(const char *name, const char *value, void *opaque)
 {
 int *nodenr = opaque;
+Error *err = NULL;
+
 if (!strcmp(name, mem-hostnode)) {
-numa_node_parse_hostnode(*nodenr, value);
+numa_node_parse_hostnode(*nodenr, value, err);
 }
+if (error_is_set(err)) {
+fprintf(stderr, qemu: %s\n, error_get_pretty(err));
+error_free(err);
+return -1;
+}
+
 return 0;
 }
 
-- 
1.8.3.1.448.gfb7dfaa




Re: [Qemu-devel] [PATCH] RFC kvm irqfd: add directly mapped MSI IRQ support

2013-06-24 Thread Gleb Natapov
On Sun, Jun 23, 2013 at 10:06:05AM -0500, Anthony Liguori wrote:
 On Thu, Jun 20, 2013 at 11:46 PM, Alex Williamson
 alex.william...@redhat.com wrote:
  On Fri, 2013-06-21 at 12:49 +1000, Alexey Kardashevskiy wrote:
  On 06/21/2013 12:34 PM, Alex Williamson wrote:
 
 
  Do not follow you, sorry. For x86, is it that MSI routing table which is
  updated via KVM_SET_GSI_ROUTING in KVM? When there is no KVM, what piece of
  code responds on msi_notify() in qemu-x86 and does qemu_irq_pulse()?
 
  vfio_msi_interrupt-msi[x]_notify-stl_le_phys(msg.address, msg.data)
 
  This writes directly to the interrupt block on the vCPU.  With KVM, the
  in-kernel APIC does the same write, where the pin to MSIMessage is setup
  by kvm_irqchip_add_msi_route and the pin is pulled by an irqfd.
 
 What is this interrupt block on the vCPU you speak of?  I reviewed
FEE0H address as seen from PCI bus is a special address range (see
10.11.1 in SDM). Any write by a PCI device to that address range is
interpreted as MSI. We do not model this correctly in QEMU yet since
all devices, including vcpus, see exactly same memory map.

 the SDM and see nothing in the APIC protocol or the brief description
 of MSI as a PCI concept that would indicate anything except that the
 PHB handles MSI writes and feeds them to the I/O APIC.
 
I/O APIC? Did you mean APIC, but even that will probably be incorrect.
I'd say it translates the data to APIC bus message. And with interrupt
remapping there is more magic happens between MSI and APIC bus.

 In fact, the wikipedia article on MSI has:
 
 A common misconception with Message Signaled Interrupts is that they
 allow the device to send data to a processor as part of the interrupt.
 The data that is sent as part of the write is used by the chipset to
 determine which interrupt to trigger on which processor; it is not
 available for the device to communicate additional information to the
 interrupt handler.
 
Not sure who claimed otherwise.

  Do I understand that on POWER the MSI from the device is intercepted at
  the PHB and converted to an IRQ that's triggered by some means other
  than a MSI write?
 
 This is exactly the same thing that happens on x86, no?  Can you point
 me to something in the SDM that says otherwise?
 
 Regards,
 
 Anthony Liguori
 
   So to correctly model the hardware, vfio should do a
  msi_notify() that does a stl_le_phys that terminates at this IRQ
  remapper thing and in turn toggles a qemu_irq.  MSIMessage is only
  extraneous data if you want to skip over hardware blocks.
 
  Maybe you could add a device parameter to kvm_irqchip_add_msi_route so
  that it can be implemented on POWER without this pci_bus_map_msi
  interface that seems very unique to POWER.  Thanks,
 
  Alex
 
   ---
hw/misc/vfio.c   |   11 +--
hw/pci/pci.c |   13 +
hw/ppc/spapr_pci.c   |   13 +
hw/virtio/virtio-pci.c   |   26 --
include/hw/pci/pci.h |4 
include/hw/pci/pci_bus.h |1 +
6 files changed, 60 insertions(+), 8 deletions(-)
  
   diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
   index 14aac04..2d9eef7 100644
   --- a/hw/misc/vfio.c
   +++ b/hw/misc/vfio.c
   @@ -639,7 +639,11 @@ static int vfio_msix_vector_do_use(PCIDevice 
   *pdev, unsigned int nr,
 * Attempt to enable route through KVM irqchip,
 * default to userspace handling if unavailable.
 */
   -vector-virq = msg ? kvm_irqchip_add_msi_route(kvm_state, *msg) 
   : -1;
   +
   +vector-virq = msg ? pci_bus_map_msi(vdev-pdev.bus, *msg) : -1;
   +if (vector-virq  0) {
   +vector-virq = msg ? kvm_irqchip_add_msi_route(kvm_state, 
   *msg) : -1;
   +}
if (vector-virq  0 ||
kvm_irqchip_add_irqfd_notifier(kvm_state, vector-interrupt,
   vector-virq)  0) {
   @@ -807,7 +811,10 @@ retry:
 * Attempt to enable route through KVM irqchip,
 * default to userspace handling if unavailable.
 */
   -vector-virq = kvm_irqchip_add_msi_route(kvm_state, msg);
   +vector-virq = pci_bus_map_msi(vdev-pdev.bus, msg);
   +if (vector-virq  0) {
   +vector-virq = kvm_irqchip_add_msi_route(kvm_state, msg);
   +}
if (vector-virq  0 ||
kvm_irqchip_add_irqfd_notifier(kvm_state, 
   vector-interrupt,
   vector-virq)  0) {
   diff --git a/hw/pci/pci.c b/hw/pci/pci.c
   index a976e46..a9875e9 100644
   --- a/hw/pci/pci.c
   +++ b/hw/pci/pci.c
   @@ -1254,6 +1254,19 @@ void 
   pci_device_set_intx_routing_notifier(PCIDevice *dev,
dev-intx_routing_notifier = notifier;
}
  
   +void pci_bus_set_map_msi_fn(PCIBus *bus, pci_map_msi_fn map_msi_fn)
   +{
   +bus-map_msi = map_msi_fn;
   +}
   +
   +int pci_bus_map_msi(PCIBus *bus, MSIMessage msg)
   +{
   +if (bus-map_msi) {
   +

[Qemu-devel] [PATCH V3 03/10] NUMA: Add Linux libnuma detection

2013-06-24 Thread Wanlong Gao
Add detection of libnuma (mostly contained in the numactl package)
to the configure script. Can be enabled or disabled on the command line,
default is use if available.

Signed-off-by: Andre Przywara andre.przyw...@amd.com
Signed-off-by: Wanlong Gao gaowanl...@cn.fujitsu.com
---
 configure | 32 
 1 file changed, 32 insertions(+)

diff --git a/configure b/configure
index ad32f87..2d2b177 100755
--- a/configure
+++ b/configure
@@ -242,6 +242,7 @@ gtk=
 gtkabi=2.0
 tpm=no
 libssh2=
+numa=
 
 # parse CC options first
 for opt do
@@ -944,6 +945,10 @@ for opt do
   ;;
   --enable-libssh2) libssh2=yes
   ;;
+  --disable-numa) numa=no
+  ;;
+  --enable-numa) numa=yes
+  ;;
   *) echo ERROR: unknown option $opt; show_help=yes
   ;;
   esac
@@ -1158,6 +1163,8 @@ echo   --gcov=GCOV  use specified gcov 
[$gcov_tool]
 echo   --enable-tpm enable TPM support
 echo   --disable-libssh2disable ssh block device support
 echo   --enable-libssh2 enable ssh block device support
+echo   --disable-numa   disable libnuma support
+echo   --enable-numaenable libnuma support
 echo 
 echo NOTE: The object files are built at the place where configure is 
launched
 exit 1
@@ -2389,6 +2396,27 @@ EOF
 fi
 
 ##
+# libnuma probe
+
+if test $numa != no ; then
+  numa=no
+  cat  $TMPC  EOF
+#include numa.h
+int main(void) { return numa_available(); }
+EOF
+
+  if compile_prog  -lnuma ; then
+numa=yes
+libs_softmmu=-lnuma $libs_softmmu
+  else
+if test $numa = yes ; then
+  feature_not_found linux NUMA (install numactl?)
+fi
+numa=no
+  fi
+fi
+
+##
 # linux-aio probe
 
 if test $linux_aio != no ; then
@@ -3556,6 +3584,7 @@ echo TPM support   $tpm
 echo libssh2 support   $libssh2
 echo TPM passthrough   $tpm_passthrough
 echo QOM debugging $qom_cast_debug
+echo NUMA host support $numa
 
 if test $sdl_too_old = yes; then
 echo - Your SDL version is too old - please upgrade to have SDL support
@@ -3589,6 +3618,9 @@ echo extra_cflags=$EXTRA_CFLAGS  $config_host_mak
 echo extra_ldflags=$EXTRA_LDFLAGS  $config_host_mak
 echo qemu_localedir=$qemu_localedir  $config_host_mak
 echo libs_softmmu=$libs_softmmu  $config_host_mak
+if test $numa = yes; then
+  echo CONFIG_NUMA=y  $config_host_mak
+fi
 
 echo ARCH=$ARCH  $config_host_mak
 
-- 
1.8.3.1.448.gfb7dfaa




[Qemu-devel] [PATCH V3 08/10] NUMA: add qmp command set-mpol to set memory policy for NUMA node

2013-06-24 Thread Wanlong Gao
The QMP command let it be able to set node's memory policy
through the QMP protocol. The qmp-shell command is like:
set-mpol nodeid=0 mem-policy=membind mem-hostnode=0-1

Signed-off-by: Wanlong Gao gaowanl...@cn.fujitsu.com
---
 cpus.c   | 54 ++
 qapi-schema.json | 15 +++
 qmp-commands.hx  | 35 +++
 3 files changed, 104 insertions(+)

diff --git a/cpus.c b/cpus.c
index 677ee15..9c2706c 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1432,3 +1432,57 @@ void qmp_inject_nmi(Error **errp)
 error_set(errp, QERR_UNSUPPORTED);
 #endif
 }
+
+void qmp_set_mpol(int64_t nodeid, bool has_mpol, const char *mpol,
+  bool has_hostnode, const char *hostnode, Error **errp)
+{
+unsigned int flags;
+DECLARE_BITMAP(host_mem, MAX_CPUMASK_BITS);
+
+if (nodeid = nb_numa_nodes) {
+error_setg(errp, Only has '%d' NUMA nodes, nb_numa_nodes);
+return;
+}
+
+bitmap_copy(host_mem, numa_info[nodeid].host_mem, MAX_CPUMASK_BITS);
+flags = numa_info[nodeid].flags;
+
+numa_info[nodeid].flags = NODE_HOST_NONE;
+bitmap_zero(numa_info[nodeid].host_mem, MAX_CPUMASK_BITS);
+
+if (!has_mpol) {
+if (set_node_mpol(nodeid) == -1) {
+error_setg(errp, Failed to set memory policy for node%lu, 
nodeid);
+goto error;
+}
+return;
+}
+
+numa_node_parse_mpol(nodeid, mpol, errp);
+if (error_is_set(errp)) {
+goto error;
+}
+
+if (!has_hostnode) {
+bitmap_fill(numa_info[nodeid].host_mem, MAX_CPUMASK_BITS);
+}
+
+if (hostnode) {
+numa_node_parse_hostnode(nodeid, hostnode, errp);
+if (error_is_set(errp)) {
+goto error;
+}
+}
+
+if (set_node_mpol(nodeid) == -1) {
+error_setg(errp, Failed to set memory policy for node%lu, nodeid);
+goto error;
+}
+
+return;
+
+error:
+bitmap_copy(numa_info[nodeid].host_mem, host_mem, MAX_CPUMASK_BITS);
+numa_info[nodeid].flags = flags;
+return;
+}
diff --git a/qapi-schema.json b/qapi-schema.json
index a80ee40..cedcbe1 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3608,3 +3608,18 @@
 '*cpuid-input-ecx': 'int',
 'cpuid-register': 'X86CPURegister32',
 'features': 'int' } }
+
+# @set-mpol:
+#
+# Set the host memory binding policy for guest NUMA node.
+#
+# @nodeid: The node ID of guest NUMA node to set memory policy to.
+#
+# @mem-policy: The memory policy string to set.
+#
+# @mem-hostnode: The host node or node range for memory policy.
+#
+# Since: 1.6.0
+##
+{ 'command': 'set-mpol', 'data': {'nodeid': 'int', '*mem-policy': 'str',
+  '*mem-hostnode': 'str'} }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 8cea5e5..7bb5038 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -2997,3 +2997,38 @@ Example:
 - { return: {} }
 
 EQMP
+
+{
+.name  = set-mpol,
+.args_type = nodeid:i,mem-policy:s?,mem-hostnode:s?,
+.help  = Set the host memory binding policy for guest NUMA node,
+.mhandler.cmd_new = qmp_marshal_input_set_mpol,
+},
+
+SQMP
+set-mpol
+--
+
+Set the host memory binding policy for guest NUMA node
+
+Arguments:
+
+- nodeid: The nodeid of guest NUMA node to set memory policy to.
+(json-int)
+- mem-policy: The memory policy string to set.
+(json-string, optional)
+- mem-hostnode: The host nodes contained to mpol.
+  (json-string, optional)
+
+Example:
+
+- { execute: set-mpol, arguments: { nodeid: 0, mem-policy: 
membind,
+   mem-hostnode: 0-1 }}
+- { return: {} }
+
+Notes:
+1. If mem-policy is not set, the memory policy of this nodeid will be 
set
+   to default.
+2. If mem-hostnode is not set, the node mask of this mpol will be set
+   to all.
+EQMP
-- 
1.8.3.1.448.gfb7dfaa




[Qemu-devel] [PATCH V3 10/10] NUMA: show host memory policy info in info numa command

2013-06-24 Thread Wanlong Gao
Show host memory policy of nodes in the info numa monitor command.
After this patch, the monitor command info numa will show the
information like following if the host numa support is enabled:

(qemu) info numa
2 nodes
node 0 cpus: 0
node 0 size: 1024 MB
node 0 mempolicy: membind=0,1
node 1 cpus: 1
node 1 size: 1024 MB
node 1 mempolicy: interleave=1

Signed-off-by: Wanlong Gao gaowanl...@cn.fujitsu.com
---
 monitor.c | 42 ++
 1 file changed, 42 insertions(+)

diff --git a/monitor.c b/monitor.c
index 61dbebb..b6e93e5 100644
--- a/monitor.c
+++ b/monitor.c
@@ -74,6 +74,11 @@
 #endif
 #include hw/lm32/lm32_pic.h
 
+#ifdef CONFIG_NUMA
+#include numa.h
+#include numaif.h
+#endif
+
 //#define DEBUG
 //#define DEBUG_COMPLETION
 
@@ -1807,6 +1812,7 @@ static void do_info_numa(Monitor *mon, const QDict *qdict)
 int i;
 CPUArchState *env;
 CPUState *cpu;
+unsigned long first, next;
 
 monitor_printf(mon, %d nodes\n, nb_numa_nodes);
 for (i = 0; i  nb_numa_nodes; i++) {
@@ -1820,6 +1826,42 @@ static void do_info_numa(Monitor *mon, const QDict 
*qdict)
 monitor_printf(mon, \n);
 monitor_printf(mon, node %d size: % PRId64  MB\n, i,
 numa_info[i].node_mem  20);
+
+#ifdef CONFIG_NUMA
+monitor_printf(mon, node %d mempolicy: , i);
+switch (numa_info[i].flags  NODE_HOST_POLICY_MASK) {
+case NODE_HOST_BIND:
+monitor_printf(mon, membind=);
+break;
+case NODE_HOST_INTERLEAVE:
+monitor_printf(mon, interleave=);
+break;
+case NODE_HOST_PREFERRED:
+monitor_printf(mon, preferred=);
+break;
+default:
+monitor_printf(mon, default\n);
+continue;
+}
+
+if (numa_info[i].flags  NODE_HOST_RELATIVE)
+monitor_printf(mon, +);
+
+next = first = find_first_bit(numa_info[i].host_mem, MAX_CPUMASK_BITS);
+monitor_printf(mon, %lu, first);
+do {
+if (next == numa_max_node())
+break;
+next = find_next_bit(numa_info[i].host_mem, MAX_CPUMASK_BITS,
+ next + 1);
+if (next  numa_max_node() || next == MAX_CPUMASK_BITS)
+break;
+
+monitor_printf(mon, ,%lu, next);
+} while (true);
+
+monitor_printf(mon, \n);
+#endif
 }
 }
 
-- 
1.8.3.1.448.gfb7dfaa




[Qemu-devel] [PATCH V3 00/10] Add support for binding guest numa nodes to host numa nodes

2013-06-24 Thread Wanlong Gao
As you know, QEMU can't direct it's memory allocation now, this may cause
guest cross node access performance regression.
And, the worse thing is that if PCI-passthrough is used,
direct-attached-device uses DMA transfer between device and qemu process.
All pages of the guest will be pinned by get_user_pages().

KVM_ASSIGN_PCI_DEVICE ioctl
  kvm_vm_ioctl_assign_device()
=kvm_assign_device()
  = kvm_iommu_map_memslots()
= kvm_iommu_map_pages()
   = kvm_pin_pages()

So, with direct-attached-device, all guest page's page count will be +1 and
any page migration will not work. AutoNUMA won't too.

So, we should set the guest nodes memory allocation policy before
the pages are really mapped.

According to this patch set, we are able to set guest nodes memory policy
like following:

 -numa node,nodeid=0,mem=1024,cpus=0,mem-policy=membind,mem-hostnode=0-1
 -numa node,nodeid=1,mem=1024,cpus=1,mem-policy=interleave,mem-hostnode=1

This supports 
mem-policy={membind|interleave|preferred},mem-hostnode=[+|!]{all|N-N} like 
format.

And patch 8/10 adds a QMP command set-mpol to set the memory policy for every
guest nodes:
set-mpol nodeid=0 mem-policy=membind mem-hostnode=0-1

And patch 9/10 adds a monitor command set-mpol whose format like:
set-mpol 0 mem-policy=membind,mem-hostnode=0-1

And with patch 10/10, we can get the current memory policy of each guest node
using monitor command info numa, for example:

(qemu) info numa
2 nodes
node 0 cpus: 0
node 0 size: 1024 MB
node 0 mempolicy: membind=0,1
node 1 cpus: 1
node 1 size: 1024 MB
node 1 mempolicy: interleave=1


V1-V2:
change to use QemuOpts in numa options (Paolo)
handle Error in mpol parser (Paolo)
change qmp command format to mem-policy=membind,mem-hostnode=0-1 like 
(Paolo)
V2-V3:
also handle Error in cpus parser (5/10)
split out common parser from cpus and hostnode parser (Bandan 6/10)


Bandan Das (1):
  NUMA: Support multiple CPU ranges on -numa option

Wanlong Gao (9):
  NUMA: Add numa_info structure to contain numa nodes info
  NUMA: Add Linux libnuma detection
  NUMA: parse guest numa nodes memory policy
  NUMA: handle Error in cpus, mpol and hostnode parser
  NUMA: split out the common range parser
  NUMA: set guest numa nodes memory policy
  NUMA: add qmp command set-mpol to set memory policy for NUMA node
  NUMA: add hmp command set-mpol
  NUMA: show host memory policy info in info numa command

 configure   |  32 ++
 cpus.c  | 143 +++-
 hmp-commands.hx |  16 +++
 hmp.c   |  35 ++
 hmp.h   |   1 +
 hw/i386/pc.c|   4 +-
 hw/net/eepro100.c   |   1 -
 include/sysemu/sysemu.h |  20 +++-
 monitor.c   |  44 +++-
 qapi-schema.json|  15 +++
 qemu-options.hx |   3 +-
 qmp-commands.hx |  35 ++
 vl.c| 285 +++-
 13 files changed, 553 insertions(+), 81 deletions(-)

-- 
1.8.3.1.448.gfb7dfaa




[Qemu-devel] [PATCH v2 26/30] i2c/smbus_ich9: substitute -qdev casts with DEVICE()

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/i2c/smbus_ich9.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/i2c/smbus_ich9.c b/hw/i2c/smbus_ich9.c
index ca22978..f87343f 100644
--- a/hw/i2c/smbus_ich9.c
+++ b/hw/i2c/smbus_ich9.c
@@ -82,7 +82,7 @@ static int ich9_smbus_initfn(PCIDevice *d)
 pci_set_byte(d-config + ICH9_SMB_HOSTC, 0);
 /* TODO bar0, bar1: 64bit BAR support*/
 
-pm_smbus_init(d-qdev, s-smb);
+pm_smbus_init(DEVICE(d), s-smb);
 pci_register_bar(d, ICH9_SMB_SMB_BASE_BAR, PCI_BASE_ADDRESS_SPACE_IO,
  s-smb.io);
 return 0;
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH V3 09/10] NUMA: add hmp command set-mpol

2013-06-24 Thread Wanlong Gao
Add hmp command set-mpol to set host memory policy for a guest
NUMA node. Then we can also set node's memory policy using
the monitor command like:
(qemu) set-mpol 0 mem-policy=membind,mem-hostnode=0-1

Signed-off-by: Wanlong Gao gaowanl...@cn.fujitsu.com
---
 hmp-commands.hx | 16 
 hmp.c   | 35 +++
 hmp.h   |  1 +
 3 files changed, 52 insertions(+)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 915b0d1..417b69f 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1567,6 +1567,22 @@ Executes a qemu-io command on the given block device.
 ETEXI
 
 {
+.name   = set-mpol,
+.args_type  = nodeid:i,args:s?,
+.params = nodeid [args],
+.help   = set host memory policy for a guest NUMA node,
+.mhandler.cmd = hmp_set_mpol,
+},
+
+STEXI
+@item set-mpol @var{nodeid} @var{args}
+@findex set-mpol
+
+Set host memory policy for a guest NUMA node
+
+ETEXI
+
+{
 .name   = info,
 .args_type  = item:s?,
 .params = [subcommand],
diff --git a/hmp.c b/hmp.c
index 494a9aa..81bddb1 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1464,3 +1464,38 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict)
 
 hmp_handle_error(mon, err);
 }
+
+void hmp_set_mpol(Monitor *mon, const QDict *qdict)
+{
+Error *local_err = NULL;
+bool has_mpol = true;
+bool has_hostnode = true;
+const char *mpol = NULL;
+const char *hostnode = NULL;
+QemuOpts *opts;
+
+uint64_t nodeid = qdict_get_int(qdict, nodeid);
+const char *args = qdict_get_try_str(qdict, args);
+
+if (args == NULL) {
+has_mpol = false;
+has_hostnode = false;
+} else {
+opts = qemu_opts_parse(qemu_find_opts(numa), args, 1);
+if (opts == NULL) {
+error_setg(local_err, Parsing memory policy args failed);
+} else {
+mpol = qemu_opt_get(opts, mem-policy);
+if (mpol == NULL) {
+has_mpol = false;
+}
+hostnode = qemu_opt_get(opts, mem-hostnode);
+if (hostnode == NULL) {
+has_hostnode = false;
+}
+}
+}
+
+qmp_set_mpol(nodeid, has_mpol, mpol, has_hostnode, hostnode, local_err);
+hmp_handle_error(mon, local_err);
+}
diff --git a/hmp.h b/hmp.h
index 56d2e92..81f631b 100644
--- a/hmp.h
+++ b/hmp.h
@@ -86,5 +86,6 @@ void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict);
 void hmp_chardev_add(Monitor *mon, const QDict *qdict);
 void hmp_chardev_remove(Monitor *mon, const QDict *qdict);
 void hmp_qemu_io(Monitor *mon, const QDict *qdict);
+void hmp_set_mpol(Monitor *mon, const QDict *qdict);
 
 #endif
-- 
1.8.3.1.448.gfb7dfaa




[Qemu-devel] [PATCH V3 07/10] NUMA: set guest numa nodes memory policy

2013-06-24 Thread Wanlong Gao
Set the guest numa nodes memory policies using the mbind(2)
system call node by node.
After this patch, we are able to set guest nodes memory policies
through the QEMU options, this arms to solve the guest cross
nodes memory access performance issue.
And as you all know, if PCI-passthrough is used,
direct-attached-device uses DMA transfer between device and qemu process.
All pages of the guest will be pinned by get_user_pages().

KVM_ASSIGN_PCI_DEVICE ioctl
  kvm_vm_ioctl_assign_device()
=kvm_assign_device()
  = kvm_iommu_map_memslots()
= kvm_iommu_map_pages()
   = kvm_pin_pages()

So, with direct-attached-device, all guest page's page count will be +1 and
any page migration will not work. AutoNUMA won't too.

So, we should set the guest nodes memory allocation policies before
the pages are really mapped.

Signed-off-by: Andre Przywara andre.przyw...@amd.com
Signed-off-by: Wanlong Gao gaowanl...@cn.fujitsu.com
---
 cpus.c | 87 ++
 1 file changed, 87 insertions(+)

diff --git a/cpus.c b/cpus.c
index e123d3f..677ee15 100644
--- a/cpus.c
+++ b/cpus.c
@@ -60,6 +60,15 @@
 
 #endif /* CONFIG_LINUX */
 
+#ifdef CONFIG_NUMA
+#include numa.h
+#include numaif.h
+#ifndef MPOL_F_RELATIVE_NODES
+#define MPOL_F_RELATIVE_NODES (1  14)
+#define MPOL_F_STATIC_NODES   (1  15)
+#endif
+#endif
+
 static CPUArchState *next_cpu;
 
 static bool cpu_thread_is_idle(CPUArchState *env)
@@ -1186,6 +1195,75 @@ static void tcg_exec_all(void)
 exit_request = 0;
 }
 
+#ifdef CONFIG_NUMA
+static int node_parse_bind_mode(unsigned int nodeid)
+{
+int bind_mode;
+
+switch (numa_info[nodeid].flags  NODE_HOST_POLICY_MASK) {
+case NODE_HOST_BIND:
+bind_mode = MPOL_BIND;
+break;
+case NODE_HOST_INTERLEAVE:
+bind_mode = MPOL_INTERLEAVE;
+break;
+case NODE_HOST_PREFERRED:
+bind_mode = MPOL_PREFERRED;
+break;
+default:
+bind_mode = MPOL_DEFAULT;
+return bind_mode;
+}
+
+bind_mode |= (numa_info[nodeid].flags  NODE_HOST_RELATIVE) ?
+MPOL_F_RELATIVE_NODES : MPOL_F_STATIC_NODES;
+
+return bind_mode;
+}
+#endif
+
+static int set_node_mpol(unsigned int nodeid)
+{
+#ifdef CONFIG_NUMA
+void *ram_ptr;
+RAMBlock *block;
+ram_addr_t len, ram_offset = 0;
+int bind_mode;
+int i;
+
+QTAILQ_FOREACH(block, ram_list.blocks, next) {
+if (!strcmp(block-mr-name, pc.ram)) {
+break;
+}
+}
+
+if (block-host == NULL)
+return -1;
+
+ram_ptr = block-host;
+for (i = 0; i  nodeid; i++) {
+len = numa_info[i].node_mem;
+ram_offset += len;
+}
+
+len = numa_info[i].node_mem;
+bind_mode = node_parse_bind_mode(i);
+
+/* This is a workaround for a long standing bug in Linux'
+ * mbind implementation, which cuts off the last specified
+ * node. To stay compatible should this bug be fixed, we
+ * specify one more node and zero this one out.
+ */
+clear_bit(numa_num_configured_nodes() + 1, numa_info[i].host_mem);
+if (mbind(ram_ptr + ram_offset, len, bind_mode,
+numa_info[i].host_mem, numa_num_configured_nodes() + 1, 0)) {
+perror(mbind);
+return -1;
+}
+#endif
+return 0;
+}
+
 void set_numa_modes(void)
 {
 CPUArchState *env;
@@ -1200,6 +1278,15 @@ void set_numa_modes(void)
 }
 }
 }
+
+#ifdef CONFIG_NUMA
+for (i = 0; i  nb_numa_nodes; i++) {
+if (set_node_mpol(i) == -1) {
+fprintf(stderr,
+qemu: can't set host memory policy for node%d\n, i);
+}
+}
+#endif
 }
 
 void list_cpus(FILE *f, fprintf_function cpu_fprintf, const char *optarg)
-- 
1.8.3.1.448.gfb7dfaa




[Qemu-devel] [PATCH v2 30/30] i386/*: substitute -qdev casts with DEVICE()

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/i386/kvm/pci-assign.c | 21 -
 hw/i386/pc.c |  3 ++-
 hw/i386/pc_piix.c|  4 ++--
 hw/i386/pc_q35.c |  4 ++--
 4 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index ff85590..d9c2436 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -491,7 +491,7 @@ static int assigned_dev_register_regions(PCIRegion 
*io_regions,
name, cur_region-size,
virtbase);
 vmstate_register_ram(pci_dev-v_addrs[i].real_iomem,
- pci_dev-dev.qdev);
+ DEVICE(pci_dev-dev));
 }
 
 assigned_dev_iomem_setup(pci_dev-dev, i, cur_region-size);
@@ -817,6 +817,7 @@ fail:
 
 static int assign_device(AssignedDevice *dev)
 {
+DeviceState *d = DEVICE(dev-dev);
 uint32_t flags = KVM_DEV_ASSIGN_ENABLE_IOMMU;
 int r;
 
@@ -830,7 +831,7 @@ static int assign_device(AssignedDevice *dev)
 
 if (!kvm_check_extension(kvm_state, KVM_CAP_IOMMU)) {
 error_report(No IOMMU found.  Unable to assign device \%s\,
- dev-dev.qdev.id);
+ d-id);
 return -ENODEV;
 }
 
@@ -842,7 +843,7 @@ static int assign_device(AssignedDevice *dev)
 r = kvm_device_pci_assign(kvm_state, dev-host, flags, dev-dev_id);
 if (r  0) {
 error_report(Failed to assign device \%s\ : %s,
- dev-dev.qdev.id, strerror(-r));
+ d-id, strerror(-r));
 
 switch (r) {
 case -EBUSY:
@@ -867,6 +868,7 @@ static bool check_irqchip_in_kernel(void)
 
 static int assign_intx(AssignedDevice *dev)
 {
+DeviceState *d = DEVICE(dev-dev);
 AssignedIRQType new_type;
 PCIINTxRoute intx_route;
 bool intx_host_msi;
@@ -942,7 +944,7 @@ retry:
 goto retry;
 }
 error_report(Failed to assign irq for \%s\: %s,
- dev-dev.qdev.id, strerror(-r));
+ d-id, strerror(-r));
 error_report(Perhaps you are assigning a device 
  that shares an IRQ with another device?);
 return r;
@@ -972,7 +974,7 @@ static void assigned_dev_update_irq_routing(PCIDevice *dev)
 
 r = assign_intx(assigned_dev);
 if (r  0) {
-qdev_unplug(dev-qdev, err);
+qdev_unplug(DEVICE(dev), err);
 assert(!err);
 }
 }
@@ -1675,7 +1677,7 @@ static const VMStateDescription vmstate_assigned_device = 
{
 
 static void reset_assigned_device(DeviceState *dev)
 {
-PCIDevice *pci_dev = DO_UPCAST(PCIDevice, qdev, dev);
+PCIDevice *pci_dev = PCI_DEVICE(dev);
 AssignedDevice *adev = DO_UPCAST(AssignedDevice, dev, pci_dev);
 char reset_file[64];
 const char reset[] = 1;
@@ -1731,6 +1733,7 @@ static void reset_assigned_device(DeviceState *dev)
 
 static int assigned_initfn(struct PCIDevice *pci_dev)
 {
+DeviceState *d = DEVICE(pci_dev);
 AssignedDevice *dev = DO_UPCAST(AssignedDevice, dev, pci_dev);
 uint8_t e_intx;
 int r;
@@ -1769,7 +1772,7 @@ static int assigned_initfn(struct PCIDevice *pci_dev)
 if (get_real_device(dev, dev-host.domain, dev-host.bus,
 dev-host.slot, dev-host.function)) {
 error_report(pci-assign: Error: Couldn't get real device (%s)!,
- dev-dev.qdev.id);
+ d-id);
 goto out;
 }
 
@@ -1811,7 +1814,7 @@ static int assigned_initfn(struct PCIDevice *pci_dev)
 
 assigned_dev_load_option_rom(dev);
 
-add_boot_device_path(dev-bootindex, pci_dev-qdev, NULL);
+add_boot_device_path(dev-bootindex, d, NULL);
 
 return 0;
 
@@ -1916,7 +1919,7 @@ static void assigned_dev_load_option_rom(AssignedDevice 
*dev)
 snprintf(name, sizeof(name), %s.rom,
 object_get_typename(OBJECT(dev)));
 memory_region_init_ram(dev-dev.rom, name, st.st_size);
-vmstate_register_ram(dev-dev.rom, dev-dev.qdev);
+vmstate_register_ram(dev-dev.rom, DEVICE(dev-dev));
 ptr = memory_region_get_ram_ptr(dev-dev.rom);
 memset(ptr, 0xff, st.st_size);
 
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 5e8f143..c0948d5 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1096,10 +1096,11 @@ DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus 
*pci_bus)
 
 if (pci_bus) {
 PCIDevice *pcidev = pci_vga_init(pci_bus);
-dev = pcidev ? pcidev-qdev : NULL;
+dev = DEVICE(pcidev);
 } else if (isa_bus) {
 ISADevice *isadev = isa_vga_init(isa_bus);
 dev = isadev ? DEVICE(isadev) : NULL;
+dev = DEVICE(isadev);
 }
 return dev;
 }
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 97362f2..b10e3d7 100644
--- a/hw/i386/pc_piix.c
+++ 

[Qemu-devel] [PATCH V3 01/10] NUMA: Support multiple CPU ranges on -numa option

2013-06-24 Thread Wanlong Gao
From: Bandan Das b...@redhat.com

This allows us to use the cpus property multiple times
to specify multiple cpu (ranges) to the -numa option :

-numa node,cpus=1,cpus=2,cpus=4
or
-numa node,cpus=1-3,cpus=5

Note that after this patch, the defalut suffix of -numa node,mem=N
will no longer be M. So we must add the suffix M like -numa node,mem=NM
when assigning N MB of node memory size.

Signed-off-by: Bandan Das b...@redhat.com
Signed-off-by: Wanlong Gao gaowanl...@cn.fujitsu.com
---
 qemu-options.hx |   3 +-
 vl.c| 108 ++--
 2 files changed, 67 insertions(+), 44 deletions(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index 8355f9b..767e601 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -100,7 +100,8 @@ STEXI
 @item -numa @var{opts}
 @findex -numa
 Simulate a multi node NUMA system. If mem and cpus are omitted, resources
-are split equally.
+are split equally. The -cpus property may be specified multiple times
+to denote multiple cpus or cpu ranges.
 ETEXI
 
 DEF(add-fd, HAS_ARG, QEMU_OPTION_add_fd,
diff --git a/vl.c b/vl.c
index 767e020..a1e5ce9 100644
--- a/vl.c
+++ b/vl.c
@@ -516,6 +516,32 @@ static QemuOptsList qemu_realtime_opts = {
 },
 };
 
+static QemuOptsList qemu_numa_opts = {
+.name = numa,
+.implied_opt_name = type,
+.head = QTAILQ_HEAD_INITIALIZER(qemu_numa_opts.head),
+.desc = {
+{
+.name = type,
+.type = QEMU_OPT_STRING,
+.help = node type
+},{
+.name = nodeid,
+.type = QEMU_OPT_NUMBER,
+.help = node ID
+},{
+.name = mem,
+.type = QEMU_OPT_SIZE,
+.help = memory size
+},{
+.name = cpus,
+.type = QEMU_OPT_STRING,
+.help = cpu number or range
+},
+{ /* end of list */ }
+},
+};
+
 const char *qemu_get_vm_name(void)
 {
 return qemu_name;
@@ -1349,56 +1375,37 @@ error:
 exit(1);
 }
 
-static void numa_add(const char *optarg)
+
+static int numa_add_cpus(const char *name, const char *value, void *opaque)
 {
-char option[128];
-char *endptr;
-unsigned long long nodenr;
+int *nodenr = opaque;
 
-optarg = get_opt_name(option, 128, optarg, ',');
-if (*optarg == ',') {
-optarg++;
+if (!strcmp(name, cpu)) {
+numa_node_parse_cpus(*nodenr, value);
 }
-if (!strcmp(option, node)) {
-
-if (nb_numa_nodes = MAX_NODES) {
-fprintf(stderr, qemu: too many NUMA nodes\n);
-exit(1);
-}
+return 0;
+}
 
-if (get_param_value(option, 128, nodeid, optarg) == 0) {
-nodenr = nb_numa_nodes;
-} else {
-if (parse_uint_full(option, nodenr, 10)  0) {
-fprintf(stderr, qemu: Invalid NUMA nodeid: %s\n, option);
-exit(1);
-}
-}
+static int numa_init_func(QemuOpts *opts, void *opaque)
+{
+uint64_t nodenr, mem_size;
 
-if (nodenr = MAX_NODES) {
-fprintf(stderr, qemu: invalid NUMA nodeid: %llu\n, nodenr);
-exit(1);
-}
+nodenr = qemu_opt_get_number(opts, nodeid, nb_numa_nodes++);
 
-if (get_param_value(option, 128, mem, optarg) == 0) {
-node_mem[nodenr] = 0;
-} else {
-int64_t sval;
-sval = strtosz(option, endptr);
-if (sval  0 || *endptr) {
-fprintf(stderr, qemu: invalid numa mem size: %s\n, optarg);
-exit(1);
-}
-node_mem[nodenr] = sval;
-}
-if (get_param_value(option, 128, cpus, optarg) != 0) {
-numa_node_parse_cpus(nodenr, option);
-}
-nb_numa_nodes++;
-} else {
-fprintf(stderr, Invalid -numa option: %s\n, option);
+if (nodenr = MAX_NODES) {
+fprintf(stderr, qemu: Max number of NUMA nodes reached : %d\n,
+(int)nodenr);
 exit(1);
 }
+
+mem_size = qemu_opt_get_size(opts, mem, 0);
+node_mem[nodenr] = mem_size;
+
+if (qemu_opt_foreach(opts, numa_add_cpus, nodenr, 1)  0) {
+return -1;
+}
+
+return 0;
 }
 
 static void smp_parse(const char *optarg)
@@ -2901,6 +2908,7 @@ int main(int argc, char **argv, char **envp)
 qemu_add_opts(qemu_object_opts);
 qemu_add_opts(qemu_tpmdev_opts);
 qemu_add_opts(qemu_realtime_opts);
+qemu_add_opts(qemu_numa_opts);
 
 runstate_init();
 
@@ -3087,7 +3095,16 @@ int main(int argc, char **argv, char **envp)
 }
 break;
 case QEMU_OPTION_numa:
-numa_add(optarg);
+olist = qemu_find_opts(numa);
+opts = qemu_opts_parse(olist, optarg, 1);
+if (!opts) {
+exit(1);
+}
+optarg = qemu_opt_get(opts, type);
+if (!optarg || strcmp(optarg, node)) {
+

Re: [Qemu-devel] [Qemu-trivial] [PATCH v2 00/13] A bunch of little socket + chardev fixes

2013-06-24 Thread Michael Tokarev
24.06.2013 10:39, Gerd Hoffmann wrote:
   Hi,
 
 Here is v2 of the series, addressing Michaels review comments.

Thank you Gerd, applied all series to the trivial-patches queue,
with two edits:

   qemu-char: use ChardevBackendKind in in CharDriver
   qemu-char: report udb backend errors

fxed these :)

/mjt



[Qemu-devel] [PATCH v2 27/30] ide/cmd646: substitute -qdev casts with DEVICE()

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/ide/cmd646.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/ide/cmd646.c b/hw/ide/cmd646.c
index a73eb9a..9544c1f 100644
--- a/hw/ide/cmd646.c
+++ b/hw/ide/cmd646.c
@@ -281,7 +281,7 @@ static int pci_cmd646_ide_initfn(PCIDevice *dev)
 
 irq = qemu_allocate_irqs(cmd646_set_irq, d, 2);
 for (i = 0; i  2; i++) {
-ide_bus_new(d-bus[i], d-dev.qdev, i, 2);
+ide_bus_new(d-bus[i], DEVICE(d), i, 2);
 ide_init2(d-bus[i], irq[i]);
 
 bmdma_init(d-bus[i], d-bmdma[i], d);
@@ -290,7 +290,7 @@ static int pci_cmd646_ide_initfn(PCIDevice *dev)
  d-bmdma[i].dma);
 }
 
-vmstate_register(dev-qdev, 0, vmstate_ide_pci, d);
+vmstate_register(DEVICE(dev), 0, vmstate_ide_pci, d);
 qemu_register_reset(cmd646_reset, d);
 return 0;
 }
@@ -317,8 +317,8 @@ void pci_cmd646_ide_init(PCIBus *bus, DriveInfo **hd_table,
 PCIDevice *dev;
 
 dev = pci_create(bus, -1, cmd646-ide);
-qdev_prop_set_uint32(dev-qdev, secondary, secondary_ide_enabled);
-qdev_init_nofail(dev-qdev);
+qdev_prop_set_uint32(DEVICE(dev), secondary, secondary_ide_enabled);
+qdev_init_nofail(DEVICE(dev));
 
 pci_ide_create_devs(dev, hd_table);
 }
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [PATCH V3 06/10] NUMA: split out the common range parser

2013-06-24 Thread Wanlong Gao
Since cpus parser and hostnode parser have the common range parser
part, split it out to the common range parser to avoid the duplicate
code.

Signed-off-by: Wanlong Gao gaowanl...@cn.fujitsu.com
---
 vl.c | 89 
 1 file changed, 37 insertions(+), 52 deletions(-)

diff --git a/vl.c b/vl.c
index 79c39b9..c9d25bd 100644
--- a/vl.c
+++ b/vl.c
@@ -1338,47 +1338,55 @@ char *get_boot_devices_list(size_t *size)
 return list;
 }
 
-static void numa_node_parse_cpus(int nodenr, const char *cpus, Error **errp)
+static int numa_node_parse_common(const char *str,
+  unsigned long long *value,
+  unsigned long long *endvalue)
 {
 char *endptr;
-unsigned long long value, endvalue;
-
-/* Empty CPU range strings will be considered valid, they will simply
- * not set any bit in the CPU bitmap.
- */
-if (!*cpus) {
-return;
+if (parse_uint(str, value, endptr, 10)  0) {
+return -1;
 }
 
-if (parse_uint(cpus, value, endptr, 10)  0) {
-goto error;
-}
 if (*endptr == '-') {
-if (parse_uint_full(endptr + 1, endvalue, 10)  0) {
-goto error;
+if (parse_uint_full(endptr + 1, endvalue, 10)  0) {
+   return -1;
 }
 } else if (*endptr == '\0') {
-endvalue = value;
+*endvalue = *value;
 } else {
-goto error;
+return -1;
 }
 
-if (endvalue = MAX_CPUMASK_BITS) {
-endvalue = MAX_CPUMASK_BITS - 1;
-fprintf(stderr,
-qemu: NUMA: A max of %d VCPUs are supported\n,
- MAX_CPUMASK_BITS);
+if (*endvalue = MAX_CPUMASK_BITS) {
+*endvalue = MAX_CPUMASK_BITS - 1;
+fprintf(stderr, qemu: NUMA: A max number %d is supported\n,
+MAX_CPUMASK_BITS);
 }
 
-if (endvalue  value) {
-goto error;
+if (*endvalue  *value) {
+return -1;
 }
 
-bitmap_set(numa_info[nodenr].node_cpu, value, endvalue-value+1);
-return;
+return 0;
+}
 
-error:
-error_setg(errp, Invalid NUMA CPU range: %s\n, cpus);
+static void numa_node_parse_cpus(int nodenr, const char *cpus, Error **errp)
+{
+unsigned long long value, endvalue;
+
+/* Empty CPU range strings will be considered valid, they will simply
+ * not set any bit in the CPU bitmap.
+ */
+if (!*cpus) {
+return;
+}
+
+if (numa_node_parse_common(cpus, value, endvalue)  0) {
+error_setg(errp, Invalid NUMA CPU range: %s, cpus);
+return;
+}
+
+bitmap_set(numa_info[nodenr].node_cpu, value, endvalue-value+1);
 return;
 }
 
@@ -1403,7 +1411,6 @@ void numa_node_parse_mpol(int nodenr, const char *mpol, 
Error **errp)
 void numa_node_parse_hostnode(int nodenr, const char *hostnode, Error **errp)
 {
 unsigned long long value, endvalue;
-char *endptr;
 bool clear = false;
 unsigned long *bm = numa_info[nodenr].host_mem;
 
@@ -1422,27 +1429,9 @@ void numa_node_parse_hostnode(int nodenr, const char 
*hostnode, Error **errp)
 return;
 }
 
-if (parse_uint(hostnode, value, endptr, 10)  0)
-goto error;
-if (*endptr == '-') {
-if (parse_uint_full(endptr + 1, endvalue, 10)  0) {
-goto error;
-}
-} else if (*endptr == '\0') {
-endvalue = value;
-} else {
-goto error;
-}
-
-if (endvalue = MAX_CPUMASK_BITS) {
-endvalue = MAX_CPUMASK_BITS - 1;
-fprintf(stderr,
-qemu: NUMA: A max of %d host nodes are supported\n,
- MAX_CPUMASK_BITS);
-}
-
-if (endvalue  value) {
-goto error;
+if (numa_node_parse_common(hostnode, value, endvalue)  0) {
+error_setg(errp, Invalid host NUMA ndoes range: %s, hostnode);
+return;
 }
 
 if (clear)
@@ -1451,10 +1440,6 @@ void numa_node_parse_hostnode(int nodenr, const char 
*hostnode, Error **errp)
 bitmap_set(bm, value, endvalue - value + 1);
 
 return;
-
-error:
-error_setg(errp, Invalid host NUMA nodes range: %s, hostnode);
-return;
 }
 
 static int numa_add_cpus(const char *name, const char *value, void *opaque)
-- 
1.8.3.1.448.gfb7dfaa




[Qemu-devel] [PATCH V3 04/10] NUMA: parse guest numa nodes memory policy

2013-06-24 Thread Wanlong Gao
The memory policy setting format is like:
mem-policy={membind|interleave|preferred},mem-hostnode=[+|!]{all|N-N}
And we are adding this setting as a suboption of -numa,
the memory policy then can be set like following:
 -numa node,nodeid=0,mem=1024,cpus=0,mem-policy=membind,mem-hostnode=0-1
 -numa node,nodeid=1,mem=1024,cpus=1,mem-policy=interleave,mem-hostnode=!1

Signed-off-by: Andre Przywara andre.przyw...@amd.com
Signed-off-by: Wanlong Gao gaowanl...@cn.fujitsu.com
---
 include/sysemu/sysemu.h |   8 
 vl.c| 110 
 2 files changed, 118 insertions(+)

diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 70fd2ed..993b8e0 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -130,10 +130,18 @@ extern QEMUClock *rtc_clock;
 
 #define MAX_NODES 64
 #define MAX_CPUMASK_BITS 255
+#define NODE_HOST_NONE0x00
+#define NODE_HOST_BIND0x01
+#define NODE_HOST_INTERLEAVE  0x02
+#define NODE_HOST_PREFERRED   0x03
+#define NODE_HOST_POLICY_MASK 0x03
+#define NODE_HOST_RELATIVE0x04
 extern int nb_numa_nodes;
 struct node_info {
 uint64_t node_mem;
 DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS);
+DECLARE_BITMAP(host_mem, MAX_CPUMASK_BITS);
+unsigned int flags;
 };
 extern struct node_info numa_info[MAX_NODES];
 
diff --git a/vl.c b/vl.c
index 357137b..4dbf5cc 100644
--- a/vl.c
+++ b/vl.c
@@ -536,6 +536,14 @@ static QemuOptsList qemu_numa_opts = {
 .name = cpus,
 .type = QEMU_OPT_STRING,
 .help = cpu number or range
+},{
+.name = mem-policy,
+.type = QEMU_OPT_STRING,
+.help = memory policy
+},{
+.name = mem-hostnode,
+.type = QEMU_OPT_STRING,
+.help = host node number or range for memory policy
 },
 { /* end of list */ }
 },
@@ -1374,6 +1382,79 @@ error:
 exit(1);
 }
 
+static void numa_node_parse_mpol(int nodenr, const char *mpol)
+{
+if (!mpol) {
+return;
+}
+
+if (!strcmp(mpol, interleave)) {
+numa_info[nodenr].flags |= NODE_HOST_INTERLEAVE;
+} else if (!strcmp(mpol, preferred)) {
+numa_info[nodenr].flags |= NODE_HOST_PREFERRED;
+} else if (!strcmp(mpol, membind)) {
+numa_info[nodenr].flags |= NODE_HOST_BIND;
+} else {
+fprintf(stderr, qemu: Invalid memory policy: %s\n, mpol);
+}
+}
+
+static void numa_node_parse_hostnode(int nodenr, const char *hostnode)
+{
+unsigned long long value, endvalue;
+char *endptr;
+bool clear = false;
+unsigned long *bm = numa_info[nodenr].host_mem;
+
+if (hostnode[0] == '!') {
+clear = true;
+bitmap_fill(bm, MAX_CPUMASK_BITS);
+hostnode++;
+}
+if (hostnode[0] == '+') {
+numa_info[nodenr].flags |= NODE_HOST_RELATIVE;
+hostnode++;
+}
+
+if (!strcmp(hostnode, all)) {
+bitmap_fill(bm, MAX_CPUMASK_BITS);
+return;
+}
+
+if (parse_uint(hostnode, value, endptr, 10)  0)
+goto error;
+if (*endptr == '-') {
+if (parse_uint_full(endptr + 1, endvalue, 10)  0) {
+goto error;
+}
+} else if (*endptr == '\0') {
+endvalue = value;
+} else {
+goto error;
+}
+
+if (endvalue = MAX_CPUMASK_BITS) {
+endvalue = MAX_CPUMASK_BITS - 1;
+fprintf(stderr,
+qemu: NUMA: A max of %d host nodes are supported\n,
+ MAX_CPUMASK_BITS);
+}
+
+if (endvalue  value) {
+goto error;
+}
+
+if (clear)
+bitmap_clear(bm, value, endvalue - value + 1);
+else
+bitmap_set(bm, value, endvalue - value + 1);
+
+return;
+
+error:
+fprintf(stderr, qemu: Invalid host NUMA nodes range: %s\n, hostnode);
+return;
+}
 
 static int numa_add_cpus(const char *name, const char *value, void *opaque)
 {
@@ -1385,6 +1466,25 @@ static int numa_add_cpus(const char *name, const char 
*value, void *opaque)
 return 0;
 }
 
+static int numa_add_mpol(const char *name, const char *value, void *opaque)
+{
+int *nodenr = opaque;
+
+if (!strcmp(name, mem-policy)) {
+numa_node_parse_mpol(*nodenr, value);
+}
+return 0;
+}
+
+static int numa_add_hostnode(const char *name, const char *value, void *opaque)
+{
+int *nodenr = opaque;
+if (!strcmp(name, mem-hostnode)) {
+numa_node_parse_hostnode(*nodenr, value);
+}
+return 0;
+}
+
 static int numa_init_func(QemuOpts *opts, void *opaque)
 {
 uint64_t nodenr, mem_size;
@@ -1404,6 +1504,14 @@ static int numa_init_func(QemuOpts *opts, void *opaque)
 return -1;
 }
 
+if (qemu_opt_foreach(opts, numa_add_mpol, nodenr, 1)  0) {
+return -1;
+}
+
+if (qemu_opt_foreach(opts, numa_add_hostnode, nodenr, 1)  0) {
+return -1;
+}
+
 return 0;
 }
 
@@ -2930,6 +3038,8 @@ int main(int argc, char **argv, char **envp)
 for (i = 0; i  

[Qemu-devel] [PATCH v2 29/30] pci-host/*: substitute -qdev casts with DEVICE()

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/pci-bridge/dec.c | 2 +-
 hw/pci-host/apb.c   | 4 ++--
 hw/pci-host/q35.c   | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/hw/pci-bridge/dec.c b/hw/pci-bridge/dec.c
index cff458b..1e5611d 100644
--- a/hw/pci-bridge/dec.c
+++ b/hw/pci-bridge/dec.c
@@ -88,7 +88,7 @@ PCIBus *pci_dec_21154_init(PCIBus *parent_bus, int devfn)
dec-21154-p2p-bridge);
 br = DO_UPCAST(PCIBridge, dev, dev);
 pci_bridge_map_irq(br, DEC 21154 PCI-PCI bridge, dec_map_irq);
-qdev_init_nofail(dev-qdev);
+qdev_init_nofail(DEVICE(dev));
 return pci_bridge_get_sec_bus(br);
 }
 
diff --git a/hw/pci-host/apb.c b/hw/pci-host/apb.c
index e099655..f3987ff 100644
--- a/hw/pci-host/apb.c
+++ b/hw/pci-host/apb.c
@@ -467,7 +467,7 @@ PCIBus *pci_apb_init(hwaddr special_base,
 br = DO_UPCAST(PCIBridge, dev, pci_dev);
 pci_bridge_map_irq(br, Advanced PCI Bus secondary bridge 1,
pci_apb_map_irq);
-qdev_init_nofail(pci_dev-qdev);
+qdev_init_nofail(DEVICE(dev));
 *bus2 = pci_bridge_get_sec_bus(br);
 
 pci_dev = pci_create_multifunction(d-bus, PCI_DEVFN(1, 1), true,
@@ -475,7 +475,7 @@ PCIBus *pci_apb_init(hwaddr special_base,
 br = DO_UPCAST(PCIBridge, dev, pci_dev);
 pci_bridge_map_irq(br, Advanced PCI Bus secondary bridge 2,
pci_apb_map_irq);
-qdev_init_nofail(pci_dev-qdev);
+qdev_init_nofail(DEVICE(pci_dev));
 *bus3 = pci_bridge_get_sec_bus(br);
 
 return d-bus;
diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c
index 24df6b5..d04471c 100644
--- a/hw/pci-host/q35.c
+++ b/hw/pci-host/q35.c
@@ -104,8 +104,8 @@ static const TypeInfo q35_host_info = {
 /* PCIe MMCFG */
 static void mch_update_pciexbar(MCHPCIState *mch)
 {
-PCIDevice *pci_dev = mch-d;
-BusState *bus = qdev_get_parent_bus(pci_dev-qdev);
+PCIDevice *pci_dev = PCI_DEVICE(mch);
+BusState *bus = qdev_get_parent_bus(DEVICE(pci_dev));
 DeviceState *qdev = bus-parent;
 Q35PCIHost *s = Q35_HOST_DEVICE(qdev);
 
-- 
1.8.3.rc1.44.gb387c77.dirty




[Qemu-devel] [target-mips] How to use smp?

2013-06-24 Thread Dongxue Zhang
Hello everybody, i want to use mips target with smp support.  When use
command without smp, then the log stopped at kernel panic, when -smp 2
added, it stoppted at NR_IRQS:256.

I use the git qemu at 576156ffed72ab4feb0b752979db86ff8759a2a1
qemu configed with ./configure --target-list=mips64el-softmmu
qemu run command qemu-system-mips64el -kernel linux-3.8.2/vmlinux
-nographic -smp 2

The linux kernel used release version.


qemu-system-mips64el -kernel linux-3.8.2/vmlinux -nographic -smp 2
QEMU 1.5.50 monitor - type 'help' for more information
(qemu)
Linux version 3.8.2 (elta@elta) (gcc version 4.7.2 (GCC) ) #1 SMP Mon Jun
24 15:35:20 CST 2013
Config serial console: console=ttyS0,38400n8r
bootconsole [early0] enabled
CPU revision is: 000182a0 (MIPS 20Kc)
FPU revision is: 000f8200
Checking for the multiply/shift bug... no.
Checking for the daddiu bug... no.
Determined physical RAM map:
 memory: 1000 @  (reserved)
 memory: 000ef000 @ 1000 (ROM data)
 memory: 00be1000 @ 000f (reserved)
 memory: 0732f000 @ 00cd1000 (usable)
Wasting 183736 bytes for tracking 3281 unused pages
Zone ranges:
  DMA  [mem 0x-0x00ff]
  Normal   [mem 0x0100-0x07ff]
Movable zone start for each node
Early memory node ranges
  node   0: [mem 0x-0x07ff]
Primary instruction cache 32kB, VIVT, 4-way, linesize 32 bytes.
Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
PERCPU: Embedded 10 pages/cpu @9800011c3000 s10816 r8192 d21952 u40960
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 32320
Kernel command line:  console=ttyS0,38400n8r
PID hash table entries: 512 (order: 0, 4096 bytes)
Dentry cache hash table entries: 16384 (order: 5, 131072 bytes)
Inode-cache hash table entries: 8192 (order: 4, 65536 bytes)
__ex_table already sorted, skipping sort
Enable cache parity protection for MIPS 20KC/25KF CPUs.
Memory: 115900k/117948k available (8466k kernel code, 2048k reserved, 3014k
data, 356k init, 0k highmem)
Hierarchical RCU implementation.
CONFIG_RCU_FANOUT set to non-default value of 32
RCU restricting CPUs from NR_CPUS=2 to nr_cpu_ids=1.
NR_IRQS:256


Is there anyone have ideas to solve this problem?


[Qemu-devel] [PATCH 1/2] qxl: fix Coverity scan SIGN_EXTENSION error

2013-06-24 Thread Gerd Hoffmann
Cc: Markus Armbruster arm...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/display/qxl-render.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/display/qxl-render.c b/hw/display/qxl-render.c
index f511a62..269b1a7 100644
--- a/hw/display/qxl-render.c
+++ b/hw/display/qxl-render.c
@@ -199,7 +199,7 @@ static QEMUCursor *qxl_cursor(PCIQXLDevice *qxl, QXLCursor 
*cursor)
 c-hot_y = cursor-header.hot_spot_y;
 switch (cursor-header.type) {
 case SPICE_CURSOR_TYPE_ALPHA:
-size = cursor-header.width * cursor-header.height * sizeof(uint32_t);
+size = sizeof(uint32_t) * cursor-header.width * cursor-header.height;
 memcpy(c-data, cursor-chunk.data, size);
 if (qxl-debug  2) {
 cursor_print_ascii_art(c, qxl/alpha);
-- 
1.7.9.7




[Qemu-devel] [PULL 0/2] spice patch queue

2013-06-24 Thread Gerd Hoffmann
  Hi,

Tiny spice patch queue with only two patches, one adding a spice cmd
line option and one bugfix.

please pull,
  Gerd

The following changes since commit 576156ffed72ab4feb0b752979db86ff8759a2a1:

  Merge remote-tracking branch 'bonzini/iommu-for-anthony' into staging 
(2013-06-20 16:53:39 -0500)

are available in the git repository at:


  git://anongit.freedesktop.org/spice/qemu spice.v71

for you to fetch changes up to 5ad24e5f3b5968240d50fb2e5b6e19517b041052:

  spice: Add -spice disable-agent-file-transfer cmdline option (rhbz#961850) 
(2013-06-24 08:23:09 +0200)


Gerd Hoffmann (1):
  qxl: fix Coverity scan SIGN_EXTENSION error

Hans de Goede (1):
  spice: Add -spice disable-agent-file-transfer cmdline option (rhbz#961850)

 hw/display/qxl-render.c |2 +-
 qemu-options.hx |7 +--
 ui/spice-core.c |   13 +
 3 files changed, 19 insertions(+), 3 deletions(-)



[Qemu-devel] [PATCH 2/2] spice: Add -spice disable-agent-file-transfer cmdline option (rhbz#961850)

2013-06-24 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

Signed-off-by: Hans de Goede hdego...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 qemu-options.hx |7 +--
 ui/spice-core.c |   13 +
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index 8355f9b..c1533a3 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -917,8 +917,8 @@ DEF(spice, HAS_ARG, QEMU_OPTION_spice,
[,jpeg-wan-compression=[auto|never|always]]\n
[,zlib-glz-wan-compression=[auto|never|always]]\n
[,streaming-video=[off|all|filter]][,disable-copy-paste]\n
-   [,agent-mouse=[on|off]][,playback-compression=[on|off]]\n
-   [,seamless-migration=[on|off]]\n
+   [,disable-agent-file-xfer][,agent-mouse=[on|off]]\n
+   [,playback-compression=[on|off]][,seamless-migration=[on|off]]\n
enable spice\n
at least one of {port, tls-port} is mandatory\n,
 QEMU_ARCH_ALL)
@@ -961,6 +961,9 @@ Allow client connects without authentication.
 @item disable-copy-paste
 Disable copy paste between the client and the guest.
 
+@item disable-agent-file-xfer
+Disable spice-vdagent based file-xfer between the client and the guest.
+
 @item tls-port=nr
 Set the TCP port spice is listening on for encrypted channels.
 
diff --git a/ui/spice-core.c b/ui/spice-core.c
index bcc4199..f308fd9 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -446,6 +446,9 @@ static QemuOptsList qemu_spice_opts = {
 .name = disable-copy-paste,
 .type = QEMU_OPT_BOOL,
 },{
+.name = disable-agent-file-xfer,
+.type = QEMU_OPT_BOOL,
+},{
 .name = sasl,
 .type = QEMU_OPT_BOOL,
 },{
@@ -739,6 +742,16 @@ void qemu_spice_init(void)
 spice_server_set_agent_copypaste(spice_server, false);
 }
 
+if (qemu_opt_get_bool(opts, disable-agent-file-xfer, 0)) {
+#if SPICE_SERVER_VERSION = 0x000c04
+spice_server_set_agent_file_xfer(spice_server, false);
+#else
+error_report(this qemu build does not support the 
+ \disable-agent-file-xfer\ option);
+exit(1);
+#endif
+}
+
 compression = SPICE_IMAGE_COMPRESS_AUTO_GLZ;
 str = qemu_opt_get(opts, image-compression);
 if (str) {
-- 
1.7.9.7




Re: [Qemu-devel] [PATCH v4] QEMUBH: make AioContext's bh re-entrant

2013-06-24 Thread Stefan Hajnoczi
On Mon, Jun 24, 2013 at 05:54:26PM +0800, Liu Ping Fan wrote:
 BH will be used outside big lock, so introduce lock to protect
 between the writers, ie, bh's adders and deleter. The lock only
 affects the writers and bh's callback does not take this extra lock.
 Note that for the same AioContext, aio_bh_poll() can not run in
 parallel yet.
 
 Signed-off-by: Liu Ping Fan pingf...@linux.vnet.ibm.com
 
 
 v3-v4
   resolve memory order of bh-idle and -scheduled
   add comments for qemu_bh_delete/cancel
 
 
 ---
  async.c | 32 ++--
  include/block/aio.h |  7 +++
  2 files changed, 37 insertions(+), 2 deletions(-)
 
 diff --git a/async.c b/async.c
 index 90fe906..108d7c3 100644
 --- a/async.c
 +++ b/async.c
 @@ -47,11 +47,16 @@ QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void 
 *opaque)
  bh-ctx = ctx;
  bh-cb = cb;
  bh-opaque = opaque;
 +qemu_mutex_lock(ctx-bh_lock);
  bh-next = ctx-first_bh;
 +/* Make sure the members ready before putting bh into list */
 +smp_wmb();

s/members/member is/



Re: [Qemu-devel] [PATCH 0/3] multiboot: Fix memory information

2013-06-24 Thread Kevin Wolf
Am 23.06.2013 um 23:39 hat Anthony Liguori geschrieben:
 Kevin Wolf m...@kevin-wolf.de writes:
 
  Kevin Wolf (3):
multiboot: Don't forget last mmap entry
multiboot: Calculate upper_mem in the ROM
multiboot: Updated ROM binary
 
 Reviewed-by: Anthony Liguori aligu...@us.ibm.com
 
 Do you have a test case that triggered this that you can share?

I haven't seen an actual kernel failure myself, this was reported by
someone else. But it's easy enough to check with a simple Multiboot
kernel that just outputs lower_mem/upper_mem and the mmap.

For debugging and fixing I added some throw-away debug code to an
existing kernel and compared the fixed version with the output when
loaded by GRUB and it matches now.

If we can have a real test case for this somewhere, I can write a small
kernel to do the check. Not sure where it would fit though - probably
kvm-unittests is the closest, even though the test wouldn't really have
anything to do with KVM.

 I'll apply this after a day or so when others have had a chance to review.

Sounds good, thanks.

Kevin



Re: [Qemu-devel] [PATCH v2 07/13] qemu-char: fix documentation for telnet+wait socket flags

2013-06-24 Thread Markus Armbruster
Gerd Hoffmann kra...@redhat.com writes:

 Signed-off-by: Gerd Hoffmann kra...@redhat.com
 ---
  qapi-schema.json |7 ---
  1 file changed, 4 insertions(+), 3 deletions(-)

 diff --git a/qapi-schema.json b/qapi-schema.json
 index a80ee40..a29ce57 100644
 --- a/qapi-schema.json
 +++ b/qapi-schema.json
 @@ -3185,10 +3185,11 @@
  # @addr: socket address to listen on (server=true)
  #or connect to (server=false)
  # @server: #optional create server socket (default: true)
 -# @wait: #optional wait for connect (not used for server
 -#sockets, default: false)
 +# @wait: #optional wait for incoming connection on server
 +#sockets (default: false).
  # @nodelay: #optional set TCP_NODELAY socket option (default: false)
 -# @telnet: #optional enable telnet protocol (default: false)
 +# @telnet: #optional enable telnet protocol on server
 +#  sockets (default: false)
  #
  # Since: 1.4
  ##

Yes, both options apply only with server=true (I double-checked).

Curiously, qemu_chr_open_socket_fd() puts telnet into chr-filename
regardless of server.

qemu_chr_open_socket() has

if (!is_listen)
is_waitconnect = 0;

Should this perhaps be

if (!is_listen) {
is_waitconnect = 0;
is_telnet = 0;
}

?



[Qemu-devel] [PATCH v2 28/30] ide/via: substitute -qdev casts with DEVICE()

2013-06-24 Thread peter . crosthwaite
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---

 hw/ide/via.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/ide/via.c b/hw/ide/via.c
index 5fe053c..b81e1fe 100644
--- a/hw/ide/via.c
+++ b/hw/ide/via.c
@@ -158,7 +158,7 @@ static void vt82c686b_init_ports(PCIIDEState *d) {
 int i;
 
 for (i = 0; i  2; i++) {
-ide_bus_new(d-bus[i], d-dev.qdev, i, 2);
+ide_bus_new(d-bus[i], DEVICE(d), i, 2);
 ide_init_ioport(d-bus[i], NULL, port_info[i].iobase,
 port_info[i].iobase2);
 ide_init2(d-bus[i], isa_get_irq(NULL, port_info[i].isairq));
@@ -183,7 +183,7 @@ static int vt82c686b_ide_initfn(PCIDevice *dev)
 bmdma_setup_bar(d);
 pci_register_bar(d-dev, 4, PCI_BASE_ADDRESS_SPACE_IO, d-bmdma_bar);
 
-vmstate_register(dev-qdev, 0, vmstate_ide_pci, d);
+vmstate_register(DEVICE(dev), 0, vmstate_ide_pci, d);
 
 vt82c686b_init_ports(d);
 
-- 
1.8.3.rc1.44.gb387c77.dirty




Re: [Qemu-devel] [PATCH 1/2] iscsi: add support for bdrv_co_is_allocated()

2013-06-24 Thread Stefan Hajnoczi
On Fri, Jun 21, 2013 at 11:18:42AM +0200, Kevin Wolf wrote:
 Am 20.06.2013 um 20:20 hat Peter Lieven geschrieben:
  @@ -800,6 +801,60 @@ iscsi_getlength(BlockDriverState *bs)
   return len;
   }
   
  +static int coroutine_fn iscsi_co_is_allocated(BlockDriverState *bs,
  +  int64_t sector_num,
  +  int nb_sectors, int *pnum)
  +{
  +IscsiLun *iscsilun = bs-opaque;
  +struct scsi_task *task = NULL;
  +struct scsi_get_lba_status *lbas = NULL;
  +struct scsi_lba_status_descriptor *lbasd = NULL;
  +int ret;
  +
  +*pnum = nb_sectors;
  +
  +if (iscsilun-lbpme == 0) {
  +return 1;
  +}
  +
  +/* in-flight requests could invalidate the lba status result */
  +while (iscsi_process_flush(iscsilun)) {
  +qemu_aio_wait();
  +}
 
 Note that you're blocking here. The preferred way would be something
 involving a yield from the coroutine and a reenter as soon as all
 requests are done. Maybe a CoRwLock does what you need?

The other option is to avoid synchronization here and instead process
bs-tracked_requests so that any in-flight writes count as allocated.

Stefan



Re: [Qemu-devel] [Qemu-trivial] [PATCH v2 00/13] A bunch of little socket + chardev fixes

2013-06-24 Thread Markus Armbruster
Michael Tokarev m...@tls.msk.ru writes:

 24.06.2013 10:39, Gerd Hoffmann wrote:
   Hi,
 
 Here is v2 of the series, addressing Michaels review comments.

 Thank you Gerd, applied all series to the trivial-patches queue,
 with two edits:

   qemu-char: use ChardevBackendKind in in CharDriver
   qemu-char: report udb backend errors

 fxed these :)

My commit message nitpicks aren't worth a respin.  Perhaps you want to
fix them in your tree.



Re: [Qemu-devel] [Qemu-trivial] [PATCH v2 00/13] A bunch of little socket + chardev fixes

2013-06-24 Thread Michael Tokarev
24.06.2013 12:14, Markus Armbruster wrote:
 Michael Tokarev m...@tls.msk.ru writes:
[]
 Thank you Gerd, applied all series to the trivial-patches queue,
 with two edits:

   qemu-char: use ChardevBackendKind in in CharDriver
   qemu-char: report udb backend errors

 fxed these :)
 
 My commit message nitpicks aren't worth a respin.  Perhaps you want to
 fix them in your tree.

I'm not sure I understand what you're saying.  I fixed them
in my tree while applying, and that's exactly what I said --
applied all..fixed these.  What does not worth what?

Thanks,

/mjt




Re: [Qemu-devel] [PATCH 2/2] PPC: Fix GDB read on code area for PPC6xx

2013-06-24 Thread Fabien Chouteau
On 06/22/2013 02:26 AM, Alexander Graf wrote:
 Thanks, applied to ppc-next. Teaching gdb a new protocol is way out of scope 
 for these rare cases :).
 

Thanks guys,

-- 
Fabien Chouteau



[Qemu-devel] [PATCH v4 11/14] ioport: Switch dispatching to memory core layer

2013-06-24 Thread Jan Kiszka
The current ioport dispatcher is a complex beast, mostly due to the
need to deal with old portio interface users. But we can overcome it
without converting all portio users by embedding the required base
address of a MemoryRegionPortio access into that data structure. That
removes the need to have the additional MemoryRegionIORange structure
in the loop on every access.

To handle old portio memory ops, we simply install dispatching handlers
for portio memory regions when registering them with the memory core.
This removes the need for the old_portio field.

We can drop the additional aliasing of ioport regions and also the
special address space listener. cpu_in and cpu_out now simply call
address_space_read/write. And we can concentrate portio handling in a
single source file.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
---

Changes in v4:
 - mark portio dispatching ops as little endian

 exec.c |   27 
 include/exec/ioport.h  |1 -
 include/exec/memory-internal.h |2 -
 include/exec/memory.h  |5 +-
 ioport.c   |  138 +---
 memory.c   |   88 -
 6 files changed, 102 insertions(+), 159 deletions(-)

diff --git a/exec.c b/exec.c
index 0b0118b..87c7ef3 100644
--- a/exec.c
+++ b/exec.c
@@ -1760,26 +1760,6 @@ static void core_log_global_stop(MemoryListener 
*listener)
 cpu_physical_memory_set_dirty_tracking(0);
 }
 
-static void io_region_add(MemoryListener *listener,
-  MemoryRegionSection *section)
-{
-MemoryRegionIORange *mrio = g_new(MemoryRegionIORange, 1);
-
-mrio-mr = section-mr;
-mrio-offset = section-offset_within_region;
-iorange_init(mrio-iorange, memory_region_iorange_ops,
- section-offset_within_address_space,
- int128_get64(section-size));
-ioport_register(mrio-iorange);
-}
-
-static void io_region_del(MemoryListener *listener,
-  MemoryRegionSection *section)
-{
-isa_unassign_ioport(section-offset_within_address_space,
-int128_get64(section-size));
-}
-
 static MemoryListener core_memory_listener = {
 .begin = core_begin,
 .log_global_start = core_log_global_start,
@@ -1787,12 +1767,6 @@ static MemoryListener core_memory_listener = {
 .priority = 1,
 };
 
-static MemoryListener io_memory_listener = {
-.region_add = io_region_add,
-.region_del = io_region_del,
-.priority = 0,
-};
-
 static MemoryListener tcg_memory_listener = {
 .commit = tcg_commit,
 };
@@ -1834,7 +1808,6 @@ static void memory_map_init(void)
 address_space_init(address_space_io, system_io, I/O);
 
 memory_listener_register(core_memory_listener, address_space_memory);
-memory_listener_register(io_memory_listener, address_space_io);
 memory_listener_register(tcg_memory_listener, address_space_memory);
 }
 
diff --git a/include/exec/ioport.h b/include/exec/ioport.h
index eb99ffe..b476857 100644
--- a/include/exec/ioport.h
+++ b/include/exec/ioport.h
@@ -56,7 +56,6 @@ typedef struct PortioList {
 struct MemoryRegion *address_space;
 unsigned nr;
 struct MemoryRegion **regions;
-struct MemoryRegion **aliases;
 void *opaque;
 const char *name;
 } PortioList;
diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h
index 26689fe..d0e0633 100644
--- a/include/exec/memory-internal.h
+++ b/include/exec/memory-internal.h
@@ -119,8 +119,6 @@ static inline void 
cpu_physical_memory_mask_dirty_range(ram_addr_t start,
 void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t end,
  int dirty_flags);
 
-extern const IORangeOps memory_region_iorange_ops;
-
 #endif
 
 #endif
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 3598c4f..7c1e6da 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -124,10 +124,6 @@ struct MemoryRegionOps {
  bool unaligned;
 } impl;
 
-/* If .read and .write are not present, old_portio may be used for
- * backwards compatibility with old portio registration
- */
-const MemoryRegionPortio *old_portio;
 /* If .read and .write are not present, old_mmio may be used for
  * backwards compatibility with old mmio registration
  */
@@ -183,6 +179,7 @@ struct MemoryRegionPortio {
 unsigned size;
 IOPortReadFunc *read;
 IOPortWriteFunc *write;
+uint32_t base; /* private field */
 };
 
 #define PORTIO_END_OF_LIST() { }
diff --git a/ioport.c b/ioport.c
index 56470c5..347da2c 100644
--- a/ioport.c
+++ b/ioport.c
@@ -28,6 +28,7 @@
 #include exec/ioport.h
 #include trace.h
 #include exec/memory.h
+#include exec/address-spaces.h
 
 /***/
 /* IO Port */
@@ -47,6 +48,12 @@
 #  define LOG_IOPORT(...) do { } while (0)
 #endif
 
+typedef struct MemoryRegionPortioList {
+

Re: [Qemu-devel] [PATCH v2 02/13] qemu-socket: drop pointless allocation

2013-06-24 Thread Markus Armbruster
Gerd Hoffmann kra...@redhat.com writes:

 Signed-off-by: Gerd Hoffmann kra...@redhat.com
 ---
  util/qemu-sockets.c |1 -
  1 file changed, 1 deletion(-)

 diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
 index 86fb09c..35023a8 100644
 --- a/util/qemu-sockets.c
 +++ b/util/qemu-sockets.c
 @@ -871,7 +871,6 @@ SocketAddress *socket_parse(const char *str, Error **errp)
  }
  } else {
  addr-kind = SOCKET_ADDRESS_KIND_INET;
 -addr-inet = g_new(InetSocketAddress, 1);
  addr-inet = inet_parse(str, errp);
  if (addr-inet == NULL) {
  goto fail;

Plugs a memory leak, which is a bit more than drop pointless
allocation.



Re: [Qemu-devel] [PATCH v2 00/13] A bunch of little socket + chardev fixes

2013-06-24 Thread Laszlo Ersek
On 06/24/13 08:39, Gerd Hoffmann wrote:
   Hi,
 
 Here is v2 of the series, addressing Michaels review comments.
 
 cheers,
   Gerd
 
 Gerd Hoffmann (13):
   qemu-socket: zero-initialize SocketAddress
   qemu-socket: drop pointless allocation
   qemu-socket: catch monitor_get_fd failures
   qemu-char: check optional fields using has_*
   qemu-char: use more specific error_setg_* variants
   qemu-char: print notification to stderr
   qemu-char: fix documentation for telnet+wait socket flags
   qemu-char: don't leak opts on error
   qemu-char: use ChardevBackendKind in in CharDriver
   qemu-char: minor mux chardev fixes
   qemu-char: add -chardev mux support
   qemu-char: report udb backend errors
   qemu-socket: don't leak opts on error
 
  include/sysemu/char.h |2 +-
  qapi-schema.json  |7 ---
  qemu-char.c   |   45 -
  util/qemu-sockets.c   |9 -
  4 files changed, 41 insertions(+), 22 deletions(-)
 

I think 11/13 doesn't qualify for qemu-trivial. In any case, it does
seem correct, like the rest.

With the commit message fixups from Michael: series

Reviewed-by: Laszlo Ersek ler...@redhat.com

Thanks
Laszlo



Re: [Qemu-devel] [Qemu-trivial] [PATCH v2 00/13] A bunch of little socket + chardev fixes

2013-06-24 Thread Markus Armbruster
Michael Tokarev m...@tls.msk.ru writes:

 24.06.2013 12:14, Markus Armbruster wrote:
 Michael Tokarev m...@tls.msk.ru writes:
 []
 Thank you Gerd, applied all series to the trivial-patches queue,
 with two edits:

   qemu-char: use ChardevBackendKind in in CharDriver
   qemu-char: report udb backend errors

 fxed these :)
 
 My commit message nitpicks aren't worth a respin.  Perhaps you want to
 fix them in your tree.

 I'm not sure I understand what you're saying.  I fixed them
 in my tree while applying, and that's exactly what I said --
 applied all..fixed these.  What does not worth what?

I replied to 02/13 and 12/13, suggesting commit message fixes.  You may
have covered some of them already, I don't know.

The question I asked re 07/13 is outside the scope of this series, so
don't worry about that one.



Re: [Qemu-devel] [PATCH v2 12/13] qemu-char: report udb backend errors

2013-06-24 Thread Markus Armbruster
Typo in subject: s/udb/UDP/

Gerd Hoffmann kra...@redhat.com writes:

 Signed-off-by: Gerd Hoffmann kra...@redhat.com
 ---
  qemu-char.c |2 ++
  1 file changed, 2 insertions(+)

 diff --git a/qemu-char.c b/qemu-char.c
 index 7d072a8..dcc91bb 100644
 --- a/qemu-char.c
 +++ b/qemu-char.c
 @@ -2255,6 +2255,8 @@ static CharDriverState *qemu_chr_open_udp(QemuOpts 
 *opts)
  
  fd = inet_dgram_opts(opts, local_err);
  if (fd  0) {
 +qerror_report_err(local_err);
 +error_free(local_err);
  return NULL;
  }
  return qemu_chr_open_udp_fd(fd);

Also plugs memory leak on error path.  Worth mentioning in commit
message.



[Qemu-devel] [PATCH 05/23] ide: Convert verify commands to ide_cmd_table handler

2013-06-24 Thread Stefan Hajnoczi
From: Kevin Wolf kw...@redhat.com

Signed-off-by: Kevin Wolf kw...@redhat.com
Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
---
 hw/ide/core.c | 27 +--
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 057662d..bf2007a 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1046,6 +1046,16 @@ static bool cmd_identify(IDEState *s, uint8_t cmd)
 return true;
 }
 
+static bool cmd_verify(IDEState *s, uint8_t cmd)
+{
+bool lba48 = (cmd == WIN_VERIFY_EXT);
+
+/* do sector number check ? */
+ide_cmd_lba48_transform(s, lba48);
+
+return true;
+}
+
 #define HD_OK (1u  IDE_HD)
 #define CD_OK (1u  IDE_CD)
 #define CFA_OK (1u  IDE_CFATA)
@@ -1079,9 +1089,9 @@ static const struct {
 [CFA_WRITE_SECT_WO_ERASE] = { NULL, CFA_OK },
 [WIN_MULTWRITE_EXT]   = { NULL, HD_CFA_OK },
 [WIN_WRITE_VERIFY]= { NULL, HD_CFA_OK },
-[WIN_VERIFY]  = { NULL, HD_CFA_OK },
-[WIN_VERIFY_ONCE] = { NULL, HD_CFA_OK },
-[WIN_VERIFY_EXT]  = { NULL, HD_CFA_OK },
+[WIN_VERIFY]  = { cmd_verify, HD_CFA_OK | SET_DSC },
+[WIN_VERIFY_ONCE] = { cmd_verify, HD_CFA_OK | SET_DSC },
+[WIN_VERIFY_EXT]  = { cmd_verify, HD_CFA_OK | SET_DSC },
 [WIN_SEEK]= { NULL, HD_CFA_OK },
 [CFA_TRANSLATE_SECTOR]= { NULL, CFA_OK },
 [WIN_DIAGNOSE]= { NULL, ALL_OK },
@@ -1187,17 +1197,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
 ide_set_irq(s-bus);
 break;
 
-case WIN_VERIFY_EXT:
-lba48 = 1;
-/* fall through */
-case WIN_VERIFY:
-case WIN_VERIFY_ONCE:
-/* do sector number check ? */
-   ide_cmd_lba48_transform(s, lba48);
-s-status = READY_STAT | SEEK_STAT;
-ide_set_irq(s-bus);
-break;
-
 case WIN_READ_EXT:
 lba48 = 1;
 /* fall through */
-- 
1.8.1.4




[Qemu-devel] [PATCH 02/23] ide: Convert WIN_DSM to ide_cmd_table handler

2013-06-24 Thread Stefan Hajnoczi
From: Kevin Wolf kw...@redhat.com

Signed-off-by: Kevin Wolf kw...@redhat.com
Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
---
 hw/ide/core.c | 29 -
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index cd9de14..567515e 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1004,6 +1004,21 @@ void ide_ioport_write(void *opaque, uint32_t addr, 
uint32_t val)
 }
 }
 
+static bool cmd_data_set_management(IDEState *s, uint8_t cmd)
+{
+switch (s-feature) {
+case DSM_TRIM:
+if (s-bs) {
+ide_sector_start_dma(s, IDE_DMA_TRIM);
+return false;
+}
+break;
+}
+
+ide_abort_command(s);
+return true;
+}
+
 #define HD_OK (1u  IDE_HD)
 #define CD_OK (1u  IDE_CD)
 #define CFA_OK (1u  IDE_CFATA)
@@ -1021,7 +1036,7 @@ static const struct {
 } ide_cmd_table[0x100] = {
 /* NOP not implemented, mandatory for CD */
 [CFA_REQ_EXT_ERROR_CODE]  = { NULL, CFA_OK },
-[WIN_DSM] = { NULL, ALL_OK },
+[WIN_DSM] = { cmd_data_set_management, ALL_OK },
 [WIN_DEVICE_RESET]= { NULL, CD_OK },
 [WIN_RECAL]   = { NULL, HD_CFA_OK },
 [WIN_READ]= { NULL, ALL_OK },
@@ -1129,18 +1144,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
 }
 
 switch(val) {
-case WIN_DSM:
-switch (s-feature) {
-case DSM_TRIM:
-if (!s-bs) {
-goto abort_cmd;
-}
-ide_sector_start_dma(s, IDE_DMA_TRIM);
-break;
-default:
-goto abort_cmd;
-}
-break;
 case WIN_IDENTIFY:
 if (s-bs  s-drive_kind != IDE_CD) {
 if (s-drive_kind != IDE_CFATA)
-- 
1.8.1.4




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

2013-06-24 Thread Stefan Hajnoczi
The following changes since commit 576156ffed72ab4feb0b752979db86ff8759a2a1:

  Merge remote-tracking branch 'bonzini/iommu-for-anthony' into staging 
(2013-06-20 16:53:39 -0500)

are available in the git repository at:


  git://github.com/stefanha/qemu.git block

for you to fetch changes up to 96c51eb5e46af2312b33f745ad72acb20e799aea:

  vmdk: refuse to open higher version than supported (2013-06-24 10:25:43 +0200)


Fam Zheng (1):
  vmdk: refuse to open higher version than supported

Kevin Wolf (22):
  ide: Add handler to ide_cmd_table
  ide: Convert WIN_DSM to ide_cmd_table handler
  ide: Convert WIN_IDENTIFY to ide_cmd_table handler
  ide: Convert cmd_nop commands to ide_cmd_table handler
  ide: Convert verify commands to ide_cmd_table handler
  ide: Convert read/write multiple commands to ide_cmd_table handler
  ide: Convert PIO read/write commands to ide_cmd_table handler
  ide: Convert DMA read/write commands to ide_cmd_table handler
  ide: Convert READ NATIVE MAX ADDRESS to ide_cmd_table handler
  ide: Convert CHECK POWER MDOE to ide_cmd_table handler
  ide: Convert SET FEATURES to ide_cmd_table handler
  ide: Convert FLUSH CACHE to ide_cmd_table handler
  ide: Convert SEEK to ide_cmd_table handler
  ide: Convert ATAPI commands to ide_cmd_table handler
  ide: Convert CF-ATA commands to ide_cmd_table handler
  ide: Convert SMART commands to ide_cmd_table handler
  ide: Clean up ide_exec_cmd()
  Revert block: Disable driver-specific options for 1.5
  qcow2: Add refcount update reason to all callers
  qcow2: Options to enable discard for freed clusters
  qcow2: Batch discards
  block: Always enable discard on the protocol level

 block.c  |2 +-
 block/qcow2-cluster.c|   41 +-
 block/qcow2-refcount.c   |  136 -
 block/qcow2-snapshot.c   |6 +-
 block/qcow2.c|   30 +-
 block/qcow2.h|   32 +-
 block/vmdk.c |9 +
 blockdev.c   |  118 +
 hw/ide/core.c| 1242 +-
 tests/qemu-iotests/group |2 +-
 10 files changed, 892 insertions(+), 726 deletions(-)

-- 
1.8.1.4




[Qemu-devel] [PATCH 11/23] ide: Convert SET FEATURES to ide_cmd_table handler

2013-06-24 Thread Stefan Hajnoczi
From: Kevin Wolf kw...@redhat.com

Signed-off-by: Kevin Wolf kw...@redhat.com
Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
---
 hw/ide/core.c | 147 ++
 1 file changed, 75 insertions(+), 72 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index a7f8445..8789758 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1206,6 +1206,80 @@ static bool cmd_check_power_mode(IDEState *s, uint8_t 
cmd)
 return true;
 }
 
+static bool cmd_set_features(IDEState *s, uint8_t cmd)
+{
+uint16_t *identify_data;
+
+if (!s-bs) {
+ide_abort_command(s);
+return true;
+}
+
+/* XXX: valid for CDROM ? */
+switch (s-feature) {
+case 0x02: /* write cache enable */
+bdrv_set_enable_write_cache(s-bs, true);
+identify_data = (uint16_t *)s-identify_data;
+put_le16(identify_data + 85, (1  14) | (1  5) | 1);
+return true;
+case 0x82: /* write cache disable */
+bdrv_set_enable_write_cache(s-bs, false);
+identify_data = (uint16_t *)s-identify_data;
+put_le16(identify_data + 85, (1  14) | 1);
+ide_flush_cache(s);
+return false;
+case 0xcc: /* reverting to power-on defaults enable */
+case 0x66: /* reverting to power-on defaults disable */
+case 0xaa: /* read look-ahead enable */
+case 0x55: /* read look-ahead disable */
+case 0x05: /* set advanced power management mode */
+case 0x85: /* disable advanced power management mode */
+case 0x69: /* NOP */
+case 0x67: /* NOP */
+case 0x96: /* NOP */
+case 0x9a: /* NOP */
+case 0x42: /* enable Automatic Acoustic Mode */
+case 0xc2: /* disable Automatic Acoustic Mode */
+return true;
+case 0x03: /* set transfer mode */
+{
+uint8_t val = s-nsector  0x07;
+identify_data = (uint16_t *)s-identify_data;
+
+switch (s-nsector  3) {
+case 0x00: /* pio default */
+case 0x01: /* pio mode */
+put_le16(identify_data + 62, 0x07);
+put_le16(identify_data + 63, 0x07);
+put_le16(identify_data + 88, 0x3f);
+break;
+case 0x02: /* sigle word dma mode*/
+put_le16(identify_data + 62, 0x07 | (1  (val + 8)));
+put_le16(identify_data + 63, 0x07);
+put_le16(identify_data + 88, 0x3f);
+break;
+case 0x04: /* mdma mode */
+put_le16(identify_data + 62, 0x07);
+put_le16(identify_data + 63, 0x07 | (1  (val + 8)));
+put_le16(identify_data + 88, 0x3f);
+break;
+case 0x08: /* udma mode */
+put_le16(identify_data + 62, 0x07);
+put_le16(identify_data + 63, 0x07);
+put_le16(identify_data + 88, 0x3f | (1  (val + 8)));
+break;
+default:
+goto abort_cmd;
+}
+return true;
+}
+}
+
+abort_cmd:
+ide_abort_command(s);
+return true;
+}
+
 #define HD_OK (1u  IDE_HD)
 #define CD_OK (1u  IDE_CD)
 #define CFA_OK (1u  IDE_CFATA)
@@ -1274,7 +1348,7 @@ static const struct {
 [WIN_FLUSH_CACHE] = { NULL, ALL_OK },
 [WIN_FLUSH_CACHE_EXT] = { NULL, HD_CFA_OK },
 [WIN_IDENTIFY]= { cmd_identify, ALL_OK },
-[WIN_SETFEATURES] = { NULL, ALL_OK },
+[WIN_SETFEATURES] = { cmd_set_features, ALL_OK | SET_DSC },
 [IBM_SENSE_CONDITION] = { NULL, CFA_OK },
 [CFA_WEAR_LEVEL]  = { NULL, HD_CFA_OK },
 [WIN_READ_NATIVE_MAX] = { cmd_read_native_max, ALL_OK | SET_DSC },
@@ -1288,7 +1362,6 @@ static bool ide_cmd_permitted(IDEState *s, uint32_t cmd)
 
 void ide_exec_cmd(IDEBus *bus, uint32_t val)
 {
-uint16_t *identify_data;
 IDEState *s;
 int n;
 
@@ -1330,76 +1403,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
 }
 
 switch(val) {
-case WIN_SETFEATURES:
-if (!s-bs)
-goto abort_cmd;
-/* XXX: valid for CDROM ? */
-switch(s-feature) {
-case 0x02: /* write cache enable */
-bdrv_set_enable_write_cache(s-bs, true);
-identify_data = (uint16_t *)s-identify_data;
-put_le16(identify_data + 85, (1  14) | (1  5) | 1);
-s-status = READY_STAT | SEEK_STAT;
-ide_set_irq(s-bus);
-break;
-case 0x82: /* write cache disable */
-bdrv_set_enable_write_cache(s-bs, false);
-identify_data = (uint16_t *)s-identify_data;
-put_le16(identify_data + 85, (1  14) | 1);
-ide_flush_cache(s);
-break;
-case 0xcc: /* reverting to power-on defaults enable */
-case 0x66: /* reverting to power-on defaults disable */
-case 0xaa: /* read look-ahead enable */
-case 0x55: /* read look-ahead 

[Qemu-devel] [PATCH 03/23] ide: Convert WIN_IDENTIFY to ide_cmd_table handler

2013-06-24 Thread Stefan Hajnoczi
From: Kevin Wolf kw...@redhat.com

Signed-off-by: Kevin Wolf kw...@redhat.com
Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
---
 hw/ide/core.c | 40 +++-
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 567515e..2df078b 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1019,6 +1019,28 @@ static bool cmd_data_set_management(IDEState *s, uint8_t 
cmd)
 return true;
 }
 
+static bool cmd_identify(IDEState *s, uint8_t cmd)
+{
+if (s-bs  s-drive_kind != IDE_CD) {
+if (s-drive_kind != IDE_CFATA) {
+ide_identify(s);
+} else {
+ide_cfata_identify(s);
+}
+s-status = READY_STAT | SEEK_STAT;
+ide_transfer_start(s, s-io_buffer, 512, ide_transfer_stop);
+ide_set_irq(s-bus);
+return false;
+} else {
+if (s-drive_kind == IDE_CD) {
+ide_set_signature(s);
+}
+ide_abort_command(s);
+}
+
+return true;
+}
+
 #define HD_OK (1u  IDE_HD)
 #define CD_OK (1u  IDE_CD)
 #define CFA_OK (1u  IDE_CFATA)
@@ -1086,7 +1108,7 @@ static const struct {
 [WIN_SLEEPNOW1]   = { NULL, ALL_OK },
 [WIN_FLUSH_CACHE] = { NULL, ALL_OK },
 [WIN_FLUSH_CACHE_EXT] = { NULL, HD_CFA_OK },
-[WIN_IDENTIFY]= { NULL, ALL_OK },
+[WIN_IDENTIFY]= { cmd_identify, ALL_OK },
 [WIN_SETFEATURES] = { NULL, ALL_OK },
 [IBM_SENSE_CONDITION] = { NULL, CFA_OK },
 [CFA_WEAR_LEVEL]  = { NULL, HD_CFA_OK },
@@ -1144,22 +1166,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
 }
 
 switch(val) {
-case WIN_IDENTIFY:
-if (s-bs  s-drive_kind != IDE_CD) {
-if (s-drive_kind != IDE_CFATA)
-ide_identify(s);
-else
-ide_cfata_identify(s);
-s-status = READY_STAT | SEEK_STAT;
-ide_transfer_start(s, s-io_buffer, 512, ide_transfer_stop);
-} else {
-if (s-drive_kind == IDE_CD) {
-ide_set_signature(s);
-}
-ide_abort_command(s);
-}
-ide_set_irq(s-bus);
-break;
 case WIN_SPECIFY:
 case WIN_RECAL:
 s-error = 0;
-- 
1.8.1.4




[Qemu-devel] [PATCH 01/23] ide: Add handler to ide_cmd_table

2013-06-24 Thread Stefan Hajnoczi
From: Kevin Wolf kw...@redhat.com

As a preparation for moving all IDE commands into their own function
like in the ATAPI code, introduce a 'handler' callback to ide_cmd_table.

Commands using this new infrastructure get some things handled
automatically:

* The BSY flag is set before calling the handler (in order to avoid bugs
  like the one fixed in f68ec837) and reset on completion.

* The (obsolete) DSC flag in the status register is set on completion if
  the command is flagged with SET_DSC in the command table

* An IRQ is triggered on completion.

* The error register and the ERR flag in the status register are cleared
  before calling the handler and on completion it is asserted that
  either none or both of them are set.

No commands are converted at this point.

Signed-off-by: Kevin Wolf kw...@redhat.com
Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
---
 hw/ide/core.c | 144 +++---
 1 file changed, 86 insertions(+), 58 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 9926d92..cd9de14 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1010,71 +1010,78 @@ void ide_ioport_write(void *opaque, uint32_t addr, 
uint32_t val)
 #define HD_CFA_OK (HD_OK | CFA_OK)
 #define ALL_OK (HD_OK | CD_OK | CFA_OK)
 
+/* Set the Disk Seek Completed status bit during completion */
+#define SET_DSC (1u  8)
+
 /* See ACS-2 T13/2015-D Table B.2 Command codes */
-static const uint8_t ide_cmd_table[0x100] = {
+static const struct {
+/* Returns true if the completion code should be run */
+bool (*handler)(IDEState *s, uint8_t cmd);
+int flags;
+} ide_cmd_table[0x100] = {
 /* NOP not implemented, mandatory for CD */
-[CFA_REQ_EXT_ERROR_CODE]= CFA_OK,
-[WIN_DSM]   = ALL_OK,
-[WIN_DEVICE_RESET]  = CD_OK,
-[WIN_RECAL] = HD_CFA_OK,
-[WIN_READ]  = ALL_OK,
-[WIN_READ_ONCE] = ALL_OK,
-[WIN_READ_EXT]  = HD_CFA_OK,
-[WIN_READDMA_EXT]   = HD_CFA_OK,
-[WIN_READ_NATIVE_MAX_EXT]   = HD_CFA_OK,
-[WIN_MULTREAD_EXT]  = HD_CFA_OK,
-[WIN_WRITE] = HD_CFA_OK,
-[WIN_WRITE_ONCE]= HD_CFA_OK,
-[WIN_WRITE_EXT] = HD_CFA_OK,
-[WIN_WRITEDMA_EXT]  = HD_CFA_OK,
-[CFA_WRITE_SECT_WO_ERASE]   = CFA_OK,
-[WIN_MULTWRITE_EXT] = HD_CFA_OK,
-[WIN_WRITE_VERIFY]  = HD_CFA_OK,
-[WIN_VERIFY]= HD_CFA_OK,
-[WIN_VERIFY_ONCE]   = HD_CFA_OK,
-[WIN_VERIFY_EXT]= HD_CFA_OK,
-[WIN_SEEK]  = HD_CFA_OK,
-[CFA_TRANSLATE_SECTOR]  = CFA_OK,
-[WIN_DIAGNOSE]  = ALL_OK,
-[WIN_SPECIFY]   = HD_CFA_OK,
-[WIN_STANDBYNOW2]   = ALL_OK,
-[WIN_IDLEIMMEDIATE2]= ALL_OK,
-[WIN_STANDBY2]  = ALL_OK,
-[WIN_SETIDLE2]  = ALL_OK,
-[WIN_CHECKPOWERMODE2]   = ALL_OK,
-[WIN_SLEEPNOW2] = ALL_OK,
-[WIN_PACKETCMD] = CD_OK,
-[WIN_PIDENTIFY] = CD_OK,
-[WIN_SMART] = HD_CFA_OK,
-[CFA_ACCESS_METADATA_STORAGE]   = CFA_OK,
-[CFA_ERASE_SECTORS] = CFA_OK,
-[WIN_MULTREAD]  = HD_CFA_OK,
-[WIN_MULTWRITE] = HD_CFA_OK,
-[WIN_SETMULT]   = HD_CFA_OK,
-[WIN_READDMA]   = HD_CFA_OK,
-[WIN_READDMA_ONCE]  = HD_CFA_OK,
-[WIN_WRITEDMA]  = HD_CFA_OK,
-[WIN_WRITEDMA_ONCE] = HD_CFA_OK,
-[CFA_WRITE_MULTI_WO_ERASE]  = CFA_OK,
-[WIN_STANDBYNOW1]   = ALL_OK,
-[WIN_IDLEIMMEDIATE] = ALL_OK,
-[WIN_STANDBY]   = ALL_OK,
-[WIN_SETIDLE1]  = ALL_OK,
-[WIN_CHECKPOWERMODE1]   = ALL_OK,
-[WIN_SLEEPNOW1] = ALL_OK,
-[WIN_FLUSH_CACHE]   = ALL_OK,
-[WIN_FLUSH_CACHE_EXT]   = HD_CFA_OK,
-[WIN_IDENTIFY]  = ALL_OK,
-[WIN_SETFEATURES]   = ALL_OK,
-[IBM_SENSE_CONDITION]   = CFA_OK,
-[CFA_WEAR_LEVEL]= HD_CFA_OK,
-[WIN_READ_NATIVE_MAX]   = ALL_OK,
+[CFA_REQ_EXT_ERROR_CODE]  = { NULL, CFA_OK },
+[WIN_DSM] = { NULL, ALL_OK },
+[WIN_DEVICE_RESET]= { NULL, CD_OK },
+[WIN_RECAL]   = { NULL, HD_CFA_OK },
+[WIN_READ]= { NULL, ALL_OK },
+[WIN_READ_ONCE]   = { NULL, ALL_OK },
+[WIN_READ_EXT]   

[Qemu-devel] [PATCH 23/23] vmdk: refuse to open higher version than supported

2013-06-24 Thread Stefan Hajnoczi
From: Fam Zheng f...@redhat.com

Refuse to open higher version for safety.

Although we try to be compatible with published VMDK spec, VMware has
newer version from ESXi 5.1 exported OVF/OVA, which we have no knowledge
what's changed in it. And it is very likely to have more new versions in
the future, so it's not safe to open them blindly.

Signed-off-by: Fam Zheng f...@redhat.com
Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
---
 block/vmdk.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/block/vmdk.c b/block/vmdk.c
index 65ae011..975e1d4 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -561,6 +561,15 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,
 header = footer.header;
 }
 
+if (le32_to_cpu(header.version) = 3) {
+char buf[64];
+snprintf(buf, sizeof(buf), VMDK version %d,
+ le32_to_cpu(header.version));
+qerror_report(QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
+bs-device_name, vmdk, buf);
+return -ENOTSUP;
+}
+
 l1_entry_sectors = le32_to_cpu(header.num_gtes_per_gte)
 * le64_to_cpu(header.granularity);
 if (l1_entry_sectors == 0) {
-- 
1.8.1.4




  1   2   3   4   >