All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2 V3] Virtual Machine Generation ID
@ 2014-09-15  7:27 Gal Hammer
  2014-09-15  7:27 ` [Qemu-devel] [PATCH 1/2] i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive Gal Hammer
  2014-09-15  7:27 ` [Qemu-devel] [PATCH 2/2] i386: Add a Virtual Machine Generation ID device Gal Hammer
  0 siblings, 2 replies; 12+ messages in thread
From: Gal Hammer @ 2014-09-15  7:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gal Hammer, pbonzini

Hi,

A two parts patch to add a QEmu support for Microsoft's Virtual Machine
Generation ID device.

The first one add a new ACPI directive which allow to use a 16-bytes
buffer in an ACPI table. This buffer is for storing the VM's UUID.

The second is the ACPI tables changes and the actual device.

Your comment are welcomed.

Thanks,

    Gal.

V3: - Fix a typo in error message string.
    - Move device's description from DSDT back to SSDT table.

V2: - Remove "-uuid" command line parameter.
    - Move device's description from SSDT to DDST table.
    - Add new "vmgenid" sysbus device.

Gal Hammer (2):
  i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive.
  i386: Add a Virtual Machine Generation ID device.

 default-configs/i386-softmmu.mak   |  1 +
 default-configs/x86_64-softmmu.mak |  1 +
 hw/i386/acpi-build.c               | 18 ++++++++
 hw/i386/ssdt-misc.dsl              | 36 ++++++++++++++++
 hw/misc/Makefile.objs              |  1 +
 hw/misc/vmgenid.c                  | 85 ++++++++++++++++++++++++++++++++++++++
 include/hw/i386/pc.h               |  3 ++
 scripts/acpi_extract.py            | 23 +++++++----
 8 files changed, 159 insertions(+), 9 deletions(-)
 create mode 100644 hw/misc/vmgenid.c

-- 
1.9.3

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

* [Qemu-devel] [PATCH 1/2] i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive.
  2014-09-15  7:27 [Qemu-devel] [PATCH 0/2 V3] Virtual Machine Generation ID Gal Hammer
@ 2014-09-15  7:27 ` Gal Hammer
  2014-09-15  7:27 ` [Qemu-devel] [PATCH 2/2] i386: Add a Virtual Machine Generation ID device Gal Hammer
  1 sibling, 0 replies; 12+ messages in thread
From: Gal Hammer @ 2014-09-15  7:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gal Hammer, pbonzini

Add a 16-bytes buffer to allow storing a 128-bit UUID value in an
ACPI table.

Signed-off-by: Gal Hammer <ghammer@redhat.com>
---
 scripts/acpi_extract.py | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/scripts/acpi_extract.py b/scripts/acpi_extract.py
index 22ea468..10c1ffb 100755
--- a/scripts/acpi_extract.py
+++ b/scripts/acpi_extract.py
@@ -139,13 +139,16 @@ def aml_name_string(offset):
         offset += 1
     return offset;
 
-# Given data offset, find 8 byte buffer offset
-def aml_data_buffer8(offset):
-    #0x08 NameOp NameString DataRef
-    expect = [0x11, 0x0B, 0x0A, 0x08]
+# Given data offset, find variable length byte buffer offset
+def aml_data_buffer(offset, length):
+    #0x11 PkgLength BufferSize ByteList
+    if (length > 63):
+        die( "Name offset 0x%x: expected a one byte PkgLength (length<=63)" %
+             (offset));
+    expect = [0x11, length+3, 0x0A, length]
     if (aml[offset:offset+4] != expect):
         die( "Name offset 0x%x: expected %s actual %s" %
-             (offset, aml[offset:offset+4], expect))
+             (offset, expect, aml[offset:offset+4]))
     return offset + len(expect)
 
 # Given data offset, find dword const offset
@@ -172,9 +175,9 @@ def aml_data_byte_const(offset):
              (offset, aml[offset]));
     return offset + 1;
 
-# Find name'd buffer8
-def aml_name_buffer8(offset):
-    return aml_data_buffer8(aml_name_string(offset) + 4)
+# Find name'd buffer
+def aml_name_buffer(offset, length):
+    return aml_data_buffer(aml_name_string(offset) + 4, length)
 
 # Given name offset, find dword const offset
 def aml_name_dword_const(offset):
@@ -308,7 +311,9 @@ for i in range(len(asl)):
         output[array] = aml
         continue
     if (directive == "ACPI_EXTRACT_NAME_BUFFER8"):
-        offset = aml_name_buffer8(offset)
+        offset = aml_name_buffer(offset, 8)
+    elif (directive == "ACPI_EXTRACT_NAME_BUFFER16"):
+        offset = aml_name_buffer(offset, 16)
     elif (directive == "ACPI_EXTRACT_NAME_DWORD_CONST"):
         offset = aml_name_dword_const(offset)
     elif (directive == "ACPI_EXTRACT_NAME_WORD_CONST"):
-- 
1.9.3

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

