blob: 44ff857d1f62d98ec5b46a63336e63e15ddedc23 [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
Patrick Georgib890a122015-03-26 15:17:45 +010018 * Foundation, Inc.
Stefan Reinauerabc0c852010-11-22 08:09:50 +000019 */
20
21#include <arch/io.h>
Edward O'Callaghan0ae068e2014-06-21 21:42:25 +100022#include <elog.h>
Stefan Reinauerabc0c852010-11-22 08:09:50 +000023#include <console/console.h>
Edward O'Callaghan0ae068e2014-06-21 21:42:25 +100024#include <device/device.h>
Duncan Laurieb6e97b12012-09-09 19:09:56 -070025#include <pc80/mc146818rtc.h>
Duncan Lauriee807c342013-06-10 09:53:33 -070026#include <smp/spinlock.h>
Stefan Reinauerabc0c852010-11-22 08:09:50 +000027
28/* Write POST information */
29
Alexandru Gagniucf88204e2012-08-03 13:20:57 -050030/* someday romcc will be gone. */
31#ifndef __ROMCC__
32/* Some mainboards have very nice features beyond just a simple display.
33 * They can override this function.
34 */
35void __attribute__((weak)) mainboard_post(uint8_t value)
36{
37}
38
39#else
40/* This just keeps the number of #ifs to a minimum */
41#define mainboard_post(x)
42#endif
43
Duncan Laurieb6e97b12012-09-09 19:09:56 -070044#if CONFIG_CMOS_POST
Duncan Laurie1fc34612012-09-09 19:14:45 -070045
Duncan Lauriee807c342013-06-10 09:53:33 -070046DECLARE_SPIN_LOCK(cmos_post_lock)
47
Duncan Laurie1fc34612012-09-09 19:14:45 -070048#if !defined(__PRE_RAM__)
49void cmos_post_log(void)
50{
Duncan Lauriee807c342013-06-10 09:53:33 -070051 u8 code = 0;
Duncan Lauried5686fe2013-06-10 10:21:41 -070052#if CONFIG_CMOS_POST_EXTRA
53 u32 extra = 0;
54#endif
Duncan Lauriee807c342013-06-10 09:53:33 -070055
56 spin_lock(&cmos_post_lock);
Duncan Laurie1fc34612012-09-09 19:14:45 -070057
58 /* Get post code from other bank */
59 switch (cmos_read(CMOS_POST_BANK_OFFSET)) {
60 case CMOS_POST_BANK_0_MAGIC:
61 code = cmos_read(CMOS_POST_BANK_1_OFFSET);
Duncan Lauried5686fe2013-06-10 10:21:41 -070062#if CONFIG_CMOS_POST_EXTRA
63 extra = cmos_read32(CMOS_POST_BANK_1_EXTRA);
64#endif
Duncan Laurie1fc34612012-09-09 19:14:45 -070065 break;
66 case CMOS_POST_BANK_1_MAGIC:
67 code = cmos_read(CMOS_POST_BANK_0_OFFSET);
Duncan Lauried5686fe2013-06-10 10:21:41 -070068#if CONFIG_CMOS_POST_EXTRA
69 extra = cmos_read32(CMOS_POST_BANK_0_EXTRA);
70#endif
Duncan Laurie1fc34612012-09-09 19:14:45 -070071 break;
Duncan Laurie1fc34612012-09-09 19:14:45 -070072 }
73
Duncan Lauriee807c342013-06-10 09:53:33 -070074 spin_unlock(&cmos_post_lock);
75
Duncan Laurie1fc34612012-09-09 19:14:45 -070076 /* Check last post code in previous boot against normal list */
77 switch (code) {
78 case POST_OS_BOOT:
79 case POST_OS_RESUME:
80 case POST_ENTER_ELF_BOOT:
81 case 0:
82 break;
83 default:
84 printk(BIOS_WARNING, "POST: Unexpected post code "
85 "in previous boot: 0x%02x\n", code);
86#if CONFIG_ELOG
87 elog_add_event_word(ELOG_TYPE_LAST_POST_CODE, code);
Duncan Lauried5686fe2013-06-10 10:21:41 -070088#if CONFIG_CMOS_POST_EXTRA
89 if (extra)
90 elog_add_event_dword(ELOG_TYPE_POST_EXTRA, extra);
91#endif
Duncan Laurie1fc34612012-09-09 19:14:45 -070092#endif
93 }
94}
Duncan Lauried5686fe2013-06-10 10:21:41 -070095
96#if CONFIG_CMOS_POST_EXTRA
97void post_log_extra(u32 value)
98{
99 spin_lock(&cmos_post_lock);
100
101 switch (cmos_read(CMOS_POST_BANK_OFFSET)) {
102 case CMOS_POST_BANK_0_MAGIC:
103 cmos_write32(CMOS_POST_BANK_0_EXTRA, value);
104 break;
105 case CMOS_POST_BANK_1_MAGIC:
106 cmos_write32(CMOS_POST_BANK_1_EXTRA, value);
107 break;
108 }
109
110 spin_unlock(&cmos_post_lock);
111}
Duncan Laurie8adf7a22013-06-10 10:34:20 -0700112
113void post_log_path(struct device *dev)
114{
115 if (dev) {
116 /* Encode path into lower 3 bytes */
117 u32 path = dev_path_encode(dev);
118 /* Upper byte contains the log type */
119 path |= CMOS_POST_EXTRA_DEV_PATH << 24;
120 post_log_extra(path);
121 }
122}
123
124void post_log_clear(void)
125{
126 post_log_extra(0);
127}
Duncan Lauried5686fe2013-06-10 10:21:41 -0700128#endif /* CONFIG_CMOS_POST_EXTRA */
Duncan Laurie1fc34612012-09-09 19:14:45 -0700129#endif /* !__PRE_RAM__ */
130
Duncan Laurieb6e97b12012-09-09 19:09:56 -0700131static void cmos_post_code(u8 value)
132{
Duncan Lauriee807c342013-06-10 09:53:33 -0700133 spin_lock(&cmos_post_lock);
134
Duncan Laurieb6e97b12012-09-09 19:09:56 -0700135 switch (cmos_read(CMOS_POST_BANK_OFFSET)) {
136 case CMOS_POST_BANK_0_MAGIC:
137 cmos_write(value, CMOS_POST_BANK_0_OFFSET);
138 break;
139 case CMOS_POST_BANK_1_MAGIC:
140 cmos_write(value, CMOS_POST_BANK_1_OFFSET);
141 break;
142 }
Duncan Lauriee807c342013-06-10 09:53:33 -0700143
144 spin_unlock(&cmos_post_lock);
Duncan Laurieb6e97b12012-09-09 19:09:56 -0700145}
146#endif /* CONFIG_CMOS_POST */
147
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000148void post_code(uint8_t value)
149{
Stefan Reinauerd4814bd2011-04-21 20:45:45 +0000150#if !CONFIG_NO_POST
151#if CONFIG_CONSOLE_POST
Stefan Reinauerd6865222015-01-05 13:12:38 -0800152 printk(BIOS_EMERG, "POST: 0x%02x\n", value);
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000153#endif
Duncan Laurieb6e97b12012-09-09 19:09:56 -0700154#if CONFIG_CMOS_POST
155 cmos_post_code(value);
156#endif
Idwer Vollering5809a732014-03-11 15:36:21 +0000157#if CONFIG_POST_IO
158 outb(value, CONFIG_POST_IO_PORT);
David Hendricks6b908d02012-11-05 12:34:09 -0800159#endif
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000160#endif
Alexandru Gagniucf88204e2012-08-03 13:20:57 -0500161 mainboard_post(value);
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000162}