blob: dd9719642e485307f215b4f0b8e3f144de4cadf4 [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>
Eric Biederman8ca8d762003-04-22 19:02:15 +000027#include <version.h>
Eric Biederman5899fd82003-04-24 06:25:08 +000028#include <device/device.h>
29#include <device/pci.h>
Eric Biederman9b4336c2003-07-19 04:28:22 +000030#include <delay.h>
Eric Biedermanb78c1972004-10-14 20:54:17 +000031#include <stdlib.h>
Stefan Reinauerde3206a2010-02-22 06:09:43 +000032#include <reset.h>
Stefan Reinauer7e9771c2009-04-22 08:17:38 +000033#include <boot/tables.h>
Peter Stuge483b7bb2009-04-14 07:40:01 +000034#include <cbfs.h>
Ronald G. Minnich9764d4c2012-06-12 16:29:32 -070035#include <lib.h>
Stefan Reinauer08670622009-06-30 15:17:49 +000036#if CONFIG_HAVE_ACPI_RESUME
Rudolf Mareka572f832009-04-13 17:57:44 +000037#include <arch/acpi.h>
Stefan Reinauer3935b192009-04-14 06:38:15 +000038#endif
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -050039#include <timer.h>
Stefan Reinauerbf729ba2011-11-04 12:31:58 -070040#include <timestamp.h>
Aaron Durbin4409a5e2013-05-06 12:20:52 -050041#include <thread.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000042
Aaron Durbin7e35efa2013-04-24 15:14:01 -050043#if BOOT_STATE_DEBUG
44#define BS_DEBUG_LVL BIOS_DEBUG
45#else
46#define BS_DEBUG_LVL BIOS_NEVER
47#endif
Rudolf Mareka572f832009-04-13 17:57:44 +000048
Aaron Durbin7e35efa2013-04-24 15:14:01 -050049static boot_state_t bs_pre_device(void *arg);
50static boot_state_t bs_dev_init_chips(void *arg);
51static boot_state_t bs_dev_enumerate(void *arg);
52static boot_state_t bs_dev_resources(void *arg);
David Hendrickscca68592013-06-20 14:08:27 -070053static boot_state_t bs_dev_enable(void *arg);
Aaron Durbin7e35efa2013-04-24 15:14:01 -050054static boot_state_t bs_dev_init(void *arg);
55static boot_state_t bs_post_device(void *arg);
Aaron Durbin0a6c20a2013-04-24 22:33:08 -050056static boot_state_t bs_os_resume_check(void *arg);
Aaron Durbin7e35efa2013-04-24 15:14:01 -050057static boot_state_t bs_os_resume(void *arg);
58static boot_state_t bs_write_tables(void *arg);
59static boot_state_t bs_payload_load(void *arg);
60static boot_state_t bs_payload_boot(void *arg);
61
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -050062/*
63 * Typically a state will take 4 time samples:
64 * 1. Before state entry callbacks
65 * 2. After state entry callbacks / Before state function.
66 * 3. After state function / Before state exit callbacks.
67 * 4. After state exit callbacks.
68 */
69#define MAX_TIME_SAMPLES 4
70struct boot_state_times {
71 int num_samples;
72 struct mono_time samples[MAX_TIME_SAMPLES];
73};
74
Aaron Durbin0748d302013-05-06 10:50:19 -050075/* The prologue (BS_ON_ENTRY) and epilogue (BS_ON_EXIT) of a state can be
76 * blocked from transitioning to the next (state,seq) pair. When the blockers
77 * field is 0 a transition may occur. */
78struct boot_phase {
79 struct boot_state_callback *callbacks;
80 int blockers;
81};
82
Aaron Durbin7e35efa2013-04-24 15:14:01 -050083struct boot_state {
84 const char *name;
85 boot_state_t id;
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_, \
Aaron Durbin0748d302013-05-06 10:50:19 -050099 .phases = { { NULL, 0 }, { NULL, 0 } }, \
Aaron Durbin8fc41e12013-04-29 23:22:01 -0500100 .run_state = run_func_, \
101 .arg = NULL, \
102 .complete = 0, \
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500103 }
104#define BS_INIT_ENTRY(state_, run_func_) \
Aaron Durbin15c671e2013-05-06 10:52:24 -0500105 [state_] = BS_INIT(state_, run_func_)
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500106
107static struct boot_state boot_states[] = {
108 BS_INIT_ENTRY(BS_PRE_DEVICE, bs_pre_device),
109 BS_INIT_ENTRY(BS_DEV_INIT_CHIPS, bs_dev_init_chips),
110 BS_INIT_ENTRY(BS_DEV_ENUMERATE, bs_dev_enumerate),
111 BS_INIT_ENTRY(BS_DEV_RESOURCES, bs_dev_resources),
David Hendrickscca68592013-06-20 14:08:27 -0700112 BS_INIT_ENTRY(BS_DEV_ENABLE, bs_dev_enable),
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500113 BS_INIT_ENTRY(BS_DEV_INIT, bs_dev_init),
114 BS_INIT_ENTRY(BS_POST_DEVICE, bs_post_device),
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500115 BS_INIT_ENTRY(BS_OS_RESUME_CHECK, bs_os_resume_check),
Aaron Durbin15c671e2013-05-06 10:52:24 -0500116 BS_INIT_ENTRY(BS_OS_RESUME, bs_os_resume),
117 BS_INIT_ENTRY(BS_WRITE_TABLES, bs_write_tables),
118 BS_INIT_ENTRY(BS_PAYLOAD_LOAD, bs_payload_load),
119 BS_INIT_ENTRY(BS_PAYLOAD_BOOT, bs_payload_boot),
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500120};
121
122static boot_state_t bs_pre_device(void *arg)
123{
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500124 return BS_DEV_INIT_CHIPS;
125}
126
127static boot_state_t bs_dev_init_chips(void *arg)
128{
Kyösti Mälkkib766b1c2013-09-07 17:26:08 +0300129 timestamp_add_now(TS_DEVICE_ENUMERATE);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500130
131 /* Initialize chips early, they might disable unused devices. */
132 dev_initialize_chips();
133
134 return BS_DEV_ENUMERATE;
135}
136
137static boot_state_t bs_dev_enumerate(void *arg)
138{
139 /* Find the devices we don't have hard coded knowledge about. */
140 dev_enumerate();
141 post_code(POST_DEVICE_ENUMERATION_COMPLETE);
142
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);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500149 /* Now compute and assign the bus resources. */
150 dev_configure();
151 post_code(POST_DEVICE_CONFIGURATION_COMPLETE);
152
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);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500159 /* Now actually enable devices on the bus */
160 dev_enable();
161 post_code(POST_DEVICES_ENABLED);
162
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);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500169 /* And of course initialize devices on the bus */
170 dev_initialize();
171 post_code(POST_DEVICES_INITIALIZED);
172
173 return BS_POST_DEVICE;
174}
175
176static boot_state_t bs_post_device(void *arg)
177{
Kyösti Mälkkib766b1c2013-09-07 17:26:08 +0300178 timestamp_add_now(TS_DEVICE_DONE);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500179
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500180 timestamp_sync();
181
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500182 return BS_OS_RESUME_CHECK;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500183}
184
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500185static boot_state_t bs_os_resume_check(void *arg)
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500186{
187#if CONFIG_HAVE_ACPI_RESUME
Aaron Durbin0a6c20a2013-04-24 22:33:08 -0500188 void *wake_vector;
189
190 wake_vector = acpi_find_wakeup_vector();
191
192 if (wake_vector != NULL) {
193 boot_states[BS_OS_RESUME].arg = wake_vector;
194 return BS_OS_RESUME;
195 }
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500196 post_code(0x8a);
197#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
220 return BS_PAYLOAD_LOAD;
221}
222
223static boot_state_t bs_payload_load(void *arg)
224{
225 void *payload;
Aaron Durbin001de1a2013-04-24 22:59:45 -0500226 void *entry;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500227
228 timestamp_add_now(TS_LOAD_PAYLOAD);
229
230 payload = cbfs_load_payload(CBFS_DEFAULT_MEDIA,
231 CONFIG_CBFS_PREFIX "/payload");
232 if (! payload)
233 die("Could not find a payload\n");
234
Aaron Durbin001de1a2013-04-24 22:59:45 -0500235 entry = selfload(get_lb_mem(), payload);
236
237 if (! entry)
238 die("Could not load payload\n");
239
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500240 /* Pass the payload to the next state. */
Aaron Durbin001de1a2013-04-24 22:59:45 -0500241 boot_states[BS_PAYLOAD_BOOT].arg = entry;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500242
243 return BS_PAYLOAD_BOOT;
244}
245
Aaron Durbin001de1a2013-04-24 22:59:45 -0500246static boot_state_t bs_payload_boot(void *entry)
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500247{
Aaron Durbin001de1a2013-04-24 22:59:45 -0500248 selfboot(entry);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500249
250 printk(BIOS_EMERG, "Boot failed");
251 /* Returning from this state will fail because the following signals
252 * return to a completed state. */
253 return BS_PAYLOAD_BOOT;
254}
255
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500256#if CONFIG_HAVE_MONOTONIC_TIMER
257static void bs_sample_time(struct boot_state *state)
258{
259 struct mono_time *mt;
260
261 mt = &state->times.samples[state->times.num_samples];
262 timer_monotonic_get(mt);
263 state->times.num_samples++;
264}
265
266static void bs_report_time(struct boot_state *state)
267{
268 struct rela_time entry_time;
269 struct rela_time run_time;
270 struct rela_time exit_time;
271 struct boot_state_times *times;
272
273 times = &state->times;
274 entry_time = mono_time_diff(&times->samples[0], &times->samples[1]);
275 run_time = mono_time_diff(&times->samples[1], &times->samples[2]);
276 exit_time = mono_time_diff(&times->samples[2], &times->samples[3]);
277
278 printk(BIOS_DEBUG, "BS: %s times (us): entry %ld run %ld exit %ld\n",
279 state->name,
280 rela_time_in_microseconds(&entry_time),
281 rela_time_in_microseconds(&run_time),
282 rela_time_in_microseconds(&exit_time));
283}
284#else
285static inline void bs_sample_time(struct boot_state *state) {}
286static inline void bs_report_time(struct boot_state *state) {}
287#endif
288
Aaron Durbin8fc41e12013-04-29 23:22:01 -0500289#if CONFIG_TIMER_QUEUE
290static void bs_run_timers(int drain)
291{
292 /* Drain all timer callbacks until none are left, if directed.
293 * Otherwise run the timers only once. */
294 do {
295 if (!timers_run())
296 break;
297 } while (drain);
298}
299#else
300static void bs_run_timers(int drain) {}
301#endif
302
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500303static void bs_call_callbacks(struct boot_state *state,
304 boot_state_sequence_t seq)
305{
Aaron Durbin0748d302013-05-06 10:50:19 -0500306 struct boot_phase *phase = &state->phases[seq];
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500307
Aaron Durbin0748d302013-05-06 10:50:19 -0500308 while (1) {
309 if (phase->callbacks != NULL) {
310 struct boot_state_callback *bscb;
311
312 /* Remove the first callback. */
313 bscb = phase->callbacks;
314 phase->callbacks = bscb->next;
315 bscb->next = NULL;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500316
317#if BOOT_STATE_DEBUG
Aaron Durbin0748d302013-05-06 10:50:19 -0500318 printk(BS_DEBUG_LVL, "BS: callback (%p) @ %s.\n",
319 bscb, bscb->location);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500320#endif
Aaron Durbin0748d302013-05-06 10:50:19 -0500321 bscb->callback(bscb->arg);
322
323 continue;
324 }
325
326 /* All callbacks are complete and there are no blockers for
327 * this state. Therefore, this part of the state is complete. */
328 if (!phase->blockers)
329 break;
330
331 /* Something is blocking this state from transitioning. As
332 * there are no more callbacks a pending timer needs to be
333 * ran to unblock the state. */
334 bs_run_timers(0);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500335 }
336}
337
Aaron Durbin0748d302013-05-06 10:50:19 -0500338/* Keep track of the current state. */
339static struct state_tracker {
340 boot_state_t state_id;
341 boot_state_sequence_t seq;
342} current_phase = {
343 .state_id = BS_PRE_DEVICE,
344 .seq = BS_ON_ENTRY,
345};
346
347static void bs_walk_state_machine(void)
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500348{
349
350 while (1) {
351 struct boot_state *state;
Aaron Durbin0748d302013-05-06 10:50:19 -0500352 boot_state_t next_id;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500353
Aaron Durbin0748d302013-05-06 10:50:19 -0500354 state = &boot_states[current_phase.state_id];
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500355
356 if (state->complete) {
357 printk(BIOS_EMERG, "BS: %s state already executed.\n",
358 state->name);
359 break;
360 }
361
362 printk(BS_DEBUG_LVL, "BS: Entering %s state.\n", state->name);
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500363
Aaron Durbin15c671e2013-05-06 10:52:24 -0500364 bs_run_timers(0);
Aaron Durbin8fc41e12013-04-29 23:22:01 -0500365
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500366 bs_sample_time(state);
367
Aaron Durbin0748d302013-05-06 10:50:19 -0500368 bs_call_callbacks(state, current_phase.seq);
369 /* Update the current sequence so that any calls to block the
370 * current state from the run_state() function will place a
371 * block on the correct phase. */
372 current_phase.seq = BS_ON_EXIT;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500373
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500374 bs_sample_time(state);
375
Aaron Durbin0748d302013-05-06 10:50:19 -0500376 next_id = state->run_state(state->arg);
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500377
378 printk(BS_DEBUG_LVL, "BS: Exiting %s state.\n", state->name);
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500379
380 bs_sample_time(state);
381
Aaron Durbin0748d302013-05-06 10:50:19 -0500382 bs_call_callbacks(state, current_phase.seq);
383
384 /* Update the current phase with new state id and sequence. */
385 current_phase.state_id = next_id;
386 current_phase.seq = BS_ON_ENTRY;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500387
Aaron Durbin6b0fb0d2013-04-26 20:54:16 -0500388 bs_sample_time(state);
389
390 bs_report_time(state);
391
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500392 state->complete = 1;
393 }
394}
395
396static int boot_state_sched_callback(struct boot_state *state,
397 struct boot_state_callback *bscb,
398 boot_state_sequence_t seq)
399{
400 if (state->complete) {
401 printk(BIOS_WARNING,
402 "Tried to schedule callback on completed state %s.\n",
403 state->name);
404
405 return -1;
406 }
407
Aaron Durbin0748d302013-05-06 10:50:19 -0500408 bscb->next = state->phases[seq].callbacks;
409 state->phases[seq].callbacks = bscb;
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500410
411 return 0;
412}
413
414int boot_state_sched_on_entry(struct boot_state_callback *bscb,
415 boot_state_t state_id)
416{
417 struct boot_state *state = &boot_states[state_id];
418
419 return boot_state_sched_callback(state, bscb, BS_ON_ENTRY);
420}
421
422int boot_state_sched_on_exit(struct boot_state_callback *bscb,
423 boot_state_t state_id)
424{
425 struct boot_state *state = &boot_states[state_id];
426
427 return boot_state_sched_callback(state, bscb, BS_ON_EXIT);
428}
Maciej Pijankaea921852009-10-27 14:29:29 +0000429
Aaron Durbina4feddf2013-04-24 16:12:52 -0500430static void boot_state_schedule_static_entries(void)
431{
432 extern struct boot_state_init_entry _bs_init_begin;
433 extern struct boot_state_init_entry _bs_init_end;
434 struct boot_state_init_entry *cur;
435
436 cur = &_bs_init_begin;
437
438 while (cur != &_bs_init_end) {
439 if (cur->when == BS_ON_ENTRY)
440 boot_state_sched_on_entry(&cur->bscb, cur->state);
441 else
442 boot_state_sched_on_exit(&cur->bscb, cur->state);
443 cur++;
444 }
445}
446
Stefan Reinauer6adef082013-05-09 16:30:06 -0700447void main(void)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000448{
Kyösti Mälkkib766b1c2013-09-07 17:26:08 +0300449 /* Record current time, try to locate timestamps in CBMEM. */
450 timestamp_init(rdtsc());
451
452 timestamp_add_now(TS_START_RAMSTAGE);
Alexandru Gagniuc5005bb062011-04-11 20:17:22 +0000453 post_code(POST_ENTRY_RAMSTAGE);
Li-Ta Lo6a8745ae2004-05-13 20:39:07 +0000454
Stefan Reinauer3b314022009-10-26 17:04:28 +0000455 /* console_init() MUST PRECEDE ALL printk()! */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000456 console_init();
Stefan Reinauer14e22772010-04-27 06:56:47 +0000457
Alexandru Gagniuc5005bb062011-04-11 20:17:22 +0000458 post_code(POST_CONSOLE_READY);
arch import user (historical)54d6b082005-07-06 17:17:41 +0000459
Stefan Reinauer2a3c1062013-05-06 16:49:56 -0700460 printk(BIOS_NOTICE, "coreboot-%s%s %s booting...\n",
461 coreboot_version, coreboot_extra_version, coreboot_build);
Eric Biederman8ca8d762003-04-22 19:02:15 +0000462
Alexandru Gagniuc5005bb062011-04-11 20:17:22 +0000463 post_code(POST_CONSOLE_BOOT_MSG);
Eric Biederman8ca8d762003-04-22 19:02:15 +0000464
Aaron Durbin4409a5e2013-05-06 12:20:52 -0500465 threads_initialize();
466
Aaron Durbina4feddf2013-04-24 16:12:52 -0500467 /* Schedule the static boot state entries. */
468 boot_state_schedule_static_entries();
469
Eric Biederman7003ba42004-10-16 06:20:29 +0000470 /* FIXME: Is there a better way to handle this? */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000471 init_timer();
Eric Biederman8ca8d762003-04-22 19:02:15 +0000472
Aaron Durbin0748d302013-05-06 10:50:19 -0500473 bs_walk_state_machine();
474
Aaron Durbin7e35efa2013-04-24 15:14:01 -0500475 die("Boot state machine failure.\n");
Eric Biederman8ca8d762003-04-22 19:02:15 +0000476}
477
Aaron Durbin0748d302013-05-06 10:50:19 -0500478
479int boot_state_block(boot_state_t state, boot_state_sequence_t seq)
480{
481 struct boot_phase *bp;
482
483 /* Blocking a previously ran state is not appropriate. */
484 if (current_phase.state_id > state ||
485 (current_phase.state_id == state && current_phase.seq > seq) ) {
486 printk(BIOS_WARNING,
487 "BS: Completed state (%d, %d) block attempted.\n",
488 state, seq);
489 return -1;
490 }
491
492 bp = &boot_states[state].phases[seq];
493 bp->blockers++;
494
495 return 0;
496}
497
498int boot_state_unblock(boot_state_t state, boot_state_sequence_t seq)
499{
500 struct boot_phase *bp;
501
502 /* Blocking a previously ran state is not appropriate. */
503 if (current_phase.state_id > state ||
504 (current_phase.state_id == state && current_phase.seq > seq) ) {
505 printk(BIOS_WARNING,
506 "BS: Completed state (%d, %d) unblock attempted.\n",
507 state, seq);
508 return -1;
509 }
510
511 bp = &boot_states[state].phases[seq];
512
513 if (bp->blockers == 0) {
514 printk(BIOS_WARNING,
515 "BS: Unblock attempted on non-blocked state (%d, %d).\n",
516 state, seq);
517 return -1;
518 }
519
520 bp->blockers--;
521
522 return 0;
523}
524
525void boot_state_current_block(void)
526{
527 boot_state_block(current_phase.state_id, current_phase.seq);
528}
529
530void boot_state_current_unblock(void)
531{
532 boot_state_unblock(current_phase.state_id, current_phase.seq);
533}