dfltcc.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // SPDX-License-Identifier: Zlib
  2. #ifndef DFLTCC_H
  3. #define DFLTCC_H
  4. #include "../zlib_deflate/defutil.h"
  5. #include <asm/facility.h>
  6. #include <asm/setup.h>
  7. /*
  8. * Tuning parameters.
  9. */
  10. #define DFLTCC_LEVEL_MASK 0x2 /* DFLTCC compression for level 1 only */
  11. #define DFLTCC_LEVEL_MASK_DEBUG 0x3fe /* DFLTCC compression for all levels */
  12. #define DFLTCC_BLOCK_SIZE 1048576
  13. #define DFLTCC_FIRST_FHT_BLOCK_SIZE 4096
  14. #define DFLTCC_DHT_MIN_SAMPLE_SIZE 4096
  15. #define DFLTCC_RIBM 0
  16. #define DFLTCC_FACILITY 151
  17. /*
  18. * Parameter Block for Query Available Functions.
  19. */
  20. struct dfltcc_qaf_param {
  21. char fns[16];
  22. char reserved1[8];
  23. char fmts[2];
  24. char reserved2[6];
  25. };
  26. static_assert(sizeof(struct dfltcc_qaf_param) == 32);
  27. #define DFLTCC_FMT0 0
  28. /*
  29. * Parameter Block for Generate Dynamic-Huffman Table, Compress and Expand.
  30. */
  31. struct dfltcc_param_v0 {
  32. uint16_t pbvn; /* Parameter-Block-Version Number */
  33. uint8_t mvn; /* Model-Version Number */
  34. uint8_t ribm; /* Reserved for IBM use */
  35. unsigned reserved32 : 31;
  36. unsigned cf : 1; /* Continuation Flag */
  37. uint8_t reserved64[8];
  38. unsigned nt : 1; /* New Task */
  39. unsigned reserved129 : 1;
  40. unsigned cvt : 1; /* Check Value Type */
  41. unsigned reserved131 : 1;
  42. unsigned htt : 1; /* Huffman-Table Type */
  43. unsigned bcf : 1; /* Block-Continuation Flag */
  44. unsigned bcc : 1; /* Block Closing Control */
  45. unsigned bhf : 1; /* Block Header Final */
  46. unsigned reserved136 : 1;
  47. unsigned reserved137 : 1;
  48. unsigned dhtgc : 1; /* DHT Generation Control */
  49. unsigned reserved139 : 5;
  50. unsigned reserved144 : 5;
  51. unsigned sbb : 3; /* Sub-Byte Boundary */
  52. uint8_t oesc; /* Operation-Ending-Supplemental Code */
  53. unsigned reserved160 : 12;
  54. unsigned ifs : 4; /* Incomplete-Function Status */
  55. uint16_t ifl; /* Incomplete-Function Length */
  56. uint8_t reserved192[8];
  57. uint8_t reserved256[8];
  58. uint8_t reserved320[4];
  59. uint16_t hl; /* History Length */
  60. unsigned reserved368 : 1;
  61. uint16_t ho : 15; /* History Offset */
  62. uint32_t cv; /* Check Value */
  63. unsigned eobs : 15; /* End-of-block Symbol */
  64. unsigned reserved431: 1;
  65. uint8_t eobl : 4; /* End-of-block Length */
  66. unsigned reserved436 : 12;
  67. unsigned reserved448 : 4;
  68. uint16_t cdhtl : 12; /* Compressed-Dynamic-Huffman Table
  69. Length */
  70. uint8_t reserved464[6];
  71. uint8_t cdht[288];
  72. uint8_t reserved[32];
  73. uint8_t csb[1152];
  74. };
  75. static_assert(offsetof(struct dfltcc_param_v0, csb) == 384);
  76. static_assert(sizeof(struct dfltcc_param_v0) == 1536);
  77. #define CVT_CRC32 0
  78. #define CVT_ADLER32 1
  79. #define HTT_FIXED 0
  80. #define HTT_DYNAMIC 1
  81. /*
  82. * Extension of inflate_state and deflate_state for DFLTCC.
  83. */
  84. struct dfltcc_state {
  85. struct dfltcc_param_v0 param; /* Parameter block */
  86. struct dfltcc_qaf_param af; /* Available functions */
  87. char msg[64]; /* Buffer for strm->msg */
  88. };
  89. /*
  90. * Extension of inflate_state and deflate_state for DFLTCC.
  91. */
  92. struct dfltcc_deflate_state {
  93. struct dfltcc_state common; /* Parameter block */
  94. uLong level_mask; /* Levels on which to use DFLTCC */
  95. uLong block_size; /* New block each X bytes */
  96. uLong block_threshold; /* New block after total_in > X */
  97. uLong dht_threshold; /* New block only if avail_in >= X */
  98. };
  99. #define ALIGN_UP(p, size) (__typeof__(p))(((uintptr_t)(p) + ((size) - 1)) & ~((size) - 1))
  100. /* Resides right after inflate_state or deflate_state */
  101. #define GET_DFLTCC_STATE(state) ((struct dfltcc_state *)((char *)(state) + ALIGN_UP(sizeof(*state), 8)))
  102. void dfltcc_reset_state(struct dfltcc_state *dfltcc_state);
  103. static inline int is_dfltcc_enabled(void)
  104. {
  105. return (zlib_dfltcc_support != ZLIB_DFLTCC_DISABLED &&
  106. test_facility(DFLTCC_FACILITY));
  107. }
  108. #define DEFLATE_DFLTCC_ENABLED() is_dfltcc_enabled()
  109. #endif /* DFLTCC_H */