Xeon-SP boards: Factor out OCP VPD `get_cxl_mode()` impl
[coreboot2.git] / util / cbfstool / lzma / C / LzmaDec.h
blob1addabe55ae31c88b9205aa940ab74f5251f3f38
1 /* LzmaDec.h -- LZMA Decoder
2 2009-02-07 : Igor Pavlov : Public domain */
4 #ifndef __LZMA_DEC_H
5 #define __LZMA_DEC_H
7 #include "Types.h"
9 typedef uint16_t CLzmaProb;
11 /* ---------- LZMA Properties ---------- */
13 #define LZMA_PROPS_SIZE 5
15 struct CLzmaProps
17 unsigned lc, lp, pb;
18 uint32_t dicSize;
21 /* LzmaProps_Decode - decodes properties
22 Returns:
23 SZ_OK
24 SZ_ERROR_UNSUPPORTED - Unsupported properties
27 SRes LzmaProps_Decode(struct CLzmaProps *p, const uint8_t *data, unsigned size);
30 /* ---------- LZMA Decoder state ---------- */
32 /* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
33 Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
35 #define LZMA_REQUIRED_INPUT_MAX 20
37 struct CLzmaDec
39 struct CLzmaProps prop;
40 CLzmaProb *probs;
41 uint8_t *dic;
42 const uint8_t *buf;
43 uint32_t range, code;
44 size_t dicPos;
45 size_t dicBufSize;
46 uint32_t processedPos;
47 uint32_t checkDicSize;
48 unsigned state;
49 uint32_t reps[4];
50 unsigned remainLen;
51 int needFlush;
52 int needInitState;
53 uint32_t numProbs;
54 unsigned tempBufSize;
55 uint8_t tempBuf[LZMA_REQUIRED_INPUT_MAX];
58 #define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
60 void LzmaDec_Init(struct CLzmaDec *p);
62 /* There are two types of LZMA streams:
63 0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
64 1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */
66 enum ELzmaFinishMode
68 LZMA_FINISH_ANY, /* finish at any point */
69 LZMA_FINISH_END /* block must be finished at the end */
72 /* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
74 You must use LZMA_FINISH_END, when you know that current output buffer
75 covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
77 If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
78 and output value of destLen will be less than output buffer size limit.
79 You can check status result also.
81 You can use multiple checks to test data integrity after full decompression:
82 1) Check Result and "status" variable.
83 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
84 3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
85 You must use correct finish mode in that case. */
87 enum ELzmaStatus
89 LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */
90 LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */
91 LZMA_STATUS_NOT_FINISHED, /* stream was not finished */
92 LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */
93 LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */
96 /* ELzmaStatus is used only as output value for function call */
99 /* ---------- Interfaces ---------- */
101 /* There are 3 levels of interfaces:
102 1) Dictionary Interface
103 2) Buffer Interface
104 3) One Call Interface
105 You can select any of these interfaces, but don't mix functions from different
106 groups for same object. */
109 /* There are two variants to allocate state for Dictionary Interface:
110 1) LzmaDec_Allocate / LzmaDec_Free
111 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
112 You can use variant 2, if you set dictionary buffer manually.
113 For Buffer Interface you must always use variant 1.
115 LzmaDec_Allocate* can return:
116 SZ_OK
117 SZ_ERROR_MEM - Memory allocation error
118 SZ_ERROR_UNSUPPORTED - Unsupported properties
121 SRes LzmaDec_AllocateProbs(struct CLzmaDec *p, const uint8_t *props, unsigned propsSize, struct ISzAlloc *alloc);
122 void LzmaDec_FreeProbs(struct CLzmaDec *p, struct ISzAlloc *alloc);
124 SRes LzmaDec_Allocate(struct CLzmaDec *state, const uint8_t *prop, unsigned propsSize, struct ISzAlloc *alloc);
125 void LzmaDec_Free(struct CLzmaDec *state, struct ISzAlloc *alloc);
127 /* ---------- Dictionary Interface ---------- */
129 /* You can use it, if you want to eliminate the overhead for data copying from
130 dictionary to some other external buffer.
131 You must work with CLzmaDec variables directly in this interface.
133 STEPS:
134 LzmaDec_Constr()
135 LzmaDec_Allocate()
136 for (each new stream)
138 LzmaDec_Init()
139 while (it needs more decompression)
141 LzmaDec_DecodeToDic()
142 use data from CLzmaDec::dic and update CLzmaDec::dicPos
145 LzmaDec_Free()
148 /* LzmaDec_DecodeToDic
150 The decoding to internal dictionary buffer (CLzmaDec::dic).
151 You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
153 finishMode:
154 It has meaning only if the decoding reaches output limit (dicLimit).
155 LZMA_FINISH_ANY - Decode just dicLimit bytes.
156 LZMA_FINISH_END - Stream must be finished after dicLimit.
158 Returns:
159 SZ_OK
160 status:
161 LZMA_STATUS_FINISHED_WITH_MARK
162 LZMA_STATUS_NOT_FINISHED
163 LZMA_STATUS_NEEDS_MORE_INPUT
164 LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
165 SZ_ERROR_DATA - Data error
168 SRes LzmaDec_DecodeToDic(struct CLzmaDec *p, size_t dicLimit,
169 const uint8_t *src, size_t *srcLen, enum ELzmaFinishMode finishMode, enum ELzmaStatus *status);
172 /* ---------- Buffer Interface ---------- */
174 /* It's zlib-like interface.
175 See LzmaDec_DecodeToDic description for information about STEPS and return results,
176 but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
177 to work with CLzmaDec variables manually.
179 finishMode:
180 It has meaning only if the decoding reaches output limit (*destLen).
181 LZMA_FINISH_ANY - Decode just destLen bytes.
182 LZMA_FINISH_END - Stream must be finished after (*destLen).
185 SRes LzmaDec_DecodeToBuf(struct CLzmaDec *p, uint8_t *dest, size_t *destLen,
186 const uint8_t *src, size_t *srcLen, enum ELzmaFinishMode finishMode, enum ELzmaStatus *status);
189 /* ---------- One Call Interface ---------- */
191 /* LzmaDecode
193 finishMode:
194 It has meaning only if the decoding reaches output limit (*destLen).
195 LZMA_FINISH_ANY - Decode just destLen bytes.
196 LZMA_FINISH_END - Stream must be finished after (*destLen).
198 Returns:
199 SZ_OK
200 status:
201 LZMA_STATUS_FINISHED_WITH_MARK
202 LZMA_STATUS_NOT_FINISHED
203 LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
204 SZ_ERROR_DATA - Data error
205 SZ_ERROR_MEM - Memory allocation error
206 SZ_ERROR_UNSUPPORTED - Unsupported properties
207 SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
210 SRes LzmaDecode(uint8_t *dest, size_t *destLen, const uint8_t *src, size_t *srcLen,
211 const uint8_t *propData, unsigned propSize, enum ELzmaFinishMode finishMode,
212 enum ELzmaStatus *status, struct ISzAlloc *alloc);
214 #endif