fixmap.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (C) 1998 Ingo Molnar
  3. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation, version 2.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  12. * NON INFRINGEMENT. See the GNU General Public License for
  13. * more details.
  14. */
  15. #ifndef _ASM_TILE_FIXMAP_H
  16. #define _ASM_TILE_FIXMAP_H
  17. #include <asm/page.h>
  18. #ifndef __ASSEMBLY__
  19. #include <linux/kernel.h>
  20. #ifdef CONFIG_HIGHMEM
  21. #include <linux/threads.h>
  22. #include <asm/kmap_types.h>
  23. #endif
  24. #define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))
  25. #define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
  26. /*
  27. * Here we define all the compile-time 'special' virtual
  28. * addresses. The point is to have a constant address at
  29. * compile time, but to set the physical address only
  30. * in the boot process. We allocate these special addresses
  31. * from the end of supervisor virtual memory backwards.
  32. * Also this lets us do fail-safe vmalloc(), we
  33. * can guarantee that these special addresses and
  34. * vmalloc()-ed addresses never overlap.
  35. *
  36. * these 'compile-time allocated' memory buffers are
  37. * fixed-size 4k pages. (or larger if used with an increment
  38. * higher than 1) use fixmap_set(idx,phys) to associate
  39. * physical memory with fixmap indices.
  40. *
  41. * TLB entries of such buffers will not be flushed across
  42. * task switches.
  43. *
  44. * We don't bother with a FIX_HOLE since above the fixmaps
  45. * is unmapped memory in any case.
  46. */
  47. enum fixed_addresses {
  48. #ifdef CONFIG_HIGHMEM
  49. FIX_KMAP_BEGIN, /* reserved pte's for temporary kernel mappings */
  50. FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,
  51. #endif
  52. __end_of_permanent_fixed_addresses,
  53. /*
  54. * Temporary boot-time mappings, used before ioremap() is functional.
  55. * Not currently needed by the Tile architecture.
  56. */
  57. #define NR_FIX_BTMAPS 0
  58. #if NR_FIX_BTMAPS
  59. FIX_BTMAP_END = __end_of_permanent_fixed_addresses,
  60. FIX_BTMAP_BEGIN = FIX_BTMAP_END + NR_FIX_BTMAPS - 1,
  61. __end_of_fixed_addresses
  62. #else
  63. __end_of_fixed_addresses = __end_of_permanent_fixed_addresses
  64. #endif
  65. };
  66. extern void __set_fixmap(enum fixed_addresses idx,
  67. unsigned long phys, pgprot_t flags);
  68. #define set_fixmap(idx, phys) \
  69. __set_fixmap(idx, phys, PAGE_KERNEL)
  70. /*
  71. * Some hardware wants to get fixmapped without caching.
  72. */
  73. #define set_fixmap_nocache(idx, phys) \
  74. __set_fixmap(idx, phys, PAGE_KERNEL_NOCACHE)
  75. #define clear_fixmap(idx) \
  76. __set_fixmap(idx, 0, __pgprot(0))
  77. #define __FIXADDR_SIZE (__end_of_permanent_fixed_addresses << PAGE_SHIFT)
  78. #define __FIXADDR_BOOT_SIZE (__end_of_fixed_addresses << PAGE_SHIFT)
  79. #define FIXADDR_START (FIXADDR_TOP + PAGE_SIZE - __FIXADDR_SIZE)
  80. #define FIXADDR_BOOT_START (FIXADDR_TOP + PAGE_SIZE - __FIXADDR_BOOT_SIZE)
  81. extern void __this_fixmap_does_not_exist(void);
  82. /*
  83. * 'index to address' translation. If anyone tries to use the idx
  84. * directly without tranlation, we catch the bug with a NULL-deference
  85. * kernel oops. Illegal ranges of incoming indices are caught too.
  86. */
  87. static __always_inline unsigned long fix_to_virt(const unsigned int idx)
  88. {
  89. /*
  90. * this branch gets completely eliminated after inlining,
  91. * except when someone tries to use fixaddr indices in an
  92. * illegal way. (such as mixing up address types or using
  93. * out-of-range indices).
  94. *
  95. * If it doesn't get removed, the linker will complain
  96. * loudly with a reasonably clear error message..
  97. */
  98. if (idx >= __end_of_fixed_addresses)
  99. __this_fixmap_does_not_exist();
  100. return __fix_to_virt(idx);
  101. }
  102. static inline unsigned long virt_to_fix(const unsigned long vaddr)
  103. {
  104. BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
  105. return __virt_to_fix(vaddr);
  106. }
  107. #endif /* !__ASSEMBLY__ */
  108. #endif /* _ASM_TILE_FIXMAP_H */