blob: 166ec8701336b9e5489ab0c94e2760c2e33966fb [file] [log] [blame]
Aaron Durbindf3a1092013-03-13 12:41:44 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 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,
Aaron Durbin2c4aab32015-03-06 23:26:06 -060011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Aaron Durbindf3a1092013-03-13 12:41:44 -050012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Aaron Durbindf3a1092013-03-13 12:41:44 -050014 */
15#include <console/console.h>
16#include <cbmem.h>
Aaron Durbin0dff57d2015-03-05 21:18:33 -060017#include <bootstate.h>
18#include <rules.h>
Kyösti Mälkki4fbac462015-01-07 04:48:43 +020019#include <symbols.h>
Aaron Durbin0dff57d2015-03-05 21:18:33 -060020#if IS_ENABLED(CONFIG_ARCH_X86) && !IS_ENABLED(CONFIG_EARLY_CBMEM_INIT)
21#include <arch/acpi.h>
22#endif
Aaron Durbindf3a1092013-03-13 12:41:44 -050023
Aaron Durbin41607a42015-06-09 13:54:10 -050024void cbmem_run_init_hooks(int is_recovery)
Kyösti Mälkki823edda2014-12-18 18:30:29 +020025{
Lee Leahy73402172017-03-10 15:23:24 -080026 cbmem_init_hook_t *init_hook_ptr =
27 (cbmem_init_hook_t *)&_cbmem_init_hooks;
28 cbmem_init_hook_t *einit_hook_ptr =
29 (cbmem_init_hook_t *)&_ecbmem_init_hooks;
Kyösti Mälkki4d107502014-12-19 10:17:46 +020030
Kyösti Mälkki4fbac462015-01-07 04:48:43 +020031 if (_cbmem_init_hooks_size == 0)
32 return;
33
34 while (init_hook_ptr != einit_hook_ptr) {
Aaron Durbin41607a42015-06-09 13:54:10 -050035 (*init_hook_ptr)(is_recovery);
Kyösti Mälkki4fbac462015-01-07 04:48:43 +020036 init_hook_ptr++;
37 }
Kyösti Mälkki823edda2014-12-18 18:30:29 +020038}
39
40void __attribute__((weak)) cbmem_fail_resume(void)
41{
42}
Aaron Durbin0dff57d2015-03-05 21:18:33 -060043
44#if ENV_RAMSTAGE && !IS_ENABLED(CONFIG_EARLY_CBMEM_INIT)
45static void init_cbmem_post_device(void *unused)
46{
47 if (acpi_is_wakeup())
48 cbmem_initialize();
49 else
50 cbmem_initialize_empty();
51}
52
53BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_ENTRY,
54 init_cbmem_post_device, NULL);
55#endif