mm: add PHYS_PFN, use it in __phys_to_pfn()
authorChen Gang <xili_gchen_5257@hotmail.com>
Thu, 14 Jan 2016 23:18:33 +0000 (15:18 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 15 Jan 2016 00:00:49 +0000 (16:00 -0800)
__phys_to_pfn and __pfn_to_phys are symmetric, PHYS_PFN and PFN_PHYS are
semmetric:

 - y = (phys_addr_t)x << PAGE_SHIFT

 - y >> PAGE_SHIFT = (phys_add_t)x

 - (unsigned long)(y >> PAGE_SHIFT) = x

[akpm@linux-foundation.org: use macro arg name `x']
[arnd@arndb.de: include linux/pfn.h for PHYS_PFN definition]
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/asm-generic/memory_model.h
include/linux/pfn.h

index 4b4b056a6eb00ee844a5af970c2ce0c2e86d87d6..5148150cc80b02d9ff440de4827ab7a173067446 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef __ASM_MEMORY_MODEL_H
 #define __ASM_MEMORY_MODEL_H
 
+#include <linux/pfn.h>
+
 #ifndef __ASSEMBLY__
 
 #if defined(CONFIG_FLATMEM)
@@ -72,7 +74,7 @@
 /*
  * Convert a physical address to a Page Frame Number and back
  */
-#define        __phys_to_pfn(paddr)    ((unsigned long)((paddr) >> PAGE_SHIFT))
+#define        __phys_to_pfn(paddr)    PHYS_PFN(paddr)
 #define        __pfn_to_phys(pfn)      PFN_PHYS(pfn)
 
 #define page_to_pfn __page_to_pfn
index 7646637221f3ac45b0e2f9381fd733950b6ff492..97f3e88aead4acbb7dcb5e3ac4cf2c9e03885e6a 100644 (file)
@@ -9,5 +9,6 @@
 #define PFN_UP(x)      (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
 #define PFN_DOWN(x)    ((x) >> PAGE_SHIFT)
 #define PFN_PHYS(x)    ((phys_addr_t)(x) << PAGE_SHIFT)
+#define PHYS_PFN(x)    ((unsigned long)((x) >> PAGE_SHIFT))
 
 #endif