1e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky/*
2e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky * Copyright (C) 2014 Sergey Senozhatsky.
3e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky *
4e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky * This program is free software; you can redistribute it and/or
5e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky * modify it under the terms of the GNU General Public License
6e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky * as published by the Free Software Foundation; either version
7e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky * 2 of the License, or (at your option) any later version.
8e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky */
9e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky
10e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky#ifndef _ZCOMP_H_
11e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky#define _ZCOMP_H_
12e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky
13e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky#include <linux/mutex.h>
14e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky
15e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatskystruct zcomp_strm {
16e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky	/* compression/decompression buffer */
17e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky	void *buffer;
18e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky	/*
19e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky	 * The private data of the compression stream, only compression
20e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky	 * stream backend can touch this (e.g. compression algorithm
21e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky	 * working memory)
22e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky	 */
23e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky	void *private;
24beca3ec71fe5490ee9237dc42400f50402baf83eSergey Senozhatsky	/* used in multi stream backend, protected by backend strm_lock */
25beca3ec71fe5490ee9237dc42400f50402baf83eSergey Senozhatsky	struct list_head list;
26e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky};
27e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky
28e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky/* static compression backend */
29e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatskystruct zcomp_backend {
30e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky	int (*compress)(const unsigned char *src, unsigned char *dst,
31e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky			size_t *dst_len, void *private);
32e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky
33e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky	int (*decompress)(const unsigned char *src, size_t src_len,
34e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky			unsigned char *dst);
35e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky
36e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky	void *(*create)(void);
37e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky	void (*destroy)(void *private);
38e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky
39e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky	const char *name;
40e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky};
41e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky
42e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky/* dynamic per-device compression frontend */
43e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatskystruct zcomp {
449cc97529a180b369fcb7e5265771b6ba7e01f05bSergey Senozhatsky	void *stream;
45e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky	struct zcomp_backend *backend;
469cc97529a180b369fcb7e5265771b6ba7e01f05bSergey Senozhatsky
479cc97529a180b369fcb7e5265771b6ba7e01f05bSergey Senozhatsky	struct zcomp_strm *(*strm_find)(struct zcomp *comp);
489cc97529a180b369fcb7e5265771b6ba7e01f05bSergey Senozhatsky	void (*strm_release)(struct zcomp *comp, struct zcomp_strm *zstrm);
4960a726e33375a1096e85399cfa1327081b4c38beMinchan Kim	bool (*set_max_streams)(struct zcomp *comp, int num_strm);
509cc97529a180b369fcb7e5265771b6ba7e01f05bSergey Senozhatsky	void (*destroy)(struct zcomp *comp);
51e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky};
52e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky
53e46b8a030d76d3c94156c545c3f4c3676d813435Sergey Senozhatskyssize_t zcomp_available_show(const char *comp, char *buf);
54e46b8a030d76d3c94156c545c3f4c3676d813435Sergey Senozhatsky
55beca3ec71fe5490ee9237dc42400f50402baf83eSergey Senozhatskystruct zcomp *zcomp_create(const char *comp, int max_strm);
56e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatskyvoid zcomp_destroy(struct zcomp *comp);
57e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky
58e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatskystruct zcomp_strm *zcomp_strm_find(struct zcomp *comp);
59e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatskyvoid zcomp_strm_release(struct zcomp *comp, struct zcomp_strm *zstrm);
60e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky
61e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatskyint zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm,
62e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky		const unsigned char *src, size_t *dst_len);
63e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky
64e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatskyint zcomp_decompress(struct zcomp *comp, const unsigned char *src,
65e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky		size_t src_len, unsigned char *dst);
66fe8eb122c82b2049c460fc6df6e8583a2f935cffSergey Senozhatsky
6760a726e33375a1096e85399cfa1327081b4c38beMinchan Kimbool zcomp_set_max_streams(struct zcomp *comp, int num_strm);
68e7e1ef439d18f9a21521116ea9f2b976d7230e54Sergey Senozhatsky#endif /* _ZCOMP_H_ */
69