blob: bdfdb642b8e2c19f639f80e8a7a0e3940af34b51 [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>
21#include <rules.h>
22
23struct romstage_handoff {
24 /* Indicate if the current boot is an S3 resume. If
25 * CONFIG_RELOCTABLE_RAMSTAGE is enabled the chipset code is
26 * responsible for initializing this variable. Otherwise, ramstage
27 * will be re-loaded from cbfs (which can be slower since it lives
28 * in flash). */
29 uint8_t s3_resume;
30 uint8_t reboot_required;
31 uint8_t reserved[2];
32};
33
34static struct romstage_handoff *romstage_handoff_find_or_add(void)
35{
36 struct romstage_handoff *handoff;
37
38 /* cbmem_add() first does a find and uses the old location before the
39 * real add. However, it is important to know when the structure is not
40 * found so it can be initialized to 0. */
41 handoff = cbmem_find(CBMEM_ID_ROMSTAGE_INFO);
42
43 if (handoff)
44 return handoff;
45
46 handoff = cbmem_add(CBMEM_ID_ROMSTAGE_INFO, sizeof(*handoff));
47
48 if (handoff != NULL)
49 memset(handoff, 0, sizeof(*handoff));
50 else
51 printk(BIOS_DEBUG, "Romstage handoff structure not added!\n");
52
53 return handoff;
54}
55
56int romstage_handoff_init(int is_s3_resume)
57{
58 struct romstage_handoff *handoff;
59
60 handoff = romstage_handoff_find_or_add();
61
62 if (handoff == NULL)
63 return -1;
64
65 handoff->s3_resume = is_s3_resume;
66
67 return 0;
68}
69
70int romstage_handoff_is_resume(void)
71{
72 struct romstage_handoff *handoff;
73
74 handoff = cbmem_find(CBMEM_ID_ROMSTAGE_INFO);
75
76 if (handoff == NULL)
77 return 0;
78
79 return handoff->s3_resume;
80}