blob: 69df2bf68cabfbd202cb200696b8c3d2af19f15f [file] [log] [blame]
Stefan Reinauer8e073822012-04-04 00:07:22 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
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 Reinauer8e073822012-04-04 00:07:22 +020015 */
16
17#include <types.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020018#include <arch/io.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020019#include <console/console.h>
20#include <cpu/x86/cache.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020021#include <device/pci_def.h>
22#include <cpu/x86/smm.h>
Duncan Laurie09209152012-06-23 17:25:29 -070023#include <elog.h>
Patrick Georgi546953c2014-11-29 10:38:17 +010024#include <halt.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020025#include "pch.h"
26
27#include "nvs.h"
28
Duncan Laurie51cb26d2012-06-23 15:22:43 -070029#include <northbridge/intel/sandybridge/sandybridge.h>
Vladimir Serbinenko4141b472015-05-16 13:48:10 +020030#include <southbridge/intel/bd82x6x/me.h>
Patrick Rudolphe8e66f42016-02-06 17:42:42 +010031#include <southbridge/intel/common/gpio.h>
Vladimir Serbinenko4141b472015-05-16 13:48:10 +020032#include <cpu/intel/model_206ax/model_206ax.h>
Arthur Heymansa0508172018-01-25 11:30:22 +010033#include <southbridge/intel/common/pmutil.h>
Tristan Corrick63626b12018-11-30 22:53:50 +130034#include <southbridge/intel/common/finalize.h>
Duncan Laurie51cb26d2012-06-23 15:22:43 -070035
Vladimir Serbinenkoa3e41c02015-05-28 16:04:17 +020036static global_nvs_t *gnvs;
Duncan Laurie7f3d4422012-10-03 19:01:57 -070037global_nvs_t *smm_get_gnvs(void)
38{
39 return gnvs;
40}
Stefan Reinauer8e073822012-04-04 00:07:22 +020041
Stefan Reinauer8e073822012-04-04 00:07:22 +020042int southbridge_io_trap_handler(int smif)
43{
44 switch (smif) {
45 case 0x32:
46 printk(BIOS_DEBUG, "OS Init\n");
47 /* gnvs->smif:
48 * On success, the IO Trap Handler returns 0
49 * On failure, the IO Trap Handler returns a value != 0
50 */
51 gnvs->smif = 0;
52 return 1; /* IO trap handled */
53 }
54
55 /* Not handled */
56 return 0;
57}
58
Vladimir Serbinenko6a7aeb32014-01-05 11:37:32 +010059static void southbridge_gate_memory_reset_real(int offset,
60 u16 use, u16 io, u16 lvl)
61{
62 u32 reg32;
63
64 /* Make sure it is set as GPIO */
65 reg32 = inl(use);
66 if (!(reg32 & (1 << offset))) {
67 reg32 |= (1 << offset);
68 outl(reg32, use);
69 }
70
71 /* Make sure it is set as output */
72 reg32 = inl(io);
73 if (reg32 & (1 << offset)) {
74 reg32 &= ~(1 << offset);
75 outl(reg32, io);
76 }
77
78 /* Drive the output low */
79 reg32 = inl(lvl);
80 reg32 &= ~(1 << offset);
81 outl(reg32, lvl);
82}
83
Stefan Reinauer8e073822012-04-04 00:07:22 +020084/*
85 * Drive GPIO 60 low to gate memory reset in S3.
86 *
87 * Intel reference designs all use GPIO 60 but it is
88 * not a requirement and boards could use a different pin.
89 */
Arthur Heymansa0508172018-01-25 11:30:22 +010090void southbridge_gate_memory_reset(void)
Stefan Reinauer8e073822012-04-04 00:07:22 +020091{
Stefan Reinauer8e073822012-04-04 00:07:22 +020092 u16 gpiobase;
93
Kyösti Mälkkifd98c652013-07-26 08:50:53 +030094 gpiobase = pci_read_config16(PCI_DEV(0, 0x1f, 0), GPIOBASE) & 0xfffc;
Stefan Reinauer8e073822012-04-04 00:07:22 +020095 if (!gpiobase)
96 return;
97
Vladimir Serbinenko6a7aeb32014-01-05 11:37:32 +010098 if (CONFIG_DRAM_RESET_GATE_GPIO >= 32)
99 southbridge_gate_memory_reset_real(CONFIG_DRAM_RESET_GATE_GPIO - 32,
100 gpiobase + GPIO_USE_SEL2,
101 gpiobase + GP_IO_SEL2,
102 gpiobase + GP_LVL2);
103 else
104 southbridge_gate_memory_reset_real(CONFIG_DRAM_RESET_GATE_GPIO,
105 gpiobase + GPIO_USE_SEL,
106 gpiobase + GP_IO_SEL,
107 gpiobase + GP_LVL);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200108}
109
Marc Jonese7ae96f2012-11-13 15:07:45 -0700110static void xhci_sleep(u8 slp_typ)
111{
Marc Jones058d70f2013-02-11 14:39:28 -0700112 u32 reg32, xhci_bar;
113 u16 reg16;
Marc Jonese7ae96f2012-11-13 15:07:45 -0700114
Marc Jones058d70f2013-02-11 14:39:28 -0700115 switch (slp_typ) {
Aaron Durbin340898f2016-07-13 23:22:28 -0500116 case ACPI_S3:
117 case ACPI_S4:
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300118 reg16 = pci_read_config16(PCH_XHCI_DEV, 0x74);
Marc Jones058d70f2013-02-11 14:39:28 -0700119 reg16 &= ~0x03UL;
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300120 pci_write_config32(PCH_XHCI_DEV, 0x74, reg16);
Marc Jones058d70f2013-02-11 14:39:28 -0700121
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300122 reg32 = pci_read_config32(PCH_XHCI_DEV, PCI_COMMAND);
Marc Jones058d70f2013-02-11 14:39:28 -0700123 reg32 |= (PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300124 pci_write_config32(PCH_XHCI_DEV, PCI_COMMAND, reg32);
Marc Jones058d70f2013-02-11 14:39:28 -0700125
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300126 xhci_bar = pci_read_config32(PCH_XHCI_DEV,
Marc Jones058d70f2013-02-11 14:39:28 -0700127 PCI_BASE_ADDRESS_0) & ~0xFUL;
128
129 if ((xhci_bar + 0x4C0) & 1)
130 pch_iobp_update(0xEC000082, ~0UL, (3 << 2));
131 if ((xhci_bar + 0x4D0) & 1)
132 pch_iobp_update(0xEC000182, ~0UL, (3 << 2));
133 if ((xhci_bar + 0x4E0) & 1)
134 pch_iobp_update(0xEC000282, ~0UL, (3 << 2));
135 if ((xhci_bar + 0x4F0) & 1)
136 pch_iobp_update(0xEC000382, ~0UL, (3 << 2));
137
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300138 reg32 = pci_read_config32(PCH_XHCI_DEV, PCI_COMMAND);
Marc Jones058d70f2013-02-11 14:39:28 -0700139 reg32 &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300140 pci_write_config32(PCH_XHCI_DEV, PCI_COMMAND, reg32);
Marc Jones058d70f2013-02-11 14:39:28 -0700141
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300142 reg16 = pci_read_config16(PCH_XHCI_DEV, 0x74);
Marc Jones058d70f2013-02-11 14:39:28 -0700143 reg16 |= 0x03;
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300144 pci_write_config16(PCH_XHCI_DEV, 0x74, reg16);
Marc Jones058d70f2013-02-11 14:39:28 -0700145 break;
146
Aaron Durbin340898f2016-07-13 23:22:28 -0500147 case ACPI_S5:
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300148 reg16 = pci_read_config16(PCH_XHCI_DEV, 0x74);
Marc Jones058d70f2013-02-11 14:39:28 -0700149 reg16 |= ((1 << 8) | 0x03);
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300150 pci_write_config16(PCH_XHCI_DEV, 0x74, reg16);
Marc Jones058d70f2013-02-11 14:39:28 -0700151 break;
Marc Jonese7ae96f2012-11-13 15:07:45 -0700152 }
153}
154
Arthur Heymansa0508172018-01-25 11:30:22 +0100155void southbridge_smi_monitor(void)
Stefan Reinauer8e073822012-04-04 00:07:22 +0200156{
157#define IOTRAP(x) (trap_sts & (1 << x))
158 u32 trap_sts, trap_cycle;
159 u32 data, mask = 0;
160 int i;
161
162 trap_sts = RCBA32(0x1e00); // TRSR - Trap Status Register
163 RCBA32(0x1e00) = trap_sts; // Clear trap(s) in TRSR
164
165 trap_cycle = RCBA32(0x1e10);
166 for (i=16; i<20; i++) {
167 if (trap_cycle & (1 << i))
168 mask |= (0xff << ((i - 16) << 2));
169 }
170
171
172 /* IOTRAP(3) SMI function call */
173 if (IOTRAP(3)) {
174 if (gnvs && gnvs->smif)
175 io_trap_handler(gnvs->smif); // call function smif
176 return;
177 }
178
179 /* IOTRAP(2) currently unused
180 * IOTRAP(1) currently unused */
181
182 /* IOTRAP(0) SMIC */
183 if (IOTRAP(0)) {
184 if (!(trap_cycle & (1 << 24))) { // It's a write
185 printk(BIOS_DEBUG, "SMI1 command\n");
186 data = RCBA32(0x1e18);
187 data &= mask;
188 // if (smi1)
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200189 // southbridge_smi_command(data);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200190 // return;
191 }
192 // Fall through to debug
193 }
194
195 printk(BIOS_DEBUG, " trapped io address = 0x%x\n", trap_cycle & 0xfffc);
Elyes HAOUAS70d79a42016-08-21 18:36:06 +0200196 for (i=0; i < 4; i++) if (IOTRAP(i)) printk(BIOS_DEBUG, " TRAP = %d\n", i);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200197 printk(BIOS_DEBUG, " AHBE = %x\n", (trap_cycle >> 16) & 0xf);
198 printk(BIOS_DEBUG, " MASK = 0x%08x\n", mask);
199 printk(BIOS_DEBUG, " read/write: %s\n", (trap_cycle & (1 << 24)) ? "read" : "write");
200
201 if (!(trap_cycle & (1 << 24))) {
202 /* Write Cycle */
203 data = RCBA32(0x1e18);
204 printk(BIOS_DEBUG, " iotrap written data = 0x%08x\n", data);
205 }
206#undef IOTRAP
207}
208
Arthur Heymansa0508172018-01-25 11:30:22 +0100209void southbridge_smm_xhci_sleep(u8 slp_type)
Stefan Reinauer8e073822012-04-04 00:07:22 +0200210{
Arthur Heymansa0508172018-01-25 11:30:22 +0100211 if (smm_get_gnvs()->xhci)
212 xhci_sleep(slp_type);
213}
Stefan Reinauer8e073822012-04-04 00:07:22 +0200214
Arthur Heymansa0508172018-01-25 11:30:22 +0100215void southbridge_update_gnvs(u8 apm_cnt, int *smm_done)
216{
217 em64t101_smm_state_save_area_t *state =
218 smi_apmc_find_state_save(apm_cnt);
219 if (state) {
220 /* EBX in the state save contains the GNVS pointer */
221 gnvs = (global_nvs_t *)((u32)state->rbx);
222 *smm_done = 1;
223 printk(BIOS_DEBUG, "SMI#: Setting GNVS to %p\n", gnvs);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200224 }
Arthur Heymansa0508172018-01-25 11:30:22 +0100225}
Stefan Reinauer8e073822012-04-04 00:07:22 +0200226
Arthur Heymansa0508172018-01-25 11:30:22 +0100227void southbridge_finalize_all(void)
228{
229 intel_me_finalize_smm();
230 intel_pch_finalize_smm();
231 intel_sandybridge_finalize_smm();
232 intel_model_206ax_finalize_smm();
Stefan Reinauer8e073822012-04-04 00:07:22 +0200233}