20 #include <linux/export.h>
21 #include <linux/sched.h>
22 #include <linux/kernel.h>
23 #include <linux/errno.h>
24 #include <linux/string.h>
26 #include <linux/types.h>
28 #include <linux/stddef.h>
37 #include <linux/slab.h>
39 #include <asm/pgalloc.h>
42 #include <asm/mmu_context.h>
43 #include <asm/pgtable.h>
46 #include <asm/machdep.h>
47 #include <asm/btext.h>
49 #include <asm/sections.h>
50 #include <asm/sparsemem.h>
52 #include <asm/fixmap.h>
53 #include <asm/swiotlb.h>
58 #ifndef CPU_FTR_COHERENT_ICACHE
59 #define CPU_FTR_COHERENT_ICACHE 0
60 #define CPU_FTR_NOEXECUTE 0
74 static inline pte_t *virt_to_kpte(
unsigned long vaddr)
77 vaddr), vaddr), vaddr);
87 struct memblock_region *
reg;
89 for_each_memblock(
memory, reg)
90 if (paddr >= reg->base && paddr < (reg->base + reg->size))
99 if (
ppc_md.phys_mem_access_prot)
100 return ppc_md.phys_mem_access_prot(file, pfn, size, vma_prot);
109 #ifdef CONFIG_MEMORY_HOTPLUG
112 int memory_add_physaddr_to_nid(
u64 start)
114 return hot_add_scn_to_nid(start);
122 unsigned long start_pfn = start >>
PAGE_SHIFT;
128 if (create_section_mapping(start, start + size))
134 return __add_pages(nid, zone, start_pfn, nr_pages);
146 void *
arg,
int (*
func)(
unsigned long,
unsigned long,
void *))
148 struct memblock_region *
reg;
149 unsigned long end_pfn = start_pfn + nr_pages;
150 unsigned long tstart, tend;
153 for_each_memblock(
memory, reg) {
154 tstart =
max(start_pfn, memblock_region_memory_base_pfn(reg));
155 tend =
min(end_pfn, memblock_region_memory_end_pfn(reg));
171 #ifndef CONFIG_NEED_MULTIPLE_NODES
174 unsigned long start, bootmap_pages;
175 unsigned long total_pages;
176 struct memblock_region *
reg;
181 #ifdef CONFIG_HIGHMEM
199 for_each_memblock(
memory, reg) {
200 unsigned long start_pfn, end_pfn;
201 start_pfn = memblock_region_memory_base_pfn(reg);
202 end_pfn = memblock_region_memory_end_pfn(reg);
209 #ifdef CONFIG_HIGHMEM
214 unsigned long top = reg->base + reg->size - 1;
223 free_bootmem_with_active_regions(0,
max_pfn);
230 sparse_memory_present_with_active_regions(0);
236 static int __init mark_nonram_nosave(
void)
240 for_each_memblock(
memory, reg) {
242 memblock_region_memory_end_pfn(prev) < memblock_region_memory_base_pfn(reg))
243 register_nosave_region(memblock_region_memory_end_pfn(prev),
244 memblock_region_memory_base_pfn(reg));
257 unsigned long max_zone_pfns[MAX_NR_ZONES];
267 #ifdef CONFIG_HIGHMEM
276 (
unsigned long long)top_of_ram, total_ram);
278 (
long int)((top_of_ram - total_ram) >> 20));
279 memset(max_zone_pfns, 0,
sizeof(max_zone_pfns));
280 #ifdef CONFIG_HIGHMEM
282 max_zone_pfns[ZONE_HIGHMEM] = top_of_ram >>
PAGE_SHIFT;
284 max_zone_pfns[ZONE_DMA] = top_of_ram >>
PAGE_SHIFT;
286 free_area_init_nodes(max_zone_pfns);
288 mark_nonram_nosave();
294 #ifdef CONFIG_NEED_MULTIPLE_NODES
300 unsigned long reservedpages = 0, codesize, initsize, datasize, bsssize;
302 #ifdef CONFIG_SWIOTLB
309 #ifdef CONFIG_NEED_MULTIPLE_NODES
312 printk(
"freeing bootmem node %d\n", nid);
326 if (PageReserved(page))
336 #ifdef CONFIG_HIGHMEM
338 unsigned long pfn, highmem_mapnr;
341 for (pfn = highmem_mapnr; pfn <
max_mapnr; ++pfn) {
346 ClearPageReserved(page);
347 init_page_count(page);
358 #if defined(CONFIG_PPC_FSL_BOOK3E) && !defined(CONFIG_SMP)
368 "%luk reserved, %luk data, %luk bss, %luk init)\n",
369 nr_free_pages() << (PAGE_SHIFT-10),
372 reservedpages << (PAGE_SHIFT-10),
378 pr_info(
"Kernel virtual memory layout:\n");
380 #ifdef CONFIG_HIGHMEM
381 pr_info(
" * 0x%08lx..0x%08lx : highmem PTEs\n",
384 #ifdef CONFIG_NOT_COHERENT_CACHE
385 pr_info(
" * 0x%08lx..0x%08lx : consistent mem\n",
388 pr_info(
" * 0x%08lx..0x%08lx : early ioremap\n",
390 pr_info(
" * 0x%08lx..0x%08lx : vmalloc & ioremap\n",
411 pr_info(
"Freeing unused kernel memory: %luk freed\n",
416 #ifdef CONFIG_BLK_DEV_INITRD
424 pr_info(
"Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
452 #ifdef CONFIG_HUGETLB_PAGE
453 if (PageCompound(page)) {
461 __flush_dcache_icache(start);
464 #elif defined(CONFIG_8xx) || defined(CONFIG_PPC64)
468 __flush_dcache_icache_phys(
page_to_pfn(page) << PAGE_SHIFT);
502 if (!vma->vm_file && ((vma->vm_flags & VM_EXEC) == 0))
510 unsigned long addr,
int len)
531 #ifdef CONFIG_PPC_STD_MMU
550 else if (
trap != 0x300)
554 #if (defined(CONFIG_PPC_BOOK3E_64) || defined(CONFIG_PPC_FSL_BOOK3E)) \
555 && defined(CONFIG_HUGETLB_PAGE)
556 if (is_vm_hugetlb_page(vma))
565 static int add_system_ram_resources(
void)
567 struct memblock_region *
reg;
569 for_each_memblock(
memory, reg) {
571 unsigned long base = reg->base;
572 unsigned long size = reg->size;
578 res->
name =
"System RAM";
580 res->
end = base + size - 1;
590 #ifdef CONFIG_STRICT_DEVMEM
604 if (page_is_rtas_user_buf(pfn))