Debian Codegraph @

src/soc/intel/common/block/smbus/tco.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
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 /* SMBUS TCO base address. */
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 /* TCO base address lockdown */
58 pci_or_config32(dev, TCOCTL, TCO_BASE_LOCK);
59
60 /* TCO Lock down */
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 /* TCO Status 1 register */
72 tco1_sts = tco_read_reg(TCO1_STS);
73
74 /*
75 * Don't reset the TIMEOUT status bit in case the WDAT
76 * table is enabled, otherwise the watchdog will never
77 * reboot the system.
78 */
79 if (CONFIG(ACPI_WDAT_WDT))
80 tco1_sts &= ~TCO1_STS_TIMEOUT;
81
82 tco_write_reg(TCO1_STS, tco1_sts);
83
84 /* TCO Status 2 register */
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 /* Stop TCO timer */
95 static void tco_timer_disable(void)
96 {
97 uint16_t tcocnt;
98
99 /* Program TCO timer halt */
100 tcocnt = tco_read_reg(TCO1_CNT);
101 tcocnt |= TCO1_TMR_HLT;
102 tco_write_reg(TCO1_CNT, tcocnt);
103 }
104
105 /* Enable and initialize TCO intruder SMI */
106 static void tco_intruder_smi_enable(void)
107 {
108 uint16_t tcocnt;
109
110 /* Make TCO issue an SMI on INTRD_DET assertion */
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 /* Enable TCO BAR using SMBUS TCO base to access TCO related register */
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 /* Disable TCO in SMBUS Device first before changing Base Address */
125 reg32 = pci_read_config32(dev, TCOCTL);
126 reg32 &= ~TCO_BASE_EN;
127 pci_write_config32(dev, TCOCTL, reg32);
128
129 /* Program TCO Base */
130 tcobase = tco_get_bar();
131 pci_write_config32(dev, TCOBASE, tcobase);
132
133 /* Enable TCO in SMBUS */
134 pci_write_config32(dev, TCOCTL, reg32 | TCO_BASE_EN);
135
136 /* Program TCO Base Address */
137 gpmr_write32(GPMR_TCOBASE, tcobase | GPMR_TCOEN);
138 }
139
140 /*
141 * Enable TCO BAR using SMBUS TCO base to access TCO related register
142 * also disable the timer.
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 /* Enable intruder interrupt if TCO interrupts are enabled*/
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 }