init.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * S390 version
  3. * Copyright IBM Corp. 1999
  4. * Author(s): Hartmut Penner (hp@de.ibm.com)
  5. *
  6. * Derived from "arch/i386/mm/init.c"
  7. * Copyright (C) 1995 Linus Torvalds
  8. */
  9. #include <linux/signal.h>
  10. #include <linux/sched.h>
  11. #include <linux/kernel.h>
  12. #include <linux/errno.h>
  13. #include <linux/string.h>
  14. #include <linux/types.h>
  15. #include <linux/ptrace.h>
  16. #include <linux/mman.h>
  17. #include <linux/mm.h>
  18. #include <linux/swap.h>
  19. #include <linux/smp.h>
  20. #include <linux/init.h>
  21. #include <linux/pagemap.h>
  22. #include <linux/bootmem.h>
  23. #include <linux/memory.h>
  24. #include <linux/pfn.h>
  25. #include <linux/poison.h>
  26. #include <linux/initrd.h>
  27. #include <linux/export.h>
  28. #include <linux/gfp.h>
  29. #include <asm/processor.h>
  30. #include <asm/uaccess.h>
  31. #include <asm/pgtable.h>
  32. #include <asm/pgalloc.h>
  33. #include <asm/dma.h>
  34. #include <asm/lowcore.h>
  35. #include <asm/tlb.h>
  36. #include <asm/tlbflush.h>
  37. #include <asm/sections.h>
  38. #include <asm/ctl_reg.h>
  39. #include <asm/sclp.h>
  40. pgd_t swapper_pg_dir[PTRS_PER_PGD] __attribute__((__aligned__(PAGE_SIZE)));
  41. unsigned long empty_zero_page, zero_page_mask;
  42. EXPORT_SYMBOL(empty_zero_page);
  43. EXPORT_SYMBOL(zero_page_mask);
  44. static void __init setup_zero_pages(void)
  45. {
  46. struct cpuid cpu_id;
  47. unsigned int order;
  48. struct page *page;
  49. int i;
  50. get_cpu_id(&cpu_id);
  51. switch (cpu_id.machine) {
  52. case 0x9672: /* g5 */
  53. case 0x2064: /* z900 */
  54. case 0x2066: /* z900 */
  55. case 0x2084: /* z990 */
  56. case 0x2086: /* z990 */
  57. case 0x2094: /* z9-109 */
  58. case 0x2096: /* z9-109 */
  59. order = 0;
  60. break;
  61. case 0x2097: /* z10 */
  62. case 0x2098: /* z10 */
  63. case 0x2817: /* z196 */
  64. case 0x2818: /* z196 */
  65. order = 2;
  66. break;
  67. case 0x2827: /* zEC12 */
  68. case 0x2828: /* zEC12 */
  69. default:
  70. order = 5;
  71. break;
  72. }
  73. /* Limit number of empty zero pages for small memory sizes */
  74. if (order > 2 && totalram_pages <= 16384)
  75. order = 2;
  76. empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, order);
  77. if (!empty_zero_page)
  78. panic("Out of memory in setup_zero_pages");
  79. page = virt_to_page((void *) empty_zero_page);
  80. split_page(page, order);
  81. for (i = 1 << order; i > 0; i--) {
  82. mark_page_reserved(page);
  83. page++;
  84. }
  85. zero_page_mask = ((PAGE_SIZE << order) - 1) & PAGE_MASK;
  86. }
  87. /*
  88. * paging_init() sets up the page tables
  89. */
  90. void __init paging_init(void)
  91. {
  92. unsigned long max_zone_pfns[MAX_NR_ZONES];
  93. unsigned long pgd_type, asce_bits;
  94. init_mm.pgd = swapper_pg_dir;
  95. #ifdef CONFIG_64BIT
  96. if (VMALLOC_END > (1UL << 42)) {
  97. asce_bits = _ASCE_TYPE_REGION2 | _ASCE_TABLE_LENGTH;
  98. pgd_type = _REGION2_ENTRY_EMPTY;
  99. } else {
  100. asce_bits = _ASCE_TYPE_REGION3 | _ASCE_TABLE_LENGTH;
  101. pgd_type = _REGION3_ENTRY_EMPTY;
  102. }
  103. #else
  104. asce_bits = _ASCE_TABLE_LENGTH;
  105. pgd_type = _SEGMENT_ENTRY_EMPTY;
  106. #endif
  107. S390_lowcore.kernel_asce = (__pa(init_mm.pgd) & PAGE_MASK) | asce_bits;
  108. clear_table((unsigned long *) init_mm.pgd, pgd_type,
  109. sizeof(unsigned long)*2048);
  110. vmem_map_init();
  111. /* enable virtual mapping in kernel mode */
  112. __ctl_load(S390_lowcore.kernel_asce, 1, 1);
  113. __ctl_load(S390_lowcore.kernel_asce, 7, 7);
  114. __ctl_load(S390_lowcore.kernel_asce, 13, 13);
  115. arch_local_irq_restore(4UL << (BITS_PER_LONG - 8));
  116. sparse_memory_present_with_active_regions(MAX_NUMNODES);
  117. sparse_init();
  118. memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
  119. max_zone_pfns[ZONE_DMA] = PFN_DOWN(MAX_DMA_ADDRESS);
  120. max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
  121. free_area_init_nodes(max_zone_pfns);
  122. }
  123. void __init mem_init(void)
  124. {
  125. if (MACHINE_HAS_TLB_LC)
  126. cpumask_set_cpu(0, &init_mm.context.cpu_attach_mask);
  127. cpumask_set_cpu(0, mm_cpumask(&init_mm));
  128. atomic_set(&init_mm.context.attach_count, 1);
  129. max_mapnr = max_low_pfn;
  130. high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
  131. /* Setup guest page hinting */
  132. cmma_init();
  133. /* this will put all low memory onto the freelists */
  134. free_all_bootmem();
  135. setup_zero_pages(); /* Setup zeroed pages. */
  136. mem_init_print_info(NULL);
  137. printk("Write protected kernel read-only data: %#lx - %#lx\n",
  138. (unsigned long)&_stext,
  139. PFN_ALIGN((unsigned long)&_eshared) - 1);
  140. }
  141. void free_initmem(void)
  142. {
  143. free_initmem_default(POISON_FREE_INITMEM);
  144. }
  145. #ifdef CONFIG_BLK_DEV_INITRD
  146. void __init free_initrd_mem(unsigned long start, unsigned long end)
  147. {
  148. free_reserved_area((void *)start, (void *)end, POISON_FREE_INITMEM,
  149. "initrd");
  150. }
  151. #endif
  152. #ifdef CONFIG_MEMORY_HOTPLUG
  153. int arch_add_memory(int nid, u64 start, u64 size)
  154. {
  155. unsigned long zone_start_pfn, zone_end_pfn, nr_pages;
  156. unsigned long start_pfn = PFN_DOWN(start);
  157. unsigned long size_pages = PFN_DOWN(size);
  158. struct zone *zone;
  159. int rc;
  160. rc = vmem_add_mapping(start, size);
  161. if (rc)
  162. return rc;
  163. for_each_zone(zone) {
  164. if (zone_idx(zone) != ZONE_MOVABLE) {
  165. /* Add range within existing zone limits */
  166. zone_start_pfn = zone->zone_start_pfn;
  167. zone_end_pfn = zone->zone_start_pfn +
  168. zone->spanned_pages;
  169. } else {
  170. /* Add remaining range to ZONE_MOVABLE */
  171. zone_start_pfn = start_pfn;
  172. zone_end_pfn = start_pfn + size_pages;
  173. }
  174. if (start_pfn < zone_start_pfn || start_pfn >= zone_end_pfn)
  175. continue;
  176. nr_pages = (start_pfn + size_pages > zone_end_pfn) ?
  177. zone_end_pfn - start_pfn : size_pages;
  178. rc = __add_pages(nid, zone, start_pfn, nr_pages);
  179. if (rc)
  180. break;
  181. start_pfn += nr_pages;
  182. size_pages -= nr_pages;
  183. if (!size_pages)
  184. break;
  185. }
  186. if (rc)
  187. vmem_remove_mapping(start, size);
  188. return rc;
  189. }
  190. unsigned long memory_block_size_bytes(void)
  191. {
  192. /*
  193. * Make sure the memory block size is always greater
  194. * or equal than the memory increment size.
  195. */
  196. return max_t(unsigned long, MIN_MEMORY_BLOCK_SIZE, sclp_get_rzm());
  197. }
  198. #ifdef CONFIG_MEMORY_HOTREMOVE
  199. int arch_remove_memory(u64 start, u64 size)
  200. {
  201. /*
  202. * There is no hardware or firmware interface which could trigger a
  203. * hot memory remove on s390. So there is nothing that needs to be
  204. * implemented.
  205. */
  206. return -EBUSY;
  207. }
  208. #endif
  209. #endif /* CONFIG_MEMORY_HOTPLUG */