Skip to content

Commit 32fe8a4

Browse files
marc-hblgirdwood
authored andcommitted
common.h: restore basic ALIGN() macro compatible with assembly
commit 39266ca ("core: assure alignment is only done on power of 2 values") changed the alignment macros, they now use C code to perform a sanity check. This broke ALIGN() usage in platform/suecreek/include/platform/lib/memory.h in two different ways: 1. it broke static initializers in platform/suecreek/base_module.c because these can't use statement-expressions. This could have been fixed by simply switching to ALIGN_UP_COMPILE(), BUT: 2. memory.h files are also included in assembly. Also note memory.h values are copied unprocessed to linker scripts that require the ALIGN() spelling. For these reasons ALIGN() needs to be switched back to a "dumb" macro. Preserve the sanity checks just added in alloc.c and pm_memory.c by switching them to the new and smarter ALIGN_UP() macro. Signed-off-by: Marc Herbert <marc.herbert@intel.com>
1 parent 7daaa51 commit 32fe8a4

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/include/sof/common.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@
7777

7878
#endif
7979

80-
#define ALIGN ALIGN_UP
80+
/* This most basic ALIGN() must be used in header files that are
81+
* included in both C and assembly code. memory.h files require this
82+
* exact spelling matching the linker function because memory.h values
83+
* are _also_ copied unprocessed to the .x[.in] linker script
84+
*/
85+
#define ALIGN(val, align) ALIGN_UP_INTERNAL(val, align)
8186
#define DIV_ROUND_UP(val, div) (((val) + (div) - 1) / (div))
8287

8388
#if !defined(__ASSEMBLER__)

src/lib/alloc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ static void *align_ptr(struct mm_heap *heap, uint32_t alignment,
197197
if (alignment <= 1)
198198
return ptr;
199199

200-
return (void *)ALIGN((uintptr_t)ptr, alignment);
200+
return (void *)ALIGN_UP((uintptr_t)ptr, alignment);
201201
}
202202

203203
/* allocate single block */
@@ -290,7 +290,7 @@ static void *alloc_cont_blocks(struct mm_heap *heap, int level,
290290

291291
/* Check if we can start a sequence here */
292292
if (alignment) {
293-
aligned = ALIGN(blk_start, alignment);
293+
aligned = ALIGN_UP(blk_start, alignment);
294294

295295
if (blk_start & (alignment - 1) &&
296296
aligned >= blk_start + map->block_size)
@@ -881,7 +881,7 @@ static void *alloc_heap_buffer(struct mm_heap *heap, uint32_t flags,
881881
if (hdr->used)
882882
continue;
883883

884-
aligned = ALIGN(free_start, alignment);
884+
aligned = ALIGN_UP(free_start, alignment);
885885

886886
if (aligned + bytes > free_start + map->block_size)
887887
continue;

src/platform/intel/cavs/lib/pm_memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static void memory_banks_get(void *start, void *end, uint32_t base,
3838
* or end for end address
3939
*/
4040
if ((uintptr_t)start % SRAM_BANK_SIZE)
41-
start = (void *)ALIGN((uintptr_t)start, SRAM_BANK_SIZE);
41+
start = (void *)ALIGN_UP((uintptr_t)start, SRAM_BANK_SIZE);
4242

4343
if ((uintptr_t)end % SRAM_BANK_SIZE)
4444
end = (void *)ALIGN_DOWN((uintptr_t)end, SRAM_BANK_SIZE);

0 commit comments

Comments
 (0)