2 * This file is part of the coreboot project.
4 * Copyright (C) 2008-2009 coresystems GmbH
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
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.
17 #define __SIMPLE_DEVICE__
19 #include <device/device.h>
20 #include <device/pci.h>
21 #include <console/console.h>
24 #include <cpu/x86/cache.h>
25 #include <cpu/x86/smm.h>
27 #include <cpu/intel/smm/gen1/smi.h>
30 /* While we read PMBASE dynamically in case it changed, let's
31 * initialize it with a sane value
33 static u16 pmbase
= DEFAULT_PMBASE
;
36 * @brief read and clear PM1_STS
37 * @return PM1_STS register
39 static u16
reset_pm1_status(void)
43 reg16
= inw(pmbase
+ PM1_STS
);
44 /* set status bits are cleared by writing 1 to them */
45 outw(reg16
, pmbase
+ PM1_STS
);
50 static void dump_pm1_status(u16 pm1_sts
)
52 printk(BIOS_DEBUG
, "PM1_STS: ");
53 if (pm1_sts
& (1 << 15)) printk(BIOS_DEBUG
, "WAK ");
54 if (pm1_sts
& (1 << 14)) printk(BIOS_DEBUG
, "PCIEXPWAK ");
55 if (pm1_sts
& (1 << 11)) printk(BIOS_DEBUG
, "PRBTNOR ");
56 if (pm1_sts
& (1 << 10)) printk(BIOS_DEBUG
, "RTC ");
57 if (pm1_sts
& (1 << 8)) printk(BIOS_DEBUG
, "PWRBTN ");
58 if (pm1_sts
& (1 << 5)) printk(BIOS_DEBUG
, "GBL ");
59 if (pm1_sts
& (1 << 4)) printk(BIOS_DEBUG
, "BM ");
60 if (pm1_sts
& (1 << 0)) printk(BIOS_DEBUG
, "TMROF ");
61 printk(BIOS_DEBUG
, "\n");
65 * @brief read and clear SMI_STS
66 * @return SMI_STS register
68 static u32
reset_smi_status(void)
72 reg32
= inl(pmbase
+ SMI_STS
);
73 /* set status bits are cleared by writing 1 to them */
74 outl(reg32
, pmbase
+ SMI_STS
);
79 static void dump_smi_status(u32 smi_sts
)
81 printk(BIOS_DEBUG
, "SMI_STS: ");
82 if (smi_sts
& (1 << 26)) printk(BIOS_DEBUG
, "SPI ");
83 if (smi_sts
& (1 << 25)) printk(BIOS_DEBUG
, "EL_SMI ");
84 if (smi_sts
& (1 << 21)) printk(BIOS_DEBUG
, "MONITOR ");
85 if (smi_sts
& (1 << 20)) printk(BIOS_DEBUG
, "PCI_EXP_SMI ");
86 if (smi_sts
& (1 << 18)) printk(BIOS_DEBUG
, "INTEL_USB2 ");
87 if (smi_sts
& (1 << 17)) printk(BIOS_DEBUG
, "LEGACY_USB2 ");
88 if (smi_sts
& (1 << 16)) printk(BIOS_DEBUG
, "SMBUS_SMI ");
89 if (smi_sts
& (1 << 15)) printk(BIOS_DEBUG
, "SERIRQ_SMI ");
90 if (smi_sts
& (1 << 14)) printk(BIOS_DEBUG
, "PERIODIC ");
91 if (smi_sts
& (1 << 13)) printk(BIOS_DEBUG
, "TCO ");
92 if (smi_sts
& (1 << 12)) printk(BIOS_DEBUG
, "DEVMON ");
93 if (smi_sts
& (1 << 11)) printk(BIOS_DEBUG
, "MCSMI ");
94 if (smi_sts
& (1 << 10)) printk(BIOS_DEBUG
, "GPI ");
95 if (smi_sts
& (1 << 9)) printk(BIOS_DEBUG
, "GPE0 ");
96 if (smi_sts
& (1 << 8)) printk(BIOS_DEBUG
, "PM1 ");
97 if (smi_sts
& (1 << 6)) printk(BIOS_DEBUG
, "SWSMI_TMR ");
98 if (smi_sts
& (1 << 5)) printk(BIOS_DEBUG
, "APM ");
99 if (smi_sts
& (1 << 4)) printk(BIOS_DEBUG
, "SLP_SMI ");
100 if (smi_sts
& (1 << 3)) printk(BIOS_DEBUG
, "LEGACY_USB ");
101 if (smi_sts
& (1 << 2)) printk(BIOS_DEBUG
, "BIOS ");
102 printk(BIOS_DEBUG
, "\n");
107 * @brief read and clear GPE0_STS
108 * @return GPE0_STS register
110 static u32
reset_gpe0_status(void)
114 reg32
= inl(pmbase
+ GPE0_STS
);
115 /* set status bits are cleared by writing 1 to them */
116 outl(reg32
, pmbase
+ GPE0_STS
);
121 static void dump_gpe0_status(u32 gpe0_sts
)
124 printk(BIOS_DEBUG
, "GPE0_STS: ");
125 for (i
=31; i
>= 16; i
--) {
126 if (gpe0_sts
& (1 << i
)) printk(BIOS_DEBUG
, "GPIO%d ", (i
-16));
128 if (gpe0_sts
& (1 << 14)) printk(BIOS_DEBUG
, "USB4 ");
129 if (gpe0_sts
& (1 << 13)) printk(BIOS_DEBUG
, "PME_B0 ");
130 if (gpe0_sts
& (1 << 12)) printk(BIOS_DEBUG
, "USB3 ");
131 if (gpe0_sts
& (1 << 11)) printk(BIOS_DEBUG
, "PME ");
132 if (gpe0_sts
& (1 << 10)) printk(BIOS_DEBUG
, "EL_SCI/BATLOW ");
133 if (gpe0_sts
& (1 << 9)) printk(BIOS_DEBUG
, "PCI_EXP ");
134 if (gpe0_sts
& (1 << 8)) printk(BIOS_DEBUG
, "RI ");
135 if (gpe0_sts
& (1 << 7)) printk(BIOS_DEBUG
, "SMB_WAK ");
136 if (gpe0_sts
& (1 << 6)) printk(BIOS_DEBUG
, "TCO_SCI ");
137 if (gpe0_sts
& (1 << 5)) printk(BIOS_DEBUG
, "AC97 ");
138 if (gpe0_sts
& (1 << 4)) printk(BIOS_DEBUG
, "USB2 ");
139 if (gpe0_sts
& (1 << 3)) printk(BIOS_DEBUG
, "USB1 ");
140 if (gpe0_sts
& (1 << 2)) printk(BIOS_DEBUG
, "HOT_PLUG ");
141 if (gpe0_sts
& (1 << 0)) printk(BIOS_DEBUG
, "THRM ");
142 printk(BIOS_DEBUG
, "\n");
147 * @brief read and clear ALT_GP_SMI_STS
148 * @return ALT_GP_SMI_STS register
150 static u16
reset_alt_gp_smi_status(void)
154 reg16
= inl(pmbase
+ ALT_GP_SMI_STS
);
155 /* set status bits are cleared by writing 1 to them */
156 outl(reg16
, pmbase
+ ALT_GP_SMI_STS
);
161 static void dump_alt_gp_smi_status(u16 alt_gp_smi_sts
)
164 printk(BIOS_DEBUG
, "ALT_GP_SMI_STS: ");
165 for (i
=15; i
>= 0; i
--) {
166 if (alt_gp_smi_sts
& (1 << i
)) printk(BIOS_DEBUG
, "GPI%d ", i
);
168 printk(BIOS_DEBUG
, "\n");
174 * @brief read and clear TCOx_STS
175 * @return TCOx_STS registers
177 static u32
reset_tco_status(void)
179 u32 tcobase
= pmbase
+ 0x60;
182 reg32
= inl(tcobase
+ 0x04);
183 /* set status bits are cleared by writing 1 to them */
184 outl(reg32
& ~(1<<18), tcobase
+ 0x04); // Don't clear BOOT_STS before SECOND_TO_STS
185 if (reg32
& (1 << 18))
186 outl(reg32
& (1<<18), tcobase
+ 0x04); // clear BOOT_STS
192 static void dump_tco_status(u32 tco_sts
)
194 printk(BIOS_DEBUG
, "TCO_STS: ");
195 if (tco_sts
& (1 << 20)) printk(BIOS_DEBUG
, "SMLINK_SLV ");
196 if (tco_sts
& (1 << 18)) printk(BIOS_DEBUG
, "BOOT ");
197 if (tco_sts
& (1 << 17)) printk(BIOS_DEBUG
, "SECOND_TO ");
198 if (tco_sts
& (1 << 16)) printk(BIOS_DEBUG
, "INTRD_DET ");
199 if (tco_sts
& (1 << 12)) printk(BIOS_DEBUG
, "DMISERR ");
200 if (tco_sts
& (1 << 10)) printk(BIOS_DEBUG
, "DMISMI ");
201 if (tco_sts
& (1 << 9)) printk(BIOS_DEBUG
, "DMISCI ");
202 if (tco_sts
& (1 << 8)) printk(BIOS_DEBUG
, "BIOSWR ");
203 if (tco_sts
& (1 << 7)) printk(BIOS_DEBUG
, "NEWCENTURY ");
204 if (tco_sts
& (1 << 3)) printk(BIOS_DEBUG
, "TIMEOUT ");
205 if (tco_sts
& (1 << 2)) printk(BIOS_DEBUG
, "TCO_INT ");
206 if (tco_sts
& (1 << 1)) printk(BIOS_DEBUG
, "SW_TCO ");
207 if (tco_sts
& (1 << 0)) printk(BIOS_DEBUG
, "NMI2SMI ");
208 printk(BIOS_DEBUG
, "\n");
214 * @brief Set the EOS bit
216 static void smi_set_eos(void)
220 reg8
= inb(pmbase
+ SMI_EN
);
222 outb(reg8
, pmbase
+ SMI_EN
);
225 void southbridge_smm_init(void)
232 /* Log events from chipset before clearing */
236 printk(BIOS_DEBUG
, "Initializing southbridge SMI...");
238 pmbase
= pci_read_config32(PCI_DEV(0, 0x1f, 0),
241 printk(BIOS_SPEW
, " ... pmbase = 0x%04x\n", pmbase
);
243 smi_en
= inl(pmbase
+ SMI_EN
);
244 if (smi_en
& APMC_EN
) {
245 printk(BIOS_INFO
, "SMI# handler already enabled?\n");
249 printk(BIOS_DEBUG
, "\n");
250 dump_smi_status(reset_smi_status());
251 dump_pm1_status(reset_pm1_status());
252 dump_gpe0_status(reset_gpe0_status());
253 dump_alt_gp_smi_status(reset_alt_gp_smi_status());
254 dump_tco_status(reset_tco_status());
256 /* Disable GPE0 PME_B0 */
257 gpe0_en
= inl(pmbase
+ GPE0_EN
);
258 gpe0_en
&= ~PME_B0_EN
;
259 outl(gpe0_en
, pmbase
+ GPE0_EN
);
264 outw(pm1_en
, pmbase
+ PM1_EN
);
266 /* Enable SMI generation:
268 * - on APMC writes (io 0xb2)
269 * - on writes to SLP_EN (sleep states)
270 * - on writes to GBL_RLS (bios commands)
272 * - on microcontroller writes (io 0x62/0x66)
275 smi_en
= 0; /* reset SMI enables */
278 smi_en
|= LEGACY_USB2_EN
| LEGACY_USB_EN
;
282 #if DEBUG_PERIODIC_SMIS
283 /* Set DEBUG_PERIODIC_SMIS in pch.h to debug using
286 smi_en
|= PERIODIC_EN
;
288 smi_en
|= SLP_SMI_EN
;
293 /* The following need to be on for SMIs to happen */
294 smi_en
|= EOS
| GBL_SMI_EN
;
296 outl(smi_en
, pmbase
+ SMI_EN
);
299 void southbridge_trigger_smi(void)
302 * There are several methods of raising a controlled SMI# via
303 * software, among them:
304 * - Writes to io 0xb2 (APMC)
305 * - Writes to the Local Apic ICR with Delivery mode SMI.
307 * Using the local apic is a bit more tricky. According to
308 * AMD Family 11 Processor BKDG no destination shorthand must be
310 * The whole SMM initialization is quite a bit hardware specific, so
311 * I'm not too worried about the better of the methods at the moment
314 /* raise an SMI interrupt */
315 printk(BIOS_SPEW
, " ... raise SMI#\n");
319 void southbridge_clear_smi_status(void)
321 /* Clear SMI status */
324 /* Clear PM1 status */
327 /* Set EOS bit so other SMIs can occur. */
331 void smm_setup_structures(void *gnvs
, void *tcg
, void *smi1
)
334 * Issue SMI to set the gnvs pointer in SMM.
335 * tcg and smi1 are unused.
337 * EAX = APM_CNT_GNVS_UPDATE
342 "outb %%al, %%dx\n\t"
343 : /* ignore result */
344 : "a" (APM_CNT_GNVS_UPDATE
),