| 1 |
|
| 2 |
|
| 3 |
#define __SIMPLE_DEVICE__ |
| 4 |
|
| 5 |
#include <arch/io.h> |
| 6 |
#include <device/pci_ops.h> |
| 7 |
#include <device/device.h> |
| 8 |
#include <device/pci.h> |
| 9 |
#include <intelblocks/gpmr.h> |
| 10 |
#include <intelblocks/pcr.h> |
| 11 |
#include <intelblocks/pmclib.h> |
| 12 |
#include <intelblocks/tco.h> |
| 13 |
#include <soc/iomap.h> |
| 14 |
#include <soc/pci_devs.h> |
| 15 |
#include <soc/pcr_ids.h> |
| 16 |
#include <soc/pm.h> |
| 17 |
#include <soc/smbus.h> |
| 18 |
|
| 19 |
|
| 20 |
#define TCOBASE 0x50 |
| 21 |
#define TCOCTL 0x54 |
| 22 |
#define TCO_BASE_EN (1 << 8) |
| 23 |
#define TCO_BASE_LOCK (1 << 0) |
| 24 |
|
| 25 |
#define TCO_TMR_MIN_VALUE 2 |
| 26 |
#define TCO_TMR_MAX_VALUE 1023 |
| 27 |
#define TCO_TMR_PERIOD_MS 600 |
| 28 |
|
| 29 |
uint16_t tco_get_bar(void) |
| 30 |
{ |
| 31 |
return TCO_BASE_ADDRESS; |
| 32 |
} |
| 33 |
|
| 34 |
uint16_t tco_read_reg(uint16_t tco_reg) |
| 35 |
{ |
| 36 |
uint16_t tcobase; |
| 37 |
|
| 38 |
tcobase = tco_get_bar(); |
| 39 |
|
| 40 |
return inw(tcobase + tco_reg); |
| 41 |
} |
| 42 |
|
| 43 |
void tco_write_reg(uint16_t tco_reg, uint16_t value) |
| 44 |
{ |
| 45 |
uint16_t tcobase; |
| 46 |
|
| 47 |
tcobase = tco_get_bar(); |
| 48 |
|
| 49 |
outw(value, tcobase + tco_reg); |
| 50 |
} |
| 51 |
|
| 52 |
void tco_lockdown(void) |
| 53 |
{ |
| 54 |
uint16_t tcocnt; |
| 55 |
const pci_devfn_t dev = PCH_DEV_SMBUS; |
| 56 |
|
| 57 |
|
| 58 |
pci_or_config32(dev, TCOCTL, TCO_BASE_LOCK); |
| 59 |
|
| 60 |
|
| 61 |
tcocnt = tco_read_reg(TCO1_CNT); |
| 62 |
tcocnt |= TCO1_LOCK; |
| 63 |
tco_write_reg(TCO1_CNT, tcocnt); |
| 64 |
} |
| 65 |
|
| 66 |
uint32_t tco_reset_status(void) |
| 67 |
{ |
| 68 |
uint16_t tco1_sts; |
| 69 |
uint16_t tco2_sts; |
| 70 |
|
| 71 |
|
| 72 |
tco1_sts = tco_read_reg(TCO1_STS); |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
if (CONFIG(ACPI_WDAT_WDT)) |
| 80 |
tco1_sts &= ~TCO1_STS_TIMEOUT; |
| 81 |
|
| 82 |
tco_write_reg(TCO1_STS, tco1_sts); |
| 83 |
|
| 84 |
|
| 85 |
tco2_sts = tco_read_reg(TCO2_STS); |
| 86 |
tco_write_reg(TCO2_STS, tco2_sts | TCO2_STS_SECOND_TO); |
| 87 |
|
| 88 |
if (CONFIG(ACPI_WDAT_WDT)) |
| 89 |
tco_write_reg(TCO_MESSAGE1, tco2_sts & TCO2_STS_SECOND_TO); |
| 90 |
|
| 91 |
return (tco2_sts << 16) | tco1_sts; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
static void tco_timer_disable(void) |
| 96 |
{ |
| 97 |
uint16_t tcocnt; |
| 98 |
|
| 99 |
|
| 100 |
tcocnt = tco_read_reg(TCO1_CNT); |
| 101 |
tcocnt |= TCO1_TMR_HLT; |
| 102 |
tco_write_reg(TCO1_CNT, tcocnt); |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
static void tco_intruder_smi_enable(void) |
| 107 |
{ |
| 108 |
uint16_t tcocnt; |
| 109 |
|
| 110 |
|
| 111 |
tcocnt = tco_read_reg(TCO2_CNT); |
| 112 |
tcocnt &= ~TCO2_INTRD_SEL_MASK; |
| 113 |
tcocnt |= TCO2_INTRD_SEL_SMI; |
| 114 |
tco_write_reg(TCO2_CNT, tcocnt); |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
static void tco_enable_bar(void) |
| 119 |
{ |
| 120 |
uint32_t reg32; |
| 121 |
uint16_t tcobase; |
| 122 |
const pci_devfn_t dev = PCH_DEV_SMBUS; |
| 123 |
|
| 124 |
|
| 125 |
reg32 = pci_read_config32(dev, TCOCTL); |
| 126 |
reg32 &= ~TCO_BASE_EN; |
| 127 |
pci_write_config32(dev, TCOCTL, reg32); |
| 128 |
|
| 129 |
|
| 130 |
tcobase = tco_get_bar(); |
| 131 |
pci_write_config32(dev, TCOBASE, tcobase); |
| 132 |
|
| 133 |
|
| 134 |
pci_write_config32(dev, TCOCTL, reg32 | TCO_BASE_EN); |
| 135 |
|
| 136 |
|
| 137 |
gpmr_write32(GPMR_TCOBASE, tcobase | GPMR_TCOEN); |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
void tco_configure(void) |
| 145 |
{ |
| 146 |
if (CONFIG(SOC_INTEL_COMMON_BLOCK_TCO_ENABLE_THROUGH_SMBUS)) |
| 147 |
tco_enable_bar(); |
| 148 |
|
| 149 |
tco_timer_disable(); |
| 150 |
|
| 151 |
|
| 152 |
if (CONFIG(SOC_INTEL_COMMON_BLOCK_SMM_TCO_ENABLE)) |
| 153 |
tco_intruder_smi_enable(); |
| 154 |
} |
| 155 |
|
| 156 |
uint32_t tco_get_timer_period(void) |
| 157 |
{ |
| 158 |
return TCO_TMR_PERIOD_MS; |
| 159 |
} |
| 160 |
|
| 161 |
uint32_t tco_get_timer_min_value(void) |
| 162 |
{ |
| 163 |
return TCO_TMR_MIN_VALUE; |
| 164 |
} |
| 165 |
|
| 166 |
uint32_t tco_get_timer_max_value(void) |
| 167 |
{ |
| 168 |
return TCO_TMR_MAX_VALUE; |
| 169 |
} |