abs_addr.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 phys_to_abs(unsigned long pa)
  38. {
  39. unsigned long chunk;
  40. chunk = addr_to_chunk(pa);
  41. if (chunk < mschunks_map.num_chunks)
  42. chunk = mschunks_map.mapping[chunk];
  43. return chunk_to_addr(chunk) + (pa & MSCHUNKS_OFFSET_MASK);
  44. }
  45. /* A macro so it can take pointers or unsigned long. */
  46. #define abs_to_phys(aa) lmb_abs_to_phys((unsigned long)(aa))
  47. #else /* !CONFIG_MSCHUNKS */
  48. #define chunk_to_addr(chunk) ((unsigned long)(chunk))
  49. #define addr_to_chunk(addr) (addr)
  50. #define chunk_offset(addr) (0)
  51. #define abs_chunk(pchunk) (pchunk)
  52. #define phys_to_abs(pa) (pa)
  53. #define physRpn_to_absRpn(rpn) (rpn)
  54. #define abs_to_phys(aa) (aa)
  55. #endif /* !CONFIG_MSCHUNKS */
  56. /* Convenience macros */
  57. #define virt_to_abs(va) phys_to_abs(__pa(va))
  58. #define abs_to_virt(aa) __va(abs_to_phys(aa))
  59. #endif /* _ABS_ADDR_H */