查找struct device *dev
2017-06-22 11:53
211 查看
在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查找范围更广一些.
相关文章推荐
- __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev)
- struct device dev;&nbs…
- int device_register(struct device *dev)
- struct device 中的dev_id哪里去了…
- struct device *device_create(struct class *class, struct device *parent, dev_t devt, void *drvdata,
- struct device 中的dev_id哪里去了…
- struct device *dev
- struct clk *clk_get(struct device *dev, const char *id)
- s3c2410_lcd & frame buffer 驱动分析 int __init s3c2410fb_probe(struct device *dev) { struct s3c2410f
- int s3c24xx_serial_probe(struct platform_device *dev,
- Linux Kernel设备驱动模型之 struct device_type
- 如何查找dev目录下磁盘设备的iscsi来源
- Linux Kernel设备驱动模型之struct device_private
- 如何查找dev目录下磁盘设备的iscsi来源
- class_create(),class_device_create()创建/dev/xxx 名字
- 关于struct device_driver结构中的probe探测函数的调用(内核版本:2.6.29)
- struct net_device网络设备结构体详解
- mount: block device /dev/cdrom is write-protected, mounting read-only
- Unable to open log device '/dev/log/main&': No such file or directory
- struct usb_device_id