~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/powerpc/platforms/pseries/of_helpers.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #include <linux/string.h>
  3 #include <linux/err.h>
  4 #include <linux/slab.h>
  5 #include <linux/of.h>
  6 #include <asm/prom.h>
  7 
  8 #include "of_helpers.h"
  9 
 10 /**
 11  * pseries_of_derive_parent - basically like dirname(1)
 12  * @path:  the full_name of a node to be added to the tree
 13  *
 14  * Returns the node which should be the parent of the node
 15  * described by path.  E.g., for path = "/foo/bar", returns
 16  * the node with full_name = "/foo".
 17  */
 18 struct device_node *pseries_of_derive_parent(const char *path)
 19 {
 20         struct device_node *parent;
 21         char *parent_path = "/";
 22         const char *tail;
 23 
 24         /* We do not want the trailing '/' character */
 25         tail = kbasename(path) - 1;
 26 
 27         /* reject if path is "/" */
 28         if (!strcmp(path, "/"))
 29                 return ERR_PTR(-EINVAL);
 30 
 31         if (tail > path) {
 32                 parent_path = kstrndup(path, tail - path, GFP_KERNEL);
 33                 if (!parent_path)
 34                         return ERR_PTR(-ENOMEM);
 35         }
 36         parent = of_find_node_by_path(parent_path);
 37         if (strcmp(parent_path, "/"))
 38                 kfree(parent_path);
 39         return parent ? parent : ERR_PTR(-EINVAL);
 40 }
 41 
 42 
 43 /* Helper Routines to convert between drc_index to cpu numbers */
 44 
 45 int of_read_drc_info_cell(struct property **prop, const __be32 **curval,
 46                         struct of_drc_info *data)
 47 {
 48         const char *p = (char *)(*curval);
 49         const __be32 *p2;
 50 
 51         if (!data)
 52                 return -EINVAL;
 53 
 54         /* Get drc-type:encode-string */
 55         data->drc_type = (char *)p;
 56         p = of_prop_next_string(*prop, p);
 57         if (!p)
 58                 return -EINVAL;
 59 
 60         /* Get drc-name-prefix:encode-string */
 61         data->drc_name_prefix = (char *)p;
 62         p = of_prop_next_string(*prop, p);
 63         if (!p)
 64                 return -EINVAL;
 65 
 66         /* Get drc-index-start:encode-int */
 67         p2 = (const __be32 *)p;
 68         data->drc_index_start = be32_to_cpu(*p2);
 69 
 70         /* Get drc-name-suffix-start:encode-int */
 71         p2 = of_prop_next_u32(*prop, p2, &data->drc_name_suffix_start);
 72         if (!p2)
 73                 return -EINVAL;
 74 
 75         /* Get number-sequential-elements:encode-int */
 76         p2 = of_prop_next_u32(*prop, p2, &data->num_sequential_elems);
 77         if (!p2)
 78                 return -EINVAL;
 79 
 80         /* Get sequential-increment:encode-int */
 81         p2 = of_prop_next_u32(*prop, p2, &data->sequential_inc);
 82         if (!p2)
 83                 return -EINVAL;
 84 
 85         /* Get drc-power-domain:encode-int */
 86         p2 = of_prop_next_u32(*prop, p2, &data->drc_power_domain);
 87         if (!p2)
 88                 return -EINVAL;
 89 
 90         /* Should now know end of current entry */
 91         (*curval) = (void *)(++p2);
 92         data->last_drc_index = data->drc_index_start +
 93                 ((data->num_sequential_elems - 1) * data->sequential_inc);
 94 
 95         return 0;
 96 }
 97 EXPORT_SYMBOL(of_read_drc_info_cell);
 98 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php