2 #include <linux/acpi.h>
3 #include <linux/init.h>
6 #include <linux/slab.h>
8 #include <asm/pci_x86.h>
10 struct pci_root_info
{
11 struct acpi_device
*bridge
;
19 static bool pci_use_crs
= true;
21 static int __init
set_use_crs(const struct dmi_system_id
*id
)
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",
33 DMI_MATCH(DMI_SYS_VENDOR
, "IBM"),
34 DMI_MATCH(DMI_PRODUCT_NAME
, "x3800"),
40 void __init
pci_acpi_crs_quirks(void)
44 if (dmi_get_date(DMI_BIOS_DATE
, &year
, NULL
, NULL
) && year
< 2008)
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
)
55 else if (pci_probe
& PCI_USE__CRS
)
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");
65 resource_to_addr(struct acpi_resource
*resource
,
66 struct acpi_resource_address64
*addr
)
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 addr
->producer_consumer
== ACPI_PRODUCER
) {
82 count_resource(struct acpi_resource
*acpi_res
, void *data
)
84 struct pci_root_info
*info
= data
;
85 struct acpi_resource_address64 addr
;
88 status
= resource_to_addr(acpi_res
, &addr
);
89 if (ACPI_SUCCESS(status
))
95 align_resource(struct acpi_device
*bridge
, struct resource
*res
)
97 int align
= (res
->flags
& IORESOURCE_MEM
) ? 16 : 4;
100 * Host bridge windows are not BARs, but the decoders on the PCI side
101 * that claim this address space have starting alignment and length
102 * constraints, so fix any obvious BIOS goofs.
104 if (!IS_ALIGNED(res
->start
, align
)) {
105 dev_printk(KERN_DEBUG
, &bridge
->dev
,
106 "host bridge window %pR invalid; "
107 "aligning start to %d-byte boundary\n", res
, align
);
108 res
->start
&= ~(align
- 1);
110 if (!IS_ALIGNED(res
->end
+ 1, align
)) {
111 dev_printk(KERN_DEBUG
, &bridge
->dev
,
112 "host bridge window %pR invalid; "
113 "aligning end to %d-byte boundary\n", res
, align
);
114 res
->end
= ALIGN(res
->end
, align
) - 1;
119 setup_resource(struct acpi_resource
*acpi_res
, void *data
)
121 struct pci_root_info
*info
= data
;
122 struct resource
*res
;
123 struct acpi_resource_address64 addr
;
126 struct resource
*root
, *conflict
;
127 u64 start
, end
, max_len
;
129 status
= resource_to_addr(acpi_res
, &addr
);
130 if (!ACPI_SUCCESS(status
))
133 if (addr
.resource_type
== ACPI_MEMORY_RANGE
) {
134 root
= &iomem_resource
;
135 flags
= IORESOURCE_MEM
;
136 if (addr
.info
.mem
.caching
== ACPI_PREFETCHABLE_MEMORY
)
137 flags
|= IORESOURCE_PREFETCH
;
138 } else if (addr
.resource_type
== ACPI_IO_RANGE
) {
139 root
= &ioport_resource
;
140 flags
= IORESOURCE_IO
;
144 max_len
= addr
.maximum
- addr
.minimum
+ 1;
145 if (addr
.address_length
> max_len
) {
146 dev_printk(KERN_DEBUG
, &info
->bridge
->dev
,
147 "host bridge window length %#llx doesn't fit in "
148 "%#llx-%#llx, trimming\n",
149 (unsigned long long) addr
.address_length
,
150 (unsigned long long) addr
.minimum
,
151 (unsigned long long) addr
.maximum
);
152 addr
.address_length
= max_len
;
155 start
= addr
.minimum
+ addr
.translation_offset
;
156 end
= start
+ addr
.address_length
- 1;
158 res
= &info
->res
[info
->res_num
];
159 res
->name
= info
->name
;
164 align_resource(info
->bridge
, res
);
167 dev_printk(KERN_DEBUG
, &info
->bridge
->dev
,
168 "host bridge window %pR (ignored)\n", res
);
172 conflict
= insert_resource_conflict(root
, res
);
174 dev_err(&info
->bridge
->dev
,
175 "address space collision: host bridge window %pR "
176 "conflicts with %s %pR\n",
177 res
, conflict
->name
, conflict
);
179 pci_bus_add_resource(info
->bus
, res
, 0);
181 if (addr
.translation_offset
)
182 dev_info(&info
->bridge
->dev
, "host bridge window %pR "
183 "(PCI address [%#llx-%#llx])\n",
184 res
, res
->start
- addr
.translation_offset
,
185 res
->end
- addr
.translation_offset
);
187 dev_info(&info
->bridge
->dev
,
188 "host bridge window %pR\n", res
);
194 get_current_resources(struct acpi_device
*device
, int busnum
,
195 int domain
, struct pci_bus
*bus
)
197 struct pci_root_info info
;
201 pci_bus_remove_resources(bus
);
203 info
.bridge
= device
;
206 acpi_walk_resources(device
->handle
, METHOD_NAME__CRS
, count_resource
,
211 size
= sizeof(*info
.res
) * info
.res_num
;
212 info
.res
= kmalloc(size
, GFP_KERNEL
);
216 info
.name
= kmalloc(16, GFP_KERNEL
);
218 goto name_alloc_fail
;
219 sprintf(info
.name
, "PCI Bus %04x:%02x", domain
, busnum
);
222 acpi_walk_resources(device
->handle
, METHOD_NAME__CRS
, setup_resource
,
233 struct pci_bus
* __devinit
pci_acpi_scan_root(struct acpi_device
*device
, int domain
, int busnum
)
236 struct pci_sysdata
*sd
;
238 #ifdef CONFIG_ACPI_NUMA
242 if (domain
&& !pci_domains_supported
) {
243 printk(KERN_WARNING
"pci_bus %04x:%02x: "
244 "ignored (multiple domains not supported)\n",
250 #ifdef CONFIG_ACPI_NUMA
251 pxm
= acpi_get_pxm(device
->handle
);
253 node
= pxm_to_node(pxm
);
255 set_mp_bus_to_node(busnum
, node
);
258 node
= get_mp_bus_to_node(busnum
);
260 if (node
!= -1 && !node_online(node
))
263 /* Allocate per-root-bus (not per bus) arch-specific data.
264 * TODO: leak; this memory is never freed.
265 * It's arguable whether it's worth the trouble to care.
267 sd
= kzalloc(sizeof(*sd
), GFP_KERNEL
);
269 printk(KERN_WARNING
"pci_bus %04x:%02x: "
270 "ignored (out of memory)\n", domain
, busnum
);
277 * Maybe the desired pci bus has been already scanned. In such case
278 * it is unnecessary to scan the pci bus with the given domain,busnum.
280 bus
= pci_find_bus(domain
, busnum
);
283 * If the desired bus exits, the content of bus->sysdata will
286 memcpy(bus
->sysdata
, sd
, sizeof(*sd
));
289 bus
= pci_create_bus(NULL
, busnum
, &pci_root_ops
, sd
);
291 get_current_resources(device
, busnum
, domain
, bus
);
292 bus
->subordinate
= pci_scan_child_bus(bus
);
299 if (bus
&& node
!= -1) {
300 #ifdef CONFIG_ACPI_NUMA
302 dev_printk(KERN_DEBUG
, &bus
->dev
,
303 "on NUMA node %d (pxm %d)\n", node
, pxm
);
305 dev_printk(KERN_DEBUG
, &bus
->dev
, "on NUMA node %d\n", node
);
312 int __init
pci_acpi_init(void)
314 struct pci_dev
*dev
= NULL
;
319 printk(KERN_INFO
"PCI: Using ACPI for IRQ routing\n");
320 acpi_irq_penalty_init();
321 pcibios_enable_irq
= acpi_pci_irq_enable
;
322 pcibios_disable_irq
= acpi_pci_irq_disable
;
323 x86_init
.pci
.init_irq
= x86_init_noop
;
327 * PCI IRQ routing is set up by pci_enable_device(), but we
328 * also do it here in case there are still broken drivers that
329 * don't use pci_enable_device().
331 printk(KERN_INFO
"PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
332 for_each_pci_dev(dev
)
333 acpi_pci_irq_enable(dev
);