fixmap.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. * Copyright 2008 Freescale Semiconductor Inc.
  11. * Port to powerpc added by Kumar Gala
  12. */
  13. #ifndef _ASM_FIXMAP_H
  14. #define _ASM_FIXMAP_H
  15. #ifndef __ASSEMBLY__
  16. #include <linux/sizes.h>
  17. #include <linux/pgtable.h>
  18. #include <asm/page.h>
  19. #ifdef CONFIG_HIGHMEM
  20. #include <linux/threads.h>
  21. #include <asm/kmap_size.h>
  22. #endif
  23. #ifdef CONFIG_PPC64
  24. #define FIXADDR_TOP (IOREMAP_END + FIXADDR_SIZE)
  25. #else
  26. #define FIXADDR_SIZE 0
  27. #ifdef CONFIG_KASAN
  28. #include <asm/kasan.h>
  29. #define FIXADDR_TOP (KASAN_SHADOW_START - PAGE_SIZE)
  30. #else
  31. #define FIXADDR_TOP ((unsigned long)(-PAGE_SIZE))
  32. #endif
  33. #endif
  34. /*
  35. * Here we define all the compile-time 'special' virtual
  36. * addresses. The point is to have a constant address at
  37. * compile time, but to set the physical address only
  38. * in the boot process. We allocate these special addresses
  39. * from the end of virtual memory (0xfffff000) backwards.
  40. * Also this lets us do fail-safe vmalloc(), we
  41. * can guarantee that these special addresses and
  42. * vmalloc()-ed addresses never overlap.
  43. *
  44. * these 'compile-time allocated' memory buffers are
  45. * fixed-size 4k pages. (or larger if used with an increment
  46. * highger than 1) use fixmap_set(idx,phys) to associate
  47. * physical memory with fixmap indices.
  48. *
  49. * TLB entries of such buffers will not be flushed across
  50. * task switches.
  51. */
  52. enum fixed_addresses {
  53. FIX_HOLE,
  54. #ifdef CONFIG_PPC32
  55. /* reserve the top 128K for early debugging purposes */
  56. FIX_EARLY_DEBUG_TOP = FIX_HOLE,
  57. FIX_EARLY_DEBUG_BASE = FIX_EARLY_DEBUG_TOP+(ALIGN(SZ_128K, PAGE_SIZE)/PAGE_SIZE)-1,
  58. #ifdef CONFIG_HIGHMEM
  59. FIX_KMAP_BEGIN, /* reserved pte's for temporary kernel mappings */
  60. FIX_KMAP_END = FIX_KMAP_BEGIN + (KM_MAX_IDX * NR_CPUS) - 1,
  61. #endif
  62. #ifdef CONFIG_PPC_8xx
  63. /* For IMMR we need an aligned 512K area */
  64. #define FIX_IMMR_SIZE (512 * 1024 / PAGE_SIZE)
  65. FIX_IMMR_START,
  66. FIX_IMMR_BASE = __ALIGN_MASK(FIX_IMMR_START, FIX_IMMR_SIZE - 1) - 1 +
  67. FIX_IMMR_SIZE,
  68. #endif
  69. #ifdef CONFIG_PPC_83xx
  70. /* For IMMR we need an aligned 2M area */
  71. #define FIX_IMMR_SIZE (SZ_2M / PAGE_SIZE)
  72. FIX_IMMR_START,
  73. FIX_IMMR_BASE = __ALIGN_MASK(FIX_IMMR_START, FIX_IMMR_SIZE - 1) - 1 +
  74. FIX_IMMR_SIZE,
  75. #endif
  76. /* FIX_PCIE_MCFG, */
  77. #endif /* CONFIG_PPC32 */
  78. __end_of_permanent_fixed_addresses,
  79. #define NR_FIX_BTMAPS (SZ_256K / PAGE_SIZE)
  80. #define FIX_BTMAPS_SLOTS 16
  81. #define TOTAL_FIX_BTMAPS (NR_FIX_BTMAPS * FIX_BTMAPS_SLOTS)
  82. FIX_BTMAP_END = __end_of_permanent_fixed_addresses,
  83. FIX_BTMAP_BEGIN = FIX_BTMAP_END + TOTAL_FIX_BTMAPS - 1,
  84. __end_of_fixed_addresses
  85. };
  86. #define __FIXADDR_SIZE (__end_of_fixed_addresses << PAGE_SHIFT)
  87. #define FIXADDR_START (FIXADDR_TOP - __FIXADDR_SIZE)
  88. #define FIXMAP_ALIGNED_SIZE (ALIGN(FIXADDR_TOP, PGDIR_SIZE) - \
  89. ALIGN_DOWN(FIXADDR_START, PGDIR_SIZE))
  90. #define FIXMAP_PTE_SIZE (FIXMAP_ALIGNED_SIZE / PGDIR_SIZE * PTE_TABLE_SIZE)
  91. #define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NCG
  92. #define FIXMAP_PAGE_IO PAGE_KERNEL_NCG
  93. #include <asm-generic/fixmap.h>
  94. static inline void __set_fixmap(enum fixed_addresses idx,
  95. phys_addr_t phys, pgprot_t flags)
  96. {
  97. BUILD_BUG_ON(IS_ENABLED(CONFIG_PPC64) && __FIXADDR_SIZE > FIXADDR_SIZE);
  98. if (__builtin_constant_p(idx))
  99. BUILD_BUG_ON(idx >= __end_of_fixed_addresses);
  100. else if (WARN_ON(idx >= __end_of_fixed_addresses))
  101. return;
  102. if (pgprot_val(flags))
  103. map_kernel_page(__fix_to_virt(idx), phys, flags);
  104. else
  105. unmap_kernel_page(__fix_to_virt(idx));
  106. }
  107. #define __early_set_fixmap __set_fixmap
  108. #endif /* !__ASSEMBLY__ */
  109. #endif