From patchwork Tue Jan 24 17:45:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 92381 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1829795qgi; Tue, 24 Jan 2017 09:45:39 -0800 (PST) X-Received: by 10.98.21.131 with SMTP id 125mr40760048pfv.110.1485279939726; Tue, 24 Jan 2017 09:45:39 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u5si19984577pgh.266.2017.01.24.09.45.39; Tue, 24 Jan 2017 09:45:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750788AbdAXRpi (ORCPT + 7 others); Tue, 24 Jan 2017 12:45:38 -0500 Received: from mail-ot0-f195.google.com ([74.125.82.195]:35841 "EHLO mail-ot0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750765AbdAXRph (ORCPT ); Tue, 24 Jan 2017 12:45:37 -0500 Received: by mail-ot0-f195.google.com with SMTP id 36so20452335otx.3; Tue, 24 Jan 2017 09:45:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+LpwoiI7kD3jnBmIudfUsRjIFfhdBmnXp5NM2+FTZ/8=; b=fj9OWBW+XGOij2isvy0VA2UnfJaQliUvzyabF0HkXSsIVKa9HvGci+O3U+Uzn36dVX Tf36j1Y7xX3vTIbG69YAt87jst5v0f3aliZveqDUBSCk5R07DvHBMRnbsAmmZ9YwgxSE Gg4ZyVkSX1bSfyVP6TX+P242UdTm2igJq7Ca/+jrFMq3TYm5Flchu/bIDjpxQLAZBPqk lnqbtZHyAhoDWoJrDwhZV3yAMZHBNixfRTOWYH0AhejWM1S0lftOj/SRIQBpHNKLN6NG 3ghUZ55mUmNUhq+x5fs8+OGMk1/fxvXsnZnVvudQTNRxU5ieK96a9mjlsAKzr7jIOe4w dFjQ== X-Gm-Message-State: AIkVDXJt7PVbYSvnDctxs6aN6yeHfuvjH0YZFonjpVt5rAQVj3Uy3ds1AkHyYOOQHjSjZA== X-Received: by 10.157.38.237 with SMTP id i42mr19341358otd.76.1485279936575; Tue, 24 Jan 2017 09:45:36 -0800 (PST) Received: from rob-hp-laptop.herring.priv (72-48-98-129.dyn.grandenetworks.net. [72.48.98.129]) by smtp.googlemail.com with ESMTPSA id w84sm10736088oiw.21.2017.01.24.09.45.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Jan 2017 09:45:36 -0800 (PST) From: Rob Herring To: David Gibson Cc: devicetree@vger.kernel.org, devicetree-compiler@vger.kernel.org Subject: [PATCH 1/5] checks: Add Warning for stricter property name character checking Date: Tue, 24 Jan 2017 11:45:30 -0600 Message-Id: <20170124174534.3865-2-robh@kernel.org> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170124174534.3865-1-robh@kernel.org> References: <20170124174534.3865-1-robh@kernel.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org While '?', '.', '+', '*', and '_' are considered valid characters their use is discouraged in recommended practices. '#' is also only recommended to be used at the beginning of property names. Testing this found one typo error with '.' used instead of ','. The rest of the warnings were all from underscores. Signed-off-by: Rob Herring --- checks.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) -- 2.10.1 -- 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 --git a/checks.c b/checks.c index 3d18e45374c8..a0d4a9d968d7 100644 --- a/checks.c +++ b/checks.c @@ -239,6 +239,7 @@ ERROR(duplicate_property_names, check_duplicate_property_names, NULL); #define UPPERCASE "ABCDEFGHIJKLMNOPQRSTUVWXYZ" #define DIGITS "0123456789" #define PROPNODECHARS LOWERCASE UPPERCASE DIGITS ",._+*#?-" +#define PROPNODECHARSSTRICT LOWERCASE UPPERCASE DIGITS ",-" static void check_node_name_chars(struct check *c, struct dt_info *dti, struct node *node) @@ -299,6 +300,38 @@ static void check_property_name_chars(struct check *c, struct dt_info *dti, } ERROR(property_name_chars, check_property_name_chars, PROPNODECHARS); +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 (strcmp(name, "device_type") == 0) + 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, "Character '%c' not recommended in property name \"%s\", node %s", + name[n], prop->name, node->fullpath); + } +} +WARNING(property_name_chars_strict, check_property_name_chars_strict, PROPNODECHARSSTRICT); + #define DESCLABEL_FMT "%s%s%s%s%s" #define DESCLABEL_ARGS(node,prop,mark) \ ((mark) ? "value of " : ""), \ @@ -703,6 +736,8 @@ static struct check *check_table[] = { &address_cells_is_cell, &size_cells_is_cell, &interrupt_cells_is_cell, &device_type_is_string, &model_is_string, &status_is_string, + &property_name_chars_strict, + &addr_size_cells, ®_format, &ranges_format, &unit_address_vs_reg, From patchwork Tue Jan 24 17:45:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 92382 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1829801qgi; Tue, 24 Jan 2017 09:45:40 -0800 (PST) X-Received: by 10.99.178.21 with SMTP id x21mr40668149pge.48.1485279940714; Tue, 24 Jan 2017 09:45:40 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u5si19984577pgh.266.2017.01.24.09.45.40; Tue, 24 Jan 2017 09:45:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750796AbdAXRpj (ORCPT + 7 others); Tue, 24 Jan 2017 12:45:39 -0500 Received: from mail-ot0-f195.google.com ([74.125.82.195]:35847 "EHLO mail-ot0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750738AbdAXRpi (ORCPT ); Tue, 24 Jan 2017 12:45:38 -0500 Received: by mail-ot0-f195.google.com with SMTP id 36so20452363otx.3; Tue, 24 Jan 2017 09:45:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=v6zyPpwvjXobZrdx+v3OS0b9K1+5vAVsGFJNEQLj9wI=; b=LMgSBQUiJdM5BRoT586TzjIbLhevKFZsm5KxdY6R8hSjMVkbrF9/qNFaiDn7b8pZdM yCzAVpjPvvbIbTCm6ckafwBlyRTlm8L0PE+7NJn6hDsJb7jUrL5DBoji1HYD5AobXnMP lFUQJJ84M26hjThu/4jJxyiN1y+9Q7gal79gUI5fja0YXRHeJaXaXRuzNsHEMtYyGgAK fTCGC4f66iPvWPEyIRHETS4YLJvxuu2ZF1+7xiTyxNnyfPaNmtQCOBErxX1RKvxPSWcz Gg4V4jCcUiPd3bipETClc5ZSKi3be65YWgvjEq0rqAGsvze+g20LGZsyMy5tXOSf+wyh p9QQ== X-Gm-Message-State: AIkVDXIrGMiGVgqefpMEp1keXLptVnNrBXcygUpe9Ef7dgXvdkPM1n2wZxk3gNNGRar/mQ== X-Received: by 10.157.7.17 with SMTP id 17mr15905918ote.231.1485279937299; Tue, 24 Jan 2017 09:45:37 -0800 (PST) Received: from rob-hp-laptop.herring.priv (72-48-98-129.dyn.grandenetworks.net. [72.48.98.129]) by smtp.googlemail.com with ESMTPSA id w84sm10736088oiw.21.2017.01.24.09.45.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Jan 2017 09:45:36 -0800 (PST) From: Rob Herring To: David Gibson Cc: devicetree@vger.kernel.org, devicetree-compiler@vger.kernel.org Subject: [PATCH 2/5] checks: Add Warning for stricter node name character checking Date: Tue, 24 Jan 2017 11:45:31 -0600 Message-Id: <20170124174534.3865-3-robh@kernel.org> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170124174534.3865-1-robh@kernel.org> References: <20170124174534.3865-1-robh@kernel.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org While '#', '?', '.', '+', '*', and '_' are considered valid characters, their use is discouraged in recommended practices. Testing this found a few cases of '.'. The majority of the warnings were all from underscores. Signed-off-by: Rob Herring --- checks.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) -- 2.10.1 -- 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 --git a/checks.c b/checks.c index a0d4a9d968d7..0c78d69316bc 100644 --- a/checks.c +++ b/checks.c @@ -252,6 +252,17 @@ static void check_node_name_chars(struct check *c, struct dt_info *dti, } ERROR(node_name_chars, check_node_name_chars, PROPNODECHARS "@"); +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, "Character '%c' not recommended in node %s", + node->name[n], node->fullpath); +} +WARNING(node_name_chars_strict, check_node_name_chars_strict, PROPNODECHARSSTRICT); + static void check_node_name_format(struct check *c, struct dt_info *dti, struct node *node) { @@ -737,6 +748,7 @@ static struct check *check_table[] = { &device_type_is_string, &model_is_string, &status_is_string, &property_name_chars_strict, + &node_name_chars_strict, &addr_size_cells, ®_format, &ranges_format, From patchwork Tue Jan 24 17:45:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 92383 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1829826qgi; Tue, 24 Jan 2017 09:45:42 -0800 (PST) X-Received: by 10.98.196.1 with SMTP id y1mr41092698pff.105.1485279942422; Tue, 24 Jan 2017 09:45:42 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u5si19984577pgh.266.2017.01.24.09.45.42; Tue, 24 Jan 2017 09:45:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750738AbdAXRpk (ORCPT + 7 others); Tue, 24 Jan 2017 12:45:40 -0500 Received: from mail-ot0-f194.google.com ([74.125.82.194]:34194 "EHLO mail-ot0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750765AbdAXRpi (ORCPT ); Tue, 24 Jan 2017 12:45:38 -0500 Received: by mail-ot0-f194.google.com with SMTP id 73so20434084otj.1; Tue, 24 Jan 2017 09:45:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=25m8LFwFXHOdlTy6lVMmOJXGaxlbxzJwfdegQ9vp3Pw=; b=aF3olemQi9b9hKSpw56sN5fiS4xHauXfQ00RHRgOK345Y+WEjcXOyd5Bple/k928Pv uo9GY6/RUHEceZ239AmZ+HQxpoAzTGPbWcwkFRk7jMshMJLcbcDeZYFdbzaCDK3elcp1 Y6TTWwkfkiPkV0yPVu80XErbFaIMTAvnEpdY1u3+q+jzHpnN4FqqG49sXJXncF2w8YAB 8TZ9L0U1N48YF79kpYghoNZ0h4wvvSQy1tepffrvOH+VP8rLJhYrCZpnQqs5vtlPJO3D rEBlRMmt1M1uaLv5SXwIemvNCUYkPTwz++5TAvgyBE7paZysYP/N1EthmgcFdwa+Tf1Z tQVA== X-Gm-Message-State: AIkVDXLqICsTA6ETjHpOfpH4pweEXHnWdQvVJ85v9megEb8VsFN98AD3ajPTjCwMKDD7Fg== X-Received: by 10.157.4.1 with SMTP id 1mr15286009otc.205.1485279937976; Tue, 24 Jan 2017 09:45:37 -0800 (PST) Received: from rob-hp-laptop.herring.priv (72-48-98-129.dyn.grandenetworks.net. [72.48.98.129]) by smtp.googlemail.com with ESMTPSA id w84sm10736088oiw.21.2017.01.24.09.45.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Jan 2017 09:45:37 -0800 (PST) From: Rob Herring To: David Gibson Cc: devicetree@vger.kernel.org, devicetree-compiler@vger.kernel.org Subject: [PATCH 3/5] checks: Warn on node name unit-addresses with '0x' or leading 0s Date: Tue, 24 Jan 2017 11:45:32 -0600 Message-Id: <20170124174534.3865-4-robh@kernel.org> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170124174534.3865-1-robh@kernel.org> References: <20170124174534.3865-1-robh@kernel.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Node name unit-addresses should never begin with 0x or leading 0s regardless of whether they have a bus specific address (i.e. one with commas) or not. Add warnings to check for these cases. Signed-off-by: Rob Herring --- checks.c | 10 ++++++++++ tests/run_tests.sh | 2 ++ tests/unit-addr-leading-0s.dts | 10 ++++++++++ tests/unit-addr-leading-0x.dts | 10 ++++++++++ 4 files changed, 32 insertions(+) create mode 100644 tests/unit-addr-leading-0s.dts create mode 100644 tests/unit-addr-leading-0x.dts -- 2.10.1 -- 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 --git a/checks.c b/checks.c index 0c78d69316bc..8e310d69ca3d 100644 --- a/checks.c +++ b/checks.c @@ -288,6 +288,16 @@ static void check_unit_address_vs_reg(struct check *c, struct dt_info *dti, if (!unitname[0]) FAIL(c, "Node %s has a reg or ranges property, but no unit name", node->fullpath); + + if (!strncmp(unitname, "0x", 2)) { + FAIL(c, "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, "Node %s unit name should not have leading 0s", + node->fullpath); } else { if (unitname[0]) FAIL(c, "Node %s has a unit name, but no reg property", diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 157dbaea7600..2c06666a9e23 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -539,6 +539,8 @@ dtc_tests () { check_tests obsolete-chosen-interrupt-controller.dts obsolete_chosen_interrupt_controller check_tests reg-without-unit-addr.dts unit_address_vs_reg check_tests unit-addr-without-reg.dts unit_address_vs_reg + check_tests unit-addr-leading-0x.dts unit_address_vs_reg + check_tests unit-addr-leading-0s.dts unit_address_vs_reg run_sh_test dtc-checkfails.sh node_name_chars -- -I dtb -O dtb bad_node_char.dtb run_sh_test dtc-checkfails.sh node_name_format -- -I dtb -O dtb bad_node_format.dtb run_sh_test dtc-checkfails.sh prop_name_chars -- -I dtb -O dtb bad_prop_char.dtb diff --git a/tests/unit-addr-leading-0s.dts b/tests/unit-addr-leading-0s.dts new file mode 100644 index 000000000000..7c8e2cebbc84 --- /dev/null +++ b/tests/unit-addr-leading-0s.dts @@ -0,0 +1,10 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + node@001 { + reg = <1 0>; + }; +}; diff --git a/tests/unit-addr-leading-0x.dts b/tests/unit-addr-leading-0x.dts new file mode 100644 index 000000000000..7ed7254e8dc2 --- /dev/null +++ b/tests/unit-addr-leading-0x.dts @@ -0,0 +1,10 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + node@0x1 { + reg = <1 0>; + }; +}; From patchwork Tue Jan 24 17:45:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 92384 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1829831qgi; Tue, 24 Jan 2017 09:45:42 -0800 (PST) X-Received: by 10.98.192.216 with SMTP id g85mr40113258pfk.117.1485279942790; Tue, 24 Jan 2017 09:45:42 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u5si19984577pgh.266.2017.01.24.09.45.42; Tue, 24 Jan 2017 09:45:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750765AbdAXRpl (ORCPT + 7 others); Tue, 24 Jan 2017 12:45:41 -0500 Received: from mail-ot0-f195.google.com ([74.125.82.195]:35860 "EHLO mail-ot0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750797AbdAXRpj (ORCPT ); Tue, 24 Jan 2017 12:45:39 -0500 Received: by mail-ot0-f195.google.com with SMTP id 36so20452459otx.3; Tue, 24 Jan 2017 09:45:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Kg+GV/0aENg7rfmtqthWXL8IIquGmInJY9hC/+/H524=; b=TI+RW/WE8B7H2iPQMvTVnv//BRDQO17cVQy4ZRozwg4yEk0qzdZ+a4yUUcMcq+fahS 4oZXteBJ7Nj0+6xz+Wq89xDVjDV6RoH+HUHZpWNabmLFppI9N0AEWV2wE3jnruA3gd8d C5BVq4KoiDvcGbJOW9sMeu41whM1HMRYosPdermmdFISLsn9ky8p7XLA30T6dXAP4XkB yY2Ke2yS9dO03cVx3J1dXKGaTgHAFT1vhONZoW5vhKe6TDMrdixpSEgjcA39q9iHUtdU BwNbETE3yCgVt+AeB190Bwnkfz4/4zSFKkXw7evoPr8tZ/r8O+e0rVngUVB1/ckdOdir mbMg== X-Gm-Message-State: AIkVDXKDFoeGM5Ij2BylE3eWDSTe2EPvlLJ5vWznVVlwZIo92y8prhM36ylrauIpHMl4hQ== X-Received: by 10.157.27.154 with SMTP id z26mr18821883otd.181.1485279938699; Tue, 24 Jan 2017 09:45:38 -0800 (PST) Received: from rob-hp-laptop.herring.priv (72-48-98-129.dyn.grandenetworks.net. [72.48.98.129]) by smtp.googlemail.com with ESMTPSA id w84sm10736088oiw.21.2017.01.24.09.45.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Jan 2017 09:45:38 -0800 (PST) From: Rob Herring To: David Gibson Cc: devicetree@vger.kernel.org, devicetree-compiler@vger.kernel.org Subject: [PATCH 4/5] checks: Add infrastructure for setting bus type of nodes Date: Tue, 24 Jan 2017 11:45:33 -0600 Message-Id: <20170124174534.3865-5-robh@kernel.org> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170124174534.3865-1-robh@kernel.org> References: <20170124174534.3865-1-robh@kernel.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org In preparation to support bus specific checks, add the necessary infrastructure to determine and set the bus type for nodes. Signed-off-by: Rob Herring --- checks.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ dtc.h | 11 +++++++++++ 2 files changed, 62 insertions(+) -- 2.10.1 -- 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 Signed-off-by: Rob Herring diff --git a/checks.c b/checks.c index 8e310d69ca3d..5ef63a6a4317 100644 --- a/checks.c +++ b/checks.c @@ -587,6 +587,53 @@ static void fixup_path_references(struct check *c, struct dt_info *dti, } ERROR(path_references, fixup_path_references, NULL, &duplicate_node_names); +struct bus_type *bus_types[] = { + NULL +}; + +static void fixup_bus_type(struct check *c, struct dt_info *dti, + struct node *node) +{ + struct bus_type **bus; + + for (bus = bus_types; *bus != NULL; bus++) { + if (!(*bus)->bridge_is_type(node)) + continue; + + node->bus_type = *bus; + break; + } +} +ERROR(bus_type, fixup_bus_type, NULL); + +static void check_bus_bridge(struct check *c, struct dt_info *dti, + struct node *node) +{ + struct bus_type *bt; + + if (!node->bus_type) + return; + + bt = node->bus_type; + if (bt->check_bridge) + bt->check_bridge(c, dti, node); +} +WARNING(bus_bridge, check_bus_bridge, NULL); + +static void check_bus_device(struct check *c, struct dt_info *dti, + struct node *node) +{ + struct bus_type *bt; + + if (!node->parent || !node->parent->bus_type) + return; + + bt = node->parent->bus_type; + if (bt->check_device) + bt->check_device(c, dti, node); +} +WARNING(bus_device, check_bus_device, NULL); + /* * Semantic checks */ @@ -753,6 +800,7 @@ static struct check *check_table[] = { &explicit_phandles, &phandle_references, &path_references, + &bus_type, &address_cells_is_cell, &size_cells_is_cell, &interrupt_cells_is_cell, &device_type_is_string, &model_is_string, &status_is_string, @@ -764,6 +812,9 @@ static struct check *check_table[] = { &unit_address_vs_reg, + &bus_bridge, + &bus_device, + &avoid_default_addr_size, &obsolete_chosen_interrupt_controller, diff --git a/dtc.h b/dtc.h index c6f125c68ba8..f27397cd7622 100644 --- a/dtc.h +++ b/dtc.h @@ -136,6 +136,16 @@ struct label { struct label *next; }; +struct check; +struct node; +struct dt_info; + +struct bus_type { + bool (*bridge_is_type)(struct node *node); + void (*check_bridge)(struct check *c, struct dt_info *dti, struct node *node); + void (*check_device)(struct check *c, struct dt_info *dti, struct node *node); +}; + struct property { bool deleted; char *name; @@ -162,6 +172,7 @@ struct node { int addr_cells, size_cells; struct label *labels; + struct bus_type *bus_type; }; #define for_each_label_withdel(l0, l) \ From patchwork Tue Jan 24 17:45:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 92385 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1829833qgi; Tue, 24 Jan 2017 09:45:43 -0800 (PST) X-Received: by 10.99.39.71 with SMTP id n68mr41172243pgn.85.1485279943087; Tue, 24 Jan 2017 09:45:43 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u5si19984577pgh.266.2017.01.24.09.45.42; Tue, 24 Jan 2017 09:45:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750806AbdAXRpm (ORCPT + 7 others); Tue, 24 Jan 2017 12:45:42 -0500 Received: from mail-ot0-f193.google.com ([74.125.82.193]:32945 "EHLO mail-ot0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750803AbdAXRpk (ORCPT ); Tue, 24 Jan 2017 12:45:40 -0500 Received: by mail-ot0-f193.google.com with SMTP id f9so20468015otd.0; Tue, 24 Jan 2017 09:45:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OdQ39pbYvpxkOhFOCaWmjxt22IcP3+SB72iK1KyLRSg=; b=VNd8gvtNKr0B4ins/p/2CO9I/iehn6UPXh0DAVqdRHpKXnDIXrHhh2VQ0Z7iaFFcCs CsUr1ewTvwBYg5rXQSCCLSKRrEvTK7iJKaHAdt0/WDuAcb31dblu/LN6pA4R56hvbUVk 4GWsir7rGFpJOqg5FpVKWVOWcXUbGQlY1ebFdXh9KSbHq1hhmoTcuRHAl/V4x7nW9R5T H8mv3TAWcBXDqpvBImgqZLpVGp/C3BgUVcHyBi+Y1ovr4qcGw24Jv8pjlkRtKM2aMmwC WjNLmOCEdr0Wrwyvjm/GYXKgjA+gR9PPKvdQGi/k/A3N9ZsAeGx38KvHnDqpCq0couhr Hndw== X-Gm-Message-State: AIkVDXJF86J0Z/HlKgn2qSmBIdG0gN/QoEtIuulIZ6zLnv7IlSP5AYhW1/RNVCZ/5yMRLQ== X-Received: by 10.157.36.161 with SMTP id z30mr18939757ota.208.1485279939462; Tue, 24 Jan 2017 09:45:39 -0800 (PST) Received: from rob-hp-laptop.herring.priv (72-48-98-129.dyn.grandenetworks.net. [72.48.98.129]) by smtp.googlemail.com with ESMTPSA id w84sm10736088oiw.21.2017.01.24.09.45.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Jan 2017 09:45:38 -0800 (PST) From: Rob Herring To: David Gibson Cc: devicetree@vger.kernel.org, devicetree-compiler@vger.kernel.org Subject: [PATCH 5/5] checks: Add bus checks for PCI buses Date: Tue, 24 Jan 2017 11:45:34 -0600 Message-Id: <20170124174534.3865-6-robh@kernel.org> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170124174534.3865-1-robh@kernel.org> References: <20170124174534.3865-1-robh@kernel.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add PCI bridge and device node checks. We identify PCI bridges with 'device_type = "pci"' as only PCI bridges should set that property. For bridges, we do a secondary check that the bridge has a ranges property in cases of nodes incorrectly setting 'device_type = "pci"'. For devices, the primary check is the reg property and the unit address. 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. Signed-off-by: Rob Herring --- checks.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 86 insertions(+), 5 deletions(-) -- 2.10.1 -- 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 --git a/checks.c b/checks.c index 5ef63a6a4317..f5fcd625a19b 100644 --- a/checks.c +++ b/checks.c @@ -20,6 +20,11 @@ #include "dtc.h" +#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) + #ifdef TRACE_CHECKS #define TRACE(c, ...) \ do { \ @@ -587,7 +592,88 @@ static void fixup_path_references(struct check *c, struct dt_info *dti, } ERROR(path_references, fixup_path_references, NULL, &duplicate_node_names); +static bool is_pci_bridge(struct node *node) +{ + struct property *prop; + + prop = get_property(node, "device_type"); + if (!prop) + return false; + + if (strcmp(prop->val.val, "pci") == 0) + return true; + + return false; +} + +static void pci_check_bridge(struct check *c, struct dt_info *dti, struct node *node) +{ + struct property *prop; + + prop = get_property(node, "ranges"); + if (!prop) { + FAIL(c, "Node %s missing ranges for PCI bridge (or not a bridge)", + node->fullpath); + return; + } + + if (node_addr_cells(node) != 3) + FAIL(c, "Node %s incorrect #address-cells for PCI bridge", + node->fullpath); + if (node_size_cells(node) != 2) + FAIL(c, "Node %s incorrect #size-cells for PCI bridge", + node->fullpath); +} + +static void pci_check_device(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; + + prop = get_property(node, "reg"); + if (!prop) + return; + + reg = fdt32_to_cpu(*((cell_t *)prop->val.val)); + + dev = (reg & 0xf800) >> 11; + func = (reg & 0x700) >> 8; + + if (reg & 0xff000000) + FAIL(c, "Node %s PCI reg address is not configuration space", + node->fullpath); + + if (dev > 0x1f) + FAIL(c, "Node %s PCI device number out of range", + node->fullpath); + if (func > 7) + FAIL(c, "Node %s PCI function number out of range", + node->fullpath); + + if (func == 0) { + snprintf(unit_addr, sizeof(unit_addr), "%x", dev); + if (!strcmp(unitname, unit_addr)) + return; + } + + snprintf(unit_addr, sizeof(unit_addr), "%x,%x", dev, func); + if (!strcmp(unitname, unit_addr)) + return; + + FAIL(c, "Node %s PCI unit address format error, expected \"%s\"", + node->fullpath, unit_addr); +} + +struct bus_type pci_bus_type = { + .bridge_is_type = is_pci_bridge, + .check_bridge = pci_check_bridge, + .check_device = pci_check_device, +}; + struct bus_type *bus_types[] = { + &pci_bus_type, NULL }; @@ -664,11 +750,6 @@ static void fixup_addr_size_cells(struct check *c, struct dt_info *dti, WARNING(addr_size_cells, fixup_addr_size_cells, NULL, &address_cells_is_cell, &size_cells_is_cell); -#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) - static void check_reg_format(struct check *c, struct dt_info *dti, struct node *node) {