[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[XEN RFC PATCH 19/40] xen: fdt: Introduce a helper to check fdt node type


  • To: <wei.chen@xxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>, <sstabellini@xxxxxxxxxx>, <julien@xxxxxxx>, <jbeulich@xxxxxxxx>
  • From: Wei Chen <wei.chen@xxxxxxx>
  • Date: Wed, 11 Aug 2021 18:24:02 +0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=odN0lHZAsbsVRMXgR2b8ZeF2f7UGOUcwvUmC6yeEvE4=; b=is5MiMPxrb9RZuFR7mTGsa/PVLhRuxTwc8gdJ45Ss+7PfQQj7RvMOGDFEyw/8Xc0ckVWelMu48AbJKmfz7j2vSoxNYurz7EZZ08vfRd75sZsSnByXPgUXabFVud7csH3qEbAkBfacLRrTbDVqKDEHrtnMGn+euZOYsBKzNLde98OumMuuFZXJfhK5KhETRJLtXsL5BmQf9eBr5kleM2qdjHX2ItzDmYA3hauXOBeEkUlu5fuUtF9ObWzCKz6RfTWdB5dWDo1e+HPS1EU/NC7Nj3pYO107I4uLYJkQ7JuQUV8GyDALxNH+r0T1RF33mG+snbsPrkkT+vqE1n7RKRVUQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Daizj4Q/2uR2wt2v6T5yYeW8wZNh53EQj9oHSwk5dEDu+9uL2E9XJzDCopF7lbYcaK8WyFUExF0WjNFQrY0nw/3GdmKCbts+pTu6l++VmvjlmLBl7GlPWaDStdtZ/LeHmZ7qp3Gr13I35SMMeYN+RnUbs0Iu4pYKoDURVA5jl85mBl5aM2NJQWr31wFcmlQU+oFAHOSIriPtTEGxYDd4+k3DmHmCQ0fFaDaBuTKYfE6Sr6Kfw6U68FtD5Zbd6gtYQK4bJZo/I/TAyFZtkNeXHLpIgZPU5HgQkue/k6KLQn48B1UJfgsfnSNGS6IIZ69sEzDE6N7pijgJ34jlPGrEew==
  • Cc: <Bertrand.Marquis@xxxxxxx>
  • Delivery-date: Wed, 11 Aug 2021 10:31:37 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true

In later patches, we will parse CPU and memory NUMA information
from device tree. FDT is using device type property to indicate
CPU nodes and memory nodes. So we introduce fdt_node_check_type
in this patch to avoid redundant code in subsequent patches.

Signed-off-by: Wei Chen <wei.chen@xxxxxxx>
---
 xen/common/libfdt/fdt_ro.c      | 15 +++++++++++++++
 xen/include/xen/libfdt/libfdt.h | 25 +++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/xen/common/libfdt/fdt_ro.c b/xen/common/libfdt/fdt_ro.c
index 36f9b480d1..ae7794d870 100644
--- a/xen/common/libfdt/fdt_ro.c
+++ b/xen/common/libfdt/fdt_ro.c
@@ -545,6 +545,21 @@ int fdt_node_check_compatible(const void *fdt, int 
nodeoffset,
                return 1;
 }
 
+int fdt_node_check_type(const void *fdt, int nodeoffset,
+                             const char *type)
+{
+       const void *prop;
+       int len;
+
+       prop = fdt_getprop(fdt, nodeoffset, "device_type", &len);
+       if (!prop)
+               return len;
+       if (fdt_stringlist_contains(prop, len, type))
+               return 0;
+       else
+               return 1;
+}
+
 int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
                                  const char *compatible)
 {
diff --git a/xen/include/xen/libfdt/libfdt.h b/xen/include/xen/libfdt/libfdt.h
index 7c75688a39..7e4930dbcd 100644
--- a/xen/include/xen/libfdt/libfdt.h
+++ b/xen/include/xen/libfdt/libfdt.h
@@ -799,6 +799,31 @@ int fdt_node_offset_by_phandle(const void *fdt, uint32_t 
phandle);
 int fdt_node_check_compatible(const void *fdt, int nodeoffset,
                              const char *compatible);
 
+/**
+ * fdt_node_check_type: check a node's device_type property
+ * @fdt: pointer to the device tree blob
+ * @nodeoffset: offset of a tree node
+ * @type: string to match against
+ *
+ *
+ * fdt_node_check_type() returns 0 if the given node contains a 'device_type'
+ * property with the given string as one of its elements, it returns non-zero
+ * otherwise, or on error.
+ *
+ * returns:
+ *     0, if the node has a 'device_type' property listing the given string
+ *     1, if the node has a 'device_type' property, but it does not list
+ *             the given string
+ *     -FDT_ERR_NOTFOUND, if the given node has no 'device_type' property
+ *     -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
+ *     -FDT_ERR_BADMAGIC,
+ *     -FDT_ERR_BADVERSION,
+ *     -FDT_ERR_BADSTATE,
+ *     -FDT_ERR_BADSTRUCTURE, standard meanings
+ */
+int fdt_node_check_type(const void *fdt, int nodeoffset,
+                             const char *type);
+
 /**
  * fdt_node_offset_by_compatible - find nodes with a given 'compatible' value
  * @fdt: pointer to the device tree blob
-- 
2.25.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.