Re: [Qemu-devel] [PATCH] win64: perform correct setjmp calls

2015-02-09 Thread Stefan Weil

Am 09.02.2015 um 08:55 schrieb Pavel Dovgalyuk:

On w64, setjmp is implemented by _setjmp which needs a second parameter.
This parameter should be NULL to allow using longjump from generated code.
This patch replaces all usages of setjmp.h with new header files which
replaces setjmp with _setjmp function on win64 platform.

Signed-off-by: Pavel Dovgalyuk 
---



Please have a look at include/sysemu/os-win32.h. I think that your patch 
is not needed because the current code already uses _setjmp.


Regards
Stefan




Re: [Qemu-devel] [PATCH RFC v4 5/6] qemu-iotests: s390x: fix test 051

2015-02-09 Thread chen xiao guang


On 02/05/2015 11:11 PM, Max Reitz wrote:

On 2015-02-04 at 22:44, Xiao Guang Chen wrote:

From: Mao Chuan Li 

The tests for device type "ide_cd" are skipped for the s390 platform.
The default device id of hard disk on the s390 platform differs to that
of the x86 platform. A new variable device_id is defined and "virtio0"
set for the s390 platform. A s390 platform specific output file is also
needed.

Reviewed-by:   Michael Mueller 
Signed-off-by: Mao Chuan Li 
---
  tests/qemu-iotests/051 |  91 +---
  tests/qemu-iotests/051.s390-virtio.out | 377 
+

  2 files changed, 439 insertions(+), 29 deletions(-)
  create mode 100644 tests/qemu-iotests/051.s390-virtio.out


First: This patch contains lines which are too long to be sent via 
email (they are broken up and thus the patch needs manual fixup by the 
reviewers). If you could specify a public repository where we could 
pull from, that may be helpful to the reviewers.

I can not find a public repository. Do you have other options?
Or I manually split the long lines into small ones only for review. But 
it will not work if you apply the patch.


Second: I'm not sure whether s390-virtio should be the special case 
here. Maybe "pc" is the platform that is actually special because it 
contains a floppy drive, an IDE CD drive and so on. So while this 
patch is (nearly?) correct, it may make more sense to move 051.out to 
051.pc.out and modify the current 051.out to be what is 
051.s390-virtio.out in this patch.



OK.
In the same way, maybe all the conditionals in this series (not just 
this patch) which check whether the machine type is s390-virtio should 
maybe instead check whether the machine type is not pc.

OK.


However, the problem with the pc machine type is that 
QEMU_DEFAULT_MACHINE will be version-dependent (currently, it's 
pc-i440fx-2.3), so that would require a workaround.


When we run the qemu-system-x86_64 -machine ? we will get the following 
output:

Supported machines are:
pc   Standard PC (i440FX + PIIX, 1996) (alias of 
pc-i440fx-2.3)

pc-i440fx-2.3Standard PC (i440FX + PIIX, 1996) (default)
pc-i440fx-2.2Standard PC (i440FX + PIIX, 1996)
pc-i440fx-2.1Standard PC (i440FX + PIIX, 1996)
..

We can get the default machine:pc-i440fx-2.3 and the alias of the 
default machine:pc.
If the default machine has an alias then we use the alias otherwise we 
use the default machine.


*qemu/tests/qemu-iotests/common.config:*
/default_machine=$($QEMU -machine \? | awk '/(default)/{print $1}')//
//default_alias_machine=$($QEMU -machine \? |\//
//awk -v var_default_machine=$default_machine\)\//
//'{if 
($(NF-2)=="(alias"&&$(NF-1)=="of"&&$(NF)==var_default_machine){print 
$1}}')//

//if [ ! -z "$default_alias_machine" ]//; then
//default_machine="$default_alias_machine"//
fi
//export QEMU_DEFAULT_MACHINE=$default_machine/

How about this change?



[snip]

diff --git a/tests/qemu-iotests/051.s390-virtio.out 
b/tests/qemu-iotests/051.s390-virtio.out

new file mode 100644
index 000..751670f
--- /dev/null
+++ b/tests/qemu-iotests/051.s390-virtio.out
@@ -0,0 +1,377 @@
+QA output created by 051
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 
backing_file='TEST_DIR/t.IMGFMT.base'

+
+=== Unknown option ===
+
+Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,unknown_opt=
+QEMU_PROG: -drive file=TEST_DIR/t.qcow2,format=qcow2,unknown_opt=: 
could not open disk image TEST_DIR/t.qcow2: Block format 'qcow2' used 
by device 'virtio0' doesn't support the option 'unknown_opt'

+
+Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,unknown_opt=on
+QEMU_PROG: -drive file=TEST_DIR/t.qcow2,format=qcow2,unknown_opt=on: 
could not open disk image TEST_DIR/t.qcow2: Block format 'qcow2' used 
by device 'virtio0' doesn't support the option 'unknown_opt'

+
+Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,unknown_opt=1234
+QEMU_PROG: -drive 
file=TEST_DIR/t.qcow2,format=qcow2,unknown_opt=1234: could not open 
disk image TEST_DIR/t.qcow2: Block format 'qcow2' used by device 
'virtio0' doesn't support the option 'unknown_opt'

+
+Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,unknown_opt=foo
+QEMU_PROG: -drive 
file=TEST_DIR/t.qcow2,format=qcow2,unknown_opt=foo: could not open 
disk image TEST_DIR/t.qcow2: Block format 'qcow2' used by device 
'virtio0' doesn't support the option 'unknown_opt'

+
+
+=== Unknown protocol option ===
+
+Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,file.unknown_opt=
+QEMU_PROG: -drive 
file=TEST_DIR/t.qcow2,format=qcow2,file.unknown_opt=: could not open 
disk image TEST_DIR/t.qcow2: Block protocol 'file' doesn't support 
the option 'unknown_opt'

+
+Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,file.unknown_opt=on
+QEMU_PROG: -drive 
file=TEST_DIR/t.qcow2,format=qcow2,file.unknown_opt=on: could not 
open disk image TEST_DIR/t.qcow2: Block protocol 'file' d

Re: [Qemu-devel] [PATCH] win64: perform correct setjmp calls

2015-02-09 Thread Pavel Dovgaluk
> From: Stefan Weil [mailto:s...@weilnetz.de]
> Am 09.02.2015 um 08:55 schrieb Pavel Dovgalyuk:
> > On w64, setjmp is implemented by _setjmp which needs a second parameter.
> > This parameter should be NULL to allow using longjump from generated code.
> > This patch replaces all usages of setjmp.h with new header files which
> > replaces setjmp with _setjmp function on win64 platform.
> >
> > Signed-off-by: Pavel Dovgalyuk 
> 
> Please have a look at include/sysemu/os-win32.h. I think that your patch
> is not needed because the current code already uses _setjmp.

Right, but some of the files (e.g. include/qom/cpu.h) include setjmp.h directly.
Then we have the following for compiling cpu-exec.c:

cpu-exec.c:
...
os-win32.h
...
setjmp.h
...

In this situation cpu-exec will call incorrect setjmp function.

Pavel Dovgalyuk




[Qemu-devel] [PATCH] Makefile: Allow "make cscope TAGS" in unconfigured source tree

2015-02-09 Thread Fam Zheng
It doesn't make much sense to ask one to switch to build dir in order to
make these two targets.

Signed-off-by: Fam Zheng 
---
 Makefile | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index 6817c6f..257bef6 100644
--- a/Makefile
+++ b/Makefile
@@ -3,6 +3,9 @@
 # Always point to the root of the build tree (needs GNU make).
 BUILD_DIR=$(CURDIR)
 
+# Before including a proper config-host.mak, assume we are in the source tree
+SRC_PATH=.
+
 # All following code might depend on configuration variables
 ifneq ($(wildcard config-host.mak),)
 # Put the all: rule here so that config-host.mak can contain dependencies.
@@ -38,7 +41,7 @@ config-host.mak: $(SRC_PATH)/configure
fi
 else
 config-host.mak:
-ifneq ($(filter-out %clean,$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
+ifneq ($(filter-out %clean TAGS cscope,$(MAKECMDGOALS)),$(if 
$(MAKECMDGOALS),,fail))
@echo "Please call configure before running make!"
@exit 1
 endif
@@ -433,9 +436,9 @@ TAGS:
find "$(SRC_PATH)" -name '*.[hc]' -exec etags --append {} +
 
 cscope:
-   rm -f ./cscope.*
-   find "$(SRC_PATH)" -name "*.[chsS]" -print | sed 's,^\./,,' > 
./cscope.files
-   cscope -b
+   rm -f "$(SRC_PATH)"/cscope.*
+   find "$(SRC_PATH)/" -name "*.[chsS]" -print | sed 's,^\./,,' > 
"$(SRC_PATH)/cscope.files"
+   cscope -b -i"$(SRC_PATH)/cscope.files"
 
 # documentation
 MAKEINFO=makeinfo
@@ -556,7 +559,7 @@ endif # CONFIG_WIN
 
 # Add a dependency on the generated files, so that they are always
 # rebuilt before other object files
-ifneq ($(filter-out %clean,$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
+ifneq ($(filter-out %clean TAGS cscope,$(MAKECMDGOALS)),$(if 
$(MAKECMDGOALS),,fail))
 Makefile: $(GENERATED_HEADERS)
 endif
 
-- 
1.9.3




Re: [Qemu-devel] [PATCH] qemu-coroutine-lock: fix co_queue multi-adding bug

2015-02-09 Thread Fam Zheng
On Sat, 02/07 17:51, w00214312 wrote:
> From: Bin Wu 
> 
> When a coroutine holds a lock, other coroutines who want to get
> the lock must wait on a co_queue by adding themselves to the
> CoQueue. However, if a waiting coroutine is woken up with the
> lock still be holding by other coroutine, this waiting coroutine

Could you explain who wakes up the waiting coroutine? Maybe the bug is that
it shouldn't be awaken in the first place.

> will add itself to the co_queue again. Latter, when the lock
> is released, a coroutine re-enter will occur.
> 
> We need to determine whether a coroutine is alread in the co_queue

s/alread/already/

Fam

> before adding it to the waiting queue.
> 
> Signed-off-by: Bin Wu 
> ---
>  include/block/coroutine_int.h | 1 +
>  qemu-coroutine-lock.c | 6 +-
>  qemu-coroutine.c  | 1 +
>  3 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/include/block/coroutine_int.h b/include/block/coroutine_int.h
> index f133d65..c524990 100644
> --- a/include/block/coroutine_int.h
> +++ b/include/block/coroutine_int.h
> @@ -42,6 +42,7 @@ struct Coroutine {
>  /* Coroutines that should be woken up when we yield or terminate */
>  QTAILQ_HEAD(, Coroutine) co_queue_wakeup;
>  QTAILQ_ENTRY(Coroutine) co_queue_next;
> +bool in_co_queue;
>  };
>  
>  Coroutine *qemu_coroutine_new(void);
> diff --git a/qemu-coroutine-lock.c b/qemu-coroutine-lock.c
> index e4860ae..d256f53 100644
> --- a/qemu-coroutine-lock.c
> +++ b/qemu-coroutine-lock.c
> @@ -36,7 +36,10 @@ void qemu_co_queue_init(CoQueue *queue)
>  void coroutine_fn qemu_co_queue_wait(CoQueue *queue)
>  {
>  Coroutine *self = qemu_coroutine_self();
> -QTAILQ_INSERT_TAIL(&queue->entries, self, co_queue_next);
> +if (!self->in_co_queue) {
> +QTAILQ_INSERT_TAIL(&queue->entries, self, co_queue_next);
> +self->in_co_queue = true;
> +}
>  qemu_coroutine_yield();
>  assert(qemu_in_coroutine());
>  }
> @@ -71,6 +74,7 @@ static bool qemu_co_queue_do_restart(CoQueue *queue, bool 
> single)
>  
>  while ((next = QTAILQ_FIRST(&queue->entries)) != NULL) {
>  QTAILQ_REMOVE(&queue->entries, next, co_queue_next);
> +next->in_co_queue = false;
>  QTAILQ_INSERT_TAIL(&self->co_queue_wakeup, next, co_queue_next);
>  trace_qemu_co_queue_next(next);
>  if (single) {
> diff --git a/qemu-coroutine.c b/qemu-coroutine.c
> index 525247b..a103721 100644
> --- a/qemu-coroutine.c
> +++ b/qemu-coroutine.c
> @@ -75,6 +75,7 @@ Coroutine *qemu_coroutine_create(CoroutineEntry *entry)
>  }
>  
>  co->entry = entry;
> +co->in_co_queue = false;
>  QTAILQ_INIT(&co->co_queue_wakeup);
>  return co;
>  }
> -- 
> 1.7.12.4
> 
> 



Re: [Qemu-devel] [PATCH] Makefile: Allow "make cscope TAGS" in unconfigured source tree

2015-02-09 Thread Peter Maydell
On 9 February 2015 at 08:08, Fam Zheng  wrote:
> It doesn't make much sense to ask one to switch to build dir in order to
> make these two targets.
>
> Signed-off-by: Fam Zheng 
> ---
>  Makefile | 13 -
>  1 file changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 6817c6f..257bef6 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -3,6 +3,9 @@
>  # Always point to the root of the build tree (needs GNU make).
>  BUILD_DIR=$(CURDIR)
>
> +# Before including a proper config-host.mak, assume we are in the source tree
> +SRC_PATH=.
> +
>  # All following code might depend on configuration variables
>  ifneq ($(wildcard config-host.mak),)
>  # Put the all: rule here so that config-host.mak can contain dependencies.
> @@ -38,7 +41,7 @@ config-host.mak: $(SRC_PATH)/configure
> fi
>  else
>  config-host.mak:
> -ifneq ($(filter-out %clean,$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
> +ifneq ($(filter-out %clean TAGS cscope,$(MAKECMDGOALS)),$(if 
> $(MAKECMDGOALS),,fail))

Probably better to define a variable for the targets which can be
called on an unconfigured directory rather than having "clean TAGS cscope"
in two places.

>  cscope:
> -   rm -f ./cscope.*
> -   find "$(SRC_PATH)" -name "*.[chsS]" -print | sed 's,^\./,,' > 
> ./cscope.files
> -   cscope -b
> +   rm -f "$(SRC_PATH)"/cscope.*
> +   find "$(SRC_PATH)/" -name "*.[chsS]" -print | sed 's,^\./,,' > 
> "$(SRC_PATH)/cscope.files"
> +   cscope -b -i"$(SRC_PATH)/cscope.files"

Isn't this going to result in our writing the cscope.files into the
source tree but the cross-reference into the build directory?
That seems inconsistent (and I'm not really convinced about the
wisdom of anything in the makefile writing to the source tree).

thanks
-- PMM



Re: [Qemu-devel] Definition of the UI layer's "key number" ?

2015-02-09 Thread Gerd Hoffmann
On Do, 2015-02-05 at 17:36 +, Peter Maydell wrote:
> Hi; I'm trying to find out what the UI layer's definition of
> a "key number" is (ie what qemu_input_event_send_key_number()'s
> "num" parameter is). We don't seem to document this anywhere,
> which makes writing UI frontends tricky...

Well, we have two ways to represent a key code in qemu, unfortunately in
the QMP api (see KeyValue in qapi-schema.json).

One is QKeyCode (defined in qapi-schema.json too), the other "key
number" is the key coding used pretty much everywhere in qemu before the
input layer rewrite (the new code in ui/input*.c) got merged.  It is
based on ps/2 keycodes.

For new code I strongly suggest to simply ignore the old "key number"
coding and use QKeyCodes exclusively, it allows you to have nicely
readable mappings like the one in ui/sdl2-keymap.h.  Then use
qemu_input_event_send_key_qcode() to feed the guest with the keyboard
input.

ui/input-keymap.c has a table to map QKeyCodes to "key numbers" and
helper functions to translate codes both ways.

cheers,
  Gerd





Re: [Qemu-devel] Definition of the UI layer's "key number" ?

2015-02-09 Thread Peter Maydell
On 9 February 2015 at 08:27, Gerd Hoffmann  wrote:
> Well, we have two ways to represent a key code in qemu, unfortunately in
> the QMP api (see KeyValue in qapi-schema.json).
>
> One is QKeyCode (defined in qapi-schema.json too), the other "key
> number" is the key coding used pretty much everywhere in qemu before the
> input layer rewrite (the new code in ui/input*.c) got merged.  It is
> based on ps/2 keycodes.
>
> For new code I strongly suggest to simply ignore the old "key number"
> coding and use QKeyCodes exclusively, it allows you to have nicely
> readable mappings like the one in ui/sdl2-keymap.h.  Then use
> qemu_input_event_send_key_qcode() to feed the guest with the keyboard
> input.
>
> ui/input-keymap.c has a table to map QKeyCodes to "key numbers" and
> helper functions to translate codes both ways.

Thanks. How do we handle key codes which don't exist in the translation
tables in input-keymap.c? Specifically, we need to support the
"keypad =" key which exists on some Mac keyboards (both for sending
it if you're using this keyboard on the host and for receiving it
if you're using the ADB keyboard in the guest). There is a
Q_KEY_CODE_KP_EQUALS but it doesn't have a table entry, and since
both the guest code and the frontend UI code in question use old
style keycodes I'd rather the answer wasn't "convert both of them
to use QKeyCode"...

-- PMM



Re: [Qemu-devel] [PATCH v2 0/3] fix qemu crash about vnc

2015-02-09 Thread Gerd Hoffmann
  Hi,

> It seems that Gerd is not in maillist recently.

Was sick, back online now, I'll try to have a closer look ASAP but I
have a big email backlog now ...

cheers,
  Gerd





Re: [Qemu-devel] [RFC] pseries: Enable in-kernel H_LOGICAL_CI_{LOAD, STORE} implementations

2015-02-09 Thread David Gibson
On Fri, 06 Feb 2015 08:56:32 +0100
Alexander Graf  wrote:

> 
> 
> On 06.02.15 03:54, David Gibson wrote:
> > On Thu, Feb 05, 2015 at 12:55:45PM +0100, Alexander Graf wrote:
> >>
> >>
> >> On 05.02.15 12:30, David Gibson wrote:
> >>> On Thu, Feb 05, 2015 at 11:22:13AM +0100, Alexander Graf wrote:
> > [snip]
> >> [snip]
> >>
> >>> +ret1 = kvmppc_enable_hcall(kvm_state, H_LOGICAL_CI_LOAD);
> >>> +if (ret1 != 0) {
> >>> +fprintf(stderr, "Warning: error enabling 
> >>> H_LOGICAL_CI_LOAD in KVM:"
> >>> +" %s\n", strerror(errno));
> >>> +}
> >>> +
> >>> +ret2 = kvmppc_enable_hcall(kvm_state, H_LOGICAL_CI_STORE);
> >>> +if (ret2 != 0) {
> >>> +fprintf(stderr, "Warning: error enabling 
> >>> H_LOGICAL_CI_STORE in KVM:"
> >>> +" %s\n", strerror(errno));
> >>> + }
> >>> +
> >>> +if ((ret1 != 0) || (ret2 != 0)) {
> >>> +fprintf(stderr, "Warning: Couldn't enable H_LOGICAL_CI_* 
> >>> in KVM, SLOF"
> >>> +" may be unable to operate devices with 
> >>> in-kernel emulation\n");
> >>> +}
> >>
> >> You'll always get these warnings if you're running on an old 
> >> (meaning
> >> current upstream) kernel, which could be annoying.
> >
> > True.
> >
> >> Is there any way
> >> to tell whether you have configured any devices which need the
> >> in-kernel MMIO emulation and only warn if you have?
> >
> > In theory, I guess so.  In practice I can't see how you'd enumerate
> > all devices that might require kernel intervention without something
> > horribly invasive.
> 
>  We could WARN_ONCE in QEMU if we emulate such a hypercall, but its
>  handler is io_mem_unassigned (or we add another minimum priority huge
>  memory region on all 64bits of address space that reports the 
>  breakage).
> >>>
> >>> Would that work for the virtio+iothread case?  I had the impression
> >>> the kernel handled notification region was layered over the qemu
> >>> emulated region in that case.
> >>
> >> IIRC we don't have a way to call back into kvm saying "please write to
> >> this in-kernel device". But we could at least defer the warning to a
> >> point where we know that we actually hit it.
> >
> > Right, but I'm saying we might miss the warning in cases where we want
> > it, because the KVM device is shadowed by a qemu device, so qemu won't
> > see the IO as unassigned or unhandled.
> >
> > In particular, I think that will happen in the case of virtio-blk with
> > iothread, which is the simplest case in which to observe the problem.
> > The virtio-blk device exists in qemu and is functional, but we rely on
> > KVM catching the queue notification MMIO before it reaches the qemu
> > implementation of the rest of the device's IO space.
> 
>  But in that case the VM stays functional and will merely see a
>  performance hit when using virtio in SLOF, no? I don't think that's
>  a problem worth worrying users about.
> >>>
> >>> Alas, no.  The iothread stuff *relies* on the in-kernel notification,
> >>> so it will not work if the IO gets punted to qemu.  This is the whole
> >>> reason for the in-kernel hcall implementation.
> >>
> >> So at least with vhost-net the in-kernel trapping is optional. If we
> >> happen to get MMIO into QEMU, we'll just handle it there.
> >>
> >> Enlighten me why the iothread stuff can't handle it that way too.
> > 
> > So, as I understand it, it could, but it doesn't.  Working out how to
> > fix it properly requires better understanding of the dataplane code
> > than I currently possess,
> > 
> > So, using virtio-blk as the example case.  Normally the queue notify
> > mmio will get routed by the general virtio code to
> > virtio_blk_handle_output().
> > 
> > In the case of dataplane, that just calls
> > virtio_blk_data_plane_start().  So the first time we get a vq notify,
> > the dataplane is started.  That sets up the host notifier
> > (VirtioBusClass::set_host_notifier -> virtio_pci_set_host_notifier ->
> > virtio_pci_set_host_notifier_internal -> memory_region_add_eventfd()
> > -> memory_region_transaction_commit() ->
> > address_space_update_ioeventfds - >address_space_add_del_ioeventfds ->
> > kvm_mem_ioeventfd_add -> kvm_set_ioeventfd_mmio -> KVM_IOEVENTFD
> > ioctl)
> > 
> > From this point on further calls to virtio_blk_handle_output() are
> > IIUC a "can't happen", because vq notifies should go to the eventfd
> > instead, where they will kick the iothread.
> > 
> > So, with SLOF, the first request is ok - it hits
> > virtio_blk_handle_output() which starts the iothread which goes on to
> > process the request

[Qemu-devel] [Bug 1301047] Re: Windows guest freezes while using passthrough on USB audio recorder.

2015-02-09 Thread zelluz
** Changed in: qemu
   Status: In Progress => Invalid

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

Title:
  Windows guest freezes while using passthrough on USB audio recorder.

Status in QEMU:
  Invalid

Bug description:
  I have the following issue with my Windows 8.1 guest. (Technical stuff
  is at the bottom):

  I have vfio-binded my graphics card(NVIDIA GTX670) and is passing it through 
to the guest.
  I run heavy 3D applications such as games(Guild Wars 2, Diablo 3, DOTA etc) 
which works fine(performance is about <90% of a "physical" Windows).

  When it comes to Rocksmith 2014 things starts to act up. I can play
  the game just as good as any other game in the guest(passing through
  the USB Rocksmith Cable and audio is working perfect), however when I
  exit the application the guest freezes completely up. I loose contact
  via Synergy(mouse/keyboard), I cant ping the guest, the screen
  freezes(always freezing before I see the desktop again), CPU usage of
  the processes drops down to 0. The memory dedicated to the guest is
  latent/in use though, as reported by htop/free -m.

  This also happens when I go to my sound settings-> record
  settings(where I can see the Rocksmith cable, as it is a recorder).
  The vm will freeze up after a couple of seconds being in that menu.

  If I remove the USB device from my qemu command and go into my sound
  settings->record settings there are no freezing issues.

  The guest will however not freeze up while browsing through device
  manager and looking at the USB Rocksmith Cable from there.

  My host(Arch Linux) works fine while the host is frozen up.

  Is it reproducible?
  Yes, every time the USB device is passed through, the guest will at some 
point lock up while the USB device are used/polled.
  Tried with both USB 2.0 and USB 3.0 port with the same thing happening.

  Expected outcome:
  USB device works without freezing up the guest.

  Suggested solution(if at all possible):
  Somehow make the USB devices reconnect in the guest when the host is 
receiving the "ERROR Transfer event for disabled endpoint or incorrect stream 
ring" messages.
  Or make it so that the guest can never lock up while this happens.

  Information about USB Rocksmith Cable:
  The realtone guitar interface cable is really just a simple USB sound card 
which is seen as a USB microphone by a computer or console game system. This is 
actually identical to other 1/4″ to USB adapters such as the Behringer UCG102 
Guitar to USB interface.

  If there is some more information you need, please do not hesitate to ask for 
it.
  Also, this is my first bug report so please be kind, I appreciate any 
feedback :)

  Technical Information:

  CPU: Intel(R) Core(TM) i7-4771 CPU @ 3.50GHz
  GPU: NVIDIA GTX 670, latest NVIDIA drivers installed in Windows.
  QEMU version: qemu-git 2.0.r31965.g63678e1-1
  Host Kernel: Linux 3.13.6-1-mainline x86_64
  Guest: Windows 8.1 Professional, fully updated as of 30th March 2014

  Qemu command line used:

  sudo -E qemu-system-x86_64 \
  -enable-kvm \
  -M q35 \
  -m 8G \
  -mem-path /dev/hugepages \
  -mem-prealloc \
  -cpu host \
  -smp 4,sockets=1,cores=4,threads=1 \
  -device vfio-pci,host=00:1b.0 \
  -bios /usr/share/qemu/bios.bin \
  -vga none \
  -device 
ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1 \
  -device vfio-pci,host=01:00.0,bus=root.1,addr=00.0,multifunction=on,x-vga=on \
  -nographic \
  -device ahci,bus=pcie.0,id=ahci \
  -drive 
file=/var/lib/libvirt/images/Windows8.1.img,id=disk,format=raw,cache=none \
  -device ide-hd,bus=ahci.0,drive=disk \
  -device vfio-pci,host=00:19.0,bus=pcie.0 \
  -drive file=/dev/sdb1,id=mmo,format=raw,cache=none \
  -device ide-hd,bus=ahci.1,drive=mmo \
  -drive 
file=/home/thor/Windows/Windows-Steam.img,id=steam,format=raw,cache=none \
  -usb -usbdevice host:045e:028e \
  -usb -usbdevice host:12ba:00ff \
  -net none \
  -device ide-hd,bus=ahci.2,drive=steam

  Strace output in the seconds leading up to the freeze:
  See attachment .

  Journalctl output on the host while the guest froze:

  Apr 01 22:03:19 ultimaarch kernel: xhci_hcd :00:14.0: ERROR Transfer 
event for disabled endpoint or incorrect stream ring
  Apr 01 22:03:19 ultimaarch kernel: xhci_hcd :00:14.0: @e410 
fff9f480  0d0c 07058000
  Apr 01 22:03:19 ultimaarch kernel: xhci_hcd :00:14.0: ERROR Transfer 
event for disabled endpoint or incorrect stream ring
  Apr 01 22:03:19 ultimaarch kernel: xhci_hcd :00:14.0: @e420 
fff9f490  0d0c 07058000
  Apr 01 22:03:19 ultimaarch kernel: xhci_hcd :00:14.0: ERROR Transfer 
event for disabled endpoint or incorrect stream ring
  Apr 01 22:03:19 ultimaarch kernel: xhci_hcd :00:14.0: @e430 
fff9f4a0  0d0c 07058000
  Apr 01 22:03:19 ultimaarch kernel: xhci_hcd :00:14.0: E

Re: [Qemu-devel] [PATCH] Makefile: Allow "make cscope TAGS" in unconfigured source tree

2015-02-09 Thread Fam Zheng
On Mon, 02/09 08:25, Peter Maydell wrote:
> On 9 February 2015 at 08:08, Fam Zheng  wrote:
> > It doesn't make much sense to ask one to switch to build dir in order to
> > make these two targets.
> >
> > Signed-off-by: Fam Zheng 
> > ---
> >  Makefile | 13 -
> >  1 file changed, 8 insertions(+), 5 deletions(-)
> >
> > diff --git a/Makefile b/Makefile
> > index 6817c6f..257bef6 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -3,6 +3,9 @@
> >  # Always point to the root of the build tree (needs GNU make).
> >  BUILD_DIR=$(CURDIR)
> >
> > +# Before including a proper config-host.mak, assume we are in the source 
> > tree
> > +SRC_PATH=.
> > +
> >  # All following code might depend on configuration variables
> >  ifneq ($(wildcard config-host.mak),)
> >  # Put the all: rule here so that config-host.mak can contain dependencies.
> > @@ -38,7 +41,7 @@ config-host.mak: $(SRC_PATH)/configure
> > fi
> >  else
> >  config-host.mak:
> > -ifneq ($(filter-out %clean,$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fail))
> > +ifneq ($(filter-out %clean TAGS cscope,$(MAKECMDGOALS)),$(if 
> > $(MAKECMDGOALS),,fail))
> 
> Probably better to define a variable for the targets which can be
> called on an unconfigured directory rather than having "clean TAGS cscope"
> in two places.
> 
> >  cscope:
> > -   rm -f ./cscope.*
> > -   find "$(SRC_PATH)" -name "*.[chsS]" -print | sed 's,^\./,,' > 
> > ./cscope.files
> > -   cscope -b
> > +   rm -f "$(SRC_PATH)"/cscope.*
> > +   find "$(SRC_PATH)/" -name "*.[chsS]" -print | sed 's,^\./,,' > 
> > "$(SRC_PATH)/cscope.files"
> > +   cscope -b -i"$(SRC_PATH)/cscope.files"
> 
> Isn't this going to result in our writing the cscope.files into the
> source tree but the cross-reference into the build directory?
> That seems inconsistent (and I'm not really convinced about the
> wisdom of anything in the makefile writing to the source tree).

This patch is useful when you really want "make cscope", when you're already at
your $(SRC_PATH). The "find | sed; cscope" command sequence is way too
cumbersome.

For those who are not the in-tree build type, I assume leaving out '-f
"$(SRC_PATH)/cscope.out"' should slightly ease the concern about writing to
source tree? :)

I don't know a better place to put the reference. I always start vim from
$(SRC_PATH).

Fam



Re: [Qemu-devel] [PATCH v2 0/3] fix qemu crash about vnc

2015-02-09 Thread Gonglei
On 2015/2/9 16:33, Gerd Hoffmann wrote:

>   Hi,
> 
>> It seems that Gerd is not in maillist recently.
> 
> Was sick, back online now, I'll try to have a closer look ASAP but I
> have a big email backlog now ...
> 

Hope you feel better now :)

Regards,
-Gonglei




Re: [Qemu-devel] [v2][RFC][PATCH] virtio: uniform virtio device IDs

2015-02-09 Thread Cornelia Huck
On Mon, 09 Feb 2015 15:10:17 +0800
"Chen, Tiejun"  wrote:

> On 2015/2/9 15:02, Michael S. Tsirkin wrote:
> > On Mon, Feb 09, 2015 at 03:01:15PM +0800, Chen, Tiejun wrote:
> >> On 2015/2/8 18:48, Michael S. Tsirkin wrote:
> >>> On Fri, Feb 06, 2015 at 01:14:46PM +0100, Cornelia Huck wrote:
>  On Fri,  6 Feb 2015 13:41:26 +0800
>  Tiejun Chen  wrote:
> 
> > Actually we define these device IDs in virtio standard, so
> > we'd better put them into one common place to manage conveniently.
> > Here I also add VIRTIO_ID_RESERVE according to virtio spec.
> >
> > Signed-off-by: Tiejun Chen 
> >>>
> >>> We really should just write a script to import the headers
> >> >from the linux kernel.
> >>> They will need some tweaks to avoid dependencies on
> >>> linux/types, but this seems easy to do - better than
> >>> trying to keep things in sync manually.
> >>
> >> I prefer Cornelia's comment since actually we're trying to define a little
> >> bit according to a spec, so the following may be enough?
> >>
> >> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
> >> index f24997d..4afb0b7 100644
> >> --- a/include/hw/virtio/virtio.h
> >> +++ b/include/hw/virtio/virtio.h
> >> @@ -23,6 +23,22 @@
> >>   #include "hw/virtio/virtio-9p.h"
> >>   #endif
> >>
> >> +/* Refer to VirtIO Spec 1.0. */
> >> +
> >> +#define VIRTIO_ID_RESERVED  0   /* reserved (invalid)*/
> >> +#define VIRTIO_ID_NET   1   /* network card */
> >> +#define VIRTIO_ID_BLOCK 2   /* block device */
> >> +#define VIRTIO_ID_CONSOLE   3   /* console */
> >> +#define VIRTIO_ID_RNG   4   /* entropy source */
> >> +#define VIRTIO_ID_BALLOON   5   /* memory ballooning */
> >> +#define VIRTIO_ID_IOMEMORY  6   /* ioMemory */
> >> +#define VIRTIO_ID_RPMSG 7   /* rpmsg */
> >> +#define VIRTIO_ID_SCSI  8   /* SCSI host */
> >> +#define VIRTIO_ID_9P9   /* 9P transport */
> >> +#define VIRTIO_ID_MAC80211_WALN 10  /* mac80211 wlan */
> >> +#define VIRTIO_ID_RPROC_SERIAL  11  /* rproc seria */
> >> +#define VIRTIO_ID_CAIF  12  /* virtio CAIF */

I like that.

> >> +
> >>   /* from Linux's linux/virtio_config.h */
> >>
> >>   /* Status byte for guest to report progress, and synchronize features. */
> >>
> >> Thanks
> >> Tiejun
> >
> > This still means each change has to be done in two places.

Well, we do need the changes in way more than two places, as every host
or guest has to collect the definitions on its own, no? (Granted, with
Linux and qemu you get most of the users; but it feels a bit strange
for a host implementation to collect information from one of its
guests. I really think that we should go back to the common root.
Didn't we have a BSD-licenced header in the spec?)

> 
> Are you saying another head file, pc-bios/s390-ccw/virtio.h?
> 
> But seems Cornelia thought in case of s390-ccw, -quote-
> 
> "Even though this one is incomplete; but we don't need anything but the
> block id anyway."

Note that this is the s390-ccw _bios_, which is a very incomplete
implementation only containing the bare minimum needed to access a
virtio-blk root device for booting.




Re: [Qemu-devel] [PATCH v3 2/7] qom/cpu: move register_vmstate to common CPUClass.realizefn

2015-02-09 Thread Chen Fan


On 01/29/2015 10:04 PM, Igor Mammedov wrote:

On Wed, 14 Jan 2015 15:27:25 +0800
Zhu Guihua  wrote:


From: Gu Zheng 

Move cpu vmstate register from cpu_exec_init into cpu_common_realizefn,
and use cc->get_arch_id as the instance id that suggested by Igor to
fix the migration issue.

Signed-off-by: Gu Zheng 
Signed-off-by: Zhu Guihua 
---
  exec.c| 32 +++-
  include/qom/cpu.h |  2 ++
  qom/cpu.c |  2 ++
  3 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/exec.c b/exec.c
index 081818e..c9ffda6 100644
--- a/exec.c
+++ b/exec.c
@@ -513,10 +513,28 @@ void tcg_cpu_address_space_init(CPUState *cpu, 
AddressSpace *as)
  }
  #endif
  
+void cpu_vmstate_register(CPUState *cpu)

+{
+CPUClass *cc = CPU_GET_CLASS(cpu);
+int cpu_index = cc->get_arch_id(cpu);

that probable would be source migration problems:
because cc->get_arch_id(cpu) depending on topology might
be not sequential, for example: sockets=4,core=3
that would create sparse APIC numbering.

as result migration from old qemu to one with this change
would be rejected due to vmsd id mismatch mismatch.

we need a better way to handle cross version migration
between old/new scheme.

Hi Igor,

I think to handler cross version migration issue, we only
need to do is converting new 'apic-id' to old 'cpu_index' to match
vmsd id  between old to new scheme.
we can save old cpu_index in alias id. and in order to keep
instance_id differ from alias id. we can use apic_id + maxcpus
as the instance_id. so during migration we can find the corresponding
cpu with instance_id regardless new/old scheme.

I has made a patch and test migrating from old version to new version.
it seems work fine. pls have a look at the attach file. ;)

Thanks,
Chen


+
+if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
+vmstate_register(NULL, cpu_index, &vmstate_cpu_common, cpu);
+}
+#if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)

that ifdef block affects only sparc/mips/cris and builds target specific code
while you are trying to call it from target independent qom/cpu.c

I'd suggest leave it where it was or better move into respective
targets realize_fns


+register_savevm(NULL, "cpu", cpu_index, CPU_SAVE_VERSION,
+cpu_save, cpu_load, cpu->env_ptr);
+assert(cc->vmsd == NULL);
+assert(qdev_get_vmsd(DEVICE(cpu)) == NULL);
+#endif
+if (cc->vmsd != NULL) {
+vmstate_register(NULL, cpu_index, cc->vmsd, cpu);
+}
+}
+
  void cpu_exec_init(CPUArchState *env)
  {
  CPUState *cpu = ENV_GET_CPU(env);
-CPUClass *cc = CPU_GET_CLASS(cpu);
  CPUState *some_cpu;
  int cpu_index;
  
@@ -539,18 +557,6 @@ void cpu_exec_init(CPUArchState *env)

  #if defined(CONFIG_USER_ONLY)
  cpu_list_unlock();
  #endif
-if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
-vmstate_register(NULL, cpu_index, &vmstate_cpu_common, cpu);
-}
-#if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)
-register_savevm(NULL, "cpu", cpu_index, CPU_SAVE_VERSION,
-cpu_save, cpu_load, env);
-assert(cc->vmsd == NULL);
-assert(qdev_get_vmsd(DEVICE(cpu)) == NULL);
-#endif
-if (cc->vmsd != NULL) {
-vmstate_register(NULL, cpu_index, cc->vmsd, cpu);
-}

And in general do CONFIG_USER_ONLY targets actually need/use
migration code?


  }
  
  #if defined(TARGET_HAS_ICE)

diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 2098f1c..936afcd 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -562,6 +562,8 @@ void cpu_interrupt(CPUState *cpu, int mask);
  
  #endif /* USER_ONLY */
  
+void cpu_vmstate_register(CPUState *cpu);

+
  #ifdef CONFIG_SOFTMMU
  static inline void cpu_unassigned_access(CPUState *cpu, hwaddr addr,
   bool is_write, bool is_exec,
diff --git a/qom/cpu.c b/qom/cpu.c
index 9c68fa4..a639822 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -302,6 +302,8 @@ static void cpu_common_realizefn(DeviceState *dev, Error 
**errp)
  {
  CPUState *cpu = CPU(dev);
  
+cpu_vmstate_register(cpu);

+
  if (dev->hotplugged) {
  cpu_synchronize_post_init(cpu);
  cpu_resume(cpu);

.



diff --git a/exec.c b/exec.c
index bda96c6..6f3a90d 100644
--- a/exec.c
+++ b/exec.c
@@ -516,10 +516,12 @@ void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as)
 void cpu_vmstate_register(CPUState *cpu)
 {
 CPUClass *cc = CPU_GET_CLASS(cpu);
-int cpu_index = cc->get_arch_id(cpu);
+int cpu_index = cc->get_arch_id(cpu) + max_cpus;
+int compat_index = cc->get_compat_id(cpu);
 
 if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
-vmstate_register(NULL, cpu_index, &vmstate_cpu_common, cpu);
+vmstate_register_with_alias_id(NULL, cpu_index, &vmstate_cpu_common,
+   cpu, compat_index, 3);
 }
 #if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)
 register_savevm(NULL, "cpu", cpu_index, CPU_SAVE_VERSION,
@

Re: [Qemu-devel] [PATCH v2] qemu-coroutine: segfault when restarting co_queue

2015-02-09 Thread Paolo Bonzini


On 09/02/2015 07:50, Bin Wu wrote:
> From: Bin Wu 
> 
> We tested VMs migration with their disk images by drive_mirror. With
> migration, two VMs copyed large files between each other. During the
> test, a segfault occured. The stack was as follow:
> 
> (gdb) bt
> qemu-coroutine-lock.c:66
> to=0x7fa5a1798648) at qemu-coroutine.c:97
> request=0x7fa28c2ffa10, reply=0x7fa28c2ffa30, qiov=0x0, offset=0) at
> block/nbd-client.c:165
> sector_num=8552704, nb_sectors=2040, qiov=0x7fa5a1757468, offset=0) at
> block/nbd-client.c:262
> sector_num=8552704, nb_sectors=2048, qiov=0x7fa5a1757468) at
> block/nbd-client.c:296
> nb_sectors=2048, qiov=0x7fa5a1757468) at block/nbd.c:291
> req=0x7fa28c2ffbb0, offset=4378984448, bytes=1048576, qiov=0x7fa5a1757468,
> flags=0) at block.c:3321
> offset=4378984448, bytes=1048576, qiov=0x7fa5a1757468, flags=(unknown: 0)) at
> block.c:3447
> sector_num=8552704, nb_sectors=2048, qiov=0x7fa5a1757468, flags=(unknown: 0)) 
> at
> block.c:3471
> nb_sectors=2048, qiov=0x7fa5a1757468) at block.c:3480
> nb_sectors=2048, qiov=0x7fa5a1757468) at block/raw_bsd.c:62
> req=0x7fa28c2ffe30, offset=4378984448, bytes=1048576, qiov=0x7fa5a1757468,
> flags=0) at block.c:3321
> offset=4378984448, bytes=1048576, qiov=0x7fa5a1757468, flags=(unknown: 0)) at
> block.c:3447
> sector_num=8552704, nb_sectors=2048, qiov=0x7fa5a1757468, flags=(unknown: 0)) 
> at
> block.c:3471
> coroutine-ucontext.c:121
> 
> After analyzing the stack and reviewing the code, we find the
> qemu_co_queue_run_restart should not be put in the coroutine_swap function 
> which
> can be invoked by qemu_coroutine_enter or qemu_coroutine_yield. Only
> qemu_coroutine_enter needs to restart the co_queue.
> 
> The error scenario is as follow: coroutine C1 enters C2, C2 yields
> back to C1, then C1 ternimates and the related coroutine memory
> becomes invalid. After a while, the C2 coroutine is entered again.
> At this point, C1 is used as a parameter passed to
> qemu_co_queue_run_restart. Therefore, qemu_co_queue_run_restart
> accesses an invalid memory and a segfault error ocurrs.
> 
> The qemu_co_queue_run_restart function re-enters coroutines waiting
> in the co_queue. However, this function should be only used int the
> qemu_coroutine_enter context. Only in this context, when the current
> coroutine gets execution control again(after the execution of
> qemu_coroutine_switch), we can restart the target coutine because the
> target coutine has yielded back to the current coroutine or it has
> terminated.

