Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Merge branch 'devel'
[palacios.git] / kitten / include / lwk / driver.h
1 #ifndef _LWK_DRIVER_H
2 #define _LWK_DRIVER_H
3
4 #include <lwk/kernel.h>
5 #include <lwk/types.h>
6
7 /*
8  * Drivers may set DRIVER_NAME before including this header.
9  * Otherwise, the KBUILD name is used.
10  */
11 #ifndef DRIVER_NAME
12 #define DRIVER_NAME KBUILD_MODNAME
13 #endif
14
15 /*
16  * Driver parameter names have the form:
17  *
18  *      driver_name.parameter_name
19  *
20  * Example:
21  * To set integer parameter foo in driver bar, add this
22  * to the kernel boot command line:
23  *
24  *      bar.foo=1
25  */
26 #define __DRIVER_PARAM_PREFIX   DRIVER_NAME "."
27
28 /*
29  * For driver parameters.  Parameters can be configured via the
30  * kernel boot command line or some other platform-dependent
31  * runtime mechanism.
32  */
33 #include <lwk/params.h>
34
35 #define driver_param(name, type) \
36         __param_named(__DRIVER_PARAM_PREFIX, name, name, type)
37
38 #define driver_param_named(name, value, type) \
39         __param_named(__DRIVER_PARAM_PREFIX, name, value, type)
40
41 #define driver_param_string(name, string, len) \
42         __param_string(__DRIVER_PARAM_PREFIX, name, string, len)
43
44 #define driver_param_array(name, type, nump) \
45         __param_array_named(__DRIVER_PARAM_PREFIX, name, name, type, nump)
46
47 #define driver_param_array_named(name, array, type, nump) \
48         __param_array_named(__DRIVER_PARAM_PREFIX, name, array, type, nump)
49
50 /*
51  * Every driver defines one of these structures via the
52  * driver_init() macro.  The structure gets placed in the 
53  * __driver_table ELF section and the kernel walks this table
54  * to find/initialize all drivers in the system.
55  */
56 struct driver_info {
57         const char *    name;           // name of the driver
58         void            (*init)(void);  // driver initialization function
59         int             init_called;    // set when .init() has been called,
60                                         // used to prevent double inits.
61 };
62
63 /*
64  * This adds a function to the __driver_table ELF section.
65  */
66 #define driver_init(init_func)                                          \
67         static char __driver_name[] = DRIVER_NAME;                      \
68         static struct driver_info const __driver_info                   \
69         __attribute_used__                                              \
70         __attribute__ ((unused,__section__ ("__driver_table"),          \
71                         aligned(sizeof(void *))))                       \
72         = { __driver_name, init_func };
73
74 /*
75  * The __driver_table ELF section is surrounded by these symbols,
76  * which are defined in the platform's linker script.
77  */
78 extern struct driver_info __start___driver_table[];
79 extern struct driver_info __stop___driver_table[];
80
81 /*
82  * This is a placeholder.  Currently drivers are never unloaded once loaded.
83  */
84 #define driver_exit(exit_func)  
85
86 extern int driver_init_by_name(const char *name);
87
88 #endif