在Linux内核平台驱动程序中使用Module_exit()

发布于 2025-01-21 07:44:09 字数 992 浏览 3 评论 0原文

我正在学习有关Linux内核平台驱动程序,涉及嵌入式处理器的书 LDD 由Alberto Liberal de Los Rios

它具有 platform_driver_register() platform_driver_unregister() hello_init() em> hello_exit()如下。

static int hello_init(void) 
{ 
  pr_info("demo_init enter\n"); 
  platform_driver_register(&my_platform_driver); 
  pr_info("hello_init exit\n"); 
  return 0; 
} 
static void hello_exit(void) 
{ 
  pr_info("demo_exit enter\n"); 
  platform_driver_unregister(&my_platform_driver); 
  pr_info("demo_exit exit\n"); 
} 
module_init(hello_init); 
module_exit(hello_exit); 

我的理解和问题如下:

  1. 兼容属性的匹配与兼容 struct of_device_id 中的条目是在内核启动时间完成的,加载驱动程序并调用了 probe(),这意味着必须将平台驱动程序构建为内核图像的一部分。那么,为什么我们需要平台驱动程序中的 module_exit()

  2. 如果我们将平台驱动程序构建为可加载模块(其中包括module_exit()部分),则如何进行 compatible 属性匹配以及如何 probe()然后称为

提到的两个查询的任何输入,我是平台驱动程序理解的新手。

I am learning about linux kernel platform drivers referring to the book LDD for Embedded processors
by Alberto Liberal de los Rios

It has a platform_driver_register() and platform_driver_unregister() that is called from hello_init() and hello_exit() functions as below.

static int hello_init(void) 
{ 
  pr_info("demo_init enter\n"); 
  platform_driver_register(&my_platform_driver); 
  pr_info("hello_init exit\n"); 
  return 0; 
} 
static void hello_exit(void) 
{ 
  pr_info("demo_exit enter\n"); 
  platform_driver_unregister(&my_platform_driver); 
  pr_info("demo_exit exit\n"); 
} 
module_init(hello_init); 
module_exit(hello_exit); 

My understandings and questions are as follows :

  1. The matching of the compatible property present in device tree with the compatible
    entries in struct of_device_id is done during kernel boot time,the driver is loaded and probe() called, it means that the platform driver must be built as part of kernel image.So why we need module_exit() in platform drivers.

  2. If we build platform driver as loadable module(which includes the module_exit() section) then how the compatible property matching takes place and how the probe() will be called then.

Any inputs on the two queries mentioned and i am new to platform driver understandings.

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

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

发布评论

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

评论(1

-黛色若梦 2025-01-28 07:44:09
  1. 我们需要Module_exit()如果我们仅将模块作为可加载模块构建。需要多个负载/卸载周期。调试目的是案件的一个例子。另一个示例是可热水设备和系统的优化(卸载相应的模块以免费资源)。 module_exit()在内置模块时根本不会在内核图中构建。如果您需要在关闭/重新启动时执行某些操作,则应在模块中实现关闭功能。
  2. module_exit()(AS module_init())与.probe()无关。至少对于“用户”或模块开发人员而言。在这些功能中,您会进行一些准备和释放,这些准备工作对于驾驶员的所有实例都常见。最后,您注册并解开驾驶员。模块还不是驱动程序 - 它只是可以“插入”/“删除”到内核空间中/“删除”的代码。在.probe()呼叫之前,内核本身实例化驱动程序。 .probe()每次适当的“兼容”在/dt中相遇时调用。在此功能中,您可以为驱动程序的每一个瞬间准备并分配所有资源,从节点的Ypur(如果需要)中获取一些数据,初始化硬件(如果需要),最后将指针附加到所谓的私人资源到驾驶员的实例。
  1. We need module_exit() if we are building our module as loadable module only. It is needed for multiple load/unload cycles. Debugging purposes is one example of the case. Another example is hot-pluggable device and optimization of system (unloading corresponding module in order to free resources). module_exit() will not be built in kernel image at all when module is built in. If you need to perform some actions on shutdown/reboot you should implement shutdown function in your module.
  2. module_exit() (as module_init()) has nothing to do with .probe(). At least for you as for "user" or module developer. In these functions you do some preparations and freeing which are common to all instances of your driver. And finally you register and unregister your driver(s). Module is not driver yet - it's just a piece of code which can be "inserted"/"removed" into/from kernel space. A driver is instantiated by kernel itself before .probe() call. .probe() called each time when appropriate "compatible" meets in OF/DT. In this function you prepare and allocate all resource for every instantion of your driver, get some data from ypur OF-node (if needed), initialize the hardware (if needed) and finally attach pointers to so called private resources to driver's instance.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文