qemu_coroutine_yield can be executed for other reasons than locks.  In
those cases, it is correct to call qemu_co_queue_run_restart.  I think
it's an NBD bug.

Paolo

> First we want to put qemu_co_queue_run_restart in qemu_coroutine_enter,
> but we find we can not access the target coroutine if it terminates.
> 
> Signed-off-by: Bin Wu 
> ---
>  qemu-coroutine.c | 16 ++--
>  1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/qemu-coroutine.c b/qemu-coroutine.c
> index 525247b..cc0bdfa 100644
> --- a/qemu-coroutine.c
> +++ b/qemu-coroutine.c
> @@ -99,29 +99,31 @@ static void coroutine_delete(Coroutine *co)
>  qemu_coroutine_delete(co);
>  }
>  
> -static void coroutine_swap(Coroutine *from, Coroutine *to)
> +static CoroutineAction coroutine_swap(Coroutine *from, Coroutine *to)
>  {
>  CoroutineAction ret;
>  
>  ret = qemu_coroutine_switch(from, to, COROUTINE_YIELD);
>  
> -qemu_co_queue_run_restart(to);
> -
>  switch (ret) {
>  case COROUTINE_YIELD:
> -return;
> +break;
>  case COROUTINE_TERMINATE:
>  trace_qemu_coroutine_terminate(to);
> +qemu_co_queue_run_restart(to);
>  coroutine_delete(to);
> -return;
> +break;
>  default:
>  abort();
>  }
> +
> +return ret;
>  }
>  
>  void qemu_coroutine_enter(Coroutine *co, void *opaque)
>  {
>  Coroutine *self = qemu_coroutine_self();
> +CoroutineAction ret;
>  
>  trace_qemu_coroutine_enter(self, co, opaque);
>  
> @@ -132,7 +134,9 @@ void qemu_coroutine_enter(Coroutine *co, void *opaque)
>  
>  co->caller = self;
>  co->entry_arg = opaque;
> -coroutine_swap(self, co);
> +ret = coroutine_swap(self, co);
> +if (ret == COROUTINE_YIELD)
> +qemu_co_queue_run_restart(co);
>  }
>  
>  void coroutine_fn qemu_coroutine_yield(void)
> 



Re: [Qemu-devel] [PATCH 0/7] NUMA code cleanup

2015-02-09 Thread Paolo Bonzini


On 08/02/2015 19:51, Eduardo Habkost wrote:
> This cleans up some of the NUMA code: moves declarations to numa.h, rename 
> some
> functions, and remove some existing code that was inside main().
> 
> Eduardo Habkost (7):
>   numa: Move NUMA declarations from sysemu.h to numa.h
>   vl.c: Remove unnecessary zero-initialization of NUMA globals
>   numa: Move NUMA globals to numa.c
>   numa: Make max_numa_nodeid static
>   numa: Move QemuOpts parsing to set_numa_nodes()
>   numa: Rename option parsing functions
>   numa: Rename set_numa_modes() to numa_post_machine_init()

Nice!

Reviewed-by: Paolo Bonzini 



Re: [Qemu-devel] Definition of the UI layer's "key number" ?

2015-02-09 Thread Gerd Hoffmann
On Mo, 2015-02-09 at 08:31 +, Peter Maydell wrote:
> On 9 February 2015 at 08:27, Gerd Hoffmann  wrote:
> > Well, we have two ways to represent a key code in qemu, unfortunately in
> > the QMP api (see KeyValue in qapi-schema.json).
> >
> > One is QKeyCode (defined in qapi-schema.json too), the other "key
> > number" is the key coding used pretty much everywhere in qemu before the
> > input layer rewrite (the new code in ui/input*.c) got merged.  It is
> > based on ps/2 keycodes.
> >
> > For new code I strongly suggest to simply ignore the old "key number"
> > coding and use QKeyCodes exclusively, it allows you to have nicely
> > readable mappings like the one in ui/sdl2-keymap.h.  Then use
> > qemu_input_event_send_key_qcode() to feed the guest with the keyboard
> > input.
> >
> > ui/input-keymap.c has a table to map QKeyCodes to "key numbers" and
> > helper functions to translate codes both ways.
> 
> Thanks. How do we handle key codes which don't exist in the translation
> tables in input-keymap.c? Specifically, we need to support the
> "keypad =" key which exists on some Mac keyboards (both for sending
> it if you're using this keyboard on the host and for receiving it
> if you're using the ADB keyboard in the guest). There is a
> Q_KEY_CODE_KP_EQUALS but it doesn't have a table entry, and since
> both the guest code and the frontend UI code in question use old
> style keycodes I'd rather the answer wasn't "convert both of them
> to use QKeyCode"...

Hmm, this certainly is the cleanest approach and it is exactly what I
did for sparc.  They had some special key numbers in the 0xf0 .. 0xff
range for keys present on the sparc keyboard but not ps/2.  sparc kbd
emulation (in hw/char/escc.c) got converted to use QKeyCodes so I could
drop those numbers.  The keymap in the sparc kbd emulation also became
much nicer in the process.

qcode_to_number[] in ui/input-keymap.c basically defines what our "key
numbers" are, so we could extend this with non-ps/2 keys, simliar to how
it was done for the sparc keys in the past.  It's hackish, but should
work as long as the number of additional keys is small.

cheers,
  Gerd





Re: [Qemu-devel] [PATCH 0/4] target-arm: fix various clang UB sanitizer warnings

2015-02-09 Thread Markus Armbruster
Peter Maydell  writes:

> On 6 February 2015 at 17:37, Eric Blake  wrote:
>> On 02/06/2015 07:34 AM, Peter Maydell wrote:
>> HACKING already implies we assume sane 2's complement behavior of shifts
>> (maybe it's worth another line for this particular case of shifting into
>> the signed bit of a signed result, and figuring out how to shut up clang):
>>
 The C language specification defines regions of undefined behavior and
 implementation defined behavior (to give compiler authors enough leeway to
 produce better code).  In general, code in QEMU should follow the language
 specification and avoid both undefined and implementation defined
 constructs. ("It works fine on the gcc I tested it with" is not a valid
 argument...) However there are a few areas where we allow ourselves to
 assume certain behaviors because in practice all the platforms we care 
 about
 behave in the same way and writing strictly conformant code would be
 painful. These are:
  * you may assume that integers are 2s complement representation
  * you may assume that right shift of a signed integer duplicates
the sign bit (ie it is an arithmetic shift, not a logical shift)
>
> The difference is that these two are implementation-defined
> behaviour, whereas shifting into the sign bit is undefined
> behaviour.
>
> I would much rather we had a well-defined and supported "friendly C"
> dialect which actually did the things programmers expect C to do:
> http://blog.regehr.org/archives/1180
>
> In the absence of that we pretty much have to assume adversarial
> optimization on the part of the compiler, because 0.5% improvements
> in SPEC benchmark scores justify breaking previously working code...

Incredibly bad tradeoff.  But what's really, truly inexcusable is
compilers smart enough to "optimize" working code into faster,
non-working code, yet not smart enough to tell us when they use their
undefined behavior license.  clang at least provides tools to give us a
fighting chance.

That said, I'm lukewarm about complicating working, straightforward code
to comply with the fine print of the standard unless there's evidence of
optimizers breaking it, without workable ways to suppress the
problematic "optimizations".  For what it's worth, the kernel uses
-fno-strict-aliasing -fno-struct-overflow.

Your option (1) "Drop the enum and just use old-fashioned #define
EC_AA64_BKPT 0x3cU" isn't too bad, though.

If Eric's option (5) "change the usage of the shifting macro" fully
solves the problem, I'd prefer it.

I've always wanted to be able to say things like "unsigned long enum".



Re: [Qemu-devel] [PATCH v2 0/7] isa: remove isa_mem_base variable

2015-02-09 Thread Leon Alrae
On 01/02/2015 08:12, Hervé Poussineau wrote:
> Hi,
> 
> This patchset removes the isa_mem_base variable in VGA display devices.
> This variable is a global variable telling at which address is the
> ISA memory base address in the system memory address space.
> 
> Once removed, we're paving the way to new QEMU functionalities:
> - supporting other MMIO ISA devices (like some network cards)
> - supporting multiple ISA buses (not done in this patchset)
> 
> Most of the changes are MIPS-related, so maybe Aurélien or Leon can
> take care of them?

Tested using Malta and looks fine for me. Since there were no objections
I'll add these patches to my mips-next tree.

Thanks,
Leon

> 
> Changes since v1:
> - correctly handle PCI0 windows in gt64xxx
> 
> Hervé Poussineau (7):
>   isa: add memory space parameter to isa_bus_new
>   jazz: do not explode QEMUMachineInitArgs structure
>   jazz: remove usage of isa_mem_base
>   mips: remove isa_mem_base usage
>   piix4: use PCI address space instead of system memory
>   gt64xxx: remove isa_mem_base usage
>   isa: remove isa_mem_base variable
> 
>  hw/alpha/typhoon.c  |2 +-
>  hw/display/cirrus_vga.c |2 +-
>  hw/display/vga-isa.c|2 +-
>  hw/display/vga.c|3 +-
>  hw/i386/pc_piix.c   |2 +-
>  hw/isa/i82378.c |3 +-
>  hw/isa/isa-bus.c|   12 --
>  hw/isa/lpc_ich9.c   |2 +-
>  hw/isa/piix4.c  |3 +-
>  hw/isa/vt82c686.c   |3 +-
>  hw/mips/gt64xxx_pci.c   |   95 
> +--
>  hw/mips/mips_jazz.c |   44 +++---
>  hw/mips/mips_r4k.c  |   19 +-
>  hw/pci-host/piix.c  |3 +-
>  hw/sparc64/sun4u.c  |3 +-
>  include/hw/isa/isa.h|6 +--
>  16 files changed, 126 insertions(+), 78 deletions(-)
> 




Re: [Qemu-devel] [PATCH] fix the co_queue multi-adding bug

2015-02-09 Thread Paolo Bonzini


On 07/02/2015 10:51, w00214312 wrote:
> From: Bin Wu 
> 
> When we test the drive_mirror between different hosts by ndb devices, 
> we find that, during the cancel phase the qemu process crashes sometimes.
> By checking the crash core file, we find the stack as follows, which means
> a coroutine re-enter error occurs:

This bug probably can be fixed simply by delaying the setting of
recv_coroutine.

What are the symptoms if you only apply your "qemu-coroutine-lock: fix
co_queue multi-adding bug" patch but not "qemu-coroutine: fix
qemu_co_queue_run_restart error"?

Can you try the patch below?  (Compile-tested only).

diff --git a/block/nbd-client.c b/block/nbd-client.c
index 6e1c97c..23d6a71 100644
--- a/block/nbd-client.c
+++ b/block/nbd-client.c
@@ -104,10 +104,21 @@ static int nbd_co_send_request(NbdClientSession *s,
 QEMUIOVector *qiov, int offset)
 {
 AioContext *aio_context;
-int rc, ret;
+int rc, ret, i;
 
 qemu_co_mutex_lock(&s->send_mutex);
+
+for (i = 0; i < MAX_NBD_REQUESTS; i++) {
+if (s->recv_coroutine[i] == NULL) {
+s->recv_coroutine[i] = qemu_coroutine_self();
+break;
+}
+}
+
+assert(i < MAX_NBD_REQUESTS);
+request->handle = INDEX_TO_HANDLE(s, i);
 s->send_coroutine = qemu_coroutine_self();
+
 aio_context = bdrv_get_aio_context(s->bs);
 aio_set_fd_handler(aio_context, s->sock,
nbd_reply_ready, nbd_restart_write, s);
@@ -164,8 +175,6 @@ static void nbd_co_receive_reply(NbdClientSession *s,
 static void nbd_coroutine_start(NbdClientSession *s,
struct nbd_request *request)
 {
-int i;
-
 /* Poor man semaphore.  The free_sema is locked when no other request
  * can be accepted, and unlocked after receiving one reply.  */
 if (s->in_flight >= MAX_NBD_REQUESTS - 1) {
@@ -174,15 +183,7 @@ static void nbd_coroutine_start(NbdClientSession *s,
 }
 s->in_flight++;
 
-for (i = 0; i < MAX_NBD_REQUESTS; i++) {
-if (s->recv_coroutine[i] == NULL) {
-s->recv_coroutine[i] = qemu_coroutine_self();
-break;
-}
-}
-
-assert(i < MAX_NBD_REQUESTS);
-request->handle = INDEX_TO_HANDLE(s, i);
+/* s->recv_coroutine[i] is set as soon as we get the send_lock.  */
 }
 
 static void nbd_coroutine_end(NbdClientSession *s,



Re: [Qemu-devel] [PATCH] qemu-coroutine-lock: fix co_queue multi-adding bug

2015-02-09 Thread Bin Wu
On 2015/2/9 16:12, Fam Zheng wrote:
> On Sat, 02/07 17:51, w00214312 wrote:
>> From: Bin Wu 
>>
>> When a coroutine holds a lock, other coroutines who want to get
>> the lock must wait on a co_queue by adding themselves to the
>> CoQueue. However, if a waiting coroutine is woken up with the
>> lock still be holding by other coroutine, this waiting coroutine
> 
> Could you explain who wakes up the waiting coroutine? Maybe the bug is that
> it shouldn't be awaken in the first place.
> 

During the mirror phase with nbd devices, if we send a cancel command or
physical network breaks down, the source qemu process will receive a readable
event and the main loop will invoke nbd_reply_ready to deal with it. This
function finds the connection is down and then goes into
nbd_teardown_connection. nbd_teardown_connection wakes up all working coroutines
by nbd_recv_coroutines_enter_all. These coroutines include the one which holds
the sending lock, the ones which wait for the lock, and the ones which wait for
receiving messages.

I think the purpose of nbd_recv_coroutines_enter_all is to terminate all waiting
coroutines by waking all of them up. If the coroutine waiting for the lock is
allowed for waking up, this implementation is ok. If not, we need to distinguish
the coroutines waiting for receiving messages from the ones waiting for the 
lock.

In my option, if the coroutines waiting for a lock is allowd for waking up, it
should be more robust :>

>> will add itself to the co_queue again. Latter, when the lock
>> is released, a coroutine re-enter will occur.
>>
>> We need to determine whether a coroutine is alread in the co_queue
> 
> s/alread/already/
> 
> Fam
> 

Thanks, my mistake.

>> before adding it to the waiting queue.
>>
>> Signed-off-by: Bin Wu 
>> ---
>>  include/block/coroutine_int.h | 1 +
>>  qemu-coroutine-lock.c | 6 +-
>>  qemu-coroutine.c  | 1 +
>>  3 files changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/include/block/coroutine_int.h b/include/block/coroutine_int.h
>> index f133d65..c524990 100644
>> --- a/include/block/coroutine_int.h
>> +++ b/include/block/coroutine_int.h
>> @@ -42,6 +42,7 @@ struct Coroutine {
>>  /* Coroutines that should be woken up when we yield or terminate */
>>  QTAILQ_HEAD(, Coroutine) co_queue_wakeup;
>>  QTAILQ_ENTRY(Coroutine) co_queue_next;
>> +bool in_co_queue;
>>  };
>>  
>>  Coroutine *qemu_coroutine_new(void);
>> diff --git a/qemu-coroutine-lock.c b/qemu-coroutine-lock.c
>> index e4860ae..d256f53 100644
>> --- a/qemu-coroutine-lock.c
>> +++ b/qemu-coroutine-lock.c
>> @@ -36,7 +36,10 @@ void qemu_co_queue_init(CoQueue *queue)
>>  void coroutine_fn qemu_co_queue_wait(CoQueue *queue)
>>  {
>>  Coroutine *self = qemu_coroutine_self();
>> -QTAILQ_INSERT_TAIL(&queue->entries, self, co_queue_next);
>> +if (!self->in_co_queue) {
>> +QTAILQ_INSERT_TAIL(&queue->entries, self, co_queue_next);
>> +self->in_co_queue = true;
>> +}
>>  qemu_coroutine_yield();
>>  assert(qemu_in_coroutine());
>>  }
>> @@ -71,6 +74,7 @@ static bool qemu_co_queue_do_restart(CoQueue *queue, bool 
>> single)
>>  
>>  while ((next = QTAILQ_FIRST(&queue->entries)) != NULL) {
>>  QTAILQ_REMOVE(&queue->entries, next, co_queue_next);
>> +next->in_co_queue = false;
>>  QTAILQ_INSERT_TAIL(&self->co_queue_wakeup, next, co_queue_next);
>>  trace_qemu_co_queue_next(next);
>>  if (single) {
>> diff --git a/qemu-coroutine.c b/qemu-coroutine.c
>> index 525247b..a103721 100644
>> --- a/qemu-coroutine.c
>> +++ b/qemu-coroutine.c
>> @@ -75,6 +75,7 @@ Coroutine *qemu_coroutine_create(CoroutineEntry *entry)
>>  }
>>  
>>  co->entry = entry;
>> +co->in_co_queue = false;
>>  QTAILQ_INIT(&co->co_queue_wakeup);
>>  return co;
>>  }
>> -- 
>> 1.7.12.4
>>
>>
> 
> .
> 

-- 
Bin Wu




Re: [Qemu-devel] [PATCH] hmp: Fix warning from smatch (wrong argument in function call)

2015-02-09 Thread Markus Armbruster
Stefan Weil  writes:

> Fix this warning:
> hmp.c:414:38: warning: Using plain integer as NULL pointer
>
> qmp_query_block expects a pointer argument, so passing false is wrong.
>
> Cc: Luiz Capitulino 
> Signed-off-by: Stefan Weil 

Reviewed-by: Markus Armbruster 



Re: [Qemu-devel] [PATCH] fix the co_queue multi-adding bug

2015-02-09 Thread Bin Wu
On 2015/2/9 17:23, Paolo Bonzini wrote:
> 
> 
> On 07/02/2015 10:51, w00214312 wrote:
>> From: Bin Wu 
>>
>> When we test the drive_mirror between different hosts by ndb devices, 
>> we find that, during the cancel phase the qemu process crashes sometimes.
>> By checking the crash core file, we find the stack as follows, which means
>> a coroutine re-enter error occurs:
> 
> This bug probably can be fixed simply by delaying the setting of
> recv_coroutine.
> 
> What are the symptoms if you only apply your "qemu-coroutine-lock: fix
> co_queue multi-adding bug" patch but not "qemu-coroutine: fix
> qemu_co_queue_run_restart error"?
> 
> Can you try the patch below?  (Compile-tested only).
> 

yes, I think this patch can solve the problem too. I will try the patch latter.

> diff --git a/block/nbd-client.c b/block/nbd-client.c
> index 6e1c97c..23d6a71 100644
> --- a/block/nbd-client.c
> +++ b/block/nbd-client.c
> @@ -104,10 +104,21 @@ static int nbd_co_send_request(NbdClientSession *s,
>  QEMUIOVector *qiov, int offset)
>  {
>  AioContext *aio_context;
> -int rc, ret;
> +int rc, ret, i;
>  
>  qemu_co_mutex_lock(&s->send_mutex);
> +
> +for (i = 0; i < MAX_NBD_REQUESTS; i++) {
> +if (s->recv_coroutine[i] == NULL) {
> +s->recv_coroutine[i] = qemu_coroutine_self();
> +break;
> +}
> +}
> +
> +assert(i < MAX_NBD_REQUESTS);
> +request->handle = INDEX_TO_HANDLE(s, i);
>  s->send_coroutine = qemu_coroutine_self();
> +
>  aio_context = bdrv_get_aio_context(s->bs);
>  aio_set_fd_handler(aio_context, s->sock,
> nbd_reply_ready, nbd_restart_write, s);
> @@ -164,8 +175,6 @@ static void nbd_co_receive_reply(NbdClientSession *s,
>  static void nbd_coroutine_start(NbdClientSession *s,
> struct nbd_request *request)
>  {
> -int i;
> -
>  /* Poor man semaphore.  The free_sema is locked when no other request
>   * can be accepted, and unlocked after receiving one reply.  */
>  if (s->in_flight >= MAX_NBD_REQUESTS - 1) {
> @@ -174,15 +183,7 @@ static void nbd_coroutine_start(NbdClientSession *s,
>  }
>  s->in_flight++;
>  
> -for (i = 0; i < MAX_NBD_REQUESTS; i++) {
> -if (s->recv_coroutine[i] == NULL) {
> -s->recv_coroutine[i] = qemu_coroutine_self();
> -break;
> -}
> -}
> -
> -assert(i < MAX_NBD_REQUESTS);
> -request->handle = INDEX_TO_HANDLE(s, i);
> +/* s->recv_coroutine[i] is set as soon as we get the send_lock.  */
>  }
>  
>  static void nbd_coroutine_end(NbdClientSession *s,
> 
> 
> 

-- 
Bin Wu




[Qemu-devel] CPU TLB flush with multithread TCG.

2015-02-09 Thread Frederic Konrad

Hi everybody,

In multithread tlb_flush is broken as CPUA can flush an other CPUB and 
CPUB can be

executing code, and fixing this can be quite hard:
  * We need to exit the CPU which is flushed.
  * Makes sure the CPU is stopped.
  * Then we can flush tlb.
The big issues are:
  * Two threads can be doing a flush at the same time.
  * Something can restart the CPU during the flush.

A better idea I think is that instead of flushing tlb we can put a flag 
in CPUState such

as flush_request and ask the cpu to exit.
Then later once the CPU is exited we can flush tlbs if flush_request is set.
It will ensure that the CPU won't execute code as it's associated thread 
will be

flushing.

Can this work?

Thanks,
Fred



Re: [Qemu-devel] [PATCH] qemu-coroutine-lock: fix co_queue multi-adding bug

2015-02-09 Thread Kevin Wolf
Am 09.02.2015 um 10:36 hat Bin Wu geschrieben:
> On 2015/2/9 16:12, Fam Zheng wrote:
> > On Sat, 02/07 17:51, w00214312 wrote:
> >> From: Bin Wu 
> >>
> >> When a coroutine holds a lock, other coroutines who want to get
> >> the lock must wait on a co_queue by adding themselves to the
> >> CoQueue. However, if a waiting coroutine is woken up with the
> >> lock still be holding by other coroutine, this waiting coroutine
> > 
> > Could you explain who wakes up the waiting coroutine? Maybe the bug is that
> > it shouldn't be awaken in the first place.
> > 
> 
> During the mirror phase with nbd devices, if we send a cancel command or
> physical network breaks down, the source qemu process will receive a readable
> event and the main loop will invoke nbd_reply_ready to deal with it. This
> function finds the connection is down and then goes into
> nbd_teardown_connection. nbd_teardown_connection wakes up all working 
> coroutines
> by nbd_recv_coroutines_enter_all. These coroutines include the one which holds
> the sending lock, the ones which wait for the lock, and the ones which wait 
> for
> receiving messages.

This is the bug. It's not allowed to reenter a coroutine if you don't
know its state. NBD needs a fix, not the the generic coroutine
infrastructure.

If we want to change anything in the lock implementation, it should be
adding an assertion to catch such violations of the rule. (Untested, but
I think the assertion should hold true.)

Kevin

diff --git a/qemu-coroutine-lock.c b/qemu-coroutine-lock.c
index e4860ae..25fc111 100644
--- a/qemu-coroutine-lock.c
+++ b/qemu-coroutine-lock.c
@@ -123,9 +123,8 @@ void coroutine_fn qemu_co_mutex_lock(CoMutex *mutex)
 
 trace_qemu_co_mutex_lock_entry(mutex, self);
 
-while (mutex->locked) {
-qemu_co_queue_wait(&mutex->queue);
-}
+qemu_co_queue_wait(&mutex->queue);
+assert(!mutex->locked);
 
 mutex->locked = true;



[Qemu-devel] --disable-vnc broken?

2015-02-09 Thread Claudio Fontana
Hello,

is some #ifdef CONFIG_VNC missing in the latest vnc changes in mainline QEMU?

I ask because configuring with --disable-vnc and then building now gets me:

../qmp-marshal.o: In function `qmp_marshal_input_query_vnc_servers':
qemu/qmp-marshal.c:2899: undefined reference to `qmp_query_vnc_servers'

while before it was working fine.

Configuring without --disable-vnc and then building works.

I bisected this and got the following.

Thanks,

Claudio

df887684603a4b3b0c623090a6b419dc70f22c32 is the first bad commit
commit df887684603a4b3b0c623090a6b419dc70f22c32
Author: Gerd Hoffmann 
Date:   Wed Dec 17 15:49:44 2014 +0100

monitor: add query-vnc-servers command

Add new query vnc qmp command, for the lack of better ideas just name it
"query-vnc-servers".  Changes over query-vnc:

 * It returns a list of vnc servers, so multiple vnc server instances
   are covered.
 * Each vnc server returns a list of server sockets.  Followup patch
   will use that to also report websockets.  In case we add support for
   multiple server sockets server sockets (to better support ipv4+ipv6
   dualstack) we can add them to the list too.

Signed-off-by: Gerd Hoffmann 




Re: [Qemu-devel] [RFC PATCH v3] tests: rtl8139: test timers and interrupt

2015-02-09 Thread Stefan Hajnoczi
On Fri, Feb 06, 2015 at 05:07:17PM +, Frediano Ziglio wrote:
> 2015-02-06 16:54 GMT+00:00 Stefan Hajnoczi :
> > On Thu, Jan 08, 2015 at 06:38:23PM +, Frediano Ziglio wrote:
> >> Test behaviour of timers and interrupts related to timeouts.
> >>
> >> Signed-off-by: Frediano Ziglio 
> >> ---
> >>  tests/Makefile   |   2 +-
> >>  tests/rtl8139-test.c | 181 
> >> +++
> >>  2 files changed, 182 insertions(+), 1 deletion(-)
> >>
> >> This patch was derived from a test I did while implementing timer in
> >> rtl8139 code. Now that there is support for integrated testing I converted
> >> it. The test was tested on a real NIC.
> >>
> >> As if it's the first test I wrote I don't know if syntax and details are
> >> fine. For instance should I remove nop test? Should I split my test?
> >>
> >> Changed from v2:
> >> - style (variable declaration, Perl script not able to spot it)
> >>
> >> Changed from v1:
> >> - style
> >
> > Thanks, applied to my net tree:
> > https://github.com/stefanha/qemu/commits/net
> 
> Hi,
>   all the comments seems to refer to my patch for testing the card but
> from https://github.com/stefanha/qemu/commits/net looks like you
> applied Paolo patch.
> 
> Is it expected?

Sorry, it didn't make it into last week's net pull request due to a
mistake.

It will be included in the next net pull request:
https://github.com/stefanha/qemu/commits/net

Stefan


pgpY8r3olsPoV.pgp
Description: PGP signature


Re: [Qemu-devel] --disable-vnc broken?

2015-02-09 Thread Gerd Hoffmann
On Mo, 2015-02-09 at 11:14 +0100, Claudio Fontana wrote:
> Hello,
> 
> is some #ifdef CONFIG_VNC missing in the latest vnc changes in mainline QEMU?
> 
> I ask because configuring with --disable-vnc and then building now gets me:
> 
> ../qmp-marshal.o: In function `qmp_marshal_input_query_vnc_servers':
> qemu/qmp-marshal.c:2899: undefined reference to `qmp_query_vnc_servers'
> 
> while before it was working fine.

http://patchwork.ozlabs.org/patch/435349/

cheers,
  Gerd





Re: [Qemu-devel] [PATCH] qemu-coroutine-lock: fix co_queue multi-adding bug

2015-02-09 Thread Paolo Bonzini


On 09/02/2015 10:36, Bin Wu wrote:
> During the mirror phase with nbd devices, if we send a cancel command or
> physical network breaks down, the source qemu process will receive a readable
> event and the main loop will invoke nbd_reply_ready to deal with it. This
> function finds the connection is down and then goes into
> nbd_teardown_connection. nbd_teardown_connection wakes up all working 
> coroutines
> by nbd_recv_coroutines_enter_all. These coroutines include the one which holds
> the sending lock, the ones which wait for the lock, and the ones which wait 
> for
> receiving messages.
> 
> I think the purpose of nbd_recv_coroutines_enter_all is to terminate all 
> waiting
> coroutines by waking all of them up. If the coroutine waiting for the lock is
> allowed for waking up, this implementation is ok. If not, we need to 
> distinguish
> the coroutines waiting for receiving messages from the ones waiting for the 
> lock.
> 
> In my option, if the coroutines waiting for a lock is allowd for waking up, it
> should be more robust :>

No, it's not allowed.

Paolo



Re: [Qemu-devel] [PATCH v2] qemu-coroutine: segfault when restarting co_queue

2015-02-09 Thread Kevin Wolf
Am 09.02.2015 um 07:50 hat Bin Wu geschrieben:
> From: Bin Wu 
> 
> We tested VMs migration with their disk images by drive_mirror. With
> migration, two VMs copyed large files between each other. During the
> test, a segfault occured. The stack was as follow:
> 
> (gdb) bt
> qemu-coroutine-lock.c:66
> to=0x7fa5a1798648) at qemu-coroutine.c:97
> request=0x7fa28c2ffa10, reply=0x7fa28c2ffa30, qiov=0x0, offset=0) at
> block/nbd-client.c:165
> sector_num=8552704, nb_sectors=2040, qiov=0x7fa5a1757468, offset=0) at
> block/nbd-client.c:262
> sector_num=8552704, nb_sectors=2048, qiov=0x7fa5a1757468) at
> block/nbd-client.c:296
> nb_sectors=2048, qiov=0x7fa5a1757468) at block/nbd.c:291
> req=0x7fa28c2ffbb0, offset=4378984448, bytes=1048576, qiov=0x7fa5a1757468,
> flags=0) at block.c:3321
> offset=4378984448, bytes=1048576, qiov=0x7fa5a1757468, flags=(unknown: 0)) at
> block.c:3447
> sector_num=8552704, nb_sectors=2048, qiov=0x7fa5a1757468, flags=(unknown: 0)) 
> at
> block.c:3471
> nb_sectors=2048, qiov=0x7fa5a1757468) at block.c:3480
> nb_sectors=2048, qiov=0x7fa5a1757468) at block/raw_bsd.c:62
> req=0x7fa28c2ffe30, offset=4378984448, bytes=1048576, qiov=0x7fa5a1757468,
> flags=0) at block.c:3321
> offset=4378984448, bytes=1048576, qiov=0x7fa5a1757468, flags=(unknown: 0)) at
> block.c:3447
> sector_num=8552704, nb_sectors=2048, qiov=0x7fa5a1757468, flags=(unknown: 0)) 
> at
> block.c:3471
> coroutine-ucontext.c:121
> 
> After analyzing the stack and reviewing the code, we find the
> qemu_co_queue_run_restart should not be put in the coroutine_swap function 
> which
> can be invoked by qemu_coroutine_enter or qemu_coroutine_yield. Only
> qemu_coroutine_enter needs to restart the co_queue.
> 
> The error scenario is as follow: coroutine C1 enters C2, C2 yields
> back to C1, then C1 ternimates and the related coroutine memory
> becomes invalid. After a while, the C2 coroutine is entered again.
> At this point, C1 is used as a parameter passed to
> qemu_co_queue_run_restart. Therefore, qemu_co_queue_run_restart
> accesses an invalid memory and a segfault error ocurrs.

