virtconvert.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:2k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  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/config.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_vtop_fallback (unsigned long) __attribute__ ((const));
  19. extern unsigned long mm_ptov(unsigned long addr) __attribute__ ((const));
  20. #else
  21. extern inline unsigned long mm_vtop(unsigned long vaddr)
  22. {
  23. return __pa(vaddr);
  24. }
  25. extern inline unsigned long mm_ptov(unsigned long paddr)
  26. {
  27. return (unsigned long)__va(paddr);
  28. }
  29. #endif 
  30. #ifdef CONFIG_SINGLE_MEMORY_CHUNK
  31. extern inline unsigned long virt_to_phys(volatile void *vaddr)
  32. {
  33. unsigned long voff = (unsigned long)vaddr - PAGE_OFFSET;
  34. if (voff < m68k_memory[0].size)
  35. return voff + m68k_memory[0].addr;
  36. return mm_vtop_fallback((unsigned long)vaddr);
  37. }
  38. extern inline void * phys_to_virt(unsigned long paddr)
  39. {
  40. unsigned long poff = paddr - m68k_memory[0].addr;
  41. if (poff < m68k_memory[0].size)
  42. return (void *)(poff + PAGE_OFFSET);
  43. #ifdef CONFIG_AMIGA
  44. /*
  45.  * if on an amiga and address is in first 16M, move it 
  46.  * to the ZTWO_VADDR range
  47.  */
  48. if (MACH_IS_AMIGA && paddr < 16*1024*1024)
  49. return (void *)ZTWO_VADDR(paddr);
  50. #endif
  51. return (void *)paddr;
  52. }
  53. #else
  54. extern inline unsigned long virt_to_phys(volatile void * address)
  55. {
  56. return mm_vtop((unsigned long)address);
  57. }
  58. extern inline void * phys_to_virt(unsigned long address)
  59. {
  60. return (void *) mm_ptov(address);
  61. }
  62. #endif
  63. /*
  64.  * IO bus memory addresses are 1:1 with the physical address,
  65.  * except on the PCI bus of the Hades.
  66.  */
  67. #ifdef CONFIG_HADES
  68. #define virt_to_bus(a) (virt_to_phys(a) + (MACH_IS_HADES ? 0x80000000 : 0))
  69. #define bus_to_virt(a) (phys_to_virt((a) - (MACH_IS_HADES ? 0x80000000 : 0)))
  70. #else
  71. #define virt_to_bus virt_to_phys
  72. #define bus_to_virt phys_to_virt
  73. #endif
  74. #endif
  75. #endif