Linux 驱动程序和 device.h
我直接从制造商那里获得了一些适用于某些 canbus 硬件的 Linux 驱动程序,但它们已经过时了(至少对于我的内核而言),让我只能自己照顾自己。在经历了一些困难之后,我在编译中遇到了一个错误,但我似乎无法摆脱这个错误。
错误是这样的:
./src/esdcan_pci.c:353:9: error: ‘struct device’ has no member named ‘driver_data’
经过大量的互联网调查,我几乎确定它与我的内核 device.h 的头文件有关。我打开标头并查看了结构体,果然没有名为 driver_data 的成员。我不确定哪位成员是同等的,或者是否有一个。这是我的头文件中的结构版本:
struct device {
struct device *parent;
struct device_private *p;
struct kobject kobj;
const char *init_name; /* initial name of the device */
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;
#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 */
/* arch specific additions */
struct dev_archdata archdata;
#ifdef CONFIG_OF
struct device_node *of_node;
#endif
dev_t devt; /* dev_t, creates the sysfs "dev" */
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);
};
由于这是我第一次编译 Linux 驱动程序,我不确定我在看什么。有没有人在这方面有经验可以提供一些提示?谢谢。
I've got some Linux drivers for some canbus hardware direct from the manufacturer, but they're out of date (for my kernel at least), leaving me to fend for myself. After jumping through some hoops I'm down to a single error in compilation, but it's one I can't seem to shake.
The error is this:
./src/esdcan_pci.c:353:9: error: ‘struct device’ has no member named ‘driver_data’
After much internet sleuthing I'm almost sure it has to do with the header file for my kernel device.h. I've opened the header and taken a look at the struct, and sure enough, there is no member named driver_data. What I'm not sure about is what member would be the equivalent, or if there is one at all. Here's the version of the struct in my header file:
struct device {
struct device *parent;
struct device_private *p;
struct kobject kobj;
const char *init_name; /* initial name of the device */
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;
#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 */
/* arch specific additions */
struct dev_archdata archdata;
#ifdef CONFIG_OF
struct device_node *of_node;
#endif
dev_t devt; /* dev_t, creates the sysfs "dev" */
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);
};
Being that this is my first time compiling a linux driver, I'm not sure what I'm looking at. Does anyone have experience in this sort of area that might be able to drop some hints? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
驱动程序模型已切换为使用
void * dev_get_drvdata( const struct device *dev )
和void dev_set_drvdata( struct device *dev, void * data)
而不是直接操作 <代码>结构设备成员。您可以在include/linux/device.h
中找到这些函数的原型。几乎每个设备驱动程序都使用这些调用,因此您可以轻松找到示例。但需要注意的一件事是,多个子系统(包括 PCI)具有这些函数的子系统特定版本:
pci_get_drvdata()
。然而,这些只是dev_*
函数的包装。The driver model has switched to using
void * dev_get_drvdata( const struct device *dev )
andvoid dev_set_drvdata( struct device *dev, void * data)
rather than direct manipulation ofstruct device
members. You'll find the prototypes for these functions ininclude/linux/device.h
Almost every device driver uses these calls so you'll have no trouble finding examples.One thing to note though is that several subsystems (including PCI) have what look like subsystem-specific versions of these functions:
pci_get_drvdata()
. However, these are just wrappers around thedev_*
functions.