Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Functions | Variables
base.c File Reference
#include <linux/ctype.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/spinlock.h>
#include <linux/slab.h>
#include <linux/proc_fs.h>

Go to the source code of this file.

Data Structures

struct  alias_prop
 

Functions

 DEFINE_RWLOCK (devtree_lock)
 
int of_n_addr_cells (struct device_node *np)
 
 EXPORT_SYMBOL (of_n_addr_cells)
 
int of_n_size_cells (struct device_node *np)
 
 EXPORT_SYMBOL (of_n_size_cells)
 
struct propertyof_find_property (const struct device_node *np, const char *name, int *lenp)
 
 EXPORT_SYMBOL (of_find_property)
 
struct device_nodeof_find_all_nodes (struct device_node *prev)
 
 EXPORT_SYMBOL (of_find_all_nodes)
 
const voidof_get_property (const struct device_node *np, const char *name, int *lenp)
 
 EXPORT_SYMBOL (of_get_property)
 
int of_device_is_compatible (const struct device_node *device, const char *compat)
 
 EXPORT_SYMBOL (of_device_is_compatible)
 
int of_machine_is_compatible (const char *compat)
 
 EXPORT_SYMBOL (of_machine_is_compatible)
 
int of_device_is_available (const struct device_node *device)
 
 EXPORT_SYMBOL (of_device_is_available)
 
struct device_nodeof_get_parent (const struct device_node *node)
 
 EXPORT_SYMBOL (of_get_parent)
 
struct device_nodeof_get_next_parent (struct device_node *node)
 
struct device_nodeof_get_next_child (const struct device_node *node, struct device_node *prev)
 
 EXPORT_SYMBOL (of_get_next_child)
 
struct device_nodeof_get_next_available_child (const struct device_node *node, struct device_node *prev)
 
 EXPORT_SYMBOL (of_get_next_available_child)
 
: child name to look for.

of_get_child_by_name - Find the child node by name for a given parent : parent node

This function looks for child node for given matching name

Returns a node pointer if found, with refcount incremented, use of_node_put() on it when done. Returns NULL if node is not found.

struct device_nodeof_get_child_by_name (const struct device_node *node, const char *name)
 
 EXPORT_SYMBOL (of_get_child_by_name)
 
struct device_nodeof_find_node_by_path (const char *path)
 
 EXPORT_SYMBOL (of_find_node_by_path)
 
: The name string to match against

of_find_node_by_name - Find a node by its "name" property : The node to start searching from or NULL, the node you pass will not be searched, only the next one will; typically, you pass what the previous call returned. of_node_put() will be called on it

Returns a node pointer with refcount incremented, use of_node_put() on it when done.

struct device_nodeof_find_node_by_name (struct device_node *from, const char *name)
 
 EXPORT_SYMBOL (of_find_node_by_name)
 
struct device_nodeof_find_node_by_type (struct device_node *from, const char *type)
 
 EXPORT_SYMBOL (of_find_node_by_type)
 
struct device_nodeof_find_compatible_node (struct device_node *from, const char *type, const char *compatible)
 
 EXPORT_SYMBOL (of_find_compatible_node)
 
struct device_nodeof_find_node_with_property (struct device_node *from, const char *prop_name)
 
 EXPORT_SYMBOL (of_find_node_with_property)
 
struct of_device_idof_match_node (const struct of_device_id *matches, const struct device_node *node)
 
 EXPORT_SYMBOL (of_match_node)
 
struct device_nodeof_find_matching_node (struct device_node *from, const struct of_device_id *matches)
 
 EXPORT_SYMBOL (of_find_matching_node)
 
int of_modalias_node (struct device_node *node, char *modalias, int len)
 
 EXPORT_SYMBOL_GPL (of_modalias_node)
 
struct device_nodeof_find_node_by_phandle (phandle handle)
 
 EXPORT_SYMBOL (of_find_node_by_phandle)
 
int of_property_read_u32_array (const struct device_node *np, const char *propname, u32 *out_values, size_t sz)
 
 EXPORT_SYMBOL_GPL (of_property_read_u32_array)
 
