fixmap.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #ifndef __ASM_OPENRISC_FIXMAP_H
  19. #define __ASM_OPENRISC_FIXMAP_H
  20. /* Why exactly do we need 2 empty pages between the top of the fixed
  21. * addresses and the top of virtual memory? Something is using that
  22. * memory space but not sure what right now... If you find it, leave
  23. * a comment here.
  24. */
  25. #define FIXADDR_TOP ((unsigned long) (-2*PAGE_SIZE))
  26. #include <linux/kernel.h>
  27. #include <asm/page.h>
  28. /*
  29. * On OpenRISC we use these special fixed_addresses for doing ioremap
  30. * early in the boot process before memory initialization is complete.
  31. * This is used, in particular, by the early serial console code.
  32. *
  33. * It's not really 'fixmap', per se, but fits loosely into the same
  34. * paradigm.
  35. */
  36. enum fixed_addresses {
  37. /*
  38. * FIX_IOREMAP entries are useful for mapping physical address
  39. * space before ioremap() is useable, e.g. really early in boot
  40. * before kmalloc() is working.
  41. */
  42. #define FIX_N_IOREMAPS 32
  43. FIX_IOREMAP_BEGIN,
  44. FIX_IOREMAP_END = FIX_IOREMAP_BEGIN + FIX_N_IOREMAPS - 1,
  45. __end_of_fixed_addresses
  46. };
  47. #define FIXADDR_SIZE (__end_of_fixed_addresses << PAGE_SHIFT)
  48. /* FIXADDR_BOTTOM might be a better name here... */
  49. #define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE)
  50. #define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))
  51. #define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
  52. /*
  53. * 'index to address' translation. If anyone tries to use the idx
  54. * directly without tranlation, we catch the bug with a NULL-deference
  55. * kernel oops. Illegal ranges of incoming indices are caught too.
  56. */
  57. static __always_inline unsigned long fix_to_virt(const unsigned int idx)
  58. {
  59. /*
  60. * this branch gets completely eliminated after inlining,
  61. * except when someone tries to use fixaddr indices in an
  62. * illegal way. (such as mixing up address types or using
  63. * out-of-range indices).
  64. *
  65. * If it doesn't get removed, the linker will complain
  66. * loudly with a reasonably clear error message..
  67. */
  68. if (idx >= __end_of_fixed_addresses)
  69. BUG();
  70. return __fix_to_virt(idx);
  71. }
  72. static inline unsigned long virt_to_fix(const unsigned long vaddr)
  73. {
  74. BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
  75. return __virt_to_fix(vaddr);
  76. }
  77. #endif