When KVM is running on VIA CPU with the option "-cpu host", the
feautures of 
PadLock hardware engine on VIA CPU, such as "ace", "ace_en" and so on
can 
be passed into kvm guest through the CPUIDs for Centaur.

Signed-off-by: BrillyWu<[email protected]>
Signed-off-by: KaryJin<[email protected]>
---
 target-i386/cpu.h   |    3 +++
 target-i386/cpuid.c |   48
+++++++++++++++++++++++++++++++++++++++++++++---
 target-i386/kvm.c   |   15 +++++++++++++++
 3 files changed, 63 insertions(+), 3 deletions(-)

--- a/target-i386/cpu.h 2011-04-07 10:51:57.102043000 +0800
+++ b/target-i386/cpu.h 2011-04-11 15:01:49.626557005 +0800
@@ -717,6 +717,9 @@ typedef struct CPUX86State {
     uint32_t cpuid_model[12];
     uint32_t cpuid_ext2_features;
     uint32_t cpuid_ext3_features;
+    /*Store the results of Centaur's CPUID instructions*/
+    uint32_t cpuid_xlevel2;
+    uint32_t cpuid_ext4_features;
     uint32_t cpuid_apic_id;
     int cpuid_vendor_override;
 
--- a/target-i386/cpuid.c       2011-04-07 11:05:48.062042998 +0800
+++ b/target-i386/cpuid.c       2011-04-13 09:17:28.835436999 +0800
@@ -225,6 +225,9 @@ typedef struct x86_def_t {
     uint32_t features, ext_features, ext2_features, ext3_features;
     uint32_t kvm_features, svm_features;
     uint32_t xlevel;
+    /*Store the results of Centaur's CPUID instructions*/
+    uint32_t ext4_features;
+    uint32_t xlevel2;
     char model_id[48];
     int vendor_override;
     uint32_t flags;
@@ -520,6 +523,13 @@ static int cpu_x86_fill_host(x86_def_t *
     cpu_x86_fill_model_id(x86_cpu_def->model_id);
     x86_cpu_def->vendor_override = 0;
 
+    /* Call Centaur's CPUID instruction. */
+    host_cpuid(0xC0000000, 0, &eax, &ebx, &ecx, &edx);
+    if (eax >= 0xC0000001) {
+       x86_cpu_def->xlevel2 = eax; /*support VIA max extended level*/
+       host_cpuid(0xC0000001, 0, &eax, &ebx, &ecx, &edx);
+       x86_cpu_def->ext4_features = edx;
+    }
 
     /*
      * Every SVM feature requires emulation support in KVM - so we
can't just
@@ -854,6 +864,8 @@ int cpu_x86_register (CPUX86State *env,
     env->cpuid_xlevel = def->xlevel;
     env->cpuid_kvm_features = def->kvm_features;
     env->cpuid_svm_features = def->svm_features;
+    env->cpuid_ext4_features = def->ext4_features;
+    env->cpuid_xlevel2 = def->xlevel2;
     if (!kvm_enabled()) {
         env->cpuid_features &= TCG_FEATURES;
         env->cpuid_ext_features &= TCG_EXT_FEATURES;
@@ -1033,9 +1045,17 @@ void cpu_x86_cpuid(CPUX86State *env, uin
                    uint32_t *ecx, uint32_t *edx)
 {
     /* test if maximum index reached */
-    if (index & 0x80000000) {
-        if (index > env->cpuid_xlevel)
-            index = env->cpuid_level;
+    if ((index & 0xC0000000) == 0xC0000000) {
+       /* Handle the Centaur's CPUID instruction.*
+       * If cpuid_xlevel2 is "0", then put into the*
+       * default case. */
+       if (env->cpuid_xlevel2 == 0)
+           index = 0xF0000000;
+       else if (index > env->cpuid_xlevel2)
+           index = env->cpuid_xlevel2;
+    } else if (index & 0x80000000) {
+       if (index > env->cpuid_xlevel)
+           index = env->cpuid_xlevel;
     } else {
         if (index > env->cpuid_level)
             index = env->cpuid_level;
@@ -1255,6 +1275,28 @@ void cpu_x86_cpuid(CPUX86State *env, uin
                *edx = 0;
        }
         break;
+    case 0xC0000000:
+       *eax = env->cpuid_xlevel2;
+       *ebx = 0;
+       *ecx = 0;
+       *edx = 0;
+       break;
+    case 0xC0000001:
+       /* Support for VIA CPU's CPUID instruction */
+       *eax = env->cpuid_version;
+       *ebx = 0;
+       *ecx = 0;
+       *edx = env->cpuid_ext4_features;
+       break;
+    case 0xC0000002:
+    case 0xC0000003:
+    case 0xC0000004:
+       /*Reserved for the future, and now filled with zero*/
+       *eax = 0;
+       *ebx = 0;
+       *ecx = 0;
+       *edx = 0;
+       break;
     default:
         /* reserved values: zero */
         *eax = 0;
--- a/target-i386/kvm.c 2011-04-07 10:52:28.392042998 +0800
+++ b/target-i386/kvm.c 2011-04-11 15:27:13.936556977 +0800
@@ -428,6 +428,21 @@ int kvm_arch_init_vcpu(CPUState *env)
         cpu_x86_cpuid(env, i, 0, &c->eax, &c->ebx, &c->ecx, &c->edx);
     }
 
+    /* Call Centaur's CPUID instructions they are supported. */
+    if (env->cpuid_xlevel2 > 0) {
+       env->cpuid_ext4_features &=
+               kvm_arch_get_supported_cpuid(env, 0xC0000001, 0, R_EDX);
+       cpu_x86_cpuid(env, 0xC0000000, 0, &limit, &unused, &unused,
&unused);
+
+       for (i = 0xC0000000; i <= limit; i++) {
+           c = &cpuid_data.entries[cpuid_i++];
+
+           c->function = i;
+           c->flags = 0;
+           cpu_x86_cpuid(env, i, 0, &c->eax, &c->ebx, &c->ecx,
&c->edx);
+       }
+    }
+
     cpuid_data.cpuid.nent = cpuid_i;
 
 #ifdef KVM_CAP_MCE
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to