blob: fd40d75109efc47347f8cd98be2de068410ffcc2 [file] [log] [blame]
Jeremy Fitzhardinge78c86e52009-09-10 10:09:38 -07001#include <linux/mmdebug.h>
2#include <linux/module.h>
3#include <linux/mm.h>
4
5#include <asm/page.h>
6
7#include "physaddr.h"
8
9#ifdef CONFIG_X86_64
10
Alexander Duyck0bdf5252012-11-16 13:53:51 -080011#ifdef CONFIG_DEBUG_VIRTUAL
Jeremy Fitzhardinge78c86e52009-09-10 10:09:38 -070012unsigned long __phys_addr(unsigned long x)
13{
Alexander Duyck0bdf5252012-11-16 13:53:51 -080014 unsigned long y = x - __START_KERNEL_map;
15
16 /* use the carry flag to determine if x was < __START_KERNEL_map */
17 if (unlikely(x > y)) {
18 x = y + phys_base;
19
20 VIRTUAL_BUG_ON(y >= KERNEL_IMAGE_SIZE);
Jeremy Fitzhardinge78c86e52009-09-10 10:09:38 -070021 } else {
Alexander Duyck0bdf5252012-11-16 13:53:51 -080022 x = y + (__START_KERNEL_map - PAGE_OFFSET);
23
24 /* carry flag will be set if starting x was >= PAGE_OFFSET */
25 VIRTUAL_BUG_ON((x > y) || !phys_addr_valid(x));
Jeremy Fitzhardinge78c86e52009-09-10 10:09:38 -070026 }
Alexander Duyck0bdf5252012-11-16 13:53:51 -080027
Jeremy Fitzhardinge78c86e52009-09-10 10:09:38 -070028 return x;
29}
30EXPORT_SYMBOL(__phys_addr);
Alexander Duyck0bdf5252012-11-16 13:53:51 -080031#endif
Jeremy Fitzhardinge78c86e52009-09-10 10:09:38 -070032
33bool __virt_addr_valid(unsigned long x)
34{
Alexander Duyck0bdf5252012-11-16 13:53:51 -080035 unsigned long y = x - __START_KERNEL_map;
36
37 /* use the carry flag to determine if x was < __START_KERNEL_map */
38 if (unlikely(x > y)) {
39 x = y + phys_base;
40
41 if (y >= KERNEL_IMAGE_SIZE)
Jeremy Fitzhardinge78c86e52009-09-10 10:09:38 -070042 return false;
Jeremy Fitzhardinge78c86e52009-09-10 10:09:38 -070043 } else {
Alexander Duyck0bdf5252012-11-16 13:53:51 -080044 x = y + (__START_KERNEL_map - PAGE_OFFSET);
45
46 /* carry flag will be set if starting x was >= PAGE_OFFSET */
47 if ((x > y) || !phys_addr_valid(x))
Jeremy Fitzhardinge78c86e52009-09-10 10:09:38 -070048 return false;
49 }
50
51 return pfn_valid(x >> PAGE_SHIFT);
52}
53EXPORT_SYMBOL(__virt_addr_valid);
54
55#else
56
57#ifdef CONFIG_DEBUG_VIRTUAL
58unsigned long __phys_addr(unsigned long x)
59{
60 /* VMALLOC_* aren't constants */
61 VIRTUAL_BUG_ON(x < PAGE_OFFSET);
62 VIRTUAL_BUG_ON(__vmalloc_start_set && is_vmalloc_addr((void *) x));
63 return x - PAGE_OFFSET;
64}
65EXPORT_SYMBOL(__phys_addr);
66#endif
67
68bool __virt_addr_valid(unsigned long x)
69{
70 if (x < PAGE_OFFSET)
71 return false;
72 if (__vmalloc_start_set && is_vmalloc_addr((void *) x))
73 return false;
74 if (x >= FIXADDR_START)
75 return false;
76 return pfn_valid((x - PAGE_OFFSET) >> PAGE_SHIFT);
77}
78EXPORT_SYMBOL(__virt_addr_valid);
79
80#endif /* CONFIG_X86_64 */