Jeremy Fitzhardinge | 78c86e5 | 2009-09-10 10:09:38 -0700 | [diff] [blame] | 1 | #include <linux/mmdebug.h> |
| 2 | #include <linux/module.h> |
| 3 | #include <linux/mm.h> |
| 4 | |
| 5 | #include <asm/page.h> |
| 6 | |
| 7 | #include "physaddr.h" |
| 8 | |
| 9 | #ifdef CONFIG_X86_64 |
| 10 | |
Alexander Duyck | 0bdf525 | 2012-11-16 13:53:51 -0800 | [diff] [blame^] | 11 | #ifdef CONFIG_DEBUG_VIRTUAL |
Jeremy Fitzhardinge | 78c86e5 | 2009-09-10 10:09:38 -0700 | [diff] [blame] | 12 | unsigned long __phys_addr(unsigned long x) |
| 13 | { |
Alexander Duyck | 0bdf525 | 2012-11-16 13:53:51 -0800 | [diff] [blame^] | 14 | unsigned long y = x - __START_KERNEL_map; |
| 15 | |
| 16 | /* use the carry flag to determine if x was < __START_KERNEL_map */ |
| 17 | if (unlikely(x > y)) { |
| 18 | x = y + phys_base; |
| 19 | |
| 20 | VIRTUAL_BUG_ON(y >= KERNEL_IMAGE_SIZE); |
Jeremy Fitzhardinge | 78c86e5 | 2009-09-10 10:09:38 -0700 | [diff] [blame] | 21 | } else { |
Alexander Duyck | 0bdf525 | 2012-11-16 13:53:51 -0800 | [diff] [blame^] | 22 | x = y + (__START_KERNEL_map - PAGE_OFFSET); |
| 23 | |
| 24 | /* carry flag will be set if starting x was >= PAGE_OFFSET */ |
| 25 | VIRTUAL_BUG_ON((x > y) || !phys_addr_valid(x)); |
Jeremy Fitzhardinge | 78c86e5 | 2009-09-10 10:09:38 -0700 | [diff] [blame] | 26 | } |
Alexander Duyck | 0bdf525 | 2012-11-16 13:53:51 -0800 | [diff] [blame^] | 27 | |
Jeremy Fitzhardinge | 78c86e5 | 2009-09-10 10:09:38 -0700 | [diff] [blame] | 28 | return x; |
| 29 | } |
| 30 | EXPORT_SYMBOL(__phys_addr); |
Alexander Duyck | 0bdf525 | 2012-11-16 13:53:51 -0800 | [diff] [blame^] | 31 | #endif |
Jeremy Fitzhardinge | 78c86e5 | 2009-09-10 10:09:38 -0700 | [diff] [blame] | 32 | |
| 33 | bool __virt_addr_valid(unsigned long x) |
| 34 | { |
Alexander Duyck | 0bdf525 | 2012-11-16 13:53:51 -0800 | [diff] [blame^] | 35 | unsigned long y = x - __START_KERNEL_map; |
| 36 | |
| 37 | /* use the carry flag to determine if x was < __START_KERNEL_map */ |
| 38 | if (unlikely(x > y)) { |
| 39 | x = y + phys_base; |
| 40 | |
| 41 | if (y >= KERNEL_IMAGE_SIZE) |
Jeremy Fitzhardinge | 78c86e5 | 2009-09-10 10:09:38 -0700 | [diff] [blame] | 42 | return false; |
Jeremy Fitzhardinge | 78c86e5 | 2009-09-10 10:09:38 -0700 | [diff] [blame] | 43 | } else { |
Alexander Duyck | 0bdf525 | 2012-11-16 13:53:51 -0800 | [diff] [blame^] | 44 | x = y + (__START_KERNEL_map - PAGE_OFFSET); |
| 45 | |
| 46 | /* carry flag will be set if starting x was >= PAGE_OFFSET */ |
| 47 | if ((x > y) || !phys_addr_valid(x)) |
Jeremy Fitzhardinge | 78c86e5 | 2009-09-10 10:09:38 -0700 | [diff] [blame] | 48 | return false; |
| 49 | } |
| 50 | |
| 51 | return pfn_valid(x >> PAGE_SHIFT); |
| 52 | } |
| 53 | EXPORT_SYMBOL(__virt_addr_valid); |
| 54 | |
| 55 | #else |
| 56 | |
| 57 | #ifdef CONFIG_DEBUG_VIRTUAL |
| 58 | unsigned long __phys_addr(unsigned long x) |
| 59 | { |
| 60 | /* VMALLOC_* aren't constants */ |
| 61 | VIRTUAL_BUG_ON(x < PAGE_OFFSET); |
| 62 | VIRTUAL_BUG_ON(__vmalloc_start_set && is_vmalloc_addr((void *) x)); |
| 63 | return x - PAGE_OFFSET; |
| 64 | } |
| 65 | EXPORT_SYMBOL(__phys_addr); |
| 66 | #endif |
| 67 | |
| 68 | bool __virt_addr_valid(unsigned long x) |
| 69 | { |
| 70 | if (x < PAGE_OFFSET) |
| 71 | return false; |
| 72 | if (__vmalloc_start_set && is_vmalloc_addr((void *) x)) |
| 73 | return false; |
| 74 | if (x >= FIXADDR_START) |
| 75 | return false; |
| 76 | return pfn_valid((x - PAGE_OFFSET) >> PAGE_SHIFT); |
| 77 | } |
| 78 | EXPORT_SYMBOL(__virt_addr_valid); |
| 79 | |
| 80 | #endif /* CONFIG_X86_64 */ |