qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gal Hammer <ghammer@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Igor Mammedov <imammedo@redhat.com>
Subject: [Qemu-devel] [PATCH FYI 13/13] hw/i386: generate AML for the VMGENID device (WIP)
Date: Sun, 13 Sep 2015 14:43:47 +0200	[thread overview]
Message-ID: <1442148227-17343-14-git-send-email-lersek@redhat.com> (raw)
In-Reply-To: <1442148227-17343-1-git-send-email-lersek@redhat.com>

This patch implements the "ACPI device, control methods" section of
"docs/vmgenid.txt", with dynamic AML generation.

A small portion of this patch was inspired by Gal Hammer's

  [PATCH V15 4/5] i386: add a Virtual Machine Generation ID device
  http://thread.gmane.org/gmane.comp.emulators.qemu/332451/focus=332454

TODO: the ACPICA instance that is built into the Linux kernel warns about
the fact that both _L04 and _E04 are provided by GPE 04, when the code in
this patch is active. Therefore this patch should also conditionalize _L04
(ATM in "hw/i386/acpi-dsdt.dsl" and "hw/i386/q35-acpi-dsdt.dsl"), so that
they are only generated when VMGENID is *not* active.

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Gal Hammer <ghammer@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 hw/i386/acpi-build.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index a742f25..67be94a 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1126,6 +1126,85 @@ build_ssdt(GArray *table_data, GArray *linker,
         aml_append(ssdt, scope);
     }
 
