From patchwork Mon Sep 17 14:00:59 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Don Slutz X-Patchwork-Id: 1467481 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 4CF823FCFC for ; Mon, 17 Sep 2012 14:02:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756186Ab2IQOC3 (ORCPT ); Mon, 17 Sep 2012 10:02:29 -0400 Received: from hub021-nj-8.exch021.serverdata.net ([206.225.164.233]:55360 "EHLO hub021-nj-8.exch021.serverdata.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755478Ab2IQOC2 (ORCPT ); Mon, 17 Sep 2012 10:02:28 -0400 Received: from localhost.localdomain (131.239.15.22) by east.exch021.serverdata.net (10.240.4.118) with Microsoft SMTP Server (TLS) id 14.2.309.2; Mon, 17 Sep 2012 07:02:27 -0700 From: Don Slutz To: , , , , , , , , CC: Don Slutz Subject: [PATCH v3 09/17] target-i386: Add cpu object access routines for Hypervisor vendor. Date: Mon, 17 Sep 2012 10:00:59 -0400 Message-ID: <1347890467-9728-10-git-send-email-Don@CloudSwitch.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1346354435-21685-1-git-send-email-Don@CloudSwitch.com> References: <1346354435-21685-1-git-send-email-Don@CloudSwitch.com> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org These are modeled after x86_cpuid_set_vendor and x86_cpuid_get_vendor. Since kvm's vendor is shorter, the test for correct size is removed and zero padding is added. Signed-off-by: Don Slutz --- target-i386/cpu.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 44 insertions(+), 0 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index d3b9bd8..5afb188 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1191,12 +1191,53 @@ static void x86_cpuid_set_hv_level(Object *obj, Visitor *v, void *opaque, cpu->env.cpuid_hv_level = value; } +static char *x86_cpuid_get_hv_vendor(Object *obj, Error **errp) +{ + X86CPU *cpu = X86_CPU(obj); + CPUX86State *env = &cpu->env; + char *value; + int i; + + value = (char *)g_malloc(CPUID_VENDOR_SZ + 1); + for (i = 0; i < 4; i++) { + value[i + 0] = env->cpuid_hv_vendor1 >> (8 * i); + value[i + 4] = env->cpuid_hv_vendor2 >> (8 * i); + value[i + 8] = env->cpuid_hv_vendor3 >> (8 * i); + } + value[CPUID_VENDOR_SZ] = '\0'; + + return value; +} + +static void x86_cpuid_set_hv_vendor(Object *obj, const char *value, + Error **errp) +{ + X86CPU *cpu = X86_CPU(obj); + CPUX86State *env = &cpu->env; + int i; + char adj_value[CPUID_VENDOR_SZ + 1]; + + memset(adj_value, 0, sizeof(adj_value)); + + pstrcpy(adj_value, sizeof(adj_value), value); + + env->cpuid_hv_vendor1 = 0; + env->cpuid_hv_vendor2 = 0; + env->cpuid_hv_vendor3 = 0; + for (i = 0; i < 4; i++) { + env->cpuid_hv_vendor1 |= ((uint8_t)adj_value[i + 0]) << (8 * i); + env->cpuid_hv_vendor2 |= ((uint8_t)adj_value[i + 4]) << (8 * i); + env->cpuid_hv_vendor3 |= ((uint8_t)adj_value[i + 8]) << (8 * i); + } +} + #if !defined(CONFIG_USER_ONLY) static void x86_set_hyperv(Object *obj, Error **errp) { X86CPU *cpu = X86_CPU(obj); cpu->env.cpuid_hv_level = HYPERV_CPUID_MIN; + x86_cpuid_set_hv_vendor(obj, "Microsoft Hv", errp); } static void x86_get_hv_spinlocks(Object *obj, Visitor *v, void *opaque, @@ -2121,6 +2162,9 @@ static void x86_cpu_initfn(Object *obj) object_property_add(obj, "hypervisor-level", "int", x86_cpuid_get_hv_level, x86_cpuid_set_hv_level, NULL, NULL, NULL); + object_property_add_str(obj, "hypervisor-vendor", + x86_cpuid_get_hv_vendor, + x86_cpuid_set_hv_vendor, NULL); #if !defined(CONFIG_USER_ONLY) object_property_add(obj, "hv_spinlocks", "int", x86_get_hv_spinlocks,