[Qemu-devel] [PATCH v2 3/6] trace: Add trace events group implementation in the backend "simple"

2011-10-19 Thread Mark Wu

Signed-off-by: Mark Wu 
---
 trace/simple.c |   30 ++
 trace/simple.h |7 +++
 2 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/trace/simple.c b/trace/simple.c
index b639dda..05acee0 100644
--- a/trace/simple.c
+++ b/trace/simple.c
@@ -321,6 +321,16 @@ void trace_print_events(FILE *stream, fprintf_function 
stream_printf)
 }
 }
 
+void trace_print_groups(FILE *stream, fprintf_function stream_printf)
+{
+unsigned int i;
+
+for (i = 0; i < NR_TRACE_EVENT_GROUPS; i++) {
+stream_printf(stream, "%s [GROUP ID %u] : state %u\n",
+  trace_group_list[i].gp_name, i,
+  trace_group_list[i].state);
+}
+}
 bool trace_event_set_state(const char *name, bool state)
 {
 unsigned int i;
@@ -334,6 +344,26 @@ bool trace_event_set_state(const char *name, bool state)
 return false;
 }
 
+bool trace_event_group_set_state(const char *gp_name, bool state)
+{
+unsigned int i;
+unsigned int j;
+TraceEventGroup *group;
+
+for (i = 0; i < NR_TRACE_EVENT_GROUPS; i++) {
+group = &trace_group_list[i];
+if (!strcmp(group->gp_name, gp_name)) {
+group->state = state;
+
+for (j = group->start; j <= group->end; j++) {
+trace_list[j].state = state;
+}
+return true;
+}
+}
+return false;
+}
+
 /* Helper function to create a thread with signals blocked.  Use glib's
  * portable threads since QEMU abstractions cannot be used due to reentrancy in
  * the tracer.  Also note the signal masking on POSIX hosts so that the thread
diff --git a/trace/simple.h b/trace/simple.h
index 466e75b..cf119f3 100644
--- a/trace/simple.h
+++ b/trace/simple.h
@@ -22,6 +22,13 @@ typedef struct {
 bool state;
 } TraceEvent;
 
+typedef struct {
+const char *gp_name;
+bool state;
+int start;
+int end;
+} TraceEventGroup;
+
 void trace0(TraceEventID event);
 void trace1(TraceEventID event, uint64_t x1);
 void trace2(TraceEventID event, uint64_t x1, uint64_t x2);
-- 
1.7.1




[Qemu-devel] [PATCH v2 2/6] trace: Add HMP monitor commands for trace events group

2011-10-19 Thread Mark Wu
Add monitor commands 'trace-group NAME on|off' and 'info trace-groups'
to set and query the state of a given group of trace events.

Signed-off-by: Mark Wu 
---
 hmp-commands.hx |   14 ++
 monitor.c   |   22 ++
 trace/control.h |9 +
 trace/default.c |   15 +++
 4 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index ab08d58..251b84f 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -194,6 +194,20 @@ STEXI
 changes status of a trace event
 ETEXI
 
+{
+.name   = "trace-group",
+.args_type  = "name:s,option:b",
+.params = "name on|off",
+.help   = "changes status of a specific trace event",
+.mhandler.cmd = do_trace_event_group_set_state,
+},
+
+STEXI
+@item trace-group
+@findex trace-group
+changes status of a group of trace events
+ETEXI
+
 #if defined(CONFIG_TRACE_SIMPLE)
 {
 .name   = "trace-file",
diff --git a/monitor.c b/monitor.c
index ffda0fe..bedb011 100644
--- a/monitor.c
+++ b/monitor.c
@@ -617,6 +617,17 @@ static void do_trace_event_set_state(Monitor *mon, const 
QDict *qdict)
 }
 }
 
+static void do_trace_event_group_set_state(Monitor *mon, const QDict *qdict)
+{
+const char *gp_name = qdict_get_str(qdict, "name");
+bool new_state = qdict_get_bool(qdict, "option");
+int ret = trace_event_group_set_state(gp_name, new_state);
+
+if (!ret) {
+monitor_printf(mon, "unknown group name \"%s\"\n", gp_name);
+}
+}
+
 #ifdef CONFIG_TRACE_SIMPLE
 static void do_trace_file(Monitor *mon, const QDict *qdict)
 {
@@ -954,6 +965,10 @@ static void do_trace_print_events(Monitor *mon)
 trace_print_events((FILE *)mon, &monitor_fprintf);
 }
 
+static void do_trace_print_groups(Monitor *mon)
+{
+trace_print_groups((FILE *)mon, &monitor_fprintf);
+}
 #ifdef CONFIG_VNC
 static int change_vnc_password(const char *password)
 {
@@ -3050,6 +3065,13 @@ static const mon_cmd_t info_cmds[] = {
 .mhandler.info = do_trace_print_events,
 },
 {
+.name   = "trace-groups",
+.args_type  = "",
+.params = "",
+.help   = "show available trace-groups & their state",
+.mhandler.info = do_trace_print_groups,
+},
+{
 .name   = NULL,
 },
 };
diff --git a/trace/control.h b/trace/control.h
index 2acaa42..97ecce7 100644
--- a/trace/control.h
+++ b/trace/control.h
@@ -15,12 +15,21 @@
 
 /** Print the state of all events. */
 void trace_print_events(FILE *stream, fprintf_function stream_printf);
+
+/** Print the state of all groups. */
+void trace_print_groups(FILE *stream, fprintf_function stream_printf);
+
 /** Set the state of an event.
  *
  * @return Whether the state changed.
  */
 bool trace_event_set_state(const char *name, bool state);
 
+/** Set the state of a group of  events.
+ *
+ * @return Whether the state changed.
+ */
+bool trace_event_group_set_state(const char *name, bool state);
 
 /** Initialize the tracing backend.
  *
diff --git a/trace/default.c b/trace/default.c
index c9b27a2..c7e70c7 100644
--- a/trace/default.c
+++ b/trace/default.c
@@ -18,6 +18,14 @@ void trace_print_events(FILE *stream, fprintf_function 
stream_printf)
   "operation not supported with the current backend\n");
 }
 
+void trace_print_groups(FILE *stream, fprintf_function stream_printf)
+{
+fprintf(stderr, "warning: "
+"cannot print the trace groups with the current backend\n");
+stream_printf(stream, "error: "
+  "operation not supported with the current backend\n");
+}
+
 bool trace_event_set_state(const char *name, bool state)
 {
 fprintf(stderr, "warning: "
@@ -25,6 +33,13 @@ bool trace_event_set_state(const char *name, bool state)
 return false;
 }
 
+bool trace_event_group_set_state(const char *gp_name, bool state)
+{
+fprintf(stderr, "warning: "
+"cannot set the state of a trace group with the current 
backend\n");
+return false;
+}
+
 bool trace_backend_init(const char *events, const char *file)
 {
 if (events) {
-- 
1.7.1




[Qemu-devel] [PATCH v2 4/6] trace: Add trace events group implementation in the backend "stderr"

2011-10-19 Thread Mark Wu

Signed-off-by: Mark Wu 
---
 trace/stderr.c |   32 
 trace/stderr.h |7 +++
 2 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/trace/stderr.c b/trace/stderr.c
index 7107c4a..c55bed4 100644
--- a/trace/stderr.c
+++ b/trace/stderr.c
@@ -12,6 +12,17 @@ void trace_print_events(FILE *stream, fprintf_function 
stream_printf)
 }
 }
 
+void trace_print_groups(FILE *stream, fprintf_function stream_printf)
+{
+unsigned int i;
+
+for (i = 0; i < NR_TRACE_EVENT_GROUPS; i++) {
+stream_printf(stream, "%s [GROUP ID %u] : state %u\n",
+  trace_group_list[i].gp_name, i,
+  trace_group_list[i].state);
+}
+}
+
 bool trace_event_set_state(const char *name, bool state)
 {
 unsigned int i;
@@ -25,6 +36,27 @@ bool trace_event_set_state(const char *name, bool state)
 return false;
 }
 
+bool trace_event_group_set_state(const char *gp_name, bool state)
+{
+unsigned int i;
+unsigned int j;
+TraceEventGroup *group;
+
+for (i = 0; i < NR_TRACE_EVENT_GROUPS; i++) {
+
+group = &trace_group_list[i];
+if (!strcmp(group->gp_name, gp_name)) {
+group->state = state;
+
+for (j = group->start; j <= group->end; j++) {
+trace_list[j].state = state;
+}
+return true;
+}
+}
+return false;
+}
+
 bool trace_backend_init(const char *events, const char *file)
 {
 if (file) {
diff --git a/trace/stderr.h b/trace/stderr.h
index d575b61..45499f6 100644
--- a/trace/stderr.h
+++ b/trace/stderr.h
@@ -8,4 +8,11 @@ typedef struct {
 bool state;
 } TraceEvent;
 
+typedef struct {
+const char *gp_name;
+bool state;
+int start;
+int end;
+} TraceEventGroup;
+
 #endif /* ! TRACE_STDERR_H */
-- 
1.7.1




[Qemu-devel] [PATCH v2 5/6] trace: Enable "-trace events" argument to control initial state of groups

2011-10-19 Thread Mark Wu
A group of trace events can be enabled in early running stage through
adding its group name prefixed with "group:" to trace events list file
which is passed to "-trace events".

Signed-off-by: Mark Wu 
---
 trace/control.c |   17 +
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/trace/control.c b/trace/control.c
index 4c5527d..18e14a1 100644
--- a/trace/control.c
+++ b/trace/control.c
@@ -23,10 +23,27 @@ void trace_backend_init_events(const char *fname)
 exit(1);
 }
 char line_buf[1024];
