jjzjj

module_platform_driver()

铁头小哥 2024-04-27 原文

在Linux设备驱动开发使用platform平台驱动模型过程中,在定义且初始化好platform_driver结构体变量以后,我们需要向 Linux 内核注册一个 platform 驱动。下面介绍两种方法。

方法一:

/**
* 在驱动入口函数里面调用platform_driver_register函数,platform_driver_register函数
* 原型如下所示:
*/
int platform_driver_register(struct platform_driver *driver)
// driver:要注册的 platform 驱动。
// 返回值:负数,失败;0,成功。
    
/**
*还需要在驱动卸载函数中通过platform_driver_unregister函数卸载platform驱动,
*platform_driver_unregister 函数原型如下:
*/
void platform_driver_unregister(struct platform_driver *drv)
// drv:要卸载的 platform 驱动。
// 返回值:无。
/**
* 具体驱动代码中实现如下所示
*/
    
// 驱动模块加载
static int __init xxx_init(void)
{
	return platform_driver_register(&xxx_driver);
}
module_init(xxx_init);
// 驱动模块卸载 
static void __exit xxx_exit(void)
{
	platform_driver_unregister(&xxx_driver);
}
module_exit(xxx_exit);

方法二:

除了方法一这种传统方法以外, Linux 内核中会大量采用 module_platform_driver 来完成向 Linux 内核注册 platform 驱动的操作。
module_platform_driver 定义在 include/linux/platform_device.h 文件中,如下:

/* module_platform_driver() - Helper macro for drivers that don't do
 * anything special in module init/exit.  This eliminates a lot of
 * boilerplate.  Each module may only use this macro once, and
 * calling it replaces module_init() and module_exit()
 */
#define module_platform_driver(__platform_driver) \
	module_driver(__platform_driver, platform_driver_register, \
			platform_driver_unregister)

可以看出,module_platform_driver 依赖 module_driver,module_driver 也是一个宏,定义在include/linux/device.h 文件中,内容如下:


/**
 * module_driver() - Helper macro for drivers that don't do anything
 * special in module init/exit. This eliminates a lot of boilerplate.
 * Each module may only use this macro once, and calling it replaces
 * module_init() and module_exit().
 *
 * @__driver: driver name
 * @__register: register function for this driver type
 * @__unregister: unregister function for this driver type
 * @...: Additional arguments to be passed to __register and __unregister.
 *
 * Use this macro to construct bus specific macros for registering
 * drivers, and do not use it on its own.
 */
