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, 370 insertions, 0 deletions
diff --git a/include/therm/thrmdev.c b/include/therm/thrmdev.c
new file mode 100644
index 0000000..63e1033
--- /dev/null
+++ b/include/therm/thrmdev.c
@@ -0,0 +1,370 @@
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;