[Qemu-devel] [PATCH v1 01/22] exec: Make tb_invalidate_phys_addr input an AS

2013-12-16 Thread edgar . iglesias
From: Edgar E. Iglesias edgar.igles...@xilinx.com

No functional change.

Signed-off-by: Edgar E. Iglesias edgar.igles...@xilinx.com
---
 exec.c|3 ++-
 include/exec/exec-all.h   |2 +-
 target-xtensa/op_helper.c |3 ++-
 translate-all.c   |4 ++--
 4 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/exec.c b/exec.c
index 00526d1..7ed34e2 100644
--- a/exec.c
+++ b/exec.c
@@ -484,7 +484,8 @@ static void breakpoint_invalidate(CPUState *cpu, 
target_ulong pc)
 {
 hwaddr phys = cpu_get_phys_page_debug(cpu, pc);
 if (phys != -1) {
-tb_invalidate_phys_addr(phys | (pc  ~TARGET_PAGE_MASK));
+tb_invalidate_phys_addr(address_space_memory,
+phys | (pc  ~TARGET_PAGE_MASK));
 }
 }
 #endif
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index ea90b64..b4dfc07 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -101,7 +101,7 @@ void tlb_flush(CPUArchState *env, int flush_global);
 void tlb_set_page(CPUArchState *env, target_ulong vaddr,
   hwaddr paddr, int prot,
   int mmu_idx, target_ulong size);
-void tb_invalidate_phys_addr(hwaddr addr);
+void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr);
 #else
 static inline void tlb_flush_page(CPUArchState *env, target_ulong addr)
 {
diff --git a/target-xtensa/op_helper.c b/target-xtensa/op_helper.c
index cf97025..89a72b5 100644
--- a/target-xtensa/op_helper.c
+++ b/target-xtensa/op_helper.c
@@ -29,6 +29,7 @@
 #include helper.h
 #include qemu/host-utils.h
 #include exec/softmmu_exec.h
+#include exec/address-spaces.h
 
 static void do_unaligned_access(CPUXtensaState *env,
 target_ulong addr, int is_write, int is_user, uintptr_t retaddr);
@@ -90,7 +91,7 @@ static void tb_invalidate_virtual_addr(CPUXtensaState *env, 
uint32_t vaddr)
 int ret = xtensa_get_physical_addr(env, false, vaddr, 2, 0,
 paddr, page_size, access);
 if (ret == 0) {
-tb_invalidate_phys_addr(paddr);
+tb_invalidate_phys_addr(address_space_memory, paddr);
 }
 }
 
diff --git a/translate-all.c b/translate-all.c
index 1c63d78..2ff8781 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -1356,13 +1356,13 @@ static TranslationBlock *tb_find_pc(uintptr_t tc_ptr)
 }
 
 #if defined(TARGET_HAS_ICE)  !defined(CONFIG_USER_ONLY)
