fixmap.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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/pgtable.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 start of the consistent memory region upwards.
  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. * higher than 1) use fixmap_set(idx,phys) to associate
  32. * physical memory with fixmap indices.
  33. */
  34. enum fixed_addresses {
  35. #ifdef CONFIG_HIGHMEM
  36. /* reserved pte's for temporary kernel mappings */
  37. FIX_KMAP_BEGIN,
  38. FIX_KMAP_END = FIX_KMAP_BEGIN +
  39. (KM_TYPE_NR * NR_CPUS * DCACHE_N_COLORS) - 1,
  40. #endif
  41. __end_of_fixed_addresses
  42. };
  43. #define FIXADDR_TOP (VMALLOC_START - PAGE_SIZE)
  44. #define FIXADDR_SIZE (__end_of_fixed_addresses << PAGE_SHIFT)
  45. #define FIXADDR_START ((FIXADDR_TOP - FIXADDR_SIZE) & PMD_MASK)
  46. #define __fix_to_virt(x) (FIXADDR_START + ((x) << PAGE_SHIFT))
  47. #define __virt_to_fix(x) (((x) - FIXADDR_START) >> PAGE_SHIFT)
  48. #ifndef __ASSEMBLY__
  49. /*
  50. * 'index to address' translation. If anyone tries to use the idx
  51. * directly without translation, we catch the bug with a NULL-deference
  52. * kernel oops. Illegal ranges of incoming indices are caught too.
  53. */
  54. static __always_inline unsigned long fix_to_virt(const unsigned int idx)
  55. {
  56. /* Check if this memory layout is broken because fixmap overlaps page
  57. * table.
  58. */
  59. BUILD_BUG_ON(FIXADDR_START <
  60. XCHAL_PAGE_TABLE_VADDR + XCHAL_PAGE_TABLE_SIZE);
  61. BUILD_BUG_ON(idx >= __end_of_fixed_addresses);
  62. return __fix_to_virt(idx);
  63. }
  64. static inline unsigned long virt_to_fix(const unsigned long vaddr)
  65. {
  66. BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
  67. return __virt_to_fix(vaddr);
  68. }
  69. #endif
  70. #define kmap_get_fixmap_pte(vaddr) \
  71. pte_offset_kernel( \
  72. pmd_offset(pud_offset(pgd_offset_k(vaddr), (vaddr)), (vaddr)), \
  73. (vaddr) \
  74. )
  75. #endif