int of_property_read_u64 (const struct device_node *np, const char *propname, u64 *out_value)
 
 EXPORT_SYMBOL_GPL (of_property_read_u64)
 
int of_property_read_string (struct device_node *np, const char *propname, const char **out_string)
 
 EXPORT_SYMBOL_GPL (of_property_read_string)
 
int of_property_read_string_index (struct device_node *np, const char *propname, int index, const char **output)
 
 EXPORT_SYMBOL_GPL (of_property_read_string_index)
 
int of_property_match_string (struct device_node *np, const char *propname, const char *string)
 
 EXPORT_SYMBOL_GPL (of_property_match_string)
 
int of_property_count_strings (struct device_node *np, const char *propname)
 
 EXPORT_SYMBOL_GPL (of_property_count_strings)
 
struct device_nodeof_parse_phandle (struct device_node *np, const char *phandle_name, int index)
 
 EXPORT_SYMBOL (of_parse_phandle)
 
int of_parse_phandle_with_args (struct device_node *np, const char *list_name, const char *cells_name, int index, struct of_phandle_args *out_args)
 
 EXPORT_SYMBOL (of_parse_phandle_with_args)
 
int prom_add_property (struct device_node *np, struct property *prop)
 
int prom_remove_property (struct device_node *np, struct property *prop)
 
int prom_update_property (struct device_node *np, struct property *newprop)
 
void of_alias_scan (void *(*dt_alloc)(u64 size, u64 align))
 
int of_alias_get_id (struct device_node *np, const char *stem)
 
 EXPORT_SYMBOL_GPL (of_alias_get_id)
 
const __be32of_prop_next_u32 (struct property *prop, const __be32 *cur, u32 *pu)
 
 EXPORT_SYMBOL_GPL (of_prop_next_u32)
 
const charof_prop_next_string (struct property *prop, const char *cur)
 
 EXPORT_SYMBOL_GPL (of_prop_next_string)
 

Variables

struct device_nodeallnodes
 
struct device_nodeof_chosen
 
struct device_nodeof_aliases
 

Function Documentation

DEFINE_RWLOCK ( devtree_lock  )
EXPORT_SYMBOL ( of_n_addr_cells  )
EXPORT_SYMBOL ( of_n_size_cells  )
EXPORT_SYMBOL ( of_find_property  )
EXPORT_SYMBOL ( of_find_all_nodes  )
EXPORT_SYMBOL ( of_get_property  )
EXPORT_SYMBOL ( of_device_is_compatible  )
EXPORT_SYMBOL ( of_machine_is_compatible  )
EXPORT_SYMBOL ( of_device_is_available  )
EXPORT_SYMBOL ( of_get_parent  )
EXPORT_SYMBOL ( of_get_next_child  )
EXPORT_SYMBOL ( of_get_next_available_child  )
EXPORT_SYMBOL ( of_get_child_by_name  )
EXPORT_SYMBOL ( of_find_node_by_path  )
EXPORT_SYMBOL ( of_find_node_by_name  )
EXPORT_SYMBOL ( of_find_node_by_type  )
EXPORT_SYMBOL ( of_find_compatible_node  )
EXPORT_SYMBOL ( of_find_node_with_property  )
EXPORT_SYMBOL ( of_match_node  )
EXPORT_SYMBOL ( of_find_matching_node  )
EXPORT_SYMBOL ( of_find_node_by_phandle  )
EXPORT_SYMBOL ( of_parse_phandle  )
EXPORT_SYMBOL ( of_parse_phandle_with_args  )
EXPORT_SYMBOL_GPL ( of_modalias_node  )
EXPORT_SYMBOL_GPL ( of_property_read_u32_array  )
EXPORT_SYMBOL_GPL ( of_property_read_u64  )
EXPORT_SYMBOL_GPL ( of_property_read_string  )
EXPORT_SYMBOL_GPL ( of_property_read_string_index  )
EXPORT_SYMBOL_GPL ( of_property_match_string  )
EXPORT_SYMBOL_GPL ( of_property_count_strings  )
EXPORT_SYMBOL_GPL ( of_alias_get_id  )
EXPORT_SYMBOL_GPL ( of_prop_next_u32  )
EXPORT_SYMBOL_GPL ( of_prop_next_string  )
int of_alias_get_id ( struct device_node np,
const char stem 
)

