函数 platform_set_drvdata()

安装IC Complier 2(安装synposys的其他工具也可以来看看,因为殊途同归) 安装ICC2 阅读详情

Probe函数中定义的私有数据,是如何保存起来的呢?

方法之一就是呼叫 函数platform_set_drvdata().


下面看一下函数platform_set_drvdata()的实现,

static inline void platform_set_drvdata(struct platform_device *pdev,
					void *data)
{
	dev_set_drvdata(&pdev->dev, data);
}


int dev_set_drvdata(struct device *dev, void *data)
{
	int error;

	if (!dev->p) {
		error = device_private_init(dev);
		if (error)
			return error;
	}
	dev->p->driver_data = data;  <====此处,将私有数据指针Dev->p->driver_data
	return 0;
}


device结构体如下,从device->p的定义中看到,这个地址是用来保存driver的私有数据的

/**
 * struct device - The basic device structure
 * @parent:	The device's "parent" device, the device to which it is attached.
 * 		In most cases, a parent device is some sort of bus or host
 * 		controller. If parent is NULL, the device, is a top-level device,
 * 		which is not usually what you want.
 * @p:		Holds the private data of the driver core portions of the device.
 * 		See the comment of the struct device_private for detail.
 * @kobj:	A top-level, abstract class from which other classes are derived.
 * @init_name:	Initial name of the device.
 * @type:	The type of device.
 * 		This identifies the device type and carries type-specific
 * 		information.
 * @mutex:	Mutex to synchronize calls to its driver.
 * @bus:	Type of bus device is on.
 * @driver:	Which driver has allocated this
 * @platform_data: Platform data specific to the device.
 * 		Example: For devices on custom boards, as typical of embedded
 * 		and SOC based hardware, Linux often uses platform_data to point
 * 		to board-specific structures describing devices and how they
 * 		are wired.  That can include what ports are available, chip
 * 		variants, which GPIO pins act in what additional roles, and so
 * 		on.  This shrinks the "Board Support Packages" (BSPs) and
 * 		minimizes board-specific #ifdefs in drivers.
 * @power:	For device power management.
 * 		See Documentation/power/devices.txt for details.
 * @pm_domain:	Provide callbacks that are executed during system suspend,
 * 		hibernation, system resume and during runtime PM transitions
 * 		along with subsystem-level and driver-level callbacks.
 * @pins:	For device pin management.
 *		See Documentation/pinctrl.txt for details.
 * @numa_node:	NUMA node this device is close to.
 * @dma_mask:	Dma mask (if dma'ble device).
 * @coherent_dma_mask: Like dma_mask, but for alloc_coherent mapping as not all
 * 		hardware supports 64-bit addresses for consistent allocations
 * 		such descriptors.
 * @dma_parms:	A low level driver may set these to teach IOMMU code about
 * 		segment limitations.
 * @dma_pools:	Dma pools (if dma'ble device).
 * @dma_mem:	Internal for coherent mem override.
 * @archdata:	For arch-specific additions.
 * @of_node:	Associated device tree node.
 * @acpi_node:	Associated ACPI device node.
 * @devt:	For creating the sysfs "dev".
 * @id:		device instance
 * @devres_lock: Spinlock to protect the resource of the device.
 * @devres_head: The resources list of the device.
 * @knode_class: The node used to add the device to the class list.
 * @class:	The class of the device.
 * @groups:	Optional attribute groups.
 * @release:	Callback to free the device after all references have
 * 		gone away. This should be set by the allocator of the
 * 		device (i.e. the bus driver that discovered the device).
 *
 * At the lowest level, every device in a Linux system is represented by an
 * instance of struct device. The device structure contains the information
 * that the device model core needs to model the system. Most subsystems,
 * however, track additional information about the devices they host. As a
 * result, it is rare for devices to be represented by bare device structures;
 * instead, that structure, like kobject structures, is usually embedded within
 * a higher-level representation of the device.
 */
struct device {
	struct device		*parent;

	struct device_private	*p;

	struct kobject kobj;
	const char		*init_name; /* initial name of the device */
	const struct device_type *type;

	struct mutex		mutex;	/* mutex to synchronize calls to
					 * its driver.
					 */

	struct bus_type	*bus;		/* type of bus device is on */
	struct device_driver *driver;	/* which driver has allocated this
					   device */
	void		*platform_data;	/* Platform specific data, device
					   core doesn't touch it */
	struct dev_pm_info	power;
	struct dev_pm_domain	*pm_domain;

#ifdef CONFIG_PINCTRL
	struct dev_pin_info	*pins;
#endif

#ifdef CONFIG_NUMA
	int		numa_node;	/* NUMA node this device is close to */
#endif
	u64		*dma_mask;	/* dma mask (if dma'able device) */
	u64		coherent_dma_mask;/* Like dma_mask, but for
					     alloc_coherent mappings as
					     not all hardware supports
					     64 bit addresses for consistent
					     allocations such descriptors. */

