blob: 77f395126a9b8c674aabd6c93697594f8019acd4 [file] [log] [blame]
Lee Leahyb0005132015-05-12 18:19:47 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 * Copyright (C) 2014 Google Inc.
Lee Leahy1d14b3e2015-05-12 18:23:27 -07006 * Copyright (C) 2015 Intel Corporation.
Lee Leahyb0005132015-05-12 18:19:47 -07007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Lee Leahyb0005132015-05-12 18:19:47 -070016 */
17
18#include <device/device.h>
19#include <device/pci.h>
20#include <console/console.h>
21#include <arch/io.h>
22#include <cpu/cpu.h>
23#include <cpu/x86/cache.h>
24#include <cpu/x86/smm.h>
25#include <string.h>
26#include <soc/iomap.h>
27#include <soc/pch.h>
28#include <soc/pm.h>
29#include <soc/smm.h>
30
31void southbridge_smm_clear_state(void)
32{
33 u32 smi_en;
34
35 printk(BIOS_DEBUG, "Initializing Southbridge SMI...");
36 printk(BIOS_SPEW, " ... pmbase = 0x%04x\n", ACPI_BASE_ADDRESS);
37
38 smi_en = inl(ACPI_BASE_ADDRESS + SMI_EN);
39 if (smi_en & APMC_EN) {
40 printk(BIOS_INFO, "SMI# handler already enabled?\n");
41 return;
42 }
43
44 printk(BIOS_DEBUG, "\n");
45
46 /* Dump and clear status registers */
47 clear_smi_status();
48 clear_pm1_status();
49 clear_tco_status();
50 clear_gpe_status();
51}
52
53void southbridge_smm_enable_smi(void)
54{
55 printk(BIOS_DEBUG, "Enabling SMIs.\n");
56 /* Configure events */
57 enable_pm1(PWRBTN_EN | GBL_EN);
58 disable_gpe(PME_B0_EN);
59
Lee Leahy1d14b3e2015-05-12 18:23:27 -070060 /*
61 * Enable SMI generation:
Lee Leahyb0005132015-05-12 18:19:47 -070062 * - on APMC writes (io 0xb2)
63 * - on writes to SLP_EN (sleep states)
64 * - on writes to GBL_RLS (bios commands)
65 * No SMIs:
66 * - on microcontroller writes (io 0x62/0x66)
67 * - on TCO events
68 */
69 enable_smi(APMC_EN | SLP_SMI_EN | GBL_SMI_EN | EOS);
70}
71
72void southbridge_trigger_smi(void)
73{
Lee Leahy1d14b3e2015-05-12 18:23:27 -070074 /*
Lee Leahyb0005132015-05-12 18:19:47 -070075 * There are several methods of raising a controlled SMI# via
76 * software, among them:
77 * - Writes to io 0xb2 (APMC)
78 * - Writes to the Local Apic ICR with Delivery mode SMI.
79 *
80 * Using the local apic is a bit more tricky. According to
81 * AMD Family 11 Processor BKDG no destination shorthand must be
82 * used.
83 * The whole SMM initialization is quite a bit hardware specific, so
84 * I'm not too worried about the better of the methods at the moment
85 */
86
87 /* raise an SMI interrupt */
88 printk(BIOS_SPEW, " ... raise SMI#\n");
89 outb(0x00, 0xb2);
90}
91
92void southbridge_clear_smi_status(void)
93{
94 /* Clear SMI status */
95 clear_smi_status();
96
97 /* Clear PM1 status */
98 clear_pm1_status();
99
100 /* Set EOS bit so other SMIs can occur. */
101 enable_smi(EOS);
102}
103
104void smm_setup_structures(void *gnvs, void *tcg, void *smi1)
105{
106 /*
107 * Issue SMI to set the gnvs pointer in SMM.
108 * tcg and smi1 are unused.
109 *
110 * EAX = APM_CNT_GNVS_UPDATE
111 * EBX = gnvs pointer
112 * EDX = APM_CNT
113 */
114 asm volatile (
115 "outb %%al, %%dx\n\t"
116 : /* ignore result */
117 : "a" (APM_CNT_GNVS_UPDATE),
118 "b" ((u32)gnvs),
119 "d" (APM_CNT)
120 );
121}