of_alias_get_id - Get alias id for the given device_node : Pointer to the given device_node : Alias stem of the given device_node

The function travels the lookup table to get alias id for the given device_node and alias stem. It returns the alias id if find it.

Definition at line 1300 of file base.c.

void of_alias_scan ( void *(*)(u64 size, u64 align dt_alloc)

of_alias_scan - Scan all properties of 'aliases' node

The function scans all the properties of 'aliases' node and populate the the global lookup table with the properties. It returns the number of alias_prop found, or error code in error case.

: An allocator that provides a virtual address to memory for the resulting tree

Definition at line 1246 of file base.c.

int of_device_is_available ( const struct device_node device)

of_device_is_available - check if a device is available for use

: Node to check for availability

Returns 1 if the status property is absent or set to "okay" or "ok", 0 otherwise

Definition at line 278 of file base.c.

int of_device_is_compatible ( const struct device_node device,
const char compat 
)

Checks if the given "compat" string matches one of the strings in the device's "compatible" property

Definition at line 228 of file base.c.

struct device_node* of_find_all_nodes ( struct device_node prev)
read

of_find_all_nodes - Get next node in global list : Previous node or NULL to start iteration of_node_put() will be called on it

Returns a node pointer with refcount incremented, use of_node_put() on it when done.

Definition at line 197 of file base.c.

struct device_node* of_find_compatible_node ( struct device_node from,
const char type,
const char compatible 
)
read

of_find_compatible_node - Find a node based on type and one of the tokens in its "compatible" property : The node to start searching from or NULL, the node you pass will not be searched, only the next one will; typically, you pass what the previous call returned. of_node_put() will be called on it : The type string to match "device_type" or NULL to ignore : The string to match to one of the tokens in the device "compatible" list.

Returns a node pointer with refcount incremented, use of_node_put() on it when done.

Definition at line 509 of file base.c.

struct device_node* of_find_matching_node ( struct device_node from,
const struct of_device_id matches 
)
read

of_find_matching_node - Find a node based on an of_device_id match table. : The node to start searching from or NULL, the node you pass will not be searched, only the next one will; typically, you pass what the previous call returned. of_node_put() will be called on it : array of of device match structures to search in

Returns a node pointer with refcount incremented, use of_node_put() on it when done.

Definition at line 608 of file base.c.

struct device_node* of_find_node_by_name ( struct device_node from,
const char name 
)
read

Definition at line 449 of file base.c.

struct device_node* of_find_node_by_path ( const char path)
read

of_find_node_by_path - Find a node matching a full OF path : The full path to match

Returns a node pointer with refcount incremented, use of_node_put() on it when done.

Definition at line 423 of file base.c.

struct device_node* of_find_node_by_phandle ( phandle  handle)
read

of_find_node_by_phandle - Find a node given a phandle : phandle of the node to find

Returns a node pointer with refcount incremented, use of_node_put() on it when done.

Definition at line 659 of file base.c.

struct device_node* of_find_node_by_type ( struct device_node from,
const char type 
)
read

of_find_node_by_type - Find a node by its "device_type" property : The node to start searching from, or NULL to start searching the entire device tree. The node you pass will not be searched, only the next one will; typically, you pass what the previous call returned. of_node_put() will be called on from for you. : The type string to match against

Returns a node pointer with refcount incremented, use of_node_put() on it when done.

Definition at line 478 of file base.c.

struct device_node* of_find_node_with_property ( struct device_node from,
const char prop_name 
)
read

of_find_node_with_property - Find a node which has a property with the given name. : The node to start searching from or NULL, the node you pass will not be searched, only the next one will; typically, you pass what the previous call returned. of_node_put() will be called on it : The name of the property to look for.

Returns a node pointer with refcount incremented, use of_node_put() on it when done.

Definition at line 541 of file base.c.

struct property* of_find_property ( const struct device_node np,
const char name,
int lenp 
)
read

Definition at line 166 of file base.c.

struct device_node* of_get_child_by_name ( const struct device_node node,
const char name 
)
read

Definition at line 404 of file base.c.

struct device_node* of_get_next_available_child ( const struct device_node node,
struct device_node prev 
)
read

of_get_next_available_child - Find the next available child node : parent node : previous child of the parent node, or NULL to get first

This function is like of_get_next_child(), except that it
automatically skips any disabled nodes (i.e. status = "disabled").

Definition at line 374 of file base.c.

struct device_node* of_get_next_child ( const struct device_node node,
struct device_node prev 
)
read

of_get_next_child - Iterate a node childs : parent node : previous child of the parent node, or NULL to get first

Returns a node pointer with refcount incremented, use of_node_put() on it when done.

Definition at line 350 of file base.c.

struct device_node* of_get_next_parent ( struct device_node node)
read

of_get_next_parent - Iterate to a node's parent : Node to get parent of

This is like of_get_parent() except that it drops the refcount on the passed node, making it suitable for iterating through a node's parents.

Returns a node pointer with refcount incremented, use of_node_put() on it when done.

Definition at line 328 of file base.c.

struct device_node* of_get_parent ( const struct device_node node)
read

of_get_parent - Get a node's parent if any : Node to get parent

Returns a node pointer with refcount incremented, use of_node_put() on it when done.

Definition at line 303 of file base.c.

const void* of_get_property ( const struct device_node np,
const char name,
int lenp 
)

Definition at line 216 of file base.c.

int of_machine_is_compatible ( const char compat)

of_machine_is_compatible - Test root of device tree for a given compatible value : compatible string to look for in root node's compatible property.

Returns true if the root node has the given value in its compatible property.

Definition at line 256 of file base.c.

struct of_device_id* of_match_node ( const struct of_device_id matches,
const struct device_node node 
)
read

of_match_node - Tell if an device_node has a matching of_match structure : array of of device match structures to search in : the of device structure to match against

Low level utility function used by device matching.

Definition at line 571 of file base.c.

int of_modalias_node ( struct device_node node,
char modalias,
int  len 
)

of_modalias_node - Lookup appropriate modalias for a device node : pointer to a device tree node : Pointer to buffer that modalias value will be copied into : Length of modalias value

Based on the value of the compatible property, this routine will attempt to choose an appropriate modalias value for a particular device tree node. It does this by stripping the manufacturer prefix (as delimited by a ',') from the first entry in the compatible list property.

This routine returns 0 on success, <0 on failure.

Definition at line 638 of file base.c.

int of_n_addr_cells ( struct device_node np)

Definition at line 59 of file base.c.

int of_n_size_cells ( struct device_node np)

Definition at line 75 of file base.c.

struct device_node* of_parse_phandle ( struct device_node np,
const char phandle_name,
int  index 
)
read

of_parse_phandle - Resolve a phandle property to a device_node pointer : Pointer to device node holding phandle property : Name of property holding a phandle value : For properties holding a table of phandles, this is the index into the table

Returns the device_node pointer with refcount incremented. Use of_node_put() on it when done.

Definition at line 897 of file base.c.

int of_parse_phandle_with_args ( struct device_node np,
const char list_name,
const char cells_name,
int  index,
struct of_phandle_args out_args 
)

of_parse_phandle_with_args() - Find a node pointed by phandle in a list : pointer to a device tree node containing a list : property name that contains a list : property name that specifies phandles' arguments count : index of a phandle to parse out : optional pointer to output arguments structure (will be filled)

This function is useful to parse lists of phandles and their arguments. Returns 0 on success and fills out_args, on error returns appropriate errno value.

Caller is responsible to call of_node_put() on the returned out_args->node pointer.

Example:

phandle1: node1 { list-cells = <2>; }

phandle2: node2 { list-cells = <1>; }

node3 { list = <&phandle1 1 2 &phandle2 3>; }

To get a device_node of the `node2' node you may call this: of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);

Definition at line 942 of file base.c.

const char* of_prop_next_string ( struct property prop,
const char cur 
)

Definition at line 1344 of file base.c.

const __be32* of_prop_next_u32 ( struct property prop,
const __be32 cur,
u32 pu 
)

Definition at line 1321 of file base.c.

int of_property_count_strings ( struct device_node np,
const char propname 
)

of_property_count_strings - Find and return the number of strings from a multiple strings property. : device node from which the property value is to be read. : name of the property to be searched.

Search for a property in a device tree node and retrieve the number of null terminated string contain in it. Returns the number of strings on success, -EINVAL if the property does not exist, -ENODATA if property does not have a value, and -EILSEQ if the string is not null-terminated within the length of the property data.

Definition at line 863 of file base.c.

int of_property_match_string ( struct device_node np,
const char propname,
const char string 
)

of_property_match_string() - Find string in a list and return index : pointer to node containing string list property : string list property name : pointer to string to search for in string list

This function searches a string list property and returns the index of a specific string value.

Definition at line 823 of file base.c.

int of_property_read_string ( struct device_node np,
const char propname,
const char **  out_string 
)

of_property_read_string - Find and read a string from a property : device node from which the property value is to be read. : name of the property to be searched. : pointer to null terminated return string, modified only if return value is 0.

Search for a property in a device tree node and retrieve a null terminated string value (pointer to data, not a copy). Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if property does not have a value, and -EILSEQ if the string is not null-terminated within the length of the property data.

The out_string pointer is modified only if a valid string can be decoded.

Definition at line 753 of file base.c.

int of_property_read_string_index ( struct device_node np,
const char propname,
int  index,
const char **  output 
)

of_property_read_string_index - Find and read a string from a multiple strings property. : device node from which the property value is to be read. : name of the property to be searched. : index of the string in the list of strings : pointer to null terminated return string, modified only if return value is 0.

Search for a property in a device tree node and retrieve a null terminated string value (pointer to data, not a copy) in the list of strings contained in that property. Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if property does not have a value, and -EILSEQ if the string is not null-terminated within the length of the property data.

The out_string pointer is modified only if a valid string can be decoded.

Definition at line 786 of file base.c.

int of_property_read_u32_array ( const struct device_node np,
const char propname,
u32 out_values,
size_t  sz 
)

of_property_read_u32_array - Find and read an array of 32 bit integers from a property.

: device node from which the property value is to be read. : name of the property to be searched. : pointer to return value, modified only if return value is 0.

Search for a property in a device node and read 32-bit value(s) from it. Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if property does not have a value, and -EOVERFLOW if the property data isn't large enough.

The out_value is modified only if a valid u32 value can be decoded.

Definition at line 688 of file base.c.

int of_property_read_u64 ( const struct device_node np,
const char propname,
u64 out_value 
)

of_property_read_u64 - Find and read a 64 bit integer from a property : device node from which the property value is to be read. : name of the property to be searched. : pointer to return value, modified only if return value is 0.

Search for a property in a device node and read a 64-bit value from it. Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if property does not have a value, and -EOVERFLOW if the property data isn't large enough.

The out_value is modified only if a valid u64 value can be decoded.

Definition at line 722 of file base.c.

int prom_add_property ( struct device_node np,
struct property prop 
)

prom_add_property - Add a property to a node

Definition at line 1034 of file base.c.

int prom_remove_property ( struct device_node np,
struct property prop 
)

prom_remove_property - Remove a property from a node.

Note that we don't actually remove it, since we have given out who-knows-how-many pointers to the data using get-property. Instead we just move the property to the "dead properties" list, so it won't be found any more.

Definition at line 1070 of file base.c.

int prom_update_property ( struct device_node np,
struct property newprop 
)

Definition at line 1112 of file base.c.

Variable Documentation

struct device_node* allnodes

Definition at line 48 of file base.c.

struct device_node* of_aliases

Definition at line 50 of file base.c.

struct device_node* of_chosen

Definition at line 49 of file base.c.