xref: /linux/arch/s390/boot/decompressor.c (revision 9c3205b2b062420c26b33924b910880889acf832)
1edd4a866SHeiko Carstens // SPDX-License-Identifier: GPL-2.0
2edd4a866SHeiko Carstens /*
3edd4a866SHeiko Carstens  * Definitions and wrapper functions for kernel decompressor
4edd4a866SHeiko Carstens  *
5edd4a866SHeiko Carstens  * Copyright IBM Corp. 2010
6edd4a866SHeiko Carstens  *
7edd4a866SHeiko Carstens  * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
8edd4a866SHeiko Carstens  */
9edd4a866SHeiko Carstens 
10edd4a866SHeiko Carstens #include <linux/kernel.h>
11edd4a866SHeiko Carstens #include <linux/string.h>
12edd4a866SHeiko Carstens #include <asm/page.h>
13edd4a866SHeiko Carstens #include "decompressor.h"
14*9c3205b2SAlexander Gordeev #include "boot.h"
15edd4a866SHeiko Carstens 
16edd4a866SHeiko Carstens /*
17edd4a866SHeiko Carstens  * gzip declarations
18edd4a866SHeiko Carstens  */
19edd4a866SHeiko Carstens #define STATIC static
20edd4a866SHeiko Carstens 
21edd4a866SHeiko Carstens #undef memset
22edd4a866SHeiko Carstens #undef memcpy
23edd4a866SHeiko Carstens #undef memmove
24edd4a866SHeiko Carstens #define memmove memmove
25edd4a866SHeiko Carstens #define memzero(s, n) memset((s), 0, (n))
26edd4a866SHeiko Carstens 
27edd4a866SHeiko Carstens #ifdef CONFIG_KERNEL_BZIP2
28edd4a866SHeiko Carstens #define BOOT_HEAP_SIZE	0x400000
29edd4a866SHeiko Carstens #elif CONFIG_KERNEL_ZSTD
30edd4a866SHeiko Carstens #define BOOT_HEAP_SIZE	0x30000
31edd4a866SHeiko Carstens #else
32edd4a866SHeiko Carstens #define BOOT_HEAP_SIZE	0x10000
33edd4a866SHeiko Carstens #endif
34edd4a866SHeiko Carstens 
35edd4a866SHeiko Carstens static unsigned long free_mem_ptr = (unsigned long) _end;
36edd4a866SHeiko Carstens static unsigned long free_mem_end_ptr = (unsigned long) _end + BOOT_HEAP_SIZE;
37edd4a866SHeiko Carstens 
38edd4a866SHeiko Carstens #ifdef CONFIG_KERNEL_GZIP
39edd4a866SHeiko Carstens #include "../../../../lib/decompress_inflate.c"
40edd4a866SHeiko Carstens #endif
41edd4a866SHeiko Carstens 
42edd4a866SHeiko Carstens #ifdef CONFIG_KERNEL_BZIP2
43edd4a866SHeiko Carstens #include "../../../../lib/decompress_bunzip2.c"
44edd4a866SHeiko Carstens #endif
45edd4a866SHeiko Carstens 
46edd4a866SHeiko Carstens #ifdef CONFIG_KERNEL_LZ4
47edd4a866SHeiko Carstens #include "../../../../lib/decompress_unlz4.c"
48edd4a866SHeiko Carstens #endif
49edd4a866SHeiko Carstens 
50edd4a866SHeiko Carstens #ifdef CONFIG_KERNEL_LZMA
51edd4a866SHeiko Carstens #include "../../../../lib/decompress_unlzma.c"
52edd4a866SHeiko Carstens #endif
53edd4a866SHeiko Carstens 
54edd4a866SHeiko Carstens #ifdef CONFIG_KERNEL_LZO
55edd4a866SHeiko Carstens #include "../../../../lib/decompress_unlzo.c"
56edd4a866SHeiko Carstens #endif
57edd4a866SHeiko Carstens 
58edd4a866SHeiko Carstens #ifdef CONFIG_KERNEL_XZ
59edd4a866SHeiko Carstens #include "../../../../lib/decompress_unxz.c"
60edd4a866SHeiko Carstens #endif
61edd4a866SHeiko Carstens 
62edd4a866SHeiko Carstens #ifdef CONFIG_KERNEL_ZSTD
63edd4a866SHeiko Carstens #include "../../../../lib/decompress_unzstd.c"
64edd4a866SHeiko Carstens #endif
65edd4a866SHeiko Carstens 
66edd4a866SHeiko Carstens #define decompress_offset ALIGN((unsigned long)_end + BOOT_HEAP_SIZE, PAGE_SIZE)
67edd4a866SHeiko Carstens 
68edd4a866SHeiko Carstens unsigned long mem_safe_offset(void)
69edd4a866SHeiko Carstens {
70edd4a866SHeiko Carstens 	/*
71edd4a866SHeiko Carstens 	 * due to 4MB HEAD_SIZE for bzip2
72edd4a866SHeiko Carstens 	 * 'decompress_offset + vmlinux.image_size' could be larger than
73edd4a866SHeiko Carstens 	 * kernel at final position + its .bss, so take the larger of two
74edd4a866SHeiko Carstens 	 */
75edd4a866SHeiko Carstens 	return max(decompress_offset + vmlinux.image_size,
76edd4a866SHeiko Carstens 		   vmlinux.default_lma + vmlinux.image_size + vmlinux.bss_size);
77edd4a866SHeiko Carstens }
78edd4a866SHeiko Carstens 
79edd4a866SHeiko Carstens void *decompress_kernel(void)
80edd4a866SHeiko Carstens {
81edd4a866SHeiko Carstens 	void *output = (void *)decompress_offset;
82edd4a866SHeiko Carstens 
83edd4a866SHeiko Carstens 	__decompress(_compressed_start, _compressed_end - _compressed_start,
84edd4a866SHeiko Carstens 		     NULL, NULL, output, 0, NULL, error);
85edd4a866SHeiko Carstens 	return output;
86edd4a866SHeiko Carstens }
87