Kyösti Mälkki | e5c00a5 | 2016-06-27 14:50:27 +0300 | [diff] [blame] | 1 | /* |
| 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 | |
| 26 | uintptr_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 | |
| 36 | uintptr_t romstage_ram_stack_bottom(void) |
| 37 | { |
| 38 | return romstage_ram_stack_base(ROMSTAGE_RAM_STACK_SIZE, |
| 39 | ROMSTAGE_STACK_CBMEM); |
| 40 | } |
| 41 | |
| 42 | uintptr_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älkki | de01136 | 2016-11-17 22:39:29 +0200 | [diff] [blame] | 47 | |
| 48 | /* Make it aligned to a 8-byte boundary. */ |
| 49 | stack_top = ALIGN_DOWN(stack_top, 8); |
Kyösti Mälkki | e5c00a5 | 2016-06-27 14:50:27 +0300 | [diff] [blame] | 50 | return stack_top; |
| 51 | } |