virtconvert.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef __VIRT_CONVERT__
  2. #define __VIRT_CONVERT__
  3. /*
  4. * Macros used for converting between virtual and physical mappings.
  5. */
  6. #ifdef __KERNEL__
  7. #include <linux/compiler.h>
  8. #include <linux/mmzone.h>
  9. #include <asm/setup.h>
  10. #include <asm/page.h>
  11. /*
  12. * Change virtual addresses to physical addresses and vv.
  13. */
  14. static inline unsigned long virt_to_phys(void *address)
  15. {
  16. return __pa(address);
  17. }
  18. static inline void *phys_to_virt(unsigned long address)
  19. {
  20. return __va(address);
  21. }
  22. /* Permanent address of a page. */
  23. #ifdef CONFIG_MMU
  24. #ifdef CONFIG_SINGLE_MEMORY_CHUNK
  25. #define page_to_phys(page) \
  26. __pa(PAGE_OFFSET + (((page) - pg_data_map[0].node_mem_map) << PAGE_SHIFT))
  27. #else
  28. #define page_to_phys(_page) ({ \
  29. struct page *__page = _page; \
  30. struct pglist_data *pgdat; \
  31. pgdat = pg_data_table[page_to_nid(__page)]; \
  32. page_to_pfn(__page) << PAGE_SHIFT; \
  33. })
  34. #endif
  35. #else
  36. #define page_to_phys(page) (((page) - mem_map) << PAGE_SHIFT)
  37. #endif
  38. /*
  39. * IO bus memory addresses are 1:1 with the physical address,
  40. */
  41. #define virt_to_bus virt_to_phys
  42. #define bus_to_virt phys_to_virt
  43. #endif
  44. #endif