Jonas Bonn | 61e85e3 | 2011-06-04 11:06:11 +0300 | [diff] [blame] | 1 | /* |
| 2 | * OpenRISC Linux |
| 3 | * |
| 4 | * Linux architectural port borrowing liberally from similar works of |
| 5 | * others. All original copyrights apply as per the original source |
| 6 | * declaration. |
| 7 | * |
| 8 | * OpenRISC implementation: |
| 9 | * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com> |
| 10 | * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se> |
| 11 | * et al. |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2 of the License, or |
| 16 | * (at your option) any later version. |
| 17 | */ |
| 18 | |
| 19 | #ifndef __ASM_OPENRISC_FIXMAP_H |
| 20 | #define __ASM_OPENRISC_FIXMAP_H |
| 21 | |
| 22 | /* Why exactly do we need 2 empty pages between the top of the fixed |
| 23 | * addresses and the top of virtual memory? Something is using that |
| 24 | * memory space but not sure what right now... If you find it, leave |
| 25 | * a comment here. |
| 26 | */ |
| 27 | #define FIXADDR_TOP ((unsigned long) (-2*PAGE_SIZE)) |
| 28 | |
| 29 | #include <linux/kernel.h> |
| 30 | #include <asm/page.h> |
| 31 | |
| 32 | /* |
| 33 | * On OpenRISC we use these special fixed_addresses for doing ioremap |
| 34 | * early in the boot process before memory initialization is complete. |
| 35 | * This is used, in particular, by the early serial console code. |
| 36 | * |
| 37 | * It's not really 'fixmap', per se, but fits loosely into the same |
| 38 | * paradigm. |
| 39 | */ |
| 40 | enum fixed_addresses { |
| 41 | /* |
| 42 | * FIX_IOREMAP entries are useful for mapping physical address |
| 43 | * space before ioremap() is useable, e.g. really early in boot |
| 44 | * before kmalloc() is working. |
| 45 | */ |
| 46 | #define FIX_N_IOREMAPS 32 |
| 47 | FIX_IOREMAP_BEGIN, |
| 48 | FIX_IOREMAP_END = FIX_IOREMAP_BEGIN + FIX_N_IOREMAPS - 1, |
| 49 | __end_of_fixed_addresses |
| 50 | }; |
| 51 | |
| 52 | #define FIXADDR_SIZE (__end_of_fixed_addresses << PAGE_SHIFT) |
| 53 | /* FIXADDR_BOTTOM might be a better name here... */ |
| 54 | #define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE) |
| 55 | |
| 56 | #define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT)) |
| 57 | #define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT) |
| 58 | |
| 59 | /* |
| 60 | * 'index to address' translation. If anyone tries to use the idx |
| 61 | * directly without tranlation, we catch the bug with a NULL-deference |
| 62 | * kernel oops. Illegal ranges of incoming indices are caught too. |
| 63 | */ |
| 64 | static __always_inline unsigned long fix_to_virt(const unsigned int idx) |
| 65 | { |
| 66 | /* |
| 67 | * this branch gets completely eliminated after inlining, |
| 68 | * except when someone tries to use fixaddr indices in an |
| 69 | * illegal way. (such as mixing up address types or using |
| 70 | * out-of-range indices). |
| 71 | * |
| 72 | * If it doesn't get removed, the linker will complain |
| 73 | * loudly with a reasonably clear error message.. |
| 74 | */ |
| 75 | if (idx >= __end_of_fixed_addresses) |
| 76 | BUG(); |
| 77 | |
| 78 | return __fix_to_virt(idx); |
| 79 | } |
| 80 | |
| 81 | static inline unsigned long virt_to_fix(const unsigned long vaddr) |
| 82 | { |
| 83 | BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START); |
| 84 | return __virt_to_fix(vaddr); |
| 85 | } |
| 86 | |
| 87 | #endif |