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) {
310 spec
->path
+= strlen("./");
312 else if (strncmp(spec
->path
, "../", strlen("../")) == 0) {
314 if (current
!= NULL
&& device_parent(current
) != NULL
)
315 current
= device_parent(current
);
316 spec
->path
+= strlen("../");
318 else if (strcmp(spec
->path
, ".") == 0) {
321 spec
->path
+= strlen(".");
323 else if (strcmp(spec
->path
, "..") == 0) {
325 if (current
!= NULL
&& device_parent(current
) != NULL
)
326 current
= device_parent(current
);
327 spec
->path
+= strlen("..");
333 /* now go through the path proper */
335 if (current
== NULL
) {
336 split_device_name(spec
);
340 while (split_device_name(spec
)) {
342 for (child
= device_child(current
);
343 child
!= NULL
; child
= device_sibling(child
)) {
344 if (strcmp(spec
->name
, device_name(child
)) == 0) {
345 if (spec
->unit
== NULL
)
349 device_decode_unit(current
, spec
->unit
, &phys
);
350 if (memcmp(&phys
, device_unit_address(child
),
351 sizeof(device_unit
)) == 0)
357 return current
; /* search failed */
367 split_fill_path(device
*current
,
368 const char *device_specifier
,
369 name_specifier
*spec
)
372 if (!split_device_specifier(current
, device_specifier
, spec
))
373 device_error(current
, "error parsing %s\n", device_specifier
);
375 /* fill our tree with its contents */
376 current
= split_find_device(current
, spec
);
378 /* add any additional devices as needed */
379 if (spec
->name
!= NULL
) {
381 current
= device_create(current
, spec
->base
, spec
->name
,
382 spec
->unit
, spec
->args
);
383 } while (split_device_name(spec
));
392 tree_init(device
*root
,
395 TRACE(trace_device_tree
, ("tree_init(root=0x%lx, system=0x%lx)\n",
398 /* remove the old, rebuild the new */
399 tree_traverse(root
, device_clean
, NULL
, system
);
400 tree_traverse(root
, device_init_static_properties
, NULL
, system
);
401 tree_traverse(root
, device_init_address
, NULL
, system
);
402 tree_traverse(root
, device_init_runtime_properties
, NULL
, system
);
403 tree_traverse(root
, device_init_data
, NULL
, system
);
408 /* <non-white-space> */
412 skip_token(const char *chp
)
414 while (!isspace(*chp
) && *chp
!= '\0')
416 while (isspace(*chp
) && *chp
!= '\0')
422 /* count the number of entries */
426 count_entries(device
*current
,
427 const char *property_name
,
428 const char *property_value
,
431 const char *chp
= property_value
;
433 while (*chp
!= '\0') {
435 chp
= skip_token(chp
);
437 if ((nr_entries
% modulo
) != 0) {
438 device_error(current
, "incorrect number of entries for %s property %s, should be multiple of %d",
439 property_name
, property_value
, modulo
);
441 return nr_entries
/ modulo
;
446 /* parse: <address> ::= <token> ; device dependant */
450 parse_address(device
*current
,
453 device_unit
*address
)
455 ASSERT(device_nr_address_cells(bus
) > 0);
456 if (device_decode_unit(bus
, chp
, address
) < 0)
457 device_error(current
, "invalid unit address in %s", chp
);
458 return skip_token(chp
);
462 /* parse: <size> ::= <number> { "," <number> } ; */
466 parse_size(device
*current
,
473 const char *curr
= chp
;
474 memset(size
, 0, sizeof(*size
));
475 /* parse the numeric list */
476 size
->nr_cells
= device_nr_size_cells(bus
);
478 ASSERT(size
->nr_cells
> 0);
481 size
->cells
[nr
] = strtoul(curr
, &next
, 0);
483 device_error(current
, "Problem parsing <size> %s", chp
);
487 if (nr
== size
->nr_cells
)
488 device_error(current
, "Too many values in <size> %s", chp
);
491 ASSERT(nr
> 0 && nr
<= size
->nr_cells
);
492 /* right align the numbers */
493 for (i
= 1; i
<= size
->nr_cells
; i
++) {
495 size
->cells
[size
->nr_cells
- i
] = size
->cells
[nr
- i
];
497 size
->cells
[size
->nr_cells
- i
] = 0;
499 return skip_token(chp
);
503 /* parse: <reg> ::= { <address> <size> } ; */
507 parse_reg_property(device
*current
,
508 const char *property_name
,
509 const char *property_value
)
513 reg_property_spec
*regs
;
515 device
*bus
= device_parent(current
);
517 /* determine the number of reg entries by counting tokens */
518 nr_regs
= count_entries(current
, property_name
, property_value
,
519 1 + (device_nr_size_cells(bus
) > 0));
521 /* create working space */
522 regs
= zalloc(nr_regs
* sizeof(*regs
));
525 chp
= property_value
;
526 for (reg_nr
= 0; reg_nr
< nr_regs
; reg_nr
++) {
527 chp
= parse_address(current
, bus
, chp
, ®s
[reg_nr
].address
);
528 if (device_nr_size_cells(bus
) > 0)
529 chp
= parse_size(current
, bus
, chp
, ®s
[reg_nr
].size
);
531 memset(®s
[reg_nr
].size
, 0, sizeof (regs
[reg_nr
].size
));
535 device_add_reg_array_property(current
, property_name
,
542 /* { <child-address> <parent-address> <child-size> }* */
546 parse_ranges_property(device
*current
,
547 const char *property_name
,
548 const char *property_value
)
552 range_property_spec
*ranges
;
555 /* determine the number of ranges specified */
556 nr_ranges
= count_entries(current
, property_name
, property_value
, 3);
558 /* create a property of that size */
559 ranges
= zalloc(nr_ranges
* sizeof(*ranges
));
562 chp
= property_value
;
563 for (range_nr
= 0; range_nr
< nr_ranges
; range_nr
++) {
564 chp
= parse_address(current
, current
,
565 chp
, &ranges
[range_nr
].child_address
);
566 chp
= parse_address(current
, device_parent(current
),
567 chp
, &ranges
[range_nr
].parent_address
);
568 chp
= parse_size(current
, current
,
569 chp
, &ranges
[range_nr
].size
);
573 device_add_range_array_property(current
, property_name
, ranges
, nr_ranges
);
583 parse_integer_property(device
*current
,
584 const char *property_name
,
585 const char *property_value
)
588 unsigned_cell words
[1024];
589 /* integer or integer array? */
593 words
[nr_entries
] = strtoul(property_value
, &end
, 0);
594 if (property_value
== end
)
597 if (nr_entries
* sizeof(words
[0]) >= sizeof(words
))
598 device_error(current
, "buffer overflow");
599 property_value
= end
;
602 device_error(current
, "error parsing integer property %s (%s)",
603 property_name
, property_value
);
604 else if (nr_entries
== 1)
605 device_add_integer_property(current
, property_name
, words
[0]);
608 for (i
= 0; i
< nr_entries
; i
++) {
611 /* perhaps integer array property is better */
612 device_add_array_property(current
, property_name
, words
,
613 sizeof(words
[0]) * nr_entries
);
617 /* PROPERTY_VALUE is a raw property value. Quote it as required by
618 parse_string_property. It is the caller's responsibility to free
619 the memory returned. */
623 tree_quote_property(const char *property_value
)
630 /* Count characters needing quotes in PROPERTY_VALUE. */
632 for (chp
= property_value
; *chp
; ++chp
)
633 if (*chp
== '\\' || *chp
== '"')
636 ret
= (char *) xmalloc (strlen (property_value
)
639 + 1 /* terminator */);
642 /* Add the opening quote. */
644 /* Copy the value. */
645 for (chp
= property_value
; *chp
; ++chp
)
646 if (*chp
== '\\' || *chp
== '"')
648 /* Quote this character. */
654 /* Add the closing quote. */
656 /* Terminate the string. */
666 parse_string_property(device
*current
,
667 const char *property_name
,
668 const char *property_value
)
673 int approx_nr_strings
;
675 /* get an estimate as to the number of strings by counting double
677 approx_nr_strings
= 2;
678 for (chp
= property_value
; *chp
; chp
++) {
682 approx_nr_strings
= (approx_nr_strings
) / 2;
684 /* create a string buffer for that many (plus a null) */
685 strings
= (char**)zalloc((approx_nr_strings
+ 1) * sizeof(char*));
687 /* now find all the strings */
688 chp
= property_value
;
692 /* skip leading space */
693 while (*chp
!= '\0' && isspace(*chp
))
700 /* a quoted string - watch for '\' et.al. */
701 /* estimate the size and allocate space for it */
705 while (chp
[pos
] != '\0' && chp
[pos
] != '"') {
706 if (chp
[pos
] == '\\' && chp
[pos
+1] != '\0')
711 strings
[nr_strings
] = zalloc(pos
+ 1);
712 /* copy the string over */
714 while (*chp
!= '\0' && *chp
!= '"') {
715 if (*chp
== '\\' && *(chp
+1) != '\0') {
716 strings
[nr_strings
][pos
] = *(chp
+1);
721 strings
[nr_strings
][pos
] = *chp
;
728 strings
[nr_strings
][pos
] = '\0';
731 /* copy over a single unquoted token */
733 while (chp
[len
] != '\0' && !isspace(chp
[len
]))
735 strings
[nr_strings
] = zalloc(len
+ 1);
736 strncpy(strings
[nr_strings
], chp
, len
);
737 strings
[nr_strings
][len
] = '\0';
741 if (nr_strings
> approx_nr_strings
)
742 device_error(current
, "String property %s badly formatted",
745 ASSERT(strings
[nr_strings
] == NULL
); /* from zalloc */
749 device_add_string_property(current
, property_name
, "");
750 else if (nr_strings
== 1)
751 device_add_string_property(current
, property_name
, strings
[0]);
753 const char **specs
= (const char**)strings
; /* stop a bogus error */
754 device_add_string_array_property(current
, property_name
,
758 /* flush the created string */
759 while (nr_strings
> 0) {
761 free(strings
[nr_strings
]);
767 /* <path-to-ihandle-device> */
771 parse_ihandle_property(device
*current
,
772 const char *property
,
775 ihandle_runtime_property_spec ihandle
;
777 /* pass the full path */
778 ihandle
.full_path
= value
;
780 /* save this ready for the ihandle create */
781 device_add_ihandle_runtime_property(current
, property
,
789 tree_parse(device
*current
,
793 char device_specifier
[1024];
796 /* format the path */
800 vsprintf(device_specifier
, fmt
, ap
);
802 if (strlen(device_specifier
) >= sizeof(device_specifier
))
803 error("device_tree_add_deviced: buffer overflow\n");
806 /* construct the tree down to the final device */
807 current
= split_fill_path(current
, device_specifier
, &spec
);
809 /* is there an interrupt spec */
810 if (spec
.property
== NULL
811 && spec
.value
!= NULL
) {
812 char *op
= split_value(&spec
);
816 char *my_port_name
= split_value(&spec
);
818 char *dest_port_name
= split_value(&spec
);
820 name_specifier dest_spec
;
821 char *dest_device_name
= split_value(&spec
);
824 my_port
= device_interrupt_decode(current
, my_port_name
,
826 /* find the dest device and port */
827 dest
= split_fill_path(current
, dest_device_name
, &dest_spec
);
828 dest_port
= device_interrupt_decode(dest
, dest_port_name
,
830 /* connect the two */
831 device_interrupt_attach(current
,
839 device_error(current
, "unreconised interrupt spec %s\n", spec
.value
);
844 /* is there a property */
845 if (spec
.property
!= NULL
) {
846 if (strcmp(spec
.value
, "true") == 0)
847 device_add_boolean_property(current
, spec
.property
, 1);
848 else if (strcmp(spec
.value
, "false") == 0)
849 device_add_boolean_property(current
, spec
.property
, 0);
851 const device_property
*property
;
852 switch (spec
.value
[0]) {
854 parse_ihandle_property(current
, spec
.property
, spec
.value
+ 1);
858 unsigned8 words
[1024];
859 char *curr
= spec
.value
+ 1;
863 words
[nr_words
] = H2BE_1(strtoul(curr
, &next
, 0));
869 device_add_array_property(current
, spec
.property
,
870 words
, sizeof(words
[0]) * nr_words
);
874 parse_string_property(current
, spec
.property
, spec
.value
);
878 property
= tree_find_property(current
, spec
.value
);
879 if (property
== NULL
)
880 device_error(current
, "property %s not found\n", spec
.value
);
881 device_add_duplicate_property(current
,
886 if (strcmp(spec
.property
, "reg") == 0
887 || strcmp(spec
.property
, "assigned-addresses") == 0
888 || strcmp(spec
.property
, "alternate-reg") == 0){
889 parse_reg_property(current
, spec
.property
, spec
.value
);
891 else if (strcmp(spec
.property
, "ranges") == 0) {
892 parse_ranges_property(current
, spec
.property
, spec
.value
);
894 else if (isdigit(spec
.value
[0])
895 || (spec
.value
[0] == '-' && isdigit(spec
.value
[1]))
896 || (spec
.value
[0] == '+' && isdigit(spec
.value
[1]))) {
897 parse_integer_property(current
, spec
.property
, spec
.value
);
900 parse_string_property(current
, spec
.property
, spec
.value
);
911 tree_traverse(device
*root
,
912 tree_traverse_function
*prefix
,
913 tree_traverse_function
*postfix
,
919 for (child
= device_child(root
);
921 child
= device_sibling(child
)) {
922 tree_traverse(child
, prefix
, postfix
, data
);
931 print_address(device
*bus
,
932 const device_unit
*phys
)
935 device_encode_unit(bus
, phys
, unit
, sizeof(unit
));
936 printf_filtered(" %s", unit
);
941 print_size(device
*bus
,
942 const device_unit
*size
)
945 for (i
= 0; i
< size
->nr_cells
; i
++)
946 if (size
->cells
[i
] != 0)
948 if (i
< size
->nr_cells
) {
949 printf_filtered(" 0x%lx", (unsigned long)size
->cells
[i
]);
951 for (; i
< size
->nr_cells
; i
++)
952 printf_filtered(",0x%lx", (unsigned long)size
->cells
[i
]);
955 printf_filtered(" 0");
960 print_reg_property(device
*me
,
961 const device_property
*property
)
964 reg_property_spec reg
;
966 device_find_reg_array_property(me
, property
->name
, reg_nr
, ®
);
968 print_address(device_parent(me
), ®
.address
);
969 print_size(me
, ®
.size
);
975 print_ranges_property(device
*me
,
976 const device_property
*property
)
979 range_property_spec range
;
981 device_find_range_array_property(me
, property
->name
, range_nr
, &range
);
983 print_address(me
, &range
.child_address
);
984 print_address(device_parent(me
), &range
.parent_address
);
985 print_size(me
, &range
.size
);
991 print_string(const char *string
)
993 printf_filtered(" \"");
994 while (*string
!= '\0') {
997 printf_filtered("\\\"");
1000 printf_filtered("\\\\");
1003 printf_filtered("%c", *string
);
1008 printf_filtered("\"");
1013 print_string_array_property(device
*me
,
1014 const device_property
*property
)
1017 string_property_spec string
;
1019 device_find_string_array_property(me
, property
->name
, nr
, &string
);
1021 print_string(string
);
1027 print_properties(device
*me
)
1029 const device_property
*property
;
1030 for (property
= device_find_property(me
, NULL
);
1032 property
= device_next_property(property
)) {
1033 printf_filtered("%s/%s", device_path(me
), property
->name
);
1034 if (property
->original
!= NULL
) {
1035 printf_filtered(" !");
1036 printf_filtered("%s/%s",
1037 device_path(property
->original
->owner
),
1038 property
->original
->name
);
1041 switch (property
->type
) {
1042 case array_property
:
1043 if ((property
->sizeof_array
% sizeof(signed_cell
)) == 0) {
1044 unsigned_cell
*w
= (unsigned_cell
*)property
->array
;
1047 cell_nr
< (property
->sizeof_array
/ sizeof(unsigned_cell
));
1049 printf_filtered(" 0x%lx", (unsigned long)BE2H_cell(w
[cell_nr
]));
1053 unsigned8
*w
= (unsigned8
*)property
->array
;
1054 printf_filtered(" [");
1055 while ((char*)w
- (char*)property
->array
< property
->sizeof_array
) {
1056 printf_filtered(" 0x%2x", BE2H_1(*w
));
1061 case boolean_property
:
1063 int b
= device_find_boolean_property(me
, property
->name
);
1064 printf_filtered(" %s", b
? "true" : "false");
1067 case ihandle_property
:
1069 if (property
->array
!= NULL
) {
1070 device_instance
*instance
= device_find_ihandle_property(me
, property
->name
);
1071 printf_filtered(" *%s", device_instance_path(instance
));
1074 /* not yet initialized, ask the device for the path */
1075 ihandle_runtime_property_spec spec
;
1076 device_find_ihandle_runtime_property(me
, property
->name
, &spec
);
1077 printf_filtered(" *%s", spec
.full_path
);
1081 case integer_property
:
1083 unsigned_word w
= device_find_integer_property(me
, property
->name
);
1084 printf_filtered(" 0x%lx", (unsigned long)w
);
1087 case range_array_property
:
1088 print_ranges_property(me
, property
);
1090 case reg_array_property
:
1091 print_reg_property(me
, property
);
1093 case string_property
:
1095 const char *s
= device_find_string_property(me
, property
->name
);
1099 case string_array_property
:
1100 print_string_array_property(me
, property
);
1104 printf_filtered("\n");
1110 print_interrupts(device
*me
,
1114 void *ignore_or_null
)
1118 device_interrupt_encode(me
, my_port
, src
, sizeof(src
), output_port
);
1119 device_interrupt_encode(dest
, dest_port
, dst
, sizeof(dst
), input_port
);
1120 printf_filtered("%s > %s %s %s\n",
1128 print_device(device
*me
,
1129 void *ignore_or_null
)
1131 printf_filtered("%s\n", device_path(me
));
1132 print_properties(me
);
1133 device_interrupt_traverse(me
, print_interrupts
, NULL
);
1138 tree_print(device
*root
)
1148 tree_usage(int verbose
)
1151 printf_filtered("\n");
1152 printf_filtered("A device/property specifier has the form:\n");
1153 printf_filtered("\n");
1154 printf_filtered(" /path/to/a/device [ property-value ]\n");
1155 printf_filtered("\n");
1156 printf_filtered("and a possible device is\n");
1157 printf_filtered("\n");
1160 printf_filtered("\n");
1161 printf_filtered("A device/property specifier (<spec>) has the format:\n");
1162 printf_filtered("\n");
1163 printf_filtered(" <spec> ::= <path> [ <value> ] ;\n");
1164 printf_filtered(" <path> ::= { <prefix> } { <node> \"/\" } <node> ;\n");
1165 printf_filtered(" <prefix> ::= ( | \"/\" | \"../\" | \"./\" ) ;\n");
1166 printf_filtered(" <node> ::= <name> [ \"@\" <unit> ] [ \":\" <args> ] ;\n");
1167 printf_filtered(" <unit> ::= <number> { \",\" <number> } ;\n");
1168 printf_filtered("\n");
1169 printf_filtered("Where:\n");
1170 printf_filtered("\n");
1171 printf_filtered(" <name> is the name of a device (list below)\n");
1172 printf_filtered(" <unit> is the unit-address relative to the parent bus\n");
1173 printf_filtered(" <args> additional arguments used when creating the device\n");
1174 printf_filtered(" <value> ::= ( <number> # integer property\n");
1175 printf_filtered(" | \"[\" { <number> } # array property (byte)\n");
1176 printf_filtered(" | \"{\" { <number> } # array property (cell)\n");
1177 printf_filtered(" | [ \"true\" | \"false\" ] # boolean property\n");
1178 printf_filtered(" | \"*\" <path> # ihandle property\n");
1179 printf_filtered(" | \"!\" <path> # copy property\n");
1180 printf_filtered(" | \">\" [ <number> ] <path> # attach interrupt\n");
1181 printf_filtered(" | \"<\" <path> # attach child interrupt\n");
1182 printf_filtered(" | \"\\\"\" <text> # string property\n");
1183 printf_filtered(" | <text> # string property\n");
1184 printf_filtered(" ) ;\n");
1185 printf_filtered("\n");
1186 printf_filtered("And the following are valid device names:\n");
1187 printf_filtered("\n");
1195 tree_instance(device
*root
,
1196 const char *device_specifier
)
1198 /* find the device node */
1200 name_specifier spec
;
1201 if (!split_device_specifier(root
, device_specifier
, &spec
))
1203 me
= split_find_device(root
, &spec
);
1204 if (spec
.name
!= NULL
)
1206 /* create the instance */
1207 return device_create_instance(me
, device_specifier
, spec
.last_args
);
1213 tree_find_device(device
*root
,
1214 const char *path_to_device
)
1217 name_specifier spec
;
1219 /* parse the path */
1220 split_device_specifier(root
, path_to_device
, &spec
);
1221 if (spec
.value
!= NULL
)
1222 return NULL
; /* something wierd */
1225 node
= split_find_device(root
, &spec
);
1226 if (spec
.name
!= NULL
)
1227 return NULL
; /* not a leaf */
1234 (const device_property
*)
1235 tree_find_property(device
*root
,
1236 const char *path_to_property
)
1238 name_specifier spec
;
1239 if (!split_property_specifier(root
, path_to_property
, &spec
))
1240 device_error(root
, "Invalid property path %s", path_to_property
);
1241 root
= split_find_device(root
, &spec
);
1242 return device_find_property(root
, spec
.property
);
1247 tree_find_boolean_property(device
*root
,
1248 const char *path_to_property
)
1250 name_specifier spec
;
1251 if (!split_property_specifier(root
, path_to_property
, &spec
))
1252 device_error(root
, "Invalid property path %s", path_to_property
);
1253 root
= split_find_device(root
, &spec
);
1254 return device_find_boolean_property(root
, spec
.property
);
1259 tree_find_integer_property(device
*root
,
1260 const char *path_to_property
)
1262 name_specifier spec
;
1263 if (!split_property_specifier(root
, path_to_property
, &spec
))
1264 device_error(root
, "Invalid property path %s", path_to_property
);
1265 root
= split_find_device(root
, &spec
);
1266 return device_find_integer_property(root
, spec
.property
);
1271 tree_find_ihandle_property(device
*root
,
1272 const char *path_to_property
)
1274 name_specifier spec
;
1275 if (!split_property_specifier(root
, path_to_property
, &spec
))
1276 device_error(root
, "Invalid property path %s", path_to_property
);
1277 root
= split_find_device(root
, &spec
);
1278 return device_find_ihandle_property(root
, spec
.property
);
1283 tree_find_string_property(device
*root
,
1284 const char *path_to_property
)
1286 name_specifier spec
;
1287 if (!split_property_specifier(root
, path_to_property
, &spec
))
1288 device_error(root
, "Invalid property path %s", path_to_property
);
1289 root
= split_find_device(root
, &spec
);
1290 return device_find_string_property(root
, spec
.property
);
1294 #endif /* _PARSE_C_ */