blob: c5c3259e0f86f3d147f9daf50719ea5e6311162c [file] [log] [blame]
David Gibson8882a4d2005-11-09 13:38:01 +11001#ifndef _ASM_POWERPC_ABS_ADDR_H
2#define _ASM_POWERPC_ABS_ADDR_H
Arnd Bergmann88ced032005-12-16 22:43:46 +01003#ifdef __KERNEL__
Linus Torvalds1da177e2005-04-16 15:20:36 -07004
5#include <linux/config.h>
6
7/*
8 * c 2001 PPC 64 Team, IBM Corp
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
14 */
15
16#include <asm/types.h>
17#include <asm/page.h>
18#include <asm/prom.h>
19#include <asm/lmb.h>
Michael Ellermanbef56862005-08-03 20:21:26 +100020#include <asm/firmware.h>
Michael Ellerman56e97b72005-08-03 20:21:23 +100021
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 Ellermance217952005-08-03 20:21:23 +100047static inline unsigned long phys_to_abs(unsigned long pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048{
Michael Ellermance217952005-08-03 20:21:23 +100049 unsigned long chunk;
50
Michael Ellermanbef56862005-08-03 20:21:26 +100051 /* This is a no-op on non-iSeries */
52 if (!firmware_has_feature(FW_FEATURE_ISERIES))
53 return pa;
54
Michael Ellermance217952005-08-03 20:21:23 +100055 chunk = addr_to_chunk(pa);
56
57 if (chunk < mschunks_map.num_chunks)
58 chunk = mschunks_map.mapping[chunk];
59
60 return chunk_to_addr(chunk) + (pa & MSCHUNKS_OFFSET_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061}
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063/* Convenience macros */
64#define virt_to_abs(va) phys_to_abs(__pa(va))
Michael Ellermane88bcd12005-08-03 20:21:25 +100065#define abs_to_virt(aa) __va(aa)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Stephen Rothwell426c1a12005-10-14 14:51:42 +100067/*
68 * Converts Virtual Address to Real Address for
69 * Legacy iSeries Hypervisor calls
70 */
71#define iseries_hv_addr(virtaddr) \
72 (0x8000000000000000 | virt_to_abs(virtaddr))
73
Arnd Bergmann88ced032005-12-16 22:43:46 +010074#endif /* __KERNEL__ */
David Gibson8882a4d2005-11-09 13:38:01 +110075#endif /* _ASM_POWERPC_ABS_ADDR_H */