linux/include/linux/property.h

/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * property.h - Unified device property interface.
 *
 * Copyright (C) 2014, Intel Corporation
 * Authors: Rafael J. Wysocki <[email protected]>
 *          Mika Westerberg <[email protected]>
 */

#ifndef _LINUX_PROPERTY_H_
#define _LINUX_PROPERTY_H_

#include <linux/args.h>
#include <linux/array_size.h>
#include <linux/bits.h>
#include <linux/cleanup.h>
#include <linux/fwnode.h>
#include <linux/stddef.h>
#include <linux/types.h>

struct device;

enum dev_prop_type {};

const struct fwnode_handle *__dev_fwnode_const(const struct device *dev);
struct fwnode_handle *__dev_fwnode(struct device *dev);
#define dev_fwnode(dev)

bool device_property_present(const struct device *dev, const char *propname);
int device_property_read_u8_array(const struct device *dev, const char *propname,
				  u8 *val, size_t nval);
int device_property_read_u16_array(const struct device *dev, const char *propname,
				   u16 *val, size_t nval);
int device_property_read_u32_array(const struct device *dev, const char *propname,
				   u32 *val, size_t nval);
int device_property_read_u64_array(const struct device *dev, const char *propname,
				   u64 *val, size_t nval);
int device_property_read_string_array(const struct device *dev, const char *propname,
				      const char **val, size_t nval);
int device_property_read_string(const struct device *dev, const char *propname,
				const char **val);
int device_property_match_string(const struct device *dev,
				 const char *propname, const char *string);

bool fwnode_property_present(const struct fwnode_handle *fwnode,
			     const char *propname);
int fwnode_property_read_u8_array(const struct fwnode_handle *fwnode,
				  const char *propname, u8 *val,
				  size_t nval);
int fwnode_property_read_u16_array(const struct fwnode_handle *fwnode,
				   const char *propname, u16 *val,
				   size_t nval);
int fwnode_property_read_u32_array(const struct fwnode_handle *fwnode,
				   const char *propname, u32 *val,
				   size_t nval);
int fwnode_property_read_u64_array(const struct fwnode_handle *fwnode,
				   const char *propname, u64 *val,
				   size_t nval);
int fwnode_property_read_string_array(const struct fwnode_handle *fwnode,
				      const char *propname, const char **val,
				      size_t nval);
int fwnode_property_read_string(const struct fwnode_handle *fwnode,
				const char *propname, const char **val);
int fwnode_property_match_string(const struct fwnode_handle *fwnode,
				 const char *propname, const char *string);

bool fwnode_device_is_available(const struct fwnode_handle *fwnode);

static inline bool fwnode_device_is_big_endian(const struct fwnode_handle *fwnode)
{}

static inline
bool fwnode_device_is_compatible(const struct fwnode_handle *fwnode, const char *compat)
{}

/**
 * device_is_big_endian - check if a device has BE registers
 * @dev: Pointer to the struct device
 *
 * Returns: true if the device has a "big-endian" property, or if the kernel
 * was compiled for BE *and* the device has a "native-endian" property.
 * Returns false otherwise.
 *
 * Callers would nominally use ioread32be/iowrite32be if
 * device_is_big_endian() == true, or readl/writel otherwise.
 */
static inline bool device_is_big_endian(const struct device *dev)
{}

/**
 * device_is_compatible - match 'compatible' property of the device with a given string
 * @dev: Pointer to the struct device
 * @compat: The string to match 'compatible' property with
 *
 * Returns: true if matches, otherwise false.
 */
static inline bool device_is_compatible(const struct device *dev, const char *compat)
{}

int fwnode_property_match_property_string(const struct fwnode_handle *fwnode,
					  const char *propname,
					  const char * const *array, size_t n);

static inline
int device_property_match_property_string(const struct device *dev,
					  const char *propname,
					  const char * const *array, size_t n)
{}

int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode,
				       const char *prop, const char *nargs_prop,
				       unsigned int nargs, unsigned int index,
				       struct fwnode_reference_args *args);

struct fwnode_handle *fwnode_find_reference(const struct fwnode_handle *fwnode,
					    const char *name,
					    unsigned int index);

const char *fwnode_get_name(const struct fwnode_handle *fwnode);
const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode);
bool fwnode_name_eq(const struct fwnode_handle *fwnode, const char *name);

struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode);
struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode);

#define fwnode_for_each_parent_node(fwnode, parent)

unsigned int fwnode_count_parents(const struct fwnode_handle *fwn);
struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwn,
					    unsigned int depth);
struct fwnode_handle *fwnode_get_next_child_node(
	const struct fwnode_handle *fwnode, struct fwnode_handle *child);
struct fwnode_handle *fwnode_get_next_available_child_node(
	const struct fwnode_handle *fwnode, struct fwnode_handle *child);

#define fwnode_for_each_child_node(fwnode, child)

#define fwnode_for_each_available_child_node(fwnode, child)

struct fwnode_handle *device_get_next_child_node(const struct device *dev,
						 struct fwnode_handle *child);

#define device_for_each_child_node(dev, child)

#define device_for_each_child_node_scoped(dev, child)

struct fwnode_handle *fwnode_get_named_child_node(const struct fwnode_handle *fwnode,
						  const char *childname);
struct fwnode_handle *device_get_named_child_node(const struct device *dev,
						  const char *childname);

struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode);

/**
 * fwnode_handle_put - Drop reference to a device node
 * @fwnode: Pointer to the device node to drop the reference to.
 *
 * This has to be used when terminating device_for_each_child_node() iteration
 * with break or return to prevent stale device node references from being left
 * behind.
 */
static inline void fwnode_handle_put(struct fwnode_handle *fwnode)
{}

DEFINE_FREE()

int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index);
int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name);

unsigned int device_get_child_node_count(const struct device *dev);

static inline bool device_property_read_bool(const struct device *dev,
					     const char *propname)
{}

static inline int device_property_read_u8(const struct device *dev,
					  const char *propname, u8 *val)
{}

static inline int device_property_read_u16(const struct device *dev,
					   const char *propname, u16 *val)
{}

static inline int device_property_read_u32(const struct device *dev,
					   const char *propname, u32 *val)
{}

static inline int device_property_read_u64(const struct device *dev,
					   const char *propname, u64 *val)
{}

static inline int device_property_count_u8(const struct device *dev, const char *propname)
{}

static inline int device_property_count_u16(const struct device *dev, const char *propname)
{}

static inline int device_property_count_u32(const struct device *dev, const char *propname)
{}

static inline int device_property_count_u64(const struct device *dev, const char *propname)
{}

static inline int device_property_string_array_count(const struct device *dev,
						     const char *propname)
{}

static inline bool fwnode_property_read_bool(const struct fwnode_handle *fwnode,
					     const char *propname)
{}

static inline int fwnode_property_read_u8(const struct fwnode_handle *fwnode,
					  const char *propname, u8 *val)
{}

static inline int fwnode_property_read_u16(const struct fwnode_handle *fwnode,
					   const char *propname, u16 *val)
{}

static inline int fwnode_property_read_u32(const struct fwnode_handle *fwnode,
					   const char *propname, u32 *val)
{}

static inline int fwnode_property_read_u64(const struct fwnode_handle *fwnode,
					   const char *propname, u64 *val)
{}

static inline int fwnode_property_count_u8(const struct fwnode_handle *fwnode,
					   const char *propname)
{}

static inline int fwnode_property_count_u16(const struct fwnode_handle *fwnode,
					    const char *propname)
{}

static inline int fwnode_property_count_u32(const struct fwnode_handle *fwnode,
					    const char *propname)
{}

static inline int fwnode_property_count_u64(const struct fwnode_handle *fwnode,
					    const char *propname)
{}

static inline int
fwnode_property_string_array_count(const struct fwnode_handle *fwnode,
				   const char *propname)
{}

struct software_node;

/**
 * struct software_node_ref_args - Reference property with additional arguments
 * @node: Reference to a software node
 * @nargs: Number of elements in @args array
 * @args: Integer arguments
 */
struct software_node_ref_args {};

#define SOFTWARE_NODE_REFERENCE(_ref_, ...)

/**
 * struct property_entry - "Built-in" device property representation.
 * @name: Name of the property.
 * @length: Length of data making up the value.
 * @is_inline: True when the property value is stored inline.
 * @type: Type of the data in unions.
 * @pointer: Pointer to the property when it is not stored inline.
 * @value: Value of the property when it is stored inline.
 */
struct property_entry {};

/*
 * Note: the below initializers for the anonymous union are carefully
 * crafted to avoid gcc-4.4.4's problems with initialization of anon unions
 * and structs.
 */
#define __PROPERTY_ENTRY_ARRAY_LEN(_name_, _elem_, _Type_, _val_, _len_)

#define PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, _len_)
#define PROPERTY_ENTRY_U16_ARRAY_LEN(_name_, _val_, _len_)
#define PROPERTY_ENTRY_U32_ARRAY_LEN(_name_, _val_, _len_)
#define PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, _len_)
#define PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, _len_)

#define PROPERTY_ENTRY_REF_ARRAY_LEN(_name_, _val_, _len_)

#define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_)
#define PROPERTY_ENTRY_U16_ARRAY(_name_, _val_)
#define PROPERTY_ENTRY_U32_ARRAY(_name_, _val_)
#define PROPERTY_ENTRY_U64_ARRAY(_name_, _val_)
#define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_)
#define PROPERTY_ENTRY_REF_ARRAY(_name_, _val_)

