diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/export/general.h | 2 | ||||
-rw-r--r-- | firmware/export/system.h | 16 | ||||
-rw-r--r-- | firmware/general.c | 20 |
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, | |||
37 | unsigned long caps_mask, | 37 | unsigned long caps_mask, |
38 | unsigned long *caps_list); | 38 | unsigned long *caps_list); |
39 | 39 | ||
40 | size_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 */ | ||
84 | size_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 | } | ||