init.c 19 KB

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