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 | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 28 | #include <elog.h> |
Stefan Reinauer | abc0c85 | 2010-11-22 08:09:50 +0000 | [diff] [blame] | 29 | |
| 30 | /* Write POST information */ |
| 31 | |
Alexandru Gagniuc | f88204e | 2012-08-03 13:20:57 -0500 | [diff] [blame] | 32 | /* someday romcc will be gone. */ |
| 33 | #ifndef __ROMCC__ |
| 34 | /* Some mainboards have very nice features beyond just a simple display. |
| 35 | * They can override this function. |
| 36 | */ |
| 37 | void __attribute__((weak)) mainboard_post(uint8_t value) |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | #else |
| 42 | /* This just keeps the number of #ifs to a minimum */ |
| 43 | #define mainboard_post(x) |
| 44 | #endif |
| 45 | |
Duncan Laurie | b6e97b1 | 2012-09-09 19:09:56 -0700 | [diff] [blame] | 46 | #if CONFIG_CMOS_POST |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 47 | |
Duncan Laurie | e807c34 | 2013-06-10 09:53:33 -0700 | [diff] [blame^] | 48 | DECLARE_SPIN_LOCK(cmos_post_lock) |
| 49 | |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 50 | #if !defined(__PRE_RAM__) |
| 51 | void cmos_post_log(void) |
| 52 | { |
Duncan Laurie | e807c34 | 2013-06-10 09:53:33 -0700 | [diff] [blame^] | 53 | u8 code = 0; |
| 54 | |
| 55 | spin_lock(&cmos_post_lock); |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 56 | |
| 57 | /* Get post code from other bank */ |
| 58 | switch (cmos_read(CMOS_POST_BANK_OFFSET)) { |
| 59 | case CMOS_POST_BANK_0_MAGIC: |
| 60 | code = cmos_read(CMOS_POST_BANK_1_OFFSET); |
| 61 | break; |
| 62 | case CMOS_POST_BANK_1_MAGIC: |
| 63 | code = cmos_read(CMOS_POST_BANK_0_OFFSET); |
| 64 | break; |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Duncan Laurie | e807c34 | 2013-06-10 09:53:33 -0700 | [diff] [blame^] | 67 | spin_unlock(&cmos_post_lock); |
| 68 | |
Duncan Laurie | 1fc3461 | 2012-09-09 19:14:45 -0700 | [diff] [blame] | 69 | /* Check last post code in previous boot against normal list */ |
| 70 | switch (code) { |
| 71 | case POST_OS_BOOT: |
| 72 | case POST_OS_RESUME: |
| 73 | case POST_ENTER_ELF_BOOT: |
| 74 | case 0: |
| 75 | break; |
| 76 | default: |
| 77 | printk(BIOS_WARNING, "POST: Unexpected post code " |
| 78 | "in previous boot: 0x%02x\n", code); |
| 79 | #if CONFIG_ELOG |
| 80 | elog_add_event_word(ELOG_TYPE_LAST_POST_CODE, code); |
| 81 | #endif |
| 82 | } |
| 83 | } |
| 84 | #endif /* !__PRE_RAM__ */ |
| 85 | |
Duncan Laurie | b6e97b1 | 2012-09-09 19:09:56 -0700 | [diff] [blame] | 86 | static void cmos_post_code(u8 value) |
| 87 | { |
Duncan Laurie | e807c34 | 2013-06-10 09:53:33 -0700 | [diff] [blame^] | 88 | spin_lock(&cmos_post_lock); |
| 89 | |
Duncan Laurie | b6e97b1 | 2012-09-09 19:09:56 -0700 | [diff] [blame] | 90 | switch (cmos_read(CMOS_POST_BANK_OFFSET)) { |
| 91 | case CMOS_POST_BANK_0_MAGIC: |
| 92 | cmos_write(value, CMOS_POST_BANK_0_OFFSET); |
| 93 | break; |
| 94 | case CMOS_POST_BANK_1_MAGIC: |
| 95 | cmos_write(value, CMOS_POST_BANK_1_OFFSET); |
| 96 | break; |
| 97 | } |
Duncan Laurie | e807c34 | 2013-06-10 09:53:33 -0700 | [diff] [blame^] | 98 | |
| 99 | spin_unlock(&cmos_post_lock); |
Duncan Laurie | b6e97b1 | 2012-09-09 19:09:56 -0700 | [diff] [blame] | 100 | } |
| 101 | #endif /* CONFIG_CMOS_POST */ |
| 102 | |
Stefan Reinauer | abc0c85 | 2010-11-22 08:09:50 +0000 | [diff] [blame] | 103 | void post_code(uint8_t value) |
| 104 | { |
Stefan Reinauer | d4814bd | 2011-04-21 20:45:45 +0000 | [diff] [blame] | 105 | #if !CONFIG_NO_POST |
| 106 | #if CONFIG_CONSOLE_POST |
Stefan Reinauer | abc0c85 | 2010-11-22 08:09:50 +0000 | [diff] [blame] | 107 | print_emerg("POST: 0x"); |
| 108 | print_emerg_hex8(value); |
| 109 | print_emerg("\n"); |
| 110 | #endif |
Duncan Laurie | b6e97b1 | 2012-09-09 19:09:56 -0700 | [diff] [blame] | 111 | #if CONFIG_CMOS_POST |
| 112 | cmos_post_code(value); |
| 113 | #endif |
David Hendricks | 6b908d0 | 2012-11-05 12:34:09 -0800 | [diff] [blame] | 114 | #if CONFIG_IO_POST |
| 115 | outb(value, CONFIG_IO_POST_PORT); |
| 116 | #endif |
Stefan Reinauer | abc0c85 | 2010-11-22 08:09:50 +0000 | [diff] [blame] | 117 | #endif |
Alexandru Gagniuc | f88204e | 2012-08-03 13:20:57 -0500 | [diff] [blame] | 118 | mainboard_post(value); |
Stefan Reinauer | abc0c85 | 2010-11-22 08:09:50 +0000 | [diff] [blame] | 119 | } |