简体   繁体   English

misc驱动程序和char驱动程序有什么区别?

[英]What is the difference between misc drivers and char drivers?

I'm reading about misc drivers in Linux, and I'm a little confused about the differences between them and char drivers. 我正在读Linux中的misc驱动程序,我对它们和char驱动程序之间的差异感到有些困惑。 One source, the Linux journal , writes: 一个来源, Linux期刊写道:

Alessandro tells us how to register a small device needing a single entry point with the misc driver. Alessandro告诉我们如何使用misc驱动程序注册需要单个入口点的小型设备。

Sometimes people need to write “small” device drivers, to support custom hacks—either hardware or software ones. 有时人们需要编写“小”设备驱动程序,以支持自定义黑客 - 硬件或软件。 To this end, as well as to host some real drivers, the Linux kernel exports an interface to allow modules to register their own small drivers. 为此,以及托管一些真正的驱动程序,Linux内核导出一个接口,允许模块注册自己的小驱动程序。 The misc driver was designed for this purpose. misc驱动程序是为此目的而设计的。

Ok, so from this I get that there's a simple driver (in this case with a single entry point), that's a misc driver. 好的,所以从这里我得到一个简单的驱动程序(在这种情况下有一个入口点),这是一个misc驱动程序。 Then another source, Essential Linux Device Drivers, states: 然后另一个源,Essential Linux设备驱动程序,指出:

Misc (or miscellaneous) drivers are simple char drivers that share certain common characteristics. 其他(或其他)驱动程序是具有某些共同特征的简单字符驱动程序。 Because misc drivers are char drivers, the earlier discussion on char driver entry points hold for misc drivers, too. 因为misc驱动程序是char驱动程序,所以早期关于char驱动程序入口点的讨论也适用于misc驱动程序。

Now this seems to say that misc drivers are just char drivers, but perhaps a subset of functions, and char drivers can have more than one entry point (such as an ioctl() or an open() or a read() call) 现在,这似乎是说,其它司机只是字符驱动,但也许一部分功能,而字符驱动可以有多个入口点(如一个ioctl()open()read()调用)

So, what, in Linux C coding terms, are the differences between a char and misc device driver? 那么,在Linux C编码术语中,char和misc设备驱动程序之间的区别是什么? (Besides the obvious major number assignment (10) for all misc drivers). (除了明显的所有misc驱动程序的主要编号(10))。 Is there a difference in supported entry points? 支持的入口点是否有区别? Is my assumption correct that misc device drivers only have a subset of what you can get in a full char device driver? 我的假设是否正确,misc设备驱动程序只有一个完整的char设备驱动程序可以获得的子集?

Edit : I thought you were talking about drivers/misc drivers, but I see you're refering to character drivers using misc_register (and all the API in drivers/char/misc.c ). 编辑 :我以为你在谈论drivers/misc驱动程序,但我看到你使用misc_register (以及drivers/char/misc.c所有API) misc_register字符驱动程序。 You should specify this in your question. 你应该在你的问题中指明这一点。

In this case, the misc API seems to make your life easier when you're writing a small character driver and do not want to need to allocate a new major number only to use one minor number, for example. 在这种情况下, misc API似乎可以让您在编写小型字符驱动程序时更轻松,并且不希望仅为了使用一个次要编号而分配新的主编号。 It simplifies things, but all the file operations are still available using the fops member of struct miscdevice . 它简化了一些事情,但所有文件操作仍然可以使用struct miscdevicefops成员。 The basic difference is you only get one minor number per misc device. 基本区别在于每个misc设备只能获得一个次要编号。

My previous, unrelated answer was, for the record: 我以前无关的答案是,记录:

Have a quick look at drivers/misc : you won't find any " misc core" out there. 快速浏览一下drivers/misc :你不会发现任何“ misc核心”。 This means: misc is not a device class; 这意味着: misc不是设备类; it's just a bunch of drivers that don't fit in any other category. 它只是一堆不适合任何其他类别的驱动程序。 Things like barometers, DACs, test suites and other strange things. 气压计,DAC,测试套件和其他奇怪的东西。

Look at the top of drivers/misc/Kconfig : 查看drivers/misc/Kconfig

#
# Misc strange devices
#

menu "Misc devices"

