| 1 | |
| 2 | |
| 3 | * (C) Copyright David Gibson <[email protected]>, IBM Corporation. 2007.
|
| 4 |
|
| 5 |
|
| 6 | #include "dtc.h"
|
| 7 | #include "srcpos.h"
|
| 8 |
|
| 9 | #ifdef TRACE_CHECKS
|
| 10 | #define TRACE(c, ...) \
|
| 11 | do { \
|
| 12 | fprintf(stderr, "=== %s: ", (c)->name); \
|
| 13 | fprintf(stderr, __VA_ARGS__); \
|
| 14 | fprintf(stderr, "\n"); \
|
| 15 | } while (0)
|
| 16 | #else
|
| 17 | #define TRACE(c, fmt, ...) do { } while (0)
|
| 18 | #endif
|
| 19 |
|
| 20 | enum checkstatus {
|
| 21 | UNCHECKED = 0,
|
| 22 | PREREQ,
|
| 23 | PASSED,
|
| 24 | FAILED,
|
| 25 | };
|
| 26 |
|
| 27 | struct check;
|
| 28 |
|
| 29 | typedef void (*check_fn)(struct check *c, struct dt_info *dti, struct node *node);
|
| 30 |
|
| 31 | struct check {
|
| 32 | const char *name;
|
| 33 | check_fn fn;
|
| 34 | const void *data;
|
| 35 | bool warn, error;
|
| 36 | enum checkstatus status;
|
| 37 | bool inprogress;
|
| 38 | int num_prereqs;
|
| 39 | struct check **prereq;
|
| 40 | };
|
| 41 |
|
| 42 | #define CHECK_ENTRY(nm_, fn_, d_, w_, e_, ...) \
|
| 43 | static struct check *nm_##_prereqs[] = { __VA_ARGS__ }; \
|
| 44 | static struct check nm_ = { \
|
| 45 | .name = #nm_, \
|
| 46 | .fn = (fn_), \
|
| 47 | .data = (d_), \
|
| 48 | .warn = (w_), \
|
| 49 | .error = (e_), \
|
| 50 | .status = UNCHECKED, \
|
| 51 | .num_prereqs = ARRAY_SIZE(nm_##_prereqs), \
|
| 52 | .prereq = nm_##_prereqs, \
|
| 53 | };
|
| 54 | #define WARNING(nm_, fn_, d_, ...) \
|
| 55 | CHECK_ENTRY(nm_, fn_, d_, true, false, __VA_ARGS__)
|
| 56 | #define ERROR(nm_, fn_, d_, ...) \
|
| 57 | CHECK_ENTRY(nm_, fn_, d_, false, true, __VA_ARGS__)
|
| 58 | #define CHECK(nm_, fn_, d_, ...) \
|
| 59 | CHECK_ENTRY(nm_, fn_, d_, false, false, __VA_ARGS__)
|
| 60 |
|
| 61 | static inline void PRINTF(5, 6) check_msg(struct check *c, struct dt_info *dti,
|
| 62 | struct node *node,
|
| 63 | struct property *prop,
|
| 64 | const char *fmt, ...)
|
| 65 | {
|
| 66 | va_list ap;
|
| 67 | char *str = NULL;
|
| 68 | struct srcpos *pos = NULL;
|
| 69 | char *file_str;
|
| 70 |
|
| 71 | if (!(c->warn && (quiet < 1)) && !(c->error && (quiet < 2)))
|
| 72 | return;
|
| 73 |
|
| 74 | if (prop && prop->srcpos)
|
| 75 | pos = prop->srcpos;
|
| 76 | else if (node && node->srcpos)
|
| 77 | pos = node->srcpos;
|
| 78 |
|
| 79 | if (pos) {
|
| 80 | file_str = srcpos_string(pos);
|
| 81 | xasprintf(&str, "%s", file_str);
|
| 82 | free(file_str);
|
| 83 | } else if (streq(dti->outname, "-")) {
|
| 84 | xasprintf(&str, "<stdout>");
|
| 85 | } else {
|
| 86 | xasprintf(&str, "%s", dti->outname);
|
| 87 | }
|
| 88 |
|
| 89 | xasprintf_append(&str, ": %s (%s): ",
|
| 90 | (c->error) ? "ERROR" : "Warning", c->name);
|
| 91 |
|
| 92 | if (node) {
|
| 93 | if (prop)
|
| 94 | xasprintf_append(&str, "%s:%s: ", node->fullpath, prop->name);
|
| 95 | else
|
| 96 | xasprintf_append(&str, "%s: ", node->fullpath);
|
| 97 | }
|
| 98 |
|
| 99 | va_start(ap, fmt);
|
| 100 | xavsprintf_append(&str, fmt, ap);
|
| 101 | va_end(ap);
|
| 102 |
|
| 103 | xasprintf_append(&str, "\n");
|
| 104 |
|
| 105 | if (!prop && pos) {
|
| 106 | pos = node->srcpos;
|
| 107 | while (pos->next) {
|
| 108 | pos = pos->next;
|
| 109 |
|
| 110 | file_str = srcpos_string(pos);
|
| 111 | xasprintf_append(&str, " also defined at %s\n", file_str);
|
| 112 | free(file_str);
|
| 113 | }
|
| 114 | }
|
| 115 |
|
| 116 | fputs(str, stderr);
|
| 117 | free(str);
|
| 118 | }
|
| 119 |
|
| 120 | #define FAIL(c, dti, node, ...) \
|
| 121 | do { \
|
| 122 | TRACE((c), "\t\tFAILED at %s:%d", __FILE__, __LINE__); \
|
| 123 | (c)->status = FAILED; \
|
| 124 | check_msg((c), dti, node, NULL, __VA_ARGS__); \
|
| 125 | } while (0)
|
| 126 |
|
| 127 | #define FAIL_PROP(c, dti, node, prop, ...) \
|
| 128 | do { \
|
| 129 | TRACE((c), "\t\tFAILED at %s:%d", __FILE__, __LINE__); \
|
| 130 | (c)->status = FAILED; \
|
| 131 | check_msg((c), dti, node, prop, __VA_ARGS__); \
|
| 132 | } while (0)
|
| 133 |
|
| 134 |
|
| 135 | static void check_nodes_props(struct check *c, struct dt_info *dti, struct node *node)
|
| 136 | {
|
| 137 | struct node *child;
|
| 138 |
|
| 139 | TRACE(c, "%s", node->fullpath);
|
| 140 | if (c->fn)
|
| 141 | c->fn(c, dti, node);
|
| 142 |
|
| 143 | for_each_child(node, child)
|
| 144 | check_nodes_props(c, dti, child);
|
| 145 | }
|
| 146 |
|
| 147 | static bool is_multiple_of(int multiple, int divisor)
|
| 148 | {
|
| 149 | if (divisor == 0)
|
| 150 | return multiple == 0;
|
| 151 | else
|
| 152 | return (multiple % divisor) == 0;
|
| 153 | }
|
| 154 |
|
| 155 | static bool run_check(struct check *c, struct dt_info *dti)
|
| 156 | {
|
| 157 | struct node *dt = dti->dt;
|
| 158 | bool error = false;
|
| 159 | int i;
|
| 160 |
|
| 161 | assert(!c->inprogress);
|
| 162 |
|
| 163 | if (c->status != UNCHECKED)
|
| 164 | goto out;
|
| 165 |
|
| 166 | c->inprogress = true;
|
| 167 |
|
| 168 | for (i = 0; i < c->num_prereqs; i++) {
|
| 169 | struct check *prq = c->prereq[i];
|
| 170 | error = error || run_check(prq, dti);
|
| 171 | if (prq->status != PASSED) {
|
| 172 | c->status = PREREQ;
|
| 173 | check_msg(c, dti, NULL, NULL, "Failed prerequisite '%s'",
|
| 174 | c->prereq[i]->name);
|
| 175 | }
|
| 176 | }
|
| 177 |
|
| 178 | if (c->status != UNCHECKED)
|
| 179 | goto out;
|
| 180 |
|
| 181 | check_nodes_props(c, dti, dt);
|
| 182 |
|
| 183 | if (c->status == UNCHECKED)
|
| 184 | c->status = PASSED;
|
| 185 |
|
| 186 | TRACE(c, "\tCompleted, status %d", c->status);
|
| 187 |
|
| 188 | out:
|
| 189 | c->inprogress = false;
|
| 190 | if ((c->status != PASSED) && (c->error))
|
| 191 | error = true;
|
| 192 | return error;
|
| 193 | }
|
| 194 |
|
| 195 | |
| 196 | * Utility check functions
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 | static inline void check_always_fail(struct check *c, struct dt_info *dti,
|
| 201 | struct node *node)
|
| 202 | {
|
| 203 | FAIL(c, dti, node, "always_fail check");
|
| 204 | }
|
| 205 | CHECK(always_fail, check_always_fail, NULL);
|
| 206 |
|
| 207 | static void check_is_string(struct check *c, struct dt_info *dti,
|
| 208 | struct node *node)
|
| 209 | {
|
| 210 | struct property *prop;
|
| 211 | const char *propname = c->data;
|
| 212 |
|
| 213 | prop = get_property(node, propname);
|
| 214 | if (!prop)
|
| 215 | return;
|
| 216 |
|
| 217 | if (!data_is_one_string(prop->val))
|
| 218 | FAIL_PROP(c, dti, node, prop, "property is not a string");
|
| 219 | }
|
| 220 | #define WARNING_IF_NOT_STRING(nm, propname) \
|
| 221 | WARNING(nm, check_is_string, (propname))
|
| 222 | #define ERROR_IF_NOT_STRING(nm, propname) \
|
| 223 | ERROR(nm, check_is_string, (propname))
|
| 224 |
|
| 225 | static void check_is_string_list(struct check *c, struct dt_info *dti,
|
| 226 | struct node *node)
|
| 227 | {
|
| 228 | int rem, l;
|
| 229 | struct property *prop;
|
| 230 | const char *propname = c->data;
|
| 231 | char *str;
|
| 232 |
|
| 233 | prop = get_property(node, propname);
|
| 234 | if (!prop)
|
| 235 | return;
|
| 236 |
|
| 237 | str = prop->val.val;
|
| 238 | rem = prop->val.len;
|
| 239 | while (rem > 0) {
|
| 240 | l = strnlen(str, rem);
|
| 241 | if (l == rem) {
|
| 242 | FAIL_PROP(c, dti, node, prop, "property is not a string list");
|
| 243 | break;
|
| 244 | }
|
| 245 | rem -= l + 1;
|
| 246 | str += l + 1;
|
| 247 | }
|
| 248 | }
|
| 249 | #define WARNING_IF_NOT_STRING_LIST(nm, propname) \
|
| 250 | WARNING(nm, check_is_string_list, (propname))
|
| 251 | #define ERROR_IF_NOT_STRING_LIST(nm, propname) \
|
| 252 | ERROR(nm, check_is_string_list, (propname))
|
| 253 |
|
| 254 | static void check_is_cell(struct check *c, struct dt_info *dti,
|
| 255 | struct node *node)
|
| 256 | {
|
| 257 | struct property *prop;
|
| 258 | const char *propname = c->data;
|
| 259 |
|
| 260 | prop = get_property(node, propname);
|
| 261 | if (!prop)
|
| 262 | return;
|
| 263 |
|
| 264 | if (prop->val.len != sizeof(cell_t))
|
| 265 | FAIL_PROP(c, dti, node, prop, "property is not a single cell");
|
| 266 | }
|
| 267 | #define WARNING_IF_NOT_CELL(nm, propname) \
|
| 268 | WARNING(nm, check_is_cell, (propname))
|
| 269 | #define ERROR_IF_NOT_CELL(nm, propname) \
|
| 270 | ERROR(nm, check_is_cell, (propname))
|
| 271 |
|
| 272 | |
| 273 | * Structural check functions
|
| 274 |
|
| 275 |
|
| 276 | static void check_duplicate_node_names(struct check *c, struct dt_info *dti,
|
| 277 | struct node *node)
|
| 278 | {
|
| 279 | struct node *child, *child2;
|
| 280 |
|
| 281 | for_each_child(node, child)
|
| 282 | for (child2 = child->next_sibling;
|
| 283 | child2;
|
| 284 | child2 = child2->next_sibling)
|
| 285 | if (streq(child->name, child2->name))
|
| 286 | FAIL(c, dti, child2, "Duplicate node name");
|
| 287 | }
|
| 288 | ERROR(duplicate_node_names, check_duplicate_node_names, NULL);
|
| 289 |
|
| 290 | static void check_duplicate_property_names(struct check *c, struct dt_info *dti,
|
| 291 | struct node *node)
|
| 292 | {
|
| 293 | struct property *prop, *prop2;
|
| 294 |
|
| 295 | for_each_property(node, prop) {
|
| 296 | for (prop2 = prop->next; prop2; prop2 = prop2->next) {
|
| 297 | if (prop2->deleted)
|
| 298 | continue;
|
| 299 | if (streq(prop->name, prop2->name))
|
| 300 | FAIL_PROP(c, dti, node, prop, "Duplicate property name");
|
| 301 | }
|
| 302 | }
|
| 303 | }
|
| 304 | ERROR(duplicate_property_names, check_duplicate_property_names, NULL);
|
| 305 |
|
| 306 | #define LOWERCASE "abcdefghijklmnopqrstuvwxyz"
|
| 307 | #define UPPERCASE "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
| 308 | #define DIGITS "0123456789"
|
| 309 | #define NODECHARS LOWERCASE UPPERCASE DIGITS ",._+-@"
|
| 310 | #define PROPCHARS LOWERCASE UPPERCASE DIGITS ",._+*#?-"
|
| 311 | #define PROPNODECHARSSTRICT LOWERCASE UPPERCASE DIGITS ",-"
|
| 312 |
|
| 313 | static void check_node_name_chars(struct check *c, struct dt_info *dti,
|
| 314 | struct node *node)
|
| 315 | {
|
| 316 | size_t n = strspn(node->name, c->data);
|
| 317 |
|
| 318 | if (n < strlen(node->name))
|
| 319 | FAIL(c, dti, node, "Bad character '%c' in node name",
|
| 320 | node->name[n]);
|
| 321 | }
|
| 322 | ERROR(node_name_chars, check_node_name_chars, NODECHARS);
|
| 323 |
|
| 324 | static void check_node_name_chars_strict(struct check *c, struct dt_info *dti,
|
| 325 | struct node *node)
|
| 326 | {
|
| 327 | size_t n = strspn(node->name, c->data);
|
| 328 |
|
| 329 | if (n < node->basenamelen)
|
| 330 | FAIL(c, dti, node, "Character '%c' not recommended in node name",
|
| 331 | node->name[n]);
|
| 332 | }
|
| 333 | CHECK(node_name_chars_strict, check_node_name_chars_strict, PROPNODECHARSSTRICT);
|
| 334 |
|
| 335 | static void check_node_name_format(struct check *c, struct dt_info *dti,
|
| 336 | struct node *node)
|
| 337 | {
|
| 338 | if (strchr(get_unitname(node), '@'))
|
| 339 | FAIL(c, dti, node, "multiple '@' characters in node name");
|
| 340 | }
|
| 341 | ERROR(node_name_format, check_node_name_format, NULL, &node_name_chars);
|
| 342 |
|
| 343 | static void check_node_name_not_empty(struct check *c, struct dt_info *dti,
|
| 344 | struct node *node)
|
| 345 | {
|
| 346 | if (node->basenamelen == 0 && node->parent != NULL)
|
| 347 | FAIL(c, dti, node, "Empty node name");
|
| 348 | }
|
| 349 | ERROR(node_name_not_empty, check_node_name_not_empty, NULL, &node_name_chars);
|
| 350 |
|
| 351 | static void check_node_name_vs_property_name(struct check *c,
|
| 352 | struct dt_info *dti,
|
| 353 | struct node *node)
|
| 354 | {
|
| 355 | if (!node->parent)
|
| 356 | return;
|
| 357 |
|
| 358 | if (get_property(node->parent, node->name)) {
|
| 359 | FAIL(c, dti, node, "node name and property name conflict");
|
| 360 | }
|
| 361 | }
|
| 362 | WARNING(node_name_vs_property_name, check_node_name_vs_property_name,
|
| 363 | NULL, &node_name_chars);
|
| 364 |
|
| 365 | static void check_unit_address_vs_reg(struct check *c, struct dt_info *dti,
|
| 366 | struct node *node)
|
| 367 | {
|
| 368 | const char *unitname = get_unitname(node);
|
| 369 | struct property *prop = get_property(node, "reg");
|
| 370 |
|
| 371 | if (get_subnode(node, "__overlay__")) {
|
| 372 |
|
| 373 | return;
|
| 374 | }
|
| 375 |
|
| 376 | if (!prop) {
|
| 377 | prop = get_property(node, "ranges");
|
| 378 | if (prop && !prop->val.len)
|
| 379 | prop = NULL;
|
| 380 | }
|
| 381 |
|
| 382 | if (prop) {
|
| 383 | if (!unitname[0])
|
| 384 | FAIL(c, dti, node, "node has a reg or ranges property, but no unit name");
|
| 385 | } else {
|
| 386 | if (unitname[0])
|
| 387 | FAIL(c, dti, node, "node has a unit name, but no reg or ranges property");
|
| 388 | }
|
| 389 | }
|
| 390 | WARNING(unit_address_vs_reg, check_unit_address_vs_reg, NULL);
|
| 391 |
|
| 392 | static void check_property_name_chars(struct check *c, struct dt_info *dti,
|
| 393 | struct node *node)
|
| 394 | {
|
| 395 | struct property *prop;
|
| 396 |
|
| 397 | for_each_property(node, prop) {
|
| 398 | size_t n = strspn(prop->name, c->data);
|
| 399 |
|
| 400 | if (n < strlen(prop->name))
|
| 401 | FAIL_PROP(c, dti, node, prop, "Bad character '%c' in property name",
|
| 402 | prop->name[n]);
|
| 403 | }
|
| 404 | }
|
| 405 | ERROR(property_name_chars, check_property_name_chars, PROPCHARS);
|
| 406 |
|
| 407 | static void check_property_name_chars_strict(struct check *c,
|
| 408 | struct dt_info *dti,
|
| 409 | struct node *node)
|
| 410 | {
|
| 411 | struct property *prop;
|
| 412 |
|
| 413 | for_each_property(node, prop) {
|
| 414 | const char *name = prop->name;
|
| 415 | size_t n = strspn(name, c->data);
|
| 416 |
|
| 417 | if (n == strlen(prop->name))
|
| 418 | continue;
|
| 419 |
|
| 420 |
|
| 421 | if (streq(name, "device_type"))
|
| 422 | continue;
|
| 423 |
|
| 424 | |
| 425 | * # is only allowed at the beginning of property names not counting
|
| 426 | * the vendor prefix.
|
| 427 |
|
| 428 | if (name[n] == '#' && ((n == 0) || (name[n-1] == ','))) {
|
| 429 | name += n + 1;
|
| 430 | n = strspn(name, c->data);
|
| 431 | }
|
| 432 | if (n < strlen(name))
|
| 433 | FAIL_PROP(c, dti, node, prop, "Character '%c' not recommended in property name",
|
| 434 | name[n]);
|
| 435 | }
|
| 436 | }
|
| 437 | CHECK(property_name_chars_strict, check_property_name_chars_strict, PROPNODECHARSSTRICT);
|
| 438 |
|
| 439 | #define DESCLABEL_FMT "%s%s%s%s%s"
|
| 440 | #define DESCLABEL_ARGS(node,prop,mark) \
|
| 441 | ((mark) ? "value of " : ""), \
|
| 442 | ((prop) ? "'" : ""), \
|
| 443 | ((prop) ? (prop)->name : ""), \
|
| 444 | ((prop) ? "' in " : ""), (node)->fullpath
|
| 445 |
|
| 446 | static void check_duplicate_label(struct check *c, struct dt_info *dti,
|
| 447 | const char *label, struct node *node,
|
| 448 | struct property *prop, struct marker *mark)
|
| 449 | {
|
| 450 | struct node *dt = dti->dt;
|
| 451 | struct node *othernode = NULL;
|
| 452 | struct property *otherprop = NULL;
|
| 453 | struct marker *othermark = NULL;
|
| 454 |
|
| 455 | othernode = get_node_by_label(dt, label);
|
| 456 |
|
| 457 | if (!othernode)
|
| 458 | otherprop = get_property_by_label(dt, label, &othernode);
|
| 459 | if (!othernode)
|
| 460 | othermark = get_marker_label(dt, label, &othernode,
|
| 461 | &otherprop);
|
| 462 |
|
| 463 | if (!othernode)
|
| 464 | return;
|
| 465 |
|
| 466 | if ((othernode != node) || (otherprop != prop) || (othermark != mark))
|
| 467 | FAIL(c, dti, node, "Duplicate label '%s' on " DESCLABEL_FMT
|
| 468 | " and " DESCLABEL_FMT,
|
| 469 | label, DESCLABEL_ARGS(node, prop, mark),
|
| 470 | DESCLABEL_ARGS(othernode, otherprop, othermark));
|
| 471 | }
|
| 472 |
|
| 473 | static void check_duplicate_label_node(struct check *c, struct dt_info *dti,
|
| 474 | struct node *node)
|
| 475 | {
|
| 476 | struct label *l;
|
| 477 | struct property *prop;
|
| 478 |
|
| 479 | for_each_label(node->labels, l)
|
| 480 | check_duplicate_label(c, dti, l->label, node, NULL, NULL);
|
| 481 |
|
| 482 | for_each_property(node, prop) {
|
| 483 | struct marker *m = prop->val.markers;
|
| 484 |
|
| 485 | for_each_label(prop->labels, l)
|
| 486 | check_duplicate_label(c, dti, l->label, node, prop, NULL);
|
| 487 |
|
| 488 | for_each_marker_of_type(m, LABEL)
|
| 489 | check_duplicate_label(c, dti, m->ref, node, prop, m);
|
| 490 | }
|
| 491 | }
|
| 492 | ERROR(duplicate_label, check_duplicate_label_node, NULL);
|
| 493 |
|
| 494 | static cell_t check_phandle_prop(struct check *c, struct dt_info *dti,
|
| 495 | struct node *node, const char *propname)
|
| 496 | {
|
| 497 | struct node *root = dti->dt;
|
| 498 | struct property *prop;
|
| 499 | struct marker *m;
|
| 500 | cell_t phandle;
|
| 501 |
|
| 502 | prop = get_property(node, propname);
|
| 503 | if (!prop)
|
| 504 | return 0;
|
| 505 |
|
| 506 | if (prop->val.len != sizeof(cell_t)) {
|
| 507 | FAIL_PROP(c, dti, node, prop, "bad length (%d) %s property",
|
| 508 | prop->val.len, prop->name);
|
| 509 | return 0;
|
| 510 | }
|
| 511 |
|
| 512 | m = prop->val.markers;
|
| 513 | for_each_marker_of_type(m, REF_PHANDLE) {
|
| 514 | assert(m->offset == 0);
|
| 515 | if (node != get_node_by_ref(root, m->ref))
|
| 516 | |
| 517 | * other node's phandle". That's nonsensical
|
| 518 | * by construction. {
|
| 519 | FAIL(c, dti, node, "%s is a reference to another node",
|
| 520 | prop->name);
|
| 521 | }
|
| 522 | |
| 523 | * phandle is allowed - that means allocate a unique
|
| 524 | * phandle for this node, even if it's not otherwise
|
| 525 | * referenced. The value will be filled in later, so
|
| 526 | * we treat it as having no phandle data for now.
|
| 527 | return 0;
|
| 528 | }
|
| 529 |
|
| 530 | phandle = propval_cell(prop);
|
| 531 |
|
| 532 | if (!phandle_is_valid(phandle)) {
|
| 533 | FAIL_PROP(c, dti, node, prop, "bad value (0x%x) in %s property",
|
| 534 | phandle, prop->name);
|
| 535 | return 0;
|
| 536 | }
|
| 537 |
|
| 538 | return phandle;
|
| 539 | }
|
| 540 |
|
| 541 | static void check_explicit_phandles(struct check *c, struct dt_info *dti,
|
| 542 | struct node *node)
|
| 543 | {
|
| 544 | struct node *root = dti->dt;
|
| 545 | struct node *other;
|
| 546 | cell_t phandle, linux_phandle;
|
| 547 |
|
| 548 |
|
| 549 | assert(!node->phandle);
|
| 550 |
|
| 551 | phandle = check_phandle_prop(c, dti, node, "phandle");
|
| 552 |
|
| 553 | linux_phandle = check_phandle_prop(c, dti, node, "linux,phandle");
|
| 554 |
|
| 555 | if (!phandle && !linux_phandle)
|
| 556 |
|
| 557 | return;
|
| 558 |
|
| 559 | if (linux_phandle && phandle && (phandle != linux_phandle))
|
| 560 | FAIL(c, dti, node, "mismatching 'phandle' and 'linux,phandle'"
|
| 561 | " properties");
|
| 562 |
|
| 563 | if (linux_phandle && !phandle)
|
| 564 | phandle = linux_phandle;
|
| 565 |
|
| 566 | other = get_node_by_phandle(root, phandle);
|
| 567 | if (other && (other != node)) {
|
| 568 | FAIL(c, dti, node, "duplicated phandle 0x%x (seen before at %s)",
|
| 569 | phandle, other->fullpath);
|
| 570 | return;
|
| 571 | }
|
| 572 |
|
| 573 | node->phandle = phandle;
|
| 574 | }
|
| 575 | ERROR(explicit_phandles, check_explicit_phandles, NULL);
|
| 576 |
|
| 577 | static void check_name_properties(struct check *c, struct dt_info *dti,
|
| 578 | struct node *node)
|
| 579 | {
|
| 580 | struct property **pp, *prop = NULL;
|
| 581 |
|
| 582 | for (pp = &node->proplist; *pp; pp = &((*pp)->next))
|
| 583 | if (streq((*pp)->name, "name")) {
|
| 584 | prop = *pp;
|
| 585 | break;
|
| 586 | }
|
| 587 |
|
| 588 | if (!prop)
|
| 589 | return;
|
| 590 |
|
| 591 | if ((prop->val.len != node->basenamelen + 1U)
|
| 592 | || (memcmp(prop->val.val, node->name, node->basenamelen) != 0)) {
|
| 593 | FAIL(c, dti, node, "\"name\" property is incorrect (\"%s\" instead"
|
| 594 | " of base node name)", prop->val.val);
|
| 595 | } else {
|
| 596 | |
| 597 | * Delete it
|
| 598 | *pp = prop->next;
|
| 599 | free(prop->name);
|
| 600 | data_free(prop->val);
|
| 601 | free(prop);
|
| 602 | }
|
| 603 | }
|
| 604 | ERROR_IF_NOT_STRING(name_is_string, "name");
|
| 605 | ERROR(name_properties, check_name_properties, NULL, &name_is_string);
|
| 606 |
|
| 607 | |
| 608 | * Reference fixup functions
|
| 609 |
|
| 610 |
|
| 611 | static void fixup_phandle_references(struct check *c, struct dt_info *dti,
|
| 612 | struct node *node)
|
| 613 | {
|
| 614 | struct node *dt = dti->dt;
|
| 615 | struct property *prop;
|
| 616 |
|
| 617 | for_each_property(node, prop) {
|
| 618 | struct marker *m = prop->val.markers;
|
| 619 | struct node *refnode;
|
| 620 | cell_t phandle;
|
| 621 |
|
| 622 | for_each_marker_of_type(m, REF_PHANDLE) {
|
| 623 | assert(m->offset + sizeof(cell_t) <= prop->val.len);
|
| 624 |
|
| 625 | refnode = get_node_by_ref(dt, m->ref);
|
| 626 | if (! refnode) {
|
| 627 | if (!(dti->dtsflags & DTSF_PLUGIN))
|
| 628 | FAIL(c, dti, node, "Reference to non-existent node or "
|
| 629 | "label \"%s\"\n", m->ref);
|
| 630 | else
|
| 631 | *((fdt32_t *)(prop->val.val + m->offset)) =
|
| 632 | cpu_to_fdt32(0xffffffff);
|
| 633 | continue;
|
| 634 | }
|
| 635 |
|
| 636 | phandle = get_node_phandle(dt, refnode);
|
| 637 | *((fdt32_t *)(prop->val.val + m->offset)) = cpu_to_fdt32(phandle);
|
| 638 |
|
| 639 | reference_node(refnode);
|
| 640 | }
|
| 641 | }
|
| 642 | }
|
| 643 | ERROR(phandle_references, fixup_phandle_references, NULL,
|
| 644 | &duplicate_node_names, &explicit_phandles);
|
| 645 |
|
| 646 | static void fixup_path_references(struct check *c, struct dt_info *dti,
|
| 647 | struct node *node)
|
| 648 | {
|
| 649 | struct node *dt = dti->dt;
|
| 650 | struct property *prop;
|
| 651 |
|
| 652 | for_each_property(node, prop) {
|
| 653 | struct marker *m = prop->val.markers;
|
| 654 | struct node *refnode;
|
| 655 | char *path;
|
| 656 |
|
| 657 | for_each_marker_of_type(m, REF_PATH) {
|
| 658 | assert(m->offset <= prop->val.len);
|
| 659 |
|
| 660 | refnode = get_node_by_ref(dt, m->ref);
|
| 661 | if (!refnode) {
|
| 662 | FAIL(c, dti, node, "Reference to non-existent node or label \"%s\"\n",
|
| 663 | m->ref);
|
| 664 | continue;
|
| 665 | }
|
| 666 |
|
| 667 | path = refnode->fullpath;
|
| 668 | prop->val = data_insert_at_marker(prop->val, m, path,
|
| 669 | strlen(path) + 1);
|
| 670 |
|
| 671 | reference_node(refnode);
|
| 672 | }
|
| 673 | }
|
| 674 | }
|
| 675 | ERROR(path_references, fixup_path_references, NULL, &duplicate_node_names);
|
| 676 |
|
| 677 | static void fixup_omit_unused_nodes(struct check *c, struct dt_info *dti,
|
| 678 | struct node *node)
|
| 679 | {
|
| 680 | if (generate_symbols && node->labels)
|
| 681 | return;
|
| 682 | if (node->omit_if_unused && !node->is_referenced)
|
| 683 | delete_node(node);
|
| 684 | }
|
| 685 | ERROR(omit_unused_nodes, fixup_omit_unused_nodes, NULL, &phandle_references, &path_references);
|
| 686 |
|
| 687 | |
| 688 | * Semantic checks
|
| 689 |
|
| 690 | WARNING_IF_NOT_CELL(address_cells_is_cell, "#address-cells");
|
| 691 | WARNING_IF_NOT_CELL(size_cells_is_cell, "#size-cells");
|
| 692 |
|
| 693 | WARNING_IF_NOT_STRING(device_type_is_string, "device_type");
|
| 694 | WARNING_IF_NOT_STRING(model_is_string, "model");
|
| 695 | WARNING_IF_NOT_STRING(status_is_string, "status");
|
| 696 | WARNING_IF_NOT_STRING(label_is_string, "label");
|
| 697 |
|
| 698 | WARNING_IF_NOT_STRING_LIST(compatible_is_string_list, "compatible");
|
| 699 |
|
| 700 | static void check_names_is_string_list(struct check *c, struct dt_info *dti,
|
| 701 | struct node *node)
|
| 702 | {
|
| 703 | struct property *prop;
|
| 704 |
|
| 705 | for_each_property(node, prop) {
|
| 706 | if (!strends(prop->name, "-names"))
|
| 707 | continue;
|
| 708 |
|
| 709 | c->data = prop->name;
|
| 710 | check_is_string_list(c, dti, node);
|
| 711 | }
|
| 712 | }
|
| 713 | WARNING(names_is_string_list, check_names_is_string_list, NULL);
|
| 714 |
|
| 715 | static void check_alias_paths(struct check *c, struct dt_info *dti,
|
| 716 | struct node *node)
|
| 717 | {
|
| 718 | struct property *prop;
|
| 719 |
|
| 720 | if (!streq(node->name, "aliases"))
|
| 721 | return;
|
| 722 |
|
| 723 | for_each_property(node, prop) {
|
| 724 | if (streq(prop->name, "phandle")
|
| 725 | || streq(prop->name, "linux,phandle")) {
|
| 726 | continue;
|
| 727 | }
|
| 728 |
|
| 729 |
|
| 730 | if (!(dti->dtsflags & DTSF_PLUGIN) &&
|
| 731 | (!prop->val.val || !get_node_by_path(dti->dt, prop->val.val))) {
|
| 732 | FAIL_PROP(c, dti, node, prop, "aliases property is not a valid node (%s)",
|
| 733 | prop->val.val);
|
| 734 | continue;
|
| 735 | }
|
| 736 |
|
| 737 | if (strspn(prop->name, LOWERCASE DIGITS "-") != strlen(prop->name))
|
| 738 | FAIL(c, dti, node, "aliases property name must include only lowercase and '-'");
|
| 739 | }
|
| 740 | }
|
| 741 | WARNING(alias_paths, check_alias_paths, NULL);
|
| 742 |
|
| 743 | static void fixup_addr_size_cells(struct check *c, struct dt_info *dti,
|
| 744 | struct node *node)
|
| 745 | {
|
| 746 | struct property *prop;
|
| 747 |
|
| 748 | node->addr_cells = -1;
|
| 749 | node->size_cells = -1;
|
| 750 |
|
| 751 | prop = get_property(node, "#address-cells");
|
| 752 | if (prop)
|
| 753 | node->addr_cells = propval_cell(prop);
|
| 754 |
|
| 755 | prop = get_property(node, "#size-cells");
|
| 756 | if (prop)
|
| 757 | node->size_cells = propval_cell(prop);
|
| 758 | }
|
| 759 | WARNING(addr_size_cells, fixup_addr_size_cells, NULL,
|
| 760 | &address_cells_is_cell, &size_cells_is_cell);
|
| 761 |
|
| 762 | #define node_addr_cells(n) \
|
| 763 | (((n)->addr_cells == -1) ? 2 : (n)->addr_cells)
|
| 764 | #define node_size_cells(n) \
|
| 765 | (((n)->size_cells == -1) ? 1 : (n)->size_cells)
|
| 766 |
|
| 767 | static void check_reg_format(struct check *c, struct dt_info *dti,
|
| 768 | struct node *node)
|
| 769 | {
|
| 770 | struct property *prop;
|
| 771 | int addr_cells, size_cells, entrylen;
|
| 772 |
|
| 773 | prop = get_property(node, "reg");
|
| 774 | if (!prop)
|
| 775 | return;
|
| 776 |
|
| 777 | if (!node->parent) {
|
| 778 | FAIL(c, dti, node, "Root node has a \"reg\" property");
|
| 779 | return;
|
| 780 | }
|
| 781 |
|
| 782 | if (prop->val.len == 0)
|
| 783 | FAIL_PROP(c, dti, node, prop, "property is empty");
|
| 784 |
|
| 785 | addr_cells = node_addr_cells(node->parent);
|
| 786 | size_cells = node_size_cells(node->parent);
|
| 787 | entrylen = (addr_cells + size_cells) * sizeof(cell_t);
|
| 788 |
|
| 789 | if (!is_multiple_of(prop->val.len, entrylen))
|
| 790 | FAIL_PROP(c, dti, node, prop, "property has invalid length (%d bytes) "
|
| 791 | "(#address-cells == %d, #size-cells == %d)",
|
| 792 | prop->val.len, addr_cells, size_cells);
|
| 793 | }
|
| 794 | WARNING(reg_format, check_reg_format, NULL, &addr_size_cells);
|
| 795 |
|
| 796 | static void check_ranges_format(struct check *c, struct dt_info *dti,
|
| 797 | struct node *node)
|
| 798 | {
|
| 799 | struct property *prop;
|
| 800 | int c_addr_cells, p_addr_cells, c_size_cells, p_size_cells, entrylen;
|
| 801 | const char *ranges = c->data;
|
| 802 |
|
| 803 | prop = get_property(node, ranges);
|
| 804 | if (!prop)
|
| 805 | return;
|
| 806 |
|
| 807 | if (!node->parent) {
|
| 808 | FAIL_PROP(c, dti, node, prop, "Root node has a \"%s\" property",
|
| 809 | ranges);
|
| 810 | return;
|
| 811 | }
|
| 812 |
|
| 813 | p_addr_cells = node_addr_cells(node->parent);
|
| 814 | p_size_cells = node_size_cells(node->parent);
|
| 815 | c_addr_cells = node_addr_cells(node);
|
| 816 | c_size_cells = node_size_cells(node);
|
| 817 | entrylen = (p_addr_cells + c_addr_cells + c_size_cells) * sizeof(cell_t);
|
| 818 |
|
| 819 | if (prop->val.len == 0) {
|
| 820 | if (p_addr_cells != c_addr_cells)
|
| 821 | FAIL_PROP(c, dti, node, prop, "empty \"%s\" property but its "
|
| 822 | "#address-cells (%d) differs from %s (%d)",
|
| 823 | ranges, c_addr_cells, node->parent->fullpath,
|
| 824 | p_addr_cells);
|
| 825 | if (p_size_cells != c_size_cells)
|
| 826 | FAIL_PROP(c, dti, node, prop, "empty \"%s\" property but its "
|
| 827 | "#size-cells (%d) differs from %s (%d)",
|
| 828 | ranges, c_size_cells, node->parent->fullpath,
|
| 829 | p_size_cells);
|
| 830 | } else if (!is_multiple_of(prop->val.len, entrylen)) {
|
| 831 | FAIL_PROP(c, dti, node, prop, "\"%s\" property has invalid length (%d bytes) "
|
| 832 | "(parent #address-cells == %d, child #address-cells == %d, "
|
| 833 | "#size-cells == %d)", ranges, prop->val.len,
|
| 834 | p_addr_cells, c_addr_cells, c_size_cells);
|
| 835 | }
|
| 836 | }
|
| 837 | WARNING(ranges_format, check_ranges_format, "ranges", &addr_size_cells);
|
| 838 | WARNING(dma_ranges_format, check_ranges_format, "dma-ranges", &addr_size_cells);
|
| 839 |
|
| 840 | static const struct bus_type pci_bus = {
|
| 841 | .name = "PCI",
|
| 842 | };
|
| 843 |
|
| 844 | static void check_pci_bridge(struct check *c, struct dt_info *dti, struct node *node)
|
| 845 | {
|
| 846 | struct property *prop;
|
| 847 | cell_t *cells;
|
| 848 |
|
| 849 | prop = get_property(node, "device_type");
|
| 850 | if (!prop || !streq(prop->val.val, "pci"))
|
| 851 | return;
|
| 852 |
|
| 853 | node->bus = &pci_bus;
|
| 854 |
|
| 855 | if (!strprefixeq(node->name, node->basenamelen, "pci") &&
|
| 856 | !strprefixeq(node->name, node->basenamelen, "pcie"))
|
| 857 | FAIL(c, dti, node, "node name is not \"pci\" or \"pcie\"");
|
| 858 |
|
| 859 | prop = get_property(node, "ranges");
|
| 860 | if (!prop)
|
| 861 | FAIL(c, dti, node, "missing ranges for PCI bridge (or not a bridge)");
|
| 862 |
|
| 863 | if (node_addr_cells(node) != 3)
|
| 864 | FAIL(c, dti, node, "incorrect #address-cells for PCI bridge");
|
| 865 | if (node_size_cells(node) != 2)
|
| 866 | FAIL(c, dti, node, "incorrect #size-cells for PCI bridge");
|
| 867 |
|
| 868 | prop = get_property(node, "bus-range");
|
| 869 | if (!prop)
|
| 870 | return;
|
| 871 |
|
| 872 | if (prop->val.len != (sizeof(cell_t) * 2)) {
|
| 873 | FAIL_PROP(c, dti, node, prop, "value must be 2 cells");
|
| 874 | return;
|
| 875 | }
|
| 876 | cells = (cell_t *)prop->val.val;
|
| 877 | if (fdt32_to_cpu(cells[0]) > fdt32_to_cpu(cells[1]))
|
| 878 | FAIL_PROP(c, dti, node, prop, "1st cell must be less than or equal to 2nd cell");
|
| 879 | if (fdt32_to_cpu(cells[1]) > 0xff)
|
| 880 | FAIL_PROP(c, dti, node, prop, "maximum bus number must be less than 256");
|
| 881 | }
|
| 882 | WARNING(pci_bridge, check_pci_bridge, NULL,
|
| 883 | &device_type_is_string, &addr_size_cells);
|
| 884 |
|
| 885 | static void check_pci_device_bus_num(struct check *c, struct dt_info *dti, struct node *node)
|
| 886 | {
|
| 887 | struct property *prop;
|
| 888 | unsigned int bus_num, min_bus, max_bus;
|
| 889 | cell_t *cells;
|
| 890 |
|
| 891 | if (!node->parent || (node->parent->bus != &pci_bus))
|
| 892 | return;
|
| 893 |
|
| 894 | prop = get_property(node, "reg");
|
| 895 | if (!prop)
|
| 896 | return;
|
| 897 |
|
| 898 | cells = (cell_t *)prop->val.val;
|
| 899 | bus_num = (fdt32_to_cpu(cells[0]) & 0x00ff0000) >> 16;
|
| 900 |
|
| 901 | prop = get_property(node->parent, "bus-range");
|
| 902 | if (!prop) {
|
| 903 | min_bus = max_bus = 0;
|
| 904 | } else {
|
| 905 | cells = (cell_t *)prop->val.val;
|
| 906 | min_bus = fdt32_to_cpu(cells[0]);
|
| 907 | max_bus = fdt32_to_cpu(cells[1]);
|
| 908 | }
|
| 909 | if ((bus_num < min_bus) || (bus_num > max_bus))
|
| 910 | FAIL_PROP(c, dti, node, prop, "PCI bus number %d out of range, expected (%d - %d)",
|
| 911 | bus_num, min_bus, max_bus);
|
| 912 | }
|
| 913 | WARNING(pci_device_bus_num, check_pci_device_bus_num, NULL, ®_format, &pci_bridge);
|
| 914 |
|
| 915 | static void check_pci_device_reg(struct check *c, struct dt_info *dti, struct node *node)
|
| 916 | {
|
| 917 | struct property *prop;
|
| 918 | const char *unitname = get_unitname(node);
|
| 919 | char unit_addr[5];
|
| 920 | unsigned int dev, func, reg;
|
| 921 | cell_t *cells;
|
| 922 |
|
| 923 | if (!node->parent || (node->parent->bus != &pci_bus))
|
| 924 | return;
|
| 925 |
|
| 926 | prop = get_property(node, "reg");
|
| 927 | if (!prop)
|
| 928 | return;
|
| 929 |
|
| 930 | cells = (cell_t *)prop->val.val;
|
| 931 | if (cells[1] || cells[2])
|
| 932 | FAIL_PROP(c, dti, node, prop, "PCI reg config space address cells 2 and 3 must be 0");
|
| 933 |
|
| 934 | reg = fdt32_to_cpu(cells[0]);
|
| 935 | dev = (reg & 0xf800) >> 11;
|
| 936 | func = (reg & 0x700) >> 8;
|
| 937 |
|
| 938 | if (reg & 0xff000000)
|
| 939 | FAIL_PROP(c, dti, node, prop, "PCI reg address is not configuration space");
|
| 940 | if (reg & 0x000000ff)
|
| 941 | FAIL_PROP(c, dti, node, prop, "PCI reg config space address register number must be 0");
|
| 942 |
|
| 943 | if (func == 0) {
|
| 944 | snprintf(unit_addr, sizeof(unit_addr), "%x", dev);
|
| 945 | if (streq(unitname, unit_addr))
|
| 946 | return;
|
| 947 | }
|
| 948 |
|
| 949 | snprintf(unit_addr, sizeof(unit_addr), "%x,%x", dev, func);
|
| 950 | if (streq(unitname, unit_addr))
|
| 951 | return;
|
| 952 |
|
| 953 | FAIL(c, dti, node, "PCI unit address format error, expected \"%s\"",
|
| 954 | unit_addr);
|
| 955 | }
|
| 956 | WARNING(pci_device_reg, check_pci_device_reg, NULL, ®_format, &pci_bridge);
|
| 957 |
|
| 958 | static const struct bus_type simple_bus = {
|
| 959 | .name = "simple-bus",
|
| 960 | };
|
| 961 |
|
| 962 | static bool node_is_compatible(struct node *node, const char *compat)
|
| 963 | {
|
| 964 | struct property *prop;
|
| 965 | const char *str, *end;
|
| 966 |
|
| 967 | prop = get_property(node, "compatible");
|
| 968 | if (!prop)
|
| 969 | return false;
|
| 970 |
|
| 971 | for (str = prop->val.val, end = str + prop->val.len; str < end;
|
| 972 | str += strnlen(str, end - str) + 1) {
|
| 973 | if (streq(str, compat))
|
| 974 | return true;
|
| 975 | }
|
| 976 | return false;
|
| 977 | }
|
| 978 |
|
| 979 | static void check_simple_bus_bridge(struct check *c, struct dt_info *dti, struct node *node)
|
| 980 | {
|
| 981 | if (node_is_compatible(node, "simple-bus"))
|
| 982 | node->bus = &simple_bus;
|
| 983 | }
|
| 984 | WARNING(simple_bus_bridge, check_simple_bus_bridge, NULL,
|
| 985 | &addr_size_cells, &compatible_is_string_list);
|
| 986 |
|
| 987 | static void check_simple_bus_reg(struct check *c, struct dt_info *dti, struct node *node)
|
| 988 | {
|
| 989 | struct property *prop;
|
| 990 | const char *unitname = get_unitname(node);
|
| 991 | char unit_addr[17];
|
| 992 | unsigned int size;
|
| 993 | uint64_t reg = 0;
|
| 994 | cell_t *cells = NULL;
|
| 995 |
|
| 996 | if (!node->parent || (node->parent->bus != &simple_bus))
|
| 997 | return;
|
| 998 |
|
| 999 | prop = get_property(node, "reg");
|
| 1000 | if (prop)
|
| 1001 | cells = (cell_t *)prop->val.val;
|
| 1002 | else {
|
| 1003 | prop = get_property(node, "ranges");
|
| 1004 | if (prop && prop->val.len)
|
| 1005 |
|
| 1006 | cells = ((cell_t *)prop->val.val) + node_addr_cells(node);
|
| 1007 | }
|
| 1008 |
|
| 1009 | if (!cells) {
|
| 1010 | if (node->parent->parent && !(node->bus == &simple_bus))
|
| 1011 | FAIL(c, dti, node, "missing or empty reg/ranges property");
|
| 1012 | return;
|
| 1013 | }
|
| 1014 |
|
| 1015 | size = node_addr_cells(node->parent);
|
| 1016 | while (size--)
|
| 1017 | reg = (reg << 32) | fdt32_to_cpu(*(cells++));
|
| 1018 |
|
| 1019 | snprintf(unit_addr, sizeof(unit_addr), "%"PRIx64, reg);
|
| 1020 | if (!streq(unitname, unit_addr))
|
| 1021 | FAIL(c, dti, node, "simple-bus unit address format error, expected \"%s\"",
|
| 1022 | unit_addr);
|
| 1023 | }
|
| 1024 | WARNING(simple_bus_reg, check_simple_bus_reg, NULL, ®_format, &simple_bus_bridge);
|
| 1025 |
|
| 1026 | static const struct bus_type i2c_bus = {
|
| 1027 | .name = "i2c-bus",
|
| 1028 | };
|
| 1029 |
|
| 1030 | static void check_i2c_bus_bridge(struct check *c, struct dt_info *dti, struct node *node)
|
| 1031 | {
|
| 1032 | if (strprefixeq(node->name, node->basenamelen, "i2c-bus") ||
|
| 1033 | strprefixeq(node->name, node->basenamelen, "i2c-arb")) {
|
| 1034 | node->bus = &i2c_bus;
|
| 1035 | } else if (strprefixeq(node->name, node->basenamelen, "i2c")) {
|
| 1036 | struct node *child;
|
| 1037 | for_each_child(node, child) {
|
| 1038 | if (strprefixeq(child->name, child->basenamelen, "i2c-bus"))
|
| 1039 | return;
|
| 1040 | }
|
| 1041 | node->bus = &i2c_bus;
|
| 1042 | } else
|
| 1043 | return;
|
| 1044 |
|
| 1045 | if (!node->children)
|
| 1046 | return;
|
| 1047 |
|
| 1048 | if (node_addr_cells(node) != 1)
|
| 1049 | FAIL(c, dti, node, "incorrect #address-cells for I2C bus");
|
| 1050 | if (node_size_cells(node) != 0)
|
| 1051 | FAIL(c, dti, node, "incorrect #size-cells for I2C bus");
|
| 1052 |
|
| 1053 | }
|
| 1054 | WARNING(i2c_bus_bridge, check_i2c_bus_bridge, NULL, &addr_size_cells);
|
| 1055 |
|
| 1056 | #define I2C_OWN_SLAVE_ADDRESS (1U << 30)
|
| 1057 | #define I2C_TEN_BIT_ADDRESS (1U << 31)
|
| 1058 |
|
| 1059 | static void check_i2c_bus_reg(struct check *c, struct dt_info *dti, struct node *node)
|
| 1060 | {
|
| 1061 | struct property *prop;
|
| 1062 | const char *unitname = get_unitname(node);
|
| 1063 | char unit_addr[17];
|
| 1064 | uint32_t reg = 0;
|
| 1065 | int len;
|
| 1066 | cell_t *cells = NULL;
|
| 1067 |
|
| 1068 | if (!node->parent || (node->parent->bus != &i2c_bus))
|
| 1069 | return;
|
| 1070 |
|
| 1071 | prop = get_property(node, "reg");
|
| 1072 | if (prop)
|
| 1073 | cells = (cell_t *)prop->val.val;
|
| 1074 |
|
| 1075 | if (!cells) {
|
| 1076 | FAIL(c, dti, node, "missing or empty reg property");
|
| 1077 | return;
|
| 1078 | }
|
| 1079 |
|
| 1080 | reg = fdt32_to_cpu(*cells);
|
| 1081 |
|
| 1082 | reg &= ~I2C_OWN_SLAVE_ADDRESS;
|
| 1083 | snprintf(unit_addr, sizeof(unit_addr), "%x", reg);
|
| 1084 | if (!streq(unitname, unit_addr))
|
| 1085 | FAIL(c, dti, node, "I2C bus unit address format error, expected \"%s\"",
|
| 1086 | unit_addr);
|
| 1087 |
|
| 1088 | for (len = prop->val.len; len > 0; len -= 4) {
|
| 1089 | reg = fdt32_to_cpu(*(cells++));
|
| 1090 |
|
| 1091 | reg &= ~I2C_OWN_SLAVE_ADDRESS;
|
| 1092 |
|
| 1093 | if (reg & I2C_TEN_BIT_ADDRESS) {
|
| 1094 | if ((reg & ~I2C_TEN_BIT_ADDRESS) > 0x3ff)
|
| 1095 | FAIL_PROP(c, dti, node, prop, "I2C address must be less than 10-bits, got \"0x%x\"",
|
| 1096 | reg);
|
| 1097 | } else if (reg > 0x7f)
|
| 1098 | FAIL_PROP(c, dti, node, prop, "I2C address must be less than 7-bits, got \"0x%x\". Set I2C_TEN_BIT_ADDRESS for 10 bit addresses or fix the property",
|
| 1099 | reg);
|
| 1100 | }
|
| 1101 | }
|
| 1102 | WARNING(i2c_bus_reg, check_i2c_bus_reg, NULL, ®_format, &i2c_bus_bridge);
|
| 1103 |
|
| 1104 | static const struct bus_type spi_bus = {
|
| 1105 | .name = "spi-bus",
|
| 1106 | };
|
| 1107 |
|
| 1108 | static void check_spi_bus_bridge(struct check *c, struct dt_info *dti, struct node *node)
|
| 1109 | {
|
| 1110 | int spi_addr_cells = 1;
|
| 1111 |
|
| 1112 | if (strprefixeq(node->name, node->basenamelen, "spi")) {
|
| 1113 | node->bus = &spi_bus;
|
| 1114 | } else {
|
| 1115 |
|
| 1116 | struct node *child;
|
| 1117 |
|
| 1118 | if (node_addr_cells(node) != 1 || node_size_cells(node) != 0)
|
| 1119 | return;
|
| 1120 |
|
| 1121 | for_each_child(node, child) {
|
| 1122 | struct property *prop;
|
| 1123 | for_each_property(child, prop) {
|
| 1124 | if (strstarts(prop->name, "spi-")) {
|
| 1125 | node->bus = &spi_bus;
|
| 1126 | break;
|
| 1127 | }
|
| 1128 | }
|
| 1129 | if (node->bus == &spi_bus)
|
| 1130 | break;
|
| 1131 | }
|
| 1132 |
|
| 1133 | if (node->bus == &spi_bus && get_property(node, "reg"))
|
| 1134 | FAIL(c, dti, node, "node name for SPI buses should be 'spi'");
|
| 1135 | }
|
| 1136 | if (node->bus != &spi_bus || !node->children)
|
| 1137 | return;
|
| 1138 |
|
| 1139 | if (get_property(node, "spi-slave"))
|
| 1140 | spi_addr_cells = 0;
|
| 1141 | if (node_addr_cells(node) != spi_addr_cells)
|
| 1142 | FAIL(c, dti, node, "incorrect #address-cells for SPI bus");
|
| 1143 | if (node_size_cells(node) != 0)
|
| 1144 | FAIL(c, dti, node, "incorrect #size-cells for SPI bus");
|
| 1145 |
|
| 1146 | }
|
| 1147 | WARNING(spi_bus_bridge, check_spi_bus_bridge, NULL, &addr_size_cells);
|
| 1148 |
|
| 1149 | static void check_spi_bus_reg(struct check *c, struct dt_info *dti, struct node *node)
|
| 1150 | {
|
| 1151 | struct property *prop;
|
| 1152 | const char *unitname = get_unitname(node);
|
| 1153 | char unit_addr[9];
|
| 1154 | uint32_t reg = 0;
|
| 1155 | cell_t *cells = NULL;
|
| 1156 |
|
| 1157 | if (!node->parent || (node->parent->bus != &spi_bus))
|
| 1158 | return;
|
| 1159 |
|
| 1160 | if (get_property(node->parent, "spi-slave"))
|
| 1161 | return;
|
| 1162 |
|
| 1163 | prop = get_property(node, "reg");
|
| 1164 | if (prop)
|
| 1165 | cells = (cell_t *)prop->val.val;
|
| 1166 |
|
| 1167 | if (!cells) {
|
| 1168 | FAIL(c, dti, node, "missing or empty reg property");
|
| 1169 | return;
|
| 1170 | }
|
| 1171 |
|
| 1172 | reg = fdt32_to_cpu(*cells);
|
| 1173 | snprintf(unit_addr, sizeof(unit_addr), "%x", reg);
|
| 1174 | if (!streq(unitname, unit_addr))
|
| 1175 | FAIL(c, dti, node, "SPI bus unit address format error, expected \"%s\"",
|
| 1176 | unit_addr);
|
| 1177 | }
|
| 1178 | WARNING(spi_bus_reg, check_spi_bus_reg, NULL, ®_format, &spi_bus_bridge);
|
| 1179 |
|
| 1180 | static void check_unit_address_format(struct check *c, struct dt_info *dti,
|
| 1181 | struct node *node)
|
| 1182 | {
|
| 1183 | const char *unitname = get_unitname(node);
|
| 1184 |
|
| 1185 | if (node->parent && node->parent->bus)
|
| 1186 | return;
|
| 1187 |
|
| 1188 | if (!unitname[0])
|
| 1189 | return;
|
| 1190 |
|
| 1191 | if (!strncmp(unitname, "0x", 2)) {
|
| 1192 | FAIL(c, dti, node, "unit name should not have leading \"0x\"");
|
| 1193 |
|
| 1194 | unitname += 2;
|
| 1195 | }
|
| 1196 | if (unitname[0] == '0' && isxdigit((unsigned char)unitname[1]))
|
| 1197 | FAIL(c, dti, node, "unit name should not have leading 0s");
|
| 1198 | }
|
| 1199 | WARNING(unit_address_format, check_unit_address_format, NULL,
|
| 1200 | &node_name_format, &pci_bridge, &simple_bus_bridge);
|
| 1201 |
|
| 1202 | |
| 1203 | * Style checks
|
| 1204 |
|
| 1205 | static void check_avoid_default_addr_size(struct check *c, struct dt_info *dti,
|
| 1206 | struct node *node)
|
| 1207 | {
|
| 1208 | struct property *reg, *ranges;
|
| 1209 |
|
| 1210 | if (!node->parent)
|
| 1211 | return;
|
| 1212 |
|
| 1213 | reg = get_property(node, "reg");
|
| 1214 | ranges = get_property(node, "ranges");
|
| 1215 |
|
| 1216 | if (!reg && !ranges)
|
| 1217 | return;
|
| 1218 |
|
| 1219 | if (node->parent->addr_cells == -1)
|
| 1220 | FAIL(c, dti, node, "Relying on default #address-cells value");
|
| 1221 |
|
| 1222 | if (node->parent->size_cells == -1)
|
| 1223 | FAIL(c, dti, node, "Relying on default #size-cells value");
|
| 1224 | }
|
| 1225 | WARNING(avoid_default_addr_size, check_avoid_default_addr_size, NULL,
|
| 1226 | &addr_size_cells);
|
| 1227 |
|
| 1228 | static void check_avoid_unnecessary_addr_size(struct check *c, struct dt_info *dti,
|
| 1229 | struct node *node)
|
| 1230 | {
|
| 1231 | struct node *child;
|
| 1232 |
|
| 1233 | if (!node->parent || node->addr_cells < 0 || node->size_cells < 0)
|
| 1234 | return;
|
| 1235 |
|
| 1236 | if (get_property(node, "ranges") || get_property(node, "dma-ranges") || !node->children)
|
| 1237 | return;
|
| 1238 |
|
| 1239 | for_each_child(node, child) {
|
| 1240 | |
| 1241 | * Even if the child devices' address space is not mapped into
|
| 1242 | * the parent bus (no 'ranges' property on node), children can
|
| 1243 | * still have registers on a local bus, or map local addresses
|
| 1244 | * to another subordinate address space. The properties on the
|
| 1245 | * child nodes then make #address-cells/#size-cells necessary:
|
| 1246 |
|
| 1247 | if (get_property(child, "reg") || get_property(child, "ranges"))
|
| 1248 | return;
|
| 1249 | }
|
| 1250 |
|
| 1251 | FAIL(c, dti, node, "unnecessary #address-cells/#size-cells without \"ranges\", \"dma-ranges\" or child \"reg\" or \"ranges\" property");
|
| 1252 | }
|
| 1253 | WARNING(avoid_unnecessary_addr_size, check_avoid_unnecessary_addr_size, NULL, &avoid_default_addr_size);
|
| 1254 |
|
| 1255 | static bool node_is_disabled(struct node *node)
|
| 1256 | {
|
| 1257 | struct property *prop;
|
| 1258 |
|
| 1259 | prop = get_property(node, "status");
|
| 1260 | if (prop) {
|
| 1261 | char *str = prop->val.val;
|
| 1262 | if (streq("disabled", str))
|
| 1263 | return true;
|
| 1264 | }
|
| 1265 |
|
| 1266 | return false;
|
| 1267 | }
|
| 1268 |
|
| 1269 | static void check_unique_unit_address_common(struct check *c,
|
| 1270 | struct dt_info *dti,
|
| 1271 | struct node *node,
|
| 1272 | bool disable_check)
|
| 1273 | {
|
| 1274 | struct node *childa;
|
| 1275 |
|
| 1276 | if (node->addr_cells < 0 || node->size_cells < 0)
|
| 1277 | return;
|
| 1278 |
|
| 1279 | if (!node->children)
|
| 1280 | return;
|
| 1281 |
|
| 1282 | for_each_child(node, childa) {
|
| 1283 | struct node *childb;
|
| 1284 | const char *addr_a = get_unitname(childa);
|
| 1285 |
|
| 1286 | if (!strlen(addr_a))
|
| 1287 | continue;
|
| 1288 |
|
| 1289 | if (disable_check && node_is_disabled(childa))
|
| 1290 | continue;
|
| 1291 |
|
| 1292 | for_each_child(node, childb) {
|
| 1293 | const char *addr_b = get_unitname(childb);
|
| 1294 | if (childa == childb)
|
| 1295 | break;
|
| 1296 |
|
| 1297 | if (disable_check && node_is_disabled(childb))
|
| 1298 | continue;
|
| 1299 |
|
| 1300 | if (streq(addr_a, addr_b))
|
| 1301 | FAIL(c, dti, childb, "duplicate unit-address (also used in node %s)", childa->fullpath);
|
| 1302 | }
|
| 1303 | }
|
| 1304 | }
|
| 1305 |
|
| 1306 | static void check_unique_unit_address(struct check *c, struct dt_info *dti,
|
| 1307 | struct node *node)
|
| 1308 | {
|
| 1309 | check_unique_unit_address_common(c, dti, node, false);
|
| 1310 | }
|
| 1311 | WARNING(unique_unit_address, check_unique_unit_address, NULL, &avoid_default_addr_size);
|
| 1312 |
|
| 1313 | static void check_unique_unit_address_if_enabled(struct check *c, struct dt_info *dti,
|
| 1314 | struct node *node)
|
| 1315 | {
|
| 1316 | check_unique_unit_address_common(c, dti, node, true);
|
| 1317 | }
|
| 1318 | CHECK_ENTRY(unique_unit_address_if_enabled, check_unique_unit_address_if_enabled,
|
| 1319 | NULL, false, false, &avoid_default_addr_size);
|
| 1320 |
|
| 1321 | static void check_obsolete_chosen_interrupt_controller(struct check *c,
|
| 1322 | struct dt_info *dti,
|
| 1323 | struct node *node)
|
| 1324 | {
|
| 1325 | struct node *dt = dti->dt;
|
| 1326 | struct node *chosen;
|
| 1327 | struct property *prop;
|
| 1328 |
|
| 1329 | if (node != dt)
|
| 1330 | return;
|
| 1331 |
|
| 1332 |
|
| 1333 | chosen = get_node_by_path(dt, "/chosen");
|
| 1334 | if (!chosen)
|
| 1335 | return;
|
| 1336 |
|
| 1337 | prop = get_property(chosen, "interrupt-controller");
|
| 1338 | if (prop)
|
| 1339 | FAIL_PROP(c, dti, node, prop,
|
| 1340 | "/chosen has obsolete \"interrupt-controller\" property");
|
| 1341 | }
|
| 1342 | WARNING(obsolete_chosen_interrupt_controller,
|
| 1343 | check_obsolete_chosen_interrupt_controller, NULL);
|
| 1344 |
|
| 1345 | static void check_chosen_node_is_root(struct check *c, struct dt_info *dti,
|
| 1346 | struct node *node)
|
| 1347 | {
|
| 1348 | if (!streq(node->name, "chosen"))
|
| 1349 | return;
|
| 1350 |
|
| 1351 | if (node->parent != dti->dt)
|
| 1352 | FAIL(c, dti, node, "chosen node must be at root node");
|
| 1353 | }
|
| 1354 | WARNING(chosen_node_is_root, check_chosen_node_is_root, NULL);
|
| 1355 |
|
| 1356 | static void check_chosen_node_bootargs(struct check *c, struct dt_info *dti,
|
| 1357 | struct node *node)
|
| 1358 | {
|
| 1359 | struct property *prop;
|
| 1360 |
|
| 1361 | if (!streq(node->name, "chosen"))
|
| 1362 | return;
|
| 1363 |
|
| 1364 | prop = get_property(node, "bootargs");
|
| 1365 | if (!prop)
|
| 1366 | return;
|
| 1367 |
|
| 1368 | c->data = prop->name;
|
| 1369 | check_is_string(c, dti, node);
|
| 1370 | }
|
| 1371 | WARNING(chosen_node_bootargs, check_chosen_node_bootargs, NULL);
|
| 1372 |
|
| 1373 | static void check_chosen_node_stdout_path(struct check *c, struct dt_info *dti,
|
| 1374 | struct node *node)
|
| 1375 | {
|
| 1376 | struct property *prop;
|
| 1377 |
|
| 1378 | if (!streq(node->name, "chosen"))
|
| 1379 | return;
|
| 1380 |
|
| 1381 | prop = get_property(node, "stdout-path");
|
| 1382 | if (!prop) {
|
| 1383 | prop = get_property(node, "linux,stdout-path");
|
| 1384 | if (!prop)
|
| 1385 | return;
|
| 1386 | FAIL_PROP(c, dti, node, prop, "Use 'stdout-path' instead");
|
| 1387 | }
|
| 1388 |
|
| 1389 | c->data = prop->name;
|
| 1390 | check_is_string(c, dti, node);
|
| 1391 | }
|
| 1392 | WARNING(chosen_node_stdout_path, check_chosen_node_stdout_path, NULL);
|
| 1393 |
|
| 1394 | struct provider {
|
| 1395 | const char *prop_name;
|
| 1396 | const char *cell_name;
|
| 1397 | bool optional;
|
| 1398 | };
|
| 1399 |
|
| 1400 | static void check_property_phandle_args(struct check *c,
|
| 1401 | struct dt_info *dti,
|
| 1402 | struct node *node,
|
| 1403 | struct property *prop,
|
| 1404 | const struct provider *provider)
|
| 1405 | {
|
| 1406 | struct node *root = dti->dt;
|
| 1407 | unsigned int cell, cellsize = 0;
|
| 1408 |
|
| 1409 | if (!is_multiple_of(prop->val.len, sizeof(cell_t))) {
|
| 1410 | FAIL_PROP(c, dti, node, prop,
|
| 1411 | "property size (%d) is invalid, expected multiple of %zu",
|
| 1412 | prop->val.len, sizeof(cell_t));
|
| 1413 | return;
|
| 1414 | }
|
| 1415 |
|
| 1416 | for (cell = 0; cell < prop->val.len / sizeof(cell_t); cell += cellsize + 1) {
|
| 1417 | struct node *provider_node;
|
| 1418 | struct property *cellprop;
|
| 1419 | cell_t phandle;
|
| 1420 | unsigned int expected;
|
| 1421 |
|
| 1422 | phandle = propval_cell_n(prop, cell);
|
| 1423 | |
| 1424 | * Some bindings use a cell value 0 or -1 to skip over optional
|
| 1425 | * entries when each index position has a specific definition.
|
| 1426 |
|
| 1427 | if (!phandle_is_valid(phandle)) {
|
| 1428 |
|
| 1429 | if (dti->dtsflags & DTSF_PLUGIN)
|
| 1430 | break;
|
| 1431 |
|
| 1432 | cellsize = 0;
|
| 1433 | continue;
|
| 1434 | }
|
| 1435 |
|
| 1436 |
|
| 1437 | if (prop->val.markers) {
|
| 1438 | struct marker *m = prop->val.markers;
|
| 1439 | for_each_marker_of_type(m, REF_PHANDLE) {
|
| 1440 | if (m->offset == (cell * sizeof(cell_t)))
|
| 1441 | break;
|
| 1442 | }
|
| 1443 | if (!m)
|
| 1444 | FAIL_PROP(c, dti, node, prop,
|
| 1445 | "cell %d is not a phandle reference",
|
| 1446 | cell);
|
| 1447 | }
|
| 1448 |
|
| 1449 | provider_node = get_node_by_phandle(root, phandle);
|
| 1450 | if (!provider_node) {
|
| 1451 | FAIL_PROP(c, dti, node, prop,
|
| 1452 | "Could not get phandle node for (cell %d)",
|
| 1453 | cell);
|
| 1454 | break;
|
| 1455 | }
|
| 1456 |
|
| 1457 | cellprop = get_property(provider_node, provider->cell_name);
|
| 1458 | if (cellprop) {
|
| 1459 | cellsize = propval_cell(cellprop);
|
| 1460 | } else if (provider->optional) {
|
| 1461 | cellsize = 0;
|
| 1462 | } else {
|
| 1463 | FAIL(c, dti, node, "Missing property '%s' in node %s or bad phandle (referred from %s[%d])",
|
| 1464 | provider->cell_name,
|
| 1465 | provider_node->fullpath,
|
| 1466 | prop->name, cell);
|
| 1467 | break;
|
| 1468 | }
|
| 1469 |
|
| 1470 | expected = (cell + cellsize + 1) * sizeof(cell_t);
|
| 1471 | if ((expected <= cell) || prop->val.len < expected) {
|
| 1472 | FAIL_PROP(c, dti, node, prop,
|
| 1473 | "property size (%d) too small for cell size %u",
|
| 1474 | prop->val.len, cellsize);
|
| 1475 | break;
|
| 1476 | }
|
| 1477 | }
|
| 1478 | }
|
| 1479 |
|
| 1480 | static void check_provider_cells_property(struct check *c,
|
| 1481 | struct dt_info *dti,
|
| 1482 | struct node *node)
|
| 1483 | {
|
| 1484 | const struct provider *provider = c->data;
|
| 1485 | struct property *prop;
|
| 1486 |
|
| 1487 | prop = get_property(node, provider->prop_name);
|
| 1488 | if (!prop)
|
| 1489 | return;
|
| 1490 |
|
| 1491 | check_property_phandle_args(c, dti, node, prop, provider);
|
| 1492 | }
|
| 1493 | #define WARNING_PROPERTY_PHANDLE_CELLS(nm, propname, cells_name, ...) \
|
| 1494 | static struct provider nm##_provider = { (propname), (cells_name), __VA_ARGS__ }; \
|
| 1495 | WARNING_IF_NOT_CELL(nm##_is_cell, cells_name); \
|
| 1496 | WARNING(nm##_property, check_provider_cells_property, &nm##_provider, &nm##_is_cell, &phandle_references);
|
| 1497 |
|
| 1498 | WARNING_PROPERTY_PHANDLE_CELLS(clocks, "clocks", "#clock-cells");
|
| 1499 | WARNING_PROPERTY_PHANDLE_CELLS(cooling_device, "cooling-device", "#cooling-cells");
|
| 1500 | WARNING_PROPERTY_PHANDLE_CELLS(dmas, "dmas", "#dma-cells");
|
| 1501 | WARNING_PROPERTY_PHANDLE_CELLS(hwlocks, "hwlocks", "#hwlock-cells");
|
| 1502 | WARNING_PROPERTY_PHANDLE_CELLS(interrupts_extended, "interrupts-extended", "#interrupt-cells");
|
| 1503 | WARNING_PROPERTY_PHANDLE_CELLS(io_channels, "io-channels", "#io-channel-cells");
|
| 1504 | WARNING_PROPERTY_PHANDLE_CELLS(iommus, "iommus", "#iommu-cells");
|
| 1505 | WARNING_PROPERTY_PHANDLE_CELLS(mboxes, "mboxes", "#mbox-cells");
|
| 1506 | WARNING_PROPERTY_PHANDLE_CELLS(msi_parent, "msi-parent", "#msi-cells", true);
|
| 1507 | WARNING_PROPERTY_PHANDLE_CELLS(mux_controls, "mux-controls", "#mux-control-cells");
|
| 1508 | WARNING_PROPERTY_PHANDLE_CELLS(phys, "phys", "#phy-cells");
|
| 1509 | WARNING_PROPERTY_PHANDLE_CELLS(power_domains, "power-domains", "#power-domain-cells");
|
| 1510 | WARNING_PROPERTY_PHANDLE_CELLS(pwms, "pwms", "#pwm-cells");
|
| 1511 | WARNING_PROPERTY_PHANDLE_CELLS(resets, "resets", "#reset-cells");
|
| 1512 | WARNING_PROPERTY_PHANDLE_CELLS(sound_dai, "sound-dai", "#sound-dai-cells");
|
| 1513 | WARNING_PROPERTY_PHANDLE_CELLS(thermal_sensors, "thermal-sensors", "#thermal-sensor-cells");
|
| 1514 |
|
| 1515 | static bool prop_is_gpio(struct property *prop)
|
| 1516 | {
|
| 1517 | |
| 1518 | * *-gpios and *-gpio can appear in property names,
|
| 1519 | * so skip over any false matches (only one known ATM)
|
| 1520 |
|
| 1521 | if (strends(prop->name, ",nr-gpios"))
|
| 1522 | return false;
|
| 1523 |
|
| 1524 | return strends(prop->name, "-gpios") ||
|
| 1525 | streq(prop->name, "gpios") ||
|
| 1526 | strends(prop->name, "-gpio") ||
|
| 1527 | streq(prop->name, "gpio");
|
| 1528 | }
|
| 1529 |
|
| 1530 | static void check_gpios_property(struct check *c,
|
| 1531 | struct dt_info *dti,
|
| 1532 | struct node *node)
|
| 1533 | {
|
| 1534 | struct property *prop;
|
| 1535 |
|
| 1536 |
|
| 1537 | if (get_property(node, "gpio-hog"))
|
| 1538 | return;
|
| 1539 |
|
| 1540 | for_each_property(node, prop) {
|
| 1541 | struct provider provider;
|
| 1542 |
|
| 1543 | if (!prop_is_gpio(prop))
|
| 1544 | continue;
|
| 1545 |
|
| 1546 | provider.prop_name = prop->name;
|
| 1547 | provider.cell_name = "#gpio-cells";
|
| 1548 | provider.optional = false;
|
| 1549 | check_property_phandle_args(c, dti, node, prop, &provider);
|
| 1550 | }
|
| 1551 |
|
| 1552 | }
|
| 1553 | WARNING(gpios_property, check_gpios_property, NULL, &phandle_references);
|
| 1554 |
|
| 1555 | static void check_deprecated_gpio_property(struct check *c,
|
| 1556 | struct dt_info *dti,
|
| 1557 | struct node *node)
|
| 1558 | {
|
| 1559 | struct property *prop;
|
| 1560 |
|
| 1561 | for_each_property(node, prop) {
|
| 1562 | if (!prop_is_gpio(prop))
|
| 1563 | continue;
|
| 1564 |
|
| 1565 | if (!strends(prop->name, "gpio"))
|
| 1566 | continue;
|
| 1567 |
|
| 1568 | FAIL_PROP(c, dti, node, prop,
|
| 1569 | "'[*-]gpio' is deprecated, use '[*-]gpios' instead");
|
| 1570 | }
|
| 1571 |
|
| 1572 | }
|
| 1573 | CHECK(deprecated_gpio_property, check_deprecated_gpio_property, NULL);
|
| 1574 |
|
| 1575 | static bool node_is_interrupt_provider(struct node *node)
|
| 1576 | {
|
| 1577 | struct property *prop;
|
| 1578 |
|
| 1579 | prop = get_property(node, "interrupt-controller");
|
| 1580 | if (prop)
|
| 1581 | return true;
|
| 1582 |
|
| 1583 | prop = get_property(node, "interrupt-map");
|
| 1584 | if (prop)
|
| 1585 | return true;
|
| 1586 |
|
| 1587 | return false;
|
| 1588 | }
|
| 1589 |
|
| 1590 | static void check_interrupt_provider(struct check *c,
|
| 1591 | struct dt_info *dti,
|
| 1592 | struct node *node)
|
| 1593 | {
|
| 1594 | struct property *prop;
|
| 1595 | bool irq_provider = node_is_interrupt_provider(node);
|
| 1596 |
|
| 1597 | prop = get_property(node, "#interrupt-cells");
|
| 1598 | if (irq_provider && !prop) {
|
| 1599 | FAIL(c, dti, node,
|
| 1600 | "Missing '#interrupt-cells' in interrupt provider");
|
| 1601 | return;
|
| 1602 | }
|
| 1603 |
|
| 1604 | if (!irq_provider && prop) {
|
| 1605 | FAIL(c, dti, node,
|
| 1606 | "'#interrupt-cells' found, but node is not an interrupt provider");
|
| 1607 | return;
|
| 1608 | }
|
| 1609 | }
|
| 1610 | WARNING(interrupt_provider, check_interrupt_provider, NULL, &interrupts_extended_is_cell);
|
| 1611 |
|
| 1612 | static void check_interrupt_map(struct check *c,
|
| 1613 | struct dt_info *dti,
|
| 1614 | struct node *node)
|
| 1615 | {
|
| 1616 | struct node *root = dti->dt;
|
| 1617 | struct property *prop, *irq_map_prop;
|
| 1618 | size_t cellsize, cell, map_cells;
|
| 1619 |
|
| 1620 | irq_map_prop = get_property(node, "interrupt-map");
|
| 1621 | if (!irq_map_prop)
|
| 1622 | return;
|
| 1623 |
|
| 1624 | if (node->addr_cells < 0) {
|
| 1625 | FAIL(c, dti, node,
|
| 1626 | "Missing '#address-cells' in interrupt-map provider");
|
| 1627 | return;
|
| 1628 | }
|
| 1629 | cellsize = node_addr_cells(node);
|
| 1630 | cellsize += propval_cell(get_property(node, "#interrupt-cells"));
|
| 1631 |
|
| 1632 | prop = get_property(node, "interrupt-map-mask");
|
| 1633 | if (prop && (prop->val.len != (cellsize * sizeof(cell_t))))
|
| 1634 | FAIL_PROP(c, dti, node, prop,
|
| 1635 | "property size (%d) is invalid, expected %zu",
|
| 1636 | prop->val.len, cellsize * sizeof(cell_t));
|
| 1637 |
|
| 1638 | if (!is_multiple_of(irq_map_prop->val.len, sizeof(cell_t))) {
|
| 1639 | FAIL_PROP(c, dti, node, irq_map_prop,
|
| 1640 | "property size (%d) is invalid, expected multiple of %zu",
|
| 1641 | irq_map_prop->val.len, sizeof(cell_t));
|
| 1642 | return;
|
| 1643 | }
|
| 1644 |
|
| 1645 | map_cells = irq_map_prop->val.len / sizeof(cell_t);
|
| 1646 | for (cell = 0; cell < map_cells; ) {
|
| 1647 | struct node *provider_node;
|
| 1648 | struct property *cellprop;
|
| 1649 | int phandle;
|
| 1650 | size_t parent_cellsize;
|
| 1651 |
|
| 1652 | if ((cell + cellsize) >= map_cells) {
|
| 1653 | FAIL_PROP(c, dti, node, irq_map_prop,
|
| 1654 | "property size (%d) too small, expected > %zu",
|
| 1655 | irq_map_prop->val.len, (cell + cellsize) * sizeof(cell_t));
|
| 1656 | break;
|
| 1657 | }
|
| 1658 | cell += cellsize;
|
| 1659 |
|
| 1660 | phandle = propval_cell_n(irq_map_prop, cell);
|
| 1661 | if (!phandle_is_valid(phandle)) {
|
| 1662 |
|
| 1663 | if (!(dti->dtsflags & DTSF_PLUGIN))
|
| 1664 | FAIL_PROP(c, dti, node, irq_map_prop,
|
| 1665 | "Cell %zu is not a phandle(%d)",
|
| 1666 | cell, phandle);
|
| 1667 | break;
|
| 1668 | }
|
| 1669 |
|
| 1670 | provider_node = get_node_by_phandle(root, phandle);
|
| 1671 | if (!provider_node) {
|
| 1672 | FAIL_PROP(c, dti, node, irq_map_prop,
|
| 1673 | "Could not get phandle(%d) node for (cell %zu)",
|
| 1674 | phandle, cell);
|
| 1675 | break;
|
| 1676 | }
|
| 1677 |
|
| 1678 | cellprop = get_property(provider_node, "#interrupt-cells");
|
| 1679 | if (cellprop) {
|
| 1680 | parent_cellsize = propval_cell(cellprop);
|
| 1681 | } else {
|
| 1682 | FAIL(c, dti, node, "Missing property '#interrupt-cells' in node %s or bad phandle (referred from interrupt-map[%zu])",
|
| 1683 | provider_node->fullpath, cell);
|
| 1684 | break;
|
| 1685 | }
|
| 1686 |
|
| 1687 | cellprop = get_property(provider_node, "#address-cells");
|
| 1688 | if (cellprop)
|
| 1689 | parent_cellsize += propval_cell(cellprop);
|
| 1690 | else
|
| 1691 | FAIL_PROP(c, dti, node, irq_map_prop,
|
| 1692 | "Missing property '#address-cells' in node %s, using 0 as fallback",
|
| 1693 | provider_node->fullpath);
|
| 1694 |
|
| 1695 | cell += 1 + parent_cellsize;
|
| 1696 | if (cell > map_cells)
|
| 1697 | FAIL_PROP(c, dti, node, irq_map_prop,
|
| 1698 | "property size (%d) mismatch, expected %zu",
|
| 1699 | irq_map_prop->val.len, cell * sizeof(cell_t));
|
| 1700 | }
|
| 1701 | }
|
| 1702 | WARNING(interrupt_map, check_interrupt_map, NULL, &phandle_references, &addr_size_cells, &interrupt_provider);
|
| 1703 |
|
| 1704 | static void check_interrupts_property(struct check *c,
|
| 1705 | struct dt_info *dti,
|
| 1706 | struct node *node)
|
| 1707 | {
|
| 1708 | struct node *root = dti->dt;
|
| 1709 | struct node *irq_node = NULL, *parent = node;
|
| 1710 | struct property *irq_prop, *prop = NULL;
|
| 1711 | cell_t irq_cells, phandle;
|
| 1712 |
|
| 1713 | irq_prop = get_property(node, "interrupts");
|
| 1714 | if (!irq_prop)
|
| 1715 | return;
|
| 1716 |
|
| 1717 | if (!is_multiple_of(irq_prop->val.len, sizeof(cell_t)))
|
| 1718 | FAIL_PROP(c, dti, node, irq_prop, "size (%d) is invalid, expected multiple of %zu",
|
| 1719 | irq_prop->val.len, sizeof(cell_t));
|
| 1720 |
|
| 1721 | while (parent && !prop) {
|
| 1722 | if (parent != node && node_is_interrupt_provider(parent)) {
|
| 1723 | irq_node = parent;
|
| 1724 | break;
|
| 1725 | }
|
| 1726 |
|
| 1727 | prop = get_property(parent, "interrupt-parent");
|
| 1728 | if (prop) {
|
| 1729 | phandle = propval_cell(prop);
|
| 1730 | if (!phandle_is_valid(phandle)) {
|
| 1731 | |
| 1732 | * external references
|
| 1733 | if (dti->dtsflags & DTSF_PLUGIN)
|
| 1734 | return;
|
| 1735 | FAIL_PROP(c, dti, parent, prop, "Invalid phandle");
|
| 1736 | continue;
|
| 1737 | }
|
| 1738 |
|
| 1739 | irq_node = get_node_by_phandle(root, phandle);
|
| 1740 | if (!irq_node) {
|
| 1741 | FAIL_PROP(c, dti, parent, prop, "Bad phandle");
|
| 1742 | return;
|
| 1743 | }
|
| 1744 | if (!node_is_interrupt_provider(irq_node))
|
| 1745 | FAIL(c, dti, irq_node,
|
| 1746 | "Missing interrupt-controller or interrupt-map property");
|
| 1747 |
|
| 1748 | break;
|
| 1749 | }
|
| 1750 |
|
| 1751 | parent = parent->parent;
|
| 1752 | }
|
| 1753 |
|
| 1754 | if (!irq_node) {
|
| 1755 | FAIL(c, dti, node, "Missing interrupt-parent");
|
| 1756 | return;
|
| 1757 | }
|
| 1758 |
|
| 1759 | prop = get_property(irq_node, "#interrupt-cells");
|
| 1760 | if (!prop) {
|
| 1761 |
|
| 1762 | return;
|
| 1763 | }
|
| 1764 |
|
| 1765 | irq_cells = propval_cell(prop);
|
| 1766 | if (!is_multiple_of(irq_prop->val.len, irq_cells * sizeof(cell_t))) {
|
| 1767 | FAIL_PROP(c, dti, node, prop,
|
| 1768 | "size is (%d), expected multiple of %d",
|
| 1769 | irq_prop->val.len, (int)(irq_cells * sizeof(cell_t)));
|
| 1770 | }
|
| 1771 | }
|
| 1772 | WARNING(interrupts_property, check_interrupts_property, &phandle_references);
|
| 1773 |
|
| 1774 | static const struct bus_type graph_port_bus = {
|
| 1775 | .name = "graph-port",
|
| 1776 | };
|
| 1777 |
|
| 1778 | static const struct bus_type graph_ports_bus = {
|
| 1779 | .name = "graph-ports",
|
| 1780 | };
|
| 1781 |
|
| 1782 | static void check_graph_nodes(struct check *c, struct dt_info *dti,
|
| 1783 | struct node *node)
|
| 1784 | {
|
| 1785 | struct node *child;
|
| 1786 |
|
| 1787 | for_each_child(node, child) {
|
| 1788 | if (!(strprefixeq(child->name, child->basenamelen, "endpoint") ||
|
| 1789 | get_property(child, "remote-endpoint")))
|
| 1790 | continue;
|
| 1791 |
|
| 1792 |
|
| 1793 | if (!node->parent) {
|
| 1794 | FAIL(c, dti, node, "root node contains endpoint node '%s', potentially misplaced remote-endpoint property", child->name);
|
| 1795 | continue;
|
| 1796 | }
|
| 1797 | node->bus = &graph_port_bus;
|
| 1798 |
|
| 1799 |
|
| 1800 | if (!node->parent->bus &&
|
| 1801 | (streq(node->parent->name, "ports") || get_property(node, "reg")))
|
| 1802 | node->parent->bus = &graph_ports_bus;
|
| 1803 |
|
| 1804 | break;
|
| 1805 | }
|
| 1806 |
|
| 1807 | }
|
| 1808 | WARNING(graph_nodes, check_graph_nodes, NULL);
|
| 1809 |
|
| 1810 | static void check_graph_reg(struct check *c, struct dt_info *dti,
|
| 1811 | struct node *node)
|
| 1812 | {
|
| 1813 | char unit_addr[9];
|
| 1814 | const char *unitname = get_unitname(node);
|
| 1815 | struct property *prop;
|
| 1816 |
|
| 1817 | prop = get_property(node, "reg");
|
| 1818 | if (!prop || !unitname)
|
| 1819 | return;
|
| 1820 |
|
| 1821 | if (!(prop->val.val && prop->val.len == sizeof(cell_t))) {
|
| 1822 | FAIL(c, dti, node, "graph node malformed 'reg' property");
|
| 1823 | return;
|
| 1824 | }
|
| 1825 |
|
| 1826 | snprintf(unit_addr, sizeof(unit_addr), "%x", propval_cell(prop));
|
| 1827 | if (!streq(unitname, unit_addr))
|
| 1828 | FAIL(c, dti, node, "graph node unit address error, expected \"%s\"",
|
| 1829 | unit_addr);
|
| 1830 |
|
| 1831 | if (node->parent->addr_cells != 1)
|
| 1832 | FAIL_PROP(c, dti, node, get_property(node, "#address-cells"),
|
| 1833 | "graph node '#address-cells' is %d, must be 1",
|
| 1834 | node->parent->addr_cells);
|
| 1835 | if (node->parent->size_cells != 0)
|
| 1836 | FAIL_PROP(c, dti, node, get_property(node, "#size-cells"),
|
| 1837 | "graph node '#size-cells' is %d, must be 0",
|
| 1838 | node->parent->size_cells);
|
| 1839 | }
|
| 1840 |
|
| 1841 | static void check_graph_port(struct check *c, struct dt_info *dti,
|
| 1842 | struct node *node)
|
| 1843 | {
|
| 1844 | if (node->bus != &graph_port_bus)
|
| 1845 | return;
|
| 1846 |
|
| 1847 | check_graph_reg(c, dti, node);
|
| 1848 |
|
| 1849 |
|
| 1850 | if (dti->dtsflags & DTSF_PLUGIN)
|
| 1851 | return;
|
| 1852 |
|
| 1853 | if (!strprefixeq(node->name, node->basenamelen, "port"))
|
| 1854 | FAIL(c, dti, node, "graph port node name should be 'port'");
|
| 1855 | }
|
| 1856 | WARNING(graph_port, check_graph_port, NULL, &graph_nodes);
|
| 1857 |
|
| 1858 | static struct node *get_remote_endpoint(struct check *c, struct dt_info *dti,
|
| 1859 | struct node *endpoint)
|
| 1860 | {
|
| 1861 | cell_t phandle;
|
| 1862 | struct node *node;
|
| 1863 | struct property *prop;
|
| 1864 |
|
| 1865 | prop = get_property(endpoint, "remote-endpoint");
|
| 1866 | if (!prop)
|
| 1867 | return NULL;
|
| 1868 |
|
| 1869 | phandle = propval_cell(prop);
|
| 1870 |
|
| 1871 | if (!phandle_is_valid(phandle))
|
| 1872 | return NULL;
|
| 1873 |
|
| 1874 | node = get_node_by_phandle(dti->dt, phandle);
|
| 1875 | if (!node)
|
| 1876 | FAIL_PROP(c, dti, endpoint, prop, "graph phandle is not valid");
|
| 1877 |
|
| 1878 | return node;
|
| 1879 | }
|
| 1880 |
|
| 1881 | static void check_graph_endpoint(struct check *c, struct dt_info *dti,
|
| 1882 | struct node *node)
|
| 1883 | {
|
| 1884 | struct node *remote_node;
|
| 1885 |
|
| 1886 | if (!node->parent || node->parent->bus != &graph_port_bus)
|
| 1887 | return;
|
| 1888 |
|
| 1889 | check_graph_reg(c, dti, node);
|
| 1890 |
|
| 1891 |
|
| 1892 | if (dti->dtsflags & DTSF_PLUGIN)
|
| 1893 | return;
|
| 1894 |
|
| 1895 | if (!strprefixeq(node->name, node->basenamelen, "endpoint"))
|
| 1896 | FAIL(c, dti, node, "graph endpoint node name should be 'endpoint'");
|
| 1897 |
|
| 1898 | remote_node = get_remote_endpoint(c, dti, node);
|
| 1899 | if (!remote_node)
|
| 1900 | return;
|
| 1901 |
|
| 1902 | if (get_remote_endpoint(c, dti, remote_node) != node)
|
| 1903 | FAIL(c, dti, node, "graph connection to node '%s' is not bidirectional",
|
| 1904 | remote_node->fullpath);
|
| 1905 | }
|
| 1906 | WARNING(graph_endpoint, check_graph_endpoint, NULL, &graph_nodes);
|
| 1907 |
|
| 1908 | static struct check *check_table[] = {
|
| 1909 | &duplicate_node_names, &duplicate_property_names,
|
| 1910 | &node_name_chars, &node_name_format, &node_name_not_empty, &property_name_chars,
|
| 1911 | &name_is_string, &name_properties, &node_name_vs_property_name,
|
| 1912 |
|
| 1913 | &duplicate_label,
|
| 1914 |
|
| 1915 | &explicit_phandles,
|
| 1916 | &phandle_references, &path_references,
|
| 1917 | &omit_unused_nodes,
|
| 1918 |
|
| 1919 | &address_cells_is_cell, &size_cells_is_cell,
|
| 1920 | &device_type_is_string, &model_is_string, &status_is_string,
|
| 1921 | &label_is_string,
|
| 1922 |
|
| 1923 | &compatible_is_string_list, &names_is_string_list,
|
| 1924 |
|
| 1925 | &property_name_chars_strict,
|
| 1926 | &node_name_chars_strict,
|
| 1927 |
|
| 1928 | &addr_size_cells, ®_format, &ranges_format, &dma_ranges_format,
|
| 1929 |
|
| 1930 | &unit_address_vs_reg,
|
| 1931 | &unit_address_format,
|
| 1932 |
|
| 1933 | &pci_bridge,
|
| 1934 | &pci_device_reg,
|
| 1935 | &pci_device_bus_num,
|
| 1936 |
|
| 1937 | &simple_bus_bridge,
|
| 1938 | &simple_bus_reg,
|
| 1939 |
|
| 1940 | &i2c_bus_bridge,
|
| 1941 | &i2c_bus_reg,
|
| 1942 |
|
| 1943 | &spi_bus_bridge,
|
| 1944 | &spi_bus_reg,
|
| 1945 |
|
| 1946 | &avoid_default_addr_size,
|
| 1947 | &avoid_unnecessary_addr_size,
|
| 1948 | &unique_unit_address,
|
| 1949 | &unique_unit_address_if_enabled,
|
| 1950 | &obsolete_chosen_interrupt_controller,
|
| 1951 | &chosen_node_is_root, &chosen_node_bootargs, &chosen_node_stdout_path,
|
| 1952 |
|
| 1953 | &clocks_property,
|
| 1954 | &clocks_is_cell,
|
| 1955 | &cooling_device_property,
|
| 1956 | &cooling_device_is_cell,
|
| 1957 | &dmas_property,
|
| 1958 | &dmas_is_cell,
|
| 1959 | &hwlocks_property,
|
| 1960 | &hwlocks_is_cell,
|
| 1961 | &interrupts_extended_property,
|
| 1962 | &interrupts_extended_is_cell,
|
| 1963 | &io_channels_property,
|
| 1964 | &io_channels_is_cell,
|
| 1965 | &iommus_property,
|
| 1966 | &iommus_is_cell,
|
| 1967 | &mboxes_property,
|
| 1968 | &mboxes_is_cell,
|
| 1969 | &msi_parent_property,
|
| 1970 | &msi_parent_is_cell,
|
| 1971 | &mux_controls_property,
|
| 1972 | &mux_controls_is_cell,
|
| 1973 | &phys_property,
|
| 1974 | &phys_is_cell,
|
| 1975 | &power_domains_property,
|
| 1976 | &power_domains_is_cell,
|
| 1977 | &pwms_property,
|
| 1978 | &pwms_is_cell,
|
| 1979 | &resets_property,
|
| 1980 | &resets_is_cell,
|
| 1981 | &sound_dai_property,
|
| 1982 | &sound_dai_is_cell,
|
| 1983 | &thermal_sensors_property,
|
| 1984 | &thermal_sensors_is_cell,
|
| 1985 |
|
| 1986 | &deprecated_gpio_property,
|
| 1987 | &gpios_property,
|
| 1988 | &interrupts_property,
|
| 1989 | &interrupt_provider,
|
| 1990 | &interrupt_map,
|
| 1991 |
|
| 1992 | &alias_paths,
|
| 1993 |
|
| 1994 | &graph_nodes, &graph_port, &graph_endpoint,
|
| 1995 |
|
| 1996 | &always_fail,
|
| 1997 | };
|
| 1998 |
|
| 1999 | static void enable_warning_error(struct check *c, bool warn, bool error)
|
| 2000 | {
|
| 2001 | int i;
|
| 2002 |
|
| 2003 |
|
| 2004 | if ((warn && !c->warn) || (error && !c->error))
|
| 2005 | for (i = 0; i < c->num_prereqs; i++)
|
| 2006 | enable_warning_error(c->prereq[i], warn, error);
|
| 2007 |
|
| 2008 | c->warn = c->warn || warn;
|
| 2009 | c->error = c->error || error;
|
| 2010 | }
|
| 2011 |
|
| 2012 | static void disable_warning_error(struct check *c, bool warn, bool error)
|
| 2013 | {
|
| 2014 | unsigned int i;
|
| 2015 |
|
| 2016 | |
| 2017 | * for
|
| 2018 | if ((warn && c->warn) || (error && c->error)) {
|
| 2019 | for (i = 0; i < ARRAY_SIZE(check_table); i++) {
|
| 2020 | struct check *cc = check_table[i];
|
| 2021 | int j;
|
| 2022 |
|
| 2023 | for (j = 0; j < cc->num_prereqs; j++)
|
| 2024 | if (cc->prereq[j] == c)
|
| 2025 | disable_warning_error(cc, warn, error);
|
| 2026 | }
|
| 2027 | }
|
| 2028 |
|
| 2029 | c->warn = c->warn && !warn;
|
| 2030 | c->error = c->error && !error;
|
| 2031 | }
|
| 2032 |
|
| 2033 | void parse_checks_option(bool warn, bool error, const char *arg)
|
| 2034 | {
|
| 2035 | unsigned int i;
|
| 2036 | const char *name = arg;
|
| 2037 | bool enable = true;
|
| 2038 |
|
| 2039 | if ((strncmp(arg, "no-", 3) == 0)
|
| 2040 | || (strncmp(arg, "no_", 3) == 0)) {
|
| 2041 | name = arg + 3;
|
| 2042 | enable = false;
|
| 2043 | }
|
| 2044 |
|
| 2045 | for (i = 0; i < ARRAY_SIZE(check_table); i++) {
|
| 2046 | struct check *c = check_table[i];
|
| 2047 |
|
| 2048 | if (streq(c->name, name)) {
|
| 2049 | if (enable)
|
| 2050 | enable_warning_error(c, warn, error);
|
| 2051 | else
|
| 2052 | disable_warning_error(c, warn, error);
|
| 2053 | return;
|
| 2054 | }
|
| 2055 | }
|
| 2056 |
|
| 2057 | die("Unrecognized check name \"%s\"\n", name);
|
| 2058 | }
|
| 2059 |
|
| 2060 | void process_checks(bool force, struct dt_info *dti)
|
| 2061 | {
|
| 2062 | unsigned int i;
|
| 2063 | int error = 0;
|
| 2064 |
|
| 2065 | for (i = 0; i < ARRAY_SIZE(check_table); i++) {
|
| 2066 | struct check *c = check_table[i];
|
| 2067 |
|
| 2068 | if (c->warn || c->error)
|
| 2069 | error = error || run_check(c, dti);
|
| 2070 | }
|
| 2071 |
|
| 2072 | if (error) {
|
| 2073 | if (!force) {
|
| 2074 | fprintf(stderr, "ERROR: Input tree has errors, aborting "
|
| 2075 | "(use -f to force output)\n");
|
| 2076 | exit(2);
|
| 2077 | } else if (quiet < 3) {
|
| 2078 | fprintf(stderr, "Warning: Input tree has errors, "
|
| 2079 | "output forced\n");
|
| 2080 | }
|
| 2081 | }
|
| 2082 | }
|