virtconvert.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 <asm/setup.h>
  9. #include <asm/page.h>
  10. #ifdef CONFIG_AMIGA
  11. #include <asm/amigahw.h>
  12. #endif
  13. /*
  14. * Change virtual addresses to physical addresses and vv.
  15. */
  16. #ifndef CONFIG_SUN3
  17. extern unsigned long mm_vtop(unsigned long addr) __attribute_const__;
  18. extern unsigned long mm_ptov(unsigned long addr) __attribute_const__;
  19. #else
  20. static inline unsigned long mm_vtop(unsigned long vaddr)
  21. {
  22. return __pa(vaddr);
  23. }
  24. static inline unsigned long mm_ptov(unsigned long paddr)
  25. {
  26. return (unsigned long)__va(paddr);
  27. }
  28. #endif
  29. #ifdef CONFIG_SINGLE_MEMORY_CHUNK
  30. static inline unsigned long virt_to_phys(void *vaddr)
  31. {
  32. return (unsigned long)vaddr - PAGE_OFFSET + m68k_memory[0].addr;
  33. }
  34. static inline void * phys_to_virt(unsigned long paddr)
  35. {
  36. return (void *)(paddr - m68k_memory[0].addr + PAGE_OFFSET);
  37. }
  38. #else
  39. static inline unsigned long virt_to_phys(void *address)
  40. {
  41. return mm_vtop((unsigned long)address);
  42. }
  43. static inline void *phys_to_virt(unsigned long address)
  44. {
  45. return (void *) mm_ptov(address);
  46. }
  47. #endif
  48. /* Permanent address of a page. */
  49. #define __page_address(page) (PAGE_OFFSET + (((page) - mem_map) << PAGE_SHIFT))
  50. #define page_to_phys(page) virt_to_phys((void *)__page_address(page))
  51. /*
  52. * IO bus memory addresses are 1:1 with the physical address,
  53. * except on the PCI bus of the Hades.
  54. */
  55. #ifdef CONFIG_HADES
  56. #define virt_to_bus(a) (virt_to_phys(a) + (MACH_IS_HADES ? 0x80000000 : 0))
  57. #define bus_to_virt(a) (phys_to_virt((a) - (MACH_IS_HADES ? 0x80000000 : 0)))
  58. #else
  59. #define virt_to_bus virt_to_phys
  60. #define bus_to_virt phys_to_virt
  61. #endif
  62. #endif
  63. #endif