hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/arch/powerpc/kernel/prom.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Procedures for creating, accessing and interpreting the device tree.
34 *
....@@ -6,11 +7,6 @@
67 *
78 * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
89 * {engebret|bergner}@us.ibm.com
9
- *
10
- * This program is free software; you can redistribute it and/or
11
- * modify it under the terms of the GNU General Public License
12
- * as published by the Free Software Foundation; either version
13
- * 2 of the License, or (at your option) any later version.
1410 */
1511
1612 #undef DEBUG
....@@ -34,6 +30,7 @@
3430 #include <linux/of_fdt.h>
3531 #include <linux/libfdt.h>
3632 #include <linux/cpu.h>
33
+#include <linux/pgtable.h>
3734
3835 #include <asm/prom.h>
3936 #include <asm/rtas.h>
....@@ -45,7 +42,6 @@
4542 #include <asm/smp.h>
4643 #include <asm/mmu.h>
4744 #include <asm/paca.h>
48
-#include <asm/pgtable.h>
4945 #include <asm/powernv.h>
5046 #include <asm/iommu.h>
5147 #include <asm/btext.h>
....@@ -59,6 +55,7 @@
5955 #include <asm/firmware.h>
6056 #include <asm/dt_cpu_ftrs.h>
6157 #include <asm/drmem.h>
58
+#include <asm/ultravisor.h>
6259
6360 #include <mm/mmu_decl.h>
6461
....@@ -99,8 +96,8 @@
9996 if (!initrd_start)
10097 return 0;
10198
102
- return (start + size) > _ALIGN_DOWN(initrd_start, PAGE_SIZE) &&
103
- start <= _ALIGN_UP(initrd_end, PAGE_SIZE);
99
+ return (start + size) > ALIGN_DOWN(initrd_start, PAGE_SIZE) &&
100
+ start <= ALIGN(initrd_end, PAGE_SIZE);
104101 #else
105102 return 0;
106103 #endif
....@@ -124,9 +121,12 @@
124121 size = fdt_totalsize(initial_boot_params);
125122
126123 if ((memory_limit && (start + size) > PHYSICAL_START + memory_limit) ||
127
- overlaps_crashkernel(start, size) ||
128
- overlaps_initrd(start, size)) {
129
- p = __va(memblock_alloc(size, PAGE_SIZE));
124
+ !memblock_is_memory(start + size - 1) ||
125
+ overlaps_crashkernel(start, size) || overlaps_initrd(start, size)) {
126
+ p = memblock_alloc_raw(size, PAGE_SIZE);
127
+ if (!p)
128
+ panic("Failed to allocate %lu bytes to move device tree\n",
129
+ size);
130130 memcpy(p, initial_boot_params, size);
131131 initial_boot_params = p;
132132 DBG("Moved device tree to 0x%px\n", p);
....@@ -163,7 +163,7 @@
163163 { .pabyte = 0, .pabit = 6, .cpu_features = CPU_FTR_NOEXECUTE },
164164 { .pabyte = 1, .pabit = 2, .mmu_features = MMU_FTR_CI_LARGE_PAGE },
165165 #ifdef CONFIG_PPC_RADIX_MMU
166
- { .pabyte = 40, .pabit = 0, .mmu_features = MMU_FTR_TYPE_RADIX },
166
+ { .pabyte = 40, .pabit = 0, .mmu_features = MMU_FTR_TYPE_RADIX | MMU_FTR_GTSE },
167167 #endif
168168 { .pabyte = 1, .pabit = 1, .invert = 1, .cpu_features = CPU_FTR_NODSISRALIGN },
169169 { .pabyte = 5, .pabit = 0, .cpu_features = CPU_FTR_REAL_LE,
....@@ -175,6 +175,8 @@
175175 */
176176 { .pabyte = 22, .pabit = 0, .cpu_features = CPU_FTR_TM_COMP,
177177 .cpu_user_ftrs2 = PPC_FEATURE2_HTM_COMP | PPC_FEATURE2_HTM_NOSC_COMP },
178
+
179
+ { .pabyte = 64, .pabit = 0, .cpu_features = CPU_FTR_DAWR1 },
178180 };
179181
180182 static void __init scan_features(unsigned long node, const unsigned char *ftrs,
....@@ -468,8 +470,9 @@
468470 * This contains a list of memory blocks along with NUMA affinity
469471 * information.
470472 */
471
-static void __init early_init_drmem_lmb(struct drmem_lmb *lmb,
472
- const __be32 **usm)
473
+static int __init early_init_drmem_lmb(struct drmem_lmb *lmb,
474
+ const __be32 **usm,
475
+ void *data)
473476 {
474477 u64 base, size;
475478 int is_kexec_kdump = 0, rngs;
....@@ -484,7 +487,7 @@
484487 */
485488 if ((lmb->flags & DRCONF_MEM_RESERVED) ||
486489 !(lmb->flags & DRCONF_MEM_ASSIGNED))
487
- return;
490
+ return 0;
488491
489492 if (*usm)
490493 is_kexec_kdump = 1;
....@@ -499,7 +502,7 @@
499502 */
500503 rngs = dt_mem_next_cell(dt_root_size_cells, usm);
501504 if (!rngs) /* there are no (base, size) duple */
502
- return;
505
+ return 0;
503506 }
504507
505508 do {
....@@ -515,10 +518,17 @@
515518 size = 0x80000000ul - base;
516519 }
517520
521
+ if (!validate_mem_limit(base, &size))
522
+ continue;
523
+
518524 DBG("Adding: %llx -> %llx\n", base, size);
519
- if (validate_mem_limit(base, &size))
520
- memblock_add(base, size);
525
+ memblock_add(base, size);
526
+
527
+ if (lmb->flags & DRCONF_MEM_HOTREMOVABLE)
528
+ memblock_mark_hotplug(base, size);
521529 } while (--rngs);
530
+
531
+ return 0;
522532 }
523533 #endif /* CONFIG_PPC_PSERIES */
524534
....@@ -529,7 +539,7 @@
529539 #ifdef CONFIG_PPC_PSERIES
530540 if (depth == 1 &&
531541 strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0) {
532
- walk_drmem_lmbs_early(node, early_init_drmem_lmb);
542
+ walk_drmem_lmbs_early(node, NULL, early_init_drmem_lmb);
533543 return 0;
534544 }
535545 #endif
....@@ -623,9 +633,9 @@
623633 #ifdef CONFIG_BLK_DEV_INITRD
624634 /* Then reserve the initrd, if any */
625635 if (initrd_start && (initrd_end > initrd_start)) {
626
- memblock_reserve(_ALIGN_DOWN(__pa(initrd_start), PAGE_SIZE),
627
- _ALIGN_UP(initrd_end, PAGE_SIZE) -
628
- _ALIGN_DOWN(initrd_start, PAGE_SIZE));
636
+ memblock_reserve(ALIGN_DOWN(__pa(initrd_start), PAGE_SIZE),
637
+ ALIGN(initrd_end, PAGE_SIZE) -
638
+ ALIGN_DOWN(initrd_start, PAGE_SIZE));
629639 }
630640 #endif /* CONFIG_BLK_DEV_INITRD */
631641
....@@ -720,9 +730,12 @@
720730 #ifdef CONFIG_PPC_POWERNV
721731 /* Some machines might need OPAL info for debugging, grab it now. */
722732 of_scan_flat_dt(early_init_dt_scan_opal, NULL);
733
+
734
+ /* Scan tree for ultravisor feature */
735
+ of_scan_flat_dt(early_init_dt_scan_ultravisor, NULL);
723736 #endif
724737
725
-#ifdef CONFIG_FA_DUMP
738
+#if defined(CONFIG_FA_DUMP) || defined(CONFIG_PRESERVE_FA_DUMP)
726739 /* scan tree to see if dump is active during last boot */
727740 of_scan_flat_dt(early_init_dt_scan_fw_dump, NULL);
728741 #endif
....@@ -737,6 +750,13 @@
737750 of_scan_flat_dt(early_init_dt_scan_root, NULL);
738751 of_scan_flat_dt(early_init_dt_scan_memory_ppc, NULL);
739752
753
+ /*
754
+ * As generic code authors expect to be able to use static keys
755
+ * in early_param() handlers, we initialize the static keys just
756
+ * before parsing early params (it's fine to call jump_label_init()
757
+ * more than once).
758
+ */
759
+ jump_label_init();
740760 parse_early_param();
741761
742762 /* make sure we've parsed cmdline for mem= before this */
....@@ -749,7 +769,7 @@
749769 if (PHYSICAL_START > MEMORY_START)
750770 memblock_reserve(MEMORY_START, 0x8000);
751771 reserve_kdump_trampoline();
752
-#ifdef CONFIG_FA_DUMP
772
+#if defined(CONFIG_FA_DUMP) || defined(CONFIG_PRESERVE_FA_DUMP)
753773 /*
754774 * If we fail to reserve memory for firmware-assisted dump then
755775 * fallback to kexec based kdump.
....@@ -762,6 +782,11 @@
762782 /* Ensure that total memory size is page-aligned. */
763783 limit = ALIGN(memory_limit ?: memblock_phys_mem_size(), PAGE_SIZE);
764784 memblock_enforce_memory_limit(limit);
785
+
786
+#if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_PPC_4K_PAGES)
787
+ if (!early_radix_enabled())
788
+ memblock_cap_memory_range(0, 1UL << (H_MAX_PHYSMEM_BITS));
789
+#endif
765790
766791 memblock_allow_resize();
767792 memblock_dump_all();
....@@ -807,6 +832,11 @@
807832 /* Now try to figure out if we are running on LPAR and so on */
808833 pseries_probe_fw_features();
809834
835
+ /*
836
+ * Initialize pkey features and default AMR/IAMR values
837
+ */
838
+ pkey_early_init_devtree();
839
+
810840 #ifdef CONFIG_PPC_PS3
811841 /* Identify PS3 firmware */
812842 if (of_flat_dt_is_compatible(of_get_flat_dt_root(), "sony,ps3"))