Linux驱动程序和device.h

时间:2011-04-13 13:47:16

标签: c linux-kernel drivers

我有一些直接来自制造商的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驱动程序,我不确定我在看什么。有没有人有这方面的经验,可能会有一些提示?谢谢。

1 个答案:

答案 0 :(得分:5)

驱动程序模型已切换为使用void * dev_get_drvdata( const struct device *dev )void dev_set_drvdata( struct device *dev, void * data),而不是直接操纵struct device成员。您将在include/linux/device.h中找到这些函数的原型。几乎每个设备驱动程序都使用这些调用,因此您可以轻松找到示例。

有一点需要注意的是,有几个子系统(包括PCI)具有这些功能的子系统特定版本:pci_get_drvdata()。但是,这些只是dev_*函数的包装。