Re: [Qemu-devel] [PATCH v2 6/7] libcacard/vcard_emul_nss: Assert vreaderOpt isn't null

2014-05-26 Thread Markus Armbruster
Michael Tokarev m...@tls.msk.ru writes:

 23.05.2014 22:16, Michael Tokarev пишет:
 23.05.2014 22:09, Michael Tokarev wrote:
 23.05.2014 15:24, Markus Armbruster wrote:
 It's not locally obvious, and Coverity can't see it either.

 Signed-off-by: Markus Armbruster arm...@redhat.com
 Reviewed-by: Alon Levy al...@redhat.com
 ---
  libcacard/vcard_emul_nss.c | 1 +
  1 file changed, 1 insertion(+)

 diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c
 index 2048917..4f55e44 100644
 --- a/libcacard/vcard_emul_nss.c
 +++ b/libcacard/vcard_emul_nss.c
 @@ -1181,6 +1181,7 @@ vcard_emul_options(const char *args)
  vreaderOpt = g_renew(VirtualReaderOptions, opts-vreader,
   reader_count);
  }
 +assert(vreaderOpt);
  opts-vreader = vreaderOpt;
  vreaderOpt = vreaderOpt[opts-vreader_count];
  vreaderOpt-name = g_strndup(name, name_length);

 Shouldn't the assignment be moved up one line into the if {}
 statement instead?
 
 Actually it looks like this code is just buggy, it works for just
 one iteration.  Because at this place, vreaderOpts will be non-NULL
 only if we expanded the array.  If we didn't (we do that in
 READER_STEP increments), we'll be assigning NULL to opts-vreader,
 because vreaderOpt will _really_ be NULL here.

You're right.  When I saw the conditional realloc, I jumped to convince
myself that it's always executed in the first loop iteration, but missed
the fact that vreaderOpt is reset to null on *every* iteration.

 So, the real fix is:

 1) drop = NULL at declaration of vreaderOpt;
 2) do not mention vreaderOpt inside the if{} statement at
all, we don't need indirection there;
 3) drop this opts-vreader assignment

 and ofcourse do not add the assert as in the patch above ;)

I'll review it.  Thanks!



Re: [Qemu-devel] [PATCH] libcacard: fix wrong array expansion logic

2014-05-26 Thread Markus Armbruster
Michael Tokarev m...@tls.msk.ru writes:

 The currrent code in libcacard/vcard_emul_nss.c:vcard_emul_options()
 has a weird bug in variable usage around expanding opts-vreader
 array.

 There's a helper variable, vreaderOpt, which is first needlessly
 initialized to NULL, next, conditionally, only we have to expand
 opts-vreader, receives array expansion from g_renew() (initially
 realloc), and next, even if we don't actually perform expansion,

I don't get the (initially realloc) part.  The sentence makes sense to
me just fine without it, though.

 the value of this variable is assigned to the actual array,
 opts-vreader, which was supposed to be expanded.

 So, since we expand the array by READER_STEP increments, only
 once in READER_STEP (=4) the code will work, in other 3/4 times
 it will fail badly.

 Fix this by not using this temp variable when expanding the
 array, and by dropping the useless =NULL initializer too -
 if it wasn't in place initially, compiler warned us about

would have warned us?

 this problem at the beginning.

 Signed-off-by: Michael Tokarev m...@tls.msk.ru
 ---
  libcacard/vcard_emul_nss.c |9 -
  1 file changed, 4 insertions(+), 5 deletions(-)

 diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c
 index b7db51d..8462aef 100644
 --- a/libcacard/vcard_emul_nss.c
 +++ b/libcacard/vcard_emul_nss.c
 @@ -1149,7 +1149,7 @@ vcard_emul_options(const char *args)
  char type_str[100];
  VCardEmulType type;
  int count, i;
 -VirtualReaderOptions *vreaderOpt = NULL;
 +VirtualReaderOptions *vreaderOpt;
  
  args = strip(args + 5);
  if (*args != '(') {
 @@ -1173,11 +1173,10 @@ vcard_emul_options(const char *args)
  
  if (opts-vreader_count = reader_count) {
  reader_count += READER_STEP;
 -vreaderOpt = g_renew(VirtualReaderOptions, opts-vreader,
 - reader_count);
 +opts-vreader = g_renew(VirtualReaderOptions, opts-vreader,
 +reader_count);
  }
 -opts-vreader = vreaderOpt;
 -vreaderOpt = vreaderOpt[opts-vreader_count];
 +vreaderOpt = opts-vreader[opts-vreader_count];
  vreaderOpt-name = g_strndup(name, name_length);
  vreaderOpt-vname = g_strndup(vname, vname_length);
  vreaderOpt-card_type = type;

Much more straightforward now.  Thanks!

Reviewed-by: Markus Armbruster arm...@redhat.com



Re: [Qemu-devel] [PATCH] libcacard: fix wrong array expansion logic

2014-05-26 Thread Michael Tokarev
26.05.2014 10:25, Markus Armbruster wrote:
 Michael Tokarev m...@tls.msk.ru writes:
 
 The currrent code in libcacard/vcard_emul_nss.c:vcard_emul_options()
 has a weird bug in variable usage around expanding opts-vreader
 array.

 There's a helper variable, vreaderOpt, which is first needlessly
 initialized to NULL, next, conditionally, only we have to expand
 opts-vreader, receives array expansion from g_renew() (initially
 realloc), and next, even if we don't actually perform expansion,
 
 I don't get the (initially realloc) part.  The sentence makes sense to
 me just fine without it, though.

I was in context of your patch which changes realloc() to g_renew().
And I failed to mention that this my patch is on top of yuors,
too - think of this comment as such a mention ;)

 the value of this variable is assigned to the actual array,
 opts-vreader, which was supposed to be expanded.

 So, since we expand the array by READER_STEP increments, only
 once in READER_STEP (=4) the code will work, in other 3/4 times
 it will fail badly.

 Fix this by not using this temp variable when expanding the
 array, and by dropping the useless =NULL initializer too -
 if it wasn't in place initially, compiler warned us about
 
 would have warned us?

Oh yeah.  I tried to remember the right English construct, but
failed.  This tense always escpapes my mind for some reason :)


 Much more straightforward now.  Thanks!
 
 Reviewed-by: Markus Armbruster arm...@redhat.com

Thank you.  I'll fix the comment.  And I'm now ready to push
whole -trivial.

/mjt




Re: [Qemu-devel] [PATCH v4 0/3] SMBIOS cleanup round

2014-05-26 Thread Markus Armbruster
Gabriel L. Somlo gso...@gmail.com writes:

 On Fri, May 23, 2014 at 12:00:12PM +0300, Michael S. Tsirkin wrote:
  1. There's a fairly complex setup (create a boot disk, start the
  guest, loop around waiting for the bios to finish booting, watch
  when your disk-based boot loader runs, etc.) before starting to
  examine the guest memory for the presence and correctness of the acpi
  tables.
  
  Would it make sense to  rename this file to something like e.g.
  tests/biostables-test.c, and add checks for smbios to the already
  started and booted guest ?
  
  If not, I'd have to replicate most of your test-harness code,
  which is almost half of acpi-test.c. That shouldn't be hard (you
  already did the heavy lifting on that one), but I intuitively dislike
  multiple cut'n'paste clones of significant code fragments :)
 
 Sure, fine.

 So I was about to send a patch with acpi-test.c renamed to
 bios-tables-test.c, but the patch is basically removing all of
 acpi-test.c, and creating a new file bios-tables-test.c.

Err, isn't that what a rename does?

 Do you have a better way to rename the file first, and then I can
 send a patch against it ? Or should we give up on renaming it
 altogether ? Or should I just bite the bullet and cut'n'paste your
 test harness into a new file specific to smbios ?

 It's not particularly important to me which way we go -- I want to do
 the right thing, whatever you decide that is :)

Did you rename with git-mv?  Did you diff with rename detection on?  See
diff.renames in git-config(1).

[...]



[Qemu-devel] [PATCH 0/8] Obtain dirty bitmap via VM logging

2014-05-26 Thread Sanidhya Kashyap
Hi,

The following patches introduce the support of dirty bitmap logging and dumping
to a specified file. Still, some work is still left in the area of runstates 
that
I will try to work on after discussing this patch series.

v1 -- v2:
* Added two new run states to avoid simultaneous execution of both migration and
  bitmap dump process.
* Removed FILE pointer usage.
* Dumping the data only in machine-readable format.
* Tried to rectified mistakes of the previous version.



Sanidhya Kashyap (8):
  enable sharing of the function between migration and bitmap dump
  bitmap dump code via QAPI framework
  RunState: added two new flags for bitmap dump and migration process
  bitmap dump process with runstates
  hmp interface for dirty bitmap dump
  cancel mechanism for an already running dump bitmap process
  set the frequency of the dump bitmap process
  python script for extracting bitmap from a binary file

 arch_init.c   |  19 +--
 hmp-commands.hx   |  45 +++
 hmp.c |  33 ++
 hmp.h |   3 +
 include/exec/ram_addr.h   |   4 +
 migration.c   |   7 ++
 qapi-schema.json  |  42 ++-
 qmp-commands.hx   |  76 
 savevm.c  | 290 ++
 scripts/extract-bitmap.py |  64 ++
 vl.c  |  29 -
 11 files changed, 602 insertions(+), 10 deletions(-)
 create mode 100755 scripts/extract-bitmap.py

-- 
1.8.3.1




[Qemu-devel] [PATCH 1/8] enable sharing of the function between migration and bitmap dump

2014-05-26 Thread Sanidhya Kashyap
As advised by Eric, I have enabled sharing of the function between of the
function that syncs the dirty bitmap obtained via kvm ioctl. I have tried
to make the least changes to the functions by concentrating only on the
function definitions.

Signed-off-by: Sanidhya Kashyap sanidhya.ii...@gmail.com
---
 arch_init.c | 19 +++
 include/exec/ram_addr.h |  4 
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 685ba0e..48eb90a 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -434,20 +434,22 @@ ram_addr_t 
migration_bitmap_find_and_reset_dirty(MemoryRegion *mr,
 return (next - base)  TARGET_PAGE_BITS;
 }
 
-static inline bool migration_bitmap_set_dirty(ram_addr_t addr)
+static inline bool bitmap_set_dirty(ram_addr_t addr, unsigned long *bitmap,
+ bool migration_flag)
 {
 bool ret;
 int nr = addr  TARGET_PAGE_BITS;
 
-ret = test_and_set_bit(nr, migration_bitmap);
+ret = test_and_set_bit(nr, bitmap);
 
-if (!ret) {
+if (!ret  migration_flag) {
 migration_dirty_pages++;
 }
 return ret;
 }
 
-static void migration_bitmap_sync_range(ram_addr_t start, ram_addr_t length)
+void bitmap_sync_range(ram_addr_t start, ram_addr_t length,
+  unsigned long *bitmap, bool migration_flag)
 {
 ram_addr_t addr;
 unsigned long page = BIT_WORD(start  TARGET_PAGE_BITS);
@@ -461,8 +463,8 @@ static void migration_bitmap_sync_range(ram_addr_t start, 
ram_addr_t length)
 for (k = page; k  page + nr; k++) {
 if (src[k]) {
 unsigned long new_dirty;
-new_dirty = ~migration_bitmap[k];
-migration_bitmap[k] |= src[k];
+new_dirty = ~bitmap[k];
+bitmap[k] |= src[k];
 new_dirty = src[k];
 migration_dirty_pages += ctpopl(new_dirty);
 src[k] = 0;
@@ -476,7 +478,7 @@ static void migration_bitmap_sync_range(ram_addr_t start, 
ram_addr_t length)
 cpu_physical_memory_reset_dirty(start + addr,
 TARGET_PAGE_SIZE,
 DIRTY_MEMORY_MIGRATION);
-migration_bitmap_set_dirty(start + addr);
+bitmap_set_dirty(start + addr, bitmap, migration_flag);
 }
 }
 }
@@ -512,7 +514,8 @@ static void migration_bitmap_sync(void)
 address_space_sync_dirty_bitmap(address_space_memory);
 
 QTAILQ_FOREACH(block, ram_list.blocks, next) {
-migration_bitmap_sync_range(block-mr-ram_addr, block-length);
+bitmap_sync_range(block-mr-ram_addr, block-length,
+  migration_bitmap, true);
 }
 trace_migration_bitmap_sync_end(migration_dirty_pages
 - num_dirty_pages_init);
diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index 2edfa96..ca7d248 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -146,5 +146,9 @@ static inline void 
cpu_physical_memory_clear_dirty_range(ram_addr_t start,
 void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t length,
  unsigned client);
 
+
+void bitmap_sync_range(ram_addr_t start, ram_addr_t length,
+  unsigned long *bitmap, bool migration_flag);
+
 #endif
 #endif
-- 
1.8.3.1




[Qemu-devel] [PATCH 8/8] python script for extracting bitmap from a binary file

2014-05-26 Thread Sanidhya Kashyap
No particular functional change. This file does not need to be included in
the Makefile as it will be only useful once the user has generated the bitmap
file via bitmap dump process.

Signed-off-by: Sanidhya Kashyap sanidhya.ii...@gmail.com
---
 scripts/extract-bitmap.py | 64 +++
 1 file changed, 64 insertions(+)
 create mode 100755 scripts/extract-bitmap.py

diff --git a/scripts/extract-bitmap.py b/scripts/extract-bitmap.py
new file mode 100755
index 000..f5ca341
--- /dev/null
+++ b/scripts/extract-bitmap.py
@@ -0,0 +1,64 @@
+#!/usr/bin/python
+# This python script helps in extracting the dirty bitmap present
+# in the file after executing the log-dirty-bitmap command either
+# from the qmp or hmp interface. This file only processes binary
+# file obtained via command.
+#
+# Copyright (C) 2014 Sanidhya Kashyap sanidhya.ii...@gmail.com
+#
+# Authors:
+#   Sanidhya Kashyap
+#
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+
+import struct
+import argparse
+from functools import partial
+
+long_bytes = 8
+complete_bitmap_list = []
+
+def get_unsigned_long_integer(value):
+return struct.unpack('Q', value)[0]
+
+def get_long_integer(value):
+return struct.unpack('q',value)[0]
+
+def dump_bitmap(infile, bitmap_length):
+count = 1
+bitmap_list = []
+for value in iter(partial(infile.read, long_bytes), ''):
+if (count % bitmap_length):
+count += 1
+bitmap_list.append(hex(get_unsigned_long_integer(value)))
+else:
+complete_bitmap_list.append(bitmap_list)
+count = 1
+bitmap_list = []
+# currently, the complete list is printed. It is up to the user to decide 
about
+# the usage of the bitmap as the bitmap provides the writable working set 
of the
+# VM for a particular duration.
+print complete_bitmap_list
+
+def main():
+extracter = argparse.ArgumentParser(description='Extract dirty bitmap from 
binary file.')
+extracter.add_argument('infile', help='Input file to extract the bitmap')
+args = extracter.parse_args()
+print 'The filename is {}'.format(args.infile)
+
+infile = open(format(args.infile), 'rb')
+
+ram_bitmap_pages = get_long_integer(infile.read(long_bytes))
+print ram_bitmap_pages
+bitmap_length = ram_bitmap_pages / long_bytes
+if ram_bitmap_pages % long_bytes != 0:
+bitmap_length += 1
+print bitmap_length
+
+dump_bitmap(infile, bitmap_length);
+
+infile.close()
+
+if __name__ == '__main__':
+main()
-- 
1.8.3.1




[Qemu-devel] [PATCH 4/8] bitmap dump process with runstates

2014-05-26 Thread Sanidhya Kashyap
Introduced both runstates: RUN_STATE_MIGRATE and RUN_STATE_DUMP_BITMAP to
both migration and bitmap dump process.

I want the bitmap dump process to get canceled so whenever the state changes
from RUN_STATE_BITMAP to something else. But, this does not happen when I stop
the guest via stop qmp interface as the current_run_state variable is not 
updated.
Any thoughts on that? Do I need to make the changes there as well or is there 
any
simple way to do it?

Signed-off-by: Sanidhya Kashyap sanidhya.ii...@gmail.com
---
 migration.c |  7 +++
 savevm.c| 26 +++---
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/migration.c b/migration.c
index 3fc03d6..d91dd4c 100644
--- a/migration.c
+++ b/migration.c
@@ -436,6 +436,13 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
 return;
 }
 
+if (runstate_check(RUN_STATE_DUMP_BITMAP)) {
+error_setg(errp, bitmap dump in progress);
+return;
+}
+
+runstate_set(RUN_STATE_MIGRATE);
+
 s = migrate_init(params);
 
 if (strstart(uri, tcp:, p)) {
diff --git a/savevm.c b/savevm.c
index 525b388..675c8e5 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1163,7 +1163,8 @@ static void *bitmap_logging_thread(void *opaque)
  * using the FILE pointer f.
  */
 while (epoch_count  total_epochs) {
-if (!runstate_is_running() || b-state != LOG_BITMAP_STATE_ACTIVE) {
+if (!runstate_check(RUN_STATE_DUMP_BITMAP) ||
+b-state != LOG_BITMAP_STATE_ACTIVE) {
 goto log_thread_end;
 }
 bitmap_zero(logging_bitmap, ram_bitmap_pages);
@@ -1193,6 +1194,7 @@ static void *bitmap_logging_thread(void *opaque)
 logging_state_set_status(b, LOG_BITMAP_STATE_ERROR,
 LOG_BITMAP_STATE_COMPLETED);
 }
+runstate_set(RUN_STATE_RUNNING);
 return NULL;
 }
 
@@ -1203,18 +1205,26 @@ void qmp_log_dirty_bitmap(const char *filename, bool 
has_epochs,
 int fd = -1;
 BitmapLogState *b = logging_current_state();
 Error *local_err = NULL;
-if (b-state == LOG_BITMAP_STATE_ACTIVE ||
-b-state == LOG_BITMAP_STATE_SETUP ||
-b-state == LOG_BITMAP_STATE_CANCELING) {
+
+if (runstate_check(RUN_STATE_DUMP_BITMAP) ||
+b-state == LOG_BITMAP_STATE_ACTIVE ||
+b-state == LOG_BITMAP_STATE_SETUP ||
+b-state == LOG_BITMAP_STATE_CANCELING) {
 b = NULL;
 error_setg(errp, dirty bitmap dump in progress);
 return;
 }
 
-if (b-state == LOG_BITMAP_STATE_COMPLETED) {
-b-state = LOG_BITMAP_STATE_NONE;
+if (!runstate_is_running()) {
+b = NULL;
+error_setg(errp, Guest is not in a running state);
+return;
 }
 
+runstate_set(RUN_STATE_DUMP_BITMAP);
+
+b-state = LOG_BITMAP_STATE_NONE;
+
 if (!has_epochs) {
 epochs = MIN_EPOCH_VALUE;
 }
@@ -1227,14 +1237,16 @@ void qmp_log_dirty_bitmap(const char *filename, bool 
has_epochs,
 if (local_err) {
 b = NULL;
 error_propagate(errp, local_err);
+runstate_set(RUN_STATE_RUNNING);
 return;
 }
 }
 
 fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRUSR);
 if (fd  0) {
-error_setg_file_open(errp, errno, filename);
 b = NULL;
+error_setg_file_open(errp, errno, filename);
+runstate_set(RUN_STATE_RUNNING);
 return;
 }
 
-- 
1.8.3.1




[Qemu-devel] [PATCH 5/8] hmp interface for dirty bitmap dump

2014-05-26 Thread Sanidhya Kashyap

Signed-off-by: Sanidhya Kashyap sanidhya.ii...@gmail.com
---
 hmp-commands.hx | 16 
 hmp.c   | 16 
 hmp.h   |  1 +
 3 files changed, 33 insertions(+)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 2e462c0..1665587 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1780,6 +1780,22 @@ STEXI
 show available trace events and their state
 ETEXI
 
+ {
+.name   = ldb|log-dirty-bitmap,
+.args_type  = filename:s,epochs:i?,frequency:i?,
+.params = filename epochs frequency,
+.help   = dumps the memory's dirty bitmap to file\n\t\t\t
+ filename: name of the file in which the bitmap will be 
saved\n\t\t\t
+  epochs: number of times, the memory will be 
logged\n\t\t\t
+  frequency: time difference in milliseconds between each 
epoch,
+.mhandler.cmd = hmp_log_dirty_bitmap,
+},
+STEXI
+@item ldb or log-dirty-bitmap @var{filename}
+@findex log-dirty-bitmap
+dumps the writable working set of a VM's memory to a file
+ETEXI
+
 STEXI
 @end table
 ETEXI
diff --git a/hmp.c b/hmp.c
index ccc35d4..a400825 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1314,6 +1314,22 @@ void hmp_device_del(Monitor *mon, const QDict *qdict)
 hmp_handle_error(mon, err);
 }
 
+void hmp_log_dirty_bitmap(Monitor *mon, const QDict *qdict)
+{
+const char *filename = qdict_get_str(qdict, filename);
+int64_t epochs = qdict_get_try_int(qdict, epochs, 3);
+int64_t frequency = qdict_get_try_int(qdict, frequency, 10);
+Error *err = NULL;
+
+qmp_log_dirty_bitmap(filename, !!epochs, epochs, !!frequency,
+ frequency, err);
+if (err) {
+monitor_printf(mon, log-dirty-bitmap: %s\n, error_get_pretty(err));
+error_free(err);
+return;
+}
+}
+
 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
 {
 Error *err = NULL;
diff --git a/hmp.h b/hmp.h
index aba59e9..3a79a93 100644
--- a/hmp.h
+++ b/hmp.h
@@ -93,6 +93,7 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict);
 void hmp_cpu_add(Monitor *mon, const QDict *qdict);
 void hmp_object_add(Monitor *mon, const QDict *qdict);
 void hmp_object_del(Monitor *mon, const QDict *qdict);
+void hmp_log_dirty_bitmap(Monitor *mon, const QDict *qdict);
 void object_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void object_del_completion(ReadLineState *rs, int nb_args, const char *str);
 void device_add_completion(ReadLineState *rs, int nb_args, const char *str);
-- 
1.8.3.1




[Qemu-devel] [PATCH 6/8] cancel mechanism for an already running dump bitmap process

2014-05-26 Thread Sanidhya Kashyap
No particular functional changes. Rectified some previous mistakes.

Signed-off-by: Sanidhya Kashyap sanidhya.ii...@gmail.com
---
 hmp-commands.hx  | 14 ++
 hmp.c|  5 +
 hmp.h|  1 +
 qapi-schema.json |  8 
 qmp-commands.hx  | 20 
 savevm.c | 19 +++
 6 files changed, 67 insertions(+)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 1665587..501e011 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1796,6 +1796,20 @@ STEXI
 dumps the writable working set of a VM's memory to a file
 ETEXI
 
+   {
+   .name   = ldbc|log-dirty-bitmap-cancel,
+   .args_type  = ,
+   .params = ,
+   .help   = cancel the current bitmap dump process,
+   .mhandler.cmd = hmp_log_dirty_bitmap_cancel,
+},
+
+STEXI
+@item ldbc or log-dirty-bitmap-cancel
+@findex log-dirty-bitmap-cancel
+Cancel the current bitmap dump process
+ETEXI
+
 STEXI
 @end table
 ETEXI
diff --git a/hmp.c b/hmp.c
index a400825..fed8795 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1330,6 +1330,11 @@ void hmp_log_dirty_bitmap(Monitor *mon, const QDict 
*qdict)
 }
 }
 
+void hmp_log_dirty_bitmap_cancel(Monitor *mon, const QDict *qdict)
+{
+qmp_log_dirty_bitmap_cancel(NULL);
+}
+
 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
 {
 Error *err = NULL;
diff --git a/hmp.h b/hmp.h
index 3a79a93..b600429 100644
--- a/hmp.h
+++ b/hmp.h
@@ -94,6 +94,7 @@ void hmp_cpu_add(Monitor *mon, const QDict *qdict);
 void hmp_object_add(Monitor *mon, const QDict *qdict);
 void hmp_object_del(Monitor *mon, const QDict *qdict);
 void hmp_log_dirty_bitmap(Monitor *mon, const QDict *qdict);
+void hmp_log_dirty_bitmap_cancel(Monitor *mon, const QDict *qdict);
 void object_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void object_del_completion(ReadLineState *rs, int nb_args, const char *str);
 void device_add_completion(ReadLineState *rs, int nb_args, const char *str);
diff --git a/qapi-schema.json b/qapi-schema.json
index 2918fc4..9f9f097 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4744,3 +4744,11 @@
   'data': { 'filename'  : 'str',
 '*epochs'   : 'int',
 '*frequency': 'int' } }
+##
+# @log-dirty-bitmap-cancel
+#
+# cancel the dirty bitmap logging process
+#
+# Since 2.1
+##
+{ 'command': 'log-dirty-bitmap-cancel' }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 183a636..2a8dacc 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3605,3 +3605,23 @@ value is 3 while that of frequency is 10.
 
 EQMP
 
+   {
+.name   = log-dirty-bitmap-cancel,
+.args_type  = ,
+.mhandler.cmd_new = qmp_marshal_input_log_dirty_bitmap_cancel,
+},
+
+SQMP
+log_bitmap_cancel
+--
+
+Cancel the current bitmap dump process.
+
+Arguments: None.
+
+Example:
+
+- { execute: log-dirty-bitmap-cancel }
+- { return: {} }
+
+EQMP
diff --git a/savevm.c b/savevm.c
index 675c8e5..ff87254 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1260,6 +1260,25 @@ void qmp_log_dirty_bitmap(const char *filename, bool 
has_epochs,
 return;
 }
 
+static void logging_bitmap_cancel(BitmapLogState *b)
+{
+int old_state;
+do {
+old_state = b-state;
+if (old_state != LOG_BITMAP_STATE_SETUP 
+old_state != LOG_BITMAP_STATE_ACTIVE) {
+break;
+}
+logging_state_set_status(b, old_state,
+ LOG_BITMAP_STATE_CANCELING);
+} while (b-state != LOG_BITMAP_STATE_CANCELING);
+}
+
+void qmp_log_dirty_bitmap_cancel(Error **errp)
+{
+logging_bitmap_cancel(logging_current_state());
+}
+
 void qmp_xen_save_devices_state(const char *filename, Error **errp)
 {
 QEMUFile *f;
-- 
1.8.3.1




[Qemu-devel] [PATCH 7/8] set the frequency of the dump bitmap process

2014-05-26 Thread Sanidhya Kashyap
No particular functional change. Corrected some mistakes.

Signed-off-by: Sanidhya Kashyap sanidhya.ii...@gmail.com
---
 hmp-commands.hx  | 15 +++
 hmp.c| 12 
 hmp.h|  1 +
 qapi-schema.json | 10 ++
 qmp-commands.hx  | 23 +++
 savevm.c | 13 +
 6 files changed, 74 insertions(+)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 501e011..ce0d9b5 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1810,6 +1810,21 @@ STEXI
 Cancel the current bitmap dump process
 ETEXI
 
+{
+.name   = ldbsf|log-dirty-bitmap-set-frequency,
+.args_type  = frequency:i,
+.params = frequency,
+.help   = set the frequency for bitmap dump process\n\t\t\t
+  frequency: the new frequency value to replace the 
existing,
+.mhandler.cmd = hmp_log_dirty_bitmap_set_frequency,
+},
+
+STEXI
+@item ldbsf or log-dirty-bitmap-set-frequency @var{frequency}
+@findex log-dirty-bitmap-set-frequency
+Set the frequency to @var{frequency} (int) for bitmap dump process.
+ETEXI
+
 STEXI
 @end table
 ETEXI
diff --git a/hmp.c b/hmp.c
index fed8795..8765093 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1335,6 +1335,18 @@ void hmp_log_dirty_bitmap_cancel(Monitor *mon, const 
QDict *qdict)
 qmp_log_dirty_bitmap_cancel(NULL);
 }
 
+void hmp_log_dirty_bitmap_set_frequency(Monitor *mon, const QDict *qdict)
+{
+int64_t frequency = qdict_get_int(qdict, frequency);
+Error *err = NULL;
+qmp_log_dirty_bitmap_set_frequency(frequency, err);
+if (err) {
+monitor_printf(mon, log-dirty-bitmap-set-frequency: %s\n,
+   error_get_pretty(err));
+error_free(err);
+}
+}
+
 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
 {
 Error *err = NULL;
diff --git a/hmp.h b/hmp.h
index b600429..991be02 100644
--- a/hmp.h
+++ b/hmp.h
@@ -95,6 +95,7 @@ void hmp_object_add(Monitor *mon, const QDict *qdict);
 void hmp_object_del(Monitor *mon, const QDict *qdict);
 void hmp_log_dirty_bitmap(Monitor *mon, const QDict *qdict);
 void hmp_log_dirty_bitmap_cancel(Monitor *mon, const QDict *qdict);
+void hmp_log_dirty_bitmap_set_frequency(Monitor *mon, const QDict *qdict);
 void object_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void object_del_completion(ReadLineState *rs, int nb_args, const char *str);
 void device_add_completion(ReadLineState *rs, int nb_args, const char *str);
diff --git a/qapi-schema.json b/qapi-schema.json
index 9f9f097..7b7e4de 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4752,3 +4752,13 @@
 # Since 2.1
 ##
 { 'command': 'log-dirty-bitmap-cancel' }
+
+## @log-dirty-bitmap-set-frequency
+#
+# sets the frequency of the dirty bitmap logging process
+# @frequency: the updated frequency value
+#
+# Since 2.1
+##
+{ 'command': 'log-dirty-bitmap-set-frequency',
+  'data': {'frequency': 'int' } }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 2a8dacc..51a0ad8 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3625,3 +3625,26 @@ Example:
 - { return: {} }
 
 EQMP
+
+{
+.name   = log-dirty-bitmap-set-frequency,
+.args_type  = frequency:i,
+.mhandler.cmd_new = qmp_marshal_input_log_dirty_bitmap_set_frequency,
+},
+
+SQMP
+log-dirty-bitmap-set-frequency
+
+
+Update the frequency for the remaining epochs.
+
+Arguments:
+
+- frequency: the updated frequency (json-int)
+
+Example:
+
+- { execute: log-dirty-bitmap-set-frequency, arguments: { value: 1024 
} }
+- { return: {} }
+
+EQMP
diff --git a/savevm.c b/savevm.c
index ff87254..cfa8dce 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1279,6 +1279,19 @@ void qmp_log_dirty_bitmap_cancel(Error **errp)
 logging_bitmap_cancel(logging_current_state());
 }
 
+void qmp_log_dirty_bitmap_set_frequency(int64_t frequency, Error **errp)
+{
+BitmapLogState *b = logging_current_state();
+Error *local_err = NULL;
+if (!check_value(frequency, MIN_FREQUENCY_VALUE, frequency, local_err)) 
{
+if (local_err) {
+error_propagate(errp, local_err);
+return;
+}
+}
+b-current_frequency = frequency;
+}
+
 void qmp_xen_save_devices_state(const char *filename, Error **errp)
 {
 QEMUFile *f;
-- 
1.8.3.1




[Qemu-devel] [PATCH 3/8] RunState: added two new flags for bitmap dump and migration process

2014-05-26 Thread Sanidhya Kashyap
I have added two new flags - RUN_STATE_MIGRATE and RUN_STATE_DUMP_BITMAP.
These both flags behave same as RUN_STATE_RUNNING flag. The purpose of
introducing these flags is to avoid running both migration and dump bitmap
process simultaneously.

I haven't added many transitions to the RUN_STATE_DUMP_BITMAP. I will try
to include the transitions on the basis of discussions.

On the other hand, I have tried to add the transitions that might occur during
the migration process. There is a possibility that some transitions can be
redundant (as pointed by Chen, this is not my patch problem,  but I have tried
to cover what I thought is necessary).

Signed-off-by: Sanidhya Kashyap sanidhya.ii...@gmail.com
---
 qapi-schema.json |  7 ++-
 vl.c | 29 -
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/qapi-schema.json b/qapi-schema.json
index 17e5147..2918fc4 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -234,12 +234,17 @@
 # @watchdog: the watchdog action is configured to pause and has been triggered
 #
 # @guest-panicked: guest has been panicked as a result of guest OS panic
+#
+# @migrate: migration process is being executed
+#
+# @dump-bitmap: dump the writable working set of the guest
+#
 ##
 { 'enum': 'RunState',
   'data': [ 'debug', 'inmigrate', 'internal-error', 'io-error', 'paused',
 'postmigrate', 'prelaunch', 'finish-migrate', 'restore-vm',
 'running', 'save-vm', 'shutdown', 'suspended', 'watchdog',
-'guest-panicked' ] }
+'guest-panicked', 'migrate', 'dump-bitmap' ] }
 
 ##
 # @SnapshotInfo
diff --git a/vl.c b/vl.c
index 709d8cd..a2ffd66 100644
--- a/vl.c
+++ b/vl.c
@@ -576,31 +576,39 @@ static const RunStateTransition 
runstate_transitions_def[] = {
 /* from  - to  */
 { RUN_STATE_DEBUG, RUN_STATE_RUNNING },
 { RUN_STATE_DEBUG, RUN_STATE_FINISH_MIGRATE },
+{ RUN_STATE_DEBUG, RUN_STATE_MIGRATE },
 
 { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING },
 { RUN_STATE_INMIGRATE, RUN_STATE_PAUSED },
 
 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED },
 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE },
+{ RUN_STATE_INTERNAL_ERROR, RUN_STATE_MIGRATE },
 
 { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING },
 { RUN_STATE_IO_ERROR, RUN_STATE_FINISH_MIGRATE },
