public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
* acpi based pci gap calculation  - v3
@ 2008-07-15 18:59 Alok Kataria
  2008-07-15 20:28 ` Jesse Barnes
  2008-07-16  5:42 ` Andi Kleen
  0 siblings, 2 replies; 17+ messages in thread
From: Alok Kataria @ 2008-07-15 18:59 UTC (permalink / raw)
  To: ak, Ingo Molnar, Brown, Len; +Cc: LKML, linux-acpi


Hi Andi,

I don't see this patch being applied in any of the tree yet.
Resending this incase you guys might have missed it. 
I assume this will go through the ACPI tree. 

The need for this patch was explained in 
http://marc.info/?l=linux-kernel&m=121441818818598&w=2

The v2 patch was discussed in 
http://marc.info/?l=linux-acpi&m=121433339619175&w=2

I then sent a incremental patch on top of v2 to fix some conditions and
handle the change in the e820_search_gap interface. 

In this v3 patch, i have folded the incremental fix into the v2 patch.
Please apply this.

Thanks,
Alok

--
acpi based pci gap calculation - v3

From: Alok N Kataria <akataria@vmware.com>

Evaluates the _CRS object under PCI0 looking for producer resources.
Then searches the e820 memory space for a gap within these producer resources.

Allows us to find a gap for the unclaimed pci resources or MMIO resources
for hotplug devices within the BIOS allowed pci regions.

v1->v2: Some changes in the print strings.
    	Also note the prototype for e820_search_gap has changed in this
    	iteration, but the return value is ignored while calling it over here.
v2->v3: Pass the pci producer resources end_addr (got from _CRS) to the
	e820_search_gap function.
	We limit the search only within the producer region's address space.
	Also add a condition to check if the resource lies in the 32bit
	address range.

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>
---

 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 19af069..fff2c42 100644
--- a/arch/x86/pci/acpi.c
+++ b/arch/x86/pci/acpi.c
@@ -4,6 +4,7 @@
 #include <linux/irq.h>
 #include <linux/dmi.h>
 #include <asm/numa.h>
+#include <asm/e820.h>
 #include "pci.h"
 
 struct pci_root_info {
@@ -14,6 +15,11 @@ struct pci_root_info {
 	int busnum;
 };
 
+struct gap_info {
+	unsigned long gapstart;
+	unsigned long gapsize;
+};
+
 static acpi_status
 resource_to_addr(struct acpi_resource *resource,
 			struct acpi_resource_address64 *addr)
@@ -110,6 +116,78 @@ adjust_transparent_bridge_resources(struct pci_bus *bus)
 	}
 }
 
+static acpi_status search_gap(struct acpi_resource *resource, void *data)
+{
+	struct acpi_resource_address64 addr;
+	acpi_status status;
+	struct gap_info *gap = data;
+	unsigned long long start_addr, end_addr;
+
+	status = resource_to_addr(resource, &addr);
+	if (ACPI_SUCCESS(status) &&
+	    addr.resource_type == ACPI_MEMORY_RANGE &&
+	    addr.address_length > gap->gapsize) {
+		start_addr = addr.minimum + addr.translation_offset;
+		/*
+		 * We want space only in the 32bit address range
+		 */
+		if (start_addr < UINT_MAX) {
+			end_addr = start_addr + addr.address_length;
+			e820_search_gap(&gap->gapstart, &gap->gapsize,
+					start_addr, end_addr);
+		}
+	}
+
+	return AE_OK;
+}
+
+/*
+ * Search for a hole in the 32 bit address space for PCI to assign MMIO
+ * resources, for hotplug or unconfigured resources.
+ * We query the CRS object of the PCI root device to look for possible producer
+ * resources in the tree and consider these while calulating the start address
+ * for this hole.
+ */
+static void pci_setup_gap(acpi_handle *handle)
+{
+	struct gap_info gap;
+	acpi_status status;
+
+	gap.gapstart = 0;
+	gap.gapsize = 0x400000;
+
+	status = acpi_walk_resources(handle, METHOD_NAME__CRS,
+				     search_gap, &gap);
+
+	if (ACPI_SUCCESS(status)) {
+		unsigned long round;
+
+		if (!gap.gapstart) {
+			printk(KERN_ERR "ACPI: Warning: Cannot find a gap "
+					"in the 32bit address range for PCI\n"
+					"ACPI: PCI devices may collide with "
+					"hotpluggable memory address range\n");
+		}
+		/*
+		 * Round the gapstart, uses the same logic as in
+		 * e820_gap_setup
+		 */
+		round = 0x100000;
+		while ((gap.gapsize >> 4) > round)
+			round += round;
+		/* Fun with two's complement */
+		pci_mem_start = (gap.gapstart + round) & -round;
+
+		printk(KERN_INFO "ACPI: PCI resources should "
+				"start at %lx (gap: %lx:%lx)\n",
+				pci_mem_start, gap.gapstart, gap.gapsize);
+	} else {
+		printk(KERN_ERR "ACPI: Error while searching for gap in "
+				"the 32bit address range for PCI\n");
+	}
+}
+
+
 static void
 get_current_resources(struct acpi_device *device, int busnum,
 			int domain, struct pci_bus *bus)
@@ -220,6 +298,8 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int do
 
 	if (bus && (pci_probe & PCI_USE__CRS))
 		get_current_resources(device, busnum, domain, bus);
+
+	pci_setup_gap(device->handle);
 	return bus;
 }
 



^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2008-07-23 18:02 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-15 18:59 acpi based pci gap calculation - v3 Alok Kataria
2008-07-15 20:28 ` Jesse Barnes
2008-07-15 20:54   ` Alok Kataria
2008-07-15 22:53     ` Jesse Barnes
2008-07-15 23:07       ` Ingo Molnar
2008-07-16  5:40       ` Andi Kleen
2008-07-16 16:06         ` Jesse Barnes
2008-07-16 16:33           ` Andi Kleen
2008-07-17  0:03             ` Jesse Barnes
2008-07-17 21:31               ` Alok Kataria
     [not found]                 ` <1216663147.26169.5.camel@alok-dev1>
     [not found]                   ` <200807221450.52114.jbarnes@virtuousgeek.org>
2008-07-22 22:52                     ` Alok Kataria
2008-07-23  7:13                       ` TJ
2008-07-23 16:58                       ` Jesse Barnes
2008-07-23 17:10                         ` Alok Kataria
2008-07-23 17:52                           ` Jesse Barnes
2008-07-23 18:02                             ` Alok Kataria
2008-07-16  5:42 ` Andi Kleen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox