summaryrefslogtreecommitdiff
path: root/src/soc/amd/common/block/acpi/alib.c
blob: da542489b08608b5e838265437010e0b398e8b2f (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
/* SPDX-License-Identifier: GPL-2.0-only */

#include <acpi/acpigen.h>
#include <amdblocks/alib.h>
#include <types.h>

static void acpigen_dptc_call_alib(const char *buf_name, uint8_t *buffer, size_t size)
{
	/* Name (buf_name, Buffer(size) {...} */
	acpigen_write_name(buf_name);
	acpigen_write_byte_buffer(buffer, size);

	/* \_SB.ALIB(0xc, buf_name) */
	acpigen_emit_namestring("\\_SB.ALIB");
	acpigen_write_integer(ALIB_FUNCTION_DYNAMIC_POWER_THERMAL_CONFIG);
	acpigen_emit_namestring(buf_name);
}

void acpigen_write_alib_dptc_default(uint8_t *default_param, size_t default_param_len)
{
	/* Scope (\_SB) */
	acpigen_write_scope("\\_SB");

	/* Default (Unthrottled) Mode */
	/* Scope (\_SB)
	 * {
	 *     Method (DDEF, 0, Serialized)
	 *     {
	 *         Debug = "DPTC: Using normal SOC DPTC Settings."
	 *         Name (DEFB, Buffer (0x25)
	 *         {
	 *             ...
	 *         })
	 *         \_SB.ALIB
	 *         0x0C
	 *         DEFB
	 *     }
	 * }
	 */
	acpigen_write_method_serialized("DDEF", 0);
	acpigen_write_debug_string("DPTC: Using normal SOC DPTC Settings.");
	acpigen_dptc_call_alib("DEFB", default_param, default_param_len);
	acpigen_write_method_end();

	acpigen_write_scope_end();
}

void acpigen_write_alib_dptc_no_battery(uint8_t *no_battery_param, size_t no_battery_param_len)
{
	/* Scope (\_SB) */
	acpigen_write_scope("\\_SB");

	/* Low/No Battery Mode */
	/* Scope (\_SB)
	 * {
	 *     Method (DTHL, 0, Serialized)
	 *     {
	 *         Debug = "DPTC: Using low/no battery mode SOC DPTC settings."
	 *         Name (THTL, Buffer (0x25)
	 *         {
	 *             ...
	 *         })
	 *         \_SB.ALIB
	 *         0x0C
	 *         THTL
	 *     }
	 * }
	 */
	acpigen_write_method_serialized("DTHL", 0);
	acpigen_write_debug_string("DPTC: Using low/no battery mode SOC DPTC settings.");
	acpigen_dptc_call_alib("THTL", no_battery_param, no_battery_param_len);
	acpigen_write_method_end();

	acpigen_write_scope_end();
}

void acpigen_write_alib_dptc_tablet(uint8_t *tablet_param, size_t tablet_param_len)
{
	/* Scope (\_SB) */
	acpigen_write_scope("\\_SB");

	/* Tablet Mode */
	/* Scope (\_SB)
	 * {
	 *     Method (DTAB, 0, Serialized)
	 *     {
	 *         Debug = "DPTC: Using tablet mode SOC DPTC Settings."
	 *         Name (TABB, Buffer (0x25)
	 *         {
	 *             ...
	 *         })
	 *         \_SB.ALIB
	 *         0x0C
	 *         TABB
	 *     }
	 * }
	 */
	acpigen_write_method_serialized("DTAB", 0);
	acpigen_write_debug_string("DPTC: Using tablet mode SOC DPTC Settings.");
	acpigen_dptc_call_alib("TABB", tablet_param, tablet_param_len);
	acpigen_write_method_end();

	acpigen_write_scope_end();
}

void acpigen_write_alib_dptc_thermal_B(uint8_t *thermal_param_B, size_t thermal_param_B_len)
{
	/* Scope (\_SB) */
	acpigen_write_scope("\\_SB");

	/* Table B for dynamic DPTC*/
	/* Scope (\_SB)
	 * {
	 *     Method (DTTB, 0, Serialized)
	 *     {
	 *         Debug = "DPTC: TABLE B"
	 *         Name (THTB, Buffer (0x25)
	 *         {
	 *             ...
	 *         })
	 *         \_SB.ALIB
	 *         0x0C
	 *         THTB
	 *     }
	 * }
	 */
	acpigen_write_method_serialized("DTTB", 0);
	acpigen_write_debug_string("DPTC: TABLE B");
	acpigen_dptc_call_alib("THTB", thermal_param_B, thermal_param_B_len);
	acpigen_write_method_end();

	acpigen_write_scope_end();
}

void acpigen_write_alib_dptc_thermal_C(uint8_t *thermal_param_C, size_t thermal_param_C_len)
{
	/* Scope (\_SB) */
	acpigen_write_scope("\\_SB");

	/* Table C for dynamic DPTC*/
	/* Scope (\_SB)
	 * {
	 *     Method (DTTC, 0, Serialized)
	 *     {
	 *         Debug = "DPTC: TABLE C"
	 *         Name (THTC, Buffer (0x25)
	 *         {
	 *             ...
	 *         })
	 *         \_SB.ALIB
	 *         0x0C
	 *         THTC
	 *     }
	 * }
	 */
	acpigen_write_method_serialized("DTTC", 0);
	acpigen_write_debug_string("DPTC: TABLE C");
	acpigen_dptc_call_alib("THTC", thermal_param_C, thermal_param_C_len);
	acpigen_write_method_end();

	acpigen_write_scope_end();
}

void acpigen_write_alib_dptc_thermal_D(uint8_t *thermal_param_D, size_t thermal_param_D_len)
{
	/* Scope (\_SB) */
	acpigen_write_scope("\\_SB");

	/* Table D for dynamic DPTC*/
	/* Scope (\_SB)
	 * {
	 *     Method (DTTD, 0, Serialized)
	 *     {
	 *         Debug = "DPTC: Using normal SOC DPTC Settings."
	 *         Name (THTD, Buffer (0x25)
	 *         {
	 *             ...
	 *         })
	 *         \_SB.ALIB
	 *         0x0C
	 *         THTD
	 *     }
	 * }
	 */
	acpigen_write_method_serialized("DTTD", 0);
	acpigen_write_debug_string("DPTC: TABLE D");
	acpigen_dptc_call_alib("THTD", thermal_param_D, thermal_param_D_len);
	acpigen_write_method_end();

	acpigen_write_scope_end();
}

void acpigen_write_alib_dptc_thermal_E(uint8_t *thermal_param_E, size_t thermal_param_E_len)
{
	/* Scope (\_SB) */
	acpigen_write_scope("\\_SB");

	/* Table E for dynamic DPTC*/
	/* Scope (\_SB)
	 * {
	 *     Method (DTTE, 0, Serialized)
	 *     {
	 *         Debug = "DPTC: TABLE E"
	 *         Name (THTE, Buffer (0x25)
	 *         {
	 *             ...
	 *         })
	 *         \_SB.ALIB
	 *         0x0C
	 *         THTE
	 *     }
	 * }
	 */
	acpigen_write_method_serialized("DTTE", 0);
	acpigen_write_debug_string("DPTC: TABLE E");
	acpigen_dptc_call_alib("THTE", thermal_param_E, thermal_param_E_len);
	acpigen_write_method_end();

	acpigen_write_scope_end();
}

void acpigen_write_alib_dptc_thermal_F(uint8_t *thermal_param_F, size_t thermal_param_F_len)
{
	/* Scope (\_SB) */
	acpigen_write_scope("\\_SB");

	/* Table F for dynamic DPTC*/
	/* Scope (\_SB)
	 * {
	 *     Method (DTTF, 0, Serialized)
	 *     {
	 *         Debug = "DPTC: TABLE F"
	 *         Name (THTF, Buffer (0x25)
	 *         {
	 *             ...
	 *         })
	 *         \_SB.ALIB
	 *         0x0C
	 *         THTF
	 *     }
	 * }
	 */
	acpigen_write_method_serialized("DTTF", 0);
	acpigen_write_debug_string("DPTC: TABLE F");
	acpigen_dptc_call_alib("THTF", thermal_param_F, thermal_param_F_len);
	acpigen_write_method_end();

	acpigen_write_scope_end();
}