2 #include <linux/acpi.h>
3 #include <linux/init.h>
10 struct pci_root_info
{
19 unsigned long gapstart
;
20 unsigned long gapsize
;
24 resource_to_addr(struct acpi_resource
*resource
,
25 struct acpi_resource_address64
*addr
)
29 status
= acpi_resource_to_address64(resource
, addr
);
30 if (ACPI_SUCCESS(status
) &&
31 (addr
->resource_type
== ACPI_MEMORY_RANGE
||
32 addr
->resource_type
== ACPI_IO_RANGE
) &&
33 addr
->address_length
> 0 &&
34 addr
->producer_consumer
== ACPI_PRODUCER
) {
41 count_resource(struct acpi_resource
*acpi_res
, void *data
)
43 struct pci_root_info
*info
= data
;
44 struct acpi_resource_address64 addr
;
47 if (info
->res_num
>= PCI_BUS_NUM_RESOURCES
)
50 status
= resource_to_addr(acpi_res
, &addr
);
51 if (ACPI_SUCCESS(status
))
57 setup_resource(struct acpi_resource
*acpi_res
, void *data
)
59 struct pci_root_info
*info
= data
;
61 struct acpi_resource_address64 addr
;
64 struct resource
*root
;
66 if (info
->res_num
>= PCI_BUS_NUM_RESOURCES
)
69 status
= resource_to_addr(acpi_res
, &addr
);
70 if (!ACPI_SUCCESS(status
))
73 if (addr
.resource_type
== ACPI_MEMORY_RANGE
) {
74 root
= &iomem_resource
;
75 flags
= IORESOURCE_MEM
;
76 if (addr
.info
.mem
.caching
== ACPI_PREFETCHABLE_MEMORY
)
77 flags
|= IORESOURCE_PREFETCH
;
78 } else if (addr
.resource_type
== ACPI_IO_RANGE
) {
79 root
= &ioport_resource
;
80 flags
= IORESOURCE_IO
;
84 res
= &info
->res
[info
->res_num
];
85 res
->name
= info
->name
;
87 res
->start
= addr
.minimum
+ addr
.translation_offset
;
88 res
->end
= res
->start
+ addr
.address_length
- 1;
91 if (insert_resource(root
, res
)) {
92 printk(KERN_ERR
"PCI: Failed to allocate 0x%lx-0x%lx "
93 "from %s for %s\n", (unsigned long) res
->start
,
94 (unsigned long) res
->end
, root
->name
, info
->name
);
96 info
->bus
->resource
[info
->res_num
] = res
;
103 adjust_transparent_bridge_resources(struct pci_bus
*bus
)
107 list_for_each_entry(dev
, &bus
->devices
, bus_list
) {
109 u16
class = dev
->class >> 8;
111 if (class == PCI_CLASS_BRIDGE_PCI
&& dev
->transparent
) {
112 for(i
= 3; i
< PCI_BUS_NUM_RESOURCES
; i
++)
113 dev
->subordinate
->resource
[i
] =
114 dev
->bus
->resource
[i
- 3];
119 static acpi_status
search_gap(struct acpi_resource
*resource
, void *data
)
121 struct acpi_resource_address64 addr
;
123 struct gap_info
*gap
= data
;
124 unsigned long long start_addr
, end_addr
;
126 status
= resource_to_addr(resource
, &addr
);
127 if (ACPI_SUCCESS(status
) &&
128 addr
.resource_type
== ACPI_MEMORY_RANGE
&&
129 addr
.address_length
> gap
->gapsize
) {
130 start_addr
= addr
.minimum
+ addr
.translation_offset
;
132 * We want space only in the 32bit address range
134 if (start_addr
< UINT_MAX
) {
135 end_addr
= start_addr
+ addr
.address_length
;
136 e820_search_gap(&gap
->gapstart
, &gap
->gapsize
,
137 start_addr
, end_addr
);
145 * Search for a hole in the 32 bit address space for PCI to assign MMIO
146 * resources, for hotplug or unconfigured resources.
147 * We query the CRS object of the PCI root device to look for possible producer
148 * resources in the tree and consider these while calulating the start address
151 static void pci_setup_gap(acpi_handle
*handle
)
157 gap
.gapsize
= 0x400000;
159 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
162 if (ACPI_SUCCESS(status
)) {
166 printk(KERN_ERR
"ACPI: Warning: Cannot find a gap "
167 "in the 32bit address range for PCI\n"
168 "ACPI: PCI devices may collide with "
169 "hotpluggable memory address range\n");
172 * Round the gapstart, uses the same logic as in
176 while ((gap
.gapsize
>> 4) > round
)
178 /* Fun with two's complement */
179 pci_mem_start
= (gap
.gapstart
+ round
) & -round
;
181 printk(KERN_INFO
"ACPI: PCI resources should "
182 "start at %lx (gap: %lx:%lx)\n",
183 pci_mem_start
, gap
.gapstart
, gap
.gapsize
);
185 printk(KERN_ERR
"ACPI: Error while searching for gap in "
186 "the 32bit address range for PCI\n");
192 get_current_resources(struct acpi_device
*device
, int busnum
,
193 int domain
, struct pci_bus
*bus
)
195 struct pci_root_info info
;
200 acpi_walk_resources(device
->handle
, METHOD_NAME__CRS
, count_resource
,
205 size
= sizeof(*info
.res
) * info
.res_num
;
206 info
.res
= kmalloc(size
, GFP_KERNEL
);
210 info
.name
= kmalloc(16, GFP_KERNEL
);
212 goto name_alloc_fail
;
213 sprintf(info
.name
, "PCI Bus %04x:%02x", domain
, busnum
);
216 acpi_walk_resources(device
->handle
, METHOD_NAME__CRS
, setup_resource
,
219 adjust_transparent_bridge_resources(bus
);
229 struct pci_bus
* __devinit
pci_acpi_scan_root(struct acpi_device
*device
, int domain
, int busnum
)
232 struct pci_sysdata
*sd
;
234 #ifdef CONFIG_ACPI_NUMA
238 if (domain
&& !pci_domains_supported
) {
239 printk(KERN_WARNING
"PCI: Multiple domains not supported "
240 "(dom %d, bus %d)\n", domain
, busnum
);
245 #ifdef CONFIG_ACPI_NUMA
246 pxm
= acpi_get_pxm(device
->handle
);
248 node
= pxm_to_node(pxm
);
250 set_mp_bus_to_node(busnum
, node
);
252 node
= get_mp_bus_to_node(busnum
);
255 /* Allocate per-root-bus (not per bus) arch-specific data.
256 * TODO: leak; this memory is never freed.
257 * It's arguable whether it's worth the trouble to care.
259 sd
= kzalloc(sizeof(*sd
), GFP_KERNEL
);
261 printk(KERN_ERR
"PCI: OOM, not probing PCI bus %02x\n", busnum
);
268 * Maybe the desired pci bus has been already scanned. In such case
269 * it is unnecessary to scan the pci bus with the given domain,busnum.
271 bus
= pci_find_bus(domain
, busnum
);
274 * If the desired bus exits, the content of bus->sysdata will
277 memcpy(bus
->sysdata
, sd
, sizeof(*sd
));
280 bus
= pci_scan_bus_parented(NULL
, busnum
, &pci_root_ops
, sd
);
285 #ifdef CONFIG_ACPI_NUMA
288 printk(KERN_DEBUG
"bus %02x -> pxm %d -> node %d\n",
289 busnum
, pxm
, pxm_to_node(pxm
));
294 if (bus
&& (pci_probe
& PCI_USE__CRS
))
295 get_current_resources(device
, busnum
, domain
, bus
);
297 pci_setup_gap(device
->handle
);
301 extern int pci_routeirq
;
302 static int __init
pci_acpi_init(void)
304 struct pci_dev
*dev
= NULL
;
312 printk(KERN_INFO
"PCI: Using ACPI for IRQ routing\n");
313 acpi_irq_penalty_init();
315 pcibios_enable_irq
= acpi_pci_irq_enable
;
316 pcibios_disable_irq
= acpi_pci_irq_disable
;
320 * PCI IRQ routing is set up by pci_enable_device(), but we
321 * also do it here in case there are still broken drivers that
322 * don't use pci_enable_device().
324 printk(KERN_INFO
"PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
325 for_each_pci_dev(dev
)
326 acpi_pci_irq_enable(dev
);
329 #ifdef CONFIG_X86_IO_APIC
336 subsys_initcall(pci_acpi_init
);