summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/therm/thrmdev.c
diff options
context:
space:
mode:
authorLakshmanan M <lm@nvidia.com>2016-10-21 07:27:15 -0400
committerDeepak Nibade <dnibade@nvidia.com>2016-12-27 04:56:51 -0500
commit58b85dd106f35d16ff568f8836dcbc7a019854b4 (patch)
treea87c10e83f020bd9f414fa4dd0bea74d961034b3 /drivers/gpu/nvgpu/therm/thrmdev.c
parent2f4405ddcb1cd7bb939d3b22ab72789afb435da6 (diff)
gpu: nvgpu: Add thermal module support
The following CL contains the following VBIOS thermal table parsing and PMU interface support. 1) Thermal device table 2) Thermal channel table JIRA DNVGPU-130 Change-Id: Ie3abab4bf099a022b1b59db96811c2ed44079519 Signed-off-by: Lakshmanan M <lm@nvidia.com> Reviewed-on: http://git-master/r/1240630 (cherry picked from commit 814962a4be0a8cd0cddc7bc5211c62308ab1fea2) Reviewed-on: http://git-master/r/1246210 GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/therm/thrmdev.c')
-rw-r--r--drivers/gpu/nvgpu/therm/thrmdev.c193
1 files changed, 193 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/therm/thrmdev.c b/drivers/gpu/nvgpu/therm/thrmdev.c
new file mode 100644
index 00000000..83ac9739
--- /dev/null
+++ b/drivers/gpu/nvgpu/therm/thrmdev.c
@@ -0,0 +1,193 @@
1/*
2 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 */
13
14#include "gk20a/gk20a.h"
15#include "thrmdev.h"
16#include "include/bios.h"
17#include "boardobj/boardobjgrp.h"
18#include "boardobj/boardobjgrp_e32.h"
19#include "pmuif/gpmuifboardobj.h"
20#include "pmuif/gpmuifthermsensor.h"
21#include "gm206/bios_gm206.h"
22#include "gk20a/pmu_gk20a.h"
23#include "ctrl/ctrltherm.h"
24
25static struct boardobj *construct_therm_device(struct gk20a *g,
26 void *pargs, u16 pargs_size, u8 type)
27{
28 struct boardobj *board_obj_ptr = NULL;
29 u32 status;
30
31 status = boardobj_construct_super(g, &board_obj_ptr,
32 pargs_size, pargs);
33 if (status)
34 return NULL;
35
36 gk20a_dbg_info(" Done");
37
38 return board_obj_ptr;
39}
40
41static u32 _therm_device_pmudata_instget(struct gk20a *g,
42 struct nv_pmu_boardobjgrp *pmuboardobjgrp,
43 struct nv_pmu_boardobj **ppboardobjpmudata,
44 u8 idx)
45{
46 struct nv_pmu_therm_therm_device_boardobj_grp_set *pgrp_set =
47 (struct nv_pmu_therm_therm_device_boardobj_grp_set *)
48 pmuboardobjgrp;
49
50 gk20a_dbg_info("");
51
52 /*check whether pmuboardobjgrp has a valid boardobj in index*/
53 if (((u32)BIT(idx) &
54 pgrp_set->hdr.data.super.obj_mask.super.data[0]) == 0)
55 return -EINVAL;
56
57 *ppboardobjpmudata = (struct nv_pmu_boardobj *)
58 &pgrp_set->objects[idx].data;
59
60 gk20a_dbg_info(" Done");
61
62 return 0;
63}
64
65static u32 devinit_get_therm_device_table(struct gk20a *g,
66 struct therm_devices *pthermdeviceobjs)
67{
68 u32 status = 0;
69 u8 *therm_device_table_ptr = NULL;
70 u8 *curr_therm_device_table_ptr = NULL;
71 struct boardobj *boardobj;
72 struct therm_device_1x_header therm_device_table_header = { 0 };
73 struct therm_device_1x_entry *therm_device_table_entry = NULL;
74 u32 index;
75 u32 obj_index = 0;
76 u16 therm_device_size = 0;
77 union {
78 struct boardobj boardobj;
79 struct therm_device therm_device;
80 } therm_device_data;
81
82 gk20a_dbg_info("");
83
84 if (g->ops.bios.get_perf_table_ptrs) {
85 therm_device_table_ptr = (u8 *)g->ops.bios.get_perf_table_ptrs(g,
86 g->bios.perf_token, THERMAL_DEVICE_TABLE);
87 if (therm_device_table_ptr == NULL) {
88 status = -EINVAL;
89 goto done;
90 }
91 }
92
93 memcpy(&therm_device_table_header, therm_device_table_ptr,
94 VBIOS_THERM_DEVICE_1X_HEADER_SIZE_04);
95
96 if (therm_device_table_header.version !=
97 VBIOS_THERM_DEVICE_VERSION_1X) {
98 status = -EINVAL;
99 goto done;
100 }
101
102 if (therm_device_table_header.header_size <
103 VBIOS_THERM_DEVICE_1X_HEADER_SIZE_04) {
104 status = -EINVAL;
105 goto done;
106 }
107
108 curr_therm_device_table_ptr = (therm_device_table_ptr +
109 VBIOS_THERM_DEVICE_1X_HEADER_SIZE_04);
110
111 for (index = 0; index < therm_device_table_header.num_table_entries;
112 index++) {
113 therm_device_table_entry = (struct therm_device_1x_entry *)
114 (curr_therm_device_table_ptr +
115 (therm_device_table_header.table_entry_size * index));
116
117 if (therm_device_table_entry->class_id !=
118 NV_VBIOS_THERM_DEVICE_1X_ENTRY_CLASS_GPU) {
119 continue;
120 }
121
122 therm_device_size = sizeof(struct therm_device);
123 therm_device_data.boardobj.type = CTRL_THERMAL_THERM_DEVICE_CLASS_GPU;
124
125 boardobj = construct_therm_device(g, &therm_device_data,
126 therm_device_size, therm_device_data.boardobj.type);
127
128 if (!boardobj) {
129 gk20a_err(dev_from_gk20a(g),
130 "unable to create thermal device for %d type %d",
131 index, therm_device_data.boardobj.type);
132 status = -EINVAL;
133 goto done;
134 }
135
136 status = boardobjgrp_objinsert(&pthermdeviceobjs->super.super,
137 boardobj, obj_index);
138
139 if (status) {
140 gk20a_err(dev_from_gk20a(g),
141 "unable to insert thermal device boardobj for %d", index);
142 status = -EINVAL;
143 goto done;
144 }
145
146 ++obj_index;
147 }
148
149done:
150 gk20a_dbg_info(" done status %x", status);
151 return status;
152}
153
154u32 therm_device_sw_setup(struct gk20a *g)
155{
156 u32 status;
157 struct boardobjgrp *pboardobjgrp = NULL;
158 struct therm_devices *pthermdeviceobjs;
159
160 /* Construct the Super Class and override the Interfaces */
161 status = boardobjgrpconstruct_e32(&g->therm_pmu.therm_deviceobjs.super);
162 if (status) {
163 gk20a_err(dev_from_gk20a(g),
164 "error creating boardobjgrp for therm devices, status - 0x%x",
165 status);
166 goto done;
167 }
168
169 pboardobjgrp = &g->therm_pmu.therm_deviceobjs.super.super;
170 pthermdeviceobjs = &(g->therm_pmu.therm_deviceobjs);
171
172 /* Override the Interfaces */
173 pboardobjgrp->pmudatainstget = _therm_device_pmudata_instget;
174
175 status = devinit_get_therm_device_table(g, pthermdeviceobjs);
176 if (status)
177 goto done;
178
179 BOARDOBJGRP_PMU_CONSTRUCT(pboardobjgrp, THERM, THERM_DEVICE);
180
181 status = BOARDOBJGRP_PMU_CMD_GRP_SET_CONSTRUCT(g, pboardobjgrp,
182 therm, THERM, therm_device, THERM_DEVICE);
183 if (status) {
184 gk20a_err(dev_from_gk20a(g),
185 "error constructing PMU_BOARDOBJ_CMD_GRP_SET interface - 0x%x",
186 status);
187 goto done;
188 }
189
190done:
191 gk20a_dbg_info(" done status %x", status);
192 return status;
193}