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->buffer); in zcomp_strm_free()
50 zstrm->buffer = NULL; in zcomp_strm_free()
53 static int zcomp_strm_init(struct zcomp *comp, struct zcomp_strm *zstrm) in zcomp_strm_init() argument
55 int ret; in zcomp_strm_init()
57 ret = comp->ops->create_ctx(comp->params, &zstrm->ctx); in zcomp_strm_init()
65 zstrm->buffer = vzalloc(2 * PAGE_SIZE); in zcomp_strm_init()
66 if (!zstrm->buffer) { in zcomp_strm_init()
67 zcomp_strm_free(comp, zstrm); in zcomp_strm_init()
68 return -ENOMEM; in zcomp_strm_init()
73 static const struct zcomp_ops *lookup_backend_ops(const char *comp) in lookup_backend_ops() argument
75 int i = 0; in lookup_backend_ops()
78 if (sysfs_streq(comp, backends[i]->name)) in lookup_backend_ops()
85 bool zcomp_available_algorithm(const char *comp) in zcomp_available_algorithm() argument
87 return lookup_backend_ops(comp) != NULL; in zcomp_available_algorithm()
91 ssize_t zcomp_available_show(const char *comp, char *buf) in zcomp_available_show() argument
94 int i; in zcomp_available_show()
96 for (i = 0; i < ARRAY_SIZE(backends) - 1; i++) { in zcomp_available_show()
97 if (!strcmp(comp, backends[i]->name)) { in zcomp_available_show()
98 sz += scnprintf(buf + sz, PAGE_SIZE - sz - 2, in zcomp_available_show()
99 "[%s] ", backends[i]->name); in zcomp_available_show()
101 sz += scnprintf(buf + sz, PAGE_SIZE - sz - 2, in zcomp_available_show()
102 "%s ", backends[i]->name); in zcomp_available_show()
106 sz += scnprintf(buf + sz, PAGE_SIZE - sz, "\n"); in zcomp_available_show()
110 struct zcomp_strm *zcomp_stream_get(struct zcomp *comp) in zcomp_stream_get() argument
112 local_lock(&comp->stream->lock); in zcomp_stream_get()
113 return this_cpu_ptr(comp->stream); in zcomp_stream_get()
116 void zcomp_stream_put(struct zcomp *comp) in zcomp_stream_put() argument
118 local_unlock(&comp->stream->lock); in zcomp_stream_put()
121 int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm, in zcomp_compress() argument
122 const void *src, unsigned int *dst_len) in zcomp_compress()
126 .dst = zstrm->buffer, in zcomp_compress()
130 int ret; in zcomp_compress()
132 ret = comp->ops->compress(comp->params, &zstrm->ctx, &req); in zcomp_compress()
138 int zcomp_decompress(struct zcomp *comp, struct zcomp_strm *zstrm, in zcomp_decompress() argument
139 const void *src, unsigned int src_len, void *dst) in zcomp_decompress()
148 return comp->ops->decompress(comp->params, &zstrm->ctx, &req); in zcomp_decompress()
151 int zcomp_cpu_up_prepare(unsigned int cpu, struct hlist_node *node) in zcomp_cpu_up_prepare()
153 struct zcomp *comp = hlist_entry(node, struct zcomp, node); in zcomp_cpu_up_prepare() local
155 int ret; in zcomp_cpu_up_prepare()
157 zstrm = per_cpu_ptr(comp->stream, cpu); in zcomp_cpu_up_prepare()
158 local_lock_init(&zstrm->lock); in zcomp_cpu_up_prepare()
160 ret = zcomp_strm_init(comp, zstrm); in zcomp_cpu_up_prepare()
166 int zcomp_cpu_dead(unsigned int cpu, struct hlist_node *node) in zcomp_cpu_dead()
168 struct zcomp *comp = hlist_entry(node, struct zcomp, node); in zcomp_cpu_dead() local
171 zstrm = per_cpu_ptr(comp->stream, cpu); in zcomp_cpu_dead()
172 zcomp_strm_free(comp, zstrm); in zcomp_cpu_dead()
176 static int zcomp_init(struct zcomp *comp, struct zcomp_params *params) in zcomp_init() argument
178 int ret; in zcomp_init()
180 comp->stream = alloc_percpu(struct zcomp_strm); in zcomp_init()
181 if (!comp->stream) in zcomp_init()
182 return -ENOMEM; in zcomp_init()
184 comp->params = params; in zcomp_init()
185 ret = comp->ops->setup_params(comp->params); in zcomp_init()
189 ret = cpuhp_state_add_instance(CPUHP_ZCOMP_PREPARE, &comp->node); in zcomp_init()
196 comp->ops->release_params(comp->params); in zcomp_init()
197 free_percpu(comp->stream); in zcomp_init()
201 void zcomp_destroy(struct zcomp *comp) in zcomp_destroy() argument
203 cpuhp_state_remove_instance(CPUHP_ZCOMP_PREPARE, &comp->node); in zcomp_destroy()
204 comp->ops->release_params(comp->params); in zcomp_destroy()
205 free_percpu(comp->stream); in zcomp_destroy()
206 kfree(comp); in zcomp_destroy()
211 struct zcomp *comp; in zcomp_create() local
212 int error; in zcomp_create()
222 comp = kzalloc(sizeof(struct zcomp), GFP_KERNEL); in zcomp_create()
223 if (!comp) in zcomp_create()
224 return ERR_PTR(-ENOMEM); in zcomp_create()
226 comp->ops = lookup_backend_ops(alg); in zcomp_create()
227 if (!comp->ops) { in zcomp_create()
228 kfree(comp); in zcomp_create()
229 return ERR_PTR(-EINVAL); in zcomp_create()
232 error = zcomp_init(comp, params); in zcomp_create()
234 kfree(comp); in zcomp_create()
237 return comp; in zcomp_create()