fixmap.h 2.5 KB

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