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 typedef u32 msChunks_entry;
21 struct msChunks {
22         unsigned long num_chunks;
23         unsigned long chunk_size;
24         unsigned long chunk_shift;
25         unsigned long chunk_mask;
26         msChunks_entry *abs;
27 };
28 
29 extern struct msChunks msChunks;
30 
31 extern unsigned long msChunks_alloc(unsigned long, unsigned long, unsigned long);
32 extern unsigned long reloc_offset(void);
33 
34 #ifdef CONFIG_MSCHUNKS
35 
36 static inline unsigned long
chunk_to_addr(unsigned long chunk)37 chunk_to_addr(unsigned long chunk)
38 {
39 	unsigned long offset = reloc_offset();
40 	struct msChunks *_msChunks = PTRRELOC(&msChunks);
41 
42 	return chunk << _msChunks->chunk_shift;
43 }
44 
45 static inline unsigned long
addr_to_chunk(unsigned long addr)46 addr_to_chunk(unsigned long addr)
47 {
48 	unsigned long offset = reloc_offset();
49 	struct msChunks *_msChunks = PTRRELOC(&msChunks);
50 
51 	return addr >> _msChunks->chunk_shift;
52 }
53 
54 static inline unsigned long
chunk_offset(unsigned long addr)55 chunk_offset(unsigned long addr)
56 {
57 	unsigned long offset = reloc_offset();
58 	struct msChunks *_msChunks = PTRRELOC(&msChunks);
59 
60 	return addr & _msChunks->chunk_mask;
61 }
62 
63 static inline unsigned long
abs_chunk(unsigned long pchunk)64 abs_chunk(unsigned long pchunk)
65 {
66 	unsigned long offset = reloc_offset();
67 	struct msChunks *_msChunks = PTRRELOC(&msChunks);
68 	if ( pchunk >= _msChunks->num_chunks ) {
69 		return pchunk;
70 	}
71 	return PTRRELOC(_msChunks->abs)[pchunk];
72 }
73 
74 
75 static inline unsigned long
phys_to_absolute(unsigned long pa)76 phys_to_absolute(unsigned long pa)
77 {
78 	return chunk_to_addr(abs_chunk(addr_to_chunk(pa))) + chunk_offset(pa);
79 }
80 
81 static inline unsigned long
physRpn_to_absRpn(unsigned long rpn)82 physRpn_to_absRpn(unsigned long rpn)
83 {
84 	unsigned long pa = rpn << PAGE_SHIFT;
85 	unsigned long aa = phys_to_absolute(pa);
86 	return (aa >> PAGE_SHIFT);
87 }
88 
89 static inline unsigned long
absolute_to_phys(unsigned long aa)90 absolute_to_phys(unsigned long aa)
91 {
92 	return lmb_abs_to_phys(aa);
93 }
94 
95 #else  /* !CONFIG_MSCHUNKS */
96 
97 #define chunk_to_addr(chunk) ((unsigned long)(chunk))
98 #define addr_to_chunk(addr) (addr)
99 #define chunk_offset(addr) (0)
100 #define abs_chunk(pchunk) (pchunk)
101 
102 #define phys_to_absolute(pa) (pa)
103 #define physRpn_to_absRpn(rpn) (rpn)
104 #define absolute_to_phys(aa) (aa)
105 
106 #endif /* !CONFIG_MSCHUNKS */
107 
108 
109 static inline unsigned long
virt_to_absolute(unsigned long ea)110 virt_to_absolute(unsigned long ea)
111 {
112 	return phys_to_absolute(__pa(ea));
113 }
114 
115 static inline unsigned long
absolute_to_virt(unsigned long aa)116 absolute_to_virt(unsigned long aa)
117 {
118 	return (unsigned long)__va(absolute_to_phys(aa));
119 }
120 
121 #endif /* _ABS_ADDR_H */
122