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

后端 未结 2 1392
囚心锁ツ
囚心锁ツ 2021-02-04 05:38

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

2条回答
  •  情话喂你
    2021-02-04 06:19

    You will need the EXPORT_SYMBOL (or EXPORT_SYMBOL_GPL) macro. For example:

    /* mod1.c */
    #include 
    #include 
    #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 
    #include 
    #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.

提交回复
热议问题