3 * modules/parser/swap_msg_parser.c
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * Copyright (C) Samsung Electronics, 2013
21 * 2013 Vyacheslav Cherkashin, Vitaliy Cherepanov: SWAP Parser implement
26 #include <linux/module.h>
27 #include <linux/vmalloc.h>
28 #include <linux/cpumask.h>
29 #include <asm/uaccess.h>
31 #include "parser_defs.h"
36 #include <driver/driver_to_msg.h>
37 #include <driver/swap_ioctl.h>
40 MSG_KEEP_ALIVE = 0x0001,
44 MSG_SWAP_INST_ADD = 0x0008,
45 MSG_SWAP_INST_REMOVE = 0x0009
48 struct basic_msg_fmt {
51 } __attribute__((packed));
53 static int msg_handler(void __user *msg)
60 struct basic_msg_fmt bmf;
61 enum { size_max = 128 * 1024 * 1024 };
63 ret = copy_from_user(&bmf, (void*)msg, sizeof(bmf));
68 if (size >= size_max) {
69 printk("%s: too large message, size=%u\n", __func__, size);
73 ret = init_mb(&mb, size);
77 payload = msg + sizeof(bmf);
79 ret = copy_from_user(mb.begin, (void*)payload, size);
87 print_parse_debug("MSG_KEEP_ALIVE. size=%d\n", size);
88 ret = msg_keep_alive(&mb);
91 print_parse_debug("MSG_START. size=%d\n", size);
97 print_parse_debug("MSG_STOP. size=%d\n", size);
99 swap_disable_nonboot_cpus_lock(&mask);
101 swap_enable_nonboot_cpus_unlock(&mask);
106 print_parse_debug("MSG_CONFIG. size=%d\n", size);
107 ret = msg_config(&mb);
109 case MSG_SWAP_INST_ADD:
110 print_parse_debug("MSG_SWAP_INST_ADD. size=%d\n", size);
111 ret = msg_swap_inst_add(&mb);
113 case MSG_SWAP_INST_REMOVE:
114 print_parse_debug("MSG_SWAP_INST_REMOVE. size=%d\n", size);
115 ret = msg_swap_inst_remove(&mb);
118 print_err("incorrect message ID [%u]. size=%d\n", msg_id, size);
128 static void register_msg_handler(void)
130 set_msg_handler(msg_handler);
133 static void unregister_msg_handler(void)
135 set_msg_handler(NULL);
138 static int __init swap_parser_init(void)
142 ret = init_cpu_deps();
146 register_msg_handler();
154 static void __exit swap_parser_exit(void)
157 unregister_msg_handler();
160 module_init(swap_parser_init);
161 module_exit(swap_parser_exit);
163 MODULE_LICENSE("GPL");