blob: ef1a3a5a1d454c62051db8cf4e9bef1a3419eaa5 [file] [log] [blame]
Stefan Reinauerabc0c852010-11-22 08:09:50 +00001/*
2 * This file is part of the coreboot project.
Stefan Reinauer5ff7c132011-10-31 12:56:45 -07003 *
Stefan Reinauerabc0c852010-11-22 08:09:50 +00004 * Copyright (C) 2003 Eric Biederman
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 * MA 02110-1301 USA
20 */
21
22#include <arch/io.h>
23#include <console/console.h>
David Hendricks534c8a02012-11-26 15:07:39 -080024#if CONFIG_CMOS_POST
Duncan Laurieb6e97b12012-09-09 19:09:56 -070025#include <pc80/mc146818rtc.h>
Duncan Lauriee807c342013-06-10 09:53:33 -070026#include <smp/spinlock.h>
David Hendricks534c8a02012-11-26 15:07:39 -080027#endif
Duncan Lauried5686fe2013-06-10 10:21:41 -070028#if CONFIG_CMOS_POST_EXTRA
29#include <device/device.h>
30#endif
Duncan Laurie1fc34612012-09-09 19:14:45 -070031#include <elog.h>
Stefan Reinauerabc0c852010-11-22 08:09:50 +000032
33/* Write POST information */
34
Alexandru Gagniucf88204e2012-08-03 13:20:57 -050035/* someday romcc will be gone. */
36#ifndef __ROMCC__
37/* Some mainboards have very nice features beyond just a simple display.
38 * They can override this function.
39 */
40void __attribute__((weak)) mainboard_post(uint8_t value)
41{
42}
43
44#else
45/* This just keeps the number of #ifs to a minimum */
46#define mainboard_post(x)
47#endif
48
Duncan Laurieb6e97b12012-09-09 19:09:56 -070049#if CONFIG_CMOS_POST
Duncan Laurie1fc34612012-09-09 19:14:45 -070050
Duncan Lauriee807c342013-06-10 09:53:33 -070051DECLARE_SPIN_LOCK(cmos_post_lock)
52
Duncan Laurie1fc34612012-09-09 19:14:45 -070053#if !defined(__PRE_RAM__)
54void cmos_post_log(void)
55{
Duncan Lauriee807c342013-06-10 09:53:33 -070056 u8 code = 0;
Duncan Lauried5686fe2013-06-10 10:21:41 -070057#if CONFIG_CMOS_POST_EXTRA
58 u32 extra = 0;
59#endif
Duncan Lauriee807c342013-06-10 09:53:33 -070060
61 spin_lock(&cmos_post_lock);
Duncan Laurie1fc34612012-09-09 19:14:45 -070062
63 /* Get post code from other bank */
64 switch (cmos_read(CMOS_POST_BANK_OFFSET)) {
65 case CMOS_POST_BANK_0_MAGIC:
66 code = cmos_read(CMOS_POST_BANK_1_OFFSET);
Duncan Lauried5686fe2013-06-10 10:21:41 -070067#if CONFIG_CMOS_POST_EXTRA
68 extra = cmos_read32(CMOS_POST_BANK_1_EXTRA);
69#endif
Duncan Laurie1fc34612012-09-09 19:14:45 -070070 break;
71 case CMOS_POST_BANK_1_MAGIC:
72 code = cmos_read(CMOS_POST_BANK_0_OFFSET);
Duncan Lauried5686fe2013-06-10 10:21:41 -070073#if CONFIG_CMOS_POST_EXTRA
74 extra = cmos_read32(CMOS_POST_BANK_0_EXTRA);
75#endif
Duncan Laurie1fc34612012-09-09 19:14:45 -070076 break;
Duncan Laurie1fc34612012-09-09 19:14:45 -070077 }
78
Duncan Lauriee807c342013-06-10 09:53:33 -070079 spin_unlock(&cmos_post_lock);
80
Duncan Laurie1fc34612012-09-09 19:14:45 -070081 /* Check last post code in previous boot against normal list */
82 switch (code) {
83 case POST_OS_BOOT:
84 case POST_OS_RESUME:
85 case POST_ENTER_ELF_BOOT:
86 case 0:
87 break;
88 default:
89 printk(BIOS_WARNING, "POST: Unexpected post code "
90 "in previous boot: 0x%02x\n", code);
91#if CONFIG_ELOG
92 elog_add_event_word(ELOG_TYPE_LAST_POST_CODE, code);
Duncan Lauried5686fe2013-06-10 10:21:41 -070093#if CONFIG_CMOS_POST_EXTRA
94 if (extra)
95 elog_add_event_dword(ELOG_TYPE_POST_EXTRA, extra);
96#endif
Duncan Laurie1fc34612012-09-09 19:14:45 -070097#endif
98 }
99}
Duncan Lauried5686fe2013-06-10 10:21:41 -0700100
101#if CONFIG_CMOS_POST_EXTRA
102void post_log_extra(u32 value)
103{
104 spin_lock(&cmos_post_lock);
105
106 switch (cmos_read(CMOS_POST_BANK_OFFSET)) {
107 case CMOS_POST_BANK_0_MAGIC:
108 cmos_write32(CMOS_POST_BANK_0_EXTRA, value);
109 break;
110 case CMOS_POST_BANK_1_MAGIC:
111 cmos_write32(CMOS_POST_BANK_1_EXTRA, value);
112 break;
113 }
114
115 spin_unlock(&cmos_post_lock);
116}
Duncan Laurie8adf7a22013-06-10 10:34:20 -0700117
118void post_log_path(struct device *dev)
119{
120 if (dev) {
121 /* Encode path into lower 3 bytes */
122 u32 path = dev_path_encode(dev);
123 /* Upper byte contains the log type */
124 path |= CMOS_POST_EXTRA_DEV_PATH << 24;
125 post_log_extra(path);
126 }
127}
128
129void post_log_clear(void)
130{
131 post_log_extra(0);
132}
Duncan Lauried5686fe2013-06-10 10:21:41 -0700133#endif /* CONFIG_CMOS_POST_EXTRA */
Duncan Laurie1fc34612012-09-09 19:14:45 -0700134#endif /* !__PRE_RAM__ */
135
Duncan Laurieb6e97b12012-09-09 19:09:56 -0700136static void cmos_post_code(u8 value)
137{
Duncan Lauriee807c342013-06-10 09:53:33 -0700138 spin_lock(&cmos_post_lock);
139
Duncan Laurieb6e97b12012-09-09 19:09:56 -0700140 switch (cmos_read(CMOS_POST_BANK_OFFSET)) {
141 case CMOS_POST_BANK_0_MAGIC:
142 cmos_write(value, CMOS_POST_BANK_0_OFFSET);
143 break;
144 case CMOS_POST_BANK_1_MAGIC:
145 cmos_write(value, CMOS_POST_BANK_1_OFFSET);
146 break;
147 }
Duncan Lauriee807c342013-06-10 09:53:33 -0700148
149 spin_unlock(&cmos_post_lock);
Duncan Laurieb6e97b12012-09-09 19:09:56 -0700150}
151#endif /* CONFIG_CMOS_POST */
152
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000153void post_code(uint8_t value)
154{
Stefan Reinauerd4814bd2011-04-21 20:45:45 +0000155#if !CONFIG_NO_POST
156#if CONFIG_CONSOLE_POST
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000157 print_emerg("POST: 0x");
158 print_emerg_hex8(value);
159 print_emerg("\n");
160#endif
Duncan Laurieb6e97b12012-09-09 19:09:56 -0700161#if CONFIG_CMOS_POST
162 cmos_post_code(value);
163#endif
Idwer Vollering5809a732014-03-11 15:36:21 +0000164#if CONFIG_POST_IO
165 outb(value, CONFIG_POST_IO_PORT);
David Hendricks6b908d02012-11-05 12:34:09 -0800166#endif
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000167#endif
Alexandru Gagniucf88204e2012-08-03 13:20:57 -0500168 mainboard_post(value);
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000169}