]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - arch/x86/pci/acpi.c
PCI: Add 'nodomains' boot option, and pci_domains_supported global
[mirror_ubuntu-focal-kernel.git] / arch / x86 / pci / acpi.c
CommitLineData
1da177e4
LT
1#include <linux/pci.h>
2#include <linux/acpi.h>
3#include <linux/init.h>
b33fa1f3 4#include <linux/irq.h>
036fff4c 5#include <linux/dmi.h>
69e1a33f 6#include <asm/numa.h>
1da177e4
LT
7#include "pci.h"
8
036fff4c
GH
9static int __devinit can_skip_ioresource_align(struct dmi_system_id *d)
10{
11 pci_probe |= PCI_CAN_SKIP_ISA_ALIGN;
12 printk(KERN_INFO "PCI: %s detected, can skip ISA alignment\n", d->ident);
13 return 0;
14}
15
16static struct dmi_system_id acpi_pciprobe_dmi_table[] = {
17/*
18 * Systems where PCI IO resource ISA alignment can be skipped
19 * when the ISA enable bit in the bridge control is not set
20 */
21 {
22 .callback = can_skip_ioresource_align,
23 .ident = "IBM System x3800",
24 .matches = {
25 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
26 DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
27 },
28 },
29 {
30 .callback = can_skip_ioresource_align,
31 .ident = "IBM System x3850",
32 .matches = {
33 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
34 DMI_MATCH(DMI_PRODUCT_NAME, "x3850"),
35 },
36 },
37 {
38 .callback = can_skip_ioresource_align,
39 .ident = "IBM System x3950",
40 .matches = {
41 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
42 DMI_MATCH(DMI_PRODUCT_NAME, "x3950"),
43 },
44 },
45 {}
46};
47
62f420f8
GH
48struct pci_root_info {
49 char *name;
50 unsigned int res_num;
51 struct resource *res;
52 struct pci_bus *bus;
53 int busnum;
54};
55
56static acpi_status
57resource_to_addr(struct acpi_resource *resource,
58 struct acpi_resource_address64 *addr)
59{
60 acpi_status status;
61
62 status = acpi_resource_to_address64(resource, addr);
63 if (ACPI_SUCCESS(status) &&
64 (addr->resource_type == ACPI_MEMORY_RANGE ||
65 addr->resource_type == ACPI_IO_RANGE) &&
66 addr->address_length > 0 &&
67 addr->producer_consumer == ACPI_PRODUCER) {
68 return AE_OK;
69 }
70 return AE_ERROR;
71}
72
73static acpi_status
74count_resource(struct acpi_resource *acpi_res, void *data)
75{
76 struct pci_root_info *info = data;
77 struct acpi_resource_address64 addr;
78 acpi_status status;
79
80 status = resource_to_addr(acpi_res, &addr);
81 if (ACPI_SUCCESS(status))
82 info->res_num++;
83 return AE_OK;
84}
85
86static acpi_status
87setup_resource(struct acpi_resource *acpi_res, void *data)
88{
89 struct pci_root_info *info = data;
90 struct resource *res;
91 struct acpi_resource_address64 addr;
92 acpi_status status;
93 unsigned long flags;
94 struct resource *root;
95
96 status = resource_to_addr(acpi_res, &addr);
97 if (!ACPI_SUCCESS(status))
98 return AE_OK;
99
100 if (addr.resource_type == ACPI_MEMORY_RANGE) {
101 root = &iomem_resource;
102 flags = IORESOURCE_MEM;
103 if (addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY)
104 flags |= IORESOURCE_PREFETCH;
105 } else if (addr.resource_type == ACPI_IO_RANGE) {
106 root = &ioport_resource;
107 flags = IORESOURCE_IO;
108 } else
109 return AE_OK;
110
111 res = &info->res[info->res_num];
112 res->name = info->name;
113 res->flags = flags;
114 res->start = addr.minimum + addr.translation_offset;
115 res->end = res->start + addr.address_length - 1;
116 res->child = NULL;
117
118 if (insert_resource(root, res)) {
119 printk(KERN_ERR "PCI: Failed to allocate 0x%lx-0x%lx "
120 "from %s for %s\n", (unsigned long) res->start,
121 (unsigned long) res->end, root->name, info->name);
122 } else {
123 info->bus->resource[info->res_num] = res;
124 info->res_num++;
125 }
126 return AE_OK;
127}
128
129static void
130adjust_transparent_bridge_resources(struct pci_bus *bus)
131{
132 struct pci_dev *dev;
133
134 list_for_each_entry(dev, &bus->devices, bus_list) {
135 int i;
136 u16 class = dev->class >> 8;
137
138 if (class == PCI_CLASS_BRIDGE_PCI && dev->transparent) {
139 for(i = 3; i < PCI_BUS_NUM_RESOURCES; i++)
140 dev->subordinate->resource[i] =
141 dev->bus->resource[i - 3];
142 }
143 }
144}
145
146static void
147get_current_resources(struct acpi_device *device, int busnum,
148 struct pci_bus *bus)
149{
150 struct pci_root_info info;
151 size_t size;
152
153 info.bus = bus;
154 info.res_num = 0;
155 acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_resource,
156 &info);
157 if (!info.res_num)
158 return;
159
160 size = sizeof(*info.res) * info.res_num;
161 info.res = kmalloc(size, GFP_KERNEL);
162 if (!info.res)
163 goto res_alloc_fail;
164
165 info.name = kmalloc(12, GFP_KERNEL);
166 if (!info.name)
167 goto name_alloc_fail;
168 sprintf(info.name, "PCI Bus #%02x", busnum);
169
170 info.res_num = 0;
171 acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource,
172 &info);
173 if (info.res_num)
174 adjust_transparent_bridge_resources(bus);
175
176 return;
177
178name_alloc_fail:
179 kfree(info.res);
180res_alloc_fail:
181 return;
182}
183
1da177e4
LT
184struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int domain, int busnum)
185{
69e1a33f 186 struct pci_bus *bus;
08f1c192
MBY
187 struct pci_sysdata *sd;
188 int pxm;
189
036fff4c
GH
190 dmi_check_system(acpi_pciprobe_dmi_table);
191
08f1c192
MBY
192 /* Allocate per-root-bus (not per bus) arch-specific data.
193 * TODO: leak; this memory is never freed.
194 * It's arguable whether it's worth the trouble to care.
195 */
196 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
197 if (!sd) {
198 printk(KERN_ERR "PCI: OOM, not probing PCI bus %02x\n", busnum);
199 return NULL;
200 }
69e1a33f 201
1da177e4
LT
202 if (domain != 0) {
203 printk(KERN_WARNING "PCI: Multiple domains not supported\n");
08f1c192 204 kfree(sd);
1da177e4
LT
205 return NULL;
206 }
207
08f1c192
MBY
208 sd->node = -1;
209
210 pxm = acpi_get_pxm(device->handle);
211#ifdef CONFIG_ACPI_NUMA
212 if (pxm >= 0)
213 sd->node = pxm_to_node(pxm);
214#endif
215
216 bus = pci_scan_bus_parented(NULL, busnum, &pci_root_ops, sd);
217 if (!bus)
218 kfree(sd);
219
69e1a33f
AK
220#ifdef CONFIG_ACPI_NUMA
221 if (bus != NULL) {
69e1a33f 222 if (pxm >= 0) {
08f1c192
MBY
223 printk("bus %d -> pxm %d -> node %d\n",
224 busnum, pxm, sd->node);
69e1a33f
AK
225 }
226 }
227#endif
62f420f8
GH
228
229 if (bus && (pci_probe & PCI_USE__CRS))
230 get_current_resources(device, busnum, bus);
69e1a33f
AK
231
232 return bus;
1da177e4
LT
233}
234
235extern int pci_routeirq;
236static int __init pci_acpi_init(void)
237{
238 struct pci_dev *dev = NULL;
239
240 if (pcibios_scanned)
241 return 0;
242
243 if (acpi_noirq)
244 return 0;
245
246 printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n");
247 acpi_irq_penalty_init();
248 pcibios_scanned++;
249 pcibios_enable_irq = acpi_pci_irq_enable;
87bec66b 250 pcibios_disable_irq = acpi_pci_irq_disable;
1da177e4
LT
251
252 if (pci_routeirq) {
253 /*
254 * PCI IRQ routing is set up by pci_enable_device(), but we
255 * also do it here in case there are still broken drivers that
256 * don't use pci_enable_device().
257 */
258 printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
fb37fb96 259 for_each_pci_dev(dev)
1da177e4
LT
260 acpi_pci_irq_enable(dev);
261 } else
262 printk(KERN_INFO "PCI: If a device doesn't work, try \"pci=routeirq\". If it helps, post a report\n");
263
264#ifdef CONFIG_X86_IO_APIC
265 if (acpi_ioapic)
266 print_IO_APIC();
267#endif
268
269 return 0;
270}
271subsys_initcall(pci_acpi_init);