init.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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 <linux/memblock.h>
  30. #include <asm/processor.h>
  31. #include <asm/uaccess.h>
  32. #include <asm/pgtable.h>
  33. #include <asm/pgalloc.h>
  34. #include <asm/dma.h>
  35. #include <asm/lowcore.h>
  36. #include <asm/tlb.h>
  37. #include <asm/tlbflush.h>
  38. #include <asm/sections.h>
  39. #include <asm/ctl_reg.h>
  40. #include <asm/sclp.h>
  41. pgd_t swapper_pg_dir[PTRS_PER_PGD] __attribute__((__aligned__(PAGE_SIZE)));
  42. unsigned long empty_zero_page, zero_page_mask;
  43. EXPORT_SYMBOL(empty_zero_page);
  44. EXPORT_SYMBOL(zero_page_mask);
  45. static void __init setup_zero_pages(void)
  46. {
  47. unsigned int order;
  48. struct page *page;
  49. int i;
  50. /* Latest machines require a mapping granularity of 512KB */
  51. order = 7;
  52. /* Limit number of empty zero pages for small memory sizes */
  53. while (order > 2 && (totalram_pages >> 10) < (1UL << order))
  54. order--;
  55. empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, order);
  56. if (!empty_zero_page)
  57. panic("Out of memory in setup_zero_pages");
  58. page = virt_to_page((void *) empty_zero_page);
  59. split_page(page, order);
  60. for (i = 1 << order; i > 0; i--) {
  61. mark_page_reserved(page);
  62. page++;
  63. }
  64. zero_page_mask = ((PAGE_SIZE << order) - 1) & PAGE_MASK;
  65. }
  66. /*
  67. * paging_init() sets up the page tables
  68. */
  69. void __init paging_init(void)
  70. {
  71. unsigned long max_zone_pfns[MAX_NR_ZONES];
  72. unsigned long pgd_type, asce_bits;
  73. init_mm.pgd = swapper_pg_dir;
  74. if (VMALLOC_END > (1UL << 42)) {
  75. asce_bits = _ASCE_TYPE_REGION2 | _ASCE_TABLE_LENGTH;
  76. pgd_type = _REGION2_ENTRY_EMPTY;
  77. } else {
  78. asce_bits = _ASCE_TYPE_REGION3 | _ASCE_TABLE_LENGTH;
  79. pgd_type = _REGION3_ENTRY_EMPTY;
  80. }
  81. init_mm.context.asce = (__pa(init_mm.pgd) & PAGE_MASK) | asce_bits;
  82. S390_lowcore.kernel_asce = init_mm.context.asce;
  83. clear_table((unsigned long *) init_mm.pgd, pgd_type,
  84. sizeof(unsigned long)*2048);
  85. vmem_map_init();
  86. /* enable virtual mapping in kernel mode */
  87. __ctl_load(S390_lowcore.kernel_asce, 1, 1);
  88. __ctl_load(S390_lowcore.kernel_asce, 7, 7);
  89. __ctl_load(S390_lowcore.kernel_asce, 13, 13);
  90. arch_local_irq_restore(4UL << (BITS_PER_LONG - 8));
  91. sparse_memory_present_with_active_regions(MAX_NUMNODES);
  92. sparse_init();
  93. memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
  94. max_zone_pfns[ZONE_DMA] = PFN_DOWN(MAX_DMA_ADDRESS);
  95. max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
  96. free_area_init_nodes(max_zone_pfns);
  97. }
  98. void __init mem_init(void)
  99. {
  100. if (MACHINE_HAS_TLB_LC)
  101. cpumask_set_cpu(0, &init_mm.context.cpu_attach_mask);
  102. cpumask_set_cpu(0, mm_cpumask(&init_mm));
  103. atomic_set(&init_mm.context.attach_count, 1);
  104. set_max_mapnr(max_low_pfn);
  105. high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
  106. /* Setup guest page hinting */
  107. cmma_init();
  108. /* this will put all low memory onto the freelists */
  109. free_all_bootmem();
  110. setup_zero_pages(); /* Setup zeroed pages. */
  111. mem_init_print_info(NULL);
  112. printk("Write protected kernel read-only data: %#lx - %#lx\n",
  113. (unsigned long)&_stext,
  114. PFN_ALIGN((unsigned long)&_eshared) - 1);
  115. }
  116. void free_initmem(void)
  117. {
  118. free_initmem_default(POISON_FREE_INITMEM);
  119. }
  120. #ifdef CONFIG_BLK_DEV_INITRD
  121. void __init free_initrd_mem(unsigned long start, unsigned long end)
  122. {
  123. free_reserved_area((void *)start, (void *)end, POISON_FREE_INITMEM,
  124. "initrd");
  125. }
  126. #endif
  127. #ifdef CONFIG_MEMORY_HOTPLUG
  128. int arch_add_memory(int nid, u64 start, u64 size, bool for_device)
  129. {
  130. unsigned long normal_end_pfn = PFN_DOWN(memblock_end_of_DRAM());
  131. unsigned long dma_end_pfn = PFN_DOWN(MAX_DMA_ADDRESS);
  132. unsigned long start_pfn = PFN_DOWN(start);
  133. unsigned long size_pages = PFN_DOWN(size);
  134. unsigned long nr_pages;
  135. int rc, zone_enum;
  136. rc = vmem_add_mapping(start, size);
  137. if (rc)
  138. return rc;
  139. while (size_pages > 0) {
  140. if (start_pfn < dma_end_pfn) {
  141. nr_pages = (start_pfn + size_pages > dma_end_pfn) ?
  142. dma_end_pfn - start_pfn : size_pages;
  143. zone_enum = ZONE_DMA;
  144. } else if (start_pfn < normal_end_pfn) {
  145. nr_pages = (start_pfn + size_pages > normal_end_pfn) ?
  146. normal_end_pfn - start_pfn : size_pages;
  147. zone_enum = ZONE_NORMAL;
  148. } else {
  149. nr_pages = size_pages;
  150. zone_enum = ZONE_MOVABLE;
  151. }
  152. rc = __add_pages(nid, NODE_DATA(nid)->node_zones + zone_enum,
  153. start_pfn, size_pages);
  154. if (rc)
  155. break;
  156. start_pfn += nr_pages;
  157. size_pages -= nr_pages;
  158. }
  159. if (rc)
  160. vmem_remove_mapping(start, size);
  161. return rc;
  162. }
  163. unsigned long memory_block_size_bytes(void)
  164. {
  165. /*
  166. * Make sure the memory block size is always greater
  167. * or equal than the memory increment size.
  168. */
  169. return max_t(unsigned long, MIN_MEMORY_BLOCK_SIZE, sclp.rzm);
  170. }
  171. #ifdef CONFIG_MEMORY_HOTREMOVE
  172. int arch_remove_memory(u64 start, u64 size)
  173. {
  174. /*
  175. * There is no hardware or firmware interface which could trigger a
  176. * hot memory remove on s390. So there is nothing that needs to be
  177. * implemented.
  178. */
  179. return -EBUSY;
  180. }
  181. #endif
  182. #endif /* CONFIG_MEMORY_HOTPLUG */