init.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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] __section(.bss..swapper_pg_dir);
  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_stosm(0x04);
  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 mark_rodata_ro(void)
  99. {
  100. unsigned long size = __end_ro_after_init - __start_ro_after_init;
  101. set_memory_ro((unsigned long)__start_ro_after_init, size >> PAGE_SHIFT);
  102. pr_info("Write protected read-only-after-init data: %luk\n", size >> 10);
  103. }
  104. void __init mem_init(void)
  105. {
  106. cpumask_set_cpu(0, &init_mm.context.cpu_attach_mask);
  107. cpumask_set_cpu(0, mm_cpumask(&init_mm));
  108. set_max_mapnr(max_low_pfn);
  109. high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
  110. /* Setup guest page hinting */
  111. cmma_init();
  112. /* this will put all low memory onto the freelists */
  113. free_all_bootmem();
  114. setup_zero_pages(); /* Setup zeroed pages. */
  115. mem_init_print_info(NULL);
  116. }
  117. void free_initmem(void)
  118. {
  119. free_initmem_default(POISON_FREE_INITMEM);
  120. }
  121. #ifdef CONFIG_BLK_DEV_INITRD
  122. void __init free_initrd_mem(unsigned long start, unsigned long end)
  123. {
  124. free_reserved_area((void *)start, (void *)end, POISON_FREE_INITMEM,
  125. "initrd");
  126. }
  127. #endif
  128. #ifdef CONFIG_MEMORY_HOTPLUG
  129. int arch_add_memory(int nid, u64 start, u64 size, bool for_device)
  130. {
  131. unsigned long zone_start_pfn, zone_end_pfn, nr_pages;
  132. unsigned long start_pfn = PFN_DOWN(start);
  133. unsigned long size_pages = PFN_DOWN(size);
  134. pg_data_t *pgdat = NODE_DATA(nid);
  135. struct zone *zone;
  136. int rc, i;
  137. rc = vmem_add_mapping(start, size);
  138. if (rc)
  139. return rc;
  140. for (i = 0; i < MAX_NR_ZONES; i++) {
  141. zone = pgdat->node_zones + i;
  142. if (zone_idx(zone) != ZONE_MOVABLE) {
  143. /* Add range within existing zone limits, if possible */
  144. zone_start_pfn = zone->zone_start_pfn;
  145. zone_end_pfn = zone->zone_start_pfn +
  146. zone->spanned_pages;
  147. } else {
  148. /* Add remaining range to ZONE_MOVABLE */
  149. zone_start_pfn = start_pfn;
  150. zone_end_pfn = start_pfn + size_pages;
  151. }
  152. if (start_pfn < zone_start_pfn || start_pfn >= zone_end_pfn)
  153. continue;
  154. nr_pages = (start_pfn + size_pages > zone_end_pfn) ?
  155. zone_end_pfn - start_pfn : size_pages;
  156. rc = __add_pages(nid, zone, start_pfn, nr_pages);
  157. if (rc)
  158. break;
  159. start_pfn += nr_pages;
  160. size_pages -= nr_pages;
  161. if (!size_pages)
  162. break;
  163. }
  164. if (rc)
  165. vmem_remove_mapping(start, size);
  166. return rc;
  167. }
  168. unsigned long memory_block_size_bytes(void)
  169. {
  170. /*
  171. * Make sure the memory block size is always greater
  172. * or equal than the memory increment size.
  173. */
  174. return max_t(unsigned long, MIN_MEMORY_BLOCK_SIZE, sclp.rzm);
  175. }
  176. #ifdef CONFIG_MEMORY_HOTREMOVE
  177. int arch_remove_memory(u64 start, u64 size)
  178. {
  179. /*
  180. * There is no hardware or firmware interface which could trigger a
  181. * hot memory remove on s390. So there is nothing that needs to be
  182. * implemented.
  183. */
  184. return -EBUSY;
  185. }
  186. #endif
  187. #endif /* CONFIG_MEMORY_HOTPLUG */