1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/string.h>
4 #include <linux/slab.h>
8 #include "of_helpers.h"
11 * pseries_of_derive_parent - basically like dirname(1)
12 * @path: the full_name of a node to be added to the tree
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".
18 struct device_node
*pseries_of_derive_parent(const char *path
)
20 struct device_node
*parent
;
21 char *parent_path
= "/";
24 /* We do not want the trailing '/' character */
25 tail
= kbasename(path
) - 1;
27 /* reject if path is "/" */
28 if (!strcmp(path
, "/"))
29 return ERR_PTR(-EINVAL
);
32 parent_path
= kstrndup(path
, tail
- path
, GFP_KERNEL
);
34 return ERR_PTR(-ENOMEM
);
36 parent
= of_find_node_by_path(parent_path
);
37 if (strcmp(parent_path
, "/"))
39 return parent
? parent
: ERR_PTR(-EINVAL
);
43 /* Helper Routines to convert between drc_index to cpu numbers */
45 int of_read_drc_info_cell(struct property
**prop
, const __be32
**curval
,
46 struct of_drc_info
*data
)
48 const char *p
= (char *)(*curval
);
54 /* Get drc-type:encode-string */
55 data
->drc_type
= (char *)p
;
56 p
= of_prop_next_string(*prop
, p
);
60 /* Get drc-name-prefix:encode-string */
61 data
->drc_name_prefix
= (char *)p
;
62 p
= of_prop_next_string(*prop
, p
);
66 /* Get drc-index-start:encode-int */
67 p2
= (const __be32
*)p
;
68 data
->drc_index_start
= be32_to_cpu(*p2
);
70 /* Get drc-name-suffix-start:encode-int */
71 p2
= of_prop_next_u32(*prop
, p2
, &data
->drc_name_suffix_start
);
75 /* Get number-sequential-elements:encode-int */
76 p2
= of_prop_next_u32(*prop
, p2
, &data
->num_sequential_elems
);
80 /* Get sequential-increment:encode-int */
81 p2
= of_prop_next_u32(*prop
, p2
, &data
->sequential_inc
);
85 /* Get drc-power-domain:encode-int */
86 p2
= of_prop_next_u32(*prop
, p2
, &data
->drc_power_domain
);
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
);
97 EXPORT_SYMBOL(of_read_drc_info_cell
);