1 #include <linux/init.h>
3 #include <linux/range.h>
7 LIST_HEAD(pci_root_infos
);
9 static struct pci_root_info
*x86_find_pci_root_info(int bus
)
11 struct pci_root_info
*info
;
13 list_for_each_entry(info
, &pci_root_infos
, list
)
14 if (info
->busn
.start
== bus
)
20 int x86_pci_root_bus_node(int bus
)
22 struct pci_root_info
*info
= x86_find_pci_root_info(bus
);
30 void x86_pci_root_bus_resources(int bus
, struct list_head
*resources
)
32 struct pci_root_info
*info
= x86_find_pci_root_info(bus
);
33 struct pci_root_res
*root_res
;
34 struct resource_entry
*window
;
38 goto default_resources
;
40 printk(KERN_DEBUG
"PCI: root bus %02x: hardware-probed resources\n",
43 /* already added by acpi ? */
44 resource_list_for_each_entry(window
, resources
)
45 if (window
->res
->flags
& IORESOURCE_BUS
) {
51 pci_add_resource(resources
, &info
->busn
);
53 list_for_each_entry(root_res
, &info
->resources
, list
) {
55 struct resource
*root
;
58 pci_add_resource(resources
, res
);
59 if (res
->flags
& IORESOURCE_IO
)
60 root
= &ioport_resource
;
62 root
= &iomem_resource
;
63 insert_resource(root
, res
);
69 * We don't have any host bridge aperture information from the
70 * "native host bridge drivers," e.g., amd_bus or broadcom_bus,
71 * so fall back to the defaults historically used by pci_create_bus().
73 printk(KERN_DEBUG
"PCI: root bus %02x: using default resources\n", bus
);
74 pci_add_resource(resources
, &ioport_resource
);
75 pci_add_resource(resources
, &iomem_resource
);
78 struct pci_root_info __init
*alloc_pci_root_info(int bus_min
, int bus_max
,
81 struct pci_root_info
*info
;
83 info
= kzalloc(sizeof(*info
), GFP_KERNEL
);
88 sprintf(info
->name
, "PCI Bus #%02x", bus_min
);
90 INIT_LIST_HEAD(&info
->resources
);
91 info
->busn
.name
= info
->name
;
92 info
->busn
.start
= bus_min
;
93 info
->busn
.end
= bus_max
;
94 info
->busn
.flags
= IORESOURCE_BUS
;
98 list_add_tail(&info
->list
, &pci_root_infos
);
103 void update_res(struct pci_root_info
*info
, resource_size_t start
,
104 resource_size_t end
, unsigned long flags
, int merge
)
106 struct resource
*res
;
107 struct pci_root_res
*root_res
;
112 if (start
== MAX_RESOURCE
)
118 /* try to merge it with old one */
119 list_for_each_entry(root_res
, &info
->resources
, list
) {
120 resource_size_t final_start
, final_end
;
121 resource_size_t common_start
, common_end
;
123 res
= &root_res
->res
;
124 if (res
->flags
!= flags
)
127 common_start
= max(res
->start
, start
);
128 common_end
= min(res
->end
, end
);
129 if (common_start
> common_end
+ 1)
132 final_start
= min(res
->start
, start
);
133 final_end
= max(res
->end
, end
);
135 res
->start
= final_start
;
136 res
->end
= final_end
;
142 /* need to add that */
143 root_res
= kzalloc(sizeof(*root_res
), GFP_KERNEL
);
147 res
= &root_res
->res
;
148 res
->name
= info
->name
;
153 list_add_tail(&root_res
->list
, &info
->resources
);