fixmap.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef _ASM_FIXMAP_H
  2. #define _ASM_FIXMAP_H
  3. #ifdef CONFIG_X86_32
  4. # include "fixmap_32.h"
  5. #else
  6. # include "fixmap_64.h"
  7. #endif
  8. extern int fixmaps_set;
  9. extern void __set_fixmap(enum fixed_addresses idx,
  10. unsigned long phys, pgprot_t flags);
  11. #define set_fixmap(idx, phys) \
  12. __set_fixmap(idx, phys, PAGE_KERNEL)
  13. /*
  14. * Some hardware wants to get fixmapped without caching.
  15. */
  16. #define set_fixmap_nocache(idx, phys) \
  17. __set_fixmap(idx, phys, PAGE_KERNEL_NOCACHE)
  18. #define clear_fixmap(idx) \
  19. __set_fixmap(idx, 0, __pgprot(0))
  20. #define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))
  21. #define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
  22. extern void __this_fixmap_does_not_exist(void);
  23. /*
  24. * 'index to address' translation. If anyone tries to use the idx
  25. * directly without translation, we catch the bug with a NULL-deference
  26. * kernel oops. Illegal ranges of incoming indices are caught too.
  27. */
  28. static __always_inline unsigned long fix_to_virt(const unsigned int idx)
  29. {
  30. /*
  31. * this branch gets completely eliminated after inlining,
  32. * except when someone tries to use fixaddr indices in an
  33. * illegal way. (such as mixing up address types or using
  34. * out-of-range indices).
  35. *
  36. * If it doesn't get removed, the linker will complain
  37. * loudly with a reasonably clear error message..
  38. */
  39. if (idx >= __end_of_fixed_addresses)
  40. __this_fixmap_does_not_exist();
  41. return __fix_to_virt(idx);
  42. }
  43. static inline unsigned long virt_to_fix(const unsigned long vaddr)
  44. {
  45. BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
  46. return __virt_to_fix(vaddr);
  47. }
  48. #endif