[adm5120] fix support for 2.6.38 kernel
[openwrt.git] / package / compcache / patches / 000-provide_lzo_kmod.patch
1 --- a/Makefile
2 +++ b/Makefile
3 @@ -1,14 +1,17 @@
4 KERNEL_BUILD_PATH ?= "/lib/modules/$(shell uname -r)/build"
5
6 XVM = sub-projects/allocators/xvmalloc-kmod
7 +LZO = sub-projects/compression/lzo-kmod
8 EXTRA_CFLAGS := -DCONFIG_RAMZSWAP_STATS \
9 -Wall
10
11 -obj-m += ramzswap.o
12 +obj-m += ramzswap.o $(LZO)/lzo1x.o
13 ramzswap-objs := ramzswap_drv.o $(XVM)/xvmalloc.o
14 +
15
16 all:
17 make -C $(KERNEL_BUILD_PATH) M=$(PWD) modules
18 + make -C $(KERNEL_BUILD_PATH) M=$(PWD)/$(LZO) modules
19 make -C sub-projects/rzscontrol
20
21 doc:
22 @@ -16,5 +19,6 @@ doc:
23
24 clean:
25 make -C $(KERNEL_BUILD_PATH) M=$(PWD) clean
26 + make -C $(KERNEL_BUILD_PATH) M=$(PWD)/$(LZO) clean
27 make -C sub-projects/rzscontrol clean
28 @rm -rf *.ko
29 --- a/ramzswap_drv.c
30 +++ b/ramzswap_drv.c
31 @@ -23,13 +23,13 @@
32 #include <linux/device.h>
33 #include <linux/genhd.h>
34 #include <linux/highmem.h>
35 -#include <linux/lzo.h>
36 #include <linux/string.h>
37 #include <linux/swap.h>
38 #include <linux/swapops.h>
39 #include <linux/vmalloc.h>
40 #include <linux/version.h>
41
42 +#include "lzo.h"
43 #include "compat.h"
44 #include "ramzswap_drv.h"
45
46 --- /dev/null
47 +++ b/sub-projects/compression/lzo-kmod/lzo1x.c
48 @@ -0,0 +1,7 @@
49 +#include <linux/module.h>
50 +
51 +#include "lzo1x_compress.c"
52 +#include "lzo1x_decompress.c"
53 +
54 +MODULE_LICENSE("GPL");
55 +MODULE_DESCRIPTION("LZO1X Lib");
56 --- /dev/null
57 +++ b/sub-projects/compression/lzo-kmod/lzo1x_compress.c
58 @@ -0,0 +1,227 @@
59 +/*
60 + * LZO1X Compressor from MiniLZO
61 + *
62 + * Copyright (C) 1996-2005 Markus F.X.J. Oberhumer <markus@oberhumer.com>
63 + *
64 + * The full LZO package can be found at:
65 + * http://www.oberhumer.com/opensource/lzo/
66 + *
67 + * Changed for kernel use by:
68 + * Nitin Gupta <nitingupta910@gmail.com>
69 + * Richard Purdie <rpurdie@openedhand.com>
70 + */
71 +
72 +#include <linux/module.h>
73 +#include <linux/kernel.h>
74 +#include <asm/unaligned.h>
75 +
76 +#include "lzodefs.h"
77 +#include "lzo.h"
78 +
79 +static noinline size_t
80 +_lzo1x_1_do_compress(const unsigned char *in, size_t in_len,
81 + unsigned char *out, size_t *out_len, void *wrkmem)
82 +{
83 + const unsigned char * const in_end = in + in_len;
84 + const unsigned char * const ip_end = in + in_len - M2_MAX_LEN - 5;
85 + const unsigned char ** const dict = wrkmem;
86 + const unsigned char *ip = in, *ii = ip;
87 + const unsigned char *end, *m, *m_pos;
88 + size_t m_off, m_len, dindex;
89 + unsigned char *op = out;
90 +
91 + ip += 4;
92 +
93 + for (;;) {
94 + dindex = ((size_t)(0x21 * DX3(ip, 5, 5, 6)) >> 5) & D_MASK;
95 + m_pos = dict[dindex];
96 +
97 + if (m_pos < in)
98 + goto literal;
99 +
100 + if (ip == m_pos || ((size_t)(ip - m_pos) > M4_MAX_OFFSET))
101 + goto literal;
102 +
103 + m_off = ip - m_pos;
104 + if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
105 + goto try_match;
106 +
107 + dindex = (dindex & (D_MASK & 0x7ff)) ^ (D_HIGH | 0x1f);
108 + m_pos = dict[dindex];
109 +
110 + if (m_pos < in)
111 + goto literal;
112 +
113 + if (ip == m_pos || ((size_t)(ip - m_pos) > M4_MAX_OFFSET))
114 + goto literal;
115 +
116 + m_off = ip - m_pos;
117 + if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
118 + goto try_match;
119 +
120 + goto literal;
121 +
122 +try_match:
123 + if (get_unaligned((const unsigned short *)m_pos)
124 + == get_unaligned((const unsigned short *)ip)) {
125 + if (likely(m_pos[2] == ip[2]))
126 + goto match;
127 + }
128 +
129 +literal:
130 + dict[dindex] = ip;
131 + ++ip;
132 + if (unlikely(ip >= ip_end))
133 + break;
134 + continue;
135 +
136 +match:
137 + dict[dindex] = ip;
138 + if (ip != ii) {
139 + size_t t = ip - ii;
140 +
141 + if (t <= 3) {
142 + op[-2] |= t;
143 + } else if (t <= 18) {
144 + *op++ = (t - 3);
145 + } else {
146 + size_t tt = t - 18;
147 +
148 + *op++ = 0;
149 + while (tt > 255) {
150 + tt -= 255;
151 + *op++ = 0;
152 + }
153 + *op++ = tt;
154 + }
155 + do {
156 + *op++ = *ii++;
157 + } while (--t > 0);
158 + }
159 +
160 + ip += 3;
161 + if (m_pos[3] != *ip++ || m_pos[4] != *ip++
162 + || m_pos[5] != *ip++ || m_pos[6] != *ip++
163 + || m_pos[7] != *ip++ || m_pos[8] != *ip++) {
164 + --ip;
165 + m_len = ip - ii;
166 +
167 + if (m_off <= M2_MAX_OFFSET) {
168 + m_off -= 1;
169 + *op++ = (((m_len - 1) << 5)
170 + | ((m_off & 7) << 2));
171 + *op++ = (m_off >> 3);
172 + } else if (m_off <= M3_MAX_OFFSET) {
173 + m_off -= 1;
174 + *op++ = (M3_MARKER | (m_len - 2));
175 + goto m3_m4_offset;
176 + } else {
177 + m_off -= 0x4000;
178 +
179 + *op++ = (M4_MARKER | ((m_off & 0x4000) >> 11)
180 + | (m_len - 2));
181 + goto m3_m4_offset;
182 + }
183 + } else {
184 + end = in_end;
185 + m = m_pos + M2_MAX_LEN + 1;
186 +
187 + while (ip < end && *m == *ip) {
188 + m++;
189 + ip++;
190 + }
191 + m_len = ip - ii;
192 +
193 + if (m_off <= M3_MAX_OFFSET) {
194 + m_off -= 1;
195 + if (m_len <= 33) {
196 + *op++ = (M3_MARKER | (m_len - 2));
197 + } else {
198 + m_len -= 33;
199 + *op++ = M3_MARKER | 0;
200 + goto m3_m4_len;
201 + }
202 + } else {
203 + m_off -= 0x4000;
204 + if (m_len <= M4_MAX_LEN) {
205 + *op++ = (M4_MARKER
206 + | ((m_off & 0x4000) >> 11)
207 + | (m_len - 2));
208 + } else {
209 + m_len -= M4_MAX_LEN;
210 + *op++ = (M4_MARKER
211 + | ((m_off & 0x4000) >> 11));
212 +m3_m4_len:
213 + while (m_len > 255) {
214 + m_len -= 255;
215 + *op++ = 0;
216 + }
217 +
218 + *op++ = (m_len);
219 + }
220 + }
221 +m3_m4_offset:
222 + *op++ = ((m_off & 63) << 2);
223 + *op++ = (m_off >> 6);
224 + }
225 +
226 + ii = ip;
227 + if (unlikely(ip >= ip_end))
228 + break;
229 + }
230 +
231 + *out_len = op - out;
232 + return in_end - ii;
233 +}
234 +
235 +int lzo1x_1_compress(const unsigned char *in, size_t in_len, unsigned char *out,
236 + size_t *out_len, void *wrkmem)
237 +{
238 + const unsigned char *ii;
239 + unsigned char *op = out;
240 + size_t t;
241 +
242 + if (unlikely(in_len <= M2_MAX_LEN + 5)) {
243 + t = in_len;
244 + } else {
245 + t = _lzo1x_1_do_compress(in, in_len, op, out_len, wrkmem);
246 + op += *out_len;
247 + }
248 +
249 + if (t > 0) {
250 + ii = in + in_len - t;
251 +
252 + if (op == out && t <= 238) {
253 + *op++ = (17 + t);
254 + } else if (t <= 3) {
255 + op[-2] |= t;
256 + } else if (t <= 18) {
257 + *op++ = (t - 3);
258 + } else {
259 + size_t tt = t - 18;
260 +
261 + *op++ = 0;
262 + while (tt > 255) {
263 + tt -= 255;
264 + *op++ = 0;
265 + }
266 +
267 + *op++ = tt;
268 + }
269 + do {
270 + *op++ = *ii++;
271 + } while (--t > 0);
272 + }
273 +
274 + *op++ = M4_MARKER | 1;
275 + *op++ = 0;
276 + *op++ = 0;
277 +
278 + *out_len = op - out;
279 + return LZO_E_OK;
280 +}
281 +EXPORT_SYMBOL_GPL(lzo1x_1_compress);
282 +
283 +MODULE_LICENSE("GPL");
284 +MODULE_DESCRIPTION("LZO1X-1 Compressor");
285 +
286 --- /dev/null
287 +++ b/sub-projects/compression/lzo-kmod/lzo1x_decompress.c
288 @@ -0,0 +1,255 @@
289 +/*
290 + * LZO1X Decompressor from MiniLZO
291 + *
292 + * Copyright (C) 1996-2005 Markus F.X.J. Oberhumer <markus@oberhumer.com>
293 + *
294 + * The full LZO package can be found at:
295 + * http://www.oberhumer.com/opensource/lzo/
296 + *
297 + * Changed for kernel use by:
298 + * Nitin Gupta <nitingupta910@gmail.com>
299 + * Richard Purdie <rpurdie@openedhand.com>
300 + */
301 +
302 +#include <linux/module.h>
303 +#include <linux/kernel.h>
304 +#include <asm/byteorder.h>
305 +#include <asm/unaligned.h>
306 +
307 +#include "lzodefs.h"
308 +#include "lzo.h"
309 +
310 +#define HAVE_IP(x, ip_end, ip) ((size_t)(ip_end - ip) < (x))
311 +#define HAVE_OP(x, op_end, op) ((size_t)(op_end - op) < (x))
312 +#define HAVE_LB(m_pos, out, op) (m_pos < out || m_pos >= op)
313 +
314 +#define COPY4(dst, src) \
315 + put_unaligned(get_unaligned((const u32 *)(src)), (u32 *)(dst))
316 +
317 +int lzo1x_decompress_safe(const unsigned char *in, size_t in_len,
318 + unsigned char *out, size_t *out_len)
319 +{
320 + const unsigned char * const ip_end = in + in_len;
321 + unsigned char * const op_end = out + *out_len;
322 + const unsigned char *ip = in, *m_pos;
323 + unsigned char *op = out;
324 + size_t t;
325 +
326 + *out_len = 0;
327 +
328 + if (*ip > 17) {
329 + t = *ip++ - 17;
330 + if (t < 4)
331 + goto match_next;
332 + if (HAVE_OP(t, op_end, op))
333 + goto output_overrun;
334 + if (HAVE_IP(t + 1, ip_end, ip))
335 + goto input_overrun;
336 + do {
337 + *op++ = *ip++;
338 + } while (--t > 0);
339 + goto first_literal_run;
340 + }
341 +
342 + while ((ip < ip_end)) {
343 + t = *ip++;
344 + if (t >= 16)
345 + goto match;
346 + if (t == 0) {
347 + if (HAVE_IP(1, ip_end, ip))
348 + goto input_overrun;
349 + while (*ip == 0) {
350 + t += 255;
351 + ip++;
352 + if (HAVE_IP(1, ip_end, ip))
353 + goto input_overrun;
354 + }
355 + t += 15 + *ip++;
356 + }
357 + if (HAVE_OP(t + 3, op_end, op))
358 + goto output_overrun;
359 + if (HAVE_IP(t + 4, ip_end, ip))
360 + goto input_overrun;
361 +
362 + COPY4(op, ip);
363 + op += 4;
364 + ip += 4;
365 + if (--t > 0) {
366 + if (t >= 4) {
367 + do {
368 + COPY4(op, ip);
369 + op += 4;
370 + ip += 4;
371 + t -= 4;
372 + } while (t >= 4);
373 + if (t > 0) {
374 + do {
375 + *op++ = *ip++;
376 + } while (--t > 0);
377 + }
378 + } else {
379 + do {
380 + *op++ = *ip++;
381 + } while (--t > 0);
382 + }
383 + }
384 +
385 +first_literal_run:
386 + t = *ip++;
387 + if (t >= 16)
388 + goto match;
389 + m_pos = op - (1 + M2_MAX_OFFSET);
390 + m_pos -= t >> 2;
391 + m_pos -= *ip++ << 2;
392 +
393 + if (HAVE_LB(m_pos, out, op))
394 + goto lookbehind_overrun;
395 +
396 + if (HAVE_OP(3, op_end, op))
397 + goto output_overrun;
398 + *op++ = *m_pos++;
399 + *op++ = *m_pos++;
400 + *op++ = *m_pos;
401 +
402 + goto match_done;
403 +
404 + do {
405 +match:
406 + if (t >= 64) {
407 + m_pos = op - 1;
408 + m_pos -= (t >> 2) & 7;
409 + m_pos -= *ip++ << 3;
410 + t = (t >> 5) - 1;
411 + if (HAVE_LB(m_pos, out, op))
412 + goto lookbehind_overrun;
413 + if (HAVE_OP(t + 3 - 1, op_end, op))
414 + goto output_overrun;
415 + goto copy_match;
416 + } else if (t >= 32) {
417 + t &= 31;
418 + if (t == 0) {
419 + if (HAVE_IP(1, ip_end, ip))
420 + goto input_overrun;
421 + while (*ip == 0) {
422 + t += 255;
423 + ip++;
424 + if (HAVE_IP(1, ip_end, ip))
425 + goto input_overrun;
426 + }
427 + t += 31 + *ip++;
428 + }
429 + m_pos = op - 1;
430 + m_pos -= le16_to_cpu(get_unaligned(
431 + (const unsigned short *)ip)) >> 2;
432 + ip += 2;
433 + } else if (t >= 16) {
434 + m_pos = op;
435 + m_pos -= (t & 8) << 11;
436 +
437 + t &= 7;
438 + if (t == 0) {
439 + if (HAVE_IP(1, ip_end, ip))
440 + goto input_overrun;
441 + while (*ip == 0) {
442 + t += 255;
443 + ip++;
444 + if (HAVE_IP(1, ip_end, ip))
445 + goto input_overrun;
446 + }
447 + t += 7 + *ip++;
448 + }
449 + m_pos -= le16_to_cpu(get_unaligned(
450 + (const unsigned short *)ip)) >> 2;
451 + ip += 2;
452 + if (m_pos == op)
453 + goto eof_found;
454 + m_pos -= 0x4000;
455 + } else {
456 + m_pos = op - 1;
457 + m_pos -= t >> 2;
458 + m_pos -= *ip++ << 2;
459 +
460 + if (HAVE_LB(m_pos, out, op))
461 + goto lookbehind_overrun;
462 + if (HAVE_OP(2, op_end, op))
463 + goto output_overrun;
464 +
465 + *op++ = *m_pos++;
466 + *op++ = *m_pos;
467 + goto match_done;
468 + }
469 +
470 + if (HAVE_LB(m_pos, out, op))
471 + goto lookbehind_overrun;
472 + if (HAVE_OP(t + 3 - 1, op_end, op))
473 + goto output_overrun;
474 +
475 + if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) {
476 + COPY4(op, m_pos);
477 + op += 4;
478 + m_pos += 4;
479 + t -= 4 - (3 - 1);
480 + do {
481 + COPY4(op, m_pos);
482 + op += 4;
483 + m_pos += 4;
484 + t -= 4;
485 + } while (t >= 4);
486 + if (t > 0)
487 + do {
488 + *op++ = *m_pos++;
489 + } while (--t > 0);
490 + } else {
491 +copy_match:
492 + *op++ = *m_pos++;
493 + *op++ = *m_pos++;
494 + do {
495 + *op++ = *m_pos++;
496 + } while (--t > 0);
497 + }
498 +match_done:
499 + t = ip[-2] & 3;
500 + if (t == 0)
501 + break;
502 +match_next:
503 + if (HAVE_OP(t, op_end, op))
504 + goto output_overrun;
505 + if (HAVE_IP(t + 1, ip_end, ip))
506 + goto input_overrun;
507 +
508 + *op++ = *ip++;
509 + if (t > 1) {
510 + *op++ = *ip++;
511 + if (t > 2)
512 + *op++ = *ip++;
513 + }
514 +
515 + t = *ip++;
516 + } while (ip < ip_end);
517 + }
518 +
519 + *out_len = op - out;
520 + return LZO_E_EOF_NOT_FOUND;
521 +
522 +eof_found:
523 + *out_len = op - out;
524 + return (ip == ip_end ? LZO_E_OK :
525 + (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
526 +input_overrun:
527 + *out_len = op - out;
528 + return LZO_E_INPUT_OVERRUN;
529 +
530 +output_overrun:
531 + *out_len = op - out;
532 + return LZO_E_OUTPUT_OVERRUN;
533 +
534 +lookbehind_overrun:
535 + *out_len = op - out;
536 + return LZO_E_LOOKBEHIND_OVERRUN;
537 +}
538 +
539 +EXPORT_SYMBOL_GPL(lzo1x_decompress_safe);
540 +
541 +MODULE_LICENSE("GPL");
542 +MODULE_DESCRIPTION("LZO1X Decompressor");
543 +
544 --- /dev/null
545 +++ b/sub-projects/compression/lzo-kmod/lzodefs.h
546 @@ -0,0 +1,43 @@
547 +/*
548 + * lzodefs.h -- architecture, OS and compiler specific defines
549 + *
550 + * Copyright (C) 1996-2005 Markus F.X.J. Oberhumer <markus@oberhumer.com>
551 + *
552 + * The full LZO package can be found at:
553 + * http://www.oberhumer.com/opensource/lzo/
554 + *
555 + * Changed for kernel use by:
556 + * Nitin Gupta <nitingupta910@gmail.com>
557 + * Richard Purdie <rpurdie@openedhand.com>
558 + */
559 +
560 +#define LZO_VERSION 0x2020
561 +#define LZO_VERSION_STRING "2.02"
562 +#define LZO_VERSION_DATE "Oct 17 2005"
563 +
564 +#define M1_MAX_OFFSET 0x0400
565 +#define M2_MAX_OFFSET 0x0800
566 +#define M3_MAX_OFFSET 0x4000
567 +#define M4_MAX_OFFSET 0xbfff
568 +
569 +#define M1_MIN_LEN 2
570 +#define M1_MAX_LEN 2
571 +#define M2_MIN_LEN 3
572 +#define M2_MAX_LEN 8
573 +#define M3_MIN_LEN 3
574 +#define M3_MAX_LEN 33
575 +#define M4_MIN_LEN 3
576 +#define M4_MAX_LEN 9
577 +
578 +#define M1_MARKER 0
579 +#define M2_MARKER 64
580 +#define M3_MARKER 32
581 +#define M4_MARKER 16
582 +
583 +#define D_BITS 14
584 +#define D_MASK ((1u << D_BITS) - 1)
585 +#define D_HIGH ((D_MASK >> 1) + 1)
586 +
587 +#define DX2(p, s1, s2) (((((size_t)((p)[2]) << (s2)) ^ (p)[1]) \
588 + << (s1)) ^ (p)[0])
589 +#define DX3(p, s1, s2, s3) ((DX2((p)+1, s2, s3) << (s1)) ^ (p)[0])
590 --- /dev/null
591 +++ b/sub-projects/compression/lzo-kmod/lzo.h
592 @@ -0,0 +1,44 @@
593 +#ifndef __LZO_H__
594 +#define __LZO_H__
595 +/*
596 + * LZO Public Kernel Interface
597 + * A mini subset of the LZO real-time data compression library
598 + *
599 + * Copyright (C) 1996-2005 Markus F.X.J. Oberhumer <markus@oberhumer.com>
600 + *
601 + * The full LZO package can be found at:
602 + * http://www.oberhumer.com/opensource/lzo/
603 + *
604 + * Changed for kernel use by:
605 + * Nitin Gupta <nitingupta910@gmail.com>
606 + * Richard Purdie <rpurdie@openedhand.com>
607 + */
608 +
609 +#define LZO1X_MEM_COMPRESS (16384 * sizeof(unsigned char *))
610 +#define LZO1X_1_MEM_COMPRESS LZO1X_MEM_COMPRESS
611 +
612 +#define lzo1x_worst_compress(x) ((x) + ((x) / 16) + 64 + 3)
613 +
614 +/* This requires 'workmem' of size LZO1X_1_MEM_COMPRESS */
615 +int lzo1x_1_compress(const unsigned char *src, size_t src_len,
616 + unsigned char *dst, size_t *dst_len, void *wrkmem);
617 +
618 +/* safe decompression with overrun testing */
619 +int lzo1x_decompress_safe(const unsigned char *src, size_t src_len,
620 + unsigned char *dst, size_t *dst_len);
621 +
622 +/*
623 + * Return values (< 0 = Error)
624 + */
625 +#define LZO_E_OK 0
626 +#define LZO_E_ERROR (-1)
627 +#define LZO_E_OUT_OF_MEMORY (-2)
628 +#define LZO_E_NOT_COMPRESSIBLE (-3)
629 +#define LZO_E_INPUT_OVERRUN (-4)
630 +#define LZO_E_OUTPUT_OVERRUN (-5)
631 +#define LZO_E_LOOKBEHIND_OVERRUN (-6)
632 +#define LZO_E_EOF_NOT_FOUND (-7)
633 +#define LZO_E_INPUT_NOT_CONSUMED (-8)
634 +#define LZO_E_NOT_YET_IMPLEMENTED (-9)
635 +
636 +#endif
637 --- /dev/null
638 +++ b/sub-projects/compression/lzo-kmod/Makefile
639 @@ -0,0 +1,8 @@
640 +obj-m += lzo1x_compress.o lzo1x_decompress.o
641 +
642 +all:
643 + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
644 +
645 +clean:
646 + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
647 +
This page took 0.078166 seconds and 5 git commands to generate.