Re: [PATCH v6 08/16] target-i386: Add cpu object access routines for Hypervisor vendor.

Marcelo Tosatti
2012-10-09T19:11:47Z

On Mon, Sep 24, 2012 at 10:32:10AM -0400, Don Slutz wrote:
> 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.
>
> Set Microsoft's Vendor now that we can. Value defined in:
> http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx
> And matches want is in target-i386/kvm.c
>
> Signed-off-by: Don Slutz <Don@CloudSwitch.com>
> ---
> target-i386/cpu.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
> target-i386/cpu.h | 2 ++
> 2 files changed, 48 insertions(+), 0 deletions(-)
>
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index 920278b..964877f 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -1192,11 +1192,54 @@ static void x86_cpuid_set_hv_level(Object *obj, Visitor *v, void *opaque,
> cpu->env.cpuid_hv_level_set = true;
> }
>
> +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);
> + }
> + env->cpuid_hv_vendor_set = true;
> +}
> +
> #if !defined(CONFIG_USER_ONLY)
> static void x86_set_hyperv(Object *obj, Error **errp)
> {
> object_property_set_int(obj, CPUID_HV_LEVEL_HYPERV,
> "hypervisor-level", errp);
> + object_property_set_str(obj, CPUID_HV_VENDOR_HYPERV,
> + "hypervisor-vendor", errp);
> }
>
> static void x86_get_hv_spinlocks(Object *obj, Visitor *v, void *opaque,
> @@ -2126,6 +2169,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,
> diff --git a/target-i386/cpu.h b/target-i386/cpu.h
> index 11730b2..eb6aa4a 100644
> --- a/target-i386/cpu.h
> +++ b/target-i386/cpu.h
> @@ -488,6 +488,8 @@
>
> #define CPUID_VENDOR_VIA "CentaurHauls"
>
> +#define CPUID_HV_VENDOR_HYPERV "Microsoft Hv"
> +
> #define CPUID_HV_LEVEL_HYPERV 0x40000005

As requested, please separate patchset in groups.