Merge branch 'x86-pci-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.git] / arch / x86 / pci / bus_numa.c
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         pci_bus_remove_resources(b);
40         info = &pci_root_info[i];
41         for (j = 0; j < info->res_num; j++) {
42                 struct resource *res;
43                 struct resource *root;
44
45                 res = &info->res[j];
46                 pci_bus_add_resource(b, res, 0);
47                 if (res->flags & IORESOURCE_IO)
48                         root = &ioport_resource;
49                 else
50                         root = &iomem_resource;
51                 insert_resource(root, res);
52         }
53 }
54
55 void __devinit update_res(struct pci_root_info *info, size_t start,
56                               size_t end, unsigned long flags, int merge)
57 {
58         int i;
59         struct resource *res;
60
61         if (start > end)
62                 return;
63
64         if (!merge)
65                 goto addit;
66
67         /* try to merge it with old one */
68         for (i = 0; i < info->res_num; i++) {
69                 size_t final_start, final_end;
70                 size_t common_start, common_end;
71
72                 res = &info->res[i];
73                 if (res->flags != flags)
74                         continue;
75
76                 common_start = max((size_t)res->start, start);
77                 common_end = min((size_t)res->end, end);
78                 if (common_start > common_end + 1)
79                         continue;
80
81                 final_start = min((size_t)res->start, start);
82                 final_end = max((size_t)res->end, end);
83
84                 res->start = final_start;
85                 res->end = final_end;
86                 return;
87         }
88
89 addit:
90
91         /* need to add that */
92         if (info->res_num >= RES_NUM)
93                 return;
94
95         res = &info->res[info->res_num];
96         res->name = info->name;
97         res->flags = flags;
98         res->start = start;
99         res->end = end;
100         res->child = NULL;
101         info->res_num++;
102 }