All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups
@ 2015-02-18 21:43 Michael S. Tsirkin
  2015-02-18 21:44 ` [Qemu-devel] [PULL 01/96] acpi-build: fix memory leak with bridge hp off Michael S. Tsirkin
                   ` (98 more replies)
  0 siblings, 99 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, dgilbert, Juan Quintela

A huge patchset, but the scariest part is Igor's patches,
and these have been used by multiple people by now.
virtio header change is a bit rushed, but getting them upstream
seems like the best way to give them the cross-platform
testing that they need, and this takes us a step closer to
virtio-1.0 support.

The following changes since commit cd2d5541271f1934345d8ca42f5fafff1744eee7:

  Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20150212' into staging (2015-02-13 11:44:50 +0000)

are available in the git repository at:

  git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream

for you to fetch changes up to 6b5e5a8361bdff0e75629b1001236d78f27676b6:

  acpi-test: update expected files (2015-02-18 22:29:26 +0100)

----------------------------------------------------------------
pci, pc, virtio fixes and cleanups

Last large pull for soft freeze.

A bunch of fixes all over the place.
Most of ACPI refactoring has been merged.

virtio header cleanup has been merged,
now that windows has been build-tested with it.

initial patches from virtio-1.0 branch have been merged.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

----------------------------------------------------------------
Cornelia Huck (3):
      virtio: cull virtio_bus_set_vdev_features
      virtio: feature bit manipulation helpers
      virtio: add feature checking helpers

Igor Mammedov (43):
      acpi: move generic aml building helpers into dedictated file
      acpi: add build_append_namestring() helper
      acpi: drop min-bytes in build_package()
      pc: acpi-build: update linker on guest access
      pc: acpi-build: migrate RSDP table
      pc: acpi: use local var for accessing ACPI tables blob in acpi_build()
      acpi: introduce AML composer aml_append()
      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: 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
      acpi: add aml_package() term
      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: acpi-build: drop template patching and memory hotplug objects dynamically
      pc: acpi-build: create memory hotplug IO region dynamically
      acpi: add aml_word_bus_number(), aml_word_io(), aml_dword_memory(), aml_qword_memory() terms
      pc: pcihp: expose MMIO base and len as properties
      pc: acpi-build: reserve PCIHP MMIO resources

Markus Armbruster (11):
      pci: Convert core to realize
      pci: Permit incremental conversion of device models to realize
      pci: Trivial device model conversions to realize
      pcnet: pcnet_common_init() always returns 0, change to void
      pcnet: Convert to realize
      serial-pci: Convert to realize
      ide/ich: Convert to realize
      cirrus-vga: Convert to realize
      qxl: Convert to realize
      pci-assign: Convert to realize
      qdev: Don't exit when running into bad -global

Michael S. Tsirkin (32):
      acpi-build: fix memory leak with bridge hp off
      bios linker: validate pointer within table
      acpi: update RSDP on guest access
      exec: round up size on MR resize
      acpi-build: fix ACPI RAM management
      acpi: has_immutable_rsdp->!rsdp_in_ram
      acpi-build: simplify rsdp management for legacy
      scripts/update-linux-headers.sh: pull virtio hdrs
      include: import virtio headers from linux 4.0
      virtio: use standard virtio_ring.h
      virtio: use standard-headers
      virtio-balloon: use standard headers
      virtio-9p: use standard headers
      virtio-blk: switch to standard-headers
      virtio-net,tap: use standard-headers
      virtio-rng: use standard-headers
      virtio-scsi: use standard-headers
      virtio-serial: switch to standard-headers
      update-linux-headers: use standard-headers
      linux-headers: use standard-headers
      virtio-pci: use standard headers
      scripts: add arch specific standard-headers
      standard-headers: add s390 virtio headers
      s390: use standard headers
      acpi-build: skip hotplugged bridges
      update-linux-headers.sh: s/__inline__/inline/
      virtio-serial-bus.c: drop virtio_ids.h
      standard-headers: include stdint.h
      virtio_ring.h: s/__inline__/inline/
      acpi: update generated hex files
      acpi: drop unused generated files
      acpi-test: update expected files

Peter Krempa (2):
      vl.c: Fix error messages when parsing maxmem parameters
      pc: memory: Validate alignment of maxram_size to page size

Tang Chen (5):
      acpi, pc: Add hotunplug request cb for pc machine.
      acpi, ich9: Add hotunplug request cb for ich9.
      acpi, pc: Add unplug cb for pc machine.
      acpi, ich9: Add unplug cb for ich9.
      acpi, piix4: Add unplug cb for piix4.

 hw/9pfs/virtio-9p.h                                |  18 +-
 hw/net/pcnet.h                                     |   2 +-
 hw/s390x/s390-virtio-bus.h                         |  36 +-
 hw/s390x/s390-virtio.h                             |   7 +-
 include/hw/acpi/aml-build.h                        | 206 +++++
 include/hw/acpi/ich9.h                             |   4 +
 include/hw/acpi/pc-hotplug.h                       |   1 +
 include/hw/acpi/pcihp.h                            |   7 +-
 include/hw/i386/pc.h                               |   1 +
 include/hw/pci/pci.h                               |   3 +-
 include/hw/qdev-properties.h                       |   4 +-
 include/hw/virtio/dataplane/vring.h                |   2 +-
 include/hw/virtio/virtio-balloon.h                 |  35 +-
 include/hw/virtio/virtio-blk.h                     |  77 +-
 include/hw/virtio/virtio-bus.h                     |   3 -
 include/hw/virtio/virtio-net.h                     | 151 +---
 include/hw/virtio/virtio-rng.h                     |   4 +-
 include/hw/virtio/virtio-scsi.h                    | 120 +--
 include/hw/virtio/virtio-serial.h                  |  40 +-
 include/hw/virtio/virtio.h                         |  71 +-
 include/net/tap.h                                  |  24 +-
 include/standard-headers/asm-s390/kvm_virtio.h     |  64 ++
 include/standard-headers/asm-s390/virtio-ccw.h     |  21 +
 include/standard-headers/linux/if_ether.h          |   1 +
 include/standard-headers/linux/types.h             |   2 +
 include/standard-headers/linux/virtio_9p.h         |  44 ++
 include/standard-headers/linux/virtio_balloon.h    |  59 ++
 include/standard-headers/linux/virtio_blk.h        | 143 ++++
 include/standard-headers/linux/virtio_config.h     |  64 ++
 include/standard-headers/linux/virtio_console.h    |  78 ++
 include/standard-headers/linux/virtio_ids.h        |  43 +
 include/standard-headers/linux/virtio_net.h        | 233 ++++++
 include/standard-headers/linux/virtio_pci.h        | 193 +++++
 .../linux}/virtio_ring.h                           | 132 ++--
 include/standard-headers/linux/virtio_rng.h        |   8 +
 include/standard-headers/linux/virtio_scsi.h       | 164 ++++
 include/standard-headers/linux/virtio_types.h      |  46 ++
 linux-headers/linux/virtio_config.h                |  58 +-
 linux-headers/linux/virtio_ring.h                  | 164 +---
 exec.c                                             |   2 +
 hw/9pfs/virtio-9p-device.c                         |   2 +-
 hw/acpi/aml-build.c                                | 867 +++++++++++++++++++++
 hw/acpi/bios-linker-loader.c                       |   4 +-
 hw/acpi/ich9.c                                     |  14 +
 hw/acpi/pcihp.c                                    |  18 +-
 hw/acpi/piix4.c                                    |  15 +-
 hw/audio/ac97.c                                    |   5 +-
 hw/audio/es1370.c                                  |   5 +-
 hw/audio/intel-hda.c                               |   6 +-
 hw/block/virtio-blk.c                              |  31 +-
 hw/char/serial-pci.c                               |  22 +-
 hw/char/virtio-serial-bus.c                        |   4 +-
 hw/core/qdev-properties.c                          |  21 +-
 hw/core/qdev.c                                     |   8 +-
 hw/display/cirrus_vga.c                            |  11 +-
 hw/display/qxl.c                                   |  36 +-
 hw/display/vga-pci.c                               |  11 +-
 hw/display/vmware_vga.c                            |   6 +-
 hw/i2c/smbus_ich9.c                                |   5 +-
 hw/i386/acpi-build.c                               | 750 +++++++++---------
 hw/i386/kvm/pci-assign.c                           |  10 +-
 hw/i386/pc.c                                       |  23 +
 hw/i386/pc_piix.c                                  |   3 +
 hw/i386/pc_q35.c                                   |   3 +
 hw/ide/cmd646.c                                    |   5 +-
 hw/ide/ich.c                                       |  13 +-
 hw/ide/piix.c                                      |  10 +-
 hw/ide/via.c                                       |   6 +-
 hw/ipack/tpci200.c                                 |   6 +-
 hw/isa/i82378.c                                    |   6 +-
 hw/isa/lpc_ich9.c                                  |  14 +-
 hw/isa/piix4.c                                     |   5 +-
 hw/isa/vt82c686.c                                  |  24 +-
 hw/misc/pci-testdev.c                              |   6 +-
 hw/net/e1000.c                                     |   6 +-
 hw/net/eepro100.c                                  |   6 +-
 hw/net/lance.c                                     |   3 +-
 hw/net/ne2000.c                                    |   6 +-
 hw/net/pcnet-pci.c                                 |   6 +-
 hw/net/pcnet.c                                     |   4 +-
 hw/net/rtl8139.c                                   |   6 +-
 hw/net/vhost_net.c                                 |   2 +-
 hw/net/virtio-net.c                                |  57 +-
 hw/net/vmxnet3.c                                   |   6 +-
 hw/pci-bridge/dec.c                                |   5 +-
 hw/pci-host/apb.c                                  |   5 +-
 hw/pci-host/bonito.c                               |   6 +-
 hw/pci-host/grackle.c                              |   5 +-
 hw/pci-host/piix.c                                 |  12 +-
 hw/pci-host/ppce500.c                              |   6 +-
 hw/pci-host/prep.c                                 |   6 +-
 hw/pci-host/q35.c                                  |   5 +-
 hw/pci-host/uninorth.c                             |  20 +-
 hw/pci-host/versatile.c                            |   5 +-
 hw/pci/pci.c                                       | 113 +--
 hw/s390x/virtio-ccw.c                              |   7 +-
 hw/scsi/virtio-scsi.c                              |   9 +-
 hw/sd/sdhci.c                                      |   5 +-
 hw/usb/hcd-ehci-pci.c                              |   6 +-
 hw/usb/hcd-xhci.c                                  |   6 +-
 hw/virtio/dataplane/vring.c                        |  10 +-
 hw/virtio/virtio-balloon.c                         |   2 +-
 hw/virtio/virtio-bus.c                             |  14 -
 hw/virtio/virtio-mmio.c                            |   2 +-
 hw/virtio/virtio-pci.c                             |  58 +-
 hw/virtio/virtio.c                                 |  33 +-
 hw/watchdog/wdt_i6300esb.c                         |   6 +-
 vl.c                                               |  34 +-
 hw/acpi/Makefile.objs                              |   1 +
 hw/i386/Makefile.objs                              |   6 +-
 hw/i386/acpi-dsdt-cpu-hotplug.dsl                  |  17 +-
 hw/i386/acpi-dsdt-mem-hotplug.dsl                  |  36 +-
 hw/i386/acpi-dsdt.hex.generated                    | 224 +-----
 hw/i386/q35-acpi-dsdt.hex.generated                | 224 +-----
 hw/i386/ssdt-mem.dsl                               |  77 --
 hw/i386/ssdt-mem.hex.generated                     | 213 -----
 hw/i386/ssdt-misc.dsl                              |  82 --
 hw/i386/ssdt-misc.hex.generated                    | 274 +------
 hw/i386/ssdt-proc.dsl                              |  63 --
 hw/i386/ssdt-proc.hex.generated                    | 134 ----
 scripts/update-linux-headers.sh                    |  52 +-
 tests/acpi-test-data/pc/DSDT                       | Bin 3621 -> 3415 bytes
 tests/acpi-test-data/pc/SSDT                       | Bin 2279 -> 2374 bytes
 tests/acpi-test-data/q35/DSDT                      | Bin 8211 -> 8005 bytes
 tests/acpi-test-data/q35/SSDT                      | Bin 560 -> 578 bytes
 125 files changed, 3236 insertions(+), 2959 deletions(-)
 create mode 100644 include/hw/acpi/aml-build.h
 create mode 100644 include/standard-headers/asm-s390/kvm_virtio.h
 create mode 100644 include/standard-headers/asm-s390/virtio-ccw.h
 create mode 100644 include/standard-headers/linux/if_ether.h
 create mode 100644 include/standard-headers/linux/types.h
 create mode 100644 include/standard-headers/linux/virtio_9p.h
 create mode 100644 include/standard-headers/linux/virtio_balloon.h
 create mode 100644 include/standard-headers/linux/virtio_blk.h
 create mode 100644 include/standard-headers/linux/virtio_config.h
 create mode 100644 include/standard-headers/linux/virtio_console.h
 create mode 100644 include/standard-headers/linux/virtio_ids.h
 create mode 100644 include/standard-headers/linux/virtio_net.h
 create mode 100644 include/standard-headers/linux/virtio_pci.h
 rename include/{hw/virtio => standard-headers/linux}/virtio_ring.h (61%)
 create mode 100644 include/standard-headers/linux/virtio_rng.h
 create mode 100644 include/standard-headers/linux/virtio_scsi.h
 create mode 100644 include/standard-headers/linux/virtio_types.h
 create mode 100644 hw/acpi/aml-build.c
 delete mode 100644 hw/i386/ssdt-mem.dsl
 delete mode 100644 hw/i386/ssdt-mem.hex.generated
 delete mode 100644 hw/i386/ssdt-proc.dsl
 delete mode 100644 hw/i386/ssdt-proc.hex.generated

^ permalink raw reply	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 01/96] acpi-build: fix memory leak with bridge hp off
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
@ 2015-02-18 21:44 ` Michael S. Tsirkin
  2015-02-18 21:44 ` [Qemu-devel] [PULL 02/96] bios linker: validate pointer within table Michael S. Tsirkin
                   ` (97 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:44 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, qemu-stable, dgilbert,
	Anthony Liguori, Paolo Bonzini, Richard Henderson

When bridge hotplug is disabled for old machine types,
we never free memory allocated for temporary tables.
Fix this up.

Cc: qemu-stable@nongnu.org
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/i386/acpi-build.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 4944249..74586f3 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -859,6 +859,9 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)
      * to make acpi tables compatible with legacy machine types.
      */
     if (!child->pcihp_bridge_en && bus->parent_dev) {
+        build_free_array(bus_table);
+        build_pci_bus_state_cleanup(child);
+        g_free(child);
         return;
     }
 
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 02/96] bios linker: validate pointer within table
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
  2015-02-18 21:44 ` [Qemu-devel] [PULL 01/96] acpi-build: fix memory leak with bridge hp off Michael S. Tsirkin
@ 2015-02-18 21:44 ` Michael S. Tsirkin
  2015-02-18 21:44 ` [Qemu-devel] [PULL 03/96] acpi: move generic aml building helpers into dedictated file Michael S. Tsirkin
                   ` (96 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, dgilbert, Juan Quintela

buios linker assumes pointer parameter it gets
is within table, validate this.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/acpi/bios-linker-loader.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/bios-linker-loader.c b/hw/acpi/bios-linker-loader.c
index 5cc4d90..d9382f8 100644
--- a/hw/acpi/bios-linker-loader.c
+++ b/hw/acpi/bios-linker-loader.c
@@ -141,6 +141,7 @@ void bios_linker_loader_add_pointer(GArray *linker,
                                     uint8_t pointer_size)
 {
     BiosLinkerLoaderEntry entry;
+    size_t offset = (gchar *)pointer - table->data;
 
     memset(&entry, 0, sizeof entry);
     strncpy(entry.pointer.dest_file, dest_file,
@@ -148,7 +149,8 @@ void bios_linker_loader_add_pointer(GArray *linker,
     strncpy(entry.pointer.src_file, src_file,
             sizeof entry.pointer.src_file - 1);
     entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_POINTER);
-    entry.pointer.offset = cpu_to_le32((gchar *)pointer - table->data);
+    assert(table->len >= offset + pointer_size);
+    entry.pointer.offset = cpu_to_le32(offset);
     entry.pointer.size = pointer_size;
     assert(pointer_size == 1 || pointer_size == 2 ||
            pointer_size == 4 || pointer_size == 8);
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 03/96] acpi: move generic aml building helpers into dedictated file
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
  2015-02-18 21:44 ` [Qemu-devel] [PULL 01/96] acpi-build: fix memory leak with bridge hp off Michael S. Tsirkin
  2015-02-18 21:44 ` [Qemu-devel] [PULL 02/96] bios linker: validate pointer within table Michael S. Tsirkin
@ 2015-02-18 21:44 ` Michael S. Tsirkin
  2015-02-18 21:44 ` [Qemu-devel] [PULL 04/96] acpi: add build_append_namestring() helper Michael S. Tsirkin
                   ` (95 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:44 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Anthony Liguori,
	Paolo Bonzini, Marcel Apfelbaum, Igor Mammedov,
	Richard Henderson

From: Igor Mammedov <imammedo@redhat.com>

the will be later used for composing AML primitives
and all that could be reused later for ARM machines
as well.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Acked-by: Marcel Apfelbaum <marcel@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h |  23 ++++++
 hw/acpi/aml-build.c         | 187 ++++++++++++++++++++++++++++++++++++++++++++
 hw/i386/acpi-build.c        | 162 +-------------------------------------
 hw/acpi/Makefile.objs       |   1 +
 4 files changed, 213 insertions(+), 160 deletions(-)
 create mode 100644 include/hw/acpi/aml-build.h
 create mode 100644 hw/acpi/aml-build.c

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
new file mode 100644
index 0000000..e6a0b28
--- /dev/null
+++ b/include/hw/acpi/aml-build.h
@@ -0,0 +1,23 @@
+#ifndef HW_ACPI_GEN_UTILS_H
+#define HW_ACPI_GEN_UTILS_H
+
+#include <stdint.h>
+#include <glib.h>
+#include "qemu/compiler.h"
+
+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_nameseg(GArray *array, const char *format, ...);
+
+void build_prepend_package_length(GArray *package, unsigned min_bytes);
+void build_package(GArray *package, uint8_t op, unsigned min_bytes);
+void build_append_value(GArray *table, uint32_t value, int size);
+void build_append_int(GArray *table, uint32_t value);
+void build_extop_package(GArray *package, uint8_t op);
+
+#endif
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
new file mode 100644
index 0000000..b28c1f4
--- /dev/null
+++ b/hw/acpi/aml-build.c
@@ -0,0 +1,187 @@
+/* Support for generating ACPI tables and passing them to Guests
+ *
+ * Copyright (C) 2015 Red Hat Inc
+ *
+ * Author: Michael S. Tsirkin <mst@redhat.com>
+ * Author: Igor Mammedov <imammedo@redhat.com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <assert.h>
+#include <stdbool.h>
+#include "hw/acpi/aml-build.h"
+
+GArray *build_alloc_array(void)
+{
+    return g_array_new(false, true /* clear */, 1);
+}
+
+void build_free_array(GArray *array)
+{
+    g_array_free(array, true);
+}
+
+void build_prepend_byte(GArray *array, uint8_t val)
+{
+    g_array_prepend_val(array, val);
+}
+
+void build_append_byte(GArray *array, uint8_t val)
+{
+    g_array_append_val(array, val);
+}
+
+void build_append_array(GArray *array, GArray *val)
+{
+    g_array_append_vals(array, val->data, val->len);
+}
+
+#define ACPI_NAMESEG_LEN 4
+
+void GCC_FMT_ATTR(2, 3)
+build_append_nameseg(GArray *array, const char *format, ...)
+{
+    /* It would be nicer to use g_string_vprintf but it's only there in 2.22 */
+    char s[] = "XXXX";
+    int len;
+    va_list args;
+
+    va_start(args, format);
+    len = vsnprintf(s, sizeof s, format, args);
+    va_end(args);
+
+    assert(len <= ACPI_NAMESEG_LEN);
+
+    g_array_append_vals(array, s, len);
+    /* Pad up to ACPI_NAMESEG_LEN characters if necessary. */
+    g_array_append_vals(array, "____", ACPI_NAMESEG_LEN - len);
+}
+
+/* 5.4 Definition Block Encoding */
+enum {
+    PACKAGE_LENGTH_1BYTE_SHIFT = 6, /* Up to 63 - use extra 2 bits. */
+    PACKAGE_LENGTH_2BYTE_SHIFT = 4,
+    PACKAGE_LENGTH_3BYTE_SHIFT = 12,
+    PACKAGE_LENGTH_4BYTE_SHIFT = 20,
+};
+
+void build_prepend_package_length(GArray *package, unsigned min_bytes)
+{
+    uint8_t byte;
+    unsigned length = package->len;
+    unsigned length_bytes;
+
+    if (length + 1 < (1 << PACKAGE_LENGTH_1BYTE_SHIFT)) {
+        length_bytes = 1;
+    } else if (length + 2 < (1 << PACKAGE_LENGTH_3BYTE_SHIFT)) {
+        length_bytes = 2;
+    } else if (length + 3 < (1 << PACKAGE_LENGTH_4BYTE_SHIFT)) {
+        length_bytes = 3;
+    } else {
+        length_bytes = 4;
+    }
+
+    /* Force length to at least min_bytes.
+     * This wastes memory but that's how bios did it.
+     */
+    length_bytes = MAX(length_bytes, min_bytes);
+
+    /* PkgLength is the length of the inclusive length of the data. */
+    length += length_bytes;
+
+    switch (length_bytes) {
+    case 1:
+        byte = length;
+        build_prepend_byte(package, byte);
+        return;
+    case 4:
+        byte = length >> PACKAGE_LENGTH_4BYTE_SHIFT;
+        build_prepend_byte(package, byte);
+        length &= (1 << PACKAGE_LENGTH_4BYTE_SHIFT) - 1;
+        /* fall through */
+    case 3:
+        byte = length >> PACKAGE_LENGTH_3BYTE_SHIFT;
+        build_prepend_byte(package, byte);
+        length &= (1 << PACKAGE_LENGTH_3BYTE_SHIFT) - 1;
+        /* fall through */
+    case 2:
+        byte = length >> PACKAGE_LENGTH_2BYTE_SHIFT;
+        build_prepend_byte(package, byte);
+        length &= (1 << PACKAGE_LENGTH_2BYTE_SHIFT) - 1;
+        /* fall through */
+    }
+    /*
+     * Most significant two bits of byte zero indicate how many following bytes
+     * are in PkgLength encoding.
+     */
+    byte = ((length_bytes - 1) << PACKAGE_LENGTH_1BYTE_SHIFT) | length;
+    build_prepend_byte(package, byte);
+}
+
+void build_package(GArray *package, uint8_t op, unsigned min_bytes)
+{
+    build_prepend_package_length(package, min_bytes);
+    build_prepend_byte(package, op);
+}
+
+void build_extop_package(GArray *package, uint8_t op)
+{
+    build_package(package, op, 1);
+    build_prepend_byte(package, 0x5B); /* ExtOpPrefix */
+}
+
+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;
+    }
+}
+
+void build_append_int(GArray *table, uint32_t value)
+{
+    if (value == 0x00) {
+        build_append_byte(table, 0x00); /* ZeroOp */
+    } else if (value == 0x01) {
+        build_append_byte(table, 0x01); /* OneOp */
+    } else if (value <= 0xFF) {
+        build_append_value(table, value, 1);
+    } else if (value <= 0xFFFF) {
+        build_append_value(table, value, 2);
+    } else {
+        build_append_value(table, value, 4);
+    }
+}
+
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 74586f3..cc638a9 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -54,6 +54,8 @@
 #include "hw/i386/q35-acpi-dsdt.hex"
 #include "hw/i386/acpi-dsdt.hex"
 
+#include "hw/acpi/aml-build.h"
+
 #include "qapi/qmp/qint.h"
 #include "qom/qom-qobject.h"
 #include "exec/ram_addr.h"
@@ -280,166 +282,6 @@ build_header(GArray *linker, GArray *table_data,
                                     table_data->data, h, len, &h->checksum);
 }
 
-static inline GArray *build_alloc_array(void)
-{
-    return g_array_new(false, true /* clear */, 1);
-}
-
-static inline void build_free_array(GArray *array)
-{
-    g_array_free(array, true);
-}
-
-static inline void build_prepend_byte(GArray *array, uint8_t val)
-{
-    g_array_prepend_val(array, val);
-}
-
-static inline void build_append_byte(GArray *array, uint8_t val)
-{
-    g_array_append_val(array, val);
-}
-
-static inline void build_append_array(GArray *array, GArray *val)
-{
-    g_array_append_vals(array, val->data, val->len);
-}
-
-#define ACPI_NAMESEG_LEN 4
-
-static void GCC_FMT_ATTR(2, 3)
-build_append_nameseg(GArray *array, const char *format, ...)
-{
-    /* It would be nicer to use g_string_vprintf but it's only there in 2.22 */
-    char s[] = "XXXX";
-    int len;
-    va_list args;
-
-    va_start(args, format);
-    len = vsnprintf(s, sizeof s, format, args);
-    va_end(args);
-
-    assert(len <= ACPI_NAMESEG_LEN);
-
-    g_array_append_vals(array, s, len);
-    /* Pad up to ACPI_NAMESEG_LEN characters if necessary. */
-    g_array_append_vals(array, "____", ACPI_NAMESEG_LEN - len);
-}
-
-/* 5.4 Definition Block Encoding */
-enum {
-    PACKAGE_LENGTH_1BYTE_SHIFT = 6, /* Up to 63 - use extra 2 bits. */
-    PACKAGE_LENGTH_2BYTE_SHIFT = 4,
-    PACKAGE_LENGTH_3BYTE_SHIFT = 12,
-    PACKAGE_LENGTH_4BYTE_SHIFT = 20,
-};
-
-static void build_prepend_package_length(GArray *package, unsigned min_bytes)
-{
-    uint8_t byte;
-    unsigned length = package->len;
-    unsigned length_bytes;
-
-    if (length + 1 < (1 << PACKAGE_LENGTH_1BYTE_SHIFT)) {
-        length_bytes = 1;
-    } else if (length + 2 < (1 << PACKAGE_LENGTH_3BYTE_SHIFT)) {
-        length_bytes = 2;
-    } else if (length + 3 < (1 << PACKAGE_LENGTH_4BYTE_SHIFT)) {
-        length_bytes = 3;
-    } else {
-        length_bytes = 4;
-    }
-
-    /* Force length to at least min_bytes.
-     * This wastes memory but that's how bios did it.
-     */
-    length_bytes = MAX(length_bytes, min_bytes);
-
-    /* PkgLength is the length of the inclusive length of the data. */
-    length += length_bytes;
-
-    switch (length_bytes) {
-    case 1:
-        byte = length;
-        build_prepend_byte(package, byte);
-        return;
-    case 4:
-        byte = length >> PACKAGE_LENGTH_4BYTE_SHIFT;
-        build_prepend_byte(package, byte);
-        length &= (1 << PACKAGE_LENGTH_4BYTE_SHIFT) - 1;
-        /* fall through */
-    case 3:
-        byte = length >> PACKAGE_LENGTH_3BYTE_SHIFT;
-        build_prepend_byte(package, byte);
-        length &= (1 << PACKAGE_LENGTH_3BYTE_SHIFT) - 1;
-        /* fall through */
-    case 2:
-        byte = length >> PACKAGE_LENGTH_2BYTE_SHIFT;
-        build_prepend_byte(package, byte);
-        length &= (1 << PACKAGE_LENGTH_2BYTE_SHIFT) - 1;
-        /* fall through */
-    }
-    /*
-     * Most significant two bits of byte zero indicate how many following bytes
-     * are in PkgLength encoding.
-     */
-    byte = ((length_bytes - 1) << PACKAGE_LENGTH_1BYTE_SHIFT) | length;
-    build_prepend_byte(package, byte);
-}
-
-static void build_package(GArray *package, uint8_t op, unsigned min_bytes)
-{
-    build_prepend_package_length(package, min_bytes);
-    build_prepend_byte(package, op);
-}
-
-static void build_extop_package(GArray *package, uint8_t op)
-{
-    build_package(package, op, 1);
-    build_prepend_byte(package, 0x5B); /* ExtOpPrefix */
-}
-
-static 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;
-    }
-}
-
-static void build_append_int(GArray *table, uint32_t value)
-{
-    if (value == 0x00) {
-        build_append_byte(table, 0x00); /* ZeroOp */
-    } else if (value == 0x01) {
-        build_append_byte(table, 0x01); /* OneOp */
-    } else if (value <= 0xFF) {
-        build_append_value(table, value, 1);
-    } else if (value <= 0xFFFF) {
-        build_append_value(table, value, 2);
-    } else {
-        build_append_value(table, value, 4);
-    }
-}
-
 static GArray *build_alloc_method(const char *name, uint8_t arg_count)
 {
     GArray *method = build_alloc_array();
diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
index ee82073..b9fefa7 100644
--- a/hw/acpi/Makefile.objs
+++ b/hw/acpi/Makefile.objs
@@ -2,3 +2,4 @@ common-obj-$(CONFIG_ACPI) += core.o piix4.o ich9.o pcihp.o cpu_hotplug.o
 common-obj-$(CONFIG_ACPI) += memory_hotplug.o
 common-obj-$(CONFIG_ACPI) += acpi_interface.o
 common-obj-$(CONFIG_ACPI) += bios-linker-loader.o
+common-obj-$(CONFIG_ACPI) += aml-build.o
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 04/96] acpi: add build_append_namestring() helper
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (2 preceding siblings ...)
  2015-02-18 21:44 ` [Qemu-devel] [PULL 03/96] acpi: move generic aml building helpers into dedictated file Michael S. Tsirkin
@ 2015-02-18 21:44 ` Michael S. Tsirkin
  2015-02-18 21:44 ` [Qemu-devel] [PULL 05/96] acpi: drop min-bytes in build_package() Michael S. Tsirkin
                   ` (94 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:44 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Anthony Liguori,
	Paolo Bonzini, Igor Mammedov, Richard Henderson

From: Igor Mammedov <imammedo@redhat.com>

Use build_append_namestring() instead of build_append_nameseg()
So user won't have to care whether name is NameSeg, NamePath or
NameString.

See for reference ACPI 5.0: 20.2.2 Name Objects Encoding

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h |  2 +-
 hw/acpi/aml-build.c         | 96 ++++++++++++++++++++++++++++++++++++++++-----
 hw/i386/acpi-build.c        | 37 ++++++++---------
 3 files changed, 105 insertions(+), 30 deletions(-)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index e6a0b28..fd50625 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -12,7 +12,7 @@ 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_nameseg(GArray *array, const char *format, ...);
+build_append_namestring(GArray *array, const char *format, ...);
 
 void build_prepend_package_length(GArray *package, unsigned min_bytes);
 void build_package(GArray *package, uint8_t op, unsigned min_bytes);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index b28c1f4..6a02474 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -23,6 +23,7 @@
 #include <stdarg.h>
 #include <assert.h>
 #include <stdbool.h>
+#include <string.h>
 #include "hw/acpi/aml-build.h"
 
 GArray *build_alloc_array(void)
@@ -52,25 +53,102 @@ void build_append_array(GArray *array, GArray *val)
 
 #define ACPI_NAMESEG_LEN 4
 
-void GCC_FMT_ATTR(2, 3)
-build_append_nameseg(GArray *array, const char *format, ...)
+static void
+build_append_nameseg(GArray *array, const char *seg)
 {
     /* It would be nicer to use g_string_vprintf but it's only there in 2.22 */
-    char s[] = "XXXX";
     int len;
-    va_list args;
-
-    va_start(args, format);
-    len = vsnprintf(s, sizeof s, format, args);
-    va_end(args);
 
+    len = strlen(seg);
     assert(len <= ACPI_NAMESEG_LEN);
 
-    g_array_append_vals(array, s, len);
+    g_array_append_vals(array, seg, len);
     /* Pad up to ACPI_NAMESEG_LEN characters if necessary. */
     g_array_append_vals(array, "____", ACPI_NAMESEG_LEN - len);
 }
 
+static void
+build_append_namestringv(GArray *array, const char *format, va_list ap)
+{
+    /* It would be nicer to use g_string_vprintf but it's only there in 2.22 */
+    char *s;
+    int len;
+    va_list va_len;
+    char **segs;
+    char **segs_iter;
+    int seg_count = 0;
+
+    va_copy(va_len, ap);
+    len = vsnprintf(NULL, 0, format, va_len);
+    va_end(va_len);
+    len += 1;
+    s = g_new(typeof(*s), len);
+
+    len = vsnprintf(s, len, format, ap);
+
+    segs = g_strsplit(s, ".", 0);
+    g_free(s);
+
+    /* count segments */
+    segs_iter = segs;
+    while (*segs_iter) {
+        ++segs_iter;
+        ++seg_count;
+    }
+    /*
+     * ACPI 5.0 spec: 20.2.2 Name Objects Encoding:
+     * "SegCount can be from 1 to 255"
+     */
+    assert(seg_count > 0 && seg_count <= 255);
+
+    /* handle RootPath || PrefixPath */
+    s = *segs;
+    while (*s == '\\' || *s == '^') {
+        build_append_byte(array, *s);
+        ++s;
+    }
+
+    switch (seg_count) {
+    case 1:
+        if (!*s) {
+            build_append_byte(array, 0x0); /* NullName */
+        } else {
+            build_append_nameseg(array, s);
+        }
+        break;
+
+    case 2:
+        build_append_byte(array, 0x2E); /* DualNamePrefix */
+        build_append_nameseg(array, s);
+        build_append_nameseg(array, segs[1]);
+        break;
+    default:
+        build_append_byte(array, 0x2F); /* MultiNamePrefix */
+        build_append_byte(array, seg_count);
+
+        /* handle the 1st segment manually due to prefix/root path */
+        build_append_nameseg(array, s);
+
+        /* add the rest of segments */
+        segs_iter = segs + 1;
+        while (*segs_iter) {
+            build_append_nameseg(array, *segs_iter);
+            ++segs_iter;
+        }
+        break;
+    }
+    g_strfreev(segs);
+}
+
+void build_append_namestring(GArray *array, const char *format, ...)
+{
+    va_list ap;
+
+    va_start(ap, format);
+    build_append_namestringv(array, format, ap);
+    va_end(ap);
+}
+
 /* 5.4 Definition Block Encoding */
 enum {
     PACKAGE_LENGTH_1BYTE_SHIFT = 6, /* Up to 63 - use extra 2 bits. */
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index cc638a9..df2bad0 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -286,7 +286,7 @@ static GArray *build_alloc_method(const char *name, uint8_t arg_count)
 {
     GArray *method = build_alloc_array();
 
-    build_append_nameseg(method, "%s", name);
+    build_append_namestring(method, "%s", name);
     build_append_byte(method, arg_count); /* MethodFlags: ArgCount */
 
     return method;
@@ -578,7 +578,7 @@ build_append_notify_method(GArray *device, const char *name,
 
     for (i = 0; i < count; i++) {
         GArray *target = build_alloc_array();
-        build_append_nameseg(target, format, i);
+        build_append_namestring(target, format, i);
         assert(i < 256); /* Fits in 1 byte */
         build_append_notify_target_ifequal(method, target, i, 1);
         build_free_array(target);
@@ -709,24 +709,24 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)
 
     if (bus->parent_dev) {
         op = 0x82; /* DeviceOp */
-        build_append_nameseg(bus_table, "S%.02X",
+        build_append_namestring(bus_table, "S%.02X",
                              bus->parent_dev->devfn);
         build_append_byte(bus_table, 0x08); /* NameOp */
-        build_append_nameseg(bus_table, "_SUN");
+        build_append_namestring(bus_table, "_SUN");
         build_append_value(bus_table, PCI_SLOT(bus->parent_dev->devfn), 1);
         build_append_byte(bus_table, 0x08); /* NameOp */
-        build_append_nameseg(bus_table, "_ADR");
+        build_append_namestring(bus_table, "_ADR");
         build_append_value(bus_table, (PCI_SLOT(bus->parent_dev->devfn) << 16) |
                            PCI_FUNC(bus->parent_dev->devfn), 4);
     } else {
         op = 0x10; /* ScopeOp */;
-        build_append_nameseg(bus_table, "PCI0");
+        build_append_namestring(bus_table, "PCI0");
     }
 
     bsel = object_property_get_qobject(OBJECT(bus), ACPI_PCIHP_PROP_BSEL, NULL);
     if (bsel) {
         build_append_byte(bus_table, 0x08); /* NameOp */
-        build_append_nameseg(bus_table, "BSEL");
+        build_append_namestring(bus_table, "BSEL");
         build_append_int(bus_table, qint_get_int(qobject_to_qint(bsel)));
         memset(slot_hotplug_enable, 0xff, sizeof slot_hotplug_enable);
     } else {
@@ -829,7 +829,7 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)
             build_append_int(notify, 0x1U << i);
             build_append_byte(notify, 0x00); /* NullName */
             build_append_byte(notify, 0x86); /* NotifyOp */
-            build_append_nameseg(notify, "S%.02X", PCI_DEVFN(i, 0));
+            build_append_namestring(notify, "S%.02X", PCI_DEVFN(i, 0));
             build_append_byte(notify, 0x69); /* Arg1Op */
 
             /* Pack it up */
@@ -853,12 +853,12 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)
         if (bsel) {
             build_append_byte(method, 0x70); /* StoreOp */
             build_append_int(method, qint_get_int(qobject_to_qint(bsel)));
-            build_append_nameseg(method, "BNUM");
-            build_append_nameseg(method, "DVNT");
-            build_append_nameseg(method, "PCIU");
+            build_append_namestring(method, "BNUM");
+            build_append_namestring(method, "DVNT");
+            build_append_namestring(method, "PCIU");
             build_append_int(method, 1); /* Device Check */
-            build_append_nameseg(method, "DVNT");
-            build_append_nameseg(method, "PCID");
+            build_append_namestring(method, "DVNT");
+            build_append_namestring(method, "PCID");
             build_append_int(method, 3); /* Eject Request */
         }
 
@@ -884,11 +884,8 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)
          * At the moment this is not needed for root as we have a single root.
          */
         if (bus->parent_dev) {
-            build_append_byte(parent->notify_table, '^'); /* ParentPrefixChar */
-            build_append_byte(parent->notify_table, 0x2E); /* DualNamePrefix */
-            build_append_nameseg(parent->notify_table, "S%.02X",
-                                 bus->parent_dev->devfn);
-            build_append_nameseg(parent->notify_table, "PCNT");
+            build_append_namestring(parent->notify_table, "^PCNT.S%.02X",
+                                    bus->parent_dev->devfn);
         }
     }
 
@@ -956,7 +953,7 @@ build_ssdt(GArray *table_data, GArray *linker,
         GArray *sb_scope = build_alloc_array();
         uint8_t op = 0x10; /* ScopeOp */
 
-        build_append_nameseg(sb_scope, "_SB");
+        build_append_namestring(sb_scope, "_SB");
 
         /* build Processor object for each processor */
         for (i = 0; i < acpi_cpus; i++) {
@@ -976,7 +973,7 @@ build_ssdt(GArray *table_data, GArray *linker,
 
         /* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" */
         build_append_byte(sb_scope, 0x08); /* NameOp */
-        build_append_nameseg(sb_scope, "CPON");
+        build_append_namestring(sb_scope, "CPON");
 
         {
             GArray *package = build_alloc_array();
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 05/96] acpi: drop min-bytes in build_package()
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (3 preceding siblings ...)
  2015-02-18 21:44 ` [Qemu-devel] [PULL 04/96] acpi: add build_append_namestring() helper Michael S. Tsirkin
@ 2015-02-18 21:44 ` Michael S. Tsirkin
  2015-02-18 21:44 ` [Qemu-devel] [PULL 06/96] pci: Convert core to realize Michael S. Tsirkin
                   ` (93 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:44 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, Claudio Fontana, dgilbert,
	Anthony Liguori, Paolo Bonzini, Marcel Apfelbaum, Igor Mammedov,
	Richard Henderson

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Claudio Fontana <claudio.fontana@huawei.com>
Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h |  4 ++--
 hw/acpi/aml-build.c         | 14 ++++----------
 hw/i386/acpi-build.c        | 13 ++++++-------
 3 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index fd50625..199f003 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -14,8 +14,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, unsigned min_bytes);
-void build_package(GArray *package, uint8_t op, unsigned min_bytes);
+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_extop_package(GArray *package, uint8_t op);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 6a02474..bcb288e 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -157,7 +157,7 @@ enum {
     PACKAGE_LENGTH_4BYTE_SHIFT = 20,
 };
 
-void build_prepend_package_length(GArray *package, unsigned min_bytes)
+void build_prepend_package_length(GArray *package)
 {
     uint8_t byte;
     unsigned length = package->len;
@@ -173,11 +173,6 @@ void build_prepend_package_length(GArray *package, unsigned min_bytes)
         length_bytes = 4;
     }
 
-    /* Force length to at least min_bytes.
-     * This wastes memory but that's how bios did it.
-     */
-    length_bytes = MAX(length_bytes, min_bytes);
-
     /* PkgLength is the length of the inclusive length of the data. */
     length += length_bytes;
 
@@ -210,15 +205,15 @@ void build_prepend_package_length(GArray *package, unsigned min_bytes)
     build_prepend_byte(package, byte);
 }
 
-void build_package(GArray *package, uint8_t op, unsigned min_bytes)
+void build_package(GArray *package, uint8_t op)
 {
-    build_prepend_package_length(package, min_bytes);
+    build_prepend_package_length(package);
     build_prepend_byte(package, op);
 }
 
 void build_extop_package(GArray *package, uint8_t op)
 {
-    build_package(package, op, 1);
+    build_package(package, op);
     build_prepend_byte(package, 0x5B); /* ExtOpPrefix */
 }
 
@@ -262,4 +257,3 @@ void build_append_int(GArray *table, uint32_t value)
         build_append_value(table, value, 4);
     }
 }
-
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index df2bad0..5737ed0 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -296,7 +296,7 @@ static void build_append_and_cleanup_method(GArray *device, GArray *method)
 {
     uint8_t op = 0x14; /* MethodOp */
 
-    build_package(method, op, 0);
+    build_package(method, op);
 
     build_append_array(device, method);
     build_free_array(method);
@@ -317,7 +317,7 @@ static void build_append_notify_target_ifequal(GArray *method,
     build_append_byte(notify, 0x69); /* Arg1Op */
 
     /* Pack it up */
-    build_package(notify, op, 1);
+    build_package(notify, op);
 
     build_append_array(method, notify);
 
@@ -833,7 +833,7 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)
             build_append_byte(notify, 0x69); /* Arg1Op */
 
             /* Pack it up */
-            build_package(notify, op, 0);
+            build_package(notify, op);
 
             build_append_array(method, notify);
 
@@ -874,7 +874,7 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)
         if (bus->parent_dev) {
             build_extop_package(bus_table, op);
         } else {
-            build_package(bus_table, op, 0);
+            build_package(bus_table, op);
         }
 
         /* Append our bus description to parent table */
@@ -997,7 +997,7 @@ build_ssdt(GArray *table_data, GArray *linker,
                 build_append_byte(package, b);
             }
 
-            build_package(package, op, 2);
+            build_package(package, op);
             build_append_array(sb_scope, package);
             build_free_array(package);
         }
@@ -1045,8 +1045,7 @@ build_ssdt(GArray *table_data, GArray *linker,
             build_append_array(sb_scope, hotplug_state.device_table);
             build_pci_bus_state_cleanup(&hotplug_state);
         }
-
-        build_package(sb_scope, op, 3);
+        build_package(sb_scope, op);
         build_append_array(table_data, sb_scope);
         build_free_array(sb_scope);
     }
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 06/96] pci: Convert core to realize
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (4 preceding siblings ...)
  2015-02-18 21:44 ` [Qemu-devel] [PULL 05/96] acpi: drop min-bytes in build_package() Michael S. Tsirkin
@ 2015-02-18 21:44 ` Michael S. Tsirkin
  2015-02-18 21:44 ` [Qemu-devel] [PULL 07/96] pci: Permit incremental conversion of device models " Michael S. Tsirkin
                   ` (92 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:44 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Gonglei, dgilbert, Markus Armbruster, Juan Quintela

From: Markus Armbruster <armbru@redhat.com>

Implement DeviceClass methods realize() and unrealize() instead of
init() and exit().  The core's initialization errors now get
propagated properly, and QMP sends them instead of an unspecific
"Device initialization failed" error.  Unrealize can't fail, so no
change there.

PCIDeviceClass is unchanged: it still provides init() and exit().
Therefore, device models' errors are still not propagated.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/pci/pci.c | 93 ++++++++++++++++++++++++++++++++----------------------------
 1 file changed, 49 insertions(+), 44 deletions(-)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index d508930..aaf480d 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -115,7 +115,7 @@ static const TypeInfo pcie_bus_info = {
 static PCIBus *pci_find_bus_nr(PCIBus *bus, int bus_num);
 static void pci_update_mappings(PCIDevice *d);
 static void pci_irq_handler(void *opaque, int irq_num, int level);
-static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom);
+static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom, Error **);
 static void pci_del_option_rom(PCIDevice *pdev);
 
 static uint16_t pci_default_sub_vendor_id = PCI_SUBVENDOR_ID_REDHAT_QUMRANET;
@@ -726,7 +726,7 @@ static void pci_init_mask_bridge(PCIDevice *d)
                                PCI_PREF_RANGE_TYPE_MASK);
 }
 
-static int pci_init_multifunction(PCIBus *bus, PCIDevice *dev)
+static void pci_init_multifunction(PCIBus *bus, PCIDevice *dev, Error **errp)
 {
     uint8_t slot = PCI_SLOT(dev->devfn);
     uint8_t func;
@@ -752,26 +752,25 @@ static int pci_init_multifunction(PCIBus *bus, PCIDevice *dev)
         PCIDevice *f0 = bus->devices[PCI_DEVFN(slot, 0)];
         if (f0 && !(f0->cap_present & QEMU_PCI_CAP_MULTIFUNCTION)) {
             /* function 0 should set multifunction bit */
-            error_report("PCI: single function device can't be populated "
-                         "in function %x.%x", slot, PCI_FUNC(dev->devfn));
-            return -1;
+            error_setg(errp, "PCI: single function device can't be populated "
+                       "in function %x.%x", slot, PCI_FUNC(dev->devfn));
+            return;
         }
-        return 0;
+        return;
     }
 
     if (dev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
-        return 0;
+        return;
     }
     /* function 0 indicates single function, so function > 0 must be NULL */
     for (func = 1; func < PCI_FUNC_MAX; ++func) {
         if (bus->devices[PCI_DEVFN(slot, func)]) {
-            error_report("PCI: %x.0 indicates single function, "
-                         "but %x.%x is already populated.",
-                         slot, slot, func);
-            return -1;
+            error_setg(errp, "PCI: %x.0 indicates single function, "
+                       "but %x.%x is already populated.",
+                       slot, slot, func);
+            return;
         }
     }
-    return 0;
 }
 
 static void pci_config_alloc(PCIDevice *pci_dev)
@@ -804,11 +803,13 @@ static void do_pci_unregister_device(PCIDevice *pci_dev)
 
 /* -1 for devfn means auto assign */
 static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
-                                         const char *name, int devfn)
+                                         const char *name, int devfn,
+                                         Error **errp)
 {
     PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(pci_dev);
     PCIConfigReadFunc *config_read = pc->config_read;
     PCIConfigWriteFunc *config_write = pc->config_write;
+    Error *local_err = NULL;
     AddressSpace *dma_as;
 
     if (devfn < 0) {
@@ -817,12 +818,15 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
             if (!bus->devices[devfn])
                 goto found;
         }
-        error_report("PCI: no slot/function available for %s, all in use", name);
+        error_setg(errp, "PCI: no slot/function available for %s, all in use",
+                   name);
         return NULL;
     found: ;
     } else if (bus->devices[devfn]) {
-        error_report("PCI: slot %d function %d not available for %s, in use by %s",
-                     PCI_SLOT(devfn), PCI_FUNC(devfn), name, bus->devices[devfn]->name);
+        error_setg(errp, "PCI: slot %d function %d not available for %s,"
+                   " in use by %s",
+                   PCI_SLOT(devfn), PCI_FUNC(devfn), name,
+                   bus->devices[devfn]->name);
         return NULL;
     }
 
@@ -866,7 +870,9 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
     if (pc->is_bridge) {
         pci_init_mask_bridge(pci_dev);
     }
-    if (pci_init_multifunction(bus, pci_dev)) {
+    pci_init_multifunction(bus, pci_dev, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
         do_pci_unregister_device(pci_dev);
         return NULL;
     }
@@ -897,7 +903,7 @@ static void pci_unregister_io_regions(PCIDevice *pci_dev)
     pci_unregister_vga(pci_dev);
 }
 
-static int pci_unregister_device(DeviceState *dev)
+static void pci_qdev_unrealize(DeviceState *dev, Error **errp)
 {
     PCIDevice *pci_dev = PCI_DEVICE(dev);
     PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(pci_dev);
@@ -910,7 +916,6 @@ static int pci_unregister_device(DeviceState *dev)
     }
 
     do_pci_unregister_device(pci_dev);
-    return 0;
 }
 
 void pci_register_bar(PCIDevice *pci_dev, int region_num,
@@ -1751,10 +1756,11 @@ PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn)
     return bus->devices[devfn];
 }
 
-static int pci_qdev_init(DeviceState *qdev)
+static void pci_qdev_realize(DeviceState *qdev, Error **errp)
 {
     PCIDevice *pci_dev = (PCIDevice *)qdev;
     PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(pci_dev);
+    Error *local_err = NULL;
     PCIBus *bus;
     int rc;
     bool is_default_rom;
@@ -1767,15 +1773,16 @@ static int pci_qdev_init(DeviceState *qdev)
     bus = PCI_BUS(qdev_get_parent_bus(qdev));
     pci_dev = do_pci_register_device(pci_dev, bus,
                                      object_get_typename(OBJECT(qdev)),
-                                     pci_dev->devfn);
+                                     pci_dev->devfn, errp);
     if (pci_dev == NULL)
-        return -1;
+        return;
 
     if (pc->init) {
         rc = pc->init(pci_dev);
         if (rc != 0) {
             do_pci_unregister_device(pci_dev);
-            return rc;
+            error_setg(errp, "Device initialization failed");
+            return;
         }
     }
 
@@ -1786,13 +1793,12 @@ static int pci_qdev_init(DeviceState *qdev)
         is_default_rom = true;
     }
 
-    rc = pci_add_option_rom(pci_dev, is_default_rom);
-    if (rc != 0) {
-        pci_unregister_device(DEVICE(pci_dev));
-        return rc;
+    pci_add_option_rom(pci_dev, is_default_rom, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        pci_qdev_unrealize(DEVICE(pci_dev), NULL);
+        return;
     }
-
-    return 0;
 }
 
 PCIDevice *pci_create_multifunction(PCIBus *bus, int devfn, bool multifunction,
@@ -1932,7 +1938,8 @@ static void pci_patch_ids(PCIDevice *pdev, uint8_t *ptr, int size)
 }
 
 /* Add an option rom for the device */
-static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)
+static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom,
+                               Error **errp)
 {
     int size;
     char *path;
@@ -1941,9 +1948,9 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)
     const VMStateDescription *vmsd;
 
     if (!pdev->romfile)
-        return 0;
+        return;
     if (strlen(pdev->romfile) == 0)
-        return 0;
+        return;
 
     if (!pdev->rom_bar) {
         /*
@@ -1957,7 +1964,9 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)
          * if the rom bar is disabled.
          */
         if (DEVICE(pdev)->hotplugged) {
-            return -1;
+            error_setg(errp, "Hot-plugged device without ROM bar"
+                       " can't have an option ROM");
+            return;
         }
 
         if (class == 0x0300) {
@@ -1965,7 +1974,7 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)
         } else {
             rom_add_option(pdev->romfile, -1);
         }
-        return 0;
+        return;
     }
 
     path = qemu_find_file(QEMU_FILE_TYPE_BIOS, pdev->romfile);
@@ -1975,15 +1984,13 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)
 
     size = get_image_size(path);
     if (size < 0) {
-        error_report("%s: failed to find romfile \"%s\"",
-                     __func__, pdev->romfile);
+        error_setg(errp, "failed to find romfile \"%s\"", pdev->romfile);
         g_free(path);
-        return -1;
+        return;
     } else if (size == 0) {
-        error_report("%s: ignoring empty romfile \"%s\"",
-                     __func__, pdev->romfile);
+        error_setg(errp, "romfile \"%s\" is empty", pdev->romfile);
         g_free(path);
-        return -1;
+        return;
     }
     if (size & (size - 1)) {
         size = 1 << qemu_fls(size);
@@ -2009,8 +2016,6 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)
     }
 
     pci_register_bar(pdev, PCI_ROM_SLOT, 0, &pdev->rom);
-
-    return 0;
 }
 
 static void pci_del_option_rom(PCIDevice *pdev)
@@ -2292,8 +2297,8 @@ MemoryRegion *pci_address_space_io(PCIDevice *dev)
 static void pci_device_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *k = DEVICE_CLASS(klass);
-    k->init = pci_qdev_init;
-    k->exit = pci_unregister_device;
+    k->realize = pci_qdev_realize;
+    k->unrealize = pci_qdev_unrealize;
     k->bus_type = TYPE_PCI_BUS;
     k->props = pci_props;
 }
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 07/96] pci: Permit incremental conversion of device models to realize
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (5 preceding siblings ...)
  2015-02-18 21:44 ` [Qemu-devel] [PULL 06/96] pci: Convert core to realize Michael S. Tsirkin
@ 2015-02-18 21:44 ` Michael S. Tsirkin
  2015-02-18 21:44 ` [Qemu-devel] [PULL 08/96] pci: Trivial device model conversions " Michael S. Tsirkin
                   ` (91 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:44 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Gonglei, dgilbert, Markus Armbruster, Juan Quintela

From: Markus Armbruster <armbru@redhat.com>

Call the new PCIDeviceClass method realize().  Default it to
pci_default_realize(), which calls old method init().

To convert a device model, make it implement realize() rather than
init().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Gonglei <arei.gonglei@huawei.com>
---
 include/hw/pci/pci.h |  3 ++-
 hw/pci/pci.c         | 24 +++++++++++++++++++-----
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index bdee464..3164fc3 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -185,7 +185,8 @@ typedef struct PCIINTxRoute {
 typedef struct PCIDeviceClass {
     DeviceClass parent_class;
 
-    int (*init)(PCIDevice *dev);
+    void (*realize)(PCIDevice *dev, Error **errp);
+    int (*init)(PCIDevice *dev);/* TODO convert to realize() and remove */
     PCIUnregisterFunc *exit;
     PCIConfigReadFunc *config_read;
     PCIConfigWriteFunc *config_write;
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index aaf480d..f415d2c 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -1762,7 +1762,6 @@ static void pci_qdev_realize(DeviceState *qdev, Error **errp)
     PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(pci_dev);
     Error *local_err = NULL;
     PCIBus *bus;
-    int rc;
     bool is_default_rom;
 
     /* initialize cap_present for pci_is_express() and pci_config_size() */
@@ -1777,11 +1776,11 @@ static void pci_qdev_realize(DeviceState *qdev, Error **errp)
     if (pci_dev == NULL)
         return;
 
-    if (pc->init) {
-        rc = pc->init(pci_dev);
-        if (rc != 0) {
+    if (pc->realize) {
+        pc->realize(pci_dev, &local_err);
+        if (local_err) {
+            error_propagate(errp, local_err);
             do_pci_unregister_device(pci_dev);
-            error_setg(errp, "Device initialization failed");
             return;
         }
     }
@@ -1801,6 +1800,18 @@ static void pci_qdev_realize(DeviceState *qdev, Error **errp)
     }
 }
 
+static void pci_default_realize(PCIDevice *dev, Error **errp)
+{
+    PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
+
+    if (pc->init) {
+        if (pc->init(dev) < 0) {
+            error_setg(errp, "Device initialization failed");
+            return;
+        }
+    }
+}
+
 PCIDevice *pci_create_multifunction(PCIBus *bus, int devfn, bool multifunction,
                                     const char *name)
 {
@@ -2297,10 +2308,13 @@ MemoryRegion *pci_address_space_io(PCIDevice *dev)
 static void pci_device_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *k = DEVICE_CLASS(klass);
+    PCIDeviceClass *pc = PCI_DEVICE_CLASS(klass);
+
     k->realize = pci_qdev_realize;
     k->unrealize = pci_qdev_unrealize;
     k->bus_type = TYPE_PCI_BUS;
     k->props = pci_props;
+    pc->realize = pci_default_realize;
 }
 
 AddressSpace *pci_device_iommu_address_space(PCIDevice *dev)
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 08/96] pci: Trivial device model conversions to realize
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (6 preceding siblings ...)
  2015-02-18 21:44 ` [Qemu-devel] [PULL 07/96] pci: Permit incremental conversion of device models " Michael S. Tsirkin
@ 2015-02-18 21:44 ` Michael S. Tsirkin
  2015-02-18 21:44 ` [Qemu-devel] [PULL 09/96] pcnet: pcnet_common_init() always returns 0, change to void Michael S. Tsirkin
                   ` (90 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:44 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Peter Maydell, Stefan Hajnoczi, Juan Quintela,
	dgilbert, Markus Armbruster, Alexander Graf, Gonglei,
	Vassili Karpov (malc),
	Gerd Hoffmann, Anthony Liguori, Dmitry Fleytman, qemu-ppc,
	=?UTF-8?q?Andreas=20F=C3=A4rber?=

From: Markus Armbruster <armbru@redhat.com>

Convert the device models where initialization obviously can't fail.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/acpi/piix4.c            |  5 ++---
 hw/audio/ac97.c            |  5 ++---
 hw/audio/es1370.c          |  5 ++---
 hw/audio/intel-hda.c       |  6 ++----
 hw/display/vga-pci.c       | 11 ++++-------
 hw/display/vmware_vga.c    |  6 ++----
 hw/i2c/smbus_ich9.c        |  5 ++---
 hw/ide/cmd646.c            |  5 ++---
 hw/ide/piix.c              | 10 ++++------
 hw/ide/via.c               |  6 ++----
 hw/ipack/tpci200.c         |  6 ++----
 hw/isa/i82378.c            |  6 ++----
 hw/isa/piix4.c             |  5 ++---
 hw/isa/vt82c686.c          | 24 ++++++++----------------
 hw/misc/pci-testdev.c      |  6 ++----
 hw/net/e1000.c             |  6 ++----
 hw/net/eepro100.c          |  6 ++----
 hw/net/ne2000.c            |  6 ++----
 hw/net/rtl8139.c           |  6 ++----
 hw/net/vmxnet3.c           |  6 ++----
 hw/pci-bridge/dec.c        |  5 ++---
 hw/pci-host/apb.c          |  5 ++---
 hw/pci-host/bonito.c       |  6 ++----
 hw/pci-host/grackle.c      |  5 ++---
 hw/pci-host/piix.c         | 12 +++++-------
 hw/pci-host/ppce500.c      |  6 ++----
 hw/pci-host/prep.c         |  6 ++----
 hw/pci-host/q35.c          |  5 ++---
 hw/pci-host/uninorth.c     | 20 ++++++++------------
 hw/pci-host/versatile.c    |  5 ++---
 hw/sd/sdhci.c              |  5 ++---
 hw/usb/hcd-ehci-pci.c      |  6 ++----
 hw/usb/hcd-xhci.c          |  6 ++----
 hw/watchdog/wdt_i6300esb.c |  6 ++----
 34 files changed, 87 insertions(+), 152 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 184e7e4..017510b 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -420,7 +420,7 @@ static void piix4_pm_add_propeties(PIIX4PMState *s)
                                   &s->io_base, NULL);
 }
 
-static int piix4_pm_initfn(PCIDevice *dev)
+static void piix4_pm_realize(PCIDevice *dev, Error **errp)
 {
     PIIX4PMState *s = PIIX4_PM(dev);
     uint8_t *pci_conf;
@@ -470,7 +470,6 @@ static int piix4_pm_initfn(PCIDevice *dev)
     piix4_acpi_system_hot_add_init(pci_address_space_io(dev), dev->bus, s);
 
     piix4_pm_add_propeties(s);
-    return 0;
 }
 
 Object *piix4_pm_find(void)
@@ -593,7 +592,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data)
     HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
     AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_CLASS(klass);
 
-    k->init = piix4_pm_initfn;
+    k->realize = piix4_pm_realize;
     k->config_write = pm_write_config;
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->device_id = PCI_DEVICE_ID_INTEL_82371AB_3;
diff --git a/hw/audio/ac97.c b/hw/audio/ac97.c
index 111ec0e..b173835 100644
--- a/hw/audio/ac97.c
+++ b/hw/audio/ac97.c
@@ -1337,7 +1337,7 @@ static void ac97_on_reset (DeviceState *dev)
     mixer_reset (s);
 }
 
-static int ac97_initfn (PCIDevice *dev)
+static void ac97_realize(PCIDevice *dev, Error **errp)
 {
     AC97LinkState *s = DO_UPCAST (AC97LinkState, dev, dev);
     uint8_t *c = s->dev.config;
@@ -1384,7 +1384,6 @@ static int ac97_initfn (PCIDevice *dev)
     pci_register_bar (&s->dev, 1, PCI_BASE_ADDRESS_SPACE_IO, &s->io_nabm);
     AUD_register_card ("ac97", &s->card);
     ac97_on_reset (&s->dev.qdev);
-    return 0;
 }
 
 static int ac97_init (PCIBus *bus)
@@ -1403,7 +1402,7 @@ static void ac97_class_init (ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS (klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS (klass);
 
-    k->init = ac97_initfn;
+    k->realize = ac97_realize;
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->device_id = PCI_DEVICE_ID_INTEL_82801AA_5;
     k->revision = 0x01;
diff --git a/hw/audio/es1370.c b/hw/audio/es1370.c
index e67d1ea..8e7bcf5 100644
--- a/hw/audio/es1370.c
+++ b/hw/audio/es1370.c
@@ -1016,7 +1016,7 @@ static void es1370_on_reset (void *opaque)
     es1370_reset (s);
 }
 
-static int es1370_initfn (PCIDevice *dev)
+static void es1370_realize(PCIDevice *dev, Error **errp)
 {
     ES1370State *s = DO_UPCAST (ES1370State, dev, dev);
     uint8_t *c = s->dev.config;
@@ -1039,7 +1039,6 @@ static int es1370_initfn (PCIDevice *dev)
 
     AUD_register_card ("es1370", &s->card);
     es1370_reset (s);
-    return 0;
 }
 
 static int es1370_init (PCIBus *bus)
@@ -1053,7 +1052,7 @@ static void es1370_class_init (ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS (klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS (klass);
 
-    k->init = es1370_initfn;
+    k->realize = es1370_realize;
     k->vendor_id = PCI_VENDOR_ID_ENSONIQ;
     k->device_id = PCI_DEVICE_ID_ENSONIQ_ES1370;
     k->class_id = PCI_CLASS_MULTIMEDIA_AUDIO;
diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c
index 2885231..433463e 100644
--- a/hw/audio/intel-hda.c
+++ b/hw/audio/intel-hda.c
@@ -1126,7 +1126,7 @@ static void intel_hda_reset(DeviceState *dev)
     intel_hda_update_irq(d);
 }
 
-static int intel_hda_init(PCIDevice *pci)
+static void intel_hda_realize(PCIDevice *pci, Error **errp)
 {
     IntelHDAState *d = INTEL_HDA(pci);
     uint8_t *conf = d->pci.config;
@@ -1147,8 +1147,6 @@ static int intel_hda_init(PCIDevice *pci)
 
     hda_codec_bus_init(DEVICE(pci), &d->codecs, sizeof(d->codecs),
                        intel_hda_response, intel_hda_xfer);
-
-    return 0;
 }
 
 static void intel_hda_exit(PCIDevice *pci)
@@ -1245,7 +1243,7 @@ static void intel_hda_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = intel_hda_init;
+    k->realize = intel_hda_realize;
     k->exit = intel_hda_exit;
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->class_id = PCI_CLASS_MULTIMEDIA_HD_AUDIO;
diff --git a/hw/display/vga-pci.c b/hw/display/vga-pci.c
index 53739e4..d67f748 100644
--- a/hw/display/vga-pci.c
+++ b/hw/display/vga-pci.c
@@ -189,7 +189,7 @@ static const MemoryRegionOps pci_vga_qext_ops = {
     .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
-static int pci_std_vga_initfn(PCIDevice *dev)
+static void pci_std_vga_realize(PCIDevice *dev, Error **errp)
 {
     PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, dev);
     VGACommonState *s = &d->vga;
@@ -232,11 +232,9 @@ static int pci_std_vga_initfn(PCIDevice *dev)
         /* compatibility with pc-0.13 and older */
         vga_init_vbe(s, OBJECT(dev), pci_address_space(dev));
     }
-
-    return 0;
 }
 
-static int pci_secondary_vga_initfn(PCIDevice *dev)
+static void pci_secondary_vga_realize(PCIDevice *dev, Error **errp)
 {
     PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, dev);
     VGACommonState *s = &d->vga;
@@ -268,7 +266,6 @@ static int pci_secondary_vga_initfn(PCIDevice *dev)
     pci_register_bar(&d->dev, 0, PCI_BASE_ADDRESS_MEM_PREFETCH, &s->vram);
     pci_register_bar(&d->dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, &d->mmio);
 
-    return 0;
 }
 
 static void pci_secondary_vga_reset(DeviceState *dev)
@@ -298,7 +295,7 @@ static void vga_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = pci_std_vga_initfn;
+    k->realize = pci_std_vga_realize;
     k->romfile = "vgabios-stdvga.bin";
     k->vendor_id = PCI_VENDOR_ID_QEMU;
     k->device_id = PCI_DEVICE_ID_QEMU_VGA;
@@ -314,7 +311,7 @@ static void secondary_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = pci_secondary_vga_initfn;
+    k->realize = pci_secondary_vga_realize;
     k->vendor_id = PCI_VENDOR_ID_QEMU;
     k->device_id = PCI_DEVICE_ID_QEMU_VGA;
     k->class_id = PCI_CLASS_DISPLAY_OTHER;
diff --git a/hw/display/vmware_vga.c b/hw/display/vmware_vga.c
index 1751f19..c17ddd1 100644
--- a/hw/display/vmware_vga.c
+++ b/hw/display/vmware_vga.c
@@ -1298,7 +1298,7 @@ static const MemoryRegionOps vmsvga_io_ops = {
     },
 };
 
-static int pci_vmsvga_initfn(PCIDevice *dev)
+static void pci_vmsvga_realize(PCIDevice *dev, Error **errp)
 {
     struct pci_vmsvga_state_s *s = VMWARE_SVGA(dev);
 
@@ -1323,8 +1323,6 @@ static int pci_vmsvga_initfn(PCIDevice *dev)
         /* compatibility with pc-0.13 and older */
         vga_init_vbe(&s->chip.vga, OBJECT(dev), pci_address_space(dev));
     }
-
-    return 0;
 }
 
 static Property vga_vmware_properties[] = {
@@ -1338,7 +1336,7 @@ static void vmsvga_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = pci_vmsvga_initfn;
+    k->realize = pci_vmsvga_realize;
     k->romfile = "vgabios-vmware.bin";
     k->vendor_id = PCI_VENDOR_ID_VMWARE;
     k->device_id = SVGA_PCI_DEVICE_ID;
diff --git a/hw/i2c/smbus_ich9.c b/hw/i2c/smbus_ich9.c
index 0803dc4..91d4d32 100644
--- a/hw/i2c/smbus_ich9.c
+++ b/hw/i2c/smbus_ich9.c
@@ -71,7 +71,7 @@ static void ich9_smbus_write_config(PCIDevice *d, uint32_t address,
     }
 }
 
-static int ich9_smbus_initfn(PCIDevice *d)
+static void ich9_smbus_realize(PCIDevice *d, Error **errp)
 {
     ICH9SMBState *s = ICH9_SMB_DEVICE(d);
 
@@ -84,7 +84,6 @@ static int ich9_smbus_initfn(PCIDevice *d)
     pm_smbus_init(&d->qdev, &s->smb);
     pci_register_bar(d, ICH9_SMB_SMB_BASE_BAR, PCI_BASE_ADDRESS_SPACE_IO,
                      &s->smb.io);
-    return 0;
 }
 
 static void ich9_smb_class_init(ObjectClass *klass, void *data)
@@ -98,7 +97,7 @@ static void ich9_smb_class_init(ObjectClass *klass, void *data)
     k->class_id = PCI_CLASS_SERIAL_SMBUS;
     dc->vmsd = &vmstate_ich9_smbus;
     dc->desc = "ICH9 SMBUS Bridge";
-    k->init = ich9_smbus_initfn;
+    k->realize = ich9_smbus_realize;
     k->config_write = ich9_smbus_write_config;
     /*
      * Reason: part of ICH9 southbridge, needs to be wired up by
diff --git a/hw/ide/cmd646.c b/hw/ide/cmd646.c
index c8b0322..dafa9ec 100644
--- a/hw/ide/cmd646.c
+++ b/hw/ide/cmd646.c
@@ -326,7 +326,7 @@ static void cmd646_pci_config_write(PCIDevice *d, uint32_t addr, uint32_t val,
 }
 
 /* CMD646 PCI IDE controller */
-static int pci_cmd646_ide_initfn(PCIDevice *dev)
+static void pci_cmd646_ide_realize(PCIDevice *dev, Error **errp)
 {
     PCIIDEState *d = PCI_IDE(dev);
     uint8_t *pci_conf = dev->config;
@@ -374,7 +374,6 @@ static int pci_cmd646_ide_initfn(PCIDevice *dev)
 
     vmstate_register(DEVICE(dev), 0, &vmstate_ide_pci, d);
     qemu_register_reset(cmd646_reset, d);
-    return 0;
 }
 
 static void pci_cmd646_ide_exitfn(PCIDevice *dev)
@@ -410,7 +409,7 @@ static void cmd646_ide_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = pci_cmd646_ide_initfn;
+    k->realize = pci_cmd646_ide_realize;
     k->exit = pci_cmd646_ide_exitfn;
     k->vendor_id = PCI_VENDOR_ID_CMD;
     k->device_id = PCI_DEVICE_ID_CMD_646;
diff --git a/hw/ide/piix.c b/hw/ide/piix.c
index b0172fb..ab93084 100644
--- a/hw/ide/piix.c
+++ b/hw/ide/piix.c
@@ -148,7 +148,7 @@ static void pci_piix_init_ports(PCIIDEState *d) {
     }
 }
 
-static int pci_piix_ide_initfn(PCIDevice *dev)
+static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
 {
     PCIIDEState *d = PCI_IDE(dev);
     uint8_t *pci_conf = dev->config;
@@ -163,8 +163,6 @@ static int pci_piix_ide_initfn(PCIDevice *dev)
     vmstate_register(DEVICE(dev), 0, &vmstate_ide_pci, d);
 
     pci_piix_init_ports(d);
-
-    return 0;
 }
 
 int pci_piix3_xen_ide_unplug(DeviceState *dev)
@@ -238,7 +236,7 @@ static void piix3_ide_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = pci_piix_ide_initfn;
+    k->realize = pci_piix_ide_realize;
     k->exit = pci_piix_ide_exitfn;
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->device_id = PCI_DEVICE_ID_INTEL_82371SB_1;
@@ -258,7 +256,7 @@ static void piix3_ide_xen_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = pci_piix_ide_initfn;
+    k->realize = pci_piix_ide_realize;
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->device_id = PCI_DEVICE_ID_INTEL_82371SB_1;
     k->class_id = PCI_CLASS_STORAGE_IDE;
@@ -276,7 +274,7 @@ static void piix4_ide_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = pci_piix_ide_initfn;
+    k->realize = pci_piix_ide_realize;
     k->exit = pci_piix_ide_exitfn;
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->device_id = PCI_DEVICE_ID_INTEL_82371AB;
diff --git a/hw/ide/via.c b/hw/ide/via.c
index 4d8089d..7a5151c 100644
--- a/hw/ide/via.c
+++ b/hw/ide/via.c
@@ -172,7 +172,7 @@ static void vt82c686b_init_ports(PCIIDEState *d) {
 }
 
 /* via ide func */
-static int vt82c686b_ide_initfn(PCIDevice *dev)
+static void vt82c686b_ide_realize(PCIDevice *dev, Error **errp)
 {
     PCIIDEState *d = PCI_IDE(dev);
     uint8_t *pci_conf = dev->config;
@@ -187,8 +187,6 @@ static int vt82c686b_ide_initfn(PCIDevice *dev)
     vmstate_register(DEVICE(dev), 0, &vmstate_ide_pci, d);
 
     vt82c686b_init_ports(d);
-
-    return 0;
 }
 
 static void vt82c686b_ide_exitfn(PCIDevice *dev)
@@ -215,7 +213,7 @@ static void via_ide_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = vt82c686b_ide_initfn;
+    k->realize = vt82c686b_ide_realize;
     k->exit = vt82c686b_ide_exitfn;
     k->vendor_id = PCI_VENDOR_ID_VIA;
     k->device_id = PCI_DEVICE_ID_VIA_IDE;
diff --git a/hw/ipack/tpci200.c b/hw/ipack/tpci200.c
index b7031a0..1df02ee 100644
--- a/hw/ipack/tpci200.c
+++ b/hw/ipack/tpci200.c
@@ -573,7 +573,7 @@ static const MemoryRegionOps tpci200_las3_ops = {
     }
 };
 
-static int tpci200_initfn(PCIDevice *pci_dev)
+static void tpci200_realize(PCIDevice *pci_dev, Error **errp)
 {
     TPCI200State *s = TPCI200(pci_dev);
     uint8_t *c = s->dev.config;
@@ -609,8 +609,6 @@ static int tpci200_initfn(PCIDevice *pci_dev)
 
     ipack_bus_new_inplace(&s->bus, sizeof(s->bus), DEVICE(pci_dev), NULL,
                           N_MODULES, tpci200_set_irq);
-
-    return 0;
 }
 
 static const VMStateDescription vmstate_tpci200 = {
@@ -632,7 +630,7 @@ static void tpci200_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = tpci200_initfn;
+    k->realize = tpci200_realize;
     k->vendor_id = PCI_VENDOR_ID_TEWS;
     k->device_id = PCI_DEVICE_ID_TEWS_TPCI200;
     k->class_id = PCI_CLASS_BRIDGE_OTHER;
diff --git a/hw/isa/i82378.c b/hw/isa/i82378.c
index a7d9aa6..9fcba4f 100644
--- a/hw/isa/i82378.c
+++ b/hw/isa/i82378.c
@@ -58,7 +58,7 @@ static void i82378_request_pic_irq(void *opaque, int irq, int level)
     qemu_set_irq(s->i8259[irq], level);
 }
 
-static int i82378_initfn(PCIDevice *pci)
+static void i82378_realize(PCIDevice *pci, Error **errp)
 {
     DeviceState *dev = DEVICE(pci);
     I82378State *s = I82378(dev);
@@ -106,8 +106,6 @@ static int i82378_initfn(PCIDevice *pci)
 
     /* timer */
     isa_create_simple(isabus, "mc146818rtc");
-
-    return 0;
 }
 
 static void i82378_init(Object *obj)
@@ -124,7 +122,7 @@ static void i82378_class_init(ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    k->init = i82378_initfn;
+    k->realize = i82378_realize;
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->device_id = PCI_DEVICE_ID_INTEL_82378;
     k->revision = 0x03;
diff --git a/hw/isa/piix4.c b/hw/isa/piix4.c
index 1aa17d7..25cf73a 100644
--- a/hw/isa/piix4.c
+++ b/hw/isa/piix4.c
@@ -82,14 +82,13 @@ static const VMStateDescription vmstate_piix4 = {
     }
 };
 
-static int piix4_initfn(PCIDevice *dev)
+static void piix4_realize(PCIDevice *dev, Error **errp)
 {
     PIIX4State *d = DO_UPCAST(PIIX4State, dev, dev);
 
     isa_bus_new(&d->dev.qdev, pci_address_space_io(dev));
     piix4_dev = &d->dev;
     qemu_register_reset(piix4_reset, d);
-    return 0;
 }
 
 int piix4_init(PCIBus *bus, ISABus **isa_bus, int devfn)
@@ -106,7 +105,7 @@ static void piix4_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = piix4_initfn;
+    k->realize = piix4_realize;
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->device_id = PCI_DEVICE_ID_INTEL_82371AB_0;
     k->class_id = PCI_CLASS_BRIDGE_ISA;
diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c
index 17510ce..bc59f29 100644
--- a/hw/isa/vt82c686.c
+++ b/hw/isa/vt82c686.c
@@ -245,7 +245,7 @@ static const VMStateDescription vmstate_acpi = {
  * just register a PCI device now, functionalities will be implemented later.
  */
 
-static int vt82c686b_ac97_initfn(PCIDevice *dev)
+static void vt82c686b_ac97_realize(PCIDevice *dev, Error **errp)
 {
     VT686AC97State *s = DO_UPCAST(VT686AC97State, dev, dev);
     uint8_t *pci_conf = s->dev.config;
@@ -255,8 +255,6 @@ static int vt82c686b_ac97_initfn(PCIDevice *dev)
     pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_CAP_LIST |
                  PCI_STATUS_DEVSEL_MEDIUM);
     pci_set_long(pci_conf + PCI_INTERRUPT_PIN, 0x03);
-
-    return 0;
 }
 
 void vt82c686b_ac97_init(PCIBus *bus, int devfn)
@@ -272,7 +270,7 @@ static void via_ac97_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = vt82c686b_ac97_initfn;
+    k->realize = vt82c686b_ac97_realize;
     k->vendor_id = PCI_VENDOR_ID_VIA;
     k->device_id = PCI_DEVICE_ID_VIA_AC97;
     k->revision = 0x50;
@@ -288,7 +286,7 @@ static const TypeInfo via_ac97_info = {
     .class_init    = via_ac97_class_init,
 };
 
-static int vt82c686b_mc97_initfn(PCIDevice *dev)
+static void vt82c686b_mc97_realize(PCIDevice *dev, Error **errp)
 {
     VT686MC97State *s = DO_UPCAST(VT686MC97State, dev, dev);
     uint8_t *pci_conf = s->dev.config;
@@ -297,8 +295,6 @@ static int vt82c686b_mc97_initfn(PCIDevice *dev)
                  PCI_COMMAND_VGA_PALETTE);
     pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM);
     pci_set_long(pci_conf + PCI_INTERRUPT_PIN, 0x03);
-
-    return 0;
 }
 
 void vt82c686b_mc97_init(PCIBus *bus, int devfn)
@@ -314,7 +310,7 @@ static void via_mc97_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = vt82c686b_mc97_initfn;
+    k->realize = vt82c686b_mc97_realize;
     k->vendor_id = PCI_VENDOR_ID_VIA;
     k->device_id = PCI_DEVICE_ID_VIA_MC97;
     k->class_id = PCI_CLASS_COMMUNICATION_OTHER;
@@ -331,7 +327,7 @@ static const TypeInfo via_mc97_info = {
 };
 
 /* vt82c686 pm init */
-static int vt82c686b_pm_initfn(PCIDevice *dev)
+static void vt82c686b_pm_realize(PCIDevice *dev, Error **errp)
 {
     VT686PMState *s = DO_UPCAST(VT686PMState, dev, dev);
     uint8_t *pci_conf;
@@ -361,8 +357,6 @@ static int vt82c686b_pm_initfn(PCIDevice *dev)
     acpi_pm_tmr_init(&s->ar, pm_tmr_timer, &s->io);
     acpi_pm1_evt_init(&s->ar, pm_tmr_timer, &s->io);
     acpi_pm1_cnt_init(&s->ar, &s->io, 2);
-
-    return 0;
 }
 
 I2CBus *vt82c686b_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
@@ -391,7 +385,7 @@ static void via_pm_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = vt82c686b_pm_initfn;
+    k->realize = vt82c686b_pm_realize;
     k->config_write = pm_write_config;
     k->vendor_id = PCI_VENDOR_ID_VIA;
     k->device_id = PCI_DEVICE_ID_VIA_ACPI;
@@ -421,7 +415,7 @@ static const VMStateDescription vmstate_via = {
 };
 
 /* init the PCI-to-ISA bridge */
-static int vt82c686b_initfn(PCIDevice *d)
+static void vt82c686b_realize(PCIDevice *d, Error **errp)
 {
     VT82C686BState *vt82c = DO_UPCAST(VT82C686BState, dev, d);
     uint8_t *pci_conf;
@@ -450,8 +444,6 @@ static int vt82c686b_initfn(PCIDevice *d)
                                 &vt82c->superio);
 
     qemu_register_reset(vt82c686b_reset, d);
-
-    return 0;
 }
 
 ISABus *vt82c686b_init(PCIBus *bus, int devfn)
@@ -468,7 +460,7 @@ static void via_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = vt82c686b_initfn;
+    k->realize = vt82c686b_realize;
     k->config_write = vt82c686b_write_config;
     k->vendor_id = PCI_VENDOR_ID_VIA;
     k->device_id = PCI_DEVICE_ID_VIA_ISA_BRIDGE;
diff --git a/hw/misc/pci-testdev.c b/hw/misc/pci-testdev.c
index c78a63e..26b9b86 100644
--- a/hw/misc/pci-testdev.c
+++ b/hw/misc/pci-testdev.c
@@ -233,7 +233,7 @@ static const MemoryRegionOps pci_testdev_pio_ops = {
     },
 };
 
-static int pci_testdev_init(PCIDevice *pci_dev)
+static void pci_testdev_realize(PCIDevice *pci_dev, Error **errp)
 {
     PCITestDevState *d = PCI_TEST_DEV(pci_dev);
     uint8_t *pci_conf;
@@ -275,8 +275,6 @@ static int pci_testdev_init(PCIDevice *pci_dev)
         assert(r >= 0);
         test->hasnotifier = true;
     }
-
-    return 0;
 }
 
 static void
@@ -306,7 +304,7 @@ static void pci_testdev_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = pci_testdev_init;
+    k->realize = pci_testdev_realize;
     k->exit = pci_testdev_uninit;
     k->vendor_id = PCI_VENDOR_ID_REDHAT;
     k->device_id = PCI_DEVICE_ID_REDHAT_TEST;
diff --git a/hw/net/e1000.c b/hw/net/e1000.c
index a207e21..3405cb9 100644
--- a/hw/net/e1000.c
+++ b/hw/net/e1000.c
@@ -1537,7 +1537,7 @@ static void e1000_write_config(PCIDevice *pci_dev, uint32_t address,
 }
 
 
-static int pci_e1000_init(PCIDevice *pci_dev)
+static void pci_e1000_realize(PCIDevice *pci_dev, Error **errp)
 {
     DeviceState *dev = DEVICE(pci_dev);
     E1000State *d = E1000(pci_dev);
@@ -1581,8 +1581,6 @@ static int pci_e1000_init(PCIDevice *pci_dev)
 
     d->autoneg_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, e1000_autoneg_timer, d);
     d->mit_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, e1000_mit_timer, d);
-
-    return 0;
 }
 
 static void qdev_e1000_reset(DeviceState *dev)
@@ -1614,7 +1612,7 @@ static void e1000_class_init(ObjectClass *klass, void *data)
     E1000BaseClass *e = E1000_DEVICE_CLASS(klass);
     const E1000Info *info = data;
 
-    k->init = pci_e1000_init;
+    k->realize = pci_e1000_realize;
     k->exit = pci_e1000_uninit;
     k->romfile = "efi-e1000.rom";
     k->vendor_id = PCI_VENDOR_ID_INTEL;
diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c
index 7a4f9f8..c374c1a 100644
--- a/hw/net/eepro100.c
+++ b/hw/net/eepro100.c
@@ -1848,7 +1848,7 @@ static NetClientInfo net_eepro100_info = {
     .receive = nic_receive,
 };
 
-static int e100_nic_init(PCIDevice *pci_dev)
+static void e100_nic_realize(PCIDevice *pci_dev, Error **errp)
 {
     EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev);
     E100PCIDeviceInfo *info = eepro100_get_class(s);
@@ -1892,8 +1892,6 @@ static int e100_nic_init(PCIDevice *pci_dev)
     memcpy(s->vmstate, &vmstate_eepro100, sizeof(vmstate_eepro100));
     s->vmstate->name = qemu_get_queue(s->nic)->model;
     vmstate_register(&pci_dev->qdev, -1, s->vmstate, s);
-
-    return 0;
 }
 
 static void eepro100_instance_init(Object *obj)
@@ -2083,7 +2081,7 @@ static void eepro100_class_init(ObjectClass *klass, void *data)
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->class_id = PCI_CLASS_NETWORK_ETHERNET;
     k->romfile = "pxe-eepro100.rom";
-    k->init = e100_nic_init;
+    k->realize = e100_nic_realize;
     k->exit = pci_nic_uninit;
     k->device_id = info->device_id;
     k->revision = info->revision;
diff --git a/hw/net/ne2000.c b/hw/net/ne2000.c
index 4dea701..3492db3 100644
--- a/hw/net/ne2000.c
+++ b/hw/net/ne2000.c
@@ -709,7 +709,7 @@ static NetClientInfo net_ne2000_info = {
     .receive = ne2000_receive,
 };
 
-static int pci_ne2000_init(PCIDevice *pci_dev)
+static void pci_ne2000_realize(PCIDevice *pci_dev, Error **errp)
 {
     PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, pci_dev);
     NE2000State *s;
@@ -729,8 +729,6 @@ static int pci_ne2000_init(PCIDevice *pci_dev)
     s->nic = qemu_new_nic(&net_ne2000_info, &s->c,
                           object_get_typename(OBJECT(pci_dev)), pci_dev->qdev.id, s);
     qemu_format_nic_info_str(qemu_get_queue(s->nic), s->c.macaddr.a);
-
-    return 0;
 }
 
 static void pci_ne2000_exit(PCIDevice *pci_dev)
@@ -763,7 +761,7 @@ static void ne2000_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = pci_ne2000_init;
+    k->realize = pci_ne2000_realize;
     k->exit = pci_ne2000_exit;
     k->romfile = "efi-ne2k_pci.rom",
     k->vendor_id = PCI_VENDOR_ID_REALTEK;
diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c
index 2d1be06..f868108 100644
--- a/hw/net/rtl8139.c
+++ b/hw/net/rtl8139.c
@@ -3455,7 +3455,7 @@ static NetClientInfo net_rtl8139_info = {
     .link_status_changed = rtl8139_set_link_status,
 };
 
-static int pci_rtl8139_init(PCIDevice *dev)
+static void pci_rtl8139_realize(PCIDevice *dev, Error **errp)
 {
     RTL8139State *s = RTL8139(dev);
     DeviceState *d = DEVICE(dev);
@@ -3496,8 +3496,6 @@ static int pci_rtl8139_init(PCIDevice *dev)
     s->cplus_txbuffer_offset = 0;
 
     s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, rtl8139_timer, s);
-
-    return 0;
 }
 
 static void rtl8139_instance_init(Object *obj)
@@ -3519,7 +3517,7 @@ static void rtl8139_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = pci_rtl8139_init;
+    k->realize = pci_rtl8139_realize;
     k->exit = pci_rtl8139_uninit;
     k->romfile = "efi-rtl8139.rom";
     k->vendor_id = PCI_VENDOR_ID_REALTEK;
diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c
index a83d2a1..dfb328d 100644
--- a/hw/net/vmxnet3.c
+++ b/hw/net/vmxnet3.c
@@ -2125,7 +2125,7 @@ static const MemoryRegionOps b1_ops = {
     },
 };
 
-static int vmxnet3_pci_init(PCIDevice *pci_dev)
+static void vmxnet3_pci_realize(PCIDevice *pci_dev, Error **errp)
 {
     DeviceState *dev = DEVICE(pci_dev);
     VMXNET3State *s = VMXNET3(pci_dev);
@@ -2164,8 +2164,6 @@ static int vmxnet3_pci_init(PCIDevice *pci_dev)
 
     register_savevm(dev, "vmxnet3-msix", -1, 1,
                     vmxnet3_msix_save, vmxnet3_msix_load, s);
-
-    return 0;
 }
 
 static void vmxnet3_instance_init(Object *obj)
@@ -2501,7 +2499,7 @@ static void vmxnet3_class_init(ObjectClass *class, void *data)
     DeviceClass *dc = DEVICE_CLASS(class);
     PCIDeviceClass *c = PCI_DEVICE_CLASS(class);
 
-    c->init = vmxnet3_pci_init;
+    c->realize = vmxnet3_pci_realize;
     c->exit = vmxnet3_pci_uninit;
     c->vendor_id = PCI_VENDOR_ID_VMWARE;
     c->device_id = PCI_DEVICE_ID_VMWARE_VMXNET3;
diff --git a/hw/pci-bridge/dec.c b/hw/pci-bridge/dec.c
index a6ca940..28d0ff9 100644
--- a/hw/pci-bridge/dec.c
+++ b/hw/pci-bridge/dec.c
@@ -107,10 +107,9 @@ static int pci_dec_21154_device_init(SysBusDevice *dev)
     return 0;
 }
 
-static int dec_21154_pci_host_init(PCIDevice *d)
+static void dec_21154_pci_host_realize(PCIDevice *d, Error **errp)
 {
     /* PCI2PCI bridge same values as PearPC - check this */
-    return 0;
 }
 
 static void dec_21154_pci_host_class_init(ObjectClass *klass, void *data)
@@ -118,7 +117,7 @@ static void dec_21154_pci_host_class_init(ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    k->init = dec_21154_pci_host_init;
+    k->realize = dec_21154_pci_host_realize;
     k->vendor_id = PCI_VENDOR_ID_DEC;
     k->device_id = PCI_DEVICE_ID_DEC_21154;
     k->revision = 0x02;
diff --git a/hw/pci-host/apb.c b/hw/pci-host/apb.c
index f573875..89b5040 100644
--- a/hw/pci-host/apb.c
+++ b/hw/pci-host/apb.c
@@ -791,14 +791,13 @@ static int pci_pbm_init_device(SysBusDevice *dev)
     return 0;
 }
 
-static int pbm_pci_host_init(PCIDevice *d)
+static void pbm_pci_host_realize(PCIDevice *d, Error **errp)
 {
     pci_set_word(d->config + PCI_COMMAND,
                  PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
     pci_set_word(d->config + PCI_STATUS,
                  PCI_STATUS_FAST_BACK | PCI_STATUS_66MHZ |
                  PCI_STATUS_DEVSEL_MEDIUM);
-    return 0;
 }
 
 static void pbm_pci_host_class_init(ObjectClass *klass, void *data)
@@ -806,7 +805,7 @@ static void pbm_pci_host_class_init(ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    k->init = pbm_pci_host_init;
+    k->realize = pbm_pci_host_realize;
     k->vendor_id = PCI_VENDOR_ID_SUN;
     k->device_id = PCI_DEVICE_ID_SUN_SABRE;
     k->class_id = PCI_CLASS_BRIDGE_HOST;
diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c
index 56292ad..8bdd569 100644
--- a/hw/pci-host/bonito.c
+++ b/hw/pci-host/bonito.c
@@ -705,7 +705,7 @@ static int bonito_pcihost_initfn(SysBusDevice *dev)
     return 0;
 }
 
-static int bonito_initfn(PCIDevice *dev)
+static void bonito_realize(PCIDevice *dev, Error **errp)
 {
     PCIBonitoState *s = DO_UPCAST(PCIBonitoState, dev, dev);
     SysBusDevice *sysbus = SYS_BUS_DEVICE(s->pcihost);
@@ -766,8 +766,6 @@ static int bonito_initfn(PCIDevice *dev)
     pci_set_byte(dev->config + PCI_MAX_LAT, 0x00);
 
     qemu_register_reset(bonito_reset, s);
-
-    return 0;
 }
 
 PCIBus *bonito_init(qemu_irq *pic)
@@ -799,7 +797,7 @@ static void bonito_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = bonito_initfn;
+    k->realize = bonito_realize;
     k->vendor_id = 0xdf53;
     k->device_id = 0x00d5;
     k->revision = 0x01;
diff --git a/hw/pci-host/grackle.c b/hw/pci-host/grackle.c
index 6c7cfdb..bfe707a 100644
--- a/hw/pci-host/grackle.c
+++ b/hw/pci-host/grackle.c
@@ -114,10 +114,9 @@ static int pci_grackle_init_device(SysBusDevice *dev)
     return 0;
 }
 
-static int grackle_pci_host_init(PCIDevice *d)
+static void grackle_pci_host_realize(PCIDevice *d, Error **errp)
 {
     d->config[0x09] = 0x01;
-    return 0;
 }
 
 static void grackle_pci_class_init(ObjectClass *klass, void *data)
@@ -125,7 +124,7 @@ static void grackle_pci_class_init(ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    k->init      = grackle_pci_host_init;
+    k->realize   = grackle_pci_host_realize;
     k->vendor_id = PCI_VENDOR_ID_MOTOROLA;
     k->device_id = PCI_DEVICE_ID_MOTOROLA_MPC106;
     k->revision  = 0x00;
diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
index 1530038..72f1ee2 100644
--- a/hw/pci-host/piix.c
+++ b/hw/pci-host/piix.c
@@ -295,14 +295,13 @@ static void i440fx_pcihost_realize(DeviceState *dev, Error **errp)
     sysbus_init_ioports(sbd, 0xcfc, 4);
 }
 
-static int i440fx_initfn(PCIDevice *dev)
+static void i440fx_realize(PCIDevice *dev, Error **errp)
 {
     PCII440FXState *d = I440FX_PCI_DEVICE(dev);
 
     dev->config[I440FX_SMRAM] = 0x02;
 
     cpu_smm_register(&i440fx_set_smm, d);
-    return 0;
 }
 
 PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
@@ -631,7 +630,7 @@ static const MemoryRegionOps rcr_ops = {
     .endianness = DEVICE_LITTLE_ENDIAN
 };
 
-static int piix3_initfn(PCIDevice *dev)
+static void piix3_realize(PCIDevice *dev, Error **errp)
 {
     PIIX3State *d = DO_UPCAST(PIIX3State, dev, dev);
 
@@ -643,7 +642,6 @@ static int piix3_initfn(PCIDevice *dev)
                                         &d->rcr_mem, 1);
 
     qemu_register_reset(piix3_reset, d);
-    return 0;
 }
 
 static void piix3_class_init(ObjectClass *klass, void *data)
@@ -654,7 +652,7 @@ static void piix3_class_init(ObjectClass *klass, void *data)
     dc->desc        = "ISA bridge";
     dc->vmsd        = &vmstate_piix3;
     dc->hotpluggable   = false;
-    k->init         = piix3_initfn;
+    k->realize      = piix3_realize;
     k->config_write = piix3_write_config;
     k->vendor_id    = PCI_VENDOR_ID_INTEL;
     /* 82371SB PIIX3 PCI-to-ISA bridge (Step A1) */
@@ -682,7 +680,7 @@ static void piix3_xen_class_init(ObjectClass *klass, void *data)
     dc->desc        = "ISA bridge";
     dc->vmsd        = &vmstate_piix3;
     dc->hotpluggable   = false;
-    k->init         = piix3_initfn;
+    k->realize      = piix3_realize;
     k->config_write = piix3_write_config_xen;
     k->vendor_id    = PCI_VENDOR_ID_INTEL;
     /* 82371SB PIIX3 PCI-to-ISA bridge (Step A1) */
@@ -707,7 +705,7 @@ static void i440fx_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = i440fx_initfn;
+    k->realize = i440fx_realize;
     k->config_write = i440fx_write_config;
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->device_id = PCI_DEVICE_ID_INTEL_82441;
diff --git a/hw/pci-host/ppce500.c b/hw/pci-host/ppce500.c
index 574f8b2..613ba73 100644
--- a/hw/pci-host/ppce500.c
+++ b/hw/pci-host/ppce500.c
@@ -416,7 +416,7 @@ static const VMStateDescription vmstate_ppce500_pci = {
 
 #include "exec/address-spaces.h"
 
-static int e500_pcihost_bridge_initfn(PCIDevice *d)
+static void e500_pcihost_bridge_realize(PCIDevice *d, Error **errp)
 {
     PPCE500PCIBridgeState *b = PPC_E500_PCI_BRIDGE(d);
     PPCE500CCSRState *ccsr = CCSR(container_get(qdev_get_machine(),
@@ -430,8 +430,6 @@ static int e500_pcihost_bridge_initfn(PCIDevice *d)
     memory_region_init_alias(&b->bar0, OBJECT(ccsr), "e500-pci-bar0", &ccsr->ccsr_space,
                              0, int128_get64(ccsr->ccsr_space.size));
     pci_register_bar(d, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &b->bar0);
-
-    return 0;
 }
 
 static AddressSpace *e500_pcihost_set_iommu(PCIBus *bus, void *opaque,
@@ -500,7 +498,7 @@ static void e500_host_bridge_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = e500_pcihost_bridge_initfn;
+    k->realize = e500_pcihost_bridge_realize;
     k->vendor_id = PCI_VENDOR_ID_FREESCALE;
     k->device_id = PCI_DEVICE_ID_MPC8533E;
     k->class_id = PCI_CLASS_PROCESSOR_POWERPC;
diff --git a/hw/pci-host/prep.c b/hw/pci-host/prep.c
index 1de3681..6cea6ff 100644
--- a/hw/pci-host/prep.c
+++ b/hw/pci-host/prep.c
@@ -289,7 +289,7 @@ static void raven_pcihost_initfn(Object *obj)
     qdev_prop_set_bit(pci_dev, "multifunction", false);
 }
 
-static int raven_init(PCIDevice *d)
+static void raven_realize(PCIDevice *d, Error **errp)
 {
     RavenPCIState *s = RAVEN_PCI_DEVICE(d);
     char *filename;
@@ -330,8 +330,6 @@ static int raven_init(PCIDevice *d)
             g_free(filename);
         }
     }
-
-    return 0;
 }
 
 static const VMStateDescription vmstate_raven = {
@@ -349,7 +347,7 @@ static void raven_class_init(ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    k->init = raven_init;
+    k->realize = raven_realize;
     k->vendor_id = PCI_VENDOR_ID_MOTOROLA;
     k->device_id = PCI_DEVICE_ID_MOTOROLA_RAVEN;
     k->revision = 0x00;
diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c
index b20bad8..df60e61 100644
--- a/hw/pci-host/q35.c
+++ b/hw/pci-host/q35.c
@@ -390,7 +390,7 @@ static void mch_init_dmar(MCHPCIState *mch)
     pci_setup_iommu(pci_bus, q35_host_dma_iommu, mch->iommu);
 }
 
-static int mch_init(PCIDevice *d)
+static void mch_realize(PCIDevice *d, Error **errp)
 {
     int i;
     MCHPCIState *mch = MCH_PCI_DEVICE(d);
@@ -418,7 +418,6 @@ static int mch_init(PCIDevice *d)
     if (qemu_opt_get_bool(qemu_get_machine_opts(), "iommu", false)) {
         mch_init_dmar(mch);
     }
-    return 0;
 }
 
 uint64_t mch_mcfg_base(void)
@@ -436,7 +435,7 @@ static void mch_class_init(ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    k->init = mch_init;
+    k->realize = mch_realize;
     k->config_write = mch_write_config;
     dc->reset = mch_reset;
     set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
diff --git a/hw/pci-host/uninorth.c b/hw/pci-host/uninorth.c
index 21f805f..53f2b59 100644
--- a/hw/pci-host/uninorth.c
+++ b/hw/pci-host/uninorth.c
@@ -315,37 +315,33 @@ PCIBus *pci_pmac_u3_init(qemu_irq *pic,
     return h->bus;
 }
 
-static int unin_main_pci_host_init(PCIDevice *d)
+static void unin_main_pci_host_realize(PCIDevice *d, Error **errp)
 {
     d->config[0x0C] = 0x08; // cache_line_size
     d->config[0x0D] = 0x10; // latency_timer
     d->config[0x34] = 0x00; // capabilities_pointer
-    return 0;
 }
 
-static int unin_agp_pci_host_init(PCIDevice *d)
+static void unin_agp_pci_host_realize(PCIDevice *d, Error **errp)
 {
     d->config[0x0C] = 0x08; // cache_line_size
     d->config[0x0D] = 0x10; // latency_timer
     //    d->config[0x34] = 0x80; // capabilities_pointer
-    return 0;
 }
 
-static int u3_agp_pci_host_init(PCIDevice *d)
+static void u3_agp_pci_host_realize(PCIDevice *d, Error **errp)
 {
     /* cache line size */
     d->config[0x0C] = 0x08;
     /* latency timer */
     d->config[0x0D] = 0x10;
-    return 0;
 }
 
-static int unin_internal_pci_host_init(PCIDevice *d)
+static void unin_internal_pci_host_realize(PCIDevice *d, Error **errp)
 {
     d->config[0x0C] = 0x08; // cache_line_size
     d->config[0x0D] = 0x10; // latency_timer
     d->config[0x34] = 0x00; // capabilities_pointer
-    return 0;
 }
 
 static void unin_main_pci_host_class_init(ObjectClass *klass, void *data)
@@ -353,7 +349,7 @@ static void unin_main_pci_host_class_init(ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    k->init      = unin_main_pci_host_init;
+    k->realize   = unin_main_pci_host_realize;
     k->vendor_id = PCI_VENDOR_ID_APPLE;
     k->device_id = PCI_DEVICE_ID_APPLE_UNI_N_PCI;
     k->revision  = 0x00;
@@ -377,7 +373,7 @@ static void u3_agp_pci_host_class_init(ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    k->init      = u3_agp_pci_host_init;
+    k->realize   = u3_agp_pci_host_realize;
     k->vendor_id = PCI_VENDOR_ID_APPLE;
     k->device_id = PCI_DEVICE_ID_APPLE_U3_AGP;
     k->revision  = 0x00;
@@ -401,7 +397,7 @@ static void unin_agp_pci_host_class_init(ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    k->init      = unin_agp_pci_host_init;
+    k->realize   = unin_agp_pci_host_realize;
     k->vendor_id = PCI_VENDOR_ID_APPLE;
     k->device_id = PCI_DEVICE_ID_APPLE_UNI_N_AGP;
     k->revision  = 0x00;
@@ -425,7 +421,7 @@ static void unin_internal_pci_host_class_init(ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    k->init      = unin_internal_pci_host_init;
+    k->realize   = unin_internal_pci_host_realize;
     k->vendor_id = PCI_VENDOR_ID_APPLE;
     k->device_id = PCI_DEVICE_ID_APPLE_UNI_N_I_PCI;
     k->revision  = 0x00;
diff --git a/hw/pci-host/versatile.c b/hw/pci-host/versatile.c
index 71ff0de..6d23553 100644
--- a/hw/pci-host/versatile.c
+++ b/hw/pci-host/versatile.c
@@ -456,12 +456,11 @@ static void pci_vpb_realize(DeviceState *dev, Error **errp)
     object_property_set_bool(OBJECT(&s->pci_dev), true, "realized", errp);
 }
 
-static int versatile_pci_host_init(PCIDevice *d)
+static void versatile_pci_host_realize(PCIDevice *d, Error **errp)
 {
     pci_set_word(d->config + PCI_STATUS,
                  PCI_STATUS_66MHZ | PCI_STATUS_DEVSEL_MEDIUM);
     pci_set_byte(d->config + PCI_LATENCY_TIMER, 0x10);
-    return 0;
 }
 
 static void versatile_pci_host_class_init(ObjectClass *klass, void *data)
@@ -469,7 +468,7 @@ static void versatile_pci_host_class_init(ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    k->init = versatile_pci_host_init;
+    k->realize = versatile_pci_host_realize;
     k->vendor_id = PCI_VENDOR_ID_XILINX;
     k->device_id = PCI_DEVICE_ID_XILINX_XC2VP30;
     k->class_id = PCI_CLASS_PROCESSOR_CO;
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index 10e5355..27b914a 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -1220,7 +1220,7 @@ static Property sdhci_properties[] = {
     DEFINE_PROP_END_OF_LIST(),
 };
 
-static int sdhci_pci_init(PCIDevice *dev)
+static void sdhci_pci_realize(PCIDevice *dev, Error **errp)
 {
     SDHCIState *s = PCI_SDHCI(dev);
     dev->config[PCI_CLASS_PROG] = 0x01; /* Standard Host supported DMA */
@@ -1232,7 +1232,6 @@ static int sdhci_pci_init(PCIDevice *dev)
     memory_region_init_io(&s->iomem, OBJECT(s), &sdhci_mmio_ops, s, "sdhci",
             SDHC_REGISTERS_MAP_SIZE);
     pci_register_bar(dev, 0, 0, &s->iomem);
-    return 0;
 }
 
 static void sdhci_pci_exit(PCIDevice *dev)
@@ -1246,7 +1245,7 @@ static void sdhci_pci_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = sdhci_pci_init;
+    k->realize = sdhci_pci_realize;
     k->exit = sdhci_pci_exit;
     k->vendor_id = PCI_VENDOR_ID_REDHAT;
     k->device_id = PCI_DEVICE_ID_REDHAT_SDHCI;
diff --git a/hw/usb/hcd-ehci-pci.c b/hw/usb/hcd-ehci-pci.c
index 490f2b6..4c80707 100644
--- a/hw/usb/hcd-ehci-pci.c
+++ b/hw/usb/hcd-ehci-pci.c
@@ -26,7 +26,7 @@ typedef struct EHCIPCIInfo {
     bool companion;
 } EHCIPCIInfo;
 
-static int usb_ehci_pci_initfn(PCIDevice *dev)
+static void usb_ehci_pci_realize(PCIDevice *dev, Error **errp)
 {
     EHCIPCIState *i = PCI_EHCI(dev);
     EHCIState *s = &i->ehci;
@@ -66,8 +66,6 @@ static int usb_ehci_pci_initfn(PCIDevice *dev)
 
     usb_ehci_realize(s, DEVICE(dev), NULL);
     pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->mem);
-
-    return 0;
 }
 
 static void usb_ehci_pci_init(Object *obj)
@@ -139,7 +137,7 @@ static void ehci_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = usb_ehci_pci_initfn;
+    k->realize = usb_ehci_pci_realize;
     k->exit = usb_ehci_pci_exit;
     k->class_id = PCI_CLASS_SERIAL_USB;
     k->config_write = usb_ehci_pci_write_config;
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 776699b..09eaa1f 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -3567,7 +3567,7 @@ static void usb_xhci_init(XHCIState *xhci)
     }
 }
 
-static int usb_xhci_initfn(struct PCIDevice *dev)
+static void usb_xhci_realize(struct PCIDevice *dev, Error **errp)
 {
     int i, ret;
 
@@ -3646,8 +3646,6 @@ static int usb_xhci_initfn(struct PCIDevice *dev)
                   &xhci->mem, 0, OFF_MSIX_PBA,
                   0x90);
     }
-
-    return 0;
 }
 
 static void usb_xhci_exit(PCIDevice *dev)
@@ -3887,7 +3885,7 @@ static void xhci_class_init(ObjectClass *klass, void *data)
     dc->props   = xhci_properties;
     dc->reset   = xhci_reset;
     set_bit(DEVICE_CATEGORY_USB, dc->categories);
-    k->init         = usb_xhci_initfn;
+    k->realize      = usb_xhci_realize;
     k->exit         = usb_xhci_exit;
     k->vendor_id    = PCI_VENDOR_ID_NEC;
     k->device_id    = PCI_DEVICE_ID_NEC_UPD720200;
diff --git a/hw/watchdog/wdt_i6300esb.c b/hw/watchdog/wdt_i6300esb.c
index 33dd6d4..b2d158f 100644
--- a/hw/watchdog/wdt_i6300esb.c
+++ b/hw/watchdog/wdt_i6300esb.c
@@ -408,7 +408,7 @@ static const VMStateDescription vmstate_i6300esb = {
     }
 };
 
-static int i6300esb_init(PCIDevice *dev)
+static void i6300esb_realize(PCIDevice *dev, Error **errp)
 {
     I6300State *d = DO_UPCAST(I6300State, dev, dev);
 
@@ -421,8 +421,6 @@ static int i6300esb_init(PCIDevice *dev)
                           "i6300esb", 0x10);
     pci_register_bar(&d->dev, 0, 0, &d->io_mem);
     /* qemu_register_coalesced_mmio (addr, 0x10); ? */
-
-    return 0;
 }
 
 static WatchdogTimerModel model = {
@@ -437,7 +435,7 @@ static void i6300esb_class_init(ObjectClass *klass, void *data)
 
     k->config_read = i6300esb_config_read;
     k->config_write = i6300esb_config_write;
-    k->init = i6300esb_init;
+    k->realize = i6300esb_realize;
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->device_id = PCI_DEVICE_ID_INTEL_ESB_9;
     k->class_id = PCI_CLASS_SYSTEM_OTHER;
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 09/96] pcnet: pcnet_common_init() always returns 0, change to void
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (7 preceding siblings ...)
  2015-02-18 21:44 ` [Qemu-devel] [PULL 08/96] pci: Trivial device model conversions " Michael S. Tsirkin
@ 2015-02-18 21:44 ` Michael S. Tsirkin
  2015-02-18 21:45 ` [Qemu-devel] [PULL 10/96] pcnet: Convert to realize Michael S. Tsirkin
                   ` (89 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:44 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Markus Armbruster,
	Gonglei, Gerd Hoffmann, Stefan Hajnoczi, Paolo Bonzini

From: Markus Armbruster <armbru@redhat.com>

The next commit will exploit the fact it never fails.  This one makes
it obvious.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/net/pcnet.h     | 2 +-
 hw/net/lance.c     | 3 ++-
 hw/net/pcnet-pci.c | 3 ++-
 hw/net/pcnet.c     | 4 +---
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/hw/net/pcnet.h b/hw/net/pcnet.h
index 3f12fe3..79c4c84 100644
--- a/hw/net/pcnet.h
+++ b/hw/net/pcnet.h
@@ -63,6 +63,6 @@ uint32_t pcnet_bcr_readw(PCNetState *s, uint32_t rap);
 int pcnet_can_receive(NetClientState *nc);
 ssize_t pcnet_receive(NetClientState *nc, const uint8_t *buf, size_t size_);
 void pcnet_set_link_status(NetClientState *nc);
-int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info);
+void pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info);
 extern const VMStateDescription vmstate_pcnet;
 #endif
diff --git a/hw/net/lance.c b/hw/net/lance.c
index ff7e789..4baa016 100644
--- a/hw/net/lance.c
+++ b/hw/net/lance.c
@@ -126,7 +126,8 @@ static int lance_init(SysBusDevice *sbd)
 
     s->phys_mem_read = ledma_memory_read;
     s->phys_mem_write = ledma_memory_write;
-    return pcnet_common_init(dev, s, &net_lance_info);
+    pcnet_common_init(dev, s, &net_lance_info);
+    return 0;
 }
 
 static void lance_reset(DeviceState *dev)
diff --git a/hw/net/pcnet-pci.c b/hw/net/pcnet-pci.c
index 5df79f0..9677c12 100644
--- a/hw/net/pcnet-pci.c
+++ b/hw/net/pcnet-pci.c
@@ -316,7 +316,8 @@ static int pci_pcnet_init(PCIDevice *pci_dev)
     s->phys_mem_write = pci_physical_memory_write;
     s->dma_opaque = pci_dev;
 
-    return pcnet_common_init(DEVICE(pci_dev), s, &net_pci_pcnet_info);
+    pcnet_common_init(DEVICE(pci_dev), s, &net_pci_pcnet_info);
+    return 0;
 }
 
 static void pci_reset(DeviceState *dev)
diff --git a/hw/net/pcnet.c b/hw/net/pcnet.c
index 7778b9a..bdfd38f 100644
--- a/hw/net/pcnet.c
+++ b/hw/net/pcnet.c
@@ -1712,7 +1712,7 @@ const VMStateDescription vmstate_pcnet = {
     }
 };
 
-int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info)
+void pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info)
 {
     int i;
     uint16_t checksum;
@@ -1751,6 +1751,4 @@ int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info)
     *(uint16_t *)&s->prom[12] = cpu_to_le16(checksum);
 
     s->lnkst = 0x40; /* initial link state: up */
-
-    return 0;
 }
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 10/96] pcnet: Convert to realize
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (8 preceding siblings ...)
  2015-02-18 21:44 ` [Qemu-devel] [PULL 09/96] pcnet: pcnet_common_init() always returns 0, change to void Michael S. Tsirkin
@ 2015-02-18 21:45 ` Michael S. Tsirkin
  2015-02-18 21:45 ` [Qemu-devel] [PULL 11/96] serial-pci: " Michael S. Tsirkin
                   ` (88 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:45 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Markus Armbruster,
	Gonglei, Gerd Hoffmann, Paolo Bonzini

From: Markus Armbruster <armbru@redhat.com>

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/net/pcnet-pci.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/net/pcnet-pci.c b/hw/net/pcnet-pci.c
index 9677c12..8305d1b 100644
--- a/hw/net/pcnet-pci.c
+++ b/hw/net/pcnet-pci.c
@@ -278,7 +278,7 @@ static NetClientInfo net_pci_pcnet_info = {
     .link_status_changed = pcnet_set_link_status,
 };
 
-static int pci_pcnet_init(PCIDevice *pci_dev)
+static void pci_pcnet_realize(PCIDevice *pci_dev, Error **errp)
 {
     PCIPCNetState *d = PCI_PCNET(pci_dev);
     PCNetState *s = &d->state;
@@ -317,7 +317,6 @@ static int pci_pcnet_init(PCIDevice *pci_dev)
     s->dma_opaque = pci_dev;
 
     pcnet_common_init(DEVICE(pci_dev), s, &net_pci_pcnet_info);
-    return 0;
 }
 
 static void pci_reset(DeviceState *dev)
@@ -347,7 +346,7 @@ static void pcnet_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = pci_pcnet_init;
+    k->realize = pci_pcnet_realize;
     k->exit = pci_pcnet_uninit;
     k->romfile = "efi-pcnet.rom",
     k->vendor_id = PCI_VENDOR_ID_AMD;
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 11/96] serial-pci: Convert to realize
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (9 preceding siblings ...)
  2015-02-18 21:45 ` [Qemu-devel] [PULL 10/96] pcnet: Convert to realize Michael S. Tsirkin
@ 2015-02-18 21:45 ` Michael S. Tsirkin
  2015-02-18 21:45 ` [Qemu-devel] [PULL 12/96] ide/ich: " Michael S. Tsirkin
                   ` (87 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:45 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Peter Crosthwaite, Juan Quintela, dgilbert,
	Markus Armbruster, Gonglei, Paolo Bonzini

From: Markus Armbruster <armbru@redhat.com>

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/char/serial-pci.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/hw/char/serial-pci.c b/hw/char/serial-pci.c
index f05c9b4..467c3b4 100644
--- a/hw/char/serial-pci.c
+++ b/hw/char/serial-pci.c
@@ -48,7 +48,7 @@ typedef struct PCIMultiSerialState {
     uint8_t      prog_if;
 } PCIMultiSerialState;
 
-static int serial_pci_init(PCIDevice *dev)
+static void serial_pci_realize(PCIDevice *dev, Error **errp)
 {
     PCISerialState *pci = DO_UPCAST(PCISerialState, dev, dev);
     SerialState *s = &pci->state;
@@ -57,9 +57,8 @@ static int serial_pci_init(PCIDevice *dev)
     s->baudbase = 115200;
     serial_realize_core(s, &err);
     if (err != NULL) {
-        qerror_report_err(err);
-        error_free(err);
-        return -1;
+        error_propagate(errp, err);
+        return;
     }
 
     pci->dev.config[PCI_CLASS_PROG] = pci->prog_if;
@@ -68,7 +67,6 @@ static int serial_pci_init(PCIDevice *dev)
 
     memory_region_init_io(&s->io, OBJECT(pci), &serial_io_ops, s, "serial", 8);
     pci_register_bar(&pci->dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &s->io);
-    return 0;
 }
 
 static void multi_serial_irq_mux(void *opaque, int n, int level)
@@ -85,7 +83,7 @@ static void multi_serial_irq_mux(void *opaque, int n, int level)
     pci_set_irq(&pci->dev, pending);
 }
 
-static int multi_serial_pci_init(PCIDevice *dev)
+static void multi_serial_pci_realize(PCIDevice *dev, Error **errp)
 {
     PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
     PCIMultiSerialState *pci = DO_UPCAST(PCIMultiSerialState, dev, dev);
@@ -116,9 +114,8 @@ static int multi_serial_pci_init(PCIDevice *dev)
         s->baudbase = 115200;
         serial_realize_core(s, &err);
         if (err != NULL) {
-            qerror_report_err(err);
-            error_free(err);
-            return -1;
+            error_propagate(errp, err);
+            return;
         }
         s->irq = pci->irqs[i];
         pci->name[i] = g_strdup_printf("uart #%d", i+1);
@@ -126,7 +123,6 @@ static int multi_serial_pci_init(PCIDevice *dev)
                               pci->name[i], 8);
         memory_region_add_subregion(&pci->iobar, 8 * i, &s->io);
     }
-    return 0;
 }
 
 static void serial_pci_exit(PCIDevice *dev)
@@ -203,7 +199,7 @@ static void serial_pci_class_initfn(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *pc = PCI_DEVICE_CLASS(klass);
-    pc->init = serial_pci_init;
+    pc->realize = serial_pci_realize;
     pc->exit = serial_pci_exit;
     pc->vendor_id = PCI_VENDOR_ID_REDHAT;
     pc->device_id = PCI_DEVICE_ID_REDHAT_SERIAL;
@@ -218,7 +214,7 @@ static void multi_2x_serial_pci_class_initfn(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *pc = PCI_DEVICE_CLASS(klass);
-    pc->init = multi_serial_pci_init;
+    pc->realize = multi_serial_pci_realize;
     pc->exit = multi_serial_pci_exit;
     pc->vendor_id = PCI_VENDOR_ID_REDHAT;
     pc->device_id = PCI_DEVICE_ID_REDHAT_SERIAL2;
@@ -233,7 +229,7 @@ static void multi_4x_serial_pci_class_initfn(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *pc = PCI_DEVICE_CLASS(klass);
-    pc->init = multi_serial_pci_init;
+    pc->realize = multi_serial_pci_realize;
     pc->exit = multi_serial_pci_exit;
     pc->vendor_id = PCI_VENDOR_ID_REDHAT;
     pc->device_id = PCI_DEVICE_ID_REDHAT_SERIAL4;
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 12/96] ide/ich: Convert to realize
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (10 preceding siblings ...)
  2015-02-18 21:45 ` [Qemu-devel] [PULL 11/96] serial-pci: " Michael S. Tsirkin
@ 2015-02-18 21:45 ` Michael S. Tsirkin
  2015-02-18 21:45 ` [Qemu-devel] [PULL 13/96] cirrus-vga: " Michael S. Tsirkin
                   ` (86 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:45 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Peter Maydell, Juan Quintela, dgilbert,
	Markus Armbruster, Gonglei, Stefan Hajnoczi

From: Markus Armbruster <armbru@redhat.com>

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/ide/ich.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/hw/ide/ich.c b/hw/ide/ich.c
index fb1d095..b1d8874 100644
--- a/hw/ide/ich.c
+++ b/hw/ide/ich.c
@@ -98,7 +98,7 @@ static void pci_ich9_reset(DeviceState *dev)
     ahci_reset(&d->ahci);
 }
 
-static int pci_ich9_ahci_init(PCIDevice *dev)
+static void pci_ich9_ahci_realize(PCIDevice *dev, Error **errp)
 {
     struct AHCIPCIState *d;
     int sata_cap_offset;
@@ -123,10 +123,11 @@ static int pci_ich9_ahci_init(PCIDevice *dev)
     pci_register_bar(dev, ICH9_MEM_BAR, PCI_BASE_ADDRESS_SPACE_MEMORY,
                      &d->ahci.mem);
 
-    sata_cap_offset = pci_add_capability(dev, PCI_CAP_ID_SATA,
-                                         ICH9_SATA_CAP_OFFSET, SATA_CAP_SIZE);
+    sata_cap_offset = pci_add_capability2(dev, PCI_CAP_ID_SATA,
+                                          ICH9_SATA_CAP_OFFSET, SATA_CAP_SIZE,
+                                          errp);
     if (sata_cap_offset < 0) {
-        return sata_cap_offset;
+        return;
     }
 
     sata_cap = dev->config + sata_cap_offset;
@@ -139,8 +140,6 @@ static int pci_ich9_ahci_init(PCIDevice *dev)
      * should be PMCAP, the Intel ICH9 data sheet specifies that the ICH9
      * AHCI device puts the MSI capability first, pointing to 0x80. */
     msi_init(dev, ICH9_MSI_CAP_OFFSET, 1, true, false);
-
-    return 0;
 }
 
 static void pci_ich9_uninit(PCIDevice *dev)
@@ -158,7 +157,7 @@ static void ich_ahci_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = pci_ich9_ahci_init;
+    k->realize = pci_ich9_ahci_realize;
     k->exit = pci_ich9_uninit;
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->device_id = PCI_DEVICE_ID_INTEL_82801IR;
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 13/96] cirrus-vga: Convert to realize
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (11 preceding siblings ...)
  2015-02-18 21:45 ` [Qemu-devel] [PULL 12/96] ide/ich: " Michael S. Tsirkin
@ 2015-02-18 21:45 ` Michael S. Tsirkin
  2015-02-18 21:45 ` [Qemu-devel] [PULL 14/96] qxl: " Michael S. Tsirkin
                   ` (85 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:45 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Markus Armbruster,
	Gonglei, Gerd Hoffmann, David Gibson

From: Markus Armbruster <armbru@redhat.com>

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/display/cirrus_vga.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/hw/display/cirrus_vga.c b/hw/display/cirrus_vga.c
index 3a53f20..c9b2639 100644
--- a/hw/display/cirrus_vga.c
+++ b/hw/display/cirrus_vga.c
@@ -3006,7 +3006,7 @@ static const TypeInfo isa_cirrus_vga_info = {
  *
  ***************************************/
 
-static int pci_cirrus_vga_initfn(PCIDevice *dev)
+static void pci_cirrus_vga_realize(PCIDevice *dev, Error **errp)
 {
      PCICirrusVGAState *d = DO_UPCAST(PCICirrusVGAState, dev, dev);
      CirrusVGAState *s = &d->cirrus_vga;
@@ -3017,9 +3017,9 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
        Also accept 8 MB/16 MB for backward compatibility. */
      if (s->vga.vram_size_mb != 4 && s->vga.vram_size_mb != 8 &&
          s->vga.vram_size_mb != 16) {
-         error_report("Invalid cirrus_vga ram size '%u'",
-                      s->vga.vram_size_mb);
-         return -1;
+         error_setg(errp, "Invalid cirrus_vga ram size '%u'",
+                    s->vga.vram_size_mb);
+         return;
      }
      /* setup VGA */
      vga_common_init(&s->vga, OBJECT(dev), true);
@@ -3044,7 +3044,6 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
      if (device_id == CIRRUS_ID_CLGD5446) {
          pci_register_bar(&d->dev, 1, 0, &s->cirrus_mmio_io);
      }
-     return 0;
 }
 
 static Property pci_vga_cirrus_properties[] = {
@@ -3058,7 +3057,7 @@ static void cirrus_vga_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = pci_cirrus_vga_initfn;
+    k->realize = pci_cirrus_vga_realize;
     k->romfile = VGABIOS_CIRRUS_FILENAME;
     k->vendor_id = PCI_VENDOR_ID_CIRRUS;
     k->device_id = CIRRUS_ID_CLGD5446;
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 14/96] qxl: Convert to realize
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (12 preceding siblings ...)
  2015-02-18 21:45 ` [Qemu-devel] [PULL 13/96] cirrus-vga: " Michael S. Tsirkin
@ 2015-02-18 21:45 ` Michael S. Tsirkin
  2015-02-18 21:45 ` [Qemu-devel] [PULL 15/96] pci-assign: " Michael S. Tsirkin
                   ` (84 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:45 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Markus Armbruster,
	Gonglei, Gerd Hoffmann

From: Markus Armbruster <armbru@redhat.com>

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/display/qxl.c | 36 +++++++++++++++++-------------------
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/hw/display/qxl.c b/hw/display/qxl.c
index 61df477..208346d 100644
--- a/hw/display/qxl.c
+++ b/hw/display/qxl.c
@@ -1916,7 +1916,7 @@ static void qxl_init_ramsize(PCIQXLDevice *qxl)
     qxl->vram_size = msb_mask(qxl->vram_size * 2 - 1);
 }
 
-static int qxl_init_common(PCIQXLDevice *qxl)
+static void qxl_realize_common(PCIQXLDevice *qxl, Error **errp)
 {
     uint8_t* config = qxl->pci.config;
     uint32_t pci_device_rev;
@@ -1948,9 +1948,9 @@ static int qxl_init_common(PCIQXLDevice *qxl)
         io_size = msb_mask(QXL_IO_RANGE_SIZE * 2 - 1);
         break;
     default:
-        error_report("Invalid revision %d for qxl device (max %d)",
-                     qxl->revision, QXL_DEFAULT_REVISION);
-        return -1;
+        error_setg(errp, "Invalid revision %d for qxl device (max %d)",
+                   qxl->revision, QXL_DEFAULT_REVISION);
+        return;
     }
 
     pci_set_byte(&config[PCI_REVISION_ID], pci_device_rev);
@@ -2014,9 +2014,9 @@ static int qxl_init_common(PCIQXLDevice *qxl)
 
     qxl->ssd.qxl.base.sif = &qxl_interface.base;
     if (qemu_spice_add_display_interface(&qxl->ssd.qxl, qxl->vga.con) != 0) {
-        error_report("qxl interface %d.%d not supported by spice-server",
-                     SPICE_INTERFACE_QXL_MAJOR, SPICE_INTERFACE_QXL_MINOR);
-        return -1;
+        error_setg(errp, "qxl interface %d.%d not supported by spice-server",
+                   SPICE_INTERFACE_QXL_MAJOR, SPICE_INTERFACE_QXL_MINOR);
+        return;
     }
     qemu_add_vm_change_state_handler(qxl_vm_change_state_handler, qxl);
 
@@ -2025,15 +2025,13 @@ static int qxl_init_common(PCIQXLDevice *qxl)
 
     qxl->update_area_bh = qemu_bh_new(qxl_render_update_area_bh, qxl);
     qxl->ssd.cursor_bh = qemu_bh_new(qemu_spice_cursor_refresh_bh, &qxl->ssd);
-
-    return 0;
 }
 
-static int qxl_init_primary(PCIDevice *dev)
+static void qxl_realize_primary(PCIDevice *dev, Error **errp)
 {
     PCIQXLDevice *qxl = DO_UPCAST(PCIQXLDevice, pci, dev);
     VGACommonState *vga = &qxl->vga;
-    int rc;
+    Error *local_err = NULL;
 
     qxl->id = 0;
     qxl_init_ramsize(qxl);
@@ -2050,18 +2048,18 @@ static int qxl_init_primary(PCIDevice *dev)
     vga->con = graphic_console_init(DEVICE(dev), 0, &qxl_ops, qxl);
     qemu_spice_display_init_common(&qxl->ssd);
 
-    rc = qxl_init_common(qxl);
-    if (rc != 0) {
-        return rc;
+    qxl_realize_common(qxl, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
     }
 
     qxl->ssd.dcl.ops = &display_listener_ops;
     qxl->ssd.dcl.con = vga->con;
     register_displaychangelistener(&qxl->ssd.dcl);
-    return rc;
 }
 
-static int qxl_init_secondary(PCIDevice *dev)
+static void qxl_realize_secondary(PCIDevice *dev, Error **errp)
 {
     static int device_id = 1;
     PCIQXLDevice *qxl = DO_UPCAST(PCIQXLDevice, pci, dev);
@@ -2074,7 +2072,7 @@ static int qxl_init_secondary(PCIDevice *dev)
     qxl->vga.vram_ptr = memory_region_get_ram_ptr(&qxl->vga.vram);
     qxl->vga.con = graphic_console_init(DEVICE(dev), 0, &qxl_ops, qxl);
 
-    return qxl_init_common(qxl);
+    qxl_realize_common(qxl, errp);
 }
 
 static void qxl_pre_save(void *opaque)
@@ -2287,7 +2285,7 @@ static void qxl_primary_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = qxl_init_primary;
+    k->realize = qxl_realize_primary;
     k->romfile = "vgabios-qxl.bin";
     k->vendor_id = REDHAT_PCI_VENDOR_ID;
     k->device_id = QXL_DEVICE_ID_STABLE;
@@ -2312,7 +2310,7 @@ static void qxl_secondary_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = qxl_init_secondary;
+    k->realize = qxl_realize_secondary;
     k->vendor_id = REDHAT_PCI_VENDOR_ID;
     k->device_id = QXL_DEVICE_ID_STABLE;
     k->class_id = PCI_CLASS_DISPLAY_OTHER;
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 15/96] pci-assign: Convert to realize
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (13 preceding siblings ...)
  2015-02-18 21:45 ` [Qemu-devel] [PULL 14/96] qxl: " Michael S. Tsirkin
@ 2015-02-18 21:45 ` Michael S. Tsirkin
  2015-02-18 21:45 ` [Qemu-devel] [PULL 16/96] qdev: Don't exit when running into bad -global Michael S. Tsirkin
                   ` (83 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:45 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Markus Armbruster,
	Gonglei, Anthony Liguori, Paolo Bonzini, Richard Henderson

From: Markus Armbruster <armbru@redhat.com>

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/i386/kvm/pci-assign.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index bb206da..5a92800 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -1742,7 +1742,7 @@ static void reset_assigned_device(DeviceState *dev)
     assigned_dev_pci_write_config(pci_dev, PCI_COMMAND, 0, 1);
 }
 
-static int assigned_initfn(struct PCIDevice *pci_dev)
+static void assigned_realize(struct PCIDevice *pci_dev, Error **errp)
 {
     AssignedDevice *dev = DO_UPCAST(AssignedDevice, dev, pci_dev);
     uint8_t e_intx;
@@ -1825,7 +1825,7 @@ static int assigned_initfn(struct PCIDevice *pci_dev)
 
     assigned_dev_load_option_rom(dev);
 
-    return 0;
+    return;
 
 assigned_out:
     deassign_device(dev);
@@ -1835,9 +1835,7 @@ out:
 
 exit_with_error:
     assert(local_err);
-    qerror_report_err(local_err);
-    error_free(local_err);
-    return -1;
+    error_propagate(errp, local_err);
 }
 
 static void assigned_exitfn(struct PCIDevice *pci_dev)
@@ -1873,7 +1871,7 @@ static void assign_class_init(ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    k->init         = assigned_initfn;
+    k->realize      = assigned_realize;
     k->exit         = assigned_exitfn;
     k->config_read  = assigned_dev_pci_read_config;
     k->config_write = assigned_dev_pci_write_config;
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 16/96] qdev: Don't exit when running into bad -global
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (14 preceding siblings ...)
  2015-02-18 21:45 ` [Qemu-devel] [PULL 15/96] pci-assign: " Michael S. Tsirkin
@ 2015-02-18 21:45 ` Michael S. Tsirkin
  2015-02-18 21:45 ` [Qemu-devel] [PULL 17/96] acpi, pc: Add hotunplug request cb for pc machine Michael S. Tsirkin
                   ` (82 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:45 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Peter Crosthwaite, Eduardo Habkost, Juan Quintela,
	dgilbert, Markus Armbruster, Stefan Hajnoczi, Igor Mammedov,
	Paolo Bonzini, =?UTF-8?q?Andreas=20F=C3=A4rber?=

From: Markus Armbruster <armbru@redhat.com>

-global lets you set a nice booby-trap for yourself:

    $ qemu-system-x86_64 -nodefaults -S -display none -usb -monitor stdio -global usb-mouse.usb_version=l
    QEMU 2.1.94 monitor - type 'help' for more information
    (qemu) device_add usb-mouse
    Parameter 'usb_version' expects an int64 value or range
    $ echo $?
    1

Not nice.  Until commit 3196270 we even abort()ed.

The same error triggers if you manage to screw up a machine type's
compat_props.  To demonstrate, change HW_COMPAT_2_1's entry to

            .driver   = "usb-mouse",\
            .property = "usb_version",\
            .value    = "1", \

Then run

    $ qemu-system-x86_64 -usb -M pc-i440fx-2.1 -device usb-mouse
    upstream-qemu: -device usb-mouse: Parameter 'usb_version' expects an int64 value or range
    $ echo $?
    1

One of our creatively cruel error messages.

Since this is actually a coding error, we *should* abort() here.
Replace the error by an assertion failure in this case.

But turn the fatal error into a mere warning when the faulty
GlobalProperty comes from the user.  Looks like this:

    $ qemu-system-x86_64 -nodefaults -S -display none -usb -monitor stdio -global usb-mouse.usb_version=l
    QEMU 2.1.94 monitor - type 'help' for more information
    (qemu) device_add usb-mouse
    Warning: global usb-mouse.usb_version=l ignored (Parameter 'usb_version' expects an int64 value or range)
    (qemu)

This is consistent with how we handle similarly unusable -global in
qdev_prop_check_globals().

You could argue that the error should make device_add fail.  Would be
harder, because we're running within TypeInfo's instance_post_init()
method device_post_init(), which can't fail.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
---
 include/hw/qdev-properties.h |  4 +---
 hw/core/qdev-properties.c    | 21 +++++++++------------
 hw/core/qdev.c               |  8 +-------
 3 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index 070006c..57ee363 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -180,9 +180,7 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
 void qdev_prop_register_global(GlobalProperty *prop);
 void qdev_prop_register_global_list(GlobalProperty *props);
 int qdev_prop_check_globals(void);
-void qdev_prop_set_globals(DeviceState *dev, Error **errp);
-void qdev_prop_set_globals_for_type(DeviceState *dev, const char *typename,
-                                    Error **errp);
+void qdev_prop_set_globals(DeviceState *dev);
 void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
                                     Property *prop, const char *value);
 
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 2e47f70..5a4e4d5 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -990,8 +990,8 @@ int qdev_prop_check_globals(void)
     return ret;
 }
 
-void qdev_prop_set_globals_for_type(DeviceState *dev, const char *typename,
-                                    Error **errp)
+static void qdev_prop_set_globals_for_type(DeviceState *dev,
+                                const char *typename)
 {
     GlobalProperty *prop;
 
@@ -1004,25 +1004,22 @@ void qdev_prop_set_globals_for_type(DeviceState *dev, const char *typename,
         prop->used = true;
         object_property_parse(OBJECT(dev), prop->value, prop->property, &err);
         if (err != NULL) {
-            error_propagate(errp, err);
+            assert(prop->user_provided);
+            error_report("Warning: global %s.%s=%s ignored (%s)",
+                         prop->driver, prop->property, prop->value,
+                         error_get_pretty(err));
+            error_free(err);
             return;
         }
     }
 }
 
-void qdev_prop_set_globals(DeviceState *dev, Error **errp)
+void qdev_prop_set_globals(DeviceState *dev)
 {
     ObjectClass *class = object_get_class(OBJECT(dev));
 
     do {
-        Error *err = NULL;
-
-        qdev_prop_set_globals_for_type(dev, object_class_get_name(class),
-                                       &err);
-        if (err != NULL) {
-            error_propagate(errp, err);
-            return;
-        }
+        qdev_prop_set_globals_for_type(dev, object_class_get_name(class));
         class = object_class_get_parent(class);
     } while (class);
 }
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 2eacac0..8419a32 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -1179,13 +1179,7 @@ static void device_initfn(Object *obj)
 
 static void device_post_init(Object *obj)
 {
-    Error *err = NULL;
-    qdev_prop_set_globals(DEVICE(obj), &err);
-    if (err) {
-        qerror_report_err(err);
-        error_free(err);
-        exit(EXIT_FAILURE);
-    }
+    qdev_prop_set_globals(DEVICE(obj));
 }
 
 /* Unlink device from bus and free the structure.  */
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 17/96] acpi, pc: Add hotunplug request cb for pc machine.
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (15 preceding siblings ...)
  2015-02-18 21:45 ` [Qemu-devel] [PULL 16/96] qdev: Don't exit when running into bad -global Michael S. Tsirkin
@ 2015-02-18 21:45 ` Michael S. Tsirkin
  2015-02-18 21:45 ` [Qemu-devel] [PULL 18/96] acpi, ich9: Add hotunplug request cb for ich9 Michael S. Tsirkin
                   ` (81 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:45 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Zhu Guihua, Juan Quintela, dgilbert, Tang Chen,
	Anthony Liguori, Paolo Bonzini, Igor Mammedov, Richard Henderson

From: Tang Chen <tangchen@cn.fujitsu.com>

Memory and CPU hot unplug are both asynchronous procedures.
They both need unplug request callback to initiate unplug operation.

Add unplug handler to pc machine that will be used by following
CPU and memory unplug patches.

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com>
Signed-off-by: Zhu Guihua <zhugh.fnst@cn.fujitsu.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/i386/pc.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index c7af6aa..15ee10a 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1680,6 +1680,13 @@ static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,
     }
 }
 
+static void pc_machine_device_unplug_request_cb(HotplugHandler *hotplug_dev,
+                                                DeviceState *dev, Error **errp)
+{
+    error_setg(errp, "acpi: device unplug request for not supported device"
+               " type: %s", object_get_typename(OBJECT(dev)));
+}
+
 static HotplugHandler *pc_get_hotpug_handler(MachineState *machine,
                                              DeviceState *dev)
 {
@@ -1809,6 +1816,7 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)
     pcmc->get_hotplug_handler = mc->get_hotplug_handler;
     mc->get_hotplug_handler = pc_get_hotpug_handler;
     hc->plug = pc_machine_device_plug_cb;
+    hc->unplug_request = pc_machine_device_unplug_request_cb;
 }
 
 static const TypeInfo pc_machine_info = {
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 18/96] acpi, ich9: Add hotunplug request cb for ich9.
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (16 preceding siblings ...)
  2015-02-18 21:45 ` [Qemu-devel] [PULL 17/96] acpi, pc: Add hotunplug request cb for pc machine Michael S. Tsirkin
@ 2015-02-18 21:45 ` Michael S. Tsirkin
  2015-02-18 21:45 ` [Qemu-devel] [PULL 19/96] acpi, pc: Add unplug cb for pc machine Michael S. Tsirkin
                   ` (80 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:45 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Zhu Guihua, Juan Quintela, dgilbert, Tang Chen,
	Anthony Liguori, Igor Mammedov

From: Tang Chen <tangchen@cn.fujitsu.com>

Memory and CPU hot unplug are both asynchronous procedures.
They both need unplug request cb when the unplug operation happens.

This patch adds hotunplug request cb for ich9, and memory and CPU
hot unplug will share it.

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com>
Signed-off-by: Zhu Guihua <zhugh.fnst@cn.fujitsu.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/ich9.h | 2 ++
 hw/acpi/ich9.c         | 7 +++++++
 hw/isa/lpc_ich9.c      | 5 +++--
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
index 12d7a7a..eaef0c3 100644
--- a/include/hw/acpi/ich9.h
+++ b/include/hw/acpi/ich9.h
@@ -63,6 +63,8 @@ extern const VMStateDescription vmstate_ich9_pm;
 void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp);
 
 void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp);
+void ich9_pm_device_unplug_request_cb(ICH9LPCPMRegs *pm, DeviceState *dev,
+                                      Error **errp);
 
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list);
 #endif /* HW_ACPI_ICH9_H */
diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 884dab3..5fe1eb8 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -397,6 +397,13 @@ void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp)
     }
 }
 
+void ich9_pm_device_unplug_request_cb(ICH9LPCPMRegs *pm, DeviceState *dev,
+                                      Error **errp)
+{
+    error_setg(errp, "acpi: device unplug request for not supported device"
+               " type: %s", object_get_typename(OBJECT(dev)));
+}
+
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
 {
     ICH9LPCState *s = ICH9_LPC_DEVICE(adev);
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index 530b074..d00b223 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -610,8 +610,9 @@ static void ich9_device_plug_cb(HotplugHandler *hotplug_dev,
 static void ich9_device_unplug_request_cb(HotplugHandler *hotplug_dev,
                                           DeviceState *dev, Error **errp)
 {
-    error_setg(errp, "acpi: device unplug request for not supported device"
-               " type: %s", object_get_typename(OBJECT(dev)));
+    ICH9LPCState *lpc = ICH9_LPC_DEVICE(hotplug_dev);
+
+    ich9_pm_device_unplug_request_cb(&lpc->pm, dev, errp);
 }
 
 static bool ich9_rst_cnt_needed(void *opaque)
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 19/96] acpi, pc: Add unplug cb for pc machine.
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (17 preceding siblings ...)
  2015-02-18 21:45 ` [Qemu-devel] [PULL 18/96] acpi, ich9: Add hotunplug request cb for ich9 Michael S. Tsirkin
@ 2015-02-18 21:45 ` Michael S. Tsirkin
  2015-02-18 21:46 ` [Qemu-devel] [PULL 20/96] acpi, ich9: Add unplug cb for ich9 Michael S. Tsirkin
                   ` (79 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:45 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Zhu Guihua, Juan Quintela, dgilbert, Tang Chen,
	Anthony Liguori, Paolo Bonzini, Igor Mammedov, Richard Henderson

From: Tang Chen <tangchen@cn.fujitsu.com>

Memory and CPU hot unplug are both asynchronous procedures.
When the unplug operation happens, unplug request cb is called first.
And when guest OS finished handling unplug, unplug cb will be called
to do the real removal of device.

This patch adds hotunplug cb to pc machine, which memory and CPU
hot unplug will use it.

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com>
Signed-off-by: Zhu Guihua <zhugh.fnst@cn.fujitsu.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/i386/pc.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 15ee10a..850b6b5 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1687,6 +1687,13 @@ static void pc_machine_device_unplug_request_cb(HotplugHandler *hotplug_dev,
                " type: %s", object_get_typename(OBJECT(dev)));
 }
 
+static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev,
+                                        DeviceState *dev, Error **errp)
+{
+    error_setg(errp, "acpi: device unplug for not supported device"
+               " type: %s", object_get_typename(OBJECT(dev)));
+}
+
 static HotplugHandler *pc_get_hotpug_handler(MachineState *machine,
                                              DeviceState *dev)
 {
@@ -1817,6 +1824,7 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)
     mc->get_hotplug_handler = pc_get_hotpug_handler;
     hc->plug = pc_machine_device_plug_cb;
     hc->unplug_request = pc_machine_device_unplug_request_cb;
+    hc->unplug = pc_machine_device_unplug_cb;
 }
 
 static const TypeInfo pc_machine_info = {
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 20/96] acpi, ich9: Add unplug cb for ich9.
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (18 preceding siblings ...)
  2015-02-18 21:45 ` [Qemu-devel] [PULL 19/96] acpi, pc: Add unplug cb for pc machine Michael S. Tsirkin
@ 2015-02-18 21:46 ` Michael S. Tsirkin
  2015-02-18 21:46 ` [Qemu-devel] [PULL 21/96] acpi, piix4: Add unplug cb for piix4 Michael S. Tsirkin
                   ` (78 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:46 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Zhu Guihua, Juan Quintela, dgilbert, Tang Chen,
	Anthony Liguori, Igor Mammedov

From: Tang Chen <tangchen@cn.fujitsu.com>

Memory and CPU hot unplug are both asynchronous procedures.
When the unplug operation happens, unplug request cb is called first.
And when guest OS finished handling unplug, unplug cb will be called
to do the real removal of device.

This patch adds hotunplug cb to ich9, which memory and CPU
hot unplug will use it.

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com>
Signed-off-by: Zhu Guihua <zhugh.fnst@cn.fujitsu.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/ich9.h | 2 ++
 hw/acpi/ich9.c         | 7 +++++++
 hw/isa/lpc_ich9.c      | 9 +++++++++
 3 files changed, 18 insertions(+)

diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
index eaef0c3..c2d3dba 100644
--- a/include/hw/acpi/ich9.h
+++ b/include/hw/acpi/ich9.h
@@ -65,6 +65,8 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp);
 void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp);
 void ich9_pm_device_unplug_request_cb(ICH9LPCPMRegs *pm, DeviceState *dev,
                                       Error **errp);
+void ich9_pm_device_unplug_cb(ICH9LPCPMRegs *pm, DeviceState *dev,
+                              Error **errp);
 
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list);
 #endif /* HW_ACPI_ICH9_H */
diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 5fe1eb8..5352e19 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -404,6 +404,13 @@ void ich9_pm_device_unplug_request_cb(ICH9LPCPMRegs *pm, DeviceState *dev,
                " type: %s", object_get_typename(OBJECT(dev)));
 }
 
+void ich9_pm_device_unplug_cb(ICH9LPCPMRegs *pm, DeviceState *dev,
+                              Error **errp)
+{
+    error_setg(errp, "acpi: device unplug for not supported device"
+               " type: %s", object_get_typename(OBJECT(dev)));
+}
+
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
 {
     ICH9LPCState *s = ICH9_LPC_DEVICE(adev);
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index d00b223..16f5a0d 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -615,6 +615,14 @@ static void ich9_device_unplug_request_cb(HotplugHandler *hotplug_dev,
     ich9_pm_device_unplug_request_cb(&lpc->pm, dev, errp);
 }
 
+static void ich9_device_unplug_cb(HotplugHandler *hotplug_dev,
+                                  DeviceState *dev, Error **errp)
+{
+    ICH9LPCState *lpc = ICH9_LPC_DEVICE(hotplug_dev);
+
+    ich9_pm_device_unplug_cb(&lpc->pm, dev, errp);
+}
+
 static bool ich9_rst_cnt_needed(void *opaque)
 {
     ICH9LPCState *lpc = opaque;
@@ -678,6 +686,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data)
     dc->cannot_instantiate_with_device_add_yet = true;
     hc->plug = ich9_device_plug_cb;
     hc->unplug_request = ich9_device_unplug_request_cb;
+    hc->unplug = ich9_device_unplug_cb;
     adevc->ospm_status = ich9_pm_ospm_status;
 }
 
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 21/96] acpi, piix4: Add unplug cb for piix4.
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (19 preceding siblings ...)
  2015-02-18 21:46 ` [Qemu-devel] [PULL 20/96] acpi, ich9: Add unplug cb for ich9 Michael S. Tsirkin
@ 2015-02-18 21:46 ` Michael S. Tsirkin
  2015-02-18 21:46 ` [Qemu-devel] [PULL 22/96] vl.c: Fix error messages when parsing maxmem parameters Michael S. Tsirkin
                   ` (77 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:46 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Zhu Guihua, Juan Quintela, dgilbert, Tang Chen,
	Anthony Liguori, Igor Mammedov

From: Tang Chen <tangchen@cn.fujitsu.com>

Memory and CPU hot unplug are both asynchronous procedures.
When the unplug operation happens, unplug request cb is called first.
And when guest OS finished handling unplug, unplug cb will be called
to do the real removal of device.

This patch adds hotunplug cb to piix4, which memory and CPU
hot unplug will use it.

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com>
Signed-off-by: Zhu Guihua <zhugh.fnst@cn.fujitsu.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/acpi/piix4.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 017510b..766f1b8 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -370,6 +370,13 @@ static void piix4_device_unplug_request_cb(HotplugHandler *hotplug_dev,
     }
 }
 
+static void piix4_device_unplug_cb(HotplugHandler *hotplug_dev,
+                                   DeviceState *dev, Error **errp)
+{
+    error_setg(errp, "acpi: device unplug for not supported device"
+               " type: %s", object_get_typename(OBJECT(dev)));
+}
+
 static void piix4_update_bus_hotplug(PCIBus *pci_bus, void *opaque)
 {
     PIIX4PMState *s = opaque;
@@ -609,6 +616,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data)
     dc->hotpluggable = false;
     hc->plug = piix4_device_plug_cb;
     hc->unplug_request = piix4_device_unplug_request_cb;
+    hc->unplug = piix4_device_unplug_cb;
     adevc->ospm_status = piix4_ospm_status;
 }
 
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 22/96] vl.c: Fix error messages when parsing maxmem parameters
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (20 preceding siblings ...)
  2015-02-18 21:46 ` [Qemu-devel] [PULL 21/96] acpi, piix4: Add unplug cb for piix4 Michael S. Tsirkin
@ 2015-02-18 21:46 ` Michael S. Tsirkin
  2015-02-18 21:46 ` [Qemu-devel] [PULL 23/96] pc: memory: Validate alignment of maxram_size to page size Michael S. Tsirkin
                   ` (76 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:46 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Peter Krempa, Juan Quintela, dgilbert,
	Anthony Liguori, Paolo Bonzini

From: Peter Krempa <pkrempa@redhat.com>

Produce more human readable error messages and fix few spelling
mistakes.

Also remove a redundant check for the max memory size.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 vl.c | 34 ++++++++++++++++------------------
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/vl.c b/vl.c
index 8c8f142..8270549 100644
--- a/vl.c
+++ b/vl.c
@@ -2697,29 +2697,27 @@ static void set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size)
         uint64_t slots;
 
         sz = qemu_opt_get_size(opts, "maxmem", 0);
+        slots = qemu_opt_get_number(opts, "slots", 0);
         if (sz < ram_size) {
-            error_report("invalid -m option value: maxmem "
-                    "(0x%" PRIx64 ") <= initial memory (0x"
-                    RAM_ADDR_FMT ")", sz, ram_size);
+            error_report("invalid value of -m option maxmem: "
+                         "maximum memory size (0x%" PRIx64 ") must be at least "
+                         "the initial memory size (0x" RAM_ADDR_FMT ")",
+                         sz, ram_size);
             exit(EXIT_FAILURE);
-        }
-
-        slots = qemu_opt_get_number(opts, "slots", 0);
-        if ((sz > ram_size) && !slots) {
-            error_report("invalid -m option value: maxmem "
-                    "(0x%" PRIx64 ") more than initial memory (0x"
-                    RAM_ADDR_FMT ") but no hotplug slots where "
-                    "specified", sz, ram_size);
+        } else if (sz > ram_size) {
+            if (!slots) {
+                error_report("invalid value of -m option: maxmem was "
+                             "specified, but no hotplug slots were specified");
+                exit(EXIT_FAILURE);
+            }
+        } else if (slots) {
+            error_report("invalid value of -m option maxmem: "
+                         "memory slots were specified but maximum memory size "
+                         "(0x%" PRIx64 ") is equal to the initial memory size "
+                         "(0x" RAM_ADDR_FMT ")", sz, ram_size);
             exit(EXIT_FAILURE);
         }
 
-        if ((sz <= ram_size) && slots) {
-            error_report("invalid -m option value:  %"
-                    PRIu64 " hotplug slots where specified but "
-                    "maxmem (0x%" PRIx64 ") <= initial memory (0x"
-                    RAM_ADDR_FMT ")", slots, sz, ram_size);
-            exit(EXIT_FAILURE);
-        }
         *maxram_size = sz;
         *ram_slots = slots;
     } else if ((!maxmem_str && slots_str) ||
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 23/96] pc: memory: Validate alignment of maxram_size to page size
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (21 preceding siblings ...)
  2015-02-18 21:46 ` [Qemu-devel] [PULL 22/96] vl.c: Fix error messages when parsing maxmem parameters Michael S. Tsirkin
@ 2015-02-18 21:46 ` Michael S. Tsirkin
  2015-02-18 21:46 ` [Qemu-devel] [PULL 24/96] acpi: update RSDP on guest access Michael S. Tsirkin
                   ` (75 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:46 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Peter Krempa, Juan Quintela, dgilbert,
	Anthony Liguori, Paolo Bonzini, Richard Henderson

From: Peter Krempa <pkrempa@redhat.com>

If the maxram_size is not aligned and dimm devices were added on the
command line qemu would terminate with a rather unhelpful message:

ERROR:hw/mem/pc-dimm.c:150:pc_dimm_get_free_addr: assertion failed:
(QEMU_ALIGN_UP(address_space_size, align) == address_space_size)

In case no dimm device was originally added on the commandline qemu
exits on the assertion failure.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 hw/i386/pc.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 850b6b5..df6fd00 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1246,6 +1246,13 @@ FWCfgState *pc_memory_init(MachineState *machine,
             exit(EXIT_FAILURE);
         }
 
+        if (QEMU_ALIGN_UP(machine->maxram_size,
+                          TARGET_PAGE_SIZE) != machine->maxram_size) {
+            error_report("maximum memory size must by aligned to multiple of "
+                         "%d bytes", TARGET_PAGE_SIZE);
+            exit(EXIT_FAILURE);
+        }
+
         pcms->hotplug_memory_base =
             ROUND_UP(0x100000000ULL + above_4g_mem_size, 1ULL << 30);
 
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 24/96] acpi: update RSDP on guest access
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (22 preceding siblings ...)
  2015-02-18 21:46 ` [Qemu-devel] [PULL 23/96] pc: memory: Validate alignment of maxram_size to page size Michael S. Tsirkin
@ 2015-02-18 21:46 ` Michael S. Tsirkin
  2015-02-18 21:46 ` [Qemu-devel] [PULL 25/96] pc: acpi-build: update linker " Michael S. Tsirkin
                   ` (74 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:46 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Anthony Liguori,
	Paolo Bonzini, Marcel Apfelbaum, Igor Mammedov,
	Richard Henderson

RSDT offset can change across reboots and that makes
immutable RSDP, which is build at startup, point to
incorrect place in ACPI table blob. That results in
BIOS corrupting tables and guest OS failing to find
ACPI tables.
We really should have put it in a ROM region, but
we can't change that for old machine types,
let's just set the callback and update it explicitly.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>
---
 hw/i386/acpi-build.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 5737ed0..d9b99bc 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1367,6 +1367,7 @@ struct AcpiBuildState {
     /* Is table patched? */
     uint8_t patched;
     PcGuestInfo *guest_info;
+    void *rsdp;
 } AcpiBuildState;
 
 static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)
@@ -1501,8 +1502,6 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
 
     /* We'll expose it all to Guest so we want to reduce
      * chance of size changes.
-     * RSDP is small so it's easy to keep it immutable, no need to
-     * bother with alignment.
      *
      * We used to align the tables to 4k, but of course this would
      * too simple to be enough.  4k turned out to be too small an
@@ -1574,6 +1573,7 @@ static void acpi_build_update(void *build_opaque, uint32_t offset)
 
     memcpy(qemu_get_ram_ptr(build_state->table_ram), tables.table_data->data,
            build_state->table_size);
+    memcpy(build_state->rsdp, tables.rsdp->data, acpi_data_len(tables.rsdp));
 
     cpu_physical_memory_set_dirty_range_nocode(build_state->table_ram,
                                                build_state->table_size);
@@ -1646,11 +1646,14 @@ void acpi_setup(PcGuestInfo *guest_info)
                     tables.tcpalog->data, acpi_data_len(tables.tcpalog));
 
     /*
-     * RSDP is small so it's easy to keep it immutable, no need to
-     * bother with ROM blobs.
+     * Though RSDP is small, its contents isn't immutable, so
+     * update it along with the rest of tables on guest access.
      */
-    fw_cfg_add_file(guest_info->fw_cfg, ACPI_BUILD_RSDP_FILE,
-                    tables.rsdp->data, acpi_data_len(tables.rsdp));
+    fw_cfg_add_file_callback(guest_info->fw_cfg, ACPI_BUILD_RSDP_FILE,
+                             acpi_build_update, build_state,
+                             tables.rsdp->data, acpi_data_len(tables.rsdp));
+
+    build_state->rsdp = tables.rsdp->data;
 
     qemu_register_reset(acpi_build_reset, build_state);
     acpi_build_reset(build_state);
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 25/96] pc: acpi-build: update linker on guest access
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (23 preceding siblings ...)
  2015-02-18 21:46 ` [Qemu-devel] [PULL 24/96] acpi: update RSDP on guest access Michael S. Tsirkin
@ 2015-02-18 21:46 ` Michael S. Tsirkin
  2015-02-18 21:46 ` [Qemu-devel] [PULL 26/96] pc: acpi-build: migrate RSDP table Michael S. Tsirkin
                   ` (73 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:46 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Anthony Liguori,
	Paolo Bonzini, Marcel Apfelbaum, Igor Mammedov,
	Richard Henderson

From: Igor Mammedov <imammedo@redhat.com>

Linker table is build only once, so if later during
tables rebuild sizes of other ACPI tables change
pointers will be patched incorrectly due to wrong
offsets in linker. Resulting in guest not being able
to find ACPI tables.
Fix it by updating 'linker' table with the rest of
tables when firmware reads it.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>
---
 hw/i386/acpi-build.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index d9b99bc..47368c9 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1368,6 +1368,8 @@ struct AcpiBuildState {
     uint8_t patched;
     PcGuestInfo *guest_info;
     void *rsdp;
+    ram_addr_t linker_ram;
+    uint32_t linker_size;
 } AcpiBuildState;
 
 static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)
@@ -1574,6 +1576,8 @@ static void acpi_build_update(void *build_opaque, uint32_t offset)
     memcpy(qemu_get_ram_ptr(build_state->table_ram), tables.table_data->data,
            build_state->table_size);
     memcpy(build_state->rsdp, tables.rsdp->data, acpi_data_len(tables.rsdp));
+    memcpy(qemu_get_ram_ptr(build_state->linker_ram), tables.linker->data,
+           build_state->linker_size);
 
     cpu_physical_memory_set_dirty_range_nocode(build_state->table_ram,
                                                build_state->table_size);
@@ -1640,7 +1644,9 @@ void acpi_setup(PcGuestInfo *guest_info)
     assert(build_state->table_ram != RAM_ADDR_MAX);
     build_state->table_size = acpi_data_len(tables.table_data);
 
-    acpi_add_rom_blob(NULL, tables.linker, "etc/table-loader", 0);
+    build_state->linker_ram =
+        acpi_add_rom_blob(build_state, tables.linker, "etc/table-loader", 0);
+    build_state->linker_size = acpi_data_len(tables.linker);
 
     fw_cfg_add_file(guest_info->fw_cfg, ACPI_BUILD_TPMLOG_FILE,
                     tables.tcpalog->data, acpi_data_len(tables.tcpalog));
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 26/96] pc: acpi-build: migrate RSDP table
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (24 preceding siblings ...)
  2015-02-18 21:46 ` [Qemu-devel] [PULL 25/96] pc: acpi-build: update linker " Michael S. Tsirkin
@ 2015-02-18 21:46 ` Michael S. Tsirkin
  2015-02-18 21:46 ` [Qemu-devel] [PULL 27/96] exec: round up size on MR resize Michael S. Tsirkin
                   ` (72 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:46 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Anthony Liguori,
	Paolo Bonzini, Marcel Apfelbaum, Igor Mammedov,
	Richard Henderson

From: Igor Mammedov <imammedo@redhat.com>

Makes sure that RSDP stays the same
/i.e. matches ACPI tables blob in source/
if guest is migrated during RSDP reading or
has been already shadowed by firmware.

Fix applies only to new machine types starting
from 2.3, so it won't break migration for old
machine types.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>
---
 include/hw/i386/pc.h |  1 +
 hw/i386/acpi-build.c | 24 +++++++++++++++---------
 hw/i386/pc_piix.c    |  3 +++
 hw/i386/pc_q35.c     |  3 +++
 4 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 69d9cf8..b0a80cf 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -104,6 +104,7 @@ struct PcGuestInfo {
     int legacy_acpi_table_size;
     bool has_acpi_build;
     bool has_reserved_memory;
+    bool has_immutable_rsdp;
 };
 
 /* parallel.c */
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 47368c9..693f447 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1651,15 +1651,21 @@ void acpi_setup(PcGuestInfo *guest_info)
     fw_cfg_add_file(guest_info->fw_cfg, ACPI_BUILD_TPMLOG_FILE,
                     tables.tcpalog->data, acpi_data_len(tables.tcpalog));
 
-    /*
-     * Though RSDP is small, its contents isn't immutable, so
-     * update it along with the rest of tables on guest access.
-     */
-    fw_cfg_add_file_callback(guest_info->fw_cfg, ACPI_BUILD_RSDP_FILE,
-                             acpi_build_update, build_state,
-                             tables.rsdp->data, acpi_data_len(tables.rsdp));
-
-    build_state->rsdp = tables.rsdp->data;
+    if (guest_info->has_immutable_rsdp) {
+        /*
+         * Keep for compatibility with old machine types.
+         * Though RSDP is small, its contents isn't immutable, so
+         * update it along with the rest of tables on guest access.
+         */
+        fw_cfg_add_file_callback(guest_info->fw_cfg, ACPI_BUILD_RSDP_FILE,
+                                 acpi_build_update, build_state,
+                                 tables.rsdp->data, acpi_data_len(tables.rsdp));
+        build_state->rsdp = tables.rsdp->data;
+    } else {
+        build_state->rsdp = qemu_get_ram_ptr(
+            acpi_add_rom_blob(build_state, tables.rsdp, ACPI_BUILD_RSDP_FILE, 0)
+        );
+    }
 
     qemu_register_reset(acpi_build_reset, build_state);
     acpi_build_reset(build_state);
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 38b42b0..e586c7b 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -60,6 +60,7 @@ static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
 static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
 
 static bool has_acpi_build = true;
+static bool has_immutable_rsdp;
 static int legacy_acpi_table_size;
 static bool smbios_defaults = true;
 static bool smbios_legacy_mode;
@@ -168,6 +169,7 @@ static void pc_init1(MachineState *machine,
 
     guest_info->isapc_ram_fw = !pci_enabled;
     guest_info->has_reserved_memory = has_reserved_memory;
+    guest_info->has_immutable_rsdp = has_immutable_rsdp;
 
     if (smbios_defaults) {
         MachineClass *mc = MACHINE_GET_CLASS(machine);
@@ -310,6 +312,7 @@ static void pc_init_pci(MachineState *machine)
 
 static void pc_compat_2_2(MachineState *machine)
 {
+    has_immutable_rsdp = true;
     x86_cpu_compat_set_features("kvm64", FEAT_1_EDX, 0, CPUID_VME);
     x86_cpu_compat_set_features("kvm32", FEAT_1_EDX, 0, CPUID_VME);
     x86_cpu_compat_set_features("Conroe", FEAT_1_EDX, 0, CPUID_VME);
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 63027ee..6151f2f 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -50,6 +50,7 @@
 #define MAX_SATA_PORTS     6
 
 static bool has_acpi_build = true;
+static bool has_immutable_rsdp;
 static bool smbios_defaults = true;
 static bool smbios_legacy_mode;
 static bool smbios_uuid_encoded = true;
@@ -154,6 +155,7 @@ static void pc_q35_init(MachineState *machine)
     guest_info->isapc_ram_fw = false;
     guest_info->has_acpi_build = has_acpi_build;
     guest_info->has_reserved_memory = has_reserved_memory;
+    guest_info->has_immutable_rsdp = has_immutable_rsdp;
 
     /* Migration was not supported in 2.0 for Q35, so do not bother
      * with this hack (see hw/i386/acpi-build.c).
@@ -289,6 +291,7 @@ static void pc_q35_init(MachineState *machine)
 
 static void pc_compat_2_2(MachineState *machine)
 {
+    has_immutable_rsdp = true;
     x86_cpu_compat_set_features("kvm64", FEAT_1_EDX, 0, CPUID_VME);
     x86_cpu_compat_set_features("kvm32", FEAT_1_EDX, 0, CPUID_VME);
     x86_cpu_compat_set_features("Conroe", FEAT_1_EDX, 0, CPUID_VME);
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 27/96] exec: round up size on MR resize
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (25 preceding siblings ...)
  2015-02-18 21:46 ` [Qemu-devel] [PULL 26/96] pc: acpi-build: migrate RSDP table Michael S. Tsirkin
@ 2015-02-18 21:46 ` Michael S. Tsirkin
  2015-02-18 21:46 ` [Qemu-devel] [PULL 28/96] acpi-build: fix ACPI RAM management Michael S. Tsirkin
                   ` (71 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:46 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Paolo Bonzini, dgilbert, Paolo Bonzini, Juan Quintela

Block size must fundamentally be a multiple of target page size.
Aligning automatically removes need to worry about the alignment
from callers.

Note: the only caller of qemu_ram_resize (acpi) already happens to have
size padded to a power of 2, but we would like to drop the padding in
ACPI core, and don't want to expose target page size knowledge to ACPI.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Paolo Bonzini <ponzini@redhat.com>
---
 exec.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/exec.c b/exec.c
index 6dff7bc..878dc54 100644
--- a/exec.c
+++ b/exec.c
@@ -1298,6 +1298,8 @@ int qemu_ram_resize(ram_addr_t base, ram_addr_t newsize, Error **errp)
 
     assert(block);
 
+    newsize = TARGET_PAGE_ALIGN(newsize);
+
     if (block->used_length == newsize) {
         return 0;
     }
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 28/96] acpi-build: fix ACPI RAM management
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (26 preceding siblings ...)
  2015-02-18 21:46 ` [Qemu-devel] [PULL 27/96] exec: round up size on MR resize Michael S. Tsirkin
@ 2015-02-18 21:46 ` Michael S. Tsirkin
  2015-02-18 21:46 ` [Qemu-devel] [PULL 29/96] acpi: has_immutable_rsdp->!rsdp_in_ram Michael S. Tsirkin
                   ` (70 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:46 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Anthony Liguori,
	Paolo Bonzini, Richard Henderson

This fixes multiple issues around ACPI RAM management:

RSDP and linker RAM aren't currently marked dirty
on update, so they won't be migrated correctly.

Let's handle all tables in the same way: set correct size (assert if
too big), update, mark RAM dirty.

This also drops assert checking that table size didn't change: table
size is fundamentally dynamic and depends on hw configuration,
just set the correct size and use that (memory core asserts if size is
too large).

This also means we can drop tracking table size, memory core does this
for us now.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/i386/acpi-build.c | 43 +++++++++++++++++++++++--------------------
 1 file changed, 23 insertions(+), 20 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 693f447..031f88d 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1363,13 +1363,12 @@ typedef
 struct AcpiBuildState {
     /* Copy of table in RAM (for patching). */
     ram_addr_t table_ram;
-    uint32_t table_size;
     /* Is table patched? */
     uint8_t patched;
     PcGuestInfo *guest_info;
     void *rsdp;
+    ram_addr_t rsdp_ram;
     ram_addr_t linker_ram;
-    uint32_t linker_size;
 } AcpiBuildState;
 
 static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)
@@ -1552,6 +1551,17 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
     g_array_free(table_offsets, true);
 }
 
+static void acpi_ram_update(ram_addr_t ram, GArray *data)
+{
+    uint32_t size = acpi_data_len(data);
+
+    /* Make sure RAM size is correct - in case it got changed e.g. by migration */
+    qemu_ram_resize(ram, size, &error_abort);
+
+    memcpy(qemu_get_ram_ptr(ram), data->data, size);
+    cpu_physical_memory_set_dirty_range_nocode(ram, size);
+}
+
 static void acpi_build_update(void *build_opaque, uint32_t offset)
 {
     AcpiBuildState *build_state = build_opaque;
@@ -1567,21 +1577,15 @@ 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);
+    acpi_ram_update(build_state->table_ram, tables.table_data);
 
-    /* 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(build_state->rsdp, tables.rsdp->data, acpi_data_len(tables.rsdp));
-    memcpy(qemu_get_ram_ptr(build_state->linker_ram), tables.linker->data,
-           build_state->linker_size);
-
-    cpu_physical_memory_set_dirty_range_nocode(build_state->table_ram,
-                                               build_state->table_size);
+    if (build_state->rsdp) {
+        memcpy(build_state->rsdp, tables.rsdp->data, acpi_data_len(tables.rsdp));
+    } else {
+        acpi_ram_update(build_state->rsdp_ram, tables.rsdp);
+    }
 
+    acpi_ram_update(build_state->linker_ram, tables.linker);
     acpi_build_tables_cleanup(&tables, true);
 }
 
@@ -1642,11 +1646,9 @@ void acpi_setup(PcGuestInfo *guest_info)
                                                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->linker_ram =
         acpi_add_rom_blob(build_state, tables.linker, "etc/table-loader", 0);
-    build_state->linker_size = acpi_data_len(tables.linker);
 
     fw_cfg_add_file(guest_info->fw_cfg, ACPI_BUILD_TPMLOG_FILE,
                     tables.tcpalog->data, acpi_data_len(tables.tcpalog));
@@ -1661,10 +1663,11 @@ void acpi_setup(PcGuestInfo *guest_info)
                                  acpi_build_update, build_state,
                                  tables.rsdp->data, acpi_data_len(tables.rsdp));
         build_state->rsdp = tables.rsdp->data;
+        build_state->rsdp_ram = (ram_addr_t)-1;
     } else {
-        build_state->rsdp = qemu_get_ram_ptr(
-            acpi_add_rom_blob(build_state, tables.rsdp, ACPI_BUILD_RSDP_FILE, 0)
-        );
+        build_state->rsdp = NULL;
+        build_state->rsdp_ram = acpi_add_rom_blob(build_state, tables.rsdp,
+                                                  ACPI_BUILD_RSDP_FILE, 0);
     }
 
     qemu_register_reset(acpi_build_reset, build_state);
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 29/96] acpi: has_immutable_rsdp->!rsdp_in_ram
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (27 preceding siblings ...)
  2015-02-18 21:46 ` [Qemu-devel] [PULL 28/96] acpi-build: fix ACPI RAM management Michael S. Tsirkin
@ 2015-02-18 21:46 ` Michael S. Tsirkin
  2015-02-18 21:47 ` [Qemu-devel] [PULL 30/96] acpi-build: simplify rsdp management for legacy Michael S. Tsirkin
                   ` (69 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:46 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Anthony Liguori,
	Paolo Bonzini, Igor Mammedov, Richard Henderson

As comment in acpi-build.c notes, RSDP is not really immutable.  So it's
really a question of whether it's in RAM, name the variable accordingly.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
---
 include/hw/i386/pc.h | 2 +-
 hw/i386/acpi-build.c | 2 +-
 hw/i386/pc_piix.c    | 6 +++---
 hw/i386/pc_q35.c     | 6 +++---
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index b0a80cf..0c595c5 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -104,7 +104,7 @@ struct PcGuestInfo {
     int legacy_acpi_table_size;
     bool has_acpi_build;
     bool has_reserved_memory;
-    bool has_immutable_rsdp;
+    bool rsdp_in_ram;
 };
 
 /* parallel.c */
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 031f88d..409229f 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1653,7 +1653,7 @@ void acpi_setup(PcGuestInfo *guest_info)
     fw_cfg_add_file(guest_info->fw_cfg, ACPI_BUILD_TPMLOG_FILE,
                     tables.tcpalog->data, acpi_data_len(tables.tcpalog));
 
-    if (guest_info->has_immutable_rsdp) {
+    if (!guest_info->rsdp_in_ram) {
         /*
          * Keep for compatibility with old machine types.
          * Though RSDP is small, its contents isn't immutable, so
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index e586c7b..13ff561 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -60,7 +60,7 @@ static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
 static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
 
 static bool has_acpi_build = true;
-static bool has_immutable_rsdp;
+static bool rsdp_in_ram = true;
 static int legacy_acpi_table_size;
 static bool smbios_defaults = true;
 static bool smbios_legacy_mode;
@@ -169,7 +169,7 @@ static void pc_init1(MachineState *machine,
 
     guest_info->isapc_ram_fw = !pci_enabled;
     guest_info->has_reserved_memory = has_reserved_memory;
-    guest_info->has_immutable_rsdp = has_immutable_rsdp;
+    guest_info->rsdp_in_ram = rsdp_in_ram;
 
     if (smbios_defaults) {
         MachineClass *mc = MACHINE_GET_CLASS(machine);
@@ -312,7 +312,7 @@ static void pc_init_pci(MachineState *machine)
 
 static void pc_compat_2_2(MachineState *machine)
 {
-    has_immutable_rsdp = true;
+    rsdp_in_ram = false;
     x86_cpu_compat_set_features("kvm64", FEAT_1_EDX, 0, CPUID_VME);
     x86_cpu_compat_set_features("kvm32", FEAT_1_EDX, 0, CPUID_VME);
     x86_cpu_compat_set_features("Conroe", FEAT_1_EDX, 0, CPUID_VME);
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 6151f2f..c0f21fe 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -50,7 +50,7 @@
 #define MAX_SATA_PORTS     6
 
 static bool has_acpi_build = true;
-static bool has_immutable_rsdp;
+static bool rsdp_in_ram = true;
 static bool smbios_defaults = true;
 static bool smbios_legacy_mode;
 static bool smbios_uuid_encoded = true;
@@ -155,7 +155,7 @@ static void pc_q35_init(MachineState *machine)
     guest_info->isapc_ram_fw = false;
     guest_info->has_acpi_build = has_acpi_build;
     guest_info->has_reserved_memory = has_reserved_memory;
-    guest_info->has_immutable_rsdp = has_immutable_rsdp;
+    guest_info->rsdp_in_ram = rsdp_in_ram;
 
     /* Migration was not supported in 2.0 for Q35, so do not bother
      * with this hack (see hw/i386/acpi-build.c).
@@ -291,7 +291,7 @@ static void pc_q35_init(MachineState *machine)
 
 static void pc_compat_2_2(MachineState *machine)
 {
-    has_immutable_rsdp = true;
+    rsdp_in_ram = false;
     x86_cpu_compat_set_features("kvm64", FEAT_1_EDX, 0, CPUID_VME);
     x86_cpu_compat_set_features("kvm32", FEAT_1_EDX, 0, CPUID_VME);
     x86_cpu_compat_set_features("Conroe", FEAT_1_EDX, 0, CPUID_VME);
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 30/96] acpi-build: simplify rsdp management for legacy
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (28 preceding siblings ...)
  2015-02-18 21:46 ` [Qemu-devel] [PULL 29/96] acpi: has_immutable_rsdp->!rsdp_in_ram Michael S. Tsirkin
@ 2015-02-18 21:47 ` Michael S. Tsirkin
  2015-02-18 21:47 ` [Qemu-devel] [PULL 31/96] scripts/update-linux-headers.sh: pull virtio hdrs Michael S. Tsirkin
                   ` (68 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Anthony Liguori,
	Paolo Bonzini, Igor Mammedov, Richard Henderson

For legacy machine types, rsdp is not in RAM, so we need a copy of rsdp
for fw cfg. We previously used g_array_free with false parameter,
but this seems to confuse people.
This also wastes a bit of memory as the buffer is unused for new
machine types.

Let's just use plain g_memdup, and free original memory together with
the array.

TODO: rationalize tcpalog memory management, and get rid of the mfre
parameter.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/acpi-build.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 409229f..9b11c92 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1354,7 +1354,7 @@ static inline void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre)
 {
     void *linker_data = bios_linker_loader_cleanup(tables->linker);
     g_free(linker_data);
-    g_array_free(tables->rsdp, mfre);
+    g_array_free(tables->rsdp, true);
     g_array_free(tables->table_data, true);
     g_array_free(tables->tcpalog, mfre);
 }
@@ -1657,12 +1657,14 @@ void acpi_setup(PcGuestInfo *guest_info)
         /*
          * Keep for compatibility with old machine types.
          * Though RSDP is small, its contents isn't immutable, so
-         * update it along with the rest of tables on guest access.
+         * we'll update it along with the rest of tables on guest access.
          */
+        uint32_t rsdp_size = acpi_data_len(tables.rsdp);
+
+        build_state->rsdp = g_memdup(tables.rsdp->data, rsdp_size);
         fw_cfg_add_file_callback(guest_info->fw_cfg, ACPI_BUILD_RSDP_FILE,
                                  acpi_build_update, build_state,
-                                 tables.rsdp->data, acpi_data_len(tables.rsdp));
-        build_state->rsdp = tables.rsdp->data;
+                                 build_state->rsdp, rsdp_size);
         build_state->rsdp_ram = (ram_addr_t)-1;
     } else {
         build_state->rsdp = NULL;
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 31/96] scripts/update-linux-headers.sh: pull virtio hdrs
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (29 preceding siblings ...)
  2015-02-18 21:47 ` [Qemu-devel] [PULL 30/96] acpi-build: simplify rsdp management for legacy Michael S. Tsirkin
@ 2015-02-18 21:47 ` Michael S. Tsirkin
  2015-02-18 21:47 ` [Qemu-devel] [PULL 32/96] include: import virtio headers from linux 4.0 Michael S. Tsirkin
                   ` (67 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Alexander Graf, Thomas Huth, dgilbert, Juan Quintela

It doesn't make sense to copy values manually:
the only issue with getting headers from linux
seems to be dealing with linux/types, we
can easily fix that automatically while importing.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com>
---
 scripts/update-linux-headers.sh | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers.sh
index c8e026d..8926dec 100755
--- a/scripts/update-linux-headers.sh
+++ b/scripts/update-linux-headers.sh
@@ -28,6 +28,36 @@ if [ -z "$output" ]; then
     output="$PWD"
 fi
 
+cp_virtio() {
+    from=$1
+    to=$2
+    virtio=$(find "$from" -name '*virtio*h')
+    if [ "$virtio" ]; then
+        rm -rf "$to"
+        mkdir -p "$to"
+        for f in $virtio; do
+            if
+                grep '#include' "$f" | grep -v -e 'linux/virtio' \
+                                             -e 'linux/types' \
+                                             -e 'linux/if_ether' \
+                                             > /dev/null
+            then
+                echo "Unexpected #include in input file $f".
+                exit 2
+            fi
+
+            header=$(basename "$f");
+            sed -e 's/__u\([0-9][0-9]*\)/uint\1_t/g' \
+                -e 's/__le\([0-9][0-9]*\)/uint\1_t/g' \
+                -e 's/__be\([0-9][0-9]*\)/uint\1_t/g' \
+                -e 's/<linux\/\([^>]*\)>/"standard-headers\/linux\/\1"/' \
+                -e 's/__bitwise__//' \
+                -e 's/__attribute__((packed))/QEMU_PACKED/' \
+                "$f" > "$to/$header";
+        done
+    fi
+}
+
 # This will pick up non-directories too (eg "Kconfig") but we will
 # ignore them in the next loop.
 ARCHLIST=$(cd "$linux/arch" && echo *)
@@ -76,4 +106,15 @@ else
     cp "$linux/COPYING" "$output/linux-headers"
 fi
 
+
+cp_virtio "$tmpdir/include/linux/" "$output/include/standard-headers/linux"
+
+cat <<EOF >$output/include/standard-headers/linux/types.h
+#include <stdint.h>
+#include "qemu/compiler.h"
+EOF
+cat <<EOF >$output/include/standard-headers/linux/if_ether.h
+#define ETH_ALEN    6
+EOF
+
 rm -rf "$tmpdir"
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 32/96] include: import virtio headers from linux 4.0
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (30 preceding siblings ...)
  2015-02-18 21:47 ` [Qemu-devel] [PULL 31/96] scripts/update-linux-headers.sh: pull virtio hdrs Michael S. Tsirkin
@ 2015-02-18 21:47 ` Michael S. Tsirkin
  2015-02-18 21:47 ` [Qemu-devel] [PULL 33/96] virtio: use standard virtio_ring.h Michael S. Tsirkin
                   ` (66 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:47 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, dgilbert, Juan Quintela

Add files imported from linux-next (what will become linux 4.0) using
scripts/update-linux-headers.sh

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/standard-headers/linux/if_ether.h       |   1 +
 include/standard-headers/linux/types.h          |   2 +
 include/standard-headers/linux/virtio_9p.h      |  44 +++++
 include/standard-headers/linux/virtio_balloon.h |  59 ++++++
 include/standard-headers/linux/virtio_blk.h     | 143 +++++++++++++++
 include/standard-headers/linux/virtio_config.h  |  64 +++++++
 include/standard-headers/linux/virtio_console.h |  78 ++++++++
 include/standard-headers/linux/virtio_ids.h     |  43 +++++
 include/standard-headers/linux/virtio_net.h     | 233 ++++++++++++++++++++++++
 include/standard-headers/linux/virtio_pci.h     | 193 ++++++++++++++++++++
 include/standard-headers/linux/virtio_ring.h    | 171 +++++++++++++++++
 include/standard-headers/linux/virtio_rng.h     |   8 +
 include/standard-headers/linux/virtio_scsi.h    | 164 +++++++++++++++++
 include/standard-headers/linux/virtio_types.h   |  46 +++++
 14 files changed, 1249 insertions(+)
 create mode 100644 include/standard-headers/linux/if_ether.h
 create mode 100644 include/standard-headers/linux/types.h
 create mode 100644 include/standard-headers/linux/virtio_9p.h
 create mode 100644 include/standard-headers/linux/virtio_balloon.h
 create mode 100644 include/standard-headers/linux/virtio_blk.h
 create mode 100644 include/standard-headers/linux/virtio_config.h
 create mode 100644 include/standard-headers/linux/virtio_console.h
 create mode 100644 include/standard-headers/linux/virtio_ids.h
 create mode 100644 include/standard-headers/linux/virtio_net.h
 create mode 100644 include/standard-headers/linux/virtio_pci.h
 create mode 100644 include/standard-headers/linux/virtio_ring.h
 create mode 100644 include/standard-headers/linux/virtio_rng.h
 create mode 100644 include/standard-headers/linux/virtio_scsi.h
 create mode 100644 include/standard-headers/linux/virtio_types.h

diff --git a/include/standard-headers/linux/if_ether.h b/include/standard-headers/linux/if_ether.h
new file mode 100644
index 0000000..91cf735
--- /dev/null
+++ b/include/standard-headers/linux/if_ether.h
@@ -0,0 +1 @@
+#define ETH_ALEN    6
diff --git a/include/standard-headers/linux/types.h b/include/standard-headers/linux/types.h
new file mode 100644
index 0000000..7d42ac6
--- /dev/null
+++ b/include/standard-headers/linux/types.h
@@ -0,0 +1,2 @@
+#include <inttypes.h>
+#include "qemu/compiler.h"
diff --git a/include/standard-headers/linux/virtio_9p.h b/include/standard-headers/linux/virtio_9p.h
new file mode 100644
index 0000000..e68f71d
--- /dev/null
+++ b/include/standard-headers/linux/virtio_9p.h
@@ -0,0 +1,44 @@
+#ifndef _LINUX_VIRTIO_9P_H
+#define _LINUX_VIRTIO_9P_H
+/* This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE. */
+#include "standard-headers/linux/types.h"
+#include "standard-headers/linux/virtio_ids.h"
+#include "standard-headers/linux/virtio_config.h"
+
+/* The feature bitmap for virtio 9P */
+
+/* The mount point is specified in a config variable */
+#define VIRTIO_9P_MOUNT_TAG 0
+
+struct virtio_9p_config {
+	/* length of the tag name */
+	uint16_t tag_len;
+	/* non-NULL terminated tag name */
+	uint8_t tag[0];
+} QEMU_PACKED;
+
+#endif /* _LINUX_VIRTIO_9P_H */
diff --git a/include/standard-headers/linux/virtio_balloon.h b/include/standard-headers/linux/virtio_balloon.h
new file mode 100644
index 0000000..799376d
--- /dev/null
+++ b/include/standard-headers/linux/virtio_balloon.h
@@ -0,0 +1,59 @@
+#ifndef _LINUX_VIRTIO_BALLOON_H
+#define _LINUX_VIRTIO_BALLOON_H
+/* This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE. */
+#include "standard-headers/linux/virtio_ids.h"
+#include "standard-headers/linux/virtio_config.h"
+
+/* The feature bitmap for virtio balloon */
+#define VIRTIO_BALLOON_F_MUST_TELL_HOST	0 /* Tell before reclaiming pages */
+#define VIRTIO_BALLOON_F_STATS_VQ	1 /* Memory Stats virtqueue */
+#define VIRTIO_BALLOON_F_DEFLATE_ON_OOM	2 /* Deflate balloon on OOM */
+
+/* Size of a PFN in the balloon interface. */
+#define VIRTIO_BALLOON_PFN_SHIFT 12
+
+struct virtio_balloon_config {
+	/* Number of pages host wants Guest to give up. */
+	uint32_t num_pages;
+	/* Number of pages we've actually got in balloon. */
+	uint32_t actual;
+};
+
+#define VIRTIO_BALLOON_S_SWAP_IN  0   /* Amount of memory swapped in */
+#define VIRTIO_BALLOON_S_SWAP_OUT 1   /* Amount of memory swapped out */
+#define VIRTIO_BALLOON_S_MAJFLT   2   /* Number of major faults */
+#define VIRTIO_BALLOON_S_MINFLT   3   /* Number of minor faults */
+#define VIRTIO_BALLOON_S_MEMFREE  4   /* Total amount of free memory */
+#define VIRTIO_BALLOON_S_MEMTOT   5   /* Total amount of memory */
+#define VIRTIO_BALLOON_S_NR       6
+
+struct virtio_balloon_stat {
+	uint16_t tag;
+	uint64_t val;
+} QEMU_PACKED;
+
+#endif /* _LINUX_VIRTIO_BALLOON_H */
diff --git a/include/standard-headers/linux/virtio_blk.h b/include/standard-headers/linux/virtio_blk.h
new file mode 100644
index 0000000..12016b4
--- /dev/null
+++ b/include/standard-headers/linux/virtio_blk.h
@@ -0,0 +1,143 @@
+#ifndef _LINUX_VIRTIO_BLK_H
+#define _LINUX_VIRTIO_BLK_H
+/* This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE. */
+#include "standard-headers/linux/types.h"
+#include "standard-headers/linux/virtio_ids.h"
+#include "standard-headers/linux/virtio_config.h"
+#include "standard-headers/linux/virtio_types.h"
+
+/* Feature bits */
+#define VIRTIO_BLK_F_SIZE_MAX	1	/* Indicates maximum segment size */
+#define VIRTIO_BLK_F_SEG_MAX	2	/* Indicates maximum # of segments */
+#define VIRTIO_BLK_F_GEOMETRY	4	/* Legacy geometry available  */
+#define VIRTIO_BLK_F_RO		5	/* Disk is read-only */
+#define VIRTIO_BLK_F_BLK_SIZE	6	/* Block size of disk is available*/
+#define VIRTIO_BLK_F_TOPOLOGY	10	/* Topology information is available */
+#define VIRTIO_BLK_F_MQ		12	/* support more than one vq */
+
+/* Legacy feature bits */
+#ifndef VIRTIO_BLK_NO_LEGACY
+#define VIRTIO_BLK_F_BARRIER	0	/* Does host support barriers? */
+#define VIRTIO_BLK_F_SCSI	7	/* Supports scsi command passthru */
+#define VIRTIO_BLK_F_WCE	9	/* Writeback mode enabled after reset */
+#define VIRTIO_BLK_F_CONFIG_WCE	11	/* Writeback mode available in config */
+/* Old (deprecated) name for VIRTIO_BLK_F_WCE. */
+#define VIRTIO_BLK_F_FLUSH VIRTIO_BLK_F_WCE
+#endif /* !VIRTIO_BLK_NO_LEGACY */
+
+#define VIRTIO_BLK_ID_BYTES	20	/* ID string length */
+
+struct virtio_blk_config {
+	/* The capacity (in 512-byte sectors). */
+	uint64_t capacity;
+	/* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */
+	uint32_t size_max;
+	/* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */
+	uint32_t seg_max;
+	/* geometry the device (if VIRTIO_BLK_F_GEOMETRY) */
+	struct virtio_blk_geometry {
+		uint16_t cylinders;
+		uint8_t heads;
+		uint8_t sectors;
+	} geometry;
+
+	/* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */
+	uint32_t blk_size;
+
+	/* the next 4 entries are guarded by VIRTIO_BLK_F_TOPOLOGY  */
+	/* exponent for physical block per logical block. */
+	uint8_t physical_block_exp;
+	/* alignment offset in logical blocks. */
+	uint8_t alignment_offset;
+	/* minimum I/O size without performance penalty in logical blocks. */
+	uint16_t min_io_size;
+	/* optimal sustained I/O size in logical blocks. */
+	uint32_t opt_io_size;
+
+	/* writeback mode (if VIRTIO_BLK_F_CONFIG_WCE) */
+	uint8_t wce;
+	uint8_t unused;
+
+	/* number of vqs, only available when VIRTIO_BLK_F_MQ is set */
+	uint16_t num_queues;
+} QEMU_PACKED;
+
+/*
+ * Command types
+ *
+ * Usage is a bit tricky as some bits are used as flags and some are not.
+ *
+ * Rules:
+ *   VIRTIO_BLK_T_OUT may be combined with VIRTIO_BLK_T_SCSI_CMD or
+ *   VIRTIO_BLK_T_BARRIER.  VIRTIO_BLK_T_FLUSH is a command of its own
+ *   and may not be combined with any of the other flags.
+ */
+
+/* These two define direction. */
+#define VIRTIO_BLK_T_IN		0
+#define VIRTIO_BLK_T_OUT	1
+
+#ifndef VIRTIO_BLK_NO_LEGACY
+/* This bit says it's a scsi command, not an actual read or write. */
+#define VIRTIO_BLK_T_SCSI_CMD	2
+#endif /* VIRTIO_BLK_NO_LEGACY */
+
+/* Cache flush command */
+#define VIRTIO_BLK_T_FLUSH	4
+
+/* Get device ID command */
+#define VIRTIO_BLK_T_GET_ID    8
+
+#ifndef VIRTIO_BLK_NO_LEGACY
+/* Barrier before this op. */
+#define VIRTIO_BLK_T_BARRIER	0x80000000
+#endif /* !VIRTIO_BLK_NO_LEGACY */
+
+/* This is the first element of the read scatter-gather list. */
+struct virtio_blk_outhdr {
+	/* VIRTIO_BLK_T* */
+	__virtio32 type;
+	/* io priority. */
+	__virtio32 ioprio;
+	/* Sector (ie. 512 byte offset) */
+	__virtio64 sector;
+};
+
+#ifndef VIRTIO_BLK_NO_LEGACY
+struct virtio_scsi_inhdr {
+	__virtio32 errors;
+	__virtio32 data_len;
+	__virtio32 sense_len;
+	__virtio32 residual;
+};
+#endif /* !VIRTIO_BLK_NO_LEGACY */
+
+/* And this is the final byte of the write scatter-gather list. */
+#define VIRTIO_BLK_S_OK		0
+#define VIRTIO_BLK_S_IOERR	1
+#define VIRTIO_BLK_S_UNSUPP	2
+#endif /* _LINUX_VIRTIO_BLK_H */
diff --git a/include/standard-headers/linux/virtio_config.h b/include/standard-headers/linux/virtio_config.h
new file mode 100644
index 0000000..bcc445b
--- /dev/null
+++ b/include/standard-headers/linux/virtio_config.h
@@ -0,0 +1,64 @@
+#ifndef _LINUX_VIRTIO_CONFIG_H
+#define _LINUX_VIRTIO_CONFIG_H
+/* This header, excluding the #ifdef __KERNEL__ part, is BSD licensed so
+ * anyone can use the definitions to implement compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE. */
+
+/* Virtio devices use a standardized configuration space to define their
+ * features and pass configuration information, but each implementation can
+ * store and access that space differently. */
+#include "standard-headers/linux/types.h"
+
+/* Status byte for guest to report progress, and synchronize features. */
+/* We have seen device and processed generic fields (VIRTIO_CONFIG_F_VIRTIO) */
+#define VIRTIO_CONFIG_S_ACKNOWLEDGE	1
+/* We have found a driver for the device. */
+#define VIRTIO_CONFIG_S_DRIVER		2
+/* Driver has used its parts of the config, and is happy */
+#define VIRTIO_CONFIG_S_DRIVER_OK	4
+/* Driver has finished configuring features */
+#define VIRTIO_CONFIG_S_FEATURES_OK	8
+/* We've given up on this device. */
+#define VIRTIO_CONFIG_S_FAILED		0x80
+
+/* Some virtio feature bits (currently bits 28 through 32) are reserved for the
+ * transport being used (eg. virtio_ring), the rest are per-device feature
+ * bits. */
+#define VIRTIO_TRANSPORT_F_START	28
+#define VIRTIO_TRANSPORT_F_END		33
+
+#ifndef VIRTIO_CONFIG_NO_LEGACY
+/* Do we get callbacks when the ring is completely used, even if we've
+ * suppressed them? */
+#define VIRTIO_F_NOTIFY_ON_EMPTY	24
+
+/* Can the device handle any descriptor layout? */
+#define VIRTIO_F_ANY_LAYOUT		27
+#endif /* VIRTIO_CONFIG_NO_LEGACY */
+
+/* v1.0 compliant. */
+#define VIRTIO_F_VERSION_1		32
+
+#endif /* _LINUX_VIRTIO_CONFIG_H */
diff --git a/include/standard-headers/linux/virtio_console.h b/include/standard-headers/linux/virtio_console.h
new file mode 100644
index 0000000..0dedc9e
--- /dev/null
+++ b/include/standard-headers/linux/virtio_console.h
@@ -0,0 +1,78 @@
+/*
+ * This header, excluding the #ifdef __KERNEL__ part, is BSD licensed so
+ * anyone can use the definitions to implement compatible drivers/servers:
+ *
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Copyright (C) Red Hat, Inc., 2009, 2010, 2011
+ * Copyright (C) Amit Shah <amit.shah@redhat.com>, 2009, 2010, 2011
+ */
+#ifndef _LINUX_VIRTIO_CONSOLE_H
+#define _LINUX_VIRTIO_CONSOLE_H
+#include "standard-headers/linux/types.h"
+#include "standard-headers/linux/virtio_types.h"
+#include "standard-headers/linux/virtio_ids.h"
+#include "standard-headers/linux/virtio_config.h"
+
+/* Feature bits */
+#define VIRTIO_CONSOLE_F_SIZE	0	/* Does host provide console size? */
+#define VIRTIO_CONSOLE_F_MULTIPORT 1	/* Does host provide multiple ports? */
+#define VIRTIO_CONSOLE_F_EMERG_WRITE 2 /* Does host support emergency write? */
+
+#define VIRTIO_CONSOLE_BAD_ID		(~(uint32_t)0)
+
+struct virtio_console_config {
+	/* colums of the screens */
+	uint16_t cols;
+	/* rows of the screens */
+	uint16_t rows;
+	/* max. number of ports this device can hold */
+	uint32_t max_nr_ports;
+	/* emergency write register */
+	uint32_t emerg_wr;
+} QEMU_PACKED;
+
+/*
+ * A message that's passed between the Host and the Guest for a
+ * particular port.
+ */
+struct virtio_console_control {
+	__virtio32 id;		/* Port number */
+	__virtio16 event;	/* The kind of control event (see below) */
+	__virtio16 value;	/* Extra information for the key */
+};
+
+/* Some events for control messages */
+#define VIRTIO_CONSOLE_DEVICE_READY	0
+#define VIRTIO_CONSOLE_PORT_ADD		1
+#define VIRTIO_CONSOLE_PORT_REMOVE	2
+#define VIRTIO_CONSOLE_PORT_READY	3
+#define VIRTIO_CONSOLE_CONSOLE_PORT	4
+#define VIRTIO_CONSOLE_RESIZE		5
+#define VIRTIO_CONSOLE_PORT_OPEN	6
+#define VIRTIO_CONSOLE_PORT_NAME	7
+
+
+#endif /* _LINUX_VIRTIO_CONSOLE_H */
diff --git a/include/standard-headers/linux/virtio_ids.h b/include/standard-headers/linux/virtio_ids.h
new file mode 100644
index 0000000..284fc3a
--- /dev/null
+++ b/include/standard-headers/linux/virtio_ids.h
@@ -0,0 +1,43 @@
+#ifndef _LINUX_VIRTIO_IDS_H
+#define _LINUX_VIRTIO_IDS_H
+/*
+ * Virtio IDs
+ *
+ * This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE. */
+
+#define VIRTIO_ID_NET		1 /* virtio net */
+#define VIRTIO_ID_BLOCK		2 /* virtio block */
+#define VIRTIO_ID_CONSOLE	3 /* virtio console */
+#define VIRTIO_ID_RNG		4 /* virtio rng */
+#define VIRTIO_ID_BALLOON	5 /* virtio balloon */
+#define VIRTIO_ID_RPMSG		7 /* virtio remote processor messaging */
+#define VIRTIO_ID_SCSI		8 /* virtio scsi */
+#define VIRTIO_ID_9P		9 /* 9p virtio console */
+#define VIRTIO_ID_RPROC_SERIAL 11 /* virtio remoteproc serial link */
+#define VIRTIO_ID_CAIF	       12 /* Virtio caif */
+
+#endif /* _LINUX_VIRTIO_IDS_H */
diff --git a/include/standard-headers/linux/virtio_net.h b/include/standard-headers/linux/virtio_net.h
new file mode 100644
index 0000000..95faf67
--- /dev/null
+++ b/include/standard-headers/linux/virtio_net.h
@@ -0,0 +1,233 @@
+#ifndef _LINUX_VIRTIO_NET_H
+#define _LINUX_VIRTIO_NET_H
+/* This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE. */
+#include "standard-headers/linux/types.h"
+#include "standard-headers/linux/virtio_ids.h"
+#include "standard-headers/linux/virtio_config.h"
+#include "standard-headers/linux/virtio_types.h"
+#include "standard-headers/linux/if_ether.h"
+
+/* The feature bitmap for virtio net */
+#define VIRTIO_NET_F_CSUM	0	/* Host handles pkts w/ partial csum */
+#define VIRTIO_NET_F_GUEST_CSUM	1	/* Guest handles pkts w/ partial csum */
+#define VIRTIO_NET_F_MAC	5	/* Host has given MAC address. */
+#define VIRTIO_NET_F_GUEST_TSO4	7	/* Guest can handle TSOv4 in. */
+#define VIRTIO_NET_F_GUEST_TSO6	8	/* Guest can handle TSOv6 in. */
+#define VIRTIO_NET_F_GUEST_ECN	9	/* Guest can handle TSO[6] w/ ECN in. */
+#define VIRTIO_NET_F_GUEST_UFO	10	/* Guest can handle UFO in. */
+#define VIRTIO_NET_F_HOST_TSO4	11	/* Host can handle TSOv4 in. */
+#define VIRTIO_NET_F_HOST_TSO6	12	/* Host can handle TSOv6 in. */
+#define VIRTIO_NET_F_HOST_ECN	13	/* Host can handle TSO[6] w/ ECN in. */
+#define VIRTIO_NET_F_HOST_UFO	14	/* Host can handle UFO in. */
+#define VIRTIO_NET_F_MRG_RXBUF	15	/* Host can merge receive buffers. */
+#define VIRTIO_NET_F_STATUS	16	/* virtio_net_config.status available */
+#define VIRTIO_NET_F_CTRL_VQ	17	/* Control channel available */
+#define VIRTIO_NET_F_CTRL_RX	18	/* Control channel RX mode support */
+#define VIRTIO_NET_F_CTRL_VLAN	19	/* Control channel VLAN filtering */
+#define VIRTIO_NET_F_CTRL_RX_EXTRA 20	/* Extra RX mode control support */
+#define VIRTIO_NET_F_GUEST_ANNOUNCE 21	/* Guest can announce device on the
+					 * network */
+#define VIRTIO_NET_F_MQ	22	/* Device supports Receive Flow
+					 * Steering */
+#define VIRTIO_NET_F_CTRL_MAC_ADDR 23	/* Set MAC address */
+
+#ifndef VIRTIO_NET_NO_LEGACY
+#define VIRTIO_NET_F_GSO	6	/* Host handles pkts w/ any GSO type */
+#endif /* VIRTIO_NET_NO_LEGACY */
+
+#define VIRTIO_NET_S_LINK_UP	1	/* Link is up */
+#define VIRTIO_NET_S_ANNOUNCE	2	/* Announcement is needed */
+
+struct virtio_net_config {
+	/* The config defining mac address (if VIRTIO_NET_F_MAC) */
+	uint8_t mac[ETH_ALEN];
+	/* See VIRTIO_NET_F_STATUS and VIRTIO_NET_S_* above */
+	uint16_t status;
+	/* Maximum number of each of transmit and receive queues;
+	 * see VIRTIO_NET_F_MQ and VIRTIO_NET_CTRL_MQ.
+	 * Legal values are between 1 and 0x8000
+	 */
+	uint16_t max_virtqueue_pairs;
+} QEMU_PACKED;
+
+#ifndef VIRTIO_NET_NO_LEGACY
+/* This header comes first in the scatter-gather list.
+ * For legacy virtio, if VIRTIO_F_ANY_LAYOUT is not negotiated, it must
+ * be the first element of the scatter-gather list.  If you don't
+ * specify GSO or CSUM features, you can simply ignore the header. */
+struct virtio_net_hdr {
+#define VIRTIO_NET_HDR_F_NEEDS_CSUM	1	// Use csum_start, csum_offset
+#define VIRTIO_NET_HDR_F_DATA_VALID	2	// Csum is valid
+	uint8_t flags;
+#define VIRTIO_NET_HDR_GSO_NONE		0	// Not a GSO frame
+#define VIRTIO_NET_HDR_GSO_TCPV4	1	// GSO frame, IPv4 TCP (TSO)
+#define VIRTIO_NET_HDR_GSO_UDP		3	// GSO frame, IPv4 UDP (UFO)
+#define VIRTIO_NET_HDR_GSO_TCPV6	4	// GSO frame, IPv6 TCP
+#define VIRTIO_NET_HDR_GSO_ECN		0x80	// TCP has ECN set
+	uint8_t gso_type;
+	__virtio16 hdr_len;		/* Ethernet + IP + tcp/udp hdrs */
+	__virtio16 gso_size;		/* Bytes to append to hdr_len per frame */
+	__virtio16 csum_start;	/* Position to start checksumming from */
+	__virtio16 csum_offset;	/* Offset after that to place checksum */
+};
+
+/* This is the version of the header to use when the MRG_RXBUF
+ * feature has been negotiated. */
+struct virtio_net_hdr_mrg_rxbuf {
+	struct virtio_net_hdr hdr;
+	__virtio16 num_buffers;	/* Number of merged rx buffers */
+};
+#else /* ... VIRTIO_NET_NO_LEGACY */
+/*
+ * This header comes first in the scatter-gather list.  If you don't
+ * specify GSO or CSUM features, you can simply ignore the header.
+ *
+ * This is bitwise-equivalent to the legacy struct virtio_net_hdr_mrg_rxbuf.
+ */
+struct virtio_net_hdr_v1 {
+#define VIRTIO_NET_HDR_F_NEEDS_CSUM	1	/* Use csum_start, csum_offset */
+#define VIRTIO_NET_HDR_F_DATA_VALID	2	/* Csum is valid */
+	uint8_t flags;
+#define VIRTIO_NET_HDR_GSO_NONE		0	/* Not a GSO frame */
+#define VIRTIO_NET_HDR_GSO_TCPV4	1	/* GSO frame, IPv4 TCP (TSO) */
+#define VIRTIO_NET_HDR_GSO_UDP		3	/* GSO frame, IPv4 UDP (UFO) */
+#define VIRTIO_NET_HDR_GSO_TCPV6	4	/* GSO frame, IPv6 TCP */
+#define VIRTIO_NET_HDR_GSO_ECN		0x80	/* TCP has ECN set */
+	uint8_t gso_type;
+	__virtio16 hdr_len;	/* Ethernet + IP + tcp/udp hdrs */
+	__virtio16 gso_size;	/* Bytes to append to hdr_len per frame */
+	__virtio16 csum_start;	/* Position to start checksumming from */
+	__virtio16 csum_offset;	/* Offset after that to place checksum */
+	__virtio16 num_buffers;	/* Number of merged rx buffers */
+};
+#endif /* ...VIRTIO_NET_NO_LEGACY */
+
+/*
+ * Control virtqueue data structures
+ *
+ * The control virtqueue expects a header in the first sg entry
+ * and an ack/status response in the last entry.  Data for the
+ * command goes in between.
+ */
+struct virtio_net_ctrl_hdr {
+	uint8_t class;
+	uint8_t cmd;
+} QEMU_PACKED;
+
+typedef uint8_t virtio_net_ctrl_ack;
+
+#define VIRTIO_NET_OK     0
+#define VIRTIO_NET_ERR    1
+
+/*
+ * Control the RX mode, ie. promisucous, allmulti, etc...
+ * All commands require an "out" sg entry containing a 1 byte
+ * state value, zero = disable, non-zero = enable.  Commands
+ * 0 and 1 are supported with the VIRTIO_NET_F_CTRL_RX feature.
+ * Commands 2-5 are added with VIRTIO_NET_F_CTRL_RX_EXTRA.
+ */
+#define VIRTIO_NET_CTRL_RX    0
+ #define VIRTIO_NET_CTRL_RX_PROMISC      0
+ #define VIRTIO_NET_CTRL_RX_ALLMULTI     1
+ #define VIRTIO_NET_CTRL_RX_ALLUNI       2
+ #define VIRTIO_NET_CTRL_RX_NOMULTI      3
+ #define VIRTIO_NET_CTRL_RX_NOUNI        4
+ #define VIRTIO_NET_CTRL_RX_NOBCAST      5
+
+/*
+ * Control the MAC
+ *
+ * The MAC filter table is managed by the hypervisor, the guest should
+ * assume the size is infinite.  Filtering should be considered
+ * non-perfect, ie. based on hypervisor resources, the guest may
+ * received packets from sources not specified in the filter list.
+ *
+ * In addition to the class/cmd header, the TABLE_SET command requires
+ * two out scatterlists.  Each contains a 4 byte count of entries followed
+ * by a concatenated byte stream of the ETH_ALEN MAC addresses.  The
+ * first sg list contains unicast addresses, the second is for multicast.
+ * This functionality is present if the VIRTIO_NET_F_CTRL_RX feature
+ * is available.
+ *
+ * The ADDR_SET command requests one out scatterlist, it contains a
+ * 6 bytes MAC address. This functionality is present if the
+ * VIRTIO_NET_F_CTRL_MAC_ADDR feature is available.
+ */
+struct virtio_net_ctrl_mac {
+	__virtio32 entries;
+	uint8_t macs[][ETH_ALEN];
+} QEMU_PACKED;
+
+#define VIRTIO_NET_CTRL_MAC    1
+ #define VIRTIO_NET_CTRL_MAC_TABLE_SET        0
+ #define VIRTIO_NET_CTRL_MAC_ADDR_SET         1
+
+/*
+ * Control VLAN filtering
+ *
+ * The VLAN filter table is controlled via a simple ADD/DEL interface.
+ * VLAN IDs not added may be filterd by the hypervisor.  Del is the
+ * opposite of add.  Both commands expect an out entry containing a 2
+ * byte VLAN ID.  VLAN filterting is available with the
+ * VIRTIO_NET_F_CTRL_VLAN feature bit.
+ */
+#define VIRTIO_NET_CTRL_VLAN       2
+ #define VIRTIO_NET_CTRL_VLAN_ADD             0
+ #define VIRTIO_NET_CTRL_VLAN_DEL             1
+
+/*
+ * Control link announce acknowledgement
+ *
+ * The command VIRTIO_NET_CTRL_ANNOUNCE_ACK is used to indicate that
+ * driver has recevied the notification; device would clear the
+ * VIRTIO_NET_S_ANNOUNCE bit in the status field after it receives
+ * this command.
+ */
+#define VIRTIO_NET_CTRL_ANNOUNCE       3
+ #define VIRTIO_NET_CTRL_ANNOUNCE_ACK         0
+
+/*
+ * Control Receive Flow Steering
+ *
+ * The command VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET
+ * enables Receive Flow Steering, specifying the number of the transmit and
+ * receive queues that will be used. After the command is consumed and acked by
+ * the device, the device will not steer new packets on receive virtqueues
+ * other than specified nor read from transmit virtqueues other than specified.
+ * Accordingly, driver should not transmit new packets  on virtqueues other than
+ * specified.
+ */
+struct virtio_net_ctrl_mq {
+	__virtio16 virtqueue_pairs;
+};
+
+#define VIRTIO_NET_CTRL_MQ   4
+ #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET        0
+ #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN        1
+ #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX        0x8000
+
+#endif /* _LINUX_VIRTIO_NET_H */
diff --git a/include/standard-headers/linux/virtio_pci.h b/include/standard-headers/linux/virtio_pci.h
new file mode 100644
index 0000000..ecdc133
--- /dev/null
+++ b/include/standard-headers/linux/virtio_pci.h
@@ -0,0 +1,193 @@
+/*
+ * Virtio PCI driver
+ *
+ * This module allows virtio devices to be used over a virtual PCI device.
+ * This can be used with QEMU based VMMs like KVM or Xen.
+ *
+ * Copyright IBM Corp. 2007
+ *
+ * Authors:
+ *  Anthony Liguori  <aliguori@us.ibm.com>
+ *
+ * This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_VIRTIO_PCI_H
+#define _LINUX_VIRTIO_PCI_H
+
+#include "standard-headers/linux/types.h"
+
+#ifndef VIRTIO_PCI_NO_LEGACY
+
+/* A 32-bit r/o bitmask of the features supported by the host */
+#define VIRTIO_PCI_HOST_FEATURES	0
+
+/* A 32-bit r/w bitmask of features activated by the guest */
+#define VIRTIO_PCI_GUEST_FEATURES	4
+
+/* A 32-bit r/w PFN for the currently selected queue */
+#define VIRTIO_PCI_QUEUE_PFN		8
+
+/* A 16-bit r/o queue size for the currently selected queue */
+#define VIRTIO_PCI_QUEUE_NUM		12
+
+/* A 16-bit r/w queue selector */
+#define VIRTIO_PCI_QUEUE_SEL		14
+
+/* A 16-bit r/w queue notifier */
+#define VIRTIO_PCI_QUEUE_NOTIFY		16
+
+/* An 8-bit device status register.  */
+#define VIRTIO_PCI_STATUS		18
+
+/* An 8-bit r/o interrupt status register.  Reading the value will return the
+ * current contents of the ISR and will also clear it.  This is effectively
+ * a read-and-acknowledge. */
+#define VIRTIO_PCI_ISR			19
+
+/* MSI-X registers: only enabled if MSI-X is enabled. */
+/* A 16-bit vector for configuration changes. */
+#define VIRTIO_MSI_CONFIG_VECTOR        20
+/* A 16-bit vector for selected queue notifications. */
+#define VIRTIO_MSI_QUEUE_VECTOR         22
+
+/* The remaining space is defined by each driver as the per-driver
+ * configuration space */
+#define VIRTIO_PCI_CONFIG_OFF(msix_enabled)	((msix_enabled) ? 24 : 20)
+/* Deprecated: please use VIRTIO_PCI_CONFIG_OFF instead */
+#define VIRTIO_PCI_CONFIG(dev)	VIRTIO_PCI_CONFIG_OFF((dev)->msix_enabled)
+
+/* Virtio ABI version, this must match exactly */
+#define VIRTIO_PCI_ABI_VERSION		0
+
+/* How many bits to shift physical queue address written to QUEUE_PFN.
+ * 12 is historical, and due to x86 page size. */
+#define VIRTIO_PCI_QUEUE_ADDR_SHIFT	12
+
+/* The alignment to use between consumer and producer parts of vring.
+ * x86 pagesize again. */
+#define VIRTIO_PCI_VRING_ALIGN		4096
+
+#endif /* VIRTIO_PCI_NO_LEGACY */
+
+/* The bit of the ISR which indicates a device configuration change. */
+#define VIRTIO_PCI_ISR_CONFIG		0x2
+/* Vector value used to disable MSI for queue */
+#define VIRTIO_MSI_NO_VECTOR            0xffff
+
+#ifndef VIRTIO_PCI_NO_MODERN
+
+/* IDs for different capabilities.  Must all exist. */
+
+/* Common configuration */
+#define VIRTIO_PCI_CAP_COMMON_CFG	1
+/* Notifications */
+#define VIRTIO_PCI_CAP_NOTIFY_CFG	2
+/* ISR access */
+#define VIRTIO_PCI_CAP_ISR_CFG		3
+/* Device specific configuration */
+#define VIRTIO_PCI_CAP_DEVICE_CFG	4
+/* PCI configuration access */
+#define VIRTIO_PCI_CAP_PCI_CFG		5
+
+/* This is the PCI capability header: */
+struct virtio_pci_cap {
+	uint8_t cap_vndr;		/* Generic PCI field: PCI_CAP_ID_VNDR */
+	uint8_t cap_next;		/* Generic PCI field: next ptr. */
+	uint8_t cap_len;		/* Generic PCI field: capability length */
+	uint8_t cfg_type;		/* Identifies the structure. */
+	uint8_t bar;		/* Where to find it. */
+	uint8_t padding[3];	/* Pad to full dword. */
+	uint32_t offset;		/* Offset within bar. */
+	uint32_t length;		/* Length of the structure, in bytes. */
+};
+
+struct virtio_pci_notify_cap {
+	struct virtio_pci_cap cap;
+	uint32_t notify_off_multiplier;	/* Multiplier for queue_notify_off. */
+};
+
+/* Fields in VIRTIO_PCI_CAP_COMMON_CFG: */
+struct virtio_pci_common_cfg {
+	/* About the whole device. */
+	uint32_t device_feature_select;	/* read-write */
+	uint32_t device_feature;		/* read-only */
+	uint32_t guest_feature_select;	/* read-write */
+	uint32_t guest_feature;		/* read-write */
+	uint16_t msix_config;		/* read-write */
+	uint16_t num_queues;		/* read-only */
+	uint8_t device_status;		/* read-write */
+	uint8_t config_generation;		/* read-only */
+
+	/* About a specific virtqueue. */
+	uint16_t queue_select;		/* read-write */
+	uint16_t queue_size;		/* read-write, power of 2. */
+	uint16_t queue_msix_vector;	/* read-write */
+	uint16_t queue_enable;		/* read-write */
+	uint16_t queue_notify_off;	/* read-only */
+	uint32_t queue_desc_lo;		/* read-write */
+	uint32_t queue_desc_hi;		/* read-write */
+	uint32_t queue_avail_lo;		/* read-write */
+	uint32_t queue_avail_hi;		/* read-write */
+	uint32_t queue_used_lo;		/* read-write */
+	uint32_t queue_used_hi;		/* read-write */
+};
+
+/* Macro versions of offsets for the Old Timers! */
+#define VIRTIO_PCI_CAP_VNDR		0
+#define VIRTIO_PCI_CAP_NEXT		1
+#define VIRTIO_PCI_CAP_LEN		2
+#define VIRTIO_PCI_CAP_CFG_TYPE		3
+#define VIRTIO_PCI_CAP_BAR		4
+#define VIRTIO_PCI_CAP_OFFSET		8
+#define VIRTIO_PCI_CAP_LENGTH		12
+
+#define VIRTIO_PCI_NOTIFY_CAP_MULT	16
+
+#define VIRTIO_PCI_COMMON_DFSELECT	0
+#define VIRTIO_PCI_COMMON_DF		4
+#define VIRTIO_PCI_COMMON_GFSELECT	8
+#define VIRTIO_PCI_COMMON_GF		12
+#define VIRTIO_PCI_COMMON_MSIX		16
+#define VIRTIO_PCI_COMMON_NUMQ		18
+#define VIRTIO_PCI_COMMON_STATUS	20
+#define VIRTIO_PCI_COMMON_CFGGENERATION	21
+#define VIRTIO_PCI_COMMON_Q_SELECT	22
+#define VIRTIO_PCI_COMMON_Q_SIZE	24
+#define VIRTIO_PCI_COMMON_Q_MSIX	26
+#define VIRTIO_PCI_COMMON_Q_ENABLE	28
+#define VIRTIO_PCI_COMMON_Q_NOFF	30
+#define VIRTIO_PCI_COMMON_Q_DESCLO	32
+#define VIRTIO_PCI_COMMON_Q_DESCHI	36
+#define VIRTIO_PCI_COMMON_Q_AVAILLO	40
+#define VIRTIO_PCI_COMMON_Q_AVAILHI	44
+#define VIRTIO_PCI_COMMON_Q_USEDLO	48
+#define VIRTIO_PCI_COMMON_Q_USEDHI	52
+
+#endif /* VIRTIO_PCI_NO_MODERN */
+
+#endif
diff --git a/include/standard-headers/linux/virtio_ring.h b/include/standard-headers/linux/virtio_ring.h
new file mode 100644
index 0000000..2bd19a8
--- /dev/null
+++ b/include/standard-headers/linux/virtio_ring.h
@@ -0,0 +1,171 @@
+#ifndef _LINUX_VIRTIO_RING_H
+#define _LINUX_VIRTIO_RING_H
+/* An interface for efficient virtio implementation, currently for use by KVM
+ * and lguest, but hopefully others soon.  Do NOT change this since it will
+ * break existing servers and clients.
+ *
+ * This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Copyright Rusty Russell IBM Corporation 2007. */
+#include "standard-headers/linux/types.h"
+#include "standard-headers/linux/virtio_types.h"
+
+/* This marks a buffer as continuing via the next field. */
+#define VRING_DESC_F_NEXT	1
+/* This marks a buffer as write-only (otherwise read-only). */
+#define VRING_DESC_F_WRITE	2
+/* This means the buffer contains a list of buffer descriptors. */
+#define VRING_DESC_F_INDIRECT	4
+
+/* The Host uses this in used->flags to advise the Guest: don't kick me when
+ * you add a buffer.  It's unreliable, so it's simply an optimization.  Guest
+ * will still kick if it's out of buffers. */
+#define VRING_USED_F_NO_NOTIFY	1
+/* The Guest uses this in avail->flags to advise the Host: don't interrupt me
+ * when you consume a buffer.  It's unreliable, so it's simply an
+ * optimization.  */
+#define VRING_AVAIL_F_NO_INTERRUPT	1
+
+/* We support indirect buffer descriptors */
+#define VIRTIO_RING_F_INDIRECT_DESC	28
+
+/* The Guest publishes the used index for which it expects an interrupt
+ * at the end of the avail ring. Host should ignore the avail->flags field. */
+/* The Host publishes the avail index for which it expects a kick
+ * at the end of the used ring. Guest should ignore the used->flags field. */
+#define VIRTIO_RING_F_EVENT_IDX		29
+
+/* Virtio ring descriptors: 16 bytes.  These can chain together via "next". */
+struct vring_desc {
+	/* Address (guest-physical). */
+	__virtio64 addr;
+	/* Length. */
+	__virtio32 len;
+	/* The flags as indicated above. */
+	__virtio16 flags;
+	/* We chain unused descriptors via this, too */
+	__virtio16 next;
+};
+
+struct vring_avail {
+	__virtio16 flags;
+	__virtio16 idx;
+	__virtio16 ring[];
+};
+
+/* u32 is used here for ids for padding reasons. */
+struct vring_used_elem {
+	/* Index of start of used descriptor chain. */
+	__virtio32 id;
+	/* Total length of the descriptor chain which was used (written to) */
+	__virtio32 len;
+};
+
+struct vring_used {
+	__virtio16 flags;
+	__virtio16 idx;
+	struct vring_used_elem ring[];
+};
+
+struct vring {
+	unsigned int num;
+
+	struct vring_desc *desc;
+
+	struct vring_avail *avail;
+
+	struct vring_used *used;
+};
+
+/* Alignment requirements for vring elements.
+ * When using pre-virtio 1.0 layout, these fall out naturally.
+ */
+#define VRING_AVAIL_ALIGN_SIZE 2
+#define VRING_USED_ALIGN_SIZE 4
+#define VRING_DESC_ALIGN_SIZE 16
+
+/* The standard layout for the ring is a continuous chunk of memory which looks
+ * like this.  We assume num is a power of 2.
+ *
+ * struct vring
+ * {
+ *	// The actual descriptors (16 bytes each)
+ *	struct vring_desc desc[num];
+ *
+ *	// A ring of available descriptor heads with free-running index.
+ *	__virtio16 avail_flags;
+ *	__virtio16 avail_idx;
+ *	__virtio16 available[num];
+ *	__virtio16 used_event_idx;
+ *
+ *	// Padding to the next align boundary.
+ *	char pad[];
+ *
+ *	// A ring of used descriptor heads with free-running index.
+ *	__virtio16 used_flags;
+ *	__virtio16 used_idx;
+ *	struct vring_used_elem used[num];
+ *	__virtio16 avail_event_idx;
+ * };
+ */
+/* We publish the used event index at the end of the available ring, and vice
+ * versa. They are at the end for backwards compatibility. */
+#define vring_used_event(vr) ((vr)->avail->ring[(vr)->num])
+#define vring_avail_event(vr) (*(__virtio16 *)&(vr)->used->ring[(vr)->num])
+
+static __inline__ void vring_init(struct vring *vr, unsigned int num, void *p,
+			      unsigned long align)
+{
+	vr->num = num;
+	vr->desc = p;
+	vr->avail = p + num*sizeof(struct vring_desc);
+	vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + sizeof(__virtio16)
+		+ align-1) & ~(align - 1));
+}
+
+static __inline__ unsigned vring_size(unsigned int num, unsigned long align)
+{
+	return ((sizeof(struct vring_desc) * num + sizeof(__virtio16) * (3 + num)
+		 + align - 1) & ~(align - 1))
+		+ sizeof(__virtio16) * 3 + sizeof(struct vring_used_elem) * num;
+}
+
+/* The following is used with USED_EVENT_IDX and AVAIL_EVENT_IDX */
+/* Assuming a given event_idx value from the other size, if
+ * we have just incremented index from old to new_idx,
+ * should we trigger an event? */
+static __inline__ int vring_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old)
+{
+	/* Note: Xen has similar logic for notification hold-off
+	 * in include/xen/interface/io/ring.h with req_event and req_prod
+	 * corresponding to event_idx + 1 and new_idx respectively.
+	 * Note also that req_event and req_prod in Xen start at 1,
+	 * event indexes in virtio start at 0. */
+	return (uint16_t)(new_idx - event_idx - 1) < (uint16_t)(new_idx - old);
+}
+
+#endif /* _LINUX_VIRTIO_RING_H */
diff --git a/include/standard-headers/linux/virtio_rng.h b/include/standard-headers/linux/virtio_rng.h
new file mode 100644
index 0000000..60fc798
--- /dev/null
+++ b/include/standard-headers/linux/virtio_rng.h
@@ -0,0 +1,8 @@
+#ifndef _LINUX_VIRTIO_RNG_H
+#define _LINUX_VIRTIO_RNG_H
+/* This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers. */
+#include "standard-headers/linux/virtio_ids.h"
+#include "standard-headers/linux/virtio_config.h"
+
+#endif /* _LINUX_VIRTIO_RNG_H */
diff --git a/include/standard-headers/linux/virtio_scsi.h b/include/standard-headers/linux/virtio_scsi.h
new file mode 100644
index 0000000..78ba9d3
--- /dev/null
+++ b/include/standard-headers/linux/virtio_scsi.h
@@ -0,0 +1,164 @@
+/*
+ * This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_VIRTIO_SCSI_H
+#define _LINUX_VIRTIO_SCSI_H
+
+#include "standard-headers/linux/virtio_types.h"
+
+#define VIRTIO_SCSI_CDB_SIZE   32
+#define VIRTIO_SCSI_SENSE_SIZE 96
+
+/* SCSI command request, followed by data-out */
+struct virtio_scsi_cmd_req {
+	uint8_t lun[8];		/* Logical Unit Number */
+	__virtio64 tag;		/* Command identifier */
+	uint8_t task_attr;		/* Task attribute */
+	uint8_t prio;		/* SAM command priority field */
+	uint8_t crn;
+	uint8_t cdb[VIRTIO_SCSI_CDB_SIZE];
+} QEMU_PACKED;
+
+/* SCSI command request, followed by protection information */
+struct virtio_scsi_cmd_req_pi {
+	uint8_t lun[8];		/* Logical Unit Number */
+	__virtio64 tag;		/* Command identifier */
+	uint8_t task_attr;		/* Task attribute */
+	uint8_t prio;		/* SAM command priority field */
+	uint8_t crn;
+	__virtio32 pi_bytesout;	/* DataOUT PI Number of bytes */
+	__virtio32 pi_bytesin;		/* DataIN PI Number of bytes */
+	uint8_t cdb[VIRTIO_SCSI_CDB_SIZE];
+} QEMU_PACKED;
+
+/* Response, followed by sense data and data-in */
+struct virtio_scsi_cmd_resp {
+	__virtio32 sense_len;		/* Sense data length */
+	__virtio32 resid;		/* Residual bytes in data buffer */
+	__virtio16 status_qualifier;	/* Status qualifier */
+	uint8_t status;		/* Command completion status */
+	uint8_t response;		/* Response values */
+	uint8_t sense[VIRTIO_SCSI_SENSE_SIZE];
+} QEMU_PACKED;
+
+/* Task Management Request */
+struct virtio_scsi_ctrl_tmf_req {
+	__virtio32 type;
+	__virtio32 subtype;
+	uint8_t lun[8];
+	__virtio64 tag;
+} QEMU_PACKED;
+
+struct virtio_scsi_ctrl_tmf_resp {
+	uint8_t response;
+} QEMU_PACKED;
+
+/* Asynchronous notification query/subscription */
+struct virtio_scsi_ctrl_an_req {
+	__virtio32 type;
+	uint8_t lun[8];
+	__virtio32 event_requested;
+} QEMU_PACKED;
+
+struct virtio_scsi_ctrl_an_resp {
+	__virtio32 event_actual;
+	uint8_t response;
+} QEMU_PACKED;
+
+struct virtio_scsi_event {
+	__virtio32 event;
+	uint8_t lun[8];
+	__virtio32 reason;
+} QEMU_PACKED;
+
+struct virtio_scsi_config {
+	uint32_t num_queues;
+	uint32_t seg_max;
+	uint32_t max_sectors;
+	uint32_t cmd_per_lun;
+	uint32_t event_info_size;
+	uint32_t sense_size;
+	uint32_t cdb_size;
+	uint16_t max_channel;
+	uint16_t max_target;
+	uint32_t max_lun;
+} QEMU_PACKED;
+
+/* Feature Bits */
+#define VIRTIO_SCSI_F_INOUT                    0
+#define VIRTIO_SCSI_F_HOTPLUG                  1
+#define VIRTIO_SCSI_F_CHANGE                   2
+#define VIRTIO_SCSI_F_T10_PI                   3
+
+/* Response codes */
+#define VIRTIO_SCSI_S_OK                       0
+#define VIRTIO_SCSI_S_OVERRUN                  1
+#define VIRTIO_SCSI_S_ABORTED                  2
+#define VIRTIO_SCSI_S_BAD_TARGET               3
+#define VIRTIO_SCSI_S_RESET                    4
+#define VIRTIO_SCSI_S_BUSY                     5
+#define VIRTIO_SCSI_S_TRANSPORT_FAILURE        6
+#define VIRTIO_SCSI_S_TARGET_FAILURE           7
+#define VIRTIO_SCSI_S_NEXUS_FAILURE            8
+#define VIRTIO_SCSI_S_FAILURE                  9
+#define VIRTIO_SCSI_S_FUNCTION_SUCCEEDED       10
+#define VIRTIO_SCSI_S_FUNCTION_REJECTED        11
+#define VIRTIO_SCSI_S_INCORRECT_LUN            12
+
+/* Controlq type codes.  */
+#define VIRTIO_SCSI_T_TMF                      0
+#define VIRTIO_SCSI_T_AN_QUERY                 1
+#define VIRTIO_SCSI_T_AN_SUBSCRIBE             2
+
+/* Valid TMF subtypes.  */
+#define VIRTIO_SCSI_T_TMF_ABORT_TASK           0
+#define VIRTIO_SCSI_T_TMF_ABORT_TASK_SET       1
+#define VIRTIO_SCSI_T_TMF_CLEAR_ACA            2
+#define VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET       3
+#define VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET      4
+#define VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET   5
+#define VIRTIO_SCSI_T_TMF_QUERY_TASK           6
+#define VIRTIO_SCSI_T_TMF_QUERY_TASK_SET       7
+
+/* Events.  */
+#define VIRTIO_SCSI_T_EVENTS_MISSED            0x80000000
+#define VIRTIO_SCSI_T_NO_EVENT                 0
+#define VIRTIO_SCSI_T_TRANSPORT_RESET          1
+#define VIRTIO_SCSI_T_ASYNC_NOTIFY             2
+#define VIRTIO_SCSI_T_PARAM_CHANGE             3
+
+/* Reasons of transport reset event */
+#define VIRTIO_SCSI_EVT_RESET_HARD             0
+#define VIRTIO_SCSI_EVT_RESET_RESCAN           1
+#define VIRTIO_SCSI_EVT_RESET_REMOVED          2
+
+#define VIRTIO_SCSI_S_SIMPLE                   0
+#define VIRTIO_SCSI_S_ORDERED                  1
+#define VIRTIO_SCSI_S_HEAD                     2
+#define VIRTIO_SCSI_S_ACA                      3
+
+
+#endif /* _LINUX_VIRTIO_SCSI_H */
diff --git a/include/standard-headers/linux/virtio_types.h b/include/standard-headers/linux/virtio_types.h
new file mode 100644
index 0000000..fd0d351
--- /dev/null
+++ b/include/standard-headers/linux/virtio_types.h
@@ -0,0 +1,46 @@
+#ifndef _LINUX_VIRTIO_TYPES_H
+#define _LINUX_VIRTIO_TYPES_H
+/* Type definitions for virtio implementations.
+ *
+ * This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ * Author: Michael S. Tsirkin <mst@redhat.com>
+ */
+#include "standard-headers/linux/types.h"
+
+/*
+ * __virtio{16,32,64} have the following meaning:
+ * - __u{16,32,64} for virtio devices in legacy mode, accessed in native endian
+ * - __le{16,32,64} for standard-compliant virtio devices
+ */
+
+typedef uint16_t  __virtio16;
+typedef uint32_t  __virtio32;
+typedef uint64_t  __virtio64;
+
+#endif /* _LINUX_VIRTIO_TYPES_H */
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 33/96] virtio: use standard virtio_ring.h
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (31 preceding siblings ...)
  2015-02-18 21:47 ` [Qemu-devel] [PULL 32/96] include: import virtio headers from linux 4.0 Michael S. Tsirkin
@ 2015-02-18 21:47 ` Michael S. Tsirkin
  2015-02-18 21:47 ` [Qemu-devel] [PULL 34/96] virtio: use standard-headers Michael S. Tsirkin
                   ` (65 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:47 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, dgilbert, Juan Quintela

Switch to virtio_ring.h from standard headers.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/virtio/dataplane/vring.h |   2 +-
 include/hw/virtio/virtio_ring.h     | 167 ------------------------------------
 hw/net/vhost_net.c                  |   2 +-
 3 files changed, 2 insertions(+), 169 deletions(-)
 delete mode 100644 include/hw/virtio/virtio_ring.h

diff --git a/include/hw/virtio/dataplane/vring.h b/include/hw/virtio/dataplane/vring.h
index d3e086a..836d26a 100644
--- a/include/hw/virtio/dataplane/vring.h
+++ b/include/hw/virtio/dataplane/vring.h
@@ -18,7 +18,7 @@
 #define VRING_H
 
 #include "qemu-common.h"
-#include "hw/virtio/virtio_ring.h"
+#include "standard-headers/linux/virtio_ring.h"
 #include "hw/virtio/virtio.h"
 
 typedef struct {
diff --git a/include/hw/virtio/virtio_ring.h b/include/hw/virtio/virtio_ring.h
deleted file mode 100644
index 0b42e6e..0000000
--- a/include/hw/virtio/virtio_ring.h
+++ /dev/null
@@ -1,167 +0,0 @@
-#ifndef _LINUX_VIRTIO_RING_H
-#define _LINUX_VIRTIO_RING_H
-/*
- * This file is copied from /usr/include/linux while converting __uNN types
- * to uXX_t, __inline__ to inline, and tab to spaces.
- * */
-
-/* An interface for efficient virtio implementation, currently for use by KVM
- * and lguest, but hopefully others soon.  Do NOT change this since it will
- * break existing servers and clients.
- *
- * This header is BSD licensed so anyone can use the definitions to implement
- * compatible drivers/servers.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of IBM nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * Copyright Rusty Russell IBM Corporation 2007. */
-
-/* This marks a buffer as continuing via the next field. */
-#define VRING_DESC_F_NEXT   1
-/* This marks a buffer as write-only (otherwise read-only). */
-#define VRING_DESC_F_WRITE  2
-/* This means the buffer contains a list of buffer descriptors. */
-#define VRING_DESC_F_INDIRECT   4
-
-/* The Host uses this in used->flags to advise the Guest: don't kick me when
- * you add a buffer.  It's unreliable, so it's simply an optimization.  Guest
- * will still kick if it's out of buffers. */
-#define VRING_USED_F_NO_NOTIFY  1
-/* The Guest uses this in avail->flags to advise the Host: don't interrupt me
- * when you consume a buffer.  It's unreliable, so it's simply an
- * optimization.  */
-#define VRING_AVAIL_F_NO_INTERRUPT  1
-
-/* We support indirect buffer descriptors */
-#define VIRTIO_RING_F_INDIRECT_DESC 28
-
-/* The Guest publishes the used index for which it expects an interrupt
- * at the end of the avail ring. Host should ignore the avail->flags field. */
-/* The Host publishes the avail index for which it expects a kick
- * at the end of the used ring. Guest should ignore the used->flags field. */
-#define VIRTIO_RING_F_EVENT_IDX     29
-
-/* Virtio ring descriptors: 16 bytes.  These can chain together via "next". */
-struct vring_desc {
-    /* Address (guest-physical). */
-    uint64_t addr;
-    /* Length. */
-    uint32_t len;
-    /* The flags as indicated above. */
-    uint16_t flags;
-    /* We chain unused descriptors via this, too */
-    uint16_t next;
-};
-
-struct vring_avail {
-    uint16_t flags;
-    uint16_t idx;
-    uint16_t ring[];
-};
-
-/* u32 is used here for ids for padding reasons. */
-struct vring_used_elem {
-    /* Index of start of used descriptor chain. */
-    uint32_t id;
-    /* Total length of the descriptor chain which was used (written to) */
-    uint32_t len;
-};
-
-struct vring_used {
-    uint16_t flags;
-    uint16_t idx;
-    struct vring_used_elem ring[];
-};
-
-struct vring {
-    unsigned int num;
-
-    struct vring_desc *desc;
-
-    struct vring_avail *avail;
-
-    struct vring_used *used;
-};
-
-/* The standard layout for the ring is a continuous chunk of memory which looks
- * like this.  We assume num is a power of 2.
- *
- * struct vring
- * {
- *  // The actual descriptors (16 bytes each)
- *  struct vring_desc desc[num];
- *
- *  // A ring of available descriptor heads with free-running index.
- *  uint16_t avail_flags;
- *  uint16_t avail_idx;
- *  uint16_t available[num];
- *  uint16_t used_event_idx;
- *
- *  // Padding to the next align boundary.
- *  char pad[];
- *
- *  // A ring of used descriptor heads with free-running index.
- *  uint16_t used_flags;
- *  uint16_t used_idx;
- *  struct vring_used_elem used[num];
- *  uint16_t avail_event_idx;
- * };
- */
-/* We publish the used event index at the end of the available ring, and vice
- * versa. They are at the end for backwards compatibility. */
-#define vring_used_event(vr) ((vr)->avail->ring[(vr)->num])
-#define vring_avail_event(vr) (*(uint16_t *)&(vr)->used->ring[(vr)->num])
-
-static inline void vring_init(struct vring *vr, unsigned int num, void *p,
-                  unsigned long align)
-{
-    vr->num = num;
-    vr->desc = p;
-    vr->avail = p + num*sizeof(struct vring_desc);
-    vr->used = (void *)(((uintptr_t)&vr->avail->ring[num] + sizeof(uint16_t)
-        + align - 1) & ~(align - 1));
-}
-
-static inline unsigned vring_size(unsigned int num, unsigned long align)
-{
-    return ((sizeof(struct vring_desc) * num + sizeof(uint16_t) * (3 + num)
-         + align - 1) & ~(align - 1))
-        + sizeof(uint16_t) * 3 + sizeof(struct vring_used_elem) * num;
-}
-
-/* The following is used with USED_EVENT_IDX and AVAIL_EVENT_IDX */
-/* Assuming a given event_idx value from the other size, if
- * we have just incremented index from old to new_idx,
- * should we trigger an event? */
-static inline int vring_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old)
-{
-    /* Note: Xen has similar logic for notification hold-off
-     * in include/xen/interface/io/ring.h with req_event and req_prod
-     * corresponding to event_idx + 1 and new_idx respectively.
-     * Note also that req_event and req_prod in Xen start at 1,
-     * event indexes in virtio start at 0. */
-    return (uint16_t)(new_idx - event_idx - 1) < (uint16_t)(new_idx - old);
-}
-
-#endif /* _LINUX_VIRTIO_RING_H */
diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 4e3a061..2ea1ef1 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -35,7 +35,7 @@
 
 #include <stdio.h>
 
-#include "hw/virtio/virtio_ring.h"
+#include "standard-headers/linux/virtio_ring.h"
 #include "hw/virtio/vhost.h"
 #include "hw/virtio/virtio-bus.h"
 
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 34/96] virtio: use standard-headers
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (32 preceding siblings ...)
  2015-02-18 21:47 ` [Qemu-devel] [PULL 33/96] virtio: use standard virtio_ring.h Michael S. Tsirkin
@ 2015-02-18 21:47 ` Michael S. Tsirkin
  2015-02-18 21:47 ` [Qemu-devel] [PULL 35/96] virtio-balloon: use standard headers Michael S. Tsirkin
                   ` (64 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Thomas Huth, Juan Quintela, dgilbert,
	Aneesh Kumar K.V, Anthony Liguori

Drop a bunch of code duplicated from virtio_config.h and virtio_ring.h.
This makes us rename event index accessors which conflict,
as reusing the ones from virtio_ring.h isn't trivial.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com>
---
 hw/9pfs/virtio-9p.h        |  1 +
 include/hw/virtio/virtio.h | 48 ++--------------------------------------------
 hw/virtio/virtio.c         | 23 +++++-----------------
 3 files changed, 8 insertions(+), 64 deletions(-)

diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index 2c3603a..0776424 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -8,6 +8,7 @@
 #include <sys/resource.h>
 #include <glib.h>
 #include "hw/virtio/virtio.h"
+#include "hw/virtio/virtio-9p.h"
 #include "fsdev/file-op-9p.h"
 #include "fsdev/virtio-9p-marshal.h"
 #include "qemu/thread.h"
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index f24997d..d1b416b 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -19,56 +19,12 @@
 #include "hw/qdev.h"
 #include "sysemu/sysemu.h"
 #include "qemu/event_notifier.h"
-#ifdef CONFIG_VIRTFS
-#include "hw/virtio/virtio-9p.h"
-#endif
+#include "standard-headers/linux/virtio_config.h"
+#include "standard-headers/linux/virtio_ring.h"
 
-/* from Linux's linux/virtio_config.h */
-
-/* Status byte for guest to report progress, and synchronize features. */
-/* We have seen device and processed generic fields (VIRTIO_CONFIG_F_VIRTIO) */
-#define VIRTIO_CONFIG_S_ACKNOWLEDGE     1
-/* We have found a driver for the device. */
-#define VIRTIO_CONFIG_S_DRIVER          2
-/* Driver has used its parts of the config, and is happy */
-#define VIRTIO_CONFIG_S_DRIVER_OK       4
-/* We've given up on this device. */
-#define VIRTIO_CONFIG_S_FAILED          0x80
-
-/* Some virtio feature bits (currently bits 28 through 31) are reserved for the
- * transport being used (eg. virtio_ring), the rest are per-device feature bits. */
-#define VIRTIO_TRANSPORT_F_START        28
-#define VIRTIO_TRANSPORT_F_END          32
-
-/* We notify when the ring is completely used, even if the guest is suppressing
- * callbacks */
-#define VIRTIO_F_NOTIFY_ON_EMPTY        24
-/* Can the device handle any descriptor layout? */
-#define VIRTIO_F_ANY_LAYOUT             27
-/* We support indirect buffer descriptors */
-#define VIRTIO_RING_F_INDIRECT_DESC     28
-/* The Guest publishes the used index for which it expects an interrupt
- * at the end of the avail ring. Host should ignore the avail->flags field. */
-/* The Host publishes the avail index for which it expects a kick
- * at the end of the used ring. Guest should ignore the used->flags field. */
-#define VIRTIO_RING_F_EVENT_IDX         29
 /* A guest should never accept this.  It implies negotiation is broken. */
 #define VIRTIO_F_BAD_FEATURE		30
 
-/* from Linux's linux/virtio_ring.h */
-
-/* This marks a buffer as continuing via the next field. */
-#define VRING_DESC_F_NEXT       1
-/* This marks a buffer as write-only (otherwise read-only). */
-#define VRING_DESC_F_WRITE      2
-/* This means the buffer contains a list of buffer descriptors. */
-#define VRING_DESC_F_INDIRECT  4
-
-/* This means don't notify other side when buffer added. */
-#define VRING_USED_F_NO_NOTIFY  1
-/* This means don't interrupt guest when buffer consumed. */
-#define VRING_AVAIL_F_NO_INTERRUPT      1
-
 struct VirtQueue;
 
 static inline hwaddr vring_align(hwaddr addr,
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index d735343..f783f31 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -155,7 +155,7 @@ static inline uint16_t vring_avail_ring(VirtQueue *vq, int i)
     return virtio_lduw_phys(vq->vdev, pa);
 }
 
-static inline uint16_t vring_used_event(VirtQueue *vq)
+static inline uint16_t vring_get_used_event(VirtQueue *vq)
 {
     return vring_avail_ring(vq, vq->vring.num);
 }
@@ -204,7 +204,7 @@ static inline void vring_used_flags_unset_bit(VirtQueue *vq, int mask)
     virtio_stw_phys(vdev, pa, virtio_lduw_phys(vdev, pa) & ~mask);
 }
 
-static inline void vring_avail_event(VirtQueue *vq, uint16_t val)
+static inline void vring_set_avail_event(VirtQueue *vq, uint16_t val)
 {
     hwaddr pa;
     if (!vq->notification) {
@@ -218,7 +218,7 @@ void virtio_queue_set_notification(VirtQueue *vq, int enable)
 {
     vq->notification = enable;
     if (vq->vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX)) {
-        vring_avail_event(vq, vring_avail_idx(vq));
+        vring_set_avail_event(vq, vring_avail_idx(vq));
     } else if (enable) {
         vring_used_flags_unset_bit(vq, VRING_USED_F_NO_NOTIFY);
     } else {
@@ -469,7 +469,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem)
 
     i = head = virtqueue_get_head(vq, vq->last_avail_idx++);
     if (vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX)) {
-        vring_avail_event(vq, vq->last_avail_idx);
+        vring_set_avail_event(vq, vq->last_avail_idx);
     }
 
     if (vring_desc_flags(vdev, desc_pa, i) & VRING_DESC_F_INDIRECT) {
@@ -819,19 +819,6 @@ void virtio_irq(VirtQueue *vq)
     virtio_notify_vector(vq->vdev, vq->vector);
 }
 
-/* Assuming a given event_idx value from the other size, if
- * we have just incremented index from old to new_idx,
- * should we trigger an event? */
-static inline int vring_need_event(uint16_t event, uint16_t new, uint16_t old)
-{
-	/* Note: Xen has similar logic for notification hold-off
-	 * in include/xen/interface/io/ring.h with req_event and req_prod
-	 * corresponding to event_idx + 1 and new respectively.
-	 * Note also that req_event and req_prod in Xen start at 1,
-	 * event indexes in virtio start at 0. */
-	return (uint16_t)(new - event - 1) < (uint16_t)(new - old);
-}
-
 static bool vring_notify(VirtIODevice *vdev, VirtQueue *vq)
 {
     uint16_t old, new;
@@ -852,7 +839,7 @@ static bool vring_notify(VirtIODevice *vdev, VirtQueue *vq)
     vq->signalled_used_valid = true;
     old = vq->signalled_used;
     new = vq->signalled_used = vring_used_idx(vq);
-    return !v || vring_need_event(vring_used_event(vq), new, old);
+    return !v || vring_need_event(vring_get_used_event(vq), new, old);
 }
 
 void virtio_notify(VirtIODevice *vdev, VirtQueue *vq)
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 35/96] virtio-balloon: use standard headers
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (33 preceding siblings ...)
  2015-02-18 21:47 ` [Qemu-devel] [PULL 34/96] virtio: use standard-headers Michael S. Tsirkin
@ 2015-02-18 21:47 ` Michael S. Tsirkin
  2015-02-18 21:47 ` [Qemu-devel] [PULL 36/96] virtio-9p: " Michael S. Tsirkin
                   ` (63 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:47 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Thomas Huth, dgilbert, Juan Quintela

Drop code duplicated from standard headers.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com>
---
 include/hw/virtio/virtio-balloon.h | 35 ++---------------------------------
 1 file changed, 2 insertions(+), 33 deletions(-)

diff --git a/include/hw/virtio/virtio-balloon.h b/include/hw/virtio/virtio-balloon.h
index f863bfe..4ab8f54 100644
--- a/include/hw/virtio/virtio-balloon.h
+++ b/include/hw/virtio/virtio-balloon.h
@@ -15,6 +15,7 @@
 #ifndef _QEMU_VIRTIO_BALLOON_H
 #define _QEMU_VIRTIO_BALLOON_H
 
+#include "standard-headers/linux/virtio_balloon.h"
 #include "hw/virtio/virtio.h"
 #include "hw/pci/pci.h"
 
@@ -22,39 +23,7 @@
 #define VIRTIO_BALLOON(obj) \
         OBJECT_CHECK(VirtIOBalloon, (obj), TYPE_VIRTIO_BALLOON)
 
-/* from Linux's linux/virtio_balloon.h */
-
-/* The ID for virtio_balloon */
-#define VIRTIO_ID_BALLOON 5
-
-/* The feature bitmap for virtio balloon */
-#define VIRTIO_BALLOON_F_MUST_TELL_HOST 0 /* Tell before reclaiming pages */
-#define VIRTIO_BALLOON_F_STATS_VQ 1       /* Memory stats virtqueue */
-
-/* Size of a PFN in the balloon interface. */
-#define VIRTIO_BALLOON_PFN_SHIFT 12
-
-struct virtio_balloon_config
-{
-    /* Number of pages host wants Guest to give up. */
-    uint32_t num_pages;
-    /* Number of pages we've actually got in balloon. */
-    uint32_t actual;
-};
-
-/* Memory Statistics */
-#define VIRTIO_BALLOON_S_SWAP_IN  0   /* Amount of memory swapped in */
-#define VIRTIO_BALLOON_S_SWAP_OUT 1   /* Amount of memory swapped out */
-#define VIRTIO_BALLOON_S_MAJFLT   2   /* Number of major faults */
-#define VIRTIO_BALLOON_S_MINFLT   3   /* Number of minor faults */
-#define VIRTIO_BALLOON_S_MEMFREE  4   /* Total amount of free memory */
-#define VIRTIO_BALLOON_S_MEMTOT   5   /* Total amount of memory */
-#define VIRTIO_BALLOON_S_NR       6
-
-typedef struct VirtIOBalloonStat {
-    uint16_t tag;
-    uint64_t val;
-} QEMU_PACKED VirtIOBalloonStat;
+typedef struct virtio_balloon_stat VirtIOBalloonStat;
 
 typedef struct VirtIOBalloon {
     VirtIODevice parent_obj;
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 36/96] virtio-9p: use standard headers
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (34 preceding siblings ...)
  2015-02-18 21:47 ` [Qemu-devel] [PULL 35/96] virtio-balloon: use standard headers Michael S. Tsirkin
@ 2015-02-18 21:47 ` Michael S. Tsirkin
  2015-02-18 21:47 ` [Qemu-devel] [PULL 37/96] virtio-blk: switch to standard-headers Michael S. Tsirkin
                   ` (62 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Thomas Huth, Juan Quintela, dgilbert,
	Aneesh Kumar K.V, Anthony Liguori

Drop code duplicated from standard headers.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com>
---
 hw/9pfs/virtio-9p.h | 17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)

diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index 0776424..58dafa9 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -7,6 +7,7 @@
 #include <utime.h>
 #include <sys/resource.h>
 #include <glib.h>
+#include "standard-headers/linux/virtio_9p.h"
 #include "hw/virtio/virtio.h"
 #include "hw/virtio/virtio-9p.h"
 #include "fsdev/file-op-9p.h"
@@ -14,10 +15,6 @@
 #include "qemu/thread.h"
 #include "block/coroutine.h"
 
-/* The feature bitmap for virtio 9P */
-/* The mount point is specified in a config variable */
-#define VIRTIO_9P_MOUNT_TAG 0
-
 enum {
     P9_TLERROR = 6,
     P9_RLERROR,
@@ -145,10 +142,6 @@ struct V9fsPDU
  * 1) change user needs to set groups and stuff
  */
 
-/* from Linux's linux/virtio_9p.h */
-
-/* The ID for virtio console */
-#define VIRTIO_ID_9P    9
 #define MAX_REQ         128
 #define MAX_TAG_LEN     32
 
@@ -278,14 +271,6 @@ typedef struct V9fsWriteState {
     int cnt;
 } V9fsWriteState;
 
-struct virtio_9p_config
-{
-    /* number of characters in tag */
-    uint16_t tag_len;
-    /* Variable size tag name */
-    uint8_t tag[0];
-} QEMU_PACKED;
-
 typedef struct V9fsMkState {
     V9fsPDU *pdu;
     size_t offset;
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 37/96] virtio-blk: switch to standard-headers
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (35 preceding siblings ...)
  2015-02-18 21:47 ` [Qemu-devel] [PULL 36/96] virtio-9p: " Michael S. Tsirkin
@ 2015-02-18 21:47 ` Michael S. Tsirkin
  2015-02-18 21:47 ` [Qemu-devel] [PULL 38/96] virtio-net,tap: use standard-headers Michael S. Tsirkin
                   ` (61 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Peter Maydell, Thomas Huth, Juan Quintela,
	Stefan Hajnoczi, dgilbert, Anthony Liguori

Drop duplicated code. Minor codechanges were required
as geometry is a sub-structure now.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com>
---
 include/hw/virtio/virtio-blk.h | 77 +-----------------------------------------
 hw/block/virtio-blk.c          |  8 ++---
 2 files changed, 5 insertions(+), 80 deletions(-)

diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h
index fc7d311..b3ffcd9 100644
--- a/include/hw/virtio/virtio-blk.h
+++ b/include/hw/virtio/virtio-blk.h
@@ -14,6 +14,7 @@
 #ifndef _QEMU_VIRTIO_BLK_H
 #define _QEMU_VIRTIO_BLK_H
 
+#include "standard-headers/linux/virtio_blk.h"
 #include "hw/virtio/virtio.h"
 #include "hw/block/block.h"
 #include "sysemu/iothread.h"
@@ -23,88 +24,12 @@
 #define VIRTIO_BLK(obj) \
         OBJECT_CHECK(VirtIOBlock, (obj), TYPE_VIRTIO_BLK)
 
-/* from Linux's linux/virtio_blk.h */
-
-/* The ID for virtio_block */
-#define VIRTIO_ID_BLOCK 2
-
-/* Feature bits */
-#define VIRTIO_BLK_F_BARRIER    0       /* Does host support barriers? */
-#define VIRTIO_BLK_F_SIZE_MAX   1       /* Indicates maximum segment size */
-#define VIRTIO_BLK_F_SEG_MAX    2       /* Indicates maximum # of segments */
-#define VIRTIO_BLK_F_GEOMETRY   4       /* Indicates support of legacy geometry */
-#define VIRTIO_BLK_F_RO         5       /* Disk is read-only */
-#define VIRTIO_BLK_F_BLK_SIZE   6       /* Block size of disk is available*/
-#define VIRTIO_BLK_F_SCSI       7       /* Supports scsi command passthru */
-/* #define VIRTIO_BLK_F_IDENTIFY   8       ATA IDENTIFY supported, DEPRECATED */
-#define VIRTIO_BLK_F_WCE        9       /* write cache enabled */
-#define VIRTIO_BLK_F_TOPOLOGY   10      /* Topology information is available */
-#define VIRTIO_BLK_F_CONFIG_WCE 11      /* write cache configurable */
-
-#define VIRTIO_BLK_ID_BYTES     20      /* ID string length */
-
-struct virtio_blk_config
-{
-    uint64_t capacity;
-    uint32_t size_max;
-    uint32_t seg_max;
-    uint16_t cylinders;
-    uint8_t heads;
-    uint8_t sectors;
-    uint32_t blk_size;
-    uint8_t physical_block_exp;
-    uint8_t alignment_offset;
-    uint16_t min_io_size;
-    uint32_t opt_io_size;
-    uint8_t wce;
-} QEMU_PACKED;
-
-/* These two define direction. */
-#define VIRTIO_BLK_T_IN         0
-#define VIRTIO_BLK_T_OUT        1
-
-/* This bit says it's a scsi command, not an actual read or write. */
-#define VIRTIO_BLK_T_SCSI_CMD   2
-
-/* Flush the volatile write cache */
-#define VIRTIO_BLK_T_FLUSH      4
-
-/* return the device ID string */
-#define VIRTIO_BLK_T_GET_ID     8
-
-/* Barrier before this op. */
-#define VIRTIO_BLK_T_BARRIER    0x80000000
-
-/* This is the first element of the read scatter-gather list. */
-struct virtio_blk_outhdr
-{
-    /* VIRTIO_BLK_T* */
-    uint32_t type;
-    /* io priority. */
-    uint32_t ioprio;
-    /* Sector (ie. 512 byte offset) */
-    uint64_t sector;
-};
-
-#define VIRTIO_BLK_S_OK         0
-#define VIRTIO_BLK_S_IOERR      1
-#define VIRTIO_BLK_S_UNSUPP     2
-
 /* This is the last element of the write scatter-gather list */
 struct virtio_blk_inhdr
 {
     unsigned char status;
 };
 
-/* SCSI pass-through header */
-struct virtio_scsi_inhdr
-{
-    uint32_t errors;
-    uint32_t data_len;
-    uint32_t sense_len;
-    uint32_t residual;
-};
-
 struct VirtIOBlkConf
 {
     BlockConf conf;
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 1a8a176..6828f48 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -667,11 +667,11 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
     memset(&blkcfg, 0, sizeof(blkcfg));
     virtio_stq_p(vdev, &blkcfg.capacity, capacity);
     virtio_stl_p(vdev, &blkcfg.seg_max, 128 - 2);
-    virtio_stw_p(vdev, &blkcfg.cylinders, conf->cyls);
+    virtio_stw_p(vdev, &blkcfg.geometry.cylinders, conf->cyls);
     virtio_stl_p(vdev, &blkcfg.blk_size, blk_size);
     virtio_stw_p(vdev, &blkcfg.min_io_size, conf->min_io_size / blk_size);
     virtio_stw_p(vdev, &blkcfg.opt_io_size, conf->opt_io_size / blk_size);
-    blkcfg.heads = conf->heads;
+    blkcfg.geometry.heads = conf->heads;
     /*
      * We must ensure that the block device capacity is a multiple of
      * the logical block size. If that is not the case, let's use
@@ -684,9 +684,9 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
      * per track (cylinder).
      */
     if (blk_getlength(s->blk) /  conf->heads / conf->secs % blk_size) {
-        blkcfg.sectors = conf->secs & ~s->sector_mask;
+        blkcfg.geometry.sectors = conf->secs & ~s->sector_mask;
     } else {
-        blkcfg.sectors = conf->secs;
+        blkcfg.geometry.sectors = conf->secs;
     }
     blkcfg.size_max = 0;
     blkcfg.physical_block_exp = get_physical_block_exp(conf);
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 38/96] virtio-net,tap: use standard-headers
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (36 preceding siblings ...)
  2015-02-18 21:47 ` [Qemu-devel] [PULL 37/96] virtio-blk: switch to standard-headers Michael S. Tsirkin
@ 2015-02-18 21:47 ` Michael S. Tsirkin
  2015-02-18 21:48 ` [Qemu-devel] [PULL 39/96] virtio-rng: " Michael S. Tsirkin
                   ` (60 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Thomas Huth, Juan Quintela, Jason Wang, dgilbert,
	Vincenzo Maffione, Stefan Hajnoczi, Laszlo Ersek, Ming Lei

Drop duplicated code.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com>
---
 include/hw/virtio/virtio-net.h | 151 +----------------------------------------
 include/net/tap.h              |  24 +------
 2 files changed, 2 insertions(+), 173 deletions(-)

diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h
index 6ceb5aa..4c2fe83 100644
--- a/include/hw/virtio/virtio-net.h
+++ b/include/hw/virtio/virtio-net.h
@@ -14,49 +14,15 @@
 #ifndef _QEMU_VIRTIO_NET_H
 #define _QEMU_VIRTIO_NET_H
 
+#include "standard-headers/linux/virtio_net.h"
 #include "hw/virtio/virtio.h"
-#include "hw/pci/pci.h"
 
 #define TYPE_VIRTIO_NET "virtio-net-device"
 #define VIRTIO_NET(obj) \
         OBJECT_CHECK(VirtIONet, (obj), TYPE_VIRTIO_NET)
 
-#define ETH_ALEN    6
-
-/* from Linux's virtio_net.h */
-
-/* The ID for virtio_net */
-#define VIRTIO_ID_NET   1
-
-/* The feature bitmap for virtio net */
-#define VIRTIO_NET_F_CSUM       0       /* Host handles pkts w/ partial csum */
-#define VIRTIO_NET_F_GUEST_CSUM 1       /* Guest handles pkts w/ partial csum */
 #define VIRTIO_NET_F_CTRL_GUEST_OFFLOADS 2 /* Control channel offload
                                          * configuration support */
-#define VIRTIO_NET_F_MAC        5       /* Host has given MAC address. */
-#define VIRTIO_NET_F_GSO        6       /* Host handles pkts w/ any GSO type */
-#define VIRTIO_NET_F_GUEST_TSO4 7       /* Guest can handle TSOv4 in. */
-#define VIRTIO_NET_F_GUEST_TSO6 8       /* Guest can handle TSOv6 in. */
-#define VIRTIO_NET_F_GUEST_ECN  9       /* Guest can handle TSO[6] w/ ECN in. */
-#define VIRTIO_NET_F_GUEST_UFO  10      /* Guest can handle UFO in. */
-#define VIRTIO_NET_F_HOST_TSO4  11      /* Host can handle TSOv4 in. */
-#define VIRTIO_NET_F_HOST_TSO6  12      /* Host can handle TSOv6 in. */
-#define VIRTIO_NET_F_HOST_ECN   13      /* Host can handle TSO[6] w/ ECN in. */
-#define VIRTIO_NET_F_HOST_UFO   14      /* Host can handle UFO in. */
-#define VIRTIO_NET_F_MRG_RXBUF  15      /* Host can merge receive buffers. */
-#define VIRTIO_NET_F_STATUS     16      /* virtio_net_config.status available */
-#define VIRTIO_NET_F_CTRL_VQ    17      /* Control channel available */
-#define VIRTIO_NET_F_CTRL_RX    18      /* Control channel RX mode support */
-#define VIRTIO_NET_F_CTRL_VLAN  19      /* Control channel VLAN filtering */
-#define VIRTIO_NET_F_CTRL_RX_EXTRA 20   /* Extra RX mode control support */
-#define VIRTIO_NET_F_GUEST_ANNOUNCE 21  /* Guest can announce itself */
-#define VIRTIO_NET_F_MQ         22      /* Device supports Receive Flow
-                                         * Steering */
-
-#define VIRTIO_NET_F_CTRL_MAC_ADDR   23 /* Set MAC address */
-
-#define VIRTIO_NET_S_LINK_UP    1       /* Link is up */
-#define VIRTIO_NET_S_ANNOUNCE   2       /* Announcement is needed */
 
 #define TX_TIMER_INTERVAL 150000 /* 150 us */
 
@@ -77,72 +43,6 @@ typedef struct virtio_net_conf
 /* Maximum packet size we can receive from tap device: header + 64k */
 #define VIRTIO_NET_MAX_BUFSIZE (sizeof(struct virtio_net_hdr) + (64 << 10))
 
-struct virtio_net_config
-{
-    /* The config defining mac address ($ETH_ALEN bytes) */
-    uint8_t mac[ETH_ALEN];
-    /* See VIRTIO_NET_F_STATUS and VIRTIO_NET_S_* above */
-    uint16_t status;
-    /* Max virtqueue pairs supported by the device */
-    uint16_t max_virtqueue_pairs;
-} QEMU_PACKED;
-
-/*
- * Control virtqueue data structures
- *
- * The control virtqueue expects a header in the first sg entry
- * and an ack/status response in the last entry.  Data for the
- * command goes in between.
- */
-struct virtio_net_ctrl_hdr {
-    uint8_t class;
-    uint8_t cmd;
-};
-
-typedef uint8_t virtio_net_ctrl_ack;
-
-#define VIRTIO_NET_OK     0
-#define VIRTIO_NET_ERR    1
-
-/*
- * Control the RX mode, ie. promisucous, allmulti, etc...
- * All commands require an "out" sg entry containing a 1 byte
- * state value, zero = disable, non-zero = enable.  Commands
- * 0 and 1 are supported with the VIRTIO_NET_F_CTRL_RX feature.
- * Commands 2-5 are added with VIRTIO_NET_F_CTRL_RX_EXTRA.
- */
-#define VIRTIO_NET_CTRL_RX    0
- #define VIRTIO_NET_CTRL_RX_PROMISC      0
- #define VIRTIO_NET_CTRL_RX_ALLMULTI     1
- #define VIRTIO_NET_CTRL_RX_ALLUNI       2
- #define VIRTIO_NET_CTRL_RX_NOMULTI      3
- #define VIRTIO_NET_CTRL_RX_NOUNI        4
- #define VIRTIO_NET_CTRL_RX_NOBCAST      5
-
-/*
- * Control the MAC
- *
- * The MAC filter table is managed by the hypervisor, the guest should
- * assume the size is infinite.  Filtering should be considered
- * non-perfect, ie. based on hypervisor resources, the guest may
- * received packets from sources not specified in the filter list.
- *
- * In addition to the class/cmd header, the TABLE_SET command requires
- * two out scatterlists.  Each contains a 4 byte count of entries followed
- * by a concatenated byte stream of the ETH_ALEN MAC addresses.  The
- * first sg list contains unicast addresses, the second is for multicast.
- * This functionality is present if the VIRTIO_NET_F_CTRL_RX feature
- * is available.
- *
- * The ADDR_SET command requests one out scatterlist, it contains a
- * 6 bytes MAC address. This functionality is present if the
- * VIRTIO_NET_F_CTRL_MAC_ADDR feature is available.
- */
-struct virtio_net_ctrl_mac {
-    uint32_t entries;
-    uint8_t macs[][ETH_ALEN];
-};
-
 typedef struct VirtIONetQueue {
     VirtQueue *rx_vq;
     VirtQueue *tx_vq;
@@ -199,55 +99,6 @@ typedef struct VirtIONet {
     int announce_counter;
 } VirtIONet;
 
-#define VIRTIO_NET_CTRL_MAC    1
- #define VIRTIO_NET_CTRL_MAC_TABLE_SET        0
- #define VIRTIO_NET_CTRL_MAC_ADDR_SET         1
-
-/*
- * Control VLAN filtering
- *
- * The VLAN filter table is controlled via a simple ADD/DEL interface.
- * VLAN IDs not added may be filterd by the hypervisor.  Del is the
- * opposite of add.  Both commands expect an out entry containing a 2
- * byte VLAN ID.  VLAN filterting is available with the
- * VIRTIO_NET_F_CTRL_VLAN feature bit.
- */
-#define VIRTIO_NET_CTRL_VLAN       2
- #define VIRTIO_NET_CTRL_VLAN_ADD             0
- #define VIRTIO_NET_CTRL_VLAN_DEL             1
-
-/*
- * Control link announce acknowledgement
- *
- * VIRTIO_NET_S_ANNOUNCE bit in the status field requests link announcement from
- * guest driver. The driver is notified by config space change interrupt.  The
- * command VIRTIO_NET_CTRL_ANNOUNCE_ACK is used to indicate that the driver has
- * received the notification. It makes the device clear the bit
- * VIRTIO_NET_S_ANNOUNCE in the status field.
- */
-#define VIRTIO_NET_CTRL_ANNOUNCE       3
- #define VIRTIO_NET_CTRL_ANNOUNCE_ACK         0
-
-/*
- * Control Multiqueue
- *
- * The command VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET
- * enables multiqueue, specifying the number of the transmit and
- * receive queues that will be used. After the command is consumed and acked by
- * the device, the device will not steer new packets on receive virtqueues
- * other than specified nor read from transmit virtqueues other than specified.
- * Accordingly, driver should not transmit new packets  on virtqueues other than
- * specified.
- */
-struct virtio_net_ctrl_mq {
-    uint16_t virtqueue_pairs;
-};
-
-#define VIRTIO_NET_CTRL_MQ   4
- #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET        0
- #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN        1
- #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX        0x8000
-
 /*
  * Control network offloads
  *
diff --git a/include/net/tap.h b/include/net/tap.h
index 6daeb42..5da4edc 100644
--- a/include/net/tap.h
+++ b/include/net/tap.h
@@ -28,6 +28,7 @@
 
 #include "qemu-common.h"
 #include "qapi-types.h"
+#include "standard-headers/linux/virtio_net.h"
 
 int tap_enable(NetClientState *nc);
 int tap_disable(NetClientState *nc);
@@ -37,27 +38,4 @@ int tap_get_fd(NetClientState *nc);
 struct vhost_net;
 struct vhost_net *tap_get_vhost_net(NetClientState *nc);
 
-struct virtio_net_hdr
-{
-#define VIRTIO_NET_HDR_F_NEEDS_CSUM     1       // Use csum_start, csum_offset
-#define VIRTIO_NET_HDR_F_DATA_VALID    2       // Csum is valid
-    uint8_t flags;
-#define VIRTIO_NET_HDR_GSO_NONE         0       // Not a GSO frame
-#define VIRTIO_NET_HDR_GSO_TCPV4        1       // GSO frame, IPv4 TCP (TSO)
-#define VIRTIO_NET_HDR_GSO_UDP          3       // GSO frame, IPv4 UDP (UFO)
-#define VIRTIO_NET_HDR_GSO_TCPV6        4       // GSO frame, IPv6 TCP
-#define VIRTIO_NET_HDR_GSO_ECN          0x80    // TCP has ECN set
-    uint8_t gso_type;
-    uint16_t hdr_len;
-    uint16_t gso_size;
-    uint16_t csum_start;
-    uint16_t csum_offset;
-};
-
-struct virtio_net_hdr_mrg_rxbuf
-{
-    struct virtio_net_hdr hdr;
-    uint16_t num_buffers;   /* Number of merged rx buffers */
-};
-
 #endif /* QEMU_NET_TAP_H */
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 39/96] virtio-rng: use standard-headers
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (37 preceding siblings ...)
  2015-02-18 21:47 ` [Qemu-devel] [PULL 38/96] virtio-net,tap: use standard-headers Michael S. Tsirkin
@ 2015-02-18 21:48 ` Michael S. Tsirkin
  2015-02-18 21:48 ` [Qemu-devel] [PULL 40/96] virtio-scsi: " Michael S. Tsirkin
                   ` (59 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Amit Shah, Peter Maydell, Thomas Huth, dgilbert, Juan Quintela

Drop duplicated code.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com>
---
 include/hw/virtio/virtio-rng.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/include/hw/virtio/virtio-rng.h b/include/hw/virtio/virtio-rng.h
index 14e85a5..7702ff4 100644
--- a/include/hw/virtio/virtio-rng.h
+++ b/include/hw/virtio/virtio-rng.h
@@ -14,6 +14,7 @@
 
 #include "sysemu/rng.h"
 #include "sysemu/rng-random.h"
+#include "standard-headers/linux/virtio_rng.h"
 
 #define TYPE_VIRTIO_RNG "virtio-rng-device"
 #define VIRTIO_RNG(obj) \
@@ -21,9 +22,6 @@
 #define VIRTIO_RNG_GET_PARENT_CLASS(obj) \
         OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_RNG)
 
-/* The Virtio ID for the virtio rng device */
-#define VIRTIO_ID_RNG    4
-
 struct VirtIORNGConf {
     RngBackend *rng;
     uint64_t max_bytes;
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 40/96] virtio-scsi: use standard-headers
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (38 preceding siblings ...)
  2015-02-18 21:48 ` [Qemu-devel] [PULL 39/96] virtio-rng: " Michael S. Tsirkin
@ 2015-02-18 21:48 ` Michael S. Tsirkin
  2015-03-11  7:14   ` Fam Zheng
  2015-02-18 21:48 ` [Qemu-devel] [PULL 41/96] virtio-serial: switch to standard-headers Michael S. Tsirkin
                   ` (58 subsequent siblings)
  98 siblings, 1 reply; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Paolo Bonzini, dgilbert, Anthony Liguori, Juan Quintela

Drop duplicated code.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
---
 include/hw/virtio/virtio-scsi.h | 120 +++-------------------------------------
 hw/scsi/virtio-scsi.c           |   1 +
 2 files changed, 10 insertions(+), 111 deletions(-)

diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h
index bf17cc9..864070d 100644
--- a/include/hw/virtio/virtio-scsi.h
+++ b/include/hw/virtio/virtio-scsi.h
@@ -14,6 +14,7 @@
 #ifndef _QEMU_VIRTIO_SCSI_H
 #define _QEMU_VIRTIO_SCSI_H
 
+#include "standard-headers/linux/virtio_scsi.h"
 #include "hw/virtio/virtio.h"
 #include "hw/pci/pci.h"
 #include "hw/scsi/scsi.h"
@@ -28,15 +29,6 @@
 #define VIRTIO_SCSI(obj) \
         OBJECT_CHECK(VirtIOSCSI, (obj), TYPE_VIRTIO_SCSI)
 
-
-/* The ID for virtio_scsi */
-#define VIRTIO_ID_SCSI  8
-
-/* Feature Bits */
-#define VIRTIO_SCSI_F_INOUT                    0
-#define VIRTIO_SCSI_F_HOTPLUG                  1
-#define VIRTIO_SCSI_F_CHANGE                   2
-
 #define VIRTIO_SCSI_VQ_SIZE     128
 #define VIRTIO_SCSI_CDB_SIZE    32
 #define VIRTIO_SCSI_SENSE_SIZE  96
@@ -44,108 +36,14 @@
 #define VIRTIO_SCSI_MAX_TARGET  255
 #define VIRTIO_SCSI_MAX_LUN     16383
 
-/* Response codes */
-#define VIRTIO_SCSI_S_OK                       0
-#define VIRTIO_SCSI_S_OVERRUN                  1
-#define VIRTIO_SCSI_S_ABORTED                  2
-#define VIRTIO_SCSI_S_BAD_TARGET               3
-#define VIRTIO_SCSI_S_RESET                    4
-#define VIRTIO_SCSI_S_BUSY                     5
-#define VIRTIO_SCSI_S_TRANSPORT_FAILURE        6
-#define VIRTIO_SCSI_S_TARGET_FAILURE           7
-#define VIRTIO_SCSI_S_NEXUS_FAILURE            8
-#define VIRTIO_SCSI_S_FAILURE                  9
-#define VIRTIO_SCSI_S_FUNCTION_SUCCEEDED       10
-#define VIRTIO_SCSI_S_FUNCTION_REJECTED        11
-#define VIRTIO_SCSI_S_INCORRECT_LUN            12
-
-/* Controlq type codes.  */
-#define VIRTIO_SCSI_T_TMF                      0
-#define VIRTIO_SCSI_T_AN_QUERY                 1
-#define VIRTIO_SCSI_T_AN_SUBSCRIBE             2
-
-/* Valid TMF subtypes.  */
-#define VIRTIO_SCSI_T_TMF_ABORT_TASK           0
-#define VIRTIO_SCSI_T_TMF_ABORT_TASK_SET       1
-#define VIRTIO_SCSI_T_TMF_CLEAR_ACA            2
-#define VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET       3
-#define VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET      4
-#define VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET   5
-#define VIRTIO_SCSI_T_TMF_QUERY_TASK           6
-#define VIRTIO_SCSI_T_TMF_QUERY_TASK_SET       7
-
-/* Events.  */
-#define VIRTIO_SCSI_T_EVENTS_MISSED            0x80000000
-#define VIRTIO_SCSI_T_NO_EVENT                 0
-#define VIRTIO_SCSI_T_TRANSPORT_RESET          1
-#define VIRTIO_SCSI_T_ASYNC_NOTIFY             2
-#define VIRTIO_SCSI_T_PARAM_CHANGE             3
-
-/* Reasons for transport reset event */
-#define VIRTIO_SCSI_EVT_RESET_HARD             0
-#define VIRTIO_SCSI_EVT_RESET_RESCAN           1
-#define VIRTIO_SCSI_EVT_RESET_REMOVED          2
-
-/* SCSI command request, followed by CDB and data-out */
-typedef struct {
-    uint8_t lun[8];              /* Logical Unit Number */
-    uint64_t tag;                /* Command identifier */
-    uint8_t task_attr;           /* Task attribute */
-    uint8_t prio;
-    uint8_t crn;
-} QEMU_PACKED VirtIOSCSICmdReq;
-
-/* Response, followed by sense data and data-in */
-typedef struct {
-    uint32_t sense_len;          /* Sense data length */
-    uint32_t resid;              /* Residual bytes in data buffer */
-    uint16_t status_qualifier;   /* Status qualifier */
-    uint8_t status;              /* Command completion status */
-    uint8_t response;            /* Response values */
-} QEMU_PACKED VirtIOSCSICmdResp;
-
-/* Task Management Request */
-typedef struct {
-    uint32_t type;
-    uint32_t subtype;
-    uint8_t lun[8];
-    uint64_t tag;
-} QEMU_PACKED VirtIOSCSICtrlTMFReq;
-
-typedef struct {
-    uint8_t response;
-} QEMU_PACKED VirtIOSCSICtrlTMFResp;
-
-/* Asynchronous notification query/subscription */
-typedef struct {
-    uint32_t type;
-    uint8_t lun[8];
-    uint32_t event_requested;
-} QEMU_PACKED VirtIOSCSICtrlANReq;
-
-typedef struct {
-    uint32_t event_actual;
-    uint8_t response;
-} QEMU_PACKED VirtIOSCSICtrlANResp;
-
-typedef struct {
-    uint32_t event;
-    uint8_t lun[8];
-    uint32_t reason;
-} QEMU_PACKED VirtIOSCSIEvent;
-
-typedef struct {
-    uint32_t num_queues;
-    uint32_t seg_max;
-    uint32_t max_sectors;
-    uint32_t cmd_per_lun;
-    uint32_t event_info_size;
-    uint32_t sense_size;
-    uint32_t cdb_size;
-    uint16_t max_channel;
-    uint16_t max_target;
-    uint32_t max_lun;
-} QEMU_PACKED VirtIOSCSIConfig;
+typedef struct virtio_scsi_cmd_req VirtIOSCSICmdReq;
+typedef struct virtio_scsi_cmd_resp VirtIOSCSICmdResp;
+typedef struct virtio_scsi_ctrl_tmf_req VirtIOSCSICtrlTMFReq;
+typedef struct virtio_scsi_ctrl_tmf_resp VirtIOSCSICtrlTMFResp;
+typedef struct virtio_scsi_ctrl_an_req VirtIOSCSICtrlANReq;
+typedef struct virtio_scsi_ctrl_an_resp VirtIOSCSICtrlANResp;
+typedef struct virtio_scsi_event VirtIOSCSIEvent;
+typedef struct virtio_scsi_config VirtIOSCSIConfig;
 
 struct VirtIOSCSIConf {
     uint32_t num_queues;
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index 9e2c718..d18654e 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -13,6 +13,7 @@
  *
  */
 
+#include "standard-headers/linux/virtio_ids.h"
 #include "hw/virtio/virtio-scsi.h"
 #include "qemu/error-report.h"
 #include "qemu/iov.h"
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 41/96] virtio-serial: switch to standard-headers
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (39 preceding siblings ...)
  2015-02-18 21:48 ` [Qemu-devel] [PULL 40/96] virtio-scsi: " Michael S. Tsirkin
@ 2015-02-18 21:48 ` Michael S. Tsirkin
  2015-02-18 21:48 ` [Qemu-devel] [PULL 42/96] update-linux-headers: use standard-headers Michael S. Tsirkin
                   ` (57 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: Amit Shah, Peter Maydell, dgilbert, Anthony Liguori, Juan Quintela

Drop duplicate code.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/virtio/virtio-serial.h | 40 +--------------------------------------
 hw/char/virtio-serial-bus.c       |  1 +
 2 files changed, 2 insertions(+), 39 deletions(-)

diff --git a/include/hw/virtio/virtio-serial.h b/include/hw/virtio/virtio-serial.h
index 11af978..ccf8459 100644
--- a/include/hw/virtio/virtio-serial.h
+++ b/include/hw/virtio/virtio-serial.h
@@ -15,53 +15,15 @@
 #ifndef _QEMU_VIRTIO_SERIAL_H
 #define _QEMU_VIRTIO_SERIAL_H
 
+#include "standard-headers/linux/virtio_console.h"
 #include "hw/qdev.h"
 #include "hw/virtio/virtio.h"
 
-/* == Interface shared between the guest kernel and qemu == */
-
-/* The Virtio ID for virtio console / serial ports */
-#define VIRTIO_ID_CONSOLE		3
-
-/* Features supported */
-#define VIRTIO_CONSOLE_F_MULTIPORT	1
-
-#define VIRTIO_CONSOLE_BAD_ID           (~(uint32_t)0)
-
-struct virtio_console_config {
-    /*
-     * These two fields are used by VIRTIO_CONSOLE_F_SIZE which
-     * isn't implemented here yet
-     */
-    uint16_t cols;
-    uint16_t rows;
-
-    uint32_t max_nr_ports;
-} QEMU_PACKED;
-
-struct virtio_console_control {
-    uint32_t id;		/* Port number */
-    uint16_t event;		/* The kind of control event (see below) */
-    uint16_t value;		/* Extra information for the key */
-};
-
 struct virtio_serial_conf {
     /* Max. number of ports we can have for a virtio-serial device */
     uint32_t max_virtserial_ports;
 };
 
-/* Some events for the internal messages (control packets) */
-#define VIRTIO_CONSOLE_DEVICE_READY	0
-#define VIRTIO_CONSOLE_PORT_ADD		1
-#define VIRTIO_CONSOLE_PORT_REMOVE	2
-#define VIRTIO_CONSOLE_PORT_READY	3
-#define VIRTIO_CONSOLE_CONSOLE_PORT	4
-#define VIRTIO_CONSOLE_RESIZE		5
-#define VIRTIO_CONSOLE_PORT_OPEN	6
-#define VIRTIO_CONSOLE_PORT_NAME	7
-
-/* == In-qemu interface == */
-
 #define TYPE_VIRTIO_SERIAL_PORT "virtio-serial-port"
 #define VIRTIO_SERIAL_PORT(obj) \
      OBJECT_CHECK(VirtIOSerialPort, (obj), TYPE_VIRTIO_SERIAL_PORT)
diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index 47fbb34..a2bac9b 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -18,6 +18,7 @@
  * GNU GPL, version 2 or (at your option) any later version.
  */
 
+#include "standard-headers/linux/virtio_ids.h"
 #include "qemu/iov.h"
 #include "monitor/monitor.h"
 #include "qemu/queue.h"
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 42/96] update-linux-headers: use standard-headers
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (40 preceding siblings ...)
  2015-02-18 21:48 ` [Qemu-devel] [PULL 41/96] virtio-serial: switch to standard-headers Michael S. Tsirkin
@ 2015-02-18 21:48 ` Michael S. Tsirkin
  2015-02-18 21:48 ` [Qemu-devel] [PULL 43/96] linux-headers: " Michael S. Tsirkin
                   ` (56 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Alexander Graf, Thomas Huth, dgilbert, Juan Quintela

Drop the linux-specific virtio headers, use the copy from
standard-headers instead.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 scripts/update-linux-headers.sh | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers.sh
index 8926dec..5ab3914 100755
--- a/scripts/update-linux-headers.sh
+++ b/scripts/update-linux-headers.sh
@@ -91,7 +91,7 @@ done
 
 rm -rf "$output/linux-headers/linux"
 mkdir -p "$output/linux-headers/linux"
-for header in kvm.h kvm_para.h vfio.h vhost.h virtio_config.h virtio_ring.h \
+for header in kvm.h kvm_para.h vfio.h vhost.h \
               psci.h; do
     cp "$tmpdir/include/linux/$header" "$output/linux-headers/linux"
 done
@@ -106,6 +106,12 @@ else
     cp "$linux/COPYING" "$output/linux-headers"
 fi
 
+cat <<EOF >$output/linux-headers/linux/virtio_config.h
+#include "standard-headers/linux/virtio_config.h"
+EOF
+cat <<EOF >$output/linux-headers/linux/virtio_ring.h
+#include "standard-headers/linux/virtio_ring.h"
+EOF
 
 cp_virtio "$tmpdir/include/linux/" "$output/include/standard-headers/linux"
 
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 43/96] linux-headers: use standard-headers
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (41 preceding siblings ...)
  2015-02-18 21:48 ` [Qemu-devel] [PULL 42/96] update-linux-headers: use standard-headers Michael S. Tsirkin
@ 2015-02-18 21:48 ` Michael S. Tsirkin
  2015-02-18 21:48 ` [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (55 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, dgilbert, Juan Quintela

Drop duplicated code.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 linux-headers/linux/virtio_config.h |  58 +------------
 linux-headers/linux/virtio_ring.h   | 164 +-----------------------------------
 2 files changed, 2 insertions(+), 220 deletions(-)

diff --git a/linux-headers/linux/virtio_config.h b/linux-headers/linux/virtio_config.h
index 75dc20b..5590f7d 100644
--- a/linux-headers/linux/virtio_config.h
+++ b/linux-headers/linux/virtio_config.h
@@ -1,57 +1 @@
-#ifndef _LINUX_VIRTIO_CONFIG_H
-#define _LINUX_VIRTIO_CONFIG_H
-/* This header, excluding the #ifdef __KERNEL__ part, is BSD licensed so
- * anyone can use the definitions to implement compatible drivers/servers.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of IBM nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE. */
-
-/* Virtio devices use a standardized configuration space to define their
- * features and pass configuration information, but each implementation can
- * store and access that space differently. */
-#include <linux/types.h>
-
-/* Status byte for guest to report progress, and synchronize features. */
-/* We have seen device and processed generic fields (VIRTIO_CONFIG_F_VIRTIO) */
-#define VIRTIO_CONFIG_S_ACKNOWLEDGE	1
-/* We have found a driver for the device. */
-#define VIRTIO_CONFIG_S_DRIVER		2
-/* Driver has used its parts of the config, and is happy */
-#define VIRTIO_CONFIG_S_DRIVER_OK	4
-/* We've given up on this device. */
-#define VIRTIO_CONFIG_S_FAILED		0x80
-
-/* Some virtio feature bits (currently bits 28 through 31) are reserved for the
- * transport being used (eg. virtio_ring), the rest are per-device feature
- * bits. */
-#define VIRTIO_TRANSPORT_F_START	28
-#define VIRTIO_TRANSPORT_F_END		32
-
-/* Do we get callbacks when the ring is completely used, even if we've
- * suppressed them? */
-#define VIRTIO_F_NOTIFY_ON_EMPTY	24
-
-/* Can the device handle any descriptor layout? */
-#define VIRTIO_F_ANY_LAYOUT		27
-
-#endif /* _LINUX_VIRTIO_CONFIG_H */
+#include "standard-headers/linux/virtio_config.h"
diff --git a/linux-headers/linux/virtio_ring.h b/linux-headers/linux/virtio_ring.h
index 1b333e2..c6f0fb6 100644
--- a/linux-headers/linux/virtio_ring.h
+++ b/linux-headers/linux/virtio_ring.h
@@ -1,163 +1 @@
-#ifndef _LINUX_VIRTIO_RING_H
-#define _LINUX_VIRTIO_RING_H
-/* An interface for efficient virtio implementation, currently for use by KVM
- * and lguest, but hopefully others soon.  Do NOT change this since it will
- * break existing servers and clients.
- *
- * This header is BSD licensed so anyone can use the definitions to implement
- * compatible drivers/servers.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of IBM nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * Copyright Rusty Russell IBM Corporation 2007. */
-#include <linux/types.h>
-
-/* This marks a buffer as continuing via the next field. */
-#define VRING_DESC_F_NEXT	1
-/* This marks a buffer as write-only (otherwise read-only). */
-#define VRING_DESC_F_WRITE	2
-/* This means the buffer contains a list of buffer descriptors. */
-#define VRING_DESC_F_INDIRECT	4
-
-/* The Host uses this in used->flags to advise the Guest: don't kick me when
- * you add a buffer.  It's unreliable, so it's simply an optimization.  Guest
- * will still kick if it's out of buffers. */
-#define VRING_USED_F_NO_NOTIFY	1
-/* The Guest uses this in avail->flags to advise the Host: don't interrupt me
- * when you consume a buffer.  It's unreliable, so it's simply an
- * optimization.  */
-#define VRING_AVAIL_F_NO_INTERRUPT	1
-
-/* We support indirect buffer descriptors */
-#define VIRTIO_RING_F_INDIRECT_DESC	28
-
-/* The Guest publishes the used index for which it expects an interrupt
- * at the end of the avail ring. Host should ignore the avail->flags field. */
-/* The Host publishes the avail index for which it expects a kick
- * at the end of the used ring. Guest should ignore the used->flags field. */
-#define VIRTIO_RING_F_EVENT_IDX		29
-
-/* Virtio ring descriptors: 16 bytes.  These can chain together via "next". */
-struct vring_desc {
-	/* Address (guest-physical). */
-	__u64 addr;
-	/* Length. */
-	__u32 len;
-	/* The flags as indicated above. */
-	__u16 flags;
-	/* We chain unused descriptors via this, too */
-	__u16 next;
-};
-
-struct vring_avail {
-	__u16 flags;
-	__u16 idx;
-	__u16 ring[];
-};
-
-/* u32 is used here for ids for padding reasons. */
-struct vring_used_elem {
-	/* Index of start of used descriptor chain. */
-	__u32 id;
-	/* Total length of the descriptor chain which was used (written to) */
-	__u32 len;
-};
-
-struct vring_used {
-	__u16 flags;
-	__u16 idx;
-	struct vring_used_elem ring[];
-};
-
-struct vring {
-	unsigned int num;
-
-	struct vring_desc *desc;
-
-	struct vring_avail *avail;
-
-	struct vring_used *used;
-};
-
-/* The standard layout for the ring is a continuous chunk of memory which looks
- * like this.  We assume num is a power of 2.
- *
- * struct vring
- * {
- *	// The actual descriptors (16 bytes each)
- *	struct vring_desc desc[num];
- *
- *	// A ring of available descriptor heads with free-running index.
- *	__u16 avail_flags;
- *	__u16 avail_idx;
- *	__u16 available[num];
- *	__u16 used_event_idx;
- *
- *	// Padding to the next align boundary.
- *	char pad[];
- *
- *	// A ring of used descriptor heads with free-running index.
- *	__u16 used_flags;
- *	__u16 used_idx;
- *	struct vring_used_elem used[num];
- *	__u16 avail_event_idx;
- * };
- */
-/* We publish the used event index at the end of the available ring, and vice
- * versa. They are at the end for backwards compatibility. */
-#define vring_used_event(vr) ((vr)->avail->ring[(vr)->num])
-#define vring_avail_event(vr) (*(__u16 *)&(vr)->used->ring[(vr)->num])
-
-static __inline__ void vring_init(struct vring *vr, unsigned int num, void *p,
-			      unsigned long align)
-{
-	vr->num = num;
-	vr->desc = p;
-	vr->avail = p + num*sizeof(struct vring_desc);
-	vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + sizeof(__u16)
-		+ align-1) & ~(align - 1));
-}
-
-static __inline__ unsigned vring_size(unsigned int num, unsigned long align)
-{
-	return ((sizeof(struct vring_desc) * num + sizeof(__u16) * (3 + num)
-		 + align - 1) & ~(align - 1))
-		+ sizeof(__u16) * 3 + sizeof(struct vring_used_elem) * num;
-}
-
-/* The following is used with USED_EVENT_IDX and AVAIL_EVENT_IDX */
-/* Assuming a given event_idx value from the other size, if
- * we have just incremented index from old to new_idx,
- * should we trigger an event? */
-static __inline__ int vring_need_event(__u16 event_idx, __u16 new_idx, __u16 old)
-{
-	/* Note: Xen has similar logic for notification hold-off
-	 * in include/xen/interface/io/ring.h with req_event and req_prod
-	 * corresponding to event_idx + 1 and new_idx respectively.
-	 * Note also that req_event and req_prod in Xen start at 1,
-	 * event indexes in virtio start at 0. */
-	return (__u16)(new_idx - event_idx - 1) < (__u16)(new_idx - old);
-}
-
-#endif /* _LINUX_VIRTIO_RING_H */
+#include "standard-headers/linux/virtio_ring.h"
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* Re: [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (42 preceding siblings ...)
  2015-02-18 21:48 ` [Qemu-devel] [PULL 43/96] linux-headers: " Michael S. Tsirkin
@ 2015-02-18 21:48 ` Michael S. Tsirkin
  2015-02-18 22:03   ` Michael S. Tsirkin
  2015-02-18 21:48 ` [Qemu-devel] [PULL 44/96] virtio-pci: use standard headers Michael S. Tsirkin
                   ` (54 subsequent siblings)
  98 siblings, 1 reply; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, dgilbert, Juan Quintela

On Wed, Feb 18, 2015 at 10:43:58PM +0100, Michael S. Tsirkin wrote:
> A huge patchset, but the scariest part is Igor's patches,
> and these have been used by multiple people by now.
> virtio header change is a bit rushed, but getting them upstream
> seems like the best way to give them the cross-platform
> testing that they need, and this takes us a step closer to
> virtio-1.0 support.

Ugh.
Missed aarch64 failures this triggers :(
Pls ignore for now, sorry about the noise.

> The following changes since commit cd2d5541271f1934345d8ca42f5fafff1744eee7:
> 
>   Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20150212' into staging (2015-02-13 11:44:50 +0000)
> 
> are available in the git repository at:
> 
>   git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream
> 
> for you to fetch changes up to 6b5e5a8361bdff0e75629b1001236d78f27676b6:
> 
>   acpi-test: update expected files (2015-02-18 22:29:26 +0100)
> 
> ----------------------------------------------------------------
> pci, pc, virtio fixes and cleanups
> 
> Last large pull for soft freeze.
> 
> A bunch of fixes all over the place.
> Most of ACPI refactoring has been merged.
> 
> virtio header cleanup has been merged,
> now that windows has been build-tested with it.
> 
> initial patches from virtio-1.0 branch have been merged.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> 
> ----------------------------------------------------------------
> Cornelia Huck (3):
>       virtio: cull virtio_bus_set_vdev_features
>       virtio: feature bit manipulation helpers
>       virtio: add feature checking helpers
> 
> Igor Mammedov (43):
>       acpi: move generic aml building helpers into dedictated file
>       acpi: add build_append_namestring() helper
>       acpi: drop min-bytes in build_package()
>       pc: acpi-build: update linker on guest access
>       pc: acpi-build: migrate RSDP table
>       pc: acpi: use local var for accessing ACPI tables blob in acpi_build()
>       acpi: introduce AML composer aml_append()
>       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: 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
>       acpi: add aml_package() term
>       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: acpi-build: drop template patching and memory hotplug objects dynamically
>       pc: acpi-build: create memory hotplug IO region dynamically
>       acpi: add aml_word_bus_number(), aml_word_io(), aml_dword_memory(), aml_qword_memory() terms
>       pc: pcihp: expose MMIO base and len as properties
>       pc: acpi-build: reserve PCIHP MMIO resources
> 
> Markus Armbruster (11):
>       pci: Convert core to realize
>       pci: Permit incremental conversion of device models to realize
>       pci: Trivial device model conversions to realize
>       pcnet: pcnet_common_init() always returns 0, change to void
>       pcnet: Convert to realize
>       serial-pci: Convert to realize
>       ide/ich: Convert to realize
>       cirrus-vga: Convert to realize
>       qxl: Convert to realize
>       pci-assign: Convert to realize
>       qdev: Don't exit when running into bad -global
> 
> Michael S. Tsirkin (32):
>       acpi-build: fix memory leak with bridge hp off
>       bios linker: validate pointer within table
>       acpi: update RSDP on guest access
>       exec: round up size on MR resize
>       acpi-build: fix ACPI RAM management
>       acpi: has_immutable_rsdp->!rsdp_in_ram
>       acpi-build: simplify rsdp management for legacy
>       scripts/update-linux-headers.sh: pull virtio hdrs
>       include: import virtio headers from linux 4.0
>       virtio: use standard virtio_ring.h
>       virtio: use standard-headers
>       virtio-balloon: use standard headers
>       virtio-9p: use standard headers
>       virtio-blk: switch to standard-headers
>       virtio-net,tap: use standard-headers
>       virtio-rng: use standard-headers
>       virtio-scsi: use standard-headers
>       virtio-serial: switch to standard-headers
>       update-linux-headers: use standard-headers
>       linux-headers: use standard-headers
>       virtio-pci: use standard headers
>       scripts: add arch specific standard-headers
>       standard-headers: add s390 virtio headers
>       s390: use standard headers
>       acpi-build: skip hotplugged bridges
>       update-linux-headers.sh: s/__inline__/inline/
>       virtio-serial-bus.c: drop virtio_ids.h
>       standard-headers: include stdint.h
>       virtio_ring.h: s/__inline__/inline/
>       acpi: update generated hex files
>       acpi: drop unused generated files
>       acpi-test: update expected files
> 
> Peter Krempa (2):
>       vl.c: Fix error messages when parsing maxmem parameters
>       pc: memory: Validate alignment of maxram_size to page size
> 
> Tang Chen (5):
>       acpi, pc: Add hotunplug request cb for pc machine.
>       acpi, ich9: Add hotunplug request cb for ich9.
>       acpi, pc: Add unplug cb for pc machine.
>       acpi, ich9: Add unplug cb for ich9.
>       acpi, piix4: Add unplug cb for piix4.
> 
>  hw/9pfs/virtio-9p.h                                |  18 +-
>  hw/net/pcnet.h                                     |   2 +-
>  hw/s390x/s390-virtio-bus.h                         |  36 +-
>  hw/s390x/s390-virtio.h                             |   7 +-
>  include/hw/acpi/aml-build.h                        | 206 +++++
>  include/hw/acpi/ich9.h                             |   4 +
>  include/hw/acpi/pc-hotplug.h                       |   1 +
>  include/hw/acpi/pcihp.h                            |   7 +-
>  include/hw/i386/pc.h                               |   1 +
>  include/hw/pci/pci.h                               |   3 +-
>  include/hw/qdev-properties.h                       |   4 +-
>  include/hw/virtio/dataplane/vring.h                |   2 +-
>  include/hw/virtio/virtio-balloon.h                 |  35 +-
>  include/hw/virtio/virtio-blk.h                     |  77 +-
>  include/hw/virtio/virtio-bus.h                     |   3 -
>  include/hw/virtio/virtio-net.h                     | 151 +---
>  include/hw/virtio/virtio-rng.h                     |   4 +-
>  include/hw/virtio/virtio-scsi.h                    | 120 +--
>  include/hw/virtio/virtio-serial.h                  |  40 +-
>  include/hw/virtio/virtio.h                         |  71 +-
>  include/net/tap.h                                  |  24 +-
>  include/standard-headers/asm-s390/kvm_virtio.h     |  64 ++
>  include/standard-headers/asm-s390/virtio-ccw.h     |  21 +
>  include/standard-headers/linux/if_ether.h          |   1 +
>  include/standard-headers/linux/types.h             |   2 +
>  include/standard-headers/linux/virtio_9p.h         |  44 ++
>  include/standard-headers/linux/virtio_balloon.h    |  59 ++
>  include/standard-headers/linux/virtio_blk.h        | 143 ++++
>  include/standard-headers/linux/virtio_config.h     |  64 ++
>  include/standard-headers/linux/virtio_console.h    |  78 ++
>  include/standard-headers/linux/virtio_ids.h        |  43 +
>  include/standard-headers/linux/virtio_net.h        | 233 ++++++
>  include/standard-headers/linux/virtio_pci.h        | 193 +++++
>  .../linux}/virtio_ring.h                           | 132 ++--
>  include/standard-headers/linux/virtio_rng.h        |   8 +
>  include/standard-headers/linux/virtio_scsi.h       | 164 ++++
>  include/standard-headers/linux/virtio_types.h      |  46 ++
>  linux-headers/linux/virtio_config.h                |  58 +-
>  linux-headers/linux/virtio_ring.h                  | 164 +---
>  exec.c                                             |   2 +
>  hw/9pfs/virtio-9p-device.c                         |   2 +-
>  hw/acpi/aml-build.c                                | 867 +++++++++++++++++++++
>  hw/acpi/bios-linker-loader.c                       |   4 +-
>  hw/acpi/ich9.c                                     |  14 +
>  hw/acpi/pcihp.c                                    |  18 +-
>  hw/acpi/piix4.c                                    |  15 +-
>  hw/audio/ac97.c                                    |   5 +-
>  hw/audio/es1370.c                                  |   5 +-
>  hw/audio/intel-hda.c                               |   6 +-
>  hw/block/virtio-blk.c                              |  31 +-
>  hw/char/serial-pci.c                               |  22 +-
>  hw/char/virtio-serial-bus.c                        |   4 +-
>  hw/core/qdev-properties.c                          |  21 +-
>  hw/core/qdev.c                                     |   8 +-
>  hw/display/cirrus_vga.c                            |  11 +-
>  hw/display/qxl.c                                   |  36 +-
>  hw/display/vga-pci.c                               |  11 +-
>  hw/display/vmware_vga.c                            |   6 +-
>  hw/i2c/smbus_ich9.c                                |   5 +-
>  hw/i386/acpi-build.c                               | 750 +++++++++---------
>  hw/i386/kvm/pci-assign.c                           |  10 +-
>  hw/i386/pc.c                                       |  23 +
>  hw/i386/pc_piix.c                                  |   3 +
>  hw/i386/pc_q35.c                                   |   3 +
>  hw/ide/cmd646.c                                    |   5 +-
>  hw/ide/ich.c                                       |  13 +-
>  hw/ide/piix.c                                      |  10 +-
>  hw/ide/via.c                                       |   6 +-
>  hw/ipack/tpci200.c                                 |   6 +-
>  hw/isa/i82378.c                                    |   6 +-
>  hw/isa/lpc_ich9.c                                  |  14 +-
>  hw/isa/piix4.c                                     |   5 +-
>  hw/isa/vt82c686.c                                  |  24 +-
>  hw/misc/pci-testdev.c                              |   6 +-
>  hw/net/e1000.c                                     |   6 +-
>  hw/net/eepro100.c                                  |   6 +-
>  hw/net/lance.c                                     |   3 +-
>  hw/net/ne2000.c                                    |   6 +-
>  hw/net/pcnet-pci.c                                 |   6 +-
>  hw/net/pcnet.c                                     |   4 +-
>  hw/net/rtl8139.c                                   |   6 +-
>  hw/net/vhost_net.c                                 |   2 +-
>  hw/net/virtio-net.c                                |  57 +-
>  hw/net/vmxnet3.c                                   |   6 +-
>  hw/pci-bridge/dec.c                                |   5 +-
>  hw/pci-host/apb.c                                  |   5 +-
>  hw/pci-host/bonito.c                               |   6 +-
>  hw/pci-host/grackle.c                              |   5 +-
>  hw/pci-host/piix.c                                 |  12 +-
>  hw/pci-host/ppce500.c                              |   6 +-
>  hw/pci-host/prep.c                                 |   6 +-
>  hw/pci-host/q35.c                                  |   5 +-
>  hw/pci-host/uninorth.c                             |  20 +-
>  hw/pci-host/versatile.c                            |   5 +-
>  hw/pci/pci.c                                       | 113 +--
>  hw/s390x/virtio-ccw.c                              |   7 +-
>  hw/scsi/virtio-scsi.c                              |   9 +-
>  hw/sd/sdhci.c                                      |   5 +-
>  hw/usb/hcd-ehci-pci.c                              |   6 +-
>  hw/usb/hcd-xhci.c                                  |   6 +-
>  hw/virtio/dataplane/vring.c                        |  10 +-
>  hw/virtio/virtio-balloon.c                         |   2 +-
>  hw/virtio/virtio-bus.c                             |  14 -
>  hw/virtio/virtio-mmio.c                            |   2 +-
>  hw/virtio/virtio-pci.c                             |  58 +-
>  hw/virtio/virtio.c                                 |  33 +-
>  hw/watchdog/wdt_i6300esb.c                         |   6 +-
>  vl.c                                               |  34 +-
>  hw/acpi/Makefile.objs                              |   1 +
>  hw/i386/Makefile.objs                              |   6 +-
>  hw/i386/acpi-dsdt-cpu-hotplug.dsl                  |  17 +-
>  hw/i386/acpi-dsdt-mem-hotplug.dsl                  |  36 +-
>  hw/i386/acpi-dsdt.hex.generated                    | 224 +-----
>  hw/i386/q35-acpi-dsdt.hex.generated                | 224 +-----
>  hw/i386/ssdt-mem.dsl                               |  77 --
>  hw/i386/ssdt-mem.hex.generated                     | 213 -----
>  hw/i386/ssdt-misc.dsl                              |  82 --
>  hw/i386/ssdt-misc.hex.generated                    | 274 +------
>  hw/i386/ssdt-proc.dsl                              |  63 --
>  hw/i386/ssdt-proc.hex.generated                    | 134 ----
>  scripts/update-linux-headers.sh                    |  52 +-
>  tests/acpi-test-data/pc/DSDT                       | Bin 3621 -> 3415 bytes
>  tests/acpi-test-data/pc/SSDT                       | Bin 2279 -> 2374 bytes
>  tests/acpi-test-data/q35/DSDT                      | Bin 8211 -> 8005 bytes
>  tests/acpi-test-data/q35/SSDT                      | Bin 560 -> 578 bytes
>  125 files changed, 3236 insertions(+), 2959 deletions(-)
>  create mode 100644 include/hw/acpi/aml-build.h
>  create mode 100644 include/standard-headers/asm-s390/kvm_virtio.h
>  create mode 100644 include/standard-headers/asm-s390/virtio-ccw.h
>  create mode 100644 include/standard-headers/linux/if_ether.h
>  create mode 100644 include/standard-headers/linux/types.h
>  create mode 100644 include/standard-headers/linux/virtio_9p.h
>  create mode 100644 include/standard-headers/linux/virtio_balloon.h
>  create mode 100644 include/standard-headers/linux/virtio_blk.h
>  create mode 100644 include/standard-headers/linux/virtio_config.h
>  create mode 100644 include/standard-headers/linux/virtio_console.h
>  create mode 100644 include/standard-headers/linux/virtio_ids.h
>  create mode 100644 include/standard-headers/linux/virtio_net.h
>  create mode 100644 include/standard-headers/linux/virtio_pci.h
>  rename include/{hw/virtio => standard-headers/linux}/virtio_ring.h (61%)
>  create mode 100644 include/standard-headers/linux/virtio_rng.h
>  create mode 100644 include/standard-headers/linux/virtio_scsi.h
>  create mode 100644 include/standard-headers/linux/virtio_types.h
>  create mode 100644 hw/acpi/aml-build.c
>  delete mode 100644 hw/i386/ssdt-mem.dsl
>  delete mode 100644 hw/i386/ssdt-mem.hex.generated
>  delete mode 100644 hw/i386/ssdt-proc.dsl
>  delete mode 100644 hw/i386/ssdt-proc.hex.generated
> 

^ permalink raw reply	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 44/96] virtio-pci: use standard headers
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (43 preceding siblings ...)
  2015-02-18 21:48 ` [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
@ 2015-02-18 21:48 ` Michael S. Tsirkin
  2015-02-18 21:48 ` [Qemu-devel] [PULL 45/96] scripts: add arch specific standard-headers Michael S. Tsirkin
                   ` (53 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, dgilbert, Anthony Liguori, Juan Quintela

Drop duplicate code.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/virtio/virtio-pci.c | 54 +++++---------------------------------------------
 1 file changed, 5 insertions(+), 49 deletions(-)

diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index dde1d73..4b17ecb 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -17,6 +17,7 @@
 
 #include <inttypes.h>
 
+#include "standard-headers/linux/virtio_pci.h"
 #include "hw/virtio/virtio.h"
 #include "hw/virtio/virtio-blk.h"
 #include "hw/virtio/virtio-net.h"
@@ -35,56 +36,11 @@
 #include "hw/virtio/virtio-bus.h"
 #include "qapi/visitor.h"
 
-/* from Linux's linux/virtio_pci.h */
-
-/* A 32-bit r/o bitmask of the features supported by the host */
-#define VIRTIO_PCI_HOST_FEATURES        0
-
-/* A 32-bit r/w bitmask of features activated by the guest */
-#define VIRTIO_PCI_GUEST_FEATURES       4
-
-/* A 32-bit r/w PFN for the currently selected queue */
-#define VIRTIO_PCI_QUEUE_PFN            8
-
-/* A 16-bit r/o queue size for the currently selected queue */
-#define VIRTIO_PCI_QUEUE_NUM            12
-
-/* A 16-bit r/w queue selector */
-#define VIRTIO_PCI_QUEUE_SEL            14
-
-/* A 16-bit r/w queue notifier */
-#define VIRTIO_PCI_QUEUE_NOTIFY         16
-
-/* An 8-bit device status register.  */
-#define VIRTIO_PCI_STATUS               18
-
-/* An 8-bit r/o interrupt status register.  Reading the value will return the
- * current contents of the ISR and will also clear it.  This is effectively
- * a read-and-acknowledge. */
-#define VIRTIO_PCI_ISR                  19
-
-/* MSI-X registers: only enabled if MSI-X is enabled. */
-/* A 16-bit vector for configuration changes. */
-#define VIRTIO_MSI_CONFIG_VECTOR        20
-/* A 16-bit vector for selected queue notifications. */
-#define VIRTIO_MSI_QUEUE_VECTOR         22
-
-/* Config space size */
-#define VIRTIO_PCI_CONFIG_NOMSI         20
-#define VIRTIO_PCI_CONFIG_MSI           24
-#define VIRTIO_PCI_REGION_SIZE(dev)     (msix_present(dev) ? \
-                                         VIRTIO_PCI_CONFIG_MSI : \
-                                         VIRTIO_PCI_CONFIG_NOMSI)
+#define VIRTIO_PCI_REGION_SIZE(dev)     VIRTIO_PCI_CONFIG_OFF(msix_present(dev))
 
 /* The remaining space is defined by each driver as the per-driver
  * configuration space */
-#define VIRTIO_PCI_CONFIG(dev)          (msix_enabled(dev) ? \
-                                         VIRTIO_PCI_CONFIG_MSI : \
-                                         VIRTIO_PCI_CONFIG_NOMSI)
-
-/* How many bits to shift physical queue address written to QUEUE_PFN.
- * 12 is historical, and due to x86 page size. */
-#define VIRTIO_PCI_QUEUE_ADDR_SHIFT    12
+#define VIRTIO_PCI_CONFIG_SIZE(dev)     VIRTIO_PCI_CONFIG_OFF(msix_enabled(dev))
 
 static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size,
                                VirtIOPCIProxy *dev);
@@ -392,7 +348,7 @@ static uint64_t virtio_pci_config_read(void *opaque, hwaddr addr,
 {
     VirtIOPCIProxy *proxy = opaque;
     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
-    uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
+    uint32_t config = VIRTIO_PCI_CONFIG_SIZE(&proxy->pci_dev);
     uint64_t val = 0;
     if (addr < config) {
         return virtio_ioport_read(proxy, addr);
@@ -423,7 +379,7 @@ static void virtio_pci_config_write(void *opaque, hwaddr addr,
                                     uint64_t val, unsigned size)
 {
     VirtIOPCIProxy *proxy = opaque;
-    uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
+    uint32_t config = VIRTIO_PCI_CONFIG_SIZE(&proxy->pci_dev);
     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
     if (addr < config) {
         virtio_ioport_write(proxy, addr, val);
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 45/96] scripts: add arch specific standard-headers
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (44 preceding siblings ...)
  2015-02-18 21:48 ` [Qemu-devel] [PULL 44/96] virtio-pci: use standard headers Michael S. Tsirkin
@ 2015-02-18 21:48 ` Michael S. Tsirkin
  2015-02-18 21:48 ` [Qemu-devel] [PULL 46/96] standard-headers: add s390 virtio headers Michael S. Tsirkin
                   ` (52 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Alexander Graf, Thomas Huth, dgilbert, Juan Quintela

Copy arch specific virtio headers.
ATM this applies to s390 only.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 scripts/update-linux-headers.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers.sh
index 5ab3914..9680e27 100755
--- a/scripts/update-linux-headers.sh
+++ b/scripts/update-linux-headers.sh
@@ -87,6 +87,8 @@ for arch in $ARCHLIST; do
     if [ $arch = powerpc ]; then
         cp "$tmpdir/include/asm/epapr_hcalls.h" "$output/linux-headers/asm-powerpc/"
     fi
+
+    cp_virtio "$tmpdir/include/asm" "$output/include/standard-headers/asm-$arch"
 done
 
 rm -rf "$output/linux-headers/linux"
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 46/96] standard-headers: add s390 virtio headers
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (45 preceding siblings ...)
  2015-02-18 21:48 ` [Qemu-devel] [PULL 45/96] scripts: add arch specific standard-headers Michael S. Tsirkin
@ 2015-02-18 21:48 ` Michael S. Tsirkin
  2015-02-18 21:48 ` [Qemu-devel] [PULL 47/96] s390: use standard headers Michael S. Tsirkin
                   ` (51 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, dgilbert, Juan Quintela

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/standard-headers/asm-s390/kvm_virtio.h | 64 ++++++++++++++++++++++++++
 include/standard-headers/asm-s390/virtio-ccw.h | 21 +++++++++
 2 files changed, 85 insertions(+)
 create mode 100644 include/standard-headers/asm-s390/kvm_virtio.h
 create mode 100644 include/standard-headers/asm-s390/virtio-ccw.h

diff --git a/include/standard-headers/asm-s390/kvm_virtio.h b/include/standard-headers/asm-s390/kvm_virtio.h
new file mode 100644
index 0000000..daad324
--- /dev/null
+++ b/include/standard-headers/asm-s390/kvm_virtio.h
@@ -0,0 +1,64 @@
+/*
+ * definition for virtio for kvm on s390
+ *
+ * Copyright IBM Corp. 2008
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ *
+ *    Author(s): Christian Borntraeger <borntraeger@de.ibm.com>
+ */
+
+#ifndef __KVM_S390_VIRTIO_H
+#define __KVM_S390_VIRTIO_H
+
+#include "standard-headers/linux/types.h"
+
+struct kvm_device_desc {
+	/* The device type: console, network, disk etc.  Type 0 terminates. */
+	uint8_t type;
+	/* The number of virtqueues (first in config array) */
+	uint8_t num_vq;
+	/*
+	 * The number of bytes of feature bits.  Multiply by 2: one for host
+	 * features and one for guest acknowledgements.
+	 */
+	uint8_t feature_len;
+	/* The number of bytes of the config array after virtqueues. */
+	uint8_t config_len;
+	/* A status byte, written by the Guest. */
+	uint8_t status;
+	uint8_t config[0];
+};
+
+/*
+ * This is how we expect the device configuration field for a virtqueue
+ * to be laid out in config space.
+ */
+struct kvm_vqconfig {
+	/* The token returned with an interrupt. Set by the guest */
+	uint64_t token;
+	/* The address of the virtio ring */
+	uint64_t address;
+	/* The number of entries in the virtio_ring */
+	uint16_t num;
+
+};
+
+#define KVM_S390_VIRTIO_NOTIFY		0
+#define KVM_S390_VIRTIO_RESET		1
+#define KVM_S390_VIRTIO_SET_STATUS	2
+
+/* The alignment to use between consumer and producer parts of vring.
+ * This is pagesize for historical reasons. */
+#define KVM_S390_VIRTIO_RING_ALIGN	4096
+
+
+/* These values are supposed to be in ext_params on an interrupt */
+#define VIRTIO_PARAM_MASK		0xff
+#define VIRTIO_PARAM_VRING_INTERRUPT	0x0
+#define VIRTIO_PARAM_CONFIG_CHANGED	0x1
+#define VIRTIO_PARAM_DEV_ADD		0x2
+
+#endif
diff --git a/include/standard-headers/asm-s390/virtio-ccw.h b/include/standard-headers/asm-s390/virtio-ccw.h
new file mode 100644
index 0000000..a9a4ebf
--- /dev/null
+++ b/include/standard-headers/asm-s390/virtio-ccw.h
@@ -0,0 +1,21 @@
+/*
+ * Definitions for virtio-ccw devices.
+ *
+ * Copyright IBM Corp. 2013
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ *
+ *  Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
+ */
+#ifndef __KVM_VIRTIO_CCW_H
+#define __KVM_VIRTIO_CCW_H
+
+/* Alignment of vring buffers. */
+#define KVM_VIRTIO_CCW_RING_ALIGN 4096
+
+/* Subcode for diagnose 500 (virtio hypercall). */
+#define KVM_S390_VIRTIO_CCW_NOTIFY 3
+
+#endif
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 47/96] s390: use standard headers
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (46 preceding siblings ...)
  2015-02-18 21:48 ` [Qemu-devel] [PULL 46/96] standard-headers: add s390 virtio headers Michael S. Tsirkin
@ 2015-02-18 21:48 ` Michael S. Tsirkin
  2015-02-18 21:48 ` [Qemu-devel] [PULL 48/96] virtio: cull virtio_bus_set_vdev_features Michael S. Tsirkin
                   ` (50 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, Alexander Graf, dgilbert,
	Cornelia Huck, Richard Henderson

Drop duplicated macros in favor of values from
standard headers.

Tested-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/s390x/s390-virtio-bus.h | 36 +++++++++++++++++++-----------------
 hw/s390x/s390-virtio.h     |  7 ++-----
 2 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/hw/s390x/s390-virtio-bus.h b/hw/s390x/s390-virtio-bus.h
index ffd0df7..92aa9d0 100644
--- a/hw/s390x/s390-virtio-bus.h
+++ b/hw/s390x/s390-virtio-bus.h
@@ -19,6 +19,10 @@
 #ifndef HW_S390_VIRTIO_BUS_H
 #define HW_S390_VIRTIO_BUS_H 1
 
+#include <stddef.h>
+
+#include "standard-headers/asm-s390/kvm_virtio.h"
+#include "standard-headers/linux/virtio_ring.h"
 #include "hw/virtio/virtio-blk.h"
 #include "hw/virtio/virtio-net.h"
 #include "hw/virtio/virtio-rng.h"
@@ -29,28 +33,26 @@
 #include "hw/virtio/vhost-scsi.h"
 #endif
 
-#define VIRTIO_DEV_OFFS_TYPE		0	/* 8 bits */
-#define VIRTIO_DEV_OFFS_NUM_VQ		1	/* 8 bits */
-#define VIRTIO_DEV_OFFS_FEATURE_LEN	2	/* 8 bits */
-#define VIRTIO_DEV_OFFS_CONFIG_LEN	3	/* 8 bits */
-#define VIRTIO_DEV_OFFS_STATUS		4	/* 8 bits */
-#define VIRTIO_DEV_OFFS_CONFIG		5	/* dynamic */
+typedef struct kvm_device_desc KvmDeviceDesc;
+
+#define VIRTIO_DEV_OFFS_TYPE        offsetof(KvmDeviceDesc, type)
+#define VIRTIO_DEV_OFFS_NUM_VQ      offsetof(KvmDeviceDesc, num_vq)
+#define VIRTIO_DEV_OFFS_FEATURE_LEN offsetof(KvmDeviceDesc, feature_len)
+#define VIRTIO_DEV_OFFS_CONFIG_LEN  offsetof(KvmDeviceDesc, config_len)
+#define VIRTIO_DEV_OFFS_STATUS      offsetof(KvmDeviceDesc, status)
+#define VIRTIO_DEV_OFFS_CONFIG      offsetof(KvmDeviceDesc, config)
 
-#define VIRTIO_VQCONFIG_OFFS_TOKEN	0	/* 64 bits */
-#define VIRTIO_VQCONFIG_OFFS_ADDRESS	8	/* 64 bits */
-#define VIRTIO_VQCONFIG_OFFS_NUM	16	/* 16 bits */
-#define VIRTIO_VQCONFIG_LEN		24
+typedef struct kvm_vqconfig KvmVqConfig;
+#define VIRTIO_VQCONFIG_OFFS_TOKEN   offsetof(KvmVqConfig,token)    /* 64 bit */
+#define VIRTIO_VQCONFIG_OFFS_ADDRESS offsetof(KvmVqConfig, address) /* 64 bit */
+#define VIRTIO_VQCONFIG_OFFS_NUM     offsetof(KvmVqConfig, num)     /* 16 bit */
+#define VIRTIO_VQCONFIG_LEN          sizeof(KvmVqConfig)
 
 #define VIRTIO_RING_LEN			(TARGET_PAGE_SIZE * 3)
-#define VIRTIO_VRING_AVAIL_IDX_OFFS 2
-#define VIRTIO_VRING_USED_IDX_OFFS 2
+#define VIRTIO_VRING_AVAIL_IDX_OFFS offsetof(struct vring_avail, idx)
+#define VIRTIO_VRING_USED_IDX_OFFS  offsetof(struct vring_used, idx)
 #define S390_DEVICE_PAGES		512
 
-#define VIRTIO_PARAM_MASK               0xff
-#define VIRTIO_PARAM_VRING_INTERRUPT    0x0
-#define VIRTIO_PARAM_CONFIG_CHANGED     0x1
-#define VIRTIO_PARAM_DEV_ADD            0x2
-
 #define TYPE_VIRTIO_S390_DEVICE "virtio-s390-device"
 #define VIRTIO_S390_DEVICE(obj) \
      OBJECT_CHECK(VirtIOS390Device, (obj), TYPE_VIRTIO_S390_DEVICE)
diff --git a/hw/s390x/s390-virtio.h b/hw/s390x/s390-virtio.h
index 33847ae..f9d67a8 100644
--- a/hw/s390x/s390-virtio.h
+++ b/hw/s390x/s390-virtio.h
@@ -13,11 +13,8 @@
 #define HW_S390_VIRTIO_H 1
 
 #include "hw/nmi.h"
-
-#define KVM_S390_VIRTIO_NOTIFY          0
-#define KVM_S390_VIRTIO_RESET           1
-#define KVM_S390_VIRTIO_SET_STATUS      2
-#define KVM_S390_VIRTIO_CCW_NOTIFY      3
+#include "standard-headers/asm-s390/kvm_virtio.h"
+#include "standard-headers/asm-s390/virtio-ccw.h"
 
 typedef int (*s390_virtio_fn)(const uint64_t *args);
 void s390_register_virtio_hypercall(uint64_t code, s390_virtio_fn fn);
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 48/96] virtio: cull virtio_bus_set_vdev_features
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (47 preceding siblings ...)
  2015-02-18 21:48 ` [Qemu-devel] [PULL 47/96] s390: use standard headers Michael S. Tsirkin
@ 2015-02-18 21:48 ` Michael S. Tsirkin
  2015-02-18 21:48 ` [Qemu-devel] [PULL 49/96] virtio: feature bit manipulation helpers Michael S. Tsirkin
                   ` (49 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Thomas Huth, Juan Quintela, dgilbert,
	Alexander Graf, Christian Borntraeger, Anthony Liguori,
	Cornelia Huck, Richard Henderson

From: Cornelia Huck <cornelia.huck@de.ibm.com>

The only user of this function was virtio-ccw, and it should use
virtio_set_features() like everybody else: We need to make sure
that bad features are masked out properly, which this function did
not do.

Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com>
Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/virtio/virtio-bus.h |  3 ---
 hw/s390x/virtio-ccw.c          |  3 +--
 hw/virtio/virtio-bus.c         | 14 --------------
 3 files changed, 1 insertion(+), 19 deletions(-)

diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h
index 0756545..0d2e7b4 100644
--- a/include/hw/virtio/virtio-bus.h
+++ b/include/hw/virtio/virtio-bus.h
@@ -84,9 +84,6 @@ size_t virtio_bus_get_vdev_config_len(VirtioBusState *bus);
 /* Get the features of the plugged device. */
 uint32_t virtio_bus_get_vdev_features(VirtioBusState *bus,
                                     uint32_t requested_features);
-/* Set the features of the plugged device. */
-void virtio_bus_set_vdev_features(VirtioBusState *bus,
-                                  uint32_t requested_features);
 /* Get bad features of the plugged device. */
 uint32_t virtio_bus_get_vdev_bad_features(VirtioBusState *bus);
 /* Get config of the plugged device. */
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index ea236c9..84f17bc 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -400,8 +400,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
                                        ccw.cda + sizeof(features.features));
             features.features = ldl_le_phys(&address_space_memory, ccw.cda);
             if (features.index < ARRAY_SIZE(dev->host_features)) {
-                virtio_bus_set_vdev_features(&dev->bus, features.features);
-                vdev->guest_features = features.features;
+                virtio_set_features(vdev, features.features);
             } else {
                 /*
                  * If the guest supports more feature bits, assert that it
diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c
index dfd2d8c..be886e7 100644
--- a/hw/virtio/virtio-bus.c
+++ b/hw/virtio/virtio-bus.c
@@ -109,20 +109,6 @@ uint32_t virtio_bus_get_vdev_features(VirtioBusState *bus,
     return k->get_features(vdev, requested_features);
 }
 
-/* Set the features of the plugged device. */
-void virtio_bus_set_vdev_features(VirtioBusState *bus,
-                                      uint32_t requested_features)
-{
-    VirtIODevice *vdev = virtio_bus_get_device(bus);
-    VirtioDeviceClass *k;
-
-    assert(vdev != NULL);
-    k = VIRTIO_DEVICE_GET_CLASS(vdev);
-    if (k->set_features != NULL) {
-        k->set_features(vdev, requested_features);
-    }
-}
-
 /* Get bad features of the plugged device. */
 uint32_t virtio_bus_get_vdev_bad_features(VirtioBusState *bus)
 {
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 49/96] virtio: feature bit manipulation helpers
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (48 preceding siblings ...)
  2015-02-18 21:48 ` [Qemu-devel] [PULL 48/96] virtio: cull virtio_bus_set_vdev_features Michael S. Tsirkin
@ 2015-02-18 21:48 ` Michael S. Tsirkin
  2015-02-18 21:49 ` [Qemu-devel] [PULL 50/96] virtio: add feature checking helpers Michael S. Tsirkin
                   ` (48 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Peter Maydell, Stefan Hajnoczi, Juan Quintela,
	dgilbert, Alexander Graf, Amit Shah, Aneesh Kumar K.V,
	Anthony Liguori, Cornelia Huck, Christian Borntraeger,
	Richard Henderson

From: Cornelia Huck <cornelia.huck@de.ibm.com>

Add virtio_{add,clear}_feature helper functions for manipulating a
feature bits variable. This has some benefits over open coding:
- add check that the bit is in a sane range
- make it obvious at a glance what is going on
- have a central point to change when we want to extend feature bits

Convert existing code manipulating features to use the new helpers.

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/virtio/virtio.h  | 12 ++++++++++++
 hw/9pfs/virtio-9p-device.c  |  2 +-
 hw/block/virtio-blk.c       | 16 ++++++++--------
 hw/char/virtio-serial-bus.c |  2 +-
 hw/net/virtio-net.c         | 34 +++++++++++++++++-----------------
 hw/s390x/virtio-ccw.c       |  4 ++--
 hw/virtio/virtio-mmio.c     |  2 +-
 hw/virtio/virtio-pci.c      |  4 ++--
 8 files changed, 44 insertions(+), 32 deletions(-)

diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index d1b416b..85e72d6 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -219,6 +219,18 @@ void virtio_queue_set_host_notifier_fd_handler(VirtQueue *vq, bool assign,
 void virtio_queue_notify_vq(VirtQueue *vq);
 void virtio_irq(VirtQueue *vq);
 
+static inline void virtio_add_feature(uint32_t *features, unsigned int fbit)
+{
+    assert(fbit < 32);
+    *features |= (1 << fbit);
+}
+
+static inline void virtio_clear_feature(uint32_t *features, unsigned int fbit)
+{
+    assert(fbit < 32);
+    *features &= ~(1 << fbit);
+}
+
 static inline bool virtio_is_big_endian(VirtIODevice *vdev)
 {
     assert(vdev->device_endian != VIRTIO_DEVICE_ENDIAN_UNKNOWN);
diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index 2572747..30492ec 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -23,7 +23,7 @@
 
 static uint32_t virtio_9p_get_features(VirtIODevice *vdev, uint32_t features)
 {
-    features |= 1 << VIRTIO_9P_MOUNT_TAG;
+    virtio_add_feature(&features, VIRTIO_9P_MOUNT_TAG);
     return features;
 }
 
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 6828f48..307df95 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -711,20 +711,20 @@ static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features)
 {
     VirtIOBlock *s = VIRTIO_BLK(vdev);
 
-    features |= (1 << VIRTIO_BLK_F_SEG_MAX);
-    features |= (1 << VIRTIO_BLK_F_GEOMETRY);
-    features |= (1 << VIRTIO_BLK_F_TOPOLOGY);
-    features |= (1 << VIRTIO_BLK_F_BLK_SIZE);
-    features |= (1 << VIRTIO_BLK_F_SCSI);
+    virtio_add_feature(&features, VIRTIO_BLK_F_SEG_MAX);
+    virtio_add_feature(&features, VIRTIO_BLK_F_GEOMETRY);
+    virtio_add_feature(&features, VIRTIO_BLK_F_TOPOLOGY);
+    virtio_add_feature(&features, VIRTIO_BLK_F_BLK_SIZE);
+    virtio_add_feature(&features, VIRTIO_BLK_F_SCSI);
 
     if (s->conf.config_wce) {
-        features |= (1 << VIRTIO_BLK_F_CONFIG_WCE);
+        virtio_add_feature(&features, VIRTIO_BLK_F_CONFIG_WCE);
     }
     if (blk_enable_write_cache(s->blk)) {
-        features |= (1 << VIRTIO_BLK_F_WCE);
+        virtio_add_feature(&features, VIRTIO_BLK_F_WCE);
     }
     if (blk_is_read_only(s->blk)) {
-        features |= 1 << VIRTIO_BLK_F_RO;
+        virtio_add_feature(&features, VIRTIO_BLK_F_RO);
     }
 
     return features;
diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index a2bac9b..2365336 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -475,7 +475,7 @@ static uint32_t get_features(VirtIODevice *vdev, uint32_t features)
     vser = VIRTIO_SERIAL(vdev);
 
     if (vser->bus.max_nr_ports > 1) {
-        features |= (1 << VIRTIO_CONSOLE_F_MULTIPORT);
+        virtio_add_feature(&features, VIRTIO_CONSOLE_F_MULTIPORT);
     }
     return features;
 }
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 45da34a..f901952 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -446,23 +446,23 @@ static uint32_t virtio_net_get_features(VirtIODevice *vdev, uint32_t features)
     VirtIONet *n = VIRTIO_NET(vdev);
     NetClientState *nc = qemu_get_queue(n->nic);
 
-    features |= (1 << VIRTIO_NET_F_MAC);
+    virtio_add_feature(&features, VIRTIO_NET_F_MAC);
 
     if (!peer_has_vnet_hdr(n)) {
-        features &= ~(0x1 << VIRTIO_NET_F_CSUM);
-        features &= ~(0x1 << VIRTIO_NET_F_HOST_TSO4);
-        features &= ~(0x1 << VIRTIO_NET_F_HOST_TSO6);
-        features &= ~(0x1 << VIRTIO_NET_F_HOST_ECN);
+        virtio_clear_feature(&features, VIRTIO_NET_F_CSUM);
+        virtio_clear_feature(&features, VIRTIO_NET_F_HOST_TSO4);
+        virtio_clear_feature(&features, VIRTIO_NET_F_HOST_TSO6);
+        virtio_clear_feature(&features, VIRTIO_NET_F_HOST_ECN);
 
-        features &= ~(0x1 << VIRTIO_NET_F_GUEST_CSUM);
-        features &= ~(0x1 << VIRTIO_NET_F_GUEST_TSO4);
-        features &= ~(0x1 << VIRTIO_NET_F_GUEST_TSO6);
-        features &= ~(0x1 << VIRTIO_NET_F_GUEST_ECN);
+        virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_CSUM);
+        virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_TSO4);
+        virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_TSO6);
+        virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_ECN);
     }
 
     if (!peer_has_vnet_hdr(n) || !peer_has_ufo(n)) {
-        features &= ~(0x1 << VIRTIO_NET_F_GUEST_UFO);
-        features &= ~(0x1 << VIRTIO_NET_F_HOST_UFO);
+        virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_UFO);
+        virtio_clear_feature(&features, VIRTIO_NET_F_HOST_UFO);
     }
 
     if (!get_vhost_net(nc->peer)) {
@@ -477,11 +477,11 @@ static uint32_t virtio_net_bad_features(VirtIODevice *vdev)
 
     /* Linux kernel 2.6.25.  It understood MAC (as everyone must),
      * but also these: */
-    features |= (1 << VIRTIO_NET_F_MAC);
-    features |= (1 << VIRTIO_NET_F_CSUM);
-    features |= (1 << VIRTIO_NET_F_HOST_TSO4);
-    features |= (1 << VIRTIO_NET_F_HOST_TSO6);
-    features |= (1 << VIRTIO_NET_F_HOST_ECN);
+    virtio_add_feature(&features, VIRTIO_NET_F_MAC);
+    virtio_add_feature(&features, VIRTIO_NET_F_CSUM);
+    virtio_add_feature(&features, VIRTIO_NET_F_HOST_TSO4);
+    virtio_add_feature(&features, VIRTIO_NET_F_HOST_TSO6);
+    virtio_add_feature(&features, VIRTIO_NET_F_HOST_ECN);
 
     return features;
 }
@@ -1552,7 +1552,7 @@ static void virtio_net_guest_notifier_mask(VirtIODevice *vdev, int idx,
 void virtio_net_set_config_size(VirtIONet *n, uint32_t host_features)
 {
     int i, config_size = 0;
-    host_features |= (1 << VIRTIO_NET_F_MAC);
+    virtio_add_feature(&host_features, VIRTIO_NET_F_MAC);
     for (i = 0; feature_sizes[i].flags != 0; i++) {
         if (host_features & feature_sizes[i].flags) {
             config_size = MAX(feature_sizes[i].end, config_size);
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index 84f17bc..3fee4aa 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -743,8 +743,8 @@ static int virtio_ccw_device_init(VirtioCcwDevice *dev, VirtIODevice *vdev)
     dev->host_features[0] = virtio_bus_get_vdev_features(&dev->bus,
                                                          dev->host_features[0]);
 
-    dev->host_features[0] |= 0x1 << VIRTIO_F_NOTIFY_ON_EMPTY;
-    dev->host_features[0] |= 0x1 << VIRTIO_F_BAD_FEATURE;
+    virtio_add_feature(&dev->host_features[0], VIRTIO_F_NOTIFY_ON_EMPTY);
+    virtio_add_feature(&dev->host_features[0], VIRTIO_F_BAD_FEATURE);
 
     css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid,
                           parent->hotplugged, 1);
diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c
index 2450c13..10123f3 100644
--- a/hw/virtio/virtio-mmio.c
+++ b/hw/virtio/virtio-mmio.c
@@ -349,7 +349,7 @@ static void virtio_mmio_device_plugged(DeviceState *opaque)
 {
     VirtIOMMIOProxy *proxy = VIRTIO_MMIO(opaque);
 
-    proxy->host_features |= (0x1 << VIRTIO_F_NOTIFY_ON_EMPTY);
+    virtio_add_feature(&proxy->host_features, VIRTIO_F_NOTIFY_ON_EMPTY);
     proxy->host_features = virtio_bus_get_vdev_features(&proxy->bus,
                                                         proxy->host_features);
 }
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 4b17ecb..73a868c 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -952,8 +952,8 @@ static void virtio_pci_device_plugged(DeviceState *d)
         proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
     }
 
-    proxy->host_features |= 0x1 << VIRTIO_F_NOTIFY_ON_EMPTY;
-    proxy->host_features |= 0x1 << VIRTIO_F_BAD_FEATURE;
+    virtio_add_feature(&proxy->host_features, VIRTIO_F_NOTIFY_ON_EMPTY);
+    virtio_add_feature(&proxy->host_features, VIRTIO_F_BAD_FEATURE);
     proxy->host_features = virtio_bus_get_vdev_features(bus,
                                                       proxy->host_features);
 }
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 50/96] virtio: add feature checking helpers
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (49 preceding siblings ...)
  2015-02-18 21:48 ` [Qemu-devel] [PULL 49/96] virtio: feature bit manipulation helpers Michael S. Tsirkin
@ 2015-02-18 21:49 ` Michael S. Tsirkin
  2015-02-18 21:49 ` [Qemu-devel] [PULL 51/96] acpi-build: skip hotplugged bridges Michael S. Tsirkin
                   ` (47 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Juan Quintela,
	dgilbert, Amit Shah, Stefan Hajnoczi, Cornelia Huck,
	Paolo Bonzini

From: Cornelia Huck <cornelia.huck@de.ibm.com>

Add a helper function for checking whether a bit is set in the guest
features for a vdev as well as one that works on a feature bit set.

Convert code that open-coded this: It cleans up the code and makes it
easier to extend the guest feature bits.

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/virtio/virtio.h  | 11 +++++++++++
 hw/block/virtio-blk.c       |  7 ++-----
 hw/char/virtio-serial-bus.c |  2 +-
 hw/net/virtio-net.c         | 23 +++++++++++++----------
 hw/scsi/virtio-scsi.c       |  8 ++++----
 hw/virtio/dataplane/vring.c | 10 +++++-----
 hw/virtio/virtio-balloon.c  |  2 +-
 hw/virtio/virtio.c          | 10 +++++-----
 8 files changed, 42 insertions(+), 31 deletions(-)

diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 85e72d6..d95f8b6 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -231,6 +231,17 @@ static inline void virtio_clear_feature(uint32_t *features, unsigned int fbit)
     *features &= ~(1 << fbit);
 }
 
+static inline bool __virtio_has_feature(uint32_t features, unsigned int fbit)
+{
+    assert(fbit < 32);
+    return !!(features & (1 << fbit));
+}
+
+static inline bool virtio_has_feature(VirtIODevice *vdev, unsigned int fbit)
+{
+    return __virtio_has_feature(vdev->guest_features, fbit);
+}
+
 static inline bool virtio_is_big_endian(VirtIODevice *vdev)
 {
     assert(vdev->device_endian != VIRTIO_DEVICE_ENDIAN_UNKNOWN);
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 307df95..3c9d0b3 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -733,7 +733,6 @@ static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features)
 static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
 {
     VirtIOBlock *s = VIRTIO_BLK(vdev);
-    uint32_t features;
 
     if (s->dataplane && !(status & (VIRTIO_CONFIG_S_DRIVER |
                                     VIRTIO_CONFIG_S_DRIVER_OK))) {
@@ -744,8 +743,6 @@ static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
         return;
     }
 
-    features = vdev->guest_features;
-
     /* A guest that supports VIRTIO_BLK_F_CONFIG_WCE must be able to send
      * cache flushes.  Thus, the "auto writethrough" behavior is never
      * necessary for guests that support the VIRTIO_BLK_F_CONFIG_WCE feature.
@@ -761,10 +758,10 @@ static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
      *
      * s->blk would erroneously be placed in writethrough mode.
      */
-    if (!(features & (1 << VIRTIO_BLK_F_CONFIG_WCE))) {
+    if (!virtio_has_feature(vdev, VIRTIO_BLK_F_CONFIG_WCE)) {
         aio_context_acquire(blk_get_aio_context(s->blk));
         blk_set_enable_write_cache(s->blk,
-                                   !!(features & (1 << VIRTIO_BLK_F_WCE)));
+                                   virtio_has_feature(vdev, VIRTIO_BLK_F_WCE));
         aio_context_release(blk_get_aio_context(s->blk));
     }
 }
diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index 2365336..ba4cf2e 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -76,7 +76,7 @@ static VirtIOSerialPort *find_port_by_name(char *name)
 static bool use_multiport(VirtIOSerial *vser)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(vser);
-    return vdev->guest_features & (1 << VIRTIO_CONSOLE_F_MULTIPORT);
+    return virtio_has_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT);
 }
 
 static size_t write_to_port(VirtIOSerialPort *port,
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index f901952..1187ab8 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -86,7 +86,7 @@ static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config)
 
     memcpy(&netcfg, config, n->config_size);
 
-    if (!(vdev->guest_features >> VIRTIO_NET_F_CTRL_MAC_ADDR & 1) &&
+    if (!virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_MAC_ADDR) &&
         memcmp(netcfg.mac, n->mac, ETH_ALEN)) {
         memcpy(n->mac, netcfg.mac, ETH_ALEN);
         qemu_format_nic_info_str(qemu_get_queue(n->nic), n->mac);
@@ -305,7 +305,7 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
     info->multicast_table = str_list;
     info->vlan_table = get_vlan_table(n);
 
-    if (!((1 << VIRTIO_NET_F_CTRL_VLAN) & vdev->guest_features)) {
+    if (!virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_VLAN)) {
         info->vlan = RX_STATE_ALL;
     } else if (!info->vlan_table) {
         info->vlan = RX_STATE_NONE;
@@ -519,9 +519,12 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features)
     VirtIONet *n = VIRTIO_NET(vdev);
     int i;
 
-    virtio_net_set_multiqueue(n, !!(features & (1 << VIRTIO_NET_F_MQ)));
+    virtio_net_set_multiqueue(n,
+                              __virtio_has_feature(features, VIRTIO_NET_F_MQ));
 
-    virtio_net_set_mrg_rx_bufs(n, !!(features & (1 << VIRTIO_NET_F_MRG_RXBUF)));
+    virtio_net_set_mrg_rx_bufs(n,
+                               __virtio_has_feature(features,
+                                                    VIRTIO_NET_F_MRG_RXBUF));
 
     if (n->has_vnet_hdr) {
         n->curr_guest_offloads =
@@ -538,7 +541,7 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features)
         vhost_net_ack_features(get_vhost_net(nc->peer), features);
     }
 
-    if ((1 << VIRTIO_NET_F_CTRL_VLAN) & features) {
+    if (__virtio_has_feature(features, VIRTIO_NET_F_CTRL_VLAN)) {
         memset(n->vlans, 0, MAX_VLAN >> 3);
     } else {
         memset(n->vlans, 0xff, MAX_VLAN >> 3);
@@ -585,7 +588,7 @@ static int virtio_net_handle_offloads(VirtIONet *n, uint8_t cmd,
     uint64_t offloads;
     size_t s;
 
-    if (!((1 << VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) & vdev->guest_features)) {
+    if (!virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
         return VIRTIO_NET_ERR;
     }
 
@@ -1378,7 +1381,7 @@ static void virtio_net_save_device(VirtIODevice *vdev, QEMUFile *f)
         }
     }
 
-    if ((1 << VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) & vdev->guest_features) {
+    if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
         qemu_put_be64(f, n->curr_guest_offloads);
     }
 }
@@ -1486,7 +1489,7 @@ static int virtio_net_load_device(VirtIODevice *vdev, QEMUFile *f,
         }
     }
 
-    if ((1 << VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) & vdev->guest_features) {
+    if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
         n->curr_guest_offloads = qemu_get_be64(f);
     } else {
         n->curr_guest_offloads = virtio_net_supported_guest_offloads(n);
@@ -1513,8 +1516,8 @@ static int virtio_net_load_device(VirtIODevice *vdev, QEMUFile *f,
         qemu_get_subqueue(n->nic, i)->link_down = link_down;
     }
 
-    if (vdev->guest_features & (0x1 << VIRTIO_NET_F_GUEST_ANNOUNCE) &&
-        vdev->guest_features & (0x1 << VIRTIO_NET_F_CTRL_VQ)) {
+    if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_ANNOUNCE) &&
+        virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ)) {
         n->announce_counter = SELF_ANNOUNCE_ROUNDS;
         timer_mod(n->announce_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL));
     }
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index d18654e..c5d9109 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -145,7 +145,7 @@ static int virtio_scsi_parse_req(VirtIOSCSIReq *req,
      *
      * TODO: always disable this workaround for virtio 1.0 devices.
      */
-    if ((vdev->guest_features & (1 << VIRTIO_F_ANY_LAYOUT)) == 0) {
+    if (!virtio_has_feature(vdev, VIRTIO_F_ANY_LAYOUT)) {
         req_size = req->elem.out_sg[0].iov_len;
         resp_size = req->elem.in_sg[0].iov_len;
     }
@@ -749,7 +749,7 @@ static void virtio_scsi_change(SCSIBus *bus, SCSIDevice *dev, SCSISense sense)
     VirtIOSCSI *s = container_of(bus, VirtIOSCSI, bus);
     VirtIODevice *vdev = VIRTIO_DEVICE(s);
 
-    if (((vdev->guest_features >> VIRTIO_SCSI_F_CHANGE) & 1) &&
+    if (virtio_has_feature(vdev, VIRTIO_SCSI_F_CHANGE) &&
         dev->type != TYPE_ROM) {
         virtio_scsi_push_event(s, dev, VIRTIO_SCSI_T_PARAM_CHANGE,
                                sense.asc | (sense.ascq << 8));
@@ -770,7 +770,7 @@ static void virtio_scsi_hotplug(HotplugHandler *hotplug_dev, DeviceState *dev,
         blk_op_block_all(sd->conf.blk, s->blocker);
     }
 
-    if ((vdev->guest_features >> VIRTIO_SCSI_F_HOTPLUG) & 1) {
+    if (virtio_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG)) {
         virtio_scsi_push_event(s, sd,
                                VIRTIO_SCSI_T_TRANSPORT_RESET,
                                VIRTIO_SCSI_EVT_RESET_RESCAN);
@@ -784,7 +784,7 @@ static void virtio_scsi_hotunplug(HotplugHandler *hotplug_dev, DeviceState *dev,
     VirtIOSCSI *s = VIRTIO_SCSI(vdev);
     SCSIDevice *sd = SCSI_DEVICE(dev);
 
-    if ((vdev->guest_features >> VIRTIO_SCSI_F_HOTPLUG) & 1) {
+    if (virtio_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG)) {
         virtio_scsi_push_event(s, sd,
                                VIRTIO_SCSI_T_TRANSPORT_RESET,
                                VIRTIO_SCSI_EVT_RESET_REMOVED);
diff --git a/hw/virtio/dataplane/vring.c b/hw/virtio/dataplane/vring.c
index 78c6f45..6e283fc 100644
--- a/hw/virtio/dataplane/vring.c
+++ b/hw/virtio/dataplane/vring.c
@@ -103,7 +103,7 @@ void vring_teardown(Vring *vring, VirtIODevice *vdev, int n)
 /* Disable guest->host notifies */
 void vring_disable_notification(VirtIODevice *vdev, Vring *vring)
 {
-    if (!(vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX))) {
+    if (!virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
         vring->vr.used->flags |= VRING_USED_F_NO_NOTIFY;
     }
 }
@@ -114,7 +114,7 @@ void vring_disable_notification(VirtIODevice *vdev, Vring *vring)
  */
 bool vring_enable_notification(VirtIODevice *vdev, Vring *vring)
 {
-    if (vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX)) {
+    if (virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
         vring_avail_event(&vring->vr) = vring->vr.avail->idx;
     } else {
         vring->vr.used->flags &= ~VRING_USED_F_NO_NOTIFY;
@@ -133,12 +133,12 @@ bool vring_should_notify(VirtIODevice *vdev, Vring *vring)
      * interrupts. */
     smp_mb();
 
-    if ((vdev->guest_features & (1 << VIRTIO_F_NOTIFY_ON_EMPTY)) &&
+    if (virtio_has_feature(vdev, VIRTIO_F_NOTIFY_ON_EMPTY) &&
         unlikely(vring->vr.avail->idx == vring->last_avail_idx)) {
         return true;
     }
 
-    if (!(vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX))) {
+    if (!virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
         return !(vring->vr.avail->flags & VRING_AVAIL_F_NO_INTERRUPT);
     }
     old = vring->signalled_used;
@@ -388,7 +388,7 @@ int vring_pop(VirtIODevice *vdev, Vring *vring,
 
     /* On success, increment avail index. */
     vring->last_avail_idx++;
-    if (vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX)) {
+    if (virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
         vring_avail_event(&vring->vr) = vring->last_avail_idx;
     }
 
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index 7bfbb75..21e449a 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -69,7 +69,7 @@ static inline void reset_stats(VirtIOBalloon *dev)
 static bool balloon_stats_supported(const VirtIOBalloon *s)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(s);
-    return vdev->guest_features & (1 << VIRTIO_BALLOON_F_STATS_VQ);
+    return virtio_has_feature(vdev, VIRTIO_BALLOON_F_STATS_VQ);
 }
 
 static bool balloon_stats_enabled(const VirtIOBalloon *s)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index f783f31..3c6e430 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -217,7 +217,7 @@ static inline void vring_set_avail_event(VirtQueue *vq, uint16_t val)
 void virtio_queue_set_notification(VirtQueue *vq, int enable)
 {
     vq->notification = enable;
-    if (vq->vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX)) {
+    if (virtio_has_feature(vq->vdev, VIRTIO_RING_F_EVENT_IDX)) {
         vring_set_avail_event(vq, vring_avail_idx(vq));
     } else if (enable) {
         vring_used_flags_unset_bit(vq, VRING_USED_F_NO_NOTIFY);
@@ -468,7 +468,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem)
     max = vq->vring.num;
 
     i = head = virtqueue_get_head(vq, vq->last_avail_idx++);
-    if (vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX)) {
+    if (virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
         vring_set_avail_event(vq, vq->last_avail_idx);
     }
 
@@ -826,12 +826,12 @@ static bool vring_notify(VirtIODevice *vdev, VirtQueue *vq)
     /* We need to expose used array entries before checking used event. */
     smp_mb();
     /* Always notify when queue is empty (when feature acknowledge) */
-    if (((vdev->guest_features & (1 << VIRTIO_F_NOTIFY_ON_EMPTY)) &&
-         !vq->inuse && vring_avail_idx(vq) == vq->last_avail_idx)) {
+    if (virtio_has_feature(vdev, VIRTIO_F_NOTIFY_ON_EMPTY) &&
+        !vq->inuse && vring_avail_idx(vq) == vq->last_avail_idx) {
         return true;
     }
 
-    if (!(vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX))) {
+    if (!virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
         return !(vring_avail_flags(vq) & VRING_AVAIL_F_NO_INTERRUPT);
     }
 
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 51/96] acpi-build: skip hotplugged bridges
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (50 preceding siblings ...)
  2015-02-18 21:49 ` [Qemu-devel] [PULL 50/96] virtio: add feature checking helpers Michael S. Tsirkin
@ 2015-02-18 21:49 ` Michael S. Tsirkin
  2015-02-18 21:49 ` [Qemu-devel] [PULL 52/96] pc: acpi: use local var for accessing ACPI tables blob in acpi_build() Michael S. Tsirkin
                   ` (46 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Anthony Liguori,
	Paolo Bonzini, Richard Henderson

hotplugged bridges don't get bsel allocated so acpi hotplug doesn't work
for them anyway.  OTOH adding them in ACPI creates a host of problems,
e.g. they can't be hot-unplugged themselves which is surprising to
users.

So let's just skip these.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/i386/acpi-build.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 9b11c92..fa7e52a 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -699,8 +699,10 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)
     /*
      * Skip bridge subtree creation if bridge hotplug is disabled
      * to make acpi tables compatible with legacy machine types.
+     * Skip creation for hotplugged bridges as well.
      */
-    if (!child->pcihp_bridge_en && bus->parent_dev) {
+    if (bus->parent_dev && (!child->pcihp_bridge_en ||
+                            DEVICE(bus->parent_dev)->hotplugged)) {
         build_free_array(bus_table);
         build_pci_bus_state_cleanup(child);
         g_free(child);
@@ -757,8 +759,10 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)
         /* When hotplug for bridges is enabled, bridges are
          * described in ACPI separately (see build_pci_bus_end).
          * In this case they aren't themselves hot-pluggable.
+         * Hotplugged bridges *are* hot-pluggable.
          */
-        bridge_in_acpi = pc->is_bridge && child->pcihp_bridge_en;
+        bridge_in_acpi = pc->is_bridge && child->pcihp_bridge_en &&
+         !DEVICE(pdev)->hotplugged;
 
         if (pc->class_id == PCI_CLASS_BRIDGE_ISA || bridge_in_acpi) {
             set_bit(slot, slot_device_system);
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 52/96] pc: acpi: use local var for accessing ACPI tables blob in acpi_build()
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (51 preceding siblings ...)
  2015-02-18 21:49 ` [Qemu-devel] [PULL 51/96] acpi-build: skip hotplugged bridges Michael S. Tsirkin
@ 2015-02-18 21:49 ` Michael S. Tsirkin
  2015-02-18 21:49 ` [Qemu-devel] [PULL 53/96] update-linux-headers.sh: s/__inline__/inline/ Michael S. Tsirkin
                   ` (45 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Anthony Liguori,
	Paolo Bonzini, Igor Mammedov, Richard Henderson

From: Igor Mammedov <imammedo@redhat.com>

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 <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 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 fa7e52a..5e4b333 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1421,6 +1421,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);
@@ -1441,66 +1442,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);
@@ -1530,23 +1531,23 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
             guest_info->legacy_acpi_table_size +
             ACPI_BUILD_LEGACY_CPU_AML_SIZE * max_cpus;
         int legacy_table_size =
-            ROUND_UP(tables->table_data->len - aml_len + legacy_aml_len,
+            ROUND_UP(tables_blob->len - aml_len + legacy_aml_len,
                      ACPI_BUILD_ALIGN_SIZE);
-        if (tables->table_data->len > legacy_table_size) {
+        if (tables_blob->len > legacy_table_size) {
             /* Should happen only with PCI bridges and -M pc-i440fx-2.0.  */
             error_report("Warning: migration may not work.");
         }
-        g_array_set_size(tables->table_data, legacy_table_size);
+        g_array_set_size(tables_blob, legacy_table_size);
     } else {
         /* Make sure we have a buffer in case we need to resize the tables. */
-        if (tables->table_data->len > ACPI_BUILD_TABLE_SIZE / 2) {
+        if (tables_blob->len > ACPI_BUILD_TABLE_SIZE / 2) {
             /* As of QEMU 2.1, this fires with 160 VCPUs and 255 memory slots.  */
             error_report("Warning: ACPI tables are larger than 64k.");
             error_report("Warning: migration may not work.");
             error_report("Warning: please remove CPUs, NUMA nodes, "
                          "memory slots or PCI bridges.");
         }
-        acpi_align_size(tables->table_data, ACPI_BUILD_TABLE_SIZE);
+        acpi_align_size(tables_blob, ACPI_BUILD_TABLE_SIZE);
     }
 
     acpi_align_size(tables->linker, ACPI_BUILD_ALIGN_SIZE);
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 53/96] update-linux-headers.sh: s/__inline__/inline/
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (52 preceding siblings ...)
  2015-02-18 21:49 ` [Qemu-devel] [PULL 52/96] pc: acpi: use local var for accessing ACPI tables blob in acpi_build() Michael S. Tsirkin
@ 2015-02-18 21:49 ` Michael S. Tsirkin
  2015-02-18 21:49 ` [Qemu-devel] [PULL 54/96] virtio-serial-bus.c: drop virtio_ids.h Michael S. Tsirkin
                   ` (44 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Alexander Graf, Thomas Huth, dgilbert, Juan Quintela

Thomas Huth noticed that some linux headers
use __inline__, change to inline to be consistent
with the rest of QEMU.

Reported-by: Thomas Huth <thuth@linux.vnet.ibm.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 scripts/update-linux-headers.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers.sh
index 9680e27..f208ec9 100755
--- a/scripts/update-linux-headers.sh
+++ b/scripts/update-linux-headers.sh
@@ -53,6 +53,7 @@ cp_virtio() {
                 -e 's/<linux\/\([^>]*\)>/"standard-headers\/linux\/\1"/' \
                 -e 's/__bitwise__//' \
                 -e 's/__attribute__((packed))/QEMU_PACKED/' \
+                -e 's/__inline__/inline/' \
                 "$f" > "$to/$header";
         done
     fi
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 54/96] virtio-serial-bus.c: drop virtio_ids.h
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (53 preceding siblings ...)
  2015-02-18 21:49 ` [Qemu-devel] [PULL 53/96] update-linux-headers.sh: s/__inline__/inline/ Michael S. Tsirkin
@ 2015-02-18 21:49 ` Michael S. Tsirkin
  2015-02-18 21:49 ` [Qemu-devel] [PULL 55/96] standard-headers: include stdint.h Michael S. Tsirkin
                   ` (43 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Thomas Huth, Juan Quintela, dgilbert,
	Anthony Liguori, Amit Shah

virtio-serial.h pulls that in already.

Reported-by: Thomas Huth <thuth@linux.vnet.ibm.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/char/virtio-serial-bus.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index ba4cf2e..9a029d2 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -18,7 +18,6 @@
  * GNU GPL, version 2 or (at your option) any later version.
  */
 
-#include "standard-headers/linux/virtio_ids.h"
 #include "qemu/iov.h"
 #include "monitor/monitor.h"
 #include "qemu/queue.h"
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 55/96] standard-headers: include stdint.h
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (54 preceding siblings ...)
  2015-02-18 21:49 ` [Qemu-devel] [PULL 54/96] virtio-serial-bus.c: drop virtio_ids.h Michael S. Tsirkin
@ 2015-02-18 21:49 ` Michael S. Tsirkin
  2015-02-18 21:49 ` [Qemu-devel] [PULL 56/96] virtio_ring.h: s/__inline__/inline/ Michael S. Tsirkin
                   ` (42 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Thomas Huth, dgilbert, Juan Quintela

The importing script got it right already, I just forgot to re-run it.

Reported-by: Thomas Huth <thuth@linux.vnet.ibm.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/standard-headers/linux/types.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/standard-headers/linux/types.h b/include/standard-headers/linux/types.h
index 7d42ac6..0526c2b 100644
--- a/include/standard-headers/linux/types.h
+++ b/include/standard-headers/linux/types.h
@@ -1,2 +1,2 @@
-#include <inttypes.h>
+#include <stdint.h>
 #include "qemu/compiler.h"
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 56/96] virtio_ring.h: s/__inline__/inline/
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (55 preceding siblings ...)
  2015-02-18 21:49 ` [Qemu-devel] [PULL 55/96] standard-headers: include stdint.h Michael S. Tsirkin
@ 2015-02-18 21:49 ` Michael S. Tsirkin
  2015-02-18 21:49 ` [Qemu-devel] [PULL 57/96] acpi: introduce AML composer aml_append() Michael S. Tsirkin
                   ` (41 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Thomas Huth, dgilbert, Juan Quintela

Thomas Huth noticed that some linux headers
use __inline__, change to inline to be consistent
with the rest of QEMU.

Reported-by: Thomas Huth <thuth@linux.vnet.ibm.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/standard-headers/linux/virtio_ring.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/standard-headers/linux/virtio_ring.h b/include/standard-headers/linux/virtio_ring.h
index 2bd19a8..cc647d6 100644
--- a/include/standard-headers/linux/virtio_ring.h
+++ b/include/standard-headers/linux/virtio_ring.h
@@ -137,7 +137,7 @@ struct vring {
 #define vring_used_event(vr) ((vr)->avail->ring[(vr)->num])
 #define vring_avail_event(vr) (*(__virtio16 *)&(vr)->used->ring[(vr)->num])
 
-static __inline__ void vring_init(struct vring *vr, unsigned int num, void *p,
+static inline void vring_init(struct vring *vr, unsigned int num, void *p,
 			      unsigned long align)
 {
 	vr->num = num;
@@ -147,7 +147,7 @@ static __inline__ void vring_init(struct vring *vr, unsigned int num, void *p,
 		+ align-1) & ~(align - 1));
 }
 
-static __inline__ unsigned vring_size(unsigned int num, unsigned long align)
+static inline unsigned vring_size(unsigned int num, unsigned long align)
 {
 	return ((sizeof(struct vring_desc) * num + sizeof(__virtio16) * (3 + num)
 		 + align - 1) & ~(align - 1))
@@ -158,7 +158,7 @@ static __inline__ unsigned vring_size(unsigned int num, unsigned long align)
 /* Assuming a given event_idx value from the other size, if
  * we have just incremented index from old to new_idx,
  * should we trigger an event? */
-static __inline__ int vring_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old)
+static inline int vring_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old)
 {
 	/* Note: Xen has similar logic for notification hold-off
 	 * in include/xen/interface/io/ring.h with req_event and req_prod
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 57/96] acpi: introduce AML composer aml_append()
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (56 preceding siblings ...)
  2015-02-18 21:49 ` [Qemu-devel] [PULL 56/96] virtio_ring.h: s/__inline__/inline/ Michael S. Tsirkin
@ 2015-02-18 21:49 ` Michael S. Tsirkin
  2015-02-18 21:49 ` [Qemu-devel] [PULL 58/96] acpi: add aml_scope() term Michael S. Tsirkin
                   ` (40 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

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 <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h | 55 ++++++++++++++++++++++++++++++++
 hw/acpi/aml-build.c         | 78 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 133 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 199f003..1e1b03b 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -5,6 +5,61 @@
 #include <glib.h>
 #include "qemu/compiler.h"
 
+typedef enum {
+    AML_NO_OPCODE = 0,/* has only data */
+    AML_OPCODE,       /* has opcode optionally followed by data */
+    AML_PACKAGE,      /* has opcode and uses PkgLength for its length */
+    AML_EXT_PACKAGE,  /* ame as AML_PACKAGE but also has 'ExOpPrefix' */
+    AML_BUFFER,       /* data encoded as 'DefBuffer' */
+    AML_RES_TEMPLATE, /* encoded as ResourceTemplate macro */
+} AmlBlockFlags;
+
+struct Aml {
+    GArray *buf;
+
+    /*< private >*/
+    uint8_t op;
+    AmlBlockFlags block_flags;
+};
+typedef struct Aml Aml;
+
+/**
+ * init_aml_allocator:
+ *
+ * Called for initializing API allocator which allow to use
+ * AML API.
+ * Returns: toplevel container which accumulates all other
+ * AML elements for a table.
+ */
+Aml *init_aml_allocator(void);
+
+/**
+ * free_aml_allocator:
+ *
+ * Releases all elements used by AML API, frees associated memory
+ * and invalidates AML allocator. After this call @init_aml_allocator
+ * should be called again if AML API is to be used again.
+ */
+void free_aml_allocator(void);
+
+/**
+ * aml_append:
+ * @parent_ctx: context to which @child element is added
+ * @child: element that is copied into @parent_ctx context
+ *
+ * Joins Aml elements together and helps to construct AML tables
+ * Examle of usage:
+ *   Aml *table = aml_def_block("SSDT", ...);
+ *   Aml *sb = aml_scope("\_SB");
+ *   Aml *dev = aml_device("PCI0");
+ *
+ *   aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03")));
+ *   aml_append(sb, dev);
+ *   aml_append(table, sb);
+ */
+void aml_append(Aml *parent_ctx, Aml *child);
+
+/* other helpers */
 GArray *build_alloc_array(void);
 void build_free_array(GArray *array);
 void build_prepend_byte(GArray *array, uint8_t val);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index bcb288e..caf792b 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -25,6 +25,7 @@
 #include <stdbool.h>
 #include <string.h>
 #include "hw/acpi/aml-build.h"
+#include "qemu/bswap.h"
 
 GArray *build_alloc_array(void)
 {
@@ -257,3 +258,80 @@ 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_NO_OPCODE;
+    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(void)
+{
+    Aml *var;
+
+    assert(!alloc_list);
+    alloc_list = g_ptr_array_new_with_free_func(aml_free);
+    var = aml_alloc();
+    return var;
+}
+
+void free_aml_allocator(void)
+{
+    g_ptr_array_free(alloc_list, true);
+    alloc_list = 0;
+}
+
+/* pack data with DefBuffer encoding */
+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_OPCODE:
+        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 are treated as succeeded if checksum
+         * field is zero. [ACPI Spec 1.0b, 6.4.2.8 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_NO_OPCODE:
+        break;
+    default:
+        assert(0);
+        break;
+    }
+    build_append_array(parent_ctx->buf, child->buf);
+}
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 58/96] acpi: add aml_scope() term
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (57 preceding siblings ...)
  2015-02-18 21:49 ` [Qemu-devel] [PULL 57/96] acpi: introduce AML composer aml_append() Michael S. Tsirkin
@ 2015-02-18 21:49 ` Michael S. Tsirkin
  2015-02-18 21:49 ` [Qemu-devel] [PULL 59/96] pc: acpi-build: use aml_scope() for \_SB scope Michael S. Tsirkin
                   ` (39 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h |  3 +++
 hw/acpi/aml-build.c         | 20 ++++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 1e1b03b..05dd3fc 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -59,6 +59,9 @@ void free_aml_allocator(void);
  */
 void aml_append(Aml *parent_ctx, Aml *child);
 
+/* Block AML object primitives */
+Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
+
 /* other helpers */
 GArray *build_alloc_array(void);
 void build_free_array(GArray *array);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index caf792b..f891406 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -271,6 +271,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;
@@ -335,3 +344,14 @@ void aml_append(Aml *parent_ctx, Aml *child)
     }
     build_append_array(parent_ctx->buf, child->buf);
 }
+
+/* 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;
+}
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 59/96] pc: acpi-build: use aml_scope() for \_SB scope
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (58 preceding siblings ...)
  2015-02-18 21:49 ` [Qemu-devel] [PULL 58/96] acpi: add aml_scope() term Michael S. Tsirkin
@ 2015-02-18 21:49 ` Michael S. Tsirkin
  2015-02-18 21:49 ` [Qemu-devel] [PULL 60/96] acpi: add aml_device() term Michael S. Tsirkin
                   ` (38 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Anthony Liguori,
	Paolo Bonzini, Igor Mammedov, Richard Henderson

From: Igor Mammedov <imammedo@redhat.com>

prepares for incremental conversion of SSDT content to AML API

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/i386/acpi-build.c | 39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 5e4b333..c66fe56 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -923,17 +923,18 @@ build_ssdt(GArray *table_data, GArray *linker,
     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, *sb_scope;
     int i;
 
+    ssdt = init_aml_allocator();
     /* The current AML generator can cover the APIC ID range [0..255],
      * inclusive, for VCPU hotplug. */
     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));
+    ssdt_ptr = acpi_data_push(ssdt->buf, sizeof(ssdp_misc_aml));
     memcpy(ssdt_ptr, ssdp_misc_aml, sizeof(ssdp_misc_aml));
     if (pm->s3_disabled) {
         ssdt_ptr[acpi_s3_name[0]] = 'X';
@@ -953,15 +954,11 @@ build_ssdt(GArray *table_data, GArray *linker,
     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);
@@ -973,11 +970,12 @@ build_ssdt(GArray *table_data, GArray *linker,
          *   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();
@@ -1002,7 +1000,7 @@ build_ssdt(GArray *table_data, GArray *linker,
             }
 
             build_package(package, op);
-            build_append_array(sb_scope, package);
+            build_append_array(sb_scope->buf, package);
             build_free_array(package);
         }
 
@@ -1011,7 +1009,7 @@ build_ssdt(GArray *table_data, GArray *linker,
             /* 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);
@@ -1022,7 +1020,7 @@ build_ssdt(GArray *table_data, GArray *linker,
             /* 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);
         }
@@ -1046,17 +1044,18 @@ build_ssdt(GArray *table_data, GArray *linker,
                                              build_pci_bus_end, &hotplug_state);
             }
 
-            build_append_array(sb_scope, hotplug_state.device_table);
+            build_append_array(sb_scope->buf, hotplug_state.device_table);
             build_pci_bus_state_cleanup(&hotplug_state);
         }
-        build_package(sb_scope, op);
-        build_append_array(table_data, sb_scope);
-        build_free_array(sb_scope);
+        aml_append(ssdt, sb_scope);
     }
 
+    /* copy AML table into ACPI tables blob and patch header there */
+    g_array_append_vals(table_data, ssdt->buf->data, ssdt->buf->len);
     build_header(linker, table_data,
-                 (void *)(table_data->data + ssdt_start),
-                 "SSDT", table_data->len - ssdt_start, 1);
+        (void *)(table_data->data + table_data->len - ssdt->buf->len),
+        "SSDT", ssdt->buf->len, 1);
+    free_aml_allocator();
 }
 
 static void
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 60/96] acpi: add aml_device() term
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (59 preceding siblings ...)
  2015-02-18 21:49 ` [Qemu-devel] [PULL 59/96] pc: acpi-build: use aml_scope() for \_SB scope Michael S. Tsirkin
@ 2015-02-18 21:49 ` Michael S. Tsirkin
  2015-02-18 21:50 ` [Qemu-devel] [PULL 61/96] acpi: add aml_method() term Michael S. Tsirkin
                   ` (37 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h |  1 +
 hw/acpi/aml-build.c         | 11 +++++++++++
 2 files changed, 12 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 05dd3fc..004fa05 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -61,6 +61,7 @@ void aml_append(Aml *parent_ctx, Aml *child);
 
 /* Block AML object primitives */
 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);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index f891406..c955d66 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -355,3 +355,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;
+}
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 61/96] acpi: add aml_method() term
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (60 preceding siblings ...)
  2015-02-18 21:49 ` [Qemu-devel] [PULL 60/96] acpi: add aml_device() term Michael S. Tsirkin
@ 2015-02-18 21:50 ` Michael S. Tsirkin
  2015-02-18 21:50 ` [Qemu-devel] [PULL 62/96] acpi: add aml_if() term Michael S. Tsirkin
                   ` (36 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h | 1 +
 hw/acpi/aml-build.c         | 9 +++++++++
 2 files changed, 10 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 004fa05..97e210a 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -62,6 +62,7 @@ void aml_append(Aml *parent_ctx, Aml *child);
 /* Block AML object primitives */
 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);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index c955d66..4e0685e 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -356,6 +356,15 @@ Aml *aml_scope(const char *name_format, ...)
     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.2 Named Objects Encoding: DefDevice */
 Aml *aml_device(const char *name_format, ...)
 {
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 62/96] acpi: add aml_if() term
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (61 preceding siblings ...)
  2015-02-18 21:50 ` [Qemu-devel] [PULL 61/96] acpi: add aml_method() term Michael S. Tsirkin
@ 2015-02-18 21:50 ` Michael S. Tsirkin
  2015-02-18 21:50 ` [Qemu-devel] [PULL 63/96] acpi: add aml_name() & aml_name_decl() term Michael S. Tsirkin
                   ` (35 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h | 1 +
 hw/acpi/aml-build.c         | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 97e210a..13cc9e9 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -63,6 +63,7 @@ void aml_append(Aml *parent_ctx, Aml *child);
 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);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 4e0685e..d19d1fb 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -356,6 +356,14 @@ Aml *aml_scope(const char *name_format, ...)
     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)
 {
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 63/96] acpi: add aml_name() & aml_name_decl() term
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (62 preceding siblings ...)
  2015-02-18 21:50 ` [Qemu-devel] [PULL 62/96] acpi: add aml_if() term Michael S. Tsirkin
@ 2015-02-18 21:50 ` Michael S. Tsirkin
  2015-02-18 21:50 ` [Qemu-devel] [PULL 64/96] acpi: add aml_int() term Michael S. Tsirkin
                   ` (34 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h |  4 ++++
 hw/acpi/aml-build.c         | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 13cc9e9..946aece 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -59,6 +59,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index d19d1fb..cb00a1b 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -271,6 +271,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_OPCODE;
+    return var;
+}
+
 static Aml *aml_bundle(uint8_t op, AmlBlockFlags flags)
 {
     Aml *var = aml_alloc();
@@ -356,6 +365,29 @@ Aml *aml_scope(const char *name_format, ...)
     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)
 {
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 64/96] acpi: add aml_int() term
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (63 preceding siblings ...)
  2015-02-18 21:50 ` [Qemu-devel] [PULL 63/96] acpi: add aml_name() & aml_name_decl() term Michael S. Tsirkin
@ 2015-02-18 21:50 ` Michael S. Tsirkin
  2015-02-18 21:50 ` [Qemu-devel] [PULL 65/96] acpi: add aml_return() term Michael S. Tsirkin
                   ` (33 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:50 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Anthony Liguori,
	Paolo Bonzini, Igor Mammedov, Richard Henderson

From: Igor Mammedov <imammedo@redhat.com>

* factor out ACPI const int packing out of build_append_value()
  and rename build_append_value() to build_append_int_noprefix()
  it will be reused for adding a plain integer value into AML.
  will be used by is aml_processor() and CRS macro helpers
* extend build_append_int{_noprefix}() to support 64-bit values
  it will be used PCI for generating 64bit _CRS entries

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h |  4 ++--
 hw/acpi/aml-build.c         | 43 ++++++++++++++++++++++---------------------
 hw/i386/acpi-build.c        | 12 ++++++------
 3 files changed, 30 insertions(+), 29 deletions(-)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 946aece..a385132 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -62,6 +62,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
@@ -81,8 +82,7 @@ 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_int(GArray *table, uint64_t value);
 void build_extop_package(GArray *package, uint8_t op);
 
 #endif
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index cb00a1b..aaa80e5 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -218,44 +218,34 @@ 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)
+static void build_append_int_noprefix(GArray *table, uint64_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;
     }
 }
 
-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 */
     } else if (value == 0x01) {
         build_append_byte(table, 0x01); /* OneOp */
     } else if (value <= 0xFF) {
-        build_append_value(table, value, 1);
+        build_append_byte(table, 0x0A); /* BytePrefix */
+        build_append_int_noprefix(table, value, 1);
     } else if (value <= 0xFFFF) {
-        build_append_value(table, value, 2);
+        build_append_byte(table, 0x0B); /* WordPrefix */
+        build_append_int_noprefix(table, value, 2);
+    } else if (value <= 0xFFFFFFFF) {
+        build_append_byte(table, 0x0C); /* DWordPrefix */
+        build_append_int_noprefix(table, value, 4);
     } else {
-        build_append_value(table, value, 4);
+        build_append_byte(table, 0x0E); /* QWordPrefix */
+        build_append_int_noprefix(table, value, 8);
     }
 }
 
@@ -366,6 +356,17 @@ Aml *aml_scope(const char *name_format, ...)
 }
 
 /*
+ * 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/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index c66fe56..bf34415 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -304,14 +304,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 */
@@ -580,7 +580,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);
     }
 
@@ -715,11 +715,11 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)
                              bus->parent_dev->devfn);
         build_append_byte(bus_table, 0x08); /* NameOp */
         build_append_namestring(bus_table, "_SUN");
-        build_append_value(bus_table, PCI_SLOT(bus->parent_dev->devfn), 1);
+        build_append_int(bus_table, PCI_SLOT(bus->parent_dev->devfn));
         build_append_byte(bus_table, 0x08); /* NameOp */
         build_append_namestring(bus_table, "_ADR");
-        build_append_value(bus_table, (PCI_SLOT(bus->parent_dev->devfn) << 16) |
-                           PCI_FUNC(bus->parent_dev->devfn), 4);
+        build_append_int(bus_table, (PCI_SLOT(bus->parent_dev->devfn) << 16) |
+                           PCI_FUNC(bus->parent_dev->devfn));
     } else {
         op = 0x10; /* ScopeOp */;
         build_append_namestring(bus_table, "PCI0");
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 65/96] acpi: add aml_return() term
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (64 preceding siblings ...)
  2015-02-18 21:50 ` [Qemu-devel] [PULL 64/96] acpi: add aml_int() term Michael S. Tsirkin
@ 2015-02-18 21:50 ` Michael S. Tsirkin
  2015-02-18 21:50 ` [Qemu-devel] [PULL 66/96] acpi: add aml_arg() term Michael S. Tsirkin
                   ` (32 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h | 1 +
 hw/acpi/aml-build.c         | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index a385132..e7fa977 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -62,6 +62,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 */
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index aaa80e5..8207d9c 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -355,6 +355,14 @@ Aml *aml_scope(const char *name_format, ...)
     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
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 66/96] acpi: add aml_arg() term
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (65 preceding siblings ...)
  2015-02-18 21:50 ` [Qemu-devel] [PULL 65/96] acpi: add aml_return() term Michael S. Tsirkin
@ 2015-02-18 21:50 ` Michael S. Tsirkin
  2015-02-18 21:50 ` [Qemu-devel] [PULL 67/96] acpi: add aml_store() term Michael S. Tsirkin
                   ` (31 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h |  1 +
 hw/acpi/aml-build.c         | 11 +++++++++++
 2 files changed, 12 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index e7fa977..63e9754 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -64,6 +64,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 8207d9c..99d213c 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -397,6 +397,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)
 {
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 67/96] acpi: add aml_store() term
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (66 preceding siblings ...)
  2015-02-18 21:50 ` [Qemu-devel] [PULL 66/96] acpi: add aml_arg() term Michael S. Tsirkin
@ 2015-02-18 21:50 ` Michael S. Tsirkin
  2015-02-18 21:50 ` [Qemu-devel] [PULL 68/96] acpi: add aml_and() term Michael S. Tsirkin
                   ` (30 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h | 1 +
 hw/acpi/aml-build.c         | 9 +++++++++
 2 files changed, 10 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 63e9754..6ad76dd 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -65,6 +65,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 99d213c..57e3176 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -408,6 +408,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)
 {
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 68/96] acpi: add aml_and() term
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (67 preceding siblings ...)
  2015-02-18 21:50 ` [Qemu-devel] [PULL 67/96] acpi: add aml_store() term Michael S. Tsirkin
@ 2015-02-18 21:50 ` Michael S. Tsirkin
  2015-02-18 21:50 ` [Qemu-devel] [PULL 69/96] acpi: add aml_notify() term Michael S. Tsirkin
                   ` (29 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h |  1 +
 hw/acpi/aml-build.c         | 10 ++++++++++
 2 files changed, 11 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 6ad76dd..2fca361 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -66,6 +66,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 57e3176..bb1fbbc 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -417,6 +417,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)
 {
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 69/96] acpi: add aml_notify() term
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (68 preceding siblings ...)
  2015-02-18 21:50 ` [Qemu-devel] [PULL 68/96] acpi: add aml_and() term Michael S. Tsirkin
@ 2015-02-18 21:50 ` Michael S. Tsirkin
  2015-02-18 21:50 ` [Qemu-devel] [PULL 70/96] acpi: add aml_call1(), aml_call2(), aml_call3(), aml_call4() helpers Michael S. Tsirkin
                   ` (28 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h | 1 +
 hw/acpi/aml-build.c         | 9 +++++++++
 2 files changed, 10 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 2fca361..cbef236 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -67,6 +67,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index bb1fbbc..3e187fa 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -427,6 +427,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)
 {
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 70/96] acpi: add aml_call1(), aml_call2(), aml_call3(), aml_call4() helpers
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (69 preceding siblings ...)
  2015-02-18 21:50 ` [Qemu-devel] [PULL 69/96] acpi: add aml_notify() term Michael S. Tsirkin
@ 2015-02-18 21:50 ` Michael S. Tsirkin
  2015-02-18 21:50 ` [Qemu-devel] [PULL 71/96] acpi: add aml_package() term Michael S. Tsirkin
                   ` (27 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h |  4 ++++
 hw/acpi/aml-build.c         | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index cbef236..5f00b07 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -68,6 +68,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 3e187fa..18427b6 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -436,6 +436,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)
 {
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 71/96] acpi: add aml_package() term
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (70 preceding siblings ...)
  2015-02-18 21:50 ` [Qemu-devel] [PULL 70/96] acpi: add aml_call1(), aml_call2(), aml_call3(), aml_call4() helpers Michael S. Tsirkin
@ 2015-02-18 21:50 ` Michael S. Tsirkin
  2015-02-18 21:50 ` [Qemu-devel] [PULL 72/96] pc: acpi-build: generate _S[345] packages dynamically Michael S. Tsirkin
                   ` (26 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h | 1 +
 hw/acpi/aml-build.c         | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 5f00b07..92097b5 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -78,6 +78,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);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 18427b6..fdeeacc 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -505,3 +505,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;
+}
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 72/96] pc: acpi-build: generate _S[345] packages dynamically
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (71 preceding siblings ...)
  2015-02-18 21:50 ` [Qemu-devel] [PULL 71/96] acpi: add aml_package() term Michael S. Tsirkin
@ 2015-02-18 21:50 ` Michael S. Tsirkin
  2015-02-18 21:51 ` [Qemu-devel] [PULL 73/96] acpi: add aml_buffer() term Michael S. Tsirkin
                   ` (25 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:50 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Anthony Liguori,
	Paolo Bonzini, Igor Mammedov, Richard Henderson

From: Igor Mammedov <imammedo@redhat.com>

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 <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/i386/acpi-build.c  | 40 ++++++++++++++++++++++++++++++----------
 hw/i386/ssdt-misc.dsl | 33 ---------------------------------
 2 files changed, 30 insertions(+), 43 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index bf34415..4536fba 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -924,7 +924,7 @@ build_ssdt(GArray *table_data, GArray *linker,
     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;
 
     ssdt = init_aml_allocator();
@@ -936,15 +936,6 @@ build_ssdt(GArray *table_data, GArray *linker,
     /* Copy header and patch values in the S3_ / S4_ / S5_ packages */
     ssdt_ptr = acpi_data_push(ssdt->buf, sizeof(ssdp_misc_aml));
     memcpy(ssdt_ptr, ssdp_misc_aml, sizeof(ssdp_misc_aml));
-    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] = ssdt_ptr[acpi_s4_pkg[0] + 3] =
-            pm->s4_val;
-    }
 
     patch_pci_windows(pci, ssdt_ptr, sizeof(ssdp_misc_aml));
 
@@ -954,6 +945,35 @@ build_ssdt(GArray *table_data, GArray *linker,
     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(1)); /* PM1b_CNT.SLP_TYP, FIXME: 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 */
+        /* PM1b_CNT.SLP_TYP, FIXME: not impl. */
+        aml_append(pkg, aml_int(pm->s4_val));
+        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 1e3baae..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 */
-            One,  /* PM1b_CNT.SLP_TYP */
-            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 */
-            0x2,  /* PM1b_CNT.SLP_TYP */
-            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)
 
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 73/96] acpi: add aml_buffer() term
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (72 preceding siblings ...)
  2015-02-18 21:50 ` [Qemu-devel] [PULL 72/96] pc: acpi-build: generate _S[345] packages dynamically Michael S. Tsirkin
@ 2015-02-18 21:51 ` Michael S. Tsirkin
  2015-02-18 21:51 ` [Qemu-devel] [PULL 74/96] acpi: add aml_resource_template() helper Michael S. Tsirkin
                   ` (24 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h | 1 +
 hw/acpi/aml-build.c         | 7 +++++++
 2 files changed, 8 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 92097b5..5fe66c6 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -79,6 +79,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);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index fdeeacc..98b1540 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -506,6 +506,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)
 {
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 74/96] acpi: add aml_resource_template() helper
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (73 preceding siblings ...)
  2015-02-18 21:51 ` [Qemu-devel] [PULL 73/96] acpi: add aml_buffer() term Michael S. Tsirkin
@ 2015-02-18 21:51 ` Michael S. Tsirkin
  2015-02-18 21:51 ` [Qemu-devel] [PULL 75/96] acpi: add aml_io() helper Michael S. Tsirkin
                   ` (23 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h | 1 +
 hw/acpi/aml-build.c         | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 5fe66c6..2810b4c 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -80,6 +80,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);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 98b1540..070ca81 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -506,6 +506,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)
 {
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 75/96] acpi: add aml_io() helper
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (74 preceding siblings ...)
  2015-02-18 21:51 ` [Qemu-devel] [PULL 74/96] acpi: add aml_resource_template() helper Michael S. Tsirkin
@ 2015-02-18 21:51 ` Michael S. Tsirkin
  2015-02-18 21:51 ` [Qemu-devel] [PULL 76/96] acpi: include PkgLength size only when requested Michael S. Tsirkin
                   ` (22 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h |  7 +++++++
 hw/acpi/aml-build.c         | 16 ++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 2810b4c..298e2ef 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -23,6 +23,11 @@ struct Aml {
 };
 typedef struct Aml Aml;
 
+typedef enum {
+    aml_decode10 = 0,
+    aml_decode16 = 1,
+} AmlIODecode;
+
 /**
  * init_aml_allocator:
  *
@@ -72,6 +77,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 070ca81..d7edda1 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -478,6 +478,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)
 {
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 76/96] acpi: include PkgLength size only when requested
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (75 preceding siblings ...)
  2015-02-18 21:51 ` [Qemu-devel] [PULL 75/96] acpi: add aml_io() helper Michael S. Tsirkin
@ 2015-02-18 21:51 ` Michael S. Tsirkin
  2015-02-18 21:51 ` [Qemu-devel] [PULL 77/96] acpi: add aml_operation_region() term Michael S. Tsirkin
                   ` (21 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

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 <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h |  3 ++-
 hw/acpi/aml-build.c         | 20 +++++++++++++++-----
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 298e2ef..b7f491e 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -99,7 +99,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_int(GArray *table, uint64_t value);
 void build_extop_package(GArray *package, uint8_t op);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index d7edda1..cc883cc 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -158,10 +158,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)) {
@@ -174,8 +174,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:
@@ -208,7 +218,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);
 }
 
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 77/96] acpi: add aml_operation_region() term
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (76 preceding siblings ...)
  2015-02-18 21:51 ` [Qemu-devel] [PULL 76/96] acpi: include PkgLength size only when requested Michael S. Tsirkin
@ 2015-02-18 21:51 ` Michael S. Tsirkin
  2015-02-18 21:51 ` [Qemu-devel] [PULL 78/96] acpi: add aml_field() & aml_named_field() terms Michael S. Tsirkin
                   ` (20 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h |  7 +++++++
 hw/acpi/aml-build.c         | 14 ++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index b7f491e..57926e5 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -28,6 +28,11 @@ typedef enum {
     aml_decode16 = 1,
 } AmlIODecode;
 
+typedef enum {
+    aml_system_memory = 0x00,
+    aml_system_io = 0x01,
+} AmlRegionSpace;
+
 /**
  * init_aml_allocator:
  *
@@ -79,6 +84,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index cc883cc..d72d5b4 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -554,3 +554,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;
+}
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 78/96] acpi: add aml_field() & aml_named_field() terms
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (77 preceding siblings ...)
  2015-02-18 21:51 ` [Qemu-devel] [PULL 77/96] acpi: add aml_operation_region() term Michael S. Tsirkin
@ 2015-02-18 21:51 ` Michael S. Tsirkin
  2015-02-18 21:51 ` [Qemu-devel] [PULL 79/96] acpi: add aml_local() term Michael S. Tsirkin
                   ` (19 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h |  6 ++++++
 hw/acpi/aml-build.c         | 28 ++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 57926e5..2bb5f39 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -29,6 +29,10 @@ typedef enum {
 } AmlIODecode;
 
 typedef enum {
+    aml_byte_acc = 1,
+} AmlFieldFlags;
+
+typedef enum {
     aml_system_memory = 0x00,
     aml_system_io = 0x01,
 } AmlRegionSpace;
@@ -86,6 +90,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
@@ -95,6 +100,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);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index d72d5b4..b91141e 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -216,6 +216,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);
@@ -568,3 +578,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;
+}
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 79/96] acpi: add aml_local() term
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (78 preceding siblings ...)
  2015-02-18 21:51 ` [Qemu-devel] [PULL 78/96] acpi: add aml_field() & aml_named_field() terms Michael S. Tsirkin
@ 2015-02-18 21:51 ` Michael S. Tsirkin
  2015-02-18 21:51 ` [Qemu-devel] [PULL 80/96] acpi: add aml_string() term Michael S. Tsirkin
                   ` (18 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h |  1 +
 hw/acpi/aml-build.c         | 11 +++++++++++
 2 files changed, 12 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 2bb5f39..de081d6 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -91,6 +91,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index b91141e..fabd0ad 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -596,3 +596,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(num <= 7);
+    var = aml_opcode(op);
+    return var;
+}
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 80/96] acpi: add aml_string() term
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (79 preceding siblings ...)
  2015-02-18 21:51 ` [Qemu-devel] [PULL 79/96] acpi: add aml_local() term Michael S. Tsirkin
@ 2015-02-18 21:51 ` Michael S. Tsirkin
  2015-02-18 21:51 ` [Qemu-devel] [PULL 81/96] pc: acpi-build: generate pvpanic device description dynamically Michael S. Tsirkin
                   ` (17 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h |  1 +
 hw/acpi/aml-build.c         | 25 +++++++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index de081d6..b1eab3c 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -92,6 +92,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index fabd0ad..57a65dd 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -597,6 +597,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)
 {
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 81/96] pc: acpi-build: generate pvpanic device description dynamically
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (80 preceding siblings ...)
  2015-02-18 21:51 ` [Qemu-devel] [PULL 80/96] acpi: add aml_string() term Michael S. Tsirkin
@ 2015-02-18 21:51 ` Michael S. Tsirkin
  2015-02-18 21:51 ` [Qemu-devel] [PULL 82/96] acpi: add aml_varpackage() term Michael S. Tsirkin
                   ` (16 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Anthony Liguori,
	Paolo Bonzini, Igor Mammedov, Richard Henderson

From: Igor Mammedov <imammedo@redhat.com>

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 <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 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 4536fba..2c581ef 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -924,7 +924,7 @@ build_ssdt(GArray *table_data, GArray *linker,
     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;
 
     ssdt = init_aml_allocator();
@@ -940,9 +940,6 @@ build_ssdt(GArray *table_data, GArray *linker,
     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 */
@@ -974,6 +971,37 @@ build_ssdt(GArray *table_data, GArray *linker,
     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, 0xFFFF)
-            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)
-            }
-        }
-    }
 }
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 82/96] acpi: add aml_varpackage() term
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (81 preceding siblings ...)
  2015-02-18 21:51 ` [Qemu-devel] [PULL 81/96] pc: acpi-build: generate pvpanic device description dynamically Michael S. Tsirkin
@ 2015-02-18 21:51 ` Michael S. Tsirkin
  2015-02-18 21:51 ` [Qemu-devel] [PULL 83/96] acpi: add aml_equal() term Michael S. Tsirkin
                   ` (15 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h | 1 +
 hw/acpi/aml-build.c         | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index b1eab3c..7f3886f 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -103,6 +103,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);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 57a65dd..36aafe4 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -632,3 +632,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;
+}
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 83/96] acpi: add aml_equal() term
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (82 preceding siblings ...)
  2015-02-18 21:51 ` [Qemu-devel] [PULL 82/96] acpi: add aml_varpackage() term Michael S. Tsirkin
@ 2015-02-18 21:51 ` Michael S. Tsirkin
  2015-02-18 21:51 ` [Qemu-devel] [PULL 84/96] acpi: add aml_processor() term Michael S. Tsirkin
                   ` (14 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h |  1 +
 hw/acpi/aml-build.c         | 10 ++++++++++
 2 files changed, 11 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 7f3886f..5e2b434 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -93,6 +93,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 36aafe4..97b027c 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -514,6 +514,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)
 {
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 84/96] acpi: add aml_processor() term
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (83 preceding siblings ...)
  2015-02-18 21:51 ` [Qemu-devel] [PULL 83/96] acpi: add aml_equal() term Michael S. Tsirkin
@ 2015-02-18 21:51 ` Michael S. Tsirkin
  2015-02-18 21:52 ` [Qemu-devel] [PULL 85/96] acpi: add aml_eisaid() term Michael S. Tsirkin
                   ` (13 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h |  2 ++
 hw/acpi/aml-build.c         | 15 +++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 5e2b434..58bbbfe 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -94,6 +94,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 97b027c..9081b49 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -650,3 +650,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_int_noprefix(var->buf, pblk_addr, sizeof(pblk_addr));
+    build_append_byte(var->buf, pblk_len); /* PblkLen */
+    return var;
+}
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 85/96] acpi: add aml_eisaid() term
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (84 preceding siblings ...)
  2015-02-18 21:51 ` [Qemu-devel] [PULL 84/96] acpi: add aml_processor() term Michael S. Tsirkin
@ 2015-02-18 21:52 ` Michael S. Tsirkin
  2015-02-18 21:52 ` [Qemu-devel] [PULL 86/96] pc: acpi-build: drop template patching and CPU hotplug objects dynamically Michael S. Tsirkin
                   ` (12 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h |  1 +
 hw/acpi/aml-build.c         | 29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 58bbbfe..bf94155 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -96,6 +96,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_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 9081b49..eeb006f 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -665,3 +665,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_int_noprefix(var->buf, bswap32(id), sizeof(id));
+    return var;
+}
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 86/96] pc: acpi-build: drop template patching and CPU hotplug objects dynamically
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (85 preceding siblings ...)
  2015-02-18 21:52 ` [Qemu-devel] [PULL 85/96] acpi: add aml_eisaid() term Michael S. Tsirkin
@ 2015-02-18 21:52 ` Michael S. Tsirkin
  2015-02-18 21:52 ` [Qemu-devel] [PULL 87/96] pc: acpi-build: create CPU hotplug IO region dynamically Michael S. Tsirkin
                   ` (11 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:52 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Anthony Liguori,
	Paolo Bonzini, Igor Mammedov, Richard Henderson

From: Igor Mammedov <imammedo@redhat.com>

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 <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/i386/acpi-build.c  | 88 ++++++++++++++++++++++++---------------------------
 hw/i386/Makefile.objs |  7 ++--
 hw/i386/ssdt-proc.dsl | 63 ------------------------------------
 3 files changed, 45 insertions(+), 113 deletions(-)
 delete mode 100644 hw/i386/ssdt-proc.dsl

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 2c581ef..c6910da 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -522,15 +522,6 @@ static inline char acpi_get_hex(uint32_t val)
     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)
-
 /* 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)
@@ -924,7 +915,7 @@ build_ssdt(GArray *table_data, GArray *linker,
     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;
 
     ssdt = init_aml_allocator();
@@ -1006,51 +997,54 @@ build_ssdt(GArray *table_data, GArray *linker,
     {
         /* 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 : 0x00;
-                build_append_byte(package, b);
-            }
+        method = aml_method("NTFY", 2);
+        for (i = 0; i < acpi_cpus; i++) {
+            ifctx = aml_if(aml_equal(aml_arg(0), aml_int(i)));
+            aml_append(ifctx,
+                aml_notify(aml_name("CP%.02X", i), aml_arg(1))
+            );
+            aml_append(method, ifctx);
+        }
+        aml_append(sb_scope, method);
+
+        /* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })"
+         *
+         * Note: The ability to create variable-sized packages was first
+         * ntroduced in ACPI 2.0. ACPI 1.0 only allowed fixed-size packages
+         * ith up to 255 elements. Windows guests up to win2k8 fail when
+         * VarPackageOp is used.
+         */
+        pkg = acpi_cpus <= 255 ? aml_package(acpi_cpus) :
+                                 aml_varpackage(acpi_cpus);
 
-            build_package(package, op);
-            build_append_array(sb_scope->buf, package);
-            build_free_array(package);
+        for (i = 0; i < acpi_cpus; i++) {
+            uint8_t b = test_bit(i, cpu->found_cpus) ? 0x01 : 0x00;
+            aml_append(pkg, aml_int(b));
         }
+        aml_append(sb_scope, aml_name_decl("CPON", pkg));
 
         if (nr_mem) {
             assert(nr_mem <= ACPI_MAX_RAM_SLOTS);
diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index 2b678ef..c9af7ba 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -7,10 +7,11 @@ 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-build.o: hw/i386/acpi-build.c \
 	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-pcihp.hex \
+	hw/i386/ssdt-misc.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/ssdt-proc.dsl b/hw/i386/ssdt-proc.dsl
deleted file mode 100644
index 8229bfd..0000000
--- a/hw/i386/ssdt-proc.dsl
+++ /dev/null
@@ -1,63 +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 <http://www.gnu.org/licenses/>.
- */
-
-/* This file is the basis for the ssdt table generated in src/acpi.c.
- * It defines the contents of the per-cpu Processor() object.  At
- * runtime, a dynamically generated SSDT will contain one copy of this
- * AML snippet for every possible cpu in the system.  The objects will
- * be placed in the \_SB_ namespace.
- *
- * In addition to the aml code generated from this file, the
- * src/acpi.c file creates a NTFY method with an entry for each cpu:
- *     Method(NTFY, 2) {
- *         If (LEqual(Arg0, 0x00)) { Notify(CP00, Arg1) }
- *         If (LEqual(Arg0, 0x01)) { Notify(CP01, Arg1) }
- *         ...
- *     }
- * and a CPON array with the list of active and inactive cpus:
- *     Name(CPON, Package() { One, One, ..., Zero, Zero, ... })
- */
-
-ACPI_EXTRACT_ALL_CODE ssdp_proc_aml
-
-DefinitionBlock ("ssdt-proc.aml", "SSDT", 0x01, "BXPC", "BXSSDT", 0x1)
-{
-    ACPI_EXTRACT_PROCESSOR_START ssdt_proc_start
-    ACPI_EXTRACT_PROCESSOR_END ssdt_proc_end
-    ACPI_EXTRACT_PROCESSOR_STRING ssdt_proc_name
-    Processor(CPAA, 0xAA, 0x00000000, 0x0) {
-        ACPI_EXTRACT_NAME_BYTE_CONST ssdt_proc_id
-        Name(ID, 0xAA)
-/*
- * The src/acpi.c code requires the above ACP_EXTRACT tags so that it can update
- * CPAA and 0xAA with the appropriate CPU id (see
- * SD_OFFSET_CPUHEX/CPUID1/CPUID2).  Don't change the above without
- * also updating the C code.
- */
-        Name(_HID, "ACPI0007")
-        External(CPMA, MethodObj)
-        External(CPST, MethodObj)
-        External(CPEJ, MethodObj)
-        Method(_MAT, 0) {
-            Return (CPMA(ID))
-        }
-        Method(_STA, 0) {
-            Return (CPST(ID))
-        }
-        Method(_EJ0, 1, NotSerialized) {
-            CPEJ(ID, Arg0)
-        }
-    }
-}
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 87/96] pc: acpi-build: create CPU hotplug IO region dynamically
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (86 preceding siblings ...)
  2015-02-18 21:52 ` [Qemu-devel] [PULL 86/96] pc: acpi-build: drop template patching and CPU hotplug objects dynamically Michael S. Tsirkin
@ 2015-02-18 21:52 ` Michael S. Tsirkin
  2015-02-18 21:52 ` [Qemu-devel] [PULL 88/96] acpi: add aml_reserved_field() term Michael S. Tsirkin
                   ` (10 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:52 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Anthony Liguori,
	Paolo Bonzini, Igor Mammedov, Richard Henderson

From: Igor Mammedov <imammedo@redhat.com>

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 <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/pc-hotplug.h      |  1 +
 hw/i386/acpi-build.c              | 27 +++++++++++++++++++++++++++
 hw/i386/acpi-dsdt-cpu-hotplug.dsl | 17 +----------------
 3 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/include/hw/acpi/pc-hotplug.h b/include/hw/acpi/pc-hotplug.h
index b9db295..efa6ed7 100644
--- a/include/hw/acpi/pc-hotplug.h
+++ b/include/hw/acpi/pc-hotplug.h
@@ -28,6 +28,7 @@
 
 #define ICH9_CPU_HOTPLUG_IO_BASE 0x0CD8
 #define PIIX4_CPU_HOTPLUG_IO_BASE 0xaf00
+#define CPU_HOTPLUG_RESOURCE_DEVICE PRES
 
 #define ACPI_MEMORY_HOTPLUG_IO_LEN 24
 #define ACPI_MEMORY_HOTPLUG_BASE 0x0a00
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index c6910da..4f1c251 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 {
@@ -176,12 +178,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) {
@@ -995,6 +1000,28 @@ build_ssdt(GArray *table_data, GArray *linker,
 
     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 */
-    }
 }
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 88/96] acpi: add aml_reserved_field() term
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (87 preceding siblings ...)
  2015-02-18 21:52 ` [Qemu-devel] [PULL 87/96] pc: acpi-build: create CPU hotplug IO region dynamically Michael S. Tsirkin
@ 2015-02-18 21:52 ` Michael S. Tsirkin
  2015-02-18 21:52 ` [Qemu-devel] [PULL 89/96] pc: acpi-build: drop template patching and memory hotplug objects dynamically Michael S. Tsirkin
                   ` (9 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h |  6 ++++++
 hw/acpi/aml-build.c         | 10 ++++++++++
 2 files changed, 16 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index bf94155..ea3ece3 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -29,7 +29,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 {
@@ -91,6 +96,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);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index eeb006f..9d9b978 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -598,6 +598,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)
 {
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 89/96] pc: acpi-build: drop template patching and memory hotplug objects dynamically
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (88 preceding siblings ...)
  2015-02-18 21:52 ` [Qemu-devel] [PULL 88/96] acpi: add aml_reserved_field() term Michael S. Tsirkin
@ 2015-02-18 21:52 ` Michael S. Tsirkin
  2015-02-18 21:52 ` [Qemu-devel] [PULL 90/96] pc: acpi-build: create memory hotplug IO region dynamically Michael S. Tsirkin
                   ` (8 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:52 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Anthony Liguori,
	Paolo Bonzini, Igor Mammedov, Richard Henderson

From: Igor Mammedov <imammedo@redhat.com>

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 <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/i386/acpi-build.c  | 112 +++++++++++++++++++++-----------------------------
 hw/i386/Makefile.objs |   1 -
 hw/i386/ssdt-mem.dsl  |  77 ----------------------------------
 3 files changed, 46 insertions(+), 144 deletions(-)
 delete mode 100644 hw/i386/ssdt-mem.dsl

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 4f1c251..377dd72 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -307,28 +307,6 @@ static void build_append_and_cleanup_method(GArray *device, GArray *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 */
 
@@ -550,14 +528,6 @@ static inline char acpi_get_hex(uint32_t val)
 #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 */
-#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
 
@@ -565,24 +535,6 @@ static inline char acpi_get_hex(uint32_t val)
 #include "hw/i386/ssdt-pcihp.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);
-}
-
 static void patch_pcihp(int slot, uint8_t *ssdt_ptr)
 {
     unsigned devfn = PCI_DEVFN(slot, 0);
@@ -1073,27 +1025,55 @@ build_ssdt(GArray *table_data, GArray *linker,
         }
         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);
+
+        for (i = 0; i < nr_mem; i++) {
+            #define BASEPATH "\\_SB.PCI0." stringify(MEMORY_HOTPLUG_DEVICE) "."
+            const char *s;
+
+            dev = aml_device("MP%02X", i);
+            aml_append(dev, aml_name_decl("_UID", aml_string("0x%02X", i)));
+            aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0C80")));
 
-            /* build Method(MEMORY_SLOT_NOTIFY_METHOD, 2) {
-             *     If (LEqual(Arg0, 0x00)) {Notify(MP00, Arg1)} ...
-             */
-            build_append_notify_method(sb_scope->buf,
-                                       stringify(MEMORY_SLOT_NOTIFY_METHOD),
-                                       "MP%0.02X", nr_mem);
+            method = aml_method("_CRS", 0);
+            s = BASEPATH stringify(MEMORY_SLOT_CRS_METHOD);
+            aml_append(method, aml_return(aml_call1(s, aml_name("_UID"))));
+            aml_append(dev, method);
+
+            method = aml_method("_STA", 0);
+            s = BASEPATH stringify(MEMORY_SLOT_STATUS_METHOD);
+            aml_append(method, aml_return(aml_call1(s, aml_name("_UID"))));
+            aml_append(dev, method);
+
+            method = aml_method("_PXM", 0);
+            s = BASEPATH stringify(MEMORY_SLOT_PROXIMITY_METHOD);
+            aml_append(method, aml_return(aml_call1(s, aml_name("_UID"))));
+            aml_append(dev, method);
+
+            method = aml_method("_OST", 3);
+            s = BASEPATH stringify(MEMORY_SLOT_OST_METHOD);
+            aml_append(method, aml_return(aml_call4(
+                s, aml_name("_UID"), aml_arg(0), aml_arg(1), aml_arg(2)
+            )));
+            aml_append(dev, method);
+
+            aml_append(sb_scope, dev);
         }
 
+        /* build Method(MEMORY_SLOT_NOTIFY_METHOD, 2) {
+         *     If (LEqual(Arg0, 0x00)) {Notify(MP00, Arg1)} ...
+         */
+        method = aml_method(stringify(MEMORY_SLOT_NOTIFY_METHOD), 2);
+        for (i = 0; i < nr_mem; i++) {
+            ifctx = aml_if(aml_equal(aml_arg(0), aml_int(i)));
+            aml_append(ifctx,
+                aml_notify(aml_name("MP%.02X", i), aml_arg(1))
+            );
+            aml_append(method, ifctx);
+        }
+        aml_append(sb_scope, method);
+
         {
             AcpiBuildPciBusHotplugState hotplug_state;
             Object *pci_host;
diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index c9af7ba..45b90a8 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -11,7 +11,6 @@ hw/i386/acpi-build.o: hw/i386/acpi-build.c \
 	hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \
 	hw/i386/ssdt-pcihp.hex \
 	hw/i386/ssdt-misc.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/ssdt-mem.dsl b/hw/i386/ssdt-mem.dsl
deleted file mode 100644
index 22ff5dd..0000000
--- a/hw/i386/ssdt-mem.dsl
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Memory hotplug ACPI DSDT static objects definitions
- *
- * Copyright ProfitBricks GmbH 2012
- * Copyright (C) 2013-2014 Red Hat Inc
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see <http://www.gnu.org/licenses/>
- */
-
-/* This file is the basis for the ssdt_mem[] variable in src/acpi.c.
- * It defines the contents of the memory device object.  At
- * runtime, a dynamically generated SSDT will contain one copy of this
- * AML snippet for every possible memory device in the system.  The
- * objects will be placed in the \_SB_ namespace.
- *
- * In addition to the aml code generated from this file, the
- * src/acpi.c file creates a MTFY method with an entry for each memdevice:
- *     Method(MTFY, 2) {
- *         If (LEqual(Arg0, 0x00)) { Notify(MP00, Arg1) }
- *         If (LEqual(Arg0, 0x01)) { Notify(MP01, Arg1) }
- *         ...
- *     }
- */
-#include "hw/acpi/pc-hotplug.h"
-
-ACPI_EXTRACT_ALL_CODE ssdm_mem_aml
-
-DefinitionBlock ("ssdt-mem.aml", "SSDT", 0x02, "BXPC", "CSSDT", 0x1)
-{
-
-    External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_CRS_METHOD, MethodObj)
-    External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_STATUS_METHOD, MethodObj)
-    External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_OST_METHOD, MethodObj)
-    External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_PROXIMITY_METHOD, MethodObj)
-
-    Scope(\_SB) {
-/*  v------------------ DO NOT EDIT ------------------v */
-        ACPI_EXTRACT_DEVICE_START ssdt_mem_start
-        ACPI_EXTRACT_DEVICE_END ssdt_mem_end
-        ACPI_EXTRACT_DEVICE_STRING ssdt_mem_name
-        Device(MPAA) {
-            ACPI_EXTRACT_NAME_STRING ssdt_mem_id
-            Name(_UID, "0xAA")
-/*  ^------------------ DO NOT EDIT ------------------^
- * Don't change the above without also updating the C code.
- */
-            Name(_HID, EISAID("PNP0C80"))
-
-            Method(_CRS, 0) {
-                Return(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_CRS_METHOD(_UID))
-            }
-
-            Method(_STA, 0) {
-                Return(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_STATUS_METHOD(_UID))
-            }
-
-            Method(_PXM, 0) {
-                Return(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_PROXIMITY_METHOD(_UID))
-            }
-
-            Method(_OST, 3) {
-                \_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_OST_METHOD(_UID, Arg0, Arg1, Arg2)
-            }
-        }
-    }
-}
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 90/96] pc: acpi-build: create memory hotplug IO region dynamically
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (89 preceding siblings ...)
  2015-02-18 21:52 ` [Qemu-devel] [PULL 89/96] pc: acpi-build: drop template patching and memory hotplug objects dynamically Michael S. Tsirkin
@ 2015-02-18 21:52 ` Michael S. Tsirkin
  2015-02-18 21:52 ` [Qemu-devel] [PULL 91/96] acpi: add aml_word_bus_number(), aml_word_io(), aml_dword_memory(), aml_qword_memory() terms Michael S. Tsirkin
                   ` (7 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:52 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Anthony Liguori,
	Paolo Bonzini, Igor Mammedov, Richard Henderson

From: Igor Mammedov <imammedo@redhat.com>

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 <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 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 377dd72..98553f8 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 {
@@ -187,6 +189,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) {
@@ -887,9 +892,6 @@ build_ssdt(GArray *table_data, GArray *linker,
 
     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) {
@@ -1027,6 +1029,55 @@ build_ssdt(GArray *table_data, GArray *linker,
 
         /* 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,
-                            ACPI_MEMORY_HOTPLUG_IO_LEN)
-
-            Name(_CRS, ResourceTemplate() {
-                IO(Decode16, ACPI_MEMORY_HOTPLUG_BASE, ACPI_MEMORY_HOTPLUG_BASE,
-                   0, ACPI_MEMORY_HOTPLUG_IO_LEN, IO)
-            })
+            External(MEMORY_SLOT_ADDR_LOW, FieldUnitObj) // read only
+            External(MEMORY_SLOT_ADDR_HIGH, FieldUnitObj) // read only
+            External(MEMORY_SLOT_SIZE_LOW, FieldUnitObj) // read only
+            External(MEMORY_SLOT_SIZE_HIGH, FieldUnitObj) // read only
+            External(MEMORY_SLOT_PROXIMITY, FieldUnitObj) // read only
+            External(MEMORY_SLOT_ENABLED, FieldUnitObj) // 1 if enabled, read only
+            External(MEMORY_SLOT_INSERT_EVENT, FieldUnitObj) // (read) 1 if has a insert event. (write) 1 to clear event
+            External(MEMORY_SLOT_SLECTOR, FieldUnitObj) // DIMM selector, write only
+            External(MEMORY_SLOT_OST_EVENT, FieldUnitObj) // _OST event code, write only
+            External(MEMORY_SLOT_OST_STATUS, FieldUnitObj) // _OST status code, write only
 
             Method(_STA, 0) {
                 If (LEqual(MEMORY_SLOTS_NUMBER, Zero)) {
@@ -39,25 +41,7 @@
                 Return(0xB)
             }
 
-            Field(MEMORY_HOTPLUG_IO_REGION, DWordAcc, NoLock, Preserve) {
-                MEMORY_SLOT_ADDR_LOW, 32,  // read only
-                MEMORY_SLOT_ADDR_HIGH, 32, // read only
-                MEMORY_SLOT_SIZE_LOW, 32,  // read only
-                MEMORY_SLOT_SIZE_HIGH, 32, // read only
-                MEMORY_SLOT_PROXIMITY, 32, // read only
-            }
-            Field(MEMORY_HOTPLUG_IO_REGION, ByteAcc, NoLock, Preserve) {
-                Offset(20),
-                MEMORY_SLOT_ENABLED,  1, // 1 if enabled, read only
-                MEMORY_SLOT_INSERT_EVENT, 1, // (read) 1 if has a insert event. (write) 1 to clear event
-            }
-
             Mutex (MEMORY_SLOT_LOCK, 0)
-            Field (MEMORY_HOTPLUG_IO_REGION, DWordAcc, NoLock, Preserve) {
-                MEMORY_SLOT_SLECTOR, 32,  // DIMM selector, write only
-                MEMORY_SLOT_OST_EVENT, 32,  // _OST event code, write only
-                MEMORY_SLOT_OST_STATUS, 32,  // _OST status code, write only
-            }
 
             Method(MEMORY_SLOT_SCAN_METHOD, 0) {
                 If (LEqual(MEMORY_SLOTS_NUMBER, Zero)) {
diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
index 81be858..2588e30 100644
--- a/hw/i386/ssdt-misc.dsl
+++ b/hw/i386/ssdt-misc.dsl
@@ -36,7 +36,5 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
        Name(P1E, Buffer() { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 })
        ACPI_EXTRACT_NAME_BUFFER8 acpi_pci64_length
        Name(P1L, Buffer() { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 })
-       ACPI_EXTRACT_NAME_DWORD_CONST ssdt_mctrl_nr_slots
-       Name(MEMORY_SLOTS_NUMBER, 0x12345678)
     }
 }
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 91/96] acpi: add aml_word_bus_number(), aml_word_io(), aml_dword_memory(), aml_qword_memory() terms
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (90 preceding siblings ...)
  2015-02-18 21:52 ` [Qemu-devel] [PULL 90/96] pc: acpi-build: create memory hotplug IO region dynamically Michael S. Tsirkin
@ 2015-02-18 21:52 ` Michael S. Tsirkin
  2015-02-18 21:52 ` [Qemu-devel] [PULL 92/96] pc: pcihp: expose MMIO base and len as properties Michael S. Tsirkin
                   ` (6 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Igor Mammedov, dgilbert, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/aml-build.h |  72 ++++++++++++++++++++
 hw/acpi/aml-build.c         | 161 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 233 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index ea3ece3..d2b2c35 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -42,6 +42,57 @@ typedef enum {
     aml_system_io = 0x01,
 } AmlRegionSpace;
 
+typedef enum {
+    aml_memory_range = 0,
+    aml_io_range = 1,
+    aml_bus_number_range = 2,
+} AmlResourceType;
+
+typedef enum {
+    aml_sub_decode = 1 << 1,
+    aml_pos_decode = 0
+} AmlDecode;
+
+typedef enum {
+    aml_max_fixed = 1 << 3,
+    aml_max_not_fixed = 0,
+} AmlMaxFixed;
+
+typedef enum {
+    aml_min_fixed = 1 << 2,
+    aml_min_not_fixed = 0
+} AmlMinFixed;
+
+/*
+ * ACPI 1.0b: Table 6-26 I/O Resource Flag (Resource Type = 1) Definitions
+ * _RNG field definition
+ */
+typedef enum {
+    aml_isa_only = 1,
+    aml_non_isa_only = 2,
+    aml_entire_range = 3,
+} AmlISARanges;
+
+/*
+ * ACPI 1.0b: Table 6-25 Memory Resource Flag (Resource Type = 0) Definitions
+ * _MEM field definition
+ */
+typedef enum {
+    aml_non_cacheable = 0,
+    aml_cacheable = 1,
+    aml_write_combining = 2,
+    aml_prefetchable = 3,
+} AmlCacheble;
+
+/*
+ * ACPI 1.0b: Table 6-25 Memory Resource Flag (Resource Type = 0) Definitions
+ * _RW field definition
+ */
+typedef enum {
+    aml_ReadOnly = 0,
+    aml_ReadWrite = 1,
+} AmlReadAndWrite;
+
 /**
  * init_aml_allocator:
  *
@@ -103,6 +154,27 @@ 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);
+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);
+Aml *aml_word_io(AmlMinFixed min_fixed, AmlMaxFixed max_fixed,
+                 AmlDecode dec, AmlISARanges isa_ranges,
+                 uint16_t addr_gran, uint16_t addr_min,
+                 uint16_t addr_max, uint16_t addr_trans,
+                 uint16_t len);
+Aml *aml_dword_memory(AmlDecode dec, AmlMinFixed min_fixed,
+                      AmlMaxFixed max_fixed, AmlCacheble cacheable,
+                      AmlReadAndWrite read_and_write,
+                      uint32_t addr_gran, uint32_t addr_min,
+                      uint32_t addr_max, uint32_t addr_trans,
+                      uint32_t len);
+Aml *aml_qword_memory(AmlDecode dec, AmlMinFixed min_fixed,
+                      AmlMaxFixed max_fixed, AmlCacheble cacheable,
+                      AmlReadAndWrite read_and_write,
+                      uint64_t addr_gran, uint64_t addr_min,
+                      uint64_t addr_max, uint64_t addr_trans,
+                      uint64_t len);
 
 /* Block AML object primitives */
 Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 9d9b978..d793775 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -704,3 +704,164 @@ Aml *aml_eisaid(const char *str)
     build_append_int_noprefix(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_int_noprefix(var->buf, addr_gran, sizeof(addr_gran));
+    build_append_int_noprefix(var->buf, addr_min, sizeof(addr_min));
+    build_append_int_noprefix(var->buf, addr_max, sizeof(addr_max));
+    build_append_int_noprefix(var->buf, addr_trans, sizeof(addr_trans));
+    build_append_int_noprefix(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_int_noprefix(var->buf, addr_gran, sizeof(addr_gran));
+    build_append_int_noprefix(var->buf, addr_min, sizeof(addr_min));
+    build_append_int_noprefix(var->buf, addr_max, sizeof(addr_max));
+    build_append_int_noprefix(var->buf, addr_trans, sizeof(addr_trans));
+    build_append_int_noprefix(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_int_noprefix(var->buf, addr_gran, sizeof(addr_gran));
+    build_append_int_noprefix(var->buf, addr_min, sizeof(addr_min));
+    build_append_int_noprefix(var->buf, addr_max, sizeof(addr_max));
+    build_append_int_noprefix(var->buf, addr_trans, sizeof(addr_trans));
+    build_append_int_noprefix(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 description at:
+ * ACPI 5.0: 19.5.142 WordIO (Word IO Resource Descriptor Macro)
+ */
+Aml *aml_word_io(AmlMinFixed min_fixed, AmlMaxFixed max_fixed,
+                 AmlDecode dec, AmlISARanges isa_ranges,
+                 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_io_range, min_fixed, max_fixed, dec,
+                            addr_gran, addr_min, addr_max, addr_trans, len,
+                            isa_ranges);
+}
+
+/*
+ * ACPI 1.0b: 6.4.3.5.4 ASL Macros for DWORD Address Space Descriptor
+ *
+ * More verbose description at:
+ * ACPI 5.0: 19.5.34 DWordMemory (DWord Memory Resource Descriptor Macro)
+ */
+Aml *aml_dword_memory(AmlDecode dec, AmlMinFixed min_fixed,
+                      AmlMaxFixed max_fixed, AmlCacheble cacheable,
+                      AmlReadAndWrite read_and_write,
+                      uint32_t addr_gran, uint32_t addr_min,
+                      uint32_t addr_max, uint32_t addr_trans,
+                      uint32_t len)
+{
+    uint8_t flags = read_and_write | (cacheable << 1);
+
+    return aml_dword_as_desc(aml_memory_range, min_fixed, max_fixed,
+                             dec, addr_gran, addr_min, addr_max,
+                             addr_trans, len, flags);
+}
+
+/*
+ * ACPI 1.0b: 6.4.3.5.2 ASL Macros for QWORD Address Space Descriptor
+ *
+ * More verbose description at:
+ * ACPI 5.0: 19.5.102 QWordMemory (QWord Memory Resource Descriptor Macro)
+ */
+Aml *aml_qword_memory(AmlDecode dec, AmlMinFixed min_fixed,
+                      AmlMaxFixed max_fixed, AmlCacheble cacheable,
+                      AmlReadAndWrite read_and_write,
+                      uint64_t addr_gran, uint64_t addr_min,
+                      uint64_t addr_max, uint64_t addr_trans,
+                      uint64_t len)
+{
+    uint8_t flags = read_and_write | (cacheable << 1);
+
+    return aml_qword_as_desc(aml_memory_range, min_fixed, max_fixed,
+                             dec, addr_gran, addr_min, addr_max,
+                             addr_trans, len, flags);
+}
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 92/96] pc: pcihp: expose MMIO base and len as properties
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (91 preceding siblings ...)
  2015-02-18 21:52 ` [Qemu-devel] [PULL 91/96] acpi: add aml_word_bus_number(), aml_word_io(), aml_dword_memory(), aml_qword_memory() terms Michael S. Tsirkin
@ 2015-02-18 21:52 ` Michael S. Tsirkin
  2015-02-18 21:52 ` [Qemu-devel] [PULL 93/96] pc: acpi-build: reserve PCIHP MMIO resources Michael S. Tsirkin
                   ` (5 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:52 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Igor Mammedov, dgilbert, Anthony Liguori, Juan Quintela

From: Igor Mammedov <imammedo@redhat.com>

it will be used later to dynamically reserve MMIO region
instead of manually punching holes in PCI0._CRS

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/acpi/pcihp.h |  7 ++++++-
 hw/acpi/pcihp.c         | 18 ++++++++++++------
 hw/acpi/piix4.c         |  2 +-
 3 files changed, 19 insertions(+), 8 deletions(-)

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,
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,
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 93/96] pc: acpi-build: reserve PCIHP MMIO resources
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (92 preceding siblings ...)
  2015-02-18 21:52 ` [Qemu-devel] [PULL 92/96] pc: pcihp: expose MMIO base and len as properties Michael S. Tsirkin
@ 2015-02-18 21:52 ` Michael S. Tsirkin
  2015-02-18 21:52 ` [Qemu-devel] [PULL 94/96] acpi: update generated hex files Michael S. Tsirkin
                   ` (4 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:52 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Anthony Liguori,
	Paolo Bonzini, Igor Mammedov, Richard Henderson

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 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 98553f8..4d5d7e3 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 {
@@ -178,9 +180,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;
@@ -892,6 +900,25 @@ build_ssdt(GArray *table_data, GArray *linker,
 
     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) {
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 94/96] acpi: update generated hex files
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (93 preceding siblings ...)
  2015-02-18 21:52 ` [Qemu-devel] [PULL 93/96] pc: acpi-build: reserve PCIHP MMIO resources Michael S. Tsirkin
@ 2015-02-18 21:52 ` Michael S. Tsirkin
  2015-02-18 21:53 ` [Qemu-devel] [PULL 95/96] acpi: drop unused generated files Michael S. Tsirkin
                   ` (3 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:52 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Juan Quintela, dgilbert, Anthony Liguori,
	Paolo Bonzini, Richard Henderson

Used for IASL builds.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/i386/acpi-dsdt.hex.generated     | 224 ++---------------------------
 hw/i386/q35-acpi-dsdt.hex.generated | 224 ++---------------------------
 hw/i386/ssdt-misc.hex.generated     | 274 +-----------------------------------
 3 files changed, 25 insertions(+), 697 deletions(-)

diff --git a/hw/i386/acpi-dsdt.hex.generated b/hw/i386/acpi-dsdt.hex.generated
index 498b194..a71e0cd 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,
+0x57,
+0xd,
 0x0,
 0x0,
 0x1,
-0x6c,
+0x26,
 0x42,
 0x58,
 0x50,
@@ -2318,8 +2318,8 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x53,
 0x1,
 0x10,
-0x4f,
-0x12,
+0x4d,
+0xc,
 0x5f,
 0x53,
 0x42,
@@ -2416,32 +2416,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 +2523,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,
-0x72,
-0x65,
-0x73,
-0x6f,
-0x75,
-0x72,
-0x63,
-0x65,
-0x73,
-0x0,
-0x8,
-0x5f,
-0x43,
-0x52,
-0x53,
-0x11,
-0xd,
-0xa,
-0xa,
-0x47,
-0x1,
-0x0,
-0xaf,
-0x0,
-0xaf,
-0x0,
-0x20,
-0x79,
-0x0,
-0x8,
-0x5f,
-0x53,
-0x54,
-0x41,
-0xa,
-0xb,
 0x10,
-0x40,
-0x31,
+0x44,
+0x2a,
 0x2e,
 0x5f,
 0x53,
@@ -2635,8 +2537,8 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x30,
 0x5b,
 0x82,
-0x43,
-0x30,
+0x47,
+0x29,
 0x4d,
 0x48,
 0x50,
@@ -2686,37 +2588,6 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x65,
 0x73,
 0x0,
-0x5b,
-0x80,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x1,
-0xb,
-0x0,
-0xa,
-0xa,
-0x18,
-0x8,
-0x5f,
-0x43,
-0x52,
-0x53,
-0x11,
-0xd,
-0xa,
-0xa,
-0x47,
-0x1,
-0x0,
-0xa,
-0x0,
-0xa,
-0x0,
-0x18,
-0x79,
-0x0,
 0x14,
 0x13,
 0x5f,
@@ -2738,89 +2609,12 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0xa,
 0xb,
 0x5b,
-0x81,
-0x1f,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x3,
-0x4d,
-0x52,
-0x42,
-0x4c,
-0x20,
-0x4d,
-0x52,
-0x42,
-0x48,
-0x20,
-0x4d,
-0x52,
-0x4c,
-0x4c,
-0x20,
-0x4d,
-0x52,
-0x4c,
-0x48,
-0x20,
-0x4d,
-0x50,
-0x58,
-0x5f,
-0x20,
-0x5b,
-0x81,
-0x13,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x1,
-0x0,
-0x40,
-0xa,
-0x4d,
-0x45,
-0x53,
-0x5f,
-0x1,
-0x4d,
-0x49,
-0x4e,
-0x53,
-0x1,
-0x5b,
 0x1,
 0x4d,
 0x4c,
 0x43,
 0x4b,
 0x0,
-0x5b,
-0x81,
-0x15,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x3,
-0x4d,
-0x53,
-0x45,
-0x4c,
-0x20,
-0x4d,
-0x4f,
-0x45,
-0x56,
-0x20,
-0x4d,
-0x4f,
-0x53,
-0x43,
-0x20,
 0x14,
 0x4a,
 0x4,
diff --git a/hw/i386/q35-acpi-dsdt.hex.generated b/hw/i386/q35-acpi-dsdt.hex.generated
index 0d5b133..28769d4 100644
--- a/hw/i386/q35-acpi-dsdt.hex.generated
+++ b/hw/i386/q35-acpi-dsdt.hex.generated
@@ -3,12 +3,12 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0x53,
 0x44,
 0x54,
-0x13,
-0x20,
+0x45,
+0x1f,
 0x0,
 0x0,
 0x1,
-0x0,
+0x59,
 0x42,
 0x58,
 0x50,
@@ -6959,8 +6959,8 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0x53,
 0x1,
 0x10,
-0x4f,
-0x12,
+0x4d,
+0xc,
 0x5f,
 0x53,
 0x42,
@@ -7057,32 +7057,6 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0x22,
 0xa,
 0xc8,
-0x5b,
-0x80,
-0x50,
-0x52,
-0x53,
-0x54,
-0x1,
-0xb,
-0xd8,
-0xc,
-0xa,
-0x20,
-0x5b,
-0x81,
-0xc,
-0x50,
-0x52,
-0x53,
-0x54,
-0x1,
-0x50,
-0x52,
-0x53,
-0x5f,
-0x40,
-0x10,
 0x14,
 0x4a,
 0x6,
@@ -7190,81 +7164,9 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 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,
-0x72,
-0x65,
-0x73,
-0x6f,
-0x75,
-0x72,
-0x63,
-0x65,
-0x73,
-0x0,
-0x8,
-0x5f,
-0x43,
-0x52,
-0x53,
-0x11,
-0xd,
-0xa,
-0xa,
-0x47,
-0x1,
-0xd8,
-0xc,
-0xd8,
-0xc,
-0x0,
-0x20,
-0x79,
-0x0,
-0x8,
-0x5f,
-0x53,
-0x54,
-0x41,
-0xa,
-0xb,
 0x10,
-0x40,
-0x31,
+0x44,
+0x2a,
 0x2e,
 0x5f,
 0x53,
@@ -7276,8 +7178,8 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0x30,
 0x5b,
 0x82,
-0x43,
-0x30,
+0x47,
+0x29,
 0x4d,
 0x48,
 0x50,
@@ -7327,37 +7229,6 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0x65,
 0x73,
 0x0,
-0x5b,
-0x80,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x1,
-0xb,
-0x0,
-0xa,
-0xa,
-0x18,
-0x8,
-0x5f,
-0x43,
-0x52,
-0x53,
-0x11,
-0xd,
-0xa,
-0xa,
-0x47,
-0x1,
-0x0,
-0xa,
-0x0,
-0xa,
-0x0,
-0x18,
-0x79,
-0x0,
 0x14,
 0x13,
 0x5f,
@@ -7379,89 +7250,12 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
 0xa,
 0xb,
 0x5b,
-0x81,
-0x1f,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x3,
-0x4d,
-0x52,
-0x42,
-0x4c,
-0x20,
-0x4d,
-0x52,
-0x42,
-0x48,
-0x20,
-0x4d,
-0x52,
-0x4c,
-0x4c,
-0x20,
-0x4d,
-0x52,
-0x4c,
-0x48,
-0x20,
-0x4d,
-0x50,
-0x58,
-0x5f,
-0x20,
-0x5b,
-0x81,
-0x13,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x1,
-0x0,
-0x40,
-0xa,
-0x4d,
-0x45,
-0x53,
-0x5f,
-0x1,
-0x4d,
-0x49,
-0x4e,
-0x53,
-0x1,
-0x5b,
 0x1,
 0x4d,
 0x4c,
 0x43,
 0x4b,
 0x0,
-0x5b,
-0x81,
-0x15,
-0x48,
-0x50,
-0x4d,
-0x52,
-0x3,
-0x4d,
-0x53,
-0x45,
-0x4c,
-0x20,
-0x4d,
-0x4f,
-0x45,
-0x56,
-0x20,
-0x4d,
-0x4f,
-0x53,
-0x43,
-0x20,
 0x14,
 0x4a,
 0x4,
diff --git a/hw/i386/ssdt-misc.hex.generated b/hw/i386/ssdt-misc.hex.generated
index cbcf61d..0b77ed4 100644
--- a/hw/i386/ssdt-misc.hex.generated
+++ b/hw/i386/ssdt-misc.hex.generated
@@ -1,15 +1,6 @@
 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
 };
@@ -21,12 +12,12 @@ static unsigned char ssdp_misc_aml[] = {
 0x53,
 0x44,
 0x54,
-0x6c,
-0x1,
+0x77,
+0x0,
 0x0,
 0x0,
 0x1,
-0x3,
+0x40,
 0x42,
 0x58,
 0x50,
@@ -49,12 +40,12 @@ static unsigned char ssdp_misc_aml[] = {
 0x4e,
 0x54,
 0x4c,
-0x28,
-0x8,
+0x7,
+0x11,
 0x14,
 0x20,
 0x10,
-0x4c,
+0x42,
 0x5,
 0x5c,
 0x0,
@@ -135,258 +126,7 @@ static unsigned char ssdp_misc_aml[] = {
 0x0,
 0x0,
 0x0,
-0x0,
-0x8,
-0x4d,
-0x44,
-0x4e,
-0x52,
-0xc,
-0x78,
-0x56,
-0x34,
-0x12,
-0x10,
-0x29,
-0x5c,
-0x0,
-0x8,
-0x5f,
-0x53,
-0x33,
-0x5f,
-0x12,
-0x6,
-0x4,
-0x1,
-0x1,
-0x0,
-0x0,
-0x8,
-0x5f,
-0x53,
-0x34,
-0x5f,
-0x12,
-0x8,
-0x4,
-0xa,
-0x2,
-0xa,
-0x2,
-0x0,
-0x0,
-0x8,
-0x5f,
-0x53,
-0x35,
-0x5f,
-0x12,
-0x6,
-0x4,
-0x0,
-0x0,
-0x0,
-0x0,
-0x10,
-0x40,
-0xc,
-0x5c,
-0x2f,
-0x3,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x49,
-0x53,
-0x41,
-0x5f,
-0x5b,
-0x82,
-0x4d,
-0xa,
-0x50,
-0x45,
-0x56,
-0x54,
-0x8,
-0x5f,
-0x48,
-0x49,
-0x44,
-0xd,
-0x51,
-0x45,
-0x4d,
-0x55,
-0x30,
-0x30,
-0x30,
-0x31,
-0x0,
-0x8,
-0x50,
-0x45,
-0x53,
-0x54,
-0xb,
-0xff,
-0xff,
-0x5b,
-0x80,
-0x50,
-0x45,
-0x4f,
-0x52,
-0x1,
-0x50,
-0x45,
-0x53,
-0x54,
-0x1,
-0x5b,
-0x81,
-0xb,
-0x50,
-0x45,
-0x4f,
-0x52,
-0x1,
-0x50,
-0x45,
-0x50,
-0x54,
-0x8,
-0x14,
-0x18,
-0x5f,
-0x53,
-0x54,
-0x41,
-0x0,
-0x70,
-0x50,
-0x45,
-0x53,
-0x54,
-0x60,
-0xa0,
-0x6,
-0x93,
-0x60,
-0x0,
-0xa4,
-0x0,
-0xa1,
-0x4,
-0xa4,
-0xa,
-0xf,
-0x14,
-0xe,
-0x52,
-0x44,
-0x50,
-0x54,
-0x0,
-0x70,
-0x50,
-0x45,
-0x50,
-0x54,
-0x60,
-0xa4,
-0x60,
-0x14,
-0xc,
-0x57,
-0x52,
-0x50,
-0x54,
-0x1,
-0x70,
-0x68,
-0x50,
-0x45,
-0x50,
-0x54,
-0x8,
-0x5f,
-0x43,
-0x52,
-0x53,
-0x11,
-0xd,
-0xa,
-0xa,
-0x47,
-0x1,
-0x0,
-0x0,
-0x0,
-0x0,
-0x1,
-0x1,
-0x79,
-0x0,
-0x8b,
-0x5f,
-0x43,
-0x52,
-0x53,
-0xa,
-0x2,
-0x49,
-0x4f,
-0x4d,
-0x4e,
-0x8b,
-0x5f,
-0x43,
-0x52,
-0x53,
-0xa,
-0x4,
-0x49,
-0x4f,
-0x4d,
-0x58,
-0x14,
-0x18,
-0x5f,
-0x49,
-0x4e,
-0x49,
-0x0,
-0x70,
-0x50,
-0x45,
-0x53,
-0x54,
-0x49,
-0x4f,
-0x4d,
-0x4e,
-0x70,
-0x50,
-0x45,
-0x53,
-0x54,
-0x49,
-0x4f,
-0x4d,
-0x58
-};
-static unsigned char ssdt_isa_pest[] = {
-0xda
-};
-static unsigned char acpi_s4_name[] = {
-0x92
+0x0
 };
 static unsigned char acpi_pci64_start[] = {
 0x4d
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 95/96] acpi: drop unused generated files
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (94 preceding siblings ...)
  2015-02-18 21:52 ` [Qemu-devel] [PULL 94/96] acpi: update generated hex files Michael S. Tsirkin
@ 2015-02-18 21:53 ` Michael S. Tsirkin
  2015-02-18 21:53 ` [Qemu-devel] [PULL 96/96] acpi-test: update expected files Michael S. Tsirkin
                   ` (2 subsequent siblings)
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, dgilbert, Juan Quintela

drop ssdt-mem.hex.generated and ssdt-proc.hex.generated:
dsl files have been removed previously.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/i386/ssdt-mem.hex.generated  | 213 ----------------------------------------
 hw/i386/ssdt-proc.hex.generated | 134 -------------------------
 2 files changed, 347 deletions(-)
 delete mode 100644 hw/i386/ssdt-mem.hex.generated
 delete mode 100644 hw/i386/ssdt-proc.hex.generated

diff --git a/hw/i386/ssdt-mem.hex.generated b/hw/i386/ssdt-mem.hex.generated
deleted file mode 100644
index b3bfbbd..0000000
--- a/hw/i386/ssdt-mem.hex.generated
+++ /dev/null
@@ -1,213 +0,0 @@
-static unsigned char ssdt_mem_id[] = {
-0x35
-};
-static unsigned char ssdm_mem_aml[] = {
-0x53,
-0x53,
-0x44,
-0x54,
-0xc7,
-0x0,
-0x0,
-0x0,
-0x2,
-0x66,
-0x42,
-0x58,
-0x50,
-0x43,
-0x0,
-0x0,
-0x43,
-0x53,
-0x53,
-0x44,
-0x54,
-0x0,
-0x0,
-0x0,
-0x1,
-0x0,
-0x0,
-0x0,
-0x49,
-0x4e,
-0x54,
-0x4c,
-0x28,
-0x8,
-0x14,
-0x20,
-0x10,
-0x42,
-0xa,
-0x5c,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x5b,
-0x82,
-0x49,
-0x9,
-0x4d,
-0x50,
-0x41,
-0x41,
-0x8,
-0x5f,
-0x55,
-0x49,
-0x44,
-0xd,
-0x30,
-0x78,
-0x41,
-0x41,
-0x0,
-0x8,
-0x5f,
-0x48,
-0x49,
-0x44,
-0xc,
-0x41,
-0xd0,
-0xc,
-0x80,
-0x14,
-0x1e,
-0x5f,
-0x43,
-0x52,
-0x53,
-0x0,
-0xa4,
-0x5c,
-0x2f,
-0x4,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x4d,
-0x48,
-0x50,
-0x44,
-0x4d,
-0x43,
-0x52,
-0x53,
-0x5f,
-0x55,
-0x49,
-0x44,
-0x14,
-0x1e,
-0x5f,
-0x53,
-0x54,
-0x41,
-0x0,
-0xa4,
-0x5c,
-0x2f,
-0x4,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x4d,
-0x48,
-0x50,
-0x44,
-0x4d,
-0x52,
-0x53,
-0x54,
-0x5f,
-0x55,
-0x49,
-0x44,
-0x14,
-0x1e,
-0x5f,
-0x50,
-0x58,
-0x4d,
-0x0,
-0xa4,
-0x5c,
-0x2f,
-0x4,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x4d,
-0x48,
-0x50,
-0x44,
-0x4d,
-0x50,
-0x58,
-0x4d,
-0x5f,
-0x55,
-0x49,
-0x44,
-0x14,
-0x20,
-0x5f,
-0x4f,
-0x53,
-0x54,
-0x3,
-0x5c,
-0x2f,
-0x4,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x4d,
-0x48,
-0x50,
-0x44,
-0x4d,
-0x4f,
-0x53,
-0x54,
-0x5f,
-0x55,
-0x49,
-0x44,
-0x68,
-0x69,
-0x6a
-};
-static unsigned char ssdt_mem_start[] = {
-0x2c
-};
-static unsigned char ssdt_mem_end[] = {
-0xc7
-};
-static unsigned char ssdt_mem_name[] = {
-0x30
-};
diff --git a/hw/i386/ssdt-proc.hex.generated b/hw/i386/ssdt-proc.hex.generated
deleted file mode 100644
index 4df0734..0000000
--- a/hw/i386/ssdt-proc.hex.generated
+++ /dev/null
@@ -1,134 +0,0 @@
-static unsigned char ssdt_proc_name[] = {
-0x28
-};
-static unsigned char ssdp_proc_aml[] = {
-0x53,
-0x53,
-0x44,
-0x54,
-0x78,
-0x0,
-0x0,
-0x0,
-0x1,
-0x7d,
-0x42,
-0x58,
-0x50,
-0x43,
-0x0,
-0x0,
-0x42,
-0x58,
-0x53,
-0x53,
-0x44,
-0x54,
-0x0,
-0x0,
-0x1,
-0x0,
-0x0,
-0x0,
-0x49,
-0x4e,
-0x54,
-0x4c,
-0x15,
-0x11,
-0x13,
-0x20,
-0x5b,
-0x83,
-0x42,
-0x5,
-0x43,
-0x50,
-0x41,
-0x41,
-0xaa,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x8,
-0x49,
-0x44,
-0x5f,
-0x5f,
-0xa,
-0xaa,
-0x8,
-0x5f,
-0x48,
-0x49,
-0x44,
-0xd,
-0x41,
-0x43,
-0x50,
-0x49,
-0x30,
-0x30,
-0x30,
-0x37,
-0x0,
-0x14,
-0xf,
-0x5f,
-0x4d,
-0x41,
-0x54,
-0x0,
-0xa4,
-0x43,
-0x50,
-0x4d,
-0x41,
-0x49,
-0x44,
-0x5f,
-0x5f,
-0x14,
-0xf,
-0x5f,
-0x53,
-0x54,
-0x41,
-0x0,
-0xa4,
-0x43,
-0x50,
-0x53,
-0x54,
-0x49,
-0x44,
-0x5f,
-0x5f,
-0x14,
-0xf,
-0x5f,
-0x45,
-0x4a,
-0x30,
-0x1,
-0x43,
-0x50,
-0x45,
-0x4a,
-0x49,
-0x44,
-0x5f,
-0x5f,
-0x68
-};
-static unsigned char ssdt_proc_id[] = {
-0x38
-};
-static unsigned char ssdt_proc_end[] = {
-0x78
-};
-static unsigned char ssdt_proc_start[] = {
-0x24
-};
-- 
MST

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* [Qemu-devel] [PULL 96/96] acpi-test: update expected files
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (95 preceding siblings ...)
  2015-02-18 21:53 ` [Qemu-devel] [PULL 95/96] acpi: drop unused generated files Michael S. Tsirkin
@ 2015-02-18 21:53 ` Michael S. Tsirkin
  2015-02-24 16:47 ` [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
  2015-02-26 11:17 ` Peter Maydell
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 21:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, dgilbert, Juan Quintela

A bunch of code moved from dsdt to ssdt,
plus we got trivial changes like 0->Zero which our test
dosn't recognize as identity yet.
Update expected files to suppress test warning.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 tests/acpi-test-data/pc/DSDT  | Bin 3621 -> 3415 bytes
 tests/acpi-test-data/pc/SSDT  | Bin 2279 -> 2374 bytes
 tests/acpi-test-data/q35/DSDT | Bin 8211 -> 8005 bytes
 tests/acpi-test-data/q35/SSDT | Bin 560 -> 578 bytes
 4 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/tests/acpi-test-data/pc/DSDT b/tests/acpi-test-data/pc/DSDT
index 010d74603f09430d65fae1ce2a0d867c1964a1a8..ad12cb35d9dafc4d50002873f5c4ca04552b36df 100644
GIT binary patch
delta 84
zcmZ1~b6twdCD<h-oR@)tv1}t3D<_jL&tyT)gvs5U*#ZJCT6*!pPVoWGo(9oP?wXVR
oxD2I5gyVxl92pjHPWE;23u0Kpu!M^{n$g$C*_&ZA8@D_&0EjXa$^ZZW

delta 292
zcmcaEwN!@7CD<iIm5+geanD9BR!$~=p~-@r2~yDw0YSkbjNA<CxfG%sdB7YX5$_-{
zxsWqEBD%?qB_PN(m?Pf9(}l<J0v8)ce5j`juX8}CLPmZ`K~8D9LQ!gQerZv1YB2*x
zymL^nATJk}J0rt-AXKOX3I&Haa&Zed80y6bJH-b$dm2PHIU7uV!)aI_-QW@68w9kQ
zi%SAoD;EP7gG42Rh%iVm!vfC9zAk=23`-c6aB)XB%7gSU`vy7rC;$l$AmIaI`2bk~
z5%EAj2!jn}aNzQF4UT8@_4Es7jAr!parS12ZWM)R4t51<@#k<21Cqhc3Y#ss<e354
C3Q0@=

diff --git a/tests/acpi-test-data/pc/SSDT b/tests/acpi-test-data/pc/SSDT
index 558e4c85b031ec081045aec6cc382a680e9c6009..d0103368a0b9e3d5410372f1f589df4eeeebaf03 100644
GIT binary patch
delta 452
zcma)&&r1S96vyAF*)}SuZ6I`LPo2URf=(S=XV-SsS*M*fj1}e(l0jf-9z6M@=q~*O
z9Xjiw|DkjLMD%Yovl3mK!{dFJHy^%lz6&2k%()%bb^y@X67Qqx^6;XQcelD_!K;E1
z&x{uJ6mwai3D>i8%x9)$o`NRYiil^pgNOUO@r^O;jRxc4b#El^cxd5_CP=^wIgHN{
ztYC%o$#QlyZ9FM)v}mNt%FY6Z$L6f{iPIY^VeS7}*RV#$1fm%Wc!)Bv#zr*H#vqHR
z<fF$E!b}t5qh|%RrXjo$MlFyeQ!3yg=sDrkO(emoLtiiYVeKmMntAC1JS)MiMp(-)
zCK1XLt$UpO{Tu2sTcfrg$esU|#ekutV!4b4G8V?AXnvp|NgF}6Y0#kR%F<L_Q+BK)
oWboa194eSPTp;TC97XfJ%`@)E*_LxD3nzx2rYhk37fNjZ0GfqxXaE2J

delta 357
zcmXX>yH3L}6uk}wjMFx>%7DbqgoK$GSV-*vu1Inlo0o#*jAiSFm|8$$fT`*a6e)ke
zKd|x{{SD%V?L4l|J?E#t>M^aQSy2GeowI#%H9r{b&_t$r8vy3Nhtsq6!_kJ-1B*g&
zr6XIsCJf^nL+z!Kol%@zbIy-}Vyul1P|PsSa^e^%Ui^Q8hK74qn+PV(DVJM|5-Rv=
zRV)a*xkTd(G-XwW?b{p;nT#E$Q!8@a>o9gf>Ow%sGkiLUc`8fN2DWN=SI4VVHSx|`
z|8d6d#}l~z#oJ(0Am=UyfGTM%gJwh|P}L(&APj608K?v%kvj;3({<@u(54Y=Jmf@R
hJalv%_EU3y?=Ahsn8CY?f20Dlv@h$b-_rB8{{RBhShxTH

diff --git a/tests/acpi-test-data/q35/DSDT b/tests/acpi-test-data/q35/DSDT
index 8ac32efc0316daeed23e9002aa8bb05fb0fe483f..de430e2a68e203518384b1db75baaefc02f2aa33 100644
GIT binary patch
delta 67
zcmbR2aMX^=CD<jzRi1%?an(jHHEAYap2<ei36s}IXA20pXz9fVJH-b$dm2PHxob|&
Xmoc2YUq+OT(bvb>n_;uM>>DNkc;^zx

delta 292
zcmX?VH`#&9CD<iISb>3oF>oW7nlzKY&}1X&1gYqTfS}+IM(!ItTnf>RJYWuxh<6Z}
zJV`n`BD%?qB_PN(m?Pf9(}l<J0v8)ce5j`juX8}CLPmZ`K~8D9LQ!gQerZv1YB2*x
zymL^nATJk}JL3(W8$1jOl|Z535JxU<0S809_+Y2_0B28w=q6`_$-FX#_0bI;0lq<u
z+zeb?5=dGZxPVZil0ifmq?cg<=VV_OzaWMs3`@AUqZ{QxdYFBKoO~33ga?rD0kM35
ztbmAkpdW<6hB7#C`ML(jGx~b^1v5r7`uaF~GekFvLNo`v0=4*axP}4AU}uHRkuq<X
E05`u%Z~y=R

diff --git a/tests/acpi-test-data/q35/SSDT b/tests/acpi-test-data/q35/SSDT
index 2cb3e08bd4dcd2998ce5f87641ade4b6ce64c695..f86643da45ad89a97a652233cb090516afde7b31 100644
GIT binary patch
delta 375
zcmX|+!Aiq07{|YCV}vw=IV(&&*pnAw7JPxVX|>&!E;gMg9poUx3BqJ^2T!vK-p5|R
zgLw8Cd;*Vq0pG)9q6z%@e&PE*e)*_;R)~~A=9d7_`;zP-e|d05>(;QPq^|^v-DPpO
z2zCwSPu)t(Jc%@vSVeI_y)RP5Y7hrCCI(J4xxc%eUpv#$Y%-r-jb?zA%sgUY#ZtLd
zBjgmV>6#+v0rE$Y$_!a+N}Rl)8_=QJ_5Asm3D<?qv8m$TB7-+3xCff_J_9lXyQad9
zi!_8C7~72`JGm^qTB|X@i&=1kndm2tGD3BRhezeV5AjF@m<LI!?f$iZ=-V_}k>Dw^
zfRJWh>>DWaZtC|Op8AoFo~e4e5*JE~Z*SV6O?W63;&CETUhMpi$x!$9!*d;yId+vB
J!PPhF{s5KbTzCKg

delta 357
zcmXX>J5Iwu5S<MMt=0~K$ORHT4FyX@L4&h4umRf>@A8w8)@A6@QU$O?Llxx$LGl4O
z13l-V#S=5t`;6Ya`S!j%VN7gg4}kqF#6G)T983gH<E#jvoke{(KMNj@Hk=tbR9b2i
zx$-R)nA}?KE_K|WB<YQm@)$TK#`*x|3nqENh_Uk3|0ig9xaW+GU`9^0+FDl7z^B)U
zLAYJSXvsiZHB}hg6=>OPN}SJ~D$H(QhzmxI7<+~fl0;AEY1Tonh4*c|&U6<~*7^<^
zJ9PlmzpO`_3Z<kN0Ip-_1awbC3U&L$34{ZeMiv@{X+#U*;B;NO6^!i!my9J-n2d=|
d!(nF6A9^c)ITi3u@lRY~o(<!+>hhOe{Q;yqSb6{e

-- 
MST

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups
  2015-02-18 21:48 ` [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
@ 2015-02-18 22:03   ` Michael S. Tsirkin
  2015-02-19  7:58     ` Michael S. Tsirkin
  2015-02-19  8:23     ` Peter Maydell
  0 siblings, 2 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-18 22:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell

On Wed, Feb 18, 2015 at 10:48:22PM +0100, Michael S. Tsirkin wrote:
> On Wed, Feb 18, 2015 at 10:43:58PM +0100, Michael S. Tsirkin wrote:
> > A huge patchset, but the scariest part is Igor's patches,
> > and these have been used by multiple people by now.
> > virtio header change is a bit rushed, but getting them upstream
> > seems like the best way to give them the cross-platform
> > testing that they need, and this takes us a step closer to
> > virtio-1.0 support.
> 
> Ugh.
> Missed aarch64 failures this triggers :(
> Pls ignore for now, sorry about the noise.

OK, I think it's a false alarm - passes fine on all other machines,
and on this one, current master gives the same error:

GTESTER check-qtest-aarch64
qemu-system-aarch64: Unknown device 'gpex-pcihost' for default sysbus
Broken pipe
GTester: last random seed: R02Sf2b7ee633e245f2aa40572f893be1567

Peter, you'll run make check anyway - can you pls try merging,
and running make check - if it passes for you too,
then I think this pull is fine, and I'll figure out
what's wrong with this box some other day.

Pls let me know.
Thanks!

> > The following changes since commit cd2d5541271f1934345d8ca42f5fafff1744eee7:
> > 
> >   Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20150212' into staging (2015-02-13 11:44:50 +0000)
> > 
> > are available in the git repository at:
> > 
> >   git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream
> > 
> > for you to fetch changes up to 6b5e5a8361bdff0e75629b1001236d78f27676b6:
> > 
> >   acpi-test: update expected files (2015-02-18 22:29:26 +0100)
> > 
> > ----------------------------------------------------------------
> > pci, pc, virtio fixes and cleanups
> > 
> > Last large pull for soft freeze.
> > 
> > A bunch of fixes all over the place.
> > Most of ACPI refactoring has been merged.
> > 
> > virtio header cleanup has been merged,
> > now that windows has been build-tested with it.
> > 
> > initial patches from virtio-1.0 branch have been merged.
> > 
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > 
> > ----------------------------------------------------------------
> > Cornelia Huck (3):
> >       virtio: cull virtio_bus_set_vdev_features
> >       virtio: feature bit manipulation helpers
> >       virtio: add feature checking helpers
> > 
> > Igor Mammedov (43):
> >       acpi: move generic aml building helpers into dedictated file
> >       acpi: add build_append_namestring() helper
> >       acpi: drop min-bytes in build_package()
> >       pc: acpi-build: update linker on guest access
> >       pc: acpi-build: migrate RSDP table
> >       pc: acpi: use local var for accessing ACPI tables blob in acpi_build()
> >       acpi: introduce AML composer aml_append()
> >       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: 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
> >       acpi: add aml_package() term
> >       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: acpi-build: drop template patching and memory hotplug objects dynamically
> >       pc: acpi-build: create memory hotplug IO region dynamically
> >       acpi: add aml_word_bus_number(), aml_word_io(), aml_dword_memory(), aml_qword_memory() terms
> >       pc: pcihp: expose MMIO base and len as properties
> >       pc: acpi-build: reserve PCIHP MMIO resources
> > 
> > Markus Armbruster (11):
> >       pci: Convert core to realize
> >       pci: Permit incremental conversion of device models to realize
> >       pci: Trivial device model conversions to realize
> >       pcnet: pcnet_common_init() always returns 0, change to void
> >       pcnet: Convert to realize
> >       serial-pci: Convert to realize
> >       ide/ich: Convert to realize
> >       cirrus-vga: Convert to realize
> >       qxl: Convert to realize
> >       pci-assign: Convert to realize
> >       qdev: Don't exit when running into bad -global
> > 
> > Michael S. Tsirkin (32):
> >       acpi-build: fix memory leak with bridge hp off
> >       bios linker: validate pointer within table
> >       acpi: update RSDP on guest access
> >       exec: round up size on MR resize
> >       acpi-build: fix ACPI RAM management
> >       acpi: has_immutable_rsdp->!rsdp_in_ram
> >       acpi-build: simplify rsdp management for legacy
> >       scripts/update-linux-headers.sh: pull virtio hdrs
> >       include: import virtio headers from linux 4.0
> >       virtio: use standard virtio_ring.h
> >       virtio: use standard-headers
> >       virtio-balloon: use standard headers
> >       virtio-9p: use standard headers
> >       virtio-blk: switch to standard-headers
> >       virtio-net,tap: use standard-headers
> >       virtio-rng: use standard-headers
> >       virtio-scsi: use standard-headers
> >       virtio-serial: switch to standard-headers
> >       update-linux-headers: use standard-headers
> >       linux-headers: use standard-headers
> >       virtio-pci: use standard headers
> >       scripts: add arch specific standard-headers
> >       standard-headers: add s390 virtio headers
> >       s390: use standard headers
> >       acpi-build: skip hotplugged bridges
> >       update-linux-headers.sh: s/__inline__/inline/
> >       virtio-serial-bus.c: drop virtio_ids.h
> >       standard-headers: include stdint.h
> >       virtio_ring.h: s/__inline__/inline/
> >       acpi: update generated hex files
> >       acpi: drop unused generated files
> >       acpi-test: update expected files
> > 
> > Peter Krempa (2):
> >       vl.c: Fix error messages when parsing maxmem parameters
> >       pc: memory: Validate alignment of maxram_size to page size
> > 
> > Tang Chen (5):
> >       acpi, pc: Add hotunplug request cb for pc machine.
> >       acpi, ich9: Add hotunplug request cb for ich9.
> >       acpi, pc: Add unplug cb for pc machine.
> >       acpi, ich9: Add unplug cb for ich9.
> >       acpi, piix4: Add unplug cb for piix4.
> > 
> >  hw/9pfs/virtio-9p.h                                |  18 +-
> >  hw/net/pcnet.h                                     |   2 +-
> >  hw/s390x/s390-virtio-bus.h                         |  36 +-
> >  hw/s390x/s390-virtio.h                             |   7 +-
> >  include/hw/acpi/aml-build.h                        | 206 +++++
> >  include/hw/acpi/ich9.h                             |   4 +
> >  include/hw/acpi/pc-hotplug.h                       |   1 +
> >  include/hw/acpi/pcihp.h                            |   7 +-
> >  include/hw/i386/pc.h                               |   1 +
> >  include/hw/pci/pci.h                               |   3 +-
> >  include/hw/qdev-properties.h                       |   4 +-
> >  include/hw/virtio/dataplane/vring.h                |   2 +-
> >  include/hw/virtio/virtio-balloon.h                 |  35 +-
> >  include/hw/virtio/virtio-blk.h                     |  77 +-
> >  include/hw/virtio/virtio-bus.h                     |   3 -
> >  include/hw/virtio/virtio-net.h                     | 151 +---
> >  include/hw/virtio/virtio-rng.h                     |   4 +-
> >  include/hw/virtio/virtio-scsi.h                    | 120 +--
> >  include/hw/virtio/virtio-serial.h                  |  40 +-
> >  include/hw/virtio/virtio.h                         |  71 +-
> >  include/net/tap.h                                  |  24 +-
> >  include/standard-headers/asm-s390/kvm_virtio.h     |  64 ++
> >  include/standard-headers/asm-s390/virtio-ccw.h     |  21 +
> >  include/standard-headers/linux/if_ether.h          |   1 +
> >  include/standard-headers/linux/types.h             |   2 +
> >  include/standard-headers/linux/virtio_9p.h         |  44 ++
> >  include/standard-headers/linux/virtio_balloon.h    |  59 ++
> >  include/standard-headers/linux/virtio_blk.h        | 143 ++++
> >  include/standard-headers/linux/virtio_config.h     |  64 ++
> >  include/standard-headers/linux/virtio_console.h    |  78 ++
> >  include/standard-headers/linux/virtio_ids.h        |  43 +
> >  include/standard-headers/linux/virtio_net.h        | 233 ++++++
> >  include/standard-headers/linux/virtio_pci.h        | 193 +++++
> >  .../linux}/virtio_ring.h                           | 132 ++--
> >  include/standard-headers/linux/virtio_rng.h        |   8 +
> >  include/standard-headers/linux/virtio_scsi.h       | 164 ++++
> >  include/standard-headers/linux/virtio_types.h      |  46 ++
> >  linux-headers/linux/virtio_config.h                |  58 +-
> >  linux-headers/linux/virtio_ring.h                  | 164 +---
> >  exec.c                                             |   2 +
> >  hw/9pfs/virtio-9p-device.c                         |   2 +-
> >  hw/acpi/aml-build.c                                | 867 +++++++++++++++++++++
> >  hw/acpi/bios-linker-loader.c                       |   4 +-
> >  hw/acpi/ich9.c                                     |  14 +
> >  hw/acpi/pcihp.c                                    |  18 +-
> >  hw/acpi/piix4.c                                    |  15 +-
> >  hw/audio/ac97.c                                    |   5 +-
> >  hw/audio/es1370.c                                  |   5 +-
> >  hw/audio/intel-hda.c                               |   6 +-
> >  hw/block/virtio-blk.c                              |  31 +-
> >  hw/char/serial-pci.c                               |  22 +-
> >  hw/char/virtio-serial-bus.c                        |   4 +-
> >  hw/core/qdev-properties.c                          |  21 +-
> >  hw/core/qdev.c                                     |   8 +-
> >  hw/display/cirrus_vga.c                            |  11 +-
> >  hw/display/qxl.c                                   |  36 +-
> >  hw/display/vga-pci.c                               |  11 +-
> >  hw/display/vmware_vga.c                            |   6 +-
> >  hw/i2c/smbus_ich9.c                                |   5 +-
> >  hw/i386/acpi-build.c                               | 750 +++++++++---------
> >  hw/i386/kvm/pci-assign.c                           |  10 +-
> >  hw/i386/pc.c                                       |  23 +
> >  hw/i386/pc_piix.c                                  |   3 +
> >  hw/i386/pc_q35.c                                   |   3 +
> >  hw/ide/cmd646.c                                    |   5 +-
> >  hw/ide/ich.c                                       |  13 +-
> >  hw/ide/piix.c                                      |  10 +-
> >  hw/ide/via.c                                       |   6 +-
> >  hw/ipack/tpci200.c                                 |   6 +-
> >  hw/isa/i82378.c                                    |   6 +-
> >  hw/isa/lpc_ich9.c                                  |  14 +-
> >  hw/isa/piix4.c                                     |   5 +-
> >  hw/isa/vt82c686.c                                  |  24 +-
> >  hw/misc/pci-testdev.c                              |   6 +-
> >  hw/net/e1000.c                                     |   6 +-
> >  hw/net/eepro100.c                                  |   6 +-
> >  hw/net/lance.c                                     |   3 +-
> >  hw/net/ne2000.c                                    |   6 +-
> >  hw/net/pcnet-pci.c                                 |   6 +-
> >  hw/net/pcnet.c                                     |   4 +-
> >  hw/net/rtl8139.c                                   |   6 +-
> >  hw/net/vhost_net.c                                 |   2 +-
> >  hw/net/virtio-net.c                                |  57 +-
> >  hw/net/vmxnet3.c                                   |   6 +-
> >  hw/pci-bridge/dec.c                                |   5 +-
> >  hw/pci-host/apb.c                                  |   5 +-
> >  hw/pci-host/bonito.c                               |   6 +-
> >  hw/pci-host/grackle.c                              |   5 +-
> >  hw/pci-host/piix.c                                 |  12 +-
> >  hw/pci-host/ppce500.c                              |   6 +-
> >  hw/pci-host/prep.c                                 |   6 +-
> >  hw/pci-host/q35.c                                  |   5 +-
> >  hw/pci-host/uninorth.c                             |  20 +-
> >  hw/pci-host/versatile.c                            |   5 +-
> >  hw/pci/pci.c                                       | 113 +--
> >  hw/s390x/virtio-ccw.c                              |   7 +-
> >  hw/scsi/virtio-scsi.c                              |   9 +-
> >  hw/sd/sdhci.c                                      |   5 +-
> >  hw/usb/hcd-ehci-pci.c                              |   6 +-
> >  hw/usb/hcd-xhci.c                                  |   6 +-
> >  hw/virtio/dataplane/vring.c                        |  10 +-
> >  hw/virtio/virtio-balloon.c                         |   2 +-
> >  hw/virtio/virtio-bus.c                             |  14 -
> >  hw/virtio/virtio-mmio.c                            |   2 +-
> >  hw/virtio/virtio-pci.c                             |  58 +-
> >  hw/virtio/virtio.c                                 |  33 +-
> >  hw/watchdog/wdt_i6300esb.c                         |   6 +-
> >  vl.c                                               |  34 +-
> >  hw/acpi/Makefile.objs                              |   1 +
> >  hw/i386/Makefile.objs                              |   6 +-
> >  hw/i386/acpi-dsdt-cpu-hotplug.dsl                  |  17 +-
> >  hw/i386/acpi-dsdt-mem-hotplug.dsl                  |  36 +-
> >  hw/i386/acpi-dsdt.hex.generated                    | 224 +-----
> >  hw/i386/q35-acpi-dsdt.hex.generated                | 224 +-----
> >  hw/i386/ssdt-mem.dsl                               |  77 --
> >  hw/i386/ssdt-mem.hex.generated                     | 213 -----
> >  hw/i386/ssdt-misc.dsl                              |  82 --
> >  hw/i386/ssdt-misc.hex.generated                    | 274 +------
> >  hw/i386/ssdt-proc.dsl                              |  63 --
> >  hw/i386/ssdt-proc.hex.generated                    | 134 ----
> >  scripts/update-linux-headers.sh                    |  52 +-
> >  tests/acpi-test-data/pc/DSDT                       | Bin 3621 -> 3415 bytes
> >  tests/acpi-test-data/pc/SSDT                       | Bin 2279 -> 2374 bytes
> >  tests/acpi-test-data/q35/DSDT                      | Bin 8211 -> 8005 bytes
> >  tests/acpi-test-data/q35/SSDT                      | Bin 560 -> 578 bytes
> >  125 files changed, 3236 insertions(+), 2959 deletions(-)
> >  create mode 100644 include/hw/acpi/aml-build.h
> >  create mode 100644 include/standard-headers/asm-s390/kvm_virtio.h
> >  create mode 100644 include/standard-headers/asm-s390/virtio-ccw.h
> >  create mode 100644 include/standard-headers/linux/if_ether.h
> >  create mode 100644 include/standard-headers/linux/types.h
> >  create mode 100644 include/standard-headers/linux/virtio_9p.h
> >  create mode 100644 include/standard-headers/linux/virtio_balloon.h
> >  create mode 100644 include/standard-headers/linux/virtio_blk.h
> >  create mode 100644 include/standard-headers/linux/virtio_config.h
> >  create mode 100644 include/standard-headers/linux/virtio_console.h
> >  create mode 100644 include/standard-headers/linux/virtio_ids.h
> >  create mode 100644 include/standard-headers/linux/virtio_net.h
> >  create mode 100644 include/standard-headers/linux/virtio_pci.h
> >  rename include/{hw/virtio => standard-headers/linux}/virtio_ring.h (61%)
> >  create mode 100644 include/standard-headers/linux/virtio_rng.h
> >  create mode 100644 include/standard-headers/linux/virtio_scsi.h
> >  create mode 100644 include/standard-headers/linux/virtio_types.h
> >  create mode 100644 hw/acpi/aml-build.c
> >  delete mode 100644 hw/i386/ssdt-mem.dsl
> >  delete mode 100644 hw/i386/ssdt-mem.hex.generated
> >  delete mode 100644 hw/i386/ssdt-proc.dsl
> >  delete mode 100644 hw/i386/ssdt-proc.hex.generated
> > 

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups
  2015-02-18 22:03   ` Michael S. Tsirkin
@ 2015-02-19  7:58     ` Michael S. Tsirkin
  2015-02-19  8:23     ` Peter Maydell
  1 sibling, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-19  7:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell

On Wed, Feb 18, 2015 at 11:03:53PM +0100, Michael S. Tsirkin wrote:
> On Wed, Feb 18, 2015 at 10:48:22PM +0100, Michael S. Tsirkin wrote:
> > On Wed, Feb 18, 2015 at 10:43:58PM +0100, Michael S. Tsirkin wrote:
> > > A huge patchset, but the scariest part is Igor's patches,
> > > and these have been used by multiple people by now.
> > > virtio header change is a bit rushed, but getting them upstream
> > > seems like the best way to give them the cross-platform
> > > testing that they need, and this takes us a step closer to
> > > virtio-1.0 support.
> > 
> > Ugh.
> > Missed aarch64 failures this triggers :(
> > Pls ignore for now, sorry about the noise.
> 
> OK, I think it's a false alarm - passes fine on all other machines,
> and on this one, current master gives the same error:
> 
> GTESTER check-qtest-aarch64
> qemu-system-aarch64: Unknown device 'gpex-pcihost' for default sysbus
> Broken pipe
> GTester: last random seed: R02Sf2b7ee633e245f2aa40572f893be1567
> 
> Peter, you'll run make check anyway - can you pls try merging,
> and running make check - if it passes for you too,
> then I think this pull is fine, and I'll figure out
> what's wrong with this box some other day.
> 
> Pls let me know.
> Thanks!

OK, this was because of some stale files apparently.
Regenerating config-devices made it go away.
Pls pull.

> > > The following changes since commit cd2d5541271f1934345d8ca42f5fafff1744eee7:
> > > 
> > >   Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20150212' into staging (2015-02-13 11:44:50 +0000)
> > > 
> > > are available in the git repository at:
> > > 
> > >   git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream
> > > 
> > > for you to fetch changes up to 6b5e5a8361bdff0e75629b1001236d78f27676b6:
> > > 
> > >   acpi-test: update expected files (2015-02-18 22:29:26 +0100)
> > > 
> > > ----------------------------------------------------------------
> > > pci, pc, virtio fixes and cleanups
> > > 
> > > Last large pull for soft freeze.
> > > 
> > > A bunch of fixes all over the place.
> > > Most of ACPI refactoring has been merged.
> > > 
> > > virtio header cleanup has been merged,
> > > now that windows has been build-tested with it.
> > > 
> > > initial patches from virtio-1.0 branch have been merged.
> > > 
> > > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > > 
> > > ----------------------------------------------------------------
> > > Cornelia Huck (3):
> > >       virtio: cull virtio_bus_set_vdev_features
> > >       virtio: feature bit manipulation helpers
> > >       virtio: add feature checking helpers
> > > 
> > > Igor Mammedov (43):
> > >       acpi: move generic aml building helpers into dedictated file
> > >       acpi: add build_append_namestring() helper
> > >       acpi: drop min-bytes in build_package()
> > >       pc: acpi-build: update linker on guest access
> > >       pc: acpi-build: migrate RSDP table
> > >       pc: acpi: use local var for accessing ACPI tables blob in acpi_build()
> > >       acpi: introduce AML composer aml_append()
> > >       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: 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
> > >       acpi: add aml_package() term
> > >       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: acpi-build: drop template patching and memory hotplug objects dynamically
> > >       pc: acpi-build: create memory hotplug IO region dynamically
> > >       acpi: add aml_word_bus_number(), aml_word_io(), aml_dword_memory(), aml_qword_memory() terms
> > >       pc: pcihp: expose MMIO base and len as properties
> > >       pc: acpi-build: reserve PCIHP MMIO resources
> > > 
> > > Markus Armbruster (11):
> > >       pci: Convert core to realize
> > >       pci: Permit incremental conversion of device models to realize
> > >       pci: Trivial device model conversions to realize
> > >       pcnet: pcnet_common_init() always returns 0, change to void
> > >       pcnet: Convert to realize
> > >       serial-pci: Convert to realize
> > >       ide/ich: Convert to realize
> > >       cirrus-vga: Convert to realize
> > >       qxl: Convert to realize
> > >       pci-assign: Convert to realize
> > >       qdev: Don't exit when running into bad -global
> > > 
> > > Michael S. Tsirkin (32):
> > >       acpi-build: fix memory leak with bridge hp off
> > >       bios linker: validate pointer within table
> > >       acpi: update RSDP on guest access
> > >       exec: round up size on MR resize
> > >       acpi-build: fix ACPI RAM management
> > >       acpi: has_immutable_rsdp->!rsdp_in_ram
> > >       acpi-build: simplify rsdp management for legacy
> > >       scripts/update-linux-headers.sh: pull virtio hdrs
> > >       include: import virtio headers from linux 4.0
> > >       virtio: use standard virtio_ring.h
> > >       virtio: use standard-headers
> > >       virtio-balloon: use standard headers
> > >       virtio-9p: use standard headers
> > >       virtio-blk: switch to standard-headers
> > >       virtio-net,tap: use standard-headers
> > >       virtio-rng: use standard-headers
> > >       virtio-scsi: use standard-headers
> > >       virtio-serial: switch to standard-headers
> > >       update-linux-headers: use standard-headers
> > >       linux-headers: use standard-headers
> > >       virtio-pci: use standard headers
> > >       scripts: add arch specific standard-headers
> > >       standard-headers: add s390 virtio headers
> > >       s390: use standard headers
> > >       acpi-build: skip hotplugged bridges
> > >       update-linux-headers.sh: s/__inline__/inline/
> > >       virtio-serial-bus.c: drop virtio_ids.h
> > >       standard-headers: include stdint.h
> > >       virtio_ring.h: s/__inline__/inline/
> > >       acpi: update generated hex files
> > >       acpi: drop unused generated files
> > >       acpi-test: update expected files
> > > 
> > > Peter Krempa (2):
> > >       vl.c: Fix error messages when parsing maxmem parameters
> > >       pc: memory: Validate alignment of maxram_size to page size
> > > 
> > > Tang Chen (5):
> > >       acpi, pc: Add hotunplug request cb for pc machine.
> > >       acpi, ich9: Add hotunplug request cb for ich9.
> > >       acpi, pc: Add unplug cb for pc machine.
> > >       acpi, ich9: Add unplug cb for ich9.
> > >       acpi, piix4: Add unplug cb for piix4.
> > > 
> > >  hw/9pfs/virtio-9p.h                                |  18 +-
> > >  hw/net/pcnet.h                                     |   2 +-
> > >  hw/s390x/s390-virtio-bus.h                         |  36 +-
> > >  hw/s390x/s390-virtio.h                             |   7 +-
> > >  include/hw/acpi/aml-build.h                        | 206 +++++
> > >  include/hw/acpi/ich9.h                             |   4 +
> > >  include/hw/acpi/pc-hotplug.h                       |   1 +
> > >  include/hw/acpi/pcihp.h                            |   7 +-
> > >  include/hw/i386/pc.h                               |   1 +
> > >  include/hw/pci/pci.h                               |   3 +-
> > >  include/hw/qdev-properties.h                       |   4 +-
> > >  include/hw/virtio/dataplane/vring.h                |   2 +-
> > >  include/hw/virtio/virtio-balloon.h                 |  35 +-
> > >  include/hw/virtio/virtio-blk.h                     |  77 +-
> > >  include/hw/virtio/virtio-bus.h                     |   3 -
> > >  include/hw/virtio/virtio-net.h                     | 151 +---
> > >  include/hw/virtio/virtio-rng.h                     |   4 +-
> > >  include/hw/virtio/virtio-scsi.h                    | 120 +--
> > >  include/hw/virtio/virtio-serial.h                  |  40 +-
> > >  include/hw/virtio/virtio.h                         |  71 +-
> > >  include/net/tap.h                                  |  24 +-
> > >  include/standard-headers/asm-s390/kvm_virtio.h     |  64 ++
> > >  include/standard-headers/asm-s390/virtio-ccw.h     |  21 +
> > >  include/standard-headers/linux/if_ether.h          |   1 +
> > >  include/standard-headers/linux/types.h             |   2 +
> > >  include/standard-headers/linux/virtio_9p.h         |  44 ++
> > >  include/standard-headers/linux/virtio_balloon.h    |  59 ++
> > >  include/standard-headers/linux/virtio_blk.h        | 143 ++++
> > >  include/standard-headers/linux/virtio_config.h     |  64 ++
> > >  include/standard-headers/linux/virtio_console.h    |  78 ++
> > >  include/standard-headers/linux/virtio_ids.h        |  43 +
> > >  include/standard-headers/linux/virtio_net.h        | 233 ++++++
> > >  include/standard-headers/linux/virtio_pci.h        | 193 +++++
> > >  .../linux}/virtio_ring.h                           | 132 ++--
> > >  include/standard-headers/linux/virtio_rng.h        |   8 +
> > >  include/standard-headers/linux/virtio_scsi.h       | 164 ++++
> > >  include/standard-headers/linux/virtio_types.h      |  46 ++
> > >  linux-headers/linux/virtio_config.h                |  58 +-
> > >  linux-headers/linux/virtio_ring.h                  | 164 +---
> > >  exec.c                                             |   2 +
> > >  hw/9pfs/virtio-9p-device.c                         |   2 +-
> > >  hw/acpi/aml-build.c                                | 867 +++++++++++++++++++++
> > >  hw/acpi/bios-linker-loader.c                       |   4 +-
> > >  hw/acpi/ich9.c                                     |  14 +
> > >  hw/acpi/pcihp.c                                    |  18 +-
> > >  hw/acpi/piix4.c                                    |  15 +-
> > >  hw/audio/ac97.c                                    |   5 +-
> > >  hw/audio/es1370.c                                  |   5 +-
> > >  hw/audio/intel-hda.c                               |   6 +-
> > >  hw/block/virtio-blk.c                              |  31 +-
> > >  hw/char/serial-pci.c                               |  22 +-
> > >  hw/char/virtio-serial-bus.c                        |   4 +-
> > >  hw/core/qdev-properties.c                          |  21 +-
> > >  hw/core/qdev.c                                     |   8 +-
> > >  hw/display/cirrus_vga.c                            |  11 +-
> > >  hw/display/qxl.c                                   |  36 +-
> > >  hw/display/vga-pci.c                               |  11 +-
> > >  hw/display/vmware_vga.c                            |   6 +-
> > >  hw/i2c/smbus_ich9.c                                |   5 +-
> > >  hw/i386/acpi-build.c                               | 750 +++++++++---------
> > >  hw/i386/kvm/pci-assign.c                           |  10 +-
> > >  hw/i386/pc.c                                       |  23 +
> > >  hw/i386/pc_piix.c                                  |   3 +
> > >  hw/i386/pc_q35.c                                   |   3 +
> > >  hw/ide/cmd646.c                                    |   5 +-
> > >  hw/ide/ich.c                                       |  13 +-
> > >  hw/ide/piix.c                                      |  10 +-
> > >  hw/ide/via.c                                       |   6 +-
> > >  hw/ipack/tpci200.c                                 |   6 +-
> > >  hw/isa/i82378.c                                    |   6 +-
> > >  hw/isa/lpc_ich9.c                                  |  14 +-
> > >  hw/isa/piix4.c                                     |   5 +-
> > >  hw/isa/vt82c686.c                                  |  24 +-
> > >  hw/misc/pci-testdev.c                              |   6 +-
> > >  hw/net/e1000.c                                     |   6 +-
> > >  hw/net/eepro100.c                                  |   6 +-
> > >  hw/net/lance.c                                     |   3 +-
> > >  hw/net/ne2000.c                                    |   6 +-
> > >  hw/net/pcnet-pci.c                                 |   6 +-
> > >  hw/net/pcnet.c                                     |   4 +-
> > >  hw/net/rtl8139.c                                   |   6 +-
> > >  hw/net/vhost_net.c                                 |   2 +-
> > >  hw/net/virtio-net.c                                |  57 +-
> > >  hw/net/vmxnet3.c                                   |   6 +-
> > >  hw/pci-bridge/dec.c                                |   5 +-
> > >  hw/pci-host/apb.c                                  |   5 +-
> > >  hw/pci-host/bonito.c                               |   6 +-
> > >  hw/pci-host/grackle.c                              |   5 +-
> > >  hw/pci-host/piix.c                                 |  12 +-
> > >  hw/pci-host/ppce500.c                              |   6 +-
> > >  hw/pci-host/prep.c                                 |   6 +-
> > >  hw/pci-host/q35.c                                  |   5 +-
> > >  hw/pci-host/uninorth.c                             |  20 +-
> > >  hw/pci-host/versatile.c                            |   5 +-
> > >  hw/pci/pci.c                                       | 113 +--
> > >  hw/s390x/virtio-ccw.c                              |   7 +-
> > >  hw/scsi/virtio-scsi.c                              |   9 +-
> > >  hw/sd/sdhci.c                                      |   5 +-
> > >  hw/usb/hcd-ehci-pci.c                              |   6 +-
> > >  hw/usb/hcd-xhci.c                                  |   6 +-
> > >  hw/virtio/dataplane/vring.c                        |  10 +-
> > >  hw/virtio/virtio-balloon.c                         |   2 +-
> > >  hw/virtio/virtio-bus.c                             |  14 -
> > >  hw/virtio/virtio-mmio.c                            |   2 +-
> > >  hw/virtio/virtio-pci.c                             |  58 +-
> > >  hw/virtio/virtio.c                                 |  33 +-
> > >  hw/watchdog/wdt_i6300esb.c                         |   6 +-
> > >  vl.c                                               |  34 +-
> > >  hw/acpi/Makefile.objs                              |   1 +
> > >  hw/i386/Makefile.objs                              |   6 +-
> > >  hw/i386/acpi-dsdt-cpu-hotplug.dsl                  |  17 +-
> > >  hw/i386/acpi-dsdt-mem-hotplug.dsl                  |  36 +-
> > >  hw/i386/acpi-dsdt.hex.generated                    | 224 +-----
> > >  hw/i386/q35-acpi-dsdt.hex.generated                | 224 +-----
> > >  hw/i386/ssdt-mem.dsl                               |  77 --
> > >  hw/i386/ssdt-mem.hex.generated                     | 213 -----
> > >  hw/i386/ssdt-misc.dsl                              |  82 --
> > >  hw/i386/ssdt-misc.hex.generated                    | 274 +------
> > >  hw/i386/ssdt-proc.dsl                              |  63 --
> > >  hw/i386/ssdt-proc.hex.generated                    | 134 ----
> > >  scripts/update-linux-headers.sh                    |  52 +-
> > >  tests/acpi-test-data/pc/DSDT                       | Bin 3621 -> 3415 bytes
> > >  tests/acpi-test-data/pc/SSDT                       | Bin 2279 -> 2374 bytes
> > >  tests/acpi-test-data/q35/DSDT                      | Bin 8211 -> 8005 bytes
> > >  tests/acpi-test-data/q35/SSDT                      | Bin 560 -> 578 bytes
> > >  125 files changed, 3236 insertions(+), 2959 deletions(-)
> > >  create mode 100644 include/hw/acpi/aml-build.h
> > >  create mode 100644 include/standard-headers/asm-s390/kvm_virtio.h
> > >  create mode 100644 include/standard-headers/asm-s390/virtio-ccw.h
> > >  create mode 100644 include/standard-headers/linux/if_ether.h
> > >  create mode 100644 include/standard-headers/linux/types.h
> > >  create mode 100644 include/standard-headers/linux/virtio_9p.h
> > >  create mode 100644 include/standard-headers/linux/virtio_balloon.h
> > >  create mode 100644 include/standard-headers/linux/virtio_blk.h
> > >  create mode 100644 include/standard-headers/linux/virtio_config.h
> > >  create mode 100644 include/standard-headers/linux/virtio_console.h
> > >  create mode 100644 include/standard-headers/linux/virtio_ids.h
> > >  create mode 100644 include/standard-headers/linux/virtio_net.h
> > >  create mode 100644 include/standard-headers/linux/virtio_pci.h
> > >  rename include/{hw/virtio => standard-headers/linux}/virtio_ring.h (61%)
> > >  create mode 100644 include/standard-headers/linux/virtio_rng.h
> > >  create mode 100644 include/standard-headers/linux/virtio_scsi.h
> > >  create mode 100644 include/standard-headers/linux/virtio_types.h
> > >  create mode 100644 hw/acpi/aml-build.c
> > >  delete mode 100644 hw/i386/ssdt-mem.dsl
> > >  delete mode 100644 hw/i386/ssdt-mem.hex.generated
> > >  delete mode 100644 hw/i386/ssdt-proc.dsl
> > >  delete mode 100644 hw/i386/ssdt-proc.hex.generated
> > > 

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups
  2015-02-18 22:03   ` Michael S. Tsirkin
  2015-02-19  7:58     ` Michael S. Tsirkin
@ 2015-02-19  8:23     ` Peter Maydell
  1 sibling, 0 replies; 111+ messages in thread
From: Peter Maydell @ 2015-02-19  8:23 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: QEMU Developers

On 19 February 2015 at 07:03, Michael S. Tsirkin <mst@redhat.com> wrote:
> OK, I think it's a false alarm - passes fine on all other machines,
> and on this one, current master gives the same error:
>
> GTESTER check-qtest-aarch64
> qemu-system-aarch64: Unknown device 'gpex-pcihost' for default sysbus
> Broken pipe
> GTester: last random seed: R02Sf2b7ee633e245f2aa40572f893be1567

As you seem to have discovered, this is just because your
build tree has stale files in it:
http://lists.gnu.org/archive/html/qemu-devel/2015-02/msg02607.html
It's one of those things where we made a change to our makefiles
(in fact a change from over a year ago, I think), and the new
dependency rules are self-consistent but don't provide an
"upgrade" path for ensuring correct files are generated
starting from a pre-change build tree state.

As far as I can tell, once you've caused the make_device_config.sh
script to get run once, the .d files will all be present so that
future changes like this aarch64 one to pci.mak or other included
files will correctly trigger rebuilds.

thanks
-- PMM

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (96 preceding siblings ...)
  2015-02-18 21:53 ` [Qemu-devel] [PULL 96/96] acpi-test: update expected files Michael S. Tsirkin
@ 2015-02-24 16:47 ` Michael S. Tsirkin
  2015-02-26 11:17 ` Peter Maydell
  98 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-24 16:47 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, dgilbert, Juan Quintela

On Wed, Feb 18, 2015 at 10:43:35PM +0100, Michael S. Tsirkin wrote:
> A huge patchset, but the scariest part is Igor's patches,
> and these have been used by multiple people by now.
> virtio header change is a bit rushed, but getting them upstream
> seems like the best way to give them the cross-platform
> testing that they need, and this takes us a step closer to
> virtio-1.0 support.

Hi Peter,
I'm going to assume this pull request is okay and
queue more stuff on top, but if there's a problem
with it, I'd appreciate if you let me know.

-- 
MST

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups
  2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
                   ` (97 preceding siblings ...)
  2015-02-24 16:47 ` [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
@ 2015-02-26 11:17 ` Peter Maydell
  2015-02-26 11:41   ` Michael S. Tsirkin
  2015-02-26 11:53   ` Michael S. Tsirkin
  98 siblings, 2 replies; 111+ messages in thread
From: Peter Maydell @ 2015-02-26 11:17 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: QEMU Developers, Dr. David Alan Gilbert, Juan Quintela

On 19 February 2015 at 06:43, Michael S. Tsirkin <mst@redhat.com> wrote:
> A huge patchset, but the scariest part is Igor's patches,
> and these have been used by multiple people by now.
> virtio header change is a bit rushed, but getting them upstream
> seems like the best way to give them the cross-platform
> testing that they need, and this takes us a step closer to
> virtio-1.0 support.
>
> The following changes since commit cd2d5541271f1934345d8ca42f5fafff1744eee7:
>
>   Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20150212' into staging (2015-02-13 11:44:50 +0000)
>
> are available in the git repository at:
>
>   git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream
>
> for you to fetch changes up to 6b5e5a8361bdff0e75629b1001236d78f27676b6:
>
>   acpi-test: update expected files (2015-02-18 22:29:26 +0100)
>
> ----------------------------------------------------------------
> pci, pc, virtio fixes and cleanups
>
> Last large pull for soft freeze.
>
> A bunch of fixes all over the place.
> Most of ACPI refactoring has been merged.
>
> virtio header cleanup has been merged,
> now that windows has been build-tested with it.
>
> initial patches from virtio-1.0 branch have been merged.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>
> ----------------------------------------------------------------

Hi. I'm afraid this fails to build:

  CP i386-softmmu/hw/i386/acpi-dsdt.hex
  CP i386-softmmu/hw/i386/q35-acpi-dsdt.hex
make[1]: *** No rule to make target
`/home/petmay01/linaro/qemu-for-merges/hw/i386/ssdt-proc.dsl', needed
by `hw/i386/ssdt-proc.hex'.  Stop.
make[1]: *** Waiting for unfinished jobs....

(There were also a bunch of conflicts in the virtio
stuff which you'll need to fix up when you rebase.)

thanks
-- PMM

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups
  2015-02-26 11:17 ` Peter Maydell
@ 2015-02-26 11:41   ` Michael S. Tsirkin
  2015-02-26 11:59     ` Peter Maydell
  2015-02-26 11:53   ` Michael S. Tsirkin
  1 sibling, 1 reply; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-26 11:41 UTC (permalink / raw)
  To: Peter Maydell; +Cc: QEMU Developers, Dr. David Alan Gilbert, Juan Quintela

On Thu, Feb 26, 2015 at 08:17:43PM +0900, Peter Maydell wrote:
> On 19 February 2015 at 06:43, Michael S. Tsirkin <mst@redhat.com> wrote:
> > A huge patchset, but the scariest part is Igor's patches,
> > and these have been used by multiple people by now.
> > virtio header change is a bit rushed, but getting them upstream
> > seems like the best way to give them the cross-platform
> > testing that they need, and this takes us a step closer to
> > virtio-1.0 support.
> >
> > The following changes since commit cd2d5541271f1934345d8ca42f5fafff1744eee7:
> >
> >   Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20150212' into staging (2015-02-13 11:44:50 +0000)
> >
> > are available in the git repository at:
> >
> >   git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream
> >
> > for you to fetch changes up to 6b5e5a8361bdff0e75629b1001236d78f27676b6:
> >
> >   acpi-test: update expected files (2015-02-18 22:29:26 +0100)
> >
> > ----------------------------------------------------------------
> > pci, pc, virtio fixes and cleanups
> >
> > Last large pull for soft freeze.
> >
> > A bunch of fixes all over the place.
> > Most of ACPI refactoring has been merged.
> >
> > virtio header cleanup has been merged,
> > now that windows has been build-tested with it.
> >
> > initial patches from virtio-1.0 branch have been merged.
> >
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> >
> > ----------------------------------------------------------------
> 
> Hi. I'm afraid this fails to build:
> 
>   CP i386-softmmu/hw/i386/acpi-dsdt.hex
>   CP i386-softmmu/hw/i386/q35-acpi-dsdt.hex
> make[1]: *** No rule to make target
> `/home/petmay01/linaro/qemu-for-merges/hw/i386/ssdt-proc.dsl', needed
> by `hw/i386/ssdt-proc.hex'.  Stop.
> make[1]: *** Waiting for unfinished jobs....

Are you sure it's a clean build?
This often results from a stale .d file.

> (There were also a bunch of conflicts in the virtio
> stuff which you'll need to fix up when you rebase.)
> 
> thanks
> -- PMM

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups
  2015-02-26 11:17 ` Peter Maydell
  2015-02-26 11:41   ` Michael S. Tsirkin
@ 2015-02-26 11:53   ` Michael S. Tsirkin
  1 sibling, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-26 11:53 UTC (permalink / raw)
  To: Peter Maydell; +Cc: QEMU Developers, Dr. David Alan Gilbert, Juan Quintela

On Thu, Feb 26, 2015 at 08:17:43PM +0900, Peter Maydell wrote:
> On 19 February 2015 at 06:43, Michael S. Tsirkin <mst@redhat.com> wrote:
> > A huge patchset, but the scariest part is Igor's patches,
> > and these have been used by multiple people by now.
> > virtio header change is a bit rushed, but getting them upstream
> > seems like the best way to give them the cross-platform
> > testing that they need, and this takes us a step closer to
> > virtio-1.0 support.
> >
> > The following changes since commit cd2d5541271f1934345d8ca42f5fafff1744eee7:
> >
> >   Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20150212' into staging (2015-02-13 11:44:50 +0000)
> >
> > are available in the git repository at:
> >
> >   git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream
> >
> > for you to fetch changes up to 6b5e5a8361bdff0e75629b1001236d78f27676b6:
> >
> >   acpi-test: update expected files (2015-02-18 22:29:26 +0100)
> >
> > ----------------------------------------------------------------
> > pci, pc, virtio fixes and cleanups
> >
> > Last large pull for soft freeze.
> >
> > A bunch of fixes all over the place.
> > Most of ACPI refactoring has been merged.
> >
> > virtio header cleanup has been merged,
> > now that windows has been build-tested with it.
> >
> > initial patches from virtio-1.0 branch have been merged.
> >
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> >
> > ----------------------------------------------------------------
> 
> Hi. I'm afraid this fails to build:
> 
>   CP i386-softmmu/hw/i386/acpi-dsdt.hex
>   CP i386-softmmu/hw/i386/q35-acpi-dsdt.hex
> make[1]: *** No rule to make target
> `/home/petmay01/linaro/qemu-for-merges/hw/i386/ssdt-proc.dsl', needed
> by `hw/i386/ssdt-proc.hex'.  Stop.
> make[1]: *** Waiting for unfinished jobs....
> 
> (There were also a bunch of conflicts in the virtio
> stuff which you'll need to fix up when you rebase.)
> 
> thanks
> -- PMM

I did the rebase to make it easy for you: pushed to
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git rebase_upstream_rebased
pls take a look.

But I couldn't reproduce your build issues.

-- 
MST

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups
  2015-02-26 11:41   ` Michael S. Tsirkin
@ 2015-02-26 11:59     ` Peter Maydell
  2015-02-26 12:06       ` Michael S. Tsirkin
  0 siblings, 1 reply; 111+ messages in thread
From: Peter Maydell @ 2015-02-26 11:59 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: QEMU Developers, Dr. David Alan Gilbert, Juan Quintela

On 26 February 2015 at 20:41, Michael S. Tsirkin <mst@redhat.com> wrote:
> On Thu, Feb 26, 2015 at 08:17:43PM +0900, Peter Maydell wrote:
>> Hi. I'm afraid this fails to build:
>>
>>   CP i386-softmmu/hw/i386/acpi-dsdt.hex
>>   CP i386-softmmu/hw/i386/q35-acpi-dsdt.hex
>> make[1]: *** No rule to make target
>> `/home/petmay01/linaro/qemu-for-merges/hw/i386/ssdt-proc.dsl', needed
>> by `hw/i386/ssdt-proc.hex'.  Stop.
>> make[1]: *** Waiting for unfinished jobs....
>
> Are you sure it's a clean build?
> This often results from a stale .d file.

No, it's not a clean build, because I like to test both
clean and incremental rebuilds. Most of my other builds
seemed OK, but this one bombed out.

-- PMM

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups
  2015-02-26 11:59     ` Peter Maydell
@ 2015-02-26 12:06       ` Michael S. Tsirkin
  0 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-02-26 12:06 UTC (permalink / raw)
  To: Peter Maydell; +Cc: QEMU Developers, Dr. David Alan Gilbert, Juan Quintela

On Thu, Feb 26, 2015 at 08:59:47PM +0900, Peter Maydell wrote:
> On 26 February 2015 at 20:41, Michael S. Tsirkin <mst@redhat.com> wrote:
> > On Thu, Feb 26, 2015 at 08:17:43PM +0900, Peter Maydell wrote:
> >> Hi. I'm afraid this fails to build:
> >>
> >>   CP i386-softmmu/hw/i386/acpi-dsdt.hex
> >>   CP i386-softmmu/hw/i386/q35-acpi-dsdt.hex
> >> make[1]: *** No rule to make target
> >> `/home/petmay01/linaro/qemu-for-merges/hw/i386/ssdt-proc.dsl', needed
> >> by `hw/i386/ssdt-proc.hex'.  Stop.
> >> make[1]: *** Waiting for unfinished jobs....
> >
> > Are you sure it's a clean build?
> > This often results from a stale .d file.
> 
> No, it's not a clean build, because I like to test both
> clean and incremental rebuilds. Most of my other builds
> seemed OK, but this one bombed out.
> 
> -- PMM

Well, it's known that incremental builds are best
effort, isn't it?

Wrt rebase, it's now on kernel.org, tag for_upstream_rebased: 1d40f18

rebased with only a trivial conflict.

-- 
MST

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [Qemu-devel] [PULL 40/96] virtio-scsi: use standard-headers
  2015-02-18 21:48 ` [Qemu-devel] [PULL 40/96] virtio-scsi: " Michael S. Tsirkin
@ 2015-03-11  7:14   ` Fam Zheng
  2015-03-11  8:31     ` Michael S. Tsirkin
  0 siblings, 1 reply; 111+ messages in thread
From: Fam Zheng @ 2015-03-11  7:14 UTC (permalink / raw)
  To: Paolo Bonzini, Michael S. Tsirkin
  Cc: Peter Maydell, Juan Quintela, qemu-devel, Anthony Liguori, dgilbert

On Wed, 02/18 22:48, Michael S. Tsirkin wrote:
> Drop duplicated code.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> Acked-by: Paolo Bonzini <pbonzini@redhat.com>

Michael, this breaks virtio-scsi-pci:

    qemu-system-x86_64: wrong size for virtio-scsi headers

Because:

> -
> -/* SCSI command request, followed by CDB and data-out */
> -typedef struct {
> -    uint8_t lun[8];              /* Logical Unit Number */
> -    uint64_t tag;                /* Command identifier */
> -    uint8_t task_attr;           /* Task attribute */
> -    uint8_t prio;
> -    uint8_t crn;

This doesn't have the cdb array (it is dynamically alloated and appended to the
end of VirtIOSCSIReq, the allocation size depends on guest configured
cdb_size)...

> -} QEMU_PACKED VirtIOSCSICmdReq;
> -

<snip>

> -typedef struct {
> -    uint32_t num_queues;
> -    uint32_t seg_max;
> -    uint32_t max_sectors;
> -    uint32_t cmd_per_lun;
> -    uint32_t event_info_size;
> -    uint32_t sense_size;
> -    uint32_t cdb_size;
> -    uint16_t max_channel;
> -    uint16_t max_target;
> -    uint32_t max_lun;
> -} QEMU_PACKED VirtIOSCSIConfig;
> +typedef struct virtio_scsi_cmd_req VirtIOSCSICmdReq;

But in virtio_scsi_cmd_req:

    /* SCSI command request, followed by data-out */
    struct virtio_scsi_cmd_req {
            uint8_t lun[8];         /* Logical Unit Number */
            __virtio64 tag;         /* Command identifier */
            uint8_t task_attr;              /* Task attribute */
            uint8_t prio;           /* SAM command priority field */
            uint8_t crn;
            uint8_t cdb[VIRTIO_SCSI_CDB_SIZE];
    } QEMU_PACKED;

the cdb array is fixed and inlined.

Fam

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [Qemu-devel] [PULL 40/96] virtio-scsi: use standard-headers
  2015-03-11  7:14   ` Fam Zheng
@ 2015-03-11  8:31     ` Michael S. Tsirkin
  2015-03-11  9:48       ` Paolo Bonzini
  0 siblings, 1 reply; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-03-11  8:31 UTC (permalink / raw)
  To: Fam Zheng
  Cc: Peter Maydell, Juan Quintela, qemu-devel, dgilbert,
	Anthony Liguori, Paolo Bonzini

On Wed, Mar 11, 2015 at 03:14:16PM +0800, Fam Zheng wrote:
> On Wed, 02/18 22:48, Michael S. Tsirkin wrote:
> > Drop duplicated code.
> > 
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > Acked-by: Paolo Bonzini <pbonzini@redhat.com>
> 
> Michael, this breaks virtio-scsi-pci:
> 
>     qemu-system-x86_64: wrong size for virtio-scsi headers

Testing this now.

diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h
index de2c739..25d96f3 100644
--- a/include/hw/virtio/virtio-scsi.h
+++ b/include/hw/virtio/virtio-scsi.h
@@ -136,15 +136,15 @@ typedef struct VirtIOSCSIReq {
     union {
         struct {
             VirtIOSCSICmdReq  cmd;
-            uint8_t           cdb[];
         } QEMU_PACKED;
         VirtIOSCSICtrlTMFReq  tmf;
         VirtIOSCSICtrlANReq   an;
     } req;
 } VirtIOSCSIReq;
 
-QEMU_BUILD_BUG_ON(offsetof(VirtIOSCSIReq, req.cdb) !=
-                  offsetof(VirtIOSCSIReq, req.cmd) + sizeof(VirtIOSCSICmdReq));
+QEMU_BUILD_BUG_ON(offsetof(VirtIOSCSIReq, req.cmd.cdb) !=
+                  offsetof(VirtIOSCSIReq, req.cmd) +
+                  offsetof(VirtIOSCSICmdReq, cdb));
 
 #define DEFINE_VIRTIO_SCSI_PROPERTIES(_state, _conf_field)                     \
     DEFINE_PROP_UINT32("num_queues", _state, _conf_field.num_queues, 1),       \
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index cfb52e8..52bc00c 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -47,7 +47,8 @@ VirtIOSCSIReq *virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq)
     const size_t zero_skip = offsetof(VirtIOSCSIReq, elem)
                              + sizeof(VirtQueueElement);
 
-    req = g_slice_alloc(sizeof(*req) + vs->cdb_size);
+    req = g_slice_alloc(sizeof(*req) + MAX(vs->cdb_size, VIRTIO_SCSI_CDB_SIZE) -
+                        VIRTIO_SCSI_CDB_SIZE);
     req->vq = vq;
     req->dev = s;
     qemu_sglist_init(&req->qsgl, DEVICE(s), 8, &address_space_memory);
@@ -62,7 +63,8 @@ void virtio_scsi_free_req(VirtIOSCSIReq *req)
 
     qemu_iovec_destroy(&req->resp_iov);
     qemu_sglist_destroy(&req->qsgl);
-    g_slice_free1(sizeof(*req) + vs->cdb_size, req);
+    g_slice_free1(sizeof(*req) + MAX(vs->cdb_size, VIRTIO_SCSI_CDB_SIZE) -
+                        VIRTIO_SCSI_CDB_SIZE, req);
 }
 
 static void virtio_scsi_complete_req(VirtIOSCSIReq *req)
@@ -213,8 +215,10 @@ static void *virtio_scsi_load_request(QEMUFile *f, SCSIRequest *sreq)
     assert(req->elem.in_num <= ARRAY_SIZE(req->elem.in_sg));
     assert(req->elem.out_num <= ARRAY_SIZE(req->elem.out_sg));
 
-    if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICmdReq) + vs->cdb_size,
-                              sizeof(VirtIOSCSICmdResp) + vs->sense_size) < 0) {
+    if (virtio_scsi_parse_req(req, offsetof(VirtIOSCSICmdReq, cdb) +
+                              vs->cdb_size,
+                              offsetof(VirtIOSCSICmdResp, sense) +
+                              vs->sense_size) < 0) {
         error_report("invalid SCSI request migration data");
         exit(1);
     }
@@ -439,7 +443,7 @@ static void virtio_scsi_complete_cmd_req(VirtIOSCSIReq *req)
     /* Sense data is not in req->resp and is copied separately
      * in virtio_scsi_command_complete.
      */
-    req->resp_size = sizeof(VirtIOSCSICmdResp);
+    req->resp_size = offsetof(VirtIOSCSICmdResp, sense);
     virtio_scsi_complete_req(req);
 }
 
@@ -462,8 +466,10 @@ static void virtio_scsi_command_complete(SCSIRequest *r, uint32_t status,
     } else {
         req->resp.cmd.resid = 0;
         sense_len = scsi_req_get_sense(r, sense, sizeof(sense));
-        sense_len = MIN(sense_len, req->resp_iov.size - sizeof(req->resp.cmd));
-        qemu_iovec_from_buf(&req->resp_iov, sizeof(req->resp.cmd),
+        sense_len = MIN(sense_len, req->resp_iov.size -
+                        offsetof(typeof(req->resp.cmd), sense));
+        qemu_iovec_from_buf(&req->resp_iov,
+                            offsetof(typeof(req->resp.cmd), sense),
                             sense, sense_len);
         req->resp.cmd.sense_len = virtio_tswap32(vdev, sense_len);
     }
@@ -522,8 +528,10 @@ bool virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req)
     SCSIDevice *d;
     int rc;
 
-    rc = virtio_scsi_parse_req(req, sizeof(VirtIOSCSICmdReq) + vs->cdb_size,
-                               sizeof(VirtIOSCSICmdResp) + vs->sense_size);
+    rc = virtio_scsi_parse_req(req, offsetof(VirtIOSCSICmdReq, cdb) +
+                               vs->cdb_size,
+                               offsetof(VirtIOSCSICmdResp, sense) +
+                               vs->sense_size);
     if (rc < 0) {
         if (rc == -ENOTSUP) {
             virtio_scsi_fail_cmd_req(req);
@@ -544,7 +552,7 @@ bool virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req)
     }
     req->sreq = scsi_req_new(d, req->req.cmd.tag,
                              virtio_scsi_get_lun(req->req.cmd.lun),
-                             req->req.cdb, req);
+                             req->req.cmd.cdb, req);
 
     if (req->sreq->cmd.mode != SCSI_XFER_NONE
         && (req->sreq->cmd.mode != req->mode ||

^ permalink raw reply related	[flat|nested] 111+ messages in thread

* Re: [Qemu-devel] [PULL 40/96] virtio-scsi: use standard-headers
  2015-03-11  8:31     ` Michael S. Tsirkin
@ 2015-03-11  9:48       ` Paolo Bonzini
  2015-03-11 12:25         ` Michael S. Tsirkin
  0 siblings, 1 reply; 111+ messages in thread
From: Paolo Bonzini @ 2015-03-11  9:48 UTC (permalink / raw)
  To: Michael S. Tsirkin, Fam Zheng
  Cc: Peter Maydell, Anthony Liguori, qemu-devel, dgilbert, Juan Quintela



On 11/03/2015 09:31, Michael S. Tsirkin wrote:
> On Wed, Mar 11, 2015 at 03:14:16PM +0800, Fam Zheng wrote:
>> On Wed, 02/18 22:48, Michael S. Tsirkin wrote:
>>> Drop duplicated code.
>>>
>>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>>> Acked-by: Paolo Bonzini <pbonzini@redhat.com>
>>
>> Michael, this breaks virtio-scsi-pci:
>>
>>     qemu-system-x86_64: wrong size for virtio-scsi headers
> 
> Testing this now.
> 
> diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h
> index de2c739..25d96f3 100644
> --- a/include/hw/virtio/virtio-scsi.h
> +++ b/include/hw/virtio/virtio-scsi.h
> @@ -136,15 +136,15 @@ typedef struct VirtIOSCSIReq {
>      union {
>          struct {
>              VirtIOSCSICmdReq  cmd;
> -            uint8_t           cdb[];
>          } QEMU_PACKED;
>          VirtIOSCSICtrlTMFReq  tmf;
>          VirtIOSCSICtrlANReq   an;
>      } req;
>  } VirtIOSCSIReq;
>  
> -QEMU_BUILD_BUG_ON(offsetof(VirtIOSCSIReq, req.cdb) !=
> -                  offsetof(VirtIOSCSIReq, req.cmd) + sizeof(VirtIOSCSICmdReq));
> +QEMU_BUILD_BUG_ON(offsetof(VirtIOSCSIReq, req.cmd.cdb) !=
> +                  offsetof(VirtIOSCSIReq, req.cmd) +
> +                  offsetof(VirtIOSCSICmdReq, cdb));

No, this is too ugly.  Can I just queue a revert?

Paolo

>  #define DEFINE_VIRTIO_SCSI_PROPERTIES(_state, _conf_field)                     \
>      DEFINE_PROP_UINT32("num_queues", _state, _conf_field.num_queues, 1),       \
> diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
> index cfb52e8..52bc00c 100644
> --- a/hw/scsi/virtio-scsi.c
> +++ b/hw/scsi/virtio-scsi.c
> @@ -47,7 +47,8 @@ VirtIOSCSIReq *virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq)
>      const size_t zero_skip = offsetof(VirtIOSCSIReq, elem)
>                               + sizeof(VirtQueueElement);
>  
> -    req = g_slice_alloc(sizeof(*req) + vs->cdb_size);
> +    req = g_slice_alloc(sizeof(*req) + MAX(vs->cdb_size, VIRTIO_SCSI_CDB_SIZE) -
> +                        VIRTIO_SCSI_CDB_SIZE);
>      req->vq = vq;
>      req->dev = s;
>      qemu_sglist_init(&req->qsgl, DEVICE(s), 8, &address_space_memory);
> @@ -62,7 +63,8 @@ void virtio_scsi_free_req(VirtIOSCSIReq *req)
>  
>      qemu_iovec_destroy(&req->resp_iov);
>      qemu_sglist_destroy(&req->qsgl);
> -    g_slice_free1(sizeof(*req) + vs->cdb_size, req);
> +    g_slice_free1(sizeof(*req) + MAX(vs->cdb_size, VIRTIO_SCSI_CDB_SIZE) -
> +                        VIRTIO_SCSI_CDB_SIZE, req);
>  }
>  
>  static void virtio_scsi_complete_req(VirtIOSCSIReq *req)
> @@ -213,8 +215,10 @@ static void *virtio_scsi_load_request(QEMUFile *f, SCSIRequest *sreq)
>      assert(req->elem.in_num <= ARRAY_SIZE(req->elem.in_sg));
>      assert(req->elem.out_num <= ARRAY_SIZE(req->elem.out_sg));
>  
> -    if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICmdReq) + vs->cdb_size,
> -                              sizeof(VirtIOSCSICmdResp) + vs->sense_size) < 0) {
> +    if (virtio_scsi_parse_req(req, offsetof(VirtIOSCSICmdReq, cdb) +
> +                              vs->cdb_size,
> +                              offsetof(VirtIOSCSICmdResp, sense) +
> +                              vs->sense_size) < 0) {
>          error_report("invalid SCSI request migration data");
>          exit(1);
>      }
> @@ -439,7 +443,7 @@ static void virtio_scsi_complete_cmd_req(VirtIOSCSIReq *req)
>      /* Sense data is not in req->resp and is copied separately
>       * in virtio_scsi_command_complete.
>       */
> -    req->resp_size = sizeof(VirtIOSCSICmdResp);
> +    req->resp_size = offsetof(VirtIOSCSICmdResp, sense);
>      virtio_scsi_complete_req(req);
>  }
>  
> @@ -462,8 +466,10 @@ static void virtio_scsi_command_complete(SCSIRequest *r, uint32_t status,
>      } else {
>          req->resp.cmd.resid = 0;
>          sense_len = scsi_req_get_sense(r, sense, sizeof(sense));
> -        sense_len = MIN(sense_len, req->resp_iov.size - sizeof(req->resp.cmd));
> -        qemu_iovec_from_buf(&req->resp_iov, sizeof(req->resp.cmd),
> +        sense_len = MIN(sense_len, req->resp_iov.size -
> +                        offsetof(typeof(req->resp.cmd), sense));
> +        qemu_iovec_from_buf(&req->resp_iov,
> +                            offsetof(typeof(req->resp.cmd), sense),
>                              sense, sense_len);
>          req->resp.cmd.sense_len = virtio_tswap32(vdev, sense_len);
>      }
> @@ -522,8 +528,10 @@ bool virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req)
>      SCSIDevice *d;
>      int rc;
>  
> -    rc = virtio_scsi_parse_req(req, sizeof(VirtIOSCSICmdReq) + vs->cdb_size,
> -                               sizeof(VirtIOSCSICmdResp) + vs->sense_size);
> +    rc = virtio_scsi_parse_req(req, offsetof(VirtIOSCSICmdReq, cdb) +
> +                               vs->cdb_size,
> +                               offsetof(VirtIOSCSICmdResp, sense) +
> +                               vs->sense_size);
>      if (rc < 0) {
>          if (rc == -ENOTSUP) {
>              virtio_scsi_fail_cmd_req(req);
> @@ -544,7 +552,7 @@ bool virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req)
>      }
>      req->sreq = scsi_req_new(d, req->req.cmd.tag,
>                               virtio_scsi_get_lun(req->req.cmd.lun),
> -                             req->req.cdb, req);
> +                             req->req.cmd.cdb, req);
>  
>      if (req->sreq->cmd.mode != SCSI_XFER_NONE
>          && (req->sreq->cmd.mode != req->mode ||
> 
> 

^ permalink raw reply	[flat|nested] 111+ messages in thread

* Re: [Qemu-devel] [PULL 40/96] virtio-scsi: use standard-headers
  2015-03-11  9:48       ` Paolo Bonzini
@ 2015-03-11 12:25         ` Michael S. Tsirkin
  0 siblings, 0 replies; 111+ messages in thread
From: Michael S. Tsirkin @ 2015-03-11 12:25 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Peter Maydell, Fam Zheng, Juan Quintela, qemu-devel, dgilbert,
	Anthony Liguori

On Wed, Mar 11, 2015 at 10:48:27AM +0100, Paolo Bonzini wrote:
> 
> 
> On 11/03/2015 09:31, Michael S. Tsirkin wrote:
> > On Wed, Mar 11, 2015 at 03:14:16PM +0800, Fam Zheng wrote:
> >> On Wed, 02/18 22:48, Michael S. Tsirkin wrote:
> >>> Drop duplicated code.
> >>>
> >>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> >>> Acked-by: Paolo Bonzini <pbonzini@redhat.com>
> >>
> >> Michael, this breaks virtio-scsi-pci:
> >>
> >>     qemu-system-x86_64: wrong size for virtio-scsi headers
> > 
> > Testing this now.
> > 
> > diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h
> > index de2c739..25d96f3 100644
> > --- a/include/hw/virtio/virtio-scsi.h
> > +++ b/include/hw/virtio/virtio-scsi.h
> > @@ -136,15 +136,15 @@ typedef struct VirtIOSCSIReq {
> >      union {
> >          struct {
> >              VirtIOSCSICmdReq  cmd;
> > -            uint8_t           cdb[];
> >          } QEMU_PACKED;
> >          VirtIOSCSICtrlTMFReq  tmf;
> >          VirtIOSCSICtrlANReq   an;
> >      } req;
> >  } VirtIOSCSIReq;
> >  
> > -QEMU_BUILD_BUG_ON(offsetof(VirtIOSCSIReq, req.cdb) !=
> > -                  offsetof(VirtIOSCSIReq, req.cmd) + sizeof(VirtIOSCSICmdReq));
> > +QEMU_BUILD_BUG_ON(offsetof(VirtIOSCSIReq, req.cmd.cdb) !=
> > +                  offsetof(VirtIOSCSIReq, req.cmd) +
> > +                  offsetof(VirtIOSCSICmdReq, cdb));
> 
> No, this is too ugly.  Can I just queue a revert?
> 
> Paolo

How about we just drop this chunk? It's not checking anything useful
now.
Others are good?


> >  #define DEFINE_VIRTIO_SCSI_PROPERTIES(_state, _conf_field)                     \
> >      DEFINE_PROP_UINT32("num_queues", _state, _conf_field.num_queues, 1),       \
> > diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
> > index cfb52e8..52bc00c 100644
> > --- a/hw/scsi/virtio-scsi.c
> > +++ b/hw/scsi/virtio-scsi.c
> > @@ -47,7 +47,8 @@ VirtIOSCSIReq *virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq)
> >      const size_t zero_skip = offsetof(VirtIOSCSIReq, elem)
> >                               + sizeof(VirtQueueElement);
> >  
> > -    req = g_slice_alloc(sizeof(*req) + vs->cdb_size);
> > +    req = g_slice_alloc(sizeof(*req) + MAX(vs->cdb_size, VIRTIO_SCSI_CDB_SIZE) -
> > +                        VIRTIO_SCSI_CDB_SIZE);
> >      req->vq = vq;
> >      req->dev = s;
> >      qemu_sglist_init(&req->qsgl, DEVICE(s), 8, &address_space_memory);
> > @@ -62,7 +63,8 @@ void virtio_scsi_free_req(VirtIOSCSIReq *req)
> >  
> >      qemu_iovec_destroy(&req->resp_iov);
> >      qemu_sglist_destroy(&req->qsgl);
> > -    g_slice_free1(sizeof(*req) + vs->cdb_size, req);
> > +    g_slice_free1(sizeof(*req) + MAX(vs->cdb_size, VIRTIO_SCSI_CDB_SIZE) -
> > +                        VIRTIO_SCSI_CDB_SIZE, req);
> >  }
> >  
> >  static void virtio_scsi_complete_req(VirtIOSCSIReq *req)
> > @@ -213,8 +215,10 @@ static void *virtio_scsi_load_request(QEMUFile *f, SCSIRequest *sreq)
> >      assert(req->elem.in_num <= ARRAY_SIZE(req->elem.in_sg));
> >      assert(req->elem.out_num <= ARRAY_SIZE(req->elem.out_sg));
> >  
> > -    if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICmdReq) + vs->cdb_size,
> > -                              sizeof(VirtIOSCSICmdResp) + vs->sense_size) < 0) {
> > +    if (virtio_scsi_parse_req(req, offsetof(VirtIOSCSICmdReq, cdb) +
> > +                              vs->cdb_size,
> > +                              offsetof(VirtIOSCSICmdResp, sense) +
> > +                              vs->sense_size) < 0) {
> >          error_report("invalid SCSI request migration data");
> >          exit(1);
> >      }
> > @@ -439,7 +443,7 @@ static void virtio_scsi_complete_cmd_req(VirtIOSCSIReq *req)
> >      /* Sense data is not in req->resp and is copied separately
> >       * in virtio_scsi_command_complete.
> >       */
> > -    req->resp_size = sizeof(VirtIOSCSICmdResp);
> > +    req->resp_size = offsetof(VirtIOSCSICmdResp, sense);
> >      virtio_scsi_complete_req(req);
> >  }
> >  
> > @@ -462,8 +466,10 @@ static void virtio_scsi_command_complete(SCSIRequest *r, uint32_t status,
> >      } else {
> >          req->resp.cmd.resid = 0;
> >          sense_len = scsi_req_get_sense(r, sense, sizeof(sense));
> > -        sense_len = MIN(sense_len, req->resp_iov.size - sizeof(req->resp.cmd));
> > -        qemu_iovec_from_buf(&req->resp_iov, sizeof(req->resp.cmd),
> > +        sense_len = MIN(sense_len, req->resp_iov.size -
> > +                        offsetof(typeof(req->resp.cmd), sense));
> > +        qemu_iovec_from_buf(&req->resp_iov,
> > +                            offsetof(typeof(req->resp.cmd), sense),
> >                              sense, sense_len);
> >          req->resp.cmd.sense_len = virtio_tswap32(vdev, sense_len);
> >      }
> > @@ -522,8 +528,10 @@ bool virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req)
> >      SCSIDevice *d;
> >      int rc;
> >  
> > -    rc = virtio_scsi_parse_req(req, sizeof(VirtIOSCSICmdReq) + vs->cdb_size,
> > -                               sizeof(VirtIOSCSICmdResp) + vs->sense_size);
> > +    rc = virtio_scsi_parse_req(req, offsetof(VirtIOSCSICmdReq, cdb) +
> > +                               vs->cdb_size,
> > +                               offsetof(VirtIOSCSICmdResp, sense) +
> > +                               vs->sense_size);
> >      if (rc < 0) {
> >          if (rc == -ENOTSUP) {
> >              virtio_scsi_fail_cmd_req(req);
> > @@ -544,7 +552,7 @@ bool virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req)
> >      }
> >      req->sreq = scsi_req_new(d, req->req.cmd.tag,
> >                               virtio_scsi_get_lun(req->req.cmd.lun),
> > -                             req->req.cdb, req);
> > +                             req->req.cmd.cdb, req);
> >  
> >      if (req->sreq->cmd.mode != SCSI_XFER_NONE
> >          && (req->sreq->cmd.mode != req->mode ||
> > 
> > 

^ permalink raw reply	[flat|nested] 111+ messages in thread

end of thread, other threads:[~2015-03-11 12:26 UTC | newest]

Thread overview: 111+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-18 21:43 [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
2015-02-18 21:44 ` [Qemu-devel] [PULL 01/96] acpi-build: fix memory leak with bridge hp off Michael S. Tsirkin
2015-02-18 21:44 ` [Qemu-devel] [PULL 02/96] bios linker: validate pointer within table Michael S. Tsirkin
2015-02-18 21:44 ` [Qemu-devel] [PULL 03/96] acpi: move generic aml building helpers into dedictated file Michael S. Tsirkin
2015-02-18 21:44 ` [Qemu-devel] [PULL 04/96] acpi: add build_append_namestring() helper Michael S. Tsirkin
2015-02-18 21:44 ` [Qemu-devel] [PULL 05/96] acpi: drop min-bytes in build_package() Michael S. Tsirkin
2015-02-18 21:44 ` [Qemu-devel] [PULL 06/96] pci: Convert core to realize Michael S. Tsirkin
2015-02-18 21:44 ` [Qemu-devel] [PULL 07/96] pci: Permit incremental conversion of device models " Michael S. Tsirkin
2015-02-18 21:44 ` [Qemu-devel] [PULL 08/96] pci: Trivial device model conversions " Michael S. Tsirkin
2015-02-18 21:44 ` [Qemu-devel] [PULL 09/96] pcnet: pcnet_common_init() always returns 0, change to void Michael S. Tsirkin
2015-02-18 21:45 ` [Qemu-devel] [PULL 10/96] pcnet: Convert to realize Michael S. Tsirkin
2015-02-18 21:45 ` [Qemu-devel] [PULL 11/96] serial-pci: " Michael S. Tsirkin
2015-02-18 21:45 ` [Qemu-devel] [PULL 12/96] ide/ich: " Michael S. Tsirkin
2015-02-18 21:45 ` [Qemu-devel] [PULL 13/96] cirrus-vga: " Michael S. Tsirkin
2015-02-18 21:45 ` [Qemu-devel] [PULL 14/96] qxl: " Michael S. Tsirkin
2015-02-18 21:45 ` [Qemu-devel] [PULL 15/96] pci-assign: " Michael S. Tsirkin
2015-02-18 21:45 ` [Qemu-devel] [PULL 16/96] qdev: Don't exit when running into bad -global Michael S. Tsirkin
2015-02-18 21:45 ` [Qemu-devel] [PULL 17/96] acpi, pc: Add hotunplug request cb for pc machine Michael S. Tsirkin
2015-02-18 21:45 ` [Qemu-devel] [PULL 18/96] acpi, ich9: Add hotunplug request cb for ich9 Michael S. Tsirkin
2015-02-18 21:45 ` [Qemu-devel] [PULL 19/96] acpi, pc: Add unplug cb for pc machine Michael S. Tsirkin
2015-02-18 21:46 ` [Qemu-devel] [PULL 20/96] acpi, ich9: Add unplug cb for ich9 Michael S. Tsirkin
2015-02-18 21:46 ` [Qemu-devel] [PULL 21/96] acpi, piix4: Add unplug cb for piix4 Michael S. Tsirkin
2015-02-18 21:46 ` [Qemu-devel] [PULL 22/96] vl.c: Fix error messages when parsing maxmem parameters Michael S. Tsirkin
2015-02-18 21:46 ` [Qemu-devel] [PULL 23/96] pc: memory: Validate alignment of maxram_size to page size Michael S. Tsirkin
2015-02-18 21:46 ` [Qemu-devel] [PULL 24/96] acpi: update RSDP on guest access Michael S. Tsirkin
2015-02-18 21:46 ` [Qemu-devel] [PULL 25/96] pc: acpi-build: update linker " Michael S. Tsirkin
2015-02-18 21:46 ` [Qemu-devel] [PULL 26/96] pc: acpi-build: migrate RSDP table Michael S. Tsirkin
2015-02-18 21:46 ` [Qemu-devel] [PULL 27/96] exec: round up size on MR resize Michael S. Tsirkin
2015-02-18 21:46 ` [Qemu-devel] [PULL 28/96] acpi-build: fix ACPI RAM management Michael S. Tsirkin
2015-02-18 21:46 ` [Qemu-devel] [PULL 29/96] acpi: has_immutable_rsdp->!rsdp_in_ram Michael S. Tsirkin
2015-02-18 21:47 ` [Qemu-devel] [PULL 30/96] acpi-build: simplify rsdp management for legacy Michael S. Tsirkin
2015-02-18 21:47 ` [Qemu-devel] [PULL 31/96] scripts/update-linux-headers.sh: pull virtio hdrs Michael S. Tsirkin
2015-02-18 21:47 ` [Qemu-devel] [PULL 32/96] include: import virtio headers from linux 4.0 Michael S. Tsirkin
2015-02-18 21:47 ` [Qemu-devel] [PULL 33/96] virtio: use standard virtio_ring.h Michael S. Tsirkin
2015-02-18 21:47 ` [Qemu-devel] [PULL 34/96] virtio: use standard-headers Michael S. Tsirkin
2015-02-18 21:47 ` [Qemu-devel] [PULL 35/96] virtio-balloon: use standard headers Michael S. Tsirkin
2015-02-18 21:47 ` [Qemu-devel] [PULL 36/96] virtio-9p: " Michael S. Tsirkin
2015-02-18 21:47 ` [Qemu-devel] [PULL 37/96] virtio-blk: switch to standard-headers Michael S. Tsirkin
2015-02-18 21:47 ` [Qemu-devel] [PULL 38/96] virtio-net,tap: use standard-headers Michael S. Tsirkin
2015-02-18 21:48 ` [Qemu-devel] [PULL 39/96] virtio-rng: " Michael S. Tsirkin
2015-02-18 21:48 ` [Qemu-devel] [PULL 40/96] virtio-scsi: " Michael S. Tsirkin
2015-03-11  7:14   ` Fam Zheng
2015-03-11  8:31     ` Michael S. Tsirkin
2015-03-11  9:48       ` Paolo Bonzini
2015-03-11 12:25         ` Michael S. Tsirkin
2015-02-18 21:48 ` [Qemu-devel] [PULL 41/96] virtio-serial: switch to standard-headers Michael S. Tsirkin
2015-02-18 21:48 ` [Qemu-devel] [PULL 42/96] update-linux-headers: use standard-headers Michael S. Tsirkin
2015-02-18 21:48 ` [Qemu-devel] [PULL 43/96] linux-headers: " Michael S. Tsirkin
2015-02-18 21:48 ` [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
2015-02-18 22:03   ` Michael S. Tsirkin
2015-02-19  7:58     ` Michael S. Tsirkin
2015-02-19  8:23     ` Peter Maydell
2015-02-18 21:48 ` [Qemu-devel] [PULL 44/96] virtio-pci: use standard headers Michael S. Tsirkin
2015-02-18 21:48 ` [Qemu-devel] [PULL 45/96] scripts: add arch specific standard-headers Michael S. Tsirkin
2015-02-18 21:48 ` [Qemu-devel] [PULL 46/96] standard-headers: add s390 virtio headers Michael S. Tsirkin
2015-02-18 21:48 ` [Qemu-devel] [PULL 47/96] s390: use standard headers Michael S. Tsirkin
2015-02-18 21:48 ` [Qemu-devel] [PULL 48/96] virtio: cull virtio_bus_set_vdev_features Michael S. Tsirkin
2015-02-18 21:48 ` [Qemu-devel] [PULL 49/96] virtio: feature bit manipulation helpers Michael S. Tsirkin
2015-02-18 21:49 ` [Qemu-devel] [PULL 50/96] virtio: add feature checking helpers Michael S. Tsirkin
2015-02-18 21:49 ` [Qemu-devel] [PULL 51/96] acpi-build: skip hotplugged bridges Michael S. Tsirkin
2015-02-18 21:49 ` [Qemu-devel] [PULL 52/96] pc: acpi: use local var for accessing ACPI tables blob in acpi_build() Michael S. Tsirkin
2015-02-18 21:49 ` [Qemu-devel] [PULL 53/96] update-linux-headers.sh: s/__inline__/inline/ Michael S. Tsirkin
2015-02-18 21:49 ` [Qemu-devel] [PULL 54/96] virtio-serial-bus.c: drop virtio_ids.h Michael S. Tsirkin
2015-02-18 21:49 ` [Qemu-devel] [PULL 55/96] standard-headers: include stdint.h Michael S. Tsirkin
2015-02-18 21:49 ` [Qemu-devel] [PULL 56/96] virtio_ring.h: s/__inline__/inline/ Michael S. Tsirkin
2015-02-18 21:49 ` [Qemu-devel] [PULL 57/96] acpi: introduce AML composer aml_append() Michael S. Tsirkin
2015-02-18 21:49 ` [Qemu-devel] [PULL 58/96] acpi: add aml_scope() term Michael S. Tsirkin
2015-02-18 21:49 ` [Qemu-devel] [PULL 59/96] pc: acpi-build: use aml_scope() for \_SB scope Michael S. Tsirkin
2015-02-18 21:49 ` [Qemu-devel] [PULL 60/96] acpi: add aml_device() term Michael S. Tsirkin
2015-02-18 21:50 ` [Qemu-devel] [PULL 61/96] acpi: add aml_method() term Michael S. Tsirkin
2015-02-18 21:50 ` [Qemu-devel] [PULL 62/96] acpi: add aml_if() term Michael S. Tsirkin
2015-02-18 21:50 ` [Qemu-devel] [PULL 63/96] acpi: add aml_name() & aml_name_decl() term Michael S. Tsirkin
2015-02-18 21:50 ` [Qemu-devel] [PULL 64/96] acpi: add aml_int() term Michael S. Tsirkin
2015-02-18 21:50 ` [Qemu-devel] [PULL 65/96] acpi: add aml_return() term Michael S. Tsirkin
2015-02-18 21:50 ` [Qemu-devel] [PULL 66/96] acpi: add aml_arg() term Michael S. Tsirkin
2015-02-18 21:50 ` [Qemu-devel] [PULL 67/96] acpi: add aml_store() term Michael S. Tsirkin
2015-02-18 21:50 ` [Qemu-devel] [PULL 68/96] acpi: add aml_and() term Michael S. Tsirkin
2015-02-18 21:50 ` [Qemu-devel] [PULL 69/96] acpi: add aml_notify() term Michael S. Tsirkin
2015-02-18 21:50 ` [Qemu-devel] [PULL 70/96] acpi: add aml_call1(), aml_call2(), aml_call3(), aml_call4() helpers Michael S. Tsirkin
2015-02-18 21:50 ` [Qemu-devel] [PULL 71/96] acpi: add aml_package() term Michael S. Tsirkin
2015-02-18 21:50 ` [Qemu-devel] [PULL 72/96] pc: acpi-build: generate _S[345] packages dynamically Michael S. Tsirkin
2015-02-18 21:51 ` [Qemu-devel] [PULL 73/96] acpi: add aml_buffer() term Michael S. Tsirkin
2015-02-18 21:51 ` [Qemu-devel] [PULL 74/96] acpi: add aml_resource_template() helper Michael S. Tsirkin
2015-02-18 21:51 ` [Qemu-devel] [PULL 75/96] acpi: add aml_io() helper Michael S. Tsirkin
2015-02-18 21:51 ` [Qemu-devel] [PULL 76/96] acpi: include PkgLength size only when requested Michael S. Tsirkin
2015-02-18 21:51 ` [Qemu-devel] [PULL 77/96] acpi: add aml_operation_region() term Michael S. Tsirkin
2015-02-18 21:51 ` [Qemu-devel] [PULL 78/96] acpi: add aml_field() & aml_named_field() terms Michael S. Tsirkin
2015-02-18 21:51 ` [Qemu-devel] [PULL 79/96] acpi: add aml_local() term Michael S. Tsirkin
2015-02-18 21:51 ` [Qemu-devel] [PULL 80/96] acpi: add aml_string() term Michael S. Tsirkin
2015-02-18 21:51 ` [Qemu-devel] [PULL 81/96] pc: acpi-build: generate pvpanic device description dynamically Michael S. Tsirkin
2015-02-18 21:51 ` [Qemu-devel] [PULL 82/96] acpi: add aml_varpackage() term Michael S. Tsirkin
2015-02-18 21:51 ` [Qemu-devel] [PULL 83/96] acpi: add aml_equal() term Michael S. Tsirkin
2015-02-18 21:51 ` [Qemu-devel] [PULL 84/96] acpi: add aml_processor() term Michael S. Tsirkin
2015-02-18 21:52 ` [Qemu-devel] [PULL 85/96] acpi: add aml_eisaid() term Michael S. Tsirkin
2015-02-18 21:52 ` [Qemu-devel] [PULL 86/96] pc: acpi-build: drop template patching and CPU hotplug objects dynamically Michael S. Tsirkin
2015-02-18 21:52 ` [Qemu-devel] [PULL 87/96] pc: acpi-build: create CPU hotplug IO region dynamically Michael S. Tsirkin
2015-02-18 21:52 ` [Qemu-devel] [PULL 88/96] acpi: add aml_reserved_field() term Michael S. Tsirkin
2015-02-18 21:52 ` [Qemu-devel] [PULL 89/96] pc: acpi-build: drop template patching and memory hotplug objects dynamically Michael S. Tsirkin
2015-02-18 21:52 ` [Qemu-devel] [PULL 90/96] pc: acpi-build: create memory hotplug IO region dynamically Michael S. Tsirkin
2015-02-18 21:52 ` [Qemu-devel] [PULL 91/96] acpi: add aml_word_bus_number(), aml_word_io(), aml_dword_memory(), aml_qword_memory() terms Michael S. Tsirkin
2015-02-18 21:52 ` [Qemu-devel] [PULL 92/96] pc: pcihp: expose MMIO base and len as properties Michael S. Tsirkin
2015-02-18 21:52 ` [Qemu-devel] [PULL 93/96] pc: acpi-build: reserve PCIHP MMIO resources Michael S. Tsirkin
2015-02-18 21:52 ` [Qemu-devel] [PULL 94/96] acpi: update generated hex files Michael S. Tsirkin
2015-02-18 21:53 ` [Qemu-devel] [PULL 95/96] acpi: drop unused generated files Michael S. Tsirkin
2015-02-18 21:53 ` [Qemu-devel] [PULL 96/96] acpi-test: update expected files Michael S. Tsirkin
2015-02-24 16:47 ` [Qemu-devel] [PULL 00/96] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
2015-02-26 11:17 ` Peter Maydell
2015-02-26 11:41   ` Michael S. Tsirkin
2015-02-26 11:59     ` Peter Maydell
2015-02-26 12:06       ` Michael S. Tsirkin
2015-02-26 11:53   ` Michael S. Tsirkin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.