add 'swap_ksyms' module
[kernel/swap-modules.git] / driver / module.c
1 ////////////////////////////////////////////////////////////////////////////////////
2 //
3 //      FILE:           module.c
4 //
5 //      DESCRIPTION:
6 //      This file is C source for SWAP driver.
7 //
8 //      SEE ALSO:       module.h
9 //      AUTHOR:         L.Komkov, A.Gerenkov
10 //      COMPANY NAME:   Samsung Research Center in Moscow
11 //      DEPT NAME:      Advanced Software Group
12 //      CREATED:        2008.02.15
13 //      VERSION:        1.0
14 //      REVISION DATE:  2008.12.03
15 //
16 ////////////////////////////////////////////////////////////////////////////////////
17
18 #include "module.h"
19
20 char gl_szDefaultDeviceName[128] = DEFAULT_DEVICE_NAME;
21 char* device_name = NULL;
22 module_param (device_name, charp, 0);
23 MODULE_PARM_DESC (device_name, "device name for '/proc/devices'");
24
25 unsigned int device_major = 0;
26 module_param (device_major, uint, 0);
27 MODULE_PARM_DESC (device_major, "default device major number");
28
29 #if (LINUX_VERSION_CODE != KERNEL_VERSION(2, 6, 16))
30 void (*__real_put_task_struct) (struct task_struct * tsk);
31 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11))
32 #define SWAPDRV_PUT_TASK_STRUCT "put_task_struct"
33 void
34 put_task_struct (struct task_struct *tsk)
35 {
36         __real_put_task_struct (tsk);
37 }
38 #else
39 #define SWAPDRV_PUT_TASK_STRUCT "__put_task_struct"
40 void
41 __put_task_struct (struct task_struct *tsk)
42 {
43         __real_put_task_struct (tsk);
44 }
45 #endif
46 #else /*2.6.16 */
47 void (*__real_put_task_struct) (struct rcu_head * rhp);
48 #define SWAPDRV_PUT_TASK_STRUCT "__put_task_struct_cb"
49 void
50 __put_task_struct_cb (struct rcu_head *rhp)
51 {
52         __real_put_task_struct (rhp);
53 }
54 #endif
55 /*void (*__real_put_task_struct)(struct task_struct *tsk);
56 void __put_task_struct(struct task_struct *tsk)
57 {
58         __real_put_task_struct(tsk);
59 }*/
60
61 #if defined(CONFIG_MIPS)
62 void (*flush_cache_page) (struct vm_area_struct * vma, unsigned long page);
63 #endif
64
65 static int __init InitializeModule(void)
66 {
67         if(device_name == NULL) {
68                 EPRINTF("Using default device name!");
69                 device_name = gl_szDefaultDeviceName;
70         }
71         if(device_major == 0) {
72                 EPRINTF("Using default device major number!");
73                 device_major = DEFAULT_DEVICE_MAJOR;
74         }
75
76         __real_put_task_struct = (void *)swap_ksyms(SWAPDRV_PUT_TASK_STRUCT);
77         if (!__real_put_task_struct)
78         {
79                 EPRINTF (SWAPDRV_PUT_TASK_STRUCT " is not found! Oops. Where is it?");
80                 return -ESRCH;
81         }
82
83 #if defined(CONFIG_MIPS)
84         flush_cache_page = (void *)swap_ksyms("r4k_flush_cache_page");
85         if (!flush_cache_page)
86         {
87                 EPRINTF ("failed to resolve 'flush_cache_page'!\n");
88                 return -ESRCH;
89         }
90 #endif
91
92         if(probes_manager_init() < 0) {
93                 EPRINTF ("Cannot initialize probe manager!");
94                 return -1;
95         }
96         if(device_init() < 0) {
97                 EPRINTF ("Cannot initialize device!");
98                 return -1;
99         }
100
101         INIT_LIST_HEAD(&cond_list.list);
102
103         DPRINTF ("is successfully initialized.");
104         return 0;
105 }
106
107 static void __exit UninitializeModule (void)
108 {
109         ec_user_stop ();
110         device_down ();
111         probes_manager_down ();
112         DPRINTF ("is successfully finished.");
113 }
114
115 module_init (InitializeModule);
116 module_exit (UninitializeModule);
117 MODULE_LICENSE ("GPL");
118 MODULE_AUTHOR("Adwanced Software Group (SRC, Moscow)");
119 MODULE_DESCRIPTION("SWAP Device Driver");
120 MODULE_VERSION("4:1.0");