| 1 |
|
| 2 |
|
| 3 |
#include <types.h> |
| 4 |
#include <arch/io.h> |
| 5 |
#include <device/pci_ops.h> |
| 6 |
#include <console/console.h> |
| 7 |
#include <cpu/x86/cache.h> |
| 8 |
#include <device/pci_def.h> |
| 9 |
#include <cpu/x86/smm.h> |
| 10 |
#include <cpu/intel/em64t101_save_state.h> |
| 11 |
#include <elog.h> |
| 12 |
#include <halt.h> |
| 13 |
#include <option.h> |
| 14 |
#include <southbridge/intel/common/finalize.h> |
| 15 |
#include <northbridge/intel/haswell/haswell.h> |
| 16 |
#include <cpu/intel/haswell/haswell.h> |
| 17 |
#include <soc/nvs.h> |
| 18 |
#include <smmstore.h> |
| 19 |
#include "me.h" |
| 20 |
#include "pch.h" |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
void southbridge_smi_set_eos(void) |
| 26 |
{ |
| 27 |
enable_smi(EOS); |
| 28 |
} |
| 29 |
|
| 30 |
static void busmaster_disable_on_bus(int bus) |
| 31 |
{ |
| 32 |
int slot, func; |
| 33 |
unsigned int val; |
| 34 |
unsigned char hdr; |
| 35 |
|
| 36 |
for (slot = 0; slot < 0x20; slot++) { |
| 37 |
for (func = 0; func < 8; func++) { |
| 38 |
pci_devfn_t dev = PCI_DEV(bus, slot, func); |
| 39 |
|
| 40 |
val = pci_read_config32(dev, PCI_VENDOR_ID); |
| 41 |
|
| 42 |
if (val == 0xffffffff || val == 0x00000000 || |
| 43 |
val == 0x0000ffff || val == 0xffff0000) |
| 44 |
continue; |
| 45 |
|
| 46 |
|
| 47 |
pci_and_config16(dev, PCI_COMMAND, ~PCI_COMMAND_MASTER); |
| 48 |
|
| 49 |
|
| 50 |
hdr = pci_read_config8(dev, PCI_HEADER_TYPE); |
| 51 |
hdr &= 0x7f; |
| 52 |
if (hdr == PCI_HEADER_TYPE_BRIDGE || |
| 53 |
hdr == PCI_HEADER_TYPE_CARDBUS) { |
| 54 |
unsigned int buses; |
| 55 |
buses = pci_read_config32(dev, PCI_PRIMARY_BUS); |
| 56 |
busmaster_disable_on_bus((buses >> 8) & 0xff); |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
static int power_on_after_fail(void) |
| 63 |
{ |
| 64 |
|
| 65 |
u8 tmp70, tmp72; |
| 66 |
tmp70 = inb(0x70); |
| 67 |
tmp72 = inb(0x72); |
| 68 |
const unsigned int s5pwr = get_uint_option("power_on_after_fail", |
| 69 |
CONFIG_MAINBOARD_POWER_FAILURE_STATE); |
| 70 |
outb(tmp70, 0x70); |
| 71 |
outb(tmp72, 0x72); |
| 72 |
|
| 73 |
|
| 74 |
return (s5pwr == MAINBOARD_POWER_ON); |
| 75 |
} |
| 76 |
|
| 77 |
static void southbridge_smi_sleep(void) |
| 78 |
{ |
| 79 |
u32 reg32; |
| 80 |
u8 slp_typ; |
| 81 |
u16 pmbase = get_pmbase(); |
| 82 |
|
| 83 |
|
| 84 |
disable_smi(SLP_SMI_EN); |
| 85 |
|
| 86 |
|
| 87 |
reg32 = inl(pmbase + PM1_CNT); |
| 88 |
printk(BIOS_SPEW, "SMI#: SLP = 0x%08x\n", reg32); |
| 89 |
slp_typ = acpi_sleep_from_pm1(reg32); |
| 90 |
|
| 91 |
|
| 92 |
mainboard_smi_sleep(slp_typ); |
| 93 |
|
| 94 |
|
| 95 |
#if !CONFIG(FINALIZE_USB_ROUTE_XHCI) |
| 96 |
usb_ehci_sleep_prepare(PCH_EHCI1_DEV, slp_typ); |
| 97 |
usb_ehci_sleep_prepare(PCH_EHCI2_DEV, slp_typ); |
| 98 |
#endif |
| 99 |
usb_xhci_sleep_prepare(PCH_XHCI_DEV, slp_typ); |
| 100 |
|
| 101 |
|
| 102 |
if (slp_typ >= ACPI_S3) |
| 103 |
elog_gsmi_add_event_byte(ELOG_TYPE_ACPI_ENTER, slp_typ); |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
switch (slp_typ) { |
| 109 |
case ACPI_S0: |
| 110 |
printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n"); |
| 111 |
break; |
| 112 |
case ACPI_S1: |
| 113 |
printk(BIOS_DEBUG, "SMI#: Entering S1 (Assert STPCLK#)\n"); |
| 114 |
break; |
| 115 |
case ACPI_S3: |
| 116 |
printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n"); |
| 117 |
|
| 118 |
|
| 119 |
wbinvd(); |
| 120 |
break; |
| 121 |
case ACPI_S4: |
| 122 |
printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n"); |
| 123 |
break; |
| 124 |
case ACPI_S5: |
| 125 |
printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n"); |
| 126 |
|
| 127 |
|
| 128 |
disable_all_gpe(); |
| 129 |
|
| 130 |
|
| 131 |
if (power_on_after_fail()) |
| 132 |
pci_and_config8(PCH_LPC_DEV, GEN_PMCON_3, ~1); |
| 133 |
else |
| 134 |
pci_or_config8(PCH_LPC_DEV, GEN_PMCON_3, 1); |
| 135 |
|
| 136 |
|
| 137 |
busmaster_disable_on_bus(0); |
| 138 |
break; |
| 139 |
default: |
| 140 |
printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n"); |
| 141 |
break; |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
enable_pm1_control(SLP_EN); |
| 150 |
|
| 151 |
|
| 152 |
if (slp_typ >= ACPI_S3) |
| 153 |
halt(); |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
reg32 = inl(pmbase + PM1_CNT); |
| 161 |
if (reg32 & SCI_EN) { |
| 162 |
|
| 163 |
disable_pm1_control(SLP_EN | SLP_TYP); |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
static em64t101_smm_state_save_area_t *smi_apmc_find_state_save(u8 cmd) |
| 173 |
{ |
| 174 |
em64t101_smm_state_save_area_t *state; |
| 175 |
int node; |
| 176 |
|
| 177 |
|
| 178 |
for (node = 0; node < CONFIG_MAX_CPUS; node++) { |
| 179 |
state = smm_get_save_state(node); |
| 180 |
if (!state) |
| 181 |
continue; |
| 182 |
|
| 183 |
|
| 184 |
if (!(state->io_misc_info & (1 << 0))) |
| 185 |
continue; |
| 186 |
|
| 187 |
|
| 188 |
if (state->io_misc_info & (1 << 4)) |
| 189 |
continue; |
| 190 |
|
| 191 |
|
| 192 |
if (((state->io_misc_info >> 16) & 0xff) != APM_CNT) |
| 193 |
continue; |
| 194 |
|
| 195 |
|
| 196 |
if ((state->rax & 0xff) != cmd) |
| 197 |
continue; |
| 198 |
|
| 199 |
return state; |
| 200 |
} |
| 201 |
|
| 202 |
return NULL; |
| 203 |
} |
| 204 |
|
| 205 |
static void southbridge_smi_gsmi(void) |
| 206 |
{ |
| 207 |
u32 *ret, *param; |
| 208 |
u8 sub_command; |
| 209 |
em64t101_smm_state_save_area_t *io_smi = |
| 210 |
smi_apmc_find_state_save(APM_CNT_ELOG_GSMI); |
| 211 |
|
| 212 |
if (!io_smi) |
| 213 |
return; |
| 214 |
|
| 215 |
|
| 216 |
ret = (u32 *)&io_smi->rax; |
| 217 |
sub_command = (u8)(*ret >> 8); |
| 218 |
|
| 219 |
|
| 220 |
param = (u32 *)&io_smi->rbx; |
| 221 |
|
| 222 |
|
| 223 |
*ret = gsmi_exec(sub_command, param); |
| 224 |
} |
| 225 |
|
| 226 |
static void southbridge_smi_store(void) |
| 227 |
{ |
| 228 |
u8 sub_command, ret; |
| 229 |
em64t101_smm_state_save_area_t *io_smi = |
| 230 |
smi_apmc_find_state_save(APM_CNT_SMMSTORE); |
| 231 |
uint32_t reg_ebx; |
| 232 |
|
| 233 |
if (!io_smi) |
| 234 |
return; |
| 235 |
|
| 236 |
sub_command = (io_smi->rax >> 8) & 0xff; |
| 237 |
|
| 238 |
|
| 239 |
reg_ebx = io_smi->rbx; |
| 240 |
|
| 241 |
|
| 242 |
ret = smmstore_exec(sub_command, (void *)reg_ebx); |
| 243 |
io_smi->rax = ret; |
| 244 |
} |
| 245 |
|
| 246 |
static void southbridge_smi_apmc(void) |
| 247 |
{ |
| 248 |
u8 reg8; |
| 249 |
static int chipset_finalized = 0; |
| 250 |
|
| 251 |
reg8 = apm_get_apmc(); |
| 252 |
switch (reg8) { |
| 253 |
case APM_CNT_FINALIZE: |
| 254 |
if (chipset_finalized) { |
| 255 |
printk(BIOS_DEBUG, "SMI#: Already finalized\n"); |
| 256 |
return; |
| 257 |
} |
| 258 |
|
| 259 |
intel_pch_finalize_smm(); |
| 260 |
intel_cpu_haswell_finalize_smm(); |
| 261 |
|
| 262 |
chipset_finalized = 1; |
| 263 |
break; |
| 264 |
case APM_CNT_ACPI_DISABLE: |
| 265 |
disable_pm1_control(SCI_EN); |
| 266 |
break; |
| 267 |
case APM_CNT_ACPI_ENABLE: |
| 268 |
enable_pm1_control(SCI_EN); |
| 269 |
break; |
| 270 |
case APM_CNT_ROUTE_ALL_XHCI: |
| 271 |
usb_xhci_route_all(); |
| 272 |
break; |
| 273 |
case APM_CNT_ELOG_GSMI: |
| 274 |
if (CONFIG(ELOG_GSMI)) |
| 275 |
southbridge_smi_gsmi(); |
| 276 |
break; |
| 277 |
case APM_CNT_SMMSTORE: |
| 278 |
if (CONFIG(SMMSTORE)) |
| 279 |
southbridge_smi_store(); |
| 280 |
break; |
| 281 |
} |
| 282 |
|
| 283 |
mainboard_smi_apmc(reg8); |
| 284 |
} |
| 285 |
|
| 286 |
static void southbridge_smi_pm1(void) |
| 287 |
{ |
| 288 |
u16 pm1_sts = clear_pm1_status(); |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
if (pm1_sts & PWRBTN_STS) { |
| 294 |
|
| 295 |
elog_gsmi_add_event(ELOG_TYPE_POWER_BUTTON); |
| 296 |
disable_pm1_control(-1); |
| 297 |
enable_pm1_control(SLP_EN | (SLP_TYP_S5 << 10)); |
| 298 |
} |
| 299 |
} |
| 300 |
|
| 301 |
static void southbridge_smi_gpe0(void) |
| 302 |
{ |
| 303 |
clear_gpe_status(); |
| 304 |
} |
| 305 |
|
| 306 |
static void southbridge_smi_gpi(void) |
| 307 |
{ |
| 308 |
mainboard_smi_gpi(clear_alt_smi_status()); |
| 309 |
|
| 310 |
|
| 311 |
clear_alt_smi_status(); |
| 312 |
} |
| 313 |
|
| 314 |
static void southbridge_smi_mc(void) |
| 315 |
{ |
| 316 |
u32 reg32 = inl(get_pmbase() + SMI_EN); |
| 317 |
|
| 318 |
|
| 319 |
if ((reg32 & MCSMI_EN) == 0) |
| 320 |
return; |
| 321 |
|
| 322 |
printk(BIOS_DEBUG, "Microcontroller SMI.\n"); |
| 323 |
} |
| 324 |
|
| 325 |
static void southbridge_smi_tco(void) |
| 326 |
{ |
| 327 |
u32 tco_sts = clear_tco_status(); |
| 328 |
|
| 329 |
|
| 330 |
if (!tco_sts) |
| 331 |
return; |
| 332 |
|
| 333 |
|
| 334 |
if (tco_sts & (1 << 8)) { |
| 335 |
u8 bios_cntl = pci_read_config8(PCH_LPC_DEV, BIOS_CNTL); |
| 336 |
|
| 337 |
if (bios_cntl & 1) { |
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
printk(BIOS_DEBUG, "Switching back to RO\n"); |
| 349 |
pci_write_config8(PCH_LPC_DEV, BIOS_CNTL, (bios_cntl & ~1)); |
| 350 |
} |
| 351 |
} else if (tco_sts & (1 << 3)) { |
| 352 |
|
| 353 |
printk(BIOS_DEBUG, "TCO Timeout.\n"); |
| 354 |
} |
| 355 |
} |
| 356 |
|
| 357 |
static void southbridge_smi_periodic(void) |
| 358 |
{ |
| 359 |
u32 reg32 = inl(get_pmbase() + SMI_EN); |
| 360 |
|
| 361 |
|
| 362 |
if ((reg32 & PERIODIC_EN) == 0) |
| 363 |
return; |
| 364 |
|
| 365 |
printk(BIOS_DEBUG, "Periodic SMI.\n"); |
| 366 |
} |
| 367 |
|
| 368 |
static void southbridge_smi_monitor(void) |
| 369 |
{ |
| 370 |
#define IOTRAP(x) (trap_sts & (1 << x)) |
| 371 |
u32 trap_sts, trap_cycle; |
| 372 |
u32 mask = 0; |
| 373 |
int i; |
| 374 |
|
| 375 |
trap_sts = RCBA32(0x1e00); |
| 376 |
RCBA32(0x1e00) = trap_sts; |
| 377 |
|
| 378 |
trap_cycle = RCBA32(0x1e10); |
| 379 |
for (i = 16; i < 20; i++) { |
| 380 |
if (trap_cycle & (1 << i)) |
| 381 |
mask |= (0xff << ((i - 16) << 3)); |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
if (IOTRAP(3)) { |
| 386 |
if (gnvs && gnvs->smif) |
| 387 |
io_trap_handler(gnvs->smif); |
| 388 |
return; |
| 389 |
} |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
if (IOTRAP(0)) { |
| 396 |
|
| 397 |
if (!(trap_cycle & (1 << 24))) { |
| 398 |
printk(BIOS_DEBUG, "SMI1 command\n"); |
| 399 |
(void)RCBA32(0x1e18); |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
} |
| 406 |
|
| 407 |
} |
| 408 |
|
| 409 |
printk(BIOS_DEBUG, " trapped io address = 0x%x\n", |
| 410 |
trap_cycle & 0xfffc); |
| 411 |
for (i = 0; i < 4; i++) |
| 412 |
if (IOTRAP(i)) |
| 413 |
printk(BIOS_DEBUG, " TRAP = %d\n", i); |
| 414 |
printk(BIOS_DEBUG, " AHBE = %x\n", (trap_cycle >> 16) & 0xf); |
| 415 |
printk(BIOS_DEBUG, " MASK = 0x%08x\n", mask); |
| 416 |
printk(BIOS_DEBUG, " read/write: %s\n", |
| 417 |
(trap_cycle & (1 << 24)) ? "read" : "write"); |
| 418 |
|
| 419 |
if (!(trap_cycle & (1 << 24))) { |
| 420 |
|
| 421 |
printk(BIOS_DEBUG, " iotrap written data = 0x%08x\n", RCBA32(0x1e18)); |
| 422 |
} |
| 423 |
#undef IOTRAP |
| 424 |
} |
| 425 |
|
| 426 |
typedef void (*smi_handler_t)(void); |
| 427 |
|
| 428 |
static smi_handler_t southbridge_smi[32] = { |
| 429 |
NULL, |
| 430 |
NULL, |
| 431 |
NULL, |
| 432 |
NULL, |
| 433 |
southbridge_smi_sleep, |
| 434 |
southbridge_smi_apmc, |
| 435 |
NULL, |
| 436 |
NULL, |
| 437 |
southbridge_smi_pm1, |
| 438 |
southbridge_smi_gpe0, |
| 439 |
southbridge_smi_gpi, |
| 440 |
southbridge_smi_mc, |
| 441 |
NULL, |
| 442 |
southbridge_smi_tco, |
| 443 |
southbridge_smi_periodic, |
| 444 |
NULL, |
| 445 |
NULL, |
| 446 |
NULL, |
| 447 |
NULL, |
| 448 |
NULL, |
| 449 |
NULL, |
| 450 |
southbridge_smi_monitor, |
| 451 |
NULL, |
| 452 |
NULL, |
| 453 |
NULL, |
| 454 |
NULL, |
| 455 |
NULL, |
| 456 |
NULL, |
| 457 |
NULL, |
| 458 |
NULL, |
| 459 |
NULL, |
| 460 |
NULL |
| 461 |
}; |
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
void southbridge_smi_handler(void) |
| 467 |
{ |
| 468 |
int i; |
| 469 |
u32 smi_sts; |
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
smi_sts = clear_smi_status(); |
| 475 |
|
| 476 |
|
| 477 |
for (i = 0; i < 31; i++) { |
| 478 |
if (smi_sts & (1 << i)) { |
| 479 |
if (southbridge_smi[i]) { |
| 480 |
southbridge_smi[i](); |
| 481 |
} else { |
| 482 |
printk(BIOS_DEBUG, |
| 483 |
"SMI_STS[%d] occurred, but no " |
| 484 |
"handler available.\n", i); |
| 485 |
} |
| 486 |
} |
| 487 |
} |
| 488 |
} |