Loading...
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/bug.h>
3#include <linux/export.h>
4#include <linux/types.h>
5#include <linux/mmdebug.h>
6#include <linux/mm.h>
7
8#include <asm/addrspace.h>
9#include <asm/sections.h>
10#include <asm/io.h>
11#include <asm/page.h>
12#include <asm/dma.h>
13
14static inline bool __debug_virt_addr_valid(unsigned long x)
15{
16 /*
17 * MAX_DMA_ADDRESS is a virtual address that may not correspond to an
18 * actual physical address. Enough code relies on
19 * virt_to_phys(MAX_DMA_ADDRESS) that we just need to work around it
20 * and always return true.
21 */
22 if (x == MAX_DMA_ADDRESS)
23 return true;
24
25 return x >= PAGE_OFFSET && (KSEGX(x) < KSEG2 ||
26 IS_ENABLED(CONFIG_EVA) ||
27 !IS_ENABLED(CONFIG_HIGHMEM));
28}
29
30phys_addr_t __virt_to_phys(volatile const void *x)
31{
32 WARN(!__debug_virt_addr_valid((unsigned long)x),
33 "virt_to_phys used for non-linear address: %pK (%pS)\n",
34 x, x);
35
36 return __virt_to_phys_nodebug(x);
37}
38EXPORT_SYMBOL(__virt_to_phys);
39
40phys_addr_t __phys_addr_symbol(unsigned long x)
41{
42 /* This is bounds checking against the kernel image only.
43 * __pa_symbol should only be used on kernel symbol addresses.
44 */
45 VIRTUAL_BUG_ON(x < (unsigned long)_text ||
46 x > (unsigned long)_end);
47
48 return __pa_symbol_nodebug(x);
49}
50EXPORT_SYMBOL(__phys_addr_symbol);
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/bug.h>
3#include <linux/export.h>
4#include <linux/types.h>
5#include <linux/mmdebug.h>
6#include <linux/mm.h>
7
8#include <asm/sections.h>
9#include <asm/io.h>
10#include <asm/page.h>
11#include <asm/dma.h>
12
13static inline bool __debug_virt_addr_valid(unsigned long x)
14{
15 /* high_memory does not get immediately defined, and there
16 * are early callers of __pa() against PAGE_OFFSET
17 */
18 if (!high_memory && x >= PAGE_OFFSET)
19 return true;
20
21 if (high_memory && x >= PAGE_OFFSET && x < (unsigned long)high_memory)
22 return true;
23
24 /*
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.
29 */
30 if (x == MAX_DMA_ADDRESS)
31 return true;
32
33 return false;
34}
35
36phys_addr_t __virt_to_phys(volatile const void *x)
37{
38 WARN(!__debug_virt_addr_valid((unsigned long)x),
39 "virt_to_phys used for non-linear address: %pK (%pS)\n",
40 x, x);
41
42 return __virt_to_phys_nodebug(x);
43}
44EXPORT_SYMBOL(__virt_to_phys);
45
46phys_addr_t __phys_addr_symbol(unsigned long x)
47{
48 /* This is bounds checking against the kernel image only.
49 * __pa_symbol should only be used on kernel symbol addresses.
50 */
51 VIRTUAL_BUG_ON(x < (unsigned long)_text ||
52 x > (unsigned long)_end);
53
54 return __pa_symbol_nodebug(x);
55}
56EXPORT_SYMBOL(__phys_addr_symbol);