fixmap.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #ifndef __UM_FIXMAP_H
  2. #define __UM_FIXMAP_H
  3. #include <asm/processor.h>
  4. #include <asm/system.h>
  5. #include <asm/kmap_types.h>
  6. #include <asm/archparam.h>
  7. #include <asm/page.h>
  8. #include <linux/threads.h>
  9. /*
  10. * Here we define all the compile-time 'special' virtual
  11. * addresses. The point is to have a constant address at
  12. * compile time, but to set the physical address only
  13. * in the boot process. We allocate these special addresses
  14. * from the end of virtual memory (0xfffff000) backwards.
  15. * Also this lets us do fail-safe vmalloc(), we
  16. * can guarantee that these special addresses and
  17. * vmalloc()-ed addresses never overlap.
  18. *
  19. * these 'compile-time allocated' memory buffers are
  20. * fixed-size 4k pages. (or larger if used with an increment
  21. * highger than 1) use fixmap_set(idx,phys) to associate
  22. * physical memory with fixmap indices.
  23. *
  24. * TLB entries of such buffers will not be flushed across
  25. * task switches.
  26. */
  27. /*
  28. * on UP currently we will have no trace of the fixmap mechanizm,
  29. * no page table allocations, etc. This might change in the
  30. * future, say framebuffers for the console driver(s) could be
  31. * fix-mapped?
  32. */
  33. enum fixed_addresses {
  34. #ifdef CONFIG_HIGHMEM
  35. FIX_KMAP_BEGIN, /* reserved pte's for temporary kernel mappings */
  36. FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,
  37. #endif
  38. __end_of_fixed_addresses
  39. };
  40. extern void __set_fixmap (enum fixed_addresses idx,
  41. unsigned long phys, pgprot_t flags);
  42. #define set_fixmap(idx, phys) \
  43. __set_fixmap(idx, phys, PAGE_KERNEL)
  44. /*
  45. * Some hardware wants to get fixmapped without caching.
  46. */
  47. #define set_fixmap_nocache(idx, phys) \
  48. __set_fixmap(idx, phys, PAGE_KERNEL_NOCACHE)
  49. /*
  50. * used by vmalloc.c.
  51. *
  52. * Leave one empty page between vmalloc'ed areas and
  53. * the start of the fixmap, and leave one page empty
  54. * at the top of mem..
  55. */
  56. #define FIXADDR_TOP (TASK_SIZE - 2 * PAGE_SIZE)
  57. #define FIXADDR_SIZE (__end_of_fixed_addresses << PAGE_SHIFT)
  58. #define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE)
  59. #define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))
  60. #define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
  61. extern void __this_fixmap_does_not_exist(void);
  62. /*
  63. * 'index to address' translation. If anyone tries to use the idx
  64. * directly without tranlation, we catch the bug with a NULL-deference
  65. * kernel oops. Illegal ranges of incoming indices are caught too.
  66. */
  67. static inline unsigned long fix_to_virt(const unsigned int idx)
  68. {
  69. /*
  70. * this branch gets completely eliminated after inlining,
  71. * except when someone tries to use fixaddr indices in an
  72. * illegal way. (such as mixing up address types or using
  73. * out-of-range indices).
  74. *
  75. * If it doesn't get removed, the linker will complain
  76. * loudly with a reasonably clear error message..
  77. */
  78. if (idx >= __end_of_fixed_addresses)
  79. __this_fixmap_does_not_exist();
  80. return __fix_to_virt(idx);
  81. }
  82. static inline unsigned long virt_to_fix(const unsigned long vaddr)
  83. {
  84. BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
  85. return __virt_to_fix(vaddr);
  86. }
  87. #endif