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