	struct device_dma_parameters *dma_parms;

	struct list_head	dma_pools;	/* dma pools (if dma'ble) */

	struct dma_coherent_mem	*dma_mem; /* internal for coherent mem
					     override */
#ifdef CONFIG_CMA
	struct cma *cma_area;		/* contiguous memory area for dma
					   allocations */
#endif
	/* arch specific additions */
	struct dev_archdata	archdata;

	struct device_node	*of_node; /* associated device tree node */
	struct acpi_dev_node	acpi_node; /* associated ACPI device node */

	dev_t			devt;	/* dev_t, creates the sysfs "dev" */
	u32			id;	/* device instance */

	spinlock_t		devres_lock;
	struct list_head	devres_head;

	struct klist_node	knode_class;
	struct class		*class;
	const struct attribute_group **groups;	/* optional groups */

	void	(*release)(struct device *dev);
	struct iommu_group	*iommu_group;
};

device_private的结构体如下,指针driver_data是用来保存driver的私有数据的。

/**
 * struct device_private - structure to hold the private to the driver core portions of the device structure.
 *
 * @klist_children - klist containing all children of this device
 * @knode_parent - node in sibling list
 * @knode_driver - node in driver list
 * @knode_bus - node in bus list
 * @deferred_probe - entry in deferred_probe_list which is used to retry the
 *	binding of drivers which were unable to get all the resources needed by
 *	the device; typically because it depends on another driver getting
 *	probed first.
 * @driver_data - private pointer for driver specific info.  Will turn into a
 * list soon.
 * @device - pointer back to the struct class that this structure is
 * associated with.
 *
 * Nothing outside of the driver core should ever touch these fields.
 */
struct device_private {
	struct klist klist_children;
	struct klist_node knode_parent;
	struct klist_node knode_driver;
	struct klist_node knode_bus;
	struct list_head deferred_probe;
	void *driver_data;
	struct device *device;
};





保姆级教程:用Cesium的Primitive API实现火箭发射全流程动画(含代码避坑) 本文详细介绍了如何使用Cesium的Primitive API实现火箭发射全流程动画,包括模型控制、关节动画和精细时序管理。通过实战代码示例和性能优化技巧,帮助开发者高效构建高复杂度航天仿真系统,显著提升三维可视化效果与运行效率。 阅读详情

相关推荐

Swift Package Manager (SPM) 创建并集成本地库

Swift Package Manager (SPM) 在macOS 项目中创建并集成的完整步骤

征战无悔人生 1428

驱动开发笔记——platform_set_drvdata分析

函数static inline void platform_set_drvdata(struct platform_device *pdev, void *data)目的存储用户在probe()中主动申请的内存区域的指针以防止丢失,static inline void *platform_get_drvdata(const struct platform_device *pdev)则是将其取出。

剑林园 1万+

Python 爬取新浪财经 7x24(1): 下载数据

前言 最近在做一个需要很多财经数据的项目。于是想到可不可以通过爬虫来解决(尝试白嫖)。 提供财经数据的网站有很多个,其中比较靠谱和更新比较及时的应该是新浪7x24 live数据。 http://finance.sina.com.cn/7x24/?tag=0 这个问题有一定的难度,因为这个网页是动态加载的。每一次只会加载部分数据,而只有拉到底部才可以加载新的数据。 于是乎,我们要做的事情是: 下载数据 保存到数据库 本篇介绍如何下载数据。 代码 闲言少叙书归正文,代码的实现如下: import reque

ZJ_11701的博客 2908

platform_set_drvdata

原文地址: http://blog.chinaunix.net/uid-25932176-id-3063323.html 驱动中常用到platform_set_drvdata 和 platform_get_drvdata这两个函数,用于保存局部变量: include/linux/platform_device.h中: static inline void *pla

wangpeiyao5566的专栏 2289

人脸情绪识别(使用深度学习和OpenCV)

基于opencv与深度学习的人脸情绪识别系统

mx0390304的博客 8254

嵌入式工程师必学(9):USB 3.0协议理解

USB3.0和USB2.0相比,在线缆上从4根线(Vbus、GND、D+、D-)变为了8根线(Vbus、GND、D+、D-、SSRX+\SSRX-\SSTX+\SSTX-),可见增加的4根线都是和超速相关的,新增加的超速有两类,分别为:超速Gen1(5.0Gbps),超速+Gen2(10Gbps),还兼容USB2.0的3类速率:low-speed(1.5Mbps),full-speed(12Mbps),andhigh-speed(480Mbps)。从设计可以看出,USB3....

码农17年的博客 1万+

2023-07-20 linux platform_set_drvdata、platform_get_drvdata和i2c_set_clientdata i2c_get_clientdata 学习

