Invalidate cache before first jump
[coreboot.git] / src / northbridge / amd / amdk8 / thermal_mixin.asl
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2011 Christoph Grenz <christophg+cb@grenz-bonn.de>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 /*
21  * include this file into a mainboards DSDT inside the PCI device
22  * "K8 Miscellaneous Control" and it will expose the temperature
23  * sensors of the processor as thermal zones.
24  *
25  * If, for example, the K8 Misc. Control device is on 0:18.3, include the
26  * following inside the PCI0 device:
27  *
28  * Device(K8MC) {
29  *   Name (_ADR, 0x00180003)
30  *   #include northbridge/amd/amdk8/thermal_mixin.asl
31  * }
32  *
33  * Note: as only the current temperature and the trip temperature for
34  * "Software Thermal Control" are available in the PCI registers, but the
35  * linux driver for thermal zones needs a critical temperature value, a
36  * reasonable critical temperature is calculated by simply adding 6°C to
37  * the trip temperature.
38  *
39  * The used registers are documented in the "BIOS and Kernel Developer's
40  * Guide for AMD NPT Family 0Fh Processors"
41  * http://support.amd.com/us/Processor_TechDocs/32559.pdf
42  *
43  */
44
45 #ifndef K8TEMP_CRITICAL_ADD
46 # define K8TEMP_CRITICAL_ADD 6
47 #endif
48
49 OperationRegion(K8TR, PCI_Config, 0xE4, 0x4)
50 Field(K8TR, DWordAcc, NoLock, Preserve) {
51         ,     1,
52         THTP, 1, /* Temperature sensor trip occured */
53         CORE, 1, /* Select Core */
54         TTS0, 1, /* Temperature sensor trip on CPU1 (or single core CPU0) */
55         TTS1, 1, /* Temperature sensor trip on CPU0 */
56         TTEN, 1, /* Temperature sensor trip enabled */
57         PLAC, 1, /* Select Sensor */
58         ,     1,
59         DOFF, 6, /* Diode offset (signed 6bit-Integer) in °C */
60         TFRC, 2, /* Temperature fractions */
61         TVAL, 8, /* Temperature value in °C biased by -49 */
62         TJOF, 5,
63         ,     2,
64         SWTT, 1, /* Induce a thermtrip event (for diagnostic purposes) */
65 }
66
67 OperationRegion(K8ST, PCI_Config, 0x70, 0x1)
68 Field(K8ST, ByteAcc, NoLock, Preserve) {
69         TMAX, 5, /* Maximum temperature for software thermal control, in °C, biased by 52 */
70 }
71
72 /* Calculates temperature in tenths Kelvin from given TVAL and TFRC values */
73 Method(K8PT, 2) {
74         Divide(Multiply(Arg1, 5), 2, , Local0)
75         Return (Add(Multiply(Add(Arg0, 224),10), Local0))
76 }
77
78 /* Calculates the diode offset from a DOFF value */
79 Method(K8PO, 1) {
80         If (And(Arg0, 0x20))
81         {
82                 Return (Multiply(Subtract(Xor(Arg0, 0x3F), 1), 10))
83         }
84         Else {
85                 Return (Multiply(Arg0, 10))
86         }
87 }
88
89 ThermalZone (K8T0) {
90         Name(_HID, EisaId("PNP0C11"))
91         Name(_UID, "k8-0")
92         Name(_STR, Unicode("K8 compatible CPU Core 1 Thermal Sensor 1"))
93
94         Method(_STA) {
95                 Store(CORE, Local0)
96                 Store(PLAC, Local1)
97
98                 Store(Zero, CORE)
99                 Store(Zero, PLAC)
100                 If (LOr(PLAC, CORE)) {
101                         Store(Local0, CORE)
102                         Store(Local1, PLAC)
103                         Return (0x00)
104                 }
105
106                 If (LOr(LNot(TVAL), LEqual(TVAL, 0xFF))) {
107                         Return (0x00)
108                 }
109
110                 Store(Local0, CORE)
111                 Store(Local1, PLAC)
112                 Return (0x0F)
113         }
114
115         Method(_TMP) {
116                 Store(CORE, Local0)
117                 Store(PLAC, Local1)
118
119                 Store(Zero, CORE)
120                 Store(Zero, PLAC)
121
122                 Store (K8PT(TVAL, TFRC), Local2)
123                 Add (K8PO(DOFF), Local2, Local2)
124                 Store(Local0, CORE)
125                 Store(Local1, PLAC)
126
127                 Return (Local2)
128         }
129
130         Method(_CRT) {
131                 Add(TMAX, 325, Local0)
132                 Add(Local0, K8TEMP_CRITICAL_ADD, Local0)
133                 Return (Multiply(Local0, 10))
134         }
135 }
136
137 ThermalZone (K8T1) {
138         Name(_HID, EisaId("PNP0C11"))
139         Name(_UID, "k8-1")
140         Name(_STR, Unicode("K8 compatible CPU Core 1 Thermal Sensor 2"))
141
142         Name(_TZD, Package () {\_PR.CPU0})
143
144         Method(_STA) {
145                 Store(CORE, Local0)
146                 Store(PLAC, Local1)
147
148                 Store(Zero, CORE)
149                 Store(Zero, PLAC)
150                 If (LOr(PLAC, CORE)) {
151                         Store(Local0, CORE)
152                         Store(Local1, PLAC)
153                         Return (0x00)
154                 }
155
156                 Store(One, PLAC)
157                 If (LOr(LNot(TVAL), LEqual(TVAL, 0xFF))) {
158                         Return (0x00)
159                 }
160
161                 Store(Local0, CORE)
162                 Store(Local1, PLAC)
163                 Return (0x0F)
164         }
165
166         Method(_TMP) {
167                 Store(CORE, Local0)
168                 Store(PLAC, Local1)
169
170                 Store(Zero, CORE)
171                 Store(One, PLAC)
172
173                 Store (K8PT(TVAL, TFRC), Local2)
174                 Add (K8PO(DOFF), Local2, Local2)
175                 Store(Local0, CORE)
176                 Store(Local1, PLAC)
177
178                 Return (Local2)
179         }
180
181         Method(_CRT) {
182                 Add(TMAX, 325, Local0)
183                 Add(Local0, K8TEMP_CRITICAL_ADD, Local0)
184                 Return (Multiply(Local0, 10))
185         }
186 }
187
188 ThermalZone (K8T2) {
189         Name(_HID, EisaId("PNP0C11"))
190         Name(_UID, "k8-2")
191         Name(_STR, Unicode("K8 compatible CPU Core 2 Thermal Sensor 1"))
192
193         Name(_TZD, Package () {\_PR.CPU0})
194
195         Method(_STA) {
196                 Store(CORE, Local0)
197                 Store(PLAC, Local1)
198
199                 Store(Zero, CORE)
200                 Store(Zero, PLAC)
201                 If (LOr(PLAC, CORE)) {
202                         Store(Local0, CORE)
203                         Store(Local1, PLAC)
204                         Return (0x00)
205                 }
206
207                 Store(One, CORE)
208                 If (LOr(LNot(TVAL), LEqual(TVAL, 0xFF))) {
209                         Return (0x00)
210                 }
211
212                 Store(Local0, CORE)
213                 Store(Local1, PLAC)
214                 Return (0x0F)
215         }
216
217         Method(_TMP) {
218                 Store(CORE, Local0)
219                 Store(PLAC, Local1)
220
221                 Store(One, CORE)
222                 Store(Zero, PLAC)
223
224                 Store (K8PT(TVAL, TFRC), Local2)
225                 Add (K8PO(DOFF), Local2, Local2)
226                 Store(Local0, CORE)
227                 Store(Local1, PLAC)
228
229                 Return (Local2)
230         }
231
232         Method(_CRT) {
233                 Add(TMAX, 325, Local0)
234                 Add(Local0, K8TEMP_CRITICAL_ADD, Local0)
235                 Return (Multiply(Local0, 10))
236         }
237 }
238
239 ThermalZone (K8T3) {
240         Name(_HID, EisaId("PNP0C11"))
241         Name(_UID, "k8-3")
242         Name(_STR, Unicode("K8 compatible CPU Core 2 Thermal Sensor 2"))
243
244         Name(_TZD, Package () {\_PR.CPU0})
245
246         Method(_STA) {
247                 Store(CORE, Local0)
248                 Store(PLAC, Local1)
249
250                 Store(Zero, CORE)
251                 Store(Zero, PLAC)
252                 If (LOr(PLAC, CORE)) {
253                         Store(Local0, CORE)
254                         Store(Local1, PLAC)
255                         Return (0x00)
256                 }
257
258                 Store(One, CORE)
259                 Store(One, PLAC)
260                 If (LOr(LNot(TVAL), LEqual(TVAL, 0xFF))) {
261                         Return (0x00)
262                 }
263
264                 Store(Local0, CORE)
265                 Store(Local1, PLAC)
266                 Return (0x0F)
267         }
268
269         Method(_TMP) {
270                 Store(CORE, Local0)
271                 Store(PLAC, Local1)
272
273                 Store(One, CORE)
274                 Store(One, PLAC)
275
276                 Store (K8PT(TVAL, TFRC), Local2)
277                 Add (K8PO(DOFF), Local2, Local2)
278                 Store(Local0, CORE)
279                 Store(Local1, PLAC)
280
281                 Return (Local2)
282         }
283
284         Method(_CRT) {
285                 Add(TMAX, 325, Local0)
286                 Add(Local0, K8TEMP_CRITICAL_ADD, Local0)
287                 Return (Multiply(Local0, 10))
288         }
289 }