Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #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 Ellerman | 56e97b7 | 2005-08-03 20:21:23 +1000 | [diff] [blame] | 20 | #ifdef CONFIG_MSCHUNKS |
| 21 | |
| 22 | struct mschunks_map { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | unsigned long num_chunks; |
| 24 | unsigned long chunk_size; |
| 25 | unsigned long chunk_shift; |
| 26 | unsigned long chunk_mask; |
Michael Ellerman | 56e97b7 | 2005-08-03 20:21:23 +1000 | [diff] [blame] | 27 | u32 *mapping; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | }; |
| 29 | |
Michael Ellerman | 56e97b7 | 2005-08-03 20:21:23 +1000 | [diff] [blame] | 30 | extern struct mschunks_map mschunks_map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Michael Ellerman | 34c8f69 | 2005-08-03 20:21:23 +1000 | [diff] [blame] | 32 | /* 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 Ellerman | 38e85dc | 2005-08-03 20:21:23 +1000 | [diff] [blame] | 37 | static inline unsigned long chunk_to_addr(unsigned long chunk) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | { |
Michael Ellerman | 34c8f69 | 2005-08-03 20:21:23 +1000 | [diff] [blame] | 39 | return chunk << MSCHUNKS_CHUNK_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Michael Ellerman | 38e85dc | 2005-08-03 20:21:23 +1000 | [diff] [blame] | 42 | static inline unsigned long addr_to_chunk(unsigned long addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | { |
Michael Ellerman | 34c8f69 | 2005-08-03 20:21:23 +1000 | [diff] [blame] | 44 | return addr >> MSCHUNKS_CHUNK_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Michael Ellerman | ce21795 | 2005-08-03 20:21:23 +1000 | [diff] [blame^] | 47 | static inline unsigned long phys_to_abs(unsigned long pa) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | { |
Michael Ellerman | ce21795 | 2005-08-03 20:21:23 +1000 | [diff] [blame^] | 49 | unsigned long chunk; |
| 50 | |
| 51 | chunk = addr_to_chunk(pa); |
| 52 | |
| 53 | if (chunk < mschunks_map.num_chunks) |
| 54 | chunk = mschunks_map.mapping[chunk]; |
| 55 | |
| 56 | return chunk_to_addr(chunk) + (pa & MSCHUNKS_OFFSET_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | static inline unsigned long |
| 60 | physRpn_to_absRpn(unsigned long rpn) |
| 61 | { |
| 62 | unsigned long pa = rpn << PAGE_SHIFT; |
| 63 | unsigned long aa = phys_to_abs(pa); |
| 64 | return (aa >> PAGE_SHIFT); |
| 65 | } |
| 66 | |
| 67 | /* A macro so it can take pointers or unsigned long. */ |
| 68 | #define abs_to_phys(aa) lmb_abs_to_phys((unsigned long)(aa)) |
| 69 | |
| 70 | #else /* !CONFIG_MSCHUNKS */ |
| 71 | |
| 72 | #define chunk_to_addr(chunk) ((unsigned long)(chunk)) |
| 73 | #define addr_to_chunk(addr) (addr) |
| 74 | #define chunk_offset(addr) (0) |
| 75 | #define abs_chunk(pchunk) (pchunk) |
| 76 | |
| 77 | #define phys_to_abs(pa) (pa) |
| 78 | #define physRpn_to_absRpn(rpn) (rpn) |
| 79 | #define abs_to_phys(aa) (aa) |
| 80 | |
| 81 | #endif /* !CONFIG_MSCHUNKS */ |
| 82 | |
| 83 | /* Convenience macros */ |
| 84 | #define virt_to_abs(va) phys_to_abs(__pa(va)) |
| 85 | #define abs_to_virt(aa) __va(abs_to_phys(aa)) |
| 86 | |
| 87 | #endif /* _ABS_ADDR_H */ |