3.4 再来看看platform_get_drvdata 和 platform_set_drvdata 的代码,里面会调用dev_get_drvdata(dev),有时候再驱动里面也可以直接用。4.3 看看 i2c_set_clientdata i2c_get_clientdata 里面 会调用dev_set_drvdata dev_get_drvdata。3.3 看上面会用到to_platform_device ,其实是调用container_of 获取device 指针。

海月汐辰 1801

第18章:AI辅助Debug——如何将错误日志交给AI定位根因

> - 如何将错误日志、堆栈、代码片段组合发给AI,快速定位问题根因 > - AI分析错误的3个核心维度:环境差异、逻辑缺陷、并发竞态 > - 常见错误的AI分析Prompt模板(前端报错、后端异常、数据库错误、网络请求失败) > - 一个完整的调试案例:从用户报错到找出问题根源的全过程 > - 我如何用AI把平均调试时间从2小时缩短到20分钟

sfishfly的博客 44

Platform 设备驱动:platform_get_drvdata 与 platform_set_drvdata

Platform 设备驱动:dev_get_platdata 与 dev_set_platdata

qq_23174771的博客 1422

解决anaconda占用C盘空间过多问题

anaconda就算安装在其他盘,默认会把索引、锁定文件、压缩包等都放到系统盘(C盘),我用了两年,占用30GB。 1. 卸载不用的虚拟环境 查看已安装的虚拟环境 conda env list 卸载不用的、过期的虚拟环境 conda remove -n (要卸载的环境的名字) --all 2. 删除索引缓存、锁定文件、未使用过的包和tar包 conda clean -a 清理完之后,删除了15GB,还剩15GB,舒服了 ...

沉迷单车的追风少年 3万+

基于DSIFT多尺度图像融合的MATLAB代码

多尺度图像融合是一种常用的图像处理技术,它可以将具有不同尺度和空间频率特征的图像融合成一幅更具信息丰富度和视觉效果的图像。DSIFT算法是一种基于SIFT算法的改进版本,它在提取图像特征时采用了密集采样的方法,能够有效地提取图像的局部特征。多尺度图像融合基于DSIFT算法的思想,通过在不同尺度下提取图像的DSIFT特征,并将这些特征进行融合,得到最终的融合图像。然后,通过DSIFT算法提取了两幅图像的特征。通过运行上述代码,我们可以在MATLAB中实现基于DSIFT多尺度图像融合的算法,并观察到融合结果。

IELLQUI9的博客 184

驱动开发笔记--platform_set_drvdata & platform_get_drvdata分析

概述 在用到Linux设备驱动的platform框架时,常常会遇到两个函数platform_get_drvdata和platform_set_drvdata。通常,会在驱动的probe函数中获取device的相关信息,然后使用platform_set_drvdata进行保存局部变量。在其他函数中要用到时(比如remove),通过platform_get_drvdata来获取。 函数定义 include\linux\platform_device.h: static inline void platfo

nancy的专栏 2321

Python量化- Black-Litterman 模型

​​​​​​​Black-Litterman 模型由 Fischer Black 和 Robert Litterman 于 1992 年开发,采用贝叶斯方法进行资产配置。该模型通过结合先前的回报估计(可以从多个来源得出)并结合投资者对未来回报的独特预期来优化分配权重。

探索人工智能领域 1031

platform_set_drvdata() platform_get_drvdata()

内核模块一般在probe()函数中动态申请内存来使用,这种情况下,这个指针就得有个位置存储防止丢失, 所以内核设计得在platform_device结构体中,保留了一个指针,就是为了这样的驱动编写方式。 所以我们一般在probe()函数中 动态申请设备结构体,并初始化它,然后使用platform_set_drvdata()将其保存到platform_device中, 在需要使用的时候再使用

烟台 嵌入式产品开发 1万+

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

Linux点滴-platform_set_drvdata 和 platform_get_drvdata

ndev是我们在probe函数中定义的局部变量,如果我想在其他地方使用它怎么办呢? 这就需要把它保存起来。内核提供了这个方法,使用函数platform_set_drvdata()可以将ndev保存成平台总线设备的私有数据。以后再要使用它时只需调用platform_get_drvdata()就可以了。

anne20072010的专栏 2212

贝叶斯统计 [韦来生编]

