]>
Commit | Line | Data |
---|---|---|
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> |
82487711 | 7 | #include <asm/pci_x86.h> |
1da177e4 | 8 | |
62f420f8 | 9 | struct pci_root_info { |
42887b29 | 10 | struct acpi_device *bridge; |
62f420f8 GH |
11 | char *name; |
12 | unsigned int res_num; | |
13 | struct resource *res; | |
14 | struct pci_bus *bus; | |
15 | int busnum; | |
16 | }; | |
17 | ||
7bc5e3f2 BH |
18 | static bool pci_use_crs = true; |
19 | ||
20 | static int __init set_use_crs(const struct dmi_system_id *id) | |
21 | { | |
22 | pci_use_crs = true; | |
23 | return 0; | |
24 | } | |
25 | ||
26 | static const struct dmi_system_id pci_use_crs_table[] __initconst = { | |
27 | /* http://bugzilla.kernel.org/show_bug.cgi?id=14183 */ | |
28 | { | |
29 | .callback = set_use_crs, | |
30 | .ident = "IBM System x3800", | |
31 | .matches = { | |
32 | DMI_MATCH(DMI_SYS_VENDOR, "IBM"), | |
33 | DMI_MATCH(DMI_PRODUCT_NAME, "x3800"), | |
34 | }, | |
35 | }, | |
36 | {} | |
37 | }; | |
38 | ||
39 | void __init pci_acpi_crs_quirks(void) | |
40 | { | |
41 | int year; | |
42 | ||
43 | if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year < 2008) | |
44 | pci_use_crs = false; | |
45 | ||
46 | dmi_check_system(pci_use_crs_table); | |
47 | ||
48 | /* | |
49 | * If the user specifies "pci=use_crs" or "pci=nocrs" explicitly, that | |
50 | * takes precedence over anything we figured out above. | |
51 | */ | |
52 | if (pci_probe & PCI_ROOT_NO_CRS) | |
53 | pci_use_crs = false; | |
54 | else if (pci_probe & PCI_USE__CRS) | |
55 | pci_use_crs = true; | |
56 | ||
57 | printk(KERN_INFO "PCI: %s host bridge windows from ACPI; " | |
58 | "if necessary, use \"pci=%s\" and report a bug\n", | |
59 | pci_use_crs ? "Using" : "Ignoring", | |
60 | pci_use_crs ? "nocrs" : "use_crs"); | |
61 | } | |
62 | ||
62f420f8 GH |
63 | static acpi_status |
64 | resource_to_addr(struct acpi_resource *resource, | |
65 | struct acpi_resource_address64 *addr) | |
66 | { | |
67 | acpi_status status; | |
68 | ||
69 | status = acpi_resource_to_address64(resource, addr); | |
70 | if (ACPI_SUCCESS(status) && | |
71 | (addr->resource_type == ACPI_MEMORY_RANGE || | |
72 | addr->resource_type == ACPI_IO_RANGE) && | |
73 | addr->address_length > 0 && | |
74 | addr->producer_consumer == ACPI_PRODUCER) { | |
75 | return AE_OK; | |
76 | } | |
77 | return AE_ERROR; | |
78 | } | |
79 | ||
80 | static acpi_status | |
81 | count_resource(struct acpi_resource *acpi_res, void *data) | |
82 | { | |
83 | struct pci_root_info *info = data; | |
84 | struct acpi_resource_address64 addr; | |
85 | acpi_status status; | |
86 | ||
87 | status = resource_to_addr(acpi_res, &addr); | |
88 | if (ACPI_SUCCESS(status)) | |
89 | info->res_num++; | |
90 | return AE_OK; | |
91 | } | |
92 | ||
03db42ad BH |
93 | static void |
94 | align_resource(struct acpi_device *bridge, struct resource *res) | |
95 | { | |
96 | int align = (res->flags & IORESOURCE_MEM) ? 16 : 4; | |
97 | ||
98 | /* | |
99 | * Host bridge windows are not BARs, but the decoders on the PCI side | |
100 | * that claim this address space have starting alignment and length | |
101 | * constraints, so fix any obvious BIOS goofs. | |
102 | */ | |
ea7f1b6e | 103 | if (!IS_ALIGNED(res->start, align)) { |
03db42ad BH |
104 | dev_printk(KERN_DEBUG, &bridge->dev, |
105 | "host bridge window %pR invalid; " | |
106 | "aligning start to %d-byte boundary\n", res, align); | |
107 | res->start &= ~(align - 1); | |
108 | } | |
ea7f1b6e | 109 | if (!IS_ALIGNED(res->end + 1, align)) { |
03db42ad BH |
110 | dev_printk(KERN_DEBUG, &bridge->dev, |
111 | "host bridge window %pR invalid; " | |
112 | "aligning end to %d-byte boundary\n", res, align); | |
ea7f1b6e | 113 | res->end = ALIGN(res->end, align) - 1; |
03db42ad BH |
114 | } |
115 | } | |
116 | ||
62f420f8 GH |
117 | static acpi_status |
118 | setup_resource(struct acpi_resource *acpi_res, void *data) | |
119 | { | |
120 | struct pci_root_info *info = data; | |
121 | struct resource *res; | |
122 | struct acpi_resource_address64 addr; | |
123 | acpi_status status; | |
124 | unsigned long flags; | |
eb9fc8ef | 125 | struct resource *root, *conflict; |
2cdb3f1d YL |
126 | u64 start, end; |
127 | ||
62f420f8 GH |
128 | status = resource_to_addr(acpi_res, &addr); |
129 | if (!ACPI_SUCCESS(status)) | |
130 | return AE_OK; | |
131 | ||
132 | if (addr.resource_type == ACPI_MEMORY_RANGE) { | |
133 | root = &iomem_resource; | |
134 | flags = IORESOURCE_MEM; | |
135 | if (addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY) | |
136 | flags |= IORESOURCE_PREFETCH; | |
137 | } else if (addr.resource_type == ACPI_IO_RANGE) { | |
138 | root = &ioport_resource; | |
139 | flags = IORESOURCE_IO; | |
140 | } else | |
141 | return AE_OK; | |
142 | ||
2cdb3f1d YL |
143 | start = addr.minimum + addr.translation_offset; |
144 | end = start + addr.address_length - 1; | |
f9cde5ff | 145 | |
2cdb3f1d YL |
146 | res = &info->res[info->res_num]; |
147 | res->name = info->name; | |
148 | res->flags = flags; | |
149 | res->start = start; | |
150 | res->end = end; | |
151 | res->child = NULL; | |
03db42ad | 152 | align_resource(info->bridge, res); |
2cdb3f1d | 153 | |
7bc5e3f2 | 154 | if (!pci_use_crs) { |
f1db6fde BH |
155 | dev_printk(KERN_DEBUG, &info->bridge->dev, |
156 | "host bridge window %pR (ignored)\n", res); | |
157 | return AE_OK; | |
158 | } | |
159 | ||
eb9fc8ef BH |
160 | conflict = insert_resource_conflict(root, res); |
161 | if (conflict) { | |
c7dabef8 | 162 | dev_err(&info->bridge->dev, |
eb9fc8ef BH |
163 | "address space collision: host bridge window %pR " |
164 | "conflicts with %s %pR\n", | |
165 | res, conflict->name, conflict); | |
62f420f8 | 166 | } else { |
2fe2abf8 | 167 | pci_bus_add_resource(info->bus, res, 0); |
62f420f8 | 168 | info->res_num++; |
42887b29 | 169 | if (addr.translation_offset) |
c7dabef8 | 170 | dev_info(&info->bridge->dev, "host bridge window %pR " |
42887b29 BH |
171 | "(PCI address [%#llx-%#llx])\n", |
172 | res, res->start - addr.translation_offset, | |
173 | res->end - addr.translation_offset); | |
174 | else | |
175 | dev_info(&info->bridge->dev, | |
c7dabef8 | 176 | "host bridge window %pR\n", res); |
62f420f8 GH |
177 | } |
178 | return AE_OK; | |
179 | } | |
180 | ||
62f420f8 GH |
181 | static void |
182 | get_current_resources(struct acpi_device *device, int busnum, | |
cb3576fa | 183 | int domain, struct pci_bus *bus) |
62f420f8 GH |
184 | { |
185 | struct pci_root_info info; | |
186 | size_t size; | |
187 | ||
7bc5e3f2 | 188 | if (pci_use_crs) |
2fe2abf8 | 189 | pci_bus_remove_resources(bus); |
f1db6fde | 190 | |
42887b29 | 191 | info.bridge = device; |
62f420f8 GH |
192 | info.bus = bus; |
193 | info.res_num = 0; | |
194 | acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_resource, | |
195 | &info); | |
196 | if (!info.res_num) | |
197 | return; | |
198 | ||
199 | size = sizeof(*info.res) * info.res_num; | |
200 | info.res = kmalloc(size, GFP_KERNEL); | |
201 | if (!info.res) | |
202 | goto res_alloc_fail; | |
203 | ||
cb3576fa | 204 | info.name = kmalloc(16, GFP_KERNEL); |
62f420f8 GH |
205 | if (!info.name) |
206 | goto name_alloc_fail; | |
cb3576fa | 207 | sprintf(info.name, "PCI Bus %04x:%02x", domain, busnum); |
62f420f8 GH |
208 | |
209 | info.res_num = 0; | |
210 | acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource, | |
211 | &info); | |
62f420f8 GH |
212 | |
213 | return; | |
214 | ||
215 | name_alloc_fail: | |
216 | kfree(info.res); | |
217 | res_alloc_fail: | |
218 | return; | |
219 | } | |
220 | ||
1da177e4 LT |
221 | struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int domain, int busnum) |
222 | { | |
69e1a33f | 223 | struct pci_bus *bus; |
08f1c192 | 224 | struct pci_sysdata *sd; |
871d5f8d YL |
225 | int node; |
226 | #ifdef CONFIG_ACPI_NUMA | |
08f1c192 | 227 | int pxm; |
871d5f8d | 228 | #endif |
08f1c192 | 229 | |
a79e4198 | 230 | if (domain && !pci_domains_supported) { |
2a6bed83 BH |
231 | printk(KERN_WARNING "pci_bus %04x:%02x: " |
232 | "ignored (multiple domains not supported)\n", | |
233 | domain, busnum); | |
a79e4198 JG |
234 | return NULL; |
235 | } | |
236 | ||
871d5f8d YL |
237 | node = -1; |
238 | #ifdef CONFIG_ACPI_NUMA | |
239 | pxm = acpi_get_pxm(device->handle); | |
240 | if (pxm >= 0) | |
241 | node = pxm_to_node(pxm); | |
242 | if (node != -1) | |
243 | set_mp_bus_to_node(busnum, node); | |
244 | else | |
871d5f8d | 245 | #endif |
871d5f8d | 246 | node = get_mp_bus_to_node(busnum); |
b755de8d YL |
247 | |
248 | if (node != -1 && !node_online(node)) | |
249 | node = -1; | |
871d5f8d | 250 | |
08f1c192 MBY |
251 | /* Allocate per-root-bus (not per bus) arch-specific data. |
252 | * TODO: leak; this memory is never freed. | |
253 | * It's arguable whether it's worth the trouble to care. | |
254 | */ | |
255 | sd = kzalloc(sizeof(*sd), GFP_KERNEL); | |
256 | if (!sd) { | |
2a6bed83 BH |
257 | printk(KERN_WARNING "pci_bus %04x:%02x: " |
258 | "ignored (out of memory)\n", domain, busnum); | |
08f1c192 MBY |
259 | return NULL; |
260 | } | |
69e1a33f | 261 | |
a79e4198 | 262 | sd->domain = domain; |
871d5f8d | 263 | sd->node = node; |
b87e81e5 | 264 | /* |
265 | * Maybe the desired pci bus has been already scanned. In such case | |
266 | * it is unnecessary to scan the pci bus with the given domain,busnum. | |
267 | */ | |
268 | bus = pci_find_bus(domain, busnum); | |
269 | if (bus) { | |
270 | /* | |
271 | * If the desired bus exits, the content of bus->sysdata will | |
272 | * be replaced by sd. | |
273 | */ | |
274 | memcpy(bus->sysdata, sd, sizeof(*sd)); | |
275 | kfree(sd); | |
626fdfec YL |
276 | } else { |
277 | bus = pci_create_bus(NULL, busnum, &pci_root_ops, sd); | |
278 | if (bus) { | |
f1db6fde | 279 | get_current_resources(device, busnum, domain, bus); |
626fdfec YL |
280 | bus->subordinate = pci_scan_child_bus(bus); |
281 | } | |
282 | } | |
08f1c192 | 283 | |
08f1c192 MBY |
284 | if (!bus) |
285 | kfree(sd); | |
286 | ||
dbb6152e | 287 | if (bus && node != -1) { |
69e1a33f | 288 | #ifdef CONFIG_ACPI_NUMA |
dbb6152e | 289 | if (pxm >= 0) |
2b8c2efe BH |
290 | dev_printk(KERN_DEBUG, &bus->dev, |
291 | "on NUMA node %d (pxm %d)\n", node, pxm); | |
dbb6152e | 292 | #else |
2b8c2efe | 293 | dev_printk(KERN_DEBUG, &bus->dev, "on NUMA node %d\n", node); |
69e1a33f | 294 | #endif |
dbb6152e | 295 | } |
62f420f8 | 296 | |
69e1a33f | 297 | return bus; |
1da177e4 LT |
298 | } |
299 | ||
8dd779b1 | 300 | int __init pci_acpi_init(void) |
1da177e4 LT |
301 | { |
302 | struct pci_dev *dev = NULL; | |
303 | ||
1da177e4 | 304 | if (acpi_noirq) |
b72d0db9 | 305 | return -ENODEV; |
1da177e4 LT |
306 | |
307 | printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n"); | |
308 | acpi_irq_penalty_init(); | |
1da177e4 | 309 | pcibios_enable_irq = acpi_pci_irq_enable; |
87bec66b | 310 | pcibios_disable_irq = acpi_pci_irq_disable; |
ab3b3793 | 311 | x86_init.pci.init_irq = x86_init_noop; |
1da177e4 LT |
312 | |
313 | if (pci_routeirq) { | |
314 | /* | |
315 | * PCI IRQ routing is set up by pci_enable_device(), but we | |
316 | * also do it here in case there are still broken drivers that | |
317 | * don't use pci_enable_device(). | |
318 | */ | |
319 | printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n"); | |
fb37fb96 | 320 | for_each_pci_dev(dev) |
1da177e4 | 321 | acpi_pci_irq_enable(dev); |
657472e9 | 322 | } |
1da177e4 | 323 | |
1da177e4 LT |
324 | return 0; |
325 | } |