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