Linux 6.13-rc4
[linux.git] / drivers / block / zram / zcomp.h
blobad576281384248daf4adbb12dcf1ae8c05fb84ce
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 #ifndef _ZCOMP_H_
4 #define _ZCOMP_H_
6 #include <linux/local_lock.h>
8 #define ZCOMP_PARAM_NO_LEVEL INT_MIN
11 * Immutable driver (backend) parameters. The driver may attach private
12 * data to it (e.g. driver representation of the dictionary, etc.).
14 * This data is kept per-comp and is shared among execution contexts.
16 struct zcomp_params {
17 void *dict;
18 size_t dict_sz;
19 s32 level;
21 void *drv_data;
25 * Run-time driver context - scratch buffers, etc. It is modified during
26 * request execution (compression/decompression), cannot be shared, so
27 * it's in per-CPU area.
29 struct zcomp_ctx {
30 void *context;
33 struct zcomp_strm {
34 local_lock_t lock;
35 /* compression buffer */
36 void *buffer;
37 struct zcomp_ctx ctx;
40 struct zcomp_req {
41 const unsigned char *src;
42 const size_t src_len;
44 unsigned char *dst;
45 size_t dst_len;
48 struct zcomp_ops {
49 int (*compress)(struct zcomp_params *params, struct zcomp_ctx *ctx,
50 struct zcomp_req *req);
51 int (*decompress)(struct zcomp_params *params, struct zcomp_ctx *ctx,
52 struct zcomp_req *req);
54 int (*create_ctx)(struct zcomp_params *params, struct zcomp_ctx *ctx);
55 void (*destroy_ctx)(struct zcomp_ctx *ctx);
57 int (*setup_params)(struct zcomp_params *params);
58 void (*release_params)(struct zcomp_params *params);
60 const char *name;
63 /* dynamic per-device compression frontend */
64 struct zcomp {
65 struct zcomp_strm __percpu *stream;
66 const struct zcomp_ops *ops;
67 struct zcomp_params *params;
68 struct hlist_node node;
71 int zcomp_cpu_up_prepare(unsigned int cpu, struct hlist_node *node);
72 int zcomp_cpu_dead(unsigned int cpu, struct hlist_node *node);
73 ssize_t zcomp_available_show(const char *comp, char *buf);
74 bool zcomp_available_algorithm(const char *comp);
76 struct zcomp *zcomp_create(const char *alg, struct zcomp_params *params);
77 void zcomp_destroy(struct zcomp *comp);
79 struct zcomp_strm *zcomp_stream_get(struct zcomp *comp);
80 void zcomp_stream_put(struct zcomp *comp);
82 int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm,
83 const void *src, unsigned int *dst_len);
84 int zcomp_decompress(struct zcomp *comp, struct zcomp_strm *zstrm,
85 const void *src, unsigned int src_len, void *dst);
87 #endif /* _ZCOMP_H_ */