简体   繁体   English

用多个参数访问linux char驱动程序的实现

[英]Implementation of linux char driver with multiple parameters to access

I am writing a simple char driver which accesses a PCI card. 我正在编写一个访问PCI卡的简单char驱动程序。 It is registered to sysfs with the help of a new class and accessible under /dev/foodev . 它借助于新类在sysfs中注册,并且可以在/dev/foodev下访问。 Using standard file operations I can perform simple read and write operations to the device. 使用标准文件操作,我可以对设备执行简单的读取和写入操作。

My problem: I have multiple parameters stored at different addresses on the card (version, status, control, ...) which I would like access independently. 我的问题:我想将多个参数存储在卡上的不同地址(版本,状态,控件等)上,这些参数需要独立访问。 Currently having only one read and one write function I therefore have to change the address every time again in the driver code. 因此,当前只有一个读和一个写功能,因此我不得不每次在驱动程序代码中再次更改地址。 Obviously there is a more convenient way to implement this. 显然,有一种更方便的方法可以实现此目的。 I stumbled about the two following approaches and was wondering which is the better one in terms of sustainability and user accessibility: 我偶然发现了以下两种方法,并且想知道哪种方法在可持续性和用户可访问性方面更好:

  • Using ioctl commands setting the address/parameter before an access. 使用ioctl命令在访问之前设置地址/参数。
  • Having the device already nicely set up in udev using multiple attributes ( device_create_file() ) of which the user than just can write/read from different "files": 使用多个属性( device_create_file() )在udev中已经很好地设置了设备,而用户不仅可以从不同的“文件”中写入/读取这些属性,还可以:

    /dev/foodev ../version ../status ../control

我认为您应该看一下PCI框架来实现驱动程序。

Don't (mis)use ioctls; 不要(滥用)ioctl; you'll have race conditions. 您将拥有比赛条件。 Use the attributes as files. 使用属性作为文件。 That scheme is already used in sysfs. 该方案已在sysfs中使用。 EG look at GPIO LEDs and keys. EG看一下GPIO LED和按键。 – sawdust - 锯末

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Char Driver Linux:file_operations 读写的正确实现是什么? 需要进行哪些偏移检查? - Char Driver Linux: What is the correct implementation of file_operations read and write? What are the offset checks needs to be made? 向linux char设备驱动写长? - Write long to linux char device driver? Linux设备驱动程序访问控制 - Linux Device Driver Access Control Linux设备驱动程序:是否可以将char *传递给unlocked_ioctl? - Linux Device Driver: Is it possible to pass a char* to unlocked_ioctl? Linux内核char驱动程序写调用未按预期工作 - Linux kernel char driver write call is not working as expected Linux 设备驱动程序:二进制 &lt;&lt; 的无效操作数(具有 char * 和 int) - Linux device driver: invalid operands to binary << (have char * and int) 在Linux上为一个简单的char驱动程序在device_create()上失败 - Debuging a simple char driver in Linux failing on device_create() Linux内核链表实现的list_entry()中的(char *)强制转换 - the (char *) cast in list_entry() of the Linux Kernel linked list implementation 在Linux PCI驱动程序中向设备添加多个属性 - Adding multiple attributes to a device in a Linux PCI driver 为什么ififd的pci linux实现使用“ platform_driver”而不是“ pci_driver”? - Why is the pci linux implementation for ififd using “platform_driver” instead of “pci_driver”?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM