blob: 11c631d4dcbb97619e48dadf9c22c163be93f117 [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 Laurie1fc34612012-09-09 19:14:45 -070028#include <elog.h>
Stefan Reinauerabc0c852010-11-22 08:09:50 +000029
30/* Write POST information */
31
Alexandru Gagniucf88204e2012-08-03 13:20:57 -050032/* someday romcc will be gone. */
33#ifndef __ROMCC__
34/* Some mainboards have very nice features beyond just a simple display.
35 * They can override this function.
36 */
37void __attribute__((weak)) mainboard_post(uint8_t value)
38{
39}
40
41#else
42/* This just keeps the number of #ifs to a minimum */
43#define mainboard_post(x)
44#endif
45
Duncan Laurieb6e97b12012-09-09 19:09:56 -070046#if CONFIG_CMOS_POST
Duncan Laurie1fc34612012-09-09 19:14:45 -070047
Duncan Lauriee807c342013-06-10 09:53:33 -070048DECLARE_SPIN_LOCK(cmos_post_lock)
49
Duncan Laurie1fc34612012-09-09 19:14:45 -070050#if !defined(__PRE_RAM__)
51void cmos_post_log(void)
52{
Duncan Lauriee807c342013-06-10 09:53:33 -070053 u8 code = 0;
54
55 spin_lock(&cmos_post_lock);
Duncan Laurie1fc34612012-09-09 19:14:45 -070056
57 /* Get post code from other bank */
58 switch (cmos_read(CMOS_POST_BANK_OFFSET)) {
59 case CMOS_POST_BANK_0_MAGIC:
60 code = cmos_read(CMOS_POST_BANK_1_OFFSET);
61 break;
62 case CMOS_POST_BANK_1_MAGIC:
63 code = cmos_read(CMOS_POST_BANK_0_OFFSET);
64 break;
Duncan Laurie1fc34612012-09-09 19:14:45 -070065 }
66
Duncan Lauriee807c342013-06-10 09:53:33 -070067 spin_unlock(&cmos_post_lock);
68
Duncan Laurie1fc34612012-09-09 19:14:45 -070069 /* Check last post code in previous boot against normal list */
70 switch (code) {
71 case POST_OS_BOOT:
72 case POST_OS_RESUME:
73 case POST_ENTER_ELF_BOOT:
74 case 0:
75 break;
76 default:
77 printk(BIOS_WARNING, "POST: Unexpected post code "
78 "in previous boot: 0x%02x\n", code);
79#if CONFIG_ELOG
80 elog_add_event_word(ELOG_TYPE_LAST_POST_CODE, code);
81#endif
82 }
83}
84#endif /* !__PRE_RAM__ */
85
Duncan Laurieb6e97b12012-09-09 19:09:56 -070086static void cmos_post_code(u8 value)
87{
Duncan Lauriee807c342013-06-10 09:53:33 -070088 spin_lock(&cmos_post_lock);
89
Duncan Laurieb6e97b12012-09-09 19:09:56 -070090 switch (cmos_read(CMOS_POST_BANK_OFFSET)) {
91 case CMOS_POST_BANK_0_MAGIC:
92 cmos_write(value, CMOS_POST_BANK_0_OFFSET);
93 break;
94 case CMOS_POST_BANK_1_MAGIC:
95 cmos_write(value, CMOS_POST_BANK_1_OFFSET);
96 break;
97 }
Duncan Lauriee807c342013-06-10 09:53:33 -070098
99 spin_unlock(&cmos_post_lock);
Duncan Laurieb6e97b12012-09-09 19:09:56 -0700100}
101#endif /* CONFIG_CMOS_POST */
102
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000103void post_code(uint8_t value)
104{
Stefan Reinauerd4814bd2011-04-21 20:45:45 +0000105#if !CONFIG_NO_POST
106#if CONFIG_CONSOLE_POST
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000107 print_emerg("POST: 0x");
108 print_emerg_hex8(value);
109 print_emerg("\n");
110#endif
Duncan Laurieb6e97b12012-09-09 19:09:56 -0700111#if CONFIG_CMOS_POST
112 cmos_post_code(value);
113#endif
David Hendricks6b908d02012-11-05 12:34:09 -0800114#if CONFIG_IO_POST
115 outb(value, CONFIG_IO_POST_PORT);
116#endif
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000117#endif
Alexandru Gagniucf88204e2012-08-03 13:20:57 -0500118 mainboard_post(value);
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000119}