blob: 2276567f133a29bf541139e33f8382260a4ad1c4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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
Linus Torvalds1da177e2005-04-16 15:20:36 -070020struct msChunks {
21 unsigned long num_chunks;
22 unsigned long chunk_size;
23 unsigned long chunk_shift;
24 unsigned long chunk_mask;
Michael Ellerman34c8f692005-08-03 20:21:23 +100025 u32 *abs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026};
27
28extern struct msChunks msChunks;
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31#ifdef CONFIG_MSCHUNKS
32
Michael Ellerman34c8f692005-08-03 20:21:23 +100033/* 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
Michael Ellerman38e85dc2005-08-03 20:21:23 +100038static inline unsigned long chunk_to_addr(unsigned long chunk)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
Michael Ellerman34c8f692005-08-03 20:21:23 +100040 return chunk << MSCHUNKS_CHUNK_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041}
42
Michael Ellerman38e85dc2005-08-03 20:21:23 +100043static inline unsigned long addr_to_chunk(unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
Michael Ellerman34c8f692005-08-03 20:21:23 +100045 return addr >> MSCHUNKS_CHUNK_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046}
47
Michael Ellerman38e85dc2005-08-03 20:21:23 +100048static inline unsigned long chunk_offset(unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
Michael Ellerman34c8f692005-08-03 20:21:23 +100050 return addr & MSCHUNKS_OFFSET_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051}
52
Michael Ellerman38e85dc2005-08-03 20:21:23 +100053static inline unsigned long abs_chunk(unsigned long pchunk)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
Michael Ellerman38e85dc2005-08-03 20:21:23 +100055 if (pchunk >= msChunks.num_chunks)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 return pchunk;
Michael Ellerman38e85dc2005-08-03 20:21:23 +100057
58 return msChunks.abs[pchunk];
Linus Torvalds1da177e2005-04-16 15:20:36 -070059}
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
67static inline unsigned long
68physRpn_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 */