贝叶斯(Bayes)统计是近几十年来迅速发展起来的数理统计的一个重要分支。贝叶斯方法与经典统计方法的主要不同之处是进行统计推断时除了利用样本信息外,还要利用参数的先验信息,因此可以提高统计推断或统计决策的效果。它在经济、金融、生物、医学、自然科学和社会科学等许多领域具有广泛的应用。贝叶斯方法的研究已渗透到了统计学的几乎所有领域。作者在给中国科学技术大学概率论与数理统计专业本科生开设的“数理统计”课程中有一章专门讲授“贝叶斯方法和统计决策理论”,近十年来也给中国科学技术大学概率统计专业研究生开设过几次“贝叶斯分析”课。本书是在对过去讲稿的内容作了适当的增减和调整的基础上完成的。  本书共分六章。第1章是绪论,介绍了贝叶斯统计的若干基本概念,同时对必要的数理统计的基础知识有重点地作了回顾。第二章介绍了确定先验分布的若干可供选择的方法。第三章介绍了几类常见统计模型参数的后验分布的主要结果和计算方法。第四章和第五章分别介绍了“贝叶斯统计推断”和“贝叶斯统计决策”的内容。第六章介绍了贝叶斯统计计算的若干方法,包括蒙特卡洛方法和马尔可夫链蒙特卡洛(MCMC)方法以及相关统计软件的简介。本书的每一章附右大量的例题和习题,书末附有常用的几个表格和部分习题解答供读者查用。  大约可在54学时内讲授本书的第1章至第六章的主要内容,教师可根据学时需要选讲本书第1章至第六章的部分内容。书中标“*”号的章节可略去不讲,留给读者作为阅读材料。第六章例题中的R代码和部分例题的数据文件等可从作者个人主页下载。  作者在编写本书的过程中参考了J.O.Berger教授的《统计决策论及贝叶斯分析》和茆诗松教授编写的《贝叶斯统计》等书中的一些内容,以及《贝叶斯分析》一书中由张伟平博士编写的有关贝叶斯统计计算的一些内容。在此表示衷心感谢。  本书编写准备过程中,中国科学技术大学统计与金融系的几个研究生帮助完成了本书部分中文的录入和排版,作者对他们的辛勤工作表示真诚的感谢。高等教育出版社为本书的出版给予了大力支持。在此一并致谢。

platform_set_drvdata 和 platform_get_drvdata

ndev是我们在probe函数中定义的局部变量,如果我想在其他地方使用它怎么办呢? 这就需要把它保存起来。内核提供了这个方法,使用函数platform_set_drvdata()可以将ndev保存成平台总线设备的私有数据。 以后再要使用它时只需调用platform_get_drvdata()就可以了。 转载于:https://www.cnblogs.com/Ph-one/p/686...

150

platform_set_drvdata的源码分析

使用函数platform_set_drvdata()可以将radio保存成平台总线设备的私有数据。以后再要使用它时只需调用platform_get_drvdata()就可以了 struct marimba_fm_platform_data *tavarua_pdata; struct tavarua_device *radio; int retval; int i; FMDBG...

weixin_33682719的博客 173

platform_set_drvdata()/platform_get_drvdata()/container_of()

platform_set_drvdata(struct platform_device *pdev, void *data) platform_get_drvdata(const struct platform_device *pdev): 驱动中常用到platform_set_drvdata 和 platform_get_drvdata这两个函数,用于保存局部变量: inc

angle_birds的专栏 3345

platform_set_drvdata() platform_get_drvdata()

platform_set_drvdata 和 platform_get_drvdata 驱动中常用到platform_set_drvdata 和 platform_get_drvdata这两个函数,用于保存局部变量: include/linux/platform_device.h中: static inline void *platform_get_drvdata(const s...

ll148305879的博客 708

platform_set_drvdata和platform_get_drvdata用法【转】

本文转载自:http://www.cnblogs.com/wangxianzhen/archive/2013/04/09/3009530.html 在用到Linux设备驱动的platform框架时,常常会遇到两个函数platform_get_drvdata和 platform_set_drvdata。通常,会在驱动的probe函数中获取device的相关信息,然后使用 platform...

301

platform_set_drvdata/platform_get_drvdata

platform_set_drvdata(struct platform_device *pdev, void *data) platform_get_drvdata(const struct platform_device *pdev): 驱动中常用到platform_set_drvdata 和 platform_get_drvdata这两个函数,用于保存局部变量: inc

技术无捷径,一步一脚印 749

platform_set_drvdata()/platform_get_drvdata()/container_of()【转】

本文转载自:http://blog.csdn.net/angle_birds/article/details/8443695 platform_set_drvdata(struct platform_device *pdev, void *data) platform_get_drvdata(const struct platform_device *pdev): 驱动中常用到pl...

290

linux驱动platform_set_drvdata 和 platform_get_drvdata这两个函数

驱动中常用到platform_set_drvdata 和 platform_get_drvdata这两个函数,用于保存局部变量: include/linux/platform_device.h中: static inline void *platform_get_drvdata(const struct platform_device *pdev) {         return

lhl161123的专栏 5221
上一篇: 函数 devm_kzalloc()
下一篇: 函数dev_get_drvdata()
jgw2008
博客等级 码龄23年 651粉丝 145原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值