blob: faa2bc9f04f82f57fcb7f81887c2029f273b68e5 [file] [log] [blame]
Angel Pons118a9c72020-04-02 23:48:34 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbinafe8aee2016-11-29 21:37:42 -06002
3#include <stdint.h>
4#include <string.h>
5#include <cbmem.h>
6#include <console/console.h>
7#include <romstage_handoff.h>
Aaron Durbinafe8aee2016-11-29 21:37:42 -06008
9struct romstage_handoff {
10 /* Indicate if the current boot is an S3 resume. If
Martin Roth0639bff2020-11-09 13:13:27 -070011 * CONFIG_RELOCATABLE_RAMSTAGE is enabled the chipset code is
Aaron Durbinafe8aee2016-11-29 21:37:42 -060012 * 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
20static 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
42int 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
56int romstage_handoff_is_resume(void)
57{
Kyösti Mälkkiac0dc4a2020-11-18 07:40:21 +020058 static int once, s3_resume;
Aaron Durbinafe8aee2016-11-29 21:37:42 -060059 struct romstage_handoff *handoff;
60
Kyösti Mälkkiac0dc4a2020-11-18 07:40:21 +020061 if (once)
62 return s3_resume;
Aaron Durbinafe8aee2016-11-29 21:37:42 -060063
Kyösti Mälkkiac0dc4a2020-11-18 07:40:21 +020064 /* Only try evaluate handoff once for s3 resume state. */
65 once = 1;
66 handoff = cbmem_find(CBMEM_ID_ROMSTAGE_INFO);
Aaron Durbinafe8aee2016-11-29 21:37:42 -060067 if (handoff == NULL)
68 return 0;
69
Kyösti Mälkkiac0dc4a2020-11-18 07:40:21 +020070 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 Durbinafe8aee2016-11-29 21:37:42 -060077}