blob: 05414a9bfdd183aba40670351b48a73fef5ec394 [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
Michael Ellerman56e97b72005-08-03 20:21:23 +100020#ifdef CONFIG_MSCHUNKS
21
22struct mschunks_map {
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 unsigned long num_chunks;
24 unsigned long chunk_size;
25 unsigned long chunk_shift;
26 unsigned long chunk_mask;
Michael Ellerman56e97b72005-08-03 20:21:23 +100027 u32 *mapping;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028};
29
Michael Ellerman56e97b72005-08-03 20:21:23 +100030extern struct mschunks_map mschunks_map;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Michael Ellerman34c8f692005-08-03 20:21:23 +100032/* Chunks are 256 KB */
33#define MSCHUNKS_CHUNK_SHIFT (18)
34#define MSCHUNKS_CHUNK_SIZE (1UL << MSCHUNKS_CHUNK_SHIFT)
35#define MSCHUNKS_OFFSET_MASK (MSCHUNKS_CHUNK_SIZE - 1)
36
Michael Ellerman38e85dc2005-08-03 20:21:23 +100037static inline unsigned long chunk_to_addr(unsigned long chunk)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038{
Michael Ellerman34c8f692005-08-03 20:21:23 +100039 return chunk << MSCHUNKS_CHUNK_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040}
41
Michael Ellerman38e85dc2005-08-03 20:21:23 +100042static inline unsigned long addr_to_chunk(unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043{
Michael Ellerman34c8f692005-08-03 20:21:23 +100044 return addr >> MSCHUNKS_CHUNK_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045}
46
Michael Ellerman38e85dc2005-08-03 20:21:23 +100047static inline unsigned long chunk_offset(unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048{
Michael Ellerman34c8f692005-08-03 20:21:23 +100049 return addr & MSCHUNKS_OFFSET_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050}
51
Michael Ellerman38e85dc2005-08-03 20:21:23 +100052static inline unsigned long abs_chunk(unsigned long pchunk)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
Michael Ellerman56e97b72005-08-03 20:21:23 +100054 if (pchunk >= mschunks_map.num_chunks)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 return pchunk;
Michael Ellerman38e85dc2005-08-03 20:21:23 +100056
Michael Ellerman56e97b72005-08-03 20:21:23 +100057 return mschunks_map.mapping[pchunk];
Linus Torvalds1da177e2005-04-16 15:20:36 -070058}
59
60/* A macro so it can take pointers or unsigned long. */
61#define phys_to_abs(pa) \
62 ({ unsigned long _pa = (unsigned long)(pa); \
63 chunk_to_addr(abs_chunk(addr_to_chunk(_pa))) + chunk_offset(_pa); \
64 })
65
66static inline unsigned long
67physRpn_to_absRpn(unsigned long rpn)
68{
69 unsigned long pa = rpn << PAGE_SHIFT;
70 unsigned long aa = phys_to_abs(pa);
71 return (aa >> PAGE_SHIFT);
72}
73
74/* A macro so it can take pointers or unsigned long. */
75#define abs_to_phys(aa) lmb_abs_to_phys((unsigned long)(aa))
76
77#else /* !CONFIG_MSCHUNKS */
78
79#define chunk_to_addr(chunk) ((unsigned long)(chunk))
80#define addr_to_chunk(addr) (addr)
81#define chunk_offset(addr) (0)
82#define abs_chunk(pchunk) (pchunk)
83
84#define phys_to_abs(pa) (pa)
85#define physRpn_to_absRpn(rpn) (rpn)
86#define abs_to_phys(aa) (aa)
87
88#endif /* !CONFIG_MSCHUNKS */
89
90/* Convenience macros */
91#define virt_to_abs(va) phys_to_abs(__pa(va))
92#define abs_to_virt(aa) __va(abs_to_phys(aa))
93
94#endif /* _ABS_ADDR_H */