Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/bug.h>
0003 #include <linux/export.h>
0004 #include <linux/types.h>
0005 #include <linux/mmdebug.h>
0006 #include <linux/mm.h>
0007 
0008 #include <asm/sections.h>
0009 #include <asm/memory.h>
0010 #include <asm/fixmap.h>
0011 #include <asm/dma.h>
0012 
0013 #include "mm.h"
0014 
0015 static inline bool __virt_addr_valid(unsigned long x)
0016 {
0017     /*
0018      * high_memory does not get immediately defined, and there
0019      * are early callers of __pa() against PAGE_OFFSET
0020      */
0021     if (!high_memory && x >= PAGE_OFFSET)
0022         return true;
0023 
0024     if (high_memory && x >= PAGE_OFFSET && x < (unsigned long)high_memory)
0025         return true;
0026 
0027     /*
0028      * MAX_DMA_ADDRESS is a virtual address that may not correspond to an
0029      * actual physical address. Enough code relies on __pa(MAX_DMA_ADDRESS)
0030      * that we just need to work around it and always return true.
0031      */
0032     if (x == MAX_DMA_ADDRESS)
0033         return true;
0034 
0035     return false;
0036 }
0037 
0038 phys_addr_t __virt_to_phys(unsigned long x)
0039 {
0040     WARN(!__virt_addr_valid(x),
0041          "virt_to_phys used for non-linear address: %pK (%pS)\n",
0042          (void *)x, (void *)x);
0043 
0044     return __virt_to_phys_nodebug(x);
0045 }
0046 EXPORT_SYMBOL(__virt_to_phys);
0047 
0048 phys_addr_t __phys_addr_symbol(unsigned long x)
0049 {
0050     /* This is bounds checking against the kernel image only.
0051      * __pa_symbol should only be used on kernel symbol addresses.
0052      */
0053     VIRTUAL_BUG_ON(x < (unsigned long)KERNEL_START ||
0054                x > (unsigned long)KERNEL_END);
0055 
0056     return __pa_symbol_nodebug(x);
0057 }
0058 EXPORT_SYMBOL(__phys_addr_symbol);