* [Qemu-devel] [PATCH 2/2] i386: Add a Virtual Machine Generation ID device.
  2014-09-15  7:27 [Qemu-devel] [PATCH 0/2 V3] Virtual Machine Generation ID Gal Hammer
  2014-09-15  7:27 ` [Qemu-devel] [PATCH 1/2] i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive Gal Hammer
@ 2014-09-15  7:27 ` Gal Hammer
  2014-09-15  8:46   ` Igor Mammedov
  1 sibling, 1 reply; 12+ messages in thread
From: Gal Hammer @ 2014-09-15  7:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gal Hammer, pbonzini

Based on Microsoft's sepecifications (paper can be dowloaded from
http://go.microsoft.com/fwlink/?LinkId=260709), add a device
description to the DSDT ACPI table.

The GUID is set using a new "vmgenid" device.

Signed-off-by: Gal Hammer <ghammer@redhat.com>
---
 default-configs/i386-softmmu.mak   |  1 +
 default-configs/x86_64-softmmu.mak |  1 +
 hw/i386/acpi-build.c               | 18 ++++++++
 hw/i386/ssdt-misc.dsl              | 36 ++++++++++++++++
 hw/misc/Makefile.objs              |  1 +
 hw/misc/vmgenid.c                  | 85 ++++++++++++++++++++++++++++++++++++++
 include/hw/i386/pc.h               |  3 ++
 7 files changed, 145 insertions(+)
 create mode 100644 hw/misc/vmgenid.c

diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index 8e08841..bd33c75 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -45,3 +45,4 @@ CONFIG_IOAPIC=y
 CONFIG_ICC_BUS=y
 CONFIG_PVPANIC=y
 CONFIG_MEM_HOTPLUG=y
+CONFIG_VMGENID=y
diff --git a/default-configs/x86_64-softmmu.mak b/default-configs/x86_64-softmmu.mak
index 66557ac..006fc7c 100644
--- a/default-configs/x86_64-softmmu.mak
+++ b/default-configs/x86_64-softmmu.mak
@@ -45,3 +45,4 @@ CONFIG_IOAPIC=y
 CONFIG_ICC_BUS=y
 CONFIG_PVPANIC=y
 CONFIG_MEM_HOTPLUG=y
+CONFIG_VMGENID=y
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index a313321..613ecfc 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1063,6 +1063,8 @@ build_ssdt(GArray *table_data, GArray *linker,
     unsigned acpi_cpus = guest_info->apic_id_limit;
     int ssdt_start = table_data->len;
     uint8_t *ssdt_ptr;
+    uint8_t *vm_gid_ptr;
+    uint32_t vm_gid_physical_address;
     int i;
 
     /* The current AML generator can cover the APIC ID range [0..255],
@@ -1088,6 +1090,22 @@ build_ssdt(GArray *table_data, GArray *linker,
     ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
                       ssdt_isa_pest[0], 16, misc->pvpanic_port);
 
+    vm_gid_ptr = acpi_data_get_ptr(ssdt_ptr, sizeof(ssdp_misc_aml),
+                                   ssdt_acpi_vm_gid[0], 16);
+    if (vm_generation_id(vm_gid_ptr)) {
+        vm_gid_physical_address = ssdt_start + ssdt_acpi_vm_gid[0];
+        bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
+                                       ACPI_BUILD_TABLE_FILE,
+                                       table_data,
+                                       ssdt_ptr + ssdt_acpi_vm_gid_addr[0],
+                                       sizeof(uint32_t));
+    } else {
+        vm_gid_physical_address = 0;
+    }
+
+    ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
+                      ssdt_acpi_vm_gid_addr[0], 32, vm_gid_physical_address);
+
     ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
                       ssdt_mctrl_nr_slots[0], 32, nr_mem);
 
diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
index 0fd4480..630cd35 100644
--- a/hw/i386/ssdt-misc.dsl
+++ b/hw/i386/ssdt-misc.dsl
@@ -118,6 +118,42 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
         }
     }
 
+/****************************************************************
+ * Virtual Machine Generation ID Device
+ ****************************************************************/
+    Scope(\_SB) {
+
+        Device(VMGI) {
+            Name(_HID, "QEMU0002")
+            Name(_CID, "VM_Gen_Counter")
+            Name(_DDN, "VM_Gen_Counter")
+
+            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_acpi_vm_gid_addr
+            Name(VGIA, 0x12345678)
+
+            ACPI_EXTRACT_NAME_BUFFER16 ssdt_acpi_vm_gid
+            Name(VGID, Buffer(16) {
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 })
+
+            Method(_STA, 0, NotSerialized) {
+                Store(VGIA, Local0)
+                If (LEqual(Local0, Zero)) {
+                    Return (0x00)
+                } Else {
+                    Return (0x0F)
+                }
+            }
+
+            Method(ADDR, 0, Serialized) {
+                Store(Package(2) { }, Local0)
+                Store(VGIA, Index(Local0, 0))
+                Store(0x0000, Index(Local0, 1))
+                return (Local0)
+            }
+        }
+    }
+
     External(MEMORY_SLOT_NOTIFY_METHOD, MethodObj)
     Scope(\_SB.PCI0) {
         Device(MEMORY_HOTPLUG_DEVICE) {
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
index 979e532..c18b800 100644
--- a/hw/misc/Makefile.objs
+++ b/hw/misc/Makefile.objs
@@ -41,3 +41,4 @@ obj-$(CONFIG_SLAVIO) += slavio_misc.o
 obj-$(CONFIG_ZYNQ) += zynq_slcr.o
 
 obj-$(CONFIG_PVPANIC) += pvpanic.o
+obj-$(CONFIG_VMGENID) += vmgenid.o
diff --git a/hw/misc/vmgenid.c b/hw/misc/vmgenid.c
new file mode 100644
index 0000000..76956d1
--- /dev/null
+++ b/hw/misc/vmgenid.c
@@ -0,0 +1,85 @@
+/*
+ *  Virtual Machine Generation ID Device
+ *
+ *  Copyright (C) 2014 Red Hat Inc.
+ *
+ *  Authors: Gal Hammer <ghammer@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "hw/i386/pc.h"
+#include "hw/sysbus.h"
+
+#define VMGENID_DEVICE "vmgenid"
+
+#define PROPERTY_UUID "uuid"
+
+#define VMGENID(obj) OBJECT_CHECK(VmGenIdState, (obj), VMGENID_DEVICE)
+
+typedef struct VmGenIdState {
+    SysBusDevice parent_obj;
+    char *guid_arg;
+} VmGenIdState;
+
+bool vm_generation_id(uint8_t id[16])
+{
+    Object *o = object_resolve_path_type("", VMGENID_DEVICE, NULL);
+    char *guid;
+
+    if (!o) {
+        return false;
+    }
+    guid = object_property_get_str(o, PROPERTY_UUID, NULL);
+    /* actual uuid validation was checked during realize. */
+    (void)qemu_uuid_parse(guid, id);
+    return true;
+}
+
+static void vmgenid_realize(DeviceState *dev, Error **errp)
+{
+    VmGenIdState *s = VMGENID(dev);
+    uint8_t id[16];
+
+    if (!s->guid_arg) {
+        error_setg(errp, "missing uuid.");
+        return;
+    }
+
+    if (qemu_uuid_parse(s->guid_arg, id) < 0) {
+        error_setg(errp, "Fail to parse UUID string.");
+        return;
+    }
+}
+
+static Property vmgenid_device_properties[] = {
+    DEFINE_PROP_STRING(PROPERTY_UUID, VmGenIdState, guid_arg),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void vmgenid_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->realize = vmgenid_realize;
+    dc->props = vmgenid_device_properties;
+    dc->cannot_instantiate_with_device_add_yet = false;
+    set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+}
+
+static const TypeInfo vmgenid_device_info = {
+    .name          = VMGENID_DEVICE,
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(VmGenIdState),
+    .class_init    = vmgenid_class_init,
+};
+
+static void vmgenid_register_types(void)
+{
+    type_register_static(&vmgenid_device_info);
+}
+
+type_init(vmgenid_register_types)
+
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 77316d5..40ecccb 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -290,6 +290,9 @@ void pc_system_firmware_init(MemoryRegion *rom_memory,
 /* pvpanic.c */
 uint16_t pvpanic_port(void);
 
+/* vmgenid.c */
+bool vm_generation_id(uint8_t id[16]);
+
 /* e820 types */
 #define E820_RAM        1
 #define E820_RESERVED   2
-- 
1.9.3

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

* Re: [Qemu-devel] [PATCH 2/2] i386: Add a Virtual Machine Generation ID device.
  2014-09-15  7:27 ` [Qemu-devel] [PATCH 2/2] i386: Add a Virtual Machine Generation ID device Gal Hammer
@ 2014-09-15  8:46   ` Igor Mammedov
  2014-09-15  9:15     ` Gal Hammer
  0 siblings, 1 reply; 12+ messages in thread
From: Igor Mammedov @ 2014-09-15  8:46 UTC (permalink / raw)
  To: Gal Hammer; +Cc: pbonzini, qemu-devel

On Mon, 15 Sep 2014 10:27:08 +0300
Gal Hammer <ghammer@redhat.com> wrote:

