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/addrspace.h>
9 #include <asm/sections.h>
14 static inline bool __debug_virt_addr_valid(unsigned long x
)
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.
22 if (x
== MAX_DMA_ADDRESS
)
25 return x
>= PAGE_OFFSET
&& (KSEGX(x
) < KSEG2
||
26 IS_ENABLED(CONFIG_EVA
) ||
27 !IS_ENABLED(CONFIG_HIGHMEM
));
30 phys_addr_t
__virt_to_phys(volatile const void *x
)
32 WARN(!__debug_virt_addr_valid((unsigned long)x
),
33 "virt_to_phys used for non-linear address: %pK (%pS)\n",
36 return __virt_to_phys_nodebug(x
);
38 EXPORT_SYMBOL(__virt_to_phys
);
40 phys_addr_t
__phys_addr_symbol(unsigned long x
)
42 /* This is bounds checking against the kernel image only.
43 * __pa_symbol should only be used on kernel symbol addresses.
45 VIRTUAL_BUG_ON(x
< (unsigned long)_text
||
46 x
> (unsigned long)_end
);
48 return __pa_symbol_nodebug(x
);
50 EXPORT_SYMBOL(__phys_addr_symbol
);