fixmap.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #define __FIXADDR_SIZE (__end_of_permanent_fixed_addresses << PAGE_SHIFT)
  75. #define __FIXADDR_BOOT_SIZE (__end_of_fixed_addresses << PAGE_SHIFT)
  76. #define FIXADDR_START (FIXADDR_TOP + PAGE_SIZE - __FIXADDR_SIZE)
  77. #define FIXADDR_BOOT_START (FIXADDR_TOP + PAGE_SIZE - __FIXADDR_BOOT_SIZE)
  78. extern void __this_fixmap_does_not_exist(void);
  79. /*
  80. * 'index to address' translation. If anyone tries to use the idx
  81. * directly without tranlation, we catch the bug with a NULL-deference
  82. * kernel oops. Illegal ranges of incoming indices are caught too.
  83. */
  84. static __always_inline unsigned long fix_to_virt(const unsigned int idx)
  85. {
  86. /*
  87. * this branch gets completely eliminated after inlining,
  88. * except when someone tries to use fixaddr indices in an
  89. * illegal way. (such as mixing up address types or using
  90. * out-of-range indices).
  91. *
  92. * If it doesn't get removed, the linker will complain
  93. * loudly with a reasonably clear error message..
  94. */
  95. if (idx >= __end_of_fixed_addresses)
  96. __this_fixmap_does_not_exist();
  97. return __fix_to_virt(idx);
  98. }
  99. static inline unsigned long virt_to_fix(const unsigned long vaddr)
  100. {
  101. BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
  102. return __virt_to_fix(vaddr);
  103. }
  104. #endif /* !__ASSEMBLY__ */
  105. #endif /* _ASM_TILE_FIXMAP_H */