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 |
Martin Roth | 0639bff | 2020-11-09 13:13:27 -0700 | [diff] [blame] | 11 | * CONFIG_RELOCATABLE_RAMSTAGE is enabled the chipset code is |
Aaron Durbin | afe8aee | 2016-11-29 21:37:42 -0600 | [diff] [blame] | 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 | { |
Kyösti Mälkki | ac0dc4a | 2020-11-18 07:40:21 +0200 | [diff] [blame] | 58 | static int once, s3_resume; |
Aaron Durbin | afe8aee | 2016-11-29 21:37:42 -0600 | [diff] [blame] | 59 | struct romstage_handoff *handoff; |
| 60 | |
Kyösti Mälkki | ac0dc4a | 2020-11-18 07:40:21 +0200 | [diff] [blame] | 61 | if (once) |
| 62 | return s3_resume; |
Aaron Durbin | afe8aee | 2016-11-29 21:37:42 -0600 | [diff] [blame] | 63 | |
Kyösti Mälkki | ac0dc4a | 2020-11-18 07:40:21 +0200 | [diff] [blame] | 64 | /* Only try evaluate handoff once for s3 resume state. */ |
| 65 | once = 1; |
| 66 | handoff = cbmem_find(CBMEM_ID_ROMSTAGE_INFO); |
Aaron Durbin | afe8aee | 2016-11-29 21:37:42 -0600 | [diff] [blame] | 67 | if (handoff == NULL) |
| 68 | return 0; |
| 69 | |
Kyösti Mälkki | ac0dc4a | 2020-11-18 07:40:21 +0200 | [diff] [blame] | 70 | s3_resume = handoff->s3_resume; |
| 71 | if (s3_resume) |
| 72 | printk(BIOS_DEBUG, "S3 Resume\n"); |
| 73 | else |
| 74 | printk(BIOS_DEBUG, "Normal boot\n"); |
| 75 | |
| 76 | return s3_resume; |
Aaron Durbin | afe8aee | 2016-11-29 21:37:42 -0600 | [diff] [blame] | 77 | } |