blob: 5ab0b71531be8f0701dc5a17fe4f1a54b3a6d22f [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
Linus Torvalds1da177e2005-04-16 15:20:36 -07005
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
Yinghai Lu95f72d12010-07-12 14:36:09 +100015#include <linux/memblock.h>
David S. Millerd9b2b2a2008-02-13 16:56:49 -080016
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/types.h>
18#include <asm/page.h>
19#include <asm/prom.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) \
Denis Kirjanov51c7fdb2010-06-16 04:34:44 +000072 (0x8000000000000000UL | virt_to_abs(virtaddr))
Stephen Rothwell426c1a12005-10-14 14:51:42 +100073
Arnd Bergmann88ced032005-12-16 22:43:46 +010074#endif /* __KERNEL__ */
David Gibson8882a4d2005-11-09 13:38:01 +110075#endif /* _ASM_POWERPC_ABS_ADDR_H */