Merge tag 'pci-v6.16-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci
[linux-block.git] / include / linux / fwnode.h
CommitLineData
d2912cb1 1/* SPDX-License-Identifier: GPL-2.0-only */
ce793486
RW
2/*
3 * fwnode.h - Firmware device node object handle type definition.
4 *
1ae5e4c0
AS
5 * This header file provides low-level data types and definitions for firmware
6 * and device property providers. The respective API header files supplied by
7 * them should contain all of the requisite data types and definitions for end
8 * users, so including it directly should not be necessary.
9 *
ce793486
RW
10 * Copyright (C) 2015, Intel Corporation
11 * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
ce793486
RW
12 */
13
14#ifndef _LINUX_FWNODE_H_
15#define _LINUX_FWNODE_H_
16
f0ada6da 17#include <linux/bits.h>
74c782cf 18#include <linux/err.h>
4dc3d612
AS
19#include <linux/list.h>
20#include <linux/types.h>
3708184a 21
420b104d
AS
22enum dev_dma_attr {
23 DEV_DMA_NOT_SUPPORTED,
24 DEV_DMA_NON_COHERENT,
25 DEV_DMA_COHERENT,
26};
27
3708184a 28struct fwnode_operations;
b283f157 29struct device;
3708184a 30
c2c724c8 31/*
6a6dfdf8 32 * fwnode flags
c2c724c8 33 *
74c782cf
SK
34 * LINKS_ADDED: The fwnode has already be parsed to add fwnode links.
35 * NOT_DEVICE: The fwnode will never be populated as a struct device.
36 * INITIALIZED: The hardware corresponding to fwnode has been initialized.
5501765a
SK
37 * NEEDS_CHILD_BOUND_ON_ADD: For this fwnode/device to probe successfully, its
38 * driver needs its child devices to be bound with
39 * their respective drivers as soon as they are
40 * added.
8f486cab
SK
41 * BEST_EFFORT: The fwnode/device needs to probe early and might be missing some
42 * suppliers. Only enforce ordering with suppliers that have
43 * drivers.
c2c724c8 44 */
5501765a
SK
45#define FWNODE_FLAG_LINKS_ADDED BIT(0)
46#define FWNODE_FLAG_NOT_DEVICE BIT(1)
47#define FWNODE_FLAG_INITIALIZED BIT(2)
48#define FWNODE_FLAG_NEEDS_CHILD_BOUND_ON_ADD BIT(3)
8f486cab 49#define FWNODE_FLAG_BEST_EFFORT BIT(4)
6a6dfdf8 50#define FWNODE_FLAG_VISITED BIT(5)
c2c724c8 51
ce793486 52struct fwnode_handle {
97badf87 53 struct fwnode_handle *secondary;
3708184a 54 const struct fwnode_operations *ops;
7523d330
AS
55
56 /* The below is used solely by device links, don't use otherwise */
372a67c0 57 struct device *dev;
7b337cb3
SK
58 struct list_head suppliers;
59 struct list_head consumers;
c2c724c8 60 u8 flags;
7b337cb3
SK
61};
62
6a6dfdf8
SK
63/*
64 * fwnode link flags
65 *
66 * CYCLE: The fwnode link is part of a cycle. Don't defer probe.
b7e1241d 67 * IGNORE: Completely ignore this link, even during cycle detection.
6a6dfdf8
SK
68 */
69#define FWLINK_FLAG_CYCLE BIT(0)
b7e1241d 70#define FWLINK_FLAG_IGNORE BIT(1)
6a6dfdf8 71
7b337cb3
SK
72struct fwnode_link {
73 struct fwnode_handle *supplier;
74 struct list_head s_hook;
75 struct fwnode_handle *consumer;
76 struct list_head c_hook;
6a6dfdf8 77 u8 flags;
ce793486
RW
78};
79
2bd5452d
SA
80/**
81 * struct fwnode_endpoint - Fwnode graph endpoint
82 * @port: Port number
83 * @id: Endpoint id
84 * @local_fwnode: reference to the related fwnode
85 */
86struct fwnode_endpoint {
87 unsigned int port;
88 unsigned int id;
89 const struct fwnode_handle *local_fwnode;
90};
91
529b56a8
DS
92/*
93 * ports and endpoints defined as software_nodes should all follow a common
94 * naming scheme; use these macros to ensure commonality.
95 */
96#define SWNODE_GRAPH_PORT_NAME_FMT "port@%u"
97#define SWNODE_GRAPH_ENDPOINT_NAME_FMT "endpoint@%u"
98
eb50844d 99#define NR_FWNODE_REFERENCE_ARGS 16
3e3119d3
SA
100
101/**
102 * struct fwnode_reference_args - Fwnode reference with additional arguments
103 * @fwnode:- A reference to the base fwnode
104 * @nargs: Number of elements in @args array
105 * @args: Integer arguments on the fwnode
106 */
107struct fwnode_reference_args {
108 struct fwnode_handle *fwnode;
109 unsigned int nargs;
977d5ad3 110 u64 args[NR_FWNODE_REFERENCE_ARGS];
3e3119d3
SA
111};
112
3708184a
SA
113/**
114 * struct fwnode_operations - Operations for fwnode interface
115 * @get: Get a reference to an fwnode.
116 * @put: Put a reference to an fwnode.
8ed61d36 117 * @device_is_available: Return true if the device is available.
b283f157 118 * @device_get_match_data: Return the device driver match data.
3708184a 119 * @property_present: Return true if a property is present.
bb391410 120 * @property_read_bool: Return a boolean property value.
8ed61d36
HK
121 * @property_read_int_array: Read an array of integer properties. Return zero on
122 * success, a negative error code otherwise.
3708184a
SA
123 * @property_read_string_array: Read an array of string properties. Return zero
124 * on success, a negative error code otherwise.
bc0500c1 125 * @get_name: Return the name of an fwnode.
e7e242bc 126 * @get_name_prefix: Get a prefix for a node (for printing purposes).
3708184a
SA
127 * @get_parent: Return the parent of an fwnode.
128 * @get_next_child_node: Return the next child node in an iteration.
129 * @get_named_child_node: Return a child node with a given name.
3e3119d3 130 * @get_reference_args: Return a reference pointed to by a property, with args
3b27d00e
SA
131 * @graph_get_next_endpoint: Return an endpoint node in an iteration.
132 * @graph_get_remote_endpoint: Return the remote endpoint node of a local
133 * endpoint node.
134 * @graph_get_port_parent: Return the parent node of a port node.
135 * @graph_parse_endpoint: Parse endpoint for port and endpoint id.
04f63c21
SK
136 * @add_links: Create fwnode links to all the suppliers of the fwnode. Return
137 * zero on success, a negative error code otherwise.
3708184a
SA
138 */
139struct fwnode_operations {
cf89a31c 140 struct fwnode_handle *(*get)(struct fwnode_handle *fwnode);
3708184a 141 void (*put)(struct fwnode_handle *fwnode);
37ba983c 142 bool (*device_is_available)(const struct fwnode_handle *fwnode);
67dcc26d
AS
143 const void *(*device_get_match_data)(const struct fwnode_handle *fwnode,
144 const struct device *dev);
8c756a0a
SA
145 bool (*device_dma_supported)(const struct fwnode_handle *fwnode);
146 enum dev_dma_attr
147 (*device_get_dma_attr)(const struct fwnode_handle *fwnode);
37ba983c 148 bool (*property_present)(const struct fwnode_handle *fwnode,
3708184a 149 const char *propname);
bb391410
RHA
150 bool (*property_read_bool)(const struct fwnode_handle *fwnode,
151 const char *propname);
37ba983c 152 int (*property_read_int_array)(const struct fwnode_handle *fwnode,
3708184a
SA
153 const char *propname,
154 unsigned int elem_size, void *val,
155 size_t nval);
37ba983c
SA
156 int
157 (*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
158 const char *propname, const char **val,
159 size_t nval);
bc0500c1 160 const char *(*get_name)(const struct fwnode_handle *fwnode);
e7e242bc 161 const char *(*get_name_prefix)(const struct fwnode_handle *fwnode);
37ba983c 162 struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
3708184a 163 struct fwnode_handle *
37ba983c 164 (*get_next_child_node)(const struct fwnode_handle *fwnode,
3708184a
SA
165 struct fwnode_handle *child);
166 struct fwnode_handle *
37ba983c
SA
167 (*get_named_child_node)(const struct fwnode_handle *fwnode,
168 const char *name);
3e3119d3
SA
169 int (*get_reference_args)(const struct fwnode_handle *fwnode,
170 const char *prop, const char *nargs_prop,
171 unsigned int nargs, unsigned int index,
172 struct fwnode_reference_args *args);
3b27d00e 173 struct fwnode_handle *
37ba983c 174 (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode,
3b27d00e
SA
175 struct fwnode_handle *prev);
176 struct fwnode_handle *
37ba983c 177 (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode);
3b27d00e
SA
178 struct fwnode_handle *
179 (*graph_get_port_parent)(struct fwnode_handle *fwnode);
37ba983c 180 int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode,
3b27d00e 181 struct fwnode_endpoint *endpoint);
68b979d0 182 void __iomem *(*iomap)(struct fwnode_handle *fwnode, int index);
99c63707 183 int (*irq_get)(const struct fwnode_handle *fwnode, unsigned int index);
2d09e6eb 184 int (*add_links)(struct fwnode_handle *fwnode);
3708184a
SA
185};
186
002752af
AS
187#define fwnode_has_op(fwnode, op) \
188 (!IS_ERR_OR_NULL(fwnode) && (fwnode)->ops && (fwnode)->ops->op)
189
3708184a 190#define fwnode_call_int_op(fwnode, op, ...) \
002752af
AS
191 (fwnode_has_op(fwnode, op) ? \
192 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : (IS_ERR_OR_NULL(fwnode) ? -EINVAL : -ENXIO))
149f3b87
AS
193
194#define fwnode_call_bool_op(fwnode, op, ...) \
195 (fwnode_has_op(fwnode, op) ? \
196 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false)
197
3708184a
SA
198#define fwnode_call_ptr_op(fwnode, op, ...) \
199 (fwnode_has_op(fwnode, op) ? \
200 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL)
201#define fwnode_call_void_op(fwnode, op, ...) \
202 do { \
203 if (fwnode_has_op(fwnode, op)) \
204 (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \
205 } while (false)
206
01bb86b3
SK
207static inline void fwnode_init(struct fwnode_handle *fwnode,
208 const struct fwnode_operations *ops)
209{
210 fwnode->ops = ops;
7b337cb3
SK
211 INIT_LIST_HEAD(&fwnode->consumers);
212 INIT_LIST_HEAD(&fwnode->suppliers);
01bb86b3
SK
213}
214
74c782cf
SK
215static inline void fwnode_dev_initialized(struct fwnode_handle *fwnode,
216 bool initialized)
217{
218 if (IS_ERR_OR_NULL(fwnode))
219 return;
220
221 if (initialized)
222 fwnode->flags |= FWNODE_FLAG_INITIALIZED;
223 else
224 fwnode->flags &= ~FWNODE_FLAG_INITIALIZED;
225}
226
75cde56a
SK
227int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup,
228 u8 flags);
7b337cb3 229void fwnode_links_purge(struct fwnode_handle *fwnode);
28ec344b 230void fw_devlink_purge_absent_suppliers(struct fwnode_handle *fwnode);
bbf6cfba 231bool fw_devlink_is_strict(void);
8375e74f 232
ce793486 233#endif