2017-05-05 05:17:45 +02:00
|
|
|
/*
|
2017-09-29 01:21:09 +02:00
|
|
|
* This file is part of the coreboot project.
|
2017-05-05 05:17:45 +02:00
|
|
|
*
|
2017-09-29 01:21:09 +02:00
|
|
|
* Copyright (C) 2017 Advanced Micro Devices, Inc.
|
2017-05-05 05:17:45 +02:00
|
|
|
* Copyright (C) 2014 Alexandru Gagniuc <mr.nuke.me@gmail.com>
|
2017-09-29 01:21:09 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2017-05-05 05:17:45 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <console/console.h>
|
|
|
|
#include <cpu/x86/smm.h>
|
|
|
|
#include <delay.h>
|
|
|
|
#include <soc/smi.h>
|
2017-08-08 03:08:24 +02:00
|
|
|
#include <soc/southbridge.h>
|
2017-05-05 05:17:45 +02:00
|
|
|
|
2017-08-08 03:08:24 +02:00
|
|
|
static void sb_apmc_smi_handler(void)
|
2017-05-05 05:17:45 +02:00
|
|
|
{
|
|
|
|
u32 reg32;
|
2017-09-27 21:32:38 +02:00
|
|
|
const uint8_t cmd = inb(pm_acpi_smi_cmd_port());
|
2017-05-05 05:17:45 +02:00
|
|
|
|
|
|
|
switch (cmd) {
|
2017-09-22 23:14:46 +02:00
|
|
|
case APM_CNT_ACPI_ENABLE:
|
2017-05-05 05:17:45 +02:00
|
|
|
reg32 = inl(ACPI_PM1_CNT_BLK);
|
|
|
|
reg32 |= (1 << 0); /* SCI_EN */
|
|
|
|
outl(reg32, ACPI_PM1_CNT_BLK);
|
|
|
|
break;
|
2017-09-22 23:14:46 +02:00
|
|
|
case APM_CNT_ACPI_DISABLE:
|
2017-05-05 05:17:45 +02:00
|
|
|
reg32 = inl(ACPI_PM1_CNT_BLK);
|
|
|
|
reg32 &= ~(1 << 0); /* clear SCI_EN */
|
|
|
|
outl(ACPI_PM1_CNT_BLK, reg32);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mainboard_smi_apmc(cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
int southbridge_io_trap_handler(int smif)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-29 01:21:09 +02:00
|
|
|
/*
|
|
|
|
* Table of functions supported in the SMI handler. Note that SMI source setup
|
|
|
|
* in southbridge.c is unrelated to this list.
|
|
|
|
*/
|
|
|
|
struct smi_sources_t smi_sources[] = {
|
|
|
|
{ .type = SMITYPE_SMI_CMD_PORT, .handler = sb_apmc_smi_handler },
|
|
|
|
};
|
|
|
|
|
2017-05-05 05:17:45 +02:00
|
|
|
static void process_smi_sci(void)
|
|
|
|
{
|
2017-09-26 22:52:45 +02:00
|
|
|
const uint32_t status = smi_read32(SMI_SCI_STATUS);
|
2017-05-05 05:17:45 +02:00
|
|
|
|
|
|
|
/* Clear events to prevent re-entering SMI if event isn't handled */
|
2017-09-26 22:52:45 +02:00
|
|
|
smi_write32(SMI_SCI_STATUS, status);
|
2017-05-05 05:17:45 +02:00
|
|
|
}
|
|
|
|
|
2017-09-29 01:21:09 +02:00
|
|
|
static void *get_source_handler(int source)
|
2017-05-05 05:17:45 +02:00
|
|
|
{
|
2017-09-29 01:21:09 +02:00
|
|
|
int i;
|
2017-05-05 05:17:45 +02:00
|
|
|
|
2017-09-29 01:21:09 +02:00
|
|
|
for (i = 0 ; i < ARRAY_SIZE(smi_sources) ; i++)
|
|
|
|
if (smi_sources[i].type == source)
|
|
|
|
return smi_sources[i].handler;
|
2017-05-05 05:17:45 +02:00
|
|
|
|
2017-09-29 01:21:09 +02:00
|
|
|
return NULL;
|
2017-05-05 05:17:45 +02:00
|
|
|
}
|
|
|
|
|
2017-09-29 01:21:09 +02:00
|
|
|
static void process_smi_sources(uint32_t reg)
|
2017-05-05 05:17:45 +02:00
|
|
|
{
|
2017-09-29 01:21:09 +02:00
|
|
|
const uint32_t status = smi_read32(reg);
|
|
|
|
int bit_zero = 32 / sizeof(uint32_t) * (reg - SMI_REG_SMISTS0);
|
|
|
|
void (*source_handler)(void);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0 ; i < 32 ; i++) {
|
|
|
|
if (status & (1 << i)) {
|
|
|
|
source_handler = get_source_handler(i + bit_zero);
|
|
|
|
if (source_handler)
|
|
|
|
source_handler();
|
|
|
|
}
|
2017-05-05 05:17:45 +02:00
|
|
|
}
|
|
|
|
|
2017-09-29 01:21:09 +02:00
|
|
|
if (reg == SMI_REG_SMISTS0)
|
|
|
|
if (status & GEVENT_MASK)
|
|
|
|
/* Gevent[23:0] are assumed to be mainboard-specific */
|
|
|
|
mainboard_smi_gpi(status & GEVENT_MASK);
|
2017-05-05 05:17:45 +02:00
|
|
|
|
2017-09-29 01:21:09 +02:00
|
|
|
/* Clear all events in this register */
|
|
|
|
smi_write32(reg, status);
|
2017-05-05 05:17:45 +02:00
|
|
|
}
|
|
|
|
|
2017-09-14 01:47:31 +02:00
|
|
|
void southbridge_smi_handler(void)
|
2017-05-05 05:17:45 +02:00
|
|
|
{
|
2017-09-26 22:52:45 +02:00
|
|
|
const uint16_t smi_src = smi_read16(SMI_REG_POINTER);
|
2017-05-05 05:17:45 +02:00
|
|
|
|
2017-09-26 22:52:45 +02:00
|
|
|
if (smi_src & SMI_STATUS_SRC_SCI)
|
2017-05-05 05:17:45 +02:00
|
|
|
process_smi_sci();
|
2017-09-26 22:52:45 +02:00
|
|
|
if (smi_src & SMI_STATUS_SRC_0)
|
2017-09-29 01:21:09 +02:00
|
|
|
process_smi_sources(SMI_REG_SMISTS0);
|
2017-09-26 22:52:45 +02:00
|
|
|
if (smi_src & SMI_STATUS_SRC_1)
|
2017-09-29 01:21:09 +02:00
|
|
|
process_smi_sources(SMI_REG_SMISTS1);
|
2017-09-26 22:52:45 +02:00
|
|
|
if (smi_src & SMI_STATUS_SRC_2)
|
2017-09-29 01:21:09 +02:00
|
|
|
process_smi_sources(SMI_REG_SMISTS2);
|
2017-09-26 22:52:45 +02:00
|
|
|
if (smi_src & SMI_STATUS_SRC_3)
|
2017-09-29 01:21:09 +02:00
|
|
|
process_smi_sources(SMI_REG_SMISTS3);
|
2017-09-26 22:52:45 +02:00
|
|
|
if (smi_src & SMI_STATUS_SRC_4)
|
2017-09-29 01:21:09 +02:00
|
|
|
process_smi_sources(SMI_REG_SMISTS4);
|
2017-05-05 05:17:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void southbridge_smi_set_eos(void)
|
|
|
|
{
|
|
|
|
uint32_t reg = smi_read32(SMI_REG_SMITRIG0);
|
|
|
|
reg |= SMITRG0_EOS;
|
|
|
|
smi_write32(SMI_REG_SMITRIG0, reg);
|
|
|
|
}
|