aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/boot
diff options
context:
space:
mode:
authorThomas Petazzoni <thomas.petazzoni@free-electrons.com>2008-07-25 04:45:44 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-25 13:53:28 -0400
commit2d6ffcca623a9a16df6cdfbe8250b7a5904a5f5e (patch)
tree70d30cb6516608e9a8a1dce60c59f3a5ff21b305 /arch/arm/boot
parentba92a43dbaee339cf5915ef766d3d3ffbaaf103c (diff)
inflate: refactor inflate malloc code
Inflate requires some dynamic memory allocation very early in the boot process and this is provided with a set of four functions: malloc/free/gzip_mark/gzip_release. The old inflate code used a mark/release strategy rather than implement free. This new version instead keeps a count on the number of outstanding allocations and when it hits zero, it resets the malloc arena. This allows removing all the mark and release implementations and unifying all the malloc/free implementations. The architecture-dependent code must define two addresses: - free_mem_ptr, the address of the beginning of the area in which allocations should be made - free_mem_end_ptr, the address of the end of the area in which allocations should be made. If set to 0, then no check is made on the number of allocations, it just grows as much as needed The architecture-dependent code can also provide an arch_decomp_wdog() function call. This function will be called several times during the decompression process, and allow to notify the watchdog that the system is still running. If an architecture provides such a call, then it must define ARCH_HAS_DECOMP_WDOG so that the generic inflate code calls arch_decomp_wdog(). Work initially done by Matt Mackall, updated to a recent version of the kernel and improved by me. [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> Cc: Matt Mackall <mpm@selenic.com> Cc: Richard Henderson <rth@twiddle.net> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru> Cc: Mikael Starvik <mikael.starvik@axis.com> Cc: Jesper Nilsson <jesper.nilsson@axis.com> Cc: Haavard Skinnemoen <hskinnemoen@atmel.com> Cc: David Howells <dhowells@redhat.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Andi Kleen <andi@firstfloor.org> Cc: "H. Peter Anvin" <hpa@zytor.com> Acked-by: Paul Mundt <lethal@linux-sh.org> Acked-by: Yoshinori Sato <ysato@users.sourceforge.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch/arm/boot')
-rw-r--r--arch/arm/boot/compressed/misc.c59
1 files changed, 7 insertions, 52 deletions
diff --git a/arch/arm/boot/compressed/misc.c b/arch/arm/boot/compressed/misc.c
index 9b444022cb9b..7145cc7c04f0 100644
--- a/arch/arm/boot/compressed/misc.c
+++ b/arch/arm/boot/compressed/misc.c
@@ -217,8 +217,6 @@ static unsigned outcnt; /* bytes in output buffer */
217static int fill_inbuf(void); 217static int fill_inbuf(void);
218static void flush_window(void); 218static void flush_window(void);
219static void error(char *m); 219static void error(char *m);
220static void gzip_mark(void **);
221static void gzip_release(void **);
222 220
223extern char input_data[]; 221extern char input_data[];
224extern char input_data_end[]; 222extern char input_data_end[];
@@ -227,64 +225,21 @@ static uch *output_data;
227static ulg output_ptr; 225static ulg output_ptr;
228static ulg bytes_out; 226static ulg bytes_out;
229 227
230static void *malloc(int size);
231static void free(void *where);
232static void error(char *m); 228static void error(char *m);
233static void gzip_mark(void **);
234static void gzip_release(void **);
235 229
236static void putstr(const char *); 230static void putstr(const char *);
237 231
238extern int end; 232extern int end;
239static ulg free_mem_ptr; 233static ulg free_mem_ptr;
240static ulg free_mem_ptr_end; 234static ulg free_mem_end_ptr;
241 235
242#define HEAP_SIZE 0x3000 236#ifdef STANDALONE_DEBUG
243 237#define NO_INFLATE_MALLOC
244#include "../../../../lib/inflate.c" 238#endif
245
246#ifndef STANDALONE_DEBUG
247static void *malloc(int size)
248{
249 void *p;
250
251 if (size <0) error("Malloc error");
252 if (free_mem_ptr <= 0) error("Memory error");
253
254 free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
255
256 p = (void *)free_mem_ptr;
257 free_mem_ptr += size;
258
259 if (free_mem_ptr >= free_mem_ptr_end)
260 error("Out of memory");
261 return p;
262}
263
264static void free(void *where)
265{ /* gzip_mark & gzip_release do the free */
266}
267
268static void gzip_mark(void **ptr)
269{
270 arch_decomp_wdog();
271 *ptr = (void *) free_mem_ptr;
272}
273 239
274static void gzip_release(void **ptr) 240#define ARCH_HAS_DECOMP_WDOG
275{
276 arch_decomp_wdog();
277 free_mem_ptr = (long) *ptr;
278}
279#else
280static void gzip_mark(void **ptr)
281{
282}
283 241
284static void gzip_release(void **ptr) 242#include "../../../../lib/inflate.c"
285{
286}
287#endif
288 243
289/* =========================================================================== 244/* ===========================================================================
290 * Fill the input buffer. This is called only when the buffer is empty 245 * Fill the input buffer. This is called only when the buffer is empty
@@ -348,7 +303,7 @@ decompress_kernel(ulg output_start, ulg free_mem_ptr_p, ulg free_mem_ptr_end_p,
348{ 303{
349 output_data = (uch *)output_start; /* Points to kernel start */ 304 output_data = (uch *)output_start; /* Points to kernel start */
350 free_mem_ptr = free_mem_ptr_p; 305 free_mem_ptr = free_mem_ptr_p;
351 free_mem_ptr_end = free_mem_ptr_end_p; 306 free_mem_end_ptr = free_mem_ptr_end_p;
352 __machine_arch_type = arch_id; 307 __machine_arch_type = arch_id;
353 308
354 arch_decomp_setup(); 309 arch_decomp_setup();