1 #include <linux/bootmem.h>
2 #include <linux/mmdebug.h>
3 #include <linux/export.h>
12 #ifdef CONFIG_DEBUG_VIRTUAL
13 unsigned long __phys_addr(unsigned long x
)
15 unsigned long y
= x
- __START_KERNEL_map
;
17 /* use the carry flag to determine if x was < __START_KERNEL_map */
18 if (unlikely(x
> y
)) {
21 VIRTUAL_BUG_ON(y
>= KERNEL_IMAGE_SIZE
);
23 x
= y
+ (__START_KERNEL_map
- PAGE_OFFSET
);
25 /* carry flag will be set if starting x was >= PAGE_OFFSET */
26 VIRTUAL_BUG_ON((x
> y
) || !phys_addr_valid(x
));
31 EXPORT_SYMBOL(__phys_addr
);
33 unsigned long __phys_addr_symbol(unsigned long x
)
35 unsigned long y
= x
- __START_KERNEL_map
;
37 /* only check upper bounds since lower bounds will trigger carry */
38 VIRTUAL_BUG_ON(y
>= KERNEL_IMAGE_SIZE
);
42 EXPORT_SYMBOL(__phys_addr_symbol
);
45 bool __virt_addr_valid(unsigned long x
)
47 unsigned long y
= x
- __START_KERNEL_map
;
49 /* use the carry flag to determine if x was < __START_KERNEL_map */
50 if (unlikely(x
> y
)) {
53 if (y
>= KERNEL_IMAGE_SIZE
)
56 x
= y
+ (__START_KERNEL_map
- PAGE_OFFSET
);
58 /* carry flag will be set if starting x was >= PAGE_OFFSET */
59 if ((x
> y
) || !phys_addr_valid(x
))
63 return pfn_valid(x
>> PAGE_SHIFT
);
65 EXPORT_SYMBOL(__virt_addr_valid
);
69 #ifdef CONFIG_DEBUG_VIRTUAL
70 unsigned long __phys_addr(unsigned long x
)
72 unsigned long phys_addr
= x
- PAGE_OFFSET
;
73 /* VMALLOC_* aren't constants */
74 VIRTUAL_BUG_ON(x
< PAGE_OFFSET
);
75 VIRTUAL_BUG_ON(__vmalloc_start_set
&& is_vmalloc_addr((void *) x
));
76 /* max_low_pfn is set early, but not _that_ early */
78 VIRTUAL_BUG_ON((phys_addr
>> PAGE_SHIFT
) > max_low_pfn
);
79 BUG_ON(slow_virt_to_phys((void *)x
) != phys_addr
);
83 EXPORT_SYMBOL(__phys_addr
);
86 bool __virt_addr_valid(unsigned long x
)
90 if (__vmalloc_start_set
&& is_vmalloc_addr((void *) x
))
92 if (x
>= FIXADDR_START
)
94 return pfn_valid((x
- PAGE_OFFSET
) >> PAGE_SHIFT
);
96 EXPORT_SYMBOL(__virt_addr_valid
);
98 #endif /* CONFIG_X86_64 */