如果是模块,是否需要__init?

发布于 2024-12-27 09:36:31 字数 229 浏览 1 评论 0原文

当我们将驱动程序与内核一起构建为静态时,我就可以理解驱动程序代码从 __init 到 _probe 的流程。但是,当驱动程序构建为模块并在内核已启动时使用 insmod 加载时,我们仍然需要这两个功能吗?

我的意思是,使用 insmod 时不是只需要 _probe 吗?难道驱动程序不能直接探测设备并且设备注册代码可以在 _probe 本身中完成吗?

我只是不清楚。也许我的怀疑是错误的,但请帮助我消除这个怀疑。

When we build a driver as static along with the kernel, Then I can understand the flow of driver code from __init to _probe. But when the driver is built as a module and is loaded with insmod when the kernel is already booted, do we still require both functions ?

I mean, wouldn't only _probe be required when insmod is used ? Wouldn't the driver probe for the device directly and the device registration code could be done in the _probe itself ?

This is just not clear to me. Maybe my doubt is wrong but help me in clearing this doubt.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自由如风 2025-01-03 09:36:31

实际上,在这两种情况下(内核中的驱动程序或作为模块)都需要两个函数(init 和probe)。

正如您所提到的,当存在设备/驱动程序注册时,将使用探测函数(设备/驱动程序内核子系统注意到给定设备有合适的驱动程序,并将它们“关联”)。

简单来说,为了能够实现这种“关联”,内核的设备/驱动程序子系统需要系统上的设备列表和可用驱动程序列表(以及一种了解驱动程序是否可以“关联”的方法) “与设备,但这对你的问题并不重要)。

在典型的模块中,init函数是将驱动程序初始化到内核的函数,或者换句话说,将驱动程序注册到内核的驱动程序/设备子系统,以便可以将这个新驱动程序添加到可用驱动程序列表中可以与设备“关联”。当驱动程序构建为模块时也必须完成此操作。

Actually, in both cases (driver in kernel or as a module) both functions (init and probe) are required.

As you mention it, the probe function is used when there is a device/driver registration (the device/driver kernel subsystem notices that there is a suitable driver for a given device and it "associates" them).

To simplify, in order to be able to achieve this "associtation", the kernel's device/driver subsystem needs a list of the devices on the system and a list of the available drivers (and a way to know if a driver can be "associated" with device, but it's not important for your question).

In a typical module, the init function is the function that initializes the driver to kernel, or to phrase it differently, to register the driver to the kernel's driver/device subsystem so that this new driver can be added to the list of available drivers that can be "associated" with the devices. This also has to be done when the driver is built as a module.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文