+{ RUN_STATE_IO_ERROR, RUN_STATE_MIGRATE },
 
 { RUN_STATE_PAUSED, RUN_STATE_RUNNING },
 { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
+{ RUN_STATE_PAUSED, RUN_STATE_MIGRATE },
 
 { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING },
 { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },
+{ RUN_STATE_POSTMIGRATE, RUN_STATE_MIGRATE },
 
 { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING },
 { RUN_STATE_PRELAUNCH, RUN_STATE_FINISH_MIGRATE },
 { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
+{ RUN_STATE_PRELAUNCH, RUN_STATE_MIGRATE },
 
 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
 
 { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING },
 
+{ RUN_STATE_DUMP_BITMAP, RUN_STATE_RUNNING},
+
 { RUN_STATE_RUNNING, RUN_STATE_DEBUG },
 { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR },
 { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR },
@@ -611,6 +619,8 @@ static const RunStateTransition runstate_transitions_def[] 
= {
 { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN },
 { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG },
 { RUN_STATE_RUNNING, RUN_STATE_GUEST_PANICKED },
+{ RUN_STATE_RUNNING, RUN_STATE_DUMP_BITMAP },
+{ RUN_STATE_RUNNING, RUN_STATE_MIGRATE },
 
 { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING },
 
@@ -621,12 +631,27 @@ static const RunStateTransition 
runstate_transitions_def[] = {
 { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED },
 { RUN_STATE_SUSPENDED, RUN_STATE_RUNNING },
 { RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE },
+{ RUN_STATE_SUSPENDED, RUN_STATE_MIGRATE },
 
 { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING },
 { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },
+{ RUN_STATE_WATCHDOG, RUN_STATE_MIGRATE },
 
 { RUN_STATE_GUEST_PANICKED, RUN_STATE_RUNNING },
 { RUN_STATE_GUEST_PANICKED, RUN_STATE_FINISH_MIGRATE },
+{ RUN_STATE_GUEST_PANICKED, RUN_STATE_MIGRATE },
+
+{ RUN_STATE_DUMP_BITMAP, RUN_STATE_RUNNING },
+
+{ RUN_STATE_MIGRATE, RUN_STATE_POSTMIGRATE },
+{ RUN_STATE_MIGRATE, RUN_STATE_PAUSED },
+{ RUN_STATE_MIGRATE, RUN_STATE_SHUTDOWN },
+{ RUN_STATE_MIGRATE, RUN_STATE_GUEST_PANICKED },
+{ RUN_STATE_MIGRATE, RUN_STATE_DEBUG },
+{ RUN_STATE_MIGRATE, RUN_STATE_RUNNING },
+{ RUN_STATE_MIGRATE, RUN_STATE_INTERNAL_ERROR },
+{ RUN_STATE_MIGRATE, RUN_STATE_IO_ERROR },
+{ RUN_STATE_MIGRATE, RUN_STATE_WATCHDOG },
 
 { RUN_STATE_MAX, RUN_STATE_MAX },
 };
@@ -666,7 +691,9 @@ void runstate_set(RunState new_state)
 
 int runstate_is_running(void)
 {
-return runstate_check(RUN_STATE_RUNNING);
+return 

[Qemu-devel] [PATCH 2/8] bitmap dump code via QAPI framework

2014-05-26 Thread Sanidhya Kashyap
Following are the changes made with respect to the previous version:
Chen's advice
1) Replaced DIRTY_MEMORY_LOG_BITMAP with DIRTY_MEMORY_MIGRATION and
completely removed the DIRTY_MEMORY_LOG_BITMAP flag.

Eric's advice
2) Replaced FILE pointer with file descriptor.
3) Replaced fopen/fclose with qemu_open / qemu_close.
4) Removed text format, output only in machine-readable format.
5) Defined constants.


Signed-off-by: Sanidhya Kashyap sanidhya.ii...@gmail.com
---
 qapi-schema.json |  17 
 qmp-commands.hx  |  33 
 savevm.c | 246 +++
 3 files changed, 296 insertions(+)

diff --git a/qapi-schema.json b/qapi-schema.json
index 7bc33ea..17e5147 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4722,3 +4722,20 @@
   'btn' : 'InputBtnEvent',
   'rel' : 'InputMoveEvent',
   'abs' : 'InputMoveEvent' } }
+##
+# @log-dirty-bitmap
+#
+# dumps the dirty bitmap to a file by logging the
+# memory for a specified number of times with a
+# a defined time differnce
+#
+# @filename: name of the file in which the bitmap will be saved.
+# @epochs: number of times the memory will be logged.
+# @frequency: time difference in milliseconds between each epoch.
+#
+# Since 2.1
+##
+{ 'command' : 'log-dirty-bitmap',
+  'data': { 'filename'  : 'str',
+'*epochs'   : 'int',
+'*frequency': 'int' } }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index d8aa4ed..183a636 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3572,3 +3572,36 @@ Example:
} } ] }
 
 EQMP
+
+{
+.name   = log-dirty-bitmap,
+.args_type  = filename:s,epochs:i?,frequency:i?,readable:-r?,
+.mhandler.cmd_new = qmp_marshal_input_log_dirty_bitmap,
+},
+
+SQMP
+log-dirty-bitmap
+
+
+start logging the memory of the VM for writable working set
+
+Arguments:
+
+- filename: name of the file, in which the bitmap will be saved
+- epochs: number of times, the memory will be logged
+- frequency: time difference in milliseconds between each epoch
+
+Examples:
+- { execute : log-dirty-bitmap,
+ arguments : {
+ filename : /tmp/fileXXX,
+ epochs : 3,
+ frequency : 10 } }
+
+- { return: {} }
+
+Note: The epochs, frequency and readable are optional. epochs default
+value is 3 while that of frequency is 10.
+
+EQMP
+
diff --git a/savevm.c b/savevm.c
index da8aa24..525b388 100644
--- a/savevm.c
+++ b/savevm.c
@@ -41,6 +41,9 @@
 #include qemu/iov.h
 #include block/snapshot.h
 #include block/qapi.h
+#include exec/address-spaces.h
+#include exec/ram_addr.h
+#include qemu/bitmap.h
 
 #define SELF_ANNOUNCE_ROUNDS 5
 
@@ -1002,6 +1005,249 @@ void do_savevm(Monitor *mon, const QDict *qdict)
 }
 }
 
+/*
+ * Adding the functionality of continuous logging of the
+ * dirty bitmap which is almost similar to the migration
+ * thread
+ */
+
+enum {
+LOG_BITMAP_STATE_ERROR = -1,
+LOG_BITMAP_STATE_NONE,
+LOG_BITMAP_STATE_SETUP,
+LOG_BITMAP_STATE_ACTIVE,
+LOG_BITMAP_STATE_CANCELING,
+LOG_BITMAP_STATE_COMPLETED
+};
+
+typedef struct BitmapLogState BitmapLogState;
+static unsigned long *logging_bitmap;
+static int64_t MIN_EPOCH_VALUE = 3;
+static int64_t MIN_FREQUENCY_VALUE = 10;
+static int64_t LOG_SIZE_MAX = 10;
+
+struct BitmapLogState {
+int state;
+int fd;
+int64_t current_frequency;
+int64_t total_epochs;
+QemuThread thread;
+};
+
+/*
+ * helper functions
+ */
+
+static inline void logging_lock(void)
+{
+qemu_mutex_lock_iothread();
+qemu_mutex_lock_ramlist();
+}
+
+static inline void logging_unlock(void)
+{
+qemu_mutex_unlock_ramlist();
+qemu_mutex_unlock_iothread();
+}
+
+static inline void logging_bitmap_set_dirty(ram_addr_t addr)
+{
+int nr  = addr  TARGET_PAGE_BITS;
+set_bit(nr, logging_bitmap);
+}
+
+static bool logging_state_set_status(BitmapLogState *b,
+ int old_state,
+ int new_state)
+{
+return atomic_cmpxchg(b-state, old_state, new_state);
+}
+
+static inline bool check_value(int64_t value, int64_t min_value,
+   const char *str, Error **errp)
+{
+if (value  min_value) {
+error_setg(errp, %s's value must be greater than %ld,
+ str, min_value);
+return false;
+}
+if (value  LOG_SIZE_MAX) {
+error_setg(errp, %s's value must be less than %ld,
+ str, LOG_SIZE_MAX);
+return false;
+}
+return true;
+}
+
+/*
+ * inspired from migration mechanism
+ */
+
+static BitmapLogState *logging_current_state(void)
+{
+static BitmapLogState current_bitmaplogstate = {
+.state = LOG_BITMAP_STATE_NONE,
+};
+
+return current_bitmaplogstate;
+}
+
+/*
+ * syncing the logging_bitmap with the ram_list dirty bitmap
+ */
+
+static void 

[Qemu-devel] [PULL 04/23] nbd: Miscellaneous typo fixes.

2014-05-26 Thread Michael Tokarev
From: Hani Benhabiles kroo...@gmail.com

Signed-off-by: Hani Benhabiles h...@linux.com
Acked-by: Paolo Bonzini pbonz...@redhat.com
Reviewed-by: Stefan Hajnoczi stefa...@redhat.com
Signed-off-by: Michael Tokarev m...@tls.msk.ru
---
 nbd.c |2 +-
 qemu-nbd.c|2 +-
 qemu-nbd.texi |2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/nbd.c b/nbd.c
index e5084b6..e0d032c 100644
--- a/nbd.c
+++ b/nbd.c
@@ -306,7 +306,7 @@ static int nbd_send_negotiate(NBDClient *client)
 [ 8 ..  15]   magic(NBD_CLIENT_MAGIC)
 [16 ..  23]   size
 [24 ..  25]   server flags (0)
-[24 ..  27]   export flags
+[26 ..  27]   export flags
 [28 .. 151]   reserved (0)
 
Negotiation header with options, part 1:
diff --git a/qemu-nbd.c b/qemu-nbd.c
index f70e4b0..cd6bd50 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -294,7 +294,7 @@ static void *nbd_client_thread(void *arg)
 fd = open(device, O_RDWR);
 if (fd  0) {
 /* Linux-only, we can use %m in printf.  */
-fprintf(stderr, Failed to open %s: %m, device);
+fprintf(stderr, Failed to open %s: %m\n, device);
 goto out_socket;
 }
 
diff --git a/qemu-nbd.texi b/qemu-nbd.texi
index 0a7e013..46fd483 100644
--- a/qemu-nbd.texi
+++ b/qemu-nbd.texi
@@ -15,7 +15,7 @@ Export QEMU disk image using NBD protocol.
 @item @var{filename}
  is a disk image filename
 @item -p, --port=@var{port}
-  port to listen on (default @samp{1024})
+  port to listen on (default @samp{10809})
 @item -o, --offset=@var{offset}
   offset into the image
 @item -b, --bind=@var{iface}
-- 
1.7.10.4




[Qemu-devel] [PULL 00/23] Trivial patches for 2014-05-26

2014-05-26 Thread Michael Tokarev
Here's another trivial patches pull request.

This time it accumulated 23 patches, in many areas, with a focus,
for some reason, on libcacard, which received quite some cleanups
and a fix for a fun bug.

More interesting changes this time are by Peter Maydell, -- these
are the bswap.h macros renaming and using a subdir in curdir for
temporaries.

Please consider applying.

/mjt

The following changes since commit 6054d883d6138bfc92c73a7c090c824b64086fd2:

  Merge remote-tracking branch 'remotes/kraxel/tags/pull-chardev-2' into 
staging (2014-05-22 18:14:01 +0100)

are available in the git repository at:


  git://git.corpit.ru/qemu.git tags/trivial-patches-2014-05-26

for you to fetch changes up to 1687a089f103f9b7a1b4a1555068054cb46ee9e9:

  libcacard: remove useless initializers (2014-05-26 10:41:22 +0400)


trivial patches for 2014-05-26


Dr. David Alan Gilbert (1):
  vl: fix 'name' option to work with -readconfig

Hani Benhabiles (2):
  nbd: Close socket on negotiation failure.
  nbd: Miscellaneous typo fixes.

Jules Wang (1):
  dma-helpers: avoid calling dma_bdrv_unmap() twice

Le Tan (3):
  arch_init: replace fprintf(stderr, ...) with error_report()
  audio: replace fprintf(stderr, ...) with error_report() in audio
  bsd-user: replace fprintf(stderr, ...) with error_report()

Markus Armbruster (6):
  libcacard/vscclient: Bury some dead code
  libcacard: Plug memory leaks around vreader_get_reader_list()
  libcacard/vreader: Drop broken recovery from failed assertion
  libcacard/vreader: Tighten assertion to clarify intent
  libcacard: Convert two leftover realloc() to GLib
  libcacard/vcard_emul_nss: Drop a redundant conditional

Michael Tokarev (3):
  libcacard: g_malloc cleanups
  libcacard: fix wrong array expansion logic
  libcacard: remove useless initializers

Peter Crosthwaite (1):
  net: cadence_gem: Fix top comment

Peter Maydell (3):
  iohandler.c: Properly initialize sigaction struct
  bswap.h: Rename ldl_p, stl_p, etc to ldl_he_p, stl_he_p, etc
  configure: Put tempfiles in a subdir of the build directory

Saravanakumar (2):
  jazz_led: Add missing break in switch case
  pci: move dereferencing of root only after verifying valid root pointer

Stefan Weil (1):
  configure: Automatically select GTK+ 3.0 if GTK+ 2.0 is unavailable

 .gitignore |1 +
 arch_init.c|   32 +--
 audio/spiceaudio.c |2 +-
 audio/wavcapture.c |3 +--
 blockdev-nbd.c |4 ++--
 bsd-user/bsdload.c |2 +-
 bsd-user/elfload.c |2 +-
 bsd-user/main.c|   14 ++--
 configure  |   51 ++--
 dma-helpers.c  |2 +-
 hw/display/jazz_led.c  |1 +
 hw/net/cadence_gem.c   |2 +-
 hw/pci/pci.c   |4 ++--
 include/qemu/bswap.h   |   45 +++---
 iohandler.c|1 +
 libcacard/cac.c|   38 +++--
 libcacard/card_7816.c  |   16 ++
 libcacard/event.c  |2 +-
 libcacard/vcard.c  |   26 ++
 libcacard/vcard_emul_nss.c |   39 +++--
 libcacard/vreader.c|   31 +++
 libcacard/vscclient.c  |   11 +-
 nbd.c  |2 +-
 qemu-nbd.c |6 --
 qemu-nbd.texi  |2 +-
 vl.c   |9 ++--
 26 files changed, 167 insertions(+), 181 deletions(-)



[Qemu-devel] [PULL 02/23] iohandler.c: Properly initialize sigaction struct

2014-05-26 Thread Michael Tokarev
From: Peter Maydell peter.mayd...@linaro.org

The code in qemu_init_child_watch() wasn't clearing the 'struct
sigaction' before passing it to sigaction(); this meant that we
would block a random set of signals while executing the SIGCHLD
handler. Initialize properly by using memset() on the struct,
as we do in similar cases elsewhere.

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Michael Tokarev m...@tls.msk.ru
---
 iohandler.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/iohandler.c b/iohandler.c
index ae2ef8f..cca614f 100644
--- a/iohandler.c
+++ b/iohandler.c
@@ -191,6 +191,7 @@ static void qemu_init_child_watch(void)
 struct sigaction act;
 sigchld_bh = qemu_bh_new(sigchld_bh_handler, NULL);
 
+memset(act, 0, sizeof(act));
 act.sa_handler = sigchld_handler;
 act.sa_flags = SA_NOCLDSTOP;
 sigaction(SIGCHLD, act, NULL);
-- 
1.7.10.4




[Qemu-devel] [PULL 01/23] libcacard: g_malloc cleanups

2014-05-26 Thread Michael Tokarev
This patch replaces g_malloc() in libcacard into g_new()
or g_new0() where appropriate (removing some init-to-zero
surrounding code), g_malloc+memcpy into g_memdup() and the
like.

Signed-off-by: Michael Tokarev m...@tls.msk.ru
Reviewed-by: Alon Levy al...@redhat.com
---
 libcacard/cac.c|   11 +++
 libcacard/card_7816.c  |   11 +--
 libcacard/event.c  |2 +-
 libcacard/vcard.c  |   22 +-
 libcacard/vcard_emul_nss.c |   12 ++--
 libcacard/vreader.c|   11 +++
 6 files changed, 23 insertions(+), 46 deletions(-)

diff --git a/libcacard/cac.c b/libcacard/cac.c
index 74ef3e3..122129e 100644
--- a/libcacard/cac.c
+++ b/libcacard/cac.c
@@ -310,16 +310,11 @@ static VCardAppletPrivate *
 cac_new_pki_applet_private(const unsigned char *cert,
int cert_len, VCardKey *key)
 {
-CACPKIAppletData *pki_applet_data = NULL;
-VCardAppletPrivate *applet_private = NULL;
-applet_private = (VCardAppletPrivate 
*)g_malloc(sizeof(VCardAppletPrivate));
+CACPKIAppletData *pki_applet_data;
+VCardAppletPrivate *applet_private;
 
+applet_private = g_new0(VCardAppletPrivate, 1);
 pki_applet_data = (applet_private-u.pki_data);
-pki_applet_data-cert_buffer = NULL;
-pki_applet_data-cert_buffer_len = 0;
-pki_applet_data-sign_buffer = NULL;
-pki_applet_data-sign_buffer_len = 0;
-pki_applet_data-key = NULL;
 pki_applet_data-cert = (unsigned char *)g_malloc(cert_len+1);
 /*
  * if we want to support compression, then we simply change the 0 to a 1
diff --git a/libcacard/card_7816.c b/libcacard/card_7816.c
index c28bb60..bca8c4a 100644
--- a/libcacard/card_7816.c
+++ b/libcacard/card_7816.c
@@ -51,7 +51,7 @@ vcard_response_new_data(unsigned char *buf, int len)
 {
 VCardResponse *new_response;
 
-new_response = (VCardResponse *)g_malloc(sizeof(VCardResponse));
+new_response = g_new(VCardResponse, 1);
 new_response-b_data = g_malloc(len + 2);
 memcpy(new_response-b_data, buf, len);
 new_response-b_total_len = len+2;
@@ -132,7 +132,7 @@ vcard_response_new_status(vcard_7816_status_t status)
 {
 VCardResponse *new_response;
 
-new_response = (VCardResponse *)g_malloc(sizeof(VCardResponse));
+new_response = g_new(VCardResponse, 1);
 new_response-b_data = new_response-b_sw1;
 new_response-b_len = 0;
 new_response-b_total_len = 2;
@@ -149,7 +149,7 @@ vcard_response_new_status_bytes(unsigned char sw1, unsigned 
char sw2)
 {
 VCardResponse *new_response;
 
-new_response = (VCardResponse *)g_malloc(sizeof(VCardResponse));
+new_response = g_new(VCardResponse, 1);
 new_response-b_data = new_response-b_sw1;
 new_response-b_len = 0;
 new_response-b_total_len = 2;
@@ -336,9 +336,8 @@ vcard_apdu_new(unsigned char *raw_apdu, int len, 
vcard_7816_status_t *status)
 return NULL;
 }
 
-new_apdu = (VCardAPDU *)g_malloc(sizeof(VCardAPDU));
-new_apdu-a_data = g_malloc(len);
-memcpy(new_apdu-a_data, raw_apdu, len);
+new_apdu = g_new(VCardAPDU, 1);
+new_apdu-a_data = g_memdup(raw_apdu, len);
 new_apdu-a_len = len;
 *status = vcard_apdu_set_class(new_apdu);
 if (*status != VCARD7816_STATUS_SUCCESS) {
diff --git a/libcacard/event.c b/libcacard/event.c
index 2d7500f..a2e6c7d 100644
--- a/libcacard/event.c
+++ b/libcacard/event.c
@@ -17,7 +17,7 @@ vevent_new(VEventType type, VReader *reader, VCard *card)
 {
 VEvent *new_vevent;
 
-new_vevent = (VEvent *)g_malloc(sizeof(VEvent));
+new_vevent = g_new(VEvent, 1);
 new_vevent-next = NULL;
 new_vevent-type = type;
 new_vevent-reader = vreader_reference(reader);
diff --git a/libcacard/vcard.c b/libcacard/vcard.c
index 539177b..227e477 100644
--- a/libcacard/vcard.c
+++ b/libcacard/vcard.c
@@ -37,9 +37,8 @@ vcard_buffer_response_new(unsigned char *buffer, int size)
 {
 VCardBufferResponse *new_buffer;
 
-new_buffer = (VCardBufferResponse *)g_malloc(sizeof(VCardBufferResponse));
-new_buffer-buffer = (unsigned char *)g_malloc(size);
-memcpy(new_buffer-buffer, buffer, size);
+new_buffer = g_new(VCardBufferResponse, 1);
+new_buffer-buffer = (unsigned char *)g_memdup(buffer, size);
 new_buffer-buffer_len = size;
 new_buffer-current = new_buffer-buffer;
 new_buffer-len = size;
@@ -102,15 +101,11 @@ vcard_new_applet(VCardProcessAPDU applet_process_function,
 {
 VCardApplet *applet;
 
-applet = (VCardApplet *)g_malloc(sizeof(VCardApplet));
-applet-next = NULL;
-applet-applet_private = NULL;
-applet-applet_private_free = NULL;
+applet = g_new0(VCardApplet, 1);
 applet-process_apdu = applet_process_function;
 applet-reset_applet = applet_reset_function;
 
-applet-aid = g_malloc(aid_len);
-memcpy(applet-aid, aid, aid_len);
+applet-aid = g_memdup(aid, aid_len);
 applet-aid_len = aid_len;
 return applet;
 }
@@ -149,18 +144,11 @@ VCard *
 

[Qemu-devel] [PULL 07/23] jazz_led: Add missing break in switch case

2014-05-26 Thread Michael Tokarev
From: Saravanakumar saravanakumar.pun...@gmail.com

Signed-off-by: Saravanakumar saravanakumar.pun...@gmail.com
Reviewed-by: Paolo Bonizni pbonz...@redhat.com
Signed-off-by: Michael Tokarev m...@tls.msk.ru
---
 hw/display/jazz_led.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/display/jazz_led.c b/hw/display/jazz_led.c
index e9bb005..12b1707 100644
--- a/hw/display/jazz_led.c
+++ b/hw/display/jazz_led.c
@@ -173,6 +173,7 @@ static void jazz_led_update_display(void *opaque)
 case 16:
 color_segment = rgb_to_pixel16(0xaa, 0xaa, 0xaa);
 color_led = rgb_to_pixel16(0x00, 0xff, 0x00);
+break;
 case 24:
 color_segment = rgb_to_pixel24(0xaa, 0xaa, 0xaa);
 color_led = rgb_to_pixel24(0x00, 0xff, 0x00);
-- 
1.7.10.4




[Qemu-devel] [PULL 05/23] configure: Automatically select GTK+ 3.0 if GTK+ 2.0 is unavailable

2014-05-26 Thread Michael Tokarev
From: Stefan Weil s...@weilnetz.de

The configure option --with-gtkabi=3.0 is still supported, but no longer
needed when GTK+-2.0 is missing. When no GTK+ ABI is selected by the
user, configure first tries 2.0, then 3.0.

For some platforms (e.g. Windows) newer binaries of GTK+ are only
available for GTK+ 3.0. Now building on these platforms is a little bit
easier.

Signed-off-by: Stefan Weil s...@weilnetz.de
Signed-off-by: Michael Tokarev m...@tls.msk.ru
---
 configure |   22 +++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index 605a0ec..678a106 100755
--- a/configure
+++ b/configure
@@ -317,7 +317,7 @@ glusterfs_discard=no
 glusterfs_zerofill=no
 virtio_blk_data_plane=
 gtk=
-gtkabi=2.0
+gtkabi=
 vte=
 tpm=no
 libssh2=
@@ -1970,6 +1970,18 @@ fi
 ##
 # GTK probe
 
+if test $gtkabi = ; then
+# The GTK ABI was not specified explicitly, so try whether 2.0 is 
available.
+# Use 3.0 as a fallback if that is available.
+if $pkg_config --exists gtk+-2.0 = 2.18.0; then
+gtkabi=2.0
+elif $pkg_config --exists gtk+-3.0 = 3.0.0; then
+gtkabi=3.0
+else
+gtkabi=2.0
+fi
+fi
+
 if test $gtk != no; then
 gtkpackage=gtk+-$gtkabi
 if test $gtkabi = 3.0 ; then
@@ -1983,7 +1995,7 @@ if test $gtk != no; then
 libs_softmmu=$gtk_libs $libs_softmmu
 gtk=yes
 elif test $gtk = yes; then
-feature_not_found gtk Install gtk2 or gtk3 (requires 
--with-gtkabi=3.0 option to configure) devel
+feature_not_found gtk Install gtk2 or gtk3 devel
 else
 gtk=no
 fi
@@ -2006,7 +2018,11 @@ if test $vte != no; then
 libs_softmmu=$vte_libs $libs_softmmu
 vte=yes
 elif test $vte = yes; then
-feature_not_found vte Install libvte or libvte-2.90 (requires 
--with-gtkabi=3.0 option to configure) devel
+if test $gtkabi = 3.0; then
+feature_not_found vte Install libvte-2.90 devel
+else
+feature_not_found vte Install libvte devel
+fi
 else
 vte=no
 fi
-- 
1.7.10.4




[Qemu-devel] [PULL 13/23] libcacard/vscclient: Bury some dead code

2014-05-26 Thread Michael Tokarev
From: Markus Armbruster arm...@redhat.com

Spotted by Coverity.

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Alon Levy al...@redhat.com
Signed-off-by: Michael Tokarev m...@tls.msk.ru
---
 libcacard/vscclient.c |6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/libcacard/vscclient.c b/libcacard/vscclient.c
index 3477ab3..29f4958 100644
--- a/libcacard/vscclient.c
+++ b/libcacard/vscclient.c
@@ -502,8 +502,7 @@ do_command(GIOChannel *source,
 if (reader != NULL) {
 error = vcard_emul_force_card_insert(reader);
 printf(insert %s, returned %d\n,
-   reader ? vreader_get_name(reader)
-   : invalid reader, error);
+   vreader_get_name(reader), error);
 } else {
 printf(no reader by id %u found\n, reader_id);
 }
@@ -515,8 +514,7 @@ do_command(GIOChannel *source,
 if (reader != NULL) {
 error = vcard_emul_force_card_remove(reader);
 printf(remove %s, returned %d\n,
-reader ? vreader_get_name(reader)
-: invalid reader, error);
+   vreader_get_name(reader), error);
 } else {
 printf(no reader by id %u found\n, reader_id);
 }
-- 
1.7.10.4




[Qemu-devel] [PULL 19/23] libcacard: fix wrong array expansion logic

2014-05-26 Thread Michael Tokarev
The currrent code in libcacard/vcard_emul_nss.c:vcard_emul_options()
has a weird bug in variable usage around expanding opts-vreader
array.

There's a helper variable, vreaderOpt, which is first needlessly
initialized to NULL, next, conditionally, only we have to expand
opts-vreader, receives array expansion from g_renew(), and next,
even if we don't actually perform expansion, the value of this
variable is assigned to the actual array, opts-vreader, which
was supposed to be expanded.

So, since we expand the array by READER_STEP increments, only
once in READER_STEP (=4) the code will work, in other 3/4 times
it will fail badly.

Fix this by not using this temp variable when expanding the
array, and by dropping the useless =NULL initializer too -
if it wasn't in place initially, compiler would have warned
us about this problem at the beginning.

Signed-off-by: Michael Tokarev m...@tls.msk.ru
Reviewed-by: Markus Armbruster arm...@redhat.com
---
 libcacard/vcard_emul_nss.c |9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c
index b7db51d..8462aef 100644
--- a/libcacard/vcard_emul_nss.c
+++ b/libcacard/vcard_emul_nss.c
@@ -1149,7 +1149,7 @@ vcard_emul_options(const char *args)
 char type_str[100];
 VCardEmulType type;
 int count, i;
-VirtualReaderOptions *vreaderOpt = NULL;
+VirtualReaderOptions *vreaderOpt;
 
 args = strip(args + 5);
 if (*args != '(') {
@@ -1173,11 +1173,10 @@ vcard_emul_options(const char *args)
 
 if (opts-vreader_count = reader_count) {
 reader_count += READER_STEP;
-vreaderOpt = g_renew(VirtualReaderOptions, opts-vreader,
- reader_count);
+opts-vreader = g_renew(VirtualReaderOptions, opts-vreader,
+reader_count);
 }
-opts-vreader = vreaderOpt;
-vreaderOpt = vreaderOpt[opts-vreader_count];
+vreaderOpt = opts-vreader[opts-vreader_count];
 vreaderOpt-name = g_strndup(name, name_length);
 vreaderOpt-vname = g_strndup(vname, vname_length);
 vreaderOpt-card_type = type;
-- 
1.7.10.4




[Qemu-devel] [PULL 10/23] dma-helpers: avoid calling dma_bdrv_unmap() twice

2014-05-26 Thread Michael Tokarev
From: Jules Wang junqing.w...@cs2c.com.cn

Calling dma_bdrv_unmap() twice is not necessary and may cause
potential problems if some code changes.

Signed-off-by: Jules Wang junqing.w...@cs2c.com.cn
Reviewed-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Michael Tokarev m...@tls.msk.ru
---
 dma-helpers.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/dma-helpers.c b/dma-helpers.c
index 5f421e9..53cbe92 100644
--- a/dma-helpers.c
+++ b/dma-helpers.c
@@ -143,12 +143,12 @@ static void dma_bdrv_cb(void *opaque, int ret)
 
 dbs-acb = NULL;
 dbs-sector_num += dbs-iov.size / 512;
-dma_bdrv_unmap(dbs);
 
 if (dbs-sg_cur_index == dbs-sg-nsg || ret  0) {
 dma_complete(dbs, ret);
 return;
 }
+dma_bdrv_unmap(dbs);
 
 while (dbs-sg_cur_index  dbs-sg-nsg) {
 cur_addr = dbs-sg-sg[dbs-sg_cur_index].base + dbs-sg_cur_byte;
-- 
1.7.10.4




[Qemu-devel] [PULL 08/23] pci: move dereferencing of root only after verifying valid root pointer

2014-05-26 Thread Michael Tokarev
From: Saravanakumar saravanakumar.pun...@gmail.com

Signed-off-by: Saravanakumar saravanakumar.pun...@gmail.com
Reviewed-by: Andreas Färber afaer...@suse.de
Reviewed-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Michael Tokarev m...@tls.msk.ru
---
 hw/pci/pci.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 22fe5ee..8d6a8d4 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -605,13 +605,13 @@ PCIBus *pci_get_bus_devfn(int *devfnp, PCIBus *root, 
const char *devaddr)
 int dom, bus;
 unsigned slot;
 
-assert(!root-parent_dev);
-
 if (!root) {
 fprintf(stderr, No primary PCI bus\n);
 return NULL;
 }
 
+assert(!root-parent_dev);
+
 if (!devaddr) {
 *devfnp = -1;
 return pci_find_bus_nr(root, 0);
-- 
1.7.10.4




[Qemu-devel] [PULL 21/23] bsd-user: replace fprintf(stderr, ...) with error_report()

2014-05-26 Thread Michael Tokarev
From: Le Tan tamlokv...@gmail.com

Replace fprintf(stderr,...) with error_report() in files bsd-user/*.
The trailing \ns of the @fmt argument have been removed
because @fmt of error_report() should not contain newline.

Signed-off-by: Le Tan tamlokv...@gmail.com
Signed-off-by: Michael Tokarev m...@tls.msk.ru
---
 bsd-user/bsdload.c |2 +-
 bsd-user/elfload.c |2 +-
 bsd-user/main.c|   14 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/bsd-user/bsdload.c b/bsd-user/bsdload.c
index 2abc713..6b52e08 100644
--- a/bsd-user/bsdload.c
+++ b/bsd-user/bsdload.c
@@ -183,7 +183,7 @@ int loader_exec(const char * filename, char ** argv, char 
** envp,
  bprm.buf[3] == 'F') {
 retval = load_elf_binary(bprm,regs,infop);
 } else {
-fprintf(stderr, Unknown binary format\n);
+error_report(Unknown binary format);
 return -1;
 }
 }
diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c
index 93fd9e4..95652b1 100644
--- a/bsd-user/elfload.c
+++ b/bsd-user/elfload.c
@@ -628,7 +628,7 @@ static abi_ulong copy_elf_strings(int argc,char ** argv, 
void **page,
 while (argc--  0) {
 tmp = argv[argc];
 if (!tmp) {
-fprintf(stderr, VFS: argc is wrong);
+error_report(VFS: argc is wrong);
 exit(-1);
 }
 tmp1 = tmp;
diff --git a/bsd-user/main.c b/bsd-user/main.c
index 4ba61da..de74d17 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -378,8 +378,8 @@ void cpu_loop(CPUX86State *env)
 #endif
 default:
 pc = env-segs[R_CS].base + env-eip;
-fprintf(stderr, qemu: 0x%08lx: unhandled CPU exception 0x%x - 
aborting\n,
-(long)pc, trapnr);
+error_report(qemu: 0x%08lx: unhandled CPU exception 0x%x
+  - aborting, (long)pc, trapnr);
 abort();
 }
 process_pending_signals(env);
@@ -752,7 +752,7 @@ int main(int argc, char **argv)
 module_call_init(MODULE_INIT_QOM);
 
 if ((envlist = envlist_create()) == NULL) {
-(void) fprintf(stderr, Unable to allocate envlist\n);
+error_report(Unable to allocate envlist);
 exit(1);
 }
 
@@ -794,7 +794,7 @@ int main(int argc, char **argv)
 } else if (!strcmp(r, ignore-environment)) {
 envlist_free(envlist);
 if ((envlist = envlist_create()) == NULL) {
-(void) fprintf(stderr, Unable to allocate envlist\n);
+error_report(Unable to allocate envlist);
 exit(1);
 }
 } else if (!strcmp(r, U)) {
@@ -816,7 +816,7 @@ int main(int argc, char **argv)
 qemu_host_page_size = atoi(argv[optind++]);
 if (qemu_host_page_size == 0 ||
 (qemu_host_page_size  (qemu_host_page_size - 1)) != 0) {
-fprintf(stderr, page size must be a power of two\n);
+error_report(page size must be a power of two);
 exit(1);
 }
 } else if (!strcmp(r, g)) {
@@ -910,7 +910,7 @@ int main(int argc, char **argv)
qemu_host_page_size */
 env = cpu_init(cpu_model);
 if (!env) {
-fprintf(stderr, Unable to find CPU definition\n);
+error_report(Unable to find CPU definition);
 exit(1);
 }
 cpu = ENV_GET_CPU(env);
@@ -1012,7 +1012,7 @@ int main(int argc, char **argv)
 #ifndef TARGET_ABI32
 /* enable 64 bit mode if possible */
 if (!(env-features[FEAT_8000_0001_EDX]  CPUID_EXT2_LM)) {
-fprintf(stderr, The selected x86 CPU does not support 64 bit mode\n);
+error_report(The selected x86 CPU does not support 64 bit mode);
 exit(1);
 }
 env-cr[4] |= CR4_PAE_MASK;
-- 
1.7.10.4




[Qemu-devel] [PULL 20/23] audio: replace fprintf(stderr, ...) with error_report() in audio

2014-05-26 Thread Michael Tokarev
From: Le Tan tamlokv...@gmail.com

Replace fprintf(stderr,...) with error_report() in files audio/*.
The trailing \ns of the @fmt argument have been removed
because @fmt of error_report() should not contain newline.

Signed-off-by: Le Tan tamlokv...@gmail.com
Signed-off-by: Michael Tokarev m...@tls.msk.ru
---
 audio/spiceaudio.c |2 +-
 audio/wavcapture.c |3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/audio/spiceaudio.c b/audio/spiceaudio.c
index fceee50..7b79bed 100644
--- a/audio/spiceaudio.c
+++ b/audio/spiceaudio.c
@@ -105,7 +105,7 @@ static int rate_get_samples (struct audio_pcm_info *info, 
SpiceRateCtl *rate)
 bytes = muldiv64 (ticks, info-bytes_per_second, get_ticks_per_sec ());
 samples = (bytes - rate-bytes_sent)  info-shift;
 if (samples  0 || samples  65536) {
-fprintf (stderr, Resetting rate control (% PRId64  samples)\n, 
samples);
+error_report(Resetting rate control (% PRId64  samples), samples);
 rate_start (rate);
 samples = 0;
 }
diff --git a/audio/wavcapture.c b/audio/wavcapture.c
index 9d94623..6f6d792 100644
--- a/audio/wavcapture.c
+++ b/audio/wavcapture.c
@@ -63,8 +63,7 @@ static void wav_destroy (void *opaque)
 }
 doclose:
 if (fclose (wav-f)) {
-fprintf (stderr, wav_destroy: fclose failed: %s,
- strerror (errno));
+error_report(wav_destroy: fclose failed: %s, strerror(errno));
 }
 }
 
-- 
1.7.10.4




[Qemu-devel] [PULL 09/23] arch_init: replace fprintf(stderr, ...) with error_report()

2014-05-26 Thread Michael Tokarev
From: Le Tan tamlokv...@gmail.com

Replace fprintf(stderr,...) with error_report() in the file
arch_init.c. The trailing \ns of the @fmt argument have been removed
because @fmt of error_report() should not contain newline.

Signed-off-by: Le Tan tamlokv...@gmail.com
Reviewed-by: Andreas Färber afaer...@suse.de
Signed-off-by: Michael Tokarev m...@tls.msk.ru
---
 arch_init.c |   32 +++-
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 685ba0e..9f1a174 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -975,12 +975,12 @@ static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void 
*host)
 xh_len = qemu_get_be16(f);
 
 if (xh_flags != ENCODING_FLAG_XBZRLE) {
-fprintf(stderr, Failed to load XBZRLE page - wrong compression!\n);
+error_report(Failed to load XBZRLE page - wrong compression!);
 return -1;
 }
 
 if (xh_len  TARGET_PAGE_SIZE) {
-fprintf(stderr, Failed to load XBZRLE page - len overflow!\n);
+error_report(Failed to load XBZRLE page - len overflow!);
 return -1;
 }
 /* load data and decode */
@@ -989,7 +989,7 @@ static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void 
*host)
 /* decode RLE */
 if (xbzrle_decode_buffer(xbzrle_decoded_buf, xh_len, host,
  TARGET_PAGE_SIZE) == -1) {
-fprintf(stderr, Failed to load XBZRLE page - decode error!\n);
+error_report(Failed to load XBZRLE page - decode error!);
 return -1;
 }
 
