init.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  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/sched/signal.h>
  15. #include <linux/mmzone.h>
  16. #include <linux/module.h>
  17. #include <linux/personality.h>
  18. #include <linux/reboot.h>
  19. #include <linux/slab.h>
  20. #include <linux/swap.h>
  21. #include <linux/proc_fs.h>
  22. #include <linux/bitops.h>
  23. #include <linux/kexec.h>
  24. #include <asm/dma.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/tlb.h>
  33. #include <linux/uaccess.h>
  34. #include <asm/unistd.h>
  35. #include <asm/mca.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(ia64_imva(__init_begin), ia64_imva(__init_end),
  139. -1, "unused kernel");
  140. }
  141. void __init
  142. free_initrd_mem (unsigned long start, unsigned long end)
  143. {
  144. /*
  145. * EFI uses 4KB pages while the kernel can use 4KB or bigger.
  146. * Thus EFI and the kernel may have different page sizes. It is
  147. * therefore possible to have the initrd share the same page as
  148. * the end of the kernel (given current setup).
  149. *
  150. * To avoid freeing/using the wrong page (kernel sized) we:
  151. * - align up the beginning of initrd
  152. * - align down the end of initrd
  153. *
  154. * | |
  155. * |=============| a000
  156. * | |
  157. * | |
  158. * | | 9000
  159. * |/////////////|
  160. * |/////////////|
  161. * |=============| 8000
  162. * |///INITRD////|
  163. * |/////////////|
  164. * |/////////////| 7000
  165. * | |
  166. * |KKKKKKKKKKKKK|
  167. * |=============| 6000
  168. * |KKKKKKKKKKKKK|
  169. * |KKKKKKKKKKKKK|
  170. * K=kernel using 8KB pages
  171. *
  172. * In this example, we must free page 8000 ONLY. So we must align up
  173. * initrd_start and keep initrd_end as is.
  174. */
  175. start = PAGE_ALIGN(start);
  176. end = end & PAGE_MASK;
  177. if (start < end)
  178. printk(KERN_INFO "Freeing initrd memory: %ldkB freed\n", (end - start) >> 10);
  179. for (; start < end; start += PAGE_SIZE) {
  180. if (!virt_addr_valid(start))
  181. continue;
  182. free_reserved_page(virt_to_page(start));
  183. }
  184. }
  185. /*
  186. * This installs a clean page in the kernel's page table.
  187. */
  188. static struct page * __init
  189. put_kernel_page (struct page *page, unsigned long address, pgprot_t pgprot)
  190. {
  191. pgd_t *pgd;
  192. pud_t *pud;
  193. pmd_t *pmd;
  194. pte_t *pte;
  195. pgd = pgd_offset_k(address); /* note: this is NOT pgd_offset()! */
  196. {
  197. pud = pud_alloc(&init_mm, pgd, address);
  198. if (!pud)
  199. goto out;
  200. pmd = pmd_alloc(&init_mm, pud, address);
  201. if (!pmd)
  202. goto out;
  203. pte = pte_alloc_kernel(pmd, address);
  204. if (!pte)
  205. goto out;
  206. if (!pte_none(*pte))
  207. goto out;
  208. set_pte(pte, mk_pte(page, pgprot));
  209. }
  210. out:
  211. /* no need for flush_tlb */
  212. return page;
  213. }
  214. static void __init
  215. setup_gate (void)
  216. {
  217. struct page *page;
  218. /*
  219. * Map the gate page twice: once read-only to export the ELF
  220. * headers etc. and once execute-only page to enable
  221. * privilege-promotion via "epc":
  222. */
  223. page = virt_to_page(ia64_imva(__start_gate_section));
  224. put_kernel_page(page, GATE_ADDR, PAGE_READONLY);
  225. #ifdef HAVE_BUGGY_SEGREL
  226. page = virt_to_page(ia64_imva(__start_gate_section + PAGE_SIZE));
  227. put_kernel_page(page, GATE_ADDR + PAGE_SIZE, PAGE_GATE);
  228. #else
  229. put_kernel_page(page, GATE_ADDR + PERCPU_PAGE_SIZE, PAGE_GATE);
  230. /* Fill in the holes (if any) with read-only zero pages: */
  231. {
  232. unsigned long addr;
  233. for (addr = GATE_ADDR + PAGE_SIZE;
  234. addr < GATE_ADDR + PERCPU_PAGE_SIZE;
  235. addr += PAGE_SIZE)
  236. {
  237. put_kernel_page(ZERO_PAGE(0), addr,
  238. PAGE_READONLY);
  239. put_kernel_page(ZERO_PAGE(0), addr + PERCPU_PAGE_SIZE,
  240. PAGE_READONLY);
  241. }
  242. }
  243. #endif
  244. ia64_patch_gate();
  245. }
  246. static struct vm_area_struct gate_vma;
  247. static int __init gate_vma_init(void)
  248. {
  249. gate_vma.vm_mm = NULL;
  250. gate_vma.vm_start = FIXADDR_USER_START;
  251. gate_vma.vm_end = FIXADDR_USER_END;
  252. gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
  253. gate_vma.vm_page_prot = __P101;
  254. return 0;
  255. }
  256. __initcall(gate_vma_init);
  257. struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
  258. {
  259. return &gate_vma;
  260. }
  261. int in_gate_area_no_mm(unsigned long addr)
  262. {
  263. if ((addr >= FIXADDR_USER_START) && (addr < FIXADDR_USER_END))
  264. return 1;
  265. return 0;
  266. }
  267. int in_gate_area(struct mm_struct *mm, unsigned long addr)
  268. {
  269. return in_gate_area_no_mm(addr);
  270. }
  271. void ia64_mmu_init(void *my_cpu_data)
  272. {
  273. unsigned long pta, impl_va_bits;
  274. extern void tlb_init(void);
  275. #ifdef CONFIG_DISABLE_VHPT
  276. # define VHPT_ENABLE_BIT 0
  277. #else
  278. # define VHPT_ENABLE_BIT 1
  279. #endif
  280. /*
  281. * Check if the virtually mapped linear page table (VMLPT) overlaps with a mapped
  282. * address space. The IA-64 architecture guarantees that at least 50 bits of
  283. * virtual address space are implemented but if we pick a large enough page size
  284. * (e.g., 64KB), the mapped address space is big enough that it will overlap with
  285. * VMLPT. I assume that once we run on machines big enough to warrant 64KB pages,
  286. * IMPL_VA_MSB will be significantly bigger, so this is unlikely to become a
  287. * problem in practice. Alternatively, we could truncate the top of the mapped
  288. * address space to not permit mappings that would overlap with the VMLPT.
  289. * --davidm 00/12/06
  290. */
  291. # define pte_bits 3
  292. # define mapped_space_bits (3*(PAGE_SHIFT - pte_bits) + PAGE_SHIFT)
  293. /*
  294. * The virtual page table has to cover the entire implemented address space within
  295. * a region even though not all of this space may be mappable. The reason for
  296. * this is that the Access bit and Dirty bit fault handlers perform
  297. * non-speculative accesses to the virtual page table, so the address range of the
  298. * virtual page table itself needs to be covered by virtual page table.
  299. */
  300. # define vmlpt_bits (impl_va_bits - PAGE_SHIFT + pte_bits)
  301. # define POW2(n) (1ULL << (n))
  302. impl_va_bits = ffz(~(local_cpu_data->unimpl_va_mask | (7UL << 61)));
  303. if (impl_va_bits < 51 || impl_va_bits > 61)
  304. panic("CPU has bogus IMPL_VA_MSB value of %lu!\n", impl_va_bits - 1);
  305. /*
  306. * mapped_space_bits - PAGE_SHIFT is the total number of ptes we need,
  307. * which must fit into "vmlpt_bits - pte_bits" slots. Second half of
  308. * the test makes sure that our mapped space doesn't overlap the
  309. * unimplemented hole in the middle of the region.
  310. */
  311. if ((mapped_space_bits - PAGE_SHIFT > vmlpt_bits - pte_bits) ||
  312. (mapped_space_bits > impl_va_bits - 1))
  313. panic("Cannot build a big enough virtual-linear page table"
  314. " to cover mapped address space.\n"
  315. " Try using a smaller page size.\n");
  316. /* place the VMLPT at the end of each page-table mapped region: */
  317. pta = POW2(61) - POW2(vmlpt_bits);
  318. /*
  319. * Set the (virtually mapped linear) page table address. Bit
  320. * 8 selects between the short and long format, bits 2-7 the
  321. * size of the table, and bit 0 whether the VHPT walker is
  322. * enabled.
  323. */
  324. ia64_set_pta(pta | (0 << 8) | (vmlpt_bits << 2) | VHPT_ENABLE_BIT);
  325. ia64_tlb_init();
  326. #ifdef CONFIG_HUGETLB_PAGE
  327. ia64_set_rr(HPAGE_REGION_BASE, HPAGE_SHIFT << 2);
  328. ia64_srlz_d();
  329. #endif
  330. }
  331. #ifdef CONFIG_VIRTUAL_MEM_MAP
  332. int vmemmap_find_next_valid_pfn(int node, int i)
  333. {
  334. unsigned long end_address, hole_next_pfn;
  335. unsigned long stop_address;
  336. pg_data_t *pgdat = NODE_DATA(node);
  337. end_address = (unsigned long) &vmem_map[pgdat->node_start_pfn + i];
  338. end_address = PAGE_ALIGN(end_address);
  339. stop_address = (unsigned long) &vmem_map[pgdat_end_pfn(pgdat)];
  340. do {
  341. pgd_t *pgd;
  342. pud_t *pud;
  343. pmd_t *pmd;
  344. pte_t *pte;
  345. pgd = pgd_offset_k(end_address);
  346. if (pgd_none(*pgd)) {
  347. end_address += PGDIR_SIZE;
  348. continue;
  349. }
  350. pud = pud_offset(pgd, end_address);
  351. if (pud_none(*pud)) {
  352. end_address += PUD_SIZE;
  353. continue;
  354. }
  355. pmd = pmd_offset(pud, end_address);
  356. if (pmd_none(*pmd)) {
  357. end_address += PMD_SIZE;
  358. continue;
  359. }
  360. pte = pte_offset_kernel(pmd, end_address);
  361. retry_pte:
  362. if (pte_none(*pte)) {
  363. end_address += PAGE_SIZE;
  364. pte++;
  365. if ((end_address < stop_address) &&
  366. (end_address != ALIGN(end_address, 1UL << PMD_SHIFT)))
  367. goto retry_pte;
  368. continue;
  369. }
  370. /* Found next valid vmem_map page */
  371. break;
  372. } while (end_address < stop_address);
  373. end_address = min(end_address, stop_address);
  374. end_address = end_address - (unsigned long) vmem_map + sizeof(struct page) - 1;
  375. hole_next_pfn = end_address / sizeof(struct page);
  376. return hole_next_pfn - pgdat->node_start_pfn;
  377. }
  378. int __init create_mem_map_page_table(u64 start, u64 end, void *arg)
  379. {
  380. unsigned long address, start_page, end_page;
  381. struct page *map_start, *map_end;
  382. int node;
  383. pgd_t *pgd;
  384. pud_t *pud;
  385. pmd_t *pmd;
  386. pte_t *pte;
  387. map_start = vmem_map + (__pa(start) >> PAGE_SHIFT);
  388. map_end = vmem_map + (__pa(end) >> PAGE_SHIFT);
  389. start_page = (unsigned long) map_start & PAGE_MASK;
  390. end_page = PAGE_ALIGN((unsigned long) map_end);
  391. node = paddr_to_nid(__pa(start));
  392. for (address = start_page; address < end_page; address += PAGE_SIZE) {
  393. pgd = pgd_offset_k(address);
  394. if (pgd_none(*pgd))
  395. pgd_populate(&init_mm, pgd, alloc_bootmem_pages_node(NODE_DATA(node), PAGE_SIZE));
  396. pud = pud_offset(pgd, address);
  397. if (pud_none(*pud))
  398. pud_populate(&init_mm, pud, alloc_bootmem_pages_node(NODE_DATA(node), PAGE_SIZE));
  399. pmd = pmd_offset(pud, address);
  400. if (pmd_none(*pmd))
  401. pmd_populate_kernel(&init_mm, pmd, alloc_bootmem_pages_node(NODE_DATA(node), PAGE_SIZE));
  402. pte = pte_offset_kernel(pmd, address);
  403. if (pte_none(*pte))
  404. set_pte(pte, pfn_pte(__pa(alloc_bootmem_pages_node(NODE_DATA(node), PAGE_SIZE)) >> PAGE_SHIFT,
  405. PAGE_KERNEL));
  406. }
  407. return 0;
  408. }
  409. struct memmap_init_callback_data {
  410. struct page *start;
  411. struct page *end;
  412. int nid;
  413. unsigned long zone;
  414. };
  415. static int __meminit
  416. virtual_memmap_init(u64 start, u64 end, void *arg)
  417. {
  418. struct memmap_init_callback_data *args;
  419. struct page *map_start, *map_end;
  420. args = (struct memmap_init_callback_data *) arg;
  421. map_start = vmem_map + (__pa(start) >> PAGE_SHIFT);
  422. map_end = vmem_map + (__pa(end) >> PAGE_SHIFT);
  423. if (map_start < args->start)
  424. map_start = args->start;
  425. if (map_end > args->end)
  426. map_end = args->end;
  427. /*
  428. * We have to initialize "out of bounds" struct page elements that fit completely
  429. * on the same pages that were allocated for the "in bounds" elements because they
  430. * may be referenced later (and found to be "reserved").
  431. */
  432. map_start -= ((unsigned long) map_start & (PAGE_SIZE - 1)) / sizeof(struct page);
  433. map_end += ((PAGE_ALIGN((unsigned long) map_end) - (unsigned long) map_end)
  434. / sizeof(struct page));
  435. if (map_start < map_end)
  436. memmap_init_zone((unsigned long)(map_end - map_start),
  437. args->nid, args->zone, page_to_pfn(map_start),
  438. MEMMAP_EARLY);
  439. return 0;
  440. }
  441. void __meminit
  442. memmap_init (unsigned long size, int nid, unsigned long zone,
  443. unsigned long start_pfn)
  444. {
  445. if (!vmem_map)
  446. memmap_init_zone(size, nid, zone, start_pfn, MEMMAP_EARLY);
  447. else {
  448. struct page *start;
  449. struct memmap_init_callback_data args;
  450. start = pfn_to_page(start_pfn);
  451. args.start = start;
  452. args.end = start + size;
  453. args.nid = nid;
  454. args.zone = zone;
  455. efi_memmap_walk(virtual_memmap_init, &args);
  456. }
  457. }
  458. int
  459. ia64_pfn_valid (unsigned long pfn)
  460. {
  461. char byte;
  462. struct page *pg = pfn_to_page(pfn);
  463. return (__get_user(byte, (char __user *) pg) == 0)
  464. && ((((u64)pg & PAGE_MASK) == (((u64)(pg + 1) - 1) & PAGE_MASK))
  465. || (__get_user(byte, (char __user *) (pg + 1) - 1) == 0));
  466. }
  467. EXPORT_SYMBOL(ia64_pfn_valid);
  468. int __init find_largest_hole(u64 start, u64 end, void *arg)
  469. {
  470. u64 *max_gap = arg;
  471. static u64 last_end = PAGE_OFFSET;
  472. /* NOTE: this algorithm assumes efi memmap table is ordered */
  473. if (*max_gap < (start - last_end))
  474. *max_gap = start - last_end;
  475. last_end = end;
  476. return 0;
  477. }
  478. #endif /* CONFIG_VIRTUAL_MEM_MAP */
  479. int __init register_active_ranges(u64 start, u64 len, int nid)
  480. {
  481. u64 end = start + len;
  482. #ifdef CONFIG_KEXEC
  483. if (start > crashk_res.start && start < crashk_res.end)
  484. start = crashk_res.end;
  485. if (end > crashk_res.start && end < crashk_res.end)
  486. end = crashk_res.start;
  487. #endif
  488. if (start < end)
  489. memblock_add_node(__pa(start), end - start, nid);
  490. return 0;
  491. }
  492. int
  493. find_max_min_low_pfn (u64 start, u64 end, void *arg)
  494. {
  495. unsigned long pfn_start, pfn_end;
  496. #ifdef CONFIG_FLATMEM
  497. pfn_start = (PAGE_ALIGN(__pa(start))) >> PAGE_SHIFT;
  498. pfn_end = (PAGE_ALIGN(__pa(end - 1))) >> PAGE_SHIFT;
  499. #else
  500. pfn_start = GRANULEROUNDDOWN(__pa(start)) >> PAGE_SHIFT;
  501. pfn_end = GRANULEROUNDUP(__pa(end - 1)) >> PAGE_SHIFT;
  502. #endif
  503. min_low_pfn = min(min_low_pfn, pfn_start);
  504. max_low_pfn = max(max_low_pfn, pfn_end);
  505. return 0;
  506. }
  507. /*
  508. * Boot command-line option "nolwsys" can be used to disable the use of any light-weight
  509. * system call handler. When this option is in effect, all fsyscalls will end up bubbling
  510. * down into the kernel and calling the normal (heavy-weight) syscall handler. This is
  511. * useful for performance testing, but conceivably could also come in handy for debugging
  512. * purposes.
  513. */
  514. static int nolwsys __initdata;
  515. static int __init
  516. nolwsys_setup (char *s)
  517. {
  518. nolwsys = 1;
  519. return 1;
  520. }
  521. __setup("nolwsys", nolwsys_setup);
  522. void __init
  523. mem_init (void)
  524. {
  525. int i;
  526. BUG_ON(PTRS_PER_PGD * sizeof(pgd_t) != PAGE_SIZE);
  527. BUG_ON(PTRS_PER_PMD * sizeof(pmd_t) != PAGE_SIZE);
  528. BUG_ON(PTRS_PER_PTE * sizeof(pte_t) != PAGE_SIZE);
  529. #ifdef CONFIG_PCI
  530. /*
  531. * This needs to be called _after_ the command line has been parsed but _before_
  532. * any drivers that may need the PCI DMA interface are initialized or bootmem has
  533. * been freed.
  534. */
  535. platform_dma_init();
  536. #endif
  537. #ifdef CONFIG_FLATMEM
  538. BUG_ON(!mem_map);
  539. #endif
  540. set_max_mapnr(max_low_pfn);
  541. high_memory = __va(max_low_pfn * PAGE_SIZE);
  542. free_all_bootmem();
  543. mem_init_print_info(NULL);
  544. /*
  545. * For fsyscall entrpoints with no light-weight handler, use the ordinary
  546. * (heavy-weight) handler, but mark it by setting bit 0, so the fsyscall entry
  547. * code can tell them apart.
  548. */
  549. for (i = 0; i < NR_syscalls; ++i) {
  550. extern unsigned long fsyscall_table[NR_syscalls];
  551. extern unsigned long sys_call_table[NR_syscalls];
  552. if (!fsyscall_table[i] || nolwsys)
  553. fsyscall_table[i] = sys_call_table[i] | 1;
  554. }
  555. setup_gate();
  556. }
  557. #ifdef CONFIG_MEMORY_HOTPLUG
  558. int arch_add_memory(int nid, u64 start, u64 size, bool for_device)
  559. {
  560. pg_data_t *pgdat;
  561. struct zone *zone;
  562. unsigned long start_pfn = start >> PAGE_SHIFT;
  563. unsigned long nr_pages = size >> PAGE_SHIFT;
  564. int ret;
  565. pgdat = NODE_DATA(nid);
  566. zone = pgdat->node_zones +
  567. zone_for_memory(nid, start, size, ZONE_NORMAL, for_device);
  568. ret = __add_pages(nid, zone, start_pfn, nr_pages);
  569. if (ret)
  570. printk("%s: Problem encountered in __add_pages() as ret=%d\n",
  571. __func__, ret);
  572. return ret;
  573. }
  574. #ifdef CONFIG_MEMORY_HOTREMOVE
  575. int arch_remove_memory(u64 start, u64 size)
  576. {
  577. unsigned long start_pfn = start >> PAGE_SHIFT;
  578. unsigned long nr_pages = size >> PAGE_SHIFT;
  579. struct zone *zone;
  580. int ret;
  581. zone = page_zone(pfn_to_page(start_pfn));
  582. ret = __remove_pages(zone, start_pfn, nr_pages);
  583. if (ret)
  584. pr_warn("%s: Problem encountered in __remove_pages() as"
  585. " ret=%d\n", __func__, ret);
  586. return ret;
  587. }
  588. #endif
  589. #endif