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


/*
 * 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.
 */

15 16
#include <linux/lmb.h>

L
Linus Torvalds 已提交
17 18 19
#include <asm/types.h>
#include <asm/page.h>
#include <asm/prom.h>
20
#include <asm/firmware.h>
21 22

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

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

32 33 34 35 36
/* 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)

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

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

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

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

55
	chunk = addr_to_chunk(pa);
56

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

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

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

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

74
#endif /* __KERNEL__ */
75
#endif /* _ASM_POWERPC_ABS_ADDR_H */