blob: b43bd0931bb0ebcdeba4d901c524bcb430784d33 [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.
Stefan Reinauerabc0c852010-11-22 08:09:50 +000015 */
16
17#include <arch/io.h>
Edward O'Callaghan0ae068e2014-06-21 21:42:25 +100018#include <elog.h>
Stefan Reinauerabc0c852010-11-22 08:09:50 +000019#include <console/console.h>
Edward O'Callaghan0ae068e2014-06-21 21:42:25 +100020#include <device/device.h>
Duncan Laurieb6e97b12012-09-09 19:09:56 -070021#include <pc80/mc146818rtc.h>
Duncan Lauriee807c342013-06-10 09:53:33 -070022#include <smp/spinlock.h>
Stefan Reinauerabc0c852010-11-22 08:09:50 +000023
24/* Write POST information */
25
Alexandru Gagniucf88204e2012-08-03 13:20:57 -050026/* someday romcc will be gone. */
27#ifndef __ROMCC__
28/* Some mainboards have very nice features beyond just a simple display.
29 * They can override this function.
30 */
31void __attribute__((weak)) mainboard_post(uint8_t value)
32{
33}
34
35#else
36/* This just keeps the number of #ifs to a minimum */
37#define mainboard_post(x)
38#endif
39
Duncan Laurieb6e97b12012-09-09 19:09:56 -070040#if CONFIG_CMOS_POST
Duncan Laurie1fc34612012-09-09 19:14:45 -070041
Duncan Lauriee807c342013-06-10 09:53:33 -070042DECLARE_SPIN_LOCK(cmos_post_lock)
43
Duncan Laurie1fc34612012-09-09 19:14:45 -070044#if !defined(__PRE_RAM__)
45void cmos_post_log(void)
46{
Duncan Lauriee807c342013-06-10 09:53:33 -070047 u8 code = 0;
Duncan Lauried5686fe2013-06-10 10:21:41 -070048#if CONFIG_CMOS_POST_EXTRA
49 u32 extra = 0;
50#endif
Duncan Lauriee807c342013-06-10 09:53:33 -070051
52 spin_lock(&cmos_post_lock);
Duncan Laurie1fc34612012-09-09 19:14:45 -070053
54 /* Get post code from other bank */
55 switch (cmos_read(CMOS_POST_BANK_OFFSET)) {
56 case CMOS_POST_BANK_0_MAGIC:
57 code = cmos_read(CMOS_POST_BANK_1_OFFSET);
Duncan Lauried5686fe2013-06-10 10:21:41 -070058#if CONFIG_CMOS_POST_EXTRA
59 extra = cmos_read32(CMOS_POST_BANK_1_EXTRA);
60#endif
Duncan Laurie1fc34612012-09-09 19:14:45 -070061 break;
62 case CMOS_POST_BANK_1_MAGIC:
63 code = cmos_read(CMOS_POST_BANK_0_OFFSET);
Duncan Lauried5686fe2013-06-10 10:21:41 -070064#if CONFIG_CMOS_POST_EXTRA
65 extra = cmos_read32(CMOS_POST_BANK_0_EXTRA);
66#endif
Duncan Laurie1fc34612012-09-09 19:14:45 -070067 break;
Duncan Laurie1fc34612012-09-09 19:14:45 -070068 }
69
Duncan Lauriee807c342013-06-10 09:53:33 -070070 spin_unlock(&cmos_post_lock);
71
Duncan Laurie1fc34612012-09-09 19:14:45 -070072 /* Check last post code in previous boot against normal list */
73 switch (code) {
74 case POST_OS_BOOT:
75 case POST_OS_RESUME:
76 case POST_ENTER_ELF_BOOT:
77 case 0:
78 break;
79 default:
80 printk(BIOS_WARNING, "POST: Unexpected post code "
81 "in previous boot: 0x%02x\n", code);
82#if CONFIG_ELOG
83 elog_add_event_word(ELOG_TYPE_LAST_POST_CODE, code);
Duncan Lauried5686fe2013-06-10 10:21:41 -070084#if CONFIG_CMOS_POST_EXTRA
85 if (extra)
86 elog_add_event_dword(ELOG_TYPE_POST_EXTRA, extra);
87#endif
Duncan Laurie1fc34612012-09-09 19:14:45 -070088#endif
89 }
90}
Duncan Lauried5686fe2013-06-10 10:21:41 -070091
92#if CONFIG_CMOS_POST_EXTRA
93void post_log_extra(u32 value)
94{
95 spin_lock(&cmos_post_lock);
96
97 switch (cmos_read(CMOS_POST_BANK_OFFSET)) {
98 case CMOS_POST_BANK_0_MAGIC:
99 cmos_write32(CMOS_POST_BANK_0_EXTRA, value);
100 break;
101 case CMOS_POST_BANK_1_MAGIC:
102 cmos_write32(CMOS_POST_BANK_1_EXTRA, value);
103 break;
104 }
105
106 spin_unlock(&cmos_post_lock);
107}
Duncan Laurie8adf7a22013-06-10 10:34:20 -0700108
109void post_log_path(struct device *dev)
110{
111 if (dev) {
112 /* Encode path into lower 3 bytes */
113 u32 path = dev_path_encode(dev);
114 /* Upper byte contains the log type */
115 path |= CMOS_POST_EXTRA_DEV_PATH << 24;
116 post_log_extra(path);
117 }
118}
119
120void post_log_clear(void)
121{
122 post_log_extra(0);
123}
Duncan Lauried5686fe2013-06-10 10:21:41 -0700124#endif /* CONFIG_CMOS_POST_EXTRA */
Duncan Laurie1fc34612012-09-09 19:14:45 -0700125#endif /* !__PRE_RAM__ */
126
Duncan Laurieb6e97b12012-09-09 19:09:56 -0700127static void cmos_post_code(u8 value)
128{
Duncan Lauriee807c342013-06-10 09:53:33 -0700129 spin_lock(&cmos_post_lock);
130
Duncan Laurieb6e97b12012-09-09 19:09:56 -0700131 switch (cmos_read(CMOS_POST_BANK_OFFSET)) {
132 case CMOS_POST_BANK_0_MAGIC:
133 cmos_write(value, CMOS_POST_BANK_0_OFFSET);
134 break;
135 case CMOS_POST_BANK_1_MAGIC:
136 cmos_write(value, CMOS_POST_BANK_1_OFFSET);
137 break;
138 }
Duncan Lauriee807c342013-06-10 09:53:33 -0700139
140 spin_unlock(&cmos_post_lock);
Duncan Laurieb6e97b12012-09-09 19:09:56 -0700141}
142#endif /* CONFIG_CMOS_POST */
143
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000144void post_code(uint8_t value)
145{
Stefan Reinauerd4814bd2011-04-21 20:45:45 +0000146#if !CONFIG_NO_POST
147#if CONFIG_CONSOLE_POST
Stefan Reinauerd6865222015-01-05 13:12:38 -0800148 printk(BIOS_EMERG, "POST: 0x%02x\n", value);
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000149#endif
Duncan Laurieb6e97b12012-09-09 19:09:56 -0700150#if CONFIG_CMOS_POST
151 cmos_post_code(value);
152#endif
Idwer Vollering5809a732014-03-11 15:36:21 +0000153#if CONFIG_POST_IO
154 outb(value, CONFIG_POST_IO_PORT);
David Hendricks6b908d02012-11-05 12:34:09 -0800155#endif
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000156#endif
Alexandru Gagniucf88204e2012-08-03 13:20:57 -0500157 mainboard_post(value);
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000158}