Why would C1 be used for the qemu_co_queue_run_restart() call? There is
only one caller, coroutine_swap(). It calls the function for the
coroutine that has just yielded or terminated. In the case of
termination, the coroutine is deleted only afterwards, in the switch
block in coroutine_swap().

> The qemu_co_queue_run_restart function re-enters coroutines waiting
> in the co_queue. However, this function should be only used int the
> qemu_coroutine_enter context.

It shouldn't make a difference. Any coroutine waiting in a CoQueue
should be ready to be restarted at either point.

Kevin



[Qemu-devel] [PATCHv2] Prevent segmentation fault in case of relative resolve of uri

2015-02-09 Thread mrezanin
From: Miroslav Rezanina 

It was possible to call strcmp with NULL argument, that can cause
segmentation fault. Properly checking parameters to prevent this
situation.

Signed-off-by: Miroslav Rezanina 
---
v2:
 - instead of adding NULL checks to strcmp call refactor whole
   NULL checking path. This will remove dead code and make whole checking
   easier to understand.

   Relative path generation part is not touched as I'm not fully sure
   of correct behavior and purpose of this patch is to prevent segmentation
   fault.
---
 util/uri.c | 55 +--
 1 file changed, 25 insertions(+), 30 deletions(-)

diff --git a/util/uri.c b/util/uri.c
index 918d235..23dbaca 100644
--- a/util/uri.c
+++ b/util/uri.c
@@ -1964,44 +1964,39 @@ uri_resolve_relative (const char *uri, const char * 
base)
  * If the scheme / server on the URI differs from the base,
  * just return the URI
  */
-if ((ref->scheme != NULL) &&
-   ((bas->scheme == NULL) ||
-(strcmp (bas->scheme, ref->scheme)) ||
-(strcmp (bas->server, ref->server {
-   val = g_strdup (uri);
-   goto done;
+
+if ((ref->scheme != NULL) && 
+((bas->scheme == NULL) || (strcmp (bas->scheme, ref->scheme {
+val = g_strdup(uri);
+goto done;
 }
-if (!strcmp(bas->path, ref->path)) {
-   val = g_strdup("");
-   goto done;
-}
-if (bas->path == NULL) {
-   val = g_strdup(ref->path);
-   goto done;
+if ((ref->server != NULL) &&
+((bas->server == NULL) || (strcmp (bas->server, ref->server {
+val = g_strdup(uri);
+goto done;
 }
+
 if (ref->path == NULL) {
 ref->path = (char *) "/";
-   remove_path = 1;
+remove_path = 1;
 }
 
-/*
- * At this point (at last!) we can compare the two paths
- *
- * First we take care of the special case where either of the
- * two path components may be missing (bug 316224)
- */
 if (bas->path == NULL) {
-   if (ref->path != NULL) {
-   uptr = ref->path;
-   if (*uptr == '/')
-   uptr++;
-   /* exception characters from uri_to_string */
-   val = uri_string_escape(uptr, "/;&=+$,");
-   }
-   goto done;
+uptr = ref->path;
+if (*uptr == '/')
+uptr++;
+/* exception characters from uri_to_string */
+val = uri_string_escape(uptr, "/;&=+$,");
+goto done;
 }
+
+if (!strcmp(bas->path, ref->path)) {
+val = g_strdup("");
+goto done;
+}
+
 bptr = bas->path;
-if (ref->path == NULL) {
+if (remove_path == 1) {
for (ix = 0; bptr[ix] != 0; ix++) {
if (bptr[ix] == '/')
nbslash++;
@@ -2010,7 +2005,7 @@ uri_resolve_relative (const char *uri, const char * base)
len = 1;/* this is for a string terminator only */
 } else {
 /*
- * Next we compare the two strings and find where they first differ
+ * We compare the two strings and find where they first differ
  */
if ((ref->path[pos] == '.') && (ref->path[pos+1] == '/'))
 pos += 2;
-- 
2.1.0




[Qemu-devel] [PATCH] vhost-scsi: Improve error reporting for invalid vhostfd

2015-02-09 Thread Markus Armbruster
We get two error messages: one from monitor_handle_fd_param2(), and
another one from vhost_scsi_realize().  The second one gets suppressed
in QMP context.

That's because monitor_handle_fd_param() calls qerror_report_err().
Calling qerror_report_err() is always inappropriate in realize
methods, because it doesn't return the Error object.  It either
reports the error to stderr or the human monitor, or it stores it in
the QMP monitor, where it makes the QMP command fail even when the
realize method ignores the error and succeeds.  Fortunately,
vhost_scsi_realize() doesn't do that.

Fix by switching to monitor_handle_fd_param2().

Signed-off-by: Markus Armbruster 
---
 hw/scsi/vhost-scsi.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c
index dcb2bc5..567f350 100644
--- a/hw/scsi/vhost-scsi.c
+++ b/hw/scsi/vhost-scsi.c
@@ -214,9 +214,11 @@ static void vhost_scsi_realize(DeviceState *dev, Error 
**errp)
 }
 
 if (vs->conf.vhostfd) {
-vhostfd = monitor_handle_fd_param(cur_mon, vs->conf.vhostfd);
+vhostfd = monitor_handle_fd_param2(cur_mon, vs->conf.vhostfd, &err);
 if (vhostfd == -1) {
-error_setg(errp, "vhost-scsi: unable to parse vhostfd");
+error_setg(errp, "vhost-scsi: unable to parse vhostfd: %s",
+   error_get_pretty(err));
+error_free(err);
 return;
 }
 } else {
-- 
1.9.3




[Qemu-devel] [PATCH v3 03/52] pc: acpi: make top level ACPI tables blob Aml*

2015-02-09 Thread Igor Mammedov
it will permit to add a separate tables into blob like other
AML constructs using aml_append() routine and hide from user
need to invoke linker manually for tables, handling it
automatically inside of aml_append() helper.

Later when all tables are converted to use AML API, it would
be possible to generate RSDT automatically and drop manual
table offsets tracking for RSDT.

Signed-off-by: Igor Mammedov 
---
 hw/i386/acpi-build.c | 19 ++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 8020899..788962e 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1238,7 +1238,7 @@ build_rsdp(GArray *rsdp_table, GArray *linker, unsigned 
rsdt)
 
 typedef
 struct AcpiBuildTables {
-GArray *table_data;
+Aml *table_data;
 GArray *rsdp;
 GArray *tcpalog;
 GArray *linker;
@@ -1247,17 +1247,17 @@ struct AcpiBuildTables {
 static inline void acpi_build_tables_init(AcpiBuildTables *tables)
 {
 tables->rsdp = g_array_new(false, true /* clear */, 1);
-tables->table_data = g_array_new(false, true /* clear */, 1);
 tables->tcpalog = g_array_new(false, true /* clear */, 1);
 tables->linker = bios_linker_loader_init();
+tables->table_data = init_aml_allocator(tables->linker);
 }
 
 static inline void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool 
mfre)
 {
 void *linker_data = bios_linker_loader_cleanup(tables->linker);
+free_aml_allocator();
 g_free(linker_data);
 g_array_free(tables->rsdp, mfre);
-g_array_free(tables->table_data, true);
 g_array_free(tables->tcpalog, mfre);
 }
 
@@ -1317,7 +1317,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables 
*tables)
 PcPciInfo pci;
 uint8_t *u;
 size_t aml_len = 0;
-GArray *tables_blob = tables->table_data;
+GArray *tables_blob = tables->table_data->buf;
 
 acpi_get_cpu_info(&cpu);
 acpi_get_pm_info(&pm);
@@ -1469,14 +1469,14 @@ static void acpi_build_update(void *build_opaque, 
uint32_t offset)
 
 acpi_build(build_state->guest_info, &tables);
 
-assert(acpi_data_len(tables.table_data) == build_state->table_size);
+assert(acpi_data_len(tables.table_data->buf) == build_state->table_size);
 
 /* Make sure RAM size is correct - in case it got changed by migration */
 qemu_ram_resize(build_state->table_ram, build_state->table_size,
 &error_abort);
 
-memcpy(qemu_get_ram_ptr(build_state->table_ram), tables.table_data->data,
-   build_state->table_size);
+memcpy(qemu_get_ram_ptr(build_state->table_ram),
+   tables.table_data->buf->data, build_state->table_size);
 
 cpu_physical_memory_set_dirty_range_nocode(build_state->table_ram,
build_state->table_size);
@@ -1537,11 +1537,12 @@ void acpi_setup(PcGuestInfo *guest_info)
 acpi_build(build_state->guest_info, &tables);
 
 /* Now expose it all to Guest */
-build_state->table_ram = acpi_add_rom_blob(build_state, tables.table_data,
+build_state->table_ram = acpi_add_rom_blob(build_state,
+   tables.table_data->buf,
ACPI_BUILD_TABLE_FILE,
ACPI_BUILD_TABLE_MAX_SIZE);
 assert(build_state->table_ram != RAM_ADDR_MAX);
-build_state->table_size = acpi_data_len(tables.table_data);
+build_state->table_size = acpi_data_len(tables.table_data->buf);
 
 acpi_add_rom_blob(NULL, tables.linker, "etc/table-loader", 0);
 
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 02/52] pc: acpi: use local var for accessing ACPI tables blob in acpi_build()

2015-02-09 Thread Igor Mammedov
except of shortening of lines and making code a bit more readable,
it will reduce renaming noise when changing tables blob from GArray* to
Aml* type.

Signed-off-by: Igor Mammedov 
---
 hw/i386/acpi-build.c | 69 ++--
 1 file changed, 35 insertions(+), 34 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 237080f..8020899 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1317,6 +1317,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables 
*tables)
 PcPciInfo pci;
 uint8_t *u;
 size_t aml_len = 0;
+GArray *tables_blob = tables->table_data;
 
 acpi_get_cpu_info(&cpu);
 acpi_get_pm_info(&pm);
@@ -1337,66 +1338,66 @@ void acpi_build(PcGuestInfo *guest_info, 
AcpiBuildTables *tables)
  * We place it first since it's the only table that has alignment
  * requirements.
  */
-facs = tables->table_data->len;
-build_facs(tables->table_data, tables->linker, guest_info);
+facs = tables_blob->len;
+build_facs(tables_blob, tables->linker, guest_info);
 
 /* DSDT is pointed to by FADT */
-dsdt = tables->table_data->len;
-build_dsdt(tables->table_data, tables->linker, &misc);
+dsdt = tables_blob->len;
+build_dsdt(tables_blob, tables->linker, &misc);
 
 /* Count the size of the DSDT and SSDT, we will need it for legacy
  * sizing of ACPI tables.
  */
-aml_len += tables->table_data->len - dsdt;
+aml_len += tables_blob->len - dsdt;
 
 /* ACPI tables pointed to by RSDT */
-acpi_add_table(table_offsets, tables->table_data);
-build_fadt(tables->table_data, tables->linker, &pm, facs, dsdt);
+acpi_add_table(table_offsets, tables_blob);
+build_fadt(tables_blob, tables->linker, &pm, facs, dsdt);
 
-ssdt = tables->table_data->len;
-acpi_add_table(table_offsets, tables->table_data);
-build_ssdt(tables->table_data, tables->linker, &cpu, &pm, &misc, &pci,
+ssdt = tables_blob->len;
+acpi_add_table(table_offsets, tables_blob);
+build_ssdt(tables_blob, tables->linker, &cpu, &pm, &misc, &pci,
guest_info);
-aml_len += tables->table_data->len - ssdt;
+aml_len += tables_blob->len - ssdt;
 
-acpi_add_table(table_offsets, tables->table_data);
-build_madt(tables->table_data, tables->linker, &cpu, guest_info);
+acpi_add_table(table_offsets, tables_blob);
+build_madt(tables_blob, tables->linker, &cpu, guest_info);
 
 if (misc.has_hpet) {
-acpi_add_table(table_offsets, tables->table_data);
-build_hpet(tables->table_data, tables->linker);
+acpi_add_table(table_offsets, tables_blob);
+build_hpet(tables_blob, tables->linker);
 }
 if (misc.has_tpm) {
-acpi_add_table(table_offsets, tables->table_data);
-build_tpm_tcpa(tables->table_data, tables->linker, tables->tcpalog);
+acpi_add_table(table_offsets, tables_blob);
+build_tpm_tcpa(tables_blob, tables->linker, tables->tcpalog);
 
-acpi_add_table(table_offsets, tables->table_data);
-build_tpm_ssdt(tables->table_data, tables->linker);
+acpi_add_table(table_offsets, tables_blob);
+build_tpm_ssdt(tables_blob, tables->linker);
 }
 if (guest_info->numa_nodes) {
-acpi_add_table(table_offsets, tables->table_data);
-build_srat(tables->table_data, tables->linker, guest_info);
+acpi_add_table(table_offsets, tables_blob);
+build_srat(tables_blob, tables->linker, guest_info);
 }
 if (acpi_get_mcfg(&mcfg)) {
-acpi_add_table(table_offsets, tables->table_data);
-build_mcfg_q35(tables->table_data, tables->linker, &mcfg);
+acpi_add_table(table_offsets, tables_blob);
+build_mcfg_q35(tables_blob, tables->linker, &mcfg);
 }
 if (acpi_has_iommu()) {
-acpi_add_table(table_offsets, tables->table_data);
-build_dmar_q35(tables->table_data, tables->linker);
+acpi_add_table(table_offsets, tables_blob);
+build_dmar_q35(tables_blob, tables->linker);
 }
 
 /* Add tables supplied by user (if any) */
 for (u = acpi_table_first(); u; u = acpi_table_next(u)) {
 unsigned len = acpi_table_len(u);
 
-acpi_add_table(table_offsets, tables->table_data);
-g_array_append_vals(tables->table_data, u, len);
+acpi_add_table(table_offsets, tables_blob);
+g_array_append_vals(tables_blob, u, len);
 }
 
 /* RSDT is pointed to by RSDP */
-rsdt = tables->table_data->len;
-build_rsdt(tables->table_data, tables->linker, table_offsets);
+rsdt = tables_blob->len;
+build_rsdt(tables_blob, tables->linker, table_offsets);
 
 /* RSDP is in FSEG memory, so allocate it separately */
 build_rsdp(tables->rsdp, tables->linker, rsdt);
@@ -1428,23 +1429,23 @@ void acpi_build(PcGuestInfo *guest_info, 
AcpiBuildTables *tables)
 guest_info->legacy_acpi_table_size +
 ACPI_BUILD_L

[Qemu-devel] [PATCH v3 04/52] acpi: factor out ACPI const int packing out of build_append_value()

2015-02-09 Thread Igor Mammedov
it will be reused for adding a plain integer value into AML.

Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c  | 19 +++
 hw/i386/acpi-build.c |  6 +++---
 2 files changed, 6 insertions(+), 19 deletions(-)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 096f347..67d1371 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -221,24 +221,8 @@ void build_extop_package(GArray *package, uint8_t op)
 
 void build_append_value(GArray *table, uint32_t value, int size)
 {
-uint8_t prefix;
 int i;
 
-switch (size) {
-case 1:
-prefix = 0x0A; /* BytePrefix */
-break;
-case 2:
-prefix = 0x0B; /* WordPrefix */
-break;
-case 4:
-prefix = 0x0C; /* DWordPrefix */
-break;
-default:
-assert(0);
-return;
-}
-build_append_byte(table, prefix);
 for (i = 0; i < size; ++i) {
 build_append_byte(table, value & 0xFF);
 value = value >> 8;
@@ -252,10 +236,13 @@ void build_append_int(GArray *table, uint32_t value)
 } else if (value == 0x01) {
 build_append_byte(table, 0x01); /* OneOp */
 } else if (value <= 0xFF) {
+build_append_byte(table, 0x0A); /* BytePrefix */
 build_append_value(table, value, 1);
 } else if (value <= 0x) {
+build_append_byte(table, 0x0B); /* WordPrefix */
 build_append_value(table, value, 2);
 } else {
+build_append_byte(table, 0x0C); /* DWordPrefix */
 build_append_value(table, value, 4);
 }
 }
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 788962e..a1bf450 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -302,14 +302,14 @@ static void build_append_and_cleanup_method(GArray 
*device, GArray *method)
 
 static void build_append_notify_target_ifequal(GArray *method,
GArray *target_name,
-   uint32_t value, int size)
+   uint32_t value)
 {
 GArray *notify = build_alloc_array();
 uint8_t op = 0xA0; /* IfOp */
 
 build_append_byte(notify, 0x93); /* LEqualOp */
 build_append_byte(notify, 0x68); /* Arg0Op */
-build_append_value(notify, value, size);
+build_append_int(notify, value);
 build_append_byte(notify, 0x86); /* NotifyOp */
 build_append_array(notify, target_name);
 build_append_byte(notify, 0x69); /* Arg1Op */
@@ -578,7 +578,7 @@ build_append_notify_method(GArray *device, const char *name,
 GArray *target = build_alloc_array();
 build_append_namestring(target, format, i);
 assert(i < 256); /* Fits in 1 byte */
-build_append_notify_target_ifequal(method, target, i, 1);
+build_append_notify_target_ifequal(method, target, i);
 build_free_array(target);
 }
 
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 00/52] ACPI refactoring: replace template patching with C AML API

2015-02-09 Thread Igor Mammedov
changes since v2:
  * rename acpi prefixes in API to aml
  * reverse conversion order from bottom->top to top->bottom
  * introduce internal Aml garbage collector and 2 API functions
to initialize and cleanup it up
  * replace acpi_argX() helpers with a single aml_arg(X) helper
do the same for acpi_localX() helpers.
  * add 3 internal allocators, for allocating dummy Aml struct
for helpers aml_alloc(), aml_opcode(OPCODE) for simple Aml
elements and aml_bundle(opcode, kind) for complex elements
that require post-processing after element has been composed
  * amend spec references to ACPI 1.0b and later if AML element
was introduced later
  * various codestyle fixes
  * rebase on top of PCI tree

changes since RFC:
  * conflicts with vmgenid (broken) patches, so it's not based on PCI tree
  * rebased on top of today's master +
[PATCH v5 0/5] pc: acpi: various fixes and cleanups +
some patches from PCI tree that above series depends on
  * small cleanups
  * droped [42/47] acpi: make tables linker-loader available to other targets
since Michael has a cleaner similar patch(es) in PCI tree,
so reuse them (not included in here)
  * move SMC device from DSDT to SSDT and create it only when
applesmc device is present.


This series refactors SSDT runtime composing and gets rid of:
* patching AML templates, with related pointer arithmetic magic
* manual AML composition, i.e. creating AML terms practically
  byte by byte
* using AML templates for SSDT creation, reducing dependency on IASL.
  as result of above, QEMU source tree doesn't have to carry
  'binary' template blobs that used to be part of SSDT.
* hand-crafted PCI0._CRSes for pc/q35 machines in DSDT with
  manual hole punching of reserved resources
and adds following:
* introduces ASL like API for creating AML objects using ASL
  like constructs/terms. API: 
  * provides a necessary minimum set of terms/helpers to
replace currently used SSDT templates.
  * simplifies AML composition and keeps track of AML
object contexts, transparently managing their 
(de)allocation and merging into parent context,
making composition of SSDT 'almost' like writing
native ASL definition of the table.
  * hides pointer arithmetic from user when composing
SSDT.
* dynamically creates unified PCI0._CRS in SSDT for pc/q35
  machines allowing to reserve resources at runtime vs
  current compile time
* while adding new API, make it target independed CONFIG_ACPI
  and also make some other utilities for composing ACPI tables
  target independed (i.e. utils on which API depends) so that
  they could be reused for ARM target later without moving
  stuff around uncessarily.
* trims SSDT by not creating objects that are not present
  (S[34] Package if disabled, pvpanic, applesmc)

As result of replacing AML templates with ASL API, codebase
reduces on ~1900LOC even with net addition of API 1050LOC counted in.


Tested with XPsp3, WS2012R2, RHEL6/7 guests. 

Git tree for playing with:
https://github.com/imammedo/qemu/commits/ASL_API_v3


Igor Mammedov (52):
  acpi: introduce AML composer aml_append()
  pc: acpi: use local var for accessing ACPI tables blob in acpi_build()
  pc: acpi: make top level ACPI tables blob Aml*
  acpi: factor out ACPI const int packing out of build_append_value()
  acpi: add aml_def_block() term
  pc: acpi-build: use aml_def_block() for declaring SSDT table
  acpi: add aml_scope() term
  pc: acpi-build: use aml_scope() for \_SB scope
  acpi: add aml_device() term
  acpi: add aml_method() term
  acpi: add aml_if() term
  acpi: add aml_name() & aml_name_decl() term
  acpi: extend build_append_{value|int}() to support 64-bit values
  acpi: add aml_int() term
  acpi: add aml_return() term
  acpi: add aml_arg() term
  acpi: add aml_store() term
  acpi: add aml_and() term
  acpi: add aml_notify() term
  acpi: add aml_call1(), aml_call2(), aml_call3(), aml_call4() helpers
  pc: acpi-build: drop template patching and create PCI bus tree
dynamically
  acpi: add aml_package() term
  pc: acpi-build: drop unsupported PM1b_CNT.SLP_TYP
  pc: acpi-build: generate _S[345] packages dynamically
  acpi: add aml_buffer() term
  acpi: add aml_resource_template() helper
  acpi: add aml_io() helper
  acpi: include PkgLength size only when requested
  acpi: add aml_operation_region() term
  acpi: add aml_field() & aml_named_field() terms
  acpi: add aml_local() term
  acpi: add aml_string() term
  pc: acpi-build: generate pvpanic device description dynamically
  acpi: add aml_varpackage() term
  acpi: add aml_equal() term
  acpi: add aml_processor() term
  acpi: add aml_eisaid() term
  pc: acpi-build: drop template patching and CPU hotplug objects
dynamically
  pc: acpi-build: create CPU hotplug IO region dynamically
  acpi: add aml_reserved_field() term
  pc: 

[Qemu-devel] [PATCH v3 09/52] acpi: add aml_device() term

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 11 +++
 include/hw/acpi/aml-build.h |  1 +
 2 files changed, 12 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 31a3786..e38a222 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -393,3 +393,14 @@ Aml *aml_scope(const char *name_format, ...)
 va_end(ap);
 return var;
 }
+
+/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefDevice */
+Aml *aml_device(const char *name_format, ...)
+{
+va_list ap;
+Aml *var = aml_bundle(0x82 /* DeviceOp */, AML_EXT_PACKAGE);
+va_start(ap, name_format);
+build_append_namestringv(var->buf, name_format, ap);
+va_end(ap);
+return var;
+}
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 35f1099..dfc725e 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -75,6 +75,7 @@ Aml *aml_def_block(const char *signature, uint8_t revision,
uint32_t oem_revision, uint32_t creator_id,
uint32_t creator_revision);
 Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
+Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 
 /* other helpers */
 GArray *build_alloc_array(void);
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 06/52] pc: acpi-build: use aml_def_block() for declaring SSDT table

2015-02-09 Thread Igor Mammedov
it replaces prebuilt SSDT table header template copying/patching
with AML API

Signed-off-by: Igor Mammedov 
---
 hw/i386/acpi-build.c | 26 --
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 553c86b..fcefa07 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -816,15 +816,15 @@ static void patch_pci_windows(PcPciInfo *pci, uint8_t 
*start, unsigned size)
 }
 
 static void
-build_ssdt(GArray *table_data, GArray *linker,
+build_ssdt(Aml *table_data,
AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
PcPciInfo *pci, PcGuestInfo *guest_info)
 {
 MachineState *machine = MACHINE(qdev_get_machine());
 uint32_t nr_mem = machine->ram_slots;
 unsigned acpi_cpus = guest_info->apic_id_limit;
-int ssdt_start = table_data->len;
 uint8_t *ssdt_ptr;
+Aml *ssdt;
 int i;
 
 /* The current AML generator can cover the APIC ID range [0..255],
@@ -832,9 +832,17 @@ build_ssdt(GArray *table_data, GArray *linker,
 QEMU_BUILD_BUG_ON(ACPI_CPU_HOTPLUG_ID_LIMIT > 256);
 g_assert(acpi_cpus <= ACPI_CPU_HOTPLUG_ID_LIMIT);
 
-/* Copy header and patch values in the S3_ / S4_ / S5_ packages */
-ssdt_ptr = acpi_data_push(table_data, sizeof(ssdp_misc_aml));
-memcpy(ssdt_ptr, ssdp_misc_aml, sizeof(ssdp_misc_aml));
+/* Init SSDT Definition Block */
+ssdt = aml_def_block("SSDT", 1, ACPI_BUILD_APPNAME6,
+ ACPI_BUILD_APPNAME4, 1,
+ ACPI_BUILD_APPNAME4_HEX, 1);
+
+/* Copy misc variables and patch values in the S3_ / S4_ / S5_ packages */
+acpi_data_push(ssdt->buf, sizeof(ssdp_misc_aml) - sizeof(AcpiTableHeader));
+ssdt_ptr = (uint8_t *)ssdt->buf->data;
+memcpy(ssdt_ptr + sizeof(AcpiTableHeader),
+   ssdp_misc_aml + sizeof(AcpiTableHeader),
+   sizeof(ssdp_misc_aml) - sizeof(AcpiTableHeader));
 if (pm->s3_disabled) {
 ssdt_ptr[acpi_s3_name[0]] = 'X';
 }
@@ -944,13 +952,11 @@ build_ssdt(GArray *table_data, GArray *linker,
 }
 }
 build_package(sb_scope, op);
-build_append_array(table_data, sb_scope);
+build_append_array(ssdt->buf, sb_scope);
 build_free_array(sb_scope);
 }
 
-build_header(linker, table_data,
- (void *)(table_data->data + ssdt_start),
- "SSDT", table_data->len - ssdt_start, 1);
+aml_append(table_data, ssdt);
 }
 
 static void
@@ -1352,7 +1358,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables 
*tables)
 
 ssdt = tables_blob->len;
 acpi_add_table(table_offsets, tables_blob);
-build_ssdt(tables_blob, tables->linker, &cpu, &pm, &misc, &pci,
+build_ssdt(tables->table_data, &cpu, &pm, &misc, &pci,
guest_info);
 aml_len += tables_blob->len - ssdt;
 
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 11/52] acpi: add aml_if() term

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 8 
 include/hw/acpi/aml-build.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 7389009..9f43fef 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -383,6 +383,14 @@ Aml *aml_def_block(const char *signature, uint8_t revision,
 return var;
 }
 
+/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
+Aml *aml_if(Aml *predicate)
+{
+Aml *var = aml_bundle(0xA0 /* IfOp */, AML_PACKAGE);
+aml_append(var, predicate);
+return var;
+}
+
 /* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefMethod */
 Aml *aml_method(const char *name, int arg_count)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index c1720e7..7cd1f51 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -77,6 +77,7 @@ Aml *aml_def_block(const char *signature, uint8_t revision,
 Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_method(const char *name, int arg_count);
+Aml *aml_if(Aml *predicate);
 
 /* other helpers */
 GArray *build_alloc_array(void);
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 01/52] acpi: introduce AML composer aml_append()

2015-02-09 Thread Igor Mammedov
Adds for dynamic AML creation, which will be used
for piecing ASL/AML primitives together and hiding
from user/caller details about how nested context
should be closed/packed leaving less space for
mistakes and necessity to know how AML should be
encoded, allowing user to concentrate on ASL
representation instead.

For example it will allow to create AML like this:

init_aml_allocator();
...
Aml *scope = aml_scope("PCI0")
Aml *dev = aml_device("PM")
aml_append(dev, aml_name_decl("_ADR", aml_int(addr)))
aml_append(scope, dev);
...
free_aml_allocator();

Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 91 +
 hw/i386/acpi-build.c|  1 -
 include/hw/acpi/aml-build.h | 61 ++
 3 files changed, 152 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index bcb288e..096f347 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -25,6 +25,8 @@
 #include 
 #include 
 #include "hw/acpi/aml-build.h"
+#include "qemu/bswap.h"
+#include "hw/acpi/bios-linker-loader.h"
 
 GArray *build_alloc_array(void)
 {
@@ -257,3 +259,92 @@ void build_append_int(GArray *table, uint32_t value)
 build_append_value(table, value, 4);
 }
 }
+
+static GPtrArray *alloc_list;
+
+static Aml *aml_alloc(void)
+{
+Aml *var = g_new0(typeof(*var), 1);
+
+g_ptr_array_add(alloc_list, var);
+var->block_flags = AML_HELPER;
+var->buf = build_alloc_array();
+return var;
+}
+
+static void aml_free(gpointer data)
+{
+Aml *var = data;
+build_free_array(var->buf);
+}
+
+Aml *init_aml_allocator(GArray *linker)
+{
+Aml *var;
+
+assert(!alloc_list);
+alloc_list = g_ptr_array_new_with_free_func(aml_free);
+var = aml_alloc();
+var->linker = linker;
+return var;
+}
+
+void free_aml_allocator(void)
+{
+g_ptr_array_free(alloc_list, true);
+alloc_list = 0;
+}
+
+static void build_buffer(GArray *array, uint8_t op)
+{
+GArray *data = build_alloc_array();
+
+build_append_int(data, array->len);
+g_array_prepend_vals(array, data->data, data->len);
+build_free_array(data);
+build_package(array, op);
+}
+
+void aml_append(Aml *parent_ctx, Aml *child)
+{
+switch (child->block_flags) {
+case AML_NON_BLOCK:
+build_append_byte(parent_ctx->buf, child->op);
+break;
+case AML_EXT_PACKAGE:
+build_extop_package(child->buf, child->op);
+break;
+case AML_PACKAGE:
+build_package(child->buf, child->op);
+break;
+case AML_RES_TEMPLATE:
+build_append_byte(child->buf, 0x79); /* EndTag */
+/*
+ * checksum operations is treated as succeeded if checksum
+ * field is zero. [ACPI Spec 5.0, 6.4.2.9 End Tag]
+ */
+build_append_byte(child->buf, 0);
+/* fall through, to pack resources in buffer */
+case AML_BUFFER:
+build_buffer(child->buf, child->op);
+break;
+case AML_DEF_BLOCK: {
+uint8_t *start = (uint8_t *)parent_ctx->buf->data +
+ parent_ctx->buf->len;
+uint32_t le32_len = cpu_to_le32(child->buf->len);
+
+/* create linker entry for the DefinitionBlock */
+bios_linker_loader_add_checksum(parent_ctx->linker,
+ACPI_BUILD_TABLE_FILE,
+parent_ctx->buf->data,
+start, child->buf->len, start + 9 /* checksum offset */);
+
+/* set DefinitionBlock length at TableLength offset*/
+memcpy(child->buf->data + 4, &le32_len, sizeof le32_len);
+break;
+}
+default:
+break;
+}
+build_append_array(parent_ctx->buf, child->buf);
+}
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 6d84f38..237080f 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -258,7 +258,6 @@ static void acpi_get_pci_info(PcPciInfo *info)
 #define ACPI_BUILD_APPNAME6 "BOCHS "
 #define ACPI_BUILD_APPNAME4 "BXPC"
 
-#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
 #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
 #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
 
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 199f003..4033796 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -5,6 +5,67 @@
 #include 
 #include "qemu/compiler.h"
 
+#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
+
+typedef enum {
+AML_HELPER = 0,
+AML_NON_BLOCK,
+AML_PACKAGE,
+AML_EXT_PACKAGE,
+AML_BUFFER,
+AML_RES_TEMPLATE,
+AML_DEF_BLOCK,
+} AmlBlockFlags;
+
+struct Aml {
+GArray *buf;
+
+/*< private >*/
+uint8_t op;
+AmlBlockFlags block_flags;
+GArray *linker;
+};
+typedef struct Aml Aml;
+
+/**
+ * init_aml_allocator:
+ * @linker: linker that used by API for registering ACPI tables
+ *  with linker firmware interfac
+ *
+ * Called for initializing API allocator which allow to use
+ * AML API.
+ * Returns: toplevel container which accumulates 

[Qemu-devel] [PATCH v3 07/52] acpi: add aml_scope() term

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 20 
 include/hw/acpi/aml-build.h |  1 +
 2 files changed, 21 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index cb1a1bd..31a3786 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -259,6 +259,15 @@ static Aml *aml_alloc(void)
 return var;
 }
 
+static Aml *aml_bundle(uint8_t op, AmlBlockFlags flags)
+{
+Aml *var = aml_alloc();
+
+var->op  = op;
+var->block_flags = flags;
+return var;
+}
+
 static void aml_free(gpointer data)
 {
 Aml *var = data;
@@ -373,3 +382,14 @@ Aml *aml_def_block(const char *signature, uint8_t revision,
 
 return var;
 }
+
+/* ACPI 1.0b: 16.2.5.1 Namespace Modifier Objects Encoding: DefScope */
+Aml *aml_scope(const char *name_format, ...)
+{
+va_list ap;
+Aml *var = aml_bundle(0x10 /* ScopeOp */, AML_PACKAGE);
+va_start(ap, name_format);
+build_append_namestringv(var->buf, name_format, ap);
+va_end(ap);
+return var;
+}
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 2610336..35f1099 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -74,6 +74,7 @@ Aml *aml_def_block(const char *signature, uint8_t revision,
const char *oem_id, const char *oem_table_id,
uint32_t oem_revision, uint32_t creator_id,
uint32_t creator_revision);
+Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 
 /* other helpers */
 GArray *build_alloc_array(void);
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 08/52] pc: acpi-build: use aml_scope() for \_SB scope

2015-02-09 Thread Igor Mammedov
prepares for incremental conversion of SSDT contents to AML API

Signed-off-by: Igor Mammedov 
---
 hw/i386/acpi-build.c | 29 -
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index fcefa07..bdc343f 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -824,7 +824,7 @@ build_ssdt(Aml *table_data,
 uint32_t nr_mem = machine->ram_slots;
 unsigned acpi_cpus = guest_info->apic_id_limit;
 uint8_t *ssdt_ptr;
-Aml *ssdt;
+Aml *ssdt, *sb_scope;
 int i;
 
 /* The current AML generator can cover the APIC ID range [0..255],
@@ -861,15 +861,11 @@ build_ssdt(Aml *table_data,
 ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
   ssdt_mctrl_nr_slots[0], 32, nr_mem);
 
+sb_scope = aml_scope("_SB");
 {
-GArray *sb_scope = build_alloc_array();
-uint8_t op = 0x10; /* ScopeOp */
-
-build_append_namestring(sb_scope, "_SB");
-
 /* build Processor object for each processor */
 for (i = 0; i < acpi_cpus; i++) {
-uint8_t *proc = acpi_data_push(sb_scope, ACPI_PROC_SIZEOF);
+uint8_t *proc = acpi_data_push(sb_scope->buf, ACPI_PROC_SIZEOF);
 memcpy(proc, ACPI_PROC_AML, ACPI_PROC_SIZEOF);
 proc[ACPI_PROC_OFFSET_CPUHEX] = acpi_get_hex(i >> 4);
 proc[ACPI_PROC_OFFSET_CPUHEX+1] = acpi_get_hex(i);
@@ -881,11 +877,12 @@ build_ssdt(Aml *table_data,
  *   Method(NTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CP00, Arg1)} ...}
  */
 /* Arg0 = Processor ID = APIC ID */
-build_append_notify_method(sb_scope, "NTFY", "CP%0.02X", acpi_cpus);
+build_append_notify_method(sb_scope->buf, "NTFY",
+   "CP%0.02X", acpi_cpus);
 
 /* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" */
-build_append_byte(sb_scope, 0x08); /* NameOp */
-build_append_namestring(sb_scope, "CPON");
+build_append_byte(sb_scope->buf, 0x08); /* NameOp */
+build_append_namestring(sb_scope->buf, "CPON");
 
 {
 GArray *package = build_alloc_array();
@@ -910,7 +907,7 @@ build_ssdt(Aml *table_data,
 }
 
 build_package(package, op);
-build_append_array(sb_scope, package);
+build_append_array(sb_scope->buf, package);
 build_free_array(package);
 }
 
@@ -919,7 +916,7 @@ build_ssdt(Aml *table_data,
 /* build memory devices */
 for (i = 0; i < nr_mem; i++) {
 char id[3];
-uint8_t *mem = acpi_data_push(sb_scope, ACPI_MEM_SIZEOF);
+uint8_t *mem = acpi_data_push(sb_scope->buf, ACPI_MEM_SIZEOF);
 
 snprintf(id, sizeof(id), "%02X", i);
 memcpy(mem, ACPI_MEM_AML, ACPI_MEM_SIZEOF);
@@ -930,7 +927,7 @@ build_ssdt(Aml *table_data,
 /* build Method(MEMORY_SLOT_NOTIFY_METHOD, 2) {
  * If (LEqual(Arg0, 0x00)) {Notify(MP00, Arg1)} ...
  */
-build_append_notify_method(sb_scope,
+build_append_notify_method(sb_scope->buf,
stringify(MEMORY_SLOT_NOTIFY_METHOD),
"MP%0.02X", nr_mem);
 }
@@ -947,13 +944,11 @@ build_ssdt(Aml *table_data,
 
 if (bus) {
 /* Scan all PCI buses. Generate tables to support hotplug. */
-build_append_pci_bus_devices(sb_scope, bus,
+build_append_pci_bus_devices(sb_scope->buf, bus,
  pm->pcihp_bridge_en);
 }
 }
-build_package(sb_scope, op);
-build_append_array(ssdt->buf, sb_scope);
-build_free_array(sb_scope);
+aml_append(ssdt, sb_scope);
 }
 
 aml_append(table_data, ssdt);
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 10/52] acpi: add aml_method() term

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 9 +
 include/hw/acpi/aml-build.h | 1 +
 2 files changed, 10 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index e38a222..7389009 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -383,6 +383,15 @@ Aml *aml_def_block(const char *signature, uint8_t revision,
 return var;
 }
 
+/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefMethod */
+Aml *aml_method(const char *name, int arg_count)
+{
+Aml *var = aml_bundle(0x14 /* MethodOp */, AML_PACKAGE);
+build_append_namestring(var->buf, "%s", name);
+build_append_byte(var->buf, arg_count); /* MethodFlags: ArgCount */
+return var;
+}
+
 /* ACPI 1.0b: 16.2.5.1 Namespace Modifier Objects Encoding: DefScope */
 Aml *aml_scope(const char *name_format, ...)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index dfc725e..c1720e7 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -76,6 +76,7 @@ Aml *aml_def_block(const char *signature, uint8_t revision,
uint32_t creator_revision);
 Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
+Aml *aml_method(const char *name, int arg_count);
 
 /* other helpers */
 GArray *build_alloc_array(void);
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 16/52] acpi: add aml_arg() term

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 11 +++
 include/hw/acpi/aml-build.h |  1 +
 2 files changed, 12 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 2a29c8f..12f0653 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -437,6 +437,17 @@ Aml *aml_name_decl(const char *name, Aml *val)
 return var;
 }
 
+/* ACPI 1.0b: 16.2.6.1 Arg Objects Encoding */
+Aml *aml_arg(int pos)
+{
+Aml *var;
+uint8_t op = 0x68 /* ARG0 op */ + pos;
+
+assert(pos <= 6);
+var = aml_opcode(op);
+return var;
+}
+
 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 Aml *aml_if(Aml *predicate)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 8d35751..80cab77 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -74,6 +74,7 @@ Aml *aml_name(const char *name_format, ...) GCC_FMT_ATTR(1, 
2);
 Aml *aml_name_decl(const char *name, Aml *val);
 Aml *aml_return(Aml *val);
 Aml *aml_int(const uint64_t val);
+Aml *aml_arg(int pos);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 12/52] acpi: add aml_name() & aml_name_decl() term

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 32 
 include/hw/acpi/aml-build.h |  4 
 2 files changed, 36 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 9f43fef..5d6553c 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -259,6 +259,15 @@ static Aml *aml_alloc(void)
 return var;
 }
 
+static Aml *aml_opcode(uint8_t op)
+{
+Aml *var = aml_alloc();
+
+var->op  = op;
+var->block_flags = AML_NON_BLOCK;
+return var;
+}
+
 static Aml *aml_bundle(uint8_t op, AmlBlockFlags flags)
 {
 Aml *var = aml_alloc();
@@ -383,6 +392,29 @@ Aml *aml_def_block(const char *signature, uint8_t revision,
 return var;
 }
 
+/*
+ * helper to construct NameString, which returns Aml object
+ * for using with aml_append or other aml_* terms
+ */
+Aml *aml_name(const char *name_format, ...)
+{
+va_list ap;
+Aml *var = aml_alloc();
+va_start(ap, name_format);
+build_append_namestringv(var->buf, name_format, ap);
+va_end(ap);
+return var;
+}
+
+/* ACPI 1.0b: 16.2.5.1 Namespace Modifier Objects Encoding: DefName */
+Aml *aml_name_decl(const char *name, Aml *val)
+{
+Aml *var = aml_opcode(0x08 /* NameOp */);
+build_append_namestring(var->buf, "%s", name);
+aml_append(var, val);
+return var;
+}
+
 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 Aml *aml_if(Aml *predicate)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 7cd1f51..d5d8c11 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -69,6 +69,10 @@ void free_aml_allocator(void);
  */
 void aml_append(Aml *parent_ctx, Aml *child);
 
+/* non block AML object primitives */
+Aml *aml_name(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
+Aml *aml_name_decl(const char *name, Aml *val);
+
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
const char *oem_id, const char *oem_table_id,
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 15/52] acpi: add aml_return() term

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 8 
 include/hw/acpi/aml-build.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index de775e2..2a29c8f 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -395,6 +395,14 @@ Aml *aml_def_block(const char *signature, uint8_t revision,
 return var;
 }
 
+/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefReturn */
+Aml *aml_return(Aml *val)
+{
+Aml *var = aml_opcode(0xA4 /* ReturnOp */);
+aml_append(var, val);
+return var;
+}
+
 /*
  * ACPI 1.0b: 16.2.3 Data Objects Encoding:
  * encodes: ByteConst, WordConst, DWordConst, QWordConst, ZeroOp, OneOp
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 31225c6..8d35751 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -72,6 +72,7 @@ void aml_append(Aml *parent_ctx, Aml *child);
 /* non block AML object primitives */
 Aml *aml_name(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_name_decl(const char *name, Aml *val);
+Aml *aml_return(Aml *val);
 Aml *aml_int(const uint64_t val);
 
 /* Block AML object primitives */
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 05/52] acpi: add aml_def_block() term

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 38 ++
 hw/i386/acpi-build.c|  4 
 include/hw/acpi/aml-build.h | 10 ++
 3 files changed, 48 insertions(+), 4 deletions(-)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 67d1371..cb1a1bd 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -335,3 +335,41 @@ void aml_append(Aml *parent_ctx, Aml *child)
 }
 build_append_array(parent_ctx->buf, child->buf);
 }
+
+/*
+ * ACPI 1.0b: 16.2.1 Top Level AML
+ *5.2.3 System Description Table Header
+ *
+ * ACPI 5.0: 20.2.1 Table and Table Header Encoding
+ */
+Aml *aml_def_block(const char *signature, uint8_t revision,
+   const char *oem_id, const char *oem_table_id,
+   uint32_t oem_revision, uint32_t creator_id,
+   uint32_t creator_revision)
+{
+int len;
+Aml *var = aml_alloc();
+var->block_flags = AML_DEF_BLOCK;
+
+assert(strlen(signature) == 4);
+g_array_append_vals(var->buf, signature, 4);
+build_append_value(var->buf, 0, 4); /* Length place holder */
+build_append_byte(var->buf, revision);
+build_append_byte(var->buf, 0); /* place holder for Checksum */
+
+len = strlen(oem_id);
+assert(len <= 6);
+g_array_append_vals(var->buf, oem_id, len);
+g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 6 - len);
+
+len = strlen(oem_table_id);
+assert(len <= 8);
+g_array_append_vals(var->buf, oem_table_id, len);
+g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 8 - len);
+
+build_append_value(var->buf, oem_revision, 4);
+build_append_value(var->buf, creator_id, 4);
+build_append_value(var->buf, creator_revision, 4);
+
+return var;
+}
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index a1bf450..553c86b 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -254,10 +254,6 @@ static void acpi_get_pci_info(PcPciInfo *info)
 NULL);
 }
 
-#define ACPI_BUILD_APPNAME  "Bochs"
-#define ACPI_BUILD_APPNAME6 "BOCHS "
-#define ACPI_BUILD_APPNAME4 "BXPC"
-
 #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
 #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
 
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 4033796..2610336 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -6,6 +6,10 @@
 #include "qemu/compiler.h"
 
 #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
+#define ACPI_BUILD_APPNAME  "Bochs"
+#define ACPI_BUILD_APPNAME6 "BOCHS "
+#define ACPI_BUILD_APPNAME4 "BXPC"
+#define ACPI_BUILD_APPNAME4_HEX 0x43505842
 
 typedef enum {
 AML_HELPER = 0,
@@ -65,6 +69,12 @@ void free_aml_allocator(void);
  */
 void aml_append(Aml *parent_ctx, Aml *child);
 
+/* Block AML object primitives */
+Aml *aml_def_block(const char *signature, uint8_t revision,
+   const char *oem_id, const char *oem_table_id,
+   uint32_t oem_revision, uint32_t creator_id,
+   uint32_t creator_revision);
+
 /* other helpers */
 GArray *build_alloc_array(void);
 void build_free_array(GArray *array);
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 13/52] acpi: extend build_append_{value|int}() to support 64-bit values

2015-02-09 Thread Igor Mammedov
it will be used for generating 64bit _CRS entries

Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 9 ++---
 include/hw/acpi/aml-build.h | 4 ++--
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 5d6553c..d71b236 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -219,7 +219,7 @@ void build_extop_package(GArray *package, uint8_t op)
 build_prepend_byte(package, 0x5B); /* ExtOpPrefix */
 }
 
-void build_append_value(GArray *table, uint32_t value, int size)
+void build_append_value(GArray *table, uint64_t value, int size)
 {
 int i;
 
@@ -229,7 +229,7 @@ void build_append_value(GArray *table, uint32_t value, int 
size)
 }
 }
 
-void build_append_int(GArray *table, uint32_t value)
+void build_append_int(GArray *table, uint64_t value)
 {
 if (value == 0x00) {
 build_append_byte(table, 0x00); /* ZeroOp */
@@ -241,9 +241,12 @@ void build_append_int(GArray *table, uint32_t value)
 } else if (value <= 0x) {
 build_append_byte(table, 0x0B); /* WordPrefix */
 build_append_value(table, value, 2);
-} else {
+} else if (value <= 0x) {
 build_append_byte(table, 0x0C); /* DWordPrefix */
 build_append_value(table, value, 4);
+} else {
+build_append_byte(table, 0x0E); /* QWordPrefix */
+build_append_value(table, value, 8);
 }
 }
 
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index d5d8c11..5abc56b 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -95,8 +95,8 @@ build_append_namestring(GArray *array, const char *format, 
...);
 
 void build_prepend_package_length(GArray *package);
 void build_package(GArray *package, uint8_t op);
-void build_append_value(GArray *table, uint32_t value, int size);
-void build_append_int(GArray *table, uint32_t value);
+void build_append_value(GArray *table, uint64_t value, int size);
+void build_append_int(GArray *table, uint64_t value);
 void build_extop_package(GArray *package, uint8_t op);
 
 #endif
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 20/52] acpi: add aml_call1(), aml_call2(), aml_call3(), aml_call4() helpers

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 42 ++
 include/hw/acpi/aml-build.h |  4 
 2 files changed, 46 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index c5feb61..0328a57 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -476,6 +476,48 @@ Aml *aml_notify(Aml *arg1, Aml *arg2)
 return var;
 }
 
