Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * fwnode.h - Firmware device node object handle type definition.
0004  *
0005  * Copyright (C) 2015, Intel Corporation
0006  * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
0007  */
0008 
0009 #ifndef _LINUX_FWNODE_H_
0010 #define _LINUX_FWNODE_H_
0011 
0012 #include <linux/types.h>
0013 #include <linux/list.h>
0014 #include <linux/bits.h>
0015 #include <linux/err.h>
0016 
0017 struct fwnode_operations;
0018 struct device;
0019 
0020 /*
0021  * fwnode link flags
0022  *
0023  * LINKS_ADDED: The fwnode has already be parsed to add fwnode links.
0024  * NOT_DEVICE:  The fwnode will never be populated as a struct device.
0025  * INITIALIZED: The hardware corresponding to fwnode has been initialized.
0026  * NEEDS_CHILD_BOUND_ON_ADD: For this fwnode/device to probe successfully, its
0027  *               driver needs its child devices to be bound with
0028  *               their respective drivers as soon as they are
0029  *               added.
0030  * BEST_EFFORT: The fwnode/device needs to probe early and might be missing some
0031  *      suppliers. Only enforce ordering with suppliers that have
0032  *      drivers.
0033  */
0034 #define FWNODE_FLAG_LINKS_ADDED         BIT(0)
0035 #define FWNODE_FLAG_NOT_DEVICE          BIT(1)
0036 #define FWNODE_FLAG_INITIALIZED         BIT(2)
0037 #define FWNODE_FLAG_NEEDS_CHILD_BOUND_ON_ADD    BIT(3)
0038 #define FWNODE_FLAG_BEST_EFFORT         BIT(4)
0039 
0040 struct fwnode_handle {
0041     struct fwnode_handle *secondary;
0042     const struct fwnode_operations *ops;
0043     struct device *dev;
0044     struct list_head suppliers;
0045     struct list_head consumers;
0046     u8 flags;
0047 };
0048 
0049 struct fwnode_link {
0050     struct fwnode_handle *supplier;
0051     struct list_head s_hook;
0052     struct fwnode_handle *consumer;
0053     struct list_head c_hook;
0054 };
0055 
0056 /**
0057  * struct fwnode_endpoint - Fwnode graph endpoint
0058  * @port: Port number
0059  * @id: Endpoint id
0060  * @local_fwnode: reference to the related fwnode
0061  */
0062 struct fwnode_endpoint {
0063     unsigned int port;
0064     unsigned int id;
0065     const struct fwnode_handle *local_fwnode;
0066 };
0067 
0068 /*
0069  * ports and endpoints defined as software_nodes should all follow a common
0070  * naming scheme; use these macros to ensure commonality.
0071  */
0072 #define SWNODE_GRAPH_PORT_NAME_FMT      "port@%u"
0073 #define SWNODE_GRAPH_ENDPOINT_NAME_FMT      "endpoint@%u"
0074 
0075 #define NR_FWNODE_REFERENCE_ARGS    8
0076 
0077 /**
0078  * struct fwnode_reference_args - Fwnode reference with additional arguments
0079  * @fwnode:- A reference to the base fwnode
0080  * @nargs: Number of elements in @args array
0081  * @args: Integer arguments on the fwnode
0082  */
0083 struct fwnode_reference_args {
0084     struct fwnode_handle *fwnode;
0085     unsigned int nargs;
0086     u64 args[NR_FWNODE_REFERENCE_ARGS];
0087 };
0088 
0089 /**
0090  * struct fwnode_operations - Operations for fwnode interface
0091  * @get: Get a reference to an fwnode.
0092  * @put: Put a reference to an fwnode.
0093  * @device_is_available: Return true if the device is available.
0094  * @device_get_match_data: Return the device driver match data.
0095  * @property_present: Return true if a property is present.
0096  * @property_read_int_array: Read an array of integer properties. Return zero on
0097  *               success, a negative error code otherwise.
0098  * @property_read_string_array: Read an array of string properties. Return zero
0099  *              on success, a negative error code otherwise.
0100  * @get_name: Return the name of an fwnode.
0101  * @get_name_prefix: Get a prefix for a node (for printing purposes).
0102  * @get_parent: Return the parent of an fwnode.
0103  * @get_next_child_node: Return the next child node in an iteration.
0104  * @get_named_child_node: Return a child node with a given name.
0105  * @get_reference_args: Return a reference pointed to by a property, with args
0106  * @graph_get_next_endpoint: Return an endpoint node in an iteration.
0107  * @graph_get_remote_endpoint: Return the remote endpoint node of a local
0108  *                 endpoint node.
0109  * @graph_get_port_parent: Return the parent node of a port node.
0110  * @graph_parse_endpoint: Parse endpoint for port and endpoint id.
0111  * @add_links:  Create fwnode links to all the suppliers of the fwnode. Return
0112  *      zero on success, a negative error code otherwise.
0113  */
0114 struct fwnode_operations {
0115     struct fwnode_handle *(*get)(struct fwnode_handle *fwnode);
0116     void (*put)(struct fwnode_handle *fwnode);
0117     bool (*device_is_available)(const struct fwnode_handle *fwnode);
0118     const void *(*device_get_match_data)(const struct fwnode_handle *fwnode,
0119                          const struct device *dev);
0120     bool (*device_dma_supported)(const struct fwnode_handle *fwnode);
0121     enum dev_dma_attr
0122     (*device_get_dma_attr)(const struct fwnode_handle *fwnode);
0123     bool (*property_present)(const struct fwnode_handle *fwnode,
0124                  const char *propname);
0125     int (*property_read_int_array)(const struct fwnode_handle *fwnode,
0126                        const char *propname,
0127                        unsigned int elem_size, void *val,
0128                        size_t nval);
0129     int
0130     (*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
0131                       const char *propname, const char **val,
0132                       size_t nval);
0133     const char *(*get_name)(const struct fwnode_handle *fwnode);
0134     const char *(*get_name_prefix)(const struct fwnode_handle *fwnode);
0135     struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
0136     struct fwnode_handle *
0137     (*get_next_child_node)(const struct fwnode_handle *fwnode,
0138                    struct fwnode_handle *child);
0139     struct fwnode_handle *
0140     (*get_named_child_node)(const struct fwnode_handle *fwnode,
0141                 const char *name);
0142     int (*get_reference_args)(const struct fwnode_handle *fwnode,
0143                   const char *prop, const char *nargs_prop,
0144                   unsigned int nargs, unsigned int index,
0145                   struct fwnode_reference_args *args);
0146     struct fwnode_handle *
0147     (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode,
0148                    struct fwnode_handle *prev);
0149     struct fwnode_handle *
0150     (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode);
0151     struct fwnode_handle *
0152     (*graph_get_port_parent)(struct fwnode_handle *fwnode);
0153     int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode,
0154                     struct fwnode_endpoint *endpoint);
0155     void __iomem *(*iomap)(struct fwnode_handle *fwnode, int index);
0156     int (*irq_get)(const struct fwnode_handle *fwnode, unsigned int index);
0157     int (*add_links)(struct fwnode_handle *fwnode);
0158 };
0159 
0160 #define fwnode_has_op(fwnode, op)                   \
0161     (!IS_ERR_OR_NULL(fwnode) && (fwnode)->ops && (fwnode)->ops->op)
0162 
0163 #define fwnode_call_int_op(fwnode, op, ...)             \
0164     (fwnode_has_op(fwnode, op) ?                    \
0165      (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : (IS_ERR_OR_NULL(fwnode) ? -EINVAL : -ENXIO))
0166 
0167 #define fwnode_call_bool_op(fwnode, op, ...)        \
0168     (fwnode_has_op(fwnode, op) ?            \
0169      (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false)
0170 
0171 #define fwnode_call_ptr_op(fwnode, op, ...)     \
0172     (fwnode_has_op(fwnode, op) ?            \
0173      (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL)
0174 #define fwnode_call_void_op(fwnode, op, ...)                \
0175     do {                                \
0176         if (fwnode_has_op(fwnode, op))              \
0177             (fwnode)->ops->op(fwnode, ## __VA_ARGS__);  \
0178     } while (false)
0179 #define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev)
0180 
0181 static inline void fwnode_init(struct fwnode_handle *fwnode,
0182                    const struct fwnode_operations *ops)
0183 {
0184     fwnode->ops = ops;
0185     INIT_LIST_HEAD(&fwnode->consumers);
0186     INIT_LIST_HEAD(&fwnode->suppliers);
0187 }
0188 
0189 static inline void fwnode_dev_initialized(struct fwnode_handle *fwnode,
0190                       bool initialized)
0191 {
0192     if (IS_ERR_OR_NULL(fwnode))
0193         return;
0194 
0195     if (initialized)
0196         fwnode->flags |= FWNODE_FLAG_INITIALIZED;
0197     else
0198         fwnode->flags &= ~FWNODE_FLAG_INITIALIZED;
0199 }
0200 
0201 extern u32 fw_devlink_get_flags(void);
0202 extern bool fw_devlink_is_strict(void);
0203 int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup);
0204 void fwnode_links_purge(struct fwnode_handle *fwnode);
0205 void fw_devlink_purge_absent_suppliers(struct fwnode_handle *fwnode);
0206 
0207 #endif