Angel Pons | 118a9c7 | 2020-04-02 23:48:34 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | afe8aee | 2016-11-29 21:37:42 -0600 | [diff] [blame] | 2 | |
| 3 | #include <stdint.h> |
| 4 | #include <string.h> |
| 5 | #include <cbmem.h> |
| 6 | #include <console/console.h> |
| 7 | #include <romstage_handoff.h> |
Aaron Durbin | afe8aee | 2016-11-29 21:37:42 -0600 | [diff] [blame] | 8 | |
| 9 | struct romstage_handoff { |
| 10 | /* Indicate if the current boot is an S3 resume. If |
| 11 | * CONFIG_RELOCTABLE_RAMSTAGE is enabled the chipset code is |
| 12 | * responsible for initializing this variable. Otherwise, ramstage |
| 13 | * will be re-loaded from cbfs (which can be slower since it lives |
| 14 | * in flash). */ |
| 15 | uint8_t s3_resume; |
| 16 | uint8_t reboot_required; |
| 17 | uint8_t reserved[2]; |
| 18 | }; |
| 19 | |
| 20 | static struct romstage_handoff *romstage_handoff_find_or_add(void) |
| 21 | { |
| 22 | struct romstage_handoff *handoff; |
| 23 | |
| 24 | /* cbmem_add() first does a find and uses the old location before the |
| 25 | * real add. However, it is important to know when the structure is not |
| 26 | * found so it can be initialized to 0. */ |
| 27 | handoff = cbmem_find(CBMEM_ID_ROMSTAGE_INFO); |
| 28 | |
| 29 | if (handoff) |
| 30 | return handoff; |
| 31 | |
| 32 | handoff = cbmem_add(CBMEM_ID_ROMSTAGE_INFO, sizeof(*handoff)); |
| 33 | |
| 34 | if (handoff != NULL) |
| 35 | memset(handoff, 0, sizeof(*handoff)); |
| 36 | else |
| 37 | printk(BIOS_DEBUG, "Romstage handoff structure not added!\n"); |
| 38 | |
| 39 | return handoff; |
| 40 | } |
| 41 | |
| 42 | int romstage_handoff_init(int is_s3_resume) |
| 43 | { |
| 44 | struct romstage_handoff *handoff; |
| 45 | |
| 46 | handoff = romstage_handoff_find_or_add(); |
| 47 | |
| 48 | if (handoff == NULL) |
| 49 | return -1; |
| 50 | |
| 51 | handoff->s3_resume = is_s3_resume; |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | int romstage_handoff_is_resume(void) |
| 57 | { |
| 58 | struct romstage_handoff *handoff; |
| 59 | |
| 60 | handoff = cbmem_find(CBMEM_ID_ROMSTAGE_INFO); |
| 61 | |
| 62 | if (handoff == NULL) |
| 63 | return 0; |
| 64 | |
| 65 | return handoff->s3_resume; |
| 66 | } |