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/>.
47 #include "libiberty.h"
49 /* manipulate/lookup device names */
51 typedef struct _name_specifier
{
52 /* components in the full length name */
72 /* Given a device specifier, break it up into its main components:
73 path (and if present) property name and property value. */
77 split_device_specifier(device
*current
,
78 const char *device_specifier
,
83 /* expand any leading alias if present */
85 && *device_specifier
!= '\0'
86 && *device_specifier
!= '.'
87 && *device_specifier
!= '/') {
88 device
*aliases
= tree_find_device(current
, "/aliases");
91 while (device_specifier
[len
] != '\0'
92 && device_specifier
[len
] != '/'
93 && device_specifier
[len
] != ':'
94 && !isspace(device_specifier
[len
])) {
95 alias
[len
] = device_specifier
[len
];
97 if (len
>= sizeof(alias
))
98 error("split_device_specifier: buffer overflow");
102 && device_find_property(aliases
, alias
)) {
103 strcpy(spec
->buf
, device_find_string_property(aliases
, alias
));
104 strcat(spec
->buf
, device_specifier
+ len
);
107 strcpy(spec
->buf
, device_specifier
);
111 strcpy(spec
->buf
, device_specifier
);
114 /* check no overflow */
115 if (strlen(spec
->buf
) >= sizeof(spec
->buf
))
116 error("split_device_specifier: buffer overflow\n");
118 /* strip leading spaces */
120 while (*chp
!= '\0' && isspace(*chp
))
125 /* find the path and terminate it with null */
127 while (*chp
!= '\0' && !isspace(*chp
))
135 while (*chp
!= '\0' && isspace(*chp
))
139 /* now go back and chop the property off of the path */
140 if (spec
->value
[0] == '\0') {
141 spec
->property
= NULL
; /*not a property*/
144 else if (spec
->value
[0] == '>'
145 || spec
->value
[0] == '<') {
146 /* an interrupt spec */
147 spec
->property
= NULL
;
150 chp
= strrchr(spec
->path
, '/');
152 spec
->property
= spec
->path
;
153 spec
->path
= strchr(spec
->property
, '\0');
157 spec
->property
= chp
+1;
161 /* and mark the rest as invalid */
166 spec
->last_name
= NULL
;
167 spec
->last_base
= NULL
;
168 spec
->last_unit
= NULL
;
169 spec
->last_args
= NULL
;
175 /* given a device specifier break it up into its main components -
176 path and property name - assuming that the last `device' is a
179 STATIC_INLINE_DEVICE\
181 split_property_specifier(device
*current
,
182 const char *property_specifier
,
183 name_specifier
*spec
)
185 if (split_device_specifier(current
, property_specifier
, spec
)) {
186 if (spec
->property
== NULL
) {
187 /* force the last name to be a property name */
188 char *chp
= strrchr(spec
->path
, '/');
190 spec
->property
= spec
->path
;
191 spec
->path
= strrchr(spec
->property
, '\0');;
195 spec
->property
= chp
+1;
205 /* device the next device name and split it up, return 0 when no more
210 split_device_name(name_specifier
*spec
)
213 /* remember what came before */
214 spec
->last_name
= spec
->name
;
215 spec
->last_base
= spec
->base
;
216 spec
->last_unit
= spec
->unit
;
217 spec
->last_args
= spec
->args
;
219 if (spec
->path
[0] == '\0') {
226 /* break the current device spec from the path */
227 spec
->name
= spec
->path
;
228 chp
= strchr(spec
->name
, '/');
230 spec
->path
= strchr(spec
->name
, '\0');
235 /* break out the base */
236 if (spec
->name
[0] == '(') {
237 chp
= strchr(spec
->name
, ')');
239 spec
->base
= spec
->name
;
243 spec
->base
= spec
->name
+ 1;
244 spec
->name
= chp
+ 1;
248 spec
->base
= spec
->name
;
250 /* now break out the unit */
251 chp
= strchr(spec
->name
, '@');
261 /* finally any args */
262 chp
= strchr(chp
, ':');
273 /* device the value, returning the next non-space token */
277 split_value(name_specifier
*spec
)
280 if (spec
->value
== NULL
)
282 /* skip leading white space */
283 while (isspace(spec
->value
[0]))
285 if (spec
->value
[0] == '\0') {
290 /* find trailing space */
291 while (spec
->value
[0] != '\0' && !isspace(spec
->value
[0]))
293 /* chop this value out */
294 if (spec
->value
[0] != '\0') {
295 spec
->value
[0] = '\0';
303 /* traverse the path specified by spec starting at current */
307 split_find_device(device
*current
,
308 name_specifier
*spec
)
310 /* strip off (and process) any leading ., .., ./ and / */
312 if (strncmp(spec
->path
, "/", strlen("/")) == 0) {
314 while (current
!= NULL
&& device_parent(current
) != NULL
)
315 current
= device_parent(current
);
316 spec
->path
+= strlen("/");
318 else if (strncmp(spec
->path
, "./", strlen("./")) == 0) {
321 spec
->path
+= strlen("./");
323 else if (strncmp(spec
->path
, "../", strlen("../")) == 0) {
325 if (current
!= NULL
&& device_parent(current
) != NULL
)
326 current
= device_parent(current
);
327 spec
->path
+= strlen("../");
329 else if (strcmp(spec
->path
, ".") == 0) {
332 spec
->path
+= strlen(".");
334 else if (strcmp(spec
->path
, "..") == 0) {
336 if (current
!= NULL
&& device_parent(current
) != NULL
)
337 current
= device_parent(current
);
338 spec
->path
+= strlen("..");
344 /* now go through the path proper */
346 if (current
== NULL
) {
347 split_device_name(spec
);
351 while (split_device_name(spec
)) {
353 for (child
= device_child(current
);
354 child
!= NULL
; child
= device_sibling(child
)) {
355 if (strcmp(spec
->name
, device_name(child
)) == 0) {
356 if (spec
->unit
== NULL
)
360 device_decode_unit(current
, spec
->unit
, &phys
);
361 if (memcmp(&phys
, device_unit_address(child
),
362 sizeof(device_unit
)) == 0)
368 return current
; /* search failed */
378 split_fill_path(device
*current
,
379 const char *device_specifier
,
380 name_specifier
*spec
)
383 if (!split_device_specifier(current
, device_specifier
, spec
))
384 device_error(current
, "error parsing %s\n", device_specifier
);
386 /* fill our tree with its contents */
387 current
= split_find_device(current
, spec
);
389 /* add any additional devices as needed */
390 if (spec
->name
!= NULL
) {
392 current
= device_create(current
, spec
->base
, spec
->name
,
393 spec
->unit
, spec
->args
);
394 } while (split_device_name(spec
));
403 tree_init(device
*root
,
406 TRACE(trace_device_tree
, ("tree_init(root=0x%lx, system=0x%lx)\n",
409 /* remove the old, rebuild the new */
410 tree_traverse(root
, device_clean
, NULL
, system
);
411 tree_traverse(root
, device_init_static_properties
, NULL
, system
);
412 tree_traverse(root
, device_init_address
, NULL
, system
);
413 tree_traverse(root
, device_init_runtime_properties
, NULL
, system
);
414 tree_traverse(root
, device_init_data
, NULL
, system
);
419 /* <non-white-space> */
423 skip_token(const char *chp
)
425 while (!isspace(*chp
) && *chp
!= '\0')
427 while (isspace(*chp
) && *chp
!= '\0')
433 /* count the number of entries */
437 count_entries(device
*current
,
438 const char *property_name
,
439 const char *property_value
,
442 const char *chp
= property_value
;
444 while (*chp
!= '\0') {
446 chp
= skip_token(chp
);
448 if ((nr_entries
% modulo
) != 0) {
449 device_error(current
, "incorrect number of entries for %s property %s, should be multiple of %d",
450 property_name
, property_value
, modulo
);
452 return nr_entries
/ modulo
;
457 /* parse: <address> ::= <token> ; device dependant */
461 parse_address(device
*current
,
464 device_unit
*address
)
466 ASSERT(device_nr_address_cells(bus
) > 0);
467 if (device_decode_unit(bus
, chp
, address
) < 0)
468 device_error(current
, "invalid unit address in %s", chp
);
469 return skip_token(chp
);
473 /* parse: <size> ::= <number> { "," <number> } ; */
477 parse_size(device
*current
,
484 const char *curr
= chp
;
485 memset(size
, 0, sizeof(*size
));
486 /* parse the numeric list */
487 size
->nr_cells
= device_nr_size_cells(bus
);
489 ASSERT(size
->nr_cells
> 0);
492 size
->cells
[nr
] = strtoul(curr
, &next
, 0);
494 device_error(current
, "Problem parsing <size> %s", chp
);
498 if (nr
== size
->nr_cells
)
499 device_error(current
, "Too many values in <size> %s", chp
);
502 ASSERT(nr
> 0 && nr
<= size
->nr_cells
);
503 /* right align the numbers */
504 for (i
= 1; i
<= size
->nr_cells
; i
++) {
506 size
->cells
[size
->nr_cells
- i
] = size
->cells
[nr
- i
];
508 size
->cells
[size
->nr_cells
- i
] = 0;
510 return skip_token(chp
);
514 /* parse: <reg> ::= { <address> <size> } ; */
518 parse_reg_property(device
*current
,
519 const char *property_name
,
520 const char *property_value
)
524 reg_property_spec
*regs
;
526 device
*bus
= device_parent(current
);
528 /* determine the number of reg entries by counting tokens */
529 nr_regs
= count_entries(current
, property_name
, property_value
,
530 1 + (device_nr_size_cells(bus
) > 0));
532 /* create working space */
533 regs
= zalloc(nr_regs
* sizeof(*regs
));
536 chp
= property_value
;
537 for (reg_nr
= 0; reg_nr
< nr_regs
; reg_nr
++) {
538 chp
= parse_address(current
, bus
, chp
, ®s
[reg_nr
].address
);
539 if (device_nr_size_cells(bus
) > 0)
540 chp
= parse_size(current
, bus
, chp
, ®s
[reg_nr
].size
);
542 memset(®s
[reg_nr
].size
, 0, sizeof (®s
[reg_nr
].size
));
546 device_add_reg_array_property(current
, property_name
,
553 /* { <child-address> <parent-address> <child-size> }* */
557 parse_ranges_property(device
*current
,
558 const char *property_name
,
559 const char *property_value
)
563 range_property_spec
*ranges
;
566 /* determine the number of ranges specified */
567 nr_ranges
= count_entries(current
, property_name
, property_value
, 3);
569 /* create a property of that size */
570 ranges
= zalloc(nr_ranges
* sizeof(*ranges
));
573 chp
= property_value
;
574 for (range_nr
= 0; range_nr
< nr_ranges
; range_nr
++) {
575 chp
= parse_address(current
, current
,
576 chp
, &ranges
[range_nr
].child_address
);
577 chp
= parse_address(current
, device_parent(current
),
578 chp
, &ranges
[range_nr
].parent_address
);
579 chp
= parse_size(current
, current
,
580 chp
, &ranges
[range_nr
].size
);
584 device_add_range_array_property(current
, property_name
, ranges
, nr_ranges
);
594 parse_integer_property(device
*current
,
595 const char *property_name
,
596 const char *property_value
)
599 unsigned_cell words
[1024];
600 /* integer or integer array? */
604 words
[nr_entries
] = strtoul(property_value
, &end
, 0);
605 if (property_value
== end
)
608 if (nr_entries
* sizeof(words
[0]) >= sizeof(words
))
609 device_error(current
, "buffer overflow");
610 property_value
= end
;
613 device_error(current
, "error parsing integer property %s (%s)",
614 property_name
, property_value
);
615 else if (nr_entries
== 1)
616 device_add_integer_property(current
, property_name
, words
[0]);
619 for (i
= 0; i
< nr_entries
; i
++) {
622 /* perhaps integer array property is better */
623 device_add_array_property(current
, property_name
, words
,
624 sizeof(words
[0]) * nr_entries
);
628 /* PROPERTY_VALUE is a raw property value. Quote it as required by
629 parse_string_property. It is the caller's responsibility to free
630 the memory returned. */
634 tree_quote_property(const char *property_value
)
641 /* Count characters needing quotes in PROPERTY_VALUE. */
643 for (chp
= property_value
; *chp
; ++chp
)
644 if (*chp
== '\\' || *chp
== '"')
647 ret
= (char *) xmalloc (strlen (property_value
)
650 + 1 /* terminator */);
653 /* Add the opening quote. */
655 /* Copy the value. */
656 for (chp
= property_value
; *chp
; ++chp
)
657 if (*chp
== '\\' || *chp
== '"')
659 /* Quote this character. */
665 /* Add the closing quote. */
667 /* Terminate the string. */
677 parse_string_property(device
*current
,
678 const char *property_name
,
679 const char *property_value
)
684 int approx_nr_strings
;
686 /* get an estimate as to the number of strings by counting double
688 approx_nr_strings
= 2;
689 for (chp
= property_value
; *chp
; chp
++) {
693 approx_nr_strings
= (approx_nr_strings
) / 2;
695 /* create a string buffer for that many (plus a null) */
696 strings
= (char**)zalloc((approx_nr_strings
+ 1) * sizeof(char*));
698 /* now find all the strings */
699 chp
= property_value
;
703 /* skip leading space */
704 while (*chp
!= '\0' && isspace(*chp
))
711 /* a quoted string - watch for '\' et.al. */
712 /* estimate the size and allocate space for it */
716 while (chp
[pos
] != '\0' && chp
[pos
] != '"') {
717 if (chp
[pos
] == '\\' && chp
[pos
+1] != '\0')
722 strings
[nr_strings
] = zalloc(pos
+ 1);
723 /* copy the string over */
725 while (*chp
!= '\0' && *chp
!= '"') {
726 if (*chp
== '\\' && *(chp
+1) != '\0') {
727 strings
[nr_strings
][pos
] = *(chp
+1);
732 strings
[nr_strings
][pos
] = *chp
;
739 strings
[nr_strings
][pos
] = '\0';
742 /* copy over a single unquoted token */
744 while (chp
[len
] != '\0' && !isspace(chp
[len
]))
746 strings
[nr_strings
] = zalloc(len
+ 1);
747 strncpy(strings
[nr_strings
], chp
, len
);
748 strings
[nr_strings
][len
] = '\0';
752 if (nr_strings
> approx_nr_strings
)
753 device_error(current
, "String property %s badly formatted",
756 ASSERT(strings
[nr_strings
] == NULL
); /* from zalloc */
760 device_add_string_property(current
, property_name
, "");
761 else if (nr_strings
== 1)
762 device_add_string_property(current
, property_name
, strings
[0]);
764 const char **specs
= (const char**)strings
; /* stop a bogus error */
765 device_add_string_array_property(current
, property_name
,
769 /* flush the created string */
770 while (nr_strings
> 0) {
772 free(strings
[nr_strings
]);
778 /* <path-to-ihandle-device> */
782 parse_ihandle_property(device
*current
,
783 const char *property
,
786 ihandle_runtime_property_spec ihandle
;
788 /* pass the full path */
789 ihandle
.full_path
= value
;
791 /* save this ready for the ihandle create */
792 device_add_ihandle_runtime_property(current
, property
,
800 tree_parse(device
*current
,
804 char device_specifier
[1024];
807 /* format the path */
811 vsprintf(device_specifier
, fmt
, ap
);
813 if (strlen(device_specifier
) >= sizeof(device_specifier
))
814 error("device_tree_add_deviced: buffer overflow\n");
817 /* construct the tree down to the final device */
818 current
= split_fill_path(current
, device_specifier
, &spec
);
820 /* is there an interrupt spec */
821 if (spec
.property
== NULL
822 && spec
.value
!= NULL
) {
823 char *op
= split_value(&spec
);
827 char *my_port_name
= split_value(&spec
);
829 char *dest_port_name
= split_value(&spec
);
831 name_specifier dest_spec
;
832 char *dest_device_name
= split_value(&spec
);
835 my_port
= device_interrupt_decode(current
, my_port_name
,
837 /* find the dest device and port */
838 dest
= split_fill_path(current
, dest_device_name
, &dest_spec
);
839 dest_port
= device_interrupt_decode(dest
, dest_port_name
,
841 /* connect the two */
842 device_interrupt_attach(current
,
850 device_error(current
, "unreconised interrupt spec %s\n", spec
.value
);
855 /* is there a property */
856 if (spec
.property
!= NULL
) {
857 if (strcmp(spec
.value
, "true") == 0)
858 device_add_boolean_property(current
, spec
.property
, 1);
859 else if (strcmp(spec
.value
, "false") == 0)
860 device_add_boolean_property(current
, spec
.property
, 0);
862 const device_property
*property
;
863 switch (spec
.value
[0]) {
865 parse_ihandle_property(current
, spec
.property
, spec
.value
+ 1);
869 unsigned8 words
[1024];
870 char *curr
= spec
.value
+ 1;
874 words
[nr_words
] = H2BE_1(strtoul(curr
, &next
, 0));
880 device_add_array_property(current
, spec
.property
,
881 words
, sizeof(words
[0]) * nr_words
);
885 parse_string_property(current
, spec
.property
, spec
.value
);
889 property
= tree_find_property(current
, spec
.value
);
890 if (property
== NULL
)
891 device_error(current
, "property %s not found\n", spec
.value
);
892 device_add_duplicate_property(current
,
897 if (strcmp(spec
.property
, "reg") == 0
898 || strcmp(spec
.property
, "assigned-addresses") == 0
899 || strcmp(spec
.property
, "alternate-reg") == 0){
900 parse_reg_property(current
, spec
.property
, spec
.value
);
902 else if (strcmp(spec
.property
, "ranges") == 0) {
903 parse_ranges_property(current
, spec
.property
, spec
.value
);
905 else if (isdigit(spec
.value
[0])
906 || (spec
.value
[0] == '-' && isdigit(spec
.value
[1]))
907 || (spec
.value
[0] == '+' && isdigit(spec
.value
[1]))) {
908 parse_integer_property(current
, spec
.property
, spec
.value
);
911 parse_string_property(current
, spec
.property
, spec
.value
);
922 tree_traverse(device
*root
,
923 tree_traverse_function
*prefix
,
924 tree_traverse_function
*postfix
,
930 for (child
= device_child(root
);
932 child
= device_sibling(child
)) {
933 tree_traverse(child
, prefix
, postfix
, data
);
942 print_address(device
*bus
,
943 const device_unit
*phys
)
946 device_encode_unit(bus
, phys
, unit
, sizeof(unit
));
947 printf_filtered(" %s", unit
);
952 print_size(device
*bus
,
953 const device_unit
*size
)
956 for (i
= 0; i
< size
->nr_cells
; i
++)
957 if (size
->cells
[i
] != 0)
959 if (i
< size
->nr_cells
) {
960 printf_filtered(" 0x%lx", (unsigned long)size
->cells
[i
]);
962 for (; i
< size
->nr_cells
; i
++)
963 printf_filtered(",0x%lx", (unsigned long)size
->cells
[i
]);
966 printf_filtered(" 0");
971 print_reg_property(device
*me
,
972 const device_property
*property
)
975 reg_property_spec reg
;
977 device_find_reg_array_property(me
, property
->name
, reg_nr
, ®
);
979 print_address(device_parent(me
), ®
.address
);
980 print_size(me
, ®
.size
);
986 print_ranges_property(device
*me
,
987 const device_property
*property
)
990 range_property_spec range
;
992 device_find_range_array_property(me
, property
->name
, range_nr
, &range
);
994 print_address(me
, &range
.child_address
);
995 print_address(device_parent(me
), &range
.parent_address
);
996 print_size(me
, &range
.size
);
1002 print_string(const char *string
)
1004 printf_filtered(" \"");
1005 while (*string
!= '\0') {
1008 printf_filtered("\\\"");
1011 printf_filtered("\\\\");
1014 printf_filtered("%c", *string
);
1019 printf_filtered("\"");
1024 print_string_array_property(device
*me
,
1025 const device_property
*property
)
1028 string_property_spec string
;
1030 device_find_string_array_property(me
, property
->name
, nr
, &string
);
1032 print_string(string
);
1038 print_properties(device
*me
)
1040 const device_property
*property
;
1041 for (property
= device_find_property(me
, NULL
);
1043 property
= device_next_property(property
)) {
1044 printf_filtered("%s/%s", device_path(me
), property
->name
);
1045 if (property
->original
!= NULL
) {
1046 printf_filtered(" !");
1047 printf_filtered("%s/%s",
1048 device_path(property
->original
->owner
),
1049 property
->original
->name
);
1052 switch (property
->type
) {
1053 case array_property
:
1054 if ((property
->sizeof_array
% sizeof(signed_cell
)) == 0) {
1055 unsigned_cell
*w
= (unsigned_cell
*)property
->array
;
1058 cell_nr
< (property
->sizeof_array
/ sizeof(unsigned_cell
));
1060 printf_filtered(" 0x%lx", (unsigned long)BE2H_cell(w
[cell_nr
]));
1064 unsigned8
*w
= (unsigned8
*)property
->array
;
1065 printf_filtered(" [");
1066 while ((char*)w
- (char*)property
->array
< property
->sizeof_array
) {
1067 printf_filtered(" 0x%2x", BE2H_1(*w
));
1072 case boolean_property
:
1074 int b
= device_find_boolean_property(me
, property
->name
);
1075 printf_filtered(" %s", b
? "true" : "false");
1078 case ihandle_property
:
1080 if (property
->array
!= NULL
) {
1081 device_instance
*instance
= device_find_ihandle_property(me
, property
->name
);
1082 printf_filtered(" *%s", device_instance_path(instance
));
1085 /* not yet initialized, ask the device for the path */
1086 ihandle_runtime_property_spec spec
;
1087 device_find_ihandle_runtime_property(me
, property
->name
, &spec
);
1088 printf_filtered(" *%s", spec
.full_path
);
1092 case integer_property
:
1094 unsigned_word w
= device_find_integer_property(me
, property
->name
);
1095 printf_filtered(" 0x%lx", (unsigned long)w
);
1098 case range_array_property
:
1099 print_ranges_property(me
, property
);
1101 case reg_array_property
:
1102 print_reg_property(me
, property
);
1104 case string_property
:
1106 const char *s
= device_find_string_property(me
, property
->name
);
1110 case string_array_property
:
1111 print_string_array_property(me
, property
);
1115 printf_filtered("\n");
1121 print_interrupts(device
*me
,
1125 void *ignore_or_null
)
1129 device_interrupt_encode(me
, my_port
, src
, sizeof(src
), output_port
);
1130 device_interrupt_encode(dest
, dest_port
, dst
, sizeof(dst
), input_port
);
1131 printf_filtered("%s > %s %s %s\n",
1139 print_device(device
*me
,
1140 void *ignore_or_null
)
1142 printf_filtered("%s\n", device_path(me
));
1143 print_properties(me
);
1144 device_interrupt_traverse(me
, print_interrupts
, NULL
);
1149 tree_print(device
*root
)
1159 tree_usage(int verbose
)
1162 printf_filtered("\n");
1163 printf_filtered("A device/property specifier has the form:\n");
1164 printf_filtered("\n");
1165 printf_filtered(" /path/to/a/device [ property-value ]\n");
1166 printf_filtered("\n");
1167 printf_filtered("and a possible device is\n");
1168 printf_filtered("\n");
1171 printf_filtered("\n");
1172 printf_filtered("A device/property specifier (<spec>) has the format:\n");
1173 printf_filtered("\n");
1174 printf_filtered(" <spec> ::= <path> [ <value> ] ;\n");
1175 printf_filtered(" <path> ::= { <prefix> } { <node> \"/\" } <node> ;\n");
1176 printf_filtered(" <prefix> ::= ( | \"/\" | \"../\" | \"./\" ) ;\n");
1177 printf_filtered(" <node> ::= <name> [ \"@\" <unit> ] [ \":\" <args> ] ;\n");
1178 printf_filtered(" <unit> ::= <number> { \",\" <number> } ;\n");
1179 printf_filtered("\n");
1180 printf_filtered("Where:\n");
1181 printf_filtered("\n");
1182 printf_filtered(" <name> is the name of a device (list below)\n");
1183 printf_filtered(" <unit> is the unit-address relative to the parent bus\n");
1184 printf_filtered(" <args> additional arguments used when creating the device\n");
1185 printf_filtered(" <value> ::= ( <number> # integer property\n");
1186 printf_filtered(" | \"[\" { <number> } # array property (byte)\n");
1187 printf_filtered(" | \"{\" { <number> } # array property (cell)\n");
1188 printf_filtered(" | [ \"true\" | \"false\" ] # boolean property\n");
1189 printf_filtered(" | \"*\" <path> # ihandle property\n");
1190 printf_filtered(" | \"!\" <path> # copy property\n");
1191 printf_filtered(" | \">\" [ <number> ] <path> # attach interrupt\n");
1192 printf_filtered(" | \"<\" <path> # attach child interrupt\n");
1193 printf_filtered(" | \"\\\"\" <text> # string property\n");
1194 printf_filtered(" | <text> # string property\n");
1195 printf_filtered(" ) ;\n");
1196 printf_filtered("\n");
1197 printf_filtered("And the following are valid device names:\n");
1198 printf_filtered("\n");
1206 tree_instance(device
*root
,
1207 const char *device_specifier
)
1209 /* find the device node */
1211 name_specifier spec
;
1212 if (!split_device_specifier(root
, device_specifier
, &spec
))
1214 me
= split_find_device(root
, &spec
);
1215 if (spec
.name
!= NULL
)
1217 /* create the instance */
1218 return device_create_instance(me
, device_specifier
, spec
.last_args
);
1224 tree_find_device(device
*root
,
1225 const char *path_to_device
)
1228 name_specifier spec
;
1230 /* parse the path */
1231 split_device_specifier(root
, path_to_device
, &spec
);
1232 if (spec
.value
!= NULL
)
1233 return NULL
; /* something wierd */
1236 node
= split_find_device(root
, &spec
);
1237 if (spec
.name
!= NULL
)
1238 return NULL
; /* not a leaf */
1245 (const device_property
*)
1246 tree_find_property(device
*root
,
1247 const char *path_to_property
)
1249 name_specifier spec
;
1250 if (!split_property_specifier(root
, path_to_property
, &spec
))
1251 device_error(root
, "Invalid property path %s", path_to_property
);
1252 root
= split_find_device(root
, &spec
);
1253 return device_find_property(root
, spec
.property
);
1258 tree_find_boolean_property(device
*root
,
1259 const char *path_to_property
)
1261 name_specifier spec
;
1262 if (!split_property_specifier(root
, path_to_property
, &spec
))
1263 device_error(root
, "Invalid property path %s", path_to_property
);
1264 root
= split_find_device(root
, &spec
);
1265 return device_find_boolean_property(root
, spec
.property
);
1270 tree_find_integer_property(device
*root
,
1271 const char *path_to_property
)
1273 name_specifier spec
;
1274 if (!split_property_specifier(root
, path_to_property
, &spec
))
1275 device_error(root
, "Invalid property path %s", path_to_property
);
1276 root
= split_find_device(root
, &spec
);
1277 return device_find_integer_property(root
, spec
.property
);
1282 tree_find_ihandle_property(device
*root
,
1283 const char *path_to_property
)
1285 name_specifier spec
;
1286 if (!split_property_specifier(root
, path_to_property
, &spec
))
1287 device_error(root
, "Invalid property path %s", path_to_property
);
1288 root
= split_find_device(root
, &spec
);
1289 return device_find_ihandle_property(root
, spec
.property
);
1294 tree_find_string_property(device
*root
,
1295 const char *path_to_property
)
1297 name_specifier spec
;
1298 if (!split_property_specifier(root
, path_to_property
, &spec
))
1299 device_error(root
, "Invalid property path %s", path_to_property
);
1300 root
= split_find_device(root
, &spec
);
1301 return device_find_string_property(root
, spec
.property
);
1305 #endif /* _PARSE_C_ */