x86/pci: AMD one chain system to use pci read out res
[linux-flexiantxendom0.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
9 void x86_pci_root_bus_res_quirks(struct pci_bus *b)
10 {
11         int i;
12         int j;
13         struct pci_root_info *info;
14
15         /* don't go for it if _CRS is used already */
16         if (b->resource[0] != &ioport_resource ||
17             b->resource[1] != &iomem_resource)
18                 return;
19
20         if (!pci_root_num)
21                 return;
22
23         for (i = 0; i < pci_root_num; i++) {
24                 if (pci_root_info[i].bus_min == b->number)
25                         break;
26         }
27
28         if (i == pci_root_num)
29                 return;
30
31         printk(KERN_DEBUG "PCI: peer root bus %02x res updated from pci conf\n",
32                         b->number);
33
34         info = &pci_root_info[i];
35         for (j = 0; j < info->res_num; j++) {
36                 struct resource *res;
37                 struct resource *root;
38
39                 res = &info->res[j];
40                 b->resource[j] = res;
41                 if (res->flags & IORESOURCE_IO)
42                         root = &ioport_resource;
43                 else
44                         root = &iomem_resource;
45                 insert_resource(root, res);
46         }
47 }
48
49 void __devinit update_res(struct pci_root_info *info, resource_size_t start,
50                           resource_size_t end, unsigned long flags, int merge)
51 {
52         int i;
53         struct resource *res;
54
55         if (start > end)
56                 return;
57
58         if (!merge)
59                 goto addit;
60
61         /* try to merge it with old one */
62         for (i = 0; i < info->res_num; i++) {
63                 resource_size_t final_start, final_end;
64                 resource_size_t common_start, common_end;
65
66                 res = &info->res[i];
67                 if (res->flags != flags)
68                         continue;
69
70                 common_start = max(res->start, start);
71                 common_end = min(res->end, end);
72                 if (common_start > common_end + 1)
73                         continue;
74
75                 final_start = min(res->start, start);
76                 final_end = max(res->end, end);
77
78                 res->start = final_start;
79                 res->end = final_end;
80                 return;
81         }
82
83 addit:
84
85         /* need to add that */
86         if (info->res_num >= RES_NUM)
87                 return;
88
89         res = &info->res[info->res_num];
90         res->name = info->name;
91         res->flags = flags;
92         res->start = start;
93         res->end = end;
94         res->child = NULL;
95         info->res_num++;
96 }