diff options
author | Carsten Otte <cotte@de.ibm.com> | 2007-10-29 11:08:51 -0400 |
---|---|---|
committer | Avi Kivity <avi@qumranet.com> | 2008-01-30 10:52:57 -0500 |
commit | 5fb76f9be1a050a25e21a44ab2003c9d36a72a77 (patch) | |
tree | fa5a184ade52e55746efb1bab59fa283ee3535ed /drivers/kvm/x86.c | |
parent | 1fe779f8eccd16e527315e1bafd2b3a876ff2489 (diff) |
KVM: Portability: Move memory segmentation to x86.c
This patch moves the definition of segment_descriptor_64 for AMD64 and
EM64T from kvm_main.c to segment_descriptor.h. It also adds a proper
#ifndef...#define...#endif around that header file.
The implementation of segment_base is moved from kvm_main.c to x86.c.
Signed-off-by: Carsten Otte <cotte@de.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
Acked-by: Hollis Blanchard <hollisb@us.ibm.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'drivers/kvm/x86.c')
-rw-r--r-- | drivers/kvm/x86.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c index b84cb6707f78..5a959220410a 100644 --- a/drivers/kvm/x86.c +++ b/drivers/kvm/x86.c | |||
@@ -16,16 +16,49 @@ | |||
16 | 16 | ||
17 | #include "kvm.h" | 17 | #include "kvm.h" |
18 | #include "x86.h" | 18 | #include "x86.h" |
19 | #include "segment_descriptor.h" | ||
19 | #include "irq.h" | 20 | #include "irq.h" |
20 | 21 | ||
21 | #include <linux/kvm.h> | 22 | #include <linux/kvm.h> |
22 | #include <linux/fs.h> | 23 | #include <linux/fs.h> |
23 | #include <linux/vmalloc.h> | 24 | #include <linux/vmalloc.h> |
25 | #include <linux/module.h> | ||
24 | 26 | ||
25 | #include <asm/uaccess.h> | 27 | #include <asm/uaccess.h> |
26 | 28 | ||
27 | #define MAX_IO_MSRS 256 | 29 | #define MAX_IO_MSRS 256 |
28 | 30 | ||
31 | unsigned long segment_base(u16 selector) | ||
32 | { | ||
33 | struct descriptor_table gdt; | ||
34 | struct segment_descriptor *d; | ||
35 | unsigned long table_base; | ||
36 | unsigned long v; | ||
37 | |||
38 | if (selector == 0) | ||
39 | return 0; | ||
40 | |||
41 | asm("sgdt %0" : "=m"(gdt)); | ||
42 | table_base = gdt.base; | ||
43 | |||
44 | if (selector & 4) { /* from ldt */ | ||
45 | u16 ldt_selector; | ||
46 | |||
47 | asm("sldt %0" : "=g"(ldt_selector)); | ||
48 | table_base = segment_base(ldt_selector); | ||
49 | } | ||
50 | d = (struct segment_descriptor *)(table_base + (selector & ~7)); | ||
51 | v = d->base_low | ((unsigned long)d->base_mid << 16) | | ||
52 | ((unsigned long)d->base_high << 24); | ||
53 | #ifdef CONFIG_X86_64 | ||
54 | if (d->system == 0 && (d->type == 2 || d->type == 9 || d->type == 11)) | ||
55 | v |= ((unsigned long) \ | ||
56 | ((struct segment_descriptor_64 *)d)->base_higher) << 32; | ||
57 | #endif | ||
58 | return v; | ||
59 | } | ||
60 | EXPORT_SYMBOL_GPL(segment_base); | ||
61 | |||
29 | /* | 62 | /* |
30 | * List of msr numbers which we expose to userspace through KVM_GET_MSRS | 63 | * List of msr numbers which we expose to userspace through KVM_GET_MSRS |
31 | * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST. | 64 | * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST. |