fixmap.h 3.8 KB

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