diff mbox

[RFC,3/3] checks: Add unit-address checks for PCI buses

Message ID 1458780021-5052-3-git-send-email-robh@kernel.org
State New
Headers show

Commit Message

Rob Herring March 24, 2016, 12:40 a.m. UTC
PCI device unit addresses are in the form DD or DD,F where DD is the
device 0-0x1f and F is the function 0-7. Add checks that the unit
address matches this form.

Signed-off-by: Rob Herring <robh@kernel.org>

---
 checks.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Rob Herring April 1, 2016, 7:52 p.m. UTC | #1
On Thu, Mar 31, 2016 at 12:32 AM, David Gibson
<david@gibson.dropbear.id.au> wrote:
> On Wed, Mar 23, 2016 at 07:40:21PM -0500, Rob Herring wrote:

>> PCI device unit addresses are in the form DD or DD,F where DD is the

>> device 0-0x1f and F is the function 0-7. Add checks that the unit

>> address matches this form.

>

> Hmm.. we ought to be able to do a bit better than this, again by

> constructing the expected unit address from reg.


If I do that, I can't check the dev and function values are within range.

> While we're at it,

> it probably makes sense to have that dependent on a check which makes

> sure the first entry in a pci device's 'reg' is the config address.


You mean just check the first cell masked with 0x1f000000 is 0, right?

Really, I'm not so worried about checking PCI devices. DT's with PCI
devices described are rare. All I really want to check first are
leading 0s, leading 0x and uppercase hex. That's 90% of what I find in
reviews and am tired of commenting on. I do think bus specific checks
are useful, but don't think we need to fill them all in right now.

Rob
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/checks.c b/checks.c
index 82a7f38..1d0fcfb 100644
--- a/checks.c
+++ b/checks.c
@@ -549,10 +549,30 @@  static bool is_pci_bridge(struct node *node)
 	return false;
 }
 
+static void pci_unit_addr(struct check *c, struct node *dt, struct node *node)
+{
+	const char *unitname = get_unitname(node);
+	unsigned int dev, func;
+	int ret;
+
+	ret = sscanf(unitname, "%2x,%1x", &dev, &func);
+	if (ret >= 1) {
+		if (dev > 0x1f)
+			FAIL(c, "Node %s PCI device number out of range",
+			     node->fullpath);
+	}
+	if (ret == 2) {
+		if (func > 7)
+			FAIL(c, "Node %s PCI function number out of range",
+			     node->fullpath);
+	}
+}
+
 struct bus_type pci_bus_type = {
         .expected_addr_cells = 3,
         .expected_size_cells = 2,
         .is_type = is_pci_bridge,
+        .check_unit_addr = pci_unit_addr,
 };
 
 static bool is_simple_bridge(struct node *node)