diff options
Diffstat (limited to 'arch/x86/pci')
-rw-r--r-- | arch/x86/pci/Makefile | 5 | ||||
-rw-r--r-- | arch/x86/pci/acpi.c | 74 | ||||
-rw-r--r-- | arch/x86/pci/amd_bus.c | 120 | ||||
-rw-r--r-- | arch/x86/pci/bus_numa.c | 101 | ||||
-rw-r--r-- | arch/x86/pci/bus_numa.h | 27 | ||||
-rw-r--r-- | arch/x86/pci/common.c | 20 | ||||
-rw-r--r-- | arch/x86/pci/early.c | 7 | ||||
-rw-r--r-- | arch/x86/pci/i386.c | 42 | ||||
-rw-r--r-- | arch/x86/pci/intel_bus.c | 90 | ||||
-rw-r--r-- | arch/x86/pci/mmconfig-shared.c | 356 | ||||
-rw-r--r-- | arch/x86/pci/mmconfig_32.c | 16 | ||||
-rw-r--r-- | arch/x86/pci/mmconfig_64.c | 88 |
12 files changed, 533 insertions, 413 deletions
diff --git a/arch/x86/pci/Makefile b/arch/x86/pci/Makefile index d49202e740ea..564b008a51c7 100644 --- a/arch/x86/pci/Makefile +++ b/arch/x86/pci/Makefile | |||
@@ -15,3 +15,8 @@ obj-$(CONFIG_X86_NUMAQ) += numaq_32.o | |||
15 | 15 | ||
16 | obj-y += common.o early.o | 16 | obj-y += common.o early.o |
17 | obj-y += amd_bus.o | 17 | obj-y += amd_bus.o |
18 | obj-$(CONFIG_X86_64) += bus_numa.o intel_bus.o | ||
19 | |||
20 | ifeq ($(CONFIG_PCI_DEBUG),y) | ||
21 | EXTRA_CFLAGS += -DDEBUG | ||
22 | endif | ||
diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c index 1014eb4bfc37..959e548a7039 100644 --- a/arch/x86/pci/acpi.c +++ b/arch/x86/pci/acpi.c | |||
@@ -7,6 +7,7 @@ | |||
7 | #include <asm/pci_x86.h> | 7 | #include <asm/pci_x86.h> |
8 | 8 | ||
9 | struct pci_root_info { | 9 | struct pci_root_info { |
10 | struct acpi_device *bridge; | ||
10 | char *name; | 11 | char *name; |
11 | unsigned int res_num; | 12 | unsigned int res_num; |
12 | struct resource *res; | 13 | struct resource *res; |
@@ -58,6 +59,30 @@ bus_has_transparent_bridge(struct pci_bus *bus) | |||
58 | return false; | 59 | return false; |
59 | } | 60 | } |
60 | 61 | ||
62 | static void | ||
63 | align_resource(struct acpi_device *bridge, struct resource *res) | ||
64 | { | ||
65 | int align = (res->flags & IORESOURCE_MEM) ? 16 : 4; | ||
66 | |||
67 | /* | ||
68 | * Host bridge windows are not BARs, but the decoders on the PCI side | ||
69 | * that claim this address space have starting alignment and length | ||
70 | * constraints, so fix any obvious BIOS goofs. | ||
71 | */ | ||
72 | if (!IS_ALIGNED(res->start, align)) { | ||
73 | dev_printk(KERN_DEBUG, &bridge->dev, | ||
74 | "host bridge window %pR invalid; " | ||
75 | "aligning start to %d-byte boundary\n", res, align); | ||
76 | res->start &= ~(align - 1); | ||
77 | } | ||
78 | if (!IS_ALIGNED(res->end + 1, align)) { | ||
79 | dev_printk(KERN_DEBUG, &bridge->dev, | ||
80 | "host bridge window %pR invalid; " | ||
81 | "aligning end to %d-byte boundary\n", res, align); | ||
82 | res->end = ALIGN(res->end, align) - 1; | ||
83 | } | ||
84 | } | ||
85 | |||
61 | static acpi_status | 86 | static acpi_status |
62 | setup_resource(struct acpi_resource *acpi_res, void *data) | 87 | setup_resource(struct acpi_resource *acpi_res, void *data) |
63 | { | 88 | { |
@@ -91,11 +116,12 @@ setup_resource(struct acpi_resource *acpi_res, void *data) | |||
91 | start = addr.minimum + addr.translation_offset; | 116 | start = addr.minimum + addr.translation_offset; |
92 | end = start + addr.address_length - 1; | 117 | end = start + addr.address_length - 1; |
93 | if (info->res_num >= max_root_bus_resources) { | 118 | if (info->res_num >= max_root_bus_resources) { |
94 | printk(KERN_WARNING "PCI: Failed to allocate 0x%lx-0x%lx " | 119 | if (pci_probe & PCI_USE__CRS) |
95 | "from %s for %s due to _CRS returning more than " | 120 | printk(KERN_WARNING "PCI: Failed to allocate " |
96 | "%d resource descriptors\n", (unsigned long) start, | 121 | "0x%lx-0x%lx from %s for %s due to _CRS " |
97 | (unsigned long) end, root->name, info->name, | 122 | "returning more than %d resource descriptors\n", |
98 | max_root_bus_resources); | 123 | (unsigned long) start, (unsigned long) end, |
124 | root->name, info->name, max_root_bus_resources); | ||
99 | return AE_OK; | 125 | return AE_OK; |
100 | } | 126 | } |
101 | 127 | ||
@@ -105,14 +131,28 @@ setup_resource(struct acpi_resource *acpi_res, void *data) | |||
105 | res->start = start; | 131 | res->start = start; |
106 | res->end = end; | 132 | res->end = end; |
107 | res->child = NULL; | 133 | res->child = NULL; |
134 | align_resource(info->bridge, res); | ||
135 | |||
136 | if (!(pci_probe & PCI_USE__CRS)) { | ||
137 | dev_printk(KERN_DEBUG, &info->bridge->dev, | ||
138 | "host bridge window %pR (ignored)\n", res); | ||
139 | return AE_OK; | ||
140 | } | ||
108 | 141 | ||
109 | if (insert_resource(root, res)) { | 142 | if (insert_resource(root, res)) { |
110 | printk(KERN_ERR "PCI: Failed to allocate 0x%lx-0x%lx " | 143 | dev_err(&info->bridge->dev, |
111 | "from %s for %s\n", (unsigned long) res->start, | 144 | "can't allocate host bridge window %pR\n", res); |
112 | (unsigned long) res->end, root->name, info->name); | ||
113 | } else { | 145 | } else { |
114 | info->bus->resource[info->res_num] = res; | 146 | info->bus->resource[info->res_num] = res; |
115 | info->res_num++; | 147 | info->res_num++; |
148 | if (addr.translation_offset) | ||
149 | dev_info(&info->bridge->dev, "host bridge window %pR " | ||
150 | "(PCI address [%#llx-%#llx])\n", | ||
151 | res, res->start - addr.translation_offset, | ||
152 | res->end - addr.translation_offset); | ||
153 | else | ||
154 | dev_info(&info->bridge->dev, | ||
155 | "host bridge window %pR\n", res); | ||
116 | } | 156 | } |
117 | return AE_OK; | 157 | return AE_OK; |
118 | } | 158 | } |
@@ -124,6 +164,12 @@ get_current_resources(struct acpi_device *device, int busnum, | |||
124 | struct pci_root_info info; | 164 | struct pci_root_info info; |
125 | size_t size; | 165 | size_t size; |
126 | 166 | ||
167 | if (!(pci_probe & PCI_USE__CRS)) | ||
168 | dev_info(&device->dev, | ||
169 | "ignoring host bridge windows from ACPI; " | ||
170 | "boot with \"pci=use_crs\" to use them\n"); | ||
171 | |||
172 | info.bridge = device; | ||
127 | info.bus = bus; | 173 | info.bus = bus; |
128 | info.res_num = 0; | 174 | info.res_num = 0; |
129 | acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_resource, | 175 | acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_resource, |
@@ -163,8 +209,9 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int do | |||
163 | #endif | 209 | #endif |
164 | 210 | ||
165 | if (domain && !pci_domains_supported) { | 211 | if (domain && !pci_domains_supported) { |
166 | printk(KERN_WARNING "PCI: Multiple domains not supported " | 212 | printk(KERN_WARNING "pci_bus %04x:%02x: " |
167 | "(dom %d, bus %d)\n", domain, busnum); | 213 | "ignored (multiple domains not supported)\n", |
214 | domain, busnum); | ||
168 | return NULL; | 215 | return NULL; |
169 | } | 216 | } |
170 | 217 | ||
@@ -188,7 +235,8 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int do | |||
188 | */ | 235 | */ |
189 | sd = kzalloc(sizeof(*sd), GFP_KERNEL); | 236 | sd = kzalloc(sizeof(*sd), GFP_KERNEL); |
190 | if (!sd) { | 237 | if (!sd) { |
191 | printk(KERN_ERR "PCI: OOM, not probing PCI bus %02x\n", busnum); | 238 | printk(KERN_WARNING "pci_bus %04x:%02x: " |
239 | "ignored (out of memory)\n", domain, busnum); | ||
192 | return NULL; | 240 | return NULL; |
193 | } | 241 | } |
194 | 242 | ||
@@ -209,9 +257,7 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int do | |||
209 | } else { | 257 | } else { |
210 | bus = pci_create_bus(NULL, busnum, &pci_root_ops, sd); | 258 | bus = pci_create_bus(NULL, busnum, &pci_root_ops, sd); |
211 | if (bus) { | 259 | if (bus) { |
212 | if (pci_probe & PCI_USE__CRS) | 260 | get_current_resources(device, busnum, domain, bus); |
213 | get_current_resources(device, busnum, domain, | ||
214 | bus); | ||
215 | bus->subordinate = pci_scan_child_bus(bus); | 261 | bus->subordinate = pci_scan_child_bus(bus); |
216 | } | 262 | } |
217 | } | 263 | } |
diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c index 572ee9782f2a..95ecbd495955 100644 --- a/arch/x86/pci/amd_bus.c +++ b/arch/x86/pci/amd_bus.c | |||
@@ -6,10 +6,10 @@ | |||
6 | 6 | ||
7 | #ifdef CONFIG_X86_64 | 7 | #ifdef CONFIG_X86_64 |
8 | #include <asm/pci-direct.h> | 8 | #include <asm/pci-direct.h> |
9 | #include <asm/mpspec.h> | ||
10 | #include <linux/cpumask.h> | ||
11 | #endif | 9 | #endif |
12 | 10 | ||
11 | #include "bus_numa.h" | ||
12 | |||
13 | /* | 13 | /* |
14 | * This discovers the pcibus <-> node mapping on AMD K8. | 14 | * This discovers the pcibus <-> node mapping on AMD K8. |
15 | * also get peer root bus resource for io,mmio | 15 | * also get peer root bus resource for io,mmio |
@@ -17,67 +17,6 @@ | |||
17 | 17 | ||
18 | #ifdef CONFIG_X86_64 | 18 | #ifdef CONFIG_X86_64 |
19 | 19 | ||
20 | /* | ||
21 | * sub bus (transparent) will use entres from 3 to store extra from root, | ||
22 | * so need to make sure have enought slot there, increase PCI_BUS_NUM_RESOURCES? | ||
23 | */ | ||
24 | #define RES_NUM 16 | ||
25 | struct pci_root_info { | ||
26 | char name[12]; | ||
27 | unsigned int res_num; | ||
28 | struct resource res[RES_NUM]; | ||
29 | int bus_min; | ||
30 | int bus_max; | ||
31 | int node; | ||
32 | int link; | ||
33 | }; | ||
34 | |||
35 | /* 4 at this time, it may become to 32 */ | ||
36 | #define PCI_ROOT_NR 4 | ||
37 | static int pci_root_num; | ||
38 | static struct pci_root_info pci_root_info[PCI_ROOT_NR]; | ||
39 | |||
40 | void x86_pci_root_bus_res_quirks(struct pci_bus *b) | ||
41 | { | ||
42 | int i; | ||
43 | int j; | ||
44 | struct pci_root_info *info; | ||
45 | |||
46 | /* don't go for it if _CRS is used already */ | ||
47 | if (b->resource[0] != &ioport_resource || | ||
48 | b->resource[1] != &iomem_resource) | ||
49 | return; | ||
50 | |||
51 | /* if only one root bus, don't need to anything */ | ||
52 | if (pci_root_num < 2) | ||
53 | return; | ||
54 | |||
55 | for (i = 0; i < pci_root_num; i++) { | ||
56 | if (pci_root_info[i].bus_min == b->number) | ||
57 | break; | ||
58 | } | ||
59 | |||
60 | if (i == pci_root_num) | ||
61 | return; | ||
62 | |||
63 | printk(KERN_DEBUG "PCI: peer root bus %02x res updated from pci conf\n", | ||
64 | b->number); | ||
65 | |||
66 | info = &pci_root_info[i]; | ||
67 | for (j = 0; j < info->res_num; j++) { | ||
68 | struct resource *res; | ||
69 | struct resource *root; | ||
70 | |||
71 | res = &info->res[j]; | ||
72 | b->resource[j] = res; | ||
73 | if (res->flags & IORESOURCE_IO) | ||
74 | root = &ioport_resource; | ||
75 | else | ||
76 | root = &iomem_resource; | ||
77 | insert_resource(root, res); | ||
78 | } | ||
79 | } | ||
80 | |||
81 | #define RANGE_NUM 16 | 20 | #define RANGE_NUM 16 |
82 | 21 | ||
83 | struct res_range { | 22 | struct res_range { |
@@ -130,52 +69,6 @@ static void __init update_range(struct res_range *range, size_t start, | |||
130 | } | 69 | } |
131 | } | 70 | } |
132 | 71 | ||
133 | static void __init update_res(struct pci_root_info *info, size_t start, | ||
134 | size_t end, unsigned long flags, int merge) | ||
135 | { | ||
136 | int i; | ||
137 | struct resource *res; | ||
138 | |||
139 | if (!merge) | ||
140 | goto addit; | ||
141 | |||
142 | /* try to merge it with old one */ | ||
143 | for (i = 0; i < info->res_num; i++) { | ||
144 | size_t final_start, final_end; | ||
145 | size_t common_start, common_end; | ||
146 | |||
147 | res = &info->res[i]; | ||
148 | if (res->flags != flags) | ||
149 | continue; | ||
150 | |||
151 | common_start = max((size_t)res->start, start); | ||
152 | common_end = min((size_t)res->end, end); | ||
153 | if (common_start > common_end + 1) | ||
154 | continue; | ||
155 | |||
156 | final_start = min((size_t)res->start, start); | ||
157 | final_end = max((size_t)res->end, end); | ||
158 | |||
159 | res->start = final_start; | ||
160 | res->end = final_end; | ||
161 | return; | ||
162 | } | ||
163 | |||
164 | addit: | ||
165 | |||
166 | /* need to add that */ | ||
167 | if (info->res_num >= RES_NUM) | ||
168 | return; | ||
169 | |||
170 | res = &info->res[info->res_num]; | ||
171 | res->name = info->name; | ||
172 | res->flags = flags; | ||
173 | res->start = start; | ||
174 | res->end = end; | ||
175 | res->child = NULL; | ||
176 | info->res_num++; | ||
177 | } | ||
178 | |||
179 | struct pci_hostbridge_probe { | 72 | struct pci_hostbridge_probe { |
180 | u32 bus; | 73 | u32 bus; |
181 | u32 slot; | 74 | u32 slot; |
@@ -230,7 +123,6 @@ static int __init early_fill_mp_bus_info(void) | |||
230 | int j; | 123 | int j; |
231 | unsigned bus; | 124 | unsigned bus; |
232 | unsigned slot; | 125 | unsigned slot; |
233 | int found; | ||
234 | int node; | 126 | int node; |
235 | int link; | 127 | int link; |
236 | int def_node; | 128 | int def_node; |
@@ -247,7 +139,7 @@ static int __init early_fill_mp_bus_info(void) | |||
247 | if (!early_pci_allowed()) | 139 | if (!early_pci_allowed()) |
248 | return -1; | 140 | return -1; |
249 | 141 | ||
250 | found = 0; | 142 | found_all_numa_early = 0; |
251 | for (i = 0; i < ARRAY_SIZE(pci_probes); i++) { | 143 | for (i = 0; i < ARRAY_SIZE(pci_probes); i++) { |
252 | u32 id; | 144 | u32 id; |
253 | u16 device; | 145 | u16 device; |
@@ -261,12 +153,12 @@ static int __init early_fill_mp_bus_info(void) | |||
261 | device = (id>>16) & 0xffff; | 153 | device = (id>>16) & 0xffff; |
262 | if (pci_probes[i].vendor == vendor && | 154 | if (pci_probes[i].vendor == vendor && |
263 | pci_probes[i].device == device) { | 155 | pci_probes[i].device == device) { |
264 | found = 1; | 156 | found_all_numa_early = 1; |
265 | break; | 157 | break; |
266 | } | 158 | } |
267 | } | 159 | } |
268 | 160 | ||
269 | if (!found) | 161 | if (!found_all_numa_early) |
270 | return 0; | 162 | return 0; |
271 | 163 | ||
272 | pci_root_num = 0; | 164 | pci_root_num = 0; |
@@ -488,7 +380,7 @@ static int __init early_fill_mp_bus_info(void) | |||
488 | info = &pci_root_info[i]; | 380 | info = &pci_root_info[i]; |
489 | res_num = info->res_num; | 381 | res_num = info->res_num; |
490 | busnum = info->bus_min; | 382 | busnum = info->bus_min; |
491 | printk(KERN_DEBUG "bus: [%02x,%02x] on node %x link %x\n", | 383 | printk(KERN_DEBUG "bus: [%02x, %02x] on node %x link %x\n", |
492 | info->bus_min, info->bus_max, info->node, info->link); | 384 | info->bus_min, info->bus_max, info->node, info->link); |
493 | for (j = 0; j < res_num; j++) { | 385 | for (j = 0; j < res_num; j++) { |
494 | res = &info->res[j]; | 386 | res = &info->res[j]; |
diff --git a/arch/x86/pci/bus_numa.c b/arch/x86/pci/bus_numa.c new file mode 100644 index 000000000000..145df00e0387 --- /dev/null +++ b/arch/x86/pci/bus_numa.c | |||
@@ -0,0 +1,101 @@ | |||
1 | #include <linux/init.h> | ||
2 | #include <linux/pci.h> | ||
3 | |||
4 | #include "bus_numa.h" | ||
5 | |||
6 | int pci_root_num; | ||
7 | struct pci_root_info pci_root_info[PCI_ROOT_NR]; | ||
8 | int found_all_numa_early; | ||
9 | |||
10 | void x86_pci_root_bus_res_quirks(struct pci_bus *b) | ||
11 | { | ||
12 | int i; | ||
13 | int j; | ||
14 | struct pci_root_info *info; | ||
15 | |||
16 | /* don't go for it if _CRS is used already */ | ||
17 | if (b->resource[0] != &ioport_resource || | ||
18 | b->resource[1] != &iomem_resource) | ||
19 | return; | ||
20 | |||
21 | if (!pci_root_num) | ||
22 | return; | ||
23 | |||
24 | /* for amd, if only one root bus, don't need to do anything */ | ||
25 | if (pci_root_num < 2 && found_all_numa_early) | ||
26 | return; | ||
27 | |||
28 | for (i = 0; i < pci_root_num; i++) { | ||
29 | if (pci_root_info[i].bus_min == b->number) | ||
30 | break; | ||
31 | } | ||
32 | |||
33 | if (i == pci_root_num) | ||
34 | return; | ||
35 | |||
36 | printk(KERN_DEBUG "PCI: peer root bus %02x res updated from pci conf\n", | ||
37 | b->number); | ||
38 | |||
39 | info = &pci_root_info[i]; | ||
40 | for (j = 0; j < info->res_num; j++) { | ||
41 | struct resource *res; | ||
42 | struct resource *root; | ||
43 | |||
44 | res = &info->res[j]; | ||
45 | b->resource[j] = res; | ||
46 | if (res->flags & IORESOURCE_IO) | ||
47 | root = &ioport_resource; | ||
48 | else | ||
49 | root = &iomem_resource; | ||
50 | insert_resource(root, res); | ||
51 | } | ||
52 | } | ||
53 | |||
54 | void __init update_res(struct pci_root_info *info, size_t start, | ||
55 | size_t end, unsigned long flags, int merge) | ||
56 | { | ||
57 | int i; | ||
58 | struct resource *res; | ||
59 | |||
60 | if (start > end) | ||
61 | return; | ||
62 | |||
63 | if (!merge) | ||
64 | goto addit; | ||
65 | |||
66 | /* try to merge it with old one */ | ||
67 | for (i = 0; i < info->res_num; i++) { | ||
68 | size_t final_start, final_end; | ||
69 | size_t common_start, common_end; | ||
70 | |||
71 | res = &info->res[i]; | ||
72 | if (res->flags != flags) | ||
73 | continue; | ||
74 | |||
75 | common_start = max((size_t)res->start, start); | ||
76 | common_end = min((size_t)res->end, end); | ||
77 | if (common_start > common_end + 1) | ||
78 | continue; | ||
79 | |||
80 | final_start = min((size_t)res->start, start); | ||
81 | final_end = max((size_t)res->end, end); | ||
82 | |||
83 | res->start = final_start; | ||
84 | res->end = final_end; | ||
85 | return; | ||
86 | } | ||
87 | |||
88 | addit: | ||
89 | |||
90 | /* need to add that */ | ||
91 | if (info->res_num >= RES_NUM) | ||
92 | return; | ||
93 | |||
94 | res = &info->res[info->res_num]; | ||
95 | res->name = info->name; | ||
96 | res->flags = flags; | ||
97 | res->start = start; | ||
98 | res->end = end; | ||
99 | res->child = NULL; | ||
100 | info->res_num++; | ||
101 | } | ||
diff --git a/arch/x86/pci/bus_numa.h b/arch/x86/pci/bus_numa.h new file mode 100644 index 000000000000..adbc23fe82ac --- /dev/null +++ b/arch/x86/pci/bus_numa.h | |||
@@ -0,0 +1,27 @@ | |||
1 | #ifdef CONFIG_X86_64 | ||
2 | |||
3 | /* | ||
4 | * sub bus (transparent) will use entres from 3 to store extra from | ||
5 | * root, so need to make sure we have enough slot there, Should we | ||
6 | * increase PCI_BUS_NUM_RESOURCES? | ||
7 | */ | ||
8 | #define RES_NUM 16 | ||
9 | struct pci_root_info { | ||
10 | char name[12]; | ||
11 | unsigned int res_num; | ||
12 | struct resource res[RES_NUM]; | ||
13 | int bus_min; | ||
14 | int bus_max; | ||
15 | int node; | ||
16 | int link; | ||
17 | }; | ||
18 | |||
19 | /* 4 at this time, it may become to 32 */ | ||
20 | #define PCI_ROOT_NR 4 | ||
21 | extern int pci_root_num; | ||
22 | extern struct pci_root_info pci_root_info[PCI_ROOT_NR]; | ||
23 | extern int found_all_numa_early; | ||
24 | |||
25 | extern void update_res(struct pci_root_info *info, size_t start, | ||
26 | size_t end, unsigned long flags, int merge); | ||
27 | #endif | ||
diff --git a/arch/x86/pci/common.c b/arch/x86/pci/common.c index 1331fcf26143..d2552c68e94d 100644 --- a/arch/x86/pci/common.c +++ b/arch/x86/pci/common.c | |||
@@ -410,8 +410,6 @@ struct pci_bus * __devinit pcibios_scan_root(int busnum) | |||
410 | return bus; | 410 | return bus; |
411 | } | 411 | } |
412 | 412 | ||
413 | extern u8 pci_cache_line_size; | ||
414 | |||
415 | int __init pcibios_init(void) | 413 | int __init pcibios_init(void) |
416 | { | 414 | { |
417 | struct cpuinfo_x86 *c = &boot_cpu_data; | 415 | struct cpuinfo_x86 *c = &boot_cpu_data; |
@@ -422,15 +420,19 @@ int __init pcibios_init(void) | |||
422 | } | 420 | } |
423 | 421 | ||
424 | /* | 422 | /* |
425 | * Assume PCI cacheline size of 32 bytes for all x86s except K7/K8 | 423 | * Set PCI cacheline size to that of the CPU if the CPU has reported it. |
426 | * and P4. It's also good for 386/486s (which actually have 16) | 424 | * (For older CPUs that don't support cpuid, we se it to 32 bytes |
425 | * It's also good for 386/486s (which actually have 16) | ||
427 | * as quite a few PCI devices do not support smaller values. | 426 | * as quite a few PCI devices do not support smaller values. |
428 | */ | 427 | */ |
429 | pci_cache_line_size = 32 >> 2; | 428 | if (c->x86_clflush_size > 0) { |
430 | if (c->x86 >= 6 && c->x86_vendor == X86_VENDOR_AMD) | 429 | pci_dfl_cache_line_size = c->x86_clflush_size >> 2; |
431 | pci_cache_line_size = 64 >> 2; /* K7 & K8 */ | 430 | printk(KERN_DEBUG "PCI: pci_cache_line_size set to %d bytes\n", |
432 | else if (c->x86 > 6 && c->x86_vendor == X86_VENDOR_INTEL) | 431 | pci_dfl_cache_line_size << 2); |
433 | pci_cache_line_size = 128 >> 2; /* P4 */ | 432 | } else { |
433 | pci_dfl_cache_line_size = 32 >> 2; | ||
434 | printk(KERN_DEBUG "PCI: Unknown cacheline size. Setting to 32 bytes\n"); | ||
435 | } | ||
434 | 436 | ||
435 | pcibios_resource_survey(); | 437 | pcibios_resource_survey(); |
436 | 438 | ||
diff --git a/arch/x86/pci/early.c b/arch/x86/pci/early.c index aaf26ae58cd5..d1067d539bee 100644 --- a/arch/x86/pci/early.c +++ b/arch/x86/pci/early.c | |||
@@ -12,8 +12,6 @@ u32 read_pci_config(u8 bus, u8 slot, u8 func, u8 offset) | |||
12 | u32 v; | 12 | u32 v; |
13 | outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8); | 13 | outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8); |
14 | v = inl(0xcfc); | 14 | v = inl(0xcfc); |
15 | if (v != 0xffffffff) | ||
16 | pr_debug("%x reading 4 from %x: %x\n", slot, offset, v); | ||
17 | return v; | 15 | return v; |
18 | } | 16 | } |
19 | 17 | ||
@@ -22,7 +20,6 @@ u8 read_pci_config_byte(u8 bus, u8 slot, u8 func, u8 offset) | |||
22 | u8 v; | 20 | u8 v; |
23 | outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8); | 21 | outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8); |
24 | v = inb(0xcfc + (offset&3)); | 22 | v = inb(0xcfc + (offset&3)); |
25 | pr_debug("%x reading 1 from %x: %x\n", slot, offset, v); | ||
26 | return v; | 23 | return v; |
27 | } | 24 | } |
28 | 25 | ||
@@ -31,28 +28,24 @@ u16 read_pci_config_16(u8 bus, u8 slot, u8 func, u8 offset) | |||
31 | u16 v; | 28 | u16 v; |
32 | outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8); | 29 | outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8); |
33 | v = inw(0xcfc + (offset&2)); | 30 | v = inw(0xcfc + (offset&2)); |
34 | pr_debug("%x reading 2 from %x: %x\n", slot, offset, v); | ||
35 | return v; | 31 | return v; |
36 | } | 32 | } |
37 | 33 | ||
38 | void write_pci_config(u8 bus, u8 slot, u8 func, u8 offset, | 34 | void write_pci_config(u8 bus, u8 slot, u8 func, u8 offset, |
39 | u32 val) | 35 | u32 val) |
40 | { | 36 | { |
41 | pr_debug("%x writing to %x: %x\n", slot, offset, val); | ||
42 | outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8); | 37 | outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8); |
43 | outl(val, 0xcfc); | 38 | outl(val, 0xcfc); |
44 | } | 39 | } |
45 | 40 | ||
46 | void write_pci_config_byte(u8 bus, u8 slot, u8 func, u8 offset, u8 val) | 41 | void write_pci_config_byte(u8 bus, u8 slot, u8 func, u8 offset, u8 val) |
47 | { | 42 | { |
48 | pr_debug("%x writing to %x: %x\n", slot, offset, val); | ||
49 | outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8); | 43 | outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8); |
50 | outb(val, 0xcfc + (offset&3)); | 44 | outb(val, 0xcfc + (offset&3)); |
51 | } | 45 | } |
52 | 46 | ||
53 | void write_pci_config_16(u8 bus, u8 slot, u8 func, u8 offset, u16 val) | 47 | void write_pci_config_16(u8 bus, u8 slot, u8 func, u8 offset, u16 val) |
54 | { | 48 | { |
55 | pr_debug("%x writing to %x: %x\n", slot, offset, val); | ||
56 | outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8); | 49 | outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8); |
57 | outw(val, 0xcfc + (offset&2)); | 50 | outw(val, 0xcfc + (offset&2)); |
58 | } | 51 | } |
diff --git a/arch/x86/pci/i386.c b/arch/x86/pci/i386.c index b22d13b0c71d..5dc9e8c63fcd 100644 --- a/arch/x86/pci/i386.c +++ b/arch/x86/pci/i386.c | |||
@@ -129,7 +129,9 @@ static void __init pcibios_allocate_bus_resources(struct list_head *bus_list) | |||
129 | continue; | 129 | continue; |
130 | if (!r->start || | 130 | if (!r->start || |
131 | pci_claim_resource(dev, idx) < 0) { | 131 | pci_claim_resource(dev, idx) < 0) { |
132 | dev_info(&dev->dev, "BAR %d: can't allocate resource\n", idx); | 132 | dev_info(&dev->dev, |
133 | "can't reserve window %pR\n", | ||
134 | r); | ||
133 | /* | 135 | /* |
134 | * Something is wrong with the region. | 136 | * Something is wrong with the region. |
135 | * Invalidate the resource to prevent | 137 | * Invalidate the resource to prevent |
@@ -144,16 +146,29 @@ static void __init pcibios_allocate_bus_resources(struct list_head *bus_list) | |||
144 | } | 146 | } |
145 | } | 147 | } |
146 | 148 | ||
149 | struct pci_check_idx_range { | ||
150 | int start; | ||
151 | int end; | ||
152 | }; | ||
153 | |||
147 | static void __init pcibios_allocate_resources(int pass) | 154 | static void __init pcibios_allocate_resources(int pass) |
148 | { | 155 | { |
149 | struct pci_dev *dev = NULL; | 156 | struct pci_dev *dev = NULL; |
150 | int idx, disabled; | 157 | int idx, disabled, i; |
151 | u16 command; | 158 | u16 command; |
152 | struct resource *r; | 159 | struct resource *r; |
153 | 160 | ||
161 | struct pci_check_idx_range idx_range[] = { | ||
162 | { PCI_STD_RESOURCES, PCI_STD_RESOURCE_END }, | ||
163 | #ifdef CONFIG_PCI_IOV | ||
164 | { PCI_IOV_RESOURCES, PCI_IOV_RESOURCE_END }, | ||
165 | #endif | ||
166 | }; | ||
167 | |||
154 | for_each_pci_dev(dev) { | 168 | for_each_pci_dev(dev) { |
155 | pci_read_config_word(dev, PCI_COMMAND, &command); | 169 | pci_read_config_word(dev, PCI_COMMAND, &command); |
156 | for (idx = 0; idx < PCI_ROM_RESOURCE; idx++) { | 170 | for (i = 0; i < ARRAY_SIZE(idx_range); i++) |
171 | for (idx = idx_range[i].start; idx <= idx_range[i].end; idx++) { | ||
157 | r = &dev->resource[idx]; | 172 | r = &dev->resource[idx]; |
158 | if (r->parent) /* Already allocated */ | 173 | if (r->parent) /* Already allocated */ |
159 | continue; | 174 | continue; |
@@ -164,12 +179,12 @@ static void __init pcibios_allocate_resources(int pass) | |||
164 | else | 179 | else |
165 | disabled = !(command & PCI_COMMAND_MEMORY); | 180 | disabled = !(command & PCI_COMMAND_MEMORY); |
166 | if (pass == disabled) { | 181 | if (pass == disabled) { |
167 | dev_dbg(&dev->dev, "resource %#08llx-%#08llx (f=%lx, d=%d, p=%d)\n", | 182 | dev_dbg(&dev->dev, |
168 | (unsigned long long) r->start, | 183 | "BAR %d: reserving %pr (d=%d, p=%d)\n", |
169 | (unsigned long long) r->end, | 184 | idx, r, disabled, pass); |
170 | r->flags, disabled, pass); | ||
171 | if (pci_claim_resource(dev, idx) < 0) { | 185 | if (pci_claim_resource(dev, idx) < 0) { |
172 | dev_info(&dev->dev, "BAR %d: can't allocate resource\n", idx); | 186 | dev_info(&dev->dev, |
187 | "can't reserve %pR\n", r); | ||
173 | /* We'll assign a new address later */ | 188 | /* We'll assign a new address later */ |
174 | r->end -= r->start; | 189 | r->end -= r->start; |
175 | r->start = 0; | 190 | r->start = 0; |
@@ -182,7 +197,7 @@ static void __init pcibios_allocate_resources(int pass) | |||
182 | /* Turn the ROM off, leave the resource region, | 197 | /* Turn the ROM off, leave the resource region, |
183 | * but keep it unregistered. */ | 198 | * but keep it unregistered. */ |
184 | u32 reg; | 199 | u32 reg; |
185 | dev_dbg(&dev->dev, "disabling ROM\n"); | 200 | dev_dbg(&dev->dev, "disabling ROM %pR\n", r); |
186 | r->flags &= ~IORESOURCE_ROM_ENABLE; | 201 | r->flags &= ~IORESOURCE_ROM_ENABLE; |
187 | pci_read_config_dword(dev, | 202 | pci_read_config_dword(dev, |
188 | dev->rom_base_reg, ®); | 203 | dev->rom_base_reg, ®); |
@@ -282,6 +297,15 @@ int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma, | |||
282 | return -EINVAL; | 297 | return -EINVAL; |
283 | 298 | ||
284 | prot = pgprot_val(vma->vm_page_prot); | 299 | prot = pgprot_val(vma->vm_page_prot); |
300 | |||
301 | /* | ||
302 | * Return error if pat is not enabled and write_combine is requested. | ||
303 | * Caller can followup with UC MINUS request and add a WC mtrr if there | ||
304 | * is a free mtrr slot. | ||
305 | */ | ||
306 | if (!pat_enabled && write_combine) | ||
307 | return -EINVAL; | ||
308 | |||
285 | if (pat_enabled && write_combine) | 309 | if (pat_enabled && write_combine) |
286 | prot |= _PAGE_CACHE_WC; | 310 | prot |= _PAGE_CACHE_WC; |
287 | else if (pat_enabled || boot_cpu_data.x86 > 3) | 311 | else if (pat_enabled || boot_cpu_data.x86 > 3) |
diff --git a/arch/x86/pci/intel_bus.c b/arch/x86/pci/intel_bus.c new file mode 100644 index 000000000000..b7a55dc55d13 --- /dev/null +++ b/arch/x86/pci/intel_bus.c | |||
@@ -0,0 +1,90 @@ | |||
1 | /* | ||
2 | * to read io range from IOH pci conf, need to do it after mmconfig is there | ||
3 | */ | ||
4 | |||
5 | #include <linux/delay.h> | ||
6 | #include <linux/dmi.h> | ||
7 | #include <linux/pci.h> | ||
8 | #include <linux/init.h> | ||
9 | #include <asm/pci_x86.h> | ||
10 | |||
11 | #include "bus_numa.h" | ||
12 | |||
13 | static inline void print_ioh_resources(struct pci_root_info *info) | ||
14 | { | ||
15 | int res_num; | ||
16 | int busnum; | ||
17 | int i; | ||
18 | |||
19 | printk(KERN_DEBUG "IOH bus: [%02x, %02x]\n", | ||
20 | info->bus_min, info->bus_max); | ||
21 | res_num = info->res_num; | ||
22 | busnum = info->bus_min; | ||
23 | for (i = 0; i < res_num; i++) { | ||
24 | struct resource *res; | ||
25 | |||
26 | res = &info->res[i]; | ||
27 | printk(KERN_DEBUG "IOH bus: %02x index %x %s: [%llx, %llx]\n", | ||
28 | busnum, i, | ||
29 | (res->flags & IORESOURCE_IO) ? "io port" : | ||
30 | "mmio", | ||
31 | res->start, res->end); | ||
32 | } | ||
33 | } | ||
34 | |||
35 | #define IOH_LIO 0x108 | ||
36 | #define IOH_LMMIOL 0x10c | ||
37 | #define IOH_LMMIOH 0x110 | ||
38 | #define IOH_LMMIOH_BASEU 0x114 | ||
39 | #define IOH_LMMIOH_LIMITU 0x118 | ||
40 | #define IOH_LCFGBUS 0x11c | ||
41 | |||
42 | static void __devinit pci_root_bus_res(struct pci_dev *dev) | ||
43 | { | ||
44 | u16 word; | ||
45 | u32 dword; | ||
46 | struct pci_root_info *info; | ||
47 | u16 io_base, io_end; | ||
48 | u32 mmiol_base, mmiol_end; | ||
49 | u64 mmioh_base, mmioh_end; | ||
50 | int bus_base, bus_end; | ||
51 | |||
52 | if (pci_root_num >= PCI_ROOT_NR) { | ||
53 | printk(KERN_DEBUG "intel_bus.c: PCI_ROOT_NR is too small\n"); | ||
54 | return; | ||
55 | } | ||
56 | |||
57 | info = &pci_root_info[pci_root_num]; | ||
58 | pci_root_num++; | ||
59 | |||
60 | pci_read_config_word(dev, IOH_LCFGBUS, &word); | ||
61 | bus_base = (word & 0xff); | ||
62 | bus_end = (word & 0xff00) >> 8; | ||
63 | sprintf(info->name, "PCI Bus #%02x", bus_base); | ||
64 | info->bus_min = bus_base; | ||
65 | info->bus_max = bus_end; | ||
66 | |||
67 | pci_read_config_word(dev, IOH_LIO, &word); | ||
68 | io_base = (word & 0xf0) << (12 - 4); | ||
69 | io_end = (word & 0xf000) | 0xfff; | ||
70 | update_res(info, io_base, io_end, IORESOURCE_IO, 0); | ||
71 | |||
72 | pci_read_config_dword(dev, IOH_LMMIOL, &dword); | ||
73 | mmiol_base = (dword & 0xff00) << (24 - 8); | ||
74 | mmiol_end = (dword & 0xff000000) | 0xffffff; | ||
75 | update_res(info, mmiol_base, mmiol_end, IORESOURCE_MEM, 0); | ||
76 | |||
77 | pci_read_config_dword(dev, IOH_LMMIOH, &dword); | ||
78 | mmioh_base = ((u64)(dword & 0xfc00)) << (26 - 10); | ||
79 | mmioh_end = ((u64)(dword & 0xfc000000) | 0x3ffffff); | ||
80 | pci_read_config_dword(dev, IOH_LMMIOH_BASEU, &dword); | ||
81 | mmioh_base |= ((u64)(dword & 0x7ffff)) << 32; | ||
82 | pci_read_config_dword(dev, IOH_LMMIOH_LIMITU, &dword); | ||
83 | mmioh_end |= ((u64)(dword & 0x7ffff)) << 32; | ||
84 | update_res(info, mmioh_base, mmioh_end, IORESOURCE_MEM, 0); | ||
85 | |||
86 | print_ioh_resources(info); | ||
87 | } | ||
88 | |||
89 | /* intel IOH */ | ||
90 | DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x342e, pci_root_bus_res); | ||
diff --git a/arch/x86/pci/mmconfig-shared.c b/arch/x86/pci/mmconfig-shared.c index 602c172d3bd5..b19d1e54201e 100644 --- a/arch/x86/pci/mmconfig-shared.c +++ b/arch/x86/pci/mmconfig-shared.c | |||
@@ -15,48 +15,98 @@ | |||
15 | #include <linux/acpi.h> | 15 | #include <linux/acpi.h> |
16 | #include <linux/sfi_acpi.h> | 16 | #include <linux/sfi_acpi.h> |
17 | #include <linux/bitmap.h> | 17 | #include <linux/bitmap.h> |
18 | #include <linux/sort.h> | 18 | #include <linux/dmi.h> |
19 | #include <asm/e820.h> | 19 | #include <asm/e820.h> |
20 | #include <asm/pci_x86.h> | 20 | #include <asm/pci_x86.h> |
21 | #include <asm/acpi.h> | 21 | #include <asm/acpi.h> |
22 | 22 | ||
23 | #define PREFIX "PCI: " | 23 | #define PREFIX "PCI: " |
24 | 24 | ||
25 | /* aperture is up to 256MB but BIOS may reserve less */ | ||
26 | #define MMCONFIG_APER_MIN (2 * 1024*1024) | ||
27 | #define MMCONFIG_APER_MAX (256 * 1024*1024) | ||
28 | |||
29 | /* Indicate if the mmcfg resources have been placed into the resource table. */ | 25 | /* Indicate if the mmcfg resources have been placed into the resource table. */ |
30 | static int __initdata pci_mmcfg_resources_inserted; | 26 | static int __initdata pci_mmcfg_resources_inserted; |
31 | 27 | ||
32 | static __init int extend_mmcfg(int num) | 28 | LIST_HEAD(pci_mmcfg_list); |
29 | |||
30 | static __init void pci_mmconfig_remove(struct pci_mmcfg_region *cfg) | ||
33 | { | 31 | { |
34 | struct acpi_mcfg_allocation *new; | 32 | if (cfg->res.parent) |
35 | int new_num = pci_mmcfg_config_num + num; | 33 | release_resource(&cfg->res); |
34 | list_del(&cfg->list); | ||
35 | kfree(cfg); | ||
36 | } | ||
36 | 37 | ||
37 | new = kzalloc(sizeof(pci_mmcfg_config[0]) * new_num, GFP_KERNEL); | 38 | static __init void free_all_mmcfg(void) |
38 | if (!new) | 39 | { |
39 | return -1; | 40 | struct pci_mmcfg_region *cfg, *tmp; |
40 | 41 | ||
41 | if (pci_mmcfg_config) { | 42 | pci_mmcfg_arch_free(); |
42 | memcpy(new, pci_mmcfg_config, | 43 | list_for_each_entry_safe(cfg, tmp, &pci_mmcfg_list, list) |
43 | sizeof(pci_mmcfg_config[0]) * new_num); | 44 | pci_mmconfig_remove(cfg); |
44 | kfree(pci_mmcfg_config); | 45 | } |
46 | |||
47 | static __init void list_add_sorted(struct pci_mmcfg_region *new) | ||
48 | { | ||
49 | struct pci_mmcfg_region *cfg; | ||
50 | |||
51 | /* keep list sorted by segment and starting bus number */ | ||
52 | list_for_each_entry(cfg, &pci_mmcfg_list, list) { | ||
53 | if (cfg->segment > new->segment || | ||
54 | (cfg->segment == new->segment && | ||
55 | cfg->start_bus >= new->start_bus)) { | ||
56 | list_add_tail(&new->list, &cfg->list); | ||
57 | return; | ||
58 | } | ||
45 | } | 59 | } |
46 | pci_mmcfg_config = new; | 60 | list_add_tail(&new->list, &pci_mmcfg_list); |
61 | } | ||
47 | 62 | ||
48 | return 0; | 63 | static __init struct pci_mmcfg_region *pci_mmconfig_add(int segment, int start, |
64 | int end, u64 addr) | ||
65 | { | ||
66 | struct pci_mmcfg_region *new; | ||
67 | int num_buses; | ||
68 | struct resource *res; | ||
69 | |||
70 | if (addr == 0) | ||
71 | return NULL; | ||
72 | |||
73 | new = kzalloc(sizeof(*new), GFP_KERNEL); | ||
74 | if (!new) | ||
75 | return NULL; | ||
76 | |||
77 | new->address = addr; | ||
78 | new->segment = segment; | ||
79 | new->start_bus = start; | ||
80 | new->end_bus = end; | ||
81 | |||
82 | list_add_sorted(new); | ||
83 | |||
84 | num_buses = end - start + 1; | ||
85 | res = &new->res; | ||
86 | res->start = addr + PCI_MMCFG_BUS_OFFSET(start); | ||
87 | res->end = addr + PCI_MMCFG_BUS_OFFSET(num_buses) - 1; | ||
88 | res->flags = IORESOURCE_MEM | IORESOURCE_BUSY; | ||
89 | snprintf(new->name, PCI_MMCFG_RESOURCE_NAME_LEN, | ||
90 | "PCI MMCONFIG %04x [bus %02x-%02x]", segment, start, end); | ||
91 | res->name = new->name; | ||
92 | |||
93 | printk(KERN_INFO PREFIX "MMCONFIG for domain %04x [bus %02x-%02x] at " | ||
94 | "%pR (base %#lx)\n", segment, start, end, &new->res, | ||
95 | (unsigned long) addr); | ||
96 | |||
97 | return new; | ||
49 | } | 98 | } |
50 | 99 | ||
51 | static __init void fill_one_mmcfg(u64 addr, int segment, int start, int end) | 100 | struct pci_mmcfg_region *pci_mmconfig_lookup(int segment, int bus) |
52 | { | 101 | { |
53 | int i = pci_mmcfg_config_num; | 102 | struct pci_mmcfg_region *cfg; |
54 | 103 | ||
55 | pci_mmcfg_config_num++; | 104 | list_for_each_entry(cfg, &pci_mmcfg_list, list) |
56 | pci_mmcfg_config[i].address = addr; | 105 | if (cfg->segment == segment && |
57 | pci_mmcfg_config[i].pci_segment = segment; | 106 | cfg->start_bus <= bus && bus <= cfg->end_bus) |
58 | pci_mmcfg_config[i].start_bus_number = start; | 107 | return cfg; |
59 | pci_mmcfg_config[i].end_bus_number = end; | 108 | |
109 | return NULL; | ||
60 | } | 110 | } |
61 | 111 | ||
62 | static const char __init *pci_mmcfg_e7520(void) | 112 | static const char __init *pci_mmcfg_e7520(void) |
@@ -68,11 +118,9 @@ static const char __init *pci_mmcfg_e7520(void) | |||
68 | if (win == 0x0000 || win == 0xf000) | 118 | if (win == 0x0000 || win == 0xf000) |
69 | return NULL; | 119 | return NULL; |
70 | 120 | ||
71 | if (extend_mmcfg(1) == -1) | 121 | if (pci_mmconfig_add(0, 0, 255, win << 16) == NULL) |
72 | return NULL; | 122 | return NULL; |
73 | 123 | ||
74 | fill_one_mmcfg(win << 16, 0, 0, 255); | ||
75 | |||
76 | return "Intel Corporation E7520 Memory Controller Hub"; | 124 | return "Intel Corporation E7520 Memory Controller Hub"; |
77 | } | 125 | } |
78 | 126 | ||
@@ -114,11 +162,9 @@ static const char __init *pci_mmcfg_intel_945(void) | |||
114 | if ((pciexbar & mask) >= 0xf0000000U) | 162 | if ((pciexbar & mask) >= 0xf0000000U) |
115 | return NULL; | 163 | return NULL; |
116 | 164 | ||
117 | if (extend_mmcfg(1) == -1) | 165 | if (pci_mmconfig_add(0, 0, (len >> 20) - 1, pciexbar & mask) == NULL) |
118 | return NULL; | 166 | return NULL; |
119 | 167 | ||
120 | fill_one_mmcfg(pciexbar & mask, 0, 0, (len >> 20) - 1); | ||
121 | |||
122 | return "Intel Corporation 945G/GZ/P/PL Express Memory Controller Hub"; | 168 | return "Intel Corporation 945G/GZ/P/PL Express Memory Controller Hub"; |
123 | } | 169 | } |
124 | 170 | ||
@@ -127,7 +173,7 @@ static const char __init *pci_mmcfg_amd_fam10h(void) | |||
127 | u32 low, high, address; | 173 | u32 low, high, address; |
128 | u64 base, msr; | 174 | u64 base, msr; |
129 | int i; | 175 | int i; |
130 | unsigned segnbits = 0, busnbits; | 176 | unsigned segnbits = 0, busnbits, end_bus; |
131 | 177 | ||
132 | if (!(pci_probe & PCI_CHECK_ENABLE_AMD_MMCONF)) | 178 | if (!(pci_probe & PCI_CHECK_ENABLE_AMD_MMCONF)) |
133 | return NULL; | 179 | return NULL; |
@@ -161,11 +207,13 @@ static const char __init *pci_mmcfg_amd_fam10h(void) | |||
161 | busnbits = 8; | 207 | busnbits = 8; |
162 | } | 208 | } |
163 | 209 | ||
164 | if (extend_mmcfg(1 << segnbits) == -1) | 210 | end_bus = (1 << busnbits) - 1; |
165 | return NULL; | ||
166 | |||
167 | for (i = 0; i < (1 << segnbits); i++) | 211 | for (i = 0; i < (1 << segnbits); i++) |
168 | fill_one_mmcfg(base + (1<<28) * i, i, 0, (1 << busnbits) - 1); | 212 | if (pci_mmconfig_add(i, 0, end_bus, |
213 | base + (1<<28) * i) == NULL) { | ||
214 | free_all_mmcfg(); | ||
215 | return NULL; | ||
216 | } | ||
169 | 217 | ||
170 | return "AMD Family 10h NB"; | 218 | return "AMD Family 10h NB"; |
171 | } | 219 | } |
@@ -190,7 +238,7 @@ static const char __init *pci_mmcfg_nvidia_mcp55(void) | |||
190 | /* | 238 | /* |
191 | * do check if amd fam10h already took over | 239 | * do check if amd fam10h already took over |
192 | */ | 240 | */ |
193 | if (!acpi_disabled || pci_mmcfg_config_num || mcp55_checked) | 241 | if (!acpi_disabled || !list_empty(&pci_mmcfg_list) || mcp55_checked) |
194 | return NULL; | 242 | return NULL; |
195 | 243 | ||
196 | mcp55_checked = true; | 244 | mcp55_checked = true; |
@@ -213,16 +261,14 @@ static const char __init *pci_mmcfg_nvidia_mcp55(void) | |||
213 | if (!(extcfg & extcfg_enable_mask)) | 261 | if (!(extcfg & extcfg_enable_mask)) |
214 | continue; | 262 | continue; |
215 | 263 | ||
216 | if (extend_mmcfg(1) == -1) | ||
217 | continue; | ||
218 | |||
219 | size_index = (extcfg & extcfg_size_mask) >> extcfg_size_shift; | 264 | size_index = (extcfg & extcfg_size_mask) >> extcfg_size_shift; |
220 | base = extcfg & extcfg_base_mask[size_index]; | 265 | base = extcfg & extcfg_base_mask[size_index]; |
221 | /* base could > 4G */ | 266 | /* base could > 4G */ |
222 | base <<= extcfg_base_lshift; | 267 | base <<= extcfg_base_lshift; |
223 | start = (extcfg & extcfg_start_mask) >> extcfg_start_shift; | 268 | start = (extcfg & extcfg_start_mask) >> extcfg_start_shift; |
224 | end = start + extcfg_sizebus[size_index] - 1; | 269 | end = start + extcfg_sizebus[size_index] - 1; |
225 | fill_one_mmcfg(base, 0, start, end); | 270 | if (pci_mmconfig_add(0, start, end, base) == NULL) |
271 | continue; | ||
226 | mcp55_mmconf_found++; | 272 | mcp55_mmconf_found++; |
227 | } | 273 | } |
228 | 274 | ||
@@ -253,45 +299,27 @@ static struct pci_mmcfg_hostbridge_probe pci_mmcfg_probes[] __initdata = { | |||
253 | 0x0369, pci_mmcfg_nvidia_mcp55 }, | 299 | 0x0369, pci_mmcfg_nvidia_mcp55 }, |
254 | }; | 300 | }; |
255 | 301 | ||
256 | static int __init cmp_mmcfg(const void *x1, const void *x2) | ||
257 | { | ||
258 | const typeof(pci_mmcfg_config[0]) *m1 = x1; | ||
259 | const typeof(pci_mmcfg_config[0]) *m2 = x2; | ||
260 | int start1, start2; | ||
261 | |||
262 | start1 = m1->start_bus_number; | ||
263 | start2 = m2->start_bus_number; | ||
264 | |||
265 | return start1 - start2; | ||
266 | } | ||
267 | |||
268 | static void __init pci_mmcfg_check_end_bus_number(void) | 302 | static void __init pci_mmcfg_check_end_bus_number(void) |
269 | { | 303 | { |
270 | int i; | 304 | struct pci_mmcfg_region *cfg, *cfgx; |
271 | typeof(pci_mmcfg_config[0]) *cfg, *cfgx; | ||
272 | |||
273 | /* sort them at first */ | ||
274 | sort(pci_mmcfg_config, pci_mmcfg_config_num, | ||
275 | sizeof(pci_mmcfg_config[0]), cmp_mmcfg, NULL); | ||
276 | 305 | ||
277 | /* last one*/ | 306 | /* last one*/ |
278 | if (pci_mmcfg_config_num > 0) { | 307 | cfg = list_entry(pci_mmcfg_list.prev, typeof(*cfg), list); |
279 | i = pci_mmcfg_config_num - 1; | 308 | if (cfg) |
280 | cfg = &pci_mmcfg_config[i]; | 309 | if (cfg->end_bus < cfg->start_bus) |
281 | if (cfg->end_bus_number < cfg->start_bus_number) | 310 | cfg->end_bus = 255; |
282 | cfg->end_bus_number = 255; | ||
283 | } | ||
284 | 311 | ||
285 | /* don't overlap please */ | 312 | if (list_is_singular(&pci_mmcfg_list)) |
286 | for (i = 0; i < pci_mmcfg_config_num - 1; i++) { | 313 | return; |
287 | cfg = &pci_mmcfg_config[i]; | ||
288 | cfgx = &pci_mmcfg_config[i+1]; | ||
289 | 314 | ||
290 | if (cfg->end_bus_number < cfg->start_bus_number) | 315 | /* don't overlap please */ |
291 | cfg->end_bus_number = 255; | 316 | list_for_each_entry(cfg, &pci_mmcfg_list, list) { |
317 | if (cfg->end_bus < cfg->start_bus) | ||
318 | cfg->end_bus = 255; | ||
292 | 319 | ||
293 | if (cfg->end_bus_number >= cfgx->start_bus_number) | 320 | cfgx = list_entry(cfg->list.next, typeof(*cfg), list); |
294 | cfg->end_bus_number = cfgx->start_bus_number - 1; | 321 | if (cfg != cfgx && cfg->end_bus >= cfgx->start_bus) |
322 | cfg->end_bus = cfgx->start_bus - 1; | ||
295 | } | 323 | } |
296 | } | 324 | } |
297 | 325 | ||
@@ -306,8 +334,7 @@ static int __init pci_mmcfg_check_hostbridge(void) | |||
306 | if (!raw_pci_ops) | 334 | if (!raw_pci_ops) |
307 | return 0; | 335 | return 0; |
308 | 336 | ||
309 | pci_mmcfg_config_num = 0; | 337 | free_all_mmcfg(); |
310 | pci_mmcfg_config = NULL; | ||
311 | 338 | ||
312 | for (i = 0; i < ARRAY_SIZE(pci_mmcfg_probes); i++) { | 339 | for (i = 0; i < ARRAY_SIZE(pci_mmcfg_probes); i++) { |
313 | bus = pci_mmcfg_probes[i].bus; | 340 | bus = pci_mmcfg_probes[i].bus; |
@@ -322,45 +349,22 @@ static int __init pci_mmcfg_check_hostbridge(void) | |||
322 | name = pci_mmcfg_probes[i].probe(); | 349 | name = pci_mmcfg_probes[i].probe(); |
323 | 350 | ||
324 | if (name) | 351 | if (name) |
325 | printk(KERN_INFO "PCI: Found %s with MMCONFIG support.\n", | 352 | printk(KERN_INFO PREFIX "%s with MMCONFIG support\n", |
326 | name); | 353 | name); |
327 | } | 354 | } |
328 | 355 | ||
329 | /* some end_bus_number is crazy, fix it */ | 356 | /* some end_bus_number is crazy, fix it */ |
330 | pci_mmcfg_check_end_bus_number(); | 357 | pci_mmcfg_check_end_bus_number(); |
331 | 358 | ||
332 | return pci_mmcfg_config_num != 0; | 359 | return !list_empty(&pci_mmcfg_list); |
333 | } | 360 | } |
334 | 361 | ||
335 | static void __init pci_mmcfg_insert_resources(void) | 362 | static void __init pci_mmcfg_insert_resources(void) |
336 | { | 363 | { |
337 | #define PCI_MMCFG_RESOURCE_NAME_LEN 24 | 364 | struct pci_mmcfg_region *cfg; |
338 | int i; | ||
339 | struct resource *res; | ||
340 | char *names; | ||
341 | unsigned num_buses; | ||
342 | |||
343 | res = kcalloc(PCI_MMCFG_RESOURCE_NAME_LEN + sizeof(*res), | ||
344 | pci_mmcfg_config_num, GFP_KERNEL); | ||
345 | if (!res) { | ||
346 | printk(KERN_ERR "PCI: Unable to allocate MMCONFIG resources\n"); | ||
347 | return; | ||
348 | } | ||
349 | 365 | ||
350 | names = (void *)&res[pci_mmcfg_config_num]; | 366 | list_for_each_entry(cfg, &pci_mmcfg_list, list) |
351 | for (i = 0; i < pci_mmcfg_config_num; i++, res++) { | 367 | insert_resource(&iomem_resource, &cfg->res); |
352 | struct acpi_mcfg_allocation *cfg = &pci_mmcfg_config[i]; | ||
353 | num_buses = cfg->end_bus_number - cfg->start_bus_number + 1; | ||
354 | res->name = names; | ||
355 | snprintf(names, PCI_MMCFG_RESOURCE_NAME_LEN, | ||
356 | "PCI MMCONFIG %u [%02x-%02x]", cfg->pci_segment, | ||
357 | cfg->start_bus_number, cfg->end_bus_number); | ||
358 | res->start = cfg->address + (cfg->start_bus_number << 20); | ||
359 | res->end = res->start + (num_buses << 20) - 1; | ||
360 | res->flags = IORESOURCE_MEM | IORESOURCE_BUSY; | ||
361 | insert_resource(&iomem_resource, res); | ||
362 | names += PCI_MMCFG_RESOURCE_NAME_LEN; | ||
363 | } | ||
364 | 368 | ||
365 | /* Mark that the resources have been inserted. */ | 369 | /* Mark that the resources have been inserted. */ |
366 | pci_mmcfg_resources_inserted = 1; | 370 | pci_mmcfg_resources_inserted = 1; |
@@ -437,11 +441,12 @@ static int __init is_acpi_reserved(u64 start, u64 end, unsigned not_used) | |||
437 | typedef int (*check_reserved_t)(u64 start, u64 end, unsigned type); | 441 | typedef int (*check_reserved_t)(u64 start, u64 end, unsigned type); |
438 | 442 | ||
439 | static int __init is_mmconf_reserved(check_reserved_t is_reserved, | 443 | static int __init is_mmconf_reserved(check_reserved_t is_reserved, |
440 | u64 addr, u64 size, int i, | 444 | struct pci_mmcfg_region *cfg, int with_e820) |
441 | typeof(pci_mmcfg_config[0]) *cfg, int with_e820) | ||
442 | { | 445 | { |
446 | u64 addr = cfg->res.start; | ||
447 | u64 size = resource_size(&cfg->res); | ||
443 | u64 old_size = size; | 448 | u64 old_size = size; |
444 | int valid = 0; | 449 | int valid = 0, num_buses; |
445 | 450 | ||
446 | while (!is_reserved(addr, addr + size, E820_RESERVED)) { | 451 | while (!is_reserved(addr, addr + size, E820_RESERVED)) { |
447 | size >>= 1; | 452 | size >>= 1; |
@@ -450,19 +455,25 @@ static int __init is_mmconf_reserved(check_reserved_t is_reserved, | |||
450 | } | 455 | } |
451 | 456 | ||
452 | if (size >= (16UL<<20) || size == old_size) { | 457 | if (size >= (16UL<<20) || size == old_size) { |
453 | printk(KERN_NOTICE | 458 | printk(KERN_INFO PREFIX "MMCONFIG at %pR reserved in %s\n", |
454 | "PCI: MCFG area at %Lx reserved in %s\n", | 459 | &cfg->res, |
455 | addr, with_e820?"E820":"ACPI motherboard resources"); | 460 | with_e820 ? "E820" : "ACPI motherboard resources"); |
456 | valid = 1; | 461 | valid = 1; |
457 | 462 | ||
458 | if (old_size != size) { | 463 | if (old_size != size) { |
459 | /* update end_bus_number */ | 464 | /* update end_bus */ |
460 | cfg->end_bus_number = cfg->start_bus_number + ((size>>20) - 1); | 465 | cfg->end_bus = cfg->start_bus + ((size>>20) - 1); |
461 | printk(KERN_NOTICE "PCI: updated MCFG configuration %d: base %lx " | 466 | num_buses = cfg->end_bus - cfg->start_bus + 1; |
462 | "segment %hu buses %u - %u\n", | 467 | cfg->res.end = cfg->res.start + |
463 | i, (unsigned long)cfg->address, cfg->pci_segment, | 468 | PCI_MMCFG_BUS_OFFSET(num_buses) - 1; |
464 | (unsigned int)cfg->start_bus_number, | 469 | snprintf(cfg->name, PCI_MMCFG_RESOURCE_NAME_LEN, |
465 | (unsigned int)cfg->end_bus_number); | 470 | "PCI MMCONFIG %04x [bus %02x-%02x]", |
471 | cfg->segment, cfg->start_bus, cfg->end_bus); | ||
472 | printk(KERN_INFO PREFIX | ||
473 | "MMCONFIG for %04x [bus%02x-%02x] " | ||
474 | "at %pR (base %#lx) (size reduced!)\n", | ||
475 | cfg->segment, cfg->start_bus, cfg->end_bus, | ||
476 | &cfg->res, (unsigned long) cfg->address); | ||
466 | } | 477 | } |
467 | } | 478 | } |
468 | 479 | ||
@@ -471,45 +482,26 @@ static int __init is_mmconf_reserved(check_reserved_t is_reserved, | |||
471 | 482 | ||
472 | static void __init pci_mmcfg_reject_broken(int early) | 483 | static void __init pci_mmcfg_reject_broken(int early) |
473 | { | 484 | { |
474 | typeof(pci_mmcfg_config[0]) *cfg; | 485 | struct pci_mmcfg_region *cfg; |
475 | int i; | ||
476 | 486 | ||
477 | if ((pci_mmcfg_config_num == 0) || | 487 | list_for_each_entry(cfg, &pci_mmcfg_list, list) { |
478 | (pci_mmcfg_config == NULL) || | ||
479 | (pci_mmcfg_config[0].address == 0)) | ||
480 | return; | ||
481 | |||
482 | for (i = 0; i < pci_mmcfg_config_num; i++) { | ||
483 | int valid = 0; | 488 | int valid = 0; |
484 | u64 addr, size; | ||
485 | |||
486 | cfg = &pci_mmcfg_config[i]; | ||
487 | addr = cfg->start_bus_number; | ||
488 | addr <<= 20; | ||
489 | addr += cfg->address; | ||
490 | size = cfg->end_bus_number + 1 - cfg->start_bus_number; | ||
491 | size <<= 20; | ||
492 | printk(KERN_NOTICE "PCI: MCFG configuration %d: base %lx " | ||
493 | "segment %hu buses %u - %u\n", | ||
494 | i, (unsigned long)cfg->address, cfg->pci_segment, | ||
495 | (unsigned int)cfg->start_bus_number, | ||
496 | (unsigned int)cfg->end_bus_number); | ||
497 | 489 | ||
498 | if (!early && !acpi_disabled) | 490 | if (!early && !acpi_disabled) |
499 | valid = is_mmconf_reserved(is_acpi_reserved, addr, size, i, cfg, 0); | 491 | valid = is_mmconf_reserved(is_acpi_reserved, cfg, 0); |
500 | 492 | ||
501 | if (valid) | 493 | if (valid) |
502 | continue; | 494 | continue; |
503 | 495 | ||
504 | if (!early) | 496 | if (!early) |
505 | printk(KERN_ERR "PCI: BIOS Bug: MCFG area at %Lx is not" | 497 | printk(KERN_ERR FW_BUG PREFIX |
506 | " reserved in ACPI motherboard resources\n", | 498 | "MMCONFIG at %pR not reserved in " |
507 | cfg->address); | 499 | "ACPI motherboard resources\n", &cfg->res); |
508 | 500 | ||
509 | /* Don't try to do this check unless configuration | 501 | /* Don't try to do this check unless configuration |
510 | type 1 is available. how about type 2 ?*/ | 502 | type 1 is available. how about type 2 ?*/ |
511 | if (raw_pci_ops) | 503 | if (raw_pci_ops) |
512 | valid = is_mmconf_reserved(e820_all_mapped, addr, size, i, cfg, 1); | 504 | valid = is_mmconf_reserved(e820_all_mapped, cfg, 1); |
513 | 505 | ||
514 | if (!valid) | 506 | if (!valid) |
515 | goto reject; | 507 | goto reject; |
@@ -518,34 +510,41 @@ static void __init pci_mmcfg_reject_broken(int early) | |||
518 | return; | 510 | return; |
519 | 511 | ||
520 | reject: | 512 | reject: |
521 | printk(KERN_INFO "PCI: Not using MMCONFIG.\n"); | 513 | printk(KERN_INFO PREFIX "not using MMCONFIG\n"); |
522 | pci_mmcfg_arch_free(); | 514 | free_all_mmcfg(); |
523 | kfree(pci_mmcfg_config); | ||
524 | pci_mmcfg_config = NULL; | ||
525 | pci_mmcfg_config_num = 0; | ||
526 | } | 515 | } |
527 | 516 | ||
528 | static int __initdata known_bridge; | 517 | static int __initdata known_bridge; |
529 | 518 | ||
530 | static int acpi_mcfg_64bit_base_addr __initdata = FALSE; | 519 | static int __init acpi_mcfg_check_entry(struct acpi_table_mcfg *mcfg, |
520 | struct acpi_mcfg_allocation *cfg) | ||
521 | { | ||
522 | int year; | ||
531 | 523 | ||
532 | /* The physical address of the MMCONFIG aperture. Set from ACPI tables. */ | 524 | if (cfg->address < 0xFFFFFFFF) |
533 | struct acpi_mcfg_allocation *pci_mmcfg_config; | 525 | return 0; |
534 | int pci_mmcfg_config_num; | ||
535 | 526 | ||
536 | static int __init acpi_mcfg_oem_check(struct acpi_table_mcfg *mcfg) | ||
537 | { | ||
538 | if (!strcmp(mcfg->header.oem_id, "SGI")) | 527 | if (!strcmp(mcfg->header.oem_id, "SGI")) |
539 | acpi_mcfg_64bit_base_addr = TRUE; | 528 | return 0; |
540 | 529 | ||
541 | return 0; | 530 | if (mcfg->header.revision >= 1) { |
531 | if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && | ||
532 | year >= 2010) | ||
533 | return 0; | ||
534 | } | ||
535 | |||
536 | printk(KERN_ERR PREFIX "MCFG region for %04x [bus %02x-%02x] at %#llx " | ||
537 | "is above 4GB, ignored\n", cfg->pci_segment, | ||
538 | cfg->start_bus_number, cfg->end_bus_number, cfg->address); | ||
539 | return -EINVAL; | ||
542 | } | 540 | } |
543 | 541 | ||
544 | static int __init pci_parse_mcfg(struct acpi_table_header *header) | 542 | static int __init pci_parse_mcfg(struct acpi_table_header *header) |
545 | { | 543 | { |
546 | struct acpi_table_mcfg *mcfg; | 544 | struct acpi_table_mcfg *mcfg; |
545 | struct acpi_mcfg_allocation *cfg_table, *cfg; | ||
547 | unsigned long i; | 546 | unsigned long i; |
548 | int config_size; | 547 | int entries; |
549 | 548 | ||
550 | if (!header) | 549 | if (!header) |
551 | return -EINVAL; | 550 | return -EINVAL; |
@@ -553,38 +552,33 @@ static int __init pci_parse_mcfg(struct acpi_table_header *header) | |||
553 | mcfg = (struct acpi_table_mcfg *)header; | 552 | mcfg = (struct acpi_table_mcfg *)header; |
554 | 553 | ||
555 | /* how many config structures do we have */ | 554 | /* how many config structures do we have */ |
556 | pci_mmcfg_config_num = 0; | 555 | free_all_mmcfg(); |
556 | entries = 0; | ||
557 | i = header->length - sizeof(struct acpi_table_mcfg); | 557 | i = header->length - sizeof(struct acpi_table_mcfg); |
558 | while (i >= sizeof(struct acpi_mcfg_allocation)) { | 558 | while (i >= sizeof(struct acpi_mcfg_allocation)) { |
559 | ++pci_mmcfg_config_num; | 559 | entries++; |
560 | i -= sizeof(struct acpi_mcfg_allocation); | 560 | i -= sizeof(struct acpi_mcfg_allocation); |
561 | }; | 561 | }; |
562 | if (pci_mmcfg_config_num == 0) { | 562 | if (entries == 0) { |
563 | printk(KERN_ERR PREFIX "MMCONFIG has no entries\n"); | 563 | printk(KERN_ERR PREFIX "MMCONFIG has no entries\n"); |
564 | return -ENODEV; | 564 | return -ENODEV; |
565 | } | 565 | } |
566 | 566 | ||
567 | config_size = pci_mmcfg_config_num * sizeof(*pci_mmcfg_config); | 567 | cfg_table = (struct acpi_mcfg_allocation *) &mcfg[1]; |
568 | pci_mmcfg_config = kmalloc(config_size, GFP_KERNEL); | 568 | for (i = 0; i < entries; i++) { |
569 | if (!pci_mmcfg_config) { | 569 | cfg = &cfg_table[i]; |
570 | printk(KERN_WARNING PREFIX | 570 | if (acpi_mcfg_check_entry(mcfg, cfg)) { |
571 | "No memory for MCFG config tables\n"); | 571 | free_all_mmcfg(); |
572 | return -ENOMEM; | ||
573 | } | ||
574 | |||
575 | memcpy(pci_mmcfg_config, &mcfg[1], config_size); | ||
576 | |||
577 | acpi_mcfg_oem_check(mcfg); | ||
578 | |||
579 | for (i = 0; i < pci_mmcfg_config_num; ++i) { | ||
580 | if ((pci_mmcfg_config[i].address > 0xFFFFFFFF) && | ||
581 | !acpi_mcfg_64bit_base_addr) { | ||
582 | printk(KERN_ERR PREFIX | ||
583 | "MMCONFIG not in low 4GB of memory\n"); | ||
584 | kfree(pci_mmcfg_config); | ||
585 | pci_mmcfg_config_num = 0; | ||
586 | return -ENODEV; | 572 | return -ENODEV; |
587 | } | 573 | } |
574 | |||
575 | if (pci_mmconfig_add(cfg->pci_segment, cfg->start_bus_number, | ||
576 | cfg->end_bus_number, cfg->address) == NULL) { | ||
577 | printk(KERN_WARNING PREFIX | ||
578 | "no memory for MCFG entries\n"); | ||
579 | free_all_mmcfg(); | ||
580 | return -ENOMEM; | ||
581 | } | ||
588 | } | 582 | } |
589 | 583 | ||
590 | return 0; | 584 | return 0; |
@@ -614,9 +608,7 @@ static void __init __pci_mmcfg_init(int early) | |||
614 | 608 | ||
615 | pci_mmcfg_reject_broken(early); | 609 | pci_mmcfg_reject_broken(early); |
616 | 610 | ||
617 | if ((pci_mmcfg_config_num == 0) || | 611 | if (list_empty(&pci_mmcfg_list)) |
618 | (pci_mmcfg_config == NULL) || | ||
619 | (pci_mmcfg_config[0].address == 0)) | ||
620 | return; | 612 | return; |
621 | 613 | ||
622 | if (pci_mmcfg_arch_init()) | 614 | if (pci_mmcfg_arch_init()) |
@@ -648,9 +640,7 @@ static int __init pci_mmcfg_late_insert_resources(void) | |||
648 | */ | 640 | */ |
649 | if ((pci_mmcfg_resources_inserted == 1) || | 641 | if ((pci_mmcfg_resources_inserted == 1) || |
650 | (pci_probe & PCI_PROBE_MMCONF) == 0 || | 642 | (pci_probe & PCI_PROBE_MMCONF) == 0 || |
651 | (pci_mmcfg_config_num == 0) || | 643 | list_empty(&pci_mmcfg_list)) |
652 | (pci_mmcfg_config == NULL) || | ||
653 | (pci_mmcfg_config[0].address == 0)) | ||
654 | return 1; | 644 | return 1; |
655 | 645 | ||
656 | /* | 646 | /* |
diff --git a/arch/x86/pci/mmconfig_32.c b/arch/x86/pci/mmconfig_32.c index f10a7e94a84c..90d5fd476ed4 100644 --- a/arch/x86/pci/mmconfig_32.c +++ b/arch/x86/pci/mmconfig_32.c | |||
@@ -27,18 +27,10 @@ static int mmcfg_last_accessed_cpu; | |||
27 | */ | 27 | */ |
28 | static u32 get_base_addr(unsigned int seg, int bus, unsigned devfn) | 28 | static u32 get_base_addr(unsigned int seg, int bus, unsigned devfn) |
29 | { | 29 | { |
30 | struct acpi_mcfg_allocation *cfg; | 30 | struct pci_mmcfg_region *cfg = pci_mmconfig_lookup(seg, bus); |
31 | int cfg_num; | ||
32 | |||
33 | for (cfg_num = 0; cfg_num < pci_mmcfg_config_num; cfg_num++) { | ||
34 | cfg = &pci_mmcfg_config[cfg_num]; | ||
35 | if (cfg->pci_segment == seg && | ||
36 | (cfg->start_bus_number <= bus) && | ||
37 | (cfg->end_bus_number >= bus)) | ||
38 | return cfg->address; | ||
39 | } | ||
40 | 31 | ||
41 | /* Fall back to type 0 */ | 32 | if (cfg) |
33 | return cfg->address; | ||
42 | return 0; | 34 | return 0; |
43 | } | 35 | } |
44 | 36 | ||
@@ -47,7 +39,7 @@ static u32 get_base_addr(unsigned int seg, int bus, unsigned devfn) | |||
47 | */ | 39 | */ |
48 | static void pci_exp_set_dev_base(unsigned int base, int bus, int devfn) | 40 | static void pci_exp_set_dev_base(unsigned int base, int bus, int devfn) |
49 | { | 41 | { |
50 | u32 dev_base = base | (bus << 20) | (devfn << 12); | 42 | u32 dev_base = base | PCI_MMCFG_BUS_OFFSET(bus) | (devfn << 12); |
51 | int cpu = smp_processor_id(); | 43 | int cpu = smp_processor_id(); |
52 | if (dev_base != mmcfg_last_accessed_device || | 44 | if (dev_base != mmcfg_last_accessed_device || |
53 | cpu != mmcfg_last_accessed_cpu) { | 45 | cpu != mmcfg_last_accessed_cpu) { |
diff --git a/arch/x86/pci/mmconfig_64.c b/arch/x86/pci/mmconfig_64.c index 94349f8b2f96..e783841bd1d7 100644 --- a/arch/x86/pci/mmconfig_64.c +++ b/arch/x86/pci/mmconfig_64.c | |||
@@ -12,38 +12,15 @@ | |||
12 | #include <asm/e820.h> | 12 | #include <asm/e820.h> |
13 | #include <asm/pci_x86.h> | 13 | #include <asm/pci_x86.h> |
14 | 14 | ||
15 | /* Static virtual mapping of the MMCONFIG aperture */ | 15 | #define PREFIX "PCI: " |
16 | struct mmcfg_virt { | ||
17 | struct acpi_mcfg_allocation *cfg; | ||
18 | char __iomem *virt; | ||
19 | }; | ||
20 | static struct mmcfg_virt *pci_mmcfg_virt; | ||
21 | |||
22 | static char __iomem *get_virt(unsigned int seg, unsigned bus) | ||
23 | { | ||
24 | struct acpi_mcfg_allocation *cfg; | ||
25 | int cfg_num; | ||
26 | |||
27 | for (cfg_num = 0; cfg_num < pci_mmcfg_config_num; cfg_num++) { | ||
28 | cfg = pci_mmcfg_virt[cfg_num].cfg; | ||
29 | if (cfg->pci_segment == seg && | ||
30 | (cfg->start_bus_number <= bus) && | ||
31 | (cfg->end_bus_number >= bus)) | ||
32 | return pci_mmcfg_virt[cfg_num].virt; | ||
33 | } | ||
34 | |||
35 | /* Fall back to type 0 */ | ||
36 | return NULL; | ||
37 | } | ||
38 | 16 | ||
39 | static char __iomem *pci_dev_base(unsigned int seg, unsigned int bus, unsigned int devfn) | 17 | static char __iomem *pci_dev_base(unsigned int seg, unsigned int bus, unsigned int devfn) |
40 | { | 18 | { |
41 | char __iomem *addr; | 19 | struct pci_mmcfg_region *cfg = pci_mmconfig_lookup(seg, bus); |
42 | 20 | ||
43 | addr = get_virt(seg, bus); | 21 | if (cfg && cfg->virt) |
44 | if (!addr) | 22 | return cfg->virt + (PCI_MMCFG_BUS_OFFSET(bus) | (devfn << 12)); |
45 | return NULL; | 23 | return NULL; |
46 | return addr + ((bus << 20) | (devfn << 12)); | ||
47 | } | 24 | } |
48 | 25 | ||
49 | static int pci_mmcfg_read(unsigned int seg, unsigned int bus, | 26 | static int pci_mmcfg_read(unsigned int seg, unsigned int bus, |
@@ -109,42 +86,30 @@ static struct pci_raw_ops pci_mmcfg = { | |||
109 | .write = pci_mmcfg_write, | 86 | .write = pci_mmcfg_write, |
110 | }; | 87 | }; |
111 | 88 | ||
112 | static void __iomem * __init mcfg_ioremap(struct acpi_mcfg_allocation *cfg) | 89 | static void __iomem * __init mcfg_ioremap(struct pci_mmcfg_region *cfg) |
113 | { | 90 | { |
114 | void __iomem *addr; | 91 | void __iomem *addr; |
115 | u64 start, size; | 92 | u64 start, size; |
93 | int num_buses; | ||
116 | 94 | ||
117 | start = cfg->start_bus_number; | 95 | start = cfg->address + PCI_MMCFG_BUS_OFFSET(cfg->start_bus); |
118 | start <<= 20; | 96 | num_buses = cfg->end_bus - cfg->start_bus + 1; |
119 | start += cfg->address; | 97 | size = PCI_MMCFG_BUS_OFFSET(num_buses); |
120 | size = cfg->end_bus_number + 1 - cfg->start_bus_number; | ||
121 | size <<= 20; | ||
122 | addr = ioremap_nocache(start, size); | 98 | addr = ioremap_nocache(start, size); |
123 | if (addr) { | 99 | if (addr) |
124 | printk(KERN_INFO "PCI: Using MMCONFIG at %Lx - %Lx\n", | 100 | addr -= PCI_MMCFG_BUS_OFFSET(cfg->start_bus); |
125 | start, start + size - 1); | ||
126 | addr -= cfg->start_bus_number << 20; | ||
127 | } | ||
128 | return addr; | 101 | return addr; |
129 | } | 102 | } |
130 | 103 | ||
131 | int __init pci_mmcfg_arch_init(void) | 104 | int __init pci_mmcfg_arch_init(void) |
132 | { | 105 | { |
133 | int i; | 106 | struct pci_mmcfg_region *cfg; |
134 | pci_mmcfg_virt = kzalloc(sizeof(*pci_mmcfg_virt) * | ||
135 | pci_mmcfg_config_num, GFP_KERNEL); | ||
136 | if (pci_mmcfg_virt == NULL) { | ||
137 | printk(KERN_ERR "PCI: Can not allocate memory for mmconfig structures\n"); | ||
138 | return 0; | ||
139 | } | ||
140 | 107 | ||
141 | for (i = 0; i < pci_mmcfg_config_num; ++i) { | 108 | list_for_each_entry(cfg, &pci_mmcfg_list, list) { |
142 | pci_mmcfg_virt[i].cfg = &pci_mmcfg_config[i]; | 109 | cfg->virt = mcfg_ioremap(cfg); |
143 | pci_mmcfg_virt[i].virt = mcfg_ioremap(&pci_mmcfg_config[i]); | 110 | if (!cfg->virt) { |
144 | if (!pci_mmcfg_virt[i].virt) { | 111 | printk(KERN_ERR PREFIX "can't map MMCONFIG at %pR\n", |
145 | printk(KERN_ERR "PCI: Cannot map mmconfig aperture for " | 112 | &cfg->res); |
146 | "segment %d\n", | ||
147 | pci_mmcfg_config[i].pci_segment); | ||
148 | pci_mmcfg_arch_free(); | 113 | pci_mmcfg_arch_free(); |
149 | return 0; | 114 | return 0; |
150 | } | 115 | } |
@@ -155,19 +120,12 @@ int __init pci_mmcfg_arch_init(void) | |||
155 | 120 | ||
156 | void __init pci_mmcfg_arch_free(void) | 121 | void __init pci_mmcfg_arch_free(void) |
157 | { | 122 | { |
158 | int i; | 123 | struct pci_mmcfg_region *cfg; |
159 | |||
160 | if (pci_mmcfg_virt == NULL) | ||
161 | return; | ||
162 | 124 | ||
163 | for (i = 0; i < pci_mmcfg_config_num; ++i) { | 125 | list_for_each_entry(cfg, &pci_mmcfg_list, list) { |
164 | if (pci_mmcfg_virt[i].virt) { | 126 | if (cfg->virt) { |
165 | iounmap(pci_mmcfg_virt[i].virt + (pci_mmcfg_virt[i].cfg->start_bus_number << 20)); | 127 | iounmap(cfg->virt + PCI_MMCFG_BUS_OFFSET(cfg->start_bus)); |
166 | pci_mmcfg_virt[i].virt = NULL; | 128 | cfg->virt = NULL; |
167 | pci_mmcfg_virt[i].cfg = NULL; | ||
168 | } | 129 | } |
169 | } | 130 | } |
170 | |||
171 | kfree(pci_mmcfg_virt); | ||
172 | pci_mmcfg_virt = NULL; | ||
173 | } | 131 | } |