From patchwork Thu Mar 24 00:40:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 64283 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp347076lbc; Wed, 23 Mar 2016 17:41:00 -0700 (PDT) X-Received: by 10.67.6.10 with SMTP id cq10mr8427454pad.120.1458780060216; Wed, 23 Mar 2016 17:41:00 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qx12si7793466pab.169.2016.03.23.17.40.59; Wed, 23 Mar 2016 17:41:00 -0700 (PDT) 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 S1753782AbcCXAk6 (ORCPT + 7 others); Wed, 23 Mar 2016 20:40:58 -0400 Received: from mail-ob0-f175.google.com ([209.85.214.175]:32907 "EHLO mail-ob0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753656AbcCXAk5 (ORCPT ); Wed, 23 Mar 2016 20:40:57 -0400 Received: by mail-ob0-f175.google.com with SMTP id xj3so26392860obb.0; Wed, 23 Mar 2016 17:40:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ceQw3rJIxwkWVCdLNksf4Zh8PcsBUPDyfd0e1bN1CFM=; b=Fl9BMSkzpcRto4jPa+oad2hBpQ0MFLrXuw3hOBRxHQ/n40SUQsVjLPuv+8CRbPFEFU mCpiTW9eLdk070hONI7N91BsVGicIArt/Q7xrReUFQiK7bMKLuWgI4SEzdElDfzx2LFJ 7fVNVUpA/aHsMaxdSoJMyz2NhMfPa31o+HlhR2x4nkLxoBejRPUj2mDw9Fp5bUNnWBYk cgq0WXClLC5BznGO5U8KnuYRWDEEJvGaPSjOiCsh01fCeHO36Lz0WZY1ZkbpCCEhUUVk ZfgzzbwhNR+k5YJzagHTZs4vtH2wZhqv68Cgl1lOUZWEJC2AVnhwy541nvXJMpZFaM31 q4pg== X-Gm-Message-State: AD7BkJJdrnkL+h6JRX/2Eu5q2EAgW7JgH53wqNEYEh422BIIC+KBPyf8bkvPCjDUIvUf8Q== X-Received: by 10.182.165.67 with SMTP id yw3mr3000347obb.45.1458780056698; Wed, 23 Mar 2016 17:40:56 -0700 (PDT) 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 c7sm1516559otb.24.2016.03.23.17.40.55 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 23 Mar 2016 17:40:56 -0700 (PDT) From: Rob Herring To: David Gibson Cc: devicetree-compiler@vger.kernel.org, devicetree@vger.kernel.org Subject: [RFC 1/3] checks: Add infrastructure for setting bus type of nodes Date: Wed, 23 Mar 2016 19:40:19 -0500 Message-Id: <1458780021-5052-1-git-send-email-robh@kernel.org> X-Mailer: git-send-email 2.5.0 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 the bus type for nodes. Initially, PCI and simple bus are supported. Signed-off-by: Rob Herring --- David, Hopefully this matches what you had in mind for bus checks. Rob checks.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ dtc.h | 11 +++++++++ 2 files changed, 90 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 diff --git a/checks.c b/checks.c index 386f956..48e926e 100644 --- a/checks.c +++ b/checks.c @@ -527,6 +527,84 @@ static void fixup_path_references(struct check *c, struct node *dt, ERROR(path_references, NULL, NULL, fixup_path_references, NULL, &duplicate_node_names); +static bool is_pci_bridge(struct node *node) +{ + struct property *prop; + + if (!node) + return false; + + prop = get_property(node, "device_type"); + if (!prop) + return false; + + if (strcmp(prop->val.val, "pci") == 0) + return true; + + return false; +} + +struct bus_type pci_bus_type = { + .expected_addr_cells = 3, + .expected_size_cells = 2, + .is_type = is_pci_bridge, +}; + +static bool is_simple_bridge(struct node *node) +{ + struct property *prop; + int len = 0; + + if (!node) + return false; + + /* root node is special case defaulting to simple-bus */ + if (!node->parent) + return true; + + prop = get_property(node, "compatible"); + if (!prop) + return false; + + do { + const char *str = prop->val.val; + + if (strcmp(str, "simple-bus") == 0) + return true; + len += strlen(str) + 1; + str += len; + } while (len < prop->val.len); + + return false; +} + +struct bus_type simple_bus_type = { + .expected_addr_cells = -1, /* For don't care */ + .expected_size_cells = -1, + .is_type = is_simple_bridge, +}; + +struct bus_type *bus_types[] = { + &pci_bus_type, + &simple_bus_type, + NULL +}; + +static void fixup_bus_type(struct check *c, struct node *dt, + struct node *node) +{ + struct bus_type **bus; + + for (bus = bus_types; *bus != NULL; bus++) { + if (!(*bus)->is_type(node)) + continue; + + node->bus_type = *bus; + break; + } +} +ERROR(bus_type, NULL, fixup_bus_type, NULL, NULL); + /* * Semantic checks */ @@ -685,6 +763,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, diff --git a/dtc.h b/dtc.h index 56212c8..c1a1fe9 100644 --- a/dtc.h +++ b/dtc.h @@ -132,6 +132,16 @@ struct label { struct label *next; }; +struct check; +struct node; + +struct bus_type { + int expected_addr_cells; + int expected_size_cells; + bool (*is_type)(struct node *node); + void (*check_unit_addr)(struct check *c, struct node *dt, struct node *node); +}; + struct property { bool deleted; char *name; @@ -158,6 +168,7 @@ struct node { int addr_cells, size_cells; struct label *labels; + struct bus_type *bus_type; }; #define for_each_label_withdel(l0, l) \