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 uLong level_mask
; /* Levels on which to use DFLTCC */
97 uLong block_size
; /* New block each X bytes */
98 uLong block_threshold
; /* New block after total_in > X */
99 uLong dht_threshold
; /* New block only if avail_in >= X */
100 char msg
[64]; /* Buffer for strm->msg */
103 /* Resides right after inflate_state or deflate_state */
104 #define GET_DFLTCC_STATE(state) ((struct dfltcc_state *)((state) + 1))
106 /* External functions */
107 int dfltcc_can_deflate(z_streamp strm
);
108 int dfltcc_deflate(z_streamp strm
,
110 block_state
*result
);
111 void dfltcc_reset(z_streamp strm
, uInt size
);
112 int dfltcc_can_inflate(z_streamp strm
);
114 DFLTCC_INFLATE_CONTINUE
,
115 DFLTCC_INFLATE_BREAK
,
116 DFLTCC_INFLATE_SOFTWARE
,
117 } dfltcc_inflate_action
;
118 dfltcc_inflate_action
dfltcc_inflate(z_streamp strm
,
119 int flush
, int *ret
);
120 static inline int is_dfltcc_enabled(void)
122 return (zlib_dfltcc_support
!= ZLIB_DFLTCC_DISABLED
&&
123 test_facility(DFLTCC_FACILITY
));
126 #define DEFLATE_RESET_HOOK(strm) \
127 dfltcc_reset((strm), sizeof(deflate_state))
129 #define DEFLATE_HOOK dfltcc_deflate
131 #define DEFLATE_NEED_CHECKSUM(strm) (!dfltcc_can_deflate((strm)))
133 #define DEFLATE_DFLTCC_ENABLED() is_dfltcc_enabled()
135 #define INFLATE_RESET_HOOK(strm) \
136 dfltcc_reset((strm), sizeof(struct inflate_state))
138 #define INFLATE_TYPEDO_HOOK(strm, flush) \
139 if (dfltcc_can_inflate((strm))) { \
140 dfltcc_inflate_action action; \
143 action = dfltcc_inflate((strm), (flush), &ret); \
145 if (action == DFLTCC_INFLATE_CONTINUE) \
147 else if (action == DFLTCC_INFLATE_BREAK) \
151 #define INFLATE_NEED_CHECKSUM(strm) (!dfltcc_can_inflate((strm)))
153 #define INFLATE_NEED_UPDATEWINDOW(strm) (!dfltcc_can_inflate((strm)))
155 #endif /* DFLTCC_H */