xref: /openbmc/linux/drivers/block/zram/zcomp.h (revision ebaf9ab5)
1 /*
2  * Copyright (C) 2014 Sergey Senozhatsky.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version
7  * 2 of the License, or (at your option) any later version.
8  */
9 
10 #ifndef _ZCOMP_H_
11 #define _ZCOMP_H_
12 
13 struct zcomp_strm {
14 	/* compression/decompression buffer */
15 	void *buffer;
16 	struct crypto_comp *tfm;
17 };
18 
19 /* static compression backend */
20 struct zcomp_backend {
21 	int (*compress)(const unsigned char *src, unsigned char *dst,
22 			size_t *dst_len, void *private);
23 
24 	int (*decompress)(const unsigned char *src, size_t src_len,
25 			unsigned char *dst);
26 
27 	void *(*create)(gfp_t flags);
28 	void (*destroy)(void *private);
29 
30 	const char *name;
31 };
32 
33 /* dynamic per-device compression frontend */
34 struct zcomp {
35 	struct zcomp_strm * __percpu *stream;
36 	struct zcomp_backend *backend;
37 	struct notifier_block notifier;
38 
39 	const char *name;
40 };
41 
42 ssize_t zcomp_available_show(const char *comp, char *buf);
43 bool zcomp_available_algorithm(const char *comp);
44 
45 struct zcomp *zcomp_create(const char *comp);
46 void zcomp_destroy(struct zcomp *comp);
47 
48 struct zcomp_strm *zcomp_stream_get(struct zcomp *comp);
49 void zcomp_stream_put(struct zcomp *comp);
50 
51 int zcomp_compress(struct zcomp_strm *zstrm,
52 		const void *src, unsigned int *dst_len);
53 
54 int zcomp_decompress(struct zcomp_strm *zstrm,
55 		const void *src, unsigned int src_len, void *dst);
56 
57 bool zcomp_set_max_streams(struct zcomp *comp, int num_strm);
58 #endif /* _ZCOMP_H_ */
59