简体   繁体   English

LInux 设备驱动分层混淆

[英]LInux Device Driver Layering Confusion

I have recently been reading about Linux Driver and Device Model.我最近一直在阅读有关 Linux 驱动程序和设备 Model 的信息。 I wanted to understand how the following works in linux in the driver subsystem.我想了解驱动子系统中 linux 中的以下工作原理。 So lets say my device tree looks as follows所以可以说我的设备树如下所示

在此处输入图像描述

To be concrete lets assume Bus1 is a PCI bus, Bus2 is ISA and Bus3 is USB.具体来说,假设 Bus1 是 PCI 总线,Bus2 是 ISA,Bus3 是 USB。 Buses are connected with each other using bridges.公共汽车使用桥梁相互连接。

Linux will identify this device tree through the enumeration process and through enumeration and probing mechanism suitable usb driver for terminal device would be identified. Linux 将通过枚举过程识别此设备树,并通过枚举和探测机制识别适合终端设备的 usb 驱动程序。

Now lets assume a Tx operation to this terminal device.现在让我们假设对该终端设备进行 Tx 操作。 The terminal device usb driver would end up doing a urb_submit(dev, write_buffer).终端设备 usb 驱动程序最终会执行 urb_submit(dev, write_buffer)。

My question is in order for the URB to reach the terminal device, theoretically it would have to be enveloped in Bus2 and Bus1 envelopes.我的问题是为了让 URB 到达终端设备,理论上它必须被包裹在 Bus2 和 Bus1 信封中。 So theoretically speaking the outgoing packet has to look something like this所以从理论上讲,传出数据包必须看起来像这样

在此处输入图像描述

So at some after the urb_submit happens in the driver, does some kernel code walk up the device tree structure and invoke the bus drivers in order (bus 2 driver and then bus 1 driver) to create this envelope structure.因此,在驱动程序中发生 urb_submit 之后,一些 kernel 代码是否会沿着设备树结构并依次调用总线驱动程序(总线 2 驱动程序和总线 1 驱动程序)来创建这个包络结构。

Can anyone point me to the code in the linux kernel where this happens?谁能指出发生这种情况的 linux kernel 中的代码? I tried to follow urb_submit but could not figure this out.我试图关注 urb_submit 但无法弄清楚。

Thanks a bunch!非常感谢!

For device drivers that have memory-mapped registers, the device's private data struct contains the addresses assigned by enumeration for each device and they directly write to the registers.对于具有内存映射寄存器的设备驱动程序,设备的私有数据结构包含通过枚举为每个设备分配的地址,并且它们直接写入寄存器。

For device drivers that go through layers, as you describe above, the enumeration tells each driver who its parent is, and the driver saves this in its private data when it is instantiated.对于 go 通过层的设备驱动程序,如上所述,枚举告诉每个驱动程序其父级是谁,并且驱动程序在实例化时将其保存在其私有数据中。 Then the read or write call of the driver formats the request properly for the device type and invokes the read or write method of the parent driver.然后驱动程序的读取或写入调用为设备类型正确格式化请求并调用父驱动程序的读取或写入方法。 For example, a USB disk read might call the read method in the file_operations block of its parent which would be https://elixir.bootlin.com/linux/v4.19.107/source/drivers/usb/core/devio.c#L2614例如,USB 磁盘读取可能会调用其父级的 file_operations 块中的读取方法,即https://elixir.bootlin.com/linux/v4.19.107/source/drivers/usb/core/devio.c# L2614

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

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