hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/arch/arm/kernel/setup.c
....@@ -1,11 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * linux/arch/arm/kernel/setup.c
34 *
45 * Copyright (C) 1995-2001 Russell King
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License version 2 as
8
- * published by the Free Software Foundation.
96 */
107 #include <linux/efi.h>
118 #include <linux/export.h>
....@@ -16,12 +13,12 @@
1613 #include <linux/utsname.h>
1714 #include <linux/initrd.h>
1815 #include <linux/console.h>
19
-#include <linux/bootmem.h>
2016 #include <linux/seq_file.h>
2117 #include <linux/screen_info.h>
2218 #include <linux/of_platform.h>
2319 #include <linux/init.h>
2420 #include <linux/kexec.h>
21
+#include <linux/libfdt.h>
2522 #include <linux/of_fdt.h>
2623 #include <linux/cpu.h>
2724 #include <linux/interrupt.h>
....@@ -112,17 +109,6 @@
112109 unsigned int elf_hwcap2 __read_mostly;
113110 EXPORT_SYMBOL(elf_hwcap2);
114111
115
-
116
-char* (*arch_read_hardware_id)(void);
117
-EXPORT_SYMBOL(arch_read_hardware_id);
118
-
119
-/* Vendor stub */
120
-unsigned int boot_reason;
121
-EXPORT_SYMBOL_GPL(boot_reason);
122
-
123
-/* Vendor stub */
124
-unsigned int cold_boot;
125
-EXPORT_SYMBOL_GPL(cold_boot);
126112
127113 #ifdef MULTI_CPU
128114 struct processor processor __ro_after_init;
....@@ -860,18 +846,24 @@
860846
861847 static void __init request_standard_resources(const struct machine_desc *mdesc)
862848 {
863
- struct memblock_region *region;
849
+ phys_addr_t start, end, res_end;
864850 struct resource *res;
851
+ u64 i;
865852
866853 kernel_code.start = virt_to_phys(_text);
867854 kernel_code.end = virt_to_phys(__init_begin - 1);
868855 kernel_data.start = virt_to_phys(_sdata);
869856 kernel_data.end = virt_to_phys(_end - 1);
870857
871
- for_each_memblock(memory, region) {
872
- phys_addr_t start = __pfn_to_phys(memblock_region_memory_base_pfn(region));
873
- phys_addr_t end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) - 1;
858
+ for_each_mem_range(i, &start, &end) {
874859 unsigned long boot_alias_start;
860
+
861
+ /*
862
+ * In memblock, end points to the first byte after the
863
+ * range while in resourses, end points to the last byte in
864
+ * the range.
865
+ */
866
+ res_end = end - 1;
875867
876868 /*
877869 * Some systems have a special memory alias which is only
....@@ -880,18 +872,24 @@
880872 */
881873 boot_alias_start = phys_to_idmap(start);
882874 if (arm_has_idmap_alias() && boot_alias_start != IDMAP_INVALID_ADDR) {
883
- res = memblock_virt_alloc(sizeof(*res), 0);
875
+ res = memblock_alloc(sizeof(*res), SMP_CACHE_BYTES);
876
+ if (!res)
877
+ panic("%s: Failed to allocate %zu bytes\n",
878
+ __func__, sizeof(*res));
884879 res->name = "System RAM (boot alias)";
885880 res->start = boot_alias_start;
886
- res->end = phys_to_idmap(end);
881
+ res->end = phys_to_idmap(res_end);
887882 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
888883 request_resource(&iomem_resource, res);
889884 }
890885
891
- res = memblock_virt_alloc(sizeof(*res), 0);
886
+ res = memblock_alloc(sizeof(*res), SMP_CACHE_BYTES);
887
+ if (!res)
888
+ panic("%s: Failed to allocate %zu bytes\n", __func__,
889
+ sizeof(*res));
892890 res->name = "System RAM";
893891 res->start = start;
894
- res->end = end;
892
+ res->end = res_end;
895893 res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
896894
897895 request_resource(&iomem_resource, res);
....@@ -1084,21 +1082,43 @@
10841082 #endif
10851083 }
10861084
1085
+static void (*__arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
1086
+
1087
+static int arm_restart(struct notifier_block *nb, unsigned long action,
1088
+ void *data)
1089
+{
1090
+ __arm_pm_restart(action, data);
1091
+ return NOTIFY_DONE;
1092
+}
1093
+
1094
+static struct notifier_block arm_restart_nb = {
1095
+ .notifier_call = arm_restart,
1096
+ .priority = 128,
1097
+};
1098
+
10871099 void __init setup_arch(char **cmdline_p)
10881100 {
1089
- const struct machine_desc *mdesc;
1101
+ const struct machine_desc *mdesc = NULL;
1102
+ void *atags_vaddr = NULL;
1103
+
1104
+ if (__atags_pointer)
1105
+ atags_vaddr = FDT_VIRT_BASE(__atags_pointer);
10901106
10911107 setup_processor();
1092
- mdesc = setup_machine_fdt(__atags_pointer);
1108
+ if (atags_vaddr) {
1109
+ mdesc = setup_machine_fdt(atags_vaddr);
1110
+ if (mdesc)
1111
+ memblock_reserve(__atags_pointer,
1112
+ fdt_totalsize(atags_vaddr));
1113
+ }
10931114 if (!mdesc)
1094
- mdesc = setup_machine_tags(__atags_pointer, __machine_arch_type);
1115
+ mdesc = setup_machine_tags(atags_vaddr, __machine_arch_type);
10951116 if (!mdesc) {
10961117 early_print("\nError: invalid dtb and unrecognized/unsupported machine ID\n");
10971118 early_print(" r1=0x%08x, r2=0x%08x\n", __machine_arch_type,
10981119 __atags_pointer);
10991120 if (__atags_pointer)
1100
- early_print(" r2[]=%*ph\n", 16,
1101
- phys_to_virt(__atags_pointer));
1121
+ early_print(" r2[]=%*ph\n", 16, atags_vaddr);
11021122 dump_machine_table();
11031123 }
11041124
....@@ -1143,8 +1163,10 @@
11431163 paging_init(mdesc);
11441164 request_standard_resources(mdesc);
11451165
1146
- if (mdesc->restart)
1147
- arm_pm_restart = mdesc->restart;
1166
+ if (mdesc->restart) {
1167
+ __arm_pm_restart = mdesc->restart;
1168
+ register_restart_handler(&arm_restart_nb);
1169
+ }
11481170
11491171 unflatten_device_tree();
11501172
....@@ -1175,8 +1197,6 @@
11751197 #ifdef CONFIG_VT
11761198 #if defined(CONFIG_VGA_CONSOLE)
11771199 conswitchp = &vga_con;
1178
-#elif defined(CONFIG_DUMMY_CONSOLE)
1179
- conswitchp = &dummy_con;
11801200 #endif
11811201 #endif
11821202
....@@ -1306,10 +1326,7 @@
13061326 seq_printf(m, "CPU revision\t: %d\n\n", cpuid & 15);
13071327 }
13081328
1309
- if (!arch_read_hardware_id)
1310
- seq_printf(m, "Hardware\t: %s\n", machine_name);
1311
- else
1312
- seq_printf(m, "Hardware\t: %s\n", arch_read_hardware_id());
1329
+ seq_printf(m, "Hardware\t: %s\n", machine_name);
13131330 seq_printf(m, "Revision\t: %04x\n", system_rev);
13141331 seq_printf(m, "Serial\t\t: %s\n", system_serial);
13151332