]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
[PATCH] unify PFN_* macros
authorDave Hansen <haveblue@us.ibm.com>
Mon, 27 Mar 2006 09:16:04 +0000 (01:16 -0800)
committerLinus Torvalds <torvalds@g5.osdl.org>
Mon, 27 Mar 2006 16:44:48 +0000 (08:44 -0800)
Just about every architecture defines some macros to do operations on pfns.
 They're all virtually identical.  This patch consolidates all of them.

One minor glitch is that at least i386 uses them in a very skeletal header
file.  To keep away from #include dependency hell, I stuck the new
definitions in a new, isolated header.

Of all of the implementations, sh64 is the only one that varied by a bit.
It used some masks to ensure that any sign-extension got ripped away before
the arithmetic is done.  This has been posted to that sh64 maintainers and
the development list.

Compiles on x86, x86_64, ia64 and ppc64.

Signed-off-by: Dave Hansen <haveblue@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
23 files changed:
arch/alpha/kernel/setup.c
arch/alpha/mm/numa.c
arch/arm26/mm/init.c
arch/cris/kernel/setup.c
arch/i386/kernel/setup.c
arch/i386/mm/discontig.c
arch/m32r/kernel/setup.c
arch/m32r/mm/discontig.c
arch/m32r/mm/init.c
arch/mips/ite-boards/ivr/init.c
arch/mips/ite-boards/qed-4n-s01b/init.c
arch/mips/kernel/setup.c
arch/mips/mips-boards/generic/memory.c
arch/mips/mips-boards/sim/sim_mem.c
arch/mips/mm/init.c
arch/mips/sgi-ip27/ip27-memory.c
arch/sh/kernel/setup.c
arch/sh64/kernel/setup.c
arch/um/kernel/physmem.c
include/asm-i386/setup.h
include/asm-m32r/setup.h
include/asm-sh64/platform.h
include/linux/pfn.h [new file with mode: 0644]

index b4e5f8ff2b25671242d110c1081d6489831ed536..9402624453c25fbab70a6fa7d7984b6bd0537e9e 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/root_dev.h>
 #include <linux/initrd.h>
 #include <linux/eisa.h>
+#include <linux/pfn.h>
 #ifdef CONFIG_MAGIC_SYSRQ
 #include <linux/sysrq.h>
 #include <linux/reboot.h>
@@ -241,9 +242,6 @@ reserve_std_resources(void)
                request_resource(io, standard_io_resources+i);
 }
 
-#define PFN_UP(x)      (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
-#define PFN_DOWN(x)    ((x) >> PAGE_SHIFT)
-#define PFN_PHYS(x)    ((x) << PAGE_SHIFT)
 #define PFN_MAX                PFN_DOWN(0x80000000)
 #define for_each_mem_cluster(memdesc, cluster, i)              \
        for ((cluster) = (memdesc)->cluster, (i) = 0;           \
@@ -472,11 +470,6 @@ page_is_ram(unsigned long pfn)
        return 0;
 }
 
