abs_addr.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #ifndef _ABS_ADDR_H
  2. #define _ABS_ADDR_H
  3. #include <linux/config.h>
  4. /*
  5. * c 2001 PPC 64 Team, IBM Corp
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. */
  12. #include <asm/types.h>
  13. #include <asm/page.h>
  14. #include <asm/prom.h>
  15. #include <asm/lmb.h>
  16. typedef u32 msChunks_entry;
  17. struct msChunks {
  18. unsigned long num_chunks;
  19. unsigned long chunk_size;
  20. unsigned long chunk_shift;
  21. unsigned long chunk_mask;
  22. msChunks_entry *abs;
  23. };
  24. extern struct msChunks msChunks;
  25. extern unsigned long msChunks_alloc(unsigned long, unsigned long, unsigned long);
  26. extern unsigned long reloc_offset(void);
  27. #ifdef CONFIG_MSCHUNKS
  28. static inline unsigned long
  29. chunk_to_addr(unsigned long chunk)
  30. {
  31. unsigned long offset = reloc_offset();
  32. struct msChunks *_msChunks = PTRRELOC(&msChunks);
  33. return chunk << _msChunks->chunk_shift;
  34. }
  35. static inline unsigned long
  36. addr_to_chunk(unsigned long addr)
  37. {
  38. unsigned long offset = reloc_offset();
  39. struct msChunks *_msChunks = PTRRELOC(&msChunks);
  40. return addr >> _msChunks->chunk_shift;
  41. }
  42. static inline unsigned long
  43. chunk_offset(unsigned long addr)
  44. {
  45. unsigned long offset = reloc_offset();
  46. struct msChunks *_msChunks = PTRRELOC(&msChunks);
  47. return addr & _msChunks->chunk_mask;
  48. }
  49. static inline unsigned long
  50. abs_chunk(unsigned long pchunk)
  51. {
  52. unsigned long offset = reloc_offset();
  53. struct msChunks *_msChunks = PTRRELOC(&msChunks);
  54. if ( pchunk >= _msChunks->num_chunks ) {
  55. return pchunk;
  56. }
  57. return PTRRELOC(_msChunks->abs)[pchunk];
  58. }
  59. /* A macro so it can take pointers or unsigned long. */
  60. #define phys_to_abs(pa) \
  61. ({ unsigned long _pa = (unsigned long)(pa); \
  62. chunk_to_addr(abs_chunk(addr_to_chunk(_pa))) + chunk_offset(_pa); \
  63. })
  64. static inline unsigned long
  65. physRpn_to_absRpn(unsigned long rpn)
  66. {
  67. unsigned long pa = rpn << PAGE_SHIFT;
  68. unsigned long aa = phys_to_abs(pa);
  69. return (aa >> PAGE_SHIFT);
  70. }
  71. /* A macro so it can take pointers or unsigned long. */
  72. #define abs_to_phys(aa) lmb_abs_to_phys((unsigned long)(aa))
  73. #else /* !CONFIG_MSCHUNKS */
  74. #define chunk_to_addr(chunk) ((unsigned long)(chunk))
  75. #define addr_to_chunk(addr) (addr)
  76. #define chunk_offset(addr) (0)
  77. #define abs_chunk(pchunk) (pchunk)
  78. #define phys_to_abs(pa) (pa)
  79. #define physRpn_to_absRpn(rpn) (rpn)
  80. #define abs_to_phys(aa) (aa)
  81. #endif /* !CONFIG_MSCHUNKS */
  82. /* Convenience macros */
  83. #define virt_to_abs(va) phys_to_abs(__pa(va))
  84. #define abs_to_virt(aa) __va(abs_to_phys(aa))
  85. #endif /* _ABS_ADDR_H */