blob: 02e60f495608c8b8086771c496b5c904c469cf65 [file] [log] [blame]
Florian Fainellie377cd82017-01-15 03:59:00 +01001#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
14static 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
37phys_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}
45EXPORT_SYMBOL(__virt_to_phys);
46
47phys_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}
57EXPORT_SYMBOL(__phys_addr_symbol);