diff options
author | Alok Kataria <akataria@vmware.com> | 2008-07-15 14:59:42 -0400 |
---|---|---|
committer | Jesse Barnes <jbarnes@virtuousgeek.org> | 2008-07-15 18:49:03 -0400 |
commit | 809d9a8f93bd8504dcc34b16bbfdfd1a8c9bb1ed (patch) | |
tree | 52a090a2a10a126f3b4762fd6c98d58f5441a6d0 | |
parent | c300bd2fb583afb6d68804afd38bc90b31310d95 (diff) |
x86/PCI: ACPI based PCI gap calculation
Using ACPI to find free address space allows us to find a gap for the
unallocated PCI resources or MMIO resources for hotplug devices within
the BIOS allowed PCI regions.
It works by evaluating the _CRS object under PCI0 looking for producer
resources. Then searches the e820 memory space for a gap within these
producer resources.
Signed-off-by: Alok N Kataria <akataria@vmware.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Len Brown <lenb@kernel.org>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
-rw-r--r-- | arch/x86/pci/acpi.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c index d95de2f199cd..d1ffb5709174 100644 --- a/arch/x86/pci/acpi.c +++ b/arch/x86/pci/acpi.c | |||
@@ -4,6 +4,7 @@ | |||
4 | #include <linux/irq.h> | 4 | #include <linux/irq.h> |
5 | #include <linux/dmi.h> | 5 | #include <linux/dmi.h> |
6 | #include <asm/numa.h> | 6 | #include <asm/numa.h> |
7 | #include <asm/e820.h> | ||
7 | #include "pci.h" | 8 | #include "pci.h" |
8 | 9 | ||
9 | struct pci_root_info { | 10 | struct pci_root_info { |
@@ -14,6 +15,11 @@ struct pci_root_info { | |||
14 | int busnum; | 15 | int busnum; |
15 | }; | 16 | }; |
16 | 17 | ||
18 | struct gap_info { | ||
19 | unsigned long gapstart; | ||
20 | unsigned long gapsize; | ||
21 | }; | ||
22 | |||
17 | static acpi_status | 23 | static acpi_status |
18 | resource_to_addr(struct acpi_resource *resource, | 24 | resource_to_addr(struct acpi_resource *resource, |
19 | struct acpi_resource_address64 *addr) | 25 | struct acpi_resource_address64 *addr) |
@@ -110,6 +116,78 @@ adjust_transparent_bridge_resources(struct pci_bus *bus) | |||
110 | } | 116 | } |
111 | } | 117 | } |
112 | 118 | ||
119 | static acpi_status search_gap(struct acpi_resource *resource, void *data) | ||
120 | { | ||
121 | struct acpi_resource_address64 addr; | ||
122 | acpi_status status; | ||
123 | struct gap_info *gap = data; | ||
124 | unsigned long long start_addr, end_addr; | ||
125 | |||
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; | ||
131 | /* | ||
132 | * We want space only in the 32bit address range | ||
133 | */ | ||
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); | ||
138 | } | ||
139 | } | ||
140 | |||
141 | return AE_OK; | ||
142 | } | ||
143 | |||
144 | /* | ||
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 | ||
149 | * for this hole. | ||
150 | */ | ||
151 | static void pci_setup_gap(acpi_handle *handle) | ||
152 | { | ||
153 | struct gap_info gap; | ||
154 | acpi_status status; | ||
155 | |||
156 | gap.gapstart = 0; | ||
157 | gap.gapsize = 0x400000; | ||
158 | |||
159 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, | ||
160 | search_gap, &gap); | ||
161 | |||
162 | if (ACPI_SUCCESS(status)) { | ||
163 | unsigned long round; | ||
164 | |||
165 | if (!gap.gapstart) { | ||
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"); | ||
170 | } | ||
171 | /* | ||
172 | * Round the gapstart, uses the same logic as in | ||
173 | * e820_gap_setup | ||
174 | */ | ||
175 | round = 0x100000; | ||
176 | while ((gap.gapsize >> 4) > round) | ||
177 | round += round; | ||
178 | /* Fun with two's complement */ | ||
179 | pci_mem_start = (gap.gapstart + round) & -round; | ||
180 | |||
181 | printk(KERN_INFO "ACPI: PCI resources should " | ||
182 | "start at %lx (gap: %lx:%lx)\n", | ||
183 | pci_mem_start, gap.gapstart, gap.gapsize); | ||
184 | } else { | ||
185 | printk(KERN_ERR "ACPI: Error while searching for gap in " | ||
186 | "the 32bit address range for PCI\n"); | ||
187 | } | ||
188 | } | ||
189 | |||
190 | |||
113 | static void | 191 | static void |
114 | get_current_resources(struct acpi_device *device, int busnum, | 192 | get_current_resources(struct acpi_device *device, int busnum, |
115 | int domain, struct pci_bus *bus) | 193 | int domain, struct pci_bus *bus) |
@@ -215,6 +293,8 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int do | |||
215 | 293 | ||
216 | if (bus && (pci_probe & PCI_USE__CRS)) | 294 | if (bus && (pci_probe & PCI_USE__CRS)) |
217 | get_current_resources(device, busnum, domain, bus); | 295 | get_current_resources(device, busnum, domain, bus); |
296 | |||
297 | pci_setup_gap(device->handle); | ||
218 | return bus; | 298 | return bus; |
219 | } | 299 | } |
220 | 300 | ||