@@ -1006,7 +1006,7 @@ static inline void *host_from_stream_offset(QEMUFile *f,
 
 if (flags  RAM_SAVE_FLAG_CONTINUE) {
 if (!block) {
-fprintf(stderr, Ack, bad migration stream!\n);
+error_report(Ack, bad migration stream!);
 return NULL;
 }
 
@@ -1022,7 +1022,7 @@ static inline void *host_from_stream_offset(QEMUFile *f,
 return memory_region_get_ram_ptr(block-mr) + offset;
 }
 
-fprintf(stderr, Can't find block %s!\n, id);
+error_report(Can't find block %s!, id);
 return NULL;
 }
 
@@ -1075,10 +1075,9 @@ static int ram_load(QEMUFile *f, void *opaque, int 
version_id)
 QTAILQ_FOREACH(block, ram_list.blocks, next) {
 if (!strncmp(id, block-idstr, sizeof(id))) {
 if (block-length != length) {
-fprintf(stderr,
-Length mismatch: %s:  RAM_ADDR_FMT
- in !=  RAM_ADDR_FMT \n, id, length,
-block-length);
+error_report(Length mismatch: %s:  RAM_ADDR_FMT
+  in !=  RAM_ADDR_FMT, id, length,
+ block-length);
 ret =  -EINVAL;
 goto done;
 }
@@ -1087,8 +1086,8 @@ static int ram_load(QEMUFile *f, void *opaque, int 
version_id)
 }
 
 if (!block) {
-fprintf(stderr, Unknown ramblock \%s\, cannot 
-accept migration\n, id);
+error_report(Unknown ramblock \%s\, cannot 
+ accept migration, id);
 ret = -EINVAL;
 goto done;
 }
@@ -1243,12 +1242,11 @@ void select_soundhw(const char *optarg)
 
 if (!c-name) {
 if (l  80) {
-fprintf(stderr,
-Unknown sound card name (too big to show)\n);
+error_report(Unknown sound card name (too big to show));
 }
 else {
-fprintf(stderr, Unknown sound card name `%.*s'\n,
-(int) l, p);
+error_report(Unknown sound card name `%.*s',
+ (int) l, p);
 }
 bad_card = 1;
 }
@@ -1271,13 +1269,13 @@ void audio_init(void)
 if (c-enabled) {
 if (c-isa) {
 if (!isa_bus) {
-fprintf(stderr, ISA bus not available for %s\n, c-name);
+error_report(ISA bus not available for %s, c-name);
 exit(1);
 }
 c-init.init_isa(isa_bus);
 } else {
 if (!pci_bus) {
-fprintf(stderr, PCI bus not available for %s\n, c-name);
+error_report(PCI bus not available for %s, c-name);
 exit(1);
 }
 c-init.init_pci(pci_bus);
-- 
1.7.10.4




[Qemu-devel] [PULL 14/23] libcacard: Plug memory leaks around vreader_get_reader_list()

2014-05-26 Thread Michael Tokarev
From: Markus Armbruster arm...@redhat.com

Spotted by Coverity.

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Alon Levy al...@redhat.com
Signed-off-by: Michael Tokarev m...@tls.msk.ru
---
 libcacard/vcard_emul_nss.c |4 
 libcacard/vscclient.c  |1 +
 2 files changed, 5 insertions(+)

diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c
index 75b9d79..7826593 100644
--- a/libcacard/vcard_emul_nss.c
+++ b/libcacard/vcard_emul_nss.c
@@ -433,11 +433,13 @@ vcard_emul_find_vreader_from_slot(PK11SlotInfo *slot)
 VReader *reader = vreader_list_get_reader(current_entry);
 VReaderEmul *reader_emul = vreader_get_private(reader);
 if (reader_emul-slot == slot) {
+vreader_list_delete(reader_list);
 return reader;
 }
 vreader_free(reader);
 }
 
+vreader_list_delete(reader_list);
 return NULL;
 }
 
@@ -1059,6 +1061,8 @@ vcard_emul_replay_insertion_events(void)
 next_entry = vreader_list_get_next(current_entry);
 vreader_queue_card_event(vreader);
 }
+
+vreader_list_delete(list);
 }
 
 /*
diff --git a/libcacard/vscclient.c b/libcacard/vscclient.c
index 29f4958..f2a753a 100644
--- a/libcacard/vscclient.c
+++ b/libcacard/vscclient.c
@@ -570,6 +570,7 @@ do_command(GIOChannel *source,
CARD_PRESENT : ,
vreader_get_name(reader));
 }
+vreader_list_delete(list);
 } else if (*string != 0) {
 printf(valid commands:\n);
 printf(insert [reader_id]\n);
-- 
1.7.10.4




[Qemu-devel] [PULL 16/23] libcacard/vreader: Tighten assertion to clarify intent

2014-05-26 Thread Michael Tokarev
From: Markus Armbruster arm...@redhat.com

Bonus: hushes up Coverity.

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Alon Levy al...@redhat.com
Signed-off-by: Michael Tokarev m...@tls.msk.ru
---
 libcacard/vreader.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcacard/vreader.c b/libcacard/vreader.c
index 93b01c8..f1288d9 100644
--- a/libcacard/vreader.c
+++ b/libcacard/vreader.c
@@ -283,7 +283,7 @@ vreader_xfr_bytes(VReader *reader,
   response-b_sw2, response-b_len, response-b_total_len);
 }
 }
-assert(card_status == VCARD_DONE);
+assert(card_status == VCARD_DONE  response);
 int size = MIN(*receive_buf_len, response-b_total_len);
 memcpy(receive_buf, response-b_data, size);
 *receive_buf_len = size;
-- 
1.7.10.4




[Qemu-devel] [PULL 15/23] libcacard/vreader: Drop broken recovery from failed assertion

2014-05-26 Thread Michael Tokarev
From: Markus Armbruster arm...@redhat.com

We suppress some code when we got unexpected status and assertion
checking is off:

 assert(card_status == VCARD_DONE);
 if (card_status == VCARD_DONE) {
 int size = MIN(*receive_buf_len, response-b_total_len);
 memcpy(receive_buf, response-b_data, size);
 *receive_buf_len = size;
}

Such recovery is of dubious value even when it works.  This one
doesn't: it fails to assign to receive_buf[] and *receive_buf_len,
which the callers expect.

Make the code unconditional.

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Alon Levy al...@redhat.com
Signed-off-by: Michael Tokarev m...@tls.msk.ru
---
 libcacard/vreader.c |8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/libcacard/vreader.c b/libcacard/vreader.c
index 9304a28..93b01c8 100644
--- a/libcacard/vreader.c
+++ b/libcacard/vreader.c
@@ -284,11 +284,9 @@ vreader_xfr_bytes(VReader *reader,
 }
 }
 assert(card_status == VCARD_DONE);
-if (card_status == VCARD_DONE) {
-int size = MIN(*receive_buf_len, response-b_total_len);
-memcpy(receive_buf, response-b_data, size);
-*receive_buf_len = size;
-}
+int size = MIN(*receive_buf_len, response-b_total_len);
+memcpy(receive_buf, response-b_data, size);
+*receive_buf_len = size;
 vcard_response_delete(response);
 vcard_apdu_delete(apdu);
 vcard_free(card); /* free our reference */
-- 
1.7.10.4




[Qemu-devel] [PULL 23/23] libcacard: remove useless initializers

2014-05-26 Thread Michael Tokarev
libcacard has many functions which initializes local variables
at declaration time, which are always assigned some values later
(often right after declaration).  Clean up these initializers.

Signed-off-by: Michael Tokarev m...@tls.msk.ru
---
 libcacard/cac.c|   14 +++---
 libcacard/card_7816.c  |5 ++---
 libcacard/vcard.c  |4 ++--
 libcacard/vcard_emul_nss.c |6 +++---
 libcacard/vreader.c|   10 +-
 libcacard/vscclient.c  |4 ++--
 6 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/libcacard/cac.c b/libcacard/cac.c
index 3887896..0a0163d 100644
--- a/libcacard/cac.c
+++ b/libcacard/cac.c
@@ -93,8 +93,8 @@ cac_common_process_apdu(VCard *card, VCardAPDU *apdu, 
VCardResponse **response)
 static VCardStatus
 cac_applet_pki_reset(VCard *card, int channel)
 {
-VCardAppletPrivate *applet_private = NULL;
-CACPKIAppletData *pki_applet = NULL;
+VCardAppletPrivate *applet_private;
+CACPKIAppletData *pki_applet;
 applet_private = vcard_get_current_applet_private(card, channel);
 assert(applet_private);
 pki_applet = (applet_private-u.pki_data);
@@ -113,8 +113,8 @@ static VCardStatus
 cac_applet_pki_process_apdu(VCard *card, VCardAPDU *apdu,
 VCardResponse **response)
 {
-CACPKIAppletData *pki_applet = NULL;
-VCardAppletPrivate *applet_private = NULL;
+CACPKIAppletData *pki_applet;
+VCardAppletPrivate *applet_private;
 int size, next;
 unsigned char *sign_buffer;
 vcard_7816_status_t status;
@@ -279,7 +279,7 @@ cac_applet_container_process_apdu(VCard *card, VCardAPDU 
*apdu,
 static void
 cac_delete_pki_applet_private(VCardAppletPrivate *applet_private)
 {
-CACPKIAppletData *pki_applet_data = NULL;
+CACPKIAppletData *pki_applet_data;
 
 if (applet_private == NULL) {
 return;
@@ -327,8 +327,8 @@ static VCardApplet *
 cac_new_pki_applet(int i, const unsigned char *cert,
int cert_len, VCardKey *key)
 {
-VCardAppletPrivate *applet_private = NULL;
-VCardApplet *applet = NULL;
+VCardAppletPrivate *applet_private;
+VCardApplet *applet;
 unsigned char pki_aid[] = { 0xa0, 0x00, 0x00, 0x00, 0x79, 0x01, 0x00 };
 int pki_aid_len = sizeof(pki_aid);
 
diff --git a/libcacard/card_7816.c b/libcacard/card_7816.c
index bca8c4a..a54f880 100644
--- a/libcacard/card_7816.c
+++ b/libcacard/card_7816.c
@@ -416,7 +416,7 @@ 
VCARD_RESPONSE_NEW_STATIC_STATUS(VCARD7816_STATUS_ERROR_GENERAL)
 VCardResponse *
 vcard_make_response(vcard_7816_status_t status)
 {
-VCardResponse *response = NULL;
+VCardResponse *response;
 
 switch (status) {
 /* known 7816 response codes */
@@ -543,9 +543,8 @@ vcard_make_response(vcard_7816_status_t status)
 return VCARD_RESPONSE_GET_STATIC(
 VCARD7816_STATUS_EXC_ERROR_MEMORY_FAILURE);
 }
+return response;
 }
-assert(response);
-return response;
 }
 
 /*
diff --git a/libcacard/vcard.c b/libcacard/vcard.c
index 227e477..6aaf085 100644
--- a/libcacard/vcard.c
+++ b/libcacard/vcard.c
@@ -166,8 +166,8 @@ vcard_reference(VCard *vcard)
 void
 vcard_free(VCard *vcard)
 {
-VCardApplet *current_applet = NULL;
-VCardApplet *next_applet = NULL;
+VCardApplet *current_applet;
+VCardApplet *next_applet;
 
 if (vcard == NULL) {
 return;
diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c
index 8462aef..cefc383 100644
--- a/libcacard/vcard_emul_nss.c
+++ b/libcacard/vcard_emul_nss.c
@@ -367,7 +367,7 @@ vcard_7816_status_t
 vcard_emul_login(VCard *card, unsigned char *pin, int pin_len)
 {
 PK11SlotInfo *slot;
-unsigned char *pin_string = NULL;
+unsigned char *pin_string;
 int i;
 SECStatus rv;
 
@@ -423,7 +423,7 @@ static VReader *
 vcard_emul_find_vreader_from_slot(PK11SlotInfo *slot)
 {
 VReaderList *reader_list = vreader_get_reader_list();
-VReaderListEntry *current_entry = NULL;
+VReaderListEntry *current_entry;
 
 if (reader_list == NULL) {
 return NULL;
@@ -1047,7 +1047,7 @@ void
 vcard_emul_replay_insertion_events(void)
 {
 VReaderListEntry *current_entry;
-VReaderListEntry *next_entry = NULL;
+VReaderListEntry *next_entry;
 VReaderList *list = vreader_get_reader_list();
 
 for (current_entry = vreader_list_get_first(list); current_entry;
diff --git a/libcacard/vreader.c b/libcacard/vreader.c
index f1288d9..d2a9b7d 100644
--- a/libcacard/vreader.c
+++ b/libcacard/vreader.c
@@ -339,7 +339,7 @@ void
 vreader_list_delete(VReaderList *list)
 {
 VReaderListEntry *current_entry;
-VReaderListEntry *next_entry = NULL;
+VReaderListEntry *next_entry;
 for (current_entry = vreader_list_get_first(list); current_entry;
  current_entry = next_entry) {
 next_entry = vreader_list_get_next(current_entry);
@@ -430,8 +430,8 @@ vreader_list_unlock(void)
 static VReaderList *
 

Re: [Qemu-devel] [Qemu-trivial] [PATCH net v1 0/4] Cadence GEM patches

2014-05-26 Thread Peter Crosthwaite
On Sat, May 24, 2014 at 5:17 PM, Michael Tokarev m...@tls.msk.ru wrote:
 24.05.2014 03:06, Peter Crosthwaite wrote:
 Ping^2!

 I'll try trivial queue too :)

 Actually this looks like trivial material.

 I'll comment in one place, for all.


 Peter Crosthwaite (4):
   net: cadence_gem: Fix Tx descriptor update

 This appears to be a bugfix, but with an interesting incomplete
 update:

 ...
 +unsigneddesc_first[2];
 ...
  cpu_physical_memory_read(s-tx_desc_addr,
 - (uint8_t *)desc[0], sizeof(desc));
 + (uint8_t *)desc_first[0], 
 sizeof(desc));

 sizeof(desc_first), not sizeof(desc).  Also can drop extra
 readdressing.


Fixed.

   net: cadence_gem: Add Tx descriptor fetch printf

 +DB_PRINT(read descriptor 0x%x\n, (unsigned)packet_desc_addr);

 packet_desc_addr is hwaddr, which is uint64_t, here it is being cast
 to unsigned,  Is it right?

Probably not.

  Other code in this file does the same,
 but it still does not mean it's right.  Maybe it is because it uses
 only the lower 32 bits of it, or that the high bits just aren't
 useful for debugging?


Well they are not useful because the IP is only 32-bit but converting
to HWADDR_PRIx because its probably the right thing to do anyway.

   net: cadence_gem: Fix top comment

 I applied this one.


Thanks.

Spinning V2. Thanks for review.

Regards,
Peter

   net: cadence_gem: Comment spelling sweep

 This look okay, except that it clashes a bit with the first.

 /mjt




Re: [Qemu-devel] [PATCH] input (curses): mask keycodes to remove modifier bits

2014-05-26 Thread Gerd Hoffmann
On Sa, 2014-05-24 at 11:02 +0400, Michael Tokarev wrote:
 24.05.2014 04:16, Andrew Oates wrote:
  Without the mask, control bits are passed on in the keycode, generating
  incorrect PS/2 sequences when SHIFT, ALT, etc are held down.
 
 While the patch itself appears to be trivial, it may have
 non-trivial effect.  Cc'ing Gerd for comments.

Patch is correct, picked it up.

cheers,
  Gerd




[Qemu-devel] [PULL 03/10] input: add name to input_event_key_number

2014-05-26 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 trace-events | 2 +-
 ui/input.c   | 6 --
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/trace-events b/trace-events
index b6d289d..0870204 100644
--- a/trace-events
+++ b/trace-events
@@ -1050,7 +1050,7 @@ gd_update(int x, int y, int w, int h) x=%d, y=%d, w=%d, 
h=%d
 gd_key_event(int gdk_keycode, int qemu_keycode, const char *action) 
translated GDK keycode %d to QEMU keycode %d (%s)
 
 # ui/input.c
-input_event_key_number(int conidx, int number, bool down) con %d, key number 
0x%x, down %d
+input_event_key_number(int conidx, int number, const char *qcode, bool down) 
con %d, key number 0x%x [%s], down %d
 input_event_key_qcode(int conidx, const char *qcode, bool down) con %d, key 
qcode %s, down %d
 input_event_btn(int conidx, const char *btn, bool down) con %d, button %s, 
down %d
 input_event_rel(int conidx, const char *axis, int value) con %d, axis %s, 
value %d
diff --git a/ui/input.c b/ui/input.c
index fc91fba..9d63035 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -94,7 +94,7 @@ static void qemu_input_transform_abs_rotate(InputEvent *evt)
 static void qemu_input_event_trace(QemuConsole *src, InputEvent *evt)
 {
 const char *name;
-int idx = -1;
+int qcode, idx = -1;
 
 if (src) {
 idx = qemu_console_get_index(src);
@@ -103,8 +103,10 @@ static void qemu_input_event_trace(QemuConsole *src, 
InputEvent *evt)
 case INPUT_EVENT_KIND_KEY:
 switch (evt-key-key-kind) {
 case KEY_VALUE_KIND_NUMBER:
+qcode = qemu_input_key_number_to_qcode(evt-key-key-number);
+name = QKeyCode_lookup[qcode];
 trace_input_event_key_number(idx, evt-key-key-number,
- evt-key-down);
+ name, evt-key-down);
 break;
 case KEY_VALUE_KIND_QCODE:
 name = QKeyCode_lookup[evt-key-key-qcode];
-- 
1.8.3.1




[Qemu-devel] [PULL 09/10] usb: add input routing support for tablet and keyboard

2014-05-26 Thread Gerd Hoffmann
Add display property to the keyboard.
Add display and head properties to the tablet.

If properties are set bind device to the display specified to
setup input routing.

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

diff --git a/hw/usb/dev-hid.c b/hw/usb/dev-hid.c
index d097d93..67a57f1 100644
--- a/hw/usb/dev-hid.c
+++ b/hw/usb/dev-hid.c
@@ -47,6 +47,8 @@ typedef struct USBHIDState {
 USBEndpoint *intr;
 HIDState hid;
 uint32_t usb_version;
+char *display;
+uint32_t head;
 } USBHIDState;
 
 enum {
@@ -574,6 +576,9 @@ static int usb_hid_initfn(USBDevice *dev, int kind)
 usb_desc_init(dev);
 us-intr = usb_ep_get(dev, USB_TOKEN_IN, 1);
 hid_init(us-hid, kind, usb_hid_changed);
+if (us-display  us-hid.s) {
+qemu_input_handler_bind(us-hid.s, us-display, us-head, NULL);
+}
 return 0;
 }
 
@@ -653,6 +658,8 @@ static void usb_hid_class_initfn(ObjectClass *klass, void 
*data)
 
 static Property usb_tablet_properties[] = {
 DEFINE_PROP_UINT32(usb_version, USBHIDState, usb_version, 2),
+DEFINE_PROP_STRING(display, USBHIDState, display),
+DEFINE_PROP_UINT32(head, USBHIDState, head, 0),
 DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -696,6 +703,11 @@ static const TypeInfo usb_mouse_info = {
 .class_init= usb_mouse_class_initfn,
 };
 
+static Property usb_keyboard_properties[] = {
+DEFINE_PROP_STRING(display, USBHIDState, display),
+DEFINE_PROP_END_OF_LIST(),
+};
+
 static void usb_keyboard_class_initfn(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
@@ -706,6 +718,7 @@ static void usb_keyboard_class_initfn(ObjectClass *klass, 
void *data)
 uc-product_desc   = QEMU USB Keyboard;
 uc-usb_desc   = desc_keyboard;
 dc-vmsd = vmstate_usb_kbd;
+dc-props = usb_keyboard_properties;
 set_bit(DEVICE_CATEGORY_INPUT, dc-categories);
 }
 
-- 
1.8.3.1




[Qemu-devel] [PULL 01/10] input (curses): mask keycodes to remove modifier bits

2014-05-26 Thread Gerd Hoffmann
From: Andrew Oates and...@aoates.org

Without the mask, control bits are passed on in the keycode, generating
incorrect PS/2 sequences when SHIFT, ALT, etc are held down.

Cc: qemu-sta...@nongnu.org
Signed-off-by: Andrew Oates and...@aoates.org
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/curses.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ui/curses.c b/ui/curses.c
index b044790..de85f76 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -288,8 +288,8 @@ static void curses_refresh(DisplayChangeListener *dcl)
 qemu_input_event_send_key_number(NULL, GREY | ALT_CODE, true);
 }
 
-qemu_input_event_send_key_number(NULL, keycode, true);
-qemu_input_event_send_key_number(NULL, keycode, false);
+qemu_input_event_send_key_number(NULL, keycode  KEY_MASK, true);
+qemu_input_event_send_key_number(NULL, keycode  KEY_MASK, false);
 
 if (keycode  ALTGR) {
 qemu_input_event_send_key_number(NULL, GREY | ALT_CODE, false);
-- 
1.8.3.1




[Qemu-devel] [PULL 00/10] input: add event routing and multiseat support.

2014-05-26 Thread Gerd Hoffmann
  Hi,

Input layer continued:  Adding input routing for multiseat.
Also has some bugfixes.

please pull,
  Gerd

The following changes since commit 178ac111bca16c08a79b2609ebdc75197bea976a:

  Merge remote-tracking branch 'remotes/qmp-unstable/queue/qmp' into staging 
(2014-05-22 19:04:49 +0100)

are available in the git repository at:


  git://git.kraxel.org/qemu tags/pull-input-9

for you to fetch changes up to 8977bd111f62035b675d41c432eb8b6bf6b86b0f:

  docs: add multiseat.txt (2014-05-26 08:42:43 +0200)


input: add event routing and multiseat support.
input: misc bugfixes and minor improvements.


Andrew Oates (1):
  input (curses): mask keycodes to remove modifier bits

Gerd Hoffmann (9):
  input: add qemu_input_key_number_to_qcode
  input: add name to input_event_key_number
  input: keymap: add meta keys
  input: switch hid keyboard to new input layer api.
  input: switch hid mouse and tablet to the new input layer api.
  input: bind devices and input routing
  sdl: pass key event source to input layer
  usb: add input routing support for tablet and keyboard
  docs: add multiseat.txt

 docs/multiseat.txt |  76 +
 hw/input/hid.c | 220 -
 hw/usb/dev-hid.c   |  13 +++
 include/hw/input/hid.h |   4 +-
 include/ui/input.h |   4 +
 trace-events   |   2 +-
 ui/curses.c|   4 +-
 ui/input-keymap.c  |  13 ++-
 ui/input.c |  49 +--
 ui/sdl2.c  |  21 +++--
 10 files changed, 308 insertions(+), 98 deletions(-)
 create mode 100644 docs/multiseat.txt



[Qemu-devel] [PULL 04/10] input: keymap: add meta keys

2014-05-26 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/input-keymap.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ui/input-keymap.c b/ui/input-keymap.c
index 4c4f0d0..5d29935 100644
--- a/ui/input-keymap.c
+++ b/ui/input-keymap.c
@@ -13,6 +13,8 @@ static const int qcode_to_number[] = {
 [Q_KEY_CODE_CTRL] = 0x1d,
 [Q_KEY_CODE_CTRL_R] = 0x9d,
 
+[Q_KEY_CODE_META_L] = 0xdb,
+[Q_KEY_CODE_META_R] = 0xdc,
 [Q_KEY_CODE_MENU] = 0xdd,
 
 [Q_KEY_CODE_ESC] = 0x01,
-- 
1.8.3.1




[Qemu-devel] [PULL 02/10] input: add qemu_input_key_number_to_qcode

2014-05-26 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 include/ui/input.h |  1 +
 ui/input-keymap.c  | 11 ---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/include/ui/input.h b/include/ui/input.h
index 3d3d487..d84ed8b 100644
--- a/include/ui/input.h
+++ b/include/ui/input.h
@@ -36,6 +36,7 @@ InputEvent *qemu_input_event_new_key(KeyValue *key, bool 
down);
 void qemu_input_event_send_key(QemuConsole *src, KeyValue *key, bool down);
 void qemu_input_event_send_key_number(QemuConsole *src, int num, bool down);
 void qemu_input_event_send_key_qcode(QemuConsole *src, QKeyCode q, bool down);
+int qemu_input_key_number_to_qcode(uint8_t nr);
 int qemu_input_key_value_to_number(const KeyValue *value);
 int qemu_input_key_value_to_qcode(const KeyValue *value);
 int qemu_input_key_value_to_scancode(const KeyValue *value, bool down,
diff --git a/ui/input-keymap.c b/ui/input-keymap.c
index 6da4495..4c4f0d0 100644
--- a/ui/input-keymap.c
+++ b/ui/input-keymap.c
@@ -129,7 +129,7 @@ static const int qcode_to_number[] = {
 [Q_KEY_CODE_MAX] = 0,
 };
 
-static int number_to_qcode[0xff];
+static int number_to_qcode[0x100];
 
 int qemu_input_key_value_to_number(const KeyValue *value)
 {
@@ -141,7 +141,7 @@ int qemu_input_key_value_to_number(const KeyValue *value)
 }
 }
 
-int qemu_input_key_value_to_qcode(const KeyValue *value)
+int qemu_input_key_number_to_qcode(uint8_t nr)
 {
 static int first = true;
 
@@ -155,11 +155,16 @@ int qemu_input_key_value_to_qcode(const KeyValue *value)
 }
 }
 
+return number_to_qcode[nr];
+}
+
+int qemu_input_key_value_to_qcode(const KeyValue *value)
+{
 if (value-kind == KEY_VALUE_KIND_QCODE) {
 return value-qcode;
 } else {
 assert(value-kind == KEY_VALUE_KIND_NUMBER);
-return number_to_qcode[value-number];
+return qemu_input_key_number_to_qcode(value-number);
 }
 }
 
-- 
1.8.3.1




[Qemu-devel] [PULL 07/10] input: bind devices and input routing

2014-05-26 Thread Gerd Hoffmann
Add function to bind input devices to display devices.  Implementing
input routing on top of this:  Events coming from the display device in
question are routed to the input device bound to it (if there is one).

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 include/ui/input.h |  3 +++
 ui/input.c | 43 ---
 2 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/include/ui/input.h b/include/ui/input.h
index d84ed8b..aa99b0c 100644
--- a/include/ui/input.h
+++ b/include/ui/input.h
@@ -29,6 +29,9 @@ QemuInputHandlerState 
*qemu_input_handler_register(DeviceState *dev,
 void qemu_input_handler_activate(QemuInputHandlerState *s);
 void qemu_input_handler_deactivate(QemuInputHandlerState *s);
 void qemu_input_handler_unregister(QemuInputHandlerState *s);
+void qemu_input_handler_bind(QemuInputHandlerState *s,
+ const char *device_id, int head,
+ Error **errp);
 void qemu_input_event_send(QemuConsole *src, InputEvent *evt);
 void qemu_input_event_sync(void);
 
diff --git a/ui/input.c b/ui/input.c
index 9d63035..14c9434 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -1,3 +1,4 @@
+#include hw/qdev.h
 #include sysemu/sysemu.h
 #include qapi-types.h
 #include qmp-commands.h
@@ -10,6 +11,7 @@ struct QemuInputHandlerState {
 QemuInputHandler  *handler;
 int   id;
 int   events;
+QemuConsole   *con;
 QTAILQ_ENTRY(QemuInputHandlerState) node;
 };
 static QTAILQ_HEAD(, QemuInputHandlerState) handlers =
@@ -53,12 +55,46 @@ void qemu_input_handler_unregister(QemuInputHandlerState *s)
 qemu_input_check_mode_change();
 }
 
+void qemu_input_handler_bind(QemuInputHandlerState *s,
+ const char *device_id, int head,
+ Error **errp)
+{
+DeviceState *dev;
+QemuConsole *con;
+
+dev = qdev_find_recursive(sysbus_get_default(), device_id);
+if (dev == NULL) {
+error_set(errp, QERR_DEVICE_NOT_FOUND, device_id);
+return;
+}
+
+con = qemu_console_lookup_by_device(dev, head);
+if (con == NULL) {
+error_setg(errp, Device %s is not bound to a QemuConsole, device_id);
+return;
+}
+
+s-con = con;
+}
+
 static QemuInputHandlerState*
-qemu_input_find_handler(uint32_t mask)
+qemu_input_find_handler(uint32_t mask, QemuConsole *con)
 {
 QemuInputHandlerState *s;
 
 QTAILQ_FOREACH(s, handlers, node) {
+if (s-con == NULL || s-con != con) {
+continue;
+}
+if (mask  s-handler-mask) {
+return s;
+}
+}
+
+QTAILQ_FOREACH(s, handlers, node) {
+if (s-con != NULL) {
+continue;
+}
 if (mask  s-handler-mask) {
 return s;
 }
@@ -151,7 +187,7 @@ void qemu_input_event_send(QemuConsole *src, InputEvent 
*evt)
 }
 
 /* send event */
-s = qemu_input_find_handler(1  evt-kind);
+s = qemu_input_find_handler(1  evt-kind, src);
 if (!s) {
 return;
 }
@@ -252,7 +288,8 @@ bool qemu_input_is_absolute(void)
 {
 QemuInputHandlerState *s;
 
-s = qemu_input_find_handler(INPUT_EVENT_MASK_REL | INPUT_EVENT_MASK_ABS);
+s = qemu_input_find_handler(INPUT_EVENT_MASK_REL | INPUT_EVENT_MASK_ABS,
+NULL);
 return (s != NULL)  (s-handler-mask  INPUT_EVENT_MASK_ABS);
 }
 
-- 
1.8.3.1




[Qemu-devel] [PULL 05/10] input: switch hid keyboard to new input layer api.

2014-05-26 Thread Gerd Hoffmann
Minimal patch to get the switchover done.  We continue processing ps/2
scancodes for now as they are part of the live migration stream.  Fixing
that, then mapping directly from QKeyValue to HID keycodes is left as
excercise for another day.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/input/hid.c | 29 ++---
 include/hw/input/hid.h |  3 ++-
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/hw/input/hid.c b/hw/input/hid.c
index bb0fa6a..ff75e41 100644
--- a/hw/input/hid.c
+++ b/hw/input/hid.c
@@ -158,17 +158,24 @@ static void hid_pointer_event(void *opaque,
 hs-event(hs);
 }
 
-static void hid_keyboard_event(void *opaque, int keycode)
+static void hid_keyboard_event(DeviceState *dev, QemuConsole *src,
+   InputEvent *evt)
 {
-HIDState *hs = opaque;
+HIDState *hs = (HIDState *)dev;
+int scancodes[3], i, count;
 int slot;
 
-if (hs-n == QUEUE_LENGTH) {
+count = qemu_input_key_value_to_scancode(evt-key-key,
+ evt-key-down,
+ scancodes);
+if (hs-n + count  QUEUE_LENGTH) {
 fprintf(stderr, usb-kbd: warning: key event queue full\n);
 return;
 }
-slot = (hs-head + hs-n)  QUEUE_MASK; hs-n++;
-hs-kbd.keycodes[slot] = keycode;
+for (i = 0; i  count; i++) {
+slot = (hs-head + hs-n)  QUEUE_MASK; hs-n++;
+hs-kbd.keycodes[slot] = scancodes[i];
+}
 hs-event(hs);
 }
 
@@ -415,7 +422,7 @@ void hid_free(HIDState *hs)
 {
 switch (hs-kind) {
 case HID_KEYBOARD:
-qemu_remove_kbd_event_handler(hs-kbd.eh_entry);
+qemu_input_handler_unregister(hs-s);
 break;
 case HID_MOUSE:
 case HID_TABLET:
@@ -425,13 +432,21 @@ void hid_free(HIDState *hs)
 hid_del_idle_timer(hs);
 }
 
+static QemuInputHandler hid_keyboard_handler = {
+.name  = QEMU HID Keyboard,
+.mask  = INPUT_EVENT_MASK_KEY,
+.event = hid_keyboard_event,
+};
+
 void hid_init(HIDState *hs, int kind, HIDEventFunc event)
 {
 hs-kind = kind;
 hs-event = event;
 
 if (hs-kind == HID_KEYBOARD) {
-hs-kbd.eh_entry = qemu_add_kbd_event_handler(hid_keyboard_event, hs);
+hs-s = qemu_input_handler_register((DeviceState *)hs,
+hid_keyboard_handler);
+qemu_input_handler_activate(hs-s);
 } else if (hs-kind == HID_MOUSE) {
 hs-ptr.eh_entry = qemu_add_mouse_event_handler(hid_pointer_event, hs,
 0, QEMU HID Mouse);
diff --git a/include/hw/input/hid.h b/include/hw/input/hid.h
index 2567879..fb913ba 100644
--- a/include/hw/input/hid.h
+++ b/include/hw/input/hid.h
@@ -2,6 +2,7 @@
 #define QEMU_HID_H
 
 #include migration/vmstate.h
+#include ui/input.h
 
 #define HID_MOUSE 1
 #define HID_TABLET2
@@ -31,7 +32,6 @@ typedef struct HIDKeyboardState {
 uint8_t leds;
 uint8_t key[16];
 int32_t keys;
-QEMUPutKbdEntry *eh_entry;
 } HIDKeyboardState;
 
 struct HIDState {
@@ -47,6 +47,7 @@ struct HIDState {
 bool idle_pending;
 QEMUTimer *idle_timer;
 HIDEventFunc event;
+QemuInputHandlerState *s;
 };
 
 void hid_init(HIDState *hs, int kind, HIDEventFunc event);
-- 
1.8.3.1




[Qemu-devel] [PULL 08/10] sdl: pass key event source to input layer

2014-05-26 Thread Gerd Hoffmann
So the input layer knows where the input is coming from
and input routing works correctly.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/sdl2.c | 21 -
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/ui/sdl2.c b/ui/sdl2.c
index 361de61..0e884f9 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -190,30 +190,33 @@ static void sdl_switch(DisplayChangeListener *dcl,
 }
 }
 
-static void reset_keys(void)
+static void reset_keys(struct sdl2_state *scon)
 {
+QemuConsole *con = scon ? scon-dcl.con : NULL;
 int i;
 
 for (i = 0; i  256; i++) {
 if (modifiers_state[i]) {
 int qcode = sdl2_scancode_to_qcode[i];
-qemu_input_event_send_key_qcode(NULL, qcode, false);
+qemu_input_event_send_key_qcode(con, qcode, false);
 modifiers_state[i] = 0;
 }
 }
 }
 
-static void sdl_process_key(SDL_KeyboardEvent *ev)
+static void sdl_process_key(struct sdl2_state *scon,
+SDL_KeyboardEvent *ev)
 {
 int qcode = sdl2_scancode_to_qcode[ev-keysym.scancode];
+QemuConsole *con = scon ? scon-dcl.con : NULL;
 
 switch (ev-keysym.scancode) {
 #if 0
 case SDL_SCANCODE_NUMLOCKCLEAR:
 case SDL_SCANCODE_CAPSLOCK:
 /* SDL does not send the key up event, so we generate it */
-qemu_input_event_send_key_qcode(NULL, qcode, true);
-qemu_input_event_send_key_qcode(NULL, qcode, false);
+qemu_input_event_send_key_qcode(con, qcode, true);
+qemu_input_event_send_key_qcode(con, qcode, false);
 return;
 #endif
 case SDL_SCANCODE_LCTRL:
@@ -231,7 +234,7 @@ static void sdl_process_key(SDL_KeyboardEvent *ev)
 }
 /* fall though */
 default:
-qemu_input_event_send_key_qcode(NULL, qcode,
+qemu_input_event_send_key_qcode(con, qcode,
 ev-type == SDL_KEYDOWN);
 }
 }
@@ -506,7 +509,7 @@ static void handle_keydown(SDL_Event *ev)
 }
 }
 if (!gui_keysym) {
-sdl_process_key(ev-key);
+sdl_process_key(scon, ev-key);
 }
 }
 
@@ -531,13 +534,13 @@ static void handle_keyup(SDL_Event *ev)
 }
 /* SDL does not send back all the modifiers key, so we must
  * correct it. */
-reset_keys();
+reset_keys(scon);
 return;
 }
 gui_keysym = 0;
 }
 if (!gui_keysym) {
-sdl_process_key(ev-key);
+sdl_process_key(scon, ev-key);
 }
 }
 
-- 
1.8.3.1




[Qemu-devel] [PULL 06/10] input: switch hid mouse and tablet to the new input layer api.

2014-05-26 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/input/hid.c | 193 +++--
 include/hw/input/hid.h |   1 -
 2 files changed, 123 insertions(+), 71 deletions(-)

diff --git a/hw/input/hid.c b/hw/input/hid.c
index ff75e41..295bdab 100644
--- a/hw/input/hid.c
+++ b/hw/input/hid.c
@@ -105,57 +105,115 @@ void hid_set_next_idle(HIDState *hs)
 }
 }
 
-static void hid_pointer_event_clear(HIDPointerEvent *e, int buttons)
+static void hid_pointer_event(DeviceState *dev, QemuConsole *src,
+  InputEvent *evt)
 {
-e-xdx = e-ydy = e-dz = 0;
-e-buttons_state = buttons;
-}
+static const int bmap[INPUT_BUTTON_MAX] = {
+[INPUT_BUTTON_LEFT]   = 0x01,
+[INPUT_BUTTON_RIGHT]  = 0x02,
+[INPUT_BUTTON_MIDDLE] = 0x04,
+};
+HIDState *hs = (HIDState *)dev;
+HIDPointerEvent *e;
 
-static void hid_pointer_event_combine(HIDPointerEvent *e, int xyrel,
-  int x1, int y1, int z1) {
-if (xyrel) {
-e-xdx += x1;
-e-ydy += y1;
-} else {
-e-xdx = x1;
-e-ydy = y1;
-/* Windows drivers do not like the 0/0 position and ignore such
- * events. */
-if (!(x1 | y1)) {
-e-xdx = 1;
+assert(hs-n  QUEUE_LENGTH);
+e = hs-ptr.queue[(hs-head + hs-n)  QUEUE_MASK];
+
+switch (evt-kind) {
+case INPUT_EVENT_KIND_REL:
+if (evt-rel-axis == INPUT_AXIS_X) {
+e-xdx += evt-rel-value;
+} else if (evt-rel-axis == INPUT_AXIS_Y) {
+e-ydy -= evt-rel-value;
+}
+break;
+
+case INPUT_EVENT_KIND_ABS:
+if (evt-rel-axis == INPUT_AXIS_X) {
+e-xdx = evt-rel-value;
+} else if (evt-rel-axis == INPUT_AXIS_Y) {
+e-ydy = evt-rel-value;
+}
+break;
+
+case INPUT_EVENT_KIND_BTN:
+if (evt-btn-down) {
+e-buttons_state |= bmap[evt-btn-button];
+if (evt-btn-button == INPUT_BUTTON_WHEEL_UP) {
+e-dz--;
+} else if (evt-btn-button == INPUT_BUTTON_WHEEL_DOWN) {
+e-dz++;
+}
+} else {
+e-buttons_state = ~bmap[evt-btn-button];
 }
+break;
+
+default:
+/* keep gcc happy */
+break;
 }
-e-dz += z1;
+
 }
 
-static void hid_pointer_event(void *opaque,
-  int x1, int y1, int z1, int buttons_state)
+static void hid_pointer_sync(DeviceState *dev)
 {
-HIDState *hs = opaque;
-unsigned use_slot = (hs-head + hs-n - 1)  QUEUE_MASK;
-unsigned previous_slot = (use_slot - 1)  QUEUE_MASK;
-
-/* We combine events where feasible to keep the queue small.  We shouldn't
- * combine anything with the first event of a particular button state, as
- * that would change the location of the button state change.  When the
- * queue is empty, a second event is needed because we don't know if
- * the first event changed the button state.  */
-if (hs-n == QUEUE_LENGTH) {
-/* Queue full.  Discard old button state, combine motion normally.  */
-hs-ptr.queue[use_slot].buttons_state = buttons_state;
-} else if (hs-n  2 ||
-   hs-ptr.queue[use_slot].buttons_state != buttons_state ||
-   hs-ptr.queue[previous_slot].buttons_state !=
-   hs-ptr.queue[use_slot].buttons_state) {
-/* Cannot or should not combine, so add an empty item to the queue.  */
-QUEUE_INCR(use_slot);
+HIDState *hs = (HIDState *)dev;
+HIDPointerEvent *prev, *curr, *next;
+bool event_compression = false;
+
+if (hs-n == QUEUE_LENGTH-1) {
+/*
+ * Queue full.  We are loosing information, but we at least
+ * keep track of most recent button state.
+ */
+return;
+}
+
+prev = hs-ptr.queue[(hs-head + hs-n - 1)  QUEUE_MASK];
+curr = hs-ptr.queue[(hs-head + hs-n)  QUEUE_MASK];
+next = hs-ptr.queue[(hs-head + hs-n + 1)  QUEUE_MASK];
+
+if (hs-n  0) {
+/*
+ * No button state change between previous and current event
+ * (and previous wasn't seen by the guest yet), so there is
+ * motion information only and we can combine the two event
+ * into one.
+ */
+if (curr-buttons_state == prev-buttons_state) {
+event_compression = true;
+}
+}
+
+if (event_compression) {
+/* add current motion to previous, clear current */
+if (hs-kind == HID_MOUSE) {
+prev-xdx += curr-xdx;
+curr-xdx = 0;
+prev-ydy -= curr-ydy;
+curr-ydy = 0;
+} else {
+prev-xdx = curr-xdx;
+prev-ydy = curr-ydy;
+}
+prev-dz += curr-dz;
+curr-dz = 0;
+} else {
+/* prepate next (clear rel, copy abs + btns) */
+if (hs-kind == HID_MOUSE) {
+next-xdx = 0;
+ 

[Qemu-devel] [PULL 10/10] docs: add multiseat.txt

2014-05-26 Thread Gerd Hoffmann
Howto on setting up multiseat for guests.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 docs/multiseat.txt | 76 ++
 1 file changed, 76 insertions(+)
 create mode 100644 docs/multiseat.txt

diff --git a/docs/multiseat.txt b/docs/multiseat.txt
new file mode 100644
index 000..a6c71dd
--- /dev/null
+++ b/docs/multiseat.txt
@@ -0,0 +1,76 @@
+
+multiseat howto (with some multihead coverage)
+==
+
+host side
+-
+
+First you must compile qemu with a user interface supporting
+multihead/multiseat and input event routing.  Right now this list is
+pretty short: sdl2.
+
+  ./configure --enable-sdl --with-sdlabi=2.0
+
+
+Next put together the qemu command line:
+
+qemu   -enable-kvm -usb $memory $disk $whatever \
+   -display sdl \
+   -vga std \
+   -device usb-tablet
+
+That is it for the first head, which will use the standard vga, the
+standard ps/2 keyboard (implicitly there) and the usb-tablet.  Now the
+additional switches for the second head:
+
+   -device pci-bridge,addr=12.0,chassis_nr=2,id=head.2 \
+   -device secondary-vga,bus=head.2,addr=02.0,id=video.2 \
+   -device nec-usb-xhci,bus=head.2,addr=0f.0,id=usb.2 \
+   -device usb-kbd,bus=usb.2.0,port=1,display=video.2 \
+   -device usb-tablet,bus=usb.2.0,port=2,display=video.2
+
+This places a pci bridge in slot 12, connects a display adapter and
+xhci (usb) controller to the bridge.  Then it adds a usb keyboard and
+usb mouse, both connected to the xhci and linked to the display.
+
+The display=video2 sets up the input routing.  Any input coming from
+the window which belongs to the video.2 display adapter will be routed
+to these input devices.
+
+
+guest side
+--
+
+You need a pretty recent linux guest.  systemd with loginctl.  kernel
+3.14+ with CONFIG_DRM_BOCHS enabled.  Fedora 20 will do.  Must be
+fully updated for the new kernel though, i.e. the live iso doesn't cut
+it.
+
+Now we'll have to configure the guest.  Boot and login.  By default
+all devices belong to seat0.  You can use loginctl seat-status seat0
+to list them all (and to get the sysfs paths for cut+paste).  Now
+we'll go assign all pci devices connected the pci bridge in slot 12 to
+a new head:
+
+loginctl attach seat-qemu \
+/sys/devices/pci:00/:00:12.0/:01:02.0/drm/card1
+loginctl attach seat-qemu \
+/sys/devices/pci:00/:00:12.0/:01:02.0/graphics/fb1
+loginctl attach seat-qemu \
+/sys/devices/pci:00/:00:12.0/:01:0f.0/usb2
+
+Use loginctl seat-status seat-qemu to check the result.  It isn't
+needed to assign the usb devices to the head individually, assigning a
+usb (root) hub will automatically assign all usb devices connected to
+it too.
+
+BTW: loginctl writes udev rules to /etc/udev/rules.d to make these
+device assignments permanent, so you need to do this only once.
+
+Now simply restart gdm (rebooting will do too), and a login screen
+should show up on the second head.
+
+Enjoy!
+
+--
+Gerd Hoffmann kra...@redhat.com
-- 
1.8.3.1




[Qemu-devel] [PULL 12/23] vl: fix 'name' option to work with -readconfig

2014-05-26 Thread Michael Tokarev
From: Dr. David Alan Gilbert dgilb...@redhat.com

The 'name' option silently failed when used in config files
( http://lists.gnu.org/archive/html/qemu-devel/2014-04/msg00378.html )

-readconfig stores the configuration read in QemuOpts.  Command line
option parsing should do the same, and no more.  In particular it should
not act upon the option.  That needs to be done separately, where both
command line and -readconfig settings are visible in QemuOpts.

Signed-off-by: Dr. David Alan Gilbert dgilb...@redhat.com
Reported-by: William Dauchy will...@gandi.net
Tested-by: William Dauchy will...@gandi.net
Reviewed-by: Markus Armbruster arm...@redhat.com
Signed-off-by: Michael Tokarev m...@tls.msk.ru
(mjt: added commit message by ambru@ and subject prefix)
---
 vl.c |9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/vl.c b/vl.c
index 709d8cd..99b6fc0 100644
--- a/vl.c
+++ b/vl.c
@@ -965,7 +965,7 @@ static int parse_sandbox(QemuOpts *opts, void *opaque)
 return 0;
 }
 
-static void parse_name(QemuOpts *opts)
+static int parse_name(QemuOpts *opts, void *opaque)
 {
 const char *proc_name;
 
@@ -978,6 +978,8 @@ static void parse_name(QemuOpts *opts)
 if (proc_name) {
 os_set_proc_name(proc_name);
 }
+
+return 0;
 }
 
 bool usb_enabled(bool default_usb)
@@ -3796,7 +3798,6 @@ int main(int argc, char **argv, char **envp)
 if (!opts) {
 exit(1);
 }
-parse_name(opts);
 break;
 case QEMU_OPTION_prom_env:
 if (nb_prom_envs = MAX_PROM_ENVS) {
@@ -3971,6 +3972,10 @@ int main(int argc, char **argv, char **envp)
 exit(1);
 }
 
+if (qemu_opts_foreach(qemu_find_opts(name), parse_name, NULL, 1)) {
+exit(1);
+}
+
 #ifndef _WIN32
 if (qemu_opts_foreach(qemu_find_opts(add-fd), parse_add_fd, NULL, 1)) {
 exit(1);
-- 
1.7.10.4




[Qemu-devel] [PULL 17/23] libcacard: Convert two leftover realloc() to GLib

2014-05-26 Thread Michael Tokarev
From: Markus Armbruster arm...@redhat.com

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Alon Levy al...@redhat.com
Signed-off-by: Michael Tokarev m...@tls.msk.ru
---
 libcacard/cac.c|   13 ++---
 libcacard/vcard_emul_nss.c |7 ++-
 2 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/libcacard/cac.c b/libcacard/cac.c
index 122129e..3887896 100644
--- a/libcacard/cac.c
+++ b/libcacard/cac.c
@@ -169,17 +169,8 @@ cac_applet_pki_process_apdu(VCard *card, VCardAPDU *apdu,
 }
 size = apdu-a_Lc;
 
-sign_buffer = realloc(pki_applet-sign_buffer,
-  pki_applet-sign_buffer_len+size);
-if (sign_buffer == NULL) {
-g_free(pki_applet-sign_buffer);
-pki_applet-sign_buffer = NULL;
-pki_applet-sign_buffer_len = 0;
-*response = vcard_make_response(
-VCARD7816_STATUS_EXC_ERROR_MEMORY_FAILURE);
-ret = VCARD_DONE;
-break;
-}
+sign_buffer = g_realloc(pki_applet-sign_buffer,
+pki_applet-sign_buffer_len + size);
 memcpy(sign_buffer+pki_applet-sign_buffer_len, apdu-a_body, size);
 size += pki_applet-sign_buffer_len;
 switch (apdu-a_p1) {
diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c
index 7826593..8e05551 100644
--- a/libcacard/vcard_emul_nss.c
+++ b/libcacard/vcard_emul_nss.c
@@ -1178,11 +1178,8 @@ vcard_emul_options(const char *args)
 
 if (opts-vreader_count = reader_count) {
 reader_count += READER_STEP;
-vreaderOpt = realloc(opts-vreader,
-reader_count * sizeof(*vreaderOpt));
-if (vreaderOpt == NULL) {
-return opts; /* we're done */
-}
+vreaderOpt = g_renew(VirtualReaderOptions, opts-vreader,
+ reader_count);
 }
 opts-vreader = vreaderOpt;
 vreaderOpt = vreaderOpt[opts-vreader_count];
-- 
1.7.10.4




[Qemu-devel] [PULL 03/23] nbd: Close socket on negotiation failure.

2014-05-26 Thread Michael Tokarev
From: Hani Benhabiles kroo...@gmail.com

Otherwise, the nbd client may hang waiting for the server response.

Signed-off-by: Hani Benhabiles h...@linux.com
Acked-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Michael Tokarev m...@tls.msk.ru
---
 blockdev-nbd.c |4 ++--
 qemu-nbd.c |4 +++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/blockdev-nbd.c b/blockdev-nbd.c
index 922cf56..b60b66d 100644
--- a/blockdev-nbd.c
+++ b/blockdev-nbd.c
@@ -27,8 +27,8 @@ static void nbd_accept(void *opaque)
 socklen_t addr_len = sizeof(addr);
 
 int fd = accept(server_fd, (struct sockaddr *)addr, addr_len);
-if (fd = 0) {
-nbd_client_new(NULL, fd, nbd_client_put);
+if (fd = 0  !nbd_client_new(NULL, fd, nbd_client_put)) {
+close(fd);
 }
 }
 
diff --git a/qemu-nbd.c b/qemu-nbd.c
index eed79fa..f70e4b0 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -369,8 +369,10 @@ static void nbd_accept(void *opaque)
 return;
 }
 
-if (fd = 0  nbd_client_new(exp, fd, nbd_client_closed)) {
+if (nbd_client_new(exp, fd, nbd_client_closed)) {
 nb_fds++;
+} else {
+close(fd);
 }
 }
 
-- 
1.7.10.4




[Qemu-devel] [PULL 22/23] net: cadence_gem: Fix top comment

2014-05-26 Thread Michael Tokarev
From: Peter Crosthwaite peter.crosthwa...@xilinx.com

To indicate Cadence GEM not Xilinx.

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
Signed-off-by: Michael Tokarev m...@tls.msk.ru
---
 hw/net/cadence_gem.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
index 47e7038..a26861e 100644
--- a/hw/net/cadence_gem.c
+++ b/hw/net/cadence_gem.c
@@ -1,5 +1,5 @@
 /*
- * QEMU Xilinx GEM emulation
+ * QEMU Cadence GEM emulation
  *
  * Copyright (c) 2011 Xilinx, Inc.
  *
-- 
1.7.10.4




Re: [Qemu-devel] [Xen-devel] [PATCH] libxl: change default QEMU machine to pc-i440fx-1.6

2014-05-26 Thread Fabio Fantoni

Il 25/05/2014 16:14, Stefano Stabellini ha scritto:

On Fri, 23 May 2014, Fabio Fantoni wrote:

Il 23/05/2014 18:07, Stefano Stabellini ha scritto:

Choose pc-i440fx-1.6 instead of pc for HVM guests, so that we know for
sure what is the machine that we are emulating.

Use pc-i440fx-1.6 regardless of the xen_platform_pci option. Add the
xen-platform device if requested. Choose slot 2 for the xen-platform
device for compatibility with current installations. In case of Intel
graphic passthrough, slot 2 might be needed by the grafic card. However
now that we can specify the slot explicitly, it is easy to change the
position of the xen-platform device on the PCI bus if graphic
passthrough is enabled.

Move the machine options earlier, before any other emulated devices
options. Otherwise the selected PCI slot for the xen-platform device is
not available in QEMU.

Specify PIIX4_PM.acpi-pci-hotplug-with-bridge-support=off, because
differently from xenfv, the other QEMU machines do not have that option
off by default.

This patch does not change the emulated environment in the guest.

Refer to this thread: http://marc.info/?l=xen-develm=140023775929625w=2

Signed-off-by: Stefano Stabellini stefano.stabell...@eu.citrix.com

diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index 8abed7b..fef684f 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -476,6 +476,29 @@ static char **
libxl__build_device_model_args_new(libxl__gc *gc,
   flexarray_vappend(dm_args, -k, keymap, NULL);
   }
   +flexarray_append(dm_args, -machine);
+switch (b_info-type) {
+case LIBXL_DOMAIN_TYPE_PV:
+flexarray_append(dm_args, xenpv);
+for (i = 0; b_info-extra_pv  b_info-extra_pv[i] != NULL; i++)
+flexarray_append(dm_args, b_info-extra_pv[i]);
+break;
+case LIBXL_DOMAIN_TYPE_HVM:
+flexarray_append(dm_args, pc-i440fx-1.6,accel=xen);


I think that a note in README should be added: qemu =1.6.1 is required 
for hvm domUs.


About the other xl parameter to be added I think that should be:
qemu_machine_type=i440fx|q35 (when also q35 will be supported on xen)
qemu_machine_version=x.y to specify the machine version, useful for 
debug/testing and other some cases.



+flexarray_append(dm_args, -global);
+flexarray_append(dm_args,
PIIX4_PM.acpi-pci-hotplug-with-bridge-support=off);

I think is good add a comment for remember to remove this workaround when pc

=2.1 will be the default since qemu 2.1 will fix it.

https://lists.gnu.org/archive/html/qemu-devel/2014-05/msg04789.html

The workaround is not actually harmful, it doesn't need to be removed
when pc = 2.1 in QEMU.



+if (libxl_defbool_val(b_info-u.hvm.xen_platform_pci)) {
+flexarray_append(dm_args, -device);
+flexarray_append(dm_args, xen-platform,addr=0x2);

The fixed pci address to 0x2 probably is a problem with intel gpu passthrough:
http://lists.gnu.org/archive/html/qemu-devel/2014-05/msg03726.html

Right, however we cannot really change the default position of the
xen-platform device on the PCI bus, otherwise we'll end up changing the
emulated environment for all the VMs out there.

I'll leave it to Tiejun to move xen-platform to another slot when
graphic passthrough is enabled.





[Qemu-devel] [PULL 06/23] bswap.h: Rename ldl_p, stl_p, etc to ldl_he_p, stl_he_p, etc

2014-05-26 Thread Michael Tokarev
From: Peter Maydell peter.mayd...@linaro.org

We have an unfortunate naming clash between the functions
ldl_p, stl_p, etc defined in bswap.h (which have semantics
load/store in host endianness) and the #defines of the same
name in cpu-all.h (which have the semantics load/store in
target endianness).

Fortunately it turns out that the only users of the bswap.h
functions are all within bswap.h itself, so we can simply
rename them to include a _he_ infix for host endianness.

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
Reviewed-by: Richard Henderson r...@twiddle.net
Signed-off-by: Michael Tokarev m...@tls.msk.ru
---
 include/qemu/bswap.h |   45 +++--
 1 file changed, 23 insertions(+), 22 deletions(-)

diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h
index 0f9c6cf..78c1ced 100644
--- a/include/qemu/bswap.h
+++ b/include/qemu/bswap.h
@@ -215,9 +215,10 @@ typedef union {
  *   q: 64 bits
  *
  * endian is:
- * (empty): host endian
+ *   he   : host endian
  *   be   : big endian
  *   le   : little endian
+ * (except for byte accesses, which have no endian infix).
  */
 
 static inline int ldub_p(const void *ptr)
@@ -239,82 +240,82 @@ static inline void stb_p(void *ptr, uint8_t v)
operations.  Thus we don't need to play games with packed attributes, or
inline byte-by-byte stores.  */
 
-static inline int lduw_p(const void *ptr)
+static inline int lduw_he_p(const void *ptr)
 {
 uint16_t r;
 memcpy(r, ptr, sizeof(r));
 return r;
 }
 
-static inline int ldsw_p(const void *ptr)
+static inline int ldsw_he_p(const void *ptr)
 {
 int16_t r;
 memcpy(r, ptr, sizeof(r));
 return r;
 }
 
-static inline void stw_p(void *ptr, uint16_t v)
+static inline void stw_he_p(void *ptr, uint16_t v)
 {
 memcpy(ptr, v, sizeof(v));
 }
 
-static inline int ldl_p(const void *ptr)
+static inline int ldl_he_p(const void *ptr)
 {
 int32_t r;
 memcpy(r, ptr, sizeof(r));
 return r;
 }
 
-static inline void stl_p(void *ptr, uint32_t v)
+static inline void stl_he_p(void *ptr, uint32_t v)
 {
 memcpy(ptr, v, sizeof(v));
 }
 
-static inline uint64_t ldq_p(const void *ptr)
+static inline uint64_t ldq_he_p(const void *ptr)
 {
 uint64_t r;
 memcpy(r, ptr, sizeof(r));
 return r;
 }
 
-static inline void stq_p(void *ptr, uint64_t v)
+static inline void stq_he_p(void *ptr, uint64_t v)
 {
 memcpy(ptr, v, sizeof(v));
 }
 
 static inline int lduw_le_p(const void *ptr)
 {
-return (uint16_t)le_bswap(lduw_p(ptr), 16);
+return (uint16_t)le_bswap(lduw_he_p(ptr), 16);
 }
 
 static inline int ldsw_le_p(const void *ptr)
 {
-return (int16_t)le_bswap(lduw_p(ptr), 16);
+return (int16_t)le_bswap(lduw_he_p(ptr), 16);
 }
 
 static inline int ldl_le_p(const void *ptr)
 {
-return le_bswap(ldl_p(ptr), 32);
+return le_bswap(ldl_he_p(ptr), 32);
 }
 
 static inline uint64_t ldq_le_p(const void *ptr)
 {
-return le_bswap(ldq_p(ptr), 64);
+return le_bswap(ldq_he_p(ptr), 64);
 }
 
 static inline void stw_le_p(void *ptr, uint16_t v)
 {
-stw_p(ptr, le_bswap(v, 16));
+stw_he_p(ptr, le_bswap(v, 16));
 }
 
 static inline void stl_le_p(void *ptr, uint32_t v)
 {
-stl_p(ptr, le_bswap(v, 32));
+stl_he_p(ptr, le_bswap(v, 32));
 }
 
 static inline void stq_le_p(void *ptr, uint64_t v)
 {
-stq_p(ptr, le_bswap(v, 64));
+stq_he_p(ptr, le_bswap(v, 64));
 }
 
 /* float access */
@@ -349,37 +350,37 @@ static inline void stfq_le_p(void *ptr, float64 v)
 
 static inline int lduw_be_p(const void *ptr)
 {
-return (uint16_t)be_bswap(lduw_p(ptr), 16);
+return (uint16_t)be_bswap(lduw_he_p(ptr), 16);
 }
 
 static inline int ldsw_be_p(const void *ptr)
 {
-return (int16_t)be_bswap(lduw_p(ptr), 16);
+return (int16_t)be_bswap(lduw_he_p(ptr), 16);
 }
 
 static inline int ldl_be_p(const void *ptr)
 {
-return be_bswap(ldl_p(ptr), 32);
+return be_bswap(ldl_he_p(ptr), 32);
 }
 
 static inline uint64_t ldq_be_p(const void *ptr)
 {
-return be_bswap(ldq_p(ptr), 64);
+return be_bswap(ldq_he_p(ptr), 64);
 }
 
 static inline void stw_be_p(void *ptr, uint16_t v)
 {
-stw_p(ptr, be_bswap(v, 16));
+stw_he_p(ptr, be_bswap(v, 16));
 }
 
 static inline void stl_be_p(void *ptr, uint32_t v)
 {
-stl_p(ptr, be_bswap(v, 32));
+stl_he_p(ptr, be_bswap(v, 32));
 }
 
 static inline void stq_be_p(void *ptr, uint64_t v)
 {
-stq_p(ptr, be_bswap(v, 64));
+stq_he_p(ptr, be_bswap(v, 64));
 }
 
 /* float access */
-- 
1.7.10.4




[Qemu-devel] [PULL 05/24] gtk: remove page numbering assumtions from the code

2014-05-26 Thread Gerd Hoffmann
Lookup page numbers using gtk_notebook_page_num() instead.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/gtk.c | 40 ++--
 1 file changed, 30 insertions(+), 10 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 6a3fe00..49753ef 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -190,7 +190,11 @@ static bool gd_grab_on_hover(GtkDisplayState *s)
 
 static bool gd_on_vga(GtkDisplayState *s)
 {
-return gtk_notebook_get_current_page(GTK_NOTEBOOK(s-notebook)) == 0;
+gint p1, p2;
+
+p1 = gtk_notebook_get_current_page(GTK_NOTEBOOK(s-notebook));
+p2 = gtk_notebook_page_num(GTK_NOTEBOOK(s-notebook), s-drawing_area);
+return p1 == p2;
 }
 
 static void gd_update_cursor(GtkDisplayState *s, gboolean override)
@@ -805,19 +809,25 @@ static void gd_menu_quit(GtkMenuItem *item, void *opaque)
 static void gd_menu_switch_vc(GtkMenuItem *item, void *opaque)
 {
 GtkDisplayState *s = opaque;
+gint page;
 
 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s-vga_item))) {
-gtk_notebook_set_current_page(GTK_NOTEBOOK(s-notebook), 0);
+page = gtk_notebook_page_num(GTK_NOTEBOOK(s-notebook),
+ s-drawing_area);
+gtk_notebook_set_current_page(GTK_NOTEBOOK(s-notebook), page);
 } else {
-int i;
-
 gtk_release_modifiers(s);
+#if defined(CONFIG_VTE)
+gint i;
 for (i = 0; i  s-nb_vcs; i++) {
 if 
(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s-vc[i].menu_item))) {
-gtk_notebook_set_current_page(GTK_NOTEBOOK(s-notebook), i + 
1);
-break;
+page = gtk_notebook_page_num(GTK_NOTEBOOK(s-notebook),
+ s-vc[i].box);
+gtk_notebook_set_current_page(GTK_NOTEBOOK(s-notebook), page);
+return;
 }
 }
+#endif
 }
 }
 
@@ -1061,12 +1071,14 @@ static void gd_change_page(GtkNotebook *nb, gpointer 
arg1, guint arg2,
 {
 GtkDisplayState *s = data;
 gboolean on_vga;
+gint page;
 
 if (!gtk_widget_get_realized(s-notebook)) {
 return;
 }
 
-on_vga = arg2 == 0;
+page = gtk_notebook_page_num(GTK_NOTEBOOK(s-notebook), s-drawing_area);
+on_vga = arg2 == page;
 
 if (!on_vga) {
 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s-grab_item),
@@ -1076,12 +1088,20 @@ static void gd_change_page(GtkNotebook *nb, gpointer 
arg1, guint arg2,
TRUE);
 }
 
-if (arg2 == 0) {
+if (on_vga) {
 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s-vga_item), TRUE);
 } else {
 #if defined(CONFIG_VTE)
-VirtualConsole *vc = s-vc[arg2 - 1];
-gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(vc-menu_item), 
TRUE);
+VirtualConsole *vc;
+gint page, i;
+for (i = 0; i  s-nb_vcs; i++) {
+vc = s-vc[i];
+page = gtk_notebook_page_num(GTK_NOTEBOOK(s-notebook), vc-box);
+if (page == arg2) {
+gtk_check_menu_item_set_active
+(GTK_CHECK_MENU_ITEM(vc-menu_item), TRUE);
+}
+}
 #else
 g_assert_not_reached();
 #endif
-- 
1.8.3.1




[Qemu-devel] [PULL 00/24] gtk: ui overhaul, multiwindow support.

2014-05-26 Thread Gerd Hoffmann
  Hi,

This series adds multiwindow support to the gtk ui.
Also brings some cleanups and bugfixes.

cheers,
  Gerd

The following changes since commit 178ac111bca16c08a79b2609ebdc75197bea976a:

  Merge remote-tracking branch 'remotes/qmp-unstable/queue/qmp' into staging 
(2014-05-22 19:04:49 +0100)

are available in the git repository at:


  git://git.kraxel.org/qemu tags/pull-gtk-7

for you to fetch changes up to 6fa27697514bb45e80fcb57f38054a8833f87ff9:

  gtk: workaround gtk2 vte resize issue (2014-05-26 08:41:04 +0200)


gtk: ui overhaul, multiwindow support.


Bruce Rogers (1):
  gtk: Add handling for the xfree86 keycodes

Cole Robinson (1):
  gtk: Add a scrollbar for text consoles

Gerd Hoffmann (22):
  gtk: zap scrolled_window
  gtk: zap vte size requests
  gtk: cleanup CONFIG_VTE ifdef a bit.
  gtk: remove page numbering assumtions from the code
  gtk: VirtualConsole restruction
  gtk: move vga state into VirtualGfxConsole
  gtk: support multiple gfx displays
  gtk: use device type as label
  gtk: simplify resize
  gtk: allow moving tabs to windows and back.
  gtk: add tab to trace events
  gtk: add gd_grab trace event
  gtk: keep track of grab owner
  gtk: skip keyboard grab when hover autograb is active
  gtk: update gd_update_caption
  gtk: fix grab checks
  gtk: update all windows on mouse mode changes
  gtk: detached window pointer grabs
  gtk: enable untabify for gfx
  gtk: zap unused global_state
  gtk: window sizing overhaul
  gtk: workaround gtk2 vte resize issue

 trace-events |7 +-
 ui/gtk.c | 1108 ++
 2 files changed, 738 insertions(+), 377 deletions(-)



[Qemu-devel] [PULL 09/24] gtk: use device type as label

2014-05-26 Thread Gerd Hoffmann
IMO useful than showing VGA for any graphic device
even in case it is something completely different.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/gtk.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 0756432..a8393dd 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -67,6 +67,7 @@
 #include x_keymap.h
 #include keymaps.h
 #include sysemu/char.h
+#include qom/object.h
 
 #define MAX_VCS 10
 
@@ -1457,6 +1458,15 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, 
VirtualConsole *vc,
   QemuConsole *con, int idx,
   GSList *group, GtkWidget *view_menu)
 {
+const char *label = VGA;
+Error *local_err = NULL;
+Object *obj;
+
+obj = object_property_get_link(OBJECT(con), device, local_err);
+if (obj) {
+label = object_get_typename(obj);
+}
+
 vc-s = s;
 vc-gfx.scale_x = 1.0;
 vc-gfx.scale_y = 1.0;
@@ -1477,10 +1487,10 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, 
VirtualConsole *vc,
 vc-type = GD_VC_GFX;
 vc-tab_item = vc-gfx.drawing_area;
 gtk_notebook_append_page(GTK_NOTEBOOK(s-notebook),
- vc-tab_item, gtk_label_new(VGA));
+ vc-tab_item, gtk_label_new(label));
 gd_connect_vc_gfx_signals(vc);
 
-group = gd_vc_menu_init(s, vc, VGA, idx, group, view_menu);
+group = gd_vc_menu_init(s, vc, label, idx, group, view_menu);
 
 vc-gfx.dcl.ops = dcl_ops;
 vc-gfx.dcl.con = con;
-- 
1.8.3.1




[Qemu-devel] [PULL 04/24] gtk: Add a scrollbar for text consoles

2014-05-26 Thread Gerd Hoffmann
From: Cole Robinson crobi...@redhat.com

Only show the scrollbar if the content doesn't fit on the visible space.

[ kraxel: fix box packing ]

Signed-off-by: Cole Robinson crobi...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/gtk.c | 42 --
 1 file changed, 40 insertions(+), 2 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 068a39b..6a3fe00 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -109,6 +109,8 @@ typedef struct VirtualConsole
 {
 GtkWidget *menu_item;
 #if defined(CONFIG_VTE)
+GtkWidget *box;
+GtkWidget *scrollbar;
 GtkWidget *terminal;
 CharDriverState *chr;
 #endif
@@ -1125,6 +1127,18 @@ static gboolean gd_focus_out_event(GtkWidget *widget,
 /** Virtual Console Callbacks **/
 
 #if defined(CONFIG_VTE)
+static void gd_vc_adjustment_changed(GtkAdjustment *adjustment, void *opaque)
+{
+VirtualConsole *vc = opaque;
+
+if (gtk_adjustment_get_upper(adjustment) 
+gtk_adjustment_get_page_size(adjustment)) {
+gtk_widget_show(vc-scrollbar);
+} else {
+gtk_widget_hide(vc-scrollbar);
+}
+}
+
 static int gd_vc_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
 {
 VirtualConsole *vc = chr-opaque;
@@ -1165,6 +1179,9 @@ static GSList *gd_vc_init(GtkDisplayState *s, 
VirtualConsole *vc, int index, GSL
 const char *label;
 char buffer[32];
 char path[32];
+GtkWidget *box;
+GtkWidget *scrollbar;
+GtkAdjustment *vadjustment;
 
 snprintf(buffer, sizeof(buffer), vc%d, index);
 snprintf(path, sizeof(path), QEMU/View/VC%d, index);
@@ -1186,12 +1203,33 @@ static GSList *gd_vc_init(GtkDisplayState *s, 
VirtualConsole *vc, int index, GSL
 g_signal_connect(vc-terminal, commit, G_CALLBACK(gd_vc_in), vc);
 
 vte_terminal_set_scrollback_lines(VTE_TERMINAL(vc-terminal), -1);
-
 vte_terminal_set_size(VTE_TERMINAL(vc-terminal), 80, 25);
 
+#if VTE_CHECK_VERSION(0, 28, 0)  GTK_CHECK_VERSION(3, 0, 0)
+vadjustment = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(vc-terminal));
+#else
+vadjustment = vte_terminal_get_adjustment(VTE_TERMINAL(vc-terminal));
+#endif
+
+#if GTK_CHECK_VERSION(3, 0, 0)
+box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
+scrollbar = gtk_scrollbar_new(GTK_ORIENTATION_VERTICAL, vadjustment);
+#else
+box = gtk_hbox_new(false, 2);
+scrollbar = gtk_vscrollbar_new(vadjustment);
+#endif
+
+gtk_box_pack_start(GTK_BOX(box), vc-terminal, TRUE, TRUE, 0);
+gtk_box_pack_start(GTK_BOX(box), scrollbar, FALSE, FALSE, 0);
+
 vc-chr-opaque = vc;
+vc-box = box;
+vc-scrollbar = scrollbar;
+
+g_signal_connect(vadjustment, changed,
+ G_CALLBACK(gd_vc_adjustment_changed), vc);
 
-gtk_notebook_append_page(GTK_NOTEBOOK(s-notebook), vc-terminal,
+gtk_notebook_append_page(GTK_NOTEBOOK(s-notebook), box,
  gtk_label_new(label));
 g_signal_connect(vc-menu_item, activate,
  G_CALLBACK(gd_menu_switch_vc), s);
-- 
1.8.3.1




[Qemu-devel] [PULL 01/24] gtk: zap scrolled_window

2014-05-26 Thread Gerd Hoffmann
The vte widget implements the scrollable interface, placing it into
a scrolled window is pointless and creates a bunch of strange effects.
Zap it.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/gtk.c | 19 ++-
 1 file changed, 2 insertions(+), 17 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 9f5061a..f6f3677 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -110,7 +110,6 @@ typedef struct VirtualConsole
 GtkWidget *menu_item;
 GtkWidget *terminal;
 #if defined(CONFIG_VTE)
-GtkWidget *scrolled_window;
 CharDriverState *chr;
 #endif
 } VirtualConsole;
@@ -1189,8 +1188,6 @@ static GSList *gd_vc_init(GtkDisplayState *s, 
VirtualConsole *vc, int index, GSL
 const char *label;
 char buffer[32];
 char path[32];
-GtkWidget *scrolled_window;
-GtkAdjustment *vadjustment;
 
 snprintf(buffer, sizeof(buffer), vc%d, index);
 snprintf(path, sizeof(path), QEMU/View/VC%d, index);
@@ -1213,24 +1210,12 @@ static GSList *gd_vc_init(GtkDisplayState *s, 
VirtualConsole *vc, int index, GSL
 
 vte_terminal_set_scrollback_lines(VTE_TERMINAL(vc-terminal), -1);
 
-#if VTE_CHECK_VERSION(0, 28, 0)  GTK_CHECK_VERSION(3, 0, 0)
-vadjustment = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(vc-terminal));
-#else
-vadjustment = vte_terminal_get_adjustment(VTE_TERMINAL(vc-terminal));
-#endif
-
-scrolled_window = gtk_scrolled_window_new(NULL, vadjustment);
-gtk_container_add(GTK_CONTAINER(scrolled_window), vc-terminal);
-
 vte_terminal_set_size(VTE_TERMINAL(vc-terminal), 80, 25);
 
 vc-chr-opaque = vc;
-vc-scrolled_window = scrolled_window;
-
-gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vc-scrolled_window),
-   GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
 
-gtk_notebook_append_page(GTK_NOTEBOOK(s-notebook), scrolled_window, 
gtk_label_new(label));
+gtk_notebook_append_page(GTK_NOTEBOOK(s-notebook), vc-terminal,
+ gtk_label_new(label));
 g_signal_connect(vc-menu_item, activate,
  G_CALLBACK(gd_menu_switch_vc), s);
 
-- 
1.8.3.1




[Qemu-devel] [PULL 03/24] gtk: cleanup CONFIG_VTE ifdef a bit.

2014-05-26 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/gtk.c | 45 ++---
 1 file changed, 26 insertions(+), 19 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 776e72d..068a39b 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -108,8 +108,8 @@ static const int modifier_keycode[] = {
 typedef struct VirtualConsole
 {
 GtkWidget *menu_item;
-GtkWidget *terminal;
 #if defined(CONFIG_VTE)
+GtkWidget *terminal;
 CharDriverState *chr;
 #endif
 } VirtualConsole;
@@ -1124,13 +1124,12 @@ static gboolean gd_focus_out_event(GtkWidget *widget,
 
 /** Virtual Console Callbacks **/
 
+#if defined(CONFIG_VTE)
 static int gd_vc_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
 {
-#if defined(CONFIG_VTE)
 VirtualConsole *vc = chr-opaque;
 
 vte_terminal_feed(VTE_TERMINAL(vc-terminal), (const char *)buf, len);
-#endif
 return len;
 }
 
@@ -1151,12 +1150,6 @@ static CharDriverState *gd_vc_handler(ChardevVC *unused)
 return chr;
 }
 
-void early_gtk_display_init(void)
-{
-register_vc_handler(gd_vc_handler);
-}
-
-#if defined(CONFIG_VTE)
 static gboolean gd_vc_in(VteTerminal *terminal, gchar *text, guint size,
  gpointer user_data)
 {
@@ -1165,12 +1158,10 @@ static gboolean gd_vc_in(VteTerminal *terminal, gchar 
*text, guint size,
 qemu_chr_be_write(vc-chr, (uint8_t  *)text, (unsigned int)size);
 return TRUE;
 }
-#endif
 
 static GSList *gd_vc_init(GtkDisplayState *s, VirtualConsole *vc, int index, 
GSList *group,
   GtkWidget *view_menu)
 {
-#if defined(CONFIG_VTE)
 const char *label;
 char buffer[32];
 char path[32];
@@ -1212,10 +1203,23 @@ static GSList *gd_vc_init(GtkDisplayState *s, 
VirtualConsole *vc, int index, GSL
 vc-chr-init(vc-chr);
 }
 
-#endif /* CONFIG_VTE */
 return group;
 }
 
+static void gd_vcs_init(GtkDisplayState *s, GSList *group,
+GtkWidget *view_menu)
+{
+int i;
+
+for (i = 0; i  nb_vcs; i++) {
+VirtualConsole *vc = s-vc[i];
+
+group = gd_vc_init(s, vc, i, group, view_menu);
+s-nb_vcs++;
+}
+}
+#endif /* CONFIG_VTE */
+
 /** Window Creation **/
 
 static void gd_connect_signals(GtkDisplayState *s)
@@ -1316,7 +1320,6 @@ static GtkWidget *gd_create_menu_view(GtkDisplayState *s, 
GtkAccelGroup *accel_g
 GSList *group = NULL;
 GtkWidget *view_menu;
 GtkWidget *separator;
-int i;
 
 view_menu = gtk_menu_new();
 gtk_menu_set_accel_group(GTK_MENU(view_menu), accel_group);
@@ -1378,12 +1381,9 @@ static GtkWidget *gd_create_menu_view(GtkDisplayState 
*s, GtkAccelGroup *accel_g
 gtk_accel_map_add_entry(QEMU/View/VGA, GDK_KEY_1, HOTKEY_MODIFIERS);
 gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s-vga_item);
 
-for (i = 0; i  nb_vcs; i++) {
-VirtualConsole *vc = s-vc[i];
-
-group = gd_vc_init(s, vc, i, group, view_menu);
-s-nb_vcs++;
-}
+#if defined(CONFIG_VTE)
+gd_vcs_init(s, group, view_menu);
+#endif
 
 separator = gtk_separator_menu_item_new();
 gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator);
@@ -1512,3 +1512,10 @@ void gtk_display_init(DisplayState *ds, bool 
full_screen, bool grab_on_hover)
 
 global_state = s;
 }
+
+void early_gtk_display_init(void)
+{
+#if defined(CONFIG_VTE)
+register_vc_handler(gd_vc_handler);
+#endif
+}
-- 
1.8.3.1




[Qemu-devel] [PULL 19/24] gtk: detached window pointer grabs

2014-05-26 Thread Gerd Hoffmann
Make ungrab hotkey work with detached windows.
Enable pointer grabs for detached windows.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/gtk.c | 24 +---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 8215841..298419b 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -773,10 +773,7 @@ static gboolean gd_button_event(GtkWidget *widget, 
GdkEventButton *button,
 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s-grab_item),
TRUE);
 } else {
-#if 0
-/* FIXME: no way (yet) to ungrab */
 gd_grab_pointer(vc);
-#endif
 gd_update_caption(s);
 }
 return TRUE;
@@ -945,6 +942,20 @@ static gboolean gd_tab_window_close(GtkWidget *widget, 
GdkEvent *event,
 return TRUE;
 }
 
+static gboolean gd_win_grab(void *opaque)
+{
+VirtualConsole *vc = opaque;
+
+fprintf(stderr, %s: %s\n, __func__, vc-label);
+if (vc-s-ptr_owner) {
+gd_ungrab_pointer(vc-s);
+} else {
+gd_grab_pointer(vc);
+}
+gd_update_caption(vc-s);
+return TRUE;
+}
+
 static void gd_menu_untabify(GtkMenuItem *item, void *opaque)
 {
 GtkDisplayState *s = opaque;
@@ -963,6 +974,13 @@ static void gd_menu_untabify(GtkMenuItem *item, void 
*opaque)
  G_CALLBACK(gd_tab_window_close), vc);
 gtk_widget_show_all(vc-window);
 
+GtkAccelGroup *ag = gtk_accel_group_new();
+gtk_window_add_accel_group(GTK_WINDOW(vc-window), ag);
+
+GClosure *cb = g_cclosure_new_swap(G_CALLBACK(gd_win_grab), vc, NULL);
+gtk_accel_group_connect(ag, GDK_KEY_g, HOTKEY_MODIFIERS, 0, cb);
+
+fprintf(stderr, %s: %p\n, __func__, vc);
 gd_update_caption(s);
 }
 }
-- 
1.8.3.1




[Qemu-devel] [PULL 08/24] gtk: support multiple gfx displays

2014-05-26 Thread Gerd Hoffmann
Each display gets its own tab.  Tab switching continues to work like it
did, just the hotkeys of the vte consoles changes in case a secondary
display is present as it will get ctrl-alt-2 assigned and the vtes are
shifted by one.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/gtk.c | 80 ++--
 1 file changed, 43 insertions(+), 37 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index bc42f68..0756432 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -1206,6 +1206,26 @@ static gboolean gd_focus_out_event(GtkWidget *widget,
 
 /** Virtual Console Callbacks **/
 
+static GSList *gd_vc_menu_init(GtkDisplayState *s, VirtualConsole *vc,
+   const char *label, int idx,
+   GSList *group, GtkWidget *view_menu)
+{
+char path[32];
+
+snprintf(path, sizeof(path), QEMU/View/VC%d, idx);
+
+vc-menu_item = gtk_radio_menu_item_new_with_mnemonic(group, label);
+group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(vc-menu_item));
+gtk_menu_item_set_accel_path(GTK_MENU_ITEM(vc-menu_item), path);
+gtk_accel_map_add_entry(path, GDK_KEY_1 + idx, HOTKEY_MODIFIERS);
+
+g_signal_connect(vc-menu_item, activate,
+ G_CALLBACK(gd_menu_switch_vc), s);
+gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), vc-menu_item);
+
+return group;
+}
+
 #if defined(CONFIG_VTE)
 static void gd_vc_adjustment_changed(GtkAdjustment *adjustment, void *opaque)
 {
@@ -1253,32 +1273,22 @@ static gboolean gd_vc_in(VteTerminal *terminal, gchar 
*text, guint size,
 return TRUE;
 }
 
-static GSList *gd_vc_vte_init(GtkDisplayState *s, VirtualConsole *vc, int 
index,
+static GSList *gd_vc_vte_init(GtkDisplayState *s, VirtualConsole *vc,
+  CharDriverState *chr, int idx,
   GSList *group, GtkWidget *view_menu)
 {
 const char *label;
 char buffer[32];
-char path[32];
 GtkWidget *box;
 GtkWidget *scrollbar;
 GtkAdjustment *vadjustment;
 
-snprintf(buffer, sizeof(buffer), vc%d, index);
-snprintf(path, sizeof(path), QEMU/View/VC%d, index);
-
 vc-s = s;
-vc-vte.chr = vcs[index];
-
-if (vc-vte.chr-label) {
-label = vc-vte.chr-label;
-} else {
-label = buffer;
-}
+vc-vte.chr = chr;
 
-vc-menu_item = gtk_radio_menu_item_new_with_mnemonic(group, label);
-group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(vc-menu_item));
-gtk_menu_item_set_accel_path(GTK_MENU_ITEM(vc-menu_item), path);
-gtk_accel_map_add_entry(path, GDK_KEY_2 + index, HOTKEY_MODIFIERS);
+snprintf(buffer, sizeof(buffer), vc%d, idx);
+label = vc-vte.chr-label ? vc-vte.chr-label : buffer;
+group = gd_vc_menu_init(s, vc, vc-vte.chr-label, idx, group, view_menu);
 
 vc-vte.terminal = vte_terminal_new();
 g_signal_connect(vc-vte.terminal, commit, G_CALLBACK(gd_vc_in), vc);
@@ -1315,10 +1325,6 @@ static GSList *gd_vc_vte_init(GtkDisplayState *s, 
VirtualConsole *vc, int index,
 vc-tab_item = box;
 gtk_notebook_append_page(GTK_NOTEBOOK(s-notebook), vc-tab_item,
  gtk_label_new(label));
-g_signal_connect(vc-menu_item, activate,
- G_CALLBACK(gd_menu_switch_vc), s);
-
-gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), vc-menu_item);
 
 qemu_chr_be_generic_open(vc-vte.chr);
 if (vc-vte.chr-init) {
@@ -1328,15 +1334,14 @@ static GSList *gd_vc_vte_init(GtkDisplayState *s, 
VirtualConsole *vc, int index,
 return group;
 }
 
-static void gd_vcs_init(GtkDisplayState *s, int offset, GSList *group,
+static void gd_vcs_init(GtkDisplayState *s, GSList *group,
 GtkWidget *view_menu)
 {
 int i;
 
 for (i = 0; i  nb_vcs; i++) {
-VirtualConsole *vc = s-vc[offset+i];
-
-group = gd_vc_vte_init(s, vc, i, group, view_menu);
+VirtualConsole *vc = s-vc[s-nb_vcs];
+group = gd_vc_vte_init(s, vc, vcs[i], s-nb_vcs, group, view_menu);
 s-nb_vcs++;
 }
 }
@@ -1449,7 +1454,7 @@ static const DisplayChangeListenerOps dcl_ops = {
 };
 
 static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,
-  QemuConsole *con, int index,
+  QemuConsole *con, int idx,
   GSList *group, GtkWidget *view_menu)
 {
 vc-s = s;
@@ -1475,15 +1480,7 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, 
VirtualConsole *vc,
  vc-tab_item, gtk_label_new(VGA));
 gd_connect_vc_gfx_signals(vc);
 
-vc-menu_item = gtk_radio_menu_item_new_with_mnemonic(group, _VGA);
-group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(vc-menu_item));
-gtk_menu_item_set_accel_path(GTK_MENU_ITEM(vc-menu_item),
- QEMU/View/VGA);
-gtk_accel_map_add_entry(QEMU/View/VGA, GDK_KEY_1, HOTKEY_MODIFIERS);
-

[Qemu-devel] [PULL 15/24] gtk: skip keyboard grab when hover autograb is active

2014-05-26 Thread Gerd Hoffmann
It's pointless.  With grab on hover enabled the keyboard grab
is already active when you press Ctrl-Alt-G ;)

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/gtk.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index d87bd1b..f804813 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -1183,7 +1183,9 @@ static void gd_menu_grab_input(GtkMenuItem *item, void 
*opaque)
 VirtualConsole *vc = gd_vc_find_current(s);
 
 if (gd_is_grab_active(s)) {
-gd_grab_keyboard(vc);
+if (!gd_grab_on_hover(s)) {
+gd_grab_keyboard(vc);
+}
 gd_grab_pointer(vc);
 } else {
 gd_ungrab_keyboard(s);
-- 
1.8.3.1




[Qemu-devel] [PULL 20/24] gtk: enable untabify for gfx

2014-05-26 Thread Gerd Hoffmann
Now we have all grab fixes in place, so we can allow detaching
graphic display tabs too.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/gtk.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 298419b..79dc8db 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -338,7 +338,11 @@ static void gd_update_windowsize(VirtualConsole *vc)
 gtk_widget_set_size_request(vc-gfx.drawing_area,
 surface_width(vc-gfx.ds) * sx,
 surface_height(vc-gfx.ds) * sy);
-gtk_window_resize(GTK_WINDOW(s-window), 320, 240);
+if (vc-window) {
+gtk_window_resize(GTK_WINDOW(vc-window), 320, 240);
+} else {
+gtk_window_resize(GTK_WINDOW(s-window), 320, 240);
+}
 }
 
 static void gd_update_full_redraw(VirtualConsole *vc)
@@ -962,8 +966,8 @@ static void gd_menu_untabify(GtkMenuItem *item, void 
*opaque)
 VirtualConsole *vc = gd_vc_find_current(s);
 
 if (vc-type == GD_VC_GFX) {
-/* temporary: needs more work to get grabs etc correct */
-return;
+gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s-grab_item),
+   FALSE);
 }
 if (!vc-window) {
 gtk_widget_set_sensitive(vc-menu_item, false);
-- 
1.8.3.1




[Qemu-devel] [PULL 10/24] gtk: simplify resize

2014-05-26 Thread Gerd Hoffmann
Simply ask for a small window size.  When the widgets don't fit in gtk
will automatically make the window large enougth to make things fit, no
need to try (and fail) duplicate that logic in qemu.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/gtk.c | 40 ++--
 1 file changed, 14 insertions(+), 26 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index a8393dd..6790cf8 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -296,35 +296,23 @@ static void gd_update_caption(GtkDisplayState *s)
 static void gd_update_windowsize(VirtualConsole *vc)
 {
 GtkDisplayState *s = vc-s;
+double sx, sy;
 
-if (!s-full_screen) {
-GtkRequisition req;
-double sx, sy;
-
-if (s-free_scale) {
-sx = vc-gfx.scale_x;
-sy = vc-gfx.scale_y;
-
-vc-gfx.scale_y = 1.0;
-vc-gfx.scale_x = 1.0;
-} else {
-sx = 1.0;
-sy = 1.0;
-}
-
-gtk_widget_set_size_request
-(vc-gfx.drawing_area,
- surface_width(vc-gfx.ds) * vc-gfx.scale_x,
- surface_height(vc-gfx.ds) * vc-gfx.scale_y);
-#if GTK_CHECK_VERSION(3, 0, 0)
-gtk_widget_get_preferred_size(s-vbox, NULL, req);
-#else
-gtk_widget_size_request(s-vbox, req);
-#endif
+if (vc-type != GD_VC_GFX || s-full_screen) {
+return;
+}
 
-gtk_window_resize(GTK_WINDOW(s-window),
-  req.width * sx, req.height * sy);
+if (s-free_scale) {
+sx = 1.0;
+sy = 1.0;
+} else {
+sx = vc-gfx.scale_x;
+sy = vc-gfx.scale_y;
 }
+gtk_widget_set_size_request(vc-gfx.drawing_area,
+surface_width(vc-gfx.ds) * sx,
+surface_height(vc-gfx.ds) * sy);
+gtk_window_resize(GTK_WINDOW(s-window), 320, 240);
 }
 
 static void gd_update_full_redraw(VirtualConsole *vc)
-- 
1.8.3.1




[Qemu-devel] [PULL 18/24] gtk: update all windows on mouse mode changes

2014-05-26 Thread Gerd Hoffmann
We might have multiple graphic displays now which all need a cursor update.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/gtk.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 91b6824..8215841 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -553,6 +553,7 @@ static void gd_change_runstate(void *opaque, int running, 
RunState state)
 static void gd_mouse_mode_change(Notifier *notify, void *data)
 {
 GtkDisplayState *s;
+int i;
 
 s = container_of(notify, GtkDisplayState, mouse_mode_notifier);
 /* release the grab at switching to absolute mode */
@@ -560,7 +561,10 @@ static void gd_mouse_mode_change(Notifier *notify, void 
*data)
 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s-grab_item),
FALSE);
 }
