Skip to contentSkip to conversation

acpi, pci, pc, virtio fixes and enhancements

GIT PULL Applied Michael S. Tsirkin 2 participants 40 messages Jan 26, 2014 – Jan 31, 2014

lore
Share & tools
lore
#0 lore raw

Hi Anthony,
I forgot to Cc you on the previous version of this pull request. So here's v2 - it also includes some more changes that got merged since then.
I also used this opportunity for smash in a compat bugfix. Please ignore the previous pull request.

The following changes since commit 0169c511554cb0014a00290b0d3d26c31a49818f:

Merge remote-tracking branch 'qemu-kvm/uq/master' into staging (2014-01-24 15:52:44 -0800)

are available in the git repository at:

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

for you to fetch changes up to a75143eda2ddf581b51e96c000974bcdfe2cbd10:

MAINTAINERS: add self as virtio co-maintainer (2014-01-26 13:11:45 +0200)

----------------------------------------------------------------
acpi,pci,pc,virtio fixes and enhancements

This includes new unit-tests for acpi by Marcel, hotplug for pci bridges by myself (piix only so far) and cpu hotplug for q35.
And a bunch of fixes all over the place as usual.

I included the patch to fix memory alignment for q35 as well - even though it limits 32 bit guests to 3G (they previously could address more memory with PAE).
To remove the limit, this will have to be fixed in seabios.

I also added self as virtio co-maintainer so I don't need to troll the list for patches to review.

----------------------------------------------------------------
Alexey Kardashevskiy (1):
tests: fix acpi to work on bigendian host

Eduardo Habkost (2):
pc: Save size of RAM below 4GB
acpi: Fix PCI hole handling on build_srat()

Gabriel L. Somlo (2):
Add DSDT node for AppleSMC
ACPI: Fix AppleSMC _STA size

Gerd Hoffmann (1):
q35: gigabyte alignment for ram

Igor Mammedov (9):
pc: make: fix dependencies: rebuild when included file is changed
acpi: factor out common cpu hotplug code for PIIX4/Q35
acpi: ich9: add CPU hotplug handling to Q35 machine
pc: set PRST base in DSDT depending on chipset
pc: PIIX DSDT: exclude CPU/PCI hotplug & GPE0 IO range from PCI bus resources
pc: Q35 DSDT: exclude CPU hotplug IO range from PCI bus resources
pc: ACPI: expose PRST IO range via _CRS
pc: ACPI: unify source of CPU hotplug IO base/len
pc: ACPI: update acpi-dsdt.hex.generated q35-acpi-dsdt.hex.generated

Laszlo Ersek (1):
Python-lang gdb script to extract x86_64 guest vmcore from qemu coredump

Marcel Apfelbaum (11):
acpi unit-test: add test files
configure: added acpi unit-test files
acpi unit-test: compare DSDT and SSDT tables against expected values
configure: add CONFIG_IASL to config-host.h
acpi unit-test: extract iasl executable from configuration acpi unit-test: added script to rebuild the expected aml files acpi unit-test: hook to rebuild expected aml files
acpi unit-test: renamed ssdt_tables to tables
acpi unit-test: resolved iasl crash
acpi unit-test: do not fail on asl mismatch
hw/pci: fix error flow in pci multifunction init

Michael S. Tsirkin (7):
pci: add pci_for_each_bus_depth_first
pcihp: generalization of piix4 acpi
piix4: add acpi pci hotplug support
acpi-build: enable hotplug for PCI bridges
acpi-test: update expected AML since recent changes
q35: document gigabyte_align
MAINTAINERS: add self as virtio co-maintainer

Stefan Weil (1):
virtio: Fix return value for dummy function vhost_net_virtqueue_pending

 configure                                    |   4 +
 include/hw/acpi/cpu_hotplug.h                |  27 ++
 include/hw/acpi/cpu_hotplug_defs.h           |  24 ++
 include/hw/acpi/ich9.h                       |   4 +
 include/hw/acpi/pcihp.h                      |  72 ++++++
 include/hw/i386/pc.h                         |   7 +-
 include/hw/isa/isa.h                         |   7 +
 include/hw/pci/pci.h                         |  14 ++
 hw/acpi/cpu_hotplug.c                        |  64 +++++
 hw/acpi/ich9.c                               |  14 ++
 hw/acpi/pcihp.c                              | 316 +++++++++++++++++++++++
 hw/acpi/piix4.c                              | 155 ++++++------
 hw/i386/acpi-build.c                         | 364 +++++++++++++++++++++------
 hw/i386/pc.c                                 |   1 +
 hw/i386/pc_q35.c                             |  20 +-
 hw/misc/applesmc.c                           |   1 -
 hw/net/vhost_net.c                           |   2 +-
 hw/pci/pci.c                                 |  48 +++-
 tests/acpi-test.c                            | 305 +++++++++++++++++++---
 MAINTAINERS                                  |   1 +
 docs/specs/acpi_cpu_hotplug.txt              |   4 +-
 hw/acpi/Makefile.objs                        |   3 +-
 hw/i386/Makefile.objs                        |   2 +-
 hw/i386/acpi-dsdt-cpu-hotplug.dsl            |  14 +-
 hw/i386/acpi-dsdt-isa.dsl                    |  11 +
 hw/i386/acpi-dsdt-pci-crs.dsl                |  15 +-
 hw/i386/acpi-dsdt.dsl                        |  76 ++++--
 hw/i386/acpi-dsdt.hex.generated              | 217 +++++++++++-----
 hw/i386/q35-acpi-dsdt.dsl                    |  19 ++
 hw/i386/q35-acpi-dsdt.hex.generated          |  74 +++++-
 hw/i386/ssdt-pcihp.dsl                       |  11 +-
 hw/i386/ssdt-pcihp.hex.generated             |  20 +-
 hw/i386/ssdt-proc.hex.generated              |   6 +-
 scripts/create_config                        |   4 +
 scripts/dump-guest-memory.py                 | 339 +++++++++++++++++++++++++
 tests/acpi-test-data/pc/APIC                 | Bin 0 -> 120 bytes
 tests/acpi-test-data/pc/DSDT                 | Bin 0 -> 4582 bytes
 tests/acpi-test-data/pc/FACP                 | Bin 0 -> 116 bytes
 tests/acpi-test-data/pc/FACS                 | Bin 0 -> 64 bytes
 tests/acpi-test-data/pc/HPET                 | Bin 0 -> 56 bytes
 tests/acpi-test-data/pc/SSDT                 | Bin 0 -> 2200 bytes
 tests/acpi-test-data/q35/APIC                | Bin 0 -> 120 bytes
 tests/acpi-test-data/q35/DSDT                | Bin 0 -> 7438 bytes
 tests/acpi-test-data/q35/FACP                | Bin 0 -> 116 bytes
 tests/acpi-test-data/q35/FACS                | Bin 0 -> 64 bytes
 tests/acpi-test-data/q35/HPET                | Bin 0 -> 56 bytes
 tests/acpi-test-data/q35/MCFG                | Bin 0 -> 60 bytes
 tests/acpi-test-data/q35/SSDT                | Bin 0 -> 475 bytes
 tests/acpi-test-data/rebuild-expected-aml.sh |  36 +++
 49 files changed, 1963 insertions(+), 338 deletions(-)
 create mode 100644 include/hw/acpi/cpu_hotplug.h
 create mode 100644 include/hw/acpi/cpu_hotplug_defs.h
 create mode 100644 include/hw/acpi/pcihp.h
 create mode 100644 hw/acpi/cpu_hotplug.c
 create mode 100644 hw/acpi/pcihp.c
 create mode 100644 scripts/dump-guest-memory.py
 create mode 100644 tests/acpi-test-data/pc/APIC
 create mode 100644 tests/acpi-test-data/pc/DSDT
 create mode 100644 tests/acpi-test-data/pc/FACP
 create mode 100644 tests/acpi-test-data/pc/FACS
 create mode 100644 tests/acpi-test-data/pc/HPET
 create mode 100644 tests/acpi-test-data/pc/SSDT
 create mode 100644 tests/acpi-test-data/q35/APIC
 create mode 100644 tests/acpi-test-data/q35/DSDT
 create mode 100644 tests/acpi-test-data/q35/FACP
 create mode 100644 tests/acpi-test-data/q35/FACS
 create mode 100644 tests/acpi-test-data/q35/HPET
 create mode 100644 tests/acpi-test-data/q35/MCFG
 create mode 100644 tests/acpi-test-data/q35/SSDT
 create mode 100755 tests/acpi-test-data/rebuild-expected-aml.sh
#1 lore raw

[Qemu-devel] [PULL v2 01/35] Python-lang gdb script to extract x86_64 guest vmcore from qemu coredump

From: Laszlo Ersek <[email protected]>

When qemu dies unexpectedly, for example in response to an explicit abort() call, or (more importantly) when an external signal is delivered to it that results in a coredump, sometimes it is useful to extract the guest vmcore from the qemu process' memory image. The guest vmcore might help understand an emulation problem in qemu, or help debug the guest.

This script reimplements (and cuts many features of) the qmp_dump_guest_memory() command in gdb/Python,

https://sourceware.org/gdb/current/onlinedocs/gdb/Python-API.html

working off the saved memory image of the qemu process. The docstring in the patch (serving as gdb help text) describes the limitations relative to the QMP command.

Dependencies of qmp_dump_guest_memory() have been reimplemented as needed. I sought to follow the general structure, sticking to original function names where possible. However, keeping it simple prevailed in some places.

The patch has been tested with a 4 VCPU, 768 MB, RHEL-6.4 (2.6.32-358.el6.x86_64) guest:

- The script printed

Quoted 13 lines

guest RAM blocks:
target_start target_end host_addr message count
---------------- ---------------- ---------------- ------- -----

0000000000000000 00000000000a0000 00007f95d0000000 added       1
00000000000a0000 00000000000b0000 00007f960ac00000 added       2
00000000000c0000 00000000000ca000 00007f95d00c0000 added       3
00000000000ca000 00000000000cd000 00007f95d00ca000 joined      3
00000000000cd000 00000000000d0000 00007f95d00cd000 joined      3
00000000000d0000 00000000000f0000 00007f95d00d0000 joined      3
00000000000f0000 0000000000100000 00007f95d00f0000 joined      3
0000000000100000 0000000030000000 00007f95d0100000 joined      3
00000000fc000000 00000000fc800000 00007f960ac00000 added       4
00000000fffe0000 0000000100000000 00007f9618800000 added       5
Quoted 5 lines

dumping range at 00007f95d0000000 for length 00000000000a0000 dumping range at 00007f960ac00000 for length 0000000000010000 dumping range at 00007f95d00c0000 for length 000000002ff40000 dumping range at 00007f960ac00000 for length 0000000000800000 dumping range at 00007f9618800000 for length 0000000000020000

- The vmcore was checked with "readelf", comparing the results against a vmcore written by qmp_dump_guest_memory():

Quoted 31 lines
mine 2013-09-12 17:39:03.820289404 +0200 renamed from theirs 2013-09-12 17:38:59.797289404 +0200 +7 -7
@@ -27,16 +27,16 @@
   Type           Offset             VirtAddr           PhysAddr
                  FileSiz            MemSiz              Flags  Align
   NOTE           0x0000000000000190 0x0000000000000000 0x0000000000000000
-                 0x0000000000000ca0 0x0000000000000ca0         0
-  LOAD           0x0000000000000e30 0x0000000000000000 0x0000000000000000
+                 0x000000000000001c 0x000000000000001c         0
+  LOAD           0x00000000000001ac 0x0000000000000000 0x0000000000000000
                  0x00000000000a0000 0x00000000000a0000         0
-  LOAD           0x00000000000a0e30 0x0000000000000000 0x00000000000a0000
+  LOAD           0x00000000000a01ac 0x0000000000000000 0x00000000000a0000
                  0x0000000000010000 0x0000000000010000         0
-  LOAD           0x00000000000b0e30 0x0000000000000000 0x00000000000c0000
+  LOAD           0x00000000000b01ac 0x0000000000000000 0x00000000000c0000
                  0x000000002ff40000 0x000000002ff40000         0
-  LOAD           0x000000002fff0e30 0x0000000000000000 0x00000000fc000000
+  LOAD           0x000000002fff01ac 0x0000000000000000 0x00000000fc000000
                  0x0000000000800000 0x0000000000800000         0
-  LOAD           0x00000000307f0e30 0x0000000000000000 0x00000000fffe0000
+  LOAD           0x00000000307f01ac 0x0000000000000000 0x00000000fffe0000
                  0x0000000000020000 0x0000000000020000         0
 
 There is no dynamic section in this file.
@@ -47,13 +47,6 @@
 
 No version information found in this file.
 
-Notes at offset 0x00000190 with length 0x00000ca0:
+Notes at offset 0x00000190 with length 0x0000001c:

mine 2013-09-12 17:39:03.820289404 +0200 line 52

Quoted 10 lines
mine 2013-09-12 17:39:03.820289404 +0200 renamed from theirs 2013-09-12 17:38:59.797289404 +0200 +1 -8
   Owner                Data size       Description
-  CORE         0x00000150      NT_PRSTATUS (prstatus structure)
-  CORE         0x00000150      NT_PRSTATUS (prstatus structure)
-  CORE         0x00000150      NT_PRSTATUS (prstatus structure)
-  CORE         0x00000150      NT_PRSTATUS (prstatus structure)
-  QEMU         0x000001b0      Unknown note type: (0x00000000)
-  QEMU         0x000001b0      Unknown note type: (0x00000000)
-  QEMU         0x000001b0      Unknown note type: (0x00000000)
-  QEMU         0x000001b0      Unknown note type: (0x00000000)
+  NONE         0x00000005      Unknown note type: (0x00000000)

- The vmcore was checked with "crash" too, again comparing the results against a vmcore written by qmp_dump_guest_memory():

Quoted 78 lines
example.dump.log2 2013-09-12 17:52:15.904289203 +0200 renamed from guest.vmcore.log2 2013-09-12 17:52:27.074289201 +0200 +12 -13
@@ -22,11 +22,11 @@
 This GDB was configured as "x86_64-unknown-linux-gnu"...
 
      KERNEL: /usr/lib/debug/lib/modules/2.6.32-358.el6.x86_64/vmlinux
-    DUMPFILE: /home/lacos/tmp/guest.vmcore
+    DUMPFILE: /home/lacos/tmp/example.dump
         CPUS: 4
-        DATE: Thu Sep 12 17:16:11 2013
-      UPTIME: 00:01:09
-LOAD AVERAGE: 0.07, 0.03, 0.00
+        DATE: Thu Sep 12 17:17:41 2013
+      UPTIME: 00:00:38
+LOAD AVERAGE: 0.18, 0.05, 0.01
        TASKS: 130
     NODENAME: localhost.localdomain
      RELEASE: 2.6.32-358.el6.x86_64
@@ -38,12 +38,12 @@
      COMMAND: "swapper"
         TASK: ffffffff81a8d020  (1 of 4)  [THREAD_INFO: ffffffff81a00000]
          CPU: 0
-       STATE: TASK_RUNNING (PANIC)
+       STATE: TASK_RUNNING (ACTIVE)
+     WARNING: panic task not found
 
 crash> bt
 PID: 0      TASK: ffffffff81a8d020  CPU: 0   COMMAND: "swapper"
- #0 [ffffffff81a01ed0] default_idle at ffffffff8101495d
- #1 [ffffffff81a01ef0] cpu_idle at ffffffff81009fc6
+ #0 [ffffffff81a01ef0] cpu_idle at ffffffff81009fc6
 crash> task ffffffff81a8d020
 PID: 0      TASK: ffffffff81a8d020  CPU: 0   COMMAND: "swapper"
 struct task_struct {
@@ -75,7 +75,7 @@
       prev = 0xffffffff81a8d080
     },
     on_rq = 0,
-    exec_start = 8618466836,
+    exec_start = 7469214014,
     sum_exec_runtime = 0,
     vruntime = 0,
     prev_sum_exec_runtime = 0,
@@ -149,7 +149,7 @@
   },
   tasks = {
     next = 0xffff88002d621948,
-    prev = 0xffff880029618f28
+    prev = 0xffff880023b74488
   },
   pushable_tasks = {
     prio = 140,
@@ -165,7 +165,7 @@
     }
   },
   mm = 0x0,
-  active_mm = 0xffff88002929b780,
+  active_mm = 0xffff8800297eb980,
   exit_state = 0,
   exit_code = 0,
   exit_signal = 0,
@@ -177,7 +177,7 @@
   sched_reset_on_fork = 0,
   pid = 0,
   tgid = 0,
