u-boot的DM驱动模型

U-Boot 2022.01-v2.07的DM驱动模型解析

0、本文基于U-Boot 2022.01-v2.07版本进行分析。

1、u-boot编译流程简要分析

2、u-boot启动流程简要分析

3、u-boot增加自定义命令

4、u-boot的DM驱动模型

  • 4.1、参考资料
    Uboot中的DM驱动模型:这篇文章详细介绍了DM驱动模型的原理。
    本文重点整理了几个数据结构和驱动示例讲解。
  • 4.2、DM驱动模型相关的数据结构
    DM模型主要依赖于下面四种数据结构:
    • 1)struct udevice,具有硬件设备的抽象, 和driver实例相关
      定义在include\dm\device.h中:
      /**
       * struct udevice - An instance of a driver
       *
       * This holds information about a device, which is a driver bound to a
       * particular port or peripheral (essentially a driver instance).
       *
       * A device will come into existence through a 'bind' call, either due to
       * a U_BOOT_DRVINFO() macro (in which case plat is non-NULL) or a node
       * in the device tree (in which case of_offset is >= 0). In the latter case
       * we translate the device tree information into plat in a function
       * implemented by the driver of_to_plat method (called just before the
       * probe method if the device has a device tree node.
       *
       * All three of plat, priv and uclass_priv can be allocated by the
       * driver, or you can use the auto members of struct driver and
       * struct uclass_driver to have driver model do this automatically.
       *
       * @driver: The driver used by this device
       * @name: Name of device, typically the FDT node name
       * @plat_: Configuration data for this device (do not access outside driver
       *	model)
       * @parent_plat_: The parent bus's configuration data for this device (do not
       *	access outside driver model)
       * @uclass_plat_: The uclass's configuration data for this device (do not access
       *	outside driver model)
       * @driver_data: Driver data word for the entry that matched this device with
       *		its driver
       * @parent: Parent of this device, or NULL for the top level device
       * @priv_: Private data for this device (do not access outside driver model)
       * @uclass: Pointer to uclass for this device
       * @uclass_priv_: The uclass's private data for this device (do not access
       *	outside driver model)
       * @parent_priv_: The parent's private data for this device (do not access
       *	outside driver model)
       * @uclass_node: Used by uclass to link its devices
       * @child_head: List of children of this device
       * @sibling_node: Next device in list of all devices
       * @flags_: Flags for this device DM_FLAG_... (do not access outside driver
       *	model)
       * @seq_: Allocated sequence number for this device (-1 = none). This is set up
       * when the device is bound and is unique within the device's uclass. If the
       * device has an alias in the devicetree then that is used to set the sequence
       * number. Otherwise, the next available number is used. Sequence numbers are
       * used by certain commands that need device to be numbered (e.g. 'mmc dev').
       * (do not access outside driver model)
       * @node_: Reference to device tree node for this device (do not access outside
       *	driver model)
       * @devres_head: List of memory allocations associated with this device.
       *		When CONFIG_DEVRES is enabled, devm_kmalloc() and friends will
       *		add to this list. Memory so-allocated will be freed
       *		automatically when the device is removed / unbound
       * @dma_offset: Offset between the physical address space (CPU's) and the
       *		device's bus address space
       */
      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_;
      #endif
      	int seq_;
      #if CONFIG_IS_ENABLED(OF_REAL)
      	ofnode node_;
      #endif
      #ifdef CONFIG_DEVRES
      	struct list_head devres_head;
      #endif
      #if CONFIG_IS_ENABLED(DM_DMA)
      	ulong dma_offset;
      #endif
      };
      
    • 2)struct driver,特定udevice的硬件驱动,包含了驱动的绑定、初始化、probe和卸载等函数。使用U_BOOT_DRIVER来注册。
      struct driver定义在include\dm\device.h中:
      /**
       * struct driver - A driver for a feature or peripheral
       *
       * This holds methods for setting up a new device, and also removing it.
       * The device needs information to set itself up - this is provided either
       * by plat or a device tree node (which we find by looking up
       * matching compatible strings with of_match).
       *
       * Drivers all belong to a uclass, representing a class of devices of the
       * same type. Common elements of the drivers can be implemented in the uclass,
       * or the uclass can provide a consistent interface to the drivers within
       * it.
       *
       * @name: Device name
       * @id: Identifies the uclass we belong to
       * @of_match: List of compatible strings to match, and any identifying data
       * for each.
       * @bind: Called to bind a device to its driver
       * @probe: Called to probe a device, i.e. activate it
       * @remove: Called to remove a device, i.e. de-activate it
       * @unbind: Called to unbind a device from its driver
       * @of_to_plat: Called before probe to decode device tree data
       * @child_post_bind: Called after a new child has been bound
       * @child_pre_probe: Called before a child device is probed. The device has
       * memory allocated but it has not yet been probed.
       * @child_post_remove: Called after a child device is removed. The device
       * has memory allocated but its device_remove() method has been called.
       * @priv_auto: If non-zero this is the size of the private data
       * to be allocated in the device's ->priv pointer. If zero, then the driver
       * is responsible for allocating any data required.
       * @plat_auto: If non-zero this is the size of the
       * platform data to be allocated in the device's ->plat pointer.
       * This is typically only useful for device-tree-aware drivers (those with
       * an of_match), since drivers which use plat will have the data
       * provided in the U_BOOT_DRVINFO() instantiation.
       * @per_child_auto: Each device can hold private data owned by
       * its parent. If required this will be automatically allocated if this
       * value is non-zero.
       * @per_child_plat_auto: A bus likes to store information about
       * its children. If non-zero this is the size of this data, to be allocated
       * in the child's parent_plat pointer.
       * @ops: Driver-specific operations. This is typically a list of function
       * pointers defined by the driver, to implement driver functions required by
       * the uclass.
       * @flags: driver flags - see DM_FLAGS_...
       * @acpi_ops: Advanced Configuration and Power Interface (ACPI) operations,
       * allowing the device to add things to the ACPI tables passed to Linux
       */
      struct driver {
             
             
      	char *name;
      	enum uclass_id id;
      	const struct udevice_id *of_match;
      	int (*bind)(struct udevice *dev);
      	int (
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值