2 #include <linux/acpi.h>
3 #include <linux/init.h>
7 #include <asm/pci_x86.h>
10 struct acpi_device
*bridge
;
19 resource_to_addr(struct acpi_resource
*resource
,
20 struct acpi_resource_address64
*addr
)
24 status
= acpi_resource_to_address64(resource
, addr
);
25 if (ACPI_SUCCESS(status
) &&
26 (addr
->resource_type
== ACPI_MEMORY_RANGE
||
27 addr
->resource_type
== ACPI_IO_RANGE
) &&
28 addr
->address_length
> 0 &&
29 addr
->producer_consumer
== ACPI_PRODUCER
) {
36 count_resource(struct acpi_resource
*acpi_res
, void *data
)
38 struct pci_root_info
*info
= data
;
39 struct acpi_resource_address64 addr
;
42 status
= resource_to_addr(acpi_res
, &addr
);
43 if (ACPI_SUCCESS(status
))
49 bus_has_transparent_bridge(struct pci_bus
*bus
)
53 list_for_each_entry(dev
, &bus
->devices
, bus_list
) {
54 u16
class = dev
->class >> 8;
56 if (class == PCI_CLASS_BRIDGE_PCI
&& dev
->transparent
)
63 setup_resource(struct acpi_resource
*acpi_res
, void *data
)
65 struct pci_root_info
*info
= data
;
67 struct acpi_resource_address64 addr
;
70 struct resource
*root
;
71 int max_root_bus_resources
= PCI_BUS_NUM_RESOURCES
;
74 if (bus_has_transparent_bridge(info
->bus
))
75 max_root_bus_resources
-= 3;
77 status
= resource_to_addr(acpi_res
, &addr
);
78 if (!ACPI_SUCCESS(status
))
81 if (addr
.resource_type
== ACPI_MEMORY_RANGE
) {
82 root
= &iomem_resource
;
83 flags
= IORESOURCE_MEM
;
84 if (addr
.info
.mem
.caching
== ACPI_PREFETCHABLE_MEMORY
)
85 flags
|= IORESOURCE_PREFETCH
;
86 } else if (addr
.resource_type
== ACPI_IO_RANGE
) {
87 root
= &ioport_resource
;
88 flags
= IORESOURCE_IO
;
92 start
= addr
.minimum
+ addr
.translation_offset
;
93 end
= start
+ addr
.address_length
- 1;
94 if (info
->res_num
>= max_root_bus_resources
) {
95 printk(KERN_WARNING
"PCI: Failed to allocate 0x%lx-0x%lx "
96 "from %s for %s due to _CRS returning more than "
97 "%d resource descriptors\n", (unsigned long) start
,
98 (unsigned long) end
, root
->name
, info
->name
,
99 max_root_bus_resources
);
103 res
= &info
->res
[info
->res_num
];
104 res
->name
= info
->name
;
110 if (insert_resource(root
, res
)) {
111 dev_err(&info
->bridge
->dev
,
112 "can't allocate host bridge window %pR\n", res
);
114 info
->bus
->resource
[info
->res_num
] = res
;
116 if (addr
.translation_offset
)
117 dev_info(&info
->bridge
->dev
, "host bridge window %pR "
118 "(PCI address [%#llx-%#llx])\n",
119 res
, res
->start
- addr
.translation_offset
,
120 res
->end
- addr
.translation_offset
);
122 dev_info(&info
->bridge
->dev
,
123 "host bridge window %pR\n", res
);
129 get_current_resources(struct acpi_device
*device
, int busnum
,
130 int domain
, struct pci_bus
*bus
)
132 struct pci_root_info info
;
135 info
.bridge
= device
;
138 acpi_walk_resources(device
->handle
, METHOD_NAME__CRS
, count_resource
,
143 size
= sizeof(*info
.res
) * info
.res_num
;
144 info
.res
= kmalloc(size
, GFP_KERNEL
);
148 info
.name
= kmalloc(16, GFP_KERNEL
);
150 goto name_alloc_fail
;
151 sprintf(info
.name
, "PCI Bus %04x:%02x", domain
, busnum
);
154 acpi_walk_resources(device
->handle
, METHOD_NAME__CRS
, setup_resource
,
165 struct pci_bus
* __devinit
pci_acpi_scan_root(struct acpi_device
*device
, int domain
, int busnum
)
168 struct pci_sysdata
*sd
;
170 #ifdef CONFIG_ACPI_NUMA
174 if (domain
&& !pci_domains_supported
) {
175 printk(KERN_WARNING
"PCI: Multiple domains not supported "
176 "(dom %d, bus %d)\n", domain
, busnum
);
181 #ifdef CONFIG_ACPI_NUMA
182 pxm
= acpi_get_pxm(device
->handle
);
184 node
= pxm_to_node(pxm
);
186 set_mp_bus_to_node(busnum
, node
);
189 node
= get_mp_bus_to_node(busnum
);
191 if (node
!= -1 && !node_online(node
))
194 /* Allocate per-root-bus (not per bus) arch-specific data.
195 * TODO: leak; this memory is never freed.
196 * It's arguable whether it's worth the trouble to care.
198 sd
= kzalloc(sizeof(*sd
), GFP_KERNEL
);
200 printk(KERN_ERR
"PCI: OOM, not probing PCI bus %02x\n", busnum
);
207 * Maybe the desired pci bus has been already scanned. In such case
208 * it is unnecessary to scan the pci bus with the given domain,busnum.
210 bus
= pci_find_bus(domain
, busnum
);
213 * If the desired bus exits, the content of bus->sysdata will
216 memcpy(bus
->sysdata
, sd
, sizeof(*sd
));
219 bus
= pci_create_bus(NULL
, busnum
, &pci_root_ops
, sd
);
221 if (pci_probe
& PCI_USE__CRS
)
222 get_current_resources(device
, busnum
, domain
,
224 bus
->subordinate
= pci_scan_child_bus(bus
);
231 if (bus
&& node
!= -1) {
232 #ifdef CONFIG_ACPI_NUMA
234 dev_printk(KERN_DEBUG
, &bus
->dev
,
235 "on NUMA node %d (pxm %d)\n", node
, pxm
);
237 dev_printk(KERN_DEBUG
, &bus
->dev
, "on NUMA node %d\n", node
);
244 int __init
pci_acpi_init(void)
246 struct pci_dev
*dev
= NULL
;
254 printk(KERN_INFO
"PCI: Using ACPI for IRQ routing\n");
255 acpi_irq_penalty_init();
257 pcibios_enable_irq
= acpi_pci_irq_enable
;
258 pcibios_disable_irq
= acpi_pci_irq_disable
;
262 * PCI IRQ routing is set up by pci_enable_device(), but we
263 * also do it here in case there are still broken drivers that
264 * don't use pci_enable_device().
266 printk(KERN_INFO
"PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
267 for_each_pci_dev(dev
)
268 acpi_pci_irq_enable(dev
);