blob: bb7f264c084ecbeb91e6fa0499f4da2bbf944b42 [file] [log] [blame]
Eric Biederman8ca8d762003-04-22 19:02:15 +00001/*
2This software and ancillary information (herein called SOFTWARE )
3called LinuxBIOS is made available under the terms described
4here. The SOFTWARE has been approved for release with associated
5LA-CC Number 00-34 . Unless otherwise indicated, this SOFTWARE has
6been authored by an employee or employees of the University of
7California, operator of the Los Alamos National Laboratory under
8Contract No. W-7405-ENG-36 with the U.S. Department of Energy. The
9U.S. Government has rights to use, reproduce, and distribute this
10SOFTWARE. The public may copy, distribute, prepare derivative works
11and publicly display this SOFTWARE without charge, provided that this
12Notice and any statement of authorship are reproduced on all copies.
13Neither the Government nor the University makes any warranty, express
14or implied, or assumes any liability or responsibility for the use of
15this SOFTWARE. If SOFTWARE is modified to produce derivative works,
16such modified SOFTWARE should be clearly marked, so as not to confuse
17it with the version available from LANL.
18 */
19/* Copyright 2000, Ron Minnich, Advanced Computing Lab, LANL
20 * rminnich@lanl.gov
21 */
22
23
24/*
Stefan Reinauerf8ee1802008-01-18 15:08:58 +000025 * C Bootstrap code for the coreboot
Eric Biederman8ca8d762003-04-22 19:02:15 +000026 */
27
Eric Biederman8ca8d762003-04-22 19:02:15 +000028#include <console/console.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>
Eric Biederman8ca8d762003-04-22 19:02:15 +000036#include <boot/elf.h>
Peter Stuge483b7bb2009-04-14 07:40:01 +000037#include <cbfs.h>
Ronald G. Minnich9764d4c2012-06-12 16:29:32 -070038#include <lib.h>
Stefan Reinauer08670622009-06-30 15:17:49 +000039#if CONFIG_HAVE_ACPI_RESUME
Rudolf Mareka572f832009-04-13 17:57:44 +000040#include <arch/acpi.h>
Stefan Reinauer3935b192009-04-14 06:38:15 +000041#endif
Stefan Reinauer3b314022009-10-26 17:04:28 +000042#if CONFIG_WRITE_HIGH_TABLES
43#include <cbmem.h>
44#endif
Stefan Reinauerbf729ba2011-11-04 12:31:58 -070045#include <timestamp.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000046
Li-Ta Lo3a812852004-12-03 22:39:34 +000047/**
Stefan Reinauer3b314022009-10-26 17:04:28 +000048 * @brief Main function of the RAM part of coreboot.
Li-Ta Lo3a812852004-12-03 22:39:34 +000049 *
Stefan Reinauer14e22772010-04-27 06:56:47 +000050 * Coreboot is divided into Pre-RAM part and RAM part.
51 *
Li-Ta Lo3a812852004-12-03 22:39:34 +000052 * Device Enumeration:
Stefan Reinauer14e22772010-04-27 06:56:47 +000053 * In the dev_enumerate() phase,
Li-Ta Lo3a812852004-12-03 22:39:34 +000054 */
Rudolf Mareka572f832009-04-13 17:57:44 +000055
Maciej Pijankaea921852009-10-27 14:29:29 +000056void hardwaremain(int boot_complete);
57
Eric Biederman8ca8d762003-04-22 19:02:15 +000058void hardwaremain(int boot_complete)
59{
Eric Biederman8ca8d762003-04-22 19:02:15 +000060 struct lb_memory *lb_mem;
Rudolf Marek3294a0f12012-04-24 16:01:24 +020061#if CONFIG_COLLECT_TIMESTAMPS
Stefan Reinauerbf729ba2011-11-04 12:31:58 -070062 tsc_t timestamps[6];
Stefan Reinauerbf729ba2011-11-04 12:31:58 -070063 timestamps[0] = rdtsc();
Rudolf Marek3294a0f12012-04-24 16:01:24 +020064#endif
Alexandru Gagniuc5005bb062011-04-11 20:17:22 +000065 post_code(POST_ENTRY_RAMSTAGE);
Li-Ta Lo6a8745ae2004-05-13 20:39:07 +000066
Stefan Reinauer3b314022009-10-26 17:04:28 +000067 /* console_init() MUST PRECEDE ALL printk()! */
Eric Biederman8ca8d762003-04-22 19:02:15 +000068 console_init();
Stefan Reinauer14e22772010-04-27 06:56:47 +000069
Alexandru Gagniuc5005bb062011-04-11 20:17:22 +000070 post_code(POST_CONSOLE_READY);
arch import user (historical)54d6b082005-07-06 17:17:41 +000071
Stefan Reinauer14e22772010-04-27 06:56:47 +000072 printk(BIOS_NOTICE, "coreboot-%s%s %s %s...\n",
Stefan Reinauerf8ee1802008-01-18 15:08:58 +000073 coreboot_version, coreboot_extra_version, coreboot_build,
Li-Ta Lo3a812852004-12-03 22:39:34 +000074 (boot_complete)?"rebooting":"booting");
Eric Biederman8ca8d762003-04-22 19:02:15 +000075
Alexandru Gagniuc5005bb062011-04-11 20:17:22 +000076 post_code(POST_CONSOLE_BOOT_MSG);
Eric Biederman8ca8d762003-04-22 19:02:15 +000077
Eric Biederman8ca8d762003-04-22 19:02:15 +000078 /* If we have already booted attempt a hard reboot */
79 if (boot_complete) {
80 hard_reset();
81 }
Li-Ta Loe5266692004-03-23 21:28:05 +000082
Eric Biederman7003ba42004-10-16 06:20:29 +000083 /* FIXME: Is there a better way to handle this? */
Stefan Reinauer14e22772010-04-27 06:56:47 +000084 init_timer();
Eric Biederman8ca8d762003-04-22 19:02:15 +000085
Rudolf Marek3294a0f12012-04-24 16:01:24 +020086#if CONFIG_COLLECT_TIMESTAMPS
Stefan Reinauerbf729ba2011-11-04 12:31:58 -070087 timestamps[1] = rdtsc();
Rudolf Marek3294a0f12012-04-24 16:01:24 +020088#endif
Eric Biederman018d8dd2004-11-04 11:04:33 +000089 /* Find the devices we don't have hard coded knowledge about. */
Eric Biederman8ca8d762003-04-22 19:02:15 +000090 dev_enumerate();
Alexandru Gagniuc5005bb062011-04-11 20:17:22 +000091 post_code(POST_DEVICE_ENUMERATION_COMPLETE);
Stefan Reinauerbf729ba2011-11-04 12:31:58 -070092
Rudolf Marek3294a0f12012-04-24 16:01:24 +020093#if CONFIG_COLLECT_TIMESTAMPS
Stefan Reinauerbf729ba2011-11-04 12:31:58 -070094 timestamps[2] = rdtsc();
Rudolf Marek3294a0f12012-04-24 16:01:24 +020095#endif
Eric Biederman018d8dd2004-11-04 11:04:33 +000096 /* Now compute and assign the bus resources. */
Eric Biederman8ca8d762003-04-22 19:02:15 +000097 dev_configure();
Alexandru Gagniuc5005bb062011-04-11 20:17:22 +000098 post_code(POST_DEVICE_CONFIGURATION_COMPLETE);
Stefan Reinauerbf729ba2011-11-04 12:31:58 -070099
Rudolf Marek3294a0f12012-04-24 16:01:24 +0200100#if CONFIG_COLLECT_TIMESTAMPS
Stefan Reinauerbf729ba2011-11-04 12:31:58 -0700101 timestamps[3] = rdtsc();
Rudolf Marek3294a0f12012-04-24 16:01:24 +0200102#endif
Eric Biederman018d8dd2004-11-04 11:04:33 +0000103 /* Now actually enable devices on the bus */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000104 dev_enable();
Stefan Reinauerbf729ba2011-11-04 12:31:58 -0700105
Rudolf Marek3294a0f12012-04-24 16:01:24 +0200106#if CONFIG_COLLECT_TIMESTAMPS
Stefan Reinauerbf729ba2011-11-04 12:31:58 -0700107 timestamps[4] = rdtsc();
Rudolf Marek3294a0f12012-04-24 16:01:24 +0200108#endif
Eric Biederman018d8dd2004-11-04 11:04:33 +0000109 /* And of course initialize devices on the bus */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000110 dev_initialize();
Alexandru Gagniuc5005bb062011-04-11 20:17:22 +0000111 post_code(POST_DEVICES_ENABLED);
Eric Biederman8ca8d762003-04-22 19:02:15 +0000112
Rudolf Marek3294a0f12012-04-24 16:01:24 +0200113#if CONFIG_COLLECT_TIMESTAMPS
Stefan Reinauerbf729ba2011-11-04 12:31:58 -0700114 timestamps[5] = rdtsc();
Rudolf Marek3294a0f12012-04-24 16:01:24 +0200115#endif
116
Patrick Georgie1667822012-05-05 15:29:32 +0200117#if CONFIG_WRITE_HIGH_TABLES
Stefan Reinauer3b314022009-10-26 17:04:28 +0000118 cbmem_initialize();
Vadim Bendebury1078c672011-09-30 11:16:49 -0700119#if CONFIG_CONSOLE_CBMEM
120 cbmemc_reinit();
121#endif
Stefan Reinauer3b314022009-10-26 17:04:28 +0000122#endif
Patrick Georgie1667822012-05-05 15:29:32 +0200123#if CONFIG_HAVE_ACPI_RESUME
Stefan Reinauer7e9771c2009-04-22 08:17:38 +0000124 suspend_resume();
125 post_code(0x8a);
Rudolf Mareka572f832009-04-13 17:57:44 +0000126#endif
127
Stefan Reinauerbf729ba2011-11-04 12:31:58 -0700128 timestamp_add(TS_START_RAMSTAGE, timestamps[0]);
129 timestamp_add(TS_DEVICE_ENUMERATE, timestamps[1]);
130 timestamp_add(TS_DEVICE_CONFIGURE, timestamps[2]);
131 timestamp_add(TS_DEVICE_ENABLE, timestamps[3]);
132 timestamp_add(TS_DEVICE_INITIALIZE, timestamps[4]);
133 timestamp_add(TS_DEVICE_DONE, timestamps[5]);
Stefan Reinauerbb11e602012-05-10 12:15:18 -0700134 timestamp_add_now(TS_CBMEM_POST);
135
136 if (cbmem_post_handling)
137 cbmem_post_handling();
138
Stefan Reinauerbf729ba2011-11-04 12:31:58 -0700139 timestamp_add_now(TS_WRITE_TABLES);
140
Eric Biedermanb78c1972004-10-14 20:54:17 +0000141 /* Now that we have collected all of our information
142 * write our configuration tables.
143 */
144 lb_mem = write_tables();
Stefan Reinauerbf729ba2011-11-04 12:31:58 -0700145
146 timestamp_add_now(TS_LOAD_PAYLOAD);
Ronald G. Minnich9764d4c2012-06-12 16:29:32 -0700147
148 void *payload;
149 payload = cbfs_load_payload(lb_mem, CONFIG_CBFS_PREFIX "/payload");
150 if (! payload)
151 die("Could not find a payload\n");
152
153 printk(BIOS_DEBUG, "Got a payload\n");
154 /* Before we go off to run the payload, see if
155 * we stayed within our bounds.
156 */
157 checkstack(&_estack, 0);
158
159 selfboot(lb_mem, payload);
160 printk(BIOS_EMERG, "Boot failed");
Eric Biederman8ca8d762003-04-22 19:02:15 +0000161}
162