hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/arch/mips/kernel/setup.c
....@@ -15,7 +15,6 @@
1515 #include <linux/export.h>
1616 #include <linux/screen_info.h>
1717 #include <linux/memblock.h>
18
-#include <linux/bootmem.h>
1918 #include <linux/initrd.h>
2019 #include <linux/root_dev.h>
2120 #include <linux/highmem.h>
....@@ -25,9 +24,11 @@
2524 #include <linux/kexec.h>
2625 #include <linux/sizes.h>
2726 #include <linux/device.h>
28
-#include <linux/dma-contiguous.h>
27
+#include <linux/dma-map-ops.h>
2928 #include <linux/decompress/generic.h>
3029 #include <linux/of_fdt.h>
30
+#include <linux/of_reserved_mem.h>
31
+#include <linux/dmi.h>
3132
3233 #include <asm/addrspace.h>
3334 #include <asm/bootinfo.h>
....@@ -43,7 +44,7 @@
4344 #include <asm/prom.h>
4445
4546 #ifdef CONFIG_MIPS_ELF_APPENDED_DTB
46
-const char __section(.appended_dtb) __appended_dtb[0x100000];
47
+const char __section(".appended_dtb") __appended_dtb[0x100000];
4748 #endif /* CONFIG_MIPS_ELF_APPENDED_DTB */
4849
4950 struct cpuinfo_mips cpu_data[NR_CPUS] __read_mostly;
....@@ -63,13 +64,13 @@
6364
6465 EXPORT_SYMBOL(mips_machtype);
6566
66
-struct boot_mem_map boot_mem_map;
67
-
6867 static char __initdata command_line[COMMAND_LINE_SIZE];
6968 char __initdata arcs_cmdline[COMMAND_LINE_SIZE];
7069
7170 #ifdef CONFIG_CMDLINE_BOOL
72
-static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
71
+static const char builtin_cmdline[] __initconst = CONFIG_CMDLINE;
72
+#else
73
+static const char builtin_cmdline[] __initconst = "";
7374 #endif
7475
7576 /*
....@@ -90,58 +91,6 @@
9091 EXPORT_SYMBOL(ARCH_PFN_OFFSET);
9192 #endif
9293
93
-void __init add_memory_region(phys_addr_t start, phys_addr_t size, long type)
94
-{
95
- int x = boot_mem_map.nr_map;
96
- int i;
97
-
98
- /*
99
- * If the region reaches the top of the physical address space, adjust
100
- * the size slightly so that (start + size) doesn't overflow
101
- */
102
- if (start + size - 1 == PHYS_ADDR_MAX)
103
- --size;
104
-
105
- /* Sanity check */
106
- if (start + size < start) {
107
- pr_warn("Trying to add an invalid memory region, skipped\n");
108
- return;
109
- }
110
-
111
- /*
112
- * Try to merge with existing entry, if any.
113
- */
114
- for (i = 0; i < boot_mem_map.nr_map; i++) {
115
- struct boot_mem_map_entry *entry = boot_mem_map.map + i;
116
- unsigned long top;
117
-
118
- if (entry->type != type)
119
- continue;
120
-
121
- if (start + size < entry->addr)
122
- continue; /* no overlap */
123
-
124
- if (entry->addr + entry->size < start)
125
- continue; /* no overlap */
126
-
127
- top = max(entry->addr + entry->size, start + size);
128
- entry->addr = min(entry->addr, start);
129
- entry->size = top - entry->addr;
130
-
131
- return;
132
- }
133
-
134
- if (boot_mem_map.nr_map == BOOT_MEM_MAP_MAX) {
135
- pr_err("Ooops! Too many entries in the memory map!\n");
136
- return;
137
- }
138
-
139
- boot_mem_map.map[x].addr = start;
140
- boot_mem_map.map[x].size = size;
141
- boot_mem_map.map[x].type = type;
142
- boot_mem_map.nr_map++;
143
-}
144
-
14594 void __init detect_memory_region(phys_addr_t start, phys_addr_t sz_min, phys_addr_t sz_max)
14695 {
14796 void *dm = &detect_magic;
....@@ -158,67 +107,7 @@
158107 ((unsigned long long) sz_min) / SZ_1M,
159108 ((unsigned long long) sz_max) / SZ_1M);
160109
161
- add_memory_region(start, size, BOOT_MEM_RAM);
162
-}
163
-
164
-static bool __init __maybe_unused memory_region_available(phys_addr_t start,
165
- phys_addr_t size)
166
-{
167
- int i;
168
- bool in_ram = false, free = true;
169
-
170
- for (i = 0; i < boot_mem_map.nr_map; i++) {
171
- phys_addr_t start_, end_;
172
-
173
- start_ = boot_mem_map.map[i].addr;
174
- end_ = boot_mem_map.map[i].addr + boot_mem_map.map[i].size;
175
-
176
- switch (boot_mem_map.map[i].type) {
177
- case BOOT_MEM_RAM:
178
- if (start >= start_ && start + size <= end_)
179
- in_ram = true;
180
- break;
181
- case BOOT_MEM_RESERVED:
182
- if ((start >= start_ && start < end_) ||
183
- (start < start_ && start + size >= start_))
184
- free = false;
185
- break;
186
- default:
187
- continue;
188
- }
189
- }
190
-
191
- return in_ram && free;
192
-}
193
-
194
-static void __init print_memory_map(void)
195
-{
196
- int i;
197
- const int field = 2 * sizeof(unsigned long);
198
-
199
- for (i = 0; i < boot_mem_map.nr_map; i++) {
200
- printk(KERN_INFO " memory: %0*Lx @ %0*Lx ",
201
- field, (unsigned long long) boot_mem_map.map[i].size,
202
- field, (unsigned long long) boot_mem_map.map[i].addr);
203
-
204
- switch (boot_mem_map.map[i].type) {
205
- case BOOT_MEM_RAM:
206
- printk(KERN_CONT "(usable)\n");
207
- break;
208
- case BOOT_MEM_INIT_RAM:
209
- printk(KERN_CONT "(usable after init)\n");
210
- break;
211
- case BOOT_MEM_ROM_DATA:
212
- printk(KERN_CONT "(ROM data)\n");
213
- break;
214
- case BOOT_MEM_RESERVED:
215
- printk(KERN_CONT "(reserved)\n");
216
- break;
217
- default:
218
- printk(KERN_CONT "type %lu\n", boot_mem_map.map[i].type);
219
- break;
220
- }
221
- }
110
+ memblock_add(start, size);
222111 }
223112
224113 /*
....@@ -333,7 +222,7 @@
333222
334223 maybe_bswap_initrd();
335224
336
- reserve_bootmem(__pa(initrd_start), size, BOOTMEM_DEFAULT);
225
+ memblock_reserve(__pa(initrd_start), size);
337226 initrd_below_start_ok = 1;
338227
339228 pr_info("Initial ramdisk at: 0x%lx (%lu bytes)\n",
....@@ -360,7 +249,7 @@
360249 * Initialize the bootmem allocator. It also setup initrd related data
361250 * if needed.
362251 */
363
-#if defined(CONFIG_SGI_IP27) || (defined(CONFIG_CPU_LOONGSON3) && defined(CONFIG_NUMA))
252
+#if defined(CONFIG_SGI_IP27) || (defined(CONFIG_CPU_LOONGSON64) && defined(CONFIG_NUMA))
364253
365254 static void __init bootmem_init(void)
366255 {
....@@ -370,21 +259,14 @@
370259
371260 #else /* !CONFIG_SGI_IP27 */
372261
373
-static unsigned long __init bootmap_bytes(unsigned long pages)
374
-{
375
- unsigned long bytes = DIV_ROUND_UP(pages, 8);
376
-
377
- return ALIGN(bytes, sizeof(long));
378
-}
379
-
380262 static void __init bootmem_init(void)
381263 {
382
- unsigned long reserved_end;
383
- unsigned long mapstart = ~0UL;
384
- unsigned long bootmap_size;
385
- phys_addr_t ramstart = PHYS_ADDR_MAX;
386
- bool bootmap_valid = false;
264
+ phys_addr_t ramstart, ramend;
265
+ unsigned long start, end;
387266 int i;
267
+
268
+ ramstart = memblock_start_of_DRAM();
269
+ ramend = memblock_end_of_DRAM();
388270
389271 /*
390272 * Sanity check any INITRD first. We don't take it into account
....@@ -393,32 +275,32 @@
393275 * will reserve the area used for the initrd.
394276 */
395277 init_initrd();
396
- reserved_end = (unsigned long) PFN_UP(__pa_symbol(&_end));
397278
279
+ /* Reserve memory occupied by kernel. */
280
+ memblock_reserve(__pa_symbol(&_text),
281
+ __pa_symbol(&_end) - __pa_symbol(&_text));
282
+
283
+ /* max_low_pfn is not a number of pages but the end pfn of low mem */
284
+
285
+#ifdef CONFIG_MIPS_AUTO_PFN_OFFSET
286
+ ARCH_PFN_OFFSET = PFN_UP(ramstart);
287
+#else
398288 /*
399
- * max_low_pfn is not a number of pages. The number of pages
400
- * of the system is given by 'max_low_pfn - min_low_pfn'.
289
+ * Reserve any memory between the start of RAM and PHYS_OFFSET
401290 */
402
- min_low_pfn = ~0UL;
403
- max_low_pfn = 0;
291
+ if (ramstart > PHYS_OFFSET)
292
+ memblock_reserve(PHYS_OFFSET, ramstart - PHYS_OFFSET);
404293
405
- /*
406
- * Find the highest page frame number we have available
407
- * and the lowest used RAM address
408
- */
409
- for (i = 0; i < boot_mem_map.nr_map; i++) {
410
- unsigned long start, end;
294
+ if (PFN_UP(ramstart) > ARCH_PFN_OFFSET) {
295
+ pr_info("Wasting %lu bytes for tracking %lu unused pages\n",
296
+ (unsigned long)((PFN_UP(ramstart) - ARCH_PFN_OFFSET) * sizeof(struct page)),
297
+ (unsigned long)(PFN_UP(ramstart) - ARCH_PFN_OFFSET));
298
+ }
299
+#endif
411300
412
- if (boot_mem_map.map[i].type != BOOT_MEM_RAM)
413
- continue;
414
-
415
- start = PFN_UP(boot_mem_map.map[i].addr);
416
- end = PFN_DOWN(boot_mem_map.map[i].addr
417
- + boot_mem_map.map[i].size);
418
-
419
- ramstart = min(ramstart, boot_mem_map.map[i].addr);
420
-
421
-#ifndef CONFIG_HIGHMEM
301
+ min_low_pfn = ARCH_PFN_OFFSET;
302
+ max_pfn = PFN_DOWN(ramend);
303
+ for_each_mem_pfn_range(i, MAX_NUMNODES, &start, &end, NULL) {
422304 /*
423305 * Skip highmem here so we get an accurate max_low_pfn if low
424306 * memory stops short of high memory.
....@@ -429,210 +311,22 @@
429311 continue;
430312 if (end > PFN_DOWN(HIGHMEM_START))
431313 end = PFN_DOWN(HIGHMEM_START);
432
-#endif
433
-
434314 if (end > max_low_pfn)
435315 max_low_pfn = end;
436
- if (start < min_low_pfn)
437
- min_low_pfn = start;
438
- if (end <= reserved_end)
439
- continue;
440
-#ifdef CONFIG_BLK_DEV_INITRD
441
- /* Skip zones before initrd and initrd itself */
442
- if (initrd_end && end <= (unsigned long)PFN_UP(__pa(initrd_end)))
443
- continue;
444
-#endif
445
- if (start >= mapstart)
446
- continue;
447
- mapstart = max(reserved_end, start);
448316 }
449317
450318 if (min_low_pfn >= max_low_pfn)
451319 panic("Incorrect memory mapping !!!");
452320
453
-#ifdef CONFIG_MIPS_AUTO_PFN_OFFSET
454
- ARCH_PFN_OFFSET = PFN_UP(ramstart);
455
-#else
456
- /*
457
- * Reserve any memory between the start of RAM and PHYS_OFFSET
458
- */
459
- if (ramstart > PHYS_OFFSET)
460
- add_memory_region(PHYS_OFFSET, ramstart - PHYS_OFFSET,
461
- BOOT_MEM_RESERVED);
462
-
463
- if (min_low_pfn > ARCH_PFN_OFFSET) {
464
- pr_info("Wasting %lu bytes for tracking %lu unused pages\n",
465
- (min_low_pfn - ARCH_PFN_OFFSET) * sizeof(struct page),
466
- min_low_pfn - ARCH_PFN_OFFSET);
467
- } else if (ARCH_PFN_OFFSET - min_low_pfn > 0UL) {
468
- pr_info("%lu free pages won't be used\n",
469
- ARCH_PFN_OFFSET - min_low_pfn);
470
- }
471
- min_low_pfn = ARCH_PFN_OFFSET;
472
-#endif
473
-
474
- /*
475
- * Determine low and high memory ranges
476
- */
477
- max_pfn = max_low_pfn;
478
- if (max_low_pfn > PFN_DOWN(HIGHMEM_START)) {
321
+ if (max_pfn > PFN_DOWN(HIGHMEM_START)) {
479322 #ifdef CONFIG_HIGHMEM
480323 highstart_pfn = PFN_DOWN(HIGHMEM_START);
481
- highend_pfn = max_low_pfn;
482
-#endif
324
+ highend_pfn = max_pfn;
325
+#else
483326 max_low_pfn = PFN_DOWN(HIGHMEM_START);
484
- }
485
-
486
-#ifdef CONFIG_BLK_DEV_INITRD
487
- /*
488
- * mapstart should be after initrd_end
489
- */
490
- if (initrd_end)
491
- mapstart = max(mapstart, (unsigned long)PFN_UP(__pa(initrd_end)));
492
-#endif
493
-
494
- /*
495
- * check that mapstart doesn't overlap with any of
496
- * memory regions that have been reserved through eg. DTB
497
- */
498
- bootmap_size = bootmap_bytes(max_low_pfn - min_low_pfn);
499
-
500
- bootmap_valid = memory_region_available(PFN_PHYS(mapstart),
501
- bootmap_size);
502
- for (i = 0; i < boot_mem_map.nr_map && !bootmap_valid; i++) {
503
- unsigned long mapstart_addr;
504
-
505
- switch (boot_mem_map.map[i].type) {
506
- case BOOT_MEM_RESERVED:
507
- mapstart_addr = PFN_ALIGN(boot_mem_map.map[i].addr +
508
- boot_mem_map.map[i].size);
509
- if (PHYS_PFN(mapstart_addr) < mapstart)
510
- break;
511
-
512
- bootmap_valid = memory_region_available(mapstart_addr,
513
- bootmap_size);
514
- if (bootmap_valid)
515
- mapstart = PHYS_PFN(mapstart_addr);
516
- break;
517
- default:
518
- break;
519
- }
520
- }
521
-
522
- if (!bootmap_valid)
523
- panic("No memory area to place a bootmap bitmap");
524
-
525
- /*
526
- * Initialize the boot-time allocator with low memory only.
527
- */
528
- if (bootmap_size != init_bootmem_node(NODE_DATA(0), mapstart,
529
- min_low_pfn, max_low_pfn))
530
- panic("Unexpected memory size required for bootmap");
531
-
532
- for (i = 0; i < boot_mem_map.nr_map; i++) {
533
- unsigned long start, end;
534
-
535
- start = PFN_UP(boot_mem_map.map[i].addr);
536
- end = PFN_DOWN(boot_mem_map.map[i].addr
537
- + boot_mem_map.map[i].size);
538
-
539
- if (start <= min_low_pfn)
540
- start = min_low_pfn;
541
- if (start >= end)
542
- continue;
543
-
544
-#ifndef CONFIG_HIGHMEM
545
- if (end > max_low_pfn)
546
- end = max_low_pfn;
547
-
548
- /*
549
- * ... finally, is the area going away?
550
- */
551
- if (end <= start)
552
- continue;
553
-#endif
554
-
555
- memblock_add_node(PFN_PHYS(start), PFN_PHYS(end - start), 0);
556
- }
557
-
558
- /*
559
- * Register fully available low RAM pages with the bootmem allocator.
560
- */
561
- for (i = 0; i < boot_mem_map.nr_map; i++) {
562
- unsigned long start, end, size;
563
-
564
- start = PFN_UP(boot_mem_map.map[i].addr);
565
- end = PFN_DOWN(boot_mem_map.map[i].addr
566
- + boot_mem_map.map[i].size);
567
-
568
- /*
569
- * Reserve usable memory.
570
- */
571
- switch (boot_mem_map.map[i].type) {
572
- case BOOT_MEM_RAM:
573
- break;
574
- case BOOT_MEM_INIT_RAM:
575
- memory_present(0, start, end);
576
- continue;
577
- default:
578
- /* Not usable memory */
579
- if (start > min_low_pfn && end < max_low_pfn)
580
- reserve_bootmem(boot_mem_map.map[i].addr,
581
- boot_mem_map.map[i].size,
582
- BOOTMEM_DEFAULT);
583
- continue;
584
- }
585
-
586
- /*
587
- * We are rounding up the start address of usable memory
588
- * and at the end of the usable range downwards.
589
- */
590
- if (start >= max_low_pfn)
591
- continue;
592
- if (start < reserved_end)
593
- start = reserved_end;
594
- if (end > max_low_pfn)
595
- end = max_low_pfn;
596
-
597
- /*
598
- * ... finally, is the area going away?
599
- */
600
- if (end <= start)
601
- continue;
602
- size = end - start;
603
-
604
- /* Register lowmem ranges */
605
- free_bootmem(PFN_PHYS(start), size << PAGE_SHIFT);
606
- memory_present(0, start, end);
607
- }
608
-
609
- /*
610
- * Reserve the bootmap memory.
611
- */
612
- reserve_bootmem(PFN_PHYS(mapstart), bootmap_size, BOOTMEM_DEFAULT);
613
-
614
-#ifdef CONFIG_RELOCATABLE
615
- /*
616
- * The kernel reserves all memory below its _end symbol as bootmem,
617
- * but the kernel may now be at a much higher address. The memory
618
- * between the original and new locations may be returned to the system.
619
- */
620
- if (__pa_symbol(_text) > __pa_symbol(VMLINUX_LOAD_ADDRESS)) {
621
- unsigned long offset;
622
- extern void show_kernel_relocation(const char *level);
623
-
624
- offset = __pa_symbol(_text) - __pa_symbol(VMLINUX_LOAD_ADDRESS);
625
- free_bootmem(__pa_symbol(VMLINUX_LOAD_ADDRESS), offset);
626
-
627
-#if defined(CONFIG_DEBUG_KERNEL) && defined(CONFIG_DEBUG_INFO)
628
- /*
629
- * This information is necessary when debugging the kernel
630
- * But is a security vulnerability otherwise!
631
- */
632
- show_kernel_relocation(KERN_INFO);
327
+ max_pfn = max_low_pfn;
633328 #endif
634329 }
635
-#endif
636330
637331 /*
638332 * Reserve initrd memory if needed.
....@@ -641,29 +335,6 @@
641335 }
642336
643337 #endif /* CONFIG_SGI_IP27 */
644
-
645
-/*
646
- * arch_mem_init - initialize memory management subsystem
647
- *
648
- * o plat_mem_setup() detects the memory configuration and will record detected
649
- * memory areas using add_memory_region.
650
- *
651
- * At this stage the memory configuration of the system is known to the
652
- * kernel but generic memory management system is still entirely uninitialized.
653
- *
654
- * o bootmem_init()
655
- * o sparse_init()
656
- * o paging_init()
657
- * o dma_contiguous_reserve()
658
- *
659
- * At this stage the bootmem allocator is ready to use.
660
- *
661
- * NOTE: historically plat_mem_setup did the entire platform initialization.
662
- * This was rather impractical because it meant plat_mem_setup had to
663
- * get away without any kind of memory allocator. To keep old code from
664
- * breaking plat_setup was just renamed to plat_mem_setup and a second platform
665
- * initialization hook for anything else was introduced.
666
- */
667338
668339 static int usermem __initdata;
669340
....@@ -677,15 +348,16 @@
677348 * size.
678349 */
679350 if (usermem == 0) {
680
- boot_mem_map.nr_map = 0;
681351 usermem = 1;
352
+ memblock_remove(memblock_start_of_DRAM(),
353
+ memblock_end_of_DRAM() - memblock_start_of_DRAM());
682354 }
683355 start = 0;
684356 size = memparse(p, &p);
685357 if (*p == '@')
686358 start = memparse(p + 1, &p);
687359
688
- add_memory_region(start, size, BOOT_MEM_RAM);
360
+ memblock_add(start, size);
689361
690362 return 0;
691363 }
....@@ -711,13 +383,14 @@
711383
712384 if (*p == '@') {
713385 start_at = memparse(p+1, &p);
714
- add_memory_region(start_at, mem_size, BOOT_MEM_RAM);
386
+ memblock_add(start_at, mem_size);
715387 } else if (*p == '#') {
716388 pr_err("\"memmap=nn#ss\" (force ACPI data) invalid on MIPS\n");
717389 return -EINVAL;
718390 } else if (*p == '$') {
719391 start_at = memparse(p+1, &p);
720
- add_memory_region(start_at, mem_size, BOOT_MEM_RESERVED);
392
+ memblock_add(start_at, mem_size);
393
+ memblock_reserve(start_at, mem_size);
721394 } else {
722395 pr_err("\"memmap\" invalid format!\n");
723396 return -EINVAL;
....@@ -732,17 +405,15 @@
732405 early_param("memmap", early_parse_memmap);
733406
734407 #ifdef CONFIG_PROC_VMCORE
735
-unsigned long setup_elfcorehdr, setup_elfcorehdr_size;
408
+static unsigned long setup_elfcorehdr, setup_elfcorehdr_size;
736409 static int __init early_parse_elfcorehdr(char *p)
737410 {
738
- int i;
411
+ phys_addr_t start, end;
412
+ u64 i;
739413
740414 setup_elfcorehdr = memparse(p, &p);
741415
742
- for (i = 0; i < boot_mem_map.nr_map; i++) {
743
- unsigned long start = boot_mem_map.map[i].addr;
744
- unsigned long end = (boot_mem_map.map[i].addr +
745
- boot_mem_map.map[i].size);
416
+ for_each_mem_range(i, &start, &end) {
746417 if (setup_elfcorehdr >= start && setup_elfcorehdr < end) {
747418 /*
748419 * Reserve from the elf core header to the end of
....@@ -762,33 +433,11 @@
762433 early_param("elfcorehdr", early_parse_elfcorehdr);
763434 #endif
764435
765
-static void __init arch_mem_addpart(phys_addr_t mem, phys_addr_t end, int type)
766
-{
767
- phys_addr_t size;
768
- int i;
769
-
770
- size = end - mem;
771
- if (!size)
772
- return;
773
-
774
- /* Make sure it is in the boot_mem_map */
775
- for (i = 0; i < boot_mem_map.nr_map; i++) {
776
- if (mem >= boot_mem_map.map[i].addr &&
777
- mem < (boot_mem_map.map[i].addr +
778
- boot_mem_map.map[i].size))
779
- return;
780
- }
781
- add_memory_region(mem, size, type);
782
-}
783
-
784436 #ifdef CONFIG_KEXEC
785
-static inline unsigned long long get_total_mem(void)
786
-{
787
- unsigned long long total;
788437
789
- total = max_pfn - min_low_pfn;
790
- return total << PAGE_SHIFT;
791
-}
438
+/* 64M alignment for crash kernel regions */
439
+#define CRASH_ALIGN SZ_64M
440
+#define CRASH_ADDR_MAX SZ_512M
792441
793442 static void __init mips_parse_crashkernel(void)
794443 {
....@@ -796,15 +445,28 @@
796445 unsigned long long crash_size, crash_base;
797446 int ret;
798447
799
- total_mem = get_total_mem();
448
+ total_mem = memblock_phys_mem_size();
800449 ret = parse_crashkernel(boot_command_line, total_mem,
801450 &crash_size, &crash_base);
802451 if (ret != 0 || crash_size <= 0)
803452 return;
804453
805
- if (!memory_region_available(crash_base, crash_size)) {
806
- pr_warn("Invalid memory region reserved for crash kernel\n");
807
- return;
454
+ if (crash_base <= 0) {
455
+ crash_base = memblock_find_in_range(CRASH_ALIGN, CRASH_ADDR_MAX,
456
+ crash_size, CRASH_ALIGN);
457
+ if (!crash_base) {
458
+ pr_warn("crashkernel reservation failed - No suitable area found.\n");
459
+ return;
460
+ }
461
+ } else {
462
+ unsigned long long start;
463
+
464
+ start = memblock_find_in_range(crash_base, crash_base + crash_size,
465
+ crash_size, 1);
466
+ if (start != crash_base) {
467
+ pr_warn("Invalid memory region reserved for crash kernel\n");
468
+ return;
469
+ }
808470 }
809471
810472 crashk_res.start = crash_base;
....@@ -821,8 +483,7 @@
821483 ret = request_resource(res, &crashk_res);
822484 if (!ret)
823485 pr_info("Reserving %ldMB of memory at %ldMB for crashkernel\n",
824
- (unsigned long)((crashk_res.end -
825
- crashk_res.start + 1) >> 20),
486
+ (unsigned long)(resource_size(&crashk_res) >> 20),
826487 (unsigned long)(crashk_res.start >> 20));
827488 }
828489 #else /* !defined(CONFIG_KEXEC) */
....@@ -835,102 +496,175 @@
835496 }
836497 #endif /* !defined(CONFIG_KEXEC) */
837498
838
-#define USE_PROM_CMDLINE IS_ENABLED(CONFIG_MIPS_CMDLINE_FROM_BOOTLOADER)
839
-#define USE_DTB_CMDLINE IS_ENABLED(CONFIG_MIPS_CMDLINE_FROM_DTB)
840
-#define EXTEND_WITH_PROM IS_ENABLED(CONFIG_MIPS_CMDLINE_DTB_EXTEND)
841
-#define BUILTIN_EXTEND_WITH_PROM \
842
- IS_ENABLED(CONFIG_MIPS_CMDLINE_BUILTIN_EXTEND)
499
+static void __init check_kernel_sections_mem(void)
500
+{
501
+ phys_addr_t start = __pa_symbol(&_text);
502
+ phys_addr_t size = __pa_symbol(&_end) - start;
843503
504
+ if (!memblock_is_region_memory(start, size)) {
505
+ pr_info("Kernel sections are not in the memory maps\n");
506
+ memblock_add(start, size);
507
+ }
508
+}
509
+
510
+static void __init bootcmdline_append(const char *s, size_t max)
511
+{
512
+ if (!s[0] || !max)
513
+ return;
514
+
515
+ if (boot_command_line[0])
516
+ strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
517
+
518
+ strlcat(boot_command_line, s, max);
519
+}
520
+
521
+#ifdef CONFIG_OF_EARLY_FLATTREE
522
+
523
+static int __init bootcmdline_scan_chosen(unsigned long node, const char *uname,
524
+ int depth, void *data)
525
+{
526
+ bool *dt_bootargs = data;
527
+ const char *p;
528
+ int l;
529
+
530
+ if (depth != 1 || !data ||
531
+ (strcmp(uname, "chosen") != 0 && strcmp(uname, "chosen@0") != 0))
532
+ return 0;
533
+
534
+ p = of_get_flat_dt_prop(node, "bootargs", &l);
535
+ if (p != NULL && l > 0) {
536
+ bootcmdline_append(p, min(l, COMMAND_LINE_SIZE));
537
+ *dt_bootargs = true;
538
+ }
539
+
540
+ return 1;
541
+}
542
+
543
+#endif /* CONFIG_OF_EARLY_FLATTREE */
544
+
545
+static void __init bootcmdline_init(void)
546
+{
547
+ bool dt_bootargs = false;
548
+
549
+ /*
550
+ * If CMDLINE_OVERRIDE is enabled then initializing the command line is
551
+ * trivial - we simply use the built-in command line unconditionally &
552
+ * unmodified.
553
+ */
554
+ if (IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) {
555
+ strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
556
+ return;
557
+ }
558
+
559
+ /*
560
+ * If the user specified a built-in command line &
561
+ * MIPS_CMDLINE_BUILTIN_EXTEND, then the built-in command line is
562
+ * prepended to arguments from the bootloader or DT so we'll copy them
563
+ * to the start of boot_command_line here. Otherwise, empty
564
+ * boot_command_line to undo anything early_init_dt_scan_chosen() did.
565
+ */
566
+ if (IS_ENABLED(CONFIG_MIPS_CMDLINE_BUILTIN_EXTEND))
567
+ strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
568
+ else
569
+ boot_command_line[0] = 0;
570
+
571
+#ifdef CONFIG_OF_EARLY_FLATTREE
572
+ /*
573
+ * If we're configured to take boot arguments from DT, look for those
574
+ * now.
575
+ */
576
+ if (IS_ENABLED(CONFIG_MIPS_CMDLINE_FROM_DTB) ||
577
+ IS_ENABLED(CONFIG_MIPS_CMDLINE_DTB_EXTEND))
578
+ of_scan_flat_dt(bootcmdline_scan_chosen, &dt_bootargs);
579
+#endif
580
+
581
+ /*
582
+ * If we didn't get any arguments from DT (regardless of whether that's
583
+ * because we weren't configured to look for them, or because we looked
584
+ * & found none) then we'll take arguments from the bootloader.
585
+ * plat_mem_setup() should have filled arcs_cmdline with arguments from
586
+ * the bootloader.
587
+ */
588
+ if (IS_ENABLED(CONFIG_MIPS_CMDLINE_DTB_EXTEND) || !dt_bootargs)
589
+ bootcmdline_append(arcs_cmdline, COMMAND_LINE_SIZE);
590
+
591
+ /*
592
+ * If the user specified a built-in command line & we didn't already
593
+ * prepend it, we append it to boot_command_line here.
594
+ */
595
+ if (IS_ENABLED(CONFIG_CMDLINE_BOOL) &&
596
+ !IS_ENABLED(CONFIG_MIPS_CMDLINE_BUILTIN_EXTEND))
597
+ bootcmdline_append(builtin_cmdline, COMMAND_LINE_SIZE);
598
+}
599
+
600
+/*
601
+ * arch_mem_init - initialize memory management subsystem
602
+ *
603
+ * o plat_mem_setup() detects the memory configuration and will record detected
604
+ * memory areas using memblock_add.
605
+ *
606
+ * At this stage the memory configuration of the system is known to the
607
+ * kernel but generic memory management system is still entirely uninitialized.
608
+ *
609
+ * o bootmem_init()
610
+ * o sparse_init()
611
+ * o paging_init()
612
+ * o dma_contiguous_reserve()
613
+ *
614
+ * At this stage the bootmem allocator is ready to use.
615
+ *
616
+ * NOTE: historically plat_mem_setup did the entire platform initialization.
617
+ * This was rather impractical because it meant plat_mem_setup had to
618
+ * get away without any kind of memory allocator. To keep old code from
619
+ * breaking plat_setup was just renamed to plat_mem_setup and a second platform
620
+ * initialization hook for anything else was introduced.
621
+ */
844622 static void __init arch_mem_init(char **cmdline_p)
845623 {
846
- struct memblock_region *reg;
847
- extern void plat_mem_setup(void);
848
-
849
- /*
850
- * Initialize boot_command_line to an innocuous but non-empty string in
851
- * order to prevent early_init_dt_scan_chosen() from copying
852
- * CONFIG_CMDLINE into it without our knowledge. We handle
853
- * CONFIG_CMDLINE ourselves below & don't want to duplicate its
854
- * content because repeating arguments can be problematic.
855
- */
856
- strlcpy(boot_command_line, " ", COMMAND_LINE_SIZE);
857
-
858624 /* call board setup routine */
859625 plat_mem_setup();
626
+ memblock_set_bottom_up(true);
860627
861
- /*
862
- * Make sure all kernel memory is in the maps. The "UP" and
863
- * "DOWN" are opposite for initdata since if it crosses over
864
- * into another memory section you don't want that to be
865
- * freed when the initdata is freed.
866
- */
867
- arch_mem_addpart(PFN_DOWN(__pa_symbol(&_text)) << PAGE_SHIFT,
868
- PFN_UP(__pa_symbol(&_edata)) << PAGE_SHIFT,
869
- BOOT_MEM_RAM);
870
- arch_mem_addpart(PFN_UP(__pa_symbol(&__init_begin)) << PAGE_SHIFT,
871
- PFN_DOWN(__pa_symbol(&__init_end)) << PAGE_SHIFT,
872
- BOOT_MEM_INIT_RAM);
873
-
874
- pr_info("Determined physical RAM map:\n");
875
- print_memory_map();
876
-
877
-#if defined(CONFIG_CMDLINE_BOOL) && defined(CONFIG_CMDLINE_OVERRIDE)
878
- strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
879
-#else
880
- if ((USE_PROM_CMDLINE && arcs_cmdline[0]) ||
881
- (USE_DTB_CMDLINE && !boot_command_line[0]))
882
- strlcpy(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
883
-
884
- if (EXTEND_WITH_PROM && arcs_cmdline[0]) {
885
- if (boot_command_line[0])
886
- strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
887
- strlcat(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
888
- }
889
-
890
-#if defined(CONFIG_CMDLINE_BOOL)
891
- if (builtin_cmdline[0]) {
892
- if (boot_command_line[0])
893
- strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
894
- strlcat(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
895
- }
896
-
897
- if (BUILTIN_EXTEND_WITH_PROM && arcs_cmdline[0]) {
898
- if (boot_command_line[0])
899
- strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
900
- strlcat(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
901
- }
902
-#endif
903
-#endif
628
+ bootcmdline_init();
904629 strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
905
-
906630 *cmdline_p = command_line;
907631
908632 parse_early_param();
909633
910
- if (usermem) {
911
- pr_info("User-defined physical RAM map:\n");
912
- print_memory_map();
913
- }
634
+ if (usermem)
635
+ pr_info("User-defined physical RAM map overwrite\n");
636
+
637
+ check_kernel_sections_mem();
914638
915639 early_init_fdt_reserve_self();
916640 early_init_fdt_scan_reserved_mem();
917641
642
+#ifndef CONFIG_NUMA
643
+ memblock_set_node(0, PHYS_ADDR_MAX, &memblock.memory, 0);
644
+#endif
918645 bootmem_init();
646
+
647
+ /*
648
+ * Prevent memblock from allocating high memory.
649
+ * This cannot be done before max_low_pfn is detected, so up
650
+ * to this point is possible to only reserve physical memory
651
+ * with memblock_reserve; memblock_alloc* can be used
652
+ * only after this point
653
+ */
654
+ memblock_set_current_limit(PFN_PHYS(max_low_pfn));
655
+
919656 #ifdef CONFIG_PROC_VMCORE
920657 if (setup_elfcorehdr && setup_elfcorehdr_size) {
921658 printk(KERN_INFO "kdump reserved memory at %lx-%lx\n",
922659 setup_elfcorehdr, setup_elfcorehdr_size);
923
- reserve_bootmem(setup_elfcorehdr, setup_elfcorehdr_size,
924
- BOOTMEM_DEFAULT);
660
+ memblock_reserve(setup_elfcorehdr, setup_elfcorehdr_size);
925661 }
926662 #endif
927663
928664 mips_parse_crashkernel();
929665 #ifdef CONFIG_KEXEC
930666 if (crashk_res.start != crashk_res.end)
931
- reserve_bootmem(crashk_res.start,
932
- crashk_res.end - crashk_res.start + 1,
933
- BOOTMEM_DEFAULT);
667
+ memblock_reserve(crashk_res.start, resource_size(&crashk_res));
934668 #endif
935669 device_tree_init();
936670
....@@ -947,18 +681,22 @@
947681 plat_swiotlb_setup();
948682
949683 dma_contiguous_reserve(PFN_PHYS(max_low_pfn));
950
- /* Tell bootmem about cma reserved memblock section */
951
- for_each_memblock(reserved, reg)
952
- if (reg->size != 0)
953
- reserve_bootmem(reg->base, reg->size, BOOTMEM_DEFAULT);
954684
955
- reserve_bootmem_region(__pa_symbol(&__nosave_begin),
956
- __pa_symbol(&__nosave_end)); /* Reserve for hibernation */
685
+ /* Reserve for hibernation. */
686
+ memblock_reserve(__pa_symbol(&__nosave_begin),
687
+ __pa_symbol(&__nosave_end) - __pa_symbol(&__nosave_begin));
688
+
689
+ fdt_init_reserved_mem();
690
+
691
+ memblock_dump_all();
692
+
693
+ early_memtest(PFN_PHYS(ARCH_PFN_OFFSET), PFN_PHYS(max_low_pfn));
957694 }
958695
959696 static void __init resource_init(void)
960697 {
961
- int i;
698
+ phys_addr_t start, end;
699
+ u64 i;
962700
963701 if (UNCAC_BASE != IO_BASE)
964702 return;
....@@ -970,34 +708,23 @@
970708 bss_resource.start = __pa_symbol(&__bss_start);
971709 bss_resource.end = __pa_symbol(&__bss_stop) - 1;
972710
973
- for (i = 0; i < boot_mem_map.nr_map; i++) {
711
+ for_each_mem_range(i, &start, &end) {
974712 struct resource *res;
975
- unsigned long start, end;
976713
977
- start = boot_mem_map.map[i].addr;
978
- end = boot_mem_map.map[i].addr + boot_mem_map.map[i].size - 1;
979
- if (start >= HIGHMEM_START)
980
- continue;
981
- if (end >= HIGHMEM_START)
982
- end = HIGHMEM_START - 1;
983
-
984
- res = alloc_bootmem(sizeof(struct resource));
714
+ res = memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES);
715
+ if (!res)
716
+ panic("%s: Failed to allocate %zu bytes\n", __func__,
717
+ sizeof(struct resource));
985718
986719 res->start = start;
987
- res->end = end;
988
- res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
989
-
990
- switch (boot_mem_map.map[i].type) {
991
- case BOOT_MEM_RAM:
992
- case BOOT_MEM_INIT_RAM:
993
- case BOOT_MEM_ROM_DATA:
994
- res->name = "System RAM";
995
- res->flags |= IORESOURCE_SYSRAM;
996
- break;
997
- case BOOT_MEM_RESERVED:
998
- default:
999
- res->name = "reserved";
1000
- }
720
+ /*
721
+ * In memblock, end points to the first byte after the
722
+ * range while in resourses, end points to the last byte in
723
+ * the range.
724
+ */
725
+ res->end = end - 1;
726
+ res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
727
+ res->name = "System RAM";
1001728
1002729 request_resource(&iomem_resource, res);
1003730
....@@ -1048,12 +775,11 @@
1048775 #if defined(CONFIG_VT)
1049776 #if defined(CONFIG_VGA_CONSOLE)
1050777 conswitchp = &vga_con;
1051
-#elif defined(CONFIG_DUMMY_CONSOLE)
1052
- conswitchp = &dummy_con;
1053778 #endif
1054779 #endif
1055780
1056781 arch_mem_init(cmdline_p);
782
+ dmi_setup();
1057783
1058784 resource_init();
1059785 plat_smp_setup();
....@@ -1074,22 +800,17 @@
1074800 struct dentry *mips_debugfs_dir;
1075801 static int __init debugfs_mips(void)
1076802 {
1077
- struct dentry *d;
1078
-
1079
- d = debugfs_create_dir("mips", NULL);
1080
- if (!d)
1081
- return -ENOMEM;
1082
- mips_debugfs_dir = d;
803
+ mips_debugfs_dir = debugfs_create_dir("mips", NULL);
1083804 return 0;
1084805 }
1085806 arch_initcall(debugfs_mips);
1086807 #endif
1087808
1088
-#if defined(CONFIG_DMA_MAYBE_COHERENT) && !defined(CONFIG_DMA_PERDEV_COHERENT)
809
+#ifdef CONFIG_DMA_MAYBE_COHERENT
1089810 /* User defined DMA coherency from command line. */
1090811 enum coherent_io_user_state coherentio = IO_COHERENCE_DEFAULT;
1091812 EXPORT_SYMBOL_GPL(coherentio);
1092
-int hw_coherentio = 0; /* Actual hardware supported DMA coherency setting. */
813
+int hw_coherentio; /* Actual hardware supported DMA coherency setting. */
1093814
1094815 static int __init setcoherentio(char *str)
1095816 {