我需要获得一个指向在 linux 中注册的特定设备的指针。简而言之,此设备代表 mii_bus
目的。问题是这个设备似乎不属于总线(它的 dev->bus
是 NULL
)所以我不能使用例如功能 bus_for_each_dev
.然而,该设备由开放固件层注册,我可以看到相关的 of_device
(这是我感兴趣的设备的父级)在 /sys/bus/of_platform
.我的设备也在 class
中注册所以我可以在 /sys/class/mdio_bus
中找到它.现在的问题:
of_device
的指针来获取指针。那是我们想要的设备的父级吗? 任何其他建议都会非常有用!谢谢你们。
最佳答案
我找到了方法。我简要解释一下,也许它可能有用。我们可以使用的方法是 device_find_child
.该方法将指向实现比较逻辑的函数的指针作为第三个参数。如果函数在使用特定设备作为第一个参数调用时返回不为零,device_find_child
将返回该指针。
#include <linux/device.h>
#include <linux/of_platform.h>
static int custom_match_dev(struct device *dev, void *data)
{
/* this function implements the comaparison logic. Return not zero if device
pointed by dev is the device you are searching for.
*/
}
static struct device *find_dev()
{
struct device *ofdev = bus_find_device_by_name(&of_platform_bus_type,
NULL, "OF_device_name");
if (ofdev)
{
/* of device is the parent of device we are interested in */
struct device *real_dev = device_find_child(ofdev,
NULL, /* passed in the second param to custom_match_dev */
custom_match_dev);
if (real_dev)
return real_dev;
}
return NULL;
}
关于linux-kernel - 在 linux 中获取指向结构设备的指针的更简洁方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7636801/