How to Write Linux Driver Module Call/Use Another Driver Module

How to write Linux driver module call/use another driver module?

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 Kernel module calling a function in another module

Yes. Of course, the other kernel module must be loaded.

For an example, look at the USB code, which is implemented as a mullti-layer driver, with each layer in its own module.Reference link here.

How can i call a function that written in kernel module, from the user program?

You can make your driver to react on writes (or if necessary, ioctl) to a /dev/xxx file or a /proc/xxx file. Also, you can create a new syscall, but that's more of a toy as the module would only work on custom built kernels.

Edit: try http://www.faqs.org/docs/kernel/x571.html (on character device drivers.)

How to call exported kernel module functions from another module?

From my research, it seems that those are the only three ways to handle this situation, and I've gotten each of them to work, so I think I'll just pick my favorite out of those.



Related Topics



Leave a reply



Submit