+/* helper to call method with 1 argument */
+Aml *aml_call1(const char *method, Aml *arg1)
+{
+Aml *var = aml_alloc();
+build_append_namestring(var->buf, "%s", method);
+aml_append(var, arg1);
+return var;
+}
+
+/* helper to call method with 2 arguments */
+Aml *aml_call2(const char *method, Aml *arg1, Aml *arg2)
+{
+Aml *var = aml_alloc();
+build_append_namestring(var->buf, "%s", method);
+aml_append(var, arg1);
+aml_append(var, arg2);
+return var;
+}
+
+/* helper to call method with 3 arguments */
+Aml *aml_call3(const char *method, Aml *arg1, Aml *arg2, Aml *arg3)
+{
+Aml *var = aml_alloc();
+build_append_namestring(var->buf, "%s", method);
+aml_append(var, arg1);
+aml_append(var, arg2);
+aml_append(var, arg3);
+return var;
+}
+
+/* helper to call method with 4 arguments */
+Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4)
+{
+Aml *var = aml_alloc();
+build_append_namestring(var->buf, "%s", method);
+aml_append(var, arg1);
+aml_append(var, arg2);
+aml_append(var, arg3);
+aml_append(var, arg4);
+return var;
+}
+
 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 Aml *aml_if(Aml *predicate)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 564517b..cd06669 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -78,6 +78,10 @@ Aml *aml_arg(int pos);
 Aml *aml_store(Aml *val, Aml *target);
 Aml *aml_and(Aml *arg1, Aml *arg2);
 Aml *aml_notify(Aml *arg1, Aml *arg2);
+Aml *aml_call1(const char *method, Aml *arg1);
+Aml *aml_call2(const char *method, Aml *arg1, Aml *arg2);
+Aml *aml_call3(const char *method, Aml *arg1, Aml *arg2, Aml *arg3);
+Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 19/52] acpi: add aml_notify() term

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 9 +
 include/hw/acpi/aml-build.h | 1 +
 2 files changed, 10 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 61149dc..c5feb61 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -467,6 +467,15 @@ Aml *aml_and(Aml *arg1, Aml *arg2)
 return var;
 }
 
+/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefNotify */
+Aml *aml_notify(Aml *arg1, Aml *arg2)
+{
+Aml *var = aml_opcode(0x86 /* NotifyOp */);
+aml_append(var, arg1);
+aml_append(var, arg2);
+return var;
+}
+
 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 Aml *aml_if(Aml *predicate)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 31db64a..564517b 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -77,6 +77,7 @@ Aml *aml_int(const uint64_t val);
 Aml *aml_arg(int pos);
 Aml *aml_store(Aml *val, Aml *target);
 Aml *aml_and(Aml *arg1, Aml *arg2);
+Aml *aml_notify(Aml *arg1, Aml *arg2);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 22/52] acpi: add aml_package() term

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 8 
 include/hw/acpi/aml-build.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 0328a57..31e999d 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -556,3 +556,11 @@ Aml *aml_device(const char *name_format, ...)
 va_end(ap);
 return var;
 }
+
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefPackage */
+Aml *aml_package(uint8_t num_elements)
+{
+Aml *var = aml_bundle(0x12 /* PackageOp */, AML_PACKAGE);
+build_append_byte(var->buf, num_elements);
+return var;
+}
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index cd06669..511abf6 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -92,6 +92,7 @@ Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 
2);
 Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_method(const char *name, int arg_count);
 Aml *aml_if(Aml *predicate);
+Aml *aml_package(uint8_t num_elements);
 
 /* other helpers */
 GArray *build_alloc_array(void);
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 14/52] acpi: add aml_int() term

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 11 +++
 include/hw/acpi/aml-build.h |  1 +
 2 files changed, 12 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index d71b236..de775e2 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -396,6 +396,17 @@ Aml *aml_def_block(const char *signature, uint8_t revision,
 }
 
 /*
+ * ACPI 1.0b: 16.2.3 Data Objects Encoding:
+ * encodes: ByteConst, WordConst, DWordConst, QWordConst, ZeroOp, OneOp
+ */
+Aml *aml_int(const uint64_t val)
+{
+Aml *var = aml_alloc();
+build_append_int(var->buf, val);
+return var;
+}
+
+/*
  * helper to construct NameString, which returns Aml object
  * for using with aml_append or other aml_* terms
  */
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 5abc56b..31225c6 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -72,6 +72,7 @@ void aml_append(Aml *parent_ctx, Aml *child);
 /* non block AML object primitives */
 Aml *aml_name(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_name_decl(const char *name, Aml *val);
+Aml *aml_int(const uint64_t val);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 18/52] acpi: add aml_and() term

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 10 ++
 include/hw/acpi/aml-build.h |  1 +
 2 files changed, 11 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index ae84b25..61149dc 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -457,6 +457,16 @@ Aml *aml_store(Aml *val, Aml *target)
 return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefAnd */
+Aml *aml_and(Aml *arg1, Aml *arg2)
+{
+Aml *var = aml_opcode(0x7B /* AndOp */);
+aml_append(var, arg1);
+aml_append(var, arg2);
+build_append_int(var->buf, 0x00 /* NullNameOp */);
+return var;
+}
+
 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 Aml *aml_if(Aml *predicate)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 93fb662..31db64a 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -76,6 +76,7 @@ Aml *aml_return(Aml *val);
 Aml *aml_int(const uint64_t val);
 Aml *aml_arg(int pos);
 Aml *aml_store(Aml *val, Aml *target);
+Aml *aml_and(Aml *arg1, Aml *arg2);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 28/52] acpi: include PkgLength size only when requested

2015-02-09 Thread Igor Mammedov
Named/Reserved{Field} definition uses PkgLength [1] encoding to specify
field length, however it doesn't include size of PkgLength field itself,
while other block objects that have explicit length of its body account
for PkgLength size while encoding it [2].
This special casing isn't mentioned in ACPI spec, but that's what 'iasl'
compiles NamedField to so add extra argument to build_prepend_pkg_length()
to allow it handle the case.

--
1. ACPI Spec 5.0, 20.2.5.2 Named Objects Encoding, page 822
2. ACPI Spec 5.0, 5.4 Definition Block Encoding

Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 20 +++-
 include/hw/acpi/aml-build.h |  3 ++-
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index a5d5b83..8c6b6a3 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -159,10 +159,10 @@ enum {
 PACKAGE_LENGTH_4BYTE_SHIFT = 20,
 };
 
-void build_prepend_package_length(GArray *package)
+void
+build_prepend_package_length(GArray *package, unsigned length, bool incl_self)
 {
 uint8_t byte;
-unsigned length = package->len;
 unsigned length_bytes;
 
 if (length + 1 < (1 << PACKAGE_LENGTH_1BYTE_SHIFT)) {
@@ -175,8 +175,18 @@ void build_prepend_package_length(GArray *package)
 length_bytes = 4;
 }
 
-/* PkgLength is the length of the inclusive length of the data. */
-length += length_bytes;
+/*
+ * NamedField uses PkgLength encoding but it doesn't include length
+ * of PkgLength itself.
+ */
+if (incl_self) {
+/*
+ * PkgLength is the length of the inclusive length of the data
+ * and PkgLength's length itself when used for terms with
+ * explitit length.
+ */
+length += length_bytes;
+}
 
 switch (length_bytes) {
 case 1:
@@ -209,7 +219,7 @@ void build_prepend_package_length(GArray *package)
 
 void build_package(GArray *package, uint8_t op)
 {
-build_prepend_package_length(package);
+build_prepend_package_length(package, package->len, true);
 build_prepend_byte(package, op);
 }
 
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 3dab2b5..1c95845 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -113,7 +113,8 @@ void build_append_array(GArray *array, GArray *val);
 void GCC_FMT_ATTR(2, 3)
 build_append_namestring(GArray *array, const char *format, ...);
 
-void build_prepend_package_length(GArray *package);
+void
+build_prepend_package_length(GArray *package, unsigned length, bool incl_self);
 void build_package(GArray *package, uint8_t op);
 void build_append_value(GArray *table, uint64_t value, int size);
 void build_append_int(GArray *table, uint64_t value);
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 17/52] acpi: add aml_store() term

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 9 +
 include/hw/acpi/aml-build.h | 1 +
 2 files changed, 10 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 12f0653..ae84b25 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -448,6 +448,15 @@ Aml *aml_arg(int pos)
 return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefStore */
+Aml *aml_store(Aml *val, Aml *target)
+{
+Aml *var = aml_opcode(0x70 /* StoreOp */);
+aml_append(var, val);
+aml_append(var, target);
+return var;
+}
+
 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 Aml *aml_if(Aml *predicate)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 80cab77..93fb662 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -75,6 +75,7 @@ Aml *aml_name_decl(const char *name, Aml *val);
 Aml *aml_return(Aml *val);
 Aml *aml_int(const uint64_t val);
 Aml *aml_arg(int pos);
+Aml *aml_store(Aml *val, Aml *target);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 24/52] pc: acpi-build: generate _S[345] packages dynamically

2015-02-09 Thread Igor Mammedov
Replaces template patching with packages composed
using AML API.

Note on behavior change:
If S3 or S4 is disabled, respective packages won't
be created and put into SSDT. Which saves us some
space in SSDT and doesn't confuse guest OS with
mangled package names as it was done originally.

Signed-off-by: Igor Mammedov 
---
 hw/i386/acpi-build.c  | 38 +-
 hw/i386/ssdt-misc.dsl | 33 -
 2 files changed, 29 insertions(+), 42 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 7cc564a..1e912d1 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -756,7 +756,7 @@ build_ssdt(Aml *table_data,
 uint32_t nr_mem = machine->ram_slots;
 unsigned acpi_cpus = guest_info->apic_id_limit;
 uint8_t *ssdt_ptr;
-Aml *ssdt, *sb_scope;
+Aml *ssdt, *sb_scope, *scope, *pkg;
 int i;
 
 /* The current AML generator can cover the APIC ID range [0..255],
@@ -775,14 +775,6 @@ build_ssdt(Aml *table_data,
 memcpy(ssdt_ptr + sizeof(AcpiTableHeader),
ssdp_misc_aml + sizeof(AcpiTableHeader),
sizeof(ssdp_misc_aml) - sizeof(AcpiTableHeader));
-if (pm->s3_disabled) {
-ssdt_ptr[acpi_s3_name[0]] = 'X';
-}
-if (pm->s4_disabled) {
-ssdt_ptr[acpi_s4_name[0]] = 'X';
-} else {
-ssdt_ptr[acpi_s4_pkg[0] + 1] = pm->s4_val;
-}
 
 patch_pci_windows(pci, ssdt_ptr, sizeof(ssdp_misc_aml));
 
@@ -792,6 +784,34 @@ build_ssdt(Aml *table_data,
 ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
   ssdt_mctrl_nr_slots[0], 32, nr_mem);
 
+/*  create S3_ / S4_ / S5_ packages if necessary */
+scope = aml_scope("\\");
+if (!pm->s3_disabled) {
+pkg = aml_package(4);
+aml_append(pkg, aml_int(1)); /* PM1a_CNT.SLP_TYP */
+aml_append(pkg, aml_int(0)); /* PM1b_CNT.SLP_TYP not impl. */
+aml_append(pkg, aml_int(0)); /* reserved */
+aml_append(pkg, aml_int(0)); /* reserved */
+aml_append(scope, aml_name_decl("_S3", pkg));
+}
+
+if (!pm->s4_disabled) {
+pkg = aml_package(4);
+aml_append(pkg, aml_int(pm->s4_val)); /* PM1a_CNT.SLP_TYP */
+aml_append(pkg, aml_int(0)); /* PM1b_CNT.SLP_TYP not impl. */
+aml_append(pkg, aml_int(0)); /* reserved */
+aml_append(pkg, aml_int(0)); /* reserved */
+aml_append(scope, aml_name_decl("_S4", pkg));
+}
+
+pkg = aml_package(4);
+aml_append(pkg, aml_int(0)); /* PM1a_CNT.SLP_TYP */
+aml_append(pkg, aml_int(0)); /* PM1b_CNT.SLP_TYP not impl. */
+aml_append(pkg, aml_int(0)); /* reserved */
+aml_append(pkg, aml_int(0)); /* reserved */
+aml_append(scope, aml_name_decl("_S5", pkg));
+aml_append(ssdt, scope);
+
 sb_scope = aml_scope("_SB");
 {
 /* build Processor object for each processor */
diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
index 96382a6..26b9241 100644
--- a/hw/i386/ssdt-misc.dsl
+++ b/hw/i386/ssdt-misc.dsl
@@ -41,39 +41,6 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", 
"BXSSDTSUSP", 0x1)
 }
 
 
