[英]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: 我偶然发现了以下两种方法,并且想知道哪种方法在可持续性和用户可访问性方面更好:
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.