From patchwork Sun Sep 14 06:25:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gal Hammer X-Patchwork-Id: 389008 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6EE93140169 for ; Sun, 14 Sep 2014 16:26:52 +1000 (EST) Received: from localhost ([::1]:53059 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XT3Gs-0000yZ-Hl for incoming@patchwork.ozlabs.org; Sun, 14 Sep 2014 02:26:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40301) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XT3GI-0008Ob-II for qemu-devel@nongnu.org; Sun, 14 Sep 2014 02:26:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XT3GC-0005FI-5A for qemu-devel@nongnu.org; Sun, 14 Sep 2014 02:26:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10325) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XT3GB-0005FE-U3 for qemu-devel@nongnu.org; Sun, 14 Sep 2014 02:26:08 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8E6Q700031120 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Sun, 14 Sep 2014 02:26:07 -0400 Received: from wolverine.usersys.redhat.com (dhcp-4-103.tlv.redhat.com [10.35.4.103]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s8E6Q0RH020346; Sun, 14 Sep 2014 02:26:05 -0400 From: Gal Hammer To: qemu-devel@nongnu.org Date: Sun, 14 Sep 2014 09:25:49 +0300 Message-Id: <1410675949-1437-3-git-send-email-ghammer@redhat.com> In-Reply-To: <1410675949-1437-1-git-send-email-ghammer@redhat.com> References: <1410675949-1437-1-git-send-email-ghammer@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Gal Hammer , pbonzini@redhat.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH 2/2] i386: Add a Virtual Machine Generation ID device. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + hw/i386/acpi-build.c | 23 ++++++++++- hw/i386/acpi-dsdt.dsl | 37 +++++++++++++++++ hw/misc/Makefile.objs | 1 + hw/misc/vmgenid.c | 85 ++++++++++++++++++++++++++++++++++++++ include/hw/i386/pc.h | 3 ++ 7 files changed, 149 insertions(+), 2 deletions(-) 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 85e5834..153dadc 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -1390,15 +1390,34 @@ build_mcfg_q35(GArray *table_data, GArray *linker, AcpiMcfgInfo *info) static void build_dsdt(GArray *table_data, GArray *linker, AcpiMiscInfo *misc) { - AcpiTableHeader *dsdt; + int dsdt_start = table_data->len; + uint8_t *dsdt; + uint8_t *vm_gid_ptr; + uint32_t vm_gid_physical_address; assert(misc->dsdt_code && misc->dsdt_size); dsdt = acpi_data_push(table_data, misc->dsdt_size); memcpy(dsdt, misc->dsdt_code, misc->dsdt_size); + vm_gid_ptr = acpi_data_get_ptr(dsdt, misc->dsdt_size, + *dsdt_acpi_vm_gid, 16); + if (vm_generation_id(vm_gid_ptr)) { + vm_gid_physical_address = dsdt_start + *dsdt_acpi_vm_gid; + bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, + ACPI_BUILD_TABLE_FILE, + table_data, + dsdt + *dsdt_acpi_vm_gid_addr, + sizeof(uint32_t)); + } else { + vm_gid_physical_address = 0; + } + + ACPI_BUILD_SET_LE(dsdt, misc->dsdt_size, + *dsdt_acpi_vm_gid_addr, 32, vm_gid_physical_address); + memset(dsdt, 0, sizeof *dsdt); - build_header(linker, table_data, dsdt, "DSDT", + build_header(linker, table_data, (AcpiTableHeader *)dsdt, "DSDT", misc->dsdt_size, 1); } diff --git a/hw/i386/acpi-dsdt.dsl b/hw/i386/acpi-dsdt.dsl index 559f4b6..9015881 100644 --- a/hw/i386/acpi-dsdt.dsl +++ b/hw/i386/acpi-dsdt.dsl @@ -294,6 +294,43 @@ DefinitionBlock ( } } +/**************************************************************** + * 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 dsdt_acpi_vm_gid_addr + Name(VGIA, 0x12345678) + + ACPI_EXTRACT_NAME_BUFFER16 dsdt_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) + } + } + } + + #include "hw/acpi/pc-hotplug.h" #define CPU_STATUS_BASE PIIX4_CPU_HOTPLUG_IO_BASE #include "acpi-dsdt-cpu-hotplug.dsl" 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 + * + * 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 a39cb42..b21c22e 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