-/
- * Suspend
- /
-
-Scope(\) {
-/*
- * S3 (suspend-to-ram), S4 (suspend-to-disk) and S5 (power-off) type codes:
- * must match piix4 emulation.
- */
-
-ACPI_EXTRACT_NAME_STRING acpi_s3_name
-Name(_S3, Package(0x04) {
-One,  /* PM1a_CNT.SLP_TYP */
-Zero,  /* PM1b_CNT.SLP_TYP, QEMU doesn't provide it */
-Zero,  /* reserved */
-Zero   /* reserved */
-})
-ACPI_EXTRACT_NAME_STRING acpi_s4_name
-ACPI_EXTRACT_PKG_START acpi_s4_pkg
-Name(_S4, Package(0x04) {
-0x2,  /* PM1a_CNT.SLP_TYP */
-Zero,  /* PM1b_CNT.SLP_TYP, QEMU doesn't provide it */
-Zero,  /* reserved */
-Zero   /* reserved */
-})
-Name(_S5, Package(0x04) {
-Zero,  /* PM1a_CNT.SLP_TYP */
-Zero,  /* PM1b_CNT.SLP_TYP */
-Zero,  /* reserved */
-Zero   /* reserved */
-})
-}
-
 External(\_SB.PCI0, DeviceObj)
 External(\_SB.PCI0.ISA, DeviceObj)
 
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 23/52] pc: acpi-build: drop unsupported PM1b_CNT.SLP_TYP

2015-02-09 Thread Igor Mammedov
QEMU doesn't implement/advertize PM1b_CNT_BLK
register block so do not set/patch its \_Sx
values to avoid confusion.

Signed-off-by: Igor Mammedov 
---
 hw/i386/acpi-build.c  | 3 +--
 hw/i386/ssdt-misc.dsl | 4 ++--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index b6626f5..7cc564a 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -781,8 +781,7 @@ build_ssdt(Aml *table_data,
 if (pm->s4_disabled) {
 ssdt_ptr[acpi_s4_name[0]] = 'X';
 } else {
-ssdt_ptr[acpi_s4_pkg[0] + 1] = ssdt_ptr[acpi_s4_pkg[0] + 3] =
-pm->s4_val;
+ssdt_ptr[acpi_s4_pkg[0] + 1] = pm->s4_val;
 }
 
 patch_pci_windows(pci, ssdt_ptr, sizeof(ssdp_misc_aml));
diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
index 1e3baae..96382a6 100644
--- a/hw/i386/ssdt-misc.dsl
+++ b/hw/i386/ssdt-misc.dsl
@@ -54,7 +54,7 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", 
"BXSSDTSUSP", 0x1)
 ACPI_EXTRACT_NAME_STRING acpi_s3_name
 Name(_S3, Package(0x04) {
 One,  /* PM1a_CNT.SLP_TYP */
-One,  /* PM1b_CNT.SLP_TYP */
+Zero,  /* PM1b_CNT.SLP_TYP, QEMU doesn't provide it */
 Zero,  /* reserved */
 Zero   /* reserved */
 })
@@ -62,7 +62,7 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", 
"BXSSDTSUSP", 0x1)
 ACPI_EXTRACT_PKG_START acpi_s4_pkg
 Name(_S4, Package(0x04) {
 0x2,  /* PM1a_CNT.SLP_TYP */
-0x2,  /* PM1b_CNT.SLP_TYP */
+Zero,  /* PM1b_CNT.SLP_TYP, QEMU doesn't provide it */
 Zero,  /* reserved */
 Zero   /* reserved */
 })
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 27/52] acpi: add aml_io() helper

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 16 
 include/hw/acpi/aml-build.h |  7 +++
 2 files changed, 23 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 452db25..a5d5b83 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -518,6 +518,22 @@ Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, 
Aml *arg3, Aml *arg4)
 return var;
 }
 
+/* ACPI 1.0b: 6.4.2.5 I/O Port Descriptor */
+Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
+uint8_t aln, uint8_t len)
+{
+Aml *var = aml_alloc();
+build_append_byte(var->buf, 0x47); /* IO port descriptor */
+build_append_byte(var->buf, dec);
+build_append_byte(var->buf, min_base & 0xff);
+build_append_byte(var->buf, (min_base >> 8) & 0xff);
+build_append_byte(var->buf, max_base & 0xff);
+build_append_byte(var->buf, (max_base >> 8) & 0xff);
+build_append_byte(var->buf, aln);
+build_append_byte(var->buf, len);
+return var;
+}
+
 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 Aml *aml_if(Aml *predicate)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 6a8aaef..3dab2b5 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -31,6 +31,11 @@ struct Aml {
 };
 typedef struct Aml Aml;
 
+typedef enum {
+aml_decode10 = 0,
+aml_decode16 = 1,
+} AmlIODecode;
+
 /**
  * init_aml_allocator:
  * @linker: linker that used by API for registering ACPI tables
@@ -82,6 +87,8 @@ Aml *aml_call1(const char *method, Aml *arg1);
 Aml *aml_call2(const char *method, Aml *arg1, Aml *arg2);
 Aml *aml_call3(const char *method, Aml *arg1, Aml *arg2, Aml *arg3);
 Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4);
+Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
+uint8_t aln, uint8_t len);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 31/52] acpi: add aml_local() term

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 11 +++
 include/hw/acpi/aml-build.h |  1 +
 2 files changed, 12 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 10995a9..cb58e19 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -647,3 +647,14 @@ Aml *aml_field(const char *name, AmlFieldFlags flags)
 build_append_byte(var->buf, flags);
 return var;
 }
+
+/* ACPI 1.0b: 16.2.6.2 Local Objects Encoding */
+Aml *aml_local(int num)
+{
+Aml *var;
+uint8_t op = 0x60 /* Local0Op */ + num;
+
+assert(op <= 7);
+var = aml_opcode(op);
+return var;
+}
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 8b954d9..6e25315 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -101,6 +101,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t 
max_base,
 Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
   uint32_t offset, uint32_t len);
 Aml *aml_named_field(const char *name, unsigned length);
+Aml *aml_local(int num);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 21/52] pc: acpi-build: drop template patching and create PCI bus tree dynamically

2015-02-09 Thread Igor Mammedov
Replace AML template patching with direct composing
of PCI device entries in C. It allows to simplify
PCI tree generation further and saves us about 400LOC
scattered through different files, confining tree
generation to one C function which is much easier
to deal with.

Signed-off-by: Igor Mammedov 
---
 hw/i386/Makefile.objs|   6 +-
 hw/i386/acpi-build.c | 207 +++-
 hw/i386/ssdt-pcihp.dsl   | 100 
 hw/i386/ssdt-pcihp.hex.generated | 251 ---
 4 files changed, 72 insertions(+), 492 deletions(-)
 delete mode 100644 hw/i386/ssdt-pcihp.dsl
 delete mode 100644 hw/i386/ssdt-pcihp.hex.generated

diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index 2b678ef..4509cd1 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -8,10 +8,8 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/
 obj-y += kvmvapic.o
 obj-y += acpi-build.o
 hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
-   hw/i386/ssdt-proc.hex hw/i386/ssdt-pcihp.hex hw/i386/ssdt-misc.hex \
-   hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \
-   hw/i386/q35-acpi-dsdt.hex hw/i386/ssdt-mem.hex \
-   hw/i386/ssdt-tpm.hex
+   hw/i386/ssdt-proc.hex hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
+   hw/i386/ssdt-mem.hex hw/i386/ssdt-tpm.hex
 
 iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
 ; then echo "$(2)"; else echo "$(3)"; fi ;)
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index bdc343f..b6626f5 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -525,29 +525,6 @@ static inline char acpi_get_hex(uint32_t val)
 #define ACPI_PROC_SIZEOF (*ssdt_proc_end - *ssdt_proc_start)
 #define ACPI_PROC_AML (ssdp_proc_aml + *ssdt_proc_start)
 
-/* 0x5B 0x82 DeviceOp PkgLength NameString */
-#define ACPI_PCIHP_OFFSET_HEX (*ssdt_pcihp_name - *ssdt_pcihp_start + 1)
-#define ACPI_PCIHP_OFFSET_ID (*ssdt_pcihp_id - *ssdt_pcihp_start)
-#define ACPI_PCIHP_OFFSET_ADR (*ssdt_pcihp_adr - *ssdt_pcihp_start)
-#define ACPI_PCIHP_OFFSET_EJ0 (*ssdt_pcihp_ej0 - *ssdt_pcihp_start)
-#define ACPI_PCIHP_SIZEOF (*ssdt_pcihp_end - *ssdt_pcihp_start)
-#define ACPI_PCIHP_AML (ssdp_pcihp_aml + *ssdt_pcihp_start)
-
-#define ACPI_PCINOHP_OFFSET_HEX (*ssdt_pcinohp_name - *ssdt_pcinohp_start + 1)
-#define ACPI_PCINOHP_OFFSET_ADR (*ssdt_pcinohp_adr - *ssdt_pcinohp_start)
-#define ACPI_PCINOHP_SIZEOF (*ssdt_pcinohp_end - *ssdt_pcinohp_start)
-#define ACPI_PCINOHP_AML (ssdp_pcihp_aml + *ssdt_pcinohp_start)
-
-#define ACPI_PCIVGA_OFFSET_HEX (*ssdt_pcivga_name - *ssdt_pcivga_start + 1)
-#define ACPI_PCIVGA_OFFSET_ADR (*ssdt_pcivga_adr - *ssdt_pcivga_start)
-#define ACPI_PCIVGA_SIZEOF (*ssdt_pcivga_end - *ssdt_pcivga_start)
-#define ACPI_PCIVGA_AML (ssdp_pcihp_aml + *ssdt_pcivga_start)
-
-#define ACPI_PCIQXL_OFFSET_HEX (*ssdt_pciqxl_name - *ssdt_pciqxl_start + 1)
-#define ACPI_PCIQXL_OFFSET_ADR (*ssdt_pciqxl_adr - *ssdt_pciqxl_start)
-#define ACPI_PCIQXL_SIZEOF (*ssdt_pciqxl_end - *ssdt_pciqxl_start)
-#define ACPI_PCIQXL_AML (ssdp_pcihp_aml + *ssdt_pciqxl_start)
-
 #include "hw/i386/ssdt-mem.hex"
 
 /* 0x5B 0x82 DeviceOp PkgLength NameString DimmID */
@@ -560,7 +537,6 @@ static inline char acpi_get_hex(uint32_t val)
 #define ACPI_SSDT_HEADER_LENGTH 36
 
 #include "hw/i386/ssdt-misc.hex"
-#include "hw/i386/ssdt-pcihp.hex"
 #include "hw/i386/ssdt-tpm.hex"
 
 static void
@@ -581,43 +557,6 @@ build_append_notify_method(GArray *device, const char 
*name,
 build_append_and_cleanup_method(device, method);
 }
 
-static void patch_pcihp(int slot, uint8_t *ssdt_ptr)
-{
-unsigned devfn = PCI_DEVFN(slot, 0);
-
-ssdt_ptr[ACPI_PCIHP_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
-ssdt_ptr[ACPI_PCIHP_OFFSET_HEX + 1] = acpi_get_hex(devfn);
-ssdt_ptr[ACPI_PCIHP_OFFSET_ID] = slot;
-ssdt_ptr[ACPI_PCIHP_OFFSET_ADR + 2] = slot;
-}
-
-static void patch_pcinohp(int slot, uint8_t *ssdt_ptr)
-{
-unsigned devfn = PCI_DEVFN(slot, 0);
-
-ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
-ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX + 1] = acpi_get_hex(devfn);
-ssdt_ptr[ACPI_PCINOHP_OFFSET_ADR + 2] = slot;
-}
-
-static void patch_pcivga(int slot, uint8_t *ssdt_ptr)
-{
-unsigned devfn = PCI_DEVFN(slot, 0);
-
-ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
-ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX + 1] = acpi_get_hex(devfn);
-ssdt_ptr[ACPI_PCIVGA_OFFSET_ADR + 2] = slot;
-}
-
-static void patch_pciqxl(int slot, uint8_t *ssdt_ptr)
-{
-unsigned devfn = PCI_DEVFN(slot, 0);
-
-ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
-ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX + 1] = acpi_get_hex(devfn);
-ssdt_ptr[ACPI_PCIQXL_OFFSET_ADR + 2] = slot;
-}
-
 /* Assign BSEL property to all buses.  In the future, this can be changed
  * to only assign to buses that support hotplug.
  */
@@ -648,46 +587,30 @@ static void acpi_set_pci_info(void)
 }
 }
 
-static void build_append

[Qemu-devel] [PATCH v3 36/52] acpi: add aml_processor() term

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
v2:
   * use build_append_value() to pack PblkAddr
 instead of doing it manually
---
 hw/acpi/aml-build.c | 15 +++
 include/hw/acpi/aml-build.h |  2 ++
 2 files changed, 17 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 670d3e9..aa5ef59 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -701,3 +701,18 @@ Aml *aml_varpackage(uint32_t num_elements)
 build_append_int(var->buf, num_elements);
 return var;
 }
+
+/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefProcessor */
+Aml *aml_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,
+   const char *name_format, ...)
+{
+va_list ap;
+Aml *var = aml_bundle(0x83 /* ProcessorOp */, AML_EXT_PACKAGE);
+va_start(ap, name_format);
+build_append_namestringv(var->buf, name_format, ap);
+va_end(ap);
+build_append_byte(var->buf, proc_id); /* ProcID */
+build_append_value(var->buf, pblk_addr, sizeof(pblk_addr)); /* PblkAddr */
+build_append_byte(var->buf, pblk_len); /* PblkLen */
+return var;
+}
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index e918055..3cf9fbb 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -104,6 +104,8 @@ Aml *aml_named_field(const char *name, unsigned length);
 Aml *aml_local(int num);
 Aml *aml_string(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_equal(Aml *arg1, Aml *arg2);
+Aml *aml_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,
+   const char *name_format, ...) GCC_FMT_ATTR(4, 5);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 29/52] acpi: add aml_operation_region() term

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 14 ++
 include/hw/acpi/aml-build.h |  7 +++
 2 files changed, 21 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 8c6b6a3..05d4a3d 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -605,3 +605,17 @@ Aml *aml_package(uint8_t num_elements)
 build_append_byte(var->buf, num_elements);
 return var;
 }
+
+/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefOpRegion */
+Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
+  uint32_t offset, uint32_t len)
+{
+Aml *var = aml_alloc();
+build_append_byte(var->buf, 0x5B); /* ExtOpPrefix */
+build_append_byte(var->buf, 0x80); /* OpRegionOp */
+build_append_namestring(var->buf, "%s", name);
+build_append_byte(var->buf, rs);
+build_append_int(var->buf, offset);
+build_append_int(var->buf, len);
+return var;
+}
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 1c95845..6db9d42 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -36,6 +36,11 @@ typedef enum {
 aml_decode16 = 1,
 } AmlIODecode;
 
+typedef enum {
+aml_system_memory = 0x00,
+aml_system_io = 0x01,
+} AmlRegionSpace;
+
 /**
  * init_aml_allocator:
  * @linker: linker that used by API for registering ACPI tables
@@ -89,6 +94,8 @@ Aml *aml_call3(const char *method, Aml *arg1, Aml *arg2, Aml 
*arg3);
 Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4);
 Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
 uint8_t aln, uint8_t len);
+Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
+  uint32_t offset, uint32_t len);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 30/52] acpi: add aml_field() & aml_named_field() terms

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 28 
 include/hw/acpi/aml-build.h |  6 ++
 2 files changed, 34 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 05d4a3d..10995a9 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -217,6 +217,16 @@ build_prepend_package_length(GArray *package, unsigned 
length, bool incl_self)
 build_prepend_byte(package, byte);
 }
 
+static void
+build_append_pkg_length(GArray *array, unsigned length, bool incl_self)
+{
+GArray *tmp = build_alloc_array();
+
+build_prepend_package_length(tmp, length, incl_self);
+build_append_array(array, tmp);
+build_free_array(tmp);
+}
+
 void build_package(GArray *package, uint8_t op)
 {
 build_prepend_package_length(package, package->len, true);
@@ -619,3 +629,21 @@ Aml *aml_operation_region(const char *name, AmlRegionSpace 
rs,
 build_append_int(var->buf, len);
 return var;
 }
+
+/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: NamedField */
+Aml *aml_named_field(const char *name, unsigned length)
+{
+Aml *var = aml_alloc();
+build_append_nameseg(var->buf, name);
+build_append_pkg_length(var->buf, length, false);
+return var;
+}
+
+/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefField */
+Aml *aml_field(const char *name, AmlFieldFlags flags)
+{
+Aml *var = aml_bundle(0x81 /* FieldOp */, AML_EXT_PACKAGE);
+build_append_namestring(var->buf, "%s", name);
+build_append_byte(var->buf, flags);
+return var;
+}
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 6db9d42..8b954d9 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -37,6 +37,10 @@ typedef enum {
 } AmlIODecode;
 
 typedef enum {
+aml_byte_acc = 1,
+} AmlFieldFlags;
+
+typedef enum {
 aml_system_memory = 0x00,
 aml_system_io = 0x01,
 } AmlRegionSpace;
@@ -96,6 +100,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t 
max_base,
 uint8_t aln, uint8_t len);
 Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
   uint32_t offset, uint32_t len);
+Aml *aml_named_field(const char *name, unsigned length);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
@@ -109,6 +114,7 @@ Aml *aml_if(Aml *predicate);
 Aml *aml_package(uint8_t num_elements);
 Aml *aml_buffer(void);
 Aml *aml_resource_template(void);
+Aml *aml_field(const char *name, AmlFieldFlags flags);
 
 /* other helpers */
 GArray *build_alloc_array(void);
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 25/52] acpi: add aml_buffer() term

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 7 +++
 include/hw/acpi/aml-build.h | 1 +
 2 files changed, 8 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 31e999d..6488433 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -557,6 +557,13 @@ Aml *aml_device(const char *name_format, ...)
 return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefBuffer */
+Aml *aml_buffer(void)
+{
+Aml *var = aml_bundle(0x11 /* BufferOp */, AML_BUFFER);
+return var;
+}
+
 /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefPackage */
 Aml *aml_package(uint8_t num_elements)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 511abf6..06826df 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -93,6 +93,7 @@ Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 
2);
 Aml *aml_method(const char *name, int arg_count);
 Aml *aml_if(Aml *predicate);
 Aml *aml_package(uint8_t num_elements);
+Aml *aml_buffer(void);
 
 /* other helpers */
 GArray *build_alloc_array(void);
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 34/52] acpi: add aml_varpackage() term

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 8 
 include/hw/acpi/aml-build.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 3929de9..90b7b65 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -683,3 +683,11 @@ Aml *aml_local(int num)
 var = aml_opcode(op);
 return var;
 }
+
+/* ACPI 2.0a: 17.2.2 Data Objects Encoding: DefVarPackage */
+Aml *aml_varpackage(uint32_t num_elements)
+{
+Aml *var = aml_bundle(0x13 /* VarPackageOp */, AML_PACKAGE);
+build_append_int(var->buf, num_elements);
+return var;
+}
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index fee4eef..d5b9325 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -117,6 +117,7 @@ Aml *aml_package(uint8_t num_elements);
 Aml *aml_buffer(void);
 Aml *aml_resource_template(void);
 Aml *aml_field(const char *name, AmlFieldFlags flags);
+Aml *aml_varpackage(uint32_t num_elements);
 
 /* other helpers */
 GArray *build_alloc_array(void);
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 26/52] acpi: add aml_resource_template() helper

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 8 
 include/hw/acpi/aml-build.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 6488433..452db25 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -557,6 +557,14 @@ Aml *aml_device(const char *name_format, ...)
 return var;
 }
 
+/* ACPI 1.0b: 6.4.1 ASL Macros for Resource Descriptors */
+Aml *aml_resource_template(void)
+{
+/* ResourceTemplate is a buffer of Resources with EndTag at the end */
+Aml *var = aml_bundle(0x11 /* BufferOp */, AML_RES_TEMPLATE);
+return var;
+}
+
 /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefBuffer */
 Aml *aml_buffer(void)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 06826df..6a8aaef 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -94,6 +94,7 @@ Aml *aml_method(const char *name, int arg_count);
 Aml *aml_if(Aml *predicate);
 Aml *aml_package(uint8_t num_elements);
 Aml *aml_buffer(void);
+Aml *aml_resource_template(void);
 
 /* other helpers */
 GArray *build_alloc_array(void);
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 39/52] pc: acpi-build: create CPU hotplug IO region dynamically

2015-02-09 Thread Igor Mammedov
it replaces a static complied in DSDT MMIO region
for CPU hotplug with one created at runtime
leaving only truly static CPU hotplug related ASL
bits in DSDT.
It also puts CPU_HOTPLUG_RESOURCE_DEVICE into
PCI0 scope and reserves resources from it,
preparing for dropping manual hole punching
in PCI0._CRS.

Later it also would make easier to reuse current
ACPI CPU hotplug on other targets.

Also later it would be possible to move remaining
CPU hotplug ASL methods into build_ssdt() and
add all CPU hotplug related AML into SSDT only
when CPU hotplug is enabled, further reducing
ACPI tables blob if CPU hotplug isn't used.

impl. detail:
Windows XP can't handle /BSODs/ OperationRegion
declaration in DSDT when variable from SSDT is used
for specifying its address/length and also when
Field declared in DSDT with OperationRegion from
SSDT if DSDT is being parsed before SSDT.
But it works just fine when referencing named
fields from another table. Hence OperationRegion
and Field declaration are moved to SSDT to make
XP based editions work.

PS:
Later Windows editions seem to be fine with above
conditions.

