File Index
Files and directories
Sign in
FILE

zcomp.h

File preview with syntax highlighting.

linux-6.19.14/drivers/block/zram/zcomp.h C
 1/* SPDX-License-Identifier: GPL-2.0-or-later */
 2
 3#ifndef _ZCOMP_H_
 4#define _ZCOMP_H_
 5
 6#include <linux/mutex.h>
 7
 8#define ZCOMP_PARAM_NOT_SET	INT_MIN
 9
10struct deflate_params {
11	s32 winbits;
12};
13
14/*
15 * Immutable driver (backend) parameters. The driver may attach private
16 * data to it (e.g. driver representation of the dictionary, etc.).
17 *
18 * This data is kept per-comp and is shared among execution contexts.
19 */
20struct zcomp_params {
21	void *dict;
22	size_t dict_sz;
23	s32 level;
24	union {
25		struct deflate_params deflate;
26	};
27
28	void *drv_data;
29};
30
31/*
32 * Run-time driver context - scratch buffers, etc. It is modified during
33 * request execution (compression/decompression), cannot be shared, so
34 * it's in per-CPU area.
35 */
36struct zcomp_ctx {
37	void *context;
38};
39
40struct zcomp_strm {
41	struct mutex lock;
42	/* compression buffer */
43	void *buffer;
44	/* local copy of handle memory */
45	void *local_copy;
46	struct zcomp_ctx ctx;
47};
48
49struct zcomp_req {
50	const unsigned char *src;
51	const size_t src_len;
52
53	unsigned char *dst;
54	size_t dst_len;
55};
56
57struct zcomp_ops {
58	int (*compress)(struct zcomp_params *params, struct zcomp_ctx *ctx,
59			struct zcomp_req *req);
60	int (*decompress)(struct zcomp_params *params, struct zcomp_ctx *ctx,
61			  struct zcomp_req *req);
62
63	int (*create_ctx)(struct zcomp_params *params, struct zcomp_ctx *ctx);
64	void (*destroy_ctx)(struct zcomp_ctx *ctx);
65
66	int (*setup_params)(struct zcomp_params *params);
67	void (*release_params)(struct zcomp_params *params);
68
69	const char *name;
70};
71
72/* dynamic per-device compression frontend */
73struct zcomp {
74	struct zcomp_strm __percpu *stream;
75	const struct zcomp_ops *ops;
76	struct zcomp_params *params;
77	struct hlist_node node;
78};
79
80int zcomp_cpu_up_prepare(unsigned int cpu, struct hlist_node *node);
81int zcomp_cpu_dead(unsigned int cpu, struct hlist_node *node);
82ssize_t zcomp_available_show(const char *comp, char *buf, ssize_t at);
83bool zcomp_available_algorithm(const char *comp);
84
85struct zcomp *zcomp_create(const char *alg, struct zcomp_params *params);
86void zcomp_destroy(struct zcomp *comp);
87
88struct zcomp_strm *zcomp_stream_get(struct zcomp *comp);
89void zcomp_stream_put(struct zcomp_strm *zstrm);
90
91int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm,
92		   const void *src, unsigned int *dst_len);
93int zcomp_decompress(struct zcomp *comp, struct zcomp_strm *zstrm,
94		     const void *src, unsigned int src_len, void *dst);
95
96#endif /* _ZCOMP_H_ */
~/ Read-only file preview.