> Based on Microsoft's sepecifications (paper can be dowloaded from
> http://go.microsoft.com/fwlink/?LinkId=260709), add a device
> description to the DSDT ACPI table.
> 
> The GUID is set using a new "vmgenid" device.
> 
> Signed-off-by: Gal Hammer <ghammer@redhat.com>
> ---
>  default-configs/i386-softmmu.mak   |  1 +
>  default-configs/x86_64-softmmu.mak |  1 +
>  hw/i386/acpi-build.c               | 18 ++++++++
>  hw/i386/ssdt-misc.dsl              | 36 ++++++++++++++++
>  hw/misc/Makefile.objs              |  1 +
>  hw/misc/vmgenid.c                  | 85 ++++++++++++++++++++++++++++++++++++++
>  include/hw/i386/pc.h               |  3 ++
>  7 files changed, 145 insertions(+)
>  create mode 100644 hw/misc/vmgenid.c
> 
> diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
> index 8e08841..bd33c75 100644
> --- a/default-configs/i386-softmmu.mak
> +++ b/default-configs/i386-softmmu.mak
> @@ -45,3 +45,4 @@ CONFIG_IOAPIC=y
>  CONFIG_ICC_BUS=y
>  CONFIG_PVPANIC=y
>  CONFIG_MEM_HOTPLUG=y
> +CONFIG_VMGENID=y
> diff --git a/default-configs/x86_64-softmmu.mak b/default-configs/x86_64-softmmu.mak
> index 66557ac..006fc7c 100644
> --- a/default-configs/x86_64-softmmu.mak
> +++ b/default-configs/x86_64-softmmu.mak
> @@ -45,3 +45,4 @@ CONFIG_IOAPIC=y
>  CONFIG_ICC_BUS=y
>  CONFIG_PVPANIC=y
>  CONFIG_MEM_HOTPLUG=y
> +CONFIG_VMGENID=y
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index a313321..613ecfc 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -1063,6 +1063,8 @@ build_ssdt(GArray *table_data, GArray *linker,
>      unsigned acpi_cpus = guest_info->apic_id_limit;
>      int ssdt_start = table_data->len;
>      uint8_t *ssdt_ptr;
> +    uint8_t *vm_gid_ptr;
> +    uint32_t vm_gid_physical_address;
>      int i;
>  
>      /* The current AML generator can cover the APIC ID range [0..255],
> @@ -1088,6 +1090,22 @@ build_ssdt(GArray *table_data, GArray *linker,
>      ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
>                        ssdt_isa_pest[0], 16, misc->pvpanic_port);
>  
> +    vm_gid_ptr = acpi_data_get_ptr(ssdt_ptr, sizeof(ssdp_misc_aml),
> +                                   ssdt_acpi_vm_gid[0], 16);
> +    if (vm_generation_id(vm_gid_ptr)) {
> +        vm_gid_physical_address = ssdt_start + ssdt_acpi_vm_gid[0];
> +        bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
> +                                       ACPI_BUILD_TABLE_FILE,
> +                                       table_data,
> +                                       ssdt_ptr + ssdt_acpi_vm_gid_addr[0],
> +                                       sizeof(uint32_t));
> +    } else {
> +        vm_gid_physical_address = 0;
> +    }
> +
> +    ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
> +                      ssdt_acpi_vm_gid_addr[0], 32, vm_gid_physical_address);
> +
>      ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
>                        ssdt_mctrl_nr_slots[0], 32, nr_mem);
>  
> diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
> index 0fd4480..630cd35 100644
> --- a/hw/i386/ssdt-misc.dsl
> +++ b/hw/i386/ssdt-misc.dsl
> @@ -118,6 +118,42 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
>          }
>      }
>  
> +/****************************************************************
> + * Virtual Machine Generation ID Device
> + ****************************************************************/
> +    Scope(\_SB) {
> +
> +        Device(VMGI) {
> +            Name(_HID, "QEMU0002")
> +            Name(_CID, "VM_Gen_Counter")
> +            Name(_DDN, "VM_Gen_Counter")
> +
> +            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_acpi_vm_gid_addr
> +            Name(VGIA, 0x12345678)
> +
> +            ACPI_EXTRACT_NAME_BUFFER16 ssdt_acpi_vm_gid
> +            Name(VGID, Buffer(16) {
> +                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> +                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 })
> +
> +            Method(_STA, 0, NotSerialized) {
> +                Store(VGIA, Local0)
> +                If (LEqual(Local0, Zero)) {
> +                    Return (0x00)
> +                } Else {
> +                    Return (0x0F)
> +                }
> +            }
> +
> +            Method(ADDR, 0, Serialized) {
> +                Store(Package(2) { }, Local0)
> +                Store(VGIA, Index(Local0, 0))
> +                Store(0x0000, Index(Local0, 1))
> +                return (Local0)
> +            }
> +        }
> +    }
> 
It's not exactly what Paolo've meant under dynamic inclusion wrt migration issues.
Sine ssdt-misc is always included in SSDT, so ACPI table size will change regardless
whether VMGENID_DEVICE is present or not.

To make it dynamice, create a separate template file like hw/i386/ssdt-tpm.dsl and
include its dump like it's done in build_tpm_ssdt() only when VMGENID_DEVICE is present.


>      External(MEMORY_SLOT_NOTIFY_METHOD, MethodObj)
>      Scope(\_SB.PCI0) {
>          Device(MEMORY_HOTPLUG_DEVICE) {
> diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
> index 979e532..c18b800 100644
> --- a/hw/misc/Makefile.objs
> +++ b/hw/misc/Makefile.objs
> @@ -41,3 +41,4 @@ obj-$(CONFIG_SLAVIO) += slavio_misc.o
>  obj-$(CONFIG_ZYNQ) += zynq_slcr.o
>  
>  obj-$(CONFIG_PVPANIC) += pvpanic.o
> +obj-$(CONFIG_VMGENID) += vmgenid.o
> diff --git a/hw/misc/vmgenid.c b/hw/misc/vmgenid.c
> new file mode 100644
> index 0000000..76956d1
> --- /dev/null
> +++ b/hw/misc/vmgenid.c
> @@ -0,0 +1,85 @@
> +/*
> + *  Virtual Machine Generation ID Device
> + *
> + *  Copyright (C) 2014 Red Hat Inc.
> + *
> + *  Authors: Gal Hammer <ghammer@redhat.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + *
> + */
> +
> +#include "hw/i386/pc.h"
> +#include "hw/sysbus.h"
> +
> +#define VMGENID_DEVICE "vmgenid"
> +
> +#define PROPERTY_UUID "uuid"
> +
> +#define VMGENID(obj) OBJECT_CHECK(VmGenIdState, (obj), VMGENID_DEVICE)
> +
> +typedef struct VmGenIdState {
> +    SysBusDevice parent_obj;
> +    char *guid_arg;
> +} VmGenIdState;
> +
> +bool vm_generation_id(uint8_t id[16])
> +{
> +    Object *o = object_resolve_path_type("", VMGENID_DEVICE, NULL);
> +    char *guid;
> +
> +    if (!o) {
> +        return false;
> +    }
> +    guid = object_property_get_str(o, PROPERTY_UUID, NULL);
> +    /* actual uuid validation was checked during realize. */
> +    (void)qemu_uuid_parse(guid, id);
> +    return true;
> +}
> +
> +static void vmgenid_realize(DeviceState *dev, Error **errp)
> +{
> +    VmGenIdState *s = VMGENID(dev);
> +    uint8_t id[16];
> +
> +    if (!s->guid_arg) {
> +        error_setg(errp, "missing uuid.");
> +        return;
> +    }
> +
> +    if (qemu_uuid_parse(s->guid_arg, id) < 0) {
> +        error_setg(errp, "Fail to parse UUID string.");
> +        return;
> +    }
> +}
> +
> +static Property vmgenid_device_properties[] = {
> +    DEFINE_PROP_STRING(PROPERTY_UUID, VmGenIdState, guid_arg),
> +    DEFINE_PROP_END_OF_LIST(),
> +};
> +
> +static void vmgenid_class_init(ObjectClass *klass, void *data)
> +{
> +    DeviceClass *dc = DEVICE_CLASS(klass);
> +
> +    dc->realize = vmgenid_realize;
> +    dc->props = vmgenid_device_properties;
> +    dc->cannot_instantiate_with_device_add_yet = false;
> +    set_bit(DEVICE_CATEGORY_MISC, dc->categories);
> +}
> +
> +static const TypeInfo vmgenid_device_info = {
> +    .name          = VMGENID_DEVICE,
> +    .parent        = TYPE_SYS_BUS_DEVICE,
> +    .instance_size = sizeof(VmGenIdState),
> +    .class_init    = vmgenid_class_init,
> +};
> +
> +static void vmgenid_register_types(void)
> +{
> +    type_register_static(&vmgenid_device_info);
> +}
> +
> +type_init(vmgenid_register_types)
> +
> diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
> index 77316d5..40ecccb 100644
> --- a/include/hw/i386/pc.h
> +++ b/include/hw/i386/pc.h
> @@ -290,6 +290,9 @@ void pc_system_firmware_init(MemoryRegion *rom_memory,
>  /* pvpanic.c */
>  uint16_t pvpanic_port(void);
>  
> +/* vmgenid.c */
> +bool vm_generation_id(uint8_t id[16]);
> +
>  /* e820 types */
>  #define E820_RAM        1
>  #define E820_RESERVED   2

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

* Re: [Qemu-devel] [PATCH 2/2] i386: Add a Virtual Machine Generation ID device.
  2014-09-15  8:46   ` Igor Mammedov
@ 2014-09-15  9:15     ` Gal Hammer
  0 siblings, 0 replies; 12+ messages in thread
From: Gal Hammer @ 2014-09-15  9:15 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: pbonzini, qemu-devel

Got it. I'll start to work on V4 then...

    Gal.

----- Original Message -----
From: "Igor Mammedov" <imammedo@redhat.com>
To: "Gal Hammer" <ghammer@redhat.com>
Cc: pbonzini@redhat.com, qemu-devel@nongnu.org
Sent: Monday, September 15, 2014 11:46:41 AM
Subject: Re: [Qemu-devel] [PATCH 2/2] i386: Add a Virtual Machine Generation ID device.

On Mon, 15 Sep 2014 10:27:08 +0300
Gal Hammer <ghammer@redhat.com> wrote:

> Based on Microsoft's sepecifications (paper can be dowloaded from
> http://go.microsoft.com/fwlink/?LinkId=260709), add a device
> description to the DSDT ACPI table.
> 
> The GUID is set using a new "vmgenid" device.
> 
> Signed-off-by: Gal Hammer <ghammer@redhat.com>
> ---
>  default-configs/i386-softmmu.mak   |  1 +
>  default-configs/x86_64-softmmu.mak |  1 +
>  hw/i386/acpi-build.c               | 18 ++++++++
>  hw/i386/ssdt-misc.dsl              | 36 ++++++++++++++++
>  hw/misc/Makefile.objs              |  1 +
>  hw/misc/vmgenid.c                  | 85 ++++++++++++++++++++++++++++++++++++++
>  include/hw/i386/pc.h               |  3 ++
>  7 files changed, 145 insertions(+)
>  create mode 100644 hw/misc/vmgenid.c
> 
> diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
> index 8e08841..bd33c75 100644
> --- a/default-configs/i386-softmmu.mak
> +++ b/default-configs/i386-softmmu.mak
> @@ -45,3 +45,4 @@ CONFIG_IOAPIC=y
>  CONFIG_ICC_BUS=y
>  CONFIG_PVPANIC=y
>  CONFIG_MEM_HOTPLUG=y
> +CONFIG_VMGENID=y
> diff --git a/default-configs/x86_64-softmmu.mak b/default-configs/x86_64-softmmu.mak
> index 66557ac..006fc7c 100644
> --- a/default-configs/x86_64-softmmu.mak
> +++ b/default-configs/x86_64-softmmu.mak
> @@ -45,3 +45,4 @@ CONFIG_IOAPIC=y
>  CONFIG_ICC_BUS=y
>  CONFIG_PVPANIC=y
>  CONFIG_MEM_HOTPLUG=y
> +CONFIG_VMGENID=y
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index a313321..613ecfc 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -1063,6 +1063,8 @@ build_ssdt(GArray *table_data, GArray *linker,
>      unsigned acpi_cpus = guest_info->apic_id_limit;
>      int ssdt_start = table_data->len;
>      uint8_t *ssdt_ptr;
> +    uint8_t *vm_gid_ptr;
> +    uint32_t vm_gid_physical_address;
>      int i;
>  
>      /* The current AML generator can cover the APIC ID range [0..255],
> @@ -1088,6 +1090,22 @@ build_ssdt(GArray *table_data, GArray *linker,
>      ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
>                        ssdt_isa_pest[0], 16, misc->pvpanic_port);
>  
> +    vm_gid_ptr = acpi_data_get_ptr(ssdt_ptr, sizeof(ssdp_misc_aml),
> +                                   ssdt_acpi_vm_gid[0], 16);
> +    if (vm_generation_id(vm_gid_ptr)) {
> +        vm_gid_physical_address = ssdt_start + ssdt_acpi_vm_gid[0];
> +        bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
> +                                       ACPI_BUILD_TABLE_FILE,
> +                                       table_data,
> +                                       ssdt_ptr + ssdt_acpi_vm_gid_addr[0],
> +                                       sizeof(uint32_t));
> +    } else {
> +        vm_gid_physical_address = 0;
> +    }
> +
> +    ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
> +                      ssdt_acpi_vm_gid_addr[0], 32, vm_gid_physical_address);
> +
>      ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
>                        ssdt_mctrl_nr_slots[0], 32, nr_mem);
>  
> diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
> index 0fd4480..630cd35 100644
> --- a/hw/i386/ssdt-misc.dsl
> +++ b/hw/i386/ssdt-misc.dsl
> @@ -118,6 +118,42 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
>          }
>      }
>  
> +/****************************************************************
> + * Virtual Machine Generation ID Device
> + ****************************************************************/
> +    Scope(\_SB) {
> +
> +        Device(VMGI) {
> +            Name(_HID, "QEMU0002")
> +            Name(_CID, "VM_Gen_Counter")
> +            Name(_DDN, "VM_Gen_Counter")
> +
> +            ACPI_EXTRACT_NAME_DWORD_CONST ssdt_acpi_vm_gid_addr
> +            Name(VGIA, 0x12345678)
> +
> +            ACPI_EXTRACT_NAME_BUFFER16 ssdt_acpi_vm_gid
> +            Name(VGID, Buffer(16) {
> +                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> +                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 })
> +
> +            Method(_STA, 0, NotSerialized) {
> +                Store(VGIA, Local0)
> +                If (LEqual(Local0, Zero)) {
> +                    Return (0x00)
> +                } Else {
> +                    Return (0x0F)
> +                }
> +            }
> +
> +            Method(ADDR, 0, Serialized) {
> +                Store(Package(2) { }, Local0)
> +                Store(VGIA, Index(Local0, 0))
> +                Store(0x0000, Index(Local0, 1))
> +                return (Local0)
> +            }
> +        }
> +    }
> 
It's not exactly what Paolo've meant under dynamic inclusion wrt migration issues.
Sine ssdt-misc is always included in SSDT, so ACPI table size will change regardless
whether VMGENID_DEVICE is present or not.

To make it dynamice, create a separate template file like hw/i386/ssdt-tpm.dsl and
include its dump like it's done in build_tpm_ssdt() only when VMGENID_DEVICE is present.


>      External(MEMORY_SLOT_NOTIFY_METHOD, MethodObj)
>      Scope(\_SB.PCI0) {
>          Device(MEMORY_HOTPLUG_DEVICE) {
> diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
> index 979e532..c18b800 100644
> --- a/hw/misc/Makefile.objs
> +++ b/hw/misc/Makefile.objs
> @@ -41,3 +41,4 @@ obj-$(CONFIG_SLAVIO) += slavio_misc.o
>  obj-$(CONFIG_ZYNQ) += zynq_slcr.o
>  
>  obj-$(CONFIG_PVPANIC) += pvpanic.o
> +obj-$(CONFIG_VMGENID) += vmgenid.o
> diff --git a/hw/misc/vmgenid.c b/hw/misc/vmgenid.c
> new file mode 100644
> index 0000000..76956d1
> --- /dev/null
> +++ b/hw/misc/vmgenid.c
> @@ -0,0 +1,85 @@
> +/*
> + *  Virtual Machine Generation ID Device
> + *
> + *  Copyright (C) 2014 Red Hat Inc.
> + *
> + *  Authors: Gal Hammer <ghammer@redhat.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + *
> + */
> +
> +#include "hw/i386/pc.h"
> +#include "hw/sysbus.h"
> +
> +#define VMGENID_DEVICE "vmgenid"
> +
> +#define PROPERTY_UUID "uuid"
> +
> +#define VMGENID(obj) OBJECT_CHECK(VmGenIdState, (obj), VMGENID_DEVICE)
> +
> +typedef struct VmGenIdState {
> +    SysBusDevice parent_obj;
> +    char *guid_arg;
> +} VmGenIdState;
> +
> +bool vm_generation_id(uint8_t id[16])
> +{
> +    Object *o = object_resolve_path_type("", VMGENID_DEVICE, NULL);
> +    char *guid;
> +
> +    if (!o) {
> +        return false;
> +    }
> +    guid = object_property_get_str(o, PROPERTY_UUID, NULL);
> +    /* actual uuid validation was checked during realize. */
> +    (void)qemu_uuid_parse(guid, id);
> +    return true;
> +}
> +
> +static void vmgenid_realize(DeviceState *dev, Error **errp)
> +{
> +    VmGenIdState *s = VMGENID(dev);
> +    uint8_t id[16];
> +
> +    if (!s->guid_arg) {
> +        error_setg(errp, "missing uuid.");
> +        return;
> +    }
> +
> +    if (qemu_uuid_parse(s->guid_arg, id) < 0) {
> +        error_setg(errp, "Fail to parse UUID string.");
> +        return;
> +    }
> +}
> +
> +static Property vmgenid_device_properties[] = {
> +    DEFINE_PROP_STRING(PROPERTY_UUID, VmGenIdState, guid_arg),
> +    DEFINE_PROP_END_OF_LIST(),
> +};
> +
> +static void vmgenid_class_init(ObjectClass *klass, void *data)
> +{
> +    DeviceClass *dc = DEVICE_CLASS(klass);
> +
> +    dc->realize = vmgenid_realize;
> +    dc->props = vmgenid_device_properties;
> +    dc->cannot_instantiate_with_device_add_yet = false;
> +    set_bit(DEVICE_CATEGORY_MISC, dc->categories);
> +}
> +
> +static const TypeInfo vmgenid_device_info = {
> +    .name          = VMGENID_DEVICE,
> +    .parent        = TYPE_SYS_BUS_DEVICE,
> +    .instance_size = sizeof(VmGenIdState),
> +    .class_init    = vmgenid_class_init,
> +};
> +
> +static void vmgenid_register_types(void)
> +{
> +    type_register_static(&vmgenid_device_info);
> +}
> +
> +type_init(vmgenid_register_types)
> +
> diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
> index 77316d5..40ecccb 100644
> --- a/include/hw/i386/pc.h
> +++ b/include/hw/i386/pc.h
> @@ -290,6 +290,9 @@ void pc_system_firmware_init(MemoryRegion *rom_memory,
>  /* pvpanic.c */
>  uint16_t pvpanic_port(void);
>  
> +/* vmgenid.c */
> +bool vm_generation_id(uint8_t id[16]);
> +
>  /* e820 types */
>  #define E820_RAM        1
>  #define E820_RESERVED   2

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

* Re: [Qemu-devel] [PATCH 1/2] i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive.
  2014-09-17 11:39 ` [Qemu-devel] [PATCH 1/2] i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive Gal Hammer
@ 2014-10-02 12:20   ` Michael S. Tsirkin
  0 siblings, 0 replies; 12+ messages in thread
From: Michael S. Tsirkin @ 2014-10-02 12:20 UTC (permalink / raw)
  To: Gal Hammer; +Cc: Paolo Bonzini, qemu-devel, Igor Mammedov

On Wed, Sep 17, 2014 at 02:39:51PM +0300, Gal Hammer wrote:
> Add a 16-bytes buffer to allow storing a 128-bit UUID value in an
> ACPI table.
> 
> Signed-off-by: Gal Hammer <ghammer@redhat.com>
> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>


This one looks good. Applied, thanks!

> ---
>  scripts/acpi_extract.py | 23 ++++++++++++++---------
>  1 file changed, 14 insertions(+), 9 deletions(-)
> 
> diff --git a/scripts/acpi_extract.py b/scripts/acpi_extract.py
> index 22ea468..10c1ffb 100755
> --- a/scripts/acpi_extract.py
> +++ b/scripts/acpi_extract.py
> @@ -139,13 +139,16 @@ def aml_name_string(offset):
>          offset += 1
>      return offset;
>  
> -# Given data offset, find 8 byte buffer offset
> -def aml_data_buffer8(offset):
> -    #0x08 NameOp NameString DataRef
> -    expect = [0x11, 0x0B, 0x0A, 0x08]
> +# Given data offset, find variable length byte buffer offset
> +def aml_data_buffer(offset, length):
> +    #0x11 PkgLength BufferSize ByteList
> +    if (length > 63):
> +        die( "Name offset 0x%x: expected a one byte PkgLength (length<=63)" %
> +             (offset));
> +    expect = [0x11, length+3, 0x0A, length]
>      if (aml[offset:offset+4] != expect):
>          die( "Name offset 0x%x: expected %s actual %s" %
> -             (offset, aml[offset:offset+4], expect))
> +             (offset, expect, aml[offset:offset+4]))
>      return offset + len(expect)
>  
>  # Given data offset, find dword const offset
> @@ -172,9 +175,9 @@ def aml_data_byte_const(offset):
>               (offset, aml[offset]));
>      return offset + 1;
>  
> -# Find name'd buffer8
> -def aml_name_buffer8(offset):
> -    return aml_data_buffer8(aml_name_string(offset) + 4)
> +# Find name'd buffer
> +def aml_name_buffer(offset, length):
> +    return aml_data_buffer(aml_name_string(offset) + 4, length)
>  
>  # Given name offset, find dword const offset
>  def aml_name_dword_const(offset):
> @@ -308,7 +311,9 @@ for i in range(len(asl)):
>          output[array] = aml
>          continue
>      if (directive == "ACPI_EXTRACT_NAME_BUFFER8"):
> -        offset = aml_name_buffer8(offset)
> +        offset = aml_name_buffer(offset, 8)
> +    elif (directive == "ACPI_EXTRACT_NAME_BUFFER16"):
> +        offset = aml_name_buffer(offset, 16)
>      elif (directive == "ACPI_EXTRACT_NAME_DWORD_CONST"):
>          offset = aml_name_dword_const(offset)
>      elif (directive == "ACPI_EXTRACT_NAME_WORD_CONST"):
> -- 
> 1.9.3
> 

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

* [Qemu-devel] [PATCH 1/2] i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive.
  2014-09-17 11:39 [Qemu-devel] [PATCH 0/2 V5] Virtual Machine Generation ID Gal Hammer
@ 2014-09-17 11:39 ` Gal Hammer
  2014-10-02 12:20   ` Michael S. Tsirkin
  0 siblings, 1 reply; 12+ messages in thread
From: Gal Hammer @ 2014-09-17 11:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gal Hammer, Paolo Bonzini, Igor Mammedov

Add a 16-bytes buffer to allow storing a 128-bit UUID value in an
ACPI table.

Signed-off-by: Gal Hammer <ghammer@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
---
 scripts/acpi_extract.py | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/scripts/acpi_extract.py b/scripts/acpi_extract.py
index 22ea468..10c1ffb 100755
--- a/scripts/acpi_extract.py
+++ b/scripts/acpi_extract.py
@@ -139,13 +139,16 @@ def aml_name_string(offset):
         offset += 1
     return offset;
 
-# Given data offset, find 8 byte buffer offset
-def aml_data_buffer8(offset):
-    #0x08 NameOp NameString DataRef
-    expect = [0x11, 0x0B, 0x0A, 0x08]
+# Given data offset, find variable length byte buffer offset
+def aml_data_buffer(offset, length):
+    #0x11 PkgLength BufferSize ByteList
+    if (length > 63):
+        die( "Name offset 0x%x: expected a one byte PkgLength (length<=63)" %
+             (offset));
+    expect = [0x11, length+3, 0x0A, length]
     if (aml[offset:offset+4] != expect):
         die( "Name offset 0x%x: expected %s actual %s" %
-             (offset, aml[offset:offset+4], expect))
+             (offset, expect, aml[offset:offset+4]))
     return offset + len(expect)
 
 # Given data offset, find dword const offset
@@ -172,9 +175,9 @@ def aml_data_byte_const(offset):
              (offset, aml[offset]));
     return offset + 1;
 
-# Find name'd buffer8
-def aml_name_buffer8(offset):
-    return aml_data_buffer8(aml_name_string(offset) + 4)
+# Find name'd buffer
+def aml_name_buffer(offset, length):
+    return aml_data_buffer(aml_name_string(offset) + 4, length)
 
 # Given name offset, find dword const offset
 def aml_name_dword_const(offset):
@@ -308,7 +311,9 @@ for i in range(len(asl)):
         output[array] = aml
         continue
     if (directive == "ACPI_EXTRACT_NAME_BUFFER8"):
-        offset = aml_name_buffer8(offset)
+        offset = aml_name_buffer(offset, 8)
+    elif (directive == "ACPI_EXTRACT_NAME_BUFFER16"):
+        offset = aml_name_buffer(offset, 16)
     elif (directive == "ACPI_EXTRACT_NAME_DWORD_CONST"):
         offset = aml_name_dword_const(offset)
     elif (directive == "ACPI_EXTRACT_NAME_WORD_CONST"):
-- 
1.9.3

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

* [Qemu-devel] [PATCH 1/2] i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive.
  2014-09-16 13:04 [Qemu-devel] [PATCH 0/2 V4] Virtual Machine Generation ID Gal Hammer
@ 2014-09-16 13:04 ` Gal Hammer
  0 siblings, 0 replies; 12+ messages in thread
From: Gal Hammer @ 2014-09-16 13:04 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gal Hammer, pbonzini

Add a 16-bytes buffer to allow storing a 128-bit UUID value in an
ACPI table.

Signed-off-by: Gal Hammer <ghammer@redhat.com>
---
 scripts/acpi_extract.py | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/scripts/acpi_extract.py b/scripts/acpi_extract.py
index 22ea468..10c1ffb 100755
--- a/scripts/acpi_extract.py
+++ b/scripts/acpi_extract.py
@@ -139,13 +139,16 @@ def aml_name_string(offset):
         offset += 1
     return offset;
 
-# Given data offset, find 8 byte buffer offset
-def aml_data_buffer8(offset):
-    #0x08 NameOp NameString DataRef
-    expect = [0x11, 0x0B, 0x0A, 0x08]
+# Given data offset, find variable length byte buffer offset
+def aml_data_buffer(offset, length):
+    #0x11 PkgLength BufferSize ByteList
+    if (length > 63):
+        die( "Name offset 0x%x: expected a one byte PkgLength (length<=63)" %
+             (offset));
+    expect = [0x11, length+3, 0x0A, length]
     if (aml[offset:offset+4] != expect):
         die( "Name offset 0x%x: expected %s actual %s" %
-             (offset, aml[offset:offset+4], expect))
+             (offset, expect, aml[offset:offset+4]))
     return offset + len(expect)
 
 # Given data offset, find dword const offset
@@ -172,9 +175,9 @@ def aml_data_byte_const(offset):
              (offset, aml[offset]));
     return offset + 1;
 
-# Find name'd buffer8
-def aml_name_buffer8(offset):
-    return aml_data_buffer8(aml_name_string(offset) + 4)
+# Find name'd buffer
+def aml_name_buffer(offset, length):
+    return aml_data_buffer(aml_name_string(offset) + 4, length)
 
 # Given name offset, find dword const offset
 def aml_name_dword_const(offset):
@@ -308,7 +311,9 @@ for i in range(len(asl)):
         output[array] = aml
         continue
     if (directive == "ACPI_EXTRACT_NAME_BUFFER8"):
-        offset = aml_name_buffer8(offset)
+        offset = aml_name_buffer(offset, 8)
+    elif (directive == "ACPI_EXTRACT_NAME_BUFFER16"):
+        offset = aml_name_buffer(offset, 16)
     elif (directive == "ACPI_EXTRACT_NAME_DWORD_CONST"):
         offset = aml_name_dword_const(offset)
     elif (directive == "ACPI_EXTRACT_NAME_WORD_CONST"):
-- 
1.9.3

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

* Re: [Qemu-devel] [PATCH 1/2] i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive.
  2014-09-14  6:25 ` [Qemu-devel] [PATCH 1/2] i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive Gal Hammer
@ 2014-09-14  8:48   ` Paolo Bonzini
  0 siblings, 0 replies; 12+ messages in thread
From: Paolo Bonzini @ 2014-09-14  8:48 UTC (permalink / raw)
  To: Gal Hammer, qemu-devel; +Cc: armbru

Il 14/09/2014 08:25, Gal Hammer ha scritto:
> Add a 16-bytes buffer to allow storing a 128-bit UUID value in an
> ACPI table.
> 
> Signed-off-by: Gal Hammer <ghammer@redhat.com>
> ---
>  scripts/acpi_extract.py | 23 ++++++++++++++---------
>  1 file changed, 14 insertions(+), 9 deletions(-)
> 
> diff --git a/scripts/acpi_extract.py b/scripts/acpi_extract.py
> index 22ea468..88314fc 100755
> --- a/scripts/acpi_extract.py
> +++ b/scripts/acpi_extract.py
> @@ -139,13 +139,16 @@ def aml_name_string(offset):
>          offset += 1
>      return offset;
>  
> -# Given data offset, find 8 byte buffer offset
> -def aml_data_buffer8(offset):
> -    #0x08 NameOp NameString DataRef
> -    expect = [0x11, 0x0B, 0x0A, 0x08]
> +# Given data offset, find variable length byte buffer offset
> +def aml_data_buffer(offset, length):
> +    #0x11 PkgLength BufferSize ByteList
> +    if (length > 63):
> +        die( "Name offset 0x%x: expected an one byte PkgLength (length<=63)" %

s/an/a/

> +             (offset));
> +    expect = [0x11, length+3, 0x0A, length]
>      if (aml[offset:offset+4] != expect):
>          die( "Name offset 0x%x: expected %s actual %s" %
> -             (offset, aml[offset:offset+4], expect))
> +             (offset, expect, aml[offset:offset+4]))
>      return offset + len(expect)
>  
>  # Given data offset, find dword const offset
> @@ -172,9 +175,9 @@ def aml_data_byte_const(offset):
>               (offset, aml[offset]));
>      return offset + 1;
>  
> -# Find name'd buffer8
> -def aml_name_buffer8(offset):
> -    return aml_data_buffer8(aml_name_string(offset) + 4)
> +# Find name'd buffer
> +def aml_name_buffer(offset, length):
> +    return aml_data_buffer(aml_name_string(offset) + 4, length)
>  
>  # Given name offset, find dword const offset
>  def aml_name_dword_const(offset):
> @@ -308,7 +311,9 @@ for i in range(len(asl)):
>          output[array] = aml
>          continue
>      if (directive == "ACPI_EXTRACT_NAME_BUFFER8"):
> -        offset = aml_name_buffer8(offset)
> +        offset = aml_name_buffer(offset, 8)
> +    elif (directive == "ACPI_EXTRACT_NAME_BUFFER16"):
> +        offset = aml_name_buffer(offset, 16)
>      elif (directive == "ACPI_EXTRACT_NAME_DWORD_CONST"):
>          offset = aml_name_dword_const(offset)
>      elif (directive == "ACPI_EXTRACT_NAME_WORD_CONST"):
> 

Apart from the above grammatical nit,

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Paolo

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

* [Qemu-devel] [PATCH 1/2] i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive.
  2014-09-14  6:25 [Qemu-devel] [PATCH RESEND 0/2 V2] Virtual Machine Generation ID Gal Hammer
@ 2014-09-14  6:25 ` Gal Hammer
  2014-09-14  8:48   ` Paolo Bonzini
  0 siblings, 1 reply; 12+ messages in thread
From: Gal Hammer @ 2014-09-14  6:25 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gal Hammer, pbonzini, armbru

Add a 16-bytes buffer to allow storing a 128-bit UUID value in an
ACPI table.

Signed-off-by: Gal Hammer <ghammer@redhat.com>
---
 scripts/acpi_extract.py | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/scripts/acpi_extract.py b/scripts/acpi_extract.py
index 22ea468..88314fc 100755
--- a/scripts/acpi_extract.py
+++ b/scripts/acpi_extract.py
@@ -139,13 +139,16 @@ def aml_name_string(offset):
         offset += 1
     return offset;
 
-# Given data offset, find 8 byte buffer offset
-def aml_data_buffer8(offset):
-    #0x08 NameOp NameString DataRef
-    expect = [0x11, 0x0B, 0x0A, 0x08]
+# Given data offset, find variable length byte buffer offset
+def aml_data_buffer(offset, length):
+    #0x11 PkgLength BufferSize ByteList
+    if (length > 63):
+        die( "Name offset 0x%x: expected an one byte PkgLength (length<=63)" %
+             (offset));
+    expect = [0x11, length+3, 0x0A, length]
     if (aml[offset:offset+4] != expect):
         die( "Name offset 0x%x: expected %s actual %s" %
-             (offset, aml[offset:offset+4], expect))
+             (offset, expect, aml[offset:offset+4]))
     return offset + len(expect)
 
 # Given data offset, find dword const offset
@@ -172,9 +175,9 @@ def aml_data_byte_const(offset):
              (offset, aml[offset]));
     return offset + 1;
 
-# Find name'd buffer8
-def aml_name_buffer8(offset):
-    return aml_data_buffer8(aml_name_string(offset) + 4)
+# Find name'd buffer
+def aml_name_buffer(offset, length):
+    return aml_data_buffer(aml_name_string(offset) + 4, length)
 
 # Given name offset, find dword const offset
 def aml_name_dword_const(offset):
@@ -308,7 +311,9 @@ for i in range(len(asl)):
         output[array] = aml
         continue
     if (directive == "ACPI_EXTRACT_NAME_BUFFER8"):
-        offset = aml_name_buffer8(offset)
+        offset = aml_name_buffer(offset, 8)
+    elif (directive == "ACPI_EXTRACT_NAME_BUFFER16"):
+        offset = aml_name_buffer(offset, 16)
     elif (directive == "ACPI_EXTRACT_NAME_DWORD_CONST"):
         offset = aml_name_dword_const(offset)
     elif (directive == "ACPI_EXTRACT_NAME_WORD_CONST"):
-- 
1.9.3

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

* [Qemu-devel] [PATCH 1/2] i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive.
  2014-09-02 12:53 [Qemu-devel] [PATCH 0/2 V2] Virtual Machine Generation ID Gal Hammer
@ 2014-09-02 12:53 ` Gal Hammer
  0 siblings, 0 replies; 12+ messages in thread
From: Gal Hammer @ 2014-09-02 12:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gal Hammer, pbonzini, armbru

Add a 16-bytes buffer to allow storing a 128-bit UUID value in an
ACPI table.

Signed-off-by: Gal Hammer <ghammer@redhat.com>
---
 scripts/acpi_extract.py | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/scripts/acpi_extract.py b/scripts/acpi_extract.py
index 22ea468..88314fc 100755
--- a/scripts/acpi_extract.py
+++ b/scripts/acpi_extract.py
@@ -139,13 +139,16 @@ def aml_name_string(offset):
         offset += 1
     return offset;
 
-# Given data offset, find 8 byte buffer offset
-def aml_data_buffer8(offset):
-    #0x08 NameOp NameString DataRef
-    expect = [0x11, 0x0B, 0x0A, 0x08]
+# Given data offset, find variable length byte buffer offset
+def aml_data_buffer(offset, length):
+    #0x11 PkgLength BufferSize ByteList
+    if (length > 63):
+        die( "Name offset 0x%x: expected an one byte PkgLength (length<=63)" %
+             (offset));
+    expect = [0x11, length+3, 0x0A, length]
     if (aml[offset:offset+4] != expect):
         die( "Name offset 0x%x: expected %s actual %s" %
-             (offset, aml[offset:offset+4], expect))
+             (offset, expect, aml[offset:offset+4]))
     return offset + len(expect)
 
 # Given data offset, find dword const offset
@@ -172,9 +175,9 @@ def aml_data_byte_const(offset):
              (offset, aml[offset]));
     return offset + 1;
 
-# Find name'd buffer8
-def aml_name_buffer8(offset):
-    return aml_data_buffer8(aml_name_string(offset) + 4)
+# Find name'd buffer
+def aml_name_buffer(offset, length):
+    return aml_data_buffer(aml_name_string(offset) + 4, length)
 
 # Given name offset, find dword const offset
 def aml_name_dword_const(offset):
@@ -308,7 +311,9 @@ for i in range(len(asl)):
         output[array] = aml
         continue
     if (directive == "ACPI_EXTRACT_NAME_BUFFER8"):
-        offset = aml_name_buffer8(offset)
+        offset = aml_name_buffer(offset, 8)
+    elif (directive == "ACPI_EXTRACT_NAME_BUFFER16"):
+        offset = aml_name_buffer(offset, 16)
     elif (directive == "ACPI_EXTRACT_NAME_DWORD_CONST"):
         offset = aml_name_dword_const(offset)
     elif (directive == "ACPI_EXTRACT_NAME_WORD_CONST"):
-- 
1.9.3

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

* [Qemu-devel] [PATCH 1/2] i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive.
  2014-08-10 11:32 [Qemu-devel] [PATCH 0/2] Virtual Machine Generation ID Gal Hammer
@ 2014-08-10 11:32 ` Gal Hammer
  0 siblings, 0 replies; 12+ messages in thread
From: Gal Hammer @ 2014-08-10 11:32 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gal Hammer

Add a 16-bytes buffer to allow storing a 128-bit UUID value in an
ACPI table.

Signed-off-by: Gal Hammer <ghammer@redhat.com>
---
 scripts/acpi_extract.py | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/scripts/acpi_extract.py b/scripts/acpi_extract.py
index 22ea468..88314fc 100755
--- a/scripts/acpi_extract.py
+++ b/scripts/acpi_extract.py
@@ -139,13 +139,16 @@ def aml_name_string(offset):
         offset += 1
     return offset;
 
-# Given data offset, find 8 byte buffer offset
-def aml_data_buffer8(offset):
-    #0x08 NameOp NameString DataRef
-    expect = [0x11, 0x0B, 0x0A, 0x08]
+# Given data offset, find variable length byte buffer offset
+def aml_data_buffer(offset, length):
+    #0x11 PkgLength BufferSize ByteList
+    if (length > 63):
+        die( "Name offset 0x%x: expected an one byte PkgLength (length<=63)" %
+             (offset));
+    expect = [0x11, length+3, 0x0A, length]
     if (aml[offset:offset+4] != expect):
         die( "Name offset 0x%x: expected %s actual %s" %
-             (offset, aml[offset:offset+4], expect))
+             (offset, expect, aml[offset:offset+4]))
     return offset + len(expect)
 
 # Given data offset, find dword const offset
@@ -172,9 +175,9 @@ def aml_data_byte_const(offset):
              (offset, aml[offset]));
     return offset + 1;
 
-# Find name'd buffer8
-def aml_name_buffer8(offset):
-    return aml_data_buffer8(aml_name_string(offset) + 4)
+# Find name'd buffer
+def aml_name_buffer(offset, length):
+    return aml_data_buffer(aml_name_string(offset) + 4, length)
 
 # Given name offset, find dword const offset
 def aml_name_dword_const(offset):
@@ -308,7 +311,9 @@ for i in range(len(asl)):
         output[array] = aml
         continue
     if (directive == "ACPI_EXTRACT_NAME_BUFFER8"):
-        offset = aml_name_buffer8(offset)
+        offset = aml_name_buffer(offset, 8)
+    elif (directive == "ACPI_EXTRACT_NAME_BUFFER16"):
+        offset = aml_name_buffer(offset, 16)
     elif (directive == "ACPI_EXTRACT_NAME_DWORD_CONST"):
         offset = aml_name_dword_const(offset)
     elif (directive == "ACPI_EXTRACT_NAME_WORD_CONST"):
-- 
1.9.3

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

end of thread, other threads:[~2014-10-02 12:17 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-15  7:27 [Qemu-devel] [PATCH 0/2 V3] Virtual Machine Generation ID Gal Hammer
2014-09-15  7:27 ` [Qemu-devel] [PATCH 1/2] i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive Gal Hammer
2014-09-15  7:27 ` [Qemu-devel] [PATCH 2/2] i386: Add a Virtual Machine Generation ID device Gal Hammer
2014-09-15  8:46   ` Igor Mammedov
2014-09-15  9:15     ` Gal Hammer
  -- strict thread matches above, loose matches on Subject: below --
2014-09-17 11:39 [Qemu-devel] [PATCH 0/2 V5] Virtual Machine Generation ID Gal Hammer
2014-09-17 11:39 ` [Qemu-devel] [PATCH 1/2] i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive Gal Hammer
2014-10-02 12:20   ` Michael S. Tsirkin
2014-09-16 13:04 [Qemu-devel] [PATCH 0/2 V4] Virtual Machine Generation ID Gal Hammer
2014-09-16 13:04 ` [Qemu-devel] [PATCH 1/2] i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive Gal Hammer
2014-09-14  6:25 [Qemu-devel] [PATCH RESEND 0/2 V2] Virtual Machine Generation ID Gal Hammer
2014-09-14  6:25 ` [Qemu-devel] [PATCH 1/2] i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive Gal Hammer
2014-09-14  8:48   ` Paolo Bonzini
2014-09-02 12:53 [Qemu-devel] [PATCH 0/2 V2] Virtual Machine Generation ID Gal Hammer
2014-09-02 12:53 ` [Qemu-devel] [PATCH 1/2] i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive Gal Hammer
2014-08-10 11:32 [Qemu-devel] [PATCH 0/2] Virtual Machine Generation ID Gal Hammer
2014-08-10 11:32 ` [Qemu-devel] [PATCH 1/2] i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive Gal Hammer

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