contig.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 <davidm@hpl.hp.com>
  8. * Stephane Eranian <eranian@hpl.hp.com>
  9. * Copyright (C) 2000, Rohit Seth <rohit.seth@intel.com>
  10. * Copyright (C) 1999 VA Linux Systems
  11. * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
  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 <asm/meminit.h>
  23. #include <asm/sections.h>
  24. #include <asm/mca.h>
  25. #ifdef CONFIG_VIRTUAL_MEM_MAP
  26. static unsigned long max_gap;
  27. #endif
  28. /* physical address where the bootmem map is located */
  29. unsigned long bootmap_start;
  30. #ifdef CONFIG_SMP
  31. static void *cpu_data;
  32. /**
  33. * per_cpu_init - setup per-cpu variables
  34. *
  35. * Allocate and setup per-cpu data areas.
  36. */
  37. void *per_cpu_init(void)
  38. {
  39. static bool first_time = true;
  40. void *cpu0_data = __cpu0_per_cpu;
  41. unsigned int cpu;
  42. if (!first_time)
  43. goto skip;
  44. first_time = false;
  45. /*
  46. * get_free_pages() cannot be used before cpu_init() done.
  47. * BSP allocates PERCPU_PAGE_SIZE bytes for all possible CPUs
  48. * to avoid that AP calls get_zeroed_page().
  49. */
  50. for_each_possible_cpu(cpu) {
  51. void *src = cpu == 0 ? cpu0_data : __phys_per_cpu_start;
  52. memcpy(cpu_data, src, __per_cpu_end - __per_cpu_start);
  53. __per_cpu_offset[cpu] = (char *)cpu_data - __per_cpu_start;
  54. per_cpu(local_per_cpu_offset, cpu) = __per_cpu_offset[cpu];
  55. /*
  56. * percpu area for cpu0 is moved from the __init area
  57. * which is setup by head.S and used till this point.
  58. * Update ar.k3. This move is ensures that percpu
  59. * area for cpu0 is on the correct node and its
  60. * virtual address isn't insanely far from other
  61. * percpu areas which is important for congruent
  62. * percpu allocator.
  63. */
  64. if (cpu == 0)
  65. ia64_set_kr(IA64_KR_PER_CPU_DATA, __pa(cpu_data) -
  66. (unsigned long)__per_cpu_start);
  67. cpu_data += PERCPU_PAGE_SIZE;
  68. }
  69. skip:
  70. return __per_cpu_start + __per_cpu_offset[smp_processor_id()];
  71. }
  72. static inline void
  73. alloc_per_cpu_data(void)
  74. {
  75. size_t size = PERCPU_PAGE_SIZE * num_possible_cpus();
  76. cpu_data = memblock_alloc_from(size, PERCPU_PAGE_SIZE,
  77. __pa(MAX_DMA_ADDRESS));
  78. if (!cpu_data)
  79. panic("%s: Failed to allocate %lu bytes align=%lx from=%lx\n",
  80. __func__, size, PERCPU_PAGE_SIZE, __pa(MAX_DMA_ADDRESS));
  81. }
  82. /**
  83. * setup_per_cpu_areas - setup percpu areas
  84. *
  85. * Arch code has already allocated and initialized percpu areas. All
  86. * this function has to do is to teach the determined layout to the
  87. * dynamic percpu allocator, which happens to be more complex than
  88. * creating whole new ones using helpers.
  89. */
  90. void __init
  91. setup_per_cpu_areas(void)
  92. {
  93. struct pcpu_alloc_info *ai;
  94. struct pcpu_group_info *gi;
  95. unsigned int cpu;
  96. ssize_t static_size, reserved_size, dyn_size;
  97. ai = pcpu_alloc_alloc_info(1, num_possible_cpus());
  98. if (!ai)
  99. panic("failed to allocate pcpu_alloc_info");
  100. gi = &ai->groups[0];
  101. /* units are assigned consecutively to possible cpus */
  102. for_each_possible_cpu(cpu)
  103. gi->cpu_map[gi->nr_units++] = cpu;
  104. /* set parameters */
  105. static_size = __per_cpu_end - __per_cpu_start;
  106. reserved_size = PERCPU_MODULE_RESERVE;
  107. dyn_size = PERCPU_PAGE_SIZE - static_size - reserved_size;
  108. if (dyn_size < 0)
  109. panic("percpu area overflow static=%zd reserved=%zd\n",
  110. static_size, reserved_size);
  111. ai->static_size = static_size;
  112. ai->reserved_size = reserved_size;
  113. ai->dyn_size = dyn_size;
  114. ai->unit_size = PERCPU_PAGE_SIZE;
  115. ai->atom_size = PAGE_SIZE;
  116. ai->alloc_size = PERCPU_PAGE_SIZE;
  117. pcpu_setup_first_chunk(ai, __per_cpu_start + __per_cpu_offset[0]);
  118. pcpu_free_alloc_info(ai);
  119. }
  120. #else
  121. #define alloc_per_cpu_data() do { } while (0)
  122. #endif /* CONFIG_SMP */
  123. /**
  124. * find_memory - setup memory map
  125. *
  126. * Walk the EFI memory map and find usable memory for the system, taking
  127. * into account reserved areas.
  128. */
  129. void __init
  130. find_memory (void)
  131. {
  132. reserve_memory();
  133. /* first find highest page frame number */
  134. min_low_pfn = ~0UL;
  135. max_low_pfn = 0;
  136. efi_memmap_walk(find_max_min_low_pfn, NULL);
  137. max_pfn = max_low_pfn;
  138. #ifdef CONFIG_VIRTUAL_MEM_MAP
  139. efi_memmap_walk(filter_memory, register_active_ranges);
  140. #else
  141. memblock_add_node(0, PFN_PHYS(max_low_pfn), 0);
  142. #endif
  143. find_initrd();
  144. alloc_per_cpu_data();
  145. }
  146. /*
  147. * Set up the page tables.
  148. */
  149. void __init
  150. paging_init (void)
  151. {
  152. unsigned long max_dma;
  153. unsigned long max_zone_pfns[MAX_NR_ZONES];
  154. memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
  155. #ifdef CONFIG_ZONE_DMA32
  156. max_dma = virt_to_phys((void *) MAX_DMA_ADDRESS) >> PAGE_SHIFT;
  157. max_zone_pfns[ZONE_DMA32] = max_dma;
  158. #endif
  159. max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
  160. #ifdef CONFIG_VIRTUAL_MEM_MAP
  161. efi_memmap_walk(find_largest_hole, (u64 *)&max_gap);
  162. if (max_gap < LARGE_GAP) {
  163. vmem_map = (struct page *) 0;
  164. } else {
  165. unsigned long map_size;
  166. /* allocate virtual_mem_map */
  167. map_size = PAGE_ALIGN(ALIGN(max_low_pfn, MAX_ORDER_NR_PAGES) *
  168. sizeof(struct page));
  169. VMALLOC_END -= map_size;
  170. vmem_map = (struct page *) VMALLOC_END;
  171. efi_memmap_walk(create_mem_map_page_table, NULL);
  172. /*
  173. * alloc_node_mem_map makes an adjustment for mem_map
  174. * which isn't compatible with vmem_map.
  175. */
  176. NODE_DATA(0)->node_mem_map = vmem_map +
  177. find_min_pfn_with_active_regions();
  178. printk("Virtual mem_map starts at 0x%p\n", mem_map);
  179. }
  180. #endif /* !CONFIG_VIRTUAL_MEM_MAP */
  181. free_area_init(max_zone_pfns);
  182. zero_page_memmap_ptr = virt_to_page(ia64_imva(empty_zero_page));
  183. }