diff options
author | Aaron Durbin <adurbin@chromium.org> | 2013-04-24 15:14:01 -0500 |
---|---|---|
committer | Ronald G. Minnich <rminnich@gmail.com> | 2013-05-01 07:04:47 +0200 |
commit | 7e35efa83cdd6240e4f9282cc4d2703c40d472d5 (patch) | |
tree | 09091124f6b118ca5c9e5ac1c675d138174564bf /src/include | |
parent | e1be5ae2f485989f88ae9af92a97e0577b033155 (diff) |
ramstage: introduce boot state machine
The boot flow currently has a fixed ordering. The ordering
is dictated by the device tree and on x86 the PCI device ordering
for when actions are performed. Many of the new machines and
configurations have dependencies that do not follow the device
ordering.
In order to be more flexible the concept of a boot state machine
is introduced. At the boundaries (entry and exit) of each state there
is opportunity to run callbacks. This ability allows one to schedule
actions to be performed without adding board-specific code to
the shared boot flow.
Change-Id: I757f406c97445f6d9b69c003bb9610b16b132aa6
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: http://review.coreboot.org/3132
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/bootstate.h | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/src/include/bootstate.h b/src/include/bootstate.h new file mode 100644 index 0000000000..a2eacfbb70 --- /dev/null +++ b/src/include/bootstate.h @@ -0,0 +1,161 @@ +/* + * 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 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#ifndef BOOTSTATE_H +#define BOOTSTATE_H + +#include <string.h> + +/* Control debugging of the boot state machine. */ +#define BOOT_STATE_DEBUG 0 + +/* + * The boot state machine provides a mechanism for calls to be made through- + * out the main boot process. The boot process is separated into discrete + * states. Upon a state's entry and exit and callbacks can be made. For + * example: + * + * Enter State + * + + * | + * V + * +-----------------+ + * | Entry callbacks | + * +-----------------+ + * | State Actions | + * +-----------------+ + * | Exit callbacks | + * +-------+---------+ + * | + * V + * Next State + * + * Below is the current flow from top to bottom: + * + * start + * | + * BS_PRE_DEVICE + * | + * BS_DEV_INIT_CHIPS + * | + * BS_DEV_ENUMERATE + * | + * BS_DEV_RESOURCES + * | + * BS_DEV_ENABLE + * | + * BS_DEV_INIT + * | + * BS_POST_DEVICE + * | + * BS_OS_RESUME_CHECK -------- BS_OS_RESUME + * | | + * BS_WRITE_TABLES os handoff + * | + * BS_PAYLOAD_LOAD + * | + * BS_PAYLOAD_BOOT + * | + * payload run + * + * Brief description of states: + * BS_PRE_DEVICE - before any device tree actions take place + * BS_DEV_INIT_CHIPS - init all chips in device tree + * BS_DEV_ENUMERATE - device tree probing + * BS_DEV_RESOURCES - device tree resource allocation and assignment + * BS_DEV_ENABLE - device tree enabling/disabling of devices + * BS_DEV_INIT - device tree device initialization + * BS_POST_DEVICE - all device tree actions performed + * BS_OS_RESUME_CHECK - check for OS resume + * BS_OS_RESUME - resume to OS + * BS_WRITE_TABLES - write coreboot tables + * BS_PAYLOAD_LOAD - Load payload into memory + * BS_PAYLOAD_BOOT - Boot to payload + */ + +typedef enum { + BS_PRE_DEVICE, + BS_DEV_INIT_CHIPS, + BS_DEV_ENUMERATE, + BS_DEV_RESOURCES, + BS_DEV_ENABLE, + BS_DEV_INIT, + BS_POST_DEVICE, + BS_OS_RESUME, + BS_WRITE_TABLES, + BS_PAYLOAD_LOAD, + BS_PAYLOAD_BOOT, +} boot_state_t; + +/* The boot_state_sequence_t describes when a callback is to be made. It is + * called either before a state is entered or when a state is exited. */ +typedef enum { + BS_ON_ENTRY, + BS_ON_EXIT +} boot_state_sequence_t; + +struct boot_state_callback { + void *arg; + void (*callback)(void *arg); + /* For use internal to the boot state machine. */ + struct boot_state_callback *next; +#if BOOT_STATE_DEBUG + const char *location; +#endif +}; + +#if BOOT_STATE_DEBUG +#define BOOT_STATE_CALLBACK_LOC __FILE__ ":" STRINGIFY(__LINE__) +#define BOOT_STATE_CALLBACK_INIT_DEBUG .location = BOOT_STATE_CALLBACK_LOC, +#define INIT_BOOT_STATE_CALLBACK_DEBUG(bscb_) \ + bscb_->location = BOOT_STATE_CALLBACK_LOC; +#else +#define BOOT_STATE_CALLBACK_INIT_DEBUG +#define INIT_BOOT_STATE_CALLBACK_DEBUG(bscb_) +#endif + +#define BOOT_STATE_CALLBACK_INIT(func_, arg_) \ + { \ + .arg = arg_, \ + .callback = func_, \ + .next = NULL, \ + BOOT_STATE_CALLBACK_INIT_DEBUG \ + } + +#define BOOT_STATE_CALLBACK(name_, func_, arg_) \ + struct boot_state_callback name_ = BOOT_STATE_CALLBACK_INIT(func_, arg_) + +/* Initialize an allocated boot_state_callback. */ +#define INIT_BOOT_STATE_CALLBACK(bscb_, func_, arg_) \ + INIT_BOOT_STATE_CALLBACK_DEBUG(bscb_) \ + bscb_->callback = func_; \ + bscb_->arg = arg_ + +/* The following 2 functions schedule a callback to be called on entry/exit + * to a given state. Note that thare are no ordering guarantees between the + * individual callbacks on a given state. 0 is returned on success < 0 on + * error. */ +int boot_state_sched_on_entry(struct boot_state_callback *bscb, + boot_state_t state); +int boot_state_sched_on_exit(struct boot_state_callback *bscb, + boot_state_t state); + +/* Entry into the boot state machine. */ +void hardwaremain(int boot_complete); + +#endif /* BOOTSTATE_H */ |