-#undef PFN_UP
-#undef PFN_DOWN
-#undef PFN_PHYS
-#undef PFN_MAX
-
 void __init
 setup_arch(char **cmdline_p)
 {
index 6d5251254f68f7dd7c8b3797211536b7d40dfff5..bf6b65c81befda0c62b2364104dd1681cd7afcac 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/bootmem.h>
 #include <linux/swap.h>
 #include <linux/initrd.h>
+#include <linux/pfn.h>
 
 #include <asm/hwrpb.h>
 #include <asm/pgalloc.h>
@@ -27,9 +28,6 @@ bootmem_data_t node_bdata[MAX_NUMNODES];
 #define DBGDCONT(args...)
 #endif
 
-#define PFN_UP(x)       (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
-#define PFN_DOWN(x)     ((x) >> PAGE_SHIFT)
-#define PFN_PHYS(x)     ((x) << PAGE_SHIFT)
 #define for_each_mem_cluster(memdesc, cluster, i)              \
        for ((cluster) = (memdesc)->cluster, (i) = 0;           \
             (i) < (memdesc)->numclusters; (i)++, (cluster)++)
index e3ecaa4537478d8cb8c9f47f114f9eae76d46228..7da8a520567874d13f8f6ee619e56ac52d7e9317 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/initrd.h>
 #include <linux/bootmem.h>
 #include <linux/blkdev.h>
+#include <linux/pfn.h>
 
 #include <asm/segment.h>
 #include <asm/mach-types.h>
@@ -101,12 +102,6 @@ struct node_info {
        int bootmap_pages;
 };
 
-#define PFN_DOWN(x)    ((x) >> PAGE_SHIFT)
-#define PFN_UP(x)      (PAGE_ALIGN(x) >> PAGE_SHIFT)
-#define PFN_SIZE(x)    ((x) >> PAGE_SHIFT)
-#define PFN_RANGE(s,e) PFN_SIZE(PAGE_ALIGN((unsigned long)(e)) - \
-                               (((unsigned long)(s)) & PAGE_MASK))
-
 /*
  * FIXME: We really want to avoid allocating the bootmap bitmap
  * over the top of the initrd.  Hopefully, this is located towards
index 1ba57efff60d5efb96194a7bd0f88f81fa9a58a5..619a6eefd893d6762f6dd068d73634a6c8113989 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/seq_file.h>
 #include <linux/tty.h>
 #include <linux/utsname.h>
+#include <linux/pfn.h>
 
 #include <asm/setup.h>
 
@@ -88,10 +89,6 @@ setup_arch(char **cmdline_p)
        init_mm.end_data =   (unsigned long) &_edata;
        init_mm.brk =        (unsigned long) &_end;
 
-#define PFN_UP(x)       (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
-#define PFN_DOWN(x)     ((x) >> PAGE_SHIFT)
-#define PFN_PHYS(x)     ((x) << PAGE_SHIFT)
-
        /* min_low_pfn points to the start of DRAM, start_pfn points
         * to the first DRAM pages after the kernel, and max_low_pfn
         * to the end of DRAM.
index 6917daa159ab351a4fe86da9aa6ee5276d959df6..8c08660b4e5dd6c2411fb79fa62cbc557f751a70 100644 (file)
@@ -46,6 +46,7 @@
 #include <linux/kexec.h>
 #include <linux/crash_dump.h>
 #include <linux/dmi.h>
+#include <linux/pfn.h>
 
 #include <video/edid.h>
 
index c3f3ae95e22db20546fae5c538bc23ea762ae1fc..fe6eb901326e6610171a927dddd5e01280d7a71b 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/nodemask.h>
 #include <linux/module.h>
 #include <linux/kexec.h>
+#include <linux/pfn.h>
 
 #include <asm/e820.h>
 #include <asm/setup.h>
index d742037a7ccb86d19cd390f455c7dcd5f6d66c80..0d78942b4c7684d01f63e74c663aa79d0737b233 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/tty.h>
 #include <linux/cpu.h>
 #include <linux/nodemask.h>
+#include <linux/pfn.h>
 
 #include <asm/processor.h>
 #include <asm/pgtable.h>
index 70c8528a0ad5c106c530b158e44c7d1b8eea8c23..cf610a7c5ff0541f8dc051e99fa4825f69a73e31 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/initrd.h>
 #include <linux/nodemask.h>
 #include <linux/module.h>
+#include <linux/pfn.h>
 
 #include <asm/setup.h>
 
index 2e0fe199ce386acbdb8a18619a65abea89b63070..b71348fec1f40165c5711d8cc8491f8574e533ce 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/highmem.h>
 #include <linux/bitops.h>
 #include <linux/nodemask.h>
+#include <linux/pfn.h>
 #include <asm/types.h>
 #include <asm/processor.h>
 #include <asm/page.h>
index ea4e1935fec5963ae73033d97c61ef5484402683..b774db035b3132c69769d37dae693e3889fd1a53 100644 (file)
@@ -45,9 +45,6 @@ extern void  __init prom_init_cmdline(void);
 extern unsigned long __init prom_get_memsize(void);
 extern void __init it8172_init_ram_resource(unsigned long memsize);
 
-#define PFN_UP(x)      (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
-#define PFN_ALIGN(x)   (((unsigned long)(x) + (PAGE_SIZE - 1)) & PAGE_MASK)
-
 const char *get_system_type(void)
 {
        return "Globespan IVR";
index 56dca7e0c21d0c0664d91201abd227978ce5719f..e8ec8be66a80b9d630948312f38654d993273cfb 100644 (file)
@@ -45,9 +45,6 @@ extern void  __init prom_init_cmdline(void);
 extern unsigned long __init prom_get_memsize(void);
 extern void __init it8172_init_ram_resource(unsigned long memsize);
 
-#define PFN_UP(x)      (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
-#define PFN_ALIGN(x)   (((unsigned long)(x) + (PAGE_SIZE - 1)) & PAGE_MASK)
-
 const char *get_system_type(void)
 {
        return "ITE QED-4N-S01B";
index 0cb3b6097e0efecdf1a5ca9142258e5248adc47d..dcbfd27071f043c82f4b14710042d4fe8df2415b 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/highmem.h>
 #include <linux/console.h>
 #include <linux/mmzone.h>
+#include <linux/pfn.h>
 
 #include <asm/addrspace.h>
 #include <asm/bootinfo.h>
@@ -257,10 +258,6 @@ static inline int parse_rd_cmdline(unsigned long* rd_start, unsigned long* rd_en
        return 0;
 }
 
-#define PFN_UP(x)      (((x) + PAGE_SIZE - 1) >> PAGE_SHIFT)
-#define PFN_DOWN(x)    ((x) >> PAGE_SHIFT)
-#define PFN_PHYS(x)    ((x) << PAGE_SHIFT)
-
 #define MAXMEM         HIGHMEM_START
 #define MAXMEM_PFN     PFN_DOWN(MAXMEM)
 
@@ -493,10 +490,6 @@ static inline void resource_init(void)
        }
 }
 
-#undef PFN_UP
-#undef PFN_DOWN
-#undef PFN_PHYS
-
 #undef MAXMEM
 #undef MAXMEM_PFN
 
index ee5e70c95cf3fbdadd877ebd347231d6df955cab..32c9210373ac864e5faab2c8789dff848f3c5322 100644 (file)
@@ -49,9 +49,6 @@ static char *mtypes[3] = {
 /* References to section boundaries */
 extern char _end;
 