-void tb_invalidate_phys_addr(hwaddr addr)
+void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr)
 {
 ram_addr_t ram_addr;
 MemoryRegion *mr;
 hwaddr l = 1;
 
-mr = address_space_translate(address_space_memory, addr, addr, l, 
false);
+mr = address_space_translate(as, addr, addr, l, false);
 if (!(memory_region_is_ram(mr)
   || memory_region_is_romd(mr))) {
 return;
-- 
1.7.10.4




[Qemu-devel] [PATCH v1 00/22] Steps towards per CPU address-spaces

2013-12-16 Thread edgar . iglesias
From: Edgar E. Iglesias edgar.igles...@xilinx.com

Hi,

I'm looking at modeling systems where multiple CPUs co-exist with
different views of their attached buses/devs.

With this series I'm trying to take some steps towards having
an address-space per CPU. It's not complete but good enough for
making it possible to model (to some extent) CPU local memories
for MicroBlaze systems in emulation mode (tcg). I'm updating the
petalogix-ml605 here and will follow-up later with the petalogix-s3adsp.

There is lots of future work needed, for example to transform more of
the cpu_* bus accessing functions. To add more usage of AddressSpace
properties to pass on address spaces to DMA models. Qtest mechanisms
to target specific address spaces, etc...

Cheers,
Edgar

Edgar E. Iglesias (22):
  exec: Make tb_invalidate_phys_addr input an AS
  exec: Make iotlb_to_region input an AS
  exec: Always initialize MemorySection address spaces
  exec: Make memory_region_section_get_iotlb use section AS
  memory: Add MemoryListener to typedefs.h
  memory: Add address_space_find_by_name()
  qdev: Add qdev property type for AddressSpaces
  cpu: Add per-cpu address space
  target-microblaze: Add address-space property
  exec: On AS changes, only flush affected CPU TLBs
  exec: Make ldl_*_phys input an AddressSpace
  exec: Make ldq/ldub_*_phys input an AddressSpace
  exec: Make lduw_*_phys input an AddressSpace
  exec: Make stq_*_phys input an AddressSpace
  exec: Make stl_*_phys input an AddressSpace
  exec: Make stl_phys_notdirty input an AddressSpace
  exec: Make stw_*_phys input an AddressSpace
  exec: Make stb_phys input an AddressSpace
  exec: Make cpu_physical_memory_write_rom input an AS
  exec: Make cpu_memory_rw_debug use the CPUs AS
  petalogix-ml605: Create the CPU with object_new()
  petalogix-ml605: Make the LMB visible only to the CPU

 cpu-exec.c  |5 +-
 cputlb.c|4 +-
 exec.c  |  176 -
 hw/alpha/dp264.c|5 +-
 hw/alpha/typhoon.c  |2 +-
 hw/arm/boot.c   |9 +-
 hw/arm/highbank.c   |6 +-
 hw/core/loader.c|3 +-
 hw/core/qdev-properties-system.c|   46 ++
 hw/display/sm501.c  |1 +
 hw/display/sm501_template.h |2 +-
 hw/dma/pl080.c  |9 +-
 hw/dma/sun4m_iommu.c|3 +-
 hw/intc/apic.c  |3 +-
 hw/microblaze/petalogix_ml605_mmu.c |   28 +++-
 hw/net/vmware_utils.h   |   16 +-
 hw/pci/msi.c|2 +-
 hw/pci/msix.c   |2 +-
 hw/ppc/ppc405_uc.c  |   44 +++---
 hw/ppc/spapr_hcall.c|   42 ++---
 hw/s390x/css.c  |   11 +-
 hw/s390x/s390-virtio-bus.c  |   36 +++--
 hw/s390x/s390-virtio.c  |2 +-
 hw/s390x/virtio-ccw.c   |   40 +++--
 hw/scsi/megasas.c   |   22 ++-
 hw/scsi/vmw_pvscsi.c|6 +-
 hw/sh4/r2d.c|4 +-
 hw/sparc/sun4m.c|3 +-
 hw/timer/hpet.c |3 +-
 hw/virtio/virtio.c  |   31 ++--
 include/exec/cpu-common.h   |   44 +++---
 include/exec/cpu-defs.h |3 +
 include/exec/exec-all.h |5 +-
 include/exec/memory.h   |   10 +-
 include/exec/softmmu_template.h |5 +-
 include/hw/ppc/spapr.h  |4 +-
 include/hw/qdev-properties.h|5 +
 include/qemu/typedefs.h |1 +
 include/qom/cpu.h   |2 +
 memory.c|   12 ++
 monitor.c   |2 +-
 target-alpha/helper.c   |6 +-
 target-alpha/helper.h   |8 +-
 target-alpha/mem_helper.c   |   28 ++--
 target-alpha/translate.c|8 +-
 target-arm/helper.c |   16 +-
 target-i386/arch_memory_mapping.c   |   46 +++---
 target-i386/helper.c|   47 +++---
 target-i386/seg_helper.c|   12 +-
 target-i386/smm_helper.c|  298 ++-
 target-i386/svm_helper.c|  291 --
 target-microblaze/cpu.c |   14 ++
 target-ppc/excp_helper.c|2 +-
 target-ppc/mmu-hash32.h |8 +-
 target-ppc/mmu-hash64.h |   10 +-
 target-s390x/cpu.c  |2 +-
 target-s390x/helper.c   |8 +-
 target-s390x/mem_helper.c   |6 +-
 target-sparc/ldst_helper.c  |   68 
 target-sparc/mmu_helper.c   |   20 +--
 target-unicore32/softmmu.c  |4 +-
 target-xtensa/helper.c  |2 +-
 target-xtensa/op_helper.c   |3 +-
 translate-all.c |4 +-
 64 files 

[Qemu-devel] [PATCH v1 02/22] exec: Make iotlb_to_region input an AS

2013-12-16 Thread edgar . iglesias
From: Edgar E. Iglesias edgar.igles...@xilinx.com

Signed-off-by: Edgar E. Iglesias edgar.igles...@xilinx.com
---
 cputlb.c|2 +-
 exec.c  |5 ++---
 include/exec/exec-all.h |2 +-
 include/exec/softmmu_template.h |5 +++--
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/cputlb.c b/cputlb.c
index fff0afb..0399172 100644
--- a/cputlb.c
+++ b/cputlb.c
@@ -327,7 +327,7 @@ tb_page_addr_t get_page_addr_code(CPUArchState *env1, 
target_ulong addr)
 cpu_ldub_code(env1, addr);
 }
 pd = env1-iotlb[mmu_idx][page_index]  ~TARGET_PAGE_MASK;
-mr = iotlb_to_region(pd);
+mr = iotlb_to_region(address_space_memory, pd);
 if (memory_region_is_unassigned(mr)) {
 CPUState *cpu = ENV_GET_CPU(env1);
 CPUClass *cc = CPU_GET_CLASS(cpu);
diff --git a/exec.c b/exec.c
index 7ed34e2..c34f642 100644
--- a/exec.c
+++ b/exec.c
@@ -1726,10 +1726,9 @@ static uint16_t dummy_section(PhysPageMap *map, 
MemoryRegion *mr)
 return phys_section_add(map, section);
 }
 
-MemoryRegion *iotlb_to_region(hwaddr index)
+MemoryRegion *iotlb_to_region(AddressSpace *as, hwaddr index)
 {
-return address_space_memory.dispatch-map.sections[
-   index  ~TARGET_PAGE_MASK].mr;
+return as-dispatch-map.sections[index  ~TARGET_PAGE_MASK].mr;
 }
 
 static void io_mem_init(void)
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index b4dfc07..6129365 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -324,7 +324,7 @@ extern uintptr_t tci_tb_ptr;
 
 void phys_mem_set_alloc(void *(*alloc)(size_t));
 
-struct MemoryRegion *iotlb_to_region(hwaddr index);
+struct MemoryRegion *iotlb_to_region(AddressSpace *as, hwaddr index);
 bool io_mem_read(struct MemoryRegion *mr, hwaddr addr,
  uint64_t *pvalue, unsigned size);
 bool io_mem_write(struct MemoryRegion *mr, hwaddr addr,
diff --git a/include/exec/softmmu_template.h b/include/exec/softmmu_template.h
index c6a5440..69d856a 100644
--- a/include/exec/softmmu_template.h
+++ b/include/exec/softmmu_template.h
@@ -22,6 +22,7 @@
  * License along with this library; if not, see http://www.gnu.org/licenses/.
  */
 #include qemu/timer.h
+#include exec/address-spaces.h
 #include exec/memory.h
 
 #define DATA_SIZE (1  SHIFT)
@@ -118,7 +119,7 @@ static inline DATA_TYPE glue(io_read, SUFFIX)(CPUArchState 
*env,
   uintptr_t retaddr)
 {
 uint64_t val;
-MemoryRegion *mr = iotlb_to_region(physaddr);
+MemoryRegion *mr = iotlb_to_region(address_space_memory, physaddr);
 
 physaddr = (physaddr  TARGET_PAGE_MASK) + addr;
 env-mem_io_pc = retaddr;
@@ -324,7 +325,7 @@ static inline void glue(io_write, SUFFIX)(CPUArchState *env,
   target_ulong addr,
   uintptr_t retaddr)
 {
-MemoryRegion *mr = iotlb_to_region(physaddr);
+MemoryRegion *mr = iotlb_to_region(address_space_memory, physaddr);
 
 physaddr = (physaddr  TARGET_PAGE_MASK) + addr;
 if (mr != io_mem_rom  mr != io_mem_notdirty  !can_do_io(env)) {
-- 
1.7.10.4




[Qemu-devel] [PATCH v1 03/22] exec: Always initialize MemorySection address spaces

2013-12-16 Thread edgar . iglesias
From: Edgar E. Iglesias edgar.igles...@xilinx.com

Signed-off-by: Edgar E. Iglesias edgar.igles...@xilinx.com
---
 exec.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/exec.c b/exec.c
index c34f642..6d88931 100644
--- a/exec.c
+++ b/exec.c
@@ -878,6 +878,7 @@ static void register_subpage(AddressSpaceDispatch *d, 
MemoryRegionSection *secti
 
 if (!(existing-mr-subpage)) {
 subpage = subpage_init(d-as, base);
+subsection.address_space = d-as;
 subsection.mr = subpage-iomem;
 phys_page_set(d, base  TARGET_PAGE_BITS, 1,
   phys_section_add(d-map, subsection));
@@ -1717,6 +1718,7 @@ static subpage_t *subpage_init(AddressSpace *as, hwaddr 
base)
 static uint16_t dummy_section(PhysPageMap *map, MemoryRegion *mr)
 {
 MemoryRegionSection section = {
+.address_space = address_space_memory,
 .mr = mr,
 .offset_within_address_space = 0,
 .offset_within_region = 0,
-- 
1.7.10.4




[Qemu-devel] [PATCH v1 04/22] exec: Make memory_region_section_get_iotlb use section AS

2013-12-16 Thread edgar . iglesias
From: Edgar E. Iglesias edgar.igles...@xilinx.com

Signed-off-by: Edgar E. Iglesias edgar.igles...@xilinx.com
---
 exec.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/exec.c b/exec.c
index 6d88931..803bbde 100644
--- a/exec.c
+++ b/exec.c
@@ -782,7 +782,7 @@ hwaddr memory_region_section_get_iotlb(CPUArchState *env,
 iotlb |= PHYS_SECTION_ROM;
 }
 } else {
-iotlb = section - address_space_memory.dispatch-map.sections;
+iotlb = section - section-address_space-dispatch-map.sections;
 iotlb += xlat;
 }
 
-- 
1.7.10.4




[Qemu-devel] [PATCH v1 05/22] memory: Add MemoryListener to typedefs.h

2013-12-16 Thread edgar . iglesias
From: Edgar E. Iglesias edgar.igles...@xilinx.com

Signed-off-by: Edgar E. Iglesias edgar.igles...@xilinx.com
---
 include/exec/memory.h   |2 --
 include/qemu/typedefs.h |1 +
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index 480dfbf..2d0b614 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -165,8 +165,6 @@ struct MemoryRegion {
 NotifierList iommu_notify;
 };
 
-typedef struct MemoryListener MemoryListener;
-
 /**
  * MemoryListener: callbacks structure for updates to the physical memory map
  *
diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
index a4c1b84..425ca1a 100644
--- a/include/qemu/typedefs.h
+++ b/include/qemu/typedefs.h
@@ -24,6 +24,7 @@ typedef struct BusClass BusClass;
 typedef struct AddressSpace AddressSpace;
 typedef struct MemoryRegion MemoryRegion;
 typedef struct MemoryRegionSection MemoryRegionSection;
+typedef struct MemoryListener MemoryListener;
 
 typedef struct MemoryMappingList MemoryMappingList;
 
-- 
1.7.10.4




[Qemu-devel] [PATCH v1 07/22] qdev: Add qdev property type for AddressSpaces

2013-12-16 Thread edgar . iglesias
From: Edgar E. Iglesias edgar.igles...@xilinx.com

Signed-off-by: Edgar E. Iglesias edgar.igles...@xilinx.com
---
 hw/core/qdev-properties-system.c |   46 ++
 include/hw/qdev-properties.h |5 +
 2 files changed, 51 insertions(+)

diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index 729efa8..f78bd50 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -170,6 +170,42 @@ PropertyInfo qdev_prop_chr = {
 .release = release_chr,
 };
 
+/* --- AddressSpace --- */
+
+static int parse_address_space(DeviceState *dev, const char *name, void **ptr)
+{
+AddressSpace *as = address_space_find_by_name(name);
+if (as == NULL) {
+return -ENOENT;
+}
+*ptr = as;
+return 0;
+}
+
+static const char *print_address_space(void *ptr)
+{
+AddressSpace *as = ptr;
+return as-name;
+}
+
+static void get_address_space(Object *obj, Visitor *v, void *opaque,
+   const char *name, Error **errp)
+{
+get_pointer(obj, v, opaque, print_address_space, name, errp);
+}
+
+static void set_address_space(Object *obj, Visitor *v, void *opaque,
+   const char *name, Error **errp)
+{
+set_pointer(obj, v, opaque, parse_address_space, name, errp);
+}
+
+PropertyInfo qdev_prop_address_space = {
+.name  = address_space,
+.get   = get_address_space,
+.set   = set_address_space,
+};
+
 /* --- netdev device --- */
 
 static int parse_netdev(DeviceState *dev, const char *str, void **ptr)
@@ -369,6 +405,16 @@ void qdev_prop_set_netdev(DeviceState *dev, const char 
*name,
 assert_no_error(errp);
 }
 
+void qdev_prop_set_address_space(DeviceState *dev, const char *name,
+ AddressSpace *value)
+{
+Error *errp = NULL;
+assert(!value || value-name);
+object_property_set_str(OBJECT(dev),
+value ? value-name : , name, errp);
+assert_no_error(errp);
+}
+
 void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd)
 {
 qdev_prop_set_macaddr(dev, mac, nd-macaddr.a);
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index 692f82e..0e1076d 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -19,6 +19,7 @@ extern PropertyInfo qdev_prop_size;
 extern PropertyInfo qdev_prop_string;
 extern PropertyInfo qdev_prop_chr;
 extern PropertyInfo qdev_prop_ptr;
+extern PropertyInfo qdev_prop_address_space;
 extern PropertyInfo qdev_prop_macaddr;
 extern PropertyInfo qdev_prop_losttickpolicy;
 extern PropertyInfo qdev_prop_bios_chs_trans;
@@ -124,6 +125,8 @@ extern PropertyInfo qdev_prop_arraylen;
 
 #define DEFINE_PROP_PTR(_n, _s, _f) \
 DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
+#define DEFINE_PROP_ADDRESS_SPACE(_n, _s, _f) \
+DEFINE_PROP(_n, _s, _f, qdev_prop_address_space, AddressSpace*)
 #define DEFINE_PROP_CHR(_n, _s, _f) \
 DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
 #define DEFINE_PROP_STRING(_n, _s, _f) \
@@ -160,6 +163,8 @@ void qdev_prop_set_uint32(DeviceState *dev, const char 
*name, uint32_t value);
 void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
 void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
 void qdev_prop_set_string(DeviceState *dev, const char *name, const char 
*value);
+void qdev_prop_set_address_space(DeviceState *dev, const char *name,
+ AddressSpace *value);
 void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState 
*value);
 void qdev_prop_set_netdev(DeviceState *dev, const char *name, NetClientState 
*value);
 int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState 
*value) QEMU_WARN_UNUSED_RESULT;
-- 
1.7.10.4




[Qemu-devel] [PATCH v1 06/22] memory: Add address_space_find_by_name()

2013-12-16 Thread edgar . iglesias
From: Edgar E. Iglesias edgar.igles...@xilinx.com

Signed-off-by: Edgar E. Iglesias edgar.igles...@xilinx.com
---
 include/exec/memory.h |8 
 memory.c  |   12 
 2 files changed, 20 insertions(+)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index 2d0b614..02f4012 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -941,6 +941,14 @@ void mtree_info(fprintf_function mon_printf, void *f);
  */
 void address_space_init(AddressSpace *as, MemoryRegion *root, const char 
*name);
 
+/**
+ * address_space_find_by_name: Find an AddressSpace * by name
+ *
+ * Returns an AddressSpace * if found.
+ *
+ * @name: name of an address space too look for.
+ */
+AddressSpace *address_space_find_by_name(const char *name);
 
 /**
  * address_space_destroy: destroy an address space
diff --git a/memory.c b/memory.c
index 7764314..4695879 100644
--- a/memory.c
+++ b/memory.c
@@ -1725,6 +1725,18 @@ void address_space_init(AddressSpace *as, MemoryRegion 
*root, const char *name)
 memory_region_transaction_commit();
 }
 
+AddressSpace *address_space_find_by_name(const char *name)
+{
+AddressSpace *as;
+
+QTAILQ_FOREACH(as, address_spaces, address_spaces_link) {
+if (strcmp(as-name, name) == 0) {
+return as;
+}
+}
+return NULL;
+}
+
 void address_space_destroy(AddressSpace *as)
 {
 /* Flush out anything from MemoryListeners listening in on this */
-- 
1.7.10.4




[Qemu-devel] [PATCH v1 09/22] target-microblaze: Add address-space property

2013-12-16 Thread edgar . iglesias
From: Edgar E. Iglesias edgar.igles...@xilinx.com

Signed-off-by: Edgar E. Iglesias edgar.igles...@xilinx.com
---
 target-microblaze/cpu.c |   14 ++
 1 file changed, 14 insertions(+)

diff --git a/target-microblaze/cpu.c b/target-microblaze/cpu.c
index 0ef9aa4..ada9556 100644
--- a/target-microblaze/cpu.c
+++ b/target-microblaze/cpu.c
@@ -88,11 +88,22 @@ static void mb_cpu_reset(CPUState *s)
 #endif
 }
 
+static void mb_cpu_setup_as(CPUState *cs)
+{
+#ifndef CONFIG_USER_ONLY
+MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs);
+CPUMBState *env = cpu-env;
+
+cpu_address_space_init(cs, env-as);
+#endif
+}
+
 static void mb_cpu_realizefn(DeviceState *dev, Error **errp)
 {
 CPUState *cs = CPU(dev);
 MicroBlazeCPUClass *mcc = MICROBLAZE_CPU_GET_CLASS(dev);
 
+mb_cpu_setup_as(cs);
 cpu_reset(cs);
 qemu_init_vcpu(cs);
 
@@ -123,6 +134,9 @@ static const VMStateDescription vmstate_mb_cpu = {
 };
 
 static Property mb_properties[] = {
+#ifndef CONFIG_USER_ONLY
+DEFINE_PROP_ADDRESS_SPACE(address-space, MicroBlazeCPU, env.as),
+#endif
 DEFINE_PROP_UINT32(xlnx.base-vectors, MicroBlazeCPU, base_vectors, 0),
 DEFINE_PROP_END_OF_LIST(),
 };
-- 
1.7.10.4




[Qemu-devel] [PATCH v1 08/22] cpu: Add per-cpu address space

2013-12-16 Thread edgar . iglesias
From: Edgar E. Iglesias edgar.igles...@xilinx.com

Signed-off-by: Edgar E. Iglesias edgar.igles...@xilinx.com
---
 cputlb.c|4 ++--
 exec.c  |   31 +++
 include/exec/cpu-defs.h |3 +++
 include/exec/exec-all.h |1 +
 include/exec/softmmu_template.h |4 ++--
 include/qom/cpu.h   |2 ++
 6 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/cputlb.c b/cputlb.c
index 0399172..a2264a3 100644
--- a/cputlb.c
+++ b/cputlb.c
@@ -254,7 +254,7 @@ void tlb_set_page(CPUArchState *env, target_ulong vaddr,
 }
 
 sz = size;
-section = address_space_translate_for_iotlb(address_space_memory, paddr,
+section = address_space_translate_for_iotlb(env-as, paddr,
 xlat, sz);
 assert(sz = TARGET_PAGE_SIZE);
 
@@ -327,7 +327,7 @@ tb_page_addr_t get_page_addr_code(CPUArchState *env1, 
target_ulong addr)
 cpu_ldub_code(env1, addr);
 }
 pd = env1-iotlb[mmu_idx][page_index]  ~TARGET_PAGE_MASK;
-mr = iotlb_to_region(address_space_memory, pd);
+mr = iotlb_to_region(env1-as, pd);
 if (memory_region_is_unassigned(mr)) {
 CPUState *cpu = ENV_GET_CPU(env1);
 CPUClass *cc = CPU_GET_CLASS(cpu);
diff --git a/exec.c b/exec.c
index 803bbde..edb6a43 100644
--- a/exec.c
+++ b/exec.c
@@ -136,6 +136,7 @@ typedef struct subpage_t {
 
 static void io_mem_init(void);
 static void memory_map_init(void);
+static void tcg_commit(MemoryListener *listener);
 
 static MemoryRegion io_mem_watch;
 #endif
@@ -434,6 +435,25 @@ CPUState *qemu_get_cpu(int index)
 return NULL;
 }
 
+#if !defined(CONFIG_USER_ONLY)
+void cpu_address_space_init(CPUState *cpu, AddressSpace *as)
+{
+CPUArchState *env = cpu-env_ptr;
+
+if (tcg_enabled()) {
+if (cpu-tcg_as_listener) {
+memory_listener_unregister(cpu-tcg_as_listener);
+} else {
+cpu-tcg_as_listener = g_new0(MemoryListener, 1);
+}
+cpu-tcg_as_listener-commit = tcg_commit;
+memory_listener_register(cpu-tcg_as_listener, as);
+}
+
+env-as = as;
+}
+#endif
+
 void cpu_exec_init(CPUArchState *env)
 {
 CPUState *cpu = ENV_GET_CPU(env);
@@ -453,6 +473,7 @@ void cpu_exec_init(CPUArchState *env)
 QTAILQ_INIT(env-breakpoints);
 QTAILQ_INIT(env-watchpoints);
 #ifndef CONFIG_USER_ONLY
+cpu_address_space_init(cpu, address_space_memory);
 cpu-thread_id = qemu_get_thread_id();
 #endif
 QTAILQ_INSERT_TAIL(cpus, cpu, node);
@@ -482,9 +503,10 @@ static void breakpoint_invalidate(CPUState *cpu, 
target_ulong pc)
 #else
 static void breakpoint_invalidate(CPUState *cpu, target_ulong pc)
 {
+CPUArchState *env = cpu-env_ptr;
 hwaddr phys = cpu_get_phys_page_debug(cpu, pc);
 if (phys != -1) {
-tb_invalidate_phys_addr(address_space_memory,
+tb_invalidate_phys_addr(env-as,
 phys | (pc  ~TARGET_PAGE_MASK));
 }
 }
@@ -1810,10 +1832,6 @@ static MemoryListener core_memory_listener = {
 .priority = 1,
 };
 
-static MemoryListener tcg_memory_listener = {
-.commit = tcg_commit,
-};
-
 void address_space_init_dispatch(AddressSpace *as)
 {
 as-dispatch = NULL;
@@ -1849,9 +1867,6 @@ static void memory_map_init(void)
 address_space_init(address_space_io, system_io, I/O);
 
 memory_listener_register(core_memory_listener, address_space_memory);
-if (tcg_enabled()) {
-memory_listener_register(tcg_memory_listener, address_space_memory);
-}
 }
 
 MemoryRegion *get_system_memory(void)
diff --git a/include/exec/cpu-defs.h b/include/exec/cpu-defs.h
index 01cd8c7..406b36c 100644
--- a/include/exec/cpu-defs.h
+++ b/include/exec/cpu-defs.h
@@ -176,6 +176,9 @@ typedef struct CPUWatchpoint {
 sigjmp_buf jmp_env; \
 int exception_index;\
 \
+/* Per CPU address-space.  */   \
+AddressSpace *as;   \
+\
 /* user data */ \
 void *opaque;   \
 
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index 6129365..61770ee 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -95,6 +95,7 @@ void tb_invalidate_phys_page_range(tb_page_addr_t start, 
tb_page_addr_t end,
 void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t end,
   int is_cpu_write_access);
 #if !defined(CONFIG_USER_ONLY)
+void cpu_address_space_init(CPUState *cpu, AddressSpace *as);
 /* cputlb.c */
 void tlb_flush_page(CPUArchState *env, target_ulong addr);
 void 

[Qemu-devel] [PATCH v1 12/22] exec: Make ldq/ldub_*_phys input an AddressSpace

2013-12-16 Thread edgar . iglesias
From: Edgar E. Iglesias edgar.igles...@xilinx.com

Signed-off-by: Edgar E. Iglesias edgar.igles...@xilinx.com
---
 exec.c|   22 
 hw/alpha/typhoon.c|2 +-
 hw/display/sm501.c|1 +
 hw/display/sm501_template.h   |2 +-
 hw/net/vmware_utils.h |4 +-
 hw/ppc/spapr_hcall.c  |   10 ++--
 hw/s390x/s390-virtio-bus.c|5 +-
 hw/s390x/virtio-ccw.c |   18 +++---
 hw/scsi/megasas.c |3 +-
 hw/virtio/virtio.c|2 +-
 include/exec/cpu-common.h |8 +--
 monitor.c |2 +-
 target-alpha/helper.c |6 +-
 target-alpha/helper.h |2 +-
 target-alpha/mem_helper.c |8 +--
 target-alpha/translate.c  |2 +-
 target-arm/helper.c   |2 +-
 target-i386/arch_memory_mapping.c |   10 ++--
 target-i386/helper.c  |   20 +++
 target-i386/smm_helper.c  |   32 +--
 target-i386/svm_helper.c  |  112 ++---
 target-ppc/mmu-hash64.h   |5 +-
 target-s390x/helper.c |2 +-
 target-s390x/mem_helper.c |2 +-
 target-sparc/ldst_helper.c|   24 
 25 files changed, 169 insertions(+), 137 deletions(-)

diff --git a/exec.c b/exec.c
index 0e898bb..db64e13 100644
--- a/exec.c
+++ b/exec.c
@@ -1596,7 +1596,7 @@ static uint64_t watch_mem_read(void *opaque, hwaddr addr,
 {
 check_watchpoint(addr  ~TARGET_PAGE_MASK, ~(size - 1), BP_MEM_READ);
 switch (size) {
-case 1: return ldub_phys(addr);
+case 1: return ldub_phys(address_space_memory, addr);
 case 2: return lduw_phys(addr);
 case 4: return ldl_phys(address_space_memory, addr);
 default: abort();
@@ -2368,7 +2368,7 @@ uint32_t ldl_be_phys(AddressSpace *as, hwaddr addr)
 }
 
 /* warning: addr must be aligned */
-static inline uint64_t ldq_phys_internal(hwaddr addr,
+static inline uint64_t ldq_phys_internal(AddressSpace *as, hwaddr addr,
  enum device_endian endian)
 {
 uint8_t *ptr;
@@ -2377,7 +2377,7 @@ static inline uint64_t ldq_phys_internal(hwaddr addr,
 hwaddr l = 8;
 hwaddr addr1;
 
-mr = address_space_translate(address_space_memory, addr, addr1, l,
+mr = address_space_translate(as, addr, addr1, l,
  false);
 if (l  8 || !memory_access_is_direct(mr, false)) {
 /* I/O case */
@@ -2411,26 +2411,26 @@ static inline uint64_t ldq_phys_internal(hwaddr addr,
 return val;
 }
 
-uint64_t ldq_phys(hwaddr addr)
+uint64_t ldq_phys(AddressSpace *as, hwaddr addr)
 {
-return ldq_phys_internal(addr, DEVICE_NATIVE_ENDIAN);
+return ldq_phys_internal(as, addr, DEVICE_NATIVE_ENDIAN);
 }
 
-uint64_t ldq_le_phys(hwaddr addr)
+uint64_t ldq_le_phys(AddressSpace *as, hwaddr addr)
 {
-return ldq_phys_internal(addr, DEVICE_LITTLE_ENDIAN);
+return ldq_phys_internal(as, addr, DEVICE_LITTLE_ENDIAN);
 }
 
-uint64_t ldq_be_phys(hwaddr addr)
+uint64_t ldq_be_phys(AddressSpace *as, hwaddr addr)
 {
-return ldq_phys_internal(addr, DEVICE_BIG_ENDIAN);
+return ldq_phys_internal(as, addr, DEVICE_BIG_ENDIAN);
 }
 
 /* XXX: optimize */
-uint32_t ldub_phys(hwaddr addr)
+uint32_t ldub_phys(AddressSpace *as, hwaddr addr)
 {
 uint8_t val;
-cpu_physical_memory_read(addr, val, 1);
+address_space_rw(as, addr, val, 1, 0);
 return val;
 }
 
diff --git a/hw/alpha/typhoon.c b/hw/alpha/typhoon.c
index 59e1bb8..d07cfe5 100644
--- a/hw/alpha/typhoon.c
+++ b/hw/alpha/typhoon.c
@@ -613,7 +613,7 @@ static bool make_iommu_tlbe(hwaddr taddr, hwaddr mask, 
IOMMUTLBEntry *ret)
translation, given the address of the PTE.  */
 static bool pte_translate(hwaddr pte_addr, IOMMUTLBEntry *ret)
 {
-uint64_t pte = ldq_phys(pte_addr);
+uint64_t pte = ldq_phys(address_space_memory, pte_addr);
 
 /* Check valid bit.  */
 if ((pte  1) == 0) {
diff --git a/hw/display/sm501.c b/hw/display/sm501.c
index c75d6ac..0b5f993 100644
--- a/hw/display/sm501.c
+++ b/hw/display/sm501.c
@@ -30,6 +30,7 @@
 #include hw/sysbus.h
 #include qemu/range.h
 #include ui/pixel_ops.h
+#include exec/address-spaces.h
 
 /*
  * Status: 2010/05/07
diff --git a/hw/display/sm501_template.h b/hw/display/sm501_template.h
index 2d4a3d8..d4cea9e 100644
--- a/hw/display/sm501_template.h
+++ b/hw/display/sm501_template.h
@@ -120,7 +120,7 @@ static void glue(draw_hwc_line_, PIXEL_NAME)(SM501State * 
s, int crt,
 
 /* get pixel value */
 if (i % 4 == 0) {
-bitset = ldub_phys(cursor_addr);
+bitset = ldub_phys(address_space_memory, cursor_addr);
 cursor_addr++;
 }
 v = bitset  3;
diff --git a/hw/net/vmware_utils.h b/hw/net/vmware_utils.h
index b465eb6..eb98d2a 100644
--- a/hw/net/vmware_utils.h
+++ b/hw/net/vmware_utils.h
@@ -65,7 +65,7 @@ vmw_shmem_set(hwaddr addr, 

[Qemu-devel] [PATCH v1 11/22] exec: Make ldl_*_phys input an AddressSpace

2013-12-16 Thread edgar . iglesias
From: Edgar E. Iglesias edgar.igles...@xilinx.com

Signed-off-by: Edgar E. Iglesias edgar.igles...@xilinx.com
---
 cpu-exec.c|5 +-
 exec.c|   19 ---
 hw/dma/pl080.c|9 ++--
 hw/dma/sun4m_iommu.c  |3 +-
 hw/net/vmware_utils.h |2 +-
 hw/ppc/spapr_hcall.c  |8 +--
 hw/s390x/css.c|3 +-
 hw/s390x/s390-virtio-bus.c|2 +-
 hw/s390x/virtio-ccw.c |5 +-
 hw/scsi/megasas.c |4 +-
 hw/scsi/vmw_pvscsi.c  |3 +-
 hw/virtio/virtio.c|3 +-
 include/exec/cpu-common.h |6 +--
 include/hw/ppc/spapr.h|2 +-
 target-alpha/helper.h |2 +-
 target-alpha/mem_helper.c |8 +--
 target-alpha/translate.c  |2 +-
 target-arm/helper.c   |   12 ++---
 target-i386/arch_memory_mapping.c |   36 ++---
 target-i386/helper.c  |8 +--
 target-i386/seg_helper.c  |4 +-
 target-i386/smm_helper.c  |  102 +++--
 target-i386/svm_helper.c  |   26 +-
 target-ppc/excp_helper.c  |2 +-
 target-ppc/mmu-hash32.h   |4 +-
 target-s390x/cpu.c|2 +-
 target-sparc/ldst_helper.c|6 +--
 target-sparc/mmu_helper.c |   18 +++
 target-unicore32/softmmu.c|4 +-
 target-xtensa/helper.c|2 +-
 30 files changed, 163 insertions(+), 149 deletions(-)

diff --git a/cpu-exec.c b/cpu-exec.c
index 30cfa2a..8f6766b 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -374,7 +374,10 @@ int cpu_exec(CPUArchState *env)
 /* FIXME: this should respect TPR */
 cpu_svm_check_intercept_param(env, SVM_EXIT_VINTR,
   0);
-intno = ldl_phys(env-vm_vmcb + offsetof(struct 
vmcb, control.int_vector));
+intno = ldl_phys(env-as,
+ env-vm_vmcb
+ + offsetof(struct vmcb,
+control.int_vector));
 qemu_log_mask(CPU_LOG_TB_IN_ASM, Servicing 
virtual hardware INT=0x%02x\n, intno);
 do_interrupt_x86_hardirq(env, intno, 1);
 cpu-interrupt_request = ~CPU_INTERRUPT_VIRQ;
diff --git a/exec.c b/exec.c
index 203c8e4..0e898bb 100644
--- a/exec.c
+++ b/exec.c
@@ -1598,7 +1598,7 @@ static uint64_t watch_mem_read(void *opaque, hwaddr addr,
 switch (size) {
 case 1: return ldub_phys(addr);
 case 2: return lduw_phys(addr);
-case 4: return ldl_phys(addr);
+case 4: return ldl_phys(address_space_memory, addr);
 default: abort();
 }
 }
@@ -2310,7 +2310,7 @@ void cpu_physical_memory_unmap(void *buffer, hwaddr len,
 }
 
 /* warning: addr must be aligned */
-static inline uint32_t ldl_phys_internal(hwaddr addr,
+static inline uint32_t ldl_phys_internal(AddressSpace *as, hwaddr addr,
  enum device_endian endian)
 {
 uint8_t *ptr;
@@ -2319,8 +2319,7 @@ static inline uint32_t ldl_phys_internal(hwaddr addr,
 hwaddr l = 4;
 hwaddr addr1;
 
-mr = address_space_translate(address_space_memory, addr, addr1, l,
- false);
+mr = address_space_translate(as, addr, addr1, l, false);
 if (l  4 || !memory_access_is_direct(mr, false)) {
 /* I/O case */
 io_mem_read(mr, addr1, val, 4);
@@ -2353,19 +2352,19 @@ static inline uint32_t ldl_phys_internal(hwaddr addr,
 return val;
 }
 
-uint32_t ldl_phys(hwaddr addr)
+uint32_t ldl_phys(AddressSpace *as, hwaddr addr)
 {
-return ldl_phys_internal(addr, DEVICE_NATIVE_ENDIAN);
+return ldl_phys_internal(as, addr, DEVICE_NATIVE_ENDIAN);
 }
 
-uint32_t ldl_le_phys(hwaddr addr)
+uint32_t ldl_le_phys(AddressSpace *as, hwaddr addr)
 {
-return ldl_phys_internal(addr, DEVICE_LITTLE_ENDIAN);
+return ldl_phys_internal(as, addr, DEVICE_LITTLE_ENDIAN);
 }
 
-uint32_t ldl_be_phys(hwaddr addr)
+uint32_t ldl_be_phys(AddressSpace *as, hwaddr addr)
 {
-return ldl_phys_internal(addr, DEVICE_BIG_ENDIAN);
+return ldl_phys_internal(as, addr, DEVICE_BIG_ENDIAN);
 }
 
 /* warning: addr must be aligned */
diff --git a/hw/dma/pl080.c b/hw/dma/pl080.c
index 35b9015..58556f3 100644
--- a/hw/dma/pl080.c
+++ b/hw/dma/pl080.c
@@ -8,6 +8,7 @@
  */
 
 #include hw/sysbus.h
+#include exec/address-spaces.h
 
 #define PL080_MAX_CHANNELS 8
 #define PL080_CONF_E0x1
@@ -204,10 +205,10 @@ again:
 if (size == 0) {
 /* Transfer complete.  */
 if (ch-lli) {
-ch-src = ldl_le_phys(ch-lli);
-ch-dest = ldl_le_phys(ch-lli + 4);
- 

[Qemu-devel] [PATCH v1 16/22] exec: Make stl_phys_notdirty input an AddressSpace

2013-12-16 Thread edgar . iglesias
From: Edgar E. Iglesias edgar.igles...@xilinx.com

Signed-off-by: Edgar E. Iglesias edgar.igles...@xilinx.com
---
 exec.c|4 ++--
 hw/arm/boot.c |9 +
 hw/arm/highbank.c |6 +++---
 include/exec/cpu-common.h |2 +-
 target-i386/helper.c  |   16 
 target-sparc/mmu_helper.c |2 +-
 6 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/exec.c b/exec.c
index 1dfdc3c..0b92ec1 100644
--- a/exec.c
+++ b/exec.c
@@ -2496,14 +2496,14 @@ uint32_t lduw_be_phys(AddressSpace *as, hwaddr addr)
 /* warning: addr must be aligned. The ram page is not masked as dirty
and the code inside is not invalidated. It is useful if the dirty
bits are used to track modified PTEs */
-void stl_phys_notdirty(hwaddr addr, uint32_t val)
+void stl_phys_notdirty(AddressSpace *as, hwaddr addr, uint32_t val)
 {
 uint8_t *ptr;
 MemoryRegion *mr;
 hwaddr l = 4;
 hwaddr addr1;
 
-mr = address_space_translate(address_space_memory, addr, addr1, l,
+mr = address_space_translate(as, addr, addr1, l,
  true);
 if (l  4 || !memory_access_is_direct(mr, true)) {
 io_mem_write(mr, addr1, val, 4);
diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index 55d552f..b04d386 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -16,6 +16,7 @@
 #include elf.h
 #include sysemu/device_tree.h
 #include qemu/config-file.h
+#include exec/address-spaces.h
 
 #define KERNEL_ARGS_ADDR 0x100
 #define KERNEL_LOAD_ADDR 0x0001
@@ -88,13 +89,13 @@ static void default_reset_secondary(ARMCPU *cpu,
 {
 CPUARMState *env = cpu-env;
 
-stl_phys_notdirty(info-smp_bootreg_addr, 0);
+stl_phys_notdirty(address_space_memory, info-smp_bootreg_addr, 0);
 env-regs[15] = info-smp_loader_start;
 }
 
-#define WRITE_WORD(p, value) do { \
-stl_phys_notdirty(p, value);  \
-p += 4;   \
+#define WRITE_WORD(p, value) do {\
+stl_phys_notdirty(address_space_memory, p, value);  \
+p += 4;  \
 } while (0)
 
 static void set_kernel_args(const struct arm_boot_info *info)
diff --git a/hw/arm/highbank.c b/hw/arm/highbank.c
index fe98ef1..2e95967 100644
--- a/hw/arm/highbank.c
+++ b/hw/arm/highbank.c
@@ -68,11 +68,11 @@ static void hb_reset_secondary(ARMCPU *cpu, const struct 
arm_boot_info *info)
 
 switch (info-nb_cpus) {
 case 4:
-stl_phys_notdirty(SMP_BOOT_REG + 0x30, 0);
+stl_phys_notdirty(address_space_memory, SMP_BOOT_REG + 0x30, 0);
 case 3:
-stl_phys_notdirty(SMP_BOOT_REG + 0x20, 0);
+stl_phys_notdirty(address_space_memory, SMP_BOOT_REG + 0x20, 0);
 case 2:
-stl_phys_notdirty(SMP_BOOT_REG + 0x10, 0);
+stl_phys_notdirty(address_space_memory, SMP_BOOT_REG + 0x10, 0);
 env-regs[15] = SMP_BOOT_ADDR;
 break;
 default:
diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index b29065d..dd5feab 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -102,7 +102,7 @@ void stq_be_phys(AddressSpace *as, hwaddr addr, uint64_t 
val);
 uint32_t lduw_phys(AddressSpace *as, hwaddr addr);
 uint32_t ldl_phys(AddressSpace *as, hwaddr addr);
 uint64_t ldq_phys(AddressSpace *as, hwaddr addr);
-void stl_phys_notdirty(hwaddr addr, uint32_t val);
+void stl_phys_notdirty(AddressSpace *as, hwaddr addr, uint32_t val);
 void stw_phys(hwaddr addr, uint32_t val);
 void stl_phys(AddressSpace *as, hwaddr addr, uint32_t val);
 void stq_phys(AddressSpace *as, hwaddr addr, uint64_t val);
diff --git a/target-i386/helper.c b/target-i386/helper.c
index 27461f1..114acb7 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -567,7 +567,7 @@ int cpu_x86_handle_mmu_fault(CPUX86State *env, target_ulong 
addr,
 }
 if (!(pml4e  PG_ACCESSED_MASK)) {
 pml4e |= PG_ACCESSED_MASK;
-stl_phys_notdirty(pml4e_addr, pml4e);
+stl_phys_notdirty(env-as, pml4e_addr, pml4e);
 }
 ptep = pml4e ^ PG_NX_MASK;
 pdpe_addr = ((pml4e  PHYS_ADDR_MASK) + (((addr  30)  0x1ff)  
3)) 
@@ -584,7 +584,7 @@ int cpu_x86_handle_mmu_fault(CPUX86State *env, target_ulong 
addr,
 ptep = pdpe ^ PG_NX_MASK;
 if (!(pdpe  PG_ACCESSED_MASK)) {
 pdpe |= PG_ACCESSED_MASK;
-stl_phys_notdirty(pdpe_addr, pdpe);
+stl_phys_notdirty(env-as, pdpe_addr, pdpe);
 }
 } else
 #endif
@@ -654,7 +654,7 @@ int cpu_x86_handle_mmu_fault(CPUX86State *env, target_ulong 
addr,
 pde |= PG_ACCESSED_MASK;
 if (is_dirty)
 pde |= PG_DIRTY_MASK;
-stl_phys_notdirty(pde_addr, pde);
+stl_phys_notdirty(env-as, pde_addr, pde);
 }
 /* align to page_size */
 pte = pde  ((PHYS_ADDR_MASK  ~(page_size - 1)) 

[Qemu-devel] [PATCH v1 17/22] exec: Make stw_*_phys input an AddressSpace

2013-12-16 Thread edgar . iglesias
From: Edgar E. Iglesias edgar.igles...@xilinx.com

Signed-off-by: Edgar E. Iglesias edgar.igles...@xilinx.com
---
 exec.c |   20 ++--
 hw/net/vmware_utils.h  |2 +-
 hw/ppc/ppc405_uc.c |2 +-
 hw/ppc/spapr_hcall.c   |4 ++--
 hw/s390x/css.c |3 ++-
 hw/s390x/s390-virtio-bus.c |8 +---
 hw/s390x/virtio-ccw.c  |3 ++-
 hw/sh4/r2d.c   |2 +-
 hw/virtio/virtio.c |   10 ++
 include/exec/cpu-common.h  |6 +++---
 target-i386/smm_helper.c   |   12 ++--
 target-i386/svm_helper.c   |4 ++--
 target-s390x/mem_helper.c  |2 +-
 target-sparc/ldst_helper.c |6 +++---
 14 files changed, 45 insertions(+), 39 deletions(-)

diff --git a/exec.c b/exec.c
index 0b92ec1..cf35cd4 100644
--- a/exec.c
+++ b/exec.c
@@ -1612,7 +1612,7 @@ static void watch_mem_write(void *opaque, hwaddr addr,
 stb_phys(addr, val);
 break;
 case 2:
-stw_phys(addr, val);
+stw_phys(address_space_memory, addr, val);
 break;
 case 4:
 stl_phys(address_space_memory, addr, val);
@@ -2589,7 +2589,8 @@ void stb_phys(hwaddr addr, uint32_t val)
 }
 
 /* warning: addr must be aligned */
-static inline void stw_phys_internal(hwaddr addr, uint32_t val,
+static inline void stw_phys_internal(AddressSpace *as,
+ hwaddr addr, uint32_t val,
  enum device_endian endian)
 {
 uint8_t *ptr;
@@ -2597,8 +2598,7 @@ static inline void stw_phys_internal(hwaddr addr, 
uint32_t val,
 hwaddr l = 2;
 hwaddr addr1;
 
-mr = address_space_translate(address_space_memory, addr, addr1, l,
- true);
+mr = address_space_translate(as, addr, addr1, l, true);
 if (l  2 || !memory_access_is_direct(mr, true)) {
 #if defined(TARGET_WORDS_BIGENDIAN)
 if (endian == DEVICE_LITTLE_ENDIAN) {
@@ -2629,19 +2629,19 @@ static inline void stw_phys_internal(hwaddr addr, 
uint32_t val,
 }
 }
 
-void stw_phys(hwaddr addr, uint32_t val)
+void stw_phys(AddressSpace *as, hwaddr addr, uint32_t val)
 {
-stw_phys_internal(addr, val, DEVICE_NATIVE_ENDIAN);
+stw_phys_internal(as, addr, val, DEVICE_NATIVE_ENDIAN);
 }
 
-void stw_le_phys(hwaddr addr, uint32_t val)
+void stw_le_phys(AddressSpace *as, hwaddr addr, uint32_t val)
 {
-stw_phys_internal(addr, val, DEVICE_LITTLE_ENDIAN);
+stw_phys_internal(as, addr, val, DEVICE_LITTLE_ENDIAN);
 }
 
-void stw_be_phys(hwaddr addr, uint32_t val)
+void stw_be_phys(AddressSpace *as, hwaddr addr, uint32_t val)
 {
-stw_phys_internal(addr, val, DEVICE_BIG_ENDIAN);
+stw_phys_internal(as, addr, val, DEVICE_BIG_ENDIAN);
 }
 
 /* XXX: optimize */
diff --git a/hw/net/vmware_utils.h b/hw/net/vmware_utils.h
index 2ed73af..d8f734f 100644
--- a/hw/net/vmware_utils.h
+++ b/hw/net/vmware_utils.h
@@ -89,7 +89,7 @@ static inline void
 vmw_shmem_st16(hwaddr addr, uint16_t value)
 {
 VMW_SHPRN(SHMEM store16: % PRIx64  (value 0x%X), addr, value);
-stw_le_phys(addr, value);
+stw_le_phys(address_space_memory, addr, value);
 }
 
 static inline uint32_t
diff --git a/hw/ppc/ppc405_uc.c b/hw/ppc/ppc405_uc.c
index 09a23ce..4d22048 100644
--- a/hw/ppc/ppc405_uc.c
+++ b/hw/ppc/ppc405_uc.c
@@ -64,7 +64,7 @@ ram_addr_t ppc405_set_bootinfo (CPUPPCState *env, 
ppc4xx_bd_info_t *bd,
 for (i = 0; i  6; i++) {
 stb_phys(bdloc + 0x24 + i, bd-bi_enetaddr[i]);
 }
-stw_be_phys(bdloc + 0x2A, bd-bi_ethspeed);
+stw_be_phys(env-as, bdloc + 0x2A, bd-bi_ethspeed);
 stl_be_phys(env-as, bdloc + 0x2C, bd-bi_intfreq);
 stl_be_phys(env-as, bdloc + 0x30, bd-bi_busfreq);
 stl_be_phys(env-as, bdloc + 0x34, bd-bi_baudrate);
diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index 8f5a242..520ffd5 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -564,7 +564,7 @@ static target_ulong h_logical_store(PowerPCCPU *cpu, 
sPAPREnvironment *spapr,
 stb_phys(addr, val);
 return H_SUCCESS;
 case 2:
-stw_phys(addr, val);
+stw_phys(cpu-env.as, addr, val);
 return H_SUCCESS;
 case 4:
 stl_phys(cpu-env.as, addr, val);
@@ -627,7 +627,7 @@ static target_ulong h_logical_memop(PowerPCCPU *cpu, 
sPAPREnvironment *spapr,
 stb_phys(dst, tmp);
 break;
 case 1:
-stw_phys(dst, tmp);
+stw_phys(cpu-env.as, dst, tmp);
 break;
 case 2:
 stl_phys(cpu-env.as, dst, tmp);
diff --git a/hw/s390x/css.c b/hw/s390x/css.c
index cfa8a9b..75b04b4 100644
--- a/hw/s390x/css.c
+++ b/hw/s390x/css.c
@@ -680,7 +680,8 @@ static void css_update_chnmon(SubchDev *sch)
 count = lduw_phys(address_space_memory,
   channel_subsys-chnmon_area + offset);
 count++;
-stw_phys(channel_subsys-chnmon_area + offset, count);
+stw_phys(address_space_memory,
+ 

[Qemu-devel] [PATCH v1 18/22] exec: Make stb_phys input an AddressSpace

2013-12-16 Thread edgar . iglesias
From: Edgar E. Iglesias edgar.igles...@xilinx.com

Signed-off-by: Edgar E. Iglesias edgar.igles...@xilinx.com
---
 exec.c |6 +++---
 hw/net/vmware_utils.h  |2 +-
 hw/ppc/ppc405_uc.c |   10 +-
 hw/ppc/spapr_hcall.c   |6 +++---
 hw/s390x/s390-virtio-bus.c |   16 +++-
 hw/s390x/s390-virtio.c |2 +-
 hw/scsi/megasas.c  |6 --
 include/exec/cpu-common.h  |2 +-
 target-i386/svm_helper.c   |2 +-
 target-s390x/mem_helper.c  |2 +-
 target-sparc/ldst_helper.c |6 +++---
 11 files changed, 34 insertions(+), 26 deletions(-)

diff --git a/exec.c b/exec.c
index cf35cd4..f027091 100644
--- a/exec.c
+++ b/exec.c
@@ -1609,7 +1609,7 @@ static void watch_mem_write(void *opaque, hwaddr addr,
 check_watchpoint(addr  ~TARGET_PAGE_MASK, ~(size - 1), BP_MEM_WRITE);
 switch (size) {
 case 1:
-stb_phys(addr, val);
+stb_phys(address_space_memory, addr, val);
 break;
 case 2:
 stw_phys(address_space_memory, addr, val);
@@ -2582,10 +2582,10 @@ void stl_be_phys(AddressSpace *as, hwaddr addr, 
uint32_t val)
 }
 
 /* XXX: optimize */
-void stb_phys(hwaddr addr, uint32_t val)
+void stb_phys(AddressSpace *as, hwaddr addr, uint32_t val)
 {
 uint8_t v = val;
-cpu_physical_memory_write(addr, v, 1);
+address_space_rw(as, addr, v, 1, 1);
 }
 
 /* warning: addr must be aligned */
diff --git a/hw/net/vmware_utils.h b/hw/net/vmware_utils.h
index d8f734f..1099df6 100644
--- a/hw/net/vmware_utils.h
+++ b/hw/net/vmware_utils.h
@@ -74,7 +74,7 @@ static inline void
 vmw_shmem_st8(hwaddr addr, uint8_t value)
 {
 VMW_SHPRN(SHMEM store8: % PRIx64  (value 0x%X), addr, value);
-stb_phys(addr, value);
+stb_phys(address_space_memory, addr, value);
 }
 
 static inline uint32_t
diff --git a/hw/ppc/ppc405_uc.c b/hw/ppc/ppc405_uc.c
index 4d22048..36a394b 100644
--- a/hw/ppc/ppc405_uc.c
+++ b/hw/ppc/ppc405_uc.c
@@ -62,27 +62,27 @@ ram_addr_t ppc405_set_bootinfo (CPUPPCState *env, 
ppc4xx_bd_info_t *bd,
 stl_be_phys(env-as, bdloc + 0x1C, bd-bi_bootflags);
 stl_be_phys(env-as, bdloc + 0x20, bd-bi_ipaddr);
 for (i = 0; i  6; i++) {
-stb_phys(bdloc + 0x24 + i, bd-bi_enetaddr[i]);
+stb_phys(env-as, bdloc + 0x24 + i, bd-bi_enetaddr[i]);
 }
 stw_be_phys(env-as, bdloc + 0x2A, bd-bi_ethspeed);
 stl_be_phys(env-as, bdloc + 0x2C, bd-bi_intfreq);
 stl_be_phys(env-as, bdloc + 0x30, bd-bi_busfreq);
 stl_be_phys(env-as, bdloc + 0x34, bd-bi_baudrate);
 for (i = 0; i  4; i++) {
-stb_phys(bdloc + 0x38 + i, bd-bi_s_version[i]);
+stb_phys(env-as, bdloc + 0x38 + i, bd-bi_s_version[i]);
 }
 for (i = 0; i  32; i++) {
-stb_phys(bdloc + 0x3C + i, bd-bi_r_version[i]);
+stb_phys(env-as, bdloc + 0x3C + i, bd-bi_r_version[i]);
 }
 stl_be_phys(env-as, bdloc + 0x5C, bd-bi_plb_busfreq);
 stl_be_phys(env-as, bdloc + 0x60, bd-bi_pci_busfreq);
 for (i = 0; i  6; i++) {
-stb_phys(bdloc + 0x64 + i, bd-bi_pci_enetaddr[i]);
+stb_phys(env-as, bdloc + 0x64 + i, bd-bi_pci_enetaddr[i]);
 }
 n = 0x6A;
 if (flags  0x0001) {
 for (i = 0; i  6; i++)
-stb_phys(bdloc + n++, bd-bi_pci_enetaddr2[i]);
+stb_phys(env-as, bdloc + n++, bd-bi_pci_enetaddr2[i]);
 }
 stl_be_phys(env-as, bdloc + n, bd-bi_opbfreq);
 n += 4;
diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index 520ffd5..5c0df80 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -369,7 +369,7 @@ static target_ulong register_vpa(CPUPPCState *env, 
target_ulong vpa)
 
 tmp = ldub_phys(env-as, env-vpa_addr + VPA_SHARED_PROC_OFFSET);
 tmp |= VPA_SHARED_PROC_VAL;
-stb_phys(env-vpa_addr + VPA_SHARED_PROC_OFFSET, tmp);
+stb_phys(env-as, env-vpa_addr + VPA_SHARED_PROC_OFFSET, tmp);
 
 return H_SUCCESS;
 }
@@ -561,7 +561,7 @@ static target_ulong h_logical_store(PowerPCCPU *cpu, 
sPAPREnvironment *spapr,
 
 switch (size) {
 case 1:
-stb_phys(addr, val);
+stb_phys(cpu-env.as, addr, val);
 return H_SUCCESS;
 case 2:
 stw_phys(cpu-env.as, addr, val);
@@ -624,7 +624,7 @@ static target_ulong h_logical_memop(PowerPCCPU *cpu, 
sPAPREnvironment *spapr,
 }
 switch (esize) {
 case 0:
-stb_phys(dst, tmp);
+stb_phys(cpu-env.as, dst, tmp);
 break;
 case 1:
 stw_phys(cpu-env.as, dst, tmp);
diff --git a/hw/s390x/s390-virtio-bus.c b/hw/s390x/s390-virtio-bus.c
index f05ca70..170d851 100644
--- a/hw/s390x/s390-virtio-bus.c
+++ b/hw/s390x/s390-virtio-bus.c
@@ -359,15 +359,21 @@ void s390_virtio_device_sync(VirtIOS390Device *dev)
 virtio_reset(dev-vdev);
 
 /* Sync dev space */
-stb_phys(dev-dev_offs + VIRTIO_DEV_OFFS_TYPE, dev-vdev-device_id);
+stb_phys(address_space_memory,
+ dev-dev_offs + VIRTIO_DEV_OFFS_TYPE, dev-vdev-device_id);
 
-

[Qemu-devel] [PATCH v1 14/22] exec: Make stq_*_phys input an AddressSpace

2013-12-16 Thread edgar . iglesias
From: Edgar E. Iglesias edgar.igles...@xilinx.com

Signed-off-by: Edgar E. Iglesias edgar.igles...@xilinx.com
---
 exec.c |   12 +++---
 hw/alpha/dp264.c   |5 ++-
 hw/net/vmware_utils.h  |2 +-
 hw/ppc/spapr_hcall.c   |4 +-
 hw/s390x/s390-virtio-bus.c |3 +-
 hw/s390x/virtio-ccw.c  |4 +-
 hw/scsi/megasas.c  |3 +-
 include/exec/cpu-common.h  |6 +--
 target-alpha/helper.h  |2 +-
 target-alpha/mem_helper.c  |6 +--
 target-alpha/translate.c   |2 +-
 target-i386/helper.c   |3 +-
 target-i386/smm_helper.c   |   32 +++---
 target-i386/svm_helper.c   |  102 +++-
 target-ppc/mmu-hash64.h|5 ++-
 target-s390x/helper.c  |6 ++-
 target-s390x/mem_helper.c  |2 +-
 target-sparc/ldst_helper.c |   14 +++---
 18 files changed, 121 insertions(+), 92 deletions(-)

diff --git a/exec.c b/exec.c
index 7ab6153..57aebd1 100644
--- a/exec.c
+++ b/exec.c
@@ -2644,22 +2644,22 @@ void stw_be_phys(hwaddr addr, uint32_t val)
 }
 
 /* XXX: optimize */
-void stq_phys(hwaddr addr, uint64_t val)
+void stq_phys(AddressSpace *as, hwaddr addr, uint64_t val)
 {
 val = tswap64(val);
-cpu_physical_memory_write(addr, val, 8);
+address_space_rw(as, addr, (void *) val, 8, 1);
 }
 
-void stq_le_phys(hwaddr addr, uint64_t val)
+void stq_le_phys(AddressSpace *as, hwaddr addr, uint64_t val)
 {
 val = cpu_to_le64(val);
-cpu_physical_memory_write(addr, val, 8);
+address_space_rw(as, addr, (void *) val, 8, 1);
 }
 
-void stq_be_phys(hwaddr addr, uint64_t val)
+void stq_be_phys(AddressSpace *as, hwaddr addr, uint64_t val)
 {
 val = cpu_to_be64(val);
-cpu_physical_memory_write(addr, val, 8);
+address_space_rw(as, addr, (void *) val, 8, 1);
 }
 
 /* virtual memory access for debug (includes writing to ROM) */
diff --git a/hw/alpha/dp264.c b/hw/alpha/dp264.c
index 20795ac..1351ba5 100644
--- a/hw/alpha/dp264.c
+++ b/hw/alpha/dp264.c
@@ -161,8 +161,9 @@ static void clipper_init(QEMUMachineInitArgs *args)
 load_image_targphys(initrd_filename, initrd_base,
 ram_size - initrd_base);
 
-stq_phys(param_offset + 0x100, initrd_base + 
0xfc00ULL);
-stq_phys(param_offset + 0x108, initrd_size);
+stq_phys(address_space_memory,
+ param_offset + 0x100, initrd_base + 
0xfc00ULL);
+stq_phys(address_space_memory, param_offset + 0x108, initrd_size);
 }
 }
 }
diff --git a/hw/net/vmware_utils.h b/hw/net/vmware_utils.h
index 7877cb6..4cf0e79 100644
--- a/hw/net/vmware_utils.h
+++ b/hw/net/vmware_utils.h
@@ -119,7 +119,7 @@ static inline void
 vmw_shmem_st64(hwaddr addr, uint64_t value)
 {
 VMW_SHPRN(SHMEM store64: % PRIx64  (value % PRIx64 ), addr, value);
-stq_le_phys(addr, value);
+stq_le_phys(address_space_memory, addr, value);
 }
 
 /* Macros for simplification of operations on array-style registers */
diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index b1d5b91..5becf91 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -570,7 +570,7 @@ static target_ulong h_logical_store(PowerPCCPU *cpu, 
sPAPREnvironment *spapr,
 stl_phys(addr, val);
 return H_SUCCESS;
 case 8:
-stq_phys(addr, val);
+stq_phys(cpu-env.as, addr, val);
 return H_SUCCESS;
 }
 return H_PARAMETER;
@@ -633,7 +633,7 @@ static target_ulong h_logical_memop(PowerPCCPU *cpu, 
sPAPREnvironment *spapr,
 stl_phys(dst, tmp);
 break;
 case 3:
-stq_phys(dst, tmp);
+stq_phys(cpu-env.as, dst, tmp);
 break;
 }
 dst = dst + step;
diff --git a/hw/s390x/s390-virtio-bus.c b/hw/s390x/s390-virtio-bus.c
index e8e6e10..5da28d7 100644
--- a/hw/s390x/s390-virtio-bus.c
+++ b/hw/s390x/s390-virtio-bus.c
@@ -378,7 +378,8 @@ void s390_virtio_device_sync(VirtIOS390Device *dev)
 vring = s390_virtio_next_ring(bus);
 virtio_queue_set_addr(dev-vdev, i, vring);
 virtio_queue_set_vector(dev-vdev, i, i);
-stq_be_phys(vq + VIRTIO_VQCONFIG_OFFS_ADDRESS, vring);
+stq_be_phys(address_space_memory,
+vq + VIRTIO_VQCONFIG_OFFS_ADDRESS, vring);
 stw_be_phys(vq + VIRTIO_VQCONFIG_OFFS_NUM, 
virtio_queue_get_num(dev-vdev, i));
 }
 
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index a92cbde..0bb98ae 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -876,7 +876,7 @@ static void virtio_ccw_notify(DeviceState *d, uint16_t 
vector)
 }
 indicators = ldq_phys(address_space_memory, dev-indicators);
 indicators |= 1ULL  vector;
-stq_phys(dev-indicators, indicators);
+stq_phys(address_space_memory, dev-indicators, indicators);
 } else {
 if (!dev-indicators2) {
 return;
@@ -884,7 +884,7 @@ static 

[Qemu-devel] [PATCH v1 20/22] exec: Make cpu_memory_rw_debug use the CPUs AS

2013-12-16 Thread edgar . iglesias
From: Edgar E. Iglesias edgar.igles...@xilinx.com

Signed-off-by: Edgar E. Iglesias edgar.igles...@xilinx.com
---
 exec.c |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/exec.c b/exec.c
index 686f0d1..e672824 100644
--- a/exec.c
+++ b/exec.c
@@ -2669,6 +2669,7 @@ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
 int l;
 hwaddr phys_addr;
 target_ulong page;
+CPUArchState *env = cpu-env_ptr;
 
 while (len  0) {
 page = addr  TARGET_PAGE_MASK;
@@ -2681,10 +2682,9 @@ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
 l = len;
 phys_addr += (addr  ~TARGET_PAGE_MASK);
 if (is_write)
-cpu_physical_memory_write_rom(address_space_memory,
-  phys_addr, buf, l);
+cpu_physical_memory_write_rom(env-as, phys_addr, buf, l);
 else
-cpu_physical_memory_rw(phys_addr, buf, l, is_write);
+address_space_rw(env-as, phys_addr, buf, l, 0);
 len -= l;
 buf += l;
 addr += l;
-- 
1.7.10.4




[Qemu-devel] [PATCH v1 19/22] exec: Make cpu_physical_memory_write_rom input an AS

2013-12-16 Thread edgar . iglesias
From: Edgar E. Iglesias edgar.igles...@xilinx.com

Signed-off-by: Edgar E. Iglesias edgar.igles...@xilinx.com
---
 exec.c|8 
 hw/core/loader.c  |3 ++-
 hw/intc/apic.c|3 ++-
 hw/sparc/sun4m.c  |3 ++-
 include/exec/cpu-common.h |2 +-
 5 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/exec.c b/exec.c
index f027091..686f0d1 100644
--- a/exec.c
+++ b/exec.c
@@ -2093,7 +2093,7 @@ void cpu_physical_memory_rw(hwaddr addr, uint8_t *buf,
 }
 
 /* used for ROM loading : can write in RAM and ROM */
-void cpu_physical_memory_write_rom(hwaddr addr,
+void cpu_physical_memory_write_rom(AddressSpace *as, hwaddr addr,
const uint8_t *buf, int len)
 {
 hwaddr l;
@@ -2103,8 +2103,7 @@ void cpu_physical_memory_write_rom(hwaddr addr,
 
 while (len  0) {
 l = len;
-mr = address_space_translate(address_space_memory,
- addr, addr1, l, true);
+mr = address_space_translate(as, addr, addr1, l, true);
 
 if (!(memory_region_is_ram(mr) ||
   memory_region_is_romd(mr))) {
@@ -2682,7 +2681,8 @@ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
 l = len;
 phys_addr += (addr  ~TARGET_PAGE_MASK);
 if (is_write)
-cpu_physical_memory_write_rom(phys_addr, buf, l);
+cpu_physical_memory_write_rom(address_space_memory,
+  phys_addr, buf, l);
 else
 cpu_physical_memory_rw(phys_addr, buf, l, is_write);
 len -= l;
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 60d2ebd..5598b30 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -778,7 +778,8 @@ static void rom_reset(void *unused)
 void *host = memory_region_get_ram_ptr(rom-mr);
 memcpy(host, rom-data, rom-datasize);
 } else {
-cpu_physical_memory_write_rom(rom-addr, rom-data, rom-datasize);
+cpu_physical_memory_write_rom(address_space_memory,
+  rom-addr, rom-data, rom-datasize);
 }
 if (rom-isrom) {
 /* rom needs to be written only once */
diff --git a/hw/intc/apic.c b/hw/intc/apic.c
index a913186..b48b5ef 100644
--- a/hw/intc/apic.c
+++ b/hw/intc/apic.c
@@ -129,7 +129,8 @@ static void apic_sync_vapic(APICCommonState *s, int 
sync_type)
 }
 vapic_state.irr = vector  0xff;
 
-cpu_physical_memory_write_rom(s-vapic_paddr + start,
+cpu_physical_memory_write_rom(address_space_memory,
+  s-vapic_paddr + start,
   ((void *)vapic_state) + start, length);
 }
 }
diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index 94f7950..2957d90 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -577,7 +577,8 @@ static void idreg_init(hwaddr addr)
 s = SYS_BUS_DEVICE(dev);
 
 sysbus_mmio_map(s, 0, addr);
-cpu_physical_memory_write_rom(addr, idreg_data, sizeof(idreg_data));
+cpu_physical_memory_write_rom(address_space_memory,
+  addr, idreg_data, sizeof(idreg_data));
 }
 
 #define MACIO_ID_REGISTER(obj) \
diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index 20d3518..1710c51 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -108,7 +108,7 @@ void stl_phys(AddressSpace *as, hwaddr addr, uint32_t val);
 void stq_phys(AddressSpace *as, hwaddr addr, uint64_t val);
 #endif
 
-void cpu_physical_memory_write_rom(hwaddr addr,
+void cpu_physical_memory_write_rom(AddressSpace *as, hwaddr addr,
const uint8_t *buf, int len);
 
 extern struct MemoryRegion io_mem_rom;
-- 
1.7.10.4




[Qemu-devel] [PATCH v1 15/22] exec: Make stl_*_phys input an AddressSpace

2013-12-16 Thread edgar . iglesias
From: Edgar E. Iglesias edgar.igles...@xilinx.com

Signed-off-by: Edgar E. Iglesias edgar.igles...@xilinx.com
---
 exec.c |   19 +
 hw/net/vmware_utils.h  |2 +-
 hw/pci/msi.c   |2 +-
 hw/pci/msix.c  |2 +-
 hw/ppc/ppc405_uc.c |   32 +++---
 hw/ppc/spapr_hcall.c   |4 +-
 hw/s390x/css.c |2 +-
 hw/s390x/s390-virtio-bus.c |2 +-
 hw/s390x/virtio-ccw.c  |2 +-
 hw/scsi/megasas.c  |6 ++-
 hw/scsi/vmw_pvscsi.c   |3 +-
 hw/sh4/r2d.c   |2 +-
 hw/timer/hpet.c|3 +-
 hw/virtio/virtio.c |4 +-
 include/exec/cpu-common.h  |6 +--
 include/hw/ppc/spapr.h |2 +-
 target-alpha/helper.h  |2 +-
 target-alpha/mem_helper.c  |6 +--
 target-alpha/translate.c   |2 +-
 target-arm/helper.c|2 +-
 target-i386/seg_helper.c   |8 ++--
 target-i386/smm_helper.c   |  100 ++--
 target-i386/svm_helper.c   |   28 -
 target-ppc/mmu-hash32.h|4 +-
 target-sparc/ldst_helper.c |6 +--
 25 files changed, 132 insertions(+), 119 deletions(-)

diff --git a/exec.c b/exec.c
index 57aebd1..1dfdc3c 100644
--- a/exec.c
+++ b/exec.c
@@ -1615,7 +1615,7 @@ static void watch_mem_write(void *opaque, hwaddr addr,
 stw_phys(addr, val);
 break;
 case 4:
-stl_phys(addr, val);
+stl_phys(address_space_memory, addr, val);
 break;
 default: abort();
 }
@@ -2525,7 +2525,8 @@ void stl_phys_notdirty(hwaddr addr, uint32_t val)
 }
 
 /* warning: addr must be aligned */
-static inline void stl_phys_internal(hwaddr addr, uint32_t val,
+static inline void stl_phys_internal(AddressSpace *as,
+ hwaddr addr, uint32_t val,
  enum device_endian endian)
 {
 uint8_t *ptr;
@@ -2533,7 +2534,7 @@ static inline void stl_phys_internal(hwaddr addr, 
uint32_t val,
 hwaddr l = 4;
 hwaddr addr1;
 
-mr = address_space_translate(address_space_memory, addr, addr1, l,
+mr = address_space_translate(as, addr, addr1, l,
  true);
 if (l  4 || !memory_access_is_direct(mr, true)) {
 #if defined(TARGET_WORDS_BIGENDIAN)
@@ -2565,19 +2566,19 @@ static inline void stl_phys_internal(hwaddr addr, 
uint32_t val,
 }
 }
 
-void stl_phys(hwaddr addr, uint32_t val)
+void stl_phys(AddressSpace *as, hwaddr addr, uint32_t val)
 {
-stl_phys_internal(addr, val, DEVICE_NATIVE_ENDIAN);
+stl_phys_internal(as, addr, val, DEVICE_NATIVE_ENDIAN);
 }
 
-void stl_le_phys(hwaddr addr, uint32_t val)
+void stl_le_phys(AddressSpace *as, hwaddr addr, uint32_t val)
 {
-stl_phys_internal(addr, val, DEVICE_LITTLE_ENDIAN);
+stl_phys_internal(as, addr, val, DEVICE_LITTLE_ENDIAN);
 }
 
-void stl_be_phys(hwaddr addr, uint32_t val)
+void stl_be_phys(AddressSpace *as, hwaddr addr, uint32_t val)
 {
-stl_phys_internal(addr, val, DEVICE_BIG_ENDIAN);
+stl_phys_internal(as, addr, val, DEVICE_BIG_ENDIAN);
 }
 
 /* XXX: optimize */
diff --git a/hw/net/vmware_utils.h b/hw/net/vmware_utils.h
index 4cf0e79..2ed73af 100644
--- a/hw/net/vmware_utils.h
+++ b/hw/net/vmware_utils.h
@@ -104,7 +104,7 @@ static inline void
 vmw_shmem_st32(hwaddr addr, uint32_t value)
 {
 VMW_SHPRN(SHMEM store32: % PRIx64  (value 0x%X), addr, value);
-stl_le_phys(addr, value);
+stl_le_phys(address_space_memory, addr, value);
 }
 
 static inline uint64_t
diff --git a/hw/pci/msi.c b/hw/pci/msi.c
index 2a04d18..a4a3040 100644
--- a/hw/pci/msi.c
+++ b/hw/pci/msi.c
@@ -291,7 +291,7 @@ void msi_notify(PCIDevice *dev, unsigned int vector)
notify vector 0x%x
 address: 0x%PRIx64 data: 0x%PRIx32\n,
vector, msg.address, msg.data);
-stl_le_phys(msg.address, msg.data);
+stl_le_phys(address_space_memory, msg.address, msg.data);
 }
 
 /* Normally called by pci_default_write_config(). */
diff --git a/hw/pci/msix.c b/hw/pci/msix.c
index 3430770..5c49bfc 100644
--- a/hw/pci/msix.c
+++ b/hw/pci/msix.c
@@ -439,7 +439,7 @@ void msix_notify(PCIDevice *dev, unsigned vector)
 
 msg = msix_get_message(dev, vector);
 
-stl_le_phys(msg.address, msg.data);
+stl_le_phys(address_space_memory, msg.address, msg.data);
 }
 
 void msix_reset(PCIDevice *dev)
diff --git a/hw/ppc/ppc405_uc.c b/hw/ppc/ppc405_uc.c
index 8109f92..09a23ce 100644
--- a/hw/ppc/ppc405_uc.c
+++ b/hw/ppc/ppc405_uc.c
@@ -52,30 +52,30 @@ ram_addr_t ppc405_set_bootinfo (CPUPPCState *env, 
ppc4xx_bd_info_t *bd,
 bdloc = 0x0100UL - sizeof(struct ppc4xx_bd_info_t);
 else
 bdloc = bd-bi_memsize - sizeof(struct ppc4xx_bd_info_t);
-stl_be_phys(bdloc + 0x00, bd-bi_memstart);
-stl_be_phys(bdloc + 0x04, bd-bi_memsize);
-stl_be_phys(bdloc + 0x08, bd-bi_flashstart);
-stl_be_phys(bdloc + 0x0C, bd-bi_flashsize);
-stl_be_phys(bdloc + 

[Qemu-devel] [PATCH v1 21/22] petalogix-ml605: Create the CPU with object_new()

2013-12-16 Thread edgar . iglesias
From: Edgar E. Iglesias edgar.igles...@xilinx.com

This is to allow future patches to set properties before cpu::realize().

Signed-off-by: Edgar E. Iglesias edgar.igles...@xilinx.com
---
 hw/microblaze/petalogix_ml605_mmu.c |   11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/hw/microblaze/petalogix_ml605_mmu.c 
b/hw/microblaze/petalogix_ml605_mmu.c
index 10970e0..4009ff5 100644
--- a/hw/microblaze/petalogix_ml605_mmu.c
+++ b/hw/microblaze/petalogix_ml605_mmu.c
@@ -76,7 +76,7 @@ static void
 petalogix_ml605_init(QEMUMachineInitArgs *args)
 {
 ram_addr_t ram_size = args-ram_size;
-const char *cpu_model = args-cpu_model;
+Error *err = NULL;
 MemoryRegion *address_space_mem = get_system_memory();
 DeviceState *dev, *dma, *eth0;
 Object *ds, *cs;
@@ -91,10 +91,13 @@ petalogix_ml605_init(QEMUMachineInitArgs *args)
 qemu_irq irq[32], *cpu_irq;
 
 /* init CPUs */
-if (cpu_model == NULL) {
-cpu_model = microblaze;
+cpu = MICROBLAZE_CPU(object_new(TYPE_MICROBLAZE_CPU));
+object_property_set_bool(OBJECT(cpu), true, realized, err);
+if (err) {
+error_report(%s, error_get_pretty(err));
+exit(EXIT_FAILURE);
 }
-cpu = cpu_mb_init(cpu_model);
+
 env = cpu-env;
 
 /* Attach emulated BRAM through the LMB.  */
-- 
1.7.10.4




[Qemu-devel] [PATCH v1 22/22] petalogix-ml605: Make the LMB visible only to the CPU

2013-12-16 Thread edgar . iglesias
From: Edgar E. Iglesias edgar.igles...@xilinx.com

Signed-off-by: Edgar E. Iglesias edgar.igles...@xilinx.com
---
 hw/microblaze/petalogix_ml605_mmu.c |   17 -
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/hw/microblaze/petalogix_ml605_mmu.c 
b/hw/microblaze/petalogix_ml605_mmu.c
index 4009ff5..0a13b0e 100644
--- a/hw/microblaze/petalogix_ml605_mmu.c
+++ b/hw/microblaze/petalogix_ml605_mmu.c
@@ -88,10 +88,18 @@ petalogix_ml605_init(QEMUMachineInitArgs *args)
 hwaddr ddr_base = MEMORY_BASEADDR;
 MemoryRegion *phys_lmb_bram = g_new(MemoryRegion, 1);
 MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
+MemoryRegion *sysmem_alias = g_new(MemoryRegion, 1);
+MemoryRegion *mr_cpu_root = g_new(MemoryRegion, 1);
+AddressSpace *as_cpu = g_malloc0(sizeof(*as_cpu));
 qemu_irq irq[32], *cpu_irq;
 
+/* Setup the CPU specific address-space.  */
+memory_region_init(mr_cpu_root, NULL, as-cpu-root, INT64_MAX);
+address_space_init(as_cpu, mr_cpu_root, as/cpu);
+
 /* init CPUs */
 cpu = MICROBLAZE_CPU(object_new(TYPE_MICROBLAZE_CPU));
+qdev_prop_set_address_space(DEVICE(cpu), address-space, as_cpu);
 object_property_set_bool(OBJECT(cpu), true, realized, err);
 if (err) {
 error_report(%s, error_get_pretty(err));
@@ -100,11 +108,18 @@ petalogix_ml605_init(QEMUMachineInitArgs *args)
 
 env = cpu-env;
 
+/* Populate the CPU AS with the LMB only visible to the CPU.  */
+memory_region_init_alias(sysmem_alias, NULL, sysmem_alias,
+ address_space_mem, 0,
+ memory_region_size(address_space_mem));
+memory_region_add_subregion(mr_cpu_root, 0x, sysmem_alias);
+
 /* Attach emulated BRAM through the LMB.  */
 memory_region_init_ram(phys_lmb_bram, NULL, petalogix_ml605.lmb_bram,
LMB_BRAM_SIZE);
 vmstate_register_ram_global(phys_lmb_bram);
-memory_region_add_subregion(address_space_mem, 0x, phys_lmb_bram);
+memory_region_add_subregion_overlap(mr_cpu_root, 0x,
+phys_lmb_bram, 2);
 
 memory_region_init_ram(phys_ram, NULL, petalogix_ml605.ram, ram_size);
 vmstate_register_ram_global(phys_ram);
-- 
1.7.10.4




Re: [Qemu-devel] [PATCH v4 00/10] Clean up and fix no_user

2013-12-16 Thread Markus Armbruster
Andreas Färber afaer...@suse.de writes:

 Am 28.11.2013 17:26, schrieb arm...@redhat.com:
 Markus Armbruster (10):
   qdev: Replace no_user by cannot_instantiate_with_device_add_yet
   sysbus: Set cannot_instantiate_with_device_add_yet
   cpu: Document why cannot_instantiate_with_device_add_yet
   apic: Document why cannot_instantiate_with_device_add_yet
   pci-host: Consistently set cannot_instantiate_with_device_add_yet
   ich9: Document why cannot_instantiate_with_device_add_yet
   piix3 piix4: Clean up use of cannot_instantiate_with_device_add_yet
   vt82c686: Clean up use of cannot_instantiate_with_device_add_yet
   isa: Clean up use of cannot_instantiate_with_device_add_yet
   qdev: Do not let the user try to device_add when it cannot work

 I've applied all except for the ISA patch, which doesn't feature a
 Reviewed-by yet.

 https://github.com/afaerber/qemu-cpu/commits/qom-next

 I'd appreciate if some previous reviewer can comment on whether any
 issues have been resolved satisfactorily.

Paolo answered a question I posted along with my RFC series, Peter
pointed out two wires I missed in v1 (fixed in v2), Marcel examined v3,
but didn't feel familiar enough with the code to risk a formal
Reviewed-by.  I asked Anthony to review a couple of times, and he said
he intended to.

However, consider the timeline:

Oct 10 RFC
* you, Paolo, Kevin and Anthony commented

Oct 17 v1

Oct 29 v2: address Peter Maydell's review
* Some commit messages improved
* Use QOM cast macros instead of .parent_class [PATCH 05]
* keep cannot_instantiate_with_device_add_yet for port92, isa-pit,
  kvm-pit, m48t59_isa, mc146818rtc [PATCH 09]

Oct 30 v3: address Eric Blake's and Marcel Apfelbaum's review
* Clean up a harmless editing accident in PATCH 07
* Simplify PATCH 10 slightly

Nov 28 v4: straightforward rebase (only PATCH 10/10 conflicts)

It's been more than six weeks since the last review comment.  I doubt
more waiting (and more rebasing) will be productive.



Re: [Qemu-devel] [PATCH v4 00/10] Clean up and fix no_user

2013-12-16 Thread Marcel Apfelbaum
On Sun, 2013-12-15 at 21:37 +0100, Andreas Färber wrote:
 Am 28.11.2013 17:26, schrieb arm...@redhat.com:
  Markus Armbruster (10):
qdev: Replace no_user by cannot_instantiate_with_device_add_yet
sysbus: Set cannot_instantiate_with_device_add_yet
cpu: Document why cannot_instantiate_with_device_add_yet
apic: Document why cannot_instantiate_with_device_add_yet
pci-host: Consistently set cannot_instantiate_with_device_add_yet
ich9: Document why cannot_instantiate_with_device_add_yet
piix3 piix4: Clean up use of cannot_instantiate_with_device_add_yet
vt82c686: Clean up use of cannot_instantiate_with_device_add_yet
isa: Clean up use of cannot_instantiate_with_device_add_yet
qdev: Do not let the user try to device_add when it cannot work
 
 I've applied all except for the ISA patch, which doesn't feature a
 Reviewed-by yet.
 
 https://github.com/afaerber/qemu-cpu/commits/qom-next
 
 I'd appreciate if some previous reviewer can comment on whether any
 issues have been resolved satisfactorily.
There are no issues with the patches reviewed by me.
Thanks,
Marcel

 
 Thanks,
 Andreas
 






Re: [Qemu-devel] [RFC PATCH v2 5/6] qcow2: implement bdrv_preallocate

2013-12-16 Thread Hu Tao
On Wed, Dec 11, 2013 at 03:33:40PM +0800, Hu Tao wrote:
 On Thu, Nov 28, 2013 at 11:03:04AM +0100, Peter Lieven wrote:
  On 28.11.2013 09:48, Hu Tao wrote:
  On Wed, Nov 27, 2013 at 11:13:40AM +0100, Peter Lieven wrote:
  Am 27.11.2013 11:07, schrieb Fam Zheng:
  On 2013年11月27日 18:03, Peter Lieven wrote:
  Am 27.11.2013 07:40, schrieb Fam Zheng:
  On 2013年11月27日 14:01, Hu Tao wrote:
  On Wed, Nov 27, 2013 at 11:01:23AM +0800, Fam Zheng wrote:
  On 2013年11月27日 10:15, Hu Tao wrote:
  Signed-off-by: Hu Tao hu...@cn.fujitsu.com
  ---
  block/qcow2.c | 7 +++
  1 file changed, 7 insertions(+)
  
  diff --git a/block/qcow2.c b/block/qcow2.c
  index b054a01..a23fade 100644
  --- a/block/qcow2.c
  +++ b/block/qcow2.c
  @@ -2180,6 +2180,12 @@ static int 
  qcow2_amend_options(BlockDriverState *bs,
  return 0;
  }
  
  +static int qcow2_preallocate(BlockDriverState *bs, int64_t offset,
  + int64_t length)
  +{
  +return bdrv_preallocate(bs-file, offset, length);
  +}
  +
  What's the semantics of .bdrv_preallocate? I think you should map
  [offset, offset + length) to clusters in image file, and then
  forward to bs-file, rather than this direct wrapper.
  
  E.g. bdrv_preallocate(qcow2_bs, 0, cluster_size) should call
  bdrv_preallocate(qcow2_bs-file, offset_off_first_cluster,
  cluster_size).
  You mean data clusters here, right? Is there a single function to get
  the offset of the first data cluster?
  
  There is a function, qcow2_get_cluster_offset.
  This should return no valid offset as long as the cluster is not 
  allocated.
  
  I think you actually have to write all clusters of a qcow2 one by one.
  Eventually this write could be an fallocate call instead of a zero 
  write.
  
  Yes, I was wrong about qcow2_get_cluster_offset. The logic here is more 
  like cluster allocation in qcow2_alloc_cluster_offset. Maybe we can 
  reuse that.
  What I don't like about the preallocation is that we would loose the 
  information that a cluster contains no valid data and would read it e.g. 
  during
  conversion.
  So the information is stored in table and you mean we shouldn't clear
  table when do preallocation? I'm not sure how the information could be
  useful on a newly-created image, but it seems ideal to keep informations
  in table.
  When you want to e.g. convert this qcow2 later the performance is lower 
  than needed because
  you read all those preallocated sectors altough you could now they are 
  empty.
  
  I think what we want is a preallocated image with all clusters 
  sequentally mapped into the qcow2 file. Preallocate all the cluster 
  extends, but still
  have the information in the table that the cluster in fact has no valid 
  data. So we would need a valid cluster offset while still haveing the
  flag that the cluster is unallocated. I think this would require 
  thoughtfully checking all the cluster functions if they can easily cope 
  with this.
  
  The quetion is Hu, what do you want to achieve? Do you want that the 
  space on the filesystem is preallocated so you can't overcommit or
  do you also want a sequential mapping of all the clusters into the file?
  The goal is to avoid sparse file as it can cause performance problem. So
  the first one. I'm not sure about the second but IIUC, one fallocate()
  is enough for all clusters if they are sequentially mapped.
  If you do not premap them they are allocated in the order they are written.
  So if you are going to preallocate the whole file anyway, you should 
  sequentally map all clusters into the file
  AND still keep the information that they are in fact not yet written.
 
 Can this be achieved by first fallocate() the disk file, then allocate
 metadata? This way all metadata clusters are allocated before any data
 clusters, leaving all data clusters at the end of file.

Any comments?




Re: [Qemu-devel] [PATCH 0/2] Pointer properties and device_add

2013-12-16 Thread Marcel Apfelbaum
On Sun, 2013-12-15 at 21:51 +0100, Andreas Färber wrote:
 Am 02.12.2013 09:52, schrieb Marcel Apfelbaum:
  On Sun, 2013-12-01 at 16:14 +0100, Andreas Färber wrote:
  The alternative BTW is dropping all those pointer properties and
  replacing them with link properties. Paolo tried that for the OMAP
  timers once but I fear that series was never picked up...?
  I heard about these link properties, can someone point me to their 
  implementation?
 
 Start from object_property_add_link().
 
 linkfoo properties represent a cross-reference to an object of type
 foo, which is representated as a pointer in C and as a textual canonical
 path representation in QMP. By contrast we model childfoo properties
 as value fields (cf. SoC/MPCore modeling discussions) and they actually
 form the canonical paths used by link properties.
Thanks Andreas!
Marcel


 
 Regards,
 Andreas
 






Re: [Qemu-devel] [PATCH 1/2] hw: cannot_instantiate_with_device_add_yet due to pointer props

2013-12-16 Thread Markus Armbruster
Peter Maydell peter.mayd...@linaro.org writes:

 On 15 December 2013 20:55, Andreas Färber afaer...@suse.de wrote:
 Since you're mentioned by name, should I wait for you to review the
 three OMAP parts?

 There's nothing particularly omap-specific in them.

The only OMAP-specific issue I can think of would be me misreading the
intent of the code.

 I kind of think this whole thing is backwards anyway:
 we should really say the user can only instantiate
 devices via command line or monitor that are specifically
 intended to be hot-pluggable, rather than having an
 enormous list of devices we flag as not instantiable
 by the user. Even if someday we manage to make it technically
 possible to instantiate an omap_i2c device (say) from the
 command line, it will still be a completely bizarre thing to do
 because it's only intended to work as a part of the omap SoC.

Hot-pluggable doesn't apply here.  There are plenty of devices that
can only be cold-plugged, yet are absolutely meant to be user-pluggable.
Real ISA cards, for instance.

I share your doubts on the wisdom of letting users plug components via
command line or monitor that are really just parts of bigger components,
like the OMAP SoC.

However, the current code lets users plug absolutely everything, even
stuff that is known not to work.  The code still has the remnants of a
mechanism meant to protect users from known-not-to-work plugs, but it
got broken some time ago.  My Clean up and fix no_user series fixes
that regression in a way that's hopefully agreeable with Anthony, who
has been quite insistent on letting device_add plug more rather than
less.  This series merely patches some holes on top.

The list of non-pluggable devices may be larger than the list of
pluggable ones, but: I count just 48 instances of
cannot_instantiate_with_device_add_yet = true.  I doubt marking
devices that can be plugged instead of the ones than can't be would take
fewer marks.  Moreover, each one comes with a comment explaining *why*
the device cannot be plugged.  Sure nice to have when such a why goes
away.  Some of them are expected to go away eventually.

 Being able to write board models in something other than C
 would be nice, but I really think that if we pursue the idea of
 being able to do it all on the command line we'll just end up with
 a horrifically confusing command line syntax.

Command line / monitor could be divorced from hardware configuration.
Doesn't make much sense with the rather primitive device_add we got now.
May well make sense when our means to wire up hardware by configuration
rather than code have moved closer to the complex wirings we need to
model.



Re: [Qemu-devel] [PATCH 0/2] Pointer properties and device_add

2013-12-16 Thread Markus Armbruster
Andreas Färber afaer...@suse.de writes:

 Am 29.11.2013 10:43, schrieb arm...@redhat.com:
 From: Markus Armbruster arm...@redhat.com
 
 Pointer properties can be set only by code, not by device_add.  A
 device with a pointer property can't work with device_add only unless
 the property may remain null.  cannot_instantiate_with_device_add_yet
 needs to be set then.  PATCH 1/2 sets it when needed and else
 documents why not.  PATCH 2/2 documents this for future users of
 pointer properties.
 
 This applies on top of my [PATCH v4 00/10] Clean up and fix no_user
 series.
 
 Markus Armbruster (2):
   hw: cannot_instantiate_with_device_add_yet due to pointer props
   qdev: Document that pointer properties kill device_add

 Queued both while still waiting for reply from PMM. I somewhat doubt
 that anyone will read the documentation you're adding in 2/2, but at
 least we can then point them to it.

Yup.  I wash my hands before the multitude ;)

 https://github.com/afaerber/qemu-cpu/commits/qom-next

Thanks!



Re: [Qemu-devel] [PATCH v3 7/8] target-arm: A64: add support for 3 src data proc insns

2013-12-16 Thread Claudio Fontana
Hello Peter,

On 13.12.2013 20:18, Peter Maydell wrote:
 From: Alexander Graf ag...@suse.de
 
 This patch adds emulation for the Data-processing (3 source)
 family of instructions, namely MADD, MSUB, SMADDL, SMSUBL, SMULH,
 UMADDL, UMSUBL, UMULH.
 
 Signed-off-by: Alexander Graf ag...@suse.de
 Signed-off-by: Alex Bennée alex.ben...@linaro.org
 Signed-off-by: Peter Maydell peter.mayd...@linaro.org
 ---
  target-arm/translate-a64.c | 91 
 +-
  1 file changed, 89 insertions(+), 2 deletions(-)
 
 diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c
 index a6f1945..b3e9449 100644
 --- a/target-arm/translate-a64.c
 +++ b/target-arm/translate-a64.c
 @@ -2125,10 +2125,97 @@ static void disas_add_sub_reg(DisasContext *s, 
 uint32_t insn)
  tcg_temp_free_i64(tcg_result);
  }
  
 -/* Data-processing (3 source) */
 +/* C3.5.9 Data-processing (3 source)
 +
 +   31 30  29 28   24 23 21  20  16  15  14  10 95 40
 +  +--+--+---+--+--++--+--+--+
 +  |sf| op54 | 1 1 0 1 1 | op31 |  Rm  | o0 |  Ra  |  Rn  |  Rd  |
 +  +--+--+---+--+--++--+--+--+
 +
 + */
  static void disas_data_proc_3src(DisasContext *s, uint32_t insn)
  {
 -unsupported_encoding(s, insn);
 +int rd = extract32(insn, 0, 5);
 +int rn = extract32(insn, 5, 5);
 +int ra = extract32(insn, 10, 5);
 +int rm = extract32(insn, 16, 5);
 +int op_id = (extract32(insn, 29, 3)  4) |
 +(extract32(insn, 21, 3)  1) |
 +extract32(insn, 15, 1);
 +bool is_32bit = !extract32(insn, 31, 1);

we have used sf everywhere else..

 +bool is_sub = extract32(op_id, 0, 1);
 +bool is_high = extract32(op_id, 2, 1);
 +bool is_signed = false;
 +TCGv_i64 tcg_op1;
 +TCGv_i64 tcg_op2;
 +TCGv_i64 tcg_tmp;
 +
 +/* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag 
 */
 +switch (op_id) {
 +case 0x42: /* SMADDL */
 +case 0x43: /* SMSUBL */
 +case 0x44: /* SMULH */
 +is_signed = true;
 +break;
 +case 0x0: /* MADD (32bit) */
 +case 0x1: /* MSUB (32bit) */
 +case 0x40: /* MADD (64bit) */
 +case 0x41: /* MSUB (64bit) */
 +case 0x4a: /* UMADDL */
 +case 0x4b: /* UMSUBL */
 +case 0x4c: /* UMULH */
 +break;
 +default:
 +unallocated_encoding(s);
 +}
 +
 +if (is_high) {
 +TCGv_i64 low_bits = tcg_temp_new_i64(); /* low bits discarded */
 +TCGv_i64 tcg_rd = cpu_reg(s, rd);
 +TCGv_i64 tcg_rn = cpu_reg(s, rn);
 +TCGv_i64 tcg_rm = cpu_reg(s, rm);
 +
 +if (is_signed) {
 +tcg_gen_muls2_i64(low_bits, tcg_rd, tcg_rn, tcg_rm);
 +} else {
 +tcg_gen_mulu2_i64(low_bits, tcg_rd, tcg_rn, tcg_rm);
 +}
 +
 +tcg_temp_free(low_bits);

should this be tcg_temp_free_i64()?

 +return;
 +}
 +
 +tcg_op1 = tcg_temp_new_i64();
 +tcg_op2 = tcg_temp_new_i64();
 +tcg_tmp = tcg_temp_new_i64();
 +
 +if (op_id  0x42) {
 +tcg_gen_mov_i64(tcg_op1, cpu_reg(s, rn));
 +tcg_gen_mov_i64(tcg_op2, cpu_reg(s, rm));
 +} else {
 +if (is_signed) {
 +tcg_gen_ext32s_i64(tcg_op1, cpu_reg(s, rn));
 +tcg_gen_ext32s_i64(tcg_op2, cpu_reg(s, rm));
 +} else {
 +tcg_gen_ext32u_i64(tcg_op1, cpu_reg(s, rn));
 +tcg_gen_ext32u_i64(tcg_op2, cpu_reg(s, rm));
 +}
 +}
 +
 +tcg_gen_mul_i64(tcg_tmp, tcg_op1, tcg_op2);
 +if (is_sub) {
 +tcg_gen_sub_i64(cpu_reg(s, rd), cpu_reg(s, ra), tcg_tmp);
 +} else {
 +tcg_gen_add_i64(cpu_reg(s, rd), cpu_reg(s, ra), tcg_tmp);
 +}
 +
 +if (is_32bit) {
 +tcg_gen_ext32u_i64(cpu_reg(s, rd), cpu_reg(s, rd));
 +}
 +
 +tcg_temp_free_i64(tcg_op1);
 +tcg_temp_free_i64(tcg_op2);
 +tcg_temp_free_i64(tcg_tmp);
  }
  
  /* Add/subtract (with carry) */
 

Ciao,

Claudio





Re: [Qemu-devel] [PATCH RFC 2/3] qapi script: add support of event

2013-12-16 Thread Markus Armbruster
Wenchao Xia xiaw...@linux.vnet.ibm.com writes:

 于 2013/12/13 21:43, Kevin Wolf 写道:
 Am 13.12.2013 um 14:31 hat Eric Blake geschrieben:
 On 11/12/2013 06:44 PM, Wenchao Xia wrote:
 +++ b/scripts/qapi-event.py
 @@ -0,0 +1,355 @@
 +#
 +# QAPI event generator
 +#
 +# Copyright IBM, Corp. 2013
 +#
 +# Authors:
 +#  Wenchao Xia xiaw...@linux.vnet.ibm.com
 +#
 +# This work is licensed under the terms of the GNU GPLv2.

 Can you please use GPLv2+ (that is, add the or later clause)?  We
 already have GPLv2-only code, but I don't want to increase the size of
 that unfortunate license choice.

 In fact, it's even worse:

 +# This work is licensed under the terms of the GNU GPLv2.
 +# See the COPYING.LIB file in the top-level directory.

 These two lines contradict each other, COPYING.LIB contains the
 LGPL 2.1. The same bad license header is in the other QAPI generator
 scripts, so it's only copypaste here.

 This doesn't make things easier, because if things are copied, the
 license of the source must be respected. And it seems rather dubious to
 me what this license actually is. If it's GPLv2-only, we can't just
 change it in the new copy.

 Kevin

   ah..I am bad in license problem, will use the doc as LGPL from other
 file.

Please use GPLv2+ unless you have a specific reason for another license.



[Qemu-devel] [PATCH v2] x86: gigabyte alignment for ram

2013-12-16 Thread Gerd Hoffmann
Map 3G (i440fx) or 2G (q35) of memory below 4G, so the RAM pieces
are nicely aligned to gigabyte borders.

Keep old memory layout for (a) old machine types and (b) in case all
memory fits below 4G and thus we don't have to split RAM into pieces
in the first place.  The later makes sure this change doesn't take
away memory from 32bit guests.

So, with i440fx and up to 3.5 GB of memory, all of it will be mapped
below 4G.  With more than 3.5 GB of memory 3 GB will be mapped below
4G and the remaining amount will be mapped above 4G.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
v2: rebased, resolved comflicts, resent as non-rfc
---
 hw/i386/pc_piix.c | 7 +--
 hw/i386/pc_q35.c  | 7 +--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 4e0dae7..acb9445 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -61,6 +61,7 @@ static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
 static bool has_pci_info;
 static bool has_acpi_build = true;
 static bool smbios_type1_defaults = true;
+static bool gigabyte_align = true;
 
 /* PC hardware initialisation */
 static void pc_init1(QEMUMachineInitArgs *args,
@@ -107,8 +108,9 @@ static void pc_init1(QEMUMachineInitArgs *args,
 }
 
 if (args-ram_size = 0xe000) {
-above_4g_mem_size = args-ram_size - 0xe000;
-below_4g_mem_size = 0xe000;
+ram_addr_t lowmem = gigabyte_align ? 0xc000 : 0xe000;
+above_4g_mem_size = args-ram_size - lowmem;
+below_4g_mem_size = lowmem;
 } else {
 above_4g_mem_size = 0;
 below_4g_mem_size = args-ram_size;
@@ -245,6 +247,7 @@ static void pc_init_pci(QEMUMachineInitArgs *args)
 static void pc_compat_1_7(QEMUMachineInitArgs *args)
 {
 smbios_type1_defaults = false;
+gigabyte_align = false;
 }
 
 static void pc_compat_1_6(QEMUMachineInitArgs *args)
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 07f38ff..7104645 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -51,6 +51,7 @@
 static bool has_pci_info;
 static bool has_acpi_build = true;
 static bool smbios_type1_defaults = true;
+static bool gigabyte_align = true;
 
 /* PC hardware initialisation */
 static void pc_q35_init(QEMUMachineInitArgs *args)
@@ -93,8 +94,9 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
 kvmclock_create();
 
 if (args-ram_size = 0xb000) {
-above_4g_mem_size = args-ram_size - 0xb000;
-below_4g_mem_size = 0xb000;
+ram_addr_t lowmem = gigabyte_align ? 0x8000 : 0xb000;
+above_4g_mem_size = args-ram_size - lowmem;
+below_4g_mem_size = lowmem;
 } else {
 above_4g_mem_size = 0;
 below_4g_mem_size = args-ram_size;
@@ -228,6 +230,7 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
 static void pc_compat_1_7(QEMUMachineInitArgs *args)
 {
 smbios_type1_defaults = false;
+gigabyte_align = false;
 }
 
 static void pc_compat_1_6(QEMUMachineInitArgs *args)
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH RFC 2/3] qapi script: add support of event

2013-12-16 Thread Markus Armbruster
[Licensing problem, cc: Anthony]

Kevin Wolf kw...@redhat.com writes:

 Am 13.12.2013 um 14:31 hat Eric Blake geschrieben:
 On 11/12/2013 06:44 PM, Wenchao Xia wrote:
  +++ b/scripts/qapi-event.py
  @@ -0,0 +1,355 @@
  +#
  +# QAPI event generator
  +#
  +# Copyright IBM, Corp. 2013
  +#
  +# Authors:
  +#  Wenchao Xia xiaw...@linux.vnet.ibm.com
  +#
  +# This work is licensed under the terms of the GNU GPLv2.
 
 Can you please use GPLv2+ (that is, add the or later clause)?  We
 already have GPLv2-only code, but I don't want to increase the size of
 that unfortunate license choice.

 In fact, it's even worse:

 +# This work is licensed under the terms of the GNU GPLv2.
 +# See the COPYING.LIB file in the top-level directory.

 These two lines contradict each other, COPYING.LIB contains the
 LGPL 2.1. The same bad license header is in the other QAPI generator
 scripts, so it's only copypaste here.

Specifically:

FileCommit
scripts/qapi-commands.pyc17d9908
scripts/qapi-visit.py   fb3182ce
scripts/qapi-types.py   06d64c62
scripts/qapi.py 0f923be2

All four from Michael Roth via Luiz.

 This doesn't make things easier, because if things are copied, the
 license of the source must be respected. And it seems rather dubious to
 me what this license actually is. If it's GPLv2-only, we can't just
 change it in the new copy.

IANAL, and I wouldn't dare to judge which of the two conflicting license
claims takes precedence.  Possibly neither, and then the files might
technically not be distributable.

Anyway, this mess needs to be addressed.  Michael, what was your
*intended* license?

If it wasn't GPLv2+, then why?

Do we need formal ACKs from all contributors to fix the licensing
comment in these four files?



Re: [Qemu-devel] [PATCH v3 5/7] Add vhost-user calls implementation

2013-12-16 Thread Luke Gorrie
Cool stuff :-)

some thoughts:

On 13 December 2013 12:14, Antonios Motakis
a.mota...@virtualopensystems.com wrote:
  static int vhost_user_recv(int fd, VhostUserMsg *msg)
  {
  ssize_t r = read(fd, msg, sizeof(VhostUserMsg));

Is it worth considering a timeout and reconnect check here? I mean
so that if the vhost server does not respond for any reason the guess
will see link down instead of freezing the hypervisor (?).

 +case VHOST_SET_VRING_ADDR:
 +memcpy(msg.addr, arg, sizeof(struct vhost_vring_addr));
 +break;

I think these vring addresses need to be remapped from qemu address
space to guest-physical address space.



Re: [Qemu-devel] [PATCH v3 7/7] Add vhost-user reconnection

2013-12-16 Thread Luke Gorrie
On 13 December 2013 12:14, Antonios Motakis
a.mota...@virtualopensystems.com wrote:
 At runtime vhost-user netdev will detect if the vhost backend is up or down.
 Upon disconnection it will set link_down accordingly and notify virtio-net.

Based on inspection with 'lsof' I think that the v3 reconnect
mechanism leaks socket file descriptors.



Re: [Qemu-devel] [RFC PATCH v2 5/6] qcow2: implement bdrv_preallocate

2013-12-16 Thread Fam Zheng

On 2013年12月11日 15:33, Hu Tao wrote:

On Thu, Nov 28, 2013 at 11:03:04AM +0100, Peter Lieven wrote:

On 28.11.2013 09:48, Hu Tao wrote:

On Wed, Nov 27, 2013 at 11:13:40AM +0100, Peter Lieven wrote:

Am 27.11.2013 11:07, schrieb Fam Zheng:

On 2013年11月27日 18:03, Peter Lieven wrote:

Am 27.11.2013 07:40, schrieb Fam Zheng:

On 2013年11月27日 14:01, Hu Tao wrote:

On Wed, Nov 27, 2013 at 11:01:23AM +0800, Fam Zheng wrote:

On 2013年11月27日 10:15, Hu Tao wrote:

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
---
block/qcow2.c | 7 +++
1 file changed, 7 insertions(+)

diff --git a/block/qcow2.c b/block/qcow2.c
index b054a01..a23fade 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2180,6 +2180,12 @@ static int qcow2_amend_options(BlockDriverState *bs,
return 0;
}

+static int qcow2_preallocate(BlockDriverState *bs, int64_t offset,
+ int64_t length)
+{
+return bdrv_preallocate(bs-file, offset, length);
+}
+

What's the semantics of .bdrv_preallocate? I think you should map
[offset, offset + length) to clusters in image file, and then
forward to bs-file, rather than this direct wrapper.

E.g. bdrv_preallocate(qcow2_bs, 0, cluster_size) should call
bdrv_preallocate(qcow2_bs-file, offset_off_first_cluster,
cluster_size).

You mean data clusters here, right? Is there a single function to get
the offset of the first data cluster?


There is a function, qcow2_get_cluster_offset.

This should return no valid offset as long as the cluster is not allocated.

I think you actually have to write all clusters of a qcow2 one by one.
Eventually this write could be an fallocate call instead of a zero write.


Yes, I was wrong about qcow2_get_cluster_offset. The logic here is more like 
cluster allocation in qcow2_alloc_cluster_offset. Maybe we can reuse that.

What I don't like about the preallocation is that we would loose the 
information that a cluster contains no valid data and would read it e.g. during
conversion.

So the information is stored in table and you mean we shouldn't clear
table when do preallocation? I'm not sure how the information could be
useful on a newly-created image, but it seems ideal to keep informations
in table.

When you want to e.g. convert this qcow2 later the performance is lower than 
needed because
you read all those preallocated sectors altough you could now they are empty.



I think what we want is a preallocated image with all clusters sequentally 
mapped into the qcow2 file. Preallocate all the cluster extends, but still
have the information in the table that the cluster in fact has no valid data. 
So we would need a valid cluster offset while still haveing the
flag that the cluster is unallocated. I think this would require thoughtfully 
checking all the cluster functions if they can easily cope with this.

The quetion is Hu, what do you want to achieve? Do you want that the space on 
the filesystem is preallocated so you can't overcommit or
do you also want a sequential mapping of all the clusters into the file?

The goal is to avoid sparse file as it can cause performance problem. So
the first one. I'm not sure about the second but IIUC, one fallocate()
is enough for all clusters if they are sequentially mapped.

If you do not premap them they are allocated in the order they are written.
So if you are going to preallocate the whole file anyway, you should 
sequentally map all clusters into the file
AND still keep the information that they are in fact not yet written.


Can this be achieved by first fallocate() the disk file, then allocate
metadata? This way all metadata clusters are allocated before any data
clusters, leaving all data clusters at the end of file.



I think Peter means your need to sequentially map clusters into the 
file, so that sequential IO in guest is translated to sequential IO on 
the image file.


fallocate() or posix_fallocate() should work. You need to set zero flag 
on the allocated cluster when mapping it in L2, instead of actually 
writing zeros.


Fam



[Qemu-devel] [PATCH 01/16] spice: flip streaming video mode to off by default

2013-12-16 Thread Gerd Hoffmann
Video streaming detection heuristics in spice-server have problems
keeping modern desktop animations (as done by gnome shell) and real
video playback apart.  This leads to jpeg compression artefacts on
your desktop, due to spice using mjpeg to send what it thinks is
a video stream.

Turn off video detection by default to avoid these artifacts.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
Reviewed-by: Alon Levy al...@redhat.com
---
 ui/spice-core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ui/spice-core.c b/ui/spice-core.c
index e4d533d..9fb9544 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -776,6 +776,8 @@ void qemu_spice_init(void)
 if (str) {
 int streaming_video = parse_stream_video(str);
 spice_server_set_streaming_video(spice_server, streaming_video);
+} else {
+spice_server_set_streaming_video(spice_server, SPICE_STREAM_VIDEO_OFF);
 }
 
 spice_server_set_agent_mouse
-- 
1.8.3.1




[Qemu-devel] [PATCH 03/16] spice-char: remove unused field

2013-12-16 Thread Gerd Hoffmann
From: Marc-André Lureau marcandre.lur...@redhat.com

Signed-off-by: Marc-André Lureau marcandre.lur...@gmail.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 spice-qemu-char.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/spice-qemu-char.c b/spice-qemu-char.c
index 6d147a7..e074d9e 100644
--- a/spice-qemu-char.c
+++ b/spice-qemu-char.c
@@ -11,7 +11,6 @@
 typedef struct SpiceCharDriver {
 CharDriverState*  chr;
 SpiceCharDeviceInstance sin;
-char  *subtype;
 bool  active;
 bool  blocked;
 const uint8_t *datapos;
-- 
1.8.3.1




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

2013-12-16 Thread Gerd Hoffmann
  Hi,

Here comes the spice patch queue, with some nbd bits for upcoming
spice-nbd and the usual share of small fixes  cleanups.

please pull,
  Gerd

The following changes since commit e157b8fdd412d48eacfbb8c67d3d58780154faa3:

  Merge remote-tracking branch 'bonzini/virtio' into staging (2013-12-13 
11:10:33 -0800)

are available in the git repository at:


  git://anongit.freedesktop.org/spice/qemu tags/pull-spice-1

for you to fetch changes up to 75c70e37bc4a6bdc394b4d1b163fe730abb82c72:

  spice: stop server for qxl hard reset (2013-12-16 10:12:20 +0100)


Collection of little cleanups anf bugfixes.
nbd patches in preparation of spice-nbd.


Gerd Hoffmann (4):
  spice: flip streaming video mode to off by default
  spice: move qemu_spice_display_*() from spice-graphics to spice-core
  spice: move spice_server_vm_{start,stop} calls into qemu_spice_display_*()
  spice: stop server for qxl hard reset

Marc-André Lureau (12):
  vscclient: do not add a socket watch if there is not data to send
  spice-char: remove unused field
  qmp_change_blockdev() remove unused has_format
  include: add missing config-host.h include
  char: add qemu_chr_fe_event()
  spice-char: implement chardev port event
  Split nbd block client code
  nbd: don't change socket block during negotiate
  nbd: pass export name as init argument
  nbd: make nbd_client_session_close() idempotent
  nbd: finish any pending coroutine
  nbd: avoid uninitialized warnings

 block/Makefile.objs   |   2 +-
 block/nbd-client.c| 385 ++
 block/nbd-client.h|  50 ++
 block/nbd.c   | 380 -
 blockdev.c|   2 +-
 hw/display/qxl.c  |  10 ++
 include/sysemu/blockdev.h |   2 +-
 include/sysemu/char.h |  10 ++
 include/ui/qemu-spice.h   |   2 +
 libcacard/vscclient.c |  10 +-
 nbd.c |   2 -
 qemu-char.c   |   7 +
 qmp.c |   2 +-
 spice-qemu-char.c |  11 +-
 ui/spice-core.c   |  22 ++-
 ui/spice-display.c|  17 --
 16 files changed, 537 insertions(+), 377 deletions(-)
 create mode 100644 block/nbd-client.c
 create mode 100644 block/nbd-client.h



[Qemu-devel] [PATCH 08/16] Split nbd block client code

2013-12-16 Thread Gerd Hoffmann
From: Marc-André Lureau marcandre.lur...@redhat.com

Signed-off-by: Marc-André Lureau marcandre.lur...@redhat.com
Acked-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 block/Makefile.objs |   2 +-
 block/nbd-client.c  | 372 +++
 block/nbd-client.h  |  51 +++
 block/nbd.c | 373 
 4 files changed, 452 insertions(+), 346 deletions(-)
 create mode 100644 block/nbd-client.c
 create mode 100644 block/nbd-client.h

diff --git a/block/Makefile.objs b/block/Makefile.objs
index f43ecbc..4e8c91e 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -10,7 +10,7 @@ block-obj-$(CONFIG_POSIX) += raw-posix.o
 block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 
 ifeq ($(CONFIG_POSIX),y)
-block-obj-y += nbd.o sheepdog.o
+block-obj-y += nbd.o nbd-client.o sheepdog.o
 block-obj-$(CONFIG_LIBISCSI) += iscsi.o
 block-obj-$(CONFIG_CURL) += curl.o
 block-obj-$(CONFIG_RBD) += rbd.o
diff --git a/block/nbd-client.c b/block/nbd-client.c
new file mode 100644
index 000..1abfc6a
--- /dev/null
+++ b/block/nbd-client.c
@@ -0,0 +1,372 @@
+/*
+ * QEMU Block driver for  NBD
+ *
+ * Copyright (C) 2008 Bull S.A.S.
+ * Author: Laurent Vivier laurent.viv...@bull.net
+ *
+ * Some parts:
+ *Copyright (C) 2007 Anthony Liguori anth...@codemonkey.ws
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the Software), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include nbd-client.h
+#include qemu/sockets.h
+
+#define HANDLE_TO_INDEX(bs, handle) ((handle) ^ ((uint64_t)(intptr_t)bs))
+#define INDEX_TO_HANDLE(bs, index)  ((index)  ^ ((uint64_t)(intptr_t)bs))
+
+static void nbd_reply_ready(void *opaque)
+{
+NbdClientSession *s = opaque;
+uint64_t i;
+int ret;
+
+if (s-reply.handle == 0) {
+/* No reply already in flight.  Fetch a header.  It is possible
+ * that another thread has done the same thing in parallel, so
+ * the socket is not readable anymore.
+ */
+ret = nbd_receive_reply(s-sock, s-reply);
+if (ret == -EAGAIN) {
+return;
+}
+if (ret  0) {
+s-reply.handle = 0;
+goto fail;
+}
+}
+
+/* There's no need for a mutex on the receive side, because the
+ * handler acts as a synchronization point and ensures that only
+ * one coroutine is called until the reply finishes.  */
+i = HANDLE_TO_INDEX(s, s-reply.handle);
+if (i = MAX_NBD_REQUESTS) {
+goto fail;
+}
+
+if (s-recv_coroutine[i]) {
+qemu_coroutine_enter(s-recv_coroutine[i], NULL);
+return;
+}
+
+fail:
+for (i = 0; i  MAX_NBD_REQUESTS; i++) {
+if (s-recv_coroutine[i]) {
+qemu_coroutine_enter(s-recv_coroutine[i], NULL);
+}
+}
+}
+
+static void nbd_restart_write(void *opaque)
+{
+NbdClientSession *s = opaque;
+
+qemu_coroutine_enter(s-send_coroutine, NULL);
+}
+
+static int nbd_co_send_request(NbdClientSession *s,
+struct nbd_request *request,
+QEMUIOVector *qiov, int offset)
+{
+int rc, ret;
+
+qemu_co_mutex_lock(s-send_mutex);
+s-send_coroutine = qemu_coroutine_self();
+qemu_aio_set_fd_handler(s-sock, nbd_reply_ready, nbd_restart_write, s);
+if (qiov) {
+if (!s-is_unix) {
+socket_set_cork(s-sock, 1);
+}
+rc = nbd_send_request(s-sock, request);
+if (rc = 0) {
+ret = qemu_co_sendv(s-sock, qiov-iov, qiov-niov,
+offset, request-len);
+if (ret != request-len) {
+rc = -EIO;
+}
+}
+if (!s-is_unix) {
+socket_set_cork(s-sock, 0);
+}
+} else {
+rc = nbd_send_request(s-sock, request);
+}
+qemu_aio_set_fd_handler(s-sock, nbd_reply_ready, NULL, s);
+s-send_coroutine = NULL;
+qemu_co_mutex_unlock(s-send_mutex);
+return rc;
+}
+
+static 

[Qemu-devel] [PATCH 02/16] vscclient: do not add a socket watch if there is not data to send

2013-12-16 Thread Gerd Hoffmann
From: Marc-André Lureau marcandre.lur...@redhat.com

Fixes the following error:
** (process:780): CRITICAL **: do_socket_send: assertion
`socket_to_send-len != 0' failed

Signed-off-by: Marc-André Lureau marcandre.lur...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 libcacard/vscclient.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libcacard/vscclient.c b/libcacard/vscclient.c
index f1d46d3..24f7088 100644
--- a/libcacard/vscclient.c
+++ b/libcacard/vscclient.c
@@ -58,7 +58,7 @@ static QemuMutex socket_to_send_lock;
 static guint socket_tag;
 
 static void
-update_socket_watch(gboolean out);
+update_socket_watch(void);
 
 static gboolean
 do_socket_send(GIOChannel *source,
@@ -80,7 +80,7 @@ do_socket_send(GIOChannel *source,
 g_byte_array_remove_range(socket_to_send, 0, bw);
 
 if (socket_to_send-len == 0) {
-update_socket_watch(FALSE);
+update_socket_watch();
 return FALSE;
 }
 return TRUE;
@@ -89,7 +89,7 @@ do_socket_send(GIOChannel *source,
 static gboolean
 socket_prepare_sending(gpointer user_data)
 {
-update_socket_watch(TRUE);
+update_socket_watch();
 
 return FALSE;
 }
@@ -440,8 +440,10 @@ do_socket(GIOChannel *source,
 }
 
 static void
-update_socket_watch(gboolean out)
+update_socket_watch(void)
 {
+gboolean out = socket_to_send-len  0;
+
 if (socket_tag != 0) {
 g_source_remove(socket_tag);
 }
-- 
1.8.3.1




[Qemu-devel] [PATCH 06/16] char: add qemu_chr_fe_event()

2013-12-16 Thread Gerd Hoffmann
From: Marc-André Lureau marcandre.lur...@redhat.com

Teach the chardev frontend to send event. This is used by the Spice port
chardev currently.

Signed-off-by: Marc-André Lureau marcandre.lur...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 include/sysemu/char.h | 10 ++
 qemu-char.c   |  7 +++
 2 files changed, 17 insertions(+)

diff --git a/include/sysemu/char.h b/include/sysemu/char.h
index ad101d9..b81a6ff 100644
--- a/include/sysemu/char.h
+++ b/include/sysemu/char.h
@@ -69,6 +69,7 @@ struct CharDriverState {
 void (*chr_accept_input)(struct CharDriverState *chr);
 void (*chr_set_echo)(struct CharDriverState *chr, bool echo);
 void (*chr_set_fe_open)(struct CharDriverState *chr, int fe_open);
+void (*chr_fe_event)(struct CharDriverState *chr, int event);
 void *opaque;
 char *label;
 char *filename;
@@ -138,6 +139,15 @@ void qemu_chr_fe_set_echo(struct CharDriverState *chr, 
bool echo);
 void qemu_chr_fe_set_open(struct CharDriverState *chr, int fe_open);
 
 /**
+ * @qemu_chr_fe_event:
+ *
+ * Send an event from the front end to the back end.
+ *
+ * @event the event to send
+ */
+void qemu_chr_fe_event(CharDriverState *s, int event);
+
+/**
  * @qemu_chr_fe_printf:
  *
  * Write to a character backend using a printf style interface.
diff --git a/qemu-char.c b/qemu-char.c
index e00f84c..418dc69 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -3353,6 +3353,13 @@ void qemu_chr_fe_set_open(struct CharDriverState *chr, 
int fe_open)
 }
 }
 
+void qemu_chr_fe_event(struct CharDriverState *chr, int event)
+{
+if (chr-chr_fe_event) {
+chr-chr_fe_event(chr, event);
+}
+}
+
 int qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond,
   GIOFunc func, void *user_data)
 {
-- 
1.8.3.1




[Qemu-devel] [PATCH 13/16] nbd: avoid uninitialized warnings

2013-12-16 Thread Gerd Hoffmann
From: Marc-André Lureau marcandre.lur...@gmail.com

==15815== Thread 1:
==15815== Syscall param socketcall.sendto(msg) points to uninitialised byte(s)
==15815==at 0x65AD5CB: send (send.c:31)
==15815==by 0x37F84B: nbd_wr_sync (nbd.c:145)
==15815==by 0x37F94B: write_sync (nbd.c:186)
==15815==by 0x380FA9: nbd_send_request (nbd.c:681)
==15815==by 0x1C4A2D: nbd_teardown_connection (nbd-client.c:337)
==15815==by 0x1C4AD8: nbd_client_session_close (nbd-client.c:354)
==15815==by 0x1ED2D8: close_socketpair (spicebd.c:132)
==15815==by 0x1EE265: spice_close (spicebd.c:457)
==15815==by 0x1ACBF6: bdrv_close (block.c:1519)
==15815==by 0x1AD804: bdrv_delete (block.c:1772)
==15815==by 0x1B4136: bdrv_unref (block.c:4476)
==15815==by 0x1ACCE0: bdrv_close (block.c:1541)
==15815==  Address 0x7feffef98 is on thread 1's stack

Signed-off-by: Marc-André Lureau marcandre.lur...@gmail.com
Acked-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 block/nbd-client.c | 21 +
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/block/nbd-client.c b/block/nbd-client.c
index 1973cf0..0922b78 100644
--- a/block/nbd-client.c
+++ b/block/nbd-client.c
@@ -185,11 +185,10 @@ static int nbd_co_readv_1(NbdClientSession *client, 
int64_t sector_num,
   int nb_sectors, QEMUIOVector *qiov,
   int offset)
 {
-struct nbd_request request;
+struct nbd_request request = { .type = NBD_CMD_READ };
 struct nbd_reply reply;
 ssize_t ret;
 
-request.type = NBD_CMD_READ;
 request.from = sector_num * 512;
 request.len = nb_sectors * 512;
 
@@ -209,11 +208,10 @@ static int nbd_co_writev_1(NbdClientSession *client, 
int64_t sector_num,
int nb_sectors, QEMUIOVector *qiov,
int offset)
 {
-struct nbd_request request;
+struct nbd_request request = { .type = NBD_CMD_WRITE };
 struct nbd_reply reply;
 ssize_t ret;
 
-request.type = NBD_CMD_WRITE;
 if (!bdrv_enable_write_cache(client-bs) 
 (client-nbdflags  NBD_FLAG_SEND_FUA)) {
 request.type |= NBD_CMD_FLAG_FUA;
@@ -275,7 +273,7 @@ int nbd_client_session_co_writev(NbdClientSession *client, 
int64_t sector_num,
 
 int nbd_client_session_co_flush(NbdClientSession *client)
 {
-struct nbd_request request;
+struct nbd_request request = { .type = NBD_CMD_FLUSH };
 struct nbd_reply reply;
 ssize_t ret;
 
@@ -283,7 +281,6 @@ int nbd_client_session_co_flush(NbdClientSession *client)
 return 0;
 }
 
-request.type = NBD_CMD_FLUSH;
 if (client-nbdflags  NBD_FLAG_SEND_FUA) {
 request.type |= NBD_CMD_FLAG_FUA;
 }
@@ -305,14 +302,13 @@ int nbd_client_session_co_flush(NbdClientSession *client)
 int nbd_client_session_co_discard(NbdClientSession *client, int64_t sector_num,
 int nb_sectors)
 {
-struct nbd_request request;
+struct nbd_request request = { .type = NBD_CMD_TRIM };
 struct nbd_reply reply;
 ssize_t ret;
 
 if (!(client-nbdflags  NBD_FLAG_SEND_TRIM)) {
 return 0;
 }
-request.type = NBD_CMD_TRIM;
 request.from = sector_num * 512;
 request.len = nb_sectors * 512;
 
@@ -330,11 +326,12 @@ int nbd_client_session_co_discard(NbdClientSession 
*client, int64_t sector_num,
 
 static void nbd_teardown_connection(NbdClientSession *client)
 {
-struct nbd_request request;
+struct nbd_request request = {
+.type = NBD_CMD_DISC,
+.from = 0,
+.len = 0
+};
 
-request.type = NBD_CMD_DISC;
-request.from = 0;
-request.len = 0;
 nbd_send_request(client-sock, request);
 
 /* finish any pending coroutines */
-- 
1.8.3.1




[Qemu-devel] [PATCH 05/16] include: add missing config-host.h include

2013-12-16 Thread Gerd Hoffmann
From: Marc-André Lureau marcandre.lur...@redhat.com

Signed-off-by: Marc-André Lureau marcandre.lur...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 include/ui/qemu-spice.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/ui/qemu-spice.h b/include/ui/qemu-spice.h
index 86c75c7..a93b4b2 100644
--- a/include/ui/qemu-spice.h
+++ b/include/ui/qemu-spice.h
@@ -18,6 +18,8 @@
 #ifndef QEMU_SPICE_H
 #define QEMU_SPICE_H
 
+#include config-host.h
+
 #ifdef CONFIG_SPICE
 
 #include spice.h
-- 
1.8.3.1




[Qemu-devel] [PATCH] usb: Remove magic constants from device bmAttributes

2013-12-16 Thread Pantelis Koukousoulas
Replace magic constants in device bmAttributes with symbolic ones
from Linux kernel ch9.h

Signed-off-by: Pantelis Koukousoulas pkt...@gmail.com
---
 hw/usb/desc.c | 2 +-
 hw/usb/dev-audio.c| 2 +-
 hw/usb/dev-bluetooth.c| 2 +-
 hw/usb/dev-hid.c  | 8 
 hw/usb/dev-hub.c  | 2 +-
 hw/usb/dev-network.c  | 4 ++--
 hw/usb/dev-serial.c   | 2 +-
 hw/usb/dev-smartcard-reader.c | 2 +-
 hw/usb/dev-storage.c  | 6 +++---
 hw/usb/dev-uas.c  | 4 ++--
 hw/usb/dev-wacom.c| 2 +-
 include/hw/usb.h  | 5 +
 12 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/hw/usb/desc.c b/hw/usb/desc.c
index f18a043..7abc1ea 100644
--- a/hw/usb/desc.c
+++ b/hw/usb/desc.c
@@ -743,7 +743,7 @@ int usb_desc_handle_control(USBDevice *dev, USBPacket *p,
  * We return the same value that a configured device would return if
  * it used the first configuration.
  */
-if (config-bmAttributes  0x40) {
+if (config-bmAttributes  USB_CONFIG_ATT_SELFPOWER) {
 data[0] |= 1  USB_DEVICE_SELF_POWERED;
 }
 if (dev-remote_wakeup) {
diff --git a/hw/usb/dev-audio.c b/hw/usb/dev-audio.c
index c5420eb..ab5df61 100644
--- a/hw/usb/dev-audio.c
+++ b/hw/usb/dev-audio.c
@@ -224,7 +224,7 @@ static const USBDescDevice desc_device = {
 .bNumInterfaces= 2,
 .bConfigurationValue   = DEV_CONFIG_VALUE,
 .iConfiguration= STRING_CONFIG,
-.bmAttributes  = 0xc0,
+.bmAttributes  = USB_CONFIG_ATT_ONE | 
USB_CONFIG_ATT_SELFPOWER,
 .bMaxPower = 0x32,
 .nif = ARRAY_SIZE(desc_iface),
 .ifs = desc_iface,
diff --git a/hw/usb/dev-bluetooth.c b/hw/usb/dev-bluetooth.c
index 7f292b1..28ef1d5 100644
--- a/hw/usb/dev-bluetooth.c
+++ b/hw/usb/dev-bluetooth.c
@@ -229,7 +229,7 @@ static const USBDescDevice desc_device_bluetooth = {
 {
 .bNumInterfaces= 2,
 .bConfigurationValue   = 1,
-.bmAttributes  = 0xc0,
+.bmAttributes  = USB_CONFIG_ATT_ONE | 
USB_CONFIG_ATT_SELFPOWER,
 .bMaxPower = 0,
 .nif = ARRAY_SIZE(desc_iface_bluetooth),
 .ifs = desc_iface_bluetooth,
diff --git a/hw/usb/dev-hid.c b/hw/usb/dev-hid.c
index 5e667f0..5f39afc 100644
--- a/hw/usb/dev-hid.c
+++ b/hw/usb/dev-hid.c
@@ -202,7 +202,7 @@ static const USBDescDevice desc_device_mouse = {
 .bNumInterfaces= 1,
 .bConfigurationValue   = 1,
 .iConfiguration= STR_CONFIG_MOUSE,
-.bmAttributes  = 0xa0,
+.bmAttributes  = USB_CONFIG_ATT_ONE | 
USB_CONFIG_ATT_WAKEUP,
 .bMaxPower = 50,
 .nif = 1,
 .ifs = desc_iface_mouse,
@@ -219,7 +219,7 @@ static const USBDescDevice desc_device_tablet = {
 .bNumInterfaces= 1,
 .bConfigurationValue   = 1,
 .iConfiguration= STR_CONFIG_TABLET,
-.bmAttributes  = 0xa0,
+.bmAttributes  = USB_CONFIG_ATT_ONE | 
USB_CONFIG_ATT_WAKEUP,
 .bMaxPower = 50,
 .nif = 1,
 .ifs = desc_iface_tablet,
@@ -236,7 +236,7 @@ static const USBDescDevice desc_device_tablet2 = {
 .bNumInterfaces= 1,
 .bConfigurationValue   = 1,
 .iConfiguration= STR_CONFIG_TABLET,
-.bmAttributes  = 0xa0,
+.bmAttributes  = USB_CONFIG_ATT_ONE | 
USB_CONFIG_ATT_WAKEUP,
 .bMaxPower = 50,
 .nif = 1,
 .ifs = desc_iface_tablet2,
@@ -253,7 +253,7 @@ static const USBDescDevice desc_device_keyboard = {
 .bNumInterfaces= 1,
 .bConfigurationValue   = 1,
 .iConfiguration= STR_CONFIG_KEYBOARD,
-.bmAttributes  = 0xa0,
+.bmAttributes  = USB_CONFIG_ATT_ONE | 
USB_CONFIG_ATT_WAKEUP,
 .bMaxPower = 50,
 .nif = 1,
 .ifs = desc_iface_keyboard,
diff --git a/hw/usb/dev-hub.c b/hw/usb/dev-hub.c
index 58647b4..ec61dfa 100644
--- a/hw/usb/dev-hub.c
+++ b/hw/usb/dev-hub.c
@@ -119,7 +119,7 @@ static const USBDescDevice desc_device_hub = {
 {
 .bNumInterfaces= 1,
 .bConfigurationValue   = 1,
-.bmAttributes  = 0xe0,
+.bmAttributes  = USB_CONFIG_ATT_ONE | 
USB_CONFIG_ATT_SELFPOWER | USB_CONFIG_ATT_WAKEUP,
 .nif = 1,
 .ifs = desc_iface_hub,
 },
diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c
index 4c532b7..dfde838 100644
--- a/hw/usb/dev-network.c
+++ b/hw/usb/dev-network.c
@@ -266,7 +266,7 @@ static const USBDescDevice desc_device_net = {
 

Re: [Qemu-devel] [PATCH v3 7/8] target-arm: A64: add support for 3 src data proc insns

2013-12-16 Thread Peter Maydell
On 16 December 2013 08:54, Claudio Fontana claudio.font...@huawei.com wrote:
 Hello Peter,

 On 13.12.2013 20:18, Peter Maydell wrote:
 From: Alexander Graf ag...@suse.de

 This patch adds emulation for the Data-processing (3 source)
 family of instructions, namely MADD, MSUB, SMADDL, SMSUBL, SMULH,
 UMADDL, UMSUBL, UMULH.

 Signed-off-by: Alexander Graf ag...@suse.de
 Signed-off-by: Alex Bennée alex.ben...@linaro.org
 Signed-off-by: Peter Maydell peter.mayd...@linaro.org
 ---
  target-arm/translate-a64.c | 91 
 +-
  1 file changed, 89 insertions(+), 2 deletions(-)

 diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c
 index a6f1945..b3e9449 100644
 --- a/target-arm/translate-a64.c
 +++ b/target-arm/translate-a64.c
 @@ -2125,10 +2125,97 @@ static void disas_add_sub_reg(DisasContext *s, 
 uint32_t insn)
  tcg_temp_free_i64(tcg_result);
  }

 -/* Data-processing (3 source) */
 +/* C3.5.9 Data-processing (3 source)
 +
 +   31 30  29 28   24 23 21  20  16  15  14  10 95 40
 +  +--+--+---+--+--++--+--+--+
 +  |sf| op54 | 1 1 0 1 1 | op31 |  Rm  | o0 |  Ra  |  Rn  |  Rd  |
 +  +--+--+---+--+--++--+--+--+
 +
 + */
  static void disas_data_proc_3src(DisasContext *s, uint32_t insn)
  {
 -unsupported_encoding(s, insn);
 +int rd = extract32(insn, 0, 5);
 +int rn = extract32(insn, 5, 5);
 +int ra = extract32(insn, 10, 5);
 +int rm = extract32(insn, 16, 5);
 +int op_id = (extract32(insn, 29, 3)  4) |
 +(extract32(insn, 21, 3)  1) |
 +extract32(insn, 15, 1);
 +bool is_32bit = !extract32(insn, 31, 1);

 we have used sf everywhere else..

Yes, might as well be consistent.

 +tcg_temp_free(low_bits);

 should this be tcg_temp_free_i64()?

Yes, since we're preferring to be explicit about i32 vs i64
temps. (We know we're always building a 64 bit binary for
translate-a64.c so in fact we can guarantee that tcg_temp_free
is always tcg_temp_free_i64; but consistency with the 32 bit
decoder is nice.)

Fixed these nits in my working tree.

thanks
-- PMM



[Qemu-devel] [PATCH 14/16] spice: move qemu_spice_display_*() from spice-graphics to spice-core

2013-12-16 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/spice-core.c| 16 
 ui/spice-display.c | 17 -
 2 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/ui/spice-core.c b/ui/spice-core.c
index 9fb9544..0c48156 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -47,6 +47,7 @@ static const char *auth = spice;
 static char *auth_passwd;
 static time_t auth_expires = TIME_MAX;
 static int spice_migration_completed;
+static int spice_display_is_running;
 int using_spice = 0;
 
 static QemuThread me;
@@ -904,6 +905,21 @@ int qemu_spice_display_add_client(int csock, int skipauth, 
int tls)
 }
 }
 
+void qemu_spice_display_start(void)
+{
+spice_display_is_running = true;
+}
+
+void qemu_spice_display_stop(void)
+{
+spice_display_is_running = false;
+}
+
+int qemu_spice_display_is_running(SimpleSpiceDisplay *ssd)
+{
+return spice_display_is_running;
+}
+
 static void spice_register_config(void)
 {
 qemu_add_opts(qemu_spice_opts);
diff --git a/ui/spice-display.c b/ui/spice-display.c
index f23a318..9bb42f1 100644
--- a/ui/spice-display.c
+++ b/ui/spice-display.c
@@ -126,23 +126,6 @@ void qemu_spice_wakeup(SimpleSpiceDisplay *ssd)
 spice_qxl_wakeup(ssd-qxl);
 }
 
-static int spice_display_is_running;
-
-void qemu_spice_display_start(void)
-{
-spice_display_is_running = true;
-}
-
-void qemu_spice_display_stop(void)
-{
-spice_display_is_running = false;
-}
-
-int qemu_spice_display_is_running(SimpleSpiceDisplay *ssd)
-{
-return spice_display_is_running;
-}
-
 static void qemu_spice_create_one_update(SimpleSpiceDisplay *ssd,
  QXLRect *rect)
 {
-- 
1.8.3.1




[Qemu-devel] [PATCH 04/16] qmp_change_blockdev() remove unused has_format

2013-12-16 Thread Gerd Hoffmann
From: Marc-André Lureau marcandre.lur...@redhat.com

Signed-off-by: Marc-André Lureau marcandre.lur...@gmail.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 blockdev.c| 2 +-
 include/sysemu/blockdev.h | 2 +-
 qmp.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index 44755e1..6a85961 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1523,7 +1523,7 @@ static void qmp_bdrv_open_encrypted(BlockDriverState *bs, 
const char *filename,
 }
 
 void qmp_change_blockdev(const char *device, const char *filename,
- bool has_format, const char *format, Error **errp)
+ const char *format, Error **errp)
 {
 BlockDriverState *bs;
 BlockDriver *drv = NULL;
diff --git a/include/sysemu/blockdev.h b/include/sysemu/blockdev.h
index 1082091..134712b 100644
--- a/include/sysemu/blockdev.h
+++ b/include/sysemu/blockdev.h
@@ -64,7 +64,7 @@ DriveInfo *drive_init(QemuOpts *arg, BlockInterfaceType 
block_default_type);
 DriveInfo *add_init_drive(const char *opts);
 
 void qmp_change_blockdev(const char *device, const char *filename,
- bool has_format, const char *format, Error **errp);
+ const char *format, Error **errp);
 void do_commit(Monitor *mon, const QDict *qdict);
 int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
 #endif
diff --git a/qmp.c b/qmp.c
index 4c149b3..1d7a04d 100644
--- a/qmp.c
+++ b/qmp.c
@@ -400,7 +400,7 @@ void qmp_change(const char *device, const char *target,
 if (strcmp(device, vnc) == 0) {
 qmp_change_vnc(target, has_arg, arg, err);
 } else {
-qmp_change_blockdev(device, target, has_arg, arg, err);
+qmp_change_blockdev(device, target, arg, err);
 }
 }
 
-- 
1.8.3.1




[Qemu-devel] [PATCH 11/16] nbd: make nbd_client_session_close() idempotent

2013-12-16 Thread Gerd Hoffmann
From: Marc-André Lureau marcandre.lur...@redhat.com

Signed-off-by: Marc-André Lureau marcandre.lur...@redhat.com
Acked-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 block/nbd-client.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/block/nbd-client.c b/block/nbd-client.c
index 3dfae1d..9156093 100644
--- a/block/nbd-client.c
+++ b/block/nbd-client.c
@@ -337,7 +337,12 @@ static void nbd_teardown_connection(NbdClientSession 
*client)
 
 void nbd_client_session_close(NbdClientSession *client)
 {
+if (!client-bs) {
+return;
+}
+
 nbd_teardown_connection(client);
+client-bs = NULL;
 }
 
 int nbd_client_session_init(NbdClientSession *client, BlockDriverState *bs,
-- 
1.8.3.1




[Qemu-devel] [Bug 1261268] Re: save guest running time is more than 450s with AVX running.

2013-12-16 Thread Paolo Bonzini
The bisection is probably incorrect.

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

Title:
  save guest running time is more than 450s with AVX running.

Status in QEMU:
  New

Bug description:
  Environment:
  
  Host OS (ia32/ia32e/IA64):ia32e
  Guest OS (ia32/ia32e/IA64):ia32e
  Guest OS Type (Linux/Windows):linux
  kvm.git Commit:d6d63b51fe3bfea0cf596993afa480b0b3b02c32
  qemu.git Commit:8f84271da83c0e9f92aa7c1c2d0d3875bf0a5cb8
  Host Kernel Version:3.13.0-rc1
  Hardware:Romley_EP, Ivytown_EP

  
  Bug detailed description:
  --
  when guest running avx , then do save /restore, save guest running time is 
too lomg

  
  Note:
  1.when save guest (migrate exec:dd of=test.img)sometimes , the file of 
test.img is 29G, running time of save guest is about 900s
  2. this should be a qemu bug:
  kvm  + qemu   =  result
  d6d63b51  + 8f84271d =  bad
  d6d63b51  + b5d54bd4 =  good


  
  Reproduce steps:
  
  1.qemu-system-x86_64 -enable-kvm -m 1024 -smp 6 -net 
nic,macaddr=00:12:34:43:14:78 -net tap,script=/etc/kvm/qemu-ifup rhel6u4.qcow
  2. scp  /usr/tet/XVS/tsets/control_panel/tools/bin/avx.tar.gz $guest_IP:/root
  3. tar -zxf avx.tar.gz
  4. cd /avx
  5. sh chk_avx.sh /dev/null 
  6. ctrl-alt-2
  7. migrate exec:dd of=test.img

  Current result:
  
  running time of save guest is more than 450s

  Expected result:
  
  running time of save guest is less than 450s

  Basic root-causing log:
  --

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1261268/+subscriptions



[Qemu-devel] [PATCH 15/16] spice: move spice_server_vm_{start, stop} calls into qemu_spice_display_*()

2013-12-16 Thread Gerd Hoffmann
So calling spice server to start/stop the worker goes
hand in hand with the status variable update.

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

diff --git a/ui/spice-core.c b/ui/spice-core.c
index 0c48156..4cce3b3 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -623,9 +623,7 @@ static void vm_change_state_handler(void *opaque, int 
running,
 {
 if (running) {
 qemu_spice_display_start();
-spice_server_vm_start(spice_server);
 } else {
-spice_server_vm_stop(spice_server);
 qemu_spice_display_stop();
 }
 }
@@ -908,10 +906,12 @@ int qemu_spice_display_add_client(int csock, int 
skipauth, int tls)
 void qemu_spice_display_start(void)
 {
 spice_display_is_running = true;
+spice_server_vm_start(spice_server);
 }
 
 void qemu_spice_display_stop(void)
 {
+spice_server_vm_stop(spice_server);
 spice_display_is_running = false;
 }
 
-- 
1.8.3.1




[Qemu-devel] [Bug 1261265] Re: win7 guest boot up fail.

2013-12-16 Thread Paolo Bonzini
Already reported
http://permalink.gmane.org/gmane.comp.emulators.qemu/245664

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

Title:
  win7 guest boot up fail.

Status in QEMU:
  New

Bug description:
  Environment:
  
  Host OS (ia32/ia32e/IA64):ia32e
  Guest OS (ia32/ia32e/IA64):ia32e
  Guest OS Type (Linux/Windows):windows
  kvm.git Commit:d6d63b51fe3bfea0cf596993afa480b0b3b02c32
  qemu.git Commit:a1d22a367d5780c9553b2cd5a24f665534ce6ed6
  Host Kernel Version:3.13.0-rc1
  Hardware:Romley_EP, Ivytown_EP

  
  Bug detailed description:
  --
  when create a win7 guest, the guest boot up fail.

  note: 
  1. when create win2k3, win2k8 guest, the guest boot up fail.
  2. when create win8, win2012 guest, the guest boot up fine.
  3. this should be a qemu bug
  kvm  + qemu =  result
  d6d63b51 + a1d22a36 =  bad
  d6d63b51 + 7dc65c02 =  good


  
  Reproduce steps:
  
  1. create guest
  qemu-system-x86_64 -enable-kvm -m 1024 -smp 2 -net none /root/win7.img

  Current result:
  
  win7 guest boot up fail

  Expected result:
  
  win7 guest boot up fine

  Basic root-causing log:
  --

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1261265/+subscriptions



Re: [Qemu-devel] [PATCH 1/2] hw: cannot_instantiate_with_device_add_yet due to pointer props

2013-12-16 Thread Peter Maydell
On 16 December 2013 08:48, Markus Armbruster arm...@redhat.com wrote:
 Peter Maydell peter.mayd...@linaro.org writes:
 I kind of think this whole thing is backwards anyway:
 we should really say the user can only instantiate
 devices via command line or monitor that are specifically
 intended to be hot-pluggable, rather than having an
 enormous list of devices we flag as not instantiable
 by the user. Even if someday we manage to make it technically
 possible to instantiate an omap_i2c device (say) from the
 command line, it will still be a completely bizarre thing to do
 because it's only intended to work as a part of the omap SoC.

 Hot-pluggable doesn't apply here.  There are plenty of devices that
 can only be cold-plugged, yet are absolutely meant to be user-pluggable.
 Real ISA cards, for instance.

Mmm. Just plain pluggable would be more what I meant:
modelling something that on real hardware is really a
simple pluggable socket.

 However, the current code lets users plug absolutely everything, even
 stuff that is known not to work.  The code still has the remnants of a
 mechanism meant to protect users from known-not-to-work plugs, but it
 got broken some time ago.  My Clean up and fix no_user series fixes
 that regression in a way that's hopefully agreeable with Anthony, who
 has been quite insistent on letting device_add plug more rather than
 less.  This series merely patches some holes on top.

 The list of non-pluggable devices may be larger than the list of
 pluggable ones, but: I count just 48 instances of
 cannot_instantiate_with_device_add_yet = true.  I doubt marking
 devices that can be plugged instead of the ones than can't be would take
 fewer marks.  Moreover, each one comes with a comment explaining *why*
 the device cannot be plugged.  Sure nice to have when such a why goes
 away.  Some of them are expected to go away eventually.

I would expect 99% of actually pluggable devices to be pluggable
because they're using a pluggable bus: ISA, PCI, USB, ...

Anyway, I don't actively object to this series. I just think
Anthony's going in the wrong direction which is why I haven't
been particularly eager to actively mark it as reviewed-by me
either...

thanks
-- PMM



[Qemu-devel] [PATCH 16/16] spice: stop server for qxl hard reset

2013-12-16 Thread Gerd Hoffmann
Hard reset can happen at any time.  We should be able to put qxl into a
known-good state no matter what.  Stop spice server thread for reset so
it can't be confused by fetching stale commands lingering around in the
rings while we reset is ongoing.

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

diff --git a/hw/display/qxl.c b/hw/display/qxl.c
index efdefd6..e4f172e 100644
--- a/hw/display/qxl.c
+++ b/hw/display/qxl.c
@@ -1144,8 +1144,14 @@ static void qxl_soft_reset(PCIQXLDevice *d)
 
 static void qxl_hard_reset(PCIQXLDevice *d, int loadvm)
 {
+bool startstop = qemu_spice_display_is_running(d-ssd);
+
 trace_qxl_hard_reset(d-id, loadvm);
 
+if (startstop) {
+qemu_spice_display_stop();
+}
+
 qxl_spice_reset_cursor(d);
 qxl_spice_reset_image_cache(d);
 qxl_reset_surfaces(d);
@@ -1159,6 +1165,10 @@ static void qxl_hard_reset(PCIQXLDevice *d, int loadvm)
 }
 qemu_spice_create_host_memslot(d-ssd);
 qxl_soft_reset(d);
+
+if (startstop) {
+qemu_spice_display_start();
+}
 }
 
 static void qxl_reset_handler(DeviceState *dev)
-- 
1.8.3.1




[Qemu-devel] [PATCH 10/16] nbd: pass export name as init argument

2013-12-16 Thread Gerd Hoffmann
From: Marc-André Lureau marcandre.lur...@redhat.com

There is no need to keep the export name around, and it seems a better
fit as an argument in the init() call.

Signed-off-by: Marc-André Lureau marcandre.lur...@redhat.com
Acked-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 block/nbd-client.c |  9 -
 block/nbd-client.h |  5 ++---
 block/nbd.c| 13 -
 3 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/block/nbd-client.c b/block/nbd-client.c
index 693110d..3dfae1d 100644
--- a/block/nbd-client.c
+++ b/block/nbd-client.c
@@ -338,18 +338,17 @@ static void nbd_teardown_connection(NbdClientSession 
*client)
 void nbd_client_session_close(NbdClientSession *client)
 {
 nbd_teardown_connection(client);
-g_free(client-export_name);
-client-export_name = NULL;
 }
 
-int nbd_client_session_init(NbdClientSession *client,
-BlockDriverState *bs, int sock)
+int nbd_client_session_init(NbdClientSession *client, BlockDriverState *bs,
+int sock, const char *export)
 {
 int ret;
 
 /* NBD handshake */
+logout(session init %s\n, export);
 qemu_set_block(sock);
-ret = nbd_receive_negotiate(sock, client-export_name,
+ret = nbd_receive_negotiate(sock, export,
 client-nbdflags, client-size,
 client-blocksize);
 if (ret  0) {
diff --git a/block/nbd-client.h b/block/nbd-client.h
index c271236..f2a6337 100644
--- a/block/nbd-client.h
+++ b/block/nbd-client.h
@@ -30,14 +30,13 @@ typedef struct NbdClientSession {
 Coroutine *recv_coroutine[MAX_NBD_REQUESTS];
 struct nbd_reply reply;
 
-char *export_name; /* An NBD server may export several devices */
 bool is_unix;
 
 BlockDriverState *bs;
 } NbdClientSession;
 
-int nbd_client_session_init(NbdClientSession *client,
-BlockDriverState *bs, int sock);
+int nbd_client_session_init(NbdClientSession *client, BlockDriverState *bs,
+int sock, const char *export_name);
 void nbd_client_session_close(NbdClientSession *client);
 
 int nbd_client_session_co_discard(NbdClientSession *client, int64_t sector_num,
diff --git a/block/nbd.c b/block/nbd.c
index be75ba0..4455a13 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -188,7 +188,7 @@ out:
 g_free(file);
 }
 
-static int nbd_config(BDRVNBDState *s, QDict *options)
+static int nbd_config(BDRVNBDState *s, QDict *options, char **export)
 {
 Error *local_err = NULL;
 
@@ -218,8 +218,8 @@ static int nbd_config(BDRVNBDState *s, QDict *options)
 qemu_opt_set_number(s-socket_opts, port, NBD_DEFAULT_PORT);
 }
 
-s-client.export_name = g_strdup(qdict_get_try_str(options, export));
-if (s-client.export_name) {
+*export = g_strdup(qdict_get_try_str(options, export));
+if (*export) {
 qdict_del(options, export);
 }
 
@@ -253,10 +253,11 @@ static int nbd_open(BlockDriverState *bs, QDict *options, 
int flags,
 Error **errp)
 {
 BDRVNBDState *s = bs-opaque;
+char *export = NULL;
 int result, sock;
 
 /* Pop the config into our state object. Exit if invalid. */
-result = nbd_config(s, options);
+result = nbd_config(s, options, export);
 if (result != 0) {
 return result;
 }
@@ -270,7 +271,9 @@ static int nbd_open(BlockDriverState *bs, QDict *options, 
int flags,
 }
 
 /* NBD handshake */
-return nbd_client_session_init(s-client, bs, sock);
+result = nbd_client_session_init(s-client, bs, sock, export);
+g_free(export);
+return result;
 }
 
 static int nbd_co_readv(BlockDriverState *bs, int64_t sector_num,
-- 
1.8.3.1




[Qemu-devel] [PATCH 09/16] nbd: don't change socket block during negotiate

2013-12-16 Thread Gerd Hoffmann
From: Marc-André Lureau marcandre.lur...@redhat.com

The caller might handle non-blocking using coroutine. Leave the choice
to the caller to use a blocking or non-blocking negotiate.

Signed-off-by: Marc-André Lureau marcandre.lur...@redhat.com
Acked-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 block/nbd-client.c | 1 +
 nbd.c  | 2 --
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/block/nbd-client.c b/block/nbd-client.c
index 1abfc6a..693110d 100644
--- a/block/nbd-client.c
+++ b/block/nbd-client.c
@@ -348,6 +348,7 @@ int nbd_client_session_init(NbdClientSession *client,
 int ret;
 
 /* NBD handshake */
+qemu_set_block(sock);
 ret = nbd_receive_negotiate(sock, client-export_name,
 client-nbdflags, client-size,
 client-blocksize);
diff --git a/nbd.c b/nbd.c
index f847940..030f56b 100644
--- a/nbd.c
+++ b/nbd.c
@@ -443,7 +443,6 @@ int nbd_receive_negotiate(int csock, const char *name, 
uint32_t *flags,
 
 TRACE(Receiving negotiation.);
 
-qemu_set_block(csock);
 rc = -EINVAL;
 
 if (read_sync(csock, buf, 8) != 8) {
@@ -558,7 +557,6 @@ int nbd_receive_negotiate(int csock, const char *name, 
uint32_t *flags,
 rc = 0;
 
 fail:
-qemu_set_nonblock(csock);
 return rc;
 }
 
-- 
1.8.3.1




[Qemu-devel] [PATCH 12/16] nbd: finish any pending coroutine

2013-12-16 Thread Gerd Hoffmann
From: Marc-André Lureau marcandre.lur...@gmail.com

Make sure all pending coroutines are finished when closing the session.

Signed-off-by: Marc-André Lureau marcandre.lur...@gmail.com
Acked-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 block/nbd-client.c | 21 -
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/block/nbd-client.c b/block/nbd-client.c
index 9156093..1973cf0 100644
--- a/block/nbd-client.c
+++ b/block/nbd-client.c
@@ -32,6 +32,17 @@
 #define HANDLE_TO_INDEX(bs, handle) ((handle) ^ ((uint64_t)(intptr_t)bs))
 #define INDEX_TO_HANDLE(bs, index)  ((index)  ^ ((uint64_t)(intptr_t)bs))
 
+static void nbd_recv_coroutines_enter_all(NbdClientSession *s)
+{
+int i;
+
+for (i = 0; i  MAX_NBD_REQUESTS; i++) {
+if (s-recv_coroutine[i]) {
+qemu_coroutine_enter(s-recv_coroutine[i], NULL);
+}
+}
+}
+
 static void nbd_reply_ready(void *opaque)
 {
 NbdClientSession *s = opaque;
@@ -67,11 +78,7 @@ static void nbd_reply_ready(void *opaque)
 }
 
 fail:
-for (i = 0; i  MAX_NBD_REQUESTS; i++) {
-if (s-recv_coroutine[i]) {
-qemu_coroutine_enter(s-recv_coroutine[i], NULL);
-}
-}
+nbd_recv_coroutines_enter_all(s);
 }
 
 static void nbd_restart_write(void *opaque)
@@ -330,6 +337,10 @@ static void nbd_teardown_connection(NbdClientSession 
*client)
 request.len = 0;
 nbd_send_request(client-sock, request);
 
+/* finish any pending coroutines */
+shutdown(client-sock, 2);
+nbd_recv_coroutines_enter_all(client);
+
 qemu_aio_set_fd_handler(client-sock, NULL, NULL, NULL);
 closesocket(client-sock);
 client-sock = -1;
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH v3 5/8] target-arm: A64: add support for add, addi, sub, subi

2013-12-16 Thread C Fontana
Sorry for noticing only now,
but there is a missing return here as well I think:

On 13 December 2013 20:17, Peter Maydell peter.mayd...@linaro.org wrote:
 From: Alex Bennée alex.ben...@linaro.org

 Implement the non-carry forms of addition and subtraction
 (immediate, extended register and shifted register).
 This includes the code to calculate NZCV if the instruction
 calls for setting the flags.

 Signed-off-by: Alex Bennée alex.ben...@linaro.org
 Signed-off-by: Peter Maydell peter.mayd...@linaro.org
 Reviewed-by: Richard Henderson r...@twiddle.net
 ---
  target-arm/translate-a64.c | 291 
 -
  1 file changed, 285 insertions(+), 6 deletions(-)

 diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c
 index 1b34a98..00dd369 100644
 --- a/target-arm/translate-a64.c
 +++ b/target-arm/translate-a64.c
 @@ -297,6 +297,102 @@ static inline void gen_logic_CC(int sf, TCGv_i64 result)
  tcg_gen_movi_i32(cpu_VF, 0);
  }

 +/* dest = T0 + T1; compute C, N, V and Z flags */
 +static void gen_add_CC(int sf, TCGv_i64 dest, TCGv_i64 t0, TCGv_i64 t1)
 +{
 +if (sf) {
 +TCGv_i64 result, flag, tmp;
 +result = tcg_temp_new_i64();
 +flag = tcg_temp_new_i64();
 +tmp = tcg_temp_new_i64();
 +
 +tcg_gen_movi_i64(tmp, 0);
 +tcg_gen_add2_i64(result, flag, t0, tmp, t1, tmp);
 +
 +tcg_gen_trunc_i64_i32(cpu_CF, flag);
 +
 +gen_set_NZ64(result);
 +
 +tcg_gen_xor_i64(flag, result, t0);
 +tcg_gen_xor_i64(tmp, t0, t1);
 +tcg_gen_andc_i64(flag, flag, tmp);
 +tcg_temp_free_i64(tmp);
 +tcg_gen_shri_i64(flag, flag, 32);
 +tcg_gen_trunc_i64_i32(cpu_VF, flag);
 +
 +tcg_gen_mov_i64(dest, result);
 +tcg_temp_free_i64(result);
 +tcg_temp_free_i64(flag);
 +} else {
 +/* 32 bit arithmetic */
 +TCGv_i32 t0_32 = tcg_temp_new_i32();
 +TCGv_i32 t1_32 = tcg_temp_new_i32();
 +TCGv_i32 tmp = tcg_temp_new_i32();
 +
 +tcg_gen_movi_i32(tmp, 0);
 +tcg_gen_trunc_i64_i32(t0_32, t0);
 +tcg_gen_trunc_i64_i32(t1_32, t1);
 +tcg_gen_add2_i32(cpu_NF, cpu_CF, t0_32, tmp, t1_32, tmp);
 +tcg_gen_mov_i32(cpu_ZF, cpu_NF);
 +tcg_gen_xor_i32(cpu_VF, cpu_NF, t0_32);
 +tcg_gen_xor_i32(tmp, t0_32, t1_32);
 +tcg_gen_andc_i32(cpu_VF, cpu_VF, tmp);
 +tcg_gen_extu_i32_i64(dest, cpu_NF);
 +
 +tcg_temp_free_i32(tmp);
 +tcg_temp_free_i32(t0_32);
 +tcg_temp_free_i32(t1_32);
 +}
 +}
 +
 +/* dest = T0 - T1; compute C, N, V and Z flags */
 +static void gen_sub_CC(int sf, TCGv_i64 dest, TCGv_i64 t0, TCGv_i64 t1)
 +{
 +if (sf) {
 +/* 64 bit arithmetic */
 +TCGv_i64 result, flag, tmp;
 +
 +result = tcg_temp_new_i64();
 +flag = tcg_temp_new_i64();
 +tcg_gen_sub_i64(result, t0, t1);
 +
 +gen_set_NZ64(result);
 +
 +tcg_gen_setcond_i64(TCG_COND_GEU, flag, t0, t1);
 +tcg_gen_trunc_i64_i32(cpu_CF, flag);
 +
 +tcg_gen_xor_i64(flag, result, t0);
 +tmp = tcg_temp_new_i64();
 +tcg_gen_xor_i64(tmp, t0, t1);
 +tcg_gen_and_i64(flag, flag, tmp);
 +tcg_temp_free_i64(tmp);
 +tcg_gen_shri_i64(flag, flag, 32);
 +tcg_gen_trunc_i64_i32(cpu_VF, flag);
 +tcg_gen_mov_i64(dest, result);
 +tcg_temp_free_i64(flag);
 +tcg_temp_free_i64(result);
 +} else {
 +/* 32 bit arithmetic */
 +TCGv_i32 t0_32 = tcg_temp_new_i32();
 +TCGv_i32 t1_32 = tcg_temp_new_i32();
 +TCGv_i32 tmp;
 +
 +tcg_gen_trunc_i64_i32(t0_32, t0);
 +tcg_gen_trunc_i64_i32(t1_32, t1);
 +tcg_gen_sub_i32(cpu_NF, t0_32, t1_32);
 +tcg_gen_mov_i32(cpu_ZF, cpu_NF);
 +tcg_gen_setcond_i32(TCG_COND_GEU, cpu_CF, t0_32, t1_32);
 +tcg_gen_xor_i32(cpu_VF, cpu_NF, t0_32);
 +tmp = tcg_temp_new_i32();
 +tcg_gen_xor_i32(tmp, t0_32, t1_32);
 +tcg_temp_free_i32(t0_32);
 +tcg_temp_free_i32(t1_32);
 +tcg_gen_and_i32(cpu_VF, cpu_VF, tmp);
 +tcg_temp_free_i32(tmp);
 +tcg_gen_extu_i32_i64(dest, cpu_NF);
 +}
 +}
 +
  /*
   * Load/Store generators
   */
 @@ -1326,10 +1422,67 @@ static void disas_pc_rel_adr(DisasContext *s, 
 uint32_t insn)
  tcg_gen_movi_i64(cpu_reg(s, rd), base + offset);
  }

 -/* Add/subtract (immediate) */
 +/*
 + * C3.4.1 Add/subtract (immediate)
 + *
 + *  31 30 29 28   24 23 22 21 10 9   5 4   0
 + * +--+--+--+---+-+-+-+-+
 + * |sf|op| S| 1 0 0 0 1 |shift|imm12|  Rn | Rd  |
 + * +--+--+--+---+-+-+-+-+
 + *
 + *sf: 0 - 32bit, 1 - 64bit
 + *op: 0 - add  , 1 - sub
 + * S: 1 - set flags
 + * shift: 00 - LSL imm by 0, 01 - LSL imm by 12
 + */
  static void disas_add_sub_imm(DisasContext *s, uint32_t insn)
  {
 -unsupported_encoding(s, insn);
 

[Qemu-devel] Question about module load

2013-12-16 Thread Choonho Son
Hello All,

I cannot understand QEMU iniitialization.
Before starting main function(main@vl.c), how modules are loaded?

Since module are already loaded in module_call_init(MODULE_INIT_QOM);


Best regards,
Choonho Son


[Qemu-devel] [Bug 1261320] [NEW] Virtual Disk with over 16TB

2013-12-16 Thread Chris Weltzien
Public bug reported:

Hi,

is there a option to create a disk for a vm with a size over 16TB.

the problem that after the diskfile reach 16TB, the disk get a state of 
read-only at this limit.
I know, that 16TB file size is max, is there a option to create the disk in 
mutliple files?
we want to use 22 TB. in the VM 

To attach a partition directly to the vm, is not what we want to do.

best regards

Chris

** Affects: qemu
 Importance: Undecided
 Status: New


** Tags: img qemu

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

Title:
  Virtual Disk with over 16TB

Status in QEMU:
  New

Bug description:
  Hi,

  is there a option to create a disk for a vm with a size over 16TB.

  the problem that after the diskfile reach 16TB, the disk get a state of 
read-only at this limit.
  I know, that 16TB file size is max, is there a option to create the disk in 
mutliple files?
  we want to use 22 TB. in the VM 

  To attach a partition directly to the vm, is not what we want to do.

  best regards

  Chris

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1261320/+subscriptions



[Qemu-devel] [PATCH 07/16] spice-char: implement chardev port event

2013-12-16 Thread Gerd Hoffmann
From: Marc-André Lureau marcandre.lur...@gmail.com

Wire up chardev fe_event to Spice port.

Signed-off-by: Marc-André Lureau marcandre.lur...@gmail.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 spice-qemu-char.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/spice-qemu-char.c b/spice-qemu-char.c
index e074d9e..16439c5 100644
--- a/spice-qemu-char.c
+++ b/spice-qemu-char.c
@@ -222,6 +222,15 @@ static void spice_chr_set_fe_open(struct CharDriverState 
*chr, int fe_open)
 }
 }
 
+static void spice_chr_fe_event(struct CharDriverState *chr, int event)
+{
+#if SPICE_SERVER_VERSION = 0x000c02
+SpiceCharDriver *s = chr-opaque;
+
+spice_server_port_event(s-sin, event);
+#endif
+}
+
 static void print_allowed_subtypes(void)
 {
 const char** psubtype;
@@ -255,6 +264,7 @@ static CharDriverState *chr_open(const char *subtype)
 chr-chr_close = spice_chr_close;
 chr-chr_set_fe_open = spice_chr_set_fe_open;
 chr-explicit_be_open = true;
+chr-chr_fe_event = spice_chr_fe_event;
 
 QLIST_INSERT_HEAD(spice_chars, s, next);
 
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH v3 1/7] Add -mem-share option

2013-12-16 Thread Paolo Bonzini
Il 16/12/2013 08:32, Edgar E. Iglesias ha scritto:
 On Fri, Dec 13, 2013 at 12:14:31PM +0100, Antonios Motakis wrote:
 This option complements -mem-path. It implies -mem-prealloc. If specified,
 the guest RAM is allocated as a shared memory object. If both -mem-path
 and -mem-share are provided, the memory is allocated from the HugeTLBFS
 supplied path, and then mmapped with MAP_SHARED.
 
 Hi,
 
 Interesting, I've got a similar use-case here where I've added a -mem-shared
 option. I've got a few comments/questions.
 
 Why do you imply -mem-prealloc? cant the user keep controlling that through
 -mem-prealloc?
 
 I'd prefer if -mem-share did not use shm_open but took a directory path as arg
 and created the backing files there. I'd also prefer if the files had
 deterministic names and where not unlinked after creation. I.e, let the user
 delete them when no longer needed.
 
 The reason for this is that it makes it easier to use apps that are not
 aware of shm or QEMU specifics to manipulate the memory backing. I understand
 that there might be issues (e.g filling up the disk, slow access over NFS etc)
 but these are at the choice of the user.
 
 Any thoughts around this?

I agree entirely with you.

Paolo




Re: [Qemu-devel] [PATCH] block/iscsi: use a bh to schedule co reentrance

2013-12-16 Thread Paolo Bonzini
Il 14/12/2013 17:31, Peter Lieven ha scritto:
 this fixes a potential segfault and performance regression.
 
 If the coroutine is reentered directly in the iscsi_co_generic_cb
 iscsi_process_{read,write} are interrupted and reentered any
 time later. One the one hand this could happen after an iscsi_close
 where the iscsi context is already gone (segfault). On the
 other hand this limits the number of processed callbacks
 in each aio_dispatch to one (potential performance regression).
 
 Cc: qemu-sta...@nongnu.org
 Signed-off-by: Peter Lieven p...@kamp.de
 ---
  block/iscsi.c |   11 ++-
  1 file changed, 10 insertions(+), 1 deletion(-)
 
 diff --git a/block/iscsi.c b/block/iscsi.c
 index fa69408..b0e6eea 100644
 --- a/block/iscsi.c
 +++ b/block/iscsi.c
 @@ -68,6 +68,7 @@ typedef struct IscsiTask {
  int do_retry;
  struct scsi_task *task;
  Coroutine *co;
 +QEMUBH *bh;
  } IscsiTask;
  
  typedef struct IscsiAIOCB {
 @@ -123,6 +124,13 @@ iscsi_schedule_bh(IscsiAIOCB *acb)
  qemu_bh_schedule(acb-bh);
  }
  
 +static void iscsi_co_generic_bh_cb(void *opaque)
 +{
 +struct IscsiTask *iTask = opaque;
 +qemu_bh_delete(iTask-bh);
 +qemu_coroutine_enter(iTask-co, NULL);
 +}
 +
  static void
  iscsi_co_generic_cb(struct iscsi_context *iscsi, int status,
  void *command_data, void *opaque)
 @@ -147,7 +155,8 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int 
 status,
  
  out:
  if (iTask-co) {
 -qemu_coroutine_enter(iTask-co, NULL);
 +iTask-bh = qemu_bh_new(iscsi_co_generic_bh_cb, iTask);
 +qemu_bh_schedule(iTask-bh);
  }
  }
  
 

Applied to scsi-next branch, thanks.

Paolo



Re: [Qemu-devel] [PATCH v3 5/8] target-arm: A64: add support for add, addi, sub, subi

2013-12-16 Thread Peter Maydell
On 16 December 2013 10:11, C Fontana claudio.font...@linaro.org wrote:
 Sorry for noticing only now,
 but there is a missing return here as well I think:

  static void disas_add_sub_imm(DisasContext *s, uint32_t insn)

 +default:
 +unallocated_encoding(s);

 should return; here I think.

Yes, fixed.

-- PMM



[Qemu-devel] [PATCH 10/42] input: keyboard: add helper functions to core

2013-12-16 Thread Gerd Hoffmann
A bunch of helper functions to manage keyboard events,
to make life simpler for the ui code when submitting
keyboard events.

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

diff --git a/include/ui/input.h b/include/ui/input.h
index 3cf3641..189f131 100644
--- a/include/ui/input.h
+++ b/include/ui/input.h
@@ -29,4 +29,9 @@ void qemu_input_handler_unregister(QemuInputHandlerState *s);
 void qemu_input_event_send(QemuConsole *src, InputEvent *evt);
 void qemu_input_event_sync(void);
 
+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);
+
 #endif /* INPUT_H */
diff --git a/ui/input.c b/ui/input.c
index 23c84f7..61c8089 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -81,3 +81,38 @@ void qemu_input_event_sync(void)
 s-events = 0;
 }
 }
+
+InputEvent *qemu_input_event_new_key(KeyValue *key, bool down)
+{
+InputEvent *evt = g_new0(InputEvent, 1);
+evt-key = g_new0(InputKeyEvent, 1);
+evt-kind = INPUT_EVENT_KIND_KEY;
+evt-key-key = key;
+evt-key-down = down;
+return evt;
+}
+
+void qemu_input_event_send_key(QemuConsole *src, KeyValue *key, bool down)
+{
+InputEvent *evt;
+evt = qemu_input_event_new_key(key, down);
+qemu_input_event_send(src, evt);
+qemu_input_event_sync();
+qapi_free_InputEvent(evt);
+}
+
+void qemu_input_event_send_key_number(QemuConsole *src, int num, bool down)
+{
+KeyValue *key = g_new0(KeyValue, 1);
+key-kind = KEY_VALUE_KIND_NUMBER;
+key-number = num;
+qemu_input_event_send_key(src, key, down);
+}
+
+void qemu_input_event_send_key_qcode(QemuConsole *src, QKeyCode q, bool down)
+{
+KeyValue *key = g_new0(KeyValue, 1);
+key-kind = KEY_VALUE_KIND_QCODE;
+key-qcode = q;
+qemu_input_event_send_key(src, key, down);
+}
-- 
1.8.3.1




[Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support

2013-12-16 Thread Gerd Hoffmann
  Hi,

This patch series features a reworked input layer and sdl2 support.

The input layer moves to a model modeled roughly after the linux
event layer.  It also uses qapi to create all the data types needed.
First, because it is convinient to have all the support code generated,
and also to make it easier to integrate with qmp some day.

Porting work has only be done on the UI side so far.  Input device
emulation is still to be done.

cocoa ui code has been updated, but is totally untested (not even
compiled).  Would be great if someone with macos hardware can give
it a spin, and send fixup patches if needed.

SDL2 consists of dave's original patch with a bunch of cleanups on
top.  Some of the cleanups depend on the new input layer code, thus
the incremental patches are sprinkled all over the patch series for
bisectability reasons.

please review  test,
  Gerd

Dave Airlie (1):
  ui/sdl2 : initial port to SDL 2.0 (v2.0)

Gerd Hoffmann (41):
  sdl2: baum build fix
  sdl2: remove text console logic
  console: export QemuConsole index,width,height
  input: rename file to legacy
  input: qapi: define event types
  input: qapi: add unmapped key
  input: qapi: add pause key
  input: add core bits of the new input layer
  input: keyboard: add helper functions to core
  input: keyboard: switch legacy handlers to new core
  input: keyboard: switch qmp_send_key() to new core.
  input: keyboard: switch gtk ui to new core
  input: keyboard: switch sdl ui to new core
  sdl2: switch keyboard handling to new core
  input: keyboard: switch vnc ui to new core
  input: keyboard: switch spice ui to new core
  input: keyboard: switch curses ui to new core
  input: mouse: add helpers functions to core
  input: mouse: add graphic_rotate support
  input: mouse: add qemu_input_is_absolute()
  input: mouse: switch legacy handlers to new core
  input: mouse: switch gtk ui to new core
  input: mouse: switch sdl ui to new core
  sdl2: switch mouse handling to new core
  input: mouse: switch vnc ui to new core
  input: mouse: switch spice ui to new core
  input: mouse: switch monitor to new core
  input: keyboard: switch cocoa ui to new core [untested]
  input: mouse: switch cocoa ui to new core [untested]
  input: trace events
  input-legacy: remove kbd_put_keycode
  input-legacy: remove kbd_mouse_has_absolute
  input-legacy: remove kbd_mouse_is_absolute
  input-legacy: remove kbd_mouse_event
  input: move mouse mode notifier to new core
  input: add input_mouse_mode tracepoint
  sdl2: simplify keymap handling
  sdl2: codestyle fixups
  input: move qmp_query_mice to new core
  input: move do_mouse_set to new core
  input: remove index_from_keycode (no users)

 backends/baum.c  |   4 +-
 configure|  23 +-
 include/ui/console.h |  16 +-
 include/ui/input.h   |  56 
 monitor.c|  31 +-
 qapi-schema.json |  81 -
 trace-events |   9 +
 ui/Makefile.objs |   6 +-
 ui/cocoa.m   |  81 +++--
 ui/console.c |  24 ++
 ui/curses.c  |  47 +--
 ui/gtk.c |  77 ++---
 ui/input-legacy.c| 453 
 ui/input.c   | 684 +++---
 ui/sdl.c | 114 ---
 ui/sdl2-keymap.h | 266 +
 ui/sdl2.c| 829 +++
 ui/sdl_keysym.h  |   3 +-
 ui/spice-input.c |  84 --
 ui/vnc.c |  71 ++---
 ui/vnc.h |   1 +
 21 files changed, 2249 insertions(+), 711 deletions(-)
 create mode 100644 include/ui/input.h
 create mode 100644 ui/input-legacy.c
 create mode 100644 ui/sdl2-keymap.h
 create mode 100644 ui/sdl2.c

-- 
1.8.3.1




[Qemu-devel] [PATCH 02/42] sdl2: baum build fix

2013-12-16 Thread Gerd Hoffmann
---
 backends/baum.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/backends/baum.c b/backends/baum.c
index 1132899..665107f 100644
--- a/backends/baum.c
+++ b/backends/baum.c
@@ -566,7 +566,7 @@ CharDriverState *chr_baum_init(void)
 BaumDriverState *baum;
 CharDriverState *chr;
 brlapi_handle_t *handle;
-#ifdef CONFIG_SDL
+#if defined(CONFIG_SDL)  SDL_COMPILEDVERSION  SDL_VERSIONNUM(2, 0, 0)
 SDL_SysWMinfo info;
 #endif
 int tty;
@@ -595,7 +595,7 @@ CharDriverState *chr_baum_init(void)
 goto fail;
 }
 
-#ifdef CONFIG_SDL
+#if defined(CONFIG_SDL)  SDL_COMPILEDVERSION  SDL_VERSIONNUM(2, 0, 0)
 memset(info, 0, sizeof(info));
 SDL_VERSION(info.version);
 if (SDL_GetWMInfo(info))
-- 
1.8.3.1




[Qemu-devel] [PATCH 04/42] console: export QemuConsole index, width, height

2013-12-16 Thread Gerd Hoffmann
Add functions to query QemuConsole properties.

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

diff --git a/include/ui/console.h b/include/ui/console.h
index 4156a87..8543d18 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -289,6 +289,9 @@ QemuConsole *qemu_console_lookup_by_device(DeviceState 
*dev);
 bool qemu_console_is_visible(QemuConsole *con);
 bool qemu_console_is_graphic(QemuConsole *con);
 bool qemu_console_is_fixedsize(QemuConsole *con);
+int qemu_console_get_index(QemuConsole *con);
+int qemu_console_get_width(QemuConsole *con, int fallback);
+int qemu_console_get_height(QemuConsole *con, int fallback);
 
 void text_consoles_set_display(DisplayState *ds);
 void console_select(unsigned int index);
diff --git a/ui/console.c b/ui/console.c
index 502e160..0bbefe5 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -1641,6 +1641,30 @@ bool qemu_console_is_fixedsize(QemuConsole *con)
 return con  (con-console_type != TEXT_CONSOLE);
 }
 
+int qemu_console_get_index(QemuConsole *con)
+{
+if (con == NULL) {
+con = active_console;
+}
+return con ? con-index : -1;
+}
+
+int qemu_console_get_width(QemuConsole *con, int fallback)
+{
+if (con == NULL) {
+con = active_console;
+}
+return con ? surface_width(con-surface) : fallback;
+}
+
+int qemu_console_get_height(QemuConsole *con, int fallback)
+{
+if (con == NULL) {
+con = active_console;
+}
+return con ? surface_height(con-surface) : fallback;
+}
+
 static void text_console_set_echo(CharDriverState *chr, bool echo)
 {
 QemuConsole *s = chr-opaque;
-- 
1.8.3.1




[Qemu-devel] [PATCH 13/42] input: keyboard: switch gtk ui to new core

2013-12-16 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/gtk.c | 19 ---
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 6316f5b..993a9b5 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -55,6 +55,7 @@
 
 #include trace.h
 #include ui/console.h
+#include ui/input.h
 #include sysemu/sysemu.h
 #include qmp-commands.h
 #include x_keymap.h
@@ -276,10 +277,7 @@ static void gtk_release_modifiers(GtkDisplayState *s)
 if (!s-modifier_pressed[i]) {
 continue;
 }
-if (keycode  SCANCODE_GREY) {
-kbd_put_keycode(SCANCODE_EMUL0);
-}
-kbd_put_keycode(keycode | SCANCODE_UP);
+qemu_input_event_send_key_number(s-dcl.con, keycode, false);
 s-modifier_pressed[i] = false;
 }
 }
@@ -733,17 +731,8 @@ static gboolean gd_key_event(GtkWidget *widget, 
GdkEventKey *key, void *opaque)
 }
 }
 
-if (qemu_keycode  SCANCODE_GREY) {
-kbd_put_keycode(SCANCODE_EMUL0);
-}
-
-if (key-type == GDK_KEY_PRESS) {
-kbd_put_keycode(qemu_keycode  SCANCODE_KEYCODEMASK);
-} else if (key-type == GDK_KEY_RELEASE) {
-kbd_put_keycode(qemu_keycode | SCANCODE_UP);
-} else {
-g_assert_not_reached();
-}
+qemu_input_event_send_key_number(s-dcl.con, qemu_keycode,
+ key-type == GDK_KEY_PRESS);
 
 return TRUE;
 }
-- 
1.8.3.1




[Qemu-devel] [PATCH 12/42] input: keyboard: switch qmp_send_key() to new core.

2013-12-16 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/input-legacy.c | 11 +++
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index 80f4f5c..a4006cc 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -260,10 +260,8 @@ static void free_keycodes(void)
 static void release_keys(void *opaque)
 {
 while (keycodes_size  0) {
-if (keycodes[--keycodes_size]  SCANCODE_GREY) {
-kbd_put_keycode(SCANCODE_EMUL0);
-}
-kbd_put_keycode(keycodes[keycodes_size] | SCANCODE_UP);
+qemu_input_event_send_key_number(NULL, keycodes[--keycodes_size],
+ false);
 }
 
 free_keycodes();
@@ -297,10 +295,7 @@ void qmp_send_key(KeyValueList *keys, bool has_hold_time, 
int64_t hold_time,
 return;
 }
 
-if (keycode  SCANCODE_GREY) {
-kbd_put_keycode(SCANCODE_EMUL0);
-}
-kbd_put_keycode(keycode  SCANCODE_KEYCODEMASK);
+qemu_input_event_send_key_number(NULL, keycode, true);
 
 keycodes = g_realloc(keycodes, sizeof(int) * (keycodes_size + 1));
 keycodes[keycodes_size++] = keycode;
-- 
1.8.3.1




[Qemu-devel] [PATCH 06/42] input: qapi: define event types

2013-12-16 Thread Gerd Hoffmann
Define input event types, using qapi.  So we get nicely autogenerated
types for our input events.  And when it comes to qmp support some day
things will be alot easier.

Types are modeled after the linux input layer.  There are separate
event types for each value.  There is a sync to indicate the end
of a event group.

Mouse events are splitted into motion events (one for each axis) and
button events, which are grouped by sync.

Keyboard events are using the existing KeyValue type.

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

diff --git a/qapi-schema.json b/qapi-schema.json
index d6f8615..0316cb4 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4235,3 +4235,79 @@
 # Since: 1.7
 ##
 { 'command': 'blockdev-add', 'data': { 'options': 'BlockdevOptions' } }
+
+##
+# @InputButton
+#
+# Button of a pointer input device (mouse, tablet).
+#
+# Since: 2.0
+##
+{ 'enum'  : 'InputButton',
+  'data'  : [ 'Left', 'Middle', 'Right', 'WheelUp', 'WheelDown' ] }
+
+##
+# @InputButton
+#
+# Position axis of a pointer input device (mouse, tablet).
+#
+# Since: 2.0
+##
+{ 'enum'  : 'InputAxis',
+  'data'  : [ 'X', 'Y' ] }
+
+##
+# @InputKeyEvent
+#
+# Keyboard input event.
+#
+# @key:Which key this event is for.
+# @down:   True for key-down and false for key-up events.
+#
+# Since: 2.0
+##
+{ 'type'  : 'InputKeyEvent',
+  'data'  : { 'key' : 'KeyValue',
+  'down': 'bool' } }
+
+##
+# @InputBtnEvent
+#
+# Pointer button input event.
+#
+# @button: Which button this event is for.
+# @down:   True for key-down and false for key-up events.
+#
+# Since: 2.0
+##
+{ 'type'  : 'InputBtnEvent',
+  'data'  : { 'button'  : 'InputButton',
+  'down': 'bool' } }
+
+##
+# @InputMoveEvent
+#
+# Pointer motion input event.
+#
+# @axis:   Which axis is referenced by @value.
+# @value:  Pointer position.  For absolute coordinates the
+#  valid range is 0 - 0x7
+#
+# Since: 2.0
+##
+{ 'type'  : 'InputMoveEvent',
+  'data'  : { 'axis': 'InputAxis',
+  'value'   : 'int' } }
+
+##
+# @InputEvent
+#
+# Input event union.
+#
+# Since: 2.0
+##
+{ 'union' : 'InputEvent',
+  'data'  : { 'key' : 'InputKeyEvent',
+  'btn' : 'InputBtnEvent',
+  'rel' : 'InputMoveEvent',
+  'abs' : 'InputMoveEvent' } }
-- 
1.8.3.1




[Qemu-devel] [PATCH 05/42] input: rename file to legacy

2013-12-16 Thread Gerd Hoffmann
Rename ui/input.c to ui/input-legacy.c.
We are going to replace it step by step.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/Makefile.objs   | 2 +-
 ui/{input.c = input-legacy.c} | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename ui/{input.c = input-legacy.c} (100%)

diff --git a/ui/Makefile.objs b/ui/Makefile.objs
index 721ad37..16db07a 100644
--- a/ui/Makefile.objs
+++ b/ui/Makefile.objs
@@ -7,7 +7,7 @@ vnc-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o
 vnc-obj-$(CONFIG_VNC_WS) += vnc-ws.o
 vnc-obj-y += vnc-jobs.o
 
-common-obj-y += keymaps.o console.o cursor.o input.o qemu-pixman.o
+common-obj-y += keymaps.o console.o cursor.o input-legacy.o qemu-pixman.o
 common-obj-$(CONFIG_SPICE) += spice-core.o spice-input.o spice-display.o
 common-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o sdl2.o
 common-obj-$(CONFIG_COCOA) += cocoa.o
diff --git a/ui/input.c b/ui/input-legacy.c
similarity index 100%
rename from ui/input.c
rename to ui/input-legacy.c
-- 
1.8.3.1




[Qemu-devel] [PATCH 18/42] input: keyboard: switch curses ui to new core

2013-12-16 Thread Gerd Hoffmann
---
 ui/curses.c | 47 +--
 1 file changed, 25 insertions(+), 22 deletions(-)

diff --git a/ui/curses.c b/ui/curses.c
index dbc3d5e..b044790 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -30,6 +30,7 @@
 
 #include qemu-common.h
 #include ui/console.h
+#include ui/input.h
 #include sysemu/sysemu.h
 
 #define FONT_HEIGHT 16
@@ -274,32 +275,34 @@ static void curses_refresh(DisplayChangeListener *dcl)
 if (qemu_console_is_graphic(NULL)) {
 /* since terminals don't know about key press and release
  * events, we need to emit both for each key received */
-if (keycode  SHIFT)
-kbd_put_keycode(SHIFT_CODE);
-if (keycode  CNTRL)
-kbd_put_keycode(CNTRL_CODE);
-if (keycode  ALT)
-kbd_put_keycode(ALT_CODE);
+if (keycode  SHIFT) {
+qemu_input_event_send_key_number(NULL, SHIFT_CODE, true);
+}
+if (keycode  CNTRL) {
+qemu_input_event_send_key_number(NULL, CNTRL_CODE, true);
+}
+if (keycode  ALT) {
+qemu_input_event_send_key_number(NULL, ALT_CODE, true);
+}
 if (keycode  ALTGR) {
-kbd_put_keycode(SCANCODE_EMUL0);
-kbd_put_keycode(ALT_CODE);
+qemu_input_event_send_key_number(NULL, GREY | ALT_CODE, true);
 }
-if (keycode  GREY)
-kbd_put_keycode(GREY_CODE);
-kbd_put_keycode(keycode  KEY_MASK);
-if (keycode  GREY)
-kbd_put_keycode(GREY_CODE);
-kbd_put_keycode((keycode  KEY_MASK) | KEY_RELEASE);
+
+qemu_input_event_send_key_number(NULL, keycode, true);
+qemu_input_event_send_key_number(NULL, keycode, false);
+
 if (keycode  ALTGR) {
-kbd_put_keycode(SCANCODE_EMUL0);
-kbd_put_keycode(ALT_CODE | KEY_RELEASE);
+qemu_input_event_send_key_number(NULL, GREY | ALT_CODE, false);
+}
+if (keycode  ALT) {
+qemu_input_event_send_key_number(NULL, ALT_CODE, false);
+}
+if (keycode  CNTRL) {
+qemu_input_event_send_key_number(NULL, CNTRL_CODE, false);
+}
+if (keycode  SHIFT) {
+qemu_input_event_send_key_number(NULL, SHIFT_CODE, false);
 }
-if (keycode  ALT)
-kbd_put_keycode(ALT_CODE | KEY_RELEASE);
-if (keycode  CNTRL)
-kbd_put_keycode(CNTRL_CODE | KEY_RELEASE);
-if (keycode  SHIFT)
-kbd_put_keycode(SHIFT_CODE | KEY_RELEASE);
 } else {
 keysym = curses2qemu[chr];
 if (keysym == -1)
-- 
1.8.3.1




[Qemu-devel] [PATCH 03/42] sdl2: remove text console logic

2013-12-16 Thread Gerd Hoffmann
sdl2 explicitly binds windows to graphics consoles.
No need to handle non-graphic consoles anywhere.
Also console switching is pointless.  Zap code.

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

diff --git a/ui/sdl2.c b/ui/sdl2.c
index 2eb3e9c..e7a30b3 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -345,7 +345,7 @@ static void sdl_show_cursor(void)
 if (!cursor_hide)
 return;
 
-if (!kbd_mouse_is_absolute() || !qemu_console_is_graphic(NULL)) {
+if (!kbd_mouse_is_absolute()) {
 SDL_ShowCursor(1);
 if (guest_cursor 
 (gui_grab || kbd_mouse_is_absolute() || absolute_enabled))
@@ -402,9 +402,7 @@ static void sdl_mouse_mode_change(Notifier *notify, void 
*data)
 if (kbd_mouse_is_absolute()) {
 if (!absolute_enabled) {
 absolute_enabled = 1;
-if (qemu_console_is_graphic(NULL)) {
-absolute_mouse_grab(sdl2_console[0]);
-}
+absolute_mouse_grab(sdl2_console[0]);
 }
 } else if (absolute_enabled) {
 if (!gui_fullscreen) {
@@ -495,7 +493,7 @@ static void toggle_full_screen(struct sdl2_console_state 
*scon)
 } else {
 do_sdl_resize(scon, width, height, 0);
 }
-if (!gui_saved_grab || !qemu_console_is_graphic(NULL)) {
+if (!gui_saved_grab) {
 sdl_grab_end(scon);
 }
 }
@@ -535,26 +533,6 @@ static void handle_keydown(SDL_Event *ev)
 }
 gui_keysym = 1;
 break;
-case 0x02 ... 0x0a: /* '1' to '9' keys */
-/* Reset the modifiers sent to the current console */
-reset_keys();
-console_select(keycode - 0x02);
-gui_keysym = 1;
-if (gui_fullscreen) {
-break;
-}
-if (!qemu_console_is_graphic(NULL)) {
-/* release grab if going to a text console */
-if (gui_grab) {
-sdl_grab_end(scon);
-} else if (absolute_enabled) {
-sdl_show_cursor();
-}
-} else if (absolute_enabled) {
-sdl_hide_cursor();
-absolute_mouse_grab(scon);
-}
-break;
 case 0x1b: /* '+' */
 case 0x35: /* '-' */
 if (!gui_fullscreen) {
@@ -575,79 +553,8 @@ static void handle_keydown(SDL_Event *ev)
 default:
 break;
 }
-} else if (!qemu_console_is_graphic(NULL)) {
-int keysym = ev-key.keysym.sym;
-
-if (ev-key.keysym.mod  (KMOD_LCTRL | KMOD_RCTRL)) {
-switch (ev-key.keysym.sym) {
-case SDLK_UP:
-keysym = QEMU_KEY_CTRL_UP;
-break;
-case SDLK_DOWN:
-keysym = QEMU_KEY_CTRL_DOWN;
-break;
-case SDLK_LEFT:
-keysym = QEMU_KEY_CTRL_LEFT;
-break;
-case SDLK_RIGHT:
-keysym = QEMU_KEY_CTRL_RIGHT;
-break;
-case SDLK_HOME:
-keysym = QEMU_KEY_CTRL_HOME;
-break;
-case SDLK_END:
-keysym = QEMU_KEY_CTRL_END;
-break;
-case SDLK_PAGEUP:
-keysym = QEMU_KEY_CTRL_PAGEUP;
-break;
-case SDLK_PAGEDOWN:
-keysym = QEMU_KEY_CTRL_PAGEDOWN;
-break;
-default:
-break;
-}
-} else {
-switch (ev-key.keysym.sym) {
-case SDLK_UP:
-keysym = QEMU_KEY_UP;
-break;
-case SDLK_DOWN:
-keysym = QEMU_KEY_DOWN;
-break;
-case SDLK_LEFT:
-keysym = QEMU_KEY_LEFT;
-break;
-case SDLK_RIGHT:
-keysym = QEMU_KEY_RIGHT;
-break;
-case SDLK_HOME:
-keysym = QEMU_KEY_HOME;
-break;
-case SDLK_END:
-keysym = QEMU_KEY_END;
-break;
-case SDLK_PAGEUP:
-keysym = QEMU_KEY_PAGEUP;
-break;
-case SDLK_PAGEDOWN:
-keysym = QEMU_KEY_PAGEDOWN;
-break;
-case SDLK_BACKSPACE:
-keysym = QEMU_KEY_BACKSPACE;
-break;
-case SDLK_DELETE:
-keysym = QEMU_KEY_DELETE;
-break;
-default:
-break;
-}
-}
-if (keysym) {
-kbd_put_keysym(keysym);
-}
 }
-if (qemu_console_is_graphic(NULL)  !gui_keysym) {
+if (!gui_keysym) {
 sdl_process_key(ev-key);
 }
 }
@@ -667,9 +574,7 @@ static void 

[Qemu-devel] [PATCH 14/42] input: keyboard: switch sdl ui to new core

2013-12-16 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/sdl.c | 27 +--
 1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/ui/sdl.c b/ui/sdl.c
index 736bb95..c3b8036 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -32,6 +32,7 @@
 
 #include qemu-common.h
 #include ui/console.h
+#include ui/input.h
 #include sysemu/sysemu.h
 #include x_keymap.h
 #include sdl_zoom.h
@@ -263,9 +264,7 @@ static void reset_keys(void)
 int i;
 for(i = 0; i  256; i++) {
 if (modifiers_state[i]) {
-if (i  SCANCODE_GREY)
-kbd_put_keycode(SCANCODE_EMUL0);
-kbd_put_keycode(i | SCANCODE_UP);
+qemu_input_event_send_key_number(dcl-con, i, false);
 modifiers_state[i] = 0;
 }
 }
@@ -273,16 +272,12 @@ static void reset_keys(void)
 
 static void sdl_process_key(SDL_KeyboardEvent *ev)
 {
-int keycode, v;
+int keycode;
 
 if (ev-keysym.sym == SDLK_PAUSE) {
 /* specific case */
-v = 0;
-if (ev-type == SDL_KEYUP)
-v |= SCANCODE_UP;
-kbd_put_keycode(0xe1);
-kbd_put_keycode(0x1d | v);
-kbd_put_keycode(0x45 | v);
+qemu_input_event_send_key_qcode(dcl-con, Q_KEY_CODE_PAUSE,
+ev-type == SDL_KEYDOWN);
 return;
 }
 
@@ -314,19 +309,15 @@ static void sdl_process_key(SDL_KeyboardEvent *ev)
 case 0x45: /* num lock */
 case 0x3a: /* caps lock */
 /* SDL does not send the key up event, so we generate it */
-kbd_put_keycode(keycode);
-kbd_put_keycode(keycode | SCANCODE_UP);
+qemu_input_event_send_key_number(dcl-con, keycode, true);
+qemu_input_event_send_key_number(dcl-con, keycode, false);
 return;
 #endif
 }
 
 /* now send the key code */
-if (keycode  SCANCODE_GREY)
-kbd_put_keycode(SCANCODE_EMUL0);
-if (ev-type == SDL_KEYUP)
-kbd_put_keycode(keycode | SCANCODE_UP);
-else
-kbd_put_keycode(keycode  SCANCODE_KEYCODEMASK);
+qemu_input_event_send_key_number(dcl-con, keycode,
+ ev-type == SDL_KEYDOWN);
 }
 
 static void sdl_update_caption(void)
-- 
1.8.3.1




[Qemu-devel] [PATCH 27/42] input: mouse: switch spice ui to new core

2013-12-16 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/spice-input.c | 62 ++--
 1 file changed, 38 insertions(+), 24 deletions(-)

diff --git a/ui/spice-input.c b/ui/spice-input.c
index c9df699..6dab23b 100644
--- a/ui/spice-input.c
+++ b/ui/spice-input.c
@@ -98,41 +98,52 @@ static void kbd_leds(void *opaque, int ledstate)
 typedef struct QemuSpicePointer {
 SpiceMouseInstance  mouse;
 SpiceTabletInstance tablet;
-int width, height, x, y;
+int width, height;
+uint32_t last_bmask;
 Notifier mouse_mode;
 bool absolute;
 } QemuSpicePointer;
 
-static int map_buttons(int spice_buttons)
+static void spice_update_buttons(QemuSpicePointer *pointer,
+ int wheel, uint32_t button_mask)
 {
-int qemu_buttons = 0;
-
-/*
- * Note: SPICE_MOUSE_BUTTON_* specifies the wire protocol but this
- * isn't what we get passed in via interface callbacks for the
- * middle and right button ...
- */
-if (spice_buttons  SPICE_MOUSE_BUTTON_MASK_LEFT) {
-qemu_buttons |= MOUSE_EVENT_LBUTTON;
+static uint32_t bmap[INPUT_BUTTON_MAX] = {
+[INPUT_BUTTON_LEFT]= 0x01,
+[INPUT_BUTTON_MIDDLE]  = 0x04,
+[INPUT_BUTTON_RIGHT]   = 0x02,
+[INPUT_BUTTON_WHEEL_UP]= 0x10,
+[INPUT_BUTTON_WHEEL_DOWN]  = 0x20,
+};
+
+if (wheel  0) {
+button_mask |= 0x10;
 }
-if (spice_buttons  0x04 /* SPICE_MOUSE_BUTTON_MASK_MIDDLE */) {
-qemu_buttons |= MOUSE_EVENT_MBUTTON;
+if (wheel  0) {
+button_mask |= 0x20;
 }
-if (spice_buttons  0x02 /* SPICE_MOUSE_BUTTON_MASK_RIGHT */) {
-qemu_buttons |= MOUSE_EVENT_RBUTTON;
+
+if (pointer-last_bmask == button_mask) {
+return;
 }
-return qemu_buttons;
+qemu_input_update_buttons(NULL, bmap, pointer-last_bmask, button_mask);
+pointer-last_bmask = button_mask;
 }
 
 static void mouse_motion(SpiceMouseInstance *sin, int dx, int dy, int dz,
  uint32_t buttons_state)
 {
-kbd_mouse_event(dx, dy, dz, map_buttons(buttons_state));
+QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, mouse);
+spice_update_buttons(pointer, dz, buttons_state);
+qemu_input_queue_rel(NULL, INPUT_AXIS_X, dx);
+qemu_input_queue_rel(NULL, INPUT_AXIS_Y, dy);
+qemu_input_event_sync();
 }
 
 static void mouse_buttons(SpiceMouseInstance *sin, uint32_t buttons_state)
 {
-kbd_mouse_event(0, 0, 0, map_buttons(buttons_state));
+QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, mouse);
+spice_update_buttons(pointer, 0, buttons_state);
+qemu_input_event_sync();
 }
 
 static const SpiceMouseInterface mouse_interface = {
@@ -163,9 +174,10 @@ static void tablet_position(SpiceTabletInstance* sin, int 
x, int y,
 {
 QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet);
 
-pointer-x = x * 0x7FFF / (pointer-width - 1);
-pointer-y = y * 0x7FFF / (pointer-height - 1);
-kbd_mouse_event(pointer-x, pointer-y, 0, map_buttons(buttons_state));
+spice_update_buttons(pointer, 0, buttons_state);
+qemu_input_queue_abs(NULL, INPUT_AXIS_X, x, pointer-width);
+qemu_input_queue_abs(NULL, INPUT_AXIS_Y, y, pointer-width);
+qemu_input_event_sync();
 }
 
 
@@ -174,7 +186,8 @@ static void tablet_wheel(SpiceTabletInstance* sin, int 
wheel,
 {
 QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet);
 
-kbd_mouse_event(pointer-x, pointer-y, wheel, map_buttons(buttons_state));
+spice_update_buttons(pointer, wheel, buttons_state);
+qemu_input_event_sync();
 }
 
 static void tablet_buttons(SpiceTabletInstance *sin,
@@ -182,7 +195,8 @@ static void tablet_buttons(SpiceTabletInstance *sin,
 {
 QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet);
 
-kbd_mouse_event(pointer-x, pointer-y, 0, map_buttons(buttons_state));
+spice_update_buttons(pointer, 0, buttons_state);
+qemu_input_event_sync();
 }
 
 static const SpiceTabletInterface tablet_interface = {
@@ -199,7 +213,7 @@ static const SpiceTabletInterface tablet_interface = {
 static void mouse_mode_notifier(Notifier *notifier, void *data)
 {
 QemuSpicePointer *pointer = container_of(notifier, QemuSpicePointer, 
mouse_mode);
-bool is_absolute  = kbd_mouse_is_absolute();
+bool is_absolute  = qemu_input_is_absolute();
 
 if (pointer-absolute == is_absolute) {
 return;
-- 
1.8.3.1




[Qemu-devel] [PATCH 25/42] sdl2: switch mouse handling to new core

2013-12-16 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/sdl2.c | 60 +++-
 1 file changed, 31 insertions(+), 29 deletions(-)

diff --git a/ui/sdl2.c b/ui/sdl2.c
index ac3ac19..e841424 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -329,7 +329,7 @@ static void sdl_hide_cursor(void)
 if (!cursor_hide)
 return;
 
-if (kbd_mouse_is_absolute()) {
+if (qemu_input_is_absolute()) {
 SDL_ShowCursor(1);
 SDL_SetCursor(sdl_cursor_hidden);
 } else {
@@ -342,10 +342,10 @@ static void sdl_show_cursor(void)
 if (!cursor_hide)
 return;
 
-if (!kbd_mouse_is_absolute()) {
+if (!qemu_input_is_absolute()) {
 SDL_ShowCursor(1);
 if (guest_cursor 
-(gui_grab || kbd_mouse_is_absolute() || absolute_enabled))
+(gui_grab || qemu_input_is_absolute() || absolute_enabled))
 SDL_SetCursor(guest_sprite);
 else
 SDL_SetCursor(sdl_cursor_normal);
@@ -364,7 +364,7 @@ static void sdl_grab_start(struct sdl2_console_state *scon)
 }
 if (guest_cursor) {
 SDL_SetCursor(guest_sprite);
-if (!kbd_mouse_is_absolute()  !absolute_enabled) {
+if (!qemu_input_is_absolute()  !absolute_enabled) {
 SDL_WarpMouseInWindow(scon-real_window, guest_x, guest_y);
 }
 } else
@@ -396,7 +396,7 @@ static void absolute_mouse_grab(struct sdl2_console_state 
*scon)
 
 static void sdl_mouse_mode_change(Notifier *notify, void *data)
 {
-if (kbd_mouse_is_absolute()) {
+if (qemu_input_is_absolute()) {
 if (!absolute_enabled) {
 absolute_enabled = 1;
 absolute_mouse_grab(sdl2_console[0]);
@@ -411,19 +411,23 @@ static void sdl_mouse_mode_change(Notifier *notify, void 
*data)
 
 static void sdl_send_mouse_event(struct sdl2_console_state *scon, int dx, int 
dy, int dz, int x, int y, int state)
 {
-int buttons = 0;
+static uint32_t bmap[INPUT_BUTTON_MAX] = {
+[INPUT_BUTTON_LEFT]   = SDL_BUTTON(SDL_BUTTON_LEFT),
+[INPUT_BUTTON_MIDDLE] = SDL_BUTTON(SDL_BUTTON_MIDDLE),
+[INPUT_BUTTON_RIGHT]  = SDL_BUTTON(SDL_BUTTON_RIGHT),
+#if 0
+[INPUT_BUTTON_WHEEL_UP]   = SDL_BUTTON(SDL_BUTTON_WHEELUP),
+[INPUT_BUTTON_WHEEL_DOWN] = SDL_BUTTON(SDL_BUTTON_WHEELDOWN),
+#endif
+};
+static uint32_t prev_state;
 
-if (state  SDL_BUTTON(SDL_BUTTON_LEFT)) {
-buttons |= MOUSE_EVENT_LBUTTON;
-}
-if (state  SDL_BUTTON(SDL_BUTTON_RIGHT)) {
-buttons |= MOUSE_EVENT_RBUTTON;
-}
-if (state  SDL_BUTTON(SDL_BUTTON_MIDDLE)) {
-buttons |= MOUSE_EVENT_MBUTTON;
+if (prev_state != state) {
+qemu_input_update_buttons(scon-dcl.con, bmap, prev_state, state);
+prev_state = state;
 }
 
-if (kbd_mouse_is_absolute()) {
+if (qemu_input_is_absolute()) {
 int scr_w, scr_h;
 int max_w = 0, max_h = 0;
 int off_x = 0, off_y = 0;
@@ -446,19 +450,17 @@ static void sdl_send_mouse_event(struct 
sdl2_console_state *scon, int dx, int dy
 }
 }
 }
-
-dx = (off_x + x) * 0x7FFF / (max_w - 1);
-dy = (off_y + y) * 0x7FFF / (max_h - 1);
+qemu_input_queue_abs(scon-dcl.con, INPUT_AXIS_X, off_x + x, max_w);
+qemu_input_queue_abs(scon-dcl.con, INPUT_AXIS_Y, off_y + y, max_h);
 } else if (guest_cursor) {
 x -= guest_x;
 y -= guest_y;
 guest_x += x;
 guest_y += y;
-dx = x;
-dy = y;
+qemu_input_queue_rel(scon-dcl.con, INPUT_AXIS_X, x);
+qemu_input_queue_rel(scon-dcl.con, INPUT_AXIS_Y, y);
 }
-
-kbd_mouse_event(dx, dy, dz, buttons);
+qemu_input_event_sync();
 }
 
 static void sdl_scale(struct sdl2_console_state *scon, int width, int height)
@@ -592,7 +594,7 @@ static void handle_mousemotion(SDL_Event *ev)
 int max_x, max_y;
 struct sdl2_console_state *scon = get_scon_from_window(ev-key.windowID);
 
-if (kbd_mouse_is_absolute() || absolute_enabled) {
+if (qemu_input_is_absolute() || absolute_enabled) {
 int scr_w, scr_h;
 SDL_GetWindowSize(scon-real_window, scr_w, scr_h);
 max_x = scr_w - 1;
@@ -607,7 +609,7 @@ static void handle_mousemotion(SDL_Event *ev)
 sdl_grab_start(scon);
 }
 }
-if (gui_grab || kbd_mouse_is_absolute() || absolute_enabled) {
+if (gui_grab || qemu_input_is_absolute() || absolute_enabled) {
 sdl_send_mouse_event(scon, ev-motion.xrel, ev-motion.yrel, 0,
  ev-motion.x, ev-motion.y, ev-motion.state);
 }
@@ -621,7 +623,7 @@ static void handle_mousebutton(SDL_Event *ev)
 int dz;
 
 bev = ev-button;
-if (!gui_grab  !kbd_mouse_is_absolute()) {
+if (!gui_grab  !qemu_input_is_absolute()) {
 if (ev-type == SDL_MOUSEBUTTONUP  bev-button == SDL_BUTTON_LEFT) {
 /* start grabbing all events */
 

[Qemu-devel] [PATCH 16/42] input: keyboard: switch vnc ui to new core

2013-12-16 Thread Gerd Hoffmann
---
 ui/vnc.c | 25 ++---
 1 file changed, 6 insertions(+), 19 deletions(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index 5601cc3..4658559 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -33,6 +33,7 @@
 #include qapi/qmp/types.h
 #include qmp-commands.h
 #include qemu/osdep.h
+#include ui/input.h
 
 #define VNC_REFRESH_INTERVAL_BASE GUI_REFRESH_INTERVAL_DEFAULT
 #define VNC_REFRESH_INTERVAL_INC  50
@@ -1542,9 +1543,7 @@ static void reset_keys(VncState *vs)
 int i;
 for(i = 0; i  256; i++) {
 if (vs-modifiers_state[i]) {
-if (i  SCANCODE_GREY)
-kbd_put_keycode(SCANCODE_EMUL0);
-kbd_put_keycode(i | SCANCODE_UP);
+qemu_input_event_send_key_number(vs-vd-dcl.con, i, false);
 vs-modifiers_state[i] = 0;
 }
 }
@@ -1553,12 +1552,8 @@ static void reset_keys(VncState *vs)
 static void press_key(VncState *vs, int keysym)
 {
 int keycode = keysym2scancode(vs-vd-kbd_layout, keysym)  
SCANCODE_KEYMASK;
-if (keycode  SCANCODE_GREY)
-kbd_put_keycode(SCANCODE_EMUL0);
-kbd_put_keycode(keycode  SCANCODE_KEYCODEMASK);
-if (keycode  SCANCODE_GREY)
-kbd_put_keycode(SCANCODE_EMUL0);
-kbd_put_keycode(keycode | SCANCODE_UP);
+qemu_input_event_send_key_number(vs-vd-dcl.con, keycode, true);
+qemu_input_event_send_key_number(vs-vd-dcl.con, keycode, false);
 }
 
 static int current_led_state(VncState *vs)
@@ -1700,12 +1695,7 @@ static void do_key_event(VncState *vs, int down, int 
keycode, int sym)
 }
 
 if (qemu_console_is_graphic(NULL)) {
-if (keycode  SCANCODE_GREY)
-kbd_put_keycode(SCANCODE_EMUL0);
-if (down)
-kbd_put_keycode(keycode  SCANCODE_KEYCODEMASK);
-else
-kbd_put_keycode(keycode | SCANCODE_UP);
+qemu_input_event_send_key_number(vs-vd-dcl.con, keycode, down);
 } else {
 bool numlock = vs-modifiers_state[0x45];
 bool control = (vs-modifiers_state[0x1d] ||
@@ -1826,10 +1816,7 @@ static void vnc_release_modifiers(VncState *vs)
 if (!vs-modifiers_state[keycode]) {
 continue;
 }
-if (keycode  SCANCODE_GREY) {
-kbd_put_keycode(SCANCODE_EMUL0);
-}
-kbd_put_keycode(keycode | SCANCODE_UP);
+qemu_input_event_send_key_number(vs-vd-dcl.con, keycode, false);
 }
 }
 
-- 
1.8.3.1




[Qemu-devel] [PATCH 15/42] sdl2: switch keyboard handling to new core

2013-12-16 Thread Gerd Hoffmann
---
 ui/sdl2.c | 23 ++-
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/ui/sdl2.c b/ui/sdl2.c
index e7a30b3..ac3ac19 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -33,6 +33,7 @@
 
 #include qemu-common.h
 #include ui/console.h
+#include ui/input.h
 #include sysemu/sysemu.h
 #include x_keymap.h
 #include sdl_zoom.h
@@ -236,9 +237,7 @@ static void reset_keys(void)
 int i;
 for(i = 0; i  256; i++) {
 if (modifiers_state[i]) {
-if (i  SCANCODE_GREY)
-kbd_put_keycode(SCANCODE_EMUL0);
-kbd_put_keycode(i | SCANCODE_UP);
+qemu_input_event_send_key_number(NULL, i, false);
 modifiers_state[i] = 0;
 }
 }
@@ -246,11 +245,12 @@ static void reset_keys(void)
 
 static void sdl_process_key(SDL_KeyboardEvent *ev)
 {
-int keycode, v;
+int keycode;
 
+#if 0
 if (ev-keysym.sym == SDLK_PAUSE) {
 /* specific case */
-v = 0;
+int v = 0;
 if (ev-type == SDL_KEYUP)
 v |= SCANCODE_UP;
 kbd_put_keycode(0xe1);
@@ -258,6 +258,7 @@ static void sdl_process_key(SDL_KeyboardEvent *ev)
 kbd_put_keycode(0x45 | v);
 return;
 }
+#endif
 
 if (kbd_layout) {
 keycode = sdl_keyevent_to_keycode_generic(ev);
@@ -284,18 +285,14 @@ static void sdl_process_key(SDL_KeyboardEvent *ev)
 case 0x45: /* num lock */
 case 0x3a: /* caps lock */
 /* SDL does not send the key up event, so we generate it */
-kbd_put_keycode(keycode);
-kbd_put_keycode(keycode | SCANCODE_UP);
+qemu_input_event_send_key_number(NULL, keycode, true);
+qemu_input_event_send_key_number(NULL, keycode, false);
 return;
 }
 
 /* now send the key code */
-if (keycode  SCANCODE_GREY)
-kbd_put_keycode(SCANCODE_EMUL0);
-if (ev-type == SDL_KEYUP)
-kbd_put_keycode(keycode | SCANCODE_UP);
-else
-kbd_put_keycode(keycode  SCANCODE_KEYCODEMASK);
+qemu_input_event_send_key_number(NULL, keycode,
+ ev-type == SDL_KEYDOWN);
 }
 
 static void sdl_update_caption(struct sdl2_console_state *scon)
-- 
1.8.3.1




[Qemu-devel] [PATCH 09/42] input: add core bits of the new input layer

2013-12-16 Thread Gerd Hoffmann
Register and unregister handlers.
Event dispatcher code.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 include/ui/input.h | 32 +
 ui/Makefile.objs   |  2 +-
 ui/input.c | 83 ++
 3 files changed, 116 insertions(+), 1 deletion(-)
 create mode 100644 include/ui/input.h
 create mode 100644 ui/input.c

diff --git a/include/ui/input.h b/include/ui/input.h
new file mode 100644
index 000..3cf3641
--- /dev/null
+++ b/include/ui/input.h
@@ -0,0 +1,32 @@
+#ifndef INPUT_H
+#define INPUT_H
+
+#include qapi-types.h
+
+#define INPUT_EVENT_MASK_KEY   (1INPUT_EVENT_KIND_KEY)
+#define INPUT_EVENT_MASK_BTN   (1INPUT_EVENT_KIND_BTN)
+#define INPUT_EVENT_MASK_REL   (1INPUT_EVENT_KIND_REL)
+#define INPUT_EVENT_MASK_ABS   (1INPUT_EVENT_KIND_ABS)
+
+typedef struct QemuInputHandler QemuInputHandler;
+typedef struct QemuInputHandlerState QemuInputHandlerState;
+
+typedef void (*QemuInputHandlerEvent)(DeviceState *dev, QemuConsole *src,
+  InputEvent *evt);
+typedef void (*QemuInputHandlerSync)(DeviceState *dev);
+
+struct QemuInputHandler {
+const char *name;
+uint32_t   mask;
+QemuInputHandlerEvent  event;
+QemuInputHandlerSync   sync;
+};
+
+QemuInputHandlerState *qemu_input_handler_register(DeviceState *dev,
+   QemuInputHandler *handler);
+void qemu_input_handler_activate(QemuInputHandlerState *s);
+void qemu_input_handler_unregister(QemuInputHandlerState *s);
+void qemu_input_event_send(QemuConsole *src, InputEvent *evt);
+void qemu_input_event_sync(void);
+
+#endif /* INPUT_H */
diff --git a/ui/Makefile.objs b/ui/Makefile.objs
index 16db07a..e6a5ec1 100644
--- a/ui/Makefile.objs
+++ b/ui/Makefile.objs
@@ -7,7 +7,7 @@ vnc-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o
 vnc-obj-$(CONFIG_VNC_WS) += vnc-ws.o
 vnc-obj-y += vnc-jobs.o
 
-common-obj-y += keymaps.o console.o cursor.o input-legacy.o qemu-pixman.o
+common-obj-y += keymaps.o console.o cursor.o input.o input-legacy.o 
qemu-pixman.o
 common-obj-$(CONFIG_SPICE) += spice-core.o spice-input.o spice-display.o
 common-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o sdl2.o
 common-obj-$(CONFIG_COCOA) += cocoa.o
diff --git a/ui/input.c b/ui/input.c
new file mode 100644
index 000..23c84f7
--- /dev/null
+++ b/ui/input.c
@@ -0,0 +1,83 @@
+#include sysemu/sysemu.h
+#include qapi-types.h
+#include ui/input.h
+
+struct QemuInputHandlerState {
+DeviceState   *dev;
+QemuInputHandler  *handler;
+int   id;
+int   events;
+QTAILQ_ENTRY(QemuInputHandlerState) node;
+};
+static QTAILQ_HEAD(, QemuInputHandlerState) handlers =
+QTAILQ_HEAD_INITIALIZER(handlers);
+
+QemuInputHandlerState *qemu_input_handler_register(DeviceState *dev,
+   QemuInputHandler *handler)
+{
+QemuInputHandlerState *s = g_new0(QemuInputHandlerState, 1);
+static int id = 1;
+
+s-dev = dev;
+s-handler = handler;
+s-id = id++;
+QTAILQ_INSERT_TAIL(handlers, s, node);
+return s;
+}
+
+void qemu_input_handler_activate(QemuInputHandlerState *s)
+{
+QTAILQ_REMOVE(handlers, s, node);
+QTAILQ_INSERT_HEAD(handlers, s, node);
+}
+
+void qemu_input_handler_unregister(QemuInputHandlerState *s)
+{
+QTAILQ_REMOVE(handlers, s, node);
+g_free(s);
+}
+
+static QemuInputHandlerState*
+qemu_input_find_handler(uint32_t mask)
+{
+QemuInputHandlerState *s;
+
+QTAILQ_FOREACH(s, handlers, node) {
+if (mask  s-handler-mask) {
+return s;
+}
+}
+return NULL;
+}
+
+void qemu_input_event_send(QemuConsole *src, InputEvent *evt)
+{
+QemuInputHandlerState *s;
+
+if (!runstate_is_running()  !runstate_check(RUN_STATE_SUSPENDED)) {
+return;
+}
+
+s = qemu_input_find_handler(1  evt-kind);
+s-handler-event(s-dev, src, evt);
+s-events++;
+}
+
+void qemu_input_event_sync(void)
+{
+QemuInputHandlerState *s;
+
+if (!runstate_is_running()  !runstate_check(RUN_STATE_SUSPENDED)) {
+return;
+}
+
+QTAILQ_FOREACH(s, handlers, node) {
+if (!s-events) {
+continue;
+}
+if (s-handler-sync) {
+s-handler-sync(s-dev);
+}
+s-events = 0;
+}
+}
-- 
1.8.3.1




[Qemu-devel] [PATCH 28/42] input: mouse: switch monitor to new core

2013-12-16 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 monitor.c | 31 ++-
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/monitor.c b/monitor.c
index 845f608..d22e720 100644
--- a/monitor.c
+++ b/monitor.c
@@ -39,6 +39,7 @@
 #include monitor/monitor.h
 #include monitor/readline.h
 #include ui/console.h
+#include ui/input.h
 #include sysemu/blockdev.h
 #include audio/audio.h
 #include disas/disas.h
@@ -1457,23 +1458,43 @@ static int mouse_button_state;
 
 static void do_mouse_move(Monitor *mon, const QDict *qdict)
 {
-int dx, dy, dz;
+int dx, dy, dz, button;
 const char *dx_str = qdict_get_str(qdict, dx_str);
 const char *dy_str = qdict_get_str(qdict, dy_str);
 const char *dz_str = qdict_get_try_str(qdict, dz_str);
+
 dx = strtol(dx_str, NULL, 0);
 dy = strtol(dy_str, NULL, 0);
-dz = 0;
-if (dz_str)
+qemu_input_queue_rel(NULL, INPUT_AXIS_X, dx);
+qemu_input_queue_rel(NULL, INPUT_AXIS_Y, dy);
+
+if (dz_str) {
 dz = strtol(dz_str, NULL, 0);
-kbd_mouse_event(dx, dy, dz, mouse_button_state);
+if (dz != 0) {
+button = (dz  0) ? INPUT_BUTTON_WHEEL_UP : 
INPUT_BUTTON_WHEEL_DOWN;
+qemu_input_queue_btn(NULL, button, true);
+qemu_input_event_sync();
+qemu_input_queue_btn(NULL, button, false);
+}
+}
+qemu_input_event_sync();
 }
 
 static void do_mouse_button(Monitor *mon, const QDict *qdict)
 {
+static uint32_t bmap[INPUT_BUTTON_MAX] = {
+[INPUT_BUTTON_LEFT]   = MOUSE_EVENT_LBUTTON,
+[INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON,
+[INPUT_BUTTON_RIGHT]  = MOUSE_EVENT_RBUTTON,
+};
 int button_state = qdict_get_int(qdict, button_state);
+
+if (mouse_button_state == button_state) {
+return;
+}
+qemu_input_update_buttons(NULL, bmap, mouse_button_state, button_state);
+qemu_input_event_sync();
 mouse_button_state = button_state;
-kbd_mouse_event(0, 0, 0, mouse_button_state);
 }
 
 static void do_ioport_read(Monitor *mon, const QDict *qdict)
-- 
1.8.3.1




[Qemu-devel] [PATCH 08/42] input: qapi: add pause key

2013-12-16 Thread Gerd Hoffmann
It's missing.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 qapi-schema.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qapi-schema.json b/qapi-schema.json
index 89d8060..56981d9 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3372,7 +3372,7 @@
 'kp_9', 'less', 'f11', 'f12', 'print', 'home', 'pgup', 'pgdn', 
'end',
 'left', 'up', 'down', 'right', 'insert', 'delete', 'stop', 'again',
 'props', 'undo', 'front', 'copy', 'open', 'paste', 'find', 'cut',
- 'lf', 'help', 'meta_l', 'meta_r', 'compose' ] }
+ 'lf', 'help', 'meta_l', 'meta_r', 'compose', 'pause' ] }
 
 ##
 # @KeyValue
-- 
1.8.3.1




[Qemu-devel] [PATCH 31/42] input: trace events

2013-12-16 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 trace-events |  8 
 ui/input.c   | 48 
 2 files changed, 56 insertions(+)

diff --git a/trace-events b/trace-events
index 9f4456a..a81d71e 100644
--- a/trace-events
+++ b/trace-events
@@ -1019,6 +1019,14 @@ 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)
 
+# ui/input.c
+input_event_key_number(int conidx, int number, bool down) con %d, key number 
0x%d, 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
+input_event_abs(int conidx, const char *axis, int value) con %d, axis %s, 
value 0x%x
+input_event_sync(void) 
+
 # hw/display/vmware_vga.c
 vmware_value_read(uint32_t index, uint32_t value) index %d, value 0x%x
 vmware_value_write(uint32_t index, uint32_t value) index %d, value 0x%x
diff --git a/ui/input.c b/ui/input.c
index 30a5b70..00eef0f 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -1,6 +1,8 @@
 #include sysemu/sysemu.h
 #include qapi-types.h
+#include trace.h
 #include ui/input.h
+#include ui/console.h
 
 struct QemuInputHandlerState {
 DeviceState   *dev;
@@ -77,6 +79,48 @@ 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;
+
+if (src) {
+idx = qemu_console_get_index(src);
+}
+switch (evt-kind) {
+case INPUT_EVENT_KIND_KEY:
+switch (evt-key-key-kind) {
+case KEY_VALUE_KIND_NUMBER:
+trace_input_event_key_number(idx, evt-key-key-number,
+ evt-key-down);
+break;
+case KEY_VALUE_KIND_QCODE:
+name = QKeyCode_lookup[evt-key-key-qcode];
+trace_input_event_key_qcode(idx, name, evt-key-down);
+break;
+case KEY_VALUE_KIND_MAX:
+/* keep gcc happy */
+break;
+}
+break;
+case INPUT_EVENT_KIND_BTN:
+name = InputButton_lookup[evt-btn-button];
+trace_input_event_btn(idx, name, evt-btn-down);
+break;
+case INPUT_EVENT_KIND_REL:
+name = InputAxis_lookup[evt-rel-axis];
+trace_input_event_rel(idx, name, evt-rel-value);
+break;
+case INPUT_EVENT_KIND_ABS:
+name = InputAxis_lookup[evt-abs-axis];
+trace_input_event_abs(idx, name, evt-abs-value);
+break;
+case INPUT_EVENT_KIND_MAX:
+/* keep gcc happy */
+break;
+}
+}
+
 void qemu_input_event_send(QemuConsole *src, InputEvent *evt)
 {
 QemuInputHandlerState *s;
@@ -85,6 +129,8 @@ void qemu_input_event_send(QemuConsole *src, InputEvent *evt)
 return;
 }
 
+qemu_input_event_trace(src, evt);
+
 /* pre processing */
 if (graphic_rotate  (evt-kind == INPUT_EVENT_KIND_ABS)) {
 qemu_input_transform_abs_rotate(evt);
@@ -104,6 +150,8 @@ void qemu_input_event_sync(void)
 return;
 }
 
+trace_input_event_sync();
+
 QTAILQ_FOREACH(s, handlers, node) {
 if (!s-events) {
 continue;
-- 
1.8.3.1




[Qemu-devel] [PATCH 34/42] input-legacy: remove kbd_mouse_is_absolute

2013-12-16 Thread Gerd Hoffmann
---
 include/ui/console.h |  1 -
 ui/input-legacy.c| 11 +--
 2 files changed, 1 insertion(+), 11 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index 53e956d..21b32e4 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -50,7 +50,6 @@ void kbd_put_ledstate(int ledstate);
 void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
 
 /* Does the current mouse generate absolute events */
-int kbd_mouse_is_absolute(void);
 void qemu_add_mouse_mode_change_notifier(Notifier *notify);
 void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
 
diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index 22796fa..412d401 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -369,7 +369,7 @@ static void check_mode_change(void)
 static int current_is_absolute;
 int is_absolute;
 
-is_absolute = kbd_mouse_is_absolute();
+is_absolute = qemu_input_is_absolute();
 
 if (is_absolute != current_is_absolute) {
 notifier_list_notify(mouse_mode_notifiers, NULL);
@@ -554,15 +554,6 @@ void kbd_mouse_event(int dx, int dy, int dz, int 
buttons_state)
 }
 }
 
-int kbd_mouse_is_absolute(void)
-{
-if (QTAILQ_EMPTY(mouse_handlers)) {
-return 0;
-}
-
-return QTAILQ_FIRST(mouse_handlers)-qemu_put_mouse_event_absolute;
-}
-
 MouseInfoList *qmp_query_mice(Error **errp)
 {
 MouseInfoList *mice_list = NULL;
-- 
1.8.3.1




[Qemu-devel] [PATCH 37/42] input: add input_mouse_mode tracepoint

2013-12-16 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 trace-events | 1 +
 ui/input.c   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/trace-events b/trace-events
index a81d71e..322ad11 100644
--- a/trace-events
+++ b/trace-events
@@ -1026,6 +1026,7 @@ input_event_btn(int conidx, const char *btn, bool down) 
con %d, button %s, down
 input_event_rel(int conidx, const char *axis, int value) con %d, axis %s, 
value %d
 input_event_abs(int conidx, const char *axis, int value) con %d, axis %s, 
value 0x%x
 input_event_sync(void) 
+input_mouse_mode(int absolute) absolute %d
 
 # hw/display/vmware_vga.c
 vmware_value_read(uint32_t index, uint32_t value) index %d, value 0x%x
diff --git a/ui/input.c b/ui/input.c
index a32bcff..55449dc 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -291,6 +291,7 @@ void qemu_input_check_mode_change(void)
 is_absolute = qemu_input_is_absolute();
 
 if (is_absolute != current_is_absolute) {
+trace_input_mouse_mode(is_absolute);
 notifier_list_notify(mouse_mode_notifiers, NULL);
 }
 
-- 
1.8.3.1




[Qemu-devel] [PATCH 20/42] input: mouse: add graphic_rotate support

2013-12-16 Thread Gerd Hoffmann
Transform absolute mouse events according to graphic_rotate.

Legacy input code does it for both absolute and relative events,
but the logic is broken for relative coordinates, so this is
most likely not used anyway.

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

diff --git a/ui/input.c b/ui/input.c
index a02172e..2c4d4d6 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -50,6 +50,33 @@ qemu_input_find_handler(uint32_t mask)
 return NULL;
 }
 
+static void qemu_input_transform_abs_rotate(InputEvent *evt)
+{
+switch (graphic_rotate) {
+case 90:
+if (evt-abs-axis == INPUT_AXIS_X) {
+evt-abs-axis = INPUT_AXIS_Y;
+}
+if (evt-abs-axis == INPUT_AXIS_Y) {
+evt-abs-axis = INPUT_AXIS_X;
+evt-abs-axis = INPUT_EVENT_ABS_SIZE - 1 - evt-abs-axis;
+}
+break;
+case 180:
+evt-abs-axis = INPUT_EVENT_ABS_SIZE - 1 - evt-abs-axis;
+break;
+case 270:
+if (evt-abs-axis == INPUT_AXIS_X) {
+evt-abs-axis = INPUT_AXIS_Y;
+evt-abs-axis = INPUT_EVENT_ABS_SIZE - 1 - evt-abs-axis;
+}
+if (evt-abs-axis == INPUT_AXIS_Y) {
+evt-abs-axis = INPUT_AXIS_X;
+}
+break;
+}
+}
+
 void qemu_input_event_send(QemuConsole *src, InputEvent *evt)
 {
 QemuInputHandlerState *s;
@@ -58,6 +85,12 @@ void qemu_input_event_send(QemuConsole *src, InputEvent *evt)
 return;
 }
 
+/* pre processing */
+if (graphic_rotate  (evt-kind == INPUT_EVENT_KIND_ABS)) {
+qemu_input_transform_abs_rotate(evt);
+}
+
+/* send event */
 s = qemu_input_find_handler(1  evt-kind);
 s-handler-event(s-dev, src, evt);
 s-events++;
-- 
1.8.3.1




[Qemu-devel] [PATCH 29/42] input: keyboard: switch cocoa ui to new core [untested]

2013-12-16 Thread Gerd Hoffmann
---
 ui/cocoa.m | 18 ++
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index be49179..a029493 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -496,16 +496,14 @@ QemuCocoaView *cocoaView;
 keycode = cocoa_keycode_to_qemu([event keyCode]);
 if (keycode) {
 if (keycode == 58 || keycode == 69) { // emulate caps lock and 
num lock keydown and keyup
-kbd_put_keycode(keycode);
-kbd_put_keycode(keycode | 0x80);
+qemu_input_event_send_key_number(dcl-con, keycode, true);
+qemu_input_event_send_key_number(dcl-con, keycode, false);
 } else if (qemu_console_is_graphic(NULL)) {
-if (keycode  0x80)
-kbd_put_keycode(0xe0);
 if (modifiers_state[keycode] == 0) { // keydown
-kbd_put_keycode(keycode  0x7f);
+qemu_input_event_send_key_number(dcl-con, keycode, 
true);
 modifiers_state[keycode] = 1;
 } else { // keyup
-kbd_put_keycode(keycode | 0x80);
+qemu_input_event_send_key_number(dcl-con, keycode, 
false);
 modifiers_state[keycode] = 0;
 }
 }
@@ -539,9 +537,7 @@ QemuCocoaView *cocoaView;
 
 // handle keys for graphic console
 } else if (qemu_console_is_graphic(NULL)) {
-if (keycode  0x80) //check bit for e0 in front
-kbd_put_keycode(0xe0);
-kbd_put_keycode(keycode  0x7f); //remove e0 bit in front
+qemu_input_event_send_key_number(dcl-con, keycode, true);
 
 // handlekeys for Monitor
 } else {
@@ -582,9 +578,7 @@ QemuCocoaView *cocoaView;
 case NSKeyUp:
 keycode = cocoa_keycode_to_qemu([event keyCode]);
 if (qemu_console_is_graphic(NULL)) {
-if (keycode  0x80)
-kbd_put_keycode(0xe0);
-kbd_put_keycode(keycode | 0x80); //add 128 to signal release 
of key
+qemu_input_event_send_key_number(dcl-con, keycode, false);
 }
 break;
 case NSMouseMoved:
-- 
1.8.3.1




[Qemu-devel] [PATCH 32/42] input-legacy: remove kbd_put_keycode

2013-12-16 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 include/ui/console.h |  1 -
 ui/input-legacy.c| 23 ---
 2 files changed, 24 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index a3062d0..c7f4e4f 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -46,7 +46,6 @@ void qemu_activate_mouse_event_handler(QEMUPutMouseEntry 
*entry);
 QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void 
*opaque);
 void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry);
 
-void kbd_put_keycode(int keycode);
 void kbd_put_ledstate(int ledstate);
 void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
 
diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index dd2dec3..3ac30e2 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -500,29 +500,6 @@ void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry)
 g_free(entry);
 }
 
-void kbd_put_keycode(int keycode)
-{
-static bool emul0;
-bool up;
-
-if (keycode == SCANCODE_EMUL0) {
-emul0 = true;
-return;
-}
-if (keycode  SCANCODE_UP) {
-keycode = ~SCANCODE_UP;
-up = true;
-} else {
-up = false;
-}
-if (emul0) {
-keycode |= SCANCODE_GREY;
-emul0 = false;
-}
-
-qemu_input_event_send_key_number(NULL, keycode, !up);
-}
-
 void kbd_put_ledstate(int ledstate)
 {
 QEMUPutLEDEntry *cursor;
-- 
1.8.3.1




[Qemu-devel] [PATCH 22/42] input: mouse: switch legacy handlers to new core

2013-12-16 Thread Gerd Hoffmann
legacy mouse event handlers are registered in the new core,
so they receive events submitted to the new input core.

legacy kbd_mouse_event() continues to use the old code paths.
So new-core event handlers wouldn't see events submitted via
kbd_mouse_event.

This leads to the constrain that we we must transition all
kbd_mouse_event() users first to keep things working.  But
that is easier to handle than translating legacy mouse events
into new-core mouse events ;)

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

diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index a4006cc..dd2dec3 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -41,6 +41,12 @@ struct QEMUPutMouseEntry {
 
 /* used internally by qemu for handling mice */
 QTAILQ_ENTRY(QEMUPutMouseEntry) node;
+
+/* new input core */
+QemuInputHandler h;
+QemuInputHandlerState *s;
+int axis[INPUT_AXIS_MAX];
+int buttons;
 };
 
 struct QEMUPutKbdEntry {
@@ -376,6 +382,51 @@ static void check_mode_change(void)
 current_has_absolute = has_absolute;
 }
 
+static void legacy_mouse_event(DeviceState *dev, QemuConsole *src,
+   InputEvent *evt)
+{
+static const int bmap[INPUT_BUTTON_MAX] = {
+[INPUT_BUTTON_LEFT]   = MOUSE_EVENT_LBUTTON,
+[INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON,
+[INPUT_BUTTON_RIGHT]  = MOUSE_EVENT_RBUTTON,
+};
+QEMUPutMouseEntry *s = (QEMUPutMouseEntry *)dev;
+
+switch (evt-kind) {
+case INPUT_EVENT_KIND_BTN:
+if (evt-btn-down) {
+s-buttons |= bmap[evt-btn-button];
+} else {
+s-buttons = ~bmap[evt-btn-button];
+}
+break;
+case INPUT_EVENT_KIND_ABS:
+s-axis[evt-abs-axis] = evt-abs-value;
+break;
+case INPUT_EVENT_KIND_REL:
+s-axis[evt-rel-axis] += evt-rel-value;
+break;
+default:
+break;
+}
+}
+
+static void legacy_mouse_sync(DeviceState *dev)
+{
+QEMUPutMouseEntry *s = (QEMUPutMouseEntry *)dev;
+
+s-qemu_put_mouse_event(s-qemu_put_mouse_event_opaque,
+s-axis[INPUT_AXIS_X],
+s-axis[INPUT_AXIS_Y],
+0,
+s-buttons);
+
+if (!s-qemu_put_mouse_event_absolute) {
+s-axis[INPUT_AXIS_X] = 0;
+s-axis[INPUT_AXIS_Y] = 0;
+}
+}
+
 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
 void *opaque, int absolute,
 const char *name)
@@ -393,6 +444,14 @@ QEMUPutMouseEntry 
*qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
 
 QTAILQ_INSERT_TAIL(mouse_handlers, s, node);
 
+s-h.name = name;
+s-h.mask = INPUT_EVENT_MASK_BTN |
+(absolute ? INPUT_EVENT_MASK_ABS : INPUT_EVENT_MASK_REL);
+s-h.event = legacy_mouse_event;
+s-h.sync = legacy_mouse_sync;
+s-s = qemu_input_handler_register((DeviceState *)s,
+   s-h);
+
 check_mode_change();
 
 return s;
@@ -403,6 +462,8 @@ void qemu_activate_mouse_event_handler(QEMUPutMouseEntry 
*entry)
 QTAILQ_REMOVE(mouse_handlers, entry, node);
 QTAILQ_INSERT_HEAD(mouse_handlers, entry, node);
 
+qemu_input_handler_activate(entry-s);
+
 check_mode_change();
 }
 
@@ -410,6 +471,8 @@ void qemu_remove_mouse_event_handler(QEMUPutMouseEntry 
*entry)
 {
 QTAILQ_REMOVE(mouse_handlers, entry, node);
 
+qemu_input_handler_unregister(entry-s);
+
 g_free(entry-qemu_put_mouse_event_name);
 g_free(entry);
 
-- 
1.8.3.1




[Qemu-devel] [PATCH 41/42] input: move do_mouse_set to new core

2013-12-16 Thread Gerd Hoffmann
This removes the last user of the lecagy input mouse handler list,
so we can remove more legacy bits with this.

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

diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index 7843482..b51e6ad 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -35,12 +35,6 @@ struct QEMUPutMouseEntry {
 QEMUPutMouseEvent *qemu_put_mouse_event;
 void *qemu_put_mouse_event_opaque;
 int qemu_put_mouse_event_absolute;
-char *qemu_put_mouse_event_name;
-
-int index;
-
-/* used internally by qemu for handling mice */
-QTAILQ_ENTRY(QEMUPutMouseEntry) node;
 
 /* new input core */
 QemuInputHandler h;
@@ -412,17 +406,12 @@ QEMUPutMouseEntry 
*qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
 const char *name)
 {
 QEMUPutMouseEntry *s;
-static int mouse_index = 0;
 
 s = g_malloc0(sizeof(QEMUPutMouseEntry));
 
 s-qemu_put_mouse_event = func;
 s-qemu_put_mouse_event_opaque = opaque;
 s-qemu_put_mouse_event_absolute = absolute;
-s-qemu_put_mouse_event_name = g_strdup(name);
-s-index = mouse_index++;
-
-QTAILQ_INSERT_TAIL(mouse_handlers, s, node);
 
 s-h.name = name;
 s-h.mask = INPUT_EVENT_MASK_BTN |
@@ -437,19 +426,13 @@ QEMUPutMouseEntry 
*qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
 
 void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry)
 {
-QTAILQ_REMOVE(mouse_handlers, entry, node);
-QTAILQ_INSERT_HEAD(mouse_handlers, entry, node);
-
 qemu_input_handler_activate(entry-s);
 }
 
 void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry)
 {
-QTAILQ_REMOVE(mouse_handlers, entry, node);
-
 qemu_input_handler_unregister(entry-s);
 
-g_free(entry-qemu_put_mouse_event_name);
 g_free(entry);
 }
 
@@ -482,29 +465,3 @@ void kbd_put_ledstate(int ledstate)
 cursor-put_led(cursor-opaque, ledstate);
 }
 }
-
-void do_mouse_set(Monitor *mon, const QDict *qdict)
-{
-QEMUPutMouseEntry *cursor;
-int index = qdict_get_int(qdict, index);
-int found = 0;
-
-if (QTAILQ_EMPTY(mouse_handlers)) {
-monitor_printf(mon, No mouse devices connected\n);
-return;
-}
-
-QTAILQ_FOREACH(cursor, mouse_handlers, node) {
-if (cursor-index == index) {
-found = 1;
-qemu_activate_mouse_event_handler(cursor);
-break;
-}
-}
-
-if (!found) {
-monitor_printf(mon, Mouse at given index not found\n);
-}
-
-qemu_input_check_mode_change();
-}
diff --git a/ui/input.c b/ui/input.c
index 2945a3c..575c50e 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -336,3 +336,24 @@ MouseInfoList *qmp_query_mice(Error **errp)
 
 return mice_list;
 }
+
+void do_mouse_set(Monitor *mon, const QDict *qdict)
+{
+QemuInputHandlerState *s;
+int index = qdict_get_int(qdict, index);
+int found = 0;
+
+QTAILQ_FOREACH(s, handlers, node) {
+if (s-id == index) {
+found = 1;
+qemu_input_handler_activate(s);
+break;
+}
+}
+
+if (!found) {
+monitor_printf(mon, Mouse at given index not found\n);
+}
+
+qemu_input_check_mode_change();
+}
-- 
1.8.3.1




[Qemu-devel] [PATCH 07/42] input: qapi: add unmapped key

2013-12-16 Thread Gerd Hoffmann
Simplifies building something - QkeyCode mapping tables.
Uninitialized entries can easily identified then.

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

diff --git a/qapi-schema.json b/qapi-schema.json
index 0316cb4..89d8060 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3357,7 +3357,8 @@
 # Since: 1.3.0
 ##
 { 'enum': 'QKeyCode',
-  'data': [ 'shift', 'shift_r', 'alt', 'alt_r', 'altgr', 'altgr_r', 'ctrl',
+  'data': [ 'unmapped',
+'shift', 'shift_r', 'alt', 'alt_r', 'altgr', 'altgr_r', 'ctrl',
 'ctrl_r', 'menu', 'esc', '1', '2', '3', '4', '5', '6', '7', '8',
 '9', '0', 'minus', 'equal', 'backspace', 'tab', 'q', 'w', 'e',
 'r', 't', 'y', 'u', 'i', 'o', 'p', 'bracket_left', 'bracket_right',
-- 
1.8.3.1




[Qemu-devel] [PATCH 35/42] input-legacy: remove kbd_mouse_event

2013-12-16 Thread Gerd Hoffmann
---
 include/ui/console.h |  1 -
 ui/input-legacy.c| 49 -
 2 files changed, 50 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index 21b32e4..71a0da3 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -47,7 +47,6 @@ QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent 
*func, void *opaque)
 void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry);
 
 void kbd_put_ledstate(int ledstate);
-void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
 
 /* Does the current mouse generate absolute events */
 void qemu_add_mouse_mode_change_notifier(Notifier *notify);
diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index 412d401..26ff06f 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -505,55 +505,6 @@ void kbd_put_ledstate(int ledstate)
 }
 }
 
-void kbd_mouse_event(int dx, int dy, int dz, int buttons_state)
-{
-QEMUPutMouseEntry *entry;
-QEMUPutMouseEvent *mouse_event;
-void *mouse_event_opaque;
-int width, height;
-
-if (!runstate_is_running()  !runstate_check(RUN_STATE_SUSPENDED)) {
-return;
-}
-if (QTAILQ_EMPTY(mouse_handlers)) {
-return;
-}
-
-entry = QTAILQ_FIRST(mouse_handlers);
-
-mouse_event = entry-qemu_put_mouse_event;
-mouse_event_opaque = entry-qemu_put_mouse_event_opaque;
-
-if (mouse_event) {
-if (entry-qemu_put_mouse_event_absolute) {
-width = 0x7fff;
-height = 0x7fff;
-} else {
-width = graphic_width - 1;
-height = graphic_height - 1;
-}
-
-switch (graphic_rotate) {
-case 0:
-mouse_event(mouse_event_opaque,
-dx, dy, dz, buttons_state);
-break;
-case 90:
-mouse_event(mouse_event_opaque,
-width - dy, dx, dz, buttons_state);
-break;
-case 180:
-mouse_event(mouse_event_opaque,
-width - dx, height - dy, dz, buttons_state);
-break;
-case 270:
-mouse_event(mouse_event_opaque,
-dy, height - dx, dz, buttons_state);
-break;
-}
-}
-}
-
 MouseInfoList *qmp_query_mice(Error **errp)
 {
 MouseInfoList *mice_list = NULL;
-- 
1.8.3.1




[Qemu-devel] [PATCH 33/42] input-legacy: remove kbd_mouse_has_absolute

2013-12-16 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 include/ui/console.h |  3 ---
 ui/input-legacy.c| 21 ++---
 2 files changed, 2 insertions(+), 22 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index c7f4e4f..53e956d 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -54,9 +54,6 @@ int kbd_mouse_is_absolute(void);
 void qemu_add_mouse_mode_change_notifier(Notifier *notify);
 void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
 
-/* Of all the mice, is there one that generates absolute events */
-int kbd_mouse_has_absolute(void);
-
 struct MouseTransformInfo {
 /* Touchscreen resolution */
 int x;
diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index 3ac30e2..22796fa 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -366,20 +366,16 @@ void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry)
 
 static void check_mode_change(void)
 {
-static int current_is_absolute, current_has_absolute;
+static int current_is_absolute;
 int is_absolute;
-int has_absolute;
 
 is_absolute = kbd_mouse_is_absolute();
-has_absolute = kbd_mouse_has_absolute();
 
-if (is_absolute != current_is_absolute ||
-has_absolute != current_has_absolute) {
+if (is_absolute != current_is_absolute) {
 notifier_list_notify(mouse_mode_notifiers, NULL);
 }
 
 current_is_absolute = is_absolute;
-current_has_absolute = has_absolute;
 }
 
 static void legacy_mouse_event(DeviceState *dev, QemuConsole *src,
@@ -567,19 +563,6 @@ int kbd_mouse_is_absolute(void)
 return QTAILQ_FIRST(mouse_handlers)-qemu_put_mouse_event_absolute;
 }
 
-int kbd_mouse_has_absolute(void)
-{
-QEMUPutMouseEntry *entry;
-
-QTAILQ_FOREACH(entry, mouse_handlers, node) {
-if (entry-qemu_put_mouse_event_absolute) {
-return 1;
-}
-}
-
-return 0;
-}
-
 MouseInfoList *qmp_query_mice(Error **errp)
 {
 MouseInfoList *mice_list = NULL;
-- 
1.8.3.1




[Qemu-devel] [PATCH 24/42] input: mouse: switch sdl ui to new core

2013-12-16 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/sdl.c | 84 ++--
 1 file changed, 39 insertions(+), 45 deletions(-)

diff --git a/ui/sdl.c b/ui/sdl.c
index c3b8036..c1a16be 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -353,7 +353,7 @@ static void sdl_hide_cursor(void)
 if (!cursor_hide)
 return;
 
-if (kbd_mouse_is_absolute()) {
+if (qemu_input_is_absolute()) {
 SDL_ShowCursor(1);
 SDL_SetCursor(sdl_cursor_hidden);
 } else {
@@ -366,10 +366,10 @@ static void sdl_show_cursor(void)
 if (!cursor_hide)
 return;
 
-if (!kbd_mouse_is_absolute() || !qemu_console_is_graphic(NULL)) {
+if (!qemu_input_is_absolute() || !qemu_console_is_graphic(NULL)) {
 SDL_ShowCursor(1);
 if (guest_cursor 
-(gui_grab || kbd_mouse_is_absolute() || absolute_enabled))
+(gui_grab || qemu_input_is_absolute() || absolute_enabled))
 SDL_SetCursor(guest_sprite);
 else
 SDL_SetCursor(sdl_cursor_normal);
@@ -388,8 +388,9 @@ static void sdl_grab_start(void)
 }
 if (guest_cursor) {
 SDL_SetCursor(guest_sprite);
-if (!kbd_mouse_is_absolute()  !absolute_enabled)
+if (!qemu_input_is_absolute()  !absolute_enabled) {
 SDL_WarpMouse(guest_x, guest_y);
+}
 } else
 sdl_hide_cursor();
 SDL_WM_GrabInput(SDL_GRAB_ON);
@@ -418,7 +419,7 @@ static void absolute_mouse_grab(void)
 
 static void sdl_mouse_mode_change(Notifier *notify, void *data)
 {
-if (kbd_mouse_is_absolute()) {
+if (qemu_input_is_absolute()) {
 if (!absolute_enabled) {
 absolute_enabled = 1;
 if (qemu_console_is_graphic(NULL)) {
@@ -433,33 +434,36 @@ static void sdl_mouse_mode_change(Notifier *notify, void 
*data)
 }
 }
 
-static void sdl_send_mouse_event(int dx, int dy, int dz, int x, int y, int 
state)
+static void sdl_send_mouse_event(int dx, int dy, int x, int y, int state)
 {
-int buttons = 0;
-
-if (state  SDL_BUTTON(SDL_BUTTON_LEFT)) {
-buttons |= MOUSE_EVENT_LBUTTON;
-}
-if (state  SDL_BUTTON(SDL_BUTTON_RIGHT)) {
-buttons |= MOUSE_EVENT_RBUTTON;
-}
-if (state  SDL_BUTTON(SDL_BUTTON_MIDDLE)) {
-buttons |= MOUSE_EVENT_MBUTTON;
-}
-
-if (kbd_mouse_is_absolute()) {
-dx = x * 0x7FFF / (real_screen-w - 1);
-dy = y * 0x7FFF / (real_screen-h - 1);
+static uint32_t bmap[INPUT_BUTTON_MAX] = {
+[INPUT_BUTTON_LEFT]   = SDL_BUTTON(SDL_BUTTON_LEFT),
+[INPUT_BUTTON_MIDDLE] = SDL_BUTTON(SDL_BUTTON_MIDDLE),
+[INPUT_BUTTON_RIGHT]  = SDL_BUTTON(SDL_BUTTON_RIGHT),
+[INPUT_BUTTON_WHEEL_UP]   = SDL_BUTTON(SDL_BUTTON_WHEELUP),
+[INPUT_BUTTON_WHEEL_DOWN] = SDL_BUTTON(SDL_BUTTON_WHEELDOWN),
+};
+static uint32_t prev_state;
+
+if (prev_state != state) {
+qemu_input_update_buttons(dcl-con, bmap, prev_state, state);
+prev_state = state;
+}
+
+if (qemu_input_is_absolute()) {
+qemu_input_queue_abs(dcl-con, INPUT_AXIS_X, x,
+ real_screen-w);
+qemu_input_queue_abs(dcl-con, INPUT_AXIS_Y, y,
+ real_screen-h);
 } else if (guest_cursor) {
 x -= guest_x;
 y -= guest_y;
 guest_x += x;
 guest_y += y;
-dx = x;
-dy = y;
+qemu_input_queue_rel(dcl-con, INPUT_AXIS_X, x);
+qemu_input_queue_rel(dcl-con, INPUT_AXIS_Y, y);
 }
-
-kbd_mouse_event(dx, dy, dz, buttons);
+qemu_input_event_sync();
 }
 
 static void sdl_scale(int width, int height)
@@ -687,7 +691,7 @@ static void handle_mousemotion(SDL_Event *ev)
 int max_x, max_y;
 
 if (qemu_console_is_graphic(NULL) 
-(kbd_mouse_is_absolute() || absolute_enabled)) {
+(qemu_input_is_absolute() || absolute_enabled)) {
 max_x = real_screen-w - 1;
 max_y = real_screen-h - 1;
 if (gui_grab  (ev-motion.x == 0 || ev-motion.y == 0 ||
@@ -700,8 +704,8 @@ static void handle_mousemotion(SDL_Event *ev)
 sdl_grab_start();
 }
 }
-if (gui_grab || kbd_mouse_is_absolute() || absolute_enabled) {
-sdl_send_mouse_event(ev-motion.xrel, ev-motion.yrel, 0,
+if (gui_grab || qemu_input_is_absolute() || absolute_enabled) {
+sdl_send_mouse_event(ev-motion.xrel, ev-motion.yrel,
  ev-motion.x, ev-motion.y, ev-motion.state);
 }
 }
@@ -710,35 +714,24 @@ static void handle_mousebutton(SDL_Event *ev)
 {
 int buttonstate = SDL_GetMouseState(NULL, NULL);
 SDL_MouseButtonEvent *bev;
-int dz;
 
 if (!qemu_console_is_graphic(NULL)) {
 return;
 }
 
 bev = ev-button;
-if (!gui_grab  !kbd_mouse_is_absolute()) {
+if (!gui_grab  !qemu_input_is_absolute()) {
 if (ev-type == SDL_MOUSEBUTTONUP  bev-button == SDL_BUTTON_LEFT) {
 

[Qemu-devel] [PATCH 42/42] input: remove index_from_keycode (no users)

2013-12-16 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 include/ui/console.h |  1 -
 ui/input-legacy.c| 14 --
 2 files changed, 15 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index 9a282cb..3bf69ee 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -329,7 +329,6 @@ void curses_display_init(DisplayState *ds, int full_screen);
 
 /* input.c */
 int index_from_key(const char *key);
-int index_from_keycode(int code);
 
 /* gtk.c */
 void early_gtk_display_init(void);
diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index b51e6ad..f38984b 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -220,20 +220,6 @@ int index_from_key(const char *key)
 return i;
 }
 
-int index_from_keycode(int code)
-{
-int i;
-
-for (i = 0; i  Q_KEY_CODE_MAX; i++) {
-if (key_defs[i] == code) {
-break;
-}
-}
-
-/* Return Q_KEY_CODE_MAX if the code is invalid */
-return i;
-}
-
 static int *keycodes;
 static int keycodes_size;
 static QEMUTimer *key_timer;
-- 
1.8.3.1




[Qemu-devel] [PATCH 30/42] input: mouse: switch cocoa ui to new core [untested]

2013-12-16 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 include/ui/console.h |  2 ++
 ui/cocoa.m   | 63 ++--
 2 files changed, 44 insertions(+), 21 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index 8543d18..a3062d0 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -14,6 +14,8 @@
 #define MOUSE_EVENT_LBUTTON 0x01
 #define MOUSE_EVENT_RBUTTON 0x02
 #define MOUSE_EVENT_MBUTTON 0x04
+#define MOUSE_EVENT_WHEELUP 0x08
+#define MOUSE_EVENT_WHEELDN 0x10
 
 /* identical to the ps/2 keyboard bits */
 #define QEMU_SCROLL_LOCK_LED (1  0)
diff --git a/ui/cocoa.m b/ui/cocoa.m
index a029493..9cc512f 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -27,6 +27,7 @@
 
 #include qemu-common.h
 #include ui/console.h
+#include ui/input.h
 #include sysemu/sysemu.h
 
 #ifndef MAC_OS_X_VERSION_10_4
@@ -49,14 +50,6 @@
 #endif
 
 #define cgrect(nsrect) (*(CGRect *)(nsrect))
-#define COCOA_MOUSE_EVENT \
-if (isTabletEnabled) { \
-kbd_mouse_event((int)(p.x * 0x7FFF / (screen.width - 1)), 
(int)((screen.height - p.y) * 0x7FFF / (screen.height - 1)), 0, buttons); \
-} else if (isMouseGrabed) { \
-kbd_mouse_event((int)[event deltaX], (int)[event deltaY], 0, 
buttons); \
-} else { \
-[NSApp sendEvent:event]; \
-}
 
 typedef struct {
 int width;
@@ -67,6 +60,7 @@ typedef struct {
 
 NSWindow *normalWindow;
 static DisplayChangeListener *dcl;
+static int last_buttons;
 
 int gArgc;
 char **gArgv;
@@ -489,6 +483,7 @@ QemuCocoaView *cocoaView;
 
 int buttons = 0;
 int keycode;
+bool mouse_event = false;
 NSPoint p = [event locationInWindow];
 
 switch ([event type]) {
@@ -595,7 +590,7 @@ QemuCocoaView *cocoaView;
 }
 }
 }
-COCOA_MOUSE_EVENT
+mouse_event = true;
 break;
 case NSLeftMouseDown:
 if ([event modifierFlags]  NSCommandKeyMask) {
@@ -603,15 +598,15 @@ QemuCocoaView *cocoaView;
 } else {
 buttons |= MOUSE_EVENT_LBUTTON;
 }
-COCOA_MOUSE_EVENT
+mouse_event = true;
 break;
 case NSRightMouseDown:
 buttons |= MOUSE_EVENT_RBUTTON;
-COCOA_MOUSE_EVENT
+mouse_event = true;
 break;
 case NSOtherMouseDown:
 buttons |= MOUSE_EVENT_MBUTTON;
-COCOA_MOUSE_EVENT
+mouse_event = true;
 break;
 case NSLeftMouseDragged:
 if ([event modifierFlags]  NSCommandKeyMask) {
@@ -619,19 +614,19 @@ QemuCocoaView *cocoaView;
 } else {
 buttons |= MOUSE_EVENT_LBUTTON;
 }
-COCOA_MOUSE_EVENT
+mouse_event = true;
 break;
 case NSRightMouseDragged:
 buttons |= MOUSE_EVENT_RBUTTON;
-COCOA_MOUSE_EVENT
+mouse_event = true;
 break;
 case NSOtherMouseDragged:
 buttons |= MOUSE_EVENT_MBUTTON;
-COCOA_MOUSE_EVENT
+mouse_event = true;
 break;
 case NSLeftMouseUp:
 if (isTabletEnabled) {
-COCOA_MOUSE_EVENT
+mouse_event = true;
 } else if (!isMouseGrabed) {
 if (p.x  -1  p.x  screen.width  p.y  -1  p.y  
screen.height) {
 [self grabMouse];
@@ -639,18 +634,20 @@ QemuCocoaView *cocoaView;
 [NSApp sendEvent:event];
 }
 } else {
-COCOA_MOUSE_EVENT
+mouse_event = true;
 }
 break;
 case NSRightMouseUp:
-COCOA_MOUSE_EVENT
+mouse_event = true;
 break;
 case NSOtherMouseUp:
-COCOA_MOUSE_EVENT
+mouse_event = true;
 break;
 case NSScrollWheel:
 if (isTabletEnabled || isMouseGrabed) {
-kbd_mouse_event(0, 0, -[event deltaY], 0);
+button |= ([event deltaY]  0) ?
+MOUSE_EVENT_WHEELUP : MOUSE_EVENT_WHEELDN;
+mouse_event = true;
 } else {
 [NSApp sendEvent:event];
 }
@@ -658,6 +655,30 @@ QemuCocoaView *cocoaView;
 default:
 [NSApp sendEvent:event];
 }
+
+if (mouse_event) {
+if (last_buttons != buttons) {
+static uint32_t bmap[INPUT_BUTTON_MAX] = {
+[INPUT_BUTTON_LEFT]   = MOUSE_EVENT_LBUTTON,
+[INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON,
+[INPUT_BUTTON_RIGHT]  = MOUSE_EVENT_RBUTTON,
+[INPUT_BUTTON_WHEEL_UP]   = MOUSE_EVENT_WHEELUP,
+[INPUT_BUTTON_WHEEL_DOWN] = MOUSE_EVENT_WHEELDN,
+};
+qemu_input_update_buttons(con, bmap, last_buttons, buttons);
+  

[Qemu-devel] [PATCH 38/42] sdl2: simplify keymap handling

2013-12-16 Thread Gerd Hoffmann
sdl2 gives us scancodes (i.e. identifies keys by location not by keysym
mapped to it).  We can map them directly to QKeyCodes, pass them on to
the new input core and be done with it.

No need to jump though any keymap hops.  Zap the code.
Also operate directly on SDL scancodes for any hotkeys.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/sdl2-keymap.h | 266 +++
 ui/sdl2.c| 147 ++--
 ui/sdl2_scancode_translate.h | 260 --
 3 files changed, 298 insertions(+), 375 deletions(-)
 create mode 100644 ui/sdl2-keymap.h
 delete mode 100644 ui/sdl2_scancode_translate.h

diff --git a/ui/sdl2-keymap.h b/ui/sdl2-keymap.h
new file mode 100644
index 000..5a12f45
--- /dev/null
+++ b/ui/sdl2-keymap.h
@@ -0,0 +1,266 @@
+
+/* map SDL2 scancodes to QKeyCode */
+
+static const int sdl2_scancode_to_qcode[SDL_NUM_SCANCODES] = {
+[SDL_SCANCODE_A] = Q_KEY_CODE_A,
+[SDL_SCANCODE_B] = Q_KEY_CODE_B,
+[SDL_SCANCODE_C] = Q_KEY_CODE_C,
+[SDL_SCANCODE_D] = Q_KEY_CODE_D,
+[SDL_SCANCODE_E] = Q_KEY_CODE_E,
+[SDL_SCANCODE_F] = Q_KEY_CODE_F,
+[SDL_SCANCODE_G] = Q_KEY_CODE_G,
+[SDL_SCANCODE_H] = Q_KEY_CODE_H,
+[SDL_SCANCODE_I] = Q_KEY_CODE_I,
+[SDL_SCANCODE_J] = Q_KEY_CODE_J,
+[SDL_SCANCODE_K] = Q_KEY_CODE_K,
+[SDL_SCANCODE_L] = Q_KEY_CODE_L,
+[SDL_SCANCODE_M] = Q_KEY_CODE_M,
+[SDL_SCANCODE_N] = Q_KEY_CODE_N,
+[SDL_SCANCODE_O] = Q_KEY_CODE_O,
+[SDL_SCANCODE_P] = Q_KEY_CODE_P,
+[SDL_SCANCODE_Q] = Q_KEY_CODE_Q,
+[SDL_SCANCODE_R] = Q_KEY_CODE_R,
+[SDL_SCANCODE_S] = Q_KEY_CODE_S,
+[SDL_SCANCODE_T] = Q_KEY_CODE_T,
+[SDL_SCANCODE_U] = Q_KEY_CODE_U,
+[SDL_SCANCODE_V] = Q_KEY_CODE_V,
+[SDL_SCANCODE_W] = Q_KEY_CODE_W,
+[SDL_SCANCODE_X] = Q_KEY_CODE_X,
+[SDL_SCANCODE_Y] = Q_KEY_CODE_Y,
+[SDL_SCANCODE_Z] = Q_KEY_CODE_Z,
+
+[SDL_SCANCODE_1] = Q_KEY_CODE_1,
+[SDL_SCANCODE_2] = Q_KEY_CODE_2,
+[SDL_SCANCODE_3] = Q_KEY_CODE_3,
+[SDL_SCANCODE_4] = Q_KEY_CODE_4,
+[SDL_SCANCODE_5] = Q_KEY_CODE_5,
+[SDL_SCANCODE_6] = Q_KEY_CODE_6,
+[SDL_SCANCODE_7] = Q_KEY_CODE_7,
+[SDL_SCANCODE_8] = Q_KEY_CODE_8,
+[SDL_SCANCODE_9] = Q_KEY_CODE_9,
+[SDL_SCANCODE_0] = Q_KEY_CODE_0,
+
+[SDL_SCANCODE_RETURN]= Q_KEY_CODE_RET,
+[SDL_SCANCODE_ESCAPE]= Q_KEY_CODE_ESC,
+[SDL_SCANCODE_BACKSPACE] = Q_KEY_CODE_BACKSPACE,
+[SDL_SCANCODE_TAB]   = Q_KEY_CODE_TAB,
+[SDL_SCANCODE_SPACE] = Q_KEY_CODE_SPC,
+[SDL_SCANCODE_MINUS] = Q_KEY_CODE_MINUS,
+[SDL_SCANCODE_EQUALS]= Q_KEY_CODE_EQUAL,
+[SDL_SCANCODE_LEFTBRACKET]   = Q_KEY_CODE_BRACKET_LEFT,
+[SDL_SCANCODE_RIGHTBRACKET]  = Q_KEY_CODE_BRACKET_RIGHT,
+[SDL_SCANCODE_BACKSLASH] = Q_KEY_CODE_BACKSLASH,
+#if 0
+[SDL_SCANCODE_NONUSHASH] = Q_KEY_CODE_NONUSHASH,
+#endif
+[SDL_SCANCODE_SEMICOLON] = Q_KEY_CODE_SEMICOLON,
+[SDL_SCANCODE_APOSTROPHE]= Q_KEY_CODE_APOSTROPHE,
+[SDL_SCANCODE_GRAVE] = Q_KEY_CODE_GRAVE_ACCENT,
+[SDL_SCANCODE_COMMA] = Q_KEY_CODE_COMMA,
+[SDL_SCANCODE_PERIOD]= Q_KEY_CODE_DOT,
+[SDL_SCANCODE_SLASH] = Q_KEY_CODE_SLASH,
+[SDL_SCANCODE_CAPSLOCK]  = Q_KEY_CODE_CAPS_LOCK,
+
+[SDL_SCANCODE_F1]= Q_KEY_CODE_F1,
+[SDL_SCANCODE_F2]= Q_KEY_CODE_F2,
+[SDL_SCANCODE_F3]= Q_KEY_CODE_F3,
+[SDL_SCANCODE_F4]= Q_KEY_CODE_F4,
+[SDL_SCANCODE_F5]= Q_KEY_CODE_F5,
+[SDL_SCANCODE_F6]= Q_KEY_CODE_F6,
+[SDL_SCANCODE_F7]= Q_KEY_CODE_F7,
+[SDL_SCANCODE_F8]= Q_KEY_CODE_F8,
+[SDL_SCANCODE_F9]= Q_KEY_CODE_F9,
+[SDL_SCANCODE_F10]   = Q_KEY_CODE_F10,
+[SDL_SCANCODE_F11]   = Q_KEY_CODE_F11,
+[SDL_SCANCODE_F12]   = Q_KEY_CODE_F12,
+
+[SDL_SCANCODE_PRINTSCREEN]   = Q_KEY_CODE_PRINT,
+[SDL_SCANCODE_SCROLLLOCK]= Q_KEY_CODE_SCROLL_LOCK,
+[SDL_SCANCODE_PAUSE] = Q_KEY_CODE_PAUSE,
+[SDL_SCANCODE_INSERT]= Q_KEY_CODE_INSERT,
+[SDL_SCANCODE_HOME]  = Q_KEY_CODE_HOME,
+[SDL_SCANCODE_PAGEUP]

Re: [Qemu-devel] [PATCH v3 7/8] target-arm: A64: add support for 3 src data proc insns

2013-12-16 Thread Peter Maydell
On 13 December 2013 19:18, Peter Maydell peter.mayd...@linaro.org wrote:
  static void disas_data_proc_3src(DisasContext *s, uint32_t insn)
  {
 -unsupported_encoding(s, insn);
 +int rd = extract32(insn, 0, 5);
 +int rn = extract32(insn, 5, 5);
 +int ra = extract32(insn, 10, 5);
 +int rm = extract32(insn, 16, 5);
 +int op_id = (extract32(insn, 29, 3)  4) |
 +(extract32(insn, 21, 3)  1) |
 +extract32(insn, 15, 1);
 +bool is_32bit = !extract32(insn, 31, 1);
 +bool is_sub = extract32(op_id, 0, 1);
 +bool is_high = extract32(op_id, 2, 1);
 +bool is_signed = false;
 +TCGv_i64 tcg_op1;
 +TCGv_i64 tcg_op2;
 +TCGv_i64 tcg_tmp;
 +
 +/* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag 
 */
 +switch (op_id) {
 +case 0x42: /* SMADDL */
 +case 0x43: /* SMSUBL */
 +case 0x44: /* SMULH */
 +is_signed = true;
 +break;
 +case 0x0: /* MADD (32bit) */
 +case 0x1: /* MSUB (32bit) */
 +case 0x40: /* MADD (64bit) */
 +case 0x41: /* MSUB (64bit) */
 +case 0x4a: /* UMADDL */
 +case 0x4b: /* UMSUBL */
 +case 0x4c: /* UMULH */
 +break;
 +default:
 +unallocated_encoding(s);
 +}

Missing 'return' after unallocated_encoding(), fixed in my
working tree.

thanks
-- PMM



[Qemu-devel] [PATCH 39/42] sdl2: codestyle fixups

2013-12-16 Thread Gerd Hoffmann
---
 ui/Makefile.objs |   2 +-
 ui/sdl2.c| 173 +--
 2 files changed, 104 insertions(+), 71 deletions(-)

diff --git a/ui/Makefile.objs b/ui/Makefile.objs
index e6a5ec1..6f2294e 100644
--- a/ui/Makefile.objs
+++ b/ui/Makefile.objs
@@ -15,6 +15,6 @@ common-obj-$(CONFIG_CURSES) += curses.o
 common-obj-$(CONFIG_VNC) += $(vnc-obj-y)
 common-obj-$(CONFIG_GTK) += gtk.o x_keymap.o
 
-$(obj)/sdl.o $(obj)/sdl_zoom.o $(obj)/sdl2.o: QEMU_CFLAGS += $(SDL_CFLAGS) 
+$(obj)/sdl.o $(obj)/sdl_zoom.o $(obj)/sdl2.o: QEMU_CFLAGS += $(SDL_CFLAGS)
 
 $(obj)/gtk.o: QEMU_CFLAGS += $(GTK_CFLAGS) $(VTE_CFLAGS)
diff --git a/ui/sdl2.c b/ui/sdl2.c
index 5338b90..f1532e9 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -40,7 +40,7 @@
 #include sdl2-keymap.h
 
 static int sdl2_num_outputs;
-static struct sdl2_console_state {
+static struct sdl2_state {
 DisplayChangeListener dcl;
 DisplaySurface *surface;
 SDL_Texture *texture;
@@ -66,21 +66,22 @@ static int gui_grab_code = KMOD_LALT | KMOD_LCTRL;
 static uint8_t modifiers_state[SDL_NUM_SCANCODES];
 static SDL_Cursor *sdl_cursor_normal;
 static SDL_Cursor *sdl_cursor_hidden;
-static int absolute_enabled = 0;
-static int guest_cursor = 0;
+static int absolute_enabled;
+static int guest_cursor;
 static int guest_x, guest_y;
-static SDL_Cursor *guest_sprite = NULL;
-static int scaling_active = 0;
+static SDL_Cursor *guest_sprite;
+static int scaling_active;
 static Notifier mouse_mode_notifier;
 
-static void sdl_update_caption(struct sdl2_console_state *scon);
+static void sdl_update_caption(struct sdl2_state *scon);
 
-static struct sdl2_console_state *get_scon_from_window(uint32_t window_id)
+static struct sdl2_state *get_scon_from_window(uint32_t window_id)
 {
 int i;
 for (i = 0; i  sdl2_num_outputs; i++) {
-if (sdl2_console[i].real_window == SDL_GetWindowFromID(window_id))
+if (sdl2_console[i].real_window == SDL_GetWindowFromID(window_id)) {
 return sdl2_console[i];
+}
 }
 return NULL;
 }
@@ -88,14 +89,16 @@ static struct sdl2_console_state 
*get_scon_from_window(uint32_t window_id)
 static void sdl_update(DisplayChangeListener *dcl,
int x, int y, int w, int h)
 {
-struct sdl2_console_state *scon = container_of(dcl, struct 
sdl2_console_state, dcl);
+struct sdl2_state *scon = container_of(dcl, struct sdl2_state, dcl);
 SDL_Rect rect;
 DisplaySurface *surf = qemu_console_surface(dcl-con);
 
-if (!surf)
+if (!surf) {
 return;
-if (!scon-texture)
+}
+if (!scon-texture) {
 return;
+}
 
 rect.x = x;
 rect.y = y;
@@ -108,14 +111,14 @@ static void sdl_update(DisplayChangeListener *dcl,
 SDL_RenderPresent(scon-real_renderer);
 }
 
-static void do_sdl_resize(struct sdl2_console_state *scon, int width, int 
height, int bpp)
+static void do_sdl_resize(struct sdl2_state *scon, int width, int height,
+  int bpp)
 {
 int flags;
 
 if (scon-real_window  scon-real_renderer) {
 if (width  height) {
 SDL_RenderSetLogicalSize(scon-real_renderer, width, height);
-   
 SDL_SetWindowSize(scon-real_window, width, height);
 } else {
 SDL_DestroyRenderer(scon-real_renderer);
@@ -128,10 +131,11 @@ static void do_sdl_resize(struct sdl2_console_state 
*scon, int width, int height
 return;
 }
 flags = 0;
-if (gui_fullscreen)
+if (gui_fullscreen) {
 flags |= SDL_WINDOW_FULLSCREEN;
-else
+} else {
 flags |= SDL_WINDOW_RESIZABLE;
+}
 
 scon-real_window = SDL_CreateWindow(, SDL_WINDOWPOS_UNDEFINED,
  SDL_WINDOWPOS_UNDEFINED,
@@ -144,7 +148,7 @@ static void do_sdl_resize(struct sdl2_console_state *scon, 
int width, int height
 static void sdl_switch(DisplayChangeListener *dcl,
DisplaySurface *new_surface)
 {
-struct sdl2_console_state *scon = container_of(dcl, struct 
sdl2_console_state, dcl);
+struct sdl2_state *scon = container_of(dcl, struct sdl2_state, dcl);
 int format = 0;
 int idx = scon-idx;
 DisplaySurface *old_surface = scon-surface;
@@ -154,13 +158,16 @@ static void sdl_switch(DisplayChangeListener *dcl,
 scon-surface = new_surface;
 }
 
-if (!new_surface  idx  0)
+if (!new_surface  idx  0) {
 scon-surface = NULL;
+}
 
-if (new_surface == NULL)
+if (new_surface == NULL) {
 do_sdl_resize(scon, 0, 0, 0);
-else
-do_sdl_resize(scon, surface_width(scon-surface), 
surface_height(scon-surface), 0);
+} else {
+do_sdl_resize(scon, surface_width(scon-surface),
+  surface_height(scon-surface), 0);
+}
 
 if (old_surface  scon-texture) {
 SDL_DestroyTexture(scon-texture);
@@ -169,14 +176,16 @@ static void sdl_switch(DisplayChangeListener 

[Qemu-devel] [PATCH 17/42] input: keyboard: switch spice ui to new core

2013-12-16 Thread Gerd Hoffmann
---
 ui/spice-input.c | 22 --
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/ui/spice-input.c b/ui/spice-input.c
index 3beb8de..c9df699 100644
--- a/ui/spice-input.c
+++ b/ui/spice-input.c
@@ -26,12 +26,15 @@
 #include qemu-common.h
 #include ui/qemu-spice.h
 #include ui/console.h
+#include ui/keymaps.h
+#include ui/input.h
 
 /* keyboard bits */
 
 typedef struct QemuSpiceKbd {
 SpiceKbdInstance sin;
 int ledstate;
+bool emul0;
 } QemuSpiceKbd;
 
 static void kbd_push_key(SpiceKbdInstance *sin, uint8_t frag);
@@ -47,9 +50,24 @@ static const SpiceKbdInterface kbd_interface = {
 .get_leds   = kbd_get_leds,
 };
 
-static void kbd_push_key(SpiceKbdInstance *sin, uint8_t frag)
+static void kbd_push_key(SpiceKbdInstance *sin, uint8_t scancode)
 {
-kbd_put_keycode(frag);
+QemuSpiceKbd *kbd = container_of(sin, QemuSpiceKbd, sin);
+int keycode;
+bool up;
+
+if (scancode == SCANCODE_EMUL0) {
+kbd-emul0 = true;
+return;
+}
+keycode = scancode  ~SCANCODE_UP;
+up = scancode  SCANCODE_UP;
+if (kbd-emul0) {
+kbd-emul0 = false;
+keycode |= SCANCODE_GREY;
+}
+
+qemu_input_event_send_key_number(NULL, keycode, !up);
 }
 
 static uint8_t kbd_get_leds(SpiceKbdInstance *sin)
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH 1/2] hw: cannot_instantiate_with_device_add_yet due to pointer props

2013-12-16 Thread Markus Armbruster
Peter Maydell peter.mayd...@linaro.org writes:

 On 16 December 2013 08:48, Markus Armbruster arm...@redhat.com wrote:
 Peter Maydell peter.mayd...@linaro.org writes:
 I kind of think this whole thing is backwards anyway:
 we should really say the user can only instantiate
 devices via command line or monitor that are specifically
 intended to be hot-pluggable, rather than having an
 enormous list of devices we flag as not instantiable
 by the user. Even if someday we manage to make it technically
 possible to instantiate an omap_i2c device (say) from the
 command line, it will still be a completely bizarre thing to do
 because it's only intended to work as a part of the omap SoC.

 Hot-pluggable doesn't apply here.  There are plenty of devices that
 can only be cold-plugged, yet are absolutely meant to be user-pluggable.
 Real ISA cards, for instance.

 Mmm. Just plain pluggable would be more what I meant:
 modelling something that on real hardware is really a
 simple pluggable socket.

That makes sense to me.

 However, the current code lets users plug absolutely everything, even
 stuff that is known not to work.  The code still has the remnants of a
 mechanism meant to protect users from known-not-to-work plugs, but it
 got broken some time ago.  My Clean up and fix no_user series fixes
 that regression in a way that's hopefully agreeable with Anthony, who
 has been quite insistent on letting device_add plug more rather than
 less.  This series merely patches some holes on top.

 The list of non-pluggable devices may be larger than the list of
 pluggable ones, but: I count just 48 instances of
 cannot_instantiate_with_device_add_yet = true.  I doubt marking
 devices that can be plugged instead of the ones than can't be would take
 fewer marks.  Moreover, each one comes with a comment explaining *why*
 the device cannot be plugged.  Sure nice to have when such a why goes
 away.  Some of them are expected to go away eventually.

 I would expect 99% of actually pluggable devices to be pluggable
 because they're using a pluggable bus: ISA, PCI, USB, ...

 Anyway, I don't actively object to this series. I just think
 Anthony's going in the wrong direction which is why I haven't
 been particularly eager to actively mark it as reviewed-by me
 either...

Understandable :)

Thanks!



[Qemu-devel] [PATCH 26/42] input: mouse: switch vnc ui to new core

2013-12-16 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/vnc.c | 46 ++
 ui/vnc.h |  1 +
 2 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index 4658559..7dfc94a 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -1484,7 +1484,7 @@ static void client_cut_text(VncState *vs, size_t len, 
uint8_t *text)
 static void check_pointer_type_change(Notifier *notifier, void *data)
 {
 VncState *vs = container_of(notifier, VncState, mouse_mode_notifier);
-int absolute = kbd_mouse_is_absolute();
+int absolute = qemu_input_is_absolute();
 
 if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE)  vs-absolute 
!= absolute) {
 vnc_lock_output(vs);
@@ -1503,39 +1503,37 @@ static void check_pointer_type_change(Notifier 
*notifier, void *data)
 
 static void pointer_event(VncState *vs, int button_mask, int x, int y)
 {
-int buttons = 0;
-int dz = 0;
+static uint32_t bmap[INPUT_BUTTON_MAX] = {
+[INPUT_BUTTON_LEFT]   = 0x01,
+[INPUT_BUTTON_MIDDLE] = 0x02,
+[INPUT_BUTTON_RIGHT]  = 0x04,
+[INPUT_BUTTON_WHEEL_UP]   = 0x08,
+[INPUT_BUTTON_WHEEL_DOWN] = 0x10,
+};
+QemuConsole *con = vs-vd-dcl.con;
 int width = surface_width(vs-vd-ds);
 int height = surface_height(vs-vd-ds);
 
-if (button_mask  0x01)
-buttons |= MOUSE_EVENT_LBUTTON;
-if (button_mask  0x02)
-buttons |= MOUSE_EVENT_MBUTTON;
-if (button_mask  0x04)
-buttons |= MOUSE_EVENT_RBUTTON;
-if (button_mask  0x08)
-dz = -1;
-if (button_mask  0x10)
-dz = 1;
+if (vs-last_bmask != button_mask) {
+qemu_input_update_buttons(con, bmap, vs-last_bmask, button_mask);
+vs-last_bmask = button_mask;
+}
 
 if (vs-absolute) {
-kbd_mouse_event(width   1 ? x * 0x7FFF / (width  - 1) : 0x4000,
-height  1 ? y * 0x7FFF / (height - 1) : 0x4000,
-dz, buttons);
+qemu_input_queue_abs(con, INPUT_AXIS_X, x, width);
+qemu_input_queue_abs(con, INPUT_AXIS_Y, y, height);
 } else if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE)) {
-x -= 0x7FFF;
-y -= 0x7FFF;
-
-kbd_mouse_event(x, y, dz, buttons);
+qemu_input_queue_rel(con, INPUT_AXIS_X, x - 0x7FFF);
+qemu_input_queue_rel(con, INPUT_AXIS_Y, y - 0x7FFF);
 } else {
-if (vs-last_x != -1)
-kbd_mouse_event(x - vs-last_x,
-y - vs-last_y,
-dz, buttons);
+if (vs-last_x != -1) {
+qemu_input_queue_rel(con, INPUT_AXIS_X, x - vs-last_x);
+qemu_input_queue_rel(con, INPUT_AXIS_Y, y - vs-last_y);
+}
 vs-last_x = x;
 vs-last_y = y;
 }
+qemu_input_event_sync();
 }
 
 static void reset_keys(VncState *vs)
diff --git a/ui/vnc.h b/ui/vnc.h
index 6e99213..e63c142 100644
--- a/ui/vnc.h
+++ b/ui/vnc.h
@@ -257,6 +257,7 @@ struct VncState
 int absolute;
 int last_x;
 int last_y;
+uint32_t last_bmask;
 int client_width;
 int client_height;
 VncShareMode share_mode;
-- 
1.8.3.1




  1   2   3   >