aboutsummaryrefslogtreecommitdiffstats
path: root/include/therm/thrmdev.c
diff options
context:
space:
mode:
Diffstat (limited to 'include/therm/thrmdev.c')
-rw-r--r--include/therm/thrmdev.c370
1 files changed, 0 insertions, 370 deletions
diff --git a/include/therm/thrmdev.c b/include/therm/thrmdev.c
deleted file mode 100644
index 63e1033..0000000
--- a/include/therm/thrmdev.c
+++ /dev/null
@@ -1,370 +0,0 @@
1/*
2 * Copyright (c) 2016-2018, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23#include <nvgpu/bios.h>
24#include <nvgpu/gk20a.h>
25#include <nvgpu/pmuif/nvgpu_gpmu_cmdif.h>
26
27#include "thrmdev.h"
28#include "boardobj/boardobjgrp.h"
29#include "boardobj/boardobjgrp_e32.h"
30#include "gp106/bios_gp106.h"
31#include "ctrl/ctrltherm.h"
32
33static int _therm_device_pmudata_instget(struct gk20a *g,
34 struct nv_pmu_boardobjgrp *pmuboardobjgrp,
35 struct nv_pmu_boardobj **ppboardobjpmudata,
36 u8 idx)
37{
38 struct nv_pmu_therm_therm_device_boardobj_grp_set *pgrp_set =
39 (struct nv_pmu_therm_therm_device_boardobj_grp_set *)
40 pmuboardobjgrp;
41
42 nvgpu_log_info(g, " ");
43
44 /*check whether pmuboardobjgrp has a valid boardobj in index*/
45 if (((u32)BIT(idx) &
46 pgrp_set->hdr.data.super.obj_mask.super.data[0]) == 0) {
47 return -EINVAL;
48 }
49
50 *ppboardobjpmudata = (struct nv_pmu_boardobj *)
51 &pgrp_set->objects[idx].data;
52
53 nvgpu_log_info(g, " Done");
54
55 return 0;
56}
57
58static int construct_therm_device(struct gk20a *g,
59 struct boardobj **ppboardobj, u16 size, void *pargs)
60{
61 return boardobj_construct_super(g, ppboardobj, size, pargs);
62}
63
64static int construct_therm_device_gpu(struct gk20a *g,
65 struct boardobj **ppboardobj, u16 size, void *pargs)
66{
67 return construct_therm_device(g, ppboardobj, size, pargs);
68}
69
70static int construct_therm_device_gpu_sci(struct gk20a *g,
71 struct boardobj **ppboardobj, u16 size, void *pargs)
72{
73 return construct_therm_device(g, ppboardobj, size, pargs);
74}
75
76
77static int therm_device_pmu_data_init_gpu_gpc_tsosc(struct gk20a *g,
78 struct boardobj *pboard_obj, struct nv_pmu_boardobj *ppmudata)
79{
80 int status = 0;
81 struct therm_device_gpu_gpc_tsosc *pdev = NULL;
82 struct nv_pmu_therm_therm_device_gpu_gpc_tsosc_boardobj_set *pset;
83
84 status = boardobj_pmudatainit_super(g, pboard_obj, ppmudata);
85 if (status != 0) {
86 goto exit;
87 }
88
89 pdev = (struct therm_device_gpu_gpc_tsosc *)(void *)pboard_obj;
90 pset = (struct nv_pmu_therm_therm_device_gpu_gpc_tsosc_boardobj_set *)
91 (void*) ppmudata;
92
93 pset->gpc_tsosc_idx = pdev->gpc_tsosc_idx;
94
95exit:
96 return status;
97}
98
99static int construct_therm_device_gpu_tsosc(struct gk20a *g,
100 struct boardobj **ppboardobj, u16 size, void *pargs)
101{
102 struct therm_device_gpu_gpc_tsosc *pdev = NULL;
103 struct therm_device_gpu_gpc_tsosc *ptmp_dev =
104 (struct therm_device_gpu_gpc_tsosc *)pargs;
105 int status = 0;
106
107 status = construct_therm_device(g, ppboardobj, size, pargs);
108 if (status != 0) {
109 return status;
110 }
111
112 pdev = (struct therm_device_gpu_gpc_tsosc *)(void *)*ppboardobj;
113
114 pdev->super.super.pmudatainit =
115 therm_device_pmu_data_init_gpu_gpc_tsosc;
116
117 pdev->gpc_tsosc_idx = ptmp_dev->gpc_tsosc_idx;
118
119 return status;
120}
121
122static int therm_device_pmu_data_init_hbm2_site(struct gk20a *g,
123 struct boardobj *pboard_obj, struct nv_pmu_boardobj *ppmudata)
124{
125 int status = 0;
126 struct therm_device_hbm2_site *pdev = NULL;
127 struct nv_pmu_therm_therm_device_hbm2_site_boardobj_set *pset;
128
129 status = boardobj_pmudatainit_super(g, pboard_obj, ppmudata);
130 if (status != 0) {
131 goto exit;
132 }
133
134 pdev = (struct therm_device_hbm2_site *)(void *)pboard_obj;
135 pset = (struct nv_pmu_therm_therm_device_hbm2_site_boardobj_set *)
136 (void *)ppmudata;
137
138 pset->site_idx = pdev->site_idx;
139
140exit:
141 return status;
142}
143
144static int construct_therm_device_hbm2_site(struct gk20a *g,
145 struct boardobj **ppboardobj, u16 size, void *pargs)
146{
147 struct therm_device_hbm2_site *pdev = NULL;
148 struct therm_device_hbm2_site *ptmp_dev =
149 (struct therm_device_hbm2_site *)pargs;
150 int status = 0;
151
152 status = construct_therm_device(g, ppboardobj, size, pargs);
153 if (status != 0) {
154 return status;
155 }
156
157 pdev = (struct therm_device_hbm2_site *)(void *)*ppboardobj;
158
159 pdev->super.super.pmudatainit =
160 therm_device_pmu_data_init_hbm2_site;
161
162 pdev->site_idx = ptmp_dev->site_idx;
163
164 return status;
165}
166
167static int construct_therm_device_hbm2_combined(struct gk20a *g,
168 struct boardobj **ppboardobj, u16 size, void *pargs)
169{
170 return construct_therm_device(g, ppboardobj, size, pargs);
171}
172
173
174static struct boardobj *therm_device_construct(struct gk20a *g,
175 void *pargs)
176{
177 struct boardobj *board_obj_ptr = NULL;
178 int status = 0;
179
180 switch (BOARDOBJ_GET_TYPE(pargs)) {
181 case NV_VBIOS_THERM_DEVICE_1X_ENTRY_CLASS_GPU:
182 status = construct_therm_device_gpu(g, &board_obj_ptr,
183 sizeof(struct therm_device), pargs);
184 break;
185 case NV_VBIOS_THERM_DEVICE_1X_ENTRY_CLASS_GPU_GPC_SCI:
186 status = construct_therm_device_gpu_sci(g, &board_obj_ptr,
187 sizeof(struct therm_device_gpu_sci), pargs);
188 break;
189 case NV_VBIOS_THERM_DEVICE_1X_ENTRY_CLASS_GPU_GPC_TSOSC:
190 status = construct_therm_device_gpu_tsosc(g, &board_obj_ptr,
191 sizeof(struct therm_device_gpu_gpc_tsosc), pargs);
192 break;
193 case NV_VBIOS_THERM_DEVICE_1X_ENTRY_CLASS_HBM2_SITE:
194 status = construct_therm_device_hbm2_site(g, &board_obj_ptr,
195 sizeof(struct therm_device_hbm2_site), pargs);
196 break;
197 case NV_VBIOS_THERM_DEVICE_1X_ENTRY_CLASS_HBM2_COMBINED:
198 status = construct_therm_device_hbm2_combined(g, &board_obj_ptr,
199 sizeof(struct therm_device_hbm2_combined), pargs);
200 break;
201 default:
202 nvgpu_err(g,
203 "unsupported therm_device class - 0x%x",
204 BOARDOBJ_GET_TYPE(pargs));
205 break;
206 }
207
208 if(status) {
209 board_obj_ptr = NULL;
210 nvgpu_err(g,
211 "could not allocate memory for therm_device");
212 if (board_obj_ptr != NULL) {
213 nvgpu_kfree(g, board_obj_ptr);
214 }
215 }
216
217
218 return board_obj_ptr;
219}
220
221static int devinit_get_therm_device_table(struct gk20a *g,
222 struct therm_devices *pthermdeviceobjs)
223{
224 int status = 0;
225 u8 *therm_device_table_ptr = NULL;
226 u8 *curr_therm_device_table_ptr = NULL;
227 struct boardobj *boardobj;
228 struct therm_device_1x_header therm_device_table_header = { 0 };
229 struct therm_device_1x_entry *therm_device_table_entry = NULL;
230 u32 index;
231 u32 obj_index = 0;
232 u8 class_id = 0;
233 union {
234 struct boardobj boardobj;
235 struct therm_device therm_device;
236 struct therm_device_gpu_sci gpu_sci;
237 struct therm_device_gpu_gpc_tsosc gpu_gpc_tsosc;
238 struct therm_device_hbm2_site hbm2_site;
239 struct therm_device_hbm2_combined hbm2_combined;
240 } therm_device_data;
241
242 nvgpu_log_info(g, " ");
243
244 therm_device_table_ptr = (u8 *)nvgpu_bios_get_perf_table_ptrs(g,
245 g->bios.perf_token, THERMAL_DEVICE_TABLE);
246 if (therm_device_table_ptr == NULL) {
247 status = -EINVAL;
248 goto done;
249 }
250
251 memcpy(&therm_device_table_header, therm_device_table_ptr,
252 VBIOS_THERM_DEVICE_1X_HEADER_SIZE_04);
253
254 if (therm_device_table_header.version !=
255 VBIOS_THERM_DEVICE_VERSION_1X) {
256 status = -EINVAL;
257 goto done;
258 }
259
260 if (therm_device_table_header.header_size <
261 VBIOS_THERM_DEVICE_1X_HEADER_SIZE_04) {
262 status = -EINVAL;
263 goto done;
264 }
265
266 curr_therm_device_table_ptr = (therm_device_table_ptr +
267 VBIOS_THERM_DEVICE_1X_HEADER_SIZE_04);
268
269 for (index = 0; index < therm_device_table_header.num_table_entries;
270 index++) {
271 therm_device_table_entry = (struct therm_device_1x_entry *)
272 (curr_therm_device_table_ptr +
273 (therm_device_table_header.table_entry_size * index));
274
275 class_id = therm_device_table_entry->class_id;
276
277 switch (class_id) {
278 case NV_VBIOS_THERM_DEVICE_1X_ENTRY_CLASS_INVALID:
279 continue;
280 break;
281 case NV_VBIOS_THERM_DEVICE_1X_ENTRY_CLASS_GPU:
282 case NV_VBIOS_THERM_DEVICE_1X_ENTRY_CLASS_GPU_GPC_SCI:
283 break;
284 case NV_VBIOS_THERM_DEVICE_1X_ENTRY_CLASS_GPU_GPC_TSOSC:
285 therm_device_data.gpu_gpc_tsosc.gpc_tsosc_idx =
286 therm_device_table_entry->param0;
287 break;
288 case NV_VBIOS_THERM_DEVICE_1X_ENTRY_CLASS_HBM2_SITE:
289 therm_device_data.hbm2_site.site_idx =
290 therm_device_table_entry->param0;
291 break;
292 case NV_VBIOS_THERM_DEVICE_1X_ENTRY_CLASS_HBM2_COMBINED:
293 break;
294 default:
295 nvgpu_err(g,
296 "Unknown thermal device class i - %x, class - %x",
297 index, class_id);
298 goto done;
299 }
300
301 therm_device_data.boardobj.type = class_id;
302 boardobj = therm_device_construct(g, &therm_device_data);
303 if (!boardobj) {
304 nvgpu_err(g,
305 "unable to create thermal device for %d type %d",
306 index, therm_device_data.boardobj.type);
307 status = -EINVAL;
308 goto done;
309 }
310
311 status = boardobjgrp_objinsert(&pthermdeviceobjs->super.super,
312 boardobj, obj_index);
313
314 if (status) {
315 nvgpu_err(g,
316 "unable to insert thermal device boardobj for %d", index);
317 status = -EINVAL;
318 goto done;
319 }
320
321 ++obj_index;
322 }
323
324done:
325 nvgpu_log_info(g, " done status %x", status);
326 return status;
327}
328
329int therm_device_sw_setup(struct gk20a *g)
330{
331 int status;
332 struct boardobjgrp *pboardobjgrp = NULL;
333 struct therm_devices *pthermdeviceobjs;
334
335 /* Construct the Super Class and override the Interfaces */
336 status = boardobjgrpconstruct_e32(g,
337 &g->therm_pmu.therm_deviceobjs.super);
338 if (status) {
339 nvgpu_err(g,
340 "error creating boardobjgrp for therm devices, status - 0x%x",
341 status);
342 goto done;
343 }
344
345 pboardobjgrp = &g->therm_pmu.therm_deviceobjs.super.super;
346 pthermdeviceobjs = &(g->therm_pmu.therm_deviceobjs);
347
348 /* Override the Interfaces */
349 pboardobjgrp->pmudatainstget = _therm_device_pmudata_instget;
350
351 status = devinit_get_therm_device_table(g, pthermdeviceobjs);
352 if (status) {
353 goto done;
354 }
355
356 BOARDOBJGRP_PMU_CONSTRUCT(pboardobjgrp, THERM, THERM_DEVICE);
357
358 status = BOARDOBJGRP_PMU_CMD_GRP_SET_CONSTRUCT(g, pboardobjgrp,
359 therm, THERM, therm_device, THERM_DEVICE);
360 if (status) {
361 nvgpu_err(g,
362 "error constructing PMU_BOARDOBJ_CMD_GRP_SET interface - 0x%x",
363 status);
364 goto done;
365 }
366
367done:
368 nvgpu_log_info(g, " done status %x", status);
369 return status;
370}