blob: fed153be48a3190c932b8d2ce81c5cd93b7d5498 [file] [log] [blame]
Eric Biederman8ca8d762003-04-22 19:02:15 +00001/*
Aaron Durbin7e35efa2013-04-24 15:14:01 -05002 * 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,
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 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Eric Biederman8ca8d762003-04-22 19:02:15 +000018 */
19
20
21/*
Stefan Reinauerf8ee1802008-01-18 15:08:58 +000022 * C Bootstrap code for the coreboot
Eric Biederman8ca8d762003-04-22 19:02:15 +000023 */
24
Aaron Durbin7e35efa2013-04-24 15:14:01 -050025#include <bootstate.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000026#include <console/console.h>
Duncan Lauriecb73a842013-06-10 10:41:04 -070027#include <console/post_codes.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000028#include <version.h>
Eric Biederman5899fd82003-04-24 06:25:08 +000029#include <device/device.h>
30#include <device/pci.h>
Eric Biederman9b4336c2003-07-19 04:28:22 +000031#include <delay.h>
Eric Biedermanb78c1972004-10-14 20:54:17 +000032#include <stdlib.h>
Stefan Reinauerde3206a2010-02-22 06:09:43 +000033#include <reset.h>
Stefan Reinauer7e9771c2009-04-22 08:17:38 +000034#include <boot/tables.h>
Peter Stuge483b7bb2009-04-14 07:40:01 +000035#include <cbfs.h>
Ronald G. Minnich9764d4c2012-06-12 16:29:32 -070036#include <lib.h>
Stefan Reinauer08670622009-06-30 15:17:49 +000037#if CONFIG_HAVE_ACPI_RESUME
Rudolf Mareka572f832009-04-13 17:57:44 +000038#include <arch/acpi.h>
Stefan Reinauer3935b192009-04-14 06:38:15 +000039#endif
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -050040#include <timer.h>
Stefan Reinauerbf729ba2011-11-04 12:31:58 -070041#include <timestamp.h>
Aaron Durbin4409a5e2013-05-06 12:20:52 -050042#include <thread.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000043
Aaron Durbin7e35efa2013-04-24 15:14:01 -050044#if BOOT_STATE_DEBUG
45#define BS_DEBUG_LVL BIOS_DEBUG
46#else
47#define BS_DEBUG_LVL BIOS_NEVER
48#endif
Rudolf Mareka572f832009-04-13 17:57:44 +000049
Aaron Durbin7e35efa2013-04-24 15:14:01 -050050static boot_state_t bs_pre_device(void *arg);
51static boot_state_t bs_dev_init_chips(void *arg);
52static boot_state_t bs_dev_enumerate(void *arg);
53static boot_state_t bs_dev_resources(void *arg);
David Hendrickscca68592013-06-20 14:08:27 -070054static boot_state_t bs_dev_enable(void *arg);
Aaron Durbin7e35efa2013-04-24 15:14:01 -050055static boot_state_t bs_dev_init(void *arg);
56static boot_state_t bs_post_device(void *arg);
Aaron Durbin0a6c20a2013-04-24 22:33:08 -050057static boot_state_t bs_os_resume_check(void *arg);
Aaron Durbin7e35efa2013-04-24 15:14:01 -050058static boot_state_t bs_os_resume(void *arg);
59static boot_state_t bs_write_tables(void *arg);
60static boot_state_t bs_payload_load(void *arg);
61static boot_state_t bs_payload_boot(void *arg);
62
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -050063/*
64 * Typically a state will take 4 time samples:
65 * 1. Before state entry callbacks
66 * 2. After state entry callbacks / Before state function.
67 * 3. After state function / Before state exit callbacks.
68 * 4. After state exit callbacks.
69 */
70#define MAX_TIME_SAMPLES 4
71struct boot_state_times {
72 int num_samples;
73 struct mono_time samples[MAX_TIME_SAMPLES];
74};
75
Aaron Durbin0748d302013-05-06 10:50:19 -050076/* The prologue (BS_ON_ENTRY) and epilogue (BS_ON_EXIT) of a state can be
77 * blocked from transitioning to the next (state,seq) pair. When the blockers
78 * field is 0 a transition may occur. */
79struct boot_phase {
80 struct boot_state_callback *callbacks;
81 int blockers;
82};
83
Aaron Durbin7e35efa2013-04-24 15:14:01 -050084struct boot_state {
85 const char *name;
86 boot_state_t id;
Duncan Lauriecb73a842013-06-10 10:41:04 -070087 u8 post_code;
Aaron Durbin0748d302013-05-06 10:50:19 -050088 struct boot_phase phases[2];
Aaron Durbin7e35efa2013-04-24 15:14:01 -050089 boot_state_t (*run_state)(void *arg);
90 void *arg;
Aaron Durbin8fc41e12013-04-29 23:22:01 -050091 int complete : 1;
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -050092#if CONFIG_HAVE_MONOTONIC_TIMER
93 struct boot_state_times times;
94#endif
Aaron Durbin7e35efa2013-04-24 15:14:01 -050095};
96
Aaron Durbin15c671e2013-05-06 10:52:24 -050097#define BS_INIT(state_, run_func_) \
Aaron Durbin8fc41e12013-04-29 23:22:01 -050098 { \
99 .name = #state_, \
100 .id = state_, \
Duncan Lauriecb73a842013-06-10 10:41:04 -0700101 .post_code = POST_ ## state_, \
Aaron Durbin0748d302013-05-06 10:50:19 -0500102 .phases = { { NULL, 0 }, { NULL, 0 } }, \
Aaron Durbin8fc41e12013-04-29 23:22:01 -0500103 .run_state = run_func_, \
104 .arg = NULL, \
105 .complete = 0, \
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500106 }
107#define BS_INIT_ENTRY(state_, run_func_) \
Aaron Durbin15c671e2013-05-06 10:52:24 -0500108 [state_] = BS_INIT(state_, run_func_)
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500109
110static struct boot_state boot_states[] = {
111 BS_INIT_ENTRY(BS_PRE_DEVICE, bs_pre_device),
112 BS_INIT_ENTRY(BS_DEV_INIT_CHIPS, bs_dev_init_chips),
113 BS_INIT_ENTRY(BS_DEV_ENUMERATE, bs_dev_enumerate),
114 BS_INIT_ENTRY(BS_DEV_RESOURCES, bs_dev_resources),
David Hendrickscca68592013-06-20 14:08:27 -0700115 BS_INIT_ENTRY(BS_DEV_ENABLE, bs_dev_enable),
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500116 BS_INIT_ENTRY(BS_DEV_INIT, bs_dev_init),
117 BS_INIT_ENTRY(BS_POST_DEVICE, bs_post_device),
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500118 BS_INIT_ENTRY(BS_OS_RESUME_CHECK, bs_os_resume_check),
Aaron Durbin15c671e2013-05-06 10:52:24 -0500119 BS_INIT_ENTRY(BS_OS_RESUME, bs_os_resume),
120 BS_INIT_ENTRY(BS_WRITE_TABLES, bs_write_tables),
121 BS_INIT_ENTRY(BS_PAYLOAD_LOAD, bs_payload_load),
122 BS_INIT_ENTRY(BS_PAYLOAD_BOOT, bs_payload_boot),
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500123};
124
125static boot_state_t bs_pre_device(void *arg)
126{
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500127 return BS_DEV_INIT_CHIPS;
128}
129
130static boot_state_t bs_dev_init_chips(void *arg)
131{
Kyösti Mälkkib766b1c2013-09-07 17:26:08 +0300132 timestamp_add_now(TS_DEVICE_ENUMERATE);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500133
134 /* Initialize chips early, they might disable unused devices. */
135 dev_initialize_chips();
136
137 return BS_DEV_ENUMERATE;
138}
139
140static boot_state_t bs_dev_enumerate(void *arg)
141{
142 /* Find the devices we don't have hard coded knowledge about. */
143 dev_enumerate();
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500144
145 return BS_DEV_RESOURCES;
146}
147
148static boot_state_t bs_dev_resources(void *arg)
149{
Kyösti Mälkkib766b1c2013-09-07 17:26:08 +0300150 timestamp_add_now(TS_DEVICE_CONFIGURE);
Duncan Lauriecb73a842013-06-10 10:41:04 -0700151
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500152 /* Now compute and assign the bus resources. */
153 dev_configure();
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500154
155 return BS_DEV_ENABLE;
156}
157
David Hendrickscca68592013-06-20 14:08:27 -0700158static boot_state_t bs_dev_enable(void *arg)
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500159{
Kyösti Mälkkib766b1c2013-09-07 17:26:08 +0300160 timestamp_add_now(TS_DEVICE_ENABLE);
Duncan Lauriecb73a842013-06-10 10:41:04 -0700161
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500162 /* Now actually enable devices on the bus */
163 dev_enable();
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500164
165 return BS_DEV_INIT;
166}
167
168static boot_state_t bs_dev_init(void *arg)
169{
Kyösti Mälkkib766b1c2013-09-07 17:26:08 +0300170 timestamp_add_now(TS_DEVICE_INITIALIZE);
Duncan Lauriecb73a842013-06-10 10:41:04 -0700171
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500172 /* And of course initialize devices on the bus */
173 dev_initialize();
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500174
175 return BS_POST_DEVICE;
176}
177
178static boot_state_t bs_post_device(void *arg)
179{
Marc Jones2a58ecd2013-10-29 17:32:00 -0600180 dev_finalize();
Kyösti Mälkkib766b1c2013-09-07 17:26:08 +0300181 timestamp_add_now(TS_DEVICE_DONE);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500182
Kyösti Mälkkicbf5bdf2013-09-10 00:07:21 +0300183 timestamp_reinit();
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500184
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500185 return BS_OS_RESUME_CHECK;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500186}
187
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500188static boot_state_t bs_os_resume_check(void *arg)
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500189{
190#if CONFIG_HAVE_ACPI_RESUME
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500191 void *wake_vector;
192
193 wake_vector = acpi_find_wakeup_vector();
194
195 if (wake_vector != NULL) {
196 boot_states[BS_OS_RESUME].arg = wake_vector;
197 return BS_OS_RESUME;
198 }
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500199#endif
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500200 timestamp_add_now(TS_CBMEM_POST);
201
202 return BS_WRITE_TABLES;
203}
204
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500205static boot_state_t bs_os_resume(void *wake_vector)
206{
207#if CONFIG_HAVE_ACPI_RESUME
208 acpi_resume(wake_vector);
209#endif
210 return BS_WRITE_TABLES;
211}
212
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500213static boot_state_t bs_write_tables(void *arg)
214{
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500215 timestamp_add_now(TS_WRITE_TABLES);
216
217 /* Now that we have collected all of our information
218 * write our configuration tables.
219 */
220 write_tables();
221
Marc Jones2a58ecd2013-10-29 17:32:00 -0600222 dev_finalize_chips();
223
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500224 return BS_PAYLOAD_LOAD;
225}
226
227static boot_state_t bs_payload_load(void *arg)
228{
229 void *payload;
Aaron Durbin001de1a2013-04-24 22:59:45 -0500230 void *entry;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500231
232 timestamp_add_now(TS_LOAD_PAYLOAD);
233
234 payload = cbfs_load_payload(CBFS_DEFAULT_MEDIA,
235 CONFIG_CBFS_PREFIX "/payload");
236 if (! payload)
237 die("Could not find a payload\n");
238
Aaron Durbin001de1a2013-04-24 22:59:45 -0500239 entry = selfload(get_lb_mem(), payload);
240
241 if (! entry)
242 die("Could not load payload\n");
243
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500244 /* Pass the payload to the next state. */
Aaron Durbin001de1a2013-04-24 22:59:45 -0500245 boot_states[BS_PAYLOAD_BOOT].arg = entry;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500246
247 return BS_PAYLOAD_BOOT;
248}
249
Aaron Durbin001de1a2013-04-24 22:59:45 -0500250static boot_state_t bs_payload_boot(void *entry)
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500251{
Aaron Durbin001de1a2013-04-24 22:59:45 -0500252 selfboot(entry);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500253
254 printk(BIOS_EMERG, "Boot failed");
255 /* Returning from this state will fail because the following signals
256 * return to a completed state. */
257 return BS_PAYLOAD_BOOT;
258}
259
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500260#if CONFIG_HAVE_MONOTONIC_TIMER
261static void bs_sample_time(struct boot_state *state)
262{
263 struct mono_time *mt;
264
265 mt = &state->times.samples[state->times.num_samples];
266 timer_monotonic_get(mt);
267 state->times.num_samples++;
268}
269
270static void bs_report_time(struct boot_state *state)
271{
272 struct rela_time entry_time;
273 struct rela_time run_time;
274 struct rela_time exit_time;
275 struct boot_state_times *times;
276
277 times = &state->times;
278 entry_time = mono_time_diff(&times->samples[0], &times->samples[1]);
279 run_time = mono_time_diff(&times->samples[1], &times->samples[2]);
280 exit_time = mono_time_diff(&times->samples[2], &times->samples[3]);
281
282 printk(BIOS_DEBUG, "BS: %s times (us): entry %ld run %ld exit %ld\n",
283 state->name,
284 rela_time_in_microseconds(&entry_time),
285 rela_time_in_microseconds(&run_time),
286 rela_time_in_microseconds(&exit_time));
287}
288#else
289static inline void bs_sample_time(struct boot_state *state) {}
290static inline void bs_report_time(struct boot_state *state) {}
291#endif
292
Aaron Durbin8fc41e12013-04-29 23:22:01 -0500293#if CONFIG_TIMER_QUEUE
294static void bs_run_timers(int drain)
295{
296 /* Drain all timer callbacks until none are left, if directed.
297 * Otherwise run the timers only once. */
298 do {
299 if (!timers_run())
300 break;
301 } while (drain);
302}
303#else
304static void bs_run_timers(int drain) {}
305#endif
306
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500307static void bs_call_callbacks(struct boot_state *state,
308 boot_state_sequence_t seq)
309{
Aaron Durbin0748d302013-05-06 10:50:19 -0500310 struct boot_phase *phase = &state->phases[seq];
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500311
Aaron Durbin0748d302013-05-06 10:50:19 -0500312 while (1) {
313 if (phase->callbacks != NULL) {
314 struct boot_state_callback *bscb;
315
316 /* Remove the first callback. */
317 bscb = phase->callbacks;
318 phase->callbacks = bscb->next;
319 bscb->next = NULL;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500320
321#if BOOT_STATE_DEBUG
Aaron Durbin0748d302013-05-06 10:50:19 -0500322 printk(BS_DEBUG_LVL, "BS: callback (%p) @ %s.\n",
323 bscb, bscb->location);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500324#endif
Aaron Durbin0748d302013-05-06 10:50:19 -0500325 bscb->callback(bscb->arg);
326
327 continue;
328 }
329
330 /* All callbacks are complete and there are no blockers for
331 * this state. Therefore, this part of the state is complete. */
332 if (!phase->blockers)
333 break;
334
335 /* Something is blocking this state from transitioning. As
336 * there are no more callbacks a pending timer needs to be
337 * ran to unblock the state. */
338 bs_run_timers(0);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500339 }
340}
341
Aaron Durbin0748d302013-05-06 10:50:19 -0500342/* Keep track of the current state. */
343static struct state_tracker {
344 boot_state_t state_id;
345 boot_state_sequence_t seq;
346} current_phase = {
347 .state_id = BS_PRE_DEVICE,
348 .seq = BS_ON_ENTRY,
349};
350
351static void bs_walk_state_machine(void)
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500352{
353
354 while (1) {
355 struct boot_state *state;
Aaron Durbin0748d302013-05-06 10:50:19 -0500356 boot_state_t next_id;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500357
Aaron Durbin0748d302013-05-06 10:50:19 -0500358 state = &boot_states[current_phase.state_id];
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500359
360 if (state->complete) {
361 printk(BIOS_EMERG, "BS: %s state already executed.\n",
362 state->name);
363 break;
364 }
365
366 printk(BS_DEBUG_LVL, "BS: Entering %s state.\n", state->name);
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500367
Aaron Durbin15c671e2013-05-06 10:52:24 -0500368 bs_run_timers(0);
Aaron Durbin8fc41e12013-04-29 23:22:01 -0500369
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500370 bs_sample_time(state);
371
Aaron Durbin0748d302013-05-06 10:50:19 -0500372 bs_call_callbacks(state, current_phase.seq);
373 /* Update the current sequence so that any calls to block the
374 * current state from the run_state() function will place a
375 * block on the correct phase. */
376 current_phase.seq = BS_ON_EXIT;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500377
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500378 bs_sample_time(state);
379
Duncan Lauriecb73a842013-06-10 10:41:04 -0700380 post_code(state->post_code);
381
Aaron Durbin0748d302013-05-06 10:50:19 -0500382 next_id = state->run_state(state->arg);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500383
384 printk(BS_DEBUG_LVL, "BS: Exiting %s state.\n", state->name);
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500385
386 bs_sample_time(state);
387
Aaron Durbin0748d302013-05-06 10:50:19 -0500388 bs_call_callbacks(state, current_phase.seq);
389
390 /* Update the current phase with new state id and sequence. */
391 current_phase.state_id = next_id;
392 current_phase.seq = BS_ON_ENTRY;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500393
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500394 bs_sample_time(state);
395
396 bs_report_time(state);
397
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500398 state->complete = 1;
399 }
400}
401
402static int boot_state_sched_callback(struct boot_state *state,
403 struct boot_state_callback *bscb,
404 boot_state_sequence_t seq)
405{
406 if (state->complete) {
407 printk(BIOS_WARNING,
408 "Tried to schedule callback on completed state %s.\n",
409 state->name);
410
411 return -1;
412 }
413
Aaron Durbin0748d302013-05-06 10:50:19 -0500414 bscb->next = state->phases[seq].callbacks;
415 state->phases[seq].callbacks = bscb;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500416
417 return 0;
418}
419
420int boot_state_sched_on_entry(struct boot_state_callback *bscb,
421 boot_state_t state_id)
422{
423 struct boot_state *state = &boot_states[state_id];
424
425 return boot_state_sched_callback(state, bscb, BS_ON_ENTRY);
426}
427
428int boot_state_sched_on_exit(struct boot_state_callback *bscb,
429 boot_state_t state_id)
430{
431 struct boot_state *state = &boot_states[state_id];
432
433 return boot_state_sched_callback(state, bscb, BS_ON_EXIT);
434}
Maciej Pijankaea921852009-10-27 14:29:29 +0000435
Aaron Durbina4feddf2013-04-24 16:12:52 -0500436static void boot_state_schedule_static_entries(void)
437{
438 extern struct boot_state_init_entry _bs_init_begin;
439 extern struct boot_state_init_entry _bs_init_end;
440 struct boot_state_init_entry *cur;
441
442 cur = &_bs_init_begin;
443
444 while (cur != &_bs_init_end) {
445 if (cur->when == BS_ON_ENTRY)
446 boot_state_sched_on_entry(&cur->bscb, cur->state);
447 else
448 boot_state_sched_on_exit(&cur->bscb, cur->state);
449 cur++;
450 }
451}
452
Stefan Reinauer6adef082013-05-09 16:30:06 -0700453void main(void)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000454{
Kyösti Mälkkib766b1c2013-09-07 17:26:08 +0300455 /* Record current time, try to locate timestamps in CBMEM. */
456 timestamp_init(rdtsc());
457
458 timestamp_add_now(TS_START_RAMSTAGE);
Alexandru Gagniuc5005bb062011-04-11 20:17:22 +0000459 post_code(POST_ENTRY_RAMSTAGE);
Li-Ta Lo6a8745ae2004-05-13 20:39:07 +0000460
Stefan Reinauer3b314022009-10-26 17:04:28 +0000461 /* console_init() MUST PRECEDE ALL printk()! */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000462 console_init();
Stefan Reinauer14e22772010-04-27 06:56:47 +0000463
Alexandru Gagniuc5005bb062011-04-11 20:17:22 +0000464 post_code(POST_CONSOLE_READY);
arch import user (historical)54d6b082005-07-06 17:17:41 +0000465
Stefan Reinauer2a3c1062013-05-06 16:49:56 -0700466 printk(BIOS_NOTICE, "coreboot-%s%s %s booting...\n",
467 coreboot_version, coreboot_extra_version, coreboot_build);
Eric Biederman8ca8d762003-04-22 19:02:15 +0000468
Alexandru Gagniuc5005bb062011-04-11 20:17:22 +0000469 post_code(POST_CONSOLE_BOOT_MSG);
Eric Biederman8ca8d762003-04-22 19:02:15 +0000470
Aaron Durbin4409a5e2013-05-06 12:20:52 -0500471 threads_initialize();
472
Aaron Durbina4feddf2013-04-24 16:12:52 -0500473 /* Schedule the static boot state entries. */
474 boot_state_schedule_static_entries();
475
Eric Biederman7003ba42004-10-16 06:20:29 +0000476 /* FIXME: Is there a better way to handle this? */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000477 init_timer();
Eric Biederman8ca8d762003-04-22 19:02:15 +0000478
Aaron Durbin0748d302013-05-06 10:50:19 -0500479 bs_walk_state_machine();
480
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500481 die("Boot state machine failure.\n");
Eric Biederman8ca8d762003-04-22 19:02:15 +0000482}
483
Aaron Durbin0748d302013-05-06 10:50:19 -0500484
485int boot_state_block(boot_state_t state, boot_state_sequence_t seq)
486{
487 struct boot_phase *bp;
488
489 /* Blocking a previously ran state is not appropriate. */
490 if (current_phase.state_id > state ||
491 (current_phase.state_id == state && current_phase.seq > seq) ) {
492 printk(BIOS_WARNING,
493 "BS: Completed state (%d, %d) block attempted.\n",
494 state, seq);
495 return -1;
496 }
497
498 bp = &boot_states[state].phases[seq];
499 bp->blockers++;
500
501 return 0;
502}
503
504int boot_state_unblock(boot_state_t state, boot_state_sequence_t seq)
505{
506 struct boot_phase *bp;
507
508 /* Blocking a previously ran state is not appropriate. */
509 if (current_phase.state_id > state ||
510 (current_phase.state_id == state && current_phase.seq > seq) ) {
511 printk(BIOS_WARNING,
512 "BS: Completed state (%d, %d) unblock attempted.\n",
513 state, seq);
514 return -1;
515 }
516
517 bp = &boot_states[state].phases[seq];
518
519 if (bp->blockers == 0) {
520 printk(BIOS_WARNING,
521 "BS: Unblock attempted on non-blocked state (%d, %d).\n",
522 state, seq);
523 return -1;
524 }
525
526 bp->blockers--;
527
528 return 0;
529}
530
531void boot_state_current_block(void)
532{
533 boot_state_block(current_phase.state_id, current_phase.seq);
534}
535
536void boot_state_current_unblock(void)
537{
538 boot_state_unblock(current_phase.state_id, current_phase.seq);
539}