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