x86/PCI: ignore Consumer/Producer bit in ACPI window descriptions
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / x86 / pci / acpi.c
blob334153ca4c301770850949e384f4feac60d4015f
1 #include <linux/pci.h>
2 #include <linux/acpi.h>
3 #include <linux/init.h>
4 #include <linux/irq.h>
5 #include <linux/dmi.h>
6 #include <linux/slab.h>
7 #include <asm/numa.h>
8 #include <asm/pci_x86.h>
10 struct pci_root_info {
11 struct acpi_device *bridge;
12 char *name;
13 unsigned int res_num;
14 struct resource *res;
15 struct pci_bus *bus;
16 int busnum;
19 static bool pci_use_crs = true;
21 static int __init set_use_crs(const struct dmi_system_id *id)
23 pci_use_crs = true;
24 return 0;
27 static const struct dmi_system_id pci_use_crs_table[] __initconst = {
28 /* http://bugzilla.kernel.org/show_bug.cgi?id=14183 */
30 .callback = set_use_crs,
31 .ident = "IBM System x3800",
32 .matches = {
33 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
34 DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
40 void __init pci_acpi_crs_quirks(void)
42 int year;
44 if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year < 2008)
45 pci_use_crs = false;
47 dmi_check_system(pci_use_crs_table);
50 * If the user specifies "pci=use_crs" or "pci=nocrs" explicitly, that
51 * takes precedence over anything we figured out above.
53 if (pci_probe & PCI_ROOT_NO_CRS)
54 pci_use_crs = false;
55 else if (pci_probe & PCI_USE__CRS)
56 pci_use_crs = true;
58 printk(KERN_INFO "PCI: %s host bridge windows from ACPI; "
59 "if necessary, use \"pci=%s\" and report a bug\n",
60 pci_use_crs ? "Using" : "Ignoring",
61 pci_use_crs ? "nocrs" : "use_crs");
64 static acpi_status
65 resource_to_addr(struct acpi_resource *resource,
66 struct acpi_resource_address64 *addr)
68 acpi_status status;
70 status = acpi_resource_to_address64(resource, addr);
71 if (ACPI_SUCCESS(status) &&
72 (addr->resource_type == ACPI_MEMORY_RANGE ||
73 addr->resource_type == ACPI_IO_RANGE) &&
74 addr->address_length > 0) {
75 return AE_OK;
77 return AE_ERROR;
80 static acpi_status
81 count_resource(struct acpi_resource *acpi_res, void *data)
83 struct pci_root_info *info = data;
84 struct acpi_resource_address64 addr;
85 acpi_status status;
87 status = resource_to_addr(acpi_res, &addr);
88 if (ACPI_SUCCESS(status))
89 info->res_num++;
90 return AE_OK;
93 static void
94 align_resource(struct acpi_device *bridge, struct resource *res)
96 int align = (res->flags & IORESOURCE_MEM) ? 16 : 4;
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.
103 if (!IS_ALIGNED(res->start, align)) {
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);
109 if (!IS_ALIGNED(res->end + 1, align)) {
110 dev_printk(KERN_DEBUG, &bridge->dev,
111 "host bridge window %pR invalid; "
112 "aligning end to %d-byte boundary\n", res, align);
113 res->end = ALIGN(res->end, align) - 1;
117 static acpi_status
118 setup_resource(struct acpi_resource *acpi_res, void *data)
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;
125 struct resource *root, *conflict;
126 u64 start, end, max_len;
128 status = resource_to_addr(acpi_res, &addr);
129 if (!ACPI_SUCCESS(status))
130 return AE_OK;
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;
143 max_len = addr.maximum - addr.minimum + 1;
144 if (addr.address_length > max_len) {
145 dev_printk(KERN_DEBUG, &info->bridge->dev,
146 "host bridge window length %#llx doesn't fit in "
147 "%#llx-%#llx, trimming\n",
148 (unsigned long long) addr.address_length,
149 (unsigned long long) addr.minimum,
150 (unsigned long long) addr.maximum);
151 addr.address_length = max_len;
154 start = addr.minimum + addr.translation_offset;
155 end = start + addr.address_length - 1;
157 res = &info->res[info->res_num];
158 res->name = info->name;
159 res->flags = flags;
160 res->start = start;
161 res->end = end;
162 res->child = NULL;
163 align_resource(info->bridge, res);
165 if (!pci_use_crs) {
166 dev_printk(KERN_DEBUG, &info->bridge->dev,
167 "host bridge window %pR (ignored)\n", res);
168 return AE_OK;
171 conflict = insert_resource_conflict(root, res);
172 if (conflict) {
173 dev_err(&info->bridge->dev,
174 "address space collision: host bridge window %pR "
175 "conflicts with %s %pR\n",
176 res, conflict->name, conflict);
177 } else {
178 pci_bus_add_resource(info->bus, res, 0);
179 info->res_num++;
180 if (addr.translation_offset)
181 dev_info(&info->bridge->dev, "host bridge window %pR "
182 "(PCI address [%#llx-%#llx])\n",
183 res, res->start - addr.translation_offset,
184 res->end - addr.translation_offset);
185 else
186 dev_info(&info->bridge->dev,
187 "host bridge window %pR\n", res);
189 return AE_OK;
192 static void
193 get_current_resources(struct acpi_device *device, int busnum,
194 int domain, struct pci_bus *bus)
196 struct pci_root_info info;
197 size_t size;
199 if (pci_use_crs)
200 pci_bus_remove_resources(bus);
202 info.bridge = device;
203 info.bus = bus;
204 info.res_num = 0;
205 acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_resource,
206 &info);
207 if (!info.res_num)
208 return;
210 size = sizeof(*info.res) * info.res_num;
211 info.res = kmalloc(size, GFP_KERNEL);
212 if (!info.res)
213 goto res_alloc_fail;
215 info.name = kmalloc(16, GFP_KERNEL);
216 if (!info.name)
217 goto name_alloc_fail;
218 sprintf(info.name, "PCI Bus %04x:%02x", domain, busnum);
220 info.res_num = 0;
221 acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource,
222 &info);
224 return;
226 name_alloc_fail:
227 kfree(info.res);
228 res_alloc_fail:
229 return;
232 struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int domain, int busnum)
234 struct pci_bus *bus;
235 struct pci_sysdata *sd;
236 int node;
237 #ifdef CONFIG_ACPI_NUMA
238 int pxm;
239 #endif
241 if (domain && !pci_domains_supported) {
242 printk(KERN_WARNING "pci_bus %04x:%02x: "
243 "ignored (multiple domains not supported)\n",
244 domain, busnum);
245 return NULL;
248 node = -1;
249 #ifdef CONFIG_ACPI_NUMA
250 pxm = acpi_get_pxm(device->handle);
251 if (pxm >= 0)
252 node = pxm_to_node(pxm);
253 if (node != -1)
254 set_mp_bus_to_node(busnum, node);
255 else
256 #endif
257 node = get_mp_bus_to_node(busnum);
259 if (node != -1 && !node_online(node))
260 node = -1;
262 /* Allocate per-root-bus (not per bus) arch-specific data.
263 * TODO: leak; this memory is never freed.
264 * It's arguable whether it's worth the trouble to care.
266 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
267 if (!sd) {
268 printk(KERN_WARNING "pci_bus %04x:%02x: "
269 "ignored (out of memory)\n", domain, busnum);
270 return NULL;
273 sd->domain = domain;
274 sd->node = node;
276 * Maybe the desired pci bus has been already scanned. In such case
277 * it is unnecessary to scan the pci bus with the given domain,busnum.
279 bus = pci_find_bus(domain, busnum);
280 if (bus) {
282 * If the desired bus exits, the content of bus->sysdata will
283 * be replaced by sd.
285 memcpy(bus->sysdata, sd, sizeof(*sd));
286 kfree(sd);
287 } else {
288 bus = pci_create_bus(NULL, busnum, &pci_root_ops, sd);
289 if (bus) {
290 get_current_resources(device, busnum, domain, bus);
291 bus->subordinate = pci_scan_child_bus(bus);
295 if (!bus)
296 kfree(sd);
298 if (bus && node != -1) {
299 #ifdef CONFIG_ACPI_NUMA
300 if (pxm >= 0)
301 dev_printk(KERN_DEBUG, &bus->dev,
302 "on NUMA node %d (pxm %d)\n", node, pxm);
303 #else
304 dev_printk(KERN_DEBUG, &bus->dev, "on NUMA node %d\n", node);
305 #endif
308 return bus;
311 int __init pci_acpi_init(void)
313 struct pci_dev *dev = NULL;
315 if (acpi_noirq)
316 return -ENODEV;
318 printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n");
319 acpi_irq_penalty_init();
320 pcibios_enable_irq = acpi_pci_irq_enable;
321 pcibios_disable_irq = acpi_pci_irq_disable;
322 x86_init.pci.init_irq = x86_init_noop;
324 if (pci_routeirq) {
326 * PCI IRQ routing is set up by pci_enable_device(), but we
327 * also do it here in case there are still broken drivers that
328 * don't use pci_enable_device().
330 printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
331 for_each_pci_dev(dev)
332 acpi_pci_irq_enable(dev);
335 return 0;