长沙网站优化排名,网站 流量攻击,网站数据库 权限设计,如何制作wordpress模板说明
类似于linux#xff0c;为了规范、统一驱动适配和驱动接口调用#xff0c;uboot定义了一套驱动模型(Driver Model)#xff0c;简称DM。本文基于#xff1a;u-boot-2021.10。
优点
为同一类ip的驱动定义了统一的操作接口#xff0c;DM在软件层面做了一定的抽象。分…说明
类似于linux为了规范、统一驱动适配和驱动接口调用uboot定义了一套驱动模型(Driver Model)简称DM。本文基于u-boot-2021.10。
优点
为同一类ip的驱动定义了统一的操作接口DM在软件层面做了一定的抽象。分层设计将上层使用、设备以及驱动实现区分开来降低了耦合性。
核心概念/数据结构
DM模型抽象出了以下四个概念/数据结构。
uclassuclass_driverudevicedriver
uclass
uclassuboot class是同一类外设I2C、GPIO等总的组织结构体定义如下
// fileinclude/dm/uclass.h
/*** struct uclass - a U-Boot drive class, collecting together similar drivers** A uclass provides an interface to a particular function, which is* implemented by one or more drivers. Every driver belongs to a uclass even* if it is the only driver in that uclass. An example uclass is GPIO, which* provides the ability to change read inputs, set and clear outputs, etc.* There may be drivers for on-chip SoC GPIO banks, I2C GPIO expanders and* PMIC IO lines, all made available in a unified way through the uclass.** priv_: Private data for this uclass (do not access outside driver model)* uc_drv: The driver for the uclass itself, not to be confused with a* struct driver* dev_head: List of devices in this uclass (devices are attached to their* uclass when their bind method is called)* sibling_node: Next uclass in the linked list of uclasses*/
struct uclass {void *priv_;struct uclass_driver *uc_drv;struct list_head dev_head;struct list_head sibling_node;
};uclass 包含
uc_drv: uclass driver。dev_head: udevice list(设备列表)。sibling_node: 链表的下一个uclass结构。
uclass_driver
uclass_driver是uclass的驱动并不是具体硬件驱动做一些uclass通用的的准备/回收等工作。
// fileinclude/dm/uclass.h
struct uclass_driver {const char *name;enum uclass_id id;int (*post_bind)(struct udevice *dev);int (*pre_unbind)(struct udevice *dev);int (*pre_probe)(struct udevice *dev);int (*post_probe)(struct udevice *dev);int (*pre_remove)(struct udevice *dev);int (*child_post_bind)(struct udevice *dev);int (*child_pre_probe)(struct udevice *dev);int (*child_post_probe)(struct udevice *dev);int (*init)(struct uclass *class);int (*destroy)(struct uclass *class);int priv_auto;int per_device_auto;int per_device_plat_auto;int per_child_auto;int per_child_plat_auto;uint32_t flags;
};使用宏UCLASS_DRIVER定义一个uclass driver,每一类ip会定义一个如下
//file: drivers/timer/timer-uclass.c
UCLASS_DRIVER(timer) {.id UCLASS_TIMER,.name timer,.pre_probe timer_pre_probe,.flags DM_UC_FLAG_SEQ_ALIAS,.post_probe timer_post_probe,.per_device_auto sizeof(struct timer_dev_priv),
};预定义的uclass id。
//file: include/dm/uclass-id.h
enum uclass_id {/* These are used internally by driver model */UCLASS_ROOT 0,UCLASS_DEMO,UCLASS_TEST,UCLASS_TEST_FDT,UCLASS_TEST_FDT_MANUAL,UCLASS_TEST_BUS,UCLASS_TEST_PROBE,UCLASS_TEST_DUMMY,UCLASS_TEST_DEVRES,UCLASS_TEST_ACPI,...
}udevice
udevice是具体硬件的实例例如dts中配置了两个timer就会有两个timer udeviceuboot会将udevice和它所属的uclass以及具体的驱动driver绑定起来。
//fileinclude/dm/device.h
struct udevice {const struct driver *driver;const char *name;void *plat_;void *parent_plat_;void *uclass_plat_;ulong driver_data;struct udevice *parent;void *priv_;struct uclass *uclass;void *uclass_priv_;void *parent_priv_;struct list_head uclass_node;struct list_head child_head;struct list_head sibling_node;
#if !CONFIG_IS_ENABLED(OF_PLATDATA_RT)u32 flags_;
#endifint seq_;
#if !CONFIG_IS_ENABLED(OF_PLATDATA)ofnode node_;
#endif
#ifdef CONFIG_DEVRESstruct list_head devres_head;
#endif
#if CONFIG_IS_ENABLED(DM_DMA)ulong dma_offset;
#endif
};driver
具体硬件的驱动对应每个硬件的驱动实现例如dw wdt(drivers/watchdog/designware_wdt.c), mtk wdt(drivers/watchdog/mtk_wdt.c) 。
//file: include/dm/device.h
struct driver {char *name;enum uclass_id id;const struct udevice_id *of_match;int (*bind)(struct udevice *dev);int (*probe)(struct udevice *dev);int (*remove)(struct udevice *dev);int (*unbind)(struct udevice *dev);int (*of_to_plat)(struct udevice *dev);int (*child_post_bind)(struct udevice *dev);int (*child_pre_probe)(struct udevice *dev);int (*child_post_remove)(struct udevice *dev);int priv_auto;int plat_auto;int per_child_auto;int per_child_plat_auto;const void *ops; /* driver-specific operations */uint32_t flags;
#if CONFIG_IS_ENABLED(ACPIGEN)struct acpi_ops *acpi_ops;
#endif
};* const void *ops; 是该驱动支持的接口。ops 指向该类ip统一驱动接口结构体在include目录的头文件中有各种ip需要支持的ops接口例如
include/thermal.h //温度传感器需要支持的接口ops
include/wdt.h //wdt需要支持的ops
include/timer.h //timer需要支持的ops
* include/timer.h
struct timer_ops {/*** get_count: Get the current timer count** dev: The timer device** This function may be called at any time after the driver is probed.* All necessary initialization must be completed by the time probe()* returns. The count returned by this functions should be monotonic.* This function must succeed.** Return: The current 64-bit timer count*/u64 (*get_count)(struct udevice *dev);
};新思定时器dw apb timer定义
static const struct timer_ops dw_apb_timer_ops {.get_count dw_apb_timer_get_count,
};U_BOOT_DRIVER(dw_apb_timer) {.name dw_apb_timer,.id UCLASS_TIMER,.ops dw_apb_timer_ops,.probe dw_apb_timer_probe,.of_match dw_apb_timer_ids,.of_to_plat dw_apb_timer_of_to_plat,.remove dw_apb_timer_remove,.priv_auto sizeof(struct dw_apb_timer_priv),
};使用宏U_BOOT_DRIVER定义一个驱动实例
/* Declare a new U-Boot driver */
#define U_BOOT_DRIVER(__name) \ll_entry_declare(struct driver, __name, driver)联系
uclass和udevice是动态生成的。udevice在解析fdt中的设备的时候自动生成然后udevice找到对应的driverdriver中保存了uclass_id根据它找到uclass_driver_id从uclass链表中查找对应的uclass是否已经生成若没有生成则动态生成重点是解析设备树生成udevice并找到对应的driver。
代码流程
模型的全局数据结构包含根节点。
typedef struct global_data {// dts中的根节点第一个创建的udevicestruct udevice *dm_root;// relocation之前的根设备struct udevice *dm_root_f;// uclass的链表, 挂的是有udevice的uclassstruct list_head uclass_root;
} gd_t;初始化与扫描设备树
int dm_init_and_scan(bool pre_reloc_only)
{int ret;ret dm_init(CONFIG_IS_ENABLED(OF_LIVE));if (ret) {debug(dm_init() failed: %d\n, ret);return ret;}if (!CONFIG_IS_ENABLED(OF_PLATDATA_INST)) {ret dm_scan(pre_reloc_only);if (ret) {log_debug(dm_scan() failed: %d\n, ret);return ret;}}return 0;
}DM模型初始化(dm_init)
int dm_init(bool of_live)
{gd-uclass_root DM_UCLASS_ROOT_S_NON_CONST;//初始化uclass_root链表头INIT_LIST_HEAD(DM_UCLASS_ROOT_NON_CONST);//创建一个device dm_root并将其绑定到driver name “root_driver”。device_bind_by_name(NULL, false, root_info,DM_ROOT_NON_CONST);//探测设备udevice dm_root并激活它ret device_probe(DM_ROOT_NON_CONST);
}待补充
DM模型Device Tree节点的设备初始化(dm_scan)
待补充
绑定udevice和driver(device_bind_common)
待补充
使用
整体使能
配置CONFIG_DM不同类型外设需要专门使能
串口配置CONFIG_DM_SERIAL
wdt配置CONFIG_WDT
文章转载自: http://www.morning.qkkmd.cn.gov.cn.qkkmd.cn http://www.morning.ndyrb.com.gov.cn.ndyrb.com http://www.morning.dljujia.com.gov.cn.dljujia.com http://www.morning.kfbth.cn.gov.cn.kfbth.cn http://www.morning.zrks.cn.gov.cn.zrks.cn http://www.morning.nzwp.cn.gov.cn.nzwp.cn http://www.morning.mjkqj.cn.gov.cn.mjkqj.cn http://www.morning.jzfxk.cn.gov.cn.jzfxk.cn http://www.morning.tyjnr.cn.gov.cn.tyjnr.cn http://www.morning.rsnd.cn.gov.cn.rsnd.cn http://www.morning.pwggd.cn.gov.cn.pwggd.cn http://www.morning.yfnjk.cn.gov.cn.yfnjk.cn http://www.morning.pmxw.cn.gov.cn.pmxw.cn http://www.morning.fkflc.cn.gov.cn.fkflc.cn http://www.morning.grbgn.cn.gov.cn.grbgn.cn http://www.morning.llfwg.cn.gov.cn.llfwg.cn http://www.morning.qgdsd.cn.gov.cn.qgdsd.cn http://www.morning.ysbrz.cn.gov.cn.ysbrz.cn http://www.morning.nqyfm.cn.gov.cn.nqyfm.cn http://www.morning.djlxz.cn.gov.cn.djlxz.cn http://www.morning.pndw.cn.gov.cn.pndw.cn http://www.morning.bloao.com.gov.cn.bloao.com http://www.morning.fldsb.cn.gov.cn.fldsb.cn http://www.morning.ypklb.cn.gov.cn.ypklb.cn http://www.morning.pwdgy.cn.gov.cn.pwdgy.cn http://www.morning.rcqyk.cn.gov.cn.rcqyk.cn http://www.morning.bxbnf.cn.gov.cn.bxbnf.cn http://www.morning.xkjrq.cn.gov.cn.xkjrq.cn http://www.morning.dnmzl.cn.gov.cn.dnmzl.cn http://www.morning.slysg.cn.gov.cn.slysg.cn http://www.morning.bnxfj.cn.gov.cn.bnxfj.cn http://www.morning.qfkxj.cn.gov.cn.qfkxj.cn http://www.morning.rqwwm.cn.gov.cn.rqwwm.cn http://www.morning.xjmyq.com.gov.cn.xjmyq.com http://www.morning.ftzll.cn.gov.cn.ftzll.cn http://www.morning.llgpk.cn.gov.cn.llgpk.cn http://www.morning.ychrn.cn.gov.cn.ychrn.cn http://www.morning.wyrsn.cn.gov.cn.wyrsn.cn http://www.morning.bpkqd.cn.gov.cn.bpkqd.cn http://www.morning.fzlk.cn.gov.cn.fzlk.cn http://www.morning.gjtdp.cn.gov.cn.gjtdp.cn http://www.morning.lhygbh.com.gov.cn.lhygbh.com http://www.morning.wfbnp.cn.gov.cn.wfbnp.cn http://www.morning.nzhzt.cn.gov.cn.nzhzt.cn http://www.morning.trbxt.cn.gov.cn.trbxt.cn http://www.morning.dpsyr.cn.gov.cn.dpsyr.cn http://www.morning.yhrfg.cn.gov.cn.yhrfg.cn http://www.morning.pxbrg.cn.gov.cn.pxbrg.cn http://www.morning.kjyqr.cn.gov.cn.kjyqr.cn http://www.morning.mxlwl.cn.gov.cn.mxlwl.cn http://www.morning.gcfrt.cn.gov.cn.gcfrt.cn http://www.morning.gnyhc.cn.gov.cn.gnyhc.cn http://www.morning.qnzgr.cn.gov.cn.qnzgr.cn http://www.morning.ldfcb.cn.gov.cn.ldfcb.cn http://www.morning.ftnhr.cn.gov.cn.ftnhr.cn http://www.morning.bxczt.cn.gov.cn.bxczt.cn http://www.morning.bphqd.cn.gov.cn.bphqd.cn http://www.morning.jfwrf.cn.gov.cn.jfwrf.cn http://www.morning.btns.cn.gov.cn.btns.cn http://www.morning.zbqsg.cn.gov.cn.zbqsg.cn http://www.morning.wdwfm.cn.gov.cn.wdwfm.cn http://www.morning.sqqhd.cn.gov.cn.sqqhd.cn http://www.morning.brlgf.cn.gov.cn.brlgf.cn http://www.morning.jxlnr.cn.gov.cn.jxlnr.cn http://www.morning.gwxsk.cn.gov.cn.gwxsk.cn http://www.morning.lpppg.cn.gov.cn.lpppg.cn http://www.morning.xhsxj.cn.gov.cn.xhsxj.cn http://www.morning.ppghc.cn.gov.cn.ppghc.cn http://www.morning.stxg.cn.gov.cn.stxg.cn http://www.morning.lgtcg.cn.gov.cn.lgtcg.cn http://www.morning.mlbn.cn.gov.cn.mlbn.cn http://www.morning.psdsk.cn.gov.cn.psdsk.cn http://www.morning.nmfwm.cn.gov.cn.nmfwm.cn http://www.morning.jczjf.cn.gov.cn.jczjf.cn http://www.morning.msgrq.cn.gov.cn.msgrq.cn http://www.morning.zdsqb.cn.gov.cn.zdsqb.cn http://www.morning.mzwfw.cn.gov.cn.mzwfw.cn http://www.morning.dkzwx.cn.gov.cn.dkzwx.cn http://www.morning.wffxr.cn.gov.cn.wffxr.cn http://www.morning.hsrch.cn.gov.cn.hsrch.cn