blob: ed6f09b4cb6f61124fb07519227d16526e25f20d [file] [log] [blame]
Kyösti Mälkkie5c00a52016-06-27 14:50:27 +03001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 Google Inc.
5 * Copyright (C) 2015-2016 Intel Corp.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <program_loading.h>
18#include <cbmem.h>
19
20/*
21 * Romstage needs quite a bit of stack for decompressing images since the lzma
22 * lib keeps its state on the stack during romstage.
23 */
24#define ROMSTAGE_RAM_STACK_SIZE 0x5000
25
26uintptr_t romstage_ram_stack_base(size_t size, int src)
27{
28 /* cbmem_add() does a find() before add(). */
29 if (src == ROMSTAGE_STACK_CBMEM)
30 return (uintptr_t)cbmem_add(CBMEM_ID_ROMSTAGE_RAM_STACK, size);
31 if (src == ROMSTAGE_STACK_LOW_MEM)
32 return CONFIG_RAMTOP - size;
33 return 0;
34}
35
36uintptr_t romstage_ram_stack_bottom(void)
37{
38 return romstage_ram_stack_base(ROMSTAGE_RAM_STACK_SIZE,
39 ROMSTAGE_STACK_CBMEM);
40}
41
42uintptr_t romstage_ram_stack_top(void)
43{
44 uintptr_t stack_top = romstage_ram_stack_base(ROMSTAGE_RAM_STACK_SIZE,
45 ROMSTAGE_STACK_CBMEM);
46 stack_top += ROMSTAGE_RAM_STACK_SIZE;
Kyösti Mälkkide011362016-11-17 22:39:29 +020047
48 /* Make it aligned to a 8-byte boundary. */
49 stack_top = ALIGN_DOWN(stack_top, 8);
Kyösti Mälkkie5c00a52016-06-27 14:50:27 +030050 return stack_top;
51}