fixmap.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * fixmap.h: compile-time virtual memory allocation
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * Copyright (C) 1998 Ingo Molnar
  9. *
  10. * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
  11. * x86_32 and x86_64 integration by Gustavo F. Padovan, February 2009
  12. * Break out common bits to asm-generic by Mark Salter, November 2013
  13. */
  14. #ifndef __ASM_GENERIC_FIXMAP_H
  15. #define __ASM_GENERIC_FIXMAP_H
  16. #include <linux/bug.h>
  17. #include <linux/mm_types.h>
  18. #define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))
  19. #define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
  20. #ifndef __ASSEMBLY__
  21. /*
  22. * 'index to address' translation. If anyone tries to use the idx
  23. * directly without translation, we catch the bug with a NULL-deference
  24. * kernel oops. Illegal ranges of incoming indices are caught too.
  25. */
  26. static __always_inline unsigned long fix_to_virt(const unsigned int idx)
  27. {
  28. BUILD_BUG_ON(idx >= __end_of_fixed_addresses);
  29. return __fix_to_virt(idx);
  30. }
  31. static inline unsigned long virt_to_fix(const unsigned long vaddr)
  32. {
  33. BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
  34. return __virt_to_fix(vaddr);
  35. }
  36. /*
  37. * Provide some reasonable defaults for page flags.
  38. * Not all architectures use all of these different types and some
  39. * architectures use different names.
  40. */
  41. #ifndef FIXMAP_PAGE_NORMAL
  42. #define FIXMAP_PAGE_NORMAL PAGE_KERNEL
  43. #endif
  44. #if !defined(FIXMAP_PAGE_RO) && defined(PAGE_KERNEL_RO)
  45. #define FIXMAP_PAGE_RO PAGE_KERNEL_RO
  46. #endif
  47. #ifndef FIXMAP_PAGE_NOCACHE
  48. #define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NOCACHE
  49. #endif
  50. #ifndef FIXMAP_PAGE_IO
  51. #define FIXMAP_PAGE_IO PAGE_KERNEL_IO
  52. #endif
  53. #ifndef FIXMAP_PAGE_CLEAR
  54. #define FIXMAP_PAGE_CLEAR __pgprot(0)
  55. #endif
  56. #ifndef set_fixmap
  57. #define set_fixmap(idx, phys) \
  58. __set_fixmap(idx, phys, FIXMAP_PAGE_NORMAL)
  59. #endif
  60. #ifndef clear_fixmap
  61. #define clear_fixmap(idx) \
  62. __set_fixmap(idx, 0, FIXMAP_PAGE_CLEAR)
  63. #endif
  64. /* Return a pointer with offset calculated */
  65. #define __set_fixmap_offset(idx, phys, flags) \
  66. ({ \
  67. unsigned long ________addr; \
  68. __set_fixmap(idx, phys, flags); \
  69. ________addr = fix_to_virt(idx) + ((phys) & (PAGE_SIZE - 1)); \
  70. ________addr; \
  71. })
  72. #define set_fixmap_offset(idx, phys) \
  73. __set_fixmap_offset(idx, phys, FIXMAP_PAGE_NORMAL)
  74. /*
  75. * Some hardware wants to get fixmapped without caching.
  76. */
  77. #define set_fixmap_nocache(idx, phys) \
  78. __set_fixmap(idx, phys, FIXMAP_PAGE_NOCACHE)
  79. #define set_fixmap_offset_nocache(idx, phys) \
  80. __set_fixmap_offset(idx, phys, FIXMAP_PAGE_NOCACHE)
  81. /*
  82. * Some fixmaps are for IO
  83. */
  84. #define set_fixmap_io(idx, phys) \
  85. __set_fixmap(idx, phys, FIXMAP_PAGE_IO)
  86. #define set_fixmap_offset_io(idx, phys) \
  87. __set_fixmap_offset(idx, phys, FIXMAP_PAGE_IO)
  88. #endif /* __ASSEMBLY__ */
  89. #endif /* __ASM_GENERIC_FIXMAP_H */