4 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
8 * Cherepanov Vitaliy <v.cherepanov@samsung.com>
9 * Nikita Kalyazin <n.kalyazin@samsung.com>
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
24 * - Samsung RnD Institute Russia
28 #include <sys/types.h>
37 #include "ioctl_commands.h"
40 #define SUBBUF_SIZE 64 * 1024
41 #define SUBBUF_NUM 32 * 16
43 static int open_buf_ctl(void)
45 manager.buf_fd = open(BUF_FILENAME, O_RDONLY);
46 if (manager.buf_fd == -1) {
47 LOGE("Cannot open buffer: %s\n", strerror(errno));
50 LOGI("buffer opened: %s, %d\n", BUF_FILENAME, manager.buf_fd);
52 manager.user_ev_fd = open(USER_EVENT_FILENAME, O_WRONLY);
53 if (manager.user_ev_fd == -1) {
54 LOGE("Cannot open user event sysfs file: %s\b", strerror(errno));
57 LOGI("user event sysfs file opened: %s, %d\n", USER_EVENT_FILENAME,
63 static void close_buf_ctl(void)
65 LOGI("close buffer (%d)\n", manager.buf_fd);
66 close(manager.buf_fd);
68 LOGI("close user event sysfs file (%d)\n", manager.user_ev_fd);
69 close(manager.user_ev_fd);
72 static int insert_buf_modules(void)
74 if (system("cd /opt/swap/sdk && ./start.sh")) {
75 LOGE("Cannot insert swap modules\n");
84 struct buffer_initialize init = {
89 if (insert_buf_modules() != 0) {
90 LOGE("Cannot insert buffer modules\n");
94 if (open_buf_ctl() != 0) {
95 LOGE("Cannot open buffer\n");
99 if (ioctl(manager.buf_fd, SWAP_DRIVER_BUFFER_INITIALIZE, &init) == -1) {
100 LOGE("Cannot init buffer: %s\n", strerror(errno));
109 LOGI("Uninit driver (%d)\n", manager.buf_fd);
110 if (ioctl(manager.buf_fd, SWAP_DRIVER_BUFFER_UNINITIALIZE) == -1)
111 LOGW("Cannot uninit driver: %s\n", strerror(errno));
118 if (ioctl(manager.buf_fd, SWAP_DRIVER_FLUSH_BUFFER) == -1)
119 LOGW("Cannot send flush to driver: %s\n", strerror(errno));
122 void wake_up_buf(void)
124 if (ioctl(manager.buf_fd, SWAP_DRIVER_WAKE_UP) == -1)
125 LOGW("Cannot send wake up to driver: %s\n", strerror(errno));
128 int write_to_buf(struct msg_data_t *msg)
130 if (write(manager.user_ev_fd, msg, MSG_DATA_HDR_LEN + msg->len) == -1) {
131 LOGE("write to buf: %s\n", strerror(errno));