From patchwork Thu Nov 9 17:09:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 10051357 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 070B660381 for ; Thu, 9 Nov 2017 17:13:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E2E042B041 for ; Thu, 9 Nov 2017 17:13:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7C9A2B043; Thu, 9 Nov 2017 17:13:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 808C12B04D for ; Thu, 9 Nov 2017 17:13:17 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eCqLl-00046N-3G; Thu, 09 Nov 2017 17:10:45 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eCqLj-00043x-Ks for xen-devel@lists.xenproject.org; Thu, 09 Nov 2017 17:10:43 +0000 Received: from [85.158.137.68] by server-12.bemta-3.messagelabs.com id 28/48-15886-21C840A5; Thu, 09 Nov 2017 17:10:42 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrLIsWRWlGSWpSXmKPExsVyMfS6k65QD0u UwdOPQhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bdM5/YCvYIVbzZdJe9gfEXbxcjF4eQwHRG ic3rpzKCOCwCL1kkrr/bywriSAj0s0pMeLQMKMMB5GRJ7H5v18XICWSmSXS+XMcKYVdJNK7fz ghiCwkoSbzeuZkJwp7NJPF4axWIzSZgILH/3RN2EFsEqObeqslMIPOZBfoZJWbM+Q82SFggSG LRxxdgg1gEVCU+HtwKZvMKuEjM6FrADrFMTuLmuU5mEJsTKP7m43U2iGXOEhdfH2ebwCi4gJF hFaN6cWpRWWqRrrleUlFmekZJbmJmjq6hgbFebmpxcWJ6ak5iUrFecn7uJkZgwDEAwQ7Gxu9O hxglOZiURHmlLFmihPiS8lMqMxKLM+KLSnNSiw8xynBwKEnwTuoCygkWpaanVqRl5gBDHyYtw cGjJMK7ESTNW1yQmFucmQ6ROsVoz3HhzqU/TBwH9twCks9mvm5g5ph2tbWJWYglLz8vVUqc16 obqE0ApC2jNA9uKCxWLzHKSgnzMgKdKcRTkFqUm1mCKv+KUZyDUUmY1xBkCk9mXgnc7ldAZzE BnRXNDnZWSSJCSqqBsdWp5sq/lxl7K+dU333+LXTeCpOQzPJgro+xL+x/W7Tnb/qak9nQ5/p3 ssITp9iUa9oB6xmzBcTenF3/e2nOVSW2S2l9X+vmHj6Xl350c33+bwXu6qrprCyuqrZF7A9PO Fz5Gp+3MuymV+iDq13elhNqN65czFqbc1Gz5WAAm+f0iULtpsrSSizFGYmGWsxFxYkAuAHMXd ACAAA= X-Env-Sender: olekstysh@gmail.com X-Msg-Ref: server-9.tower-31.messagelabs.com!1510247442!58804208!1 X-Originating-IP: [209.85.215.66] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 2148 invoked from network); 9 Nov 2017 17:10:42 -0000 Received: from mail-lf0-f66.google.com (HELO mail-lf0-f66.google.com) (209.85.215.66) by server-9.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 9 Nov 2017 17:10:42 -0000 Received: by mail-lf0-f66.google.com with SMTP id 90so8024052lfs.13 for ; Thu, 09 Nov 2017 09:10:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+1ejMnDRgsRDsbr0w+CUW+3UOWtFocW+7ZO+CCRRqig=; b=HbDdaXsT1H6lcgzRgV9tDPY6WiEcw+Bph5gxja8u7sDs+tAdMu0OpkaKzrvCRydTaj Fh5m/WIeOBklGX7OawNmuAe1koxsfMAfdob5MfqCWgUHhLeuFiz0to8lM9q8e6QOF8FY ghyvZKnmyKT9RBSSlDxuyGM4jDrmRqbBbQ0w2wBBWdF3FBdofrTGUz46DCFSW8XZKEFi 7e0bCtQvY9riSmM+8Rc3vHKB4TFPdN3nRJPts7lpIvHtyv4a3p7euklf90IaACJZ5MgQ m02OZPH12FlfADTZfAY37wr2L1gVc8Hgqs2poxBfy++L+7nV1GIvvvjU/f2g4VJ3/9WA +tYg== 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=+1ejMnDRgsRDsbr0w+CUW+3UOWtFocW+7ZO+CCRRqig=; b=b30diH3p6Ng/13CfY1zKqKFh9aMbdIW8t2bUDOIx9rv58U9OCm0HLc+okoR7hsIC6A VJefDb6oAZWSbexjijeXsUtslqoThoWcfrDXLZ7LV5unIA2H2hjlfnf3PeALXBpR70w6 vH/Ex46cXIIht9XnZe8nPI/N2nE/lE6uj8/HIRZNUqWiYoyTVAdQtOJGTZbitbeEs+FA thtwhRGER/WwxxLHE8bCmyD5QtY3I2xEfy0qn3XzGcKa3Nxe5B3MaWqLFmveMlosXd1L P/jZ2qYIgydCOUetnVdUcLeqs2NFNznWe/wakXKfpLavUwmSY6Mgbwj1UwFDkmwlefLT hGcw== X-Gm-Message-State: AJaThX7oChdkgpuBSd1RCAX/Scwj7MhK7eOmfvm5O8sKs2UqN9Fo2crM U4f/WhYZQtLl4kG+4x9a53fohg== X-Google-Smtp-Source: AGs4zMZQQO8SHrE+SkQ9/GCe+IYREZEl96prkrZgCAAaAr8fDkmG3qyr+LgYYVq3FRCGC3vZiSzLPw== X-Received: by 10.25.156.129 with SMTP id f123mr488950lfe.238.1510247441503; Thu, 09 Nov 2017 09:10:41 -0800 (PST) Received: from otyshchenko.kyiv.epam.com (ll-53.209.223.85.sovam.net.ua. [85.223.209.53]) by smtp.gmail.com with ESMTPSA id x90sm1394299ljb.86.2017.11.09.09.10.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Nov 2017 09:10:40 -0800 (PST) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Thu, 9 Nov 2017 19:09:59 +0200 Message-Id: <1510247421-24094-10-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510247421-24094-1-git-send-email-olekstysh@gmail.com> References: <1510247421-24094-1-git-send-email-olekstysh@gmail.com> Cc: Oleksandr Tyshchenko , Stefano Stabellini , Julien Grall Subject: [Xen-devel] [RFC PATCH 09/31] xen/device-tree: Add dt_property_for_each_string macros X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Oleksandr Tyshchenko This is a port from Linux. Signed-off-by: Oleksandr Tyshchenko CC: Stefano Stabellini CC: Julien Grall --- xen/common/device_tree.c | 18 ++++++++++++++++++ xen/include/xen/device_tree.h | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 60b0095..08f8072 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -208,6 +208,24 @@ int dt_property_read_string(const struct dt_device_node *np, return 0; } +const char *dt_property_next_string(const struct dt_property *prop, + const char *cur) +{ + const void *curv = cur; + + if ( !prop ) + return NULL; + + if ( !cur ) + return prop->value; + + curv += strlen(cur) + 1; + if ( curv >= prop->value + prop->length ) + return NULL; + + return curv; +} + bool_t dt_device_is_compatible(const struct dt_device_node *device, const char *compat) { diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 738f1b6..9e0931c 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -420,6 +420,27 @@ int dt_property_read_string(const struct dt_device_node *np, const char *propname, const char **out_string); /** + * dt_property_for_each_string - Iterate over an array of strings within + * a property with a given name for a given node. + * + * Example: + * + * struct dt_property *prop; + * const char *s; + * + * dt_property_for_each_string(np, "propname", prop, s) + * printk("String value: %s\n", s); + */ +const char *dt_property_next_string(const struct dt_property *prop, + const char *cur); + +#define dt_property_for_each_string(np, propname, prop, s) \ + for (prop = dt_find_property(np, propname, NULL), \ + s = dt_property_next_string(prop, NULL); \ + s; \ + s = dt_property_next_string(prop, s)) + +/** * Checks if the given "compat" string matches one of the strings in * the device's "compatible" property */