1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * fwnode.h - Firmware device node object handle type definition.
5 * Copyright (C) 2015, Intel Corporation
6 * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
9 #ifndef _LINUX_FWNODE_H_
10 #define _LINUX_FWNODE_H_
12 #include <linux/types.h>
13 #include <linux/list.h>
15 struct fwnode_operations;
21 * LINKS_ADDED: The fwnode has already be parsed to add fwnode links.
23 #define FWNODE_FLAG_LINKS_ADDED BIT(0)
25 struct fwnode_handle {
26 struct fwnode_handle *secondary;
27 const struct fwnode_operations *ops;
29 struct list_head suppliers;
30 struct list_head consumers;
35 struct fwnode_handle *supplier;
36 struct list_head s_hook;
37 struct fwnode_handle *consumer;
38 struct list_head c_hook;
42 * struct fwnode_endpoint - Fwnode graph endpoint
45 * @local_fwnode: reference to the related fwnode
47 struct fwnode_endpoint {
50 const struct fwnode_handle *local_fwnode;
54 * ports and endpoints defined as software_nodes should all follow a common
55 * naming scheme; use these macros to ensure commonality.
57 #define SWNODE_GRAPH_PORT_NAME_FMT "port@%u"
58 #define SWNODE_GRAPH_ENDPOINT_NAME_FMT "endpoint@%u"
60 #define NR_FWNODE_REFERENCE_ARGS 8
63 * struct fwnode_reference_args - Fwnode reference with additional arguments
64 * @fwnode:- A reference to the base fwnode
65 * @nargs: Number of elements in @args array
66 * @args: Integer arguments on the fwnode
68 struct fwnode_reference_args {
69 struct fwnode_handle *fwnode;
71 u64 args[NR_FWNODE_REFERENCE_ARGS];
75 * struct fwnode_operations - Operations for fwnode interface
76 * @get: Get a reference to an fwnode.
77 * @put: Put a reference to an fwnode.
78 * @device_is_available: Return true if the device is available.
79 * @device_get_match_data: Return the device driver match data.
80 * @property_present: Return true if a property is present.
81 * @property_read_int_array: Read an array of integer properties. Return zero on
82 * success, a negative error code otherwise.
83 * @property_read_string_array: Read an array of string properties. Return zero
84 * on success, a negative error code otherwise.
85 * @get_name: Return the name of an fwnode.
86 * @get_name_prefix: Get a prefix for a node (for printing purposes).
87 * @get_parent: Return the parent of an fwnode.
88 * @get_next_child_node: Return the next child node in an iteration.
89 * @get_named_child_node: Return a child node with a given name.
90 * @get_reference_args: Return a reference pointed to by a property, with args
91 * @graph_get_next_endpoint: Return an endpoint node in an iteration.
92 * @graph_get_remote_endpoint: Return the remote endpoint node of a local
94 * @graph_get_port_parent: Return the parent node of a port node.
95 * @graph_parse_endpoint: Parse endpoint for port and endpoint id.
96 * @add_links: Create fwnode links to all the suppliers of the fwnode. Return
97 * zero on success, a negative error code otherwise.
99 struct fwnode_operations {
100 struct fwnode_handle *(*get)(struct fwnode_handle *fwnode);
101 void (*put)(struct fwnode_handle *fwnode);
102 bool (*device_is_available)(const struct fwnode_handle *fwnode);
103 const void *(*device_get_match_data)(const struct fwnode_handle *fwnode,
104 const struct device *dev);
105 bool (*property_present)(const struct fwnode_handle *fwnode,
106 const char *propname);
107 int (*property_read_int_array)(const struct fwnode_handle *fwnode,
108 const char *propname,
109 unsigned int elem_size, void *val,
112 (*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
113 const char *propname, const char **val,
115 const char *(*get_name)(const struct fwnode_handle *fwnode);
116 const char *(*get_name_prefix)(const struct fwnode_handle *fwnode);
117 struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
118 struct fwnode_handle *
119 (*get_next_child_node)(const struct fwnode_handle *fwnode,
120 struct fwnode_handle *child);
121 struct fwnode_handle *
122 (*get_named_child_node)(const struct fwnode_handle *fwnode,
124 int (*get_reference_args)(const struct fwnode_handle *fwnode,
125 const char *prop, const char *nargs_prop,
126 unsigned int nargs, unsigned int index,
127 struct fwnode_reference_args *args);
128 struct fwnode_handle *
129 (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode,
130 struct fwnode_handle *prev);
131 struct fwnode_handle *
132 (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode);
133 struct fwnode_handle *
134 (*graph_get_port_parent)(struct fwnode_handle *fwnode);
135 int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode,
136 struct fwnode_endpoint *endpoint);
137 int (*add_links)(struct fwnode_handle *fwnode);
140 #define fwnode_has_op(fwnode, op) \
141 ((fwnode) && (fwnode)->ops && (fwnode)->ops->op)
142 #define fwnode_call_int_op(fwnode, op, ...) \
143 (fwnode ? (fwnode_has_op(fwnode, op) ? \
144 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \
147 #define fwnode_call_bool_op(fwnode, op, ...) \
148 (fwnode_has_op(fwnode, op) ? \
149 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false)
151 #define fwnode_call_ptr_op(fwnode, op, ...) \
152 (fwnode_has_op(fwnode, op) ? \
153 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL)
154 #define fwnode_call_void_op(fwnode, op, ...) \
156 if (fwnode_has_op(fwnode, op)) \
157 (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \
159 #define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev)
161 static inline void fwnode_init(struct fwnode_handle *fwnode,
162 const struct fwnode_operations *ops)
165 INIT_LIST_HEAD(&fwnode->consumers);
166 INIT_LIST_HEAD(&fwnode->suppliers);
169 extern u32 fw_devlink_get_flags(void);
170 int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup);
171 void fwnode_links_purge(struct fwnode_handle *fwnode);