设备树在文件系统中的体现: 在/proc/device-tree
设备节点:
struct device_node {
const char *name; /* 节点名字 */
const char *type; /* 设备类型 */
phandle phandle;
const char *full_name; /* 节点全名 */
struct fwnode_handle fwnode;
struct property *properties; /* 属性 */
struct property *deadprops; /* removed 属性 */
struct device_node *parent; /* 父节点 */
struct device_node *child; /* 子节点 */
struct device_node *sibling;
struct kobject kobj;
unsigned long _flags;
void *data;
#if defined(CONFIG_SPARC)
const char *path_component_name;
unsigned int unique_id;
struct of_irq_controller *irq_trans;
#endif
};
OF函数:
1、通过节点名查找指定节点:struct device_node * of_find_node_by_name(struct device_node *from_node,const char *name);
2、通过device_type查找指定节点:struct device_node * of_fine_node_by_type(struct device_node *from_node,const char *type);
3、通过compatible和device_type查找节点 struct device_node * of_find_compatible_node(struct device_node *from_node,const char *type,const char*compatible_name);
4、通过of_device_id来查找节点:struct device_node * of_find_matching_node_and_match(struct device_node *from_node,const char matchs*,const char** match);
5、通过路径来查找节点:struct device_node * of_find_by_name(const char *path);
6、查找指定节点的父节点:struct device_node * of_get_parent(const struct device_node *node)
7、迭代查找子节点:of_get_next_child(struct device_node *parent,struct device_node prev)
8、查找指定属性:property * of_find_property(struct device_node *node,const char *name,int *len);len属性字节数
9、获取属性元素的数量 :int of_property-count_elems_of_size(struct device_node *node,const char *prop_name,int len);//元素长度
10、从属性中获取指定索引位置的u32数据 int of_property_read_u32_index(struct device_node *node,const propname,u32 index,u32 *value);
11、读取属性中 u8、 u16、 u32 和 u64 类型的数组数据:
int of_property_read_u8_array(const struct device_node *np,
const char *propname,
u8 *out_values,
size_t sz)
int of_property_read_u16_array(const struct device_node *np,
const char *propname,
u16 *out_values,
size_t sz)
int of_property_read_u32_array(const struct device_node *np,
const char *propname,
u32 *out_values,
size_t sz)
int of_property_read_u64_array(const struct device_node *np,
const char *propname,
u32 *out_values,
size_t sz)
12、读取这种只有一个整形值的属性
int of_property_read_u8(const struct device_node *np,
const char *propname,
u8 *out_value)
int of_property_read_u16(const struct device_node *np,
const char *propname,
u16 *out_value)
int of_property_read_u32(const struct device_node *np,
const char *propname,
u32 *out_value)
int of_property_read_u64(const struct device_node *np,
const char *propname,
u64 *out_value)
13、读取属性中的字符串:int of_property_read_string(const struct device_node *np,const char *propname,char **value_str)
14、获取#address-cells数据 int of_n_addr_cells(const struct device_node *np);
15、获取#size-cells数据 int of_n_size_cells(const struct device_node *np);
------------------------
16、查看compatible属性是否包含conpat指定的字符串:of_device_is_compatible(const struct device_node *np,const char *compat_str);//返回 0 则包含
17、获取地址相关的属性,主要是“reg”或者“assigned-addresses”属性值:of_get_addr();
18、将从设备树得到的地址转换为物理地址:u64 of_translate_address(struct device_node *dev, const _be32 * in_addr);
19、将reg属性抓换位resource结构数据:int of_address_to_resource(struct device_node *dev,int index,struct *resource *re);
struct resource {
resource_size_t start;
resource_size_t end;
const char *name;
unsigned long flags;//常见参数IORESOURCE_MEM 、 IORESOURCE_REG 和IORESOURCE_IRQ
struct resource *parent, *sibling, *child;
};
20、获取内存地址对应的虚拟地址:of_iomap(struct device_node *np,int index);//index:reg 属性中要完成内存映射的段