2 * System management interrupt dispatch routines for ICH2 southbridge
3 * NetWatch system management mode administration console
5 * Copyright (c) 2008 Jacob Potter and Joshua Wise. All rights reserved.
6 * This program is free software; you can redistribute and/or modify it under
7 * the terms found in the file LICENSE in the root of this source tree.
16 #include <vga-overlay.h>
17 #include <reg-82801b.h>
20 static smi_handler_t _handlers[SMI_EVENT_MAX] = {0};
22 static uint16_t _get_PMBASE()
24 static long pmbase = -1;
26 if (pmbase == -1) /* Memoize it so that we don't have to hit PCI so often. */
27 pmbase = pci_read32(ICH2_LPC_BUS, ICH2_LPC_DEV, ICH2_LPC_FN, ICH2_LPC_PCI_PMBASE) & ICH2_PMBASE_MASK;
34 unsigned short smi_en = _get_PMBASE() + ICH2_PMBASE_SMI_EN;
35 outl(smi_en, inl(smi_en) & ~ICH2_SMI_EN_GBL_SMI_EN);
40 unsigned short smi_en = _get_PMBASE() + ICH2_PMBASE_SMI_EN;
41 outl(smi_en, inl(smi_en) | ICH2_SMI_EN_GBL_SMI_EN);
44 unsigned long smi_status()
46 unsigned short smi_sts = _get_PMBASE() + ICH2_PMBASE_SMI_STS;
52 unsigned long sts = smi_status();
54 if (sts & ICH2_SMI_STS_BIOS_STS)
56 if (_handlers[SMI_EVENT_GBL_RLS] == SMI_HANDLER_NONE)
57 output("Unhandled: BIOS_STS");
58 else if (_handlers[SMI_EVENT_GBL_RLS] != SMI_HANDLER_IGNORE)
59 _handlers[SMI_EVENT_GBL_RLS](SMI_EVENT_GBL_RLS);
60 outl(_get_PMBASE() + ICH2_PMBASE_SMI_STS, ICH2_SMI_STS_BIOS_STS);
63 if (sts & ICH2_SMI_STS_LEGACY_USB_STS)
65 output("Unhandled: LEGACY_USB_STS");
66 outl(_get_PMBASE() + ICH2_PMBASE_SMI_STS, ICH2_SMI_STS_LEGACY_USB_STS);
69 if (sts & ICH2_SMI_STS_SLP_SMI_STS)
71 output("Unhandled: SLP_SMI_STS");
72 outl(_get_PMBASE() + ICH2_PMBASE_SMI_STS, ICH2_SMI_STS_SLP_SMI_STS);
75 if (sts & ICH2_SMI_STS_APM_STS)
77 output("Unhandled: APM_STS");
78 outl(_get_PMBASE() + ICH2_PMBASE_SMI_STS, ICH2_SMI_STS_APM_STS);
81 if (sts & ICH2_SMI_STS_SWSMI_TMR_STS) // Ack it, then request another.
83 if (_handlers[SMI_EVENT_FAST_TIMER] == SMI_HANDLER_NONE)
84 output("Unhandled: SWSMI_TMR_STS");
85 else if (_handlers[SMI_EVENT_FAST_TIMER] != SMI_HANDLER_IGNORE)
86 _handlers[SMI_EVENT_FAST_TIMER](SMI_EVENT_FAST_TIMER);
87 outl(_get_PMBASE() + ICH2_PMBASE_SMI_STS, ICH2_SMI_STS_SWSMI_TMR_STS);
90 if (sts & ICH2_SMI_STS_PM1_STS_REG)
92 unsigned short pm1_sts = inw(_get_PMBASE() + ICH2_PMBASE_PM1_STS);
93 unsigned short pm1_en = inw(_get_PMBASE() + ICH2_PMBASE_PM1_EN);
96 if (pm1_sts & ICH2_PM1_STS_RTC_STS)
98 output("Unhandled: PM1_STS: RTC_STS");
99 outw(_get_PMBASE() + ICH2_PMBASE_PM1_STS, ICH2_PM1_STS_RTC_STS);
102 if (pm1_sts & ICH2_PM1_STS_PWRBTN_STS)
104 output("Unhandled: PM1_STS: PWRBTN_STS");
105 outw(_get_PMBASE() + ICH2_PMBASE_PM1_STS, ICH2_PM1_STS_PWRBTN_STS);
108 if (pm1_sts & ICH2_PM1_STS_GBL_STS)
110 output("Unhandled: PM1_STS: GBL_STS");
111 outw(_get_PMBASE() + ICH2_PMBASE_PM1_STS, ICH2_PM1_STS_GBL_STS);
114 if (pm1_sts & ICH2_PM1_STS_TMROF_STS)
116 output("Unhandled: PM1_STS: TMROF_STS");
117 outw(_get_PMBASE() + ICH2_PMBASE_PM1_STS, ICH2_PM1_STS_TMROF_STS);
120 outl(_get_PMBASE() + ICH2_PMBASE_SMI_STS, ICH2_SMI_STS_PM1_STS_REG);
123 if (sts & ICH2_SMI_STS_GPE0_STS)
125 /* XXX -- trawl through GPE0_STS to see what happened */
126 output("XXX Unhandled: GPE0_STS (expect lockup)");
129 if (sts & ICH2_SMI_STS_GPE1_STS)
131 /* XXX -- trawl through GPE1_STS to see what happened */
132 output("XXX Unhandled: GPE1_STS (expect lockup)");
135 if (sts & ICH2_SMI_STS_MCSMI_STS)
137 output("Unhandled: MCSMI_STS");
138 outl(_get_PMBASE() + ICH2_PMBASE_SMI_STS, ICH2_SMI_STS_MCSMI_STS);
141 if (sts & ICH2_SMI_STS_DEVMON_STS)
143 unsigned short mon_smi = inw(_get_PMBASE() + ICH2_PMBASE_MON_SMI);
144 unsigned long devact_sts = inl(_get_PMBASE() + ICH2_PMBASE_DEVACT_STS);
145 unsigned long devtrap_en = inl(_get_PMBASE() + ICH2_PMBASE_DEVTRAP_EN);
147 if (devact_sts & ICH2_DEVACT_STS_KBC_ACT_STS)
149 if (_handlers[SMI_EVENT_DEVTRAP_KBC] == SMI_HANDLER_NONE)
150 output("Unhandled: DEVACT_KBC_ACT_STS");
151 else if (_handlers[SMI_EVENT_DEVTRAP_KBC] != SMI_HANDLER_IGNORE)
152 _handlers[SMI_EVENT_DEVTRAP_KBC](SMI_EVENT_DEVTRAP_KBC);
153 outl(_get_PMBASE() + ICH2_PMBASE_DEVACT_STS, ICH2_DEVACT_STS_KBC_ACT_STS);
156 /* Refresh register cache so that we can print unhandleds as needed. */
157 mon_smi = inw(_get_PMBASE() + ICH2_PMBASE_MON_SMI);
158 devact_sts = inl(_get_PMBASE() + ICH2_PMBASE_DEVACT_STS);
159 devtrap_en = inl(_get_PMBASE() + ICH2_PMBASE_DEVTRAP_EN);
161 if (((mon_smi & 0x0F00) >> 8) & ((mon_smi & 0xF000) >> 12))
162 outputf("Unhandled: MON_SMI (%04x)", mon_smi);
163 if (devact_sts & devtrap_en)
164 outputf("Unhandled: DEVTRAP (%08x)", devact_sts & devtrap_en);
167 if (sts & ICH2_SMI_STS_TCO_STS)
169 output("Unhandled: TCO_STS");
170 outl(_get_PMBASE() + ICH2_PMBASE_SMI_STS, ICH2_SMI_STS_TCO_STS);
173 if (sts & ICH2_SMI_STS_PERIODIC_STS)
175 output("Unhandled: PERIODIC_STS");
176 outl(_get_PMBASE() + ICH2_PMBASE_SMI_STS, ICH2_SMI_STS_PERIODIC_STS);
179 if (sts & ICH2_SMI_STS_SERIRQ_SMI_STS)
181 output("Unhandled: SERIRQ_SMI_STS");
182 outl(_get_PMBASE() + ICH2_PMBASE_SMI_STS, ICH2_SMI_STS_SERIRQ_SMI_STS);
185 if (sts & ICH2_SMI_STS_SMBUS_SMI_STS)
187 output("Unhandled: SMBUS_SMI_STS");
188 outl(_get_PMBASE() + ICH2_PMBASE_SMI_STS, ICH2_SMI_STS_SMBUS_SMI_STS);
191 if (smi_status() & ~ICH2_SMI_STS_PM1_STS_REG) /* Either the chipset is buggy, or we are. */
192 outputf("WARN: couldn't clear SMI_STS! (%08x)", smi_status());
194 outl(_get_PMBASE() + ICH2_PMBASE_SMI_EN,
195 inl(_get_PMBASE() + ICH2_PMBASE_SMI_EN) |
197 ICH2_SMI_EN_GBL_SMI_EN);
200 int smi_register_handler(smi_event_t ev, smi_handler_t hnd)
202 if (ev >= SMI_EVENT_MAX)
208 int smi_enable_event(smi_event_t ev)
212 case SMI_EVENT_FAST_TIMER:
213 outl(_get_PMBASE() + ICH2_PMBASE_SMI_EN,
214 inl(_get_PMBASE() + ICH2_PMBASE_SMI_EN) |
215 ICH2_SMI_EN_SWSMI_TMR_EN);
217 case SMI_EVENT_DEVTRAP_KBC:
218 outl(_get_PMBASE() + ICH2_PMBASE_DEVTRAP_EN,
219 inl(_get_PMBASE() + ICH2_PMBASE_DEVTRAP_EN) |
220 ICH2_DEVTRAP_EN_KBC_TRP_EN);
222 case SMI_EVENT_GBL_RLS:
223 outl(_get_PMBASE() + ICH2_PMBASE_SMI_EN,
224 inl(_get_PMBASE() + ICH2_PMBASE_SMI_EN) |
225 ICH2_SMI_EN_BIOS_EN);
232 int smi_disable_event(smi_event_t ev)
236 case SMI_EVENT_FAST_TIMER:
237 outl(_get_PMBASE() + ICH2_PMBASE_SMI_EN,
238 inl(_get_PMBASE() + ICH2_PMBASE_SMI_EN) &
239 ~ICH2_SMI_EN_SWSMI_TMR_EN);
241 case SMI_EVENT_DEVTRAP_KBC:
242 outl(_get_PMBASE() + ICH2_PMBASE_DEVTRAP_EN,
243 inl(_get_PMBASE() + ICH2_PMBASE_DEVTRAP_EN) &
244 ~ICH2_DEVTRAP_EN_KBC_TRP_EN);
246 case SMI_EVENT_GBL_RLS:
247 outl(_get_PMBASE() + ICH2_PMBASE_SMI_EN,
248 inl(_get_PMBASE() + ICH2_PMBASE_SMI_EN) &
249 ~ICH2_SMI_EN_BIOS_EN);