]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - include/asm-ppc64/abs_addr.h
[PATCH] ppc64: msChunks cleanups
[linux-2.6-omap-h63xx.git] / include / asm-ppc64 / abs_addr.h
1 #ifndef _ABS_ADDR_H
2 #define _ABS_ADDR_H
3
4 #include <linux/config.h>
5
6 /*
7  * c 2001 PPC 64 Team, IBM Corp
8  *
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.
13  */
14
15 #include <asm/types.h>
16 #include <asm/page.h>
17 #include <asm/prom.h>
18 #include <asm/lmb.h>
19
20 struct msChunks {
21         unsigned long num_chunks;
22         unsigned long chunk_size;
23         unsigned long chunk_shift;
24         unsigned long chunk_mask;
25         u32 *abs;
26 };
27
28 extern struct msChunks msChunks;
29
30
31 #ifdef CONFIG_MSCHUNKS
32
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)
37
38 static inline unsigned long chunk_to_addr(unsigned long chunk)
39 {
40         return chunk << MSCHUNKS_CHUNK_SHIFT;
41 }
42
43 static inline unsigned long addr_to_chunk(unsigned long addr)
44 {
45         return addr >> MSCHUNKS_CHUNK_SHIFT;
46 }
47
48 static inline unsigned long chunk_offset(unsigned long addr)
49 {
50         return addr & MSCHUNKS_OFFSET_MASK;
51 }
52
53 static inline unsigned long abs_chunk(unsigned long pchunk)
54 {
55         if (pchunk >= msChunks.num_chunks)
56                 return pchunk;
57
58         return msChunks.abs[pchunk];
59 }
60
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); \
65         })
66
67 static inline unsigned long
68 physRpn_to_absRpn(unsigned long rpn)
69 {
70         unsigned long pa = rpn << PAGE_SHIFT;
71         unsigned long aa = phys_to_abs(pa);
72         return (aa >> PAGE_SHIFT);
73 }
74
75 /* A macro so it can take pointers or unsigned long. */
76 #define abs_to_phys(aa) lmb_abs_to_phys((unsigned long)(aa))
77
78 #else  /* !CONFIG_MSCHUNKS */
79
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)
84
85 #define phys_to_abs(pa) (pa)
86 #define physRpn_to_absRpn(rpn) (rpn)
87 #define abs_to_phys(aa) (aa)
88
89 #endif /* !CONFIG_MSCHUNKS */
90
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))
94
95 #endif /* _ABS_ADDR_H */