blob: 3f834b3ab5bdad32a2281e80917f8df931a62d31 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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 Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/compiler.h>
Roman Zippel12d810c2007-05-31 00:40:54 -070011#include <linux/mmzone.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <asm/setup.h>
13#include <asm/page.h>
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015/*
16 * Change virtual addresses to physical addresses and vv.
17 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018static inline unsigned long virt_to_phys(void *address)
19{
Roman Zippel12d810c2007-05-31 00:40:54 -070020 return __pa(address);
Linus Torvalds1da177e2005-04-16 15:20:36 -070021}
22
23static inline void *phys_to_virt(unsigned long address)
24{
Roman Zippel12d810c2007-05-31 00:40:54 -070025 return __va(address);
Linus Torvalds1da177e2005-04-16 15:20:36 -070026}
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28/* Permanent address of a page. */
Greg Ungerer682137f2010-01-13 10:42:05 +100029#ifdef CONFIG_MMU
Roman Zippel12d810c2007-05-31 00:40:54 -070030#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
34#define page_to_phys(_page) ({ \
35 struct page *__page = _page; \
36 struct pglist_data *pgdat; \
37 pgdat = pg_data_table[page_to_nid(__page)]; \
38 page_to_pfn(__page) << PAGE_SHIFT; \
39})
40#endif
Greg Ungerer682137f2010-01-13 10:42:05 +100041#else
42#define page_to_phys(page) (((page) - mem_map) << PAGE_SHIFT)
43#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45/*
46 * IO bus memory addresses are 1:1 with the physical address,
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define virt_to_bus virt_to_phys
49#define bus_to_virt phys_to_virt
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51#endif
52#endif