aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/pci/amd_bus.c
diff options
context:
space:
mode:
authorYinghai Lu <yinghai@kernel.org>2010-02-10 04:20:07 -0500
committerH. Peter Anvin <hpa@zytor.com>2010-02-10 20:47:17 -0500
commit27811d8cabe56e0c3622251b049086f49face4ff (patch)
treed3966301efca0886fa2b53d74d1f9e5f1cf55056 /arch/x86/pci/amd_bus.c
parentc85e4aae699360e8db4ebfe710e917ac9b6fc77e (diff)
x86: Move range related operation to one file
We have almost the same code for mtrr cleanup and amd_bus checkup, and this code will also be used in replacing bootmem with early_res, so try to move them together and reuse it from different parts. Also rename update_range to subtract_range as that is what the function is actually doing. -v2: update comments as Christoph requested Signed-off-by: Yinghai Lu <yinghai@kernel.org> LKML-Reference: <1265793639-15071-4-git-send-email-yinghai@kernel.org> Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'arch/x86/pci/amd_bus.c')
-rw-r--r--arch/x86/pci/amd_bus.c70
1 files changed, 11 insertions, 59 deletions
diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
index 95ecbd495955..2356ea18697d 100644
--- a/arch/x86/pci/amd_bus.c
+++ b/arch/x86/pci/amd_bus.c
@@ -2,6 +2,8 @@
2#include <linux/pci.h> 2#include <linux/pci.h>
3#include <linux/topology.h> 3#include <linux/topology.h>
4#include <linux/cpu.h> 4#include <linux/cpu.h>
5#include <linux/range.h>
6
5#include <asm/pci_x86.h> 7#include <asm/pci_x86.h>
6 8
7#ifdef CONFIG_X86_64 9#ifdef CONFIG_X86_64
@@ -17,58 +19,6 @@
17 19
18#ifdef CONFIG_X86_64 20#ifdef CONFIG_X86_64
19 21
20#define RANGE_NUM 16
21
22struct res_range {
23 size_t start;
24 size_t end;
25};
26
27static void __init update_range(struct res_range *range, size_t start,
28 size_t end)
29{
30 int i;
31 int j;
32
33 for (j = 0; j < RANGE_NUM; j++) {
34 if (!range[j].end)
35 continue;
36
37 if (start <= range[j].start && end >= range[j].end) {
38 range[j].start = 0;
39 range[j].end = 0;
40 continue;
41 }
42
43 if (start <= range[j].start && end < range[j].end && range[j].start < end + 1) {
44 range[j].start = end + 1;
45 continue;
46 }
47
48
49 if (start > range[j].start && end >= range[j].end && range[j].end > start - 1) {
50 range[j].end = start - 1;
51 continue;
52 }
53
54 if (start > range[j].start && end < range[j].end) {
55 /* find the new spare */
56 for (i = 0; i < RANGE_NUM; i++) {
57 if (range[i].end == 0)
58 break;
59 }
60 if (i < RANGE_NUM) {
61 range[i].end = range[j].end;
62 range[i].start = end + 1;
63 } else {
64 printk(KERN_ERR "run of slot in ranges\n");
65 }
66 range[j].end = start - 1;
67 continue;
68 }
69 }
70}
71
72struct pci_hostbridge_probe { 22struct pci_hostbridge_probe {
73 u32 bus; 23 u32 bus;
74 u32 slot; 24 u32 slot;
@@ -111,6 +61,8 @@ static void __init get_pci_mmcfg_amd_fam10h_range(void)
111 fam10h_mmconf_end = base + (1ULL<<(segn_busn_bits + 20)) - 1; 61 fam10h_mmconf_end = base + (1ULL<<(segn_busn_bits + 20)) - 1;
112} 62}
113 63
64#define RANGE_NUM 16
65
114/** 66/**
115 * early_fill_mp_bus_to_node() 67 * early_fill_mp_bus_to_node()
116 * called before pcibios_scan_root and pci_scan_bus 68 * called before pcibios_scan_root and pci_scan_bus
@@ -132,7 +84,7 @@ static int __init early_fill_mp_bus_info(void)
132 struct resource *res; 84 struct resource *res;
133 size_t start; 85 size_t start;
134 size_t end; 86 size_t end;
135 struct res_range range[RANGE_NUM]; 87 struct range range[RANGE_NUM];
136 u64 val; 88 u64 val;
137 u32 address; 89 u32 address;
138 90
@@ -226,7 +178,7 @@ static int __init early_fill_mp_bus_info(void)
226 if (end > 0xffff) 178 if (end > 0xffff)
227 end = 0xffff; 179 end = 0xffff;
228 update_res(info, start, end, IORESOURCE_IO, 1); 180 update_res(info, start, end, IORESOURCE_IO, 1);
229 update_range(range, start, end); 181 subtract_range(range, RANGE_NUM, start, end);
230 } 182 }
231 /* add left over io port range to def node/link, [0, 0xffff] */ 183 /* add left over io port range to def node/link, [0, 0xffff] */
232 /* find the position */ 184 /* find the position */
@@ -256,14 +208,14 @@ static int __init early_fill_mp_bus_info(void)
256 end = (val & 0xffffff800000ULL); 208 end = (val & 0xffffff800000ULL);
257 printk(KERN_INFO "TOM: %016lx aka %ldM\n", end, end>>20); 209 printk(KERN_INFO "TOM: %016lx aka %ldM\n", end, end>>20);
258 if (end < (1ULL<<32)) 210 if (end < (1ULL<<32))
259 update_range(range, 0, end - 1); 211 subtract_range(range, RANGE_NUM, 0, end - 1);
260 212
261 /* get mmconfig */ 213 /* get mmconfig */
262 get_pci_mmcfg_amd_fam10h_range(); 214 get_pci_mmcfg_amd_fam10h_range();
263 /* need to take out mmconf range */ 215 /* need to take out mmconf range */
264 if (fam10h_mmconf_end) { 216 if (fam10h_mmconf_end) {
265 printk(KERN_DEBUG "Fam 10h mmconf [%llx, %llx]\n", fam10h_mmconf_start, fam10h_mmconf_end); 217 printk(KERN_DEBUG "Fam 10h mmconf [%llx, %llx]\n", fam10h_mmconf_start, fam10h_mmconf_end);
266 update_range(range, fam10h_mmconf_start, fam10h_mmconf_end); 218 subtract_range(range, RANGE_NUM, fam10h_mmconf_start, fam10h_mmconf_end);
267 } 219 }
268 220
269 /* mmio resource */ 221 /* mmio resource */
@@ -318,7 +270,7 @@ static int __init early_fill_mp_bus_info(void)
318 /* we got a hole */ 270 /* we got a hole */
319 endx = fam10h_mmconf_start - 1; 271 endx = fam10h_mmconf_start - 1;
320 update_res(info, start, endx, IORESOURCE_MEM, 0); 272 update_res(info, start, endx, IORESOURCE_MEM, 0);
321 update_range(range, start, endx); 273 subtract_range(range, RANGE_NUM, start, endx);
322 printk(KERN_CONT " ==> [%llx, %llx]", (u64)start, endx); 274 printk(KERN_CONT " ==> [%llx, %llx]", (u64)start, endx);
323 start = fam10h_mmconf_end + 1; 275 start = fam10h_mmconf_end + 1;
324 changed = 1; 276 changed = 1;
@@ -334,7 +286,7 @@ static int __init early_fill_mp_bus_info(void)
334 } 286 }
335 287
336 update_res(info, start, end, IORESOURCE_MEM, 1); 288 update_res(info, start, end, IORESOURCE_MEM, 1);
337 update_range(range, start, end); 289 subtract_range(range, RANGE_NUM, start, end);
338 printk(KERN_CONT "\n"); 290 printk(KERN_CONT "\n");
339 } 291 }
340 292
@@ -349,7 +301,7 @@ static int __init early_fill_mp_bus_info(void)
349 rdmsrl(address, val); 301 rdmsrl(address, val);
350 end = (val & 0xffffff800000ULL); 302 end = (val & 0xffffff800000ULL);
351 printk(KERN_INFO "TOM2: %016lx aka %ldM\n", end, end>>20); 303 printk(KERN_INFO "TOM2: %016lx aka %ldM\n", end, end>>20);
352 update_range(range, 1ULL<<32, end - 1); 304 subtract_range(range, RANGE_NUM, 1ULL<<32, end - 1);
353 } 305 }
354 306
355 /* 307 /*