Commit 22a9835c350782a5c3257343713932af3ac92ee0
Committed by
Linus Torvalds
1 parent
95144c788d
Exists in
master
and in
4 other branches
[PATCH] unify PFN_* macros
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>
Showing 23 changed files with 29 additions and 68 deletions Side-by-side Diff
- 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
arch/alpha/kernel/setup.c
| ... | ... | @@ -34,6 +34,7 @@ |
| 34 | 34 | #include <linux/root_dev.h> |
| 35 | 35 | #include <linux/initrd.h> |
| 36 | 36 | #include <linux/eisa.h> |
| 37 | +#include <linux/pfn.h> | |
| 37 | 38 | #ifdef CONFIG_MAGIC_SYSRQ |
| 38 | 39 | #include <linux/sysrq.h> |
| 39 | 40 | #include <linux/reboot.h> |
| ... | ... | @@ -241,9 +242,6 @@ |
| 241 | 242 | request_resource(io, standard_io_resources+i); |
| 242 | 243 | } |
| 243 | 244 | |
| 244 | -#define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT) | |
| 245 | -#define PFN_DOWN(x) ((x) >> PAGE_SHIFT) | |
| 246 | -#define PFN_PHYS(x) ((x) << PAGE_SHIFT) | |
| 247 | 245 | #define PFN_MAX PFN_DOWN(0x80000000) |
| 248 | 246 | #define for_each_mem_cluster(memdesc, cluster, i) \ |
| 249 | 247 | for ((cluster) = (memdesc)->cluster, (i) = 0; \ |
| ... | ... | @@ -471,11 +469,6 @@ |
| 471 | 469 | |
| 472 | 470 | return 0; |
| 473 | 471 | } |
| 474 | - | |
| 475 | -#undef PFN_UP | |
| 476 | -#undef PFN_DOWN | |
| 477 | -#undef PFN_PHYS | |
| 478 | -#undef PFN_MAX | |
| 479 | 472 | |
| 480 | 473 | void __init |
| 481 | 474 | setup_arch(char **cmdline_p) |
arch/alpha/mm/numa.c
| ... | ... | @@ -13,6 +13,7 @@ |
| 13 | 13 | #include <linux/bootmem.h> |
| 14 | 14 | #include <linux/swap.h> |
| 15 | 15 | #include <linux/initrd.h> |
| 16 | +#include <linux/pfn.h> | |
| 16 | 17 | |
| 17 | 18 | #include <asm/hwrpb.h> |
| 18 | 19 | #include <asm/pgalloc.h> |
| ... | ... | @@ -27,9 +28,6 @@ |
| 27 | 28 | #define DBGDCONT(args...) |
| 28 | 29 | #endif |
| 29 | 30 | |
| 30 | -#define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT) | |
| 31 | -#define PFN_DOWN(x) ((x) >> PAGE_SHIFT) | |
| 32 | -#define PFN_PHYS(x) ((x) << PAGE_SHIFT) | |
| 33 | 31 | #define for_each_mem_cluster(memdesc, cluster, i) \ |
| 34 | 32 | for ((cluster) = (memdesc)->cluster, (i) = 0; \ |
| 35 | 33 | (i) < (memdesc)->numclusters; (i)++, (cluster)++) |
arch/arm26/mm/init.c
| ... | ... | @@ -23,6 +23,7 @@ |
| 23 | 23 | #include <linux/initrd.h> |
| 24 | 24 | #include <linux/bootmem.h> |
| 25 | 25 | #include <linux/blkdev.h> |
| 26 | +#include <linux/pfn.h> | |
| 26 | 27 | |
| 27 | 28 | #include <asm/segment.h> |
| 28 | 29 | #include <asm/mach-types.h> |
| ... | ... | @@ -100,12 +101,6 @@ |
| 100 | 101 | unsigned int end; |
| 101 | 102 | int bootmap_pages; |
| 102 | 103 | }; |
| 103 | - | |
| 104 | -#define PFN_DOWN(x) ((x) >> PAGE_SHIFT) | |
| 105 | -#define PFN_UP(x) (PAGE_ALIGN(x) >> PAGE_SHIFT) | |
| 106 | -#define PFN_SIZE(x) ((x) >> PAGE_SHIFT) | |
| 107 | -#define PFN_RANGE(s,e) PFN_SIZE(PAGE_ALIGN((unsigned long)(e)) - \ | |
| 108 | - (((unsigned long)(s)) & PAGE_MASK)) | |
| 109 | 104 | |
| 110 | 105 | /* |
| 111 | 106 | * FIXME: We really want to avoid allocating the bootmap bitmap |
arch/cris/kernel/setup.c
| ... | ... | @@ -18,6 +18,7 @@ |
| 18 | 18 | #include <linux/seq_file.h> |
| 19 | 19 | #include <linux/tty.h> |
| 20 | 20 | #include <linux/utsname.h> |
| 21 | +#include <linux/pfn.h> | |
| 21 | 22 | |
| 22 | 23 | #include <asm/setup.h> |
| 23 | 24 | |
| ... | ... | @@ -87,10 +88,6 @@ |
| 87 | 88 | init_mm.end_code = (unsigned long) &_etext; |
| 88 | 89 | init_mm.end_data = (unsigned long) &_edata; |
| 89 | 90 | init_mm.brk = (unsigned long) &_end; |
| 90 | - | |
| 91 | -#define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT) | |
| 92 | -#define PFN_DOWN(x) ((x) >> PAGE_SHIFT) | |
| 93 | -#define PFN_PHYS(x) ((x) << PAGE_SHIFT) | |
| 94 | 91 | |
| 95 | 92 | /* min_low_pfn points to the start of DRAM, start_pfn points |
| 96 | 93 | * to the first DRAM pages after the kernel, and max_low_pfn |
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
| ... | ... | @@ -45,9 +45,6 @@ |
| 45 | 45 | extern unsigned long __init prom_get_memsize(void); |
| 46 | 46 | extern void __init it8172_init_ram_resource(unsigned long memsize); |
| 47 | 47 | |
| 48 | -#define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT) | |
| 49 | -#define PFN_ALIGN(x) (((unsigned long)(x) + (PAGE_SIZE - 1)) & PAGE_MASK) | |
| 50 | - | |
| 51 | 48 | const char *get_system_type(void) |
| 52 | 49 | { |
| 53 | 50 | return "Globespan IVR"; |
arch/mips/ite-boards/qed-4n-s01b/init.c
| ... | ... | @@ -45,9 +45,6 @@ |
| 45 | 45 | extern unsigned long __init prom_get_memsize(void); |
| 46 | 46 | extern void __init it8172_init_ram_resource(unsigned long memsize); |
| 47 | 47 | |
| 48 | -#define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT) | |
| 49 | -#define PFN_ALIGN(x) (((unsigned long)(x) + (PAGE_SIZE - 1)) & PAGE_MASK) | |
| 50 | - | |
| 51 | 48 | const char *get_system_type(void) |
| 52 | 49 | { |
| 53 | 50 | return "ITE QED-4N-S01B"; |
arch/mips/kernel/setup.c
| ... | ... | @@ -34,6 +34,7 @@ |
| 34 | 34 | #include <linux/highmem.h> |
| 35 | 35 | #include <linux/console.h> |
| 36 | 36 | #include <linux/mmzone.h> |
| 37 | +#include <linux/pfn.h> | |
| 37 | 38 | |
| 38 | 39 | #include <asm/addrspace.h> |
| 39 | 40 | #include <asm/bootinfo.h> |
| ... | ... | @@ -257,10 +258,6 @@ |
| 257 | 258 | return 0; |
| 258 | 259 | } |
| 259 | 260 | |
| 260 | -#define PFN_UP(x) (((x) + PAGE_SIZE - 1) >> PAGE_SHIFT) | |
| 261 | -#define PFN_DOWN(x) ((x) >> PAGE_SHIFT) | |
| 262 | -#define PFN_PHYS(x) ((x) << PAGE_SHIFT) | |
| 263 | - | |
| 264 | 261 | #define MAXMEM HIGHMEM_START |
| 265 | 262 | #define MAXMEM_PFN PFN_DOWN(MAXMEM) |
| 266 | 263 | |
| ... | ... | @@ -492,10 +489,6 @@ |
| 492 | 489 | request_resource(res, &data_resource); |
| 493 | 490 | } |
| 494 | 491 | } |
| 495 | - | |
| 496 | -#undef PFN_UP | |
| 497 | -#undef PFN_DOWN | |
| 498 | -#undef PFN_PHYS | |
| 499 | 492 | |
| 500 | 493 | #undef MAXMEM |
| 501 | 494 | #undef MAXMEM_PFN |
arch/mips/mips-boards/generic/memory.c
| ... | ... | @@ -49,9 +49,6 @@ |
| 49 | 49 | /* References to section boundaries */ |
| 50 | 50 | extern char _end; |
| 51 | 51 | |
| 52 | -#define PFN_ALIGN(x) (((unsigned long)(x) + (PAGE_SIZE - 1)) & PAGE_MASK) | |
| 53 | - | |
| 54 | - | |
| 55 | 52 | struct prom_pmemblock * __init prom_getmdesc(void) |
| 56 | 53 | { |
| 57 | 54 | char *memsize_str; |
| 58 | 55 | |
| ... | ... | @@ -109,10 +106,10 @@ |
| 109 | 106 | |
| 110 | 107 | mdesc[3].type = yamon_dontuse; |
| 111 | 108 | mdesc[3].base = 0x00100000; |
| 112 | - mdesc[3].size = CPHYSADDR(PFN_ALIGN(&_end)) - mdesc[3].base; | |
| 109 | + mdesc[3].size = CPHYSADDR(PAGE_ALIGN(&_end)) - mdesc[3].base; | |
| 113 | 110 | |
| 114 | 111 | mdesc[4].type = yamon_free; |
| 115 | - mdesc[4].base = CPHYSADDR(PFN_ALIGN(&_end)); | |
| 112 | + mdesc[4].base = CPHYSADDR(PAGE_ALIGN(&_end)); | |
| 116 | 113 | mdesc[4].size = memsize - mdesc[4].base; |
| 117 | 114 | |
| 118 | 115 | return &mdesc[0]; |
arch/mips/mips-boards/sim/sim_mem.c
| ... | ... | @@ -42,9 +42,6 @@ |
| 42 | 42 | /* References to section boundaries */ |
| 43 | 43 | extern char _end; |
| 44 | 44 | |
| 45 | -#define PFN_ALIGN(x) (((unsigned long)(x) + (PAGE_SIZE - 1)) & PAGE_MASK) | |
| 46 | - | |
| 47 | - | |
| 48 | 45 | struct prom_pmemblock * __init prom_getmdesc(void) |
| 49 | 46 | { |
| 50 | 47 | unsigned int memsize; |
| 51 | 48 | |
| ... | ... | @@ -64,10 +61,10 @@ |
| 64 | 61 | |
| 65 | 62 | mdesc[2].type = simmem_reserved; |
| 66 | 63 | mdesc[2].base = 0x00100000; |
| 67 | - mdesc[2].size = CPHYSADDR(PFN_ALIGN(&_end)) - mdesc[2].base; | |
| 64 | + mdesc[2].size = CPHYSADDR(PAGE_ALIGN(&_end)) - mdesc[2].base; | |
| 68 | 65 | |
| 69 | 66 | mdesc[3].type = simmem_free; |
| 70 | - mdesc[3].base = CPHYSADDR(PFN_ALIGN(&_end)); | |
| 67 | + mdesc[3].base = CPHYSADDR(PAGE_ALIGN(&_end)); | |
| 71 | 68 | mdesc[3].size = memsize - mdesc[3].base; |
| 72 | 69 | |
| 73 | 70 | return &mdesc[0]; |
arch/mips/mm/init.c
| ... | ... | @@ -25,6 +25,7 @@ |
| 25 | 25 | #include <linux/highmem.h> |
| 26 | 26 | #include <linux/swap.h> |
| 27 | 27 | #include <linux/proc_fs.h> |
| 28 | +#include <linux/pfn.h> | |
| 28 | 29 | |
| 29 | 30 | #include <asm/bootinfo.h> |
| 30 | 31 | #include <asm/cachectl.h> |
| ... | ... | @@ -176,9 +177,6 @@ |
| 176 | 177 | |
| 177 | 178 | free_area_init(zones_size); |
| 178 | 179 | } |
| 179 | - | |
| 180 | -#define PFN_UP(x) (((x) + PAGE_SIZE - 1) >> PAGE_SHIFT) | |
| 181 | -#define PFN_DOWN(x) ((x) >> PAGE_SHIFT) | |
| 182 | 180 | |
| 183 | 181 | static inline int page_is_ram(unsigned long pagenr) |
| 184 | 182 | { |
arch/mips/sgi-ip27/ip27-memory.c
| ... | ... | @@ -19,6 +19,7 @@ |
| 19 | 19 | #include <linux/nodemask.h> |
| 20 | 20 | #include <linux/swap.h> |
| 21 | 21 | #include <linux/bootmem.h> |
| 22 | +#include <linux/pfn.h> | |
| 22 | 23 | #include <asm/page.h> |
| 23 | 24 | #include <asm/sections.h> |
| 24 | 25 | |
| ... | ... | @@ -27,8 +28,6 @@ |
| 27 | 28 | #include <asm/sn/klconfig.h> |
| 28 | 29 | #include <asm/sn/sn_private.h> |
| 29 | 30 | |
| 30 | - | |
| 31 | -#define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT) | |
| 32 | 31 | |
| 33 | 32 | #define SLOT_PFNSHIFT (SLOT_SHIFT - PAGE_SHIFT) |
| 34 | 33 | #define PFN_NASIDSHFT (NASID_SHFT - PAGE_SHIFT) |
arch/sh/kernel/setup.c
| ... | ... | @@ -20,6 +20,7 @@ |
| 20 | 20 | #include <linux/root_dev.h> |
| 21 | 21 | #include <linux/utsname.h> |
| 22 | 22 | #include <linux/cpu.h> |
| 23 | +#include <linux/pfn.h> | |
| 23 | 24 | #include <asm/uaccess.h> |
| 24 | 25 | #include <asm/io.h> |
| 25 | 26 | #include <asm/sections.h> |
| ... | ... | @@ -274,10 +275,6 @@ |
| 274 | 275 | data_resource.end = (unsigned long)virt_to_phys(_edata)-1; |
| 275 | 276 | |
| 276 | 277 | sh_mv_setup(cmdline_p); |
| 277 | - | |
| 278 | -#define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT) | |
| 279 | -#define PFN_DOWN(x) ((x) >> PAGE_SHIFT) | |
| 280 | -#define PFN_PHYS(x) ((x) << PAGE_SHIFT) | |
| 281 | 278 | |
| 282 | 279 | /* |
| 283 | 280 | * Find the highest page frame number we have available |
arch/sh64/kernel/setup.c
arch/um/kernel/physmem.c
| ... | ... | @@ -9,6 +9,7 @@ |
| 9 | 9 | #include "linux/vmalloc.h" |
| 10 | 10 | #include "linux/bootmem.h" |
| 11 | 11 | #include "linux/module.h" |
| 12 | +#include "linux/pfn.h" | |
| 12 | 13 | #include "asm/types.h" |
| 13 | 14 | #include "asm/pgtable.h" |
| 14 | 15 | #include "kern_util.h" |
| ... | ... | @@ -315,8 +316,6 @@ |
| 315 | 316 | "err = %d\n", virt, fd, offset, len, r, w, x, err); |
| 316 | 317 | } |
| 317 | 318 | } |
| 318 | - | |
| 319 | -#define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT) | |
| 320 | 319 | |
| 321 | 320 | extern int __syscall_stub_start, __binary_start; |
| 322 | 321 |
include/asm-i386/setup.h
| ... | ... | @@ -6,9 +6,7 @@ |
| 6 | 6 | #ifndef _i386_SETUP_H |
| 7 | 7 | #define _i386_SETUP_H |
| 8 | 8 | |
| 9 | -#define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT) | |
| 10 | -#define PFN_DOWN(x) ((x) >> PAGE_SHIFT) | |
| 11 | -#define PFN_PHYS(x) ((x) << PAGE_SHIFT) | |
| 9 | +#include <linux/pfn.h> | |
| 12 | 10 | |
| 13 | 11 | /* |
| 14 | 12 | * Reserved space for vmalloc and iomap - defined in asm/page.h |
include/asm-m32r/setup.h
| ... | ... | @@ -24,10 +24,6 @@ |
| 24 | 24 | #define RAMDISK_PROMPT_FLAG (0x8000) |
| 25 | 25 | #define RAMDISK_LOAD_FLAG (0x4000) |
| 26 | 26 | |
| 27 | -#define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT) | |
| 28 | -#define PFN_DOWN(x) ((x) >> PAGE_SHIFT) | |
| 29 | -#define PFN_PHYS(x) ((x) << PAGE_SHIFT) | |
| 30 | - | |
| 31 | 27 | extern unsigned long memory_start; |
| 32 | 28 | extern unsigned long memory_end; |
include/asm-sh64/platform.h
| ... | ... | @@ -61,10 +61,5 @@ |
| 61 | 61 | #define code_resource (platform_parms.kram_res_p[STANDARD_KRAM_RESOURCES - 2]) |
| 62 | 62 | #define data_resource (platform_parms.kram_res_p[STANDARD_KRAM_RESOURCES - 1]) |
| 63 | 63 | |
| 64 | -/* Be prepared to 64-bit sign extensions */ | |
| 65 | -#define PFN_UP(x) ((((x) + PAGE_SIZE-1) >> PAGE_SHIFT) & 0x000fffff) | |
| 66 | -#define PFN_DOWN(x) (((x) >> PAGE_SHIFT) & 0x000fffff) | |
| 67 | -#define PFN_PHYS(x) ((x) << PAGE_SHIFT) | |
| 68 | - | |
| 69 | 64 | #endif /* __ASM_SH64_PLATFORM_H */ |
include/linux/pfn.h