Linux 平台驱动程序和普通设备驱动程序有什么区别? [英] What is the difference between a Linux platform driver and normal device driver?

查看:80
本文介绍了Linux 平台驱动程序和普通设备驱动程序有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之前我认为:

  • 平台驱动程序适用于片上设备.
  • 普通设备驱动程序适用于那些与处理器芯片接口的设备.

在遇到一个 i2c 驱动程序之前...但是在这里,我正在阅读定义为平台驱动程序的多功能 i2c 驱动程序.我已经通过 https://www.kernel.org/doc/文档/驱动程序模型/平台.txt.但是对于如何定义驱动程序,例如片上设备和接口设备,仍然没有明确的想法得出结论.

请人解释一下.

解决方案

您的参考资料很好,但缺乏对什么是平台设备的定义.LWN 上有一个.我们可以从这个页面学到什么:

  1. 平台设备本质上是不可发现的,即硬件不能对软件说嘿!我在场!".典型的例子是 i2c 设备,kernel/Documentation/i2c/instantiating-devices 状态:

    <块引用>

    与 PCI 或 USB 设备不同,I2C 设备不会在硬件级别(在运行时)进行枚举.相反,软件必须知道(在编译时)每个 I2C 总线段上连接了哪些设备.所以 USB 和 PCI 不是平台设备.

  2. 平台设备与驱动程序通过匹配名称

  3. 平台设备应在系统启动期间尽早注册.因为它们通常对系统的其余部分(平台)及其驱动程序至关重要.

所以基本上,它是平台设备还是标准设备?"的问题更多是关于它使用哪种总线的问题.要使用特定平台设备,您必须:

  1. 注册将管理此设备的平台驱动程序.它应该定义一个唯一名称,
  2. 注册您的平台设备,定义与驱动程序相同的名称.

<块引用>

平台驱动程序适用于片上设备.

不正确(理论上,但在实践中是正确的).i2c 设备不是片上设备,而是平台设备,因为它们是不可发现的.我们也可以考虑片上设备,它们是普通设备.示例:现代 x86 处理器上的集成 PCI GPU 芯片.它是可发现的,因此不是平台设备.

<块引用>

普通设备驱动程序用于那些与处理器芯片接口的驱动程序.在遇到一个 i2c 驱动程序之前.

不是真的.许多普通设备连接到处理器,但不通过 i2c 总线.示例:USB 鼠标.

在你的情况下,看看 drivers/usb/host/ohci-pnx4008.c,这是一个 USB 主机控制器平台设备(这里USB 主机控制器是不可发现的,而将连接到它的 USB 设备是).它是由板文件(arch/arm/mach-pnx4008/core.c:pnx4008_init)注册的平台设备.在它的探测函数中,它使用 i2c_register_driver 将其 i2c 设备注册到总线.我们可以推断 USB 主机控制器芯片组通过 i2c 总线 CPU 通信.

为什么是那种架构?因为一方面,这个设备可以被认为是一个裸 i2c 设备,为系统提供一些功能.另一方面,它是一个支持 USB 主机的设备.它需要注册到 USB 堆栈 (usb_create_hcd).因此,仅探测 i2c 是不够的.查看Documentation/i2c/instantiating-devices.

Earlier I had assumed that :

  • Platform driver is for those devices that are on chip.
  • Normal device driver are for those that are interfaced to the processor chip.

Before coming across one i2c driver... But here, I am reading through multi function i2c driver defined as platform driver. I had gone through https://www.kernel.org/doc/Documentation/driver-model/platform.txt. But still could not get clear idea to come to an conclusion on how to define drivers, like for both onchip as well interfaced devices.

Please somebody explain.

解决方案

Your references are good but lack a definition of what is a platform device. There is one on LWN. What we can learn from this page:

  1. Platform devices are inherently not discoverable, i.e. the hardware cannot say "Hey! I'm present!" to the software. Typical examples are i2c devices, kernel/Documentation/i2c/instantiating-devices states:

    Unlike PCI or USB devices, I2C devices are not enumerated at the hardware level (at run time). Instead, the software must know (at compile time) which devices are connected on each I2C bus segment. So USB and PCI are not platform devices.

  2. Platform devices are bound to drivers by matching names,

  3. Platform devices should be registered very early during system boot. Because they are often critical to the rest of the system (platform) and its drivers.

So basically, the question "is it a platform device or a standard device?" is more a question of which bus it uses. To work with a particular platform device, you have to:

  1. register a platform driver that will manage this device. It should define a unique name,
  2. register your platform device, defining the same name as the driver.

Platform driver is for those devices that are on chip.

Not true (in theory, but true in practice). i2c devices are not onChip, but are platform devices because they are not discoverable. Also we can think of onChip devices which are normal devices. Example: an integrated PCI GPU chip on a modern x86 processor. It is discoverable, thus not a platform device.

Normal device driver are for those that are interfaced to the processor chip. before coming across one i2c driver.

Not true. Many normal devices are interfaced to the processor, but not through an i2c bus. Example: a USB mouse.

[EDIT] In your case, have a look to drivers/usb/host/ohci-pnx4008.c, which is a USB host controller platform device (Here the USB host controller is not discoverable, whereas USB devices, which will connect to it, are). It is a platform device registered by the board file (arch/arm/mach-pnx4008/core.c:pnx4008_init). And within its probe function, it registers its i2c device to the bus with i2c_register_driver. We can infer that the USB Host controller chipset talks to the CPU through an i2c bus.

Why that architecture? Because on one hand, this device can be considered a bare i2c device providing some functionalities to the system. On the other hand, it is a USB Host capable device. It needs to register to the USB stack (usb_create_hcd). So probing only i2c will be insufficient. Have a look to Documentation/i2c/instantiating-devices.

这篇关于Linux 平台驱动程序和普通设备驱动程序有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