blob: 40f5412a9102603616a580a28c455e4d50d45900 [file] [log] [blame]
Arthur Heymansa0508172018-01-25 11:30:22 +01001/*
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.
15 */
16
17
18#include <device/device.h>
19#include <device/pci.h>
20#include <console/console.h>
21#include <arch/io.h>
Arthur Heymansa0508172018-01-25 11:30:22 +010022#include <cpu/x86/cache.h>
23#include <cpu/x86/smm.h>
24#include <cpu/intel/smm/gen1/smi.h>
Patrick Rudolphed3242e2018-06-29 10:34:37 +020025#include <southbridge/intel/common/pmbase.h>
Arthur Heymansf0a017f2018-12-25 15:26:58 +010026#include <southbridge/intel/common/pmutil.h>
Arthur Heymansa0508172018-01-25 11:30:22 +010027
28#include "pmutil.h"
29
30#define DEBUG_PERIODIC_SMIS 0
31
Arthur Heymansa0508172018-01-25 11:30:22 +010032u16 get_pmbase(void)
33{
Patrick Rudolphed3242e2018-06-29 10:34:37 +020034 return lpc_get_pmbase();
Arthur Heymansa0508172018-01-25 11:30:22 +010035}
36
37void southbridge_smm_init(void)
38{
39 u32 smi_en;
40 u16 pm1_en;
41 u32 gpe0_en;
42
Arthur Heymansf0a017f2018-12-25 15:26:58 +010043 if (IS_ENABLED(CONFIG_ELOG))
Arthur Heymansa0508172018-01-25 11:30:22 +010044 /* Log events from chipset before clearing */
Arthur Heymansf0a017f2018-12-25 15:26:58 +010045 pch_log_state();
Arthur Heymansa0508172018-01-25 11:30:22 +010046
47 printk(BIOS_DEBUG, "Initializing southbridge SMI...");
48
Patrick Rudolphed3242e2018-06-29 10:34:37 +020049 printk(BIOS_SPEW, " ... pmbase = 0x%04x\n", lpc_get_pmbase());
Arthur Heymansa0508172018-01-25 11:30:22 +010050
Patrick Rudolphed3242e2018-06-29 10:34:37 +020051 smi_en = read_pmbase32(SMI_EN);
Arthur Heymansa0508172018-01-25 11:30:22 +010052 if (smi_en & APMC_EN) {
53 printk(BIOS_INFO, "SMI# handler already enabled?\n");
54 return;
55 }
56
57 printk(BIOS_DEBUG, "\n");
58 dump_smi_status(reset_smi_status());
59 dump_pm1_status(reset_pm1_status());
60 dump_gpe0_status(reset_gpe0_status());
61 dump_alt_gp_smi_status(reset_alt_gp_smi_status());
62 dump_tco_status(reset_tco_status());
63
64 /* Disable GPE0 PME_B0 */
Patrick Rudolphed3242e2018-06-29 10:34:37 +020065 gpe0_en = read_pmbase32(GPE0_EN);
Arthur Heymansa0508172018-01-25 11:30:22 +010066 gpe0_en &= ~PME_B0_EN;
Patrick Rudolphed3242e2018-06-29 10:34:37 +020067 write_pmbase32(GPE0_EN, gpe0_en);
Arthur Heymansa0508172018-01-25 11:30:22 +010068
69 pm1_en = 0;
70 pm1_en |= PWRBTN_EN;
71 pm1_en |= GBL_EN;
Patrick Rudolphed3242e2018-06-29 10:34:37 +020072 write_pmbase16(PM1_EN, pm1_en);
Arthur Heymansa0508172018-01-25 11:30:22 +010073
74 /* Enable SMI generation:
75 * - on TCO events
76 * - on APMC writes (io 0xb2)
77 * - on writes to SLP_EN (sleep states)
78 * - on writes to GBL_RLS (bios commands)
79 * No SMIs:
80 * - on microcontroller writes (io 0x62/0x66)
81 */
82
83 smi_en = 0; /* reset SMI enables */
84
85#if 0
86 smi_en |= LEGACY_USB2_EN | LEGACY_USB_EN;
87#endif
88 smi_en |= TCO_EN;
89 smi_en |= APMC_EN;
90#if DEBUG_PERIODIC_SMIS
91 /* Set DEBUG_PERIODIC_SMIS in pch.h to debug using
92 * periodic SMIs.
93 */
94 smi_en |= PERIODIC_EN;
95#endif
96 smi_en |= SLP_SMI_EN;
97#if 0
98 smi_en |= BIOS_EN;
99#endif
100
101 /* The following need to be on for SMIs to happen */
102 smi_en |= EOS | GBL_SMI_EN;
103
Patrick Rudolphed3242e2018-06-29 10:34:37 +0200104 write_pmbase32(SMI_EN, smi_en);
Arthur Heymansa0508172018-01-25 11:30:22 +0100105}
106
107void southbridge_trigger_smi(void)
108{
109 /**
110 * There are several methods of raising a controlled SMI# via
111 * software, among them:
112 * - Writes to io 0xb2 (APMC)
113 * - Writes to the Local Apic ICR with Delivery mode SMI.
114 *
115 * Using the local apic is a bit more tricky. According to
116 * AMD Family 11 Processor BKDG no destination shorthand must be
117 * used.
118 * The whole SMM initialization is quite a bit hardware specific, so
119 * I'm not too worried about the better of the methods at the moment
120 */
121
122 /* raise an SMI interrupt */
123 printk(BIOS_SPEW, " ... raise SMI#\n");
124 outb(0x00, 0xb2);
125}
126
127void southbridge_clear_smi_status(void)
128{
129 /* Clear SMI status */
130 reset_smi_status();
131
132 /* Clear PM1 status */
133 reset_pm1_status();
134
135 /* Set EOS bit so other SMIs can occur. */
136 smi_set_eos();
137}
138
139void smm_setup_structures(void *gnvs, void *tcg, void *smi1)
140{
141 /*
142 * Issue SMI to set the gnvs pointer in SMM.
143 * tcg and smi1 are unused.
144 *
145 * EAX = APM_CNT_GNVS_UPDATE
146 * EBX = gnvs pointer
147 * EDX = APM_CNT
148 */
149 asm volatile (
150 "outb %%al, %%dx\n\t"
151 : /* ignore result */
152 : "a" (APM_CNT_GNVS_UPDATE),
Patrick Rudolph4af2add2018-11-26 15:56:11 +0100153 "b" ((uintptr_t)gnvs),
Arthur Heymansa0508172018-01-25 11:30:22 +0100154 "d" (APM_CNT)
155 );
156}
Arthur Heymansedbf5d92018-01-25 20:03:42 +0100157
158void southbridge_smm_clear_state(void)
159{
160 u32 smi_en;
161
162 if (IS_ENABLED(CONFIG_ELOG))
163 /* Log events from chipset before clearing */
164 pch_log_state();
165
166 printk(BIOS_DEBUG, "Initializing Southbridge SMI...\n");
167 printk(BIOS_SPEW, " ... pmbase = 0x%04x\n", get_pmbase());
168
169 smi_en = inl(get_pmbase() + SMI_EN);
170 if (smi_en & APMC_EN) {
171 printk(BIOS_INFO, "SMI# handler already enabled?\n");
172 return;
173 }
174
175 printk(BIOS_DEBUG, "\n");
176
177 /* Dump and clear status registers */
178 reset_smi_status();
179 reset_pm1_status();
180 reset_tco_status();
181 reset_gpe0_status();
182}