如何编写Linux驱动程序模块调用/使用其他驱动程序模块? [英] How to write Linux driver module call/use another driver module?
问题描述
我正在开发Linux驱动程序可加载模块,必须在驱动程序中使用其他设备.(某种驱动程序堆叠在另一个驱动程序上)
I'm developing a Linux driver loadable module and I have to use another device in my driver.(kind of driver stacked on another driver)
如何在驱动程序中调用/使用其他驱动程序?我认为它们都在内核中,因此可能存在一种可以直接使用其他驱动程序的方法.
How do I call/use another driver in my driver? I think they are both in the kernel so there might be a way that can use another driver directly.
推荐答案
您将需要EXPORT_SYMBOL
(或EXPORT_SYMBOL_GPL
)宏.例如:
You will need the EXPORT_SYMBOL
(or EXPORT_SYMBOL_GPL
) macro. For example:
/* mod1.c */
#include <linux/module.h>
#include <linux/kernel.h>
#include "mod1.h"
....
void mod1_foo(void)
{
printk(KERN_ALERT "mod1_foo\n");
}
EXPORT_SYMBOL(mod1_foo);
/* mod2.h */
....
extern void mod1_foo(void);
....
/* mod2.c */
#include <linux/module.h>
#include <linux/kernel.h>
#include "mod1.h"
#include "mod2.h"
int init_module(void)
{
mod1_foo();
...
这应该是一帆风顺的事情,但是您必须对名称空间保持谨慎-踩别人的内核模块符号将是不幸的.
This should be plain sailing, but you must of course be careful with the namespace - stomping on somebody else's kernel module symbols would be unfortunate.
这篇关于如何编写Linux驱动程序模块调用/使用其他驱动程序模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!