blob: 64aa2a5513359801351a98049b49d6f6b9cd7712 [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 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; version 2 of
7 * the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Stefan Reinauerabc0c852010-11-22 08:09:50 +000013 */
14
Kyösti Mälkki3ee8b752019-03-03 00:35:15 +020015#include <stdint.h>
Edward O'Callaghan0ae068e2014-06-21 21:42:25 +100016#include <elog.h>
Stefan Reinauerabc0c852010-11-22 08:09:50 +000017#include <console/console.h>
Edward O'Callaghan0ae068e2014-06-21 21:42:25 +100018#include <device/device.h>
Duncan Laurieb6e97b12012-09-09 19:09:56 -070019#include <pc80/mc146818rtc.h>
Duncan Lauriee807c342013-06-10 09:53:33 -070020#include <smp/spinlock.h>
Julius Wernercd49cce2019-03-05 16:53:33 -080021#if CONFIG(POST_IO)
Kyösti Mälkki3ee8b752019-03-03 00:35:15 +020022#include <arch/io.h>
23#endif
Stefan Reinauerabc0c852010-11-22 08:09:50 +000024
25/* Write POST information */
26
Alexandru Gagniucf88204e2012-08-03 13:20:57 -050027/* someday romcc will be gone. */
28#ifndef __ROMCC__
29/* Some mainboards have very nice features beyond just a simple display.
30 * They can override this function.
31 */
Aaron Durbin64031672018-04-21 14:45:32 -060032void __weak mainboard_post(uint8_t value)
Alexandru Gagniucf88204e2012-08-03 13:20:57 -050033{
34}
35
36#else
37/* This just keeps the number of #ifs to a minimum */
38#define mainboard_post(x)
39#endif
40
Julius Wernercd49cce2019-03-05 16:53:33 -080041#if CONFIG(CMOS_POST)
Duncan Laurie1fc34612012-09-09 19:14:45 -070042
Duncan Lauriee807c342013-06-10 09:53:33 -070043DECLARE_SPIN_LOCK(cmos_post_lock)
44
Duncan Laurie1fc34612012-09-09 19:14:45 -070045void cmos_post_log(void)
46{
Duncan Lauriee807c342013-06-10 09:53:33 -070047 u8 code = 0;
Julius Wernercd49cce2019-03-05 16:53:33 -080048#if CONFIG(CMOS_POST_EXTRA)
Duncan Lauried5686fe2013-06-10 10:21:41 -070049 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);
Julius Wernercd49cce2019-03-05 16:53:33 -080058#if CONFIG(CMOS_POST_EXTRA)
Duncan Lauried5686fe2013-06-10 10:21:41 -070059 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);
Julius Wernercd49cce2019-03-05 16:53:33 -080064#if CONFIG(CMOS_POST_EXTRA)
Duncan Lauried5686fe2013-06-10 10:21:41 -070065 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);
Jett Rinkba44a272019-05-21 13:48:04 -060082#if CONFIG(ELOG) && (ENV_RAMSTAGE || CONFIG(ELOG_PRERAM))
Duncan Laurie1fc34612012-09-09 19:14:45 -070083 elog_add_event_word(ELOG_TYPE_LAST_POST_CODE, code);
Julius Wernercd49cce2019-03-05 16:53:33 -080084#if CONFIG(CMOS_POST_EXTRA)
Duncan Lauried5686fe2013-06-10 10:21:41 -070085 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
Julius Wernercd49cce2019-03-05 16:53:33 -080092#if CONFIG(CMOS_POST_EXTRA)
Duncan Lauried5686fe2013-06-10 10:21:41 -070093void 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
Subrata Banik564547f2018-05-02 10:27:36 +0530109void post_log_path(const struct device *dev)
Duncan Laurie8adf7a22013-06-10 10:34:20 -0700110{
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
Duncan Laurieb6e97b12012-09-09 19:09:56 -0700126static void cmos_post_code(u8 value)
127{
Duncan Lauriee807c342013-06-10 09:53:33 -0700128 spin_lock(&cmos_post_lock);
129
Duncan Laurieb6e97b12012-09-09 19:09:56 -0700130 switch (cmos_read(CMOS_POST_BANK_OFFSET)) {
131 case CMOS_POST_BANK_0_MAGIC:
132 cmos_write(value, CMOS_POST_BANK_0_OFFSET);
133 break;
134 case CMOS_POST_BANK_1_MAGIC:
135 cmos_write(value, CMOS_POST_BANK_1_OFFSET);
136 break;
137 }
Duncan Lauriee807c342013-06-10 09:53:33 -0700138
139 spin_unlock(&cmos_post_lock);
Duncan Laurieb6e97b12012-09-09 19:09:56 -0700140}
141#endif /* CONFIG_CMOS_POST */
142
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000143void post_code(uint8_t value)
144{
Julius Wernercd49cce2019-03-05 16:53:33 -0800145#if !CONFIG(NO_POST)
146#if CONFIG(CONSOLE_POST)
Stefan Reinauerd6865222015-01-05 13:12:38 -0800147 printk(BIOS_EMERG, "POST: 0x%02x\n", value);
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000148#endif
Julius Wernercd49cce2019-03-05 16:53:33 -0800149#if CONFIG(CMOS_POST)
Duncan Laurieb6e97b12012-09-09 19:09:56 -0700150 cmos_post_code(value);
151#endif
Julius Wernercd49cce2019-03-05 16:53:33 -0800152#if CONFIG(POST_IO)
Idwer Vollering5809a732014-03-11 15:36:21 +0000153 outb(value, CONFIG_POST_IO_PORT);
David Hendricks6b908d02012-11-05 12:34:09 -0800154#endif
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000155#endif
Alexandru Gagniucf88204e2012-08-03 13:20:57 -0500156 mainboard_post(value);
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000157}