From patchwork Mon Mar 20 14:44:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 95555 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp977715qgd; Mon, 20 Mar 2017 07:54:23 -0700 (PDT) X-Received: by 10.84.222.4 with SMTP id w4mr16901554pls.159.1490021663553; Mon, 20 Mar 2017 07:54:23 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 4si17813691plh.326.2017.03.20.07.54.23; Mon, 20 Mar 2017 07:54:23 -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 S1754301AbdCTOxb (ORCPT + 7 others); Mon, 20 Mar 2017 10:53:31 -0400 Received: from mail-ot0-f195.google.com ([74.125.82.195]:35587 "EHLO mail-ot0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754591AbdCTOw4 (ORCPT ); Mon, 20 Mar 2017 10:52:56 -0400 Received: by mail-ot0-f195.google.com with SMTP id a12so19562183ota.2; Mon, 20 Mar 2017 07:51:37 -0700 (PDT) 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=dtteb/sbZG1gHXzI2bcgoF7e8UNsWAz5tAGjo1SE5vk=; b=qpo+5I0JhqVvyolj5RCdxACkoDfNexEnkOQsOsi3Ad6A0yDQCJpFEHoswt0uTcp8+r YF1KSLjl2Km5fT9aXaF9Y5DwKlJV907vqOPgZGlOEh0q58ChwOO5EZiM3O+G2OrlQ87Y u7T5U02o+IFndE24e023KY1AobWj+TELOtETdaP9XmMgiL1ci0hr3cJ0ypOnPmxzM+Nb wb0+IwxaTQoGTeAV4uYxM47iJeEEpKgdDpCcjATRQe2T/6qsXRQPOlwi0r6iLqi/ZWWG iVNPa0C3FTsaXPLzte0mFVydH7e3348ldn7NqmqKPXGDUoOmkxvx1gP1gJkB8aWcTUKp cE/g== X-Gm-Message-State: AFeK/H3Xs5LCjQmXjixsdZo05DBbOiwa871+FQtuj2DQJgEsXz6nGcFDWNS4xZbvrdMEGw== X-Received: by 10.157.3.136 with SMTP id f8mr17025239otf.141.1490021062737; Mon, 20 Mar 2017 07:44:22 -0700 (PDT) Received: from rob-hp-laptop.herring.priv (66-90-148-125.dyn.grandenetworks.net. [66.90.148.125]) by smtp.googlemail.com with ESMTPSA id c55sm7536708otd.31.2017.03.20.07.44.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Mar 2017 07:44:22 -0700 (PDT) From: Rob Herring To: David Gibson Cc: devicetree@vger.kernel.org, devicetree-compiler@vger.kernel.org Subject: [PATCH v4 2/3] checks: Add bus checks for simple-bus buses Date: Mon, 20 Mar 2017 09:44:17 -0500 Message-Id: <20170320144418.5021-3-robh@kernel.org> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170320144418.5021-1-robh@kernel.org> References: <20170320144418.5021-1-robh@kernel.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add checks to identify simple-bus bus types and checks for child devices. Simple-bus type is generally identified by "simple-bus" compatible string. We also treat the root as a simple-bus, but only for child nodes with reg property. Signed-off-by: Rob Herring --- v4: - Avoid strlen overrunning property buffer in node_is_compatible - Drop assuming root node is a simple-bus v3: - new patch checks.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 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 427a5787b004..33036b8dbbc2 100644 --- a/checks.c +++ b/checks.c @@ -813,6 +813,73 @@ static void check_pci_device_reg(struct check *c, struct dt_info *dti, struct no } WARNING(pci_device_reg, check_pci_device_reg, NULL, ®_format); +static const struct bus_type simple_bus = { + .name = "simple-bus", +}; + +static bool node_is_compatible(struct node *node, const char *compat) +{ + struct property *prop; + const char *str, *end; + + prop = get_property(node, "compatible"); + if (!prop) + return false; + + for (str = prop->val.val, end = str + prop->val.len; str < end; + str += strnlen(str, end - str) + 1) { + if (strneq(str, compat, end - str)) + return true; + } + return false; +} + +static void check_simple_bus_bridge(struct check *c, struct dt_info *dti, struct node *node) +{ + if (node_is_compatible(node, "simple-bus")) + node->bus = &simple_bus; +} +WARNING(simple_bus_bridge, check_simple_bus_bridge, NULL, &addr_size_cells); + +static void check_simple_bus_reg(struct check *c, struct dt_info *dti, struct node *node) +{ + struct property *prop; + const char *unitname = get_unitname(node); + char unit_addr[17]; + unsigned int size; + uint64_t reg = 0; + cell_t *cells = NULL; + + if (!node->parent || (node->parent->bus != &simple_bus)) + return; + + prop = get_property(node, "reg"); + if (prop) + cells = (cell_t *)prop->val.val; + else { + prop = get_property(node, "ranges"); + if (prop && prop->val.len) + /* skip of child address */ + cells = ((cell_t *)prop->val.val) + node_addr_cells(node); + } + + if (!cells) { + if (node->parent->parent && !(node->bus == &simple_bus)) + FAIL(c, dti, "Node %s missing or empty reg/ranges property", node->fullpath); + return; + } + + size = node_addr_cells(node->parent); + while (size--) + reg = (reg << 32) | fdt32_to_cpu(*(cells++)); + + snprintf(unit_addr, sizeof(unit_addr), "%lx", reg); + if (!streq(unitname, unit_addr)) + FAIL(c, dti, "Node %s simple-bus unit address format error, expected \"%s\"", + node->fullpath, unit_addr); +} +WARNING(simple_bus_reg, check_simple_bus_reg, NULL, ®_format, &simple_bus_bridge); + /* * Style checks */ @@ -889,6 +956,9 @@ static struct check *check_table[] = { &pci_device_reg, &pci_device_bus_num, + &simple_bus_bridge, + &simple_bus_reg, + &avoid_default_addr_size, &obsolete_chosen_interrupt_controller,