blob: 04ead0a83f7801a8d215e718fdf956cbdc3112ba [file] [log] [blame]
Aaron Durbinafe8aee2016-11-29 21:37:42 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2016 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <stdint.h>
17#include <string.h>
18#include <cbmem.h>
19#include <console/console.h>
20#include <romstage_handoff.h>
Aaron Durbinafe8aee2016-11-29 21:37:42 -060021
22struct romstage_handoff {
23 /* Indicate if the current boot is an S3 resume. If
24 * CONFIG_RELOCTABLE_RAMSTAGE is enabled the chipset code is
25 * responsible for initializing this variable. Otherwise, ramstage
26 * will be re-loaded from cbfs (which can be slower since it lives
27 * in flash). */
28 uint8_t s3_resume;
29 uint8_t reboot_required;
30 uint8_t reserved[2];
31};
32
33static struct romstage_handoff *romstage_handoff_find_or_add(void)
34{
35 struct romstage_handoff *handoff;
36
37 /* cbmem_add() first does a find and uses the old location before the
38 * real add. However, it is important to know when the structure is not
39 * found so it can be initialized to 0. */
40 handoff = cbmem_find(CBMEM_ID_ROMSTAGE_INFO);
41
42 if (handoff)
43 return handoff;
44
45 handoff = cbmem_add(CBMEM_ID_ROMSTAGE_INFO, sizeof(*handoff));
46
47 if (handoff != NULL)
48 memset(handoff, 0, sizeof(*handoff));
49 else
50 printk(BIOS_DEBUG, "Romstage handoff structure not added!\n");
51
52 return handoff;
53}
54
55int romstage_handoff_init(int is_s3_resume)
56{
57 struct romstage_handoff *handoff;
58
59 handoff = romstage_handoff_find_or_add();
60
61 if (handoff == NULL)
62 return -1;
63
64 handoff->s3_resume = is_s3_resume;
65
66 return 0;
67}
68
69int romstage_handoff_is_resume(void)
70{
71 struct romstage_handoff *handoff;
72
73 handoff = cbmem_find(CBMEM_ID_ROMSTAGE_INFO);
74
75 if (handoff == NULL)
76 return 0;
77
78 return handoff->s3_resume;
79}