3 * modules/buffer/swap_buffer_module.h
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 Alexander Aksenov <a.aksenov@samsung.com>: SWAP Buffer implement
25 /* SWAP Buffer interface description */
27 #ifndef __SWAP_BUFFER_MODULE_H__
28 #define __SWAP_BUFFER_MODULE_H__
30 #include <linux/types.h>
32 struct swap_subbuffer;
34 struct buffer_init_t {
35 size_t subbuffer_size;
36 unsigned int nr_subbuffers;
37 int (*subbuffer_full_cb)(void);
39 /* Lower threshold in percent. When buffers fall below this limit
40 * low_mem_cb is called and swap_buffer is suspended. */
41 unsigned char lower_threshold;
42 int (*low_mem_cb)(void);
44 /* Top threshold in percent. When buffers exceed this limit
45 * enough_mem_cb is called */
46 unsigned char top_threshold;
47 int (*enough_mem_cb)(void);
50 /* SWAP Buffer initialization function. Call it before using buffer.
51 * Returns memory pages count (>0) in one subbuffer on success, or error code
53 int swap_buffer_init(struct buffer_init_t *buf_init);
55 /* SWAP Buffer uninitialization function. Call it every time before removing
57 * Returns E_SB_SUCCESS (0) on success, otherwise error code. */
58 int swap_buffer_uninit(void);
60 /* SWAP Buffer write function. Pass it size of the data and pointer to the data.
61 * On success returns number of bytes written (>=0) or error code (<0) otherwise */
62 ssize_t swap_buffer_write(void* data, size_t size);
64 /* SWAP Buffer get. Put subbuffer pointer to the variable *subbuffer.
65 * Return pages count in subbuffer. */
66 int swap_buffer_get(struct swap_subbuffer **subbuffer);
68 /* SWAP Buffer release. All 'get' buffers must be released with this function.
69 * Just pass &subbuffer_ptr to it */
70 int swap_buffer_release(struct swap_subbuffer **subbuffer);
72 /* SWAP Buffer flush. Puts all buffers to read queue and returns their count. */
73 unsigned int swap_buffer_flush(void);
75 #endif /* __SWAP_BUFFER_MODULE_H__ */