-gd_update_cursor(gd_vc_find_current(s));
+for (i = 0; i  s-nb_vcs; i++) {
+VirtualConsole *vc = s-vc[i];
+gd_update_cursor(vc);
+}
 }
 
 /** GTK Events **/
-- 
1.8.3.1




[Qemu-devel] [PULL 13/24] gtk: add gd_grab trace event

2014-05-26 Thread Gerd Hoffmann
Input grab code is tricky, add some debug  trouble shooting aid.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 trace-events | 1 +
 ui/gtk.c | 4 
 2 files changed, 5 insertions(+)

diff --git a/trace-events b/trace-events
index 3a41abf..e42 100644
--- a/trace-events
+++ b/trace-events
@@ -1048,6 +1048,7 @@ ppm_save(const char *filename, void *display_surface) %s 
surface=%p
 gd_switch(const char *tab, int width, int height) tab=%s, width=%d, height=%d
 gd_update(const char *tab, int x, int y, int w, int h) tab=%s, x=%d, y=%d, 
w=%d, h=%d
 gd_key_event(const char *tab, int gdk_keycode, int qemu_keycode, const char 
*action) tab=%s, translated GDK keycode %d to QEMU keycode %d (%s)
+gd_grab(const char *tab, const char *device, bool on) tab=%s, %s %d
 
 # ui/input.c
 input_event_key_number(int conidx, int number, bool down) con %d, key number 
