hc
2024-05-10 748e4f3d702def1a4bff191e0cf93b6a05340f01
kernel/arch/sparc/kernel/prom_64.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,11 +9,6 @@
89 * {engebret|bergner}@us.ibm.com
910 *
1011 * Adapted for sparc64 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/memblock.h>
....@@ -34,16 +30,13 @@
3430
3531 void * __init prom_early_alloc(unsigned long size)
3632 {
37
- unsigned long paddr = memblock_alloc(size, SMP_CACHE_BYTES);
38
- void *ret;
33
+ void *ret = memblock_alloc(size, SMP_CACHE_BYTES);
3934
40
- if (!paddr) {
35
+ if (!ret) {
4136 prom_printf("prom_early_alloc(%lu) failed\n", size);
4237 prom_halt();
4338 }
4439
45
- ret = __va(paddr);
46
- memset(ret, 0, size);
4740 prom_early_allocated += size;
4841
4942 return ret;
....@@ -72,6 +65,7 @@
7265 */
7366 static void __init sun4v_path_component(struct device_node *dp, char *tmp_buf)
7467 {
68
+ const char *name = of_get_property(dp, "name", NULL);
7569 struct linux_prom64_registers *regs;
7670 struct property *rprop;
7771 u32 high_bits, low_bits, type;
....@@ -83,7 +77,7 @@
8377 regs = rprop->value;
8478 if (!of_node_is_root(dp->parent)) {
8579 sprintf(tmp_buf, "%s@%x,%x",
86
- dp->name,
80
+ name,
8781 (unsigned int) (regs->phys_addr >> 32UL),
8882 (unsigned int) (regs->phys_addr & 0xffffffffUL));
8983 return;
....@@ -98,21 +92,22 @@
9892
9993 if (low_bits)
10094 sprintf(tmp_buf, "%s@%s%x,%x",
101
- dp->name, prefix,
95
+ name, prefix,
10296 high_bits, low_bits);
10397 else
10498 sprintf(tmp_buf, "%s@%s%x",
105
- dp->name,
99
+ name,
106100 prefix,
107101 high_bits);
108102 } else if (type == 12) {
109103 sprintf(tmp_buf, "%s@%x",
110
- dp->name, high_bits);
104
+ name, high_bits);
111105 }
112106 }
113107
114108 static void __init sun4u_path_component(struct device_node *dp, char *tmp_buf)
115109 {
110
+ const char *name = of_get_property(dp, "name", NULL);
116111 struct linux_prom64_registers *regs;
117112 struct property *prop;
118113
....@@ -123,7 +118,7 @@
123118 regs = prop->value;
124119 if (!of_node_is_root(dp->parent)) {
125120 sprintf(tmp_buf, "%s@%x,%x",
126
- dp->name,
121
+ name,
127122 (unsigned int) (regs->phys_addr >> 32UL),
128123 (unsigned int) (regs->phys_addr & 0xffffffffUL));
129124 return;
....@@ -139,7 +134,7 @@
139134 mask = 0x7fffff;
140135
141136 sprintf(tmp_buf, "%s@%x,%x",
142
- dp->name,
137
+ name,
143138 *(u32 *)prop->value,
144139 (unsigned int) (regs->phys_addr & mask));
145140 }
....@@ -148,6 +143,7 @@
148143 /* "name@slot,offset" */
149144 static void __init sbus_path_component(struct device_node *dp, char *tmp_buf)
150145 {
146
+ const char *name = of_get_property(dp, "name", NULL);
151147 struct linux_prom_registers *regs;
152148 struct property *prop;
153149
....@@ -157,7 +153,7 @@
157153
158154 regs = prop->value;
159155 sprintf(tmp_buf, "%s@%x,%x",
160
- dp->name,
156
+ name,
161157 regs->which_io,
162158 regs->phys_addr);
163159 }
....@@ -165,6 +161,7 @@
165161 /* "name@devnum[,func]" */
166162 static void __init pci_path_component(struct device_node *dp, char *tmp_buf)
167163 {
164
+ const char *name = of_get_property(dp, "name", NULL);
168165 struct linux_prom_pci_registers *regs;
169166 struct property *prop;
170167 unsigned int devfn;
....@@ -177,12 +174,12 @@
177174 devfn = (regs->phys_hi >> 8) & 0xff;
178175 if (devfn & 0x07) {
179176 sprintf(tmp_buf, "%s@%x,%x",
180
- dp->name,
177
+ name,
181178 devfn >> 3,
182179 devfn & 0x07);
183180 } else {
184181 sprintf(tmp_buf, "%s@%x",
185
- dp->name,
182
+ name,
186183 devfn >> 3);
187184 }
188185 }
....@@ -190,6 +187,7 @@
190187 /* "name@UPA_PORTID,offset" */
191188 static void __init upa_path_component(struct device_node *dp, char *tmp_buf)
192189 {
190
+ const char *name = of_get_property(dp, "name", NULL);
193191 struct linux_prom64_registers *regs;
194192 struct property *prop;
195193
....@@ -204,7 +202,7 @@
204202 return;
205203
206204 sprintf(tmp_buf, "%s@%x,%x",
207
- dp->name,
205
+ name,
208206 *(u32 *) prop->value,
209207 (unsigned int) (regs->phys_addr & 0xffffffffUL));
210208 }
....@@ -212,6 +210,7 @@
212210 /* "name@reg" */
213211 static void __init vdev_path_component(struct device_node *dp, char *tmp_buf)
214212 {
213
+ const char *name = of_get_property(dp, "name", NULL);
215214 struct property *prop;
216215 u32 *regs;
217216
....@@ -221,12 +220,13 @@
221220
222221 regs = prop->value;
223222
224
- sprintf(tmp_buf, "%s@%x", dp->name, *regs);
223
+ sprintf(tmp_buf, "%s@%x", name, *regs);
225224 }
226225
227226 /* "name@addrhi,addrlo" */
228227 static void __init ebus_path_component(struct device_node *dp, char *tmp_buf)
229228 {
229
+ const char *name = of_get_property(dp, "name", NULL);
230230 struct linux_prom64_registers *regs;
231231 struct property *prop;
232232
....@@ -237,7 +237,7 @@
237237 regs = prop->value;
238238
239239 sprintf(tmp_buf, "%s@%x,%x",
240
- dp->name,
240
+ name,
241241 (unsigned int) (regs->phys_addr >> 32UL),
242242 (unsigned int) (regs->phys_addr & 0xffffffffUL));
243243 }
....@@ -245,6 +245,7 @@
245245 /* "name@bus,addr" */
246246 static void __init i2c_path_component(struct device_node *dp, char *tmp_buf)
247247 {
248
+ const char *name = of_get_property(dp, "name", NULL);
248249 struct property *prop;
249250 u32 *regs;
250251
....@@ -258,12 +259,13 @@
258259 * property of the i2c bus node etc. etc.
259260 */
260261 sprintf(tmp_buf, "%s@%x,%x",
261
- dp->name, regs[0], regs[1]);
262
+ name, regs[0], regs[1]);
262263 }
263264
264265 /* "name@reg0[,reg1]" */
265266 static void __init usb_path_component(struct device_node *dp, char *tmp_buf)
266267 {
268
+ const char *name = of_get_property(dp, "name", NULL);
267269 struct property *prop;
268270 u32 *regs;
269271
....@@ -275,16 +277,17 @@
275277
276278 if (prop->length == sizeof(u32) || regs[1] == 1) {
277279 sprintf(tmp_buf, "%s@%x",
278
- dp->name, regs[0]);
280
+ name, regs[0]);
279281 } else {
280282 sprintf(tmp_buf, "%s@%x,%x",
281
- dp->name, regs[0], regs[1]);
283
+ name, regs[0], regs[1]);
282284 }
283285 }
284286
285287 /* "name@reg0reg1[,reg2reg3]" */
286288 static void __init ieee1394_path_component(struct device_node *dp, char *tmp_buf)
287289 {
290
+ const char *name = of_get_property(dp, "name", NULL);
288291 struct property *prop;
289292 u32 *regs;
290293
....@@ -296,10 +299,10 @@
296299
297300 if (regs[2] || regs[3]) {
298301 sprintf(tmp_buf, "%s@%08x%08x,%04x%08x",
299
- dp->name, regs[0], regs[1], regs[2], regs[3]);
302
+ name, regs[0], regs[1], regs[2], regs[3]);
300303 } else {
301304 sprintf(tmp_buf, "%s@%08x%08x",
302
- dp->name, regs[0], regs[1]);
305
+ name, regs[0], regs[1]);
303306 }
304307 }
305308
....@@ -308,37 +311,37 @@
308311 struct device_node *parent = dp->parent;
309312
310313 if (parent != NULL) {
311
- if (!strcmp(parent->type, "pci") ||
312
- !strcmp(parent->type, "pciex")) {
314
+ if (of_node_is_type(parent, "pci") ||
315
+ of_node_is_type(parent, "pciex")) {
313316 pci_path_component(dp, tmp_buf);
314317 return;
315318 }
316
- if (!strcmp(parent->type, "sbus")) {
319
+ if (of_node_is_type(parent, "sbus")) {
317320 sbus_path_component(dp, tmp_buf);
318321 return;
319322 }
320
- if (!strcmp(parent->type, "upa")) {
323
+ if (of_node_is_type(parent, "upa")) {
321324 upa_path_component(dp, tmp_buf);
322325 return;
323326 }
324
- if (!strcmp(parent->type, "ebus")) {
327
+ if (of_node_is_type(parent, "ebus")) {
325328 ebus_path_component(dp, tmp_buf);
326329 return;
327330 }
328
- if (!strcmp(parent->name, "usb") ||
329
- !strcmp(parent->name, "hub")) {
331
+ if (of_node_name_eq(parent, "usb") ||
332
+ of_node_name_eq(parent, "hub")) {
330333 usb_path_component(dp, tmp_buf);
331334 return;
332335 }
333
- if (!strcmp(parent->type, "i2c")) {
336
+ if (of_node_is_type(parent, "i2c")) {
334337 i2c_path_component(dp, tmp_buf);
335338 return;
336339 }
337
- if (!strcmp(parent->type, "firewire")) {
340
+ if (of_node_is_type(parent, "firewire")) {
338341 ieee1394_path_component(dp, tmp_buf);
339342 return;
340343 }
341
- if (!strcmp(parent->type, "virtual-devices")) {
344
+ if (of_node_is_type(parent, "virtual-devices")) {
342345 vdev_path_component(dp, tmp_buf);
343346 return;
344347 }
....@@ -356,12 +359,13 @@
356359
357360 char * __init build_path_component(struct device_node *dp)
358361 {
362
+ const char *name = of_get_property(dp, "name", NULL);
359363 char tmp_buf[64], *n;
360364
361365 tmp_buf[0] = '\0';
362366 __build_path_component(dp, tmp_buf);
363367 if (tmp_buf[0] == '\0')
364
- strcpy(tmp_buf, dp->name);
368
+ strcpy(tmp_buf, name);
365369
366370 n = prom_early_alloc(strlen(tmp_buf) + 1);
367371 strcpy(n, tmp_buf);
....@@ -594,7 +598,6 @@
594598 {
595599 char *msg = "OF stdout device is: %s\n";
596600 struct device_node *dp;
597
- const char *type;
598601 phandle node;
599602
600603 of_console_path = prom_early_alloc(256);
....@@ -617,13 +620,8 @@
617620 }
618621
619622 dp = of_find_node_by_phandle(node);
620
- type = of_get_property(dp, "device_type", NULL);
621
- if (!type) {
622
- prom_printf("Console stdout lacks device_type property.\n");
623
- prom_halt();
624
- }
625623
626
- if (strcmp(type, "display") && strcmp(type, "serial")) {
624
+ if (!of_node_is_type(dp, "display") && !of_node_is_type(dp, "serial")) {
627625 prom_printf("Console device_type is neither display "
628626 "nor serial.\n");
629627 prom_halt();