blob: 969c7c703f5db1443ff950886d64432e24d6ed61 [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>
Aaron Durbin64031672018-04-21 14:45:32 -060019#include <compiler.h>
Stefan Reinauerabc0c852010-11-22 08:09:50 +000020#include <console/console.h>
Edward O'Callaghan0ae068e2014-06-21 21:42:25 +100021#include <device/device.h>
Duncan Laurieb6e97b12012-09-09 19:09:56 -070022#include <pc80/mc146818rtc.h>
Duncan Lauriee807c342013-06-10 09:53:33 -070023#include <smp/spinlock.h>
Aaron Durbin9acd39d2016-05-24 14:47:10 -050024#include <rules.h>
Stefan Reinauerabc0c852010-11-22 08:09:50 +000025
26/* Write POST information */
27
Alexandru Gagniucf88204e2012-08-03 13:20:57 -050028/* someday romcc will be gone. */
29#ifndef __ROMCC__
30/* Some mainboards have very nice features beyond just a simple display.
31 * They can override this function.
32 */
Aaron Durbin64031672018-04-21 14:45:32 -060033void __weak mainboard_post(uint8_t value)
Alexandru Gagniucf88204e2012-08-03 13:20:57 -050034{
35}
36
37#else
38/* This just keeps the number of #ifs to a minimum */
39#define mainboard_post(x)
40#endif
41
Martin Roth53de6cd2017-06-09 09:27:08 -060042#if IS_ENABLED(CONFIG_CMOS_POST)
Duncan Laurie1fc34612012-09-09 19:14:45 -070043
Duncan Lauriee807c342013-06-10 09:53:33 -070044DECLARE_SPIN_LOCK(cmos_post_lock)
45
Aaron Durbin9acd39d2016-05-24 14:47:10 -050046#if ENV_RAMSTAGE
Duncan Laurie1fc34612012-09-09 19:14:45 -070047void cmos_post_log(void)
48{
Duncan Lauriee807c342013-06-10 09:53:33 -070049 u8 code = 0;
Martin Roth53de6cd2017-06-09 09:27:08 -060050#if IS_ENABLED(CONFIG_CMOS_POST_EXTRA)
Duncan Lauried5686fe2013-06-10 10:21:41 -070051 u32 extra = 0;
52#endif
Duncan Lauriee807c342013-06-10 09:53:33 -070053
54 spin_lock(&cmos_post_lock);
Duncan Laurie1fc34612012-09-09 19:14:45 -070055
56 /* Get post code from other bank */
57 switch (cmos_read(CMOS_POST_BANK_OFFSET)) {
58 case CMOS_POST_BANK_0_MAGIC:
59 code = cmos_read(CMOS_POST_BANK_1_OFFSET);
Martin Roth53de6cd2017-06-09 09:27:08 -060060#if IS_ENABLED(CONFIG_CMOS_POST_EXTRA)
Duncan Lauried5686fe2013-06-10 10:21:41 -070061 extra = cmos_read32(CMOS_POST_BANK_1_EXTRA);
62#endif
Duncan Laurie1fc34612012-09-09 19:14:45 -070063 break;
64 case CMOS_POST_BANK_1_MAGIC:
65 code = cmos_read(CMOS_POST_BANK_0_OFFSET);
Martin Roth53de6cd2017-06-09 09:27:08 -060066#if IS_ENABLED(CONFIG_CMOS_POST_EXTRA)
Duncan Lauried5686fe2013-06-10 10:21:41 -070067 extra = cmos_read32(CMOS_POST_BANK_0_EXTRA);
68#endif
Duncan Laurie1fc34612012-09-09 19:14:45 -070069 break;
Duncan Laurie1fc34612012-09-09 19:14:45 -070070 }
71
Duncan Lauriee807c342013-06-10 09:53:33 -070072 spin_unlock(&cmos_post_lock);
73
Duncan Laurie1fc34612012-09-09 19:14:45 -070074 /* Check last post code in previous boot against normal list */
75 switch (code) {
76 case POST_OS_BOOT:
77 case POST_OS_RESUME:
78 case POST_ENTER_ELF_BOOT:
79 case 0:
80 break;
81 default:
82 printk(BIOS_WARNING, "POST: Unexpected post code "
83 "in previous boot: 0x%02x\n", code);
Martin Roth53de6cd2017-06-09 09:27:08 -060084#if IS_ENABLED(CONFIG_ELOG)
Duncan Laurie1fc34612012-09-09 19:14:45 -070085 elog_add_event_word(ELOG_TYPE_LAST_POST_CODE, code);
Martin Roth53de6cd2017-06-09 09:27:08 -060086#if IS_ENABLED(CONFIG_CMOS_POST_EXTRA)
Duncan Lauried5686fe2013-06-10 10:21:41 -070087 if (extra)
88 elog_add_event_dword(ELOG_TYPE_POST_EXTRA, extra);
89#endif
Duncan Laurie1fc34612012-09-09 19:14:45 -070090#endif
91 }
92}
Duncan Lauried5686fe2013-06-10 10:21:41 -070093
Martin Roth53de6cd2017-06-09 09:27:08 -060094#if IS_ENABLED(CONFIG_CMOS_POST_EXTRA)
Duncan Lauried5686fe2013-06-10 10:21:41 -070095void post_log_extra(u32 value)
96{
97 spin_lock(&cmos_post_lock);
98
99 switch (cmos_read(CMOS_POST_BANK_OFFSET)) {
100 case CMOS_POST_BANK_0_MAGIC:
101 cmos_write32(CMOS_POST_BANK_0_EXTRA, value);
102 break;
103 case CMOS_POST_BANK_1_MAGIC:
104 cmos_write32(CMOS_POST_BANK_1_EXTRA, value);
105 break;
106 }
107
108 spin_unlock(&cmos_post_lock);
109}
Duncan Laurie8adf7a22013-06-10 10:34:20 -0700110
Subrata Banik564547f2018-05-02 10:27:36 +0530111void post_log_path(const struct device *dev)
Duncan Laurie8adf7a22013-06-10 10:34:20 -0700112{
113 if (dev) {
114 /* Encode path into lower 3 bytes */
115 u32 path = dev_path_encode(dev);
116 /* Upper byte contains the log type */
117 path |= CMOS_POST_EXTRA_DEV_PATH << 24;
118 post_log_extra(path);
119 }
120}
121
122void post_log_clear(void)
123{
124 post_log_extra(0);
125}
Duncan Lauried5686fe2013-06-10 10:21:41 -0700126#endif /* CONFIG_CMOS_POST_EXTRA */
Aaron Durbin9acd39d2016-05-24 14:47:10 -0500127#endif /* ENV_RAMSTAGE */
Duncan Laurie1fc34612012-09-09 19:14:45 -0700128
Duncan Laurieb6e97b12012-09-09 19:09:56 -0700129static void cmos_post_code(u8 value)
130{
Duncan Lauriee807c342013-06-10 09:53:33 -0700131 spin_lock(&cmos_post_lock);
132
Duncan Laurieb6e97b12012-09-09 19:09:56 -0700133 switch (cmos_read(CMOS_POST_BANK_OFFSET)) {
134 case CMOS_POST_BANK_0_MAGIC:
135 cmos_write(value, CMOS_POST_BANK_0_OFFSET);
136 break;
137 case CMOS_POST_BANK_1_MAGIC:
138 cmos_write(value, CMOS_POST_BANK_1_OFFSET);
139 break;
140 }
Duncan Lauriee807c342013-06-10 09:53:33 -0700141
142 spin_unlock(&cmos_post_lock);
Duncan Laurieb6e97b12012-09-09 19:09:56 -0700143}
144#endif /* CONFIG_CMOS_POST */
145
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000146void post_code(uint8_t value)
147{
Martin Roth53de6cd2017-06-09 09:27:08 -0600148#if !IS_ENABLED(CONFIG_NO_POST)
149#if IS_ENABLED(CONFIG_CONSOLE_POST)
Stefan Reinauerd6865222015-01-05 13:12:38 -0800150 printk(BIOS_EMERG, "POST: 0x%02x\n", value);
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000151#endif
Martin Roth53de6cd2017-06-09 09:27:08 -0600152#if IS_ENABLED(CONFIG_CMOS_POST)
Duncan Laurieb6e97b12012-09-09 19:09:56 -0700153 cmos_post_code(value);
154#endif
Martin Roth53de6cd2017-06-09 09:27:08 -0600155#if IS_ENABLED(CONFIG_POST_IO)
Idwer Vollering5809a732014-03-11 15:36:21 +0000156 outb(value, CONFIG_POST_IO_PORT);
David Hendricks6b908d02012-11-05 12:34:09 -0800157#endif
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000158#endif
Alexandru Gagniucf88204e2012-08-03 13:20:57 -0500159 mainboard_post(value);
Stefan Reinauerabc0c852010-11-22 08:09:50 +0000160}