+char *group;
+
 while (fgets(line_buf, sizeof(line_buf), fp)) {
 size_t len = strlen(line_buf);
 if (len > 1) {  /* skip empty lines */
 line_buf[len - 1] = '\0';
+group = strstr(line_buf, "group:");
+if (group != NULL) {
+group += strlen("group:");
+if (group == NULL) {
+fprintf(stderr, "error: empty group name\n");
+exit(1);
+}
+if (!trace_event_group_set_state(group, true)) {
+fprintf(stderr, "error: trace event group '%s'"
+"does not exist\n", group);
+exit(1);
+}
+continue;
+}
+
 if (!trace_event_set_state(line_buf, true)) {
 fprintf(stderr,
 "error: trace event '%s' does not exist\n", line_buf);
-- 
1.7.1




[Qemu-devel] [PATCH v2 0/6] trace: Add support for trace events grouping

2011-10-19 Thread Mark Wu
This series add support for trace events grouping. The state of a given group
of trace events can be queried or changed in bulk by the following monitor
commands:

* info trace-groups
   View available trace event groups and their state.  State 1 means enabled,
   state 0 means disabled.

* trace-group NAME on|off
   Enable/disable a given trace event group.

A group of trace events can also be enabled in early running stage through
adding its group name prefixed with "group:" to trace events list file
which is passed to "-trace events". 

Change from V1:
* fix coding style problems
* rebase against latest master 

Mark Wu (6):
  trace: Make "tracetool" generate a group list
  trace: Add HMP monitor commands for trace events group
  trace: Add trace events group implementation in the backend "simple"
  trace: Add trace events group implementation in the backend "stderr"
  trace: Enable "-trace events" argument to control initial state of   
 groups
  trace: Update doc for trace events group

 docs/tracing.txt  |   29 ++--
 hmp-commands.hx   |   14 
 monitor.c |   22 
 scripts/tracetool |   94 +++-
 trace-events  |   94 +
 trace/control.c   |   17 +
 trace/control.h   |9 +
 trace/default.c   |   15 
 trace/simple.c|   30 +
 trace/simple.h|7 
 trace/stderr.c|   32 ++
 trace/stderr.h|7 
 12 files changed, 365 insertions(+), 5 deletions(-)




[Qemu-devel] buildbot failure in qemu on s390-next_i386_debian_6_0

2011-10-19 Thread qemu
The Buildbot has detected a new failure on builder s390-next_i386_debian_6_0 
while building qemu.
Full details are available at:
 http://buildbot.b1-systems.de/qemu/builders/s390-next_i386_debian_6_0/builds/67

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

Buildslave for this Build: yuzuki

Build Reason: The Nightly scheduler named 'nightly_s390-next' triggered this 
build
Build Source Stamp: [branch s390-next] HEAD
Blamelist: 

BUILD FAILED: failed git

sincerely,
 -The Buildbot



[Qemu-devel] buildbot failure in qemu on s390-next_x86_64_debian_6_0

2011-10-19 Thread qemu
The Buildbot has detected a new failure on builder s390-next_x86_64_debian_6_0 
while building qemu.
Full details are available at:
 
http://buildbot.b1-systems.de/qemu/builders/s390-next_x86_64_debian_6_0/builds/66

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

Buildslave for this Build: yuzuki

Build Reason: The Nightly scheduler named 'nightly_s390-next' triggered this 
build
Build Source Stamp: [branch s390-next] HEAD
Blamelist: 

BUILD FAILED: failed git

sincerely,
 -The Buildbot



Re: [Qemu-devel] [PATCH 1/1] Introduce a new bus "ICC" to connect APIC

2011-10-19 Thread liu ping fan
On Wed, Oct 19, 2011 at 03:42:27PM +0200, Jan Kiszka wrote:
> On 2011-10-19 15:33, Jan Kiszka wrote:
> > On 2011-10-19 14:54, Anthony Liguori wrote:
> >> On 10/19/2011 05:53 AM, Jan Kiszka wrote:
> >>> On 2011-10-19 03:55, pingf...@linux.vnet.ibm.com wrote:
>  From: Liu Ping Fan
> 
>  Introduce a new structure CPUS as the controller of ICC (INTERRUPT
>  CONTROLLER COMMUNICATIONS), and new bus "ICC" to hold APIC,instead
>  of sysbus. So we can support APIC hot-plug feature.
> 
>  Signed-off-by: liu ping fan
>  ---
>    Makefile.target |1 +
>    hw/apic.c   |   25 +++
>    hw/apic.h   |1 +
>    hw/icc_bus.c|   91 
>  +++
>    hw/icc_bus.h|   56 ++
>    hw/pc.c |   11 --
>    6 files changed, 174 insertions(+), 11 deletions(-)
>    create mode 100644 hw/icc_bus.c
>    create mode 100644 hw/icc_bus.h
> 
>  diff --git a/Makefile.target b/Makefile.target
>  index 9011f28..5607c6d 100644
>  --- a/Makefile.target
>  +++ b/Makefile.target
>  @@ -241,6 +241,7 @@ obj-i386-$(CONFIG_KVM) += kvmclock.o
>    obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
>    obj-i386-y += testdev.o
>    obj-i386-y += acpi.o acpi_piix4.o
>  +obj-i386-y += icc_bus.o
> 
>    obj-i386-y += pcspk.o i8254.o
>    obj-i386-$(CONFIG_KVM_PIT) += i8254-kvm.o
>  diff --git a/hw/apic.c b/hw/apic.c
>  index 69d6ac5..00d2297 100644
>  --- a/hw/apic.c
>  +++ b/hw/apic.c
>  @@ -21,9 +21,10 @@
>    #include "ioapic.h"
>    #include "qemu-timer.h"
>    #include "host-utils.h"
>  -#include "sysbus.h"
>  +#include "icc_bus.h"
>    #include "trace.h"
>    #include "kvm.h"
>  +#include "exec-memory.h"
> >>>
> >>> Mmh, don't your rather want memory.h?
> >>>
> 
>    /* APIC Local Vector Table */
>    #define APIC_LVT_TIMER   0
>  @@ -80,7 +81,7 @@
>    typedef struct APICState APICState;
> 
>    struct APICState {
>  -SysBusDevice busdev;
>  +ICCBusDevice busdev;
>    MemoryRegion io_memory;
>    void *cpu_env;
>    uint32_t apicbase;
>  @@ -1104,9 +1105,20 @@ static const MemoryRegionOps apic_io_ops = {
>    .endianness = DEVICE_NATIVE_ENDIAN,
>    };
> 
>  -static int apic_init1(SysBusDevice *dev)
>  +/**/
> >>>
> >>> Empty comment.
> >>>
>  +int apic_mmio_map(DeviceState *dev, target_phys_addr_t base)
>    {
>  -APICState *s = FROM_SYSBUS(APICState, dev);
>  +APICState *s = DO_UPCAST(APICState, busdev.qdev, dev);
>  +
>  +memory_region_add_subregion(get_system_memory(),
>  +base,
>  +&s->io_memory);
>  +return 0;
>  +}
>  +
>  +static int apic_init1(ICCBusDevice *dev)
>  +{
>  +APICState *s = DO_UPCAST(APICState, busdev, dev);
>    static int last_apic_idx;
> 
>    if (last_apic_idx>= MAX_APICS) {
>  @@ -1114,7 +1126,6 @@ static int apic_init1(SysBusDevice *dev)
>    }
>    memory_region_init_io(&s->io_memory,&apic_io_ops, s, "apic",
>  MSI_ADDR_SIZE);
>  -sysbus_init_mmio_region(dev,&s->io_memory);
> 
>    s->timer = qemu_new_timer_ns(vm_clock, apic_timer, s);
>    s->idx = last_apic_idx++;
>  @@ -1122,7 +1133,7 @@ static int apic_init1(SysBusDevice *dev)
>    return 0;
>    }
> 
>  -static SysBusDeviceInfo apic_info = {
>  +static ICCBusDeviceInfo apic_info = {
>    .init = apic_init1,
>    .qdev.name = "apic",
>    .qdev.size = sizeof(APICState),
>  @@ -1138,7 +1149,7 @@ static SysBusDeviceInfo apic_info = {
> 
>    static void apic_register_devices(void)
>    {
>  -sysbus_register_withprop(&apic_info);
>  +iccbus_register_devinfo(&apic_info);
>    }
> 
>    device_init(apic_register_devices)
>  diff --git a/hw/apic.h b/hw/apic.h
>  index c857d52..e2c0af5 100644
>  --- a/hw/apic.h
>  +++ b/hw/apic.h
>  @@ -20,6 +20,7 @@ void cpu_set_apic_tpr(DeviceState *s, uint8_t val);
>    uint8_t cpu_get_apic_tpr(DeviceState *s);
>    void apic_init_reset(DeviceState *s);
>    void apic_sipi(DeviceState *s);
>  +int apic_mmio_map(DeviceState *dev, target_phys_addr_t base);
> 
>    /* pc.c */
>    int cpu_is_bsp(CPUState *env);
>  diff --git a/hw/icc_bus.c b/hw/icc_bus.c
>  new file mode 100644
>  index 000..61a408e
>  --- /dev/null
>  +++ b/hw/icc_bus.c
>  @@ -0,0 +1,91 @@
>  +/* icc_bus.c
>  + * emulate x86 ICC(INTERRUPT CONTROLLER COMMUNICATIONS) bus
> >>>
> >>> Copyright?
> >>>
>  + *
>  + * This library is free software; you can redistribute it and/or
>  + * modi

Re: [Qemu-devel] gcc auto-omit-frame-pointer vs msvc longjmp

2011-10-19 Thread xunxun
Hi, all

I think this issue causes the gdb crash on XP.
You can see the thread: http://sourceware.org/ml/gdb/2011-10/msg00056.html

My many friends and I can reproduce this crash issue, but no problem on Win7.

On Thu, Oct 20, 2011 at 5:05 AM, Bob Breuer  wrote:
> Kai Tietz wrote:
>> 2011/10/18 Bob Breuer :
>>> Kai Tietz wrote:
 2011/10/17 Bob Breuer :
> Richard Henderson wrote:
>> On 10/17/2011 07:09 AM, Bob Breuer wrote:
>>> Google finds a mention of longjmp failing with -fomit-frame-pointer:
>>> http://lua-users.org/lists/lua-l/2005-02/msg00158.html
>>>
>>> Looks like gcc 4.6 turns on -fomit-frame-pointer by default.
>> Hmm.  This is the first I've heard of a longjmp implementation
>> failing without a frame pointer.  Presumably this is with the
>> mingw i.e. msvc libc?
> Yeah, mingw from www.mingw.org which I believe uses msvcrt.dll, package
> gcc-core-4.6.1-2-mingw32-bin.
>
>> This is something that could be worked around in gcc, I suppose.
>> We recognize longjmp for some things, we could force the use of
>> a frame pointer for msvc targets too.
>>
>> For now it might be best to simply force -fno-omit-frame-pointer
>> for mingw host in the configure script.
> Here's a testcase that crashes on the longjmp:
>
> #include 
> #include 
>
> jmp_buf env;
>
> int test(void)
> {
>  int i;
>
>  asm("xor %%ebp,%%ebp" ::: "ebp");
>
>  i = setjmp(env);
>  printf("i = %d\n", i);
>
>  if (i == 0)
>    longjmp(env, 2);
>
>  return i;
> }
>
> int main(void)
> {
>  return test();
> }
>
> Remove the asm statement to make it not crash.  Obviously with
> omit-frame-pointer, gcc can shove anything into ebp.
>
> Bob
 This crash isn'r related to ebp existing, or not. The issue is the
 hidden argument of setjmp, which is missing.  If you can try the
 following at top of file after include section.

 #define setjmp(BUF) _setjmpex((BUF), NULL)
 int __cdecl __attribute__ ((__nothrow__,__returns_twice__))
 _setjmp3(jmp_buf _Buf, void *_Ctx);
 ...
>>> Did you mean _setjmp3 instead of _setjmpex?  With _setjmp3, it works
>>> without the asm, but still crashes if I zero out ebp before the setjmp.
>>>  Aren't the function arguments on the stack anyway?
>>
>> Yes, I mean _setjmp3 (pasto from headers and missed the second line
>> prototyping _setjmp3).
>> I repeat myself here.  setjmp() has an hidden arguement, which is
>> passed on x86 on stack.  By not passing this required argument, setjmp
>> will take a random-value from stack.  In your case 'i'.  btw if you
>> would pre-initialize 'i' with zero, I would assume you won't see a
>> crash, but anyway this is just by chance.
>> For this I suggest to use here _setjmp3 instead, as here
>> second-argument is documented as being present.
>>
>> Btw I tested your code with i686-pc-mingw32 version 4.6.x and 4.7.x
>> gcc version.  With my suggested pattern, I don't see a crash for your
>> provide test-code with, or without zero-ing ebp.
>
>
> We probably have a difference in build or run environment.  I've
> double-checked with another machine and can get the same crash in
> longjmp when running the test executable on both WinXP and Win2k, but
> not on Win7.  So it looks like Microsoft may have changed this "feature"
> somewhere between WinXP and Win7.
>
> The msvcrt implementation of longjmp (or at least the one I'm looking
> at) does a ebp based access using the saved value of ebp.  Here's the
> relevant disassembly of longjmp:
>
> 0x7801e6f3 in longjmpex () from C:\WINNT\system32\msvcrt.dll
> (gdb) disas
> Dump of assembler code for function longjmpex:
>   0x7801e6ef <+0>:     mov    0x4(%esp),%ebx
> => 0x7801e6f3 <+4>:     mov    (%ebx),%ebp
> ...
>   0x7801e73d <+78>:    call   0x7800bd5e 
> ...
>   0x7800bd5e <+56>:    push   %ebx
>   0x7800bd5f <+57>:    push   %ecx
>   0x7800bd60 <+58>:    mov    $0x7803dc64,%ebx
> => 0x7800bd65 <+63>:    mov    0x8(%ebp),%ecx
>
> It crashes on the access of 0x8(%ebp).  Those are the only 2 places
> where this version of longjmp touches ebp.  Is it possible to force a
> stackframe by just adding a suitable attribute to either the setjmp
> function prototype, or the function which calls setjmp?
>
> Bob
>



-- 
Best Regards,
xunxun



Re: [Qemu-devel] [PATCH 1/9] Add stub functions for PCI device models to do PCI DMA

2011-10-19 Thread David Gibson
On Wed, Oct 19, 2011 at 11:10:15AM +0200, Avi Kivity wrote:
> On 10/18/2011 03:46 AM, David Gibson wrote:
> > On Sun, Oct 16, 2011 at 03:15:53PM +0200, Avi Kivity wrote:
> > > On 10/14/2011 04:14 AM, David Gibson wrote:
> > > > > Virtio is a very, very special case.  virtio requires coherent RAM 
> > > > > access.
> > > >
> > > > Right.  Virtio's access to memory is *not* emulated PCI DMA, it's
> > > > god-like hypervisor access to guest system memory.  It should
> > > > correctly bypass any IOMMU, and so should remain as
> > > > cpu_physical_memory_rw() or the atomic accessors, rather than being
> > > > converted to this new API.
> > > 
> > > virtio should definitely not bypass an iommu.
> >
> > So, I just had a chat with Rusty about this.  Perhaps it shouldn't,
> > but it does.  The spec is in terms of guest physical addresses, not
> > bus/DMA addresses, and more to the point the Linux driver does *not*
> > do the necessary dma_map() and unmap operations to treat this as a PCI
> > DMA.  So like it or not, god-like hypervisor access rather than
> > emulated PCI DMA is what it does.
> 
> Wow, how did we manage to break virtio in so many different ways?
> 
> Is there a way to unbreak it?

Yes, using a feature bit.

>  On x86 it will continue to work if we
> rewrite the spec in terms of pci dma, what about non-x86?

No, anything with a non-optional IOMMU will break horribly.  That's
why we need a feature bit.

> > >  A guest may assign a
> > > virtio device to nested guests, and would wish it confined by the
> > > emulated iommu.
> >
> > Well, that would be nice, but it can't be done.  It could be fixed,
> > but it would be an incompatible change so it would need a new feature
> > bit corresponding changes in the Linux driver to do the dma map/unmap
> > if it accepts the "respect IOMMU" feature.
> 
> Needs to be done IMO.

Well, sure, but my point is that I'm not volunteering for it.  Someone
who actually needs the feature can do the work.

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson




Re: [Qemu-devel] [Question] dump memory when host pci device is used by guest

2011-10-19 Thread Wen Congyang
At 10/19/2011 07:40 PM, Jan Kiszka Write:
> On 2011-10-19 04:04, KAMEZAWA Hiroyuki wrote:
>> On Tue, 18 Oct 2011 10:31:10 +0200
>> Jan Kiszka  wrote:
>>
>>> On 2011-10-18 10:31, Wen Congyang wrote:
 At 10/18/2011 04:26 PM, Jan Kiszka Write:
> On 2011-10-18 10:25, Wen Congyang wrote:
>> At 10/18/2011 04:19 PM, Jan Kiszka Write:
>>> On 2011-10-18 09:58, Wen Congyang wrote:
 At 10/18/2011 03:52 PM, Jan Kiszka Write:
> On 2011-10-18 09:15, Wen Congyang wrote:
>> Hi, Jan Kiszka
>>
>> At 10/10/2011 05:34 PM, Jan Kiszka Write:
>>> On 2011-10-10 11:02, Daniel P. Berrange wrote:
 On Mon, Oct 10, 2011 at 08:52:08AM +0200, Jan Kiszka wrote:
>>
>>>
>>> Run gdb with "set debug remote 1" and watch the communication, it 
>>> is not
>>> that complex. But a dump command is probably simpler for those
>>> scenarios, I agree.
>>
>> I have implemented the command dump and reuse migration's code. But 
>> I meet a problem
>> when I test it.
>
> Using migration code for dump is most probably the wrong approach as 
> you
> saw through that conflict. All you need are the register states and 
> the
> RAM. Reuse gdbstub services for this.

 Hmm, if the migration code can not be reused, I think we should define 
 a new
 qemu's vmcore format, and add some codes into crash to support such 
 format.
>>>
>>> Please try to avoid defining something new. Unless there is a striking
>>> reason, standard gdb core files should be generated so that you can load
>>> the dump directly into gdb for analysis.
>>
>> I am not sure whehter the standard gdb core files can not be analyzed by 
>> crash.
>> If not, I think we should define something new because it's easier to use
>> crash than gdb to analyze the core files.
>
> gdb allows you to walk up the frame and print variables (globals &
> local) etc.

 Crash uses gdb to provide common function, and you can also use all the 
 gdb commands
 in crash.
>>>
>>> That what's the added value here when I can use gdb directly?
>>>
>>
>> I didn't read full story but 'crash' is used for investigating kernel core 
>> generated
>> by kdump for several years. Considering support service guys, virsh dump 
>> should support
>> a format for crash because they can't work well at investigating vmcore by 
>> gdb.
>>
>> crash has several functionality useful for them as 'show kerne log', 'focus 
>> on a cpu'
>> 'for-each-task', 'for-each-vma', 'extract ftrace log' etc.
>>
>> Anyway, if a man, who is not developper of qemu/kvm, should learn 2 tools for
>> investigating kernel dump, it sounds harmful.
> 
> Right, that's why everything (live debugging & crash analysis) should be
> consolidated on the long run over gdb. crash is architecturally obsolete
> today - not saying it is useless!

I do not know why crash is obsoleted today. Is there a new better tool to 
instead
crash?

At least, I always use crash to live debugging & crash analysis.

Thanks
Wen Congyang

> 
> Jan
> 




Re: [Qemu-devel] [PATCH] Add linux-headers/asm to .gitignore

2011-10-19 Thread Juan Quintela
David Gibson  wrote:
> linux-headers/asm is a symlink generated during configure.  It should not,
> therefore be committed to git, nor show up in git diffs and the like.
>
> Signed-off-by: David Gibson 

Reviewed-by: Juan Quintela 



[Qemu-devel] [PATCH v5 00/37] Migration errors & cleanup (the integrated version)

2011-10-19 Thread Juan Quintela
Hi

v5:
- addressed review comments:
  * Amit
- move "return real error code" after has_error has got a negative value
  (i.e. from patch 3 to patch 11)
  * Kevin
- return -errno, no errno.
  * Orit
- return errno instead of EINVAL
- once there, introduce some comments (more needed)
- Make sure that *save_live() return negative on error, and adjust all callers.
- make migration_state enum anonymous (Anthony)


v4:

- rebase on top of new qemu and new migration-errors series
- integrate back erros & cleanup series
- s/MIG_STATE_NONE/MIG_STATE_SETUP/ (Orit suggestion)
- s/migrate_create_state/migrate_new/ (Anthony suggestion)
- Add migrate_get_current() accessor.
- make has_error contain the errno instead of a bool
- rename qemu_file_has_error() -> qemu_file_get_error()
- rename has_error field into last_error
- migration_state_notifiers now pass MigrationState pointer


v3:
this patch applies on top of my previous "migration error"
patches.  All error handling has been moved to that series,
except for "propagate error correctly", without this
refactoring, it is quite complicated to apply it.

Please, review.

Later, Juan.

v3:
- more checkpatch.pl happines
- split error handling in a previous series
- make Anthony happy.  current_migration is still a pointer, but points to
  a static variable.  We can change current_migration when we integrate
  kemari.

v2:
- make Jan^Wcheckpatch.pl happy
- Yoshiaki Tamura suggestions:
  - include its two patches to clean things
  - MAX_THROTTLE define
  - migration_state enum
- I removed spurious differences between migration-{tcp,unix}
- better error propagation, after this patch:
   migrate -d "tcp:name_don_exist:port"
   migrate -d "tcp:name:port_dont_exist"
   migrate -d "exec: prog_dont_exist"
   migrate -d "exec: gzip > /path/dont/exist"
 fail as expected.  Last two used to enter an infinite loop.

The fixes part should be backported to 0.14, waiting for the review to do that.

Later, Juan.

v1:
This series:
- Fold MigrationState into FdMigrationState (and then rename)
- Factorize migration statec creation in a single place
- Make use of MIG_STATE_*, setup through helpers and make them local
- remove relase & cancel callbacks (where used only one in same
  file than defined)
- get_status() is no more, just access directly to .state
- current_migration use cleanup, and make variable static
- max_throotle is gone, now inside current_migration
- change get_migration_status() to migration_has_finished()
  and actualize single user.

Please review.

Later, Juan.



Juan Quintela (36):
  ds1225y: Use stdio instead of QEMUFile
  migration: simplify state assignmente
  migration: Check that migration is active before cancel it
  migration: If there is one error, it makes no sense to continue
  buffered_file: Use right "opaque"
  buffered_file: reuse QEMUFile has_error field
  migration: don't "write" when migration is not active
  migration: set error if select return one error
  migration: change has_error to contain errno values
  migration: return real error code
  migration: rename qemu_file_has_error to qemu_file_get_error
  savevm: Rename has_error to last_error field
  migration: use qemu_file_get_error() return value when possible
  migration: make *save_live return errors
  migration: Make *start_outgoing_migration return FdMigrationState
  migration: Use FdMigrationState instead of MigrationState when
possible
  migration: Fold MigrationState into FdMigrationState
  migration: Rename FdMigrationState MigrationState
  migration: Refactor MigrationState creation
  migration: Make all posible migration functions static
  migration: move migrate_new to do_migrate
  migration: Introduce MIG_STATE_SETUP
  migration: Refactor and simplify error checking in
migrate_fd_put_ready
  migration: Introduce migrate_fd_completed() for consistency
  migration: Our release callback was just free
  migration: Remove get_status() accessor
  migration: Remove migration cancel() callback
  migration: Move exported functions to the end of the file
  migration: create accessor for current_migration
  migration: Use bandwidth_limit directly
  migration: Pass MigrationState in migration notifiers
  migration: Export a function that tells if the migration has finished
correctly
  migration: Make state definitions local
  migration: Don't use callback on file defining it
  migration: propagate error correctly
  migration: make migration-{tcp,unix} consistent

Yoshiaki Tamura (1):
  migration: add error handling to migrate_fd_put_notify().

 arch_init.c   |   17 ++-
 block-migration.c |   35 +++--
 buffered_file.c   |   44 --
 hw/ds1225y.c  |   28 ++--
 hw/hw.h   |4 +-
 migration-exec.c  |   39 +
 migration-fd.c|   42 +
 migration-tcp.c   |   76 --
 migration-unix.c  |  113 ++-
 migration.c   |  439 +++--
 migration.h   |  

[Qemu-devel] [PATCH 10/37] migration: change has_error to contain errno values

2011-10-19 Thread Juan Quintela
We normally already have an errno value.  When not, abuse EIO.

Signed-off-by: Juan Quintela 
---
 arch_init.c   |2 +-
 block-migration.c |   11 ++-
 buffered_file.c   |4 ++--
 hw/hw.h   |2 +-
 migration.c   |2 +-
 savevm.c  |8 
 6 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index a6c69c7..941d585 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -263,7 +263,7 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, 
void *opaque)
 }

 if (cpu_physical_sync_dirty_bitmap(0, TARGET_PHYS_ADDR_MAX) != 0) {
-qemu_file_set_error(f);
+qemu_file_set_error(f, -EINVAL);
 return 0;
 }

diff --git a/block-migration.c b/block-migration.c
index e2775ee..325c905 100644
--- a/block-migration.c
+++ b/block-migration.c
@@ -263,7 +263,7 @@ static int mig_save_device_bulk(Monitor *mon, QEMUFile *f,

 error:
 monitor_printf(mon, "Error reading sector %" PRId64 "\n", cur_sector);
-qemu_file_set_error(f);
+qemu_file_set_error(f, -EIO);
 g_free(blk->buf);
 g_free(blk);
 return 0;
@@ -383,6 +383,7 @@ static int mig_save_device_dirty(Monitor *mon, QEMUFile *f,
 int64_t total_sectors = bmds->total_sectors;
 int64_t sector;
 int nr_sectors;
+int ret = -EIO;

 for (sector = bmds->cur_dirty; sector < bmds->total_sectors;) {
 if (bmds_aio_inflight(bmds, sector)) {
@@ -418,8 +419,8 @@ static int mig_save_device_dirty(Monitor *mon, QEMUFile *f,
 block_mig_state.submitted++;
 bmds_set_aio_inflight(bmds, sector, nr_sectors, 1);
 } else {
-if (bdrv_read(bmds->bs, sector, blk->buf,
-  nr_sectors) < 0) {
+ret = bdrv_read(bmds->bs, sector, blk->buf, nr_sectors);
+if (ret < 0) {
 goto error;
 }
 blk_send(f, blk);
@@ -439,7 +440,7 @@ static int mig_save_device_dirty(Monitor *mon, QEMUFile *f,

 error:
 monitor_printf(mon, "Error reading sector %" PRId64 "\n", sector);
-qemu_file_set_error(f);
+qemu_file_set_error(f, ret);
 g_free(blk->buf);
 g_free(blk);
 return 0;
@@ -473,7 +474,7 @@ static void flush_blks(QEMUFile* f)
 break;
 }
 if (blk->ret < 0) {
-qemu_file_set_error(f);
+qemu_file_set_error(f, blk->ret);
 break;
 }
 blk_send(f, blk);
diff --git a/buffered_file.c b/buffered_file.c
index 4f49763..94ca8d1 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -92,7 +92,7 @@ static void buffered_flush(QEMUFileBuffered *s)

 if (ret <= 0) {
 DPRINTF("error flushing data, %zd\n", ret);
-qemu_file_set_error(s->file);
+qemu_file_set_error(s->file, ret);
 break;
 } else {
 DPRINTF("flushed %zd byte(s)\n", ret);
@@ -138,7 +138,7 @@ static int buffered_put_buffer(void *opaque, const uint8_t 
*buf, int64_t pos, in

 if (ret <= 0) {
 DPRINTF("error putting\n");
-qemu_file_set_error(s->file);
+qemu_file_set_error(s->file, ret);
 offset = -EINVAL;
 break;
 }
diff --git a/hw/hw.h b/hw/hw.h
index a124da9..6cf8cd2 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -86,7 +86,7 @@ int qemu_file_rate_limit(QEMUFile *f);
 int64_t qemu_file_set_rate_limit(QEMUFile *f, int64_t new_rate);
 int64_t qemu_file_get_rate_limit(QEMUFile *f);
 int qemu_file_has_error(QEMUFile *f);
-void qemu_file_set_error(QEMUFile *f);
+void qemu_file_set_error(QEMUFile *f, int error);

 /* Try to send any outstanding data.  This function is useful when output is
  * halted due to rate limiting or EAGAIN errors occur as it can be used to
diff --git a/migration.c b/migration.c
index a682168..d5876a9 100644
--- a/migration.c
+++ b/migration.c
@@ -455,7 +455,7 @@ void migrate_fd_wait_for_unfreeze(void *opaque)
 } while (ret == -1 && (s->get_error(s)) == EINTR);

 if (ret == -1) {
-qemu_file_set_error(s->file);
+qemu_file_set_error(s->file, -s->get_error(s));
 }
 }

diff --git a/savevm.c b/savevm.c
index bf4d0e7..8f00f0c 100644
--- a/savevm.c
+++ b/savevm.c
@@ -430,9 +430,9 @@ int qemu_file_has_error(QEMUFile *f)
 return f->has_error;
 }

-void qemu_file_set_error(QEMUFile *f)
+void qemu_file_set_error(QEMUFile *f, int ret)
 {
-f->has_error = 1;
+f->has_error = ret;
 }

 void qemu_fflush(QEMUFile *f)
@@ -447,7 +447,7 @@ void qemu_fflush(QEMUFile *f)
 if (len > 0)
 f->buf_offset += f->buf_index;
 else
-f->has_error = 1;
+f->has_error = -EINVAL;
 f->buf_index = 0;
 }
 }
@@ -468,7 +468,7 @@ static void qemu_fill_buffer(QEMUFile *f)
 f->buf_size = len;
 f->buf_offset += len;
 } else if (len != -EAGAIN)
-f->has_error = 1;
+f->has_error = len;
 }

 int qemu_fclose(QE

[Qemu-devel] [PATCH] Add linux-headers/asm to .gitignore

2011-10-19 Thread David Gibson
linux-headers/asm is a symlink generated during configure.  It should not,
therefore be committed to git, nor show up in git diffs and the like.

Signed-off-by: David Gibson 
---
 .gitignore |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore
index 59c343c..6d2acab 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,6 +15,7 @@ libdis*
 libhw32
 libhw64
 libuser
+linux-headers/asm
 qapi-generated
 qemu-doc.html
 qemu-tech.html
-- 
1.7.6.3




[Qemu-devel] [PATCH 23/37] migration: Introduce MIG_STATE_SETUP

2011-10-19 Thread Juan Quintela
Use MIG_STATE_ACTIVE only when migration has really started.  Use this
new state to setup migration parameters.  Change defines for an
anonymous struct.

Signed-off-by: Juan Quintela 
---
 migration.c |6 +-
 migration.h |   11 +++
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/migration.c b/migration.c
index ca038ec..281fbae 100644
--- a/migration.c
+++ b/migration.c
@@ -239,6 +239,9 @@ void do_info_migrate(Monitor *mon, QObject **ret_data)
 MigrationState *s = current_migration;

 switch (s->get_status(current_migration)) {
+case MIG_STATE_SETUP:
+/* no migration has happened ever */
+break;
 case MIG_STATE_ACTIVE:
 qdict = qdict_new();
 qdict_put(qdict, "status", qstring_from_str("active"));
@@ -478,6 +481,7 @@ void migrate_fd_connect(MigrationState *s)
 {
 int ret;

+s->state = MIG_STATE_ACTIVE;
 s->file = qemu_fopen_ops_buffered(s,
   s->bandwidth_limit,
   migrate_fd_put_buffer,
@@ -507,7 +511,7 @@ static MigrationState *migrate_new(Monitor *mon, int64_t 
bandwidth_limit,
 s->shared = inc;
 s->mon = NULL;
 s->bandwidth_limit = bandwidth_limit;
-s->state = MIG_STATE_ACTIVE;
+s->state = MIG_STATE_SETUP;

 if (!detach) {
 migrate_fd_monitor_suspend(s, mon);
diff --git a/migration.h b/migration.h
index 14c3ebc..fed1cf1 100644
--- a/migration.h
+++ b/migration.h
@@ -18,10 +18,13 @@
 #include "qemu-common.h"
 #include "notify.h"

-#define MIG_STATE_ERROR-1
-#define MIG_STATE_COMPLETED0
-#define MIG_STATE_CANCELLED1
-#define MIG_STATE_ACTIVE   2
+enum {
+MIG_STATE_ERROR,
+MIG_STATE_SETUP,
+MIG_STATE_CANCELLED,
+MIG_STATE_ACTIVE,
+MIG_STATE_COMPLETED,
+};

 typedef struct MigrationState MigrationState;

-- 
1.7.6.4




[Qemu-devel] [PATCH 14/37] migration: use qemu_file_get_error() return value when possible

2011-10-19 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 arch_init.c   |6 --
 block-migration.c |7 ---
 buffered_file.c   |   23 ++-
 savevm.c  |4 ++--
 4 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 9128be0..98daaf3 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -371,6 +371,7 @@ int ram_load(QEMUFile *f, void *opaque, int version_id)
 {
 ram_addr_t addr;
 int flags;
+int error;

 if (version_id < 3 || version_id > 4) {
 return -EINVAL;
@@ -451,8 +452,9 @@ int ram_load(QEMUFile *f, void *opaque, int version_id)

 qemu_get_buffer(f, host, TARGET_PAGE_SIZE);
 }
-if (qemu_file_get_error(f)) {
-return -EIO;
+error = qemu_file_get_error(f);
+if (error) {
+return error;
 }
 } while (!(flags & RAM_SAVE_FLAG_EOS));

diff --git a/block-migration.c b/block-migration.c
index 56907a6..b8d19a1 100644
--- a/block-migration.c
+++ b/block-migration.c
@@ -647,6 +647,7 @@ static int block_load(QEMUFile *f, void *opaque, int 
version_id)
 uint8_t *buf;
 int64_t total_sectors = 0;
 int nr_sectors;
+int ret;

 do {
 addr = qemu_get_be64(f);
@@ -655,7 +656,6 @@ static int block_load(QEMUFile *f, void *opaque, int 
version_id)
 addr >>= BDRV_SECTOR_BITS;

 if (flags & BLK_MIG_FLAG_DEVICE_BLOCK) {
-int ret;
 /* get device name */
 len = qemu_get_byte(f);
 qemu_get_buffer(f, (uint8_t *)device_name, len);
@@ -705,8 +705,9 @@ static int block_load(QEMUFile *f, void *opaque, int 
version_id)
 fprintf(stderr, "Unknown flags\n");
 return -EINVAL;
 }
-if (qemu_file_get_error(f)) {
-return -EIO;
+ret = qemu_file_get_error(f);
+if (ret != 0) {
+return ret;
 }
 } while (!(flags & BLK_MIG_FLAG_EOS));

diff --git a/buffered_file.c b/buffered_file.c
index 41c659c..fed9a22 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -71,9 +71,11 @@ static void buffered_append(QEMUFileBuffered *s,
 static void buffered_flush(QEMUFileBuffered *s)
 {
 size_t offset = 0;
+int error;

-if (qemu_file_get_error(s->file)) {
-DPRINTF("flush when error, bailing\n");
+error = qemu_file_get_error(s->file);
+if (error != 0) {
+DPRINTF("flush when error, bailing: %s\n", strerror(-error));
 return;
 }

@@ -108,14 +110,15 @@ static void buffered_flush(QEMUFileBuffered *s)
 static int buffered_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, 
int size)
 {
 QEMUFileBuffered *s = opaque;
-int offset = 0;
+int offset = 0, error;
 ssize_t ret;

 DPRINTF("putting %d bytes at %" PRId64 "\n", size, pos);

-if (qemu_file_get_error(s->file)) {
-DPRINTF("flush when error, bailing\n");
-return -EINVAL;
+error = qemu_file_get_error(s->file);
+if (error) {
+DPRINTF("flush when error, bailing: %s\n", strerror(-error));
+return error;
 }

 DPRINTF("unfreezing output\n");
@@ -192,14 +195,16 @@ static int buffered_close(void *opaque)
  * The meaning of the return values is:
  *   0: We can continue sending
  *   1: Time to stop
- *  -1: There has been an error
+ *   negative: There has been an error
  */
 static int buffered_rate_limit(void *opaque)
 {
 QEMUFileBuffered *s = opaque;
+int ret;

-if (qemu_file_get_error(s->file)) {
-return -1;
+ret = qemu_file_get_error(s->file);
+if (ret) {
+return ret;
 }
 if (s->freeze_output)
 return 1;
diff --git a/savevm.c b/savevm.c
index b7a61c5..f27f474 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1841,8 +1841,8 @@ out:
 g_free(le);
 }

-if (qemu_file_get_error(f)) {
-ret = -EIO;
+if (ret == 0) {
+ret = qemu_file_get_error(f);
 }

 return ret;
-- 
1.7.6.4




[Qemu-devel] [PATCH 15/37] migration: make *save_live return errors

2011-10-19 Thread Juan Quintela
Make *save_live() return negative values when there is one error, and
updates all callers to check for the error.

Signed-off-by: Juan Quintela 
---
 arch_init.c   |9 +++--
 block-migration.c |   17 +++--
 savevm.c  |   14 +++---
 3 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 98daaf3..a411fdf 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -256,6 +256,7 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, 
void *opaque)
 uint64_t bytes_transferred_last;
 double bwidth = 0;
 uint64_t expected_time = 0;
+int ret;

 if (stage < 0) {
 cpu_physical_memory_set_dirty_tracking(0);
@@ -264,7 +265,7 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, 
void *opaque)

 if (cpu_physical_sync_dirty_bitmap(0, TARGET_PHYS_ADDR_MAX) != 0) {
 qemu_file_set_error(f, -EINVAL);
-return 0;
+return -EINVAL;
 }

 if (stage == 1) {
@@ -300,7 +301,7 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, 
void *opaque)
 bytes_transferred_last = bytes_transferred;
 bwidth = qemu_get_clock_ns(rt_clock);

-while (!qemu_file_rate_limit(f)) {
+while ((ret = qemu_file_rate_limit(f)) == 0) {
 int bytes_sent;

 bytes_sent = ram_save_block(f);
@@ -310,6 +311,10 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, 
void *opaque)
 }
 }

+if (ret < 0) {
+return ret;
+}
+
 bwidth = qemu_get_clock_ns(rt_clock) - bwidth;
 bwidth = (bytes_transferred - bytes_transferred_last) / bwidth;

diff --git a/block-migration.c b/block-migration.c
index b8d19a1..0bff075 100644
--- a/block-migration.c
+++ b/block-migration.c
@@ -557,6 +557,8 @@ static void blk_mig_cleanup(Monitor *mon)

 static int block_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
 {
+int ret;
+
 DPRINTF("Enter save live stage %d submitted %d transferred %d\n",
 stage, block_mig_state.submitted, block_mig_state.transferred);

@@ -580,9 +582,10 @@ static int block_save_live(Monitor *mon, QEMUFile *f, int 
stage, void *opaque)

 flush_blks(f);

-if (qemu_file_get_error(f)) {
+ret = qemu_file_get_error(f);
+if (ret) {
 blk_mig_cleanup(mon);
-return 0;
+return ret;
 }

 blk_mig_reset_dirty_cursor();
@@ -608,9 +611,10 @@ static int block_save_live(Monitor *mon, QEMUFile *f, int 
stage, void *opaque)

 flush_blks(f);

-if (qemu_file_get_error(f)) {
+ret = qemu_file_get_error(f);
+if (ret) {
 blk_mig_cleanup(mon);
-return 0;
+return ret;
 }
 }

@@ -625,8 +629,9 @@ static int block_save_live(Monitor *mon, QEMUFile *f, int 
stage, void *opaque)
 /* report completion */
 qemu_put_be64(f, (100 << BDRV_SECTOR_BITS) | BLK_MIG_FLAG_PROGRESS);

-if (qemu_file_get_error(f)) {
-return 0;
+ret = qemu_file_get_error(f);
+if (ret) {
+return ret;
 }

 monitor_printf(mon, "Block migration completed\n");
diff --git a/savevm.c b/savevm.c
index f27f474..9a5a369 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1496,7 +1496,11 @@ int qemu_savevm_state_begin(Monitor *mon, QEMUFile *f, 
int blk_enable,
 qemu_put_be32(f, se->instance_id);
 qemu_put_be32(f, se->version_id);

-se->save_live_state(mon, f, QEMU_VM_SECTION_START, se->opaque);
+ret = se->save_live_state(mon, f, QEMU_VM_SECTION_START, se->opaque);
+if (ret < 0) {
+qemu_savevm_state_cancel(mon, f);
+return ret;
+}
 }
 ret = qemu_file_get_error(f);
 if (ret != 0) {
@@ -1527,7 +1531,7 @@ int qemu_savevm_state_iterate(Monitor *mon, QEMUFile *f)
 qemu_put_be32(f, se->section_id);

 ret = se->save_live_state(mon, f, QEMU_VM_SECTION_PART, se->opaque);
-if (!ret) {
+if (ret <= 0) {
 /* Do not proceed to the next vmstate before this one reported
completion of the current stage. This serializes the migration
and reduces the probability that a faster changing state is
@@ -1548,6 +1552,7 @@ int qemu_savevm_state_iterate(Monitor *mon, QEMUFile *f)
 int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f)
 {
 SaveStateEntry *se;
+int ret;

 cpu_synchronize_all_states();

@@ -1559,7 +1564,10 @@ int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f)
 qemu_put_byte(f, QEMU_VM_SECTION_END);
 qemu_put_be32(f, se->section_id);

-se->save_live_state(mon, f, QEMU_VM_SECTION_END, se->opaque);
+ret = se->save_live_state(mon, f, QEMU_VM_SECTION_END, se->opaque);
+if (ret < 0) {
+return ret;
+}
 }

 QTAILQ_FOREACH(se, &savevm_handlers, entry) {
-- 
1.7.6.4




[Qemu-devel] [PATCH 05/37] migration: If there is one error, it makes no sense to continue

2011-10-19 Thread Juan Quintela
Once there, add a comment about what each error mean.

Signed-off-by: Juan Quintela 
---
 buffered_file.c |   12 +---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/buffered_file.c b/buffered_file.c
index 486af57..94ecbbc 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -189,13 +189,19 @@ static int buffered_close(void *opaque)
 return ret;
 }

+/*
+ * The meaning of the return values is:
+ *   0: We can continue sending
+ *   1: Time to stop
+ *  -1: There has been an error
+ */
 static int buffered_rate_limit(void *opaque)
 {
 QEMUFileBuffered *s = opaque;

-if (s->has_error)
-return 0;
-
+if (s->has_error) {
+return -1;
+}
 if (s->freeze_output)
 return 1;

-- 
1.7.6.4




[Qemu-devel] Can qemu emulate IBM Power env?

2011-10-19 Thread Ryan Wang
If it can, where can I find the related instructions?

thanks,


[Qemu-devel] KVM VMenter/exit cost

2011-10-19 Thread Xin Tong
Currently, when amd svm or intel vmx is used to run the guest os natively on
the chip, a kernel enter and vmenter are needed, and when the guest os
executes a trapping instruction, a vmexit and kernel exit is incurred. I
would like to know the latest estimate of the cost of VMEnter/VMExit on the
Intel or AMD x86 chip and kernel enter/exit on 2.6.x linux.  Any paper or
presentation on it would be great.


Thanks


Xin


Re: [Qemu-devel] [PATCH] libcacard: Fix wrong assertion (reported by cppcheck)

2011-10-19 Thread Alon Levy
On Wed, Oct 19, 2011 at 09:03:22PM +0200, Stefan Weil wrote:
> assert("...") will never do anything. This assertion handles a case
> which should never occur, so it must be assert(!"...").
> 

Thanks, I'll pick it up for a pull request.

> Cc: Alon Levy 
> Signed-off-by: Stefan Weil 
> ---
>  libcacard/card_7816.c |2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/libcacard/card_7816.c b/libcacard/card_7816.c
> index 9fd59d4..6fe27d5 100644
> --- a/libcacard/card_7816.c
> +++ b/libcacard/card_7816.c
> @@ -754,7 +754,7 @@ vcard_process_apdu(VCard *card, VCardAPDU *apdu, 
> VCardResponse **response)
>  return vcard7816_vm_process_apdu(card, apdu, response);
>  case VCARD_DIRECT:
>  /* if we are type direct, then the applet should handle everything */
> -assert("VCARD_DIRECT: applet failure");
> +assert(!"VCARD_DIRECT: applet failure");
>  break;
>  }
>  *response =
> -- 
> 1.7.2.5
> 



Re: [Qemu-devel] gcc auto-omit-frame-pointer vs msvc longjmp

2011-10-19 Thread Richard Henderson
On 10/19/2011 02:05 PM, Bob Breuer wrote:
> Is it possible to force a
> stackframe by just adding a suitable attribute to either the setjmp
> function prototype, or the function which calls setjmp?

The only thing I can think of that'll be portable to a large number
of versions of GCC is

  {
int n; char *p;
asm("" : "=r"(n) : "0"(1));
p = __builtin_alloca(n);
asm("" : : "r"(p));
  }

The first asm prevents constant propagation of the 1 to the alloca;
the second asm prevents the alloca from being considered dead code.


r~



[Qemu-devel] [Bug 739785] Re: qemu-i386 user mode on ARMv5 host fails (bash: fork: Invalid argument)

2011-10-19 Thread Peter Maydell
Steve: there are a number of issues with that patch:
 * x86 cpu_set_tls() doesn't belong in linux-user/syscall.c (but it's not 
trivial to put it in target-i386 because it's calling do_set_thread_area())
 * it's not "obviously correct" and the author says it needs review, and I'd 
have to dig out info about this obscure corner of the x86 ABI/architecture
 * I'm pretty sure it's not the only thing needed for threading support on x86, 
so (until/unless I look much more closely at the whole area) I don't have much 
confidence that this patch is a coherent single part of the required work
 * there's no Signed-off-by: line from the author so it can't be committed as is

Hopefully somebody else on the list will have time to look properly at
the patch; I'm afraid I don't expect to currently.

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

Title:
  qemu-i386 user mode on ARMv5 host fails (bash: fork: Invalid argument)

Status in QEMU:
  New

Bug description:
  Good time of day everybody,

  I have been trying to make usermode qemu on ARM with plugapps
  (archlinux) with archlinux i386 chroot to work.

  1. I installed arch linux in a virtuabox and created a chroot for it with 
mkarchroot. Transferred it to my pogo plug into /i386/
  2. I comiled qemu-i386 static and put it into /i386/usr/bin/
  ./configure --static --disable-blobs --disable-system 
--target-list=i386-linux-user
  make

  3. I also compiled linux kernel 2.6.38 with CONFIG_BINFMT_MISC=y and 
installed it.
  uname -a
  Linux Plugbox 2.6.38 #4 PREEMPT Fri Mar 18 22:19:10 CDT 2011 armv5tel 
Feroceon 88FR131 rev 1 (v5l) Marvell SheevaPlug Reference Board GNU/Linux

  4. Added the following options into /etc/rc.local
  /sbin/modprobe binfmt_misc
  /bin/mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
  echo 
':qemu-i386:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff\xff:/usr/bin/qemu-i386:'
 >/proc/sys/fs/binfmt_misc/register

  5. Also copied ld-linux.so.3 (actually ld-2.13.so because ld-
  linux.so.3 is a link to that file) from /lib/ to /i386/lib/

  6.Now i chroot into /i386 and I get this:
  [root@Plugbox i386]# chroot .
  [II aI hnve ao n@P /]# pacman -Suy
  bash: fork: Invalid argument

  7.I also downloaded linux-user-test-0.3 from qemu website and ran the test:
  [root@Plugbox linux-user-test-0.3]# make
  ./qemu-linux-user.sh
  [qemu-i386]
  ../qemu-0.14.0/i386-linux-user/qemu-i386 -L ./gnemul/qemu-i386 i386/ls -l 
dummyfile
  BUG IN DYNAMIC LINKER ld.so: dl-version.c: 210: _dl_check_map_versions: 
Assertion `needed != ((void *)0)' failed!
  make: *** [test] Error 127

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



Re: [Qemu-devel] gcc auto-omit-frame-pointer vs msvc longjmp

2011-10-19 Thread Bob Breuer
Kai Tietz wrote:
> 2011/10/18 Bob Breuer :
>> Kai Tietz wrote:
>>> 2011/10/17 Bob Breuer :
 Richard Henderson wrote:
> On 10/17/2011 07:09 AM, Bob Breuer wrote:
>> Google finds a mention of longjmp failing with -fomit-frame-pointer:
>> http://lua-users.org/lists/lua-l/2005-02/msg00158.html
>>
>> Looks like gcc 4.6 turns on -fomit-frame-pointer by default.
> Hmm.  This is the first I've heard of a longjmp implementation
> failing without a frame pointer.  Presumably this is with the
> mingw i.e. msvc libc?
 Yeah, mingw from www.mingw.org which I believe uses msvcrt.dll, package
 gcc-core-4.6.1-2-mingw32-bin.

> This is something that could be worked around in gcc, I suppose.
> We recognize longjmp for some things, we could force the use of
> a frame pointer for msvc targets too.
>
> For now it might be best to simply force -fno-omit-frame-pointer
> for mingw host in the configure script.
 Here's a testcase that crashes on the longjmp:

 #include 
 #include 

 jmp_buf env;

 int test(void)
 {
  int i;

  asm("xor %%ebp,%%ebp" ::: "ebp");

  i = setjmp(env);
  printf("i = %d\n", i);

  if (i == 0)
longjmp(env, 2);

  return i;
 }

 int main(void)
 {
  return test();
 }

 Remove the asm statement to make it not crash.  Obviously with
 omit-frame-pointer, gcc can shove anything into ebp.

 Bob
>>> This crash isn'r related to ebp existing, or not. The issue is the
>>> hidden argument of setjmp, which is missing.  If you can try the
>>> following at top of file after include section.
>>>
>>> #define setjmp(BUF) _setjmpex((BUF), NULL)
>>> int __cdecl __attribute__ ((__nothrow__,__returns_twice__))
>>> _setjmp3(jmp_buf _Buf, void *_Ctx);
>>> ...
>> Did you mean _setjmp3 instead of _setjmpex?  With _setjmp3, it works
>> without the asm, but still crashes if I zero out ebp before the setjmp.
>>  Aren't the function arguments on the stack anyway?
> 
> Yes, I mean _setjmp3 (pasto from headers and missed the second line
> prototyping _setjmp3).
> I repeat myself here.  setjmp() has an hidden arguement, which is
> passed on x86 on stack.  By not passing this required argument, setjmp
> will take a random-value from stack.  In your case 'i'.  btw if you
> would pre-initialize 'i' with zero, I would assume you won't see a
> crash, but anyway this is just by chance.
> For this I suggest to use here _setjmp3 instead, as here
> second-argument is documented as being present.
> 
> Btw I tested your code with i686-pc-mingw32 version 4.6.x and 4.7.x
> gcc version.  With my suggested pattern, I don't see a crash for your
> provide test-code with, or without zero-ing ebp.


We probably have a difference in build or run environment.  I've
double-checked with another machine and can get the same crash in
longjmp when running the test executable on both WinXP and Win2k, but
not on Win7.  So it looks like Microsoft may have changed this "feature"
somewhere between WinXP and Win7.

The msvcrt implementation of longjmp (or at least the one I'm looking
at) does a ebp based access using the saved value of ebp.  Here's the
relevant disassembly of longjmp:

0x7801e6f3 in longjmpex () from C:\WINNT\system32\msvcrt.dll
(gdb) disas
Dump of assembler code for function longjmpex:
   0x7801e6ef <+0>: mov0x4(%esp),%ebx
=> 0x7801e6f3 <+4>: mov(%ebx),%ebp
...
   0x7801e73d <+78>:call   0x7800bd5e 
...
   0x7800bd5e <+56>:push   %ebx
   0x7800bd5f <+57>:push   %ecx
   0x7800bd60 <+58>:mov$0x7803dc64,%ebx
=> 0x7800bd65 <+63>:mov0x8(%ebp),%ecx

It crashes on the access of 0x8(%ebp).  Those are the only 2 places
where this version of longjmp touches ebp.  Is it possible to force a
stackframe by just adding a suitable attribute to either the setjmp
function prototype, or the function which calls setjmp?

Bob



[Qemu-devel] [Bug 739785] Re: qemu-i386 user mode on ARMv5 host fails (bash: fork: Invalid argument)

2011-10-19 Thread Steve
This bug also pertains to armv7l.  I have a Debian chroot install on my
Android phone, and was trying to do an i386 chroot within my chroot
(want to run the i386 specific binaries included in the Android SDK).

I installed the qemu-user-static package (tried both v  0.14.1 and
0.15.0).

When putting qemu-i386-static in the usr/bin folder of my chroot, and
trying to run `chroot .` I got the fork error mentioned above when
executing any command-line programs. Incidentally-- it *did* work if I
used `exec ls`, but obviously that would kill my chroot. I assume using
exec just circumvented the fork() call.

I was able to native compile qemu 0.14.1 as --static, with the patch
provided in #32 above, and I can confirm it works fine -- no fork error.

@Peter Maydell -- do you think you will get that patch incorporated into
the main fork of QEMU? I imagine it becoming a bigger issue as more and
more people start running full Linux distros on their ARM-based phones;
especially as the mobile processors get faster.

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

Title:
  qemu-i386 user mode on ARMv5 host fails (bash: fork: Invalid argument)

Status in QEMU:
  New

Bug description:
  Good time of day everybody,

  I have been trying to make usermode qemu on ARM with plugapps
  (archlinux) with archlinux i386 chroot to work.

  1. I installed arch linux in a virtuabox and created a chroot for it with 
mkarchroot. Transferred it to my pogo plug into /i386/
  2. I comiled qemu-i386 static and put it into /i386/usr/bin/
  ./configure --static --disable-blobs --disable-system 
--target-list=i386-linux-user
  make

  3. I also compiled linux kernel 2.6.38 with CONFIG_BINFMT_MISC=y and 
installed it.
  uname -a
  Linux Plugbox 2.6.38 #4 PREEMPT Fri Mar 18 22:19:10 CDT 2011 armv5tel 
Feroceon 88FR131 rev 1 (v5l) Marvell SheevaPlug Reference Board GNU/Linux

  4. Added the following options into /etc/rc.local
  /sbin/modprobe binfmt_misc
  /bin/mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
  echo 
':qemu-i386:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff\xff:/usr/bin/qemu-i386:'
 >/proc/sys/fs/binfmt_misc/register

  5. Also copied ld-linux.so.3 (actually ld-2.13.so because ld-
  linux.so.3 is a link to that file) from /lib/ to /i386/lib/

  6.Now i chroot into /i386 and I get this:
  [root@Plugbox i386]# chroot .
  [II aI hnve ao n@P /]# pacman -Suy
  bash: fork: Invalid argument

  7.I also downloaded linux-user-test-0.3 from qemu website and ran the test:
  [root@Plugbox linux-user-test-0.3]# make
  ./qemu-linux-user.sh
  [qemu-i386]
  ../qemu-0.14.0/i386-linux-user/qemu-i386 -L ./gnemul/qemu-i386 i386/ls -l 
dummyfile
  BUG IN DYNAMIC LINKER ld.so: dl-version.c: 210: _dl_check_map_versions: 
Assertion `needed != ((void *)0)' failed!
  make: *** [test] Error 127

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



[Qemu-devel] [PATCH] libcacard: Fix wrong assertion (reported by cppcheck)

2011-10-19 Thread Stefan Weil
assert("...") will never do anything. This assertion handles a case
which should never occur, so it must be assert(!"...").

Cc: Alon Levy 
Signed-off-by: Stefan Weil 
---
 libcacard/card_7816.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libcacard/card_7816.c b/libcacard/card_7816.c
index 9fd59d4..6fe27d5 100644
--- a/libcacard/card_7816.c
+++ b/libcacard/card_7816.c
@@ -754,7 +754,7 @@ vcard_process_apdu(VCard *card, VCardAPDU *apdu, 
VCardResponse **response)
 return vcard7816_vm_process_apdu(card, apdu, response);
 case VCARD_DIRECT:
 /* if we are type direct, then the applet should handle everything */
-assert("VCARD_DIRECT: applet failure");
+assert(!"VCARD_DIRECT: applet failure");
 break;
 }
 *response =
-- 
1.7.2.5




Re: [Qemu-devel] [PATCH] [v2] arm gic saving/loading fix

2011-10-19 Thread Peter Maydell
On 19 October 2011 15:10, Dmitry Koshelev  wrote:
> irq_target field saving/loading is in the wrong loop
> version bump
>
> Signed-off-by: Dmitry Koshelev 
> ---
>  hw/arm_gic.c |   16 
>  1 files changed, 8 insertions(+), 8 deletions(-)
>
> @@ -744,5 +744,5 @@ static void gic_init(gic_state *s)
>     s->iomemtype = cpu_register_io_memory(gic_dist_readfn,
>                                           gic_dist_writefn, s);
>     gic_reset(s);
> -    register_savevm(NULL, "arm_gic", -1, 1, gic_save, gic_load, s);
> +    register_savevm(NULL, "arm_gic", -1, 2, gic_save, gic_load, s);
>  }
>

This doesn't apply against master -- can you rebase, please?

Since you need to resend anyway, convention for git commit messages
is to put the filename in the summary line, something like

 hw/arm_gic.c: Fix save/load of irq_target array

Also, if at all possible, can you send via a mailer which doesn't
wrap long lines? Otherwise I have to fix them at this end which
is very tedious...

thanks
-- PMM



Re: [Qemu-devel] [PATCH 00/26] AREG0 conversion

2011-10-19 Thread Richard Henderson
On 10/09/2011 12:20 PM, Blue Swirl wrote:
>> I didn't bother to attach the patches, if someone wants to try, the
>> patch set can be found here:
>>git://repo.or.cz/qemu/blueswirl.git
>>http://repo.or.cz/r/qemu/blueswirl.git
> 
> I pushed the patch set to repo.or.cz so if someone wants to comment or
> test, they are there.
> 
> It's mostly the same stuff as before, though I split int_helper.c to
> int32_helper.c and int64_helper.c since they have nothing in common
> and extracted TCG iargs/oargs changes.
> 
>> Blue Swirl (26):
>>  Document softmmu templates
>>  softmmu_header: pass CPUState to tlb_fill
>>  Move GETPC from dyngen-exec.h to exec-all.h

I don't see these three in the repo.

>>  Sparc: fix coding style

Reviewed-by: Richard Henderson 

>>  Sparc: split helper.c

Reviewed-by: Richard Henderson 

>>  Sparc: move trivial functions from op_helper.c

Reviewed-by: Richard Henderson 

>>  Sparc: avoid AREG0 for raise_exception and helper_debug

Reviewed-by: Richard Henderson 

>>  Sparc: fix coding style

Reviewed-by: Richard Henderson 

>>  Sparc: split FPU and VIS op helpers

Reviewed-by: Richard Henderson 

>>  Sparc: avoid AREG0 for float and VIS ops

Reviewed-by: Richard Henderson 

>>  Sparc: split lazy condition code handling op helpers

Reviewed-by: Richard Henderson 

>>  Sparc: avoid AREG0 for lazy condition code helpers

Reviewed-by: Richard Henderson 

>>  Sparc: split CWP and PSTATE op helpers

Reviewed-by: Richard Henderson 

>>  Sparc: avoid AREG0 for CWP and PSTATE helpers

Reviewed-by: Richard Henderson 
An especially nice cleanup too, avoiding all of the saved_env frobbing.

>>  Sparc: avoid AREG0 for softint op helpers and Leon cache control

This one loses do_modify_softint in the move.  Which gets re-instated
in your following "convert int_helper to trace framework" patch.  But
in the meantime the series is non-bisectable.

>>  Sparc: avoid AREG0 for division op helpers

Reviewed-by: Richard Henderson 

>>  Sparc: fix coding style in helper.c

Reviewed-by: Richard Henderson 

>>  Sparc: split MMU helpers

Reviewed-by: Richard Henderson 

>>  Sparc: convert mmu_helper to trace framework

Reviewed-by: Richard Henderson 

>>  Sparc: convert int_helper to trace framework

Reviewed-by: Richard Henderson 

>>  Sparc: convert win_helper to trace framework

Reviewed-by: Richard Henderson 

>>  Sparc: split load and store op helpers

Reviewed-by: Richard Henderson 

>>  TCG: add 5 arg helpers to def-helper.h

Reviewed-by: Richard Henderson 

>>  Sparc: avoid AREG0 for memory access helpers

> +#define WRAP_LD(rettype, fn)\
> +rettype cpu_ ## fn (CPUState *env1, target_ulong addr)  \
> +{   \
> +CPUState *saved_env;\
> +rettype ret;\
> +\
> +saved_env = env;\
> +env = env1; \
> +ret = fn(addr); \
> +env = saved_env;\
> +return ret; \
> +}

I don't think this actually works in the fault case.  In particular GETPC
will return an incorrect address.  OTOH, I suppose we already have this
problem from the other ldst helpers, e.g. ld_asi, which is where these new
routines are going to be called from.  So this doesn't really change the
state of affairs much.  I have no good ideas for solving this problem.

Reviewed-by: Richard Henderson 

>>  softmmu templates: optionally pass CPUState to memory access
>>functions
>>  Sparc: avoid AREG0 wrappers for memory access helpers

Both look ok.  I'm certainly not fond of the intermediate state.  If we
convert target-sparc and tcg-i386, we should convert all of them, and 
not leave that intermediate state for long.

Something that's clearly not going to happen for the 1.0 release.


r~



[Qemu-devel] [PATCH 2/2] hw/9pfs: Read-only support for 9p export

2011-10-19 Thread M. Mohan Kumar
From: "M. Mohan Kumar" 

A new fsdev parameter "readonly" is introduced to control accessing 9p export.
readonly=on|off can be used to specify the access type. By default rw access
is given to 9p export.

Signed-off-by: M. Mohan Kumar 

---
Changes from previous version V4:
* Updated on top of current for-upstream branch

Changes from previous version V3:
* Use opt_set_bool function to set readonly option
* Change the flag from MS_READONLY to 9p specific

Change from previous version V2:
* QEMU_OPT_BOOL is used for readdonly parameter

Changes from previous version:
* Use "readonly" option instead of "access"
* Change function return type to boolean where its needed

 fsdev/file-op-9p.h  |2 ++
 fsdev/qemu-fsdev.c  |7 ++-
 hw/9pfs/virtio-9p.c |   51 +++
 qemu-config.c   |7 +++
 vl.c|2 ++
 5 files changed, 68 insertions(+), 1 deletions(-)

diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h
index c7b4e38..ba564d4 100644
--- a/fsdev/file-op-9p.h
+++ b/fsdev/file-op-9p.h
@@ -60,6 +60,8 @@ typedef struct extended_ops {
 
 #define V9FS_SEC_MASK   0x001C
 
+#define V9FS_RDONLY 0x0020
+
 typedef struct FsContext
 {
 uid_t uid;
diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c
index e8dc0fd..7fd2aa7 100644
--- a/fsdev/qemu-fsdev.c
+++ b/fsdev/qemu-fsdev.c
@@ -36,7 +36,7 @@ int qemu_fsdev_add(QemuOpts *opts)
 const char *path = qemu_opt_get(opts, "path");
 const char *sec_model = qemu_opt_get(opts, "security_model");
 const char *writeout = qemu_opt_get(opts, "writeout");
-
+bool ro = qemu_opt_get_bool(opts, "readonly", 0);
 
 if (!fsdev_id) {
 fprintf(stderr, "fsdev: No id specified\n");
@@ -87,6 +87,11 @@ int qemu_fsdev_add(QemuOpts *opts)
 fsle->fse.export_flags |= V9FS_IMMEDIATE_WRITEOUT;
 }
 }
+if (ro) {
+fsle->fse.export_flags |= V9FS_RDONLY;
+} else {
+fsle->fse.export_flags &= ~V9FS_RDONLY;
+}
 
 if (strcmp(fsdriver, "local")) {
 goto done;
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 1c67bfe..b6770e2 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -1271,6 +1271,11 @@ static void v9fs_fix_path(V9fsPath *dst, V9fsPath *src, 
int len)
 dst->size++;
 }
 
+static inline bool is_ro_export(int export_flags)
+{
+return export_flags & V9FS_RDONLY;
+}
+
 static void v9fs_version(void *opaque)
 {
 V9fsPDU *pdu = opaque;
@@ -1692,6 +1697,15 @@ static void v9fs_open(void *opaque)
 } else {
 flags = omode_to_uflags(mode);
 }
+if (is_ro_export(s->ctx.export_flags)) {
+if (mode & O_WRONLY || mode & O_RDWR ||
+mode & O_APPEND || mode & O_TRUNC) {
+err = -EROFS;
+goto out;
+} else {
+flags |= O_NOATIME;
+}
+}
 err = v9fs_co_open(pdu, fidp, flags);
 if (err < 0) {
 goto out;
@@ -3311,6 +3325,39 @@ static void v9fs_op_not_supp(void *opaque)
 complete_pdu(pdu->s, pdu, -EOPNOTSUPP);
 }
 
+static void v9fs_fs_ro(void *opaque)
+{
+V9fsPDU *pdu = opaque;
+complete_pdu(pdu->s, pdu, -EROFS);
+}
+
+static inline bool is_read_only_op(int id)
+{
+switch (id) {
+case P9_TREADDIR:
+case P9_TSTATFS:
+case P9_TGETATTR:
+case P9_TXATTRWALK:
+case P9_TLOCK:
+case P9_TGETLOCK:
+case P9_TREADLINK:
+case P9_TVERSION:
+case P9_TLOPEN:
+case P9_TATTACH:
+case P9_TSTAT:
+case P9_TWALK:
+case P9_TCLUNK:
+case P9_TFSYNC:
+case P9_TOPEN:
+case P9_TREAD:
+case P9_TAUTH:
+case P9_TFLUSH:
+return 1;
+default:
+return 0;
+}
+}
+
 static void submit_pdu(V9fsState *s, V9fsPDU *pdu)
 {
 Coroutine *co;
@@ -3322,6 +3369,10 @@ static void submit_pdu(V9fsState *s, V9fsPDU *pdu)
 } else {
 handler = pdu_co_handlers[pdu->id];
 }
+
+if (is_ro_export(s->ctx.export_flags) && !is_read_only_op(pdu->id)) {
+handler = v9fs_fs_ro;
+}
 co = qemu_coroutine_create(handler);
 qemu_coroutine_enter(co, pdu);
 }
diff --git a/qemu-config.c b/qemu-config.c
index 90b6b3e..597d7e1 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -180,7 +180,11 @@ QemuOptsList qemu_fsdev_opts = {
 }, {
 .name = "writeout",
 .type = QEMU_OPT_STRING,
+}, {
+.name = "readonly",
+.type = QEMU_OPT_BOOL,
 },
+
 { /*End of list */ }
 },
 };
@@ -205,6 +209,9 @@ QemuOptsList qemu_virtfs_opts = {
 }, {
 .name = "writeout",
 .type = QEMU_OPT_STRING,
+}, {
+.name = "readonly",
+.type = QEMU_OPT_BOOL,
 },
 
 { /*End of list */ }
diff --git a/vl.c b/vl.c
index c9de124..cf66ef9 100644
--- a/vl.c
+++ b/vl.c
@@ -2823,6 +2823,8 @@ int main(int argc, char **argv, cha

[Qemu-devel] [PATCH 1/2] qemu: Add opt_set_bool functionality

2011-10-19 Thread M. Mohan Kumar
From: "M. Mohan Kumar" 

Signed-off-by: M. Mohan Kumar 
---
Changes from previous version:
* Changed qemu_opt_{get|set}_bool to use 'bool' data type

 qemu-option.c |   43 +++
 qemu-option.h |3 ++-
 2 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/qemu-option.c b/qemu-option.c
index 105d760..1fd2755 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -168,7 +168,7 @@ QEMUOptionParameter 
*get_option_parameter(QEMUOptionParameter *list,
 return NULL;
 }
 
-static int parse_option_bool(const char *name, const char *value, int *ret)
+static int parse_option_bool(const char *name, const char *value, bool *ret)
 {
 if (value != NULL) {
 if (!strcmp(value, "on")) {
@@ -258,7 +258,7 @@ static int parse_option_size(const char *name, const char 
*value, uint64_t *ret)
 int set_option_parameter(QEMUOptionParameter *list, const char *name,
 const char *value)
 {
-int flag;
+bool flag;
 
 // Find a matching parameter
 list = get_option_parameter(list, name);
@@ -508,7 +508,7 @@ struct QemuOpt {
 
 const QemuOptDesc *desc;
 union {
-int  boolean;
+bool boolean;
 uint64_t uint;
 } value;
 
@@ -542,7 +542,7 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name)
 return opt ? opt->str : NULL;
 }
 
-int qemu_opt_get_bool(QemuOpts *opts, const char *name, int defval)
+bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
 {
 QemuOpt *opt = qemu_opt_find(opts, name);
 
@@ -636,6 +636,41 @@ int qemu_opt_set(QemuOpts *opts, const char *name, const 
char *value)
 return 0;
 }
 
+int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val)
+{
+QemuOpt *opt;
+const QemuOptDesc *desc = opts->list->desc;
+int i;
+
+for (i = 0; desc[i].name != NULL; i++) {
+if (strcmp(desc[i].name, name) == 0) {
+break;
+}
+}
+if (desc[i].name == NULL) {
+if (i == 0) {
+/* empty list -> allow any */;
+} else {
+qerror_report(QERR_INVALID_PARAMETER, name);
+return -1;
+}
+}
+
+opt = g_malloc0(sizeof(*opt));
+opt->name = g_strdup(name);
+opt->opts = opts;
+QTAILQ_INSERT_TAIL(&opts->head, opt, next);
+if (desc[i].name != NULL) {
+opt->desc = desc+i;
+}
+opt->value.boolean = !!val;
+if (qemu_opt_parse(opt) < 0) {
+qemu_opt_del(opt);
+return -1;
+}
+return 0;
+}
+
 int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
  int abort_on_failure)
 {
diff --git a/qemu-option.h b/qemu-option.h
index b515813..07958e4 100644
--- a/qemu-option.h
+++ b/qemu-option.h
@@ -105,10 +105,11 @@ struct QemuOptsList {
 };
 
 const char *qemu_opt_get(QemuOpts *opts, const char *name);
-int qemu_opt_get_bool(QemuOpts *opts, const char *name, int defval);
+bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval);
 uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t 
defval);
 uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval);
 int qemu_opt_set(QemuOpts *opts, const char *name, const char *value);
+int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val);
 typedef int (*qemu_opt_loopfunc)(const char *name, const char *value, void 
*opaque);
 int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
  int abort_on_failure);
-- 
1.7.6




Re: [Qemu-devel] [PATCH 1/2] hw/nand: reject read-only drives

2011-10-19 Thread Markus Armbruster
juha.riihim...@nokia.com writes:

> From: Juha Riihimäki 
>
> Signed-off-by: Juha Riihimäki 
> ---
>  hw/nand.c |   23 +++
>  1 files changed, 15 insertions(+), 8 deletions(-)
>
> diff --git a/hw/nand.c b/hw/nand.c
> index c27783e..da6529d 100644
> --- a/hw/nand.c
> +++ b/hw/nand.c
> @@ -19,6 +19,7 @@
>  # include "flash.h"
>  # include "blockdev.h"
>  # include "sysbus.h"
> +#include "qemu-error.h"
>  
>  # define NAND_CMD_READ0  0x00
>  # define NAND_CMD_READ1  0x01
> @@ -384,18 +385,24 @@ static int nand_device_init(SysBusDevice *dev)
>  nand_init_2048(s);
>  break;
>  default:
> -hw_error("%s: Unsupported NAND block size.\n", __func__);
> +error_report("Unsupported NAND block size");
> +return -1;

Not mentioned in commit message.  Separate patch?

>  }
>  
> -pagesize = 1 << s->oob_shift;
>  s->mem_oob = 1;
> -if (s->bdrv && bdrv_getlength(s->bdrv) >=
> +if (s->bdrv) {
> +if (bdrv_is_read_only(s->bdrv)) {
> +error_report("Can't use a read-only drive");
> +return -1;
> +}
> +if (bdrv_getlength(s->bdrv) >=
>  (s->pages << s->page_shift) + (s->pages << s->oob_shift)) {
> -pagesize = 0;
> -s->mem_oob = 0;
> -}
> -
> -if (!s->bdrv) {
> +pagesize = 0;
> +s->mem_oob = 0;
> +} else {
> +pagesize = 1 << s->oob_shift;
> +}
> +} else {
>  pagesize += 1 << s->page_shift;

Doesn't this use pagesize uninitialized?

>  }
>  if (pagesize) {



Re: [Qemu-devel] [PATCH] [v2] arm gic saving/loading fix

2011-10-19 Thread Andreas Färber
Dmitry,

It would be nice to cc the people that have cared to review previous
versions of the patch, Peter Maydell and me. Gets you quicker replies.

Functional ARM patches are being reviewed by our ARM gurus and not by
Stefan Hajnoczi, so please drop qemu-trivial from the cc list, as
pointed out before.

Am 19.10.2011 16:10, schrieb Dmitry Koshelev:
> irq_target field saving/loading is in the wrong loop
> version bump
> 
> Signed-off-by: Dmitry Koshelev 

>From my side this version looks okay now, with a check for loading and a
bump for registration. Being no expert for the old savevm format,

Reviewed-by: Andreas Färber 

Andreas

> ---
>  hw/arm_gic.c |   16 
>  1 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/arm_gic.c b/hw/arm_gic.c
> index 8286a28..d0747cf 100644
> --- a/hw/arm_gic.c
> +++ b/hw/arm_gic.c
> @@ -662,9 +662,6 @@ static void gic_save(QEMUFile *f, void *opaque)
>  qemu_put_be32(f, s->enabled);
>  for (i = 0; i < NUM_CPU(s); i++) {
>  qemu_put_be32(f, s->cpu_enabled[i]);
> -#ifndef NVIC
> -qemu_put_be32(f, s->irq_target[i]);
> -#endif
>  for (j = 0; j < 32; j++)
>  qemu_put_be32(f, s->priority1[j][i]);
>  for (j = 0; j < GIC_NIRQ; j++)
> @@ -678,6 +675,9 @@ static void gic_save(QEMUFile *f, void *opaque)
>  qemu_put_be32(f, s->priority2[i]);
>  }
>  for (i = 0; i < GIC_NIRQ; i++) {
> +#ifndef NVIC
> +qemu_put_be32(f, s->irq_target[i]);
> +#endif
>  qemu_put_byte(f, s->irq_state[i].enabled);
>  qemu_put_byte(f, s->irq_state[i].pending);
>  qemu_put_byte(f, s->irq_state[i].active);
> @@ -693,15 +693,12 @@ static int gic_load(QEMUFile *f, void *opaque,
> int version_id)
>  int i;
>  int j;
> 
> -if (version_id != 1)
> +if (version_id != 2)
>  return -EINVAL;
> 
>  s->enabled = qemu_get_be32(f);
>  for (i = 0; i < NUM_CPU(s); i++) {
>  s->cpu_enabled[i] = qemu_get_be32(f);
> -#ifndef NVIC
> -s->irq_target[i] = qemu_get_be32(f);
> -#endif
>  for (j = 0; j < 32; j++)
>  s->priority1[j][i] = qemu_get_be32(f);
>  for (j = 0; j < GIC_NIRQ; j++)
> @@ -715,6 +712,9 @@ static int gic_load(QEMUFile *f, void *opaque, int
> version_id)
>  s->priority2[i] = qemu_get_be32(f);
>  }
>  for (i = 0; i < GIC_NIRQ; i++) {
> +#ifndef NVIC
> +s->irq_target[i] = qemu_get_be32(f);
> +#endif
>  s->irq_state[i].enabled = qemu_get_byte(f);
>  s->irq_state[i].pending = qemu_get_byte(f);
>  s->irq_state[i].active = qemu_get_byte(f);
> @@ -744,5 +744,5 @@ static void gic_init(gic_state *s)
>  s->iomemtype = cpu_register_io_memory(gic_dist_readfn,
>gic_dist_writefn, s);
>  gic_reset(s);
> -register_savevm(NULL, "arm_gic", -1, 1, gic_save, gic_load, s);
> +register_savevm(NULL, "arm_gic", -1, 2, gic_save, gic_load, s);
>  }
> 


-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746, AG Nürnberg



Re: [Qemu-devel] [PATCH 1/1 V6] qemu-kvm: fix improper nmi emulation

2011-10-19 Thread Lai Jiangshan
On 10/19/2011 05:29 PM, Avi Kivity wrote:
> 
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
> 
> On 10/18/2011 09:41 PM, Jan Kiszka wrote:
>>
>> Looks OK to me.
>>
>>
> 
> Same here.

Who will merge it?

Thanks,
Lai

> 
> - -- 
> I have a truly marvellous patch that fixes the bug which this
> signature is too narrow to contain.
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.11 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> 
> iQIcBAEBAgAGBQJOnpiNAAoJEI7yEDeUysxllqUP/3K9oPbz9OxbqH3+9G1W9cUy
> 49hKR0DtLyf5WH0hoSq3/jA2T00PWR6fLIo6itth76x/TqnIuimjln6Nrj/T2nhO
> PPvwJB4OE/9ahSlm3JOVsE/JYwDx6h3u9eouN5BqVoQax8S3mnhxSGLxZOp8wvar
> ol6vDj2U8JbigV3fCsFheiP9tTZWZgH66qCdCUzuNUnYWUW5m9repdsXflTp6YyW
> id30xzuZETnQ/0RFU0hnhrfQ/vvm1dJeK6Y2bPKowoDCp+CFNi/CnJYDAZA18FSQ
> V5096U8cj8/m/Hr8fPLpyZzDonPz0KfMPvtfV9rVHEtqvf04Ym+gcdfwo+2U4LQs
> 16RNGWwsF6qIAcyevK9xCpcU9g00v6m0fyj3eQgD+JT+pV+m8QCzNnQyDqDlEUEl
> ub0WR7ilnl3/NIa6FTKHqZ5Wct8f9mO6wcCtJKXDTcHo/2uB5+kHzqJsLE2UCaXm
> ptaiyFGZgGNpUocO+tYxeORWm4kNMoZRAaYmiU0RWaoIkQMY0P/m/Ghy+nZBUexM
> vdH1lQ8DQoqQQxiC38MoO717rBOHDgxPoUGVPyPtU7qPhI2sSMYa2r+Uwi/Pmsm/
> /dbKMbQs9q9pVkESBsmpkSLMVOrLQE/ju3h7iikZmY5RVrm+pI8fyOo9e20+/mKG
> aO5IT5IDaHXAVk8jjAWB
> =rMf/
> -END PGP SIGNATURE-
> 
> 




[Qemu-devel] [PATCH 6/8] block: take lock around bdrv_write implementations

2011-10-19 Thread Paolo Bonzini
This does the first part of the conversion to coroutines, by
wrapping bdrv_write implementations to take the write side of the
rwlock.

Drivers that implement bdrv_write rather than bdrv_co_writev can
then benefit from asynchronous operation (at least if the underlying
protocol supports it, which is not the case for raw-win32), even
though they still operate with a bounce buffer.

Signed-off-by: Paolo Bonzini 
---
 block/cow.c   |   13 -
 block/nbd.c   |   13 -
 block/vmdk.c  |   13 -
 block/vpc.c   |   13 -
 block/vvfat.c |   13 -
 5 files changed, 60 insertions(+), 5 deletions(-)

diff --git a/block/cow.c b/block/cow.c
index 9571549..61eaca2 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -226,6 +226,17 @@ static int cow_write(BlockDriverState *bs, int64_t 
sector_num,
 return cow_update_bitmap(bs, sector_num, nb_sectors);
 }
 
+static coroutine_fn int cow_co_write(BlockDriverState *bs, int64_t sector_num,
+ const uint8_t *buf, int nb_sectors)
+{
+int ret;
+BDRVCowState *s = bs->opaque;
+qemu_co_rwlock_wrlock(&s->lock);
+ret = cow_write(bs, sector_num, buf, nb_sectors);
+qemu_co_rwlock_unlock(&s->lock);
+return ret;
+}
+
 static void cow_close(BlockDriverState *bs)
 {
 }
@@ -320,7 +331,7 @@ static BlockDriver bdrv_cow = {
 .bdrv_probe= cow_probe,
 .bdrv_open = cow_open,
 .bdrv_read = cow_co_read,
-.bdrv_write= cow_write,
+.bdrv_write= cow_co_write,
 .bdrv_close= cow_close,
 .bdrv_create   = cow_create,
 .bdrv_flush= cow_flush,
diff --git a/block/nbd.c b/block/nbd.c
index f8fed92..12da988 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -251,6 +251,17 @@ static coroutine_fn int nbd_co_read(BlockDriverState *bs, 
int64_t sector_num,
 return ret;
 }
 
+static coroutine_fn int nbd_co_write(BlockDriverState *bs, int64_t sector_num,
+ const uint8_t *buf, int nb_sectors)
+{
+int ret;
+BDRVNBDState *s = bs->opaque;
+qemu_co_rwlock_wrlock(&s->lock);
+ret = nbd_write(bs, sector_num, buf, nb_sectors);
+qemu_co_rwlock_unlock(&s->lock);
+return ret;
+}
+
 static void nbd_close(BlockDriverState *bs)
 {
 BDRVNBDState *s = bs->opaque;
@@ -272,7 +283,7 @@ static BlockDriver bdrv_nbd = {
 .instance_size = sizeof(BDRVNBDState),
 .bdrv_file_open= nbd_open,
 .bdrv_read = nbd_co_read,
-.bdrv_write= nbd_write,
+.bdrv_write= nbd_co_write,
 .bdrv_close= nbd_close,
 .bdrv_getlength= nbd_getlength,
 .protocol_name = "nbd",
diff --git a/block/vmdk.c b/block/vmdk.c
index ff78e25..a0c22f1 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1114,6 +1114,17 @@ static int vmdk_write(BlockDriverState *bs, int64_t 
sector_num,
 return 0;
 }
 
+static coroutine_fn int vmdk_co_write(BlockDriverState *bs, int64_t sector_num,
+  const uint8_t *buf, int nb_sectors)
+{
+int ret;
+BDRVVmdkState *s = bs->opaque;
+qemu_co_rwlock_wrlock(&s->lock);
+ret = vmdk_write(bs, sector_num, buf, nb_sectors);
+qemu_co_rwlock_unlock(&s->lock);
+return ret;
+}
+
 
 static int vmdk_create_extent(const char *filename, int64_t filesize,
   bool flat, bool compress)
@@ -1552,7 +1563,7 @@ static BlockDriver bdrv_vmdk = {
 .bdrv_probe = vmdk_probe,
 .bdrv_open  = vmdk_open,
 .bdrv_read  = vmdk_co_read,
-.bdrv_write = vmdk_write,
+.bdrv_write = vmdk_co_write,
 .bdrv_close = vmdk_close,
 .bdrv_create= vmdk_create,
 .bdrv_flush = vmdk_flush,
diff --git a/block/vpc.c b/block/vpc.c
index e805769..915e30c 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -456,6 +456,17 @@ static int vpc_write(BlockDriverState *bs, int64_t 
sector_num,
 return 0;
 }
 
+static coroutine_fn int vpc_co_write(BlockDriverState *bs, int64_t sector_num,
+ const uint8_t *buf, int nb_sectors)
+{
+int ret;
+BDRVVPCState *s = bs->opaque;
+qemu_co_rwlock_wrlock(&s->lock);
+ret = vpc_write(bs, sector_num, buf, nb_sectors);
+qemu_co_rwlock_unlock(&s->lock);
+return ret;
+}
+
 static int vpc_flush(BlockDriverState *bs)
 {
 return bdrv_flush(bs->file);
@@ -661,7 +672,7 @@ static BlockDriver bdrv_vpc = {
 .bdrv_probe = vpc_probe,
 .bdrv_open  = vpc_open,
 .bdrv_read  = vpc_co_read,
-.bdrv_write = vpc_write,
+.bdrv_write = vpc_co_write,
 .bdrv_flush = vpc_flush,
 .bdrv_close = vpc_close,
 .bdrv_create= vpc_create,
diff --git a/block/vvfat.c b/block/vvfat.c
index f1d94ad..be8f990 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2725,6 +2725,17 @@ DLOG(checkpoint());
 return 0;
 }
 
+static coroutine_fn int vvfat_

[Qemu-devel] [PATCH 3/8] vmdk: clean up open

2011-10-19 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini 
---
 block/vmdk.c |   37 +++--
 1 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index 21566eb..12b38d2 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -622,20 +622,7 @@ static int vmdk_open_desc_file(BlockDriverState *bs, int 
flags,
 return -ENOTSUP;
 }
 s->desc_offset = 0;
-ret = vmdk_parse_extents(buf, bs, bs->file->filename);
-if (ret) {
-vmdk_free_extents(bs);
-return ret;
-}
-
-/* try to open parent images, if exist */
-ret = vmdk_parent_open(bs);
-if (ret) {
-vmdk_free_extents(bs);
-return ret;
-}
-s->parent_cid = vmdk_read_cid(bs, 1);
-return 0;
+return vmdk_parse_extents(buf, bs, bs->file->filename);
 }
 
 static int vmdk_open(BlockDriverState *bs, int flags)
@@ -645,17 +632,23 @@ static int vmdk_open(BlockDriverState *bs, int flags)
 
 if (vmdk_open_sparse(bs, bs->file, flags) == 0) {
 s->desc_offset = 0x200;
-/* try to open parent images, if exist */
-ret = vmdk_parent_open(bs);
+} else {
+ret = vmdk_open_desc_file(bs, flags, 0);
 if (ret) {
-vmdk_free_extents(bs);
-return ret;
+goto fail;
 }
-s->parent_cid = vmdk_read_cid(bs, 1);
-return 0;
-} else {
-return vmdk_open_desc_file(bs, flags, 0);
 }
+/* try to open parent images, if exist */
+ret = vmdk_parent_open(bs);
+if (ret) {
+goto fail;
+}
+s->parent_cid = vmdk_read_cid(bs, 1);
+return ret;
+
+fail:
+vmdk_free_extents(bs);
+return ret;
 }
 
 static int get_whole_cluster(BlockDriverState *bs,
-- 
1.7.6





[Qemu-devel] [PATCH 1/1 V6] qemu: fix improper nmi emulation

2011-10-19 Thread Lai Jiangshan
On 10/19/2011 06:57 PM, Jan Kiszka wrote:

>>>
>>> Looks OK to me.
>>>
>>> Please don't forget to bake a qemu-only patch for those bits that apply
>>> to upstream as well (ie. the user space APIC path).
>>>
>>> Jan
>>>
>>
>> I did forget it.
>> Did you mean we need to add "#ifdef KVM_CAP_IRQCHIP" back?
> 
> No. I meant basically your patch minus the kvm_in_kernel_irqchip code
> paths, applicable against current qemu.git. Those paths will be re-added
> (slightly differently) when upstream gains that support. I'm working on
> a basic version an will incorporate the logic if your qemu patch is
> already available.
> 
> Jan
> 

Patch for qemu.git

From: Lai Jiangshan 

Currently, NMI interrupt is blindly sent to all the vCPUs when NMI
button event happens. This doesn't properly emulate real hardware on
which NMI button event triggers LINT1. Because of this, NMI is sent to
the processor even when LINT1 is masked in LVT. For example, this
causes the problem that kdump initiated by NMI sometimes doesn't work
on KVM, because kdump assumes NMI is masked on CPUs other than CPU0.

With this patch, inject-nmi request is handled as delivering LINT1.

Signed-off-by: Lai Jiangshan 
Reported-by: Kenji Kaneshige 
---
 hw/apic.c |7 +++
 hw/apic.h |1 +
 monitor.c |6 +-
 3 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/hw/apic.c b/hw/apic.c
index 8289eef..c8dc997 100644
--- a/hw/apic.c
+++ b/hw/apic.c
@@ -205,6 +205,13 @@ void apic_deliver_pic_intr(DeviceState *d, int level)
 }
 }
 
+void apic_deliver_nmi(DeviceState *d)
+{
+APICState *s = DO_UPCAST(APICState, busdev.qdev, d);
+
+apic_local_deliver(s, APIC_LVT_LINT1);
+}
+
 #define foreach_apic(apic, deliver_bitmask, code) \
 {\
 int __i, __j, __mask;\
diff --git a/hw/apic.h b/hw/apic.h
index a5c910f..a62d83b 100644
--- a/hw/apic.h
+++ b/hw/apic.h
@@ -8,6 +8,7 @@ void apic_deliver_irq(uint8_t dest, uint8_t dest_mode, uint8_t 
delivery_mode,
   uint8_t vector_num, uint8_t trigger_mode);
 int apic_accept_pic_intr(DeviceState *s);
 void apic_deliver_pic_intr(DeviceState *s, int level);
+void apic_deliver_nmi(DeviceState *d);
 int apic_get_interrupt(DeviceState *s);
 void apic_reset_irq_delivered(void);
 int apic_get_irq_delivered(void);
diff --git a/monitor.c b/monitor.c
index ffda0fe..144099a 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2501,7 +2501,11 @@ static int do_inject_nmi(Monitor *mon, const QDict 
*qdict, QObject **ret_data)
 CPUState *env;
 
 for (env = first_cpu; env != NULL; env = env->next_cpu) {
-cpu_interrupt(env, CPU_INTERRUPT_NMI);
+if (!env->apic_state) {
+cpu_interrupt(env, CPU_INTERRUPT_NMI);
+} else {
+apic_deliver_nmi(env->apic_state);
+}
 }
 
 return 0;



[Qemu-devel] [PATCH 2/8] vmdk: fix return values of vmdk_parent_open

2011-10-19 Thread Paolo Bonzini
While vmdk_open_desc_file (touched by the patch) correctly changed -1
to -EINVAL, vmdk_open did not.  Fix it directly in vmdk_parent_open.

Signed-off-by: Paolo Bonzini 
---
 block/vmdk.c |   11 ++-
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index 5d16ec4..21566eb 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -286,7 +286,7 @@ static int vmdk_parent_open(BlockDriverState *bs)
 
 desc[DESC_SIZE] = '\0';
 if (bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE) != DESC_SIZE) {
-return -1;
+return -EINVAL;
 }
 
 p_name = strstr(desc, "parentFileNameHint");
@@ -296,10 +296,10 @@ static int vmdk_parent_open(BlockDriverState *bs)
 p_name += sizeof("parentFileNameHint") + 1;
 end_name = strchr(p_name, '\"');
 if (end_name == NULL) {
-return -1;
+return -EINVAL;
 }
 if ((end_name - p_name) > sizeof(bs->backing_file) - 1) {
-return -1;
+return -EINVAL;
 }
 
 pstrcpy(bs->backing_file, end_name - p_name + 1, p_name);
@@ -629,9 +629,10 @@ static int vmdk_open_desc_file(BlockDriverState *bs, int 
flags,
 }
 
 /* try to open parent images, if exist */
-if (vmdk_parent_open(bs)) {
+ret = vmdk_parent_open(bs);
+if (ret) {
 vmdk_free_extents(bs);
-return -EINVAL;
+return ret;
 }
 s->parent_cid = vmdk_read_cid(bs, 1);
 return 0;
-- 
1.7.6





[Qemu-devel] [PATCH V2 01/10] configure: Introduce --enable-xen-pci-passthrough.

2011-10-19 Thread Anthony PERARD
Signed-off-by: Anthony PERARD 
---
 Makefile.target |2 ++
 configure   |   21 +
 2 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/Makefile.target b/Makefile.target
index 417f23e..c518103 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -208,6 +208,8 @@ obj-$(CONFIG_NO_XEN) += xen-stub.o
 
 obj-i386-$(CONFIG_XEN) += xen_platform.o
 
+# Xen PCI Passthrough
+
 # Inter-VM PCI shared memory
 CONFIG_IVSHMEM =
 ifeq ($(CONFIG_KVM), y)
diff --git a/configure b/configure
index 9b4fe34..63c5c30 100755
--- a/configure
+++ b/configure
@@ -127,6 +127,7 @@ vnc_png=""
 vnc_thread="no"
 xen=""
 xen_ctrl_version=""
+xen_pci_passthrough=""
 linux_aio=""
 attr=""
 xfs=""
@@ -641,6 +642,10 @@ for opt do
   ;;
   --enable-xen) xen="yes"
   ;;
+  --disable-xen-pci-passthrough) xen_pci_passthrough="no"
+  ;;
+  --enable-xen-pci-passthrough) xen_pci_passthrough="yes"
+  ;;
   --disable-brlapi) brlapi="no"
   ;;
   --enable-brlapi) brlapi="yes"
@@ -979,6 +984,8 @@ echo "   (affects only QEMU, not 
qemu-img)"
 echo "  --enable-mixemu  enable mixer emulation"
 echo "  --disable-xendisable xen backend driver support"
 echo "  --enable-xen enable xen backend driver support"
+echo "  --disable-xen-pci-passthrough"
+echo "  --enable-xen-pci-passthrough"
 echo "  --disable-brlapi disable BrlAPI"
 echo "  --enable-brlapi  enable BrlAPI"
 echo "  --disable-vnc-tlsdisable TLS encryption for VNC server"
@@ -1342,6 +1349,17 @@ EOF
   fi
 fi
 
+if test "$xen_pci_passthrough" != "no"; then
+  if test "$xen" = "yes" -a "$linux" = "yes"; then
+xen_pci_passthrough=yes
+  else
+if test "$xen_pci_passthrough" = "yes"; then
+  feature_not_found "Xen PCI Passthrough without Xen or not on linux"
+fi
+xen_pci_passthrough=no
+  fi
+fi
+
 ##
 # pkg-config probe
 
@@ -3365,6 +3383,9 @@ case "$target_arch2" in
 if test "$xen" = "yes" -a "$target_softmmu" = "yes" ; then
   target_phys_bits=64
   echo "CONFIG_XEN=y" >> $config_target_mak
+  if test "$xen_pci_passthrough" = yes; then
+echo "CONFIG_XEN_PCI_PASSTHROUGH=y" >> "$config_target_mak"
+  fi
 else
   echo "CONFIG_NO_XEN=y" >> $config_target_mak
 fi
-- 
Anthony PERARD




[Qemu-devel] [PATCH 1/8] vpc: detect floppy disk geometries

2011-10-19 Thread Paolo Bonzini
Converting a floppy image from RAW to VPC and back will generate
a zero-padded file of the wrong size, because the geometry is not
computed correctly.  Special case floppy disk images, handling
standard MS-DOS capacities (160/180/320/360 for low density
5.25" disks, 1200 for high density 5.25" disks, 720/1440/2880
for 3.5" disks).

Signed-off-by: Paolo Bonzini 
---
 block/vpc.c |8 
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/block/vpc.c b/block/vpc.c
index cb6c570..549a632 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -463,6 +463,14 @@ static int calculate_geometry(int64_t total_sectors, 
uint16_t* cyls,
 {
 uint32_t cyls_times_heads;
 
+if (total_sectors <= 5760) {
+/* Floppy disk geometry */
+*heads = total_sectors < 640 ? 1 : 2; /* 1 = single side 5.25" */
+*cyls = total_sectors < 1440 ? 40 : 80;  /* 40 = low density 5.25" */
+*secs_per_cyl = total_sectors / *heads / *cyls;
+return 0;
+}
+
 if (total_sectors > 65535 * 16 * 255)
 return -EFBIG;
 
-- 
1.7.6





[Qemu-devel] [PATCH 8/8] block: change discard to co_discard

2011-10-19 Thread Paolo Bonzini
Since coroutine operation is now mandatory, convert both bdrv_discard
implementations to coroutines.  For qcow2, this means taking the lock
around the operation.  raw-posix remains synchronous.

The bdrv_discard callback is then unused and can be eliminated.

Signed-off-by: Paolo Bonzini 
---
 block.c   |2 --
 block/qcow2.c |   12 +---
 block/raw-posix.c |4 ++--
 block_int.h   |2 --
 4 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/block.c b/block.c
index 81fb709..70aab63 100644
--- a/block.c
+++ b/block.c
@@ -2962,8 +2962,6 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, 
int64_t sector_num,
 qemu_coroutine_yield();
 return co.ret;
 }
-} else if (bs->drv->bdrv_discard) {
-return bs->drv->bdrv_discard(bs, sector_num, nb_sectors);
 } else {
 return 0;
 }
diff --git a/block/qcow2.c b/block/qcow2.c
index 3758dbf..0832d11 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -978,11 +978,17 @@ static int qcow2_make_empty(BlockDriverState *bs)
 return 0;
 }
 
-static int qcow2_discard(BlockDriverState *bs, int64_t sector_num,
-int nb_sectors)
+static coroutine_fn int qcow2_co_discard(BlockDriverState *bs,
+int64_t sector_num, int nb_sectors)
 {
-return qcow2_discard_clusters(bs, sector_num << BDRV_SECTOR_BITS,
+int ret;
+BDRVQcowState *s = bs->opaque;
+
+qemu_co_mutex_lock(&s->lock);
+ret = qcow2_discard_clusters(bs, sector_num << BDRV_SECTOR_BITS,
 nb_sectors);
+qemu_co_mutex_unlock(&s->lock);
+return ret;
 }
 
 static int qcow2_truncate(BlockDriverState *bs, int64_t offset)
@@ -1232,7 +1238,7 @@ static BlockDriver bdrv_qcow2 = {
 .bdrv_co_writev = qcow2_co_writev,
 .bdrv_co_flush  = qcow2_co_flush,
 
-.bdrv_discard   = qcow2_discard,
+.bdrv_co_discard= qcow2_co_discard,
 .bdrv_truncate  = qcow2_truncate,
 .bdrv_write_compressed  = qcow2_write_compressed,
 
diff --git a/block/raw-posix.c b/block/raw-posix.c
index afcb4c1..cf337f7 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -602,7 +602,8 @@ static int xfs_discard(BDRVRawState *s, int64_t sector_num, 
int nb_sectors)
 }
 #endif
 
-static int raw_discard(BlockDriverState *bs, int64_t sector_num, int 
nb_sectors)
+static coroutine_fn int raw_co_discard(BlockDriverState *bs,
+int64_t sector_num, int nb_sectors)
 {
 #ifdef CONFIG_XFS
 BDRVRawState *s = bs->opaque;
@@ -632,7 +632,7 @@ static BlockDriver bdrv_file = {
 .bdrv_file_open = raw_open,
 .bdrv_close = raw_close,
 .bdrv_create = raw_create,
-.bdrv_discard = raw_discard,
+.bdrv_co_discard = raw_co_discard,
 
 .bdrv_aio_readv = raw_aio_readv,
 .bdrv_aio_writev = raw_aio_writev,
diff --git a/block_int.h b/block_int.h
index bc3b07e..dac00f5 100644
--- a/block_int.h
+++ b/block_int.h
@@ -62,8 +62,6 @@ struct BlockDriver {
   const uint8_t *buf, int nb_sectors);
 void (*bdrv_close)(BlockDriverState *bs);
 int (*bdrv_create)(const char *filename, QEMUOptionParameter *options);
-int (*bdrv_discard)(BlockDriverState *bs, int64_t sector_num,
-int nb_sectors);
 int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num,
  int nb_sectors, int *pnum);
 int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
-- 
1.7.6




[Qemu-devel] [PATCH 4/8] block: add a Rwlock to synchronous read/write drivers

2011-10-19 Thread Paolo Bonzini
The big conversion of bdrv_read/write to coroutines caused the two
homonymous callbacks in BlockDriver to become reentrant.  It goes
like this:

1) bdrv_read is now called in a coroutine, and calls bdrv_read or
bdrv_pread.

2) the nested bdrv_read goes through the fast path in bdrv_rw_co_entry;

3) in the common case when the protocol is file, bdrv_co_do_readv calls
bdrv_co_readv_em (and from here goes to bdrv_co_io_em), which yields
until the AIO operation is complete;

4) if bdrv_read had been called from a bottom half, the main loop
is free to iterate again: a device model or another bottom half
can then come and call bdrv_read again.

This applies to all four of read/write/flush/discard.  It would also
apply to is_allocated, but it is not used from within coroutines:
besides qemu-img.c and qemu-io.c, which operate synchronously, the
only user is the monitor.  Copy-on-read will introduce a use in the
block layer, and will require converting it.

The solution is "simply" to convert all drivers to coroutines!  We
have nothing to do for the read-only drivers.  For the others, we
add a Rwlock that is taken around affected operations.

Signed-off-by: Paolo Bonzini 
---
 block/cow.c   |2 ++
 block/nbd.c   |2 ++
 block/vmdk.c  |2 ++
 block/vpc.c   |2 ++
 block/vvfat.c |2 ++
 5 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/block/cow.c b/block/cow.c
index 4cf543c..d27e0aa 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -42,6 +42,7 @@ struct cow_header_v2 {
 };
 
 typedef struct BDRVCowState {
+CoRwlock lock;
 int64_t cow_sectors_offset;
 } BDRVCowState;
 
@@ -84,6 +85,7 @@ static int cow_open(BlockDriverState *bs, int flags)
 
 bitmap_size = ((bs->total_sectors + 7) >> 3) + sizeof(cow_header);
 s->cow_sectors_offset = (bitmap_size + 511) & ~511;
+qemu_co_rwlock_init(&s->lock);
 return 0;
  fail:
 return -1;
diff --git a/block/nbd.c b/block/nbd.c
index 76f04d8..ec8f086 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -47,6 +47,7 @@
 #endif
 
 typedef struct BDRVNBDState {
+CoRwlock lock;
 int sock;
 uint32_t nbdflags;
 off_t size;
@@ -175,6 +176,7 @@ static int nbd_open(BlockDriverState *bs, const char* 
filename, int flags)
  */
 result = nbd_establish_connection(bs);
 
+qemu_co_rwlock_init(&s->lock);
 return result;
 }
 
diff --git a/block/vmdk.c b/block/vmdk.c
index 12b38d2..6afd53e 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -90,6 +90,7 @@ typedef struct VmdkExtent {
 } VmdkExtent;
 
 typedef struct BDRVVmdkState {
+CoRwlock lock;
 int desc_offset;
 bool cid_updated;
 uint32_t parent_cid;
@@ -644,6 +645,7 @@ static int vmdk_open(BlockDriverState *bs, int flags)
 goto fail;
 }
 s->parent_cid = vmdk_read_cid(bs, 1);
+qemu_co_rwlock_init(&s->lock);
 return ret;
 
 fail:
diff --git a/block/vpc.c b/block/vpc.c
index 549a632..7220488 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -110,6 +110,7 @@ struct vhd_dyndisk_header {
 };
 
 typedef struct BDRVVPCState {
+CoRwlock lock;
 uint8_t footer_buf[HEADER_SIZE];
 uint64_t free_data_block_offset;
 int max_table_entries;
@@ -226,6 +227,7 @@ static int vpc_open(BlockDriverState *bs, int flags)
 s->last_pagetable = -1;
 #endif
 
+qemu_co_rwlock_init(&s->lock);
 return 0;
  fail:
 return err;
diff --git a/block/vvfat.c b/block/vvfat.c
index c567697..08a72ee 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -317,6 +317,7 @@ static void print_mapping(const struct mapping_t* mapping);
 /* here begins the real VVFAT driver */
 
 typedef struct BDRVVVFATState {
+CoRwlock lock;
 BlockDriverState* bs; /* pointer to parent */
 unsigned int first_sectors_number; /* 1 for a single partition, 0x40 for a 
disk with partition table */
 unsigned char first_sectors[0x40*0x200];
@@ -1063,6 +1064,7 @@ DLOG(if (stderr == NULL) {
 }
 
 //assert(is_consistent(s));
+qemu_co_rwlock_init(&s->lock);
 return 0;
 }
 
-- 
1.7.6





Re: [Qemu-devel] [PATCH V2 01/10] configure: Introduce --enable-xen-pci-passthrough.

2011-10-19 Thread Anthony PERARD
On Wed, Oct 19, 2011 at 15:48, Peter Maydell  wrote:
> On 19 October 2011 14:56, Anthony PERARD  wrote:
>> +if test "$xen_pci_passthrough" != "no"; then
>> +  if test "$xen" = "yes" -a "$linux" = "yes"; then
>> +    xen_pci_passthrough=yes
>> +  else
>> +    if test "$xen_pci_passthrough" = "yes"; then
>> +      feature_not_found "Xen PCI Passthrough without Xen or not on linux"
>> +    fi
>> +    xen_pci_passthrough=no
>> +  fi
>> +fi
>
> The -a flag to test is obsolete -- don't use it in new code.

ok, I'll just replace it by "&& test"

> This is a bit of a misuse of the feature_not_found function IMHO.
> (Also, Linux needs a capital letter.)

Yes, probably this message will be more useful:
echo "ERROR: User requested feature Xen PCI Passthrough"
echo "ERROR: but this feature require /sys from Linux"

Thanks,

-- 
Anthony PERARD



[Qemu-devel] [PATCH 5/8] block: take lock around bdrv_read implementations

2011-10-19 Thread Paolo Bonzini
This does the first part of the conversion to coroutines, by
wrapping bdrv_read implementations to take the read side of the
rwlock.

Drivers that implement bdrv_read rather than bdrv_co_readv can
then benefit from asynchronous operation (at least if the underlying
protocol supports it, which is not the case for raw-win32), even
though they still operate with a bounce buffer.

raw-win32 does not need the lock, because it cannot yield.
nbd also doesn't probably, but better be safe.

Signed-off-by: Paolo Bonzini 
---
 block/cow.c   |   13 -
 block/nbd.c   |   13 -
 block/vmdk.c  |   13 -
 block/vpc.c   |   13 -
 block/vvfat.c |   13 -
 5 files changed, 60 insertions(+), 5 deletions(-)

diff --git a/block/cow.c b/block/cow.c
index d27e0aa..9571549 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -201,6 +201,17 @@ static int cow_read(BlockDriverState *bs, int64_t 
sector_num,
 return 0;
 }
 
+static coroutine_fn int cow_co_read(BlockDriverState *bs, int64_t sector_num,
+uint8_t *buf, int nb_sectors)
+{
+int ret;
+BDRVCowState *s = bs->opaque;
+qemu_co_rwlock_rdlock(&s->lock);
+ret = cow_read(bs, sector_num, buf, nb_sectors);
+qemu_co_rwlock_unlock(&s->lock);
+return ret;
+}
+
 static int cow_write(BlockDriverState *bs, int64_t sector_num,
  const uint8_t *buf, int nb_sectors)
 {
@@ -308,7 +319,7 @@ static BlockDriver bdrv_cow = {
 .instance_size = sizeof(BDRVCowState),
 .bdrv_probe= cow_probe,
 .bdrv_open = cow_open,
-.bdrv_read = cow_read,
+.bdrv_read = cow_co_read,
 .bdrv_write= cow_write,
 .bdrv_close= cow_close,
 .bdrv_create   = cow_create,
diff --git a/block/nbd.c b/block/nbd.c
index ec8f086..f8fed92 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -240,6 +240,17 @@ static int nbd_write(BlockDriverState *bs, int64_t 
sector_num,
 return 0;
 }
 
+static coroutine_fn int nbd_co_read(BlockDriverState *bs, int64_t sector_num,
+uint8_t *buf, int nb_sectors)
+{
+int ret;
+BDRVNBDState *s = bs->opaque;
+qemu_co_rwlock_rdlock(&s->lock);
+ret = nbd_read(bs, sector_num, buf, nb_sectors);
+qemu_co_rwlock_unlock(&s->lock);
+return ret;
+}
+
 static void nbd_close(BlockDriverState *bs)
 {
 BDRVNBDState *s = bs->opaque;
@@ -260,7 +271,7 @@ static BlockDriver bdrv_nbd = {
 .format_name   = "nbd",
 .instance_size = sizeof(BDRVNBDState),
 .bdrv_file_open= nbd_open,
-.bdrv_read = nbd_read,
+.bdrv_read = nbd_co_read,
 .bdrv_write= nbd_write,
 .bdrv_close= nbd_close,
 .bdrv_getlength= nbd_getlength,
diff --git a/block/vmdk.c b/block/vmdk.c
index 6afd53e..ff78e25 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1022,6 +1022,17 @@ static int vmdk_read(BlockDriverState *bs, int64_t 
sector_num,
 return 0;
 }
 
+static coroutine_fn int vmdk_co_read(BlockDriverState *bs, int64_t sector_num,
+ uint8_t *buf, int nb_sectors)
+{
+int ret;
+BDRVVmdkState *s = bs->opaque;
+qemu_co_rwlock_rdlock(&s->lock);
+ret = vmdk_read(bs, sector_num, buf, nb_sectors);
+qemu_co_rwlock_unlock(&s->lock);
+return ret;
+}
+
 static int vmdk_write(BlockDriverState *bs, int64_t sector_num,
  const uint8_t *buf, int nb_sectors)
 {
@@ -1540,7 +1551,7 @@ static BlockDriver bdrv_vmdk = {
 .instance_size  = sizeof(BDRVVmdkState),
 .bdrv_probe = vmdk_probe,
 .bdrv_open  = vmdk_open,
-.bdrv_read  = vmdk_read,
+.bdrv_read  = vmdk_co_read,
 .bdrv_write = vmdk_write,
 .bdrv_close = vmdk_close,
 .bdrv_create= vmdk_create,
diff --git a/block/vpc.c b/block/vpc.c
index 7220488..e805769 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -409,6 +409,17 @@ static int vpc_read(BlockDriverState *bs, int64_t 
sector_num,
 return 0;
 }
 
+static coroutine_fn int vpc_co_read(BlockDriverState *bs, int64_t sector_num,
+uint8_t *buf, int nb_sectors)
+{
+int ret;
+BDRVVPCState *s = bs->opaque;
+qemu_co_rwlock_rdlock(&s->lock);
+ret = vpc_read(bs, sector_num, buf, nb_sectors);
+qemu_co_rwlock_unlock(&s->lock);
+return ret;
+}
+
 static int vpc_write(BlockDriverState *bs, int64_t sector_num,
 const uint8_t *buf, int nb_sectors)
 {
@@ -649,7 +660,7 @@ static BlockDriver bdrv_vpc = {
 .instance_size  = sizeof(BDRVVPCState),
 .bdrv_probe = vpc_probe,
 .bdrv_open  = vpc_open,
-.bdrv_read  = vpc_read,
+.bdrv_read  = vpc_co_read,
 .bdrv_write = vpc_write,
 .bdrv_flush = vpc_flush,
 .bdrv_close = vpc_close,
diff --git a/block/vvfat.c b/block/vvfat.c
index 08a72ee..f1d94ad 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@

[Qemu-devel] [PATCH 7/8] block: change flush to co_flush

2011-10-19 Thread Paolo Bonzini
Since coroutine operation is now mandatory, convert all bdrv_flush
implementations to coroutines.  For qcow2, this means taking the lock.
Other implementations are simpler and just forward bdrv_flush to the
underlying protocol, so they can avoid the lock.

The bdrv_flush callback is then unused and can be eliminated.

Signed-off-by: Paolo Bonzini 
---
 block.c   |2 --
 block/cow.c   |6 +++---
 block/qcow.c  |   11 +--
 block/qcow2.c |   14 +++---
 block/raw-win32.c |4 ++--
 block/rbd.c   |4 ++--
 block/vdi.c   |6 +++---
 block/vmdk.c  |8 
 block/vpc.c   |6 +++---
 block_int.h   |1 -
 10 files changed, 29 insertions(+), 33 deletions(-)

diff --git a/block.c b/block.c
index 28508f2..81fb709 100644
--- a/block.c
+++ b/block.c
@@ -2892,8 +2892,6 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs)
 qemu_coroutine_yield();
 return co.ret;
 }
-} else if (bs->drv->bdrv_flush) {
-return bs->drv->bdrv_flush(bs);
 } else {
 /*
  * Some block drivers always operate in either writethrough or unsafe
diff --git a/block/cow.c b/block/cow.c
index 61eaca2..77989e8 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -306,9 +306,9 @@ exit:
 return ret;
 }
 
-static int cow_flush(BlockDriverState *bs)
+static coroutine_fn int cow_co_flush(BlockDriverState *bs)
 {
-return bdrv_flush(bs->file);
+return bdrv_co_flush(bs->file);
 }
 
 static QEMUOptionParameter cow_create_options[] = {
@@ -334,7 +334,7 @@ static BlockDriver bdrv_cow = {
 .bdrv_write= cow_co_write,
 .bdrv_close= cow_close,
 .bdrv_create   = cow_create,
-.bdrv_flush= cow_flush,
+.bdrv_co_flush = cow_co_flush,
 .bdrv_is_allocated = cow_is_allocated,
 
 .create_options = cow_create_options,
diff --git a/block/qcow.c b/block/qcow.c
index f93e3eb..61f73d6 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -781,10 +781,9 @@ static int qcow_write_compressed(BlockDriverState *bs, 
int64_t sector_num,
 return 0;
 }
 
-static BlockDriverAIOCB *qcow_aio_flush(BlockDriverState *bs,
-BlockDriverCompletionFunc *cb, void *opaque)
+static coroutine_fn int qcow_co_flush(BlockDriverState *bs)
 {
-return bdrv_aio_flush(bs->file, cb, opaque);
+return bdrv_co_flush(bs->file);
 }
 
 static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
@@ -824,9 +823,9 @@ static BlockDriver bdrv_qcow = {
 .bdrv_is_allocated = qcow_is_allocated,
 .bdrv_set_key  = qcow_set_key,
 .bdrv_make_empty   = qcow_make_empty,
-.bdrv_co_readv  = qcow_co_readv,
-.bdrv_co_writev = qcow_co_writev,
-.bdrv_aio_flush= qcow_aio_flush,
+.bdrv_co_readv  = qcow_co_readv,
+.bdrv_co_writev = qcow_co_writev,
+.bdrv_co_flush = qcow_co_flush,
 .bdrv_write_compressed = qcow_write_compressed,
 .bdrv_get_info = qcow_get_info,
 
diff --git a/block/qcow2.c b/block/qcow2.c
index 4dc980c..3758dbf 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1092,24 +1092,24 @@ static int qcow2_write_compressed(BlockDriverState *bs, 
int64_t sector_num,
 return 0;
 }
 
-static BlockDriverAIOCB *qcow2_aio_flush(BlockDriverState *bs,
- BlockDriverCompletionFunc *cb,
- void *opaque)
+static int qcow2_co_flush(BlockDriverState *bs)
 {
 BDRVQcowState *s = bs->opaque;
 int ret;
 
+qemu_co_mutex_lock(&s->lock);
 ret = qcow2_cache_flush(bs, s->l2_table_cache);
 if (ret < 0) {
-return NULL;
+return ret;
 }
 
 ret = qcow2_cache_flush(bs, s->refcount_block_cache);
 if (ret < 0) {
-return NULL;
+return ret;
 }
+qemu_co_mutex_unlock(&s->lock);
 
-return bdrv_aio_flush(bs->file, cb, opaque);
+return bdrv_co_flush(bs->file);
 }
 
 static int64_t qcow2_vm_state_offset(BDRVQcowState *s)
@@ -1230,7 +1230,7 @@ static BlockDriver bdrv_qcow2 = {
 
 .bdrv_co_readv  = qcow2_co_readv,
 .bdrv_co_writev = qcow2_co_writev,
-.bdrv_aio_flush = qcow2_aio_flush,
+.bdrv_co_flush  = qcow2_co_flush,
 
 .bdrv_discard   = qcow2_discard,
 .bdrv_truncate  = qcow2_truncate,
diff --git a/block/raw-win32.c b/block/raw-win32.c
index b7dd357..2fa7437 100644
--- a/block/raw-win32.c
+++ b/block/raw-win32.c
@@ -281,7 +281,7 @@ static BlockDriver bdrv_file = {
 .bdrv_file_open= raw_open,
 .bdrv_close= raw_close,
 .bdrv_create   = raw_create,
-.bdrv_flush= raw_flush,
+.bdrv_co_flush = raw_flush,
 .bdrv_read = raw_read,
 .bdrv_write= raw_write,
 .bdrv_truncate = raw_truncate,
@@ -409,7 +409,7 @@ static BlockDriver bdrv_host_device = {
 .bdrv_probe_device = hdev_probe_device,
 .bdrv_file_open= hdev_open,
 .bdrv_close 

[Qemu-devel] [PATCH 0/8] finish coroutinization of drivers

2011-10-19 Thread Paolo Bonzini
Drivers that only implement the bdrv_read and bdrv_write callbacks
were unwillingly converted to be reentrant when bdrv_read and
bdrv_write were changed to always create coroutines.  So,
we need locks aroudn read and write operations.

This series does this (patches 4-6) and removes the flush/discard
callbacks that, as it turns out, are really duplicates of co_flush
and co_discard (patches 7-8).

Patches 1-3 are fixes/cleanups that I discovered while testing.


Paolo Bonzini (8):
  vpc: detect floppy disk geometries
  vmdk: fix return values of vmdk_parent_open
  vmdk: clean up open
  block: add a Rwlock to synchronous read/write drivers
  block: take lock around bdrv_read implementations
  block: take lock around bdrv_write implementations
  block: change flush to co_flush
  block: change discard to co_discard

 block.c   |4 ---
 block/cow.c   |   34 +++---
 block/nbd.c   |   28 +-
 block/qcow.c  |   11 +++
 block/qcow2.c |   26 +++---
 block/raw-posix.c |4 +-
 block/raw-win32.c |4 +-
 block/rbd.c   |4 +-
 block/vdi.c   |6 ++--
 block/vmdk.c  |   78 
 block/vpc.c   |   42 +---
 block/vvfat.c |   28 +-
 block_int.h   |3 --
 13 files changed, 196 insertions(+), 76 deletions(-)

-- 
1.7.6




[Qemu-devel] [PATCH V2 10/10] Introduce Xen PCI Passthrough, MSI (3/3)

2011-10-19 Thread Anthony PERARD
From: Jiang Yunhong 

Signed-off-by: Jiang Yunhong 
Signed-off-by: Shan Haitao 
Signed-off-by: Anthony PERARD 
---
 Makefile.target  |1 +
 hw/apic-msidef.h |2 +
 hw/xen_pci_passthrough.h |   20 ++
 hw/xen_pci_passthrough_msi.c |  667 ++
 4 files changed, 690 insertions(+), 0 deletions(-)
 create mode 100644 hw/xen_pci_passthrough_msi.c

diff --git a/Makefile.target b/Makefile.target
index 875a507..76530d9 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -213,6 +213,7 @@ obj-i386-$(CONFIG_XEN_PCI_PASSTHROUGH) += host-pci-device.o
 obj-i386-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pci_passthrough.o
 obj-i386-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pci_passthrough_helpers.o
 obj-i386-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pci_passthrough_config_init.o
+obj-i386-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pci_passthrough_msi.o
 
 # Inter-VM PCI shared memory
 CONFIG_IVSHMEM =
diff --git a/hw/apic-msidef.h b/hw/apic-msidef.h
index 3182f0b..6e2eb71 100644
--- a/hw/apic-msidef.h
+++ b/hw/apic-msidef.h
@@ -22,6 +22,8 @@
 
 #define MSI_ADDR_DEST_MODE_SHIFT2
 
+#define MSI_ADDR_REDIRECTION_SHIFT  3
+
 #define MSI_ADDR_DEST_ID_SHIFT  12
 #define  MSI_ADDR_DEST_ID_MASK  0x000
 
diff --git a/hw/xen_pci_passthrough.h b/hw/xen_pci_passthrough.h
index 7cb563f..5f404b0 100644
--- a/hw/xen_pci_passthrough.h
+++ b/hw/xen_pci_passthrough.h
@@ -63,6 +63,10 @@ typedef int (*conf_byte_restore)
 
 #define PT_BAR_ALLF0x  /* BAR ALLF value */
 
+/* MSI-X */
+#define PT_MSI_FLAG_UNINIT 0x1000
+#define PT_MSI_FLAG_MAPPED 0x2000
+
 
 typedef enum {
 GRP_TYPE_HARDWIRED = 0, /* 0 Hardwired reg group */
@@ -257,4 +261,20 @@ static inline uint8_t pci_read_intx(XenPCIPassthroughState 
*s)
 }
 uint8_t pci_intx(XenPCIPassthroughState *ptdev);
 
+/* MSI/MSI-X */
+void pt_msi_set_enable(XenPCIPassthroughState *s, int en);
+int pt_msi_setup(XenPCIPassthroughState *s);
+int pt_msi_update(XenPCIPassthroughState *d);
+void pt_msi_disable(XenPCIPassthroughState *s);
+int pt_enable_msi_translate(XenPCIPassthroughState *s);
+void pt_disable_msi_translate(XenPCIPassthroughState *s);
+
+int pt_msix_init(XenPCIPassthroughState *s, int pos);
+void pt_msix_delete(XenPCIPassthroughState *s);
+int pt_msix_update(XenPCIPassthroughState *s);
+int pt_msix_update_remap(XenPCIPassthroughState *s, int bar_index);
+void pt_msix_disable(XenPCIPassthroughState *s);
+int pt_add_msix_mapping(XenPCIPassthroughState *s, int bar_index);
+int pt_remove_msix_mapping(XenPCIPassthroughState *s, int bar_index);
+
 #endif /* !QEMU_HW_XEN_PCI_PASSTHROUGH_H */
diff --git a/hw/xen_pci_passthrough_msi.c b/hw/xen_pci_passthrough_msi.c
new file mode 100644
index 000..533aef4
--- /dev/null
+++ b/hw/xen_pci_passthrough_msi.c
@@ -0,0 +1,667 @@
+/*
+ * Copyright (c) 2007, Intel Corporation.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ * Jiang Yunhong 
+ *
+ * This file implements direct PCI assignment to a HVM guest
+ */
+
+#include 
+
+#include "xen_backend.h"
+#include "xen_pci_passthrough.h"
+#include "apic-msidef.h"
+
+
+#define AUTO_ASSIGN -1
+
+/* shift count for gflags */
+#define GFLAGS_SHIFT_DEST_ID0
+#define GFLAGS_SHIFT_RH 8
+#define GFLAGS_SHIFT_DM 9
+#define GLFAGS_SHIFT_DELIV_MODE 12
+#define GLFAGS_SHIFT_TRG_MODE   15
+
+
+void pt_msi_set_enable(XenPCIPassthroughState *s, int en)
+{
+uint16_t val = 0;
+uint32_t address = 0;
+PT_LOG("enable: %i\n", en);
+
+if (!s->msi) {
+return;
+}
+
+address = s->msi->ctrl_offset;
+if (!address) {
+return;
+}
+
+val = host_pci_get_word(s->real_device, address);
+val &= ~PCI_MSI_FLAGS_ENABLE;
+val |= en & PCI_MSI_FLAGS_ENABLE;
+host_pci_set_word(s->real_device, address, val);
+
+PT_LOG("done, address: %#x, val: %#x\n", address, val);
+}
+
+static void msix_set_enable(XenPCIPassthroughState *s, int en)
+{
+uint16_t val = 0;
+uint32_t address = 0;
+
+if (!s->msix) {
+return;
+}
+
+address = s->msix->ctrl_offset;
+if (!address) {
+return;
+}
+
+val = host_pci_get_word(s->real_device, address);
+val &= ~PCI_MSIX_FLAGS_ENABLE;
+if (en) {
+val |= PCI_MSIX_FLAGS_ENABLE;
+}
+host_pci_set_word(s->real_device, address, val);
+}
+
+/*/
+/* MSI virtuailization functions */
+
+/*
+ * setup physical msi, but didn't enable it
+ */
+int pt_msi_setup(XenPCIPassthroughState *s)
+{
+int pirq = -1;
+uint8_t gvec = 0;
+
+if (!(s->msi->flags & PT_MSI_FLAG_UNINIT)) {
+PT_LOG("Error: setup physical after initialized??\n");
+return -1;
+}
+
+gvec = s->msi->data & 0xFF;
+if (!gvec) {
+/* if gvec is 0, the guest is asking for a particular pirq that
+ * is passed as dest_id */
+

[Qemu-devel] [PATCH V2 05/10] pci_regs: Fix value of PCI_EXP_TYPE_RC_EC.

2011-10-19 Thread Anthony PERARD
Value check in PCI Express Base Specification rev 1.1

Signed-off-by: Anthony PERARD 
---
 hw/pci_regs.h |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/pci_regs.h b/hw/pci_regs.h
index e8357c3..6b42515 100644
--- a/hw/pci_regs.h
+++ b/hw/pci_regs.h
@@ -393,7 +393,7 @@
 #define  PCI_EXP_TYPE_DOWNSTREAM 0x6   /* Downstream Port */
 #define  PCI_EXP_TYPE_PCI_BRIDGE 0x7   /* PCI/PCI-X Bridge */
 #define  PCI_EXP_TYPE_RC_END   0x9 /* Root Complex Integrated Endpoint */
-#define  PCI_EXP_TYPE_RC_EC0x10/* Root Complex Event Collector */
+#define  PCI_EXP_TYPE_RC_EC 0xa /* Root Complex Event Collector */
 #define PCI_EXP_FLAGS_SLOT 0x0100  /* Slot implemented */
 #define PCI_EXP_FLAGS_IRQ  0x3e00  /* Interrupt message number */
 #define PCI_EXP_DEVCAP 4   /* Device capabilities */
-- 
Anthony PERARD




[Qemu-devel] [PATCH V2 07/10] Introduce apic-msidef.h

2011-10-19 Thread Anthony PERARD
This patch move the msi definition from apic.c to apic-msidef.h. So it can be
used also by other .c files.

Signed-off-by: Anthony PERARD 
---
 hw/apic-msidef.h |   28 
 hw/apic.c|   11 +--
 2 files changed, 29 insertions(+), 10 deletions(-)
 create mode 100644 hw/apic-msidef.h

diff --git a/hw/apic-msidef.h b/hw/apic-msidef.h
new file mode 100644
index 000..3182f0b
--- /dev/null
+++ b/hw/apic-msidef.h
@@ -0,0 +1,28 @@
+#ifndef HW_APIC_MSIDEF_H
+#define HW_APIC_MSIDEF_H
+
+/*
+ * Intel APIC constants: from include/asm/msidef.h
+ */
+
+/*
+ * Shifts for MSI data
+ */
+
+#define MSI_DATA_VECTOR_SHIFT   0
+#define  MSI_DATA_VECTOR_MASK   0x00ff
+
+#define MSI_DATA_DELIVERY_MODE_SHIFT8
+#define MSI_DATA_LEVEL_SHIFT14
+#define MSI_DATA_TRIGGER_SHIFT  15
+
+/*
+ * Shift/mask fields for msi address
+ */
+
+#define MSI_ADDR_DEST_MODE_SHIFT2
+
+#define MSI_ADDR_DEST_ID_SHIFT  12
+#define  MSI_ADDR_DEST_ID_MASK  0x000
+
+#endif /* HW_APIC_MSIDEF_H */
diff --git a/hw/apic.c b/hw/apic.c
index 8289eef..18c4a87 100644
--- a/hw/apic.c
+++ b/hw/apic.c
@@ -24,6 +24,7 @@
 #include "sysbus.h"
 #include "trace.h"
 #include "pc.h"
+#include "apic-msidef.h"
 
 /* APIC Local Vector Table */
 #define APIC_LVT_TIMER   0
@@ -65,16 +66,6 @@
 #define MAX_APICS 255
 #define MAX_APIC_WORDS 8
 
-/* Intel APIC constants: from include/asm/msidef.h */
-#define MSI_DATA_VECTOR_SHIFT  0
-#define MSI_DATA_VECTOR_MASK   0x00ff
-#define MSI_DATA_DELIVERY_MODE_SHIFT   8
-#define MSI_DATA_TRIGGER_SHIFT 15
-#define MSI_DATA_LEVEL_SHIFT   14
-#define MSI_ADDR_DEST_MODE_SHIFT   2
-#define MSI_ADDR_DEST_ID_SHIFT 12
-#defineMSI_ADDR_DEST_ID_MASK   0x000
-
 #define MSI_ADDR_SIZE   0x10
 
 typedef struct APICState APICState;
-- 
Anthony PERARD




[Qemu-devel] [PATCH V2 06/10] pci_regs: Add PCI_EXP_TYPE_PCIE_BRIDGE

2011-10-19 Thread Anthony PERARD
Signed-off-by: Anthony PERARD 
---
 hw/pci_regs.h |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/hw/pci_regs.h b/hw/pci_regs.h
index 6b42515..56a404b 100644
--- a/hw/pci_regs.h
+++ b/hw/pci_regs.h
@@ -392,6 +392,7 @@
 #define  PCI_EXP_TYPE_UPSTREAM 0x5 /* Upstream Port */
 #define  PCI_EXP_TYPE_DOWNSTREAM 0x6   /* Downstream Port */
 #define  PCI_EXP_TYPE_PCI_BRIDGE 0x7   /* PCI/PCI-X Bridge */
+#define  PCI_EXP_TYPE_PCIE_BRIDGE 0x8   /* PCI/PCI-X to PCIE Bridge */
 #define  PCI_EXP_TYPE_RC_END   0x9 /* Root Complex Integrated Endpoint */
 #define  PCI_EXP_TYPE_RC_EC 0xa /* Root Complex Event Collector */
 #define PCI_EXP_FLAGS_SLOT 0x0100  /* Slot implemented */
-- 
Anthony PERARD




Re: [Qemu-devel] [PATCH V2 01/10] configure: Introduce --enable-xen-pci-passthrough.

2011-10-19 Thread Peter Maydell
On 19 October 2011 14:56, Anthony PERARD  wrote:
> +if test "$xen_pci_passthrough" != "no"; then
> +  if test "$xen" = "yes" -a "$linux" = "yes"; then
> +    xen_pci_passthrough=yes
> +  else
> +    if test "$xen_pci_passthrough" = "yes"; then
> +      feature_not_found "Xen PCI Passthrough without Xen or not on linux"
> +    fi
> +    xen_pci_passthrough=no
> +  fi
> +fi

The -a flag to test is obsolete -- don't use it in new code.
This is a bit of a misuse of the feature_not_found function IMHO.
(Also, Linux needs a capital letter.)

-- PMM



[Qemu-devel] [PATCH V2 04/10] pci_ids: Add INTEL_82599_VF id.

2011-10-19 Thread Anthony PERARD
Signed-off-by: Anthony PERARD 
---
 hw/pci_ids.h |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/hw/pci_ids.h b/hw/pci_ids.h
index 83f3893..2ea5ec2 100644
--- a/hw/pci_ids.h
+++ b/hw/pci_ids.h
@@ -117,6 +117,7 @@
 #define PCI_DEVICE_ID_INTEL_82801I_UHCI6 0x2939
 #define PCI_DEVICE_ID_INTEL_82801I_EHCI1 0x293a
 #define PCI_DEVICE_ID_INTEL_82801I_EHCI2 0x293c
+#define PCI_DEVICE_ID_INTEL_82599_VF 0x10ed
 
 #define PCI_VENDOR_ID_XEN   0x5853
 #define PCI_DEVICE_ID_XEN_PLATFORM  0x0001
-- 
Anthony PERARD




[Qemu-devel] [PATCH V2 00/10] Xen PCI Passthrough

2011-10-19 Thread Anthony PERARD
Hi all,

This patch series introduce the PCI passthrough for Xen.

First, we have HostPCIDevice that help to access one PCI device of the host.

Then, there is an additions in the QEMU code, pci_check_bar_overlap.

There are also several change in pci_ids and pci_regs.

Last part, but not least, the PCI passthrough device himself. Cut in 3 parts
(or file), there is one to take care of the initialisation of a passthrough
device. The second one handle everything about the config address space, there
are specifics functions for every config register. The third one is to handle
MSI.

There is a patch series on xen-devel that add the support of setting a PCI
passthrough device through QMP from libxl (xen tool stack). It is just a call
to device_add, with the driver parametter hostaddr=":00:1b.0".

Change since the v1:
  - fix style issue (checkpatch.pl)
  - set the original authors, add some missing copyright headers
  - HostPCIDevice:
- introduce HostPCIIORegions (with base_addr, size, flags)
- save all flags from ./resource and store it in a separate field.
- fix endianess on write
- new host_pci_dev_put function
- use pci.c like interface host_pci_get/set_byte/word/long (instead of
  host_pci_read/write_)
  - compile HostPCIDevice only on linux (as well as xen_pci_passthrough)
  - introduce apic-msidef.h file.
  - no more run_one_timer, if a pci device is in the middle of a power
transition, just "return an error" in config read/write
  - use a global var mapped_machine_irq (local to xen_pci_passthrough.c)
  - add msitranslate and power-mgmt ad qdev property



Allen Kay (2):
  Introduce Xen PCI Passthrough, qdevice (1/3)
  Introduce Xen PCI Passthrough, PCI config space helpers (2/3)

Anthony PERARD (6):
  configure: Introduce --enable-xen-pci-passthrough.
  Introduce HostPCIDevice to access a pci device on the host.
  pci_ids: Add INTEL_82599_VF id.
  pci_regs: Fix value of PCI_EXP_TYPE_RC_EC.
  pci_regs: Add PCI_EXP_TYPE_PCIE_BRIDGE
  Introduce apic-msidef.h

Jiang Yunhong (1):
  Introduce Xen PCI Passthrough, MSI (3/3)

Yuji Shimada (1):
  pci.c: Add pci_check_bar_overlap

 Makefile.target  |7 +
 configure|   21 +
 hw/apic-msidef.h |   30 +
 hw/apic.c|   11 +-
 hw/host-pci-device.c |  245 
 hw/host-pci-device.h |   75 +
 hw/pci.c |   47 +
 hw/pci.h |3 +
 hw/pci_ids.h |1 +
 hw/pci_regs.h|3 +-
 hw/xen_pci_passthrough.c |  861 
 hw/xen_pci_passthrough.h |  280 
 hw/xen_pci_passthrough_config_init.c | 2553 ++
 hw/xen_pci_passthrough_helpers.c |   46 +
 hw/xen_pci_passthrough_msi.c |  667 +
 15 files changed, 4839 insertions(+), 11 deletions(-)
 create mode 100644 hw/apic-msidef.h
 create mode 100644 hw/host-pci-device.c
 create mode 100644 hw/host-pci-device.h
 create mode 100644 hw/xen_pci_passthrough.c
 create mode 100644 hw/xen_pci_passthrough.h
 create mode 100644 hw/xen_pci_passthrough_config_init.c
 create mode 100644 hw/xen_pci_passthrough_helpers.c
 create mode 100644 hw/xen_pci_passthrough_msi.c

-- 
Anthony PERARD




[Qemu-devel] [PATCH V2 03/10] pci.c: Add pci_check_bar_overlap

2011-10-19 Thread Anthony PERARD
From: Yuji Shimada 

This function help Xen PCI Passthrough device to check for overlap.

Signed-off-by: Yuji Shimada 
Signed-off-by: Anthony PERARD 
---
 hw/pci.c |   47 +++
 hw/pci.h |3 +++
 2 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index 749e8d8..d85ceca 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -2129,3 +2129,50 @@ MemoryRegion *pci_address_space_io(PCIDevice *dev)
 {
 return dev->bus->address_space_io;
 }
+
+int pci_check_bar_overlap(PCIDevice *dev,
+  pcibus_t addr, pcibus_t size, uint8_t type)
+{
+PCIBus *bus = dev->bus;
+PCIDevice *devices = NULL;
+PCIIORegion *r;
+int i, j;
+int rc = 0;
+
+/* check Overlapped to Base Address */
+for (i = 0; i < ARRAY_SIZE(bus->devices); i++) {
+devices = bus->devices[i];
+if (!devices) {
+continue;
+}
+
+/* skip itself */
+if (devices->devfn == dev->devfn) {
+continue;
+}
+
+for (j = 0; j < PCI_NUM_REGIONS; j++) {
+r = &devices->io_regions[j];
+
+/* skip different resource type, but don't skip when
+ * prefetch and non-prefetch memory are compared.
+ */
+if (type != r->type) {
+if (type == PCI_BASE_ADDRESS_SPACE_IO ||
+r->type == PCI_BASE_ADDRESS_SPACE_IO) {
+continue;
+}
+}
+
+if ((addr < (r->addr + r->size)) && ((addr + size) > r->addr)) {
+printf("Overlapped to device[%02x:%02x.%x][Region:%d]"
+   "[Address:%"PRIx64"h][Size:%"PRIx64"h]\n",
+   pci_bus_num(bus), PCI_SLOT(devices->devfn),
+   PCI_FUNC(devices->devfn), j, r->addr, r->size);
+rc = 1;
+}
+}
+}
+
+return rc;
+}
diff --git a/hw/pci.h b/hw/pci.h
index 86a81c8..0e1a07d 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -487,4 +487,7 @@ static inline uint32_t pci_config_size(const PCIDevice *d)
 return pci_is_express(d) ? PCIE_CONFIG_SPACE_SIZE : PCI_CONFIG_SPACE_SIZE;
 }
 
+int pci_check_bar_overlap(PCIDevice *dev,
+  pcibus_t addr, pcibus_t size, uint8_t type);
+
 #endif
-- 
Anthony PERARD




[Qemu-devel] [PATCH V2 02/10] Introduce HostPCIDevice to access a pci device on the host.

2011-10-19 Thread Anthony PERARD
Signed-off-by: Anthony PERARD 
---
 Makefile.target  |1 +
 hw/host-pci-device.c |  245 ++
 hw/host-pci-device.h |   75 +++
 3 files changed, 321 insertions(+), 0 deletions(-)
 create mode 100644 hw/host-pci-device.c
 create mode 100644 hw/host-pci-device.h

diff --git a/Makefile.target b/Makefile.target
index c518103..ca3420d 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -209,6 +209,7 @@ obj-$(CONFIG_NO_XEN) += xen-stub.o
 obj-i386-$(CONFIG_XEN) += xen_platform.o
 
 # Xen PCI Passthrough
+obj-i386-$(CONFIG_XEN_PCI_PASSTHROUGH) += host-pci-device.o
 
 # Inter-VM PCI shared memory
 CONFIG_IVSHMEM =
diff --git a/hw/host-pci-device.c b/hw/host-pci-device.c
new file mode 100644
index 000..0f25fcf
--- /dev/null
+++ b/hw/host-pci-device.c
@@ -0,0 +1,245 @@
+/*
+ * Copyright (C) 2011   Citrix Ltd.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu-common.h"
+#include "host-pci-device.h"
+
+static int path_to(const HostPCIDevice *d,
+   const char *name, char *buf, ssize_t size)
+{
+return snprintf(buf, size, "/sys/bus/pci/devices/%04x:%02x:%02x.%x/%s",
+d->domain, d->bus, d->dev, d->func, name);
+}
+
+static int get_resource(HostPCIDevice *d)
+{
+int i, rc = 0;
+FILE *f;
+char path[PATH_MAX];
+unsigned long long start, end, flags, size;
+
+path_to(d, "resource", path, sizeof (path));
+f = fopen(path, "r");
+if (!f) {
+fprintf(stderr, "Error: Can't open %s: %s\n", path, strerror(errno));
+return -1;
+}
+
+for (i = 0; i < PCI_NUM_REGIONS; i++) {
+if (fscanf(f, "%llx %llx %llx", &start, &end, &flags) != 3) {
+fprintf(stderr, "Error: Syntax error in %s\n", path);
+rc = -1;
+break;
+}
+if (start) {
+size = end - start + 1;
+} else {
+size = 0;
+}
+
+if (i < PCI_ROM_SLOT) {
+d->io_regions[i].base_addr = start;
+d->io_regions[i].size = size;
+d->io_regions[i].flags = flags;
+} else {
+d->rom.base_addr = start;
+d->rom.size = size;
+d->rom.flags = flags;
+}
+}
+
+fclose(f);
+return rc;
+}
+
+static unsigned long get_value(HostPCIDevice *d, const char *name)
+{
+char path[PATH_MAX];
+FILE *f;
+unsigned long value;
+
+path_to(d, name, path, sizeof (path));
+f = fopen(path, "r");
+if (!f) {
+fprintf(stderr, "Error: Can't open %s: %s\n", path, strerror(errno));
+return -1;
+}
+if (fscanf(f, "%lx\n", &value) != 1) {
+fprintf(stderr, "Error: Syntax error in %s\n", path);
+value = -1;
+}
+fclose(f);
+return value;
+}
+
+static int pci_dev_is_virtfn(HostPCIDevice *d)
+{
+int rc;
+char path[PATH_MAX];
+struct stat buf;
+
+path_to(d, "physfn", path, sizeof (path));
+rc = !stat(path, &buf);
+
+return rc;
+}
+
+static int host_pci_config_fd(HostPCIDevice *d)
+{
+char path[PATH_MAX];
+
+if (d->config_fd < 0) {
+path_to(d, "config", path, sizeof (path));
+d->config_fd = open(path, O_RDWR);
+if (d->config_fd < 0) {
+fprintf(stderr, "HostPCIDevice: Can not open '%s': %s\n",
+path, strerror(errno));
+}
+}
+return d->config_fd;
+}
+static int host_pci_config_read(HostPCIDevice *d, int pos, void *buf, int len)
+{
+int fd = host_pci_config_fd(d);
+int res = 0;
+
+res = pread(fd, buf, len, pos);
+if (res < 0) {
+fprintf(stderr, "host_pci_config: read failed: %s (fd: %i)\n",
+strerror(errno), fd);
+return -1;
+}
+return res;
+}
+static int host_pci_config_write(HostPCIDevice *d,
+ int pos, const void *buf, int len)
+{
+int fd = host_pci_config_fd(d);
+int res = 0;
+
+res = pwrite(fd, buf, len, pos);
+if (res < 0) {
+fprintf(stderr, "host_pci_config: write failed: %s\n",
+strerror(errno));
+return -1;
+}
+return res;
+}
+
+uint8_t host_pci_get_byte(HostPCIDevice *d, int pos)
+{
+  uint8_t buf;
+  host_pci_config_read(d, pos, &buf, 1);
+  return buf;
+}
+uint16_t host_pci_get_word(HostPCIDevice *d, int pos)
+{
+  uint16_t buf;
+  host_pci_config_read(d, pos, &buf, 2);
+  return le16_to_cpu(buf);
+}
+uint32_t host_pci_get_long(HostPCIDevice *d, int pos)
+{
+  uint32_t buf;
+  host_pci_config_read(d, pos, &buf, 4);
+  return le32_to_cpu(buf);
+}
+int host_pci_get_block(HostPCIDevice *d, int pos, uint8_t *buf, int len)
+{
+  return host_pci_config_read(d, pos, buf, len);
+}
+
+int host_pci_set_byte(HostPCIDevice *d, int pos, uint8_t data)
+{
+  return host_pci_config_write(d, pos, &data, 1);
+}
+int host_pci_set_word(HostPCIDevice *d, int pos, uint16_t 

[Qemu-devel] [PATCH] [v2] arm gic saving/loading fix

2011-10-19 Thread Dmitry Koshelev
irq_target field saving/loading is in the wrong loop
version bump

Signed-off-by: Dmitry Koshelev 
---
 hw/arm_gic.c |   16 
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/hw/arm_gic.c b/hw/arm_gic.c
index 8286a28..d0747cf 100644
--- a/hw/arm_gic.c
+++ b/hw/arm_gic.c
@@ -662,9 +662,6 @@ static void gic_save(QEMUFile *f, void *opaque)
 qemu_put_be32(f, s->enabled);
 for (i = 0; i < NUM_CPU(s); i++) {
 qemu_put_be32(f, s->cpu_enabled[i]);
-#ifndef NVIC
-qemu_put_be32(f, s->irq_target[i]);
-#endif
 for (j = 0; j < 32; j++)
 qemu_put_be32(f, s->priority1[j][i]);
 for (j = 0; j < GIC_NIRQ; j++)
@@ -678,6 +675,9 @@ static void gic_save(QEMUFile *f, void *opaque)
 qemu_put_be32(f, s->priority2[i]);
 }
 for (i = 0; i < GIC_NIRQ; i++) {
+#ifndef NVIC
+qemu_put_be32(f, s->irq_target[i]);
+#endif
 qemu_put_byte(f, s->irq_state[i].enabled);
 qemu_put_byte(f, s->irq_state[i].pending);
 qemu_put_byte(f, s->irq_state[i].active);
@@ -693,15 +693,12 @@ static int gic_load(QEMUFile *f, void *opaque,
int version_id)
 int i;
 int j;

-if (version_id != 1)
+if (version_id != 2)
 return -EINVAL;

 s->enabled = qemu_get_be32(f);
 for (i = 0; i < NUM_CPU(s); i++) {
 s->cpu_enabled[i] = qemu_get_be32(f);
-#ifndef NVIC
-s->irq_target[i] = qemu_get_be32(f);
-#endif
 for (j = 0; j < 32; j++)
 s->priority1[j][i] = qemu_get_be32(f);
 for (j = 0; j < GIC_NIRQ; j++)
@@ -715,6 +712,9 @@ static int gic_load(QEMUFile *f, void *opaque, int
version_id)
 s->priority2[i] = qemu_get_be32(f);
 }
 for (i = 0; i < GIC_NIRQ; i++) {
+#ifndef NVIC
+s->irq_target[i] = qemu_get_be32(f);
+#endif
 s->irq_state[i].enabled = qemu_get_byte(f);
 s->irq_state[i].pending = qemu_get_byte(f);
 s->irq_state[i].active = qemu_get_byte(f);
@@ -744,5 +744,5 @@ static void gic_init(gic_state *s)
 s->iomemtype = cpu_register_io_memory(gic_dist_readfn,
   gic_dist_writefn, s);
 gic_reset(s);
-register_savevm(NULL, "arm_gic", -1, 1, gic_save, gic_load, s);
+register_savevm(NULL, "arm_gic", -1, 2, gic_save, gic_load, s);
 }



[Qemu-devel] [PATCH V2 08/10] Introduce Xen PCI Passthrough, qdevice (1/3)

2011-10-19 Thread Anthony PERARD
From: Allen Kay 

Signed-off-by: Allen Kay 
Signed-off-by: Guy Zana 
Signed-off-by: Anthony PERARD 
---
 Makefile.target  |2 +
 hw/xen_pci_passthrough.c |  861 ++
 hw/xen_pci_passthrough.h |  258 
 hw/xen_pci_passthrough_helpers.c |   46 ++
 4 files changed, 1167 insertions(+), 0 deletions(-)
 create mode 100644 hw/xen_pci_passthrough.c
 create mode 100644 hw/xen_pci_passthrough.h
 create mode 100644 hw/xen_pci_passthrough_helpers.c

diff --git a/Makefile.target b/Makefile.target
index ca3420d..0673b51 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -210,6 +210,8 @@ obj-i386-$(CONFIG_XEN) += xen_platform.o
 
 # Xen PCI Passthrough
 obj-i386-$(CONFIG_XEN_PCI_PASSTHROUGH) += host-pci-device.o
+obj-i386-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pci_passthrough.o
+obj-i386-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pci_passthrough_helpers.o
 
 # Inter-VM PCI shared memory
 CONFIG_IVSHMEM =
diff --git a/hw/xen_pci_passthrough.c b/hw/xen_pci_passthrough.c
new file mode 100644
index 000..0b631f7
--- /dev/null
+++ b/hw/xen_pci_passthrough.c
@@ -0,0 +1,861 @@
+/*
+ * Copyright (c) 2007, Neocleus Corporation.
+ * Copyright (c) 2007, Intel Corporation.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ * Alex Novik 
+ * Allen Kay 
+ * Guy Zana 
+ *
+ * This file implements direct PCI assignment to a HVM guest
+ */
+
+/*
+ * Interrupt Disable policy:
+ *
+ * INTx interrupt:
+ *   Initialize(register_real_device)
+ * Map INTx(xc_physdev_map_pirq):
+ *   
+ * - Set real Interrupt Disable bit to '1'.
+ * - Set machine_irq and assigned_device->machine_irq to '0'.
+ * * Don't bind INTx.
+ *
+ * Bind INTx(xc_domain_bind_pt_pci_irq):
+ *   
+ * - Set real Interrupt Disable bit to '1'.
+ * - Unmap INTx.
+ * - Decrement mapped_machine_irq[machine_irq]
+ * - Set assigned_device->machine_irq to '0'.
+ *
+ *   Write to Interrupt Disable bit by guest software(pt_cmd_reg_write)
+ * Write '0'
+ *   msi_trans_en is false>
+ * - Set real bit to '0' if assigned_device->machine_irq isn't '0'.
+ *
+ * Write '1'
+ *   msi_trans_en is false>
+ * - Set real bit to '1'.
+ *
+ * MSI-INTx translation.
+ *   Initialize(xc_physdev_map_pirq_msi/pt_msi_setup)
+ * Bind MSI-INTx(xc_domain_bind_pt_irq)
+ *   
+ * - Unmap MSI.
+ *   
+ * - Set dev->msi->pirq to '-1'.
+ *   
+ * - Do nothing.
+ *
+ *   Write to Interrupt Disable bit by guest software(pt_cmd_reg_write)
+ * Write '0'
+ *   msi_trans_en is true>
+ * - Set MSI Enable bit to '1'.
+ *
+ * Write '1'
+ *   msi_trans_en is true>
+ * - Set MSI Enable bit to '0'.
+ *
+ * MSI interrupt:
+ *   Initialize MSI register(pt_msi_setup, pt_msi_update)
+ * Bind MSI(xc_domain_update_msi_irq)
+ *   
+ * - Unmap MSI.
+ * - Set dev->msi->pirq to '-1'.
+ *
+ * MSI-X interrupt:
+ *   Initialize MSI-X register(pt_msix_update_one)
+ * Bind MSI-X(xc_domain_update_msi_irq)
+ *   
+ * - Unmap MSI-X.
+ * - Set entry->pirq to '-1'.
+ */
+
+#include 
+
+#include "pci.h"
+#include "xen.h"
+#include "xen_backend.h"
+#include "xen_pci_passthrough.h"
+
+#define PCI_BAR_ENTRIES (6)
+
+#define PT_NR_IRQS  (256)
+char mapped_machine_irq[PT_NR_IRQS] = {0};
+
+/* Config Space */
+static int pt_pci_config_access_check(PCIDevice *d, uint32_t address, int len)
+{
+/* check offset range */
+if (address >= 0xFF) {
+PT_LOG("Error: Failed to access register with offset exceeding FFh. "
+   "[%02x:%02x.%x][Offset:%02xh][Length:%d]\n",
+   pci_bus_num(d->bus), PCI_SLOT(d->devfn), PCI_FUNC(d->devfn),
+   address, len);
+return -1;
+}
+
+/* check read size */
+if ((len != 1) && (len != 2) && (len != 4)) {
+PT_LOG("Error: Failed to access register with invalid access length. "
+   "[%02x:%02x.%x][Offset:%02xh][Length:%d]\n",
+   pci_bus_num(d->bus), PCI_SLOT(d->devfn), PCI_FUNC(d->devfn),
+   address, len);
+return -1;
+}
+
+/* check offset alignment */
+if (address & (len - 1)) {
+PT_LOG("Error: Failed to access register with invalid access size "
+"alignment. [%02x:%02x.%x][Offset:%02xh][Length:%d]\n",
+pci_bus_num(d->bus), PCI_SLOT(d->devfn), PCI_FUNC(d->devfn),
+address, len);
+return -1;
+}
+
+return 0;
+}
+
+int pt_bar_offset_to_index(uint32_t offset)
+{
+int index = 0;
+
+/* check Exp ROM BAR */
+if (offset == PCI_ROM_ADDRESS) {
+return PCI_ROM_SLOT;
+}
+
+/* calculate BAR index */
+index = (offset - PCI_BASE_ADDRESS_0) >> 2;
+if (index >= PCI_NUM_REGIONS) {
+return -1;
+}
+
+return i

[Qemu-devel] [PATCH 4/5] savevm: qemu_savevm_state(): Drop stop VM logic

2011-10-19 Thread Luiz Capitulino
qemu_savevm_state() has some logic to stop the VM and to (or not to)
resume it. But this seems to be a big noop, as qemu_savevm_state()
is only called by do_savevm() when the VM is already stopped.

So, let's drop qemu_savevm_state()'s stop VM logic.

Reviewed-by: Michael Roth 
Reviewed-by: Kevin Wolf 
Reviewed-by: Juan Quintela 
Signed-off-by: Luiz Capitulino 
---
 savevm.c |7 ---
 1 files changed, 0 insertions(+), 7 deletions(-)

diff --git a/savevm.c b/savevm.c
index bf4d0e7..abb4a60 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1599,12 +1599,8 @@ void qemu_savevm_state_cancel(Monitor *mon, QEMUFile *f)
 
 static int qemu_savevm_state(Monitor *mon, QEMUFile *f)
 {
-int saved_vm_running;
 int ret;
 
-saved_vm_running = runstate_is_running();
-vm_stop(RUN_STATE_SAVE_VM);
-
 if (qemu_savevm_state_blocked(mon)) {
 ret = -EINVAL;
 goto out;
@@ -1626,9 +1622,6 @@ out:
 if (qemu_file_has_error(f))
 ret = -EIO;
 
-if (!ret && saved_vm_running)
-vm_start();
-
 return ret;
 }
 
-- 
1.7.7.rc3




[Qemu-devel] [PATCH] integratorcp: convert control to sysbus

2011-10-19 Thread Benoît Canet
Signed-off-by: Benoit Canet 
---
 hw/integratorcp.c |   20 +---
 1 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/hw/integratorcp.c b/hw/integratorcp.c
index 7f79560..7ad68b7 100644
--- a/hw/integratorcp.c
+++ b/hw/integratorcp.c
@@ -393,6 +393,11 @@ static int icp_pic_init(SysBusDevice *dev)
 
 /* CP control registers.  */
 
+typedef struct icp_control_state {
+SysBusDevice busdev;
+MemoryRegion iomem;
+} icp_control_state;
+
 static uint64_t icp_control_read(void *opaque, target_phys_addr_t offset,
  unsigned size)
 {
@@ -431,15 +436,14 @@ static const MemoryRegionOps icp_control_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static void icp_control_init(target_phys_addr_t base)
+static int icp_control_init(SysBusDevice *dev)
 {
-MemoryRegion *io;
+icp_control_state *s = FROM_SYSBUS(icp_control_state, dev);
 
-io = (MemoryRegion *)g_malloc0(sizeof(MemoryRegion));
-memory_region_init_io(io, &icp_control_ops, NULL,
+memory_region_init_io(&s->iomem, &icp_control_ops, s,
   "control", 0x0080);
-memory_region_add_subregion(get_system_memory(), base, io);
-/* ??? Save/restore.  */
+sysbus_init_mmio_region(dev, &s->iomem);
+return 0;
 }
 
 
@@ -498,7 +502,7 @@ static void integratorcp_init(ram_addr_t ram_size,
 sysbus_create_simple("pl031", 0x1500, pic[8]);
 sysbus_create_simple("pl011", 0x1600, pic[1]);
 sysbus_create_simple("pl011", 0x1700, pic[2]);
-icp_control_init(0xcb00);
+sysbus_create_simple("integrator_control", 0xcb00, NULL);
 sysbus_create_simple("pl050_keyboard", 0x1800, pic[3]);
 sysbus_create_simple("pl050_mouse", 0x1900, pic[4]);
 sysbus_create_varargs("pl181", 0x1c00, pic[23], pic[24], NULL);
@@ -541,6 +545,8 @@ static SysBusDeviceInfo core_info = {
 static void integratorcp_register_devices(void)
 {
 sysbus_register_dev("integrator_pic", sizeof(icp_pic_state), icp_pic_init);
+sysbus_register_dev("integrator_control", sizeof(icp_control_state),
+icp_control_init);
 sysbus_register_withprop(&core_info);
 }
 
-- 
1.7.5.4




Re: [Qemu-devel] [PATCH 1/1] Introduce a new bus "ICC" to connect APIC

2011-10-19 Thread Jan Kiszka
On 2011-10-19 15:33, Jan Kiszka wrote:
> On 2011-10-19 14:54, Anthony Liguori wrote:
>> On 10/19/2011 05:53 AM, Jan Kiszka wrote:
>>> On 2011-10-19 03:55, pingf...@linux.vnet.ibm.com wrote:
 From: Liu Ping Fan

 Introduce a new structure CPUS as the controller of ICC (INTERRUPT
 CONTROLLER COMMUNICATIONS), and new bus "ICC" to hold APIC,instead
 of sysbus. So we can support APIC hot-plug feature.

 Signed-off-by: liu ping fan
 ---
   Makefile.target |1 +
   hw/apic.c   |   25 +++
   hw/apic.h   |1 +
   hw/icc_bus.c|   91 
 +++
   hw/icc_bus.h|   56 ++
   hw/pc.c |   11 --
   6 files changed, 174 insertions(+), 11 deletions(-)
   create mode 100644 hw/icc_bus.c
   create mode 100644 hw/icc_bus.h

 diff --git a/Makefile.target b/Makefile.target
 index 9011f28..5607c6d 100644
 --- a/Makefile.target
 +++ b/Makefile.target
 @@ -241,6 +241,7 @@ obj-i386-$(CONFIG_KVM) += kvmclock.o
   obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
   obj-i386-y += testdev.o
   obj-i386-y += acpi.o acpi_piix4.o
 +obj-i386-y += icc_bus.o

   obj-i386-y += pcspk.o i8254.o
   obj-i386-$(CONFIG_KVM_PIT) += i8254-kvm.o
 diff --git a/hw/apic.c b/hw/apic.c
 index 69d6ac5..00d2297 100644
 --- a/hw/apic.c
 +++ b/hw/apic.c
 @@ -21,9 +21,10 @@
   #include "ioapic.h"
   #include "qemu-timer.h"
   #include "host-utils.h"
 -#include "sysbus.h"
 +#include "icc_bus.h"
   #include "trace.h"
   #include "kvm.h"
 +#include "exec-memory.h"
>>>
>>> Mmh, don't your rather want memory.h?
>>>

   /* APIC Local Vector Table */
   #define APIC_LVT_TIMER   0
 @@ -80,7 +81,7 @@
   typedef struct APICState APICState;

   struct APICState {
 -SysBusDevice busdev;
 +ICCBusDevice busdev;
   MemoryRegion io_memory;
   void *cpu_env;
   uint32_t apicbase;
 @@ -1104,9 +1105,20 @@ static const MemoryRegionOps apic_io_ops = {
   .endianness = DEVICE_NATIVE_ENDIAN,
   };

 -static int apic_init1(SysBusDevice *dev)
 +/**/
>>>
>>> Empty comment.
>>>
 +int apic_mmio_map(DeviceState *dev, target_phys_addr_t base)
   {
 -APICState *s = FROM_SYSBUS(APICState, dev);
 +APICState *s = DO_UPCAST(APICState, busdev.qdev, dev);
 +
 +memory_region_add_subregion(get_system_memory(),
 +base,
 +&s->io_memory);
 +return 0;
 +}
 +
 +static int apic_init1(ICCBusDevice *dev)
 +{
 +APICState *s = DO_UPCAST(APICState, busdev, dev);
   static int last_apic_idx;

   if (last_apic_idx>= MAX_APICS) {
 @@ -1114,7 +1126,6 @@ static int apic_init1(SysBusDevice *dev)
   }
   memory_region_init_io(&s->io_memory,&apic_io_ops, s, "apic",
 MSI_ADDR_SIZE);
 -sysbus_init_mmio_region(dev,&s->io_memory);

   s->timer = qemu_new_timer_ns(vm_clock, apic_timer, s);
   s->idx = last_apic_idx++;
 @@ -1122,7 +1133,7 @@ static int apic_init1(SysBusDevice *dev)
   return 0;
   }

 -static SysBusDeviceInfo apic_info = {
 +static ICCBusDeviceInfo apic_info = {
   .init = apic_init1,
   .qdev.name = "apic",
   .qdev.size = sizeof(APICState),
 @@ -1138,7 +1149,7 @@ static SysBusDeviceInfo apic_info = {

   static void apic_register_devices(void)
   {
 -sysbus_register_withprop(&apic_info);
 +iccbus_register_devinfo(&apic_info);
   }

   device_init(apic_register_devices)
 diff --git a/hw/apic.h b/hw/apic.h
 index c857d52..e2c0af5 100644
 --- a/hw/apic.h
 +++ b/hw/apic.h
 @@ -20,6 +20,7 @@ void cpu_set_apic_tpr(DeviceState *s, uint8_t val);
   uint8_t cpu_get_apic_tpr(DeviceState *s);
   void apic_init_reset(DeviceState *s);
   void apic_sipi(DeviceState *s);
 +int apic_mmio_map(DeviceState *dev, target_phys_addr_t base);

   /* pc.c */
   int cpu_is_bsp(CPUState *env);
 diff --git a/hw/icc_bus.c b/hw/icc_bus.c
 new file mode 100644
 index 000..61a408e
 --- /dev/null
 +++ b/hw/icc_bus.c
 @@ -0,0 +1,91 @@
 +/* icc_bus.c
 + * emulate x86 ICC(INTERRUPT CONTROLLER COMMUNICATIONS) bus
>>>
>>> Copyright?
>>>
 + *
 + * This library is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU Lesser General Public
 + * License as published by the Free Software Foundation; either
 + * version 2 of the License, or (at your option) any later version.
 + *
 + * This library is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied w

[Qemu-devel] [PATCH 5/5] runstate: Allow user to migrate twice

2011-10-19 Thread Luiz Capitulino
It should be a matter of allowing the transition POSTMIGRATE ->
FINISH_MIGRATE, but it turns out that the VM won't do the
transition the second time because it's already stopped.

So this commit also adds vm_stop_force_state() which performs
the transition even if the VM is already stopped.

While there also allow other states to migrate.

Signed-off-by: Luiz Capitulino 
---
 cpus.c  |   11 +++
 migration.c |2 +-
 sysemu.h|1 +
 vl.c|9 +++--
 4 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/cpus.c b/cpus.c
index 8978779..5f5b763 100644
--- a/cpus.c
+++ b/cpus.c
@@ -887,6 +887,17 @@ void vm_stop(RunState state)
 do_vm_stop(state);
 }
 
+/* does a state transition even if the VM is already stopped,
+   current state is forgotten forever */
+void vm_stop_force_state(RunState state)
+{
+if (runstate_is_running()) {
+vm_stop(state);
+} else {
+runstate_set(state);
+}
+}
+
 static int tcg_cpu_exec(CPUState *env)
 {
 int ret;
diff --git a/migration.c b/migration.c
index 77a51ad..62b74a6 100644
--- a/migration.c
+++ b/migration.c
@@ -375,7 +375,7 @@ void migrate_fd_put_ready(void *opaque)
 int old_vm_running = runstate_is_running();
 
 DPRINTF("done iterating\n");
-vm_stop(RUN_STATE_FINISH_MIGRATE);
+vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
 
 if ((qemu_savevm_state_complete(s->mon, s->file)) < 0) {
 if (old_vm_running) {
diff --git a/sysemu.h b/sysemu.h
index a889d90..7d288f8 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -35,6 +35,7 @@ void vm_state_notify(int running, RunState state);
 
 void vm_start(void);
 void vm_stop(RunState state);
+void vm_stop_force_state(RunState state);
 
 void qemu_system_reset_request(void);
 void qemu_system_shutdown_request(void);
diff --git a/vl.c b/vl.c
index 3e5fdf5..fff2b4c 100644
--- a/vl.c
+++ b/vl.c
@@ -337,17 +337,20 @@ static const RunStateTransition 
runstate_transitions_def[] = {
 { RUN_STATE_INMIGRATE, RUN_STATE_PRELAUNCH },
 
 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED },
+{ RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE },
 
 { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING },
+{ RUN_STATE_IO_ERROR, RUN_STATE_FINISH_MIGRATE },
 
 { RUN_STATE_PAUSED, RUN_STATE_RUNNING },
-{ RUN_STATE_PAUSED, RUN_STATE_POSTMIGRATE },
+{ RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
 
 { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING },
+{ RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },
 
 { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING },
+{ RUN_STATE_PRELAUNCH, RUN_STATE_FINISH_MIGRATE },
 { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
-{ RUN_STATE_PRELAUNCH, RUN_STATE_POSTMIGRATE },
 
 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
@@ -367,8 +370,10 @@ static const RunStateTransition runstate_transitions_def[] 
= {
 { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING },
 
 { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED },
+{ RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE },
 
 { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING },
+{ RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },
 
 { RUN_STATE_MAX, RUN_STATE_MAX },
 };
-- 
1.7.7.rc3




Re: [Qemu-devel] [PATCH 1/1] ACPI: Call ACPI remove handler when handling ACPI eject event

2011-10-19 Thread Gong Chen
On Wed, Oct 19, 2011 at 10:47 AM,   wrote:
> From: Liu Ping Fan 
>
> Call the remove handler for ACPI_NOTIFY_EJECT_REQUEST
>
> Signed-off-by: Liu Ping Fan 
> ---
>  drivers/acpi/bus.c      |    2 +-
>  drivers/acpi/scan.c     |    2 +-
>  include/acpi/acpi_bus.h |    2 ++
>  3 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
> index 437ddbf..d06ec6d 100644
> --- a/drivers/acpi/bus.c
> +++ b/drivers/acpi/bus.c
> @@ -764,7 +764,7 @@ static void acpi_bus_notify(acpi_handle handle, u32 type, 
> void *data)
>                break;
>
>        case ACPI_NOTIFY_EJECT_REQUEST:
> -               /* TBD */
> +               acpi_os_hotplug_execute(acpi_bus_hot_remove_device, handle);
>                break;
>
>        case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
> diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
> index 449c556..3b97b61 100644
> --- a/drivers/acpi/scan.c
> +++ b/drivers/acpi/scan.c
> @@ -83,7 +83,7 @@ acpi_device_modalias_show(struct device *dev, struct 
> device_attribute *attr, cha
>  }
>  static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL);
>
> -static void acpi_bus_hot_remove_device(void *context)
> +void acpi_bus_hot_remove_device(void *context)
>  {
>        struct acpi_device *device;
>        acpi_handle handle = context;
> diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
> index 6cd5b64..b19c09d 100644
> --- a/include/acpi/acpi_bus.h
> +++ b/include/acpi/acpi_bus.h
> @@ -310,6 +310,8 @@ extern int unregister_acpi_notifier(struct notifier_block 
> *);
>
>  extern int register_acpi_bus_notifier(struct notifier_block *nb);
>  extern void unregister_acpi_bus_notifier(struct notifier_block *nb);
> +extern void acpi_bus_hot_remove_device(void *context);
> +
>  /*
>  * External Functions
>  */
> --
> 1.7.4.4
>

I preferred the patch from Shen before. Here is the link:
https://lkml.org/lkml/2011/9/24/15
As Bjorn said, "long-term goal to move the hotplug flow out of drivers and into
the ACPI core". An arbitrary change in the global level just mess up the codes.



Re: [Qemu-devel] [PATCH V5] Add AACI audio playback support to the ARM Versatile/PB platform

2011-10-19 Thread Peter Maydell
On 19 October 2011 14:30, Peter Maydell  wrote:
> NB: this doesn't apply on current master for two reasons:
> (1) something somewhere has added extra leading spaces
> (2) the versatilepb patches don't seem to be against master
> so don't apply for a trivial wrong-context reason

Oops, (2) was me doing my testing on a slightly out of date
branch, sorry about that.

-- PMM



Re: [Qemu-devel] [PATCH 1/1] Introduce a new bus "ICC" to connect APIC

2011-10-19 Thread Jan Kiszka
On 2011-10-19 14:54, Anthony Liguori wrote:
> On 10/19/2011 05:53 AM, Jan Kiszka wrote:
>> On 2011-10-19 03:55, pingf...@linux.vnet.ibm.com wrote:
>>> From: Liu Ping Fan
>>>
>>> Introduce a new structure CPUS as the controller of ICC (INTERRUPT
>>> CONTROLLER COMMUNICATIONS), and new bus "ICC" to hold APIC,instead
>>> of sysbus. So we can support APIC hot-plug feature.
>>>
>>> Signed-off-by: liu ping fan
>>> ---
>>>   Makefile.target |1 +
>>>   hw/apic.c   |   25 +++
>>>   hw/apic.h   |1 +
>>>   hw/icc_bus.c|   91 
>>> +++
>>>   hw/icc_bus.h|   56 ++
>>>   hw/pc.c |   11 --
>>>   6 files changed, 174 insertions(+), 11 deletions(-)
>>>   create mode 100644 hw/icc_bus.c
>>>   create mode 100644 hw/icc_bus.h
>>>
>>> diff --git a/Makefile.target b/Makefile.target
>>> index 9011f28..5607c6d 100644
>>> --- a/Makefile.target
>>> +++ b/Makefile.target
>>> @@ -241,6 +241,7 @@ obj-i386-$(CONFIG_KVM) += kvmclock.o
>>>   obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
>>>   obj-i386-y += testdev.o
>>>   obj-i386-y += acpi.o acpi_piix4.o
>>> +obj-i386-y += icc_bus.o
>>>
>>>   obj-i386-y += pcspk.o i8254.o
>>>   obj-i386-$(CONFIG_KVM_PIT) += i8254-kvm.o
>>> diff --git a/hw/apic.c b/hw/apic.c
>>> index 69d6ac5..00d2297 100644
>>> --- a/hw/apic.c
>>> +++ b/hw/apic.c
>>> @@ -21,9 +21,10 @@
>>>   #include "ioapic.h"
>>>   #include "qemu-timer.h"
>>>   #include "host-utils.h"
>>> -#include "sysbus.h"
>>> +#include "icc_bus.h"
>>>   #include "trace.h"
>>>   #include "kvm.h"
>>> +#include "exec-memory.h"
>>
>> Mmh, don't your rather want memory.h?
>>
>>>
>>>   /* APIC Local Vector Table */
>>>   #define APIC_LVT_TIMER   0
>>> @@ -80,7 +81,7 @@
>>>   typedef struct APICState APICState;
>>>
>>>   struct APICState {
>>> -SysBusDevice busdev;
>>> +ICCBusDevice busdev;
>>>   MemoryRegion io_memory;
>>>   void *cpu_env;
>>>   uint32_t apicbase;
>>> @@ -1104,9 +1105,20 @@ static const MemoryRegionOps apic_io_ops = {
>>>   .endianness = DEVICE_NATIVE_ENDIAN,
>>>   };
>>>
>>> -static int apic_init1(SysBusDevice *dev)
>>> +/**/
>>
>> Empty comment.
>>
>>> +int apic_mmio_map(DeviceState *dev, target_phys_addr_t base)
>>>   {
>>> -APICState *s = FROM_SYSBUS(APICState, dev);
>>> +APICState *s = DO_UPCAST(APICState, busdev.qdev, dev);
>>> +
>>> +memory_region_add_subregion(get_system_memory(),
>>> +base,
>>> +&s->io_memory);
>>> +return 0;
>>> +}
>>> +
>>> +static int apic_init1(ICCBusDevice *dev)
>>> +{
>>> +APICState *s = DO_UPCAST(APICState, busdev, dev);
>>>   static int last_apic_idx;
>>>
>>>   if (last_apic_idx>= MAX_APICS) {
>>> @@ -1114,7 +1126,6 @@ static int apic_init1(SysBusDevice *dev)
>>>   }
>>>   memory_region_init_io(&s->io_memory,&apic_io_ops, s, "apic",
>>> MSI_ADDR_SIZE);
>>> -sysbus_init_mmio_region(dev,&s->io_memory);
>>>
>>>   s->timer = qemu_new_timer_ns(vm_clock, apic_timer, s);
>>>   s->idx = last_apic_idx++;
>>> @@ -1122,7 +1133,7 @@ static int apic_init1(SysBusDevice *dev)
>>>   return 0;
>>>   }
>>>
>>> -static SysBusDeviceInfo apic_info = {
>>> +static ICCBusDeviceInfo apic_info = {
>>>   .init = apic_init1,
>>>   .qdev.name = "apic",
>>>   .qdev.size = sizeof(APICState),
>>> @@ -1138,7 +1149,7 @@ static SysBusDeviceInfo apic_info = {
>>>
>>>   static void apic_register_devices(void)
>>>   {
>>> -sysbus_register_withprop(&apic_info);
>>> +iccbus_register_devinfo(&apic_info);
>>>   }
>>>
>>>   device_init(apic_register_devices)
>>> diff --git a/hw/apic.h b/hw/apic.h
>>> index c857d52..e2c0af5 100644
>>> --- a/hw/apic.h
>>> +++ b/hw/apic.h
>>> @@ -20,6 +20,7 @@ void cpu_set_apic_tpr(DeviceState *s, uint8_t val);
>>>   uint8_t cpu_get_apic_tpr(DeviceState *s);
>>>   void apic_init_reset(DeviceState *s);
>>>   void apic_sipi(DeviceState *s);
>>> +int apic_mmio_map(DeviceState *dev, target_phys_addr_t base);
>>>
>>>   /* pc.c */
>>>   int cpu_is_bsp(CPUState *env);
>>> diff --git a/hw/icc_bus.c b/hw/icc_bus.c
>>> new file mode 100644
>>> index 000..61a408e
>>> --- /dev/null
>>> +++ b/hw/icc_bus.c
>>> @@ -0,0 +1,91 @@
>>> +/* icc_bus.c
>>> + * emulate x86 ICC(INTERRUPT CONTROLLER COMMUNICATIONS) bus
>>
>> Copyright?
>>
>>> + *
>>> + * This library is free software; you can redistribute it and/or
>>> + * modify it under the terms of the GNU Lesser General Public
>>> + * License as published by the Free Software Foundation; either
>>> + * version 2 of the License, or (at your option) any later version.
>>> + *
>>> + * This library is distributed in the hope that it will be useful,
>>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>>> + * Lesser General Public License for more details.
>>> + *
>>> + * You should have received a c

[Qemu-devel] [PATCH] hw/vexpress.c, hw/realview.c: Add PL041 to VExpress, Realview boards

2011-10-19 Thread Peter Maydell
Instantiate the PL041 audio on the Versatile Express and
Realview board models.

Signed-off-by: Peter Maydell 
---
This obviously is intended to be applied after Mathieu Sonet's
PL041/AACI v5 patch.

 hw/realview.c |8 +++-
 hw/vexpress.c |7 ++-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/hw/realview.c b/hw/realview.c
index 549bb15..433d397 100644
--- a/hw/realview.c
+++ b/hw/realview.c
@@ -126,7 +126,7 @@ static void realview_init(ram_addr_t ram_size,
 {
 CPUState *env = NULL;
 ram_addr_t ram_offset;
-DeviceState *dev, *sysctl, *gpio2;
+DeviceState *dev, *sysctl, *gpio2, *pl041;
 SysBusDevice *busdev;
 qemu_irq *irqp;
 qemu_irq pic[64];
@@ -233,6 +233,12 @@ static void realview_init(ram_addr_t ram_size,
 pic[n] = qdev_get_gpio_in(dev, n);
 }
 
+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_connect_irq(sysbus_from_qdev(pl041), 0, pic[19]);
+
 sysbus_create_simple("pl050_keyboard", 0x10006000, pic[20]);
 sysbus_create_simple("pl050_mouse", 0x10007000, pic[21]);
 
diff --git a/hw/vexpress.c b/hw/vexpress.c
index c9766dd..0940a26 100644
--- a/hw/vexpress.c
+++ b/hw/vexpress.c
@@ -41,7 +41,7 @@ static void vexpress_a9_init(ram_addr_t ram_size,
 {
 CPUState *env = NULL;
 ram_addr_t ram_offset, vram_offset, sram_offset;
-DeviceState *dev, *sysctl;
+DeviceState *dev, *sysctl, *pl041;
 SysBusDevice *busdev;
 qemu_irq *irqp;
 qemu_irq pic[64];
@@ -118,6 +118,11 @@ static void vexpress_a9_init(ram_addr_t ram_size,
 /* 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_connect_irq(sysbus_from_qdev(pl041), 0, pic[11]);
 
 dev = sysbus_create_varargs("pl181", 0x10005000, pic[9], pic[10], NULL);
 /* Wire up MMC card detect and read-only signals */
-- 
1.7.1




[Qemu-devel] [PATCH 1/5] QMP: Fix blockdev-snapshot-sync doc example

2011-10-19 Thread Luiz Capitulino
Fix wrong command name.

Reported-by: Eric Blake 
Signed-off-by: Luiz Capitulino 
---
 qmp-commands.hx |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/qmp-commands.hx b/qmp-commands.hx
index 9c11e87..4328e8b 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -710,10 +710,10 @@ Arguments:
 
 Example:
 
--> { "execute": "blockdev-snapshot", "arguments": { "device": "ide-hd0",
-"snapshot-file":
-"/some/place/my-image",
-"format": "qcow2" } }
+-> { "execute": "blockdev-snapshot-sync", "arguments": { "device": "ide-hd0",
+ "snapshot-file":
+"/some/place/my-image",
+"format": "qcow2" } }
 <- { "return": {} }
 
 EQMP
-- 
1.7.7.rc3




Re: [Qemu-devel] [PATCH V5] Add AACI audio playback support to the ARM Versatile/PB platform

2011-10-19 Thread Peter Maydell
On 18 October 2011 22:45, Mathieu Sonet  wrote:
> This driver emulates the ARM AACI interface (PL041) connected to a LM4549
> codec.
> It enables audio playback for the Versatile/PB platform.

> Signed-off-by: Mathieu Sonet 

Reviewed-by: Peter Maydell 

I'm about to send out the patch which adds the PL041 to vexpress
and realview boards.

NB: this doesn't apply on current master for two reasons:
(1) something somewhere has added extra leading spaces
(2) the versatilepb patches don't seem to be against master
so don't apply for a trivial wrong-context reason

I'm going to take this patch into my arm-devs tree and fix these
nits up as I do so (unless anybody else has any further review
comments they want to make).

-- PMM



Re: [Qemu-devel] [PATCH v2 21/35] scsi-disk: bump SCSIRequest reference count until aio completion runs

2011-10-19 Thread Paolo Bonzini

On 10/17/2011 05:37 PM, Paolo Bonzini wrote:

In some cases a request may be canceled before the completion
callback runs.  Keep a reference to the request between starting
an AIO operation, and let scsi_*_complete remove it.

Since scsi_handle_rw_error returns whether something else has to
be done for the request by the caller, it makes sense to transfer
ownership of the ref to scsi_handle_rw_error when it returns 1;
scsi_dma_restart_bh will then free the reference after restarting
the operation.

Signed-off-by: Paolo Bonzini
---
 v1->v2: Add "return" after calling scsi_write_complete with
 ENOMEDIUM.  Bump refcount before testing data direction.

  hw/scsi-disk.c |   16 
  1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index e28c39d..702e6ca 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -139,6 +139,7 @@ static void scsi_read_complete(void * opaque, int ret)

  if (ret) {
  if (scsi_handle_rw_error(r, -ret, SCSI_REQ_STATUS_RETRY_READ)) {
+/* Leave in ref for scsi_dma_restart_bh.  */
  return;
  }
  }
@@ -149,6 +150,7 @@ static void scsi_read_complete(void * opaque, int ret)
  r->sector += n;
  r->sector_count -= n;
  scsi_req_data(&r->req, r->qiov.size);
+scsi_req_unref(&r->req);
  }

  static void scsi_flush_complete(void * opaque, int ret)
@@ -163,11 +165,13 @@ static void scsi_flush_complete(void * opaque, int ret)

  if (ret<  0) {
  if (scsi_handle_rw_error(r, -ret, SCSI_REQ_STATUS_RETRY_FLUSH)) {
+/* Leave in ref for scsi_dma_restart_bh.  */
  return;
  }
  }

  scsi_req_complete(&r->req, GOOD);
+scsi_req_unref(&r->req);
  }

  /* Read more data from scsi device into buffer.  */
@@ -193,6 +197,8 @@ static void scsi_read_data(SCSIRequest *req)
  /* No data transfer may already be in progress */
  assert(r->req.aiocb == NULL);

+/* Save a ref for scsi_read_complete, in case r is canceled.  */
+scsi_req_ref(&r->req);
  if (r->req.cmd.mode == SCSI_XFER_TO_DEV) {
  DPRINTF("Data transfer direction invalid\n");
  scsi_read_complete(r, -EINVAL);
@@ -201,7 +207,9 @@ static void scsi_read_data(SCSIRequest *req)

  if (s->tray_open) {
  scsi_read_complete(r, -ENOMEDIUM);
+return;
  }
+
  n = scsi_init_iovec(r);
  bdrv_acct_start(s->bs,&r->acct, n * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);
  r->req.aiocb = bdrv_aio_readv(s->bs, r->sector,&r->qiov, n,
@@ -279,6 +287,7 @@ static void scsi_write_complete(void * opaque, int ret)
  DPRINTF("Write complete tag=0x%x more=%d\n", r->req.tag, 
r->qiov.size);
  scsi_req_data(&r->req, r->qiov.size);
  }
+scsi_req_unref(&r->req);
  }

  static void scsi_write_data(SCSIRequest *req)
@@ -290,6 +299,8 @@ static void scsi_write_data(SCSIRequest *req)
  /* No data transfer may already be in progress */
  assert(r->req.aiocb == NULL);

+/* Save a ref for scsi_write_complete, in case r is canceled.  */
+scsi_req_ref(&r->req);
  if (r->req.cmd.mode != SCSI_XFER_TO_DEV) {
  DPRINTF("Data transfer direction invalid\n");
  scsi_write_complete(r, -EINVAL);
@@ -300,6 +311,7 @@ static void scsi_write_data(SCSIRequest *req)
  if (n) {
  if (s->tray_open) {
  scsi_write_complete(r, -ENOMEDIUM);
+return;
  }
  bdrv_acct_start(s->bs,&r->acct, n * BDRV_SECTOR_SIZE, 
BDRV_ACCT_WRITE);
  r->req.aiocb = bdrv_aio_writev(s->bs, r->sector,&r->qiov, n,
@@ -344,6 +356,8 @@ static void scsi_dma_restart_bh(void *opaque)
  scsi_req_complete(&r->req, GOOD);
  }
  }
+/* This reference was left in by scsi_handle_rw_error.  */
+scsi_req_unref(&r->req);
  }
  }
  }
@@ -1345,6 +1359,8 @@ static int32_t scsi_send_command(SCSIRequest *req, 
uint8_t *buf)
  r->iov.iov_len = rc;
  break;
  case SYNCHRONIZE_CACHE:
+/* Save a ref for scsi_flush_complete, in case r is canceled.  */
+scsi_req_ref(&r->req);
  bdrv_acct_start(s->bs,&r->acct, 0, BDRV_ACCT_FLUSH);
  r->req.aiocb = bdrv_aio_flush(s->bs, scsi_flush_complete, r);
  if (r->req.aiocb == NULL) {


This needs to be redone after dropping 20/35.

Paolo



Re: [Qemu-devel] [PATCH 20/35] scsi-disk: do not complete requests twice

2011-10-19 Thread Paolo Bonzini

On 10/13/2011 01:03 PM, Paolo Bonzini wrote:

When scsi_handle_rw_error reports a CHECK CONDITION code, the
owner should not call scsi_req_complete.

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

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index b041fd5..d4f773f 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -231,6 +231,7 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error, 
int type)
  bdrv_mon_event(s->bs, BDRV_ACTION_STOP, is_read);
  vm_stop(RUN_STATE_IO_ERROR);
  bdrv_iostatus_set_err(s->bs, error);
+return 1;
  } else {
  switch (error) {
  case ENOMEDIUM:
@@ -247,8 +248,8 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error, 
int type)
  break;
  }
  bdrv_mon_event(s->bs, BDRV_ACTION_REPORT, is_read);
+return 0;
  }
-return 1;
  }

  static void scsi_write_complete(void * opaque, int ret)


Kevin mentioned on IRC that this patch is bogus, and I agreed.

Paolo



Re: [Qemu-devel] [PATCH] integratorcp: convert control to sysbus

2011-10-19 Thread Peter Maydell
2011/10/19 Benoît Canet :
> Signed-off-by: Benoit Canet 

Reviewed-by: Peter Maydell 

Avi -- since this applies on top of the memory region
conversions in your queue, do you want to take this
patch too? Otherwise I'll just have to hold onto it
until you land those...

thanks
-- PMM



[Qemu-devel] [PATCH 2/5] runstate: Print state transition when invalid

2011-10-19 Thread Luiz Capitulino
Makes it easier to debug.

Signed-off-by: Luiz Capitulino 
---
 vl.c |9 ++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/vl.c b/vl.c
index 2dce3ae..2a634a7 100644
--- a/vl.c
+++ b/vl.c
@@ -393,9 +393,12 @@ void runstate_init(void)
 /* This function will abort() on invalid state transitions */
 void runstate_set(RunState new_state)
 {
-if (new_state >= RUN_STATE_MAX ||
-!runstate_valid_transitions[current_run_state][new_state]) {
-fprintf(stderr, "invalid runstate transition\n");
+assert(new_state < RUN_STATE_MAX);
+
+if (!runstate_valid_transitions[current_run_state][new_state]) {
+fprintf(stderr, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
+RunState_lookup[current_run_state],
+RunState_lookup[new_state]);
 abort();
 }
 
-- 
1.7.7.rc3




[Qemu-devel] [PATCH V2] integratorcp: convert control to sysbus

2011-10-19 Thread Benoît Canet
Convert control registers to sysbus.
This version get rid of an unneeded comment.

Benoît Canet (1):
  integratorcp: convert control to sysbus

 hw/integratorcp.c |   20 +---
 1 files changed, 13 insertions(+), 7 deletions(-)

-- 
1.7.5.4




[Qemu-devel] [RESEND PULL 0/5]: QMP queue

2011-10-19 Thread Luiz Capitulino
Anthony,

I'm resending this pull request because Wen Congyang has found a bug in
one of the patches. And also to ping you to pull it :-)

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

git://repo.or.cz/qemu/qmp-unstable.git queue/qmp

Luiz Capitulino (5):
  QMP: Fix blockdev-snapshot-sync doc example
  runstate: Print state transition when invalid
  runstate: Allow to transition from paused to postmigrate
  savevm: qemu_savevm_state(): Drop stop VM logic
  runstate: Allow user to migrate twice

 cpus.c  |   11 +++
 migration.c |2 +-
 qmp-commands.hx |8 
 savevm.c|7 ---
 sysemu.h|1 +
 vl.c|   17 +
 6 files changed, 30 insertions(+), 16 deletions(-)




[Qemu-devel] [PATCH 3/5] runstate: Allow to transition from paused to postmigrate

2011-10-19 Thread Luiz Capitulino
The user may already have paused the VM before starting the
migration process. If s/he does that, then the state will be
'paused' when we finish the migration process. In that case
we want to transition from 'paused' to 'postmigrate' as the
latter is now the real reason why the VM is stopped.

Signed-off-by: Luiz Capitulino 
---
 vl.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/vl.c b/vl.c
index 2a634a7..3e5fdf5 100644
--- a/vl.c
+++ b/vl.c
@@ -341,6 +341,7 @@ static const RunStateTransition runstate_transitions_def[] 
= {
 { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING },
 
 { RUN_STATE_PAUSED, RUN_STATE_RUNNING },
+{ RUN_STATE_PAUSED, RUN_STATE_POSTMIGRATE },
 
 { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING },
 
-- 
1.7.7.rc3




Re: [Qemu-devel] [PATCH 2/5] runstate: Print state transition when invalid

2011-10-19 Thread Luiz Capitulino
On Wed, 19 Oct 2011 08:43:33 +0800
Wen Congyang  wrote:

> At 10/15/2011 01:26 AM, Luiz Capitulino Write:
> > Makes it easier to debug.
> > 
> > Signed-off-by: Luiz Capitulino 
> > ---
> >  vl.c |4 +++-
> >  1 files changed, 3 insertions(+), 1 deletions(-)
> > 
> > diff --git a/vl.c b/vl.c
> > index dbf7778..6645720 100644
> > --- a/vl.c
> > +++ b/vl.c
> > @@ -397,7 +397,9 @@ void runstate_set(RunState new_state)
> >  {
> >  if (new_state >= RUN_STATE_MAX ||
> >  !runstate_valid_transitions[current_run_state][new_state]) {
> > -fprintf(stderr, "invalid runstate transition\n");
> > +fprintf(stderr, "ERROR: invalid runstate transition: '%s' -> 
> > '%s'\n",
> > +RunState_lookup[current_run_state],
> > +RunState_lookup[new_state]);
> 
> If new_state >= RUN_STATE_MAX, we can not use RunState_lookup.

Good catch!

> I think it's better to use:
> new_state >= RUN_STATE_MAX ? "invalid state" : RunState_lookup[new_state]

I prefer to do the following instead:

diff --git a/vl.c b/vl.c
index 2dce3ae..2a634a7 100644
--- a/vl.c
+++ b/vl.c
@@ -393,9 +393,12 @@ void runstate_init(void)
 /* This function will abort() on invalid state transitions */
 void runstate_set(RunState new_state)
 {
-if (new_state >= RUN_STATE_MAX ||
-!runstate_valid_transitions[current_run_state][new_state]) {
-fprintf(stderr, "invalid runstate transition\n");
+assert(new_state < RUN_STATE_MAX);
+
+if (!runstate_valid_transitions[current_run_state][new_state]) {
+fprintf(stderr, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
+RunState_lookup[current_run_state],
+RunState_lookup[new_state]);
 abort();
 }
 
-- 
1.7.7.rc3


> 
> Thanks
> Wen Congyang
> 
> >  abort();
> >  }
> >  
> 




Re: [Qemu-devel] [PATCH 1/1] Introduce a new bus "ICC" to connect APIC

2011-10-19 Thread Anthony Liguori

On 10/19/2011 05:53 AM, Jan Kiszka wrote:

On 2011-10-19 03:55, pingf...@linux.vnet.ibm.com wrote:

From: Liu Ping Fan

Introduce a new structure CPUS as the controller of ICC (INTERRUPT
CONTROLLER COMMUNICATIONS), and new bus "ICC" to hold APIC,instead
of sysbus. So we can support APIC hot-plug feature.

Signed-off-by: liu ping fan
---
  Makefile.target |1 +
  hw/apic.c   |   25 +++
  hw/apic.h   |1 +
  hw/icc_bus.c|   91 +++
  hw/icc_bus.h|   56 ++
  hw/pc.c |   11 --
  6 files changed, 174 insertions(+), 11 deletions(-)
  create mode 100644 hw/icc_bus.c
  create mode 100644 hw/icc_bus.h

diff --git a/Makefile.target b/Makefile.target
index 9011f28..5607c6d 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -241,6 +241,7 @@ obj-i386-$(CONFIG_KVM) += kvmclock.o
  obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
  obj-i386-y += testdev.o
  obj-i386-y += acpi.o acpi_piix4.o
+obj-i386-y += icc_bus.o

  obj-i386-y += pcspk.o i8254.o
  obj-i386-$(CONFIG_KVM_PIT) += i8254-kvm.o
diff --git a/hw/apic.c b/hw/apic.c
index 69d6ac5..00d2297 100644
--- a/hw/apic.c
+++ b/hw/apic.c
@@ -21,9 +21,10 @@
  #include "ioapic.h"
  #include "qemu-timer.h"
  #include "host-utils.h"
-#include "sysbus.h"
+#include "icc_bus.h"
  #include "trace.h"
  #include "kvm.h"
+#include "exec-memory.h"


Mmh, don't your rather want memory.h?



  /* APIC Local Vector Table */
  #define APIC_LVT_TIMER   0
@@ -80,7 +81,7 @@
  typedef struct APICState APICState;

  struct APICState {
-SysBusDevice busdev;
+ICCBusDevice busdev;
  MemoryRegion io_memory;
  void *cpu_env;
  uint32_t apicbase;
@@ -1104,9 +1105,20 @@ static const MemoryRegionOps apic_io_ops = {
  .endianness = DEVICE_NATIVE_ENDIAN,
  };

-static int apic_init1(SysBusDevice *dev)
+/**/


Empty comment.


+int apic_mmio_map(DeviceState *dev, target_phys_addr_t base)
  {
-APICState *s = FROM_SYSBUS(APICState, dev);
+APICState *s = DO_UPCAST(APICState, busdev.qdev, dev);
+
+memory_region_add_subregion(get_system_memory(),
+base,
+&s->io_memory);
+return 0;
+}
+
+static int apic_init1(ICCBusDevice *dev)
+{
+APICState *s = DO_UPCAST(APICState, busdev, dev);
  static int last_apic_idx;

  if (last_apic_idx>= MAX_APICS) {
@@ -1114,7 +1126,6 @@ static int apic_init1(SysBusDevice *dev)
  }
  memory_region_init_io(&s->io_memory,&apic_io_ops, s, "apic",
MSI_ADDR_SIZE);
-sysbus_init_mmio_region(dev,&s->io_memory);

  s->timer = qemu_new_timer_ns(vm_clock, apic_timer, s);
  s->idx = last_apic_idx++;
@@ -1122,7 +1133,7 @@ static int apic_init1(SysBusDevice *dev)
  return 0;
  }

-static SysBusDeviceInfo apic_info = {
+static ICCBusDeviceInfo apic_info = {
  .init = apic_init1,
  .qdev.name = "apic",
  .qdev.size = sizeof(APICState),
@@ -1138,7 +1149,7 @@ static SysBusDeviceInfo apic_info = {

  static void apic_register_devices(void)
  {
-sysbus_register_withprop(&apic_info);
+iccbus_register_devinfo(&apic_info);
  }

  device_init(apic_register_devices)
diff --git a/hw/apic.h b/hw/apic.h
index c857d52..e2c0af5 100644
--- a/hw/apic.h
+++ b/hw/apic.h
@@ -20,6 +20,7 @@ void cpu_set_apic_tpr(DeviceState *s, uint8_t val);
  uint8_t cpu_get_apic_tpr(DeviceState *s);
  void apic_init_reset(DeviceState *s);
  void apic_sipi(DeviceState *s);
+int apic_mmio_map(DeviceState *dev, target_phys_addr_t base);

  /* pc.c */
  int cpu_is_bsp(CPUState *env);
diff --git a/hw/icc_bus.c b/hw/icc_bus.c
new file mode 100644
index 000..61a408e
--- /dev/null
+++ b/hw/icc_bus.c
@@ -0,0 +1,91 @@
+/* icc_bus.c
+ * emulate x86 ICC(INTERRUPT CONTROLLER COMMUNICATIONS) bus


Copyright?


+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ */
+#include "icc_bus.h"
+
+static CPUS *dummy_cpus;


Why "dummy"? Also, no statics please. The bus owner is the chipset
(440fx), so embedded it there. That also avoid that strange "cpus"
device below.


That's an odd model IMHO.  The i440fx doesn't implement the ICC bus.  The ICC 
bus is entirely independent of the northbridge.


Maybe CPUSockets would be a better device name?

Regards,

Anthony Liguori




+
+
+static ICCBusInfo icc_bus_info = {
+.qinfo.name = "icc",

Re: [Qemu-devel] [PATCH] qxl: fix guest cursor tracking

2011-10-19 Thread Gerd Hoffmann
On 10/18/11 18:58, Yonit Halperin wrote:
> (1) If the guest cursor command is empty, don't reload it after migration.
> (2) Cleaning the guest cursor when it is released by
> the spice server. In addition, explicitly reset the
> cursor in spice upon destroying the primary surface
> (was done by spice-server implicitly). This will prevent
> access to pci memory that was released.

Added to spice patch queue.

thanks,
  Gerd




Re: [Qemu-devel] [PATCH] integratorcp: convert control to sysbus

2011-10-19 Thread Peter Maydell
2011/10/19 Benoît Canet :
> +static int icp_control_init(SysBusDevice *dev)
>  {
> -    MemoryRegion *io;
> +    icp_control_state *s = FROM_SYSBUS(icp_control_state, dev);
>
> -    io = (MemoryRegion *)g_malloc0(sizeof(MemoryRegion));
> -    memory_region_init_io(io, &icp_control_ops, NULL,
> +    memory_region_init_io(&s->iomem, &icp_control_ops, s,
>                           "control", 0x0080);
> -    memory_region_add_subregion(get_system_memory(), base, io);
> +    sysbus_init_mmio_region(dev, &s->iomem);
>     /* ??? Save/restore.  */
> +    return 0;
>  }

You should delete the "??? Save/restore" comment -- the
device currently has no state it needs to save/restore, and
now it's a sysbus device we have an easy path to add save/restore
if we do add state (ie we can at that point give it a vmstate).

Otherwise looks good.

-- PMM



[Qemu-devel] [PATCH 03/18] pxa2xx: convert to memory API (part I)

2011-10-19 Thread Avi Kivity
Signed-off-by: Avi Kivity 
---
 hw/pxa.h|1 +
 hw/pxa2xx.c |  116 --
 2 files changed, 49 insertions(+), 68 deletions(-)

diff --git a/hw/pxa.h b/hw/pxa.h
index 1204165..3fb070f 100644
--- a/hw/pxa.h
+++ b/hw/pxa.h
@@ -151,6 +151,7 @@ typedef struct {
 } PXA2xxState;
 
 struct PXA2xxI2SState {
+MemoryRegion iomem;
 qemu_irq irq;
 qemu_irq rx_dma;
 qemu_irq tx_dma;
diff --git a/hw/pxa2xx.c b/hw/pxa2xx.c
index 70d7c8a..19ee094 100644
--- a/hw/pxa2xx.c
+++ b/hw/pxa2xx.c
@@ -521,6 +521,7 @@ static void pxa2xx_mm_write(void *opaque, 
target_phys_addr_t addr,
 /* Synchronous Serial Ports */
 typedef struct {
 SysBusDevice busdev;
+MemoryRegion iomem;
 qemu_irq irq;
 int enable;
 SSIBus *bus;
@@ -627,7 +628,8 @@ static void pxa2xx_ssp_fifo_update(PXA2xxSSPState *s)
 pxa2xx_ssp_int_update(s);
 }
 
-static uint32_t pxa2xx_ssp_read(void *opaque, target_phys_addr_t addr)
+static uint64_t pxa2xx_ssp_read(void *opaque, target_phys_addr_t addr,
+unsigned size)
 {
 PXA2xxSSPState *s = (PXA2xxSSPState *) opaque;
 uint32_t retval;
@@ -673,9 +675,10 @@ static uint32_t pxa2xx_ssp_read(void *opaque, 
target_phys_addr_t addr)
 }
 
 static void pxa2xx_ssp_write(void *opaque, target_phys_addr_t addr,
-uint32_t value)
+ uint64_t value64, unsigned size)
 {
 PXA2xxSSPState *s = (PXA2xxSSPState *) opaque;
+uint32_t value = value64;
 
 switch (addr) {
 case SSCR0:
@@ -762,16 +765,10 @@ static void pxa2xx_ssp_write(void *opaque, 
target_phys_addr_t addr,
 }
 }
 
-static CPUReadMemoryFunc * const pxa2xx_ssp_readfn[] = {
-pxa2xx_ssp_read,
-pxa2xx_ssp_read,
-pxa2xx_ssp_read,
-};
-
-static CPUWriteMemoryFunc * const pxa2xx_ssp_writefn[] = {
-pxa2xx_ssp_write,
-pxa2xx_ssp_write,
-pxa2xx_ssp_write,
+static const MemoryRegionOps pxa2xx_ssp_ops = {
+.read = pxa2xx_ssp_read,
+.write = pxa2xx_ssp_write,
+.endianness = DEVICE_NATIVE_ENDIAN,
 };
 
 static void pxa2xx_ssp_save(QEMUFile *f, void *opaque)
@@ -823,15 +820,12 @@ static int pxa2xx_ssp_load(QEMUFile *f, void *opaque, int 
version_id)
 
 static int pxa2xx_ssp_init(SysBusDevice *dev)
 {
-int iomemtype;
 PXA2xxSSPState *s = FROM_SYSBUS(PXA2xxSSPState, dev);
 
 sysbus_init_irq(dev, &s->irq);
 
-iomemtype = cpu_register_io_memory(pxa2xx_ssp_readfn,
-   pxa2xx_ssp_writefn, s,
-   DEVICE_NATIVE_ENDIAN);
-sysbus_init_mmio(dev, 0x1000, iomemtype);
+memory_region_init_io(&s->iomem, &pxa2xx_ssp_ops, s, "pxa2xx-ssp", 0x1000);
+sysbus_init_mmio_region(dev, &s->iomem);
 register_savevm(&dev->qdev, "pxa2xx_ssp", -1, 0,
 pxa2xx_ssp_save, pxa2xx_ssp_load, s);
 
@@ -858,6 +852,7 @@ static int pxa2xx_ssp_init(SysBusDevice *dev)
 
 typedef struct {
 SysBusDevice busdev;
+MemoryRegion iomem;
 uint32_t rttr;
 uint32_t rtsr;
 uint32_t rtar;
@@ -1009,7 +1004,8 @@ static inline void pxa2xx_rtc_pi_tick(void *opaque)
 pxa2xx_rtc_int_update(s);
 }
 
-static uint32_t pxa2xx_rtc_read(void *opaque, target_phys_addr_t addr)
+static uint64_t pxa2xx_rtc_read(void *opaque, target_phys_addr_t addr,
+unsigned size)
 {
 PXA2xxRTCState *s = (PXA2xxRTCState *) opaque;
 
@@ -1055,9 +1051,10 @@ static uint32_t pxa2xx_rtc_read(void *opaque, 
target_phys_addr_t addr)
 }
 
 static void pxa2xx_rtc_write(void *opaque, target_phys_addr_t addr,
-uint32_t value)
+ uint64_t value64, unsigned size)
 {
 PXA2xxRTCState *s = (PXA2xxRTCState *) opaque;
+uint32_t value = value64;
 
 switch (addr) {
 case RTTR:
@@ -1157,16 +1154,10 @@ static void pxa2xx_rtc_write(void *opaque, 
target_phys_addr_t addr,
 }
 }
 
-static CPUReadMemoryFunc * const pxa2xx_rtc_readfn[] = {
-pxa2xx_rtc_read,
-pxa2xx_rtc_read,
-pxa2xx_rtc_read,
-};
-
-static CPUWriteMemoryFunc * const pxa2xx_rtc_writefn[] = {
-pxa2xx_rtc_write,
-pxa2xx_rtc_write,
-pxa2xx_rtc_write,
+static const MemoryRegionOps pxa2xx_rtc_ops = {
+.read = pxa2xx_rtc_read,
+.write = pxa2xx_rtc_write,
+.endianness = DEVICE_NATIVE_ENDIAN,
 };
 
 static int pxa2xx_rtc_init(SysBusDevice *dev)
@@ -1174,7 +1165,6 @@ static int pxa2xx_rtc_init(SysBusDevice *dev)
 PXA2xxRTCState *s = FROM_SYSBUS(PXA2xxRTCState, dev);
 struct tm tm;
 int wom;
-int iomemtype;
 
 s->rttr = 0x7fff;
 s->rtsr = 0;
@@ -1201,9 +1191,8 @@ static int pxa2xx_rtc_init(SysBusDevice *dev)
 
 sysbus_init_irq(dev, &s->rtc_irq);
 
-iomemtype = cpu_register_io_memory(pxa2xx_rtc_readfn,
-pxa2xx_rtc_writefn, s, DEVICE_NATIVE_ENDIAN);
-sysbus_init_mmio(dev, 0x1, iomemtype);
+memory_region_init_io(&s->iomem, &pxa2xx_rtc_ops, s, "pxa2xx-rtc", 
0x1);
+sysbus_init

[Qemu-devel] [PATCH 11/18] spapr: convert to memory API

2011-10-19 Thread Avi Kivity
Signed-off-by: Avi Kivity 
---
 hw/spapr.c |9 ++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/hw/spapr.c b/hw/spapr.c
index b118975..63e5d33 100644
--- a/hw/spapr.c
+++ b/hw/spapr.c
@@ -41,6 +41,8 @@
 #include "kvm.h"
 #include "kvm_ppc.h"
 
+#include "exec-memory.h"
+
 #include 
 
 #define KERNEL_LOAD_ADDR0x
@@ -324,7 +326,8 @@ static void ppc_spapr_init(ram_addr_t ram_size,
 {
 CPUState *env;
 int i;
-ram_addr_t ram_offset;
+MemoryRegion *sysmem = get_system_memory();
+MemoryRegion *ram = g_new(MemoryRegion, 1);
 uint32_t initrd_base;
 long kernel_size, initrd_size, fw_size;
 long pteg_shift = 17;
@@ -361,8 +364,8 @@ static void ppc_spapr_init(ram_addr_t ram_size,
 
 /* allocate RAM */
 spapr->ram_limit = ram_size;
-ram_offset = qemu_ram_alloc(NULL, "ppc_spapr.ram", spapr->ram_limit);
-cpu_register_physical_memory(0, ram_size, ram_offset);
+memory_region_init_ram(ram, NULL, "ppc_spapr.ram", spapr->ram_limit);
+memory_region_add_subregion(sysmem, 0, ram);
 
 /* allocate hash page table.  For now we always make this 16mb,
  * later we should probably make it scale to the size of guest
-- 
1.7.6.3




[Qemu-devel] [PATCH 01/18] ppc_oldworld: convert to memory API

2011-10-19 Thread Avi Kivity
Signed-off-by: Avi Kivity 
---
 hw/ppc_oldworld.c |   13 -
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/hw/ppc_oldworld.c b/hw/ppc_oldworld.c
index ebcaafa..aac3526 100644
--- a/hw/ppc_oldworld.c
+++ b/hw/ppc_oldworld.c
@@ -73,11 +73,13 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
const char *initrd_filename,
const char *cpu_model)
 {
+MemoryRegion *sysmem = get_system_memory();
 CPUState *env = NULL;
 char *filename;
 qemu_irq *pic, **heathrow_irqs;
 int linux_boot, i;
-ram_addr_t ram_offset, bios_offset;
+MemoryRegion *ram = g_new(MemoryRegion, 1);
+MemoryRegion *bios = g_new(MemoryRegion, 1);
 uint32_t kernel_base, initrd_base, cmdline_base = 0;
 int32_t kernel_size, initrd_size;
 PCIBus *pci_bus;
@@ -114,15 +116,16 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
 exit(1);
 }
 
-ram_offset = qemu_ram_alloc(NULL, "ppc_heathrow.ram", ram_size);
-cpu_register_physical_memory(0, ram_size, ram_offset);
+memory_region_init_ram(ram, NULL, "ppc_heathrow.ram", ram_size);
+memory_region_add_subregion(sysmem, 0, ram);
 
 /* allocate and load BIOS */
-bios_offset = qemu_ram_alloc(NULL, "ppc_heathrow.bios", BIOS_SIZE);
+memory_region_init_ram(bios, NULL, "ppc_heathrow.bios", BIOS_SIZE);
 if (bios_name == NULL)
 bios_name = PROM_FILENAME;
 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
-cpu_register_physical_memory(PROM_ADDR, BIOS_SIZE, bios_offset | 
IO_MEM_ROM);
+memory_region_set_readonly(bios, true);
+memory_region_add_subregion(sysmem, PROM_ADDR, bios);
 
 /* Load OpenBIOS (ELF) */
 if (filename) {
-- 
1.7.6.3




[Qemu-devel] [PATCH 06/18] ppcr500_mpc8544ds: convert to memory API

2011-10-19 Thread Avi Kivity
Signed-off-by: Avi Kivity 
---
 hw/ppce500_mpc8544ds.c |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/ppce500_mpc8544ds.c b/hw/ppce500_mpc8544ds.c
index 5bf8eab..51b6abd 100644
--- a/hw/ppce500_mpc8544ds.c
+++ b/hw/ppce500_mpc8544ds.c
@@ -229,6 +229,7 @@ static void mpc8544ds_init(ram_addr_t ram_size,
  const char *cpu_model)
 {
 MemoryRegion *address_space_mem = get_system_memory();
+MemoryRegion *ram = g_new(MemoryRegion, 1);
 PCIBus *pci_bus;
 CPUState *env = NULL;
 uint64_t elf_entry;
@@ -291,8 +292,8 @@ static void mpc8544ds_init(ram_addr_t ram_size,
 ram_size &= ~(RAM_SIZES_ALIGN - 1);
 
 /* Register Memory */
-cpu_register_physical_memory(0, ram_size, qemu_ram_alloc(NULL,
- "mpc8544ds.ram", ram_size));
+memory_region_init_ram(ram, NULL, "mpc8544ds.ram", ram_size);
+memory_region_add_subregion(address_space_mem, 0, ram);
 
 /* MPIC */
 mpic = mpic_init(address_space_mem, MPC8544_MPIC_REGS_BASE,
-- 
1.7.6.3




[Qemu-devel] [PATCH 07/18] r2d: convert to memory API

2011-10-19 Thread Avi Kivity
Signed-off-by: Avi Kivity 
---
 hw/r2d.c |   35 +++
 1 files changed, 15 insertions(+), 20 deletions(-)

diff --git a/hw/r2d.c b/hw/r2d.c
index 82377a0..b65fd42 100644
--- a/hw/r2d.c
+++ b/hw/r2d.c
@@ -82,6 +82,7 @@
 
 /* output pin */
 qemu_irq irl;
+MemoryRegion iomem;
 } r2d_fpga_t;
 
 enum r2d_fpga_irq {
@@ -168,31 +169,25 @@ static uint32_t r2d_fpga_read(void *opaque, 
target_phys_addr_t addr)
 }
 }
 
-static CPUReadMemoryFunc * const r2d_fpga_readfn[] = {
-r2d_fpga_read,
-r2d_fpga_read,
-NULL,
+static const MemoryRegionOps r2d_fpga_ops = {
+.old_mmio = {
+.read = { r2d_fpga_read, r2d_fpga_read, NULL, },
+.write = { r2d_fpga_write, r2d_fpga_write, NULL, },
+},
+.endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static CPUWriteMemoryFunc * const r2d_fpga_writefn[] = {
-r2d_fpga_write,
-r2d_fpga_write,
-NULL,
-};
-
-static qemu_irq *r2d_fpga_init(target_phys_addr_t base, qemu_irq irl)
+static qemu_irq *r2d_fpga_init(MemoryRegion *sysmem,
+   target_phys_addr_t base, qemu_irq irl)
 {
-int iomemtype;
 r2d_fpga_t *s;
 
 s = g_malloc0(sizeof(r2d_fpga_t));
 
 s->irl = irl;
 
-iomemtype = cpu_register_io_memory(r2d_fpga_readfn,
-  r2d_fpga_writefn, s,
-   DEVICE_NATIVE_ENDIAN);
-cpu_register_physical_memory(base, 0x40, iomemtype);
+memory_region_init_io(&s->iomem, &r2d_fpga_ops, s, "r2d-fpga", 0x40);
+memory_region_add_subregion(sysmem, base, &s->iomem);
 return qemu_allocate_irqs(r2d_fpga_irq_set, s, NR_IRQS);
 }
 
@@ -232,7 +227,7 @@ static void r2d_init(ram_addr_t ram_size,
 CPUState *env;
 ResetData *reset_info;
 struct SH7750State *s;
-ram_addr_t sdram_addr;
+MemoryRegion *sdram = g_new(MemoryRegion, 1);
 qemu_irq *irq;
 DriveInfo *dinfo;
 int i;
@@ -252,11 +247,11 @@ static void r2d_init(ram_addr_t ram_size,
 qemu_register_reset(main_cpu_reset, reset_info);
 
 /* Allocate memory space */
-sdram_addr = qemu_ram_alloc(NULL, "r2d.sdram", SDRAM_SIZE);
-cpu_register_physical_memory(SDRAM_BASE, SDRAM_SIZE, sdram_addr);
+memory_region_init_ram(sdram, NULL, "r2d.sdram", SDRAM_SIZE);
+memory_region_add_subregion(address_space_mem, SDRAM_BASE, sdram);
 /* Register peripherals */
 s = sh7750_init(env);
-irq = r2d_fpga_init(0x0400, sh7750_irl(s));
+irq = r2d_fpga_init(address_space_mem, 0x0400, sh7750_irl(s));
 sysbus_create_varargs("sh_pci", 0x1e20, irq[PCI_INTA], irq[PCI_INTB],
   irq[PCI_INTC], irq[PCI_INTD], NULL);
 
-- 
1.7.6.3




[Qemu-devel] [PATCH 08/18] realview: convert to memory API

2011-10-19 Thread Avi Kivity
Signed-off-by: Avi Kivity 
---
 hw/realview.c |   54 ++
 1 files changed, 26 insertions(+), 28 deletions(-)

diff --git a/hw/realview.c b/hw/realview.c
index 11ffb8a..14281b0 100644
--- a/hw/realview.c
+++ b/hw/realview.c
@@ -18,17 +18,20 @@
 #include "boards.h"
 #include "bitbang_i2c.h"
 #include "blockdev.h"
+#include "exec-memory.h"
 
 #define SMP_BOOT_ADDR 0xe000
 
 typedef struct {
 SysBusDevice busdev;
+MemoryRegion iomem;
 bitbang_i2c_interface *bitbang;
 int out;
 int in;
 } RealViewI2CState;
 
-static uint32_t realview_i2c_read(void *opaque, target_phys_addr_t offset)
+static uint64_t realview_i2c_read(void *opaque, target_phys_addr_t offset,
+  unsigned size)
 {
 RealViewI2CState *s = (RealViewI2CState *)opaque;
 
@@ -41,7 +44,7 @@ static uint32_t realview_i2c_read(void *opaque, 
target_phys_addr_t offset)
 }
 
 static void realview_i2c_write(void *opaque, target_phys_addr_t offset,
-   uint32_t value)
+   uint64_t value, unsigned size)
 {
 RealViewI2CState *s = (RealViewI2CState *)opaque;
 
@@ -59,30 +62,22 @@ static void realview_i2c_write(void *opaque, 
target_phys_addr_t offset,
 s->in = bitbang_i2c_set(s->bitbang, BITBANG_I2C_SDA, (s->out & 2) != 0);
 }
 
-static CPUReadMemoryFunc * const realview_i2c_readfn[] = {
-   realview_i2c_read,
-   realview_i2c_read,
-   realview_i2c_read
-};
-
-static CPUWriteMemoryFunc * const realview_i2c_writefn[] = {
-   realview_i2c_write,
-   realview_i2c_write,
-   realview_i2c_write
+static const MemoryRegionOps realview_i2c_ops = {
+.read = realview_i2c_read,
+.write = realview_i2c_write,
+.endianness = DEVICE_NATIVE_ENDIAN,
 };
 
 static int realview_i2c_init(SysBusDevice *dev)
 {
 RealViewI2CState *s = FROM_SYSBUS(RealViewI2CState, dev);
 i2c_bus *bus;
-int iomemtype;
 
 bus = i2c_init_bus(&dev->qdev, "i2c");
 s->bitbang = bitbang_i2c_init(bus);
-iomemtype = cpu_register_io_memory(realview_i2c_readfn,
-   realview_i2c_writefn, s,
-   DEVICE_NATIVE_ENDIAN);
-sysbus_init_mmio(dev, 0x1000, iomemtype);
+memory_region_init_io(&s->iomem, &realview_i2c_ops, s,
+  "realview-i2c", 0x1000);
+sysbus_init_mmio_region(dev, &s->iomem);
 return 0;
 }
 
@@ -125,7 +120,11 @@ static void realview_init(ram_addr_t ram_size,
  enum realview_board_type board_type)
 {
 CPUState *env = NULL;
-ram_addr_t ram_offset;
+MemoryRegion *sysmem = get_system_memory();
+MemoryRegion *ram_lo = g_new(MemoryRegion, 1);
+MemoryRegion *ram_hi = g_new(MemoryRegion, 1);
+MemoryRegion *ram_alias = g_new(MemoryRegion, 1);
+MemoryRegion *ram_hack = g_new(MemoryRegion, 1);
 DeviceState *dev, *sysctl, *gpio2;
 SysBusDevice *busdev;
 qemu_irq *irqp;
@@ -184,21 +183,21 @@ static void realview_init(ram_addr_t ram_size,
 /* Core tile RAM.  */
 low_ram_size = ram_size - 0x2000;
 ram_size = 0x2000;
-ram_offset = qemu_ram_alloc(NULL, "realview.lowmem", low_ram_size);
-cpu_register_physical_memory(0x2000, low_ram_size,
- ram_offset | IO_MEM_RAM);
+memory_region_init_ram(ram_lo, NULL, "realview.lowmem", low_ram_size);
+memory_region_add_subregion(sysmem, 0x2000, ram_lo);
 }
 
-ram_offset = qemu_ram_alloc(NULL, "realview.highmem", ram_size);
+memory_region_init_ram(ram_hi, NULL, "realview.highmem", ram_size);
 low_ram_size = ram_size;
 if (low_ram_size > 0x1000)
   low_ram_size = 0x1000;
 /* SDRAM at address zero.  */
-cpu_register_physical_memory(0, low_ram_size, ram_offset | IO_MEM_RAM);
+memory_region_init_alias(ram_alias, "realview.alias",
+ ram_hi, 0, low_ram_size);
+memory_region_add_subregion(sysmem, 0, ram_alias);
 if (is_pb) {
 /* And again at a high address.  */
-cpu_register_physical_memory(0x7000, ram_size,
- ram_offset | IO_MEM_RAM);
+memory_region_add_subregion(sysmem, 0x7000, ram_hi);
 } else {
 ram_size = low_ram_size;
 }
@@ -372,9 +371,8 @@ static void realview_init(ram_addr_t ram_size,
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.  */
-ram_offset = qemu_ram_alloc(NULL, "realview.hack", 0x1000);
-cpu_register_physical_memory(SMP_BOOT_ADDR, 0x1000,
- ram_offset | IO_MEM_RAM);
+memory_region_init_ram(ram_hack, NULL, "realview.hack", 0x1000);
+memory_region_add_subregion(sysmem, SMP_BOOT_ADDR, ram_hack);
 
 realview_binfo.ram_size = ram_size;
 re

[Qemu-devel] [PATCH 10/18] sm501: convert to memory API

2011-10-19 Thread Avi Kivity
Signed-off-by: Avi Kivity 
---
 hw/sm501.c |  143 +--
 1 files changed, 70 insertions(+), 73 deletions(-)

diff --git a/hw/sm501.c b/hw/sm501.c
index a7ed6fa..297bc9c 100644
--- a/hw/sm501.c
+++ b/hw/sm501.c
@@ -459,7 +459,7 @@
 target_phys_addr_t base;
 uint32_t local_mem_size_index;
 uint8_t * local_mem;
-ram_addr_t local_mem_offset;
+MemoryRegion local_mem_region;
 uint32_t last_width;
 uint32_t last_height;
 
@@ -726,7 +726,8 @@ static void sm501_2d_operation(SM501State * s)
 }
 }
 
-static uint32_t sm501_system_config_read(void *opaque, target_phys_addr_t addr)
+static uint64_t sm501_system_config_read(void *opaque, target_phys_addr_t addr,
+ unsigned size)
 {
 SM501State * s = (SM501State *)opaque;
 uint32_t ret = 0;
@@ -778,12 +779,12 @@ static uint32_t sm501_system_config_read(void *opaque, 
target_phys_addr_t addr)
 return ret;
 }
 
-static void sm501_system_config_write(void *opaque,
- target_phys_addr_t addr, uint32_t value)
+static void sm501_system_config_write(void *opaque, target_phys_addr_t addr,
+  uint64_t value, unsigned size)
 {
 SM501State * s = (SM501State *)opaque;
 SM501_DPRINTF("sm501 system config regs : write addr=%x, val=%x\n",
- addr, value);
+ (uint32_t)addr, (uint32_t)value);
 
 switch(addr) {
 case SM501_SYSTEM_CONTROL:
@@ -821,21 +822,19 @@ static void sm501_system_config_write(void *opaque,
 
 default:
printf("sm501 system config : not implemented register write."
-  " addr=%x, val=%x\n", (int)addr, value);
+  " addr=%x, val=%x\n", (int)addr, (uint32_t)value);
 abort();
 }
 }
 
-static CPUReadMemoryFunc * const sm501_system_config_readfn[] = {
-NULL,
-NULL,
-&sm501_system_config_read,
-};
-
-static CPUWriteMemoryFunc * const sm501_system_config_writefn[] = {
-NULL,
-NULL,
-&sm501_system_config_write,
+static const MemoryRegionOps sm501_system_config_ops = {
+.read = sm501_system_config_read,
+.write = sm501_system_config_write,
+.valid = {
+.min_access_size = 4,
+.max_access_size = 4,
+},
+.endianness = DEVICE_NATIVE_ENDIAN,
 };
 
 static uint32_t sm501_palette_read(void *opaque, target_phys_addr_t addr)
@@ -864,7 +863,8 @@ static void sm501_palette_write(void *opaque,
 *(uint32_t*)&s->dc_palette[addr] = value;
 }
 
-static uint32_t sm501_disp_ctrl_read(void *opaque, target_phys_addr_t addr)
+static uint64_t sm501_disp_ctrl_read(void *opaque, target_phys_addr_t addr,
+ unsigned size)
 {
 SM501State * s = (SM501State *)opaque;
 uint32_t ret = 0;
@@ -958,13 +958,12 @@ static uint32_t sm501_disp_ctrl_read(void *opaque, 
target_phys_addr_t addr)
 return ret;
 }
 
-static void sm501_disp_ctrl_write(void *opaque,
-  target_phys_addr_t addr,
-  uint32_t value)
+static void sm501_disp_ctrl_write(void *opaque, target_phys_addr_t addr,
+  uint64_t value, unsigned size)
 {
 SM501State * s = (SM501State *)opaque;
 SM501_DPRINTF("sm501 disp ctrl regs : write addr=%x, val=%x\n",
- addr, value);
+ (unsigned)addr, (unsigned)value);
 
 switch(addr) {
 case SM501_DC_PANEL_CONTROL:
@@ -1059,24 +1058,23 @@ static void sm501_disp_ctrl_write(void *opaque,
 
 default:
printf("sm501 disp ctrl : not implemented register write."
-  " addr=%x, val=%x\n", (int)addr, value);
+  " addr=%x, val=%x\n", (int)addr, (unsigned)value);
 abort();
 }
 }
 
-static CPUReadMemoryFunc * const sm501_disp_ctrl_readfn[] = {
-NULL,
-NULL,
-&sm501_disp_ctrl_read,
-};
-
-static CPUWriteMemoryFunc * const sm501_disp_ctrl_writefn[] = {
-NULL,
-NULL,
-&sm501_disp_ctrl_write,
+static const MemoryRegionOps sm501_disp_ctrl_ops = {
+.read = sm501_disp_ctrl_read,
+.write = sm501_disp_ctrl_write,
+.valid = {
+.min_access_size = 4,
+.max_access_size = 4,
+},
+.endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static uint32_t sm501_2d_engine_read(void *opaque, target_phys_addr_t addr)
+static uint64_t sm501_2d_engine_read(void *opaque, target_phys_addr_t addr,
+ unsigned size)
 {
 SM501State * s = (SM501State *)opaque;
 uint32_t ret = 0;
@@ -1095,12 +1093,12 @@ static uint32_t sm501_2d_engine_read(void *opaque, 
target_phys_addr_t addr)
 return ret;
 }
 
-static void sm501_2d_engine_write(void *opaque,
-  target_phys_addr_t addr, uint32_t value)
+static void sm501_2d_engine_write(void *opaque, target_phys_addr_t addr,
+  uint64_t value, unsigned size)
 {

[Qemu-devel] [PATCH 17/18] tc63963xb: convert to memory API

2011-10-19 Thread Avi Kivity
Signed-off-by: Avi Kivity 
---
 hw/devices.h  |3 +-
 hw/tc6393xb.c |   71 +---
 hw/tosa.c |2 +-
 3 files changed, 25 insertions(+), 51 deletions(-)

diff --git a/hw/devices.h b/hw/devices.h
index 8ac384f..1a55c1e 100644
--- a/hw/devices.h
+++ b/hw/devices.h
@@ -53,7 +53,8 @@ void retu_key_event(void *retu, int state);
 /* tc6393xb.c */
 typedef struct TC6393xbState TC6393xbState;
 #define TC6393XB_RAM   0x11 /* amount of ram for Video and USB */
-TC6393xbState *tc6393xb_init(uint32_t base, qemu_irq irq);
+TC6393xbState *tc6393xb_init(struct MemoryRegion *sysmem,
+ uint32_t base, qemu_irq irq);
 void tc6393xb_gpio_out_set(TC6393xbState *s, int line,
 qemu_irq handler);
 qemu_irq *tc6393xb_gpio_in_get(TC6393xbState *s);
diff --git a/hw/tc6393xb.c b/hw/tc6393xb.c
index c28005a..c144dcf 100644
--- a/hw/tc6393xb.c
+++ b/hw/tc6393xb.c
@@ -79,6 +79,7 @@
 #define NAND_MODE_ECC_RST   0x60
 
 struct TC6393xbState {
+MemoryRegion iomem;
 qemu_irq irq;
 qemu_irq *sub_irqs;
 struct {
@@ -122,7 +123,7 @@ struct TC6393xbState {
 ECCState ecc;
 
 DisplayState *ds;
-ram_addr_t vram_addr;
+MemoryRegion vram;
 uint16_t *vram_ptr;
 uint32_t scr_width, scr_height; /* in pixels */
 qemu_irq l3v;
@@ -495,7 +496,9 @@ static void tc6393xb_update_display(void *opaque)
 }
 
 
-static uint32_t tc6393xb_readb(void *opaque, target_phys_addr_t addr) {
+static uint64_t tc6393xb_readb(void *opaque, target_phys_addr_t addr,
+   unsigned size)
+{
 TC6393xbState *s = opaque;
 
 switch (addr >> 8) {
@@ -516,7 +519,8 @@ static uint32_t tc6393xb_readb(void *opaque, 
target_phys_addr_t addr) {
 return 0;
 }
 
-static void tc6393xb_writeb(void *opaque, target_phys_addr_t addr, uint32_t 
value) {
+static void tc6393xb_writeb(void *opaque, target_phys_addr_t addr,
+uint64_t value, unsigned size) {
 TC6393xbState *s = opaque;
 
 switch (addr >> 8) {
@@ -532,51 +536,21 @@ static void tc6393xb_writeb(void *opaque, 
target_phys_addr_t addr, uint32_t valu
 tc6393xb_nand_writeb(s, addr & 0xff, value);
 else
 fprintf(stderr, "tc6393xb: unhandled write at %08x: %02x\n",
-   (uint32_t) addr, value & 0xff);
-}
-
-static uint32_t tc6393xb_readw(void *opaque, target_phys_addr_t addr)
-{
-return (tc6393xb_readb(opaque, addr) & 0xff) |
-(tc6393xb_readb(opaque, addr + 1) << 8);
-}
-
-static uint32_t tc6393xb_readl(void *opaque, target_phys_addr_t addr)
-{
-return (tc6393xb_readb(opaque, addr) & 0xff) |
-((tc6393xb_readb(opaque, addr + 1) & 0xff) << 8) |
-((tc6393xb_readb(opaque, addr + 2) & 0xff) << 16) |
-((tc6393xb_readb(opaque, addr + 3) & 0xff) << 24);
+(uint32_t) addr, (int)value & 0xff);
 }
 
-static void tc6393xb_writew(void *opaque, target_phys_addr_t addr, uint32_t 
value)
+TC6393xbState *tc6393xb_init(MemoryRegion *sysmem, uint32_t base, qemu_irq irq)
 {
-tc6393xb_writeb(opaque, addr, value);
-tc6393xb_writeb(opaque, addr + 1, value >> 8);
-}
-
-static void tc6393xb_writel(void *opaque, target_phys_addr_t addr, uint32_t 
value)
-{
-tc6393xb_writeb(opaque, addr, value);
-tc6393xb_writeb(opaque, addr + 1, value >> 8);
-tc6393xb_writeb(opaque, addr + 2, value >> 16);
-tc6393xb_writeb(opaque, addr + 3, value >> 24);
-}
-
-TC6393xbState *tc6393xb_init(uint32_t base, qemu_irq irq)
-{
-int iomemtype;
 TC6393xbState *s;
 DriveInfo *nand;
-CPUReadMemoryFunc * const tc6393xb_readfn[] = {
-tc6393xb_readb,
-tc6393xb_readw,
-tc6393xb_readl,
-};
-CPUWriteMemoryFunc * const tc6393xb_writefn[] = {
-tc6393xb_writeb,
-tc6393xb_writew,
-tc6393xb_writel,
+static const MemoryRegionOps tc6393xb_ops = {
+.read = tc6393xb_readb,
+.write = tc6393xb_writeb,
+.endianness = DEVICE_NATIVE_ENDIAN,
+.impl = {
+.min_access_size = 1,
+.max_access_size = 1,
+},
 };
 
 s = (TC6393xbState *) g_malloc0(sizeof(TC6393xbState));
@@ -591,13 +565,12 @@ static void tc6393xb_writel(void *opaque, 
target_phys_addr_t addr, uint32_t valu
 nand = drive_get(IF_MTD, 0, 0);
 s->flash = nand_init(nand ? nand->bdrv : NULL, NAND_MFR_TOSHIBA, 0x76);
 
-iomemtype = cpu_register_io_memory(tc6393xb_readfn,
-tc6393xb_writefn, s, DEVICE_NATIVE_ENDIAN);
-cpu_register_physical_memory(base, 0x1, iomemtype);
+memory_region_init_io(&s->iomem, &tc6393xb_ops, s, "tc6393xb", 0x1);
+memory_region_add_subregion(sysmem, base, &s->iomem);
 
-s->vram_addr = qemu_ram_alloc(NULL, "tc6393xb.vram", 0x10);
-s->vram_ptr = qemu_get_ram_ptr(s->vram_addr);
-cpu_register_physical_memory(base + 0x10, 0x10, s->vram_addr);
+memory_region_init_ram(&s

[Qemu-devel] [PATCH 16/18] syborg: convert to memory API

2011-10-19 Thread Avi Kivity
Signed-off-by: Avi Kivity 
---
 hw/syborg.c |8 +---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/hw/syborg.c b/hw/syborg.c
index bc200e4..248de54 100644
--- a/hw/syborg.c
+++ b/hw/syborg.c
@@ -26,6 +26,7 @@
 #include "boards.h"
 #include "arm-misc.h"
 #include "net.h"
+#include "exec-memory.h"
 
 static struct arm_boot_info syborg_binfo;
 
@@ -35,9 +36,10 @@ static void syborg_init(ram_addr_t ram_size,
 const char *initrd_filename, const char *cpu_model)
 {
 CPUState *env;
+MemoryRegion *sysmem = get_system_memory();
+MemoryRegion *ram = g_new(MemoryRegion, 1);
 qemu_irq *cpu_pic;
 qemu_irq pic[64];
-ram_addr_t ram_addr;
 DeviceState *dev;
 int i;
 
@@ -50,8 +52,8 @@ static void syborg_init(ram_addr_t ram_size,
 }
 
 /* RAM at address zero. */
-ram_addr = qemu_ram_alloc(NULL, "syborg.ram", ram_size);
-cpu_register_physical_memory(0, ram_size, ram_addr | IO_MEM_RAM);
+memory_region_init_ram(ram, NULL, "syborg.ram", ram_size);
+memory_region_add_subregion(sysmem, 0, ram);
 
 cpu_pic = arm_pic_init_cpu(env);
 dev = sysbus_create_simple("syborg,interrupt", 0xC000,
-- 
1.7.6.3




[Qemu-devel] [PATCH 02/18] ppc_prep: convert to memory API

2011-10-19 Thread Avi Kivity
Signed-off-by: Avi Kivity 
---
 hw/ppc_prep.c |  107 ++---
 1 files changed, 41 insertions(+), 66 deletions(-)

diff --git a/hw/ppc_prep.c b/hw/ppc_prep.c
index 6427baa..f22d5b9 100644
--- a/hw/ppc_prep.c
+++ b/hw/ppc_prep.c
@@ -116,16 +116,17 @@ static uint32_t speaker_ioport_read (void *opaque, 
uint32_t addr)
 
 /* PCI intack register */
 /* Read-only register (?) */
-static void _PPC_intack_write (void *opaque,
-   target_phys_addr_t addr, uint32_t value)
+static void PPC_intack_write (void *opaque, target_phys_addr_t addr,
+  uint64_t value, unsigned size)
 {
 #if 0
-printf("%s: 0x" TARGET_FMT_plx " => 0x%08" PRIx32 "\n", __func__, addr,
+printf("%s: 0x" TARGET_FMT_plx " => 0x%08" PRIx64 "\n", __func__, addr,
value);
 #endif
 }
 
-static inline uint32_t _PPC_intack_read(target_phys_addr_t addr)
+static uint64_t PPC_intack_read(void *opaque, target_phys_addr_t addr,
+unsigned size)
 {
 uint32_t retval = 0;
 
@@ -139,31 +140,10 @@ static inline uint32_t 
_PPC_intack_read(target_phys_addr_t addr)
 return retval;
 }
 
-static uint32_t PPC_intack_readb (void *opaque, target_phys_addr_t addr)
-{
-return _PPC_intack_read(addr);
-}
-
-static uint32_t PPC_intack_readw (void *opaque, target_phys_addr_t addr)
-{
-return _PPC_intack_read(addr);
-}
-
-static uint32_t PPC_intack_readl (void *opaque, target_phys_addr_t addr)
-{
-return _PPC_intack_read(addr);
-}
-
-static CPUWriteMemoryFunc * const PPC_intack_write[] = {
-&_PPC_intack_write,
-&_PPC_intack_write,
-&_PPC_intack_write,
-};
-
-static CPUReadMemoryFunc * const PPC_intack_read[] = {
-&PPC_intack_readb,
-&PPC_intack_readw,
-&PPC_intack_readl,
+static const MemoryRegionOps PPC_intack_ops = {
+.read = PPC_intack_read,
+.write = PPC_intack_write,
+.endianness = DEVICE_LITTLE_ENDIAN,
 };
 
 /* PowerPC control and status registers */
@@ -244,17 +224,14 @@ static uint32_t PPC_XCSR_readl (void *opaque, 
target_phys_addr_t addr)
 return retval;
 }
 
-static CPUWriteMemoryFunc * const PPC_XCSR_write[] = {
-&PPC_XCSR_writeb,
-&PPC_XCSR_writew,
-&PPC_XCSR_writel,
+static const MemoryRegionOps PPC_XCSR_ops = {
+.old_mmio = {
+.read = { PPC_XCSR_readb, PPC_XCSR_readw, PPC_XCSR_readl, },
+.write = { PPC_XCSR_writeb, PPC_XCSR_writew, PPC_XCSR_writel, },
+},
+.endianness = DEVICE_LITTLE_ENDIAN,
 };
 
-static CPUReadMemoryFunc * const PPC_XCSR_read[] = {
-&PPC_XCSR_readb,
-&PPC_XCSR_readw,
-&PPC_XCSR_readl,
-};
 #endif
 
 /* Fake super-io ports for PREP platform (Intel 82378ZB) */
@@ -503,16 +480,12 @@ static uint32_t PPC_prep_io_readl (void *opaque, 
target_phys_addr_t addr)
 return ret;
 }
 
-static CPUWriteMemoryFunc * const PPC_prep_io_write[] = {
-&PPC_prep_io_writeb,
-&PPC_prep_io_writew,
-&PPC_prep_io_writel,
-};
-
-static CPUReadMemoryFunc * const PPC_prep_io_read[] = {
-&PPC_prep_io_readb,
-&PPC_prep_io_readw,
-&PPC_prep_io_readl,
+static const MemoryRegionOps PPC_prep_io_ops = {
+.old_mmio = {
+.read = { PPC_prep_io_readb, PPC_prep_io_readw, PPC_prep_io_readl },
+.write = { PPC_prep_io_writeb, PPC_prep_io_writew, PPC_prep_io_writel 
},
+},
+.endianness = DEVICE_LITTLE_ENDIAN,
 };
 
 #define NVRAM_SIZE0x2000
@@ -534,13 +507,19 @@ static void ppc_prep_init (ram_addr_t ram_size,
const char *initrd_filename,
const char *cpu_model)
 {
+MemoryRegion *sysmem = get_system_memory();
 CPUState *env = NULL;
 char *filename;
 nvram_t nvram;
 M48t59State *m48t59;
-int PPC_io_memory;
+MemoryRegion *PPC_io_memory = g_new(MemoryRegion, 1);
+MemoryRegion *intack = g_new(MemoryRegion, 1);
+#if 0
+MemoryRegion *xcsr = g_new(MemoryRegion, 1);
+#endif
 int linux_boot, i, nb_nics1, bios_size;
-ram_addr_t ram_offset, bios_offset;
+MemoryRegion *ram = g_new(MemoryRegion, 1);
+MemoryRegion *bios = g_new(MemoryRegion, 1);
 uint32_t kernel_base, initrd_base;
 long kernel_size, initrd_size;
 PCIBus *pci_bus;
@@ -574,11 +553,11 @@ static void ppc_prep_init (ram_addr_t ram_size,
 }
 
 /* allocate RAM */
-ram_offset = qemu_ram_alloc(NULL, "ppc_prep.ram", ram_size);
-cpu_register_physical_memory(0, ram_size, ram_offset);
+memory_region_init_ram(ram, NULL, "ppc_prep.ram", ram_size);
+memory_region_add_subregion(sysmem, 0, ram);
 
 /* allocate and load BIOS */
-bios_offset = qemu_ram_alloc(NULL, "ppc_prep.bios", BIOS_SIZE);
+memory_region_init_ram(bios, NULL, "ppc_prep.bios", BIOS_SIZE);
 if (bios_name == NULL)
 bios_name = BIOS_FILENAME;
 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
@@ -591,8 +570,8 @@ static void ppc_prep_init (ram_addr_t ram_size,
 target_phys_addr_t bios_a

[Qemu-devel] [PATCH 05/18] pci: simplify memory region registration

2011-10-19 Thread Avi Kivity
The two code paths (for ADDRESS_SPACE_IO and ADDRESS_SPACE_MEM) are
identical.  Unify them.

Signed-off-by: Avi Kivity 
---
 hw/pci.c |   13 ++---
 1 files changed, 2 insertions(+), 11 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index 749e8d8..e8cc1b0 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -998,17 +998,8 @@ static void pci_update_mappings(PCIDevice *d)
 }
 r->addr = new_addr;
 if (r->addr != PCI_BAR_UNMAPPED) {
-if (r->type & PCI_BASE_ADDRESS_SPACE_IO) {
-memory_region_add_subregion_overlap(r->address_space,
-r->addr,
-r->memory,
-1);
-} else {
-memory_region_add_subregion_overlap(r->address_space,
-r->addr,
-r->memory,
-1);
-}
+memory_region_add_subregion_overlap(r->address_space,
+r->addr, r->memory, 1);
 }
 }
 }
-- 
1.7.6.3




[Qemu-devel] [PATCH 09/18] s390-virtio: convert to memory API

2011-10-19 Thread Avi Kivity
Signed-off-by: Avi Kivity 
---
 hw/s390-virtio.c |8 +---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/hw/s390-virtio.c b/hw/s390-virtio.c
index 778cffe..60c66e9 100644
--- a/hw/s390-virtio.c
+++ b/hw/s390-virtio.c
@@ -29,6 +29,7 @@
 #include "hw/virtio.h"
 #include "hw/sysbus.h"
 #include "kvm.h"
+#include "exec-memory.h"
 
 #include "hw/s390-virtio-bus.h"
 
@@ -128,7 +129,8 @@ static void s390_init(ram_addr_t my_ram_size,
   const char *cpu_model)
 {
 CPUState *env = NULL;
-ram_addr_t ram_addr;
+MemoryRegion *sysmem = get_system_memory();
+MemoryRegion *ram = g_new(MemoryRegion, 1);
 ram_addr_t kernel_size = 0;
 ram_addr_t initrd_offset;
 ram_addr_t initrd_size = 0;
@@ -150,8 +152,8 @@ static void s390_init(ram_addr_t my_ram_size,
 s390_bus = s390_virtio_bus_init(&my_ram_size);
 
 /* allocate RAM */
-ram_addr = qemu_ram_alloc(NULL, "s390.ram", my_ram_size);
-cpu_register_physical_memory(0, my_ram_size, ram_addr);
+memory_region_init_ram(ram, NULL, "s390.ram", my_ram_size);
+memory_region_add_subregion(sysmem, 0, ram);
 
 /* allocate storage keys */
 storage_keys = g_malloc0(my_ram_size / TARGET_PAGE_SIZE);
-- 
1.7.6.3




[Qemu-devel] [PATCH 14/18] sun4m: convert to memory API

2011-10-19 Thread Avi Kivity
Signed-off-by: Avi Kivity 
---
 hw/sun4m.c |   49 -
 1 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/hw/sun4m.c b/hw/sun4m.c
index 71bf648..314edc4 100644
--- a/hw/sun4m.c
+++ b/hw/sun4m.c
@@ -593,19 +593,25 @@ static void idreg_init(target_phys_addr_t addr)
 cpu_physical_memory_write_rom(addr, idreg_data, sizeof(idreg_data));
 }
 
+typedef struct IDRegState {
+SysBusDevice busdev;
+MemoryRegion mem;
+} IDRegState;
+
 static int idreg_init1(SysBusDevice *dev)
 {
-ram_addr_t idreg_offset;
+IDRegState *s = FROM_SYSBUS(IDRegState, dev);
 
-idreg_offset = qemu_ram_alloc(NULL, "sun4m.idreg", sizeof(idreg_data));
-sysbus_init_mmio(dev, sizeof(idreg_data), idreg_offset | IO_MEM_ROM);
+memory_region_init_ram(&s->mem, NULL, "sun4m.idreg", sizeof(idreg_data));
+memory_region_set_readonly(&s->mem, true);
+sysbus_init_mmio_region(dev, &s->mem);
 return 0;
 }
 
 static SysBusDeviceInfo idreg_info = {
 .init = idreg_init1,
 .qdev.name  = "macio_idreg",
-.qdev.size  = sizeof(SysBusDevice),
+.qdev.size  = sizeof(IDRegState),
 };
 
 static void idreg_register_devices(void)
@@ -615,6 +621,11 @@ static void idreg_register_devices(void)
 
 device_init(idreg_register_devices);
 
+typedef struct AFXState {
+SysBusDevice busdev;
+MemoryRegion mem;
+} AFXState;
+
 /* SS-5 TCX AFX register */
 static void afx_init(target_phys_addr_t addr)
 {
@@ -630,17 +641,17 @@ static void afx_init(target_phys_addr_t addr)
 
 static int afx_init1(SysBusDevice *dev)
 {
-ram_addr_t afx_offset;
+AFXState *s = FROM_SYSBUS(AFXState, dev);
 
-afx_offset = qemu_ram_alloc(NULL, "sun4m.afx", 4);
-sysbus_init_mmio(dev, 4, afx_offset | IO_MEM_RAM);
+memory_region_init_ram(&s->mem, NULL, "sun4m.afx", 4);
+sysbus_init_mmio_region(dev, &s->mem);
 return 0;
 }
 
 static SysBusDeviceInfo afx_info = {
 .init = afx_init1,
 .qdev.name  = "tcx_afx",
-.qdev.size  = sizeof(SysBusDevice),
+.qdev.size  = sizeof(AFXState),
 };
 
 static void afx_register_devices(void)
@@ -650,6 +661,11 @@ static void afx_register_devices(void)
 
 device_init(afx_register_devices);
 
+typedef struct PROMState {
+SysBusDevice busdev;
+MemoryRegion prom;
+} PROMState;
+
 /* Boot PROM (OpenBIOS) */
 static uint64_t translate_prom_address(void *opaque, uint64_t addr)
 {
@@ -693,17 +709,18 @@ static void prom_init(target_phys_addr_t addr, const char 
*bios_name)
 
 static int prom_init1(SysBusDevice *dev)
 {
-ram_addr_t prom_offset;
+PROMState *s = FROM_SYSBUS(PROMState, dev);
 
-prom_offset = qemu_ram_alloc(NULL, "sun4m.prom", PROM_SIZE_MAX);
-sysbus_init_mmio(dev, PROM_SIZE_MAX, prom_offset | IO_MEM_ROM);
+memory_region_init_ram(&s->prom, NULL, "sun4m.prom", PROM_SIZE_MAX);
+memory_region_set_readonly(&s->prom, true);
+sysbus_init_mmio_region(dev, &s->prom);
 return 0;
 }
 
 static SysBusDeviceInfo prom_info = {
 .init = prom_init1,
 .qdev.name  = "openprom",
-.qdev.size  = sizeof(SysBusDevice),
+.qdev.size  = sizeof(PROMState),
 .qdev.props = (Property[]) {
 {/* end of property list */}
 }
@@ -719,19 +736,17 @@ static void prom_register_devices(void)
 typedef struct RamDevice
 {
 SysBusDevice busdev;
+MemoryRegion ram;
 uint64_t size;
 } RamDevice;
 
 /* System RAM */
 static int ram_init1(SysBusDevice *dev)
 {
-ram_addr_t RAM_size, ram_offset;
 RamDevice *d = FROM_SYSBUS(RamDevice, dev);
 
-RAM_size = d->size;
-
-ram_offset = qemu_ram_alloc(NULL, "sun4m.ram", RAM_size);
-sysbus_init_mmio(dev, RAM_size, ram_offset);
+memory_region_init_ram(&d->ram, NULL, "sun4m.ram", d->size);
+sysbus_init_mmio_region(dev, &d->ram);
 return 0;
 }
 
-- 
1.7.6.3




[Qemu-devel] [PATCH 13/18] strongarm: convert to memory API

2011-10-19 Thread Avi Kivity
Signed-off-by: Avi Kivity 
---
 hw/collie.c|4 +-
 hw/strongarm.c |  171 ++--
 hw/strongarm.h |6 ++-
 3 files changed, 75 insertions(+), 106 deletions(-)

diff --git a/hw/collie.c b/hw/collie.c
index a10cc1b..8dd6e4e 100644
--- a/hw/collie.c
+++ b/hw/collie.c
@@ -13,6 +13,7 @@
 #include "arm-misc.h"
 #include "flash.h"
 #include "blockdev.h"
+#include "exec-memory.h"
 
 static struct arm_boot_info collie_binfo = {
 .loader_start = SA_SDCS0,
@@ -26,12 +27,13 @@ static void collie_init(ram_addr_t ram_size,
 {
 StrongARMState *s;
 DriveInfo *dinfo;
+MemoryRegion *sysmem = get_system_memory();
 
 if (!cpu_model) {
 cpu_model = "sa1110";
 }
 
-s = sa1110_init(collie_binfo.ram_size, cpu_model);
+s = sa1110_init(sysmem, collie_binfo.ram_size, cpu_model);
 
 dinfo = drive_get(IF_PFLASH, 0, 0);
 pflash_cfi01_register(SA_CS0, NULL, "collie.fl1", 0x0200,
diff --git a/hw/strongarm.c b/hw/strongarm.c
index 6097ea2..a3d9080 100644
--- a/hw/strongarm.c
+++ b/hw/strongarm.c
@@ -68,6 +68,7 @@
 /* Interrupt Controller */
 typedef struct {
 SysBusDevice busdev;
+MemoryRegion iomem;
 qemu_irqirq;
 qemu_irqfiq;
 
@@ -109,7 +110,8 @@ static void strongarm_pic_set_irq(void *opaque, int irq, 
int level)
 strongarm_pic_update(s);
 }
 
-static uint32_t strongarm_pic_mem_read(void *opaque, target_phys_addr_t offset)
+static uint64_t strongarm_pic_mem_read(void *opaque, target_phys_addr_t offset,
+   unsigned size)
 {
 StrongARMPICState *s = opaque;
 
@@ -134,7 +136,7 @@ static uint32_t strongarm_pic_mem_read(void *opaque, 
target_phys_addr_t offset)
 }
 
 static void strongarm_pic_mem_write(void *opaque, target_phys_addr_t offset,
-uint32_t value)
+uint64_t value, unsigned size)
 {
 StrongARMPICState *s = opaque;
 
@@ -156,27 +158,19 @@ static void strongarm_pic_mem_write(void *opaque, 
target_phys_addr_t offset,
 strongarm_pic_update(s);
 }
 
-static CPUReadMemoryFunc * const strongarm_pic_readfn[] = {
-strongarm_pic_mem_read,
-strongarm_pic_mem_read,
-strongarm_pic_mem_read,
-};
-
-static CPUWriteMemoryFunc * const strongarm_pic_writefn[] = {
-strongarm_pic_mem_write,
-strongarm_pic_mem_write,
-strongarm_pic_mem_write,
+static const MemoryRegionOps strongarm_pic_ops = {
+.read = strongarm_pic_mem_read,
+.write = strongarm_pic_mem_write,
+.endianness = DEVICE_NATIVE_ENDIAN,
 };
 
 static int strongarm_pic_initfn(SysBusDevice *dev)
 {
 StrongARMPICState *s = FROM_SYSBUS(StrongARMPICState, dev);
-int iomemtype;
 
 qdev_init_gpio_in(&dev->qdev, strongarm_pic_set_irq, SA_PIC_SRCS);
-iomemtype = cpu_register_io_memory(strongarm_pic_readfn,
-strongarm_pic_writefn, s, DEVICE_NATIVE_ENDIAN);
-sysbus_init_mmio(dev, 0x1000, iomemtype);
+memory_region_init_io(&s->iomem, &strongarm_pic_ops, s, "pic", 0x1000);
+sysbus_init_mmio_region(dev, &s->iomem);
 sysbus_init_irq(dev, &s->irq);
 sysbus_init_irq(dev, &s->fiq);
 
@@ -229,6 +223,7 @@ static int strongarm_pic_post_load(void *opaque, int 
version_id)
 
 typedef struct {
 SysBusDevice busdev;
+MemoryRegion iomem;
 uint32_t rttr;
 uint32_t rtsr;
 uint32_t rtar;
@@ -287,7 +282,8 @@ static inline void strongarm_rtc_hz_tick(void *opaque)
 strongarm_rtc_int_update(s);
 }
 
-static uint32_t strongarm_rtc_read(void *opaque, target_phys_addr_t addr)
+static uint64_t strongarm_rtc_read(void *opaque, target_phys_addr_t addr,
+   unsigned size)
 {
 StrongARMRTCState *s = opaque;
 
@@ -309,7 +305,7 @@ static uint32_t strongarm_rtc_read(void *opaque, 
target_phys_addr_t addr)
 }
 
 static void strongarm_rtc_write(void *opaque, target_phys_addr_t addr,
-uint32_t value)
+uint64_t value, unsigned size)
 {
 StrongARMRTCState *s = opaque;
 uint32_t old_rtsr;
@@ -349,23 +345,16 @@ static void strongarm_rtc_write(void *opaque, 
target_phys_addr_t addr,
 }
 }
 
-static CPUReadMemoryFunc * const strongarm_rtc_readfn[] = {
-strongarm_rtc_read,
-strongarm_rtc_read,
-strongarm_rtc_read,
-};
-
-static CPUWriteMemoryFunc * const strongarm_rtc_writefn[] = {
-strongarm_rtc_write,
-strongarm_rtc_write,
-strongarm_rtc_write,
+static const MemoryRegionOps strongarm_rtc_ops = {
+.read = strongarm_rtc_read,
+.write = strongarm_rtc_write,
+.endianness = DEVICE_NATIVE_ENDIAN,
 };
 
 static int strongarm_rtc_init(SysBusDevice *dev)
 {
 StrongARMRTCState *s = FROM_SYSBUS(StrongARMRTCState, dev);
 struct tm tm;
-int iomemtype;
 
 s->rttr = 0x0;
 s->rtsr = 0;
@@ -381,9 +370,8 @@ static int strongarm_rtc_init(SysBusDevice *dev)
 sysbus_init_irq(dev, &s->rtc_irq);
 sysbus_init_irq(dev, &s->rtc_hz_irq);
 
-iomemtype = cpu_re

[Qemu-devel] [PATCH 12/18] spitz: convert to memory API

2011-10-19 Thread Avi Kivity
Signed-off-by: Avi Kivity 
---
 hw/spitz.c |   48 ++--
 1 files changed, 18 insertions(+), 30 deletions(-)

diff --git a/hw/spitz.c b/hw/spitz.c
index 6f8a94c..23f9d41 100644
--- a/hw/spitz.c
+++ b/hw/spitz.c
@@ -49,6 +49,7 @@
 
 typedef struct {
 SysBusDevice busdev;
+MemoryRegion iomem;
 DeviceState *nand;
 uint8_t ctl;
 uint8_t manf_id;
@@ -56,7 +57,7 @@
 ECCState ecc;
 } SLNANDState;
 
-static uint32_t sl_readb(void *opaque, target_phys_addr_t addr)
+static uint64_t sl_read(void *opaque, target_phys_addr_t addr, unsigned size)
 {
 SLNANDState *s = (SLNANDState *) opaque;
 int ryby;
@@ -86,6 +87,10 @@ static uint32_t sl_readb(void *opaque, target_phys_addr_t 
addr)
 return s->ctl;
 
 case FLASH_FLASHIO:
+if (size == 4) {
+return ecc_digest(&s->ecc, nand_getio(s->nand)) |
+(ecc_digest(&s->ecc, nand_getio(s->nand)) << 16);
+}
 return ecc_digest(&s->ecc, nand_getio(s->nand));
 
 default:
@@ -94,19 +99,8 @@ static uint32_t sl_readb(void *opaque, target_phys_addr_t 
addr)
 return 0;
 }
 
-static uint32_t sl_readl(void *opaque, target_phys_addr_t addr)
-{
-SLNANDState *s = (SLNANDState *) opaque;
-
-if (addr == FLASH_FLASHIO)
-return ecc_digest(&s->ecc, nand_getio(s->nand)) |
-(ecc_digest(&s->ecc, nand_getio(s->nand)) << 16);
-
-return sl_readb(opaque, addr);
-}
-
-static void sl_writeb(void *opaque, target_phys_addr_t addr,
-uint32_t value)
+static void sl_write(void *opaque, target_phys_addr_t addr,
+ uint64_t value, unsigned size)
 {
 SLNANDState *s = (SLNANDState *) opaque;
 
@@ -140,15 +134,10 @@ enum {
 FLASH_1024M,
 };
 
-static CPUReadMemoryFunc * const sl_readfn[] = {
-sl_readb,
-sl_readb,
-sl_readl,
-};
-static CPUWriteMemoryFunc * const sl_writefn[] = {
-sl_writeb,
-sl_writeb,
-sl_writeb,
+static const MemoryRegionOps sl_ops = {
+.read = sl_read,
+.write = sl_write,
+.endianness = DEVICE_NATIVE_ENDIAN,
 };
 
 static void sl_flash_register(PXA2xxState *cpu, int size)
@@ -168,7 +157,6 @@ static void sl_flash_register(PXA2xxState *cpu, int size)
 }
 
 static int sl_nand_init(SysBusDevice *dev) {
-int iomemtype;
 SLNANDState *s;
 DriveInfo *nand;
 
@@ -178,10 +166,8 @@ static int sl_nand_init(SysBusDevice *dev) {
 nand = drive_get(IF_MTD, 0, 0);
 s->nand = nand_init(nand ? nand->bdrv : NULL, s->manf_id, s->chip_id);
 
-iomemtype = cpu_register_io_memory(sl_readfn,
-sl_writefn, s, DEVICE_NATIVE_ENDIAN);
-
-sysbus_init_mmio(dev, 0x40, iomemtype);
+memory_region_init_io(&s->iomem, &sl_ops, s, "sl", 0x40);
+sysbus_init_mmio_region(dev, &s->iomem);
 
 return 0;
 }
@@ -898,6 +884,7 @@ static void spitz_common_init(ram_addr_t ram_size,
 PXA2xxState *cpu;
 DeviceState *scp0, *scp1 = NULL;
 MemoryRegion *address_space_mem = get_system_memory();
+MemoryRegion *rom = g_new(MemoryRegion, 1);
 
 if (!cpu_model)
 cpu_model = (model == terrier) ? "pxa270-c5" : "pxa270-c0";
@@ -907,8 +894,9 @@ static void spitz_common_init(ram_addr_t ram_size,
 
 sl_flash_register(cpu, (model == spitz) ? FLASH_128M : FLASH_1024M);
 
-cpu_register_physical_memory(0, SPITZ_ROM,
-qemu_ram_alloc(NULL, "spitz.rom", SPITZ_ROM) | IO_MEM_ROM);
+memory_region_init_ram(rom, NULL, "spitz.rom", SPITZ_ROM);
+memory_region_set_readonly(rom, true);
+memory_region_add_subregion(address_space_mem, 0, rom);
 
 /* Setup peripherals */
 spitz_keyboard_register(cpu);
-- 
1.7.6.3




[Qemu-devel] [PATCH 15/18] sun4u: convert to memory API

2011-10-19 Thread Avi Kivity
Signed-off-by: Avi Kivity 
---
 hw/sun4u.c |   22 +-
 1 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/hw/sun4u.c b/hw/sun4u.c
index 96fc3d0..eaaefe3 100644
--- a/hw/sun4u.c
+++ b/hw/sun4u.c
@@ -574,6 +574,11 @@ static void pci_ebus_register(void)
 
 device_init(pci_ebus_register);
 
+typedef struct PROMState {
+SysBusDevice busdev;
+MemoryRegion prom;
+} PROMState;
+
 static uint64_t translate_prom_address(void *opaque, uint64_t addr)
 {
 target_phys_addr_t *base_addr = (target_phys_addr_t *)opaque;
@@ -617,17 +622,18 @@ static void prom_init(target_phys_addr_t addr, const char 
*bios_name)
 
 static int prom_init1(SysBusDevice *dev)
 {
-ram_addr_t prom_offset;
+PROMState *s = FROM_SYSBUS(PROMState, dev);
 
-prom_offset = qemu_ram_alloc(NULL, "sun4u.prom", PROM_SIZE_MAX);
-sysbus_init_mmio(dev, PROM_SIZE_MAX, prom_offset | IO_MEM_ROM);
+memory_region_init_ram(&s->prom, NULL, "sun4u.prom", PROM_SIZE_MAX);
+memory_region_set_readonly(&s->prom, true);
+sysbus_init_mmio_region(dev, &s->prom);
 return 0;
 }
 
 static SysBusDeviceInfo prom_info = {
 .init = prom_init1,
 .qdev.name  = "openprom",
-.qdev.size  = sizeof(SysBusDevice),
+.qdev.size  = sizeof(PROMState),
 .qdev.props = (Property[]) {
 {/* end of property list */}
 }
@@ -644,19 +650,17 @@ static void prom_register_devices(void)
 typedef struct RamDevice
 {
 SysBusDevice busdev;
+MemoryRegion ram;
 uint64_t size;
 } RamDevice;
 
 /* System RAM */
 static int ram_init1(SysBusDevice *dev)
 {
-ram_addr_t RAM_size, ram_offset;
 RamDevice *d = FROM_SYSBUS(RamDevice, dev);
 
-RAM_size = d->size;
-
-ram_offset = qemu_ram_alloc(NULL, "sun4u.ram", RAM_size);
-sysbus_init_mmio(dev, RAM_size, ram_offset);
+memory_region_init_ram(&d->ram, NULL, "sun4u.ram", d->size);
+sysbus_init_mmio_region(dev, &d->ram);
 return 0;
 }
 
-- 
1.7.6.3




Re: [Qemu-devel] [Question] dump memory when host pci device is used by guest

2011-10-19 Thread Jan Kiszka
On 2011-10-19 04:04, KAMEZAWA Hiroyuki wrote:
> On Tue, 18 Oct 2011 10:31:10 +0200
> Jan Kiszka  wrote:
> 
>> On 2011-10-18 10:31, Wen Congyang wrote:
>>> At 10/18/2011 04:26 PM, Jan Kiszka Write:
 On 2011-10-18 10:25, Wen Congyang wrote:
> At 10/18/2011 04:19 PM, Jan Kiszka Write:
>> On 2011-10-18 09:58, Wen Congyang wrote:
>>> At 10/18/2011 03:52 PM, Jan Kiszka Write:
 On 2011-10-18 09:15, Wen Congyang wrote:
> Hi, Jan Kiszka
>
> At 10/10/2011 05:34 PM, Jan Kiszka Write:
>> On 2011-10-10 11:02, Daniel P. Berrange wrote:
>>> On Mon, Oct 10, 2011 at 08:52:08AM +0200, Jan Kiszka wrote:
>
>>
>> Run gdb with "set debug remote 1" and watch the communication, it is 
>> not
>> that complex. But a dump command is probably simpler for those
>> scenarios, I agree.
>
> I have implemented the command dump and reuse migration's code. But I 
> meet a problem
> when I test it.

 Using migration code for dump is most probably the wrong approach as 
 you
 saw through that conflict. All you need are the register states and the
 RAM. Reuse gdbstub services for this.
>>>
>>> Hmm, if the migration code can not be reused, I think we should define 
>>> a new
>>> qemu's vmcore format, and add some codes into crash to support such 
>>> format.
>>
>> Please try to avoid defining something new. Unless there is a striking
>> reason, standard gdb core files should be generated so that you can load
>> the dump directly into gdb for analysis.
>
> I am not sure whehter the standard gdb core files can not be analyzed by 
> crash.
> If not, I think we should define something new because it's easier to use
> crash than gdb to analyze the core files.

 gdb allows you to walk up the frame and print variables (globals &
 local) etc.
>>>
>>> Crash uses gdb to provide common function, and you can also use all the gdb 
>>> commands
>>> in crash.
>>
>> That what's the added value here when I can use gdb directly?
>>
> 
> I didn't read full story but 'crash' is used for investigating kernel core 
> generated
> by kdump for several years. Considering support service guys, virsh dump 
> should support
> a format for crash because they can't work well at investigating vmcore by 
> gdb.
> 
> crash has several functionality useful for them as 'show kerne log', 'focus 
> on a cpu'
> 'for-each-task', 'for-each-vma', 'extract ftrace log' etc.
> 
> Anyway, if a man, who is not developper of qemu/kvm, should learn 2 tools for
> investigating kernel dump, it sounds harmful.

Right, that's why everything (live debugging & crash analysis) should be
consolidated on the long run over gdb. crash is architecturally obsolete
today - not saying it is useless!

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux



[Qemu-devel] [PATCH 04/18] pxa2xx: convert to memory API (part II)

2011-10-19 Thread Avi Kivity
Signed-off-by: Avi Kivity 
---
 hw/pxa.h|5 ++
 hw/pxa2xx.c |  148 --
 2 files changed, 66 insertions(+), 87 deletions(-)

diff --git a/hw/pxa.h b/hw/pxa.h
index 3fb070f..7e98384 100644
--- a/hw/pxa.h
+++ b/hw/pxa.h
@@ -122,6 +122,11 @@ typedef struct {
 CPUState *env;
 DeviceState *pic;
 qemu_irq reset;
+MemoryRegion sdram;
+MemoryRegion internal;
+MemoryRegion cm_iomem;
+MemoryRegion mm_iomem;
+MemoryRegion pm_iomem;
 DeviceState *dma;
 DeviceState *gpio;
 PXA2xxLCDState *lcd;
diff --git a/hw/pxa2xx.c b/hw/pxa2xx.c
index 19ee094..bfc28a9 100644
--- a/hw/pxa2xx.c
+++ b/hw/pxa2xx.c
@@ -88,7 +88,8 @@
 #define PCMD0  0x80/* Power Manager I2C Command register File 0 */
 #define PCMD31 0xfc/* Power Manager I2C Command register File 31 */
 
-static uint32_t pxa2xx_pm_read(void *opaque, target_phys_addr_t addr)
+static uint64_t pxa2xx_pm_read(void *opaque, target_phys_addr_t addr,
+   unsigned size)
 {
 PXA2xxState *s = (PXA2xxState *) opaque;
 
@@ -107,7 +108,7 @@ static uint32_t pxa2xx_pm_read(void *opaque, 
target_phys_addr_t addr)
 }
 
 static void pxa2xx_pm_write(void *opaque, target_phys_addr_t addr,
-uint32_t value)
+uint64_t value, unsigned size)
 {
 PXA2xxState *s = (PXA2xxState *) opaque;
 
@@ -134,16 +135,10 @@ static void pxa2xx_pm_write(void *opaque, 
target_phys_addr_t addr,
 }
 }
 
-static CPUReadMemoryFunc * const pxa2xx_pm_readfn[] = {
-pxa2xx_pm_read,
-pxa2xx_pm_read,
-pxa2xx_pm_read,
-};
-
-static CPUWriteMemoryFunc * const pxa2xx_pm_writefn[] = {
-pxa2xx_pm_write,
-pxa2xx_pm_write,
-pxa2xx_pm_write,
+static const MemoryRegionOps pxa2xx_pm_ops = {
+.read = pxa2xx_pm_read,
+.write = pxa2xx_pm_write,
+.endianness = DEVICE_NATIVE_ENDIAN,
 };
 
 static const VMStateDescription vmstate_pxa2xx_pm = {
@@ -162,7 +157,8 @@ static void pxa2xx_pm_write(void *opaque, 
target_phys_addr_t addr,
 #define OSCC   0x08/* Oscillator Configuration register */
 #define CCSR   0x0c/* Core Clock Status register */
 
-static uint32_t pxa2xx_cm_read(void *opaque, target_phys_addr_t addr)
+static uint64_t pxa2xx_cm_read(void *opaque, target_phys_addr_t addr,
+   unsigned size)
 {
 PXA2xxState *s = (PXA2xxState *) opaque;
 
@@ -183,7 +179,7 @@ static uint32_t pxa2xx_cm_read(void *opaque, 
target_phys_addr_t addr)
 }
 
 static void pxa2xx_cm_write(void *opaque, target_phys_addr_t addr,
-uint32_t value)
+uint64_t value, unsigned size)
 {
 PXA2xxState *s = (PXA2xxState *) opaque;
 
@@ -206,16 +202,10 @@ static void pxa2xx_cm_write(void *opaque, 
target_phys_addr_t addr,
 }
 }
 
-static CPUReadMemoryFunc * const pxa2xx_cm_readfn[] = {
-pxa2xx_cm_read,
-pxa2xx_cm_read,
-pxa2xx_cm_read,
-};
-
-static CPUWriteMemoryFunc * const pxa2xx_cm_writefn[] = {
-pxa2xx_cm_write,
-pxa2xx_cm_write,
-pxa2xx_cm_write,
+static const MemoryRegionOps pxa2xx_cm_ops = {
+.read = pxa2xx_cm_read,
+.write = pxa2xx_cm_write,
+.endianness = DEVICE_NATIVE_ENDIAN,
 };
 
 static const VMStateDescription vmstate_pxa2xx_cm = {
@@ -461,7 +451,8 @@ static void pxa2xx_cp14_write(void *opaque, int op2, int 
reg, int crm,
 #define BSCNTR30x60/* Memory Buffer Strength Control 
register 3 */
 #define SA1110 0x64/* SA-1110 Memory Compatibility register */
 
-static uint32_t pxa2xx_mm_read(void *opaque, target_phys_addr_t addr)
+static uint64_t pxa2xx_mm_read(void *opaque, target_phys_addr_t addr,
+   unsigned size)
 {
 PXA2xxState *s = (PXA2xxState *) opaque;
 
@@ -478,7 +469,7 @@ static uint32_t pxa2xx_mm_read(void *opaque, 
target_phys_addr_t addr)
 }
 
 static void pxa2xx_mm_write(void *opaque, target_phys_addr_t addr,
-uint32_t value)
+uint64_t value, unsigned size)
 {
 PXA2xxState *s = (PXA2xxState *) opaque;
 
@@ -495,16 +486,10 @@ static void pxa2xx_mm_write(void *opaque, 
target_phys_addr_t addr,
 }
 }
 
-static CPUReadMemoryFunc * const pxa2xx_mm_readfn[] = {
-pxa2xx_mm_read,
-pxa2xx_mm_read,
-pxa2xx_mm_read,
-};
-
-static CPUWriteMemoryFunc * const pxa2xx_mm_writefn[] = {
-pxa2xx_mm_write,
-pxa2xx_mm_write,
-pxa2xx_mm_write,
+static const MemoryRegionOps pxa2xx_mm_ops = {
+.read = pxa2xx_mm_read,
+.write = pxa2xx_mm_write,
+.endianness = DEVICE_NATIVE_ENDIAN,
 };
 
 static const VMStateDescription vmstate_pxa2xx_mm = {
@@ -1764,6 +1749,7 @@ static void pxa2xx_i2s_data_req(void *opaque, int tx, int 
rx)
 
 /* PXA Fast Infra-red Communications Port */
 struct PXA2xxFIrState {
+MemoryRegion iomem;
 qemu_irq irq;
 qemu_irq rx_dma;
 qemu_irq tx_dma;
@@ -1834,7 +1820,8 @@ static inline void pxa2xx_fir_update(PXA2xxFIrState *s)
 #define IC

[Qemu-devel] [PATCH 18/18] tcx: convert to memory API

2011-10-19 Thread Avi Kivity
Signed-off-by: Avi Kivity 
---
 hw/tcx.c |  152 ++---
 1 files changed, 85 insertions(+), 67 deletions(-)

diff --git a/hw/tcx.c b/hw/tcx.c
index 309600d..cd24100 100644
--- a/hw/tcx.c
+++ b/hw/tcx.c
@@ -40,7 +40,15 @@
 DisplayState *ds;
 uint8_t *vram;
 uint32_t *vram24, *cplane;
-ram_addr_t vram_offset, vram24_offset, cplane_offset;
+MemoryRegion vram_mem;
+MemoryRegion vram_8bit;
+MemoryRegion vram_24bit;
+MemoryRegion vram_cplane;
+MemoryRegion dac;
+MemoryRegion tec;
+MemoryRegion thc24;
+MemoryRegion thc8;
+ram_addr_t vram24_offset, cplane_offset;
 uint32_t vram_size;
 uint32_t palette[256];
 uint8_t r[256], g[256], b[256];
@@ -56,7 +64,7 @@ static void tcx_set_dirty(TCXState *s)
 unsigned int i;
 
 for (i = 0; i < MAXX * MAXY; i += TARGET_PAGE_SIZE) {
-cpu_physical_memory_set_dirty(s->vram_offset + i);
+memory_region_set_dirty(&s->vram_mem, i);
 }
 }
 
@@ -65,8 +73,8 @@ static void tcx24_set_dirty(TCXState *s)
 unsigned int i;
 
 for (i = 0; i < MAXX * MAXY * 4; i += TARGET_PAGE_SIZE) {
-cpu_physical_memory_set_dirty(s->vram24_offset + i);
-cpu_physical_memory_set_dirty(s->cplane_offset + i);
+memory_region_set_dirty(&s->vram_mem, s->vram24_offset + i);
+memory_region_set_dirty(&s->vram_mem, s->cplane_offset + i);
 }
 }
 
@@ -174,16 +182,18 @@ static inline void tcx24_draw_line32(TCXState *s1, 
uint8_t *d,
 }
 }
 
-static inline int check_dirty(ram_addr_t page, ram_addr_t page24,
+static inline int check_dirty(TCXState *s, ram_addr_t page, ram_addr_t page24,
   ram_addr_t cpage)
 {
 int ret;
 unsigned int off;
 
-ret = cpu_physical_memory_get_dirty(page, VGA_DIRTY_FLAG);
+ret = memory_region_get_dirty(&s->vram_mem, page, DIRTY_MEMORY_VGA);
 for (off = 0; off < TARGET_PAGE_SIZE * 4; off += TARGET_PAGE_SIZE) {
-ret |= cpu_physical_memory_get_dirty(page24 + off, VGA_DIRTY_FLAG);
-ret |= cpu_physical_memory_get_dirty(cpage + off, VGA_DIRTY_FLAG);
+ret |= memory_region_get_dirty(&s->vram_mem, page24 + off,
+   DIRTY_MEMORY_VGA);
+ret |= memory_region_get_dirty(&s->vram_mem, cpage + off,
+   DIRTY_MEMORY_VGA);
 }
 return ret;
 }
@@ -192,16 +202,17 @@ static inline void reset_dirty(TCXState *ts, ram_addr_t 
page_min,
ram_addr_t page_max, ram_addr_t page24,
   ram_addr_t cpage)
 {
-cpu_physical_memory_reset_dirty(page_min, page_max + TARGET_PAGE_SIZE,
-VGA_DIRTY_FLAG);
-page_min -= ts->vram_offset;
-page_max -= ts->vram_offset;
-cpu_physical_memory_reset_dirty(page24 + page_min * 4,
-page24 + page_max * 4 + TARGET_PAGE_SIZE,
-VGA_DIRTY_FLAG);
-cpu_physical_memory_reset_dirty(cpage + page_min * 4,
-cpage + page_max * 4 + TARGET_PAGE_SIZE,
-VGA_DIRTY_FLAG);
+memory_region_reset_dirty(&ts->vram_mem,
+  page_min, page_max + TARGET_PAGE_SIZE,
+  DIRTY_MEMORY_VGA);
+memory_region_reset_dirty(&ts->vram_mem,
+  page24 + page_min * 4,
+  page24 + page_max * 4 + TARGET_PAGE_SIZE,
+  DIRTY_MEMORY_VGA);
+memory_region_reset_dirty(&ts->vram_mem,
+  cpage + page_min * 4,
+  cpage + page_max * 4 + TARGET_PAGE_SIZE,
+  DIRTY_MEMORY_VGA);
 }
 
 /* Fixed line length 1024 allows us to do nice tricks not possible on
@@ -216,7 +227,7 @@ static void tcx_update_display(void *opaque)
 
 if (ds_get_bits_per_pixel(ts->ds) == 0)
 return;
-page = ts->vram_offset;
+page = 0;
 y_start = -1;
 page_min = -1;
 page_max = 0;
@@ -242,7 +253,7 @@ static void tcx_update_display(void *opaque)
 }
 
 for(y = 0; y < ts->height; y += 4, page += TARGET_PAGE_SIZE) {
-if (cpu_physical_memory_get_dirty(page, VGA_DIRTY_FLAG)) {
+if (memory_region_get_dirty(&ts->vram_mem, page, DIRTY_MEMORY_VGA)) {
 if (y_start < 0)
 y_start = y;
 if (page < page_min)
@@ -279,8 +290,9 @@ static void tcx_update_display(void *opaque)
 }
 /* reset modified pages */
 if (page_max >= page_min) {
-cpu_physical_memory_reset_dirty(page_min, page_max + TARGET_PAGE_SIZE,
-VGA_DIRTY_FLAG);
+memory_region_reset_dirty(&ts->vram_mem,
+  page_min, page_max + TARGET_PAGE_SIZE,
+  DIRTY_MEMORY_VGA);
 }
 }
 
@@ -294,7 +306,7 

[Qemu-devel] [PATCH] integratorcp: convert control to sysbus

2011-10-19 Thread Benoît Canet
Signed-off-by: Benoit Canet 
---
 hw/integratorcp.c |   19 +--
 1 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/hw/integratorcp.c b/hw/integratorcp.c
index 7f79560..70fedbe 100644
--- a/hw/integratorcp.c
+++ b/hw/integratorcp.c
@@ -393,6 +393,11 @@ static int icp_pic_init(SysBusDevice *dev)
 
 /* CP control registers.  */
 
+typedef struct icp_control_state {
+SysBusDevice busdev;
+MemoryRegion iomem;
+} icp_control_state;
+
 static uint64_t icp_control_read(void *opaque, target_phys_addr_t offset,
  unsigned size)
 {
@@ -431,15 +436,15 @@ static const MemoryRegionOps icp_control_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static void icp_control_init(target_phys_addr_t base)
+static int icp_control_init(SysBusDevice *dev)
 {
-MemoryRegion *io;
+icp_control_state *s = FROM_SYSBUS(icp_control_state, dev);
 
-io = (MemoryRegion *)g_malloc0(sizeof(MemoryRegion));
-memory_region_init_io(io, &icp_control_ops, NULL,
+memory_region_init_io(&s->iomem, &icp_control_ops, s,
   "control", 0x0080);
-memory_region_add_subregion(get_system_memory(), base, io);
+sysbus_init_mmio_region(dev, &s->iomem);
 /* ??? Save/restore.  */
+return 0;
 }
 
 
@@ -498,7 +503,7 @@ static void integratorcp_init(ram_addr_t ram_size,
 sysbus_create_simple("pl031", 0x1500, pic[8]);
 sysbus_create_simple("pl011", 0x1600, pic[1]);
 sysbus_create_simple("pl011", 0x1700, pic[2]);
-icp_control_init(0xcb00);
+sysbus_create_simple("integrator_control", 0xcb00, NULL);
 sysbus_create_simple("pl050_keyboard", 0x1800, pic[3]);
 sysbus_create_simple("pl050_mouse", 0x1900, pic[4]);
 sysbus_create_varargs("pl181", 0x1c00, pic[23], pic[24], NULL);
@@ -541,6 +546,8 @@ static SysBusDeviceInfo core_info = {
 static void integratorcp_register_devices(void)
 {
 sysbus_register_dev("integrator_pic", sizeof(icp_pic_state), icp_pic_init);
+sysbus_register_dev("integrator_control", sizeof(icp_control_state),
+icp_control_init);
 sysbus_register_withprop(&core_info);
 }
 
-- 
1.7.5.4




[Qemu-devel] [PATCH] integratorcp: convert control to sysbus

2011-10-19 Thread Benoît Canet
This patch convert the integratorcp control registers to sysbus.

Benoît Canet (1):
  integratorcp: convert control to sysbus

 hw/integratorcp.c |   19 +--
 1 files changed, 13 insertions(+), 6 deletions(-)

-- 
1.7.5.4




Re: [Qemu-devel] [PATCH 1/2] Move graphic-related coalesced MMIO flushes to affected device models

2011-10-19 Thread Jan Kiszka
On 2011-10-19 11:04, Avi Kivity wrote:
> 
> On 10/18/2011 09:50 PM, Jan Kiszka wrote:
>> On 2011-10-18 19:34, Avi Kivity wrote:
>>> On 10/18/2011 06:49 PM, Jan Kiszka wrote:
 On 2011-10-18 18:40, Avi Kivity wrote:
> On 10/18/2011 04:30 PM, Avi Kivity wrote:
>> This takes a while to reproduce, let me talk to gdb for a bit.
>>
>
> a vcpu exit causes kvm_flush_coalesced_mmio_buffer() to run, which does
> a bitblt, which is cirrus_do_copy(), which goes to vga_hw_update, which

 Why does it have to do vga_hw_update? Why can't it set some flag for the
 next requested screen update or so? Just thinking, haven't looked at the
 code yet.
>>>
>>> Maybe it's a remnant from the days where it asked the host hardware to
>>> do the blt.
> 
>> If it's no longer needed - drop it? Already for other reasons like
>> efficiency.
> 
> I think it actually is needed - it calls qemu_console_copy() to do the
> copy.  Which incidentally means the the coalesced flush, had it worked,
> would be a bug: it would bring pending mmio writes in front of a
> currently executing bitblt.  I don't think we can regard my hack as a
> fix for that.  Maybe we need to revert the original patch.  Or make sure
> the flush only happens from the display thread.

I hope we can avoid the old scheme as it hurts when trying to make
progress /wrt scalability. Will have a look if we can avoid the
recursion in some reasonable way at device level here.

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux



  1   2   >