summaryrefslogtreecommitdiff
path: root/arch/x86/kvm/mtrr.c
diff options
context:
space:
mode:
authorXiao Guangrong <guangrong.xiao@linux.intel.com>2015-06-15 11:55:32 +0300
committerPaolo Bonzini <pbonzini@redhat.com>2015-06-19 18:16:28 +0300
commitf7bfb57b3e89ff89c0da9f93dedab89f68d6ca27 (patch)
treea27ab306e80b1d48705a61335122f4aa30175324 /arch/x86/kvm/mtrr.c
parent19efffa244071ccd0385b240d03adb38feaab04e (diff)
downloadlinux-f7bfb57b3e89ff89c0da9f93dedab89f68d6ca27.tar.xz
KVM: MTRR: introduce fixed_mtrr_addr_* functions
Two functions are introduced: - fixed_mtrr_addr_to_seg() translates the address to the fixed MTRR segment - fixed_mtrr_addr_seg_to_range_index() translates the address to the index of kvm_mtrr.fixed_ranges[] They will be used in the later patch Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com> [Adjust for range_size->range_shift change. - Paolo] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'arch/x86/kvm/mtrr.c')
-rw-r--r--arch/x86/kvm/mtrr.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/arch/x86/kvm/mtrr.c b/arch/x86/kvm/mtrr.c
index faa582488bb8..b5346d20f458 100644
--- a/arch/x86/kvm/mtrr.c
+++ b/arch/x86/kvm/mtrr.c
@@ -241,6 +241,31 @@ static int fixed_msr_to_range_index(u32 msr)
return fixed_mtrr_seg_unit_range_index(seg, unit);
}
+static int fixed_mtrr_addr_to_seg(u64 addr)
+{
+ struct fixed_mtrr_segment *mtrr_seg;
+ int seg, seg_num = ARRAY_SIZE(fixed_seg_table);
+
+ for (seg = 0; seg < seg_num; seg++) {
+ mtrr_seg = &fixed_seg_table[seg];
+ if (mtrr_seg->start >= addr && addr < mtrr_seg->end)
+ return seg;
+ }
+
+ return -1;
+}
+
+static int fixed_mtrr_addr_seg_to_range_index(u64 addr, int seg)
+{
+ struct fixed_mtrr_segment *mtrr_seg;
+ int index;
+
+ mtrr_seg = &fixed_seg_table[seg];
+ index = mtrr_seg->range_start;
+ index += (addr - mtrr_seg->start) >> mtrr_seg->range_shift;
+ return index;
+}
+
static void var_mtrr_range(struct kvm_mtrr_range *range, u64 *start, u64 *end)
{
u64 mask;