1 // SPDX-License-Identifier: GPL-2.0 1 // SPDX-License-Identifier: GPL-2.0 2 #include <linux/memblock.h> !! 2 #include <linux/bug.h> 3 #include <linux/mmdebug.h> << 4 #include <linux/export.h> 3 #include <linux/export.h> >> 4 #include <linux/types.h> >> 5 #include <linux/mmdebug.h> 5 #include <linux/mm.h> 6 #include <linux/mm.h> 6 7 >> 8 #include <asm/addrspace.h> >> 9 #include <asm/sections.h> >> 10 #include <asm/io.h> 7 #include <asm/page.h> 11 #include <asm/page.h> 8 #include <linux/vmalloc.h> !! 12 #include <asm/dma.h> 9 << 10 #include "physaddr.h" << 11 << 12 #ifdef CONFIG_X86_64 << 13 << 14 #ifdef CONFIG_DEBUG_VIRTUAL << 15 unsigned long __phys_addr(unsigned long x) << 16 { << 17 unsigned long y = x - __START_KERNEL_m << 18 << 19 /* use the carry flag to determine if << 20 if (unlikely(x > y)) { << 21 x = y + phys_base; << 22 << 23 VIRTUAL_BUG_ON(y >= KERNEL_IMA << 24 } else { << 25 x = y + (__START_KERNEL_map - << 26 << 27 /* carry flag will be set if s << 28 VIRTUAL_BUG_ON((x > y) || !phy << 29 } << 30 << 31 return x; << 32 } << 33 EXPORT_SYMBOL(__phys_addr); << 34 13 35 unsigned long __phys_addr_symbol(unsigned long !! 14 static inline bool __debug_virt_addr_valid(unsigned long x) 36 { 15 { 37 unsigned long y = x - __START_KERNEL_m !! 16 /* 38 !! 17 * MAX_DMA_ADDRESS is a virtual address that may not correspond to an 39 /* only check upper bounds since lower !! 18 * actual physical address. Enough code relies on 40 VIRTUAL_BUG_ON(y >= KERNEL_IMAGE_SIZE) !! 19 * virt_to_phys(MAX_DMA_ADDRESS) that we just need to work around it 41 !! 20 * and always return true. 42 return y + phys_base; !! 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)); 43 } 28 } 44 EXPORT_SYMBOL(__phys_addr_symbol); << 45 #endif << 46 29 47 bool __virt_addr_valid(unsigned long x) !! 30 phys_addr_t __virt_to_phys(volatile const void *x) 48 { 31 { 49 unsigned long y = x - __START_KERNEL_m !! 32 WARN(!__debug_virt_addr_valid((unsigned long)x), 50 !! 33 "virt_to_phys used for non-linear address: %pK (%pS)\n", 51 /* use the carry flag to determine if !! 34 x, x); 52 if (unlikely(x > y)) { << 53 x = y + phys_base; << 54 << 55 if (y >= KERNEL_IMAGE_SIZE) << 56 return false; << 57 } else { << 58 x = y + (__START_KERNEL_map - << 59 << 60 /* carry flag will be set if s << 61 if ((x > y) || !phys_addr_vali << 62 return false; << 63 } << 64 35 65 return pfn_valid(x >> PAGE_SHIFT); !! 36 return __virt_to_phys_nodebug(x); 66 } 37 } 67 EXPORT_SYMBOL(__virt_addr_valid); !! 38 EXPORT_SYMBOL(__virt_to_phys); 68 39 69 #else !! 40 phys_addr_t __phys_addr_symbol(unsigned long x) 70 << 71 #ifdef CONFIG_DEBUG_VIRTUAL << 72 unsigned long __phys_addr(unsigned long x) << 73 { 41 { 74 unsigned long phys_addr = x - PAGE_OFF !! 42 /* This is bounds checking against the kernel image only. 75 /* VMALLOC_* aren't constants */ !! 43 * __pa_symbol should only be used on kernel symbol addresses. 76 VIRTUAL_BUG_ON(x < PAGE_OFFSET); !! 44 */ 77 VIRTUAL_BUG_ON(__vmalloc_start_set && !! 45 VIRTUAL_BUG_ON(x < (unsigned long)_text || 78 /* max_low_pfn is set early, but not _ !! 46 x > (unsigned long)_end); 79 if (max_low_pfn) { << 80 VIRTUAL_BUG_ON((phys_addr >> P << 81 BUG_ON(slow_virt_to_phys((void << 82 } << 83 return phys_addr; << 84 } << 85 EXPORT_SYMBOL(__phys_addr); << 86 #endif << 87 47 88 bool __virt_addr_valid(unsigned long x) !! 48 return __pa_symbol_nodebug(x); 89 { << 90 if (x < PAGE_OFFSET) << 91 return false; << 92 if (__vmalloc_start_set && is_vmalloc_ << 93 return false; << 94 if (x >= FIXADDR_START) << 95 return false; << 96 return pfn_valid((x - PAGE_OFFSET) >> << 97 } 49 } 98 EXPORT_SYMBOL(__virt_addr_valid); !! 50 EXPORT_SYMBOL(__phys_addr_symbol); 99 << 100 #endif /* CONFIG_X86_64 */ << 101 51
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.