0x%x, down %d
diff --git a/ui/gtk.c b/ui/gtk.c
index 3ee9465..0e35abf 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -1058,6 +1058,7 @@ static void gd_grab_keyboard(VirtualConsole *vc)
   FALSE,
   GDK_CURRENT_TIME);
 #endif
+trace_gd_grab(vc-label, kbd, true);
 }
 
 static void gd_ungrab_keyboard(VirtualConsole *vc)
@@ -1080,6 +1081,7 @@ static void gd_ungrab_keyboard(VirtualConsole *vc)
 #else
 gdk_keyboard_ungrab(GDK_CURRENT_TIME);
 #endif
+trace_gd_grab(vc-label, kbd, false);
 }
 
 static void gd_grab_pointer(VirtualConsole *vc)
@@ -1125,6 +1127,7 @@ static void gd_grab_pointer(VirtualConsole *vc)
 gdk_display_get_pointer(display, NULL,
 vc-s-grab_x_root, vc-s-grab_y_root, NULL);
 #endif
+trace_gd_grab(vc-label, ptr, true);
 }
 
 static void gd_ungrab_pointer(VirtualConsole *vc)
@@ -1153,6 +1156,7 @@ static void gd_ungrab_pointer(VirtualConsole *vc)
  gtk_widget_get_screen(vc-gfx.drawing_area),
  vc-s-grab_x_root, vc-s-grab_y_root);
 #endif
+trace_gd_grab(vc-label, ptr, false);
 }
 
 static void gd_menu_grab_input(GtkMenuItem *item, void *opaque)
-- 
1.8.3.1




[Qemu-devel] [PULL 12/24] gtk: add tab to trace events

2014-05-26 Thread Gerd Hoffmann
So you can see which of multiple displays (if present) was resized ;)

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 trace-events | 6 +++---
 ui/gtk.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/trace-events b/trace-events
index b6d289d..3a41abf 100644
--- a/trace-events
+++ b/trace-events
@@ -1045,9 +1045,9 @@ displaychangelistener_unregister(void *dcl, const char 
*name) %p [ %s ]
 ppm_save(const char *filename, void *display_surface) %s surface=%p
 
 # ui/gtk.c
-gd_switch(int width, int height) width=%d, height=%d
-gd_update(int x, int y, int w, int h) x=%d, y=%d, w=%d, h=%d
-gd_key_event(int gdk_keycode, int qemu_keycode, const char *action) 
translated GDK keycode %d to QEMU keycode %d (%s)
+gd_switch(const char *tab, int width, int height) tab=%s, width=%d, height=%d
+gd_update(const char *tab, int x, int y, int w, int h) tab=%s, x=%d, y=%d, 
w=%d, h=%d
+gd_key_event(const char *tab, int gdk_keycode, int qemu_keycode, const char 
*action) tab=%s, translated GDK keycode %d to QEMU keycode %d (%s)
 
 # ui/input.c
 input_event_key_number(int conidx, int number, bool down) con %d, key number 