#define __PROPERTY_ENTRY_ELEMENT(_name_, _elem_, _Type_, _val_)

#define PROPERTY_ENTRY_U8(_name_, _val_)
#define PROPERTY_ENTRY_U16(_name_, _val_)
#define PROPERTY_ENTRY_U32(_name_, _val_)
#define PROPERTY_ENTRY_U64(_name_, _val_)
#define PROPERTY_ENTRY_STRING(_name_, _val_)

#define PROPERTY_ENTRY_REF(_name_, _ref_, ...)

#define PROPERTY_ENTRY_BOOL(_name_)

struct property_entry *
property_entries_dup(const struct property_entry *properties);
void property_entries_free(const struct property_entry *properties);

bool device_dma_supported(const struct device *dev);
enum dev_dma_attr device_get_dma_attr(const struct device *dev);

const void *device_get_match_data(const struct device *dev);

int device_get_phy_mode(struct device *dev);
int fwnode_get_phy_mode(const struct fwnode_handle *fwnode);

void __iomem *fwnode_iomap(struct fwnode_handle *fwnode, int index);

struct fwnode_handle *fwnode_graph_get_next_endpoint(
	const struct fwnode_handle *fwnode, struct fwnode_handle *prev);
struct fwnode_handle *
fwnode_graph_get_port_parent(const struct fwnode_handle *fwnode);
struct fwnode_handle *fwnode_graph_get_remote_port_parent(
	const struct fwnode_handle *fwnode);
struct fwnode_handle *fwnode_graph_get_remote_port(
	const struct fwnode_handle *fwnode);
struct fwnode_handle *fwnode_graph_get_remote_endpoint(
	const struct fwnode_handle *fwnode);

static inline bool fwnode_graph_is_endpoint(const struct fwnode_handle *fwnode)
{}

/*
 * Fwnode lookup flags
 *
 * @FWNODE_GRAPH_ENDPOINT_NEXT: In the case of no exact match, look for the
 *				closest endpoint ID greater than the specified
 *				one.
 * @FWNODE_GRAPH_DEVICE_DISABLED: That the device to which the remote
 *				  endpoint of the given endpoint belongs to,
 *				  may be disabled, or that the endpoint is not
 *				  connected.
 */
#define FWNODE_GRAPH_ENDPOINT_NEXT
#define FWNODE_GRAPH_DEVICE_DISABLED

struct fwnode_handle *
fwnode_graph_get_endpoint_by_id(const struct fwnode_handle *fwnode,
				u32 port, u32 endpoint, unsigned long flags);
unsigned int fwnode_graph_get_endpoint_count(const struct fwnode_handle *fwnode,
					     unsigned long flags);

#define fwnode_graph_for_each_endpoint(fwnode, child)

int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode,
				struct fwnode_endpoint *endpoint);

devcon_match_fn_t;

void *fwnode_connection_find_match(const struct fwnode_handle *fwnode,
				   const char *con_id, void *data,
				   devcon_match_fn_t match);

static inline void *device_connection_find_match(const struct device *dev,
						 const char *con_id, void *data,
						 devcon_match_fn_t match)
{}

int fwnode_connection_find_matches(const struct fwnode_handle *fwnode,
				   const char *con_id, void *data,
				   devcon_match_fn_t match,
				   void **matches, unsigned int matches_len);

/* -------------------------------------------------------------------------- */
/* Software fwnode support - when HW description is incomplete or missing */

/**
 * struct software_node - Software node description
 * @name: Name of the software node
 * @parent: Parent of the software node
 * @properties: Array of device properties
 */
struct software_node {};

#define SOFTWARE_NODE(_name_, _properties_, _parent_)

bool is_software_node(const struct fwnode_handle *fwnode);
const struct software_node *
to_software_node(const struct fwnode_handle *fwnode);
struct fwnode_handle *software_node_fwnode(const struct software_node *node);

const struct software_node *
software_node_find_by_name(const struct software_node *parent,
			   const char *name);

int software_node_register_node_group(const struct software_node **node_group);
void software_node_unregister_node_group(const struct software_node **node_group);

int software_node_register(const struct software_node *node);
void software_node_unregister(const struct software_node *node);

struct fwnode_handle *
fwnode_create_software_node(const struct property_entry *properties,
			    const struct fwnode_handle *parent);
void fwnode_remove_software_node(struct fwnode_handle *fwnode);

int device_add_software_node(struct device *dev, const struct software_node *node);
void device_remove_software_node(struct device *dev);

int device_create_managed_software_node(struct device *dev,
					const struct property_entry *properties,
					const struct software_node *parent);

#endif /* _LINUX_PROPERTY_H_ */