tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / kernel / swap / parser / cpu_ctrl.c
1 /**
2  * parser/cpu_ctrl.c
3  * @author Vasiliy Ulyanov <v.ulyanov@samsung.com>
4  *
5  * @section LICENSE
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  *
21  * @section COPYRIGHT
22  *
23  * Copyright (C) Samsung Electronics, 2014
24  *
25  * @section DESCRIPTION
26  *
27  * CPU controls implementation.
28  */
29
30 #include <linux/cpumask.h>
31 #include <linux/cpu.h>
32 #include <ksyms/ksyms.h>
33
34 #ifdef CONFIG_SMP
35 static void (*swap_cpu_maps_update_begin)(void);
36 static void (*swap_cpu_maps_update_done)(void);
37 static int (*swap_cpu_down)(unsigned int, int);
38 static int (*swap_cpu_up)(unsigned int, int);
39
40 /**
41  * @brief Disables nonboot CPUs lock.
42  *
43  * @param mask Pointer to CPU mask struct.
44  * @return 0 on success, error code on error.
45  */
46 int swap_disable_nonboot_cpus_lock(struct cpumask *mask)
47 {
48         int boot_cpu, cpu;
49         int ret = 0;
50
51         swap_cpu_maps_update_begin();
52         cpumask_clear(mask);
53
54         boot_cpu = cpumask_first(cpu_online_mask);
55
56         for_each_online_cpu(cpu) {
57                 if (cpu == boot_cpu)
58                         continue;
59                 ret = swap_cpu_down(cpu, 0);
60                 if (ret == 0)
61                         cpumask_set_cpu(cpu, mask);
62                 printk(KERN_INFO "===> SWAP CPU[%d] down(%d)\n", cpu, ret);
63         }
64
65         WARN_ON(num_online_cpus() > 1);
66         return ret;
67 }
68
69 /**
70  * @brief Enables nonboot CPUs unlock.
71  *
72  * @param mask Pointer to CPU mask struct.
73  * @return 0 on success, error code on error.
74  */
75 int swap_enable_nonboot_cpus_unlock(struct cpumask *mask)
76 {
77         int cpu, ret = 0;
78
79         if (cpumask_empty(mask))
80                 goto out;
81
82         for_each_cpu(cpu, mask) {
83                 ret = swap_cpu_up(cpu, 0);
84                 printk(KERN_INFO "===> SWAP CPU[%d] up(%d)\n", cpu, ret);
85         }
86
87 out:
88         swap_cpu_maps_update_done();
89
90         return ret;
91 }
92
93 /**
94  * @brief Intializes CPU controls.
95  *
96  * @return 0 on success, error code on error.
97  */
98 int init_cpu_deps(void)
99 {
100         const char *sym = "cpu_maps_update_begin";
101
102         swap_cpu_maps_update_begin = (void *)swap_ksyms(sym);
103         if (!swap_cpu_maps_update_begin)
104                 goto not_found;
105
106         sym = "cpu_maps_update_done";
107         swap_cpu_maps_update_done = (void *)swap_ksyms(sym);
108         if (!swap_cpu_maps_update_done)
109                 goto not_found;
110
111         sym = "_cpu_up";
112         swap_cpu_up = (void *)swap_ksyms(sym);
113         if (!swap_cpu_up)
114                 goto not_found;
115
116         sym = "_cpu_down";
117         swap_cpu_down = (void *)swap_ksyms(sym);
118         if (!swap_cpu_down)
119                 goto not_found;
120
121         return 0;
122
123 not_found:
124         printk(KERN_INFO "ERROR: symbol %s(...) not found\n", sym);
125         return -ESRCH;
126 }
127
128 #endif /* CONFIG_SMP */