blob: 34340a5770729cb0b4da3532c0d66a058f808a18 [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.
Eric Biederman8ca8d762003-04-22 19:02:15 +000014 */
15
16
17/*
Stefan Reinauerf8ee1802008-01-18 15:08:58 +000018 * C Bootstrap code for the coreboot
Eric Biederman8ca8d762003-04-22 19:02:15 +000019 */
20
Julius Werner85620db2013-11-13 18:22:15 -080021#include <arch/exception.h>
Aaron Durbin7e35efa2013-04-24 15:14:01 -050022#include <bootstate.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000023#include <console/console.h>
Duncan Lauriecb73a842013-06-10 10:41:04 -070024#include <console/post_codes.h>
Aaron Durbinb0d8f5e2015-04-06 16:12:58 -050025#include <cbmem.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000026#include <version.h>
Eric Biederman5899fd82003-04-24 06:25:08 +000027#include <device/device.h>
28#include <device/pci.h>
Eric Biederman9b4336c2003-07-19 04:28:22 +000029#include <delay.h>
Eric Biedermanb78c1972004-10-14 20:54:17 +000030#include <stdlib.h>
Stefan Reinauerde3206a2010-02-22 06:09:43 +000031#include <reset.h>
Stefan Reinauer7e9771c2009-04-22 08:17:38 +000032#include <boot/tables.h>
Aaron Durbin04654a22015-03-17 11:43:44 -050033#include <program_loading.h>
Ronald G. Minnich9764d4c2012-06-12 16:29:32 -070034#include <lib.h>
Stefan Reinauer08670622009-06-30 15:17:49 +000035#if CONFIG_HAVE_ACPI_RESUME
Rudolf Mareka572f832009-04-13 17:57:44 +000036#include <arch/acpi.h>
Stefan Reinauer3935b192009-04-14 06:38:15 +000037#endif
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -050038#include <timer.h>
Stefan Reinauerbf729ba2011-11-04 12:31:58 -070039#include <timestamp.h>
Aaron Durbin4409a5e2013-05-06 12:20:52 -050040#include <thread.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000041
Aaron Durbin7e35efa2013-04-24 15:14:01 -050042#if BOOT_STATE_DEBUG
43#define BS_DEBUG_LVL BIOS_DEBUG
44#else
45#define BS_DEBUG_LVL BIOS_NEVER
46#endif
Rudolf Mareka572f832009-04-13 17:57:44 +000047
Aaron Durbin7e35efa2013-04-24 15:14:01 -050048static boot_state_t bs_pre_device(void *arg);
49static boot_state_t bs_dev_init_chips(void *arg);
50static boot_state_t bs_dev_enumerate(void *arg);
51static boot_state_t bs_dev_resources(void *arg);
David Hendrickscca68592013-06-20 14:08:27 -070052static boot_state_t bs_dev_enable(void *arg);
Aaron Durbin7e35efa2013-04-24 15:14:01 -050053static boot_state_t bs_dev_init(void *arg);
54static boot_state_t bs_post_device(void *arg);
Aaron Durbin0a6c20a2013-04-24 22:33:08 -050055static boot_state_t bs_os_resume_check(void *arg);
Aaron Durbin7e35efa2013-04-24 15:14:01 -050056static boot_state_t bs_os_resume(void *arg);
57static boot_state_t bs_write_tables(void *arg);
58static boot_state_t bs_payload_load(void *arg);
59static boot_state_t bs_payload_boot(void *arg);
60
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -050061/*
62 * Typically a state will take 4 time samples:
63 * 1. Before state entry callbacks
64 * 2. After state entry callbacks / Before state function.
65 * 3. After state function / Before state exit callbacks.
66 * 4. After state exit callbacks.
67 */
68#define MAX_TIME_SAMPLES 4
69struct boot_state_times {
70 int num_samples;
71 struct mono_time samples[MAX_TIME_SAMPLES];
72};
73
Aaron Durbin0748d302013-05-06 10:50:19 -050074/* The prologue (BS_ON_ENTRY) and epilogue (BS_ON_EXIT) of a state can be
75 * blocked from transitioning to the next (state,seq) pair. When the blockers
76 * field is 0 a transition may occur. */
77struct boot_phase {
78 struct boot_state_callback *callbacks;
79 int blockers;
80};
81
Aaron Durbin7e35efa2013-04-24 15:14:01 -050082struct boot_state {
83 const char *name;
84 boot_state_t id;
Duncan Lauriecb73a842013-06-10 10:41:04 -070085 u8 post_code;
Aaron Durbin0748d302013-05-06 10:50:19 -050086 struct boot_phase phases[2];
Aaron Durbin7e35efa2013-04-24 15:14:01 -050087 boot_state_t (*run_state)(void *arg);
88 void *arg;
Aaron Durbin8fc41e12013-04-29 23:22:01 -050089 int complete : 1;
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -050090#if CONFIG_HAVE_MONOTONIC_TIMER
91 struct boot_state_times times;
92#endif
Aaron Durbin7e35efa2013-04-24 15:14:01 -050093};
94
Aaron Durbin15c671e2013-05-06 10:52:24 -050095#define BS_INIT(state_, run_func_) \
Aaron Durbin8fc41e12013-04-29 23:22:01 -050096 { \
97 .name = #state_, \
98 .id = state_, \
Duncan Lauriecb73a842013-06-10 10:41:04 -070099 .post_code = POST_ ## state_, \
Aaron Durbin0748d302013-05-06 10:50:19 -0500100 .phases = { { NULL, 0 }, { NULL, 0 } }, \
Aaron Durbin8fc41e12013-04-29 23:22:01 -0500101 .run_state = run_func_, \
102 .arg = NULL, \
103 .complete = 0, \
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500104 }
105#define BS_INIT_ENTRY(state_, run_func_) \
Aaron Durbin15c671e2013-05-06 10:52:24 -0500106 [state_] = BS_INIT(state_, run_func_)
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500107
108static struct boot_state boot_states[] = {
109 BS_INIT_ENTRY(BS_PRE_DEVICE, bs_pre_device),
110 BS_INIT_ENTRY(BS_DEV_INIT_CHIPS, bs_dev_init_chips),
111 BS_INIT_ENTRY(BS_DEV_ENUMERATE, bs_dev_enumerate),
112 BS_INIT_ENTRY(BS_DEV_RESOURCES, bs_dev_resources),
David Hendrickscca68592013-06-20 14:08:27 -0700113 BS_INIT_ENTRY(BS_DEV_ENABLE, bs_dev_enable),
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500114 BS_INIT_ENTRY(BS_DEV_INIT, bs_dev_init),
115 BS_INIT_ENTRY(BS_POST_DEVICE, bs_post_device),
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500116 BS_INIT_ENTRY(BS_OS_RESUME_CHECK, bs_os_resume_check),
Aaron Durbin15c671e2013-05-06 10:52:24 -0500117 BS_INIT_ENTRY(BS_OS_RESUME, bs_os_resume),
118 BS_INIT_ENTRY(BS_WRITE_TABLES, bs_write_tables),
119 BS_INIT_ENTRY(BS_PAYLOAD_LOAD, bs_payload_load),
120 BS_INIT_ENTRY(BS_PAYLOAD_BOOT, bs_payload_boot),
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500121};
122
123static boot_state_t bs_pre_device(void *arg)
124{
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500125 return BS_DEV_INIT_CHIPS;
126}
127
128static boot_state_t bs_dev_init_chips(void *arg)
129{
Kyösti Mälkkib766b1c2013-09-07 17:26:08 +0300130 timestamp_add_now(TS_DEVICE_ENUMERATE);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500131
132 /* Initialize chips early, they might disable unused devices. */
133 dev_initialize_chips();
134
135 return BS_DEV_ENUMERATE;
136}
137
138static boot_state_t bs_dev_enumerate(void *arg)
139{
140 /* Find the devices we don't have hard coded knowledge about. */
141 dev_enumerate();
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500142
143 return BS_DEV_RESOURCES;
144}
145
146static boot_state_t bs_dev_resources(void *arg)
147{
Kyösti Mälkkib766b1c2013-09-07 17:26:08 +0300148 timestamp_add_now(TS_DEVICE_CONFIGURE);
Duncan Lauriecb73a842013-06-10 10:41:04 -0700149
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500150 /* Now compute and assign the bus resources. */
151 dev_configure();
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500152
153 return BS_DEV_ENABLE;
154}
155
David Hendrickscca68592013-06-20 14:08:27 -0700156static boot_state_t bs_dev_enable(void *arg)
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500157{
Kyösti Mälkkib766b1c2013-09-07 17:26:08 +0300158 timestamp_add_now(TS_DEVICE_ENABLE);
Duncan Lauriecb73a842013-06-10 10:41:04 -0700159
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500160 /* Now actually enable devices on the bus */
161 dev_enable();
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500162
163 return BS_DEV_INIT;
164}
165
166static boot_state_t bs_dev_init(void *arg)
167{
Kyösti Mälkkib766b1c2013-09-07 17:26:08 +0300168 timestamp_add_now(TS_DEVICE_INITIALIZE);
Duncan Lauriecb73a842013-06-10 10:41:04 -0700169
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500170 /* And of course initialize devices on the bus */
171 dev_initialize();
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500172
173 return BS_POST_DEVICE;
174}
175
176static boot_state_t bs_post_device(void *arg)
177{
Marc Jones2a58ecd2013-10-29 17:32:00 -0600178 dev_finalize();
Kyösti Mälkkib766b1c2013-09-07 17:26:08 +0300179 timestamp_add_now(TS_DEVICE_DONE);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500180
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500181 return BS_OS_RESUME_CHECK;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500182}
183
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500184static boot_state_t bs_os_resume_check(void *arg)
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500185{
186#if CONFIG_HAVE_ACPI_RESUME
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500187 void *wake_vector;
188
189 wake_vector = acpi_find_wakeup_vector();
190
191 if (wake_vector != NULL) {
192 boot_states[BS_OS_RESUME].arg = wake_vector;
193 return BS_OS_RESUME;
194 }
Kyösti Mälkki7b14f082014-10-16 20:58:47 +0300195
196 acpi_prepare_resume_backup();
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500197#endif
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500198 timestamp_add_now(TS_CBMEM_POST);
199
200 return BS_WRITE_TABLES;
201}
202
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500203static boot_state_t bs_os_resume(void *wake_vector)
204{
205#if CONFIG_HAVE_ACPI_RESUME
206 acpi_resume(wake_vector);
207#endif
208 return BS_WRITE_TABLES;
209}
210
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500211static boot_state_t bs_write_tables(void *arg)
212{
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500213 timestamp_add_now(TS_WRITE_TABLES);
214
215 /* Now that we have collected all of our information
216 * write our configuration tables.
217 */
218 write_tables();
219
Marc Jones2a58ecd2013-10-29 17:32:00 -0600220 dev_finalize_chips();
221
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500222 return BS_PAYLOAD_LOAD;
223}
224
225static boot_state_t bs_payload_load(void *arg)
226{
Aaron Durbinebf2ed42015-03-20 10:20:15 -0500227 payload_load();
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500228
229 return BS_PAYLOAD_BOOT;
230}
231
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600232static boot_state_t bs_payload_boot(void *arg)
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500233{
Aaron Durbinebf2ed42015-03-20 10:20:15 -0500234 payload_run();
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500235
236 printk(BIOS_EMERG, "Boot failed");
237 /* Returning from this state will fail because the following signals
238 * return to a completed state. */
239 return BS_PAYLOAD_BOOT;
240}
241
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500242#if CONFIG_HAVE_MONOTONIC_TIMER
243static void bs_sample_time(struct boot_state *state)
244{
245 struct mono_time *mt;
246
247 mt = &state->times.samples[state->times.num_samples];
248 timer_monotonic_get(mt);
249 state->times.num_samples++;
250}
251
252static void bs_report_time(struct boot_state *state)
253{
Aaron Durbinad5a9092014-09-24 09:48:47 -0500254 long entry_time;
255 long run_time;
256 long exit_time;
257 struct mono_time *samples = &state->times.samples[0];
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500258
Aaron Durbinad5a9092014-09-24 09:48:47 -0500259 entry_time = mono_time_diff_microseconds(&samples[0], &samples[1]);
260 run_time = mono_time_diff_microseconds(&samples[1], &samples[2]);
261 exit_time = mono_time_diff_microseconds(&samples[2], &samples[3]);
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500262
263 printk(BIOS_DEBUG, "BS: %s times (us): entry %ld run %ld exit %ld\n",
Aaron Durbinad5a9092014-09-24 09:48:47 -0500264 state->name, entry_time, run_time, exit_time);
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500265}
266#else
267static inline void bs_sample_time(struct boot_state *state) {}
268static inline void bs_report_time(struct boot_state *state) {}
269#endif
270
Aaron Durbin8fc41e12013-04-29 23:22:01 -0500271#if CONFIG_TIMER_QUEUE
272static void bs_run_timers(int drain)
273{
274 /* Drain all timer callbacks until none are left, if directed.
275 * Otherwise run the timers only once. */
276 do {
277 if (!timers_run())
278 break;
279 } while (drain);
280}
281#else
282static void bs_run_timers(int drain) {}
283#endif
284
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500285static void bs_call_callbacks(struct boot_state *state,
286 boot_state_sequence_t seq)
287{
Aaron Durbin0748d302013-05-06 10:50:19 -0500288 struct boot_phase *phase = &state->phases[seq];
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500289
Aaron Durbin0748d302013-05-06 10:50:19 -0500290 while (1) {
291 if (phase->callbacks != NULL) {
292 struct boot_state_callback *bscb;
293
294 /* Remove the first callback. */
295 bscb = phase->callbacks;
296 phase->callbacks = bscb->next;
297 bscb->next = NULL;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500298
299#if BOOT_STATE_DEBUG
Aaron Durbin0748d302013-05-06 10:50:19 -0500300 printk(BS_DEBUG_LVL, "BS: callback (%p) @ %s.\n",
301 bscb, bscb->location);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500302#endif
Aaron Durbin0748d302013-05-06 10:50:19 -0500303 bscb->callback(bscb->arg);
304
305 continue;
306 }
307
308 /* All callbacks are complete and there are no blockers for
309 * this state. Therefore, this part of the state is complete. */
310 if (!phase->blockers)
311 break;
312
313 /* Something is blocking this state from transitioning. As
314 * there are no more callbacks a pending timer needs to be
315 * ran to unblock the state. */
316 bs_run_timers(0);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500317 }
318}
319
Aaron Durbin0748d302013-05-06 10:50:19 -0500320/* Keep track of the current state. */
321static struct state_tracker {
322 boot_state_t state_id;
323 boot_state_sequence_t seq;
324} current_phase = {
325 .state_id = BS_PRE_DEVICE,
326 .seq = BS_ON_ENTRY,
327};
328
329static void bs_walk_state_machine(void)
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500330{
331
332 while (1) {
333 struct boot_state *state;
Aaron Durbin0748d302013-05-06 10:50:19 -0500334 boot_state_t next_id;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500335
Aaron Durbin0748d302013-05-06 10:50:19 -0500336 state = &boot_states[current_phase.state_id];
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500337
338 if (state->complete) {
339 printk(BIOS_EMERG, "BS: %s state already executed.\n",
340 state->name);
341 break;
342 }
343
344 printk(BS_DEBUG_LVL, "BS: Entering %s state.\n", state->name);
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500345
Aaron Durbin15c671e2013-05-06 10:52:24 -0500346 bs_run_timers(0);
Aaron Durbin8fc41e12013-04-29 23:22:01 -0500347
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500348 bs_sample_time(state);
349
Aaron Durbin0748d302013-05-06 10:50:19 -0500350 bs_call_callbacks(state, current_phase.seq);
351 /* Update the current sequence so that any calls to block the
352 * current state from the run_state() function will place a
353 * block on the correct phase. */
354 current_phase.seq = BS_ON_EXIT;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500355
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500356 bs_sample_time(state);
357
Duncan Lauriecb73a842013-06-10 10:41:04 -0700358 post_code(state->post_code);
359
Aaron Durbin0748d302013-05-06 10:50:19 -0500360 next_id = state->run_state(state->arg);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500361
362 printk(BS_DEBUG_LVL, "BS: Exiting %s state.\n", state->name);
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500363
364 bs_sample_time(state);
365
Aaron Durbin0748d302013-05-06 10:50:19 -0500366 bs_call_callbacks(state, current_phase.seq);
367
368 /* Update the current phase with new state id and sequence. */
369 current_phase.state_id = next_id;
370 current_phase.seq = BS_ON_ENTRY;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500371
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500372 bs_sample_time(state);
373
374 bs_report_time(state);
375
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500376 state->complete = 1;
377 }
378}
379
380static int boot_state_sched_callback(struct boot_state *state,
381 struct boot_state_callback *bscb,
382 boot_state_sequence_t seq)
383{
384 if (state->complete) {
385 printk(BIOS_WARNING,
386 "Tried to schedule callback on completed state %s.\n",
387 state->name);
388
389 return -1;
390 }
391
Aaron Durbin0748d302013-05-06 10:50:19 -0500392 bscb->next = state->phases[seq].callbacks;
393 state->phases[seq].callbacks = bscb;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500394
395 return 0;
396}
397
398int boot_state_sched_on_entry(struct boot_state_callback *bscb,
399 boot_state_t state_id)
400{
401 struct boot_state *state = &boot_states[state_id];
402
403 return boot_state_sched_callback(state, bscb, BS_ON_ENTRY);
404}
405
406int boot_state_sched_on_exit(struct boot_state_callback *bscb,
407 boot_state_t state_id)
408{
409 struct boot_state *state = &boot_states[state_id];
410
411 return boot_state_sched_callback(state, bscb, BS_ON_EXIT);
412}
Maciej Pijankaea921852009-10-27 14:29:29 +0000413
Aaron Durbina4feddf2013-04-24 16:12:52 -0500414static void boot_state_schedule_static_entries(void)
415{
Aaron Durbin9ef9d852015-03-16 17:30:09 -0500416 extern struct boot_state_init_entry *_bs_init_begin[];
417 struct boot_state_init_entry **slot;
Aaron Durbina4feddf2013-04-24 16:12:52 -0500418
Aaron Durbin9ef9d852015-03-16 17:30:09 -0500419 for (slot = &_bs_init_begin[0]; *slot != NULL; slot++) {
420 struct boot_state_init_entry *cur = *slot;
Aaron Durbina4feddf2013-04-24 16:12:52 -0500421
Aaron Durbina4feddf2013-04-24 16:12:52 -0500422 if (cur->when == BS_ON_ENTRY)
423 boot_state_sched_on_entry(&cur->bscb, cur->state);
424 else
425 boot_state_sched_on_exit(&cur->bscb, cur->state);
Aaron Durbina4feddf2013-04-24 16:12:52 -0500426 }
427}
428
Stefan Reinauer6adef082013-05-09 16:30:06 -0700429void main(void)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000430{
Duncan Lauriea5181512015-06-04 08:42:48 -0700431 /* TODO: Understand why this is here and move to arch/platform code. */
432 /* For MMIO UART this needs to be called before any other printk. */
433 if (IS_ENABLED(CONFIG_ARCH_X86))
434 init_timer();
435
Aaron Durbinbe347972015-04-21 11:57:18 -0500436 /* console_init() MUST PRECEDE ALL printk()! Additionally, ensure
437 * it is the very first thing done in ramstage.*/
438 console_init();
439
440 post_code(POST_CONSOLE_READY);
441
Aaron Durbinb0d8f5e2015-04-06 16:12:58 -0500442 /*
443 * CBMEM needs to be recovered in the EARLY_CBMEM_INIT case because
444 * timestamps, APCI, etc rely on the cbmem infrastructure being
445 * around. Explicitly recover it.
446 */
447 if (IS_ENABLED(CONFIG_EARLY_CBMEM_INIT))
448 cbmem_initialize();
449
Kyösti Mälkkib766b1c2013-09-07 17:26:08 +0300450 /* Record current time, try to locate timestamps in CBMEM. */
Stefan Reinauer3a6550d2013-08-01 13:31:44 -0700451 timestamp_init(timestamp_get());
Kyösti Mälkkib766b1c2013-09-07 17:26:08 +0300452
453 timestamp_add_now(TS_START_RAMSTAGE);
Alexandru Gagniuc5005bb062011-04-11 20:17:22 +0000454 post_code(POST_ENTRY_RAMSTAGE);
Li-Ta Lo6a8745ae2004-05-13 20:39:07 +0000455
Kyösti Mälkkidb8693b2014-06-19 23:29:07 +0300456 /* Handoff sleep type from romstage. */
457#if CONFIG_HAVE_ACPI_RESUME
458 acpi_is_wakeup();
459#endif
460
Julius Werner85620db2013-11-13 18:22:15 -0800461 exception_init();
Aaron Durbin4409a5e2013-05-06 12:20:52 -0500462 threads_initialize();
463
Aaron Durbina4feddf2013-04-24 16:12:52 -0500464 /* Schedule the static boot state entries. */
465 boot_state_schedule_static_entries();
466
Aaron Durbin0748d302013-05-06 10:50:19 -0500467 bs_walk_state_machine();
468
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500469 die("Boot state machine failure.\n");
Eric Biederman8ca8d762003-04-22 19:02:15 +0000470}
471
Aaron Durbin0748d302013-05-06 10:50:19 -0500472
473int boot_state_block(boot_state_t state, boot_state_sequence_t seq)
474{
475 struct boot_phase *bp;
476
477 /* Blocking a previously ran state is not appropriate. */
478 if (current_phase.state_id > state ||
479 (current_phase.state_id == state && current_phase.seq > seq) ) {
480 printk(BIOS_WARNING,
481 "BS: Completed state (%d, %d) block attempted.\n",
482 state, seq);
483 return -1;
484 }
485
486 bp = &boot_states[state].phases[seq];
487 bp->blockers++;
488
489 return 0;
490}
491
492int boot_state_unblock(boot_state_t state, boot_state_sequence_t seq)
493{
494 struct boot_phase *bp;
495
496 /* Blocking a previously ran state is not appropriate. */
497 if (current_phase.state_id > state ||
498 (current_phase.state_id == state && current_phase.seq > seq) ) {
499 printk(BIOS_WARNING,
500 "BS: Completed state (%d, %d) unblock attempted.\n",
501 state, seq);
502 return -1;
503 }
504
505 bp = &boot_states[state].phases[seq];
506
507 if (bp->blockers == 0) {
508 printk(BIOS_WARNING,
509 "BS: Unblock attempted on non-blocked state (%d, %d).\n",
510 state, seq);
511 return -1;
512 }
513
514 bp->blockers--;
515
516 return 0;
517}
518
519void boot_state_current_block(void)
520{
521 boot_state_block(current_phase.state_id, current_phase.seq);
522}
523
524void boot_state_current_unblock(void)
525{
526 boot_state_unblock(current_phase.state_id, current_phase.seq);
527}