From nobody Thu Dec 18 23:23:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1607621767; cv=none; d=zohomail.com; s=zohoarc; b=KPJEc4W+rL59nQf3uSpSsgfHP99WNrMmqEp8QcHWxRX0yU08ojE1NQgqEMZIxM5EeTix2aIRVxJxUEFmPbnUR7htoim2/KY8hWcLCa8MzC/MDgrkd7FzH52q78CqYkAWtEKI7kV1kZRW3v5D4PrdDPe5HK9o0YNBkq/vpDJ91Ok= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607621767; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=WWmaK2sjINpvgguI8tqZdAYO6CSy0kGdMpQTkLpVa+M=; b=eFNL+GENgmgZ5C+qa8FhWnW8zYlgbqqdrbk3IgTCOLRxMODrBtE8/80qbwbwnVUOyrbPp0m7g8CVoV1a5RQU++O4xkpgoaGONts3U/IZBCbLuhW11gSzGU7j0o4+w+DJB4G1QYFPg4+jgvwWuYOHL4jmOnWzu93nYtW3Tuy0Ptk= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTP id 1607621767679541.2110668570153; Thu, 10 Dec 2020 09:36:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.49591.87715 (Exim 4.92) (envelope-from ) id 1knPIK-0006Ru-TV; Thu, 10 Dec 2020 16:59:56 +0000 Received: by outflank-mailman (output) from mailman id 49591.87715; Thu, 10 Dec 2020 16:59:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1knPIK-0006Rn-QP; Thu, 10 Dec 2020 16:59:56 +0000 Received: by outflank-mailman (input) for mailman id 49591; Thu, 10 Dec 2020 16:59:55 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1knPIJ-0006R7-Bb for xen-devel@lists.xenproject.org; Thu, 10 Dec 2020 16:59:55 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id e03e9275-5d13-4ebf-ba32-7557c250fe9d; Thu, 10 Dec 2020 16:59:52 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6286E30E; Thu, 10 Dec 2020 08:59:51 -0800 (PST) Received: from scm-wfh-server-rahsin01.stack04.eu02.mi.arm.com (unknown [10.58.246.76]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8D4173F66B; Thu, 10 Dec 2020 08:59:50 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e03e9275-5d13-4ebf-ba32-7557c250fe9d From: Rahul Singh To: xen-devel@lists.xenproject.org Cc: bertrand.marquis@arm.com, rahul.singh@arm.com, Stefano Stabellini , Julien Grall Subject: [PATCH v3 5/8] xen/device-tree: Add dt_property_match_string helper Date: Thu, 10 Dec 2020 16:57:03 +0000 Message-Id: <2cf4c10d0ce81290af96e29ee364df87c06ef849.1607617848.git.rahul.singh@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Import the Linux helper of_property_match_string. This function searches a string list property and returns the index of a specific string value. Signed-off-by: Rahul Singh Reviewed-by: Bertrand Marquis Reviewed-by: Stefano Stabellini --- Changes in v3: - This patch is introduce in this verison. --- xen/common/device_tree.c | 27 +++++++++++++++++++++++++++ xen/include/xen/device_tree.h | 12 ++++++++++++ 2 files changed, 39 insertions(+) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index e107c6f89f..18825e333e 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -208,6 +208,33 @@ int dt_property_read_string(const struct dt_device_nod= e *np, return 0; } =20 +int dt_property_match_string(const struct dt_device_node *np, + const char *propname, const char *string) +{ + const struct dt_property *dtprop =3D dt_find_property(np, propname, NU= LL); + size_t l; + int i; + const char *p, *end; + + if ( !dtprop ) + return -EINVAL; + if ( !dtprop->value ) + return -ENODATA; + + p =3D dtprop->value; + end =3D p + dtprop->length; + + for ( i =3D 0; p < end; i++, p +=3D l ) + { + l =3D strnlen(p, end - p) + 1; + if ( p + l > end ) + return -EILSEQ; + if ( strcmp(string, p) =3D=3D 0 ) + return i; /* Found it; return index */ + } + return -ENODATA; +} + 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 f2ad22b79c..b02696be94 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -400,6 +400,18 @@ static inline bool_t dt_property_read_bool(const struc= t dt_device_node *np, int dt_property_read_string(const struct dt_device_node *np, const char *propname, const char **out_string); =20 +/** + * dt_property_match_string() - Find string in a list and return index + * @np: pointer to node containing string list property + * @propname: string list property name + * @string: pointer to string to search for in string list + * + * This function searches a string list property and returns the index + * of a specific string value. + */ +int dt_property_match_string(const struct dt_device_node *np, + const char *propname, const char *string); + /** * Checks if the given "compat" string matches one of the strings in * the device's "compatible" property --=20 2.17.1