summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/export/general.h2
-rw-r--r--firmware/export/system.h16
-rw-r--r--firmware/general.c20
3 files changed, 13 insertions, 25 deletions
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,
unsigned long caps_mask,
unsigned long *caps_list);
-size_t align_buffer(void **start, size_t size, size_t align);
-
#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);
#define ALIGN_DOWN(n, a) ((n)/(a)*(a))
#define ALIGN_UP(n, a) ALIGN_DOWN((n)+((a)-1),a)
+/* align start and end of buffer to nearest integer multiple of a */
+#define ALIGN_BUFFER(ptr,len,align) \
+{\
+ uintptr_t tmp_ptr1 = (uintptr_t)ptr; \
+ uintptr_t tmp_ptr2 = tmp_ptr1 + len;\
+ tmp_ptr1 = ALIGN_UP(tmp_ptr1,align); \
+ tmp_ptr2 = ALIGN_DOWN(tmp_ptr2,align); \
+ len = tmp_ptr2 - tmp_ptr1; \
+ ptr = (typeof(ptr))tmp_ptr1; \
+}
+
/* live endianness conversion */
#ifdef ROCKBOX_LITTLE_ENDIAN
#define letoh16(x) (x)
@@ -275,7 +286,7 @@ static inline uint32_t swap_odd_even32(uint32_t value)
__attribute__((aligned(CACHEALIGN_UP(x))))
/* Aligns a buffer pointer and size to proper boundaries */
#define CACHEALIGN_BUFFER(start, size) \
- ({ align_buffer(PUN_PTR(void **, (start)), (size), CACHEALIGN_SIZE); })
+ ALIGN_BUFFER((start), (size), CACHEALIGN_SIZE)
#else /* ndef PROC_NEEDS_CACHEALIGN */
@@ -286,8 +297,7 @@ static inline uint32_t swap_odd_even32(uint32_t value)
#define CACHEALIGN_UP(x) (x)
#define CACHEALIGN_DOWN(x) (x)
/* Make no adjustments */
-#define CACHEALIGN_BUFFER(start, size) \
- ({ (void)(start); (size); })
+#define CACHEALIGN_BUFFER(start, size)
#endif /* PROC_NEEDS_CACHEALIGN */
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,
return count;
} /* make_list_from_caps32 */
-
-/* Align a buffer and size to a size boundary while remaining within
- * the original boundaries */
-size_t align_buffer(void **start, size_t size, size_t align)
-{
- void *newstart = *start;
- void *newend = newstart + size;
-
- /* Align the end down and the start up */
- newend = (void *)ALIGN_DOWN((intptr_t)newend, align);
- newstart = (void *)ALIGN_UP((intptr_t)newstart, align);
-
- /* Hmmm - too small for this */
- if (newend <= newstart)
- return 0;
-
- /* Return adjusted pointer and size */
- *start = newstart;
- return newend - newstart;
-}