blob: 3510778aa8bb373a5149709a3357082b112c74d4 [file] [log] [blame]
Yinghai Lu67f241f2009-11-11 22:27:40 -08001#include <linux/init.h>
2#include <linux/pci.h>
Yinghai Lu9ad3f2c2010-02-10 01:20:11 -08003#include <linux/range.h>
Yinghai Lu67f241f2009-11-11 22:27:40 -08004
5#include "bus_numa.h"
6
7int pci_root_num;
8struct pci_root_info pci_root_info[PCI_ROOT_NR];
Yinghai Lu67f241f2009-11-11 22:27:40 -08009
10void 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
Yinghai Lu67f241f2009-11-11 22:27:40 -080024 for (i = 0; i < pci_root_num; i++) {
25 if (pci_root_info[i].bus_min == b->number)
26 break;
27 }
28
29 if (i == pci_root_num)
30 return;
31
32 printk(KERN_DEBUG "PCI: peer root bus %02x res updated from pci conf\n",
33 b->number);
34
35 info = &pci_root_info[i];
36 for (j = 0; j < info->res_num; j++) {
37 struct resource *res;
38 struct resource *root;
39
40 res = &info->res[j];
41 b->resource[j] = res;
42 if (res->flags & IORESOURCE_IO)
43 root = &ioport_resource;
44 else
45 root = &iomem_resource;
46 insert_resource(root, res);
47 }
48}
49
Yinghai Lub74fd232010-02-10 01:20:08 -080050void __devinit update_res(struct pci_root_info *info, resource_size_t start,
51 resource_size_t end, unsigned long flags, int merge)
Yinghai Lu67f241f2009-11-11 22:27:40 -080052{
53 int i;
54 struct resource *res;
55
56 if (start > end)
57 return;
58
Yinghai Lu9ad3f2c2010-02-10 01:20:11 -080059 if (start == MAX_RESOURCE)
60 return;
61
Yinghai Lu67f241f2009-11-11 22:27:40 -080062 if (!merge)
63 goto addit;
64
65 /* try to merge it with old one */
66 for (i = 0; i < info->res_num; i++) {
Yinghai Lub74fd232010-02-10 01:20:08 -080067 resource_size_t final_start, final_end;
68 resource_size_t common_start, common_end;
Yinghai Lu67f241f2009-11-11 22:27:40 -080069
70 res = &info->res[i];
71 if (res->flags != flags)
72 continue;
73
Yinghai Lub74fd232010-02-10 01:20:08 -080074 common_start = max(res->start, start);
75 common_end = min(res->end, end);
Yinghai Lu67f241f2009-11-11 22:27:40 -080076 if (common_start > common_end + 1)
77 continue;
78
Yinghai Lub74fd232010-02-10 01:20:08 -080079 final_start = min(res->start, start);
80 final_end = max(res->end, end);
Yinghai Lu67f241f2009-11-11 22:27:40 -080081
82 res->start = final_start;
83 res->end = final_end;
84 return;
85 }
86
87addit:
88
89 /* need to add that */
90 if (info->res_num >= RES_NUM)
91 return;
92
93 res = &info->res[info->res_num];
94 res->name = info->name;
95 res->flags = flags;
96 res->start = start;
97 res->end = end;
98 res->child = NULL;
99 info->res_num++;
100}