Lines Matching +full:comp +full:- +full:int
1 // SPDX-License-Identifier: GPL-2.0-or-later
46 static void zcomp_strm_free(struct zcomp *comp, struct zcomp_strm *zstrm) in zcomp_strm_free() argument
48 comp->ops->destroy_ctx(&zstrm->ctx); in zcomp_strm_free()
49 vfree(zstrm->local_copy); in zcomp_strm_free()
50 vfree(zstrm->buffer); in zcomp_strm_free()
51 zstrm->buffer = NULL; in zcomp_strm_free()
54 static int zcomp_strm_init(struct zcomp *comp, struct zcomp_strm *zstrm) in zcomp_strm_init() argument
56 int ret; in zcomp_strm_init()
58 ret = comp->ops->create_ctx(comp->params, &zstrm->ctx); in zcomp_strm_init()
62 zstrm->local_copy = vzalloc(PAGE_SIZE); in zcomp_strm_init()
67 zstrm->buffer = vzalloc(2 * PAGE_SIZE); in zcomp_strm_init()
68 if (!zstrm->buffer || !zstrm->local_copy) { in zcomp_strm_init()
69 zcomp_strm_free(comp, zstrm); in zcomp_strm_init()
70 return -ENOMEM; in zcomp_strm_init()
75 static const struct zcomp_ops *lookup_backend_ops(const char *comp) in lookup_backend_ops() argument
77 int i = 0; in lookup_backend_ops()
80 if (sysfs_streq(comp, backends[i]->name)) in lookup_backend_ops()
87 bool zcomp_available_algorithm(const char *comp) in zcomp_available_algorithm() argument
89 return lookup_backend_ops(comp) != NULL; in zcomp_available_algorithm()
93 ssize_t zcomp_available_show(const char *comp, char *buf, ssize_t at) in zcomp_available_show() argument
95 int i; in zcomp_available_show()
97 for (i = 0; i < ARRAY_SIZE(backends) - 1; i++) { in zcomp_available_show()
98 if (!strcmp(comp, backends[i]->name)) { in zcomp_available_show()
100 backends[i]->name); in zcomp_available_show()
102 at += sysfs_emit_at(buf, at, "%s ", backends[i]->name); in zcomp_available_show()
110 struct zcomp_strm *zcomp_stream_get(struct zcomp *comp) in zcomp_stream_get() argument
113 struct zcomp_strm *zstrm = raw_cpu_ptr(comp->stream); in zcomp_stream_get()
118 * stream is returned with ->mutex locked which prevents in zcomp_stream_get()
123 * so then unlock and re-try on the current CPU. in zcomp_stream_get()
125 mutex_lock(&zstrm->lock); in zcomp_stream_get()
126 if (likely(zstrm->buffer)) in zcomp_stream_get()
128 mutex_unlock(&zstrm->lock); in zcomp_stream_get()
134 mutex_unlock(&zstrm->lock); in zcomp_stream_put()
137 int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm, in zcomp_compress() argument
138 const void *src, unsigned int *dst_len) in zcomp_compress()
142 .dst = zstrm->buffer, in zcomp_compress()
146 int ret; in zcomp_compress()
149 ret = comp->ops->compress(comp->params, &zstrm->ctx, &req); in zcomp_compress()
155 int zcomp_decompress(struct zcomp *comp, struct zcomp_strm *zstrm, in zcomp_decompress() argument
156 const void *src, unsigned int src_len, void *dst) in zcomp_decompress()
166 return comp->ops->decompress(comp->params, &zstrm->ctx, &req); in zcomp_decompress()
169 int zcomp_cpu_up_prepare(unsigned int cpu, struct hlist_node *node) in zcomp_cpu_up_prepare()
171 struct zcomp *comp = hlist_entry(node, struct zcomp, node); in zcomp_cpu_up_prepare() local
172 struct zcomp_strm *zstrm = per_cpu_ptr(comp->stream, cpu); in zcomp_cpu_up_prepare()
173 int ret; in zcomp_cpu_up_prepare()
175 ret = zcomp_strm_init(comp, zstrm); in zcomp_cpu_up_prepare()
181 int zcomp_cpu_dead(unsigned int cpu, struct hlist_node *node) in zcomp_cpu_dead()
183 struct zcomp *comp = hlist_entry(node, struct zcomp, node); in zcomp_cpu_dead() local
184 struct zcomp_strm *zstrm = per_cpu_ptr(comp->stream, cpu); in zcomp_cpu_dead()
186 mutex_lock(&zstrm->lock); in zcomp_cpu_dead()
187 zcomp_strm_free(comp, zstrm); in zcomp_cpu_dead()
188 mutex_unlock(&zstrm->lock); in zcomp_cpu_dead()
192 static int zcomp_init(struct zcomp *comp, struct zcomp_params *params) in zcomp_init() argument
194 int ret, cpu; in zcomp_init()
196 comp->stream = alloc_percpu(struct zcomp_strm); in zcomp_init()
197 if (!comp->stream) in zcomp_init()
198 return -ENOMEM; in zcomp_init()
200 comp->params = params; in zcomp_init()
201 ret = comp->ops->setup_params(comp->params); in zcomp_init()
206 mutex_init(&per_cpu_ptr(comp->stream, cpu)->lock); in zcomp_init()
208 ret = cpuhp_state_add_instance(CPUHP_ZCOMP_PREPARE, &comp->node); in zcomp_init()
215 comp->ops->release_params(comp->params); in zcomp_init()
216 free_percpu(comp->stream); in zcomp_init()
220 void zcomp_destroy(struct zcomp *comp) in zcomp_destroy() argument
222 cpuhp_state_remove_instance(CPUHP_ZCOMP_PREPARE, &comp->node); in zcomp_destroy()
223 comp->ops->release_params(comp->params); in zcomp_destroy()
224 free_percpu(comp->stream); in zcomp_destroy()
225 kfree(comp); in zcomp_destroy()
230 struct zcomp *comp; in zcomp_create() local
231 int error; in zcomp_create()
241 comp = kzalloc(sizeof(struct zcomp), GFP_KERNEL); in zcomp_create()
242 if (!comp) in zcomp_create()
243 return ERR_PTR(-ENOMEM); in zcomp_create()
245 comp->ops = lookup_backend_ops(alg); in zcomp_create()
246 if (!comp->ops) { in zcomp_create()
247 kfree(comp); in zcomp_create()
248 return ERR_PTR(-EINVAL); in zcomp_create()
251 error = zcomp_init(comp, params); in zcomp_create()
253 kfree(comp); in zcomp_create()
256 return comp; in zcomp_create()