1 /* This file is part of the program psim.
3 Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>.
36 #include "libiberty.h"
38 /* manipulate/lookup device names */
40 typedef struct _name_specifier
{
41 /* components in the full length name */
61 /* Given a device specifier, break it up into its main components:
62 path (and if present) property name and property value. */
66 split_device_specifier(device
*current
,
67 const char *device_specifier
,
72 /* expand any leading alias if present */
74 && *device_specifier
!= '\0'
75 && *device_specifier
!= '.'
76 && *device_specifier
!= '/') {
77 device
*aliases
= tree_find_device(current
, "/aliases");
80 while (device_specifier
[len
] != '\0'
81 && device_specifier
[len
] != '/'
82 && device_specifier
[len
] != ':'
83 && !isspace(device_specifier
[len
])) {
84 alias
[len
] = device_specifier
[len
];
86 if (len
>= sizeof(alias
))
87 error("split_device_specifier: buffer overflow");
91 && device_find_property(aliases
, alias
)) {
92 strcpy(spec
->buf
, device_find_string_property(aliases
, alias
));
93 strcat(spec
->buf
, device_specifier
+ len
);
96 strcpy(spec
->buf
, device_specifier
);
100 strcpy(spec
->buf
, device_specifier
);
103 /* check no overflow */
104 if (strlen(spec
->buf
) >= sizeof(spec
->buf
))
105 error("split_device_specifier: buffer overflow\n");
107 /* strip leading spaces */
109 while (*chp
!= '\0' && isspace(*chp
))
114 /* find the path and terminate it with null */
116 while (*chp
!= '\0' && !isspace(*chp
))
124 while (*chp
!= '\0' && isspace(*chp
))
128 /* now go back and chop the property off of the path */
129 if (spec
->value
[0] == '\0') {
130 spec
->property
= NULL
; /*not a property*/
133 else if (spec
->value
[0] == '>'
134 || spec
->value
[0] == '<') {
135 /* an interrupt spec */
136 spec
->property
= NULL
;
139 chp
= strrchr(spec
->path
, '/');
141 spec
->property
= spec
->path
;
142 spec
->path
= strchr(spec
->property
, '\0');
146 spec
->property
= chp
+1;
150 /* and mark the rest as invalid */
155 spec
->last_name
= NULL
;
156 spec
->last_base
= NULL
;
157 spec
->last_unit
= NULL
;
158 spec
->last_args
= NULL
;
164 /* given a device specifier break it up into its main components -
165 path and property name - assuming that the last `device' is a
168 STATIC_INLINE_DEVICE\
170 split_property_specifier(device
*current
,
171 const char *property_specifier
,
172 name_specifier
*spec
)
174 if (split_device_specifier(current
, property_specifier
, spec
)) {
175 if (spec
->property
== NULL
) {
176 /* force the last name to be a property name */
177 char *chp
= strrchr(spec
->path
, '/');
179 spec
->property
= spec
->path
;
180 spec
->path
= strrchr(spec
->property
, '\0');;
184 spec
->property
= chp
+1;
194 /* device the next device name and split it up, return 0 when no more
199 split_device_name(name_specifier
*spec
)
202 /* remember what came before */
203 spec
->last_name
= spec
->name
;
204 spec
->last_base
= spec
->base
;
205 spec
->last_unit
= spec
->unit
;
206 spec
->last_args
= spec
->args
;
208 if (spec
->path
[0] == '\0') {
215 /* break the current device spec from the path */
216 spec
->name
= spec
->path
;
217 chp
= strchr(spec
->name
, '/');
219 spec
->path
= strchr(spec
->name
, '\0');
224 /* break out the base */
225 if (spec
->name
[0] == '(') {
226 chp
= strchr(spec
->name
, ')');
228 spec
->base
= spec
->name
;
232 spec
->base
= spec
->name
+ 1;
233 spec
->name
= chp
+ 1;
237 spec
->base
= spec
->name
;
239 /* now break out the unit */
240 chp
= strchr(spec
->name
, '@');
250 /* finally any args */
251 chp
= strchr(chp
, ':');
262 /* device the value, returning the next non-space token */
266 split_value(name_specifier
*spec
)
269 if (spec
->value
== NULL
)
271 /* skip leading white space */
272 while (isspace(spec
->value
[0]))
274 if (spec
->value
[0] == '\0') {
279 /* find trailing space */
280 while (spec
->value
[0] != '\0' && !isspace(spec
->value
[0]))
282 /* chop this value out */
283 if (spec
->value
[0] != '\0') {
284 spec
->value
[0] = '\0';
292 /* traverse the path specified by spec starting at current */
296 split_find_device(device
*current
,
297 name_specifier
*spec
)
299 /* strip off (and process) any leading ., .., ./ and / */
301 if (strncmp(spec
->path
, "/", strlen("/")) == 0) {
303 while (current
!= NULL
&& device_parent(current
) != NULL
)
304 current
= device_parent(current
);
305 spec
->path
+= strlen("/");
307 else if (strncmp(spec
->path
, "./", strlen("./")) == 0) {
309 spec
->path
+= strlen("./");
311 else if (strncmp(spec
->path
, "../", strlen("../")) == 0) {
313 if (current
!= NULL
&& device_parent(current
) != NULL
)
314 current
= device_parent(current
);
315 spec
->path
+= strlen("../");
317 else if (strcmp(spec
->path
, ".") == 0) {
319 spec
->path
+= strlen(".");
321 else if (strcmp(spec
->path
, "..") == 0) {
323 if (current
!= NULL
&& device_parent(current
) != NULL
)
324 current
= device_parent(current
);
325 spec
->path
+= strlen("..");
331 /* now go through the path proper */
333 if (current
== NULL
) {
334 split_device_name(spec
);
338 while (split_device_name(spec
)) {
340 for (child
= device_child(current
);
341 child
!= NULL
; child
= device_sibling(child
)) {
342 if (strcmp(spec
->name
, device_name(child
)) == 0) {
343 if (spec
->unit
== NULL
)
347 device_decode_unit(current
, spec
->unit
, &phys
);
348 if (memcmp(&phys
, device_unit_address(child
),
349 sizeof(device_unit
)) == 0)
355 return current
; /* search failed */
365 split_fill_path(device
*current
,
366 const char *device_specifier
,
367 name_specifier
*spec
)
370 if (!split_device_specifier(current
, device_specifier
, spec
))
371 device_error(current
, "error parsing %s\n", device_specifier
);
373 /* fill our tree with its contents */
374 current
= split_find_device(current
, spec
);
376 /* add any additional devices as needed */
377 if (spec
->name
!= NULL
) {
379 current
= device_create(current
, spec
->base
, spec
->name
,
380 spec
->unit
, spec
->args
);
381 } while (split_device_name(spec
));
390 tree_init(device
*root
,
393 TRACE(trace_device_tree
, ("tree_init(root=%p, system=%p)\n",
396 /* remove the old, rebuild the new */
397 tree_traverse(root
, device_clean
, NULL
, system
);
398 tree_traverse(root
, device_init_static_properties
, NULL
, system
);
399 tree_traverse(root
, device_init_address
, NULL
, system
);
400 tree_traverse(root
, device_init_runtime_properties
, NULL
, system
);
401 tree_traverse(root
, device_init_data
, NULL
, system
);
406 /* <non-white-space> */
410 skip_token(const char *chp
)
412 while (!isspace(*chp
) && *chp
!= '\0')
414 while (isspace(*chp
) && *chp
!= '\0')
420 /* count the number of entries */
424 count_entries(device
*current
,
425 const char *property_name
,
426 const char *property_value
,
429 const char *chp
= property_value
;
431 while (*chp
!= '\0') {
433 chp
= skip_token(chp
);
435 if ((nr_entries
% modulo
) != 0) {
436 device_error(current
, "incorrect number of entries for %s property %s, should be multiple of %d",
437 property_name
, property_value
, modulo
);
439 return nr_entries
/ modulo
;
444 /* parse: <address> ::= <token> ; device dependant */
448 parse_address(device
*current
,
451 device_unit
*address
)
453 ASSERT(device_nr_address_cells(bus
) > 0);
454 if (device_decode_unit(bus
, chp
, address
) < 0)
455 device_error(current
, "invalid unit address in %s", chp
);
456 return skip_token(chp
);
460 /* parse: <size> ::= <number> { "," <number> } ; */
464 parse_size(device
*current
,
471 const char *curr
= chp
;
472 memset(size
, 0, sizeof(*size
));
473 /* parse the numeric list */
474 size
->nr_cells
= device_nr_size_cells(bus
);
476 ASSERT(size
->nr_cells
> 0);
479 size
->cells
[nr
] = strtoul(curr
, &next
, 0);
481 device_error(current
, "Problem parsing <size> %s", chp
);
485 if (nr
== size
->nr_cells
)
486 device_error(current
, "Too many values in <size> %s", chp
);
489 ASSERT(nr
> 0 && nr
<= size
->nr_cells
);
490 /* right align the numbers */
491 for (i
= 1; i
<= size
->nr_cells
; i
++) {
493 size
->cells
[size
->nr_cells
- i
] = size
->cells
[nr
- i
];
495 size
->cells
[size
->nr_cells
- i
] = 0;
497 return skip_token(chp
);
501 /* parse: <reg> ::= { <address> <size> } ; */
505 parse_reg_property(device
*current
,
506 const char *property_name
,
507 const char *property_value
)
511 reg_property_spec
*regs
;
513 device
*bus
= device_parent(current
);
515 /* determine the number of reg entries by counting tokens */
516 nr_regs
= count_entries(current
, property_name
, property_value
,
517 1 + (device_nr_size_cells(bus
) > 0));
519 /* create working space */
520 regs
= zalloc(nr_regs
* sizeof(*regs
));
523 chp
= property_value
;
524 for (reg_nr
= 0; reg_nr
< nr_regs
; reg_nr
++) {
525 chp
= parse_address(current
, bus
, chp
, ®s
[reg_nr
].address
);
526 if (device_nr_size_cells(bus
) > 0)
527 chp
= parse_size(current
, bus
, chp
, ®s
[reg_nr
].size
);
529 memset(®s
[reg_nr
].size
, 0, sizeof (regs
[reg_nr
].size
));
533 device_add_reg_array_property(current
, property_name
,
540 /* { <child-address> <parent-address> <child-size> }* */
544 parse_ranges_property(device
*current
,
545 const char *property_name
,
546 const char *property_value
)
550 range_property_spec
*ranges
;
553 /* determine the number of ranges specified */
554 nr_ranges
= count_entries(current
, property_name
, property_value
, 3);
556 /* create a property of that size */
557 ranges
= zalloc(nr_ranges
* sizeof(*ranges
));
560 chp
= property_value
;
561 for (range_nr
= 0; range_nr
< nr_ranges
; range_nr
++) {
562 chp
= parse_address(current
, current
,
563 chp
, &ranges
[range_nr
].child_address
);
564 chp
= parse_address(current
, device_parent(current
),
565 chp
, &ranges
[range_nr
].parent_address
);
566 chp
= parse_size(current
, current
,
567 chp
, &ranges
[range_nr
].size
);
571 device_add_range_array_property(current
, property_name
, ranges
, nr_ranges
);
581 parse_integer_property(device
*current
,
582 const char *property_name
,
583 const char *property_value
)
586 unsigned_cell words
[1024];
587 /* integer or integer array? */
591 words
[nr_entries
] = strtoul(property_value
, &end
, 0);
592 if (property_value
== end
)
595 if (nr_entries
* sizeof(words
[0]) >= sizeof(words
))
596 device_error(current
, "buffer overflow");
597 property_value
= end
;
600 device_error(current
, "error parsing integer property %s (%s)",
601 property_name
, property_value
);
602 else if (nr_entries
== 1)
603 device_add_integer_property(current
, property_name
, words
[0]);
606 for (i
= 0; i
< nr_entries
; i
++) {
609 /* perhaps integer array property is better */
610 device_add_array_property(current
, property_name
, words
,
611 sizeof(words
[0]) * nr_entries
);
615 /* PROPERTY_VALUE is a raw property value. Quote it as required by
616 parse_string_property. It is the caller's responsibility to free
617 the memory returned. */
621 tree_quote_property(const char *property_value
)
628 /* Count characters needing quotes in PROPERTY_VALUE. */
630 for (chp
= property_value
; *chp
; ++chp
)
631 if (*chp
== '\\' || *chp
== '"')
634 ret
= (char *) xmalloc (strlen (property_value
)
637 + 1 /* terminator */);
640 /* Add the opening quote. */
642 /* Copy the value. */
643 for (chp
= property_value
; *chp
; ++chp
)
644 if (*chp
== '\\' || *chp
== '"')
646 /* Quote this character. */
652 /* Add the closing quote. */
654 /* Terminate the string. */
664 parse_string_property(device
*current
,
665 const char *property_name
,
666 const char *property_value
)
671 int approx_nr_strings
;
673 /* get an estimate as to the number of strings by counting double
675 approx_nr_strings
= 2;
676 for (chp
= property_value
; *chp
; chp
++) {
680 approx_nr_strings
= (approx_nr_strings
) / 2;
682 /* create a string buffer for that many (plus a null) */
683 strings
= (char**)zalloc((approx_nr_strings
+ 1) * sizeof(char*));
685 /* now find all the strings */
686 chp
= property_value
;
690 /* skip leading space */
691 while (*chp
!= '\0' && isspace(*chp
))
698 /* a quoted string - watch for '\' et.al. */
699 /* estimate the size and allocate space for it */
703 while (chp
[pos
] != '\0' && chp
[pos
] != '"') {
704 if (chp
[pos
] == '\\' && chp
[pos
+1] != '\0')
709 strings
[nr_strings
] = zalloc(pos
+ 1);
710 /* copy the string over */
712 while (*chp
!= '\0' && *chp
!= '"') {
713 if (*chp
== '\\' && *(chp
+1) != '\0') {
714 strings
[nr_strings
][pos
] = *(chp
+1);
719 strings
[nr_strings
][pos
] = *chp
;
726 strings
[nr_strings
][pos
] = '\0';
729 /* copy over a single unquoted token */
731 while (chp
[len
] != '\0' && !isspace(chp
[len
]))
733 strings
[nr_strings
] = zalloc(len
+ 1);
734 strncpy(strings
[nr_strings
], chp
, len
);
735 strings
[nr_strings
][len
] = '\0';
739 if (nr_strings
> approx_nr_strings
)
740 device_error(current
, "String property %s badly formatted",
743 ASSERT(strings
[nr_strings
] == NULL
); /* from zalloc */
747 device_add_string_property(current
, property_name
, "");
748 else if (nr_strings
== 1)
749 device_add_string_property(current
, property_name
, strings
[0]);
751 const char **specs
= (const char**)strings
; /* stop a bogus error */
752 device_add_string_array_property(current
, property_name
,
756 /* flush the created string */
757 while (nr_strings
> 0) {
759 free(strings
[nr_strings
]);
765 /* <path-to-ihandle-device> */
769 parse_ihandle_property(device
*current
,
770 const char *property
,
773 ihandle_runtime_property_spec ihandle
;
775 /* pass the full path */
776 ihandle
.full_path
= value
;
778 /* save this ready for the ihandle create */
779 device_add_ihandle_runtime_property(current
, property
,
787 tree_parse(device
*current
,
791 char device_specifier
[1024];
794 /* format the path */
798 vsprintf(device_specifier
, fmt
, ap
);
800 if (strlen(device_specifier
) >= sizeof(device_specifier
))
801 error("device_tree_add_deviced: buffer overflow\n");
804 /* construct the tree down to the final device */
805 current
= split_fill_path(current
, device_specifier
, &spec
);
807 /* is there an interrupt spec */
808 if (spec
.property
== NULL
809 && spec
.value
!= NULL
) {
810 char *op
= split_value(&spec
);
814 char *my_port_name
= split_value(&spec
);
816 char *dest_port_name
= split_value(&spec
);
818 name_specifier dest_spec
;
819 char *dest_device_name
= split_value(&spec
);
822 my_port
= device_interrupt_decode(current
, my_port_name
,
824 /* find the dest device and port */
825 dest
= split_fill_path(current
, dest_device_name
, &dest_spec
);
826 dest_port
= device_interrupt_decode(dest
, dest_port_name
,
828 /* connect the two */
829 device_interrupt_attach(current
,
837 device_error(current
, "unreconised interrupt spec %s\n", spec
.value
);
842 /* is there a property */
843 if (spec
.property
!= NULL
) {
844 if (strcmp(spec
.value
, "true") == 0)
845 device_add_boolean_property(current
, spec
.property
, 1);
846 else if (strcmp(spec
.value
, "false") == 0)
847 device_add_boolean_property(current
, spec
.property
, 0);
849 const device_property
*property
;
850 switch (spec
.value
[0]) {
852 parse_ihandle_property(current
, spec
.property
, spec
.value
+ 1);
857 char *curr
= spec
.value
+ 1;
861 words
[nr_words
] = H2BE_1(strtoul(curr
, &next
, 0));
867 device_add_array_property(current
, spec
.property
,
868 words
, sizeof(words
[0]) * nr_words
);
872 parse_string_property(current
, spec
.property
, spec
.value
);
876 property
= tree_find_property(current
, spec
.value
);
877 if (property
== NULL
)
878 device_error(current
, "property %s not found\n", spec
.value
);
879 device_add_duplicate_property(current
,
884 if (strcmp(spec
.property
, "reg") == 0
885 || strcmp(spec
.property
, "assigned-addresses") == 0
886 || strcmp(spec
.property
, "alternate-reg") == 0){
887 parse_reg_property(current
, spec
.property
, spec
.value
);
889 else if (strcmp(spec
.property
, "ranges") == 0) {
890 parse_ranges_property(current
, spec
.property
, spec
.value
);
892 else if (isdigit(spec
.value
[0])
893 || (spec
.value
[0] == '-' && isdigit(spec
.value
[1]))
894 || (spec
.value
[0] == '+' && isdigit(spec
.value
[1]))) {
895 parse_integer_property(current
, spec
.property
, spec
.value
);
898 parse_string_property(current
, spec
.property
, spec
.value
);
909 tree_traverse(device
*root
,
910 tree_traverse_function
*prefix
,
911 tree_traverse_function
*postfix
,
917 for (child
= device_child(root
);
919 child
= device_sibling(child
)) {
920 tree_traverse(child
, prefix
, postfix
, data
);
929 print_address(device
*bus
,
930 const device_unit
*phys
)
933 device_encode_unit(bus
, phys
, unit
, sizeof(unit
));
934 printf_filtered(" %s", unit
);
939 print_size(device
*bus
,
940 const device_unit
*size
)
943 for (i
= 0; i
< size
->nr_cells
; i
++)
944 if (size
->cells
[i
] != 0)
946 if (i
< size
->nr_cells
) {
947 printf_filtered(" 0x%lx", (unsigned long)size
->cells
[i
]);
949 for (; i
< size
->nr_cells
; i
++)
950 printf_filtered(",0x%lx", (unsigned long)size
->cells
[i
]);
953 printf_filtered(" 0");
958 print_reg_property(device
*me
,
959 const device_property
*property
)
962 reg_property_spec reg
;
964 device_find_reg_array_property(me
, property
->name
, reg_nr
, ®
);
966 print_address(device_parent(me
), ®
.address
);
967 print_size(me
, ®
.size
);
973 print_ranges_property(device
*me
,
974 const device_property
*property
)
977 range_property_spec range
;
979 device_find_range_array_property(me
, property
->name
, range_nr
, &range
);
981 print_address(me
, &range
.child_address
);
982 print_address(device_parent(me
), &range
.parent_address
);
983 print_size(me
, &range
.size
);
989 print_string(const char *string
)
991 printf_filtered(" \"");
992 while (*string
!= '\0') {
995 printf_filtered("\\\"");
998 printf_filtered("\\\\");
1001 printf_filtered("%c", *string
);
1006 printf_filtered("\"");
1011 print_string_array_property(device
*me
,
1012 const device_property
*property
)
1015 string_property_spec string
;
1017 device_find_string_array_property(me
, property
->name
, nr
, &string
);
1019 print_string(string
);
1025 print_properties(device
*me
)
1027 const device_property
*property
;
1028 for (property
= device_find_property(me
, NULL
);
1030 property
= device_next_property(property
)) {
1031 printf_filtered("%s/%s", device_path(me
), property
->name
);
1032 if (property
->original
!= NULL
) {
1033 printf_filtered(" !");
1034 printf_filtered("%s/%s",
1035 device_path(property
->original
->owner
),
1036 property
->original
->name
);
1039 switch (property
->type
) {
1040 case array_property
:
1041 if ((property
->sizeof_array
% sizeof(signed_cell
)) == 0) {
1042 unsigned_cell
*w
= (unsigned_cell
*)property
->array
;
1045 cell_nr
< (property
->sizeof_array
/ sizeof(unsigned_cell
));
1047 printf_filtered(" 0x%lx", (unsigned long)BE2H_cell(w
[cell_nr
]));
1051 uint8_t *w
= (uint8_t*)property
->array
;
1052 printf_filtered(" [");
1053 while ((char*)w
- (char*)property
->array
< property
->sizeof_array
) {
1054 printf_filtered(" 0x%2x", BE2H_1(*w
));
1059 case boolean_property
:
1061 int b
= device_find_boolean_property(me
, property
->name
);
1062 printf_filtered(" %s", b
? "true" : "false");
1065 case ihandle_property
:
1067 if (property
->array
!= NULL
) {
1068 device_instance
*instance
= device_find_ihandle_property(me
, property
->name
);
1069 printf_filtered(" *%s", device_instance_path(instance
));
1072 /* not yet initialized, ask the device for the path */
1073 ihandle_runtime_property_spec spec
;
1074 device_find_ihandle_runtime_property(me
, property
->name
, &spec
);
1075 printf_filtered(" *%s", spec
.full_path
);
1079 case integer_property
:
1081 unsigned_word w
= device_find_integer_property(me
, property
->name
);
1082 printf_filtered(" 0x%lx", (unsigned long)w
);
1085 case range_array_property
:
1086 print_ranges_property(me
, property
);
1088 case reg_array_property
:
1089 print_reg_property(me
, property
);
1091 case string_property
:
1093 const char *s
= device_find_string_property(me
, property
->name
);
1097 case string_array_property
:
1098 print_string_array_property(me
, property
);
1102 printf_filtered("\n");
1108 print_interrupts(device
*me
,
1112 void *ignore_or_null
)
1116 device_interrupt_encode(me
, my_port
, src
, sizeof(src
), output_port
);
1117 device_interrupt_encode(dest
, dest_port
, dst
, sizeof(dst
), input_port
);
1118 printf_filtered("%s > %s %s %s\n",
1126 print_device(device
*me
,
1127 void *ignore_or_null
)
1129 printf_filtered("%s\n", device_path(me
));
1130 print_properties(me
);
1131 device_interrupt_traverse(me
, print_interrupts
, NULL
);
1136 tree_print(device
*root
)
1146 tree_usage(int verbose
)
1149 printf_filtered("\n");
1150 printf_filtered("A device/property specifier has the form:\n");
1151 printf_filtered("\n");
1152 printf_filtered(" /path/to/a/device [ property-value ]\n");
1153 printf_filtered("\n");
1154 printf_filtered("and a possible device is\n");
1155 printf_filtered("\n");
1158 printf_filtered("\n");
1159 printf_filtered("A device/property specifier (<spec>) has the format:\n");
1160 printf_filtered("\n");
1161 printf_filtered(" <spec> ::= <path> [ <value> ] ;\n");
1162 printf_filtered(" <path> ::= { <prefix> } { <node> \"/\" } <node> ;\n");
1163 printf_filtered(" <prefix> ::= ( | \"/\" | \"../\" | \"./\" ) ;\n");
1164 printf_filtered(" <node> ::= <name> [ \"@\" <unit> ] [ \":\" <args> ] ;\n");
1165 printf_filtered(" <unit> ::= <number> { \",\" <number> } ;\n");
1166 printf_filtered("\n");
1167 printf_filtered("Where:\n");
1168 printf_filtered("\n");
1169 printf_filtered(" <name> is the name of a device (list below)\n");
1170 printf_filtered(" <unit> is the unit-address relative to the parent bus\n");
1171 printf_filtered(" <args> additional arguments used when creating the device\n");
1172 printf_filtered(" <value> ::= ( <number> # integer property\n");
1173 printf_filtered(" | \"[\" { <number> } # array property (byte)\n");
1174 printf_filtered(" | \"{\" { <number> } # array property (cell)\n");
1175 printf_filtered(" | [ \"true\" | \"false\" ] # boolean property\n");
1176 printf_filtered(" | \"*\" <path> # ihandle property\n");
1177 printf_filtered(" | \"!\" <path> # copy property\n");
1178 printf_filtered(" | \">\" [ <number> ] <path> # attach interrupt\n");
1179 printf_filtered(" | \"<\" <path> # attach child interrupt\n");
1180 printf_filtered(" | \"\\\"\" <text> # string property\n");
1181 printf_filtered(" | <text> # string property\n");
1182 printf_filtered(" ) ;\n");
1183 printf_filtered("\n");
1184 printf_filtered("And the following are valid device names:\n");
1185 printf_filtered("\n");
1193 tree_instance(device
*root
,
1194 const char *device_specifier
)
1196 /* find the device node */
1198 name_specifier spec
;
1199 if (!split_device_specifier(root
, device_specifier
, &spec
))
1201 me
= split_find_device(root
, &spec
);
1202 if (spec
.name
!= NULL
)
1204 /* create the instance */
1205 return device_create_instance(me
, device_specifier
, spec
.last_args
);
1211 tree_find_device(device
*root
,
1212 const char *path_to_device
)
1215 name_specifier spec
;
1217 /* parse the path */
1218 split_device_specifier(root
, path_to_device
, &spec
);
1219 if (spec
.value
!= NULL
)
1220 return NULL
; /* something wierd */
1223 node
= split_find_device(root
, &spec
);
1224 if (spec
.name
!= NULL
)
1225 return NULL
; /* not a leaf */
1232 (const device_property
*)
1233 tree_find_property(device
*root
,
1234 const char *path_to_property
)
1236 name_specifier spec
;
1237 if (!split_property_specifier(root
, path_to_property
, &spec
))
1238 device_error(root
, "Invalid property path %s", path_to_property
);
1239 root
= split_find_device(root
, &spec
);
1240 return device_find_property(root
, spec
.property
);
1245 tree_find_boolean_property(device
*root
,
1246 const char *path_to_property
)
1248 name_specifier spec
;
1249 if (!split_property_specifier(root
, path_to_property
, &spec
))
1250 device_error(root
, "Invalid property path %s", path_to_property
);
1251 root
= split_find_device(root
, &spec
);
1252 return device_find_boolean_property(root
, spec
.property
);
1257 tree_find_integer_property(device
*root
,
1258 const char *path_to_property
)
1260 name_specifier spec
;
1261 if (!split_property_specifier(root
, path_to_property
, &spec
))
1262 device_error(root
, "Invalid property path %s", path_to_property
);
1263 root
= split_find_device(root
, &spec
);
1264 return device_find_integer_property(root
, spec
.property
);
1269 tree_find_ihandle_property(device
*root
,
1270 const char *path_to_property
)
1272 name_specifier spec
;
1273 if (!split_property_specifier(root
, path_to_property
, &spec
))
1274 device_error(root
, "Invalid property path %s", path_to_property
);
1275 root
= split_find_device(root
, &spec
);
1276 return device_find_ihandle_property(root
, spec
.property
);
1281 tree_find_string_property(device
*root
,
1282 const char *path_to_property
)
1284 name_specifier spec
;
1285 if (!split_property_specifier(root
, path_to_property
, &spec
))
1286 device_error(root
, "Invalid property path %s", path_to_property
);
1287 root
= split_find_device(root
, &spec
);
1288 return device_find_string_property(root
, spec
.property
);
1292 #endif /* _PARSE_C_ */