init.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. /*
  2. * Initialize MMU support.
  3. *
  4. * Copyright (C) 1998-2003 Hewlett-Packard Co
  5. * David Mosberger-Tang <davidm@hpl.hp.com>
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/init.h>
  9. #include <linux/bootmem.h>
  10. #include <linux/efi.h>
  11. #include <linux/elf.h>
  12. #include <linux/memblock.h>
  13. #include <linux/mm.h>
  14. #include <linux/mmzone.h>
  15. #include <linux/module.h>
  16. #include <linux/personality.h>
  17. #include <linux/reboot.h>
  18. #include <linux/slab.h>
  19. #include <linux/swap.h>
  20. #include <linux/proc_fs.h>
  21. #include <linux/bitops.h>
  22. #include <linux/kexec.h>
  23. #include <asm/dma.h>
  24. #include <asm/io.h>
  25. #include <asm/machvec.h>
  26. #include <asm/numa.h>
  27. #include <asm/patch.h>
  28. #include <asm/pgalloc.h>
  29. #include <asm/sal.h>
  30. #include <asm/sections.h>
  31. #include <asm/tlb.h>
  32. #include <asm/uaccess.h>
  33. #include <asm/unistd.h>
  34. #include <asm/mca.h>
  35. extern void ia64_tlb_init (void);
  36. unsigned long MAX_DMA_ADDRESS = PAGE_OFFSET + 0x100000000UL;
  37. #ifdef CONFIG_VIRTUAL_MEM_MAP
  38. unsigned long VMALLOC_END = VMALLOC_END_INIT;
  39. EXPORT_SYMBOL(VMALLOC_END);
  40. struct page *vmem_map;
  41. EXPORT_SYMBOL(vmem_map);
  42. #endif
  43. struct page *zero_page_memmap_ptr; /* map entry for zero page */
  44. EXPORT_SYMBOL(zero_page_memmap_ptr);
  45. void
  46. __ia64_sync_icache_dcache (pte_t pte)
  47. {
  48. unsigned long addr;
  49. struct page *page;
  50. page = pte_page(pte);
  51. addr = (unsigned long) page_address(page);
  52. if (test_bit(PG_arch_1, &page->flags))
  53. return; /* i-cache is already coherent with d-cache */
  54. flush_icache_range(addr, addr + (PAGE_SIZE << compound_order(page)));
  55. set_bit(PG_arch_1, &page->flags); /* mark page as clean */
  56. }
  57. /*
  58. * Since DMA is i-cache coherent, any (complete) pages that were written via
  59. * DMA can be marked as "clean" so that lazy_mmu_prot_update() doesn't have to
  60. * flush them when they get mapped into an executable vm-area.
  61. */
  62. void
  63. dma_mark_clean(void *addr, size_t size)
  64. {
  65. unsigned long pg_addr, end;
  66. pg_addr = PAGE_ALIGN((unsigned long) addr);
  67. end = (unsigned long) addr + size;
  68. while (pg_addr + PAGE_SIZE <= end) {
  69. struct page *page = virt_to_page(pg_addr);
  70. set_bit(PG_arch_1, &page->flags);
  71. pg_addr += PAGE_SIZE;
  72. }
  73. }
  74. inline void
  75. ia64_set_rbs_bot (void)
  76. {
  77. unsigned long stack_size = rlimit_max(RLIMIT_STACK) & -16;
  78. if (stack_size > MAX_USER_STACK_SIZE)
  79. stack_size = MAX_USER_STACK_SIZE;
  80. current->thread.rbs_bot = PAGE_ALIGN(current->mm->start_stack - stack_size);
  81. }
  82. /*
  83. * This performs some platform-dependent address space initialization.
  84. * On IA-64, we want to setup the VM area for the register backing
  85. * store (which grows upwards) and install the gateway page which is
  86. * used for signal trampolines, etc.
  87. */
  88. void
  89. ia64_init_addr_space (void)
  90. {
  91. struct vm_area_struct *vma;
  92. ia64_set_rbs_bot();
  93. /*
  94. * If we're out of memory and kmem_cache_alloc() returns NULL, we simply ignore
  95. * the problem. When the process attempts to write to the register backing store
  96. * for the first time, it will get a SEGFAULT in this case.
  97. */
  98. vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
  99. if (vma) {
  100. INIT_LIST_HEAD(&vma->anon_vma_chain);
  101. vma->vm_mm = current->mm;
  102. vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
  103. vma->vm_end = vma->vm_start + PAGE_SIZE;
  104. vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
  105. vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
  106. down_write(&current->mm->mmap_sem);
  107. if (insert_vm_struct(current->mm, vma)) {
  108. up_write(&current->mm->mmap_sem);
  109. kmem_cache_free(vm_area_cachep, vma);
  110. return;
  111. }
  112. up_write(&current->mm->mmap_sem);
  113. }
  114. /* map NaT-page at address zero to speed up speculative dereferencing of NULL: */
  115. if (!(current->personality & MMAP_PAGE_ZERO)) {
  116. vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
  117. if (vma) {
  118. INIT_LIST_HEAD(&vma->anon_vma_chain);
  119. vma->vm_mm = current->mm;
  120. vma->vm_end = PAGE_SIZE;
  121. vma->vm_page_prot = __pgprot(pgprot_val(PAGE_READONLY) | _PAGE_MA_NAT);
  122. vma->vm_flags = VM_READ | VM_MAYREAD | VM_IO |
  123. VM_DONTEXPAND | VM_DONTDUMP;
  124. down_write(&current->mm->mmap_sem);
  125. if (insert_vm_struct(current->mm, vma)) {
  126. up_write(&current->mm->mmap_sem);
  127. kmem_cache_free(vm_area_cachep, vma);
  128. return;
  129. }
  130. up_write(&current->mm->mmap_sem);
  131. }
  132. }
  133. }
  134. void
  135. free_initmem (void)
  136. {
  137. free_reserved_area(ia64_imva(__init_begin), ia64_imva(__init_end),
  138. -1, "unused kernel");
  139. }
  140. void __init
  141. free_initrd_mem (unsigned long start, unsigned long end)
  142. {
  143. /*
  144. * EFI uses 4KB pages while the kernel can use 4KB or bigger.
  145. * Thus EFI and the kernel may have different page sizes. It is
  146. * therefore possible to have the initrd share the same page as
  147. * the end of the kernel (given current setup).
  148. *
  149. * To avoid freeing/using the wrong page (kernel sized) we:
  150. * - align up the beginning of initrd
  151. * - align down the end of initrd
  152. *
  153. * | |
  154. * |=============| a000
  155. * | |
  156. * | |
  157. * | | 9000
  158. * |/////////////|
  159. * |/////////////|
  160. * |=============| 8000
  161. * |///INITRD////|
  162. * |/////////////|
  163. * |/////////////| 7000
  164. * | |
  165. * |KKKKKKKKKKKKK|
  166. * |=============| 6000
  167. * |KKKKKKKKKKKKK|
  168. * |KKKKKKKKKKKKK|
  169. * K=kernel using 8KB pages
  170. *
  171. * In this example, we must free page 8000 ONLY. So we must align up
  172. * initrd_start and keep initrd_end as is.
  173. */
  174. start = PAGE_ALIGN(start);
  175. end = end & PAGE_MASK;
  176. if (start < end)
  177. printk(KERN_INFO "Freeing initrd memory: %ldkB freed\n", (end - start) >> 10);
  178. for (; start < end; start += PAGE_SIZE) {
  179. if (!virt_addr_valid(start))
  180. continue;
  181. free_reserved_page(virt_to_page(start));
  182. }
  183. }
  184. /*
  185. * This installs a clean page in the kernel's page table.
  186. */
  187. static struct page * __init
  188. put_kernel_page (struct page *page, unsigned long address, pgprot_t pgprot)
  189. {
  190. pgd_t *pgd;
  191. pud_t *pud;
  192. pmd_t *pmd;
  193. pte_t *pte;
  194. pgd = pgd_offset_k(address); /* note: this is NOT pgd_offset()! */
  195. {
  196. pud = pud_alloc(&init_mm, pgd, address);
  197. if (!pud)
  198. goto out;
  199. pmd = pmd_alloc(&init_mm, pud, address);
  200. if (!pmd)
  201. goto out;
  202. pte = pte_alloc_kernel(pmd, address);
  203. if (!pte)
  204. goto out;
  205. if (!pte_none(*pte))
  206. goto out;
  207. set_pte(pte, mk_pte(page, pgprot));
  208. }
  209. out:
  210. /* no need for flush_tlb */
  211. return page;
  212. }
  213. static void __init
  214. setup_gate (void)
  215. {
  216. struct page *page;
  217. /*
  218. * Map the gate page twice: once read-only to export the ELF
  219. * headers etc. and once execute-only page to enable
  220. * privilege-promotion via "epc":
  221. */
  222. page = virt_to_page(ia64_imva(__start_gate_section));
  223. put_kernel_page(page, GATE_ADDR, PAGE_READONLY);
  224. #ifdef HAVE_BUGGY_SEGREL
  225. page = virt_to_page(ia64_imva(__start_gate_section + PAGE_SIZE));
  226. put_kernel_page(page, GATE_ADDR + PAGE_SIZE, PAGE_GATE);
  227. #else
  228. put_kernel_page(page, GATE_ADDR + PERCPU_PAGE_SIZE, PAGE_GATE);
  229. /* Fill in the holes (if any) with read-only zero pages: */
  230. {
  231. unsigned long addr;
  232. for (addr = GATE_ADDR + PAGE_SIZE;
  233. addr < GATE_ADDR + PERCPU_PAGE_SIZE;
  234. addr += PAGE_SIZE)
  235. {
  236. put_kernel_page(ZERO_PAGE(0), addr,
  237. PAGE_READONLY);
  238. put_kernel_page(ZERO_PAGE(0), addr + PERCPU_PAGE_SIZE,
  239. PAGE_READONLY);
  240. }
  241. }
  242. #endif
  243. ia64_patch_gate();
  244. }
  245. static struct vm_area_struct gate_vma;
  246. static int __init gate_vma_init(void)
  247. {
  248. gate_vma.vm_mm = NULL;
  249. gate_vma.vm_start = FIXADDR_USER_START;
  250. gate_vma.vm_end = FIXADDR_USER_END;
  251. gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
  252. gate_vma.vm_page_prot = __P101;
  253. return 0;
  254. }
  255. __initcall(gate_vma_init);
  256. struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
  257. {
  258. return &gate_vma;
  259. }
  260. int in_gate_area_no_mm(unsigned long addr)
  261. {
  262. if ((addr >= FIXADDR_USER_START) && (addr < FIXADDR_USER_END))
  263. return 1;
  264. return 0;
  265. }
  266. int in_gate_area(struct mm_struct *mm, unsigned long addr)
  267. {
  268. return in_gate_area_no_mm(addr);
  269. }
  270. void ia64_mmu_init(void *my_cpu_data)
  271. {
  272. unsigned long pta, impl_va_bits;
  273. extern void tlb_init(void);
  274. #ifdef CONFIG_DISABLE_VHPT
  275. # define VHPT_ENABLE_BIT 0
  276. #else
  277. # define VHPT_ENABLE_BIT 1
  278. #endif
  279. /*
  280. * Check if the virtually mapped linear page table (VMLPT) overlaps with a mapped
  281. * address space. The IA-64 architecture guarantees that at least 50 bits of
  282. * virtual address space are implemented but if we pick a large enough page size
  283. * (e.g., 64KB), the mapped address space is big enough that it will overlap with
  284. * VMLPT. I assume that once we run on machines big enough to warrant 64KB pages,
  285. * IMPL_VA_MSB will be significantly bigger, so this is unlikely to become a
  286. * problem in practice. Alternatively, we could truncate the top of the mapped
  287. * address space to not permit mappings that would overlap with the VMLPT.
  288. * --davidm 00/12/06
  289. */
  290. # define pte_bits 3
  291. # define mapped_space_bits (3*(PAGE_SHIFT - pte_bits) + PAGE_SHIFT)
  292. /*
  293. * The virtual page table has to cover the entire implemented address space within
  294. * a region even though not all of this space may be mappable. The reason for
  295. * this is that the Access bit and Dirty bit fault handlers perform
  296. * non-speculative accesses to the virtual page table, so the address range of the
  297. * virtual page table itself needs to be covered by virtual page table.
  298. */
  299. # define vmlpt_bits (impl_va_bits - PAGE_SHIFT + pte_bits)
  300. # define POW2(n) (1ULL << (n))
  301. impl_va_bits = ffz(~(local_cpu_data->unimpl_va_mask | (7UL << 61)));
  302. if (impl_va_bits < 51 || impl_va_bits > 61)
  303. panic("CPU has bogus IMPL_VA_MSB value of %lu!\n", impl_va_bits - 1);
  304. /*
  305. * mapped_space_bits - PAGE_SHIFT is the total number of ptes we need,
  306. * which must fit into "vmlpt_bits - pte_bits" slots. Second half of
  307. * the test makes sure that our mapped space doesn't overlap the
  308. * unimplemented hole in the middle of the region.
  309. */
  310. if ((mapped_space_bits - PAGE_SHIFT > vmlpt_bits - pte_bits) ||
  311. (mapped_space_bits > impl_va_bits - 1))
  312. panic("Cannot build a big enough virtual-linear page table"
  313. " to cover mapped address space.\n"
  314. " Try using a smaller page size.\n");
  315. /* place the VMLPT at the end of each page-table mapped region: */
  316. pta = POW2(61) - POW2(vmlpt_bits);
  317. /*
  318. * Set the (virtually mapped linear) page table address. Bit
  319. * 8 selects between the short and long format, bits 2-7 the
  320. * size of the table, and bit 0 whether the VHPT walker is
  321. * enabled.
  322. */
  323. ia64_set_pta(pta | (0 << 8) | (vmlpt_bits << 2) | VHPT_ENABLE_BIT);
  324. ia64_tlb_init();
  325. #ifdef CONFIG_HUGETLB_PAGE
  326. ia64_set_rr(HPAGE_REGION_BASE, HPAGE_SHIFT << 2);
  327. ia64_srlz_d();
  328. #endif
  329. }
  330. #ifdef CONFIG_VIRTUAL_MEM_MAP
  331. int vmemmap_find_next_valid_pfn(int node, int i)
  332. {
  333. unsigned long end_address, hole_next_pfn;
  334. unsigned long stop_address;
  335. pg_data_t *pgdat = NODE_DATA(node);
  336. end_address = (unsigned long) &vmem_map[pgdat->node_start_pfn + i];
  337. end_address = PAGE_ALIGN(end_address);
  338. stop_address = (unsigned long) &vmem_map[pgdat_end_pfn(pgdat)];
  339. do {
  340. pgd_t *pgd;
  341. pud_t *pud;
  342. pmd_t *pmd;
  343. pte_t *pte;
  344. pgd = pgd_offset_k(end_address);
  345. if (pgd_none(*pgd)) {
  346. end_address += PGDIR_SIZE;
  347. continue;
  348. }
  349. pud = pud_offset(pgd, end_address);
  350. if (pud_none(*pud)) {
  351. end_address += PUD_SIZE;
  352. continue;
  353. }
  354. pmd = pmd_offset(pud, end_address);
  355. if (pmd_none(*pmd)) {
  356. end_address += PMD_SIZE;
  357. continue;
  358. }
  359. pte = pte_offset_kernel(pmd, end_address);
  360. retry_pte:
  361. if (pte_none(*pte)) {
  362. end_address += PAGE_SIZE;
  363. pte++;
  364. if ((end_address < stop_address) &&
  365. (end_address != ALIGN(end_address, 1UL << PMD_SHIFT)))
  366. goto retry_pte;
  367. continue;
  368. }
  369. /* Found next valid vmem_map page */
  370. break;
  371. } while (end_address < stop_address);
  372. end_address = min(end_address, stop_address);
  373. end_address = end_address - (unsigned long) vmem_map + sizeof(struct page) - 1;
  374. hole_next_pfn = end_address / sizeof(struct page);
  375. return hole_next_pfn - pgdat->node_start_pfn;
  376. }
  377. int __init create_mem_map_page_table(u64 start, u64 end, void *arg)
  378. {
  379. unsigned long address, start_page, end_page;
  380. struct page *map_start, *map_end;
  381. int node;
  382. pgd_t *pgd;
  383. pud_t *pud;
  384. pmd_t *pmd;
  385. pte_t *pte;
  386. map_start = vmem_map + (__pa(start) >> PAGE_SHIFT);
  387. map_end = vmem_map + (__pa(end) >> PAGE_SHIFT);
  388. start_page = (unsigned long) map_start & PAGE_MASK;
  389. end_page = PAGE_ALIGN((unsigned long) map_end);
  390. node = paddr_to_nid(__pa(start));
  391. for (address = start_page; address < end_page; address += PAGE_SIZE) {
  392. pgd = pgd_offset_k(address);
  393. if (pgd_none(*pgd))
  394. pgd_populate(&init_mm, pgd, alloc_bootmem_pages_node(NODE_DATA(node), PAGE_SIZE));
  395. pud = pud_offset(pgd, address);
  396. if (pud_none(*pud))
  397. pud_populate(&init_mm, pud, alloc_bootmem_pages_node(NODE_DATA(node), PAGE_SIZE));
  398. pmd = pmd_offset(pud, address);
  399. if (pmd_none(*pmd))
  400. pmd_populate_kernel(&init_mm, pmd, alloc_bootmem_pages_node(NODE_DATA(node), PAGE_SIZE));
  401. pte = pte_offset_kernel(pmd, address);
  402. if (pte_none(*pte))
  403. set_pte(pte, pfn_pte(__pa(alloc_bootmem_pages_node(NODE_DATA(node), PAGE_SIZE)) >> PAGE_SHIFT,
  404. PAGE_KERNEL));
  405. }
  406. return 0;
  407. }
  408. struct memmap_init_callback_data {
  409. struct page *start;
  410. struct page *end;
  411. int nid;
  412. unsigned long zone;
  413. };
  414. static int __meminit
  415. virtual_memmap_init(u64 start, u64 end, void *arg)
  416. {
  417. struct memmap_init_callback_data *args;
  418. struct page *map_start, *map_end;
  419. args = (struct memmap_init_callback_data *) arg;
  420. map_start = vmem_map + (__pa(start) >> PAGE_SHIFT);
  421. map_end = vmem_map + (__pa(end) >> PAGE_SHIFT);
  422. if (map_start < args->start)
  423. map_start = args->start;
  424. if (map_end > args->end)
  425. map_end = args->end;
  426. /*
  427. * We have to initialize "out of bounds" struct page elements that fit completely
  428. * on the same pages that were allocated for the "in bounds" elements because they
  429. * may be referenced later (and found to be "reserved").
  430. */
  431. map_start -= ((unsigned long) map_start & (PAGE_SIZE - 1)) / sizeof(struct page);
  432. map_end += ((PAGE_ALIGN((unsigned long) map_end) - (unsigned long) map_end)
  433. / sizeof(struct page));
  434. if (map_start < map_end)
  435. memmap_init_zone((unsigned long)(map_end - map_start),
  436. args->nid, args->zone, page_to_pfn(map_start),
  437. MEMMAP_EARLY);
  438. return 0;
  439. }
  440. void __meminit
  441. memmap_init (unsigned long size, int nid, unsigned long zone,
  442. unsigned long start_pfn)
  443. {
  444. if (!vmem_map)
  445. memmap_init_zone(size, nid, zone, start_pfn, MEMMAP_EARLY);
  446. else {
  447. struct page *start;
  448. struct memmap_init_callback_data args;
  449. start = pfn_to_page(start_pfn);
  450. args.start = start;
  451. args.end = start + size;
  452. args.nid = nid;
  453. args.zone = zone;
  454. efi_memmap_walk(virtual_memmap_init, &args);
  455. }
  456. }
  457. int
  458. ia64_pfn_valid (unsigned long pfn)
  459. {
  460. char byte;
  461. struct page *pg = pfn_to_page(pfn);
  462. return (__get_user(byte, (char __user *) pg) == 0)
  463. && ((((u64)pg & PAGE_MASK) == (((u64)(pg + 1) - 1) & PAGE_MASK))
  464. || (__get_user(byte, (char __user *) (pg + 1) - 1) == 0));
  465. }
  466. EXPORT_SYMBOL(ia64_pfn_valid);
  467. int __init find_largest_hole(u64 start, u64 end, void *arg)
  468. {
  469. u64 *max_gap = arg;
  470. static u64 last_end = PAGE_OFFSET;
  471. /* NOTE: this algorithm assumes efi memmap table is ordered */
  472. if (*max_gap < (start - last_end))
  473. *max_gap = start - last_end;
  474. last_end = end;
  475. return 0;
  476. }
  477. #endif /* CONFIG_VIRTUAL_MEM_MAP */
  478. int __init register_active_ranges(u64 start, u64 len, int nid)
  479. {
  480. u64 end = start + len;
  481. #ifdef CONFIG_KEXEC
  482. if (start > crashk_res.start && start < crashk_res.end)
  483. start = crashk_res.end;
  484. if (end > crashk_res.start && end < crashk_res.end)
  485. end = crashk_res.start;
  486. #endif
  487. if (start < end)
  488. memblock_add_node(__pa(start), end - start, nid);
  489. return 0;
  490. }
  491. int
  492. find_max_min_low_pfn (u64 start, u64 end, void *arg)
  493. {
  494. unsigned long pfn_start, pfn_end;
  495. #ifdef CONFIG_FLATMEM
  496. pfn_start = (PAGE_ALIGN(__pa(start))) >> PAGE_SHIFT;
  497. pfn_end = (PAGE_ALIGN(__pa(end - 1))) >> PAGE_SHIFT;
  498. #else
  499. pfn_start = GRANULEROUNDDOWN(__pa(start)) >> PAGE_SHIFT;
  500. pfn_end = GRANULEROUNDUP(__pa(end - 1)) >> PAGE_SHIFT;
  501. #endif
  502. min_low_pfn = min(min_low_pfn, pfn_start);
  503. max_low_pfn = max(max_low_pfn, pfn_end);
  504. return 0;
  505. }
  506. /*
  507. * Boot command-line option "nolwsys" can be used to disable the use of any light-weight
  508. * system call handler. When this option is in effect, all fsyscalls will end up bubbling
  509. * down into the kernel and calling the normal (heavy-weight) syscall handler. This is
  510. * useful for performance testing, but conceivably could also come in handy for debugging
  511. * purposes.
  512. */
  513. static int nolwsys __initdata;
  514. static int __init
  515. nolwsys_setup (char *s)
  516. {
  517. nolwsys = 1;
  518. return 1;
  519. }
  520. __setup("nolwsys", nolwsys_setup);
  521. void __init
  522. mem_init (void)
  523. {
  524. int i;
  525. BUG_ON(PTRS_PER_PGD * sizeof(pgd_t) != PAGE_SIZE);
  526. BUG_ON(PTRS_PER_PMD * sizeof(pmd_t) != PAGE_SIZE);
  527. BUG_ON(PTRS_PER_PTE * sizeof(pte_t) != PAGE_SIZE);
  528. #ifdef CONFIG_PCI
  529. /*
  530. * This needs to be called _after_ the command line has been parsed but _before_
  531. * any drivers that may need the PCI DMA interface are initialized or bootmem has
  532. * been freed.
  533. */
  534. platform_dma_init();
  535. #endif
  536. #ifdef CONFIG_FLATMEM
  537. BUG_ON(!mem_map);
  538. #endif
  539. set_max_mapnr(max_low_pfn);
  540. high_memory = __va(max_low_pfn * PAGE_SIZE);
  541. free_all_bootmem();
  542. mem_init_print_info(NULL);
  543. /*
  544. * For fsyscall entrpoints with no light-weight handler, use the ordinary
  545. * (heavy-weight) handler, but mark it by setting bit 0, so the fsyscall entry
  546. * code can tell them apart.
  547. */
  548. for (i = 0; i < NR_syscalls; ++i) {
  549. extern unsigned long fsyscall_table[NR_syscalls];
  550. extern unsigned long sys_call_table[NR_syscalls];
  551. if (!fsyscall_table[i] || nolwsys)
  552. fsyscall_table[i] = sys_call_table[i] | 1;
  553. }
  554. setup_gate();
  555. }
  556. #ifdef CONFIG_MEMORY_HOTPLUG
  557. int arch_add_memory(int nid, u64 start, u64 size, bool for_device)
  558. {
  559. pg_data_t *pgdat;
  560. struct zone *zone;
  561. unsigned long start_pfn = start >> PAGE_SHIFT;
  562. unsigned long nr_pages = size >> PAGE_SHIFT;
  563. int ret;
  564. pgdat = NODE_DATA(nid);
  565. zone = pgdat->node_zones +
  566. zone_for_memory(nid, start, size, ZONE_NORMAL, for_device);
  567. ret = __add_pages(nid, zone, start_pfn, nr_pages);
  568. if (ret)
  569. printk("%s: Problem encountered in __add_pages() as ret=%d\n",
  570. __func__, ret);
  571. return ret;
  572. }
  573. #ifdef CONFIG_MEMORY_HOTREMOVE
  574. int arch_remove_memory(u64 start, u64 size)
  575. {
  576. unsigned long start_pfn = start >> PAGE_SHIFT;
  577. unsigned long nr_pages = size >> PAGE_SHIFT;
  578. struct zone *zone;
  579. int ret;
  580. zone = page_zone(pfn_to_page(start_pfn));
  581. ret = __remove_pages(zone, start_pfn, nr_pages);
  582. if (ret)
  583. pr_warn("%s: Problem encountered in __remove_pages() as"
  584. " ret=%d\n", __func__, ret);
  585. return ret;
  586. }
  587. #endif
  588. #endif
  589. /**
  590. * show_mem - give short summary of memory stats
  591. *
  592. * Shows a simple page count of reserved and used pages in the system.
  593. * For discontig machines, it does this on a per-pgdat basis.
  594. */
  595. void show_mem(unsigned int filter)
  596. {
  597. int total_reserved = 0;
  598. unsigned long total_present = 0;
  599. pg_data_t *pgdat;
  600. printk(KERN_INFO "Mem-info:\n");
  601. show_free_areas(filter);
  602. printk(KERN_INFO "Node memory in pages:\n");
  603. for_each_online_pgdat(pgdat) {
  604. unsigned long present;
  605. unsigned long flags;
  606. int reserved = 0;
  607. int nid = pgdat->node_id;
  608. int zoneid;
  609. if (skip_free_areas_node(filter, nid))
  610. continue;
  611. pgdat_resize_lock(pgdat, &flags);
  612. for (zoneid = 0; zoneid < MAX_NR_ZONES; zoneid++) {
  613. struct zone *zone = &pgdat->node_zones[zoneid];
  614. if (!populated_zone(zone))
  615. continue;
  616. reserved += zone->present_pages - zone->managed_pages;
  617. }
  618. present = pgdat->node_present_pages;
  619. pgdat_resize_unlock(pgdat, &flags);
  620. total_present += present;
  621. total_reserved += reserved;
  622. printk(KERN_INFO "Node %4d: RAM: %11ld, rsvd: %8d, ",
  623. nid, present, reserved);
  624. }
  625. printk(KERN_INFO "%ld pages of RAM\n", total_present);
  626. printk(KERN_INFO "%d reserved pages\n", total_reserved);
  627. printk(KERN_INFO "Total of %ld pages in page table cache\n",
  628. quicklist_total_size());
  629. printk(KERN_INFO "%ld free buffer pages\n", nr_free_buffer_pages());
  630. }