aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYinghai Lu <yinghai@kernel.org>2010-02-10 04:20:13 -0500
committerH. Peter Anvin <hpa@zytor.com>2010-02-10 20:47:17 -0500
commite9a0064ad03b899938059bb576615ad9ed0f27f9 (patch)
treeb1c7dd0c7844fb4b8f56bb991684ece56bcd6e1c
parent284f933d45a1e60404328440910bc2651c0fb51d (diff)
x86: Change range end to start+size
So make interface more consistent with early_res. Later we can share some code with early_res. Signed-off-by: Yinghai Lu <yinghai@kernel.org> LKML-Reference: <1265793639-15071-10-git-send-email-yinghai@kernel.org> Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--arch/x86/kernel/cpu/mtrr/cleanup.c32
-rw-r--r--arch/x86/pci/amd_bus.c24
-rw-r--r--kernel/range.c20
3 files changed, 40 insertions, 36 deletions
diff --git a/arch/x86/kernel/cpu/mtrr/cleanup.c b/arch/x86/kernel/cpu/mtrr/cleanup.c
index 669da09ab9a8..06130b52f012 100644
--- a/arch/x86/kernel/cpu/mtrr/cleanup.c
+++ b/arch/x86/kernel/cpu/mtrr/cleanup.c
@@ -78,13 +78,13 @@ x86_get_mtrr_mem_range(struct range *range, int nr_range,
78 base = range_state[i].base_pfn; 78 base = range_state[i].base_pfn;
79 size = range_state[i].size_pfn; 79 size = range_state[i].size_pfn;
80 nr_range = add_range_with_merge(range, RANGE_NUM, nr_range, 80 nr_range = add_range_with_merge(range, RANGE_NUM, nr_range,
81 base, base + size - 1); 81 base, base + size);
82 } 82 }
83 if (debug_print) { 83 if (debug_print) {
84 printk(KERN_DEBUG "After WB checking\n"); 84 printk(KERN_DEBUG "After WB checking\n");
85 for (i = 0; i < nr_range; i++) 85 for (i = 0; i < nr_range; i++)
86 printk(KERN_DEBUG "MTRR MAP PFN: %016llx - %016llx\n", 86 printk(KERN_DEBUG "MTRR MAP PFN: %016llx - %016llx\n",
87 range[i].start, range[i].end + 1); 87 range[i].start, range[i].end);
88 } 88 }
89 89
90 /* Take out UC ranges: */ 90 /* Take out UC ranges: */
@@ -106,11 +106,11 @@ x86_get_mtrr_mem_range(struct range *range, int nr_range,
106 size -= (1<<(20-PAGE_SHIFT)) - base; 106 size -= (1<<(20-PAGE_SHIFT)) - base;
107 base = 1<<(20-PAGE_SHIFT); 107 base = 1<<(20-PAGE_SHIFT);
108 } 108 }
109 subtract_range(range, RANGE_NUM, base, base + size - 1); 109 subtract_range(range, RANGE_NUM, base, base + size);
110 } 110 }
111 if (extra_remove_size) 111 if (extra_remove_size)
112 subtract_range(range, RANGE_NUM, extra_remove_base, 112 subtract_range(range, RANGE_NUM, extra_remove_base,
113 extra_remove_base + extra_remove_size - 1); 113 extra_remove_base + extra_remove_size);
114 114
115 if (debug_print) { 115 if (debug_print) {
116 printk(KERN_DEBUG "After UC checking\n"); 116 printk(KERN_DEBUG "After UC checking\n");
@@ -118,7 +118,7 @@ x86_get_mtrr_mem_range(struct range *range, int nr_range,
118 if (!range[i].end) 118 if (!range[i].end)
119 continue; 119 continue;
120 printk(KERN_DEBUG "MTRR MAP PFN: %016llx - %016llx\n", 120 printk(KERN_DEBUG "MTRR MAP PFN: %016llx - %016llx\n",
121 range[i].start, range[i].end + 1); 121 range[i].start, range[i].end);
122 } 122 }
123 } 123 }
124 124
@@ -128,7 +128,7 @@ x86_get_mtrr_mem_range(struct range *range, int nr_range,
128 printk(KERN_DEBUG "After sorting\n"); 128 printk(KERN_DEBUG "After sorting\n");
129 for (i = 0; i < nr_range; i++) 129 for (i = 0; i < nr_range; i++)
130 printk(KERN_DEBUG "MTRR MAP PFN: %016llx - %016llx\n", 130 printk(KERN_DEBUG "MTRR MAP PFN: %016llx - %016llx\n",
131 range[i].start, range[i].end + 1); 131 range[i].start, range[i].end);
132 } 132 }
133 133
134 return nr_range; 134 return nr_range;
@@ -142,7 +142,7 @@ static unsigned long __init sum_ranges(struct range *range, int nr_range)
142 int i; 142 int i;
143 143
144 for (i = 0; i < nr_range; i++) 144 for (i = 0; i < nr_range; i++)
145 sum += range[i].end + 1 - range[i].start; 145 sum += range[i].end - range[i].start;
146 146
147 return sum; 147 return sum;
148} 148}
@@ -489,7 +489,7 @@ x86_setup_var_mtrrs(struct range *range, int nr_range,
489 /* Write the range: */ 489 /* Write the range: */
490 for (i = 0; i < nr_range; i++) { 490 for (i = 0; i < nr_range; i++) {
491 set_var_mtrr_range(&var_state, range[i].start, 491 set_var_mtrr_range(&var_state, range[i].start,
492 range[i].end - range[i].start + 1); 492 range[i].end - range[i].start);
493 } 493 }
494 494
495 /* Write the last range: */ 495 /* Write the last range: */
@@ -720,7 +720,7 @@ int __init mtrr_cleanup(unsigned address_bits)
720 * and fixed mtrrs should take effect before var mtrr for it: 720 * and fixed mtrrs should take effect before var mtrr for it:
721 */ 721 */
722 nr_range = add_range_with_merge(range, RANGE_NUM, nr_range, 0, 722 nr_range = add_range_with_merge(range, RANGE_NUM, nr_range, 0,
723 (1ULL<<(20 - PAGE_SHIFT)) - 1); 723 1ULL<<(20 - PAGE_SHIFT));
724 /* Sort the ranges: */ 724 /* Sort the ranges: */
725 sort_range(range, nr_range); 725 sort_range(range, nr_range);
726 726
@@ -939,9 +939,9 @@ int __init mtrr_trim_uncached_memory(unsigned long end_pfn)
939 nr_range = 0; 939 nr_range = 0;
940 if (mtrr_tom2) { 940 if (mtrr_tom2) {
941 range[nr_range].start = (1ULL<<(32 - PAGE_SHIFT)); 941 range[nr_range].start = (1ULL<<(32 - PAGE_SHIFT));
942 range[nr_range].end = (mtrr_tom2 >> PAGE_SHIFT) - 1; 942 range[nr_range].end = mtrr_tom2 >> PAGE_SHIFT;
943 if (highest_pfn < range[nr_range].end + 1) 943 if (highest_pfn < range[nr_range].end)
944 highest_pfn = range[nr_range].end + 1; 944 highest_pfn = range[nr_range].end;
945 nr_range++; 945 nr_range++;
946 } 946 }
947 nr_range = x86_get_mtrr_mem_range(range, nr_range, 0, 0); 947 nr_range = x86_get_mtrr_mem_range(range, nr_range, 0, 0);
@@ -953,15 +953,15 @@ int __init mtrr_trim_uncached_memory(unsigned long end_pfn)
953 953
954 /* Check the holes: */ 954 /* Check the holes: */
955 for (i = 0; i < nr_range - 1; i++) { 955 for (i = 0; i < nr_range - 1; i++) {
956 if (range[i].end + 1 < range[i+1].start) 956 if (range[i].end < range[i+1].start)
957 total_trim_size += real_trim_memory(range[i].end + 1, 957 total_trim_size += real_trim_memory(range[i].end,
958 range[i+1].start); 958 range[i+1].start);
959 } 959 }
960 960
961 /* Check the top: */ 961 /* Check the top: */
962 i = nr_range - 1; 962 i = nr_range - 1;
963 if (range[i].end + 1 < end_pfn) 963 if (range[i].end < end_pfn)
964 total_trim_size += real_trim_memory(range[i].end + 1, 964 total_trim_size += real_trim_memory(range[i].end,
965 end_pfn); 965 end_pfn);
966 966
967 if (total_trim_size) { 967 if (total_trim_size) {
diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
index ea6072fcf3d4..fc1e8fe07e5c 100644
--- a/arch/x86/pci/amd_bus.c
+++ b/arch/x86/pci/amd_bus.c
@@ -145,7 +145,7 @@ static int __init early_fill_mp_bus_info(void)
145 def_link = (reg >> 8) & 0x03; 145 def_link = (reg >> 8) & 0x03;
146 146
147 memset(range, 0, sizeof(range)); 147 memset(range, 0, sizeof(range));
148 range[0].end = 0xffff; 148 add_range(range, RANGE_NUM, 0, 0, 0xffff + 1);
149 /* io port resource */ 149 /* io port resource */
150 for (i = 0; i < 4; i++) { 150 for (i = 0; i < 4; i++) {
151 reg = read_pci_config(bus, slot, 1, 0xc0 + (i << 3)); 151 reg = read_pci_config(bus, slot, 1, 0xc0 + (i << 3));
@@ -175,7 +175,7 @@ static int __init early_fill_mp_bus_info(void)
175 if (end > 0xffff) 175 if (end > 0xffff)
176 end = 0xffff; 176 end = 0xffff;
177 update_res(info, start, end, IORESOURCE_IO, 1); 177 update_res(info, start, end, IORESOURCE_IO, 1);
178 subtract_range(range, RANGE_NUM, start, end); 178 subtract_range(range, RANGE_NUM, start, end + 1);
179 } 179 }
180 /* add left over io port range to def node/link, [0, 0xffff] */ 180 /* add left over io port range to def node/link, [0, 0xffff] */
181 /* find the position */ 181 /* find the position */
@@ -190,14 +190,16 @@ static int __init early_fill_mp_bus_info(void)
190 if (!range[i].end) 190 if (!range[i].end)
191 continue; 191 continue;
192 192
193 update_res(info, range[i].start, range[i].end, 193 update_res(info, range[i].start, range[i].end - 1,
194 IORESOURCE_IO, 1); 194 IORESOURCE_IO, 1);
195 } 195 }
196 } 196 }
197 197
198 memset(range, 0, sizeof(range)); 198 memset(range, 0, sizeof(range));
199 /* 0xfd00000000-0xffffffffff for HT */ 199 /* 0xfd00000000-0xffffffffff for HT */
200 range[0].end = cap_resource((0xfdULL<<32) - 1); 200 end = cap_resource((0xfdULL<<32) - 1);
201 end++;
202 add_range(range, RANGE_NUM, 0, 0, end);
201 203
202 /* need to take out [0, TOM) for RAM*/ 204 /* need to take out [0, TOM) for RAM*/
203 address = MSR_K8_TOP_MEM1; 205 address = MSR_K8_TOP_MEM1;
@@ -205,14 +207,15 @@ static int __init early_fill_mp_bus_info(void)
205 end = (val & 0xffffff800000ULL); 207 end = (val & 0xffffff800000ULL);
206 printk(KERN_INFO "TOM: %016llx aka %lldM\n", end, end>>20); 208 printk(KERN_INFO "TOM: %016llx aka %lldM\n", end, end>>20);
207 if (end < (1ULL<<32)) 209 if (end < (1ULL<<32))
208 subtract_range(range, RANGE_NUM, 0, end - 1); 210 subtract_range(range, RANGE_NUM, 0, end);
209 211
210 /* get mmconfig */ 212 /* get mmconfig */
211 get_pci_mmcfg_amd_fam10h_range(); 213 get_pci_mmcfg_amd_fam10h_range();
212 /* need to take out mmconf range */ 214 /* need to take out mmconf range */
213 if (fam10h_mmconf_end) { 215 if (fam10h_mmconf_end) {
214 printk(KERN_DEBUG "Fam 10h mmconf [%llx, %llx]\n", fam10h_mmconf_start, fam10h_mmconf_end); 216 printk(KERN_DEBUG "Fam 10h mmconf [%llx, %llx]\n", fam10h_mmconf_start, fam10h_mmconf_end);
215 subtract_range(range, RANGE_NUM, fam10h_mmconf_start, fam10h_mmconf_end); 217 subtract_range(range, RANGE_NUM, fam10h_mmconf_start,
218 fam10h_mmconf_end + 1);
216 } 219 }
217 220
218 /* mmio resource */ 221 /* mmio resource */
@@ -267,7 +270,8 @@ static int __init early_fill_mp_bus_info(void)
267 /* we got a hole */ 270 /* we got a hole */
268 endx = fam10h_mmconf_start - 1; 271 endx = fam10h_mmconf_start - 1;
269 update_res(info, start, endx, IORESOURCE_MEM, 0); 272 update_res(info, start, endx, IORESOURCE_MEM, 0);
270 subtract_range(range, RANGE_NUM, start, endx); 273 subtract_range(range, RANGE_NUM, start,
274 endx + 1);
271 printk(KERN_CONT " ==> [%llx, %llx]", start, endx); 275 printk(KERN_CONT " ==> [%llx, %llx]", start, endx);
272 start = fam10h_mmconf_end + 1; 276 start = fam10h_mmconf_end + 1;
273 changed = 1; 277 changed = 1;
@@ -284,7 +288,7 @@ static int __init early_fill_mp_bus_info(void)
284 288
285 update_res(info, cap_resource(start), cap_resource(end), 289 update_res(info, cap_resource(start), cap_resource(end),
286 IORESOURCE_MEM, 1); 290 IORESOURCE_MEM, 1);
287 subtract_range(range, RANGE_NUM, start, end); 291 subtract_range(range, RANGE_NUM, start, end + 1);
288 printk(KERN_CONT "\n"); 292 printk(KERN_CONT "\n");
289 } 293 }
290 294
@@ -299,7 +303,7 @@ static int __init early_fill_mp_bus_info(void)
299 rdmsrl(address, val); 303 rdmsrl(address, val);
300 end = (val & 0xffffff800000ULL); 304 end = (val & 0xffffff800000ULL);
301 printk(KERN_INFO "TOM2: %016llx aka %lldM\n", end, end>>20); 305 printk(KERN_INFO "TOM2: %016llx aka %lldM\n", end, end>>20);
302 subtract_range(range, RANGE_NUM, 1ULL<<32, end - 1); 306 subtract_range(range, RANGE_NUM, 1ULL<<32, end);
303 } 307 }
304 308
305 /* 309 /*
@@ -319,7 +323,7 @@ static int __init early_fill_mp_bus_info(void)
319 continue; 323 continue;
320 324
321 update_res(info, cap_resource(range[i].start), 325 update_res(info, cap_resource(range[i].start),
322 cap_resource(range[i].end), 326 cap_resource(range[i].end - 1),
323 IORESOURCE_MEM, 1); 327 IORESOURCE_MEM, 1);
324 } 328 }
325 } 329 }
diff --git a/kernel/range.c b/kernel/range.c
index 71e0021281fe..74e2e6114927 100644
--- a/kernel/range.c
+++ b/kernel/range.c
@@ -13,7 +13,7 @@
13 13
14int add_range(struct range *range, int az, int nr_range, u64 start, u64 end) 14int add_range(struct range *range, int az, int nr_range, u64 start, u64 end)
15{ 15{
16 if (start > end) 16 if (start >= end)
17 return nr_range; 17 return nr_range;
18 18
19 /* Out of slots: */ 19 /* Out of slots: */
@@ -33,7 +33,7 @@ int add_range_with_merge(struct range *range, int az, int nr_range,
33{ 33{
34 int i; 34 int i;
35 35
36 if (start > end) 36 if (start >= end)
37 return nr_range; 37 return nr_range;
38 38
39 /* Try to merge it with old one: */ 39 /* Try to merge it with old one: */
@@ -46,7 +46,7 @@ int add_range_with_merge(struct range *range, int az, int nr_range,
46 46
47 common_start = max(range[i].start, start); 47 common_start = max(range[i].start, start);
48 common_end = min(range[i].end, end); 48 common_end = min(range[i].end, end);
49 if (common_start > common_end + 1) 49 if (common_start > common_end)
50 continue; 50 continue;
51 51
52 final_start = min(range[i].start, start); 52 final_start = min(range[i].start, start);
@@ -65,7 +65,7 @@ void subtract_range(struct range *range, int az, u64 start, u64 end)
65{ 65{
66 int i, j; 66 int i, j;
67 67
68 if (start > end) 68 if (start >= end)
69 return; 69 return;
70 70
71 for (j = 0; j < az; j++) { 71 for (j = 0; j < az; j++) {
@@ -79,15 +79,15 @@ void subtract_range(struct range *range, int az, u64 start, u64 end)
79 } 79 }
80 80
81 if (start <= range[j].start && end < range[j].end && 81 if (start <= range[j].start && end < range[j].end &&
82 range[j].start < end + 1) { 82 range[j].start < end) {
83 range[j].start = end + 1; 83 range[j].start = end;
84 continue; 84 continue;
85 } 85 }
86 86
87 87
88 if (start > range[j].start && end >= range[j].end && 88 if (start > range[j].start && end >= range[j].end &&
89 range[j].end > start - 1) { 89 range[j].end > start) {
90 range[j].end = start - 1; 90 range[j].end = start;
91 continue; 91 continue;
92 } 92 }
93 93
@@ -99,11 +99,11 @@ void subtract_range(struct range *range, int az, u64 start, u64 end)
99 } 99 }
100 if (i < az) { 100 if (i < az) {
101 range[i].end = range[j].end; 101 range[i].end = range[j].end;
102 range[i].start = end + 1; 102 range[i].start = end;
103 } else { 103 } else {
104 printk(KERN_ERR "run of slot in ranges\n"); 104 printk(KERN_ERR "run of slot in ranges\n");
105 } 105 }
106 range[j].end = start - 1; 106 range[j].end = start;
107 continue; 107 continue;
108 } 108 }
109 } 109 }