summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Mahone <andrew.mahone@gmail.com>2009-01-13 13:48:26 +0000
committerAndrew Mahone <andrew.mahone@gmail.com>2009-01-13 13:48:26 +0000
commit2fbf09752d385af861279af195d68f920859202d (patch)
tree98bf09ebc24217d122b61c2a079337b793c35d9b
parentc0d9084d6a5182460da0472a4e88d6d078adb86e (diff)
downloadrockbox-2fbf09752d385af861279af195d68f920859202d.tar.gz
rockbox-2fbf09752d385af861279af195d68f920859202d.zip
remove align_buffer from firmare/general.c, replacing with ALIGN_BUFFER macro, and replace all uses of it (only resize.c in core, and pictureflow and mpegplayer plugins), remove it from plugin_api,
and remove wrapper for it from plugin.h git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19758 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugin.c1
-rw-r--r--apps/plugin.h13
-rw-r--r--apps/plugins/lib/wrappers.h3
-rw-r--r--apps/plugins/mpegplayer/alloc.c5
-rw-r--r--apps/plugins/mpegplayer/disk_buf.c3
-rw-r--r--apps/plugins/mpegplayer/mpegplayer.c1
-rw-r--r--apps/plugins/pictureflow.c3
-rw-r--r--apps/recorder/resize.c6
-rw-r--r--docs/PLUGIN_API.new9
-rw-r--r--firmware/export/general.h2
-rw-r--r--firmware/export/system.h16
-rw-r--r--firmware/general.c20
12 files changed, 23 insertions, 59 deletions
diff --git a/apps/plugin.c b/apps/plugin.c
index 66d614ec58..151cb1d04d 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -308,7 +308,6 @@ static const struct plugin_api rockbox_api = {
308 mutex_init, 308 mutex_init,
309 mutex_lock, 309 mutex_lock,
310 mutex_unlock, 310 mutex_unlock,
311 align_buffer,
312#endif 311#endif
313 312
314 reset_poweroff_timer, 313 reset_poweroff_timer,
diff --git a/apps/plugin.h b/apps/plugin.h
index 6b198686f2..7bb1c7fc5f 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -126,12 +126,12 @@ void* plugin_get_buffer(size_t *buffer_size);
126#define PLUGIN_MAGIC 0x526F634B /* RocK */ 126#define PLUGIN_MAGIC 0x526F634B /* RocK */
127 127
128/* increase this every time the api struct changes */ 128/* increase this every time the api struct changes */
129#define PLUGIN_API_VERSION 135 129#define PLUGIN_API_VERSION 136
130 130
131/* update this to latest version if a change to the api struct breaks 131/* update this to latest version if a change to the api struct breaks
132 backwards compatibility (and please take the opportunity to sort in any 132 backwards compatibility (and please take the opportunity to sort in any
133 new function which are "waiting" at the end of the function table) */ 133 new function which are "waiting" at the end of the function table) */
134#define PLUGIN_MIN_API_VERSION 135 134#define PLUGIN_MIN_API_VERSION 136
135 135
136/* plugin return codes */ 136/* plugin return codes */
137enum plugin_status { 137enum plugin_status {
@@ -419,7 +419,6 @@ struct plugin_api {
419 void (*mutex_init)(struct mutex *m); 419 void (*mutex_init)(struct mutex *m);
420 void (*mutex_lock)(struct mutex *m); 420 void (*mutex_lock)(struct mutex *m);
421 void (*mutex_unlock)(struct mutex *m); 421 void (*mutex_unlock)(struct mutex *m);
422 size_t (*align_buffer)(void **start, size_t size, size_t align);
423#endif 422#endif
424 423
425 void (*reset_poweroff_timer)(void); 424 void (*reset_poweroff_timer)(void);
@@ -884,13 +883,5 @@ enum plugin_status plugin_start(const struct plugin_api* rockbox, const void* pa
884 883
885#endif /* CACHE_FUNCTION_WRAPPERS */ 884#endif /* CACHE_FUNCTION_WRAPPERS */
886 885
887#ifndef ALIGN_BUFFER_WRAPPER
888#define ALIGN_BUFFER_WRAPPER(api) \
889 size_t align_buffer(void **start, size_t size, size_t align) \
890 { \
891 return (api)->align_buffer(start, size, align); \
892 }
893#endif /* ALIGN_BUFFER_WRAPPER */
894
895#endif /* __PCTOOL__ */ 886#endif /* __PCTOOL__ */
896#endif 887#endif
diff --git a/apps/plugins/lib/wrappers.h b/apps/plugins/lib/wrappers.h
index 2eb4ea025e..385cd5d613 100644
--- a/apps/plugins/lib/wrappers.h
+++ b/apps/plugins/lib/wrappers.h
@@ -36,9 +36,6 @@
36#define cpu_boost rb->cpu_boost 36#define cpu_boost rb->cpu_boost
37#endif 37#endif
38#define yield rb->yield 38#define yield rb->yield
39#if CONFIG_CODEC == SWCODEC
40#define align_buffer rb->align_buffer
41#endif
42 39
43#endif 40#endif
44 41
diff --git a/apps/plugins/mpegplayer/alloc.c b/apps/plugins/mpegplayer/alloc.c
index c4f936ee14..6b50b8f24c 100644
--- a/apps/plugins/mpegplayer/alloc.c
+++ b/apps/plugins/mpegplayer/alloc.c
@@ -27,6 +27,7 @@
27 27
28#include "plugin.h" 28#include "plugin.h"
29#include "mpegplayer.h" 29#include "mpegplayer.h"
30#include <system.h>
30 31
31/* Main allocator */ 32/* Main allocator */
32static off_t mem_ptr; 33static off_t mem_ptr;
@@ -132,8 +133,8 @@ bool mpeg_alloc_init(unsigned char *buf, size_t mallocsize)
132 mem_ptr = 0; 133 mem_ptr = 0;
133 /* Cache-align buffer or 4-byte align */ 134 /* Cache-align buffer or 4-byte align */
134 mallocbuf = buf; 135 mallocbuf = buf;
135 bufsize = align_buffer(PUN_PTR(void **, &mallocbuf), 136 bufsize = mallocsize;
136 mallocsize, CACHEALIGN_UP(4)); 137 ALIGN_BUFFER(mallocbuf, bufsize, CACHEALIGN_UP(4));
137 138
138 /* Separate allocator for video */ 139 /* Separate allocator for video */
139 mpeg2_mem_ptr = 0; 140 mpeg2_mem_ptr = 0;
diff --git a/apps/plugins/mpegplayer/disk_buf.c b/apps/plugins/mpegplayer/disk_buf.c
index c008139356..defd8ef81d 100644
--- a/apps/plugins/mpegplayer/disk_buf.c
+++ b/apps/plugins/mpegplayer/disk_buf.c
@@ -22,6 +22,7 @@
22 ****************************************************************************/ 22 ****************************************************************************/
23#include "plugin.h" 23#include "plugin.h"
24#include "mpegplayer.h" 24#include "mpegplayer.h"
25#include <system.h>
25 26
26static struct mutex disk_buf_mtx SHAREDBSS_ATTR; 27static struct mutex disk_buf_mtx SHAREDBSS_ATTR;
27static struct event_queue disk_buf_queue SHAREDBSS_ATTR; 28static struct event_queue disk_buf_queue SHAREDBSS_ATTR;
@@ -859,7 +860,7 @@ bool disk_buf_init(void)
859 return false; 860 return false;
860 861
861#ifdef PROC_NEEDS_CACHEALIGN 862#ifdef PROC_NEEDS_CACHEALIGN
862 disk_buf.size = CACHEALIGN_BUFFER(&disk_buf.start, disk_buf.size); 863 CACHEALIGN_BUFFER(disk_buf.start, disk_buf.size);
863 disk_buf.start = UNCACHED_ADDR(disk_buf.start); 864 disk_buf.start = UNCACHED_ADDR(disk_buf.start);
864#endif 865#endif
865 disk_buf.size -= DISK_GUARDBUF_SIZE; 866 disk_buf.size -= DISK_GUARDBUF_SIZE;
diff --git a/apps/plugins/mpegplayer/mpegplayer.c b/apps/plugins/mpegplayer/mpegplayer.c
index cb5d4edb76..0b5bb518fe 100644
--- a/apps/plugins/mpegplayer/mpegplayer.c
+++ b/apps/plugins/mpegplayer/mpegplayer.c
@@ -283,7 +283,6 @@ CONFIG_KEYPAD == SANSA_M200_PAD
283const struct plugin_api* rb; 283const struct plugin_api* rb;
284 284
285CACHE_FUNCTION_WRAPPERS(rb); 285CACHE_FUNCTION_WRAPPERS(rb);
286ALIGN_BUFFER_WRAPPER(rb);
287 286
288/* One thing we can do here for targets with remotes is having a display 287/* One thing we can do here for targets with remotes is having a display
289 * always on the remote instead of always forcing a popup on the main display */ 288 * always on the remote instead of always forcing a popup on the main display */
diff --git a/apps/plugins/pictureflow.c b/apps/plugins/pictureflow.c
index 83ab1ddef0..a3552836fa 100644
--- a/apps/plugins/pictureflow.c
+++ b/apps/plugins/pictureflow.c
@@ -2144,8 +2144,7 @@ enum plugin_status plugin_start(const struct plugin_api *api,
2144 rb->cpu_boost(true); 2144 rb->cpu_boost(true);
2145#endif 2145#endif
2146 plugin_buf = rb->plugin_get_buffer(&plugin_buf_size); 2146 plugin_buf = rb->plugin_get_buffer(&plugin_buf_size);
2147 plugin_buf_size = rb->align_buffer(PUN_PTR(void**,&plugin_buf), 2147 ALIGN_BUFFER(plugin_buf, plugin_buf_size, 4);
2148 plugin_buf_size, 4);
2149 ret = main(); 2148 ret = main();
2150#ifdef HAVE_ADJUSTABLE_CPU_FREQ 2149#ifdef HAVE_ADJUSTABLE_CPU_FREQ
2151 rb->cpu_boost(false); 2150 rb->cpu_boost(false);
diff --git a/apps/recorder/resize.c b/apps/recorder/resize.c
index 99ccc84d55..2e6c3ff266 100644
--- a/apps/recorder/resize.c
+++ b/apps/recorder/resize.c
@@ -31,6 +31,7 @@
31 * 31 *
32 ****************************************************************************/ 32 ****************************************************************************/
33 33
34#include <system.h>
34#include <stdio.h> 35#include <stdio.h>
35#include <stdlib.h> 36#include <stdlib.h>
36#include <string.h> 37#include <string.h>
@@ -616,10 +617,7 @@ int resize_on_load(struct bitmap *bm, bool dither, struct dim *src,
616 uint8_t sc_buf[(needed <= len || needed > MAX_SC_STACK_ALLOC) ? 617 uint8_t sc_buf[(needed <= len || needed > MAX_SC_STACK_ALLOC) ?
617 0 : needed]; 618 0 : needed];
618#endif 619#endif
619#if CONFIG_CODEC == SWCODEC 620 ALIGN_BUFFER(buf, len, sizeof(uint32_t));
620 len = (unsigned int)align_buffer(PUN_PTR(void**, &buf), len,
621 sizeof(uint32_t));
622#endif
623 if (needed > len) 621 if (needed > len)
624 { 622 {
625#if MAX_SC_STACK_ALLOC 623#if MAX_SC_STACK_ALLOC
diff --git a/docs/PLUGIN_API.new b/docs/PLUGIN_API.new
index 1f24ac08bc..b4790e3ea6 100644
--- a/docs/PLUGIN_API.new
+++ b/docs/PLUGIN_API.new
@@ -39,15 +39,6 @@ bool action_userabort(int timeout)
39 \return 39 \return
40 \description 40 \description
41 41
42size_t align_buffer(void **start, size_t size, size_t align)
43 \group kernel/ system
44 \conditions (CONFIG_CODEC == SWCODEC)
45 \param start
46 \param size
47 \param align
48 \return
49 \description
50
51const char *appsversion 42const char *appsversion
52 \return version of the plugin API 43 \return version of the plugin API
53 \description 44 \description
diff --git a/firmware/export/general.h b/firmware/export/general.h
index 7bcd08da00..d1bd14558c 100644
--- a/firmware/export/general.h
+++ b/firmware/export/general.h
@@ -37,6 +37,4 @@ int make_list_from_caps32(unsigned long src_mask,
37 unsigned long caps_mask, 37 unsigned long caps_mask,
38 unsigned long *caps_list); 38 unsigned long *caps_list);
39 39
40size_t align_buffer(void **start, size_t size, size_t align);
41
42#endif /* GENERAL_H */ 40#endif /* GENERAL_H */
diff --git a/firmware/export/system.h b/firmware/export/system.h
index 8ebd30ac4e..cc2a08db2e 100644
--- a/firmware/export/system.h
+++ b/firmware/export/system.h
@@ -110,6 +110,17 @@ int get_cpu_boost_counter(void);
110#define ALIGN_DOWN(n, a) ((n)/(a)*(a)) 110#define ALIGN_DOWN(n, a) ((n)/(a)*(a))
111#define ALIGN_UP(n, a) ALIGN_DOWN((n)+((a)-1),a) 111#define ALIGN_UP(n, a) ALIGN_DOWN((n)+((a)-1),a)
112 112
113/* align start and end of buffer to nearest integer multiple of a */
114#define ALIGN_BUFFER(ptr,len,align) \
115{\
116 uintptr_t tmp_ptr1 = (uintptr_t)ptr; \
117 uintptr_t tmp_ptr2 = tmp_ptr1 + len;\
118 tmp_ptr1 = ALIGN_UP(tmp_ptr1,align); \
119 tmp_ptr2 = ALIGN_DOWN(tmp_ptr2,align); \
120 len = tmp_ptr2 - tmp_ptr1; \
121 ptr = (typeof(ptr))tmp_ptr1; \
122}
123
113/* live endianness conversion */ 124/* live endianness conversion */
114#ifdef ROCKBOX_LITTLE_ENDIAN 125#ifdef ROCKBOX_LITTLE_ENDIAN
115#define letoh16(x) (x) 126#define letoh16(x) (x)
@@ -275,7 +286,7 @@ static inline uint32_t swap_odd_even32(uint32_t value)
275 __attribute__((aligned(CACHEALIGN_UP(x)))) 286 __attribute__((aligned(CACHEALIGN_UP(x))))
276/* Aligns a buffer pointer and size to proper boundaries */ 287/* Aligns a buffer pointer and size to proper boundaries */
277#define CACHEALIGN_BUFFER(start, size) \ 288#define CACHEALIGN_BUFFER(start, size) \
278 ({ align_buffer(PUN_PTR(void **, (start)), (size), CACHEALIGN_SIZE); }) 289 ALIGN_BUFFER((start), (size), CACHEALIGN_SIZE)
279 290
280#else /* ndef PROC_NEEDS_CACHEALIGN */ 291#else /* ndef PROC_NEEDS_CACHEALIGN */
281 292
@@ -286,8 +297,7 @@ static inline uint32_t swap_odd_even32(uint32_t value)
286#define CACHEALIGN_UP(x) (x) 297#define CACHEALIGN_UP(x) (x)
287#define CACHEALIGN_DOWN(x) (x) 298#define CACHEALIGN_DOWN(x) (x)
288/* Make no adjustments */ 299/* Make no adjustments */
289#define CACHEALIGN_BUFFER(start, size) \ 300#define CACHEALIGN_BUFFER(start, size)
290 ({ (void)(start); (size); })
291 301
292#endif /* PROC_NEEDS_CACHEALIGN */ 302#endif /* PROC_NEEDS_CACHEALIGN */
293 303
diff --git a/firmware/general.c b/firmware/general.c
index 1c2abe1256..ff6594086e 100644
--- a/firmware/general.c
+++ b/firmware/general.c
@@ -78,23 +78,3 @@ int make_list_from_caps32(unsigned long src_mask,
78 78
79 return count; 79 return count;
80} /* make_list_from_caps32 */ 80} /* make_list_from_caps32 */
81
82/* Align a buffer and size to a size boundary while remaining within
83 * the original boundaries */
84size_t align_buffer(void **start, size_t size, size_t align)
85{
86 void *newstart = *start;
87 void *newend = newstart + size;
88
89 /* Align the end down and the start up */
90 newend = (void *)ALIGN_DOWN((intptr_t)newend, align);
91 newstart = (void *)ALIGN_UP((intptr_t)newstart, align);
92
93 /* Hmmm - too small for this */
94 if (newend <= newstart)
95 return 0;
96
97 /* Return adjusted pointer and size */
98 *start = newstart;
99 return newend - newstart;
100}