init.c 18 KB

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