aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/kvm/kvm_main.c
diff options
context:
space:
mode:
authorAvi Kivity <avi@qumranet.com>2006-12-29 19:49:48 -0500
committerLinus Torvalds <torvalds@woody.osdl.org>2006-12-30 13:56:44 -0500
commit3bab1f5dda3443043cc8fe68c5ae75530339f28f (patch)
treed1b675e8f5328094c1a3d651da5e7563ad692252 /drivers/kvm/kvm_main.c
parent671d6564796e0c90398aab30f89b5e48fc5a3fbe (diff)
[PATCH] KVM: Move common msr handling to arch independent code
Signed-off-by: Avi Kivity <avi@qumranet.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/kvm/kvm_main.c')
-rw-r--r--drivers/kvm/kvm_main.c71
1 files changed, 69 insertions, 2 deletions
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 06314071c6d2..567121d9142a 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -1103,6 +1103,47 @@ void realmode_set_cr(struct kvm_vcpu *vcpu, int cr, unsigned long val,
1103 } 1103 }
1104} 1104}
1105 1105
1106int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
1107{
1108 u64 data;
1109
1110 switch (msr) {
1111 case 0xc0010010: /* SYSCFG */
1112 case 0xc0010015: /* HWCR */
1113 case MSR_IA32_PLATFORM_ID:
1114 case MSR_IA32_P5_MC_ADDR:
1115 case MSR_IA32_P5_MC_TYPE:
1116 case MSR_IA32_MC0_CTL:
1117 case MSR_IA32_MCG_STATUS:
1118 case MSR_IA32_MCG_CAP:
1119 case MSR_IA32_MC0_MISC:
1120 case MSR_IA32_MC0_MISC+4:
1121 case MSR_IA32_MC0_MISC+8:
1122 case MSR_IA32_MC0_MISC+12:
1123 case MSR_IA32_MC0_MISC+16:
1124 case MSR_IA32_UCODE_REV:
1125 /* MTRR registers */
1126 case 0xfe:
1127 case 0x200 ... 0x2ff:
1128 data = 0;
1129 break;
1130 case MSR_IA32_APICBASE:
1131 data = vcpu->apic_base;
1132 break;
1133#ifdef CONFIG_X86_64
1134 case MSR_EFER:
1135 data = vcpu->shadow_efer;
1136 break;
1137#endif
1138 default:
1139 printk(KERN_ERR "kvm: unhandled rdmsr: 0x%x\n", msr);
1140 return 1;
1141 }
1142 *pdata = data;
1143 return 0;
1144}
1145EXPORT_SYMBOL_GPL(kvm_get_msr_common);
1146
1106/* 1147/*
1107 * Reads an msr value (of 'msr_index') into 'pdata'. 1148 * Reads an msr value (of 'msr_index') into 'pdata'.
1108 * Returns 0 on success, non-0 otherwise. 1149 * Returns 0 on success, non-0 otherwise.
@@ -1115,7 +1156,7 @@ static int get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata)
1115 1156
1116#ifdef CONFIG_X86_64 1157#ifdef CONFIG_X86_64
1117 1158
1118void set_efer(struct kvm_vcpu *vcpu, u64 efer) 1159static void set_efer(struct kvm_vcpu *vcpu, u64 efer)
1119{ 1160{
1120 if (efer & EFER_RESERVED_BITS) { 1161 if (efer & EFER_RESERVED_BITS) {
1121 printk(KERN_DEBUG "set_efer: 0x%llx #GP, reserved bits\n", 1162 printk(KERN_DEBUG "set_efer: 0x%llx #GP, reserved bits\n",
@@ -1138,10 +1179,36 @@ void set_efer(struct kvm_vcpu *vcpu, u64 efer)
1138 1179
1139 vcpu->shadow_efer = efer; 1180 vcpu->shadow_efer = efer;
1140} 1181}
1141EXPORT_SYMBOL_GPL(set_efer);
1142 1182
1143#endif 1183#endif
1144 1184
1185int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)
1186{
1187 switch (msr) {
1188#ifdef CONFIG_X86_64
1189 case MSR_EFER:
1190 set_efer(vcpu, data);
1191 break;
1192#endif
1193 case MSR_IA32_MC0_STATUS:
1194 printk(KERN_WARNING "%s: MSR_IA32_MC0_STATUS 0x%llx, nop\n",
1195 __FUNCTION__, data);
1196 break;
1197 case MSR_IA32_UCODE_REV:
1198 case MSR_IA32_UCODE_WRITE:
1199 case 0x200 ... 0x2ff: /* MTRRs */
1200 break;
1201 case MSR_IA32_APICBASE:
1202 vcpu->apic_base = data;
1203 break;
1204 default:
1205 printk(KERN_ERR "kvm: unhandled wrmsr: 0x%x\n", msr);
1206 return 1;
1207 }
1208 return 0;
1209}
1210EXPORT_SYMBOL_GPL(kvm_set_msr_common);
1211
1145/* 1212/*
1146 * Writes msr value into into the appropriate "register". 1213 * Writes msr value into into the appropriate "register".
1147 * Returns 0 on success, non-0 otherwise. 1214 * Returns 0 on success, non-0 otherwise.