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.
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.