[PATCH] x86: trim ram need to check if mtrr is there v2

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Yinghai Lu
Date: Thursday, January 24, 2008 - 8:47 pm

[PATCH] x86: trim ram need to check if mtrr is there v2


so check it mtrr is there, also check if mem less 4G and is AMD as early

Signed-off-by: Yinghai Lu <yinghai.lu@sun.com>

Index: linux-2.6/arch/x86/kernel/cpu/mtrr/main.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/cpu/mtrr/main.c
+++ linux-2.6/arch/x86/kernel/cpu/mtrr/main.c
@@ -642,13 +642,10 @@ early_param("disable_mtrr_trim", disable
 #define Tom2Enabled (1U << 21)
 #define Tom2ForceMemTypeWB (1U << 22)
 
-static __init int amd_special_default_mtrr(unsigned long end_pfn)
+static __init int amd_special_default_mtrr(void)
 {
 	u32 l, h;
 
-	/* Doesn't apply to memory < 4GB */
-	if (end_pfn <= (0xffffffff >> PAGE_SHIFT))
-		return 0;
 	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
 		return 0;
 	if (boot_cpu_data.x86 < 0xf || boot_cpu_data.x86 > 0x11)
@@ -682,6 +679,13 @@ int __init mtrr_trim_uncached_memory(uns
 	mtrr_type type;
 	u64 trim_start, trim_size;
 
+	if (!cpu_has_mtrr)
+		return 0;
+
+	/* Doesn't apply to memory < 4GB */
+	if (end_pfn <= (0xffffffffUL >> PAGE_SHIFT))
+		return 0;
+
 	/*
 	 * Make sure we only trim uncachable memory on machines that
 	 * support the Intel MTRR architecture:
@@ -691,6 +695,9 @@ int __init mtrr_trim_uncached_memory(uns
 	if (!is_cpu(INTEL) || disable_mtrr_trim || def != MTRR_TYPE_UNCACHABLE)
 		return 0;
 
+	if (amd_special_default_mtrr())
+		return 0;
+
 	/* Find highest cached pfn */
 	for (i = 0; i < num_var_ranges; i++) {
 		mtrr_if->get(i, &base, &size, &type);
@@ -702,9 +709,6 @@ int __init mtrr_trim_uncached_memory(uns
 			highest_addr = base + size;
 	}
 
-	if (amd_special_default_mtrr(end_pfn))
-		return 0;
-
 	if ((highest_addr >> PAGE_SHIFT) < end_pfn) {
 		printk(KERN_WARNING "***************\n");
 		printk(KERN_WARNING "**** WARNING: likely BIOS bug\n");
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
x86.git: mtrr trimming removes all memory under kvm, Jeremy Fitzhardinge, (Thu Jan 24, 6:44 pm)
Re: x86.git: mtrr trimming removes all memory under kvm, H. Peter Anvin, (Thu Jan 24, 6:49 pm)
[PATCH] x86: trim ram need to check if mtrr is there v2, Yinghai Lu, (Thu Jan 24, 8:47 pm)
Re: [PATCH] x86: trim ram need to check if mtrr is there v2, H. Peter Anvin, (Thu Jan 24, 10:44 pm)
Re: [PATCH] x86: trim ram need to check if mtrr is there v2, Jeremy Fitzhardinge, (Fri Jan 25, 12:43 am)
Re: [PATCH] x86: trim ram need to check if mtrr is there v3, Jeremy Fitzhardinge, (Fri Jan 25, 11:55 am)
Re: [PATCH] x86: trim ram need to check if mtrr is there v3, Jeremy Fitzhardinge, (Fri Jan 25, 11:59 am)
Re: [PATCH] x86: trim ram need to check if mtrr is there v3, Jeremy Fitzhardinge, (Fri Jan 25, 12:01 pm)
Re: [PATCH] x86: trim ram need to check if mtrr is there v3, Jeremy Fitzhardinge, (Fri Jan 25, 12:04 pm)
Re: [PATCH] x86: trim ram need to check if mtrr is there v3, Jeremy Fitzhardinge, (Fri Jan 25, 12:27 pm)
Re: [PATCH] x86: trim ram need to check if mtrr is there v3, Jeremy Fitzhardinge, (Fri Jan 25, 12:39 pm)