diff options
author | Thomas Petazzoni <thomas.petazzoni@free-electrons.com> | 2008-07-25 04:45:44 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-07-25 13:53:28 -0400 |
commit | 2d6ffcca623a9a16df6cdfbe8250b7a5904a5f5e (patch) | |
tree | 70d30cb6516608e9a8a1dce60c59f3a5ff21b305 /arch/sh/boot | |
parent | ba92a43dbaee339cf5915ef766d3d3ffbaaf103c (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/sh/boot')
-rw-r--r-- | arch/sh/boot/compressed/misc_32.c | 38 | ||||
-rw-r--r-- | arch/sh/boot/compressed/misc_64.c | 40 |
2 files changed, 0 insertions, 78 deletions
diff --git a/arch/sh/boot/compressed/misc_32.c b/arch/sh/boot/compressed/misc_32.c index adcea31e663e..f386997e4d9c 100644 --- a/arch/sh/boot/compressed/misc_32.c +++ b/arch/sh/boot/compressed/misc_32.c | |||
@@ -74,8 +74,6 @@ static unsigned outcnt = 0; /* bytes in output buffer */ | |||
74 | static int fill_inbuf(void); | 74 | static int fill_inbuf(void); |
75 | static void flush_window(void); | 75 | static void flush_window(void); |
76 | static void error(char *m); | 76 | static void error(char *m); |
77 | static void gzip_mark(void **); | ||
78 | static void gzip_release(void **); | ||
79 | 77 | ||
80 | extern char input_data[]; | 78 | extern char input_data[]; |
81 | extern int input_len; | 79 | extern int input_len; |
@@ -84,11 +82,7 @@ static long bytes_out = 0; | |||
84 | static uch *output_data; | 82 | static uch *output_data; |
85 | static unsigned long output_ptr = 0; | 83 | static unsigned long output_ptr = 0; |
86 | 84 | ||
87 | static void *malloc(int size); | ||
88 | static void free(void *where); | ||
89 | static void error(char *m); | 85 | static void error(char *m); |
90 | static void gzip_mark(void **); | ||
91 | static void gzip_release(void **); | ||
92 | 86 | ||
93 | int puts(const char *); | 87 | int puts(const char *); |
94 | 88 | ||
@@ -101,38 +95,6 @@ static unsigned long free_mem_end_ptr; | |||
101 | 95 | ||
102 | #include "../../../../lib/inflate.c" | 96 | #include "../../../../lib/inflate.c" |
103 | 97 | ||
104 | static void *malloc(int size) | ||
105 | { | ||
106 | void *p; | ||
107 | |||
108 | if (size <0) error("Malloc error"); | ||
109 | if (free_mem_ptr == 0) error("Memory error"); | ||
110 | |||
111 | free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */ | ||
112 | |||
113 | p = (void *)free_mem_ptr; | ||
114 | free_mem_ptr += size; | ||
115 | |||
116 | if (free_mem_ptr >= free_mem_end_ptr) | ||
117 | error("Out of memory"); | ||
118 | |||
119 | return p; | ||
120 | } | ||
121 | |||
122 | static void free(void *where) | ||
123 | { /* Don't care */ | ||
124 | } | ||
125 | |||
126 | static void gzip_mark(void **ptr) | ||
127 | { | ||
128 | *ptr = (void *) free_mem_ptr; | ||
129 | } | ||
130 | |||
131 | static void gzip_release(void **ptr) | ||
132 | { | ||
133 | free_mem_ptr = (long) *ptr; | ||
134 | } | ||
135 | |||
136 | #ifdef CONFIG_SH_STANDARD_BIOS | 98 | #ifdef CONFIG_SH_STANDARD_BIOS |
137 | size_t strlen(const char *s) | 99 | size_t strlen(const char *s) |
138 | { | 100 | { |
diff --git a/arch/sh/boot/compressed/misc_64.c b/arch/sh/boot/compressed/misc_64.c index a006ef89b9dd..2941657e18aa 100644 --- a/arch/sh/boot/compressed/misc_64.c +++ b/arch/sh/boot/compressed/misc_64.c | |||
@@ -72,8 +72,6 @@ static unsigned outcnt = 0; /* bytes in output buffer */ | |||
72 | static int fill_inbuf(void); | 72 | static int fill_inbuf(void); |
73 | static void flush_window(void); | 73 | static void flush_window(void); |
74 | static void error(char *m); | 74 | static void error(char *m); |
75 | static void gzip_mark(void **); | ||
76 | static void gzip_release(void **); | ||
77 | 75 | ||
78 | extern char input_data[]; | 76 | extern char input_data[]; |
79 | extern int input_len; | 77 | extern int input_len; |
@@ -82,11 +80,7 @@ static long bytes_out = 0; | |||
82 | static uch *output_data; | 80 | static uch *output_data; |
83 | static unsigned long output_ptr = 0; | 81 | static unsigned long output_ptr = 0; |
84 | 82 | ||
85 | static void *malloc(int size); | ||
86 | static void free(void *where); | ||
87 | static void error(char *m); | 83 | static void error(char *m); |
88 | static void gzip_mark(void **); | ||
89 | static void gzip_release(void **); | ||
90 | 84 | ||
91 | static void puts(const char *); | 85 | static void puts(const char *); |
92 | 86 | ||
@@ -99,40 +93,6 @@ static unsigned long free_mem_end_ptr; | |||
99 | 93 | ||
100 | #include "../../../../lib/inflate.c" | 94 | #include "../../../../lib/inflate.c" |
101 | 95 | ||
102 | static void *malloc(int size) | ||
103 | { | ||
104 | void *p; | ||
105 | |||
106 | if (size < 0) | ||
107 | error("Malloc error\n"); | ||
108 | if (free_mem_ptr == 0) | ||
109 | error("Memory error\n"); | ||
110 | |||
111 | free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */ | ||
112 | |||
113 | p = (void *) free_mem_ptr; | ||
114 | free_mem_ptr += size; | ||
115 | |||
116 | if (free_mem_ptr >= free_mem_end_ptr) | ||
117 | error("\nOut of memory\n"); | ||
118 | |||
119 | return p; | ||
120 | } | ||
121 | |||
122 | static void free(void *where) | ||
123 | { /* Don't care */ | ||
124 | } | ||
125 | |||
126 | static void gzip_mark(void **ptr) | ||
127 | { | ||
128 | *ptr = (void *) free_mem_ptr; | ||
129 | } | ||
130 | |||
131 | static void gzip_release(void **ptr) | ||
132 | { | ||
133 | free_mem_ptr = (long) *ptr; | ||
134 | } | ||
135 | |||
136 | void puts(const char *s) | 96 | void puts(const char *s) |
137 | { | 97 | { |
138 | } | 98 | } |