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
Check If Local Git Repo Is Ahead/Behind Remote
Does Gcc, Icc, or Microsoft's C/C++ Compiler Support or Know Anything About Numa
Stripping Single and Double Quotes in a String Using Bash/Standard Linux Commands Only
How to List the Size of Each File and Directory and Sort by Descending Size in Bash
Sed Command with -I Option (In-Place Editing) Works Fine on Ubuntu But Not MAC
How Set Multiple Env Variables for a Bash Command
Ld: Using -Rpath,$Origin Inside a Shared Library (Recursive)
Sort a Tab Delimited File Based on Column Sort Command Bash
Installing Jenkins Plugins to Docker Jenkins
Get Gnu Octave to Work with a Multicore Processor. (Multithreading)
Linux Command to Empty All Files of a Directory
How to Control Backlight by Terminal Command
Is It Possible That Linux File Descriptor 0 1 2 Not for Stdin, Stdout and Stderr
Redirect All Output to File Using Bash on Linux