1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/export.h>
4 #include <linux/types.h>
5 #include <linux/mmdebug.h>
8 #include <asm/sections.h>
13 static inline bool __debug_virt_addr_valid(unsigned long x)
15 /* high_memory does not get immediately defined, and there
16 * are early callers of __pa() against PAGE_OFFSET
18 if (!high_memory && x >= PAGE_OFFSET)
21 if (high_memory && x >= PAGE_OFFSET && x < (unsigned long)high_memory)
25 * MAX_DMA_ADDRESS is a virtual address that may not correspond to an
26 * actual physical address. Enough code relies on
27 * virt_to_phys(MAX_DMA_ADDRESS) that we just need to work around it
28 * and always return true.
30 if (x == MAX_DMA_ADDRESS)
36 phys_addr_t __virt_to_phys(volatile const void *x)
38 WARN(!__debug_virt_addr_valid((unsigned long)x),
39 "virt_to_phys used for non-linear address: %pK (%pS)\n",
42 return __virt_to_phys_nodebug(x);
44 EXPORT_SYMBOL(__virt_to_phys);
46 phys_addr_t __phys_addr_symbol(unsigned long x)
48 /* This is bounds checking against the kernel image only.
49 * __pa_symbol should only be used on kernel symbol addresses.
51 VIRTUAL_BUG_ON(x < (unsigned long)_text ||
52 x > (unsigned long)_end);
54 return __pa_symbol_nodebug(x);
56 EXPORT_SYMBOL(__phys_addr_symbol);