init.c 19 KB

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