dtc: Convert #address-cells and #size-cells related checks
This patch converts checks related to #address-cells and #size-cells
to the new framework. Specifically, it reimplements the check that
"reg" properties have a valid size based on the relevant
#address-cells and #size-cells values. The new implementation uses
the correct default value, unlike the old-style check which assumed
the values were inherited by default.
It also implements a new, similar test for "ranges" properties.
Finally, since relying on the default values of these variables is
considered not-good-practice these days, it implements a "style" check
which will give a warning if the tree ever relies on the default
values (that is if any node with either "reg" or "ranges" appears
under a parent which has no #address-cells or #size-cells property).
int check_semantics(struct node *dt, int outversion, int boot_cpuid_phys);
@ -487,10 +612,6 @@ static int check_root(struct node *root)
@@ -487,10 +612,6 @@ static int check_root(struct node *root)
int ok = 1;
CHECK_HAVE_STRING(root, "model");
CHECK_HAVE(root, "#address-cells");
CHECK_HAVE(root, "#size-cells");
CHECK_HAVE_WARN(root, "compatible");
return ok;
@ -509,19 +630,16 @@ static int check_cpus(struct node *root, int outversion, int boot_cpuid_phys)
@@ -509,19 +630,16 @@ static int check_cpus(struct node *root, int outversion, int boot_cpuid_phys)
return 0;
}
CHECK_HAVE_WARN(cpus, "#address-cells");
CHECK_HAVE_WARN(cpus, "#size-cells");
if (cpus->addr_cells != 1)
DO_ERR("%s has bad #address-cells value %d (should be 1)\n",
cpus->fullpath, cpus->addr_cells);
if (cpus->size_cells != 0)
DO_ERR("%s has bad #size-cells value %d (should be 0)\n",
cpus->fullpath, cpus->size_cells);
for_each_child(cpus, cpu) {
CHECK_HAVE_STREQ(cpu, "device_type", "cpu");
if (cpu->addr_cells != 1)
DO_ERR("%s has bad #address-cells value %d (should be 1)\n",
cpu->fullpath, cpu->addr_cells);
if (cpu->size_cells != 0)
DO_ERR("%s has bad #size-cells value %d (should be 0)\n",
cpu->fullpath, cpu->size_cells);
CHECK_HAVE_ONECELL(cpu, "reg");
if (prop) {
cell_t unitnum;
@ -618,47 +736,10 @@ static int check_chosen(struct node *root)
@@ -618,47 +736,10 @@ static int check_chosen(struct node *root)
return ok;
}
static int check_addr_size_reg(struct node *node,
int p_addr_cells, int p_size_cells)
{
int addr_cells = p_addr_cells;
int size_cells = p_size_cells;
struct property *prop;
struct node *child;
int ok = 1;
node->addr_cells = addr_cells;
node->size_cells = size_cells;
prop = get_property(node, "reg");
if (prop) {
int reg_entry_len = (addr_cells + size_cells) * sizeof(cell_t);
if ((prop->val.len % reg_entry_len) != 0)
DO_ERR("\"reg\" property in %s has invalid length (%d bytes) for given #address-cells (%d) and #size-cells (%d)\n",
node->fullpath, prop->val.len,
addr_cells, size_cells);
}
prop = get_property(node, "#address-cells");
if (prop)
addr_cells = propval_cell(prop);
prop = get_property(node, "#size-cells");
if (prop)
size_cells = propval_cell(prop);
for_each_child(node, child) {
ok = ok && check_addr_size_reg(child, addr_cells, size_cells);
}
return ok;
}
int check_semantics(struct node *dt, int outversion, int boot_cpuid_phys)
{
int ok = 1;
ok = ok && check_addr_size_reg(dt, -1, -1);
ok = ok && check_root(dt);
ok = ok && check_cpus(dt, outversion, boot_cpuid_phys);