Derive stack alignment from CACHE_WRITEBACK_GRANULE
authorSoby Mathew <[email protected]>
Thu, 9 Jun 2016 16:16:35 +0000 (17:16 +0100)
committerSoby Mathew <[email protected]>
Fri, 8 Jul 2016 08:58:10 +0000 (09:58 +0100)
The per-cpu stacks should be aligned to the cache-line size and
the `declare_stack` helper in asm_macros.S macro assumed a
cache-line size of 64 bytes. The platform defines the cache-line
size via CACHE_WRITEBACK_GRANULE macro. This patch modifies
`declare_stack` helper macro to derive stack alignment from the
platform defined macro.

Change-Id: I1e1b00fc8806ecc88190ed169f4c8d3dd25fe95b

include/common/asm_macros.S
plat/common/aarch64/platform_mp_stack.S
plat/common/aarch64/platform_up_stack.S

index d4bd11ee2c770a2341ffdfd04b65ee1d9870ebdf..bd8bb70902119f03446562d8893feac76083313e 100644 (file)
        .endm
 #endif
 
+       /*
+        * Helper assembler macro to count trailing zeros. The output is
+        * populated in the `TZ_COUNT` symbol.
+        */
+       .macro count_tz _value, _tz_count
+       .if \_value
+         count_tz "(\_value >> 1)", "(\_tz_count + 1)"
+       .else
+         .equ TZ_COUNT, (\_tz_count - 1)
+       .endif
+       .endm
+
        /*
         * This macro declares an array of 1 or more stacks, properly
         * aligned and in the requested section
         */
-#define STACK_ALIGN    6
+#define DEFAULT_STACK_ALIGN    (1 << 6)   /* In case the caller doesnt provide alignment */
 
-       .macro declare_stack _name, _section, _size, _count
-       .if ((\_size & ((1 << STACK_ALIGN) - 1)) <> 0)
+       .macro declare_stack _name, _section, _size, _count, _align=DEFAULT_STACK_ALIGN
+       count_tz \_align, 0
+       .if (\_align - (1 << TZ_COUNT))
+         .error "Incorrect stack alignment specified (Must be a power of 2)."
+       .endif
+       .if ((\_size & ((1 << TZ_COUNT) - 1)) <> 0)
          .error "Stack size not correctly aligned"
        .endif
        .section    \_section, "aw", %nobits
-       .align STACK_ALIGN
+       .align TZ_COUNT
        \_name:
        .space ((\_count) * (\_size)), 0
        .endm
index c719019ac4736deedc6cc4c41755e443f48f7dda..a077f658c807b999ebdd77d1f0287c3292ef51ef 100644 (file)
@@ -193,4 +193,5 @@ endfunc plat_set_my_stack
         * -----------------------------------------------------
         */
 declare_stack platform_normal_stacks, tzfw_normal_stacks, \
-               PLATFORM_STACK_SIZE, PLATFORM_CORE_COUNT
+               PLATFORM_STACK_SIZE, PLATFORM_CORE_COUNT, \
+               CACHE_WRITEBACK_GRANULE
index c01534af5f3f48fe4eebc856170c825f995150ee..24b3a71fb3041f474f3db21f93f287157e086fe6 100644 (file)
@@ -99,4 +99,4 @@ endfunc_deprecated platform_set_stack
         * -----------------------------------------------------
         */
 declare_stack platform_normal_stacks, tzfw_normal_stacks, \
-               PLATFORM_STACK_SIZE, 1
+               PLATFORM_STACK_SIZE, 1, CACHE_WRITEBACK_GRANULE