blob: b54619d8d8d8373ad17d3e8288d69c7051115311 [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
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
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{
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}