This is a preparatory patch for the next patch in series.
Moves some code from e820_setup_gap to a new function e820_search_gap.
This function will be used by the next patch in the series.
Signed-off-by: Alok N Kataria <[email protected]>
Index: linux-2.6/arch/x86/kernel/e820_64.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/e820_64.c 2008-06-12 10:42:22.000000000 -0700
+++ linux-2.6/arch/x86/kernel/e820_64.c 2008-06-13 14:05:18.000000000 -0700
@@ -872,26 +872,20 @@
EXPORT_SYMBOL(pci_mem_start);
/*
- * Search for the biggest gap in the low 32 bits of the e820
- * memory space. We pass this space to PCI to assign MMIO resources
- * for hotplug or unconfigured devices in.
- * Hopefully the BIOS let enough space left.
+ * Search for a gap in the e820 memory space from start_addr to 2^32.
*/
-__init void e820_setup_gap(void)
+__init void e820_search_gap(unsigned long *gapstart, unsigned long *gapsize,
+ unsigned long start_addr)
{
- unsigned long gapstart, gapsize, round;
- unsigned long last;
- int i;
- int found = 0;
+ unsigned long last = 0x100000000ull;
+ int i = e820.nr_map;
- last = 0x100000000ull;
- gapstart = 0x10000000;
- gapsize = 0x400000;
- i = e820.nr_map;
while (--i >= 0) {
unsigned long long start = e820.map[i].addr;
unsigned long long end = start + e820.map[i].size;
+ if (end < start_addr)
+ continue;
/*
* Since "last" is at most 4GB, we know we'll
* fit in 32 bits if this condition is true
@@ -899,17 +893,32 @@
if (last > end) {
unsigned long gap = last - end;
- if (gap > gapsize) {
- gapsize = gap;
- gapstart = end;
- found = 1;
+ if (gap >= *gapsize) {
+ *gapsize = gap;
+ *gapstart = end;
}
}
if (start < last)
last = start;
}
+}
+
+/*
+ * Search for the biggest gap in the low 32 bits of the e820
+ * memory space. We pass this space to PCI to assign MMIO resources
+ * for hotplug or unconfigured devices in.
+ * Hopefully the BIOS let enough space left.
+ */
+__init void e820_setup_gap(void)
+{
+ unsigned long gapstart, gapsize, round;
+
+ gapstart = 0;
+ gapsize = 0x400000;
+
+ e820_search_gap(&gapstart, &gapsize, 0);
- if (!found) {
+ if (!gapstart) {
gapstart = (end_pfn << PAGE_SHIFT) + 1024*1024;
printk(KERN_ERR "PCI: Warning: Cannot find a gap in the 32bit "
"address range\n"
Index: linux-2.6/include/asm-x86/e820_64.h
===================================================================
--- linux-2.6.orig/include/asm-x86/e820_64.h 2008-06-12 10:42:22.000000000 -0700
+++ linux-2.6/include/asm-x86/e820_64.h 2008-06-12 10:55:09.000000000 -0700
@@ -39,6 +39,7 @@
extern unsigned long e820_hole_size(unsigned long start, unsigned long end);
extern void e820_setup_gap(void);
+extern void e820_search_gap(unsigned long *, unsigned long *, unsigned long);
extern void e820_register_active_regions(int nid, unsigned long start_pfn,
unsigned long end_pfn);
* Alok Kataria <[email protected]> wrote:
> This is a preparatory patch for the next patch in series. Moves some
> code from e820_setup_gap to a new function e820_search_gap. This
> function will be used by the next patch in the series.
>
> Signed-off-by: Alok N Kataria <[email protected]>
>
> Index: linux-2.6/arch/x86/kernel/e820_64.c
> ===================================================================
> --- linux-2.6.orig/arch/x86/kernel/e820_64.c 2008-06-12 10:42:22.000000000 -0700
> +++ linux-2.6/arch/x86/kernel/e820_64.c 2008-06-13 14:05:18.000000000 -0700
> @@ -872,26 +872,20 @@
note that this code has significantly changed in x86-next (it has been
fixed, extended, cleaned up and unified). You can find the latest
patches in tip/master at:
http://people.redhat.com/mingo/tip.git/README
tip/master contains the integration of all changes in this area.
We could apply and test your change in tip/x86 as well, as it seems
standalone and independent of ACPI - so that when the acpi change shows
up in linux-next there's a e820_search_gap() function available.
Ingo
Here is the patch based on tip/master
Please have a look
--
This is a preparatory patch for the next patch in series.
Moves some code from e820_setup_gap to a new function e820_search_gap.
This patch is a part of a bug fix where we walk the ACPI table to calculate
a gap for PCI optional devices.
Signed-off-by: Alok N Kataria <[email protected]>
Index: linux-trees.git/arch/x86/kernel/e820.c
===================================================================
--- linux-trees.git.orig/arch/x86/kernel/e820.c 2008-06-20 10:32:44.000000000 -0700
+++ linux-trees.git/arch/x86/kernel/e820.c 2008-06-20 12:27:58.000000000 -0700
@@ -442,26 +442,22 @@
}
/*
- * Search for the biggest gap in the low 32 bits of the e820
- * memory space. We pass this space to PCI to assign MMIO resources
- * for hotplug or unconfigured devices in.
- * Hopefully the BIOS let enough space left.
+ * Search for a gap in the e820 memory space from start_addr to 2^32.
*/
-__init void e820_setup_gap(void)
+__init int e820_search_gap(unsigned long *gapstart, unsigned long *gapsize,
+ unsigned long start_addr)
{
- unsigned long gapstart, gapsize, round;
- unsigned long long last;
- int i;
+ unsigned long last = 0x100000000ull;
+ int i = e820.nr_map;
int found = 0;
- last = 0x100000000ull;
- gapstart = 0x10000000;
- gapsize = 0x400000;
- i = e820.nr_map;
while (--i >= 0) {
unsigned long long start = e820.map[i].addr;
unsigned long long end = start + e820.map[i].size;
+ if (end < start_addr)
+ continue;
+
/*
* Since "last" is at most 4GB, we know we'll
* fit in 32 bits if this condition is true
@@ -469,15 +465,32 @@
if (last > end) {
unsigned long gap = last - end;
- if (gap > gapsize) {
- gapsize = gap;
- gapstart = end;
+ if (gap >= *gapsize) {
+ *gapsize = gap;
+ *gapstart = end;
found = 1;
}
}
if (start < last)
last = start;
}
+ return found;
+}
+
+/*
+ * Search for the biggest gap in the low 32 bits of the e820
+ * memory space. We pass this space to PCI to assign MMIO resources
+ * for hotplug or unconfigured devices in.
+ * Hopefully the BIOS let enough space left.
+ */
+__init void e820_setup_gap(void)
+{
+ unsigned long gapstart, gapsize, round;
+ int found;
+
+ gapstart = 0x10000000;
+ gapsize = 0x400000;
+ found = e820_search_gap(&gapstart, &gapsize, 0);
#ifdef CONFIG_X86_64
if (!found) {
Index: linux-trees.git/include/asm-x86/e820.h
===================================================================
--- linux-trees.git.orig/include/asm-x86/e820.h 2008-06-20 10:32:44.000000000 -0700
+++ linux-trees.git/include/asm-x86/e820.h 2008-06-20 12:18:40.000000000 -0700
@@ -69,6 +69,8 @@
unsigned new_type);
extern void update_e820(void);
extern void e820_setup_gap(void);
+extern int e820_search_gap(unsigned long *gapstart, unsigned long *gapsize,
+ unsigned long start_addr);
struct setup_data;
extern void parse_e820_ext(struct setup_data *data, unsigned long pa_data);
On Fri, Jun 20, 2008 at 12:38 PM, Alok Kataria <[email protected]> wrote:
> Here is the patch based on tip/master
>
> Please have a look
>
> --
>
> This is a preparatory patch for the next patch in series.
> Moves some code from e820_setup_gap to a new function e820_search_gap.
> This patch is a part of a bug fix where we walk the ACPI table to calculate
> a gap for PCI optional devices.
>
> Signed-off-by: Alok N Kataria <[email protected]>
>
> Index: linux-trees.git/arch/x86/kernel/e820.c
> ===================================================================
> --- linux-trees.git.orig/arch/x86/kernel/e820.c 2008-06-20 10:32:44.000000000 -0700
> +++ linux-trees.git/arch/x86/kernel/e820.c 2008-06-20 12:27:58.000000000 -0700
> @@ -442,26 +442,22 @@
> }
>
> /*
> - * Search for the biggest gap in the low 32 bits of the e820
> - * memory space. We pass this space to PCI to assign MMIO resources
> - * for hotplug or unconfigured devices in.
> - * Hopefully the BIOS let enough space left.
> + * Search for a gap in the e820 memory space from start_addr to 2^32.
> */
> -__init void e820_setup_gap(void)
> +__init int e820_search_gap(unsigned long *gapstart, unsigned long *gapsize,
> + unsigned long start_addr)
> {
> - unsigned long gapstart, gapsize, round;
> - unsigned long long last;
> - int i;
> + unsigned long last = 0x100000000ull;
why changing "unsigned long long" to "unsigned long" ?
it will overflow on 32bit
YH
On Fri, 2008-06-20 at 12:50 -0700, Yinghai Lu wrote:
> On Fri, Jun 20, 2008 at 12:38 PM, Alok Kataria <[email protected]> wrote:
> > Here is the patch based on tip/master
> >
> > Please have a look
> >
> > --
> >
> > This is a preparatory patch for the next patch in series.
> > Moves some code from e820_setup_gap to a new function e820_search_gap.
> > This patch is a part of a bug fix where we walk the ACPI table to calculate
> > a gap for PCI optional devices.
> >
> > Signed-off-by: Alok N Kataria <[email protected]>
> >
> > Index: linux-trees.git/arch/x86/kernel/e820.c
> > ===================================================================
> > --- linux-trees.git.orig/arch/x86/kernel/e820.c 2008-06-20 10:32:44.000000000 -0700
> > +++ linux-trees.git/arch/x86/kernel/e820.c 2008-06-20 12:27:58.000000000 -0700
> > @@ -442,26 +442,22 @@
> > }
> >
> > /*
> > - * Search for the biggest gap in the low 32 bits of the e820
> > - * memory space. We pass this space to PCI to assign MMIO resources
> > - * for hotplug or unconfigured devices in.
> > - * Hopefully the BIOS let enough space left.
> > + * Search for a gap in the e820 memory space from start_addr to 2^32.
> > */
> > -__init void e820_setup_gap(void)
> > +__init int e820_search_gap(unsigned long *gapstart, unsigned long *gapsize,
> > + unsigned long start_addr)
> > {
> > - unsigned long gapstart, gapsize, round;
> > - unsigned long long last;
> > - int i;
> > + unsigned long last = 0x100000000ull;
>
> why changing "unsigned long long" to "unsigned long" ?
> it will overflow on 32bit
>
Oops...my bad, it was unsigned long in e820_64.c. Should be more careful
with these cross ports.
Thanks for catching it.
--
This is a preparatory patch for the next patch in series.
Moves some code from e820_setup_gap to a new function e820_search_gap.
This patch is a part of a bug fix where we walk the ACPI table to calculate
a gap for PCI optional devices.
Signed-off-by: Alok N Kataria <[email protected]>
Index: linux-trees.git/arch/x86/kernel/e820.c
===================================================================
--- linux-trees.git.orig/arch/x86/kernel/e820.c 2008-06-20 10:32:44.000000000 -0700
+++ linux-trees.git/arch/x86/kernel/e820.c 2008-06-20 13:23:32.000000000 -0700
@@ -442,26 +442,22 @@
}
/*
- * Search for the biggest gap in the low 32 bits of the e820
- * memory space. We pass this space to PCI to assign MMIO resources
- * for hotplug or unconfigured devices in.
- * Hopefully the BIOS let enough space left.
+ * Search for a gap in the e820 memory space from start_addr to 2^32.
*/
-__init void e820_setup_gap(void)
+__init int e820_search_gap(unsigned long *gapstart, unsigned long *gapsize,
+ unsigned long start_addr)
{
- unsigned long gapstart, gapsize, round;
- unsigned long long last;
- int i;
+ unsigned long long last = 0x100000000ull;
+ int i = e820.nr_map;
int found = 0;
- last = 0x100000000ull;
- gapstart = 0x10000000;
- gapsize = 0x400000;
- i = e820.nr_map;
while (--i >= 0) {
unsigned long long start = e820.map[i].addr;
unsigned long long end = start + e820.map[i].size;
+ if (end < start_addr)
+ continue;
+
/*
* Since "last" is at most 4GB, we know we'll
* fit in 32 bits if this condition is true
@@ -469,15 +465,32 @@
if (last > end) {
unsigned long gap = last - end;
- if (gap > gapsize) {
- gapsize = gap;
- gapstart = end;
+ if (gap >= *gapsize) {
+ *gapsize = gap;
+ *gapstart = end;
found = 1;
}
}
if (start < last)
last = start;
}
+ return found;
+}
+
+/*
+ * Search for the biggest gap in the low 32 bits of the e820
+ * memory space. We pass this space to PCI to assign MMIO resources
+ * for hotplug or unconfigured devices in.
+ * Hopefully the BIOS let enough space left.
+ */
+__init void e820_setup_gap(void)
+{
+ unsigned long gapstart, gapsize, round;
+ int found;
+
+ gapstart = 0x10000000;
+ gapsize = 0x400000;
+ found = e820_search_gap(&gapstart, &gapsize, 0);
#ifdef CONFIG_X86_64
if (!found) {
Index: linux-trees.git/include/asm-x86/e820.h
===================================================================
--- linux-trees.git.orig/include/asm-x86/e820.h 2008-06-20 10:32:44.000000000 -0700
+++ linux-trees.git/include/asm-x86/e820.h 2008-06-20 12:18:40.000000000 -0700
@@ -69,6 +69,8 @@
unsigned new_type);
extern void update_e820(void);
extern void e820_setup_gap(void);
+extern int e820_search_gap(unsigned long *gapstart, unsigned long *gapsize,
+ unsigned long start_addr);
struct setup_data;
extern void parse_e820_ext(struct setup_data *data, unsigned long pa_data);
* Alok Kataria <[email protected]> wrote:
> On Fri, 2008-06-20 at 12:50 -0700, Yinghai Lu wrote:
> > On Fri, Jun 20, 2008 at 12:38 PM, Alok Kataria <[email protected]> wrote:
> > > Here is the patch based on tip/master
> > >
> > > Please have a look
> > >
> > > --
> > >
> > > This is a preparatory patch for the next patch in series.
> > > Moves some code from e820_setup_gap to a new function e820_search_gap.
> > > This patch is a part of a bug fix where we walk the ACPI table to calculate
> > > a gap for PCI optional devices.
> > >
> > > Signed-off-by: Alok N Kataria <[email protected]>
> > >
> > > Index: linux-trees.git/arch/x86/kernel/e820.c
> > > ===================================================================
> > > --- linux-trees.git.orig/arch/x86/kernel/e820.c 2008-06-20 10:32:44.000000000 -0700
> > > +++ linux-trees.git/arch/x86/kernel/e820.c 2008-06-20 12:27:58.000000000 -0700
> > > @@ -442,26 +442,22 @@
> > > }
> > >
> > > /*
> > > - * Search for the biggest gap in the low 32 bits of the e820
> > > - * memory space. We pass this space to PCI to assign MMIO resources
> > > - * for hotplug or unconfigured devices in.
> > > - * Hopefully the BIOS let enough space left.
> > > + * Search for a gap in the e820 memory space from start_addr to 2^32.
> > > */
> > > -__init void e820_setup_gap(void)
> > > +__init int e820_search_gap(unsigned long *gapstart, unsigned long *gapsize,
> > > + unsigned long start_addr)
> > > {
> > > - unsigned long gapstart, gapsize, round;
> > > - unsigned long long last;
> > > - int i;
> > > + unsigned long last = 0x100000000ull;
> >
> > why changing "unsigned long long" to "unsigned long" ?
> > it will overflow on 32bit
> >
>
> Oops...my bad, it was unsigned long in e820_64.c. Should be more careful
> with these cross ports.
> Thanks for catching it.
ok, could you please resend the fixed up series? This breakage would be
a nasty bisection point which we want to avoid.
Ingo