1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/memblock.h>
3 #include <linux/mmdebug.h>
4 #include <linux/export.h>
13 #ifdef CONFIG_DEBUG_VIRTUAL
14 unsigned long __phys_addr(unsigned long x
)
16 unsigned long y
= x
- __START_KERNEL_map
;
18 /* use the carry flag to determine if x was < __START_KERNEL_map */
19 if (unlikely(x
> y
)) {
22 VIRTUAL_BUG_ON(y
>= KERNEL_IMAGE_SIZE
);
24 x
= y
+ (__START_KERNEL_map
- PAGE_OFFSET
);
26 /* carry flag will be set if starting x was >= PAGE_OFFSET */
27 VIRTUAL_BUG_ON((x
> y
) || !phys_addr_valid(x
));
32 EXPORT_SYMBOL(__phys_addr
);
34 unsigned long __phys_addr_symbol(unsigned long x
)
36 unsigned long y
= x
- __START_KERNEL_map
;
38 /* only check upper bounds since lower bounds will trigger carry */
39 VIRTUAL_BUG_ON(y
>= KERNEL_IMAGE_SIZE
);
43 EXPORT_SYMBOL(__phys_addr_symbol
);
46 bool __virt_addr_valid(unsigned long x
)
48 unsigned long y
= x
- __START_KERNEL_map
;
50 /* use the carry flag to determine if x was < __START_KERNEL_map */
51 if (unlikely(x
> y
)) {
54 if (y
>= KERNEL_IMAGE_SIZE
)
57 x
= y
+ (__START_KERNEL_map
- PAGE_OFFSET
);
59 /* carry flag will be set if starting x was >= PAGE_OFFSET */
60 if ((x
> y
) || !phys_addr_valid(x
))
64 return pfn_valid(x
>> PAGE_SHIFT
);
66 EXPORT_SYMBOL(__virt_addr_valid
);
70 #ifdef CONFIG_DEBUG_VIRTUAL
71 unsigned long __phys_addr(unsigned long x
)
73 unsigned long phys_addr
= x
- PAGE_OFFSET
;
74 /* VMALLOC_* aren't constants */
75 VIRTUAL_BUG_ON(x
< PAGE_OFFSET
);
76 VIRTUAL_BUG_ON(__vmalloc_start_set
&& is_vmalloc_addr((void *) x
));
77 /* max_low_pfn is set early, but not _that_ early */
79 VIRTUAL_BUG_ON((phys_addr
>> PAGE_SHIFT
) > max_low_pfn
);
80 BUG_ON(slow_virt_to_phys((void *)x
) != phys_addr
);
84 EXPORT_SYMBOL(__phys_addr
);
87 bool __virt_addr_valid(unsigned long x
)
91 if (__vmalloc_start_set
&& is_vmalloc_addr((void *) x
))
93 if (x
>= FIXADDR_START
)
95 return pfn_valid((x
- PAGE_OFFSET
) >> PAGE_SHIFT
);
97 EXPORT_SYMBOL(__virt_addr_valid
);
99 #endif /* CONFIG_X86_64 */