#define module_driver(__driver, __register, __unregister, ...) \
static int __init __driver##_init(void) \
{ \
	return __register(&(__driver) , ##__VA_ARGS__); \
} \
module_init(__driver##_init); \
static void __exit __driver##_exit(void) \
{ \
	__unregister(&(__driver) , ##__VA_ARGS__); \
} \
module_exit(__driver##_exit);
/**
* 具体驱动代码中实现如下所示
*/
module_platform_driver(xxx_driver);

因此方法一就是方法二的展开形式。

有关module_platform_driver()的更多相关文章

  1. ruby - Facter::Util::Uptime:Module 的未定义方法 get_uptime (NoMethodError) - 2

    我正在尝试设置一个puppet节点,但ruby​​gems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由ruby​​gems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby

  2. ruby - 为什么人们使用 `Module.send(:prepend, …)` ? - 2

    我正在学习如何在我的Ruby代码中使用Module.prepend而不是alias_method_chain,我注意到有些人使用send调用它(example):ActionView::TemplateRenderer.send(:prepend,ActionViewTemplateRendererWithCurrentTemplate)而其他人直接调用它(example):ActionView::TemplateRenderer.prepend(ActionViewTemplateRendererWithCurrentTemplate)而且,虽然我还没有看到任何人使用这种风格,但我从

  3. ruby-on-rails - Capybara-webkit 引发 Capybara::Driver::Webkit::WebkitInvalidResponseError - 2

    我在rspec中收到来自webkit驱动程序的以下消息:Capybara::Driver::Webkit::WebkitInvalidResponseError:UnabletoloadURL:http://127.0.0.1:44923/posts几天前它成功了。问题出在save_page方法上。有什么问题吗? 最佳答案 当我的页面出现错误时,我收到过类似的错误消息。您应该通过在测试模式下启动服务器(railss-etest)并自行访问页面来手动检查情况是否如此。 关于ruby-on-

  4. ruby-on-rails - 测试我的 Ruby gem:Shoulda::Matchers:Module (NoMethodError) 的未定义方法 `configure' - 2

    我正在开发我的第一个Rubygem,并捆绑了cucumber、rspec和shoulda-matches进行测试。当我运行rspec时,出现以下错误:/app/my_gem/spec/spec_helper.rb:6:in`':undefinedmethod`configure'forShoulda::Matchers:Module(NoMethodError)这是我的gem规范:#my_gem.gemspec...Gem::Specification.newdo|spec|......spec.add_development_dependency"activemodel"spec.a

  5. ruby-on-rails - 类型错误 : wrong argument type String (expected Module) - 2

    我有以下代码:classProfileLookup基本上包含大量查找数据,按类别拆分。目的是为数据库中的每个类别创建一个方法。通过Rails控制台,此代码按预期工作:ruby-1.9.3@hub:002>ProfileLookup.available_gendersProfileLookupLoad(0.6ms)SELECT"profile_lookups".*FROM"profile_lookups"WHERE"profile_lookups"."category"='gender'ORDERBYvalue=>["Female","Male"]但是,我的规范不合格。以下规范:requ

  6. ruby - 如何解决错误消息 "Cannot find module ' abbrev' - 2

    我的问题与HowdoIresolve"Cannotfindmodule"errorusingNode.js?非常相似,但我无法使用给出的答案中提供的信息解决我的问题。我尝试运行UNCSSgrunt插件,但是当我尝试安装它时(npminstallgrunt-uncss--save-dev),我收到以下错误:$npminstallgrunt-uncss--save-devmodule.js:340throwerr;^Error:Cannotfindmodule'abbrev'atFunction.Module._resolveFilename(module.js:338:15)atFunc

  7. ruby - 类与 Class.new,模块与 Module.new - 2

    class之间有什么区别?和Class.new&module和Module.new?我知道:Class.new/Module.new创建一个匿名class/module.当我们第一次将它分配给常量时,它变成了那个class的名称。/module.class/module自动执行此操作。当我们想要继承时,我们可以传递一个参数:Class.new(ancestor).当我们不指定祖先时,它被设置为Object.class使用此语法:classAClass.new返回object.classA返回nil.同样适用于module秒。我错过了什么吗? 最佳答案

  8. ruby - Chromedriver `driver.manage.logs.get(:browser)` 在 chromedriver 75.0.3770.8 上失败 - 2

    在chromedriver75.0.3770.8上访问driver.manage.logs.get(:browser)-它导致错误#(NoMethodError)的未定义方法“日志”在74.0.3729.6上工作正常来自:https://github.com/SeleniumHQ/selenium/issues/7270 最佳答案 在最近的selenium-webdriver(4.4.0)和最近的Chrome(105)中,manage.logs不见了,但这有效:page.driver.browser.logs.get(:browse

  9. ruby-on-rails - ubuntu 14.04 上 passenger-install-nginx-module 的 Bundler 错误 - 2

    我正在ubuntu14.04和ruby2.2.4上安装passenger+nginx。passenger-install-nginx-module有bundler错误$passenger-install-nginx-module/home/ubuntu/.rvm/gems/ruby-2.2.4/gems/bundler-1.13.1/lib/bundler/rubygems_ext.rb:45:in`full_gem_path':uninitializedconstantBundler::Plugin::API::Source(NameError)from/home/ubuntu/.r

  10. ruby - 模块嵌套在 instance_eval/exec 或 module_eval/exec 中 - 2

    我在尝试回答this时想到了这个问题.以下是预期的行为:moduleApModule.nestingend#=>[A]但是以下内容:A.instance_eval{pModule.nesting}A.instance_exec{pModule.nesting}A.module_eval{pModule.nesting}A.module_exec{pModule.nesting}全部返回[]。为什么这些不能像上面那样工作?附加问题Muistooshort提出了一个有趣的观点。如果这是正确的,那么Module.nesting将是依赖于文字上下文的方法和变量之一,例如Method#sourc

随机推荐