init.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * arch/s390/mm/init.c
  3. *
  4. * S390 version
  5. * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
  6. * Author(s): Hartmut Penner (hp@de.ibm.com)
  7. *
  8. * Derived from "arch/i386/mm/init.c"
  9. * Copyright (C) 1995 Linus Torvalds
  10. */
  11. #include <linux/signal.h>
  12. #include <linux/sched.h>
  13. #include <linux/kernel.h>
  14. #include <linux/errno.h>
  15. #include <linux/string.h>
  16. #include <linux/types.h>
  17. #include <linux/ptrace.h>
  18. #include <linux/mman.h>
  19. #include <linux/mm.h>
  20. #include <linux/swap.h>
  21. #include <linux/smp.h>
  22. #include <linux/init.h>
  23. #include <linux/pagemap.h>
  24. #include <linux/bootmem.h>
  25. #include <linux/pfn.h>
  26. #include <linux/poison.h>
  27. #include <linux/initrd.h>
  28. #include <linux/gfp.h>
  29. #include <asm/processor.h>
  30. #include <asm/system.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. pgd_t swapper_pg_dir[PTRS_PER_PGD] __attribute__((__aligned__(PAGE_SIZE)));
  40. unsigned long empty_zero_page, zero_page_mask;
  41. EXPORT_SYMBOL(empty_zero_page);
  42. static unsigned long setup_zero_pages(void)
  43. {
  44. struct cpuid cpu_id;
  45. unsigned int order;
  46. unsigned long size;
  47. struct page *page;
  48. int i;
  49. get_cpu_id(&cpu_id);
  50. switch (cpu_id.machine) {
  51. case 0x9672: /* g5 */
  52. case 0x2064: /* z900 */
  53. case 0x2066: /* z900 */
  54. case 0x2084: /* z990 */
  55. case 0x2086: /* z990 */
  56. case 0x2094: /* z9-109 */
  57. case 0x2096: /* z9-109 */
  58. order = 0;
  59. break;
  60. case 0x2097: /* z10 */
  61. case 0x2098: /* z10 */
  62. default:
  63. order = 2;
  64. break;
  65. }
  66. empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, order);
  67. if (!empty_zero_page)
  68. panic("Out of memory in setup_zero_pages");
  69. page = virt_to_page((void *) empty_zero_page);
  70. split_page(page, order);
  71. for (i = 1 << order; i > 0; i--) {
  72. SetPageReserved(page);
  73. page++;
  74. }
  75. size = PAGE_SIZE << order;
  76. zero_page_mask = (size - 1) & PAGE_MASK;
  77. return 1UL << order;
  78. }
  79. /*
  80. * paging_init() sets up the page tables
  81. */
  82. void __init paging_init(void)
  83. {
  84. unsigned long max_zone_pfns[MAX_NR_ZONES];
  85. unsigned long pgd_type;
  86. init_mm.pgd = swapper_pg_dir;
  87. S390_lowcore.kernel_asce = __pa(init_mm.pgd) & PAGE_MASK;
  88. #ifdef CONFIG_64BIT
  89. /* A three level page table (4TB) is enough for the kernel space. */
  90. S390_lowcore.kernel_asce |= _ASCE_TYPE_REGION3 | _ASCE_TABLE_LENGTH;
  91. pgd_type = _REGION3_ENTRY_EMPTY;
  92. #else
  93. S390_lowcore.kernel_asce |= _ASCE_TABLE_LENGTH;
  94. pgd_type = _SEGMENT_ENTRY_EMPTY;
  95. #endif
  96. clear_table((unsigned long *) init_mm.pgd, pgd_type,
  97. sizeof(unsigned long)*2048);
  98. vmem_map_init();
  99. /* enable virtual mapping in kernel mode */
  100. __ctl_load(S390_lowcore.kernel_asce, 1, 1);
  101. __ctl_load(S390_lowcore.kernel_asce, 7, 7);
  102. __ctl_load(S390_lowcore.kernel_asce, 13, 13);
  103. arch_local_irq_restore(4UL << (BITS_PER_LONG - 8));
  104. atomic_set(&init_mm.context.attach_count, 1);
  105. sparse_memory_present_with_active_regions(MAX_NUMNODES);
  106. sparse_init();
  107. memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
  108. max_zone_pfns[ZONE_DMA] = PFN_DOWN(MAX_DMA_ADDRESS);
  109. max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
  110. free_area_init_nodes(max_zone_pfns);
  111. fault_init();
  112. }
  113. void __init mem_init(void)
  114. {
  115. unsigned long codesize, reservedpages, datasize, initsize;
  116. max_mapnr = num_physpages = max_low_pfn;
  117. high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
  118. /* Setup guest page hinting */
  119. cmma_init();
  120. /* this will put all low memory onto the freelists */
  121. totalram_pages += free_all_bootmem();
  122. totalram_pages -= setup_zero_pages(); /* Setup zeroed pages. */
  123. reservedpages = 0;
  124. codesize = (unsigned long) &_etext - (unsigned long) &_text;
  125. datasize = (unsigned long) &_edata - (unsigned long) &_etext;
  126. initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
  127. printk("Memory: %luk/%luk available (%ldk kernel code, %ldk reserved, %ldk data, %ldk init)\n",
  128. nr_free_pages() << (PAGE_SHIFT-10),
  129. max_mapnr << (PAGE_SHIFT-10),
  130. codesize >> 10,
  131. reservedpages << (PAGE_SHIFT-10),
  132. datasize >>10,
  133. initsize >> 10);
  134. printk("Write protected kernel read-only data: %#lx - %#lx\n",
  135. (unsigned long)&_stext,
  136. PFN_ALIGN((unsigned long)&_eshared) - 1);
  137. }
  138. #ifdef CONFIG_DEBUG_PAGEALLOC
  139. void kernel_map_pages(struct page *page, int numpages, int enable)
  140. {
  141. pgd_t *pgd;
  142. pud_t *pud;
  143. pmd_t *pmd;
  144. pte_t *pte;
  145. unsigned long address;
  146. int i;
  147. for (i = 0; i < numpages; i++) {
  148. address = page_to_phys(page + i);
  149. pgd = pgd_offset_k(address);
  150. pud = pud_offset(pgd, address);
  151. pmd = pmd_offset(pud, address);
  152. pte = pte_offset_kernel(pmd, address);
  153. if (!enable) {
  154. __ptep_ipte(address, pte);
  155. pte_val(*pte) = _PAGE_TYPE_EMPTY;
  156. continue;
  157. }
  158. *pte = mk_pte_phys(address, __pgprot(_PAGE_TYPE_RW));
  159. /* Flush cpu write queue. */
  160. mb();
  161. }
  162. }
  163. #endif
  164. void free_init_pages(char *what, unsigned long begin, unsigned long end)
  165. {
  166. unsigned long addr = begin;
  167. if (begin >= end)
  168. return;
  169. for (; addr < end; addr += PAGE_SIZE) {
  170. ClearPageReserved(virt_to_page(addr));
  171. init_page_count(virt_to_page(addr));
  172. memset((void *)(addr & PAGE_MASK), POISON_FREE_INITMEM,
  173. PAGE_SIZE);
  174. free_page(addr);
  175. totalram_pages++;
  176. }
  177. printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
  178. }
  179. void free_initmem(void)
  180. {
  181. free_init_pages("unused kernel memory",
  182. (unsigned long)&__init_begin,
  183. (unsigned long)&__init_end);
  184. }
  185. #ifdef CONFIG_BLK_DEV_INITRD
  186. void free_initrd_mem(unsigned long start, unsigned long end)
  187. {
  188. free_init_pages("initrd memory", start, end);
  189. }
  190. #endif
  191. #ifdef CONFIG_MEMORY_HOTPLUG
  192. int arch_add_memory(int nid, u64 start, u64 size)
  193. {
  194. struct pglist_data *pgdat;
  195. struct zone *zone;
  196. int rc;
  197. pgdat = NODE_DATA(nid);
  198. zone = pgdat->node_zones + ZONE_MOVABLE;
  199. rc = vmem_add_mapping(start, size);
  200. if (rc)
  201. return rc;
  202. rc = __add_pages(nid, zone, PFN_DOWN(start), PFN_DOWN(size));
  203. if (rc)
  204. vmem_remove_mapping(start, size);
  205. return rc;
  206. }
  207. #endif /* CONFIG_MEMORY_HOTPLUG */