fixmap.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. enum fixed_addresses {
  45. #ifdef __tilegx__
  46. /*
  47. * TILEPro has unmapped memory above so the hole isn't needed,
  48. * and in any case the hole pushes us over a single 16MB pmd.
  49. */
  50. FIX_HOLE,
  51. #endif
  52. #ifdef CONFIG_HIGHMEM
  53. FIX_KMAP_BEGIN, /* reserved pte's for temporary kernel mappings */
  54. FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,
  55. #endif
  56. #ifdef __tilegx__ /* see homecache.c */
  57. FIX_HOMECACHE_BEGIN,
  58. FIX_HOMECACHE_END = FIX_HOMECACHE_BEGIN+(NR_CPUS)-1,
  59. #endif
  60. __end_of_permanent_fixed_addresses,
  61. /*
  62. * Temporary boot-time mappings, used before ioremap() is functional.
  63. * Not currently needed by the Tile architecture.
  64. */
  65. #define NR_FIX_BTMAPS 0
  66. #if NR_FIX_BTMAPS
  67. FIX_BTMAP_END = __end_of_permanent_fixed_addresses,
  68. FIX_BTMAP_BEGIN = FIX_BTMAP_END + NR_FIX_BTMAPS - 1,
  69. __end_of_fixed_addresses
  70. #else
  71. __end_of_fixed_addresses = __end_of_permanent_fixed_addresses
  72. #endif
  73. };
  74. extern void __set_fixmap(enum fixed_addresses idx,
  75. unsigned long phys, pgprot_t flags);
  76. #define set_fixmap(idx, phys) \
  77. __set_fixmap(idx, phys, PAGE_KERNEL)
  78. #define clear_fixmap(idx) \
  79. __set_fixmap(idx, 0, __pgprot(0))
  80. #define __FIXADDR_SIZE (__end_of_permanent_fixed_addresses << PAGE_SHIFT)
  81. #define __FIXADDR_BOOT_SIZE (__end_of_fixed_addresses << PAGE_SHIFT)
  82. #define FIXADDR_START (FIXADDR_TOP + PAGE_SIZE - __FIXADDR_SIZE)
  83. #define FIXADDR_BOOT_START (FIXADDR_TOP + PAGE_SIZE - __FIXADDR_BOOT_SIZE)
  84. extern void __this_fixmap_does_not_exist(void);
  85. /*
  86. * 'index to address' translation. If anyone tries to use the idx
  87. * directly without tranlation, we catch the bug with a NULL-deference
  88. * kernel oops. Illegal ranges of incoming indices are caught too.
  89. */
  90. static __always_inline unsigned long fix_to_virt(const unsigned int idx)
  91. {
  92. /*
  93. * this branch gets completely eliminated after inlining,
  94. * except when someone tries to use fixaddr indices in an
  95. * illegal way. (such as mixing up address types or using
  96. * out-of-range indices).
  97. *
  98. * If it doesn't get removed, the linker will complain
  99. * loudly with a reasonably clear error message..
  100. */
  101. if (idx >= __end_of_fixed_addresses)
  102. __this_fixmap_does_not_exist();
  103. return __fix_to_virt(idx);
  104. }
  105. static inline unsigned long virt_to_fix(const unsigned long vaddr)
  106. {
  107. BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
  108. return __virt_to_fix(vaddr);
  109. }
  110. #endif /* !__ASSEMBLY__ */
  111. #endif /* _ASM_TILE_FIXMAP_H */