checks.c 36.0 KB
Newer Older
D
David Gibson 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
/*
 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation.  2007.
 *
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 *                                                                   USA
 */

#include "dtc.h"

#ifdef TRACE_CHECKS
#define TRACE(c, ...) \
	do { \
		fprintf(stderr, "=== %s: ", (c)->name); \
		fprintf(stderr, __VA_ARGS__); \
		fprintf(stderr, "\n"); \
	} while (0)
#else
#define TRACE(c, fmt, ...)	do { } while (0)
#endif

enum checkstatus {
	UNCHECKED = 0,
	PREREQ,
	PASSED,
	FAILED,
};

struct check;

43
typedef void (*check_fn)(struct check *c, struct dt_info *dti, struct node *node);
D
David Gibson 已提交
44 45 46

struct check {
	const char *name;
47
	check_fn fn;
D
David Gibson 已提交
48
	void *data;
S
Stephen Warren 已提交
49
	bool warn, error;
D
David Gibson 已提交
50
	enum checkstatus status;
51
	bool inprogress;
D
David Gibson 已提交
52 53 54 55
	int num_prereqs;
	struct check **prereq;
};

56 57 58 59 60 61 62 63
#define CHECK_ENTRY(_nm, _fn, _d, _w, _e, ...)	       \
	static struct check *_nm##_prereqs[] = { __VA_ARGS__ }; \
	static struct check _nm = { \
		.name = #_nm, \
		.fn = (_fn), \
		.data = (_d), \
		.warn = (_w), \
		.error = (_e), \
D
David Gibson 已提交
64
		.status = UNCHECKED, \
65 66
		.num_prereqs = ARRAY_SIZE(_nm##_prereqs), \
		.prereq = _nm##_prereqs, \
D
David Gibson 已提交
67
	};
68 69 70 71 72 73
#define WARNING(_nm, _fn, _d, ...) \
	CHECK_ENTRY(_nm, _fn, _d, true, false, __VA_ARGS__)
#define ERROR(_nm, _fn, _d, ...) \
	CHECK_ENTRY(_nm, _fn, _d, false, true, __VA_ARGS__)
#define CHECK(_nm, _fn, _d, ...) \
	CHECK_ENTRY(_nm, _fn, _d, false, false, __VA_ARGS__)
D
David Gibson 已提交
74

75 76
static inline void  PRINTF(3, 4) check_msg(struct check *c, struct dt_info *dti,
					   const char *fmt, ...)
D
David Gibson 已提交
77 78 79 80
{
	va_list ap;
	va_start(ap, fmt);

S
Stephen Warren 已提交
81 82
	if ((c->warn && (quiet < 1))
	    || (c->error && (quiet < 2))) {
83 84
		fprintf(stderr, "%s: %s (%s): ",
			strcmp(dti->outname, "-") ? dti->outname : "<stdout>",
S
Stephen Warren 已提交
85 86 87 88
			(c->error) ? "ERROR" : "Warning", c->name);
		vfprintf(stderr, fmt, ap);
		fprintf(stderr, "\n");
	}
89
	va_end(ap);
D
David Gibson 已提交
90 91
}

92 93 94 95 96
#define FAIL(c, dti, ...)						\
	do {								\
		TRACE((c), "\t\tFAILED at %s:%d", __FILE__, __LINE__);	\
		(c)->status = FAILED;					\
		check_msg((c), dti, __VA_ARGS__);			\
D
David Gibson 已提交
97 98
	} while (0)

99
static void check_nodes_props(struct check *c, struct dt_info *dti, struct node *node)
D
David Gibson 已提交
100 101 102 103
{
	struct node *child;

	TRACE(c, "%s", node->fullpath);
104 105
	if (c->fn)
		c->fn(c, dti, node);
D
David Gibson 已提交
106 107

	for_each_child(node, child)
108
		check_nodes_props(c, dti, child);
D
David Gibson 已提交
109 110
}

111
static bool run_check(struct check *c, struct dt_info *dti)
D
David Gibson 已提交
112
{
113
	struct node *dt = dti->dt;
114
	bool error = false;
D
David Gibson 已提交
115 116 117 118 119 120 121
	int i;

	assert(!c->inprogress);

	if (c->status != UNCHECKED)
		goto out;

122
	c->inprogress = true;
D
David Gibson 已提交
123 124 125

	for (i = 0; i < c->num_prereqs; i++) {
		struct check *prq = c->prereq[i];
126
		error = error || run_check(prq, dti);
D
David Gibson 已提交
127 128
		if (prq->status != PASSED) {
			c->status = PREREQ;
129
			check_msg(c, dti, "Failed prerequisite '%s'",
D
David Gibson 已提交
130 131 132 133 134 135 136
				  c->prereq[i]->name);
		}
	}

	if (c->status != UNCHECKED)
		goto out;

137
	check_nodes_props(c, dti, dt);
D
David Gibson 已提交
138 139 140 141 142 143 144

	if (c->status == UNCHECKED)
		c->status = PASSED;

	TRACE(c, "\tCompleted, status %d", c->status);

out:
145
	c->inprogress = false;
S
Stephen Warren 已提交
146
	if ((c->status != PASSED) && (c->error))
147
		error = true;
D
David Gibson 已提交
148 149 150 151 152 153 154
	return error;
}

/*
 * Utility check functions
 */

S
Stephen Warren 已提交
155
/* A check which always fails, for testing purposes only */
156 157
static inline void check_always_fail(struct check *c, struct dt_info *dti,
				     struct node *node)
S
Stephen Warren 已提交
158
{
159
	FAIL(c, dti, "always_fail check");
S
Stephen Warren 已提交
160
}
161
CHECK(always_fail, check_always_fail, NULL);
S
Stephen Warren 已提交
162

163
static void check_is_string(struct check *c, struct dt_info *dti,
D
David Gibson 已提交
164 165 166 167 168 169 170 171 172 173
			    struct node *node)
{
	struct property *prop;
	char *propname = c->data;

	prop = get_property(node, propname);
	if (!prop)
		return; /* Not present, assumed ok */

	if (!data_is_one_string(prop->val))
174
		FAIL(c, dti, "\"%s\" property in %s is not a string",
D
David Gibson 已提交
175 176
		     propname, node->fullpath);
}
S
Stephen Warren 已提交
177
#define WARNING_IF_NOT_STRING(nm, propname) \
178
	WARNING(nm, check_is_string, (propname))
S
Stephen Warren 已提交
179
#define ERROR_IF_NOT_STRING(nm, propname) \
180
	ERROR(nm, check_is_string, (propname))
D
David Gibson 已提交
181

182
static void check_is_cell(struct check *c, struct dt_info *dti,
D
David Gibson 已提交
183 184 185 186 187 188 189 190 191 192
			  struct node *node)
{
	struct property *prop;
	char *propname = c->data;

	prop = get_property(node, propname);
	if (!prop)
		return; /* Not present, assumed ok */

	if (prop->val.len != sizeof(cell_t))
193
		FAIL(c, dti, "\"%s\" property in %s is not a single cell",
D
David Gibson 已提交
194 195
		     propname, node->fullpath);
}
S
Stephen Warren 已提交
196
#define WARNING_IF_NOT_CELL(nm, propname) \
197
	WARNING(nm, check_is_cell, (propname))
S
Stephen Warren 已提交
198
#define ERROR_IF_NOT_CELL(nm, propname) \
199
	ERROR(nm, check_is_cell, (propname))
D
David Gibson 已提交
200 201 202 203 204

/*
 * Structural check functions
 */

205
static void check_duplicate_node_names(struct check *c, struct dt_info *dti,
D
David Gibson 已提交
206 207 208 209 210 211 212 213 214
				       struct node *node)
{
	struct node *child, *child2;

	for_each_child(node, child)
		for (child2 = child->next_sibling;
		     child2;
		     child2 = child2->next_sibling)
			if (streq(child->name, child2->name))
215
				FAIL(c, dti, "Duplicate node name %s",
D
David Gibson 已提交
216 217
				     child->fullpath);
}
218
ERROR(duplicate_node_names, check_duplicate_node_names, NULL);
D
David Gibson 已提交
219

220
static void check_duplicate_property_names(struct check *c, struct dt_info *dti,
D
David Gibson 已提交
221 222 223 224
					   struct node *node)
{
	struct property *prop, *prop2;

S
Stephen Warren 已提交
225 226 227 228
	for_each_property(node, prop) {
		for (prop2 = prop->next; prop2; prop2 = prop2->next) {
			if (prop2->deleted)
				continue;
D
David Gibson 已提交
229
			if (streq(prop->name, prop2->name))
230
				FAIL(c, dti, "Duplicate property name %s in %s",
D
David Gibson 已提交
231
				     prop->name, node->fullpath);
S
Stephen Warren 已提交
232 233
		}
	}
D
David Gibson 已提交
234
}
235
ERROR(duplicate_property_names, check_duplicate_property_names, NULL);
D
David Gibson 已提交
236

237 238 239 240
#define LOWERCASE	"abcdefghijklmnopqrstuvwxyz"
#define UPPERCASE	"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define DIGITS		"0123456789"
#define PROPNODECHARS	LOWERCASE UPPERCASE DIGITS ",._+*#?-"
241
#define PROPNODECHARSSTRICT	LOWERCASE UPPERCASE DIGITS ",-"
242

243
static void check_node_name_chars(struct check *c, struct dt_info *dti,
244 245 246 247 248
				  struct node *node)
{
	int n = strspn(node->name, c->data);

	if (n < strlen(node->name))
249
		FAIL(c, dti, "Bad character '%c' in node %s",
250 251
		     node->name[n], node->fullpath);
}
252
ERROR(node_name_chars, check_node_name_chars, PROPNODECHARS "@");
253

254 255 256 257 258 259 260 261 262 263 264
static void check_node_name_chars_strict(struct check *c, struct dt_info *dti,
					 struct node *node)
{
	int n = strspn(node->name, c->data);

	if (n < node->basenamelen)
		FAIL(c, dti, "Character '%c' not recommended in node %s",
		     node->name[n], node->fullpath);
}
CHECK(node_name_chars_strict, check_node_name_chars_strict, PROPNODECHARSSTRICT);

265
static void check_node_name_format(struct check *c, struct dt_info *dti,
266 267 268
				   struct node *node)
{
	if (strchr(get_unitname(node), '@'))
269
		FAIL(c, dti, "Node %s has multiple '@' characters in name",
270 271
		     node->fullpath);
}
272
ERROR(node_name_format, check_node_name_format, NULL, &node_name_chars);
273

274 275
static void check_unit_address_vs_reg(struct check *c, struct dt_info *dti,
				      struct node *node)
276 277 278 279 280 281 282 283 284 285 286 287
{
	const char *unitname = get_unitname(node);
	struct property *prop = get_property(node, "reg");

	if (!prop) {
		prop = get_property(node, "ranges");
		if (prop && !prop->val.len)
			prop = NULL;
	}

	if (prop) {
		if (!unitname[0])
288
			FAIL(c, dti, "Node %s has a reg or ranges property, but no unit name",
289 290 291
			    node->fullpath);
	} else {
		if (unitname[0])
292
			FAIL(c, dti, "Node %s has a unit name, but no reg property",
293 294 295
			    node->fullpath);
	}
}
296
WARNING(unit_address_vs_reg, check_unit_address_vs_reg, NULL);
297

298 299
static void check_property_name_chars(struct check *c, struct dt_info *dti,
				      struct node *node)
300
{
301 302 303 304
	struct property *prop;

	for_each_property(node, prop) {
		int n = strspn(prop->name, c->data);
305

306
		if (n < strlen(prop->name))
307
			FAIL(c, dti, "Bad character '%c' in property name \"%s\", node %s",
308 309
			     prop->name[n], prop->name, node->fullpath);
	}
310
}
311
ERROR(property_name_chars, check_property_name_chars, PROPNODECHARS);
312

313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
static void check_property_name_chars_strict(struct check *c,
					     struct dt_info *dti,
					     struct node *node)
{
	struct property *prop;

	for_each_property(node, prop) {
		const char *name = prop->name;
		int n = strspn(name, c->data);

		if (n == strlen(prop->name))
			continue;

		/* Certain names are whitelisted */
		if (streq(name, "device_type"))
			continue;

		/*
		 * # is only allowed at the beginning of property names not counting
		 * the vendor prefix.
		 */
		if (name[n] == '#' && ((n == 0) || (name[n-1] == ','))) {
			name += n + 1;
			n = strspn(name, c->data);
		}
		if (n < strlen(name))
			FAIL(c, dti, "Character '%c' not recommended in property name \"%s\", node %s",
			     name[n], prop->name, node->fullpath);
	}
}
CHECK(property_name_chars_strict, check_property_name_chars_strict, PROPNODECHARSSTRICT);

345 346 347 348 349 350 351
#define DESCLABEL_FMT	"%s%s%s%s%s"
#define DESCLABEL_ARGS(node,prop,mark)		\
	((mark) ? "value of " : ""),		\
	((prop) ? "'" : ""), \
	((prop) ? (prop)->name : ""), \
	((prop) ? "' in " : ""), (node)->fullpath

352
static void check_duplicate_label(struct check *c, struct dt_info *dti,
353 354 355
				  const char *label, struct node *node,
				  struct property *prop, struct marker *mark)
{
356
	struct node *dt = dti->dt;
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
	struct node *othernode = NULL;
	struct property *otherprop = NULL;
	struct marker *othermark = NULL;

	othernode = get_node_by_label(dt, label);

	if (!othernode)
		otherprop = get_property_by_label(dt, label, &othernode);
	if (!othernode)
		othermark = get_marker_label(dt, label, &othernode,
					       &otherprop);

	if (!othernode)
		return;

	if ((othernode != node) || (otherprop != prop) || (othermark != mark))
373
		FAIL(c, dti, "Duplicate label '%s' on " DESCLABEL_FMT
374 375 376 377 378
		     " and " DESCLABEL_FMT,
		     label, DESCLABEL_ARGS(node, prop, mark),
		     DESCLABEL_ARGS(othernode, otherprop, othermark));
}

379
static void check_duplicate_label_node(struct check *c, struct dt_info *dti,
380 381 382
				       struct node *node)
{
	struct label *l;
383
	struct property *prop;
384 385

	for_each_label(node->labels, l)
386 387 388 389
		check_duplicate_label(c, dti, l->label, node, NULL, NULL);

	for_each_property(node, prop) {
		struct marker *m = prop->val.markers;
390

391 392
		for_each_label(prop->labels, l)
			check_duplicate_label(c, dti, l->label, node, prop, NULL);
393

394 395 396
		for_each_marker_of_type(m, LABEL)
			check_duplicate_label(c, dti, m->ref, node, prop, m);
	}
397
}
398
ERROR(duplicate_label, check_duplicate_label_node, NULL);
399

400 401
static cell_t check_phandle_prop(struct check *c, struct dt_info *dti,
				 struct node *node, const char *propname)
D
David Gibson 已提交
402
{
403 404
	struct node *root = dti->dt;
	struct property *prop;
405
	struct marker *m;
D
David Gibson 已提交
406 407
	cell_t phandle;

408 409 410
	prop = get_property(node, propname);
	if (!prop)
		return 0;
D
David Gibson 已提交
411 412

	if (prop->val.len != sizeof(cell_t)) {
413
		FAIL(c, dti, "%s has bad length (%d) %s property",
414
		     node->fullpath, prop->val.len, prop->name);
415
		return 0;
416 417 418 419 420 421 422 423 424
	}

	m = prop->val.markers;
	for_each_marker_of_type(m, REF_PHANDLE) {
		assert(m->offset == 0);
		if (node != get_node_by_ref(root, m->ref))
			/* "Set this node's phandle equal to some
			 * other node's phandle".  That's nonsensical
			 * by construction. */ {
425
			FAIL(c, dti, "%s in %s is a reference to another node",
426 427 428 429 430 431
			     prop->name, node->fullpath);
		}
		/* But setting this node's phandle equal to its own
		 * phandle is allowed - that means allocate a unique
		 * phandle for this node, even if it's not otherwise
		 * referenced.  The value will be filled in later, so
432 433
		 * we treat it as having no phandle data for now. */
		return 0;
D
David Gibson 已提交
434 435 436
	}

	phandle = propval_cell(prop);
437

D
David Gibson 已提交
438
	if ((phandle == 0) || (phandle == -1)) {
439
		FAIL(c, dti, "%s has bad value (0x%x) in %s property",
440
		     node->fullpath, phandle, prop->name);
441
		return 0;
D
David Gibson 已提交
442 443
	}

444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
	return phandle;
}

static void check_explicit_phandles(struct check *c, struct dt_info *dti,
				    struct node *node)
{
	struct node *root = dti->dt;
	struct node *other;
	cell_t phandle, linux_phandle;

	/* Nothing should have assigned phandles yet */
	assert(!node->phandle);

	phandle = check_phandle_prop(c, dti, node, "phandle");

	linux_phandle = check_phandle_prop(c, dti, node, "linux,phandle");

	if (!phandle && !linux_phandle)
		/* No valid phandles; nothing further to check */
		return;

	if (linux_phandle && phandle && (phandle != linux_phandle))
466
		FAIL(c, dti, "%s has mismatching 'phandle' and 'linux,phandle'"
467 468 469 470
		     " properties", node->fullpath);

	if (linux_phandle && !phandle)
		phandle = linux_phandle;
471

D
David Gibson 已提交
472
	other = get_node_by_phandle(root, phandle);
473
	if (other && (other != node)) {
474
		FAIL(c, dti, "%s has duplicated phandle 0x%x (seen before at %s)",
D
David Gibson 已提交
475 476 477 478 479 480
		     node->fullpath, phandle, other->fullpath);
		return;
	}

	node->phandle = phandle;
}
481
ERROR(explicit_phandles, check_explicit_phandles, NULL);
D
David Gibson 已提交
482

483
static void check_name_properties(struct check *c, struct dt_info *dti,
D
David Gibson 已提交
484 485
				  struct node *node)
{
486 487 488 489 490 491 492
	struct property **pp, *prop = NULL;

	for (pp = &node->proplist; *pp; pp = &((*pp)->next))
		if (streq((*pp)->name, "name")) {
			prop = *pp;
			break;
		}
D
David Gibson 已提交
493 494 495 496 497

	if (!prop)
		return; /* No name property, that's fine */

	if ((prop->val.len != node->basenamelen+1)
498
	    || (memcmp(prop->val.val, node->name, node->basenamelen) != 0)) {
499
		FAIL(c, dti, "\"name\" property in %s is incorrect (\"%s\" instead"
D
David Gibson 已提交
500
		     " of base node name)", node->fullpath, prop->val.val);
501 502 503 504 505 506 507 508
	} else {
		/* The name property is correct, and therefore redundant.
		 * Delete it */
		*pp = prop->next;
		free(prop->name);
		data_free(prop->val);
		free(prop);
	}
D
David Gibson 已提交
509
}
S
Stephen Warren 已提交
510
ERROR_IF_NOT_STRING(name_is_string, "name");
511
ERROR(name_properties, check_name_properties, NULL, &name_is_string);
D
David Gibson 已提交
512 513 514 515 516

/*
 * Reference fixup functions
 */

517 518
static void fixup_phandle_references(struct check *c, struct dt_info *dti,
				     struct node *node)
D
David Gibson 已提交
519
{
520 521
	struct node *dt = dti->dt;
	struct property *prop;
522

523 524 525 526 527 528 529 530 531 532 533
	for_each_property(node, prop) {
		struct marker *m = prop->val.markers;
		struct node *refnode;
		cell_t phandle;

		for_each_marker_of_type(m, REF_PHANDLE) {
			assert(m->offset + sizeof(cell_t) <= prop->val.len);

			refnode = get_node_by_ref(dt, m->ref);
			if (! refnode) {
				if (!(dti->dtsflags & DTSF_PLUGIN))
534
					FAIL(c, dti, "Reference to non-existent node or "
535 536
							"label \"%s\"\n", m->ref);
				else /* mark the entry as unresolved */
537
					*((fdt32_t *)(prop->val.val + m->offset)) =
538 539 540
						cpu_to_fdt32(0xffffffff);
				continue;
			}
541

542
			phandle = get_node_phandle(dt, refnode);
543
			*((fdt32_t *)(prop->val.val + m->offset)) = cpu_to_fdt32(phandle);
544 545
		}
	}
D
David Gibson 已提交
546
}
547
ERROR(phandle_references, fixup_phandle_references, NULL,
D
David Gibson 已提交
548 549
      &duplicate_node_names, &explicit_phandles);

550 551
static void fixup_path_references(struct check *c, struct dt_info *dti,
				  struct node *node)
D
David Gibson 已提交
552
{
553 554 555 556 557 558 559 560 561 562
	struct node *dt = dti->dt;
	struct property *prop;

	for_each_property(node, prop) {
		struct marker *m = prop->val.markers;
		struct node *refnode;
		char *path;

		for_each_marker_of_type(m, REF_PATH) {
			assert(m->offset <= prop->val.len);
D
David Gibson 已提交
563

564 565
			refnode = get_node_by_ref(dt, m->ref);
			if (!refnode) {
566
				FAIL(c, dti, "Reference to non-existent node or label \"%s\"\n",
567 568 569 570 571 572 573 574
				     m->ref);
				continue;
			}

			path = refnode->fullpath;
			prop->val = data_insert_at_marker(prop->val, m, path,
							  strlen(path) + 1);
		}
D
David Gibson 已提交
575 576
	}
}
577
ERROR(path_references, fixup_path_references, NULL, &duplicate_node_names);
D
David Gibson 已提交
578 579 580 581

/*
 * Semantic checks
 */
S
Stephen Warren 已提交
582 583 584
WARNING_IF_NOT_CELL(address_cells_is_cell, "#address-cells");
WARNING_IF_NOT_CELL(size_cells_is_cell, "#size-cells");
WARNING_IF_NOT_CELL(interrupt_cells_is_cell, "#interrupt-cells");
D
David Gibson 已提交
585

S
Stephen Warren 已提交
586 587 588
WARNING_IF_NOT_STRING(device_type_is_string, "device_type");
WARNING_IF_NOT_STRING(model_is_string, "model");
WARNING_IF_NOT_STRING(status_is_string, "status");
D
David Gibson 已提交
589

590
static void fixup_addr_size_cells(struct check *c, struct dt_info *dti,
D
David Gibson 已提交
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
				  struct node *node)
{
	struct property *prop;

	node->addr_cells = -1;
	node->size_cells = -1;

	prop = get_property(node, "#address-cells");
	if (prop)
		node->addr_cells = propval_cell(prop);

	prop = get_property(node, "#size-cells");
	if (prop)
		node->size_cells = propval_cell(prop);
}
606
WARNING(addr_size_cells, fixup_addr_size_cells, NULL,
S
Stephen Warren 已提交
607
	&address_cells_is_cell, &size_cells_is_cell);
D
David Gibson 已提交
608 609 610 611 612 613

#define node_addr_cells(n) \
	(((n)->addr_cells == -1) ? 2 : (n)->addr_cells)
#define node_size_cells(n) \
	(((n)->size_cells == -1) ? 1 : (n)->size_cells)

614
static void check_reg_format(struct check *c, struct dt_info *dti,
D
David Gibson 已提交
615 616 617 618 619 620 621 622 623 624
			     struct node *node)
{
	struct property *prop;
	int addr_cells, size_cells, entrylen;

	prop = get_property(node, "reg");
	if (!prop)
		return; /* No "reg", that's fine */

	if (!node->parent) {
625
		FAIL(c, dti, "Root node has a \"reg\" property");
D
David Gibson 已提交
626 627 628 629
		return;
	}

	if (prop->val.len == 0)
630
		FAIL(c, dti, "\"reg\" property in %s is empty", node->fullpath);
D
David Gibson 已提交
631 632 633 634 635

	addr_cells = node_addr_cells(node->parent);
	size_cells = node_size_cells(node->parent);
	entrylen = (addr_cells + size_cells) * sizeof(cell_t);

636
	if (!entrylen || (prop->val.len % entrylen) != 0)
637
		FAIL(c, dti, "\"reg\" property in %s has invalid length (%d bytes) "
D
David Gibson 已提交
638 639 640
		     "(#address-cells == %d, #size-cells == %d)",
		     node->fullpath, prop->val.len, addr_cells, size_cells);
}
641
WARNING(reg_format, check_reg_format, NULL, &addr_size_cells);
D
David Gibson 已提交
642

643
static void check_ranges_format(struct check *c, struct dt_info *dti,
D
David Gibson 已提交
644 645 646 647 648 649 650 651 652 653
				struct node *node)
{
	struct property *prop;
	int c_addr_cells, p_addr_cells, c_size_cells, p_size_cells, entrylen;

	prop = get_property(node, "ranges");
	if (!prop)
		return;

	if (!node->parent) {
654
		FAIL(c, dti, "Root node has a \"ranges\" property");
D
David Gibson 已提交
655 656 657 658 659 660 661 662 663 664 665
		return;
	}

	p_addr_cells = node_addr_cells(node->parent);
	p_size_cells = node_size_cells(node->parent);
	c_addr_cells = node_addr_cells(node);
	c_size_cells = node_size_cells(node);
	entrylen = (p_addr_cells + c_addr_cells + c_size_cells) * sizeof(cell_t);

	if (prop->val.len == 0) {
		if (p_addr_cells != c_addr_cells)
666
			FAIL(c, dti, "%s has empty \"ranges\" property but its "
D
David Gibson 已提交
667 668 669 670
			     "#address-cells (%d) differs from %s (%d)",
			     node->fullpath, c_addr_cells, node->parent->fullpath,
			     p_addr_cells);
		if (p_size_cells != c_size_cells)
671
			FAIL(c, dti, "%s has empty \"ranges\" property but its "
D
David Gibson 已提交
672 673 674 675
			     "#size-cells (%d) differs from %s (%d)",
			     node->fullpath, c_size_cells, node->parent->fullpath,
			     p_size_cells);
	} else if ((prop->val.len % entrylen) != 0) {
676
		FAIL(c, dti, "\"ranges\" property in %s has invalid length (%d bytes) "
D
David Gibson 已提交
677 678 679 680 681
		     "(parent #address-cells == %d, child #address-cells == %d, "
		     "#size-cells == %d)", node->fullpath, prop->val.len,
		     p_addr_cells, c_addr_cells, c_size_cells);
	}
}
682
WARNING(ranges_format, check_ranges_format, NULL, &addr_size_cells);
D
David Gibson 已提交
683

684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875
static const struct bus_type pci_bus = {
	.name = "PCI",
};

static void check_pci_bridge(struct check *c, struct dt_info *dti, struct node *node)
{
	struct property *prop;
	cell_t *cells;

	prop = get_property(node, "device_type");
	if (!prop || !streq(prop->val.val, "pci"))
		return;

	node->bus = &pci_bus;

	if (!strneq(node->name, "pci", node->basenamelen) &&
	    !strneq(node->name, "pcie", node->basenamelen))
		FAIL(c, dti, "Node %s node name is not \"pci\" or \"pcie\"",
			     node->fullpath);

	prop = get_property(node, "ranges");
	if (!prop)
		FAIL(c, dti, "Node %s missing ranges for PCI bridge (or not a bridge)",
			     node->fullpath);

	if (node_addr_cells(node) != 3)
		FAIL(c, dti, "Node %s incorrect #address-cells for PCI bridge",
			     node->fullpath);
	if (node_size_cells(node) != 2)
		FAIL(c, dti, "Node %s incorrect #size-cells for PCI bridge",
			     node->fullpath);

	prop = get_property(node, "bus-range");
	if (!prop) {
		FAIL(c, dti, "Node %s missing bus-range for PCI bridge",
			     node->fullpath);
		return;
	}
	if (prop->val.len != (sizeof(cell_t) * 2)) {
		FAIL(c, dti, "Node %s bus-range must be 2 cells",
			     node->fullpath);
		return;
	}
	cells = (cell_t *)prop->val.val;
	if (fdt32_to_cpu(cells[0]) > fdt32_to_cpu(cells[1]))
		FAIL(c, dti, "Node %s bus-range 1st cell must be less than or equal to 2nd cell",
			     node->fullpath);
	if (fdt32_to_cpu(cells[1]) > 0xff)
		FAIL(c, dti, "Node %s bus-range maximum bus number must be less than 256",
			     node->fullpath);
}
WARNING(pci_bridge, check_pci_bridge, NULL,
	&device_type_is_string, &addr_size_cells);

static void check_pci_device_bus_num(struct check *c, struct dt_info *dti, struct node *node)
{
	struct property *prop;
	unsigned int bus_num, min_bus, max_bus;
	cell_t *cells;

	if (!node->parent || (node->parent->bus != &pci_bus))
		return;

	prop = get_property(node, "reg");
	if (!prop)
		return;

	cells = (cell_t *)prop->val.val;
	bus_num = (fdt32_to_cpu(cells[0]) & 0x00ff0000) >> 16;

	prop = get_property(node->parent, "bus-range");
	if (!prop) {
		min_bus = max_bus = 0;
	} else {
		cells = (cell_t *)prop->val.val;
		min_bus = fdt32_to_cpu(cells[0]);
		max_bus = fdt32_to_cpu(cells[0]);
	}
	if ((bus_num < min_bus) || (bus_num > max_bus))
		FAIL(c, dti, "Node %s PCI bus number %d out of range, expected (%d - %d)",
		     node->fullpath, bus_num, min_bus, max_bus);
}
WARNING(pci_device_bus_num, check_pci_device_bus_num, NULL, &reg_format, &pci_bridge);

static void check_pci_device_reg(struct check *c, struct dt_info *dti, struct node *node)
{
	struct property *prop;
	const char *unitname = get_unitname(node);
	char unit_addr[5];
	unsigned int dev, func, reg;
	cell_t *cells;

	if (!node->parent || (node->parent->bus != &pci_bus))
		return;

	prop = get_property(node, "reg");
	if (!prop) {
		FAIL(c, dti, "Node %s missing PCI reg property", node->fullpath);
		return;
	}

	cells = (cell_t *)prop->val.val;
	if (cells[1] || cells[2])
		FAIL(c, dti, "Node %s PCI reg config space address cells 2 and 3 must be 0",
			     node->fullpath);

	reg = fdt32_to_cpu(cells[0]);
	dev = (reg & 0xf800) >> 11;
	func = (reg & 0x700) >> 8;

	if (reg & 0xff000000)
		FAIL(c, dti, "Node %s PCI reg address is not configuration space",
			     node->fullpath);
	if (reg & 0x000000ff)
		FAIL(c, dti, "Node %s PCI reg config space address register number must be 0",
			     node->fullpath);

	if (func == 0) {
		snprintf(unit_addr, sizeof(unit_addr), "%x", dev);
		if (streq(unitname, unit_addr))
			return;
	}

	snprintf(unit_addr, sizeof(unit_addr), "%x,%x", dev, func);
	if (streq(unitname, unit_addr))
		return;

	FAIL(c, dti, "Node %s PCI unit address format error, expected \"%s\"",
	     node->fullpath, unit_addr);
}
WARNING(pci_device_reg, check_pci_device_reg, NULL, &reg_format, &pci_bridge);

static const struct bus_type simple_bus = {
	.name = "simple-bus",
};

static bool node_is_compatible(struct node *node, const char *compat)
{
	struct property *prop;
	const char *str, *end;

	prop = get_property(node, "compatible");
	if (!prop)
		return false;

	for (str = prop->val.val, end = str + prop->val.len; str < end;
	     str += strnlen(str, end - str) + 1) {
		if (strneq(str, compat, end - str))
			return true;
	}
	return false;
}

static void check_simple_bus_bridge(struct check *c, struct dt_info *dti, struct node *node)
{
	if (node_is_compatible(node, "simple-bus"))
		node->bus = &simple_bus;
}
WARNING(simple_bus_bridge, check_simple_bus_bridge, NULL, &addr_size_cells);

static void check_simple_bus_reg(struct check *c, struct dt_info *dti, struct node *node)
{
	struct property *prop;
	const char *unitname = get_unitname(node);
	char unit_addr[17];
	unsigned int size;
	uint64_t reg = 0;
	cell_t *cells = NULL;

	if (!node->parent || (node->parent->bus != &simple_bus))
		return;

	prop = get_property(node, "reg");
	if (prop)
		cells = (cell_t *)prop->val.val;
	else {
		prop = get_property(node, "ranges");
		if (prop && prop->val.len)
			/* skip of child address */
			cells = ((cell_t *)prop->val.val) + node_addr_cells(node);
	}

	if (!cells) {
		if (node->parent->parent && !(node->bus == &simple_bus))
			FAIL(c, dti, "Node %s missing or empty reg/ranges property", node->fullpath);
		return;
	}

	size = node_addr_cells(node->parent);
	while (size--)
		reg = (reg << 32) | fdt32_to_cpu(*(cells++));

876
	snprintf(unit_addr, sizeof(unit_addr), "%"PRIx64, reg);
877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906
	if (!streq(unitname, unit_addr))
		FAIL(c, dti, "Node %s simple-bus unit address format error, expected \"%s\"",
		     node->fullpath, unit_addr);
}
WARNING(simple_bus_reg, check_simple_bus_reg, NULL, &reg_format, &simple_bus_bridge);

static void check_unit_address_format(struct check *c, struct dt_info *dti,
				      struct node *node)
{
	const char *unitname = get_unitname(node);

	if (node->parent && node->parent->bus)
		return;

	if (!unitname[0])
		return;

	if (!strncmp(unitname, "0x", 2)) {
		FAIL(c, dti, "Node %s unit name should not have leading \"0x\"",
		    node->fullpath);
		/* skip over 0x for next test */
		unitname += 2;
	}
	if (unitname[0] == '0' && isxdigit(unitname[1]))
		FAIL(c, dti, "Node %s unit name should not have leading 0s",
		    node->fullpath);
}
WARNING(unit_address_format, check_unit_address_format, NULL,
	&node_name_format, &pci_bridge, &simple_bus_bridge);

D
David Gibson 已提交
907 908 909
/*
 * Style checks
 */
910
static void check_avoid_default_addr_size(struct check *c, struct dt_info *dti,
D
David Gibson 已提交
911 912 913 914 915 916 917 918 919 920 921 922 923
					  struct node *node)
{
	struct property *reg, *ranges;

	if (!node->parent)
		return; /* Ignore root node */

	reg = get_property(node, "reg");
	ranges = get_property(node, "ranges");

	if (!reg && !ranges)
		return;

924
	if (node->parent->addr_cells == -1)
925
		FAIL(c, dti, "Relying on default #address-cells value for %s",
D
David Gibson 已提交
926 927
		     node->fullpath);

928
	if (node->parent->size_cells == -1)
929
		FAIL(c, dti, "Relying on default #size-cells value for %s",
D
David Gibson 已提交
930 931
		     node->fullpath);
}
932 933
WARNING(avoid_default_addr_size, check_avoid_default_addr_size, NULL,
	&addr_size_cells);
D
David Gibson 已提交
934 935

static void check_obsolete_chosen_interrupt_controller(struct check *c,
936 937
						       struct dt_info *dti,
						       struct node *node)
D
David Gibson 已提交
938
{
939
	struct node *dt = dti->dt;
D
David Gibson 已提交
940 941 942
	struct node *chosen;
	struct property *prop;

943 944 945 946
	if (node != dt)
		return;


D
David Gibson 已提交
947 948 949 950 951 952
	chosen = get_node_by_path(dt, "/chosen");
	if (!chosen)
		return;

	prop = get_property(chosen, "interrupt-controller");
	if (prop)
953
		FAIL(c, dti, "/chosen has obsolete \"interrupt-controller\" "
D
David Gibson 已提交
954 955
		     "property");
}
956 957
WARNING(obsolete_chosen_interrupt_controller,
	check_obsolete_chosen_interrupt_controller, NULL);
D
David Gibson 已提交
958

959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217
struct provider {
	const char *prop_name;
	const char *cell_name;
	bool optional;
};

static void check_property_phandle_args(struct check *c,
					  struct dt_info *dti,
				          struct node *node,
				          struct property *prop,
				          const struct provider *provider)
{
	struct node *root = dti->dt;
	int cell, cellsize = 0;

	if (prop->val.len % sizeof(cell_t)) {
		FAIL(c, dti, "property '%s' size (%d) is invalid, expected multiple of %zu in node %s",
		     prop->name, prop->val.len, sizeof(cell_t), node->fullpath);
		return;
	}

	for (cell = 0; cell < prop->val.len / sizeof(cell_t); cell += cellsize + 1) {
		struct node *provider_node;
		struct property *cellprop;
		int phandle;

		phandle = propval_cell_n(prop, cell);
		/*
		 * Some bindings use a cell value 0 or -1 to skip over optional
		 * entries when each index position has a specific definition.
		 */
		if (phandle == 0 || phandle == -1) {
			cellsize = 0;
			continue;
		}

		/* If we have markers, verify the current cell is a phandle */
		if (prop->val.markers) {
			struct marker *m = prop->val.markers;
			for_each_marker_of_type(m, REF_PHANDLE) {
				if (m->offset == (cell * sizeof(cell_t)))
					break;
			}
			if (!m)
				FAIL(c, dti, "Property '%s', cell %d is not a phandle reference in %s",
				     prop->name, cell, node->fullpath);
		}

		provider_node = get_node_by_phandle(root, phandle);
		if (!provider_node) {
			FAIL(c, dti, "Could not get phandle node for %s:%s(cell %d)",
			     node->fullpath, prop->name, cell);
			break;
		}

		cellprop = get_property(provider_node, provider->cell_name);
		if (cellprop) {
			cellsize = propval_cell(cellprop);
		} else if (provider->optional) {
			cellsize = 0;
		} else {
			FAIL(c, dti, "Missing property '%s' in node %s or bad phandle (referred from %s:%s[%d])",
			     provider->cell_name,
			     provider_node->fullpath,
			     node->fullpath, prop->name, cell);
			break;
		}

		if (prop->val.len < ((cell + cellsize + 1) * sizeof(cell_t))) {
			FAIL(c, dti, "%s property size (%d) too small for cell size %d in %s",
			     prop->name, prop->val.len, cellsize, node->fullpath);
		}
	}
}

static void check_provider_cells_property(struct check *c,
					  struct dt_info *dti,
				          struct node *node)
{
	struct provider *provider = c->data;
	struct property *prop;

	prop = get_property(node, provider->prop_name);
	if (!prop)
		return;

	check_property_phandle_args(c, dti, node, prop, provider);
}
#define WARNING_PROPERTY_PHANDLE_CELLS(nm, propname, cells_name, ...) \
	static struct provider nm##_provider = { (propname), (cells_name), __VA_ARGS__ }; \
	WARNING(nm##_property, check_provider_cells_property, &nm##_provider, &phandle_references);

WARNING_PROPERTY_PHANDLE_CELLS(clocks, "clocks", "#clock-cells");
WARNING_PROPERTY_PHANDLE_CELLS(cooling_device, "cooling-device", "#cooling-cells");
WARNING_PROPERTY_PHANDLE_CELLS(dmas, "dmas", "#dma-cells");
WARNING_PROPERTY_PHANDLE_CELLS(hwlocks, "hwlocks", "#hwlock-cells");
WARNING_PROPERTY_PHANDLE_CELLS(interrupts_extended, "interrupts-extended", "#interrupt-cells");
WARNING_PROPERTY_PHANDLE_CELLS(io_channels, "io-channels", "#io-channel-cells");
WARNING_PROPERTY_PHANDLE_CELLS(iommus, "iommus", "#iommu-cells");
WARNING_PROPERTY_PHANDLE_CELLS(mboxes, "mboxes", "#mbox-cells");
WARNING_PROPERTY_PHANDLE_CELLS(msi_parent, "msi-parent", "#msi-cells", true);
WARNING_PROPERTY_PHANDLE_CELLS(mux_controls, "mux-controls", "#mux-control-cells");
WARNING_PROPERTY_PHANDLE_CELLS(phys, "phys", "#phy-cells");
WARNING_PROPERTY_PHANDLE_CELLS(power_domains, "power-domains", "#power-domain-cells");
WARNING_PROPERTY_PHANDLE_CELLS(pwms, "pwms", "#pwm-cells");
WARNING_PROPERTY_PHANDLE_CELLS(resets, "resets", "#reset-cells");
WARNING_PROPERTY_PHANDLE_CELLS(sound_dais, "sound-dais", "#sound-dai-cells");
WARNING_PROPERTY_PHANDLE_CELLS(thermal_sensors, "thermal-sensors", "#thermal-sensor-cells");

static bool prop_is_gpio(struct property *prop)
{
	char *str;

	/*
	 * *-gpios and *-gpio can appear in property names,
	 * so skip over any false matches (only one known ATM)
	 */
	if (strstr(prop->name, "nr-gpio"))
		return false;

	str = strrchr(prop->name, '-');
	if (str)
		str++;
	else
		str = prop->name;
	if (!(streq(str, "gpios") || streq(str, "gpio")))
		return false;

	return true;
}

static void check_gpios_property(struct check *c,
					  struct dt_info *dti,
				          struct node *node)
{
	struct property *prop;

	/* Skip GPIO hog nodes which have 'gpios' property */
	if (get_property(node, "gpio-hog"))
		return;

	for_each_property(node, prop) {
		struct provider provider;

		if (!prop_is_gpio(prop))
			continue;

		provider.prop_name = prop->name;
		provider.cell_name = "#gpio-cells";
		provider.optional = false;
		check_property_phandle_args(c, dti, node, prop, &provider);
	}

}
WARNING(gpios_property, check_gpios_property, NULL, &phandle_references);

static void check_deprecated_gpio_property(struct check *c,
					   struct dt_info *dti,
				           struct node *node)
{
	struct property *prop;

	for_each_property(node, prop) {
		char *str;

		if (!prop_is_gpio(prop))
			continue;

		str = strstr(prop->name, "gpio");
		if (!streq(str, "gpio"))
			continue;

		FAIL(c, dti, "'[*-]gpio' is deprecated, use '[*-]gpios' instead for %s:%s",
		     node->fullpath, prop->name);
	}

}
CHECK(deprecated_gpio_property, check_deprecated_gpio_property, NULL);

static bool node_is_interrupt_provider(struct node *node)
{
	struct property *prop;

	prop = get_property(node, "interrupt-controller");
	if (prop)
		return true;

	prop = get_property(node, "interrupt-map");
	if (prop)
		return true;

	return false;
}
static void check_interrupts_property(struct check *c,
				      struct dt_info *dti,
				      struct node *node)
{
	struct node *root = dti->dt;
	struct node *irq_node = NULL, *parent = node;
	struct property *irq_prop, *prop = NULL;
	int irq_cells, phandle;

	irq_prop = get_property(node, "interrupts");
	if (!irq_prop)
		return;

	if (irq_prop->val.len % sizeof(cell_t))
		FAIL(c, dti, "property '%s' size (%d) is invalid, expected multiple of %zu in node %s",
		     irq_prop->name, irq_prop->val.len, sizeof(cell_t),
		     node->fullpath);

	while (parent && !prop) {
		if (parent != node && node_is_interrupt_provider(parent)) {
			irq_node = parent;
			break;
		}

		prop = get_property(parent, "interrupt-parent");
		if (prop) {
			phandle = propval_cell(prop);
			irq_node = get_node_by_phandle(root, phandle);
			if (!irq_node) {
				FAIL(c, dti, "Bad interrupt-parent phandle for %s",
				     node->fullpath);
				return;
			}
			if (!node_is_interrupt_provider(irq_node))
				FAIL(c, dti,
				     "Missing interrupt-controller or interrupt-map property in %s",
				     irq_node->fullpath);

			break;
		}

		parent = parent->parent;
	}

	if (!irq_node) {
		FAIL(c, dti, "Missing interrupt-parent for %s", node->fullpath);
		return;
	}

	prop = get_property(irq_node, "#interrupt-cells");
	if (!prop) {
		FAIL(c, dti, "Missing #interrupt-cells in interrupt-parent %s",
		     irq_node->fullpath);
		return;
	}

	irq_cells = propval_cell(prop);
	if (irq_prop->val.len % (irq_cells * sizeof(cell_t))) {
		FAIL(c, dti,
		     "interrupts size is (%d), expected multiple of %d in %s",
		     irq_prop->val.len, (int)(irq_cells * sizeof(cell_t)),
		     node->fullpath);
	}
}
WARNING(interrupts_property, check_interrupts_property, &phandle_references);

D
David Gibson 已提交
1218 1219
static struct check *check_table[] = {
	&duplicate_node_names, &duplicate_property_names,
1220
	&node_name_chars, &node_name_format, &property_name_chars,
D
David Gibson 已提交
1221
	&name_is_string, &name_properties,
1222 1223 1224

	&duplicate_label,

D
David Gibson 已提交
1225 1226 1227 1228 1229 1230
	&explicit_phandles,
	&phandle_references, &path_references,

	&address_cells_is_cell, &size_cells_is_cell, &interrupt_cells_is_cell,
	&device_type_is_string, &model_is_string, &status_is_string,

1231 1232 1233
	&property_name_chars_strict,
	&node_name_chars_strict,

D
David Gibson 已提交
1234 1235
	&addr_size_cells, &reg_format, &ranges_format,

1236
	&unit_address_vs_reg,
1237 1238 1239 1240 1241 1242 1243 1244
	&unit_address_format,

	&pci_bridge,
	&pci_device_reg,
	&pci_device_bus_num,

	&simple_bus_bridge,
	&simple_bus_reg,
1245

D
David Gibson 已提交
1246 1247
	&avoid_default_addr_size,
	&obsolete_chosen_interrupt_controller,
S
Stephen Warren 已提交
1248

1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269
	&clocks_property,
	&cooling_device_property,
	&dmas_property,
	&hwlocks_property,
	&interrupts_extended_property,
	&io_channels_property,
	&iommus_property,
	&mboxes_property,
	&msi_parent_property,
	&mux_controls_property,
	&phys_property,
	&power_domains_property,
	&pwms_property,
	&resets_property,
	&sound_dais_property,
	&thermal_sensors_property,

	&deprecated_gpio_property,
	&gpios_property,
	&interrupts_property,

S
Stephen Warren 已提交
1270
	&always_fail,
D
David Gibson 已提交
1271 1272
};

S
Stephen Warren 已提交
1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306
static void enable_warning_error(struct check *c, bool warn, bool error)
{
	int i;

	/* Raising level, also raise it for prereqs */
	if ((warn && !c->warn) || (error && !c->error))
		for (i = 0; i < c->num_prereqs; i++)
			enable_warning_error(c->prereq[i], warn, error);

	c->warn = c->warn || warn;
	c->error = c->error || error;
}

static void disable_warning_error(struct check *c, bool warn, bool error)
{
	int i;

	/* Lowering level, also lower it for things this is the prereq
	 * for */
	if ((warn && c->warn) || (error && c->error)) {
		for (i = 0; i < ARRAY_SIZE(check_table); i++) {
			struct check *cc = check_table[i];
			int j;

			for (j = 0; j < cc->num_prereqs; j++)
				if (cc->prereq[j] == c)
					disable_warning_error(cc, warn, error);
		}
	}

	c->warn = c->warn && !warn;
	c->error = c->error && !error;
}

1307
void parse_checks_option(bool warn, bool error, const char *arg)
S
Stephen Warren 已提交
1308 1309
{
	int i;
1310
	const char *name = arg;
S
Stephen Warren 已提交
1311 1312
	bool enable = true;

1313 1314 1315
	if ((strncmp(arg, "no-", 3) == 0)
	    || (strncmp(arg, "no_", 3) == 0)) {
		name = arg + 3;
S
Stephen Warren 已提交
1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333
		enable = false;
	}

	for (i = 0; i < ARRAY_SIZE(check_table); i++) {
		struct check *c = check_table[i];

		if (streq(c->name, name)) {
			if (enable)
				enable_warning_error(c, warn, error);
			else
				disable_warning_error(c, warn, error);
			return;
		}
	}

	die("Unrecognized check name \"%s\"\n", name);
}

1334
void process_checks(bool force, struct dt_info *dti)
D
David Gibson 已提交
1335 1336 1337 1338 1339 1340 1341
{
	int i;
	int error = 0;

	for (i = 0; i < ARRAY_SIZE(check_table); i++) {
		struct check *c = check_table[i];

S
Stephen Warren 已提交
1342
		if (c->warn || c->error)
1343
			error = error || run_check(c, dti);
D
David Gibson 已提交
1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356
	}

	if (error) {
		if (!force) {
			fprintf(stderr, "ERROR: Input tree has errors, aborting "
				"(use -f to force output)\n");
			exit(2);
		} else if (quiet < 3) {
			fprintf(stderr, "Warning: Input tree has errors, "
				"output forced\n");
		}
	}
}