Linux設備樹相關

設備樹在文件系統中的體現: 在/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 屬性中要完成內存映射的段
                

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章