zcomp.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef _ZCOMP_H_
  3. #define _ZCOMP_H_
  4. #include <linux/local_lock.h>
  5. #define ZCOMP_PARAM_NO_LEVEL INT_MIN
  6. /*
  7. * Immutable driver (backend) parameters. The driver may attach private
  8. * data to it (e.g. driver representation of the dictionary, etc.).
  9. *
  10. * This data is kept per-comp and is shared among execution contexts.
  11. */
  12. struct zcomp_params {
  13. void *dict;
  14. size_t dict_sz;
  15. s32 level;
  16. void *drv_data;
  17. };
  18. /*
  19. * Run-time driver context - scratch buffers, etc. It is modified during
  20. * request execution (compression/decompression), cannot be shared, so
  21. * it's in per-CPU area.
  22. */
  23. struct zcomp_ctx {
  24. void *context;
  25. };
  26. struct zcomp_strm {
  27. local_lock_t lock;
  28. /* compression buffer */
  29. void *buffer;
  30. struct zcomp_ctx ctx;
  31. };
  32. struct zcomp_req {
  33. const unsigned char *src;
  34. const size_t src_len;
  35. unsigned char *dst;
  36. size_t dst_len;
  37. };
  38. struct zcomp_ops {
  39. int (*compress)(struct zcomp_params *params, struct zcomp_ctx *ctx,
  40. struct zcomp_req *req);
  41. int (*decompress)(struct zcomp_params *params, struct zcomp_ctx *ctx,
  42. struct zcomp_req *req);
  43. int (*create_ctx)(struct zcomp_params *params, struct zcomp_ctx *ctx);
  44. void (*destroy_ctx)(struct zcomp_ctx *ctx);
  45. int (*setup_params)(struct zcomp_params *params);
  46. void (*release_params)(struct zcomp_params *params);
  47. const char *name;
  48. };
  49. /* dynamic per-device compression frontend */
  50. struct zcomp {
  51. struct zcomp_strm __percpu *stream;
  52. const struct zcomp_ops *ops;
  53. struct zcomp_params *params;
  54. struct hlist_node node;
  55. };
  56. int zcomp_cpu_up_prepare(unsigned int cpu, struct hlist_node *node);
  57. int zcomp_cpu_dead(unsigned int cpu, struct hlist_node *node);
  58. ssize_t zcomp_available_show(const char *comp, char *buf);
  59. bool zcomp_available_algorithm(const char *comp);
  60. struct zcomp *zcomp_create(const char *alg, struct zcomp_params *params);
  61. void zcomp_destroy(struct zcomp *comp);
  62. struct zcomp_strm *zcomp_stream_get(struct zcomp *comp);
  63. void zcomp_stream_put(struct zcomp *comp);
  64. int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm,
  65. const void *src, unsigned int *dst_len);
  66. int zcomp_decompress(struct zcomp *comp, struct zcomp_strm *zstrm,
  67. const void *src, unsigned int src_len, void *dst);
  68. #endif /* _ZCOMP_H_ */