Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-btrfs-devel.git] / arch / x86 / mm / physaddr.c
blobd2e2735327b4b2ed8f65dd06895aabc71e67e4d3
1 #include <linux/mmdebug.h>
2 #include <linux/module.h>
3 #include <linux/mm.h>
5 #include <asm/page.h>
7 #include "physaddr.h"
9 #ifdef CONFIG_X86_64
11 unsigned long __phys_addr(unsigned long x)
13 if (x >= __START_KERNEL_map) {
14 x -= __START_KERNEL_map;
15 VIRTUAL_BUG_ON(x >= KERNEL_IMAGE_SIZE);
16 x += phys_base;
17 } else {
18 VIRTUAL_BUG_ON(x < PAGE_OFFSET);
19 x -= PAGE_OFFSET;
20 VIRTUAL_BUG_ON(!phys_addr_valid(x));
22 return x;
24 EXPORT_SYMBOL(__phys_addr);
26 bool __virt_addr_valid(unsigned long x)
28 if (x >= __START_KERNEL_map) {
29 x -= __START_KERNEL_map;
30 if (x >= KERNEL_IMAGE_SIZE)
31 return false;
32 x += phys_base;
33 } else {
34 if (x < PAGE_OFFSET)
35 return false;
36 x -= PAGE_OFFSET;
37 if (!phys_addr_valid(x))
38 return false;
41 return pfn_valid(x >> PAGE_SHIFT);
43 EXPORT_SYMBOL(__virt_addr_valid);
45 #else
47 #ifdef CONFIG_DEBUG_VIRTUAL
48 unsigned long __phys_addr(unsigned long x)
50 /* VMALLOC_* aren't constants */
51 VIRTUAL_BUG_ON(x < PAGE_OFFSET);
52 VIRTUAL_BUG_ON(__vmalloc_start_set && is_vmalloc_addr((void *) x));
53 return x - PAGE_OFFSET;
55 EXPORT_SYMBOL(__phys_addr);
56 #endif
58 bool __virt_addr_valid(unsigned long x)
60 if (x < PAGE_OFFSET)
61 return false;
62 if (__vmalloc_start_set && is_vmalloc_addr((void *) x))
63 return false;
64 if (x >= FIXADDR_START)
65 return false;
66 return pfn_valid((x - PAGE_OFFSET) >> PAGE_SHIFT);
68 EXPORT_SYMBOL(__virt_addr_valid);
70 #endif /* CONFIG_X86_64 */