abs_addr.h 1.8 KB
Newer Older
1 2
#ifndef _ASM_POWERPC_ABS_ADDR_H
#define _ASM_POWERPC_ABS_ADDR_H
3
#ifdef __KERNEL__
L
Linus Torvalds 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18


/*
 * c 2001 PPC 64 Team, IBM Corp
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
 */

#include <asm/types.h>
#include <asm/page.h>
#include <asm/prom.h>
#include <asm/lmb.h>
19
#include <asm/firmware.h>
20 21

struct mschunks_map {
L
Linus Torvalds 已提交
22 23 24 25
        unsigned long num_chunks;
        unsigned long chunk_size;
        unsigned long chunk_shift;
        unsigned long chunk_mask;
26
        u32 *mapping;
L
Linus Torvalds 已提交
27 28
};

29
extern struct mschunks_map mschunks_map;
L
Linus Torvalds 已提交
30

31 32 33 34 35
/* Chunks are 256 KB */
#define MSCHUNKS_CHUNK_SHIFT	(18)
#define MSCHUNKS_CHUNK_SIZE	(1UL << MSCHUNKS_CHUNK_SHIFT)
#define MSCHUNKS_OFFSET_MASK	(MSCHUNKS_CHUNK_SIZE - 1)

36
static inline unsigned long chunk_to_addr(unsigned long chunk)
L
Linus Torvalds 已提交
37
{
38
	return chunk << MSCHUNKS_CHUNK_SHIFT;
L
Linus Torvalds 已提交
39 40
}

41
static inline unsigned long addr_to_chunk(unsigned long addr)
L
Linus Torvalds 已提交
42
{
43
	return addr >> MSCHUNKS_CHUNK_SHIFT;
L
Linus Torvalds 已提交
44 45
}

46
static inline unsigned long phys_to_abs(unsigned long pa)
L
Linus Torvalds 已提交
47
{
48
	unsigned long chunk;
L
Linus Torvalds 已提交
49

50 51 52 53
	/* This is a no-op on non-iSeries */
	if (!firmware_has_feature(FW_FEATURE_ISERIES))
		return pa;

54
	chunk = addr_to_chunk(pa);
55

56 57
	if (chunk < mschunks_map.num_chunks)
		chunk = mschunks_map.mapping[chunk];
L
Linus Torvalds 已提交
58

59 60
	return chunk_to_addr(chunk) + (pa & MSCHUNKS_OFFSET_MASK);
}
L
Linus Torvalds 已提交
61 62 63

/* Convenience macros */
#define virt_to_abs(va) phys_to_abs(__pa(va))
64
#define abs_to_virt(aa) __va(aa)
L
Linus Torvalds 已提交
65

66 67 68 69 70 71 72
/*
 * Converts Virtual Address to Real Address for
 * Legacy iSeries Hypervisor calls
 */
#define iseries_hv_addr(virtaddr)	\
	(0x8000000000000000 | virt_to_abs(virtaddr))

73
#endif /* __KERNEL__ */
74
#endif /* _ASM_POWERPC_ABS_ADDR_H */