summaryrefslogtreecommitdiff
path: root/src/northbridge/amd/amdk8/thermal_mixin.asl
blob: f6257a679e0ffbbe7cd299a145d1a6fd3c5a584a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/*
 * This file is part of the coreboot project.
 *
 * Copyright (C) 2011 Christoph Grenz <christophg+cb@grenz-bonn.de>
 *
 * 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.
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */

/*
 * include this file into a mainboards DSDT inside the PCI device
 * "K8 Miscellaneous Control" and it will expose the temperature
 * sensors of the processor as thermal zones.
 *
 * If, for example, the K8 Misc. Control device is on 0:18.3, include the
 * following inside the PCI0 device:
 *
 * Device(K8MC) {
 *   Name (_ADR, 0x00180003)
 *   #include northbridge/amd/amdk8/thermal_mixin.asl
 * }
 *
 * Note: as only the current temperature and the trip temperature for
 * "Software Thermal Control" are available in the PCI registers, but the
 * linux driver for thermal zones needs a critical temperature value, a
 * reasonable critical temperature is calculated by simply adding 6°C to
 * the trip temperature.
 *
 * The used registers are documented in the "BIOS and Kernel Developer's
 * Guide for AMD NPT Family 0Fh Processors"
 * http://support.amd.com/us/Processor_TechDocs/32559.pdf
 *
 */

#ifndef K8TEMP_CRITICAL_ADD
# define K8TEMP_CRITICAL_ADD 6
#endif

OperationRegion(K8TR, PCI_Config, 0xE4, 0x4)
Field(K8TR, DWordAcc, NoLock, Preserve) {
	,     1,
	THTP, 1, /* Temperature sensor trip occured */
	CORE, 1, /* Select Core */
	TTS0, 1, /* Temperature sensor trip on CPU1 (or single core CPU0) */
	TTS1, 1, /* Temperature sensor trip on CPU0 */
	TTEN, 1, /* Temperature sensor trip enabled */
	PLAC, 1, /* Select Sensor */
	,     1,
	DOFF, 6, /* Diode offset (signed 6bit-Integer) in °C */
	TFRC, 2, /* Temperature fractions */
	TVAL, 8, /* Temperature value in °C biased by -49 */
	TJOF, 5,
	,     2,
	SWTT, 1, /* Induce a thermtrip event (for diagnostic purposes) */
}

OperationRegion(K8ST, PCI_Config, 0x70, 0x1)
Field(K8ST, ByteAcc, NoLock, Preserve) {
	TMAX, 5, /* Maximum temperature for software thermal control, in °C, biased by 52 */
}

/* Calculates temperature in tenths Kelvin from given TVAL and TFRC values */
Method(K8PT, 2) {
	Divide(Multiply(Arg1, 5), 2, , Local0)
	Return (Add(Multiply(Add(Arg0, 224),10), Local0))
}

/* Calculates the diode offset from a DOFF value */
Method(K8PO, 1) {
	If (And(Arg0, 0x20))
	{
		Return (Multiply(Subtract(Xor(Arg0, 0x3F), 1), 10))
	}
	Else {
		Return (Multiply(Arg0, 10))
	}
}

ThermalZone (K8T0) {
	Name(_HID, EisaId("PNP0C11"))
	Name(_UID, "k8-0")
	Name(_STR, Unicode("K8 compatible CPU Core 1 Thermal Sensor 1"))

	Method(_STA) {
		Store(CORE, Local0)
		Store(PLAC, Local1)

		Store(Zero, CORE)
		Store(Zero, PLAC)
		If (LOr(PLAC, CORE)) {
			Store(Local0, CORE)
			Store(Local1, PLAC)
			Return (0x00)
		}

		If (LOr(LNot(TVAL), LEqual(TVAL, 0xFF))) {
			Return (0x00)
		}

		Store(Local0, CORE)
		Store(Local1, PLAC)
		Return (0x0F)
	}

	Method(_TMP) {
		Store(CORE, Local0)
		Store(PLAC, Local1)

		Store(Zero, CORE)
		Store(Zero, PLAC)

		Store (K8PT(TVAL, TFRC), Local2)
		Add (K8PO(DOFF), Local2, Local2)
		Store(Local0, CORE)
		Store(Local1, PLAC)

		Return (Local2)
	}

	Method(_CRT) {
		Add(TMAX, 325, Local0)
		Add(Local0, K8TEMP_CRITICAL_ADD, Local0)
		Return (Multiply(Local0, 10))
	}
}

