2003-04-22 21:02:15 +02:00
|
|
|
/*
|
2013-04-24 22:14:01 +02:00
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Google, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
Remove address from GPLv2 headers
As per discussion with lawyers[tm], it's not a good idea to
shorten the license header too much - not for legal reasons
but because there are tools that look for them, and giving
them a standard pattern simplifies things.
However, we got confirmation that we don't have to update
every file ever added to coreboot whenever the FSF gets a
new lease, but can drop the address instead.
util/kconfig is excluded because that's imported code that
we may want to synchronize every now and then.
$ find * -type f -exec sed -i "s:Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *MA[, ]*02110-1301[, ]*USA:Foundation, Inc.:" {} +
$ find * -type f -exec sed -i "s:Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA:Foundation, Inc.:" {} +
$ find * -type f -exec sed -i "s:Foundation, Inc., 59 Temple Place[-, ]*Suite 330, Boston, MA *02111-1307[, ]*USA:Foundation, Inc.:" {} +
$ find * -type f -exec sed -i "s:Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.:Foundation, Inc.:" {} +
$ find * -type f
-a \! -name \*.patch \
-a \! -name \*_shipped \
-a \! -name LICENSE_GPL \
-a \! -name LGPL.txt \
-a \! -name COPYING \
-a \! -name DISCLAIMER \
-exec sed -i "/Foundation, Inc./ N;s:Foundation, Inc.* USA\.* *:Foundation, Inc. :;s:Foundation, Inc. $:Foundation, Inc.:" {} +
Change-Id: Icc968a5a5f3a5df8d32b940f9cdb35350654bef9
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Reviewed-on: http://review.coreboot.org/9233
Tested-by: build bot (Jenkins)
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
2015-03-26 15:17:45 +01:00
|
|
|
* Foundation, Inc.
|
2003-04-22 21:02:15 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2008-01-18 16:08:58 +01:00
|
|
|
* C Bootstrap code for the coreboot
|
2003-04-22 21:02:15 +02:00
|
|
|
*/
|
|
|
|
|
2013-11-14 03:22:15 +01:00
|
|
|
#include <arch/exception.h>
|
2013-04-24 22:14:01 +02:00
|
|
|
#include <bootstate.h>
|
2003-04-22 21:02:15 +02:00
|
|
|
#include <console/console.h>
|
2013-06-10 19:41:04 +02:00
|
|
|
#include <console/post_codes.h>
|
2015-04-06 23:12:58 +02:00
|
|
|
#include <cbmem.h>
|
2003-04-22 21:02:15 +02:00
|
|
|
#include <version.h>
|
2003-04-24 08:25:08 +02:00
|
|
|
#include <device/device.h>
|
|
|
|
#include <device/pci.h>
|
2003-07-19 06:28:22 +02:00
|
|
|
#include <delay.h>
|
2004-10-14 22:54:17 +02:00
|
|
|
#include <stdlib.h>
|
2010-02-22 07:09:43 +01:00
|
|
|
#include <reset.h>
|
2009-04-22 10:17:38 +02:00
|
|
|
#include <boot/tables.h>
|
2015-03-17 17:43:44 +01:00
|
|
|
#include <program_loading.h>
|
2012-06-13 01:29:32 +02:00
|
|
|
#include <lib.h>
|
2009-06-30 17:17:49 +02:00
|
|
|
#if CONFIG_HAVE_ACPI_RESUME
|
2009-04-13 19:57:44 +02:00
|
|
|
#include <arch/acpi.h>
|
2009-04-14 08:38:15 +02:00
|
|
|
#endif
|
2013-04-27 03:54:16 +02:00
|
|
|
#include <timer.h>
|
2011-11-04 20:31:58 +01:00
|
|
|
#include <timestamp.h>
|
2013-05-06 19:20:52 +02:00
|
|
|
#include <thread.h>
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
#if BOOT_STATE_DEBUG
|
|
|
|
#define BS_DEBUG_LVL BIOS_DEBUG
|
|
|
|
#else
|
|
|
|
#define BS_DEBUG_LVL BIOS_NEVER
|
Implement GCC code coverage analysis
In order to provide some insight on what code is executed during
coreboot's run time and how well our test scenarios work, this
adds code coverage support to coreboot's ram stage. This should
be easily adaptable for payloads, and maybe even romstage.
See http://gcc.gnu.org/onlinedocs/gcc/Gcov.html for
more information.
To instrument coreboot, select CONFIG_COVERAGE ("Code coverage
support") in Kconfig, and recompile coreboot. coreboot will then
store its code coverage information into CBMEM, if possible.
Then, run "cbmem -CV" as root on the target system running the
instrumented coreboot binary. This will create a whole bunch of
.gcda files that contain coverage information. Tar them up, copy
them to your build system machine, and untar them. Then you can
use your favorite coverage utility (gcov, lcov, ...) to visualize
code coverage.
For a sneak peak of what will expect you, please take a look
at http://www.coreboot.org/~stepan/coreboot-coverage/
Change-Id: Ib287d8309878a1f5c4be770c38b1bc0bb3aa6ec7
Signed-off-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/2052
Tested-by: build bot (Jenkins)
Reviewed-by: David Hendricks <dhendrix@chromium.org>
Reviewed-by: Martin Roth <martin@se-eng.com>
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
2012-12-19 01:23:28 +01:00
|
|
|
#endif
|
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
static boot_state_t bs_pre_device(void *arg);
|
|
|
|
static boot_state_t bs_dev_init_chips(void *arg);
|
|
|
|
static boot_state_t bs_dev_enumerate(void *arg);
|
|
|
|
static boot_state_t bs_dev_resources(void *arg);
|
2013-06-20 23:08:27 +02:00
|
|
|
static boot_state_t bs_dev_enable(void *arg);
|
2013-04-24 22:14:01 +02:00
|
|
|
static boot_state_t bs_dev_init(void *arg);
|
|
|
|
static boot_state_t bs_post_device(void *arg);
|
2013-04-25 05:33:08 +02:00
|
|
|
static boot_state_t bs_os_resume_check(void *arg);
|
2013-04-24 22:14:01 +02:00
|
|
|
static boot_state_t bs_os_resume(void *arg);
|
|
|
|
static boot_state_t bs_write_tables(void *arg);
|
|
|
|
static boot_state_t bs_payload_load(void *arg);
|
|
|
|
static boot_state_t bs_payload_boot(void *arg);
|
|
|
|
|
2013-04-27 03:54:16 +02:00
|
|
|
/*
|
|
|
|
* Typically a state will take 4 time samples:
|
|
|
|
* 1. Before state entry callbacks
|
|
|
|
* 2. After state entry callbacks / Before state function.
|
|
|
|
* 3. After state function / Before state exit callbacks.
|
|
|
|
* 4. After state exit callbacks.
|
|
|
|
*/
|
|
|
|
#define MAX_TIME_SAMPLES 4
|
|
|
|
struct boot_state_times {
|
|
|
|
int num_samples;
|
|
|
|
struct mono_time samples[MAX_TIME_SAMPLES];
|
|
|
|
};
|
|
|
|
|
2013-05-06 17:50:19 +02:00
|
|
|
/* The prologue (BS_ON_ENTRY) and epilogue (BS_ON_EXIT) of a state can be
|
|
|
|
* blocked from transitioning to the next (state,seq) pair. When the blockers
|
|
|
|
* field is 0 a transition may occur. */
|
|
|
|
struct boot_phase {
|
|
|
|
struct boot_state_callback *callbacks;
|
|
|
|
int blockers;
|
|
|
|
};
|
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
struct boot_state {
|
|
|
|
const char *name;
|
|
|
|
boot_state_t id;
|
2013-06-10 19:41:04 +02:00
|
|
|
u8 post_code;
|
2013-05-06 17:50:19 +02:00
|
|
|
struct boot_phase phases[2];
|
2013-04-24 22:14:01 +02:00
|
|
|
boot_state_t (*run_state)(void *arg);
|
|
|
|
void *arg;
|
2013-04-30 06:22:01 +02:00
|
|
|
int complete : 1;
|
2013-04-27 03:54:16 +02:00
|
|
|
#if CONFIG_HAVE_MONOTONIC_TIMER
|
|
|
|
struct boot_state_times times;
|
|
|
|
#endif
|
2013-04-24 22:14:01 +02:00
|
|
|
};
|
|
|
|
|
2013-05-06 17:52:24 +02:00
|
|
|
#define BS_INIT(state_, run_func_) \
|
2013-04-30 06:22:01 +02:00
|
|
|
{ \
|
|
|
|
.name = #state_, \
|
|
|
|
.id = state_, \
|
2013-06-10 19:41:04 +02:00
|
|
|
.post_code = POST_ ## state_, \
|
2013-05-06 17:50:19 +02:00
|
|
|
.phases = { { NULL, 0 }, { NULL, 0 } }, \
|
2013-04-30 06:22:01 +02:00
|
|
|
.run_state = run_func_, \
|
|
|
|
.arg = NULL, \
|
|
|
|
.complete = 0, \
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
2013-04-24 22:14:01 +02:00
|
|
|
#define BS_INIT_ENTRY(state_, run_func_) \
|
2013-05-06 17:52:24 +02:00
|
|
|
[state_] = BS_INIT(state_, run_func_)
|
2013-04-24 22:14:01 +02:00
|
|
|
|
|
|
|
static struct boot_state boot_states[] = {
|
|
|
|
BS_INIT_ENTRY(BS_PRE_DEVICE, bs_pre_device),
|
|
|
|
BS_INIT_ENTRY(BS_DEV_INIT_CHIPS, bs_dev_init_chips),
|
|
|
|
BS_INIT_ENTRY(BS_DEV_ENUMERATE, bs_dev_enumerate),
|
|
|
|
BS_INIT_ENTRY(BS_DEV_RESOURCES, bs_dev_resources),
|
2013-06-20 23:08:27 +02:00
|
|
|
BS_INIT_ENTRY(BS_DEV_ENABLE, bs_dev_enable),
|
2013-04-24 22:14:01 +02:00
|
|
|
BS_INIT_ENTRY(BS_DEV_INIT, bs_dev_init),
|
|
|
|
BS_INIT_ENTRY(BS_POST_DEVICE, bs_post_device),
|
2013-04-25 05:33:08 +02:00
|
|
|
BS_INIT_ENTRY(BS_OS_RESUME_CHECK, bs_os_resume_check),
|
2013-05-06 17:52:24 +02:00
|
|
|
BS_INIT_ENTRY(BS_OS_RESUME, bs_os_resume),
|
|
|
|
BS_INIT_ENTRY(BS_WRITE_TABLES, bs_write_tables),
|
|
|
|
BS_INIT_ENTRY(BS_PAYLOAD_LOAD, bs_payload_load),
|
|
|
|
BS_INIT_ENTRY(BS_PAYLOAD_BOOT, bs_payload_boot),
|
2013-04-24 22:14:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static boot_state_t bs_pre_device(void *arg)
|
|
|
|
{
|
|
|
|
return BS_DEV_INIT_CHIPS;
|
|
|
|
}
|
2013-02-12 07:40:30 +01:00
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
static boot_state_t bs_dev_init_chips(void *arg)
|
|
|
|
{
|
2013-09-07 16:26:08 +02:00
|
|
|
timestamp_add_now(TS_DEVICE_ENUMERATE);
|
2012-07-25 10:33:05 +02:00
|
|
|
|
|
|
|
/* Initialize chips early, they might disable unused devices. */
|
|
|
|
dev_initialize_chips();
|
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
return BS_DEV_ENUMERATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static boot_state_t bs_dev_enumerate(void *arg)
|
|
|
|
{
|
2004-11-04 12:04:33 +01:00
|
|
|
/* Find the devices we don't have hard coded knowledge about. */
|
2003-04-22 21:02:15 +02:00
|
|
|
dev_enumerate();
|
2011-11-04 20:31:58 +01:00
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
return BS_DEV_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
static boot_state_t bs_dev_resources(void *arg)
|
|
|
|
{
|
2013-09-07 16:26:08 +02:00
|
|
|
timestamp_add_now(TS_DEVICE_CONFIGURE);
|
2013-06-10 19:41:04 +02:00
|
|
|
|
2004-11-04 12:04:33 +01:00
|
|
|
/* Now compute and assign the bus resources. */
|
2003-04-22 21:02:15 +02:00
|
|
|
dev_configure();
|
2011-11-04 20:31:58 +01:00
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
return BS_DEV_ENABLE;
|
|
|
|
}
|
|
|
|
|
2013-06-20 23:08:27 +02:00
|
|
|
static boot_state_t bs_dev_enable(void *arg)
|
2013-04-24 22:14:01 +02:00
|
|
|
{
|
2013-09-07 16:26:08 +02:00
|
|
|
timestamp_add_now(TS_DEVICE_ENABLE);
|
2013-06-10 19:41:04 +02:00
|
|
|
|
2004-11-04 12:04:33 +01:00
|
|
|
/* Now actually enable devices on the bus */
|
2003-04-22 21:02:15 +02:00
|
|
|
dev_enable();
|
2011-11-04 20:31:58 +01:00
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
return BS_DEV_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static boot_state_t bs_dev_init(void *arg)
|
|
|
|
{
|
2013-09-07 16:26:08 +02:00
|
|
|
timestamp_add_now(TS_DEVICE_INITIALIZE);
|
2013-06-10 19:41:04 +02:00
|
|
|
|
2004-11-04 12:04:33 +01:00
|
|
|
/* And of course initialize devices on the bus */
|
2003-04-22 21:02:15 +02:00
|
|
|
dev_initialize();
|
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
return BS_POST_DEVICE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static boot_state_t bs_post_device(void *arg)
|
|
|
|
{
|
2013-10-30 00:32:00 +01:00
|
|
|
dev_finalize();
|
2013-09-07 16:26:08 +02:00
|
|
|
timestamp_add_now(TS_DEVICE_DONE);
|
2012-04-24 16:01:24 +02:00
|
|
|
|
2013-04-25 05:33:08 +02:00
|
|
|
return BS_OS_RESUME_CHECK;
|
2013-04-24 22:14:01 +02:00
|
|
|
}
|
|
|
|
|
2013-04-25 05:33:08 +02:00
|
|
|
static boot_state_t bs_os_resume_check(void *arg)
|
2013-04-24 22:14:01 +02:00
|
|
|
{
|
2012-10-15 22:41:56 +02:00
|
|
|
#if CONFIG_HAVE_ACPI_RESUME
|
2013-04-25 05:33:08 +02:00
|
|
|
void *wake_vector;
|
|
|
|
|
|
|
|
wake_vector = acpi_find_wakeup_vector();
|
|
|
|
|
|
|
|
if (wake_vector != NULL) {
|
|
|
|
boot_states[BS_OS_RESUME].arg = wake_vector;
|
|
|
|
return BS_OS_RESUME;
|
|
|
|
}
|
2014-10-16 19:58:47 +02:00
|
|
|
|
|
|
|
acpi_prepare_resume_backup();
|
2012-10-15 22:41:56 +02:00
|
|
|
#endif
|
2012-05-10 21:15:18 +02:00
|
|
|
timestamp_add_now(TS_CBMEM_POST);
|
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
return BS_WRITE_TABLES;
|
|
|
|
}
|
|
|
|
|
2013-04-25 05:33:08 +02:00
|
|
|
static boot_state_t bs_os_resume(void *wake_vector)
|
|
|
|
{
|
|
|
|
#if CONFIG_HAVE_ACPI_RESUME
|
|
|
|
acpi_resume(wake_vector);
|
|
|
|
#endif
|
|
|
|
return BS_WRITE_TABLES;
|
|
|
|
}
|
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
static boot_state_t bs_write_tables(void *arg)
|
|
|
|
{
|
2011-11-04 20:31:58 +01:00
|
|
|
timestamp_add_now(TS_WRITE_TABLES);
|
|
|
|
|
2004-10-14 22:54:17 +02:00
|
|
|
/* Now that we have collected all of our information
|
|
|
|
* write our configuration tables.
|
|
|
|
*/
|
2013-04-24 22:14:01 +02:00
|
|
|
write_tables();
|
|
|
|
|
2013-10-30 00:32:00 +01:00
|
|
|
dev_finalize_chips();
|
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
return BS_PAYLOAD_LOAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
static boot_state_t bs_payload_load(void *arg)
|
|
|
|
{
|
2015-03-20 16:20:15 +01:00
|
|
|
payload_load();
|
2013-04-24 22:14:01 +02:00
|
|
|
|
|
|
|
return BS_PAYLOAD_BOOT;
|
|
|
|
}
|
|
|
|
|
2014-02-24 21:56:34 +01:00
|
|
|
static boot_state_t bs_payload_boot(void *arg)
|
2013-04-24 22:14:01 +02:00
|
|
|
{
|
2015-03-20 16:20:15 +01:00
|
|
|
payload_run();
|
2013-04-24 22:14:01 +02:00
|
|
|
|
2012-06-13 01:29:32 +02:00
|
|
|
printk(BIOS_EMERG, "Boot failed");
|
2013-04-24 22:14:01 +02:00
|
|
|
/* Returning from this state will fail because the following signals
|
|
|
|
* return to a completed state. */
|
|
|
|
return BS_PAYLOAD_BOOT;
|
|
|
|
}
|
|
|
|
|
2013-04-27 03:54:16 +02:00
|
|
|
#if CONFIG_HAVE_MONOTONIC_TIMER
|
|
|
|
static void bs_sample_time(struct boot_state *state)
|
|
|
|
{
|
|
|
|
struct mono_time *mt;
|
|
|
|
|
|
|
|
mt = &state->times.samples[state->times.num_samples];
|
|
|
|
timer_monotonic_get(mt);
|
|
|
|
state->times.num_samples++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bs_report_time(struct boot_state *state)
|
|
|
|
{
|
2014-09-24 16:48:47 +02:00
|
|
|
long entry_time;
|
|
|
|
long run_time;
|
|
|
|
long exit_time;
|
|
|
|
struct mono_time *samples = &state->times.samples[0];
|
2013-04-27 03:54:16 +02:00
|
|
|
|
2014-09-24 16:48:47 +02:00
|
|
|
entry_time = mono_time_diff_microseconds(&samples[0], &samples[1]);
|
|
|
|
run_time = mono_time_diff_microseconds(&samples[1], &samples[2]);
|
|
|
|
exit_time = mono_time_diff_microseconds(&samples[2], &samples[3]);
|
2013-04-27 03:54:16 +02:00
|
|
|
|
|
|
|
printk(BIOS_DEBUG, "BS: %s times (us): entry %ld run %ld exit %ld\n",
|
2014-09-24 16:48:47 +02:00
|
|
|
state->name, entry_time, run_time, exit_time);
|
2013-04-27 03:54:16 +02:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline void bs_sample_time(struct boot_state *state) {}
|
|
|
|
static inline void bs_report_time(struct boot_state *state) {}
|
|
|
|
#endif
|
|
|
|
|
2013-04-30 06:22:01 +02:00
|
|
|
#if CONFIG_TIMER_QUEUE
|
|
|
|
static void bs_run_timers(int drain)
|
|
|
|
{
|
|
|
|
/* Drain all timer callbacks until none are left, if directed.
|
|
|
|
* Otherwise run the timers only once. */
|
|
|
|
do {
|
|
|
|
if (!timers_run())
|
|
|
|
break;
|
|
|
|
} while (drain);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void bs_run_timers(int drain) {}
|
|
|
|
#endif
|
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
static void bs_call_callbacks(struct boot_state *state,
|
|
|
|
boot_state_sequence_t seq)
|
|
|
|
{
|
2013-05-06 17:50:19 +02:00
|
|
|
struct boot_phase *phase = &state->phases[seq];
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
if (phase->callbacks != NULL) {
|
|
|
|
struct boot_state_callback *bscb;
|
2013-04-24 22:14:01 +02:00
|
|
|
|
2013-05-06 17:50:19 +02:00
|
|
|
/* Remove the first callback. */
|
|
|
|
bscb = phase->callbacks;
|
|
|
|
phase->callbacks = bscb->next;
|
|
|
|
bscb->next = NULL;
|
2013-04-24 22:14:01 +02:00
|
|
|
|
|
|
|
#if BOOT_STATE_DEBUG
|
2013-05-06 17:50:19 +02:00
|
|
|
printk(BS_DEBUG_LVL, "BS: callback (%p) @ %s.\n",
|
|
|
|
bscb, bscb->location);
|
2013-04-24 22:14:01 +02:00
|
|
|
#endif
|
2013-05-06 17:50:19 +02:00
|
|
|
bscb->callback(bscb->arg);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* All callbacks are complete and there are no blockers for
|
|
|
|
* this state. Therefore, this part of the state is complete. */
|
|
|
|
if (!phase->blockers)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Something is blocking this state from transitioning. As
|
|
|
|
* there are no more callbacks a pending timer needs to be
|
|
|
|
* ran to unblock the state. */
|
|
|
|
bs_run_timers(0);
|
2013-04-24 22:14:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-06 17:50:19 +02:00
|
|
|
/* Keep track of the current state. */
|
|
|
|
static struct state_tracker {
|
|
|
|
boot_state_t state_id;
|
|
|
|
boot_state_sequence_t seq;
|
|
|
|
} current_phase = {
|
|
|
|
.state_id = BS_PRE_DEVICE,
|
|
|
|
.seq = BS_ON_ENTRY,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void bs_walk_state_machine(void)
|
2013-04-24 22:14:01 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
struct boot_state *state;
|
2013-05-06 17:50:19 +02:00
|
|
|
boot_state_t next_id;
|
2013-04-24 22:14:01 +02:00
|
|
|
|
2013-05-06 17:50:19 +02:00
|
|
|
state = &boot_states[current_phase.state_id];
|
2013-04-24 22:14:01 +02:00
|
|
|
|
|
|
|
if (state->complete) {
|
|
|
|
printk(BIOS_EMERG, "BS: %s state already executed.\n",
|
|
|
|
state->name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
printk(BS_DEBUG_LVL, "BS: Entering %s state.\n", state->name);
|
2013-04-27 03:54:16 +02:00
|
|
|
|
2013-05-06 17:52:24 +02:00
|
|
|
bs_run_timers(0);
|
2013-04-30 06:22:01 +02:00
|
|
|
|
2013-04-27 03:54:16 +02:00
|
|
|
bs_sample_time(state);
|
|
|
|
|
2013-05-06 17:50:19 +02:00
|
|
|
bs_call_callbacks(state, current_phase.seq);
|
|
|
|
/* Update the current sequence so that any calls to block the
|
|
|
|
* current state from the run_state() function will place a
|
|
|
|
* block on the correct phase. */
|
|
|
|
current_phase.seq = BS_ON_EXIT;
|
2013-04-24 22:14:01 +02:00
|
|
|
|
2013-04-27 03:54:16 +02:00
|
|
|
bs_sample_time(state);
|
|
|
|
|
2013-06-10 19:41:04 +02:00
|
|
|
post_code(state->post_code);
|
|
|
|
|
2013-05-06 17:50:19 +02:00
|
|
|
next_id = state->run_state(state->arg);
|
2013-04-24 22:14:01 +02:00
|
|
|
|
|
|
|
printk(BS_DEBUG_LVL, "BS: Exiting %s state.\n", state->name);
|
2013-04-27 03:54:16 +02:00
|
|
|
|
|
|
|
bs_sample_time(state);
|
|
|
|
|
2013-05-06 17:50:19 +02:00
|
|
|
bs_call_callbacks(state, current_phase.seq);
|
|
|
|
|
|
|
|
/* Update the current phase with new state id and sequence. */
|
|
|
|
current_phase.state_id = next_id;
|
|
|
|
current_phase.seq = BS_ON_ENTRY;
|
2013-04-24 22:14:01 +02:00
|
|
|
|
2013-04-27 03:54:16 +02:00
|
|
|
bs_sample_time(state);
|
|
|
|
|
|
|
|
bs_report_time(state);
|
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
state->complete = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int boot_state_sched_callback(struct boot_state *state,
|
|
|
|
struct boot_state_callback *bscb,
|
|
|
|
boot_state_sequence_t seq)
|
|
|
|
{
|
|
|
|
if (state->complete) {
|
|
|
|
printk(BIOS_WARNING,
|
|
|
|
"Tried to schedule callback on completed state %s.\n",
|
|
|
|
state->name);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-05-06 17:50:19 +02:00
|
|
|
bscb->next = state->phases[seq].callbacks;
|
|
|
|
state->phases[seq].callbacks = bscb;
|
2013-04-24 22:14:01 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int boot_state_sched_on_entry(struct boot_state_callback *bscb,
|
|
|
|
boot_state_t state_id)
|
|
|
|
{
|
|
|
|
struct boot_state *state = &boot_states[state_id];
|
|
|
|
|
|
|
|
return boot_state_sched_callback(state, bscb, BS_ON_ENTRY);
|
|
|
|
}
|
|
|
|
|
|
|
|
int boot_state_sched_on_exit(struct boot_state_callback *bscb,
|
|
|
|
boot_state_t state_id)
|
|
|
|
{
|
|
|
|
struct boot_state *state = &boot_states[state_id];
|
|
|
|
|
|
|
|
return boot_state_sched_callback(state, bscb, BS_ON_EXIT);
|
|
|
|
}
|
|
|
|
|
2013-04-24 23:12:52 +02:00
|
|
|
static void boot_state_schedule_static_entries(void)
|
|
|
|
{
|
2015-03-16 23:30:09 +01:00
|
|
|
extern struct boot_state_init_entry *_bs_init_begin[];
|
|
|
|
struct boot_state_init_entry **slot;
|
2013-04-24 23:12:52 +02:00
|
|
|
|
2015-03-16 23:30:09 +01:00
|
|
|
for (slot = &_bs_init_begin[0]; *slot != NULL; slot++) {
|
|
|
|
struct boot_state_init_entry *cur = *slot;
|
2013-04-24 23:12:52 +02:00
|
|
|
|
|
|
|
if (cur->when == BS_ON_ENTRY)
|
|
|
|
boot_state_sched_on_entry(&cur->bscb, cur->state);
|
|
|
|
else
|
|
|
|
boot_state_sched_on_exit(&cur->bscb, cur->state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-10 01:30:06 +02:00
|
|
|
void main(void)
|
2013-04-24 22:14:01 +02:00
|
|
|
{
|
2015-04-21 18:57:18 +02:00
|
|
|
/* console_init() MUST PRECEDE ALL printk()! Additionally, ensure
|
|
|
|
* it is the very first thing done in ramstage.*/
|
|
|
|
console_init();
|
|
|
|
|
|
|
|
post_code(POST_CONSOLE_READY);
|
|
|
|
|
2015-04-06 23:12:58 +02:00
|
|
|
/*
|
|
|
|
* CBMEM needs to be recovered in the EARLY_CBMEM_INIT case because
|
|
|
|
* timestamps, APCI, etc rely on the cbmem infrastructure being
|
|
|
|
* around. Explicitly recover it.
|
|
|
|
*/
|
|
|
|
if (IS_ENABLED(CONFIG_EARLY_CBMEM_INIT))
|
|
|
|
cbmem_initialize();
|
|
|
|
|
2013-09-07 16:26:08 +02:00
|
|
|
/* Record current time, try to locate timestamps in CBMEM. */
|
2013-08-01 22:31:44 +02:00
|
|
|
timestamp_init(timestamp_get());
|
2013-09-07 16:26:08 +02:00
|
|
|
|
|
|
|
timestamp_add_now(TS_START_RAMSTAGE);
|
2013-04-24 22:14:01 +02:00
|
|
|
post_code(POST_ENTRY_RAMSTAGE);
|
|
|
|
|
2014-06-19 22:29:07 +02:00
|
|
|
/* Handoff sleep type from romstage. */
|
|
|
|
#if CONFIG_HAVE_ACPI_RESUME
|
|
|
|
acpi_is_wakeup();
|
|
|
|
#endif
|
|
|
|
|
2013-11-14 03:22:15 +01:00
|
|
|
exception_init();
|
2013-05-06 19:20:52 +02:00
|
|
|
threads_initialize();
|
|
|
|
|
2013-04-24 23:12:52 +02:00
|
|
|
/* Schedule the static boot state entries. */
|
|
|
|
boot_state_schedule_static_entries();
|
|
|
|
|
2014-12-08 22:39:14 +01:00
|
|
|
/* TODO: Understand why this is here and move to arch/platform code. */
|
|
|
|
if (IS_ENABLED(CONFIG_ARCH_X86))
|
|
|
|
init_timer();
|
2013-04-24 22:14:01 +02:00
|
|
|
|
2013-05-06 17:50:19 +02:00
|
|
|
bs_walk_state_machine();
|
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
die("Boot state machine failure.\n");
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
|
|
|
|
2013-05-06 17:50:19 +02:00
|
|
|
|
|
|
|
int boot_state_block(boot_state_t state, boot_state_sequence_t seq)
|
|
|
|
{
|
|
|
|
struct boot_phase *bp;
|
|
|
|
|
|
|
|
/* Blocking a previously ran state is not appropriate. */
|
|
|
|
if (current_phase.state_id > state ||
|
|
|
|
(current_phase.state_id == state && current_phase.seq > seq) ) {
|
|
|
|
printk(BIOS_WARNING,
|
|
|
|
"BS: Completed state (%d, %d) block attempted.\n",
|
|
|
|
state, seq);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bp = &boot_states[state].phases[seq];
|
|
|
|
bp->blockers++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int boot_state_unblock(boot_state_t state, boot_state_sequence_t seq)
|
|
|
|
{
|
|
|
|
struct boot_phase *bp;
|
|
|
|
|
|
|
|
/* Blocking a previously ran state is not appropriate. */
|
|
|
|
if (current_phase.state_id > state ||
|
|
|
|
(current_phase.state_id == state && current_phase.seq > seq) ) {
|
|
|
|
printk(BIOS_WARNING,
|
|
|
|
"BS: Completed state (%d, %d) unblock attempted.\n",
|
|
|
|
state, seq);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bp = &boot_states[state].phases[seq];
|
|
|
|
|
|
|
|
if (bp->blockers == 0) {
|
|
|
|
printk(BIOS_WARNING,
|
|
|
|
"BS: Unblock attempted on non-blocked state (%d, %d).\n",
|
|
|
|
state, seq);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bp->blockers--;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void boot_state_current_block(void)
|
|
|
|
{
|
|
|
|
boot_state_block(current_phase.state_id, current_phase.seq);
|
|
|
|
}
|
|
|
|
|
|
|
|
void boot_state_current_unblock(void)
|
|
|
|
{
|
|
|
|
boot_state_unblock(current_phase.state_id, current_phase.seq);
|
|
|
|
}
|