blob: 1091c00d346afe6513cab655d8f70510d2a4869b [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
Julius Werner85620db2013-11-13 18:22:15 -080025#include <arch/exception.h>
Aaron Durbin7e35efa2013-04-24 15:14:01 -050026#include <bootstate.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000027#include <console/console.h>
Duncan Lauriecb73a842013-06-10 10:41:04 -070028#include <console/post_codes.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000029#include <version.h>
Eric Biederman5899fd82003-04-24 06:25:08 +000030#include <device/device.h>
31#include <device/pci.h>
Eric Biederman9b4336c2003-07-19 04:28:22 +000032#include <delay.h>
Eric Biedermanb78c1972004-10-14 20:54:17 +000033#include <stdlib.h>
Stefan Reinauerde3206a2010-02-22 06:09:43 +000034#include <reset.h>
Stefan Reinauer7e9771c2009-04-22 08:17:38 +000035#include <boot/tables.h>
Aaron Durbin04654a22015-03-17 11:43:44 -050036#include <program_loading.h>
Ronald G. Minnich9764d4c2012-06-12 16:29:32 -070037#include <lib.h>
Stefan Reinauer08670622009-06-30 15:17:49 +000038#if CONFIG_HAVE_ACPI_RESUME
Rudolf Mareka572f832009-04-13 17:57:44 +000039#include <arch/acpi.h>
Stefan Reinauer3935b192009-04-14 06:38:15 +000040#endif
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -050041#include <timer.h>
Stefan Reinauerbf729ba2011-11-04 12:31:58 -070042#include <timestamp.h>
Aaron Durbin4409a5e2013-05-06 12:20:52 -050043#include <thread.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000044
Aaron Durbin7e35efa2013-04-24 15:14:01 -050045#if BOOT_STATE_DEBUG
46#define BS_DEBUG_LVL BIOS_DEBUG
47#else
48#define BS_DEBUG_LVL BIOS_NEVER
49#endif
Rudolf Mareka572f832009-04-13 17:57:44 +000050
Aaron Durbin7e35efa2013-04-24 15:14:01 -050051static boot_state_t bs_pre_device(void *arg);
52static boot_state_t bs_dev_init_chips(void *arg);
53static boot_state_t bs_dev_enumerate(void *arg);
54static boot_state_t bs_dev_resources(void *arg);
David Hendrickscca68592013-06-20 14:08:27 -070055static boot_state_t bs_dev_enable(void *arg);
Aaron Durbin7e35efa2013-04-24 15:14:01 -050056static boot_state_t bs_dev_init(void *arg);
57static boot_state_t bs_post_device(void *arg);
Aaron Durbin0a6c20a2013-04-24 22:33:08 -050058static boot_state_t bs_os_resume_check(void *arg);
Aaron Durbin7e35efa2013-04-24 15:14:01 -050059static boot_state_t bs_os_resume(void *arg);
60static boot_state_t bs_write_tables(void *arg);
61static boot_state_t bs_payload_load(void *arg);
62static boot_state_t bs_payload_boot(void *arg);
63
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -050064/*
65 * Typically a state will take 4 time samples:
66 * 1. Before state entry callbacks
67 * 2. After state entry callbacks / Before state function.
68 * 3. After state function / Before state exit callbacks.
69 * 4. After state exit callbacks.
70 */
71#define MAX_TIME_SAMPLES 4
72struct boot_state_times {
73 int num_samples;
74 struct mono_time samples[MAX_TIME_SAMPLES];
75};
76
Aaron Durbin0748d302013-05-06 10:50:19 -050077/* The prologue (BS_ON_ENTRY) and epilogue (BS_ON_EXIT) of a state can be
78 * blocked from transitioning to the next (state,seq) pair. When the blockers
79 * field is 0 a transition may occur. */
80struct boot_phase {
81 struct boot_state_callback *callbacks;
82 int blockers;
83};
84
Aaron Durbin7e35efa2013-04-24 15:14:01 -050085struct boot_state {
86 const char *name;
87 boot_state_t id;
Duncan Lauriecb73a842013-06-10 10:41:04 -070088 u8 post_code;
Aaron Durbin0748d302013-05-06 10:50:19 -050089 struct boot_phase phases[2];
Aaron Durbin7e35efa2013-04-24 15:14:01 -050090 boot_state_t (*run_state)(void *arg);
91 void *arg;
Aaron Durbin8fc41e12013-04-29 23:22:01 -050092 int complete : 1;
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -050093#if CONFIG_HAVE_MONOTONIC_TIMER
94 struct boot_state_times times;
95#endif
Aaron Durbin7e35efa2013-04-24 15:14:01 -050096};
97
Aaron Durbin15c671e2013-05-06 10:52:24 -050098#define BS_INIT(state_, run_func_) \
Aaron Durbin8fc41e12013-04-29 23:22:01 -050099 { \
100 .name = #state_, \
101 .id = state_, \
Duncan Lauriecb73a842013-06-10 10:41:04 -0700102 .post_code = POST_ ## state_, \
Aaron Durbin0748d302013-05-06 10:50:19 -0500103 .phases = { { NULL, 0 }, { NULL, 0 } }, \
Aaron Durbin8fc41e12013-04-29 23:22:01 -0500104 .run_state = run_func_, \
105 .arg = NULL, \
106 .complete = 0, \
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500107 }
108#define BS_INIT_ENTRY(state_, run_func_) \
Aaron Durbin15c671e2013-05-06 10:52:24 -0500109 [state_] = BS_INIT(state_, run_func_)
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500110
111static struct boot_state boot_states[] = {
112 BS_INIT_ENTRY(BS_PRE_DEVICE, bs_pre_device),
113 BS_INIT_ENTRY(BS_DEV_INIT_CHIPS, bs_dev_init_chips),
114 BS_INIT_ENTRY(BS_DEV_ENUMERATE, bs_dev_enumerate),
115 BS_INIT_ENTRY(BS_DEV_RESOURCES, bs_dev_resources),
David Hendrickscca68592013-06-20 14:08:27 -0700116 BS_INIT_ENTRY(BS_DEV_ENABLE, bs_dev_enable),
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500117 BS_INIT_ENTRY(BS_DEV_INIT, bs_dev_init),
118 BS_INIT_ENTRY(BS_POST_DEVICE, bs_post_device),
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500119 BS_INIT_ENTRY(BS_OS_RESUME_CHECK, bs_os_resume_check),
Aaron Durbin15c671e2013-05-06 10:52:24 -0500120 BS_INIT_ENTRY(BS_OS_RESUME, bs_os_resume),
121 BS_INIT_ENTRY(BS_WRITE_TABLES, bs_write_tables),
122 BS_INIT_ENTRY(BS_PAYLOAD_LOAD, bs_payload_load),
123 BS_INIT_ENTRY(BS_PAYLOAD_BOOT, bs_payload_boot),
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500124};
125
126static boot_state_t bs_pre_device(void *arg)
127{
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500128 return BS_DEV_INIT_CHIPS;
129}
130
131static boot_state_t bs_dev_init_chips(void *arg)
132{
Kyösti Mälkkib766b1c2013-09-07 17:26:08 +0300133 timestamp_add_now(TS_DEVICE_ENUMERATE);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500134
135 /* Initialize chips early, they might disable unused devices. */
136 dev_initialize_chips();
137
138 return BS_DEV_ENUMERATE;
139}
140
141static boot_state_t bs_dev_enumerate(void *arg)
142{
143 /* Find the devices we don't have hard coded knowledge about. */
144 dev_enumerate();
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500145
146 return BS_DEV_RESOURCES;
147}
148
149static boot_state_t bs_dev_resources(void *arg)
150{
Kyösti Mälkkib766b1c2013-09-07 17:26:08 +0300151 timestamp_add_now(TS_DEVICE_CONFIGURE);
Duncan Lauriecb73a842013-06-10 10:41:04 -0700152
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500153 /* Now compute and assign the bus resources. */
154 dev_configure();
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500155
156 return BS_DEV_ENABLE;
157}
158
David Hendrickscca68592013-06-20 14:08:27 -0700159static boot_state_t bs_dev_enable(void *arg)
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500160{
Kyösti Mälkkib766b1c2013-09-07 17:26:08 +0300161 timestamp_add_now(TS_DEVICE_ENABLE);
Duncan Lauriecb73a842013-06-10 10:41:04 -0700162
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500163 /* Now actually enable devices on the bus */
164 dev_enable();
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500165
166 return BS_DEV_INIT;
167}
168
169static boot_state_t bs_dev_init(void *arg)
170{
Kyösti Mälkkib766b1c2013-09-07 17:26:08 +0300171 timestamp_add_now(TS_DEVICE_INITIALIZE);
Duncan Lauriecb73a842013-06-10 10:41:04 -0700172
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500173 /* And of course initialize devices on the bus */
174 dev_initialize();
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500175
176 return BS_POST_DEVICE;
177}
178
179static boot_state_t bs_post_device(void *arg)
180{
Marc Jones2a58ecd2013-10-29 17:32:00 -0600181 dev_finalize();
Kyösti Mälkkib766b1c2013-09-07 17:26:08 +0300182 timestamp_add_now(TS_DEVICE_DONE);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500183
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500184 return BS_OS_RESUME_CHECK;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500185}
186
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500187static boot_state_t bs_os_resume_check(void *arg)
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500188{
189#if CONFIG_HAVE_ACPI_RESUME
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500190 void *wake_vector;
191
192 wake_vector = acpi_find_wakeup_vector();
193
194 if (wake_vector != NULL) {
195 boot_states[BS_OS_RESUME].arg = wake_vector;
196 return BS_OS_RESUME;
197 }
Kyösti Mälkki7b14f082014-10-16 20:58:47 +0300198
199 acpi_prepare_resume_backup();
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500200#endif
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500201 timestamp_add_now(TS_CBMEM_POST);
202
203 return BS_WRITE_TABLES;
204}
205
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500206static boot_state_t bs_os_resume(void *wake_vector)
207{
208#if CONFIG_HAVE_ACPI_RESUME
209 acpi_resume(wake_vector);
210#endif
211 return BS_WRITE_TABLES;
212}
213
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500214static boot_state_t bs_write_tables(void *arg)
215{
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500216 timestamp_add_now(TS_WRITE_TABLES);
217
218 /* Now that we have collected all of our information
219 * write our configuration tables.
220 */
221 write_tables();
222
Marc Jones2a58ecd2013-10-29 17:32:00 -0600223 dev_finalize_chips();
224
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500225 return BS_PAYLOAD_LOAD;
226}
227
228static boot_state_t bs_payload_load(void *arg)
229{
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600230 struct payload *payload;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500231
232 timestamp_add_now(TS_LOAD_PAYLOAD);
233
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600234 payload = payload_load();
235
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500236 if (! payload)
Aaron Durbin001de1a2013-04-24 22:59:45 -0500237 die("Could not load payload\n");
238
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500239 /* Pass the payload to the next state. */
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600240 boot_states[BS_PAYLOAD_BOOT].arg = payload;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500241
242 return BS_PAYLOAD_BOOT;
243}
244
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600245static boot_state_t bs_payload_boot(void *arg)
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500246{
Aaron Durbinbdf913a2014-02-24 14:56:34 -0600247 struct payload *payload = arg;
248
249 payload_run(payload);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500250
251 printk(BIOS_EMERG, "Boot failed");
252 /* Returning from this state will fail because the following signals
253 * return to a completed state. */
254 return BS_PAYLOAD_BOOT;
255}
256
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500257#if CONFIG_HAVE_MONOTONIC_TIMER
258static void bs_sample_time(struct boot_state *state)
259{
260 struct mono_time *mt;
261
262 mt = &state->times.samples[state->times.num_samples];
263 timer_monotonic_get(mt);
264 state->times.num_samples++;
265}
266
267static void bs_report_time(struct boot_state *state)
268{
Aaron Durbinad5a9092014-09-24 09:48:47 -0500269 long entry_time;
270 long run_time;
271 long exit_time;
272 struct mono_time *samples = &state->times.samples[0];
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500273
Aaron Durbinad5a9092014-09-24 09:48:47 -0500274 entry_time = mono_time_diff_microseconds(&samples[0], &samples[1]);
275 run_time = mono_time_diff_microseconds(&samples[1], &samples[2]);
276 exit_time = mono_time_diff_microseconds(&samples[2], &samples[3]);
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500277
278 printk(BIOS_DEBUG, "BS: %s times (us): entry %ld run %ld exit %ld\n",
Aaron Durbinad5a9092014-09-24 09:48:47 -0500279 state->name, entry_time, run_time, exit_time);
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500280}
281#else
282static inline void bs_sample_time(struct boot_state *state) {}
283static inline void bs_report_time(struct boot_state *state) {}
284#endif
285
Aaron Durbin8fc41e12013-04-29 23:22:01 -0500286#if CONFIG_TIMER_QUEUE
287static void bs_run_timers(int drain)
288{
289 /* Drain all timer callbacks until none are left, if directed.
290 * Otherwise run the timers only once. */
291 do {
292 if (!timers_run())
293 break;
294 } while (drain);
295}
296#else
297static void bs_run_timers(int drain) {}
298#endif
299
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500300static void bs_call_callbacks(struct boot_state *state,
301 boot_state_sequence_t seq)
302{
Aaron Durbin0748d302013-05-06 10:50:19 -0500303 struct boot_phase *phase = &state->phases[seq];
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500304
Aaron Durbin0748d302013-05-06 10:50:19 -0500305 while (1) {
306 if (phase->callbacks != NULL) {
307 struct boot_state_callback *bscb;
308
309 /* Remove the first callback. */
310 bscb = phase->callbacks;
311 phase->callbacks = bscb->next;
312 bscb->next = NULL;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500313
314#if BOOT_STATE_DEBUG
Aaron Durbin0748d302013-05-06 10:50:19 -0500315 printk(BS_DEBUG_LVL, "BS: callback (%p) @ %s.\n",
316 bscb, bscb->location);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500317#endif
Aaron Durbin0748d302013-05-06 10:50:19 -0500318 bscb->callback(bscb->arg);
319
320 continue;
321 }
322
323 /* All callbacks are complete and there are no blockers for
324 * this state. Therefore, this part of the state is complete. */
325 if (!phase->blockers)
326 break;
327
328 /* Something is blocking this state from transitioning. As
329 * there are no more callbacks a pending timer needs to be
330 * ran to unblock the state. */
331 bs_run_timers(0);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500332 }
333}
334
Aaron Durbin0748d302013-05-06 10:50:19 -0500335/* Keep track of the current state. */
336static struct state_tracker {
337 boot_state_t state_id;
338 boot_state_sequence_t seq;
339} current_phase = {
340 .state_id = BS_PRE_DEVICE,
341 .seq = BS_ON_ENTRY,
342};
343
344static void bs_walk_state_machine(void)
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500345{
346
347 while (1) {
348 struct boot_state *state;
Aaron Durbin0748d302013-05-06 10:50:19 -0500349 boot_state_t next_id;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500350
Aaron Durbin0748d302013-05-06 10:50:19 -0500351 state = &boot_states[current_phase.state_id];
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500352
353 if (state->complete) {
354 printk(BIOS_EMERG, "BS: %s state already executed.\n",
355 state->name);
356 break;
357 }
358
359 printk(BS_DEBUG_LVL, "BS: Entering %s state.\n", state->name);
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500360
Aaron Durbin15c671e2013-05-06 10:52:24 -0500361 bs_run_timers(0);
Aaron Durbin8fc41e12013-04-29 23:22:01 -0500362
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500363 bs_sample_time(state);
364
Aaron Durbin0748d302013-05-06 10:50:19 -0500365 bs_call_callbacks(state, current_phase.seq);
366 /* Update the current sequence so that any calls to block the
367 * current state from the run_state() function will place a
368 * block on the correct phase. */
369 current_phase.seq = BS_ON_EXIT;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500370
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500371 bs_sample_time(state);
372
Duncan Lauriecb73a842013-06-10 10:41:04 -0700373 post_code(state->post_code);
374
Aaron Durbin0748d302013-05-06 10:50:19 -0500375 next_id = state->run_state(state->arg);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500376
377 printk(BS_DEBUG_LVL, "BS: Exiting %s state.\n", state->name);
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500378
379 bs_sample_time(state);
380
Aaron Durbin0748d302013-05-06 10:50:19 -0500381 bs_call_callbacks(state, current_phase.seq);
382
383 /* Update the current phase with new state id and sequence. */
384 current_phase.state_id = next_id;
385 current_phase.seq = BS_ON_ENTRY;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500386
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500387 bs_sample_time(state);
388
389 bs_report_time(state);
390
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500391 state->complete = 1;
392 }
393}
394
395static int boot_state_sched_callback(struct boot_state *state,
396 struct boot_state_callback *bscb,
397 boot_state_sequence_t seq)
398{
399 if (state->complete) {
400 printk(BIOS_WARNING,
401 "Tried to schedule callback on completed state %s.\n",
402 state->name);
403
404 return -1;
405 }
406
Aaron Durbin0748d302013-05-06 10:50:19 -0500407 bscb->next = state->phases[seq].callbacks;
408 state->phases[seq].callbacks = bscb;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500409
410 return 0;
411}
412
413int boot_state_sched_on_entry(struct boot_state_callback *bscb,
414 boot_state_t state_id)
415{
416 struct boot_state *state = &boot_states[state_id];
417
418 return boot_state_sched_callback(state, bscb, BS_ON_ENTRY);
419}
420
421int boot_state_sched_on_exit(struct boot_state_callback *bscb,
422 boot_state_t state_id)
423{
424 struct boot_state *state = &boot_states[state_id];
425
426 return boot_state_sched_callback(state, bscb, BS_ON_EXIT);
427}
Maciej Pijankaea921852009-10-27 14:29:29 +0000428
Aaron Durbina4feddf2013-04-24 16:12:52 -0500429static void boot_state_schedule_static_entries(void)
430{
Aaron Durbin9ef9d852015-03-16 17:30:09 -0500431 extern struct boot_state_init_entry *_bs_init_begin[];
432 struct boot_state_init_entry **slot;
Aaron Durbina4feddf2013-04-24 16:12:52 -0500433
Aaron Durbin9ef9d852015-03-16 17:30:09 -0500434 for (slot = &_bs_init_begin[0]; *slot != NULL; slot++) {
435 struct boot_state_init_entry *cur = *slot;
Aaron Durbina4feddf2013-04-24 16:12:52 -0500436
Aaron Durbina4feddf2013-04-24 16:12:52 -0500437 if (cur->when == BS_ON_ENTRY)
438 boot_state_sched_on_entry(&cur->bscb, cur->state);
439 else
440 boot_state_sched_on_exit(&cur->bscb, cur->state);
Aaron Durbina4feddf2013-04-24 16:12:52 -0500441 }
442}
443
Stefan Reinauer6adef082013-05-09 16:30:06 -0700444void main(void)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000445{
Kyösti Mälkkib766b1c2013-09-07 17:26:08 +0300446 /* Record current time, try to locate timestamps in CBMEM. */
Stefan Reinauer3a6550d2013-08-01 13:31:44 -0700447 timestamp_init(timestamp_get());
Kyösti Mälkkib766b1c2013-09-07 17:26:08 +0300448
449 timestamp_add_now(TS_START_RAMSTAGE);
Alexandru Gagniuc5005bb062011-04-11 20:17:22 +0000450 post_code(POST_ENTRY_RAMSTAGE);
Li-Ta Lo6a8745ae2004-05-13 20:39:07 +0000451
Stefan Reinauer3b314022009-10-26 17:04:28 +0000452 /* console_init() MUST PRECEDE ALL printk()! */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000453 console_init();
Stefan Reinauer14e22772010-04-27 06:56:47 +0000454
Alexandru Gagniuc5005bb062011-04-11 20:17:22 +0000455 post_code(POST_CONSOLE_READY);
arch import user (historical)54d6b082005-07-06 17:17:41 +0000456
Kyösti Mälkkidb8693b2014-06-19 23:29:07 +0300457 /* Handoff sleep type from romstage. */
458#if CONFIG_HAVE_ACPI_RESUME
459 acpi_is_wakeup();
460#endif
461
Julius Werner85620db2013-11-13 18:22:15 -0800462 exception_init();
Aaron Durbin4409a5e2013-05-06 12:20:52 -0500463 threads_initialize();
464
Aaron Durbina4feddf2013-04-24 16:12:52 -0500465 /* Schedule the static boot state entries. */
466 boot_state_schedule_static_entries();
467
Eric Biederman7003ba42004-10-16 06:20:29 +0000468 /* FIXME: Is there a better way to handle this? */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000469 init_timer();
Eric Biederman8ca8d762003-04-22 19:02:15 +0000470
Aaron Durbin0748d302013-05-06 10:50:19 -0500471 bs_walk_state_machine();
472
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500473 die("Boot state machine failure.\n");
Eric Biederman8ca8d762003-04-22 19:02:15 +0000474}
475
Aaron Durbin0748d302013-05-06 10:50:19 -0500476
477int boot_state_block(boot_state_t state, boot_state_sequence_t seq)
478{
479 struct boot_phase *bp;
480
481 /* Blocking a previously ran state is not appropriate. */
482 if (current_phase.state_id > state ||
483 (current_phase.state_id == state && current_phase.seq > seq) ) {
484 printk(BIOS_WARNING,
485 "BS: Completed state (%d, %d) block attempted.\n",
486 state, seq);
487 return -1;
488 }
489
490 bp = &boot_states[state].phases[seq];
491 bp->blockers++;
492
493 return 0;
494}
495
496int boot_state_unblock(boot_state_t state, boot_state_sequence_t seq)
497{
498 struct boot_phase *bp;
499
500 /* Blocking a previously ran state is not appropriate. */
501 if (current_phase.state_id > state ||
502 (current_phase.state_id == state && current_phase.seq > seq) ) {
503 printk(BIOS_WARNING,
504 "BS: Completed state (%d, %d) unblock attempted.\n",
505 state, seq);
506 return -1;
507 }
508
509 bp = &boot_states[state].phases[seq];
510
511 if (bp->blockers == 0) {
512 printk(BIOS_WARNING,
513 "BS: Unblock attempted on non-blocked state (%d, %d).\n",
514 state, seq);
515 return -1;
516 }
517
518 bp->blockers--;
519
520 return 0;
521}
522
523void boot_state_current_block(void)
524{
525 boot_state_block(current_phase.state_id, current_phase.seq);
526}
527
528void boot_state_current_unblock(void)
529{
530 boot_state_unblock(current_phase.state_id, current_phase.seq);
531}