From: Andre Przywara <andre.przywara-5wv7dgnIgG8@public.gmane.org>
To: David Gibson
<david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>,
Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [RFC PATCH v3 3/3] checks: interrupt-map: Dump entries on error
Date: Tue, 2 Jun 2020 12:04:19 +0100 [thread overview]
Message-ID: <20200602110419.22488-4-andre.przywara@arm.com> (raw)
In-Reply-To: <20200602110419.22488-1-andre.przywara-5wv7dgnIgG8@public.gmane.org>
While the interrupt-map property is now validated, the current error
messages will probably leave people scratching their head on what the
actual problem is.
To help with the diagnosis, dump the map property formatted in a way
that corresponds to the actual interpretation from an IRQ consumer's
point of view. While this can't pinpoint the actual problem, it's much
easier to see what went wrong, especially when comparing it to the .dts
source.
As this will generate one line per mapped interrupt, it can be
potentially long on those larger maps.
A report would look like this:
Warning (interrupt_map): /soc/pci@1c00000:interrupt-map: invalid phandle for interrupt-map entry
< <0x0 0x0 0x0>, <0x1>, <&gic@17a00000>, <0x0>, <0x87 0x4 0x0> >,
< <0x0 0x0 0x2>, <0x1>, <&invalid>, >
Signed-off-by: Andre Przywara <andre.przywara-5wv7dgnIgG8@public.gmane.org>
---
checks.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 78 insertions(+)
diff --git a/checks.c b/checks.c
index 7b54981..f712e23 100644
--- a/checks.c
+++ b/checks.c
@@ -1636,6 +1636,80 @@ static void check_interrupts_property(struct check *c,
WARNING(interrupts_property, check_interrupts_property, &phandle_references,
&interrupt_cells_is_cell, &interrupt_provider);
+static void dump_cell_group(struct property *prop, int index, int cells,
+ int nr_cells)
+{
+ int limit, i;
+
+ if (index + cells > nr_cells)
+ limit = nr_cells - index;
+ else
+ limit = cells;
+
+ fputs("<", stderr);
+ for (i = 0; i < limit; i++) {
+ cell_t v = propval_cell_n(prop, index + i);
+ fprintf(stderr, "%s0x%x", i == 0 ? "" : " ", v);
+ }
+ if (limit < cells)
+ fputs(", MISSING", stderr);
+ fputs(">", stderr);
+}
+
+static void dump_interrupt_map(struct node *root, struct node *nexus,
+ struct property *map, int irq_cells)
+{
+ int cells = map->val.len / 4;
+ struct property *prop;
+ int value;
+ int i;
+
+ for (i = 0; i < cells;) {
+ struct node *intc = NULL;
+
+ fprintf(stderr, "%s\t< ", i == 0 ? "" : ",\n");
+ dump_cell_group(map, i, node_addr_cells(nexus), cells);
+ fputs(", ", stderr);
+ dump_cell_group(map, i + node_addr_cells(nexus), irq_cells, cells);
+ fputs(", <&", stderr);
+ i += node_addr_cells(nexus) + irq_cells;
+ if (i >= cells)
+ break;
+ value = propval_cell_n(map, i);
+ if (value != 0)
+ intc = get_node_by_phandle(root, value);
+ fprintf(stderr, "%s>, ",
+ intc && intc->name ? intc->name : "invalid");
+ if (!intc) {
+ fprintf(stderr, ">\n");
+ return;
+ }
+ /*
+ * Linux treats non-existing #address-cells in the interrupt
+ * parent as 0 (and not 2, as the spec says).
+ * Deal with that, since many DTs rely on that.
+ */
+ prop = get_property(intc, "#address-cells");
+ if (prop)
+ value = propval_cell(prop);
+ else
+ value = 0;
+ dump_cell_group(map, i + 1, value, cells);
+ fputs(", ", stderr);
+ i += 1 + value;
+
+ prop = get_property(intc, "#interrupt-cells");
+ if (prop) {
+ value = propval_cell(prop);
+ dump_cell_group(map, i, value, cells);
+ } else
+ fputs("<?>", stderr);
+ fputs(" >", stderr);
+ i += value;
+ }
+ fputs("\n", stderr);
+}
+
static void check_interrupt_map(struct check *c, struct dt_info *dti,
struct node *node)
{
@@ -1667,6 +1741,7 @@ static void check_interrupt_map(struct check *c, struct dt_info *dti,
if (phandle_idx + 1 >= cells) {
FAIL_PROP(c, dti, node, map,
"insufficient cells for interrupt-map entry");
+ dump_interrupt_map(dti->dt, node, map, irq_cells);
return;
}
intc_phandle = propval_cell_n(map, phandle_idx);
@@ -1680,12 +1755,14 @@ static void check_interrupt_map(struct check *c, struct dt_info *dti,
if (!intc) {
FAIL_PROP(c, dti, node, map,
"invalid phandle for interrupt-map entry");
+ dump_interrupt_map(dti->dt, node, map, irq_cells);
return;
}
if (!node_is_interrupt_provider(intc)) {
FAIL_PROP(c,dti, node, map,
"interrupt-map phandle does not point to interrupt provider");
+ dump_interrupt_map(dti->dt, node, map, irq_cells);
return;
}
@@ -1709,6 +1786,7 @@ static void check_interrupt_map(struct check *c, struct dt_info *dti,
if (phandle_idx + intc_addr_cells + intc_irq_cells >= cells) {
FAIL_PROP(c, dti, node, map,
"insufficient cells for interrupt-map entry");
+ dump_interrupt_map(dti->dt, node, map, irq_cells);
return;
}
i = phandle_idx + 1 + intc_addr_cells + intc_irq_cells;
--
2.14.1
prev parent reply other threads:[~2020-06-02 11:04 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-02 11:04 [PATCH v3 0/3] dtc: checks: Validate interrupt-map properties Andre Przywara
[not found] ` <20200602110419.22488-1-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-06-02 11:04 ` [PATCH v3 1/3] checks: Add interrupt provider test Andre Przywara
[not found] ` <20200602110419.22488-2-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-06-08 19:48 ` Rob Herring
2020-06-10 5:10 ` David Gibson
[not found] ` <20200610051057.GM494336-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2020-06-11 20:04 ` Rob Herring
2020-06-02 11:04 ` [PATCH v3 2/3] checks: Validate interrupt-map properties Andre Przywara
[not found] ` <20200602110419.22488-3-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-06-08 20:12 ` Rob Herring
2020-06-02 11:04 ` Andre Przywara [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200602110419.22488-4-andre.przywara@arm.com \
--to=andre.przywara-5wv7dgnigg8@public.gmane.org \
--cc=david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org \
--cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).