2 #include <linux/acpi.h>
3 #include <linux/init.h>
18 resource_to_addr(struct acpi_resource
*resource
,
19 struct acpi_resource_address64
*addr
)
23 status
= acpi_resource_to_address64(resource
, addr
);
24 if (ACPI_SUCCESS(status
) &&
25 (addr
->resource_type
== ACPI_MEMORY_RANGE
||
26 addr
->resource_type
== ACPI_IO_RANGE
) &&
27 addr
->address_length
> 0 &&
28 addr
->producer_consumer
== ACPI_PRODUCER
) {
35 count_resource(struct acpi_resource
*acpi_res
, void *data
)
37 struct pci_root_info
*info
= data
;
38 struct acpi_resource_address64 addr
;
41 if (info
->res_num
>= PCI_BUS_NUM_RESOURCES
)
44 status
= resource_to_addr(acpi_res
, &addr
);
45 if (ACPI_SUCCESS(status
))
51 setup_resource(struct acpi_resource
*acpi_res
, void *data
)
53 struct pci_root_info
*info
= data
;
55 struct acpi_resource_address64 addr
;
58 struct resource
*root
;
60 if (info
->res_num
>= PCI_BUS_NUM_RESOURCES
)
63 status
= resource_to_addr(acpi_res
, &addr
);
64 if (!ACPI_SUCCESS(status
))
67 if (addr
.resource_type
== ACPI_MEMORY_RANGE
) {
68 root
= &iomem_resource
;
69 flags
= IORESOURCE_MEM
;
70 if (addr
.info
.mem
.caching
== ACPI_PREFETCHABLE_MEMORY
)
71 flags
|= IORESOURCE_PREFETCH
;
72 } else if (addr
.resource_type
== ACPI_IO_RANGE
) {
73 root
= &ioport_resource
;
74 flags
= IORESOURCE_IO
;
78 res
= &info
->res
[info
->res_num
];
79 res
->name
= info
->name
;
81 res
->start
= addr
.minimum
+ addr
.translation_offset
;
82 res
->end
= res
->start
+ addr
.address_length
- 1;
85 if (insert_resource(root
, res
)) {
86 printk(KERN_ERR
"PCI: Failed to allocate 0x%lx-0x%lx "
87 "from %s for %s\n", (unsigned long) res
->start
,
88 (unsigned long) res
->end
, root
->name
, info
->name
);
90 info
->bus
->resource
[info
->res_num
] = res
;
97 adjust_transparent_bridge_resources(struct pci_bus
*bus
)
101 list_for_each_entry(dev
, &bus
->devices
, bus_list
) {
103 u16
class = dev
->class >> 8;
105 if (class == PCI_CLASS_BRIDGE_PCI
&& dev
->transparent
) {
106 for(i
= 3; i
< PCI_BUS_NUM_RESOURCES
; i
++)
107 dev
->subordinate
->resource
[i
] =
108 dev
->bus
->resource
[i
- 3];
114 get_current_resources(struct acpi_device
*device
, int busnum
,
115 int domain
, struct pci_bus
*bus
)
117 struct pci_root_info info
;
122 acpi_walk_resources(device
->handle
, METHOD_NAME__CRS
, count_resource
,
127 size
= sizeof(*info
.res
) * info
.res_num
;
128 info
.res
= kmalloc(size
, GFP_KERNEL
);
132 info
.name
= kmalloc(16, GFP_KERNEL
);
134 goto name_alloc_fail
;
135 sprintf(info
.name
, "PCI Bus %04x:%02x", domain
, busnum
);
138 acpi_walk_resources(device
->handle
, METHOD_NAME__CRS
, setup_resource
,
141 adjust_transparent_bridge_resources(bus
);
151 struct pci_bus
* __devinit
pci_acpi_scan_root(struct acpi_device
*device
, int domain
, int busnum
)
154 struct pci_sysdata
*sd
;
156 #ifdef CONFIG_ACPI_NUMA
160 if (domain
&& !pci_domains_supported
) {
161 printk(KERN_WARNING
"PCI: Multiple domains not supported "
162 "(dom %d, bus %d)\n", domain
, busnum
);
167 #ifdef CONFIG_ACPI_NUMA
168 pxm
= acpi_get_pxm(device
->handle
);
170 node
= pxm_to_node(pxm
);
172 set_mp_bus_to_node(busnum
, node
);
175 node
= get_mp_bus_to_node(busnum
);
177 if (node
!= -1 && !node_online(node
))
180 /* Allocate per-root-bus (not per bus) arch-specific data.
181 * TODO: leak; this memory is never freed.
182 * It's arguable whether it's worth the trouble to care.
184 sd
= kzalloc(sizeof(*sd
), GFP_KERNEL
);
186 printk(KERN_ERR
"PCI: OOM, not probing PCI bus %02x\n", busnum
);
193 * Maybe the desired pci bus has been already scanned. In such case
194 * it is unnecessary to scan the pci bus with the given domain,busnum.
196 bus
= pci_find_bus(domain
, busnum
);
199 * If the desired bus exits, the content of bus->sysdata will
202 memcpy(bus
->sysdata
, sd
, sizeof(*sd
));
205 bus
= pci_scan_bus_parented(NULL
, busnum
, &pci_root_ops
, sd
);
210 if (bus
&& node
!= -1) {
211 #ifdef CONFIG_ACPI_NUMA
213 printk(KERN_DEBUG
"bus %02x -> pxm %d -> node %d\n",
216 printk(KERN_DEBUG
"bus %02x -> node %d\n",
221 if (bus
&& (pci_probe
& PCI_USE__CRS
))
222 get_current_resources(device
, busnum
, domain
, bus
);
226 int __init
pci_acpi_init(void)
228 struct pci_dev
*dev
= NULL
;
236 printk(KERN_INFO
"PCI: Using ACPI for IRQ routing\n");
237 acpi_irq_penalty_init();
239 pcibios_enable_irq
= acpi_pci_irq_enable
;
240 pcibios_disable_irq
= acpi_pci_irq_disable
;
244 * PCI IRQ routing is set up by pci_enable_device(), but we
245 * also do it here in case there are still broken drivers that
246 * don't use pci_enable_device().
248 printk(KERN_INFO
"PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
249 for_each_pci_dev(dev
)
250 acpi_pci_irq_enable(dev
);