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