abs_addr.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. struct msChunks {
  17. unsigned long num_chunks;
  18. unsigned long chunk_size;
  19. unsigned long chunk_shift;
  20. unsigned long chunk_mask;
  21. u32 *abs;
  22. };
  23. extern struct msChunks msChunks;
  24. #ifdef CONFIG_MSCHUNKS
  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.num_chunks)
  44. return pchunk;
  45. return msChunks.abs[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 */