1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/init.h>
4 #include <linux/range.h>
8 LIST_HEAD(pci_root_infos);
10 static struct pci_root_info *x86_find_pci_root_info(int bus)
12 struct pci_root_info *info;
14 list_for_each_entry(info, &pci_root_infos, list)
15 if (info->busn.start == bus)
21 int x86_pci_root_bus_node(int bus)
23 struct pci_root_info *info = x86_find_pci_root_info(bus);
31 void x86_pci_root_bus_resources(int bus, struct list_head *resources)
33 struct pci_root_info *info = x86_find_pci_root_info(bus);
34 struct pci_root_res *root_res;
35 struct resource_entry *window;
39 goto default_resources;
41 printk(KERN_DEBUG "PCI: root bus %02x: hardware-probed resources\n",
44 /* already added by acpi ? */
45 resource_list_for_each_entry(window, resources)
46 if (window->res->flags & IORESOURCE_BUS) {
52 pci_add_resource(resources, &info->busn);
54 list_for_each_entry(root_res, &info->resources, list)
55 pci_add_resource(resources, &root_res->res);
61 * We don't have any host bridge aperture information from the
62 * "native host bridge drivers," e.g., amd_bus or broadcom_bus,
63 * so fall back to the defaults historically used by pci_create_bus().
65 printk(KERN_DEBUG "PCI: root bus %02x: using default resources\n", bus);
66 pci_add_resource(resources, &ioport_resource);
67 pci_add_resource(resources, &iomem_resource);
70 struct pci_root_info __init *alloc_pci_root_info(int bus_min, int bus_max,
73 struct pci_root_info *info;
75 info = kzalloc(sizeof(*info), GFP_KERNEL);
80 sprintf(info->name, "PCI Bus #%02x", bus_min);
82 INIT_LIST_HEAD(&info->resources);
83 info->busn.name = info->name;
84 info->busn.start = bus_min;
85 info->busn.end = bus_max;
86 info->busn.flags = IORESOURCE_BUS;
90 list_add_tail(&info->list, &pci_root_infos);
95 void update_res(struct pci_root_info *info, resource_size_t start,
96 resource_size_t end, unsigned long flags, int merge)
99 struct pci_root_res *root_res;
104 if (start == MAX_RESOURCE)
110 /* try to merge it with old one */
111 list_for_each_entry(root_res, &info->resources, list) {
112 resource_size_t final_start, final_end;
113 resource_size_t common_start, common_end;
115 res = &root_res->res;
116 if (res->flags != flags)
119 common_start = max(res->start, start);
120 common_end = min(res->end, end);
121 if (common_start > common_end + 1)
124 final_start = min(res->start, start);
125 final_end = max(res->end, end);
127 res->start = final_start;
128 res->end = final_end;
134 /* need to add that */
135 root_res = kzalloc(sizeof(*root_res), GFP_KERNEL);
139 res = &root_res->res;
140 res->name = info->name;
145 list_add_tail(&root_res->list, &info->resources);