Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1 | /* |
| 2 | This software and ancillary information (herein called SOFTWARE ) |
| 3 | called LinuxBIOS is made available under the terms described |
| 4 | here. The SOFTWARE has been approved for release with associated |
| 5 | LA-CC Number 00-34 . Unless otherwise indicated, this SOFTWARE has |
| 6 | been authored by an employee or employees of the University of |
| 7 | California, operator of the Los Alamos National Laboratory under |
| 8 | Contract No. W-7405-ENG-36 with the U.S. Department of Energy. The |
| 9 | U.S. Government has rights to use, reproduce, and distribute this |
| 10 | SOFTWARE. The public may copy, distribute, prepare derivative works |
| 11 | and publicly display this SOFTWARE without charge, provided that this |
| 12 | Notice and any statement of authorship are reproduced on all copies. |
| 13 | Neither the Government nor the University makes any warranty, express |
| 14 | or implied, or assumes any liability or responsibility for the use of |
| 15 | this SOFTWARE. If SOFTWARE is modified to produce derivative works, |
| 16 | such modified SOFTWARE should be clearly marked, so as not to confuse |
| 17 | it 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 Reinauer | f8ee180 | 2008-01-18 15:08:58 +0000 | [diff] [blame] | 25 | * C Bootstrap code for the coreboot |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 26 | */ |
| 27 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 28 | #include <console/console.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 29 | #include <version.h> |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 30 | #include <device/device.h> |
| 31 | #include <device/pci.h> |
Eric Biederman | 9b4336c | 2003-07-19 04:28:22 +0000 | [diff] [blame] | 32 | #include <delay.h> |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 33 | #include <stdlib.h> |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 34 | #include <reset.h> |
Stefan Reinauer | 7e9771c | 2009-04-22 08:17:38 +0000 | [diff] [blame] | 35 | #include <boot/tables.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 36 | #include <boot/elf.h> |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 37 | #include <cbfs.h> |
Ronald G. Minnich | 9764d4c | 2012-06-12 16:29:32 -0700 | [diff] [blame^] | 38 | #include <lib.h> |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 39 | #if CONFIG_HAVE_ACPI_RESUME |
Rudolf Marek | a572f83 | 2009-04-13 17:57:44 +0000 | [diff] [blame] | 40 | #include <arch/acpi.h> |
Stefan Reinauer | 3935b19 | 2009-04-14 06:38:15 +0000 | [diff] [blame] | 41 | #endif |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 42 | #if CONFIG_WRITE_HIGH_TABLES |
| 43 | #include <cbmem.h> |
| 44 | #endif |
Stefan Reinauer | bf729ba | 2011-11-04 12:31:58 -0700 | [diff] [blame] | 45 | #include <timestamp.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 46 | |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 47 | /** |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 48 | * @brief Main function of the RAM part of coreboot. |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 49 | * |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 50 | * Coreboot is divided into Pre-RAM part and RAM part. |
| 51 | * |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 52 | * Device Enumeration: |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 53 | * In the dev_enumerate() phase, |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 54 | */ |
Rudolf Marek | a572f83 | 2009-04-13 17:57:44 +0000 | [diff] [blame] | 55 | |
Maciej Pijanka | ea92185 | 2009-10-27 14:29:29 +0000 | [diff] [blame] | 56 | void hardwaremain(int boot_complete); |
| 57 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 58 | void hardwaremain(int boot_complete) |
| 59 | { |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 60 | struct lb_memory *lb_mem; |
Rudolf Marek | 3294a0f1 | 2012-04-24 16:01:24 +0200 | [diff] [blame] | 61 | #if CONFIG_COLLECT_TIMESTAMPS |
Stefan Reinauer | bf729ba | 2011-11-04 12:31:58 -0700 | [diff] [blame] | 62 | tsc_t timestamps[6]; |
Stefan Reinauer | bf729ba | 2011-11-04 12:31:58 -0700 | [diff] [blame] | 63 | timestamps[0] = rdtsc(); |
Rudolf Marek | 3294a0f1 | 2012-04-24 16:01:24 +0200 | [diff] [blame] | 64 | #endif |
Alexandru Gagniuc | 5005bb06 | 2011-04-11 20:17:22 +0000 | [diff] [blame] | 65 | post_code(POST_ENTRY_RAMSTAGE); |
Li-Ta Lo | 6a8745ae | 2004-05-13 20:39:07 +0000 | [diff] [blame] | 66 | |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 67 | /* console_init() MUST PRECEDE ALL printk()! */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 68 | console_init(); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 69 | |
Alexandru Gagniuc | 5005bb06 | 2011-04-11 20:17:22 +0000 | [diff] [blame] | 70 | post_code(POST_CONSOLE_READY); |
arch import user (historical) | 54d6b08 | 2005-07-06 17:17:41 +0000 | [diff] [blame] | 71 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 72 | printk(BIOS_NOTICE, "coreboot-%s%s %s %s...\n", |
Stefan Reinauer | f8ee180 | 2008-01-18 15:08:58 +0000 | [diff] [blame] | 73 | coreboot_version, coreboot_extra_version, coreboot_build, |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 74 | (boot_complete)?"rebooting":"booting"); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 75 | |
Alexandru Gagniuc | 5005bb06 | 2011-04-11 20:17:22 +0000 | [diff] [blame] | 76 | post_code(POST_CONSOLE_BOOT_MSG); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 77 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 78 | /* If we have already booted attempt a hard reboot */ |
| 79 | if (boot_complete) { |
| 80 | hard_reset(); |
| 81 | } |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 82 | |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 83 | /* FIXME: Is there a better way to handle this? */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 84 | init_timer(); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 85 | |
Rudolf Marek | 3294a0f1 | 2012-04-24 16:01:24 +0200 | [diff] [blame] | 86 | #if CONFIG_COLLECT_TIMESTAMPS |
Stefan Reinauer | bf729ba | 2011-11-04 12:31:58 -0700 | [diff] [blame] | 87 | timestamps[1] = rdtsc(); |
Rudolf Marek | 3294a0f1 | 2012-04-24 16:01:24 +0200 | [diff] [blame] | 88 | #endif |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 89 | /* Find the devices we don't have hard coded knowledge about. */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 90 | dev_enumerate(); |
Alexandru Gagniuc | 5005bb06 | 2011-04-11 20:17:22 +0000 | [diff] [blame] | 91 | post_code(POST_DEVICE_ENUMERATION_COMPLETE); |
Stefan Reinauer | bf729ba | 2011-11-04 12:31:58 -0700 | [diff] [blame] | 92 | |
Rudolf Marek | 3294a0f1 | 2012-04-24 16:01:24 +0200 | [diff] [blame] | 93 | #if CONFIG_COLLECT_TIMESTAMPS |
Stefan Reinauer | bf729ba | 2011-11-04 12:31:58 -0700 | [diff] [blame] | 94 | timestamps[2] = rdtsc(); |
Rudolf Marek | 3294a0f1 | 2012-04-24 16:01:24 +0200 | [diff] [blame] | 95 | #endif |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 96 | /* Now compute and assign the bus resources. */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 97 | dev_configure(); |
Alexandru Gagniuc | 5005bb06 | 2011-04-11 20:17:22 +0000 | [diff] [blame] | 98 | post_code(POST_DEVICE_CONFIGURATION_COMPLETE); |
Stefan Reinauer | bf729ba | 2011-11-04 12:31:58 -0700 | [diff] [blame] | 99 | |
Rudolf Marek | 3294a0f1 | 2012-04-24 16:01:24 +0200 | [diff] [blame] | 100 | #if CONFIG_COLLECT_TIMESTAMPS |
Stefan Reinauer | bf729ba | 2011-11-04 12:31:58 -0700 | [diff] [blame] | 101 | timestamps[3] = rdtsc(); |
Rudolf Marek | 3294a0f1 | 2012-04-24 16:01:24 +0200 | [diff] [blame] | 102 | #endif |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 103 | /* Now actually enable devices on the bus */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 104 | dev_enable(); |
Stefan Reinauer | bf729ba | 2011-11-04 12:31:58 -0700 | [diff] [blame] | 105 | |
Rudolf Marek | 3294a0f1 | 2012-04-24 16:01:24 +0200 | [diff] [blame] | 106 | #if CONFIG_COLLECT_TIMESTAMPS |
Stefan Reinauer | bf729ba | 2011-11-04 12:31:58 -0700 | [diff] [blame] | 107 | timestamps[4] = rdtsc(); |
Rudolf Marek | 3294a0f1 | 2012-04-24 16:01:24 +0200 | [diff] [blame] | 108 | #endif |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 109 | /* And of course initialize devices on the bus */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 110 | dev_initialize(); |
Alexandru Gagniuc | 5005bb06 | 2011-04-11 20:17:22 +0000 | [diff] [blame] | 111 | post_code(POST_DEVICES_ENABLED); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 112 | |
Rudolf Marek | 3294a0f1 | 2012-04-24 16:01:24 +0200 | [diff] [blame] | 113 | #if CONFIG_COLLECT_TIMESTAMPS |
Stefan Reinauer | bf729ba | 2011-11-04 12:31:58 -0700 | [diff] [blame] | 114 | timestamps[5] = rdtsc(); |
Rudolf Marek | 3294a0f1 | 2012-04-24 16:01:24 +0200 | [diff] [blame] | 115 | #endif |
| 116 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 117 | #if CONFIG_WRITE_HIGH_TABLES |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 118 | cbmem_initialize(); |
Vadim Bendebury | 1078c67 | 2011-09-30 11:16:49 -0700 | [diff] [blame] | 119 | #if CONFIG_CONSOLE_CBMEM |
| 120 | cbmemc_reinit(); |
| 121 | #endif |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 122 | #endif |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 123 | #if CONFIG_HAVE_ACPI_RESUME |
Stefan Reinauer | 7e9771c | 2009-04-22 08:17:38 +0000 | [diff] [blame] | 124 | suspend_resume(); |
| 125 | post_code(0x8a); |
Rudolf Marek | a572f83 | 2009-04-13 17:57:44 +0000 | [diff] [blame] | 126 | #endif |
| 127 | |
Stefan Reinauer | bf729ba | 2011-11-04 12:31:58 -0700 | [diff] [blame] | 128 | 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 Reinauer | bb11e60 | 2012-05-10 12:15:18 -0700 | [diff] [blame] | 134 | timestamp_add_now(TS_CBMEM_POST); |
| 135 | |
| 136 | if (cbmem_post_handling) |
| 137 | cbmem_post_handling(); |
| 138 | |
Stefan Reinauer | bf729ba | 2011-11-04 12:31:58 -0700 | [diff] [blame] | 139 | timestamp_add_now(TS_WRITE_TABLES); |
| 140 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 141 | /* Now that we have collected all of our information |
| 142 | * write our configuration tables. |
| 143 | */ |
| 144 | lb_mem = write_tables(); |
Stefan Reinauer | bf729ba | 2011-11-04 12:31:58 -0700 | [diff] [blame] | 145 | |
| 146 | timestamp_add_now(TS_LOAD_PAYLOAD); |
Ronald G. Minnich | 9764d4c | 2012-06-12 16:29:32 -0700 | [diff] [blame^] | 147 | |
| 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 Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 161 | } |
| 162 | |