blob: 3411687b676e88eacd635e10c7f7c2fd5ee31265 [file] [log] [blame]
Yinghai Lu67f241f2009-11-11 22:27:40 -08001#include <linux/init.h>
2#include <linux/pci.h>
3
4#include "bus_numa.h"
5
6int pci_root_num;
7struct pci_root_info pci_root_info[PCI_ROOT_NR];
Yinghai Lu67f241f2009-11-11 22:27:40 -08008
9void 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
Yinghai Lu67f241f2009-11-11 22:27:40 -080023 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
Yinghai Lub74fd232010-02-10 01:20:08 -080049void __devinit update_res(struct pci_root_info *info, resource_size_t start,
50 resource_size_t end, unsigned long flags, int merge)
Yinghai Lu67f241f2009-11-11 22:27:40 -080051{
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++) {
Yinghai Lub74fd232010-02-10 01:20:08 -080063 resource_size_t final_start, final_end;
64 resource_size_t common_start, common_end;
Yinghai Lu67f241f2009-11-11 22:27:40 -080065
66 res = &info->res[i];
67 if (res->flags != flags)
68 continue;
69
Yinghai Lub74fd232010-02-10 01:20:08 -080070 common_start = max(res->start, start);
71 common_end = min(res->end, end);
Yinghai Lu67f241f2009-11-11 22:27:40 -080072 if (common_start > common_end + 1)
73 continue;
74
Yinghai Lub74fd232010-02-10 01:20:08 -080075 final_start = min(res->start, start);
76 final_end = max(res->end, end);
Yinghai Lu67f241f2009-11-11 22:27:40 -080077
78 res->start = final_start;
79 res->end = final_end;
80 return;
81 }
82
83addit:
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}