struct udevice

struct udevice定义

100/**
101 * struct udevice - An instance of a driver
102 *
103 * This holds information about a device, which is a driver bound to a
104 * particular port or peripheral (essentially a driver instance).
105 *
106 * A device will come into existence through a 'bind' call, either due to
107 * a U_BOOT_DEVICE() macro (in which case platdata is non-NULL) or a node
108 * in the device tree (in which case of_offset is >= 0). In the latter case
109 * we translate the device tree information into platdata in a function
110 * implemented by the driver ofdata_to_platdata method (called just before the
111 * probe method if the device has a device tree node.
112 *
113 * All three of platdata, priv and uclass_priv can be allocated by the
114 * driver, or you can use the auto_alloc_size members of struct driver and
115 * struct uclass_driver to have driver model do this automatically.
116 *
117 * @driver: The driver used by this device
118 * @name: Name of device, typically the FDT node name
119 * @platdata: Configuration data for this device
120 * @parent_platdata: The parent bus's configuration data for this device
121 * @uclass_platdata: The uclass's configuration data for this device
122 * @node: Reference to device tree node for this device
123 * @driver_data: Driver data word for the entry that matched this device with
124 *		its driver
125 * @parent: Parent of this device, or NULL for the top level device
126 * @priv: Private data for this device
127 * @uclass: Pointer to uclass for this device
128 * @uclass_priv: The uclass's private data for this device
129 * @parent_priv: The parent's private data for this device
130 * @uclass_node: Used by uclass to link its devices
131 * @child_head: List of children of this device
132 * @sibling_node: Next device in list of all devices
133 * @flags: Flags for this device DM_FLAG_...
134 * @req_seq: Requested sequence number for this device (-1 = any)
135 * @seq: Allocated sequence number for this device (-1 = none). This is set up
136 * when the device is probed and will be unique within the device's uclass.
137 * @devres_head: List of memory allocations associated with this device.
138 *		When CONFIG_DEVRES is enabled, devm_kmalloc() and friends will
139 *		add to this list. Memory so-allocated will be freed
140 *		automatically when the device is removed / unbound
141 */
142struct udevice {
143	const struct driver *driver;
144	const char *name;
145	void *platdata;
146	void *parent_platdata;
147	void *uclass_platdata;
148	ofnode node;
149	ulong driver_data;
150	struct udevice *parent;
151	void *priv;
152	struct uclass *uclass;
153	void *uclass_priv;
154	void *parent_priv;
155	struct list_head uclass_node;
156	struct list_head child_head;
157	struct list_head sibling_node;
158	uint32_t flags;
159	int req_seq;
160	int seq;
161#ifdef CONFIG_DEVRES
162	struct list_head devres_head;
163#endif
164};

驱动程序的实例

  • 它保存有关设备的信息,设备是绑定到特定端口或外设的驱动程序(本质上是驱动程序实例)。
  • 设备将通过'bind'调用来存在,要么是由于U_BOOT_DEVICE()宏(在这种情况下,platdata是非null),要么是由于设备树中的节点(在这种情况下,of_offset >= 0)。在后一种情况下,我们将设备树信息转换为platdata在由驱动程序的data_to_platdata方法实现的函数中(如果设备具有设备树节点,则在probe方法之前调用)。
  • platdata、priv和uclass_priv这三个参数都可以由驱动程序分配,或者您可以使用struct driver和struct uclass_driver的auto_alloc_size成员让驱动程序模型自动完成分配。
  • @driver:设备使用的驱动程序
  • @name:设备名称,通常是FDT节点名称
  • @platdata:该设备的配置数据
  • @parent_platdata:该设备的父总线配置数据
  • @uclass_platdata:该设备的uclass配置数据
  • @node:引用该设备的设备树节点
  • @driver_data:这个设备与其驱动程序相匹配的项的驱动程序数据字
  • @parent:该设备的父级,对于顶级设备为NULL
  • @priv:此设备的私有数据
  • @uclass:指向该设备的uclass指针
  • @uclass_priv:此设备的ucclass的私有数据
  • @parent_priv:父设备的私有数据
  • @uclass_node: uclass用于连接其设备
  • @child_head:该设备的子节点列表
  • @sibling_node:所有设备列表中的下一个设备
  • @flags:此设备的标志DM_FLAG_…
  • @req_seq:该设备的请求序列号(-1 = any)
  • @seq:为该设备分配的序列号(-1 =无)。这是在探测设备时设置的,并且在设备的ucclass中是唯一的。
  • @devres_head:与该设备相关的内存分配列表。当CONFIG_DEVRES被启用时,devm_kmalloc()和朋友会添加到这个列表中。这样分配的内存将在设备被移除/解除绑定时自动释放

dev_get_platdata

返回设备的配置数据

534void *dev_get_platdata(const struct udevice *dev)
535{
536	if (!dev) {
537		dm_warn("%s: null device\n", __func__);
538		return NULL;
539	}
540
541	return dev->platdata;
542}

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

打个工而已

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值