-#define PFN_ALIGN(x)    (((unsigned long)(x) + (PAGE_SIZE - 1)) & PAGE_MASK)
-
-
 struct prom_pmemblock * __init prom_getmdesc(void)
 {
        char *memsize_str;
@@ -109,10 +106,10 @@ struct prom_pmemblock * __init prom_getmdesc(void)
 
        mdesc[3].type = yamon_dontuse;
        mdesc[3].base = 0x00100000;
-       mdesc[3].size = CPHYSADDR(PFN_ALIGN(&_end)) - mdesc[3].base;
+       mdesc[3].size = CPHYSADDR(PAGE_ALIGN(&_end)) - mdesc[3].base;
 
        mdesc[4].type = yamon_free;
-       mdesc[4].base = CPHYSADDR(PFN_ALIGN(&_end));
+       mdesc[4].base = CPHYSADDR(PAGE_ALIGN(&_end));
        mdesc[4].size = memsize - mdesc[4].base;
 
        return &mdesc[0];
index 1ec4e75656bd11c395559c9a65b1fff628becd56..e57f737bab10265aeb1b46866336ad57651e24ba 100644 (file)
@@ -42,9 +42,6 @@ static char *mtypes[3] = {
 /* References to section boundaries */
 extern char _end;
 
-#define PFN_ALIGN(x)    (((unsigned long)(x) + (PAGE_SIZE - 1)) & PAGE_MASK)
-
-
 struct prom_pmemblock * __init prom_getmdesc(void)
 {
        unsigned int memsize;
@@ -64,10 +61,10 @@ struct prom_pmemblock * __init prom_getmdesc(void)
 
        mdesc[2].type = simmem_reserved;
        mdesc[2].base = 0x00100000;
-       mdesc[2].size = CPHYSADDR(PFN_ALIGN(&_end)) - mdesc[2].base;
+       mdesc[2].size = CPHYSADDR(PAGE_ALIGN(&_end)) - mdesc[2].base;
 
        mdesc[3].type = simmem_free;
-       mdesc[3].base = CPHYSADDR(PFN_ALIGN(&_end));
+       mdesc[3].base = CPHYSADDR(PAGE_ALIGN(&_end));
        mdesc[3].size = memsize - mdesc[3].base;
 
        return &mdesc[0];
index 52f7d59fe6123b28469802a36120722e6224f365..ad89c442f2998918d52fdac6ad7a98c193fcdfa2 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/highmem.h>
 #include <linux/swap.h>
 #include <linux/proc_fs.h>
+#include <linux/pfn.h>
 
 #include <asm/bootinfo.h>
 #include <asm/cachectl.h>
@@ -177,9 +178,6 @@ void __init paging_init(void)
        free_area_init(zones_size);
 }
 
-#define PFN_UP(x)      (((x) + PAGE_SIZE - 1) >> PAGE_SHIFT)
-#define PFN_DOWN(x)    ((x) >> PAGE_SHIFT)
-
 static inline int page_is_ram(unsigned long pagenr)
 {
        int i;
index e0d095daa5ed76782116ed5909d751e41345404f..6c00dce9f73fbd386e3366700c69c71c5a46f5c8 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/nodemask.h>
 #include <linux/swap.h>
 #include <linux/bootmem.h>
+#include <linux/pfn.h>
 #include <asm/page.h>
 #include <asm/sections.h>
 
@@ -28,8 +29,6 @@
 #include <asm/sn/sn_private.h>
 
 
-#define PFN_UP(x)              (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
-
 #define SLOT_PFNSHIFT           (SLOT_SHIFT - PAGE_SHIFT)
 #define PFN_NASIDSHFT           (NASID_SHFT - PAGE_SHIFT)
 
index c0e79843f580437ef9e3d15ec33148dbf8d2415d..7ee4ca203616fee32ae01be36eab00ec2cab026a 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/root_dev.h>
 #include <linux/utsname.h>
 #include <linux/cpu.h>
+#include <linux/pfn.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
 #include <asm/sections.h>
@@ -275,10 +276,6 @@ void __init setup_arch(char **cmdline_p)
 
        sh_mv_setup(cmdline_p);
 
-#define PFN_UP(x)      (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
-#define PFN_DOWN(x)    ((x) >> PAGE_SHIFT)
-#define PFN_PHYS(x)    ((x) << PAGE_SHIFT)
-
        /*
         * Find the highest page frame number we have available
         */
index c7a7b816a30f3974f25e55690a5ed0eb9d8670c4..d2711c9c9d13954dbadaecdf0665e7b3d06cdbe1 100644 (file)
@@ -48,6 +48,7 @@
 #include <linux/root_dev.h>
 #include <linux/cpu.h>
 #include <linux/initrd.h>
+#include <linux/pfn.h>
 #include <asm/processor.h>
 #include <asm/page.h>
 #include <asm/pgtable.h>
index 0e65340eee33704f141621b46cc2641de0e4f949..0500800df1c130f4c239282f8c624a26ac63d355 100644 (file)
@@ -9,6 +9,7 @@
 #include "linux/vmalloc.h"
 #include "linux/bootmem.h"
 #include "linux/module.h"
+#include "linux/pfn.h"
 #include "asm/types.h"
 #include "asm/pgtable.h"
 #include "kern_util.h"
@@ -316,8 +317,6 @@ void map_memory(unsigned long virt, unsigned long phys, unsigned long len,
        }
 }
 
-#define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
-
 extern int __syscall_stub_start, __binary_start;
 
 void setup_physmem(unsigned long start, unsigned long reserve_end,
index 826a8ca50ac801dd6960e2396d9a55e02e1ba2a4..ee941457b55dcd6e979c43845d625b1274cb86a5 100644 (file)
@@ -6,9 +6,7 @@
 #ifndef _i386_SETUP_H
 #define _i386_SETUP_H
 
-#define PFN_UP(x)      (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
-#define PFN_DOWN(x)    ((x) >> PAGE_SHIFT)
-#define PFN_PHYS(x)    ((x) << PAGE_SHIFT)
+#include <linux/pfn.h>
 
 /*
  * Reserved space for vmalloc and iomap - defined in asm/page.h
index 5f028dc26a9bc2140ee7bf184f539db18ea89452..52f4fa29abfc7e8854d672beb277dd46bba9f3d1 100644 (file)
 #define RAMDISK_PROMPT_FLAG            (0x8000)
 #define RAMDISK_LOAD_FLAG              (0x4000)
 
-#define PFN_UP(x)      (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
-#define PFN_DOWN(x)    ((x) >> PAGE_SHIFT)
-#define PFN_PHYS(x)    ((x) << PAGE_SHIFT)
-
 extern unsigned long memory_start;
 extern unsigned long memory_end;
 
index 7046a9014027e519927cd88438e0f5b4f5c59d05..bd0d9c405a8006c7134a8d7387d07fd38e0cd5ba 100644 (file)
@@ -61,9 +61,4 @@ extern int platform_int_priority[NR_INTC_IRQS];
 #define code_resource (platform_parms.kram_res_p[STANDARD_KRAM_RESOURCES - 2])
 #define data_resource (platform_parms.kram_res_p[STANDARD_KRAM_RESOURCES - 1])
 
-/* Be prepared to 64-bit sign extensions */
-#define PFN_UP(x)       ((((x) + PAGE_SIZE-1) >> PAGE_SHIFT) & 0x000fffff)
-#define PFN_DOWN(x)     (((x) >> PAGE_SHIFT) & 0x000fffff)
-#define PFN_PHYS(x)     ((x) << PAGE_SHIFT)
-
 #endif /* __ASM_SH64_PLATFORM_H */
diff --git a/include/linux/pfn.h b/include/linux/pfn.h
new file mode 100644 (file)
index 0000000..bb01f8b
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef _LINUX_PFN_H_
+#define _LINUX_PFN_H_
+
+#define PFN_ALIGN(x)   (((unsigned long)(x) + (PAGE_SIZE - 1)) & PAGE_MASK)
+#define PFN_UP(x)      (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
+#define PFN_DOWN(x)    ((x) >> PAGE_SHIFT)
+#define PFN_PHYS(x)    ((x) << PAGE_SHIFT)
+
+#endif