PageRenderTime 54ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/arch/s390/mm/init.c

https://bitbucket.org/arv/linux
C | 228 lines | 182 code | 24 blank | 22 comment | 16 complexity | c057b8dd2540e4adc929f4ab4fbd1543 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  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/pfn.h>
  24. #include <linux/poison.h>
  25. #include <linux/initrd.h>
  26. #include <linux/export.h>
  27. #include <linux/gfp.h>
  28. #include <asm/processor.h>
  29. #include <asm/uaccess.h>
  30. #include <asm/pgtable.h>
  31. #include <asm/pgalloc.h>
  32. #include <asm/dma.h>
  33. #include <asm/lowcore.h>
  34. #include <asm/tlb.h>
  35. #include <asm/tlbflush.h>
  36. #include <asm/sections.h>
  37. #include <asm/ctl_reg.h>
  38. pgd_t swapper_pg_dir[PTRS_PER_PGD] __attribute__((__aligned__(PAGE_SIZE)));
  39. unsigned long empty_zero_page, zero_page_mask;
  40. EXPORT_SYMBOL(empty_zero_page);
  41. static void __init setup_zero_pages(void)
  42. {
  43. struct cpuid cpu_id;
  44. unsigned int order;
  45. struct page *page;
  46. int i;
  47. get_cpu_id(&cpu_id);
  48. switch (cpu_id.machine) {
  49. case 0x9672: /* g5 */
  50. case 0x2064: /* z900 */
  51. case 0x2066: /* z900 */
  52. case 0x2084: /* z990 */
  53. case 0x2086: /* z990 */
  54. case 0x2094: /* z9-109 */
  55. case 0x2096: /* z9-109 */
  56. order = 0;
  57. break;
  58. case 0x2097: /* z10 */
  59. case 0x2098: /* z10 */
  60. case 0x2817: /* z196 */
  61. case 0x2818: /* z196 */
  62. order = 2;
  63. break;
  64. case 0x2827: /* zEC12 */
  65. default:
  66. order = 5;
  67. break;
  68. }
  69. /* Limit number of empty zero pages for small memory sizes */
  70. if (order > 2 && totalram_pages <= 16384)
  71. order = 2;
  72. empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, order);
  73. if (!empty_zero_page)
  74. panic("Out of memory in setup_zero_pages");
  75. page = virt_to_page((void *) empty_zero_page);
  76. split_page(page, order);
  77. for (i = 1 << order; i > 0; i--) {
  78. mark_page_reserved(page);
  79. page++;
  80. }
  81. zero_page_mask = ((PAGE_SIZE << order) - 1) & PAGE_MASK;
  82. }
  83. /*
  84. * paging_init() sets up the page tables
  85. */
  86. void __init paging_init(void)
  87. {
  88. unsigned long max_zone_pfns[MAX_NR_ZONES];
  89. unsigned long pgd_type, asce_bits;
  90. init_mm.pgd = swapper_pg_dir;
  91. #ifdef CONFIG_64BIT
  92. if (VMALLOC_END > (1UL << 42)) {
  93. asce_bits = _ASCE_TYPE_REGION2 | _ASCE_TABLE_LENGTH;
  94. pgd_type = _REGION2_ENTRY_EMPTY;
  95. } else {
  96. asce_bits = _ASCE_TYPE_REGION3 | _ASCE_TABLE_LENGTH;
  97. pgd_type = _REGION3_ENTRY_EMPTY;
  98. }
  99. #else
  100. asce_bits = _ASCE_TABLE_LENGTH;
  101. pgd_type = _SEGMENT_ENTRY_EMPTY;
  102. #endif
  103. S390_lowcore.kernel_asce = (__pa(init_mm.pgd) & PAGE_MASK) | asce_bits;
  104. clear_table((unsigned long *) init_mm.pgd, pgd_type,
  105. sizeof(unsigned long)*2048);
  106. vmem_map_init();
  107. /* enable virtual mapping in kernel mode */
  108. __ctl_load(S390_lowcore.kernel_asce, 1, 1);
  109. __ctl_load(S390_lowcore.kernel_asce, 7, 7);
  110. __ctl_load(S390_lowcore.kernel_asce, 13, 13);
  111. arch_local_irq_restore(4UL << (BITS_PER_LONG - 8));
  112. atomic_set(&init_mm.context.attach_count, 1);
  113. sparse_memory_present_with_active_regions(MAX_NUMNODES);
  114. sparse_init();
  115. memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
  116. max_zone_pfns[ZONE_DMA] = PFN_DOWN(MAX_DMA_ADDRESS);
  117. max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
  118. free_area_init_nodes(max_zone_pfns);
  119. }
  120. void __init mem_init(void)
  121. {
  122. unsigned long codesize, reservedpages, datasize, initsize;
  123. max_mapnr = num_physpages = max_low_pfn;
  124. high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
  125. /* Setup guest page hinting */
  126. cmma_init();
  127. /* this will put all low memory onto the freelists */
  128. totalram_pages += free_all_bootmem();
  129. setup_zero_pages(); /* Setup zeroed pages. */
  130. reservedpages = 0;
  131. codesize = (unsigned long) &_etext - (unsigned long) &_text;
  132. datasize = (unsigned long) &_edata - (unsigned long) &_etext;
  133. initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
  134. printk("Memory: %luk/%luk available (%ldk kernel code, %ldk reserved, %ldk data, %ldk init)\n",
  135. nr_free_pages() << (PAGE_SHIFT-10),
  136. max_mapnr << (PAGE_SHIFT-10),
  137. codesize >> 10,
  138. reservedpages << (PAGE_SHIFT-10),
  139. datasize >>10,
  140. initsize >> 10);
  141. printk("Write protected kernel read-only data: %#lx - %#lx\n",
  142. (unsigned long)&_stext,
  143. PFN_ALIGN((unsigned long)&_eshared) - 1);
  144. }
  145. void free_initmem(void)
  146. {
  147. free_initmem_default(0);
  148. }
  149. #ifdef CONFIG_BLK_DEV_INITRD
  150. void __init free_initrd_mem(unsigned long start, unsigned long end)
  151. {
  152. free_reserved_area(start, end, POISON_FREE_INITMEM, "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. #ifdef CONFIG_MEMORY_HOTREMOVE
  194. int arch_remove_memory(u64 start, u64 size)
  195. {
  196. /*
  197. * There is no hardware or firmware interface which could trigger a
  198. * hot memory remove on s390. So there is nothing that needs to be
  199. * implemented.
  200. */
  201. return -EBUSY;
  202. }
  203. #endif
  204. #endif /* CONFIG_MEMORY_HOTPLUG */