+    if (true /* lersek: misc->vmgenid_iobase */) {
+        unsigned adbp_offset;
+        size_t genid_incr;
+
+        scope = aml_scope("\\_SB");
+        dev = aml_device("VMGI");
+
+        aml_append(dev, aml_name_decl("_CID", aml_string("VM_Gen_Counter")));
+        aml_append(dev, aml_name_decl("_DDN", aml_string("VM_Gen_Counter")));
+        aml_append(dev, aml_name_decl("_HID", aml_string("QEMU0002")));
+
+        aml_append(dev, aml_name_decl("_STA", aml_int(0xF)));
+
+        method = aml_method_serialized("ADDR", 0, true);
+
+        aml_append(method,
+                   aml_data_table_region("TBLR",
+                                         aml_string("UEFI"),
+                                         aml_string("%s", ACPI_BUILD_APPNAME6),
+                                         aml_string("QEMUPARM")));
+        field = aml_field("TBLR", AML_ANY_ACC, AML_PRESERVE);
+        adbp_offset = offsetof (AcpiQemuParamTable, vmgenid_addr_base_ptr);
+        /* Offset() before ADBP, expressed in bits */
+        aml_append(field, aml_reserved_field(adbp_offset * 8));
+        aml_append(field, aml_named_field("ADBP", 64));
+        aml_append(method, field);
+
+        aml_append(method,
+                   aml_operation_region("VMGR", AML_SYSTEM_IO,
+                                        0x512 /* lersek: misc->vmgenid_iobase */,
+                                        9));
+        field = aml_field("VMGR", AML_DWORD_ACC, AML_PRESERVE);
+        aml_append(field, aml_named_field("PTLO", 32));
+        aml_append(field, aml_named_field("PTHI", 32));
+        aml_append(field, aml_access_field(AML_BYTE_ACC));
+        aml_append(field, aml_named_field("DONE", 8));
+        aml_append(method, field);
+
+        aml_append(method, aml_name_decl("RESU", aml_buffer(8, NULL)));
+        aml_append(method,
+                  aml_create_qword_field(aml_name("RESU"), aml_int(0),
+                                         "ADFU"));
+        aml_append(method,
+                  aml_create_dword_field(aml_name("RESU"), aml_int(0),
+                                         "ADLO"));
+        aml_append(method,
+                  aml_create_dword_field(aml_name("RESU"), aml_int(4),
+                                         "ADHI"));
+
+        /*
+         * Offset increment from the end of the parameter table (ie. where ADBP
+         * points to) until the generation ID field, skipping over the "OVMF
+         * SDT Header probe suppressor" and "VMGenID alignment padding" fields
+         * in the blob.
+         */
+        genid_incr = VM_GENERATION_ID_OFFSET - sizeof(AcpiQemuParamTable);
+        aml_append(method, aml_store(aml_add(aml_name("ADBP"),
+                                             aml_int(genid_incr)),
+                                     aml_name("ADFU")));
+        aml_append(method, aml_store(aml_name("ADLO"), aml_name("PTLO")));
+        aml_append(method, aml_store(aml_name("ADHI"), aml_name("PTHI")));
+        aml_append(method, aml_store(aml_int(0), aml_name("DONE")));
+
+        pkg = aml_package(2);
+        aml_append(pkg, aml_name("ADLO"));
+        aml_append(pkg, aml_name("ADHI"));
+        aml_append(method, aml_return(pkg));
+
+        aml_append(dev, method);
+        aml_append(scope, dev);
+        aml_append(ssdt, scope);
+
+        scope = aml_scope("\\_GPE");
+        method = aml_method("_E04", 0);
+        aml_append(method, aml_notify(aml_name("\\_SB.VMGI"), aml_int(0x80)));
+        aml_append(scope, method);
+        aml_append(ssdt, scope);
+    }
+
     sb_scope = aml_scope("\\_SB");
     {
         /* create PCI0.PRES device and its _CRS to reserve CPU hotplug MMIO */
-- 
1.8.3.1

      parent reply	other threads:[~2015-09-13 12:44 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-28 20:18 [Qemu-devel] [RFC] docs: describe QEMU's VMGenID design Laszlo Ersek
2015-09-01 19:47 ` Eric Blake
2015-09-01 22:05   ` Laszlo Ersek
2015-09-01 22:22     ` Eric Blake
2015-09-07 16:30       ` Paolo Bonzini
2015-09-03 13:49 ` Michael S. Tsirkin
2015-09-03 14:24   ` Laszlo Ersek
2015-09-13 11:56 ` [Qemu-devel] Windows does not support DataTableRegion at all [was: docs: describe QEMU's VMGenID design] Laszlo Ersek
2015-09-13 12:34   ` Michael S. Tsirkin
2015-09-13 12:57     ` Laszlo Ersek
2015-09-14  8:24     ` Igor Mammedov
2015-09-14 10:24       ` Laszlo Ersek
2015-09-14 16:53         ` [Qemu-devel] [edk2] " Bill Paul
2015-09-14 17:14           ` Moore, Robert
2015-09-14 17:23             ` Walz, Michael C
2015-09-14 18:04               ` Moore, Robert
2015-09-14 18:24               ` Laszlo Ersek
2015-09-15 10:49               ` Laszlo Ersek
2015-09-14 18:20           ` Laszlo Ersek
2015-09-14 21:12             ` Bill Paul
2015-09-15 10:49               ` Laszlo Ersek
2015-09-15 13:45                 ` Moore, Robert
2015-09-15 14:29                   ` Laszlo Ersek
2015-09-13 12:43   ` [Qemu-devel] [PATCH FYI 00/13] ACPI stuff for the DataTableRegion()-based VMGenID Laszlo Ersek
2015-09-13 12:43     ` [Qemu-devel] [PATCH FYI 01/13] docs: describe QEMU's VMGenID design Laszlo Ersek
2015-09-13 12:43     ` [Qemu-devel] [PATCH FYI 02/13] hw/acpi: add i386 callbacks for injecting GPE 04 when the VMGENID changes Laszlo Ersek
2015-09-13 12:43     ` [Qemu-devel] [PATCH FYI 03/13] hw/acpi: rename "AcpiBuildTables.table_data" to "main_blob" Laszlo Ersek
2015-09-13 12:43     ` [Qemu-devel] [PATCH FYI 04/13] hw/acpi: allow RSDT entries to be relocated to various fw_cfg blobs Laszlo Ersek
2015-09-13 12:43     ` [Qemu-devel] [PATCH FYI 05/13] hw/acpi: add more flexible acpi_add_table() and build_header() variants Laszlo Ersek
2015-09-13 12:43     ` [Qemu-devel] [PATCH FYI 06/13] hw/acpi: introduce ACPI_BUILD_QEMUPARAM_FILE Laszlo Ersek
2015-09-13 12:43     ` [Qemu-devel] [PATCH FYI 07/13] hw/acpi: introduce the AcpiQemuParamTable structure Laszlo Ersek
2015-09-13 12:43     ` [Qemu-devel] [PATCH FYI 08/13] hw/i386: build UEFI ACPI Data Table for VMGENID in the dedicated blob (WIP) Laszlo Ersek
2015-09-13 12:43     ` [Qemu-devel] [PATCH FYI 09/13] hw/acpi: expose more parameters for aml_method() Laszlo Ersek
2015-09-13 12:43     ` [Qemu-devel] [PATCH FYI 10/13] hw/acpi: add AML generator function for DataTableRegion() Laszlo Ersek
2015-09-13 12:43     ` [Qemu-devel] [PATCH FYI 11/13] hw/acpi: add AML generator function for AccessAs() Laszlo Ersek
2015-09-13 12:43     ` [Qemu-devel] [PATCH FYI 12/13] hw/acpi: add AML generator function for CreateQWordField() Laszlo Ersek
2015-09-13 12:43     ` Laszlo Ersek [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1442148227-17343-14-git-send-email-lersek@redhat.com \
    --to=lersek@redhat.com \
    --cc=ghammer@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).