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 <asm/uaccess.h>
30 #include "parser_defs.h"
34 #include <driver/driver_to_msg.h>
35 #include <driver/swap_ioctl.h>
38 MSG_KEEP_ALIVE = 0x0001,
42 MSG_SWAP_INST_ADD = 0x0008,
43 MSG_SWAP_INST_REMOVE = 0x0009
46 struct basic_msg_fmt {
49 } __attribute__((packed));
51 static int msg_handler(void __user *msg)
58 struct basic_msg_fmt bmf;
59 enum { size_max = 128 * 1024 * 1024 };
61 ret = copy_from_user(&bmf, (void*)msg, sizeof(bmf));
66 if (size >= size_max) {
67 printk("%s: too large message, size=%u\n", __func__, size);
71 ret = init_mb(&mb, size);
75 payload = msg + sizeof(bmf);
77 ret = copy_from_user(mb.begin, (void*)payload, size);
85 print_parse_debug("MSG_KEEP_ALIVE. size=%d\n", size);
86 ret = msg_keep_alive(&mb);
89 print_parse_debug("MSG_START. size=%d\n", size);
93 print_parse_debug("MSG_STOP. size=%d\n", size);
97 print_parse_debug("MSG_CONFIG. size=%d\n", size);
98 ret = msg_config(&mb);
100 case MSG_SWAP_INST_ADD:
101 print_parse_debug("MSG_SWAP_INST_ADD. size=%d\n", size);
102 ret = msg_swap_inst_add(&mb);
104 case MSG_SWAP_INST_REMOVE:
105 print_parse_debug("MSG_SWAP_INST_REMOVE. size=%d\n", size);
106 ret = msg_swap_inst_remove(&mb);
109 print_err("incorrect message ID [%u]. size=%d\n", msg_id, size);
119 static void register_msg_handler(void)
121 set_msg_handler(msg_handler);
124 static void unregister_msg_handler(void)
126 set_msg_handler(NULL);
129 static int __init swap_parser_init(void)
132 register_msg_handler();
139 static void __exit swap_parser_exit(void)
142 unregister_msg_handler();
145 module_init(swap_parser_init);
146 module_exit(swap_parser_exit);
148 MODULE_LICENSE("GPL");