| .. | .. |
|---|
| 7 | 7 | * for more details. |
|---|
| 8 | 8 | */ |
|---|
| 9 | 9 | |
|---|
| 10 | | -#include <linux/bootmem.h> |
|---|
| 10 | +#include <linux/dma-map-ops.h> |
|---|
| 11 | +#include <linux/memblock.h> |
|---|
| 11 | 12 | #include <linux/init.h> |
|---|
| 12 | 13 | #include <linux/kernel.h> |
|---|
| 13 | | -#include <linux/memblock.h> |
|---|
| 14 | 14 | #include <linux/mm.h> /* mem_init */ |
|---|
| 15 | 15 | #include <linux/initrd.h> |
|---|
| 16 | 16 | #include <linux/pagemap.h> |
|---|
| .. | .. |
|---|
| 46 | 46 | EXPORT_SYMBOL(memory_size); |
|---|
| 47 | 47 | unsigned long lowmem_size; |
|---|
| 48 | 48 | |
|---|
| 49 | +EXPORT_SYMBOL(min_low_pfn); |
|---|
| 50 | +EXPORT_SYMBOL(max_low_pfn); |
|---|
| 51 | + |
|---|
| 49 | 52 | #ifdef CONFIG_HIGHMEM |
|---|
| 50 | 53 | pte_t *kmap_pte; |
|---|
| 51 | 54 | EXPORT_SYMBOL(kmap_pte); |
|---|
| 52 | | -pgprot_t kmap_prot; |
|---|
| 53 | | -EXPORT_SYMBOL(kmap_prot); |
|---|
| 54 | | - |
|---|
| 55 | | -static inline pte_t *virt_to_kpte(unsigned long vaddr) |
|---|
| 56 | | -{ |
|---|
| 57 | | - return pte_offset_kernel(pmd_offset(pgd_offset_k(vaddr), |
|---|
| 58 | | - vaddr), vaddr); |
|---|
| 59 | | -} |
|---|
| 60 | 55 | |
|---|
| 61 | 56 | static void __init highmem_init(void) |
|---|
| 62 | 57 | { |
|---|
| .. | .. |
|---|
| 65 | 60 | pkmap_page_table = virt_to_kpte(PKMAP_BASE); |
|---|
| 66 | 61 | |
|---|
| 67 | 62 | kmap_pte = virt_to_kpte(__fix_to_virt(FIX_KMAP_BEGIN)); |
|---|
| 68 | | - kmap_prot = PAGE_KERNEL; |
|---|
| 69 | 63 | } |
|---|
| 70 | 64 | |
|---|
| 71 | 65 | static void highmem_setup(void) |
|---|
| .. | .. |
|---|
| 109 | 103 | #endif |
|---|
| 110 | 104 | |
|---|
| 111 | 105 | /* We don't have holes in memory map */ |
|---|
| 112 | | - free_area_init_nodes(zones_size); |
|---|
| 106 | + free_area_init(zones_size); |
|---|
| 113 | 107 | } |
|---|
| 114 | 108 | |
|---|
| 115 | 109 | void __init setup_memory(void) |
|---|
| 116 | 110 | { |
|---|
| 117 | | - struct memblock_region *reg; |
|---|
| 118 | | - |
|---|
| 119 | 111 | #ifndef CONFIG_MMU |
|---|
| 120 | 112 | u32 kernel_align_start, kernel_align_size; |
|---|
| 113 | + phys_addr_t start, end; |
|---|
| 114 | + u64 i; |
|---|
| 121 | 115 | |
|---|
| 122 | 116 | /* Find main memory where is the kernel */ |
|---|
| 123 | | - for_each_memblock(memory, reg) { |
|---|
| 124 | | - memory_start = (u32)reg->base; |
|---|
| 125 | | - lowmem_size = reg->size; |
|---|
| 117 | + for_each_mem_range(i, &start, &end) { |
|---|
| 118 | + memory_start = start; |
|---|
| 119 | + lowmem_size = end - start; |
|---|
| 126 | 120 | if ((memory_start <= (u32)_text) && |
|---|
| 127 | 121 | ((u32)_text <= (memory_start + lowmem_size - 1))) { |
|---|
| 128 | 122 | memory_size = lowmem_size; |
|---|
| .. | .. |
|---|
| 170 | 164 | pr_info("%s: max_low_pfn: %#lx\n", __func__, max_low_pfn); |
|---|
| 171 | 165 | pr_info("%s: max_pfn: %#lx\n", __func__, max_pfn); |
|---|
| 172 | 166 | |
|---|
| 173 | | - /* Add active regions with valid PFNs */ |
|---|
| 174 | | - for_each_memblock(memory, reg) { |
|---|
| 175 | | - unsigned long start_pfn, end_pfn; |
|---|
| 176 | | - |
|---|
| 177 | | - start_pfn = memblock_region_memory_base_pfn(reg); |
|---|
| 178 | | - end_pfn = memblock_region_memory_end_pfn(reg); |
|---|
| 179 | | - memblock_set_node(start_pfn << PAGE_SHIFT, |
|---|
| 180 | | - (end_pfn - start_pfn) << PAGE_SHIFT, |
|---|
| 181 | | - &memblock.memory, 0); |
|---|
| 182 | | - } |
|---|
| 183 | | - |
|---|
| 184 | | - /* XXX need to clip this if using highmem? */ |
|---|
| 185 | | - sparse_memory_present_with_active_regions(0); |
|---|
| 186 | | - |
|---|
| 187 | 167 | paging_init(); |
|---|
| 188 | | -} |
|---|
| 189 | | - |
|---|
| 190 | | -#ifdef CONFIG_BLK_DEV_INITRD |
|---|
| 191 | | -void free_initrd_mem(unsigned long start, unsigned long end) |
|---|
| 192 | | -{ |
|---|
| 193 | | - free_reserved_area((void *)start, (void *)end, -1, "initrd"); |
|---|
| 194 | | -} |
|---|
| 195 | | -#endif |
|---|
| 196 | | - |
|---|
| 197 | | -void free_initmem(void) |
|---|
| 198 | | -{ |
|---|
| 199 | | - free_initmem_default(-1); |
|---|
| 200 | 168 | } |
|---|
| 201 | 169 | |
|---|
| 202 | 170 | void __init mem_init(void) |
|---|
| .. | .. |
|---|
| 204 | 172 | high_memory = (void *)__va(memory_start + lowmem_size - 1); |
|---|
| 205 | 173 | |
|---|
| 206 | 174 | /* this will put all memory onto the freelists */ |
|---|
| 207 | | - free_all_bootmem(); |
|---|
| 175 | + memblock_free_all(); |
|---|
| 208 | 176 | #ifdef CONFIG_HIGHMEM |
|---|
| 209 | 177 | highmem_setup(); |
|---|
| 210 | 178 | #endif |
|---|
| 211 | 179 | |
|---|
| 212 | 180 | mem_init_print_info(NULL); |
|---|
| 213 | | -#ifdef CONFIG_MMU |
|---|
| 214 | | - pr_info("Kernel virtual memory layout:\n"); |
|---|
| 215 | | - pr_info(" * 0x%08lx..0x%08lx : fixmap\n", FIXADDR_START, FIXADDR_TOP); |
|---|
| 216 | | -#ifdef CONFIG_HIGHMEM |
|---|
| 217 | | - pr_info(" * 0x%08lx..0x%08lx : highmem PTEs\n", |
|---|
| 218 | | - PKMAP_BASE, PKMAP_ADDR(LAST_PKMAP)); |
|---|
| 219 | | -#endif /* CONFIG_HIGHMEM */ |
|---|
| 220 | | - pr_info(" * 0x%08lx..0x%08lx : early ioremap\n", |
|---|
| 221 | | - ioremap_bot, ioremap_base); |
|---|
| 222 | | - pr_info(" * 0x%08lx..0x%08lx : vmalloc & ioremap\n", |
|---|
| 223 | | - (unsigned long)VMALLOC_START, VMALLOC_END); |
|---|
| 224 | | -#endif |
|---|
| 225 | 181 | mem_init_done = 1; |
|---|
| 226 | 182 | } |
|---|
| 227 | 183 | |
|---|
| .. | .. |
|---|
| 355 | 311 | /* This will also cause that unflatten device tree will be allocated |
|---|
| 356 | 312 | * inside 768MB limit */ |
|---|
| 357 | 313 | memblock_set_current_limit(memory_start + lowmem_size - 1); |
|---|
| 314 | + |
|---|
| 315 | + parse_early_param(); |
|---|
| 316 | + |
|---|
| 317 | + /* CMA initialization */ |
|---|
| 318 | + dma_contiguous_reserve(memory_start + lowmem_size - 1); |
|---|
| 358 | 319 | } |
|---|
| 359 | 320 | |
|---|
| 360 | 321 | /* This is only called until mem_init is done. */ |
|---|
| .. | .. |
|---|
| 364 | 325 | * Mem start + kernel_tlb -> here is limit |
|---|
| 365 | 326 | * because of mem mapping from head.S |
|---|
| 366 | 327 | */ |
|---|
| 367 | | - return __va(memblock_alloc_base(PAGE_SIZE, PAGE_SIZE, |
|---|
| 368 | | - memory_start + kernel_tlb)); |
|---|
| 328 | + return memblock_alloc_try_nid_raw(PAGE_SIZE, PAGE_SIZE, |
|---|
| 329 | + MEMBLOCK_LOW_LIMIT, memory_start + kernel_tlb, |
|---|
| 330 | + NUMA_NO_NODE); |
|---|
| 369 | 331 | } |
|---|
| 370 | 332 | |
|---|
| 371 | 333 | #endif /* CONFIG_MMU */ |
|---|
| .. | .. |
|---|
| 374 | 336 | { |
|---|
| 375 | 337 | void *p; |
|---|
| 376 | 338 | |
|---|
| 377 | | - if (mem_init_done) |
|---|
| 339 | + if (mem_init_done) { |
|---|
| 378 | 340 | p = kzalloc(size, mask); |
|---|
| 379 | | - else { |
|---|
| 380 | | - p = alloc_bootmem(size); |
|---|
| 381 | | - if (p) |
|---|
| 382 | | - memset(p, 0, size); |
|---|
| 341 | + } else { |
|---|
| 342 | + p = memblock_alloc(size, SMP_CACHE_BYTES); |
|---|
| 343 | + if (!p) |
|---|
| 344 | + panic("%s: Failed to allocate %zu bytes\n", |
|---|
| 345 | + __func__, size); |
|---|
| 383 | 346 | } |
|---|
| 347 | + |
|---|
| 384 | 348 | return p; |
|---|
| 385 | 349 | } |
|---|