From: Patrick Delaunay <patrick.delaunay@st.com>
To: u-boot@lists.denx.de
Subject: [PATCH v4 4/4] board_f.c: Ensure 16 alignment of start_addr_sp and reserved memory
Date: Tue, 10 Mar 2020 10:15:05 +0100 [thread overview]
Message-ID: <20200310091505.24862-5-patrick.delaunay@st.com> (raw)
In-Reply-To: <20200310091505.24862-1-patrick.delaunay@st.com>
Add a function reserve_stack_aligned() to reserved memory with 16 bits
alignment after the stack pointer (gd->start_addr_sp) and use this new
function in board_f.c to reserve all the memory area (malloc, board, gd,
fdt, bootstage, stacks).
This 16 byte alignment is needed for cast on struct pointer
for the reserved memory, for example:
+ x86_64 ABI: https://reviews.llvm.org/D30049: 16 bytes
+ ARMv8 Instruction Set Overview: quad word, 16 bytes
An other alignment value could be needed for other architecture.
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Acked-by: Stephen Warren <swarren@nvidia.com>
---
Changes in v4:
- replace insure by ensure
Changes in v3:
- rename reserve_sp to reserve_stack_aligned
Changes in v2:
- fix commit message s/bits/bytes/
common/board_f.c | 32 ++++++++++++++++++--------------
1 file changed, 18 insertions(+), 14 deletions(-)
diff --git a/common/board_f.c b/common/board_f.c
index 0427b7b096..2ec5dbaa68 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -472,6 +472,17 @@ static int reserve_uboot(void)
return 0;
}
+/*
+ * reserve after start_addr_sp the requested size and make the stack pointer
+ * 16-byte aligned, this alignment is needed for cast on the reserved memory
+ * ref = x86_64 ABI: https://reviews.llvm.org/D30049: 16 bytes
+ * = ARMv8 Instruction Set Overview: quad word, 16 bytes
+ */
+static unsigned long reserve_stack_aligned(size_t size)
+{
+ return ALIGN_DOWN(gd->start_addr_sp - size, 16);
+}
+
#ifdef CONFIG_SYS_NONCACHED_MEMORY
static int reserve_noncached(void)
{
@@ -497,7 +508,7 @@ static int reserve_noncached(void)
/* reserve memory for malloc() area */
static int reserve_malloc(void)
{
- gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
+ gd->start_addr_sp = reserve_stack_aligned(TOTAL_MALLOC_LEN);
debug("Reserving %dk for malloc() at: %08lx\n",
TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
#ifdef CONFIG_SYS_NONCACHED_MEMORY
@@ -511,7 +522,7 @@ static int reserve_malloc(void)
static int reserve_board(void)
{
if (!gd->bd) {
- gd->start_addr_sp -= sizeof(bd_t);
+ gd->start_addr_sp = reserve_stack_aligned(sizeof(bd_t));
gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t));
memset(gd->bd, '\0', sizeof(bd_t));
debug("Reserving %zu Bytes for Board Info at: %08lx\n",
@@ -530,7 +541,7 @@ static int setup_machine(void)
static int reserve_global_data(void)
{
- gd->start_addr_sp -= sizeof(gd_t);
+ gd->start_addr_sp = reserve_stack_aligned(sizeof(gd_t));
gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
debug("Reserving %zu Bytes for Global Data at: %08lx\n",
sizeof(gd_t), gd->start_addr_sp);
@@ -548,7 +559,7 @@ static int reserve_fdt(void)
if (gd->fdt_blob) {
gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
- gd->start_addr_sp -= gd->fdt_size;
+ gd->start_addr_sp = reserve_stack_aligned(gd->fdt_size);
gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
debug("Reserving %lu Bytes for FDT at: %08lx\n",
gd->fdt_size, gd->start_addr_sp);
@@ -563,12 +574,7 @@ static int reserve_bootstage(void)
#ifdef CONFIG_BOOTSTAGE
int size = bootstage_get_size();
- gd->start_addr_sp -= size;
- /*
- * Ensure that start_addr_sp is aligned down to reserve enough
- * space for new_bootstage
- */
- gd->start_addr_sp = ALIGN_DOWN(gd->start_addr_sp, 16);
+ gd->start_addr_sp = reserve_stack_aligned(size);
gd->new_bootstage = map_sysmem(gd->start_addr_sp, size);
debug("Reserving %#x Bytes for bootstage at: %08lx\n", size,
gd->start_addr_sp);
@@ -585,8 +591,7 @@ __weak int arch_reserve_stacks(void)
static int reserve_stacks(void)
{
/* make stack pointer 16-byte aligned */
- gd->start_addr_sp -= 16;
- gd->start_addr_sp &= ~0xf;
+ gd->start_addr_sp = reserve_stack_aligned(16);
/*
* let the architecture-specific code tailor gd->start_addr_sp and
@@ -598,8 +603,7 @@ static int reserve_stacks(void)
static int reserve_bloblist(void)
{
#ifdef CONFIG_BLOBLIST
- gd->start_addr_sp &= ~0xf;
- gd->start_addr_sp -= CONFIG_BLOBLIST_SIZE;
+ gd->start_addr_sp = reserve_stack_aligned(CONFIG_BLOBLIST_SIZE);
gd->new_bloblist = map_sysmem(gd->start_addr_sp, CONFIG_BLOBLIST_SIZE);
#endif
--
2.17.1
next prev parent reply other threads:[~2020-03-10 9:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-10 9:15 [PATCH v4 0/4] Ensure 16 alignment of reserved memory in board_f.c Patrick Delaunay
2020-03-10 9:15 ` [PATCH v4 1/4] board_f.c: Ensure gd->new_bootstage alignment Patrick Delaunay
2020-04-17 21:08 ` Tom Rini
2020-03-10 9:15 ` [PATCH v4 2/4] Revert "stm32mp1: remove the imply BOOTSTAGE" Patrick Delaunay
2020-04-17 21:08 ` Tom Rini
2020-03-10 9:15 ` [PATCH v4 3/4] arm: set the relocated gd with gd->new_gd Patrick Delaunay
2020-04-17 21:08 ` Tom Rini
2020-03-10 9:15 ` Patrick Delaunay [this message]
2020-04-17 21:08 ` [PATCH v4 4/4] board_f.c: Ensure 16 alignment of start_addr_sp and reserved memory Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200310091505.24862-5-patrick.delaunay@st.com \
--to=patrick.delaunay@st.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox