Linux kernel device tree operations common API "Go"

Source: Internet
Author: User

The syntax of the device tree is described in detail in the Linux device tree syntax, which mainly describes the APIs that are provided in the kernel to manipulate the device tree, which are usually declared in "Include/of.h" .

Device_node

The following structure is used in the kernel to describe a node in the device tree, and subsequent APIs require an Device_node object to be passed in as a parameter.

Include/of.h46struct Device_node {47ConstChar *name;48ConstChar *type;Phandle Phandle;50ConstChar *full_name;5152struct property *properties;53struct property *deadprops;/* Removed properties */54struct Device_node *parent;55struct Device_node *child;56struct Device_node *sibling;57struct Device_node *next;/* Next device of same type */58struct Device_node *allnext;/* Next in the list of all nodes */59struct Proc_dir_entry *pde;/* This node ' s proc Directory */60 struct kref kref; 61 unsigned long _flags; 62 void *data; 63 #if defined (CONFIG_SPARC) Span class= "Hljs-number" >64 const char *path_component_name; 65 unsigned int unique_id; 66 struct Of_irq_controller *irq_trans; 67 #endif 68};             

struct Device_node
--47--> node Name
--48--> Device Type
--50--> Full path node name
--54--> parent Node pointer
--55--> child node pointer

Find Node API
/** * of_find_compatible_node - 通过compatible属性查找指定节点 * @from - 指向开始路径的节点,如果为NULL,则从根节点开始 * @type - device_type设备类型,可以为NULL * @compat - 指向节点的compatible属性的值(字符串)的首地址 * 成功:得到节点的首地址;失败:NULL */struct device_node *of_find_compatible_node(struct device_node *from,const char *type, const char *compat);
 /** * of_find_matching_node-Find specified node by compatible property * @from-                The node that points to the start path, if NULL, starts at the root node * @matches-points to the Device ID table, note that the ID table must end with NULL * example: const struct OF_DEVICE_ID mydemo_of_match[] = {       {. compatible = "Fs4412,mydemo",}, {}}; * Success: Get the node's first address; failure: NULL */struct device_node *of_find_matching_nodestruct device_node *from, const struct of_device_id *matches);     
/** * of_find_node_by_path - 通过路径查找指定节点 * @path - 带全路径的节点名,也可以是节点的别名 * 成功:得到节点的首地址;失败:NULL */struct device_node *of_find_node_by_path(const char *path);
/** * of_find_node_by_name - 通过节点名查找指定节点 * @from - 开始查找节点,如果为NULL,则从根节点开始 * @name- 节点名 *  成功:得到节点的首地址;失败:NULL */struct device_node *of_find_node_by_name(struct device_node *from,const char *name);
Extracting the Common Properties API
 /** * of_find_property-Extract the value of the specified property * @np-Device node pointer * @name-property name * @lenp-Number of bytes of attribute value * Success: first address of attribute value; failure: NULL */struct property *of_find_property (const struct device_node *np, const char *name, int *lenp)            
 /** * of_property_count_elems_of_size-Get the number of data in the attribute value *  @np-Device node pointer *  @propname-property name *  @elem_size-Per Units of data (number of bytes) * Success: Number of data for attribute values; failure: negative, absolute error code */int of_property_count_elems_of_sizeconst struct Device_node *np,const char *propname, int elem_size);            
 /** * of_property_read_u32_index-Gets the 32-bit data value of the specified label in the attribute value *  @np-Device node pointer *  @propname-property name *  @index-attribute value middle finger Fixed data designator *  @out_value-output parameter, get the value of the specified data * success: 0; failure: negative, absolute error code */< Span class= "Hljs-keyword" >int of_property_read_u32_index ( Span class= "Hljs-keyword" >const struct Device_node *np, const  Char *propname, U32 index, u32 *out_value);            
/** * of_property_read_string - 提取字符串(属性值) * @np - 设备节点指针 * @propname  - 属性名称 * @out_string - 输出参数,指向字符串(属性值) * 成功:0;失败:负数,绝对值是错误码 */int of_property_read_string(struct device_node *np, const char *propname, const char **out_string);
Extract Addr Property API
/** * of_n_addr_cells - 提取默认属性“#address-cells”的值 * @np - 设备节点指针 * 成功:地址的数量;失败:负数,绝对值是错误码 */int of_n_addr_cells(struct device_node *np);
/** * of_n_size_cells - 提取默认属性“#size-cells”的值 * @np - 设备节点指针 * 成功:地址长度的数量;失败:负数,绝对值是错误码 */int of_n_size_cells(struct device_node *np);
 /** * of_get_address-extract I/O port address * @np-device node pointer * @index-label of address * @ Size-output parameter, length of the I/O port address * @flags-output parameter, type (IORESOURCE_IO, IORESOURCE_MEM) * Success: First address of I/O port address; failure: NULL */__be32 *of_get_address ( struct device_node *dev, int index, U64 *size, unsigned int *flags);         
/** * of_translate_address - 从设备树中提取I/O口地址转换成物理地址 * @np - 设备节点指针 * @in_addr - 设备树提取的I/O地址 * 成功:物理地址;失败:OF_BAD_ADDR */u64 of_translate_address(struct device_node *dev, const __be32 *in_addr);
/** * of_iomap - 提取I/O口地址并映射成虚拟地址 * @np - 设备节点指针 * @index - I/O地址的标号 * 成功:映射好虚拟地址;失败:NULL */void __iomem *of_iomap(struct device_node *np, int index);
/** * 功能:提取I/O口地址并申请I/O资源及映射成虚拟地址 * @np - 设备节点指针 * @index - I/O地址的标号 * @name - 设备名,申请I/O地址时使用 * 成功:映射好虚拟地址;失败:NULL */void __iomem *of_io_request_and_map(struct device_node *np, int index, const char *name);
Extract Resource Property API
/**  * of_address_to_resource - 从设备树中提取资源resource(I/O地址) * @np - 设备节点指针 * @index - I/O地址资源的标号 * @r - 输出参数,指向资源resource(I/O地址)  * 成功:0;失败:负数,绝对值是错误码 */int of_address_to_resource(struct device_node *dev, int index, struct resource *r);
Extracting Gpio Attribute API
/** * include/of_gpio.h * of_get_named_gpio - 从设备树中提取gpio口 * @np - 设备节点指针 * @propname - 属性名 * @index - gpio口引脚标号  * 成功:得到GPIO口编号;失败:负数,绝对值是错误码 */int of_get_named_gpio(struct device_node *np, const char *propname, int index);
Extract IRQ Property API
/** * of_irq_count从设备树中提取中断的数量 * @np - 设备节点指针 * 成功:大于等于0,实际中断数量,0则表示没有中断 */int of_irq_count(struct device_node *dev);
/** * of_irq_get - 从设备树中提取中断号 * @np - 设备节点指针 * @index - 要提取的中断号的标号 * 成功:中断号;失败:负数,其绝对值是错误码int of_irq_get(struct device_node *dev, int index);
Extracting additional Property APIs
/**  * of_get_mac_address - 从设备树中提取MAC地址 * @np - 设备节点指针 * @成功:MAC(6字节)的首地址;失败:NULL */void *of_get_mac_address(struct device_node *np);

Linux kernel device tree operations common API "Go"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.