2 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2007.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (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 GNU
13 * 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, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 #define TRACE(c, ...) \
27 fprintf(stderr, "=== %s: ", (c)->name); \
28 fprintf(stderr, __VA_ARGS__); \
29 fprintf(stderr, "\n"); \
32 #define TRACE(c, fmt, ...) do { } while (0)
44 typedef void (*check_fn
)(struct check
*c
, struct dt_info
*dti
, struct node
*node
);
51 enum checkstatus status
;
54 struct check
**prereq
;
57 #define CHECK_ENTRY(nm_, fn_, d_, w_, e_, ...) \
58 static struct check *nm_##_prereqs[] = { __VA_ARGS__ }; \
59 static struct check nm_ = { \
65 .status = UNCHECKED, \
66 .num_prereqs = ARRAY_SIZE(nm_##_prereqs), \
67 .prereq = nm_##_prereqs, \
69 #define WARNING(nm_, fn_, d_, ...) \
70 CHECK_ENTRY(nm_, fn_, d_, true, false, __VA_ARGS__)
71 #define ERROR(nm_, fn_, d_, ...) \
72 CHECK_ENTRY(nm_, fn_, d_, false, true, __VA_ARGS__)
73 #define CHECK(nm_, fn_, d_, ...) \
74 CHECK_ENTRY(nm_, fn_, d_, false, false, __VA_ARGS__)
76 static inline void PRINTF(5, 6) check_msg(struct check
*c
, struct dt_info
*dti
,
78 struct property
*prop
,
83 struct srcpos
*pos
= NULL
;
86 if (!(c
->warn
&& (quiet
< 1)) && !(c
->error
&& (quiet
< 2)))
89 if (prop
&& prop
->srcpos
)
91 else if (node
&& node
->srcpos
)
95 file_str
= srcpos_string(pos
);
96 xasprintf(&str
, "%s", file_str
);
98 } else if (streq(dti
->outname
, "-")) {
99 xasprintf(&str
, "<stdout>");
101 xasprintf(&str
, "%s", dti
->outname
);
104 xasprintf_append(&str
, ": %s (%s): ",
105 (c
->error
) ? "ERROR" : "Warning", c
->name
);
109 xasprintf_append(&str
, "%s:%s: ", node
->fullpath
, prop
->name
);
111 xasprintf_append(&str
, "%s: ", node
->fullpath
);
115 xavsprintf_append(&str
, fmt
, ap
);
118 xasprintf_append(&str
, "\n");
125 file_str
= srcpos_string(pos
);
126 xasprintf_append(&str
, " also defined at %s\n", file_str
);
134 #define FAIL(c, dti, node, ...) \
136 TRACE((c), "\t\tFAILED at %s:%d", __FILE__, __LINE__); \
137 (c)->status = FAILED; \
138 check_msg((c), dti, node, NULL, __VA_ARGS__); \
141 #define FAIL_PROP(c, dti, node, prop, ...) \
143 TRACE((c), "\t\tFAILED at %s:%d", __FILE__, __LINE__); \
144 (c)->status = FAILED; \
145 check_msg((c), dti, node, prop, __VA_ARGS__); \
149 static void check_nodes_props(struct check
*c
, struct dt_info
*dti
, struct node
*node
)
153 TRACE(c
, "%s", node
->fullpath
);
157 for_each_child(node
, child
)
158 check_nodes_props(c
, dti
, child
);
161 static bool run_check(struct check
*c
, struct dt_info
*dti
)
163 struct node
*dt
= dti
->dt
;
167 assert(!c
->inprogress
);
169 if (c
->status
!= UNCHECKED
)
172 c
->inprogress
= true;
174 for (i
= 0; i
< c
->num_prereqs
; i
++) {
175 struct check
*prq
= c
->prereq
[i
];
176 error
= error
|| run_check(prq
, dti
);
177 if (prq
->status
!= PASSED
) {
179 check_msg(c
, dti
, NULL
, NULL
, "Failed prerequisite '%s'",
184 if (c
->status
!= UNCHECKED
)
187 check_nodes_props(c
, dti
, dt
);
189 if (c
->status
== UNCHECKED
)
192 TRACE(c
, "\tCompleted, status %d", c
->status
);
195 c
->inprogress
= false;
196 if ((c
->status
!= PASSED
) && (c
->error
))
202 * Utility check functions
205 /* A check which always fails, for testing purposes only */
206 static inline void check_always_fail(struct check
*c
, struct dt_info
*dti
,
209 FAIL(c
, dti
, node
, "always_fail check");
211 CHECK(always_fail
, check_always_fail
, NULL
);
213 static void check_is_string(struct check
*c
, struct dt_info
*dti
,
216 struct property
*prop
;
217 char *propname
= c
->data
;
219 prop
= get_property(node
, propname
);
221 return; /* Not present, assumed ok */
223 if (!data_is_one_string(prop
->val
))
224 FAIL_PROP(c
, dti
, node
, prop
, "property is not a string");
226 #define WARNING_IF_NOT_STRING(nm, propname) \
227 WARNING(nm, check_is_string, (propname))
228 #define ERROR_IF_NOT_STRING(nm, propname) \
229 ERROR(nm, check_is_string, (propname))
231 static void check_is_string_list(struct check
*c
, struct dt_info
*dti
,
235 struct property
*prop
;
236 char *propname
= c
->data
;
239 prop
= get_property(node
, propname
);
241 return; /* Not present, assumed ok */
246 l
= strnlen(str
, rem
);
248 FAIL_PROP(c
, dti
, node
, prop
, "property is not a string list");
255 #define WARNING_IF_NOT_STRING_LIST(nm, propname) \
256 WARNING(nm, check_is_string_list, (propname))
257 #define ERROR_IF_NOT_STRING_LIST(nm, propname) \
258 ERROR(nm, check_is_string_list, (propname))
260 static void check_is_cell(struct check
*c
, struct dt_info
*dti
,
263 struct property
*prop
;
264 char *propname
= c
->data
;
266 prop
= get_property(node
, propname
);
268 return; /* Not present, assumed ok */
270 if (prop
->val
.len
!= sizeof(cell_t
))
271 FAIL_PROP(c
, dti
, node
, prop
, "property is not a single cell");
273 #define WARNING_IF_NOT_CELL(nm, propname) \
274 WARNING(nm, check_is_cell, (propname))
275 #define ERROR_IF_NOT_CELL(nm, propname) \
276 ERROR(nm, check_is_cell, (propname))
279 * Structural check functions
282 static void check_duplicate_node_names(struct check
*c
, struct dt_info
*dti
,
285 struct node
*child
, *child2
;
287 for_each_child(node
, child
)
288 for (child2
= child
->next_sibling
;
290 child2
= child2
->next_sibling
)
291 if (streq(child
->name
, child2
->name
))
292 FAIL(c
, dti
, child2
, "Duplicate node name");
294 ERROR(duplicate_node_names
, check_duplicate_node_names
, NULL
);
296 static void check_duplicate_property_names(struct check
*c
, struct dt_info
*dti
,
299 struct property
*prop
, *prop2
;
301 for_each_property(node
, prop
) {
302 for (prop2
= prop
->next
; prop2
; prop2
= prop2
->next
) {
305 if (streq(prop
->name
, prop2
->name
))
306 FAIL_PROP(c
, dti
, node
, prop
, "Duplicate property name");
310 ERROR(duplicate_property_names
, check_duplicate_property_names
, NULL
);
312 #define LOWERCASE "abcdefghijklmnopqrstuvwxyz"
313 #define UPPERCASE "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
314 #define DIGITS "0123456789"
315 #define PROPNODECHARS LOWERCASE UPPERCASE DIGITS ",._+*#?-"
316 #define PROPNODECHARSSTRICT LOWERCASE UPPERCASE DIGITS ",-"
318 static void check_node_name_chars(struct check
*c
, struct dt_info
*dti
,
321 int n
= strspn(node
->name
, c
->data
);
323 if (n
< strlen(node
->name
))
324 FAIL(c
, dti
, node
, "Bad character '%c' in node name",
327 ERROR(node_name_chars
, check_node_name_chars
, PROPNODECHARS
"@");
329 static void check_node_name_chars_strict(struct check
*c
, struct dt_info
*dti
,
332 int n
= strspn(node
->name
, c
->data
);
334 if (n
< node
->basenamelen
)
335 FAIL(c
, dti
, node
, "Character '%c' not recommended in node name",
338 CHECK(node_name_chars_strict
, check_node_name_chars_strict
, PROPNODECHARSSTRICT
);
340 static void check_node_name_format(struct check
*c
, struct dt_info
*dti
,
343 if (strchr(get_unitname(node
), '@'))
344 FAIL(c
, dti
, node
, "multiple '@' characters in node name");
346 ERROR(node_name_format
, check_node_name_format
, NULL
, &node_name_chars
);
348 static void check_unit_address_vs_reg(struct check
*c
, struct dt_info
*dti
,
351 const char *unitname
= get_unitname(node
);
352 struct property
*prop
= get_property(node
, "reg");
354 if (get_subnode(node
, "__overlay__")) {
355 /* HACK: Overlay fragments are a special case */
360 prop
= get_property(node
, "ranges");
361 if (prop
&& !prop
->val
.len
)
367 FAIL(c
, dti
, node
, "node has a reg or ranges property, but no unit name");
370 FAIL(c
, dti
, node
, "node has a unit name, but no reg property");
373 WARNING(unit_address_vs_reg
, check_unit_address_vs_reg
, NULL
);
375 static void check_property_name_chars(struct check
*c
, struct dt_info
*dti
,
378 struct property
*prop
;
380 for_each_property(node
, prop
) {
381 int n
= strspn(prop
->name
, c
->data
);
383 if (n
< strlen(prop
->name
))
384 FAIL_PROP(c
, dti
, node
, prop
, "Bad character '%c' in property name",
388 ERROR(property_name_chars
, check_property_name_chars
, PROPNODECHARS
);
390 static void check_property_name_chars_strict(struct check
*c
,
394 struct property
*prop
;
396 for_each_property(node
, prop
) {
397 const char *name
= prop
->name
;
398 int n
= strspn(name
, c
->data
);
400 if (n
== strlen(prop
->name
))
403 /* Certain names are whitelisted */
404 if (streq(name
, "device_type"))
408 * # is only allowed at the beginning of property names not counting
411 if (name
[n
] == '#' && ((n
== 0) || (name
[n
-1] == ','))) {
413 n
= strspn(name
, c
->data
);
415 if (n
< strlen(name
))
416 FAIL_PROP(c
, dti
, node
, prop
, "Character '%c' not recommended in property name",
420 CHECK(property_name_chars_strict
, check_property_name_chars_strict
, PROPNODECHARSSTRICT
);
422 #define DESCLABEL_FMT "%s%s%s%s%s"
423 #define DESCLABEL_ARGS(node,prop,mark) \
424 ((mark) ? "value of " : ""), \
425 ((prop) ? "'" : ""), \
426 ((prop) ? (prop)->name : ""), \
427 ((prop) ? "' in " : ""), (node)->fullpath
429 static void check_duplicate_label(struct check
*c
, struct dt_info
*dti
,
430 const char *label
, struct node
*node
,
431 struct property
*prop
, struct marker
*mark
)
433 struct node
*dt
= dti
->dt
;
434 struct node
*othernode
= NULL
;
435 struct property
*otherprop
= NULL
;
436 struct marker
*othermark
= NULL
;
438 othernode
= get_node_by_label(dt
, label
);
441 otherprop
= get_property_by_label(dt
, label
, &othernode
);
443 othermark
= get_marker_label(dt
, label
, &othernode
,
449 if ((othernode
!= node
) || (otherprop
!= prop
) || (othermark
!= mark
))
450 FAIL(c
, dti
, node
, "Duplicate label '%s' on " DESCLABEL_FMT
451 " and " DESCLABEL_FMT
,
452 label
, DESCLABEL_ARGS(node
, prop
, mark
),
453 DESCLABEL_ARGS(othernode
, otherprop
, othermark
));
456 static void check_duplicate_label_node(struct check
*c
, struct dt_info
*dti
,
460 struct property
*prop
;
462 for_each_label(node
->labels
, l
)
463 check_duplicate_label(c
, dti
, l
->label
, node
, NULL
, NULL
);
465 for_each_property(node
, prop
) {
466 struct marker
*m
= prop
->val
.markers
;
468 for_each_label(prop
->labels
, l
)
469 check_duplicate_label(c
, dti
, l
->label
, node
, prop
, NULL
);
471 for_each_marker_of_type(m
, LABEL
)
472 check_duplicate_label(c
, dti
, m
->ref
, node
, prop
, m
);
475 ERROR(duplicate_label
, check_duplicate_label_node
, NULL
);
477 static cell_t
check_phandle_prop(struct check
*c
, struct dt_info
*dti
,
478 struct node
*node
, const char *propname
)
480 struct node
*root
= dti
->dt
;
481 struct property
*prop
;
485 prop
= get_property(node
, propname
);
489 if (prop
->val
.len
!= sizeof(cell_t
)) {
490 FAIL_PROP(c
, dti
, node
, prop
, "bad length (%d) %s property",
491 prop
->val
.len
, prop
->name
);
495 m
= prop
->val
.markers
;
496 for_each_marker_of_type(m
, REF_PHANDLE
) {
497 assert(m
->offset
== 0);
498 if (node
!= get_node_by_ref(root
, m
->ref
))
499 /* "Set this node's phandle equal to some
500 * other node's phandle". That's nonsensical
501 * by construction. */ {
502 FAIL(c
, dti
, node
, "%s is a reference to another node",
505 /* But setting this node's phandle equal to its own
506 * phandle is allowed - that means allocate a unique
507 * phandle for this node, even if it's not otherwise
508 * referenced. The value will be filled in later, so
509 * we treat it as having no phandle data for now. */
513 phandle
= propval_cell(prop
);
515 if ((phandle
== 0) || (phandle
== -1)) {
516 FAIL_PROP(c
, dti
, node
, prop
, "bad value (0x%x) in %s property",
517 phandle
, prop
->name
);
524 static void check_explicit_phandles(struct check
*c
, struct dt_info
*dti
,
527 struct node
*root
= dti
->dt
;
529 cell_t phandle
, linux_phandle
;
531 /* Nothing should have assigned phandles yet */
532 assert(!node
->phandle
);
534 phandle
= check_phandle_prop(c
, dti
, node
, "phandle");
536 linux_phandle
= check_phandle_prop(c
, dti
, node
, "linux,phandle");
538 if (!phandle
&& !linux_phandle
)
539 /* No valid phandles; nothing further to check */
542 if (linux_phandle
&& phandle
&& (phandle
!= linux_phandle
))
543 FAIL(c
, dti
, node
, "mismatching 'phandle' and 'linux,phandle'"
546 if (linux_phandle
&& !phandle
)
547 phandle
= linux_phandle
;
549 other
= get_node_by_phandle(root
, phandle
);
550 if (other
&& (other
!= node
)) {
551 FAIL(c
, dti
, node
, "duplicated phandle 0x%x (seen before at %s)",
552 phandle
, other
->fullpath
);
556 node
->phandle
= phandle
;
558 ERROR(explicit_phandles
, check_explicit_phandles
, NULL
);
560 static void check_name_properties(struct check
*c
, struct dt_info
*dti
,
563 struct property
**pp
, *prop
= NULL
;
565 for (pp
= &node
->proplist
; *pp
; pp
= &((*pp
)->next
))
566 if (streq((*pp
)->name
, "name")) {
572 return; /* No name property, that's fine */
574 if ((prop
->val
.len
!= node
->basenamelen
+1)
575 || (memcmp(prop
->val
.val
, node
->name
, node
->basenamelen
) != 0)) {
576 FAIL(c
, dti
, node
, "\"name\" property is incorrect (\"%s\" instead"
577 " of base node name)", prop
->val
.val
);
579 /* The name property is correct, and therefore redundant.
583 data_free(prop
->val
);
587 ERROR_IF_NOT_STRING(name_is_string
, "name");
588 ERROR(name_properties
, check_name_properties
, NULL
, &name_is_string
);
591 * Reference fixup functions
594 static void fixup_phandle_references(struct check
*c
, struct dt_info
*dti
,
597 struct node
*dt
= dti
->dt
;
598 struct property
*prop
;
600 for_each_property(node
, prop
) {
601 struct marker
*m
= prop
->val
.markers
;
602 struct node
*refnode
;
605 for_each_marker_of_type(m
, REF_PHANDLE
) {
606 assert(m
->offset
+ sizeof(cell_t
) <= prop
->val
.len
);
608 refnode
= get_node_by_ref(dt
, m
->ref
);
610 if (!(dti
->dtsflags
& DTSF_PLUGIN
))
611 FAIL(c
, dti
, node
, "Reference to non-existent node or "
612 "label \"%s\"\n", m
->ref
);
613 else /* mark the entry as unresolved */
614 *((fdt32_t
*)(prop
->val
.val
+ m
->offset
)) =
615 cpu_to_fdt32(0xffffffff);
619 phandle
= get_node_phandle(dt
, refnode
);
620 *((fdt32_t
*)(prop
->val
.val
+ m
->offset
)) = cpu_to_fdt32(phandle
);
622 reference_node(refnode
);
626 ERROR(phandle_references
, fixup_phandle_references
, NULL
,
627 &duplicate_node_names
, &explicit_phandles
);
629 static void fixup_path_references(struct check
*c
, struct dt_info
*dti
,
632 struct node
*dt
= dti
->dt
;
633 struct property
*prop
;
635 for_each_property(node
, prop
) {
636 struct marker
*m
= prop
->val
.markers
;
637 struct node
*refnode
;
640 for_each_marker_of_type(m
, REF_PATH
) {
641 assert(m
->offset
<= prop
->val
.len
);
643 refnode
= get_node_by_ref(dt
, m
->ref
);
645 FAIL(c
, dti
, node
, "Reference to non-existent node or label \"%s\"\n",
650 path
= refnode
->fullpath
;
651 prop
->val
= data_insert_at_marker(prop
->val
, m
, path
,
654 reference_node(refnode
);
658 ERROR(path_references
, fixup_path_references
, NULL
, &duplicate_node_names
);
660 static void fixup_omit_unused_nodes(struct check
*c
, struct dt_info
*dti
,
663 if (node
->omit_if_unused
&& !node
->is_referenced
)
666 ERROR(omit_unused_nodes
, fixup_omit_unused_nodes
, NULL
, &phandle_references
, &path_references
);
671 WARNING_IF_NOT_CELL(address_cells_is_cell
, "#address-cells");
672 WARNING_IF_NOT_CELL(size_cells_is_cell
, "#size-cells");
673 WARNING_IF_NOT_CELL(interrupt_cells_is_cell
, "#interrupt-cells");
675 WARNING_IF_NOT_STRING(device_type_is_string
, "device_type");
676 WARNING_IF_NOT_STRING(model_is_string
, "model");
677 WARNING_IF_NOT_STRING(status_is_string
, "status");
678 WARNING_IF_NOT_STRING(label_is_string
, "label");
680 WARNING_IF_NOT_STRING_LIST(compatible_is_string_list
, "compatible");
682 static void check_names_is_string_list(struct check
*c
, struct dt_info
*dti
,
685 struct property
*prop
;
687 for_each_property(node
, prop
) {
688 const char *s
= strrchr(prop
->name
, '-');
689 if (!s
|| !streq(s
, "-names"))
692 c
->data
= prop
->name
;
693 check_is_string_list(c
, dti
, node
);
696 WARNING(names_is_string_list
, check_names_is_string_list
, NULL
);
698 static void check_alias_paths(struct check
*c
, struct dt_info
*dti
,
701 struct property
*prop
;
703 if (!streq(node
->name
, "aliases"))
706 for_each_property(node
, prop
) {
707 if (!prop
->val
.val
|| !get_node_by_path(dti
->dt
, prop
->val
.val
)) {
708 FAIL_PROP(c
, dti
, node
, prop
, "aliases property is not a valid node (%s)",
712 if (strspn(prop
->name
, LOWERCASE DIGITS
"-") != strlen(prop
->name
))
713 FAIL(c
, dti
, node
, "aliases property name must include only lowercase and '-'");
716 WARNING(alias_paths
, check_alias_paths
, NULL
);
718 static void fixup_addr_size_cells(struct check
*c
, struct dt_info
*dti
,
721 struct property
*prop
;
723 node
->addr_cells
= -1;
724 node
->size_cells
= -1;
726 prop
= get_property(node
, "#address-cells");
728 node
->addr_cells
= propval_cell(prop
);
730 prop
= get_property(node
, "#size-cells");
732 node
->size_cells
= propval_cell(prop
);
734 WARNING(addr_size_cells
, fixup_addr_size_cells
, NULL
,
735 &address_cells_is_cell
, &size_cells_is_cell
);
737 #define node_addr_cells(n) \
738 (((n)->addr_cells == -1) ? 2 : (n)->addr_cells)
739 #define node_size_cells(n) \
740 (((n)->size_cells == -1) ? 1 : (n)->size_cells)
742 static void check_reg_format(struct check
*c
, struct dt_info
*dti
,
745 struct property
*prop
;
746 int addr_cells
, size_cells
, entrylen
;
748 prop
= get_property(node
, "reg");
750 return; /* No "reg", that's fine */
753 FAIL(c
, dti
, node
, "Root node has a \"reg\" property");
757 if (prop
->val
.len
== 0)
758 FAIL_PROP(c
, dti
, node
, prop
, "property is empty");
760 addr_cells
= node_addr_cells(node
->parent
);
761 size_cells
= node_size_cells(node
->parent
);
762 entrylen
= (addr_cells
+ size_cells
) * sizeof(cell_t
);
764 if (!entrylen
|| (prop
->val
.len
% entrylen
) != 0)
765 FAIL_PROP(c
, dti
, node
, prop
, "property has invalid length (%d bytes) "
766 "(#address-cells == %d, #size-cells == %d)",
767 prop
->val
.len
, addr_cells
, size_cells
);
769 WARNING(reg_format
, check_reg_format
, NULL
, &addr_size_cells
);
771 static void check_ranges_format(struct check
*c
, struct dt_info
*dti
,
774 struct property
*prop
;
775 int c_addr_cells
, p_addr_cells
, c_size_cells
, p_size_cells
, entrylen
;
777 prop
= get_property(node
, "ranges");
782 FAIL_PROP(c
, dti
, node
, prop
, "Root node has a \"ranges\" property");
786 p_addr_cells
= node_addr_cells(node
->parent
);
787 p_size_cells
= node_size_cells(node
->parent
);
788 c_addr_cells
= node_addr_cells(node
);
789 c_size_cells
= node_size_cells(node
);
790 entrylen
= (p_addr_cells
+ c_addr_cells
+ c_size_cells
) * sizeof(cell_t
);
792 if (prop
->val
.len
== 0) {
793 if (p_addr_cells
!= c_addr_cells
)
794 FAIL_PROP(c
, dti
, node
, prop
, "empty \"ranges\" property but its "
795 "#address-cells (%d) differs from %s (%d)",
796 c_addr_cells
, node
->parent
->fullpath
,
798 if (p_size_cells
!= c_size_cells
)
799 FAIL_PROP(c
, dti
, node
, prop
, "empty \"ranges\" property but its "
800 "#size-cells (%d) differs from %s (%d)",
801 c_size_cells
, node
->parent
->fullpath
,
803 } else if ((prop
->val
.len
% entrylen
) != 0) {
804 FAIL_PROP(c
, dti
, node
, prop
, "\"ranges\" property has invalid length (%d bytes) "
805 "(parent #address-cells == %d, child #address-cells == %d, "
806 "#size-cells == %d)", prop
->val
.len
,
807 p_addr_cells
, c_addr_cells
, c_size_cells
);
810 WARNING(ranges_format
, check_ranges_format
, NULL
, &addr_size_cells
);
812 static const struct bus_type pci_bus
= {
816 static void check_pci_bridge(struct check
*c
, struct dt_info
*dti
, struct node
*node
)
818 struct property
*prop
;
821 prop
= get_property(node
, "device_type");
822 if (!prop
|| !streq(prop
->val
.val
, "pci"))
825 node
->bus
= &pci_bus
;
827 if (!strprefixeq(node
->name
, node
->basenamelen
, "pci") &&
828 !strprefixeq(node
->name
, node
->basenamelen
, "pcie"))
829 FAIL(c
, dti
, node
, "node name is not \"pci\" or \"pcie\"");
831 prop
= get_property(node
, "ranges");
833 FAIL(c
, dti
, node
, "missing ranges for PCI bridge (or not a bridge)");
835 if (node_addr_cells(node
) != 3)
836 FAIL(c
, dti
, node
, "incorrect #address-cells for PCI bridge");
837 if (node_size_cells(node
) != 2)
838 FAIL(c
, dti
, node
, "incorrect #size-cells for PCI bridge");
840 prop
= get_property(node
, "bus-range");
844 if (prop
->val
.len
!= (sizeof(cell_t
) * 2)) {
845 FAIL_PROP(c
, dti
, node
, prop
, "value must be 2 cells");
848 cells
= (cell_t
*)prop
->val
.val
;
849 if (fdt32_to_cpu(cells
[0]) > fdt32_to_cpu(cells
[1]))
850 FAIL_PROP(c
, dti
, node
, prop
, "1st cell must be less than or equal to 2nd cell");
851 if (fdt32_to_cpu(cells
[1]) > 0xff)
852 FAIL_PROP(c
, dti
, node
, prop
, "maximum bus number must be less than 256");
854 WARNING(pci_bridge
, check_pci_bridge
, NULL
,
855 &device_type_is_string
, &addr_size_cells
);
857 static void check_pci_device_bus_num(struct check
*c
, struct dt_info
*dti
, struct node
*node
)
859 struct property
*prop
;
860 unsigned int bus_num
, min_bus
, max_bus
;
863 if (!node
->parent
|| (node
->parent
->bus
!= &pci_bus
))
866 prop
= get_property(node
, "reg");
870 cells
= (cell_t
*)prop
->val
.val
;
871 bus_num
= (fdt32_to_cpu(cells
[0]) & 0x00ff0000) >> 16;
873 prop
= get_property(node
->parent
, "bus-range");
875 min_bus
= max_bus
= 0;
877 cells
= (cell_t
*)prop
->val
.val
;
878 min_bus
= fdt32_to_cpu(cells
[0]);
879 max_bus
= fdt32_to_cpu(cells
[0]);
881 if ((bus_num
< min_bus
) || (bus_num
> max_bus
))
882 FAIL_PROP(c
, dti
, node
, prop
, "PCI bus number %d out of range, expected (%d - %d)",
883 bus_num
, min_bus
, max_bus
);
885 WARNING(pci_device_bus_num
, check_pci_device_bus_num
, NULL
, ®_format
, &pci_bridge
);
887 static void check_pci_device_reg(struct check
*c
, struct dt_info
*dti
, struct node
*node
)
889 struct property
*prop
;
890 const char *unitname
= get_unitname(node
);
892 unsigned int dev
, func
, reg
;
895 if (!node
->parent
|| (node
->parent
->bus
!= &pci_bus
))
898 prop
= get_property(node
, "reg");
900 FAIL(c
, dti
, node
, "missing PCI reg property");
904 cells
= (cell_t
*)prop
->val
.val
;
905 if (cells
[1] || cells
[2])
906 FAIL_PROP(c
, dti
, node
, prop
, "PCI reg config space address cells 2 and 3 must be 0");
908 reg
= fdt32_to_cpu(cells
[0]);
909 dev
= (reg
& 0xf800) >> 11;
910 func
= (reg
& 0x700) >> 8;
912 if (reg
& 0xff000000)
913 FAIL_PROP(c
, dti
, node
, prop
, "PCI reg address is not configuration space");
914 if (reg
& 0x000000ff)
915 FAIL_PROP(c
, dti
, node
, prop
, "PCI reg config space address register number must be 0");
918 snprintf(unit_addr
, sizeof(unit_addr
), "%x", dev
);
919 if (streq(unitname
, unit_addr
))
923 snprintf(unit_addr
, sizeof(unit_addr
), "%x,%x", dev
, func
);
924 if (streq(unitname
, unit_addr
))
927 FAIL(c
, dti
, node
, "PCI unit address format error, expected \"%s\"",
930 WARNING(pci_device_reg
, check_pci_device_reg
, NULL
, ®_format
, &pci_bridge
);
932 static const struct bus_type simple_bus
= {
933 .name
= "simple-bus",
936 static bool node_is_compatible(struct node
*node
, const char *compat
)
938 struct property
*prop
;
939 const char *str
, *end
;
941 prop
= get_property(node
, "compatible");
945 for (str
= prop
->val
.val
, end
= str
+ prop
->val
.len
; str
< end
;
946 str
+= strnlen(str
, end
- str
) + 1) {
947 if (streq(str
, compat
))
953 static void check_simple_bus_bridge(struct check
*c
, struct dt_info
*dti
, struct node
*node
)
955 if (node_is_compatible(node
, "simple-bus"))
956 node
->bus
= &simple_bus
;
958 WARNING(simple_bus_bridge
, check_simple_bus_bridge
, NULL
,
959 &addr_size_cells
, &compatible_is_string_list
);
961 static void check_simple_bus_reg(struct check
*c
, struct dt_info
*dti
, struct node
*node
)
963 struct property
*prop
;
964 const char *unitname
= get_unitname(node
);
968 cell_t
*cells
= NULL
;
970 if (!node
->parent
|| (node
->parent
->bus
!= &simple_bus
))
973 prop
= get_property(node
, "reg");
975 cells
= (cell_t
*)prop
->val
.val
;
977 prop
= get_property(node
, "ranges");
978 if (prop
&& prop
->val
.len
)
979 /* skip of child address */
980 cells
= ((cell_t
*)prop
->val
.val
) + node_addr_cells(node
);
984 if (node
->parent
->parent
&& !(node
->bus
== &simple_bus
))
985 FAIL(c
, dti
, node
, "missing or empty reg/ranges property");
989 size
= node_addr_cells(node
->parent
);
991 reg
= (reg
<< 32) | fdt32_to_cpu(*(cells
++));
993 snprintf(unit_addr
, sizeof(unit_addr
), "%"PRIx64
, reg
);
994 if (!streq(unitname
, unit_addr
))
995 FAIL(c
, dti
, node
, "simple-bus unit address format error, expected \"%s\"",
998 WARNING(simple_bus_reg
, check_simple_bus_reg
, NULL
, ®_format
, &simple_bus_bridge
);
1000 static const struct bus_type i2c_bus
= {
1004 static void check_i2c_bus_bridge(struct check
*c
, struct dt_info
*dti
, struct node
*node
)
1006 if (strprefixeq(node
->name
, node
->basenamelen
, "i2c-bus") ||
1007 strprefixeq(node
->name
, node
->basenamelen
, "i2c-arb")) {
1008 node
->bus
= &i2c_bus
;
1009 } else if (strprefixeq(node
->name
, node
->basenamelen
, "i2c")) {
1011 for_each_child(node
, child
) {
1012 if (strprefixeq(child
->name
, node
->basenamelen
, "i2c-bus"))
1015 node
->bus
= &i2c_bus
;
1019 if (!node
->children
)
1022 if (node_addr_cells(node
) != 1)
1023 FAIL(c
, dti
, node
, "incorrect #address-cells for I2C bus");
1024 if (node_size_cells(node
) != 0)
1025 FAIL(c
, dti
, node
, "incorrect #size-cells for I2C bus");
1028 WARNING(i2c_bus_bridge
, check_i2c_bus_bridge
, NULL
, &addr_size_cells
);
1030 static void check_i2c_bus_reg(struct check
*c
, struct dt_info
*dti
, struct node
*node
)
1032 struct property
*prop
;
1033 const char *unitname
= get_unitname(node
);
1037 cell_t
*cells
= NULL
;
1039 if (!node
->parent
|| (node
->parent
->bus
!= &i2c_bus
))
1042 prop
= get_property(node
, "reg");
1044 cells
= (cell_t
*)prop
->val
.val
;
1047 FAIL(c
, dti
, node
, "missing or empty reg property");
1051 reg
= fdt32_to_cpu(*cells
);
1052 snprintf(unit_addr
, sizeof(unit_addr
), "%x", reg
);
1053 if (!streq(unitname
, unit_addr
))
1054 FAIL(c
, dti
, node
, "I2C bus unit address format error, expected \"%s\"",
1057 for (len
= prop
->val
.len
; len
> 0; len
-= 4) {
1058 reg
= fdt32_to_cpu(*(cells
++));
1060 FAIL_PROP(c
, dti
, node
, prop
, "I2C address must be less than 10-bits, got \"0x%x\"",
1065 WARNING(i2c_bus_reg
, check_i2c_bus_reg
, NULL
, ®_format
, &i2c_bus_bridge
);
1067 static const struct bus_type spi_bus
= {
1071 static void check_spi_bus_bridge(struct check
*c
, struct dt_info
*dti
, struct node
*node
)
1073 int spi_addr_cells
= 1;
1075 if (strprefixeq(node
->name
, node
->basenamelen
, "spi")) {
1076 node
->bus
= &spi_bus
;
1078 /* Try to detect SPI buses which don't have proper node name */
1081 if (node_addr_cells(node
) != 1 || node_size_cells(node
) != 0)
1084 for_each_child(node
, child
) {
1085 struct property
*prop
;
1086 for_each_property(child
, prop
) {
1087 if (strprefixeq(prop
->name
, 4, "spi-")) {
1088 node
->bus
= &spi_bus
;
1092 if (node
->bus
== &spi_bus
)
1096 if (node
->bus
== &spi_bus
&& get_property(node
, "reg"))
1097 FAIL(c
, dti
, node
, "node name for SPI buses should be 'spi'");
1099 if (node
->bus
!= &spi_bus
|| !node
->children
)
1102 if (get_property(node
, "spi-slave"))
1104 if (node_addr_cells(node
) != spi_addr_cells
)
1105 FAIL(c
, dti
, node
, "incorrect #address-cells for SPI bus");
1106 if (node_size_cells(node
) != 0)
1107 FAIL(c
, dti
, node
, "incorrect #size-cells for SPI bus");
1110 WARNING(spi_bus_bridge
, check_spi_bus_bridge
, NULL
, &addr_size_cells
);
1112 static void check_spi_bus_reg(struct check
*c
, struct dt_info
*dti
, struct node
*node
)
1114 struct property
*prop
;
1115 const char *unitname
= get_unitname(node
);
1118 cell_t
*cells
= NULL
;
1120 if (!node
->parent
|| (node
->parent
->bus
!= &spi_bus
))
1123 if (get_property(node
->parent
, "spi-slave"))
1126 prop
= get_property(node
, "reg");
1128 cells
= (cell_t
*)prop
->val
.val
;
1131 FAIL(c
, dti
, node
, "missing or empty reg property");
1135 reg
= fdt32_to_cpu(*cells
);
1136 snprintf(unit_addr
, sizeof(unit_addr
), "%x", reg
);
1137 if (!streq(unitname
, unit_addr
))
1138 FAIL(c
, dti
, node
, "SPI bus unit address format error, expected \"%s\"",
1141 WARNING(spi_bus_reg
, check_spi_bus_reg
, NULL
, ®_format
, &spi_bus_bridge
);
1143 static void check_unit_address_format(struct check
*c
, struct dt_info
*dti
,
1146 const char *unitname
= get_unitname(node
);
1148 if (node
->parent
&& node
->parent
->bus
)
1154 if (!strncmp(unitname
, "0x", 2)) {
1155 FAIL(c
, dti
, node
, "unit name should not have leading \"0x\"");
1156 /* skip over 0x for next test */
1159 if (unitname
[0] == '0' && isxdigit(unitname
[1]))
1160 FAIL(c
, dti
, node
, "unit name should not have leading 0s");
1162 WARNING(unit_address_format
, check_unit_address_format
, NULL
,
1163 &node_name_format
, &pci_bridge
, &simple_bus_bridge
);
1168 static void check_avoid_default_addr_size(struct check
*c
, struct dt_info
*dti
,
1171 struct property
*reg
, *ranges
;
1174 return; /* Ignore root node */
1176 reg
= get_property(node
, "reg");
1177 ranges
= get_property(node
, "ranges");
1179 if (!reg
&& !ranges
)
1182 if (node
->parent
->addr_cells
== -1)
1183 FAIL(c
, dti
, node
, "Relying on default #address-cells value");
1185 if (node
->parent
->size_cells
== -1)
1186 FAIL(c
, dti
, node
, "Relying on default #size-cells value");
1188 WARNING(avoid_default_addr_size
, check_avoid_default_addr_size
, NULL
,
1191 static void check_avoid_unnecessary_addr_size(struct check
*c
, struct dt_info
*dti
,
1194 struct property
*prop
;
1196 bool has_reg
= false;
1198 if (!node
->parent
|| node
->addr_cells
< 0 || node
->size_cells
< 0)
1201 if (get_property(node
, "ranges") || !node
->children
)
1204 for_each_child(node
, child
) {
1205 prop
= get_property(child
, "reg");
1211 FAIL(c
, dti
, node
, "unnecessary #address-cells/#size-cells without \"ranges\" or child \"reg\" property");
1213 WARNING(avoid_unnecessary_addr_size
, check_avoid_unnecessary_addr_size
, NULL
, &avoid_default_addr_size
);
1215 static void check_unique_unit_address(struct check
*c
, struct dt_info
*dti
,
1218 struct node
*childa
;
1220 if (node
->addr_cells
< 0 || node
->size_cells
< 0)
1223 if (!node
->children
)
1226 for_each_child(node
, childa
) {
1227 struct node
*childb
;
1228 const char *addr_a
= get_unitname(childa
);
1230 if (!strlen(addr_a
))
1233 for_each_child(node
, childb
) {
1234 const char *addr_b
= get_unitname(childb
);
1235 if (childa
== childb
)
1238 if (streq(addr_a
, addr_b
))
1239 FAIL(c
, dti
, childb
, "duplicate unit-address (also used in node %s)", childa
->fullpath
);
1243 WARNING(unique_unit_address
, check_unique_unit_address
, NULL
, &avoid_default_addr_size
);
1245 static void check_obsolete_chosen_interrupt_controller(struct check
*c
,
1246 struct dt_info
*dti
,
1249 struct node
*dt
= dti
->dt
;
1250 struct node
*chosen
;
1251 struct property
*prop
;
1257 chosen
= get_node_by_path(dt
, "/chosen");
1261 prop
= get_property(chosen
, "interrupt-controller");
1263 FAIL_PROP(c
, dti
, node
, prop
,
1264 "/chosen has obsolete \"interrupt-controller\" property");
1266 WARNING(obsolete_chosen_interrupt_controller
,
1267 check_obsolete_chosen_interrupt_controller
, NULL
);
1269 static void check_chosen_node_is_root(struct check
*c
, struct dt_info
*dti
,
1272 if (!streq(node
->name
, "chosen"))
1275 if (node
->parent
!= dti
->dt
)
1276 FAIL(c
, dti
, node
, "chosen node must be at root node");
1278 WARNING(chosen_node_is_root
, check_chosen_node_is_root
, NULL
);
1280 static void check_chosen_node_bootargs(struct check
*c
, struct dt_info
*dti
,
1283 struct property
*prop
;
1285 if (!streq(node
->name
, "chosen"))
1288 prop
= get_property(node
, "bootargs");
1292 c
->data
= prop
->name
;
1293 check_is_string(c
, dti
, node
);
1295 WARNING(chosen_node_bootargs
, check_chosen_node_bootargs
, NULL
);
1297 static void check_chosen_node_stdout_path(struct check
*c
, struct dt_info
*dti
,
1300 struct property
*prop
;
1302 if (!streq(node
->name
, "chosen"))
1305 prop
= get_property(node
, "stdout-path");
1307 prop
= get_property(node
, "linux,stdout-path");
1310 FAIL_PROP(c
, dti
, node
, prop
, "Use 'stdout-path' instead");
1313 c
->data
= prop
->name
;
1314 check_is_string(c
, dti
, node
);
1316 WARNING(chosen_node_stdout_path
, check_chosen_node_stdout_path
, NULL
);
1319 const char *prop_name
;
1320 const char *cell_name
;
1324 static void check_property_phandle_args(struct check
*c
,
1325 struct dt_info
*dti
,
1327 struct property
*prop
,
1328 const struct provider
*provider
)
1330 struct node
*root
= dti
->dt
;
1331 int cell
, cellsize
= 0;
1333 if (prop
->val
.len
% sizeof(cell_t
)) {
1334 FAIL_PROP(c
, dti
, node
, prop
,
1335 "property size (%d) is invalid, expected multiple of %zu",
1336 prop
->val
.len
, sizeof(cell_t
));
1340 for (cell
= 0; cell
< prop
->val
.len
/ sizeof(cell_t
); cell
+= cellsize
+ 1) {
1341 struct node
*provider_node
;
1342 struct property
*cellprop
;
1345 phandle
= propval_cell_n(prop
, cell
);
1347 * Some bindings use a cell value 0 or -1 to skip over optional
1348 * entries when each index position has a specific definition.
1350 if (phandle
== 0 || phandle
== -1) {
1351 /* Give up if this is an overlay with external references */
1352 if (dti
->dtsflags
& DTSF_PLUGIN
)
1359 /* If we have markers, verify the current cell is a phandle */
1360 if (prop
->val
.markers
) {
1361 struct marker
*m
= prop
->val
.markers
;
1362 for_each_marker_of_type(m
, REF_PHANDLE
) {
1363 if (m
->offset
== (cell
* sizeof(cell_t
)))
1367 FAIL_PROP(c
, dti
, node
, prop
,
1368 "cell %d is not a phandle reference",
1372 provider_node
= get_node_by_phandle(root
, phandle
);
1373 if (!provider_node
) {
1374 FAIL_PROP(c
, dti
, node
, prop
,
1375 "Could not get phandle node for (cell %d)",
1380 cellprop
= get_property(provider_node
, provider
->cell_name
);
1382 cellsize
= propval_cell(cellprop
);
1383 } else if (provider
->optional
) {
1386 FAIL(c
, dti
, node
, "Missing property '%s' in node %s or bad phandle (referred from %s[%d])",
1387 provider
->cell_name
,
1388 provider_node
->fullpath
,
1393 if (prop
->val
.len
< ((cell
+ cellsize
+ 1) * sizeof(cell_t
))) {
1394 FAIL_PROP(c
, dti
, node
, prop
,
1395 "property size (%d) too small for cell size %d",
1396 prop
->val
.len
, cellsize
);
1401 static void check_provider_cells_property(struct check
*c
,
1402 struct dt_info
*dti
,
1405 struct provider
*provider
= c
->data
;
1406 struct property
*prop
;
1408 prop
= get_property(node
, provider
->prop_name
);
1412 check_property_phandle_args(c
, dti
, node
, prop
, provider
);
1414 #define WARNING_PROPERTY_PHANDLE_CELLS(nm, propname, cells_name, ...) \
1415 static struct provider nm##_provider = { (propname), (cells_name), __VA_ARGS__ }; \
1416 WARNING(nm##_property, check_provider_cells_property, &nm##_provider, &phandle_references);
1418 WARNING_PROPERTY_PHANDLE_CELLS(clocks
, "clocks", "#clock-cells");
1419 WARNING_PROPERTY_PHANDLE_CELLS(cooling_device
, "cooling-device", "#cooling-cells");
1420 WARNING_PROPERTY_PHANDLE_CELLS(dmas
, "dmas", "#dma-cells");
1421 WARNING_PROPERTY_PHANDLE_CELLS(hwlocks
, "hwlocks", "#hwlock-cells");
1422 WARNING_PROPERTY_PHANDLE_CELLS(interrupts_extended
, "interrupts-extended", "#interrupt-cells");
1423 WARNING_PROPERTY_PHANDLE_CELLS(io_channels
, "io-channels", "#io-channel-cells");
1424 WARNING_PROPERTY_PHANDLE_CELLS(iommus
, "iommus", "#iommu-cells");
1425 WARNING_PROPERTY_PHANDLE_CELLS(mboxes
, "mboxes", "#mbox-cells");
1426 WARNING_PROPERTY_PHANDLE_CELLS(msi_parent
, "msi-parent", "#msi-cells", true);
1427 WARNING_PROPERTY_PHANDLE_CELLS(mux_controls
, "mux-controls", "#mux-control-cells");
1428 WARNING_PROPERTY_PHANDLE_CELLS(phys
, "phys", "#phy-cells");
1429 WARNING_PROPERTY_PHANDLE_CELLS(power_domains
, "power-domains", "#power-domain-cells");
1430 WARNING_PROPERTY_PHANDLE_CELLS(pwms
, "pwms", "#pwm-cells");
1431 WARNING_PROPERTY_PHANDLE_CELLS(resets
, "resets", "#reset-cells");
1432 WARNING_PROPERTY_PHANDLE_CELLS(sound_dai
, "sound-dai", "#sound-dai-cells");
1433 WARNING_PROPERTY_PHANDLE_CELLS(thermal_sensors
, "thermal-sensors", "#thermal-sensor-cells");
1435 static bool prop_is_gpio(struct property
*prop
)
1440 * *-gpios and *-gpio can appear in property names,
1441 * so skip over any false matches (only one known ATM)
1443 if (strstr(prop
->name
, "nr-gpio"))
1446 str
= strrchr(prop
->name
, '-');
1451 if (!(streq(str
, "gpios") || streq(str
, "gpio")))
1457 static void check_gpios_property(struct check
*c
,
1458 struct dt_info
*dti
,
1461 struct property
*prop
;
1463 /* Skip GPIO hog nodes which have 'gpios' property */
1464 if (get_property(node
, "gpio-hog"))
1467 for_each_property(node
, prop
) {
1468 struct provider provider
;
1470 if (!prop_is_gpio(prop
))
1473 provider
.prop_name
= prop
->name
;
1474 provider
.cell_name
= "#gpio-cells";
1475 provider
.optional
= false;
1476 check_property_phandle_args(c
, dti
, node
, prop
, &provider
);
1480 WARNING(gpios_property
, check_gpios_property
, NULL
, &phandle_references
);
1482 static void check_deprecated_gpio_property(struct check
*c
,
1483 struct dt_info
*dti
,
1486 struct property
*prop
;
1488 for_each_property(node
, prop
) {
1491 if (!prop_is_gpio(prop
))
1494 str
= strstr(prop
->name
, "gpio");
1495 if (!streq(str
, "gpio"))
1498 FAIL_PROP(c
, dti
, node
, prop
,
1499 "'[*-]gpio' is deprecated, use '[*-]gpios' instead");
1503 CHECK(deprecated_gpio_property
, check_deprecated_gpio_property
, NULL
);
1505 static bool node_is_interrupt_provider(struct node
*node
)
1507 struct property
*prop
;
1509 prop
= get_property(node
, "interrupt-controller");
1513 prop
= get_property(node
, "interrupt-map");
1519 static void check_interrupts_property(struct check
*c
,
1520 struct dt_info
*dti
,
1523 struct node
*root
= dti
->dt
;
1524 struct node
*irq_node
= NULL
, *parent
= node
;
1525 struct property
*irq_prop
, *prop
= NULL
;
1526 int irq_cells
, phandle
;
1528 irq_prop
= get_property(node
, "interrupts");
1532 if (irq_prop
->val
.len
% sizeof(cell_t
))
1533 FAIL_PROP(c
, dti
, node
, irq_prop
, "size (%d) is invalid, expected multiple of %zu",
1534 irq_prop
->val
.len
, sizeof(cell_t
));
1536 while (parent
&& !prop
) {
1537 if (parent
!= node
&& node_is_interrupt_provider(parent
)) {
1542 prop
= get_property(parent
, "interrupt-parent");
1544 phandle
= propval_cell(prop
);
1545 /* Give up if this is an overlay with external references */
1546 if ((phandle
== 0 || phandle
== -1) &&
1547 (dti
->dtsflags
& DTSF_PLUGIN
))
1550 irq_node
= get_node_by_phandle(root
, phandle
);
1552 FAIL_PROP(c
, dti
, parent
, prop
, "Bad phandle");
1555 if (!node_is_interrupt_provider(irq_node
))
1556 FAIL(c
, dti
, irq_node
,
1557 "Missing interrupt-controller or interrupt-map property");
1562 parent
= parent
->parent
;
1566 FAIL(c
, dti
, node
, "Missing interrupt-parent");
1570 prop
= get_property(irq_node
, "#interrupt-cells");
1572 FAIL(c
, dti
, irq_node
, "Missing #interrupt-cells in interrupt-parent");
1576 irq_cells
= propval_cell(prop
);
1577 if (irq_prop
->val
.len
% (irq_cells
* sizeof(cell_t
))) {
1578 FAIL_PROP(c
, dti
, node
, prop
,
1579 "size is (%d), expected multiple of %d",
1580 irq_prop
->val
.len
, (int)(irq_cells
* sizeof(cell_t
)));
1583 WARNING(interrupts_property
, check_interrupts_property
, &phandle_references
);
1585 static const struct bus_type graph_port_bus
= {
1586 .name
= "graph-port",
1589 static const struct bus_type graph_ports_bus
= {
1590 .name
= "graph-ports",
1593 static void check_graph_nodes(struct check
*c
, struct dt_info
*dti
,
1598 for_each_child(node
, child
) {
1599 if (!(strprefixeq(child
->name
, child
->basenamelen
, "endpoint") ||
1600 get_property(child
, "remote-endpoint")))
1603 node
->bus
= &graph_port_bus
;
1605 /* The parent of 'port' nodes can be either 'ports' or a device */
1606 if (!node
->parent
->bus
&&
1607 (streq(node
->parent
->name
, "ports") || get_property(node
, "reg")))
1608 node
->parent
->bus
= &graph_ports_bus
;
1614 WARNING(graph_nodes
, check_graph_nodes
, NULL
);
1616 static void check_graph_child_address(struct check
*c
, struct dt_info
*dti
,
1622 if (node
->bus
!= &graph_ports_bus
&& node
->bus
!= &graph_port_bus
)
1625 for_each_child(node
, child
) {
1626 struct property
*prop
= get_property(child
, "reg");
1628 /* No error if we have any non-zero unit address */
1629 if (prop
&& propval_cell(prop
) != 0)
1635 if (cnt
== 1 && node
->addr_cells
!= -1)
1636 FAIL(c
, dti
, node
, "graph node has single child node '%s', #address-cells/#size-cells are not necessary",
1637 node
->children
->name
);
1639 WARNING(graph_child_address
, check_graph_child_address
, NULL
, &graph_nodes
);
1641 static void check_graph_reg(struct check
*c
, struct dt_info
*dti
,
1645 const char *unitname
= get_unitname(node
);
1646 struct property
*prop
;
1648 prop
= get_property(node
, "reg");
1649 if (!prop
|| !unitname
)
1652 if (!(prop
->val
.val
&& prop
->val
.len
== sizeof(cell_t
))) {
1653 FAIL(c
, dti
, node
, "graph node malformed 'reg' property");
1657 snprintf(unit_addr
, sizeof(unit_addr
), "%x", propval_cell(prop
));
1658 if (!streq(unitname
, unit_addr
))
1659 FAIL(c
, dti
, node
, "graph node unit address error, expected \"%s\"",
1662 if (node
->parent
->addr_cells
!= 1)
1663 FAIL_PROP(c
, dti
, node
, get_property(node
, "#address-cells"),
1664 "graph node '#address-cells' is %d, must be 1",
1665 node
->parent
->addr_cells
);
1666 if (node
->parent
->size_cells
!= 0)
1667 FAIL_PROP(c
, dti
, node
, get_property(node
, "#size-cells"),
1668 "graph node '#size-cells' is %d, must be 0",
1669 node
->parent
->size_cells
);
1672 static void check_graph_port(struct check
*c
, struct dt_info
*dti
,
1675 if (node
->bus
!= &graph_port_bus
)
1678 if (!strprefixeq(node
->name
, node
->basenamelen
, "port"))
1679 FAIL(c
, dti
, node
, "graph port node name should be 'port'");
1681 check_graph_reg(c
, dti
, node
);
1683 WARNING(graph_port
, check_graph_port
, NULL
, &graph_nodes
);
1685 static struct node
*get_remote_endpoint(struct check
*c
, struct dt_info
*dti
,
1686 struct node
*endpoint
)
1690 struct property
*prop
;
1692 prop
= get_property(endpoint
, "remote-endpoint");
1696 phandle
= propval_cell(prop
);
1697 /* Give up if this is an overlay with external references */
1698 if (phandle
== 0 || phandle
== -1)
1701 node
= get_node_by_phandle(dti
->dt
, phandle
);
1703 FAIL_PROP(c
, dti
, endpoint
, prop
, "graph phandle is not valid");
1708 static void check_graph_endpoint(struct check
*c
, struct dt_info
*dti
,
1711 struct node
*remote_node
;
1713 if (!node
->parent
|| node
->parent
->bus
!= &graph_port_bus
)
1716 if (!strprefixeq(node
->name
, node
->basenamelen
, "endpoint"))
1717 FAIL(c
, dti
, node
, "graph endpont node name should be 'endpoint'");
1719 check_graph_reg(c
, dti
, node
);
1721 remote_node
= get_remote_endpoint(c
, dti
, node
);
1725 if (get_remote_endpoint(c
, dti
, remote_node
) != node
)
1726 FAIL(c
, dti
, node
, "graph connection to node '%s' is not bidirectional",
1727 remote_node
->fullpath
);
1729 WARNING(graph_endpoint
, check_graph_endpoint
, NULL
, &graph_nodes
);
1731 static struct check
*check_table
[] = {
1732 &duplicate_node_names
, &duplicate_property_names
,
1733 &node_name_chars
, &node_name_format
, &property_name_chars
,
1734 &name_is_string
, &name_properties
,
1739 &phandle_references
, &path_references
,
1742 &address_cells_is_cell
, &size_cells_is_cell
, &interrupt_cells_is_cell
,
1743 &device_type_is_string
, &model_is_string
, &status_is_string
,
1746 &compatible_is_string_list
, &names_is_string_list
,
1748 &property_name_chars_strict
,
1749 &node_name_chars_strict
,
1751 &addr_size_cells
, ®_format
, &ranges_format
,
1753 &unit_address_vs_reg
,
1754 &unit_address_format
,
1758 &pci_device_bus_num
,
1769 &avoid_default_addr_size
,
1770 &avoid_unnecessary_addr_size
,
1771 &unique_unit_address
,
1772 &obsolete_chosen_interrupt_controller
,
1773 &chosen_node_is_root
, &chosen_node_bootargs
, &chosen_node_stdout_path
,
1776 &cooling_device_property
,
1779 &interrupts_extended_property
,
1780 &io_channels_property
,
1783 &msi_parent_property
,
1784 &mux_controls_property
,
1786 &power_domains_property
,
1789 &sound_dai_property
,
1790 &thermal_sensors_property
,
1792 &deprecated_gpio_property
,
1794 &interrupts_property
,
1798 &graph_nodes
, &graph_child_address
, &graph_port
, &graph_endpoint
,
1803 static void enable_warning_error(struct check
*c
, bool warn
, bool error
)
1807 /* Raising level, also raise it for prereqs */
1808 if ((warn
&& !c
->warn
) || (error
&& !c
->error
))
1809 for (i
= 0; i
< c
->num_prereqs
; i
++)
1810 enable_warning_error(c
->prereq
[i
], warn
, error
);
1812 c
->warn
= c
->warn
|| warn
;
1813 c
->error
= c
->error
|| error
;
1816 static void disable_warning_error(struct check
*c
, bool warn
, bool error
)
1820 /* Lowering level, also lower it for things this is the prereq
1822 if ((warn
&& c
->warn
) || (error
&& c
->error
)) {
1823 for (i
= 0; i
< ARRAY_SIZE(check_table
); i
++) {
1824 struct check
*cc
= check_table
[i
];
1827 for (j
= 0; j
< cc
->num_prereqs
; j
++)
1828 if (cc
->prereq
[j
] == c
)
1829 disable_warning_error(cc
, warn
, error
);
1833 c
->warn
= c
->warn
&& !warn
;
1834 c
->error
= c
->error
&& !error
;
1837 void parse_checks_option(bool warn
, bool error
, const char *arg
)
1840 const char *name
= arg
;
1843 if ((strncmp(arg
, "no-", 3) == 0)
1844 || (strncmp(arg
, "no_", 3) == 0)) {
1849 for (i
= 0; i
< ARRAY_SIZE(check_table
); i
++) {
1850 struct check
*c
= check_table
[i
];
1852 if (streq(c
->name
, name
)) {
1854 enable_warning_error(c
, warn
, error
);
1856 disable_warning_error(c
, warn
, error
);
1861 die("Unrecognized check name \"%s\"\n", name
);
1864 void process_checks(bool force
, struct dt_info
*dti
)
1869 for (i
= 0; i
< ARRAY_SIZE(check_table
); i
++) {
1870 struct check
*c
= check_table
[i
];
1872 if (c
->warn
|| c
->error
)
1873 error
= error
|| run_check(c
, dti
);
1878 fprintf(stderr
, "ERROR: Input tree has errors, aborting "
1879 "(use -f to force output)\n");
1881 } else if (quiet
< 3) {
1882 fprintf(stderr
, "Warning: Input tree has errors, "