fixmap.h 3.6 KB

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