diff options
Diffstat (limited to 'firmware/export')
-rw-r--r-- | firmware/export/system.h | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/firmware/export/system.h b/firmware/export/system.h index 0a13ec2208..5064fcd91d 100644 --- a/firmware/export/system.h +++ b/firmware/export/system.h | |||
@@ -118,15 +118,17 @@ int get_cpu_boost_counter(void); | |||
118 | #define ALIGN_UP(n, a) ALIGN_DOWN((n)+((a)-1),a) | 118 | #define ALIGN_UP(n, a) ALIGN_DOWN((n)+((a)-1),a) |
119 | 119 | ||
120 | /* align start and end of buffer to nearest integer multiple of a */ | 120 | /* align start and end of buffer to nearest integer multiple of a */ |
121 | #define ALIGN_BUFFER(ptr,len,align) \ | 121 | #define ALIGN_BUFFER(ptr, size, align) \ |
122 | {\ | 122 | ({ \ |
123 | uintptr_t tmp_ptr1 = (uintptr_t)ptr; \ | 123 | size_t __sz = (size); \ |
124 | uintptr_t tmp_ptr2 = tmp_ptr1 + len;\ | 124 | size_t __ali = (align); \ |
125 | tmp_ptr1 = ALIGN_UP(tmp_ptr1,align); \ | 125 | uintptr_t __a1 = (uintptr_t)(ptr); \ |
126 | tmp_ptr2 = ALIGN_DOWN(tmp_ptr2,align); \ | 126 | uintptr_t __a2 = __a1 + __sz; \ |
127 | len = tmp_ptr2 - tmp_ptr1; \ | 127 | __a1 = ALIGN_UP(__a1, __ali); \ |
128 | ptr = (typeof(ptr))tmp_ptr1; \ | 128 | __a2 = ALIGN_DOWN(__a2, __ali); \ |
129 | } | 129 | (ptr) = (typeof (ptr))__a1; \ |
130 | (size) = __a2 > __a1 ? __a2 - __a1 : 0; \ | ||
131 | }) | ||
130 | 132 | ||
131 | #define PTR_ADD(ptr, x) ((typeof(ptr))((char*)(ptr) + (x))) | 133 | #define PTR_ADD(ptr, x) ((typeof(ptr))((char*)(ptr) + (x))) |
132 | #define PTR_SUB(ptr, x) ((typeof(ptr))((char*)(ptr) - (x))) | 134 | #define PTR_SUB(ptr, x) ((typeof(ptr))((char*)(ptr) - (x))) |
@@ -150,11 +152,16 @@ int get_cpu_boost_counter(void); | |||
150 | #endif | 152 | #endif |
151 | 153 | ||
152 | /* Get the byte offset of a type's member */ | 154 | /* Get the byte offset of a type's member */ |
153 | #define OFFSETOF(type, membername) ((off_t)&((type *)0)->membername) | 155 | #ifndef offsetof |
156 | #define offsetof(type, member) __builtin_offsetof(type, member) | ||
157 | #endif | ||
154 | 158 | ||
155 | /* Get the type pointer from one of its members */ | 159 | /* Get the containing item of *ptr in type */ |
156 | #define TYPE_FROM_MEMBER(type, memberptr, membername) \ | 160 | #ifndef container_of |
157 | ((type *)((intptr_t)(memberptr) - OFFSETOF(type, membername))) | 161 | #define container_of(ptr, type, member) ({ \ |
162 | const typeof (((type *)0)->member) *__mptr = (ptr); \ | ||
163 | (type *)((void *)(__mptr) - offsetof(type, member)); }) | ||
164 | #endif | ||
158 | 165 | ||
159 | /* returns index of first set bit or 32 if no bits are set */ | 166 | /* returns index of first set bit or 32 if no bits are set */ |
160 | #if defined(CPU_ARM) && ARM_ARCH >= 5 && !defined(__thumb__) | 167 | #if defined(CPU_ARM) && ARM_ARCH >= 5 && !defined(__thumb__) |
@@ -324,6 +331,11 @@ static inline uint32_t swaw32_hw(uint32_t value) | |||
324 | * for all ARM CPUs. */ | 331 | * for all ARM CPUs. */ |
325 | #ifdef CPU_ARM | 332 | #ifdef CPU_ARM |
326 | #define HAVE_CPU_CACHE_ALIGN | 333 | #define HAVE_CPU_CACHE_ALIGN |
334 | #define MIN_STACK_ALIGN 8 | ||
335 | #endif | ||
336 | |||
337 | #ifndef MIN_STACK_ALIGN | ||
338 | #define MIN_STACK_ALIGN (sizeof (uintptr_t)) | ||
327 | #endif | 339 | #endif |
328 | 340 | ||
329 | /* Calculate CACHEALIGN_SIZE from CACHEALIGN_BITS */ | 341 | /* Calculate CACHEALIGN_SIZE from CACHEALIGN_BITS */ |