dfltcc.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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(sizeof(struct dfltcc_param_v0) == 1536);
  76. #define CVT_CRC32 0
  77. #define CVT_ADLER32 1
  78. #define HTT_FIXED 0
  79. #define HTT_DYNAMIC 1
  80. /*
  81. * Extension of inflate_state and deflate_state for DFLTCC.
  82. */
  83. struct dfltcc_state {
  84. struct dfltcc_param_v0 param; /* Parameter block */
  85. struct dfltcc_qaf_param af; /* Available functions */
  86. uLong level_mask; /* Levels on which to use DFLTCC */
  87. uLong block_size; /* New block each X bytes */
  88. uLong block_threshold; /* New block after total_in > X */
  89. uLong dht_threshold; /* New block only if avail_in >= X */
  90. char msg[64]; /* Buffer for strm->msg */
  91. };
  92. /* Resides right after inflate_state or deflate_state */
  93. #define GET_DFLTCC_STATE(state) ((struct dfltcc_state *)((state) + 1))
  94. /* External functions */
  95. int dfltcc_can_deflate(z_streamp strm);
  96. int dfltcc_deflate(z_streamp strm,
  97. int flush,
  98. block_state *result);
  99. void dfltcc_reset(z_streamp strm, uInt size);
  100. int dfltcc_can_inflate(z_streamp strm);
  101. typedef enum {
  102. DFLTCC_INFLATE_CONTINUE,
  103. DFLTCC_INFLATE_BREAK,
  104. DFLTCC_INFLATE_SOFTWARE,
  105. } dfltcc_inflate_action;
  106. dfltcc_inflate_action dfltcc_inflate(z_streamp strm,
  107. int flush, int *ret);
  108. static inline int is_dfltcc_enabled(void)
  109. {
  110. return (zlib_dfltcc_support != ZLIB_DFLTCC_DISABLED &&
  111. test_facility(DFLTCC_FACILITY));
  112. }
  113. #define DEFLATE_RESET_HOOK(strm) \
  114. dfltcc_reset((strm), sizeof(deflate_state))
  115. #define DEFLATE_HOOK dfltcc_deflate
  116. #define DEFLATE_NEED_CHECKSUM(strm) (!dfltcc_can_deflate((strm)))
  117. #define DEFLATE_DFLTCC_ENABLED() is_dfltcc_enabled()
  118. #define INFLATE_RESET_HOOK(strm) \
  119. dfltcc_reset((strm), sizeof(struct inflate_state))
  120. #define INFLATE_TYPEDO_HOOK(strm, flush) \
  121. if (dfltcc_can_inflate((strm))) { \
  122. dfltcc_inflate_action action; \
  123. \
  124. RESTORE(); \
  125. action = dfltcc_inflate((strm), (flush), &ret); \
  126. LOAD(); \
  127. if (action == DFLTCC_INFLATE_CONTINUE) \
  128. break; \
  129. else if (action == DFLTCC_INFLATE_BREAK) \
  130. goto inf_leave; \
  131. }
  132. #define INFLATE_NEED_CHECKSUM(strm) (!dfltcc_can_inflate((strm)))
  133. #define INFLATE_NEED_UPDATEWINDOW(strm) (!dfltcc_can_inflate((strm)))
  134. #endif /* DFLTCC_H */