Signed-off-by: Igor Mammedov 
---
 hw/i386/acpi-build.c  | 27 +++
 hw/i386/acpi-dsdt-cpu-hotplug.dsl | 17 +
 include/hw/acpi/pc-hotplug.h  |  1 +
 3 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index b82e636..eceba1c 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -101,6 +101,8 @@ typedef struct AcpiPmInfo {
 uint32_t gpe0_blk;
 uint32_t gpe0_blk_len;
 uint32_t io_base;
+uint16_t cpu_hp_io_base;
+uint16_t cpu_hp_io_len;
 } AcpiPmInfo;
 
 typedef struct AcpiMiscInfo {
@@ -175,12 +177,15 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
 
 if (piix) {
 obj = piix;
+pm->cpu_hp_io_base = PIIX4_CPU_HOTPLUG_IO_BASE;
 }
 if (lpc) {
 obj = lpc;
+pm->cpu_hp_io_base = ICH9_CPU_HOTPLUG_IO_BASE;
 }
 assert(obj);
 
+pm->cpu_hp_io_len = ACPI_GPE_PROC_LEN;
 /* Fill in optional s3/s4 related properties */
 o = object_property_get_qobject(obj, ACPI_PM_PROP_S3_DISABLED, NULL);
 if (o) {
@@ -826,6 +831,28 @@ build_ssdt(Aml *table_data,
 
 sb_scope = aml_scope("_SB");
 {
+/* create PCI0.PRES device and its _CRS to reserve CPU hotplug MMIO */
+dev = aml_device("PCI0." stringify(CPU_HOTPLUG_RESOURCE_DEVICE));
+aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0A06")));
+aml_append(dev,
+aml_name_decl("_UID", aml_string("CPU Hotplug resources"))
+);
+/* device present, functioning, decoding, not shown in UI */
+aml_append(dev, aml_name_decl("_STA", aml_int(0xB)));
+crs = aml_resource_template();
+aml_append(crs,
+aml_io(aml_decode16, pm->cpu_hp_io_base, pm->cpu_hp_io_base, 1,
+   pm->cpu_hp_io_len)
+);
+aml_append(dev, aml_name_decl("_CRS", crs));
+aml_append(sb_scope, dev);
+/* declare CPU hotplug MMIO region and PRS field to access it */
+aml_append(sb_scope, aml_operation_region(
+"PRST", aml_system_io, pm->cpu_hp_io_base, pm->cpu_hp_io_len));
+field = aml_field("PRST", aml_byte_acc);
+aml_append(field, aml_named_field("PRS", 256));
+aml_append(sb_scope, field);
+
 /* build Processor object for each processor */
 for (i = 0; i < acpi_cpus; i++) {
 dev = aml_processor(i, 0, 0, "CP%.02X", i);
diff --git a/hw/i386/acpi-dsdt-cpu-hotplug.dsl 
b/hw/i386/acpi-dsdt-cpu-hotplug.dsl
index 268d870..1aff746 100644
--- a/hw/i386/acpi-dsdt-cpu-hotplug.dsl
+++ b/hw/i386/acpi-dsdt-cpu-hotplug.dsl
@@ -16,12 +16,12 @@
 /
  * CPU hotplug
  /
-#define CPU_HOTPLUG_RESOURCE_DEVICE PRES
 
 Scope(\_SB) {
 /* Objects filled in by run-time generated SSDT */
 External(NTFY, MethodObj)
 External(CPON, PkgObj)
+External(PRS, FieldUnitObj)
 
 /* Methods called by run-time generated SSDT Processor objects */
 Method(CPMA, 1, NotSerialized) {
@@ -54,10 +54,6 @@ Scope(\_SB) {
 }
 
 #define CPU_STATUS_LEN ACPI_GPE_PROC_LEN
-OperationRegion(PRST, SystemIO, CPU_STATUS_BASE, CPU_STATUS_LEN)
-Field(PRST, ByteAcc, NoLock, Preserve) {
-PRS, 256
-}
 Method(PRSC, 0) {
 // Local5 = active cpu bitmap
 Store(PRS, Local5)
@@ -91,15 +87,4 @@ Scope(\_SB) {
 Increment(Local0)
 }
 }
-
-Device(CPU_HOTPLUG_RESOURCE_DEVICE) {
-Name(_HID, EisaId("PNP0A06"))
-Name(_UID, "CPU hotplug resources")
-
-Name(_CRS, ResourceTemplate() {
-IO(Decode16, CPU_STATUS_BASE, CPU_STATUS_BASE, 0, CPU_STATUS_LEN)
-})
-
-Name(_STA, 0xB) /* present, functioning, decoding, not shown in UI */
-}
 }

[Qemu-devel] [PATCH v3 35/52] acpi: add aml_equal() term

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 10 ++
 include/hw/acpi/aml-build.h |  1 +
 2 files changed, 11 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 90b7b65..670d3e9 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -554,6 +554,16 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t 
max_base,
 return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefLEqual */
+Aml *aml_equal(Aml *arg1, Aml *arg2)
+{
+Aml *var = aml_opcode(0x93 /* LequalOp */);
+aml_append(var, arg1);
+aml_append(var, arg2);
+build_append_int(var->buf, 0x00); /* NullNameOp */
+return var;
+}
+
 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
 Aml *aml_if(Aml *predicate)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index d5b9325..e918055 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -103,6 +103,7 @@ Aml *aml_operation_region(const char *name, AmlRegionSpace 
rs,
 Aml *aml_named_field(const char *name, unsigned length);
 Aml *aml_local(int num);
 Aml *aml_string(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
+Aml *aml_equal(Aml *arg1, Aml *arg2);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 38/52] pc: acpi-build: drop template patching and CPU hotplug objects dynamically

2015-02-09 Thread Igor Mammedov
in addition it saves us ~400LOC and makes it
one binary blob less stored in QEMU source
tree by removing need to keep and update
hw/i386/ssdt-proc.hex.generated file there.

Signed-off-by: Igor Mammedov 
---
 hw/i386/Makefile.objs   |   2 +-
 hw/i386/acpi-build.c|  95 
 hw/i386/ssdt-proc.dsl   |  63 ---
 hw/i386/ssdt-proc.hex.generated | 134 
 4 files changed, 42 insertions(+), 252 deletions(-)
 delete mode 100644 hw/i386/ssdt-proc.dsl
 delete mode 100644 hw/i386/ssdt-proc.hex.generated

diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index 4509cd1..a1e5aa2 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -8,7 +8,7 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/
 obj-y += kvmvapic.o
 obj-y += acpi-build.o
 hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
-   hw/i386/ssdt-proc.hex hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
+   hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
hw/i386/ssdt-mem.hex hw/i386/ssdt-tpm.hex
 
 iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index a86dc42..b82e636 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -509,22 +509,6 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo 
*cpu,
  table_data->len - madt_start, 1);
 }
 
-/* Encode a hex value */
-static inline char acpi_get_hex(uint32_t val)
-{
-val &= 0x0f;
-return (val <= 9) ? ('0' + val) : ('A' + val - 10);
-}
-
-#include "hw/i386/ssdt-proc.hex"
-
-/* 0x5B 0x83 ProcessorOp PkgLength NameString ProcID */
-#define ACPI_PROC_OFFSET_CPUHEX (*ssdt_proc_name - *ssdt_proc_start + 2)
-#define ACPI_PROC_OFFSET_CPUID1 (*ssdt_proc_name - *ssdt_proc_start + 4)
-#define ACPI_PROC_OFFSET_CPUID2 (*ssdt_proc_id - *ssdt_proc_start)
-#define ACPI_PROC_SIZEOF (*ssdt_proc_end - *ssdt_proc_start)
-#define ACPI_PROC_AML (ssdp_proc_aml + *ssdt_proc_start)
-
 #include "hw/i386/ssdt-mem.hex"
 
 /* 0x5B 0x82 DeviceOp PkgLength NameString DimmID */
@@ -756,7 +740,7 @@ build_ssdt(Aml *table_data,
 uint32_t nr_mem = machine->ram_slots;
 unsigned acpi_cpus = guest_info->apic_id_limit;
 uint8_t *ssdt_ptr;
-Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field;
+Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field, *ifctx;
 int i;
 
 /* The current AML generator can cover the APIC ID range [0..255],
@@ -844,51 +828,54 @@ build_ssdt(Aml *table_data,
 {
 /* build Processor object for each processor */
 for (i = 0; i < acpi_cpus; i++) {
-uint8_t *proc = acpi_data_push(sb_scope->buf, ACPI_PROC_SIZEOF);
-memcpy(proc, ACPI_PROC_AML, ACPI_PROC_SIZEOF);
-proc[ACPI_PROC_OFFSET_CPUHEX] = acpi_get_hex(i >> 4);
-proc[ACPI_PROC_OFFSET_CPUHEX+1] = acpi_get_hex(i);
-proc[ACPI_PROC_OFFSET_CPUID1] = i;
-proc[ACPI_PROC_OFFSET_CPUID2] = i;
+dev = aml_processor(i, 0, 0, "CP%.02X", i);
+
+method = aml_method("_MAT", 0);
+aml_append(method, aml_return(aml_call1("CPMA", aml_int(i;
+aml_append(dev, method);
+
+method = aml_method("_STA", 0);
+aml_append(method, aml_return(aml_call1("CPST", aml_int(i;
+aml_append(dev, method);
+
+method = aml_method("_EJ0", 1);
+aml_append(method,
+aml_return(aml_call2("CPEJ", aml_int(i), aml_arg(0)))
+);
+aml_append(dev, method);
+
+aml_append(sb_scope, dev);
 }
 
 /* build this code:
  *   Method(NTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CP00, Arg1)} ...}
  */
 /* Arg0 = Processor ID = APIC ID */
-build_append_notify_method(sb_scope->buf, "NTFY",
-   "CP%0.02X", acpi_cpus);
-
-/* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" */
-build_append_byte(sb_scope->buf, 0x08); /* NameOp */
-build_append_namestring(sb_scope->buf, "CPON");
-
-{
-GArray *package = build_alloc_array();
-uint8_t op;
-
-/*
- * Note: The ability to create variable-sized packages was first 
introduced in ACPI 2.0. ACPI 1.0 only
- * allowed fixed-size packages with up to 255 elements.
- * Windows guests up to win2k8 fail when VarPackageOp is used.
- */
-if (acpi_cpus <= 255) {
-op = 0x12; /* PackageOp */
-build_append_byte(package, acpi_cpus); /* NumElements */
-} else {
-op = 0x13; /* VarPackageOp */
-build_append_int(package, acpi_cpus); /* VarNumElements */
-}
-
-for (i = 0; i < acpi_cpus; i++) {
-uint8_t b = test_bit(i, cpu->found_cpus) ? 0x01 : 0

[Qemu-devel] [PATCH v3 47/52] pc: acpi-build: drop remaining ssdt_misc template and use acpi_def_block()

2015-02-09 Thread Igor Mammedov
It completes dynamic SSDT generation and makes it
independed of IASL binary blobs. It also hides
from user all pointer arithmetic when building
SSDT which makes resulting code a bit cleaner
and concentrating only on composing ASL construct
/i.e. a task build_ssdt() should be doing/.

Also it makes one binary blob less stored in QEMU
source tree by removing need to keep and update
hw/i386/ssdt-misc.hex.generated file here in total
saving us ~430LOC.

Signed-off-by: Igor Mammedov 
---
 hw/i386/Makefile.objs   |   2 +-
 hw/i386/acpi-build.c|  12 --
 hw/i386/ssdt-misc.dsl   |  21 ---
 hw/i386/ssdt-misc.hex.generated | 399 
 4 files changed, 1 insertion(+), 433 deletions(-)
 delete mode 100644 hw/i386/ssdt-misc.dsl
 delete mode 100644 hw/i386/ssdt-misc.hex.generated

diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index 6c8705d..dc8c38a 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -8,7 +8,7 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/
 obj-y += kvmvapic.o
 obj-y += acpi-build.o
 hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
-   hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
+   hw/i386/q35-acpi-dsdt.hex \
hw/i386/ssdt-tpm.hex
 
 iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index bead77e..14c1c7d 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -466,10 +466,6 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo 
*cpu,
  table_data->len - madt_start, 1);
 }
 
-#define ACPI_SSDT_SIGNATURE 0x54445353 /* SSDT */
-#define ACPI_SSDT_HEADER_LENGTH 36
-
-#include "hw/i386/ssdt-misc.hex"
 #include "hw/i386/ssdt-tpm.hex"
 
 /* Assign BSEL property to all buses.  In the future, this can be changed
@@ -654,7 +650,6 @@ build_ssdt(Aml *table_data,
 MachineState *machine = MACHINE(qdev_get_machine());
 uint32_t nr_mem = machine->ram_slots;
 unsigned acpi_cpus = guest_info->apic_id_limit;
-uint8_t *ssdt_ptr;
 Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field, *ifctx;
 int i;
 
@@ -668,13 +663,6 @@ build_ssdt(Aml *table_data,
  ACPI_BUILD_APPNAME4, 1,
  ACPI_BUILD_APPNAME4_HEX, 1);
 
-/* Copy misc variables and patch values in the S3_ / S4_ / S5_ packages */
-acpi_data_push(ssdt->buf, sizeof(ssdp_misc_aml) - sizeof(AcpiTableHeader));
-ssdt_ptr = (uint8_t *)ssdt->buf->data;
-memcpy(ssdt_ptr + sizeof(AcpiTableHeader),
-   ssdp_misc_aml + sizeof(AcpiTableHeader),
-   sizeof(ssdp_misc_aml) - sizeof(AcpiTableHeader));
-
 scope = aml_scope("\\_SB.PCI0");
 /* build PCI0._CRS */
 crs = aml_resource_template();
diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
deleted file mode 100644
index 8d61f21..000
--- a/hw/i386/ssdt-misc.dsl
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, see .
- */
-#include "hw/acpi/pc-hotplug.h"
-
-ACPI_EXTRACT_ALL_CODE ssdp_misc_aml
-
-DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
-{
-}
diff --git a/hw/i386/ssdt-misc.hex.generated b/hw/i386/ssdt-misc.hex.generated
deleted file mode 100644
index cbcf61d..000
--- a/hw/i386/ssdt-misc.hex.generated
+++ /dev/null
@@ -1,399 +0,0 @@
-static unsigned char acpi_pci64_length[] = {
-0x6f
-};
-static unsigned char acpi_s4_pkg[] = {
-0x99
-};
-static unsigned char ssdt_mctrl_nr_slots[] = {
-0x7d
-};
-static unsigned char acpi_s3_name[] = {
-0x86
-};
-static unsigned char acpi_pci32_start[] = {
-0x2f
-};
-static unsigned char acpi_pci64_valid[] = {
-0x43
-};
-static unsigned char ssdp_misc_aml[] = {
-0x53,
-0x53,
-0x44,
-0x54,
-0x6c,
-0x1,
-0x0,
-0x0,
-0x1,
-0x3,
-0x42,
-0x58,
-0x50,
-0x43,
-0x0,
-0x0,
-0x42,
-0x58,
-0x53,
-0x53,
-0x44,
-0x54,
-0x53,
-0x55,
-0x1,
-0x0,
-0x0,
-0x0,
-0x49,
-0x4e,
-0x54,
-0x4c,
-0x28,
-0x8,
-0x14,
-0x20,
-0x10,
-0x4c,
-0x5,
-0x5c,
-0x0,
-0x8,
-0x50,
-0x30,
-0x53,
-0x5f,
-0xc,
-0x78,
-0x56,
-0x34,
-0x12,
-0x8,
-0x50,
-0x30,
-0x45,
-0x5f,
-0xc,
-0x78,
-0x56,
-0x34,
-0x12,
-0x8,
-0x50,
-0x31,
-0x56,
-0x5f,
-0xa,
-0x12,
-0x8,
-0x50,
-0x31,
-0x53,
-0x5f,
-0x11,
-0xb,
-0xa,
-0x8,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x8,
-0x50,
-0x31,
-0x45,
-0x5f,
-0x11,
-0xb,
-0xa,
-0x8,
-0x0,
-0x0,
-0x0,
-0x0,
-0

[Qemu-devel] [PATCH v3 37/52] acpi: add aml_eisaid() term

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 29 +
 include/hw/acpi/aml-build.h |  1 +
 2 files changed, 30 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index aa5ef59..90c1272 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -716,3 +716,32 @@ Aml *aml_processor(uint8_t proc_id, uint32_t pblk_addr, 
uint8_t pblk_len,
 build_append_byte(var->buf, pblk_len); /* PblkLen */
 return var;
 }
+
+static uint8_t Hex2Digit(char c)
+{
+if (c >= 'A') {
+return c - 'A' + 10;
+}
+
+return c - '0';
+}
+
+/* ACPI 1.0b: 15.2.3.6.4.1 EISAID Macro - Convert EISA ID String To Integer */
+Aml *aml_eisaid(const char *str)
+{
+Aml *var = aml_alloc();
+uint32_t id;
+
+g_assert(strlen(str) == 7);
+id = (str[0] - 0x40) << 26 |
+(str[1] - 0x40) << 21 |
+(str[2] - 0x40) << 16 |
+Hex2Digit(str[3]) << 12 |
+Hex2Digit(str[4]) << 8 |
+Hex2Digit(str[5]) << 4 |
+Hex2Digit(str[6]);
+
+build_append_byte(var->buf, 0x0C); /* DWordPrefix */
+build_append_value(var->buf, bswap32(id), sizeof(id));
+return var;
+}
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 3cf9fbb..84fe4db 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -106,6 +106,7 @@ Aml *aml_string(const char *name_format, ...) 
GCC_FMT_ATTR(1, 2);
 Aml *aml_equal(Aml *arg1, Aml *arg2);
 Aml *aml_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,
const char *name_format, ...) GCC_FMT_ATTR(4, 5);
+Aml *aml_eisaid(const char *str);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 40/52] acpi: add aml_reserved_field() term

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 10 ++
 include/hw/acpi/aml-build.h |  6 ++
 2 files changed, 16 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 90c1272..1b23459 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -649,6 +649,16 @@ Aml *aml_named_field(const char *name, unsigned length)
 return var;
 }
 
+/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: ReservedField */
+Aml *aml_reserved_field(unsigned length)
+{
+Aml *var = aml_alloc();
+/* ReservedField  := 0x00 PkgLength */
+build_append_byte(var->buf, 0x00);
+build_append_pkg_length(var->buf, length, false);
+return var;
+}
+
 /* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefField */
 Aml *aml_field(const char *name, AmlFieldFlags flags)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 84fe4db..a04c107 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -37,7 +37,12 @@ typedef enum {
 } AmlIODecode;
 
 typedef enum {
+aml_any_acc = 0,
 aml_byte_acc = 1,
+aml_word_acc = 2,
+aml_dword_acc = 3,
+aml_qword_acc = 4,
+aml_buffer_acc = 5,
 } AmlFieldFlags;
 
 typedef enum {
@@ -101,6 +106,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t 
max_base,
 Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
   uint32_t offset, uint32_t len);
 Aml *aml_named_field(const char *name, unsigned length);
+Aml *aml_reserved_field(unsigned length);
 Aml *aml_local(int num);
 Aml *aml_string(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_equal(Aml *arg1, Aml *arg2);
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 41/52] pc: acpi-build: drop template patching and memory hotplug objects dynamically

2015-02-09 Thread Igor Mammedov
in addition it saves us ~330LOC and makes it one binary blob less
stored in QEMU source tree by removing need to keep and update
hw/i386/ssdt-mem.hex.generated file there.

Signed-off-by: Igor Mammedov 
---
 hw/i386/Makefile.objs  |   2 +-
 hw/i386/acpi-build.c   | 133 +
 hw/i386/ssdt-mem.dsl   |  77 ---
 hw/i386/ssdt-mem.hex.generated | 213 -
 4 files changed, 47 insertions(+), 378 deletions(-)
 delete mode 100644 hw/i386/ssdt-mem.dsl
 delete mode 100644 hw/i386/ssdt-mem.hex.generated

diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index a1e5aa2..6c8705d 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -9,7 +9,7 @@ obj-y += kvmvapic.o
 obj-y += acpi-build.o
 hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
hw/i386/ssdt-misc.hex hw/i386/q35-acpi-dsdt.hex \
-   hw/i386/ssdt-mem.hex hw/i386/ssdt-tpm.hex
+   hw/i386/ssdt-tpm.hex
 
 iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
 ; then echo "$(2)"; else echo "$(3)"; fi ;)
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index eceba1c..18e69a7 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -281,49 +281,6 @@ build_header(GArray *linker, GArray *table_data,
 table_data->data, h, len, &h->checksum);
 }
 
-static GArray *build_alloc_method(const char *name, uint8_t arg_count)
-{
-GArray *method = build_alloc_array();
-
-build_append_namestring(method, "%s", name);
-build_append_byte(method, arg_count); /* MethodFlags: ArgCount */
-
-return method;
-}
-
-static void build_append_and_cleanup_method(GArray *device, GArray *method)
-{
-uint8_t op = 0x14; /* MethodOp */
-
-build_package(method, op);
-
-build_append_array(device, method);
-build_free_array(method);
-}
-
-static void build_append_notify_target_ifequal(GArray *method,
-   GArray *target_name,
-   uint32_t value)
-{
-GArray *notify = build_alloc_array();
-uint8_t op = 0xA0; /* IfOp */
-
-build_append_byte(notify, 0x93); /* LEqualOp */
-build_append_byte(notify, 0x68); /* Arg0Op */
-build_append_int(notify, value);
-build_append_byte(notify, 0x86); /* NotifyOp */
-build_append_array(notify, target_name);
-build_append_byte(notify, 0x69); /* Arg1Op */
-
-/* Pack it up */
-build_package(notify, op);
-
-build_append_array(method, notify);
-
-build_free_array(notify);
-}
-
-/* End here */
 #define ACPI_PORT_SMI_CMD   0x00b2 /* TODO: this is APM_CNT_IOPORT */
 
 static inline void *acpi_data_push(GArray *table_data, unsigned size)
@@ -514,38 +471,12 @@ build_madt(GArray *table_data, GArray *linker, 
AcpiCpuInfo *cpu,
  table_data->len - madt_start, 1);
 }
 
-#include "hw/i386/ssdt-mem.hex"
-
-/* 0x5B 0x82 DeviceOp PkgLength NameString DimmID */
-#define ACPI_MEM_OFFSET_HEX (*ssdt_mem_name - *ssdt_mem_start + 2)
-#define ACPI_MEM_OFFSET_ID (*ssdt_mem_id - *ssdt_mem_start + 7)
-#define ACPI_MEM_SIZEOF (*ssdt_mem_end - *ssdt_mem_start)
-#define ACPI_MEM_AML (ssdm_mem_aml + *ssdt_mem_start)
-
 #define ACPI_SSDT_SIGNATURE 0x54445353 /* SSDT */
 #define ACPI_SSDT_HEADER_LENGTH 36
 
 #include "hw/i386/ssdt-misc.hex"
 #include "hw/i386/ssdt-tpm.hex"
 
-static void
-build_append_notify_method(GArray *device, const char *name,
-   const char *format, int count)
-{
-int i;
-GArray *method = build_alloc_method(name, 2);
-
-for (i = 0; i < count; i++) {
-GArray *target = build_alloc_array();
-build_append_namestring(target, format, i);
-assert(i < 256); /* Fits in 1 byte */
-build_append_notify_target_ifequal(method, target, i);
-build_free_array(target);
-}
-
-build_append_and_cleanup_method(device, method);
-}
-
 /* Assign BSEL property to all buses.  In the future, this can be changed
  * to only assign to buses that support hotplug.
  */
@@ -904,26 +835,54 @@ build_ssdt(Aml *table_data,
 }
 aml_append(sb_scope, aml_name_decl("CPON", pkg));
 
-if (nr_mem) {
-assert(nr_mem <= ACPI_MAX_RAM_SLOTS);
-/* build memory devices */
-for (i = 0; i < nr_mem; i++) {
-char id[3];
-uint8_t *mem = acpi_data_push(sb_scope->buf, ACPI_MEM_SIZEOF);
-
-snprintf(id, sizeof(id), "%02X", i);
-memcpy(mem, ACPI_MEM_AML, ACPI_MEM_SIZEOF);
-memcpy(mem + ACPI_MEM_OFFSET_HEX, id, 2);
-memcpy(mem + ACPI_MEM_OFFSET_ID, id, 2);
-}
+/* build memory devices */
+assert(nr_mem <= ACPI_MAX_RAM_SLOTS);
 
-/* build Method(MEMORY_SLOT_NOTIFY_METHOD, 2) {
- * If (LEqual(Arg0, 0x00)) {Notify(MP00, Arg1)} ...
- */
-build_

[Qemu-devel] [PATCH v3 46/52] pc: acpi-build: create PCI0._CRS dynamically

2015-02-09 Thread Igor Mammedov
Replace template patching and runtime
calculation in _CRS() method with static _CRS
defined in SSDT.

It also drops manual hole patching for reserved
PCI/MEM/CPU hoptlug MMIO resources and utilizes
the fact that MMIO resources are reserved by
respective child /i.e. PHPR, MHPD, PRES/ containers.

Signed-off-by: Igor Mammedov 
---
 hw/i386/acpi-build.c  | 69 
 hw/i386/acpi-dsdt-pci-crs.dsl | 92 ---
 hw/i386/acpi-dsdt.dsl | 45 -
 hw/i386/q35-acpi-dsdt.dsl | 18 -
 hw/i386/ssdt-misc.dsl | 19 -
 5 files changed, 33 insertions(+), 210 deletions(-)
 delete mode 100644 hw/i386/acpi-dsdt-pci-crs.dsl

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index e195017..bead77e 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -319,24 +319,6 @@ static void acpi_align_size(GArray *blob, unsigned align)
 g_array_set_size(blob, ROUND_UP(acpi_data_len(blob), align));
 }
 
-/* Set a value within table in a safe manner */
-#define ACPI_BUILD_SET_LE(table, size, off, bits, val) \
-do { \
-uint64_t ACPI_BUILD_SET_LE_val = cpu_to_le64(val); \
-memcpy(acpi_data_get_ptr(table, size, off, \
- (bits) / BITS_PER_BYTE), \
-   &ACPI_BUILD_SET_LE_val, \
-   (bits) / BITS_PER_BYTE); \
-} while (0)
-
-static inline void *acpi_data_get_ptr(uint8_t *table_data, unsigned table_size,
-  unsigned off, unsigned size)
-{
-assert(off + size > off);
-assert(off + size <= table_size);
-return table_data + off;
-}
-
 static inline void acpi_add_table(GArray *table_offsets, GArray *table_data)
 {
 uint32_t offset = cpu_to_le32(table_data->len);
@@ -664,22 +646,6 @@ static void build_append_pci_bus_devices(Aml 
*parent_scope, PCIBus *bus,
 aml_append(parent_scope, method);
 }
 
-static void patch_pci_windows(PcPciInfo *pci, uint8_t *start, unsigned size)
-{
-ACPI_BUILD_SET_LE(start, size, acpi_pci32_start[0], 32, pci->w32.begin);
-
-ACPI_BUILD_SET_LE(start, size, acpi_pci32_end[0], 32, pci->w32.end - 1);
-
-if (pci->w64.end || pci->w64.begin) {
-ACPI_BUILD_SET_LE(start, size, acpi_pci64_valid[0], 8, 1);
-ACPI_BUILD_SET_LE(start, size, acpi_pci64_start[0], 64, 
pci->w64.begin);
-ACPI_BUILD_SET_LE(start, size, acpi_pci64_end[0], 64, pci->w64.end - 
1);
-ACPI_BUILD_SET_LE(start, size, acpi_pci64_length[0], 64, pci->w64.end 
- pci->w64.begin);
-} else {
-ACPI_BUILD_SET_LE(start, size, acpi_pci64_valid[0], 8, 0);
-}
-}
-
 static void
 build_ssdt(Aml *table_data,
AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -709,9 +675,40 @@ build_ssdt(Aml *table_data,
ssdp_misc_aml + sizeof(AcpiTableHeader),
sizeof(ssdp_misc_aml) - sizeof(AcpiTableHeader));
 
-patch_pci_windows(pci, ssdt_ptr, sizeof(ssdp_misc_aml));
-
 scope = aml_scope("\\_SB.PCI0");
+/* build PCI0._CRS */
+crs = aml_resource_template();
+aml_append(crs,
+aml_word_bus_number(aml_min_fixed, aml_max_fixed, aml_pos_decode,
+0x, 0x, 0x00FF, 0x, 0x0100));
+aml_append(crs, aml_io(aml_decode16, 0x0CF8, 0x0CF8, 0x01, 0x08));
+
+aml_append(crs,
+aml_word_io(aml_min_fixed, aml_max_fixed,
+aml_pos_decode, aml_entire_range,
+0x, 0x, 0x0CF7, 0x, 0x0CF8));
+aml_append(crs,
+aml_word_io(aml_min_fixed, aml_max_fixed,
+aml_pos_decode, aml_entire_range,
+0x, 0x0D00, 0x, 0x, 0xF300));
+aml_append(crs,
+aml_dword_memory(aml_pos_decode, aml_min_fixed, aml_max_fixed,
+ aml_cacheable, aml_ReadWrite,
+ 0, 0x000A, 0x000B, 0, 0x0002));
+aml_append(crs,
+aml_dword_memory(aml_pos_decode, aml_min_fixed, aml_max_fixed,
+ aml_non_cacheable, aml_ReadWrite,
+ 0, pci->w32.begin, pci->w32.end - 1, 0,
+ pci->w32.end - pci->w32.begin));
+if (pci->w64.begin) {
+aml_append(crs,
+aml_qword_memory(aml_pos_decode, aml_min_fixed, aml_max_fixed,
+ aml_cacheable, aml_ReadWrite,
+ 0, pci->w64.begin, pci->w64.end - 1, 0,
+ pci->w64.end - pci->w64.begin));
+}
+aml_append(scope, aml_name_decl("_CRS", crs));
+
 /* reserve PCIHP resources */
 if (pm->pcihp_io_len) {
 dev = aml_device("PHPR");
diff --git a/hw/i386/acpi-dsdt-pci-crs.dsl b/hw/i386/acpi-dsdt-pci-crs.dsl
deleted file mode 100644
index 4648e90..000
--- a/hw/i386/acpi-dsdt-pci-crs.dsl
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of t

[Qemu-devel] [PATCH v3 32/52] acpi: add aml_string() term

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 25 +
 include/hw/acpi/aml-build.h |  1 +
 2 files changed, 26 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index cb58e19..3929de9 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -648,6 +648,31 @@ Aml *aml_field(const char *name, AmlFieldFlags flags)
 return var;
 }
 
+/* ACPI 1.0b: 16.2.3 Data Objects Encoding: String */
+Aml *aml_string(const char *name_format, ...)
+{
+Aml *var = aml_opcode(0x0D /* StringPrefix */);
+va_list ap, va_len;
+char *s;
+int len;
+
+va_start(ap, name_format);
+va_copy(va_len, ap);
+len = vsnprintf(NULL, 0, name_format, va_len);
+va_end(va_len);
+len += 1;
+s = g_new0(typeof(*s), len);
+
+len = vsnprintf(s, len, name_format, ap);
+va_end(ap);
+
+g_array_append_vals(var->buf, s, len);
+build_append_byte(var->buf, 0x0); /* NullChar */
+g_free(s);
+
+return var;
+}
+
 /* ACPI 1.0b: 16.2.6.2 Local Objects Encoding */
 Aml *aml_local(int num)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 6e25315..fee4eef 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -102,6 +102,7 @@ Aml *aml_operation_region(const char *name, AmlRegionSpace 
rs,
   uint32_t offset, uint32_t len);
 Aml *aml_named_field(const char *name, unsigned length);
 Aml *aml_local(int num);
+Aml *aml_string(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 
 /* Block AML object primitives */
 Aml *aml_def_block(const char *signature, uint8_t revision,
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 43/52] acpi: add aml_word_bus_number(), aml_word_io(), aml_dword_memory(), aml_qword_memory() terms

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 161 
 include/hw/acpi/aml-build.h |  72 
 2 files changed, 233 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 1b23459..bfebdb4 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -755,3 +755,164 @@ Aml *aml_eisaid(const char *str)
 build_append_value(var->buf, bswap32(id), sizeof(id));
 return var;
 }
+
+/* ACPI 1.0b: 6.4.3.5.5 Word Address Space Descriptor: bytes 3-5 */
+static Aml *aml_as_desc_header(AmlResourceType type, AmlMinFixed min_fixed,
+   AmlMaxFixed max_fixed, AmlDecode dec,
+   uint8_t type_flags)
+{
+uint8_t flags = max_fixed | min_fixed | dec;
+Aml *var = aml_alloc();
+
+build_append_byte(var->buf, type);
+build_append_byte(var->buf, flags);
+build_append_byte(var->buf, type_flags); /* Type Specific Flags */
+return var;
+}
+
+/* ACPI 1.0b: 6.4.3.5.5 Word Address Space Descriptor */
+static Aml *aml_word_as_desc(AmlResourceType type, AmlMinFixed min_fixed,
+ AmlMaxFixed max_fixed, AmlDecode dec,
+ uint16_t addr_gran, uint16_t addr_min,
+ uint16_t addr_max, uint16_t addr_trans,
+ uint16_t len, uint8_t type_flags)
+{
+Aml *var = aml_alloc();
+
+build_append_byte(var->buf, 0x88); /* Word Address Space Descriptor */
+/* minimum length since we do not encode optional fields */
+build_append_byte(var->buf, 0x0D);
+build_append_byte(var->buf, 0x0);
+
+aml_append(var,
+aml_as_desc_header(type, min_fixed, max_fixed, dec, type_flags));
+build_append_value(var->buf, addr_gran, sizeof(addr_gran));
+build_append_value(var->buf, addr_min, sizeof(addr_min));
+build_append_value(var->buf, addr_max, sizeof(addr_max));
+build_append_value(var->buf, addr_trans, sizeof(addr_trans));
+build_append_value(var->buf, len, sizeof(len));
+return var;
+}
+
+/* ACPI 1.0b: 6.4.3.5.3 DWord Address Space Descriptor */
+static Aml *aml_dword_as_desc(AmlResourceType type, AmlMinFixed min_fixed,
+  AmlMaxFixed max_fixed, AmlDecode dec,
+  uint32_t addr_gran, uint32_t addr_min,
+  uint32_t addr_max, uint32_t addr_trans,
+  uint32_t len, uint8_t type_flags)
+{
+Aml *var = aml_alloc();
+
+build_append_byte(var->buf, 0x87); /* DWord Address Space Descriptor */
+/* minimum length since we do not encode optional fields */
+build_append_byte(var->buf, 23);
+build_append_byte(var->buf, 0x0);
+
+
+aml_append(var,
+aml_as_desc_header(type, min_fixed, max_fixed, dec, type_flags));
+build_append_value(var->buf, addr_gran, sizeof(addr_gran));
+build_append_value(var->buf, addr_min, sizeof(addr_min));
+build_append_value(var->buf, addr_max, sizeof(addr_max));
+build_append_value(var->buf, addr_trans, sizeof(addr_trans));
+build_append_value(var->buf, len, sizeof(len));
+return var;
+}
+
+/* ACPI 1.0b: 6.4.3.5.1 QWord Address Space Descriptor */
+static Aml *aml_qword_as_desc(AmlResourceType type, AmlMinFixed min_fixed,
+  AmlMaxFixed max_fixed, AmlDecode dec,
+  uint64_t addr_gran, uint64_t addr_min,
+  uint64_t addr_max, uint64_t addr_trans,
+  uint64_t len, uint8_t type_flags)
+{
+Aml *var = aml_alloc();
+
+build_append_byte(var->buf, 0x8A); /* QWord Address Space Descriptor */
+/* minimum length since we do not encode optional fields */
+build_append_byte(var->buf, 0x2B);
+build_append_byte(var->buf, 0x0);
+
+aml_append(var,
+aml_as_desc_header(type, min_fixed, max_fixed, dec, type_flags));
+build_append_value(var->buf, addr_gran, sizeof(addr_gran));
+build_append_value(var->buf, addr_min, sizeof(addr_min));
+build_append_value(var->buf, addr_max, sizeof(addr_max));
+build_append_value(var->buf, addr_trans, sizeof(addr_trans));
+build_append_value(var->buf, len, sizeof(len));
+return var;
+}
+
+/*
+ * ACPI 1.0b: 6.4.3.5.6 ASL Macros for WORD Address Descriptor
+ *
+ * More verbose description at:
+ * ACPI 5.0: 19.5.141 WordBusNumber (Word Bus Number Resource Descriptor Macro)
+ */
+Aml *aml_word_bus_number(AmlMinFixed min_fixed, AmlMaxFixed max_fixed,
+ AmlDecode dec, uint16_t addr_gran,
+ uint16_t addr_min, uint16_t addr_max,
+ uint16_t addr_trans, uint16_t len)
+
+{
+return aml_word_as_desc(aml_bus_number_range, min_fixed, max_fixed, dec,
+addr_gran, addr_min, addr_max, addr_trans, len, 0);
+}
+
+/*
+ * ACPI 1.0b: 6.4.3.5.6 ASL Macros for WORD Address Descriptor
+ *
+ * More verbose des

[Qemu-devel] [PATCH v3 51/52] pc: acpi-build: update [q35-]acpi-dsdt.hex.generated due to moved SMC

2015-02-09 Thread Igor Mammedov
so that build on IASL less hosts won't fail due to
present but unused variable warning

Signed-off-by: Igor Mammedov 
---
 hw/i386/acpi-dsdt.hex.generated | 714 ++--
 hw/i386/q35-acpi-dsdt.hex.generated | 662 ++---
 2 files changed, 58 insertions(+), 1318 deletions(-)

diff --git a/hw/i386/acpi-dsdt.hex.generated b/hw/i386/acpi-dsdt.hex.generated
index 498b194..09f064e 100644
--- a/hw/i386/acpi-dsdt.hex.generated
+++ b/hw/i386/acpi-dsdt.hex.generated
@@ -3,12 +3,12 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x53,
 0x44,
 0x54,
-0x25,
-0xe,
+0x9a,
+0xb,
 0x0,
 0x0,
 0x1,
-0x6c,
+0xe1,
 0x42,
 0x58,
 0x50,
@@ -31,8 +31,8 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x4e,
 0x54,
 0x4c,
-0x7,
-0x11,
+0x26,
+0x9,
 0x14,
 0x20,
 0x10,
@@ -145,405 +145,6 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x44,
 0x1,
 0x10,
-0x4e,
-0x18,
-0x2e,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x8,
-0x43,
-0x52,
-0x45,
-0x53,
-0x11,
-0x42,
-0xa,
-0xa,
-0x9e,
-0x88,
-0xd,
-0x0,
-0x2,
-0xc,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0xff,
-0x0,
-0x0,
-0x0,
-0x0,
-0x1,
-0x47,
-0x1,
-0xf8,
-0xc,
-0xf8,
-0xc,
-0x1,
-0x8,
-0x88,
-0xd,
-0x0,
-0x1,
-0xc,
-0x3,
-0x0,
-0x0,
-0x0,
-0x0,
-0xf7,
-0xc,
-0x0,
-0x0,
-0xf8,
-0xc,
-0x88,
-0xd,
-0x0,
-0x1,
-0xc,
-0x3,
-0x0,
-0x0,
-0x0,
-0xd,
-0xff,
-0xad,
-0x0,
-0x0,
-0x0,
-0xa1,
-0x88,
-0xd,
-0x0,
-0x1,
-0xc,
-0x3,
-0x0,
-0x0,
-0xf,
-0xae,
-0xff,
-0xae,
-0x0,
-0x0,
-0xf1,
-0x0,
-0x88,
-0xd,
-0x0,
-0x1,
-0xc,
-0x3,
-0x0,
-0x0,
-0x20,
-0xaf,
-0xdf,
-0xaf,
-0x0,
-0x0,
-0xc0,
-0x0,
-0x88,
-0xd,
-0x0,
-0x1,
-0xc,
-0x3,
-0x0,
-0x0,
-0xe4,
-0xaf,
-0xff,
-0xff,
-0x0,
-0x0,
-0x1c,
-0x50,
-0x87,
-0x17,
-0x0,
-0x0,
-0xc,
-0x3,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0xa,
-0x0,
-0xff,
-0xff,
-0xb,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x2,
-0x0,
-0x87,
-0x17,
-0x0,
-0x0,
-0xc,
-0x1,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0xe0,
-0xff,
-0xff,
-0xbf,
-0xfe,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0xc0,
-0x1e,
-0x79,
-0x0,
-0x8,
-0x43,
-0x52,
-0x36,
-0x34,
-0x11,
-0x33,
-0xa,
-0x30,
-0x8a,
-0x2b,
-0x0,
-0x0,
-0xc,
-0x3,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x80,
-0x0,
-0x0,
-0x0,
-0xff,
-0xff,
-0xff,
-0xff,
-0xff,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x80,
-0x0,
-0x0,
-0x0,
-0x79,
-0x0,
-0x14,
-0x41,
-0xa,
-0x5f,
-0x43,
-0x52,
-0x53,
-0x0,
-0x8a,
-0x43,
-0x52,
-0x45,
-0x53,
-0xa,
-0x8c,
-0x50,
-0x53,
-0x33,
-0x32,
-0x8a,
-0x43,
-0x52,
-0x45,
-0x53,
-0xa,
-0x90,
-0x50,
-0x45,
-0x33,
-0x32,
-0x8a,
-0x43,
-0x52,
-0x45,
-0x53,
-0xa,
-0x98,
-0x50,
-0x4c,
-0x33,
-0x32,
-0x70,
-0x50,
-0x30,
-0x53,
-0x5f,
-0x50,
-0x53,
-0x33,
-0x32,
-0x70,
-0x50,
-0x30,
-0x45,
-0x5f,
-0x50,
-0x45,
-0x33,
-0x32,
-0x70,
-0x72,
-0x74,
-0x50,
-0x30,
-0x45,
-0x5f,
-0x50,
-0x30,
-0x53,
-0x5f,
-0x0,
-0x1,
-0x0,
-0x50,
-0x4c,
-0x33,
-0x32,
-0xa0,
-0xc,
-0x93,
-0x50,
-0x31,
-0x56,
-0x5f,
-0x0,
-0xa4,
-0x43,
-0x52,
-0x45,
-0x53,
-0x8f,
-0x43,
-0x52,
-0x36,
-0x34,
-0xa,
-0xe,
-0x50,
-0x53,
-0x36,
-0x34,
-0x8f,
-0x43,
-0x52,
-0x36,
-0x34,
-0xa,
-0x16,
-0x50,
-0x45,
-0x36,
-0x34,
-0x8f,
-0x43,
-0x52,
-0x36,
-0x34,
-0xa,
-0x26,
-0x50,
-0x4c,
-0x36,
-0x34,
-0x70,
-0x50,
-0x31,
-0x53,
-0x5f,
-0x50,
-0x53,
-0x36,
-0x34,
-0x70,
-0x50,
-0x31,
-0x45,
-0x5f,
-0x50,
-0x45,
-0x36,
-0x34,
-0x70,
-0x50,
-0x31,
-0x4c,
-0x5f,
-0x50,
-0x4c,
-0x36,
-0x34,
-0x84,
-0x43,
-0x52,
-0x45,
-0x53,
-0x43,
-0x52,
-0x36,
-0x34,
-0x60,
-0xa4,
-0x60,
-0x10,
 0x4d,
 0x8,
 0x5f,
@@ -801,78 +402,32 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x3,
 0x43,
 0x42,
-0x45,
-0x4e,
-0x1,
-0x8,
-0x46,
-0x44,
-0x45,
-0x4e,
-0x1,
-0x10,
-0x4a,
-0x1e,
-0x2f,
-0x3,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x49,
-0x53,
-0x41,
-0x5f,
-0x5b,
-0x82,
-0x2c,
-0x53,
-0x4d,
-0x43,
-0x5f,
-0x8,
-0x5f,
-0x48,
-0x49,
-0x44,
-0xc,
-0x6,
-0x10,
-0x0,
+0x45,
+0x4e,
 0x1,
 0x8,
+0x46,
+0x44,
+0x45,
+0x4e,
+0x1,
+0x10,
+0x4c,
+0x1b,
+0x2f,
+0x3,
 0x5f,
 0x53,
-0x54,
-0x41,
-0xa,
-0xf0,
-0x8,
+0x42,
 0x5f,
+0x50,
 0x43,
-0x52,
+0x49,
+0x30,
+0x49,
 0x53,
-0x11,
-0x10,
-0xa,
-0xd,
-0x47,
-0x1,
-0x0,
-0x3,
-0x0,
-0x3,
-0x1,
-0x20,
-0x22,
-0x40,
-0x0,
-0x79,
-0x0,
+0x41,
+0x5f,
 0x5b,
 0x82,
 0x2d,
@@ -2318,8 +1873,8 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x53,
 0x1,
 0x10,
-0x4f,
-0x12,
+0x4d,
+0xc,
 0x5f,
 0x53,
 0x42,
@@ -2416,32 +1971,6 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x22,
 0xa,
 0xc8,
-0x5b,
-0x80,
-0x50,
-0x52,
-0x53,
-0x54,
-0x1,
-0xb,
-0x0,
-0xaf,
-0xa,
-0x20,
-0x5b,
-0x81,
-0xc,
-0x50,
-0x52,
-0x53,
-0x54,
-0x1,
-0x50,
-0x52,
-0x53,
-0x5f,
-0x40,
-0x10,
 0x14,
 0x4a,
 0x6,
@@ -2549,81 +2078,9 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x3,
 0x75,
 0x60,
-0x5b,
-0x82,
-0x46,
-0x4,
-0x50,
-0x52,
-0x45,
-0x53,
-0x8,
-0x5f,
-0x48,
-0x49,
-0x44,
-0xc,
-0x41,
-0xd0,
-0xa,
-0x6,
-0x8,
-0x5f,
-0x55,
-0x49,
-0x44,
-0xd,
-0x43,
-0x50,
-0x55,
-0x20,
-0x68,
-0x6f,
-0x74,
-0x70,
-0x6c,
-0x75,
-0x67,
-0x20

[Qemu-devel] [PATCH v3 44/52] pc: pcihp: expose MMIO base and len as properties

2015-02-09 Thread Igor Mammedov
it will be used later to dynamically reserve MMIO region
instead of manually punching holes in PCI0._CRS

Signed-off-by: Igor Mammedov 
---
 hw/acpi/pcihp.c | 18 --
 hw/acpi/piix4.c |  2 +-
 include/hw/acpi/pcihp.h |  7 ++-
 3 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c
index 34dedf1..612fec0 100644
--- a/hw/acpi/pcihp.c
+++ b/hw/acpi/pcihp.c
@@ -297,10 +297,11 @@ static const MemoryRegionOps acpi_pcihp_io_ops = {
 },
 };
 
-void acpi_pcihp_init(AcpiPciHpState *s, PCIBus *root_bus,
+void acpi_pcihp_init(Object *owner, AcpiPciHpState *s, PCIBus *root_bus,
  MemoryRegion *address_space_io, bool bridges_enabled)
 {
-uint16_t io_size = ACPI_PCIHP_SIZE;
+s->io_len = ACPI_PCIHP_SIZE;
+s->io_base = ACPI_PCIHP_ADDR;
 
 s->root= root_bus;
 s->legacy_piix = !bridges_enabled;
@@ -308,16 +309,21 @@ void acpi_pcihp_init(AcpiPciHpState *s, PCIBus *root_bus,
 if (s->legacy_piix) {
 unsigned *bus_bsel = g_malloc(sizeof *bus_bsel);
 
-io_size = ACPI_PCIHP_LEGACY_SIZE;
+s->io_len = ACPI_PCIHP_LEGACY_SIZE;
 
 *bus_bsel = ACPI_PCIHP_BSEL_DEFAULT;
 object_property_add_uint32_ptr(OBJECT(root_bus), ACPI_PCIHP_PROP_BSEL,
bus_bsel, NULL);
 }
 
-memory_region_init_io(&s->io, NULL, &acpi_pcihp_io_ops, s,
-  "acpi-pci-hotplug", io_size);
-memory_region_add_subregion(address_space_io, ACPI_PCIHP_ADDR, &s->io);
+memory_region_init_io(&s->io, owner, &acpi_pcihp_io_ops, s,
+  "acpi-pci-hotplug", s->io_len);
+memory_region_add_subregion(address_space_io, s->io_base, &s->io);
+
+object_property_add_uint16_ptr(owner, ACPI_PCIHP_IO_BASE_PROP, &s->io_base,
+   &error_abort);
+object_property_add_uint16_ptr(owner, ACPI_PCIHP_IO_LEN_PROP, &s->io_len,
+   &error_abort);
 }
 
 const VMStateDescription vmstate_acpi_pcihp_pci_status = {
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 766f1b8..d1f1179 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -562,7 +562,7 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion 
*parent,
   "acpi-gpe0", GPE_LEN);
 memory_region_add_subregion(parent, GPE_BASE, &s->io_gpe);
 
-acpi_pcihp_init(&s->acpi_pci_hotplug, bus, parent,
+acpi_pcihp_init(OBJECT(s), &s->acpi_pci_hotplug, bus, parent,
 s->use_acpi_pci_hotplug);
 
 acpi_cpu_hotplug_init(parent, OBJECT(s), &s->gpe_cpu,
diff --git a/include/hw/acpi/pcihp.h b/include/hw/acpi/pcihp.h
index 9323838..f3526d4 100644
--- a/include/hw/acpi/pcihp.h
+++ b/include/hw/acpi/pcihp.h
@@ -32,6 +32,9 @@
 #include "hw/acpi/acpi.h"
 #include "migration/vmstate.h"
 
+#define ACPI_PCIHP_IO_BASE_PROP "acpi-pcihp-io-base"
+#define ACPI_PCIHP_IO_LEN_PROP "acpi-pcihp-io-len"
+
 typedef struct AcpiPciHpPciStatus {
 uint32_t up;
 uint32_t down;
@@ -48,9 +51,11 @@ typedef struct AcpiPciHpState {
 PCIBus *root;
 MemoryRegion io;
 bool legacy_piix;
+uint16_t io_base;
+uint16_t io_len;
 } AcpiPciHpState;
 
-void acpi_pcihp_init(AcpiPciHpState *, PCIBus *root,
+void acpi_pcihp_init(Object *owner, AcpiPciHpState *, PCIBus *root,
  MemoryRegion *address_space_io, bool bridges_enabled);
 
 void acpi_pcihp_device_plug_cb(ACPIREGS *ar, qemu_irq irq, AcpiPciHpState *s,
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 52/52] acpi: make build_*() routines static to aml-build.c

2015-02-09 Thread Igor Mammedov
build_*() routines were used for composing AML
structures manually in acpi-build.c but after
conversion to AML API they are not used outside
of aml-build.c anymore, so hide them from external
users.

Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 22 +++---
 include/hw/acpi/aml-build.h | 17 -
 2 files changed, 11 insertions(+), 28 deletions(-)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 3f87d51..8f06f56 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -28,27 +28,27 @@
 #include "qemu/bswap.h"
 #include "hw/acpi/bios-linker-loader.h"
 
-GArray *build_alloc_array(void)
+static GArray *build_alloc_array(void)
 {
 return g_array_new(false, true /* clear */, 1);
 }
 
-void build_free_array(GArray *array)
+static void build_free_array(GArray *array)
 {
 g_array_free(array, true);
 }
 
-void build_prepend_byte(GArray *array, uint8_t val)
+static void build_prepend_byte(GArray *array, uint8_t val)
 {
 g_array_prepend_val(array, val);
 }
 
-void build_append_byte(GArray *array, uint8_t val)
+static void build_append_byte(GArray *array, uint8_t val)
 {
 g_array_append_val(array, val);
 }
 
-void build_append_array(GArray *array, GArray *val)
+static void build_append_array(GArray *array, GArray *val)
 {
 g_array_append_vals(array, val->data, val->len);
 }
@@ -142,7 +142,7 @@ build_append_namestringv(GArray *array, const char *format, 
va_list ap)
 g_strfreev(segs);
 }
 
-void build_append_namestring(GArray *array, const char *format, ...)
+static void build_append_namestring(GArray *array, const char *format, ...)
 {
 va_list ap;
 
@@ -159,7 +159,7 @@ enum {
 PACKAGE_LENGTH_4BYTE_SHIFT = 20,
 };
 
-void
+static void
 build_prepend_package_length(GArray *package, unsigned length, bool incl_self)
 {
 uint8_t byte;
@@ -227,19 +227,19 @@ build_append_pkg_length(GArray *array, unsigned length, 
bool incl_self)
 build_free_array(tmp);
 }
 
-void build_package(GArray *package, uint8_t op)
+static void build_package(GArray *package, uint8_t op)
 {
 build_prepend_package_length(package, package->len, true);
 build_prepend_byte(package, op);
 }
 
-void build_extop_package(GArray *package, uint8_t op)
+static void build_extop_package(GArray *package, uint8_t op)
 {
 build_package(package, op);
 build_prepend_byte(package, 0x5B); /* ExtOpPrefix */
 }
 
-void build_append_value(GArray *table, uint64_t value, int size)
+static void build_append_value(GArray *table, uint64_t value, int size)
 {
 int i;
 
@@ -249,7 +249,7 @@ void build_append_value(GArray *table, uint64_t value, int 
size)
 }
 }
 
-void build_append_int(GArray *table, uint64_t value)
+static void build_append_int(GArray *table, uint64_t value)
 {
 if (value == 0x00) {
 build_append_byte(table, 0x00); /* ZeroOp */
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 44cb7ea..7e9ce38 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -202,21 +202,4 @@ Aml *aml_resource_template(void);
 Aml *aml_field(const char *name, AmlFieldFlags flags);
 Aml *aml_varpackage(uint32_t num_elements);
 
-/* other helpers */
-GArray *build_alloc_array(void);
-void build_free_array(GArray *array);
-void build_prepend_byte(GArray *array, uint8_t val);
-void build_append_byte(GArray *array, uint8_t val);
-void build_append_array(GArray *array, GArray *val);
-
-void GCC_FMT_ATTR(2, 3)
-build_append_namestring(GArray *array, const char *format, ...);
-
-void
-build_prepend_package_length(GArray *package, unsigned length, bool incl_self);
-void build_package(GArray *package, uint8_t op);
-void build_append_value(GArray *table, uint64_t value, int size);
-void build_append_int(GArray *table, uint64_t value);
-void build_extop_package(GArray *package, uint8_t op);
-
 #endif
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 45/52] pc: acpi-build: reserve PCIHP MMIO resources

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/i386/acpi-build.c | 27 +++
 1 file changed, 27 insertions(+)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 256870b..e195017 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -105,6 +105,8 @@ typedef struct AcpiPmInfo {
 uint16_t cpu_hp_io_len;
 uint16_t mem_hp_io_base;
 uint16_t mem_hp_io_len;
+uint16_t pcihp_io_base;
+uint16_t pcihp_io_len;
 } AcpiPmInfo;
 
 typedef struct AcpiMiscInfo {
@@ -177,9 +179,15 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
 Object *obj = NULL;
 QObject *o;
 
+pm->pcihp_io_base = 0;
+pm->pcihp_io_len = 0;
 if (piix) {
 obj = piix;
 pm->cpu_hp_io_base = PIIX4_CPU_HOTPLUG_IO_BASE;
+pm->pcihp_io_base =
+object_property_get_int(obj, ACPI_PCIHP_IO_BASE_PROP, NULL);
+pm->pcihp_io_len =
+object_property_get_int(obj, ACPI_PCIHP_IO_LEN_PROP, NULL);
 }
 if (lpc) {
 obj = lpc;
@@ -703,6 +711,25 @@ build_ssdt(Aml *table_data,
 
 patch_pci_windows(pci, ssdt_ptr, sizeof(ssdp_misc_aml));
 
+scope = aml_scope("\\_SB.PCI0");
+/* reserve PCIHP resources */
+if (pm->pcihp_io_len) {
+dev = aml_device("PHPR");
+aml_append(dev, aml_name_decl("_HID", aml_string("PNP0A06")));
+aml_append(dev,
+aml_name_decl("_UID", aml_string("PCI Hotplug resources")));
+/* device present, functioning, decoding, not shown in UI */
+aml_append(dev, aml_name_decl("_STA", aml_int(0xB)));
+crs = aml_resource_template();
+aml_append(crs,
+aml_io(aml_decode16, pm->pcihp_io_base, pm->pcihp_io_base, 1,
+   pm->pcihp_io_len)
+);
+aml_append(dev, aml_name_decl("_CRS", crs));
+aml_append(scope, dev);
+}
+aml_append(ssdt, scope);
+
 /*  create S3_ / S4_ / S5_ packages if necessary */
 scope = aml_scope("\\");
 if (!pm->s3_disabled) {
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 42/52] pc: acpi-build: create memory hotplug IO region dynamically

2015-02-09 Thread Igor Mammedov
it replaces a static complied in DSDT MMIO region
for memory hotplug with one created at runtime
leaving only truly static memory hotplug related
ASL bits in DSDT. And replaces template patching
of MEMORY_SLOTS_NUMBER value with ASL API created
named value.

Later it also would make easier to reuse current
ACPI memory hotplug on other targets.

Also later it would be possible to move remaining
memory hotplug ASL methods into build_ssdt() and
add all memory hotplug related AML into SSDT only
when memory hotplug is enabled, further reducing
ACPI tables blob if memory hotplug isn't used.

Signed-off-by: Igor Mammedov 
---
 hw/i386/acpi-build.c  | 57 ---
 hw/i386/acpi-dsdt-mem-hotplug.dsl | 36 +++--
 hw/i386/ssdt-misc.dsl |  2 --
 3 files changed, 64 insertions(+), 31 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 18e69a7..256870b 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -103,6 +103,8 @@ typedef struct AcpiPmInfo {
 uint32_t io_base;
 uint16_t cpu_hp_io_base;
 uint16_t cpu_hp_io_len;
+uint16_t mem_hp_io_base;
+uint16_t mem_hp_io_len;
 } AcpiPmInfo;
 
 typedef struct AcpiMiscInfo {
@@ -186,6 +188,9 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
 assert(obj);
 
 pm->cpu_hp_io_len = ACPI_GPE_PROC_LEN;
+pm->mem_hp_io_base = ACPI_MEMORY_HOTPLUG_BASE;
+pm->mem_hp_io_len = ACPI_MEMORY_HOTPLUG_IO_LEN;
+
 /* Fill in optional s3/s4 related properties */
 o = object_property_get_qobject(obj, ACPI_PM_PROP_S3_DISABLED, NULL);
 if (o) {
@@ -698,9 +703,6 @@ build_ssdt(Aml *table_data,
 
 patch_pci_windows(pci, ssdt_ptr, sizeof(ssdp_misc_aml));
 
-ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
-  ssdt_mctrl_nr_slots[0], 32, nr_mem);
-
 /*  create S3_ / S4_ / S5_ packages if necessary */
 scope = aml_scope("\\");
 if (!pm->s3_disabled) {
@@ -837,6 +839,55 @@ build_ssdt(Aml *table_data,
 
 /* build memory devices */
 assert(nr_mem <= ACPI_MAX_RAM_SLOTS);
+scope = aml_scope("\\_SB.PCI0." stringify(MEMORY_HOTPLUG_DEVICE));
+aml_append(scope,
+aml_name_decl(stringify(MEMORY_SLOTS_NUMBER), aml_int(nr_mem))
+);
+
+crs = aml_resource_template();
+aml_append(crs,
+aml_io(aml_decode16, pm->mem_hp_io_base, pm->mem_hp_io_base, 0,
+   pm->mem_hp_io_len)
+);
+aml_append(scope, aml_name_decl("_CRS", crs));
+
+aml_append(scope, aml_operation_region(
+stringify(MEMORY_HOTPLUG_IO_REGION), aml_system_io,
+pm->mem_hp_io_base, pm->mem_hp_io_len)
+);
+
+field = aml_field(stringify(MEMORY_HOTPLUG_IO_REGION), aml_dword_acc);
+aml_append(field, /* read only */
+aml_named_field(stringify(MEMORY_SLOT_ADDR_LOW), 32));
+aml_append(field, /* read only */
+aml_named_field(stringify(MEMORY_SLOT_ADDR_HIGH), 32));
+aml_append(field, /* read only */
+aml_named_field(stringify(MEMORY_SLOT_SIZE_LOW), 32));
+aml_append(field, /* read only */
+aml_named_field(stringify(MEMORY_SLOT_SIZE_HIGH), 32));
+aml_append(field, /* read only */
+aml_named_field(stringify(MEMORY_SLOT_PROXIMITY), 32));
+aml_append(scope, field);
+
+field = aml_field(stringify(MEMORY_HOTPLUG_IO_REGION), aml_byte_acc);
+aml_append(field, aml_reserved_field(160 /* bits, Offset(20) */));
+aml_append(field, /* 1 if enabled, read only */
+aml_named_field(stringify(MEMORY_SLOT_ENABLED), 1));
+aml_append(field,
+/*(read) 1 if has a insert event. (write) 1 to clear event */
+aml_named_field(stringify(MEMORY_SLOT_INSERT_EVENT), 1));
+aml_append(scope, field);
+
+field = aml_field(stringify(MEMORY_HOTPLUG_IO_REGION), aml_dword_acc);
+aml_append(field, /* DIMM selector, write only */
+aml_named_field(stringify(MEMORY_SLOT_SLECTOR), 32));
+aml_append(field, /* _OST event code, write only */
+aml_named_field(stringify(MEMORY_SLOT_OST_EVENT), 32));
+aml_append(field, /* _OST status code, write only */
+aml_named_field(stringify(MEMORY_SLOT_OST_STATUS), 32));
+aml_append(scope, field);
+
+aml_append(sb_scope, scope);
 
 for (i = 0; i < nr_mem; i++) {
 #define BASEPATH "\\_SB.PCI0." stringify(MEMORY_HOTPLUG_DEVICE) "."
diff --git a/hw/i386/acpi-dsdt-mem-hotplug.dsl 
b/hw/i386/acpi-dsdt-mem-hotplug.dsl
index 2a36c47..1e9ec39 100644
--- a/hw/i386/acpi-dsdt-mem-hotplug.dsl
+++ b/hw/i386/acpi-dsdt-mem-hotplug.dsl
@@ -22,14 +22,16 @@
 External(MEMORY_SLOTS_NUMBER, IntObj)
 
 /* Memory hotplug IO registers */
-OperationRegion(MEMORY_HOTPLUG_IO_REGION, SystemIO,
-ACPI_MEMORY_HOTPLUG_BASE,
-

[Qemu-devel] [PATCH v3 48/52] acpi: add acpi_irq_no_flags() term

2015-02-09 Thread Igor Mammedov
Signed-off-by: Igor Mammedov 
---
 hw/acpi/aml-build.c | 21 +
 include/hw/acpi/aml-build.h |  1 +
 2 files changed, 22 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index bfebdb4..3f87d51 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -554,6 +554,27 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t 
max_base,
 return var;
 }
 
+/*
+ * ACPI 1.0b: 6.4.2.1.1 ASL Macro for IRQ Descriptor
+ *
+ * More verbose description at:
+ * ACPI 5.0: 19.5.64 IRQNoFlags (Interrupt Resource Descriptor Macro)
+ *   6.4.2.1 IRQ Descriptor
+ */
+Aml *aml_irq_no_flags(uint8_t irq)
+{
+uint16_t irq_mask;
+Aml *var = aml_alloc();
+
+assert(irq < 16);
+build_append_byte(var->buf, 0x22); /* IRQ descriptor 2 byte form */
+
+irq_mask = 1U << irq;
+build_append_byte(var->buf, irq_mask & 0xFF); /* IRQ mask bits[7:0] */
+build_append_byte(var->buf, irq_mask >> 8); /* IRQ mask bits[15:8] */
+return var;
+}
+
 /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefLEqual */
 Aml *aml_equal(Aml *arg1, Aml *arg2)
 {
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 0f499a6..44cb7ea 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -156,6 +156,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t 
max_base,
 uint8_t aln, uint8_t len);
 Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
   uint32_t offset, uint32_t len);
+Aml *aml_irq_no_flags(uint8_t irq);
 Aml *aml_named_field(const char *name, unsigned length);
 Aml *aml_reserved_field(unsigned length);
 Aml *aml_local(int num);
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 33/52] pc: acpi-build: generate pvpanic device description dynamically

2015-02-09 Thread Igor Mammedov
Drops AML template patching and allows to
save some space in SSDT if pvpanic device doesn't
exist by not including disabled device description
into SSDT. It also makes device description
smaller by replacing _STA method with named value
and dropping _INI method.

Signed-off-by: Igor Mammedov 
---
 hw/i386/acpi-build.c  | 36 
 hw/i386/ssdt-misc.dsl | 47 ---
 2 files changed, 32 insertions(+), 51 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 1e912d1..a86dc42 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -756,7 +756,7 @@ build_ssdt(Aml *table_data,
 uint32_t nr_mem = machine->ram_slots;
 unsigned acpi_cpus = guest_info->apic_id_limit;
 uint8_t *ssdt_ptr;
-Aml *ssdt, *sb_scope, *scope, *pkg;
+Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field;
 int i;
 
 /* The current AML generator can cover the APIC ID range [0..255],
@@ -779,9 +779,6 @@ build_ssdt(Aml *table_data,
 patch_pci_windows(pci, ssdt_ptr, sizeof(ssdp_misc_aml));
 
 ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
-  ssdt_isa_pest[0], 16, misc->pvpanic_port);
-
-ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
   ssdt_mctrl_nr_slots[0], 32, nr_mem);
 
 /*  create S3_ / S4_ / S5_ packages if necessary */
@@ -812,6 +809,37 @@ build_ssdt(Aml *table_data,
 aml_append(scope, aml_name_decl("_S5", pkg));
 aml_append(ssdt, scope);
 
+if (misc->pvpanic_port) {
+scope = aml_scope("\\_SB.PCI0.ISA");
+
+dev = aml_device("PEVR");
+aml_append(dev, aml_name_decl("_HID", aml_string("QEMU0002")));
+
+crs = aml_resource_template();
+aml_append(crs,
+aml_io(aml_decode16, misc->pvpanic_port, misc->pvpanic_port, 1, 1)
+);
+aml_append(dev, aml_name_decl("_CRS", crs));
+
+aml_append(dev, aml_operation_region("PEOR", aml_system_io,
+  misc->pvpanic_port, 1));
+field = aml_field("PEOR", aml_byte_acc);
+aml_append(field, aml_named_field("PEPT", 8));
+aml_append(dev, field);
+
+method = aml_method("RDPT", 0);
+aml_append(method, aml_store(aml_name("PEPT"), aml_local(0)));
+aml_append(method, aml_return(aml_local(0)));
+aml_append(dev, method);
+
+method = aml_method("WRPT", 1);
+aml_append(method, aml_store(aml_arg(0), aml_name("PEPT")));
+aml_append(dev, method);
+
+aml_append(scope, dev);
+aml_append(ssdt, scope);
+}
+
 sb_scope = aml_scope("_SB");
 {
 /* build Processor object for each processor */
diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
index 26b9241..81be858 100644
--- a/hw/i386/ssdt-misc.dsl
+++ b/hw/i386/ssdt-misc.dsl
@@ -39,51 +39,4 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", 
"BXSSDTSUSP", 0x1)
ACPI_EXTRACT_NAME_DWORD_CONST ssdt_mctrl_nr_slots
Name(MEMORY_SLOTS_NUMBER, 0x12345678)
 }
-
-
-External(\_SB.PCI0, DeviceObj)
-External(\_SB.PCI0.ISA, DeviceObj)
-
-Scope(\_SB.PCI0.ISA) {
-Device(PEVT) {
-Name(_HID, "QEMU0001")
-/* PEST will be patched to be Zero if no such device */
-ACPI_EXTRACT_NAME_WORD_CONST ssdt_isa_pest
-Name(PEST, 0x)
-OperationRegion(PEOR, SystemIO, PEST, 0x01)
-Field(PEOR, ByteAcc, NoLock, Preserve) {
-PEPT,   8,
-}
-
-Method(_STA, 0, NotSerialized) {
-Store(PEST, Local0)
-If (LEqual(Local0, Zero)) {
-Return (0x00)
-} Else {
-Return (0x0F)
-}
-}
-
-Method(RDPT, 0, NotSerialized) {
-Store(PEPT, Local0)
-Return (Local0)
-}
-
-Method(WRPT, 1, NotSerialized) {
-Store(Arg0, PEPT)
-}
-
-Name(_CRS, ResourceTemplate() {
-IO(Decode16, 0x00, 0x00, 0x01, 0x01, IO)
-})
-
-CreateWordField(_CRS, IO._MIN, IOMN)
-CreateWordField(_CRS, IO._MAX, IOMX)
-
-Method(_INI, 0, NotSerialized) {
-Store(PEST, IOMN)
-Store(PEST, IOMX)
-}
-}
-}
 }
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 49/52] pc: export applesmc IO port/len

2015-02-09 Thread Igor Mammedov
IO port and length will be used in following patch
to correctly generate SMC ACPI device in SSDT.

Signed-off-by: Igor Mammedov 
---
 hw/i386/acpi-build.c |  2 +-
 hw/misc/applesmc.c   |  5 ++---
 include/hw/isa/isa.h | 11 +--
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 14c1c7d..26076dd 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -144,7 +144,7 @@ static void acpi_get_dsdt(AcpiMiscInfo *info)
 
 /* Patch in appropriate value for AppleSMC _STA */
 *(uint8_t *)(info->dsdt_code + *applesmc_sta) =
-applesmc_find() ? 0x0b : 0x00;
+applesmc_port() ? 0x0b : 0x00;
 }
 
 static
diff --git a/hw/misc/applesmc.c b/hw/misc/applesmc.c
index 6a56b07..6bd61e7 100644
--- a/hw/misc/applesmc.c
+++ b/hw/misc/applesmc.c
@@ -43,7 +43,6 @@
 /* command/status port used by Apple SMC */
 #define APPLESMC_CMD_PORT  0x4
 #define APPLESMC_NR_PORTS  32
-#define APPLESMC_MAX_DATA_LENGTH   32
 
 #define APPLESMC_READ_CMD  0x10
 #define APPLESMC_WRITE_CMD 0x11
@@ -249,8 +248,8 @@ static void applesmc_isa_realize(DeviceState *dev, Error 
**errp)
 }
 
 static Property applesmc_isa_properties[] = {
-DEFINE_PROP_UINT32("iobase", AppleSMCState, iobase,
-  APPLESMC_DEFAULT_IOBASE),
+DEFINE_PROP_UINT32(APPLESMC_PROP_IO_BASE, AppleSMCState, iobase,
+   APPLESMC_DEFAULT_IOBASE),
 DEFINE_PROP_STRING("osk", AppleSMCState, osk),
 DEFINE_PROP_END_OF_LIST(),
 };
diff --git a/include/hw/isa/isa.h b/include/hw/isa/isa.h
index e0c749f..1ee9fa0 100644
--- a/include/hw/isa/isa.h
+++ b/include/hw/isa/isa.h
@@ -21,10 +21,17 @@
 #define ISA_BUS(obj) OBJECT_CHECK(ISABus, (obj), TYPE_ISA_BUS)
 
 #define TYPE_APPLE_SMC "isa-applesmc"
+#define APPLESMC_MAX_DATA_LENGTH   32
+#define APPLESMC_PROP_IO_BASE "iobase"
 
-static inline bool applesmc_find(void)
+static inline uint16_t applesmc_port(void)
 {
-return object_resolve_path_type("", TYPE_APPLE_SMC, NULL);
+Object *obj = object_resolve_path_type("", TYPE_APPLE_SMC, NULL);
+
+if (obj) {
+return object_property_get_int(obj, APPLESMC_PROP_IO_BASE, NULL);
+}
+return 0;
 }
 
 typedef struct ISADeviceClass {
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 50/52] pc: acpi-build: drop template patching and create Device(SMC) dynamically

2015-02-09 Thread Igor Mammedov
patch moves SMC device into SSDT and creates it only
when device is present, which makes ACPI tables smaller
in default case when device is not present.

PS:
also it fixes wrong IO range in CRS if "iobase"
property is set to a not default value.

Signed-off-by: Igor Mammedov 
---
 hw/i386/acpi-build.c  | 29 ++---
 hw/i386/acpi-dsdt-isa.dsl | 11 ---
 hw/i386/acpi-dsdt.dsl |  1 -
 hw/i386/q35-acpi-dsdt.dsl |  1 -
 4 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 26076dd..d564a61 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -115,6 +115,7 @@ typedef struct AcpiMiscInfo {
 const unsigned char *dsdt_code;
 unsigned dsdt_size;
 uint16_t pvpanic_port;
+uint16_t applesmc_io_base;
 } AcpiMiscInfo;
 
 typedef struct AcpiBuildPciBusHotplugState {
@@ -126,7 +127,6 @@ typedef struct AcpiBuildPciBusHotplugState {
 
 static void acpi_get_dsdt(AcpiMiscInfo *info)
 {
-uint16_t *applesmc_sta;
 Object *piix = piix4_pm_find();
 Object *lpc = ich9_lpc_find();
 assert(!!piix != !!lpc);
@@ -134,17 +134,11 @@ static void acpi_get_dsdt(AcpiMiscInfo *info)
 if (piix) {
 info->dsdt_code = AcpiDsdtAmlCode;
 info->dsdt_size = sizeof AcpiDsdtAmlCode;
-applesmc_sta = piix_dsdt_applesmc_sta;
 }
 if (lpc) {
 info->dsdt_code = Q35AcpiDsdtAmlCode;
 info->dsdt_size = sizeof Q35AcpiDsdtAmlCode;
-applesmc_sta = q35_dsdt_applesmc_sta;
 }
-
-/* Patch in appropriate value for AppleSMC _STA */
-*(uint8_t *)(info->dsdt_code + *applesmc_sta) =
-applesmc_port() ? 0x0b : 0x00;
 }
 
 static
@@ -247,6 +241,7 @@ static void acpi_get_misc_info(AcpiMiscInfo *info)
 info->has_hpet = hpet_find();
 info->has_tpm = tpm_find();
 info->pvpanic_port = pvpanic_port();
+info->applesmc_io_base = applesmc_port();
 }
 
 static void acpi_get_pci_info(PcPciInfo *info)
@@ -743,6 +738,26 @@ build_ssdt(Aml *table_data,
 aml_append(scope, aml_name_decl("_S5", pkg));
 aml_append(ssdt, scope);
 
+if (misc->applesmc_io_base) {
+scope = aml_scope("\\_SB.PCI0.ISA");
+dev = aml_device("SMC");
+
+aml_append(dev, aml_name_decl("_HID", aml_eisaid("APP0001")));
+/* device present, functioning, decoding, not shown in UI */
+aml_append(dev, aml_name_decl("_STA", aml_int(0xB)));
+
+crs = aml_resource_template();
+aml_append(crs,
+aml_io(aml_decode16, misc->applesmc_io_base, 
misc->applesmc_io_base,
+   0x01, APPLESMC_MAX_DATA_LENGTH)
+);
+aml_append(crs, aml_irq_no_flags(6));
+aml_append(dev, aml_name_decl("_CRS", crs));
+
+aml_append(scope, dev);
+aml_append(ssdt, scope);
+}
+
 if (misc->pvpanic_port) {
 scope = aml_scope("\\_SB.PCI0.ISA");
 
diff --git a/hw/i386/acpi-dsdt-isa.dsl b/hw/i386/acpi-dsdt-isa.dsl
index deb37de..89caa16 100644
--- a/hw/i386/acpi-dsdt-isa.dsl
+++ b/hw/i386/acpi-dsdt-isa.dsl
@@ -16,17 +16,6 @@
 /* Common legacy ISA style devices. */
 Scope(\_SB.PCI0.ISA) {
 
-Device (SMC) {
-Name(_HID, EisaId("APP0001"))
-/* _STA will be patched to 0x0B if AppleSMC is present */
-ACPI_EXTRACT_NAME_BYTE_CONST DSDT_APPLESMC_STA
-Name(_STA, 0xF0)
-Name(_CRS, ResourceTemplate () {
-IO (Decode16, 0x0300, 0x0300, 0x01, 0x20)
-IRQNoFlags() { 6 }
-})
-}
-
 Device(RTC) {
 Name(_HID, EisaId("PNP0B00"))
 Name(_CRS, ResourceTemplate() {
diff --git a/hw/i386/acpi-dsdt.dsl b/hw/i386/acpi-dsdt.dsl
index 09b68f0..a2d84ec 100644
--- a/hw/i386/acpi-dsdt.dsl
+++ b/hw/i386/acpi-dsdt.dsl
@@ -85,7 +85,6 @@ DefinitionBlock (
 }
 }
 
-#define DSDT_APPLESMC_STA piix_dsdt_applesmc_sta
 #include "acpi-dsdt-isa.dsl"
 
 
diff --git a/hw/i386/q35-acpi-dsdt.dsl b/hw/i386/q35-acpi-dsdt.dsl
index 3fb4b2f..16eaca3 100644
--- a/hw/i386/q35-acpi-dsdt.dsl
+++ b/hw/i386/q35-acpi-dsdt.dsl
@@ -150,7 +150,6 @@ DefinitionBlock (
 }
 }
 
-#define DSDT_APPLESMC_STA q35_dsdt_applesmc_sta
 #include "acpi-dsdt-isa.dsl"
 
 
-- 
1.8.3.1




Re: [Qemu-devel] [Xen-devel] [v2][PATCH] libxl: add one machine property to support IGD GFX passthrough

2015-02-09 Thread Ian Campbell
On Mon, 2015-02-09 at 14:28 +0800, Chen, Tiejun wrote:

> What about this?

I've not read the code in detail,since I'm travelling but from a quick
glance it looks to be implementing the sort of thing I meant, thanks.

A couple of higher level comments:

I'd suggest to put the code for reading the vid/did into a helper
function so it can be reused.

You might like to optionally consider add a forcing option somehow so
that people with new devices not in the list can control things without
the need to recompile (e.g. gfx_passthru_kind_override?). Perhaps that
isn't needed for a first cut though and it would be a libxl API so
thought required.

I think it should probably log something at a lowish level when it has
autodetected IGD.

Ian.




[Qemu-devel] [PATCH v4 0/2] buildsys: Fix and enable module build

2015-02-09 Thread Fam Zheng
v4: Fix patch 1 by:

- Squashing Paolo's patch in reply to v2, to fix static build.

- Fix "pie" check to allow module build on ARM (and hopefully other
  platforms).

- Tested {$DEFAULT,--enable-modules,--disable-modules} on {x86_64, arm}
  hosts. "--static" is not tested because I don't have the static libraries
  on my machine.


Fam Zheng (2):
  configure: Default to enable module build
  .travis.yml: Add "--disable-modules"

 .travis.yml |   2 +-
 configure   | 126 +++-
 2 files changed, 84 insertions(+), 44 deletions(-)

-- 
1.9.3




[Qemu-devel] [PATCH v4 1/2] configure: Default to enable module build

2015-02-09 Thread Fam Zheng
We have module build support around for a while, but also had it bitrot
several times. It probably makes sense to enable it by default so that
people can notice and use it.

Add --disable-modules as a counterpart to --enable-modules, which is
now turned on by default.  If both are omitted, support is guessed as
usual.

pie is now checked for all platforms, because it's depended on by module
build.

Signed-off-by: Fam Zheng 
---
 configure | 126 +-
 1 file changed, 83 insertions(+), 43 deletions(-)

diff --git a/configure b/configure
index f185dd0..803bb2e 100755
--- a/configure
+++ b/configure
@@ -271,7 +271,7 @@ gcov_tool="gcov"
 EXESUF=""
 DSOSUF=".so"
 LDFLAGS_SHARED="-shared"
-modules="no"
+modules=""
 prefix="/usr/local"
 mandir="\${prefix}/share/man"
 datadir="\${prefix}/share"
@@ -768,6 +768,9 @@ for opt do
   --enable-modules)
   modules="yes"
   ;;
+  --disable-modules)
+  modules="no"
+  ;;
   --cpu=*)
   ;;
   --target-list=*) target_list="$optarg"
@@ -1259,7 +1262,8 @@ Advanced options (experts only):
   --sysconfdir=PATHinstall config in PATH$confsuffix
   --localstatedir=PATH install local state in PATH (set at runtime on 
win32)
   --with-confsuffix=SUFFIX suffix for QEMU data inside 
datadir/libdir/sysconfdir [$confsuffix]
-  --enable-modules enable modules support
+  --enable-modules enable modules support (default)
+  --disable-modulesenable modules support
   --enable-debug-tcg   enable TCG debugging
   --disable-debug-tcg  disable TCG debugging (default)
   --enable-debug-info  enable debugging information (default)
@@ -1532,9 +1536,6 @@ if compile_prog "-Werror -fno-gcse" "" ; then
 fi
 
 if test "$static" = "yes" ; then
-  if test "$modules" = "yes" ; then
-error_exit "static and modules are mutually incompatible"
-  fi
   if test "$pie" = "yes" ; then
 error_exit "static and pie are mutually incompatible"
   else
@@ -1542,16 +1543,6 @@ if test "$static" = "yes" ; then
   fi
 fi
 
-if test "$pie" = ""; then
-  case "$cpu-$targetos" in
-i386-Linux|x86_64-Linux|x32-Linux|i386-OpenBSD|x86_64-OpenBSD)
-  ;;
-*)
-  pie="no"
-  ;;
-  esac
-fi
-
 if test "$pie" != "no" ; then
   cat > $TMPC << EOF
 
@@ -2725,22 +2716,25 @@ if test "$mingw32" = yes; then
 else
 glib_req_ver=2.12
 fi
-glib_modules=gthread-2.0
-if test "$modules" = yes; then
-glib_modules="$glib_modules gmodule-2.0"
-fi
 
-for i in $glib_modules; do
-if $pkg_config --atleast-version=$glib_req_ver $i; then
-glib_cflags=`$pkg_config --cflags $i`
-glib_libs=`$pkg_config --libs $i`
-CFLAGS="$glib_cflags $CFLAGS"
-LIBS="$glib_libs $LIBS"
-libs_qga="$glib_libs $libs_qga"
-else
-error_exit "glib-$glib_req_ver $i is required to compile QEMU"
-fi
-done
+glib_pkg_config()
+{
+  if $pkg_config --atleast-version=$glib_req_ver $1; then
+local probe_cflags=$($pkg_config --cflags $1)
+local probe_libs=$($pkg_config --libs $1)
+CFLAGS="$probe_cflags $CFLAGS"
+LIBS="$probe_libs $LIBS"
+libs_qga="$probe_libs $libs_qga"
+glib_cflags="$probe_cflags $glib_cflags"
+glib_libs="$probe_libs $glib_libs"
+return 0
+  else
+return 1
+  fi
+}
+
+glib_pkg_config gthread-2.0 || \
+  error_exit "glib-$glib_req_ver gthread-2.0 is required to compile QEMU"
 
 # g_test_trap_subprocess added in 2.38. Used by some tests.
 glib_subprocess=yes
@@ -2749,19 +2743,65 @@ if ! $pkg_config --atleast-version=2.38 glib-2.0; then
 fi
 
 ##
-# SHA command probe for modules
-if test "$modules" = yes; then
-shacmd_probe="sha1sum sha1 shasum"
-for c in $shacmd_probe; do
-if has $c; then
-shacmd="$c"
-break
-fi
-done
-if test "$shacmd" = ""; then
-error_exit "one of the checksum commands is required to enable 
modules: $shacmd_probe"
-fi
-fi
+# SHA command and gmodule-2.0 probe for modules
+# return 0 if probe succeeds
+# $1: true - force mode, exit if probe fail
+# false - optoinal mode, return 1 if probe fail
+module_try_enable()
+{
+  force=$1
+  if test "$static" = "yes"; then
+if $force; then
+  error_exit "static and modules are mutually incompatible"
+else
+  modules="no"
+  return
+fi
+  fi
+  shacmd_probe="sha1sum sha1 shasum"
+  for c in $shacmd_probe; do
+if has $c; then
+  shacmd="$c"
+  break
+fi
+  done
+  if test "$pie" = "no"; then
+if $force; then
+  error_exit "PIE support is required to enable modules"
+else
+  modules="no"
+  return
+fi
+  fi
+  if test "$shacmd" = ""; then
+if $force; then
+  error_exit "one of the checksum commands is required to enable modules: 
$shacmd_probe"
+else
+  modules="no"
+  return
+fi
+  fi
+  if ! glib_pkg_config gmodule-2.0; then
+if $force; then
+  error_exit "glib-$glib_req_ver 

[Qemu-devel] [PATCH v4 2/2] .travis.yml: Add "--disable-modules"

2015-02-09 Thread Fam Zheng
Now we default to "--enable-modules", let's cover the old way in travis.

Signed-off-by: Fam Zheng 
---
 .travis.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 0ac170b..12bf1db 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -99,5 +99,5 @@ matrix:
   EXTRA_CONFIG="--enable-trace-backends=ust"
   compiler: gcc
 - env: TARGETS=i386-softmmu,x86_64-softmmu
-   EXTRA_CONFIG="--enable-modules"
+   EXTRA_CONFIG="--disable-modules"
   compiler: gcc
-- 
1.9.3




Re: [Qemu-devel] [PATCH v2 1/2] target-mips: Rework ABIs to allow all required configurations

2015-02-09 Thread Leon Alrae
On 11/12/2014 00:21, Maciej W. Rozycki wrote:
> Rework the MIPS ABIs and CPU emulations available according to the 
> following target list:
> 
> - mips|mipsel   -- 32-bit CPUs only, system and user emulation mode, 
>o32 user ABI,
> 
> - mips64|mips64el   -- 32-bit and 64-bit CPUs, system and user emulation 
>mode, o32 user ABI,

I'm not sure if it's a good idea to change the meaning of linux-user
qemu-mips64 and qemu-mips64el, this will cause unnecessary confusion in
my opinion. I think we’d be better off leaving it consistent across QEMU
versions.

Do we really need MIPS64 executables for o32 ABI for linux-user? They
would merely enable MIPS64 CPUs to run o32 programs. So far we've been
handling this by using 32-bit CPUs (artificial if the real CPU don't
exist), therefore I don't see an issue here. Also I'm concerned that
once we add new executables, it will be difficult to revert that change
later, thus we must be certain that this is the right way to go.

In general I would prefer to avoid changing the user interface and pain
related to breaking people's scripts whenever it's possible.

Regards,
Leon




Re: [Qemu-devel] [PATCHv2] Prevent segmentation fault in case of relative resolve of uri

2015-02-09 Thread Paolo Bonzini


On 09/02/2015 11:47, mreza...@redhat.com wrote:
> From: Miroslav Rezanina 
> 
> It was possible to call strcmp with NULL argument, that can cause
> segmentation fault. Properly checking parameters to prevent this
> situation.
> 
> Signed-off-by: Miroslav Rezanina 
> ---
> v2:
>  - instead of adding NULL checks to strcmp call refactor whole
>NULL checking path. This will remove dead code and make whole checking
>easier to understand.
> 
>Relative path generation part is not touched as I'm not fully sure
>of correct behavior and purpose of this patch is to prevent segmentation
>fault.
> ---
>  util/uri.c | 55 +--
>  1 file changed, 25 insertions(+), 30 deletions(-)
> 
> diff --git a/util/uri.c b/util/uri.c
> index 918d235..23dbaca 100644
> --- a/util/uri.c
> +++ b/util/uri.c
> @@ -1964,44 +1964,39 @@ uri_resolve_relative (const char *uri, const char * 
> base)
>   * If the scheme / server on the URI differs from the base,
>   * just return the URI
>   */
> -if ((ref->scheme != NULL) &&
> - ((bas->scheme == NULL) ||
> -  (strcmp (bas->scheme, ref->scheme)) ||
> -  (strcmp (bas->server, ref->server {
> - val = g_strdup (uri);
> - goto done;
> +
> +if ((ref->scheme != NULL) && 
> +((bas->scheme == NULL) || (strcmp (bas->scheme, ref->scheme {
> +val = g_strdup(uri);
> +goto done;
>  }
> -if (!strcmp(bas->path, ref->path)) {
> - val = g_strdup("");
> - goto done;
> -}
> -if (bas->path == NULL) {
> - val = g_strdup(ref->path);
> - goto done;
> +if ((ref->server != NULL) &&
> +((bas->server == NULL) || (strcmp (bas->server, ref->server {
> +val = g_strdup(uri);
> +goto done;
>  }
> +
>  if (ref->path == NULL) {
>  ref->path = (char *) "/";
> - remove_path = 1;
> +remove_path = 1;
>  }
>  
> -/*
> - * At this point (at last!) we can compare the two paths
> - *
> - * First we take care of the special case where either of the
> - * two path components may be missing (bug 316224)
> - */
>  if (bas->path == NULL) {
> - if (ref->path != NULL) {
> - uptr = ref->path;
> - if (*uptr == '/')
> - uptr++;
> - /* exception characters from uri_to_string */
> - val = uri_string_escape(uptr, "/;&=+$,");
> - }
> - goto done;
> +uptr = ref->path;
> +if (*uptr == '/')
> +uptr++;
> +/* exception characters from uri_to_string */
> +val = uri_string_escape(uptr, "/;&=+$,");
> +goto done;
>  }
> +
> +if (!strcmp(bas->path, ref->path)) {
> +val = g_strdup("");
> +goto done;
> +}
> +
>  bptr = bas->path;
> -if (ref->path == NULL) {
> +if (remove_path == 1) {
>   for (ix = 0; bptr[ix] != 0; ix++) {
>   if (bptr[ix] == '/')
>   nbslash++;
> @@ -2010,7 +2005,7 @@ uri_resolve_relative (const char *uri, const char * 
> base)
>   len = 1;/* this is for a string terminator only */
>  } else {
>  /*
> - * Next we compare the two strings and find where they first differ
> + * We compare the two strings and find where they first differ
>   */
>   if ((ref->path[pos] == '.') && (ref->path[pos+1] == '/'))
>  pos += 2;
> 

It's the third time a fix for this is submitted. :)

[PATCH 3/3] util/uri: URI member path can be null, compare more carfully
(by Markus)

[PATCH 3/7] uri: avoid NULL arguments to strcmp
(by me).

Markus's patch was accepted.  Further cleanups on the code on top of his
patch are welcome, though.

The logic for "compare two possibly-NULL strings" could be replaced by
g_strcmp0, but that's only provided by glib versions 2.16 or newer,
while we support 2.12.

Paolo



Re: [Qemu-devel] [PATCH] linux-user: correct stat structure in MIPS N32

2015-02-09 Thread James Hogan
Hi Leon,

On 30/01/15 15:08, Leon Alrae wrote:
> Simple "hello world" MIPS N32 userland program crashes with segfault due to
> incorrectly defined stat structure in QEMU.
> 
> Correct "target_stat" definition to match kernel's "stat64" as in MIPS N32
> there are only plain "stat" syscalls using 64-bit structure.
> 
> Reported-by: Daniel Sanders 
> Signed-off-by: Leon Alrae 
> Tested-by: Daniel Sanders 

Reviewed-by: James Hogan 

Cheers
James

> ---
>  linux-user/syscall_defs.h | 86 
> +++
>  1 file changed, 19 insertions(+), 67 deletions(-)
> 
> diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
> index ebb3be1..0fc4317 100644
> --- a/linux-user/syscall_defs.h
> +++ b/linux-user/syscall_defs.h
> @@ -1600,73 +1600,25 @@ struct target_stat {
>  #elif defined(TARGET_ABI_MIPSN32)
>  
>  struct target_stat {
> - unsignedst_dev;
> - int st_pad1[3]; /* Reserved for network id */
> - unsigned intst_ino;
> - unsigned intst_mode;
> - unsigned intst_nlink;
> - int st_uid;
> - int st_gid;
> - unsignedst_rdev;
> - unsigned intst_pad2[2];
> - unsigned intst_size;
> - unsigned intst_pad3;
> - /*
> -  * Actually this should be timestruc_t st_atime, st_mtime and st_ctime
> -  * but we don't have it under Linux.
> -  */
> - unsigned inttarget_st_atime;
> - unsigned inttarget_st_atime_nsec;
> - unsigned inttarget_st_mtime;
> - unsigned inttarget_st_mtime_nsec;
> - unsigned inttarget_st_ctime;
> - unsigned inttarget_st_ctime_nsec;
> - unsigned intst_blksize;
> - unsigned intst_blocks;
> - unsigned intst_pad4[14];
> -};
> -
> -/*
> - * This matches struct stat64 in glibc2.1, hence the absolutely insane
> - * amounts of padding around dev_t's.  The memory layout is the same as of
> - * struct stat of the 64-bit kernel.
> - */
> -
> -#define TARGET_HAS_STRUCT_STAT64
> -struct target_stat64 {
> - unsigned intst_dev;
> - unsigned intst_pad0[3]; /* Reserved for st_dev expansion  */
> -
> - target_ulongst_ino;
> -
> -unsigned int st_mode;
> -unsigned int st_nlink;
> -
> - int st_uid;
> - int st_gid;
> -
> - unsigned intst_rdev;
> - unsigned intst_pad1[3]; /* Reserved for st_rdev expansion  */
> -
> - int st_size;
> -
> - /*
> -  * Actually this should be timestruc_t st_atime, st_mtime and st_ctime
> -  * but we don't have it under Linux.
> -  */
> - int target_st_atime;
> - unsigned inttarget_st_atime_nsec;   /* Reserved for st_atime 
> expansion  */
> -
> - int target_st_mtime;
> - unsigned inttarget_st_mtime_nsec;   /* Reserved for st_mtime 
> expansion  */
> -
> - int target_st_ctime;
> - unsigned inttarget_st_ctime_nsec;   /* Reserved for st_ctime 
> expansion  */
> -
> - unsigned intst_blksize;
> - unsigned intst_pad2;
> -
> - int st_blocks;
> +abi_ulongst_dev;
> +abi_ulongst_pad0[3]; /* Reserved for st_dev expansion */
> +uint64_t st_ino;
> +unsigned int st_mode;
> +unsigned int st_nlink;
> +int  st_uid;
> +int  st_gid;
> +abi_ulongst_rdev;
> +abi_ulongst_pad1[3]; /* Reserved for st_rdev expansion */
> +int64_t  st_size;
> +abi_long target_st_atime;
> +abi_ulongtarget_st_atime_nsec; /* Reserved for st_atime 
> expansion */
> +abi_long target_st_mtime;
> +abi_ulongtarget_st_mtime_nsec; /* Reserved for st_mtime 
> expansion */
> +abi_long target_st_ctime;
> +abi_ulongtarget_st_ctime_nsec; /* Reserved for st_ctime 
> expansion */
> +abi_ulongst_blksize;
> +abi_ulongst_pad2;
> +int64_t  st_blocks;
>  };
>  
>  #elif defined(TARGET_ABI_MIPSO32)
> 



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [RFC PATCH v8 20/21] replay: command line options

2015-02-09 Thread Pavel Dovgaluk
> From: Paolo Bonzini [mailto:pbonz...@redhat.com]
> On 22/01/2015 09:53, Pavel Dovgalyuk wrote:
> > This patch introduces command line options for enabling recording or 
> > replaying
> > virtual machine behavior. "-record" option starts recording of the execution
> > and saves it into the log, specified with "fname" parameter. "-replay" 
> > option
> > is intended for replaying previously saved log.
> >
> > Signed-off-by: Pavel Dovgalyuk 
> >  break;
> >  case QEMU_OPTION_snapshot:
> >  snapshot = 1;
> > @@ -3105,6 +3114,7 @@ int main(int argc, char **argv, char **envp)
> >  #endif
> >  case QEMU_OPTION_bt:
> >  add_device_config(DEV_BT, optarg);
> > +not_compatible_replay_param++;
> 
> Could it be enough to add a migration blocker?

Record/replay core does not use migration subsystem.
That is why it should check the hardware by itself.

> 
> >  break;
> >  case QEMU_OPTION_audio_help:
> >  AUD_help ();
> > @@ -3244,6 +3254,7 @@ int main(int argc, char **argv, char **envp)
> >  if (!opts) {
> >  exit(1);
> >  }
> > +not_compatible_replay_param++;
> 
> Why not compatible?

Replay for audio adapter will be added in latter patches.
Trying to record/replay machine with audio using current
set of patches will break the replay.

Pavel Dovgalyuk




Re: [Qemu-devel] [Qemu-trivial] [PATCH 0/7] Six coverity fixes and a cleanup

2015-02-09 Thread Juan Quintela
Paolo Bonzini  wrote:
> On 07/02/2015 10:00, Michael Tokarev wrote:
>>> > Patch 2 is the cleanup.  The other six patches make the tcg, utils and
>>> > migration components clean.
>> Applied to -trivial patches 1,2,3,4 and 6, not applied 5 (due to
>> questionable errno checking addition) and 7, due to a discussion.
>
> Thanks, will resubmit 5.
>
> Juan/Amit, can you pick up 7 which Juan has already reviewed?

I pick 7.

Thanks, Juan.



[Qemu-devel] [PATCH] checkpatch: port fix from kernel "## is not a valid modifier"

2015-02-09 Thread Christian Borntraeger
From: Andy Whitcroft 

checkpatch currently loops on fpu/softfloat.c
Turns out this is fixed in the Linux version of checkpatch.

So this is a port of Andy Whitcrofts fix from Linux,
Original commit was commit 89a883530fe7 ("checkpatch: ## is not a
valid modifier")

Cc: Andy Whitcroft 
Signed-off-by: Christian Borntraeger 
---
 scripts/checkpatch.pl | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 5df61f9..8635f4c 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1061,7 +1061,9 @@ sub possible {
case|
else|
asm|__asm__|
-   do
+   do|
+   \#|
+   \#\#|
)(?:\s|$)|
^(?:typedef|struct|enum)\b
)}x;
-- 
1.9.3




Re: [Qemu-devel] [RFC PATCH v8 20/21] replay: command line options

2015-02-09 Thread Paolo Bonzini


On 09/02/2015 13:15, Pavel Dovgaluk wrote:
>> From: Paolo Bonzini [mailto:pbonz...@redhat.com]
>> On 22/01/2015 09:53, Pavel Dovgalyuk wrote:
>>> This patch introduces command line options for enabling recording or 
>>> replaying
>>> virtual machine behavior. "-record" option starts recording of the execution
>>> and saves it into the log, specified with "fname" parameter. "-replay" 
>>> option
>>> is intended for replaying previously saved log.
>>>
>>> Signed-off-by: Pavel Dovgalyuk 
>>>  break;
>>>  case QEMU_OPTION_snapshot:
>>>  snapshot = 1;
>>> @@ -3105,6 +3114,7 @@ int main(int argc, char **argv, char **envp)
>>>  #endif
>>>  case QEMU_OPTION_bt:
>>>  add_device_config(DEV_BT, optarg);
>>> +not_compatible_replay_param++;
>>
>> Could it be enough to add a migration blocker?
> 
> Record/replay core does not use migration subsystem.
> That is why it should check the hardware by itself.

Right.  But is there anything that supports migration but not replay?
If the two overlap, you can just check migration blockers to see if
record/replay can be allowed.

>>
>>>  break;
>>>  case QEMU_OPTION_audio_help:
>>>  AUD_help ();
>>> @@ -3244,6 +3254,7 @@ int main(int argc, char **argv, char **envp)
>>>  if (!opts) {
>>>  exit(1);
>>>  }
>>> +not_compatible_replay_param++;
>>
>> Why not compatible?
> 
> Replay for audio adapter will be added in latter patches.
> Trying to record/replay machine with audio using current
> set of patches will break the replay.

For this case you can try adding a mechanism similar to migration
blockers (replay blockers).

Paolo



Re: [Qemu-devel] [PATCH v2 1/3] nbd: Drop BDS backpointer

2015-02-09 Thread Paolo Bonzini


On 06/02/2015 22:06, Max Reitz wrote:
> @@ -889,7 +889,7 @@ void nbd_client_put(NBDClient *client)
>  }
>  }
>  
> -void nbd_client_close(NBDClient *client)
> +static void client_close(NBDClient *client)
>  {
>  if (client->closing) {
>  return;

Probably NBDClient should be renamed to NBDServerSession.  Can be done
on top.

Reviewed-by: Paolo Bonzini 

Paolo



Re: [Qemu-devel] [PATCH 2/2] openpic: convert to vmstate

2015-02-09 Thread Juan Quintela
Mark Cave-Ayland  wrote:
> Signed-off-by: Mark Cave-Ayland 
> ---
>  hw/intc/openpic.c |  253 
> +
>  1 file changed, 119 insertions(+), 134 deletions(-)
>

> +static const VMStateDescription vmstate_openpic_irq_queue = {
> +.name = "openpic_irq_queue",
> +.version_id = 0,
> +.minimum_version_id = 0,
> +.fields = (VMStateField[]) {
> +VMSTATE_BITMAP(queue, IRQQueue, 0, queue_size),

Can I assume that this layout is compatible with the one given by:

-for (i = 0; i < BITS_TO_LONGS(IRQQUEUE_SIZE_BITS); i++) {
-/* Always put the lower half of a 64-bit long first, in case we
- * restore on a 32-bit host.  The least significant bits correspond
- * to lower IRQ numbers in the bitmap.
- */
-qemu_put_be32(f, (uint32_t)q->queue[i]);
-#if LONG_MAX > 0x7FFF
-qemu_put_be32(f, (uint32_t)(q->queue[i] >> 32));
-#endif
-}


> +VMSTATE_INT32(next, IRQQueue),
> +VMSTATE_INT32(priority, IRQQueue),
> +VMSTATE_END_OF_LIST()
> +}
> +};
> +
> +static const VMStateDescription vmstate_openpic_irqdest = {
> +.name = "openpic_irqdest",
> +.version_id = 0,
> +.minimum_version_id = 0,
> +.fields = (VMStateField[]) {
> +VMSTATE_INT32(ctpr, IRQDest),
> +VMSTATE_STRUCT(raised, IRQDest, 0, vmstate_openpic_irq_queue,
> +   IRQQueue),
> +VMSTATE_STRUCT(servicing, IRQDest, 0, vmstate_openpic_irq_queue,
> +   IRQQueue),
> +VMSTATE_UINT32_ARRAY(outputs_active, IRQDest, OPENPIC_OUTPUT_NB),

This change would make big/little endian migration unhappy. (no, I don't
know if it is more correct the new or the old code, just that they give
different results).

> +VMSTATE_END_OF_LIST()
> +}
> +};

> +static const VMStateDescription vmstate_openpic = {
> +.name = "openpic",
   .version_id = 2,
   .minimum_version_id = 2
> +.post_load = openpic_post_load,
> +.fields = (VMStateField[]) {
> +VMSTATE_UINT32(gcr, OpenPICState),
> +VMSTATE_UINT32(vir, OpenPICState),
> +VMSTATE_UINT32(pir, OpenPICState),
> +VMSTATE_UINT32(spve, OpenPICState),
> +VMSTATE_UINT32(tfrr, OpenPICState),
> +VMSTATE_UINT32(max_irq, OpenPICState),

   VMSTATE_UINT32_EQUAL(nb_cpus, OpenPICState),

   VMSTATE_STRUCT_VARRAY_UINT32(dst, OpenPICState, nb_cpus, 0,
vmstate_openpic_irqdest, IRQDest),

   VMSTATE_STRUCT_ARRAY(timers, OpenPICState, OPENPIC_MAX_TMR, 0,
vmstate_openpic_timer, OpenPICTimer),

   VMSTATE_STRUCT_VARRAY_UINT32(src, OpenPICState, max_irq, 0,
vmstate_openpic_irqsource, IRQSource),
> +VMSTATE_END_OF_LIST()
> +}
> +};

If you do this changes, this should get the v2 format working, right?
Notice the two questions that I asked above, if that is true, we can go
from here making the change compatible.

If so, we could go from here about ading the following ones with a
subsection or so.


> +VMSTATE_STRUCT_ARRAY(msi, OpenPICState, MAX_MSI, 0,
> + vmstate_openpic_msi, OpenPICMSI),
> +VMSTATE_UINT32(irq_ipi0, OpenPICState),
> +VMSTATE_UINT32(irq_tim0, OpenPICState),
> +VMSTATE_UINT32(irq_msi, OpenPICState),
> +VMSTATE_END_OF_LIST()
> +}
> +};

If this is only used when MSI is used, and there is a check for that, we
could use a new subsection.  If it always used, we should change format
version to three.

Anyways, spliting this patch in two would make clear what is the
equivalent of the old code and what is new.

What do you think?

Later, Juan.



Re: [Qemu-devel] [Qemu-ppc] [PATCH 2/2] openpic: convert to vmstate

2015-02-09 Thread Alexander Graf


On 09.02.15 13:39, Juan Quintela wrote:
> Mark Cave-Ayland  wrote:
>> Signed-off-by: Mark Cave-Ayland 
>> ---
>>  hw/intc/openpic.c |  253 
>> +
>>  1 file changed, 119 insertions(+), 134 deletions(-)
>>
> 
>> +static const VMStateDescription vmstate_openpic_irq_queue = {
>> +.name = "openpic_irq_queue",
>> +.version_id = 0,
>> +.minimum_version_id = 0,
>> +.fields = (VMStateField[]) {
>> +VMSTATE_BITMAP(queue, IRQQueue, 0, queue_size),
> 
> Can I assume that this layout is compatible with the one given by:
> 
> -for (i = 0; i < BITS_TO_LONGS(IRQQUEUE_SIZE_BITS); i++) {
> -/* Always put the lower half of a 64-bit long first, in case we
> - * restore on a 32-bit host.  The least significant bits correspond
> - * to lower IRQ numbers in the bitmap.
> - */
> -qemu_put_be32(f, (uint32_t)q->queue[i]);
> -#if LONG_MAX > 0x7FFF
> -qemu_put_be32(f, (uint32_t)(q->queue[i] >> 32));
> -#endif
> -}
> 
> 
>> +VMSTATE_INT32(next, IRQQueue),
>> +VMSTATE_INT32(priority, IRQQueue),
>> +VMSTATE_END_OF_LIST()
>> +}
>> +};
>> +
>> +static const VMStateDescription vmstate_openpic_irqdest = {
>> +.name = "openpic_irqdest",
>> +.version_id = 0,
>> +.minimum_version_id = 0,
>> +.fields = (VMStateField[]) {
>> +VMSTATE_INT32(ctpr, IRQDest),
>> +VMSTATE_STRUCT(raised, IRQDest, 0, vmstate_openpic_irq_queue,
>> +   IRQQueue),
>> +VMSTATE_STRUCT(servicing, IRQDest, 0, vmstate_openpic_irq_queue,
>> +   IRQQueue),
>> +VMSTATE_UINT32_ARRAY(outputs_active, IRQDest, OPENPIC_OUTPUT_NB),
> 
> This change would make big/little endian migration unhappy. (no, I don't
> know if it is more correct the new or the old code, just that they give
> different results).
> 
>> +VMSTATE_END_OF_LIST()
>> +}
>> +};
> 
>> +static const VMStateDescription vmstate_openpic = {
>> +.name = "openpic",
>.version_id = 2,
>.minimum_version_id = 2
>> +.post_load = openpic_post_load,
>> +.fields = (VMStateField[]) {
>> +VMSTATE_UINT32(gcr, OpenPICState),
>> +VMSTATE_UINT32(vir, OpenPICState),
>> +VMSTATE_UINT32(pir, OpenPICState),
>> +VMSTATE_UINT32(spve, OpenPICState),
>> +VMSTATE_UINT32(tfrr, OpenPICState),
>> +VMSTATE_UINT32(max_irq, OpenPICState),
> 
>VMSTATE_UINT32_EQUAL(nb_cpus, OpenPICState),
> 
>VMSTATE_STRUCT_VARRAY_UINT32(dst, OpenPICState, nb_cpus, 0,
> vmstate_openpic_irqdest, IRQDest),
> 
>VMSTATE_STRUCT_ARRAY(timers, OpenPICState, OPENPIC_MAX_TMR, 0,
> vmstate_openpic_timer, OpenPICTimer),
> 
>VMSTATE_STRUCT_VARRAY_UINT32(src, OpenPICState, max_irq, 0,
> vmstate_openpic_irqsource, IRQSource),
>> +VMSTATE_END_OF_LIST()
>> +}
>> +};
> 
> If you do this changes, this should get the v2 format working, right?
> Notice the two questions that I asked above, if that is true, we can go
> from here making the change compatible.
> 
> If so, we could go from here about ading the following ones with a
> subsection or so.
> 
> 
>> +VMSTATE_STRUCT_ARRAY(msi, OpenPICState, MAX_MSI, 0,
>> + vmstate_openpic_msi, OpenPICMSI),
>> +VMSTATE_UINT32(irq_ipi0, OpenPICState),
>> +VMSTATE_UINT32(irq_tim0, OpenPICState),
>> +VMSTATE_UINT32(irq_msi, OpenPICState),
>> +VMSTATE_END_OF_LIST()
>> +}
>> +};
> 
> If this is only used when MSI is used, and there is a check for that, we
> could use a new subsection.  If it always used, we should change format
> version to three.

Yes, please, just bump the version number and ignore all the legacy
cruft. OpenPIC state saving is broken for years, any old state that we
could potentially save is not usable anyway :)


Alex

> 
> Anyways, spliting this patch in two would make clear what is the
> equivalent of the old code and what is new.
> 
> What do you think?
> 
> Later, Juan.
> 



  1   2   3   4   >