1 // SPDX-License-Identifier: Zlib
5 #include "../zlib_deflate/defutil.h"
6 #include <asm/facility.h>
12 #define DFLTCC_LEVEL_MASK 0x2 /* DFLTCC compression for level 1 only */
13 #define DFLTCC_LEVEL_MASK_DEBUG 0x3fe /* DFLTCC compression for all levels */
14 #define DFLTCC_BLOCK_SIZE 1048576
15 #define DFLTCC_FIRST_FHT_BLOCK_SIZE 4096
16 #define DFLTCC_DHT_MIN_SAMPLE_SIZE 4096
19 #define DFLTCC_FACILITY 151
22 * Parameter Block for Query Available Functions.
24 struct dfltcc_qaf_param {
31 static_assert(sizeof(struct dfltcc_qaf_param) == 32);
36 * Parameter Block for Generate Dynamic-Huffman Table, Compress and Expand.
38 struct dfltcc_param_v0 {
39 uint16_t pbvn; /* Parameter-Block-Version Number */
40 uint8_t mvn; /* Model-Version Number */
41 uint8_t ribm; /* Reserved for IBM use */
42 unsigned reserved32 : 31;
43 unsigned cf : 1; /* Continuation Flag */
44 uint8_t reserved64[8];
45 unsigned nt : 1; /* New Task */
46 unsigned reserved129 : 1;
47 unsigned cvt : 1; /* Check Value Type */
48 unsigned reserved131 : 1;
49 unsigned htt : 1; /* Huffman-Table Type */
50 unsigned bcf : 1; /* Block-Continuation Flag */
51 unsigned bcc : 1; /* Block Closing Control */
52 unsigned bhf : 1; /* Block Header Final */
53 unsigned reserved136 : 1;
54 unsigned reserved137 : 1;
55 unsigned dhtgc : 1; /* DHT Generation Control */
56 unsigned reserved139 : 5;
57 unsigned reserved144 : 5;
58 unsigned sbb : 3; /* Sub-Byte Boundary */
59 uint8_t oesc; /* Operation-Ending-Supplemental Code */
60 unsigned reserved160 : 12;
61 unsigned ifs : 4; /* Incomplete-Function Status */
62 uint16_t ifl; /* Incomplete-Function Length */
63 uint8_t reserved192[8];
64 uint8_t reserved256[8];
65 uint8_t reserved320[4];
66 uint16_t hl; /* History Length */
67 unsigned reserved368 : 1;
68 uint16_t ho : 15; /* History Offset */
69 uint32_t cv; /* Check Value */
70 unsigned eobs : 15; /* End-of-block Symbol */
71 unsigned reserved431: 1;
72 uint8_t eobl : 4; /* End-of-block Length */
73 unsigned reserved436 : 12;
74 unsigned reserved448 : 4;
75 uint16_t cdhtl : 12; /* Compressed-Dynamic-Huffman Table
77 uint8_t reserved464[6];
83 static_assert(sizeof(struct dfltcc_param_v0) == 1536);
91 * Extension of inflate_state and deflate_state for DFLTCC.
94 struct dfltcc_param_v0 param; /* Parameter block */
95 struct dfltcc_qaf_param af; /* Available functions */
96 char msg[64]; /* Buffer for strm->msg */
100 * Extension of inflate_state and deflate_state for DFLTCC.
102 struct dfltcc_deflate_state {
103 struct dfltcc_state common; /* Parameter block */
104 uLong level_mask; /* Levels on which to use DFLTCC */
105 uLong block_size; /* New block each X bytes */
106 uLong block_threshold; /* New block after total_in > X */
107 uLong dht_threshold; /* New block only if avail_in >= X */
110 #define ALIGN_UP(p, size) (__typeof__(p))(((uintptr_t)(p) + ((size) - 1)) & ~((size) - 1))
111 /* Resides right after inflate_state or deflate_state */
112 #define GET_DFLTCC_STATE(state) ((struct dfltcc_state *)((char *)(state) + ALIGN_UP(sizeof(*state), 8)))
114 void dfltcc_reset_state(struct dfltcc_state *dfltcc_state);
116 static inline int is_dfltcc_enabled(void)
118 return (zlib_dfltcc_support != ZLIB_DFLTCC_DISABLED &&
119 test_facility(DFLTCC_FACILITY));
122 #define DEFLATE_DFLTCC_ENABLED() is_dfltcc_enabled()
124 #endif /* DFLTCC_H */