-  stack_canary = 2483693585637059287,
+  stack_canary = 7266362296181431986,
   real_parent = 0xffffffff81a8d020,
   parent = 0xffffffff81a8d020,
   children = {
@@ -224,14 +224,14 @@
   set_child_tid = 0x0,
   clear_child_tid = 0x0,
   utime = 0,
-  stime = 3,
+  stime = 2,
   utimescaled = 0,
-  stimescaled = 3,

example.dump.log2 2013-09-12 17:52:15.904289203 +0200 line 237

Quoted 10 lines
example.dump.log2 2013-09-12 17:52:15.904289203 +0200 renamed from guest.vmcore.log2 2013-09-12 17:52:27.074289201 +0200 +2 -1
+  stimescaled = 2,
   gtime = 0,
   prev_utime = 0,
   prev_stime = 0,
   nvcsw = 0,
-  nivcsw = 1000,
+  nivcsw = 1764,
   start_time = {
     tv_sec = 0,
     tv_nsec = 0

- <name_dropping>I asked for Dave Anderson's help with verifying the extracted vmcore, and his comments make me think I should post this.</name_dropping>

---
 scripts/dump-guest-memory.py | 339 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 339 insertions(+)
 create mode 100644 scripts/dump-guest-memory.py
scripts/dump-guest-memory.py new file +339 -0
new file mode 100644
index 0000000..1ed8b67
@@ -0,0 +1,339 @@
+# This python script adds a new gdb command, "dump-guest-memory". It
+# should be loaded with "source dump-guest-memory.py" at the (gdb)
+# prompt.
+#
+# Copyright (C) 2013, Red Hat, Inc.
+#
+# Authors:
+#   Laszlo Ersek <[email protected]>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later. See
+# the COPYING file in the top-level directory.
+#
+# The leading docstring doesn't have idiomatic Python formatting. It is
+# printed by gdb's "help" command (the first line is printed in the
+# "help data" summary), and it should match how other help texts look in
+# gdb.
+
+import struct
+
+class DumpGuestMemory(gdb.Command):
+    """Extract guest vmcore from qemu process coredump.
+
+The sole argument is FILE, identifying the target file to write the
+guest vmcore to.
+
+This GDB command reimplements the dump-guest-memory QMP command in
+python, using the representation of guest memory as captured in the qemu
+coredump. The qemu process that has been dumped must have had the
+command line option "-machine dump-guest-core=on".
+
+For simplicity, the "paging", "begin" and "end" parameters of the QMP
+command are not supported -- no attempt is made to get the guest's
+internal paging structures (ie. paging=false is hard-wired), and guest
+memory is always fully dumped.
+
+Only x86_64 guests are supported.
+
+The CORE/NT_PRSTATUS and QEMU notes (that is, the VCPUs' statuses) are
+not written to the vmcore. Preparing these would require context that is
+only present in the KVM host kernel module when the guest is alive. A
+fake ELF note is written instead, only to keep the ELF parser of "crash"
+happy.
+
+Dependent on how busted the qemu process was at the time of the
+coredump, this command might produce unpredictable results. If qemu
+deliberately called abort(), or it was dumped in response to a signal at
+a halfway fortunate point, then its coredump should be in reasonable
+shape and this command should mostly work."""
+
+    TARGET_PAGE_SIZE = 0x1000
+    TARGET_PAGE_MASK = 0xFFFFFFFFFFFFF000
+
+    # Various ELF constants
+    EM_X86_64   = 62        # AMD x86-64 target machine
+    ELFDATA2LSB = 1         # little endian
+    ELFCLASS64  = 2
+    ELFMAG      = "\x7FELF"
+    EV_CURRENT  = 1
+    ET_CORE     = 4
+    PT_LOAD     = 1
+    PT_NOTE     = 4
+
+    # Special value for e_phnum. This indicates that the real number of
+    # program headers is too large to fit into e_phnum. Instead the real
+    # value is in the field sh_info of section 0.
+    PN_XNUM = 0xFFFF
+
+    # Format strings for packing and header size calculation.
+    ELF64_EHDR = ("4s" # e_ident/magic
+                  "B"  # e_ident/class
+                  "B"  # e_ident/data
+                  "B"  # e_ident/version
+                  "B"  # e_ident/osabi
+                  "8s" # e_ident/pad
+                  "H"  # e_type
+                  "H"  # e_machine
+                  "I"  # e_version
+                  "Q"  # e_entry
+                  "Q"  # e_phoff
+                  "Q"  # e_shoff
+                  "I"  # e_flags
+                  "H"  # e_ehsize
+                  "H"  # e_phentsize
+                  "H"  # e_phnum
+                  "H"  # e_shentsize
+                  "H"  # e_shnum
+                  "H"  # e_shstrndx
+                 )
+    ELF64_PHDR = ("I"  # p_type
+                  "I"  # p_flags
+                  "Q"  # p_offset
+                  "Q"  # p_vaddr
+                  "Q"  # p_paddr
+                  "Q"  # p_filesz
+                  "Q"  # p_memsz
+                  "Q"  # p_align
+                 )
+
+    def __init__(self):
+        super(DumpGuestMemory, self).__init__("dump-guest-memory",
+                                              gdb.COMMAND_DATA,
+                                              gdb.COMPLETE_FILENAME)
+        self.uintptr_t     = gdb.lookup_type("uintptr_t")
+        self.elf64_ehdr_le = struct.Struct("<%s" % self.ELF64_EHDR)
+        self.elf64_phdr_le = struct.Struct("<%s" % self.ELF64_PHDR)
+
+    def int128_get64(self, val):
+        assert (val["hi"] == 0)
+        return val["lo"]
+
+    def qtailq_foreach(self, head, field_str):
+        var_p = head["tqh_first"]
+        while (var_p != 0):
+            var = var_p.dereference()
+            yield var
+            var_p = var[field_str]["tqe_next"]
+
+    def qemu_get_ram_block(self, ram_addr):
+        ram_blocks = gdb.parse_and_eval("ram_list.blocks")
+        for block in self.qtailq_foreach(ram_blocks, "next"):
+            if (ram_addr - block["offset"] < block["length"]):
+                return block
+        raise gdb.GdbError("Bad ram offset %x" % ram_addr)
+
+    def qemu_get_ram_ptr(self, ram_addr):
+        block = self.qemu_get_ram_block(ram_addr)
+        return block["host"] + (ram_addr - block["offset"])
+
+    def memory_region_get_ram_ptr(self, mr):
+        if (mr["alias"] != 0):
+            return (self.memory_region_get_ram_ptr(mr["alias"].dereference()) +
+                    mr["alias_offset"])
+        return self.qemu_get_ram_ptr(mr["ram_addr"] & self.TARGET_PAGE_MASK)
+
+    def guest_phys_blocks_init(self):
+        self.guest_phys_blocks = []
+
+    def guest_phys_blocks_append(self):
+        print "guest RAM blocks:"
+        print ("target_start     target_end       host_addr        message "
+               "count")
+        print ("---------------- ---------------- ---------------- ------- "
+               "-----")
+
+        current_map_p = gdb.parse_and_eval("address_space_memory.current_map")
+        current_map = current_map_p.dereference()
+        for cur in range(current_map["nr"]):
+            flat_range   = (current_map["ranges"] + cur).dereference()
+            mr           = flat_range["mr"].dereference()
+
+            # we only care about RAM
+            if (not mr["ram"]):
+                continue
+
+            section_size = self.int128_get64(flat_range["addr"]["size"])
+            target_start = self.int128_get64(flat_range["addr"]["start"])
+            target_end   = target_start + section_size
+            host_addr    = (self.memory_region_get_ram_ptr(mr) +
+                            flat_range["offset_in_region"])
+            predecessor = None
+
+            # find continuity in guest physical address space
+            if (len(self.guest_phys_blocks) > 0):
+                predecessor = self.guest_phys_blocks[-1]
+                predecessor_size = (predecessor["target_end"] -
+                                    predecessor["target_start"])
+
+                # the memory API guarantees monotonically increasing
+                # traversal
+                assert (predecessor["target_end"] <= target_start)
+
+                # we want continuity in both guest-physical and
+                # host-virtual memory
+                if (predecessor["target_end"] < target_start or
+                    predecessor["host_addr"] + predecessor_size != host_addr):
+                    predecessor = None
+
+            if (predecessor is None):
+                # isolated mapping, add it to the list
+                self.guest_phys_blocks.append({"target_start": target_start,
+                                               "target_end"  : target_end,
+                                               "host_addr"   : host_addr})
+                message = "added"
+            else:
+                # expand predecessor until @target_end; predecessor's
+                # start doesn't change
+                predecessor["target_end"] = target_end
+                message = "joined"
+
+            print ("%016x %016x %016x %-7s %5u" %
+                   (target_start, target_end, host_addr.cast(self.uintptr_t),
+                    message, len(self.guest_phys_blocks)))
+
+    def cpu_get_dump_info(self):
+        # We can't synchronize the registers with KVM post-mortem, and
+        # the bits in (first_x86_cpu->env.hflags) seem to be stale; they
+        # may not reflect long mode for example. Hence just assume the
+        # most common values. This also means that instruction pointer
+        # etc. will be bogus in the dump, but at least the RAM contents
+        # should be valid.
+        self.dump_info = {"d_machine": self.EM_X86_64,
+                          "d_endian" : self.ELFDATA2LSB,
+                          "d_class"  : self.ELFCLASS64}
+
+    def encode_elf64_ehdr_le(self):
+        return self.elf64_ehdr_le.pack(
+                                 self.ELFMAG,                 # e_ident/magic
+                                 self.dump_info["d_class"],   # e_ident/class
+                                 self.dump_info["d_endian"],  # e_ident/data
+                                 self.EV_CURRENT,             # e_ident/version
+                                 0,                           # e_ident/osabi
+                                 "",                          # e_ident/pad
+                                 self.ET_CORE,                # e_type
+                                 self.dump_info["d_machine"], # e_machine
+                                 self.EV_CURRENT,             # e_version
+                                 0,                           # e_entry
+                                 self.elf64_ehdr_le.size,     # e_phoff
+                                 0,                           # e_shoff
+                                 0,                           # e_flags
+                                 self.elf64_ehdr_le.size,     # e_ehsize
+                                 self.elf64_phdr_le.size,     # e_phentsize
+                                 self.phdr_num,               # e_phnum
+                                 0,                           # e_shentsize
+                                 0,                           # e_shnum
+                                 0                            # e_shstrndx
+                                )
+
+    def encode_elf64_note_le(self):
+        return self.elf64_phdr_le.pack(self.PT_NOTE,         # p_type
+                                       0,                    # p_flags
+                                       (self.memory_offset -
+                                        len(self.note)),     # p_offset
+                                       0,                    # p_vaddr
+                                       0,                    # p_paddr
+                                       len(self.note),       # p_filesz
+                                       len(self.note),       # p_memsz
+                                       0                     # p_align
+                                      )
+
+    def encode_elf64_load_le(self, offset, start_hwaddr, range_size):
+        return self.elf64_phdr_le.pack(self.PT_LOAD, # p_type
+                                       0,            # p_flags
+                                       offset,       # p_offset
+                                       0,            # p_vaddr
+                                       start_hwaddr, # p_paddr
+                                       range_size,   # p_filesz
+                                       range_size,   # p_memsz
+                                       0             # p_align
+                                      )
+
+    def note_init(self, name, desc, type):
+        # name must include a trailing NUL
+        namesz = (len(name) + 1 + 3) / 4 * 4
+        descsz = (len(desc)     + 3) / 4 * 4
+        fmt = ("<"   # little endian
+               "I"   # n_namesz
+               "I"   # n_descsz
+               "I"   # n_type
+               "%us" # name
+               "%us" # desc
+               % (namesz, descsz))
+        self.note = struct.pack(fmt,
+                                len(name) + 1, len(desc), type, name, desc)
+
+    def dump_init(self):
+        self.guest_phys_blocks_init()
+        self.guest_phys_blocks_append()
+        self.cpu_get_dump_info()
+        # we have no way to retrieve the VCPU status from KVM
+        # post-mortem
+        self.note_init("NONE", "EMPTY", 0)
+
+        # Account for PT_NOTE.
+        self.phdr_num = 1
+
+        # We should never reach PN_XNUM for paging=false dumps: there's
+        # just a handful of discontiguous ranges after merging.
+        self.phdr_num += len(self.guest_phys_blocks)
+        assert (self.phdr_num < self.PN_XNUM)
+
+        # Calculate the ELF file offset where the memory dump commences:
+        #
+        #   ELF header
+        #   PT_NOTE
+        #   PT_LOAD: 1
+        #   PT_LOAD: 2
+        #   ...
+        #   PT_LOAD: len(self.guest_phys_blocks)
+        #   ELF note
+        #   memory dump
+        self.memory_offset = (self.elf64_ehdr_le.size +
+                              self.elf64_phdr_le.size * self.phdr_num +
+                              len(self.note))
+
+    def dump_begin(self, vmcore):
+        vmcore.write(self.encode_elf64_ehdr_le())
+        vmcore.write(self.encode_elf64_note_le())
+        running = self.memory_offset
+        for block in self.guest_phys_blocks:
+            range_size = block["target_end"] - block["target_start"]
+            vmcore.write(self.encode_elf64_load_le(running,
+                                                   block["target_start"],
+                                                   range_size))
+            running += range_size
+        vmcore.write(self.note)
+
+    def dump_iterate(self, vmcore):
+        qemu_core = gdb.inferiors()[0]
+        for block in self.guest_phys_blocks:
+            cur  = block["host_addr"]
+            left = block["target_end"] - block["target_start"]
+            print ("dumping range at %016x for length %016x" %
+                   (cur.cast(self.uintptr_t), left))
+            while (left > 0):
+                chunk_size = min(self.TARGET_PAGE_SIZE, left)
+                chunk = qemu_core.read_memory(cur, chunk_size)
+                vmcore.write(chunk)
+                cur  += chunk_size
+                left -= chunk_size
+
+    def create_vmcore(self, filename):
+        vmcore = open(filename, "wb")
+        self.dump_begin(vmcore)
+        self.dump_iterate(vmcore)
+        vmcore.close()
+
+    def invoke(self, args, from_tty):
+        # Unwittingly pressing the Enter key after the command should
+        # not dump the same multi-gig coredump to the same file.
+        self.dont_repeat()
+
+        argv = gdb.string_to_argv(args)
+        if (len(argv) != 1):
+            raise gdb.GdbError("usage: dump-guest-memory FILE")
+
+        self.dump_init()
+        self.create_vmcore(argv[0])
+
+DumpGuestMemory()
Signature · 1 line
MST
#2 lore raw

[Qemu-devel] [PULL v2 02/35] Add DSDT node for AppleSMC

In reply to Michael S. Tsirkin

From: "Gabriel L. Somlo" <[email protected]>

AppleSMC (-device isa-applesmc) is required to boot OS X guests. OS X expects a SMC node to be present in the ACPI DSDT. This patch adds a SMC node to the DSDT, and dynamically patches the return value of SMC._STA to either 0x0B if the chip is present, or otherwise to 0x00, before booting the guest.

---
 include/hw/isa/isa.h      |  7 +++++++
 hw/i386/acpi-build.c      |  9 +++++++++
 hw/misc/applesmc.c        |  1 -
 hw/i386/acpi-dsdt-isa.dsl | 11 +++++++++++
 hw/i386/acpi-dsdt.dsl     |  1 +
 hw/i386/q35-acpi-dsdt.dsl |  1 +
 6 files changed, 29 insertions(+), 1 deletion(-)
include/hw/isa/isa.h +7 -0
index fa45a5b..e0c749f 100644
@@ -20,6 +20,13 @@
 #define TYPE_ISA_BUS "ISA"
 #define ISA_BUS(obj) OBJECT_CHECK(ISABus, (obj), TYPE_ISA_BUS)
 
+#define TYPE_APPLE_SMC "isa-applesmc"
+
+static inline bool applesmc_find(void)
+{
+    return object_resolve_path_type("", TYPE_APPLE_SMC, NULL);
+}
+
 typedef struct ISADeviceClass {
     DeviceClass parent_class;
 } ISADeviceClass;
hw/i386/acpi-build.c +9 -0
index 48312f5..30bfcd2 100644
@@ -36,6 +36,7 @@
 #include "hw/nvram/fw_cfg.h"
 #include "bios-linker-loader.h"
 #include "hw/loader.h"
+#include "hw/isa/isa.h"
 
 /* Supported chipsets: */
 #include "hw/acpi/piix4.h"
@@ -80,6 +81,7 @@ typedef struct AcpiMiscInfo {
 
 static void acpi_get_dsdt(AcpiMiscInfo *info)
 {
+    unsigned short applesmc_sta_val, *applesmc_sta_off;
     Object *piix = piix4_pm_find();
     Object *lpc = ich9_lpc_find();
     assert(!!piix != !!lpc);
@@ -87,11 +89,18 @@ static void acpi_get_dsdt(AcpiMiscInfo *info)
     if (piix) {
         info->dsdt_code = AcpiDsdtAmlCode;
         info->dsdt_size = sizeof AcpiDsdtAmlCode;
+        applesmc_sta_off = piix_dsdt_applesmc_sta;
     }
     if (lpc) {
         info->dsdt_code = Q35AcpiDsdtAmlCode;
         info->dsdt_size = sizeof Q35AcpiDsdtAmlCode;
+        applesmc_sta_off = q35_dsdt_applesmc_sta;
     }
+
+    /* Patch in appropriate value for AppleSMC _STA */
+    applesmc_sta_val = applesmc_find() ? 0x0b : 0x00;
+    *(uint16_t *)(info->dsdt_code + *applesmc_sta_off) =
+        cpu_to_le16(applesmc_sta_val);
 }
 
 static
hw/misc/applesmc.c +0 -1
index 1e8d183..627adb9 100644
@@ -66,7 +66,6 @@ struct AppleSMCData {
     QLIST_ENTRY(AppleSMCData) node;
 };
 
-#define TYPE_APPLE_SMC "isa-applesmc"
 #define APPLE_SMC(obj) OBJECT_CHECK(AppleSMCState, (obj), TYPE_APPLE_SMC)
 
 typedef struct AppleSMCState AppleSMCState;
hw/i386/acpi-dsdt-isa.dsl +11 -0
index 89caa16..46942c1 100644
@@ -16,6 +16,17 @@
 /* Common legacy ISA style devices. */
 Scope(\_SB.PCI0.ISA) {
 
+    Device (SMC) {
+        Name(_HID, EisaId("APP0001"))
+        /* _STA will be patched to 0x0B if AppleSMC is present */
+        ACPI_EXTRACT_NAME_WORD_CONST DSDT_APPLESMC_STA
+        Name(_STA, 0xFF00)
+        Name(_CRS, ResourceTemplate () {
+            IO (Decode16, 0x0300, 0x0300, 0x01, 0x20)
+            IRQNoFlags() { 6 }
+        })
+    }
+
     Device(RTC) {
         Name(_HID, EisaId("PNP0B00"))
         Name(_CRS, ResourceTemplate() {
hw/i386/acpi-dsdt.dsl +1 -0
index a377424..b87c6e0 100644
@@ -114,6 +114,7 @@ DefinitionBlock (
         }
     }
 
+#define DSDT_APPLESMC_STA piix_dsdt_applesmc_sta
 #include "acpi-dsdt-isa.dsl"
 
 
hw/i386/q35-acpi-dsdt.dsl +1 -0
index 7934a9d..ee38fd6 100644
@@ -171,6 +171,7 @@ DefinitionBlock (
         }
     }
 
+#define DSDT_APPLESMC_STA q35_dsdt_applesmc_sta
 #include "acpi-dsdt-isa.dsl"
 
 
Signature · 1 line
MST
#3 lore raw

[Qemu-devel] [PULL v2 03/35] ACPI: Fix AppleSMC _STA size

In reply to Michael S. Tsirkin

From: "Gabriel L. Somlo" <[email protected]>

Minimize the storage used for AppleSMC's _STA (8bit), relying on ASL to implicitly convert it to the officially specified 32bit value.

---
 hw/i386/acpi-build.c      | 11 +++++------
 hw/i386/acpi-dsdt-isa.dsl |  4 ++--
 2 files changed, 7 insertions(+), 8 deletions(-)
hw/i386/acpi-build.c +5 -6
index 30bfcd2..1d62866 100644
@@ -81,7 +81,7 @@ typedef struct AcpiMiscInfo {
 
 static void acpi_get_dsdt(AcpiMiscInfo *info)
 {
-    unsigned short applesmc_sta_val, *applesmc_sta_off;
+    uint16_t *applesmc_sta;
     Object *piix = piix4_pm_find();
     Object *lpc = ich9_lpc_find();
     assert(!!piix != !!lpc);
@@ -89,18 +89,17 @@ static void acpi_get_dsdt(AcpiMiscInfo *info)
     if (piix) {
         info->dsdt_code = AcpiDsdtAmlCode;
         info->dsdt_size = sizeof AcpiDsdtAmlCode;
-        applesmc_sta_off = piix_dsdt_applesmc_sta;
+        applesmc_sta = piix_dsdt_applesmc_sta;
     }
     if (lpc) {
         info->dsdt_code = Q35AcpiDsdtAmlCode;
         info->dsdt_size = sizeof Q35AcpiDsdtAmlCode;
-        applesmc_sta_off = q35_dsdt_applesmc_sta;
+        applesmc_sta = q35_dsdt_applesmc_sta;
     }
 
     /* Patch in appropriate value for AppleSMC _STA */
-    applesmc_sta_val = applesmc_find() ? 0x0b : 0x00;
-    *(uint16_t *)(info->dsdt_code + *applesmc_sta_off) =
-        cpu_to_le16(applesmc_sta_val);
+    *(uint8_t *)(info->dsdt_code + *applesmc_sta) =
+        applesmc_find() ? 0x0b : 0x00;
 }
 
 static
hw/i386/acpi-dsdt-isa.dsl +2 -2
index 46942c1..deb37de 100644
@@ -19,8 +19,8 @@ Scope(\_SB.PCI0.ISA) {
     Device (SMC) {
         Name(_HID, EisaId("APP0001"))
         /* _STA will be patched to 0x0B if AppleSMC is present */
-        ACPI_EXTRACT_NAME_WORD_CONST DSDT_APPLESMC_STA
-        Name(_STA, 0xFF00)
+        ACPI_EXTRACT_NAME_BYTE_CONST DSDT_APPLESMC_STA
+        Name(_STA, 0xF0)
         Name(_CRS, ResourceTemplate () {
             IO (Decode16, 0x0300, 0x0300, 0x01, 0x20)
             IRQNoFlags() { 6 }
Signature · 1 line
MST
#4 lore raw

[Qemu-devel] [PULL v2 04/35] virtio: Fix return value for dummy function vhost_net_virtqueue_pending

In reply to Michael S. Tsirkin

From: Stefan Weil <[email protected]>

cgcc complains that -ENOSYS is not a good value for 'bool'.

A dummy virtio will never have pending queue entries, so let us return false.

---
 hw/net/vhost_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/vhost_net.c +1 -1
index 006576d..854997d 100644
@@ -321,7 +321,7 @@ void vhost_net_ack_features(struct vhost_net *net, unsigned features)
 
 bool vhost_net_virtqueue_pending(VHostNetState *net, int idx)
 {
-    return -ENOSYS;
+    return false;
 }
 
 void vhost_net_virtqueue_mask(VHostNetState *net, VirtIODevice *dev,
Signature · 1 line
MST
#5 lore raw

[Qemu-devel] [PULL v2 05/35] acpi unit-test: add test files

In reply to Michael S. Tsirkin

From: Marcel Apfelbaum <[email protected]>

Added unit-test's expected aml files to be compared with the actual ACPI tables.

---
 tests/acpi-test-data/pc/APIC  | Bin 0 -> 120 bytes
 tests/acpi-test-data/pc/DSDT  | Bin 0 -> 4407 bytes
 tests/acpi-test-data/pc/FACP  | Bin 0 -> 116 bytes
 tests/acpi-test-data/pc/FACS  | Bin 0 -> 64 bytes
 tests/acpi-test-data/pc/HPET  | Bin 0 -> 56 bytes
 tests/acpi-test-data/pc/SSDT  | Bin 0 -> 2104 bytes
 tests/acpi-test-data/q35/APIC | Bin 0 -> 120 bytes
 tests/acpi-test-data/q35/DSDT | Bin 0 -> 7344 bytes
 tests/acpi-test-data/q35/FACP | Bin 0 -> 116 bytes
 tests/acpi-test-data/q35/FACS | Bin 0 -> 64 bytes
 tests/acpi-test-data/q35/HPET | Bin 0 -> 56 bytes
 tests/acpi-test-data/q35/MCFG | Bin 0 -> 60 bytes
 tests/acpi-test-data/q35/SSDT | Bin 0 -> 2104 bytes
 13 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 tests/acpi-test-data/pc/APIC
 create mode 100644 tests/acpi-test-data/pc/DSDT
 create mode 100644 tests/acpi-test-data/pc/FACP
 create mode 100644 tests/acpi-test-data/pc/FACS
 create mode 100644 tests/acpi-test-data/pc/HPET
 create mode 100644 tests/acpi-test-data/pc/SSDT
 create mode 100644 tests/acpi-test-data/q35/APIC
 create mode 100644 tests/acpi-test-data/q35/DSDT
 create mode 100644 tests/acpi-test-data/q35/FACP
 create mode 100644 tests/acpi-test-data/q35/FACS
 create mode 100644 tests/acpi-test-data/q35/HPET
 create mode 100644 tests/acpi-test-data/q35/MCFG
 create mode 100644 tests/acpi-test-data/q35/SSDT
tests/acpi-test-data/pc/APIC new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..84509e0ae4cabeb5ead3e42a4edfa50abddbc17d
GIT binary patch
tests/acpi-test-data/pc/DSDT new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..b12e5eb85bb22f27fe10ce0fcf1d9a71f38360eb
GIT binary patch
tests/acpi-test-data/pc/FACP new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..0639999ed1f748d44977f88e63d6a0ab49add040
GIT binary patch
tests/acpi-test-data/pc/FACS new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..fc67ecc40782bd7fe8921e430d7de67f0bfaad93
GIT binary patch
tests/acpi-test-data/pc/HPET new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..df689b8f99c1c43cfd7d63bdede3bcdfd23b7de1
GIT binary patch
tests/acpi-test-data/pc/SSDT new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..5ab1b96af004737738f3386e73e4dc1d425ab77e
GIT binary patch
tests/acpi-test-data/q35/APIC new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..84509e0ae4cabeb5ead3e42a4edfa50abddbc17d
GIT binary patch
tests/acpi-test-data/q35/DSDT new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..59243b952d78c465298e0a2ec05a52f480dd92fb
GIT binary patch
tests/acpi-test-data/q35/FACP new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..19f3ac3ce6ab732caa750d835ce1261bc7343cf2
GIT binary patch
tests/acpi-test-data/q35/FACS new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..fc67ecc40782bd7fe8921e430d7de67f0bfaad93
GIT binary patch
tests/acpi-test-data/q35/HPET new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..df689b8f99c1c43cfd7d63bdede3bcdfd23b7de1
GIT binary patch
tests/acpi-test-data/q35/MCFG new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..79ceb27a038c6e29d098b98dda2e229495f96b7c
GIT binary patch
tests/acpi-test-data/q35/SSDT new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..186e748e6c16ffef80634be5eae9c3fa17210811
GIT binary patch
Signature · 1 line
MST
#6 lore raw

[Qemu-devel] [PULL v2 06/35] configure: added acpi unit-test files

In reply to Michael S. Tsirkin

From: Marcel Apfelbaum <[email protected]>

Ensure configure will set-up links for the files
if the build is created in other directory.

---
 configure | 4 ++++
 1 file changed, 4 insertions(+)
configure +4 -0
index b472694..236764a 100755
@@ -4774,6 +4774,10 @@ for bios_file in \
 do
     FILES="$FILES pc-bios/`basename $bios_file`"
 done
+for test_file in `find $source_path/tests/acpi-test-data -type f`
+do
+    FILES="$FILES tests/acpi-test-data`echo $test_file | sed -e 's/.*acpi-test-data//'`"
+done
 mkdir -p $DIRS
 for f in $FILES ; do
     if [ -e "$source_path/$f" ] && [ "$source_path" != `pwd` ]; then
Signature · 1 line
MST
#7 lore raw

[Qemu-devel] [PULL v2 07/35] acpi unit-test: compare DSDT and SSDT tables against expected values

In reply to Michael S. Tsirkin

From: Marcel Apfelbaum <[email protected]>

This test will run only if iasl is installed on the host machine. The test plan:
1. Dumps the ACPI tables as AML on the disk.
2. Runs iasl to disassembly the tables into ASL files.
3. Runs iasl to disassembly the offline AML files into ASL files.
4. Compares the ASL files.

The test runs for both default machine and q35. In case the test fails, it can be easily tweaked to show the differences between the ASL files and understand the issue.

---
 tests/acpi-test.c | 261 +++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 240 insertions(+), 21 deletions(-)
tests/acpi-test.c +240 -21
index df1af83..c3fc603 100644
@@ -18,14 +18,22 @@
 #include "qemu/compiler.h"
 #include "hw/i386/acpi-defs.h"
 
+#define MACHINE_PC "pc"
+#define MACHINE_Q35 "q35"
+
 /* DSDT and SSDTs format */
 typedef struct {
     AcpiTableHeader header;
-    uint8_t *aml;
-    int aml_len;
-} AcpiSdtTable;
+    gchar *aml;            /* aml bytecode from guest */
+    gsize aml_len;
+    gchar *aml_file;
+    gchar *asl;            /* asl code generated from aml */
+    gsize asl_len;
+    gchar *asl_file;
+} QEMU_PACKED AcpiSdtTable;
 
 typedef struct {
+    const char *machine;
     uint32_t rsdp_addr;
     AcpiRsdpDescriptor rsdp_table;
     AcpiRsdtDescriptorRev1 rsdt_table;
@@ -33,8 +41,7 @@ typedef struct {
     AcpiFacsDescriptorRev1 facs_table;
     uint32_t *rsdt_tables_addr;
     int rsdt_tables_nr;
-    AcpiSdtTable dsdt_table;
-    GArray *ssdt_tables;
+    GArray *ssdt_tables; /* first is DSDT */
 } test_data;
 
 #define LOW(x) ((x) & 0xff)
@@ -91,8 +98,10 @@ typedef struct {
 
 /* Boot sector code: write SIGNATURE into memory,
  * then halt.
+ * Q35 machine requires a minimum 0x7e000 bytes disk.
+ * (bug or feature?)
  */
-static uint8_t boot_sector[0x200] = {
+static uint8_t boot_sector[0x7e000] = {
     /* 7c00: mov $0xdead,%ax */
     [0x00] = 0xb8,
     [0x01] = LOW(SIGNATURE),
@@ -117,17 +126,40 @@ static uint8_t boot_sector[0x200] = {
 };
 
 static const char *disk = "tests/acpi-test-disk.raw";
+static const char *data_dir = "tests/acpi-test-data";
 
 static void free_test_data(test_data *data)
 {
+    AcpiSdtTable *temp;
     int i;
 
-    g_free(data->rsdt_tables_addr);
+    if (data->rsdt_tables_addr) {
+        g_free(data->rsdt_tables_addr);
+    }
+
     for (i = 0; i < data->ssdt_tables->len; ++i) {
-        g_free(g_array_index(data->ssdt_tables, AcpiSdtTable, i).aml);
+        temp = &g_array_index(data->ssdt_tables, AcpiSdtTable, i);
+        if (temp->aml) {
+            g_free(temp->aml);
+        }
+        if (temp->aml_file) {
+            if (g_strstr_len(temp->aml_file, -1, "aml-")) {
+                unlink(temp->aml_file);
+            }
+            g_free(temp->aml_file);
+        }
+        if (temp->asl) {
+            g_free(temp->asl);
+        }
+        if (temp->asl_file) {
+            if (g_strstr_len(temp->asl_file, -1, "asl-")) {
+                unlink(temp->asl_file);
+            }
+            g_free(temp->asl_file);
+        }
     }
+
     g_array_free(data->ssdt_tables, false);
-    g_free(data->dsdt_table.aml);
 }
 
 static uint8_t acpi_checksum(const uint8_t *data, int len)
@@ -292,34 +324,207 @@ static void test_dst_table(AcpiSdtTable *sdt_table, uint32_t addr)
     ACPI_READ_ARRAY_PTR(sdt_table->aml, sdt_table->aml_len, addr);
 
     checksum = acpi_checksum((uint8_t *)sdt_table, sizeof(AcpiTableHeader)) +
-               acpi_checksum(sdt_table->aml, sdt_table->aml_len);
+               acpi_checksum((uint8_t *)sdt_table->aml, sdt_table->aml_len);
     g_assert(!checksum);
 }
 
 static void test_acpi_dsdt_table(test_data *data)
 {
-    AcpiSdtTable *dsdt_table = &data->dsdt_table;
+    AcpiSdtTable dsdt_table;
     uint32_t addr = data->fadt_table.dsdt;
 
-    test_dst_table(dsdt_table, addr);
-    g_assert_cmphex(dsdt_table->header.signature, ==, ACPI_DSDT_SIGNATURE);
+    memset(&dsdt_table, 0, sizeof(dsdt_table));
+    data->ssdt_tables = g_array_new(false, true, sizeof(AcpiSdtTable));
+
+    test_dst_table(&dsdt_table, addr);
+    g_assert_cmphex(dsdt_table.header.signature, ==, ACPI_DSDT_SIGNATURE);
+
+    /* Place DSDT first */
+    g_array_append_val(data->ssdt_tables, dsdt_table);
 }
 
 static void test_acpi_ssdt_tables(test_data *data)
 {
-    GArray *ssdt_tables;
     int ssdt_tables_nr = data->rsdt_tables_nr - 1; /* fadt is first */
     int i;
 
-    ssdt_tables = g_array_sized_new(false, true, sizeof(AcpiSdtTable),
-                                    ssdt_tables_nr);
     for (i = 0; i < ssdt_tables_nr; i++) {
         AcpiSdtTable ssdt_table;
+
+        memset(&ssdt_table, 0 , sizeof(ssdt_table));
         uint32_t addr = data->rsdt_tables_addr[i + 1]; /* fadt is first */
         test_dst_table(&ssdt_table, addr);
-        g_array_append_val(ssdt_tables, ssdt_table);
+        g_array_append_val(data->ssdt_tables, ssdt_table);
     }
-    data->ssdt_tables = ssdt_tables;
+}
+
+static bool iasl_installed(void)
+{
+    gchar *out = NULL, *out_err = NULL;
+    bool ret;
+
+    /* pass 'out' and 'out_err' in order to be redirected */
+    ret = g_spawn_command_line_sync("iasl", &out, &out_err, NULL, NULL);
+
+    if (out_err) {
+        ret = ret && (out_err[0] == '\0');
+        g_free(out_err);
+    }
+
+    if (out) {
+        g_free(out);
+    }
+
+    return ret;
+}
+
+static void dump_aml_files(test_data *data)
+{
+    AcpiSdtTable *sdt;
+    GError *error = NULL;
+    gint fd;
+    ssize_t ret;
+    int i;
+
+    for (i = 0; i < data->ssdt_tables->len; ++i) {
+        sdt = &g_array_index(data->ssdt_tables, AcpiSdtTable, i);
+        g_assert(sdt->aml);
+
+        fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error);
+        g_assert_no_error(error);
+
+        ret = qemu_write_full(fd, sdt, sizeof(AcpiTableHeader));
+        g_assert(ret == sizeof(AcpiTableHeader));
+        ret = qemu_write_full(fd, sdt->aml, sdt->aml_len);
+        g_assert(ret == sdt->aml_len);
+
+        close(fd);
+    }
+}
+
+static void load_asl(GArray *sdts, AcpiSdtTable *sdt)
+{
+    AcpiSdtTable *temp;
+    GError *error = NULL;
+    GString *command_line = g_string_new("'iasl' ");
+    gint fd;
+    gchar *out, *out_err;
+    gboolean ret;
+    int i;
+
+    fd = g_file_open_tmp("asl-XXXXXX.dsl", &sdt->asl_file, &error);
+    g_assert_no_error(error);
+    close(fd);
+
+    /* build command line */
+    g_string_append_printf(command_line, "-p %s ", sdt->asl_file);
+    for (i = 0; i < 2; ++i) { /* reference DSDT and SSDT */
+        temp = &g_array_index(sdts, AcpiSdtTable, i);
+        g_string_append_printf(command_line, "-e %s ", temp->aml_file);
+    }
+    g_string_append_printf(command_line, "-d %s", sdt->aml_file);
+
+    /* pass 'out' and 'out_err' in order to be redirected */
+    g_spawn_command_line_sync(command_line->str, &out, &out_err, NULL, &error);
+    g_assert_no_error(error);
+
+    ret = g_file_get_contents(sdt->asl_file, (gchar **)&sdt->asl,
+                              &sdt->asl_len, &error);
+    g_assert(ret);
+    g_assert_no_error(error);
+    g_assert(sdt->asl_len);
+
+    g_free(out);
+    g_free(out_err);
+    g_string_free(command_line, true);
+}
+
+#define COMMENT_END "*/"
+#define DEF_BLOCK "DefinitionBlock ("
+#define BLOCK_NAME_END ".aml"
+
+static GString *normalize_asl(gchar *asl_code)
+{
+    GString *asl = g_string_new(asl_code);
+    gchar *comment, *block_name;
+
+    /* strip comments (different generation days) */
+    comment = g_strstr_len(asl->str, asl->len, COMMENT_END);
+    if (comment) {
+        asl = g_string_erase(asl, 0, comment + sizeof(COMMENT_END) - asl->str);
+    }
+
+    /* strip def block name (it has file path in it) */
+    if (g_str_has_prefix(asl->str, DEF_BLOCK)) {
+        block_name = g_strstr_len(asl->str, asl->len, BLOCK_NAME_END);
+        g_assert(block_name);
+        asl = g_string_erase(asl, 0,
+                             block_name + sizeof(BLOCK_NAME_END) - asl->str);
+    }
+
+    return asl;
+}
+
+static GArray *load_expected_aml(test_data *data)
+{
+    int i;
+    AcpiSdtTable *sdt;
+    gchar *aml_file;
+    GError *error = NULL;
+    gboolean ret;
+
+    GArray *exp_ssdt_tables = g_array_new(false, true, sizeof(AcpiSdtTable));
+    for (i = 0; i < data->ssdt_tables->len; ++i) {
+        AcpiSdtTable exp_sdt;
+        sdt = &g_array_index(data->ssdt_tables, AcpiSdtTable, i);
+
+        memset(&exp_sdt, 0, sizeof(exp_sdt));
+        exp_sdt.header.signature = sdt->header.signature;
+
+        aml_file = g_strdup_printf("%s/%s/%.4s", data_dir, data->machine,
+                                   (gchar *)&exp_sdt.header.signature);
+        exp_sdt.aml_file = aml_file;
+        g_assert(g_file_test(aml_file, G_FILE_TEST_EXISTS));
+        ret = g_file_get_contents(aml_file, &exp_sdt.aml,
+                                  &exp_sdt.aml_len, &error);
+        g_assert(ret);
+        g_assert_no_error(error);
+        g_assert(exp_sdt.aml);
+        g_assert(exp_sdt.aml_len);
+
+        g_array_append_val(exp_ssdt_tables, exp_sdt);
+    }
+
+    return exp_ssdt_tables;
+}
+
+static void test_acpi_asl(test_data *data)
+{
+    int i;
+    AcpiSdtTable *sdt, *exp_sdt;
+    test_data exp_data;
+
+    memset(&exp_data, 0, sizeof(exp_data));
+    exp_data.ssdt_tables = load_expected_aml(data);
+    dump_aml_files(data);
+    for (i = 0; i < data->ssdt_tables->len; ++i) {
+        GString *asl, *exp_asl;
+
+        sdt = &g_array_index(data->ssdt_tables, AcpiSdtTable, i);
+        exp_sdt = &g_array_index(exp_data.ssdt_tables, AcpiSdtTable, i);
+
+        load_asl(data->ssdt_tables, sdt);
+        asl = normalize_asl(sdt->asl);
+
+        load_asl(exp_data.ssdt_tables, exp_sdt);
+        exp_asl = normalize_asl(exp_sdt->asl);
+
+        g_assert(!g_strcmp0(asl->str, exp_asl->str));
+        g_string_free(asl, true);
+        g_string_free(exp_asl, true);
+    }
+
+    free_test_data(&exp_data);
 }
 
 static void test_acpi_one(const char *params, test_data *data)
@@ -329,10 +534,14 @@ static void test_acpi_one(const char *params, test_data *data)
     uint8_t signature_high;
     uint16_t signature;
     int i;
+    const char *device = "";
 
-    memset(data, 0, sizeof(*data));
-    args = g_strdup_printf("-net none -display none %s %s",
-                           params ? params : "", disk);
+    if (!g_strcmp0(data->machine, MACHINE_Q35)) {
+        device = ",id=hd -device ide-hd,drive=hd";
+    }
+
+    args = g_strdup_printf("-net none -display none %s -drive file=%s%s,",
+                           params ? params : "", disk, device);
     qtest_start(args);
 
    /* Wait at most 1 minute */
@@ -362,6 +571,10 @@ static void test_acpi_one(const char *params, test_data *data)
     test_acpi_dsdt_table(data);
     test_acpi_ssdt_tables(data);
 
+    if (iasl_installed()) {
+        test_acpi_asl(data);
+    }
+
     qtest_quit(global_qtest);
     g_free(args);
 }
@@ -373,8 +586,14 @@ static void test_acpi_tcg(void)
     /* Supplying -machine accel argument overrides the default (qtest).
      * This is to make guest actually run.
      */
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_PC;
     test_acpi_one("-machine accel=tcg", &data);
+    free_test_data(&data);
 
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_Q35;
+    test_acpi_one("-machine q35,accel=tcg", &data);
     free_test_data(&data);
 }
 
Signature · 1 line
MST
#8 lore raw

[Qemu-devel] [PULL v2 08/35] configure: add CONFIG_IASL to config-host.h

In reply to Michael S. Tsirkin

From: Marcel Apfelbaum <[email protected]>

Acpi unit-tests will extract iasl executable
from CONFIG_IASL define.

---
 scripts/create_config | 4 ++++
 1 file changed, 4 insertions(+)
scripts/create_config +4 -0
index b1adbf5..06f5316 100755
@@ -26,6 +26,10 @@ case $line in
     # save for the next definitions
     prefix=${line#*=}
     ;;
+ IASL=*) # iasl executable
+    value=${line#*=}
+    echo "#define CONFIG_IASL $value"
+    ;;
  CONFIG_AUDIO_DRIVERS=*)
     drivers=${line#*=}
     echo "#define CONFIG_AUDIO_DRIVERS \\"
Signature · 1 line
MST
#9 lore raw

[Qemu-devel] [PULL v2 09/35] acpi unit-test: extract iasl executable from configuration

In reply to Michael S. Tsirkin

From: Marcel Apfelbaum <[email protected]>

The test checked if iasl is installed by running "iasl" and checking the error output.
It is better to use the iasl executable as appears in configuration.

---
 tests/acpi-test.c | 31 ++++++++-----------------------
 1 file changed, 8 insertions(+), 23 deletions(-)
tests/acpi-test.c +8 -23
index c3fc603..83e5aed 100644
@@ -127,6 +127,11 @@ static uint8_t boot_sector[0x7e000] = {
 
 static const char *disk = "tests/acpi-test-disk.raw";
 static const char *data_dir = "tests/acpi-test-data";
+#ifdef CONFIG_IASL
+static const char *iasl = stringify(CONFIG_IASL);
+#else
+static const char *iasl;
+#endif
 
 static void free_test_data(test_data *data)
 {
@@ -358,26 +363,6 @@ static void test_acpi_ssdt_tables(test_data *data)
     }
 }
 
-static bool iasl_installed(void)
-{
-    gchar *out = NULL, *out_err = NULL;
-    bool ret;
-
-    /* pass 'out' and 'out_err' in order to be redirected */
-    ret = g_spawn_command_line_sync("iasl", &out, &out_err, NULL, NULL);
-
-    if (out_err) {
-        ret = ret && (out_err[0] == '\0');
-        g_free(out_err);
-    }
-
-    if (out) {
-        g_free(out);
-    }
-
-    return ret;
-}
-
 static void dump_aml_files(test_data *data)
 {
     AcpiSdtTable *sdt;
@@ -406,7 +391,7 @@ static void load_asl(GArray *sdts, AcpiSdtTable *sdt)
 {
     AcpiSdtTable *temp;
     GError *error = NULL;
-    GString *command_line = g_string_new("'iasl' ");
+    GString *command_line = g_string_new(iasl);
     gint fd;
     gchar *out, *out_err;
     gboolean ret;
@@ -417,7 +402,7 @@ static void load_asl(GArray *sdts, AcpiSdtTable *sdt)
     close(fd);
 
     /* build command line */
-    g_string_append_printf(command_line, "-p %s ", sdt->asl_file);
+    g_string_append_printf(command_line, " -p %s ", sdt->asl_file);
     for (i = 0; i < 2; ++i) { /* reference DSDT and SSDT */
         temp = &g_array_index(sdts, AcpiSdtTable, i);
         g_string_append_printf(command_line, "-e %s ", temp->aml_file);
@@ -571,7 +556,7 @@ static void test_acpi_one(const char *params, test_data *data)
     test_acpi_dsdt_table(data);
     test_acpi_ssdt_tables(data);
 
-    if (iasl_installed()) {
+    if (iasl) {
         test_acpi_asl(data);
     }
 
Signature · 1 line
MST
#10 lore raw

[Qemu-devel] [PULL v2 10/35] acpi unit-test: added script to rebuild the expected aml files

In reply to Michael S. Tsirkin

From: Marcel Apfelbaum <[email protected]>

Acpi unit-test will fail every time the acpi tables change. This script rebuild the expected aml files, so the test will pass. It also validates the modifications.

---
 tests/acpi-test-data/rebuild-expected-aml.sh | 36 ++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100755 tests/acpi-test-data/rebuild-expected-aml.sh
tests/acpi-test-data/rebuild-expected-aml.sh new file +36 -0
new file mode 100755
index 0000000..ab98498
@@ -0,0 +1,36 @@
+#! /bin/bash
+
+#
+# Rebuild expected AML files for acpi unit-test
+#
+# Copyright (c) 2013 Red Hat Inc.
+#
+# Authors:
+#  Marcel Apfelbaum <[email protected]>
+#
+# This work is licensed under the terms of the GNU GPLv2.
+# See the COPYING.LIB file in the top-level directory.
+
+qemu=
+
+if [ -e x86_64-softmmu/qemu-system-x86_64 ]; then
+    qemu="x86_64-softmmu/qemu-system-x86_64"
+elif [ -e i386-softmmu/qemu-system-i386 ]; then
+    qemu="i386-softmmu/qemu-system-i386"
+else
+    echo "Run 'make' to build the qemu exectutable!"
+    echo "Run this script from the build directory."
+    exit 1;
+fi
+
+if [ ! -e "tests/acpi-test" ]; then
+    echo "Test: acpi-test is required! Run make check before this script."
+    echo "Run this script from the build directory."
+    exit 1;
+fi
+
+TEST_ACPI_REBUILD_AML=y QTEST_QEMU_BINARY=$qemu tests/acpi-test
+
+echo "The files were rebuilt and can be added to git."
+echo "However, if new files were created, please copy them manually" \
+     "to tests/acpi-test-data/pc/ or tests/acpi-test-data/q35/ ."
Signature · 1 line
MST
#11 lore raw

[Qemu-devel] [PULL v2 11/35] acpi unit-test: hook to rebuild expected aml files

In reply to Michael S. Tsirkin

From: Marcel Apfelbaum <[email protected]>

When running the test with TEST_ACPI_REBUILD_AML=y environment variable, the test will rebuild and validate the expected aml files.

---
 tests/acpi-test.c | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)
tests/acpi-test.c +25 -5
index 83e5aed..89c4b81 100644
@@ -13,6 +13,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <glib.h>
+#include <glib/gstdio.h>
 #include "qemu-common.h"
 #include "libqtest.h"
 #include "qemu/compiler.h"
@@ -21,6 +22,8 @@
 #define MACHINE_PC "pc"
 #define MACHINE_Q35 "q35"
 
+#define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML"
+
 /* DSDT and SSDTs format */
 typedef struct {
     AcpiTableHeader header;
@@ -363,10 +366,11 @@ static void test_acpi_ssdt_tables(test_data *data)
     }
 }
 
-static void dump_aml_files(test_data *data)
+static void dump_aml_files(test_data *data, bool rebuild)
 {
     AcpiSdtTable *sdt;
     GError *error = NULL;
+    gchar *aml_file = NULL;
     gint fd;
     ssize_t ret;
     int i;
@@ -375,8 +379,16 @@ static void dump_aml_files(test_data *data)
         sdt = &g_array_index(data->ssdt_tables, AcpiSdtTable, i);
         g_assert(sdt->aml);
 
-        fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error);
-        g_assert_no_error(error);
+        if (rebuild) {
+            aml_file = g_strdup_printf("%s/%s/%.4s", data_dir, data->machine,
+                                       (gchar *)&sdt->header.signature);
+            fd = g_open(aml_file, O_WRONLY|O_TRUNC|O_CREAT,
+                        S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
+        } else {
+            fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error);
+            g_assert_no_error(error);
+        }
+        g_assert(fd >= 0);
 
         ret = qemu_write_full(fd, sdt, sizeof(AcpiTableHeader));
         g_assert(ret == sizeof(AcpiTableHeader));
@@ -384,6 +396,10 @@ static void dump_aml_files(test_data *data)
         g_assert(ret == sdt->aml_len);
 
         close(fd);
+
+        if (aml_file) {
+            g_free(aml_file);
+        }
     }
 }
 
@@ -491,7 +507,7 @@ static void test_acpi_asl(test_data *data)
 
     memset(&exp_data, 0, sizeof(exp_data));
     exp_data.ssdt_tables = load_expected_aml(data);
-    dump_aml_files(data);
+    dump_aml_files(data, false);
     for (i = 0; i < data->ssdt_tables->len; ++i) {
         GString *asl, *exp_asl;
 
@@ -557,7 +573,11 @@ static void test_acpi_one(const char *params, test_data *data)
     test_acpi_ssdt_tables(data);
 
     if (iasl) {
-        test_acpi_asl(data);
+        if (getenv(ACPI_REBUILD_EXPECTED_AML)) {
+            dump_aml_files(data, true);
+        } else {
+            test_acpi_asl(data);
+        }
     }
 
     qtest_quit(global_qtest);
Signature · 1 line
MST
#12 lore raw

[Qemu-devel] [PULL v2 12/35] tests: fix acpi to work on bigendian host

In reply to Michael S. Tsirkin

From: Alexey Kardashevskiy <[email protected]>

Double endianness convertion make this test failing on POWERPC machine running in big-endian.

This fixes the test to success on big-endian host.

---
 tests/acpi-test.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tests/acpi-test.c +3 -3
index 89c4b81..b5ab70a 100644
@@ -61,13 +61,13 @@ typedef struct {
             field = readb(addr);               \
             break;                             \
         case 2:                                \
-            field = le16_to_cpu(readw(addr));  \
+            field = readw(addr);               \
             break;                             \
         case 4:                                \
-            field = le32_to_cpu(readl(addr));  \
+            field = readl(addr);               \
             break;                             \
         case 8:                                \
-            field = le64_to_cpu(readq(addr));  \
+            field = readq(addr);               \
             break;                             \
         default:                               \
             g_assert(false);                   \
Signature · 1 line
MST
#13 lore raw

[Qemu-devel] [PULL v2 13/35] acpi unit-test: renamed ssdt_tables to tables

In reply to Michael S. Tsirkin

From: Marcel Apfelbaum <[email protected]>

Just a refactoring, ssdt_tables name was confusing as it included other tables as well.

---
 tests/acpi-test.c | 48 ++++++++++++++++++++++++------------------------
 1 file changed, 24 insertions(+), 24 deletions(-)
tests/acpi-test.c +24 -24
index b5ab70a..a3d2b34 100644
@@ -44,7 +44,7 @@ typedef struct {
     AcpiFacsDescriptorRev1 facs_table;
     uint32_t *rsdt_tables_addr;
     int rsdt_tables_nr;
-    GArray *ssdt_tables; /* first is DSDT */
+    GArray *tables;
 } test_data;
 
 #define LOW(x) ((x) & 0xff)
@@ -145,8 +145,8 @@ static void free_test_data(test_data *data)
         g_free(data->rsdt_tables_addr);
     }
 
-    for (i = 0; i < data->ssdt_tables->len; ++i) {
-        temp = &g_array_index(data->ssdt_tables, AcpiSdtTable, i);
+    for (i = 0; i < data->tables->len; ++i) {
+        temp = &g_array_index(data->tables, AcpiSdtTable, i);
         if (temp->aml) {
             g_free(temp->aml);
         }
@@ -167,7 +167,7 @@ static void free_test_data(test_data *data)
         }
     }
 
-    g_array_free(data->ssdt_tables, false);
+    g_array_free(data->tables, false);
 }
 
 static uint8_t acpi_checksum(const uint8_t *data, int len)
@@ -342,27 +342,27 @@ static void test_acpi_dsdt_table(test_data *data)
     uint32_t addr = data->fadt_table.dsdt;
 
     memset(&dsdt_table, 0, sizeof(dsdt_table));
-    data->ssdt_tables = g_array_new(false, true, sizeof(AcpiSdtTable));
+    data->tables = g_array_new(false, true, sizeof(AcpiSdtTable));
 
     test_dst_table(&dsdt_table, addr);
     g_assert_cmphex(dsdt_table.header.signature, ==, ACPI_DSDT_SIGNATURE);
 
     /* Place DSDT first */
-    g_array_append_val(data->ssdt_tables, dsdt_table);
+    g_array_append_val(data->tables, dsdt_table);
 }
 
-static void test_acpi_ssdt_tables(test_data *data)
+static void test_acpi_tables(test_data *data)
 {
-    int ssdt_tables_nr = data->rsdt_tables_nr - 1; /* fadt is first */
+    int tables_nr = data->rsdt_tables_nr - 1; /* fadt is first */
     int i;
 
-    for (i = 0; i < ssdt_tables_nr; i++) {
+    for (i = 0; i < tables_nr; i++) {
         AcpiSdtTable ssdt_table;
 
         memset(&ssdt_table, 0 , sizeof(ssdt_table));
         uint32_t addr = data->rsdt_tables_addr[i + 1]; /* fadt is first */
         test_dst_table(&ssdt_table, addr);
-        g_array_append_val(data->ssdt_tables, ssdt_table);
+        g_array_append_val(data->tables, ssdt_table);
     }
 }
 
@@ -375,8 +375,8 @@ static void dump_aml_files(test_data *data, bool rebuild)
     ssize_t ret;
     int i;
 
-    for (i = 0; i < data->ssdt_tables->len; ++i) {
-        sdt = &g_array_index(data->ssdt_tables, AcpiSdtTable, i);
+    for (i = 0; i < data->tables->len; ++i) {
+        sdt = &g_array_index(data->tables, AcpiSdtTable, i);
         g_assert(sdt->aml);
 
         if (rebuild) {
@@ -474,10 +474,10 @@ static GArray *load_expected_aml(test_data *data)
     GError *error = NULL;
     gboolean ret;
 
-    GArray *exp_ssdt_tables = g_array_new(false, true, sizeof(AcpiSdtTable));
-    for (i = 0; i < data->ssdt_tables->len; ++i) {
+    GArray *exp_tables = g_array_new(false, true, sizeof(AcpiSdtTable));
+    for (i = 0; i < data->tables->len; ++i) {
         AcpiSdtTable exp_sdt;
-        sdt = &g_array_index(data->ssdt_tables, AcpiSdtTable, i);
+        sdt = &g_array_index(data->tables, AcpiSdtTable, i);
 
         memset(&exp_sdt, 0, sizeof(exp_sdt));
         exp_sdt.header.signature = sdt->header.signature;
@@ -493,10 +493,10 @@ static GArray *load_expected_aml(test_data *data)
         g_assert(exp_sdt.aml);
         g_assert(exp_sdt.aml_len);
 
-        g_array_append_val(exp_ssdt_tables, exp_sdt);
+        g_array_append_val(exp_tables, exp_sdt);
     }
 
-    return exp_ssdt_tables;
+    return exp_tables;
 }
 
 static void test_acpi_asl(test_data *data)
@@ -506,18 +506,18 @@ static void test_acpi_asl(test_data *data)
     test_data exp_data;
 
     memset(&exp_data, 0, sizeof(exp_data));
-    exp_data.ssdt_tables = load_expected_aml(data);
+    exp_data.tables = load_expected_aml(data);
     dump_aml_files(data, false);
-    for (i = 0; i < data->ssdt_tables->len; ++i) {
+    for (i = 0; i < data->tables->len; ++i) {
         GString *asl, *exp_asl;
 
-        sdt = &g_array_index(data->ssdt_tables, AcpiSdtTable, i);
-        exp_sdt = &g_array_index(exp_data.ssdt_tables, AcpiSdtTable, i);
+        sdt = &g_array_index(data->tables, AcpiSdtTable, i);
+        exp_sdt = &g_array_index(exp_data.tables, AcpiSdtTable, i);
 
-        load_asl(data->ssdt_tables, sdt);
+        load_asl(data->tables, sdt);
         asl = normalize_asl(sdt->asl);
 
-        load_asl(exp_data.ssdt_tables, exp_sdt);
+        load_asl(exp_data.tables, exp_sdt);
         exp_asl = normalize_asl(exp_sdt->asl);
 
         g_assert(!g_strcmp0(asl->str, exp_asl->str));
@@ -570,7 +570,7 @@ static void test_acpi_one(const char *params, test_data *data)
     test_acpi_fadt_table(data);
     test_acpi_facs_table(data);
     test_acpi_dsdt_table(data);
-    test_acpi_ssdt_tables(data);
+    test_acpi_tables(data);
 
     if (iasl) {
         if (getenv(ACPI_REBUILD_EXPECTED_AML)) {
Signature · 1 line
MST
#14 lore raw

[Qemu-devel] [PULL v2 14/35] acpi unit-test: resolved iasl crash

In reply to Michael S. Tsirkin

From: Marcel Apfelbaum <[email protected]>

It seems that iasl has an issue when disassembles some ACPI tables using the command line:
iasl -e DSDT -e SSDT -d HPET

Modified the iasl command line to "iasl -d HPET" until the problem is solved. The command line remained the same for DSDT and SSDT tables.

---
 tests/acpi-test.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
tests/acpi-test.c +15 -3
index a3d2b34..6095d07 100644
@@ -23,6 +23,7 @@
 #define MACHINE_Q35 "q35"
 
 #define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML"
+#define ACPI_SSDT_SIGNATURE 0x54445353 /* SSDT */
 
 /* DSDT and SSDTs format */
 typedef struct {
@@ -403,6 +404,11 @@ static void dump_aml_files(test_data *data, bool rebuild)
     }
 }
 
+static bool compare_signature(AcpiSdtTable *sdt, uint32_t signature)
+{
+   return sdt->header.signature == signature;
+}
+
 static void load_asl(GArray *sdts, AcpiSdtTable *sdt)
 {
     AcpiSdtTable *temp;
@@ -419,9 +425,15 @@ static void load_asl(GArray *sdts, AcpiSdtTable *sdt)
 
     /* build command line */
     g_string_append_printf(command_line, " -p %s ", sdt->asl_file);
-    for (i = 0; i < 2; ++i) { /* reference DSDT and SSDT */
-        temp = &g_array_index(sdts, AcpiSdtTable, i);
-        g_string_append_printf(command_line, "-e %s ", temp->aml_file);
+    if (compare_signature(sdt, ACPI_DSDT_SIGNATURE) ||
+        compare_signature(sdt, ACPI_SSDT_SIGNATURE)) {
+        for (i = 0; i < sdts->len; ++i) {
+            temp = &g_array_index(sdts, AcpiSdtTable, i);
+            if (compare_signature(temp, ACPI_DSDT_SIGNATURE) ||
+                compare_signature(temp, ACPI_SSDT_SIGNATURE)) {
+                g_string_append_printf(command_line, "-e %s ", temp->aml_file);
+            }
+        }
     }
     g_string_append_printf(command_line, "-d %s", sdt->aml_file);
 
Signature · 1 line
MST
#15 lore raw

[Qemu-devel] [PULL v2 16/35] pc: make: fix dependencies: rebuild when included file is changed

In reply to Michael S. Tsirkin

From: Igor Mammedov <[email protected]>

some *.dsl files include another *.dsl files but there weren't any dependicies and when included file changed target table wasn't rebuild. Fix this by using the same auto dependency generation as for C files.

---
 hw/i386/Makefile.objs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/Makefile.objs +1 -1
index 09ac433..d58a103 100644
@@ -17,7 +17,7 @@ iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
 ifdef IASL
 #IASL Present. Generate hex files from .dsl
 hw/i386/%.hex: $(SRC_PATH)/hw/i386/%.dsl $(SRC_PATH)/scripts/acpi_extract_preprocess.py $(SRC_PATH)/scripts/acpi_extract.py
-	$(call quiet-command, cpp -P $< -o $*.dsl.i.orig, "  CPP $(TARGET_DIR)$*.dsl.i.orig")
+	$(call quiet-command, cpp -P $(QEMU_DGFLAGS) $< -o $*.dsl.i.orig, "  CPP $(TARGET_DIR)$*.dsl.i.orig")
 	$(call quiet-command, $(PYTHON) $(SRC_PATH)/scripts/acpi_extract_preprocess.py $*.dsl.i.orig > $*.dsl.i, "  ACPI_PREPROCESS $(TARGET_DIR)$*.dsl.i")
 	$(call quiet-command, $(IASL) $(call iasl-option,$(IASL),-Pn,) -vs -l -tc -p $* $*.dsl.i $(if $(V), , > /dev/null) 2>&1 ,"  IASL $(TARGET_DIR)$*.dsl.i")
 	$(call quiet-command, $(PYTHON) $(SRC_PATH)/scripts/acpi_extract.py $*.lst > $*.off, "  ACPI_EXTRACT $(TARGET_DIR)$*.off")
Signature · 1 line
MST
#16 lore raw

[Qemu-devel] [PULL v2 15/35] acpi unit-test: do not fail on asl mismatch

In reply to Michael S. Tsirkin

From: Marcel Apfelbaum <[email protected]>

The asl comparison will break every time the ACPI tables are updated. This may break the git bisect. Instead of failing print a warning on stderr including the retained asl files, so they can be compared offline.

---
 tests/acpi-test.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
tests/acpi-test.c +11 -2
index 6095d07..31f5359 100644
@@ -34,6 +34,7 @@ typedef struct {
     gchar *asl;            /* asl code generated from aml */
     gsize asl_len;
     gchar *asl_file;
+    bool asl_file_retain;   /* do not delete the temp asl */
 } QEMU_PACKED AcpiSdtTable;
 
 typedef struct {
@@ -161,7 +162,7 @@ static void free_test_data(test_data *data)
             g_free(temp->asl);
         }
         if (temp->asl_file) {
-            if (g_strstr_len(temp->asl_file, -1, "asl-")) {
+            if (!temp->asl_file_retain) {
                 unlink(temp->asl_file);
             }
             g_free(temp->asl_file);
@@ -532,7 +533,15 @@ static void test_acpi_asl(test_data *data)
         load_asl(exp_data.tables, exp_sdt);
         exp_asl = normalize_asl(exp_sdt->asl);
 
-        g_assert(!g_strcmp0(asl->str, exp_asl->str));
+        if (g_strcmp0(asl->str, exp_asl->str)) {
+            sdt->asl_file_retain = true;
+            exp_sdt->asl_file_retain = true;
+            fprintf(stderr,
+                    "acpi-test: Warning! %.4s mismatch. "
+                    "Orig asl: %s, expected asl %s.\n",
+                    (gchar *)&exp_sdt->header.signature,
+                    sdt->asl_file, exp_sdt->asl_file);
+        }
         g_string_free(asl, true);
         g_string_free(exp_asl, true);
     }
Signature · 1 line
MST
#17 lore raw

[Qemu-devel] [PULL v2 17/35] pci: add pci_for_each_bus_depth_first

In reply to Michael S. Tsirkin

Useful for ACPI hotplug.

---
 include/hw/pci/pci.h | 14 ++++++++++++++
 hw/pci/pci.c         | 28 ++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)
include/hw/pci/pci.h +14 -0
index 754b82d..5252346 100644
@@ -387,6 +387,20 @@ int pci_bus_num(PCIBus *s);
 void pci_for_each_device(PCIBus *bus, int bus_num,
                          void (*fn)(PCIBus *bus, PCIDevice *d, void *opaque),
                          void *opaque);
+void pci_for_each_bus_depth_first(PCIBus *bus,
+                                  void *(*begin)(PCIBus *bus, void *parent_state),
+                                  void (*end)(PCIBus *bus, void *state),
+                                  void *parent_state);
+
+/* Use this wrapper when specific scan order is not required. */
+static inline
+void pci_for_each_bus(PCIBus *bus,
+                      void (*fn)(PCIBus *bus, void *opaque),
+                      void *opaque)
+{
+    pci_for_each_bus_depth_first(bus, NULL, fn, opaque);
+}
+
 PCIBus *pci_find_primary_bus(void);
 PCIBus *pci_device_root_bus(const PCIDevice *d);
 const char *pci_root_bus_path(PCIDevice *dev);
hw/pci/pci.c +28 -0
index aa2a395..2aca8a4 100644
@@ -1704,6 +1704,34 @@ static PCIBus *pci_find_bus_nr(PCIBus *bus, int bus_num)
     return NULL;
 }
 
+void pci_for_each_bus_depth_first(PCIBus *bus,
+                                  void *(*begin)(PCIBus *bus, void *parent_state),
+                                  void (*end)(PCIBus *bus, void *state),
+                                  void *parent_state)
+{
+    PCIBus *sec;
+    void *state;
+
+    if (!bus) {
+        return;
+    }
+
+    if (begin) {
+        state = begin(bus, parent_state);
+    } else {
+        state = parent_state;
+    }
+
+    QLIST_FOREACH(sec, &bus->child, sibling) {
+        pci_for_each_bus_depth_first(sec, begin, end, state);
+    }
+
+    if (end) {
+        end(bus, state);
+    }
+}
+
+
 PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn)
 {
     bus = pci_find_bus_nr(bus, bus_num);
Signature · 1 line
MST
#18 lore raw

[Qemu-devel] [PULL v2 18/35] pcihp: generalization of piix4 acpi

In reply to Michael S. Tsirkin

Add ACPI based PCI hotplug library with bridge hotplug support.
Design
- each bus gets assigned "bsel" property.
- ACPI code writes this number
to a new BNUM register, then uses existing UP/DOWN registers to probe slot status; to eject, write number to BNUM register, then slot into existing EJ.

The interface is actually backwards-compatible with existing PIIX4 ACPI (though not migration compatible).

This is split out from PIIX4 codebase so we can
reuse it for Q35 as well.

---
 include/hw/acpi/pcihp.h |  72 +++++++++++
 hw/acpi/pcihp.c         | 316 ++++++++++++++++++++++++++++++++++++++++++++++++
 hw/acpi/Makefile.objs   |   3 +-
 3 files changed, 389 insertions(+), 2 deletions(-)
 create mode 100644 include/hw/acpi/pcihp.h
 create mode 100644 hw/acpi/pcihp.c
include/hw/acpi/pcihp.h new file +72 -0
new file mode 100644
index 0000000..6230e60
@@ -0,0 +1,72 @@
+/*
+ * QEMU<->ACPI BIOS PCI hotplug interface
+ *
+ * QEMU supports PCI hotplug via ACPI. This module
+ * implements the interface between QEMU and the ACPI BIOS.
+ * Interface specification - see docs/specs/acpi_pci_hotplug.txt
+ *
+ * Copyright (c) 2013, Red Hat Inc, Michael S. Tsirkin ([email protected])
+ * Copyright (c) 2006 Fabrice Bellard
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * 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/>
+ *
+ * Contributions after 2012-01-13 are licensed under the terms of the
+ * GNU GPL, version 2 or (at your option) any later version.
+ */
+
+#ifndef HW_ACPI_PCIHP_H
+#define HW_ACPI_PCIHP_H
+
+#include <inttypes.h>
+#include <qemu/typedefs.h>
+#include "hw/pci/pci.h" /* for PCIHotplugState */
+
+typedef struct AcpiPciHpPciStatus {
+    uint32_t up; /* deprecated, maintained for migration compatibility */
+    uint32_t down;
+    uint32_t hotplug_enable;
+    uint32_t device_present;
+} AcpiPciHpPciStatus;
+
+#define ACPI_PCIHP_PROP_BSEL "acpi-pcihp-bsel"
+#define ACPI_PCIHP_MAX_HOTPLUG_BUS 256
+
+typedef struct AcpiPciHpState {
+    AcpiPciHpPciStatus acpi_pcihp_pci_status[ACPI_PCIHP_MAX_HOTPLUG_BUS];
+    uint32_t hotplug_select;
+    PCIBus *root;
+    MemoryRegion io;
+} AcpiPciHpState;
+
+void acpi_pcihp_init(AcpiPciHpState *, PCIBus *root,
+                     MemoryRegion *address_space_io);
+
+/* Invoke on device hotplug */
+int acpi_pcihp_device_hotplug(AcpiPciHpState *, PCIDevice *,
+                              PCIHotplugState state);
+
+/* Called on reset */
+void acpi_pcihp_reset(AcpiPciHpState *s);
+
+extern const VMStateDescription vmstate_acpi_pcihp_pci_status;
+
+#define VMSTATE_PCI_HOTPLUG(pcihp, state, test_pcihp) \
+        VMSTATE_UINT32_TEST(pcihp.hotplug_select, state, \
+                            test_pcihp), \
+        VMSTATE_STRUCT_ARRAY_TEST(pcihp.acpi_pcihp_pci_status, state, \
+                                  ACPI_PCIHP_MAX_HOTPLUG_BUS, \
+                                  test_pcihp, 1, \
+                                  vmstate_acpi_pcihp_pci_status, \
+                                  AcpiPciHpPciStatus)
+
+#endif
hw/acpi/pcihp.c new file +316 -0

316 lines not on this page · raw message

hw/acpi/Makefile.objs +1 -2
index a0b63b5..841eca2 100644
@@ -1,2 +1 @@
-common-obj-$(CONFIG_ACPI) += core.o piix4.o ich9.o
-
+common-obj-$(CONFIG_ACPI) += core.o piix4.o ich9.o pcihp.o
Signature · 1 line
MST
#19 lore raw

[Qemu-devel] [PULL v2 19/35] piix4: add acpi pci hotplug support

In reply to Michael S. Tsirkin

Add support for acpi pci hotplug using the
new infrastructure.
PIIX4 legacy interface is maintained as is for
machine types 1.7 and older.

---
 include/hw/i386/pc.h |  5 ++++
 hw/acpi/piix4.c      | 75 +++++++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 70 insertions(+), 10 deletions(-)
include/hw/i386/pc.h +5 -0
index 7fe2bd1..92eabeb 100644
@@ -265,6 +265,11 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t);
             .driver   = TYPE_USB_DEVICE,\
             .property = "msos-desc",\
             .value    = "no",\
+        },\
+        {\
+            .driver   = "PIIX4_PM",\
+            .property = "acpi-pci-hotplug-with-bridge-support",\
+            .value    = "off",\
         }
 
 #define PC_COMPAT_1_6 \
hw/acpi/piix4.c +65 -10

139 lines not on this page · raw message

Signature · 1 line
MST
#20 lore raw

[Qemu-devel] [PULL v2 20/35] acpi-build: enable hotplug for PCI bridges

In reply to Michael S. Tsirkin

This enables support for device hotplug behind
pci bridges. Bridge devices themselves need
to be pre-configured on qemu command line.

Design:
- at machine init time, assign "bsel" property to bridges with hotplug support
- dynamically (At ACPI table read) generate ACPI code to handle hotplug events for each bridge with "bsel" property

Note: ACPI doesn't support adding or removing bridges by hotplug. We detect and prevent removal of bridges by hotplug, unless they were added by hotplug previously
(and so, are not described by ACPI).

---
 hw/i386/acpi-build.c   | 346 +++++++++++++++++++++++++++++++++++++++----------
 hw/i386/acpi-dsdt.dsl  |  34 +++--
 hw/i386/ssdt-pcihp.dsl |  11 +-
 3 files changed, 297 insertions(+), 94 deletions(-)
hw/i386/acpi-build.c +276 -70
index 1d62866..9cd3d0e 100644
@@ -40,6 +40,7 @@
 
 /* Supported chipsets: */
 #include "hw/acpi/piix4.h"
+#include "hw/acpi/pcihp.h"
 #include "hw/i386/ich9.h"
 #include "hw/pci/pci_bus.h"
 #include "hw/pci-host/q35.h"
@@ -79,6 +80,12 @@ typedef struct AcpiMiscInfo {
     uint16_t pvpanic_port;
 } AcpiMiscInfo;
 
+typedef struct AcpiBuildPciBusHotplugState {
+    GArray *device_table;
+    GArray *notify_table;
+    struct AcpiBuildPciBusHotplugState *parent;
+} AcpiBuildPciBusHotplugState;
+
 static void acpi_get_dsdt(AcpiMiscInfo *info)
 {
     uint16_t *applesmc_sta;
@@ -179,38 +186,6 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
                                                NULL);
 }
 
-static void acpi_get_hotplug_info(AcpiMiscInfo *misc)
-{
-    int i;
-    PCIBus *bus = find_i440fx();
-
-    if (!bus) {
-        /* Only PIIX supports ACPI hotplug */
-        memset(misc->slot_hotplug_enable, 0, sizeof misc->slot_hotplug_enable);
-        return;
-    }
-
-    memset(misc->slot_hotplug_enable, 0xff,
-           DIV_ROUND_UP(PCI_SLOT_MAX, BITS_PER_BYTE));
-
-    for (i = 0; i < ARRAY_SIZE(bus->devices); ++i) {
-        PCIDeviceClass *pc;
-        PCIDevice *pdev = bus->devices[i];
-
-        if (!pdev) {
-            continue;
-        }
-
-        pc = PCI_DEVICE_GET_CLASS(pdev);
-
-        if (pc->no_hotplug) {
-            int slot = PCI_SLOT(i);
-
-            clear_bit(slot, misc->slot_hotplug_enable);
-        }
-    }
-}
-
 static void acpi_get_misc_info(AcpiMiscInfo *info)
 {
     info->has_hpet = hpet_find();
@@ -376,6 +351,12 @@ static void build_package(GArray *package, uint8_t op, unsigned 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;
@@ -402,8 +383,44 @@ static void build_append_value(GArray *table, uint32_t value, int size)
     }
 }
 
-static void build_append_notify_target(GArray *method, GArray *target_name,
-                                       uint32_t value, int size)
+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 <= 0xFFFFF) {
+        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();
+
+    build_append_nameseg(method, "%s", name);
+    build_append_byte(method, arg_count); /* MethodFlags: ArgCount */
+
+    return method;
+}
+
+static void build_append_and_cleanup_method(GArray *device, GArray *method)
+{
+    uint8_t op = 0x14; /* MethodOp */
+
+    build_package(method, op, 0);
+
+    build_append_array(device, method);
+    build_free_array(method);
+}
+
+static void build_append_notify_target_ifequal(GArray *method,
+                                               GArray *target_name,
+                                               uint32_t value, int size)
 {
     GArray *notify = build_alloc_array();
     uint8_t op = 0xA0; /* IfOp */
@@ -423,6 +440,7 @@ static void build_append_notify_target(GArray *method, GArray *target_name,
     build_free_array(notify);
 }
 
+/* End here */
 #define ACPI_PORT_SMI_CMD           0x00b2 /* TODO: this is APM_CNT_IOPORT */
 
 static inline void *acpi_data_push(GArray *table_data, unsigned size)
@@ -632,44 +650,236 @@ static inline char acpi_get_hex(uint32_t val)
 #include "hw/i386/ssdt-pcihp.hex"
 
 static void
-build_append_notify(GArray *device, const char *name,
-                    const char *format, int skip, int count)
+build_append_notify_method(GArray *device, const char *name,
+                           const char *format, int count)
 {
     int i;
-    GArray *method = build_alloc_array();
-    uint8_t op = 0x14; /* MethodOp */
+    GArray *method = build_alloc_method(name, 2);
 
-    build_append_nameseg(method, "%s", name);
-    build_append_byte(method, 0x02); /* MethodFlags: ArgCount */
-    for (i = skip; i < count; i++) {
+    for (i = 0; i < count; i++) {
         GArray *target = build_alloc_array();
         build_append_nameseg(target, format, i);
         assert(i < 256); /* Fits in 1 byte */
-        build_append_notify_target(method, target, i, 1);
+        build_append_notify_target_ifequal(method, target, i, 1);
         build_free_array(target);
     }
-    build_package(method, op, 2);
 
-    build_append_array(device, method);
-    build_free_array(method);
+    build_append_and_cleanup_method(device, method);
 }
 
-static void patch_pcihp(int slot, uint8_t *ssdt_ptr, uint32_t eject)
+static void patch_pcihp(int slot, uint8_t *ssdt_ptr)
 {
-    ssdt_ptr[ACPI_PCIHP_OFFSET_HEX] = acpi_get_hex(slot >> 4);
-    ssdt_ptr[ACPI_PCIHP_OFFSET_HEX + 1] = acpi_get_hex(slot);
+    unsigned devfn = PCI_DEVFN(slot, 0);
+
+    ssdt_ptr[ACPI_PCIHP_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
+    ssdt_ptr[ACPI_PCIHP_OFFSET_HEX + 1] = acpi_get_hex(devfn);
     ssdt_ptr[ACPI_PCIHP_OFFSET_ID] = slot;
     ssdt_ptr[ACPI_PCIHP_OFFSET_ADR + 2] = slot;
+}
+
+/* Assign BSEL property to all buses.  In the future, this can be changed
+ * to only assign to buses that support hotplug.
+ */
+static void *acpi_set_bsel(PCIBus *bus, void *opaque)
+{
+    unsigned *bsel_alloc = opaque;
+    unsigned *bus_bsel;
+
+    if (bus->qbus.allow_hotplug) {
+        bus_bsel = g_malloc(sizeof *bus_bsel);
+
+        *bus_bsel = (*bsel_alloc)++;
+        object_property_add_uint32_ptr(OBJECT(bus), ACPI_PCIHP_PROP_BSEL,
+                                       bus_bsel, NULL);
+    }
+
+    return bsel_alloc;
+}
+
+static void acpi_set_pci_info(void)
+{
+    PCIBus *bus = find_i440fx(); /* TODO: Q35 support */
+    unsigned bsel_alloc = 0;
+
+    if (bus) {
+        /* Scan all PCI buses. Set property to enable acpi based hotplug. */
+        pci_for_each_bus_depth_first(bus, acpi_set_bsel, NULL, &bsel_alloc);
+    }
+}
+
+static void build_pci_bus_state_init(AcpiBuildPciBusHotplugState *state,
+                                     AcpiBuildPciBusHotplugState *parent)
+{
+    state->parent = parent;
+    state->device_table = build_alloc_array();
+    state->notify_table = build_alloc_array();
+}
+
+static void build_pci_bus_state_cleanup(AcpiBuildPciBusHotplugState *state)
+{
+    build_free_array(state->device_table);
+    build_free_array(state->notify_table);
+}
+
+static void *build_pci_bus_begin(PCIBus *bus, void *parent_state)
+{
+    AcpiBuildPciBusHotplugState *parent = parent_state;
+    AcpiBuildPciBusHotplugState *child = g_malloc(sizeof *child);
+
+    build_pci_bus_state_init(child, parent);
+
+    return child;
+}
+
+static void build_pci_bus_end(PCIBus *bus, void *bus_state)
+{
+    AcpiBuildPciBusHotplugState *child = bus_state;
+    AcpiBuildPciBusHotplugState *parent = child->parent;
+    GArray *bus_table = build_alloc_array();
+    DECLARE_BITMAP(slot_hotplug_enable, PCI_SLOT_MAX);
+    uint8_t op;
+    int i;
+    QObject *bsel;
+    GArray *method;
+    bool bus_hotplug_support = false;
+
+    if (bus->parent_dev) {
+        op = 0x82; /* DeviceOp */
+        build_append_nameseg(bus_table, "S%.02X_",
+                             bus->parent_dev->devfn);
+        build_append_byte(bus_table, 0x08); /* NameOp */
+        build_append_nameseg(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_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");
+    }
 
-    /* Runtime patching of ACPI_EJ0: to disable hotplug for a slot,
-     * replace the method name: _EJ0 by ACPI_EJ0_.
+    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_int(bus_table, qint_get_int(qobject_to_qint(bsel)));
+
+        memset(slot_hotplug_enable, 0xff, sizeof slot_hotplug_enable);
+
+        for (i = 0; i < ARRAY_SIZE(bus->devices); ++i) {
+            PCIDeviceClass *pc;
+            PCIDevice *pdev = bus->devices[i];
+
+            if (!pdev) {
+                continue;
+            }
+
+            pc = PCI_DEVICE_GET_CLASS(pdev);
+
+            if (pc->no_hotplug || pc->is_bridge) {
+                int slot = PCI_SLOT(i);
+
+                clear_bit(slot, slot_hotplug_enable);
+            }
+        }
+
+        /* Append Device object for each slot which supports eject */
+        for (i = 0; i < PCI_SLOT_MAX; i++) {
+            bool can_eject = test_bit(i, slot_hotplug_enable);
+            if (can_eject) {
+                void *pcihp = acpi_data_push(bus_table,
+                                             ACPI_PCIHP_SIZEOF);
+                memcpy(pcihp, ACPI_PCIHP_AML, ACPI_PCIHP_SIZEOF);
+                patch_pcihp(i, pcihp);
+                bus_hotplug_support = true;
+            }
+        }
+
+        method = build_alloc_method("DVNT", 2);
+
+        for (i = 0; i < PCI_SLOT_MAX; i++) {
+            GArray *notify;
+            uint8_t op;
+
+            if (!test_bit(i, slot_hotplug_enable)) {
+                continue;
+            }
+
+            notify = build_alloc_array();
+            op = 0xA0; /* IfOp */
+
+            build_append_byte(notify, 0x7B); /* AndOp */
+            build_append_byte(notify, 0x68); /* Arg0Op */
+            build_append_int(notify, 0x1 << 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_byte(notify, 0x69); /* Arg1Op */
+
+            /* Pack it up */
+            build_package(notify, op, 0);
+
+            build_append_array(method, notify);
+
+            build_free_array(notify);
+        }
+
+        build_append_and_cleanup_method(bus_table, method);
+    }
+
+    /* Append PCNT method to notify about events on local and child buses.
+     * Add unconditionally for root since DSDT expects it.
      */
-    /* Sanity check */
-    assert(!memcmp(ssdt_ptr + ACPI_PCIHP_OFFSET_EJ0, "_EJ0", 4));
+    if (bus_hotplug_support || child->notify_table->len || !bus->parent_dev) {
+        method = build_alloc_method("PCNT", 0);
+
+        /* If bus supports hotplug select it and notify about local events */
+        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_int(method, 1); /* Device Check */
+            build_append_nameseg(method, "DVNT");
+            build_append_nameseg(method, "PCID");
+            build_append_int(method, 3); /* Eject Request */
+        }
+
+        /* Notify about child bus events in any case */
+        build_append_array(method, child->notify_table);
+
+        build_append_and_cleanup_method(bus_table, method);
+
+        /* Append description of child buses */
+        build_append_array(bus_table, child->device_table);
+
+        /* Pack it up */
+        if (bus->parent_dev) {
+            build_extop_package(bus_table, op);
+        } else {
+            build_package(bus_table, op, 0);
+        }
 
-    if (!eject) {
-        memcpy(ssdt_ptr + ACPI_PCIHP_OFFSET_EJ0, "EJ0_", 4);
+        /* Append our bus description to parent table */
+        build_append_array(parent->device_table, bus_table);
+
+        /* Also tell parent how to notify us, invoking PCNT method.
+         * 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_free_array(bus_table);
+    build_pci_bus_state_cleanup(child);
+    g_free(child);
 }
 
 static void patch_pci_windows(PcPciInfo *pci, uint8_t *start, unsigned size)
@@ -741,7 +951,7 @@ 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(sb_scope, "NTFY", "CP%0.02X", 0, acpi_cpus);
+        build_append_notify_method(sb_scope, "NTFY", "CP%0.02X", acpi_cpus);
 
         /* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" */
         build_append_byte(sb_scope, 0x08); /* NameOp */
@@ -763,24 +973,19 @@ build_ssdt(GArray *table_data, GArray *linker,
         }
 
         {
-            GArray *pci0 = build_alloc_array();
-            uint8_t op = 0x10; /* ScopeOp */;
+            AcpiBuildPciBusHotplugState hotplug_state;
+            PCIBus *bus = find_i440fx(); /* TODO: Q35 support */
 
-            build_append_nameseg(pci0, "PCI0");
+            build_pci_bus_state_init(&hotplug_state, NULL);
 
-            /* build Device object for each slot */
-            for (i = 1; i < PCI_SLOT_MAX; i++) {
-                bool eject = test_bit(i, misc->slot_hotplug_enable);
-                void *pcihp = acpi_data_push(pci0, ACPI_PCIHP_SIZEOF);
-
-                memcpy(pcihp, ACPI_PCIHP_AML, ACPI_PCIHP_SIZEOF);
-                patch_pcihp(i, pcihp, eject);
+            if (bus) {
+                /* Scan all PCI buses. Generate tables to support hotplug. */
+                pci_for_each_bus_depth_first(bus, build_pci_bus_begin,
+                                             build_pci_bus_end, &hotplug_state);
             }
 
-            build_append_notify(pci0, "PCNT", "S%0.02X_", 1, PCI_SLOT_MAX);
-            build_package(pci0, op, 3);
-            build_append_array(sb_scope, pci0);
-            build_free_array(pci0);
+            build_append_array(sb_scope, hotplug_state.device_table);
+            build_pci_bus_state_cleanup(&hotplug_state);
         }
 
         build_package(sb_scope, op, 3);
@@ -1063,7 +1268,6 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
     acpi_get_cpu_info(&cpu);
     acpi_get_pm_info(&pm);
     acpi_get_dsdt(&misc);
-    acpi_get_hotplug_info(&misc);
     acpi_get_misc_info(&misc);
     acpi_get_pci_info(&pci);
 
@@ -1208,6 +1412,8 @@ void acpi_setup(PcGuestInfo *guest_info)
 
     build_state->guest_info = guest_info;
 
+    acpi_set_pci_info();
+
     acpi_build_tables_init(&tables);
     acpi_build(build_state->guest_info, &tables);
 
hw/i386/acpi-dsdt.dsl +16 -18
index b87c6e0..6d76f30 100644
@@ -134,32 +134,28 @@ DefinitionBlock (
             B0EJ, 32,
         }
 
+        OperationRegion(BNMR, SystemIO, 0xae10, 0x04)
+        Field(BNMR, DWordAcc, NoLock, WriteAsZeros) {
+            BNUM, 32,
+        }
+
+        /* Lock to protect access to fields above. */
+        Mutex(BLCK, 0)
+
         /* Methods called by bulk generated PCI devices below */
 
         /* Methods called by hotplug devices */
-        Method(PCEJ, 1, NotSerialized) {
+        Method(PCEJ, 2, NotSerialized) {
             // _EJ0 method - eject callback
-            Store(ShiftLeft(1, Arg0), B0EJ)
+            Acquire(BLCK, 0xFFFF)
+            Store(Arg0, BNUM)
+            Store(ShiftLeft(1, Arg1), B0EJ)
+            Release(BLCK)
             Return (0x0)
         }
 
         /* Hotplug notification method supplied by SSDT */
         External(\_SB.PCI0.PCNT, MethodObj)
-
-        /* PCI hotplug notify method */
-        Method(PCNF, 0) {
-            // Local0 = iterator
-            Store(Zero, Local0)
-            While (LLess(Local0, 31)) {
-                Increment(Local0)
-                If (And(PCIU, ShiftLeft(1, Local0))) {
-                    PCNT(Local0, 1)
-                }
-                If (And(PCID, ShiftLeft(1, Local0))) {
-                    PCNT(Local0, 3)
-                }
-            }
-        }
     }
 
 
@@ -308,7 +304,9 @@ DefinitionBlock (
         }
         Method(_E01) {
             // PCI hotplug event
-            \_SB.PCI0.PCNF()
+            Acquire(\_SB.PCI0.BLCK, 0xFFFF)
+            \_SB.PCI0.PCNT()
+            Release(\_SB.PCI0.BLCK)
         }
         Method(_E02) {
             // CPU hotplug event
hw/i386/ssdt-pcihp.dsl +5 -6
index d29a5b9..cc245c3 100644
@@ -25,6 +25,7 @@ DefinitionBlock ("ssdt-pcihp.aml", "SSDT", 0x01, "BXPC", "BXSSDTPCIHP", 0x1)
     /* Objects supplied by DSDT */
     External(\_SB.PCI0, DeviceObj)
     External(\_SB.PCI0.PCEJ, MethodObj)
+    External(BSEL, IntObj)
 
     Scope(\_SB.PCI0) {
 
@@ -33,19 +34,17 @@ DefinitionBlock ("ssdt-pcihp.aml", "SSDT", 0x01, "BXPC", "BXSSDTPCIHP", 0x1)
         ACPI_EXTRACT_DEVICE_END ssdt_pcihp_end
         ACPI_EXTRACT_DEVICE_STRING ssdt_pcihp_name
 
-        // Method _EJ0 can be patched by BIOS to EJ0_
-        // at runtime, if the slot is detected to not support hotplug.
-        // Extract the offset of the address dword and the
-        // _EJ0 name to allow this patching.
+        // Extract the offsets of the device name, address dword and the slot
+        // name byte - we fill them in for each device.
         Device(SAA) {
             ACPI_EXTRACT_NAME_BYTE_CONST ssdt_pcihp_id
             Name(_SUN, 0xAA)
             ACPI_EXTRACT_NAME_DWORD_CONST ssdt_pcihp_adr
             Name(_ADR, 0xAA0000)
-            ACPI_EXTRACT_METHOD_STRING ssdt_pcihp_ej0
             Method(_EJ0, 1) {
-                Return (PCEJ(_SUN))
+                PCEJ(BSEL, _SUN)
             }
         }
+
     }
 }
Signature · 1 line
MST
#21 lore raw

[Qemu-devel] [PULL v2 21/35] acpi: factor out common cpu hotplug code for PIIX4/Q35

In reply to Michael S. Tsirkin

From: Igor Mammedov <[email protected]>

.. so it could be used for adding CPU hotplug to Q35 machine

Add an additional header with that will be shared between C and ASL code: include/hw/acpi/cpu_hotplug_defs.h

---
 include/hw/acpi/cpu_hotplug.h      | 27 +++++++++++++
 include/hw/acpi/cpu_hotplug_defs.h | 22 +++++++++++
 hw/acpi/cpu_hotplug.c              | 64 +++++++++++++++++++++++++++++++
 hw/acpi/piix4.c                    | 77 +++-----------------------------------
 hw/acpi/Makefile.objs              |  2 +-
 5 files changed, 120 insertions(+), 72 deletions(-)
 create mode 100644 include/hw/acpi/cpu_hotplug.h
 create mode 100644 include/hw/acpi/cpu_hotplug_defs.h
 create mode 100644 hw/acpi/cpu_hotplug.c
include/hw/acpi/cpu_hotplug.h new file +27 -0
new file mode 100644
index 0000000..4576400
@@ -0,0 +1,27 @@
+/*
+ * QEMU ACPI hotplug utilities
+ *
+ * Copyright (C) 2013 Red Hat Inc
+ *
+ * Authors:
+ *   Igor Mammedov <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#ifndef ACPI_HOTPLUG_H
+#define ACPI_HOTPLUG_H
+
+#include "hw/acpi/acpi.h"
+#include "hw/acpi/cpu_hotplug_defs.h"
+
+typedef struct AcpiCpuHotplug {
+    MemoryRegion io;
+    uint8_t sts[ACPI_GPE_PROC_LEN];
+} AcpiCpuHotplug;
+
+void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu);
+
+void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
+                         AcpiCpuHotplug *gpe_cpu, uint16_t base);
+#endif
include/hw/acpi/cpu_hotplug_defs.h new file +22 -0
new file mode 100644
index 0000000..c6c4f78
@@ -0,0 +1,22 @@
+/*
+ * QEMU ACPI hotplug utilities shared defines
+ *
+ * Copyright (C) 2013 Red Hat Inc
+ *
+ * Authors:
+ *   Igor Mammedov <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#ifndef ACPI_HOTPLUG_DEFS_H
+#define ACPI_HOTPLUG_DEFS_H
+
+/*
+ * ONLY DEFINEs are permited in this file since it's shared
+ * between C and ASL code.
+ */
+#define ACPI_CPU_HOTPLUG_STATUS 4
+#define ACPI_GPE_PROC_LEN 32
+
+#endif
hw/acpi/cpu_hotplug.c new file +64 -0

64 lines not on this page · raw message

hw/acpi/piix4.c +6 -71

131 lines not on this page · raw message

hw/acpi/Makefile.objs +1 -1
index 841eca2..397d32b 100644
@@ -1 +1 @@
-common-obj-$(CONFIG_ACPI) += core.o piix4.o ich9.o pcihp.o
+common-obj-$(CONFIG_ACPI) += core.o piix4.o ich9.o pcihp.o cpu_hotplug.o
Signature · 1 line
MST
#22 lore raw

[Qemu-devel] [PULL v2 22/35] acpi: ich9: add CPU hotplug handling to Q35 machine

In reply to Michael S. Tsirkin

From: Igor Mammedov <[email protected]>

.. use IO port 0cd8-0xcf7 range for CPU present bitmap

---
 include/hw/acpi/cpu_hotplug_defs.h |  1 +
 include/hw/acpi/ich9.h             |  4 ++++
 hw/acpi/ich9.c                     | 14 ++++++++++++++
 docs/specs/acpi_cpu_hotplug.txt    |  4 +++-
 4 files changed, 22 insertions(+), 1 deletion(-)
include/hw/acpi/cpu_hotplug_defs.h +1 -0
index c6c4f78..47a35e3 100644
@@ -18,5 +18,6 @@
  */
 #define ACPI_CPU_HOTPLUG_STATUS 4
 #define ACPI_GPE_PROC_LEN 32
+#define ICH9_CPU_HOTPLUG_IO_BASE 0x0CD8
 
 #endif
include/hw/acpi/ich9.h +4 -0
index 82fcf9f..104f419 100644
@@ -22,6 +22,7 @@
 #define HW_ACPI_ICH9_H
 
 #include "hw/acpi/acpi.h"
+#include "hw/acpi/cpu_hotplug.h"
 
 typedef struct ICH9LPCPMRegs {
     /*
@@ -42,6 +43,9 @@ typedef struct ICH9LPCPMRegs {
 
     uint32_t pm_io_base;
     Notifier powerdown_notifier;
+
+    AcpiCpuHotplug gpe_cpu;
+    Notifier cpu_added_notifier;
 } ICH9LPCPMRegs;
 
 void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
hw/acpi/ich9.c +14 -0
index 30f0df8..0afac42 100644
@@ -185,6 +185,15 @@ static void pm_powerdown_req(Notifier *n, void *opaque)
     acpi_pm1_evt_power_down(&pm->acpi_regs);
 }
 
+static void ich9_cpu_added_req(Notifier *n, void *opaque)
+{
+    ICH9LPCPMRegs *pm = container_of(n, ICH9LPCPMRegs, cpu_added_notifier);
+
+    assert(pm != NULL);
+    AcpiCpuHotplug_add(&pm->acpi_regs.gpe, &pm->gpe_cpu, CPU(opaque));
+    acpi_update_sci(&pm->acpi_regs, pm->irq);
+}
+
 void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
                   qemu_irq sci_irq)
 {
@@ -210,6 +219,11 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
     qemu_register_reset(pm_reset, pm);
     pm->powerdown_notifier.notify = pm_powerdown_req;
     qemu_register_powerdown_notifier(&pm->powerdown_notifier);
+
+    AcpiCpuHotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
+                        &pm->gpe_cpu, ICH9_CPU_HOTPLUG_IO_BASE);
+    pm->cpu_added_notifier.notify = ich9_cpu_added_req;
+    qemu_register_cpu_added_notifier(&pm->cpu_added_notifier);
 }
 
 static void ich9_pm_get_gpe0_blk(Object *obj, Visitor *v,
docs/specs/acpi_cpu_hotplug.txt +3 -1
index f6f5774..340b751 100644
@@ -10,7 +10,9 @@ ACPI GPE block (IO ports 0xafe0-0xafe3, byte access):
 Generic ACPI GPE block. Bit 2 (GPE.2) used to notify CPU
 hot-add/remove event to ACPI BIOS, via SCI interrupt.
 
-CPU present bitmap (IO port 0xaf00-0xaf1f, 1-byte access):
+CPU present bitmap for:
+  ICH9-LPC (IO port 0x0cd8-0xcf7, 1-byte access)
+  PIIX-PM  (IO port 0xaf00-0xaf1f, 1-byte access)
 ---------------------------------------------------------------
 One bit per CPU. Bit position reflects corresponding CPU APIC ID.
 Read-only.
Signature · 1 line
MST
#23 lore raw

[Qemu-devel] [PULL v2 23/35] pc: set PRST base in DSDT depending on chipset

In reply to Michael S. Tsirkin

From: Igor Mammedov <[email protected]>

---
 hw/i386/acpi-dsdt-cpu-hotplug.dsl | 2 +-
 hw/i386/acpi-dsdt.dsl             | 1 +
 hw/i386/q35-acpi-dsdt.dsl         | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)
hw/i386/acpi-dsdt-cpu-hotplug.dsl +1 -1
index 995b415..1dfbb4f 100644
@@ -52,7 +52,7 @@ Scope(\_SB) {
         Sleep(200)
     }
 
-    OperationRegion(PRST, SystemIO, 0xaf00, 32)
+    OperationRegion(PRST, SystemIO, CPU_STATUS_BASE, 32)
     Field(PRST, ByteAcc, NoLock, Preserve) {
         PRS, 256
     }
hw/i386/acpi-dsdt.dsl +1 -0
index 6d76f30..3dc4789 100644
@@ -290,6 +290,7 @@ DefinitionBlock (
         }
     }
 
+#define CPU_STATUS_BASE 0xaf00
 #include "acpi-dsdt-cpu-hotplug.dsl"
 
 
hw/i386/q35-acpi-dsdt.dsl +1 -0
index ee38fd6..9a43947 100644
@@ -405,6 +405,7 @@ DefinitionBlock (
         define_gsi_link(GSIH, 0, 0x17)
     }
 
+#define CPU_STATUS_BASE 0x0CD8
 #include "acpi-dsdt-cpu-hotplug.dsl"
 
 
Signature · 1 line
MST
#24 lore raw

[Qemu-devel] [PULL v2 24/35] pc: PIIX DSDT: exclude CPU/PCI hotplug & GPE0 IO range from PCI bus resources

In reply to Michael S. Tsirkin

From: Igor Mammedov <[email protected]>

.. so that they might not be used by PCI devices.

Note:
Resort to concatenating templates with preprocessor help, because 1.0b spec isn't supporting ConcatenateResTemplate, as result Windows XP fails to execute PCI0._CRS method if ConcatenateResTemplate() is used.

---
 hw/i386/acpi-dsdt-pci-crs.dsl |  8 +-------
 hw/i386/acpi-dsdt.dsl         | 32 ++++++++++++++++++++++++++++++++
 hw/i386/q35-acpi-dsdt.dsl     |  8 ++++++++
 3 files changed, 41 insertions(+), 7 deletions(-)
hw/i386/acpi-dsdt-pci-crs.dsl +1 -7
index b375a19..8b631d1 100644
@@ -37,13 +37,7 @@ Scope(\_SB.PCI0) {
             0x0000,             // Address Translation Offset
             0x0CF8,             // Address Length
             ,, , TypeStatic)
-        WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
-            0x0000,             // Address Space Granularity
-            0x0D00,             // Address Range Minimum
-            0xFFFF,             // Address Range Maximum
-            0x0000,             // Address Translation Offset
-            0xF300,             // Address Length
-            ,, , TypeStatic)
+        BOARD_SPECIFIC_PCI_RESOURSES
         DWordMemory(ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
             0x00000000,         // Address Space Granularity
             0x000A0000,         // Address Range Minimum
hw/i386/acpi-dsdt.dsl +32 -0
index 3dc4789..f501c8d 100644
@@ -35,6 +35,38 @@ DefinitionBlock (
 /****************************************************************
  * PCI Bus definition
  ****************************************************************/
+#define BOARD_SPECIFIC_PCI_RESOURSES \
+     WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange, \
+         0x0000, \
+         0x0D00, \
+         0xADFF, \
+         0x0000, \
+         0xA100, \
+         ,, , TypeStatic) \
+     /* 0xae00-0xae0e hole for PCI hotplug, hw/acpi/piix4.c:PCI_HOTPLUG_ADDR */ \
+     WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange, \
+         0x0000, \
+         0xAE0F, \
+         0xAEFF, \
+         0x0000, \
+         0x00F1, \
+         ,, , TypeStatic) \
+     /* 0xaf00-0xaf1f hole for CPU hotplug, hw/acpi/piix4.c:PIIX4_PROC_BASE */ \
+     WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange, \
+         0x0000, \
+         0xAF20, \
+         0xAFDF, \
+         0x0000, \
+         0x00C0, \
+         ,, , TypeStatic) \
+     /* 0xafe0-0xafe3 hole for ACPI.GPE0, hw/acpi/piix4.c:GPE_BASE */ \
+     WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange, \
+         0x0000, \
+         0xAFE4, \
+         0xFFFF, \
+         0x0000, \
+         0x501C, \
+         ,, , TypeStatic)
 
     Scope(\_SB) {
         Device(PCI0) {
hw/i386/q35-acpi-dsdt.dsl +8 -0
index 9a43947..f3e5921 100644
@@ -48,6 +48,14 @@ DefinitionBlock (
 /****************************************************************
  * PCI Bus definition
  ****************************************************************/
+#define BOARD_SPECIFIC_PCI_RESOURSES \
+     WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange, \
+         0x0000, \
+         0x0D00, \
+         0xFFFF, \
+         0x0000, \
+         0xF300, \
+         ,, , TypeStatic)
 
     Scope(\_SB) {
         Device(PCI0) {
Signature · 1 line
MST
#25 lore raw

[Qemu-devel] [PULL v2 25/35] pc: Q35 DSDT: exclude CPU hotplug IO range from PCI bus resources

In reply to Michael S. Tsirkin

From: Igor Mammedov <[email protected]>

... for range defined at hw/acpi/ich9.c:ICH9_PROC_BASE

---
 hw/i386/acpi-dsdt-pci-crs.dsl | 7 -------
 hw/i386/acpi-dsdt.dsl         | 7 +++++++
 hw/i386/q35-acpi-dsdt.dsl     | 8 ++++++++
 3 files changed, 15 insertions(+), 7 deletions(-)
hw/i386/acpi-dsdt-pci-crs.dsl +0 -7
index 8b631d1..4648e90 100644
@@ -30,13 +30,6 @@ Scope(\_SB.PCI0) {
             0x01,               // Address Alignment
             0x08,               // Address Length
             )
-        WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
-            0x0000,             // Address Space Granularity
-            0x0000,             // Address Range Minimum
-            0x0CF7,             // Address Range Maximum
-            0x0000,             // Address Translation Offset
-            0x0CF8,             // Address Length
-            ,, , TypeStatic)
         BOARD_SPECIFIC_PCI_RESOURSES
         DWordMemory(ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
             0x00000000,         // Address Space Granularity
hw/i386/acpi-dsdt.dsl +7 -0
index f501c8d..d89dcda 100644
@@ -38,6 +38,13 @@ DefinitionBlock (
 #define BOARD_SPECIFIC_PCI_RESOURSES \
      WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange, \
          0x0000, \
+         0x0000, \
+         0x0CF7, \
+         0x0000, \
+         0x0CF8, \
+         ,, , TypeStatic) \
+     WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange, \
+         0x0000, \
          0x0D00, \
          0xADFF, \
          0x0000, \
hw/i386/q35-acpi-dsdt.dsl +8 -0
index f3e5921..9e070ee 100644
@@ -51,6 +51,14 @@ DefinitionBlock (
 #define BOARD_SPECIFIC_PCI_RESOURSES \
      WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange, \
          0x0000, \
+         0x0000, \
+         0x0CD7, \
+         0x0000, \
+         0x0CD8, \
+         ,, , TypeStatic) \
+     /* 0xcd8-0xcf7 hole for CPU hotplug, hw/acpi/ich9.c:ICH9_PROC_BASE */ \
+     WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange, \
+         0x0000, \
          0x0D00, \
          0xFFFF, \
          0x0000, \
Signature · 1 line
MST
#26 lore raw

[Qemu-devel] [PULL v2 26/35] pc: ACPI: expose PRST IO range via _CRS

In reply to Michael S. Tsirkin

From: Igor Mammedov <[email protected]>

.. so OSPM could notice resource conflict if there is any.

---
 hw/i386/acpi-dsdt-cpu-hotplug.dsl | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
hw/i386/acpi-dsdt-cpu-hotplug.dsl +13 -1
index 1dfbb4f..f91eafd 100644
@@ -16,6 +16,7 @@
 /****************************************************************
  * CPU hotplug
  ****************************************************************/
+#define CPU_HOTPLUG_RESOURCE_DEVICE PRES
 
 Scope(\_SB) {
     /* Objects filled in by run-time generated SSDT */
@@ -52,7 +53,8 @@ Scope(\_SB) {
         Sleep(200)
     }
 
-    OperationRegion(PRST, SystemIO, CPU_STATUS_BASE, 32)
+#define CPU_STATUS_LEN 32
+    OperationRegion(PRST, SystemIO, CPU_STATUS_BASE, CPU_STATUS_LEN)
     Field(PRST, ByteAcc, NoLock, Preserve) {
         PRS, 256
     }
@@ -89,4 +91,14 @@ Scope(\_SB) {
             Increment(Local0)
         }
     }
+
+    Device(CPU_HOTPLUG_RESOURCE_DEVICE) {
+        Name(_HID, "ACPI0004")
+
+        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 */
+    }
 }
Signature · 1 line
MST
#27 lore raw

[Qemu-devel] [PULL v2 27/35] pc: ACPI: unify source of CPU hotplug IO base/len

In reply to Michael S. Tsirkin

From: Igor Mammedov <[email protected]>

use C headers defines as source of IO base/len for respective values in ASL code.

---
 include/hw/acpi/cpu_hotplug_defs.h | 1 +
 hw/acpi/piix4.c                    | 5 ++---
 hw/i386/Makefile.objs              | 2 +-
 hw/i386/acpi-dsdt-cpu-hotplug.dsl  | 2 +-
 hw/i386/acpi-dsdt.dsl              | 3 ++-
 hw/i386/q35-acpi-dsdt.dsl          | 3 ++-
 6 files changed, 9 insertions(+), 7 deletions(-)
include/hw/acpi/cpu_hotplug_defs.h +1 -0
index 47a35e3..2725b50 100644
@@ -19,5 +19,6 @@
 #define ACPI_CPU_HOTPLUG_STATUS 4
 #define ACPI_GPE_PROC_LEN 32
 #define ICH9_CPU_HOTPLUG_IO_BASE 0x0CD8
+#define PIIX4_CPU_HOTPLUG_IO_BASE 0xaf00
 
 #endif
hw/acpi/piix4.c +2 -3
index 12f8dde..5d55a3c 100644
@@ -51,8 +51,6 @@
 #define PCI_EJ_BASE 0xae08
 #define PCI_RMV_BASE 0xae0c
 
-#define PIIX4_PROC_BASE 0xaf00
-
 #define PIIX4_PCI_HOTPLUG_STATUS 2
 
 struct pci_status {
@@ -706,7 +704,8 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
         pci_bus_hotplug(bus, piix4_device_hotplug, DEVICE(s));
     }
 
-    AcpiCpuHotplug_init(parent, OBJECT(s), &s->gpe_cpu, PIIX4_PROC_BASE);
+    AcpiCpuHotplug_init(parent, OBJECT(s), &s->gpe_cpu,
+                        PIIX4_CPU_HOTPLUG_IO_BASE);
     s->cpu_added_notifier.notify = piix4_cpu_added_req;
     qemu_register_cpu_added_notifier(&s->cpu_added_notifier);
 }
hw/i386/Makefile.objs +1 -1
index d58a103..3df1612 100644
@@ -17,7 +17,7 @@ iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
 ifdef IASL
 #IASL Present. Generate hex files from .dsl
 hw/i386/%.hex: $(SRC_PATH)/hw/i386/%.dsl $(SRC_PATH)/scripts/acpi_extract_preprocess.py $(SRC_PATH)/scripts/acpi_extract.py
-	$(call quiet-command, cpp -P $(QEMU_DGFLAGS) $< -o $*.dsl.i.orig, "  CPP $(TARGET_DIR)$*.dsl.i.orig")
+	$(call quiet-command, cpp -P $(QEMU_DGFLAGS) $(QEMU_INCLUDES) $< -o $*.dsl.i.orig, "  CPP $(TARGET_DIR)$*.dsl.i.orig")
 	$(call quiet-command, $(PYTHON) $(SRC_PATH)/scripts/acpi_extract_preprocess.py $*.dsl.i.orig > $*.dsl.i, "  ACPI_PREPROCESS $(TARGET_DIR)$*.dsl.i")
 	$(call quiet-command, $(IASL) $(call iasl-option,$(IASL),-Pn,) -vs -l -tc -p $* $*.dsl.i $(if $(V), , > /dev/null) 2>&1 ,"  IASL $(TARGET_DIR)$*.dsl.i")
 	$(call quiet-command, $(PYTHON) $(SRC_PATH)/scripts/acpi_extract.py $*.lst > $*.off, "  ACPI_EXTRACT $(TARGET_DIR)$*.off")
hw/i386/acpi-dsdt-cpu-hotplug.dsl +1 -1
index f91eafd..dee4843 100644
@@ -53,7 +53,7 @@ Scope(\_SB) {
         Sleep(200)
     }
 
-#define CPU_STATUS_LEN 32
+#define CPU_STATUS_LEN ACPI_GPE_PROC_LEN
     OperationRegion(PRST, SystemIO, CPU_STATUS_BASE, CPU_STATUS_LEN)
     Field(PRST, ByteAcc, NoLock, Preserve) {
         PRS, 256
hw/i386/acpi-dsdt.dsl +2 -1
index d89dcda..b23d5e0 100644
@@ -329,7 +329,8 @@ DefinitionBlock (
         }
     }
 
-#define CPU_STATUS_BASE 0xaf00
+#include "hw/acpi/cpu_hotplug_defs.h"
+#define CPU_STATUS_BASE PIIX4_CPU_HOTPLUG_IO_BASE
 #include "acpi-dsdt-cpu-hotplug.dsl"
 
 
hw/i386/q35-acpi-dsdt.dsl +2 -1
index 9e070ee..d618e9e 100644
@@ -421,7 +421,8 @@ DefinitionBlock (
         define_gsi_link(GSIH, 0, 0x17)
     }
 
-#define CPU_STATUS_BASE 0x0CD8
+#include "hw/acpi/cpu_hotplug_defs.h"
+#define CPU_STATUS_BASE ICH9_CPU_HOTPLUG_IO_BASE
 #include "acpi-dsdt-cpu-hotplug.dsl"
 
 
Signature · 1 line
MST
#28 lore raw

[Qemu-devel] [PULL v2 28/35] pc: ACPI: update acpi-dsdt.hex.generated q35-acpi-dsdt.hex.generated

In reply to Michael S. Tsirkin

From: Igor Mammedov <[email protected]>

---
 hw/i386/acpi-dsdt.hex.generated     | 217 +++++++++++++++++++++++++-----------
 hw/i386/q35-acpi-dsdt.hex.generated |  74 ++++++++++--
 hw/i386/ssdt-pcihp.hex.generated    |  20 ++--
 hw/i386/ssdt-proc.hex.generated     |   6 +-
 4 files changed, 225 insertions(+), 92 deletions(-)
hw/i386/acpi-dsdt.hex.generated +150 -67
index f8bd4ea..1e58801 100644
@@ -3,12 +3,12 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x53,
 0x44,
 0x54,
-0x37,
+0x87,
 0x11,
 0x0,
 0x0,
 0x1,
-0xd8,
+0xb8,
 0x42,
 0x58,
 0x50,
@@ -860,8 +860,8 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x4e,
 0x1,
 0x10,
-0x4c,
-0x1b,
+0x4b,
+0x1e,
 0x2f,
 0x3,
 0x5f,
@@ -879,6 +879,53 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x5b,
 0x82,
 0x2d,
+0x53,
+0x4d,
+0x43,
+0x5f,
+0x8,
+0x5f,
+0x48,
+0x49,
+0x44,
+0xc,
+0x6,
+0x10,
+0x0,
+0x1,
+0x8,
+0x5f,
+0x53,
+0x54,
+0x41,
+0xb,
+0x0,
+0xff,
+0x8,
+0x5f,
+0x43,
+0x52,
+0x53,
+0x11,
+0x10,
+0xa,
+0xd,
+0x47,
+0x1,
+0x0,
+0x3,
+0x0,
+0x3,
+0x1,
+0x20,
+0x22,
+0x40,
+0x0,
+0x79,
+0x0,
+0x5b,
+0x82,
+0x2d,
 0x52,
 0x54,
 0x43,
@@ -1305,7 +1352,7 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x79,
 0x0,
 0x10,
-0x4b,
+0x48,
 0x8,
 0x2e,
 0x5f,
@@ -1371,79 +1418,76 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x45,
 0x4a,
 0x20,
+0x5b,
+0x80,
+0x42,
+0x4e,
+0x4d,
+0x52,
+0x1,
+0xb,
+0x10,
+0xae,
+0xa,
+0x4,
+0x5b,
+0x81,
+0xb,
+0x42,
+0x4e,
+0x4d,
+0x52,
+0x43,
+0x42,
+0x4e,
+0x55,
+0x4d,
+0x20,
+0x5b,
+0x1,
+0x42,
+0x4c,
+0x43,
+0x4b,
+0x0,
 0x14,
-0x11,
+0x25,
 0x50,
 0x43,
 0x45,
 0x4a,
-0x1,
+0x2,
+0x5b,
+0x23,
+0x42,
+0x4c,
+0x43,
+0x4b,
+0xff,
+0xff,
 0x70,
-0x79,
-0x1,
 0x68,
-0x0,
 0x42,
-0x30,
-0x45,
-0x4a,
-0xa4,
-0x0,
-0x14,
-0x36,
-0x50,
-0x43,
 0x4e,
-0x46,
-0x0,
-0x70,
-0x0,
-0x60,
-0xa2,
-0x2c,
-0x95,
-0x60,
-0xa,
-0x1f,
-0x75,
-0x60,
-0xa0,
-0x11,
-0x7b,
-0x50,
-0x43,
-0x49,
 0x55,
+0x4d,
+0x70,
 0x79,
 0x1,
-0x60,
+0x69,
 0x0,
-0x0,
-0x50,
-0x43,
-0x4e,
-0x54,
-0x60,
-0x1,
-0xa0,
-0x12,
-0x7b,
-0x50,
+0x42,
+0x30,
+0x45,
+0x4a,
+0x5b,
+0x27,
+0x42,
+0x4c,
 0x43,
-0x49,
-0x44,
-0x79,
-0x1,
-0x60,
-0x0,
+0x4b,
+0xa4,
 0x0,
-0x50,
-0x43,
-0x4e,
-0x54,
-0x60,
-0xa,
-0x3,
 0x10,
 0x4a,
 0xa0,
@@ -4248,8 +4292,8 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x75,
 0x60,
 0x10,
-0x4e,
-0x9,
+0x42,
+0xc,
 0x5f,
 0x47,
 0x50,
@@ -4277,12 +4321,31 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x30,
 0x0,
 0x14,
-0x15,
+0x39,
 0x5f,
 0x45,
 0x30,
 0x31,
 0x0,
+0x5b,
+0x23,
+0x5c,
+0x2f,
+0x3,
+0x5f,
+0x53,
+0x42,
+0x5f,
+0x50,
+0x43,
+0x49,
+0x30,
+0x42,
+0x4c,
+0x43,
+0x4b,
+0xff,
+0xff,
 0x5c,
 0x2f,
 0x3,
@@ -4297,7 +4360,24 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x50,
 0x43,
 0x4e,
-0x46,
+0x54,
+0x5b,
+0x27,
+0x5c,
+0x2f,
+0x3,
+0x5f,
+0x53,
+0x42,
+0x5f,
+0x50,
+0x43,
+0x49,
+0x30,
+0x42,
+0x4c,
+0x43,
+0x4b,
 0x14,
 0x10,
 0x5f,
@@ -4407,3 +4487,6 @@ static unsigned char AcpiDsdtAmlCode[] = {
 0x46,
 0x0
 };
+static unsigned short piix_dsdt_applesmc_sta[] = {
+0x384
+};
hw/i386/q35-acpi-dsdt.hex.generated +62 -12

116 lines not on this page · raw message

hw/i386/ssdt-pcihp.hex.generated +10 -10
index b3c2cd5..610a631 100644
@@ -5,19 +5,19 @@ static unsigned char ssdt_pcihp_adr[] = {
 0x44
 };
 static unsigned char ssdt_pcihp_end[] = {
-0x58
+0x5b
 };
 static unsigned char ssdp_pcihp_aml[] = {
 0x53,
 0x53,
 0x44,
 0x54,
-0x58,
+0x5b,
 0x0,
 0x0,
 0x0,
 0x1,
-0x76,
+0xe8,
 0x42,
 0x58,
 0x50,
@@ -45,7 +45,7 @@ static unsigned char ssdp_pcihp_aml[] = {
 0x13,
 0x20,
 0x10,
-0x33,
+0x36,
 0x5c,
 0x2e,
 0x5f,
@@ -58,7 +58,7 @@ static unsigned char ssdp_pcihp_aml[] = {
 0x30,
 0x5b,
 0x82,
-0x26,
+0x29,
 0x53,
 0x41,
 0x41,
@@ -81,17 +81,20 @@ static unsigned char ssdp_pcihp_aml[] = {
 0xaa,
 0x0,
 0x14,
-0xf,
+0x12,
 0x5f,
 0x45,
 0x4a,
 0x30,
 0x1,
-0xa4,
 0x50,
 0x43,
 0x45,
 0x4a,
+0x42,
+0x53,
+0x45,
+0x4c,
 0x5f,
 0x53,
 0x55,
@@ -103,6 +106,3 @@ static unsigned char ssdt_pcihp_start[] = {
 static unsigned char ssdt_pcihp_id[] = {
 0x3d
 };
-static unsigned char ssdt_pcihp_ej0[] = {
-0x4a
-};
hw/i386/ssdt-proc.hex.generated +3 -3
index bb9920d..97e28d4 100644
@@ -11,7 +11,7 @@ static unsigned char ssdp_proc_aml[] = {
 0x0,
 0x0,
 0x1,
-0xb8,
+0x78,
 0x42,
 0x58,
 0x50,
@@ -47,8 +47,8 @@ static unsigned char ssdp_proc_aml[] = {
 0x41,
 0x41,
 0xaa,
-0x10,
-0xb0,
+0x0,
+0x0,
 0x0,
 0x0,
 0x0,
Signature · 1 line
MST
#29 lore raw

[Qemu-devel] [PULL v2 29/35] acpi-test: update expected AML since recent changes

In reply to Michael S. Tsirkin
---
 tests/acpi-test-data/pc/DSDT  | Bin 4407 -> 4582 bytes
 tests/acpi-test-data/pc/SSDT  | Bin 2104 -> 2200 bytes
 tests/acpi-test-data/q35/DSDT | Bin 7344 -> 7438 bytes
 tests/acpi-test-data/q35/SSDT | Bin 2104 -> 475 bytes
 4 files changed, 0 insertions(+), 0 deletions(-)
tests/acpi-test-data/pc/DSDT binary +0 -0
index b12e5eb85bb22f27fe10ce0fcf1d9a71f38360eb..fbf1c3e6e8f791f8e7bae95ad43ea11d0be64c72 100644
GIT binary patch
tests/acpi-test-data/pc/SSDT binary +0 -0
index 5ab1b96af004737738f3386e73e4dc1d425ab77e..a51c68e21b7f1556009331966c56eb7a563dd51e 100644
GIT binary patch
tests/acpi-test-data/q35/DSDT binary +0 -0
index 59243b952d78c465298e0a2ec05a52f480dd92fb..5086b839a6e11ee819af91e72f71efb3e8d97fe2 100644
GIT binary patch
tests/acpi-test-data/q35/SSDT binary +0 -0
index 186e748e6c16ffef80634be5eae9c3fa17210811..9c6cad8b0b7e009d88232166112ed8877cfe11c0 100644
GIT binary patch
Signature · 1 line
MST
#30 lore raw

[Qemu-devel] [PULL v2 30/35] hw/pci: fix error flow in pci multifunction init

In reply to Michael S. Tsirkin

From: Marcel Apfelbaum <[email protected]>

Scenario:
- There is a non multifunction pci device A on 00:0X.0.
- Hot-plug another multifunction pci device B at 00:0X.1.
- The operation will fail of course.
- Try to hot-plug the B device 2-3 more times, qemu will crash.

Reason: The error flow leaves the B's address space into global address spaces list, but the device object is freed. Fixed that.

---
 hw/pci/pci.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
hw/pci/pci.c +10 -10
index 2aca8a4..1221f32 100644
@@ -793,6 +793,15 @@ static void pci_config_free(PCIDevice *pci_dev)
     g_free(pci_dev->used);
 }
 
+static void do_pci_unregister_device(PCIDevice *pci_dev)
+{
+    pci_dev->bus->devices[pci_dev->devfn] = NULL;
+    pci_config_free(pci_dev);
+
+    address_space_destroy(&pci_dev->bus_master_as);
+    memory_region_destroy(&pci_dev->bus_master_enable_region);
+}
+
 /* -1 for devfn means auto assign */
 static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
                                          const char *name, int devfn)
@@ -858,7 +867,7 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
         pci_init_mask_bridge(pci_dev);
     }
     if (pci_init_multifunction(bus, pci_dev)) {
-        pci_config_free(pci_dev);
+        do_pci_unregister_device(pci_dev);
         return NULL;
     }
 
@@ -873,15 +882,6 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
     return pci_dev;
 }
 
-static void do_pci_unregister_device(PCIDevice *pci_dev)
-{
-    pci_dev->bus->devices[pci_dev->devfn] = NULL;
-    pci_config_free(pci_dev);
-
-    address_space_destroy(&pci_dev->bus_master_as);
-    memory_region_destroy(&pci_dev->bus_master_enable_region);
-}
-
 static void pci_unregister_io_regions(PCIDevice *pci_dev)
 {
     PCIIORegion *r;
Signature · 1 line
MST
#31 lore raw

[Qemu-devel] [PULL v2 31/35] pc: Save size of RAM below 4GB

In reply to Michael S. Tsirkin

From: Eduardo Habkost <[email protected]>

The ram_below_4g value will be useful in other places, such as the ACPI table code, and other code that currently requires passing below_4g_mem_size around in function arguments.

---
 include/hw/i386/pc.h | 2 +-
 hw/i386/pc.c         | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
include/hw/i386/pc.h +1 -1
index 92eabeb..3e1e81b 100644
@@ -35,7 +35,7 @@ typedef struct PcPciInfo {
 struct PcGuestInfo {
     bool has_pci_info;
     bool isapc_ram_fw;
-    hwaddr ram_size;
+    hwaddr ram_size, ram_size_below_4g;
     unsigned apic_id_limit;
     bool apic_xrupt_override;
     uint64_t numa_nodes;
hw/i386/pc.c +1 -0
index 6f0be37..348b15f 100644
@@ -1072,6 +1072,7 @@ PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
     PcGuestInfo *guest_info = &guest_info_state->info;
     int i, j;
 
+    guest_info->ram_size_below_4g = below_4g_mem_size;
     guest_info->ram_size = below_4g_mem_size + above_4g_mem_size;
     guest_info->apic_id_limit = pc_apic_id_limit(max_cpus);
     guest_info->apic_xrupt_override = kvm_allows_irq0_override();
Signature · 1 line
MST
#32 lore raw

[Qemu-devel] [PULL v2 32/35] acpi: Fix PCI hole handling on build_srat()

In reply to Michael S. Tsirkin

From: Eduardo Habkost <[email protected]>

The original SeaBIOS code used the RamSize variable, that was used by SeaBIOS for the size of RAM below 4GB, not for all RAM. When copied to QEMU, the code was changed to use the full RAM size, and this broke the build_srat() code that handles the PCI hole.

Change build_srat() to use ram_size_below_4g instead of ram_size, to restore the original behavior from SeaBIOS.

---
 hw/i386/acpi-build.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
hw/i386/acpi-build.c +5 -5
index 9cd3d0e..50e83f3 100644
@@ -1080,16 +1080,16 @@ build_srat(GArray *table_data, GArray *linker,
         next_base = mem_base + mem_len;
 
         /* Cut out the ACPI_PCI hole */
-        if (mem_base <= guest_info->ram_size &&
-            next_base > guest_info->ram_size) {
-            mem_len -= next_base - guest_info->ram_size;
+        if (mem_base <= guest_info->ram_size_below_4g &&
+            next_base > guest_info->ram_size_below_4g) {
+            mem_len -= next_base - guest_info->ram_size_below_4g;
             if (mem_len > 0) {
                 numamem = acpi_data_push(table_data, sizeof *numamem);
                 acpi_build_srat_memory(numamem, mem_base, mem_len, i-1, 1);
             }
             mem_base = 1ULL << 32;
-            mem_len = next_base - guest_info->ram_size;
-            next_base += (1ULL << 32) - guest_info->ram_size;
+            mem_len = next_base - guest_info->ram_size_below_4g;
+            next_base += (1ULL << 32) - guest_info->ram_size_below_4g;
         }
         numamem = acpi_data_push(table_data, sizeof *numamem);
         acpi_build_srat_memory(numamem, mem_base, mem_len, i - 1, 1);
Signature · 1 line
MST
#33 lore raw

[Qemu-devel] [PULL v2 33/35] q35: gigabyte alignment for ram

In reply to Michael S. Tsirkin

From: Gerd Hoffmann <[email protected]>

Map 2G (q35) of memory below 4G, so the RAM pieces are nicely aligned to gigabyte borders.

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

---
 hw/i386/pc_q35.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
hw/i386/pc_q35.c +5 -2
index 07f38ff..7104645 100644
@@ -51,6 +51,7 @@
 static bool has_pci_info;
 static bool has_acpi_build = true;
 static bool smbios_type1_defaults = true;
+static bool gigabyte_align = true;
 
 /* PC hardware initialisation */
 static void pc_q35_init(QEMUMachineInitArgs *args)
@@ -93,8 +94,9 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
     kvmclock_create();
 
     if (args->ram_size >= 0xb0000000) {
-        above_4g_mem_size = args->ram_size - 0xb0000000;
-        below_4g_mem_size = 0xb0000000;
+        ram_addr_t lowmem = gigabyte_align ? 0x80000000 : 0xb0000000;
+        above_4g_mem_size = args->ram_size - lowmem;
+        below_4g_mem_size = lowmem;
     } else {
         above_4g_mem_size = 0;
         below_4g_mem_size = args->ram_size;
@@ -228,6 +230,7 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
 static void pc_compat_1_7(QEMUMachineInitArgs *args)
 {
     smbios_type1_defaults = false;
+    gigabyte_align = false;
 }
 
 static void pc_compat_1_6(QEMUMachineInitArgs *args)
Signature · 1 line
MST
#34 lore raw

[Qemu-devel] [PULL v2 34/35] q35: document gigabyte_align

In reply to Michael S. Tsirkin

Document the logic behind the below/above 4G split.

---
 hw/i386/pc_q35.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
hw/i386/pc_q35.c +13 -0
index 7104645..a7f6260 100644
@@ -51,6 +51,10 @@
 static bool has_pci_info;
 static bool has_acpi_build = true;
 static bool smbios_type1_defaults = true;
+/* Make sure that guest addresses aligned at 1Gbyte boundaries get mapped to
+ * host addresses aligned at 1Gbyte boundaries.  This way we can use 1GByte
+ * pages in the host.
+ */
 static bool gigabyte_align = true;
 
 /* PC hardware initialisation */
@@ -93,6 +97,15 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
 
     kvmclock_create();
 
+    /* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory
+     * and 256 Mbytes for PCI Express Enhanced Configuration Access Mapping
+     * also known as MMCFG).
+     * If it doesn't, we need to split it in chunks below and above 4G.
+     * In any case, try to make sure that guest addresses aligned at
+     * 1G boundaries get mapped to host addresses aligned at 1G boundaries.
+     * For old machine types, use whatever split we used historically to avoid
+     * breaking migration.
+     */
     if (args->ram_size >= 0xb0000000) {
         ram_addr_t lowmem = gigabyte_align ? 0x80000000 : 0xb0000000;
         above_4g_mem_size = args->ram_size - lowmem;
Signature · 1 line
MST
#35 lore raw

[Qemu-devel] [PULL v2 35/35] MAINTAINERS: add self as virtio co-maintainer

In reply to Michael S. Tsirkin

This will help make sure I get Cc'd on patches.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index fb53242..adc5973 100644
@@ -610,6 +610,7 @@ F: hw/*/*vhost*
 
 virtio
 M: Anthony Liguori <[email protected]>
+M: Michael S. Tsirkin <[email protected]>
 S: Supported
 F: hw/*/virtio*
 
Signature · 1 line
MST
#36 lore raw
In reply to Michael S. Tsirkin

Hi Peter,
could you merge the below please?
Thanks in advance!

Quoted 163 lines · Michael S. Tsirkin

Hi Anthony,
I forgot to Cc you on the previous version of this pull request. So here's v2 - it also includes some more changes that got merged since then.
I also used this opportunity for smash in a compat bugfix. Please ignore the previous pull request.

The following changes since commit 0169c511554cb0014a00290b0d3d26c31a49818f:

Merge remote-tracking branch 'qemu-kvm/uq/master' into staging (2014-01-24 15:52:44 -0800)

are available in the git repository at:

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

for you to fetch changes up to a75143eda2ddf581b51e96c000974bcdfe2cbd10:

MAINTAINERS: add self as virtio co-maintainer (2014-01-26 13:11:45 +0200)

----------------------------------------------------------------
acpi,pci,pc,virtio fixes and enhancements

This includes new unit-tests for acpi by Marcel, hotplug for pci bridges by myself (piix only so far) and cpu hotplug for q35.
And a bunch of fixes all over the place as usual.

I included the patch to fix memory alignment for q35 as well - even though it limits 32 bit guests to 3G (they previously could address more memory with PAE).
To remove the limit, this will have to be fixed in seabios.

I also added self as virtio co-maintainer so I don't need to troll the list for patches to review.

----------------------------------------------------------------
Alexey Kardashevskiy (1):
tests: fix acpi to work on bigendian host

Eduardo Habkost (2):
pc: Save size of RAM below 4GB
acpi: Fix PCI hole handling on build_srat()

Gabriel L. Somlo (2):
Add DSDT node for AppleSMC
ACPI: Fix AppleSMC _STA size

Gerd Hoffmann (1):
q35: gigabyte alignment for ram

Igor Mammedov (9):
pc: make: fix dependencies: rebuild when included file is changed
acpi: factor out common cpu hotplug code for PIIX4/Q35
acpi: ich9: add CPU hotplug handling to Q35 machine
pc: set PRST base in DSDT depending on chipset
pc: PIIX DSDT: exclude CPU/PCI hotplug & GPE0 IO range from PCI bus resources
pc: Q35 DSDT: exclude CPU hotplug IO range from PCI bus resources
pc: ACPI: expose PRST IO range via _CRS
pc: ACPI: unify source of CPU hotplug IO base/len
pc: ACPI: update acpi-dsdt.hex.generated q35-acpi-dsdt.hex.generated

Laszlo Ersek (1):
Python-lang gdb script to extract x86_64 guest vmcore from qemu coredump

Marcel Apfelbaum (11):
acpi unit-test: add test files
configure: added acpi unit-test files
acpi unit-test: compare DSDT and SSDT tables against expected values
configure: add CONFIG_IASL to config-host.h
acpi unit-test: extract iasl executable from configuration acpi unit-test: added script to rebuild the expected aml files acpi unit-test: hook to rebuild expected aml files
acpi unit-test: renamed ssdt_tables to tables
acpi unit-test: resolved iasl crash
acpi unit-test: do not fail on asl mismatch
hw/pci: fix error flow in pci multifunction init

Michael S. Tsirkin (7):
pci: add pci_for_each_bus_depth_first
pcihp: generalization of piix4 acpi
piix4: add acpi pci hotplug support
acpi-build: enable hotplug for PCI bridges
acpi-test: update expected AML since recent changes
q35: document gigabyte_align
MAINTAINERS: add self as virtio co-maintainer

Stefan Weil (1):
virtio: Fix return value for dummy function vhost_net_virtqueue_pending

 configure                                    |   4 +
 include/hw/acpi/cpu_hotplug.h                |  27 ++
 include/hw/acpi/cpu_hotplug_defs.h           |  24 ++
 include/hw/acpi/ich9.h                       |   4 +
 include/hw/acpi/pcihp.h                      |  72 ++++++
 include/hw/i386/pc.h                         |   7 +-
 include/hw/isa/isa.h                         |   7 +
 include/hw/pci/pci.h                         |  14 ++
 hw/acpi/cpu_hotplug.c                        |  64 +++++
 hw/acpi/ich9.c                               |  14 ++
 hw/acpi/pcihp.c                              | 316 +++++++++++++++++++++++
 hw/acpi/piix4.c                              | 155 ++++++------
 hw/i386/acpi-build.c                         | 364 +++++++++++++++++++++------
 hw/i386/pc.c                                 |   1 +
 hw/i386/pc_q35.c                             |  20 +-
 hw/misc/applesmc.c                           |   1 -
 hw/net/vhost_net.c                           |   2 +-
 hw/pci/pci.c                                 |  48 +++-
 tests/acpi-test.c                            | 305 +++++++++++++++++++---
 MAINTAINERS                                  |   1 +
 docs/specs/acpi_cpu_hotplug.txt              |   4 +-
 hw/acpi/Makefile.objs                        |   3 +-
 hw/i386/Makefile.objs                        |   2 +-
 hw/i386/acpi-dsdt-cpu-hotplug.dsl            |  14 +-
 hw/i386/acpi-dsdt-isa.dsl                    |  11 +
 hw/i386/acpi-dsdt-pci-crs.dsl                |  15 +-
 hw/i386/acpi-dsdt.dsl                        |  76 ++++--
 hw/i386/acpi-dsdt.hex.generated              | 217 +++++++++++-----
 hw/i386/q35-acpi-dsdt.dsl                    |  19 ++
 hw/i386/q35-acpi-dsdt.hex.generated          |  74 +++++-
 hw/i386/ssdt-pcihp.dsl                       |  11 +-
 hw/i386/ssdt-pcihp.hex.generated             |  20 +-
 hw/i386/ssdt-proc.hex.generated              |   6 +-
 scripts/create_config                        |   4 +
 scripts/dump-guest-memory.py                 | 339 +++++++++++++++++++++++++
 tests/acpi-test-data/pc/APIC                 | Bin 0 -> 120 bytes
 tests/acpi-test-data/pc/DSDT                 | Bin 0 -> 4582 bytes
 tests/acpi-test-data/pc/FACP                 | Bin 0 -> 116 bytes
 tests/acpi-test-data/pc/FACS                 | Bin 0 -> 64 bytes
 tests/acpi-test-data/pc/HPET                 | Bin 0 -> 56 bytes
 tests/acpi-test-data/pc/SSDT                 | Bin 0 -> 2200 bytes
 tests/acpi-test-data/q35/APIC                | Bin 0 -> 120 bytes
 tests/acpi-test-data/q35/DSDT                | Bin 0 -> 7438 bytes
 tests/acpi-test-data/q35/FACP                | Bin 0 -> 116 bytes
 tests/acpi-test-data/q35/FACS                | Bin 0 -> 64 bytes
 tests/acpi-test-data/q35/HPET                | Bin 0 -> 56 bytes
 tests/acpi-test-data/q35/MCFG                | Bin 0 -> 60 bytes
 tests/acpi-test-data/q35/SSDT                | Bin 0 -> 475 bytes
 tests/acpi-test-data/rebuild-expected-aml.sh |  36 +++
 49 files changed, 1963 insertions(+), 338 deletions(-)
 create mode 100644 include/hw/acpi/cpu_hotplug.h
 create mode 100644 include/hw/acpi/cpu_hotplug_defs.h
 create mode 100644 include/hw/acpi/pcihp.h
 create mode 100644 hw/acpi/cpu_hotplug.c
 create mode 100644 hw/acpi/pcihp.c
 create mode 100644 scripts/dump-guest-memory.py
 create mode 100644 tests/acpi-test-data/pc/APIC
 create mode 100644 tests/acpi-test-data/pc/DSDT
 create mode 100644 tests/acpi-test-data/pc/FACP
 create mode 100644 tests/acpi-test-data/pc/FACS
 create mode 100644 tests/acpi-test-data/pc/HPET
 create mode 100644 tests/acpi-test-data/pc/SSDT
 create mode 100644 tests/acpi-test-data/q35/APIC
 create mode 100644 tests/acpi-test-data/q35/DSDT
 create mode 100644 tests/acpi-test-data/q35/FACP
 create mode 100644 tests/acpi-test-data/q35/FACS
 create mode 100644 tests/acpi-test-data/q35/HPET
 create mode 100644 tests/acpi-test-data/q35/MCFG
 create mode 100644 tests/acpi-test-data/q35/SSDT
 create mode 100755 tests/acpi-test-data/rebuild-expected-aml.sh
#37 lore raw
Quoted 3 lines · Michael S. Tsirkin

Hi Peter,
could you merge the below please?
Thanks in advance!

I'm still waiting for input from Anthony on how best to manage pull request merging (workflow, command lines, etc). I've been playing around with the 'patches' tool this afternoon and it hasn't been being terribly cooperative...

thanks
-- PMM

#38 lore raw
Quoted 5 lines · Peter Maydell
Quoted 3 lines · Michael S. Tsirkin

Hi Peter,
could you merge the below please?
Thanks in advance!

Quoted 7 lines

I'm still waiting for input from Anthony on how best to manage pull request merging (workflow, command lines, etc). I've been playing around with the 'patches' tool this afternoon and it hasn't been being terribly cooperative...

thanks
-- PMM

I think patches is for managing patches - isn't it? For merging git pull should be enough should it not?

Signature · 1 line
MST
#39 lore raw
In reply to Michael S. Tsirkin
Quoted 4 lines · Michael S. Tsirkin

Hi Peter,
could you merge the below please?
Thanks in advance!

Quoted 23 lines
Quoted 22 lines · Michael S. Tsirkin

Hi Anthony,
I forgot to Cc you on the previous version of this pull request. So here's v2 - it also includes some more changes that got merged since then.
I also used this opportunity for smash in a compat bugfix. Please ignore the previous pull request.

The following changes since commit 0169c511554cb0014a00290b0d3d26c31a49818f:

Merge remote-tracking branch 'qemu-kvm/uq/master' into staging (2014-01-24 15:52:44 -0800)

are available in the git repository at:

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

for you to fetch changes up to a75143eda2ddf581b51e96c000974bcdfe2cbd10:

MAINTAINERS: add self as virtio co-maintainer (2014-01-26 13:11:45 +0200)

----------------------------------------------------------------
acpi,pci,pc,virtio fixes and enhancements

Applied, thanks.

-- PMM