blob: 2a057d6ba43d309f9769a9bf70902475cf1d1289 [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{
Kyösti Mälkki4fbac462015-01-07 04:48:43 +020026 cbmem_init_hook_t *init_hook_ptr = (cbmem_init_hook_t*) &_cbmem_init_hooks;
27 cbmem_init_hook_t *einit_hook_ptr = (cbmem_init_hook_t*) &_ecbmem_init_hooks;
Kyösti Mälkki4d107502014-12-19 10:17:46 +020028
Kyösti Mälkki4fbac462015-01-07 04:48:43 +020029 if (_cbmem_init_hooks_size == 0)
30 return;
31
32 while (init_hook_ptr != einit_hook_ptr) {
Aaron Durbin41607a42015-06-09 13:54:10 -050033 (*init_hook_ptr)(is_recovery);
Kyösti Mälkki4fbac462015-01-07 04:48:43 +020034 init_hook_ptr++;
35 }
Kyösti Mälkki823edda2014-12-18 18:30:29 +020036}
37
38void __attribute__((weak)) cbmem_fail_resume(void)
39{
40}
Aaron Durbin0dff57d2015-03-05 21:18:33 -060041
42#if ENV_RAMSTAGE && !IS_ENABLED(CONFIG_EARLY_CBMEM_INIT)
43static void init_cbmem_post_device(void *unused)
44{
45 if (acpi_is_wakeup())
46 cbmem_initialize();
47 else
48 cbmem_initialize_empty();
49}
50
51BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_ENTRY,
52 init_cbmem_post_device, NULL);
53#endif