contig.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1998-2003 Hewlett-Packard Co
  7. * David Mosberger-Tang <[email protected]>
  8. * Stephane Eranian <[email protected]>
  9. * Copyright (C) 2000, Rohit Seth <[email protected]>
  10. * Copyright (C) 1999 VA Linux Systems
  11. * Copyright (C) 1999 Walt Drummond <[email protected]>
  12. * Copyright (C) 2003 Silicon Graphics, Inc. All rights reserved.
  13. *
  14. * Routines used by ia64 machines with contiguous (or virtually contiguous)
  15. * memory.
  16. */
  17. #include <linux/efi.h>
  18. #include <linux/memblock.h>
  19. #include <linux/mm.h>
  20. #include <linux/nmi.h>
  21. #include <linux/swap.h>
  22. #include <linux/sizes.h>
  23. #include <asm/efi.h>
  24. #include <asm/meminit.h>
  25. #include <asm/sections.h>
  26. #include <asm/mca.h>
  27. /* physical address where the bootmem map is located */
  28. unsigned long bootmap_start;
  29. #ifdef CONFIG_SMP
  30. static void *cpu_data;
  31. /**
  32. * per_cpu_init - setup per-cpu variables
  33. *
  34. * Allocate and setup per-cpu data areas.
  35. */
  36. void *per_cpu_init(void)
  37. {
  38. static bool first_time = true;
  39. void *cpu0_data = __cpu0_per_cpu;
  40. unsigned int cpu;
  41. if (!first_time)
  42. goto skip;
  43. first_time = false;
  44. /*
  45. * get_free_pages() cannot be used before cpu_init() done.
  46. * BSP allocates PERCPU_PAGE_SIZE bytes for all possible CPUs
  47. * to avoid that AP calls get_zeroed_page().
  48. */
  49. for_each_possible_cpu(cpu) {
  50. void *src = cpu == 0 ? cpu0_data : __phys_per_cpu_start;
  51. memcpy(cpu_data, src, __per_cpu_end - __per_cpu_start);
  52. __per_cpu_offset[cpu] = (char *)cpu_data - __per_cpu_start;
  53. per_cpu(local_per_cpu_offset, cpu) = __per_cpu_offset[cpu];
  54. /*
  55. * percpu area for cpu0 is moved from the __init area
  56. * which is setup by head.S and used till this point.
  57. * Update ar.k3. This move is ensures that percpu
  58. * area for cpu0 is on the correct node and its
  59. * virtual address isn't insanely far from other
  60. * percpu areas which is important for congruent
  61. * percpu allocator.
  62. */
  63. if (cpu == 0)
  64. ia64_set_kr(IA64_KR_PER_CPU_DATA, __pa(cpu_data) -
  65. (unsigned long)__per_cpu_start);
  66. cpu_data += PERCPU_PAGE_SIZE;
  67. }
  68. skip:
  69. return __per_cpu_start + __per_cpu_offset[smp_processor_id()];
  70. }
  71. static inline __init void
  72. alloc_per_cpu_data(void)
  73. {
  74. size_t size = PERCPU_PAGE_SIZE * num_possible_cpus();
  75. cpu_data = memblock_alloc_from(size, PERCPU_PAGE_SIZE,
  76. __pa(MAX_DMA_ADDRESS));
  77. if (!cpu_data)
  78. panic("%s: Failed to allocate %lu bytes align=%lx from=%lx\n",
  79. __func__, size, PERCPU_PAGE_SIZE, __pa(MAX_DMA_ADDRESS));
  80. }
  81. /**
  82. * setup_per_cpu_areas - setup percpu areas
  83. *
  84. * Arch code has already allocated and initialized percpu areas. All
  85. * this function has to do is to teach the determined layout to the
  86. * dynamic percpu allocator, which happens to be more complex than
  87. * creating whole new ones using helpers.
  88. */
  89. void __init
  90. setup_per_cpu_areas(void)
  91. {
  92. struct pcpu_alloc_info *ai;
  93. struct pcpu_group_info *gi;
  94. unsigned int cpu;
  95. ssize_t static_size, reserved_size, dyn_size;
  96. ai = pcpu_alloc_alloc_info(1, num_possible_cpus());
  97. if (!ai)
  98. panic("failed to allocate pcpu_alloc_info");
  99. gi = &ai->groups[0];
  100. /* units are assigned consecutively to possible cpus */
  101. for_each_possible_cpu(cpu)
  102. gi->cpu_map[gi->nr_units++] = cpu;
  103. /* set parameters */
  104. static_size = __per_cpu_end - __per_cpu_start;
  105. reserved_size = PERCPU_MODULE_RESERVE;
  106. dyn_size = PERCPU_PAGE_SIZE - static_size - reserved_size;
  107. if (dyn_size < 0)
  108. panic("percpu area overflow static=%zd reserved=%zd\n",
  109. static_size, reserved_size);
  110. ai->static_size = static_size;
  111. ai->reserved_size = reserved_size;
  112. ai->dyn_size = dyn_size;
  113. ai->unit_size = PERCPU_PAGE_SIZE;
  114. ai->atom_size = PAGE_SIZE;
  115. ai->alloc_size = PERCPU_PAGE_SIZE;
  116. pcpu_setup_first_chunk(ai, __per_cpu_start + __per_cpu_offset[0]);
  117. pcpu_free_alloc_info(ai);
  118. }
  119. #else
  120. #define alloc_per_cpu_data() do { } while (0)
  121. #endif /* CONFIG_SMP */
  122. /**
  123. * find_memory - setup memory map
  124. *
  125. * Walk the EFI memory map and find usable memory for the system, taking
  126. * into account reserved areas.
  127. */
  128. void __init
  129. find_memory (void)
  130. {
  131. reserve_memory();
  132. /* first find highest page frame number */
  133. min_low_pfn = ~0UL;
  134. max_low_pfn = 0;
  135. efi_memmap_walk(find_max_min_low_pfn, NULL);
  136. max_pfn = max_low_pfn;
  137. memblock_add_node(0, PFN_PHYS(max_low_pfn), 0, MEMBLOCK_NONE);
  138. find_initrd();
  139. alloc_per_cpu_data();
  140. }
  141. static int __init find_largest_hole(u64 start, u64 end, void *arg)
  142. {
  143. u64 *max_gap = arg;
  144. static u64 last_end = PAGE_OFFSET;
  145. /* NOTE: this algorithm assumes efi memmap table is ordered */
  146. if (*max_gap < (start - last_end))
  147. *max_gap = start - last_end;
  148. last_end = end;
  149. return 0;
  150. }
  151. static void __init verify_gap_absence(void)
  152. {
  153. unsigned long max_gap;
  154. /* Forbid FLATMEM if hole is > than 1G */
  155. efi_memmap_walk(find_largest_hole, (u64 *)&max_gap);
  156. if (max_gap >= SZ_1G)
  157. panic("Cannot use FLATMEM with %ldMB hole\n"
  158. "Please switch over to SPARSEMEM\n",
  159. (max_gap >> 20));
  160. }
  161. /*
  162. * Set up the page tables.
  163. */
  164. void __init
  165. paging_init (void)
  166. {
  167. unsigned long max_dma;
  168. unsigned long max_zone_pfns[MAX_NR_ZONES];
  169. memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
  170. max_dma = virt_to_phys((void *) MAX_DMA_ADDRESS) >> PAGE_SHIFT;
  171. max_zone_pfns[ZONE_DMA32] = max_dma;
  172. max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
  173. verify_gap_absence();
  174. free_area_init(max_zone_pfns);
  175. zero_page_memmap_ptr = virt_to_page(ia64_imva(empty_zero_page));
  176. }