hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/arch/sparc/kernel/prom_32.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 *
....@@ -8,18 +9,13 @@
89 * {engebret|bergner}@us.ibm.com
910 *
1011 * Adapted for sparc32 by David S. Miller davem@davemloft.net
11
- *
12
- * This program is free software; you can redistribute it and/or
13
- * modify it under the terms of the GNU General Public License
14
- * as published by the Free Software Foundation; either version
15
- * 2 of the License, or (at your option) any later version.
1612 */
1713
1814 #include <linux/kernel.h>
1915 #include <linux/types.h>
2016 #include <linux/string.h>
2117 #include <linux/mm.h>
22
-#include <linux/bootmem.h>
18
+#include <linux/memblock.h>
2319
2420 #include <asm/prom.h>
2521 #include <asm/oplib.h>
....@@ -32,9 +28,9 @@
3228 {
3329 void *ret;
3430
35
- ret = __alloc_bootmem(size, SMP_CACHE_BYTES, 0UL);
36
- if (ret != NULL)
37
- memset(ret, 0, size);
31
+ ret = memblock_alloc(size, SMP_CACHE_BYTES);
32
+ if (!ret)
33
+ panic("%s: Failed to allocate %lu bytes\n", __func__, size);
3834
3935 prom_early_allocated += size;
4036
....@@ -60,6 +56,7 @@
6056 */
6157 static void __init sparc32_path_component(struct device_node *dp, char *tmp_buf)
6258 {
59
+ const char *name = of_get_property(dp, "name", NULL);
6360 struct linux_prom_registers *regs;
6461 struct property *rprop;
6562
....@@ -69,13 +66,14 @@
6966
7067 regs = rprop->value;
7168 sprintf(tmp_buf, "%s@%x,%x",
72
- dp->name,
69
+ name,
7370 regs->which_io, regs->phys_addr);
7471 }
7572
7673 /* "name@slot,offset" */
7774 static void __init sbus_path_component(struct device_node *dp, char *tmp_buf)
7875 {
76
+ const char *name = of_get_property(dp, "name", NULL);
7977 struct linux_prom_registers *regs;
8078 struct property *prop;
8179
....@@ -85,7 +83,7 @@
8583
8684 regs = prop->value;
8785 sprintf(tmp_buf, "%s@%x,%x",
88
- dp->name,
86
+ name,
8987 regs->which_io,
9088 regs->phys_addr);
9189 }
....@@ -93,6 +91,7 @@
9391 /* "name@devnum[,func]" */
9492 static void __init pci_path_component(struct device_node *dp, char *tmp_buf)
9593 {
94
+ const char *name = of_get_property(dp, "name", NULL);
9695 struct linux_prom_pci_registers *regs;
9796 struct property *prop;
9897 unsigned int devfn;
....@@ -105,12 +104,12 @@
105104 devfn = (regs->phys_hi >> 8) & 0xff;
106105 if (devfn & 0x07) {
107106 sprintf(tmp_buf, "%s@%x,%x",
108
- dp->name,
107
+ name,
109108 devfn >> 3,
110109 devfn & 0x07);
111110 } else {
112111 sprintf(tmp_buf, "%s@%x",
113
- dp->name,
112
+ name,
114113 devfn >> 3);
115114 }
116115 }
....@@ -118,6 +117,7 @@
118117 /* "name@addrhi,addrlo" */
119118 static void __init ebus_path_component(struct device_node *dp, char *tmp_buf)
120119 {
120
+ const char *name = of_get_property(dp, "name", NULL);
121121 struct linux_prom_registers *regs;
122122 struct property *prop;
123123
....@@ -128,15 +128,17 @@
128128 regs = prop->value;
129129
130130 sprintf(tmp_buf, "%s@%x,%x",
131
- dp->name,
131
+ name,
132132 regs->which_io, regs->phys_addr);
133133 }
134134
135
-/* "name:vendor:device@irq,addrlo" */
135
+/* "name@irq,addrlo" */
136136 static void __init ambapp_path_component(struct device_node *dp, char *tmp_buf)
137137 {
138
+ const char *name = of_get_property(dp, "name", NULL);
138139 struct amba_prom_registers *regs;
139
- unsigned int *intr, *device, *vendor, reg0;
140
+ unsigned int *intr;
141
+ unsigned int reg0;
140142 struct property *prop;
141143 int interrupt = 0;
142144
....@@ -158,18 +160,7 @@
158160 else
159161 intr = prop->value;
160162
161
- prop = of_find_property(dp, "vendor", NULL);
162
- if (!prop)
163
- return;
164
- vendor = prop->value;
165
- prop = of_find_property(dp, "device", NULL);
166
- if (!prop)
167
- return;
168
- device = prop->value;
169
-
170
- sprintf(tmp_buf, "%s:%d:%d@%x,%x",
171
- dp->name, *vendor, *device,
172
- *intr, reg0);
163
+ sprintf(tmp_buf, "%s@%x,%x", name, *intr, reg0);
173164 }
174165
175166 static void __init __build_path_component(struct device_node *dp, char *tmp_buf)
....@@ -177,14 +168,14 @@
177168 struct device_node *parent = dp->parent;
178169
179170 if (parent != NULL) {
180
- if (!strcmp(parent->type, "pci") ||
181
- !strcmp(parent->type, "pciex"))
171
+ if (of_node_is_type(parent, "pci") ||
172
+ of_node_is_type(parent, "pciex"))
182173 return pci_path_component(dp, tmp_buf);
183
- if (!strcmp(parent->type, "sbus"))
174
+ if (of_node_is_type(parent, "sbus"))
184175 return sbus_path_component(dp, tmp_buf);
185
- if (!strcmp(parent->type, "ebus"))
176
+ if (of_node_is_type(parent, "ebus"))
186177 return ebus_path_component(dp, tmp_buf);
187
- if (!strcmp(parent->type, "ambapp"))
178
+ if (of_node_is_type(parent, "ambapp"))
188179 return ambapp_path_component(dp, tmp_buf);
189180
190181 /* "isa" is handled with platform naming */
....@@ -196,12 +187,13 @@
196187
197188 char * __init build_path_component(struct device_node *dp)
198189 {
190
+ const char *name = of_get_property(dp, "name", NULL);
199191 char tmp_buf[64], *n;
200192
201193 tmp_buf[0] = '\0';
202194 __build_path_component(dp, tmp_buf);
203195 if (tmp_buf[0] == '\0')
204
- strcpy(tmp_buf, dp->name);
196
+ strcpy(tmp_buf, name);
205197
206198 n = prom_early_alloc(strlen(tmp_buf) + 1);
207199 strcpy(n, tmp_buf);
....@@ -232,7 +224,7 @@
232224
233225 case PROMDEV_TTYB:
234226 skip = 1;
235
- /* FALLTHRU */
227
+ fallthrough;
236228
237229 case PROMDEV_TTYA:
238230 type = "serial";
....@@ -255,7 +247,7 @@
255247 }
256248 of_console_device = dp;
257249
258
- strcpy(of_console_path, dp->full_name);
250
+ sprintf(of_console_path, "%pOF", dp);
259251 if (!strcmp(type, "serial")) {
260252 strcat(of_console_path,
261253 (skip ? ":b" : ":a"));
....@@ -278,15 +270,9 @@
278270 prom_halt();
279271 }
280272 dp = of_find_node_by_phandle(node);
281
- type = of_get_property(dp, "device_type", NULL);
282273
283
- if (!type) {
284
- prom_printf("Console stdout lacks "
285
- "device_type property.\n");
286
- prom_halt();
287
- }
288
-
289
- if (strcmp(type, "display") && strcmp(type, "serial")) {
274
+ if (!of_node_is_type(dp, "display") &&
275
+ !of_node_is_type(dp, "serial")) {
290276 prom_printf("Console device_type is neither display "
291277 "nor serial.\n");
292278 prom_halt();
....@@ -295,7 +281,7 @@
295281 of_console_device = dp;
296282
297283 if (prom_vers == PROM_V2) {
298
- strcpy(of_console_path, dp->full_name);
284
+ sprintf(of_console_path, "%pOF", dp);
299285 switch (*romvec->pv_stdout) {
300286 case PROMDEV_TTYA:
301287 strcat(of_console_path, ":a");