1

我正在将平台驱动程序代码移植到 PCIe 变体,但我不明白为什么我没有/dev/显示条目。修改后的平台驱动代码:

static dev_t first;
static struct class * class;
ATTRIBUTE_GROUPS(my);
static int __init my_pci_init(void)
{

    int ret;
    /* Create a class entry in sysfs */
    if ((class = class_create(THIS_MODULE, "test_driver")) == NULL) {
        pr_err("Couldn't create 'struct class' structure.");
        ret = -ENODEV;
        goto exit;
    }
    class->dev_groups = my_groups;
    /* Create the /dev/ file system entry */
    /* return value ignored: there's a 'struct class' to 'struct device' mapping */
    if (device_create(class, NULL, first, NULL, KBUILD_MODNAME) == NULL) {
        pr_err("Couldn't create entry in '/dev/' file system.");
        ret = -ENODEV;
        goto exit;
    } else {
        pr_info("Created a /dev/ entry.");
    }

    if ((ret = pci_register_driver(&pci_driver)) < 0) {
        pr_err("Couldn't register pci driver.");
    }
 exit:
    if (ret < 0) {
        my_pci_exit();
        pr_err(" ret = %d", ret);
    }
    return ret;
}

module_init(my_pci_init);

如果模块名称是“cz_tdm”,我希望上面的代码会创建一个条目/dev/cz_tdm。至少在我将其编译为平台驱动程序时是这样。

驱动程序枚举得很好,输出lspci显示驱动程序已加载并仔细阅读sysfs显示我的所有属性/sys/devices/virtual/...都在我期望的位置。

是什么赋予了?

4

1 回答 1

2

哎呀。

因为它也不应该。对代码的过度删除删除了这个必要的元素:

/* Add the char device to the system. */
cdev_init(&cdev, &fops);
if ((ret = cdev_add(&cdev, first, DEV_MINOR_NUMBER_COUNT)) < 0) {
    pr_err("Couldn't add device to system: %d", ret);
    ret = -ENODEV;
    goto exit;
}
于 2014-10-08T17:06:37.160 回答