Lines Matching defs:node
31 typedef void (*check_fn)(struct check *c, struct dt_info *dti, struct node *node);
61 check_msg(struct check *c, struct dt_info *dti, struct node *node, struct property *prop, const char *fmt, ...)
74 } else if (node && node->srcpos) {
75 pos = node->srcpos;
90 if (node) {
92 xasprintf_append(&str, "%s:%s: ", node->fullpath, prop->name);
94 xasprintf_append(&str, "%s: ", node->fullpath);
105 pos = node->srcpos;
118 #define FAIL(c, dti, node, ...) \
122 check_msg((c), dti, node, NULL, __VA_ARGS__); \
125 #define FAIL_PROP(c, dti, node, prop, ...) \
129 check_msg((c), dti, node, prop, __VA_ARGS__); \
132 static void check_nodes_props(struct check *c, struct dt_info *dti, struct node *node)
134 struct node *child;
136 TRACE(c, "%s", node->fullpath);
138 c->fn(c, dti, node);
141 for_each_child(node, child) check_nodes_props(c, dti, child);
146 struct node *dt = dti->dt;
192 static inline void check_always_fail(struct check *c, struct dt_info *dti, struct node *node)
194 FAIL(c, dti, node, "always_fail check");
198 static void check_is_string(struct check *c, struct dt_info *dti, struct node *node)
203 prop = get_property(node, propname);
209 FAIL_PROP(c, dti, node, prop, "property is not a string");
215 static void check_is_string_list(struct check *c, struct dt_info *dti, struct node *node)
222 prop = get_property(node, propname);
232 FAIL_PROP(c, dti, node, prop, "property is not a string list");
242 static void check_is_cell(struct check *c, struct dt_info *dti, struct node *node)
247 prop = get_property(node, propname);
253 FAIL_PROP(c, dti, node, prop, "property is not a single cell");
263 static void check_duplicate_node_names(struct check *c, struct dt_info *dti, struct node *node)
265 struct node *child, *child2;
267 for_each_child(node, child) {
271 FAIL(c, dti, child2, "Duplicate node name");
277 static void check_duplicate_property_names(struct check *c, struct dt_info *dti, struct node *node)
281 for_each_property(node, prop)
288 FAIL_PROP(c, dti, node, prop, "Duplicate property name");
301 static void check_node_name_chars(struct check *c, struct dt_info *dti, struct node *node)
303 int n = strspn(node->name, c->data);
304 if (n < strlen(node->name)) {
305 FAIL(c, dti, node, "Bad character '%c' in node name", node->name[n]);
310 static void check_node_name_chars_strict(struct check *c, struct dt_info *dti, struct node *node)
312 int n = strspn(node->name, c->data);
313 if (n < node->basenamelen) {
314 FAIL(c, dti, node, "Character '%c' not recommended in node name", node->name[n]);
319 static void check_node_name_format(struct check *c, struct dt_info *dti, struct node *node)
321 if (strchr(get_unitname(node), '@')) {
322 FAIL(c, dti, node, "multiple '@' characters in node name");
327 static void check_unit_address_vs_reg(struct check *c, struct dt_info *dti, struct node *node)
329 const char *unitname = get_unitname(node);
330 struct property *prop = get_property(node, "reg");
332 if (get_subnode(node, "__overlay__")) {
338 prop = get_property(node, "ranges");
346 FAIL(c, dti, node, "node has a reg or ranges property, but no unit name");
350 FAIL(c, dti, node, "node has a unit name, but no reg or ranges property");
356 static void check_property_name_chars(struct check *c, struct dt_info *dti, struct node *node)
360 for_each_property(node, prop)
364 FAIL_PROP(c, dti, node, prop, "Bad character '%c' in property name", prop->name[n]);
370 static void check_property_name_chars_strict(struct check *c, struct dt_info *dti, struct node *node)
374 for_each_property(node, prop)
396 FAIL_PROP(c, dti, node, prop, "Character '%c' not recommended in property name", name[n]);
403 #define DESCLABEL_ARGS(node, prop, mark) \
405 (node)->fullpath
407 static void check_duplicate_label(struct check *c, struct dt_info *dti, const char *label, struct node *node,
410 struct node *dt = dti->dt;
411 struct node *othernode = NULL;
427 if ((othernode != node) || (otherprop != prop) || (othermark != mark)) {
428 FAIL(c, dti, node, "Duplicate label '%s' on " DESCLABEL_FMT " and " DESCLABEL_FMT, label,
429 DESCLABEL_ARGS(node, prop, mark), DESCLABEL_ARGS(othernode, otherprop, othermark));
433 static void check_duplicate_label_node(struct check *c, struct dt_info *dti, struct node *node)
438 for_each_label(node->labels, l) check_duplicate_label(c, dti, l->label, node, NULL, NULL);
440 for_each_property(node, prop)
444 for_each_label(prop->labels, l) check_duplicate_label(c, dti, l->label, node, prop, NULL);
446 for_each_marker_of_type(m, LABEL) check_duplicate_label(c, dti, m->ref, node, prop, m);
451 static cell_t check_phandle_prop(struct check *c, struct dt_info *dti, struct node *node, const char *propname)
453 struct node *root = dti->dt;
458 prop = get_property(node, propname);
464 FAIL_PROP(c, dti, node, prop, "bad length (%d) %s property", prop->val.len, prop->name);
472 if (node != get_node_by_ref(root, m->ref)) {
473 /* "Set this node's phandle equal to some
474 * other node's phandle". That's nonsensical
476 FAIL(c, dti, node, "%s is a reference to another node", prop->name);
478 /* But setting this node's phandle equal to its own
480 * phandle for this node, even if it's not otherwise
488 FAIL_PROP(c, dti, node, prop, "bad value (0x%x) in %s property", phandle, prop->name);
495 static void check_explicit_phandles(struct check *c, struct dt_info *dti, struct node *node)
497 struct node *root = dti->dt;
498 struct node *other;
502 assert(!node->phandle);
504 phandle = check_phandle_prop(c, dti, node, "phandle");
506 linux_phandle = check_phandle_prop(c, dti, node, "linux,phandle");
513 FAIL(c, dti, node,
523 if (other && (other != node)) {
524 FAIL(c, dti, node, "duplicated phandle 0x%x (seen before at %s)", phandle, other->fullpath);
528 node->phandle = phandle;
532 static void check_name_properties(struct check *c, struct dt_info *dti, struct node *node)
536 for (pp = &node->proplist; *pp; pp = &((*pp)->next)) {
547 if ((prop->val.len != node->basenamelen + 1) || (memcmp(prop->val.val, node->name, node->basenamelen) != 0)) {
548 FAIL(c, dti, node,
550 " of base node name)",
568 static void fixup_phandle_references(struct check *c, struct dt_info *dti, struct node *node)
570 struct node *dt = dti->dt;
573 for_each_property(node, prop)
576 struct node *refnode;
586 FAIL(c, dti, node,
587 "Reference to non-existent node or "
605 static void fixup_path_references(struct check *c, struct dt_info *dti, struct node *node)
607 struct node *dt = dti->dt;
610 for_each_property(node, prop)
613 struct node *refnode;
622 FAIL(c, dti, node, "Reference to non-existent node or label \"%s\"\n", m->ref);
635 static void fixup_omit_unused_nodes(struct check *c, struct dt_info *dti, struct node *node)
637 if (generate_symbols && node->labels) {
640 if (node->omit_if_unused && !node->is_referenced) {
641 delete_node(node);
644 if (node->deleted) {
645 struct node *parent = node->parent;
646 struct node *child;
675 static void check_names_is_string_list(struct check *c, struct dt_info *dti, struct node *node)
679 for_each_property(node, prop)
687 check_is_string_list(c, dti, node);
692 static void check_alias_paths(struct check *c, struct dt_info *dti, struct node *node)
696 if (!streq(node->name, "aliases")) {
700 for_each_property(node, prop)
707 FAIL_PROP(c, dti, node, prop, "aliases property is not a valid node (%s)", prop->val.val);
711 FAIL(c, dti, node, "aliases property name must include only lowercase and '-'");
717 static void fixup_addr_size_cells(struct check *c, struct dt_info *dti, struct node *node)
721 node->addr_cells = -1;
722 node->size_cells = -1;
724 prop = get_property(node, "#address-cells");
726 node->addr_cells = propval_cell(prop);
729 prop = get_property(node, "#size-cells");
731 node->size_cells = propval_cell(prop);
766 static void check_reg_format(struct check *c, struct dt_info *dti, struct node *node)
771 prop = get_property(node, "reg");
776 if (!node->parent) {
777 FAIL(c, dti, node, "Root node has a \"reg\" property");
782 FAIL_PROP(c, dti, node, prop, "property is empty");
785 addr_cells = node_addr_cells(node->parent);
786 size_cells = node_size_cells(node->parent);
790 FAIL_PROP(c, dti, node, prop,
798 static void check_ranges_format(struct check *c, struct dt_info *dti, struct node *node)
804 prop = get_property(node, ranges);
809 if (!node->parent) {
810 FAIL_PROP(c, dti, node, prop, "Root node has a \"%s\" property", ranges);
814 p_addr_cells = node_addr_cells(node->parent);
815 p_size_cells = node_size_cells(node->parent);
816 c_addr_cells = node_addr_cells(node);
817 c_size_cells = node_size_cells(node);
822 FAIL_PROP(c, dti, node, prop,
825 ranges, c_addr_cells, node->parent->fullpath, p_addr_cells);
828 FAIL_PROP(c, dti, node, prop,
831 ranges, c_size_cells, node->parent->fullpath, p_size_cells);
834 FAIL_PROP(c, dti, node, prop,
848 static void check_pci_bridge(struct check *c, struct dt_info *dti, struct node *node)
853 prop = get_property(node, "device_type");
858 node->bus = &pci_bus;
860 if (!strprefixeq(node->name, node->basenamelen, "pci") && !strprefixeq(node->name, node->basenamelen, "pcie")) {
861 FAIL(c, dti, node, "node name is not \"pci\" or \"pcie\"");
864 prop = get_property(node, "ranges");
866 FAIL(c, dti, node, "missing ranges for PCI bridge (or not a bridge)");
869 if (node_addr_cells(node) != PCI_ADDRESS_CELLS_THREE) {
870 FAIL(c, dti, node, "incorrect #address-cells for PCI bridge");
872 if (node_size_cells(node) != PCI_ADDRESS_CELLS_TWO) {
873 FAIL(c, dti, node, "incorrect #size-cells for PCI bridge");
876 prop = get_property(node, "bus-range");
882 FAIL_PROP(c, dti, node, prop, "value must be 2 cells");
887 FAIL_PROP(c, dti, node, prop, "1st cell must be less than or equal to 2nd cell");
890 FAIL_PROP(c, dti, node, prop, "maximum bus number must be less than 256");
895 static void check_pci_device_bus_num(struct check *c, struct dt_info *dti, struct node *node)
901 if (!node->parent || (node->parent->bus != &pci_bus)) {
905 prop = get_property(node, "reg");
913 prop = get_property(node->parent, "bus-range");
922 FAIL_PROP(c, dti, node, prop, "PCI bus number %d out of range, expected (%d - %d)", bus_num, min_bus, max_bus);
927 static void check_pci_device_reg(struct check *c, struct dt_info *dti, struct node *node)
930 const char *unitname = get_unitname(node);
935 if (!node->parent || (node->parent->bus != &pci_bus)) {
939 prop = get_property(node, "reg");
946 FAIL_PROP(c, dti, node, prop, "PCI reg config space address cells 2 and 3 must be 0");
954 FAIL_PROP(c, dti, node, prop, "PCI reg address is not configuration space");
957 FAIL_PROP(c, dti, node, prop, "PCI reg config space address register number must be 0");
972 FAIL(c, dti, node, "PCI unit address format error, expected \"%s\"", unit_addr);
980 static bool node_is_compatible(struct node *node, const char *compat)
985 prop = get_property(node, "compatible");
998 static void check_simple_bus_bridge(struct check *c, struct dt_info *dti, struct node *node)
1000 if (node_is_compatible(node, "simple-bus")) {
1001 node->bus = &simple_bus;
1006 static void check_simple_bus_reg(struct check *c, struct dt_info *dti, struct node *node)
1009 const char *unitname = get_unitname(node);
1015 if (!node->parent || (node->parent->bus != &simple_bus)) {
1019 prop = get_property(node, "reg");
1023 prop = get_property(node, "ranges");
1026 cells = ((cell_t *)prop->val.val) + node_addr_cells(node);
1031 if (node->parent->parent && !(node->bus == &simple_bus)) {
1032 FAIL(c, dti, node, "missing or empty reg/ranges property");
1037 size = node_addr_cells(node->parent);
1044 FAIL(c, dti, node, "simple-bus unit address format error, expected \"%s\"", unit_addr);
1053 static void check_i2c_bus_bridge(struct check *c, struct dt_info *dti, struct node *node)
1055 if (strprefixeq(node->name, node->basenamelen, "i2c-bus") ||
1056 strprefixeq(node->name, node->basenamelen, "i2c-arb")) {
1057 node->bus = &i2c_bus;
1058 } else if (strprefixeq(node->name, node->basenamelen, "i2c")) {
1059 struct node *child;
1060 for_each_child(node, child)
1062 if (strprefixeq(child->name, node->basenamelen, "i2c-bus")) {
1066 node->bus = &i2c_bus;
1071 if (!node->children) {
1075 if (node_addr_cells(node) != 1) {
1076 FAIL(c, dti, node, "incorrect #address-cells for I2C bus");
1078 if (node_size_cells(node) != 0) {
1079 FAIL(c, dti, node, "incorrect #size-cells for I2C bus");
1087 static void check_i2c_bus_reg(struct check *c, struct dt_info *dti, struct node *node)
1090 const char *unitname = get_unitname(node);
1096 if (!node->parent || (node->parent->bus != &i2c_bus)) {
1100 prop = get_property(node, "reg");
1106 FAIL(c, dti, node, "missing or empty reg property");
1115 FAIL(c, dti, node, "I2C bus unit address format error, expected \"%s\"", unit_addr);
1124 FAIL_PROP(c, dti, node, prop, "I2C address must be less than 10-bits, got \"0x%x\"", reg);
1126 FAIL_PROP(c, dti, node, prop,
1139 static void check_spi_bus_bridge(struct check *c, struct dt_info *dti, struct node *node)
1143 if (strprefixeq(node->name, node->basenamelen, "spi")) {
1144 node->bus = &spi_bus;
1146 /* Try to detect SPI buses which don't have proper node name */
1147 struct node *child;
1149 if (node_addr_cells(node) != 1 || node_size_cells(node) != 0) {
1153 for_each_child(node, child)
1159 node->bus = &spi_bus;
1163 if (node->bus == &spi_bus) {
1168 if (node->bus == &spi_bus && get_property(node, "reg")) {
1169 FAIL(c, dti, node, "node name for SPI buses should be 'spi'");
1172 if (node->bus != &spi_bus || !node->children) {
1176 if (get_property(node, "spi-slave")) {
1179 if (node_addr_cells(node) != spi_addr_cells) {
1180 FAIL(c, dti, node, "incorrect #address-cells for SPI bus");
1182 if (node_size_cells(node) != 0) {
1183 FAIL(c, dti, node, "incorrect #size-cells for SPI bus");
1188 static void check_spi_bus_reg(struct check *c, struct dt_info *dti, struct node *node)
1191 const char *unitname = get_unitname(node);
1196 if (!node->parent || (node->parent->bus != &spi_bus)) {
1200 if (get_property(node->parent, "spi-slave")) {
1204 prop = get_property(node, "reg");
1210 FAIL(c, dti, node, "missing or empty reg property");
1217 FAIL(c, dti, node, "SPI bus unit address format error, expected \"%s\"", unit_addr);
1222 static void check_unit_address_format(struct check *c, struct dt_info *dti, struct node *node)
1224 const char *unitname = get_unitname(node);
1226 if (node->parent && node->parent->bus) {
1235 FAIL(c, dti, node, "unit name should not have leading \"0x\"");
1241 FAIL(c, dti, node, "unit name should not have leading 0s");
1249 static void check_avoid_default_addr_size(struct check *c, struct dt_info *dti, struct node *node)
1253 if (!node->parent) {
1254 return; /* Ignore root node */
1257 reg = get_property(node, "reg");
1258 ranges = get_property(node, "ranges");
1263 if (node->parent->addr_cells == -1) {
1264 FAIL(c, dti, node, "Relying on default #address-cells value");
1267 if (node->parent->size_cells == -1) {
1268 FAIL(c, dti, node, "Relying on default #size-cells value");
1273 static void check_avoid_unnecessary_addr_size(struct check *c, struct dt_info *dti, struct node *node)
1276 struct node *child;
1279 if (!node->parent || node->addr_cells < 0 || node->size_cells < 0) {
1283 if (get_property(node, "ranges") || !node->children) {
1287 for_each_child(node, child)
1296 FAIL(c, dti, node, "unnecessary #address-cells/#size-cells without \"ranges\" or child \"reg\" property");
1301 static bool node_is_disabled(struct node *node)
1305 prop = get_property(node, "status");
1316 static void check_unique_unit_address_common(struct check *c, struct dt_info *dti, struct node *node,
1319 struct node *childa;
1321 if (node->addr_cells < 0 || node->size_cells < 0) {
1325 if (!node->children) {
1329 for_each_child(node, childa)
1331 struct node *childb;
1342 for_each_child(node, childb)
1354 FAIL(c, dti, childb, "duplicate unit-address (also used in node %s)", childa->fullpath);
1360 static void check_unique_unit_address(struct check *c, struct dt_info *dti, struct node *node)
1362 check_unique_unit_address_common(c, dti, node, false);
1366 static void check_unique_unit_address_if_enabled(struct check *c, struct dt_info *dti, struct node *node)
1368 check_unique_unit_address_common(c, dti, node, true);
1373 static void check_obsolete_chosen_interrupt_controller(struct check *c, struct dt_info *dti, struct node *node)
1375 struct node *dt = dti->dt;
1376 struct node *chosen;
1379 if (node != dt) {
1390 FAIL_PROP(c, dti, node, prop, "/chosen has obsolete \"interrupt-controller\" property");
1395 static void check_chosen_node_is_root(struct check *c, struct dt_info *dti, struct node *node)
1397 if (!streq(node->name, "chosen")) {
1401 if (node->parent != dti->dt) {
1402 FAIL(c, dti, node, "chosen node must be at root node");
1407 static void check_chosen_node_bootargs(struct check *c, struct dt_info *dti, struct node *node)
1411 if (!streq(node->name, "chosen")) {
1415 prop = get_property(node, "bootargs");
1421 check_is_string(c, dti, node);
1425 static void check_chosen_node_stdout_path(struct check *c, struct dt_info *dti, struct node *node)
1429 if (!streq(node->name, "chosen")) {
1433 prop = get_property(node, "stdout-path");
1435 prop = get_property(node, "linux,stdout-path");
1439 FAIL_PROP(c, dti, node, prop, "Use 'stdout-path' instead");
1443 check_is_string(c, dti, node);
1453 static void check_property_phandle_args(struct check *c, struct dt_info *dti, struct node *node, struct property *prop,
1456 struct node *root = dti->dt;
1460 FAIL_PROP(c, dti, node, prop, "property size (%d) is invalid, expected multiple of %zu", prop->val.len,
1466 struct node *provider_node;
1495 FAIL_PROP(c, dti, node, prop, "cell %d is not a phandle reference", cell);
1501 FAIL_PROP(c, dti, node, prop, "Could not get phandle node for (cell %d)", cell);
1511 FAIL(c, dti, node, "Missing property '%s' in node %s or bad phandle (referred from %s[%d])",
1517 FAIL_PROP(c, dti, node, prop, "property size (%d) too small for cell size %d", prop->val.len, cellsize);
1522 static void check_provider_cells_property(struct check *c, struct dt_info *dti, struct node *node)
1527 prop = get_property(node, provider->prop_name);
1532 check_property_phandle_args(c, dti, node, prop, provider);
1580 static void check_gpios_property(struct check *c, struct dt_info *dti, struct node *node)
1585 if (get_property(node, "gpio-hog")) {
1589 for_each_property(node, prop)
1600 check_property_phandle_args(c, dti, node, prop, &provider);
1605 static void check_deprecated_gpio_property(struct check *c, struct dt_info *dti, struct node *node)
1609 for_each_property(node, prop)
1622 FAIL_PROP(c, dti, node, prop, "'[*-]gpio' is deprecated, use '[*-]gpios' instead");
1627 static bool node_is_interrupt_provider(struct node *node)
1631 prop = get_property(node, "interrupt-controller");
1636 prop = get_property(node, "interrupt-map");
1644 static void check_interrupt_provider(struct check *c, struct dt_info *dti, struct node *node)
1648 if (!node_is_interrupt_provider(node)) {
1652 prop = get_property(node, "#interrupt-cells");
1654 FAIL(c, dti, node, "Missing #interrupt-cells in interrupt provider");
1657 prop = get_property(node, "#address-cells");
1659 FAIL(c, dti, node, "Missing #address-cells in interrupt provider");
1664 static void check_interrupts_property(struct check *c, struct dt_info *dti, struct node *node)
1666 struct node *root = dti->dt;
1667 struct node *irq_node = NULL, *parent = node;
1671 irq_prop = get_property(node, "interrupts");
1677 FAIL_PROP(c, dti, node, irq_prop, "size (%d) is invalid, expected multiple of %zu", irq_prop->val.len,
1682 if (parent != node && node_is_interrupt_provider(parent)) {
1716 FAIL(c, dti, node, "Missing interrupt-parent");
1728 FAIL_PROP(c, dti, node, prop, "size is (%d), expected multiple of %d", irq_prop->val.len,
1742 static void check_graph_nodes(struct check *c, struct dt_info *dti, struct node *node)
1744 struct node *child;
1746 for_each_child(node, child)
1752 node->bus = &graph_port_bus;
1755 if (!node->parent->bus && (streq(node->parent->name, "ports") || get_property(node, "reg"))) {
1756 node->parent->bus = &graph_ports_bus;
1764 static void check_graph_child_address(struct check *c, struct dt_info *dti, struct node *node)
1767 struct node *child;
1769 if (node->bus != &graph_ports_bus && node->bus != &graph_port_bus) {
1773 for_each_child(node, child)
1785 if (cnt == 1 && node->addr_cells != -1) {
1786 FAIL(c, dti, node, "graph node has single child node '%s', #address-cells/#size-cells are not necessary",
1787 node->children->name);
1792 static void check_graph_reg(struct check *c, struct dt_info *dti, struct node *node)
1795 const char *unitname = get_unitname(node);
1798 prop = get_property(node, "reg");
1804 FAIL(c, dti, node, "graph node malformed 'reg' property");
1810 FAIL(c, dti, node, "graph node unit address error, expected \"%s\"", unit_addr);
1813 if (node->parent->addr_cells != 1) {
1814 FAIL_PROP(c, dti, node, get_property(node, "#address-cells"), "graph node '#address-cells' is %d, must be 1",
1815 node->parent->addr_cells);
1817 if (node->parent->size_cells != 0) {
1818 FAIL_PROP(c, dti, node, get_property(node, "#size-cells"), "graph node '#size-cells' is %d, must be 0",
1819 node->parent->size_cells);
1823 static void check_graph_port(struct check *c, struct dt_info *dti, struct node *node)
1825 if (node->bus != &graph_port_bus) {
1829 if (!strprefixeq(node->name, node->basenamelen, "port")) {
1830 FAIL(c, dti, node, "graph port node name should be 'port'");
1833 check_graph_reg(c, dti, node);
1837 static struct node *get_remote_endpoint(struct check *c, struct dt_info *dti, struct node *endpoint)
1840 struct node *node;
1854 node = get_node_by_phandle(dti->dt, phandle);
1855 if (!node) {
1859 return node;
1862 static void check_graph_endpoint(struct check *c, struct dt_info *dti, struct node *node)
1864 struct node *remote_node;
1866 if (!node->parent || node->parent->bus != &graph_port_bus) {
1870 if (!strprefixeq(node->name, node->basenamelen, "endpoint")) {
1871 FAIL(c, dti, node, "graph endpoint node name should be 'endpoint'");
1874 check_graph_reg(c, dti, node);
1876 remote_node = get_remote_endpoint(c, dti, node);
1881 if (get_remote_endpoint(c, dti, remote_node) != node) {
1882 FAIL(c, dti, node, "graph connection to node '%s' is not bidirectional", remote_node->fullpath);