init.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. order = 5;
  70. break;
  71. case 0x2964: /* z13 */
  72. default:
  73. order = 7;
  74. break;
  75. }
  76. /* Limit number of empty zero pages for small memory sizes */
  77. while (order > 2 && (totalram_pages >> 10) < (1UL << order))
  78. order--;
  79. empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, order);
  80. if (!empty_zero_page)
  81. panic("Out of memory in setup_zero_pages");
  82. page = virt_to_page((void *) empty_zero_page);
  83. split_page(page, order);
  84. for (i = 1 << order; i > 0; i--) {
  85. mark_page_reserved(page);
  86. page++;
  87. }
  88. zero_page_mask = ((PAGE_SIZE << order) - 1) & PAGE_MASK;
  89. }
  90. /*
  91. * paging_init() sets up the page tables
  92. */
  93. void __init paging_init(void)
  94. {
  95. unsigned long max_zone_pfns[MAX_NR_ZONES];
  96. unsigned long pgd_type, asce_bits;
  97. init_mm.pgd = swapper_pg_dir;
  98. #ifdef CONFIG_64BIT
  99. if (VMALLOC_END > (1UL << 42)) {
  100. asce_bits = _ASCE_TYPE_REGION2 | _ASCE_TABLE_LENGTH;
  101. pgd_type = _REGION2_ENTRY_EMPTY;
  102. } else {
  103. asce_bits = _ASCE_TYPE_REGION3 | _ASCE_TABLE_LENGTH;
  104. pgd_type = _REGION3_ENTRY_EMPTY;
  105. }
  106. #else
  107. asce_bits = _ASCE_TABLE_LENGTH;
  108. pgd_type = _SEGMENT_ENTRY_EMPTY;
  109. #endif
  110. S390_lowcore.kernel_asce = (__pa(init_mm.pgd) & PAGE_MASK) | asce_bits;
  111. clear_table((unsigned long *) init_mm.pgd, pgd_type,
  112. sizeof(unsigned long)*2048);
  113. vmem_map_init();
  114. /* enable virtual mapping in kernel mode */
  115. __ctl_load(S390_lowcore.kernel_asce, 1, 1);
  116. __ctl_load(S390_lowcore.kernel_asce, 7, 7);
  117. __ctl_load(S390_lowcore.kernel_asce, 13, 13);
  118. arch_local_irq_restore(4UL << (BITS_PER_LONG - 8));
  119. sparse_memory_present_with_active_regions(MAX_NUMNODES);
  120. sparse_init();
  121. memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
  122. max_zone_pfns[ZONE_DMA] = PFN_DOWN(MAX_DMA_ADDRESS);
  123. max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
  124. free_area_init_nodes(max_zone_pfns);
  125. }
  126. void __init mem_init(void)
  127. {
  128. if (MACHINE_HAS_TLB_LC)
  129. cpumask_set_cpu(0, &init_mm.context.cpu_attach_mask);
  130. cpumask_set_cpu(0, mm_cpumask(&init_mm));
  131. atomic_set(&init_mm.context.attach_count, 1);
  132. max_mapnr = max_low_pfn;
  133. high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
  134. /* Setup guest page hinting */
  135. cmma_init();
  136. /* this will put all low memory onto the freelists */
  137. free_all_bootmem();
  138. setup_zero_pages(); /* Setup zeroed pages. */
  139. mem_init_print_info(NULL);
  140. printk("Write protected kernel read-only data: %#lx - %#lx\n",
  141. (unsigned long)&_stext,
  142. PFN_ALIGN((unsigned long)&_eshared) - 1);
  143. }
  144. void free_initmem(void)
  145. {
  146. free_initmem_default(POISON_FREE_INITMEM);
  147. }
  148. #ifdef CONFIG_BLK_DEV_INITRD
  149. void __init free_initrd_mem(unsigned long start, unsigned long end)
  150. {
  151. free_reserved_area((void *)start, (void *)end, POISON_FREE_INITMEM,
  152. "initrd");
  153. }
  154. #endif
  155. #ifdef CONFIG_MEMORY_HOTPLUG
  156. int arch_add_memory(int nid, u64 start, u64 size)
  157. {
  158. unsigned long zone_start_pfn, zone_end_pfn, nr_pages;
  159. unsigned long start_pfn = PFN_DOWN(start);
  160. unsigned long size_pages = PFN_DOWN(size);
  161. struct zone *zone;
  162. int rc;
  163. rc = vmem_add_mapping(start, size);
  164. if (rc)
  165. return rc;
  166. for_each_zone(zone) {
  167. if (zone_idx(zone) != ZONE_MOVABLE) {
  168. /* Add range within existing zone limits */
  169. zone_start_pfn = zone->zone_start_pfn;
  170. zone_end_pfn = zone->zone_start_pfn +
  171. zone->spanned_pages;
  172. } else {
  173. /* Add remaining range to ZONE_MOVABLE */
  174. zone_start_pfn = start_pfn;
  175. zone_end_pfn = start_pfn + size_pages;
  176. }
  177. if (start_pfn < zone_start_pfn || start_pfn >= zone_end_pfn)
  178. continue;
  179. nr_pages = (start_pfn + size_pages > zone_end_pfn) ?
  180. zone_end_pfn - start_pfn : size_pages;
  181. rc = __add_pages(nid, zone, start_pfn, nr_pages);
  182. if (rc)
  183. break;
  184. start_pfn += nr_pages;
  185. size_pages -= nr_pages;
  186. if (!size_pages)
  187. break;
  188. }
  189. if (rc)
  190. vmem_remove_mapping(start, size);
  191. return rc;
  192. }
  193. unsigned long memory_block_size_bytes(void)
  194. {
  195. /*
  196. * Make sure the memory block size is always greater
  197. * or equal than the memory increment size.
  198. */
  199. return max_t(unsigned long, MIN_MEMORY_BLOCK_SIZE, sclp_get_rzm());
  200. }
  201. #ifdef CONFIG_MEMORY_HOTREMOVE
  202. int arch_remove_memory(u64 start, u64 size)
  203. {
  204. /*
  205. * There is no hardware or firmware interface which could trigger a
  206. * hot memory remove on s390. So there is nothing that needs to be
  207. * implemented.
  208. */
  209. return -EBUSY;
  210. }
  211. #endif
  212. #endif /* CONFIG_MEMORY_HOTPLUG */