查找struct device *dev
来源:互联网 发布:淄博网络推广哪家好 编辑:程序博客网 时间:2024/06/07 00:09
在driver中经常要找到另外一个struct device *dev。这时候有两种办法,一种是根据这个device所在的class查找
例如下例。即调用class_find_device
static int __ae_match(struct device *dev, const void *data)
{
struct hnae_ae_dev *hdev = cls_to_ae_dev(dev);
if (dev_of_node(hdev->dev))
return (data == &hdev->dev->of_node->fwnode);
else if (is_acpi_node(hdev->dev->fwnode))
return (data == hdev->dev->fwnode);
dev_err(dev, "__ae_match cannot read cfg data from OF or acpi\n");
return 0;
}
static struct hnae_ae_dev *find_ae(const struct fwnode_handle *fwnode)
{
struct device *dev;
WARN_ON(!fwnode);
dev = class_find_device(hnae_class, NULL, fwnode, __ae_match);
return dev ? cls_to_ae_dev(dev) : NULL;
}
第二中是通过bus来查找,即调用bus_find_device
static int hns_roce_node_match(struct device *dev, void *fwnode)
{
return dev->fwnode == fwnode;
}
static struct
platform_device *hns_roce_find_pdev(struct fwnode_handle *fwnode)
{
struct device *dev;
/* get the 'device'corresponding to matching 'fwnode' */
dev = bus_find_device(&platform_bus_type, NULL,
fwnode, hns_roce_node_match);
/* get the platform device */
return dev ? to_platform_device(dev) : NULL;
}
很明显通过class查找效率会高一点,通过bus查找范围更广一些.
例如下例。即调用class_find_device
static int __ae_match(struct device *dev, const void *data)
{
struct hnae_ae_dev *hdev = cls_to_ae_dev(dev);
if (dev_of_node(hdev->dev))
return (data == &hdev->dev->of_node->fwnode);
else if (is_acpi_node(hdev->dev->fwnode))
return (data == hdev->dev->fwnode);
dev_err(dev, "__ae_match cannot read cfg data from OF or acpi\n");
return 0;
}
static struct hnae_ae_dev *find_ae(const struct fwnode_handle *fwnode)
{
struct device *dev;
WARN_ON(!fwnode);
dev = class_find_device(hnae_class, NULL, fwnode, __ae_match);
return dev ? cls_to_ae_dev(dev) : NULL;
}
第二中是通过bus来查找,即调用bus_find_device
static int hns_roce_node_match(struct device *dev, void *fwnode)
{
return dev->fwnode == fwnode;
}
static struct
platform_device *hns_roce_find_pdev(struct fwnode_handle *fwnode)
{
struct device *dev;
/* get the 'device'corresponding to matching 'fwnode' */
dev = bus_find_device(&platform_bus_type, NULL,
fwnode, hns_roce_node_match);
/* get the platform device */
return dev ? to_platform_device(dev) : NULL;
}
很明显通过class查找效率会高一点,通过bus查找范围更广一些.
阅读全文
0 0
- 查找struct device *dev
- struct device *dev
- int device_register(struct device *dev)
- struct clk *clk_get(struct device *dev, const char *id)
- struct device dev;&nbs…
- s3c2410_lcd & frame buffer 驱动分析 int __init s3c2410fb_probe(struct device *dev) { struct s3c2410f
- struct device
- struct device
- struct device
- struct device浅析
- struct device 结构
- struct device结构体(
- struct device结构体
- Device /dev/ttyS0 is locked.
- "Device /dev/ttyS? is locked."
- "Device /dev/ttyS? is locked."
- Device /dev/ttyS0 is locked.
- "Device /dev/ttyS? is locked."
- 算法导论14.3 -区间树
- 【记录】git命令行初用记录
- Opencv学习之霍夫变换
- [Unity&接口]建立管理时间速度tiemSpeed的控制脚本
- 设计模式之六大原则(转载)
- 查找struct device *dev
- hibernate对数据的增删改查
- 'chromedriver' executable needs to be in PATH.
- MySQL数据库事务基本操作
- 第一次使用Android Studio时你应该知道的一切配置(三):gradle项目构建
- iOS 读取相册二维码
- 偶尔用到的方法
- unity UGUI实现卡片椭圆方向滚动
- VMWARE 桥接和NAT模式的区别