Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | 54309d6 | 2009-01-20 22:53:10 +0000 | [diff] [blame] | 4 | * Copyright (C) 2008-2009 coresystems GmbH |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 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 | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 17 | #include <types.h> |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 18 | #include <console/console.h> |
| 19 | #include <cpu/x86/cache.h> |
| 20 | #include <cpu/x86/smm.h> |
Stefan Reinauer | 7a3d095 | 2010-01-17 13:49:07 +0000 | [diff] [blame] | 21 | #include <device/pci_def.h> |
Sven Schnelle | 811787a | 2011-06-29 15:05:28 +0200 | [diff] [blame] | 22 | #include <pc80/mc146818rtc.h> |
Arthur Heymans | 31312b2 | 2018-04-10 12:56:19 +0200 | [diff] [blame] | 23 | #include <southbridge/intel/common/pmutil.h> |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 24 | #include "i82801gx.h" |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 25 | |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 26 | /* I945 */ |
| 27 | #define SMRAM 0x9d |
| 28 | #define D_OPEN (1 << 6) |
| 29 | #define D_CLS (1 << 5) |
| 30 | #define D_LCK (1 << 4) |
| 31 | #define G_SMRANE (1 << 3) |
| 32 | #define C_BASE_SEG ((0 << 2) | (1 << 1) | (0 << 0)) |
| 33 | |
stepan | 836ae29 | 2010-12-08 05:42:47 +0000 | [diff] [blame] | 34 | #include "nvs.h" |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 35 | |
| 36 | /* While we read PMBASE dynamically in case it changed, let's |
| 37 | * initialize it with a sane value |
| 38 | */ |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 39 | u16 pmbase = DEFAULT_PMBASE; |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 40 | u8 smm_initialized = 0; |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 41 | |
| 42 | /* GNVS needs to be updated by an 0xEA PM Trap (B2) after it has been located |
| 43 | * by coreboot. |
| 44 | */ |
| 45 | global_nvs_t *gnvs = (global_nvs_t *)0x0; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 46 | |
Arthur Heymans | 31312b2 | 2018-04-10 12:56:19 +0200 | [diff] [blame] | 47 | void southbridge_update_gnvs(u8 apm_cnt, int *smm_done) |
Kyösti Mälkki | b85a87b | 2014-12-29 11:32:27 +0200 | [diff] [blame] | 48 | { |
Arthur Heymans | 31312b2 | 2018-04-10 12:56:19 +0200 | [diff] [blame] | 49 | gnvs = *(global_nvs_t **)0x500; |
| 50 | *smm_done = 1; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Stefan Reinauer | 3b38745 | 2009-03-06 19:52:36 +0000 | [diff] [blame] | 53 | int southbridge_io_trap_handler(int smif) |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 54 | { |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 55 | switch (smif) { |
| 56 | case 0x32: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 57 | printk(BIOS_DEBUG, "OS Init\n"); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 58 | /* gnvs->smif: |
| 59 | * On success, the IO Trap Handler returns 0 |
| 60 | * On failure, the IO Trap Handler returns a value != 0 |
| 61 | */ |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 62 | gnvs->smif = 0; |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 63 | return 1; /* IO trap handled */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 66 | /* Not handled */ |
| 67 | return 0; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Arthur Heymans | 31312b2 | 2018-04-10 12:56:19 +0200 | [diff] [blame] | 70 | void southbridge_smi_monitor(void) |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 71 | { |
| 72 | #define IOTRAP(x) (trap_sts & (1 << x)) |
| 73 | u32 trap_sts, trap_cycle; |
| 74 | u32 data, mask = 0; |
| 75 | int i; |
| 76 | |
| 77 | trap_sts = RCBA32(0x1e00); // TRSR - Trap Status Register |
| 78 | RCBA32(0x1e00) = trap_sts; // Clear trap(s) in TRSR |
| 79 | |
| 80 | trap_cycle = RCBA32(0x1e10); |
Arthur Heymans | 3f111b0 | 2017-03-09 12:02:52 +0100 | [diff] [blame] | 81 | for (i = 16; i < 20; i++) { |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 82 | if (trap_cycle & (1 << i)) |
| 83 | mask |= (0xff << ((i - 16) << 2)); |
| 84 | } |
| 85 | |
| 86 | |
| 87 | /* IOTRAP(3) SMI function call */ |
| 88 | if (IOTRAP(3)) { |
| 89 | if (gnvs && gnvs->smif) |
| 90 | io_trap_handler(gnvs->smif); // call function smif |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | /* IOTRAP(2) currently unused |
| 95 | * IOTRAP(1) currently unused */ |
| 96 | |
Vladimir Serbinenko | a485705 | 2014-08-31 01:09:12 +0200 | [diff] [blame] | 97 | /* IOTRAP(0) SMIC: currently unused */ |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 98 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 99 | printk(BIOS_DEBUG, " trapped io address = 0x%x\n", trap_cycle & 0xfffc); |
Arthur Heymans | 3f111b0 | 2017-03-09 12:02:52 +0100 | [diff] [blame] | 100 | for (i = 0; i < 4; i++) |
| 101 | if (IOTRAP(i)) |
| 102 | printk(BIOS_DEBUG, " TRAP = %d\n", i); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 103 | printk(BIOS_DEBUG, " AHBE = %x\n", (trap_cycle >> 16) & 0xf); |
| 104 | printk(BIOS_DEBUG, " MASK = 0x%08x\n", mask); |
| 105 | printk(BIOS_DEBUG, " read/write: %s\n", (trap_cycle & (1 << 24)) ? "read" : "write"); |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 106 | |
| 107 | if (!(trap_cycle & (1 << 24))) { |
| 108 | /* Write Cycle */ |
| 109 | data = RCBA32(0x1e18); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 110 | printk(BIOS_DEBUG, " iotrap written data = 0x%08x\n", data); |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 111 | } |
| 112 | #undef IOTRAP |
| 113 | } |
| 114 | |
Arthur Heymans | 31312b2 | 2018-04-10 12:56:19 +0200 | [diff] [blame] | 115 | void southbridge_finalize_all(void) |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 116 | { |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 117 | } |