All the items in this Kconfig do not depend on any " misc core", but on other cores ( i2c , pci , tty , etc.). 此Kconfig中的所有项目都不依赖于任何“ misc核心”,而是依赖于其他核心( i2cpcitty等)。 Usually, when a driver is really using a driver core, you will see it in its Kconfig. 通常,当驱动程序真正使用驱动程序核心时,您将在其Kconfig中看到它。 For instance, pretty much all leds drivers ( drivers/leds ) depend on the leds class core and have this in their Kconfig node : 例如,几乎所有leds驱动程序( drivers/leds )都依赖于leds类核心并在其Kconfig节点中具有此功能

depends on LEDS_CLASS

Maybe misc drivers are all character drivers (I didn't check all of them), but something else would still work there, although it would probably be at the wrong place. 也许misc驱动程序都是字符驱动程序(我没有检查所有它们),但其他东西仍然可以在那里工作 ,虽然它可能在错误的地方。 I believe that lots of misc drivers could be moved to better places now... a veteran kernel hacker could confirm this. 我相信很多misc驱动程序现在可以转移到更好的地方......一位经验丰富的内核黑客可以证实这一点。

So, to answer your question: misc drivers do not have to be character drivers, so the two categories are completely unrelated. 所以,回答你的问题: misc驱动程序不一定是字符驱动程序,因此这两个类别完全不相关。 A misc driver brings nothing more than a character driver because a misc driver is, again, nothing special. misc驱动程序只带来一个字符驱动程序,因为misc驱动程序再一点也没什么特别之处。

Update : the Honeywell compass driver is a great example. 更新霍尼韦尔罗盘驱动器就是一个很好的例子。 It is small and straightforward. 它小巧而直接。

It communicates with the actual compass using I²C. 它使用I²C与实际罗盘进行通信。 This device won't show up as a character device, so forget about major number 10. It will, however, appear somewhere in Sysfs, under /sys/bus/i2c/devices , like all I²C devices do. 该设备不会显示为字符设备,因此请忘记主要编号10.然而,它将出现在Sysfs中的/sys/bus/i2c/devices ,就像所有I²C设备一样。 And you will see the Sysfs attributes it adds to its group, like heading0_input that will show the current compass direction when read. 您将看到它添加到其组中的Sysfs属性,例如heading0_input ,它将在读取时显示当前的罗盘方向。

So here you have it: a misc driver that's not a character driver. 所以在这里你拥有它:一个不是字符驱动程序的misc驱动程序。

Now this seems to say that misc drivers are just char drivers, but perhaps a subset of functions, and char drivers can have more than one entry point (such as an ioctl() or an open() or a read() call) 现在这似乎说misc驱动程序只是char驱动程序,但也许是函数的一个子集,而char驱动程序可以有多个入口点(例如ioctl()或open()或read()调用)

Yes,it just Charater driver, and Misc driver also have multiple entry point read(), write(), ioctl() (because in miscdevice 's structure already have filefile_operations structure) 是的,它只是Charater驱动程序,而Misc驱动程序也有多个入口点read(),write(),ioctl()(因为在miscdevice的结构中已经有了filefile_operations结构)

in my understanding, when we need to write a small driver (only have one entry point or some more (2,3,... entry points) <<< mean small driver) we should use misc driver. 在我的理解中,当我们需要编写一个小驱动程序(只有一个入口点或更多(2,3,...入口点)<<<意味着小驱动程序)我们应该使用misc驱动程序。 it will prevent waste of RAM if we register new Major Number. 如果我们注册新的主要号码,它将防止浪费RAM。

Now Since the kernel keeps a static table of device drivers, frivolous allocation of major numbers is rather wasteful of RAM. 现在由于内核保留了设备驱动程序的静态表,因此主要数字的无聊分配相当浪费RAM。 The Linux kernel, therefore, offers a simplified interface for simple drivers—those that will register a single entry point. 因此,Linux内核为简单的驱动程序提供了简化的接口 - 那些将注册单个入口点的驱动程序。 Note that, in general, allocating the whole name space of a major number to every device is beneficial. 注意,通常,将主要编号的整个名称空间分配给每个设备是有益的。 This allows the handling of multiple terminals, multiple serial ports and several disk partitions without any overhead in the kernel proper: a single driver takes care of all of them, and uses the minor number to differentiate. 这允许处理多个终端,多个串行端口和多个磁盘分区,而无需内核中的任何开销:单个驱动程序负责所有这些,并使用次要编号进行区分。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM