Skip to content

Commit 9bf88f3

Browse files
committed
memory: align stack space between xtensa smp and up
Aligns stack space, so that xtensa smp implementation matches xtensa up implementation. It also fixes problem with stack dump on smp architecture. Signed-off-by: Tomasz Lauda <tomasz.lauda@linux.intel.com>
1 parent 6baff99 commit 9bf88f3

22 files changed

Lines changed: 145 additions & 53 deletions

File tree

src/arch/xtensa/Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ nodist_sof_SOURCES = $(LINK_SCRIPT).in
2424
BUILT_SOURCES = $(LINK_SCRIPT)
2525
CLEANFILES = $(LINK_SCRIPT)
2626
$(LINK_SCRIPT): Makefile $(LINK_SCRIPT).in $(LINK_DEPS)
27-
cat $(LINK_SCRIPT).in | $(CPP) -P $(PLATFORM_INCDIR) $(SOF_INCDIR) - >$@
27+
cat $(LINK_SCRIPT).in | $(CPP) -P $(PLATFORM_INCDIR) $(SOF_INCDIR) $(ARCH_INCDIR) - >$@
2828

2929
noinst_LIBRARIES = \
3030
libreset.a
@@ -144,7 +144,7 @@ CLEANFILES += $(LINK_BOOT_LDR_SCRIPT)
144144

145145
nodist_boot_ldr_SOURCES = $(LINK_BOOT_LDR_SCRIPT).in
146146
$(LINK_BOOT_LDR_SCRIPT): Makefile $(LINK_BOOT_LDR_SCRIPT).in $(LINK_DEPS)
147-
cat $(LINK_BOOT_LDR_SCRIPT).in | $(CPP) -P $(PLATFORM_INCDIR) $(SOF_INCDIR) - >$@
147+
cat $(LINK_BOOT_LDR_SCRIPT).in | $(CPP) -P $(PLATFORM_INCDIR) $(SOF_INCDIR) $(ARCH_INCDIR) - >$@
148148

149149
boot_ldr_SOURCES = \
150150
boot_entry.S \
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
noinst_HEADERS = \
22
alloc.h \
3-
idc.h
3+
idc.h \
4+
memory.h
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2018, Intel Corporation
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
* * Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* * Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
* * Neither the name of the Intel Corporation nor the
13+
* names of its contributors may be used to endorse or promote products
14+
* derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
*
28+
* Author: Tomasz Lauda <tomasz.lauda@linux.intel.com>
29+
*/
30+
31+
/**
32+
* \file arch/xtensa/smp/include/arch/memory.h
33+
* \brief Xtensa SMP memory header file
34+
* \authors Tomasz Lauda <tomasz.lauda@linux.intel.com>
35+
*/
36+
37+
#ifndef __ARCH_MEMORY_H__
38+
#define __ARCH_MEMORY_H__
39+
40+
#include <platform/platcfg.h>
41+
42+
/** \brief Stack size. */
43+
#define ARCH_STACK_SIZE 0x1000
44+
45+
/** \brief Stack total size. */
46+
#define ARCH_STACK_TOTAL_SIZE (PLATFORM_CORE_COUNT * ARCH_STACK_SIZE)
47+
48+
#endif

src/arch/xtensa/smp/xtos/crt1-boards.S

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <xtensa/coreasm.h>
3434
#include "xtos-internal.h"
3535
#include <config.h>
36+
#include <arch/memory.h>
3637

3738

3839
// Exports
@@ -64,24 +65,6 @@
6465
#endif
6566

6667
/**************************************************************************/
67-
.macro generate_stack_for_idle core_id
68-
.if GREATERTHAN(PLATFORM_CORE_COUNT, \core_id)
69-
.section .bss, "aw"
70-
.align XTOS_IDLE_STACK_SIZE
71-
.if EQUAL(0, \core_id)
72-
.global _stack_start
73-
_stack_start:
74-
.endif
75-
.global _stack_start&core_id
76-
_stack_start&core_id:
77-
.space XTOS_IDLE_STACK_SIZE
78-
.endif
79-
.endm
80-
81-
generate_stack_for_idle 0
82-
generate_stack_for_idle 1
83-
generate_stack_for_idle 2
84-
generate_stack_for_idle 3
8568

8669
.text
8770
.align 4
@@ -248,7 +231,7 @@ xtos_per_core_init_interrupt_mask:
248231

249232
// Assign stack ptr before PS is initialized to avoid any debugger
250233
// side effects and prevent from double exception.
251-
xtos_stack_addr_percore_basic sp, a3, _stack_start, XTOS_IDLE_STACK_SIZE
234+
xtos_stack_addr_percore_basic sp, a3, _stack_sentry, ARCH_STACK_SIZE
252235

253236
/*
254237
* Now that sp (a1) is set, we can set PS as per the application

src/arch/xtensa/smp/xtos/xtos-internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,6 @@ extern void xtos_unhandled_interrupt();
510510
#define EQUAL(a, b) ((1 << (a)) & (1 << (b)))
511511

512512
#define XTOS_INT_STACK_SIZE 4096
513-
#define XTOS_IDLE_STACK_SIZE 4096
514513

515514
// sizeof(xtos_enabled)
516515
#define XTOS_ENABLED_SIZE_PER_CORE (4)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
noinst_HEADERS = \
2-
idc.h
2+
idc.h \
3+
memory.h
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2018, Intel Corporation
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
* * Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* * Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
* * Neither the name of the Intel Corporation nor the
13+
* names of its contributors may be used to endorse or promote products
14+
* derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
*
28+
* Author: Tomasz Lauda <tomasz.lauda@linux.intel.com>
29+
*/
30+
31+
/**
32+
* \file arch/xtensa/up/include/arch/memory.h
33+
* \brief Xtensa UP memory header file
34+
* \authors Tomasz Lauda <tomasz.lauda@linux.intel.com>
35+
*/
36+
37+
#ifndef __ARCH_MEMORY_H__
38+
#define __ARCH_MEMORY_H__
39+
40+
/** \brief Stack size. */
41+
#define ARCH_STACK_SIZE 0x1000
42+
43+
/** \brief Stack total size. */
44+
#define ARCH_STACK_TOTAL_SIZE ARCH_STACK_SIZE
45+
46+
#endif

src/include/sof/debug.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#include <sof/sof.h>
3636
#include <sof/mailbox.h>
37+
#include <sof/cpu.h>
3738
#include <uapi/ipc.h>
3839
#include <platform/platform.h>
3940
#include <stdint.h>
@@ -131,10 +132,10 @@
131132
static inline uint32_t dump_stack(uint32_t p, void *addr, size_t offset,
132133
size_t limit)
133134
{
134-
extern void *__stack;
135135
extern void *_stack_sentry;
136-
void *stack_bottom = (void *)&__stack - sizeof(void *);
137-
void *stack_limit = (void *)&_stack_sentry;
136+
void *stack_limit = (void *)&_stack_sentry +
137+
(cpu_get_id() * SOF_STACK_SIZE);
138+
void *stack_bottom = stack_limit + SOF_STACK_SIZE - sizeof(void *);
138139
void *stack_top = arch_get_stack_ptr() + offset;
139140
size_t size = stack_bottom - stack_top;
140141

src/library/include/platform/memory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#endif
3939

4040
#define HEAP_BUFFER_SIZE (1024 * 128)
41+
#define SOF_STACK_SIZE 0x1000
4142

4243
#if 0
4344
/* physical DSP addresses */

src/platform/apollolake/apollolake.x.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ SECTIONS
558558
{
559559
. = ALIGN (4096);
560560
_sof_stack_start = ABSOLUTE(.);
561-
. = . + SOF_STACK_SIZE;
561+
. = . + SOF_STACK_TOTAL_SIZE;
562562
_sof_stack_end = ABSOLUTE(.);
563563
} >sof_stack :sof_stack_phdr
564564

0 commit comments

Comments
 (0)