0x%x, down %d
diff --git a/ui/gtk.c b/ui/gtk.c
index 07883a1..3ee9465 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -355,7 +355,7 @@ static void gd_update(DisplayChangeListener *dcl,
 int fbw, fbh;
 int ww, wh;
 
-trace_gd_update(x, y, w, h);
+trace_gd_update(vc-label, x, y, w, h);
 
 if (vc-gfx.convert) {
 pixman_image_composite(PIXMAN_OP_SRC, vc-gfx.ds-image,
@@ -461,7 +461,7 @@ static void gd_switch(DisplayChangeListener *dcl,
 VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
 bool resized = true;
 
-trace_gd_switch(surface_width(surface), surface_height(surface));
+trace_gd_switch(vc-label, surface_width(surface), 
surface_height(surface));
 
 if (vc-gfx.surface) {
 cairo_surface_destroy(vc-gfx.surface);
@@ -815,7 +815,7 @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey 
*key, void *opaque)
 }
 #endif
 
-trace_gd_key_event(gdk_keycode, qemu_keycode,
+trace_gd_key_event(vc-label, gdk_keycode, qemu_keycode,
(key-type == GDK_KEY_PRESS) ? down : up);
 
 for (i = 0; i  ARRAY_SIZE(modifier_keycode); i++) {
-- 
1.8.3.1




[Qemu-devel] [PULL 07/24] gtk: move vga state into VirtualGfxConsole

2014-05-26 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/gtk.c | 615 ++-
 1 file changed, 337 insertions(+), 278 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 78f6ccc..bc42f68 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -105,6 +105,18 @@ static const int modifier_keycode[] = {
 0x2a, 0x36, 0x1d, 0x9d, 0x38, 0xb8, 0xdb, 0xdd,
 };
 
+typedef struct GtkDisplayState GtkDisplayState;
+
+typedef struct VirtualGfxConsole {
+GtkWidget *drawing_area;
+DisplayChangeListener dcl;
+DisplaySurface *ds;
+pixman_image_t *convert;
+cairo_surface_t *surface;
+double scale_x;
+double scale_y;
+} VirtualGfxConsole;
+
 #if defined(CONFIG_VTE)
 typedef struct VirtualVteConsole {
 GtkWidget *box;
@@ -114,18 +126,25 @@ typedef struct VirtualVteConsole {
 } VirtualVteConsole;
 #endif
 
+typedef enum VirtualConsoleType {
+GD_VC_GFX,
+GD_VC_VTE,
+} VirtualConsoleType;
+
 typedef struct VirtualConsole {
+GtkDisplayState *s;
 GtkWidget *menu_item;
 GtkWidget *tab_item;
+VirtualConsoleType type;
 union {
+VirtualGfxConsole gfx;
 #if defined(CONFIG_VTE)
 VirtualVteConsole vte;
 #endif
 };
 } VirtualConsole;
 
-typedef struct GtkDisplayState
-{
+struct GtkDisplayState {
 GtkWidget *window;
 
 GtkWidget *menu_bar;
@@ -148,7 +167,6 @@ typedef struct GtkDisplayState
 GtkWidget *zoom_fit_item;
 GtkWidget *grab_item;
 GtkWidget *grab_on_hover_item;
-GtkWidget *vga_item;
 
 int nb_vcs;
 VirtualConsole vc[MAX_VCS];
@@ -157,11 +175,6 @@ typedef struct GtkDisplayState
 
 GtkWidget *vbox;
 GtkWidget *notebook;
-GtkWidget *drawing_area;
-cairo_surface_t *surface;
-pixman_image_t *convert;
-DisplayChangeListener dcl;
-DisplaySurface *ds;
 int button_mask;
 gboolean last_set;
 int last_x;
@@ -169,8 +182,6 @@ typedef struct GtkDisplayState
 int grab_x_root;
 int grab_y_root;
 
-double scale_x;
-double scale_y;
 gboolean full_screen;
 
 GdkCursor *null_cursor;
@@ -180,7 +191,7 @@ typedef struct GtkDisplayState
 bool external_pause_update;
 
 bool modifier_pressed[ARRAY_SIZE(modifier_keycode)];
-} GtkDisplayState;
+};
 
 static GtkDisplayState *global_state;
 
@@ -216,6 +227,14 @@ static VirtualConsole *gd_vc_find_by_page(GtkDisplayState 
*s, gint page)
 return NULL;
 }
 
+static VirtualConsole *gd_vc_find_current(GtkDisplayState *s)
+{
+gint page;
+
+page = gtk_notebook_get_current_page(GTK_NOTEBOOK(s-notebook));
+return gd_vc_find_by_page(s, page);
+}
+
 static bool gd_is_grab_active(GtkDisplayState *s)
 {
 return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s-grab_item));
@@ -226,26 +245,17 @@ static bool gd_grab_on_hover(GtkDisplayState *s)
 return 
gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s-grab_on_hover_item));
 }
 
-static bool gd_on_vga(GtkDisplayState *s)
-{
-gint p1, p2;
-
-p1 = gtk_notebook_get_current_page(GTK_NOTEBOOK(s-notebook));
-p2 = gtk_notebook_page_num(GTK_NOTEBOOK(s-notebook), s-drawing_area);
-return p1 == p2;
-}
-
-static void gd_update_cursor(GtkDisplayState *s, gboolean override)
+static void gd_update_cursor(VirtualConsole *vc)
 {
+GtkDisplayState *s = vc-s;
 GdkWindow *window;
-bool on_vga;
-
-window = gtk_widget_get_window(GTK_WIDGET(s-drawing_area));
 
-on_vga = gd_on_vga(s);
+if (vc-type != GD_VC_GFX) {
+return;
+}
 
-if ((override || on_vga) 
-(s-full_screen || qemu_input_is_absolute() || gd_is_grab_active(s))) {
+window = gtk_widget_get_window(GTK_WIDGET(vc-gfx.drawing_area));
+if (s-full_screen || qemu_input_is_absolute() || gd_is_grab_active(s)) {
 gdk_window_set_cursor(window, s-null_cursor);
 } else {
 gdk_window_set_cursor(window, NULL);
@@ -282,26 +292,29 @@ static void gd_update_caption(GtkDisplayState *s)
 g_free(title);
 }
 
-static void gd_update_windowsize(GtkDisplayState *s)
+static void gd_update_windowsize(VirtualConsole *vc)
 {
+GtkDisplayState *s = vc-s;
+
 if (!s-full_screen) {
 GtkRequisition req;
 double sx, sy;
 
 if (s-free_scale) {
-sx = s-scale_x;
-sy = s-scale_y;
+sx = vc-gfx.scale_x;
+sy = vc-gfx.scale_y;
 
-s-scale_y = 1.0;
-s-scale_x = 1.0;
+vc-gfx.scale_y = 1.0;
+vc-gfx.scale_x = 1.0;
 } else {
 sx = 1.0;
 sy = 1.0;
 }
 
-gtk_widget_set_size_request(s-drawing_area,
-surface_width(s-ds) * s-scale_x,
-surface_height(s-ds) * s-scale_y);
+gtk_widget_set_size_request
+(vc-gfx.drawing_area,
+ surface_width(vc-gfx.ds) * vc-gfx.scale_x,
+ surface_height(vc-gfx.ds) * vc-gfx.scale_y);
 #if GTK_CHECK_VERSION(3, 0, 0)
 

[Qemu-devel] [PULL 16/24] gtk: update gd_update_caption

2014-05-26 Thread Gerd Hoffmann
Adapt to recent changes, handle multiple windows.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/gtk.c | 45 -
 1 file changed, 28 insertions(+), 17 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index f804813..7d6a20d 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -271,11 +271,20 @@ static void gd_update_cursor(VirtualConsole *vc)
 static void gd_update_caption(GtkDisplayState *s)
 {
 const char *status = ;
+gchar *prefix;
 gchar *title;
 const char *grab = ;
 bool is_paused = !runstate_is_running();
+int i;
 
-if (gd_is_grab_active(s)) {
+if (qemu_name) {
+prefix = g_strdup_printf(QEMU (%s), qemu_name);
+} else {
+prefix = g_strdup_printf(QEMU);
+}
+
+if (s-ptr_owner != NULL 
+s-ptr_owner-window == NULL) {
 grab = _( - Press Ctrl+Alt+G to release grab);
 }
 
@@ -287,15 +296,24 @@ static void gd_update_caption(GtkDisplayState *s)
is_paused);
 s-external_pause_update = false;
 
-if (qemu_name) {
-title = g_strdup_printf(QEMU (%s)%s%s, qemu_name, status, grab);
-} else {
-title = g_strdup_printf(QEMU%s%s, status, grab);
-}
-
+title = g_strdup_printf(%s%s%s, prefix, status, grab);
 gtk_window_set_title(GTK_WINDOW(s-window), title);
-
 g_free(title);
+
+for (i = 0; i  s-nb_vcs; i++) {
+VirtualConsole *vc = s-vc[i];
+
+if (!vc-window) {
+continue;
+}
+title = g_strdup_printf(%s: %s%s%s, prefix, vc-label,
+vc == s-kbd_owner ?  +kbd : ,
+vc == s-ptr_owner ?  +ptr : );
+gtk_window_set_title(GTK_WINDOW(vc-window), title);
+g_free(title);
+}
+
+g_free(prefix);
 }
 
 static void gd_update_windowsize(VirtualConsole *vc)
@@ -915,7 +933,6 @@ static void gd_menu_untabify(GtkMenuItem *item, void 
*opaque)
 {
 GtkDisplayState *s = opaque;
 VirtualConsole *vc = gd_vc_find_current(s);
-char *title;
 
 if (vc-type == GD_VC_GFX) {
 /* temporary: needs more work to get grabs etc correct */
@@ -926,17 +943,11 @@ static void gd_menu_untabify(GtkMenuItem *item, void 
*opaque)
 vc-window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 gtk_widget_reparent(vc-tab_item, vc-window);
 
-if (qemu_name) {
-title = g_strdup_printf(QEMU (%s): %s, qemu_name, vc-label);
-} else {
-title = g_strdup_printf(QEMU: %s, vc-label);
-}
-gtk_window_set_title(GTK_WINDOW(vc-window), title);
-g_free(title);
-
 g_signal_connect(vc-window, delete-event,
  G_CALLBACK(gd_tab_window_close), vc);
 gtk_widget_show_all(vc-window);
+
+gd_update_caption(s);
 }
 }
 
-- 
1.8.3.1




[Qemu-devel] [PULL 14/24] gtk: keep track of grab owner

2014-05-26 Thread Gerd Hoffmann
Simplifies grab state tracking and makes ungrab more reliable.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/gtk.c | 28 +++-
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 0e35abf..d87bd1b 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -185,6 +185,8 @@ struct GtkDisplayState {
 int last_y;
 int grab_x_root;
 int grab_y_root;
+VirtualConsole *kbd_owner;
+VirtualConsole *ptr_owner;
 
 gboolean full_screen;
 
@@ -1058,11 +1060,19 @@ static void gd_grab_keyboard(VirtualConsole *vc)
   FALSE,
   GDK_CURRENT_TIME);
 #endif
+vc-s-kbd_owner = vc;
 trace_gd_grab(vc-label, kbd, true);
 }
 
-static void gd_ungrab_keyboard(VirtualConsole *vc)
+static void gd_ungrab_keyboard(GtkDisplayState *s)
 {
+VirtualConsole *vc = s-kbd_owner;
+
+if (vc == NULL) {
+return;
+}
+s-kbd_owner = NULL;
+
 #if GTK_CHECK_VERSION(3, 0, 0)
 GdkDisplay *display = gtk_widget_get_display(vc-gfx.drawing_area);
 GdkDeviceManager *mgr = gdk_display_get_device_manager(display);
@@ -1127,11 +1137,19 @@ static void gd_grab_pointer(VirtualConsole *vc)
 gdk_display_get_pointer(display, NULL,
 vc-s-grab_x_root, vc-s-grab_y_root, NULL);
 #endif
+vc-s-ptr_owner = vc;
 trace_gd_grab(vc-label, ptr, true);
 }
 
-static void gd_ungrab_pointer(VirtualConsole *vc)
+static void gd_ungrab_pointer(GtkDisplayState *s)
 {
+VirtualConsole *vc = s-ptr_owner;
+
+if (vc == NULL) {
+return;
+}
+s-ptr_owner = NULL;
+
 GdkDisplay *display = gtk_widget_get_display(vc-gfx.drawing_area);
 #if GTK_CHECK_VERSION(3, 0, 0)
 GdkDeviceManager *mgr = gdk_display_get_device_manager(display);
@@ -1168,8 +1186,8 @@ static void gd_menu_grab_input(GtkMenuItem *item, void 
*opaque)
 gd_grab_keyboard(vc);
 gd_grab_pointer(vc);
 } else {
-gd_ungrab_keyboard(vc);
-gd_ungrab_pointer(vc);
+gd_ungrab_keyboard(s);
+gd_ungrab_pointer(s);
 }
 
 gd_update_caption(s);
@@ -1227,7 +1245,7 @@ static gboolean gd_leave_event(GtkWidget *widget, 
GdkEventCrossing *crossing,
 GtkDisplayState *s = vc-s;
 
 if (!gd_is_grab_active(s)  gd_grab_on_hover(s)) {
-gd_ungrab_keyboard(vc);
+gd_ungrab_keyboard(s);
 }
 
 return TRUE;
-- 
1.8.3.1




[Qemu-devel] [PULL 02/24] gtk: zap vte size requests

2014-05-26 Thread Gerd Hoffmann
The vte tabs simply get the size of the vga tab then, with whatever
cols and lines are fitting in.  I find this bahavior more useful than
resizing the qemu window all day long.

YMMV.  Comments are welcome.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/gtk.c | 14 --
 1 file changed, 14 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index f6f3677..776e72d 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -1058,19 +1058,12 @@ static void gd_change_page(GtkNotebook *nb, gpointer 
arg1, guint arg2,
gpointer data)
 {
 GtkDisplayState *s = data;
-guint last_page;
 gboolean on_vga;
 
 if (!gtk_widget_get_realized(s-notebook)) {
 return;
 }
 
-last_page = gtk_notebook_get_current_page(nb);
-
-if (last_page) {
-gtk_widget_set_size_request(s-vc[last_page - 1].terminal, -1, -1);
-}
-
 on_vga = arg2 == 0;
 
 if (!on_vga) {
@@ -1086,14 +1079,7 @@ static void gd_change_page(GtkNotebook *nb, gpointer 
arg1, guint arg2,
 } else {
 #if defined(CONFIG_VTE)
 VirtualConsole *vc = s-vc[arg2 - 1];
-VteTerminal *term = VTE_TERMINAL(vc-terminal);
-int width, height;
-
-width = 80 * vte_terminal_get_char_width(term);
-height = 25 * vte_terminal_get_char_height(term);
-
 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(vc-menu_item), 
TRUE);
-gtk_widget_set_size_request(vc-terminal, width, height);
 #else
 g_assert_not_reached();
 #endif
-- 
1.8.3.1




[Qemu-devel] [PULL 22/24] gtk: zap unused global_state

2014-05-26 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/gtk.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index a55ceb4..0d86025 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -204,8 +204,6 @@ struct GtkDisplayState {
 bool has_evdev;
 };
 
-static GtkDisplayState *global_state;
-
 static void gd_grab_pointer(VirtualConsole *vc);
 static void gd_ungrab_pointer(GtkDisplayState *s);
 
@@ -1815,8 +1813,6 @@ void gtk_display_init(DisplayState *ds, bool full_screen, 
bool grab_on_hover)
 }
 
 gd_set_keycode_type(s);
-
-global_state = s;
 }
 
 void early_gtk_display_init(void)
-- 
1.8.3.1




[Qemu-devel] [PULL 17/24] gtk: fix grab checks

2014-05-26 Thread Gerd Hoffmann
Make it handle multiple windows case correctly.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/gtk.c | 35 +++
 1 file changed, 23 insertions(+), 12 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 7d6a20d..91b6824 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -201,6 +201,9 @@ struct GtkDisplayState {
 
 static GtkDisplayState *global_state;
 
+static void gd_grab_pointer(VirtualConsole *vc);
+static void gd_ungrab_pointer(GtkDisplayState *s);
+
 /** Utility Functions **/
 
 static VirtualConsole *gd_vc_find_by_menu(GtkDisplayState *s)
@@ -261,7 +264,7 @@ static void gd_update_cursor(VirtualConsole *vc)
 }
 
 window = gtk_widget_get_window(GTK_WIDGET(vc-gfx.drawing_area));
-if (s-full_screen || qemu_input_is_absolute() || gd_is_grab_active(s)) {
+if (s-full_screen || qemu_input_is_absolute() || s-ptr_owner == vc) {
 gdk_window_set_cursor(window, s-null_cursor);
 } else {
 gdk_window_set_cursor(window, NULL);
@@ -702,7 +705,7 @@ static gboolean gd_motion_event(GtkWidget *widget, 
GdkEventMotion *motion,
 qemu_input_queue_abs(vc-gfx.dcl.con, INPUT_AXIS_Y, y,
  surface_height(vc-gfx.ds));
 qemu_input_event_sync();
-} else if (s-last_set  gd_is_grab_active(s)) {
+} else if (s-last_set  s-ptr_owner == vc) {
 qemu_input_queue_rel(vc-gfx.dcl.con, INPUT_AXIS_X, x - s-last_x);
 qemu_input_queue_rel(vc-gfx.dcl.con, INPUT_AXIS_Y, y - s-last_y);
 qemu_input_event_sync();
@@ -711,7 +714,7 @@ static gboolean gd_motion_event(GtkWidget *widget, 
GdkEventMotion *motion,
 s-last_y = y;
 s-last_set = TRUE;
 
-if (!qemu_input_is_absolute()  gd_is_grab_active(s)) {
+if (!qemu_input_is_absolute()  s-ptr_owner == vc) {
 GdkScreen *screen = gtk_widget_get_screen(vc-gfx.drawing_area);
 int x = (int)motion-x_root;
 int y = (int)motion-y_root;
@@ -760,9 +763,18 @@ static gboolean gd_button_event(GtkWidget *widget, 
GdkEventButton *button,
 
 /* implicitly grab the input at the first click in the relative mode */
 if (button-button == 1  button-type == GDK_BUTTON_PRESS 
-!qemu_input_is_absolute()  !gd_is_grab_active(s)) {
-gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s-grab_item),
-   TRUE);
+!qemu_input_is_absolute()  s-ptr_owner != vc) {
+gd_ungrab_pointer(s);
+if (!vc-window) {
+gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s-grab_item),
+   TRUE);
+} else {
+#if 0
+/* FIXME: no way (yet) to ungrab */
+gd_grab_pointer(vc);
+#endif
+gd_update_caption(s);
+}
 return TRUE;
 }
 
@@ -1224,7 +1236,6 @@ static void gd_change_page(GtkNotebook *nb, gpointer 
arg1, guint arg2,
 }
 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(vc-menu_item),
TRUE);
-
 on_vga = (vc-type == GD_VC_GFX);
 if (!on_vga) {
 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s-grab_item),
@@ -1244,10 +1255,11 @@ static gboolean gd_enter_event(GtkWidget *widget, 
GdkEventCrossing *crossing,
 VirtualConsole *vc = opaque;
 GtkDisplayState *s = vc-s;
 
-if (!gd_is_grab_active(s)  gd_grab_on_hover(s)) {
+if (gd_grab_on_hover(s)) {
+gd_ungrab_keyboard(s);
 gd_grab_keyboard(vc);
+gd_update_caption(s);
 }
-
 return TRUE;
 }
 
@@ -1257,10 +1269,10 @@ static gboolean gd_leave_event(GtkWidget *widget, 
GdkEventCrossing *crossing,
 VirtualConsole *vc = opaque;
 GtkDisplayState *s = vc-s;
 
-if (!gd_is_grab_active(s)  gd_grab_on_hover(s)) {
+if (gd_grab_on_hover(s)) {
 gd_ungrab_keyboard(s);
+gd_update_caption(s);
 }
-
 return TRUE;
 }
 
@@ -1271,7 +1283,6 @@ static gboolean gd_focus_out_event(GtkWidget *widget,
 GtkDisplayState *s = vc-s;
 
 gtk_release_modifiers(s);
-
 return TRUE;
 }
 
-- 
1.8.3.1




[Qemu-devel] [PULL 24/24] gtk: workaround gtk2 vte resize issue

2014-05-26 Thread Gerd Hoffmann
Hack isn't pretty, but gets the job done.
See source code comment for details.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/gtk.c | 40 
 1 file changed, 40 insertions(+)

diff --git a/ui/gtk.c b/ui/gtk.c
index ac5dbe0..b908936 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -85,6 +85,20 @@
 # define VTE_CHECK_VERSION(a, b, c) 0
 #endif
 
+#if defined(CONFIG_VTE)  !GTK_CHECK_VERSION(3, 0, 0)
+/*
+ * The gtk2 vte terminal widget seriously messes up the window resize
+ * for some reason.  You basically can't make the qemu window smaller
+ * any more because the toplevel window geoemtry hints are overridden.
+ *
+ * Workaround that by hiding all vte widgets, except the one in the
+ * current tab.
+ *
+ * Luckily everything works smooth in gtk3.
+ */
+# define VTE_RESIZE_HACK 1
+#endif
+
 /* Compatibility define to let us build on both Gtk2 and Gtk3 */
 #if GTK_CHECK_VERSION(3, 0, 0)
 static inline void gdk_drawable_get_size(GdkWindow *w, gint *ww, gint *wh)
@@ -1301,10 +1315,21 @@ static void gd_change_page(GtkNotebook *nb, gpointer 
arg1, guint arg2,
 return;
 }
 
+#ifdef VTE_RESIZE_HACK
+vc = gd_vc_find_current(s);
+if (vc  vc-type == GD_VC_VTE) {
+gtk_widget_hide(vc-vte.terminal);
+}
+#endif
 vc = gd_vc_find_by_page(s, arg2);
 if (!vc) {
 return;
 }
+#ifdef VTE_RESIZE_HACK
+if (vc-type == GD_VC_VTE) {
+gtk_widget_show(vc-vte.terminal);
+}
+#endif
 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(vc-menu_item),
TRUE);
 on_vga = (vc-type == GD_VC_GFX);
@@ -1845,6 +1870,21 @@ void gtk_display_init(DisplayState *ds, bool 
full_screen, bool grab_on_hover)
 
 gtk_widget_show_all(s-window);
 
+#ifdef VTE_RESIZE_HACK
+{
+VirtualConsole *cur = gd_vc_find_current(s);
+int i;
+
+for (i = 0; i  s-nb_vcs; i++) {
+VirtualConsole *vc = s-vc[i];
+if (vc  vc-type == GD_VC_VTE  vc != cur) {
+gtk_widget_hide(vc-vte.terminal);
+}
+}
+gd_update_windowsize(cur);
+}
+#endif
+
 if (full_screen) {
 gtk_menu_item_activate(GTK_MENU_ITEM(s-full_screen_item));
 }
-- 
1.8.3.1




[Qemu-devel] [PULL 23/24] gtk: window sizing overhaul

2014-05-26 Thread Gerd Hoffmann
Major overhaul for window size handling.  This basically switches qemu
over to use geometry hints for the window manager instead of trying to
get the job done with widget resize requests.  This allows to specify
better what we need and also avoids window resizes.

FIXME: on gtk2 someone overwrites the geometry hints :(

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/gtk.c | 100 ---
 1 file changed, 70 insertions(+), 30 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 0d86025..ac5dbe0 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -74,6 +74,12 @@
 #endif
 
 #define MAX_VCS 10
+#define VC_WINDOW_X_MIN  320
+#define VC_WINDOW_Y_MIN  240
+#define VC_TERM_X_MIN 80
+#define VC_TERM_Y_MIN 25
+#define VC_SCALE_MIN0.25
+#define VC_SCALE_STEP   0.25
 
 #if !defined(CONFIG_VTE)
 # define VTE_CHECK_VERSION(a, b, c) 0
@@ -322,29 +328,63 @@ static void gd_update_caption(GtkDisplayState *s)
 g_free(prefix);
 }
 
-static void gd_update_windowsize(VirtualConsole *vc)
+static void gd_update_geometry_hints(VirtualConsole *vc)
 {
 GtkDisplayState *s = vc-s;
-double sx, sy;
+GdkWindowHints mask = 0;
+GdkGeometry geo = {};
+GtkWidget *geo_widget = NULL;
+GtkWindow *geo_window;
 
-if (vc-type != GD_VC_GFX || s-full_screen) {
-return;
+if (vc-type == GD_VC_GFX) {
+if (s-free_scale) {
+geo.min_width  = surface_width(vc-gfx.ds) * VC_SCALE_MIN;
+geo.min_height = surface_height(vc-gfx.ds) * VC_SCALE_MIN;
+mask |= GDK_HINT_MIN_SIZE;
+} else {
+geo.min_width  = surface_width(vc-gfx.ds) * vc-gfx.scale_x;
+geo.min_height = surface_height(vc-gfx.ds) * vc-gfx.scale_y;
+mask |= GDK_HINT_MIN_SIZE;
+}
+geo_widget = vc-gfx.drawing_area;
+gtk_widget_set_size_request(geo_widget, geo.min_width, geo.min_height);
+
+#if defined(CONFIG_VTE)
+} else if (vc-type == GD_VC_VTE) {
+VteTerminal *term = VTE_TERMINAL(vc-vte.terminal);
+GtkBorder *ib;
+
+geo.width_inc  = vte_terminal_get_char_width(term);
+geo.height_inc = vte_terminal_get_char_height(term);
+mask |= GDK_HINT_RESIZE_INC;
+geo.base_width  = geo.width_inc;
+geo.base_height = geo.height_inc;
+mask |= GDK_HINT_BASE_SIZE;
+geo.min_width  = geo.width_inc * VC_TERM_X_MIN;
+geo.min_height = geo.height_inc * VC_TERM_Y_MIN;
+mask |= GDK_HINT_MIN_SIZE;
+gtk_widget_style_get(vc-vte.terminal, inner-border, ib, NULL);
+geo.base_width  += ib-left + ib-right;
+geo.base_height += ib-top + ib-bottom;
+geo.min_width   += ib-left + ib-right;
+geo.min_height  += ib-top + ib-bottom;
+geo_widget = vc-vte.terminal;
+#endif
 }
 
-if (s-free_scale) {
-sx = 1.0;
-sy = 1.0;
-} else {
-sx = vc-gfx.scale_x;
-sy = vc-gfx.scale_y;
-}
-gtk_widget_set_size_request(vc-gfx.drawing_area,
-surface_width(vc-gfx.ds) * sx,
-surface_height(vc-gfx.ds) * sy);
-if (vc-window) {
-gtk_window_resize(GTK_WINDOW(vc-window), 320, 240);
-} else {
-gtk_window_resize(GTK_WINDOW(s-window), 320, 240);
+geo_window = GTK_WINDOW(vc-window ? vc-window : s-window);
+gtk_window_set_geometry_hints(geo_window, geo_widget, geo, mask);
+}
+
+static void gd_update_windowsize(VirtualConsole *vc)
+{
+GtkDisplayState *s = vc-s;
+
+gd_update_geometry_hints(vc);
+
+if (vc-type == GD_VC_GFX  !s-full_screen  !s-free_scale) {
+gtk_window_resize(GTK_WINDOW(vc-window ? vc-window : s-window),
+  VC_WINDOW_X_MIN, VC_WINDOW_Y_MIN);
 }
 }
 
@@ -991,7 +1031,7 @@ static void gd_menu_untabify(GtkMenuItem *item, void 
*opaque)
 GClosure *cb = g_cclosure_new_swap(G_CALLBACK(gd_win_grab), vc, NULL);
 gtk_accel_group_connect(ag, GDK_KEY_g, HOTKEY_MODIFIERS, 0, cb);
 
-fprintf(stderr, %s: %p\n, __func__, vc);
+gd_update_geometry_hints(vc);
 gd_update_caption(s);
 }
 }
@@ -1019,9 +1059,7 @@ static void gd_menu_full_screen(GtkMenuItem *item, void 
*opaque)
 if (vc-type == GD_VC_GFX) {
 vc-gfx.scale_x = 1.0;
 vc-gfx.scale_y = 1.0;
-gtk_widget_set_size_request(vc-gfx.drawing_area,
-surface_width(vc-gfx.ds),
-surface_height(vc-gfx.ds));
+gd_update_windowsize(vc);
 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s-grab_item),
FALSE);
 }
@@ -1038,8 +1076,8 @@ static void gd_menu_zoom_in(GtkMenuItem *item, void 
*opaque)
 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s-zoom_fit_item),
FALSE);
 
-vc-gfx.scale_x += .25;
-vc-gfx.scale_y 

[Qemu-devel] [PATCH] macio ide: Do remainder access asynchronously

2014-05-26 Thread Alexander Graf
The macio IDE controller has some pretty nasty magic in its implementation to
allow for unaligned sector accesses. We used to handle these accesses
synchronously inside the IO callback handler.

However, the block infrastructure changed below our feet and now it's impossible
to call a synchronous block read/write from the aio callback handler of a
previous block access.

Work around that limitation by making the unaligned handling bits also go
through our asynchronous handler.

This fixes booting Mac OS X for me.

Reported-by: John Arbuckle programmingk...@gmail.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 hw/ide/macio.c | 50 --
 hw/misc/macio/mac_dbdma.c  |  6 ++
 include/hw/ppc/mac_dbdma.h |  5 +
 3 files changed, 51 insertions(+), 10 deletions(-)

diff --git a/hw/ide/macio.c b/hw/ide/macio.c
index af57168..c14a1dd 100644
--- a/hw/ide/macio.c
+++ b/hw/ide/macio.c
@@ -193,6 +193,11 @@ static void pmac_ide_transfer_cb(void *opaque, int ret)
 goto done;
 }
 
+if (--io-requests) {
+/* More requests still in flight */
+return;
+}
+
 if (!m-dma_active) {
 MACIO_DPRINTF(waiting for data (%#x - %#x - %x)\n,
   s-nsector, io-len, s-status);
@@ -212,6 +217,13 @@ static void pmac_ide_transfer_cb(void *opaque, int ret)
 s-nsector -= n;
 }
 
+if (io-finish_remain_read) {
+/* Finish a stale read from the last iteration */
+io-finish_remain_read = false;
+cpu_physical_memory_write(io-finish_addr, io-remainder,
+  io-finish_len);
+}
+
 MACIO_DPRINTF(remainder: %d io-len: %d nsector: %d 
   sector_num: % PRId64 \n,
   io-remainder_len, io-len, s-nsector, sector_num);
@@ -229,7 +241,6 @@ static void pmac_ide_transfer_cb(void *opaque, int ret)
 break;
 case IDE_DMA_WRITE:
 cpu_physical_memory_read(io-addr, p, remainder_len);
-bdrv_write(s-bs, sector_num - 1, io-remainder, 1);
 break;
 case IDE_DMA_TRIM:
 break;
@@ -237,6 +248,15 @@ static void pmac_ide_transfer_cb(void *opaque, int ret)
 io-addr += remainder_len;
 io-len -= remainder_len;
 io-remainder_len -= remainder_len;
+
+if (s-dma_cmd == IDE_DMA_WRITE  !io-remainder_len) {
+io-requests++;
+qemu_iovec_reset(io-iov);
+qemu_iovec_add(io-iov, io-remainder, 0x200);
+
+m-aiocb = bdrv_aio_writev(s-bs, sector_num - 1, io-iov, 1,
+   pmac_ide_transfer_cb, io);
+}
 }
 
 if (s-nsector == 0  !io-remainder_len) {
@@ -267,20 +287,25 @@ static void pmac_ide_transfer_cb(void *opaque, int ret)
 
 switch (s-dma_cmd) {
 case IDE_DMA_READ:
-bdrv_read(s-bs, sector_num + nsector, io-remainder, 1);
-cpu_physical_memory_write(io-addr + io-len - unaligned,
-  io-remainder, unaligned);
+io-requests++;
+io-finish_addr = io-addr + io-len - unaligned;
+io-finish_len = unaligned;
+io-finish_remain_read = true;
+qemu_iovec_reset(io-iov);
+qemu_iovec_add(io-iov, io-remainder, 0x200);
+
+m-aiocb = bdrv_aio_readv(s-bs, sector_num + nsector, io-iov, 1,
+  pmac_ide_transfer_cb, io);
 break;
 case IDE_DMA_WRITE:
 /* cache the contents in our io struct */
 cpu_physical_memory_read(io-addr + io-len - unaligned,
- io-remainder, unaligned);
+ io-remainder + io-remainder_len,
+ unaligned);
 break;
 case IDE_DMA_TRIM:
 break;
 }
-
-io-len -= unaligned;
 }
 
 MACIO_DPRINTF(io-len = %#x\n, io-len);
@@ -292,10 +317,12 @@ static void pmac_ide_transfer_cb(void *opaque, int ret)
 io-remainder_len = (0x200 - unaligned)  0x1ff;
 MACIO_DPRINTF(set remainder to: %d\n, io-remainder_len);
 
-/* We would read no data from the block layer, thus not get a callback.
-   Just fake completion manually. */
+/* Only subsector reads happening */
 if (!io-len) {
-pmac_ide_transfer_cb(opaque, 0);
+if (!io-requests) {
+io-requests++;
+pmac_ide_transfer_cb(opaque, ret);
+}
 return;
 }
 
@@ -319,6 +346,8 @@ static void pmac_ide_transfer_cb(void *opaque, int ret)
DMA_DIRECTION_TO_DEVICE);
 break;
 }
+
+io-requests++;
 return;
 
 done:
@@ -374,6 +403,7 @@ static void pmac_ide_transfer(DBDMA_io *io)
 break;
 }
 
+io-requests++;
 pmac_ide_transfer_cb(io, 0);
 }
 
diff --git a/hw/misc/macio/mac_dbdma.c b/hw/misc/macio/mac_dbdma.c
index 

[Qemu-devel] [PULL 06/24] gtk: VirtualConsole restruction

2014-05-26 Thread Gerd Hoffmann
Move all vte-related items into VirtualVteConsole substruct.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/gtk.c | 119 +++
 1 file changed, 73 insertions(+), 46 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 49753ef..78f6ccc 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -105,15 +105,23 @@ static const int modifier_keycode[] = {
 0x2a, 0x36, 0x1d, 0x9d, 0x38, 0xb8, 0xdb, 0xdd,
 };
 
-typedef struct VirtualConsole
-{
-GtkWidget *menu_item;
 #if defined(CONFIG_VTE)
+typedef struct VirtualVteConsole {
 GtkWidget *box;
 GtkWidget *scrollbar;
 GtkWidget *terminal;
 CharDriverState *chr;
+} VirtualVteConsole;
+#endif
+
+typedef struct VirtualConsole {
+GtkWidget *menu_item;
+GtkWidget *tab_item;
+union {
+#if defined(CONFIG_VTE)
+VirtualVteConsole vte;
 #endif
+};
 } VirtualConsole;
 
 typedef struct GtkDisplayState
@@ -178,6 +186,36 @@ static GtkDisplayState *global_state;
 
 /** Utility Functions **/
 
+static VirtualConsole *gd_vc_find_by_menu(GtkDisplayState *s)
+{
+VirtualConsole *vc;
+gint i;
+
+for (i = 0; i  s-nb_vcs; i++) {
+vc = s-vc[i];
+if (gtk_check_menu_item_get_active
+(GTK_CHECK_MENU_ITEM(vc-menu_item))) {
+return vc;
+}
+}
+return NULL;
+}
+
+static VirtualConsole *gd_vc_find_by_page(GtkDisplayState *s, gint page)
+{
+VirtualConsole *vc;
+gint i, p;
+
+for (i = 0; i  s-nb_vcs; i++) {
+vc = s-vc[i];
+p = gtk_notebook_page_num(GTK_NOTEBOOK(s-notebook), vc-tab_item);
+if (p == page) {
+return vc;
+}
+}
+return NULL;
+}
+
 static bool gd_is_grab_active(GtkDisplayState *s)
 {
 return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s-grab_item));
@@ -817,17 +855,12 @@ static void gd_menu_switch_vc(GtkMenuItem *item, void 
*opaque)
 gtk_notebook_set_current_page(GTK_NOTEBOOK(s-notebook), page);
 } else {
 gtk_release_modifiers(s);
-#if defined(CONFIG_VTE)
-gint i;
-for (i = 0; i  s-nb_vcs; i++) {
-if 
(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s-vc[i].menu_item))) {
-page = gtk_notebook_page_num(GTK_NOTEBOOK(s-notebook),
- s-vc[i].box);
-gtk_notebook_set_current_page(GTK_NOTEBOOK(s-notebook), page);
-return;
-}
+VirtualConsole *vc = gd_vc_find_by_menu(s);
+if (vc) {
+page = gtk_notebook_page_num(GTK_NOTEBOOK(s-notebook),
+ vc-tab_item);
+gtk_notebook_set_current_page(GTK_NOTEBOOK(s-notebook), page);
 }
-#endif
 }
 }
 
@@ -1091,20 +1124,12 @@ static void gd_change_page(GtkNotebook *nb, gpointer 
arg1, guint arg2,
 if (on_vga) {
 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s-vga_item), TRUE);
 } else {
-#if defined(CONFIG_VTE)
 VirtualConsole *vc;
-gint page, i;
-for (i = 0; i  s-nb_vcs; i++) {
-vc = s-vc[i];
-page = gtk_notebook_page_num(GTK_NOTEBOOK(s-notebook), vc-box);
-if (page == arg2) {
-gtk_check_menu_item_set_active
-(GTK_CHECK_MENU_ITEM(vc-menu_item), TRUE);
-}
+vc = gd_vc_find_by_page(s, arg2);
+if (vc) {
+gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(vc-menu_item),
+   TRUE);
 }
-#else
-g_assert_not_reached();
-#endif
 }
 
 gtk_widget_set_sensitive(s-grab_item, on_vga);
@@ -1153,9 +1178,9 @@ static void gd_vc_adjustment_changed(GtkAdjustment 
*adjustment, void *opaque)
 
 if (gtk_adjustment_get_upper(adjustment) 
 gtk_adjustment_get_page_size(adjustment)) {
-gtk_widget_show(vc-scrollbar);
+gtk_widget_show(vc-vte.scrollbar);
 } else {
-gtk_widget_hide(vc-scrollbar);
+gtk_widget_hide(vc-vte.scrollbar);
 }
 }
 
