abs_addr.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #ifdef CONFIG_MSCHUNKS
  17. struct mschunks_map {
  18. unsigned long num_chunks;
  19. unsigned long chunk_size;
  20. unsigned long chunk_shift;
  21. unsigned long chunk_mask;
  22. u32 *mapping;
  23. };
  24. extern struct mschunks_map mschunks_map;
  25. /* Chunks are 256 KB */
  26. #define MSCHUNKS_CHUNK_SHIFT (18)
  27. #define MSCHUNKS_CHUNK_SIZE (1UL << MSCHUNKS_CHUNK_SHIFT)
  28. #define MSCHUNKS_OFFSET_MASK (MSCHUNKS_CHUNK_SIZE - 1)
  29. static inline unsigned long chunk_to_addr(unsigned long chunk)
  30. {
  31. return chunk << MSCHUNKS_CHUNK_SHIFT;
  32. }
  33. static inline unsigned long addr_to_chunk(unsigned long addr)
  34. {
  35. return addr >> MSCHUNKS_CHUNK_SHIFT;
  36. }
  37. static inline unsigned long chunk_offset(unsigned long addr)
  38. {
  39. return addr & MSCHUNKS_OFFSET_MASK;
  40. }
  41. static inline unsigned long abs_chunk(unsigned long pchunk)
  42. {
  43. if (pchunk >= mschunks_map.num_chunks)
  44. return pchunk;
  45. return mschunks_map.mapping[pchunk];
  46. }
  47. /* A macro so it can take pointers or unsigned long. */
  48. #define phys_to_abs(pa) \
  49. ({ unsigned long _pa = (unsigned long)(pa); \
  50. chunk_to_addr(abs_chunk(addr_to_chunk(_pa))) + chunk_offset(_pa); \
  51. })
  52. static inline unsigned long
  53. physRpn_to_absRpn(unsigned long rpn)
  54. {
  55. unsigned long pa = rpn << PAGE_SHIFT;
  56. unsigned long aa = phys_to_abs(pa);
  57. return (aa >> PAGE_SHIFT);
  58. }
  59. /* A macro so it can take pointers or unsigned long. */
  60. #define abs_to_phys(aa) lmb_abs_to_phys((unsigned long)(aa))
  61. #else /* !CONFIG_MSCHUNKS */
  62. #define chunk_to_addr(chunk) ((unsigned long)(chunk))
  63. #define addr_to_chunk(addr) (addr)
  64. #define chunk_offset(addr) (0)
  65. #define abs_chunk(pchunk) (pchunk)
  66. #define phys_to_abs(pa) (pa)
  67. #define physRpn_to_absRpn(rpn) (rpn)
  68. #define abs_to_phys(aa) (aa)
  69. #endif /* !CONFIG_MSCHUNKS */
  70. /* Convenience macros */
  71. #define virt_to_abs(va) phys_to_abs(__pa(va))
  72. #define abs_to_virt(aa) __va(abs_to_phys(aa))
  73. #endif /* _ABS_ADDR_H */