| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: ofw_subr.c,v 1.39 2020/06/26 10:14:32 martin Exp $ */ | | 1 | /* $NetBSD: ofw_subr.c,v 1.40 2020/07/16 21:32:44 jmcneill Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright 1998 | | 4 | * Copyright 1998 |
5 | * Digital Equipment Corporation. All rights reserved. | | 5 | * Digital Equipment Corporation. All rights reserved. |
6 | * | | 6 | * |
7 | * This software is furnished under license and may be used and | | 7 | * This software is furnished under license and may be used and |
8 | * copied only in accordance with the following terms and conditions. | | 8 | * copied only in accordance with the following terms and conditions. |
9 | * Subject to these conditions, you may download, copy, install, | | 9 | * Subject to these conditions, you may download, copy, install, |
10 | * use, modify and distribute this software in source and/or binary | | 10 | * use, modify and distribute this software in source and/or binary |
11 | * form. No title or ownership is transferred hereby. | | 11 | * form. No title or ownership is transferred hereby. |
12 | * | | 12 | * |
13 | * 1) Any source code used, modified or distributed must reproduce | | 13 | * 1) Any source code used, modified or distributed must reproduce |
14 | * and retain this copyright notice and list of conditions as | | 14 | * and retain this copyright notice and list of conditions as |
| @@ -24,27 +24,27 @@ | | | @@ -24,27 +24,27 @@ |
24 | * 3) This software is provided "AS-IS" and any express or implied | | 24 | * 3) This software is provided "AS-IS" and any express or implied |
25 | * warranties, including but not limited to, any implied warranties | | 25 | * warranties, including but not limited to, any implied warranties |
26 | * of merchantability, fitness for a particular purpose, or | | 26 | * of merchantability, fitness for a particular purpose, or |
27 | * non-infringement are disclaimed. In no event shall DIGITAL be | | 27 | * non-infringement are disclaimed. In no event shall DIGITAL be |
28 | * liable for any damages whatsoever, and in particular, DIGITAL | | 28 | * liable for any damages whatsoever, and in particular, DIGITAL |
29 | * shall not be liable for special, indirect, consequential, or | | 29 | * shall not be liable for special, indirect, consequential, or |
30 | * incidental damages or damages for lost profits, loss of | | 30 | * incidental damages or damages for lost profits, loss of |
31 | * revenue or loss of use, whether such damages arise in contract, | | 31 | * revenue or loss of use, whether such damages arise in contract, |
32 | * negligence, tort, under statute, in equity, at law or otherwise, | | 32 | * negligence, tort, under statute, in equity, at law or otherwise, |
33 | * even if advised of the possibility of such damage. | | 33 | * even if advised of the possibility of such damage. |
34 | */ | | 34 | */ |
35 | | | 35 | |
36 | #include <sys/cdefs.h> | | 36 | #include <sys/cdefs.h> |
37 | __KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.39 2020/06/26 10:14:32 martin Exp $"); | | 37 | __KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.40 2020/07/16 21:32:44 jmcneill Exp $"); |
38 | | | 38 | |
39 | #include <sys/param.h> | | 39 | #include <sys/param.h> |
40 | #include <sys/systm.h> | | 40 | #include <sys/systm.h> |
41 | #include <sys/malloc.h> | | 41 | #include <sys/malloc.h> |
42 | #include <dev/ofw/openfirm.h> | | 42 | #include <dev/ofw/openfirm.h> |
43 | | | 43 | |
44 | #define OFW_MAX_STACK_BUF_SIZE 256 | | 44 | #define OFW_MAX_STACK_BUF_SIZE 256 |
45 | #define OFW_PATH_BUF_SIZE 512 | | 45 | #define OFW_PATH_BUF_SIZE 512 |
46 | | | 46 | |
47 | /* | | 47 | /* |
48 | * int of_decode_int(p) | | 48 | * int of_decode_int(p) |
49 | * | | 49 | * |
50 | * This routine converts OFW encoded-int datums | | 50 | * This routine converts OFW encoded-int datums |
| @@ -327,26 +327,46 @@ of_find_firstchild_byname(int node, cons | | | @@ -327,26 +327,46 @@ of_find_firstchild_byname(int node, cons |
327 | int nn; | | 327 | int nn; |
328 | | | 328 | |
329 | for (nn = OF_child(node); nn; nn = OF_peer(nn)) { | | 329 | for (nn = OF_child(node); nn; nn = OF_peer(nn)) { |
330 | memset(namex, 0, sizeof(namex)); | | 330 | memset(namex, 0, sizeof(namex)); |
331 | if (OF_getprop(nn, "name", namex, sizeof(namex)) == -1) | | 331 | if (OF_getprop(nn, "name", namex, sizeof(namex)) == -1) |
332 | continue; | | 332 | continue; |
333 | if (strcmp(name, namex) == 0) | | 333 | if (strcmp(name, namex) == 0) |
334 | return nn; | | 334 | return nn; |
335 | } | | 335 | } |
336 | return -1; | | 336 | return -1; |
337 | } | | 337 | } |
338 | | | 338 | |
339 | /* | | 339 | /* |
| | | 340 | * Find a child node that is compatible with str. Recurses, starting at node. |
| | | 341 | */ |
| | | 342 | int |
| | | 343 | of_find_bycompat(int node, const char *str) |
| | | 344 | { |
| | | 345 | const char * compatible[] = { str, NULL }; |
| | | 346 | int child, ret; |
| | | 347 | |
| | | 348 | for (child = OF_child(node); child; child = OF_peer(child)) { |
| | | 349 | if (of_match_compatible(child, compatible) != 0) |
| | | 350 | return child; |
| | | 351 | ret = of_find_bycompat(child, str); |
| | | 352 | if (ret != -1) |
| | | 353 | return ret; |
| | | 354 | } |
| | | 355 | |
| | | 356 | return -1; |
| | | 357 | } |
| | | 358 | |
| | | 359 | /* |
340 | * Find a give node by name. Recurses, and seems to walk upwards too. | | 360 | * Find a give node by name. Recurses, and seems to walk upwards too. |
341 | */ | | 361 | */ |
342 | | | 362 | |
343 | int | | 363 | int |
344 | of_getnode_byname(int start, const char *target) | | 364 | of_getnode_byname(int start, const char *target) |
345 | { | | 365 | { |
346 | int node, next; | | 366 | int node, next; |
347 | char name[64]; | | 367 | char name[64]; |
348 | | | 368 | |
349 | if (start == 0) | | 369 | if (start == 0) |
350 | start = OF_peer(0); | | 370 | start = OF_peer(0); |
351 | | | 371 | |
352 | for (node = start; node; node = next) { | | 372 | for (node = start; node; node = next) { |