diff options
author | Boris Gjenero <dreamlayers@rockbox.org> | 2011-11-29 00:42:27 +0000 |
---|---|---|
committer | Boris Gjenero <dreamlayers@rockbox.org> | 2011-11-29 00:42:27 +0000 |
commit | d51e5983357593981e604b05ad3826f2496f4a6b (patch) | |
tree | 036fa986dcf4f6ec4c529dd74c5f996533f62d4f /firmware | |
parent | 297c29cba60e34ed01fb72974dcb562e58df322b (diff) | |
download | rockbox-d51e5983357593981e604b05ad3826f2496f4a6b.tar.gz rockbox-d51e5983357593981e604b05ad3826f2496f4a6b.zip |
FS#12412 : Delete old buffer allocation code which has been replaced by core_alloc, and move buffer setup code to core_alloc.c
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31088 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/SOURCES | 1 | ||||
-rw-r--r-- | firmware/buffer.c | 202 | ||||
-rw-r--r-- | firmware/buflib.c | 1 | ||||
-rw-r--r-- | firmware/core_alloc.c | 35 | ||||
-rw-r--r-- | firmware/include/buffer.h | 38 | ||||
-rw-r--r-- | firmware/thread.c | 11 |
6 files changed, 29 insertions, 259 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES index b918a19418..f5ee7873a2 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES | |||
@@ -1,7 +1,6 @@ | |||
1 | ata_idle_notify.c | 1 | ata_idle_notify.c |
2 | events.c | 2 | events.c |
3 | backlight.c | 3 | backlight.c |
4 | buffer.c | ||
5 | buflib.c | 4 | buflib.c |
6 | core_alloc.c | 5 | core_alloc.c |
7 | general.c | 6 | general.c |
diff --git a/firmware/buffer.c b/firmware/buffer.c deleted file mode 100644 index e0496fe149..0000000000 --- a/firmware/buffer.c +++ /dev/null | |||
@@ -1,202 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include <stdio.h> | ||
22 | #include <stdint.h> | ||
23 | #include "system.h" | ||
24 | #include "buffer.h" | ||
25 | #include "panic.h" | ||
26 | #include "logf.h" | ||
27 | |||
28 | #if (CONFIG_PLATFORM & PLATFORM_HOSTED) | ||
29 | #else | ||
30 | #endif | ||
31 | |||
32 | /* defined in linker script */ | ||
33 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) | ||
34 | #if defined(IPOD_VIDEO) && !defined(BOOTLOADER) | ||
35 | extern unsigned char *audiobufend_lds[]; | ||
36 | unsigned char *audiobufend; | ||
37 | #else /* !IPOD_VIDEO */ | ||
38 | extern unsigned char audiobufend[]; | ||
39 | #endif | ||
40 | /* defined in linker script */ | ||
41 | extern unsigned char audiobuffer[]; | ||
42 | #else /* PLATFORM_HOSTED */ | ||
43 | unsigned char audiobuffer[(MEMORYSIZE*1024-256)*1024]; | ||
44 | unsigned char *audiobufend = audiobuffer + sizeof(audiobuffer); | ||
45 | extern unsigned char *audiobufend; | ||
46 | #endif | ||
47 | |||
48 | static unsigned char *audiobuf; | ||
49 | |||
50 | #ifdef BUFFER_ALLOC_DEBUG | ||
51 | static unsigned char *audiobuf_orig_start; | ||
52 | |||
53 | struct buffer_start_marker | ||
54 | { | ||
55 | unsigned int magic; | ||
56 | size_t buffer_size; | ||
57 | }; | ||
58 | #define BUF_MAGIC 0xDEADD0D0 | ||
59 | |||
60 | struct buffer_end_marker | ||
61 | { | ||
62 | unsigned int magic; | ||
63 | int last; | ||
64 | }; | ||
65 | #endif /* BUFFER_ALLOC_DEBUG */ | ||
66 | |||
67 | void buffer_init(void) | ||
68 | { | ||
69 | /* 32-bit aligned */ | ||
70 | audiobuf = (void *)(((unsigned long)audiobuffer + 3) & ~3); | ||
71 | |||
72 | #if defined(IPOD_VIDEO) && !defined(BOOTLOADER) && !defined(SIMULATOR) | ||
73 | audiobufend=(unsigned char *)audiobufend_lds; | ||
74 | if(MEMORYSIZE==64 && probed_ramsize!=64) | ||
75 | { | ||
76 | audiobufend -= (32<<20); | ||
77 | } | ||
78 | #endif | ||
79 | |||
80 | #ifdef BUFFER_ALLOC_DEBUG | ||
81 | audiobuf_orig_start = audiobuf; | ||
82 | #endif /* BUFFER_ALLOC_DEBUG */ | ||
83 | } | ||
84 | |||
85 | /* protect concurrent access */ | ||
86 | static volatile int lock; | ||
87 | |||
88 | /* | ||
89 | * Give the entire buffer, return the size in size. | ||
90 | * The caller needs to make sure audiobuf is not otherwise used | ||
91 | * | ||
92 | * Note that this does not modify the buffer position (buffer_release_buffer() | ||
93 | * does), so call this if you want to aquire temporary memory | ||
94 | **/ | ||
95 | void *buffer_get_buffer(size_t *size) | ||
96 | { | ||
97 | if (lock) | ||
98 | panicf("concurrent audiobuf access"); | ||
99 | lock = 1; | ||
100 | audiobuf = ALIGN_UP(audiobuf, sizeof(intptr_t)); | ||
101 | *size = (audiobufend - audiobuf); | ||
102 | return audiobuf; | ||
103 | } | ||
104 | |||
105 | /* | ||
106 | * Release the buffer gotten with buffer_get_buffer | ||
107 | * | ||
108 | * size should have the amount of bytes (from the front) that caller keeps for | ||
109 | * its own, 0 if the entire buffer is to be released | ||
110 | * | ||
111 | * safe to be called with size=0 even if the buffer wasn't claimed before | ||
112 | **/ | ||
113 | void buffer_release_buffer(size_t size) | ||
114 | { | ||
115 | audiobuf += size; | ||
116 | /* ensure alignment */ | ||
117 | audiobuf = ALIGN_UP(audiobuf, sizeof(intptr_t)); | ||
118 | lock = 0; | ||
119 | } | ||
120 | |||
121 | /* | ||
122 | * Query how much free space the buffer has */ | ||
123 | size_t buffer_available(void) | ||
124 | { | ||
125 | return audiobufend - audiobuf; | ||
126 | } | ||
127 | |||
128 | void *buffer_alloc(size_t size) | ||
129 | { | ||
130 | if (lock) /* it's not save to call this here */ | ||
131 | panicf("buffer_alloc(): exclusive buffer owner"); | ||
132 | void *retval; | ||
133 | #ifdef BUFFER_ALLOC_DEBUG | ||
134 | struct buffer_start_marker *start; | ||
135 | struct buffer_end_marker *end; | ||
136 | #endif /* BUFFER_ALLOC_DEBUG */ | ||
137 | |||
138 | /* 32-bit aligned */ | ||
139 | size = (size + 3) & ~3; | ||
140 | |||
141 | /* Other code touches audiobuf. Make sure it stays aligned */ | ||
142 | audiobuf = (void *)(((unsigned long)audiobuf + 3) & ~3); | ||
143 | |||
144 | retval = audiobuf; | ||
145 | |||
146 | #ifdef BUFFER_ALLOC_DEBUG | ||
147 | retval +=sizeof(struct buffer_start_marker); | ||
148 | if(size>0) | ||
149 | { | ||
150 | end=(struct buffer_end_marker*)(audiobuf - sizeof(struct buffer_end_marker)); | ||
151 | if(end->magic == BUF_MAGIC) | ||
152 | { | ||
153 | end->last=0; | ||
154 | } | ||
155 | start=(struct buffer_start_marker*)audiobuf; | ||
156 | start->magic = BUF_MAGIC; | ||
157 | start->buffer_size = size; | ||
158 | end=(struct buffer_end_marker*)(audiobuf+sizeof(struct buffer_start_marker)+size); | ||
159 | end->magic = BUF_MAGIC; | ||
160 | end->last = 1; | ||
161 | |||
162 | audiobuf = ((unsigned char *)end) + sizeof(struct buffer_end_marker); | ||
163 | } | ||
164 | |||
165 | logf("Alloc %x %d",(unsigned int)retval,size); | ||
166 | #else /* !BUFFER_ALLOC_DEBUG */ | ||
167 | audiobuf += size; | ||
168 | #endif /* BUFFER_ALLOC_DEBUG */ | ||
169 | |||
170 | if (audiobuf > audiobufend) { | ||
171 | panicf("OOM: %d bytes", (int) size); | ||
172 | } | ||
173 | |||
174 | return retval; | ||
175 | } | ||
176 | |||
177 | #ifdef BUFFER_ALLOC_DEBUG | ||
178 | void buffer_alloc_check(char *name) | ||
179 | { | ||
180 | unsigned char *buf_ptr = audiobuf_orig_start; | ||
181 | struct buffer_start_marker *start; | ||
182 | struct buffer_end_marker *end; | ||
183 | |||
184 | |||
185 | while(buf_ptr < audiobuf) | ||
186 | { | ||
187 | start=(struct buffer_start_marker*)buf_ptr; | ||
188 | if(start->magic != BUF_MAGIC) | ||
189 | { | ||
190 | panicf("%s corrupted buffer %x start", name,(unsigned int)buf_ptr+sizeof(struct buffer_start_marker)); | ||
191 | } | ||
192 | end=(struct buffer_end_marker*)(buf_ptr+sizeof(struct buffer_start_marker)+start->buffer_size); | ||
193 | if(end->magic != BUF_MAGIC) | ||
194 | { | ||
195 | panicf("%s corrupted %x end", name,(unsigned int)buf_ptr+sizeof(struct buffer_start_marker)); | ||
196 | } | ||
197 | if(end->last) | ||
198 | break; | ||
199 | buf_ptr=((unsigned char *)end)+sizeof(struct buffer_end_marker); | ||
200 | } | ||
201 | } | ||
202 | #endif /* BUFFER_ALLOC_DEBUG */ | ||
diff --git a/firmware/buflib.c b/firmware/buflib.c index 748e8a2378..d3f1455c99 100644 --- a/firmware/buflib.c +++ b/firmware/buflib.c | |||
@@ -30,7 +30,6 @@ | |||
30 | #include "buflib.h" | 30 | #include "buflib.h" |
31 | #include "string-extra.h" /* strlcpy() */ | 31 | #include "string-extra.h" /* strlcpy() */ |
32 | #include "debug.h" | 32 | #include "debug.h" |
33 | #include "buffer.h" | ||
34 | #include "system.h" /* for ALIGN_*() */ | 33 | #include "system.h" /* for ALIGN_*() */ |
35 | 34 | ||
36 | /* The main goal of this design is fast fetching of the pointer for a handle. | 35 | /* The main goal of this design is fast fetching of the pointer for a handle. |
diff --git a/firmware/core_alloc.c b/firmware/core_alloc.c index 21dd1319dd..34ed48b39f 100644 --- a/firmware/core_alloc.c +++ b/firmware/core_alloc.c | |||
@@ -1,21 +1,44 @@ | |||
1 | 1 | ||
2 | #include "config.h" | ||
2 | #include <string.h> | 3 | #include <string.h> |
4 | #include "system.h" | ||
3 | #include "core_alloc.h" | 5 | #include "core_alloc.h" |
4 | #include "buflib.h" | 6 | #include "buflib.h" |
5 | #include "buffer.h" | ||
6 | 7 | ||
7 | /* not static so it can be discovered by core_get_data() */ | 8 | /* not static so it can be discovered by core_get_data() */ |
8 | struct buflib_context core_ctx; | 9 | struct buflib_context core_ctx; |
9 | 10 | ||
11 | /* defined in linker script */ | ||
12 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) | ||
13 | #if defined(IPOD_VIDEO) && !defined(BOOTLOADER) | ||
14 | extern unsigned char *audiobufend_lds[]; | ||
15 | unsigned char *audiobufend; | ||
16 | #else /* !IPOD_VIDEO */ | ||
17 | extern unsigned char audiobufend[]; | ||
18 | #endif | ||
19 | /* defined in linker script */ | ||
20 | extern unsigned char audiobuffer[]; | ||
21 | #else /* PLATFORM_HOSTED */ | ||
22 | unsigned char audiobuffer[(MEMORYSIZE*1024-256)*1024]; | ||
23 | unsigned char *audiobufend = audiobuffer + sizeof(audiobuffer); | ||
24 | extern unsigned char *audiobufend; | ||
25 | #endif | ||
26 | |||
10 | /* debug test alloc */ | 27 | /* debug test alloc */ |
11 | static int test_alloc; | 28 | static int test_alloc; |
12 | void core_allocator_init(void) | 29 | void core_allocator_init(void) |
13 | { | 30 | { |
14 | buffer_init(); | 31 | unsigned char *start = ALIGN_UP(audiobuffer, sizeof(intptr_t)); |
15 | size_t size; | 32 | |
16 | void *start = buffer_get_buffer(&size); | 33 | #if defined(IPOD_VIDEO) && !defined(BOOTLOADER) && !defined(SIMULATOR) |
17 | buflib_init(&core_ctx, start, size); | 34 | audiobufend=(unsigned char *)audiobufend_lds; |
18 | buffer_release_buffer(size); | 35 | if(MEMORYSIZE==64 && probed_ramsize!=64) |
36 | { | ||
37 | audiobufend -= (32<<20); | ||
38 | } | ||
39 | #endif | ||
40 | |||
41 | buflib_init(&core_ctx, start, audiobufend - start); | ||
19 | 42 | ||
20 | test_alloc = core_alloc("test", 112); | 43 | test_alloc = core_alloc("test", 112); |
21 | } | 44 | } |
diff --git a/firmware/include/buffer.h b/firmware/include/buffer.h deleted file mode 100644 index bdf91bcb3f..0000000000 --- a/firmware/include/buffer.h +++ /dev/null | |||
@@ -1,38 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #ifndef BUFFER_H | ||
22 | #define BUFFER_H | ||
23 | |||
24 | #include "config.h" | ||
25 | |||
26 | void buffer_init(void) INIT_ATTR; | ||
27 | |||
28 | void* buffer_get_buffer(size_t *size); | ||
29 | void buffer_release_buffer(size_t size); | ||
30 | size_t buffer_available(void); | ||
31 | |||
32 | void *buffer_alloc(size_t size); | ||
33 | |||
34 | #ifdef BUFFER_ALLOC_DEBUG | ||
35 | void buffer_alloc_check(char *name); | ||
36 | #endif | ||
37 | |||
38 | #endif | ||
diff --git a/firmware/thread.c b/firmware/thread.c index cfedbbedba..a1886cbc07 100644 --- a/firmware/thread.c +++ b/firmware/thread.c | |||
@@ -27,7 +27,6 @@ | |||
27 | #include "kernel.h" | 27 | #include "kernel.h" |
28 | #include "cpu.h" | 28 | #include "cpu.h" |
29 | #include "string.h" | 29 | #include "string.h" |
30 | #include "buffer.h" | ||
31 | #ifdef RB_PROFILE | 30 | #ifdef RB_PROFILE |
32 | #include <profile.h> | 31 | #include <profile.h> |
33 | #endif | 32 | #endif |
@@ -1168,16 +1167,6 @@ void switch_thread(void) | |||
1168 | if (UNLIKELY(thread->stack[0] != DEADBEEF) && thread->stack_size > 0) | 1167 | if (UNLIKELY(thread->stack[0] != DEADBEEF) && thread->stack_size > 0) |
1169 | thread_stkov(thread); | 1168 | thread_stkov(thread); |
1170 | 1169 | ||
1171 | #ifdef BUFFER_ALLOC_DEBUG | ||
1172 | /* Check if the current thread just did bad things with buffer_alloc()ed | ||
1173 | * memory */ | ||
1174 | { | ||
1175 | static char name[32]; | ||
1176 | thread_get_name(name, 32, thread); | ||
1177 | buffer_alloc_check(name); | ||
1178 | } | ||
1179 | #endif | ||
1180 | |||
1181 | #if NUM_CORES > 1 | 1170 | #if NUM_CORES > 1 |
1182 | /* Run any blocking operations requested before switching/sleeping */ | 1171 | /* Run any blocking operations requested before switching/sleeping */ |
1183 | run_blocking_ops(core, thread); | 1172 | run_blocking_ops(core, thread); |