fixmap.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))
  18. #define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
  19. #ifndef __ASSEMBLY__
  20. /*
  21. * 'index to address' translation. If anyone tries to use the idx
  22. * directly without translation, we catch the bug with a NULL-deference
  23. * kernel oops. Illegal ranges of incoming indices are caught too.
  24. */
  25. static __always_inline unsigned long fix_to_virt(const unsigned int idx)
  26. {
  27. BUILD_BUG_ON(idx >= __end_of_fixed_addresses);
  28. return __fix_to_virt(idx);
  29. }
  30. static inline unsigned long virt_to_fix(const unsigned long vaddr)
  31. {
  32. BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
  33. return __virt_to_fix(vaddr);
  34. }
  35. /*
  36. * Provide some reasonable defaults for page flags.
  37. * Not all architectures use all of these different types and some
  38. * architectures use different names.
  39. */
  40. #ifndef FIXMAP_PAGE_NORMAL
  41. #define FIXMAP_PAGE_NORMAL PAGE_KERNEL
  42. #endif
  43. #if !defined(FIXMAP_PAGE_RO) && defined(PAGE_KERNEL_RO)
  44. #define FIXMAP_PAGE_RO PAGE_KERNEL_RO
  45. #endif
  46. #ifndef FIXMAP_PAGE_NOCACHE
  47. #define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NOCACHE
  48. #endif
  49. #ifndef FIXMAP_PAGE_IO
  50. #define FIXMAP_PAGE_IO PAGE_KERNEL_IO
  51. #endif
  52. #ifndef FIXMAP_PAGE_CLEAR
  53. #define FIXMAP_PAGE_CLEAR __pgprot(0)
  54. #endif
  55. #ifndef set_fixmap
  56. #define set_fixmap(idx, phys) \
  57. __set_fixmap(idx, phys, FIXMAP_PAGE_NORMAL)
  58. #endif
  59. #ifndef clear_fixmap
  60. #define clear_fixmap(idx) \
  61. __set_fixmap(idx, 0, FIXMAP_PAGE_CLEAR)
  62. #endif
  63. /* Return a pointer with offset calculated */
  64. #define __set_fixmap_offset(idx, phys, flags) \
  65. ({ \
  66. unsigned long ________addr; \
  67. __set_fixmap(idx, phys, flags); \
  68. ________addr = fix_to_virt(idx) + ((phys) & (PAGE_SIZE - 1)); \
  69. ________addr; \
  70. })
  71. #define set_fixmap_offset(idx, phys) \
  72. __set_fixmap_offset(idx, phys, FIXMAP_PAGE_NORMAL)
  73. /*
  74. * Some hardware wants to get fixmapped without caching.
  75. */
  76. #define set_fixmap_nocache(idx, phys) \
  77. __set_fixmap(idx, phys, FIXMAP_PAGE_NOCACHE)
  78. #define set_fixmap_offset_nocache(idx, phys) \
  79. __set_fixmap_offset(idx, phys, FIXMAP_PAGE_NOCACHE)
  80. /*
  81. * Some fixmaps are for IO
  82. */
  83. #define set_fixmap_io(idx, phys) \
  84. __set_fixmap(idx, phys, FIXMAP_PAGE_IO)
  85. #define set_fixmap_offset_io(idx, phys) \
  86. __set_fixmap_offset(idx, phys, FIXMAP_PAGE_IO)
  87. #endif /* __ASSEMBLY__ */
  88. #endif /* __ASM_GENERIC_FIXMAP_H */