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. |
| 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 |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
| 19 | * MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | #include <arch/io.h> |
| 23 | #include <console/console.h> |
David Hendricks | 534c8a0 | 2012-11-26 15:07:39 -0800 | [diff] [blame] | 24 | #if CONFIG_CMOS_POST |
Duncan Laurie | b6e97b1 | 2012-09-09 19:09:56 -0700 | [diff] [blame] | 25 | #include <pc80/mc146818rtc.h> |
Duncan Laurie | e807c34 | 2013-06-10 09:53:33 -0700 | [diff] [blame] | 26 | #include <smp/spinlock.h> |
David Hendricks | 534c8a0 | 2012-11-26 15:07:39 -0800 | [diff] [blame] | 27 | #endif |
Duncan Laurie | d5686fe | 2013-06-10 10:21:41 -0700 | [diff] [blame] | 28 | #if CONFIG_CMOS_POST_EXTRA |
| 29 | #include <device/device.h> |
| 30 | #endif |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 31 | #include <elog.h> |
Stefan Reinauer | abc0c85 | 2010-11-22 08:09:50 +0000 | [diff] [blame] | 32 | |
| 33 | /* Write POST information */ |
| 34 | |
Alexandru Gagniuc | f88204e | 2012-08-03 13:20:57 -0500 | [diff] [blame] | 35 | /* someday romcc will be gone. */ |
| 36 | #ifndef __ROMCC__ |
| 37 | /* Some mainboards have very nice features beyond just a simple display. |
| 38 | * They can override this function. |
| 39 | */ |
| 40 | void __attribute__((weak)) mainboard_post(uint8_t value) |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | #else |
| 45 | /* This just keeps the number of #ifs to a minimum */ |
| 46 | #define mainboard_post(x) |
| 47 | #endif |
| 48 | |
Duncan Laurie | b6e97b1 | 2012-09-09 19:09:56 -0700 | [diff] [blame] | 49 | #if CONFIG_CMOS_POST |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 50 | |
Duncan Laurie | e807c34 | 2013-06-10 09:53:33 -0700 | [diff] [blame] | 51 | DECLARE_SPIN_LOCK(cmos_post_lock) |
| 52 | |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 53 | #if !defined(__PRE_RAM__) |
| 54 | void cmos_post_log(void) |
| 55 | { |
Duncan Laurie | e807c34 | 2013-06-10 09:53:33 -0700 | [diff] [blame] | 56 | u8 code = 0; |
Duncan Laurie | d5686fe | 2013-06-10 10:21:41 -0700 | [diff] [blame] | 57 | #if CONFIG_CMOS_POST_EXTRA |
| 58 | u32 extra = 0; |
| 59 | #endif |
Duncan Laurie | e807c34 | 2013-06-10 09:53:33 -0700 | [diff] [blame] | 60 | |
| 61 | spin_lock(&cmos_post_lock); |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 62 | |
| 63 | /* Get post code from other bank */ |
| 64 | switch (cmos_read(CMOS_POST_BANK_OFFSET)) { |
| 65 | case CMOS_POST_BANK_0_MAGIC: |
| 66 | code = cmos_read(CMOS_POST_BANK_1_OFFSET); |
Duncan Laurie | d5686fe | 2013-06-10 10:21:41 -0700 | [diff] [blame] | 67 | #if CONFIG_CMOS_POST_EXTRA |
| 68 | extra = cmos_read32(CMOS_POST_BANK_1_EXTRA); |
| 69 | #endif |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 70 | break; |
| 71 | case CMOS_POST_BANK_1_MAGIC: |
| 72 | code = cmos_read(CMOS_POST_BANK_0_OFFSET); |
Duncan Laurie | d5686fe | 2013-06-10 10:21:41 -0700 | [diff] [blame] | 73 | #if CONFIG_CMOS_POST_EXTRA |
| 74 | extra = cmos_read32(CMOS_POST_BANK_0_EXTRA); |
| 75 | #endif |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 76 | break; |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Duncan Laurie | e807c34 | 2013-06-10 09:53:33 -0700 | [diff] [blame] | 79 | spin_unlock(&cmos_post_lock); |
| 80 | |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 81 | /* Check last post code in previous boot against normal list */ |
| 82 | switch (code) { |
| 83 | case POST_OS_BOOT: |
| 84 | case POST_OS_RESUME: |
| 85 | case POST_ENTER_ELF_BOOT: |
| 86 | case 0: |
| 87 | break; |
| 88 | default: |
| 89 | printk(BIOS_WARNING, "POST: Unexpected post code " |
| 90 | "in previous boot: 0x%02x\n", code); |
| 91 | #if CONFIG_ELOG |
| 92 | elog_add_event_word(ELOG_TYPE_LAST_POST_CODE, code); |
Duncan Laurie | d5686fe | 2013-06-10 10:21:41 -0700 | [diff] [blame] | 93 | #if CONFIG_CMOS_POST_EXTRA |
| 94 | if (extra) |
| 95 | elog_add_event_dword(ELOG_TYPE_POST_EXTRA, extra); |
| 96 | #endif |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 97 | #endif |
| 98 | } |
| 99 | } |
Duncan Laurie | d5686fe | 2013-06-10 10:21:41 -0700 | [diff] [blame] | 100 | |
| 101 | #if CONFIG_CMOS_POST_EXTRA |
| 102 | void post_log_extra(u32 value) |
| 103 | { |
| 104 | spin_lock(&cmos_post_lock); |
| 105 | |
| 106 | switch (cmos_read(CMOS_POST_BANK_OFFSET)) { |
| 107 | case CMOS_POST_BANK_0_MAGIC: |
| 108 | cmos_write32(CMOS_POST_BANK_0_EXTRA, value); |
| 109 | break; |
| 110 | case CMOS_POST_BANK_1_MAGIC: |
| 111 | cmos_write32(CMOS_POST_BANK_1_EXTRA, value); |
| 112 | break; |
| 113 | } |
| 114 | |
| 115 | spin_unlock(&cmos_post_lock); |
| 116 | } |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 117 | |
| 118 | void post_log_path(struct device *dev) |
| 119 | { |
| 120 | if (dev) { |
| 121 | /* Encode path into lower 3 bytes */ |
| 122 | u32 path = dev_path_encode(dev); |
| 123 | /* Upper byte contains the log type */ |
| 124 | path |= CMOS_POST_EXTRA_DEV_PATH << 24; |
| 125 | post_log_extra(path); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | void post_log_clear(void) |
| 130 | { |
| 131 | post_log_extra(0); |
| 132 | } |
Duncan Laurie | d5686fe | 2013-06-10 10:21:41 -0700 | [diff] [blame] | 133 | #endif /* CONFIG_CMOS_POST_EXTRA */ |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 134 | #endif /* !__PRE_RAM__ */ |
| 135 | |
Duncan Laurie | b6e97b1 | 2012-09-09 19:09:56 -0700 | [diff] [blame] | 136 | static void cmos_post_code(u8 value) |
| 137 | { |
Duncan Laurie | e807c34 | 2013-06-10 09:53:33 -0700 | [diff] [blame] | 138 | spin_lock(&cmos_post_lock); |
| 139 | |
Duncan Laurie | b6e97b1 | 2012-09-09 19:09:56 -0700 | [diff] [blame] | 140 | switch (cmos_read(CMOS_POST_BANK_OFFSET)) { |
| 141 | case CMOS_POST_BANK_0_MAGIC: |
| 142 | cmos_write(value, CMOS_POST_BANK_0_OFFSET); |
| 143 | break; |
| 144 | case CMOS_POST_BANK_1_MAGIC: |
| 145 | cmos_write(value, CMOS_POST_BANK_1_OFFSET); |
| 146 | break; |
| 147 | } |
Duncan Laurie | e807c34 | 2013-06-10 09:53:33 -0700 | [diff] [blame] | 148 | |
| 149 | spin_unlock(&cmos_post_lock); |
Duncan Laurie | b6e97b1 | 2012-09-09 19:09:56 -0700 | [diff] [blame] | 150 | } |
| 151 | #endif /* CONFIG_CMOS_POST */ |
| 152 | |
Stefan Reinauer | abc0c85 | 2010-11-22 08:09:50 +0000 | [diff] [blame] | 153 | void post_code(uint8_t value) |
| 154 | { |
Stefan Reinauer | d4814bd | 2011-04-21 20:45:45 +0000 | [diff] [blame] | 155 | #if !CONFIG_NO_POST |
| 156 | #if CONFIG_CONSOLE_POST |
Stefan Reinauer | abc0c85 | 2010-11-22 08:09:50 +0000 | [diff] [blame] | 157 | print_emerg("POST: 0x"); |
| 158 | print_emerg_hex8(value); |
| 159 | print_emerg("\n"); |
| 160 | #endif |
Duncan Laurie | b6e97b1 | 2012-09-09 19:09:56 -0700 | [diff] [blame] | 161 | #if CONFIG_CMOS_POST |
| 162 | cmos_post_code(value); |
| 163 | #endif |
Idwer Vollering | 5809a73 | 2014-03-11 15:36:21 +0000 | [diff] [blame] | 164 | #if CONFIG_POST_IO |
| 165 | outb(value, CONFIG_POST_IO_PORT); |
David Hendricks | 6b908d0 | 2012-11-05 12:34:09 -0800 | [diff] [blame] | 166 | #endif |
Stefan Reinauer | abc0c85 | 2010-11-22 08:09:50 +0000 | [diff] [blame] | 167 | #endif |
Alexandru Gagniuc | f88204e | 2012-08-03 13:20:57 -0500 | [diff] [blame] | 168 | mainboard_post(value); |
Stefan Reinauer | abc0c85 | 2010-11-22 08:09:50 +0000 | [diff] [blame] | 169 | } |