]> git.openfabrics.org - ~shefty/rdma-dev.git/blob - arch/x86/pci/acpi.c
ACPI / x86: Add quirk for "CheckPoint P-20-00" to not use bridge _CRS_ info
[~shefty/rdma-dev.git] / arch / x86 / pci / acpi.c
1 #include <linux/pci.h>
2 #include <linux/acpi.h>
3 #include <linux/init.h>
4 #include <linux/irq.h>
5 #include <linux/dmi.h>
6 #include <linux/slab.h>
7 #include <asm/numa.h>
8 #include <asm/pci_x86.h>
9
10 struct pci_root_info {
11         struct acpi_device *bridge;
12         char name[16];
13         unsigned int res_num;
14         struct resource *res;
15         struct pci_sysdata sd;
16 #ifdef  CONFIG_PCI_MMCONFIG
17         bool mcfg_added;
18         u16 segment;
19         u8 start_bus;
20         u8 end_bus;
21 #endif
22 };
23
24 static bool pci_use_crs = true;
25
26 static int __init set_use_crs(const struct dmi_system_id *id)
27 {
28         pci_use_crs = true;
29         return 0;
30 }
31
32 static int __init set_nouse_crs(const struct dmi_system_id *id)
33 {
34         pci_use_crs = false;
35         return 0;
36 }
37
38 static const struct dmi_system_id pci_use_crs_table[] __initconst = {
39         /* http://bugzilla.kernel.org/show_bug.cgi?id=14183 */
40         {
41                 .callback = set_use_crs,
42                 .ident = "IBM System x3800",
43                 .matches = {
44                         DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
45                         DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
46                 },
47         },
48         /* https://bugzilla.kernel.org/show_bug.cgi?id=16007 */
49         /* 2006 AMD HT/VIA system with two host bridges */
50         {
51                 .callback = set_use_crs,
52                 .ident = "ASRock ALiveSATA2-GLAN",
53                 .matches = {
54                         DMI_MATCH(DMI_PRODUCT_NAME, "ALiveSATA2-GLAN"),
55                 },
56         },
57         /* https://bugzilla.kernel.org/show_bug.cgi?id=30552 */
58         /* 2006 AMD HT/VIA system with two host bridges */
59         {
60                 .callback = set_use_crs,
61                 .ident = "ASUS M2V-MX SE",
62                 .matches = {
63                         DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
64                         DMI_MATCH(DMI_BOARD_NAME, "M2V-MX SE"),
65                         DMI_MATCH(DMI_BIOS_VENDOR, "American Megatrends Inc."),
66                 },
67         },
68         /* https://bugzilla.kernel.org/show_bug.cgi?id=42619 */
69         {
70                 .callback = set_use_crs,
71                 .ident = "MSI MS-7253",
72                 .matches = {
73                         DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"),
74                         DMI_MATCH(DMI_BOARD_NAME, "MS-7253"),
75                         DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies, LTD"),
76                 },
77         },
78
79         /* Now for the blacklist.. */
80
81         /* https://bugzilla.redhat.com/show_bug.cgi?id=769657 */
82         {
83                 .callback = set_nouse_crs,
84                 .ident = "Dell Studio 1557",
85                 .matches = {
86                         DMI_MATCH(DMI_BOARD_VENDOR, "Dell Inc."),
87                         DMI_MATCH(DMI_PRODUCT_NAME, "Studio 1557"),
88                         DMI_MATCH(DMI_BIOS_VERSION, "A09"),
89                 },
90         },
91         /* https://bugzilla.redhat.com/show_bug.cgi?id=769657 */
92         {
93                 .callback = set_nouse_crs,
94                 .ident = "Thinkpad SL510",
95                 .matches = {
96                         DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"),
97                         DMI_MATCH(DMI_BOARD_NAME, "2847DFG"),
98                         DMI_MATCH(DMI_BIOS_VERSION, "6JET85WW (1.43 )"),
99                 },
100         },
101         /* https://bugzilla.kernel.org/show_bug.cgi?id=47981 */
102         {
103                 .callback = set_nouse_crs,
104                 .ident = "CheckPoint P-20-00",
105                 .matches = {
106                         DMI_MATCH(DMI_SYS_VENDOR, "CheckPoint"),
107                         DMI_MATCH(DMI_PRODUCT_NAME, "P-20-00"),
108                         DMI_MATCH(DMI_BOARD_NAME, "Bridgeport"),
109                 },
110         },
111         {}
112 };
113
114 void __init pci_acpi_crs_quirks(void)
115 {
116         int year;
117
118         if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year < 2008)
119                 pci_use_crs = false;
120
121         dmi_check_system(pci_use_crs_table);
122
123         /*
124          * If the user specifies "pci=use_crs" or "pci=nocrs" explicitly, that
125          * takes precedence over anything we figured out above.
126          */
127         if (pci_probe & PCI_ROOT_NO_CRS)
128                 pci_use_crs = false;
129         else if (pci_probe & PCI_USE__CRS)
130                 pci_use_crs = true;
131
132         printk(KERN_INFO "PCI: %s host bridge windows from ACPI; "
133                "if necessary, use \"pci=%s\" and report a bug\n",
134                pci_use_crs ? "Using" : "Ignoring",
135                pci_use_crs ? "nocrs" : "use_crs");
136 }
137
138 #ifdef  CONFIG_PCI_MMCONFIG
139 static int __devinit check_segment(u16 seg, struct device *dev, char *estr)
140 {
141         if (seg) {
142                 dev_err(dev,
143                         "%s can't access PCI configuration "
144                         "space under this host bridge.\n",
145                         estr);
146                 return -EIO;
147         }
148
149         /*
150          * Failure in adding MMCFG information is not fatal,
151          * just can't access extended configuration space of
152          * devices under this host bridge.
153          */
154         dev_warn(dev,
155                  "%s can't access extended PCI configuration "
156                  "space under this bridge.\n",
157                  estr);
158
159         return 0;
160 }
161
162 static int __devinit setup_mcfg_map(struct pci_root_info *info,
163                                     u16 seg, u8 start, u8 end,
164                                     phys_addr_t addr)
165 {
166         int result;
167         struct device *dev = &info->bridge->dev;
168
169         info->start_bus = start;
170         info->end_bus = end;
171         info->mcfg_added = false;
172
173         /* return success if MMCFG is not in use */
174         if (raw_pci_ext_ops && raw_pci_ext_ops != &pci_mmcfg)
175                 return 0;
176
177         if (!(pci_probe & PCI_PROBE_MMCONF))
178                 return check_segment(seg, dev, "MMCONFIG is disabled,");
179
180         result = pci_mmconfig_insert(dev, seg, start, end, addr);
181         if (result == 0) {
182                 /* enable MMCFG if it hasn't been enabled yet */
183                 if (raw_pci_ext_ops == NULL)
184                         raw_pci_ext_ops = &pci_mmcfg;
185                 info->mcfg_added = true;
186         } else if (result != -EEXIST)
187                 return check_segment(seg, dev,
188                          "fail to add MMCONFIG information,");
189
190         return 0;
191 }
192
193 static void teardown_mcfg_map(struct pci_root_info *info)
194 {
195         if (info->mcfg_added) {
196                 pci_mmconfig_delete(info->segment, info->start_bus,
197                                     info->end_bus);
198                 info->mcfg_added = false;
199         }
200 }
201 #else
202 static int __devinit setup_mcfg_map(struct pci_root_info *info,
203                                     u16 seg, u8 start, u8 end,
204                                     phys_addr_t addr)
205 {
206         return 0;
207 }
208 static void teardown_mcfg_map(struct pci_root_info *info)
209 {
210 }
211 #endif
212
213 static acpi_status
214 resource_to_addr(struct acpi_resource *resource,
215                         struct acpi_resource_address64 *addr)
216 {
217         acpi_status status;
218         struct acpi_resource_memory24 *memory24;
219         struct acpi_resource_memory32 *memory32;
220         struct acpi_resource_fixed_memory32 *fixed_memory32;
221
222         memset(addr, 0, sizeof(*addr));
223         switch (resource->type) {
224         case ACPI_RESOURCE_TYPE_MEMORY24:
225                 memory24 = &resource->data.memory24;
226                 addr->resource_type = ACPI_MEMORY_RANGE;
227                 addr->minimum = memory24->minimum;
228                 addr->address_length = memory24->address_length;
229                 addr->maximum = addr->minimum + addr->address_length - 1;
230                 return AE_OK;
231         case ACPI_RESOURCE_TYPE_MEMORY32:
232                 memory32 = &resource->data.memory32;
233                 addr->resource_type = ACPI_MEMORY_RANGE;
234                 addr->minimum = memory32->minimum;
235                 addr->address_length = memory32->address_length;
236                 addr->maximum = addr->minimum + addr->address_length - 1;
237                 return AE_OK;
238         case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
239                 fixed_memory32 = &resource->data.fixed_memory32;
240                 addr->resource_type = ACPI_MEMORY_RANGE;
241                 addr->minimum = fixed_memory32->address;
242                 addr->address_length = fixed_memory32->address_length;
243                 addr->maximum = addr->minimum + addr->address_length - 1;
244                 return AE_OK;
245         case ACPI_RESOURCE_TYPE_ADDRESS16:
246         case ACPI_RESOURCE_TYPE_ADDRESS32:
247         case ACPI_RESOURCE_TYPE_ADDRESS64:
248                 status = acpi_resource_to_address64(resource, addr);
249                 if (ACPI_SUCCESS(status) &&
250                     (addr->resource_type == ACPI_MEMORY_RANGE ||
251                     addr->resource_type == ACPI_IO_RANGE) &&
252                     addr->address_length > 0) {
253                         return AE_OK;
254                 }
255                 break;
256         }
257         return AE_ERROR;
258 }
259
260 static acpi_status
261 count_resource(struct acpi_resource *acpi_res, void *data)
262 {
263         struct pci_root_info *info = data;
264         struct acpi_resource_address64 addr;
265         acpi_status status;
266
267         status = resource_to_addr(acpi_res, &addr);
268         if (ACPI_SUCCESS(status))
269                 info->res_num++;
270         return AE_OK;
271 }
272
273 static acpi_status
274 setup_resource(struct acpi_resource *acpi_res, void *data)
275 {
276         struct pci_root_info *info = data;
277         struct resource *res;
278         struct acpi_resource_address64 addr;
279         acpi_status status;
280         unsigned long flags;
281         u64 start, orig_end, end;
282
283         status = resource_to_addr(acpi_res, &addr);
284         if (!ACPI_SUCCESS(status))
285                 return AE_OK;
286
287         if (addr.resource_type == ACPI_MEMORY_RANGE) {
288                 flags = IORESOURCE_MEM;
289                 if (addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY)
290                         flags |= IORESOURCE_PREFETCH;
291         } else if (addr.resource_type == ACPI_IO_RANGE) {
292                 flags = IORESOURCE_IO;
293         } else
294                 return AE_OK;
295
296         start = addr.minimum + addr.translation_offset;
297         orig_end = end = addr.maximum + addr.translation_offset;
298
299         /* Exclude non-addressable range or non-addressable portion of range */
300         end = min(end, (u64)iomem_resource.end);
301         if (end <= start) {
302                 dev_info(&info->bridge->dev,
303                         "host bridge window [%#llx-%#llx] "
304                         "(ignored, not CPU addressable)\n", start, orig_end);
305                 return AE_OK;
306         } else if (orig_end != end) {
307                 dev_info(&info->bridge->dev,
308                         "host bridge window [%#llx-%#llx] "
309                         "([%#llx-%#llx] ignored, not CPU addressable)\n", 
310                         start, orig_end, end + 1, orig_end);
311         }
312
313         res = &info->res[info->res_num];
314         res->name = info->name;
315         res->flags = flags;
316         res->start = start;
317         res->end = end;
318
319         if (!pci_use_crs) {
320                 dev_printk(KERN_DEBUG, &info->bridge->dev,
321                            "host bridge window %pR (ignored)\n", res);
322                 return AE_OK;
323         }
324
325         info->res_num++;
326
327         return AE_OK;
328 }
329
330 static void coalesce_windows(struct pci_root_info *info, unsigned long type)
331 {
332         int i, j;
333         struct resource *res1, *res2;
334
335         for (i = 0; i < info->res_num; i++) {
336                 res1 = &info->res[i];
337                 if (!(res1->flags & type))
338                         continue;
339
340                 for (j = i + 1; j < info->res_num; j++) {
341                         res2 = &info->res[j];
342                         if (!(res2->flags & type))
343                                 continue;
344
345                         /*
346                          * I don't like throwing away windows because then
347                          * our resources no longer match the ACPI _CRS, but
348                          * the kernel resource tree doesn't allow overlaps.
349                          */
350                         if (resource_overlaps(res1, res2)) {
351                                 res1->start = min(res1->start, res2->start);
352                                 res1->end = max(res1->end, res2->end);
353                                 dev_info(&info->bridge->dev,
354                                          "host bridge window expanded to %pR; %pR ignored\n",
355                                          res1, res2);
356                                 res2->flags = 0;
357                         }
358                 }
359         }
360 }
361
362 static void add_resources(struct pci_root_info *info,
363                           struct list_head *resources)
364 {
365         int i;
366         struct resource *res, *root, *conflict;
367
368         coalesce_windows(info, IORESOURCE_MEM);
369         coalesce_windows(info, IORESOURCE_IO);
370
371         for (i = 0; i < info->res_num; i++) {
372                 res = &info->res[i];
373
374                 if (res->flags & IORESOURCE_MEM)
375                         root = &iomem_resource;
376                 else if (res->flags & IORESOURCE_IO)
377                         root = &ioport_resource;
378                 else
379                         continue;
380
381                 conflict = insert_resource_conflict(root, res);
382                 if (conflict)
383                         dev_info(&info->bridge->dev,
384                                  "ignoring host bridge window %pR (conflicts with %s %pR)\n",
385                                  res, conflict->name, conflict);
386                 else
387                         pci_add_resource(resources, res);
388         }
389 }
390
391 static void free_pci_root_info_res(struct pci_root_info *info)
392 {
393         kfree(info->res);
394         info->res = NULL;
395         info->res_num = 0;
396 }
397
398 static void __release_pci_root_info(struct pci_root_info *info)
399 {
400         int i;
401         struct resource *res;
402
403         for (i = 0; i < info->res_num; i++) {
404                 res = &info->res[i];
405
406                 if (!res->parent)
407                         continue;
408
409                 if (!(res->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
410                         continue;
411
412                 release_resource(res);
413         }
414
415         free_pci_root_info_res(info);
416
417         teardown_mcfg_map(info);
418
419         kfree(info);
420 }
421
422 static void release_pci_root_info(struct pci_host_bridge *bridge)
423 {
424         struct pci_root_info *info = bridge->release_data;
425
426         __release_pci_root_info(info);
427 }
428
429 static void
430 probe_pci_root_info(struct pci_root_info *info, struct acpi_device *device,
431                     int busnum, int domain)
432 {
433         size_t size;
434
435         sprintf(info->name, "PCI Bus %04x:%02x", domain, busnum);
436         info->bridge = device;
437
438         info->res_num = 0;
439         acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_resource,
440                                 info);
441         if (!info->res_num)
442                 return;
443
444         size = sizeof(*info->res) * info->res_num;
445         info->res_num = 0;
446         info->res = kzalloc(size, GFP_KERNEL);
447         if (!info->res)
448                 return;
449
450         acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource,
451                                 info);
452 }
453
454 struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_pci_root *root)
455 {
456         struct acpi_device *device = root->device;
457         struct pci_root_info *info = NULL;
458         int domain = root->segment;
459         int busnum = root->secondary.start;
460         LIST_HEAD(resources);
461         struct pci_bus *bus = NULL;
462         struct pci_sysdata *sd;
463         int node;
464 #ifdef CONFIG_ACPI_NUMA
465         int pxm;
466 #endif
467
468         if (domain && !pci_domains_supported) {
469                 printk(KERN_WARNING "pci_bus %04x:%02x: "
470                        "ignored (multiple domains not supported)\n",
471                        domain, busnum);
472                 return NULL;
473         }
474
475         node = -1;
476 #ifdef CONFIG_ACPI_NUMA
477         pxm = acpi_get_pxm(device->handle);
478         if (pxm >= 0)
479                 node = pxm_to_node(pxm);
480         if (node != -1)
481                 set_mp_bus_to_node(busnum, node);
482         else
483 #endif
484                 node = get_mp_bus_to_node(busnum);
485
486         if (node != -1 && !node_online(node))
487                 node = -1;
488
489         info = kzalloc(sizeof(*info), GFP_KERNEL);
490         if (!info) {
491                 printk(KERN_WARNING "pci_bus %04x:%02x: "
492                        "ignored (out of memory)\n", domain, busnum);
493                 return NULL;
494         }
495
496         sd = &info->sd;
497         sd->domain = domain;
498         sd->node = node;
499         /*
500          * Maybe the desired pci bus has been already scanned. In such case
501          * it is unnecessary to scan the pci bus with the given domain,busnum.
502          */
503         bus = pci_find_bus(domain, busnum);
504         if (bus) {
505                 /*
506                  * If the desired bus exits, the content of bus->sysdata will
507                  * be replaced by sd.
508                  */
509                 memcpy(bus->sysdata, sd, sizeof(*sd));
510                 kfree(info);
511         } else {
512                 probe_pci_root_info(info, device, busnum, domain);
513
514                 /* insert busn res at first */
515                 pci_add_resource(&resources,  &root->secondary);
516                 /*
517                  * _CRS with no apertures is normal, so only fall back to
518                  * defaults or native bridge info if we're ignoring _CRS.
519                  */
520                 if (pci_use_crs)
521                         add_resources(info, &resources);
522                 else {
523                         free_pci_root_info_res(info);
524                         x86_pci_root_bus_resources(busnum, &resources);
525                 }
526
527                 if (!setup_mcfg_map(info, domain, (u8)root->secondary.start,
528                                     (u8)root->secondary.end, root->mcfg_addr))
529                         bus = pci_create_root_bus(NULL, busnum, &pci_root_ops,
530                                                   sd, &resources);
531
532                 if (bus) {
533                         pci_scan_child_bus(bus);
534                         pci_set_host_bridge_release(
535                                 to_pci_host_bridge(bus->bridge),
536                                 release_pci_root_info, info);
537                 } else {
538                         pci_free_resource_list(&resources);
539                         __release_pci_root_info(info);
540                 }
541         }
542
543         /* After the PCI-E bus has been walked and all devices discovered,
544          * configure any settings of the fabric that might be necessary.
545          */
546         if (bus) {
547                 struct pci_bus *child;
548                 list_for_each_entry(child, &bus->children, node) {
549                         struct pci_dev *self = child->self;
550                         if (!self)
551                                 continue;
552
553                         pcie_bus_configure_settings(child, self->pcie_mpss);
554                 }
555         }
556
557         if (bus && node != -1) {
558 #ifdef CONFIG_ACPI_NUMA
559                 if (pxm >= 0)
560                         dev_printk(KERN_DEBUG, &bus->dev,
561                                    "on NUMA node %d (pxm %d)\n", node, pxm);
562 #else
563                 dev_printk(KERN_DEBUG, &bus->dev, "on NUMA node %d\n", node);
564 #endif
565         }
566
567         return bus;
568 }
569
570 int __init pci_acpi_init(void)
571 {
572         struct pci_dev *dev = NULL;
573
574         if (acpi_noirq)
575                 return -ENODEV;
576
577         printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n");
578         acpi_irq_penalty_init();
579         pcibios_enable_irq = acpi_pci_irq_enable;
580         pcibios_disable_irq = acpi_pci_irq_disable;
581         x86_init.pci.init_irq = x86_init_noop;
582
583         if (pci_routeirq) {
584                 /*
585                  * PCI IRQ routing is set up by pci_enable_device(), but we
586                  * also do it here in case there are still broken drivers that
587                  * don't use pci_enable_device().
588                  */
589                 printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
590                 for_each_pci_dev(dev)
591                         acpi_pci_irq_enable(dev);
592         }
593
594         return 0;
595 }