Re: [Qemu-devel] [PATCH 07/16] qdev: allow reusing get/set for legacy property

2012-02-03 Thread Paolo Bonzini

On 02/02/2012 11:38 PM, Andreas Färber wrote:

Am 02.02.2012 17:45, schrieb Paolo Bonzini:

In some cases, a legacy property does need a special print method
but not a special parse method.  In this case, we can reuse the get/set
from the static (non-legacy) property.

If neither parse nor print is needed, though, do not register the
legacy property at all.  The previous patch ensures that the right
fallback will be used.

Signed-off-by: Paolo Bonzini
---
  hw/qdev-monitor.c|5 ++---
  hw/qdev-properties.c |6 +++---
  hw/qdev.c|   11 +++
  3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
index 64505b4..e21bd50 100644
--- a/hw/qdev-monitor.c
+++ b/hw/qdev-monitor.c
@@ -489,8 +489,8 @@ static void qdev_print_props(Monitor *mon, DeviceState 
*dev, Property *props,
  {
  if (!props)
  return;
-while (props->name) {
-Error *err;
+for (; props->name; props++) {
+Error *err = NULL;


Do either of these fix a bug? Should be mentioned or avoided. [...]

Bugfix?


Yes, I squashed these in the wrong patch, thanks for catching it.

Paolo



[Qemu-devel] [PATCH v12 00/10] ARM: Samsung Exynos4210-based boards support.

2012-02-03 Thread Evgeny Voevodin
This set of patches adds support for Samsung Exynos4210-based boards NURI and 
SMDKC210.
Tested on Linux kernel v3.x series.

Usage:
Exynos4210 SOC boards are modelled to run two CPU cores..
Linux kernel v3.x configured with exynos4_defconfig can be used for boards 
models testing with rootfs
on initrd.

To enable support of framebuffer in kernel, enable Samsung S3C framebuffer 
driver in kernel configuration.
Note: at present time (26.01.2012) Samsung S3C framebuffer support in 
mainline kernel is broken. This
problem will be solved soon by Samsung kernel developers. People interested 
in enabling framebuffer right
now can patch Linux kernel source files a bit to fix S3C framebuffer 
support:
- in array init_clocks_off (file arch/arm/mach-exynos/clock.c) for a member 
with .devname = "exynos4-fb.0"
  replace .name from "fimd" to "lcd";
- for framebuffer support on nuri board you need to additionally change 
file arch/arm/mach-exynos/common.c:
  add include file
  "#include "
  and add string
  init_consistent_dma_size(SZ_2M + SZ_4M);
  at the very beginning of function "void __init exynos4_map_io(void)".

To enable support of ethernet on smdkc210 board, enable SMSC LAN911x/LAN921x 
families
embedded ethernet driver in Linux kernel configuration file.
Note: NURI board does not have ethernet adapter and currently has no net 
support.


Example usage:
Boot smdkc210 board with root filesystem on NFS disk.
# qemu-system-arm -kernel ./zImage -append "ip=dhcp root=/dev/nfs 
nfsroot=10.0.2.2:/srv/nfs/ rw rootwait" -M smdkc210

Boot smdkc210 board with root filesystem on NFS disk and serial port #0 
redirected to terminal
# qemu-system-arm -kernel ./zImage -append "console=ttySAC0,115200n8 ip=dhcp 
root=/dev/nfs nfsroot=10.0.2.2:/srv/nfs/ rw " -serial stdio -M smdkc210

Boot NURI with rootfs on inird and serial port #0 redirected to terminal
# qemu-system-arm -kernel ./zImage -append "console=ttySAC0,115200n8 
root=/dev/ram rw " -serial stdio -M nuri -initrd ./rootfs.ext2


Changelog:
 v11->v12
   Hardcoded amount of SOC's CPU cores to two.
   Updated ./MAINTAINERS.
   Rebased on current master.
   Removed "Reviewed-by:" from IRQ, PWM, MCT since following changes:
 - hw/exynos4210_gic.c: Spaces, CamelCase fixes, definitions converted to enum
 - hw/exynos4210_pwm.c, hw/exynos4210_mct.c: CamelCase fixes
 - hw/exynos4210_combiner.c: CamelCase fixes, removed useless structure 
definition
 - hw/exynos4_boards.c: Slightly reorganized machines, added warning message if 
smp_cpus != 2
 v10->v11
 - rebased and converted to QOM: hw/exynos4210_combiner.c, hw/exynos4210_gic.c, 
hw/exynos4210_fimd.c, hw/exynos4210_mct.c, hw/exynos4210_pmu.c,
   hw/exynos4210_pwm.c, hw/exynos4210_uart.c.
   Also we have removed "Reviewed-by:" from those patches touched by conversion 
to QOM.
 v9->v10
 - hw/lan9118.c: fixed migration-breaking bug in previous patch version;
 - hw/exynos4210_pmu.c: we do not waste space for non-existing registers in PMU 
state anymore;
non-existing registers are now RAZ/WI;
added vmstate structure;

 v8->v9
 - exynos4210.c: secondary cpu bootloader memory region allocation is removed 
(it resides in already allocated IROM),
 removed hack memory region for secondary CPU boot loader (PMU 
device added).
 added l2x0 cache controller
 - exynos4210_pmu.c: PMU registers modelling device added to emulation. It is 
needed since PMU contains 
 INFORM5 register which is used to boot the secondary CPUs.
 - exynos4_boards.c: indentation fix
 - exynos4210_uart.c: indentation fix, BREAK event handling code added, fixed 
size of allocated registers region
 - exynos4210_gic.c: number of IRQs passed to gic_init() due to last mainline 
update.
 - lan9118.: added VMSTATE fields due to last mainline update.
 v7->v8
 - exynos4_boards.c: lack of spaces fix
 - exynos4210_gic.c: lack of spaces fix
 - exynos4210_combiner.c: lack of spaces fix
 - exynos4210_uart.c: lack of spaces fix, indentation fix
 - exynos4210_mct.c: ULL suffix fix
 v6->v7
 - exynos4210_pwm.c: added usage of "ptimer.h"
 - exynos4210_mct.c: added usage of "ptimer.h"
 v5->v6
 - arm_boot.c, vexpress.c, realview.c: board should specify smp_bootreg_addr if 
its ncpu > 1
 - patch order changed, "boot secondary CPU" is included in "exynos boards" 
patch.
 - exynos4210_mct.c: usage of UINTX_MAX, removed excessive property list, fixed 
indentation,
 fixed comments
 - exynos4210_pwm.c: spaces and brakcets in macros, removed excessive property 
list,
 fixed indentation,
 - exynos4210_combiner.c: removed excessive reset, fixed indentation, fixed 
comments
 - exynos4210_gic.c: fixed indentation, fixed syntax
 - exynos4210_uart.c: fixed indentation, fixed syntax
 - exynos4210.c: fixed comments
 - Makefile.target: removed "\"
 - hw/exynos4210_fimd.c: rebased against current master: all manipulation 

[Qemu-devel] [PATCH v12 06/10] ARM: exynos4210: MCT support.

2012-02-03 Thread Evgeny Voevodin
Signed-off-by: Evgeny Voevodin 
---
 Makefile.target |2 +-
 hw/exynos4210.c |   19 +
 hw/exynos4210_mct.c | 1486 +++
 3 files changed, 1506 insertions(+), 1 deletions(-)
 create mode 100644 hw/exynos4210_mct.c

diff --git a/Makefile.target b/Makefile.target
index 5803072..61727bf 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -340,7 +340,7 @@ obj-arm-y += versatile_pci.o
 obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o
 obj-arm-y += exynos4210_gic.o exynos4210_combiner.o exynos4210.o
 obj-arm-y += exynos4_boards.o exynos4210_uart.o exynos4210_pwm.o
-obj-arm-y += exynos4210_pmu.o
+obj-arm-y += exynos4210_pmu.o exynos4210_mct.o
 obj-arm-y += arm_l2x0.o
 obj-arm-y += arm_mptimer.o
 obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o
diff --git a/hw/exynos4210.c b/hw/exynos4210.c
index cc77905..9563fcc 100644
--- a/hw/exynos4210.c
+++ b/hw/exynos4210.c
@@ -32,6 +32,9 @@
 /* PWM */
 #define EXYNOS4210_PWM_BASE_ADDR   0x139D
 
+/* MCT */
+#define EXYNOS4210_MCT_BASE_ADDR   0x1005
+
 /* UART's definitions */
 #define EXYNOS4210_UART0_BASE_ADDR 0x1380
 #define EXYNOS4210_UART1_BASE_ADDR 0x1381
@@ -222,6 +225,22 @@ Exynos4210State *exynos4210_init(MemoryRegion *system_mem,
 irq_table[exynos4210_get_irq(22, 4)],
 NULL);
 
+/* Multi Core Timer */
+dev = qdev_create(NULL, "exynos4210.mct");
+qdev_init_nofail(dev);
+busdev = sysbus_from_qdev(dev);
+for (n = 0; n < 4; n++) {
+/* Connect global timer interrupts to Combiner gpio_in */
+sysbus_connect_irq(busdev, n,
+irq_table[exynos4210_get_irq(1, 4 + n)]);
+}
+/* Connect local timer interrupts to Combiner gpio_in */
+sysbus_connect_irq(busdev, 4,
+irq_table[exynos4210_get_irq(51, 0)]);
+sysbus_connect_irq(busdev, 5,
+irq_table[exynos4210_get_irq(35, 3)]);
+sysbus_mmio_map(busdev, 0, EXYNOS4210_MCT_BASE_ADDR);
+
 /*** UARTs ***/
 exynos4210_uart_create(EXYNOS4210_UART0_BASE_ADDR,
EXYNOS4210_UART0_FIFO_SIZE, 0, NULL,
diff --git a/hw/exynos4210_mct.c b/hw/exynos4210_mct.c
new file mode 100644
index 000..bc5c11c
--- /dev/null
+++ b/hw/exynos4210_mct.c
@@ -0,0 +1,1486 @@
+/*
+ * Samsung exynos4210 Multi Core timer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
+ * All rights reserved.
+ *
+ * Evgeny Voevodin 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+/*
+ * Global Timer:
+ *
+ * Consists of two timers. First represents Free Running Counter and second
+ * is used to measure interval from FRC to nearest comparator.
+ *
+ *0   
UINT64_MAX
+ *|  timer0 |
+ *| <-- |
+ *| frc---> |
+ *|__|__|
+ *CMP0  CMP1 CMP2|   CMP3
+ * __||_
+ * | timer1 |
+ * | -> |
+ *frc  CMPx
+ *
+ * Problem: when implementing global timer as is, overflow arises.
+ * next_time = cur_time + period * count;
+ * period and count are 64 bits width.
+ * Lets arm timer for MCT_GT_COUNTER_STEP count and update internal G_CNT
+ * register during each event.
+ *
+ * Problem: both timers need to be implemented using MCT_XT_COUNTER_STEP 
because
+ * local timer contains two counters: TCNT and ICNT. TCNT == 0 -> ICNT--.
+ * IRQ is generated when ICNT riches zero. Implementation where TCNT == 0
+ * generates IRQs suffers from too frequently events. Better to have one
+ * uint64_t counter equal to TCNT*ICNT and arm ptimer.c for a 
minimum(TCNT*ICNT,
+ * MCT_GT_COUNTER_STEP); (yes, if target tunes ICNT * TCNT to be too low 
values,
+ * there is no way to avoid frequently events).
+ */
+
+#include "sysbus.h"
+#include "qemu-timer.h"
+#include "qemu-common.h"
+#include "ptim

[Qemu-devel] [PATCH v12 08/10] hw/exynos4210.c: Add LAN support for SMDKC210.

2012-02-03 Thread Evgeny Voevodin
SMDKC210 uses lan9215 chip, but lan9118 in 16-bit mode seems to
be enough.

Signed-off-by: Evgeny Voevodin 
Reviewed-by: Peter Maydell 
---
 hw/exynos4_boards.c |   27 +--
 1 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/hw/exynos4_boards.c b/hw/exynos4_boards.c
index 767dc45..329efbe 100644
--- a/hw/exynos4_boards.c
+++ b/hw/exynos4_boards.c
@@ -23,6 +23,7 @@
 
 #include "sysemu.h"
 #include "sysbus.h"
+#include "net.h"
 #include "arm-misc.h"
 #include "exec-memory.h"
 #include "exynos4210.h"
@@ -42,6 +43,8 @@
 #define  PRINT_DEBUG(fmt, args...)  do {} while (0)
 #endif
 
+#define SMDK_LAN9118_BASE_ADDR  0x0500
+
 typedef enum Exynos4BoardType {
 EXYNOS4_BOARD_NURI,
 EXYNOS4_BOARD_SMDKC210,
@@ -71,6 +74,24 @@ static struct arm_boot_info exynos4_board_binfo = {
 
 static QEMUMachine exynos4_machines[EXYNOS4_NUM_OF_BOARDS];
 
+static void lan9215_init(uint32_t base, qemu_irq irq)
+{
+DeviceState *dev;
+SysBusDevice *s;
+
+/* This should be a 9215 but the 9118 is close enough */
+if (nd_table[0].vlan) {
+qemu_check_nic_model(&nd_table[0], "lan9118");
+dev = qdev_create(NULL, "lan9118");
+qdev_set_nic_properties(dev, &nd_table[0]);
+qdev_prop_set_uint32(dev, "mode_16bit", 1);
+qdev_init_nofail(dev);
+s = sysbus_from_qdev(dev);
+sysbus_mmio_map(s, 0, base);
+sysbus_connect_irq(s, 0, irq);
+}
+}
+
 static Exynos4210State *exynos4_boards_init_common(
 const char *kernel_filename,
 const char *kernel_cmdline,
@@ -123,9 +144,11 @@ static void smdkc210_init(ram_addr_t ram_size,
 const char *kernel_filename, const char *kernel_cmdline,
 const char *initrd_filename, const char *cpu_model)
 {
-exynos4_boards_init_common(kernel_filename, kernel_cmdline,
-initrd_filename, EXYNOS4_BOARD_SMDKC210);
+Exynos4210State *s = exynos4_boards_init_common(kernel_filename,
+kernel_cmdline, initrd_filename, EXYNOS4_BOARD_SMDKC210);
 
+lan9215_init(SMDK_LAN9118_BASE_ADDR,
+qemu_irq_invert(s->irq_table[exynos4210_get_irq(37, 1)]));
 arm_load_kernel(first_cpu, &exynos4_board_binfo);
 }
 
-- 
1.7.4.1




[Qemu-devel] [PATCH v12 04/10] ARM: exynos4210: PWM support.

2012-02-03 Thread Evgeny Voevodin
Signed-off-by: Evgeny Voevodin 
---
 Makefile.target |2 +-
 hw/exynos4210.c |   12 ++
 hw/exynos4210_pwm.c |  420 +++
 3 files changed, 433 insertions(+), 1 deletions(-)
 create mode 100644 hw/exynos4210_pwm.c

diff --git a/Makefile.target b/Makefile.target
index 4291619..5f0726d 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -339,7 +339,7 @@ obj-arm-y += arm_boot.o pl011.o pl031.o pl050.o pl080.o 
pl110.o pl181.o pl190.o
 obj-arm-y += versatile_pci.o
 obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o
 obj-arm-y += exynos4210_gic.o exynos4210_combiner.o exynos4210.o
-obj-arm-y += exynos4_boards.o exynos4210_uart.o
+obj-arm-y += exynos4_boards.o exynos4210_uart.o exynos4210_pwm.o
 obj-arm-y += arm_l2x0.o
 obj-arm-y += arm_mptimer.o
 obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o
diff --git a/hw/exynos4210.c b/hw/exynos4210.c
index 916342c..ce50a09 100644
--- a/hw/exynos4210.c
+++ b/hw/exynos4210.c
@@ -29,6 +29,9 @@
 
 #define EXYNOS4210_CHIPID_ADDR 0x1000
 
+/* PWM */
+#define EXYNOS4210_PWM_BASE_ADDR   0x139D
+
 /* UART's definitions */
 #define EXYNOS4210_UART0_BASE_ADDR 0x1380
 #define EXYNOS4210_UART1_BASE_ADDR 0x1381
@@ -201,6 +204,15 @@ Exynos4210State *exynos4210_init(MemoryRegion *system_mem,
 memory_region_add_subregion(system_mem, EXYNOS4210_DRAM0_BASE_ADDR,
 &s->dram0_mem);
 
+/* PWM */
+sysbus_create_varargs("exynos4210.pwm", EXYNOS4210_PWM_BASE_ADDR,
+irq_table[exynos4210_get_irq(22, 0)],
+irq_table[exynos4210_get_irq(22, 1)],
+irq_table[exynos4210_get_irq(22, 2)],
+irq_table[exynos4210_get_irq(22, 3)],
+irq_table[exynos4210_get_irq(22, 4)],
+NULL);
+
 /*** UARTs ***/
 exynos4210_uart_create(EXYNOS4210_UART0_BASE_ADDR,
EXYNOS4210_UART0_FIFO_SIZE, 0, NULL,
diff --git a/hw/exynos4210_pwm.c b/hw/exynos4210_pwm.c
new file mode 100644
index 000..9263555
--- /dev/null
+++ b/hw/exynos4210_pwm.c
@@ -0,0 +1,420 @@
+/*
+ * Samsung exynos4210 Pulse Width Modulation Timer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
+ * All rights reserved.
+ *
+ * Evgeny Voevodin 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#include "sysbus.h"
+#include "qemu-timer.h"
+#include "qemu-common.h"
+#include "ptimer.h"
+
+#include "exynos4210.h"
+
+//#define DEBUG_PWM
+
+#ifdef DEBUG_PWM
+#define DPRINTF(fmt, ...) \
+do { fprintf(stdout, "PWM: [%24s:%5d] " fmt, __func__, __LINE__, \
+## __VA_ARGS__); } while (0)
+#else
+#define DPRINTF(fmt, ...) do {} while (0)
+#endif
+
+#define EXYNOS4210_PWM_TIMERS_NUM  5
+#define EXYNOS4210_PWM_REG_MEM_SIZE0x50
+
+#define TCFG00x
+#define TCFG10x0004
+#define TCON 0x0008
+#define TCNTB0   0x000C
+#define TCMPB0   0x0010
+#define TCNTO0   0x0014
+#define TCNTB1   0x0018
+#define TCMPB1   0x001C
+#define TCNTO1   0x0020
+#define TCNTB2   0x0024
+#define TCMPB2   0x0028
+#define TCNTO2   0x002C
+#define TCNTB3   0x0030
+#define TCMPB3   0x0034
+#define TCNTO3   0x0038
+#define TCNTB4   0x003C
+#define TCNTO4   0x0040
+#define TINT_CSTAT   0x0044
+
+#define TCNTB(x)(0xC * (x))
+#define TCMPB(x)(0xC * (x) + 1)
+#define TCNTO(x)(0xC * (x) + 2)
+
+#define GET_PRESCALER(reg, x) (((reg) & (0xFF << (8 * (x >> 8 * (x))
+#define GET_DIVIDER(reg, x) (1 << (((reg) & (0xF << (4 * (x >> (4 * (x
+
+/*
+ * Attention! Timer4 doesn't have OUTPUT_INVERTER,
+ * so Auto Reload bit is not accessible by macros!
+ */
+#define TCON_TIMER_BASE(x)  (((x) ? 1 : 0) * 4 + 4 * (x))
+#define TCON_TIMER_START(x) (1 << (TCON_TIMER_BASE(x) + 0))
+#define TCON_TIMER_MANUAL_UPD(x)(1 << (TCON_TIMER_BASE(x) + 1))
+#define TCON_TIMER_OUTPUT_INV(x)(1 << (TCON_TIMER_BASE(x) + 2))
+#define TCON_TIMER_AUTO_RELOAD(x)   (1 << (TCON_TIMER_BASE(x) + 3))
+#define TCON_TIMER4_AUTO_RELOAD (1 << 22)
+
+#define TINT_CSTAT_STATUS(x)(1 << (5 + (x)))
+#define TINT_CSTAT_ENABLE(x)(1 << (x))
+
+/* timer struct */
+typedef struct 

[Qemu-devel] [Bug 924943] Re: usb-host devices given by command line are routed incomplete to the guest

2012-02-03 Thread Erik Rull
update:
it works with the following parameter set:
-usb -device usb-host
but then only USB 1.1 is available (very slow)

it does not work with:
-readconfig ich9-ehci-uhci.cfg -device usb-host,bus=ehci.0
but there I have USB 2.0 and USB 1.1 devices routed perfectly with a good speed 
to the guest at runtime

the .cfg is taken from the docs/ directory
I also tested with ehci-only parameters (no uhci / companion), same effect

And: This seems only to be related to USB 2.0 devices!
I tested both with a USB 1.1 device plugged in before starting the guest and 
there it works perfectly.

it would be really great to find a solution for that

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

Title:
  usb-host devices given by command line are routed incomplete to the
  guest

Status in QEMU:
  New

Bug description:
  affected qemus: qemu-1.0, qemu-kvm-1.0, qemu and qemu-kvm master branches 
(older versions not tested)
  affected guests: linux, windows
  test hardware: standard usb key (or any other piece of USB hardware) that 
works perfectly when plugged in after guest bootup

  Several Sequences have been tested:
  - start qemu with  -readconfig /etc/ich9-ehci-uhci.cfg -device usb-tablet 
-device usb-host,bus=ehci.0
  - start qemu with -readconfig /etc/ich9-ehci-uhci.cfg -device usb-tablet -S 
(to not start up the guest directly) + at the console prompt: "device_add 
usb-host" then "c" to start the guest.

  For the linux guest, I get a usb device listed and detected as /dev/sdb when 
plugging it in at runtime. At startup linux does NOT detect it.
  For the windows guest, I get a usb device listed and detected as "removable 
media" when plugging it in at runtime. At startup Windows does detect 
"something" that is listed in the device manager as Generic Mass Storage 
device, but with a yellow exclamation mark and there is no removable media 
listed in Explorer

  If you need further testings, just let me know.

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



[Qemu-devel] [PATCH v12 05/10] ARM: exynos4210: basic Power Management Unit implementation

2012-02-03 Thread Evgeny Voevodin
From: Maksim Kozlov 

Patch adds basic model for Exynos4210 SoC PMU.
This model implements PMU registers just as a bulk of memory. Currently,
the only reason this device exists is that secondary CPU boot loader
uses PMU INFORM5 register as a holding pen.

Signed-off-by: Maksim Kozlov 
Signed-off-by: Evgeny Voevodin 
---
 Makefile.target |1 +
 hw/exynos4210.c |9 +
 hw/exynos4210_pmu.c |  497 +++
 3 files changed, 507 insertions(+), 0 deletions(-)
 create mode 100644 hw/exynos4210_pmu.c

diff --git a/Makefile.target b/Makefile.target
index 5f0726d..5803072 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -340,6 +340,7 @@ obj-arm-y += versatile_pci.o
 obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o
 obj-arm-y += exynos4210_gic.o exynos4210_combiner.o exynos4210.o
 obj-arm-y += exynos4_boards.o exynos4210_uart.o exynos4210_pwm.o
+obj-arm-y += exynos4210_pmu.o
 obj-arm-y += arm_l2x0.o
 obj-arm-y += arm_mptimer.o
 obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o
diff --git a/hw/exynos4210.c b/hw/exynos4210.c
index ce50a09..cc77905 100644
--- a/hw/exynos4210.c
+++ b/hw/exynos4210.c
@@ -52,6 +52,9 @@
 #define EXYNOS4210_EXT_COMBINER_BASE_ADDR   0x1044
 #define EXYNOS4210_INT_COMBINER_BASE_ADDR   0x10448000
 
+/* PMU SFR base address */
+#define EXYNOS4210_PMU_BASE_ADDR0x1002
+
 static uint8_t chipid_and_omr[] = { 0x11, 0x02, 0x21, 0x43,
 0x09, 0x00, 0x00, 0x00 };
 
@@ -204,6 +207,12 @@ Exynos4210State *exynos4210_init(MemoryRegion *system_mem,
 memory_region_add_subregion(system_mem, EXYNOS4210_DRAM0_BASE_ADDR,
 &s->dram0_mem);
 
+   /* PMU.
+* The only reason of existence at the moment is that secondary CPU boot
+* loader uses PMU INFORM5 register as a holding pen.
+*/
+sysbus_create_simple("exynos4210.pmu", EXYNOS4210_PMU_BASE_ADDR, NULL);
+
 /* PWM */
 sysbus_create_varargs("exynos4210.pwm", EXYNOS4210_PWM_BASE_ADDR,
 irq_table[exynos4210_get_irq(22, 0)],
diff --git a/hw/exynos4210_pmu.c b/hw/exynos4210_pmu.c
new file mode 100644
index 000..8262685
--- /dev/null
+++ b/hw/exynos4210_pmu.c
@@ -0,0 +1,497 @@
+/*
+ *  Exynos4210 Power Management Unit (PMU) Emulation
+ *
+ *  Copyright (C) 2011 Samsung Electronics Co Ltd.
+ *Maksim Kozlov 
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms of the GNU General Public License as published by the
+ *  Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful, but WITHOUT
+ *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ *  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ *  for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, see .
+ */
+
+/*
+ * This model implements PMU registers just as a bulk of memory. Currently,
+ * the only reason this device exists is that secondary CPU boot loader
+ * uses PMU INFORM5 register as a holding pen.
+ */
+
+#include "sysbus.h"
+
+#ifndef DEBUG_PMU
+#define DEBUG_PMU   0
+#endif
+
+#ifndef DEBUG_PMU_EXTEND
+#define DEBUG_PMU_EXTEND0
+#endif
+
+#if DEBUG_PMU
+#define  PRINT_DEBUG(fmt, args...)  \
+do { \
+fprintf(stderr, "  [%s:%d]   "fmt, __func__, __LINE__, ##args); \
+} while (0)
+
+#if DEBUG_PMU_EXTEND
+#define  PRINT_DEBUG_EXTEND(fmt, args...) \
+do { \
+fprintf(stderr, "  [%s:%d]   "fmt, __func__, __LINE__, ##args); \
+} while (0)
+#else
+#define  PRINT_DEBUG_EXTEND(fmt, args...)  do {} while (0)
+#endif /* EXTEND */
+
+#else
+#define  PRINT_DEBUG(fmt, args...)   do {} while (0)
+#define  PRINT_DEBUG_EXTEND(fmt, args...)  do {} while (0)
+#endif
+
+/*
+ *  Offsets for PMU registers
+ */
+#define OM_STAT  0x /* OM status register */
+#define RTC_CLKO_SEL 0x000C /* Controls RTCCLKOUT */
+#define GNSS_RTC_OUT_CTRL0x0010 /* Controls GNSS_RTC_OUT */
+/* Decides whether system-level low-power mode is used. */
+#define SYSTEM_POWER_DOWN_CTRL   0x0200
+/* Sets control options for CENTRAL_SEQ */
+#define SYSTEM_POWER_DOWN_OPTION 0x0208
+#define SWRESET  0x0400 /* Generate software reset */
+#define RST_STAT 0x0404 /* Reset status register */
+#define WAKEUP_STAT  0x0600 /* Wakeup status register  */
+#define EINT_WAKEUP_MASK 0x0604 /* Configure External INTerrupt mask */
+#define WAKEUP_MASK  0x0608 /* Configure wakeup source mask */
+#define HDMI_PHY_CONTROL 0x0700 /* HDMI PHY control register */
+#define USBDEVICE_PHY_CONTROL0x0704 /* USB Device PHY control register */
+#define USBHOST_PHY_CONTROL  

[Qemu-devel] [Bug 924943] Re: usb-host devices given by command line are routed incomplete to the guest

2012-02-03 Thread Erik Rull
update:

Seems to affect only USB 2.0 devices and if USB 2.0 (EHCI) is enabled.

If there is only -usb -device usb-host added, it works for both USB 2.0 and USB 
1.1 but extremely slow due to the missing USB 2.0 layer
If the command line is given as reported above, it works for USB 1.1 devices, 
too! USB 2.0 devices show the problems as reported.

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

Title:
  usb-host devices given by command line are routed incomplete to the
  guest

Status in QEMU:
  New

Bug description:
  affected qemus: qemu-1.0, qemu-kvm-1.0, qemu and qemu-kvm master branches 
(older versions not tested)
  affected guests: linux, windows
  test hardware: standard usb key (or any other piece of USB hardware) that 
works perfectly when plugged in after guest bootup

  Several Sequences have been tested:
  - start qemu with  -readconfig /etc/ich9-ehci-uhci.cfg -device usb-tablet 
-device usb-host,bus=ehci.0
  - start qemu with -readconfig /etc/ich9-ehci-uhci.cfg -device usb-tablet -S 
(to not start up the guest directly) + at the console prompt: "device_add 
usb-host" then "c" to start the guest.

  For the linux guest, I get a usb device listed and detected as /dev/sdb when 
plugging it in at runtime. At startup linux does NOT detect it.
  For the windows guest, I get a usb device listed and detected as "removable 
media" when plugging it in at runtime. At startup Windows does detect 
"something" that is listed in the device manager as Generic Mass Storage 
device, but with a yellow exclamation mark and there is no removable media 
listed in Explorer

  If you need further testings, just let me know.

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



[Qemu-devel] [PATCH v12 03/10] ARM: exynos4210: UART support

2012-02-03 Thread Evgeny Voevodin
From: Maksim Kozlov 

Add basic support of exynos4210 UART

Signed-off-by: Maksim Kozlov 
Signed-off-by: Evgeny Voevodin 
Reviewed-by: Peter Maydell 
---
 Makefile.target  |2 +-
 hw/exynos4210.c  |   29 +++
 hw/exynos4210.h  |9 +
 hw/exynos4210_uart.c |  670 ++
 4 files changed, 709 insertions(+), 1 deletions(-)
 create mode 100644 hw/exynos4210_uart.c

diff --git a/Makefile.target b/Makefile.target
index 93eb7d6..4291619 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -339,7 +339,7 @@ obj-arm-y += arm_boot.o pl011.o pl031.o pl050.o pl080.o 
pl110.o pl181.o pl190.o
 obj-arm-y += versatile_pci.o
 obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o
 obj-arm-y += exynos4210_gic.o exynos4210_combiner.o exynos4210.o
-obj-arm-y += exynos4_boards.o
+obj-arm-y += exynos4_boards.o exynos4210_uart.o
 obj-arm-y += arm_l2x0.o
 obj-arm-y += arm_mptimer.o
 obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o
diff --git a/hw/exynos4210.c b/hw/exynos4210.c
index 95c2d03..916342c 100644
--- a/hw/exynos4210.c
+++ b/hw/exynos4210.c
@@ -29,6 +29,18 @@
 
 #define EXYNOS4210_CHIPID_ADDR 0x1000
 
+/* UART's definitions */
+#define EXYNOS4210_UART0_BASE_ADDR 0x1380
+#define EXYNOS4210_UART1_BASE_ADDR 0x1381
+#define EXYNOS4210_UART2_BASE_ADDR 0x1382
+#define EXYNOS4210_UART3_BASE_ADDR 0x1383
+#define EXYNOS4210_UART0_FIFO_SIZE 256
+#define EXYNOS4210_UART1_FIFO_SIZE 64
+#define EXYNOS4210_UART2_FIFO_SIZE 16
+#define EXYNOS4210_UART3_FIFO_SIZE 16
+/* Interrupt Group of External Interrupt Combiner for UART */
+#define EXYNOS4210_UART_INT_GRP26
+
 /* External GIC */
 #define EXYNOS4210_EXT_GIC_CPU_BASE_ADDR0x1048
 #define EXYNOS4210_EXT_GIC_DIST_BASE_ADDR   0x1049
@@ -189,5 +201,22 @@ Exynos4210State *exynos4210_init(MemoryRegion *system_mem,
 memory_region_add_subregion(system_mem, EXYNOS4210_DRAM0_BASE_ADDR,
 &s->dram0_mem);
 
+/*** UARTs ***/
+exynos4210_uart_create(EXYNOS4210_UART0_BASE_ADDR,
+   EXYNOS4210_UART0_FIFO_SIZE, 0, NULL,
+irq_table[exynos4210_get_irq(EXYNOS4210_UART_INT_GRP, 0)]);
+
+exynos4210_uart_create(EXYNOS4210_UART1_BASE_ADDR,
+   EXYNOS4210_UART1_FIFO_SIZE, 1, NULL,
+irq_table[exynos4210_get_irq(EXYNOS4210_UART_INT_GRP, 1)]);
+
+exynos4210_uart_create(EXYNOS4210_UART2_BASE_ADDR,
+   EXYNOS4210_UART2_FIFO_SIZE, 2, NULL,
+irq_table[exynos4210_get_irq(EXYNOS4210_UART_INT_GRP, 2)]);
+
+exynos4210_uart_create(EXYNOS4210_UART3_BASE_ADDR,
+   EXYNOS4210_UART3_FIFO_SIZE, 3, NULL,
+irq_table[exynos4210_get_irq(EXYNOS4210_UART_INT_GRP, 3)]);
+
 return s;
 }
diff --git a/hw/exynos4210.h b/hw/exynos4210.h
index 0026a52..e7522f8 100644
--- a/hw/exynos4210.h
+++ b/hw/exynos4210.h
@@ -119,4 +119,13 @@ uint32_t exynos4210_get_irq(uint32_t grp, uint32_t bit);
 void exynos4210_combiner_get_gpioin(Exynos4210Irq *irqs, DeviceState *dev,
 int ext);
 
+/*
+ * exynos4210 UART
+ */
+DeviceState *exynos4210_uart_create(target_phys_addr_t addr,
+int fifo_size,
+int channel,
+CharDriverState *chr,
+qemu_irq irq);
+
 #endif /* EXYNOS4210_H_ */
diff --git a/hw/exynos4210_uart.c b/hw/exynos4210_uart.c
new file mode 100644
index 000..e3d5d0f
--- /dev/null
+++ b/hw/exynos4210_uart.c
@@ -0,0 +1,670 @@
+/*
+ *  Exynos4210 UART Emulation
+ *
+ *  Copyright (C) 2011 Samsung Electronics Co Ltd.
+ *Maksim Kozlov, 
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms of the GNU General Public License as published by the
+ *  Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful, but WITHOUT
+ *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ *  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ *  for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, see .
+ *
+ */
+
+#include "sysbus.h"
+#include "sysemu.h"
+#include "qemu-char.h"
+
+#include "exynos4210.h"
+
+#undef DEBUG_UART
+#undef DEBUG_UART_EXTEND
+#undef DEBUG_IRQ
+#undef DEBUG_Rx_DATA
+#undef DEBUG_Tx_DATA
+
+#define DEBUG_UART0
+#define DEBUG_UART_EXTEND 0
+#define DEBUG_IRQ 0
+#define DEBUG_Rx_DATA 0
+#define DEBUG_Tx_DATA 0
+
+#if DEBUG_UART
+#define  PRINT_DEBUG(fmt, args...)  \
+do { \
+fprintf(stderr, "  [%s:%d]   "fmt, __func__, __LINE__, 

[Qemu-devel] [PATCH v12 02/10] ARM: Samsung exynos4210-based boards emulation

2012-02-03 Thread Evgeny Voevodin
Add initial support of NURI and SMDKC210 boards

Signed-off-by: Evgeny Voevodin 
---
 Makefile.target |3 +-
 hw/exynos4210.c |  193 +++
 hw/exynos4210.h |   40 +++
 hw/exynos4_boards.c |  153 
 4 files changed, 388 insertions(+), 1 deletions(-)
 create mode 100644 hw/exynos4210.c
 create mode 100644 hw/exynos4_boards.c

diff --git a/Makefile.target b/Makefile.target
index 1b17f15..93eb7d6 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -338,7 +338,8 @@ obj-arm-y = integratorcp.o versatilepb.o arm_pic.o 
arm_timer.o
 obj-arm-y += arm_boot.o pl011.o pl031.o pl050.o pl080.o pl110.o pl181.o pl190.o
 obj-arm-y += versatile_pci.o
 obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o
-obj-arm-y += exynos4210_gic.o exynos4210_combiner.o
+obj-arm-y += exynos4210_gic.o exynos4210_combiner.o exynos4210.o
+obj-arm-y += exynos4_boards.o
 obj-arm-y += arm_l2x0.o
 obj-arm-y += arm_mptimer.o
 obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o
diff --git a/hw/exynos4210.c b/hw/exynos4210.c
new file mode 100644
index 000..95c2d03
--- /dev/null
+++ b/hw/exynos4210.c
@@ -0,0 +1,193 @@
+/*
+ *  Samsung exynos4210 SoC emulation
+ *
+ *  Copyright (c) 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *Maksim Kozlov 
+ *Evgeny Voevodin 
+ *Igor Mitsyanko  
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms of the GNU General Public License as published by the
+ *  Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful, but WITHOUT
+ *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ *  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ *  for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, see .
+ *
+ */
+
+#include "boards.h"
+#include "sysemu.h"
+#include "sysbus.h"
+#include "arm-misc.h"
+#include "exynos4210.h"
+
+#define EXYNOS4210_CHIPID_ADDR 0x1000
+
+/* External GIC */
+#define EXYNOS4210_EXT_GIC_CPU_BASE_ADDR0x1048
+#define EXYNOS4210_EXT_GIC_DIST_BASE_ADDR   0x1049
+
+/* Combiner */
+#define EXYNOS4210_EXT_COMBINER_BASE_ADDR   0x1044
+#define EXYNOS4210_INT_COMBINER_BASE_ADDR   0x10448000
+
+static uint8_t chipid_and_omr[] = { 0x11, 0x02, 0x21, 0x43,
+0x09, 0x00, 0x00, 0x00 };
+
+Exynos4210State *exynos4210_init(MemoryRegion *system_mem,
+unsigned long ram_size)
+{
+qemu_irq cpu_irq[4];
+int n;
+Exynos4210State *s = g_new(Exynos4210State, 1);
+qemu_irq *irq_table;
+qemu_irq *irqp;
+qemu_irq gate_irq[EXYNOS4210_IRQ_GATE_NINPUTS];
+unsigned long mem_size;
+DeviceState *dev;
+SysBusDevice *busdev;
+
+for (n = 0; n < EXYNOS4210_NCPUS; n++) {
+s->env[n] = cpu_init("cortex-a9");
+if (!s->env[n]) {
+fprintf(stderr, "Unable to find CPU %d definition\n", n);
+exit(1);
+}
+/* Create PIC controller for each processor instance */
+irqp = arm_pic_init_cpu(s->env[n]);
+
+/*
+ * Get GICs gpio_in cpu_irq to connect a combiner to them later.
+ * Use only IRQ for a while.
+ */
+cpu_irq[n] = irqp[ARM_PIC_CPU_IRQ];
+}
+
+/*** IRQs ***/
+
+s->irq_table = exynos4210_init_irq(&s->irqs);
+irq_table = s->irq_table;
+
+/* IRQ Gate */
+dev = qdev_create(NULL, "exynos4210.irq_gate");
+qdev_init_nofail(dev);
+/* Get IRQ Gate input in gate_irq */
+for (n = 0; n < EXYNOS4210_IRQ_GATE_NINPUTS; n++) {
+gate_irq[n] = qdev_get_gpio_in(dev, n);
+}
+busdev = sysbus_from_qdev(dev);
+/* Connect IRQ Gate output to cpu_irq */
+for (n = 0; n < EXYNOS4210_NCPUS; n++) {
+sysbus_connect_irq(busdev, n, cpu_irq[n]);
+}
+
+/* Private memory region and Internal GIC */
+dev = qdev_create(NULL, "a9mpcore_priv");
+qdev_prop_set_uint32(dev, "num-cpu", EXYNOS4210_NCPUS);
+qdev_init_nofail(dev);
+busdev = sysbus_from_qdev(dev);
+sysbus_mmio_map(busdev, 0, EXYNOS4210_SMP_PRIVATE_BASE_ADDR);
+for (n = 0; n < EXYNOS4210_NCPUS; n++) {
+sysbus_connect_irq(busdev, n, gate_irq[n * 2]);
+}
+for (n = 0; n < EXYNOS4210_INT_GIC_NIRQ; n++) {
+s->irqs.int_gic_irq[n] = qdev_get_gpio_in(dev, n);
+}
+
+/* Cache controller */
+sysbus_create_simple("l2x0", EXYNOS4210_L2X0_BASE_ADDR, NULL);
+
+/* External GIC */
+dev = qdev_create(NULL, "exynos4210.gic");
+qdev_prop_set_uint32(dev, "num-cpu", EXYNOS4210_NCPUS);
+qdev_init_nofail(dev);
+busdev = sysbus_from_qdev(dev);
+/* Map CPU interface */
+sysbus_mmio_map(busdev, 0

[Qemu-devel] [PATCH v12 07/10] hw/lan9118: Add basic 16-bit mode support.

2012-02-03 Thread Evgeny Voevodin
Signed-off-by: Evgeny Voevodin 
Reviewed-by: Peter Maydell 
---
 hw/lan9118.c |  124 +++---
 1 files changed, 118 insertions(+), 6 deletions(-)

diff --git a/hw/lan9118.c b/hw/lan9118.c
index 3925b04..c95724d 100644
--- a/hw/lan9118.c
+++ b/hw/lan9118.c
@@ -235,11 +235,21 @@ typedef struct {
 int32_t rxp_offset;
 int32_t rxp_size;
 int32_t rxp_pad;
+
+uint32_t write_word_prev_offset;
+uint32_t write_word_n;
+uint16_t write_word_l;
+uint16_t write_word_h;
+uint32_t read_word_prev_offset;
+uint32_t read_word_n;
+uint32_t read_long;
+
+uint32_t mode_16bit;
 } lan9118_state;
 
 static const VMStateDescription vmstate_lan9118 = {
 .name = "lan9118",
-.version_id = 1,
+.version_id = 2,
 .minimum_version_id = 1,
 .fields = (VMStateField[]) {
 VMSTATE_PTIMER(timer, lan9118_state),
@@ -294,6 +304,14 @@ static const VMStateDescription vmstate_lan9118 = {
 VMSTATE_INT32(rxp_offset, lan9118_state),
 VMSTATE_INT32(rxp_size, lan9118_state),
 VMSTATE_INT32(rxp_pad, lan9118_state),
+VMSTATE_UINT32_V(write_word_prev_offset, lan9118_state, 2),
+VMSTATE_UINT32_V(write_word_n, lan9118_state, 2),
+VMSTATE_UINT16_V(write_word_l, lan9118_state, 2),
+VMSTATE_UINT16_V(write_word_h, lan9118_state, 2),
+VMSTATE_UINT32_V(read_word_prev_offset, lan9118_state, 2),
+VMSTATE_UINT32_V(read_word_n, lan9118_state, 2),
+VMSTATE_UINT32_V(read_long, lan9118_state, 2),
+VMSTATE_UINT32_V(mode_16bit, lan9118_state, 2),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -390,7 +408,7 @@ static void lan9118_reset(DeviceState *d)
 s->fifo_int = 0x4800;
 s->rx_cfg = 0;
 s->tx_cfg = 0;
-s->hw_cfg = 0x0005;
+s->hw_cfg = s->mode_16bit ? 0x0005 : 0x00050004;
 s->pmt_ctrl &= 0x45;
 s->gpio_cfg = 0;
 s->txp->fifo_used = 0;
@@ -429,6 +447,9 @@ static void lan9118_reset(DeviceState *d)
 s->mac_mii_data = 0;
 s->mac_flow = 0;
 
+s->read_word_n = 0;
+s->write_word_n = 0;
+
 phy_reset(s);
 
 s->eeprom_writable = 0;
@@ -984,7 +1005,7 @@ static void lan9118_writel(void *opaque, 
target_phys_addr_t offset,
 {
 lan9118_state *s = (lan9118_state *)opaque;
 offset &= 0xff;
-
+
 //DPRINTF("Write reg 0x%02x = 0x%08x\n", (int)offset, val);
 if (offset >= 0x20 && offset < 0x40) {
 /* TX FIFO */
@@ -1034,7 +1055,7 @@ static void lan9118_writel(void *opaque, 
target_phys_addr_t offset,
 /* SRST */
 lan9118_reset(&s->busdev.qdev);
 } else {
-s->hw_cfg = val & 0x003f300;
+s->hw_cfg = (val & 0x003f300) | (s->hw_cfg & 0x4);
 }
 break;
 case CSR_RX_DP_CTRL:
@@ -1113,6 +1134,46 @@ static void lan9118_writel(void *opaque, 
target_phys_addr_t offset,
 lan9118_update(s);
 }
 
+static void lan9118_writew(void *opaque, target_phys_addr_t offset,
+   uint32_t val)
+{
+lan9118_state *s = (lan9118_state *)opaque;
+offset &= 0xff;
+
+if (s->write_word_prev_offset != (offset & ~0x3)) {
+/* New offset, reset word counter */
+s->write_word_n = 0;
+s->write_word_prev_offset = offset & ~0x3;
+}
+
+if (offset & 0x2) {
+s->write_word_h = val;
+} else {
+s->write_word_l = val;
+}
+
+//DPRINTF("Writew reg 0x%02x = 0x%08x\n", (int)offset, val);
+s->write_word_n++;
+if (s->write_word_n == 2) {
+s->write_word_n = 0;
+lan9118_writel(s, offset & ~3, s->write_word_l +
+(s->write_word_h << 16), 4);
+}
+}
+
+static void lan9118_16bit_mode_write(void *opaque, target_phys_addr_t offset,
+ uint64_t val, unsigned size)
+{
+switch (size) {
+case 2:
+return lan9118_writew(opaque, offset, (uint32_t)val);
+case 4:
+return lan9118_writel(opaque, offset, val, size);
+}
+
+hw_error("lan9118_write: Bad size 0x%x\n", size);
+}
+
 static uint64_t lan9118_readl(void *opaque, target_phys_addr_t offset,
   unsigned size)
 {
@@ -1149,7 +1210,7 @@ static uint64_t lan9118_readl(void *opaque, 
target_phys_addr_t offset,
 case CSR_TX_CFG:
 return s->tx_cfg;
 case CSR_HW_CFG:
-return s->hw_cfg | 0x4;
+return s->hw_cfg;
 case CSR_RX_DP_CTRL:
 return 0;
 case CSR_RX_FIFO_INF:
@@ -1187,12 +1248,60 @@ static uint64_t lan9118_readl(void *opaque, 
target_phys_addr_t offset,
 return 0;
 }
 
+static uint32_t lan9118_readw(void *opaque, target_phys_addr_t offset)
+{
+lan9118_state *s = (lan9118_state *)opaque;
+uint32_t val;
+
+if (s->read_word_prev_offset != (offset & ~0x3)) {
+/* New offset, reset word counter */
+s->read_word_n = 0;
+s->read_word_prev_offset = offset & ~0x3;
+}
+
+s->read_word_n++;
+if (s->read_word_n == 1) 

[Qemu-devel] [PATCH v12 01/10] ARM: exynos4210: IRQ subsystem support.

2012-02-03 Thread Evgeny Voevodin
Signed-off-by: Evgeny Voevodin 
---
 Makefile.target  |1 +
 hw/exynos4210.h  |   82 
 hw/exynos4210_combiner.c |  467 ++
 hw/exynos4210_gic.c  |  454 
 4 files changed, 1004 insertions(+), 0 deletions(-)
 create mode 100644 hw/exynos4210.h
 create mode 100644 hw/exynos4210_combiner.c
 create mode 100644 hw/exynos4210_gic.c

diff --git a/Makefile.target b/Makefile.target
index 68481a3..1b17f15 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -338,6 +338,7 @@ obj-arm-y = integratorcp.o versatilepb.o arm_pic.o 
arm_timer.o
 obj-arm-y += arm_boot.o pl011.o pl031.o pl050.o pl080.o pl110.o pl181.o pl190.o
 obj-arm-y += versatile_pci.o
 obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o
+obj-arm-y += exynos4210_gic.o exynos4210_combiner.o
 obj-arm-y += arm_l2x0.o
 obj-arm-y += arm_mptimer.o
 obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o
diff --git a/hw/exynos4210.h b/hw/exynos4210.h
new file mode 100644
index 000..ef4732f
--- /dev/null
+++ b/hw/exynos4210.h
@@ -0,0 +1,82 @@
+/*
+ *  Samsung exynos4210 SoC emulation
+ *
+ *  Copyright (c) 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *Maksim Kozlov 
+ *Evgeny Voevodin 
+ *Igor Mitsyanko 
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms of the GNU General Public License as published by the
+ *  Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful, but WITHOUT
+ *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ *  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ *  for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, see .
+ *
+ */
+
+
+#ifndef EXYNOS4210_H_
+#define EXYNOS4210_H_
+
+#include "qemu-common.h"
+#include "memory.h"
+
+#define EXYNOS4210_NCPUS2
+
+/*
+ * exynos4210 IRQ subsystem stub definitions.
+ */
+#define EXYNOS4210_IRQ_GATE_NINPUTS 8
+
+#define EXYNOS4210_MAX_INT_COMBINER_OUT_IRQ  64
+#define EXYNOS4210_MAX_EXT_COMBINER_OUT_IRQ  16
+#define EXYNOS4210_MAX_INT_COMBINER_IN_IRQ   \
+(EXYNOS4210_MAX_INT_COMBINER_OUT_IRQ * 8)
+#define EXYNOS4210_MAX_EXT_COMBINER_IN_IRQ   \
+(EXYNOS4210_MAX_EXT_COMBINER_OUT_IRQ * 8)
+
+#define EXYNOS4210_COMBINER_GET_IRQ_NUM(grp, bit)  ((grp)*8 + (bit))
+#define EXYNOS4210_COMBINER_GET_GRP_NUM(irq)   ((irq) / 8)
+#define EXYNOS4210_COMBINER_GET_BIT_NUM(irq) \
+((irq) - 8 * EXYNOS4210_COMBINER_GET_GRP_NUM(irq))
+
+/* IRQs number for external and internal GIC */
+#define EXYNOS4210_EXT_GIC_NIRQ (160-32)
+#define EXYNOS4210_INT_GIC_NIRQ 64
+
+typedef struct Exynos4210Irq {
+qemu_irq int_combiner_irq[EXYNOS4210_MAX_INT_COMBINER_IN_IRQ];
+qemu_irq ext_combiner_irq[EXYNOS4210_MAX_EXT_COMBINER_IN_IRQ];
+qemu_irq int_gic_irq[EXYNOS4210_INT_GIC_NIRQ];
+qemu_irq ext_gic_irq[EXYNOS4210_EXT_GIC_NIRQ];
+qemu_irq board_irqs[EXYNOS4210_MAX_INT_COMBINER_IN_IRQ];
+} Exynos4210Irq;
+
+/* Initialize exynos4210 IRQ subsystem stub */
+qemu_irq *exynos4210_init_irq(Exynos4210Irq *env);
+
+/* Initialize board IRQs.
+ * These IRQs contain splitted Int/External Combiner and External Gic IRQs */
+void exynos4210_init_board_irqs(Exynos4210Irq *s);
+
+/* Get IRQ number from exynos4210 IRQ subsystem stub.
+ * To identify IRQ source use internal combiner group and bit number
+ *  grp - group number
+ *  bit - bit number inside group */
+uint32_t exynos4210_get_irq(uint32_t grp, uint32_t bit);
+
+/*
+ * Get Combiner input GPIO into irqs structure
+ */
+void exynos4210_combiner_get_gpioin(Exynos4210Irq *irqs, DeviceState *dev,
+int ext);
+
+#endif /* EXYNOS4210_H_ */
diff --git a/hw/exynos4210_combiner.c b/hw/exynos4210_combiner.c
new file mode 100644
index 000..7734e1e
--- /dev/null
+++ b/hw/exynos4210_combiner.c
@@ -0,0 +1,467 @@
+/*
+ * Samsung exynos4210 Interrupt Combiner
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
+ * All rights reserved.
+ *
+ * Evgeny Voevodin 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+/*

[Qemu-devel] [PATCH v12 10/10] MAINTAINERS: Add maintainers for Exynos SOC.

2012-02-03 Thread Evgeny Voevodin

Signed-off-by: Evgeny Voevodin 
---
 MAINTAINERS |8 
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 173e893..33e480d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -237,6 +237,14 @@ M: Peter Maydell 
 S: Maintained
 F: hw/versatilepb.c
 
+Exynos
+M: Evgeny Voevodin 
+M: Maksim Kozlov 
+M: Igor Mitsyanko 
+M: Dmitry Solodkiy 
+S: Maintained
+F: hw/exynos*
+
 CRIS Machines
 -
 Axis Dev88
-- 
1.7.4.1




[Qemu-devel] [PATCH] memory-region: Report if region is read-only on info mtree

2012-02-03 Thread Jan Kiszka
Helpful to understand guest configurations of things like the i440FX's
PAM.

Signed-off-by: Jan Kiszka 
---
 memory.c |6 --
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/memory.c b/memory.c
index ee4c98a..ea4adda 100644
--- a/memory.c
+++ b/memory.c
@@ -1608,23 +1608,25 @@ static void mtree_print_mr(fprintf_function mon_printf, 
void *f,
 ml->printed = false;
 QTAILQ_INSERT_TAIL(alias_print_queue, ml, queue);
 }
-mon_printf(f, TARGET_FMT_plx "-" TARGET_FMT_plx " (prio %d): alias %s 
@%s "
+mon_printf(f, TARGET_FMT_plx "-" TARGET_FMT_plx " (prio %d, %s): alias 
%s @%s "
TARGET_FMT_plx "-" TARGET_FMT_plx "\n",
base + mr->addr,
base + mr->addr
+ (target_phys_addr_t)int128_get64(mr->size) - 1,
mr->priority,
+   mr->readonly ? "RO" : "RW",
mr->name,
mr->alias->name,
mr->alias_offset,
mr->alias_offset
+ (target_phys_addr_t)int128_get64(mr->size) - 1);
 } else {
-mon_printf(f, TARGET_FMT_plx "-" TARGET_FMT_plx " (prio %d): %s\n",
+mon_printf(f, TARGET_FMT_plx "-" TARGET_FMT_plx " (prio %d, %s): %s\n",
base + mr->addr,
base + mr->addr
+ (target_phys_addr_t)int128_get64(mr->size) - 1,
mr->priority,
+   mr->readonly ? "RO" : "RW",
mr->name);
 }
 
-- 
1.7.3.4



Re: [Qemu-devel] [PATCH 02/16] qom: store object with correct type in interface links

2012-02-03 Thread Paolo Bonzini

On 02/02/2012 06:05 PM, Anthony Liguori wrote:

On 02/02/2012 10:45 AM, Paolo Bonzini wrote:

When a link property's type is an interface, the code expects the
implementation object (not the parent object) to be stored in the
variable. The parent object does not contain the right vtable.

Signed-off-by: Paolo Bonzini
---
qom/object.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/qom/object.c b/qom/object.c
index cd517f6..de6484d 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -749,7 +749,8 @@ static void object_set_link_property(Object *obj,
Visitor *v, void *opaque,
target_type = g_strdup(&type[5]);
target_type[strlen(target_type) - 2] = 0;

- if (object_dynamic_cast(target, target_type)) {
+ target = object_dynamic_cast(target, target_type);
+ if (target) {
object_ref(target);
*child = target;


Very good catch.


But when we implement type-based search for partial paths it will be 
fixed automatically (because object_resolve_path will have to do a 
dynamic cast on its own).  Let's do that instead.


I'll rebase the patch while travelling, since I have to convert 
LostTickPolicy as well.  Let's look at this after the weekend.


Paolo



[Qemu-devel] [PATCH 2/2] linux-user: Add support for prctl PR_GET_NAME and PR_SET_NAME

2012-02-03 Thread Peter Maydell
Add support for the prctl options PR_GET_NAME and PR_SET_NAME,
which take or return a name in a 16 byte buffer pointed to by arg2.

Signed-off-by: Peter Maydell 
---
 linux-user/syscall.c |   24 
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 7851fb5..489a8c2 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6853,6 +6853,30 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 }
 break;
 }
+#ifdef PR_GET_NAME
+case PR_GET_NAME:
+{
+void *name = lock_user(VERIFY_WRITE, arg2, 16, 1);
+if (!name) {
+goto efault;
+}
+ret = get_errno(prctl(arg1, (unsigned long)name,
+  arg3, arg4, arg5));
+unlock_user(name, arg2, 16);
+break;
+}
+case PR_SET_NAME:
+{
+void *name = lock_user(VERIFY_READ, arg2, 16, 1);
+if (!name) {
+goto efault;
+}
+ret = get_errno(prctl(arg1, (unsigned long)name,
+  arg3, arg4, arg5));
+unlock_user(name, arg2, 0);
+break;
+}
+#endif
 default:
 /* Most prctl options have no pointer arguments */
 ret = get_errno(prctl(arg1, arg2, arg3, arg4, arg5));
-- 
1.7.1




[Qemu-devel] [PATCH 0/2] linux-user: Support prctl PR_GET/SET_NAME

2012-02-03 Thread Peter Maydell
These patches add support for the prctl options PR_GET_NAME
and PR_SET_NAME. In particular, perl 5.14 will use PR_SET_NAME
if you change the value of $0, which means that adduser will
fail if run under qemu with a sufficiently modern perl.

Patch one is just indentation cleanup, the meat is patch 2.

The only other prctl options which take pointer arguments are
all architecture specific, so there didn't seem much point in
adding them (they all work like PR_GET_PDEATHSIG in that they
pass an int* to be filled in); we'd have to actually emulate them
if we cared about them.

Peter Maydell (2):
  linux-user/syscall.c: Fix indentation in prctl handling
  linux-user: Add support for prctl PR_GET_NAME and PR_SET_NAME

 linux-user/syscall.c |   53 -
 1 files changed, 39 insertions(+), 14 deletions(-)




[Qemu-devel] [PATCH 1/2] linux-user/syscall.c: Fix indentation in prctl handling

2012-02-03 Thread Peter Maydell
Clean up the odd indentation of this switch statement before
we double its size by adding new cases to it.

Signed-off-by: Peter Maydell 
---
 linux-user/syscall.c |   29 +++--
 1 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 2bf9e7e..7851fb5 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6842,21 +6842,22 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 goto unimplemented;
 #endif
 case TARGET_NR_prctl:
-switch (arg1)
-{
-case PR_GET_PDEATHSIG:
-{
-int deathsig;
-ret = get_errno(prctl(arg1, &deathsig, arg3, arg4, arg5));
-if (!is_error(ret) && arg2
-&& put_user_ual(deathsig, arg2))
-goto efault;
-}
-break;
-default:
-ret = get_errno(prctl(arg1, arg2, arg3, arg4, arg5));
-break;
+switch (arg1) {
+case PR_GET_PDEATHSIG:
+{
+int deathsig;
+ret = get_errno(prctl(arg1, &deathsig, arg3, arg4, arg5));
+if (!is_error(ret) && arg2
+&& put_user_ual(deathsig, arg2)) {
+goto efault;
 }
+break;
+}
+default:
+/* Most prctl options have no pointer arguments */
+ret = get_errno(prctl(arg1, arg2, arg3, arg4, arg5));
+break;
+}
 break;
 #ifdef TARGET_NR_arch_prctl
 case TARGET_NR_arch_prctl:
-- 
1.7.1




Re: [Qemu-devel] [PATCH 10/16] qdev: make the non-legacy pci address property accept an integer

2012-02-03 Thread Anthony Liguori

On 02/02/2012 02:19 PM, Paolo Bonzini wrote:

On 02/02/2012 09:07 PM, Anthony Liguori wrote:


Signed-off-by: Paolo Bonzini


Isn't this a compatibility breaker?

Won't this break libvirt's usage of -device addr=0.2 ?


Nope, the legacy property still keeps the dd.f format. This is only for QOM (and
internal use by qdev).


Ah, I forgot we duplicate the properties here.

Since there is now a programmatic mapping between legacy properties types and 
non-legacy property types, could we remove the legacy properties that now have 
well behaved types and add some code to device_add to maintain compatibility?


Regards,

Anthony Liguori


Paolo






Re: [Qemu-devel] [PATCH v2 0/8] qemu-ga: add support for Windows

2012-02-03 Thread Luiz Capitulino
On Thu,  2 Feb 2012 13:58:52 -0600
Michael Roth  wrote:

> These patches apply on top of qemu.git master, and can also be obtained from:
> git://github.com/mdroth/qemu.git qga-win32-v2
> 
> Luiz/Gal, I decided not to roll the suspend/hibernate stuff into this series
> since the s3 situation isn't fully sorted out yet. The file structure is a
> little different now, posix/linux-specific stuff goes in qga/commands-posix.c,
> win32-specific stuff in qga/commands-win32.c, but other than that it should be
> a straightforward rebase if this gets merged first.

I think I'll have to rebase my series on top of this one, when do you plan to
merge this?



Re: [Qemu-devel] [PATCH 01/16] qdev: fix hot-unplug

2012-02-03 Thread Anthony Liguori

On 02/02/2012 10:45 AM, Paolo Bonzini wrote:

The reference that is returned by qdev_device_add is never given
back, so that device_del does not cause the refcount to go to zero
(and thus does nothing).

Signed-off-by: Paolo Bonzini


This isn't needed in qom-upstream.14.  Here's why:

object_init does not increase the reference count

object_property_add_child increases the reference count
object_new increases the reference count

object_delete decrements the reference count
object_property_del_child decreases the reference count

object_delete calls object_property_del_child(obj->parent, obj)

qdev_device_add calls object_new and object_property_add_child
 -> ref == 2

qdev_device_del calls object_delete
 -> ref -= 2

In qom-upstream.13, object_delete wasn't calling object_property_del_child which 
is why you saw the behavior you did.  This problem would still exist with a 
composed device so dropping the reference here isn't enough.


Regards,

Anthony Liguori


---
  vl.c |1 +
  1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/vl.c b/vl.c
index d88a18c..c63af69 100644
--- a/vl.c
+++ b/vl.c
@@ -1746,6 +1746,7 @@ static int device_init_func(QemuOpts *opts, void *opaque)
  dev = qdev_device_add(opts);
  if (!dev)
  return -1;
+object_unref(OBJECT(dev));
  return 0;
  }






[Qemu-devel] [PATCH 06/19] linux-user: fake /proc/self/auxv

2012-02-03 Thread riku . voipio
From: Alexander Graf 

Gtk tries to read /proc/self/auxv to find its auxv table instead of
taking it from its own program memory space.

However, when running with linux-user, we see the host's auxv which
clearly exposes wrong information. so let's instead expose the guest
memory backed auxv tables via /proc/self/auxv as well.

Signed-off-by: Alexander Graf 
Signed-off-by: Riku Voipio 
---
 linux-user/syscall.c |   30 ++
 1 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 5a5fdac..c6bfcd8 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -4639,6 +4639,35 @@ static int open_self_stat(void *cpu_env, int fd)
 return 0;
 }
 
+static int open_self_auxv(void *cpu_env, int fd)
+{
+TaskState *ts = ((CPUState *)cpu_env)->opaque;
+abi_ulong auxv = ts->info->saved_auxv;
+abi_ulong len = ts->info->auxv_len;
+char *ptr;
+
+/*
+ * Auxiliary vector is stored in target process stack.
+ * read in whole auxv vector and copy it to file
+ */
+ptr = lock_user(VERIFY_READ, auxv, len, 0);
+if (ptr != NULL) {
+while (len > 0) {
+ssize_t r;
+r = write(fd, ptr, len);
+if (r <= 0) {
+break;
+}
+len -= r;
+ptr += r;
+}
+lseek(fd, 0, SEEK_SET);
+unlock_user(ptr, auxv, len);
+}
+
+return 0;
+}
+
 static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode)
 {
 struct fake_open {
@@ -4649,6 +4678,7 @@ static int do_open(void *cpu_env, const char *pathname, 
int flags, mode_t mode)
 static const struct fake_open fakes[] = {
 { "/proc/self/maps", open_self_maps },
 { "/proc/self/stat", open_self_stat },
+{ "/proc/self/auxv", open_self_auxv },
 { NULL, NULL }
 };
 
-- 
1.7.5.4




[Qemu-devel] [PATCH 09/19] linux-user: fix QEMU_STRACE=1 segfault

2012-02-03 Thread riku . voipio
From: Alexander Graf 

While debugging some issues with QEMU_STRACE I stumbled over segmentation
faults that were pretty reproducible. Turns out we tried to treat a
normal return value as errno, resulting in an access over array boundaries
for the resolution.

Fix this by allowing failure to resolve invalid errnos into strings.

Signed-off-by: Alexander Graf 
Signed-off-by: Riku Voipio 
---
 linux-user/strace.c  |   18 ++
 linux-user/syscall.c |3 +++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 90027a1..269481e 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -284,8 +284,13 @@ print_ipc(const struct syscallname *name,
 static void
 print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
 {
-if( ret == -1 ) {
-gemu_log(" = -1 errno=%d (%s)\n", errno, target_strerror(errno));
+char *errstr = NULL;
+
+if (ret == -1) {
+errstr = target_strerror(errno);
+}
+if ((ret == -1) && errstr) {
+gemu_log(" = -1 errno=%d (%s)\n", errno, errstr);
 } else {
 gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
 }
@@ -1515,14 +1520,19 @@ void
 print_syscall_ret(int num, abi_long ret)
 {
 int i;
+char *errstr = NULL;
 
 for(i=0;i= ERRNO_TABLE_SIZE) || (err < 0)) {
+return NULL;
+}
 return strerror(target_to_host_errno(err));
 }
 
-- 
1.7.5.4




[Qemu-devel] [PATCH 10/19] linux-user/strace.c: Correct errno printing for mmap etc

2012-02-03 Thread riku . voipio
From: Peter Maydell 

Correct the printing of errnos for syscalls which are handled
via print_syscall_ret_addr (mmap, mmap2, brk, shmat): errnos
are returned as negative returned values at this level, not
via the host 'errno' variable.

Signed-off-by: Peter Maydell 
Signed-off-by: Riku Voipio 
---
 linux-user/strace.c |9 -
 1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 269481e..05a0d3e 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1,5 +1,4 @@
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -286,11 +285,11 @@ print_syscall_ret_addr(const struct syscallname *name, 
abi_long ret)
 {
 char *errstr = NULL;
 
-if (ret == -1) {
-errstr = target_strerror(errno);
+if (ret < 0) {
+errstr = target_strerror(-ret);
 }
-if ((ret == -1) && errstr) {
-gemu_log(" = -1 errno=%d (%s)\n", errno, errstr);
+if (errstr) {
+gemu_log(" = -1 errno=%d (%s)\n", (int)-ret, errstr);
 } else {
 gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
 }
-- 
1.7.5.4




[Qemu-devel] [PATCH 14/19] linux-user: Implement *listxattr syscalls

2012-02-03 Thread riku . voipio
From: Peter Maydell 

Implement listxattr, flistxattr and llistxattr syscalls.

Signed-off-by: Peter Maydell 
Signed-off-by: Riku Voipio 
---
 linux-user/syscall.c |   36 +++-
 1 files changed, 35 insertions(+), 1 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 762115b..ee8899e 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7798,9 +7798,43 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 #ifdef TARGET_NR_setxattr
 case TARGET_NR_listxattr:
 case TARGET_NR_llistxattr:
+{
+void *p, *b = 0;
+if (arg2) {
+b = lock_user(VERIFY_WRITE, arg2, arg3, 0);
+if (!b) {
+ret = -TARGET_EFAULT;
+break;
+}
+}
+p = lock_user_string(arg1);
+if (p) {
+if (num == TARGET_NR_listxattr) {
+ret = get_errno(listxattr(p, b, arg3));
+} else {
+ret = get_errno(llistxattr(p, b, arg3));
+}
+} else {
+ret = -TARGET_EFAULT;
+}
+unlock_user(p, arg1, 0);
+unlock_user(b, arg2, arg3);
+break;
+}
 case TARGET_NR_flistxattr:
-ret = -TARGET_EOPNOTSUPP;
+{
+void *b = 0;
+if (arg2) {
+b = lock_user(VERIFY_WRITE, arg2, arg3, 0);
+if (!b) {
+ret = -TARGET_EFAULT;
+break;
+}
+}
+ret = get_errno(flistxattr(arg1, b, arg3));
+unlock_user(b, arg2, arg3);
 break;
+}
 case TARGET_NR_setxattr:
 case TARGET_NR_lsetxattr:
 {
-- 
1.7.5.4




[Qemu-devel] [PATCH 11/19] linux-user: fix wait* syscall status returns

2012-02-03 Thread riku . voipio
From: Alexander Graf 

When calling wait4 or waitpid with a status pointer and WNOHANG, the
syscall can potentially not modify the status pointer input. Now if we
have guest code like:

  int status = 0;
  waitpid(pid, &status, WNOHANG);
  if (status)
 

then we have to make sure that in case status did not change we actually
return the guest's initialized status variable instead of our own uninitialized.
We fail to do so today, as we proxy everything through an uninitialized status
variable which for me ended up always containing the last error code.

This patch fixes some test cases when building yast2-core in OBS for ARM.

Signed-off-by: Alexander Graf 
Signed-off-by: Riku Voipio 
---
 linux-user/syscall.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 29d92c4..06b19e0 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -4867,7 +4867,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 {
 int status;
 ret = get_errno(waitpid(arg1, &status, arg3));
-if (!is_error(ret) && arg2
+if (!is_error(ret) && arg2 && ret
 && put_user_s32(host_to_target_waitstatus(status), arg2))
 goto efault;
 }
@@ -6423,7 +6423,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 rusage_ptr = NULL;
 ret = get_errno(wait4(arg1, &status, arg3, rusage_ptr));
 if (!is_error(ret)) {
-if (status_ptr) {
+if (status_ptr && ret) {
 status = host_to_target_waitstatus(status);
 if (put_user_s32(status, status_ptr))
 goto efault;
-- 
1.7.5.4




[Qemu-devel] [PATCH 07/19] linux-user/main.c: Add option to user-mode emulation so that user can specify log file name

2012-02-03 Thread riku . voipio
From: 陳韋任 

  QEMU linux user-mode's default log file name is "/tmp/qemu.log". In order to
change the log file name, user need to modify the source code then recompile
QEMU. This patch allow user use "-D logfile" option to specify the log file
name.

Signed-off-by: Chen Wen-Ren 
Signed-off-by: Riku Voipio 
---
 linux-user/main.c |7 +++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 64d2208..14bf5f0 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -2945,6 +2945,11 @@ static void handle_arg_log(const char *arg)
 cpu_set_log(mask);
 }
 
+static void handle_arg_log_filename(const char *arg)
+{
+cpu_set_log_filename(arg);
+}
+
 static void handle_arg_set_env(const char *arg)
 {
 char *r, *p, *token;
@@ -3125,6 +3130,8 @@ struct qemu_argument arg_table[] = {
 #endif
 {"d",  "QEMU_LOG", true,  handle_arg_log,
  "options","activate log"},
+{"D",  "QEMU_LOG_FILENAME", true, handle_arg_log_filename,
+ "logfile", "override default logfile location"},
 {"p",  "QEMU_PAGESIZE",true,  handle_arg_pagesize,
  "pagesize",   "set the host page size to 'pagesize'"},
 {"singlestep", "QEMU_SINGLESTEP",  false, handle_arg_singlestep,
-- 
1.7.5.4




[Qemu-devel] [PATCH 13/19] linux-user/syscall.c: Implement f and l versions of set/get/removexattr

2012-02-03 Thread riku . voipio
From: Peter Maydell 

Implement the f and l versions (operate on fd, don't follow links)
of the setxattr, getxattr and removexattr syscalls.

Signed-off-by: Peter Maydell 
Signed-off-by: Riku Voipio 
---
 linux-user/syscall.c |   79 --
 1 files changed, 70 insertions(+), 9 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 0a78a18..762115b 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7796,18 +7796,13 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 #endif
 #ifdef CONFIG_ATTR
 #ifdef TARGET_NR_setxattr
-case TARGET_NR_lsetxattr:
-case TARGET_NR_fsetxattr:
-case TARGET_NR_lgetxattr:
-case TARGET_NR_fgetxattr:
 case TARGET_NR_listxattr:
 case TARGET_NR_llistxattr:
 case TARGET_NR_flistxattr:
-case TARGET_NR_lremovexattr:
-case TARGET_NR_fremovexattr:
 ret = -TARGET_EOPNOTSUPP;
 break;
 case TARGET_NR_setxattr:
+case TARGET_NR_lsetxattr:
 {
 void *p, *n, *v = 0;
 if (arg3) {
@@ -7820,7 +7815,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 p = lock_user_string(arg1);
 n = lock_user_string(arg2);
 if (p && n) {
-ret = get_errno(setxattr(p, n, v, arg4, arg5));
+if (num == TARGET_NR_setxattr) {
+ret = get_errno(setxattr(p, n, v, arg4, arg5));
+} else {
+ret = get_errno(lsetxattr(p, n, v, arg4, arg5));
+}
 } else {
 ret = -TARGET_EFAULT;
 }
@@ -7829,7 +7828,28 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 unlock_user(v, arg3, 0);
 }
 break;
+case TARGET_NR_fsetxattr:
+{
+void *n, *v = 0;
+if (arg3) {
+v = lock_user(VERIFY_READ, arg3, arg4, 1);
+if (!v) {
+ret = -TARGET_EFAULT;
+break;
+}
+}
+n = lock_user_string(arg2);
+if (n) {
+ret = get_errno(fsetxattr(arg1, n, v, arg4, arg5));
+} else {
+ret = -TARGET_EFAULT;
+}
+unlock_user(n, arg2, 0);
+unlock_user(v, arg3, 0);
+}
+break;
 case TARGET_NR_getxattr:
+case TARGET_NR_lgetxattr:
 {
 void *p, *n, *v = 0;
 if (arg3) {
@@ -7842,7 +7862,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 p = lock_user_string(arg1);
 n = lock_user_string(arg2);
 if (p && n) {
-ret = get_errno(getxattr(p, n, v, arg4));
+if (num == TARGET_NR_getxattr) {
+ret = get_errno(getxattr(p, n, v, arg4));
+} else {
+ret = get_errno(lgetxattr(p, n, v, arg4));
+}
 } else {
 ret = -TARGET_EFAULT;
 }
@@ -7851,13 +7875,38 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 unlock_user(v, arg3, arg4);
 }
 break;
+case TARGET_NR_fgetxattr:
+{
+void *n, *v = 0;
+if (arg3) {
+v = lock_user(VERIFY_WRITE, arg3, arg4, 0);
+if (!v) {
+ret = -TARGET_EFAULT;
+break;
+}
+}
+n = lock_user_string(arg2);
+if (n) {
+ret = get_errno(fgetxattr(arg1, n, v, arg4));
+} else {
+ret = -TARGET_EFAULT;
+}
+unlock_user(n, arg2, 0);
+unlock_user(v, arg3, arg4);
+}
+break;
 case TARGET_NR_removexattr:
+case TARGET_NR_lremovexattr:
 {
 void *p, *n;
 p = lock_user_string(arg1);
 n = lock_user_string(arg2);
 if (p && n) {
-ret = get_errno(removexattr(p, n));
+if (num == TARGET_NR_removexattr) {
+ret = get_errno(removexattr(p, n));
+} else {
+ret = get_errno(lremovexattr(p, n));
+}
 } else {
 ret = -TARGET_EFAULT;
 }
@@ -7865,6 +7914,18 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 unlock_user(n, arg2, 0);
 }
 break;
+case TARGET_NR_fremovexattr:
+{
+void *n;
+n = lock_user_string(arg2);
+if (n) {
+ret = get_errno(fremovexattr(arg1, n));
+} else {
+ret = -TARGET_EFAULT;
+}
+unlock_user(n, arg2, 0);
+}
+break;
 #endif
 #endif /* CONFIG_ATTR */
 #ifdef TARGET_NR_set_thread_area
-- 
1.7.5.4




[Qemu-devel] [PATCH 17/19] linux-user: Define TARGET_QEMU_ESIGRETURN for mipsn32

2012-02-03 Thread riku . voipio
From: Andreas Färber 

Copied from mips/syscall.h.

Signed-off-by: Ulrich Hecht 
Signed-off-by: Andreas Färber 
Signed-off-by: Riku Voipio 
---
 linux-user/mipsn32/syscall.h |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/linux-user/mipsn32/syscall.h b/linux-user/mipsn32/syscall.h
index 4ec506c..ebe98f2 100644
--- a/linux-user/mipsn32/syscall.h
+++ b/linux-user/mipsn32/syscall.h
@@ -218,4 +218,7 @@ struct target_pt_regs {
 
 
 
+/* Nasty hack: define a fake errno value for use by sigreturn. */
+#define TARGET_QEMU_ESIGRETURN 255
+
 #define UNAME_MACHINE "mips64"
-- 
1.7.5.4




[Qemu-devel] [PATCH 18/19] linux-user: Define TARGET_QEMU_ESIGRETURN for mips64

2012-02-03 Thread riku . voipio
From: Andreas Färber 

Copied from mips/syscall.h.

Signed-off-by: Khansa Butt 
Signed-off-by: Andreas Färber 
Signed-off-by: Riku Voipio 
---
 linux-user/mips64/syscall.h |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/linux-user/mips64/syscall.h b/linux-user/mips64/syscall.h
index 668a2b9..e436ea5 100644
--- a/linux-user/mips64/syscall.h
+++ b/linux-user/mips64/syscall.h
@@ -218,4 +218,7 @@ struct target_pt_regs {
 
 
 
+/* Nasty hack: define a fake errno value for use by sigreturn. */
+#define TARGET_QEMU_ESIGRETURN 255
+
 #define UNAME_MACHINE "mips64"
-- 
1.7.5.4




[Qemu-devel] [PATCH 12/19] linux-user: Allow NULL value pointer in setxattr and getxattr

2012-02-03 Thread riku . voipio
From: Peter Maydell 

It's valid to pass a NULL value pointer to setxattr, so don't
fail this case EFAULT.

Signed-off-by: Peter Maydell 
Signed-off-by: Riku Voipio 
---
 linux-user/syscall.c |   24 ++--
 1 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 06b19e0..0a78a18 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7809,11 +7809,17 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 break;
 case TARGET_NR_setxattr:
 {
-void *p, *n, *v;
+void *p, *n, *v = 0;
+if (arg3) {
+v = lock_user(VERIFY_READ, arg3, arg4, 1);
+if (!v) {
+ret = -TARGET_EFAULT;
+break;
+}
+}
 p = lock_user_string(arg1);
 n = lock_user_string(arg2);
-v = lock_user(VERIFY_READ, arg3, arg4, 1);
-if (p && n && v) {
+if (p && n) {
 ret = get_errno(setxattr(p, n, v, arg4, arg5));
 } else {
 ret = -TARGET_EFAULT;
@@ -7825,11 +7831,17 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 break;
 case TARGET_NR_getxattr:
 {
-void *p, *n, *v;
+void *p, *n, *v = 0;
+if (arg3) {
+v = lock_user(VERIFY_WRITE, arg3, arg4, 0);
+if (!v) {
+ret = -TARGET_EFAULT;
+break;
+}
+}
 p = lock_user_string(arg1);
 n = lock_user_string(arg2);
-v = lock_user(VERIFY_WRITE, arg3, arg4, 0);
-if (p && n && v) {
+if (p && n) {
 ret = get_errno(getxattr(p, n, v, arg4));
 } else {
 ret = -TARGET_EFAULT;
-- 
1.7.5.4




[Qemu-devel] [PATCH 15/19] linux-user: Add default-configs for mipsn32[el]

2012-02-03 Thread riku . voipio
From: Andreas Färber 

Prepares for mipsn32[el]-linux-user targets.

Signed-off-by: Ulricht Hecht 
Signed-off-by: Andreas Färber 
Signed-off-by: Riku Voipio 
---
 default-configs/mipsn32-linux-user.mak   |1 +
 default-configs/mipsn32el-linux-user.mak |1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644 default-configs/mipsn32-linux-user.mak
 create mode 100644 default-configs/mipsn32el-linux-user.mak

diff --git a/default-configs/mipsn32-linux-user.mak 
b/default-configs/mipsn32-linux-user.mak
new file mode 100644
index 000..5b97919
--- /dev/null
+++ b/default-configs/mipsn32-linux-user.mak
@@ -0,0 +1 @@
+# Default configuration for mipsn32-linux-user
diff --git a/default-configs/mipsn32el-linux-user.mak 
b/default-configs/mipsn32el-linux-user.mak
new file mode 100644
index 000..d6367ff
--- /dev/null
+++ b/default-configs/mipsn32el-linux-user.mak
@@ -0,0 +1 @@
+# Default configuration for mipsn32el-linux-user
-- 
1.7.5.4




[Qemu-devel] [PATCH 01/19] linux-user: stack_base is now mandatory on all targets

2012-02-03 Thread riku . voipio
From: Riku Voipio 

Signed-off-by: Riku Voipio 
---
 linux-user/qemu.h |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index 55ad9d8..30e2abd 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -123,10 +123,10 @@ typedef struct TaskState {
 #endif
 #if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_UNICORE32)
 /* Extra fields for semihosted binaries.  */
-uint32_t stack_base;
 uint32_t heap_base;
 uint32_t heap_limit;
 #endif
+uint32_t stack_base;
 int used; /* non zero if used */
 struct image_info *info;
 struct linux_binprm *bprm;
-- 
1.7.5.4




[Qemu-devel] [PATCH 03/19] linux-user: add open() hijack infrastructure

2012-02-03 Thread riku . voipio
From: Alexander Graf 

There are a number of files in /proc that expose host information
to the guest program. This patch adds infrastructure to override
the open() syscall for guest programs to enable us to on the fly
generate guest sensible files.

Signed-off-by: Alexander Graf 
Signed-off-by: Riku Voipio 
---
 linux-user/syscall.c |   52 +++--
 1 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 2bf9e7e..e100025 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -4600,6 +4600,52 @@ int get_osversion(void)
 return osversion;
 }
 
+static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode)
+{
+struct fake_open {
+const char *filename;
+int (*fill)(void *cpu_env, int fd);
+};
+const struct fake_open *fake_open;
+static const struct fake_open fakes[] = {
+{ NULL, NULL }
+};
+
+for (fake_open = fakes; fake_open->filename; fake_open++) {
+if (!strncmp(pathname, fake_open->filename,
+ strlen(fake_open->filename))) {
+break;
+}
+}
+
+if (fake_open->filename) {
+const char *tmpdir;
+char filename[PATH_MAX];
+int fd, r;
+
+/* create temporary file to map stat to */
+tmpdir = getenv("TMPDIR");
+if (!tmpdir)
+tmpdir = "/tmp";
+snprintf(filename, sizeof(filename), "%s/qemu-open.XX", tmpdir);
+fd = mkstemp(filename);
+if (fd < 0) {
+return fd;
+}
+unlink(filename);
+
+if ((r = fake_open->fill(cpu_env, fd))) {
+close(fd);
+return r;
+}
+lseek(fd, 0, SEEK_SET);
+
+return fd;
+}
+
+return get_errno(open(path(pathname), flags, mode));
+}
+
 /* do_syscall() should always have a single exit point at the end so
that actions, such as logging of syscall results, can be performed.
All errnos that do_syscall() returns must be -TARGET_. */
@@ -4685,9 +4731,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 case TARGET_NR_open:
 if (!(p = lock_user_string(arg1)))
 goto efault;
-ret = get_errno(open(path(p),
- target_to_host_bitmask(arg2, fcntl_flags_tbl),
- arg3));
+ret = get_errno(do_open(cpu_env, p,
+target_to_host_bitmask(arg2, fcntl_flags_tbl),
+arg3));
 unlock_user(p, arg1, 0);
 break;
 #if defined(TARGET_NR_openat) && defined(__NR_openat)
-- 
1.7.5.4




[Qemu-devel] [PATCH 19/19] linux-user: Fix sa_flags byte swaps for mips

2012-02-03 Thread riku . voipio
From: Andreas Färber 

sa_flags is uint32_t for mips{,n32,64}, so don't use tswapal().

edited by Riku Voipio: likewise on alpha

Reported-by: Khansa Butt 
Suggested-by: Richard Henderson 
Signed-off-by: Andreas Färber 
Cc: Ehsan Ul Haq 
Signed-off-by: Riku Voipio 
---
 linux-user/signal.c |8 
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/linux-user/signal.c b/linux-user/signal.c
index ded12ca..79a39dc 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -587,7 +587,11 @@ int do_sigaction(int sig, const struct target_sigaction 
*act,
 #endif
 if (oact) {
 oact->_sa_handler = tswapal(k->_sa_handler);
+#if defined(TARGET_MIPS) || defined (TARGET_ALPHA)
+oact->sa_flags = bswap32(k->sa_flags);
+#else
 oact->sa_flags = tswapal(k->sa_flags);
+#endif
 #if !defined(TARGET_MIPS)
 oact->sa_restorer = tswapal(k->sa_restorer);
 #endif
@@ -596,7 +600,11 @@ int do_sigaction(int sig, const struct target_sigaction 
*act,
 if (act) {
 /* FIXME: This is not threadsafe.  */
 k->_sa_handler = tswapal(act->_sa_handler);
+#if defined(TARGET_MIPS) || defined (TARGET_ALPHA)
+k->sa_flags = bswap32(act->sa_flags);
+#else
 k->sa_flags = tswapal(act->sa_flags);
+#endif
 #if !defined(TARGET_MIPS)
 k->sa_restorer = tswapal(act->sa_restorer);
 #endif
-- 
1.7.5.4




[Qemu-devel] [PATCH 05/19] linux-user: fake /proc/self/stat

2012-02-03 Thread riku . voipio
From: Alexander Graf 

The boehm gc finds the program's stack starting pointer by
checking /proc/self/stat. Unfortunately, so far it reads
qemu's stack pointer which clearly is wrong.

So let's instead fake the file so the guest program sees the
right address.

Signed-off-by: Alexander Graf 
Signed-off-by: Riku Voipio 
---
 linux-user/syscall.c |   26 ++
 1 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 1864d7f..5a5fdac 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -4614,6 +4614,31 @@ static int open_self_maps(void *cpu_env, int fd)
 return 0;
 }
 
+static int open_self_stat(void *cpu_env, int fd)
+{
+TaskState *ts = ((CPUState *)cpu_env)->opaque;
+abi_ulong start_stack = ts->info->start_stack;
+int i;
+
+for (i = 0; i < 44; i++) {
+  char buf[128];
+  int len;
+  uint64_t val = 0;
+
+  if (i == 27) {
+  /* stack bottom */
+  val = start_stack;
+  }
+  snprintf(buf, sizeof(buf), "%"PRId64 "%c", val, i == 43 ? '\n' : ' ');
+  len = strlen(buf);
+  if (write(fd, buf, len) != len) {
+  return -1;
+  }
+}
+
+return 0;
+}
+
 static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode)
 {
 struct fake_open {
@@ -4623,6 +4648,7 @@ static int do_open(void *cpu_env, const char *pathname, 
int flags, mode_t mode)
 const struct fake_open *fake_open;
 static const struct fake_open fakes[] = {
 { "/proc/self/maps", open_self_maps },
+{ "/proc/self/stat", open_self_stat },
 { NULL, NULL }
 };
 
-- 
1.7.5.4




[Qemu-devel] [PATCH 08/19] linux-user: add SO_PEERCRED support for getsockopt

2012-02-03 Thread riku . voipio
From: Akos PASZTORY 

Signed-off-by: Akos PASZTORY 
Signed-off-by: Riku Voipio 
---
 linux-user/syscall.c  |   34 +-
 linux-user/syscall_defs.h |6 ++
 2 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index c6bfcd8..15b8b22 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1530,9 +1530,41 @@ static abi_long do_getsockopt(int sockfd, int level, int 
optname,
 case TARGET_SO_LINGER:
 case TARGET_SO_RCVTIMEO:
 case TARGET_SO_SNDTIMEO:
-case TARGET_SO_PEERCRED:
 case TARGET_SO_PEERNAME:
 goto unimplemented;
+case TARGET_SO_PEERCRED: {
+struct ucred cr;
+socklen_t crlen;
+struct target_ucred *tcr;
+
+if (get_user_u32(len, optlen)) {
+return -TARGET_EFAULT;
+}
+if (len < 0) {
+return -TARGET_EINVAL;
+}
+
+crlen = sizeof(cr);
+ret = get_errno(getsockopt(sockfd, level, SO_PEERCRED,
+   &cr, &crlen));
+if (ret < 0) {
+return ret;
+}
+if (len > crlen) {
+len = crlen;
+}
+if (!lock_user_struct(VERIFY_WRITE, tcr, optval_addr, 0)) {
+return -TARGET_EFAULT;
+}
+__put_user(cr.pid, &tcr->pid);
+__put_user(cr.uid, &tcr->uid);
+__put_user(cr.gid, &tcr->gid);
+unlock_user_struct(tcr, optval_addr, 1);
+if (put_user_u32(len, optlen)) {
+return -TARGET_EFAULT;
+}
+break;
+}
 /* Options with 'int' argument.  */
 case TARGET_SO_DEBUG:
 optname = SO_DEBUG;
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 2857805..41f0ff8 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2336,3 +2336,9 @@ struct target_rlimit64 {
 uint64_t rlim_cur;
 uint64_t rlim_max;
 };
+
+struct target_ucred {
+uint32_t pid;
+uint32_t uid;
+uint32_t gid;
+};
-- 
1.7.5.4




[Qemu-devel] [PATCH 02/19] linux-user: save auxv length

2012-02-03 Thread riku . voipio
From: Alexander Graf 

We create our own AUXV segment on stack and save a pointer to it.
However we don't save the length of it, so any code that wants to
do anything useful with it later on has to walk it again.

Instead, let's remember the length of our AUXV segment. This
simplifies later uses by a lot.

(edited by Riku to apply to qemu HEAD)

Signed-off-by: Alexander Graf 
Signed-off-by: Riku Voipio 
---
 linux-user/elfload.c |   15 ---
 linux-user/qemu.h|1 +
 2 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 845be8b..2fd4a93 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1245,6 +1245,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, 
int envc,
struct image_info *interp_info)
 {
 abi_ulong sp;
+abi_ulong sp_auxv;
 int size;
 int i;
 abi_ulong u_rand_bytes;
@@ -1316,6 +1317,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, 
int envc,
 sp -= n; put_user_ual(id, sp);  \
 } while(0)
 
+sp_auxv = sp;
 NEW_AUX_ENT (AT_NULL, 0);
 
 /* There must be exactly DLINFO_ITEMS entries here.  */
@@ -1346,6 +1348,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, 
int envc,
 #undef NEW_AUX_ENT
 
 info->saved_auxv = sp;
+info->auxv_len = sp_auxv - sp;
 
 sp = loader_build_argptr(envc, argc, sp, p, 0);
 return sp;
@@ -2326,9 +2329,8 @@ static void fill_auxv_note(struct memelfnote *note, const 
TaskState *ts)
 {
 elf_addr_t auxv = (elf_addr_t)ts->info->saved_auxv;
 elf_addr_t orig_auxv = auxv;
-abi_ulong val;
 void *ptr;
-int i, len;
+int len = ts->info->auxv_len;
 
 /*
  * Auxiliary vector is stored in target process stack.  It contains
@@ -2336,15 +2338,6 @@ static void fill_auxv_note(struct memelfnote *note, 
const TaskState *ts)
  * strictly necessary but we do it here for sake of completeness.
  */
 
-/* find out length of the vector, AT_NULL is terminator */
-i = len = 0;
-do {
-get_user_ual(val, auxv);
-i += 2;
-auxv += 2 * sizeof (elf_addr_t);
-} while (val != AT_NULL);
-len = i * sizeof (elf_addr_t);
-
 /* read in whole auxv vector and copy it to memelfnote */
 ptr = lock_user(VERIFY_READ, orig_auxv, len, 0);
 if (ptr != NULL) {
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index 30e2abd..308dbc0 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -48,6 +48,7 @@ struct image_info {
 abi_ulong   code_offset;
 abi_ulong   data_offset;
 abi_ulong   saved_auxv;
+abi_ulong   auxv_len;
 abi_ulong   arg_start;
 abi_ulong   arg_end;
int personality;
-- 
1.7.5.4




[Qemu-devel] [PATCH 04/19] linux-user: fake /proc/self/maps

2012-02-03 Thread riku . voipio
From: Alexander Graf 

glibc's pthread_attr_getstack tries to find the stack range from
/proc/self/maps. Unfortunately, /proc is usually the host's /proc
which means linux-user guests see qemu's stack there.

Fake the file with a constructed maps entry that exposes the guest's
stack range.

Signed-off-by: Alexander Graf 
Signed-off-by: Riku Voipio 
---
 linux-user/syscall.c |   15 +++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e100025..1864d7f 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -4600,6 +4600,20 @@ int get_osversion(void)
 return osversion;
 }
 
+
+static int open_self_maps(void *cpu_env, int fd)
+{
+TaskState *ts = ((CPUState *)cpu_env)->opaque;
+
+dprintf(fd, "%08llx-%08llx rw-p %08llx 00:00 0  [stack]\n",
+(unsigned long long)ts->info->stack_limit,
+(unsigned long long)(ts->stack_base + (TARGET_PAGE_SIZE - 1))
+ & TARGET_PAGE_MASK,
+(unsigned long long)ts->stack_base);
+
+return 0;
+}
+
 static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode)
 {
 struct fake_open {
@@ -4608,6 +4622,7 @@ static int do_open(void *cpu_env, const char *pathname, 
int flags, mode_t mode)
 };
 const struct fake_open *fake_open;
 static const struct fake_open fakes[] = {
+{ "/proc/self/maps", open_self_maps },
 { NULL, NULL }
 };
 
-- 
1.7.5.4




[Qemu-devel] [PATCH 16/19] linux-user: Add default configs for mips64[el]

2012-02-03 Thread riku . voipio
From: Andreas Färber 

Prepares for mips64[el]-linux-user targets.

Signed-off-by: Khansa Butt 
Signed-off-by: Andreas Färber 
Signed-off-by: Riku Voipio 
---
 default-configs/mips64-linux-user.mak   |1 +
 default-configs/mips64el-linux-user.mak |1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644 default-configs/mips64-linux-user.mak
 create mode 100644 default-configs/mips64el-linux-user.mak

diff --git a/default-configs/mips64-linux-user.mak 
b/default-configs/mips64-linux-user.mak
new file mode 100644
index 000..1598bfc
--- /dev/null
+++ b/default-configs/mips64-linux-user.mak
@@ -0,0 +1 @@
+# Default configuration for mips64-linux-user
diff --git a/default-configs/mips64el-linux-user.mak 
b/default-configs/mips64el-linux-user.mak
new file mode 100644
index 000..629f084
--- /dev/null
+++ b/default-configs/mips64el-linux-user.mak
@@ -0,0 +1 @@
+# Default configuration for mips64el-linux-user
-- 
1.7.5.4




[Qemu-devel] [PULL] [PATCH 00/19] linux-user update

2012-02-03 Thread riku . voipio
From: Riku Voipio 

The following changes since commit d34e8f6e9d3a396c3327aa9807c83f9e1f4a7bd7:

  main-loop: For tools, initialize timers as part of qemu_init_main_loop() 
(2012-02-01 14:45:02 -0600)

are available in the git repository at:
  git://git.linaro.org/people/rikuvoipio/qemu.git linux-user-for-upstream

Akos PASZTORY (1):
  linux-user: add SO_PEERCRED support for getsockopt

Alexander Graf (7):
  linux-user: save auxv length
  linux-user: add open() hijack infrastructure
  linux-user: fake /proc/self/maps
  linux-user: fake /proc/self/stat
  linux-user: fake /proc/self/auxv
  linux-user: fix QEMU_STRACE=1 segfault
  linux-user: fix wait* syscall status returns

Andreas Färber (5):
  linux-user: Add default-configs for mipsn32[el]
  linux-user: Add default configs for mips64[el]
  linux-user: Define TARGET_QEMU_ESIGRETURN for mipsn32
  linux-user: Define TARGET_QEMU_ESIGRETURN for mips64
  linux-user: Fix sa_flags byte swaps for mips

Peter Maydell (4):
  linux-user/strace.c: Correct errno printing for mmap etc
  linux-user: Allow NULL value pointer in setxattr and getxattr
  linux-user/syscall.c: Implement f and l versions of
set/get/removexattr
  linux-user: Implement *listxattr syscalls

Riku Voipio (1):
  linux-user: stack_base is now mandatory on all targets

陳韋任 (1):
  linux-user/main.c: Add option to user-mode emulation so that user can
specify log file name

 default-configs/mips64-linux-user.mak|1 +
 default-configs/mips64el-linux-user.mak  |1 +
 default-configs/mipsn32-linux-user.mak   |1 +
 default-configs/mipsn32el-linux-user.mak |1 +
 linux-user/elfload.c |   15 +-
 linux-user/main.c|7 +
 linux-user/mips64/syscall.h  |3 +
 linux-user/mipsn32/syscall.h |3 +
 linux-user/qemu.h|3 +-
 linux-user/signal.c  |8 +
 linux-user/strace.c  |   19 ++-
 linux-user/syscall.c |  303 +++---
 linux-user/syscall_defs.h|6 +
 13 files changed, 332 insertions(+), 39 deletions(-)
 create mode 100644 default-configs/mips64-linux-user.mak
 create mode 100644 default-configs/mips64el-linux-user.mak
 create mode 100644 default-configs/mipsn32-linux-user.mak
 create mode 100644 default-configs/mipsn32el-linux-user.mak

-- 
1.7.5.4




Re: [Qemu-devel] [PATCH 01/16] qdev: fix hot-unplug

2012-02-03 Thread Anthony Liguori

On 02/02/2012 01:07 PM, Alexander Graf wrote:


On 02.02.2012, at 20:01, Anthony Liguori wrote:


On 02/02/2012 11:29 AM, Paolo Bonzini wrote:

On 02/02/2012 06:03 PM, Anthony Liguori wrote:




Is this still needed with qom-upstream.14? I fixed a bug on .14 that
involved child properties that was making device-del sometimes fail.


Not sure, I tried with .13 but, from the look of it, it should still be there.
Regarding the .13->.14 diff:

- you need QTAILQ_FOREACH_SAFE in object_property_del_child.


Ack.



- you need to check for the existence of the non-aliased name when accessing the
alias table, because s390 does not have PCI.


I don't think that's the right strategy as it means that s390 only works if we 
don't include the PCI objects in the build (regardless of whether it uses PCI). 
 This would be defeated if/when we move to having all device objects in a 
single shared library used by all of the qemu executables.

I'd prefer to just drop the aliases for s390.  I don't see a lot of value in it 
and I don't think there are tons of s390 users that will be affected.


The reason for the aliases is to make -drive and -net work. If you have 
alternatives to aliases there, I'm happy to go with them.


Um, but I see (in s390-virtio.c):


for(i = 0; i < nb_nics; i++) {
NICInfo *nd = &nd_table[i];
DeviceState *dev;

if (!nd->model) {
nd->model = g_strdup("virtio");
}

if (strcmp(nd->model, "virtio")) {
fprintf(stderr, "S390 only supports VirtIO nics\n");
exit(1);
}

dev = qdev_create((BusState *)s390_bus, "virtio-net-s390");
qdev_set_nic_properties(dev, nd);
qdev_init_nofail(dev);
}

/* Create VirtIO disk drives */
for(i = 0; i < MAX_BLK_DEVS; i++) {
DriveInfo *dinfo;
DeviceState *dev;

dinfo = drive_get(IF_IDE, 0, i);
if (!dinfo) {
continue;
}

dev = qdev_create((BusState *)s390_bus, "virtio-blk-s390");
qdev_prop_set_drive_nofail(dev, "drive", dinfo->bdrv);
qdev_init_nofail(dev);
}

So s390 totally ignores the -drive if parameter and will only accept virtio for 
-net.


From what I can tell, it's not an issue.  But if we need it, we can do:

diff --git a/arch_init.h b/arch_init.h
index 828256c..bfbd9e1 100644
--- a/arch_init.h
+++ b/arch_init.h
@@ -32,4 +32,9 @@ int tcg_available(void);
 int kvm_available(void);
 int xen_available(void);

+static inline int target_get_arch(void)
+{
+return arch_type;
+}
+
 #endif
diff --git a/blockdev.c b/blockdev.c
index 7e4c548..caa9205 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -565,7 +565,15 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
 case IF_VIRTIO:
 /* add virtio block device */
 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
-qemu_opt_set(opts, "driver", "virtio-blk");
+switch(target_get_arch()) {
+case QEMU_ARCH_S390X:
+qemu_opt_set(opts, "driver", "virtio-blk-s390");
+break;
+default:
+qemu_opt_set(opts, "driver", "virtio-blk-pci");
+break;
+}
+
 qemu_opt_set(opts, "drive", dinfo->id);
 if (devaddr)
 qemu_opt_set(opts, "addr", devaddr);
diff --git a/blockdev.c b/blockdev.c
index 7e4c548..caa9205 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -565,7 +565,15 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
 case IF_VIRTIO:
 /* add virtio block device */
 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
-qemu_opt_set(opts, "driver", "virtio-blk");
+switch(target_get_arch()) {
+case QEMU_ARCH_S390X:
+qemu_opt_set(opts, "driver", "virtio-blk-s390");
+break;
+default:
+qemu_opt_set(opts, "driver", "virtio-blk-pci");
+break;
+}
+
 qemu_opt_set(opts, "drive", dinfo->id);
 if (devaddr)
 qemu_opt_set(opts, "addr", devaddr);


Can you confirm what we actually need here?

Regards,

Anthony Liguori




Alex







Re: [Qemu-devel] [PATCH v2 0/8] qemu-ga: add support for Windows

2012-02-03 Thread Luiz Capitulino
On Fri, 03 Feb 2012 10:37:25 -0600
Michael Roth  wrote:

> On 02/03/2012 08:18 AM, Luiz Capitulino wrote:
> > On Thu,  2 Feb 2012 13:58:52 -0600
> > Michael Roth  wrote:
> >
> >> These patches apply on top of qemu.git master, and can also be obtained 
> >> from:
> >> git://github.com/mdroth/qemu.git qga-win32-v2
> >>
> >> Luiz/Gal, I decided not to roll the suspend/hibernate stuff into this 
> >> series
> >> since the s3 situation isn't fully sorted out yet. The file structure is a
> >> little different now, posix/linux-specific stuff goes in 
> >> qga/commands-posix.c,
> >> win32-specific stuff in qga/commands-win32.c, but other than that it 
> >> should be
> >> a straightforward rebase if this gets merged first.
> >
> > I think I'll have to rebase my series on top of this one, when do you plan 
> > to
> > merge this?
> >
> 
> Hopefully soon, was planning on waiting for the suspend/hibernate bits 
> but we seem to be blocked on the s3 issues and I have other patches 
> accumulating on top of win32 (hesitant to base those on master since 
> this patchset does a lot of refactoring that might affect them), so I 
> figured I'd push this for merge since it doesn't have any dependencies 
> outside master.

The S3 issues seem sorted to me, but I don't oppose having this series in first.



Re: [Qemu-devel] [PATCH v2 0/8] qemu-ga: add support for Windows

2012-02-03 Thread Michael Roth

On 02/03/2012 08:18 AM, Luiz Capitulino wrote:

On Thu,  2 Feb 2012 13:58:52 -0600
Michael Roth  wrote:


These patches apply on top of qemu.git master, and can also be obtained from:
git://github.com/mdroth/qemu.git qga-win32-v2

Luiz/Gal, I decided not to roll the suspend/hibernate stuff into this series
since the s3 situation isn't fully sorted out yet. The file structure is a
little different now, posix/linux-specific stuff goes in qga/commands-posix.c,
win32-specific stuff in qga/commands-win32.c, but other than that it should be
a straightforward rebase if this gets merged first.


I think I'll have to rebase my series on top of this one, when do you plan to
merge this?



Hopefully soon, was planning on waiting for the suspend/hibernate bits 
but we seem to be blocked on the s3 issues and I have other patches 
accumulating on top of win32 (hesitant to base those on master since 
this patchset does a lot of refactoring that might affect them), so I 
figured I'd push this for merge since it doesn't have any dependencies 
outside master.





Re: [Qemu-devel] [PATCH 01/16] qdev: fix hot-unplug

2012-02-03 Thread Alexander Graf


On 03.02.2012, at 17:37, Anthony Liguori  wrote:

> On 02/02/2012 01:07 PM, Alexander Graf wrote:
>> 
>> On 02.02.2012, at 20:01, Anthony Liguori wrote:
>> 
>>> On 02/02/2012 11:29 AM, Paolo Bonzini wrote:
 On 02/02/2012 06:03 PM, Anthony Liguori wrote:
>> 
> 
> Is this still needed with qom-upstream.14? I fixed a bug on .14 that
> involved child properties that was making device-del sometimes fail.
 
 Not sure, I tried with .13 but, from the look of it, it should still be 
 there.
 Regarding the .13->.14 diff:
 
 - you need QTAILQ_FOREACH_SAFE in object_property_del_child.
>>> 
>>> Ack.
>>> 
 
 - you need to check for the existence of the non-aliased name when 
 accessing the
 alias table, because s390 does not have PCI.
>>> 
>>> I don't think that's the right strategy as it means that s390 only works if 
>>> we don't include the PCI objects in the build (regardless of whether it 
>>> uses PCI).  This would be defeated if/when we move to having all device 
>>> objects in a single shared library used by all of the qemu executables.
>>> 
>>> I'd prefer to just drop the aliases for s390.  I don't see a lot of value 
>>> in it and I don't think there are tons of s390 users that will be affected.
>> 
>> The reason for the aliases is to make -drive and -net work. If you have 
>> alternatives to aliases there, I'm happy to go with them.
> 
> Um, but I see (in s390-virtio.c):
> 
> 
>for(i = 0; i < nb_nics; i++) {
>NICInfo *nd = &nd_table[i];
>DeviceState *dev;
> 
>if (!nd->model) {
>nd->model = g_strdup("virtio");
>}
> 
>if (strcmp(nd->model, "virtio")) {
>fprintf(stderr, "S390 only supports VirtIO nics\n");
>exit(1);
>}
> 
>dev = qdev_create((BusState *)s390_bus, "virtio-net-s390");
>qdev_set_nic_properties(dev, nd);
>qdev_init_nofail(dev);
>}
> 
>/* Create VirtIO disk drives */
>for(i = 0; i < MAX_BLK_DEVS; i++) {
>DriveInfo *dinfo;
>DeviceState *dev;
> 
>dinfo = drive_get(IF_IDE, 0, i);
>if (!dinfo) {
>continue;
>}
> 
>dev = qdev_create((BusState *)s390_bus, "virtio-blk-s390");
>qdev_prop_set_drive_nofail(dev, "drive", dinfo->bdrv);
>qdev_init_nofail(dev);
>}
> 
> So s390 totally ignores the -drive if

Nope, since virtio drives aren't handled through the IF_ legacy stuff but 
through qden instantiation. We only fake virtio disks for -hda here (which 
should be replaced by a default_virtio option in the machine config).

> parameter and will only accept virtio for -net.

It only supports virtio at all, yes. No MMIO there ;).

> 
> From what I can tell, it's not an issue.  But if we need it, we can do:
> 
> diff --git a/arch_init.h b/arch_init.h
> index 828256c..bfbd9e1 100644
> --- a/arch_init.h
> +++ b/arch_init.h
> @@ -32,4 +32,9 @@ int tcg_available(void);
> int kvm_available(void);
> int xen_available(void);
> 
> +static inline int target_get_arch(void)
> +{
> +return arch_type;

We could also have a machine type field that could be PCI or S390, right? I 
somehow don't like globals.

And just because it's s390 doesn't tell us anything. Maybe someone clever will 
find a way to expose PCI in a later machine type and use that for all devices?

The same thing goes for arm and their mmio virtio too btw.

> +}
> +
> #endif
> diff --git a/blockdev.c b/blockdev.c
> index 7e4c548..caa9205 100644
> --- a/blockdev.c
> +++ b/blockdev.c
> @@ -565,7 +565,15 @@ DriveInfo *drive_init(QemuOpts *opts, int 
> default_to_scsi)
> case IF_VIRTIO:
> /* add virtio block device */
> opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
> -qemu_opt_set(opts, "driver", "virtio-blk");
> +switch(target_get_arch()) {
> +case QEMU_ARCH_S390X:
> +qemu_opt_set(opts, "driver", "virtio-blk-s390");
> +break;
> +default:
> +qemu_opt_set(opts, "driver", "virtio-blk-pci");
> +break;
> +}
> +
> qemu_opt_set(opts, "drive", dinfo->id);
> if (devaddr)
> qemu_opt_set(opts, "addr", devaddr);
> diff --git a/blockdev.c b/blockdev.c
> index 7e4c548..caa9205 100644
> --- a/blockdev.c
> +++ b/blockdev.c
> @@ -565,7 +565,15 @@ DriveInfo *drive_init(QemuOpts *opts, int 
> default_to_scsi)
> case IF_VIRTIO:
> /* add virtio block device */
> opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
> -qemu_opt_set(opts, "driver", "virtio-blk");
> +switch(target_get_arch()) {
> +case QEMU_ARCH_S390X:
> +qemu_opt_set(opts, "driver", "virtio-blk-s390");
> +break;
> +default:
> +qemu_opt_set(opts, "driver", "virtio-blk-pci");
> +break;
> +}
> +
> qemu_opt_set(opts, "drive", dinfo->id);
> if (devaddr)
> qemu_opt_set(opts, "ad

Re: [Qemu-devel] [PATCH v2 2/8] qemu-ga: move channel/transport functionalit

2012-02-03 Thread Michael Roth

On 02/02/2012 10:25 PM, MATSUDA, Daiki wrote:

Hi, Michael!
Thank you for your working.

And I have a question the process id written in pid file.
If qemu-ga is ran as daemon, the parent process id not child is written
in pid file. So, id gotten by 'ps' command is different. Is it correct
work? Many other daemon writes child process id.

Regards
MATSUDA Daiki



Hi Matsuda,

Thank you for testing!

In the become_daemon() function, the parent exits immediately after the 
fork(), so only the child has the opportunity to write to the pid file. 
It calls getpid() to get the pid to write, which should be it's own 
lwpid. So I'm not seeing where there's an opportunity for the parent pid 
to be written.


Can you confirm? It seems to behave as expected for me:

[root@vm ~]# /home/mdroth/w/qemu-build/qemu-ga -d
** (process:7441): DEBUG: starting daemon
[root@vm ~]# ps aux | grep qemu-ga
root  7442  0.0  0.0  13792   348 ?Ss   10:56   0:00 
/home/mdroth/w/qemu-build/qemu-ga -d
root  7471  0.0  0.1 109108   816 pts/2R+   11:00   0:00 grep 
--color=auto qemu-ga

[root@vm ~]# cat /var/run/qemu-ga.pid
7442




Re: [Qemu-devel] [PATCH 01/16] qdev: fix hot-unplug

2012-02-03 Thread Anthony Liguori

On 02/03/2012 10:57 AM, Alexander Graf wrote:



On 03.02.2012, at 17:37, Anthony Liguori  wrote:


On 02/02/2012 01:07 PM, Alexander Graf wrote:


On 02.02.2012, at 20:01, Anthony Liguori wrote:


On 02/02/2012 11:29 AM, Paolo Bonzini wrote:

On 02/02/2012 06:03 PM, Anthony Liguori wrote:




Is this still needed with qom-upstream.14? I fixed a bug on .14 that
involved child properties that was making device-del sometimes fail.


Not sure, I tried with .13 but, from the look of it, it should still be there.
Regarding the .13->.14 diff:

- you need QTAILQ_FOREACH_SAFE in object_property_del_child.


Ack.



- you need to check for the existence of the non-aliased name when accessing the
alias table, because s390 does not have PCI.


I don't think that's the right strategy as it means that s390 only works if we 
don't include the PCI objects in the build (regardless of whether it uses PCI). 
 This would be defeated if/when we move to having all device objects in a 
single shared library used by all of the qemu executables.

I'd prefer to just drop the aliases for s390.  I don't see a lot of value in it 
and I don't think there are tons of s390 users that will be affected.


The reason for the aliases is to make -drive and -net work. If you have 
alternatives to aliases there, I'm happy to go with them.


Um, but I see (in s390-virtio.c):


for(i = 0; i<  nb_nics; i++) {
NICInfo *nd =&nd_table[i];
DeviceState *dev;

if (!nd->model) {
nd->model = g_strdup("virtio");
}

if (strcmp(nd->model, "virtio")) {
fprintf(stderr, "S390 only supports VirtIO nics\n");
exit(1);
}

dev = qdev_create((BusState *)s390_bus, "virtio-net-s390");
qdev_set_nic_properties(dev, nd);
qdev_init_nofail(dev);
}

/* Create VirtIO disk drives */
for(i = 0; i<  MAX_BLK_DEVS; i++) {
DriveInfo *dinfo;
DeviceState *dev;

dinfo = drive_get(IF_IDE, 0, i);
if (!dinfo) {
continue;
}

dev = qdev_create((BusState *)s390_bus, "virtio-blk-s390");
qdev_prop_set_drive_nofail(dev, "drive", dinfo->bdrv);
qdev_init_nofail(dev);
}

So s390 totally ignores the -drive if


Nope, since virtio drives aren't handled through the IF_ legacy stuff but 
through qden instantiation. We only fake virtio disks for -hda here (which 
should be replaced by a default_virtio option in the machine config).


parameter and will only accept virtio for -net.


It only supports virtio at all, yes. No MMIO there ;).



 From what I can tell, it's not an issue.  But if we need it, we can do:

diff --git a/arch_init.h b/arch_init.h
index 828256c..bfbd9e1 100644
--- a/arch_init.h
+++ b/arch_init.h
@@ -32,4 +32,9 @@ int tcg_available(void);
int kvm_available(void);
int xen_available(void);

+static inline int target_get_arch(void)
+{
+return arch_type;


We could also have a machine type field that could be PCI or S390, right? I 
somehow don't like globals.

And just because it's s390 doesn't tell us anything. Maybe someone clever will 
find a way to expose PCI in a later machine type and use that for all devices?

The same thing goes for arm and their mmio virtio too btw.


Right, you're just pointing out though that the current code is dumb.  I full 
heartedly agree with you :-)


If you added PCI to the build for s390, aliases wouldn't do what you expect 
anymore.




+}
+
#endif
diff --git a/blockdev.c b/blockdev.c
index 7e4c548..caa9205 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -565,7 +565,15 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
 case IF_VIRTIO:
 /* add virtio block device */
 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
-qemu_opt_set(opts, "driver", "virtio-blk");
+switch(target_get_arch()) {
+case QEMU_ARCH_S390X:
+qemu_opt_set(opts, "driver", "virtio-blk-s390");
+break;
+default:
+qemu_opt_set(opts, "driver", "virtio-blk-pci");
+break;
+}
+
 qemu_opt_set(opts, "drive", dinfo->id);
 if (devaddr)
 qemu_opt_set(opts, "addr", devaddr);
diff --git a/blockdev.c b/blockdev.c
index 7e4c548..caa9205 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -565,7 +565,15 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
 case IF_VIRTIO:
 /* add virtio block device */
 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
-qemu_opt_set(opts, "driver", "virtio-blk");
+switch(target_get_arch()) {
+case QEMU_ARCH_S390X:
+qemu_opt_set(opts, "driver", "virtio-blk-s390");
+break;
+default:
+qemu_opt_set(opts, "driver", "virtio-blk-pci");
+break;
+}
+
 qemu_opt_set(opts, "drive", dinfo->id);
 if (devaddr)
 qemu_opt_set(opts, "addr", devaddr);


Can you confirm what we actuall

[Qemu-devel] [PATCH] s390x: fix -drive in the absence of aliases

2012-02-03 Thread Anthony Liguori
Signed-off-by: Anthony Liguori 
---
 blockdev.c |6 +-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index 7e4c548..7d7ac31 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -565,7 +565,11 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
 case IF_VIRTIO:
 /* add virtio block device */
 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
-qemu_opt_set(opts, "driver", "virtio-blk");
+if (arch_type == QEMU_ARCH_S390X) {
+qemu_opt_set(opts, "driver", "virtio-blk-s390");
+} else {
+qemu_opt_set(opts, "driver", "virtio-blk-pci");
+}
 qemu_opt_set(opts, "drive", dinfo->id);
 if (devaddr)
 qemu_opt_set(opts, "addr", devaddr);
-- 
1.7.4.1




Re: [Qemu-devel] [PATCH 00/22] qom: use Type system to register all devices (v2)

2012-02-03 Thread Anthony Liguori

On 02/01/2012 01:50 PM, Anthony Liguori wrote:

This is the 3rd QOM series.  All known issues have been resolved.  This has been
extensively tested (including for bisectability).  I think this is ready to
apply.

The goal of this series is to make DeviceState a first class QOM base class.
The result is that you can object_new(TYPE_E1000) and have a functioning
device.  qdev_create() and qdev_free() are now trivialized as QOM wrappers.

Patch 8/23 is an automated touch everything patch.  I decided to leave it as
one big patch because this is entirely programmatic.  There's no intelligence
in this patch so I think it's easier to review quickly as one big change.

The other notable feature of this series it that properties have been moved to
the Object base class.  This means that other subsystems can begin using QOM.

This is the last touch every file in the tree series.


Applied.

Regards,

Anthony Liguori



  b/Makefile.objs  |4
  b/hw/9pfs/virtio-9p-device.c |   16
  b/hw/a9mpcore.c  |   40 -
  b/hw/ac97.c  |   18
  b/hw/acpi_piix4.c|   20
  b/hw/ads7846.c   |   11
  b/hw/alpha_typhoon.c |   14
  b/hw/apb_pci.c   |   41 -
  b/hw/apic.c  |   10
  b/hw/apic_common.c   |   15
  b/hw/apic_internal.h |1
  b/hw/applesmc.c  |   28 -
  b/hw/arm11mpcore.c   |   28 -
  b/hw/arm_l2x0.c  |   24
  b/hw/arm_mptimer.c   |   28 -
  b/hw/arm_sysctl.c|   18
  b/hw/arm_timer.c |   35 -
  b/hw/armv7m.c|   14
  b/hw/armv7m_nvic.c   |   32 -
  b/hw/bitbang_i2c.c   |   14
  b/hw/bonito.c|   32 -
  b/hw/ccid-card-emulated.c|   35 -
  b/hw/ccid-card-passthru.c|   28 -
  b/hw/ccid.h  |1
  b/hw/cirrus_vga.c|   30 -
  b/hw/cs4231.c|   18
  b/hw/cs4231a.c   |   30 -
  b/hw/debugcon.c  |   26
  b/hw/dec_pci.c   |   40 -
  b/hw/ds1225y.c   |   16
  b/hw/ds1338.c|   11
  b/hw/e1000.c |   20
  b/hw/eccmemctl.c |   18
  b/hw/eepro100.c  |   83 +--
  b/hw/empty_slot.c|   11
  b/hw/es1370.c|   16
  b/hw/escc.c  |   18
  b/hw/esp.c   |   18
  b/hw/etraxfs_eth.c   |   14
  b/hw/etraxfs_pic.c   |   14
  b/hw/etraxfs_ser.c   |   16
  b/hw/etraxfs_timer.c |   11
  b/hw/fdc.c   |   76 +-
  b/hw/fw_cfg.c|   20
  b/hw/g364fb.c|   20
  b/hw/grackle_pci.c   |   26
  b/hw/grlib_apbuart.c |   14
  b/hw/grlib_gptimer.c |   16
  b/hw/grlib_irqmp.c   |   16
  b/hw/gt64xxx.c   |   22
  b/hw/gus.c   |   32 -
  b/hw/hda-audio.c |   36 -
  b/hw/highbank.c  |   18
  b/hw/hpet.c  |   20
  b/hw/i2c.c   |   23
  b/hw/i2c.h   |3
  b/hw/i82374.c|   22
  b/hw/i82378.c|   22
  b/hw/i8254.c |   30 -
  b/hw/i8259.c |   11
  b/hw/i8259_common.c  |   13
  b/hw/i8259_internal.h|1
  b/hw/ide/ahci.c  |   24
  b/hw/ide/cmd646.c|   14
  b/hw/ide/ich.c   |   15
  b/hw/ide/isa.c   |   30 -
  b/hw/ide/piix.c  |   44 -
  b/hw/ide/qdev.c  |   95 ++-
  b/hw/ide/via.c   |   14
  b/hw/integratorcp.c  |   25
  b/hw/intel-hda.c |   39 -
  b/hw/intel-hda.h |1
  b/hw/ioapic.c|   14
  b/hw/ioapic_common.c |   10
  b/hw/ioapic_internal.h   |1
  b/hw/ioh3420.c   |   20
  b/hw/isa-bus.c   |   38 -
  b/hw/isa.h   |2
  b/hw/ivshmem.c   |   16
  b/hw/kvm/apic.c  |5
  b/hw/kvm/clock.c |   16
  b/hw/kvm/i8259.c |8
  b/hw/kvm/ioapic.c|   20
  b/hw/lan9118.c   |   18
  b/hw/lance.c |   20
  b/hw/lm32_juart.c|   18
  b/hw/lm32_pic.c  |   16
  b/hw/lm32_sys.c  |   18
  b/hw/lm32_timer.c|   18
  b/hw/lm32_uart.c |   18
  b/hw/lm832x.c|   14
  b/hw/lsi53c895a.c|   17
  b/hw/m48t59.c|   46 -
  b/hw/macio.c |   11
  b/hw/marvell_88w8618_audio.c |   18
  b/hw/max111x.c   |   22
  b/hw/max7310.c   |   16
  b/hw/mc146818rtc.c   |   34 -
  b/hw/milkymist-ac97.c|   16
  b/hw/milkymist-hpdmc.c   |   16
  b/hw/milkymist-memcard.c |   16
  b/hw/milkymist-minimac2.c|   18
  b/hw/milkymist-pfpu.c|   16
  b/hw/milkymist-softusb.c |   18
  b/hw/milkymist-sysctl.c  |   18
  b/hw/milkymist-tmu2.c   

Re: [Qemu-devel] [PATCH v8 0/4] -net bridge: rootless bridge support for qemu

2012-02-03 Thread Anthony Liguori

On 01/26/2012 08:42 AM, Corey Bryant wrote:

With qemu it is possible to run a guest from an unprivileged user but if
we wanted to communicate with the outside world we had to switch
to root.

We address this problem by introducing a new network backend and a new
network option for -net tap.  This is less flexible when compared to
existing -net tap options because it relies on a helper with elevated
privileges to do the heavy lifting of allocating and attaching a tap
device to a bridge.  We use a special purpose helper because we don't
want to elevate the privileges of more generic tools like brctl.

Qemu can be run with the default network helper as follows (in these cases
attaching the tap device to the default br0 bridge):

   qemu linux.img -net bridge -net nic,model=virtio

   qemu linux.img -net tap,helper="/usr/local/libexec/qemu-bridge-helper"
  -net nic,model=virtio

   qemu linux.img -netdev bridge,id=hn0
  -device virtio-net-pci,netdev=hn0,id=nic1

   qemu linux.img -netdev 
tap,"helper=/usr/local/libexec/qemu-bridge-helper",id=hn0
  -device virtio-net-pci,netdev=hn0,id=nic1

The default helper uses it's own ACL mechanism for access control, but
future network helpers could be developed, for example, to support PolicyKit
for access control.

More details are included in individual patches.  The helper is broken into
a series of patches to improve reviewabilty.


Applied.  Thanks.

Regards,

Anthony Liguori



v2:
  - Updated signed-off-by's
  - Updated author's email
  - Set default bridge to br0
  - Added -net bridge
  - Updated ACL example
  - Moved from libcap to libcap-ng
  - Fail helper when libcap-ng not configured

v3:
  - Use simple queue to store ACLs
  - Added goto cleanup to helper's main
  - Allow helper execution if libcap-ng not configured
  - Completed static analysis and memory analysis on helper

v4:
  - Update has_vnet_hdr() to return bool
  - Update helper's main() to prevent errno clobbering
  - Let Kernel cleanup helper's file descriptors

v5:
  - Removed if statement with TUNGETIFF ioctl() from has_vnet_hdr()
  - Added -netdev examples and udpated qemu -help netdev documentation
  - Disallow vnet_hdr option with -net tap,helper

v6:
  - Fixed uninitialized variable (TAPState *s) in net_tap_init()

v7:
  - Added options --br= and --fd= to default network helper
  - Updated -netdev tap,helper= to accept a command
  - Removed br option from -netdev tap

v8:
  - Rebased on top of commit 5b4448d27d7c6ff6e18a1edc8245cb1db783e37c
  - Rebase required changes in configure script for libcap-ng config

Corey Bryant (4):
   Add basic version of bridge helper
   Add access control support to qemu bridge helper
   Add cap reduction support to enable use as SUID
   Add support for net bridge

  Makefile |   12 ++-
  configure|   37 +
  net.c|   25 +++-
  net.h|3 +
  net/tap.c|  204 -
  net/tap.h|3 +
  qemu-bridge-helper.c |  410 ++
  qemu-options.hx  |   73 --
  8 files changed, 748 insertions(+), 19 deletions(-)
  create mode 100644 qemu-bridge-helper.c






Re: [Qemu-devel] [PATCH v2] keep the PID file locked for the lifetime of the process

2012-02-03 Thread Anthony Liguori

On 01/27/2012 07:34 AM, Laszlo Ersek wrote:

The lockf() call in qemu_create_pidfile() aims at ensuring mutual
exclusion. We shouldn't close the pidfile on success (as introduced by
commit 1bbd1592), because that drops the lock as well [1]:

 "File locks shall be released on first close by the locking process
 of any file descriptor for the file."

Coverity may complain again about the leaked file descriptor; let's
worry about that later.

v1->v2:
- add reference to 1bbd1592
- explain the intentional fd leak in the source

[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/lockf.html


Applied.  Thanks.

Regards,

Anthony Liguori



Signed-off-by: Laszlo Ersek
---
  os-posix.c |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 5c437ca..e3ed497 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -348,6 +348,6 @@ int qemu_create_pidfile(const char *filename)
  return -1;
  }

-close(fd);
+/* keep pidfile open&  locked forever */
  return 0;
  }





Re: [Qemu-devel] [PATCH] hw/vmmouse.c: Disable vmmouse after reboot

2012-02-03 Thread Anthony Liguori

On 01/25/2012 02:04 PM, Gerhard Wiesinger wrote:

Bugfix after reboot when vmmouse was enabled and another OS which uses e.g. PS/2
mouse.

Details:
When a guest activated the vmmouse followed by a reboot the vmmouse was still
enabled and the PS/2 mouse was therefore unsusable. When another guest is then
booted without vmmouse support (e.g. PS/2 mouse) the mouse is not working.

Reason is that VMMouse has priority and disables all other mouse entities
and therefore must be disabled on reset.

Testscenario:
1.) Boot e.g. OS with VMMouse support (e.g. Windows with VMMouse tools)
2.) reboot
3.) Boot e.g. OS without VMMouse support (e.g. DOS) => PS/2 mouse doesn't work
any more. Fixes that issue.

Testscenario 2 by Jan Kiszka :
Confirm that this patch fixes a real issue. Setup: qemu.git,
opensuse 11.4 guest, SDL graphic, system_reset while guest is using the
vmmouse. Without the patch, the vmmouse become unusable after the
reboot. Also, the mouse stays in absolute mode even before X starts again.

Fixed by:
Disabling the vmmouse in its reset handler.

Signed-off-by: Gerhard Wiesinger 


Applied.  Thanks.

Regards,

Anthony Liguori


---
hw/vmmouse.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/hw/vmmouse.c b/hw/vmmouse.c
index 1113f33..f9f5b53 100644
--- a/hw/vmmouse.c
+++ b/hw/vmmouse.c
@@ -254,6 +254,8 @@ static void vmmouse_reset(DeviceState *d)

s->status = 0x;
s->queue_size = VMMOUSE_QUEUE_SIZE;
+
+ vmmouse_disable(s);
}

static int vmmouse_initfn(ISADevice *dev)





Re: [Qemu-devel] [PATCH] Change license from GPLv2 to GPLv2+

2012-02-03 Thread Anthony Liguori

On 01/27/2012 10:40 AM, Stefan Weil wrote:

This file only contains code from Red Hat, so it can use GPLv2+.
Tested with `git blame -M -C net/checksum.c`.

Signed-off-by: Stefan Weil


Applied.  Thanks.

Regards,

Anthony Liguori


---
  net/checksum.c |5 +
  1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/net/checksum.c b/net/checksum.c
index 264c23f..9919b2e 100644
--- a/net/checksum.c
+++ b/net/checksum.c
@@ -4,7 +4,7 @@
   *
   *  This program is free software; you can redistribute it and/or modify
   *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; under version 2 of the License.
+ *  the Free Software Foundation; under version 2 or later of the License.
   *
   *  This program is distributed in the hope that it will be useful,
   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,9 +13,6 @@
   *
   *  You should have received a copy of the GNU General Public License
   *  along with this program; if not, see.
- *
- *  Contributions after 2012-01-13 are licensed under the terms of the
- *  GNU GPL, version 2 or (at your option) any later version.
   */

  #include "net/checksum.h"





Re: [Qemu-devel] [PATCH] s390x: fix -drive in the absence of aliases

2012-02-03 Thread Anthony Liguori

On 02/03/2012 11:18 AM, Anthony Liguori wrote:

Signed-off-by: Anthony Liguori
---
  blockdev.c |6 +-
  1 files changed, 5 insertions(+), 1 deletions(-)


*sigh*

my work directory was dirty.  This needs a #include "arch_init.h" too.

Regards,

Anthony Liguori



diff --git a/blockdev.c b/blockdev.c
index 7e4c548..7d7ac31 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -565,7 +565,11 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
  case IF_VIRTIO:
  /* add virtio block device */
  opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
-qemu_opt_set(opts, "driver", "virtio-blk");
+if (arch_type == QEMU_ARCH_S390X) {
+qemu_opt_set(opts, "driver", "virtio-blk-s390");
+} else {
+qemu_opt_set(opts, "driver", "virtio-blk-pci");
+}
  qemu_opt_set(opts, "drive", dinfo->id);
  if (devaddr)
  qemu_opt_set(opts, "addr", devaddr);





Re: [Qemu-devel] [PATCH v2 0/8] qemu-ga: add support for Windows

2012-02-03 Thread Michael Roth

On 02/03/2012 10:45 AM, Luiz Capitulino wrote:

On Fri, 03 Feb 2012 10:37:25 -0600
Michael Roth  wrote:


On 02/03/2012 08:18 AM, Luiz Capitulino wrote:

On Thu,  2 Feb 2012 13:58:52 -0600
Michael Roth   wrote:


These patches apply on top of qemu.git master, and can also be obtained from:
git://github.com/mdroth/qemu.git qga-win32-v2

Luiz/Gal, I decided not to roll the suspend/hibernate stuff into this series
since the s3 situation isn't fully sorted out yet. The file structure is a
little different now, posix/linux-specific stuff goes in qga/commands-posix.c,
win32-specific stuff in qga/commands-win32.c, but other than that it should be
a straightforward rebase if this gets merged first.


I think I'll have to rebase my series on top of this one, when do you plan to
merge this?



Hopefully soon, was planning on waiting for the suspend/hibernate bits
but we seem to be blocked on the s3 issues and I have other patches
accumulating on top of win32 (hesitant to base those on master since
this patchset does a lot of refactoring that might affect them), so I
figured I'd push this for merge since it doesn't have any dependencies
outside master.


The S3 issues seem sorted to me, but I don't oppose having this series in first.



Thanks, in retrospect I probably should've just gotten these out of the 
way weeks ago since they'd immediately clobber git blame.


I'd been tracking Gerd's QMP wakeup series as the s3 resolution we need 
for guest-suspend, is that still the case? I guess those are coming 
through your QMP queue?





Re: [Qemu-devel] [PATCH] hw/vmmouse.c: Disable vmmouse after reboot

2012-02-03 Thread Gerhard Wiesinger

On Fri, 3 Feb 2012, Anthony Liguori wrote:


On 01/25/2012 02:04 PM, Gerhard Wiesinger wrote:
Bugfix after reboot when vmmouse was enabled and another OS which uses e.g. 
PS/2

mouse.

Details:
When a guest activated the vmmouse followed by a reboot the vmmouse was 
still
enabled and the PS/2 mouse was therefore unsusable. When another guest is 
then

booted without vmmouse support (e.g. PS/2 mouse) the mouse is not working.

Reason is that VMMouse has priority and disables all other mouse entities
and therefore must be disabled on reset.

Testscenario:
1.) Boot e.g. OS with VMMouse support (e.g. Windows with VMMouse tools)
2.) reboot
3.) Boot e.g. OS without VMMouse support (e.g. DOS) => PS/2 mouse doesn't 
work

any more. Fixes that issue.

Testscenario 2 by Jan Kiszka :
Confirm that this patch fixes a real issue. Setup: qemu.git,
opensuse 11.4 guest, SDL graphic, system_reset while guest is using the
vmmouse. Without the patch, the vmmouse become unusable after the
reboot. Also, the mouse stays in absolute mode even before X starts again.

Fixed by:
Disabling the vmmouse in its reset handler.

Signed-off-by: Gerhard Wiesinger 


Applied.  Thanks.

Regards,

Anthony Liguori


Thanks.

BTW: Why are always "signed offs" generated when a maintainer commits?
e.g. 069ab0eb8a46bc4ff6f4d4d81bf037d3441347da
Signed-off-by: Anthony Liguori 

Ciao,
Gerhard

--
http://www.wiesinger.com/



Re: [Qemu-devel] [RFC] Next gen kvm api

2012-02-03 Thread Eric Northup
On Thu, Feb 2, 2012 at 8:09 AM, Avi Kivity  wrote:
[...]
>
> Moving to syscalls avoids these problems, but introduces new ones:
>
> - adding new syscalls is generally frowned upon, and kvm will need several
> - syscalls into modules are harder and rarer than into core kernel code
> - will need to add a vcpu pointer to task_struct, and a kvm pointer to
> mm_struct
- Lost a good place to put access control (permissions on /dev/kvm)
for which user-mode processes can use KVM.

How would the ability to use sys_kvm_* be regulated?



[Qemu-devel] [PATCH v4 2/7] hw/vexpress.c: Make motherboard peripheral memory map table-driven

2012-02-03 Thread Peter Maydell
Pull the addresses used for mapping motherboard peripherals into
memory out into a table. This will allow us to simply provide a
second table to implement the "Cortex-A Series" memory map used by
the A15 variant of Versatile Express, as well as the current
"Legacy" map used by A9.

Signed-off-by: Peter Maydell 
Reviewed-by: Andreas Färber 
---
 hw/vexpress.c |  137 +++--
 1 files changed, 103 insertions(+), 34 deletions(-)

diff --git a/hw/vexpress.c b/hw/vexpress.c
index 64fab45..8c4d3b3 100644
--- a/hw/vexpress.c
+++ b/hw/vexpress.c
@@ -31,13 +31,80 @@
 #include "exec-memory.h"
 
 #define SMP_BOOT_ADDR 0xe000
-#define SMP_BOOTREG_ADDR 0x1030
 
 #define VEXPRESS_BOARD_ID 0x8e0
 
 static struct arm_boot_info vexpress_binfo = {
 .smp_loader_start = SMP_BOOT_ADDR,
-.smp_bootreg_addr = SMP_BOOTREG_ADDR,
+};
+
+/* Address maps for peripherals:
+ * the Versatile Express motherboard has two possible maps,
+ * the "legacy" one (used for A9) and the "Cortex-A Series"
+ * map (used for newer cores).
+ * Individual daughterboards can also have different maps for
+ * their peripherals.
+ */
+
+enum {
+VE_SYSREGS,
+VE_SP810,
+VE_SERIALPCI,
+VE_PL041,
+VE_MMCI,
+VE_KMI0,
+VE_KMI1,
+VE_UART0,
+VE_UART1,
+VE_UART2,
+VE_UART3,
+VE_WDT,
+VE_TIMER01,
+VE_TIMER23,
+VE_SERIALDVI,
+VE_RTC,
+VE_COMPACTFLASH,
+VE_CLCD,
+VE_NORFLASH0,
+VE_NORFLASH0ALIAS,
+VE_NORFLASH1,
+VE_SRAM,
+VE_VIDEORAM,
+VE_ETHERNET,
+VE_USB,
+VE_DAPROM,
+};
+
+static target_phys_addr_t motherboard_legacy_map[] = {
+/* CS7: 0x1000 .. 0x1002 */
+[VE_SYSREGS] = 0x1000,
+[VE_SP810] = 0x10001000,
+[VE_SERIALPCI] = 0x10002000,
+[VE_PL041] = 0x10004000,
+[VE_MMCI] = 0x10005000,
+[VE_KMI0] = 0x10006000,
+[VE_KMI1] = 0x10007000,
+[VE_UART0] = 0x10009000,
+[VE_UART1] = 0x1000a000,
+[VE_UART2] = 0x1000b000,
+[VE_UART3] = 0x1000c000,
+[VE_WDT] = 0x1000f000,
+[VE_TIMER01] = 0x10011000,
+[VE_TIMER23] = 0x10012000,
+[VE_SERIALDVI] = 0x10016000,
+[VE_RTC] = 0x10017000,
+[VE_COMPACTFLASH] = 0x1001a000,
+[VE_CLCD] = 0x1001f000,
+/* CS0: 0x4000 .. 0x4400 */
+[VE_NORFLASH0] = 0x4000,
+/* CS1: 0x4400 .. 0x4800 */
+[VE_NORFLASH1] = 0x4400,
+/* CS2: 0x4800 .. 0x4a00 */
+[VE_SRAM] = 0x4800,
+/* CS3: 0x4c00 .. 0x5000 */
+[VE_VIDEORAM] = 0x4c00,
+[VE_ETHERNET] = 0x4e00,
+[VE_USB] = 0x4f00,
 };
 
 static void vexpress_a9_init(ram_addr_t ram_size,
@@ -61,6 +128,7 @@ static void vexpress_a9_init(ram_addr_t ram_size,
 uint32_t proc_id;
 uint32_t sys_id;
 ram_addr_t low_ram_size, vram_size, sram_size;
+target_phys_addr_t *map = motherboard_legacy_map;
 
 if (!cpu_model) {
 cpu_model = "cortex-a9";
@@ -116,53 +184,53 @@ static void vexpress_a9_init(ram_addr_t ram_size,
 pic[n] = qdev_get_gpio_in(dev, n);
 }
 
-/* Motherboard peripherals CS7 : 0x1000 .. 0x1002 */
+/* Motherboard peripherals: the wiring is the same but the
+ * addresses vary between the legacy and A-Series memory maps.
+ */
+
 sys_id = 0x1190f500;
 proc_id = 0x0c000191;
 
-/* 0x1000 System registers */
 sysctl = qdev_create(NULL, "realview_sysctl");
 qdev_prop_set_uint32(sysctl, "sys_id", sys_id);
 qdev_init_nofail(sysctl);
 qdev_prop_set_uint32(sysctl, "proc_id", proc_id);
-sysbus_mmio_map(sysbus_from_qdev(sysctl), 0, 0x1000);
+sysbus_mmio_map(sysbus_from_qdev(sysctl), 0, map[VE_SYSREGS]);
+
+/* VE_SP810: not modelled */
+/* VE_SERIALPCI: not modelled */
 
-/* 0x10001000 SP810 system control */
-/* 0x10002000 serial bus PCI */
-/* 0x10004000 PL041 audio */
 pl041 = qdev_create(NULL, "pl041");
 qdev_prop_set_uint32(pl041, "nc_fifo_depth", 512);
 qdev_init_nofail(pl041);
-sysbus_mmio_map(sysbus_from_qdev(pl041), 0, 0x10004000);
+sysbus_mmio_map(sysbus_from_qdev(pl041), 0, map[VE_PL041]);
 sysbus_connect_irq(sysbus_from_qdev(pl041), 0, pic[11]);
 
-dev = sysbus_create_varargs("pl181", 0x10005000, pic[9], pic[10], NULL);
+dev = sysbus_create_varargs("pl181", map[VE_MMCI], pic[9], pic[10], NULL);
 /* Wire up MMC card detect and read-only signals */
 qdev_connect_gpio_out(dev, 0,
   qdev_get_gpio_in(sysctl, ARM_SYSCTL_GPIO_MMC_WPROT));
 qdev_connect_gpio_out(dev, 1,
   qdev_get_gpio_in(sysctl, 
ARM_SYSCTL_GPIO_MMC_CARDIN));
 
-sysbus_create_simple("pl050_keyboard", 0x10006000, pic[12]);
-sysbus_create_simple("pl050_mouse", 0x10007000, pic[13]);
-
-sysbus_create_simple("pl011", 0x10009000, pic[5]);
-sysbus_create_simple("pl011", 0x1000a000, pic[6]);
-sysbus_create_simple("pl011", 0x1000b000, pic[7]);
-sysbus_create_simple("pl011", 0x1000c00

[Qemu-devel] [PATCH v4 3/7] hw/vexpress.c: Move secondary CPU boot code to SRAM

2012-02-03 Thread Peter Maydell
On real Versatile Express hardware, the boot ROM puts the secondary
CPU bootcode/holding pen in SRAM. We can therefore rely on Linux not
trashing this memory until secondary CPUs have booted up, and can
put our QEMU-specific pen code in the same place. This allows us to
drop the odd "hack" RAM page we were using before.

Signed-off-by: Peter Maydell 
---
 hw/vexpress.c |   16 ++--
 1 files changed, 2 insertions(+), 14 deletions(-)

diff --git a/hw/vexpress.c b/hw/vexpress.c
index 8c4d3b3..99a9690 100644
--- a/hw/vexpress.c
+++ b/hw/vexpress.c
@@ -30,13 +30,9 @@
 #include "boards.h"
 #include "exec-memory.h"
 
-#define SMP_BOOT_ADDR 0xe000
-
 #define VEXPRESS_BOARD_ID 0x8e0
 
-static struct arm_boot_info vexpress_binfo = {
-.smp_loader_start = SMP_BOOT_ADDR,
-};
+static struct arm_boot_info vexpress_binfo;
 
 /* Address maps for peripherals:
  * the Versatile Express motherboard has two possible maps,
@@ -118,7 +114,6 @@ static void vexpress_a9_init(ram_addr_t ram_size,
 MemoryRegion *lowram = g_new(MemoryRegion, 1);
 MemoryRegion *vram = g_new(MemoryRegion, 1);
 MemoryRegion *sram = g_new(MemoryRegion, 1);
-MemoryRegion *hackram = g_new(MemoryRegion, 1);
 DeviceState *dev, *sysctl, *pl041;
 SysBusDevice *busdev;
 qemu_irq *irqp;
@@ -275,14 +270,6 @@ static void vexpress_a9_init(ram_addr_t ram_size,
 
 /* VE_DAPROM: not modelled */
 
-/* ??? Hack to map an additional page of ram for the secondary CPU
-   startup code.  I guess this works on real hardware because the
-   BootROM happens to be in ROM/flash or in memory that isn't clobbered
-   until after Linux boots the secondary CPUs.  */
-memory_region_init_ram(hackram, "vexpress.hack", 0x1000);
-vmstate_register_ram_global(hackram);
-memory_region_add_subregion(sysmem, SMP_BOOT_ADDR, hackram);
-
 vexpress_binfo.ram_size = ram_size;
 vexpress_binfo.kernel_filename = kernel_filename;
 vexpress_binfo.kernel_cmdline = kernel_cmdline;
@@ -290,6 +277,7 @@ static void vexpress_a9_init(ram_addr_t ram_size,
 vexpress_binfo.nb_cpus = smp_cpus;
 vexpress_binfo.board_id = VEXPRESS_BOARD_ID;
 vexpress_binfo.loader_start = 0x6000;
+vexpress_binfo.smp_loader_start = map[VE_SRAM];
 vexpress_binfo.smp_bootreg_addr = map[VE_SYSREGS] + 0x30;
 arm_load_kernel(first_cpu, &vexpress_binfo);
 }
-- 
1.7.1




[Qemu-devel] [PATCH v4 1/7] hw/a15mpcore.c: Add Cortex-A15 private peripheral model

2012-02-03 Thread Peter Maydell
Add a model of the Cortex-A15 memory mapped private peripheral
space. This is fairly simple because the only memory mapped
bit of the A15 is the GIC.

Note that we don't currently model a VGIC and therefore don't
map the VGIC related bits of the GIC.

Signed-off-by: Peter Maydell 
---
 Makefile.target |2 +-
 hw/a15mpcore.c  |  103 +++
 2 files changed, 104 insertions(+), 1 deletions(-)
 create mode 100644 hw/a15mpcore.c

diff --git a/Makefile.target b/Makefile.target
index 68481a3..9deb2f2 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -339,7 +339,7 @@ obj-arm-y += arm_boot.o pl011.o pl031.o pl050.o pl080.o 
pl110.o pl181.o pl190.o
 obj-arm-y += versatile_pci.o
 obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o
 obj-arm-y += arm_l2x0.o
-obj-arm-y += arm_mptimer.o
+obj-arm-y += arm_mptimer.o a15mpcore.o
 obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o
 obj-arm-y += highbank.o
 obj-arm-y += pl061.o
diff --git a/hw/a15mpcore.c b/hw/a15mpcore.c
new file mode 100644
index 000..b345afc
--- /dev/null
+++ b/hw/a15mpcore.c
@@ -0,0 +1,103 @@
+/*
+ * Cortex-A15MPCore internal peripheral emulation.
+ *
+ * Copyright (c) 2012 Linaro Limited.
+ * Written by Peter Maydell.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#include "sysbus.h"
+
+/* Configuration for arm_gic.c:
+ * max number of CPUs, how to ID current CPU
+ */
+#define NCPU 4
+
+static inline int gic_get_current_cpu(void)
+{
+  return cpu_single_env->cpu_index;
+}
+
+#include "arm_gic.c"
+
+/* A15MP private memory region.  */
+
+typedef struct A15MPPrivState {
+gic_state gic;
+uint32_t num_cpu;
+uint32_t num_irq;
+MemoryRegion container;
+} A15MPPrivState;
+
+static int a15mp_priv_init(SysBusDevice *dev)
+{
+A15MPPrivState *s = FROM_SYSBUSGIC(A15MPPrivState, dev);
+
+if (s->num_cpu > NCPU) {
+hw_error("a15mp_priv_init: num-cpu may not be more than %d\n", NCPU);
+}
+
+gic_init(&s->gic, s->num_cpu, s->num_irq);
+
+/* Memory map (addresses are offsets from PERIPHBASE):
+ *  0x-0x0fff -- reserved
+ *  0x1000-0x1fff -- GIC Distributor
+ *  0x2000-0x2fff -- GIC CPU interface
+ *  0x4000-0x4fff -- GIC virtual interface control (not modelled)
+ *  0x5000-0x5fff -- GIC virtual interface control (not modelled)
+ *  0x6000-0x7fff -- GIC virtual CPU interface (not modelled)
+ */
+memory_region_init(&s->container, "a15mp-priv-container", 0x8000);
+memory_region_add_subregion(&s->container, 0x1000, &s->gic.iomem);
+memory_region_add_subregion(&s->container, 0x2000, &s->gic.cpuiomem[0]);
+
+sysbus_init_mmio(dev, &s->container);
+return 0;
+}
+
+static Property a15mp_priv_properties[] = {
+DEFINE_PROP_UINT32("num-cpu", A15MPPrivState, num_cpu, 1),
+/* The Cortex-A15MP may have anything from 0 to 224 external interrupt
+ * IRQ lines (with another 32 internal). We default to 64+32, which
+ * is the number provided by the Cortex-A15MP test chip in the
+ * Versatile Express A15 development board.
+ * Other boards may differ and should set this property appropriately.
+ */
+DEFINE_PROP_UINT32("num-irq", A15MPPrivState, num_irq, 96),
+DEFINE_PROP_END_OF_LIST(),
+};
+
+static void a15mp_priv_class_init(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+k->init = a15mp_priv_init;
+dc->props = a15mp_priv_properties;
+/* We currently have no savable state outside the common GIC state */
+}
+
+static TypeInfo a15mp_priv_info = {
+.name  = "a15mpcore_priv",
+.parent = TYPE_SYS_BUS_DEVICE,
+.instance_size  = sizeof(A15MPPrivState),
+.class_init = a15mp_priv_class_init,
+};
+
+static void a15mp_register_devices(void)
+{
+type_register_static(&a15mp_priv_info);
+}
+
+device_init(a15mp_register_devices)
-- 
1.7.1




[Qemu-devel] [PATCH v4 7/7] hw/vexpress.c: Add vexpress-a15 machine

2012-02-03 Thread Peter Maydell
Add the vexpress-a15 machine, and the A-Series memory map it uses.

Signed-off-by: Peter Maydell 
Reviewed-by: Andreas Färber 
---
 hw/vexpress.c |  141 +
 1 files changed, 141 insertions(+), 0 deletions(-)

diff --git a/hw/vexpress.c b/hw/vexpress.c
index a5b9448..cb2ab39 100644
--- a/hw/vexpress.c
+++ b/hw/vexpress.c
@@ -103,6 +103,41 @@ static target_phys_addr_t motherboard_legacy_map[] = {
 [VE_USB] = 0x4f00,
 };
 
+static target_phys_addr_t motherboard_aseries_map[] = {
+/* CS0: 0x .. 0x0c00 */
+[VE_NORFLASH0] = 0x,
+[VE_NORFLASH0ALIAS] = 0x0800,
+/* CS4: 0x0c00 .. 0x1000 */
+[VE_NORFLASH1] = 0x0c00,
+/* CS5: 0x1000 .. 0x1400 */
+/* CS1: 0x1400 .. 0x1800 */
+[VE_SRAM] = 0x1400,
+/* CS2: 0x1800 .. 0x1c00 */
+[VE_VIDEORAM] = 0x1800,
+[VE_ETHERNET] = 0x1a00,
+[VE_USB] = 0x1b00,
+/* CS3: 0x1c00 .. 0x2000 */
+[VE_DAPROM] = 0x1c00,
+[VE_SYSREGS] = 0x1c01,
+[VE_SP810] = 0x1c02,
+[VE_SERIALPCI] = 0x1c03,
+[VE_PL041] = 0x1c04,
+[VE_MMCI] = 0x1c05,
+[VE_KMI0] = 0x1c06,
+[VE_KMI1] = 0x1c07,
+[VE_UART0] = 0x1c09,
+[VE_UART1] = 0x1c0a,
+[VE_UART2] = 0x1c0b,
+[VE_UART3] = 0x1c0c,
+[VE_WDT] = 0x1c0f,
+[VE_TIMER01] = 0x1c11,
+[VE_TIMER23] = 0x1c12,
+[VE_SERIALDVI] = 0x1c16,
+[VE_RTC] = 0x1c17,
+[VE_COMPACTFLASH] = 0x1c1a,
+[VE_CLCD] = 0x1c1f,
+};
+
 /* Structure defining the peculiarities of a specific daughterboard */
 
 typedef struct VEDBoardInfo VEDBoardInfo;
@@ -218,6 +253,91 @@ static const VEDBoardInfo a9_daughterboard = {
 .init = a9_daughterboard_init,
 };
 
+static void a15_daughterboard_init(const VEDBoardInfo *daughterboard,
+   ram_addr_t ram_size,
+   const char *cpu_model,
+   qemu_irq *pic, uint32_t *proc_id)
+{
+int n;
+CPUState *env = NULL;
+MemoryRegion *sysmem = get_system_memory();
+MemoryRegion *ram = g_new(MemoryRegion, 1);
+MemoryRegion *sram = g_new(MemoryRegion, 1);
+qemu_irq cpu_irq[4];
+DeviceState *dev;
+SysBusDevice *busdev;
+
+if (!cpu_model) {
+cpu_model = "cortex-a15";
+}
+
+*proc_id = 0x14000217;
+
+for (n = 0; n < smp_cpus; n++) {
+qemu_irq *irqp;
+env = cpu_init(cpu_model);
+if (!env) {
+fprintf(stderr, "Unable to find CPU definition\n");
+exit(1);
+}
+irqp = arm_pic_init_cpu(env);
+cpu_irq[n] = irqp[ARM_PIC_CPU_IRQ];
+}
+
+if (ram_size > 0x8000) {
+fprintf(stderr, "vexpress-a15: cannot model more than 2GB RAM\n");
+exit(1);
+}
+
+memory_region_init_ram(ram, "vexpress.highmem", ram_size);
+vmstate_register_ram_global(ram);
+/* RAM is from 0x8000 upwards; there is no low-memory alias for it. */
+memory_region_add_subregion(sysmem, 0x8000, ram);
+
+/* 0x2c00 A15MPCore private memory region (GIC) */
+dev = qdev_create(NULL, "a15mpcore_priv");
+qdev_prop_set_uint32(dev, "num-cpu", smp_cpus);
+qdev_init_nofail(dev);
+busdev = sysbus_from_qdev(dev);
+sysbus_mmio_map(busdev, 0, 0x2c00);
+for (n = 0; n < smp_cpus; n++) {
+sysbus_connect_irq(busdev, n, cpu_irq[n]);
+}
+/* Interrupts [42:0] are from the motherboard;
+ * [47:43] are reserved; [63:48] are daughterboard
+ * peripherals. Note that some documentation numbers
+ * external interrupts starting from 32 (because there
+ * are internal interrupts 0..31).
+ */
+for (n = 0; n < 64; n++) {
+pic[n] = qdev_get_gpio_in(dev, n);
+}
+
+/* A15 daughterboard peripherals: */
+
+/* 0x2000: CoreSight interfaces: not modelled */
+/* 0x2a00: PL301 AXI interconnect: not modelled */
+/* 0x2a42: SCC: not modelled */
+/* 0x2a43: system counter: not modelled */
+/* 0x2b00: HDLCD controller: not modelled */
+/* 0x2b06: SP805 watchdog: not modelled */
+/* 0x2b0a: PL341 dynamic memory controller: not modelled */
+/* 0x2e00: system SRAM */
+memory_region_init_ram(sram, "vexpress.a15sram", 0x1);
+vmstate_register_ram_global(sram);
+memory_region_add_subregion(sysmem, 0x2e00, sram);
+
+/* 0x7ffb: DMA330 DMA controller: not modelled */
+/* 0x7ffd: PL354 static memory controller: not modelled */
+}
+
+static const VEDBoardInfo a15_daughterboard = {
+.motherboard_map = motherboard_aseries_map,
+.loader_start = 0x8000,
+.gic_cpu_if_addr = 0x2c002000,
+.init = a15_daughterboard_init,
+};
+
 static void vexpress_common_init(const VEDBoardInfo *daughterboard,
  ram_addr_t ram_size,
   

[Qemu-devel] [PATCH v4 4/7] hw/vexpress.c: Factor out daughterboard-specific initialization

2012-02-03 Thread Peter Maydell
Factor out daughterboard specifics into a data structure and
daughterboard initialization function, in preparation for adding
vexpress-a15 support.

Signed-off-by: Peter Maydell 
---
 hw/vexpress.c |  118 -
 1 files changed, 83 insertions(+), 35 deletions(-)

diff --git a/hw/vexpress.c b/hw/vexpress.c
index 99a9690..26537f7 100644
--- a/hw/vexpress.c
+++ b/hw/vexpress.c
@@ -103,32 +103,43 @@ static target_phys_addr_t motherboard_legacy_map[] = {
 [VE_USB] = 0x4f00,
 };
 
-static void vexpress_a9_init(ram_addr_t ram_size,
- const char *boot_device,
- const char *kernel_filename, const char *kernel_cmdline,
- const char *initrd_filename, const char *cpu_model)
+/* Structure defining the peculiarities of a specific daughterboard */
+
+typedef struct VEDBoardInfo VEDBoardInfo;
+
+typedef void DBoardInitFn(const VEDBoardInfo *daughterboard,
+  ram_addr_t ram_size,
+  const char *cpu_model,
+  qemu_irq *pic, uint32_t *proc_id);
+
+struct VEDBoardInfo {
+const target_phys_addr_t *motherboard_map;
+target_phys_addr_t loader_start;
+DBoardInitFn *init;
+};
+
+static void a9_daughterboard_init(const VEDBoardInfo *daughterboard,
+  ram_addr_t ram_size,
+  const char *cpu_model,
+  qemu_irq *pic, uint32_t *proc_id)
 {
 CPUState *env = NULL;
 MemoryRegion *sysmem = get_system_memory();
 MemoryRegion *ram = g_new(MemoryRegion, 1);
 MemoryRegion *lowram = g_new(MemoryRegion, 1);
-MemoryRegion *vram = g_new(MemoryRegion, 1);
-MemoryRegion *sram = g_new(MemoryRegion, 1);
-DeviceState *dev, *sysctl, *pl041;
+DeviceState *dev;
 SysBusDevice *busdev;
 qemu_irq *irqp;
-qemu_irq pic[64];
 int n;
 qemu_irq cpu_irq[4];
-uint32_t proc_id;
-uint32_t sys_id;
-ram_addr_t low_ram_size, vram_size, sram_size;
-target_phys_addr_t *map = motherboard_legacy_map;
+ram_addr_t low_ram_size;
 
 if (!cpu_model) {
 cpu_model = "cortex-a9";
 }
 
+*proc_id = 0x0c000191;
+
 for (n = 0; n < smp_cpus; n++) {
 env = cpu_init(cpu_model);
 if (!env) {
@@ -141,7 +152,7 @@ static void vexpress_a9_init(ram_addr_t ram_size,
 
 if (ram_size > 0x4000) {
 /* 1GB is the maximum the address space permits */
-fprintf(stderr, "vexpress: cannot model more than 1GB RAM\n");
+fprintf(stderr, "vexpress-a9: cannot model more than 1GB RAM\n");
 exit(1);
 }
 
@@ -179,12 +190,58 @@ static void vexpress_a9_init(ram_addr_t ram_size,
 pic[n] = qdev_get_gpio_in(dev, n);
 }
 
+/* Daughterboard peripherals : 0x1002 .. 0x2000 */
+
+/* 0x1002 PL111 CLCD (daughterboard) */
+sysbus_create_simple("pl111", 0x1002, pic[44]);
+
+/* 0x1006 AXI RAM */
+/* 0x100e PL341 Dynamic Memory Controller */
+/* 0x100e1000 PL354 Static Memory Controller */
+/* 0x100e2000 System Configuration Controller */
+
+sysbus_create_simple("sp804", 0x100e4000, pic[48]);
+/* 0x100e5000 SP805 Watchdog module */
+/* 0x100e6000 BP147 TrustZone Protection Controller */
+/* 0x100e9000 PL301 'Fast' AXI matrix */
+/* 0x100ea000 PL301 'Slow' AXI matrix */
+/* 0x100ec000 TrustZone Address Space Controller */
+/* 0x1020 CoreSight debug APB */
+/* 0x1e00a000 PL310 L2 Cache Controller */
+sysbus_create_varargs("l2x0", 0x1e00a000, NULL);
+}
+
+static const VEDBoardInfo a9_daughterboard = {
+.motherboard_map = motherboard_legacy_map,
+.loader_start = 0x6000,
+.init = a9_daughterboard_init,
+};
+
+static void vexpress_common_init(const VEDBoardInfo *daughterboard,
+ ram_addr_t ram_size,
+ const char *boot_device,
+ const char *kernel_filename,
+ const char *kernel_cmdline,
+ const char *initrd_filename,
+ const char *cpu_model)
+{
+DeviceState *dev, *sysctl, *pl041;
+qemu_irq pic[64];
+uint32_t proc_id;
+uint32_t sys_id;
+ram_addr_t vram_size, sram_size;
+MemoryRegion *sysmem = get_system_memory();
+MemoryRegion *vram = g_new(MemoryRegion, 1);
+MemoryRegion *sram = g_new(MemoryRegion, 1);
+const target_phys_addr_t *map = daughterboard->motherboard_map;
+
+daughterboard->init(daughterboard, ram_size, cpu_model, pic, &proc_id);
+
 /* Motherboard peripherals: the wiring is the same but the
  * addresses vary between the legacy and A-Series memory maps.
  */
 
 sys_id = 0x1190f500;
-proc_id = 0x0c000191;
 
 sysctl = qdev_create(NULL, "realview_sysctl");
 qdev_prop_set_uint32(sysctl, "sys_id", sys_id);
@@ -

[Qemu-devel] [PATCH v4 5/7] hw/vexpress.c: Instantiate the motherboard CLCD

2012-02-03 Thread Peter Maydell
Instantiate the CLCD on the vexpress motherboard as well as one on
the daughterboard -- the A15 daughterboard does not have a CLCD
and so relies on the motherboard one.

At the moment QEMU doesn't provide infrastructure for selecting
which display device gets to actually show graphics -- the first
one registered is it. Fortunately this works for the major use
case (Linux): if the daughterboard has a CLCD it will come first
and be used, otherwise we fall back to the motherboard CLCD.
So we don't (currently) need to implement the control register
which allows software to tell the mux which video output to pass
through to the outside world.

Signed-off-by: Peter Maydell 
Reviewed-by: Andreas Färber 
---
 hw/vexpress.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/vexpress.c b/hw/vexpress.c
index 26537f7..27459d9 100644
--- a/hw/vexpress.c
+++ b/hw/vexpress.c
@@ -282,7 +282,7 @@ static void vexpress_common_init(const VEDBoardInfo 
*daughterboard,
 
 /* VE_COMPACTFLASH: not modelled */
 
-/* VE_CLCD: not modelled (we use the daughterboard CLCD only) */
+sysbus_create_simple("pl111", map[VE_CLCD], pic[14]);
 
 /* VE_NORFLASH0: not modelled */
 /* VE_NORFLASH0ALIAS: not modelled */
-- 
1.7.1




Re: [Qemu-devel] [PATCH v2 0/8] qemu-ga: add support for Windows

2012-02-03 Thread Luiz Capitulino
On Fri, 03 Feb 2012 11:23:05 -0600
Michael Roth  wrote:

> On 02/03/2012 10:45 AM, Luiz Capitulino wrote:
> > On Fri, 03 Feb 2012 10:37:25 -0600
> > Michael Roth  wrote:
> >
> >> On 02/03/2012 08:18 AM, Luiz Capitulino wrote:
> >>> On Thu,  2 Feb 2012 13:58:52 -0600
> >>> Michael Roth   wrote:
> >>>
>  These patches apply on top of qemu.git master, and can also be obtained 
>  from:
>  git://github.com/mdroth/qemu.git qga-win32-v2
> 
>  Luiz/Gal, I decided not to roll the suspend/hibernate stuff into this 
>  series
>  since the s3 situation isn't fully sorted out yet. The file structure is 
>  a
>  little different now, posix/linux-specific stuff goes in 
>  qga/commands-posix.c,
>  win32-specific stuff in qga/commands-win32.c, but other than that it 
>  should be
>  a straightforward rebase if this gets merged first.
> >>>
> >>> I think I'll have to rebase my series on top of this one, when do you 
> >>> plan to
> >>> merge this?
> >>>
> >>
> >> Hopefully soon, was planning on waiting for the suspend/hibernate bits
> >> but we seem to be blocked on the s3 issues and I have other patches
> >> accumulating on top of win32 (hesitant to base those on master since
> >> this patchset does a lot of refactoring that might affect them), so I
> >> figured I'd push this for merge since it doesn't have any dependencies
> >> outside master.
> >
> > The S3 issues seem sorted to me, but I don't oppose having this series in 
> > first.
> >
> 
> Thanks, in retrospect I probably should've just gotten these out of the 
> way weeks ago since they'd immediately clobber git blame.
> 
> I'd been tracking Gerd's QMP wakeup series as the s3 resolution we need 
> for guest-suspend, is that still the case?

Yes. But now I remembered about a seabios bug with S3... Need to check if
it were already addressed.

> I guess those are coming 
> through your QMP queue?

Oh, as the QMP part is trivial I thought someone else would pick them up,
but I can do that.



[Qemu-devel] [PATCH v4 0/7] Add support for vexpress-a15

2012-02-03 Thread Peter Maydell
This patchset adds support for the Versatile Express A15 daughterboard.
The resulting model is capable of booting a Linux kernel which has
been configured for Cortex-A15 with the Versatile Express "extended
memory map" and without support for LPAE.

Changes v3->v4:
 * fixed a minor spacing issue in the gpl-license header comment in one file
 * rebased on current master after the QOM.3 series landing

Changes v2->v3:
 * the target-arm patches are now in master
 * dropped spurious 'const' from 'factor out daughterboard' patch
 * rebased on current master and updated a15mpcore.c with QOM changes


Peter Maydell (7):
  hw/a15mpcore.c: Add Cortex-A15 private peripheral model
  hw/vexpress.c: Make motherboard peripheral memory map table-driven
  hw/vexpress.c: Move secondary CPU boot code to SRAM
  hw/vexpress.c: Factor out daughterboard-specific initialization
  hw/vexpress.c: Instantiate the motherboard CLCD
  arm_boot: Pass base address of GIC CPU interface, not whole GIC
  hw/vexpress.c: Add vexpress-a15 machine

 Makefile.target |2 +-
 hw/a15mpcore.c  |  103 ++
 hw/arm-misc.h   |2 +-
 hw/arm_boot.c   |8 +-
 hw/realview.c   |   12 +-
 hw/vexpress.c   |  410 ---
 6 files changed, 445 insertions(+), 92 deletions(-)
 create mode 100644 hw/a15mpcore.c




[Qemu-devel] [PATCH v4 6/7] arm_boot: Pass base address of GIC CPU interface, not whole GIC

2012-02-03 Thread Peter Maydell
The arm_boot secondary boot loader code needs the address of
the GIC CPU interface. Obtaining this from the base address
of the private peripheral region was possible for A9 and 11MPcore,
but the A15 puts the GIC CPU interface in a different place.
So make boards pass in the GIC CPU interface address directly.

Signed-off-by: Peter Maydell 
---
 hw/arm-misc.h |2 +-
 hw/arm_boot.c |8 
 hw/realview.c |   12 +++-
 hw/vexpress.c |6 --
 4 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/hw/arm-misc.h b/hw/arm-misc.h
index 5e5204b..306013a 100644
--- a/hw/arm-misc.h
+++ b/hw/arm-misc.h
@@ -37,7 +37,7 @@ struct arm_boot_info {
  */
 target_phys_addr_t smp_loader_start;
 target_phys_addr_t smp_bootreg_addr;
-target_phys_addr_t smp_priv_base;
+target_phys_addr_t gic_cpu_if_addr;
 int nb_cpus;
 int board_id;
 int (*atag_board)(const struct arm_boot_info *info, void *p);
diff --git a/hw/arm_boot.c b/hw/arm_boot.c
index 5f163fd..4637636 100644
--- a/hw/arm_boot.c
+++ b/hw/arm_boot.c
@@ -43,16 +43,16 @@ static uint32_t bootloader[] = {
  * location for the kernel secondary CPU entry point.
  */
 static uint32_t smpboot[] = {
-  0xe59f201c, /* ldr r2, privbase */
+  0xe59f201c, /* ldr r2, gic_cpu_if */
   0xe59f001c, /* ldr r0, startaddr */
   0xe3a01001, /* mov r1, #1 */
-  0xe5821100, /* str r1, [r2, #256] */
+  0xe5821000, /* str r1, [r2] */
   0xe320f003, /* wfi */
   0xe5901000, /* ldr r1, [r0] */
   0xe1110001, /* tst r1, r1 */
   0x0afb, /* beq  */
   0xe12fff11, /* bx  r1 */
-  0,  /* privbase: Private memory region base address.  */
+  0,  /* gic_cpu_if: base address of GIC CPU interface */
   0   /* bootreg: Boot register address is held here */
 };
 
@@ -61,7 +61,7 @@ static void default_write_secondary(CPUState *env,
 {
 int n;
 smpboot[ARRAY_SIZE(smpboot) - 1] = info->smp_bootreg_addr;
-smpboot[ARRAY_SIZE(smpboot) - 2] = info->smp_priv_base;
+smpboot[ARRAY_SIZE(smpboot) - 2] = info->gic_cpu_if_addr;
 for (n = 0; n < ARRAY_SIZE(smpboot); n++) {
 smpboot[n] = tswap32(smpboot[n]);
 }
diff --git a/hw/realview.c b/hw/realview.c
index 821e627..ee61f26 100644
--- a/hw/realview.c
+++ b/hw/realview.c
@@ -222,21 +222,23 @@ static void realview_init(ram_addr_t ram_size,
 sysbus_mmio_map(sysbus_from_qdev(sysctl), 0, 0x1000);
 
 if (is_mpcore) {
+target_phys_addr_t periphbase;
 dev = qdev_create(NULL, is_pb ? "a9mpcore_priv": "realview_mpcore");
 qdev_prop_set_uint32(dev, "num-cpu", smp_cpus);
 qdev_init_nofail(dev);
 busdev = sysbus_from_qdev(dev);
 if (is_pb) {
-realview_binfo.smp_priv_base = 0x1f00;
+periphbase = 0x1f00;
 } else {
-realview_binfo.smp_priv_base = 0x1010;
+periphbase = 0x1010;
 }
-sysbus_mmio_map(busdev, 0, realview_binfo.smp_priv_base);
+sysbus_mmio_map(busdev, 0, periphbase);
 for (n = 0; n < smp_cpus; n++) {
 sysbus_connect_irq(busdev, n, cpu_irq[n]);
 }
-sysbus_create_varargs("l2x0", realview_binfo.smp_priv_base + 0x2000,
-  NULL);
+sysbus_create_varargs("l2x0", periphbase + 0x2000, NULL);
+/* Both A9 and 11MPCore put the GIC CPU i/f at base + 0x100 */
+realview_binfo.gic_cpu_if_addr = periphbase + 0x100;
 } else {
 uint32_t gic_addr = is_pb ? 0x1e00 : 0x1004;
 /* For now just create the nIRQ GIC, and ignore the others.  */
diff --git a/hw/vexpress.c b/hw/vexpress.c
index 27459d9..a5b9448 100644
--- a/hw/vexpress.c
+++ b/hw/vexpress.c
@@ -115,6 +115,7 @@ typedef void DBoardInitFn(const VEDBoardInfo *daughterboard,
 struct VEDBoardInfo {
 const target_phys_addr_t *motherboard_map;
 target_phys_addr_t loader_start;
+const target_phys_addr_t gic_cpu_if_addr;
 DBoardInitFn *init;
 };
 
@@ -175,8 +176,7 @@ static void a9_daughterboard_init(const VEDBoardInfo 
*daughterboard,
 qdev_prop_set_uint32(dev, "num-cpu", smp_cpus);
 qdev_init_nofail(dev);
 busdev = sysbus_from_qdev(dev);
-vexpress_binfo.smp_priv_base = 0x1e00;
-sysbus_mmio_map(busdev, 0, vexpress_binfo.smp_priv_base);
+sysbus_mmio_map(busdev, 0, 0x1e00);
 for (n = 0; n < smp_cpus; n++) {
 sysbus_connect_irq(busdev, n, cpu_irq[n]);
 }
@@ -214,6 +214,7 @@ static void a9_daughterboard_init(const VEDBoardInfo 
*daughterboard,
 static const VEDBoardInfo a9_daughterboard = {
 .motherboard_map = motherboard_legacy_map,
 .loader_start = 0x6000,
+.gic_cpu_if_addr = 0x1e000100,
 .init = a9_daughterboard_init,
 };
 
@@ -316,6 +317,7 @@ static void vexpress_common_init(const VEDBoardInfo 
*daughterboard,
 vexpress_binfo.loader_start = daughterboard->loader_start;
 vexpress_binfo.smp_loader_start = map[VE_SRAM];
 vexpress_binfo.smp_bootreg_addr =

[Qemu-devel] [PATCH] MAINTAINERS: Add hw/highbank.c maintainer

2012-02-03 Thread Mark Langsdorf
Signed-off-by: Mark Langsdorf 
---
 MAINTAINERS |5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 173e893..bdc254f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -237,6 +237,11 @@ M: Peter Maydell 
 S: Maintained
 F: hw/versatilepb.c
 
+Calxeda Highbank
+M: Mark Langsdorf 
+S: Supported
+F: hw/highbank.c
+
 CRIS Machines
 -
 Axis Dev88
-- 
1.7.5.4




[Qemu-devel] [PATCH] KVM: Fix breakages of QOM conversion

2012-02-03 Thread Jan Kiszka
From: Jan Kiszka 

KVM APIC and PIC require instance sizes.

Signed-off-by: Jan Kiszka 
---
 hw/kvm/apic.c  |1 +
 hw/kvm/i8259.c |1 +
 2 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/hw/kvm/apic.c b/hw/kvm/apic.c
index 89e33b0..dfc2ab3 100644
--- a/hw/kvm/apic.c
+++ b/hw/kvm/apic.c
@@ -135,6 +135,7 @@ static void kvm_apic_class_init(ObjectClass *klass, void 
*data)
 static TypeInfo kvm_apic_info = {
 .name = "kvm-apic",
 .parent = TYPE_APIC_COMMON,
+.instance_size = sizeof(APICCommonState),
 .class_init = kvm_apic_class_init,
 };
 
diff --git a/hw/kvm/i8259.c b/hw/kvm/i8259.c
index ae0f41d..00c7c91 100644
--- a/hw/kvm/i8259.c
+++ b/hw/kvm/i8259.c
@@ -126,6 +126,7 @@ static void kvm_i8259_class_init(ObjectClass *klass, void 
*data)
 static TypeInfo kvm_i8259_info = {
 .name  = "kvm-i8259",
 .parent = TYPE_PIC_COMMON,
+.instance_size = sizeof(PICCommonState),
 .class_init = kvm_i8259_class_init,
 };
 
-- 
1.7.3.4



[Qemu-devel] [PATCH v2 00/11] tracetool: Improvements for future expansion

2012-02-03 Thread Lluís Vilanova
NOTE: Depend's on Harsh's port of tractool to python.

A general overhaul of the pythonic tracetool script to allow simpler future
extensions.

Signed-off-by: Lluís Vilanova 
---

Changes in v2:

* Minor changes


Lluís Vilanova (11):
  [trivial] Fix a compiler warning
  trace: [tracetool] Do not rebuild event list in backend code
  trace: [tracetool] Simplify event line parsing
  trace: [ŧracetool] Do not precompute the event number
  trace: [tracetool] Add support for event properties
  trace: [tracetool] Process the "disable" event property
  trace: [tracetool] Rewrite event argument parsing
  trace: [tracetool] Make format-specific code optional and with access to 
event information
  trace: [tracetool] Automatically establish available backends and formats
  trace: Provide a per-event status define for conditional compilation
  trace: [tracetool] Add error-reporting functions


 Makefile.objs|6 
 Makefile.target  |3 
 docs/tracing.txt |   46 +++-
 scripts/tracetool.py |  627 --
 4 files changed, 397 insertions(+), 285 deletions(-)


To: qemu-devel@nongnu.org
Cc: Stefan Hajnoczi 
Cc: Harsh Prateek Bora 



[Qemu-devel] [PATCH v2 01/11] [trivial] Fix a compiler warning

2012-02-03 Thread Lluís Vilanova
Signed-off-by: Lluís Vilanova 
---
 scripts/tracetool.py |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index 6874f66..f0d7e1e 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -183,7 +183,7 @@ def simple_c(events):
 argc = event.argc
 print '''void trace_%(name)s(%(args)s)
 {
-unsigned int tbuf_idx, rec_off;
+unsigned int tbuf_idx, rec_off __attribute__((unused));
 uint64_t var64 __attribute__ ((unused));
 uint64_t pvar64 __attribute__ ((unused));
 uint32_t slen __attribute__ ((unused));




[Qemu-devel] [PATCH v2 02/11] trace: [tracetool] Do not rebuild event list in backend code

2012-02-03 Thread Lluís Vilanova
Signed-off-by: Lluís Vilanova 
---
 scripts/tracetool.py |   14 +++---
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index f0d7e1e..7042728 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -171,15 +171,14 @@ def simple_c(events):
 print
 print 'TraceEvent trace_list[] = {'
 print
-eventlist = list(events)
-for event in eventlist:
+for event in events:
 print '{.tp_name = "%(name)s", .state=0},' % {
 'name': event.name
 }
 print
 print '};'
 print
-for event in eventlist:
+for event in events:
 argc = event.argc
 print '''void trace_%(name)s(%(args)s)
 {
@@ -311,8 +310,7 @@ def ust_c(events):
 #undef inline
 #undef wmb
 #include "trace.h"'''
-eventlist = list(events)
-for event in eventlist:
+for event in events:
 argnames = event.argnames
 if event.argc > 0:
 argnames = ', ' + event.argnames
@@ -344,7 +342,7 @@ static void ust_%(name)s_probe(%(args)s)
 print '''
 static void __attribute__((constructor)) trace_init(void)
 {'''
-for event in eventlist:
+for event in events:
 print 'register_trace_ust_%(name)s(ust_%(name)s_probe);' % {
 'name': event.name
 }
@@ -510,14 +508,16 @@ class Event(object):
 
 # Generator that yields Event objects given a trace-events file object
 def read_events(fobj):
+res = []
 event_num = 0
 for line in fobj:
 if not line.strip():
 continue
 if line.lstrip().startswith('#'):
continue
-   yield Event(event_num, line)
+   res.append(Event(event_num, line))
event_num += 1
+return res
 
 backend = ""
 output = ""




[Qemu-devel] [PATCH v2 03/11] trace: [tracetool] Simplify event line parsing

2012-02-03 Thread Lluís Vilanova
Signed-off-by: Lluís Vilanova 
---
 scripts/tracetool.py |   46 ++
 1 files changed, 14 insertions(+), 32 deletions(-)

diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index 7042728..f675d96 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -38,19 +38,9 @@ Options:
 '''
 sys.exit(1)
 
-def get_name(line, sep='('):
-head, sep, tail = line.partition(sep)
-return head
-
-def get_args(line, sep1='(', sep2=')'):
-head, sep1, tail = line.partition(sep1)
-args, sep2, fmt_str = tail.partition(sep2)
-return args
-
-def get_argnames(line, sep=','):
+def get_argnames(args):
 nfields = 0
 str = []
-args = get_args(line)
 for field in args.split():
   nfields = nfields + 1
   # Drop pointer star
@@ -71,21 +61,7 @@ def get_argnames(line, sep=','):
 else:
   return ''
 
-def get_argc(line):
-argc = 0
-argnames = get_argnames(line)
-if argnames:
-  for name in argnames.split(','):
-argc = argc + 1
-return argc
-
-def get_fmt(line, sep=')'):
-event, sep, fmt = line.partition(sep)
-return fmt
-
-def calc_sizeofargs(line):
-args = get_args(line)
-argc = get_argc(line)
+def calc_sizeofargs(args, argc):
 strtype = ('const char*', 'char*', 'const char *', 'char *')
 str = []
 newstr = ""
@@ -495,16 +471,22 @@ trace_gen = {
 }
 
 # A trace event
+import re
+cre = re.compile("(?P[^(\s]+)\((?P[^)]*)\)\s*(?P\".*)?")
+
 class Event(object):
 def __init__(self, num, line):
 self.num = num
-self.args = get_args(line)
+m = cre.match(line)
+assert m is not None
+groups = m.groupdict('')
+self.args = groups["args"]
 self.arglist = self.args.split(',')
-self.name = get_name(line)
-self.argc = get_argc(line)
-self.argnames = get_argnames(line)
-self.sizestr = calc_sizeofargs(line)
-self.fmt = get_fmt(line)
+self.name = groups["name"]
+self.argc = len(self.arglist)
+self.argnames = get_argnames(self.args)
+self.sizestr = calc_sizeofargs(self.args, self.argc)
+self.fmt = groups["fmt"]
 
 # Generator that yields Event objects given a trace-events file object
 def read_events(fobj):




[Qemu-devel] [PATCH v2 04/11] trace: [ŧracetool] Do not precompute the event number

2012-02-03 Thread Lluís Vilanova
This would otherwise break event numbering when actually using the "disable"
property.

Signed-off-by: Lluís Vilanova 
---
 scripts/tracetool.py |   21 +
 1 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index f675d96..94c8d7d 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -128,7 +128,7 @@ def simple_h(events):
 'args': event.args
 }
 print
-print '#define NR_TRACE_EVENTS %d' % (event.num + 1)
+print '#define NR_TRACE_EVENTS %d' % len(events)
 print 'extern TraceEvent trace_list[NR_TRACE_EVENTS];'
 
 return
@@ -154,7 +154,7 @@ def simple_c(events):
 print
 print '};'
 print
-for event in events:
+for num, event in enumerate(events):
 argc = event.argc
 print '''void trace_%(name)s(%(args)s)
 {
@@ -169,12 +169,12 @@ def simple_c(events):
 ''' % {
 'name': event.name,
 'args': event.args,
-'event_id': event.num,
+'event_id': num,
 }
 print '''
 tbuf_idx = trace_alloc_record(%(event_id)s, %(sizestr)s);
 rec_off = (tbuf_idx + ST_V2_REC_HDR_LEN) %% TRACE_BUF_LEN; /* seek record 
header */
-''' % {'event_id': event.num, 'sizestr': event.sizestr,}
+''' % {'event_id': num, 'sizestr': event.sizestr,}
 
 if argc > 0:
 str = event.arglist
@@ -220,7 +220,7 @@ def stderr_h(events):
 #include "trace/stderr.h"
 
 extern TraceEvent trace_list[];'''
-for event in events:
+for num, event in enumerate(events):
 argnames = event.argnames
 if event.argc > 0:
 argnames = ', ' + event.argnames
@@ -235,12 +235,12 @@ static inline void trace_%(name)s(%(args)s)
 }''' % {
 'name': event.name,
 'args': event.args,
-'event_num': event.num,
+'event_num': num,
 'fmt': event.fmt.rstrip('\n'),
 'argnames': argnames
 }
 print
-print '#define NR_TRACE_EVENTS %d' % (event.num + 1)
+print '#define NR_TRACE_EVENTS %d' % len(events)
 
 def stderr_c(events):
 print '''#include "trace.h"
@@ -475,8 +475,7 @@ import re
 cre = re.compile("(?P[^(\s]+)\((?P[^)]*)\)\s*(?P\".*)?")
 
 class Event(object):
-def __init__(self, num, line):
-self.num = num
+def __init__(self, line):
 m = cre.match(line)
 assert m is not None
 groups = m.groupdict('')
@@ -491,14 +490,12 @@ class Event(object):
 # Generator that yields Event objects given a trace-events file object
 def read_events(fobj):
 res = []
-event_num = 0
 for line in fobj:
 if not line.strip():
 continue
 if line.lstrip().startswith('#'):
continue
-   res.append(Event(event_num, line))
-   event_num += 1
+   res.append(Event(line))
 return res
 
 backend = ""




[Qemu-devel] [PATCH v2 05/11] trace: [tracetool] Add support for event properties

2012-02-03 Thread Lluís Vilanova
Signed-off-by: Lluís Vilanova 
---
 scripts/tracetool.py |8 +++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index 94c8d7d..de867bd 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -472,7 +472,9 @@ trace_gen = {
 
 # A trace event
 import re
-cre = re.compile("(?P[^(\s]+)\((?P[^)]*)\)\s*(?P\".*)?")
+cre = 
re.compile("((?P.*)\s+)?(?P[^(\s]+)\((?P[^)]*)\)\s*(?P\".*)?")
+
+VALID_PROPS = set(["disable"])
 
 class Event(object):
 def __init__(self, line):
@@ -486,6 +488,10 @@ class Event(object):
 self.argnames = get_argnames(self.args)
 self.sizestr = calc_sizeofargs(self.args, self.argc)
 self.fmt = groups["fmt"]
+self.properties = groups["props"].split()
+unknown_props = set(self.properties) - VALID_PROPS
+if len(unknown_props) > 0:
+raise ValueError("Unknown properties: %s" % ", 
".join(unknown_props))
 
 # Generator that yields Event objects given a trace-events file object
 def read_events(fobj):




[Qemu-devel] [PATCH v2 06/11] trace: [tracetool] Process the "disable" event property

2012-02-03 Thread Lluís Vilanova
Signed-off-by: Lluís Vilanova 
---
 scripts/tracetool.py |   13 +++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index de867bd..b735a54 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -365,6 +365,9 @@ def dtrace_d(events):
 print '};'
 return
 
+def dtrace_nop_d(events):
+pass
+
 def dtrace_stp(events):
 for event in events:
 # Define prototype for probe arguments
@@ -387,6 +390,9 @@ probe %(probeprefix)s.%(name)s = 
process("%(binary)s").mark("%(name)s")
 print
 return
 
+def dtrace_nop_stp(events):
+pass
+
 def trace_stap_begin():
 global probeprefix
 if backend != "dtrace":
@@ -429,6 +435,8 @@ converters = {
 'nop': {
 'h': nop_h,
 'c': nop_c,
+'d': dtrace_nop_d,
+'stap': dtrace_nop_stp,
 },
 
 'stderr': {
@@ -560,10 +568,11 @@ def main():
 sys.exit(0)
 
 events = read_events(sys.stdin)
+
 trace_gen[output]['begin']()
-converters[backend][output](events)
+converters[backend][output]([ e for e in events if 'disable' not in 
e.properties ])
+converters['nop'][output]([ e for e in events if 'disable' in e.properties 
])
 trace_gen[output]['end']()
-return
 
 if __name__ == "__main__":
 main()




[Qemu-devel] [PATCH v2 07/11] trace: [tracetool] Rewrite event argument parsing

2012-02-03 Thread Lluís Vilanova
Signed-off-by: Lluís Vilanova 
---
 scripts/tracetool.py |  187 --
 1 files changed, 91 insertions(+), 96 deletions(-)

diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index b735a54..cd1c29d 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -38,49 +38,6 @@ Options:
 '''
 sys.exit(1)
 
-def get_argnames(args):
-nfields = 0
-str = []
-for field in args.split():
-  nfields = nfields + 1
-  # Drop pointer star
-  type, ptr, tail = field.partition('*')
-  if type != field:
-field = tail
-
-  name, sep, tail = field.partition(',')
-
-  if name == field:
-continue
-  str.append(name)
-  str.append(", ")
-
-if nfields > 1:
-  str.append(name)
-  return ''.join(str)
-else:
-  return ''
-
-def calc_sizeofargs(args, argc):
-strtype = ('const char*', 'char*', 'const char *', 'char *')
-str = []
-newstr = ""
-if argc > 0:
-  str = args.split(',')
-  for elem in str:
-if elem.lstrip().startswith(strtype): #strings
-  type, sep, var = elem.rpartition('*')
-  newstr = newstr+"4 + strlen("+var.lstrip()+") + "
-#elif '*' in elem:
-#  newstr = newstr + "4 + " # pointer vars
-else:
-  #type, sep, var = elem.rpartition(' ')
-  #newstr = newstr+"sizeof("+type.lstrip()+") + "
-  newstr = newstr + '8 + '
-newstr = newstr + '0' # for last +
-return newstr
-
-
 def trace_h_begin():
 print '''#ifndef TRACE_H
 #define TRACE_H
@@ -133,13 +90,6 @@ def simple_h(events):
 
 return
 
-def is_string(arg):
-strtype = ('const char*', 'char*', 'const char *', 'char *')
-if arg.lstrip().startswith(strtype):
-return True
-else:
-return False
-
 def simple_c(events):
 rec_off = 0
 print '#include "trace.h"'
@@ -154,8 +104,16 @@ def simple_c(events):
 print
 print '};'
 print
+
 for num, event in enumerate(events):
-argc = event.argc
+sizes = []
+for type_, name in event.args:
+if type_is_string(type_):
+sizes.append("4 + strlen(%s)" % name)
+else:
+sizes.append("8 + sizeof(%s)" % type_)
+sizestr = " + ".join(sizes)
+
 print '''void trace_%(name)s(%(args)s)
 {
 unsigned int tbuf_idx, rec_off __attribute__((unused));
@@ -166,52 +124,52 @@ def simple_c(events):
 if (!trace_list[%(event_id)s].state) {
 return;
 }
+
+tbuf_idx = trace_alloc_record(%(event_id)s, %(sizestr)s);
+rec_off = (tbuf_idx + ST_V2_REC_HDR_LEN) %% TRACE_BUF_LEN; /* seek record 
header */
 ''' % {
 'name': event.name,
 'args': event.args,
 'event_id': num,
+'sizestr' : sizestr,
 }
-print '''
-tbuf_idx = trace_alloc_record(%(event_id)s, %(sizestr)s);
-rec_off = (tbuf_idx + ST_V2_REC_HDR_LEN) %% TRACE_BUF_LEN; /* seek record 
header */
-''' % {'event_id': num, 'sizestr': event.sizestr,}
 
-if argc > 0:
-str = event.arglist
-for elem in str:
-if is_string(elem): # if string
-type, sep, var = elem.rpartition('*')
+if len(event.args) > 0:
+for type_, name in event.args:
+# string
+if type_is_string(type_):
 print '''
-slen = strlen(%(var)s);
+slen = strlen(%(name)s);
 write_to_buffer(rec_off, (uint8_t*)&slen, sizeof(slen));
 rec_off += sizeof(slen);''' % {
-'var': var.lstrip()
+'name': name
 }
 print '''
-write_to_buffer(rec_off, (uint8_t*)%(var)s, slen);
+write_to_buffer(rec_off, (uint8_t*)%(name)s, slen);
 rec_off += slen;''' % {
-'var': var.lstrip()
+'name': name
 }
-elif '*' in elem: # pointer var (not string)
-type, sep, var = elem.rpartition('*')
+# pointer var (not string)
+elif type_.endswith('*'):
 print '''
-pvar64 = (uint64_t)(uint64_t*)%(var)s;
+pvar64 = (uint64_t)(uint64_t*)%(name)s;
 write_to_buffer(rec_off, (uint8_t*)&pvar64, sizeof(uint64_t));
 rec_off += sizeof(uint64_t);''' % {
-'var': var.lstrip()
+'name': name
 }
-else: # primitive data type
-type, sep, var = elem.rpartition(' ')
+# primitive data type
+else:
 print '''
-var64 = (uint64_t)%(var)s;
+var64 = (uint64_t)%(name)s;
 write_to_buffer(rec_off, (uint8_t*)&var64, sizeof(uint64_t));
 rec_off += sizeof(uint64_t);''' % {
-'var': var.lstrip()
+'name': name
 }
 print '''
-trace_mark_record_complete(tbuf_idx);'''
-print '}'
-print
+trace_mark_record_complete(tbuf_idx);
+}
+
+'''
 
 return
 
@@ -220,12 +178,11 @@ def stderr_h(events):
 #include "trace/stderr.h"
 
 extern TraceEvent trace_list

[Qemu-devel] [PATCH v2 08/11] trace: [tracetool] Make format-specific code optional and with access to event information

2012-02-03 Thread Lluís Vilanova
Signed-off-by: Lluís Vilanova 
---
 scripts/tracetool.py |   35 ++-
 1 files changed, 10 insertions(+), 25 deletions(-)

diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index cd1c29d..91e7620 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -38,26 +38,19 @@ Options:
 '''
 sys.exit(1)
 
-def trace_h_begin():
+def trace_h_begin(events):
 print '''#ifndef TRACE_H
 #define TRACE_H
 
 /* This file is autogenerated by tracetool, do not edit. */
 
 #include "qemu-common.h"'''
-return
 
-def trace_h_end():
+def trace_h_end(events):
 print '#endif /* TRACE_H */'
-return
 
-def trace_c_begin():
+def trace_c_begin(events):
 print '/* This file is autogenerated by tracetool, do not edit. */'
-return
-
-def trace_c_end():
-# nop, required for trace_gen
-return
 
 def nop_h(events):
 print
@@ -350,7 +343,7 @@ probe %(probeprefix)s.%(name)s = 
process("%(binary)s").mark("%(name)s")
 def dtrace_nop_stp(events):
 pass
 
-def trace_stap_begin():
+def trace_stap_begin(events):
 global probeprefix
 if backend != "dtrace":
 print 'SystemTAP tapset generator not applicable to %s backend' % 
backend
@@ -367,20 +360,13 @@ def trace_stap_begin():
 if probeprefix == "":
 probeprefix = 'qemu.' + targettype + '.' + targetarch
 print '/* This file is autogenerated by tracetool, do not edit. */'
-return
 
-def trace_stap_end():
-return #nop, reqd for trace_gen
-
-def trace_d_begin():
+def trace_d_begin(events):
 if backend != 'dtrace':
 print 'DTrace probe generator not applicable to %s backend' % backend
 sys.exit(1)
 print '/* This file is autogenerated by tracetool, do not edit. */'
 
-def trace_d_end():
-return #nop, reqd for trace_gen
-
 
 # Registry of backends and their converter functions
 converters = {
@@ -416,22 +402,19 @@ converters = {
 }
 
 # Trace file header and footer code generators
-trace_gen = {
+formats = {
 'h': {
 'begin': trace_h_begin,
 'end': trace_h_end,
 },
 'c': {
 'begin': trace_c_begin,
-'end': trace_c_end,
 },
 'd': {
 'begin': trace_d_begin,
-'end': trace_d_end,
 },
 'stap': {
 'begin': trace_stap_begin,
-'end': trace_stap_end,
 },
 }
 
@@ -564,10 +547,12 @@ def main():
 
 events = read_events(sys.stdin)
 
-trace_gen[output]['begin']()
+if 'begin' in formats[output]:
+formats[output]['begin'](events)
 converters[backend][output]([ e for e in events if 'disable' not in 
e.properties ])
 converters['nop'][output]([ e for e in events if 'disable' in e.properties 
])
-trace_gen[output]['end']()
+if 'end' in formats[output]:
+formats[output]['end'](events)
 
 if __name__ == "__main__":
 main()




[Qemu-devel] [PATCH v2 09/11] trace: [tracetool] Automatically establish available backends and formats

2012-02-03 Thread Lluís Vilanova
Signed-off-by: Lluís Vilanova 
---
 Makefile.objs|6 -
 Makefile.target  |3 
 scripts/tracetool.py |  357 --
 3 files changed, 230 insertions(+), 136 deletions(-)

diff --git a/Makefile.objs b/Makefile.objs
index 2b68739..941386b 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -354,12 +354,12 @@ else
 trace.h: trace.h-timestamp
 endif
 trace.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
-   $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/tracetool.py 
--backend=$(TRACE_BACKEND) -h < $< > $@,"  GEN   trace.h")
+   $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/tracetool.py 
--format=h --backend=$(TRACE_BACKEND) < $< > $@,"  GEN   trace.h")
@cmp -s $@ trace.h || cp $@ trace.h
 
 trace.c: trace.c-timestamp
 trace.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
-   $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/tracetool.py 
--backend=$(TRACE_BACKEND) -c < $< > $@,"  GEN   trace.c")
+   $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/tracetool.py 
--format=c --backend=$(TRACE_BACKEND) < $< > $@,"  GEN   trace.c")
@cmp -s $@ trace.c || cp $@ trace.c
 
 trace.o: trace.c $(GENERATED_HEADERS)
@@ -372,7 +372,7 @@ trace-dtrace.h: trace-dtrace.dtrace
 # rule file. So we use '.dtrace' instead
 trace-dtrace.dtrace: trace-dtrace.dtrace-timestamp
 trace-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events 
$(BUILD_DIR)/config-host.mak
-   $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/tracetool.py 
--backend=$(TRACE_BACKEND) -d < $< > $@,"  GEN   trace-dtrace.dtrace")
+   $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/tracetool.py 
--format=d --backend=$(TRACE_BACKEND) < $< > $@,"  GEN   trace-dtrace.dtrace")
@cmp -s $@ trace-dtrace.dtrace || cp $@ trace-dtrace.dtrace
 
 trace-dtrace.o: trace-dtrace.dtrace $(GENERATED_HEADERS)
diff --git a/Makefile.target b/Makefile.target
index 2b24ea1..2bdf955 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -53,11 +53,12 @@ endif
 
 $(QEMU_PROG).stp:
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/tracetool.py \
+   --format=stap \
--backend=$(TRACE_BACKEND) \
--binary=$(bindir)/$(QEMU_PROG) \
--target-arch=$(TARGET_ARCH) \
--target-type=$(TARGET_TYPE) \
-   --stap < $(SRC_PATH)/trace-events > $(QEMU_PROG).stp,"  GEN   
$(QEMU_PROG).stp")
+   < $(SRC_PATH)/trace-events > $(QEMU_PROG).stp,"  GEN   
$(QEMU_PROG).stp")
 else
 stap:
 endif
diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index 91e7620..8ce39df 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -11,33 +11,109 @@
 import sys
 import getopt
 
-def usage():
-print "Tracetool: Generate tracing code for trace events file on stdin"
-print "Usage:"
-print sys.argv[0], " --backend=[nop|simple|stderr|dtrace|ust] 
[-h|-c|-d|--stap]"
-print '''
-Backends:
-  --nop Tracing disabled
-  --simple  Simple built-in backend
-  --stderr  Stderr built-in backend
-  --dtrace  DTrace/SystemTAP backend
-  --ust LTTng User Space Tracing backend
-
-Output formats:
-  -h Generate .h file
-  -c Generate .c file
-  -d Generate .d file (DTrace only)
-  --stap Generate .stp file (DTrace with SystemTAP only)
 
-Options:
-  --binary   [path]Full path to QEMU binary
-  --target-arch  [arch]QEMU emulator target arch
-  --target-type  [type]QEMU emulator target type ('system' or 'user')
-  --probe-prefix [prefix]  Prefix for dtrace probe names
-   (default: qemu-targettype-targetarch)
-'''
-sys.exit(1)
 
+##
+# format auto-registration
+
+class _Tag:
+pass
+
+_formats = {}
+
+BEGIN = _Tag()
+END = _Tag()
+_DESCR = _Tag()
+
+def for_format(format_, when, descr = None):
+"""Decorator for format generator functions."""
+
+if when is not BEGIN and when is not END:
+raise ValueError("Invalid 'when' tag")
+if format_ in _formats and when in _formats[format_]:
+raise ValueError("Format '%s' already set for given 'when' tag" % 
format_)
+
+if format_ not in _formats:
+_formats[format_] = {}
+if descr is not None:
+if _DESCR in _formats[format_]:
+raise ValueError("Description already set")
+_formats[format_][_DESCR] = descr
+
+def func(f):
+_formats[format_][when] = f
+return f
+return func
+
+def get_format(format_, when):
+"""Get a format generator function."""
+
+def nop(*args, **kwargs):
+pass
+if format_ in _formats and when in _formats[format_]:
+return _formats[format_][when]
+else:
+return nop
+
+def get_format_descr(format_):
+"""Get the description of a format generator."""
+
+if format_ in _formats and _DESCR in _formats[format_]:
+return _formats[f

[Qemu-devel] [PATCH v2 10/11] trace: Provide a per-event status define for conditional compilation

2012-02-03 Thread Lluís Vilanova
NOTE: This is a port of a patch in Stefanha's tracing tree to the new pythonic
  tracetool version.

Adds a 'TRACE_${NAME}_ENABLED' preprocessor define for each tracing event in
"trace.h".

This lets the user conditionally compile code with a relatively high execution
cost that is only necessary when producing the tracing information for an event
that is enabled.

Note that events using this define will probably have the "disable" property by
default, in order to avoid such costs on regular builds.

Signed-off-by: Lluís Vilanova 
---
 docs/tracing.txt |   46 --
 scripts/tracetool.py |7 +++
 2 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/docs/tracing.txt b/docs/tracing.txt
index ea29f2c..a92716f 100644
--- a/docs/tracing.txt
+++ b/docs/tracing.txt
@@ -98,12 +98,6 @@ respectively.  This ensures portability between 32- and 
64-bit platforms.
 4. Name trace events after their function.  If there are multiple trace events
in one function, append a unique distinguisher at the end of the name.
 
-5. If specific trace events are going to be called a huge number of times, this
-   might have a noticeable performance impact even when the trace events are
-   programmatically disabled. In this case you should declare the trace event
-   with the "disable" property, which will effectively disable it at compile
-   time (using the "nop" backend).
-
 == Generic interface and monitor commands ==
 
 You can programmatically query and control the dynamic state of trace events
@@ -234,3 +228,43 @@ probes:
   --target-type system \
   --target-arch x86_64 \
   qemu.stp
+
+== Trace event properties ==
+
+Each event in the "trace-events" file can be prefixed with a space-separated
+list of zero or more of the following event properties.
+
+=== "disable" ===
+
+If a specific trace event is going to be invoked a huge number of times, this
+might have a noticeable performance impact even when the event is
+programmatically disabled.
+
+In this case you should declare such event with the "disable" property. This
+will effectively disable the event at compile time (by using the "nop" 
backend),
+thus having no performance impact at all on regular builds (i.e., unless you
+edit the "trace-events" file).
+
+In addition, there might be cases where relatively complex computations must be
+performed to generate values that are only used as arguments for a trace
+function. In these cases you can use the macro 'TRACE_${EVENT_NAME}_ENABLED' to
+guard such computations and avoid its compilation when the event is disabled:
+
+#include "trace.h"  /* needed for trace event prototype */
+
+void *qemu_vmalloc(size_t size)
+{
+void *ptr;
+size_t align = QEMU_VMALLOC_ALIGN;
+
+if (size < align) {
+align = getpagesize();
+}
+ptr = qemu_memalign(align, size);
+if (TRACE_QEMU_VMALLOC_ENABLED) { /* preprocessor macro */
+void *complex;
+/* some complex computations to produce the 'complex' value */
+trace_qemu_vmalloc(size, ptr, complex);
+}
+return ptr;
+}
diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index 8ce39df..1134544 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -124,6 +124,13 @@ def trace_h_begin(events):
 
 @for_format("h", END)
 def trace_h_end(events):
+for e in events:
+if 'disable' in e.properties:
+enabled = 0
+else:
+enabled = 1
+print "#define TRACE_%s_ENABLED %d" % (e.name.upper(), enabled)
+print
 print '#endif /* TRACE_H */'
 
 




[Qemu-devel] [PATCH v2 11/11] trace: [tracetool] Add error-reporting functions

2012-02-03 Thread Lluís Vilanova
Signed-off-by: Lluís Vilanova 
---
 scripts/tracetool.py |   27 +++
 1 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index 1134544..7053a74 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -12,6 +12,13 @@ import sys
 import getopt
 
 
+def error_write(*lines):
+sys.stderr.writelines(lines)
+
+def error(*lines):
+error_write(*lines)
+sys.exit(1)
+
 
 ##
 # format auto-registration
@@ -443,14 +450,11 @@ def dtrace_nop_d(events):
 def trace_stap_begin(events):
 global probeprefix
 if binary == "":
-print '--binary is required for SystemTAP tapset generator'
-sys.exit(1)
+error("--binary is required for SystemTAP tapset generator\n")
 if ((probeprefix == "") and (targettype == "")):
-print '--target-type is required for SystemTAP tapset generator'
-sys.exit(1)
+error("--target-type is required for SystemTAP tapset generator\n")
 if ((probeprefix == "") and (targetarch == "")):
-print '--target-arch is required for SystemTAP tapset generator'
-sys.exit(1)
+error("--target-arch is required for SystemTAP tapset generator\n")
 if probeprefix == "":
 probeprefix = 'qemu.' + targettype + '.' + targetarch
 print '/* This file is autogenerated by tracetool, do not edit. */'
@@ -601,8 +605,9 @@ def main():
 try:
 opts, args = getopt.getopt(sys.argv[1:], "", long_options)
 except getopt.GetoptError, err:
-# print help information and exit:
-print str(err) # will print something like "option -a not recognized"
+# print help information and exit
+# will print something like "option -a not recognized"
+error_write(str(err)+"\n")
 usage()
 sys.exit(2)
 for opt, arg in opts:
@@ -631,12 +636,10 @@ def main():
 usage()
 
 if format_ not in _formats:
-print "Unknown format: %s" % format_
-print
+error_write("Unknown format: %s\n\n" % format_)
 usage()
 if backend not in _backends:
-print "Unknown backend: %s" % backend
-print
+error_write("Unknown backend: %s\n\n" % backend)
 usage()
 
 events = read_events(sys.stdin)




[Qemu-devel] [PATCH 0/3] More concise handling of tracetool-generated files

2012-02-03 Thread Lluís Vilanova
NOTE: Applies on top of the tracetool improvements series.

Some trivial changes to handle tracetool-generated files more concisely.

Signed-off-by: Lluís Vilanova 
---

Lluís Vilanova (3):
  [trivial] Generic elimination of auto-generated files
  [trivial] Simpler handling of tracetool-generated files in makfiles
  [trivial] Regenerate files when tracetool changes


 Makefile  |8 
 Makefile.objs |   25 -
 rules.mak |6 ++
 3 files changed, 22 insertions(+), 17 deletions(-)


To: qemu-devel@nongnu.org
Cc: Stefan Hajnoczi 



[Qemu-devel] [PATCH 1/3] [trivial] Generic elimination of auto-generated files

2012-02-03 Thread Lluís Vilanova
Signed-off-by: Lluís Vilanova 
---
 Makefile |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile
index 47acf3d..a9f3c7e 100644
--- a/Makefile
+++ b/Makefile
@@ -8,7 +8,7 @@ ifeq ($(TRACE_BACKEND),dtrace)
 GENERATED_HEADERS += trace-dtrace.h
 endif
 GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h
-GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c
+GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c trace.c
 
 ifneq ($(wildcard config-host.mak),)
 # Put the all: rule here so that config-host.mak can contain dependencies.
@@ -216,11 +216,11 @@ clean:
rm -f slirp/*.o slirp/*.d audio/*.o audio/*.d block/*.o block/*.d 
net/*.o net/*.d fsdev/*.o fsdev/*.d ui/*.o ui/*.d qapi/*.o qapi/*.d qga/*.o 
qga/*.d
rm -f qemu-img-cmds.h
rm -f trace/*.o trace/*.d
-   rm -f trace.c trace.h trace.c-timestamp trace.h-timestamp
rm -f trace-dtrace.dtrace trace-dtrace.dtrace-timestamp
+   @# May not be present in GENERATED_HEADERS
rm -f trace-dtrace.h trace-dtrace.h-timestamp
-   rm -f $(GENERATED_HEADERS)
-   rm -f $(GENERATED_SOURCES)
+   rm -f $(foreach f,$(GENERATED_HEADERS),$(f) $(f)-timestamp */$(f) 
*/$(f)-timestamp)
+   rm -f $(foreach f,$(GENERATED_SOURCES),$(f) $(f)-timestamp */$(f) 
*/$(f)-timestamp)
rm -rf $(qapi-dir)
$(MAKE) -C tests/tcg clean
for d in $(ALL_SUBDIRS) $(QEMULIBS) libcacard; do \




[Qemu-devel] [PATCH v2] usb: Resolve warnings about unassigned bus on usb device creation

2012-02-03 Thread Jan Kiszka
From: Jan Kiszka 

When creating an USB device the old way, there is no way to specify the
target bus. Thus the warning issued by usb_create makes no sense and
rather confuses our users.

Resolve this by passing a bus reference to the usbdevice_init handler
and letting those handlers forward it to usb_create.

Signed-off-by: Jan Kiszka 
---

Changes in v2:
 - rebased over master

 hw/usb-bt.c |4 ++--
 hw/usb-bus.c|   18 --
 hw/usb-msd.c|4 ++--
 hw/usb-net.c|4 ++--
 hw/usb-serial.c |8 
 hw/usb.h|7 ---
 usb-bsd.c   |4 ++--
 usb-linux.c |4 ++--
 vl.c|7 ---
 9 files changed, 26 insertions(+), 34 deletions(-)

diff --git a/hw/usb-bt.c b/hw/usb-bt.c
index 90c3b0e..46ea447 100644
--- a/hw/usb-bt.c
+++ b/hw/usb-bt.c
@@ -498,14 +498,14 @@ static int usb_bt_initfn(USBDevice *dev)
 return 0;
 }
 
-USBDevice *usb_bt_init(HCIInfo *hci)
+USBDevice *usb_bt_init(USBBus *bus, HCIInfo *hci)
 {
 USBDevice *dev;
 struct USBBtState *s;
 
 if (!hci)
 return NULL;
-dev = usb_create_simple(NULL /* FIXME */, "usb-bt-dongle");
+dev = usb_create_simple(bus, "usb-bt-dongle");
 if (!dev) {
 return NULL;
 }
diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index b753834..73b946e 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -203,13 +203,14 @@ typedef struct LegacyUSBFactory
 {
 const char *name;
 const char *usbdevice_name;
-USBDevice *(*usbdevice_init)(const char *params);
+USBDevice *(*usbdevice_init)(USBBus *bus, const char *params);
 } LegacyUSBFactory;
 
 static GSList *legacy_usb_factory;
 
 void usb_legacy_register(const char *typename, const char *usbdevice_name,
- USBDevice *(*usbdevice_init)(const char *params))
+ USBDevice *(*usbdevice_init)(USBBus *bus,
+  const char *params))
 {
 if (usbdevice_name) {
 LegacyUSBFactory *f = g_malloc0(sizeof(*f));
@@ -224,17 +225,6 @@ USBDevice *usb_create(USBBus *bus, const char *name)
 {
 DeviceState *dev;
 
-#if 1
-/* temporary stopgap until all usb is properly qdev-ified */
-if (!bus) {
-bus = usb_bus_find(-1);
-if (!bus)
-return NULL;
-error_report("%s: no bus specified, using \"%s\" for \"%s\"",
-__FUNCTION__, bus->qbus.name, name);
-}
-#endif
-
 dev = qdev_create(&bus->qbus, name);
 return USB_DEVICE(dev);
 }
@@ -565,7 +555,7 @@ USBDevice *usbdevice_create(const char *cmdline)
 }
 return usb_create_simple(bus, f->name);
 }
-return f->usbdevice_init(params);
+return f->usbdevice_init(bus, params);
 }
 
 static void usb_device_class_init(ObjectClass *klass, void *data)
diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index 6153376..50f0094 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -568,7 +568,7 @@ static int usb_msd_initfn(USBDevice *dev)
 return 0;
 }
 
-static USBDevice *usb_msd_init(const char *filename)
+static USBDevice *usb_msd_init(USBBus *bus, const char *filename)
 {
 static int nr=0;
 char id[8];
@@ -611,7 +611,7 @@ static USBDevice *usb_msd_init(const char *filename)
 }
 
 /* create guest device */
-dev = usb_create(NULL /* FIXME */, "usb-storage");
+dev = usb_create(bus, "usb-storage");
 if (!dev) {
 return NULL;
 }
diff --git a/hw/usb-net.c b/hw/usb-net.c
index e211141..f81bb8c 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1353,7 +1353,7 @@ static int usb_net_initfn(USBDevice *dev)
 return 0;
 }
 
-static USBDevice *usb_net_init(const char *cmdline)
+static USBDevice *usb_net_init(USBBus *bus, const char *cmdline)
 {
 USBDevice *dev;
 QemuOpts *opts;
@@ -1371,7 +1371,7 @@ static USBDevice *usb_net_init(const char *cmdline)
 return NULL;
 }
 
-dev = usb_create(NULL /* FIXME */, "usb-net");
+dev = usb_create(bus, "usb-net");
 if (!dev) {
 return NULL;
 }
diff --git a/hw/usb-serial.c b/hw/usb-serial.c
index c2cb6d2..ac7bc40 100644
--- a/hw/usb-serial.c
+++ b/hw/usb-serial.c
@@ -492,7 +492,7 @@ static int usb_serial_initfn(USBDevice *dev)
 return 0;
 }
 
-static USBDevice *usb_serial_init(const char *filename)
+static USBDevice *usb_serial_init(USBBus *bus, const char *filename)
 {
 USBDevice *dev;
 CharDriverState *cdrv;
@@ -535,7 +535,7 @@ static USBDevice *usb_serial_init(const char *filename)
 if (!cdrv)
 return NULL;
 
-dev = usb_create(NULL /* FIXME */, "usb-serial");
+dev = usb_create(bus, "usb-serial");
 if (!dev) {
 return NULL;
 }
@@ -549,7 +549,7 @@ static USBDevice *usb_serial_init(const char *filename)
 return dev;
 }
 
-static USBDevice *usb_braille_init(const char *unused)
+static USBDevice *usb_braille_init(USBBus *bus, const char *unused)
 {
 USBDevice *dev;
 CharDriverState *cdrv;
@@ -558,7 +558,7 @@ static USBDevice *usb_braille_init(

[Qemu-devel] [PATCH 2/3] [trivial] Simpler handling of tracetool-generated files in makfiles

2012-02-03 Thread Lluís Vilanova
Signed-off-by: Lluís Vilanova 
---
 Makefile.objs |   19 +--
 rules.mak |6 ++
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/Makefile.objs b/Makefile.objs
index 941386b..b187d17 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -349,18 +349,17 @@ libdis-$(CONFIG_SPARC_DIS) += sparc-dis.o
 # trace
 
 ifeq ($(TRACE_BACKEND),dtrace)
-trace.h: trace.h-timestamp trace-dtrace.h
-else
-trace.h: trace.h-timestamp
+TRACE_H_EXTRA_DEPS=trace-dtrace.h
 endif
+trace.h: trace.h-timestamp $(TRACE_H_EXTRA_DEPS)
 trace.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
-   $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/tracetool.py 
--format=h --backend=$(TRACE_BACKEND) < $< > $@,"  GEN   trace.h")
-   @cmp -s $@ trace.h || cp $@ trace.h
+   $(call tracetool-gen,h,$(TRACE_BACKEND))
+   $(call tracetool-ci)
 
 trace.c: trace.c-timestamp
 trace.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
-   $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/tracetool.py 
--format=c --backend=$(TRACE_BACKEND) < $< > $@,"  GEN   trace.c")
-   @cmp -s $@ trace.c || cp $@ trace.c
+   $(call tracetool-gen,c,$(TRACE_BACKEND))
+   $(call tracetool-ci)
 
 trace.o: trace.c $(GENERATED_HEADERS)
 
@@ -372,11 +371,11 @@ trace-dtrace.h: trace-dtrace.dtrace
 # rule file. So we use '.dtrace' instead
 trace-dtrace.dtrace: trace-dtrace.dtrace-timestamp
 trace-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events 
$(BUILD_DIR)/config-host.mak
-   $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/tracetool.py 
--format=d --backend=$(TRACE_BACKEND) < $< > $@,"  GEN   trace-dtrace.dtrace")
-   @cmp -s $@ trace-dtrace.dtrace || cp $@ trace-dtrace.dtrace
+   $(call tracetool-gen,d,$(TRACE_BACKEND))
+   $(call tracetool-ci)
 
 trace-dtrace.o: trace-dtrace.dtrace $(GENERATED_HEADERS)
-   $(call quiet-command,dtrace -o $@ -G -s $<, "  GEN trace-dtrace.o")
+   $(call quiet-command,dtrace -o $@ -G -s $<, "  GEN   trace-dtrace.o")
 
 ifeq ($(LIBTOOL),)
 trace-dtrace.lo: trace-dtrace.dtrace
diff --git a/rules.mak b/rules.mak
index 04a9198..a7e58a0 100644
--- a/rules.mak
+++ b/rules.mak
@@ -59,6 +59,12 @@ find-in-path = $(if $(find-string /, $1), \
 $(wildcard $1), \
 $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH)
 
+# Generate files with tracetool
+
+TRACETOOL=$(SRC_PATH)/scripts/tracetool.py
+tracetool-gen=$(call quiet-command,$(PYTHON) $(TRACETOOL) $(3) --format=$(1) 
--backend=$(2) < $< > $@,"  GEN   $(subst -timestamp,,$@)")
+tracetool-ci=@cmp -s $@ $(subst -timestamp,,$@) || cp $@ $(subst 
-timestamp,,$@)
+
 # Generate timestamp files for .h include files
 
 %.h: %.h-timestamp




[Qemu-devel] [PATCH 3/3] [trivial] Regenerate files when tracetool changes

2012-02-03 Thread Lluís Vilanova
Signed-off-by: Lluís Vilanova 
---
 Makefile.objs |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/Makefile.objs b/Makefile.objs
index b187d17..e6644c6 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -352,12 +352,12 @@ ifeq ($(TRACE_BACKEND),dtrace)
 TRACE_H_EXTRA_DEPS=trace-dtrace.h
 endif
 trace.h: trace.h-timestamp $(TRACE_H_EXTRA_DEPS)
-trace.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
+trace.h-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak 
$(TRACETOOL)
$(call tracetool-gen,h,$(TRACE_BACKEND))
$(call tracetool-ci)
 
 trace.c: trace.c-timestamp
-trace.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak
+trace.c-timestamp: $(SRC_PATH)/trace-events $(BUILD_DIR)/config-host.mak 
$(TRACETOOL)
$(call tracetool-gen,c,$(TRACE_BACKEND))
$(call tracetool-ci)
 
@@ -370,7 +370,7 @@ trace-dtrace.h: trace-dtrace.dtrace
 # but that gets picked up by QEMU's Makefile as an external dependency
 # rule file. So we use '.dtrace' instead
 trace-dtrace.dtrace: trace-dtrace.dtrace-timestamp
-trace-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events 
$(BUILD_DIR)/config-host.mak
+trace-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events 
$(BUILD_DIR)/config-host.mak $(TRACETOOL)
$(call tracetool-gen,d,$(TRACE_BACKEND))
$(call tracetool-ci)
 




[Qemu-devel] [PATCH 0/6] trace: Generic event state description

2012-02-03 Thread Lluís Vilanova
NOTE: Applies on top of the tracetool-handling trivial changes.

Provides a generic event state description and a more detailed event control and
query interface.

Signed-off-by: Lluís Vilanova 
---

Lluís Vilanova (6):
  trace: Provide a generic tracing event descriptor
  trace: Provide a detailed event control interface
  trace: [monitor] Use new event control interface
  trace: [default] Use new event control interface
  trace: [simple] Port to generic event information and new control 
interface
  trace: [stderr] Port to generic event information and new control 
interface


 Makefile |5 ++
 Makefile.objs|   13 
 docs/tracing.txt |   38 
 monitor.c|   15 -
 scripts/tracetool.py |  144 --
 trace/control-internal.h |   49 
 trace/control.c  |   89 ++--
 trace/control.h  |  126 +---
 trace/default.c  |3 -
 trace/event-internal.h   |   31 ++
 trace/simple.c   |   32 ++
 trace/simple.h   |6 --
 trace/stderr.c   |   34 ++-
 trace/stderr.h   |   11 
 14 files changed, 434 insertions(+), 162 deletions(-)
 create mode 100644 trace/control-internal.h
 create mode 100644 trace/event-internal.h
 delete mode 100644 trace/stderr.h


To: qemu-devel@nongnu.org
Cc: Stefan Hajnoczi 
Cc: Blue Swirl 



[Qemu-devel] [PATCH 1/6] trace: Provide a generic tracing event descriptor

2012-02-03 Thread Lluís Vilanova
Uses tracetool to generate a backend-independent tracing event description.

Signed-off-by: Lluís Vilanova 
---
 Makefile   |5 +++
 Makefile.objs  |   13 +++
 scripts/tracetool.py   |   90 
 trace/event-internal.h |   31 +
 4 files changed, 132 insertions(+), 7 deletions(-)
 create mode 100644 trace/event-internal.h

diff --git a/Makefile b/Makefile
index a9f3c7e..13e603c 100644
--- a/Makefile
+++ b/Makefile
@@ -4,9 +4,14 @@
 BUILD_DIR=$(CURDIR)
 
 GENERATED_HEADERS = config-host.h trace.h qemu-options.def
+
+GENERATED_HEADERS += trace-events.h
+GENERATED_SOURCES += trace-events.c
+
 ifeq ($(TRACE_BACKEND),dtrace)
 GENERATED_HEADERS += trace-dtrace.h
 endif
+
 GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h
 GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c trace.c
 
diff --git a/Makefile.objs b/Makefile.objs
index e6644c6..194a33d 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -348,6 +348,19 @@ libdis-$(CONFIG_SPARC_DIS) += sparc-dis.o
 ##
 # trace
 
+trace-events.h: trace-events.h-timestamp
+trace-events.h-timestamp: $(SRC_PATH)/trace-events $(TRACETOOL)
+   $(call tracetool-gen,events-h,events)
+   $(call tracetool-ci)
+
+trace-events.c: trace-events.c-timestamp
+trace-events.c-timestamp: $(SRC_PATH)/trace-events $(TRACETOOL)
+   $(call tracetool-gen,events-c,events)
+   $(call tracetool-ci)
+
+trace-obj-y += trace-events.o
+
+
 ifeq ($(TRACE_BACKEND),dtrace)
 TRACE_H_EXTRA_DEPS=trace-dtrace.h
 endif
diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index 7053a74..91da998 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -118,6 +118,73 @@ def get_backend_descr(backend):
 # formats
 
 ##
+# format: events-h
+
+@for_format("events-h", BEGIN, "Generate .h for event description")
+def process(events):
+print """\
+/* This file is autogenerated by tracetool, do not edit. */
+
+#ifndef TRACE_EVENTS_H
+#define TRACE_EVENTS_H
+
+#include 
+"""
+
+# event identifiers
+print """
+typedef enum {\
+"""
+for event in events:
+print "TRACE_%s," % event.name.upper()
+print """\
+TRACE_EVENT_COUNT
+} TraceEventID;
+"""
+
+# static state
+for e in events:
+if 'disable' in e.properties:
+enabled = 0
+else:
+enabled = 1
+print "#define TRACE_%s_ENABLED %d" % (e.name.upper(), enabled)
+
+print """\
+#include "trace/event-internal.h"
+
+#endif  /* TRACE_EVENTS_H */\
+"""
+
+
+##
+# format: events-c
+
+@for_format("events-c", BEGIN, "Generate .h for event description")
+def process(events):
+print """\
+/* This file is autogenerated by tracetool, do not edit. */
+
+#include "trace.h"
+#include "trace-events.h"
+#include "trace/control.h"
+
+
+TraceEvent trace_events[TRACE_EVENT_COUNT] = {\
+"""
+for e in events:
+print """\
+{ .id = %(id)s, .name = \"%(name)s\", .sstate = %(sstate)s, .dstate = 0 },\
+""" % { "id": "TRACE_" + e.name.upper(),
+"name": e.name,
+"sstate": "TRACE_%s_ENABLED" % e.name.upper(),
+}
+print """\
+};
+"""
+
+
+##
 # format: h
 
 @for_format("h", BEGIN, "Generate .h file")
@@ -131,13 +198,6 @@ def trace_h_begin(events):
 
 @for_format("h", END)
 def trace_h_end(events):
-for e in events:
-if 'disable' in e.properties:
-enabled = 0
-else:
-enabled = 1
-print "#define TRACE_%s_ENABLED %d" % (e.name.upper(), enabled)
-print
 print '#endif /* TRACE_H */'
 
 
@@ -154,6 +214,22 @@ def trace_c_begin(events):
 # backends
 
 ##
+# backend: events
+
+@for_backend("events", "events-h", "Generic event description")
+def process(events):
+pass
+
+@for_backend("nop", "events-h")
+def process(events):
+pass
+
+@for_backend("events", "events-c")
+def process(events):
+pass
+
+
+##
 # backend: nop
 
 @for_backend("nop", "h", "Tracing disabled")
diff --git a/trace/event-internal.h b/trace/event-internal.h
new file mode 100644
index 000..48f1298
--- /dev/null
+++ b/trace/event-internal.h
@@ -0,0 +1,31 @@
+/*
+ * Interface for configuring and controlling the state of tracing events.
+ *
+ * Copyright (C) 2012 Lluís Vilanova 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef TRACE__EVENT_H
+#define TRACE__EVENT_H
+
+#include "trace-events.h"
+
+
+/**
+ * Generic description of a tracing event.
+ */
+typedef struct {
+/** Unique event identifier. */
+TraceEventID id;
+/** Event name. */
+const char * name;
+/** Static instrumentation 

[Qemu-devel] [PATCH 2/6] trace: Provide a detailed event control interface

2012-02-03 Thread Lluís Vilanova
This interface decouples event obtention from interaction.

Event can be obtained through three different methods:

* identifier
* name
* simple wildcard pattern

Signed-off-by: Lluís Vilanova 
---
 docs/tracing.txt |   38 +-
 trace/control-internal.h |   49 ++
 trace/control.c  |   89 ++--
 trace/control.h  |  126 ++
 4 files changed, 260 insertions(+), 42 deletions(-)
 create mode 100644 trace/control-internal.h

diff --git a/docs/tracing.txt b/docs/tracing.txt
index a92716f..787cabd 100644
--- a/docs/tracing.txt
+++ b/docs/tracing.txt
@@ -100,44 +100,32 @@ respectively.  This ensures portability between 32- and 
64-bit platforms.
 
 == Generic interface and monitor commands ==
 
-You can programmatically query and control the dynamic state of trace events
-through a backend-agnostic interface:
+You can programmatically query and control the state of trace events through a
+backend-agnostic interface provided by the file "trace/control.h".
 
-* trace_print_events
+Note that some of the backends do not provide an implementation for some parts
+of this interface, in which case QEMU will just print a warning (please refer 
to
+header "trace/control.h" to see which routines are backend-dependant).
 
-* trace_event_set_state
-  Enables or disables trace events at runtime inside QEMU.
-  The function returns "true" if the state of the event has been successfully
-  changed, or "false" otherwise:
-
-#include "trace/control.h"
-
-trace_event_set_state("virtio_irq", true); /* enable */
-[...]
-trace_event_set_state("virtio_irq", false); /* disable */
-
-Note that some of the backends do not provide an implementation for this
-interface, in which case QEMU will just print a warning.
-
-This functionality is also provided through monitor commands:
+The state of events can also be queried and modified through monitor commands:
 
 * info trace-events
   View available trace events and their state.  State 1 means enabled, state 0
   means disabled.
 
 * trace-event NAME on|off
-  Enable/disable a given trace event or a group of events having common prefix
-  through wildcard.
+  Enable/disable a given trace event or a group of events (using wildcards).
 
 The "-trace events=" command line argument can be used to enable the
 events listed in  from the very beginning of the program. This file must
 contain one event name per line.
 
-A basic wildcard matching is supported in both the monitor command "trace
--event" and the events list file. That means you can enable/disable the events
-having a common prefix in a batch. For example, virtio-blk trace events could
-be enabled using:
-  trace-event virtio_blk_* on
+Wildcard matching is supported in both the monitor command "trace -event" and
+the events list file. That means you can enable/disable the events having a
+common prefix in a batch. For example, virtio-blk trace events could be enabled
+using the following monitor command:
+
+trace-event virtio_blk_* on
 
 == Trace backends ==
 
diff --git a/trace/control-internal.h b/trace/control-internal.h
new file mode 100644
index 000..e609ab2
--- /dev/null
+++ b/trace/control-internal.h
@@ -0,0 +1,49 @@
+/*
+ * Interface for configuring and controlling the state of tracing events.
+ *
+ * Copyright (C) 2011, 2012 Lluís Vilanova 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+
+extern TraceEvent trace_events[];
+
+
+static inline TraceEvent *trace_event_id(TraceEventID id)
+{
+assert(id < trace_event_count());
+return &trace_events[id];
+}
+
+static inline TraceEventID trace_event_count(void)
+{
+return TRACE_EVENT_COUNT;
+}
+
+static inline bool trace_event_is_pattern(const char *str)
+{
+while (*str != '\0') {
+if (*str == '*') {
+return true;
+}
+str++;
+}
+return false;
+}
+
+static inline TraceEventID trace_event_get_id(TraceEvent *ev)
+{
+return ev->id;
+}
+
+static inline const char * trace_event_get_name(TraceEvent *ev)
+{
+return ev->name;
+}
+
+static inline bool trace_event_get_state_dynamic(TraceEvent *ev)
+{
+return ev->dstate;
+}
diff --git a/trace/control.c b/trace/control.c
index 4c5527d..c159fab 100644
--- a/trace/control.c
+++ b/trace/control.c
@@ -1,15 +1,81 @@
 /*
  * Interface for configuring and controlling the state of tracing events.
  *
- * Copyright (C) 2011 Lluís Vilanova 
+ * Copyright (C) 2011, 2012 Lluís Vilanova 
  *
- * This work is licensed under the terms of the GNU GPL, version 2.  See
- * the COPYING file in the top-level directory.
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
  */
 
 #include "trace/control.h"
 
 
+TraceEvent *trace_event_name(const char *name)
+{
+TraceEventID i;
+   

[Qemu-devel] [PATCH 3/6] trace: [monitor] Use new event control interface

2012-02-03 Thread Lluís Vilanova
Signed-off-by: Lluís Vilanova 
---
 monitor.c |   15 ---
 1 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/monitor.c b/monitor.c
index 5e099bd..010f659 100644
--- a/monitor.c
+++ b/monitor.c
@@ -617,10 +617,19 @@ static void do_trace_event_set_state(Monitor *mon, const 
QDict *qdict)
 {
 const char *tp_name = qdict_get_str(qdict, "name");
 bool new_state = qdict_get_bool(qdict, "option");
-int ret = trace_event_set_state(tp_name, new_state);
 
-if (!ret) {
-monitor_printf(mon, "unknown event name \"%s\"\n", tp_name);
+if (trace_event_is_pattern(tp_name)) {
+TraceEvent *ev = NULL;
+while ((ev = trace_event_pattern(tp_name, ev)) != NULL) {
+trace_event_set_state_dynamic(ev, new_state);
+}
+} else {
+TraceEvent *ev = trace_event_name(tp_name);
+if (ev == NULL) {
+monitor_printf(mon, "unknown event name \"%s\"\n", tp_name);
+} else {
+trace_event_set_state_dynamic(ev, new_state);
+}
 }
 }
 




[Qemu-devel] [PATCH 4/6] trace: [default] Use new event control interface

2012-02-03 Thread Lluís Vilanova
Signed-off-by: Lluís Vilanova 
---
 trace/default.c |3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/trace/default.c b/trace/default.c
index c9b27a2..12db18d 100644
--- a/trace/default.c
+++ b/trace/default.c
@@ -18,11 +18,10 @@ void trace_print_events(FILE *stream, fprintf_function 
stream_printf)
   "operation not supported with the current backend\n");
 }
 
-bool trace_event_set_state(const char *name, bool state)
+void trace_event_set_state_dynamic(TraceEvent *ev, bool state)
 {
 fprintf(stderr, "warning: "
 "cannot set the state of a trace event with the current 
backend\n");
-return false;
 }
 
 bool trace_backend_init(const char *events, const char *file)




[Qemu-devel] [PATCH 5/6] trace: [simple] Port to generic event information and new control interface

2012-02-03 Thread Lluís Vilanova
Signed-off-by: Lluís Vilanova 
---
 scripts/tracetool.py |   28 +---
 trace/simple.c   |   32 +---
 trace/simple.h   |6 +-
 trace/stderr.h   |   11 ---
 4 files changed, 15 insertions(+), 62 deletions(-)
 delete mode 100644 trace/stderr.h

diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index 91da998..f4ce927 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -261,28 +261,17 @@ def simple_h(events):
 'name': event.name,
 'args': event.args
 }
-print
-print '#define NR_TRACE_EVENTS %d' % len(events)
-print 'extern TraceEvent trace_list[NR_TRACE_EVENTS];'
 
 @for_backend("simple", "c")
 def simple_c(events):
 rec_off = 0
-print '#include "trace.h"'
-print '#include "trace/simple.h"'
-print
-print 'TraceEvent trace_list[] = {'
-print
-for event in events:
-print '{.tp_name = "%(name)s", .state=0},' % {
-'name': event.name
-}
-print
-print '};'
-print
+print """\
+#include "trace.h"
+#include "trace/simple.h"
+"""
 
-for num, event in enumerate(events):
-sizes = []
+for event in events:
+sizes = ["0"]
 for type_, name in event.args:
 if type_is_string(type_):
 sizes.append("4 + strlen(%s)" % name)
@@ -297,7 +286,8 @@ def simple_c(events):
 uint64_t pvar64 __attribute__ ((unused));
 uint32_t slen __attribute__ ((unused));
 
-if (!trace_list[%(event_id)s].state) {
+bool _state = trace_event_get_state(%(event_id)s);
+if (!_state) {
 return;
 }
 
@@ -306,7 +296,7 @@ def simple_c(events):
 ''' % {
 'name': event.name,
 'args': event.args,
-'event_id': num,
+'event_id': "TRACE_" + event.name.upper(),
 'sizestr' : sizestr,
 }
 
diff --git a/trace/simple.c b/trace/simple.c
index f5aa3bd..d4da9d3 100644
--- a/trace/simple.c
+++ b/trace/simple.c
@@ -263,38 +263,16 @@ void trace_print_events(FILE *stream, fprintf_function 
stream_printf)
 {
 unsigned int i;
 
-for (i = 0; i < NR_TRACE_EVENTS; i++) {
+for (i = 0; i < trace_event_count(); i++) {
+TraceEvent *ev = trace_event_id(i);
 stream_printf(stream, "%s [Event ID %u] : state %u\n",
-  trace_list[i].tp_name, i, trace_list[i].state);
+  trace_event_get_name(ev), i, 
trace_event_get_state_dynamic(ev));
 }
 }
 
-bool trace_event_set_state(const char *name, bool state)
+void trace_event_set_state_dynamic(TraceEvent *ev, bool state)
 {
-unsigned int i;
-unsigned int len;
-bool wildcard = false;
-bool matched = false;
-
-len = strlen(name);
-if (len > 0 && name[len - 1] == '*') {
-wildcard = true;
-len -= 1;
-}
-for (i = 0; i < NR_TRACE_EVENTS; i++) {
-if (wildcard) {
-if (!strncmp(trace_list[i].tp_name, name, len)) {
-trace_list[i].state = state;
-matched = true;
-}
-continue;
-}
-if (!strcmp(trace_list[i].tp_name, name)) {
-trace_list[i].state = state;
-return true;
-}
-}
-return matched;
+ev->dstate = state;
 }
 
 /* Helper function to create a thread with signals blocked.  Use glib's
diff --git a/trace/simple.h b/trace/simple.h
index 671cbeb..6850ac5 100644
--- a/trace/simple.h
+++ b/trace/simple.h
@@ -15,12 +15,8 @@
 #include 
 #include 
 
-typedef uint64_t TraceEventID;
+#include "trace-events.h"
 
-typedef struct {
-const char *tp_name;
-bool state;
-} TraceEvent;
 
 void st_print_trace(FILE *stream, fprintf_function stream_printf);
 void st_print_trace_file_status(FILE *stream, fprintf_function stream_printf);
diff --git a/trace/stderr.h b/trace/stderr.h
deleted file mode 100644
index d575b61..000
--- a/trace/stderr.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef TRACE_STDERR_H
-#define TRACE_STDERR_H
-
-typedef uint64_t TraceEventID;
-
-typedef struct {
-const char *tp_name;
-bool state;
-} TraceEvent;
-
-#endif /* ! TRACE_STDERR_H */




[Qemu-devel] [PATCH 6/6] trace: [stderr] Port to generic event information and new control interface

2012-02-03 Thread Lluís Vilanova
Signed-off-by: Lluís Vilanova 
---
 scripts/tracetool.py |   26 --
 trace/stderr.c   |   34 ++
 2 files changed, 14 insertions(+), 46 deletions(-)

diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index f4ce927..c6f5ea6 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -343,10 +343,10 @@ def simple_c(events):
 
 @for_backend("stderr", "h", "Stderr built-in backend")
 def stderr_h(events):
-print '''#include 
-#include "trace/stderr.h"
-
-extern TraceEvent trace_list[];'''
+print """\
+#include 
+#include "trace/control.h"
+"""
 
 for num, event in enumerate(events):
 argnames = ", ".join(event.args.names())
@@ -355,31 +355,21 @@ extern TraceEvent trace_list[];'''
 print '''
 static inline void trace_%(name)s(%(args)s)
 {
-if (trace_list[%(event_num)s].state != 0) {
+bool _state = trace_event_get_state(%(event_id)s);
+if (_state) {
 fprintf(stderr, "%(name)s " %(fmt)s "\\n" %(argnames)s);
 }
 }''' % {
 'name': event.name,
 'args': event.args,
-'event_num': num,
+'event_id': "TRACE_" + event.name.upper(),
 'fmt': event.fmt.rstrip('\n'),
 'argnames': argnames
 }
-print
-print '#define NR_TRACE_EVENTS %d' % len(events)
 
 @for_backend("stderr", "c")
 def stderr_c(events):
-print '''#include "trace.h"
-
-TraceEvent trace_list[] = {
-'''
-for event in events:
-print '{.tp_name = "%(name)s", .state=0},' % {
-'name': event.name
-}
-print
-print '};'
+pass
 
 
 ##
diff --git a/trace/stderr.c b/trace/stderr.c
index 0810d6f..6685aeb 100644
--- a/trace/stderr.c
+++ b/trace/stderr.c
@@ -4,40 +4,18 @@
 
 void trace_print_events(FILE *stream, fprintf_function stream_printf)
 {
-unsigned int i;
+TraceEventID i;
 
-for (i = 0; i < NR_TRACE_EVENTS; i++) {
+for (i = 0; i < trace_event_count(); i++) {
+TraceEvent *ev = trace_event_id(i);
 stream_printf(stream, "%s [Event ID %u] : state %u\n",
-  trace_list[i].tp_name, i, trace_list[i].state);
+  trace_event_get_name(ev), i, 
trace_event_get_state_dynamic(ev));
 }
 }
 
-bool trace_event_set_state(const char *name, bool state)
+void trace_event_set_state_dynamic(TraceEvent *ev, bool state)
 {
-unsigned int i;
-unsigned int len;
-bool wildcard = false;
-bool matched = false;
-
-len = strlen(name);
-if (len > 0 && name[len - 1] == '*') {
-wildcard = true;
-len -= 1;
-}
-for (i = 0; i < NR_TRACE_EVENTS; i++) {
-if (wildcard) {
-if (!strncmp(trace_list[i].tp_name, name, len)) {
-trace_list[i].state = state;
-matched = true;
-}
-continue;
-}
-if (!strcmp(trace_list[i].tp_name, name)) {
-trace_list[i].state = state;
-return true;
-}
-}
-return matched;
+ev->dstate = state;
 }
 
 bool trace_backend_init(const char *events, const char *file)




Re: [Qemu-devel] Is there any document about qemu's kernel boot loader?

2012-02-03 Thread 陳韋任
On Thu, Feb 02, 2012 at 10:48:13AM +0800, 杨亮 wrote:
> Hi, recently I am focusing on KVM(kernel virtualization machine), in which
> the device simulation employ the Qemu’s code directly. Still, the Qemu can
> run the Guest OS alone, from kernel boot to device simulation.
> 
>  
> 
> Device simulation is somehow easy to comprehend. As for kernel boot, is
> there any detailed document? I need some to make it clearer.

  I guess not. You might need to read the source code first then ask question
here. :)

Regards,
chenwj

-- 
Wei-Ren Chen (陳韋任)
Computer Systems Lab, Institute of Information Science,
Academia Sinica, Taiwan (R.O.C.)
Tel:886-2-2788-3799 #1667
Homepage: http://people.cs.nctu.edu.tw/~chenwj



Re: [Qemu-devel] [PATCH v2 2/8] qemu-ga: move channel/transport functionalit

2012-02-03 Thread MATSUDA, Daiki
Hi, Michael!
Thank you for your working.

And I have a question the process id written in pid file.
If qemu-ga is ran as daemon, the parent process id not child is written
in pid file. So, id gotten by 'ps' command is different. Is it correct
work? Many other daemon writes child process id.

Regards
MATSUDA Daiki



Re: [Qemu-devel] [RFC] Next gen kvm api

2012-02-03 Thread Rob Earhart
(Resending as plain text to appease vger.kernel.org :-)

On Thu, Feb 2, 2012 at 8:09 AM, Avi Kivity  wrote:
>
> The kvm api has been accumulating cruft for several years now.  This is
> due to feature creep, fixing mistakes, experience gained by the
> maintainers and developers on how to do things, ports to new
> architectures, and simply as a side effect of a code base that is
> developed slowly and incrementally.
>
> While I don't think we can justify a complete revamp of the API now, I'm
> writing this as a thought experiment to see where a from-scratch API can
> take us.  Of course, if we do implement this, the new and old APIs will
> have to be supported side by side for several years.
>
> Syscalls
> 
> kvm currently uses the much-loved ioctl() system call as its entry
> point.  While this made it easy to add kvm to the kernel unintrusively,
> it does have downsides:
>
> - overhead in the entry path, for the ioctl dispatch path and vcpu mutex
> (low but measurable)
> - semantic mismatch: kvm really wants a vcpu to be tied to a thread, and
> a vm to be tied to an mm_struct, but the current API ties them to file
> descriptors, which can move between threads and processes.  We check
> that they don't, but we don't want to.
>
> Moving to syscalls avoids these problems, but introduces new ones:
>
> - adding new syscalls is generally frowned upon, and kvm will need several
> - syscalls into modules are harder and rarer than into core kernel code
> - will need to add a vcpu pointer to task_struct, and a kvm pointer to
> mm_struct
>
> Syscalls that operate on the entire guest will pick it up implicitly
> from the mm_struct, and syscalls that operate on a vcpu will pick it up
> from current.
>



I like the ioctl() interface.  If the overhead matters in your hot
path, I suspect you're doing it wrong; use irq fds & ioevent fds.  You
might fix the semantic mismatch by having a notion of a "current
process's VM" and "current thread's VCPU", and just use the one
/dev/kvm filedescriptor.

Or you could go the other way, and break the connection between VMs
and processes / VCPUs and threads: I don't know how easy it is to do
it in Linux, but a VCPU might be backed by a kernel thread, operated
on via ioctl()s, indicating that they've exited the guest by having
their descriptors become readable (and either use read() or mmap() to
pull off the reason why the VCPU exited).  This would allow for a
variety of different programming styles for the VMM--I'm a fan of CSP
model myself, but that's hard to do with the current API.

It'd be nice to be able to kick a VCPU out of the guest without
messing around with signals.  One possibility would be to tie it to an
eventfd; another might be to add a pseudo-register to indicate whether
the VCPU is explicitly suspended.  (Combined with the decoupling idea,
you'd want another pseudo-register to indicate whether the VMM is
implicitly suspended due to an intercept; a single "runnable" bit is
racy if both the VMM and VCPU are setting it.)

ioevent fds are definitely useful.  It might be cute if they could
synchronously set the VIRTIO_USED_F_NOTIFY bit - the guest could do
this itself, but that'd require giving the guest write access to the
used side of the virtio queue, and I kind of like the idea that it
doesn't need write access there.  Then again, I don't have any perf
data to back up the need for this.

The rest of it sounds great.

)Rob



Re: [Qemu-devel] [RFC] Next gen kvm api

2012-02-03 Thread Rob Earhart
On Thu, Feb 2, 2012 at 8:09 AM, Avi Kivity  wrote:

> The kvm api has been accumulating cruft for several years now.  This is
> due to feature creep, fixing mistakes, experience gained by the
> maintainers and developers on how to do things, ports to new
> architectures, and simply as a side effect of a code base that is
> developed slowly and incrementally.
>
> While I don't think we can justify a complete revamp of the API now, I'm
> writing this as a thought experiment to see where a from-scratch API can
> take us.  Of course, if we do implement this, the new and old APIs will
> have to be supported side by side for several years.
>
> Syscalls
> 
> kvm currently uses the much-loved ioctl() system call as its entry
> point.  While this made it easy to add kvm to the kernel unintrusively,
> it does have downsides:
>
> - overhead in the entry path, for the ioctl dispatch path and vcpu mutex
> (low but measurable)
> - semantic mismatch: kvm really wants a vcpu to be tied to a thread, and
> a vm to be tied to an mm_struct, but the current API ties them to file
> descriptors, which can move between threads and processes.  We check
> that they don't, but we don't want to.
>
> Moving to syscalls avoids these problems, but introduces new ones:
>
> - adding new syscalls is generally frowned upon, and kvm will need several
> - syscalls into modules are harder and rarer than into core kernel code
> - will need to add a vcpu pointer to task_struct, and a kvm pointer to
> mm_struct
>
> Syscalls that operate on the entire guest will pick it up implicitly
> from the mm_struct, and syscalls that operate on a vcpu will pick it up
> from current.
>
>


I like the ioctl() interface.  If the overhead matters in your hot path, I
suspect you're doing it wrong; use irq fds & ioevent fds.  You might fix
the semantic mismatch by having a notion of a "current process's VM" and
"current thread's VCPU", and just use the one /dev/kvm filedescriptor.

Or you could go the other way, and break the connection between VMs and
processes / VCPUs and threads: I don't know how easy it is to do it in
Linux, but a VCPU might be backed by a kernel thread, operated on via
ioctl()s, indicating that they've exited the guest by having their
descriptors become readable (and either use read() or mmap() to pull off
the reason why the VCPU exited).  This would allow for a variety of
different programming styles for the VMM--I'm a fan of CSP model myself,
but that's hard to do with the current API.

It'd be nice to be able to kick a VCPU out of the guest without messing
around with signals.  One possibility would be to tie it to an eventfd;
another might be to add a pseudo-register to indicate whether the VCPU is
explicitly suspended.  (Combined with the decoupling idea, you'd want
another pseudo-register to indicate whether the VMM is implicitly suspended
due to an intercept; a single "runnable" bit is racy if both the VMM and
VCPU are setting it.)

ioevent fds are definitely useful.  It might be cute if they could
synchronously set the VIRTIO_USED_F_NOTIFY bit - the guest could do this
itself, but that'd require giving the guest write access to the used side
of the virtio queue, and I kind of like the idea that it doesn't need write
access there.  Then again, I don't have any perf data to back up the need
for this.

The rest of it sounds great.

)Rob


[Qemu-devel] QEMU build errors with 'fdopendir'

2012-02-03 Thread Meador Inge
Did these [1] builds errors ever get fixed?  I am running into one of them.  I
am building QEMU in an environment where 'fdopendir' is not present.
'fdopendir' was introduced in POSIX 2008 (and The Open Group Technical
Standard, 2006, Extended API Set Part 2.), so it may not be available in some
environments where QEMU is built.

[1] http://lists.nongnu.org/archive/html/qemu-devel/2011-12/msg00171.html

-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



Re: [Qemu-devel] [RFC] Next gen kvm api

2012-02-03 Thread Anthony Liguori

On 02/03/2012 12:07 PM, Eric Northup wrote:

On Thu, Feb 2, 2012 at 8:09 AM, Avi Kivity  wrote:
[...]


Moving to syscalls avoids these problems, but introduces new ones:

- adding new syscalls is generally frowned upon, and kvm will need several
- syscalls into modules are harder and rarer than into core kernel code
- will need to add a vcpu pointer to task_struct, and a kvm pointer to
mm_struct

- Lost a good place to put access control (permissions on /dev/kvm)
for which user-mode processes can use KVM.

How would the ability to use sys_kvm_* be regulated?


Why should it be regulated?

It's not a finite or privileged resource.

Regards,

Anthony Liguori








Re: [Qemu-devel] libqemu for use in parallel-language based simulator

2012-02-03 Thread 陳韋任
Hi, Sean

> libqemu appears to be the heart of what we 
> need.  Just the core functionality of a 
> processor's instruction-set.  We will need a few 
> thousand or so separate processor-states, similar 
> to how COREMU has multiple processor states.

  libqemu is gone. Maybe you can try libcpu [1] instead?

Regards,
chenwj

[1] http://www.libcpu.org/wiki/Main_Page

-- 
Wei-Ren Chen (陳韋任)
Computer Systems Lab, Institute of Information Science,
Academia Sinica, Taiwan (R.O.C.)
Tel:886-2-2788-3799 #1667
Homepage: http://people.cs.nctu.edu.tw/~chenwj



[Qemu-devel] buildbot failure in qemu on default_i386_rhel61

2012-02-03 Thread qemu
The Buildbot has detected a new failure on builder default_i386_rhel61 while 
building qemu.
Full details are available at:
 http://buildbot.b1-systems.de/qemu/builders/default_i386_rhel61/builds/166

Buildbot URL: http://buildbot.b1-systems.de/qemu/

Buildslave for this Build: kraxel_rhel61_32bit

Build Reason: The Nightly scheduler named 'nightly_default' triggered this build
Build Source Stamp: [branch master] HEAD
Blamelist: 

BUILD FAILED: failed compile

sincerely,
 -The Buildbot



  1   2   >