Stefan Reinauer | abc0c85 | 2010-11-22 08:09:50 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 3 | * |
Stefan Reinauer | abc0c85 | 2010-11-22 08:09:50 +0000 | [diff] [blame] | 4 | * 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 Reinauer | abc0c85 | 2010-11-22 08:09:50 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <arch/io.h> |
Edward O'Callaghan | 0ae068e | 2014-06-21 21:42:25 +1000 | [diff] [blame] | 18 | #include <elog.h> |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 19 | #include <compiler.h> |
Stefan Reinauer | abc0c85 | 2010-11-22 08:09:50 +0000 | [diff] [blame] | 20 | #include <console/console.h> |
Edward O'Callaghan | 0ae068e | 2014-06-21 21:42:25 +1000 | [diff] [blame] | 21 | #include <device/device.h> |
Duncan Laurie | b6e97b1 | 2012-09-09 19:09:56 -0700 | [diff] [blame] | 22 | #include <pc80/mc146818rtc.h> |
Duncan Laurie | e807c34 | 2013-06-10 09:53:33 -0700 | [diff] [blame] | 23 | #include <smp/spinlock.h> |
Aaron Durbin | 9acd39d | 2016-05-24 14:47:10 -0500 | [diff] [blame] | 24 | #include <rules.h> |
Stefan Reinauer | abc0c85 | 2010-11-22 08:09:50 +0000 | [diff] [blame] | 25 | |
| 26 | /* Write POST information */ |
| 27 | |
Alexandru Gagniuc | f88204e | 2012-08-03 13:20:57 -0500 | [diff] [blame] | 28 | /* 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 Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 33 | void __weak mainboard_post(uint8_t value) |
Alexandru Gagniuc | f88204e | 2012-08-03 13:20:57 -0500 | [diff] [blame] | 34 | { |
| 35 | } |
| 36 | |
| 37 | #else |
| 38 | /* This just keeps the number of #ifs to a minimum */ |
| 39 | #define mainboard_post(x) |
| 40 | #endif |
| 41 | |
Martin Roth | 53de6cd | 2017-06-09 09:27:08 -0600 | [diff] [blame] | 42 | #if IS_ENABLED(CONFIG_CMOS_POST) |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 43 | |
Duncan Laurie | e807c34 | 2013-06-10 09:53:33 -0700 | [diff] [blame] | 44 | DECLARE_SPIN_LOCK(cmos_post_lock) |
| 45 | |
Aaron Durbin | 9acd39d | 2016-05-24 14:47:10 -0500 | [diff] [blame] | 46 | #if ENV_RAMSTAGE |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 47 | void cmos_post_log(void) |
| 48 | { |
Duncan Laurie | e807c34 | 2013-06-10 09:53:33 -0700 | [diff] [blame] | 49 | u8 code = 0; |
Martin Roth | 53de6cd | 2017-06-09 09:27:08 -0600 | [diff] [blame] | 50 | #if IS_ENABLED(CONFIG_CMOS_POST_EXTRA) |
Duncan Laurie | d5686fe | 2013-06-10 10:21:41 -0700 | [diff] [blame] | 51 | u32 extra = 0; |
| 52 | #endif |
Duncan Laurie | e807c34 | 2013-06-10 09:53:33 -0700 | [diff] [blame] | 53 | |
| 54 | spin_lock(&cmos_post_lock); |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 55 | |
| 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 Roth | 53de6cd | 2017-06-09 09:27:08 -0600 | [diff] [blame] | 60 | #if IS_ENABLED(CONFIG_CMOS_POST_EXTRA) |
Duncan Laurie | d5686fe | 2013-06-10 10:21:41 -0700 | [diff] [blame] | 61 | extra = cmos_read32(CMOS_POST_BANK_1_EXTRA); |
| 62 | #endif |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 63 | break; |
| 64 | case CMOS_POST_BANK_1_MAGIC: |
| 65 | code = cmos_read(CMOS_POST_BANK_0_OFFSET); |
Martin Roth | 53de6cd | 2017-06-09 09:27:08 -0600 | [diff] [blame] | 66 | #if IS_ENABLED(CONFIG_CMOS_POST_EXTRA) |
Duncan Laurie | d5686fe | 2013-06-10 10:21:41 -0700 | [diff] [blame] | 67 | extra = cmos_read32(CMOS_POST_BANK_0_EXTRA); |
| 68 | #endif |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 69 | break; |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Duncan Laurie | e807c34 | 2013-06-10 09:53:33 -0700 | [diff] [blame] | 72 | spin_unlock(&cmos_post_lock); |
| 73 | |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 74 | /* 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 Roth | 53de6cd | 2017-06-09 09:27:08 -0600 | [diff] [blame] | 84 | #if IS_ENABLED(CONFIG_ELOG) |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 85 | elog_add_event_word(ELOG_TYPE_LAST_POST_CODE, code); |
Martin Roth | 53de6cd | 2017-06-09 09:27:08 -0600 | [diff] [blame] | 86 | #if IS_ENABLED(CONFIG_CMOS_POST_EXTRA) |
Duncan Laurie | d5686fe | 2013-06-10 10:21:41 -0700 | [diff] [blame] | 87 | if (extra) |
| 88 | elog_add_event_dword(ELOG_TYPE_POST_EXTRA, extra); |
| 89 | #endif |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 90 | #endif |
| 91 | } |
| 92 | } |
Duncan Laurie | d5686fe | 2013-06-10 10:21:41 -0700 | [diff] [blame] | 93 | |
Martin Roth | 53de6cd | 2017-06-09 09:27:08 -0600 | [diff] [blame] | 94 | #if IS_ENABLED(CONFIG_CMOS_POST_EXTRA) |
Duncan Laurie | d5686fe | 2013-06-10 10:21:41 -0700 | [diff] [blame] | 95 | void 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 Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 110 | |
Subrata Banik | 564547f | 2018-05-02 10:27:36 +0530 | [diff] [blame] | 111 | void post_log_path(const struct device *dev) |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 112 | { |
| 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 | |
| 122 | void post_log_clear(void) |
| 123 | { |
| 124 | post_log_extra(0); |
| 125 | } |
Duncan Laurie | d5686fe | 2013-06-10 10:21:41 -0700 | [diff] [blame] | 126 | #endif /* CONFIG_CMOS_POST_EXTRA */ |
Aaron Durbin | 9acd39d | 2016-05-24 14:47:10 -0500 | [diff] [blame] | 127 | #endif /* ENV_RAMSTAGE */ |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 128 | |
Duncan Laurie | b6e97b1 | 2012-09-09 19:09:56 -0700 | [diff] [blame] | 129 | static void cmos_post_code(u8 value) |
| 130 | { |
Duncan Laurie | e807c34 | 2013-06-10 09:53:33 -0700 | [diff] [blame] | 131 | spin_lock(&cmos_post_lock); |
| 132 | |
Duncan Laurie | b6e97b1 | 2012-09-09 19:09:56 -0700 | [diff] [blame] | 133 | 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 Laurie | e807c34 | 2013-06-10 09:53:33 -0700 | [diff] [blame] | 141 | |
| 142 | spin_unlock(&cmos_post_lock); |
Duncan Laurie | b6e97b1 | 2012-09-09 19:09:56 -0700 | [diff] [blame] | 143 | } |
| 144 | #endif /* CONFIG_CMOS_POST */ |
| 145 | |
Stefan Reinauer | abc0c85 | 2010-11-22 08:09:50 +0000 | [diff] [blame] | 146 | void post_code(uint8_t value) |
| 147 | { |
Martin Roth | 53de6cd | 2017-06-09 09:27:08 -0600 | [diff] [blame] | 148 | #if !IS_ENABLED(CONFIG_NO_POST) |
| 149 | #if IS_ENABLED(CONFIG_CONSOLE_POST) |
Stefan Reinauer | d686522 | 2015-01-05 13:12:38 -0800 | [diff] [blame] | 150 | printk(BIOS_EMERG, "POST: 0x%02x\n", value); |
Stefan Reinauer | abc0c85 | 2010-11-22 08:09:50 +0000 | [diff] [blame] | 151 | #endif |
Martin Roth | 53de6cd | 2017-06-09 09:27:08 -0600 | [diff] [blame] | 152 | #if IS_ENABLED(CONFIG_CMOS_POST) |
Duncan Laurie | b6e97b1 | 2012-09-09 19:09:56 -0700 | [diff] [blame] | 153 | cmos_post_code(value); |
| 154 | #endif |
Martin Roth | 53de6cd | 2017-06-09 09:27:08 -0600 | [diff] [blame] | 155 | #if IS_ENABLED(CONFIG_POST_IO) |
Idwer Vollering | 5809a73 | 2014-03-11 15:36:21 +0000 | [diff] [blame] | 156 | outb(value, CONFIG_POST_IO_PORT); |
David Hendricks | 6b908d0 | 2012-11-05 12:34:09 -0800 | [diff] [blame] | 157 | #endif |
Stefan Reinauer | abc0c85 | 2010-11-22 08:09:50 +0000 | [diff] [blame] | 158 | #endif |
Alexandru Gagniuc | f88204e | 2012-08-03 13:20:57 -0500 | [diff] [blame] | 159 | mainboard_post(value); |
Stefan Reinauer | abc0c85 | 2010-11-22 08:09:50 +0000 | [diff] [blame] | 160 | } |