init.c 19 KB

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