0001
0002 #ifndef DFLTCC_H
0003 #define DFLTCC_H
0004
0005 #include "../zlib_deflate/defutil.h"
0006 #include <asm/facility.h>
0007 #include <asm/setup.h>
0008
0009
0010
0011
0012 #define DFLTCC_LEVEL_MASK 0x2
0013 #define DFLTCC_LEVEL_MASK_DEBUG 0x3fe
0014 #define DFLTCC_BLOCK_SIZE 1048576
0015 #define DFLTCC_FIRST_FHT_BLOCK_SIZE 4096
0016 #define DFLTCC_DHT_MIN_SAMPLE_SIZE 4096
0017 #define DFLTCC_RIBM 0
0018
0019 #define DFLTCC_FACILITY 151
0020
0021
0022
0023
0024 struct dfltcc_qaf_param {
0025 char fns[16];
0026 char reserved1[8];
0027 char fmts[2];
0028 char reserved2[6];
0029 };
0030
0031 static_assert(sizeof(struct dfltcc_qaf_param) == 32);
0032
0033 #define DFLTCC_FMT0 0
0034
0035
0036
0037
0038 struct dfltcc_param_v0 {
0039 uint16_t pbvn;
0040 uint8_t mvn;
0041 uint8_t ribm;
0042 unsigned reserved32 : 31;
0043 unsigned cf : 1;
0044 uint8_t reserved64[8];
0045 unsigned nt : 1;
0046 unsigned reserved129 : 1;
0047 unsigned cvt : 1;
0048 unsigned reserved131 : 1;
0049 unsigned htt : 1;
0050 unsigned bcf : 1;
0051 unsigned bcc : 1;
0052 unsigned bhf : 1;
0053 unsigned reserved136 : 1;
0054 unsigned reserved137 : 1;
0055 unsigned dhtgc : 1;
0056 unsigned reserved139 : 5;
0057 unsigned reserved144 : 5;
0058 unsigned sbb : 3;
0059 uint8_t oesc;
0060 unsigned reserved160 : 12;
0061 unsigned ifs : 4;
0062 uint16_t ifl;
0063 uint8_t reserved192[8];
0064 uint8_t reserved256[8];
0065 uint8_t reserved320[4];
0066 uint16_t hl;
0067 unsigned reserved368 : 1;
0068 uint16_t ho : 15;
0069 uint32_t cv;
0070 unsigned eobs : 15;
0071 unsigned reserved431: 1;
0072 uint8_t eobl : 4;
0073 unsigned reserved436 : 12;
0074 unsigned reserved448 : 4;
0075 uint16_t cdhtl : 12;
0076
0077 uint8_t reserved464[6];
0078 uint8_t cdht[288];
0079 uint8_t reserved[32];
0080 uint8_t csb[1152];
0081 };
0082
0083 static_assert(sizeof(struct dfltcc_param_v0) == 1536);
0084
0085 #define CVT_CRC32 0
0086 #define CVT_ADLER32 1
0087 #define HTT_FIXED 0
0088 #define HTT_DYNAMIC 1
0089
0090
0091
0092
0093 struct dfltcc_state {
0094 struct dfltcc_param_v0 param;
0095 struct dfltcc_qaf_param af;
0096 uLong level_mask;
0097 uLong block_size;
0098 uLong block_threshold;
0099 uLong dht_threshold;
0100 char msg[64];
0101 };
0102
0103
0104 #define GET_DFLTCC_STATE(state) ((struct dfltcc_state *)((state) + 1))
0105
0106
0107 int dfltcc_can_deflate(z_streamp strm);
0108 int dfltcc_deflate(z_streamp strm,
0109 int flush,
0110 block_state *result);
0111 void dfltcc_reset(z_streamp strm, uInt size);
0112 int dfltcc_can_inflate(z_streamp strm);
0113 typedef enum {
0114 DFLTCC_INFLATE_CONTINUE,
0115 DFLTCC_INFLATE_BREAK,
0116 DFLTCC_INFLATE_SOFTWARE,
0117 } dfltcc_inflate_action;
0118 dfltcc_inflate_action dfltcc_inflate(z_streamp strm,
0119 int flush, int *ret);
0120 static inline int is_dfltcc_enabled(void)
0121 {
0122 return (zlib_dfltcc_support != ZLIB_DFLTCC_DISABLED &&
0123 test_facility(DFLTCC_FACILITY));
0124 }
0125
0126 #define DEFLATE_RESET_HOOK(strm) \
0127 dfltcc_reset((strm), sizeof(deflate_state))
0128
0129 #define DEFLATE_HOOK dfltcc_deflate
0130
0131 #define DEFLATE_NEED_CHECKSUM(strm) (!dfltcc_can_deflate((strm)))
0132
0133 #define DEFLATE_DFLTCC_ENABLED() is_dfltcc_enabled()
0134
0135 #define INFLATE_RESET_HOOK(strm) \
0136 dfltcc_reset((strm), sizeof(struct inflate_state))
0137
0138 #define INFLATE_TYPEDO_HOOK(strm, flush) \
0139 if (dfltcc_can_inflate((strm))) { \
0140 dfltcc_inflate_action action; \
0141 \
0142 RESTORE(); \
0143 action = dfltcc_inflate((strm), (flush), &ret); \
0144 LOAD(); \
0145 if (action == DFLTCC_INFLATE_CONTINUE) \
0146 break; \
0147 else if (action == DFLTCC_INFLATE_BREAK) \
0148 goto inf_leave; \
0149 }
0150
0151 #define INFLATE_NEED_CHECKSUM(strm) (!dfltcc_can_inflate((strm)))
0152
0153 #define INFLATE_NEED_UPDATEWINDOW(strm) (!dfltcc_can_inflate((strm)))
0154
0155 #endif