ThermalZone (K8T1) {
	Name(_HID, EisaId("PNP0C11"))
	Name(_UID, "k8-1")
	Name(_STR, Unicode("K8 compatible CPU Core 1 Thermal Sensor 2"))

	Name(_TZD, Package () {\_PR.CP00})

	Method(_STA) {
		Store(CORE, Local0)
		Store(PLAC, Local1)

		Store(Zero, CORE)
		Store(Zero, PLAC)
		If (LOr(PLAC, CORE)) {
			Store(Local0, CORE)
			Store(Local1, PLAC)
			Return (0x00)
		}

		Store(One, PLAC)
		If (LOr(LNot(TVAL), LEqual(TVAL, 0xFF))) {
			Return (0x00)
		}

		Store(Local0, CORE)
		Store(Local1, PLAC)
		Return (0x0F)
	}

	Method(_TMP) {
		Store(CORE, Local0)
		Store(PLAC, Local1)

		Store(Zero, CORE)
		Store(One, PLAC)

		Store (K8PT(TVAL, TFRC), Local2)
		Add (K8PO(DOFF), Local2, Local2)
		Store(Local0, CORE)
		Store(Local1, PLAC)

		Return (Local2)
	}

	Method(_CRT) {
		Add(TMAX, 325, Local0)
		Add(Local0, K8TEMP_CRITICAL_ADD, Local0)
		Return (Multiply(Local0, 10))
	}
}

ThermalZone (K8T2) {
	Name(_HID, EisaId("PNP0C11"))
	Name(_UID, "k8-2")
	Name(_STR, Unicode("K8 compatible CPU Core 2 Thermal Sensor 1"))

	Name(_TZD, Package () {\_PR.CP00})

	Method(_STA) {
		Store(CORE, Local0)
		Store(PLAC, Local1)

		Store(Zero, CORE)
		Store(Zero, PLAC)
		If (LOr(PLAC, CORE)) {
			Store(Local0, CORE)
			Store(Local1, PLAC)
			Return (0x00)
		}

		Store(One, CORE)
		If (LOr(LNot(TVAL), LEqual(TVAL, 0xFF))) {
			Return (0x00)
		}

		Store(Local0, CORE)
		Store(Local1, PLAC)
		Return (0x0F)
	}

	Method(_TMP) {
		Store(CORE, Local0)
		Store(PLAC, Local1)

		Store(One, CORE)
		Store(Zero, PLAC)

		Store (K8PT(TVAL, TFRC), Local2)
		Add (K8PO(DOFF), Local2, Local2)
		Store(Local0, CORE)
		Store(Local1, PLAC)

		Return (Local2)
	}

	Method(_CRT) {
		Add(TMAX, 325, Local0)
		Add(Local0, K8TEMP_CRITICAL_ADD, Local0)
		Return (Multiply(Local0, 10))
	}
}

ThermalZone (K8T3) {
	Name(_HID, EisaId("PNP0C11"))
	Name(_UID, "k8-3")
	Name(_STR, Unicode("K8 compatible CPU Core 2 Thermal Sensor 2"))

	Name(_TZD, Package () {\_PR.CP00})

	Method(_STA) {
		Store(CORE, Local0)
		Store(PLAC, Local1)

		Store(Zero, CORE)
		Store(Zero, PLAC)
		If (LOr(PLAC, CORE)) {
			Store(Local0, CORE)
			Store(Local1, PLAC)
			Return (0x00)
		}

		Store(One, CORE)
		Store(One, PLAC)
		If (LOr(LNot(TVAL), LEqual(TVAL, 0xFF))) {
			Return (0x00)
		}

		Store(Local0, CORE)
		Store(Local1, PLAC)
		Return (0x0F)
	}

	Method(_TMP) {
		Store(CORE, Local0)
		Store(PLAC, Local1)

		Store(One, CORE)
		Store(One, PLAC)

		Store (K8PT(TVAL, TFRC), Local2)
		Add (K8PO(DOFF), Local2, Local2)
		Store(Local0, CORE)
		Store(Local1, PLAC)

		Return (Local2)
	}

	Method(_CRT) {
		Add(TMAX, 325, Local0)
		Add(Local0, K8TEMP_CRITICAL_ADD, Local0)
		Return (Multiply(Local0, 10))
	}
}