
This Patch is mostly to allow SPARSE+NUMA to build.  The changes
separate the SPARSE and DISCONTIG specific code in the ppc64 mmzone.h
header file.  As a patch/change this was pretty straight forward.

This patch also contains a 'fix' for a boot time bug that I spent
way too much time diagnosing.  Here is what caused the bug:

static struct page *sparse_early_mem_map_alloc(int pnum)
{
        struct page *map;
        int nid = early_pfn_to_nid(pnum << PFN_SECTION_SHIFT);

Note that the expression (pnum << PFN_SECTION_SHIFT) is still
of type int.  On ppc64, we had early_pfn_to_nid() defined as:

#define early_pfn_to_nid(pfn)   pa_to_nid((pfn) << PAGE_SHIFT)

Note again that what should be a physical address ((pfn) << PAGE_SHIFT)
is still of type int.  And, it doesn't take too much memory to get
physical addresses that would be 'negative' if of type int or overflow.

I 'fixed' this by a simple cast within the ppc64 early_pfn_to_nid()
macro.  Also, I think we want to change sparse_early_mem_map_alloc()
so that pfn's are always typed as unsigned longs.  I haven't looked
closely at the other sparse routines to determine if there are other
issues like this.

Signed-off-by: Mike Kravetz <kravetz@us.ibm.com>

Signed-off-by: Dave Hansen <haveblue@us.ibm.com>
---

 memhotplug-dave/include/asm-ppc64/mmzone.h |   29 +++++++++++------------------
 1 files changed, 11 insertions(+), 18 deletions(-)

diff -puN include/asm-ppc64/mmzone.h~B-sparse-173-ppc64-sparse-fixes-kravetz include/asm-ppc64/mmzone.h
--- memhotplug/include/asm-ppc64/mmzone.h~B-sparse-173-ppc64-sparse-fixes-kravetz	2005-04-13 14:20:26.000000000 -0700
+++ memhotplug-dave/include/asm-ppc64/mmzone.h	2005-04-13 14:20:26.000000000 -0700
@@ -40,10 +40,6 @@ extern int nr_cpus_in_node[];
 #define MEMORY_INCREMENT_SHIFT 24
 #define MEMORY_INCREMENT (1UL << MEMORY_INCREMENT_SHIFT)
 
-#endif /* !CONFIG_DISCONTIGMEM || !CONFIG_SPARSEMEM */
-
-#ifdef CONFIG_DISCONTIGMEM
-
 /* NUMA debugging, will not work on a DLPAR machine */
 #undef DEBUG_NUMA
 
@@ -64,25 +60,29 @@ static inline int pa_to_nid(unsigned lon
 	return nid;
 }
 
-#define pfn_to_nid(pfn)		pa_to_nid((pfn) << PAGE_SHIFT)
-
 #define node_localnr(pfn, nid)	((pfn) - NODE_DATA(nid)->node_start_pfn)
 
 /*
  * Following are macros that each numa implmentation must define.
  */
 
-/*
- * Given a kernel address, find the home node of the underlying memory.
- */
-#define kvaddr_to_nid(kaddr)	pa_to_nid(__pa(kaddr))
-
 #define node_start_pfn(nid)	(NODE_DATA(nid)->node_start_pfn)
 #define node_end_pfn(nid)	(NODE_DATA(nid)->node_end_pfn)
 
 #define local_mapnr(kvaddr) \
 	( (__pa(kvaddr) >> PAGE_SHIFT) - node_start_pfn(kvaddr_to_nid(kvaddr)) 
 
+#endif /* CONFIG_DISCONTIGMEM || CONFIG_SPARSEMEM */
+
+#ifdef CONFIG_DISCONTIGMEM
+
+/*
+ * Given a kernel address, find the home node of the underlying memory.
+ */
+#define kvaddr_to_nid(kaddr)	pa_to_nid(__pa(kaddr))
+
+#define pfn_to_nid(pfn)		pa_to_nid((unsigned long)(pfn) << PAGE_SHIFT)
+
 /* Written this way to avoid evaluating arguments twice */
 #define discontigmem_pfn_to_page(pfn) \
 ({ \
@@ -103,13 +103,6 @@ static inline int pa_to_nid(unsigned lon
 
 #endif /* CONFIG_DISCONTIGMEM */
 
-#ifdef CONFIG_SPARSEMEM
-#define pa_to_nid(pa)			\
-({					\
-	pfn_to_nid(pa >> PAGE_SHIFT);	\
-})
-#endif /* CONFIG_SPARSEMEM */
-
 #endif /* CONFIG_NEED_MULTIPLE_NODES */
 
 #ifdef CONFIG_NEED_MULTIPLE_NODES
_
