Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __VIRT_CONVERT__ |
| 2 | #define __VIRT_CONVERT__ |
| 3 | |
| 4 | /* |
| 5 | * Macros used for converting between virtual and physical mappings. |
| 6 | */ |
| 7 | |
| 8 | #ifdef __KERNEL__ |
| 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/compiler.h> |
Roman Zippel | 12d810c | 2007-05-31 00:40:54 -0700 | [diff] [blame] | 11 | #include <linux/mmzone.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <asm/setup.h> |
| 13 | #include <asm/page.h> |
| 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | /* |
| 16 | * Change virtual addresses to physical addresses and vv. |
| 17 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | static inline unsigned long virt_to_phys(void *address) |
| 19 | { |
Roman Zippel | 12d810c | 2007-05-31 00:40:54 -0700 | [diff] [blame] | 20 | return __pa(address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | static inline void *phys_to_virt(unsigned long address) |
| 24 | { |
Roman Zippel | 12d810c | 2007-05-31 00:40:54 -0700 | [diff] [blame] | 25 | return __va(address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
| 28 | /* Permanent address of a page. */ |
Greg Ungerer | 682137f | 2010-01-13 10:42:05 +1000 | [diff] [blame] | 29 | #ifdef CONFIG_MMU |
Roman Zippel | 12d810c | 2007-05-31 00:40:54 -0700 | [diff] [blame] | 30 | #ifdef CONFIG_SINGLE_MEMORY_CHUNK |
| 31 | #define page_to_phys(page) \ |
| 32 | __pa(PAGE_OFFSET + (((page) - pg_data_map[0].node_mem_map) << PAGE_SHIFT)) |
| 33 | #else |
Geert Uytterhoeven | f54bcdc | 2010-01-12 08:32:18 +0100 | [diff] [blame] | 34 | #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT) |
Roman Zippel | 12d810c | 2007-05-31 00:40:54 -0700 | [diff] [blame] | 35 | #endif |
Greg Ungerer | 682137f | 2010-01-13 10:42:05 +1000 | [diff] [blame] | 36 | #else |
| 37 | #define page_to_phys(page) (((page) - mem_map) << PAGE_SHIFT) |
| 38 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | /* |
| 41 | * IO bus memory addresses are 1:1 with the physical address, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #define virt_to_bus virt_to_phys |
| 44 | #define bus_to_virt phys_to_virt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | #endif |
| 47 | #endif |