4 #include <linux/config.h>
7 * c 2001 PPC 64 Team, IBM Corp
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
15 #include <asm/types.h>
21 unsigned long num_chunks;
22 unsigned long chunk_size;
23 unsigned long chunk_shift;
24 unsigned long chunk_mask;
28 extern struct msChunks msChunks;
31 #ifdef CONFIG_MSCHUNKS
33 /* Chunks are 256 KB */
34 #define MSCHUNKS_CHUNK_SHIFT (18)
35 #define MSCHUNKS_CHUNK_SIZE (1UL << MSCHUNKS_CHUNK_SHIFT)
36 #define MSCHUNKS_OFFSET_MASK (MSCHUNKS_CHUNK_SIZE - 1)
38 static inline unsigned long chunk_to_addr(unsigned long chunk)
40 return chunk << MSCHUNKS_CHUNK_SHIFT;
43 static inline unsigned long addr_to_chunk(unsigned long addr)
45 return addr >> MSCHUNKS_CHUNK_SHIFT;
48 static inline unsigned long chunk_offset(unsigned long addr)
50 return addr & MSCHUNKS_OFFSET_MASK;
53 static inline unsigned long abs_chunk(unsigned long pchunk)
55 if (pchunk >= msChunks.num_chunks)
58 return msChunks.abs[pchunk];
61 /* A macro so it can take pointers or unsigned long. */
62 #define phys_to_abs(pa) \
63 ({ unsigned long _pa = (unsigned long)(pa); \
64 chunk_to_addr(abs_chunk(addr_to_chunk(_pa))) + chunk_offset(_pa); \
67 static inline unsigned long
68 physRpn_to_absRpn(unsigned long rpn)
70 unsigned long pa = rpn << PAGE_SHIFT;
71 unsigned long aa = phys_to_abs(pa);
72 return (aa >> PAGE_SHIFT);
75 /* A macro so it can take pointers or unsigned long. */
76 #define abs_to_phys(aa) lmb_abs_to_phys((unsigned long)(aa))
78 #else /* !CONFIG_MSCHUNKS */
80 #define chunk_to_addr(chunk) ((unsigned long)(chunk))
81 #define addr_to_chunk(addr) (addr)
82 #define chunk_offset(addr) (0)
83 #define abs_chunk(pchunk) (pchunk)
85 #define phys_to_abs(pa) (pa)
86 #define physRpn_to_absRpn(rpn) (rpn)
87 #define abs_to_phys(aa) (aa)
89 #endif /* !CONFIG_MSCHUNKS */
91 /* Convenience macros */
92 #define virt_to_abs(va) phys_to_abs(__pa(va))
93 #define abs_to_virt(aa) __va(abs_to_phys(aa))
95 #endif /* _ABS_ADDR_H */