@@ -1163,7 +1188,7 @@ static int gd_vc_chr_write(CharDriverState *chr, const 
uint8_t *buf, int len)
 {
 VirtualConsole *vc = chr-opaque;
 
-vte_terminal_feed(VTE_TERMINAL(vc-terminal), (const char *)buf, len);
+vte_terminal_feed(VTE_TERMINAL(vc-vte.terminal), (const char *)buf, len);
 return len;
 }
 
@@ -1189,7 +1214,7 @@ static gboolean gd_vc_in(VteTerminal *terminal, gchar 
*text, guint size,
 {
 VirtualConsole *vc = user_data;
 
-qemu_chr_be_write(vc-chr, (uint8_t  *)text, (unsigned int)size);
+qemu_chr_be_write(vc-vte.chr, (uint8_t  *)text, (unsigned int)size);
 return TRUE;
 }
 
@@ -1206,10 +1231,10 @@ static GSList *gd_vc_init(GtkDisplayState *s, 
VirtualConsole *vc, int index, GSL
 snprintf(buffer, sizeof(buffer), vc%d, index);
 snprintf(path, sizeof(path), QEMU/View/VC%d, index);
 
-vc-chr = vcs[index];
+vc-vte.chr = vcs[index];
 
-if (vc-chr-label) {
- 

Re: [Qemu-devel] [PATCH v2 3/6] target-arm: add hvc and smc exception emulation handling infrastructure

2014-05-26 Thread Peter Maydell
On 26 May 2014 05:25, Edgar E. Iglesias edgar.igles...@gmail.com wrote:
 On Thu, May 22, 2014 at 09:30:06PM -0500, Rob Herring wrote:
 From: Rob Herring rob.herr...@linaro.org

 Add the infrastructure to handle and emulate hvc and smc exceptions.
 This will enable emulation of things such as PSCI calls. This commit
 does not change the behavior and will exit with unknown exception.

 Hi Rob,

 I've got some conflicting work but am happy to rebase on top of this.
 A few comments inline.

Since this series is dependent on the PSCI patchset which includes
a header update to headers which haven't hit the kernel kvm-next
branch yet, I'm currently expecting that your initial EL2/EL3 patchset
will get in first and this will be the set that needs to rebase...

thanks
-- PMM



[Qemu-devel] [PULL 11/23] configure: Put tempfiles in a subdir of the build directory

2014-05-26 Thread Michael Tokarev
From: Peter Maydell peter.mayd...@linaro.org

When libtool support was added to configure, the new temporary files
were left out of the list of files cleaned up on exit; this results
in a lot of stale .lo files being left around in /tmp. Worse, libtool
creates a /tmp/.libs directory which we can't easily clean up.

Put all our temporary files in a single temporary directory created
as a subdirectory of the build directory, so we can easily clean it up,
and don't need fragile or complicated code for creation to avoid it
clashing with temporary directories from other instances of QEMU
configure or being subject to attack from adversaries who can write
to /tmp.

Since the temporaries now live in the build tree, we have no
need to jump through hoops with a trap handler to try to remove
them when configure exits; this fixes some weird bugs where hitting
^C during a configure run wouldn't actually make it stop, because
we would run the trap handler but then not stop. (It is possible
to get the trap handler semantics right but it is convoluted largely
because of bugs in dash, so it is simpler to just avoid it.)

Note that temporary files go in the build directory, not /tmp is
the way autoconf behaves.

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
Reviewed-by: Eric Blake ebl...@redhat.com
Signed-off-by: Michael Tokarev m...@tls.msk.ru
---
 .gitignore |1 +
 configure  |   29 -
 2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/.gitignore b/.gitignore
index 8a52709..c658613 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@
 /config-host.*
 /config-target.*
 /config.status
+/config-temp
 /trace/generated-tracers.h
 /trace/generated-tracers.c
 /trace/generated-tracers-dtrace.h
diff --git a/configure b/configure
index 678a106..cde4325 100755
--- a/configure
+++ b/configure
@@ -2,26 +2,28 @@
 #
 # qemu configure script (c) 2003 Fabrice Bellard
 #
-# set temporary file name
-if test ! -z $TMPDIR ; then
-TMPDIR1=${TMPDIR}
-elif test ! -z $TEMPDIR ; then
-TMPDIR1=${TEMPDIR}
-else
-TMPDIR1=/tmp
+
+# Temporary directory used for files created while
+# configure runs. Since it is in the build directory
+# we can safely blow away any previous version of it
+# (and we need not jump through hoops to try to delete
+# it when configure exits.)
+TMPDIR1=config-temp
+rm -rf ${TMPDIR1}
+mkdir -p ${TMPDIR1}
+if [ $? -ne 0 ]; then
+echo ERROR: failed to create temporary directory
+exit 1
 fi
 
-TMPC=${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.c
-TMPB=qemu-conf-${RANDOM}-$$-${RANDOM}
+TMPB=qemu-conf
+TMPC=${TMPDIR1}/${TMPB}.c
 TMPO=${TMPDIR1}/${TMPB}.o
 TMPCXX=${TMPDIR1}/${TMPB}.cxx
 TMPL=${TMPDIR1}/${TMPB}.lo
 TMPA=${TMPDIR1}/lib${TMPB}.la
-TMPE=${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.exe
+TMPE=${TMPDIR1}/${TMPB}.exe
 
-# NB: do not call exit in the trap handler; this is buggy with some shells;
-# see 1285349658-3122-1-git-send-email-loic.min...@linaro.org
-trap rm -f $TMPC $TMPO $TMPCXX $TMPE EXIT INT QUIT TERM
 rm -f config.log
 
 # Print a helpful header at the top of config.log
@@ -5235,3 +5237,4 @@ printf  '%s' $0 $@ config.status
 echo config.status
 chmod +x config.status
 
+rm -r $TMPDIR1
-- 
1.7.10.4




[Qemu-devel] [PULL 4/5] console: rework text terminal cursor logic

2014-05-26 Thread Gerd Hoffmann
Have a global timer.  Update all visible terminal windows syncronously.
Right now this can be the active_console only, but that will change
soon.  The global timer will disable itself if not needed, so we only
have to care start it if needed.  Which might be at console switch time
or when a new displaychangelistener is registered.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/console.c | 50 --
 1 file changed, 32 insertions(+), 18 deletions(-)

diff --git a/ui/console.c b/ui/console.c
index 85f46ae..f6ce0ef 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -143,8 +143,6 @@ struct QemuConsole {
 TextCell *cells;
 int text_x[2], text_y[2], cursor_invalidate;
 int echo;
-bool cursor_visible_phase;
-QEMUTimer *cursor_timer;
 
 int update_x0;
 int update_y0;
@@ -177,10 +175,14 @@ static DisplayState *display_state;
 static QemuConsole *active_console;
 static QemuConsole *consoles[MAX_CONSOLES];
 static int nb_consoles = 0;
+static bool cursor_visible_phase;
+static QEMUTimer *cursor_timer;
 
 static void text_console_do_init(CharDriverState *chr, DisplayState *ds);
 static void dpy_refresh(DisplayState *s);
 static DisplayState *get_alloc_displaystate(void);
+static void text_console_update_cursor_timer(void);
+static void text_console_update_cursor(void *opaque);
 
 static void gui_update(void *opaque)
 {
@@ -530,7 +532,7 @@ static void console_show_cursor(QemuConsole *s, int show)
 }
 if (y  s-height) {
 c = s-cells[y1 * s-width + x];
-if (show  s-cursor_visible_phase) {
+if (show  cursor_visible_phase) {
 TextAttributes t_attrib = s-t_attrib_default;
 t_attrib.invers = !(t_attrib.invers); /* invert fg and bg */
 vga_putcharxy(s, x, y, c-ch, t_attrib);
@@ -989,9 +991,6 @@ void console_select(unsigned int index)
 if (s) {
 DisplayState *ds = s-ds;
 
-if (active_console  active_console-cursor_timer) {
-timer_del(active_console-cursor_timer);
-}
 active_console = s;
 if (ds-have_gfx) {
 QLIST_FOREACH(dcl, ds-listeners, next) {
@@ -1008,10 +1007,7 @@ void console_select(unsigned int index)
 if (ds-have_text) {
 dpy_text_resize(s, s-width, s-height);
 }
-if (s-cursor_timer) {
-timer_mod(s-cursor_timer,
-   qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 
CONSOLE_CURSOR_PERIOD / 2);
-}
+text_console_update_cursor(NULL);
 }
 }
 
@@ -1314,6 +1310,7 @@ void register_displaychangelistener(DisplayChangeListener 
*dcl)
 dcl-ops-dpy_gfx_switch(dcl, dummy);
 }
 }
+text_console_update_cursor(NULL);
 }
 
 void update_displaychangelistener(DisplayChangeListener *dcl,
@@ -1537,6 +1534,8 @@ static DisplayState *get_alloc_displaystate(void)
 {
 if (!display_state) {
 display_state = g_new0(DisplayState, 1);
+cursor_timer = timer_new_ms(QEMU_CLOCK_REALTIME,
+text_console_update_cursor, NULL);
 }
 return display_state;
 }
@@ -1696,14 +1695,32 @@ static void text_console_set_echo(CharDriverState *chr, 
bool echo)
 s-echo = echo;
 }
 
+static void text_console_update_cursor_timer(void)
+{
+timer_mod(cursor_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME)
+  + CONSOLE_CURSOR_PERIOD / 2);
+}
+
 static void text_console_update_cursor(void *opaque)
 {
-QemuConsole *s = opaque;
+QemuConsole *s;
+int i, count = 0;
+
+cursor_visible_phase = !cursor_visible_phase;
 
-s-cursor_visible_phase = !s-cursor_visible_phase;
-graphic_hw_invalidate(s);
-timer_mod(s-cursor_timer,
-   qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 
CONSOLE_CURSOR_PERIOD / 2);
+for (i = 0; i  nb_consoles; i++) {
+s = consoles[i];
+if (qemu_console_is_graphic(s) ||
+!qemu_console_is_visible(s)) {
+continue;
+}
+count++;
+graphic_hw_invalidate(s);
+}
+
+if (count) {
+text_console_update_cursor_timer();
+}
 }
 
 static const GraphicHwOps text_console_ops = {
@@ -1739,9 +1756,6 @@ static void text_console_do_init(CharDriverState *chr, 
DisplayState *ds)
 s-surface = qemu_create_displaysurface(g_width, g_height);
 }
 
-s-cursor_timer =
-timer_new_ms(QEMU_CLOCK_REALTIME, text_console_update_cursor, s);
-
 s-hw_ops = text_console_ops;
 s-hw = s;
 
-- 
1.8.3.1




[Qemu-devel] [PULL 0/5] console: text terminal updates

2014-05-26 Thread Gerd Hoffmann
  Hi,

This pull prepares qemu text consoles (-chardev vc) for multiwindow
support.  Also some small fixes.

please pull,
  Gerd

The following changes since commit 178ac111bca16c08a79b2609ebdc75197bea976a:

  Merge remote-tracking branch 'remotes/qmp-unstable/queue/qmp' into staging 
(2014-05-22 19:04:49 +0100)

are available in the git repository at:


  git://git.kraxel.org/qemu tags/pull-console-1

for you to fetch changes up to 3f9a6e852eec56453a423a9564499fa2305f1cb4:

  console: add kbd_put_keysym_console (2014-05-26 08:41:02 +0200)


console: multiwindow support for text terminal QemuConsoles
console: small fixes


Gerd Hoffmann (4):
  console: nicer initial screen
  console: update text terminal surface unconditionally
  console: rework text terminal cursor logic
  console: add kbd_put_keysym_console

Kirill Batuzov (1):
  console: Abort on property access errors

 include/ui/console.h |   1 +
 ui/console.c | 233 ++-
 2 files changed, 118 insertions(+), 116 deletions(-)



[Qemu-devel] [PULL 3/5] console: update text terminal surface unconditionally

2014-05-26 Thread Gerd Hoffmann
These days each QemuConsole has its own private DisplaySurface,
so we can simply render updates all the time.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/console.c | 127 ++-
 1 file changed, 56 insertions(+), 71 deletions(-)

diff --git a/ui/console.c b/ui/console.c
index c6087d8..85f46ae 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -475,6 +475,9 @@ static inline void text_update_xy(QemuConsole *s, int x, 
int y)
 
 static void invalidate_xy(QemuConsole *s, int x, int y)
 {
+if (!qemu_console_is_visible(s)) {
+return;
+}
 if (s-update_x0  x * FONT_WIDTH)
 s-update_x0 = x * FONT_WIDTH;
 if (s-update_y0  y * FONT_HEIGHT)
@@ -490,25 +493,20 @@ static void update_xy(QemuConsole *s, int x, int y)
 TextCell *c;
 int y1, y2;
 
-if (!qemu_console_is_visible(s)) {
-return;
-}
-
 if (s-ds-have_text) {
 text_update_xy(s, x, y);
 }
 
-if (s-ds-have_gfx) {
-y1 = (s-y_base + y) % s-total_height;
-y2 = y1 - s-y_displayed;
-if (y2  0)
-y2 += s-total_height;
-if (y2  s-height) {
-c = s-cells[y1 * s-width + x];
-vga_putcharxy(s, x, y2, c-ch,
-  (c-t_attrib));
-invalidate_xy(s, x, y2);
-}
+y1 = (s-y_base + y) % s-total_height;
+y2 = y1 - s-y_displayed;
+if (y2  0) {
+y2 += s-total_height;
+}
+if (y2  s-height) {
+c = s-cells[y1 * s-width + x];
+vga_putcharxy(s, x, y2, c-ch,
+  (c-t_attrib));
+invalidate_xy(s, x, y2);
 }
 }
 
@@ -518,33 +516,28 @@ static void console_show_cursor(QemuConsole *s, int show)
 int y, y1;
 int x = s-x;
 
-if (!qemu_console_is_visible(s)) {
-return;
-}
-
 if (s-ds-have_text) {
 s-cursor_invalidate = 1;
 }
 
-if (s-ds-have_gfx) {
-if (x = s-width) {
-x = s-width - 1;
-}
-y1 = (s-y_base + s-y) % s-total_height;
-y = y1 - s-y_displayed;
-if (y  0)
-y += s-total_height;
-if (y  s-height) {
-c = s-cells[y1 * s-width + x];
-if (show  s-cursor_visible_phase) {
-TextAttributes t_attrib = s-t_attrib_default;
-t_attrib.invers = !(t_attrib.invers); /* invert fg and bg */
-vga_putcharxy(s, x, y, c-ch, t_attrib);
-} else {
-vga_putcharxy(s, x, y, c-ch, (c-t_attrib));
-}
-invalidate_xy(s, x, y);
+if (x = s-width) {
+x = s-width - 1;
+}
+y1 = (s-y_base + s-y) % s-total_height;
+y = y1 - s-y_displayed;
+if (y  0) {
+y += s-total_height;
+}
+if (y  s-height) {
+c = s-cells[y1 * s-width + x];
+if (show  s-cursor_visible_phase) {
+TextAttributes t_attrib = s-t_attrib_default;
+t_attrib.invers = !(t_attrib.invers); /* invert fg and bg */
+vga_putcharxy(s, x, y, c-ch, t_attrib);
+} else {
+vga_putcharxy(s, x, y, c-ch, (c-t_attrib));
 }
+invalidate_xy(s, x, y);
 }
 }
 
@@ -554,10 +547,6 @@ static void console_refresh(QemuConsole *s)
 TextCell *c;
 int x, y, y1;
 
-if (!qemu_console_is_visible(s)) {
-return;
-}
-
 if (s-ds-have_text) {
 s-text_x[0] = 0;
 s-text_y[0] = 0;
@@ -566,25 +555,23 @@ static void console_refresh(QemuConsole *s)
 s-cursor_invalidate = 1;
 }
 
-if (s-ds-have_gfx) {
-vga_fill_rect(s, 0, 0, surface_width(surface), surface_height(surface),
-  color_table_rgb[0][COLOR_BLACK]);
-y1 = s-y_displayed;
-for (y = 0; y  s-height; y++) {
-c = s-cells + y1 * s-width;
-for (x = 0; x  s-width; x++) {
-vga_putcharxy(s, x, y, c-ch,
-  (c-t_attrib));
-c++;
-}
-if (++y1 == s-total_height) {
-y1 = 0;
-}
+vga_fill_rect(s, 0, 0, surface_width(surface), surface_height(surface),
+  color_table_rgb[0][COLOR_BLACK]);
+y1 = s-y_displayed;
+for (y = 0; y  s-height; y++) {
+c = s-cells + y1 * s-width;
+for (x = 0; x  s-width; x++) {
+vga_putcharxy(s, x, y, c-ch,
+  (c-t_attrib));
+c++;
+}
+if (++y1 == s-total_height) {
+y1 = 0;
 }
-console_show_cursor(s, 1);
-dpy_gfx_update(s, 0, 0,
-   surface_width(surface), surface_height(surface));
 }
+console_show_cursor(s, 1);
+dpy_gfx_update(s, 0, 0,
+   surface_width(surface), surface_height(surface));
 }
 
 static void console_scroll(QemuConsole *s, int ydelta)
@@ -640,7 +627,7 @@ static void console_put_lf(QemuConsole *s)
 c-t_attrib = 

[Qemu-devel] [PATCH trivial v2 0/4] Cadence GEM patches

2014-05-26 Thread Peter Crosthwaite

Hi Michael,

Found a bug in the Cadence GEM. Fixed in P1. Have some follow up
trivials as well (P2-4).

Changed since v1:
Addressed mjt review
Dropped top comment patch (applied to trivial already).
Fixed other foo[0] usages

Regards,
Peter


Peter Crosthwaite (4):
  net: cadence_gem: Fix Tx descriptor update
  net: cadence_gem: Add Tx descriptor fetch printf
  net: cadence_gem: Comment spelling sweep
  net: cadence_gem: Remove desc[0] usages

 hw/net/cadence_gem.c | 31 ++-
 1 file changed, 18 insertions(+), 13 deletions(-)

-- 
1.9.3.1.ga73a6ad




[Qemu-devel] [PULL 1/5] console: Abort on property access errors

2014-05-26 Thread Gerd Hoffmann
From: Kirill Batuzov batuz...@ispras.ru

All defined properties of QemuConsole are mandatory and no access to them
should fail. Nevertheless not checking returned errors is bad because in case
of unexpected failure it will hide the bug and cause a memory leak.

Abort in case of unexpected property access errors. This change exposed a bug
where an attempt was made to write to a read-only property head.

Set head property's value at creation time and do not attempt to change it
later. This fixes the bug mentioned above.

Signed-off-by: Kirill Batuzov batuz...@ispras.ru
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/console.c | 30 +-
 1 file changed, 13 insertions(+), 17 deletions(-)

diff --git a/ui/console.c b/ui/console.c
index 34d1eaa..c92df8b 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -1167,9 +1167,9 @@ static void text_console_update(void *opaque, 
console_ch_t *chardata)
 }
 }
 
-static QemuConsole *new_console(DisplayState *ds, console_type_t console_type)
+static QemuConsole *new_console(DisplayState *ds, console_type_t console_type,
+uint32_t head)
 {
-Error *local_err = NULL;
 Object *obj;
 QemuConsole *s;
 int i;
@@ -1179,13 +1179,14 @@ static QemuConsole *new_console(DisplayState *ds, 
console_type_t console_type)
 
 obj = object_new(TYPE_QEMU_CONSOLE);
 s = QEMU_CONSOLE(obj);
+s-head = head;
 object_property_add_link(obj, device, TYPE_DEVICE,
  (Object **)s-device,
  object_property_allow_set_link,
  OBJ_PROP_LINK_UNREF_ON_RELEASE,
- local_err);
+ error_abort);
 object_property_add_uint32_ptr(obj, head,
-   s-head, local_err);
+   s-head, error_abort);
 
 if (!active_console || ((active_console-console_type != GRAPHIC_CONSOLE) 

 (console_type == GRAPHIC_CONSOLE))) {
@@ -1560,7 +1561,6 @@ static DisplayState *get_alloc_displaystate(void)
  */
 DisplayState *init_displaystate(void)
 {
-Error *local_err = NULL;
 gchar *name;
 int i;
 
@@ -1579,7 +1579,7 @@ DisplayState *init_displaystate(void)
  * doesn't change any more */
 name = g_strdup_printf(console[%d], i);
 object_property_add_child(container_get(object_get_root(), /backend),
-  name, OBJECT(consoles[i]), local_err);
+  name, OBJECT(consoles[i]), error_abort);
 g_free(name);
 }
 
@@ -1590,7 +1590,6 @@ QemuConsole *graphic_console_init(DeviceState *dev, 
uint32_t head,
   const GraphicHwOps *hw_ops,
   void *opaque)
 {
-Error *local_err = NULL;
 int width = 640;
 int height = 480;
 QemuConsole *s;
@@ -1598,14 +1597,12 @@ QemuConsole *graphic_console_init(DeviceState *dev, 
uint32_t head,
 
 ds = get_alloc_displaystate();
 trace_console_gfx_new();
-s = new_console(ds, GRAPHIC_CONSOLE);
+s = new_console(ds, GRAPHIC_CONSOLE, head);
 s-hw_ops = hw_ops;
 s-hw = opaque;
 if (dev) {
-object_property_set_link(OBJECT(s), OBJECT(dev),
- device, local_err);
-object_property_set_int(OBJECT(s), head,
-head, local_err);
+object_property_set_link(OBJECT(s), OBJECT(dev), device,
+ error_abort);
 }
 
 s-surface = qemu_create_displaysurface(width, height);
@@ -1622,7 +1619,6 @@ QemuConsole *qemu_console_lookup_by_index(unsigned int 
index)
 
 QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head)
 {
-Error *local_err = NULL;
 Object *obj;
 uint32_t h;
 int i;
@@ -1632,12 +1628,12 @@ QemuConsole *qemu_console_lookup_by_device(DeviceState 
*dev, uint32_t head)
 continue;
 }
 obj = object_property_get_link(OBJECT(consoles[i]),
-   device, local_err);
+   device, error_abort);
 if (DEVICE(obj) != dev) {
 continue;
 }
 h = object_property_get_int(OBJECT(consoles[i]),
-head, local_err);
+head, error_abort);
 if (h != head) {
 continue;
 }
@@ -1811,9 +1807,9 @@ static CharDriverState *text_console_init(ChardevVC *vc)
 
 trace_console_txt_new(width, height);
 if (width == 0 || height == 0) {
-s = new_console(NULL, TEXT_CONSOLE);
+s = new_console(NULL, TEXT_CONSOLE, 0);
 } else {
-s = new_console(NULL, TEXT_CONSOLE_FIXED_SIZE);
+s = new_console(NULL, TEXT_CONSOLE_FIXED_SIZE, 0);
 s-surface = qemu_create_displaysurface(width, height);
 }
 
-- 
1.8.3.1




[Qemu-devel] [PULL 2/5] console: nicer initial screen

2014-05-26 Thread Gerd Hoffmann
Now that we have a function to create a fancy DisplaySurface with a
message for the user, to handle non-existing graphics hardware, we
can make it more generic and use it for other things too.

This patch adds a text line to the in initial DisplaySurface, notifying
the user that the display isn't initialized yet by the guest.

You can see this in action when starting qemu with '-S'.  Also when
booting ovmf in qemu (which needs a few moments to initialize itself
before it initializes the vga).

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/console.c | 19 +++
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/ui/console.c b/ui/console.c
index c92df8b..c6087d8 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -1271,19 +1271,18 @@ DisplaySurface *qemu_create_displaysurface_from(int 
width, int height, int bpp,
 return surface;
 }
 
-static DisplaySurface *qemu_create_dummy_surface(void)
+static DisplaySurface *qemu_create_message_surface(int w, int h,
+   const char *msg)
 {
-static const char msg[] =
-This VM has no graphic display device.;
-DisplaySurface *surface = qemu_create_displaysurface(640, 480);
+DisplaySurface *surface = qemu_create_displaysurface(w, h);
 pixman_color_t bg = color_table_rgb[0][COLOR_BLACK];
 pixman_color_t fg = color_table_rgb[0][COLOR_WHITE];
 pixman_image_t *glyph;
 int len, x, y, i;
 
 len = strlen(msg);
-x = (640/FONT_WIDTH  - len) / 2;
-y = (480/FONT_HEIGHT - 1)   / 2;
+x = (w / FONT_WIDTH  - len) / 2;
+y = (h / FONT_HEIGHT - 1)   / 2;
 for (i = 0; i  len; i++) {
 glyph = qemu_pixman_glyph_from_vgafont(FONT_HEIGHT, vgafont16, msg[i]);
 qemu_pixman_glyph_render(glyph, surface-image, fg, bg,
@@ -1305,6 +1304,8 @@ void qemu_free_displaysurface(DisplaySurface *surface)
 
 void register_displaychangelistener(DisplayChangeListener *dcl)
 {
+static const char nodev[] =
+This VM has no graphic display device.;
 static DisplaySurface *dummy;
 QemuConsole *con;
 
@@ -1323,7 +1324,7 @@ void register_displaychangelistener(DisplayChangeListener 
*dcl)
 dcl-ops-dpy_gfx_switch(dcl, con-surface);
 } else {
 if (!dummy) {
-dummy = qemu_create_dummy_surface();
+dummy = qemu_create_message_surface(640, 480, nodev);
 }
 dcl-ops-dpy_gfx_switch(dcl, dummy);
 }
@@ -1590,6 +1591,8 @@ QemuConsole *graphic_console_init(DeviceState *dev, 
uint32_t head,
   const GraphicHwOps *hw_ops,
   void *opaque)
 {
+static const char noinit[] =
+Guest has not initialized the display (yet).;
 int width = 640;
 int height = 480;
 QemuConsole *s;
@@ -1605,7 +1608,7 @@ QemuConsole *graphic_console_init(DeviceState *dev, 
uint32_t head,
  error_abort);
 }
 
-s-surface = qemu_create_displaysurface(width, height);
+s-surface = qemu_create_message_surface(width, height, noinit);
 return s;
 }
 
-- 
1.8.3.1




[Qemu-devel] [PATCH trivial v2 1/4] net: cadence_gem: Fix Tx descriptor update

2014-05-26 Thread Peter Crosthwaite
The local variable desc was being used to read-modify-write the
first descriptor (of a multi-desc packet) upon packet completion.
desc however continues to be used by the code as the current
descriptor. Give this first desc RMW it's own local variable to
avoid trampling.

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---
changed since v1 (MJT review):
Removed foo[0] usage
Corrected sizeof(desc) to sizeof(desc_first)

 hw/net/cadence_gem.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
index 47e7038..1721fb7 100644
--- a/hw/net/cadence_gem.c
+++ b/hw/net/cadence_gem.c
@@ -911,14 +911,16 @@ static void gem_transmit(GemState *s)
 
 /* Last descriptor for this packet; hand the whole thing off */
 if (tx_desc_get_last(desc)) {
+unsigneddesc_first[2];
+
 /* Modify the 1st descriptor of this packet to be owned by
  * the processor.
  */
-cpu_physical_memory_read(s-tx_desc_addr,
- (uint8_t *)desc[0], sizeof(desc));
-tx_desc_set_used(desc);
-cpu_physical_memory_write(s-tx_desc_addr,
-  (uint8_t *)desc[0], sizeof(desc));
+cpu_physical_memory_read(s-tx_desc_addr, (uint8_t *)desc_first,
+ sizeof(desc_first));
+tx_desc_set_used(desc_first);
+cpu_physical_memory_write(s-tx_desc_addr, (uint8_t *)desc_first,
+  sizeof(desc_first));
 /* Advance the hardare current descriptor past this packet */
 if (tx_desc_get_wrap(desc)) {
 s-tx_desc_addr = s-regs[GEM_TXQBASE];
-- 
1.9.3.1.ga73a6ad




[Qemu-devel] [PATCH trivial v2 3/4] net: cadence_gem: Comment spelling sweep

2014-05-26 Thread Peter Crosthwaite
Fix some typos in comments.

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

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

diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
index f0e9f5b..7cd4b54 100644
--- a/hw/net/cadence_gem.c
+++ b/hw/net/cadence_gem.c
@@ -50,7 +50,7 @@
 #define GEM_IER   (0x0028/4) /* Interrupt Enable reg */
 #define GEM_IDR   (0x002C/4) /* Interrupt Disable reg */
 #define GEM_IMR   (0x0030/4) /* Interrupt Mask reg */
-#define GEM_PHYMNTNC  (0x0034/4) /* Phy Maintaince reg */
+#define GEM_PHYMNTNC  (0x0034/4) /* Phy Maintenance reg */
 #define GEM_RXPAUSE   (0x0038/4) /* RX Pause Time reg */
 #define GEM_TXPAUSE   (0x003C/4) /* TX Pause Time reg */
 #define GEM_TXPARTIALSF   (0x0040/4) /* TX Partial Store and Forward */
@@ -150,7 +150,7 @@
 #define GEM_NWCTRL_LOCALLOOP   0x0002 /* Local Loopback */
 
 #define GEM_NWCFG_STRIP_FCS0x0002 /* Strip FCS field */
-#define GEM_NWCFG_LERR_DISC0x0001 /* Discard RX frames with lenth err 
*/
+#define GEM_NWCFG_LERR_DISC0x0001 /* Discard RX frames with len err */
 #define GEM_NWCFG_BUFF_OFST_M  0xC000 /* Receive buffer offset mask */
 #define GEM_NWCFG_BUFF_OFST_S  14 /* Receive buffer offset shift */
 #define GEM_NWCFG_UCAST_HASH   0x0080 /* accept unicast if hash match */
@@ -397,7 +397,7 @@ static const uint8_t broadcast_addr[] = { 0xFF, 0xFF, 0xFF, 
0xFF, 0xFF, 0xFF };
  */
 static void gem_init_register_masks(GemState *s)
 {
-/* Mask of register bits which are read only*/
+/* Mask of register bits which are read only */
 memset(s-regs_ro[0], 0, sizeof(s-regs_ro));
 s-regs_ro[GEM_NWCTRL]   = 0xFFF8;
 s-regs_ro[GEM_NWSTATUS] = 0x;
@@ -719,7 +719,7 @@ static ssize_t gem_receive(NetClientState *nc, const 
uint8_t *buf, size_t size)
 unsigned crc_val;
 
 /* The application wants the FCS field, which QEMU does not provide.
- * We must try and caclculate one.
+ * We must try and calculate one.
  */
 
 memcpy(rxbuf, buf, size);
@@ -871,7 +871,7 @@ static void gem_transmit(GemState *s)
 
 DB_PRINT(\n);
 
-/* The packet we will hand off to qemu.
+/* The packet we will hand off to QEMU.
  * Packets scattered across multiple descriptors are gathered to this
  * one contiguous buffer first.
  */
@@ -923,7 +923,7 @@ static void gem_transmit(GemState *s)
 tx_desc_set_used(desc_first);
 cpu_physical_memory_write(s-tx_desc_addr, (uint8_t *)desc_first,
   sizeof(desc_first));
-/* Advance the hardare current descriptor past this packet */
+/* Advance the hardware current descriptor past this packet */
 if (tx_desc_get_wrap(desc)) {
 s-tx_desc_addr = s-regs[GEM_TXQBASE];
 } else {
-- 
1.9.3.1.ga73a6ad




[Qemu-devel] [PATCH trivial v2 2/4] net: cadence_gem: Add Tx descriptor fetch printf

2014-05-26 Thread Peter Crosthwaite
Add a debug printf for TX descriptor fetching. This helpful to anyone
needing to debug TX ring buffer traversal. Its also now consistent with
the RX code which has a similar printf.

Signed-off-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
---
changed since v1:
don't cast to unsigned (mjt review).

 hw/net/cadence_gem.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
index 1721fb7..f0e9f5b 100644
--- a/hw/net/cadence_gem.c
+++ b/hw/net/cadence_gem.c
@@ -880,6 +880,8 @@ static void gem_transmit(GemState *s)
 
 /* read current descriptor */
 packet_desc_addr = s-tx_desc_addr;
+
+DB_PRINT(read descriptor 0x% HWADDR_PRIx \n, packet_desc_addr);
 cpu_physical_memory_read(packet_desc_addr,
  (uint8_t *)desc[0], sizeof(desc));
 /* Handle all descriptors owned by hardware */
@@ -962,6 +964,7 @@ static void gem_transmit(GemState *s)
 } else {
 packet_desc_addr += 8;
 }
+DB_PRINT(read descriptor 0x% HWADDR_PRIx \n, packet_desc_addr);
 cpu_physical_memory_read(packet_desc_addr,
  (uint8_t *)desc[0], sizeof(desc));
 }
-- 
1.9.3.1.ga73a6ad




[Qemu-devel] [PULL 03/10] xhci: add xhci_get_flag

2014-05-26 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-xhci.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index a203bc6..54dea16 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -621,6 +621,11 @@ static const char *ep_state_name(uint32_t state)
ARRAY_SIZE(ep_state_names));
 }
 
+static bool xhci_get_flag(XHCIState *xhci, enum xhci_flags bit)
+{
+return xhci-flags  (1  bit);
+}
+
 static uint64_t xhci_mfindex_get(XHCIState *xhci)
 {
 int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
@@ -3599,10 +3604,10 @@ static int usb_xhci_initfn(struct PCIDevice *dev)
 assert(ret = 0);
 }
 
-if (xhci-flags  (1  XHCI_FLAG_USE_MSI)) {
+if (xhci_get_flag(xhci, XHCI_FLAG_USE_MSI)) {
 msi_init(dev, 0x70, xhci-numintrs, true, false);
 }
-if (xhci-flags  (1  XHCI_FLAG_USE_MSI_X)) {
+if (xhci_get_flag(xhci, XHCI_FLAG_USE_MSI_X)) {
 msix_init(dev, xhci-numintrs,
   xhci-mem, 0, OFF_MSIX_TABLE,
   xhci-mem, 0, OFF_MSIX_PBA,
-- 
1.8.3.1




[Qemu-devel] [PULL 00/10] usb queue: usb3 streams, xhci + mtp fixes

2014-05-26 Thread Gerd Hoffmann
  Hi,

Finally support for usb3 streams is coming.  The depending bits landed
upstream (kernel 3.15, libusbx 1.0.19, usbredir 0.7), time to get the
qemu support upstream too.

This pull also has some xhci and mtp bugfixes.

please pull,
  Gerd

The following changes since commit 178ac111bca16c08a79b2609ebdc75197bea976a:

  Merge remote-tracking branch 'remotes/qmp-unstable/queue/qmp' into staging 
(2014-05-22 19:04:49 +0100)

are available in the git repository at:


  git://git.kraxel.org/qemu tags/pull-usb-7

for you to fetch changes up to 8d1bd3c901a315db09b495fa9d5b87641bd9:

  usb-host-libusb: Set stream id when submitting bulk-stream transfers 
(2014-05-26 08:41:07 +0200)


usb: usb3 streams support for usb-host and usb-redir
usb: xhci and mtp bugfixes.


Gerd Hoffmann (6):
  xhci: child detach fix
  xhci: add endpoint cap on express bus only
  xhci: add xhci_get_flag
  usb-mtp: use bool to track MTPObject init status
  usb-mtp: handle lseek failure
  usb-mtp: handle usb_mtp_get_object failure

Hans de Goede (4):
  usb-redir: Add support for bulk streams
  usb-host-libusb: Fill in endpoint max_streams when available
  usb-host-libusb: Add alloc / free streams ops
  usb-host-libusb: Set stream id when submitting bulk-stream transfers

 hw/usb/dev-mtp.c |  28 +++
 hw/usb/hcd-xhci.c|  17 +--
 hw/usb/host-libusb.c |  83 +--
 hw/usb/redirect.c| 137 +--
 4 files changed, 242 insertions(+), 23 deletions(-)



[Qemu-devel] [PULL 04/10] usb-mtp: use bool to track MTPObject init status

2014-05-26 Thread Gerd Hoffmann
Stop setting nchildren to -1.  Use separate bool variable to track
whenever we've already fetched the child objects instead.

Also make nchildren unsigned.

Cc: Dr. David Alan Gilbert dgilb...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/dev-mtp.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 943f930..c2750e4 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -109,7 +109,8 @@ struct MTPObject {
 struct stat  stat;
 MTPObject*parent;
 MTPObject**children;
-int32_t  nchildren;
+uint32_t nchildren;
+bool have_children;
 QTAILQ_ENTRY(MTPObject) next;
 };
 
@@ -273,7 +274,6 @@ static MTPObject *usb_mtp_object_alloc(MTPState *s, 
uint32_t handle,
 o-handle = handle;
 o-parent = parent;
 o-name = g_strdup(name);
-o-nchildren = -1;
 if (parent == NULL) {
 o-path = g_strdup(name);
 } else {
@@ -340,7 +340,11 @@ static void usb_mtp_object_readdir(MTPState *s, MTPObject 
*o)
 struct dirent *entry;
 DIR *dir;
 
-o-nchildren = 0;
+if (o-have_children) {
+return;
+}
+o-have_children = true;
+
 dir = opendir(o-path);
 if (!dir) {
 return;
@@ -789,9 +793,7 @@ static void usb_mtp_command(MTPState *s, MTPControl *c)
  c-trans, 0, 0, 0);
 return;
 }
-if (o-nchildren == -1) {
-usb_mtp_object_readdir(s, o);
-}
+usb_mtp_object_readdir(s, o);
 if (c-code == CMD_GET_NUM_OBJECTS) {
 trace_usb_mtp_op_get_num_objects(s-dev.addr, o-handle, o-path);
 nres = 1;
-- 
1.8.3.1




[Qemu-devel] [PULL 09/10] usb-host-libusb: Add alloc / free streams ops

2014-05-26 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

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

diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
index 3fdbd93..401eb74 100644
--- a/hw/usb/host-libusb.c
+++ b/hw/usb/host-libusb.c
@@ -1280,6 +1280,54 @@ static void usb_host_handle_reset(USBDevice *udev)
 }
 }
 
+static int usb_host_alloc_streams(USBDevice *udev, USBEndpoint **eps,
+  int nr_eps, int streams)
+{
+#if LIBUSBX_API_VERSION = 0x01000103
+USBHostDevice *s = USB_HOST_DEVICE(udev);
+unsigned char endpoints[30];
+int i, rc;
+
+for (i = 0; i  nr_eps; i++) {
+endpoints[i] = eps[i]-nr;
+if (eps[i]-pid == USB_TOKEN_IN) {
+endpoints[i] |= 0x80;
+}
+}
+rc = libusb_alloc_streams(s-dh, streams, endpoints, nr_eps);
+if (rc  0) {
+usb_host_libusb_error(libusb_alloc_streams, rc);
+} else if (rc != streams) {
+fprintf(stderr,
+libusb_alloc_streams: got less streams then requested %d  %d\n,
+rc, streams);
+}
+
+return (rc == streams) ? 0 : -1;
+#else
+fprintf(stderr, libusb_alloc_streams: error not implemented\n);
+return -1;
+#endif
+}
+
+static void usb_host_free_streams(USBDevice *udev, USBEndpoint **eps,
+  int nr_eps)
+{
+#if LIBUSBX_API_VERSION = 0x01000103
+USBHostDevice *s = USB_HOST_DEVICE(udev);
+unsigned char endpoints[30];
+int i;
+
+for (i = 0; i  nr_eps; i++) {
+endpoints[i] = eps[i]-nr;
+if (eps[i]-pid == USB_TOKEN_IN) {
+endpoints[i] |= 0x80;
+}
+}
+libusb_free_streams(s-dh, endpoints, nr_eps);
+#endif
+}
+
 /*
  * This is *NOT* about restoring state.  We have absolutely no idea
  * what state the host device is in at the moment and whenever it is
@@ -1361,6 +1409,8 @@ static void usb_host_class_initfn(ObjectClass *klass, 
void *data)
 uc-handle_reset   = usb_host_handle_reset;
 uc-handle_destroy = usb_host_handle_destroy;
 uc-flush_ep_queue = usb_host_flush_ep_queue;
+uc-alloc_streams  = usb_host_alloc_streams;
+uc-free_streams   = usb_host_free_streams;
 dc-vmsd = vmstate_usb_host;
 dc-props = usb_host_dev_properties;
 set_bit(DEVICE_CATEGORY_BRIDGE, dc-categories);
-- 
1.8.3.1




[Qemu-devel] [PULL 02/10] xhci: add endpoint cap on express bus only

2014-05-26 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-xhci.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 6753a42..a203bc6 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -3594,8 +3594,10 @@ static int usb_xhci_initfn(struct PCIDevice *dev)
  
PCI_BASE_ADDRESS_SPACE_MEMORY|PCI_BASE_ADDRESS_MEM_TYPE_64,
  xhci-mem);
 
-ret = pcie_endpoint_cap_init(dev, 0xa0);
-assert(ret = 0);
+if (pci_bus_is_express(dev-bus)) {
+ret = pcie_endpoint_cap_init(dev, 0xa0);
+assert(ret = 0);
+}
 
 if (xhci-flags  (1  XHCI_FLAG_USE_MSI)) {
 msi_init(dev, 0x70, xhci-numintrs, true, false);
-- 
1.8.3.1




[Qemu-devel] [PULL 08/10] usb-host-libusb: Fill in endpoint max_streams when available

2014-05-26 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

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

diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
index 57bed09..3fdbd93 100644
--- a/hw/usb/host-libusb.c
+++ b/hw/usb/host-libusb.c
@@ -720,6 +720,9 @@ static void usb_host_ep_update(USBHostDevice *s)
 struct libusb_config_descriptor *conf;
 const struct libusb_interface_descriptor *intf;
 const struct libusb_endpoint_descriptor *endp;
+#if LIBUSBX_API_VERSION = 0x01000103
+struct libusb_ss_endpoint_companion_descriptor *endp_ss_comp;
+#endif
 uint8_t devep, type;
 int pid, ep;
 int rc, i, e;
@@ -765,6 +768,15 @@ static void usb_host_ep_update(USBHostDevice *s)
 usb_ep_set_type(udev, pid, ep, type);
 usb_ep_set_ifnum(udev, pid, ep, i);
 usb_ep_set_halted(udev, pid, ep, 0);
+#if LIBUSBX_API_VERSION = 0x01000103
+if (type == LIBUSB_TRANSFER_TYPE_BULK 
+libusb_get_ss_endpoint_companion_descriptor(ctx, endp,
+endp_ss_comp) == LIBUSB_SUCCESS) {
+usb_ep_set_max_streams(udev, pid, ep,
+   endp_ss_comp-bmAttributes);
+libusb_free_ss_endpoint_companion_descriptor(endp_ss_comp);
+}
+#endif
 }
 }
 
-- 
1.8.3.1




[Qemu-devel] [PULL 01/10] xhci: child detach fix

2014-05-26 Thread Gerd Hoffmann
xhci_child_detach() zaps the wrong slot when unplugging a device
connected via usb-hub:  Instead of the device's slot the slot of the
usb-hub is used.  Fix it.

https://bugzilla.redhat.com/show_bug.cgi?id=1075846

Signed-off-by: Gerd Hoffmann kra...@redhat.com
Reviewed-by: Gonglei arei.gong...@huawei.com
---
 hw/usb/hcd-xhci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index ef3177a..6753a42 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -3435,7 +3435,7 @@ static void xhci_child_detach(USBPort *uport, USBDevice 
*child)
 USBBus *bus = usb_bus_from_device(child);
 XHCIState *xhci = container_of(bus, XHCIState, bus);
 
-xhci_detach_slot(xhci, uport);
+xhci_detach_slot(xhci, child-port);
 }
 
 static USBPortOps xhci_uport_ops = {
-- 
1.8.3.1




[Qemu-devel] [PATCH trivial v2 4/4] net: cadence_gem: Remove desc[0] usages

2014-05-26 Thread Peter Crosthwaite
Just use desc instead.

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

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

diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
index 7cd4b54..7d3355e 100644
--- a/hw/net/cadence_gem.c
+++ b/hw/net/cadence_gem.c
@@ -883,7 +883,7 @@ static void gem_transmit(GemState *s)
 
 DB_PRINT(read descriptor 0x% HWADDR_PRIx \n, packet_desc_addr);
 cpu_physical_memory_read(packet_desc_addr,
- (uint8_t *)desc[0], sizeof(desc));
+ (uint8_t *)desc, sizeof(desc));
 /* Handle all descriptors owned by hardware */
 while (tx_desc_get_used(desc) == 0) {
 
@@ -966,7 +966,7 @@ static void gem_transmit(GemState *s)
 }
 DB_PRINT(read descriptor 0x% HWADDR_PRIx \n, packet_desc_addr);
 cpu_physical_memory_read(packet_desc_addr,
- (uint8_t *)desc[0], sizeof(desc));
+ (uint8_t *)desc, sizeof(desc));
 }
 
 if (tx_desc_get_used(desc)) {
-- 
1.9.3.1.ga73a6ad




[Qemu-devel] [PULL 05/10] usb-mtp: handle lseek failure

2014-05-26 Thread Gerd Hoffmann
Cc: Dr. David Alan Gilbert dgilb...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/dev-mtp.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index c2750e4..a95298b 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -702,7 +702,10 @@ static MTPData *usb_mtp_get_partial_object(MTPState *s, 
MTPControl *c,
 if (offset  o-stat.st_size) {
 offset = o-stat.st_size;
 }
-lseek(d-fd, offset, SEEK_SET);
+if (lseek(d-fd, offset, SEEK_SET)  0) {
+usb_mtp_data_free(d);
+return NULL;
+}
 
 d-length = c-argv[2];
 if (d-length  o-stat.st_size - offset) {
-- 
1.8.3.1




Re: [Qemu-devel] Disk image fuzz testing (OPW)

2014-05-26 Thread Kevin Wolf
Hi Maria,

Am 26.05.2014 um 07:07 hat M.Kustova geschrieben:
 My name is Maria and  I'm a participant of the Outreach Program for Women.
 My project is fuzz testing of support of qcow2 image format.
 
 The project git:
 https://github.com/maxalab/qemu_fuzzer.git
 
 It's pubic, so welcome, make yourself at home.

Thanks for sharing this. I read your requirements file and have a
question or two.

The first is about what actions are. You define it as structure
elements retrieved from an image format or element of an image
structure, which unfortunately doesn't make things much clearer to me.
My guess is that you mean a data structure (like header, L1 table,
refcount block, etc.) and this is the structure that is going to be
modified during the fuzzing? Is this right?

The other thing is that you seem to concentrate on generating test image
(and probably rightly so), but there's also the part that you need to
use that image for something, i.e. using the right actions with qemu to
actually test it against that image in a meaningful way (for example,
corrupting a snapshot's L1 table isn't interesting as long as this
snapshot isn't touched). What are your plans for determining what test
to run against the generated test images?

Also, if you don't mind, I'd like to be CCed on your further emails
about this project.

Kevin



[Qemu-devel] [PULL] target-xtensa: fix cross-page jumps/calls at the end of TB

2014-05-26 Thread Max Filippov
Hi Peter,

please pull my fixes series for target-xtensa.
The following changes since commit 178ac111bca16c08a79b2609ebdc75197bea976a:

  Merge remote-tracking branch 'remotes/qmp-unstable/queue/qmp' into staging 
(2014-05-22 19:04:49 +0100)

are available in the git repository at:


  git://github.com/OSLL/qemu-xtensa.git tags/20140526-xtensa

for you to fetch changes up to 57a740514d2f68330ae408894b4c5ab01cfb0a83:

  target-xtensa: add tests for cross-page TB (2014-05-26 12:33:54 +0400)


Xtensa fixes queue 2014-05-26:
- fix cross-page jumps/calls at the end of TB;
- add tests for TBs and instructions crossing page boundary.


Max Filippov (3):
  target-xtensa: fix cross-page jumps/calls at the end of TB
  target-xtensa: completely clean TLB between MMU tests
  target-xtensa: add tests for cross-page TB

 target-xtensa/translate.c   |   4 +-
 tests/tcg/xtensa/test_mmu.S | 246 ++--
 2 files changed, 241 insertions(+), 9 deletions(-)



[Qemu-devel] [PULL 10/10] usb-host-libusb: Set stream id when submitting bulk-stream transfers

2014-05-26 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

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

diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
index 401eb74..8007d1d 100644
--- a/hw/usb/host-libusb.c
+++ b/hw/usb/host-libusb.c
@@ -1214,10 +1214,23 @@ static void usb_host_handle_data(USBDevice *udev, 
USBPacket *p)
 usb_packet_copy(p, r-buffer, size);
 }
 ep = p-ep-nr | (r-in ? USB_DIR_IN : 0);
-libusb_fill_bulk_transfer(r-xfer, s-dh, ep,
-  r-buffer, size,
-  usb_host_req_complete_data, r,
-  BULK_TIMEOUT);
+if (p-stream) {
+#if LIBUSBX_API_VERSION = 0x01000103
+libusb_fill_bulk_stream_transfer(r-xfer, s-dh, ep, p-stream,
+ r-buffer, size,
+ usb_host_req_complete_data, r,
+ BULK_TIMEOUT);
+#else
+usb_host_req_free(r);
+p-status = USB_RET_STALL;
+return;
+#endif
+} else {
+libusb_fill_bulk_transfer(r-xfer, s-dh, ep,
+  r-buffer, size,
+  usb_host_req_complete_data, r,
+  BULK_TIMEOUT);
+}
 break;
 case USB_ENDPOINT_XFER_INT:
 r = usb_host_req_alloc(s, p, p-pid == USB_TOKEN_IN, p-iov.size);
-- 
1.8.3.1




[Qemu-devel] [PULL 07/10] usb-redir: Add support for bulk streams

2014-05-26 Thread Gerd Hoffmann
From: Hans de Goede hdego...@redhat.com

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

diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index 287a505..4c6187b 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -50,6 +50,10 @@
((i)  0x10) ? USB_TOKEN_IN : USB_TOKEN_OUT, \
(i)  0x0f))
 
+#ifndef USBREDIR_VERSION /* This is not defined in older usbredir versions */
+#define USBREDIR_VERSION 0
+#endif
+
 typedef struct USBRedirDevice USBRedirDevice;
 
 /* Struct to hold buffered packets */
@@ -68,6 +72,7 @@ struct endp_data {
 uint8_t interval;
 uint8_t interface; /* bInterfaceNumber this ep belongs to */
 uint16_t max_packet_size; /* In bytes, not wMaxPacketSize format !! */
+uint32_t max_streams;
 uint8_t iso_started;
 uint8_t iso_error; /* For reporting iso errors to the HC */
 uint8_t interrupt_started;
@@ -106,8 +111,9 @@ struct USBRedirDevice {
 int read_buf_size;
 /* Active chardev-watch-tag */
 guint watch;
-/* For async handling of close */
+/* For async handling of close / reject */
 QEMUBH *chardev_close_bh;
+QEMUBH *device_reject_bh;
 /* To delay the usb attach in case of quick chardev close + open */
 QEMUTimer *attach_timer;
 int64_t next_attach_time;
@@ -780,11 +786,12 @@ static void usbredir_handle_bulk_data(USBRedirDevice 
*dev, USBPacket *p,
 dev-endpoint[EP2I(ep)].bulk_receiving_enabled = 0;
 }
 
-DPRINTF(bulk-out ep %02X len %zd id %PRIu64\n, ep, size, p-id);
+DPRINTF(bulk-out ep %02X stream %u len %zd id %PRIu64\n,
+ep, p-stream, size, p-id);
 
 bulk_packet.endpoint  = ep;
 bulk_packet.length= size;
-bulk_packet.stream_id = 0;
+bulk_packet.stream_id = p-stream;
 bulk_packet.length_high = size  16;
 assert(bulk_packet.length_high == 0 ||
usbredirparser_peer_has_cap(dev-parser,
@@ -1091,6 +1098,66 @@ static void usbredir_handle_control(USBDevice *udev, 
USBPacket *p,
 p-status = USB_RET_ASYNC;
 }
 
+static int usbredir_alloc_streams(USBDevice *udev, USBEndpoint **eps,
+  int nr_eps, int streams)
+{
+USBRedirDevice *dev = DO_UPCAST(USBRedirDevice, dev, udev);
+#if USBREDIR_VERSION = 0x000700
+struct usb_redir_alloc_bulk_streams_header alloc_streams;
+int i;
+
+if (!usbredirparser_peer_has_cap(dev-parser,
+ usb_redir_cap_bulk_streams)) {
+ERROR(peer does not support streams\n);
+goto reject;
+}
+
+if (streams == 0) {
+ERROR(request to allocate 0 streams\n);
+return -1;
+}
+
+alloc_streams.no_streams = streams;
+alloc_streams.endpoints = 0;
+for (i = 0; i  nr_eps; i++) {
+alloc_streams.endpoints |= 1  USBEP2I(eps[i]);
+}
+usbredirparser_send_alloc_bulk_streams(dev-parser, 0, alloc_streams);
+usbredirparser_do_write(dev-parser);
+
+return 0;
+#else
+ERROR(usbredir_alloc_streams not implemented\n);
+goto reject;
+#endif
+reject:
+ERROR(streams are not available, disconnecting\n);
+qemu_bh_schedule(dev-device_reject_bh);
+return -1;
+}
+
+static void usbredir_free_streams(USBDevice *udev, USBEndpoint **eps,
+  int nr_eps)
+{
+#if USBREDIR_VERSION = 0x000700
+USBRedirDevice *dev = DO_UPCAST(USBRedirDevice, dev, udev);
+struct usb_redir_free_bulk_streams_header free_streams;
+int i;
+
+if (!usbredirparser_peer_has_cap(dev-parser,
+ usb_redir_cap_bulk_streams)) {
+return;
+}
+
+free_streams.endpoints = 0;
+for (i = 0; i  nr_eps; i++) {
+free_streams.endpoints |= 1  USBEP2I(eps[i]);
+}
+usbredirparser_send_free_bulk_streams(dev-parser, 0, free_streams);
+usbredirparser_do_write(dev-parser);
+#endif
+}
+
 /*
  * Close events can be triggered by usbredirparser_do_write which gets called
  * from within the USBDevice data / control packet callbacks and doing a
@@ -1102,6 +1169,7 @@ static void usbredir_chardev_close_bh(void *opaque)
 {
 USBRedirDevice *dev = opaque;
 
+qemu_bh_cancel(dev-device_reject_bh);
 usbredir_device_disconnect(dev);
 
 if (dev-parser) {
@@ -1153,6 +1221,9 @@ static void usbredir_create_parser(USBRedirDevice *dev)
 usbredirparser_caps_set_cap(caps, usb_redir_cap_64bits_ids);
 usbredirparser_caps_set_cap(caps, usb_redir_cap_32bits_bulk_length);
 usbredirparser_caps_set_cap(caps, usb_redir_cap_bulk_receiving);
+#if USBREDIR_VERSION = 0x000700
+usbredirparser_caps_set_cap(caps, usb_redir_cap_bulk_streams);
+#endif
 
 if (runstate_check(RUN_STATE_INMIGRATE)) {
 flags |= usbredirparser_fl_no_hello;
@@ -1171,6 +1242,17 @@ static void 

[Qemu-devel] [PULL 06/10] usb-mtp: handle usb_mtp_get_object failure

2014-05-26 Thread Gerd Hoffmann
Cc: Dr. David Alan Gilbert dgilb...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/dev-mtp.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index a95298b..380b465 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -46,6 +46,7 @@ enum mtp_code {
 
 /* response codes */
 RES_OK = 0x2001,
+RES_GENERAL_ERROR  = 0x2002,
 RES_SESSION_NOT_OPEN   = 0x2003,
 RES_INVALID_TRANSACTION_ID = 0x2004,
 RES_OPERATION_NOT_SUPPORTED= 0x2005,
@@ -828,7 +829,9 @@ static void usb_mtp_command(MTPState *s, MTPControl *c)
 }
 data_in = usb_mtp_get_object(s, c, o);
 if (NULL == data_in) {
-fprintf(stderr, %s: TODO: handle error\n, __func__);
+usb_mtp_queue_result(s, RES_GENERAL_ERROR,
+ c-trans, 0, 0, 0);
+return;
 }
 break;
 case CMD_GET_PARTIAL_OBJECT:
@@ -845,7 +848,9 @@ static void usb_mtp_command(MTPState *s, MTPControl *c)
 }
 data_in = usb_mtp_get_partial_object(s, c, o);
 if (NULL == data_in) {
-fprintf(stderr, %s: TODO: handle error\n, __func__);
+usb_mtp_queue_result(s, RES_GENERAL_ERROR,
+ c-trans, 0, 0, 0);
+return;
 }
 nres = 1;
 res0 = data_in-length;
-- 
1.8.3.1




[Qemu-devel] [PATCH 5/5] usb: improve ehci/uhci test

2014-05-26 Thread Gerd Hoffmann
 * Attach usb devices to the bus.
 * Check initial port status register state.
 * Flip ehci initialization bit.
 * Check port status register state again to
   see whenever device handover to ehci worked.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 tests/Makefile|   4 +-
 tests/usb-hcd-ehci-test.c | 153 --
 2 files changed, 152 insertions(+), 5 deletions(-)

diff --git a/tests/Makefile b/tests/Makefile
index 9f7ca61..92ad722 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -152,6 +152,8 @@ gcov-files-i386-y += hw/pci-bridge/ioh3420.c
 check-qtest-i386-y += tests/usb-hcd-ehci-test$(EXESUF)
 gcov-files-i386-y += hw/usb/hcd-ehci.c
 gcov-files-i386-y += hw/usb/hcd-uhci.c
+gcov-files-i386-y += hw/usb/dev-hid.c
+gcov-files-i386-y += hw/usb/dev-storage.c
 check-qtest-x86_64-y = $(check-qtest-i386-y)
 gcov-files-i386-y += i386-softmmu/hw/timer/mc146818rtc.c
 gcov-files-x86_64-y = $(subst 
i386-softmmu/,x86_64-softmmu/,$(gcov-files-i386-y))
@@ -317,7 +319,7 @@ tests/ac97-test$(EXESUF): tests/ac97-test.o
 tests/es1370-test$(EXESUF): tests/es1370-test.o
 tests/intel-hda-test$(EXESUF): tests/intel-hda-test.o
 tests/ioh3420-test$(EXESUF): tests/ioh3420-test.o
-tests/usb-hcd-ehci-test$(EXESUF): tests/usb-hcd-ehci-test.o
+tests/usb-hcd-ehci-test$(EXESUF): tests/usb-hcd-ehci-test.o $(libqos-pc-obj-y)
 tests/qemu-iotests/socket_scm_helper$(EXESUF): 
tests/qemu-iotests/socket_scm_helper.o
 
 # QTest rules
diff --git a/tests/usb-hcd-ehci-test.c b/tests/usb-hcd-ehci-test.c
index bc56ba7..bcdf62f 100644
--- a/tests/usb-hcd-ehci-test.c
+++ b/tests/usb-hcd-ehci-test.c
@@ -9,12 +9,149 @@
 
 #include glib.h
 #include string.h
+#include stdio.h
 #include libqtest.h
+#include libqos/pci-pc.h
 #include qemu/osdep.h
+#include hw/usb/uhci-regs.h
+#include hw/usb/ehci-regs.h
 
-/* Tests only initialization so far. TODO: Replace with functional tests */
-static void pci_nop(void)
+struct qhc {
+QPCIDevice *dev;
+void *base;
+};
+
+static QPCIBus *pcibus;
+static struct qhc uhci1;
+static struct qhc uhci2;
+static struct qhc uhci3;
+static struct qhc ehci1;
+
+/* helpers */
+
+static void pci_init_one(struct qhc *hc, uint32_t devfn, int bar)
+{
+hc-dev = qpci_device_find(pcibus, devfn);
+g_assert(hc-dev != NULL);
+qpci_device_enable(hc-dev);
+hc-base = qpci_iomap(hc-dev, bar);
+g_assert(hc-base != NULL);
+}
+
+#if 0
+static void uhci_port_update(struct qhc *hc, int port,
+ uint16_t set, uint16_t clear)
 {
+void *addr = hc-base + 0x10 + 2 * port;
+uint16_t value;
+
+value = qpci_io_readw(hc-dev, addr);
+value |= set;
+value = ~clear;
+qpci_io_writew(hc-dev, addr, value);
+}
+#endif
+
+static void uhci_port_test(struct qhc *hc, int port, uint16_t expect)
+{
+void *addr = hc-base + 0x10 + 2 * port;
+uint16_t value = qpci_io_readw(hc-dev, addr);
+uint16_t mask = ~(UHCI_PORT_WRITE_CLEAR | UHCI_PORT_RSVD1);
+
+#if 0
+fprintf(stderr, %s: %d, have 0x%04x, want 0x%04x\n,
+__func__, port, value  mask, expect  mask);
+#endif
+g_assert((value  mask) == (expect  mask));
+}
+
+static void ehci_port_test(struct qhc *hc, int port, uint32_t expect)
+{
+void *addr = hc-base + 0x64 + 4 * port;
+uint32_t value = qpci_io_readl(hc-dev, addr);
+uint16_t mask = ~(PORTSC_CSC | PORTSC_PEDC | PORTSC_OCC);
+
+#if 0
+fprintf(stderr, %s: %d, have 0x%08x, want 0x%08x\n,
+__func__, port, value  mask, expect  mask);
+#endif
+g_assert((value  mask) == (expect  mask));
+}
+
+/* tests */
+
+static void pci_init(void)
+{
+if (pcibus) {
+return;
+}
+pcibus = qpci_init_pc();
+g_assert(pcibus != NULL);
+
+pci_init_one(uhci1, QPCI_DEVFN(0x1d, 0), 4);
+pci_init_one(uhci2, QPCI_DEVFN(0x1d, 1), 4);
+pci_init_one(uhci3, QPCI_DEVFN(0x1d, 2), 4);
+pci_init_one(ehci1, QPCI_DEVFN(0x1d, 7), 0);
+}
+
+static void pci_uhci_port_1(void)
+{
+g_assert(pcibus != NULL);
+
+uhci_port_test(uhci1, 0, UHCI_PORT_CCS); /* usb-tablet  */
+uhci_port_test(uhci1, 1, UHCI_PORT_CCS); /* usb-storage */
+uhci_port_test(uhci2, 0, 0);
+uhci_port_test(uhci2, 1, 0);
+uhci_port_test(uhci3, 0, 0);
+uhci_port_test(uhci3, 1, 0);
+}
+
+static void pci_ehci_port_1(void)
+{
+int i;
+
+g_assert(pcibus != NULL);
+
+for (i = 0; i  6; i++) {
+ehci_port_test(ehci1, i, PORTSC_POWNER | PORTSC_PPOWER);
+}
+}
+
+static void pci_ehci_config(void)
+{
+/* hands over all ports from companion uhci to ehci */
+qpci_io_writew(ehci1.dev, ehci1.base + 0x60, 1);
+}
+
+static void pci_uhci_port_2(void)
+{
+g_assert(pcibus != NULL);
+
+uhci_port_test(uhci1, 0, 0); /* usb-tablet,  @ehci */
+uhci_port_test(uhci1, 1, 0); /* usb-storage, @ehci */
+uhci_port_test(uhci2, 0, 0);
+uhci_port_test(uhci2, 1, 0);
+uhci_port_test(uhci3, 0, 0);
+uhci_port_test(uhci3, 1, 0);
+}
+
+static void pci_ehci_port_2(void)
+{
+  

[Qemu-devel] [PATCH 2/5] usb: move uhci register defines to header file

2014-05-26 Thread Gerd Hoffmann
So we can easily use them in tests.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb/hcd-uhci.c  | 36 +---
 include/hw/usb/uhci-regs.h | 39 +++
 2 files changed, 40 insertions(+), 35 deletions(-)
 create mode 100644 include/hw/usb/uhci-regs.h

diff --git a/hw/usb/hcd-uhci.c b/hw/usb/hcd-uhci.c
index 9b1166b..c3bf72c 100644
--- a/hw/usb/hcd-uhci.c
+++ b/hw/usb/hcd-uhci.c
@@ -27,6 +27,7 @@
  */
 #include hw/hw.h
 #include hw/usb.h
+#include hw/usb/uhci-regs.h
 #include hw/pci/pci.h
 #include qemu/timer.h
 #include qemu/iov.h
@@ -37,41 +38,6 @@
 //#define DEBUG
 //#define DEBUG_DUMP_DATA
 
-#define UHCI_CMD_FGR  (1  4)
-#define UHCI_CMD_EGSM (1  3)
-#define UHCI_CMD_GRESET   (1  2)
-#define UHCI_CMD_HCRESET  (1  1)
-#define UHCI_CMD_RS   (1  0)
-
-#define UHCI_STS_HCHALTED (1  5)
-#define UHCI_STS_HCPERR   (1  4)
-#define UHCI_STS_HSERR(1  3)
-#define UHCI_STS_RD   (1  2)
-#define UHCI_STS_USBERR   (1  1)
-#define UHCI_STS_USBINT   (1  0)
-
-#define TD_CTRL_SPD (1  29)
-#define TD_CTRL_ERROR_SHIFT  27
-#define TD_CTRL_IOS (1  25)
-#define TD_CTRL_IOC (1  24)
-#define TD_CTRL_ACTIVE  (1  23)
-#define TD_CTRL_STALL   (1  22)
-#define TD_CTRL_BABBLE  (1  20)
-#define TD_CTRL_NAK (1  19)
-#define TD_CTRL_TIMEOUT (1  18)
-
-#define UHCI_PORT_SUSPEND (1  12)
-#define UHCI_PORT_RESET (1  9)
-#define UHCI_PORT_LSDA  (1  8)
-#define UHCI_PORT_RD(1  6)
-#define UHCI_PORT_ENC   (1  3)
-#define UHCI_PORT_EN(1  2)
-#define UHCI_PORT_CSC   (1  1)
-#define UHCI_PORT_CCS   (1  0)
-
-#define UHCI_PORT_READ_ONLY(0x1bb)
-#define UHCI_PORT_WRITE_CLEAR  (UHCI_PORT_CSC | UHCI_PORT_ENC)
-
 #define FRAME_TIMER_FREQ 1000
 
 #define FRAME_MAX_LOOPS  256
diff --git a/include/hw/usb/uhci-regs.h b/include/hw/usb/uhci-regs.h
new file mode 100644
index 000..63c8223
--- /dev/null
+++ b/include/hw/usb/uhci-regs.h
@@ -0,0 +1,39 @@
+#ifndef HW_USB_UHCI_REGS_H
+#define HW_USB_UHCI_REGS_H 1
+
+#define UHCI_CMD_FGR  (1  4)
+#define UHCI_CMD_EGSM (1  3)
+#define UHCI_CMD_GRESET   (1  2)
+#define UHCI_CMD_HCRESET  (1  1)
+#define UHCI_CMD_RS   (1  0)
+
+#define UHCI_STS_HCHALTED (1  5)
+#define UHCI_STS_HCPERR   (1  4)
+#define UHCI_STS_HSERR(1  3)
+#define UHCI_STS_RD   (1  2)
+#define UHCI_STS_USBERR   (1  1)
+#define UHCI_STS_USBINT   (1  0)
+
+#define TD_CTRL_SPD (1  29)
+#define TD_CTRL_ERROR_SHIFT  27
+#define TD_CTRL_IOS (1  25)
+#define TD_CTRL_IOC (1  24)
+#define TD_CTRL_ACTIVE  (1  23)
+#define TD_CTRL_STALL   (1  22)
+#define TD_CTRL_BABBLE  (1  20)
+#define TD_CTRL_NAK (1  19)
+#define TD_CTRL_TIMEOUT (1  18)
+
+#define UHCI_PORT_SUSPEND (1  12)
+#define UHCI_PORT_RESET (1  9)
+#define UHCI_PORT_LSDA  (1  8)
+#define UHCI_PORT_RD(1  6)
+#define UHCI_PORT_ENC   (1  3)
+#define UHCI_PORT_EN(1  2)
+#define UHCI_PORT_CSC   (1  1)
+#define UHCI_PORT_CCS   (1  0)
+
+#define UHCI_PORT_READ_ONLY(0x1bb)
+#define UHCI_PORT_WRITE_CLEAR  (UHCI_PORT_CSC | UHCI_PORT_ENC)
+
+#endif /* HW_USB_UHCI_REGS_H */
-- 
1.8.3.1




  1   2   3   >